@coldsmirk/inkstone-codemirror 0.8.3 → 0.10.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 +33 -3
- package/dist/context-BJzyiP0A.js +389 -0
- package/dist/index.d.ts +136 -5
- package/dist/index.js +218 -58
- package/dist/minijinja-D5ANOjtx.js +700 -0
- package/dist/sql-schema-DiPx5-bu.js +15 -0
- package/dist/sql-support-Gk7Wv9Kj.js +29 -0
- package/package.json +5 -12
- package/dist/context-BDibyUwD.cjs +0 -270
- package/dist/context-Dx6bPnKq.js +0 -235
- package/dist/index.cjs +0 -310
- package/dist/index.d.cts +0 -554
- package/dist/minijinja-DN9iLNbL.cjs +0 -357
- package/dist/minijinja-HpehSBbW.js +0 -355
package/dist/index.js
CHANGED
|
@@ -1,10 +1,77 @@
|
|
|
1
|
-
import { a as setMinijinjaContext, i as resolveMembers, n as minijinjaContextField, o as typeAtPath, r as normalizeContext } from "./context-
|
|
2
|
-
import {
|
|
1
|
+
import { a as setMinijinjaContext, i as resolveMembers, n as minijinjaContextField, o as typeAtPath, r as normalizeContext } from "./context-BJzyiP0A.js";
|
|
2
|
+
import { n as sqlSchemaField, t as setSqlSchema } from "./sql-schema-DiPx5-bu.js";
|
|
3
|
+
import { Compartment, EditorState, Transaction } from "@codemirror/state";
|
|
3
4
|
import { EditorView, drawSelection, highlightActiveLine, keymap, lineNumbers, placeholder } from "@codemirror/view";
|
|
4
5
|
import { autocompletion, closeBrackets, closeBracketsKeymap, completionKeymap } from "@codemirror/autocomplete";
|
|
5
6
|
import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
|
|
6
7
|
import { LanguageSupport, StreamLanguage, bracketMatching, codeFolding, foldGutter, foldKeymap, indentOnInput } from "@codemirror/language";
|
|
7
8
|
import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
|
|
9
|
+
import { MergeView } from "@codemirror/merge";
|
|
10
|
+
//#region src/minimal-replace.ts
|
|
11
|
+
function minimalReplace(state, externalValue) {
|
|
12
|
+
const current = state.doc;
|
|
13
|
+
const value = state.toText(externalValue);
|
|
14
|
+
if (value.eq(current)) return null;
|
|
15
|
+
const from = commonLength(current, value, 1, Math.min(current.length, value.length));
|
|
16
|
+
const suffix = commonLength(current, value, -1, Math.min(current.length - from, value.length - from));
|
|
17
|
+
const currentEnd = current.length - suffix;
|
|
18
|
+
const valueEnd = value.length - suffix;
|
|
19
|
+
return {
|
|
20
|
+
from,
|
|
21
|
+
to: currentEnd,
|
|
22
|
+
insert: value.slice(from, valueEnd)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function commonLength(a, b, direction, maximum) {
|
|
26
|
+
const aIterator = a.iter(direction);
|
|
27
|
+
const bIterator = b.iter(direction);
|
|
28
|
+
let length = 0;
|
|
29
|
+
aIterator.next();
|
|
30
|
+
bIterator.next();
|
|
31
|
+
while (length < maximum && !aIterator.done && !bIterator.done) {
|
|
32
|
+
if (aIterator.lineBreak || bIterator.lineBreak) {
|
|
33
|
+
if (aIterator.lineBreak !== bIterator.lineBreak) break;
|
|
34
|
+
length += 1;
|
|
35
|
+
aIterator.next();
|
|
36
|
+
bIterator.next();
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const available = Math.min(aIterator.value.length, bIterator.value.length, maximum - length);
|
|
40
|
+
if (aIterator.value !== bIterator.value) {
|
|
41
|
+
length += commonStringLength(aIterator.value, bIterator.value, direction, available);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
if (available < aIterator.value.length) {
|
|
45
|
+
length += available;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
length += available;
|
|
49
|
+
aIterator.next();
|
|
50
|
+
bIterator.next();
|
|
51
|
+
}
|
|
52
|
+
return length;
|
|
53
|
+
}
|
|
54
|
+
function commonStringLength(a, b, direction, maximum) {
|
|
55
|
+
let length = 0;
|
|
56
|
+
let previous = -1;
|
|
57
|
+
while (length < maximum) {
|
|
58
|
+
const aCode = a.charCodeAt(direction === 1 ? length : a.length - length - 1);
|
|
59
|
+
if (aCode !== b.charCodeAt(direction === 1 ? length : b.length - length - 1)) {
|
|
60
|
+
if (direction === 1 && isHighSurrogate(previous) || direction === -1 && isLowSurrogate(previous)) length -= 1;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
previous = aCode;
|
|
64
|
+
length += 1;
|
|
65
|
+
}
|
|
66
|
+
return length;
|
|
67
|
+
}
|
|
68
|
+
function isHighSurrogate(codeUnit) {
|
|
69
|
+
return codeUnit >= 55296 && codeUnit <= 56319;
|
|
70
|
+
}
|
|
71
|
+
function isLowSurrogate(codeUnit) {
|
|
72
|
+
return codeUnit >= 56320 && codeUnit <= 57343;
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
8
75
|
//#region src/controlled-host.ts
|
|
9
76
|
var ControlledEditorHost = class {
|
|
10
77
|
compartment = new Compartment();
|
|
@@ -16,34 +83,26 @@ var ControlledEditorHost = class {
|
|
|
16
83
|
state: EditorState.create({
|
|
17
84
|
doc,
|
|
18
85
|
extensions: [
|
|
86
|
+
minijinjaContextField,
|
|
87
|
+
sqlSchemaField,
|
|
19
88
|
...extensions,
|
|
20
89
|
this.compartment.of(dynamicExtensions),
|
|
21
90
|
EditorView.updateListener.of((update) => {
|
|
22
|
-
if (update.docChanged && !this.silent) onChange(update.state.
|
|
91
|
+
if (update.docChanged && !this.silent) onChange(update.state.sliceDoc());
|
|
23
92
|
})
|
|
24
93
|
]
|
|
25
94
|
})
|
|
26
95
|
});
|
|
27
96
|
}
|
|
28
97
|
setValue(value) {
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
const shorter = Math.min(current.length, value.length);
|
|
32
|
-
let from = 0;
|
|
33
|
-
while (from < shorter && current.codePointAt(from) === value.codePointAt(from)) from += 1;
|
|
34
|
-
let currentEnd = current.length;
|
|
35
|
-
let valueEnd = value.length;
|
|
36
|
-
while (currentEnd > from && valueEnd > from && current.codePointAt(currentEnd - 1) === value.codePointAt(valueEnd - 1)) {
|
|
37
|
-
currentEnd -= 1;
|
|
38
|
-
valueEnd -= 1;
|
|
39
|
-
}
|
|
98
|
+
const changes = minimalReplace(this.view.state, value);
|
|
99
|
+
if (!changes) return;
|
|
40
100
|
this.silent = true;
|
|
41
101
|
try {
|
|
42
|
-
this.view.dispatch({
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} });
|
|
102
|
+
this.view.dispatch({
|
|
103
|
+
changes,
|
|
104
|
+
annotations: Transaction.addToHistory.of(false)
|
|
105
|
+
});
|
|
47
106
|
} finally {
|
|
48
107
|
this.silent = false;
|
|
49
108
|
}
|
|
@@ -69,6 +128,8 @@ const searchPhrasesZhCn = EditorState.phrases.of({
|
|
|
69
128
|
close: "关闭",
|
|
70
129
|
"current match": "当前匹配",
|
|
71
130
|
"on line": "所在行",
|
|
131
|
+
"replaced $ matches": "已替换 $ 处匹配",
|
|
132
|
+
"replaced match on line $": "已替换第 $ 行的匹配",
|
|
72
133
|
"Go to line": "跳转到行",
|
|
73
134
|
go: "跳转"
|
|
74
135
|
});
|
|
@@ -96,7 +157,7 @@ function documentExtensions({ placeholder: placeholder$1, lineWrapping = false,
|
|
|
96
157
|
...completionKeymap,
|
|
97
158
|
indentWithTab
|
|
98
159
|
]),
|
|
99
|
-
placeholder(placeholder$1
|
|
160
|
+
...placeholder$1 === void 0 ? [] : [placeholder(placeholder$1)],
|
|
100
161
|
...spellcheck ? [EditorView.contentAttributes.of({ spellcheck: "true" })] : []
|
|
101
162
|
];
|
|
102
163
|
}
|
|
@@ -134,14 +195,14 @@ const loaders = {
|
|
|
134
195
|
liquid: () => import("@codemirror/lang-liquid").then((mod) => mod.liquid()),
|
|
135
196
|
wast: () => import("@codemirror/lang-wast").then((mod) => mod.wast()),
|
|
136
197
|
lezer: () => import("@codemirror/lang-lezer").then((mod) => mod.lezer()),
|
|
137
|
-
sql: () => import("@codemirror/lang-sql").then((mod) => mod.sql()),
|
|
138
|
-
mysql: () => import("@codemirror/lang-sql").then((mod) => mod.sql({ dialect: mod.MySQL })),
|
|
139
|
-
pgsql: () => import("@codemirror/lang-sql").then((mod) => mod.sql({ dialect: mod.PostgreSQL })),
|
|
140
|
-
sqlite: () => import("@codemirror/lang-sql").then((mod) => mod.sql({ dialect: mod.SQLite })),
|
|
141
|
-
mssql: () => import("@codemirror/lang-sql").then((mod) => mod.sql({ dialect: mod.MSSQL })),
|
|
142
|
-
mariadb: () => import("@codemirror/lang-sql").then((mod) => mod.sql({ dialect: mod.MariaSQL })),
|
|
143
|
-
plsql: () => import("@codemirror/lang-sql").then((mod) => mod.sql({ dialect: mod.PLSQL })),
|
|
144
|
-
cassandra: () => import("@codemirror/lang-sql").then((mod) => mod.sql({ dialect: mod.Cassandra })),
|
|
198
|
+
sql: () => Promise.all([import("./sql-support-Gk7Wv9Kj.js"), import("@codemirror/lang-sql")]).then(([schema, mod]) => schema.withSqlSchema(mod.sql(), mod.StandardSQL)),
|
|
199
|
+
mysql: () => Promise.all([import("./sql-support-Gk7Wv9Kj.js"), import("@codemirror/lang-sql")]).then(([schema, mod]) => schema.withSqlSchema(mod.sql({ dialect: mod.MySQL }), mod.MySQL)),
|
|
200
|
+
pgsql: () => Promise.all([import("./sql-support-Gk7Wv9Kj.js"), import("@codemirror/lang-sql")]).then(([schema, mod]) => schema.withSqlSchema(mod.sql({ dialect: mod.PostgreSQL }), mod.PostgreSQL)),
|
|
201
|
+
sqlite: () => Promise.all([import("./sql-support-Gk7Wv9Kj.js"), import("@codemirror/lang-sql")]).then(([schema, mod]) => schema.withSqlSchema(mod.sql({ dialect: mod.SQLite }), mod.SQLite)),
|
|
202
|
+
mssql: () => Promise.all([import("./sql-support-Gk7Wv9Kj.js"), import("@codemirror/lang-sql")]).then(([schema, mod]) => schema.withSqlSchema(mod.sql({ dialect: mod.MSSQL }), mod.MSSQL)),
|
|
203
|
+
mariadb: () => Promise.all([import("./sql-support-Gk7Wv9Kj.js"), import("@codemirror/lang-sql")]).then(([schema, mod]) => schema.withSqlSchema(mod.sql({ dialect: mod.MariaSQL }), mod.MariaSQL)),
|
|
204
|
+
plsql: () => Promise.all([import("./sql-support-Gk7Wv9Kj.js"), import("@codemirror/lang-sql")]).then(([schema, mod]) => schema.withSqlSchema(mod.sql({ dialect: mod.PLSQL }), mod.PLSQL)),
|
|
205
|
+
cassandra: () => Promise.all([import("./sql-support-Gk7Wv9Kj.js"), import("@codemirror/lang-sql")]).then(([schema, mod]) => schema.withSqlSchema(mod.sql({ dialect: mod.Cassandra }), mod.Cassandra)),
|
|
145
206
|
apl: legacy(() => import("@codemirror/legacy-modes/mode/apl").then((mod) => mod.apl)),
|
|
146
207
|
asciiarmor: legacy(() => import("@codemirror/legacy-modes/mode/asciiarmor").then((mod) => mod.asciiArmor)),
|
|
147
208
|
asn1: legacy(() => import("@codemirror/legacy-modes/mode/asn1").then((mod) => mod.asn1({}))),
|
|
@@ -262,39 +323,138 @@ const loaders = {
|
|
|
262
323
|
xu: legacy(() => import("@codemirror/legacy-modes/mode/mscgen").then((mod) => mod.xu)),
|
|
263
324
|
yacas: legacy(() => import("@codemirror/legacy-modes/mode/yacas").then((mod) => mod.yacas)),
|
|
264
325
|
z80: legacy(() => import("@codemirror/legacy-modes/mode/z80").then((mod) => mod.z80)),
|
|
265
|
-
minijinja: () => import("./minijinja-
|
|
266
|
-
"minijinja-html": () => Promise.all([import("./minijinja-
|
|
267
|
-
"minijinja-xml": () => Promise.all([import("./minijinja-
|
|
268
|
-
"minijinja-json": () => Promise.all([import("./minijinja-
|
|
269
|
-
"minijinja-yaml": () => Promise.all([import("./minijinja-
|
|
270
|
-
"minijinja-css": () => Promise.all([import("./minijinja-
|
|
271
|
-
"minijinja-scss": () => Promise.all([import("./minijinja-
|
|
272
|
-
"minijinja-sass": () => Promise.all([import("./minijinja-
|
|
273
|
-
"minijinja-less": () => Promise.all([import("./minijinja-
|
|
274
|
-
"minijinja-markdown": () => Promise.all([import("./minijinja-
|
|
275
|
-
"minijinja-sql": () => Promise.all([
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
"minijinja-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
"minijinja-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
"minijinja-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
326
|
+
minijinja: () => import("./minijinja-D5ANOjtx.js").then((mod) => mod.minijinja()),
|
|
327
|
+
"minijinja-html": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/lang-html")]).then(([mj, mod]) => mj.minijinja({ base: mod.html() })),
|
|
328
|
+
"minijinja-xml": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/lang-xml")]).then(([mj, mod]) => mj.minijinja({ base: mod.xml() })),
|
|
329
|
+
"minijinja-json": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/lang-json")]).then(([mj, mod]) => mj.minijinja({ base: mod.json() })),
|
|
330
|
+
"minijinja-yaml": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/lang-yaml")]).then(([mj, mod]) => mj.minijinja({ base: mod.yaml() })),
|
|
331
|
+
"minijinja-css": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/lang-css")]).then(([mj, mod]) => mj.minijinja({ base: mod.css() })),
|
|
332
|
+
"minijinja-scss": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/lang-sass")]).then(([mj, mod]) => mj.minijinja({ base: mod.sass() })),
|
|
333
|
+
"minijinja-sass": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/lang-sass")]).then(([mj, mod]) => mj.minijinja({ base: mod.sass({ indented: true }) })),
|
|
334
|
+
"minijinja-less": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/lang-less")]).then(([mj, mod]) => mj.minijinja({ base: mod.less() })),
|
|
335
|
+
"minijinja-markdown": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/lang-markdown")]).then(([mj, mod]) => mj.minijinja({ base: mod.markdown() })),
|
|
336
|
+
"minijinja-sql": () => Promise.all([
|
|
337
|
+
import("./minijinja-D5ANOjtx.js"),
|
|
338
|
+
import("./sql-support-Gk7Wv9Kj.js"),
|
|
339
|
+
import("@codemirror/lang-sql")
|
|
340
|
+
]).then(([mj, schema, mod]) => mj.minijinja({ base: schema.withSqlSchema(mod.sql(), mod.StandardSQL) })),
|
|
341
|
+
"minijinja-mysql": () => Promise.all([
|
|
342
|
+
import("./minijinja-D5ANOjtx.js"),
|
|
343
|
+
import("./sql-support-Gk7Wv9Kj.js"),
|
|
344
|
+
import("@codemirror/lang-sql")
|
|
345
|
+
]).then(([mj, schema, mod]) => mj.minijinja({ base: schema.withSqlSchema(mod.sql({ dialect: mod.MySQL }), mod.MySQL) })),
|
|
346
|
+
"minijinja-pgsql": () => Promise.all([
|
|
347
|
+
import("./minijinja-D5ANOjtx.js"),
|
|
348
|
+
import("./sql-support-Gk7Wv9Kj.js"),
|
|
349
|
+
import("@codemirror/lang-sql")
|
|
350
|
+
]).then(([mj, schema, mod]) => mj.minijinja({ base: schema.withSqlSchema(mod.sql({ dialect: mod.PostgreSQL }), mod.PostgreSQL) })),
|
|
351
|
+
"minijinja-sqlite": () => Promise.all([
|
|
352
|
+
import("./minijinja-D5ANOjtx.js"),
|
|
353
|
+
import("./sql-support-Gk7Wv9Kj.js"),
|
|
354
|
+
import("@codemirror/lang-sql")
|
|
355
|
+
]).then(([mj, schema, mod]) => mj.minijinja({ base: schema.withSqlSchema(mod.sql({ dialect: mod.SQLite }), mod.SQLite) })),
|
|
356
|
+
"minijinja-mssql": () => Promise.all([
|
|
357
|
+
import("./minijinja-D5ANOjtx.js"),
|
|
358
|
+
import("./sql-support-Gk7Wv9Kj.js"),
|
|
359
|
+
import("@codemirror/lang-sql")
|
|
360
|
+
]).then(([mj, schema, mod]) => mj.minijinja({ base: schema.withSqlSchema(mod.sql({ dialect: mod.MSSQL }), mod.MSSQL) })),
|
|
361
|
+
"minijinja-mariadb": () => Promise.all([
|
|
362
|
+
import("./minijinja-D5ANOjtx.js"),
|
|
363
|
+
import("./sql-support-Gk7Wv9Kj.js"),
|
|
364
|
+
import("@codemirror/lang-sql")
|
|
365
|
+
]).then(([mj, schema, mod]) => mj.minijinja({ base: schema.withSqlSchema(mod.sql({ dialect: mod.MariaSQL }), mod.MariaSQL) })),
|
|
366
|
+
"minijinja-plsql": () => Promise.all([
|
|
367
|
+
import("./minijinja-D5ANOjtx.js"),
|
|
368
|
+
import("./sql-support-Gk7Wv9Kj.js"),
|
|
369
|
+
import("@codemirror/lang-sql")
|
|
370
|
+
]).then(([mj, schema, mod]) => mj.minijinja({ base: schema.withSqlSchema(mod.sql({ dialect: mod.PLSQL }), mod.PLSQL) })),
|
|
371
|
+
"minijinja-cassandra": () => Promise.all([
|
|
372
|
+
import("./minijinja-D5ANOjtx.js"),
|
|
373
|
+
import("./sql-support-Gk7Wv9Kj.js"),
|
|
374
|
+
import("@codemirror/lang-sql")
|
|
375
|
+
]).then(([mj, schema, mod]) => mj.minijinja({ base: schema.withSqlSchema(mod.sql({ dialect: mod.Cassandra }), mod.Cassandra) })),
|
|
376
|
+
"minijinja-hive": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/sql")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.hive)) })),
|
|
377
|
+
"minijinja-sparksql": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/sql")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.sparkSQL)) })),
|
|
378
|
+
"minijinja-gql": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/sql")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.gql)) })),
|
|
379
|
+
"minijinja-gpsql": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/sql")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.gpSQL)) })),
|
|
380
|
+
"minijinja-esper": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/sql")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.esper)) })),
|
|
381
|
+
"minijinja-toml": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/toml")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.toml)) })),
|
|
382
|
+
"minijinja-ini": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/properties")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.properties)) })),
|
|
383
|
+
"minijinja-env": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/properties")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.properties)) })),
|
|
384
|
+
"minijinja-shell": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/shell")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.shell)) })),
|
|
385
|
+
"minijinja-dockerfile": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/dockerfile")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.dockerFile)) })),
|
|
386
|
+
"minijinja-nginx": () => Promise.all([import("./minijinja-D5ANOjtx.js"), import("@codemirror/legacy-modes/mode/nginx")]).then(([mj, mod]) => mj.minijinja({ base: new LanguageSupport(StreamLanguage.define(mod.nginx)) }))
|
|
294
387
|
};
|
|
295
388
|
const codeMirrorLanguages = Object.keys(loaders).toSorted();
|
|
296
389
|
function loadLanguage(language) {
|
|
297
390
|
return loaders[language]();
|
|
298
391
|
}
|
|
299
392
|
//#endregion
|
|
300
|
-
|
|
393
|
+
//#region src/merge-host.ts
|
|
394
|
+
var ControlledMergeHost = class {
|
|
395
|
+
originalCompartment = new Compartment();
|
|
396
|
+
modifiedCompartment = new Compartment();
|
|
397
|
+
silent = false;
|
|
398
|
+
view;
|
|
399
|
+
constructor(options) {
|
|
400
|
+
const { parent, original, modified, onOriginalChange, onModifiedChange, extensions = [], originalExtensions = [], modifiedExtensions = [], dynamicExtensions = [], ...mergeConfig } = options;
|
|
401
|
+
this.view = new MergeView({
|
|
402
|
+
...mergeConfig,
|
|
403
|
+
parent,
|
|
404
|
+
a: {
|
|
405
|
+
doc: original,
|
|
406
|
+
extensions: [
|
|
407
|
+
...originalExtensions,
|
|
408
|
+
minijinjaContextField,
|
|
409
|
+
sqlSchemaField,
|
|
410
|
+
...extensions,
|
|
411
|
+
this.originalCompartment.of(dynamicExtensions),
|
|
412
|
+
EditorView.updateListener.of((update) => {
|
|
413
|
+
if (update.docChanged && !this.silent) onOriginalChange?.(update.state.sliceDoc());
|
|
414
|
+
})
|
|
415
|
+
]
|
|
416
|
+
},
|
|
417
|
+
b: {
|
|
418
|
+
doc: modified,
|
|
419
|
+
extensions: [
|
|
420
|
+
...modifiedExtensions,
|
|
421
|
+
minijinjaContextField,
|
|
422
|
+
sqlSchemaField,
|
|
423
|
+
...extensions,
|
|
424
|
+
this.modifiedCompartment.of(dynamicExtensions),
|
|
425
|
+
EditorView.updateListener.of((update) => {
|
|
426
|
+
if (update.docChanged && !this.silent) onModifiedChange?.(update.state.sliceDoc());
|
|
427
|
+
})
|
|
428
|
+
]
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
reconcile(editor, value) {
|
|
433
|
+
const changes = minimalReplace(editor.state, value);
|
|
434
|
+
if (!changes) return;
|
|
435
|
+
this.silent = true;
|
|
436
|
+
try {
|
|
437
|
+
editor.dispatch({
|
|
438
|
+
changes,
|
|
439
|
+
annotations: Transaction.addToHistory.of(false)
|
|
440
|
+
});
|
|
441
|
+
} finally {
|
|
442
|
+
this.silent = false;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
setOriginal(value) {
|
|
446
|
+
this.reconcile(this.view.a, value);
|
|
447
|
+
}
|
|
448
|
+
setModified(value) {
|
|
449
|
+
this.reconcile(this.view.b, value);
|
|
450
|
+
}
|
|
451
|
+
reconfigure(dynamicExtensions) {
|
|
452
|
+
this.view.a.dispatch({ effects: this.originalCompartment.reconfigure(dynamicExtensions) });
|
|
453
|
+
this.view.b.dispatch({ effects: this.modifiedCompartment.reconfigure(dynamicExtensions) });
|
|
454
|
+
}
|
|
455
|
+
destroy() {
|
|
456
|
+
this.view.destroy();
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
//#endregion
|
|
460
|
+
export { ControlledEditorHost, ControlledMergeHost, codeMirrorLanguages, documentExtensions, loadLanguage, minijinjaContextField, normalizeContext, resolveMembers, searchPhrasesZhCn, setMinijinjaContext, setSqlSchema, sqlSchemaField, typeAtPath };
|