@fieldia/code 0.13.1 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -8
- package/package.json +19 -4
- package/src/index.d.mts +2 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -1
- package/src/index.mjs +2 -0
- package/src/index.mjs.map +1 -1
- package/src/lib/code.d.mts +6 -1
- package/src/lib/code.d.ts +6 -1
- package/src/lib/code.js +84 -12
- package/src/lib/code.js.map +1 -1
- package/src/lib/code.mjs +86 -15
- package/src/lib/code.mjs.map +1 -1
- package/src/lib/languages.d.mts +25 -0
- package/src/lib/languages.d.ts +25 -0
- package/src/lib/languages.js +137 -0
- package/src/lib/languages.js.map +1 -0
- package/src/lib/languages.mjs +132 -0
- package/src/lib/languages.mjs.map +1 -0
- package/src/lib/palette.d.mts +36 -0
- package/src/lib/palette.d.ts +36 -0
- package/src/lib/palette.js +53 -0
- package/src/lib/palette.js.map +1 -0
- package/src/lib/palette.mjs +50 -0
- package/src/lib/palette.mjs.map +1 -0
- package/src/lib/styles.d.mts +1 -1
- package/src/lib/styles.d.ts +1 -1
- package/src/lib/styles.js +17 -2
- package/src/lib/styles.js.map +1 -1
- package/src/lib/styles.mjs +17 -2
- package/src/lib/styles.mjs.map +1 -1
- package/src/lib/text-code.d.mts +2 -0
- package/src/lib/text-code.d.ts +2 -0
- package/src/lib/text-code.js +123 -0
- package/src/lib/text-code.js.map +1 -0
- package/src/lib/text-code.mjs +119 -0
- package/src/lib/text-code.mjs.map +1 -0
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# @fieldia/code
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
[Fieldia](https://fieldia.dev) fields in a code editor: JSON, and text in
|
|
4
|
+
any of 44 languages, coloured as you type. CodeMirror 6, installed with the
|
|
5
|
+
package, so it works offline; each language's grammar loads only when a
|
|
6
|
+
field uses it.
|
|
6
7
|
|
|
7
8
|
```sh
|
|
8
9
|
npm install @fieldia/code
|
|
@@ -15,13 +16,51 @@ import { codeWidgets } from '@fieldia/code';
|
|
|
15
16
|
mountViewer(host, { page, dataSource, widgets: codeWidgets });
|
|
16
17
|
```
|
|
17
18
|
|
|
18
|
-
A
|
|
19
|
+
A node opts in with `"widget": "code"`; others keep their plain box.
|
|
19
20
|
In React pass `widgets={codeWidgets}`, in Vue `:widgets="codeWidgets"`, in
|
|
20
21
|
Angular `[widgets]="codeWidgets"` (spread it beside `gridWidgets` to use both).
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
## Code in a language
|
|
24
|
+
|
|
25
|
+
On a `text` field (or a `char` field, kept to one line), name the language:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{ "type": "field", "field": "script", "widget": "code", "options": { "language": "python" } }
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- JavaScript, TypeScript (and either with JSX), Python, SQL (and the
|
|
32
|
+
PostgreSQL, MySQL, SQLite and SQL Server dialects), HTML, CSS, XML, YAML,
|
|
33
|
+
Markdown, JSON, Java, C, C++, PHP, Rust and Go; and shell, PowerShell,
|
|
34
|
+
Ruby, Perl, Lua, R, Swift, Kotlin, C#, Scala, Dart, Dockerfile, TOML, INI,
|
|
35
|
+
diff, nginx, Protocol Buffers, Haskell, Clojure, Erlang, Groovy and Julia.
|
|
36
|
+
`CODE_LANGUAGES` lists them, each with its other names (`py`, `bash`,
|
|
37
|
+
`yml`, `c++`…); a name is read in any case.
|
|
38
|
+
- Each grammar is a dynamic import of its own, so your bundler makes it a
|
|
39
|
+
file of its own: a page with one Python field loads Python's grammar and no
|
|
40
|
+
other.
|
|
41
|
+
- A language not on the list, or none, is plain text.
|
|
42
|
+
- What is typed reaches the form as text; an empty editor as nothing (null).
|
|
43
|
+
|
|
44
|
+
## JSON
|
|
45
|
+
|
|
46
|
+
On a `json` field, `"widget": "code"` edits the value as JSON: valid JSON
|
|
47
|
+
reaches the form as it is typed; text that is not valid is said so, and the
|
|
48
|
+
last good value stays.
|
|
49
|
+
|
|
50
|
+
## Every editor
|
|
51
|
+
|
|
52
|
+
- Line numbers, bracket matching, undo.
|
|
53
|
+
- Tab moves to the next field, as in every field; Ctrl+] and Ctrl+[ indent.
|
|
54
|
+
- Read-only when the field is; required, invalid and its messages said to
|
|
55
|
+
assistive technology, and named by the field's label.
|
|
56
|
+
- Code reads left to right, on an Arabic page too.
|
|
57
|
+
- Coloured in Fieldia's tokens: the box on the form's surface, comments in
|
|
58
|
+
its quiet words; keywords, strings and the rest in colours that read at
|
|
59
|
+
4.5:1 or more on every theme's surface, light and dark. Set your own with
|
|
60
|
+
the `--fd-code-keyword`, `--fd-code-string`, `--fd-code-literal`,
|
|
61
|
+
`--fd-code-function`, `--fd-code-type`, `--fd-code-tag` and
|
|
62
|
+
`--fd-code-property` tokens.
|
|
63
|
+
|
|
64
|
+
For VS Code's editor instead, see `@fieldia/monaco`.
|
|
26
65
|
|
|
27
66
|
MIT. CodeMirror is MIT too.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fieldia/code",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Fieldia
|
|
3
|
+
"version": "0.14.1",
|
|
4
|
+
"description": "Fieldia fields in a code editor: JSON, and text in 44 languages from Python to SQL. CodeMirror 6, each grammar loaded only when a field uses it.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://fieldia.dev",
|
|
7
7
|
"type": "commonjs",
|
|
@@ -22,13 +22,28 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@codemirror/commands": "^6.11.1",
|
|
25
|
+
"@codemirror/lang-cpp": "^6.0.3",
|
|
26
|
+
"@codemirror/lang-css": "^6.3.1",
|
|
27
|
+
"@codemirror/lang-go": "^6.0.1",
|
|
28
|
+
"@codemirror/lang-html": "^6.4.12",
|
|
29
|
+
"@codemirror/lang-java": "^6.0.2",
|
|
30
|
+
"@codemirror/lang-javascript": "^6.2.5",
|
|
25
31
|
"@codemirror/lang-json": "^6.0.2",
|
|
32
|
+
"@codemirror/lang-markdown": "^6.5.2",
|
|
33
|
+
"@codemirror/lang-php": "^6.0.2",
|
|
34
|
+
"@codemirror/lang-python": "^6.2.1",
|
|
35
|
+
"@codemirror/lang-rust": "^6.0.2",
|
|
36
|
+
"@codemirror/lang-sql": "^6.10.0",
|
|
37
|
+
"@codemirror/lang-xml": "^6.1.0",
|
|
38
|
+
"@codemirror/lang-yaml": "^6.1.3",
|
|
26
39
|
"@codemirror/language": ">=6.12.4 <6.13.0 || >=6.13.1 <7.0.0",
|
|
40
|
+
"@codemirror/legacy-modes": "^6.5.4",
|
|
27
41
|
"@codemirror/lint": "^6.9.7",
|
|
28
42
|
"@codemirror/state": "^6.7.6",
|
|
29
43
|
"@codemirror/view": "^6.43.13",
|
|
30
|
-
"@fieldia/core": "0.
|
|
31
|
-
"@fieldia/widgets": "0.
|
|
44
|
+
"@fieldia/core": "0.14.1",
|
|
45
|
+
"@fieldia/widgets": "0.14.1",
|
|
46
|
+
"@lezer/highlight": "^1.2.5",
|
|
32
47
|
"tslib": "^2.8.1"
|
|
33
48
|
},
|
|
34
49
|
"sideEffects": false,
|
package/src/index.d.mts
CHANGED
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -3,4 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./lib/code"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./lib/styles"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/languages"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/palette"), exports);
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/code/src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,uDAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/code/src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,uDAA6B;AAC7B,0DAAgC;AAChC,wDAA8B"}
|
package/src/index.mjs
CHANGED
package/src/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../libs/code/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../libs/code/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
|
package/src/lib/code.d.mts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { type WidgetFactory } from '@fieldia/widgets';
|
|
2
|
+
export { textCodeWidget } from './text-code.mjs';
|
|
2
3
|
export declare const codeWidget: WidgetFactory;
|
|
3
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Pass these to the viewer (`widgets`) to show nodes marked `"widget": "code"`
|
|
6
|
+
* in the editor: json as JSON, text and char in the language the node names
|
|
7
|
+
* (`"options": { "language": "python" }`).
|
|
8
|
+
*/
|
|
4
9
|
export declare const codeWidgets: Record<string, WidgetFactory>;
|
package/src/lib/code.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { type WidgetFactory } from '@fieldia/widgets';
|
|
2
|
+
export { textCodeWidget } from './text-code';
|
|
2
3
|
export declare const codeWidget: WidgetFactory;
|
|
3
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Pass these to the viewer (`widgets`) to show nodes marked `"widget": "code"`
|
|
6
|
+
* in the editor: json as JSON, text and char in the language the node names
|
|
7
|
+
* (`"options": { "language": "python" }`).
|
|
8
|
+
*/
|
|
4
9
|
export declare const codeWidgets: Record<string, WidgetFactory>;
|
package/src/lib/code.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.codeWidgets = exports.codeWidget = void 0;
|
|
3
|
+
exports.codeWidgets = exports.codeWidget = exports.textCodeWidget = void 0;
|
|
4
4
|
const commands_1 = require("@codemirror/commands");
|
|
5
5
|
const lang_json_1 = require("@codemirror/lang-json");
|
|
6
6
|
const language_1 = require("@codemirror/language");
|
|
7
7
|
const state_1 = require("@codemirror/state");
|
|
8
8
|
const view_1 = require("@codemirror/view");
|
|
9
9
|
const widgets_1 = require("@fieldia/widgets");
|
|
10
|
+
const palette_1 = require("./palette");
|
|
10
11
|
const styles_1 = require("./styles");
|
|
12
|
+
const text_code_1 = require("./text-code");
|
|
13
|
+
var text_code_2 = require("./text-code");
|
|
14
|
+
Object.defineProperty(exports, "textCodeWidget", { enumerable: true, get: function () { return text_code_2.textCodeWidget; } });
|
|
11
15
|
/**
|
|
12
16
|
* A JSON field in a code editor: CodeMirror 6, bundled with the package, so it
|
|
13
17
|
* works offline and loads only on pages that ask for it (`"widget": "code"` on
|
|
@@ -27,15 +31,50 @@ function read(text) {
|
|
|
27
31
|
return undefined;
|
|
28
32
|
}
|
|
29
33
|
}
|
|
34
|
+
/** Where the JSON went wrong, marked: its line shaded, the character that cannot be there underlined. Null takes the marks away. */
|
|
35
|
+
const markProblem = state_1.StateEffect.define();
|
|
36
|
+
const problemMarks = state_1.StateField.define({
|
|
37
|
+
create: () => view_1.Decoration.none,
|
|
38
|
+
update(marks, tr) {
|
|
39
|
+
let next = marks.map(tr.changes);
|
|
40
|
+
for (const effect of tr.effects) {
|
|
41
|
+
if (!effect.is(markProblem))
|
|
42
|
+
continue;
|
|
43
|
+
if (effect.value === null) {
|
|
44
|
+
next = view_1.Decoration.none;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const at = Math.min(effect.value, tr.state.doc.length);
|
|
48
|
+
const line = tr.state.doc.lineAt(at);
|
|
49
|
+
const ranges = [view_1.Decoration.line({ class: 'fd-code-bad-line' }).range(line.from)];
|
|
50
|
+
if (at < line.to)
|
|
51
|
+
ranges.push(view_1.Decoration.mark({ class: 'fd-code-bad-spot' }).range(at, at + 1));
|
|
52
|
+
next = view_1.Decoration.set(ranges, true);
|
|
53
|
+
}
|
|
54
|
+
return next;
|
|
55
|
+
},
|
|
56
|
+
provide: (field) => view_1.EditorView.decorations.from(field),
|
|
57
|
+
});
|
|
58
|
+
/** How long typing pauses before a problem is said: not at every key of a word half typed. */
|
|
59
|
+
const SETTLE_MS = 500;
|
|
30
60
|
const codeWidget = ({ form, name, id, document, labels = widgets_1.WIDGET_LABELS.en }) => {
|
|
31
61
|
(0, styles_1.installCodeStyles)(document);
|
|
32
62
|
const element = document.createElement('div');
|
|
33
63
|
element.className = 'fd-code';
|
|
64
|
+
// JSON reads left to right, on an Arabic page too: drawn right to left, its punctuation moves.
|
|
65
|
+
element.dir = 'ltr';
|
|
34
66
|
const error = document.createElement('div');
|
|
35
67
|
error.className = 'fd-error fd-code-error';
|
|
68
|
+
error.id = `${id}-json-problem`;
|
|
69
|
+
// In the page's language, though the code above it reads left to right: an Arabic message reads right to left.
|
|
70
|
+
error.dir = 'auto';
|
|
36
71
|
error.setAttribute('role', 'alert');
|
|
37
72
|
error.textContent = labels.invalidJson;
|
|
38
73
|
error.hidden = true;
|
|
74
|
+
/** The field's own help and error, from the form. */
|
|
75
|
+
let described = '';
|
|
76
|
+
let invalidByForm = false;
|
|
77
|
+
let saying;
|
|
39
78
|
const editable = new state_1.Compartment();
|
|
40
79
|
/** What the form holds, as last written or shown: an echo of it is not a change. */
|
|
41
80
|
let known = JSON.stringify(form.getState().values[name] ?? null);
|
|
@@ -49,8 +88,10 @@ const codeWidget = ({ form, name, id, document, labels = widgets_1.WIDGET_LABELS
|
|
|
49
88
|
(0, commands_1.history)(),
|
|
50
89
|
(0, language_1.bracketMatching)(),
|
|
51
90
|
(0, language_1.indentOnInput)(),
|
|
52
|
-
|
|
91
|
+
// The code colours, light or dark with the page: CodeMirror's own are for light pages only.
|
|
92
|
+
(0, language_1.syntaxHighlighting)(palette_1.codeHighlightStyle),
|
|
53
93
|
(0, lang_json_1.json)(),
|
|
94
|
+
problemMarks,
|
|
54
95
|
view_1.keymap.of([...commands_1.defaultKeymap, ...commands_1.historyKeymap]),
|
|
55
96
|
editable.of([view_1.EditorView.editable.of(true), state_1.EditorState.readOnly.of(false)]),
|
|
56
97
|
// Named by the field's label, like every other field.
|
|
@@ -58,12 +99,15 @@ const codeWidget = ({ form, name, id, document, labels = widgets_1.WIDGET_LABELS
|
|
|
58
99
|
view_1.EditorView.updateListener.of((update) => {
|
|
59
100
|
if (!update.docChanged || writing)
|
|
60
101
|
return;
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
102
|
+
const text = update.state.doc.toString();
|
|
103
|
+
const parsed = read(text);
|
|
104
|
+
clearTimeout(saying);
|
|
105
|
+
if (parsed === undefined) {
|
|
106
|
+
// Said, and marked where it breaks, once typing pauses.
|
|
107
|
+
saying = setTimeout(() => say((0, widgets_1.jsonProblem)(text)), SETTLE_MS);
|
|
66
108
|
return;
|
|
109
|
+
}
|
|
110
|
+
queueMicrotask(() => say(null));
|
|
67
111
|
known = JSON.stringify(parsed);
|
|
68
112
|
form.setValue(name, parsed);
|
|
69
113
|
}),
|
|
@@ -71,14 +115,38 @@ const codeWidget = ({ form, name, id, document, labels = widgets_1.WIDGET_LABELS
|
|
|
71
115
|
}),
|
|
72
116
|
});
|
|
73
117
|
element.append(error);
|
|
118
|
+
/** Says where the JSON goes wrong, or that nothing does: under the editor, in it, and to assistive technology. */
|
|
119
|
+
function say(problem) {
|
|
120
|
+
error.hidden = !problem;
|
|
121
|
+
if (problem)
|
|
122
|
+
error.textContent = labels.invalidJsonAt.replace('{line}', String(problem.line)).replace('{column}', String(problem.column));
|
|
123
|
+
view.dispatch({ effects: markProblem.of(problem ? problem.offset : null) });
|
|
124
|
+
describe();
|
|
125
|
+
}
|
|
126
|
+
function describe() {
|
|
127
|
+
const content = view.contentDOM;
|
|
128
|
+
content.setAttribute('aria-invalid', String(invalidByForm || !error.hidden));
|
|
129
|
+
const ids = [described, error.hidden ? '' : error.id].filter(Boolean).join(' ');
|
|
130
|
+
if (ids)
|
|
131
|
+
content.setAttribute('aria-describedby', ids);
|
|
132
|
+
else
|
|
133
|
+
content.removeAttribute('aria-describedby');
|
|
134
|
+
}
|
|
74
135
|
return {
|
|
75
136
|
element,
|
|
76
137
|
focus: () => view.focus(),
|
|
77
|
-
destroy: () =>
|
|
138
|
+
destroy: () => {
|
|
139
|
+
clearTimeout(saying);
|
|
140
|
+
view.destroy();
|
|
141
|
+
},
|
|
78
142
|
update(state) {
|
|
79
143
|
view.dispatch({
|
|
80
144
|
effects: editable.reconfigure([view_1.EditorView.editable.of(!state.readonly), state_1.EditorState.readOnly.of(state.readonly)]),
|
|
81
145
|
});
|
|
146
|
+
described = state.describedBy ?? '';
|
|
147
|
+
invalidByForm = state.invalid;
|
|
148
|
+
view.contentDOM.setAttribute('aria-required', String(state.required));
|
|
149
|
+
describe();
|
|
82
150
|
// A value from elsewhere (loaded, discarded) replaces the text; the echo of what was typed does not.
|
|
83
151
|
const incoming = JSON.stringify(state.value ?? null);
|
|
84
152
|
if (incoming === known)
|
|
@@ -87,12 +155,16 @@ const codeWidget = ({ form, name, id, document, labels = widgets_1.WIDGET_LABELS
|
|
|
87
155
|
writing = true;
|
|
88
156
|
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: show(state.value) } });
|
|
89
157
|
writing = false;
|
|
90
|
-
|
|
91
|
-
|
|
158
|
+
clearTimeout(saying);
|
|
159
|
+
say(null);
|
|
92
160
|
},
|
|
93
161
|
};
|
|
94
162
|
};
|
|
95
163
|
exports.codeWidget = codeWidget;
|
|
96
|
-
/**
|
|
97
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Pass these to the viewer (`widgets`) to show nodes marked `"widget": "code"`
|
|
166
|
+
* in the editor: json as JSON, text and char in the language the node names
|
|
167
|
+
* (`"options": { "language": "python" }`).
|
|
168
|
+
*/
|
|
169
|
+
exports.codeWidgets = { 'json.code': exports.codeWidget, 'text.code': text_code_1.textCodeWidget, 'char.code': text_code_1.textCodeWidget };
|
|
98
170
|
//# sourceMappingURL=code.js.map
|
package/src/lib/code.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../../../../libs/code/src/lib/code.ts"],"names":[],"mappings":";;;AAAA,mDAA6E;AAC7E,qDAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../../../../libs/code/src/lib/code.ts"],"names":[],"mappings":";;;AAAA,mDAA6E;AAC7E,qDAA6C;AAC7C,mDAA0F;AAC1F,6CAAsF;AACtF,2CAAmG;AAEnG,8CAAkF;AAClF,uCAA+C;AAC/C,qCAA6C;AAC7C,2CAA6C;AAE7C,yCAA6C;AAApC,2GAAA,cAAc,OAAA;AAEvB;;;;;;GAMG;AAEH,MAAM,IAAI,GAAG,CAAC,KAAwB,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAEzH,iFAAiF;AACjF,SAAS,IAAI,CAAC,IAAY;IACxB,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,CAAC;QACH,OAAO,I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O,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9F,OAAO,GAAG,KAAK,CAAC;YAChB,YAAY,CAAC,MAAM,CAAC,CAAC;YACrB,GAAG,CAAC,IAAI,CAAC,CAAC;QACZ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAtGW,QAAA,UAAU,cAsGrB;AAEF;;;;GAIG;AACU,QAAA,WAAW,GAAkC,EAAE,WAAW,EAAE,kBAAU,EAAE,WAAW,EAAE,0BAAc,EAAE,WAAW,EAAE,0BAAc,EAAE,CAAC"}
|
package/src/lib/code.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
|
|
2
2
|
import { json } from '@codemirror/lang-json';
|
|
3
|
-
import { bracketMatching,
|
|
4
|
-
import { Compartment, EditorState } from '@codemirror/state';
|
|
5
|
-
import { EditorView, keymap, lineNumbers } from '@codemirror/view';
|
|
6
|
-
import { WIDGET_LABELS } from '@fieldia/widgets';
|
|
3
|
+
import { bracketMatching, indentOnInput, syntaxHighlighting } from '@codemirror/language';
|
|
4
|
+
import { Compartment, EditorState, StateEffect, StateField } from '@codemirror/state';
|
|
5
|
+
import { Decoration, EditorView, keymap, lineNumbers } from '@codemirror/view';
|
|
6
|
+
import { jsonProblem, WIDGET_LABELS } from '@fieldia/widgets';
|
|
7
|
+
import { codeHighlightStyle } from './palette.mjs';
|
|
7
8
|
import { installCodeStyles } from './styles.mjs';
|
|
9
|
+
import { textCodeWidget } from './text-code.mjs';
|
|
10
|
+
export { textCodeWidget } from './text-code.mjs';
|
|
8
11
|
/**
|
|
9
12
|
* A JSON field in a code editor: CodeMirror 6, bundled with the package, so it
|
|
10
13
|
* works offline and loads only on pages that ask for it (`"widget": "code"` on
|
|
@@ -24,15 +27,50 @@ function read(text) {
|
|
|
24
27
|
return undefined;
|
|
25
28
|
}
|
|
26
29
|
}
|
|
30
|
+
/** Where the JSON went wrong, marked: its line shaded, the character that cannot be there underlined. Null takes the marks away. */
|
|
31
|
+
const markProblem = StateEffect.define();
|
|
32
|
+
const problemMarks = StateField.define({
|
|
33
|
+
create: () => Decoration.none,
|
|
34
|
+
update(marks, tr) {
|
|
35
|
+
let next = marks.map(tr.changes);
|
|
36
|
+
for (const effect of tr.effects) {
|
|
37
|
+
if (!effect.is(markProblem))
|
|
38
|
+
continue;
|
|
39
|
+
if (effect.value === null) {
|
|
40
|
+
next = Decoration.none;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const at = Math.min(effect.value, tr.state.doc.length);
|
|
44
|
+
const line = tr.state.doc.lineAt(at);
|
|
45
|
+
const ranges = [Decoration.line({ class: 'fd-code-bad-line' }).range(line.from)];
|
|
46
|
+
if (at < line.to)
|
|
47
|
+
ranges.push(Decoration.mark({ class: 'fd-code-bad-spot' }).range(at, at + 1));
|
|
48
|
+
next = Decoration.set(ranges, true);
|
|
49
|
+
}
|
|
50
|
+
return next;
|
|
51
|
+
},
|
|
52
|
+
provide: (field) => EditorView.decorations.from(field),
|
|
53
|
+
});
|
|
54
|
+
/** How long typing pauses before a problem is said: not at every key of a word half typed. */
|
|
55
|
+
const SETTLE_MS = 500;
|
|
27
56
|
export const codeWidget = ({ form, name, id, document, labels = WIDGET_LABELS.en }) => {
|
|
28
57
|
installCodeStyles(document);
|
|
29
58
|
const element = document.createElement('div');
|
|
30
59
|
element.className = 'fd-code';
|
|
60
|
+
// JSON reads left to right, on an Arabic page too: drawn right to left, its punctuation moves.
|
|
61
|
+
element.dir = 'ltr';
|
|
31
62
|
const error = document.createElement('div');
|
|
32
63
|
error.className = 'fd-error fd-code-error';
|
|
64
|
+
error.id = `${id}-json-problem`;
|
|
65
|
+
// In the page's language, though the code above it reads left to right: an Arabic message reads right to left.
|
|
66
|
+
error.dir = 'auto';
|
|
33
67
|
error.setAttribute('role', 'alert');
|
|
34
68
|
error.textContent = labels.invalidJson;
|
|
35
69
|
error.hidden = true;
|
|
70
|
+
/** The field's own help and error, from the form. */
|
|
71
|
+
let described = '';
|
|
72
|
+
let invalidByForm = false;
|
|
73
|
+
let saying;
|
|
36
74
|
const editable = new Compartment();
|
|
37
75
|
/** What the form holds, as last written or shown: an echo of it is not a change. */
|
|
38
76
|
let known = JSON.stringify(form.getState().values[name] ?? null);
|
|
@@ -46,8 +84,10 @@ export const codeWidget = ({ form, name, id, document, labels = WIDGET_LABELS.en
|
|
|
46
84
|
history(),
|
|
47
85
|
bracketMatching(),
|
|
48
86
|
indentOnInput(),
|
|
49
|
-
|
|
87
|
+
// The code colours, light or dark with the page: CodeMirror's own are for light pages only.
|
|
88
|
+
syntaxHighlighting(codeHighlightStyle),
|
|
50
89
|
json(),
|
|
90
|
+
problemMarks,
|
|
51
91
|
keymap.of([...defaultKeymap, ...historyKeymap]),
|
|
52
92
|
editable.of([EditorView.editable.of(true), EditorState.readOnly.of(false)]),
|
|
53
93
|
// Named by the field's label, like every other field.
|
|
@@ -55,12 +95,15 @@ export const codeWidget = ({ form, name, id, document, labels = WIDGET_LABELS.en
|
|
|
55
95
|
EditorView.updateListener.of((update) => {
|
|
56
96
|
if (!update.docChanged || writing)
|
|
57
97
|
return;
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
98
|
+
const text = update.state.doc.toString();
|
|
99
|
+
const parsed = read(text);
|
|
100
|
+
clearTimeout(saying);
|
|
101
|
+
if (parsed === undefined) {
|
|
102
|
+
// Said, and marked where it breaks, once typing pauses.
|
|
103
|
+
saying = setTimeout(() => say(jsonProblem(text)), SETTLE_MS);
|
|
63
104
|
return;
|
|
105
|
+
}
|
|
106
|
+
queueMicrotask(() => say(null));
|
|
64
107
|
known = JSON.stringify(parsed);
|
|
65
108
|
form.setValue(name, parsed);
|
|
66
109
|
}),
|
|
@@ -68,14 +111,38 @@ export const codeWidget = ({ form, name, id, document, labels = WIDGET_LABELS.en
|
|
|
68
111
|
}),
|
|
69
112
|
});
|
|
70
113
|
element.append(error);
|
|
114
|
+
/** Says where the JSON goes wrong, or that nothing does: under the editor, in it, and to assistive technology. */
|
|
115
|
+
function say(problem) {
|
|
116
|
+
error.hidden = !problem;
|
|
117
|
+
if (problem)
|
|
118
|
+
error.textContent = labels.invalidJsonAt.replace('{line}', String(problem.line)).replace('{column}', String(problem.column));
|
|
119
|
+
view.dispatch({ effects: markProblem.of(problem ? problem.offset : null) });
|
|
120
|
+
describe();
|
|
121
|
+
}
|
|
122
|
+
function describe() {
|
|
123
|
+
const content = view.contentDOM;
|
|
124
|
+
content.setAttribute('aria-invalid', String(invalidByForm || !error.hidden));
|
|
125
|
+
const ids = [described, error.hidden ? '' : error.id].filter(Boolean).join(' ');
|
|
126
|
+
if (ids)
|
|
127
|
+
content.setAttribute('aria-describedby', ids);
|
|
128
|
+
else
|
|
129
|
+
content.removeAttribute('aria-describedby');
|
|
130
|
+
}
|
|
71
131
|
return {
|
|
72
132
|
element,
|
|
73
133
|
focus: () => view.focus(),
|
|
74
|
-
destroy: () =>
|
|
134
|
+
destroy: () => {
|
|
135
|
+
clearTimeout(saying);
|
|
136
|
+
view.destroy();
|
|
137
|
+
},
|
|
75
138
|
update(state) {
|
|
76
139
|
view.dispatch({
|
|
77
140
|
effects: editable.reconfigure([EditorView.editable.of(!state.readonly), EditorState.readOnly.of(state.readonly)]),
|
|
78
141
|
});
|
|
142
|
+
described = state.describedBy ?? '';
|
|
143
|
+
invalidByForm = state.invalid;
|
|
144
|
+
view.contentDOM.setAttribute('aria-required', String(state.required));
|
|
145
|
+
describe();
|
|
79
146
|
// A value from elsewhere (loaded, discarded) replaces the text; the echo of what was typed does not.
|
|
80
147
|
const incoming = JSON.stringify(state.value ?? null);
|
|
81
148
|
if (incoming === known)
|
|
@@ -84,11 +151,15 @@ export const codeWidget = ({ form, name, id, document, labels = WIDGET_LABELS.en
|
|
|
84
151
|
writing = true;
|
|
85
152
|
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: show(state.value) } });
|
|
86
153
|
writing = false;
|
|
87
|
-
|
|
88
|
-
|
|
154
|
+
clearTimeout(saying);
|
|
155
|
+
say(null);
|
|
89
156
|
},
|
|
90
157
|
};
|
|
91
158
|
};
|
|
92
|
-
/**
|
|
93
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Pass these to the viewer (`widgets`) to show nodes marked `"widget": "code"`
|
|
161
|
+
* in the editor: json as JSON, text and char in the language the node names
|
|
162
|
+
* (`"options": { "language": "python" }`).
|
|
163
|
+
*/
|
|
164
|
+
export const codeWidgets = { 'json.code': codeWidget, 'text.code': textCodeWidget, 'char.code': textCodeWidget };
|
|
94
165
|
//# sourceMappingURL=code.mjs.map
|
package/src/lib/code.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.mjs","sourceRoot":"","sources":["../../../../../libs/code/src/lib/code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"code.mjs","sourceRoot":"","sources":["../../../../../libs/code/src/lib/code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,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AAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;aAClH,CAAC,CAAC;YACH,SAAS,GAAG,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC;YACpC,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC;YAC9B,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;YACtE,QAAQ,EAAE,CAAC;YACX,qGAAqG;YACrG,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;YACrD,IAAI,QAAQ,KAAK,KAAK;gBAAE,OAAO;YAC/B,KAAK,GAAG,QAAQ,CAAC;YACjB,OAAO,GAAG,IAAI,CAAC;YACf,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9F,OAAO,GAAG,KAAK,CAAC;YAChB,YAAY,CAAC,MAAM,CAAC,CAAC;YACrB,GAAG,CAAC,IAAI,CAAC,CAAC;QACZ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAkC,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Extension } from '@codemirror/state';
|
|
2
|
+
/**
|
|
3
|
+
* The languages a code field can be written in (`options.language`), each
|
|
4
|
+
* grammar loaded only when a field asks for it: a dynamic import of its own,
|
|
5
|
+
* so a bundler splits it off and a page with one Python field carries
|
|
6
|
+
* Python's grammar alone. A name this list does not know is plain text.
|
|
7
|
+
*/
|
|
8
|
+
export interface CodeLanguage {
|
|
9
|
+
/** The name a page gives it: `{ "widget": "code", "options": { "language": "python" } }`. */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Its name as people know it. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Other names a page may give it: `py`, `bash`, `yml`. */
|
|
14
|
+
aliases: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
/** Every language a code field can be written in, in the order a person picking one reads them. */
|
|
17
|
+
export declare const CODE_LANGUAGES: readonly CodeLanguage[];
|
|
18
|
+
/** The language a page names, by its id or another of its names, in any case; null for one not on the list. */
|
|
19
|
+
export declare function codeLanguage(name: unknown): CodeLanguage | null;
|
|
20
|
+
/**
|
|
21
|
+
* The grammar of the language a page names, ready for an editor: loaded the
|
|
22
|
+
* first time a field asks for it. Null for a language not on the list, and
|
|
23
|
+
* for one whose file could not be fetched — the field stays plain text.
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadCodeLanguage(name: unknown): Promise<Extension | null>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Extension } from '@codemirror/state';
|
|
2
|
+
/**
|
|
3
|
+
* The languages a code field can be written in (`options.language`), each
|
|
4
|
+
* grammar loaded only when a field asks for it: a dynamic import of its own,
|
|
5
|
+
* so a bundler splits it off and a page with one Python field carries
|
|
6
|
+
* Python's grammar alone. A name this list does not know is plain text.
|
|
7
|
+
*/
|
|
8
|
+
export interface CodeLanguage {
|
|
9
|
+
/** The name a page gives it: `{ "widget": "code", "options": { "language": "python" } }`. */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Its name as people know it. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Other names a page may give it: `py`, `bash`, `yml`. */
|
|
14
|
+
aliases: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
/** Every language a code field can be written in, in the order a person picking one reads them. */
|
|
17
|
+
export declare const CODE_LANGUAGES: readonly CodeLanguage[];
|
|
18
|
+
/** The language a page names, by its id or another of its names, in any case; null for one not on the list. */
|
|
19
|
+
export declare function codeLanguage(name: unknown): CodeLanguage | null;
|
|
20
|
+
/**
|
|
21
|
+
* The grammar of the language a page names, ready for an editor: loaded the
|
|
22
|
+
* first time a field asks for it. Null for a language not on the list, and
|
|
23
|
+
* for one whose file could not be fetched — the field stays plain text.
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadCodeLanguage(name: unknown): Promise<Extension | null>;
|