markdown-flow-ui 0.2.35 → 0.3.0-dev.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 +12 -0
- package/dist/_virtual/index.es10.js +2 -2
- package/dist/_virtual/index.es3.js +5 -4
- package/dist/_virtual/index.es3.js.map +1 -1
- package/dist/_virtual/index.es4.js +4 -5
- package/dist/_virtual/index.es4.js.map +1 -1
- package/dist/_virtual/index.es5.js +5 -5
- package/dist/_virtual/index.es6.js +5 -3
- package/dist/_virtual/index.es6.js.map +1 -1
- package/dist/_virtual/index.es7.js +3 -5
- package/dist/_virtual/index.es7.js.map +1 -1
- package/dist/_virtual/index.es8.js +2 -2
- package/dist/_virtual/index10.cjs +1 -1
- package/dist/_virtual/index3.cjs +1 -1
- package/dist/_virtual/index4.cjs +1 -1
- package/dist/_virtual/index5.cjs +1 -1
- package/dist/_virtual/index6.cjs +1 -1
- package/dist/_virtual/index7.cjs +1 -1
- package/dist/_virtual/index8.cjs +1 -1
- package/dist/_virtual/variable-marker.cjs +2 -0
- package/dist/_virtual/variable-marker.cjs.map +1 -0
- package/dist/_virtual/variable-marker.es.js +5 -0
- package/dist/_virtual/variable-marker.es.js.map +1 -0
- package/dist/_virtual/variable-name.cjs +2 -0
- package/dist/_virtual/variable-name.cjs.map +1 -0
- package/dist/_virtual/variable-name.es.js +5 -0
- package/dist/_virtual/variable-name.es.js.map +1 -0
- package/dist/components/ContentRender/ContentRender.cjs +2 -2
- package/dist/components/ContentRender/ContentRender.cjs.map +1 -1
- package/dist/components/ContentRender/ContentRender.es.js +206 -205
- package/dist/components/ContentRender/ContentRender.es.js.map +1 -1
- package/dist/components/ContentRender/plugins/CustomVariable.cjs +1 -1
- package/dist/components/ContentRender/plugins/CustomVariable.cjs.map +1 -1
- package/dist/components/ContentRender/plugins/CustomVariable.es.js +52 -51
- package/dist/components/ContentRender/plugins/CustomVariable.es.js.map +1 -1
- package/dist/components/ContentRender/utils/inline-code-ranges.cjs +9 -9
- package/dist/components/ContentRender/utils/inline-code-ranges.cjs.map +1 -1
- package/dist/components/ContentRender/utils/inline-code-ranges.d.ts +3 -0
- package/dist/components/ContentRender/utils/inline-code-ranges.es.js +185 -161
- package/dist/components/ContentRender/utils/inline-code-ranges.es.js.map +1 -1
- package/dist/components/ContentRender/utils/mermaid-parse.cjs +4 -4
- package/dist/components/ContentRender/utils/mermaid-parse.cjs.map +1 -1
- package/dist/components/ContentRender/utils/mermaid-parse.es.js +53 -48
- package/dist/components/ContentRender/utils/mermaid-parse.es.js.map +1 -1
- package/dist/components/ContentRender/utils/split-content.cjs +6 -6
- package/dist/components/ContentRender/utils/split-content.cjs.map +1 -1
- package/dist/components/ContentRender/utils/split-content.d.ts +1 -0
- package/dist/components/ContentRender/utils/split-content.es.js +361 -313
- package/dist/components/ContentRender/utils/split-content.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs.map +1 -1
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js +286 -290
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/components/VariableSelect.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/components/VariableSelect.cjs.map +1 -1
- package/dist/components/MarkdownFlowEditor/components/VariableSelect.es.js +62 -63
- package/dist/components/MarkdownFlowEditor/components/VariableSelect.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.es.js +1 -1
- package/dist/components/MarkdownFlowEditor/locales/de-DE.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/de-DE.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/de-DE.json.es.js +13 -13
- package/dist/components/MarkdownFlowEditor/locales/en-US.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/en-US.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/en-US.json.es.js +19 -19
- package/dist/components/MarkdownFlowEditor/locales/es-ES.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/es-ES.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/es-ES.json.es.js +13 -13
- package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.es.js +16 -16
- package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.es.js +13 -13
- package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.es.js +1 -1
- package/dist/components/MarkdownFlowEditor/locales/th-TH.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/th-TH.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/th-TH.json.es.js +1 -1
- package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.es.js +1 -1
- package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.es.js +13 -13
- package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.d.ts +1 -1
- package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.es.js +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.cjs +3 -3
- package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.cjs.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.es.js +176 -174
- package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.cjs +2 -1
- package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.cjs.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.d.ts +3 -1
- package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.es.js +38 -55
- package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.test.d.ts +1 -0
- package/dist/components/MarkdownFlowEditor/utils.cjs +1 -1
- package/dist/components/MarkdownFlowEditor/utils.cjs.map +1 -1
- package/dist/components/MarkdownFlowEditor/utils.d.ts +2 -3
- package/dist/components/MarkdownFlowEditor/utils.es.js +47 -51
- package/dist/components/MarkdownFlowEditor/utils.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/utils.variables.test.d.ts +1 -0
- package/dist/components/ui/inputGroup/textarea.cjs +1 -1
- package/dist/components/ui/inputGroup/textarea.es.js +1 -1
- package/dist/lib/interaction-defaults.cjs +1 -1
- package/dist/lib/interaction-defaults.cjs.map +1 -1
- package/dist/lib/interaction-defaults.es.js +123 -132
- package/dist/lib/interaction-defaults.es.js.map +1 -1
- package/dist/lib/interaction-defaults.failure.test.d.ts +1 -0
- package/dist/node_modules/@braintree/sanitize-url/dist/index.cjs +1 -1
- package/dist/node_modules/@braintree/sanitize-url/dist/index.es.js +1 -1
- package/dist/node_modules/classnames/index.cjs +1 -1
- package/dist/node_modules/classnames/index.es.js +1 -1
- package/dist/node_modules/cose-base/cose-base.cjs +1 -1
- package/dist/node_modules/cose-base/cose-base.cjs.map +1 -1
- package/dist/node_modules/cose-base/cose-base.es.js +1 -1
- package/dist/node_modules/cytoscape-fcose/node_modules/cose-base/cose-base.cjs +1 -1
- package/dist/node_modules/cytoscape-fcose/node_modules/cose-base/cose-base.cjs.map +1 -1
- package/dist/node_modules/cytoscape-fcose/node_modules/cose-base/cose-base.es.js +1 -1
- package/dist/node_modules/cytoscape-fcose/node_modules/layout-base/layout-base.cjs +1 -1
- package/dist/node_modules/cytoscape-fcose/node_modules/layout-base/layout-base.cjs.map +1 -1
- package/dist/node_modules/cytoscape-fcose/node_modules/layout-base/layout-base.es.js +1 -1
- package/dist/node_modules/hast-util-to-jsx-runtime/lib/index.cjs +1 -1
- package/dist/node_modules/hast-util-to-jsx-runtime/lib/index.es.js +1 -1
- package/dist/node_modules/layout-base/layout-base.cjs +1 -1
- package/dist/node_modules/layout-base/layout-base.cjs.map +1 -1
- package/dist/node_modules/layout-base/layout-base.es.js +1 -1
- package/dist/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-AAMF2YG6.cjs +1 -1
- package/dist/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-AAMF2YG6.es.js +1 -1
- package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-OMD6QJNC.cjs +1 -1
- package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-OMD6QJNC.es.js +1 -1
- package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-U37J5Y7L.cjs +1 -1
- package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-U37J5Y7L.es.js +1 -1
- package/dist/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-WV7ZQ7D5.cjs +1 -1
- package/dist/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-WV7ZQ7D5.es.js +1 -1
- package/dist/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-4MX5Z3NR.cjs +1 -1
- package/dist/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-4MX5Z3NR.es.js +1 -1
- package/dist/node_modules/rc-input/es/BaseInput.cjs +1 -1
- package/dist/node_modules/rc-input/es/BaseInput.es.js +1 -1
- package/dist/node_modules/rc-textarea/es/ResizableTextArea.cjs +1 -1
- package/dist/node_modules/rc-textarea/es/ResizableTextArea.es.js +1 -1
- package/dist/node_modules/rc-textarea/es/TextArea.cjs +1 -1
- package/dist/node_modules/rc-textarea/es/TextArea.es.js +1 -1
- package/dist/node_modules/rc-textarea/es/index.cjs +1 -1
- package/dist/node_modules/rc-textarea/es/index.es.js +1 -1
- package/dist/node_modules/remark-flow/dist/escaping.cjs +2 -2
- package/dist/node_modules/remark-flow/dist/escaping.cjs.map +1 -1
- package/dist/node_modules/remark-flow/dist/escaping.es.js +128 -63
- package/dist/node_modules/remark-flow/dist/escaping.es.js.map +1 -1
- package/dist/node_modules/remark-flow/dist/index.cjs +1 -1
- package/dist/node_modules/remark-flow/dist/index.cjs.map +1 -1
- package/dist/node_modules/remark-flow/dist/index.es.js +62 -33
- package/dist/node_modules/remark-flow/dist/index.es.js.map +1 -1
- package/dist/node_modules/remark-flow/dist/interaction-parser.cjs +1 -1
- package/dist/node_modules/remark-flow/dist/interaction-parser.cjs.map +1 -1
- package/dist/node_modules/remark-flow/dist/interaction-parser.es.js +260 -256
- package/dist/node_modules/remark-flow/dist/interaction-parser.es.js.map +1 -1
- package/dist/node_modules/remark-flow/dist/interaction-plugin-core.cjs +1 -1
- package/dist/node_modules/remark-flow/dist/interaction-plugin-core.cjs.map +1 -1
- package/dist/node_modules/remark-flow/dist/interaction-plugin-core.es.js +71 -42
- package/dist/node_modules/remark-flow/dist/interaction-plugin-core.es.js.map +1 -1
- package/dist/node_modules/remark-flow/dist/interaction-syntax.cjs +1 -1
- package/dist/node_modules/remark-flow/dist/interaction-syntax.cjs.map +1 -1
- package/dist/node_modules/remark-flow/dist/interaction-syntax.es.js +500 -46
- package/dist/node_modules/remark-flow/dist/interaction-syntax.es.js.map +1 -1
- package/dist/node_modules/remark-flow/dist/variable-marker.cjs +2 -0
- package/dist/node_modules/remark-flow/dist/variable-marker.cjs.map +1 -0
- package/dist/node_modules/remark-flow/dist/variable-marker.es.js +77 -0
- package/dist/node_modules/remark-flow/dist/variable-marker.es.js.map +1 -0
- package/dist/node_modules/remark-flow/dist/variable-name.cjs +15 -0
- package/dist/node_modules/remark-flow/dist/variable-name.cjs.map +1 -0
- package/dist/node_modules/remark-flow/dist/variable-name.es.js +748 -0
- package/dist/node_modules/remark-flow/dist/variable-name.es.js.map +1 -0
- package/dist/node_modules/style-to-object/cjs/index.cjs +1 -1
- package/dist/node_modules/style-to-object/cjs/index.cjs.map +1 -1
- package/dist/node_modules/style-to-object/cjs/index.es.js +1 -1
- package/dist/node_modules/unified/lib/index.cjs +1 -1
- package/dist/node_modules/unified/lib/index.es.js +1 -1
- package/package.json +2 -2
|
@@ -1,213 +1,215 @@
|
|
|
1
|
-
import { ViewPlugin as
|
|
2
|
-
import { RangeSetBuilder as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
const
|
|
6
|
-
|
|
1
|
+
import { ViewPlugin as B, Decoration as H } from "../../../node_modules/@codemirror/view/dist/index.es.js";
|
|
2
|
+
import { RangeSetBuilder as P } from "../../../node_modules/@codemirror/state/dist/index.es.js";
|
|
3
|
+
import { getMarkdownSourceAnalysis as L } from "../../ContentRender/utils/inline-code-ranges.es.js";
|
|
4
|
+
import { d as N } from "../../../_virtual/index.es.js";
|
|
5
|
+
const F = /<!--[\s\S]*?-->/g, W = (n) => {
|
|
6
|
+
const i = N.findVariableMarkers(n), f = n.indexOf("{{", i.at(-1)?.end ?? 0);
|
|
7
|
+
return f === -1 ? i : [...i, { start: f, end: n.length, name: null }];
|
|
8
|
+
}, M = new RegExp(
|
|
9
|
+
`\\?\\[(${N.INTERACTION_CONTENT_SOURCE})\\](?!\\()`,
|
|
7
10
|
"g"
|
|
8
|
-
);
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
let
|
|
12
|
-
for (;
|
|
13
|
-
const
|
|
14
|
-
`,
|
|
15
|
-
if (
|
|
16
|
-
from:
|
|
17
|
-
to:
|
|
11
|
+
), _ = (n) => L(n).interactions;
|
|
12
|
+
function U(n, i) {
|
|
13
|
+
const f = [];
|
|
14
|
+
let l = null, s = 0;
|
|
15
|
+
for (; s <= n.length; ) {
|
|
16
|
+
const u = n.indexOf(`
|
|
17
|
+
`, s), e = u === -1 ? n.length : u;
|
|
18
|
+
if (n.slice(s, e).trim() === "!===" && !i(s) && (l === null ? l = s : (f.push({
|
|
19
|
+
from: l,
|
|
20
|
+
to: e,
|
|
18
21
|
className: "syntax-fixed"
|
|
19
|
-
}),
|
|
22
|
+
}), l = null)), u === -1)
|
|
20
23
|
break;
|
|
21
|
-
|
|
24
|
+
s = u + 1;
|
|
22
25
|
}
|
|
23
|
-
return
|
|
26
|
+
return f;
|
|
24
27
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
let
|
|
28
|
-
const
|
|
29
|
-
for (;
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
return !!
|
|
28
|
+
function $(n, i, f) {
|
|
29
|
+
const l = [];
|
|
30
|
+
let s = 0;
|
|
31
|
+
const u = (t) => {
|
|
32
|
+
for (; s < i.length && i[s].to <= t; )
|
|
33
|
+
s++;
|
|
34
|
+
const r = i[s];
|
|
35
|
+
return !!r && t >= r.from && t < r.to;
|
|
33
36
|
};
|
|
34
|
-
let
|
|
35
|
-
for (;
|
|
36
|
-
const
|
|
37
|
-
`,
|
|
38
|
-
let
|
|
39
|
-
for (;
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
37
|
+
let e = 0;
|
|
38
|
+
for (; e <= n.length; ) {
|
|
39
|
+
const t = n.indexOf(`
|
|
40
|
+
`, e), r = t === -1 ? n.length : t, d = n.slice(e, r), x = [];
|
|
41
|
+
let g = 0;
|
|
42
|
+
for (; g < d.length; ) {
|
|
43
|
+
const c = d.indexOf("===", g);
|
|
44
|
+
if (c === -1)
|
|
42
45
|
break;
|
|
43
|
-
const
|
|
44
|
-
!(
|
|
46
|
+
const p = e + c;
|
|
47
|
+
!(p > 0 && n[p - 1] === "!") && !u(p) && !f(p) && x.push(p), g = c + 3;
|
|
45
48
|
}
|
|
46
|
-
for (let
|
|
47
|
-
|
|
48
|
-
from:
|
|
49
|
-
to:
|
|
49
|
+
for (let c = 0; c + 1 < x.length; c += 2)
|
|
50
|
+
l.push({
|
|
51
|
+
from: x[c],
|
|
52
|
+
to: x[c + 1] + 3,
|
|
50
53
|
className: "syntax-fixed"
|
|
51
54
|
});
|
|
52
|
-
if (
|
|
55
|
+
if (t === -1)
|
|
53
56
|
break;
|
|
54
|
-
|
|
57
|
+
e = t + 1;
|
|
55
58
|
}
|
|
56
|
-
return
|
|
59
|
+
return l;
|
|
57
60
|
}
|
|
58
|
-
function
|
|
59
|
-
const
|
|
60
|
-
let
|
|
61
|
-
for (
|
|
62
|
-
l.push({
|
|
63
|
-
from:
|
|
64
|
-
to:
|
|
61
|
+
function j(n, i) {
|
|
62
|
+
const f = [];
|
|
63
|
+
let l;
|
|
64
|
+
for (F.lastIndex = 0; (l = F.exec(n)) !== null; )
|
|
65
|
+
i(l.index) || f.push({
|
|
66
|
+
from: l.index,
|
|
67
|
+
to: l.index + l[0].length,
|
|
65
68
|
className: "syntax-comment"
|
|
66
69
|
});
|
|
67
|
-
return
|
|
70
|
+
return f;
|
|
68
71
|
}
|
|
69
|
-
function
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
function q(n) {
|
|
73
|
+
const i = N.findDocumentVariableMarkers(n), f = (e) => i.some(
|
|
74
|
+
(t) => e >= t.start && e < t.end
|
|
75
|
+
), l = j(n, f), s = [
|
|
76
|
+
...U(n, f),
|
|
77
|
+
...$(
|
|
78
|
+
n,
|
|
79
|
+
l,
|
|
80
|
+
f
|
|
81
|
+
),
|
|
73
82
|
...l
|
|
74
|
-
].sort((
|
|
75
|
-
for (const
|
|
76
|
-
const
|
|
77
|
-
(!
|
|
83
|
+
].sort((e, t) => e.from !== t.from ? e.from - t.from : t.to - e.to), u = [];
|
|
84
|
+
for (const e of s) {
|
|
85
|
+
const t = u[u.length - 1];
|
|
86
|
+
(!t || e.from >= t.to) && u.push(e);
|
|
78
87
|
}
|
|
79
|
-
return
|
|
88
|
+
return u;
|
|
80
89
|
}
|
|
81
|
-
function
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}), g += t.length;
|
|
90
|
+
function z(n, i = () => !1) {
|
|
91
|
+
const f = [], l = N.findDocumentVariableMarkers(n), s = [];
|
|
92
|
+
M.lastIndex = 0;
|
|
93
|
+
const u = (t, r) => s.some((d) => !(r <= d.from || t >= d.to)), e = (t, r, d) => t >= r || u(t, r) ? !1 : (s.push({ from: t, to: r }), f.push({ from: t, to: r, className: d }), !0);
|
|
94
|
+
for (const t of q(n))
|
|
95
|
+
e(t.from, t.to, t.className);
|
|
96
|
+
for (const t of _(n)) {
|
|
97
|
+
M.lastIndex = t.start;
|
|
98
|
+
const r = M.exec(n);
|
|
99
|
+
if (!r || r.index !== t.start || r.index + r[0].length !== t.end)
|
|
100
|
+
continue;
|
|
101
|
+
const d = r.index, x = r.index + r[0].length, g = r[1], c = d + 2;
|
|
102
|
+
if (u(d, x) || l.some(
|
|
103
|
+
(b) => b.start <= d && d < b.end
|
|
104
|
+
))
|
|
105
|
+
continue;
|
|
106
|
+
e(d, d + 1, "syntax-keyword"), e(d + 1, d + 2, "syntax-bracket"), e(x - 1, x, "syntax-bracket");
|
|
107
|
+
const p = W(g), y = p[0], O = y ? y.start - 1 : -1, E = O >= 0 && g[O] === "%" && N.trimVariablePadding(g.slice(0, O)) === "";
|
|
108
|
+
if (g.startsWith("%") || E) {
|
|
109
|
+
let b = "syntax-percent-invalid";
|
|
110
|
+
if (y && E) {
|
|
111
|
+
const o = c + y.start, h = c + y.end, I = i(o, h);
|
|
112
|
+
b = y.name !== null && !I ? "syntax-percent-valid" : "syntax-percent-invalid";
|
|
113
|
+
}
|
|
114
|
+
const v = c + (E ? O : 0);
|
|
115
|
+
e(v, v + 1, b);
|
|
116
|
+
const V = [], R = [], S = [];
|
|
117
|
+
for (const o of p)
|
|
118
|
+
R.push({
|
|
119
|
+
from: c + o.start,
|
|
120
|
+
to: c + o.end,
|
|
121
|
+
className: o.name === null ? "syntax-variable-invalid" : "syntax-variable"
|
|
122
|
+
});
|
|
123
|
+
let m = 0;
|
|
124
|
+
for (; m < g.length; ) {
|
|
125
|
+
const o = R.find(
|
|
126
|
+
(I) => c + m === I.from
|
|
127
|
+
);
|
|
128
|
+
if (o) {
|
|
129
|
+
m = o.to - c;
|
|
130
|
+
continue;
|
|
123
131
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const t = p[0], d = h(t);
|
|
128
|
-
w.push({
|
|
129
|
-
from: a + p.index,
|
|
130
|
-
to: a + p.index + t.length,
|
|
131
|
-
className: d.className
|
|
132
|
-
});
|
|
132
|
+
if (N.isEscape(g, m)) {
|
|
133
|
+
m += 2;
|
|
134
|
+
continue;
|
|
133
135
|
}
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
})),
|
|
139
|
-
...w.map((t) => ({
|
|
140
|
-
...t,
|
|
141
|
-
className: t.className
|
|
142
|
-
}))
|
|
143
|
-
].sort((t, d) => t.from !== d.from ? t.from - d.from : t.to - d.to);
|
|
144
|
-
for (const t of N)
|
|
145
|
-
t.className.startsWith("syntax-variable") && l(t.from, t.to) || n(t.from, t.to, t.className) && k.push({ from: t.from, to: t.to });
|
|
146
|
-
const C = a + 1, S = r - 1;
|
|
147
|
-
let v = C;
|
|
148
|
-
const F = k.sort((t, d) => t.from !== d.from ? t.from - d.from : t.to - d.to);
|
|
149
|
-
for (const t of F)
|
|
150
|
-
v < t.from && n(v, t.from, "syntax-string"), v = Math.max(v, t.to);
|
|
151
|
-
v < S && n(v, S, "syntax-string");
|
|
152
|
-
} else {
|
|
153
|
-
const x = [], y = [];
|
|
154
|
-
let b;
|
|
155
|
-
const R = /\{\{.*?\}\}/g;
|
|
156
|
-
for (; (b = R.exec(u)) !== null; ) {
|
|
157
|
-
const i = b[0], N = h(i);
|
|
158
|
-
x.push({
|
|
159
|
-
from: a + b.index,
|
|
160
|
-
to: a + b.index + i.length,
|
|
161
|
-
className: N.className
|
|
162
|
-
});
|
|
136
|
+
const h = g.startsWith("||", m) ? "||" : g[m] === "|" ? "|" : g.startsWith("...", m) ? "..." : null;
|
|
137
|
+
if (!h) {
|
|
138
|
+
m += 1;
|
|
139
|
+
continue;
|
|
163
140
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
let p = k;
|
|
169
|
-
for (const i of y)
|
|
170
|
-
p < i.from && n(p, i.from, "syntax-button-text"), p = Math.max(p, i.to);
|
|
171
|
-
p < g && n(p, g, "syntax-button-text");
|
|
141
|
+
V.push({
|
|
142
|
+
from: c + m,
|
|
143
|
+
to: c + m + h.length
|
|
144
|
+
}), m += h.length;
|
|
172
145
|
}
|
|
146
|
+
const a = [
|
|
147
|
+
...V.map((o) => ({
|
|
148
|
+
...o,
|
|
149
|
+
className: "syntax-keyword"
|
|
150
|
+
})),
|
|
151
|
+
...R.map((o) => ({
|
|
152
|
+
...o,
|
|
153
|
+
className: o.className
|
|
154
|
+
}))
|
|
155
|
+
].sort((o, h) => o.from !== h.from ? o.from - h.from : o.to - h.to);
|
|
156
|
+
for (const o of a)
|
|
157
|
+
o.className.startsWith("syntax-variable") && i(o.from, o.to) || e(o.from, o.to, o.className) && S.push({ from: o.from, to: o.to });
|
|
158
|
+
const w = v + 1, C = x - 1;
|
|
159
|
+
let k = w;
|
|
160
|
+
const D = S.sort((o, h) => o.from !== h.from ? o.from - h.from : o.to - h.to);
|
|
161
|
+
for (const o of D)
|
|
162
|
+
k < o.from && e(k, o.from, "syntax-string"), k = Math.max(k, o.to);
|
|
163
|
+
k < C && e(k, C, "syntax-string");
|
|
164
|
+
} else {
|
|
165
|
+
const b = [], v = [];
|
|
166
|
+
for (const a of W(g))
|
|
167
|
+
b.push({
|
|
168
|
+
from: c + a.start,
|
|
169
|
+
to: c + a.end,
|
|
170
|
+
className: a.name === null ? "syntax-variable-invalid" : "syntax-variable"
|
|
171
|
+
});
|
|
172
|
+
const V = b.sort((a, w) => a.from !== w.from ? a.from - w.from : a.to - w.to);
|
|
173
|
+
for (const a of V)
|
|
174
|
+
a.className.startsWith("syntax-variable") && i(a.from, a.to) || e(a.from, a.to, a.className) && v.push({ from: a.from, to: a.to });
|
|
175
|
+
const R = c, S = x - 1;
|
|
176
|
+
let m = R;
|
|
177
|
+
for (const a of v)
|
|
178
|
+
m < a.from && e(m, a.from, "syntax-button-text"), m = Math.max(m, a.to);
|
|
179
|
+
m < S && e(m, S, "syntax-button-text");
|
|
180
|
+
}
|
|
173
181
|
}
|
|
174
|
-
for (
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
m.index,
|
|
178
|
-
m.index + m[0].length,
|
|
179
|
-
r.className
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
return c.sort((o, r) => o.from !== r.from ? o.from - r.from : r.to - o.to), c;
|
|
182
|
+
for (const t of l)
|
|
183
|
+
t.name !== null && !i(t.start, t.end) && e(t.start, t.end, "syntax-variable");
|
|
184
|
+
return f.sort((t, r) => t.from !== r.from ? t.from - r.from : r.to - t.to), f;
|
|
183
185
|
}
|
|
184
|
-
function
|
|
185
|
-
const
|
|
186
|
-
for (const s of
|
|
186
|
+
function A(n) {
|
|
187
|
+
const i = new P(), f = n.state.doc.toString(), l = z(f, (s, u) => n.state.selection.ranges.some((e) => e.from >= s && e.to <= u));
|
|
188
|
+
for (const s of l)
|
|
187
189
|
if (s.from < s.to)
|
|
188
190
|
try {
|
|
189
|
-
|
|
190
|
-
} catch (
|
|
191
|
-
console.warn("SyntaxHighlighter: Failed to add decoration", s,
|
|
191
|
+
i.add(s.from, s.to, H.mark({ class: s.className }));
|
|
192
|
+
} catch (u) {
|
|
193
|
+
console.warn("SyntaxHighlighter: Failed to add decoration", s, u);
|
|
192
194
|
}
|
|
193
|
-
return
|
|
195
|
+
return i.finish();
|
|
194
196
|
}
|
|
195
|
-
const
|
|
197
|
+
const T = B.fromClass(
|
|
196
198
|
class {
|
|
197
|
-
constructor(
|
|
198
|
-
this.decorations =
|
|
199
|
+
constructor(n) {
|
|
200
|
+
this.decorations = A(n);
|
|
199
201
|
}
|
|
200
|
-
update(
|
|
201
|
-
(
|
|
202
|
+
update(n) {
|
|
203
|
+
(n.docChanged || n.viewportChanged || n.selectionSet) && (this.decorations = A(n.view));
|
|
202
204
|
}
|
|
203
205
|
},
|
|
204
206
|
{
|
|
205
|
-
decorations: (
|
|
207
|
+
decorations: (n) => n.decorations
|
|
206
208
|
}
|
|
207
209
|
);
|
|
208
210
|
export {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
211
|
+
q as collectOuterBlockRanges,
|
|
212
|
+
z as collectSyntaxHighlightRanges,
|
|
213
|
+
T as default
|
|
212
214
|
};
|
|
213
215
|
//# sourceMappingURL=SyntaxHighlighter.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyntaxHighlighter.es.js","sources":["../../../../src/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.ts"],"sourcesContent":["import {\n Decoration,\n DecorationSet,\n EditorView,\n ViewPlugin,\n ViewUpdate,\n} from \"@codemirror/view\";\nimport { RangeSetBuilder } from \"@codemirror/state\";\nimport { INTERACTION_CONTENT_SOURCE, isEscape } from \"remark-flow\";\n\nimport { createVariableExpressionRegexp } from \"../utils\";\n\nconst broadVariableRegex = /\\{\\{.*?\\}\\}/g;\nconst commentRegex = /<!--[\\s\\S]*?-->/g;\n// The grammar's own definition of where an interaction ends, so a `\\]` an option escaped does\n// not cut the highlight short, and the same `(?!\\()` the parser uses, so `?[text](url)` stays a\n// markdown link. Taken from remark-flow rather than written again here: the editor and the\n// parser have to agree about what they are looking at.\nconst controlBlockRegex = new RegExp(\n `\\\\?\\\\[(${INTERACTION_CONTENT_SOURCE})\\\\](?!\\\\()`,\n \"g\"\n);\n\nexport interface SyntaxHighlightRange {\n from: number;\n to: number;\n className: string;\n}\n\nfunction collectMultilineFixedOutputRanges(\n docText: string\n): SyntaxHighlightRange[] {\n const ranges: SyntaxHighlightRange[] = [];\n let pendingStart: number | null = null;\n let lineStart = 0;\n\n while (lineStart <= docText.length) {\n const newlineIndex = docText.indexOf(\"\\n\", lineStart);\n const lineEnd = newlineIndex === -1 ? docText.length : newlineIndex;\n const lineText = docText.slice(lineStart, lineEnd);\n\n if (lineText.trim() === \"!===\") {\n if (pendingStart === null) {\n pendingStart = lineStart;\n } else {\n ranges.push({\n from: pendingStart,\n to: lineEnd,\n className: \"syntax-fixed\",\n });\n pendingStart = null;\n }\n }\n\n if (newlineIndex === -1) {\n break;\n }\n\n lineStart = newlineIndex + 1;\n }\n\n return ranges;\n}\n\nfunction collectSingleLineFixedOutputRanges(\n docText: string,\n commentRanges: SyntaxHighlightRange[]\n): SyntaxHighlightRange[] {\n const ranges: SyntaxHighlightRange[] = [];\n let commentIndex = 0;\n\n const isInsideComment = (index: number) => {\n while (\n commentIndex < commentRanges.length &&\n commentRanges[commentIndex].to <= index\n ) {\n commentIndex++;\n }\n\n const range = commentRanges[commentIndex];\n return !!range && index >= range.from && index < range.to;\n };\n\n let lineStart = 0;\n while (lineStart <= docText.length) {\n const newlineIndex = docText.indexOf(\"\\n\", lineStart);\n const lineEnd = newlineIndex === -1 ? docText.length : newlineIndex;\n const lineText = docText.slice(lineStart, lineEnd);\n const markerPositions: number[] = [];\n let searchFrom = 0;\n\n while (searchFrom < lineText.length) {\n const markerOffset = lineText.indexOf(\"===\", searchFrom);\n if (markerOffset === -1) {\n break;\n }\n\n const markerIndex = lineStart + markerOffset;\n const isNegated = markerIndex > 0 && docText[markerIndex - 1] === \"!\";\n if (!isNegated && !isInsideComment(markerIndex)) {\n markerPositions.push(markerIndex);\n }\n\n searchFrom = markerOffset + 3;\n }\n\n for (let i = 0; i + 1 < markerPositions.length; i += 2) {\n ranges.push({\n from: markerPositions[i],\n to: markerPositions[i + 1] + 3,\n className: \"syntax-fixed\",\n });\n }\n\n if (newlineIndex === -1) {\n break;\n }\n\n lineStart = newlineIndex + 1;\n }\n\n return ranges;\n}\n\nfunction collectCommentRanges(docText: string): SyntaxHighlightRange[] {\n const ranges: SyntaxHighlightRange[] = [];\n let match;\n\n commentRegex.lastIndex = 0;\n while ((match = commentRegex.exec(docText)) !== null) {\n ranges.push({\n from: match.index,\n to: match.index + match[0].length,\n className: \"syntax-comment\",\n });\n }\n\n return ranges;\n}\n\n/**\n * Collects non-overlapping fixed-output and comment wrapper ranges.\n *\n * @param docText - Document text to scan.\n * @returns Outer syntax highlight ranges sorted by document position.\n */\nexport function collectOuterBlockRanges(\n docText: string\n): SyntaxHighlightRange[] {\n const commentRanges = collectCommentRanges(docText);\n const blockRanges = [\n ...collectMultilineFixedOutputRanges(docText),\n ...collectSingleLineFixedOutputRanges(docText, commentRanges),\n ...commentRanges,\n ].sort((a, b) => {\n if (a.from !== b.from) return a.from - b.from;\n return b.to - a.to;\n });\n\n const outerRanges: SyntaxHighlightRange[] = [];\n\n for (const range of blockRanges) {\n const lastOuter = outerRanges[outerRanges.length - 1];\n if (!lastOuter || range.from >= lastOuter.to) {\n outerRanges.push(range);\n }\n }\n\n return outerRanges;\n}\n\n/**\n * Collects all custom syntax highlight ranges for editor decorations.\n *\n * @param docText - Document text to scan.\n * @param isCursorInside - Returns true when the current cursor is inside a range.\n * @returns Non-overlapping syntax highlight ranges sorted by document position.\n */\nexport function collectSyntaxHighlightRanges(\n docText: string,\n isCursorInside: (from: number, to: number) => boolean = () => false\n): SyntaxHighlightRange[] {\n const matches: SyntaxHighlightRange[] = [];\n const occupied: { from: number; to: number }[] = [];\n\n controlBlockRegex.lastIndex = 0;\n\n // Prevent overlapping decorations so styling stays deterministic\n const isOverlapping = (from: number, to: number) =>\n occupied.some((range) => !(to <= range.from || from >= range.to));\n\n const addMatch = (from: number, to: number, className: string) => {\n if (from >= to) return false;\n if (isOverlapping(from, to)) return false;\n occupied.push({ from, to });\n matches.push({ from, to, className });\n return true;\n };\n\n const classifyVariable = (raw: string) => {\n const inner = raw.slice(2, -2).trim();\n if (!inner) return { className: \"syntax-variable-invalid\", valid: false };\n const strict = createVariableExpressionRegexp();\n const strictMatch = strict.exec(raw);\n const valid =\n !!strictMatch && strictMatch.index === 0 && strictMatch[0] === raw;\n return {\n className: valid ? \"syntax-variable\" : \"syntax-variable-invalid\",\n valid,\n };\n };\n\n let match;\n\n // 1. Outer block ranges win over any syntax inside them.\n for (const range of collectOuterBlockRanges(docText)) {\n addMatch(range.from, range.to, range.className);\n }\n\n // 2. Control Blocks\n while ((match = controlBlockRegex.exec(docText)) !== null) {\n const fullStart = match.index;\n const fullEnd = match.index + match[0].length;\n const content = match[1];\n const contentStart = fullStart + 2; // after ?[\n if (isOverlapping(fullStart, fullEnd)) {\n continue;\n }\n\n // Outer brackets and question mark\n addMatch(fullStart, fullStart + 1, \"syntax-keyword\"); // ?\n addMatch(fullStart + 1, fullStart + 2, \"syntax-bracket\"); // [\n addMatch(fullEnd - 1, fullEnd, \"syntax-bracket\"); // ]\n\n if (content.startsWith(\"%\")) {\n // Input / Select\n const contentVariableRegex = /\\{\\{.*?\\}\\}/g;\n const firstVariableMatch = contentVariableRegex.exec(content);\n contentVariableRegex.lastIndex = 0;\n let percentClass = \"syntax-percent-invalid\";\n if (firstVariableMatch) {\n const classification = classifyVariable(firstVariableMatch[0]);\n const varFrom = contentStart + firstVariableMatch.index;\n const varTo = varFrom + firstVariableMatch[0].length;\n const cursorInsideVar = isCursorInside(varFrom, varTo);\n percentClass =\n classification.valid && !cursorInsideVar\n ? \"syntax-percent-valid\"\n : \"syntax-percent-invalid\";\n }\n addMatch(contentStart, contentStart + 1, percentClass); // %\n\n const operatorRanges: { from: number; to: number }[] = [];\n const variableRanges: { from: number; to: number; className: string }[] =\n [];\n const appliedTokenRanges: { from: number; to: number }[] = [];\n\n // Inner operators | || ... -- skipping any an option escaped, the way the parser does.\n // Painted as separators, they told the author the grammar had split an option that it\n // had in fact left whole.\n let scanIndex = 0;\n while (scanIndex < content.length) {\n if (isEscape(content, scanIndex)) {\n scanIndex += 2;\n continue;\n }\n const operator = content.startsWith(\"||\", scanIndex)\n ? \"||\"\n : content[scanIndex] === \"|\"\n ? \"|\"\n : content.startsWith(\"...\", scanIndex)\n ? \"...\"\n : null;\n if (!operator) {\n scanIndex += 1;\n continue;\n }\n operatorRanges.push({\n from: contentStart + scanIndex,\n to: contentStart + scanIndex + operator.length,\n });\n scanIndex += operator.length;\n }\n\n // Variables inside control block content\n let innerVariableMatch;\n const innerVariableRegex = /\\{\\{.*?\\}\\}/g;\n while ((innerVariableMatch = innerVariableRegex.exec(content)) !== null) {\n const rawVariable = innerVariableMatch[0];\n const classification = classifyVariable(rawVariable);\n variableRanges.push({\n from: contentStart + innerVariableMatch.index,\n to: contentStart + innerVariableMatch.index + rawVariable.length,\n className: classification.className,\n });\n }\n\n const allTokens = [\n ...operatorRanges.map((range) => ({\n ...range,\n className: \"syntax-keyword\",\n })),\n ...variableRanges.map((range) => ({\n ...range,\n className: range.className,\n })),\n ].sort((a, b) => {\n if (a.from !== b.from) return a.from - b.from;\n return a.to - b.to;\n });\n\n for (const token of allTokens) {\n if (\n token.className.startsWith(\"syntax-variable\") &&\n isCursorInside(token.from, token.to)\n ) {\n continue;\n }\n if (addMatch(token.from, token.to, token.className)) {\n appliedTokenRanges.push({ from: token.from, to: token.to });\n }\n }\n\n // Content (Dark Blue) for remaining text segments\n const stringStart = contentStart + 1;\n const stringEnd = fullEnd - 1;\n let cursor = stringStart;\n const sortedApplied = appliedTokenRanges.sort((a, b) => {\n if (a.from !== b.from) return a.from - b.from;\n return a.to - b.to;\n });\n\n for (const token of sortedApplied) {\n if (cursor < token.from) {\n addMatch(cursor, token.from, \"syntax-string\");\n }\n cursor = Math.max(cursor, token.to);\n }\n if (cursor < stringEnd) {\n addMatch(cursor, stringEnd, \"syntax-string\");\n }\n } else {\n // Button ?[text]\n const variableRanges: { from: number; to: number; className: string }[] =\n [];\n const appliedVariableRanges: { from: number; to: number }[] = [];\n\n let innerVariableMatch;\n const innerVariableRegex = /\\{\\{.*?\\}\\}/g;\n while ((innerVariableMatch = innerVariableRegex.exec(content)) !== null) {\n const rawVariable = innerVariableMatch[0];\n const classification = classifyVariable(rawVariable);\n variableRanges.push({\n from: contentStart + innerVariableMatch.index,\n to: contentStart + innerVariableMatch.index + rawVariable.length,\n className: classification.className,\n });\n }\n\n const sortedVariables = variableRanges.sort((a, b) => {\n if (a.from !== b.from) return a.from - b.from;\n return a.to - b.to;\n });\n\n for (const variable of sortedVariables) {\n if (\n variable.className.startsWith(\"syntax-variable\") &&\n isCursorInside(variable.from, variable.to)\n ) {\n continue;\n }\n if (addMatch(variable.from, variable.to, variable.className)) {\n appliedVariableRanges.push({ from: variable.from, to: variable.to });\n }\n }\n\n const buttonTextStart = contentStart;\n const buttonTextEnd = fullEnd - 1;\n let cursor = buttonTextStart;\n\n for (const variable of appliedVariableRanges) {\n if (cursor < variable.from) {\n addMatch(cursor, variable.from, \"syntax-button-text\");\n }\n cursor = Math.max(cursor, variable.to);\n }\n if (cursor < buttonTextEnd) {\n addMatch(cursor, buttonTextEnd, \"syntax-button-text\");\n }\n }\n }\n\n // 3. Variables (only if not already decorated; invalid ones stay default outside control blocks)\n broadVariableRegex.lastIndex = 0;\n while ((match = broadVariableRegex.exec(docText)) !== null) {\n const text = match[0];\n const classification = classifyVariable(text);\n if (\n classification.valid &&\n !isCursorInside(match.index, match.index + match[0].length)\n ) {\n addMatch(\n match.index,\n match.index + match[0].length,\n classification.className\n );\n }\n }\n\n // Sort matches by 'from' asc, then 'to' desc (longest first)\n matches.sort((a, b) => {\n if (a.from !== b.from) return a.from - b.from;\n return b.to - a.to;\n });\n\n return matches;\n}\n\nfunction buildDecorations(view: EditorView): DecorationSet {\n const builder = new RangeSetBuilder<Decoration>();\n const docText = view.state.doc.toString();\n const matches = collectSyntaxHighlightRanges(docText, (from, to) => {\n return view.state.selection.ranges.some((range) => {\n return range.from >= from && range.to <= to;\n });\n });\n\n for (const m of matches) {\n if (m.from < m.to) {\n try {\n builder.add(m.from, m.to, Decoration.mark({ class: m.className }));\n } catch (e) {\n console.warn(\"SyntaxHighlighter: Failed to add decoration\", m, e);\n }\n }\n }\n\n return builder.finish();\n}\n\nconst SyntaxHighlighter = ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = buildDecorations(view);\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged || update.viewportChanged || update.selectionSet) {\n this.decorations = buildDecorations(update.view);\n }\n }\n },\n {\n decorations: (instance) => instance.decorations,\n }\n);\n\nexport default SyntaxHighlighter;\n"],"names":["broadVariableRegex","commentRegex","controlBlockRegex","INTERACTION_CONTENT_SOURCE","collectMultilineFixedOutputRanges","docText","ranges","pendingStart","lineStart","newlineIndex","lineEnd","collectSingleLineFixedOutputRanges","commentRanges","commentIndex","isInsideComment","index","range","lineText","markerPositions","searchFrom","markerOffset","markerIndex","i","collectCommentRanges","match","collectOuterBlockRanges","blockRanges","a","b","outerRanges","lastOuter","collectSyntaxHighlightRanges","isCursorInside","matches","occupied","isOverlapping","from","to","addMatch","className","classifyVariable","raw","strictMatch","createVariableExpressionRegexp","valid","fullStart","fullEnd","content","contentStart","contentVariableRegex","firstVariableMatch","percentClass","classification","varFrom","varTo","cursorInsideVar","operatorRanges","variableRanges","appliedTokenRanges","scanIndex","isEscape","operator","innerVariableMatch","innerVariableRegex","rawVariable","allTokens","token","stringStart","stringEnd","cursor","sortedApplied","appliedVariableRanges","sortedVariables","variable","buttonTextStart","buttonTextEnd","text","buildDecorations","view","builder","RangeSetBuilder","m","Decoration","e","SyntaxHighlighter","ViewPlugin","update","instance"],"mappings":";;;;AAYA,MAAMA,IAAqB,gBACrBC,IAAe,oBAKfC,IAAoB,IAAI;AAAA,EAC5B,UAAUC,EAAAA,0BAA0B;AAAA,EACpC;AACF;AAQA,SAASC,EACPC,GACwB;AACxB,QAAMC,IAAiC,CAAA;AACvC,MAAIC,IAA8B,MAC9BC,IAAY;AAEhB,SAAOA,KAAaH,EAAQ,UAAQ;AAClC,UAAMI,IAAeJ,EAAQ,QAAQ;AAAA,GAAMG,CAAS,GAC9CE,IAAUD,MAAiB,KAAKJ,EAAQ,SAASI;AAgBvD,QAfiBJ,EAAQ,MAAMG,GAAWE,CAAO,EAEpC,KAAA,MAAW,WAClBH,MAAiB,OACnBA,IAAeC,KAEfF,EAAO,KAAK;AAAA,MACV,MAAMC;AAAA,MACN,IAAIG;AAAA,MACJ,WAAW;AAAA,IAAA,CACZ,GACDH,IAAe,QAIfE,MAAiB;AACnB;AAGF,IAAAD,IAAYC,IAAe;AAAA,EAC7B;AAEA,SAAOH;AACT;AAEA,SAASK,EACPN,GACAO,GACwB;AACxB,QAAMN,IAAiC,CAAA;AACvC,MAAIO,IAAe;AAEnB,QAAMC,IAAkB,CAACC,MAAkB;AACzC,WACEF,IAAeD,EAAc,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cAAcD,EAAiBC,CAAI;AAAA,IAC1C;AAAA,IAEA,OAAOQ,GAAoB;AACzB,OAAIA,EAAO,cAAcA,EAAO,mBAAmBA,EAAO,kBACxD,KAAK,cAAcT,EAAiBS,EAAO,IAAI;AAAA,IAEnD;AAAA,EAAA;AAAA,EAEF;AAAA,IACE,aAAa,CAACC,MAAaA,EAAS;AAAA,EAAA;AAExC;"}
|
|
1
|
+
{"version":3,"file":"SyntaxHighlighter.es.js","sources":["../../../../src/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.ts"],"sourcesContent":["import {\n Decoration,\n DecorationSet,\n EditorView,\n ViewPlugin,\n ViewUpdate,\n} from \"@codemirror/view\";\nimport { RangeSetBuilder } from \"@codemirror/state\";\nimport { getMarkdownSourceAnalysis } from \"../../ContentRender/utils/inline-code-ranges\";\nimport { INTERACTION_CONTENT_SOURCE, isEscape } from \"remark-flow\";\n\nimport {\n findVariableMarkers,\n findDocumentVariableMarkers,\n trimVariablePadding,\n} from \"../utils\";\n\nconst commentRegex = /<!--[\\s\\S]*?-->/g;\n\n// An unfinished marker still owns its tail, so nested syntax stays literal while typing.\nconst interactionVariableRanges = (text: string) => {\n const markers = findVariableMarkers(text);\n const pending = text.indexOf(\"{{\", markers.at(-1)?.end ?? 0);\n return pending === -1\n ? markers\n : [...markers, { start: pending, end: text.length, name: null }];\n};\n// The grammar's own definition of where an interaction ends, so a `\\]` an option escaped does\n// not cut the highlight short, and the same `(?!\\()` the parser uses, so `?[text](url)` stays a\n// markdown link. Taken from remark-flow rather than written again here: the editor and the\n// parser have to agree about what they are looking at.\nconst controlBlockRegex = new RegExp(\n `\\\\?\\\\[(${INTERACTION_CONTENT_SOURCE})\\\\](?!\\\\()`,\n \"g\"\n);\n\nconst documentControlRanges = (text: string) =>\n getMarkdownSourceAnalysis(text).interactions;\n\nexport interface SyntaxHighlightRange {\n from: number;\n to: number;\n className: string;\n}\n\nfunction collectMultilineFixedOutputRanges(\n docText: string,\n isInsideVariable: (position: number) => boolean\n): SyntaxHighlightRange[] {\n const ranges: SyntaxHighlightRange[] = [];\n let pendingStart: number | null = null;\n let lineStart = 0;\n\n while (lineStart <= docText.length) {\n const newlineIndex = docText.indexOf(\"\\n\", lineStart);\n const lineEnd = newlineIndex === -1 ? docText.length : newlineIndex;\n const lineText = docText.slice(lineStart, lineEnd);\n\n if (lineText.trim() === \"!===\" && !isInsideVariable(lineStart)) {\n if (pendingStart === null) {\n pendingStart = lineStart;\n } else {\n ranges.push({\n from: pendingStart,\n to: lineEnd,\n className: \"syntax-fixed\",\n });\n pendingStart = null;\n }\n }\n\n if (newlineIndex === -1) {\n break;\n }\n\n lineStart = newlineIndex + 1;\n }\n\n return ranges;\n}\n\nfunction collectSingleLineFixedOutputRanges(\n docText: string,\n commentRanges: SyntaxHighlightRange[],\n isInsideVariable: (position: number) => boolean\n): SyntaxHighlightRange[] {\n const ranges: SyntaxHighlightRange[] = [];\n let commentIndex = 0;\n\n const isInsideComment = (index: number) => {\n while (\n commentIndex < commentRanges.length &&\n commentRanges[commentIndex].to <= index\n ) {\n commentIndex++;\n }\n\n const range = commentRanges[commentIndex];\n return !!range && index >= range.from && index < range.to;\n };\n\n let lineStart = 0;\n while (lineStart <= docText.length) {\n const newlineIndex = docText.indexOf(\"\\n\", lineStart);\n const lineEnd = newlineIndex === -1 ? docText.length : newlineIndex;\n const lineText = docText.slice(lineStart, lineEnd);\n const markerPositions: number[] = [];\n let searchFrom = 0;\n\n while (searchFrom < lineText.length) {\n const markerOffset = lineText.indexOf(\"===\", searchFrom);\n if (markerOffset === -1) {\n break;\n }\n\n const markerIndex = lineStart + markerOffset;\n const isNegated = markerIndex > 0 && docText[markerIndex - 1] === \"!\";\n if (\n !isNegated &&\n !isInsideComment(markerIndex) &&\n !isInsideVariable(markerIndex)\n ) {\n markerPositions.push(markerIndex);\n }\n\n searchFrom = markerOffset + 3;\n }\n\n for (let i = 0; i + 1 < markerPositions.length; i += 2) {\n ranges.push({\n from: markerPositions[i],\n to: markerPositions[i + 1] + 3,\n className: \"syntax-fixed\",\n });\n }\n\n if (newlineIndex === -1) {\n break;\n }\n\n lineStart = newlineIndex + 1;\n }\n\n return ranges;\n}\n\nfunction collectCommentRanges(\n docText: string,\n isInsideVariable: (position: number) => boolean\n): SyntaxHighlightRange[] {\n const ranges: SyntaxHighlightRange[] = [];\n let match;\n\n commentRegex.lastIndex = 0;\n while ((match = commentRegex.exec(docText)) !== null) {\n if (isInsideVariable(match.index)) continue;\n ranges.push({\n from: match.index,\n to: match.index + match[0].length,\n className: \"syntax-comment\",\n });\n }\n\n return ranges;\n}\n\n/**\n * Collects non-overlapping fixed-output and comment wrapper ranges.\n *\n * @param docText - Document text to scan.\n * @returns Outer syntax highlight ranges sorted by document position.\n */\nexport function collectOuterBlockRanges(\n docText: string\n): SyntaxHighlightRange[] {\n const variables = findDocumentVariableMarkers(docText);\n const isInsideVariable = (position: number) =>\n variables.some(\n (marker) => position >= marker.start && position < marker.end\n );\n const commentRanges = collectCommentRanges(docText, isInsideVariable);\n const blockRanges = [\n ...collectMultilineFixedOutputRanges(docText, isInsideVariable),\n ...collectSingleLineFixedOutputRanges(\n docText,\n commentRanges,\n isInsideVariable\n ),\n ...commentRanges,\n ].sort((a, b) => {\n if (a.from !== b.from) return a.from - b.from;\n return b.to - a.to;\n });\n\n const outerRanges: SyntaxHighlightRange[] = [];\n\n for (const range of blockRanges) {\n const lastOuter = outerRanges[outerRanges.length - 1];\n if (!lastOuter || range.from >= lastOuter.to) {\n outerRanges.push(range);\n }\n }\n\n return outerRanges;\n}\n\n/**\n * Collects all custom syntax highlight ranges for editor decorations.\n *\n * @param docText - Document text to scan.\n * @param isCursorInside - Returns true when the current cursor is inside a range.\n * @returns Non-overlapping syntax highlight ranges sorted by document position.\n */\nexport function collectSyntaxHighlightRanges(\n docText: string,\n isCursorInside: (from: number, to: number) => boolean = () => false\n): SyntaxHighlightRange[] {\n const matches: SyntaxHighlightRange[] = [];\n const documentVariables = findDocumentVariableMarkers(docText);\n const occupied: { from: number; to: number }[] = [];\n\n controlBlockRegex.lastIndex = 0;\n\n // Prevent overlapping decorations so styling stays deterministic\n const isOverlapping = (from: number, to: number) =>\n occupied.some((range) => !(to <= range.from || from >= range.to));\n\n const addMatch = (from: number, to: number, className: string) => {\n if (from >= to) return false;\n if (isOverlapping(from, to)) return false;\n occupied.push({ from, to });\n matches.push({ from, to, className });\n return true;\n };\n\n // 1. Outer block ranges win over any syntax inside them.\n for (const range of collectOuterBlockRanges(docText)) {\n addMatch(range.from, range.to, range.className);\n }\n\n // 2. Control Blocks\n for (const control of documentControlRanges(docText)) {\n // Native Markdown owns document boundaries. The shared token grammar still\n // supplies the exact source offsets used for individual editor decorations.\n controlBlockRegex.lastIndex = control.start;\n const match = controlBlockRegex.exec(docText);\n if (\n !match ||\n match.index !== control.start ||\n match.index + match[0].length !== control.end\n )\n continue;\n const fullStart = match.index;\n const fullEnd = match.index + match[0].length;\n const content = match[1];\n const contentStart = fullStart + 2; // after ?[\n if (\n isOverlapping(fullStart, fullEnd) ||\n documentVariables.some(\n (marker) => marker.start <= fullStart && fullStart < marker.end\n )\n ) {\n continue;\n }\n\n // Outer brackets and question mark\n addMatch(fullStart, fullStart + 1, \"syntax-keyword\"); // ?\n addMatch(fullStart + 1, fullStart + 2, \"syntax-bracket\"); // [\n addMatch(fullEnd - 1, fullEnd, \"syntax-bracket\"); // ]\n\n const variables = interactionVariableRanges(content);\n const firstVariable = variables[0];\n const percentIndex = firstVariable ? firstVariable.start - 1 : -1;\n const hasLeadingAssignment =\n percentIndex >= 0 &&\n content[percentIndex] === \"%\" &&\n trimVariablePadding(content.slice(0, percentIndex)) === \"\";\n if (content.startsWith(\"%\") || hasLeadingAssignment) {\n // Input / Select\n let percentClass = \"syntax-percent-invalid\";\n if (firstVariable && hasLeadingAssignment) {\n const varFrom = contentStart + firstVariable.start;\n const varTo = contentStart + firstVariable.end;\n const cursorInsideVar = isCursorInside(varFrom, varTo);\n percentClass =\n firstVariable.name !== null && !cursorInsideVar\n ? \"syntax-percent-valid\"\n : \"syntax-percent-invalid\";\n }\n const percentStart =\n contentStart + (hasLeadingAssignment ? percentIndex : 0);\n addMatch(percentStart, percentStart + 1, percentClass); // %\n\n const operatorRanges: { from: number; to: number }[] = [];\n const variableRanges: { from: number; to: number; className: string }[] =\n [];\n const appliedTokenRanges: { from: number; to: number }[] = [];\n\n // Keep a variable name atomic even when it contains option punctuation.\n for (const variable of variables) {\n variableRanges.push({\n from: contentStart + variable.start,\n to: contentStart + variable.end,\n className:\n variable.name === null\n ? \"syntax-variable-invalid\"\n : \"syntax-variable\",\n });\n }\n\n // Inner operators | || ... -- skipping any an option escaped, the way the parser does.\n // Painted as separators, they told the author the grammar had split an option that it\n // had in fact left whole.\n let scanIndex = 0;\n while (scanIndex < content.length) {\n const variable = variableRanges.find(\n (range) => contentStart + scanIndex === range.from\n );\n if (variable) {\n scanIndex = variable.to - contentStart;\n continue;\n }\n if (isEscape(content, scanIndex)) {\n scanIndex += 2;\n continue;\n }\n const operator = content.startsWith(\"||\", scanIndex)\n ? \"||\"\n : content[scanIndex] === \"|\"\n ? \"|\"\n : content.startsWith(\"...\", scanIndex)\n ? \"...\"\n : null;\n if (!operator) {\n scanIndex += 1;\n continue;\n }\n operatorRanges.push({\n from: contentStart + scanIndex,\n to: contentStart + scanIndex + operator.length,\n });\n scanIndex += operator.length;\n }\n\n const allTokens = [\n ...operatorRanges.map((range) => ({\n ...range,\n className: \"syntax-keyword\",\n })),\n ...variableRanges.map((range) => ({\n ...range,\n className: range.className,\n })),\n ].sort((a, b) => {\n if (a.from !== b.from) return a.from - b.from;\n return a.to - b.to;\n });\n\n for (const token of allTokens) {\n if (\n token.className.startsWith(\"syntax-variable\") &&\n isCursorInside(token.from, token.to)\n ) {\n continue;\n }\n if (addMatch(token.from, token.to, token.className)) {\n appliedTokenRanges.push({ from: token.from, to: token.to });\n }\n }\n\n // Content (Dark Blue) for remaining text segments\n const stringStart = percentStart + 1;\n const stringEnd = fullEnd - 1;\n let cursor = stringStart;\n const sortedApplied = appliedTokenRanges.sort((a, b) => {\n if (a.from !== b.from) return a.from - b.from;\n return a.to - b.to;\n });\n\n for (const token of sortedApplied) {\n if (cursor < token.from) {\n addMatch(cursor, token.from, \"syntax-string\");\n }\n cursor = Math.max(cursor, token.to);\n }\n if (cursor < stringEnd) {\n addMatch(cursor, stringEnd, \"syntax-string\");\n }\n } else {\n // Button ?[text]\n const variableRanges: { from: number; to: number; className: string }[] =\n [];\n const appliedVariableRanges: { from: number; to: number }[] = [];\n\n for (const variable of interactionVariableRanges(content)) {\n variableRanges.push({\n from: contentStart + variable.start,\n to: contentStart + variable.end,\n className:\n variable.name === null\n ? \"syntax-variable-invalid\"\n : \"syntax-variable\",\n });\n }\n\n const sortedVariables = variableRanges.sort((a, b) => {\n if (a.from !== b.from) return a.from - b.from;\n return a.to - b.to;\n });\n\n for (const variable of sortedVariables) {\n if (\n variable.className.startsWith(\"syntax-variable\") &&\n isCursorInside(variable.from, variable.to)\n ) {\n continue;\n }\n if (addMatch(variable.from, variable.to, variable.className)) {\n appliedVariableRanges.push({ from: variable.from, to: variable.to });\n }\n }\n\n const buttonTextStart = contentStart;\n const buttonTextEnd = fullEnd - 1;\n let cursor = buttonTextStart;\n\n for (const variable of appliedVariableRanges) {\n if (cursor < variable.from) {\n addMatch(cursor, variable.from, \"syntax-button-text\");\n }\n cursor = Math.max(cursor, variable.to);\n }\n if (cursor < buttonTextEnd) {\n addMatch(cursor, buttonTextEnd, \"syntax-button-text\");\n }\n }\n }\n\n // 3. Variables (only if not already decorated; invalid ones stay default outside control blocks)\n for (const variable of documentVariables) {\n if (\n variable.name !== null &&\n !isCursorInside(variable.start, variable.end)\n ) {\n addMatch(variable.start, variable.end, \"syntax-variable\");\n }\n }\n\n // Sort matches by 'from' asc, then 'to' desc (longest first)\n matches.sort((a, b) => {\n if (a.from !== b.from) return a.from - b.from;\n return b.to - a.to;\n });\n\n return matches;\n}\n\nfunction buildDecorations(view: EditorView): DecorationSet {\n const builder = new RangeSetBuilder<Decoration>();\n const docText = view.state.doc.toString();\n const matches = collectSyntaxHighlightRanges(docText, (from, to) => {\n return view.state.selection.ranges.some((range) => {\n return range.from >= from && range.to <= to;\n });\n });\n\n for (const m of matches) {\n if (m.from < m.to) {\n try {\n builder.add(m.from, m.to, Decoration.mark({ class: m.className }));\n } catch (e) {\n console.warn(\"SyntaxHighlighter: Failed to add decoration\", m, e);\n }\n }\n }\n\n return builder.finish();\n}\n\nconst SyntaxHighlighter = ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = buildDecorations(view);\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged || update.viewportChanged || update.selectionSet) {\n this.decorations = buildDecorations(update.view);\n }\n }\n },\n {\n decorations: (instance) => instance.decorations,\n }\n);\n\nexport default SyntaxHighlighter;\n"],"names":["commentRegex","interactionVariableRanges","text","markers","findVariableMarkers","pending","controlBlockRegex","INTERACTION_CONTENT_SOURCE","documentControlRanges","getMarkdownSourceAnalysis","collectMultilineFixedOutputRanges","docText","isInsideVariable","ranges","pendingStart","lineStart","newlineIndex","lineEnd","collectSingleLineFixedOutputRanges","commentRanges","commentIndex","isInsideComment","index","range","lineText","markerPositions","searchFrom","markerOffset","markerIndex","i","collectCommentRanges","match","collectOuterBlockRanges","variables","findDocumentVariableMarkers","position","marker","blockRanges","a","b","outerRanges","lastOuter","collectSyntaxHighlightRanges","isCursorInside","matches","documentVariables","occupied","isOverlapping","from","to","addMatch","className","control","fullStart","fullEnd","content","contentStart","firstVariable","percentIndex","hasLeadingAssignment","trimVariablePadding","percentClass","varFrom","varTo","cursorInsideVar","percentStart","operatorRanges","variableRanges","appliedTokenRanges","variable","scanIndex","isEscape","operator","allTokens","token","stringStart","stringEnd","cursor","sortedApplied","appliedVariableRanges","sortedVariables","buttonTextStart","buttonTextEnd","buildDecorations","view","builder","RangeSetBuilder","m","Decoration","e","SyntaxHighlighter","ViewPlugin","update","instance"],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K,cAAcT,EAAiBS,EAAO,IAAI;AAAA,IAEnD;AAAA,EAAA;AAAA,EAEF;AAAA,IACE,aAAa,CAACC,MAAaA,EAAS;AAAA,EAAA;AAExC;"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../../../node_modules/@codemirror/view/dist/index.cjs"),g=require("../types.cjs"),f=require("./PlaceholderWidget.cjs"),a=require("../../../_virtual/index.cjs"),d=(e,s,n)=>{const t=s+2,r=n-2;return r<t?!1:e.state.selection.ranges.some(o=>{const h=o.anchor>=t&&o.anchor<=r,u=o.head>=t&&o.head<=r;return h||u})},c=(e,s)=>{const n=e.state.doc.toString();return i.Decoration.set(s.flatMap(t=>{const r=n.slice(t.start,t.end);return t.name===null||r.includes(`
|
|
2
|
+
`)||d(e,t.start,t.end)?[]:[i.Decoration.replace({widget:new f.default(r,{tag:"variable",title:t.name},"tag-variable",g.SelectedOption.Variable,e)}).range(t.start,t.end)]}))},l=(e,s)=>s.filter(n=>d(e,n.start,n.end)).map(n=>n.start).join(","),S=i.ViewPlugin.fromClass(class{constructor(e){this.markers=a.distExports.findDocumentVariableMarkers(e.state.doc.toString()),this.selectionSignature=l(e,this.markers),this.placeholders=c(e,this.markers)}update(e){if(e.docChanged&&(this.markers=a.distExports.findDocumentVariableMarkers(e.state.doc.toString())),e.docChanged||e.selectionSet){const s=l(e.view,this.markers);(e.docChanged||s!==this.selectionSignature)&&(this.selectionSignature=s,this.placeholders=c(e.view,this.markers))}}},{decorations:e=>e.placeholders,provide:e=>i.EditorView.atomicRanges.of(s=>s.plugin(e)?.placeholders||i.Decoration.none)});exports.default=S;
|
|
2
3
|
//# sourceMappingURL=VariablePlaceholder.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariablePlaceholder.cjs","sources":["../../../../src/components/MarkdownFlowEditor/plugins/VariablePlaceholder.ts"],"sourcesContent":["import {\n EditorView,\n Decoration,\n DecorationSet,\n ViewPlugin,\n ViewUpdate,\n
|
|
1
|
+
{"version":3,"file":"VariablePlaceholder.cjs","sources":["../../../../src/components/MarkdownFlowEditor/plugins/VariablePlaceholder.ts"],"sourcesContent":["import {\n EditorView,\n Decoration,\n DecorationSet,\n ViewPlugin,\n ViewUpdate,\n} from \"@codemirror/view\";\nimport { SelectedOption } from \"../types\";\nimport PlaceholderWidget from \"./PlaceholderWidget\";\nimport { findDocumentVariableMarkers } from \"../utils\";\n\nconst selectionInsideVariableExpression = (\n view: EditorView,\n from: number,\n to: number\n) => {\n const innerStart = from + 2;\n const innerEnd = to - 2;\n if (innerEnd < innerStart) {\n return false;\n }\n return view.state.selection.ranges.some((range) => {\n const isAnchorInside =\n range.anchor >= innerStart && range.anchor <= innerEnd;\n const isHeadInside = range.head >= innerStart && range.head <= innerEnd;\n return isAnchorInside || isHeadInside;\n });\n};\n\nconst buildPlaceholders = (\n view: EditorView,\n markers: ReturnType<typeof findDocumentVariableMarkers>\n): DecorationSet => {\n const text = view.state.doc.toString();\n return Decoration.set(\n markers.flatMap((marker) => {\n const rawMarker = text.slice(marker.start, marker.end);\n if (\n marker.name === null ||\n // CodeMirror inline widgets cannot replace line breaks in marker padding.\n rawMarker.includes(\"\\n\") ||\n selectionInsideVariableExpression(view, marker.start, marker.end)\n ) {\n return [];\n }\n return [\n Decoration.replace({\n widget: new PlaceholderWidget(\n rawMarker,\n { tag: \"variable\", title: marker.name },\n \"tag-variable\",\n SelectedOption.Variable,\n view\n ),\n }).range(marker.start, marker.end),\n ];\n })\n );\n};\n\nconst selectedMarkers = (\n view: EditorView,\n markers: ReturnType<typeof findDocumentVariableMarkers>\n) =>\n markers\n .filter((marker) =>\n selectionInsideVariableExpression(view, marker.start, marker.end)\n )\n .map((marker) => marker.start)\n .join(\",\");\n\nconst VariablePlaceholder = ViewPlugin.fromClass(\n class {\n placeholders: DecorationSet;\n markers: ReturnType<typeof findDocumentVariableMarkers>;\n selectionSignature: string;\n constructor(view: EditorView) {\n this.markers = findDocumentVariableMarkers(view.state.doc.toString());\n this.selectionSignature = selectedMarkers(view, this.markers);\n this.placeholders = buildPlaceholders(view, this.markers);\n }\n update(update: ViewUpdate) {\n if (update.docChanged)\n this.markers = findDocumentVariableMarkers(update.state.doc.toString());\n if (update.docChanged || update.selectionSet) {\n const signature = selectedMarkers(update.view, this.markers);\n if (update.docChanged || signature !== this.selectionSignature) {\n this.selectionSignature = signature;\n this.placeholders = buildPlaceholders(update.view, this.markers);\n }\n }\n }\n },\n {\n decorations: (instance) => instance.placeholders,\n provide: (plugin) =>\n EditorView.atomicRanges.of((view) => {\n return view.plugin(plugin)?.placeholders || Decoration.none;\n }),\n }\n);\n\nexport default VariablePlaceholder;\n"],"names":["selectionInsideVariableExpression","view","from","to","innerStart","innerEnd","range","isAnchorInside","isHeadInside","buildPlaceholders","markers","text","Decoration","marker","rawMarker","PlaceholderWidget","SelectedOption","selectedMarkers","VariablePlaceholder","ViewPlugin","findDocumentVariableMarkers","update","signature","instance","plugin","EditorView"],"mappings":"6RAWMA,EAAoC,CACxCC,EACAC,EACAC,IACG,CACH,MAAMC,EAAaF,EAAO,EACpBG,EAAWF,EAAK,EACtB,OAAIE,EAAWD,EACN,GAEFH,EAAK,MAAM,UAAU,OAAO,KAAMK,GAAU,CACjD,MAAMC,EACJD,EAAM,QAAUF,GAAcE,EAAM,QAAUD,EAC1CG,EAAeF,EAAM,MAAQF,GAAcE,EAAM,MAAQD,EAC/D,OAAOE,GAAkBC,CAC3B,CAAC,CACH,EAEMC,EAAoB,CACxBR,EACAS,IACkB,CAClB,MAAMC,EAAOV,EAAK,MAAM,IAAI,SAAA,EAC5B,OAAOW,EAAAA,WAAW,IAChBF,EAAQ,QAASG,GAAW,CAC1B,MAAMC,EAAYH,EAAK,MAAME,EAAO,MAAOA,EAAO,GAAG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ViewPlugin, ViewUpdate } from '@codemirror/view';
|
|
2
|
+
import { findDocumentVariableMarkers } from '../utils.js';
|
|
2
3
|
declare const VariablePlaceholder: ViewPlugin<{
|
|
3
4
|
placeholders: DecorationSet;
|
|
4
|
-
|
|
5
|
+
markers: ReturnType<typeof findDocumentVariableMarkers>;
|
|
6
|
+
selectionSignature: string;
|
|
5
7
|
update(update: ViewUpdate): void;
|
|
6
8
|
}, undefined>;
|
|
7
9
|
export default VariablePlaceholder;
|