markdown-flow-ui 0.2.36-dev.1 → 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.
Files changed (159) hide show
  1. package/README.md +11 -11
  2. package/dist/_virtual/index.es10.js +2 -2
  3. package/dist/_virtual/index.es3.js +5 -4
  4. package/dist/_virtual/index.es3.js.map +1 -1
  5. package/dist/_virtual/index.es4.js +4 -5
  6. package/dist/_virtual/index.es4.js.map +1 -1
  7. package/dist/_virtual/index.es5.js +5 -5
  8. package/dist/_virtual/index.es6.js +5 -3
  9. package/dist/_virtual/index.es6.js.map +1 -1
  10. package/dist/_virtual/index.es7.js +3 -5
  11. package/dist/_virtual/index.es7.js.map +1 -1
  12. package/dist/_virtual/index.es9.js +2 -2
  13. package/dist/_virtual/index10.cjs +1 -1
  14. package/dist/_virtual/index3.cjs +1 -1
  15. package/dist/_virtual/index4.cjs +1 -1
  16. package/dist/_virtual/index5.cjs +1 -1
  17. package/dist/_virtual/index6.cjs +1 -1
  18. package/dist/_virtual/index7.cjs +1 -1
  19. package/dist/_virtual/index9.cjs +1 -1
  20. package/dist/_virtual/variable-marker.cjs +2 -0
  21. package/dist/_virtual/variable-marker.cjs.map +1 -0
  22. package/dist/_virtual/variable-marker.es.js +5 -0
  23. package/dist/_virtual/variable-marker.es.js.map +1 -0
  24. package/dist/components/ContentRender/ContentRender.cjs +2 -2
  25. package/dist/components/ContentRender/ContentRender.cjs.map +1 -1
  26. package/dist/components/ContentRender/ContentRender.es.js +206 -205
  27. package/dist/components/ContentRender/ContentRender.es.js.map +1 -1
  28. package/dist/components/ContentRender/utils/inline-code-ranges.cjs +9 -9
  29. package/dist/components/ContentRender/utils/inline-code-ranges.cjs.map +1 -1
  30. package/dist/components/ContentRender/utils/inline-code-ranges.d.ts +3 -0
  31. package/dist/components/ContentRender/utils/inline-code-ranges.es.js +185 -161
  32. package/dist/components/ContentRender/utils/inline-code-ranges.es.js.map +1 -1
  33. package/dist/components/ContentRender/utils/mermaid-parse.cjs +4 -4
  34. package/dist/components/ContentRender/utils/mermaid-parse.cjs.map +1 -1
  35. package/dist/components/ContentRender/utils/mermaid-parse.es.js +53 -48
  36. package/dist/components/ContentRender/utils/mermaid-parse.es.js.map +1 -1
  37. package/dist/components/ContentRender/utils/split-content.cjs +6 -6
  38. package/dist/components/ContentRender/utils/split-content.cjs.map +1 -1
  39. package/dist/components/ContentRender/utils/split-content.d.ts +1 -0
  40. package/dist/components/ContentRender/utils/split-content.es.js +361 -313
  41. package/dist/components/ContentRender/utils/split-content.es.js.map +1 -1
  42. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs +1 -1
  43. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs.map +1 -1
  44. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js +278 -283
  45. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js.map +1 -1
  46. package/dist/components/MarkdownFlowEditor/components/VariableSelect.cjs +1 -1
  47. package/dist/components/MarkdownFlowEditor/components/VariableSelect.cjs.map +1 -1
  48. package/dist/components/MarkdownFlowEditor/components/VariableSelect.es.js +57 -58
  49. package/dist/components/MarkdownFlowEditor/components/VariableSelect.es.js.map +1 -1
  50. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.cjs +1 -1
  51. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.d.ts +1 -1
  52. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.es.js +1 -1
  53. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.cjs +1 -1
  54. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.d.ts +1 -1
  55. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.es.js +19 -19
  56. package/dist/components/MarkdownFlowEditor/locales/en-US.json.cjs +1 -1
  57. package/dist/components/MarkdownFlowEditor/locales/en-US.json.d.ts +1 -1
  58. package/dist/components/MarkdownFlowEditor/locales/en-US.json.es.js +5 -5
  59. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.cjs +1 -1
  60. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.d.ts +1 -1
  61. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.es.js +1 -1
  62. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.cjs +1 -1
  63. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.d.ts +1 -1
  64. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.es.js +15 -15
  65. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.cjs +1 -1
  66. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.d.ts +1 -1
  67. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.es.js +13 -13
  68. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.cjs +1 -1
  69. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.d.ts +1 -1
  70. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.es.js +1 -1
  71. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.cjs +1 -1
  72. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.d.ts +1 -1
  73. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.es.js +1 -1
  74. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.cjs +1 -1
  75. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.d.ts +1 -1
  76. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.es.js +1 -1
  77. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.cjs +1 -1
  78. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.d.ts +1 -1
  79. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.es.js +15 -15
  80. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.cjs +1 -1
  81. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.d.ts +1 -1
  82. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.es.js +1 -1
  83. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.cjs +3 -3
  84. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.cjs.map +1 -1
  85. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.es.js +177 -176
  86. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.es.js.map +1 -1
  87. package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.cjs +2 -1
  88. package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.cjs.map +1 -1
  89. package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.d.ts +3 -1
  90. package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.es.js +38 -55
  91. package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.es.js.map +1 -1
  92. package/dist/components/MarkdownFlowEditor/utils.cjs +1 -1
  93. package/dist/components/MarkdownFlowEditor/utils.cjs.map +1 -1
  94. package/dist/components/MarkdownFlowEditor/utils.d.ts +2 -2
  95. package/dist/components/MarkdownFlowEditor/utils.es.js +34 -31
  96. package/dist/components/MarkdownFlowEditor/utils.es.js.map +1 -1
  97. package/dist/components/ui/inputGroup/textarea.cjs +1 -1
  98. package/dist/components/ui/inputGroup/textarea.es.js +1 -1
  99. package/dist/lib/interaction-defaults.cjs +1 -1
  100. package/dist/lib/interaction-defaults.cjs.map +1 -1
  101. package/dist/lib/interaction-defaults.es.js +124 -133
  102. package/dist/lib/interaction-defaults.es.js.map +1 -1
  103. package/dist/lib/interaction-defaults.failure.test.d.ts +1 -0
  104. package/dist/node_modules/classnames/index.cjs +1 -1
  105. package/dist/node_modules/classnames/index.es.js +1 -1
  106. package/dist/node_modules/hast-util-to-jsx-runtime/lib/index.cjs +1 -1
  107. package/dist/node_modules/hast-util-to-jsx-runtime/lib/index.es.js +1 -1
  108. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-AAMF2YG6.cjs +1 -1
  109. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-AAMF2YG6.es.js +1 -1
  110. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-OMD6QJNC.cjs +1 -1
  111. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-OMD6QJNC.es.js +1 -1
  112. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-U37J5Y7L.cjs +1 -1
  113. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-U37J5Y7L.es.js +1 -1
  114. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-WV7ZQ7D5.cjs +1 -1
  115. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-WV7ZQ7D5.es.js +1 -1
  116. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-4MX5Z3NR.cjs +1 -1
  117. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-4MX5Z3NR.es.js +1 -1
  118. package/dist/node_modules/rc-input/es/BaseInput.cjs +1 -1
  119. package/dist/node_modules/rc-input/es/BaseInput.es.js +1 -1
  120. package/dist/node_modules/rc-textarea/es/ResizableTextArea.cjs +1 -1
  121. package/dist/node_modules/rc-textarea/es/ResizableTextArea.es.js +1 -1
  122. package/dist/node_modules/rc-textarea/es/TextArea.cjs +1 -1
  123. package/dist/node_modules/rc-textarea/es/TextArea.es.js +1 -1
  124. package/dist/node_modules/rc-textarea/es/index.cjs +1 -1
  125. package/dist/node_modules/rc-textarea/es/index.es.js +1 -1
  126. package/dist/node_modules/remark-flow/dist/escaping.cjs +2 -2
  127. package/dist/node_modules/remark-flow/dist/escaping.cjs.map +1 -1
  128. package/dist/node_modules/remark-flow/dist/escaping.es.js +128 -63
  129. package/dist/node_modules/remark-flow/dist/escaping.es.js.map +1 -1
  130. package/dist/node_modules/remark-flow/dist/index.cjs +1 -1
  131. package/dist/node_modules/remark-flow/dist/index.cjs.map +1 -1
  132. package/dist/node_modules/remark-flow/dist/index.es.js +49 -37
  133. package/dist/node_modules/remark-flow/dist/index.es.js.map +1 -1
  134. package/dist/node_modules/remark-flow/dist/interaction-parser.cjs +1 -1
  135. package/dist/node_modules/remark-flow/dist/interaction-parser.cjs.map +1 -1
  136. package/dist/node_modules/remark-flow/dist/interaction-parser.es.js +260 -255
  137. package/dist/node_modules/remark-flow/dist/interaction-parser.es.js.map +1 -1
  138. package/dist/node_modules/remark-flow/dist/interaction-plugin-core.cjs +1 -1
  139. package/dist/node_modules/remark-flow/dist/interaction-plugin-core.cjs.map +1 -1
  140. package/dist/node_modules/remark-flow/dist/interaction-plugin-core.es.js +71 -42
  141. package/dist/node_modules/remark-flow/dist/interaction-plugin-core.es.js.map +1 -1
  142. package/dist/node_modules/remark-flow/dist/interaction-syntax.cjs +1 -1
  143. package/dist/node_modules/remark-flow/dist/interaction-syntax.cjs.map +1 -1
  144. package/dist/node_modules/remark-flow/dist/interaction-syntax.es.js +500 -46
  145. package/dist/node_modules/remark-flow/dist/interaction-syntax.es.js.map +1 -1
  146. package/dist/node_modules/remark-flow/dist/variable-marker.cjs +2 -0
  147. package/dist/node_modules/remark-flow/dist/variable-marker.cjs.map +1 -0
  148. package/dist/node_modules/remark-flow/dist/variable-marker.es.js +77 -0
  149. package/dist/node_modules/remark-flow/dist/variable-marker.es.js.map +1 -0
  150. package/dist/node_modules/remark-flow/dist/variable-name.cjs +14 -1
  151. package/dist/node_modules/remark-flow/dist/variable-name.cjs.map +1 -1
  152. package/dist/node_modules/remark-flow/dist/variable-name.es.js +742 -25
  153. package/dist/node_modules/remark-flow/dist/variable-name.es.js.map +1 -1
  154. package/dist/node_modules/style-to-object/cjs/index.cjs +1 -1
  155. package/dist/node_modules/style-to-object/cjs/index.cjs.map +1 -1
  156. package/dist/node_modules/style-to-object/cjs/index.es.js +1 -1
  157. package/dist/node_modules/unified/lib/index.cjs +1 -1
  158. package/dist/node_modules/unified/lib/index.es.js +1 -1
  159. package/package.json +2 -2
@@ -1,214 +1,215 @@
1
- import { ViewPlugin as W, Decoration as A } from "../../../node_modules/@codemirror/view/dist/index.es.js";
2
- import { RangeSetBuilder as B } from "../../../node_modules/@codemirror/state/dist/index.es.js";
3
- import { d as O } from "../../../_virtual/index.es.js";
4
- const w = /\{\{.*?\}\}/g, V = /<!--[\s\S]*?-->/g, I = new RegExp(
5
- `\\?\\[(${O.INTERACTION_CONTENT_SOURCE})\\](?!\\()`,
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})\\](?!\\()`,
6
10
  "g"
7
- );
8
- function H(e) {
9
- const l = [];
10
- let c = null, f = 0;
11
- for (; f <= e.length; ) {
12
- const r = e.indexOf(`
13
- `, f), n = r === -1 ? e.length : r;
14
- if (e.slice(f, n).trim() === "!===" && (c === null ? c = f : (l.push({
15
- from: c,
16
- to: n,
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,
17
21
  className: "syntax-fixed"
18
- }), c = null)), r === -1)
22
+ }), l = null)), u === -1)
19
23
  break;
20
- f = r + 1;
24
+ s = u + 1;
21
25
  }
22
- return l;
26
+ return f;
23
27
  }
24
- function D(e, l) {
25
- const c = [];
26
- let f = 0;
27
- const r = (h) => {
28
- for (; f < l.length && l[f].to <= h; )
29
- f++;
30
- const m = l[f];
31
- return !!m && h >= m.from && h < m.to;
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;
32
36
  };
33
- let n = 0;
34
- for (; n <= e.length; ) {
35
- const h = e.indexOf(`
36
- `, n), m = h === -1 ? e.length : h, o = e.slice(n, m), s = [];
37
- let u = 0;
38
- for (; u < o.length; ) {
39
- const a = o.indexOf("===", u);
40
- if (a === -1)
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)
41
45
  break;
42
- const d = n + a;
43
- !(d > 0 && e[d - 1] === "!") && !r(d) && s.push(d), u = a + 3;
46
+ const p = e + c;
47
+ !(p > 0 && n[p - 1] === "!") && !u(p) && !f(p) && x.push(p), g = c + 3;
44
48
  }
45
- for (let a = 0; a + 1 < s.length; a += 2)
46
- c.push({
47
- from: s[a],
48
- to: s[a + 1] + 3,
49
+ for (let c = 0; c + 1 < x.length; c += 2)
50
+ l.push({
51
+ from: x[c],
52
+ to: x[c + 1] + 3,
49
53
  className: "syntax-fixed"
50
54
  });
51
- if (h === -1)
55
+ if (t === -1)
52
56
  break;
53
- n = h + 1;
57
+ e = t + 1;
54
58
  }
55
- return c;
59
+ return l;
56
60
  }
57
- function P(e) {
58
- const l = [];
59
- let c;
60
- for (V.lastIndex = 0; (c = V.exec(e)) !== null; )
61
- l.push({
62
- from: c.index,
63
- to: c.index + c[0].length,
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,
64
68
  className: "syntax-comment"
65
69
  });
66
- return l;
70
+ return f;
67
71
  }
68
- function T(e) {
69
- const l = P(e), c = [
70
- ...H(e),
71
- ...D(e, l),
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
+ ),
72
82
  ...l
73
- ].sort((r, n) => r.from !== n.from ? r.from - n.from : n.to - r.to), f = [];
74
- for (const r of c) {
75
- const n = f[f.length - 1];
76
- (!n || r.from >= n.to) && f.push(r);
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);
77
87
  }
78
- return f;
88
+ return u;
79
89
  }
80
- function _(e, l = () => !1) {
81
- const c = [], f = [];
82
- I.lastIndex = 0;
83
- const r = (o, s) => f.some((u) => !(s <= u.from || o >= u.to)), n = (o, s, u) => o >= s || r(o, s) ? !1 : (f.push({ from: o, to: s }), c.push({ from: o, to: s, className: u }), !0), h = (o) => {
84
- const s = O.normalizeVariableName(o.slice(2, -2)) !== null;
85
- return {
86
- className: s ? "syntax-variable" : "syntax-variable-invalid",
87
- valid: s
88
- };
89
- };
90
- let m;
91
- for (const o of T(e))
92
- n(o.from, o.to, o.className);
93
- for (; (m = I.exec(e)) !== null; ) {
94
- const o = m.index, s = m.index + m[0].length, u = m[1], a = o + 2;
95
- if (!r(o, s))
96
- if (n(o, o + 1, "syntax-keyword"), n(o + 1, o + 2, "syntax-bracket"), n(s - 1, s, "syntax-bracket"), u.startsWith("%")) {
97
- const d = new RegExp(w.source, "g"), p = d.exec(u);
98
- d.lastIndex = 0;
99
- let b = "syntax-percent-invalid";
100
- if (p?.index === 1) {
101
- const t = h(p[0]), x = a + p.index, E = x + p[0].length, F = l(x, E);
102
- b = t.valid && !F ? "syntax-percent-valid" : "syntax-percent-invalid";
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;
103
131
  }
104
- n(a, a + 1, b);
105
- const k = [], v = [], S = [];
106
- for (const t of u.matchAll(w))
107
- v.push({
108
- from: a + t.index,
109
- to: a + t.index + t[0].length,
110
- className: h(t[0]).className
111
- });
112
- let g = 0;
113
- for (; g < u.length; ) {
114
- const t = v.find(
115
- (E) => a + g === E.from
116
- );
117
- if (t) {
118
- g = t.to - a;
119
- continue;
120
- }
121
- if (O.isEscape(u, g)) {
122
- g += 2;
123
- continue;
124
- }
125
- const x = u.startsWith("||", g) ? "||" : u[g] === "|" ? "|" : u.startsWith("...", g) ? "..." : null;
126
- if (!x) {
127
- g += 1;
128
- continue;
129
- }
130
- k.push({
131
- from: a + g,
132
- to: a + g + x.length
133
- }), g += x.length;
132
+ if (N.isEscape(g, m)) {
133
+ m += 2;
134
+ continue;
134
135
  }
135
- const y = [
136
- ...k.map((t) => ({
137
- ...t,
138
- className: "syntax-keyword"
139
- })),
140
- ...v.map((t) => ({
141
- ...t,
142
- className: t.className
143
- }))
144
- ].sort((t, x) => t.from !== x.from ? t.from - x.from : t.to - x.to);
145
- for (const t of y)
146
- t.className.startsWith("syntax-variable") && l(t.from, t.to) || n(t.from, t.to, t.className) && S.push({ from: t.from, to: t.to });
147
- const i = a + 1, N = s - 1;
148
- let R = i;
149
- const C = S.sort((t, x) => t.from !== x.from ? t.from - x.from : t.to - x.to);
150
- for (const t of C)
151
- R < t.from && n(R, t.from, "syntax-string"), R = Math.max(R, t.to);
152
- R < N && n(R, N, "syntax-string");
153
- } else {
154
- const d = [], p = [];
155
- let b;
156
- const k = new RegExp(w.source, "g");
157
- for (; (b = k.exec(u)) !== null; ) {
158
- const i = b[0], N = h(i);
159
- d.push({
160
- from: a + b.index,
161
- to: a + b.index + i.length,
162
- className: N.className
163
- });
136
+ const h = g.startsWith("||", m) ? "||" : g[m] === "|" ? "|" : g.startsWith("...", m) ? "..." : null;
137
+ if (!h) {
138
+ m += 1;
139
+ continue;
164
140
  }
165
- const v = d.sort((i, N) => i.from !== N.from ? i.from - N.from : i.to - N.to);
166
- for (const i of v)
167
- i.className.startsWith("syntax-variable") && l(i.from, i.to) || n(i.from, i.to, i.className) && p.push({ from: i.from, to: i.to });
168
- const S = a, g = s - 1;
169
- let y = S;
170
- for (const i of p)
171
- y < i.from && n(y, i.from, "syntax-button-text"), y = Math.max(y, i.to);
172
- y < g && n(y, g, "syntax-button-text");
141
+ V.push({
142
+ from: c + m,
143
+ to: c + m + h.length
144
+ }), m += h.length;
173
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
+ }
174
181
  }
175
- for (w.lastIndex = 0; (m = w.exec(e)) !== null; ) {
176
- const o = m[0], s = h(o);
177
- s.valid && !l(m.index, m.index + m[0].length) && n(
178
- m.index,
179
- m.index + m[0].length,
180
- s.className
181
- );
182
- }
183
- return c.sort((o, s) => o.from !== s.from ? o.from - s.from : s.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;
184
185
  }
185
- function M(e) {
186
- const l = new B(), c = e.state.doc.toString(), f = _(c, (r, n) => e.state.selection.ranges.some((h) => h.from >= r && h.to <= n));
187
- for (const r of f)
188
- if (r.from < r.to)
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)
189
+ if (s.from < s.to)
189
190
  try {
190
- l.add(r.from, r.to, A.mark({ class: r.className }));
191
- } catch (n) {
192
- console.warn("SyntaxHighlighter: Failed to add decoration", r, n);
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);
193
194
  }
194
- return l.finish();
195
+ return i.finish();
195
196
  }
196
- const $ = W.fromClass(
197
+ const T = B.fromClass(
197
198
  class {
198
- constructor(e) {
199
- this.decorations = M(e);
199
+ constructor(n) {
200
+ this.decorations = A(n);
200
201
  }
201
- update(e) {
202
- (e.docChanged || e.viewportChanged || e.selectionSet) && (this.decorations = M(e.view));
202
+ update(n) {
203
+ (n.docChanged || n.viewportChanged || n.selectionSet) && (this.decorations = A(n.view));
203
204
  }
204
205
  },
205
206
  {
206
- decorations: (e) => e.decorations
207
+ decorations: (n) => n.decorations
207
208
  }
208
209
  );
209
210
  export {
210
- T as collectOuterBlockRanges,
211
- _ as collectSyntaxHighlightRanges,
212
- $ as default
211
+ q as collectOuterBlockRanges,
212
+ z as collectSyntaxHighlightRanges,
213
+ T as default
213
214
  };
214
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 { normalizeVariableName } 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 valid = normalizeVariableName(raw.slice(2, -2)) !== null;\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 = new RegExp(broadVariableRegex.source, \"g\");\n const firstVariableMatch = contentVariableRegex.exec(content);\n contentVariableRegex.lastIndex = 0;\n let percentClass = \"syntax-percent-invalid\";\n if (firstVariableMatch?.index === 1) {\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 // Keep a variable name atomic even when it contains option punctuation.\n for (const variableMatch of content.matchAll(broadVariableRegex)) {\n variableRanges.push({\n from: contentStart + variableMatch.index,\n to: contentStart + variableMatch.index + variableMatch[0].length,\n className: classifyVariable(variableMatch[0]).className,\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 = 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 = new RegExp(broadVariableRegex.source, \"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","valid","normalizeVariableName","fullStart","fullEnd","content","contentStart","contentVariableRegex","firstVariableMatch","percentClass","classification","varFrom","varTo","cursorInsideVar","operatorRanges","variableRanges","appliedTokenRanges","variableMatch","scanIndex","variable","isEscape","operator","allTokens","token","stringStart","stringEnd","cursor","sortedApplied","appliedVariableRanges","innerVariableMatch","innerVariableRegex","rawVariable","sortedVariables","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,UAC7BA,EAAcC,CAAY,EAAE,MAAME;AAElC,MAAAF;AAGF,UAAMG,IAAQJ,EAAcC,CAAY;AACxC,WAAO,CAAC,CAACG,KAASD,KAASC,EAAM,QAAQD,IAAQC,EAAM;AAAA,EACzD;AAEA,MAAIR,IAAY;AAChB,SAAOA,KAAaH,EAAQ,UAAQ;AAClC,UAAMI,IAAeJ,EAAQ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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"],"mappings":";;;;AAiBA,MAAMA,IAAe,oBAGfC,IAA4B,CAACC,MAAiB;AAClD,QAAMC,IAAUC,EAAAA,oBAAoBF,CAAI,GAClCG,IAAUH,EAAK,QAAQ,MAAMC,EAAQ,GAAG,EAAE,GAAG,OAAO,CAAC;AAC3D,SAAOE,MAAY,KACfF,IACA,CAAC,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require("../../../node_modules/@codemirror/view/dist/index.cjs"),p=require("../types.cjs"),f=require("./PlaceholderWidget.cjs"),c=require("../utils.cjs"),g=c.createVariableExpressionRegexp(),l=e=>{const t=e.state.doc.toString();if(!t)return!1;const n=c.createVariableExpressionRegexp();let r;for(;(r=n.exec(t))!==null;){const i=r.index??0,s=i+r[0].length;if(d(e,i,s))return!0;n.lastIndex===r.index&&n.lastIndex++}return!1},d=(e,t,n)=>{const r=t+2,i=n-2;return i<r?!1:e.state.selection.ranges.some(s=>{const u=s.anchor>=r&&s.anchor<=i,h=s.head>=r&&s.head<=i;return u||h})},a=new o.MatchDecorator({regexp:g,decoration:(e,t,n)=>{const r=e?.[0];if(!r)return null;const i=n+r.length;return d(t,n,i)?null:o.Decoration.replace({widget:new f.default(r,{tag:"variable",title:e?.[1]},"tag-variable",p.SelectedOption.Variable,t)})}}),x=o.ViewPlugin.fromClass(class{constructor(e){this.selectionInsideVariable=l(e),this.placeholders=a.createDeco(e)}update(e){if(e.selectionSet||e.docChanged){const t=l(e.view);if(t!==this.selectionInsideVariable){this.selectionInsideVariable=t,this.placeholders=a.createDeco(e.view);return}}this.placeholders=a.updateDeco(e,this.placeholders)}},{decorations:e=>e.placeholders,provide:e=>o.EditorView.atomicRanges.of(t=>t.plugin(e)?.placeholders||o.Decoration.none)});exports.default=x;
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 MatchDecorator,\n} from \"@codemirror/view\";\nimport { SelectedOption } from \"../types\";\nimport PlaceholderWidget from \"./PlaceholderWidget\";\nimport { createVariableExpressionRegexp } from \"../utils\";\n\nconst variableContextRegexp = createVariableExpressionRegexp();\n\nconst selectionInsideAnyVariable = (view: EditorView) => {\n const docText = view.state.doc.toString();\n if (!docText) return false;\n const regexp = createVariableExpressionRegexp();\n let match: RegExpExecArray | null;\n while ((match = regexp.exec(docText)) !== null) {\n const from = match.index ?? 0;\n const to = from + match[0].length;\n if (selectionInsideVariableExpression(view, from, to)) {\n return true;\n }\n if (regexp.lastIndex === match.index) {\n regexp.lastIndex++;\n }\n }\n return false;\n};\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 variableUrlMatcher = new MatchDecorator({\n regexp: variableContextRegexp,\n decoration: (match, view, from) => {\n const rawMatch = match?.[0];\n if (!rawMatch) {\n return null;\n }\n const to = from + rawMatch.length;\n if (selectionInsideVariableExpression(view, from, to)) {\n return null;\n }\n return Decoration.replace({\n widget: new PlaceholderWidget(\n rawMatch,\n {\n tag: \"variable\",\n title: match?.[1],\n },\n \"tag-variable\",\n SelectedOption.Variable,\n view\n ),\n });\n },\n});\n\nconst VariablePlaceholder = ViewPlugin.fromClass(\n class {\n placeholders: DecorationSet;\n selectionInsideVariable: boolean;\n constructor(view: EditorView) {\n this.selectionInsideVariable = selectionInsideAnyVariable(view);\n this.placeholders = variableUrlMatcher.createDeco(view);\n }\n update(update: ViewUpdate) {\n if (update.selectionSet || update.docChanged) {\n const insideNow = selectionInsideAnyVariable(update.view);\n if (insideNow !== this.selectionInsideVariable) {\n this.selectionInsideVariable = insideNow;\n this.placeholders = variableUrlMatcher.createDeco(update.view);\n return;\n }\n }\n this.placeholders = variableUrlMatcher.updateDeco(\n update,\n this.placeholders\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":["variableContextRegexp","createVariableExpressionRegexp","selectionInsideAnyVariable","view","docText","regexp","match","from","to","selectionInsideVariableExpression","innerStart","innerEnd","range","isAnchorInside","isHeadInside","variableUrlMatcher","MatchDecorator","rawMatch","Decoration","PlaceholderWidget","SelectedOption","VariablePlaceholder","ViewPlugin","update","insideNow","instance","plugin","EditorView"],"mappings":"8QAYMA,EAAwBC,EAAAA,+BAAA,EAExBC,EAA8BC,GAAqB,CACvD,MAAMC,EAA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A,EAAO,cAAgBA,EAAO,WAAY,CAC5C,MAAMC,EAAYtB,EAA2BqB,EAAO,IAAI,EACxD,GAAIC,IAAc,KAAK,wBAAyB,CAC9C,KAAK,wBAA0BA,EAC/B,KAAK,aAAeT,EAAmB,WAAWQ,EAAO,IAAI,EAC7D,MACF,CACF,CACA,KAAK,aAAeR,EAAmB,WACrCQ,EACA,KAAK,YAAA,CAET,CAAA,EAEF,CACE,YAAcE,GAAaA,EAAS,aACpC,QAAUC,GACRC,EAAAA,WAAW,aAAa,GAAIxB,GACnBA,EAAK,OAAOuB,CAAM,GAAG,cAAgBR,EAAAA,WAAW,IACxD,CAAA,CAEP"}
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,EAA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AAK,aAAeb,EAAkBY,EAAO,KAAM,KAAK,OAAO,EAEnE,CACF,CAAA,EAEF,CACE,YAAcE,GAAaA,EAAS,aACpC,QAAUC,GACRC,EAAAA,WAAW,aAAa,GAAIxB,GACnBA,EAAK,OAAOuB,CAAM,GAAG,cAAgBZ,EAAAA,WAAW,IACxD,CAAA,CAEP"}
@@ -1,7 +1,9 @@
1
1
  import { DecorationSet, ViewPlugin, ViewUpdate } from '@codemirror/view';
2
+ import { findDocumentVariableMarkers } from '../utils.js';
2
3
  declare const VariablePlaceholder: ViewPlugin<{
3
4
  placeholders: DecorationSet;
4
- selectionInsideVariable: boolean;
5
+ markers: ReturnType<typeof findDocumentVariableMarkers>;
6
+ selectionSignature: string;
5
7
  update(update: ViewUpdate): void;
6
8
  }, undefined>;
7
9
  export default VariablePlaceholder;