markdown-flow-ui 0.1.111 → 0.1.112

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 (39) hide show
  1. package/dist/_virtual/index.cjs10.js +1 -1
  2. package/dist/_virtual/index.cjs9.js +1 -1
  3. package/dist/_virtual/index.es10.js +2 -2
  4. package/dist/_virtual/index.es9.js +2 -2
  5. package/dist/assets/markdown-flow-ui.css +1 -1
  6. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs.js +1 -1
  7. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs.js.map +1 -1
  8. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js +321 -317
  9. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js.map +1 -1
  10. package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.cjs.js +1 -1
  11. package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.cjs.js.map +1 -1
  12. package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.es.js +48 -44
  13. package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.es.js.map +1 -1
  14. package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.cjs.js +1 -1
  15. package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.cjs.js.map +1 -1
  16. package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.d.ts +1 -0
  17. package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.es.js +38 -28
  18. package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.es.js.map +1 -1
  19. package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.cjs.js +1 -1
  20. package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.cjs.js.map +1 -1
  21. package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.es.js +28 -26
  22. package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.es.js.map +1 -1
  23. package/dist/components/MarkdownFlowEditor/utils.cjs.js +1 -1
  24. package/dist/components/MarkdownFlowEditor/utils.cjs.js.map +1 -1
  25. package/dist/components/MarkdownFlowEditor/utils.d.ts +8 -1
  26. package/dist/components/MarkdownFlowEditor/utils.es.js +59 -39
  27. package/dist/components/MarkdownFlowEditor/utils.es.js.map +1 -1
  28. package/dist/components/Slide/Slide.cjs.js.map +1 -1
  29. package/dist/components/Slide/Slide.es.js.map +1 -1
  30. package/dist/components/Slide/useSlide.cjs.js.map +1 -1
  31. package/dist/components/Slide/useSlide.es.js.map +1 -1
  32. package/dist/components/Slide/utils/streamingNavigation.cjs.js.map +1 -1
  33. package/dist/components/Slide/utils/streamingNavigation.es.js.map +1 -1
  34. package/dist/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.cjs.js +1 -1
  35. package/dist/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.cjs.js.map +1 -1
  36. package/dist/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.es.js +1 -1
  37. package/dist/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.cjs.js +1 -1
  38. package/dist/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js +1 -1
  39. package/package.json +1 -1
@@ -1,35 +1,35 @@
1
1
  import { WidgetType as u, EditorView as l } from "../../../markdown-flow-ui/node_modules/.pnpm/@codemirror_view@6.38.6/node_modules/@codemirror/view/dist/index.es.js";
2
- const h = "http://www.w3.org/2000/svg", n = (e) => document.createElementNS(h, e), b = () => {
3
- const e = n("svg");
2
+ const h = "http://www.w3.org/2000/svg", r = (e) => document.createElementNS(h, e), p = () => {
3
+ const e = r("svg");
4
4
  e.setAttribute("viewBox", "0 0 24 24"), e.setAttribute("width", "14"), e.setAttribute("height", "14"), e.setAttribute("fill", "none"), e.setAttribute("stroke", "currentColor"), e.setAttribute("stroke-width", "1.5"), e.setAttribute("stroke-linecap", "round"), e.setAttribute("stroke-linejoin", "round");
5
- const t = n("rect");
5
+ const t = r("rect");
6
6
  t.setAttribute("width", "18"), t.setAttribute("height", "18"), t.setAttribute("x", "3"), t.setAttribute("y", "3"), t.setAttribute("rx", "2"), t.setAttribute("ry", "2");
7
- const s = n("circle");
7
+ const s = r("circle");
8
8
  s.setAttribute("cx", "9"), s.setAttribute("cy", "9"), s.setAttribute("r", "2");
9
- const i = n("path");
10
- return i.setAttribute("d", "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"), e.append(t, s, i), e;
11
- }, p = () => {
12
- const e = n("svg");
9
+ const n = r("path");
10
+ return n.setAttribute("d", "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"), e.append(t, s, n), e;
11
+ }, b = () => {
12
+ const e = r("svg");
13
13
  e.setAttribute("viewBox", "0 0 24 24"), e.setAttribute("width", "14"), e.setAttribute("height", "14"), e.setAttribute("fill", "none"), e.setAttribute("stroke", "currentColor"), e.setAttribute("stroke-width", "1.5"), e.setAttribute("stroke-linecap", "round"), e.setAttribute("stroke-linejoin", "round");
14
- const t = n("rect");
14
+ const t = r("rect");
15
15
  t.setAttribute("width", "18"), t.setAttribute("height", "18"), t.setAttribute("x", "3"), t.setAttribute("y", "3"), t.setAttribute("rx", "2");
16
- const s = n("path");
16
+ const s = r("path");
17
17
  return s.setAttribute("d", "m9 8 6 4-6 4Z"), e.append(t, s), e;
18
18
  };
19
- class g extends u {
20
- constructor(t, s, i, r, o) {
21
- super(), this.text = t, this.dataset = s, this.styleClass = i, this.type = r, this.view = o;
19
+ class m extends u {
20
+ constructor(t, s, n, i, a) {
21
+ super(), this.text = t, this.dataset = s, this.styleClass = n, this.type = i, this.view = a;
22
22
  }
23
23
  getPosition() {
24
24
  let t = -1, s = -1;
25
- const i = this.view.state.facet(l.decorations);
26
- for (const r of i)
27
- if ((typeof r == "function" ? r(this.view) : r).between(
25
+ const n = this.view.state.facet(l.decorations);
26
+ for (const i of n)
27
+ if ((typeof i == "function" ? i(this.view) : i).between(
28
28
  0,
29
29
  this.view.state.doc.length,
30
- (a, c, d) => {
30
+ (o, c, d) => {
31
31
  if (d.spec.widget === this)
32
- return t = a, s = c, !1;
32
+ return t = o, s = c, !1;
33
33
  }
34
34
  ), t !== -1) break;
35
35
  if (t !== -1 && s !== -1)
@@ -39,32 +39,42 @@ class g extends u {
39
39
  const t = document.createElement("span");
40
40
  t.className = this.styleClass;
41
41
  const s = document.createElement("span");
42
- if (s.textContent = this.text, s.dataset.tag = this.dataset.tag || "", s.dataset.url = this.dataset.url || "", s.dataset.title = this.dataset.title || "", s.addEventListener("click", (i) => {
43
- const [r, o] = this.getPosition() ?? [-1, -1], a = new CustomEvent("globalTagClick", {
42
+ s.className = "tag-placeholder-content";
43
+ const n = document.createElement("span");
44
+ if (n.className = "tag-placeholder-label", n.textContent = this.text, n.dataset.tag = this.dataset.tag || "", n.dataset.url = this.dataset.url || "", n.dataset.title = this.dataset.title || "", s.addEventListener("click", (i) => {
45
+ const [a, o] = this.getPosition() ?? [-1, -1], c = new CustomEvent("globalTagClick", {
44
46
  detail: {
45
47
  view: this.view,
46
48
  type: this.type,
47
49
  dataset: this.dataset,
48
- content: s.textContent,
49
- from: r,
50
+ content: n.textContent,
51
+ from: a,
50
52
  to: o,
51
53
  target: i.currentTarget
52
54
  }
53
55
  });
54
- window.dispatchEvent(a);
55
- }), this.dataset.tag === "image" || this.dataset.tag === "video") {
56
+ window.dispatchEvent(c);
57
+ }), this.dataset.fixedOutput) {
58
+ const i = document.createElement("span");
59
+ i.className = "tag-fixed-output-marker", i.textContent = "===", t.appendChild(i);
60
+ }
61
+ if (this.dataset.tag === "image" || this.dataset.tag === "video") {
56
62
  const i = document.createElement("span");
57
63
  i.className = "tag-placeholder-icon";
58
- const r = this.dataset.tag === "image" ? b() : p();
59
- i.appendChild(r), t.appendChild(i);
64
+ const a = this.dataset.tag === "image" ? p() : b();
65
+ i.appendChild(a), s.appendChild(i);
66
+ }
67
+ if (s.appendChild(n), t.appendChild(s), this.dataset.fixedOutput) {
68
+ const i = document.createElement("span");
69
+ i.className = "tag-fixed-output-marker", i.textContent = "===", t.appendChild(i);
60
70
  }
61
- return t.appendChild(s), t;
71
+ return t;
62
72
  }
63
73
  ignoreEvent() {
64
74
  return !1;
65
75
  }
66
76
  }
67
77
  export {
68
- g as default
78
+ m as default
69
79
  };
70
80
  //# sourceMappingURL=PlaceholderWidget.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlaceholderWidget.es.js","sources":["../../../../src/components/MarkdownFlowEditor/plugins/PlaceholderWidget.ts"],"sourcesContent":["import { EditorView, Decoration, WidgetType } from \"@codemirror/view\";\nimport { SelectedOption } from \"../types\";\n\nconst SVG_NS = \"http://www.w3.org/2000/svg\";\n\nconst createSvgElement = (tag: string) => document.createElementNS(SVG_NS, tag);\n// TODO: if use renderToStaticMarkup & createElement, it will cause react & react-dom version mismatch\n// so we use lucide-react to build the icon\n// lucide-react image icon\nconst buildImageIcon = () => {\n const svg = createSvgElement(\"svg\");\n svg.setAttribute(\"viewBox\", \"0 0 24 24\");\n svg.setAttribute(\"width\", \"14\");\n svg.setAttribute(\"height\", \"14\");\n svg.setAttribute(\"fill\", \"none\");\n svg.setAttribute(\"stroke\", \"currentColor\");\n svg.setAttribute(\"stroke-width\", \"1.5\");\n svg.setAttribute(\"stroke-linecap\", \"round\");\n svg.setAttribute(\"stroke-linejoin\", \"round\");\n\n const rect = createSvgElement(\"rect\");\n rect.setAttribute(\"width\", \"18\");\n rect.setAttribute(\"height\", \"18\");\n rect.setAttribute(\"x\", \"3\");\n rect.setAttribute(\"y\", \"3\");\n rect.setAttribute(\"rx\", \"2\");\n rect.setAttribute(\"ry\", \"2\");\n\n const circle = createSvgElement(\"circle\");\n circle.setAttribute(\"cx\", \"9\");\n circle.setAttribute(\"cy\", \"9\");\n circle.setAttribute(\"r\", \"2\");\n\n const path = createSvgElement(\"path\");\n path.setAttribute(\"d\", \"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21\");\n\n svg.append(rect, circle, path);\n return svg;\n};\n\n// lucide-react image icon\nconst buildVideoIcon = () => {\n const svg = createSvgElement(\"svg\");\n svg.setAttribute(\"viewBox\", \"0 0 24 24\");\n svg.setAttribute(\"width\", \"14\");\n svg.setAttribute(\"height\", \"14\");\n svg.setAttribute(\"fill\", \"none\");\n svg.setAttribute(\"stroke\", \"currentColor\");\n svg.setAttribute(\"stroke-width\", \"1.5\");\n svg.setAttribute(\"stroke-linecap\", \"round\");\n svg.setAttribute(\"stroke-linejoin\", \"round\");\n\n const rect = createSvgElement(\"rect\");\n rect.setAttribute(\"width\", \"18\");\n rect.setAttribute(\"height\", \"18\");\n rect.setAttribute(\"x\", \"3\");\n rect.setAttribute(\"y\", \"3\");\n rect.setAttribute(\"rx\", \"2\");\n\n const path = createSvgElement(\"path\");\n path.setAttribute(\"d\", \"m9 8 6 4-6 4Z\");\n\n svg.append(rect, path);\n return svg;\n};\n\nclass PlaceholderWidget extends WidgetType {\n constructor(\n private text: string,\n private dataset: {\n tag: \"image\" | \"video\" | \"variable\";\n title?: string;\n url?: string;\n scalePercent?: number;\n },\n private styleClass: string,\n private type: SelectedOption,\n private view: EditorView\n ) {\n super();\n }\n\n getPosition() {\n let from = -1;\n let to = -1;\n const decorations = this.view.state.facet(EditorView.decorations);\n for (const deco of decorations) {\n const decoSet = typeof deco === \"function\" ? deco(this.view) : deco;\n decoSet.between(\n 0,\n this.view.state.doc.length,\n (start: number, end: number, decoration: Decoration) => {\n if (decoration.spec.widget === this) {\n from = start;\n to = end;\n return false;\n }\n }\n );\n if (from !== -1) break;\n }\n if (from !== -1 && to !== -1) {\n return [from, to];\n }\n }\n\n toDOM() {\n const container = document.createElement(\"span\");\n container.className = this.styleClass;\n const span = document.createElement(\"span\");\n span.textContent = this.text;\n span.dataset[\"tag\"] = this.dataset.tag || \"\";\n span.dataset[\"url\"] = this.dataset.url || \"\";\n span.dataset[\"title\"] = this.dataset.title || \"\";\n // const icon = document.createElement(\"span\");\n // icon.className = \"tag-icon\";\n // icon.innerHTML = \"✕\";\n // icon.addEventListener(\"click\", (e) => {\n // e.stopPropagation();\n // const [from, to] = this.getPosition() ?? [-1, -1];\n // if (from !== -1 && to !== -1) {\n // this.view.dispatch({\n // changes: { from, to, insert: \"\" },\n // });\n // }\n // });\n span.addEventListener(\"click\", (e) => {\n const [from, to] = this.getPosition() ?? [-1, -1];\n const event = new CustomEvent(\"globalTagClick\", {\n detail: {\n view: this.view,\n type: this.type,\n dataset: this.dataset,\n content: span.textContent,\n from,\n to,\n target: e.currentTarget,\n },\n });\n window.dispatchEvent(event);\n });\n if (this.dataset.tag === \"image\" || this.dataset.tag === \"video\") {\n const iconWrapper = document.createElement(\"span\");\n iconWrapper.className = \"tag-placeholder-icon\";\n\n const icon =\n this.dataset.tag === \"image\" ? buildImageIcon() : buildVideoIcon();\n iconWrapper.appendChild(icon);\n container.appendChild(iconWrapper);\n }\n container.appendChild(span);\n // container.appendChild(icon);\n return container;\n }\n\n ignoreEvent() {\n return false;\n }\n}\n\nexport default PlaceholderWidget;\n"],"names":["SVG_NS","createSvgElement","tag","buildImageIcon","svg","rect","circle","path","buildVideoIcon","PlaceholderWidget","WidgetType","text","dataset","styleClass","type","view","from","to","decorations","EditorView","deco","start","end","decoration","container","span","e","event","iconWrapper","icon"],"mappings":";AAGA,MAAMA,IAAS,8BAETC,IAAmB,CAACC,MAAgB,SAAS,gBAAgBF,GAAQE,CAAG,GAIxEC,IAAiB,MAAM;AAC3B,QAAMC,IAAMH,EAAiB,KAAK;AAClC,EAAAG,EAAI,aAAa,WAAW,WAAW,GACvCA,EAAI,aAAa,SAAS,IAAI,GAC9BA,EAAI,aAAa,UAAU,IAAI,GAC/BA,EAAI,aAAa,QAAQ,MAAM,GAC/BA,EAAI,aAAa,UAAU,cAAc,GACzCA,EAAI,a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AAAT;AAAA,UACA,IAAAC;AAAA,UACA,QAAQS,EAAE;AAAA,QAAA;AAAA,MACZ,CACD;AACD,aAAO,cAAcC,CAAK;AAAA,IAC5B,CAAC,GACG,KAAK,QAAQ,QAAQ,WAAW,KAAK,QAAQ,QAAQ,SAAS;AAChE,YAAMC,IAAc,SAAS,cAAc,MAAM;AACjD,MAAAA,EAAY,YAAY;AAExB,YAAMC,IACJ,KAAK,QAAQ,QAAQ,UAAU1B,EAAA,IAAmBK,EAAA;AACpD,MAAAoB,EAAY,YAAYC,CAAI,GAC5BL,EAAU,YAAYI,CAAW;AAAA,IACnC;AACA,WAAAJ,EAAU,YAAYC,CAAI,GAEnBD;AAAA,EACT;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,EACT;AACF;"}
1
+ {"version":3,"file":"PlaceholderWidget.es.js","sources":["../../../../src/components/MarkdownFlowEditor/plugins/PlaceholderWidget.ts"],"sourcesContent":["import { EditorView, Decoration, WidgetType } from \"@codemirror/view\";\nimport { SelectedOption } from \"../types\";\n\nconst SVG_NS = \"http://www.w3.org/2000/svg\";\n\nconst createSvgElement = (tag: string) => document.createElementNS(SVG_NS, tag);\n// TODO: if use renderToStaticMarkup & createElement, it will cause react & react-dom version mismatch\n// so we use lucide-react to build the icon\n// lucide-react image icon\nconst buildImageIcon = () => {\n const svg = createSvgElement(\"svg\");\n svg.setAttribute(\"viewBox\", \"0 0 24 24\");\n svg.setAttribute(\"width\", \"14\");\n svg.setAttribute(\"height\", \"14\");\n svg.setAttribute(\"fill\", \"none\");\n svg.setAttribute(\"stroke\", \"currentColor\");\n svg.setAttribute(\"stroke-width\", \"1.5\");\n svg.setAttribute(\"stroke-linecap\", \"round\");\n svg.setAttribute(\"stroke-linejoin\", \"round\");\n\n const rect = createSvgElement(\"rect\");\n rect.setAttribute(\"width\", \"18\");\n rect.setAttribute(\"height\", \"18\");\n rect.setAttribute(\"x\", \"3\");\n rect.setAttribute(\"y\", \"3\");\n rect.setAttribute(\"rx\", \"2\");\n rect.setAttribute(\"ry\", \"2\");\n\n const circle = createSvgElement(\"circle\");\n circle.setAttribute(\"cx\", \"9\");\n circle.setAttribute(\"cy\", \"9\");\n circle.setAttribute(\"r\", \"2\");\n\n const path = createSvgElement(\"path\");\n path.setAttribute(\"d\", \"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21\");\n\n svg.append(rect, circle, path);\n return svg;\n};\n\n// lucide-react image icon\nconst buildVideoIcon = () => {\n const svg = createSvgElement(\"svg\");\n svg.setAttribute(\"viewBox\", \"0 0 24 24\");\n svg.setAttribute(\"width\", \"14\");\n svg.setAttribute(\"height\", \"14\");\n svg.setAttribute(\"fill\", \"none\");\n svg.setAttribute(\"stroke\", \"currentColor\");\n svg.setAttribute(\"stroke-width\", \"1.5\");\n svg.setAttribute(\"stroke-linecap\", \"round\");\n svg.setAttribute(\"stroke-linejoin\", \"round\");\n\n const rect = createSvgElement(\"rect\");\n rect.setAttribute(\"width\", \"18\");\n rect.setAttribute(\"height\", \"18\");\n rect.setAttribute(\"x\", \"3\");\n rect.setAttribute(\"y\", \"3\");\n rect.setAttribute(\"rx\", \"2\");\n\n const path = createSvgElement(\"path\");\n path.setAttribute(\"d\", \"m9 8 6 4-6 4Z\");\n\n svg.append(rect, path);\n return svg;\n};\n\nclass PlaceholderWidget extends WidgetType {\n constructor(\n private text: string,\n private dataset: {\n tag: \"image\" | \"video\" | \"variable\";\n title?: string;\n url?: string;\n scalePercent?: number;\n fixedOutput?: boolean;\n },\n private styleClass: string,\n private type: SelectedOption,\n private view: EditorView\n ) {\n super();\n }\n\n getPosition() {\n let from = -1;\n let to = -1;\n const decorations = this.view.state.facet(EditorView.decorations);\n for (const deco of decorations) {\n const decoSet = typeof deco === \"function\" ? deco(this.view) : deco;\n decoSet.between(\n 0,\n this.view.state.doc.length,\n (start: number, end: number, decoration: Decoration) => {\n if (decoration.spec.widget === this) {\n from = start;\n to = end;\n return false;\n }\n }\n );\n if (from !== -1) break;\n }\n if (from !== -1 && to !== -1) {\n return [from, to];\n }\n }\n\n toDOM() {\n const container = document.createElement(\"span\");\n container.className = this.styleClass;\n const content = document.createElement(\"span\");\n content.className = \"tag-placeholder-content\";\n const span = document.createElement(\"span\");\n span.className = \"tag-placeholder-label\";\n span.textContent = this.text;\n span.dataset[\"tag\"] = this.dataset.tag || \"\";\n span.dataset[\"url\"] = this.dataset.url || \"\";\n span.dataset[\"title\"] = this.dataset.title || \"\";\n // const icon = document.createElement(\"span\");\n // icon.className = \"tag-icon\";\n // icon.innerHTML = \"✕\";\n // icon.addEventListener(\"click\", (e) => {\n // e.stopPropagation();\n // const [from, to] = this.getPosition() ?? [-1, -1];\n // if (from !== -1 && to !== -1) {\n // this.view.dispatch({\n // changes: { from, to, insert: \"\" },\n // });\n // }\n // });\n content.addEventListener(\"click\", (e) => {\n const [from, to] = this.getPosition() ?? [-1, -1];\n const event = new CustomEvent(\"globalTagClick\", {\n detail: {\n view: this.view,\n type: this.type,\n dataset: this.dataset,\n content: span.textContent,\n from,\n to,\n target: e.currentTarget,\n },\n });\n window.dispatchEvent(event);\n });\n\n if (this.dataset.fixedOutput) {\n const prefix = document.createElement(\"span\");\n prefix.className = \"tag-fixed-output-marker\";\n prefix.textContent = \"===\";\n container.appendChild(prefix);\n }\n\n if (this.dataset.tag === \"image\" || this.dataset.tag === \"video\") {\n const iconWrapper = document.createElement(\"span\");\n iconWrapper.className = \"tag-placeholder-icon\";\n\n const icon =\n this.dataset.tag === \"image\" ? buildImageIcon() : buildVideoIcon();\n iconWrapper.appendChild(icon);\n content.appendChild(iconWrapper);\n }\n content.appendChild(span);\n container.appendChild(content);\n\n if (this.dataset.fixedOutput) {\n const suffix = document.createElement(\"span\");\n suffix.className = \"tag-fixed-output-marker\";\n suffix.textContent = \"===\";\n container.appendChild(suffix);\n }\n\n // container.appendChild(icon);\n return container;\n }\n\n ignoreEvent() {\n return false;\n }\n}\n\nexport default PlaceholderWidget;\n"],"names":["SVG_NS","createSvgElement","tag","buildImageIcon","svg","rect","circle","path","buildVideoIcon","PlaceholderWidget","WidgetType","text","dataset","styleClass","type","view","from","to","decorations","EditorView","deco","start","end","decoration","container","content","span","e","event","prefix","iconWrapper","icon","suffix"],"mappings":";AAGA,MAAMA,IAAS,8BAETC,IAAmB,CAACC,MAAgB,SAAS,gBAAgBF,GAAQE,CAAG,GAIxEC,IAAiB,MAAM;AAC3B,QAAMC,IAAMH,EAAiB,KAAK;AAClC,EAAAG,EAAI,aAAa,WAAW,WAAW,GACvCA,EAAI,aAAa,SAAS,IAAI,GAC9BA,EAAI,aAAa,UAAU,IAAI,GAC/BA,EAAI,aAAa,QAAQ,MAAM,GAC/BA,EAAI,aAAa,UAAU,cAAc,GACzCA,EAAI,aAAa,gBAAgB,KAAK,GACtCA,EAAI,aAAa,kBAAkB,OAAO,GAC1CA,EAAI,aAAa,mBAAmB,OAAO;AAE3C,QAAMC,IAAOJ,EAAiB,MAAM;AACpC,EAAAI,EAAK,aAAa,SAAS,IAAI,GAC/BA,EAAK,aAAa,UAAU,IAAI,GAChCA,EAAK,aAAa,KAAK,GAAG,GAC1BA,EAAK,aAAa,KAAK,GAAG,GAC1BA,EAAK,aAAa,MAAM,GAAG,GAC3BA,EAAK,aAAa,MAAM,GAAG;AAE3B,QAAMC,IAASL,EAAiB,QAAQ;AACxC,EAAAK,EAAO,aAAa,MAAM,GAAG,GAC7BA,EAAO,aAAa,MAAM,GAAG,GAC7BA,EAAO,aAAa,KAAK,GAAG;AAE5B,QAAMC,IAAON,EAAiB,MAAM;AACpC,SAAAM,EAAK,aAAa,KAAK,2CAA2C,GAElEH,EAAI,OAAOC,GAAMC,GAAQC,CAAI,GACtBH;AACT,GAGMI,IAAiB,MAAM;AAC3B,QAAMJ,IAAMH,EAAiB,KAAK;AAClC,EAAAG,EAAI,aAAa,WAAW,WAAW,GACvCA,EAAI,aAAa,SAAS,IAAI,GAC9BA,EAAI,aAAa,UAAU,IAAI,GAC/BA,EAAI,aAAa,QAAQ,MAAM,GAC/BA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BA,EAAO,cAAc,OACrBR,EAAU,YAAYQ,CAAM;AAAA,IAC9B;AAGA,WAAOR;AAAA,EACT;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,EACT;AACF;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("../../../markdown-flow-ui/node_modules/.pnpm/@codemirror_view@6.38.6/node_modules/@codemirror/view/dist/index.cjs.js"),w=require("../types.cjs.js"),f=require("./PlaceholderWidget.cjs.js"),R=/<iframe\s[^>]*data-tag="video"[^>]*><\/iframe>/gi,i=(e,t)=>{const r=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),c=new RegExp(`${r}="([^"]*)"`,"i"),o=e.match(c);return o?o[1]:""},s=e=>e.replace(/&quot;/g,'"').replace(/&amp;/g,"&"),m=new a.MatchDecorator({regexp:R,decoration:(e,t)=>{const r=e?.[0]||"",c=i(r,"src"),o=i(r,"data-title"),n=i(r,"data-url"),d=o?s(o):"",l=c?s(c):"",u=n?s(n):"";let p=u||l;try{if(!u&&l){const h=new URLSearchParams(new URL(l).search).get("url");h&&(p=decodeURIComponent(h))}}catch(g){console.warn("Failed to decode video URL:",g)}return a.Decoration.replace({widget:new f.default(d||"Video",{tag:"video",url:p,title:d},"tag-video",w.SelectedOption.Video,t)})}}),U=a.ViewPlugin.fromClass(class{constructor(e){this.placeholders=m.createDeco(e)}update(e){this.placeholders=m.updateDeco(e,this.placeholders)}},{decorations:e=>e.placeholders,provide:e=>a.EditorView.atomicRanges.of(t=>t.plugin(e)?.placeholders||a.Decoration.none)});exports.default=U;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("../../../markdown-flow-ui/node_modules/.pnpm/@codemirror_view@6.38.6/node_modules/@codemirror/view/dist/index.cjs.js"),R=require("../types.cjs.js"),x=require("../utils.cjs.js"),U=require("./PlaceholderWidget.cjs.js"),V=/===\s*<iframe\s[^>]*data-tag="video"[^>]*><\/iframe>\s*===|<iframe\s[^>]*data-tag="video"[^>]*><\/iframe>/gi,i=(e,t)=>{const a=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`${a}="([^"]*)"`,"i"),c=e.match(r);return c?c[1]:""},l=e=>e.replace(/&quot;/g,'"').replace(/&amp;/g,"&"),w=new o.MatchDecorator({regexp:V,decoration:(e,t)=>{const a=e?.[0]||"",r=x.unwrapFixedOutput(a),c=/^\s*===/.test(a),n=i(r,"src"),d=i(r,"data-title"),u=i(r,"data-url"),p=d?l(d):"",s=n?l(n):"",g=u?l(u):"";let h=g||s;try{if(!g&&s){const f=new URLSearchParams(new URL(s).search).get("url");f&&(h=decodeURIComponent(f))}}catch(m){console.warn("Failed to decode video URL:",m)}return o.Decoration.replace({widget:new U.default(p||"Video",{tag:"video",url:h,title:p,fixedOutput:c},"tag-video",R.SelectedOption.Video,t)})}}),v=o.ViewPlugin.fromClass(class{constructor(e){this.placeholders=w.createDeco(e)}update(e){this.placeholders=w.updateDeco(e,this.placeholders)}},{decorations:e=>e.placeholders,provide:e=>o.EditorView.atomicRanges.of(t=>t.plugin(e)?.placeholders||o.Decoration.none)});exports.default=v;
2
2
  //# sourceMappingURL=VideoPlaceholder.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"VideoPlaceholder.cjs.js","sources":["../../../../src/components/MarkdownFlowEditor/plugins/VideoPlaceholder.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\";\n\nconst biliVideoContextRegexp =\n /<iframe\\s[^>]*data-tag=\"video\"[^>]*><\\/iframe>/gi;\n\nconst extractAttrValue = (markup: string, attr: string) => {\n const escapedAttr = attr.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const regexp = new RegExp(`${escapedAttr}=\"([^\"]*)\"`, \"i\");\n const match = markup.match(regexp);\n return match ? match[1] : \"\";\n};\n\nconst decodeHtmlEntities = (value: string) =>\n value.replace(/&quot;/g, '\"').replace(/&amp;/g, \"&\");\n\nconst biliUrlMatcher = new MatchDecorator({\n regexp: biliVideoContextRegexp,\n decoration: (match, view) => {\n const iframeMarkup = match?.[0] || \"\";\n const srcValueRaw = extractAttrValue(iframeMarkup, \"src\");\n const titleAttrRaw = extractAttrValue(iframeMarkup, \"data-title\");\n const dataUrlAttrRaw = extractAttrValue(iframeMarkup, \"data-url\");\n const titleAttr = titleAttrRaw ? decodeHtmlEntities(titleAttrRaw) : \"\";\n const decodedSrcValue = srcValueRaw ? decodeHtmlEntities(srcValueRaw) : \"\";\n const storedDataUrl = dataUrlAttrRaw\n ? decodeHtmlEntities(dataUrlAttrRaw)\n : \"\";\n // Extract and decode the original URL from stored attributes or API endpoint\n let originalUrl = storedDataUrl || decodedSrcValue;\n try {\n if (!storedDataUrl && decodedSrcValue) {\n const urlParams = new URLSearchParams(new URL(decodedSrcValue).search);\n const encodedUrl = urlParams.get(\"url\");\n if (encodedUrl) {\n originalUrl = decodeURIComponent(encodedUrl);\n }\n }\n } catch (error) {\n console.warn(\"Failed to decode video URL:\", error);\n }\n\n return Decoration.replace({\n widget: new PlaceholderWidget(\n titleAttr || \"Video\", // Display title from data-title\n {\n tag: \"video\",\n url: originalUrl, // Decoded original Bilibili URL\n title: titleAttr, // title from data-title attribute\n },\n \"tag-video\",\n SelectedOption.Video,\n view\n ),\n });\n },\n});\n\nconst VideoPlaceholder = ViewPlugin.fromClass(\n class {\n placeholders: DecorationSet;\n constructor(view: EditorView) {\n this.placeholders = biliUrlMatcher.createDeco(view);\n }\n update(update: ViewUpdate) {\n this.placeholders = biliUrlMatcher.updateDeco(update, this.placeholders);\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 VideoPlaceholder;\n"],"names":["biliVideoContextRegexp","extractAttrValue","markup","attr","escapedAttr","regexp","match","decodeHtmlEntities","value","biliUrlMatcher","MatchDecorator","view","iframeMarkup","srcValueRaw","titleAttrRaw","dataUrlAttrRaw","titleAttr","decodedSrcValue","storedDataUrl","originalUrl","encodedUrl","error","Decoration","PlaceholderWidget","SelectedOption","VideoPlaceholder","ViewPlugin","update","instance","plugin","EditorView"],"mappings":"yTAWMA,EACJ,mDAEIC,EAAmB,CAACC,EAAgBC,IAAiB,CACzD,MAAMC,EAAcD,EAAK,QAAQ,sBAAuB,MAAM,EACxDE,EAAS,IAAI,OAAO,GAAGD,CAAW,aAAc,GAAG,EACnDE,EAAQJ,EAAO,MAAMG,CAAM,EACjC,OAAOC,EAAQA,EAAM,CAAC,EAAI,EAC5B,EAEMC,EAAsBC,GAC1BA,EAAM,QAAQ,UAAW,GAAG,EAAE,QAAQ,SAAU,GAAG,EAE/CC,EAAiB,IAAIC,EAAAA,eAAe,CACxC,OAAQV,EACR,WAAY,CAACM,EAAOK,IAAS,CAC3B,MAAMC,EAAeN,IAAQ,CAAC,GAAK,GAC7BO,EAAcZ,EAAiBW,EAAc,KAAK,EAClDE,EAAeb,EAAiBW,EAAc,YAAY,EAC1DG,EAAiBd,EAAiBW,EAAc,UAAU,EAC1DI,EAAYF,EAAeP,EAAmBO,CAAY,EAAI,GAC9DG,EAAkBJ,EAAcN,EAAmBM,CAAW,EAAI,GAClEK,EAAgBH,EAClBR,EAAmBQ,CAAc,EACjC,GAEJ,IAAII,EAAcD,GAAiBD,EACnC,GAAI,CACF,GAAI,CAACC,GAAiBD,EAAiB,CAErC,MAAMG,EADY,IAAI,gBAAgB,IAAI,IAAIH,CAAe,EAAE,MAAM,EACxC,IAAI,KAAK,EAClCG,IACFD,EAAc,mBAAmBC,CAAU,EAE/C,CACF,OAASC,EAAO,CACd,QAAQ,KAAK,8BAA+BA,CAAK,CACnD,CAEA,OAAOC,EAAAA,WAAW,QAAQ,CACxB,OAAQ,IAAIC,EAAAA,QACVP,GAAa,QACb,CACE,IAAK,QACL,IAAKG,EACL,MAAOH,CAAA,EAET,YACAQ,EAAAA,eAAe,MACfb,CAAA,CACF,CACD,CACH,CACF,CAAC,EAEKc,EAAmBC,EAAAA,WAAW,UAClC,KAAM,CAEJ,YAAYf,EAAkB,CAC5B,KAAK,aAAeF,EAAe,WAAWE,CAAI,CACpD,CACA,OAAOgB,EAAoB,CACzB,KAAK,aAAelB,EAAe,WAAWkB,EAAQ,KAAK,YAAY,CACzE,CAAA,EAEF,CACE,YAAcC,GAAaA,EAAS,aACpC,QAAUC,GACRC,EAAAA,WAAW,aAAa,GAAInB,GACnBA,EAAK,OAAOkB,CAAM,GAAG,cAAgBP,EAAAA,WAAW,IACxD,CAAA,CAEP"}
1
+ {"version":3,"file":"VideoPlaceholder.cjs.js","sources":["../../../../src/components/MarkdownFlowEditor/plugins/VideoPlaceholder.ts"],"sourcesContent":["import {\n EditorView,\n Decoration,\n DecorationSet,\n ViewPlugin,\n ViewUpdate,\n MatchDecorator,\n} from \"@codemirror/view\";\nimport { SelectedOption } from \"../types\";\nimport { unwrapFixedOutput } from \"../utils\";\nimport PlaceholderWidget from \"./PlaceholderWidget\";\n\nconst biliVideoContextRegexp =\n /===\\s*<iframe\\s[^>]*data-tag=\"video\"[^>]*><\\/iframe>\\s*===|<iframe\\s[^>]*data-tag=\"video\"[^>]*><\\/iframe>/gi;\n\nconst extractAttrValue = (markup: string, attr: string) => {\n const escapedAttr = attr.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const regexp = new RegExp(`${escapedAttr}=\"([^\"]*)\"`, \"i\");\n const match = markup.match(regexp);\n return match ? match[1] : \"\";\n};\n\nconst decodeHtmlEntities = (value: string) =>\n value.replace(/&quot;/g, '\"').replace(/&amp;/g, \"&\");\n\nconst biliUrlMatcher = new MatchDecorator({\n regexp: biliVideoContextRegexp,\n decoration: (match, view) => {\n const source = match?.[0] || \"\";\n const iframeMarkup = unwrapFixedOutput(source);\n const fixedOutput = /^\\s*===/.test(source);\n const srcValueRaw = extractAttrValue(iframeMarkup, \"src\");\n const titleAttrRaw = extractAttrValue(iframeMarkup, \"data-title\");\n const dataUrlAttrRaw = extractAttrValue(iframeMarkup, \"data-url\");\n const titleAttr = titleAttrRaw ? decodeHtmlEntities(titleAttrRaw) : \"\";\n const decodedSrcValue = srcValueRaw ? decodeHtmlEntities(srcValueRaw) : \"\";\n const storedDataUrl = dataUrlAttrRaw\n ? decodeHtmlEntities(dataUrlAttrRaw)\n : \"\";\n // Extract and decode the original URL from stored attributes or API endpoint\n let originalUrl = storedDataUrl || decodedSrcValue;\n try {\n if (!storedDataUrl && decodedSrcValue) {\n const urlParams = new URLSearchParams(new URL(decodedSrcValue).search);\n const encodedUrl = urlParams.get(\"url\");\n if (encodedUrl) {\n originalUrl = decodeURIComponent(encodedUrl);\n }\n }\n } catch (error) {\n console.warn(\"Failed to decode video URL:\", error);\n }\n\n return Decoration.replace({\n widget: new PlaceholderWidget(\n titleAttr || \"Video\", // Display title from data-title\n {\n tag: \"video\",\n url: originalUrl, // Decoded original Bilibili URL\n title: titleAttr, // title from data-title attribute\n fixedOutput,\n },\n \"tag-video\",\n SelectedOption.Video,\n view\n ),\n });\n },\n});\n\nconst VideoPlaceholder = ViewPlugin.fromClass(\n class {\n placeholders: DecorationSet;\n constructor(view: EditorView) {\n this.placeholders = biliUrlMatcher.createDeco(view);\n }\n update(update: ViewUpdate) {\n this.placeholders = biliUrlMatcher.updateDeco(update, this.placeholders);\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 VideoPlaceholder;\n"],"names":["biliVideoContextRegexp","extractAttrValue","markup","attr","escapedAttr","regexp","match","decodeHtmlEntities","value","biliUrlMatcher","MatchDecorator","view","source","iframeMarkup","unwrapFixedOutput","fixedOutput","srcValueRaw","titleAttrRaw","dataUrlAttrRaw","titleAttr","decodedSrcValue","storedDataUrl","originalUrl","encodedUrl","error","Decoration","PlaceholderWidget","SelectedOption","VideoPlaceholder","ViewPlugin","update","instance","plugin","EditorView"],"mappings":"sVAYMA,EACJ,8GAEIC,EAAmB,CAACC,EAAgBC,IAAiB,CACzD,MAAMC,EAAcD,EAAK,QAAQ,sBAAuB,MAAM,EACxDE,EAAS,IAAI,OAAO,GAAGD,CAAW,aAAc,GAAG,EACnDE,EAAQJ,EAAO,MAAMG,CAAM,EACjC,OAAOC,EAAQA,EAAM,CAAC,EAAI,EAC5B,EAEMC,EAAsBC,GAC1BA,EAAM,QAAQ,UAAW,GAAG,EAAE,QAAQ,SAAU,GAAG,EAE/CC,EAAiB,IAAIC,EAAAA,eAAe,CACxC,OAAQV,EACR,WAAY,CAACM,EAAOK,IAAS,CAC3B,MAAMC,EAASN,IAAQ,CAAC,GAAK,GACvBO,EAAeC,EAAAA,kBAAkBF,CAAM,EACvCG,EAAc,UAAU,KAAKH,CAAM,EACnCI,EAAcf,EAAiBY,EAAc,KAAK,EAClDI,EAAehB,EAAiBY,EAAc,YAAY,EAC1DK,EAAiBjB,EAAiBY,EAAc,UAAU,EAC1DM,EAAYF,EAAeV,EAAmBU,CAAY,EAAI,GAC9DG,EAAkBJ,EAAcT,EAAmBS,CAAW,EAAI,GAClEK,EAAgBH,EAClBX,EAAmBW,CAAc,EACjC,GAEJ,IAAII,EAAcD,GAAiBD,EACnC,GAAI,CACF,GAAI,CAACC,GAAiBD,EAAiB,CAErC,MAAMG,EADY,IAAI,gBAAgB,IAAI,IAAIH,CAAe,EAAE,MAAM,EACxC,IAAI,KAAK,EAClCG,IACFD,EAAc,mBAAmBC,CAAU,EAE/C,CACF,OAASC,EAAO,CACd,QAAQ,KAAK,8BAA+BA,CAAK,CACnD,CAEA,OAAOC,EAAAA,WAAW,QAAQ,CACxB,OAAQ,IAAIC,EAAAA,QACVP,GAAa,QACb,CACE,IAAK,QACL,IAAKG,EACL,MAAOH,EACP,YAAAJ,CAAA,EAEF,YACAY,EAAAA,eAAe,MACfhB,CAAA,CACF,CACD,CACH,CACF,CAAC,EAEKiB,EAAmBC,EAAAA,WAAW,UAClC,KAAM,CAEJ,YAAYlB,EAAkB,CAC5B,KAAK,aAAeF,EAAe,WAAWE,CAAI,CACpD,CACA,OAAOmB,EAAoB,CACzB,KAAK,aAAerB,EAAe,WAAWqB,EAAQ,KAAK,YAAY,CACzE,CAAA,EAEF,CACE,YAAcC,GAAaA,EAAS,aACpC,QAAUC,GACRC,EAAAA,WAAW,aAAa,GAAItB,GACnBA,EAAK,OAAOqB,CAAM,GAAG,cAAgBP,EAAAA,WAAW,IACxD,CAAA,CAEP"}
@@ -1,54 +1,56 @@
1
- import { MatchDecorator as w, Decoration as h, ViewPlugin as f, EditorView as R } from "../../../markdown-flow-ui/node_modules/.pnpm/@codemirror_view@6.38.6/node_modules/@codemirror/view/dist/index.es.js";
2
- import { SelectedOption as U } from "../types.es.js";
3
- import V from "./PlaceholderWidget.es.js";
4
- const x = /<iframe\s[^>]*data-tag="video"[^>]*><\/iframe>/gi, l = (e, t) => {
5
- const o = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), a = new RegExp(`${o}="([^"]*)"`, "i"), r = e.match(a);
6
- return r ? r[1] : "";
7
- }, i = (e) => e.replace(/&quot;/g, '"').replace(/&amp;/g, "&"), g = new w({
8
- regexp: x,
1
+ import { MatchDecorator as R, Decoration as w, ViewPlugin as x, EditorView as U } from "../../../markdown-flow-ui/node_modules/.pnpm/@codemirror_view@6.38.6/node_modules/@codemirror/view/dist/index.es.js";
2
+ import { SelectedOption as V } from "../types.es.js";
3
+ import { unwrapFixedOutput as v } from "../utils.es.js";
4
+ import P from "./PlaceholderWidget.es.js";
5
+ const A = /===\s*<iframe\s[^>]*data-tag="video"[^>]*><\/iframe>\s*===|<iframe\s[^>]*data-tag="video"[^>]*><\/iframe>/gi, i = (e, t) => {
6
+ const r = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), o = new RegExp(`${r}="([^"]*)"`, "i"), a = e.match(o);
7
+ return a ? a[1] : "";
8
+ }, s = (e) => e.replace(/&quot;/g, '"').replace(/&amp;/g, "&"), f = new R({
9
+ regexp: A,
9
10
  decoration: (e, t) => {
10
- const o = e?.[0] || "", a = l(o, "src"), r = l(o, "data-title"), s = l(o, "data-url"), d = r ? i(r) : "", c = a ? i(a) : "", n = s ? i(s) : "";
11
- let p = n || c;
11
+ const r = e?.[0] || "", o = v(r), a = /^\s*===/.test(r), l = i(o, "src"), d = i(o, "data-title"), n = i(o, "data-url"), p = d ? s(d) : "", c = l ? s(l) : "", u = n ? s(n) : "";
12
+ let m = u || c;
12
13
  try {
13
- if (!n && c) {
14
- const u = new URLSearchParams(new URL(c).search).get("url");
15
- u && (p = decodeURIComponent(u));
14
+ if (!u && c) {
15
+ const h = new URLSearchParams(new URL(c).search).get("url");
16
+ h && (m = decodeURIComponent(h));
16
17
  }
17
- } catch (m) {
18
- console.warn("Failed to decode video URL:", m);
18
+ } catch (g) {
19
+ console.warn("Failed to decode video URL:", g);
19
20
  }
20
- return h.replace({
21
- widget: new V(
22
- d || "Video",
21
+ return w.replace({
22
+ widget: new P(
23
+ p || "Video",
23
24
  // Display title from data-title
24
25
  {
25
26
  tag: "video",
26
- url: p,
27
+ url: m,
27
28
  // Decoded original Bilibili URL
28
- title: d
29
+ title: p,
29
30
  // title from data-title attribute
31
+ fixedOutput: a
30
32
  },
31
33
  "tag-video",
32
- U.Video,
34
+ V.Video,
33
35
  t
34
36
  )
35
37
  });
36
38
  }
37
- }), D = f.fromClass(
39
+ }), M = x.fromClass(
38
40
  class {
39
41
  constructor(e) {
40
- this.placeholders = g.createDeco(e);
42
+ this.placeholders = f.createDeco(e);
41
43
  }
42
44
  update(e) {
43
- this.placeholders = g.updateDeco(e, this.placeholders);
45
+ this.placeholders = f.updateDeco(e, this.placeholders);
44
46
  }
45
47
  },
46
48
  {
47
49
  decorations: (e) => e.placeholders,
48
- provide: (e) => R.atomicRanges.of((t) => t.plugin(e)?.placeholders || h.none)
50
+ provide: (e) => U.atomicRanges.of((t) => t.plugin(e)?.placeholders || w.none)
49
51
  }
50
52
  );
51
53
  export {
52
- D as default
54
+ M as default
53
55
  };
54
56
  //# sourceMappingURL=VideoPlaceholder.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"VideoPlaceholder.es.js","sources":["../../../../src/components/MarkdownFlowEditor/plugins/VideoPlaceholder.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\";\n\nconst biliVideoContextRegexp =\n /<iframe\\s[^>]*data-tag=\"video\"[^>]*><\\/iframe>/gi;\n\nconst extractAttrValue = (markup: string, attr: string) => {\n const escapedAttr = attr.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const regexp = new RegExp(`${escapedAttr}=\"([^\"]*)\"`, \"i\");\n const match = markup.match(regexp);\n return match ? match[1] : \"\";\n};\n\nconst decodeHtmlEntities = (value: string) =>\n value.replace(/&quot;/g, '\"').replace(/&amp;/g, \"&\");\n\nconst biliUrlMatcher = new MatchDecorator({\n regexp: biliVideoContextRegexp,\n decoration: (match, view) => {\n const iframeMarkup = match?.[0] || \"\";\n const srcValueRaw = extractAttrValue(iframeMarkup, \"src\");\n const titleAttrRaw = extractAttrValue(iframeMarkup, \"data-title\");\n const dataUrlAttrRaw = extractAttrValue(iframeMarkup, \"data-url\");\n const titleAttr = titleAttrRaw ? decodeHtmlEntities(titleAttrRaw) : \"\";\n const decodedSrcValue = srcValueRaw ? decodeHtmlEntities(srcValueRaw) : \"\";\n const storedDataUrl = dataUrlAttrRaw\n ? decodeHtmlEntities(dataUrlAttrRaw)\n : \"\";\n // Extract and decode the original URL from stored attributes or API endpoint\n let originalUrl = storedDataUrl || decodedSrcValue;\n try {\n if (!storedDataUrl && decodedSrcValue) {\n const urlParams = new URLSearchParams(new URL(decodedSrcValue).search);\n const encodedUrl = urlParams.get(\"url\");\n if (encodedUrl) {\n originalUrl = decodeURIComponent(encodedUrl);\n }\n }\n } catch (error) {\n console.warn(\"Failed to decode video URL:\", error);\n }\n\n return Decoration.replace({\n widget: new PlaceholderWidget(\n titleAttr || \"Video\", // Display title from data-title\n {\n tag: \"video\",\n url: originalUrl, // Decoded original Bilibili URL\n title: titleAttr, // title from data-title attribute\n },\n \"tag-video\",\n SelectedOption.Video,\n view\n ),\n });\n },\n});\n\nconst VideoPlaceholder = ViewPlugin.fromClass(\n class {\n placeholders: DecorationSet;\n constructor(view: EditorView) {\n this.placeholders = biliUrlMatcher.createDeco(view);\n }\n update(update: ViewUpdate) {\n this.placeholders = biliUrlMatcher.updateDeco(update, this.placeholders);\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 VideoPlaceholder;\n"],"names":["biliVideoContextRegexp","extractAttrValue","markup","attr","escapedAttr","regexp","match","decodeHtmlEntities","value","biliUrlMatcher","MatchDecorator","view","iframeMarkup","srcValueRaw","titleAttrRaw","dataUrlAttrRaw","titleAttr","decodedSrcValue","storedDataUrl","originalUrl","encodedUrl","error","Decoration","PlaceholderWidget","SelectedOption","VideoPlaceholder","ViewPlugin","update","instance","plugin","EditorView"],"mappings":";;;AAWA,MAAMA,IACJ,oDAEIC,IAAmB,CAACC,GAAgBC,MAAiB;AACzD,QAAMC,IAAcD,EAAK,QAAQ,uBAAuB,MAAM,GACxDE,IAAS,IAAI,OAAO,GAAGD,CAAW,cAAc,GAAG,GACnDE,IAAQJ,EAAO,MAAMG,CAAM;AACjC,SAAOC,IAAQA,EAAM,CAAC,IAAI;AAC5B,GAEMC,IAAqB,CAACC,MAC1BA,EAA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SAAS,CAACC,MACRC,EAAW,aAAa,GAAG,CAACnB,MACnBA,EAAK,OAAOkB,CAAM,GAAG,gBAAgBP,EAAW,IACxD;AAAA,EAAA;AAEP;"}
1
+ {"version":3,"file":"VideoPlaceholder.es.js","sources":["../../../../src/components/MarkdownFlowEditor/plugins/VideoPlaceholder.ts"],"sourcesContent":["import {\n EditorView,\n Decoration,\n DecorationSet,\n ViewPlugin,\n ViewUpdate,\n MatchDecorator,\n} from \"@codemirror/view\";\nimport { SelectedOption } from \"../types\";\nimport { unwrapFixedOutput } from \"../utils\";\nimport PlaceholderWidget from \"./PlaceholderWidget\";\n\nconst biliVideoContextRegexp =\n /===\\s*<iframe\\s[^>]*data-tag=\"video\"[^>]*><\\/iframe>\\s*===|<iframe\\s[^>]*data-tag=\"video\"[^>]*><\\/iframe>/gi;\n\nconst extractAttrValue = (markup: string, attr: string) => {\n const escapedAttr = attr.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const regexp = new RegExp(`${escapedAttr}=\"([^\"]*)\"`, \"i\");\n const match = markup.match(regexp);\n return match ? match[1] : \"\";\n};\n\nconst decodeHtmlEntities = (value: string) =>\n value.replace(/&quot;/g, '\"').replace(/&amp;/g, \"&\");\n\nconst biliUrlMatcher = new MatchDecorator({\n regexp: biliVideoContextRegexp,\n decoration: (match, view) => {\n const source = match?.[0] || \"\";\n const iframeMarkup = unwrapFixedOutput(source);\n const fixedOutput = /^\\s*===/.test(source);\n const srcValueRaw = extractAttrValue(iframeMarkup, \"src\");\n const titleAttrRaw = extractAttrValue(iframeMarkup, \"data-title\");\n const dataUrlAttrRaw = extractAttrValue(iframeMarkup, \"data-url\");\n const titleAttr = titleAttrRaw ? decodeHtmlEntities(titleAttrRaw) : \"\";\n const decodedSrcValue = srcValueRaw ? decodeHtmlEntities(srcValueRaw) : \"\";\n const storedDataUrl = dataUrlAttrRaw\n ? decodeHtmlEntities(dataUrlAttrRaw)\n : \"\";\n // Extract and decode the original URL from stored attributes or API endpoint\n let originalUrl = storedDataUrl || decodedSrcValue;\n try {\n if (!storedDataUrl && decodedSrcValue) {\n const urlParams = new URLSearchParams(new URL(decodedSrcValue).search);\n const encodedUrl = urlParams.get(\"url\");\n if (encodedUrl) {\n originalUrl = decodeURIComponent(encodedUrl);\n }\n }\n } catch (error) {\n console.warn(\"Failed to decode video URL:\", error);\n }\n\n return Decoration.replace({\n widget: new PlaceholderWidget(\n titleAttr || \"Video\", // Display title from data-title\n {\n tag: \"video\",\n url: originalUrl, // Decoded original Bilibili URL\n title: titleAttr, // title from data-title attribute\n fixedOutput,\n },\n \"tag-video\",\n SelectedOption.Video,\n view\n ),\n });\n },\n});\n\nconst VideoPlaceholder = ViewPlugin.fromClass(\n class {\n placeholders: DecorationSet;\n constructor(view: EditorView) {\n this.placeholders = biliUrlMatcher.createDeco(view);\n }\n update(update: ViewUpdate) {\n this.placeholders = biliUrlMatcher.updateDeco(update, this.placeholders);\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 VideoPlaceholder;\n"],"names":["biliVideoContextRegexp","extractAttrValue","markup","attr","escapedAttr","regexp","match","decodeHtmlEntities","value","biliUrlMatcher","MatchDecorator","view","source","iframeMarkup","unwrapFixedOutput","fixedOutput","srcValueRaw","titleAttrRaw","dataUrlAttrRaw","titleAttr","decodedSrcValue","storedDataUrl","originalUrl","encodedUrl","error","Decoration","PlaceholderWidget","SelectedOption","VideoPlaceholder","ViewPlugin","update","instance","plugin","EditorView"],"mappings":";;;;AAYA,MAAMA,IACJ,+GAEIC,IAAmB,CAACC,GAAgBC,MAAiB;AACzD,QAAMC,IAAcD,EAAK,QAAQ,uBAAuB,MAAM,GACxDE,IAAS,IAAI,OAAO,GAAGD,CAAW,cAAc,GAAG,GACnDE,IAAQJ,EAAO,MAAMG,CAAM;AACjC,SAAOC,IAAQA,EAAM,CAAC,IAA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AerB,EAAe,WAAWqB,GAAQ,KAAK,YAAY;AAAA,IACzE;AAAA,EAAA;AAAA,EAEF;AAAA,IACE,aAAa,CAACC,MAAaA,EAAS;AAAA,IACpC,SAAS,CAACC,MACRC,EAAW,aAAa,GAAG,CAACtB,MACnBA,EAAK,OAAOqB,CAAM,GAAG,gBAAgBP,EAAW,IACxD;AAAA,EAAA;AAEP;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./types.cjs.js"),g=require("./utils/video.cjs.js"),u="[\\p{L}\\p{N}_]+",b=new RegExp(`^${u}$`,"u"),V=`\\{\\{(${u})\\}\\}`,p=()=>new RegExp(V,"gu"),E=t=>typeof t=="string"&&b.test(t),f=t=>{if(!t)return[];const e=[],c=p();let r;for(;(r=c.exec(t))!==null;)e.push(r[1]);return e},S=(t,e)=>{switch(t){case i.SelectedOption.Image:return{resourceUrl:e.url,resourceTitle:e.title,scalePercent:e.scalePercent};case i.SelectedOption.Video:return{resourceUrl:e.url,resourceTitle:e.title};case i.SelectedOption.Variable:return{variableName:e.title};default:return{resourceUrl:e.url??"",resourceTitle:e.title??""}}};function R(t,e){return c=>{const r=c.matchBefore(/\/(\w*)$/);if(!r)return null;const s=(l,o,a,n,m)=>{l.dispatch({changes:{from:a,to:n,insert:""}}),t(m)};return{from:r.from,to:r.to,options:[{label:e?.variable??"Variable",apply:(l,o,a,n)=>{s(l,o,a,n,i.SelectedOption.Variable)}},{label:e?.image??"Image",apply:(l,o,a,n)=>{s(l,o,a,n,i.SelectedOption.Image)}},{label:e?.video??"Video",apply:(l,o,a,n)=>{s(l,o,a,n,i.SelectedOption.Video)}}],filter:!1}}}const d=t=>g.getVideoEmbedUrl(t),h=(t,e)=>{const c=d(t),r=a=>a.replace(/&/g,"&amp;").replace(/"/g,"&quot;"),s=e?r(e):"",l=r(t),o=r(c);return`<iframe data-tag="video" data-title="${s}" data-url="${l}" class="w-full aspect-video rounded-lg border-0" src="${o}" allowfullscreen="" allow="autoplay; encrypted-media"></iframe>`};exports.createSlashCommands=R;exports.createVariableExpressionRegexp=p;exports.extractVariableNames=f;exports.getEmbedUrl=d;exports.getVideoContentToInsert=h;exports.isValidVariableName=E;exports.parseContentInfo=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./types.cjs.js"),E=require("./utils/video.cjs.js"),g="[\\p{L}\\p{N}_]+",h=new RegExp(`^${g}$`,"u"),w=`\\{\\{(${g})\\}\\}`,c="===",$=()=>new RegExp(w,"gu"),f=t=>typeof t=="string"&&h.test(t),V=t=>{if(!t)return[];const e=[],a=$();let r;for(;(r=a.exec(t))!==null;)e.push(r[1]);return e},x=(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:e.title};default:return{resourceUrl:e.url??"",resourceTitle:e.title??""}}};function S(t,e){return a=>{const r=a.matchBefore(/\/(\w*)$/);if(!r)return null;const l=(n,o,i,s,d)=>{n.dispatch({changes:{from:i,to:s,insert:""}}),t(d)};return{from:r.from,to:r.to,options:[{label:e?.variable??"Variable",apply:(n,o,i,s)=>{l(n,o,i,s,p.SelectedOption.Variable)}},{label:e?.image??"Image",apply:(n,o,i,s)=>{l(n,o,i,s,p.SelectedOption.Image)}},{label:e?.video??"Video",apply:(n,o,i,s)=>{l(n,o,i,s,p.SelectedOption.Video)}}],filter:!1}}}const b=t=>E.getVideoEmbedUrl(t),u=t=>t.replace(/&/g,"&amp;").replace(/"/g,"&quot;"),I=t=>t.replace(/([\[\]\\])/g,"\\$1"),R=t=>Math.max(1,Math.min(1e3,Math.round(t))),m=t=>{const e=t.trim();return e?new RegExp(`^${c}\\s*[\\s\\S]*?\\s*${c}$`).test(e)?e:`${c} ${e} ${c}`:`${c}${c}`},O=t=>{const e=t.trim(),a=new RegExp(`^${c}\\s*([\\s\\S]*?)\\s*${c}$`);return(e.match(a)?.[1]??e).trim()},A=({resourceUrl:t,resourceTitle:e,scalePercent:a})=>{const r=typeof a=="number"?R(a):void 0,l=u(t),n=e?u(e):void 0,o=e?I(e):"",i=typeof r=="number"&&r!==100?` width="${r}%"`:"",s=n?` alt="${n}" title="${n}"`:"",d=!r||r===100?`![${o}](${t})`:`<img src="${l}"${s}${i} />`;return m(d)},T=(t,e)=>{const a=b(t),r=e?u(e):"",l=u(t),n=u(a),o=`<iframe data-tag="video" data-title="${r}" data-url="${l}" class="w-full aspect-video rounded-lg border-0" src="${n}" allowfullscreen="" allow="autoplay; encrypted-media"></iframe>`;return m(o)};exports.createSlashCommands=S;exports.createVariableExpressionRegexp=$;exports.extractVariableNames=V;exports.getEmbedUrl=b;exports.getImageContentToInsert=A;exports.getVideoContentToInsert=T;exports.isValidVariableName=f;exports.parseContentInfo=x;exports.unwrapFixedOutput=O;exports.wrapWithFixedOutput=m;
2
2
  //# sourceMappingURL=utils.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs.js","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\nconst VARIABLE_NAME_SOURCE = \"[\\\\p{L}\\\\p{N}_]+\";\nconst VARIABLE_NAME_REGEXP = new RegExp(`^${VARIABLE_NAME_SOURCE}$`, \"u\");\nconst VARIABLE_EXPRESSION_PATTERN = `\\\\{\\\\{(${VARIABLE_NAME_SOURCE})\\\\}\\\\}`;\n\nconst createVariableExpressionRegexp = () =>\n new RegExp(VARIABLE_EXPRESSION_PATTERN, \"gu\");\n\nconst isValidVariableName = (name: string) =>\n typeof name === \"string\" && VARIABLE_NAME_REGEXP.test(name);\n\nconst extractVariableNames = (content: string) => {\n if (!content) {\n return [];\n }\n const matches: string[] = [];\n const regexp = createVariableExpressionRegexp();\n let match: RegExpExecArray | null;\n\n while ((match = regexp.exec(content)) !== null) {\n matches.push(match[1]);\n }\n\n return matches;\n};\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: dataset.title,\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 getVideoContentToInsert = (\n resourceUrl: string,\n resourceTitle: string\n) => {\n const embedUrl = getEmbedUrl(resourceUrl);\n const escapeAttr = (value: string) =>\n value.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\");\n const sanitizedTitle = resourceTitle ? escapeAttr(resourceTitle) : \"\";\n const sanitizedResourceUrl = escapeAttr(resourceUrl);\n const sanitizedEmbedUrl = escapeAttr(embedUrl);\n return `<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\nexport {\n createSlashCommands,\n parseContentInfo,\n getEmbedUrl,\n getVideoContentToInsert,\n isValidVariableName,\n extractVariableNames,\n createVariableExpressionRegexp,\n};\n"],"names":["VARIABLE_NAME_SOURCE","VARIABLE_NAME_REGEXP","VARIABLE_EXPRESSION_PATTERN","createVariableExpressionRegexp","isValidVariableName","name","extractVariableNames","content","matches","regexp","match","parseContentInfo","type","dataset","SelectedOption","createSlashCommands","onSelectOption","labels","context","word","handleSelect","view","_","from","to","selectedOption","getEmbedUrl","url","getVideoEmbedUrl","getVideoContentToInsert","resourceUrl","resourceTitle","embedUrl","escapeAttr","value","sanitizedTitle","sanitizedResourceUrl","sanitizedEmbedUrl"],"mappings":"oJAQMA,EAAuB,mBACvBC,EAAuB,IAAI,OAAO,IAAID,CAAoB,IAAK,GAAG,EAClEE,EAA8B,UAAUF,CAAoB,UAE5DG,EAAiC,IACrC,IAAI,OAAOD,EAA6B,IAAI,EAExCE,EAAuBC,GAC3B,OAAOA,GAAS,UAAYJ,EAAqB,KAAKI,CAAI,EAEtDC,EAAwBC,GAAoB,CAChD,GAAI,CAACA,EACH,MAAO,CAAA,EAET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GAAQ,OAAS,QACxB,MAAO,CAACI,EAAMC,EAAGC,EAAMC,IAAO,CAC5BJ,EAAaC,EAAMC,EAAGC,EAAMC,EAAIV,EAAAA,eAAe,KAAK,CACtD,CAAA,CACF,EAEF,OAAQ,EAAA,CAEZ,CACF,CAEA,MAAMY,EAAeC,GACZC,EAAAA,iBAAiBD,CAAG,EAGvBE,EAA0B,CAC9BC,EACAC,IACG,CACH,MAAMC,EAAWN,EAAYI,CAAW,EAClCG,EAAcC,GAClBA,EAAM,QAAQ,KAAM,OAAO,EAAE,QAAQ,KAAM,QAAQ,EAC/CC,EAAiBJ,EAAgBE,EAAWF,CAAa,EAAI,GAC7DK,EAAuBH,EAAWH,CAAW,EAC7CO,EAAoBJ,EAAWD,CAAQ,EAC7C,MAAO,wCAAwCG,CAAc,eAAeC,CAAoB,0DAA0DC,CAAiB,kEAC7K"}
1
+ {"version":3,"file":"utils.cjs.js","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\nconst VARIABLE_NAME_SOURCE = \"[\\\\p{L}\\\\p{N}_]+\";\nconst VARIABLE_NAME_REGEXP = new RegExp(`^${VARIABLE_NAME_SOURCE}$`, \"u\");\nconst VARIABLE_EXPRESSION_PATTERN = `\\\\{\\\\{(${VARIABLE_NAME_SOURCE})\\\\}\\\\}`;\nconst FIXED_OUTPUT_MARKER = \"===\";\n\nconst createVariableExpressionRegexp = () =>\n new RegExp(VARIABLE_EXPRESSION_PATTERN, \"gu\");\n\nconst isValidVariableName = (name: string) =>\n typeof name === \"string\" && VARIABLE_NAME_REGEXP.test(name);\n\nconst extractVariableNames = (content: string) => {\n if (!content) {\n return [];\n }\n const matches: string[] = [];\n const regexp = createVariableExpressionRegexp();\n let match: RegExpExecArray | null;\n\n while ((match = regexp.exec(content)) !== null) {\n matches.push(match[1]);\n }\n\n return matches;\n};\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: dataset.title,\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 extractVariableNames,\n createVariableExpressionRegexp,\n wrapWithFixedOutput,\n unwrapFixedOutput,\n};\n"],"names":["VARIABLE_NAME_SOURCE","VARIABLE_NAME_REGEXP","VARIABLE_EXPRESSION_PATTERN","FIXED_OUTPUT_MARKER","createVariableExpressionRegexp","isValidVariableName","name","extractVariableNames","content","matches","regexp","match","parseContentInfo","type","dataset","SelectedOption","createSlashCommands","onSelectOption","labels","context","word","handleSelect","view","_","from","to","selectedOption","getEmbedUrl","url","getVideoEmbedUrl","escapeHtmlAttribute","value","escapeMarkdownText","text","clampScalePercent","wrapWithFixedOutput","normalizedContent","unwrapFixedOutput","wrappedPattern","getImageContentToInsert","resourceUrl","resourceTitle","scalePercent","clampedScale","sanitizedHtmlUrl","sanitizedTitle","markdownTitle","widthAttribute","htmlTitleAttributes","imageMarkup","getVideoContentToInsert","embedUrl","sanitizedResourceUrl","sanitizedEmbedUrl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B,YAAAC,EACA,cAAAC,EACA,aAAAC,CACF,IAIM,CACJ,MAAMC,EACJ,OAAOD,GAAiB,SACpBR,EAAkBQ,CAAY,EAC9B,OACAE,EAAmBd,EAAoBU,CAAW,EAClDK,EAAiBJ,EACnBX,EAAoBW,CAAa,EACjC,OACEK,EAAgBL,EAAgBT,EAAmBS,CAAa,EAAI,GACpEM,EACJ,OAAOJ,GAAiB,UAAYA,IAAiB,IACjD,WAAWA,CAAY,KACvB,GACAK,EAAsBH,EACxB,SAASA,CAAc,YAAYA,CAAc,IACjD,GACEI,EACJ,CAACN,GAAgBA,IAAiB,IAC9B,KAAKG,CAAa,KAAKN,CAAW,IAClC,aAAaI,CAAgB,IAAII,CAAmB,GAAGD,CAAc,MAE3E,OAAOZ,EAAoBc,CAAW,CACxC,EAEMC,EAA0B,CAC9BV,EACAC,IACG,CACH,MAAMU,EAAWxB,EAAYa,CAAW,EAClCK,EAAiBJ,EACnBX,EAAoBW,CAAa,EACjC,GACEW,EAAuBtB,EAAoBU,CAAW,EACtDa,EAAoBvB,EAAoBqB,CAAQ,EAChDG,EAAc,wCAAwCT,CAAc,eAAeO,CAAoB,0DAA0DC,CAAiB,mEAExL,OAAOlB,EAAoBmB,CAAW,CACxC"}
@@ -31,5 +31,12 @@ declare function createSlashCommands(onSelectOption: (selectedOption: SelectedOp
31
31
  variable?: string;
32
32
  }): (context: CompletionContext) => CompletionResult | null;
33
33
  declare const getEmbedUrl: (url: string) => string;
34
+ declare const wrapWithFixedOutput: (content: string) => string;
35
+ declare const unwrapFixedOutput: (content: string) => string;
36
+ declare const getImageContentToInsert: ({ resourceUrl, resourceTitle, scalePercent, }: {
37
+ resourceUrl: string;
38
+ resourceTitle?: string;
39
+ scalePercent?: number;
40
+ }) => string;
34
41
  declare const getVideoContentToInsert: (resourceUrl: string, resourceTitle: string) => string;
35
- export { createSlashCommands, parseContentInfo, getEmbedUrl, getVideoContentToInsert, isValidVariableName, extractVariableNames, createVariableExpressionRegexp, };
42
+ export { createSlashCommands, parseContentInfo, getEmbedUrl, getImageContentToInsert, getVideoContentToInsert, isValidVariableName, extractVariableNames, createVariableExpressionRegexp, wrapWithFixedOutput, unwrapFixedOutput, };
@@ -1,27 +1,27 @@
1
- import { SelectedOption as c } from "./types.es.js";
2
- import { getVideoEmbedUrl as m } from "./utils/video.es.js";
3
- const u = "[\\p{L}\\p{N}_]+", d = new RegExp(`^${u}$`, "u"), g = `\\{\\{(${u})\\}\\}`, f = () => new RegExp(g, "gu"), R = (r) => typeof r == "string" && d.test(r), h = (r) => {
4
- if (!r)
1
+ import { SelectedOption as p } from "./types.es.js";
2
+ import { getVideoEmbedUrl as g } from "./utils/video.es.js";
3
+ const d = "[\\p{L}\\p{N}_]+", f = new RegExp(`^${d}$`, "u"), E = `\\{\\{(${d})\\}\\}`, s = "===", h = () => new RegExp(E, "gu"), A = (t) => typeof t == "string" && f.test(t), I = (t) => {
4
+ if (!t)
5
5
  return [];
6
- const e = [], i = f();
7
- let t;
8
- for (; (t = i.exec(r)) !== null; )
9
- e.push(t[1]);
6
+ const e = [], o = h();
7
+ let r;
8
+ for (; (r = o.exec(t)) !== null; )
9
+ e.push(r[1]);
10
10
  return e;
11
- }, A = (r, e) => {
12
- switch (r) {
13
- case c.Image:
11
+ }, S = (t, e) => {
12
+ switch (t) {
13
+ case p.Image:
14
14
  return {
15
15
  resourceUrl: e.url,
16
16
  resourceTitle: e.title,
17
17
  scalePercent: e.scalePercent
18
18
  };
19
- case c.Video:
19
+ case p.Video:
20
20
  return {
21
21
  resourceUrl: e.url,
22
22
  resourceTitle: e.title
23
23
  };
24
- case c.Variable:
24
+ case p.Variable:
25
25
  return {
26
26
  variableName: e.title
27
27
  };
@@ -32,18 +32,18 @@ const u = "[\\p{L}\\p{N}_]+", d = new RegExp(`^${u}$`, "u"), g = `\\{\\{(${u})\\
32
32
  };
33
33
  }
34
34
  };
35
- function w(r, e) {
36
- return (i) => {
37
- const t = i.matchBefore(/\/(\w*)$/);
38
- if (!t) return null;
39
- const s = (l, a, o, n, p) => {
40
- l.dispatch({
41
- changes: { from: o, to: n, insert: "" }
42
- }), r(p);
35
+ function T(t, e) {
36
+ return (o) => {
37
+ const r = o.matchBefore(/\/(\w*)$/);
38
+ if (!r) return null;
39
+ const l = (n, a, i, c, u) => {
40
+ n.dispatch({
41
+ changes: { from: i, to: c, insert: "" }
42
+ }), t(u);
43
43
  };
44
44
  return {
45
- from: t.from,
46
- to: t.to,
45
+ from: r.from,
46
+ to: r.to,
47
47
  options: [
48
48
  // {
49
49
  // label: labels?.divider ?? "Divider",
@@ -59,20 +59,20 @@ function w(r, e) {
59
59
  // },
60
60
  {
61
61
  label: e?.variable ?? "Variable",
62
- apply: (l, a, o, n) => {
63
- s(l, a, o, n, c.Variable);
62
+ apply: (n, a, i, c) => {
63
+ l(n, a, i, c, p.Variable);
64
64
  }
65
65
  },
66
66
  {
67
67
  label: e?.image ?? "Image",
68
- apply: (l, a, o, n) => {
69
- s(l, a, o, n, c.Image);
68
+ apply: (n, a, i, c) => {
69
+ l(n, a, i, c, p.Image);
70
70
  }
71
71
  },
72
72
  {
73
73
  label: e?.video ?? "Video",
74
- apply: (l, a, o, n) => {
75
- s(l, a, o, n, c.Video);
74
+ apply: (n, a, i, c) => {
75
+ l(n, a, i, c, p.Video);
76
76
  }
77
77
  }
78
78
  ],
@@ -80,17 +80,37 @@ function w(r, e) {
80
80
  };
81
81
  };
82
82
  }
83
- const E = (r) => m(r), I = (r, e) => {
84
- const i = E(r), t = (o) => o.replace(/&/g, "&amp;").replace(/"/g, "&quot;"), s = e ? t(e) : "", l = t(r), a = t(i);
85
- return `<iframe data-tag="video" data-title="${s}" data-url="${l}" class="w-full aspect-video rounded-lg border-0" src="${a}" allowfullscreen="" allow="autoplay; encrypted-media"></iframe>`;
83
+ const w = (t) => g(t), m = (t) => t.replace(/&/g, "&amp;").replace(/"/g, "&quot;"), b = (t) => t.replace(/([\[\]\\])/g, "\\$1"), R = (t) => Math.max(1, Math.min(1e3, Math.round(t))), $ = (t) => {
84
+ const e = t.trim();
85
+ return e ? new RegExp(
86
+ `^${s}\\s*[\\s\\S]*?\\s*${s}$`
87
+ ).test(e) ? e : `${s} ${e} ${s}` : `${s}${s}`;
88
+ }, U = (t) => {
89
+ const e = t.trim(), o = new RegExp(
90
+ `^${s}\\s*([\\s\\S]*?)\\s*${s}$`
91
+ );
92
+ return (e.match(o)?.[1] ?? e).trim();
93
+ }, _ = ({
94
+ resourceUrl: t,
95
+ resourceTitle: e,
96
+ scalePercent: o
97
+ }) => {
98
+ const r = typeof o == "number" ? R(o) : void 0, l = m(t), n = e ? m(e) : void 0, a = e ? b(e) : "", i = typeof r == "number" && r !== 100 ? ` width="${r}%"` : "", c = n ? ` alt="${n}" title="${n}"` : "", u = !r || r === 100 ? `![${a}](${t})` : `<img src="${l}"${c}${i} />`;
99
+ return $(u);
100
+ }, M = (t, e) => {
101
+ const o = w(t), r = e ? m(e) : "", l = m(t), n = m(o), a = `<iframe data-tag="video" data-title="${r}" data-url="${l}" class="w-full aspect-video rounded-lg border-0" src="${n}" allowfullscreen="" allow="autoplay; encrypted-media"></iframe>`;
102
+ return $(a);
86
103
  };
87
104
  export {
88
- w as createSlashCommands,
89
- f as createVariableExpressionRegexp,
90
- h as extractVariableNames,
91
- E as getEmbedUrl,
92
- I as getVideoContentToInsert,
93
- R as isValidVariableName,
94
- A as parseContentInfo
105
+ T as createSlashCommands,
106
+ h as createVariableExpressionRegexp,
107
+ I as extractVariableNames,
108
+ w as getEmbedUrl,
109
+ _ as getImageContentToInsert,
110
+ M as getVideoContentToInsert,
111
+ A as isValidVariableName,
112
+ S as parseContentInfo,
113
+ U as unwrapFixedOutput,
114
+ $ as wrapWithFixedOutput
95
115
  };
96
116
  //# sourceMappingURL=utils.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.es.js","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\nconst VARIABLE_NAME_SOURCE = \"[\\\\p{L}\\\\p{N}_]+\";\nconst VARIABLE_NAME_REGEXP = new RegExp(`^${VARIABLE_NAME_SOURCE}$`, \"u\");\nconst VARIABLE_EXPRESSION_PATTERN = `\\\\{\\\\{(${VARIABLE_NAME_SOURCE})\\\\}\\\\}`;\n\nconst createVariableExpressionRegexp = () =>\n new RegExp(VARIABLE_EXPRESSION_PATTERN, \"gu\");\n\nconst isValidVariableName = (name: string) =>\n typeof name === \"string\" && VARIABLE_NAME_REGEXP.test(name);\n\nconst extractVariableNames = (content: string) => {\n if (!content) {\n return [];\n }\n const matches: string[] = [];\n const regexp = createVariableExpressionRegexp();\n let match: RegExpExecArray | null;\n\n while ((match = regexp.exec(content)) !== null) {\n matches.push(match[1]);\n }\n\n return matches;\n};\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: dataset.title,\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 getVideoContentToInsert = (\n resourceUrl: string,\n resourceTitle: string\n) => {\n const embedUrl = getEmbedUrl(resourceUrl);\n const escapeAttr = (value: string) =>\n value.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\");\n const sanitizedTitle = resourceTitle ? escapeAttr(resourceTitle) : \"\";\n const sanitizedResourceUrl = escapeAttr(resourceUrl);\n const sanitizedEmbedUrl = escapeAttr(embedUrl);\n return `<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\nexport {\n createSlashCommands,\n parseContentInfo,\n getEmbedUrl,\n getVideoContentToInsert,\n isValidVariableName,\n extractVariableNames,\n createVariableExpressionRegexp,\n};\n"],"names":["VARIABLE_NAME_SOURCE","VARIABLE_NAME_REGEXP","VARIABLE_EXPRESSION_PATTERN","createVariableExpressionRegexp","isValidVariableName","name","extractVariableNames","content","matches","regexp","match","parseContentInfo","type","dataset","SelectedOption","createSlashCommands","onSelectOption","labels","context","word","handleSelect","view","_","from","to","selectedOption","getEmbedUrl","url","getVideoEmbedUrl","getVideoContentToInsert","resourceUrl","resourceTitle","embedUrl","escapeAttr","value","sanitizedTitle","sanitizedResourceUrl","sanitizedEmbedUrl"],"mappings":";;AAQA,MAAMA,IAAuB,oBACvBC,IAAuB,IAAI,OAAO,IAAID,CAAoB,KAAK,GAAG,GAClEE,IAA8B,UAAUF,CAAoB,WAE5DG,IAAiC,MACrC,IAAI,OAAOD,GAA6B,IAAI,GAExCE,IAAsB,CAACC,MAC3B,OAAOA,KAAS,YAAYJ,EAAqB,KAAKI,CAAI,GAEtDC,IAAuB,CAACC,MAAoB;AAChD,MAAI,CAACA;AACH,WAAO,CAAA;AAET,QAAMC,IAAoB,CAAA,GACpBC,IAASN,EAAA;AACf,MAAIO;AAEJ,UAAQA,IAAQD,EAAO,KAAKF,CAAO,OAAO;AACxC,IAAAC,EAAQ,KAAKE,EAAM,CAAC,CAAC;AAGvB,SAAOF;AACT,GAEMG,IAAmB,CACvBC,GACAC,MACG;AACH,UAAQD,GAAA;AAAA,IACN,KAAKE,EAAe;AAClB,aAAO;AAAA,QACL,aAAaD,EAAQ;AAAA,QACrB,eAAeA,EAAQ;AAAA,QACvB,cAAcA,EAAQ;AAAA,MAAA;AAAA,IAG1B,KAAKC,EAAe;AAClB,aAAO;AAAA,QACL,aAAaD,EAAQ;AAAA,QACrB,eAAeA,EAAQ;AAAA,MAAA;AAAA,IAE3B,KAAKC,EAAe;AAClB,aAAO;AAAA,QACL,cAAcD,EAAQ;AAAA,MAAA;AAAA,IAE1B;AACE,aAAO;AAAA,QACL,aAAaA,EAAQ,OAAO;AAAA,QAC5B,eAAeA,EAAQ,SAAS;AAAA,MAAA;AAAA,EAClC;AAEN;AAEA,SAASE,EACPC,GACAC,GAOA;AACA,SAAO,CAACC,MAAwD;AAC9D,UAAMC,IAAOD,EAAQ,YAAY,UAAU;AAC3C,QAAI,CA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CAAW,GAC7CO,IAAoBJ,EAAWD,CAAQ;AAC7C,SAAO,wCAAwCG,CAAc,eAAeC,CAAoB,0DAA0DC,CAAiB;AAC7K;"}
1
+ {"version":3,"file":"utils.es.js","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\nconst VARIABLE_NAME_SOURCE = \"[\\\\p{L}\\\\p{N}_]+\";\nconst VARIABLE_NAME_REGEXP = new RegExp(`^${VARIABLE_NAME_SOURCE}$`, \"u\");\nconst VARIABLE_EXPRESSION_PATTERN = `\\\\{\\\\{(${VARIABLE_NAME_SOURCE})\\\\}\\\\}`;\nconst FIXED_OUTPUT_MARKER = \"===\";\n\nconst createVariableExpressionRegexp = () =>\n new RegExp(VARIABLE_EXPRESSION_PATTERN, \"gu\");\n\nconst isValidVariableName = (name: string) =>\n typeof name === \"string\" && VARIABLE_NAME_REGEXP.test(name);\n\nconst extractVariableNames = (content: string) => {\n if (!content) {\n return [];\n }\n const matches: string[] = [];\n const regexp = createVariableExpressionRegexp();\n let match: RegExpExecArray | null;\n\n while ((match = regexp.exec(content)) !== null) {\n matches.push(match[1]);\n }\n\n return matches;\n};\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: dataset.title,\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 extractVariableNames,\n createVariableExpressionRegexp,\n wrapWithFixedOutput,\n unwrapFixedOutput,\n};\n"],"names":["VARIABLE_NAME_SOURCE","VARIABLE_NAME_REGEXP","VARIABLE_EXPRESSION_PATTERN","FIXED_OUTPUT_MARKER","createVariableExpressionRegexp","isValidVariableName","name","extractVariableNames","content","matches","regexp","match","parseContentInfo","type","dataset","SelectedOption","createSlashCommands","onSelectOption","labels","context","word","handleSelect","view","_","from","to","selectedOption","getEmbedUrl","url","getVideoEmbedUrl","escapeHtmlAttribute","value","escapeMarkdownText","text","clampScalePercent","wrapWithFixedOutput","normalizedContent","unwrapFixedOutput","wrappedPattern","getImageContentToInsert","resourceUrl","resourceTitle","scalePercent","clampedScale","sanitizedHtmlUrl","sanitizedTitle","markdownTitle","widthAttribute","htmlTitleAttributes","imageMarkup","getVideoContentToInsert","embedUrl","sanitizedResourceUrl","sanitizedEmbedUrl","videoMarkup"],"mappings":";;AAQA,MAAMA,IAAuB,oBACvBC,IAAuB,IAAI,OAAO,IAAID,CAAoB,KAAK,GAAG,GAClEE,IAA8B,UAAUF,CAAoB,WAC5DG,IAAsB,OAEtBC,IAAiC,MACrC,IAAI,OAAOF,GAA6B,IAAI,GAExCG,IAAsB,CAACC,MAC3B,OAAOA,KAAS,YAAYL,EAAqB,KAAKK,CAAI,GAEtDC,IAAuB,CAACC,MAAoB;AAChD,MAAI,CAACA;AACH,WAAO,CAAA;AAET,QAAMC,IAAoB,CAAA,GACpBC,IAASN,EAAA;AACf,MAAIO;AAEJ,UAAQA,IAAQD,EAAO,KAAKF,CAAO,OAAO;AACxC,IAAAC,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