cylc / cylc-ui

Web app for monitoring and controlling Cylc workflows
https://cylc.github.io
GNU General Public License v3.0
37 stars 27 forks source link

text editor #144

Open oliver-sanders opened 5 years ago

oliver-sanders commented 5 years ago

Edit 2023:

This issue has moved on as full editor capability is no longer required. We now only require a file "viewer", see https://github.com/cylc/cylc-ui/issues/144#issuecomment-1505175390 for more details.

The Cylc UI will need a text editor (readonly) for:

Cylc7 Functionality:

Potential future functionality:

We want an in-browser text editor which:

So here's our shopping list:

1) Syntax highlighting via TextMate grammar.

Additional bonus marks for an editor which:

a) Has auto-completion (e.g. for task names). b) ~Has tabbing with lazy load (e.g. open job.* files).~ we will likely rely on lumino for this c) Can elegantly display diffs (e.g. cylc diff). d) Regex search.

kinow commented 5 years ago

Hopefully this one we should be able to find a component that does most of what we need, then just use it with none/little customization.

wxtim commented 4 years ago

Investigation:

Editor TextMate Grammars Display File Streams Linkable Lines Large File Handling Auto Completion Diffs RE Search
Ace Yes No (would have to implement ourselves) Yes (syntax highlight) Yes
CodeMirror No (needs 3rd party package) No (would have to implement ourselves) Yes (syntax highlight) Yes
Monaco No (needs 3rd party package) No (would have to implement ourselves) Yes (rich) Yes
Prism.js (read-only) No Yes (plugin) N/A Yes (syntax highlight) No?
oliver-sanders commented 4 years ago

Jupyterlab uses codemirror, I found this package which converts textmate grammars for codemirror editors, it's pretty small though :(

hjoliver commented 4 years ago

What do you mean by "small" there?

oliver-sanders commented 4 years ago

0-4 weekly downloads, 11 stars.

oliver-sanders commented 2 years ago

Update: trigger edit may use an auto-generated form which reduces the requirements as we no longer require an editor, only a viewer.

MetRonnie commented 2 years ago

Monaco:

oliver-sanders commented 2 years ago

Monaco might be a bit heavy weight for us

Unpacked Size 79.5 MB --- https://www.npmjs.com/package/monaco-editor

kinow commented 2 years ago

I think the editor can be lazy-loaded (i.e. loaded only when used in the UI), and it should also be possible to tree-shake it, loading only what's actually used in the Cylc UI code (some times it works, some times it doesn't — e.g. I never got Vuetify to unload some modules I was sure it was not using, and I think other users reported a similar issue…).

IIRC, the… vue ui? vue inspect? That utility that displays the bundled web application to inspect the Vue app settings… it has a reporting tool to show the size of the artefacts generated, including imported libraries. So someone can import monaco editor (important to import like import { moduleA } from "monaco" or so, to hint to webpack/etc what's actually used :+1:, instead of import "monaco" or import * from monaco as bla", etc)

kinow commented 2 years ago

(or there are other smaller editors if the UI doesn't need a lot of features in the text editor, like Ace editor for instance - https://ace.c9.io/)

oliver-sanders commented 2 years ago

Ace looks pretty good and supports TextMate grammars which is a big win.

Given that we don't need editor functionality we might be better off going with a more light-weight display-only tool for simplicity.

oliver-sanders commented 1 year ago

VitePress uses Shikijs which supports TextMate as well as VSCode colour themes:

https://github.com/shikijs/shiki

oliver-sanders commented 1 year ago

The monaco editor, whilst 85mb in size can be chunked. There is also a vite plugin: https://www.npmjs.com/package/vite-plugin-monaco-editor

One barrier would be that monaco integrates with webkit, but not rollup as it does not support ESM modules, this could interfere with chunking? Would need to try.

oliver-sanders commented 1 year ago

Our requirements are now fairly simplistic (we don't need an editor any more), we could get by with just a syntax highlighter.

I think the main items on the shopping list are:

With bonus marks for:

[1] The TextMate grammar approach does NOT support incremental lexing, so handing a dynamic document involves rendering and re-rendering the same code block over and over. This will need to be handled in an efficient way, and ideally one which doesn't delete the whole component and re-create it from scratch as that would create continuity issues for the user. Note, some systems use WASM code for this which should be a performance win.