markdown-flow-ui 0.3.1 → 0.3.2-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 (115) hide show
  1. package/README.md +13 -0
  2. package/dist/_virtual/index.es3.js +4 -5
  3. package/dist/_virtual/index.es3.js.map +1 -1
  4. package/dist/_virtual/index.es4.js +5 -4
  5. package/dist/_virtual/index.es4.js.map +1 -1
  6. package/dist/_virtual/index.es6.js +5 -3
  7. package/dist/_virtual/index.es6.js.map +1 -1
  8. package/dist/_virtual/index.es7.js +3 -5
  9. package/dist/_virtual/index.es7.js.map +1 -1
  10. package/dist/_virtual/index3.cjs +1 -1
  11. package/dist/_virtual/index4.cjs +1 -1
  12. package/dist/_virtual/index6.cjs +1 -1
  13. package/dist/_virtual/index7.cjs +1 -1
  14. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs +1 -1
  15. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs.map +1 -1
  16. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.d.ts +2 -0
  17. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js +440 -415
  18. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js.map +1 -1
  19. package/dist/components/MarkdownFlowEditor/components/EditorToolbar.cjs +1 -1
  20. package/dist/components/MarkdownFlowEditor/components/EditorToolbar.cjs.map +1 -1
  21. package/dist/components/MarkdownFlowEditor/components/EditorToolbar.d.ts +1 -0
  22. package/dist/components/MarkdownFlowEditor/components/EditorToolbar.es.js +71 -68
  23. package/dist/components/MarkdownFlowEditor/components/EditorToolbar.es.js.map +1 -1
  24. package/dist/components/MarkdownFlowEditor/editorI18n.d.ts +22 -0
  25. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.cjs +1 -1
  26. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.d.ts +2 -1
  27. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.es.js +16 -14
  28. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.es.js.map +1 -1
  29. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.cjs +1 -1
  30. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.d.ts +2 -1
  31. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.es.js +19 -17
  32. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.es.js.map +1 -1
  33. package/dist/components/MarkdownFlowEditor/locales/en-US.json.cjs +1 -1
  34. package/dist/components/MarkdownFlowEditor/locales/en-US.json.d.ts +2 -1
  35. package/dist/components/MarkdownFlowEditor/locales/en-US.json.es.js +15 -13
  36. package/dist/components/MarkdownFlowEditor/locales/en-US.json.es.js.map +1 -1
  37. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.cjs +1 -1
  38. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.d.ts +2 -1
  39. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.es.js +21 -19
  40. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.es.js.map +1 -1
  41. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.cjs +1 -1
  42. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.d.ts +2 -1
  43. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.es.js +27 -25
  44. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.es.js.map +1 -1
  45. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.cjs +1 -1
  46. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.d.ts +2 -1
  47. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.es.js +21 -19
  48. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.es.js.map +1 -1
  49. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.cjs +1 -1
  50. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.d.ts +2 -1
  51. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.es.js +19 -17
  52. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.es.js.map +1 -1
  53. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.cjs +1 -1
  54. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.d.ts +2 -1
  55. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.es.js +18 -16
  56. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.es.js.map +1 -1
  57. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.cjs +1 -1
  58. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.d.ts +2 -1
  59. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.es.js +17 -15
  60. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.es.js.map +1 -1
  61. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.cjs +1 -1
  62. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.d.ts +2 -1
  63. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.es.js +25 -23
  64. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.es.js.map +1 -1
  65. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.cjs +1 -1
  66. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.d.ts +2 -1
  67. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.es.js +28 -26
  68. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.es.js.map +1 -1
  69. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.cjs +3 -3
  70. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.cjs.map +1 -1
  71. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.d.ts +5 -1
  72. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.es.js +154 -149
  73. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.es.js.map +1 -1
  74. package/dist/components/MarkdownFlowEditor/utils.cjs +1 -1
  75. package/dist/components/MarkdownFlowEditor/utils.cjs.map +1 -1
  76. package/dist/components/MarkdownFlowEditor/utils.d.ts +2 -0
  77. package/dist/components/MarkdownFlowEditor/utils.es.js +54 -52
  78. package/dist/components/MarkdownFlowEditor/utils.es.js.map +1 -1
  79. package/dist/components/ui/inputGroup/textarea.cjs +1 -1
  80. package/dist/components/ui/inputGroup/textarea.es.js +1 -1
  81. package/dist/node_modules/hast-util-to-jsx-runtime/lib/index.cjs +1 -1
  82. package/dist/node_modules/hast-util-to-jsx-runtime/lib/index.es.js +1 -1
  83. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-5PPSVZJV.cjs +1 -1
  84. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-5PPSVZJV.es.js +1 -1
  85. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-2GRJ4B5K.cjs +1 -1
  86. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-2GRJ4B5K.es.js +1 -1
  87. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-NSK5VX7P.cjs +1 -1
  88. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/chunk-NSK5VX7P.es.js +1 -1
  89. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/classDiagram-JCYQIIEL.cjs +1 -1
  90. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/classDiagram-JCYQIIEL.es.js +1 -1
  91. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/classDiagram-v2-OCEON4UE.cjs +1 -1
  92. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/classDiagram-v2-OCEON4UE.es.js +1 -1
  93. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/flowDiagram-UKHOOZJN.cjs +1 -1
  94. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/flowDiagram-UKHOOZJN.es.js +1 -1
  95. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-PKOTCBZU.cjs +1 -1
  96. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-PKOTCBZU.es.js +1 -1
  97. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-SI44F4Z6.cjs +1 -1
  98. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-SI44F4Z6.es.js +1 -1
  99. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/stateDiagram-OKZ733FA.cjs +1 -1
  100. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/stateDiagram-OKZ733FA.es.js +1 -1
  101. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/stateDiagram-v2-UEYNNEHI.cjs +1 -1
  102. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/stateDiagram-v2-UEYNNEHI.es.js +1 -1
  103. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/swimlanesDiagram-ULZ7WXOC.cjs +1 -1
  104. package/dist/node_modules/mermaid/dist/chunks/mermaid.core/swimlanesDiagram-ULZ7WXOC.es.js +1 -1
  105. package/dist/node_modules/rc-input/es/BaseInput.cjs +1 -1
  106. package/dist/node_modules/rc-input/es/BaseInput.es.js +1 -1
  107. package/dist/node_modules/rc-textarea/es/ResizableTextArea.cjs +1 -1
  108. package/dist/node_modules/rc-textarea/es/ResizableTextArea.es.js +1 -1
  109. package/dist/node_modules/rc-textarea/es/TextArea.cjs +1 -1
  110. package/dist/node_modules/rc-textarea/es/TextArea.es.js +1 -1
  111. package/dist/node_modules/rc-textarea/es/index.cjs +1 -1
  112. package/dist/node_modules/rc-textarea/es/index.es.js +1 -1
  113. package/dist/node_modules/remark-flow/dist/interaction-plugin-core.cjs +1 -1
  114. package/dist/node_modules/remark-flow/dist/interaction-plugin-core.es.js +1 -1
  115. package/package.json +1 -1
@@ -1,215 +1,220 @@
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";
1
+ import { ViewPlugin as P, Decoration as L } from "../../../node_modules/@codemirror/view/dist/index.es.js";
2
+ import { RangeSetBuilder as _ } from "../../../node_modules/@codemirror/state/dist/index.es.js";
3
+ import { getMarkdownSourceAnalysis as Q } from "../../ContentRender/utils/inline-code-ranges.es.js";
4
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 }];
5
+ const H = /<!--[\s\S]*?-->/g, W = (n) => {
6
+ const s = N.findVariableMarkers(n), f = n.indexOf("{{", s.at(-1)?.end ?? 0);
7
+ return f === -1 ? s : [...s, { start: f, end: n.length, name: null }];
8
8
  }, M = new RegExp(
9
9
  `\\?\\[(${N.INTERACTION_CONTENT_SOURCE})\\](?!\\()`,
10
10
  "g"
11
- ), _ = (n) => L(n).interactions;
12
- function U(n, i) {
11
+ ), U = (n) => Q(n).interactions;
12
+ function $(n, s) {
13
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,
14
+ let i = null, d = 0;
15
+ for (; d <= n.length; ) {
16
+ const a = n.indexOf(`
17
+ `, d), r = a === -1 ? n.length : a;
18
+ if (n.slice(d, r).trim() === "!===" && !s(d) && (i === null ? i = d : (f.push({
19
+ from: i,
20
+ to: r,
21
21
  className: "syntax-fixed"
22
- }), l = null)), u === -1)
22
+ }), i = null)), a === -1)
23
23
  break;
24
- s = u + 1;
24
+ d = a + 1;
25
25
  }
26
26
  return f;
27
27
  }
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;
28
+ function j(n, s, f) {
29
+ const i = [];
30
+ let d = 0;
31
+ const a = (t) => {
32
+ for (; d < s.length && s[d].to <= t; )
33
+ d++;
34
+ const o = s[d];
35
+ return !!o && t >= o.from && t < o.to;
36
36
  };
37
- let e = 0;
38
- for (; e <= n.length; ) {
37
+ let r = 0;
38
+ for (; r <= n.length; ) {
39
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)
40
+ `, r), o = t === -1 ? n.length : t, l = n.slice(r, o), g = [];
41
+ let p = 0;
42
+ for (; p < l.length; ) {
43
+ const m = l.indexOf("===", p);
44
+ if (m === -1)
45
45
  break;
46
- const p = e + c;
47
- !(p > 0 && n[p - 1] === "!") && !u(p) && !f(p) && x.push(p), g = c + 3;
46
+ const h = r + m;
47
+ !(h > 0 && n[h - 1] === "!") && !a(h) && !f(h) && g.push(h), p = m + 3;
48
48
  }
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
+ for (let m = 0; m + 1 < g.length; m += 2)
50
+ i.push({
51
+ from: g[m],
52
+ to: g[m + 1] + 3,
53
53
  className: "syntax-fixed"
54
54
  });
55
55
  if (t === -1)
56
56
  break;
57
- e = t + 1;
57
+ r = t + 1;
58
58
  }
59
- return l;
59
+ return i;
60
60
  }
61
- function j(n, i) {
61
+ function z(n, s) {
62
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,
63
+ let i;
64
+ for (H.lastIndex = 0; (i = H.exec(n)) !== null; )
65
+ s(i.index) || f.push({
66
+ from: i.index,
67
+ to: i.index + i[0].length,
68
68
  className: "syntax-comment"
69
69
  });
70
70
  return f;
71
71
  }
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
- ...$(
72
+ function G(n) {
73
+ const s = N.findDocumentVariableMarkers(n), f = (r) => s.some(
74
+ (t) => r >= t.start && r < t.end
75
+ ), i = z(n, f), d = [
76
+ ...$(n, f),
77
+ ...j(
78
78
  n,
79
- l,
79
+ i,
80
80
  f
81
81
  ),
82
- ...l
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);
82
+ ...i
83
+ ].sort((r, t) => r.from !== t.from ? r.from - t.from : t.to - r.to), a = [];
84
+ for (const r of d) {
85
+ const t = a[a.length - 1];
86
+ (!t || r.from >= t.to) && a.push(r);
87
87
  }
88
- return u;
88
+ return a;
89
89
  }
90
- function z(n, i = () => !1) {
91
- const f = [], l = N.findDocumentVariableMarkers(n), s = [];
90
+ function J(n, s = () => !1, f = !1) {
91
+ const i = [], d = N.findDocumentVariableMarkers(n), a = [];
92
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)
93
+ const r = (o, l) => a.some((g) => !(l <= g.from || o >= g.to)), t = (o, l, g) => o >= l || r(o, l) ? !1 : (a.push({ from: o, to: l }), i.push({ from: o, to: l, className: g }), !0);
94
+ for (const o of G(n))
95
+ t(o.from, o.to, o.className);
96
+ for (const o of U(n)) {
97
+ M.lastIndex = o.start;
98
+ const l = M.exec(n);
99
+ if (!l || l.index !== o.start || l.index + l[0].length !== o.end)
100
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
101
+ const g = l.index, p = l.index + l[0].length, m = l[1], h = g + 2;
102
+ if (r(g, p) || d.some(
103
+ (y) => y.start <= g && g < y.end
104
104
  ))
105
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";
106
+ t(g, g + 1, "syntax-keyword"), t(g + 1, g + 2, "syntax-bracket"), t(p - 1, p, "syntax-bracket");
107
+ const E = W(m), b = E[0], O = b ? b.start - 1 : -1, I = O >= 0 && m[O] === "%" && N.trimVariablePadding(m.slice(0, O)) === "";
108
+ if (m.startsWith("%") || I) {
109
+ let y = "syntax-percent-invalid";
110
+ if (b && I) {
111
+ const e = h + b.start, x = h + b.end, C = s(e, x);
112
+ y = b.name !== null && !C ? "syntax-percent-valid" : "syntax-percent-invalid";
113
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"
114
+ const v = h + (I ? O : 0);
115
+ t(v, v + 1, y);
116
+ const V = [], S = [], R = [];
117
+ for (const e of E)
118
+ S.push({
119
+ from: h + e.start,
120
+ to: h + e.end,
121
+ className: e.name === null ? "syntax-variable-invalid" : "syntax-variable"
122
122
  });
123
- let m = 0;
124
- for (; m < g.length; ) {
125
- const o = R.find(
126
- (I) => c + m === I.from
123
+ let u = 0;
124
+ for (; u < m.length; ) {
125
+ const e = S.find(
126
+ (C) => h + u === C.from
127
127
  );
128
- if (o) {
129
- m = o.to - c;
128
+ if (e) {
129
+ u = e.to - h;
130
130
  continue;
131
131
  }
132
- if (N.isEscape(g, m)) {
133
- m += 2;
132
+ if (N.isEscape(m, u)) {
133
+ u += 2;
134
134
  continue;
135
135
  }
136
- const h = g.startsWith("||", m) ? "||" : g[m] === "|" ? "|" : g.startsWith("...", m) ? "..." : null;
137
- if (!h) {
138
- m += 1;
136
+ const x = m.startsWith("||", u) ? "||" : m[u] === "|" ? "|" : m.startsWith("...", u) ? "..." : null;
137
+ if (!x) {
138
+ u += 1;
139
139
  continue;
140
140
  }
141
141
  V.push({
142
- from: c + m,
143
- to: c + m + h.length
144
- }), m += h.length;
142
+ from: h + u,
143
+ to: h + u + x.length
144
+ }), u += x.length;
145
145
  }
146
- const a = [
147
- ...V.map((o) => ({
148
- ...o,
146
+ const c = [
147
+ ...V.map((e) => ({
148
+ ...e,
149
149
  className: "syntax-keyword"
150
150
  })),
151
- ...R.map((o) => ({
152
- ...o,
153
- className: o.className
151
+ ...S.map((e) => ({
152
+ ...e,
153
+ className: e.className
154
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;
155
+ ].sort((e, x) => e.from !== x.from ? e.from - x.from : e.to - x.to);
156
+ for (const e of c)
157
+ e.className.startsWith("syntax-variable") && s(e.from, e.to) || t(e.from, e.to, e.className) && R.push({ from: e.from, to: e.to });
158
+ const w = v + 1, F = p - 1;
159
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");
160
+ const B = R.sort((e, x) => e.from !== x.from ? e.from - x.from : e.to - x.to);
161
+ for (const e of B)
162
+ k < e.from && t(k, e.from, "syntax-string"), k = Math.max(k, e.to);
163
+ k < F && t(k, F, "syntax-string");
164
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"
165
+ const y = [], v = [];
166
+ for (const c of W(m))
167
+ y.push({
168
+ from: h + c.start,
169
+ to: h + c.end,
170
+ className: c.name === null ? "syntax-variable-invalid" : "syntax-variable"
171
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");
172
+ const V = y.sort((c, w) => c.from !== w.from ? c.from - w.from : c.to - w.to);
173
+ for (const c of V)
174
+ c.className.startsWith("syntax-variable") && s(c.from, c.to) || t(c.from, c.to, c.className) && v.push({ from: c.from, to: c.to });
175
+ const S = h, R = p - 1;
176
+ let u = S;
177
+ for (const c of v)
178
+ u < c.from && t(u, c.from, "syntax-button-text"), u = Math.max(u, c.to);
179
+ u < R && t(u, R, "syntax-button-text");
180
180
  }
181
181
  }
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;
182
+ for (const o of f ? [] : d)
183
+ o.name !== null && !s(o.start, o.end) && t(o.start, o.end, "syntax-variable");
184
+ return i.sort((o, l) => o.from !== l.from ? o.from - l.from : l.to - o.to), i;
185
185
  }
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)
186
+ function A(n, s = !1) {
187
+ const f = new _(), i = n.state.doc.toString(), d = J(
188
+ i,
189
+ (a, r) => n.state.selection.ranges.some((t) => t.from >= a && t.to <= r),
190
+ s
191
+ );
192
+ for (const a of d)
193
+ if (a.from < a.to)
190
194
  try {
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);
195
+ f.add(a.from, a.to, L.mark({ class: a.className }));
196
+ } catch (r) {
197
+ console.warn("SyntaxHighlighter: Failed to add decoration", a, r);
194
198
  }
195
- return i.finish();
199
+ return f.finish();
196
200
  }
197
- const T = B.fromClass(
201
+ const D = (n = !1) => P.fromClass(
198
202
  class {
199
- constructor(n) {
200
- this.decorations = A(n);
203
+ constructor(s) {
204
+ this.decorations = A(s, n);
201
205
  }
202
- update(n) {
203
- (n.docChanged || n.viewportChanged || n.selectionSet) && (this.decorations = A(n.view));
206
+ update(s) {
207
+ (s.docChanged || s.viewportChanged || s.selectionSet) && (this.decorations = A(s.view, n));
204
208
  }
205
209
  },
206
210
  {
207
- decorations: (n) => n.decorations
211
+ decorations: (s) => s.decorations
208
212
  }
209
- );
213
+ ), Z = D(), q = D(!0);
210
214
  export {
211
- q as collectOuterBlockRanges,
212
- z as collectSyntaxHighlightRanges,
213
- T as default
215
+ q as QuestionSyntaxHighlighter,
216
+ G as collectOuterBlockRanges,
217
+ J as collectSyntaxHighlightRanges,
218
+ Z as default
214
219
  };
215
220
  //# 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 { 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,GAAGA,GAAS,EAAE,OAAOE,GAAS,KAAKH,EAAK,QAAQ,MAAM,MAAM;AACnE,GAKMI,IAAoB,IAAI;AAAA,EAC5B,UAAUC,EAAAA,0BAA0B;AAAA,EACpC;AACF,GAEMC,IAAwB,CAACN,MAC7BO,EAA0BP,CAAI,EAAE;AAQlC,SAASQ,EACPC,GACAC,GACwB;AACxB,QAAMC,IAAiC,C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,KAAKD,EAAE,EACjB,GAEMM;AACT;AAEA,SAASuC,EAAiBC,GAAiC;AACzD,QAAMC,IAAU,IAAIC,EAAA,GACd3E,IAAUyE,EAAK,MAAM,IAAI,SAAA,GACzBxC,IAAUF,EAA6B/B,GAAS,CAACqC,GAAMC,MACpDmC,EAAK,MAAM,UAAU,OAAO,KAAK,CAAC7D,MAChCA,EAAM,QAAQyB,KAAQzB,EAAM,MAAM0B,CAC1C,CACF;AAED,aAAWsC,KAAK3C;AACd,QAAI2C,EAAE,OAAOA,EAAE;AACb,UAAI;AACF,QAAAF,EAAQ,IAAIE,EAAE,MAAMA,EAAE,IAAIC,EAAW,KAAK,EAAE,OAAOD,EAAE,UAAA,CAAW,CAAC;AAAA,MACnE,SAASE,GAAG;AACV,gBAAQ,KAAK,+CAA+CF,GAAGE,CAAC;AAAA,MAClE;AAIJ,SAAOJ,EAAQ,OAAA;AACjB;AAEA,MAAMK,IAAoBC,EAAW;AAAA,EACnC,MAAM;AAAA,IAGJ,YAAYP,GAAkB;AAC5B,WAAK,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 questionMode = 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 questionMode ? [] : 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(\n view: EditorView,\n questionMode = false\n): DecorationSet {\n const builder = new RangeSetBuilder<Decoration>();\n const docText = view.state.doc.toString();\n const matches = collectSyntaxHighlightRanges(\n docText,\n (from, to) => {\n return view.state.selection.ranges.some((range) => {\n return range.from >= from && range.to <= to;\n });\n },\n questionMode\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 createSyntaxHighlighter = (questionMode = false) =>\n ViewPlugin.fromClass(\n class {\n decorations: DecorationSet;\n\n constructor(view: EditorView) {\n this.decorations = buildDecorations(view, questionMode);\n }\n\n update(update: ViewUpdate) {\n if (\n update.docChanged ||\n update.viewportChanged ||\n update.selectionSet\n ) {\n this.decorations = buildDecorations(update.view, questionMode);\n }\n }\n },\n {\n decorations: (instance) => instance.decorations,\n }\n );\n\nconst SyntaxHighlighter = createSyntaxHighlighter();\nexport const QuestionSyntaxHighlighter = createSyntaxHighlighter(true);\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","questionMode","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","createSyntaxHighlighter","ViewPlugin","update","instance","SyntaxHighlighter","QuestionSyntaxHighlighter"],"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,GAAGA,GAAS,EAAE,OAAOE,GAAS,KAAKH,EAAK,QAAQ,MAAM,MAAM;AACnE,GAKMI,IAAoB,IAAI;AAAA,EAC5B,UAAUC,EAAAA,0BAA0B;AAAA,EACpC;AACF,GAEMC,IAAwB,CAACN,MAC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video.cjs"),d=require("../../_virtual/index.cjs"),s="===",$=(t,e)=>{switch(t){case m.SelectedOption.Image:return{resourceUrl:e.url,resourceTitle:e.title,scalePercent:e.scalePercent};case m.SelectedOption.Video:return{resourceUrl:e.url,resourceTitle:e.title};case m.SelectedOption.Variable:return{variableName:d.distExports.normalizeVariableName(e.title??"")??void 0};default:return{resourceUrl:e.url??"",resourceTitle:e.title??""}}};function V(t,e){return i=>{const a=i.matchBefore(/\/(\w*)$/);if(!a)return null;const c=(r,n,o,l,u)=>{r.dispatch({changes:{from:o,to:l,insert:""}}),t(u)};return{from:a.from,to:a.to,options:[{label:e?.variable??"Variable",apply:(r,n,o,l)=>{c(r,n,o,l,m.SelectedOption.Variable)}},{label:e?.image??"Image",apply:(r,n,o,l)=>{c(r,n,o,l,m.SelectedOption.Image)}},{label:e?.video??"Video",apply:(r,n,o,l)=>{c(r,n,o,l,m.SelectedOption.Video)}}],filter:!1}}}const f=t=>g.getVideoEmbedUrl(t),p=t=>t.replace(/&/g,"&amp;").replace(/"/g,"&quot;"),w=t=>t.replace(/([\[\]\\])/g,"\\$1"),h=t=>Math.max(1,Math.min(1e3,Math.round(t))),b=t=>{const e=t.trim();return e?new RegExp(`^${s}\\s*[\\s\\S]*?\\s*${s}$`).test(e)?e:`${s} ${e} ${s}`:`${s}${s}`},x=t=>{const e=t.trim(),i=new RegExp(`^${s}\\s*([\\s\\S]*?)\\s*${s}$`);return(e.match(i)?.[1]??e).trim()},E=({resourceUrl:t,resourceTitle:e,scalePercent:i})=>{const a=typeof i=="number"?h(i):void 0,c=p(t),r=e?p(e):void 0,n=e?w(e):"",o=typeof a=="number"&&a!==100?` width="${a}%"`:"",l=r?` alt="${r}" title="${r}"`:"",u=!a||a===100?`![${n}](${t})`:`<img src="${c}"${l}${o} />`;return b(u)},S=(t,e)=>{const i=f(t),a=e?p(e):"",c=p(t),r=p(i),n=`<iframe data-tag="video" data-title="${a}" data-url="${c}" class="w-full aspect-video rounded-lg border-0" src="${r}" allowfullscreen="" allow="autoplay; encrypted-media"></iframe>`;return b(n)};exports.createSlashCommands=V;exports.extractVariableNames=d.distExports.extractVariableNames;exports.findDocumentVariableMarkers=d.distExports.findDocumentVariableMarkers;exports.findVariableMarkers=d.distExports.findVariableMarkers;exports.formatVariableReference=d.distExports.formatVariableReference;exports.getEmbedUrl=f;exports.getImageContentToInsert=E;exports.getVideoContentToInsert=S;exports.normalizeVariableName=d.distExports.normalizeVariableName;exports.parseContentInfo=$;exports.trimVariablePadding=d.distExports.trimVariablePadding;exports.unwrapFixedOutput=x;exports.wrapWithFixedOutput=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./types.cjs"),$=require("./utils/video.cjs"),m=require("../../_virtual/index.cjs"),c="===",V=(t,e)=>{switch(t){case p.SelectedOption.Image:return{resourceUrl:e.url,resourceTitle:e.title,scalePercent:e.scalePercent};case p.SelectedOption.Video:return{resourceUrl:e.url,resourceTitle:e.title};case p.SelectedOption.Variable:return{variableName:m.distExports.normalizeVariableName(e.title??"")??void 0};default:return{resourceUrl:e.url??"",resourceTitle:e.title??""}}};function w(t,e,{enableVariables:n=!0}={}){return a=>{const d=a.matchBefore(/\/(\w*)$/);if(!d)return null;const i=(r,s,o,l,g)=>{r.dispatch({changes:{from:o,to:l,insert:""}}),t(g)};return{from:d.from,to:d.to,options:[...n?[{label:e?.variable??"Variable",apply:(r,s,o,l)=>{i(r,s,o,l,p.SelectedOption.Variable)}}]:[],{label:e?.image??"Image",apply:(r,s,o,l)=>{i(r,s,o,l,p.SelectedOption.Image)}},{label:e?.video??"Video",apply:(r,s,o,l)=>{i(r,s,o,l,p.SelectedOption.Video)}}],filter:!1}}}const f=t=>$.getVideoEmbedUrl(t),u=t=>t.replace(/&/g,"&amp;").replace(/"/g,"&quot;"),h=t=>t.replace(/([\[\]\\])/g,"\\$1"),x=t=>Math.max(1,Math.min(1e3,Math.round(t))),b=t=>{const e=t.trim();return e?new RegExp(`^${c}\\s*[\\s\\S]*?\\s*${c}$`).test(e)?e:`${c} ${e} ${c}`:`${c}${c}`},E=t=>{const e=t.trim(),n=new RegExp(`^${c}\\s*([\\s\\S]*?)\\s*${c}$`);return(e.match(n)?.[1]??e).trim()},S=({resourceUrl:t,resourceTitle:e,scalePercent:n})=>{const a=typeof n=="number"?x(n):void 0,d=u(t),i=e?u(e):void 0,r=e?h(e):"",s=typeof a=="number"&&a!==100?` width="${a}%"`:"",o=i?` alt="${i}" title="${i}"`:"",l=!a||a===100?`![${r}](${t})`:`<img src="${d}"${o}${s} />`;return b(l)},I=(t,e)=>{const n=f(t),a=e?u(e):"",d=u(t),i=u(n),r=`<iframe data-tag="video" data-title="${a}" data-url="${d}" class="w-full aspect-video rounded-lg border-0" src="${i}" allowfullscreen="" allow="autoplay; encrypted-media"></iframe>`;return b(r)};exports.createSlashCommands=w;exports.extractVariableNames=m.distExports.extractVariableNames;exports.findDocumentVariableMarkers=m.distExports.findDocumentVariableMarkers;exports.findVariableMarkers=m.distExports.findVariableMarkers;exports.formatVariableReference=m.distExports.formatVariableReference;exports.getEmbedUrl=f;exports.getImageContentToInsert=S;exports.getVideoContentToInsert=I;exports.normalizeVariableName=m.distExports.normalizeVariableName;exports.parseContentInfo=V;exports.trimVariablePadding=m.distExports.trimVariablePadding;exports.unwrapFixedOutput=E;exports.wrapWithFixedOutput=b;
2
2
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sources":["../../../src/components/MarkdownFlowEditor/utils.ts"],"sourcesContent":["import {\n type CompletionContext,\n type CompletionResult,\n} from \"@codemirror/autocomplete\";\nimport { EditorView } from \"@codemirror/view\";\nimport { SelectedOption } from \"./types\";\nimport { getVideoEmbedUrl } from \"./utils/video\";\n\nimport {\n createVariableExpressionRegex,\n extractVariableNames,\n findVariableMarkers,\n findDocumentVariableMarkers,\n formatVariableReference,\n formatVariableAssignment,\n isValidVariableName,\n normalizeVariableName,\n trimVariablePadding,\n} from \"remark-flow\";\n\nconst FIXED_OUTPUT_MARKER = \"===\";\nconst createVariableExpressionRegexp = () =>\n createVariableExpressionRegex(\"gu\");\n\nconst parseContentInfo = (\n type: SelectedOption,\n dataset: { title?: string; url?: string; scalePercent?: number }\n) => {\n switch (type) {\n case SelectedOption.Image:\n return {\n resourceUrl: dataset.url,\n resourceTitle: dataset.title,\n scalePercent: dataset.scalePercent,\n };\n\n case SelectedOption.Video:\n return {\n resourceUrl: dataset.url,\n resourceTitle: dataset.title,\n };\n case SelectedOption.Variable:\n return {\n variableName: normalizeVariableName(dataset.title ?? \"\") ?? undefined,\n };\n default:\n return {\n resourceUrl: dataset.url ?? \"\",\n resourceTitle: dataset.title ?? \"\",\n };\n }\n};\n\nfunction createSlashCommands(\n onSelectOption: (selectedOption: SelectedOption) => void,\n labels?: {\n divider?: string;\n fixedText?: string;\n image?: string;\n video?: string;\n variable?: string;\n }\n) {\n return (context: CompletionContext): CompletionResult | null => {\n const word = context.matchBefore(/\\/(\\w*)$/);\n if (!word) return null;\n\n const handleSelect = (\n view: EditorView,\n _: any,\n from: number,\n to: number,\n selectedOption: SelectedOption\n ) => {\n view.dispatch({\n changes: { from, to, insert: \"\" },\n });\n onSelectOption(selectedOption);\n };\n\n return {\n from: word.from,\n to: word.to,\n options: [\n // {\n // label: labels?.divider ?? \"Divider\",\n // apply: (view, _, from, to) => {\n // handleSelect(view, _, from, to, SelectedOption.Divider);\n // },\n // },\n // {\n // label: labels?.fixedText ?? \"Fixed Text\",\n // apply: (view, _, from, to) => {\n // handleSelect(view, _, from, to, SelectedOption.FixedText);\n // },\n // },\n {\n label: labels?.variable ?? \"Variable\",\n apply: (view, _, from, to) => {\n handleSelect(view, _, from, to, SelectedOption.Variable);\n },\n },\n {\n label: labels?.image ?? \"Image\",\n apply: (view, _, from, to) => {\n handleSelect(view, _, from, to, SelectedOption.Image);\n },\n },\n {\n label: labels?.video ?? \"Video\",\n apply: (view, _, from, to) => {\n handleSelect(view, _, from, to, SelectedOption.Video);\n },\n },\n ],\n filter: false,\n };\n };\n}\n\nconst getEmbedUrl = (url: string) => {\n return getVideoEmbedUrl(url);\n};\n\nconst escapeHtmlAttribute = (value: string) =>\n value.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\");\n\nconst escapeMarkdownText = (text: string) =>\n text.replace(/([\\[\\]\\\\])/g, \"\\\\$1\");\n\nconst clampScalePercent = (value: number) =>\n Math.max(1, Math.min(1000, Math.round(value)));\n\nconst wrapWithFixedOutput = (content: string) => {\n const normalizedContent = content.trim();\n if (!normalizedContent) {\n return `${FIXED_OUTPUT_MARKER}${FIXED_OUTPUT_MARKER}`;\n }\n const wrappedPattern = new RegExp(\n `^${FIXED_OUTPUT_MARKER}\\\\s*[\\\\s\\\\S]*?\\\\s*${FIXED_OUTPUT_MARKER}$`\n );\n if (wrappedPattern.test(normalizedContent)) {\n return normalizedContent;\n }\n return `${FIXED_OUTPUT_MARKER} ${normalizedContent} ${FIXED_OUTPUT_MARKER}`;\n};\n\nconst unwrapFixedOutput = (content: string) => {\n const normalizedContent = content.trim();\n const wrappedPattern = new RegExp(\n `^${FIXED_OUTPUT_MARKER}\\\\s*([\\\\s\\\\S]*?)\\\\s*${FIXED_OUTPUT_MARKER}$`\n );\n const match = normalizedContent.match(wrappedPattern);\n return (match?.[1] ?? normalizedContent).trim();\n};\n\nconst getImageContentToInsert = ({\n resourceUrl,\n resourceTitle,\n scalePercent,\n}: {\n resourceUrl: string;\n resourceTitle?: string;\n scalePercent?: number;\n}) => {\n const clampedScale =\n typeof scalePercent === \"number\"\n ? clampScalePercent(scalePercent)\n : undefined;\n const sanitizedHtmlUrl = escapeHtmlAttribute(resourceUrl);\n const sanitizedTitle = resourceTitle\n ? escapeHtmlAttribute(resourceTitle)\n : undefined;\n const markdownTitle = resourceTitle ? escapeMarkdownText(resourceTitle) : \"\";\n const widthAttribute =\n typeof clampedScale === \"number\" && clampedScale !== 100\n ? ` width=\"${clampedScale}%\"`\n : \"\";\n const htmlTitleAttributes = sanitizedTitle\n ? ` alt=\"${sanitizedTitle}\" title=\"${sanitizedTitle}\"`\n : \"\";\n const imageMarkup =\n !clampedScale || clampedScale === 100\n ? `![${markdownTitle}](${resourceUrl})`\n : `<img src=\"${sanitizedHtmlUrl}\"${htmlTitleAttributes}${widthAttribute} />`;\n\n return wrapWithFixedOutput(imageMarkup);\n};\n\nconst getVideoContentToInsert = (\n resourceUrl: string,\n resourceTitle: string\n) => {\n const embedUrl = getEmbedUrl(resourceUrl);\n const sanitizedTitle = resourceTitle\n ? escapeHtmlAttribute(resourceTitle)\n : \"\";\n const sanitizedResourceUrl = escapeHtmlAttribute(resourceUrl);\n const sanitizedEmbedUrl = escapeHtmlAttribute(embedUrl);\n const videoMarkup = `<iframe data-tag=\"video\" data-title=\"${sanitizedTitle}\" data-url=\"${sanitizedResourceUrl}\" class=\"w-full aspect-video rounded-lg border-0\" src=\"${sanitizedEmbedUrl}\" allowfullscreen=\"\" allow=\"autoplay; encrypted-media\"></iframe>`;\n\n return wrapWithFixedOutput(videoMarkup);\n};\n\nexport {\n createSlashCommands,\n parseContentInfo,\n getEmbedUrl,\n getImageContentToInsert,\n getVideoContentToInsert,\n isValidVariableName,\n normalizeVariableName,\n trimVariablePadding,\n extractVariableNames,\n findVariableMarkers,\n findDocumentVariableMarkers,\n formatVariableReference,\n formatVariableAssignment,\n createVariableExpressionRegexp,\n wrapWithFixedOutput,\n unwrapFixedOutput,\n};\n"],"names":["FIXED_OUTPUT_MARKER","parseContentInfo","type","dataset","SelectedOption","normalizeVariableName","createSlashCommands","onSelectOption","labels","context","word","handleSelect","view","_","from","to","selectedOption","getEmbedUrl","url","getVideoEmbedUrl","escapeHtmlAttribute","value","escapeMarkdownText","text","clampScalePercent","wrapWithFixedOutput","content","normalizedContent","unwrapFixedOutput","wrappedPattern","getImageContentToInsert","resourceUrl","resourceTitle","scalePercent","clampedScale","sanitizedHtmlUrl","sanitizedTitle","markdownTitle","widthAttribute","htmlTitleAttributes","imageMarkup","getVide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I,EACJ,CAACN,GAAgBA,IAAiB,IAC9B,KAAKG,CAAa,KAAKN,CAAW,IAClC,aAAaI,CAAgB,IAAII,CAAmB,GAAGD,CAAc,MAE3E,OAAOb,EAAoBe,CAAW,CACxC,EAEMC,EAA0B,CAC9BV,EACAC,IACG,CACH,MAAMU,EAAWzB,EAAYc,CAAW,EAClCK,EAAiBJ,EACnBZ,EAAoBY,CAAa,EACjC,GACEW,EAAuBvB,EAAoBW,CAAW,EACtDa,EAAoBxB,EAAoBsB,CAAQ,EAChDG,EAAc,wCAAwCT,CAAc,eAAeO,CAAoB,0DAA0DC,CAAiB,mEAExL,OAAOnB,EAAoBoB,CAAW,CACxC"}
1
+ {"version":3,"file":"utils.cjs","sources":["../../../src/components/MarkdownFlowEditor/utils.ts"],"sourcesContent":["import {\n type Completion,\n type CompletionContext,\n type CompletionResult,\n} from \"@codemirror/autocomplete\";\nimport { EditorView } from \"@codemirror/view\";\nimport { SelectedOption } from \"./types\";\nimport { getVideoEmbedUrl } from \"./utils/video\";\n\nimport {\n createVariableExpressionRegex,\n extractVariableNames,\n findVariableMarkers,\n findDocumentVariableMarkers,\n formatVariableReference,\n formatVariableAssignment,\n isValidVariableName,\n normalizeVariableName,\n trimVariablePadding,\n} from \"remark-flow\";\n\nconst FIXED_OUTPUT_MARKER = \"===\";\nconst createVariableExpressionRegexp = () =>\n createVariableExpressionRegex(\"gu\");\n\nconst parseContentInfo = (\n type: SelectedOption,\n dataset: { title?: string; url?: string; scalePercent?: number }\n) => {\n switch (type) {\n case SelectedOption.Image:\n return {\n resourceUrl: dataset.url,\n resourceTitle: dataset.title,\n scalePercent: dataset.scalePercent,\n };\n\n case SelectedOption.Video:\n return {\n resourceUrl: dataset.url,\n resourceTitle: dataset.title,\n };\n case SelectedOption.Variable:\n return {\n variableName: normalizeVariableName(dataset.title ?? \"\") ?? undefined,\n };\n default:\n return {\n resourceUrl: dataset.url ?? \"\",\n resourceTitle: dataset.title ?? \"\",\n };\n }\n};\n\nfunction createSlashCommands(\n onSelectOption: (selectedOption: SelectedOption) => void,\n labels?: {\n divider?: string;\n fixedText?: string;\n image?: string;\n video?: string;\n variable?: string;\n },\n { enableVariables = true }: { enableVariables?: boolean } = {}\n) {\n return (context: CompletionContext): CompletionResult | null => {\n const word = context.matchBefore(/\\/(\\w*)$/);\n if (!word) return null;\n\n const handleSelect = (\n view: EditorView,\n _: any,\n from: number,\n to: number,\n selectedOption: SelectedOption\n ) => {\n view.dispatch({\n changes: { from, to, insert: \"\" },\n });\n onSelectOption(selectedOption);\n };\n\n return {\n from: word.from,\n to: word.to,\n options: [\n // {\n // label: labels?.divider ?? \"Divider\",\n // apply: (view, _, from, to) => {\n // handleSelect(view, _, from, to, SelectedOption.Divider);\n // },\n // },\n // {\n // label: labels?.fixedText ?? \"Fixed Text\",\n // apply: (view, _, from, to) => {\n // handleSelect(view, _, from, to, SelectedOption.FixedText);\n // },\n // },\n ...(enableVariables\n ? [\n {\n label: labels?.variable ?? \"Variable\",\n apply: (\n view: EditorView,\n _: Completion,\n from: number,\n to: number\n ) => {\n handleSelect(view, _, from, to, SelectedOption.Variable);\n },\n },\n ]\n : []),\n {\n label: labels?.image ?? \"Image\",\n apply: (view, _, from, to) => {\n handleSelect(view, _, from, to, SelectedOption.Image);\n },\n },\n {\n label: labels?.video ?? \"Video\",\n apply: (view, _, from, to) => {\n handleSelect(view, _, from, to, SelectedOption.Video);\n },\n },\n ],\n filter: false,\n };\n };\n}\n\nconst getEmbedUrl = (url: string) => {\n return getVideoEmbedUrl(url);\n};\n\nconst escapeHtmlAttribute = (value: string) =>\n value.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\");\n\nconst escapeMarkdownText = (text: string) =>\n text.replace(/([\\[\\]\\\\])/g, \"\\\\$1\");\n\nconst clampScalePercent = (value: number) =>\n Math.max(1, Math.min(1000, Math.round(value)));\n\nconst wrapWithFixedOutput = (content: string) => {\n const normalizedContent = content.trim();\n if (!normalizedContent) {\n return `${FIXED_OUTPUT_MARKER}${FIXED_OUTPUT_MARKER}`;\n }\n const wrappedPattern = new RegExp(\n `^${FIXED_OUTPUT_MARKER}\\\\s*[\\\\s\\\\S]*?\\\\s*${FIXED_OUTPUT_MARKER}$`\n );\n if (wrappedPattern.test(normalizedContent)) {\n return normalizedContent;\n }\n return `${FIXED_OUTPUT_MARKER} ${normalizedContent} ${FIXED_OUTPUT_MARKER}`;\n};\n\nconst unwrapFixedOutput = (content: string) => {\n const normalizedContent = content.trim();\n const wrappedPattern = new RegExp(\n `^${FIXED_OUTPUT_MARKER}\\\\s*([\\\\s\\\\S]*?)\\\\s*${FIXED_OUTPUT_MARKER}$`\n );\n const match = normalizedContent.match(wrappedPattern);\n return (match?.[1] ?? normalizedContent).trim();\n};\n\nconst getImageContentToInsert = ({\n resourceUrl,\n resourceTitle,\n scalePercent,\n}: {\n resourceUrl: string;\n resourceTitle?: string;\n scalePercent?: number;\n}) => {\n const clampedScale =\n typeof scalePercent === \"number\"\n ? clampScalePercent(scalePercent)\n : undefined;\n const sanitizedHtmlUrl = escapeHtmlAttribute(resourceUrl);\n const sanitizedTitle = resourceTitle\n ? escapeHtmlAttribute(resourceTitle)\n : undefined;\n const markdownTitle = resourceTitle ? escapeMarkdownText(resourceTitle) : \"\";\n const widthAttribute =\n typeof clampedScale === \"number\" && clampedScale !== 100\n ? ` width=\"${clampedScale}%\"`\n : \"\";\n const htmlTitleAttributes = sanitizedTitle\n ? ` alt=\"${sanitizedTitle}\" title=\"${sanitizedTitle}\"`\n : \"\";\n const imageMarkup =\n !clampedScale || clampedScale === 100\n ? `![${markdownTitle}](${resourceUrl})`\n : `<img src=\"${sanitizedHtmlUrl}\"${htmlTitleAttributes}${widthAttribute} />`;\n\n return wrapWithFixedOutput(imageMarkup);\n};\n\nconst getVideoContentToInsert = (\n resourceUrl: string,\n resourceTitle: string\n) => {\n const embedUrl = getEmbedUrl(resourceUrl);\n const sanitizedTitle = resourceTitle\n ? escapeHtmlAttribute(resourceTitle)\n : \"\";\n const sanitizedResourceUrl = escapeHtmlAttribute(resourceUrl);\n const sanitizedEmbedUrl = escapeHtmlAttribute(embedUrl);\n const videoMarkup = `<iframe data-tag=\"video\" data-title=\"${sanitizedTitle}\" data-url=\"${sanitizedResourceUrl}\" class=\"w-full aspect-video rounded-lg border-0\" src=\"${sanitizedEmbedUrl}\" allowfullscreen=\"\" allow=\"autoplay; encrypted-media\"></iframe>`;\n\n return wrapWithFixedOutput(videoMarkup);\n};\n\nexport {\n createSlashCommands,\n parseContentInfo,\n getEmbedUrl,\n getImageContentToInsert,\n getVideoContentToInsert,\n isValidVariableName,\n normalizeVariableName,\n trimVariablePadding,\n extractVariableNames,\n findVariableMarkers,\n findDocumentVariableMarkers,\n formatVariableReference,\n formatVariableAssignment,\n createVariableExpressionRegexp,\n wrapWithFixedOutput,\n unwrapFixedOutput,\n};\n"],"names":["FIXED_OUTPUT_MARKER","parseContentInfo","type","dataset","SelectedOption","normalizeVariableName","createSlashCommands","onSelectOption","labels","enableVariables","context","word","handleSelect","view","_","from","to","selectedOption","getEmbedUrl","url","getVideoEmbedUrl","escapeHtmlAttribute","value","escapeMarkdownText","text","clampScalePercent","wrapWithFixedOutput","content","normalizedContent","unwrapFixedOutput","wrappedPattern","getImageContentToInsert","resourceUrl","resourceTitle","scalePercent","clampedScale","sanitizedHtmlUrl","sanitizedTitle","markdownTitle","widthAttribute","htmlTitleAttributes","imageMarkup","getVideoContentToInsert","embedUrl","sanitizedResourceUrl","sanitizedEmbedUrl","videoMarkup"],"mappings":"oLAqBMA,EAAsB,MAItBC,EAAmB,CACvBC,EACAC,IACG,CACH,OAAQD,EAAA,CACN,KAAKE,EAAAA,eAAe,MAClB,MAAO,CACL,YAAaD,EAAQ,IACrB,cAAeA,EAAQ,MACvB,aAAcA,EAAQ,YAAA,EAG1B,KAAKC,EAAAA,eAAe,MAClB,MAAO,CACL,YAAaD,EAAQ,IACrB,cAAeA,EAAQ,KAAA,EAE3B,KAAKC,EAAAA,eAAe,SAClB,M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CAAW,EACtDa,EAAoBxB,EAAoBsB,CAAQ,EAChDG,EAAc,wCAAwCT,CAAc,eAAeO,CAAoB,0DAA0DC,CAAiB,mEAExL,OAAOnB,EAAoBoB,CAAW,CACxC"}
@@ -28,6 +28,8 @@ declare function createSlashCommands(onSelectOption: (selectedOption: SelectedOp
28
28
  image?: string;
29
29
  video?: string;
30
30
  variable?: string;
31
+ }, { enableVariables }?: {
32
+ enableVariables?: boolean;
31
33
  }): (context: CompletionContext) => CompletionResult | null;
32
34
  declare const getEmbedUrl: (url: string) => string;
33
35
  declare const wrapWithFixedOutput: (content: string) => string;