@fieldia/code 0.13.1 → 0.14.0
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 +15 -4
- package/src/lib/code.js.map +1 -1
- package/src/lib/code.mjs +14 -4
- 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 +50 -0
- package/src/lib/palette.js.map +1 -0
- package/src/lib/palette.mjs +47 -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 +12 -1
- package/src/lib/styles.js.map +1 -1
- package/src/lib/styles.mjs +12 -1
- 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
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { StreamLanguage, indentUnit } from '@codemirror/language';
|
|
2
|
+
/** A grammar from @codemirror/legacy-modes, as a language the editor reads. */
|
|
3
|
+
const stream = (parser) => StreamLanguage.define(parser);
|
|
4
|
+
/** How each language's grammar loads: a dynamic import each, so each is a file of its own. */
|
|
5
|
+
const LOADERS = {
|
|
6
|
+
javascript: () => import('@codemirror/lang-javascript').then((m) => m.javascript()),
|
|
7
|
+
typescript: () => import('@codemirror/lang-javascript').then((m) => m.javascript({ typescript: true })),
|
|
8
|
+
jsx: () => import('@codemirror/lang-javascript').then((m) => m.javascript({ jsx: true })),
|
|
9
|
+
tsx: () => import('@codemirror/lang-javascript').then((m) => m.javascript({ jsx: true, typescript: true })),
|
|
10
|
+
python: () => import('@codemirror/lang-python').then((m) => m.python()),
|
|
11
|
+
sql: () => import('@codemirror/lang-sql').then((m) => m.sql()),
|
|
12
|
+
postgresql: () => import('@codemirror/lang-sql').then((m) => m.sql({ dialect: m.PostgreSQL })),
|
|
13
|
+
mysql: () => import('@codemirror/lang-sql').then((m) => m.sql({ dialect: m.MySQL })),
|
|
14
|
+
sqlite: () => import('@codemirror/lang-sql').then((m) => m.sql({ dialect: m.SQLite })),
|
|
15
|
+
mssql: () => import('@codemirror/lang-sql').then((m) => m.sql({ dialect: m.MSSQL })),
|
|
16
|
+
html: () => import('@codemirror/lang-html').then((m) => m.html()),
|
|
17
|
+
css: () => import('@codemirror/lang-css').then((m) => m.css()),
|
|
18
|
+
xml: () => import('@codemirror/lang-xml').then((m) => m.xml()),
|
|
19
|
+
yaml: () => import('@codemirror/lang-yaml').then((m) => m.yaml()),
|
|
20
|
+
markdown: () => import('@codemirror/lang-markdown').then((m) => m.markdown()),
|
|
21
|
+
json: () => import('@codemirror/lang-json').then((m) => m.json()),
|
|
22
|
+
java: () => import('@codemirror/lang-java').then((m) => m.java()),
|
|
23
|
+
c: () => import('@codemirror/lang-cpp').then((m) => m.cpp()),
|
|
24
|
+
cpp: () => import('@codemirror/lang-cpp').then((m) => m.cpp()),
|
|
25
|
+
php: () => import('@codemirror/lang-php').then((m) => m.php()),
|
|
26
|
+
rust: () => import('@codemirror/lang-rust').then((m) => m.rust()),
|
|
27
|
+
go: () => import('@codemirror/lang-go').then((m) => m.go()),
|
|
28
|
+
// The rest from CodeMirror 5's modes, each a small file of its own.
|
|
29
|
+
shell: () => import('@codemirror/legacy-modes/mode/shell').then((m) => stream(m.shell)),
|
|
30
|
+
powershell: () => import('@codemirror/legacy-modes/mode/powershell').then((m) => stream(m.powerShell)),
|
|
31
|
+
ruby: () => import('@codemirror/legacy-modes/mode/ruby').then((m) => stream(m.ruby)),
|
|
32
|
+
perl: () => import('@codemirror/legacy-modes/mode/perl').then((m) => stream(m.perl)),
|
|
33
|
+
lua: () => import('@codemirror/legacy-modes/mode/lua').then((m) => stream(m.lua)),
|
|
34
|
+
r: () => import('@codemirror/legacy-modes/mode/r').then((m) => stream(m.r)),
|
|
35
|
+
swift: () => import('@codemirror/legacy-modes/mode/swift').then((m) => stream(m.swift)),
|
|
36
|
+
kotlin: () => import('@codemirror/legacy-modes/mode/clike').then((m) => stream(m.kotlin)),
|
|
37
|
+
csharp: () => import('@codemirror/legacy-modes/mode/clike').then((m) => stream(m.csharp)),
|
|
38
|
+
scala: () => import('@codemirror/legacy-modes/mode/clike').then((m) => stream(m.scala)),
|
|
39
|
+
dart: () => import('@codemirror/legacy-modes/mode/clike').then((m) => stream(m.dart)),
|
|
40
|
+
dockerfile: () => import('@codemirror/legacy-modes/mode/dockerfile').then((m) => stream(m.dockerFile)),
|
|
41
|
+
toml: () => import('@codemirror/legacy-modes/mode/toml').then((m) => stream(m.toml)),
|
|
42
|
+
ini: () => import('@codemirror/legacy-modes/mode/properties').then((m) => stream(m.properties)),
|
|
43
|
+
diff: () => import('@codemirror/legacy-modes/mode/diff').then((m) => stream(m.diff)),
|
|
44
|
+
nginx: () => import('@codemirror/legacy-modes/mode/nginx').then((m) => stream(m.nginx)),
|
|
45
|
+
protobuf: () => import('@codemirror/legacy-modes/mode/protobuf').then((m) => stream(m.protobuf)),
|
|
46
|
+
haskell: () => import('@codemirror/legacy-modes/mode/haskell').then((m) => stream(m.haskell)),
|
|
47
|
+
clojure: () => import('@codemirror/legacy-modes/mode/clojure').then((m) => stream(m.clojure)),
|
|
48
|
+
erlang: () => import('@codemirror/legacy-modes/mode/erlang').then((m) => stream(m.erlang)),
|
|
49
|
+
groovy: () => import('@codemirror/legacy-modes/mode/groovy').then((m) => stream(m.groovy)),
|
|
50
|
+
julia: () => import('@codemirror/legacy-modes/mode/julia').then((m) => stream(m.julia)),
|
|
51
|
+
};
|
|
52
|
+
/** How a language is usually indented, where it is not by two spaces: four for Python, C and their kin, a tab for Go. */
|
|
53
|
+
const INDENTS = Object.fromEntries([
|
|
54
|
+
...['python', 'java', 'c', 'cpp', 'csharp', 'php', 'rust', 'kotlin', 'swift', 'powershell', 'perl', 'julia', 'groovy'].map((id) => [id, ' ']),
|
|
55
|
+
['go', '\t'],
|
|
56
|
+
]);
|
|
57
|
+
const language = (id, name, ...aliases) => ({ id, name, aliases });
|
|
58
|
+
/** Every language a code field can be written in, in the order a person picking one reads them. */
|
|
59
|
+
export const CODE_LANGUAGES = [
|
|
60
|
+
language('javascript', 'JavaScript', 'js', 'mjs', 'cjs', 'node'),
|
|
61
|
+
language('typescript', 'TypeScript', 'ts', 'mts', 'cts'),
|
|
62
|
+
language('jsx', 'JavaScript with JSX'),
|
|
63
|
+
language('tsx', 'TypeScript with JSX'),
|
|
64
|
+
language('python', 'Python', 'py', 'python3'),
|
|
65
|
+
language('sql', 'SQL'),
|
|
66
|
+
language('postgresql', 'PostgreSQL', 'postgres', 'pgsql', 'psql'),
|
|
67
|
+
language('mysql', 'MySQL', 'mariadb'),
|
|
68
|
+
language('sqlite', 'SQLite'),
|
|
69
|
+
language('mssql', 'SQL Server', 'tsql', 't-sql', 'sqlserver'),
|
|
70
|
+
language('html', 'HTML', 'htm', 'xhtml'),
|
|
71
|
+
language('css', 'CSS'),
|
|
72
|
+
language('xml', 'XML', 'svg', 'xsl'),
|
|
73
|
+
language('yaml', 'YAML', 'yml'),
|
|
74
|
+
language('markdown', 'Markdown', 'md'),
|
|
75
|
+
language('json', 'JSON', 'jsonc'),
|
|
76
|
+
language('java', 'Java'),
|
|
77
|
+
language('c', 'C', 'h'),
|
|
78
|
+
language('cpp', 'C++', 'c++', 'cc', 'cxx', 'hpp'),
|
|
79
|
+
language('php', 'PHP'),
|
|
80
|
+
language('rust', 'Rust', 'rs'),
|
|
81
|
+
language('go', 'Go', 'golang'),
|
|
82
|
+
language('shell', 'Shell', 'sh', 'bash', 'zsh'),
|
|
83
|
+
language('powershell', 'PowerShell', 'ps1', 'pwsh'),
|
|
84
|
+
language('ruby', 'Ruby', 'rb'),
|
|
85
|
+
language('perl', 'Perl', 'pl'),
|
|
86
|
+
language('lua', 'Lua'),
|
|
87
|
+
language('r', 'R'),
|
|
88
|
+
language('swift', 'Swift'),
|
|
89
|
+
language('kotlin', 'Kotlin', 'kt', 'kts'),
|
|
90
|
+
language('csharp', 'C#', 'c#', 'cs'),
|
|
91
|
+
language('scala', 'Scala'),
|
|
92
|
+
language('dart', 'Dart'),
|
|
93
|
+
language('dockerfile', 'Dockerfile', 'docker'),
|
|
94
|
+
language('toml', 'TOML'),
|
|
95
|
+
language('ini', 'INI', 'properties', 'conf'),
|
|
96
|
+
language('diff', 'Diff', 'patch'),
|
|
97
|
+
language('nginx', 'nginx'),
|
|
98
|
+
language('protobuf', 'Protocol Buffers', 'proto'),
|
|
99
|
+
language('haskell', 'Haskell', 'hs'),
|
|
100
|
+
language('clojure', 'Clojure', 'clj'),
|
|
101
|
+
language('erlang', 'Erlang', 'erl'),
|
|
102
|
+
language('groovy', 'Groovy', 'gradle'),
|
|
103
|
+
language('julia', 'Julia', 'jl'),
|
|
104
|
+
];
|
|
105
|
+
const BY_NAME = new Map(CODE_LANGUAGES.flatMap((language) => [language.id, ...language.aliases].map((name) => [name, language])));
|
|
106
|
+
/** The language a page names, by its id or another of its names, in any case; null for one not on the list. */
|
|
107
|
+
export function codeLanguage(name) {
|
|
108
|
+
return typeof name === 'string' ? BY_NAME.get(name.trim().toLowerCase()) ?? null : null;
|
|
109
|
+
}
|
|
110
|
+
/** Each grammar's load, once: every field in that language shares it. */
|
|
111
|
+
const loading = new Map();
|
|
112
|
+
/**
|
|
113
|
+
* The grammar of the language a page names, ready for an editor: loaded the
|
|
114
|
+
* first time a field asks for it. Null for a language not on the list, and
|
|
115
|
+
* for one whose file could not be fetched — the field stays plain text.
|
|
116
|
+
*/
|
|
117
|
+
export function loadCodeLanguage(name) {
|
|
118
|
+
const found = codeLanguage(name);
|
|
119
|
+
if (!found)
|
|
120
|
+
return Promise.resolve(null);
|
|
121
|
+
let load = loading.get(found.id);
|
|
122
|
+
if (!load) {
|
|
123
|
+
load = LOADERS[found.id]().then((support) => [support, indentUnit.of(INDENTS[found.id] ?? ' ')], () => {
|
|
124
|
+
// Not fetched (offline, say): plain text this time, and another try next time.
|
|
125
|
+
loading.delete(found.id);
|
|
126
|
+
return null;
|
|
127
|
+
});
|
|
128
|
+
loading.set(found.id, load);
|
|
129
|
+
}
|
|
130
|
+
return load;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=languages.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"languages.mjs","sourceRoot":"","sources":["../../../../../libs/code/src/lib/languages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAqB,MAAM,sBAAsB,CAAC;AAmBrF,+EAA+E;AAC/E,MAAM,MAAM,GAAG,CAAC,MAA6B,EAAa,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAE3F,8FAA8F;AAC9F,MAAM,OAAO,GAA6C;IACxD,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,6BAA6B,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;IACnF,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,6BAA6B,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IACvG,GAAG,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ours code is drawn in, by what a word is: a keyword, a string, a
|
|
4
|
+
* number… Light and dark, each reading at 4.5:1 or more (WCAG AA) on the
|
|
5
|
+
* surface of every Fieldia theme in that scheme (palette.spec.ts). Comments
|
|
6
|
+
* take the page's quiet words (`--fd-muted`), errors its error colour, and
|
|
7
|
+
* the rest of the text its words, so the code sits among the other fields.
|
|
8
|
+
*
|
|
9
|
+
* They are CSS variables, `--fd-code-keyword` and the rest, in Fieldia's
|
|
10
|
+
* tokens' layer: a host sets its own over them as it sets any token.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CODE_COLOURS: {
|
|
13
|
+
readonly light: {
|
|
14
|
+
readonly keyword: "#cf222e";
|
|
15
|
+
readonly string: "#0a3069";
|
|
16
|
+
readonly literal: "#0550ae";
|
|
17
|
+
readonly function: "#6639ba";
|
|
18
|
+
readonly type: "#953800";
|
|
19
|
+
readonly tag: "#116329";
|
|
20
|
+
readonly property: "#0550ae";
|
|
21
|
+
};
|
|
22
|
+
readonly dark: {
|
|
23
|
+
readonly keyword: "#ff7b72";
|
|
24
|
+
readonly string: "#a5d6ff";
|
|
25
|
+
readonly literal: "#79c0ff";
|
|
26
|
+
readonly function: "#d2a8ff";
|
|
27
|
+
readonly type: "#ffa657";
|
|
28
|
+
readonly tag: "#7ee787";
|
|
29
|
+
readonly property: "#79c0ff";
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export type CodeRole = keyof (typeof CODE_COLOURS)['light'];
|
|
33
|
+
/** The colours as CSS: light on any code box, dark where the page's scheme is dark, or follows a dark system. */
|
|
34
|
+
export declare const CODE_COLOURS_CSS: string;
|
|
35
|
+
/** What each kind of word in a grammar is drawn as, in the colours above. */
|
|
36
|
+
export declare const codeHighlightStyle: HighlightStyle;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { HighlightStyle } from '@codemirror/language';
|
|
2
|
+
/**
|
|
3
|
+
* The colours code is drawn in, by what a word is: a keyword, a string, a
|
|
4
|
+
* number… Light and dark, each reading at 4.5:1 or more (WCAG AA) on the
|
|
5
|
+
* surface of every Fieldia theme in that scheme (palette.spec.ts). Comments
|
|
6
|
+
* take the page's quiet words (`--fd-muted`), errors its error colour, and
|
|
7
|
+
* the rest of the text its words, so the code sits among the other fields.
|
|
8
|
+
*
|
|
9
|
+
* They are CSS variables, `--fd-code-keyword` and the rest, in Fieldia's
|
|
10
|
+
* tokens' layer: a host sets its own over them as it sets any token.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CODE_COLOURS: {
|
|
13
|
+
readonly light: {
|
|
14
|
+
readonly keyword: "#cf222e";
|
|
15
|
+
readonly string: "#0a3069";
|
|
16
|
+
readonly literal: "#0550ae";
|
|
17
|
+
readonly function: "#6639ba";
|
|
18
|
+
readonly type: "#953800";
|
|
19
|
+
readonly tag: "#116329";
|
|
20
|
+
readonly property: "#0550ae";
|
|
21
|
+
};
|
|
22
|
+
readonly dark: {
|
|
23
|
+
readonly keyword: "#ff7b72";
|
|
24
|
+
readonly string: "#a5d6ff";
|
|
25
|
+
readonly literal: "#79c0ff";
|
|
26
|
+
readonly function: "#d2a8ff";
|
|
27
|
+
readonly type: "#ffa657";
|
|
28
|
+
readonly tag: "#7ee787";
|
|
29
|
+
readonly property: "#79c0ff";
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export type CodeRole = keyof (typeof CODE_COLOURS)['light'];
|
|
33
|
+
/** The colours as CSS: light on any code box, dark where the page's scheme is dark, or follows a dark system. */
|
|
34
|
+
export declare const CODE_COLOURS_CSS: string;
|
|
35
|
+
/** What each kind of word in a grammar is drawn as, in the colours above. */
|
|
36
|
+
export declare const codeHighlightStyle: HighlightStyle;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codeHighlightStyle = exports.CODE_COLOURS_CSS = exports.CODE_COLOURS = void 0;
|
|
4
|
+
const language_1 = require("@codemirror/language");
|
|
5
|
+
const highlight_1 = require("@lezer/highlight");
|
|
6
|
+
/**
|
|
7
|
+
* The colours code is drawn in, by what a word is: a keyword, a string, a
|
|
8
|
+
* number… Light and dark, each reading at 4.5:1 or more (WCAG AA) on the
|
|
9
|
+
* surface of every Fieldia theme in that scheme (palette.spec.ts). Comments
|
|
10
|
+
* take the page's quiet words (`--fd-muted`), errors its error colour, and
|
|
11
|
+
* the rest of the text its words, so the code sits among the other fields.
|
|
12
|
+
*
|
|
13
|
+
* They are CSS variables, `--fd-code-keyword` and the rest, in Fieldia's
|
|
14
|
+
* tokens' layer: a host sets its own over them as it sets any token.
|
|
15
|
+
*/
|
|
16
|
+
exports.CODE_COLOURS = {
|
|
17
|
+
light: { keyword: '#cf222e', string: '#0a3069', literal: '#0550ae', function: '#6639ba', type: '#953800', tag: '#116329', property: '#0550ae' },
|
|
18
|
+
dark: { keyword: '#ff7b72', string: '#a5d6ff', literal: '#79c0ff', function: '#d2a8ff', type: '#ffa657', tag: '#7ee787', property: '#79c0ff' },
|
|
19
|
+
};
|
|
20
|
+
const declare = (scheme) => Object.entries(exports.CODE_COLOURS[scheme])
|
|
21
|
+
.map(([role, colour]) => `--fd-code-${role}: ${colour};`)
|
|
22
|
+
.join(' ');
|
|
23
|
+
/** The colours as CSS: light on any code box, dark where the page's scheme is dark, or follows a dark system. */
|
|
24
|
+
exports.CODE_COLOURS_CSS = `@layer fieldia-tokens {
|
|
25
|
+
.fd-code { ${declare('light')} }
|
|
26
|
+
:is(.fd-form, .fd-form-dialog, .fd-theme)[data-scheme="dark"] .fd-code { ${declare('dark')} }
|
|
27
|
+
@media (prefers-color-scheme: dark) { :is(.fd-form, .fd-form-dialog, .fd-theme)[data-scheme="auto"] .fd-code { ${declare('dark')} } }
|
|
28
|
+
}`;
|
|
29
|
+
const v = (role) => `var(--fd-code-${role})`;
|
|
30
|
+
/** What each kind of word in a grammar is drawn as, in the colours above. */
|
|
31
|
+
exports.codeHighlightStyle = language_1.HighlightStyle.define([
|
|
32
|
+
{ tag: [highlight_1.tags.keyword, highlight_1.tags.modifier, highlight_1.tags.operatorKeyword, highlight_1.tags.controlKeyword, highlight_1.tags.definitionKeyword, highlight_1.tags.moduleKeyword, highlight_1.tags.self], color: v('keyword') },
|
|
33
|
+
{ tag: [highlight_1.tags.string, highlight_1.tags.special(highlight_1.tags.string), highlight_1.tags.character, highlight_1.tags.regexp, highlight_1.tags.escape], color: v('string') },
|
|
34
|
+
{ tag: [highlight_1.tags.number, highlight_1.tags.bool, highlight_1.tags.null, highlight_1.tags.atom, highlight_1.tags.unit, highlight_1.tags.constant(highlight_1.tags.name), highlight_1.tags.standard(highlight_1.tags.name)], color: v('literal') },
|
|
35
|
+
{ tag: [highlight_1.tags.function(highlight_1.tags.variableName), highlight_1.tags.function(highlight_1.tags.propertyName), highlight_1.tags.function(highlight_1.tags.definition(highlight_1.tags.variableName)), highlight_1.tags.macroName], color: v('function') },
|
|
36
|
+
{ tag: [highlight_1.tags.typeName, highlight_1.tags.className, highlight_1.tags.namespace, highlight_1.tags.labelName], color: v('type') },
|
|
37
|
+
{ tag: [highlight_1.tags.tagName, highlight_1.tags.angleBracket], color: v('tag') },
|
|
38
|
+
{ tag: [highlight_1.tags.attributeName, highlight_1.tags.propertyName], color: v('property') },
|
|
39
|
+
{ tag: [highlight_1.tags.comment, highlight_1.tags.lineComment, highlight_1.tags.blockComment, highlight_1.tags.docComment, highlight_1.tags.meta, highlight_1.tags.processingInstruction, highlight_1.tags.documentMeta], color: 'var(--fd-muted)', fontStyle: 'italic' },
|
|
40
|
+
{ tag: highlight_1.tags.heading, color: v('keyword'), fontWeight: 'bold' },
|
|
41
|
+
{ tag: highlight_1.tags.strong, fontWeight: 'bold' },
|
|
42
|
+
{ tag: highlight_1.tags.emphasis, fontStyle: 'italic' },
|
|
43
|
+
{ tag: highlight_1.tags.strikethrough, textDecoration: 'line-through' },
|
|
44
|
+
{ tag: [highlight_1.tags.link, highlight_1.tags.url], color: v('string'), textDecoration: 'underline' },
|
|
45
|
+
{ tag: highlight_1.tags.inserted, color: v('tag') },
|
|
46
|
+
{ tag: highlight_1.tags.deleted, color: v('keyword') },
|
|
47
|
+
{ tag: highlight_1.tags.changed, color: v('type') },
|
|
48
|
+
{ tag: highlight_1.tags.invalid, color: 'var(--fd-error)' },
|
|
49
|
+
]);
|
|
50
|
+
//# sourceMappingURL=palette.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"palette.js","sourceRoot":"","sources":["../../../../../libs/code/src/lib/palette.ts"],"names":[],"mappings":";;;AAAA,mDAAsD;AACtD,gDAA6C;AAE7C;;;;;;;;;GASG;AACU,QAAA,YAAY,GAAG;IAC1B,KAAK,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE;IAC/I,IAAI,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE;CACtI,CAAC;AAIX,MAAM,OAAO,GAAG,CAAC,MAAwB,EAAE,EAAE,CAC3C,MAAM,CAAC,OAAO,CAAC,oBAAY,CAAC,MAAM,CAAC,CAAC;KACjC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,aAAa,IAAI,KAAK,MAAM,GAAG,CAAC;KACxD,IAAI,CAAC,GAAG,CAAC,CAAC;AAEf,iHAAiH;AACpG,QAAA,gBAAgB,GAAG;aACnB,OAAO,CAAC,OAAO,CAAC;2EAC8C,OAAO,CAAC,MAAM,CAAC;iHACuB,OAAO,CAAC,MAAM,CAAC;EAC9H,CAAC;AAEH,MAAM,CA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,EAAE,GAAG,EAAE,gBAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE;IACpC,EAAE,GAAG,EAAE,gBAAC,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE;IACvC,EAAE,GAAG,EAAE,gBAAC,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE;IACpC,EAAE,GAAG,EAAE,gBAAC,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE;CAC7C,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { HighlightStyle } from '@codemirror/language';
|
|
2
|
+
import { tags as t } from '@lezer/highlight';
|
|
3
|
+
/**
|
|
4
|
+
* The colours code is drawn in, by what a word is: a keyword, a string, a
|
|
5
|
+
* number… Light and dark, each reading at 4.5:1 or more (WCAG AA) on the
|
|
6
|
+
* surface of every Fieldia theme in that scheme (palette.spec.ts). Comments
|
|
7
|
+
* take the page's quiet words (`--fd-muted`), errors its error colour, and
|
|
8
|
+
* the rest of the text its words, so the code sits among the other fields.
|
|
9
|
+
*
|
|
10
|
+
* They are CSS variables, `--fd-code-keyword` and the rest, in Fieldia's
|
|
11
|
+
* tokens' layer: a host sets its own over them as it sets any token.
|
|
12
|
+
*/
|
|
13
|
+
export const CODE_COLOURS = {
|
|
14
|
+
light: { keyword: '#cf222e', string: '#0a3069', literal: '#0550ae', function: '#6639ba', type: '#953800', tag: '#116329', property: '#0550ae' },
|
|
15
|
+
dark: { keyword: '#ff7b72', string: '#a5d6ff', literal: '#79c0ff', function: '#d2a8ff', type: '#ffa657', tag: '#7ee787', property: '#79c0ff' },
|
|
16
|
+
};
|
|
17
|
+
const declare = (scheme) => Object.entries(CODE_COLOURS[scheme])
|
|
18
|
+
.map(([role, colour]) => `--fd-code-${role}: ${colour};`)
|
|
19
|
+
.join(' ');
|
|
20
|
+
/** The colours as CSS: light on any code box, dark where the page's scheme is dark, or follows a dark system. */
|
|
21
|
+
export const CODE_COLOURS_CSS = `@layer fieldia-tokens {
|
|
22
|
+
.fd-code { ${declare('light')} }
|
|
23
|
+
:is(.fd-form, .fd-form-dialog, .fd-theme)[data-scheme="dark"] .fd-code { ${declare('dark')} }
|
|
24
|
+
@media (prefers-color-scheme: dark) { :is(.fd-form, .fd-form-dialog, .fd-theme)[data-scheme="auto"] .fd-code { ${declare('dark')} } }
|
|
25
|
+
}`;
|
|
26
|
+
const v = (role) => `var(--fd-code-${role})`;
|
|
27
|
+
/** What each kind of word in a grammar is drawn as, in the colours above. */
|
|
28
|
+
export const codeHighlightStyle = HighlightStyle.define([
|
|
29
|
+
{ tag: [t.keyword, t.modifier, t.operatorKeyword, t.controlKeyword, t.definitionKeyword, t.moduleKeyword, t.self], color: v('keyword') },
|
|
30
|
+
{ tag: [t.string, t.special(t.string), t.character, t.regexp, t.escape], color: v('string') },
|
|
31
|
+
{ tag: [t.number, t.bool, t.null, t.atom, t.unit, t.constant(t.name), t.standard(t.name)], color: v('literal') },
|
|
32
|
+
{ tag: [t.function(t.variableName), t.function(t.propertyName), t.function(t.definition(t.variableName)), t.macroName], color: v('function') },
|
|
33
|
+
{ tag: [t.typeName, t.className, t.namespace, t.labelName], color: v('type') },
|
|
34
|
+
{ tag: [t.tagName, t.angleBracket], color: v('tag') },
|
|
35
|
+
{ tag: [t.attributeName, t.propertyName], color: v('property') },
|
|
36
|
+
{ tag: [t.comment, t.lineComment, t.blockComment, t.docComment, t.meta, t.processingInstruction, t.documentMeta], color: 'var(--fd-muted)', fontStyle: 'italic' },
|
|
37
|
+
{ tag: t.heading, color: v('keyword'), fontWeight: 'bold' },
|
|
38
|
+
{ tag: t.strong, fontWeight: 'bold' },
|
|
39
|
+
{ tag: t.emphasis, fontStyle: 'italic' },
|
|
40
|
+
{ tag: t.strikethrough, textDecoration: 'line-through' },
|
|
41
|
+
{ tag: [t.link, t.url], color: v('string'), textDecoration: 'underline' },
|
|
42
|
+
{ tag: t.inserted, color: v('tag') },
|
|
43
|
+
{ tag: t.deleted, color: v('keyword') },
|
|
44
|
+
{ tag: t.changed, color: v('type') },
|
|
45
|
+
{ tag: t.invalid, color: 'var(--fd-error)' },
|
|
46
|
+
]);
|
|
47
|
+
//# sourceMappingURL=palette.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"palette.mjs","sourceRoot":"","sources":["../../../../../libs/code/src/lib/palette.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,KAAK,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE;IAC/I,IAAI,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE;CACtI,CAAC;AAIX,MAAM,OAAO,GAAG,CAAC,MAAwB,EAAE,EAAE,CAC3C,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;KACjC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,aAAa,IAAI,KAAK,MAAM,GAAG,CAAC;KACxD,IAAI,CAAC,GAAG,CAAC,CAAC;AAEf,iHAAiH;AACjH,MAAM,CAAC,MAAM,gBAAgB,GAAG;aACnB,OAAO,CAAC,OAAO,CAAC;2EAC8C,OAA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,cAAc,EAAE,WAAW,EAAE;IACzE,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE;IACpC,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE;IACvC,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE;IACpC,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE;CAC7C,CAAC,CAAC"}
|
package/src/lib/styles.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** The editor in Fieldia's colours, so it sits among the other fields. Installed once per document. */
|
|
2
|
-
export declare const CODE_CSS
|
|
2
|
+
export declare const CODE_CSS: string;
|
|
3
3
|
export declare function installCodeStyles(doc: Document): void;
|
package/src/lib/styles.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** The editor in Fieldia's colours, so it sits among the other fields. Installed once per document. */
|
|
2
|
-
export declare const CODE_CSS
|
|
2
|
+
export declare const CODE_CSS: string;
|
|
3
3
|
export declare function installCodeStyles(doc: Document): void;
|
package/src/lib/styles.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CODE_CSS = void 0;
|
|
4
4
|
exports.installCodeStyles = installCodeStyles;
|
|
5
|
+
const palette_1 = require("./palette");
|
|
5
6
|
/** The editor in Fieldia's colours, so it sits among the other fields. Installed once per document. */
|
|
6
7
|
exports.CODE_CSS = `
|
|
7
|
-
|
|
8
|
+
/* One column, as wide as the field: a long line scrolls inside the editor, never widens the page. */
|
|
9
|
+
.fd-code { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; min-width: 0; }
|
|
8
10
|
.fd-code .cm-editor {
|
|
9
11
|
border: 1px solid var(--fd-border); border-radius: var(--fd-control-radius); background: var(--fd-surface);
|
|
10
12
|
color: var(--fd-text); font-size: 13px; min-height: 96px; max-height: 360px;
|
|
@@ -13,6 +15,15 @@ exports.CODE_CSS = `
|
|
|
13
15
|
.fd-code .cm-scroller { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.5; }
|
|
14
16
|
.fd-code .cm-gutters { background: var(--fd-page); color: var(--fd-muted); border-inline-end: 1px solid var(--fd-border); }
|
|
15
17
|
.fd-code .cm-content[aria-invalid="true"] { background: var(--fd-error-soft); }
|
|
18
|
+
/* Code in a language: its words in the code colours, the box shaded when it is only to be read. */
|
|
19
|
+
.fd-code-text .cm-editor { color: var(--fd-text); }
|
|
20
|
+
.fd-code-text[data-readonly] .cm-editor { background: color-mix(in srgb, var(--fd-text) 4%, var(--fd-surface)); }
|
|
21
|
+
.fd-code-text .cm-placeholder { color: var(--fd-muted); }
|
|
22
|
+
/* A char field's code is one line: as tall as a text box, no line numbers. */
|
|
23
|
+
.fd-code-line { min-height: 0; }
|
|
24
|
+
.fd-code-line .cm-editor { min-height: 0; }
|
|
25
|
+
.fd-code-line .cm-content { padding-block: max(2px, calc(var(--fd-pad-y, 4px) - 1px)); }
|
|
26
|
+
${palette_1.CODE_COLOURS_CSS}
|
|
16
27
|
`;
|
|
17
28
|
function installCodeStyles(doc) {
|
|
18
29
|
if (doc.getElementById('fieldia-code-styles'))
|
package/src/lib/styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../../../libs/code/src/lib/styles.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../../../libs/code/src/lib/styles.ts"],"names":[],"mappings":";;;AAyBA,8CAMC;AA/BD,uCAA6C;AAE7C,uGAAuG;AAC1F,QAAA,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;EAmBtB,0BAAgB;CACjB,CAAC;AAEF,SAAgB,iBAAiB,CAAC,GAAa;IAC7C,IAAI,GAAG,CAAC,cAAc,CAAC,qBAAqB,CAAC;QAAE,OAAO;IACtD,MAAM,KAAK,GAAG,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,GAAG,qBAAqB,CAAC;IACjC,KAAK,CAAC,WAAW,GAAG,gBAAQ,CAAC;IAC7B,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC"}
|
package/src/lib/styles.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { CODE_COLOURS_CSS } from './palette.mjs';
|
|
1
2
|
/** The editor in Fieldia's colours, so it sits among the other fields. Installed once per document. */
|
|
2
3
|
export const CODE_CSS = `
|
|
3
|
-
|
|
4
|
+
/* One column, as wide as the field: a long line scrolls inside the editor, never widens the page. */
|
|
5
|
+
.fd-code { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; min-width: 0; }
|
|
4
6
|
.fd-code .cm-editor {
|
|
5
7
|
border: 1px solid var(--fd-border); border-radius: var(--fd-control-radius); background: var(--fd-surface);
|
|
6
8
|
color: var(--fd-text); font-size: 13px; min-height: 96px; max-height: 360px;
|
|
@@ -9,6 +11,15 @@ export const CODE_CSS = `
|
|
|
9
11
|
.fd-code .cm-scroller { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.5; }
|
|
10
12
|
.fd-code .cm-gutters { background: var(--fd-page); color: var(--fd-muted); border-inline-end: 1px solid var(--fd-border); }
|
|
11
13
|
.fd-code .cm-content[aria-invalid="true"] { background: var(--fd-error-soft); }
|
|
14
|
+
/* Code in a language: its words in the code colours, the box shaded when it is only to be read. */
|
|
15
|
+
.fd-code-text .cm-editor { color: var(--fd-text); }
|
|
16
|
+
.fd-code-text[data-readonly] .cm-editor { background: color-mix(in srgb, var(--fd-text) 4%, var(--fd-surface)); }
|
|
17
|
+
.fd-code-text .cm-placeholder { color: var(--fd-muted); }
|
|
18
|
+
/* A char field's code is one line: as tall as a text box, no line numbers. */
|
|
19
|
+
.fd-code-line { min-height: 0; }
|
|
20
|
+
.fd-code-line .cm-editor { min-height: 0; }
|
|
21
|
+
.fd-code-line .cm-content { padding-block: max(2px, calc(var(--fd-pad-y, 4px) - 1px)); }
|
|
22
|
+
${CODE_COLOURS_CSS}
|
|
12
23
|
`;
|
|
13
24
|
export function installCodeStyles(doc) {
|
|
14
25
|
if (doc.getElementById('fieldia-code-styles'))
|
package/src/lib/styles.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.mjs","sourceRoot":"","sources":["../../../../../libs/code/src/lib/styles.ts"],"names":[],"mappings":"AAAA,uGAAuG;AACvG,MAAM,CAAC,MAAM,QAAQ,GAAG
|
|
1
|
+
{"version":3,"file":"styles.mjs","sourceRoot":"","sources":["../../../../../libs/code/src/lib/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,uGAAuG;AACvG,MAAM,CAAC,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;EAmBtB,gBAAgB;CACjB,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,GAAa;IAC7C,IAAI,GAAG,CAAC,cAAc,CAAC,qBAAqB,CAAC;QAAE,OAAO;IACtD,MAAM,KAAK,GAAG,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,GAAG,qBAAqB,CAAC;IACjC,KAAK,CAAC,WAAW,GAAG,QAAQ,CAAC;IAC7B,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.textCodeWidget = void 0;
|
|
4
|
+
const commands_1 = require("@codemirror/commands");
|
|
5
|
+
const language_1 = require("@codemirror/language");
|
|
6
|
+
const state_1 = require("@codemirror/state");
|
|
7
|
+
const view_1 = require("@codemirror/view");
|
|
8
|
+
const languages_1 = require("./languages");
|
|
9
|
+
const palette_1 = require("./palette");
|
|
10
|
+
const styles_1 = require("./styles");
|
|
11
|
+
/**
|
|
12
|
+
* A text or char field as code, coloured in the language the page names:
|
|
13
|
+
* `{ "widget": "code", "options": { "language": "python" } }`. The grammar
|
|
14
|
+
* loads when the field is drawn, and only that one; a language the editor
|
|
15
|
+
* does not know is plain text. What is typed reaches the form as text, an
|
|
16
|
+
* empty editor as nothing. Tab is left to move between fields; Ctrl+] and
|
|
17
|
+
* Ctrl+[ indent. Code reads left to right, on an Arabic page too.
|
|
18
|
+
*/
|
|
19
|
+
const textOf = (value) => (value === null || value === undefined ? '' : String(value));
|
|
20
|
+
/** A char field is one line: Enter adds nothing, and pasted lines join, as a text box joins them. */
|
|
21
|
+
const oneLine = state_1.EditorState.transactionFilter.of((tr) => {
|
|
22
|
+
if (!tr.docChanged || tr.newDoc.lines === 1)
|
|
23
|
+
return tr;
|
|
24
|
+
let words = false;
|
|
25
|
+
const changes = [];
|
|
26
|
+
tr.changes.iterChanges((from, to, _fromB, _toB, inserted) => {
|
|
27
|
+
const text = inserted.toString();
|
|
28
|
+
if (text.trim() !== '')
|
|
29
|
+
words = true;
|
|
30
|
+
changes.push({ from, to, insert: text.replace(/\s*[\r\n]+\s*/g, ' ') });
|
|
31
|
+
});
|
|
32
|
+
if (!words)
|
|
33
|
+
return [];
|
|
34
|
+
const joined = tr.startState.changes(changes);
|
|
35
|
+
return { changes: joined, selection: { anchor: joined.mapPos(tr.startState.selection.main.head, 1) }, scrollIntoView: true };
|
|
36
|
+
});
|
|
37
|
+
/** No longer than the field's size: a change that would make it longer is refused, as a text box's maxlength does. */
|
|
38
|
+
const atMost = (size) => state_1.EditorState.transactionFilter.of((tr) => (tr.docChanged && tr.newDoc.length > size && tr.newDoc.length > tr.startState.doc.length ? [] : tr));
|
|
39
|
+
const textCodeWidget = ({ form, name, field, node, id, document }) => {
|
|
40
|
+
(0, styles_1.installCodeStyles)(document);
|
|
41
|
+
const line = field.type === 'char';
|
|
42
|
+
const element = document.createElement('div');
|
|
43
|
+
element.className = line ? 'fd-code fd-code-text fd-code-line' : 'fd-code fd-code-text';
|
|
44
|
+
element.dir = 'ltr';
|
|
45
|
+
const size = (field.type === 'char' || field.type === 'text') && field.size !== undefined ? field.size : undefined;
|
|
46
|
+
const grammar = new state_1.Compartment();
|
|
47
|
+
const editable = new state_1.Compartment();
|
|
48
|
+
const described = new state_1.Compartment();
|
|
49
|
+
/** What the form holds as text, as last written or shown: its echo of what was typed changes nothing. */
|
|
50
|
+
let known = textOf(form.getState().values[name]);
|
|
51
|
+
let writing = false;
|
|
52
|
+
let readonly = null;
|
|
53
|
+
let attributes = '';
|
|
54
|
+
const view = new view_1.EditorView({
|
|
55
|
+
parent: element,
|
|
56
|
+
state: state_1.EditorState.create({
|
|
57
|
+
doc: known,
|
|
58
|
+
extensions: [
|
|
59
|
+
line ? oneLine : (0, view_1.lineNumbers)(),
|
|
60
|
+
size !== undefined ? atMost(size) : [],
|
|
61
|
+
(0, commands_1.history)(),
|
|
62
|
+
(0, language_1.bracketMatching)(),
|
|
63
|
+
(0, language_1.indentOnInput)(),
|
|
64
|
+
(0, language_1.syntaxHighlighting)(palette_1.codeHighlightStyle),
|
|
65
|
+
grammar.of([]),
|
|
66
|
+
view_1.keymap.of([...commands_1.defaultKeymap, ...commands_1.historyKeymap]),
|
|
67
|
+
node.placeholder ? (0, view_1.placeholder)(node.placeholder) : [],
|
|
68
|
+
editable.of([]),
|
|
69
|
+
// Named by the field's label, like every other field; its state said as the form says it.
|
|
70
|
+
view_1.EditorView.contentAttributes.of({ id, 'aria-labelledby': `${id}-label` }),
|
|
71
|
+
described.of([]),
|
|
72
|
+
view_1.EditorView.updateListener.of((update) => {
|
|
73
|
+
if (!update.docChanged || writing)
|
|
74
|
+
return;
|
|
75
|
+
known = update.state.doc.toString();
|
|
76
|
+
form.setValue(name, known === '' ? null : known);
|
|
77
|
+
}),
|
|
78
|
+
],
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
// The language's grammar, once loaded; nothing if the page names none the editor knows. (An editor
|
|
82
|
+
// destroyed meanwhile takes the change quietly.)
|
|
83
|
+
void (0, languages_1.loadCodeLanguage)(node.options?.['language']).then((support) => {
|
|
84
|
+
if (support)
|
|
85
|
+
view.dispatch({ effects: grammar.reconfigure(support) });
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
element,
|
|
89
|
+
focus: () => view.focus(),
|
|
90
|
+
destroy: () => view.destroy(),
|
|
91
|
+
update(state) {
|
|
92
|
+
const effects = [];
|
|
93
|
+
if (state.readonly !== readonly) {
|
|
94
|
+
readonly = state.readonly;
|
|
95
|
+
element.toggleAttribute('data-readonly', readonly);
|
|
96
|
+
effects.push(editable.reconfigure([view_1.EditorView.editable.of(!readonly), state_1.EditorState.readOnly.of(readonly)]));
|
|
97
|
+
}
|
|
98
|
+
const said = { 'aria-invalid': String(state.invalid), 'aria-required': String(state.required), 'aria-readonly': String(state.readonly) };
|
|
99
|
+
// Read-only code is still reached by Tab, as a read-only text box is: to read it, and copy from it.
|
|
100
|
+
if (state.readonly)
|
|
101
|
+
said['tabindex'] = '0';
|
|
102
|
+
if (state.describedBy)
|
|
103
|
+
said['aria-describedby'] = state.describedBy;
|
|
104
|
+
if (JSON.stringify(said) !== attributes) {
|
|
105
|
+
attributes = JSON.stringify(said);
|
|
106
|
+
effects.push(described.reconfigure(view_1.EditorView.contentAttributes.of(said)));
|
|
107
|
+
}
|
|
108
|
+
if (effects.length)
|
|
109
|
+
view.dispatch({ effects });
|
|
110
|
+
// A value from elsewhere (loaded, discarded, set by a step) replaces the text; the echo of what was typed does not.
|
|
111
|
+
const incoming = textOf(state.value);
|
|
112
|
+
if (incoming === known)
|
|
113
|
+
return;
|
|
114
|
+
known = incoming;
|
|
115
|
+
writing = true;
|
|
116
|
+
// Shown whole, whatever its length or lines: the filters are for what is typed.
|
|
117
|
+
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: incoming }, filter: false });
|
|
118
|
+
writing = false;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
exports.textCodeWidget = textCodeWidget;
|
|
123
|
+
//# sourceMappingURL=text-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-code.js","sourceRoot":"","sources":["../../../../../libs/code/src/lib/text-code.ts"],"names":[],"mappings":";;;AAAA,mDAA6E;AAC7E,mDAA0F;AAC1F,6CAA8F;AAC9F,2CAAgF;AAGhF,2CAA+C;AAC/C,uCAA+C;AAC/C,qCAA6C;AAE7C;;;;;;;GAOG;AAEH,MAAM,MAAM,GAAG,CAAC,KAAwB,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAE1G,qGAAqG;AACrG,MAAM,OAAO,GAAc,mBAAW,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE;IACjE,IAAI,CAAC,EAAE,CAAC,UAAU,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACvD,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,MAAM,OAAO,GAAiB,EAAE,CAAC;IACjC,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;QAC1D,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACjC,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,KAAK,GAAG,IAAI,CAAC;QACrC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