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.
- package/dist/_virtual/index.cjs10.js +1 -1
- package/dist/_virtual/index.cjs9.js +1 -1
- package/dist/_virtual/index.es10.js +2 -2
- package/dist/_virtual/index.es9.js +2 -2
- package/dist/assets/markdown-flow-ui.css +1 -1
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs.js +1 -1
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js +321 -317
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.cjs.js +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.cjs.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.es.js +48 -44
- package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.cjs.js +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.cjs.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.d.ts +1 -0
- package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.es.js +38 -28
- package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.cjs.js +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.cjs.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.es.js +28 -26
- package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/utils.cjs.js +1 -1
- package/dist/components/MarkdownFlowEditor/utils.cjs.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/utils.d.ts +8 -1
- package/dist/components/MarkdownFlowEditor/utils.es.js +59 -39
- package/dist/components/MarkdownFlowEditor/utils.es.js.map +1 -1
- package/dist/components/Slide/Slide.cjs.js.map +1 -1
- package/dist/components/Slide/Slide.es.js.map +1 -1
- package/dist/components/Slide/useSlide.cjs.js.map +1 -1
- package/dist/components/Slide/useSlide.es.js.map +1 -1
- package/dist/components/Slide/utils/streamingNavigation.cjs.js.map +1 -1
- package/dist/components/Slide/utils/streamingNavigation.es.js.map +1 -1
- 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
- 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
- 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
- package/dist/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js +1 -1
- 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",
|
|
3
|
-
const e =
|
|
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 =
|
|
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 =
|
|
7
|
+
const s = r("circle");
|
|
8
8
|
s.setAttribute("cx", "9"), s.setAttribute("cy", "9"), s.setAttribute("r", "2");
|
|
9
|
-
const
|
|
10
|
-
return
|
|
11
|
-
},
|
|
12
|
-
const e =
|
|
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 =
|
|
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 =
|
|
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
|
|
20
|
-
constructor(t, s,
|
|
21
|
-
super(), this.text = t, this.dataset = s, this.styleClass =
|
|
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
|
|
26
|
-
for (const
|
|
27
|
-
if ((typeof
|
|
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
|
-
(
|
|
30
|
+
(o, c, d) => {
|
|
31
31
|
if (d.spec.widget === this)
|
|
32
|
-
return t =
|
|
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
|
-
|
|
43
|
-
|
|
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:
|
|
49
|
-
from:
|
|
50
|
+
content: n.textContent,
|
|
51
|
+
from: a,
|
|
50
52
|
to: o,
|
|
51
53
|
target: i.currentTarget
|
|
52
54
|
}
|
|
53
55
|
});
|
|
54
|
-
window.dispatchEvent(
|
|
55
|
-
}), this.dataset.
|
|
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
|
|
59
|
-
i.appendChild(
|
|
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
|
|
71
|
+
return t;
|
|
62
72
|
}
|
|
63
73
|
ignoreEvent() {
|
|
64
74
|
return !1;
|
|
65
75
|
}
|
|
66
76
|
}
|
|
67
77
|
export {
|
|
68
|
-
|
|
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
|
|
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,EAAI,a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,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
|
|
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(/"/g,'"').replace(/&/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
|
|
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(/"/g, '\"').replace(/&/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,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F,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
|
|
2
|
-
import { SelectedOption as
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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(/"/g, '"').replace(/&/g, "&"), f = new R({
|
|
9
|
+
regexp: A,
|
|
9
10
|
decoration: (e, t) => {
|
|
10
|
-
const
|
|
11
|
-
let
|
|
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 (!
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
if (!u && c) {
|
|
15
|
+
const h = new URLSearchParams(new URL(c).search).get("url");
|
|
16
|
+
h && (m = decodeURIComponent(h));
|
|
16
17
|
}
|
|
17
|
-
} catch (
|
|
18
|
-
console.warn("Failed to decode video URL:",
|
|
18
|
+
} catch (g) {
|
|
19
|
+
console.warn("Failed to decode video URL:", g);
|
|
19
20
|
}
|
|
20
|
-
return
|
|
21
|
-
widget: new
|
|
22
|
-
|
|
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:
|
|
27
|
+
url: m,
|
|
27
28
|
// Decoded original Bilibili URL
|
|
28
|
-
title:
|
|
29
|
+
title: p,
|
|
29
30
|
// title from data-title attribute
|
|
31
|
+
fixedOutput: a
|
|
30
32
|
},
|
|
31
33
|
"tag-video",
|
|
32
|
-
|
|
34
|
+
V.Video,
|
|
33
35
|
t
|
|
34
36
|
)
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
|
-
}),
|
|
39
|
+
}), M = x.fromClass(
|
|
38
40
|
class {
|
|
39
41
|
constructor(e) {
|
|
40
|
-
this.placeholders =
|
|
42
|
+
this.placeholders = f.createDeco(e);
|
|
41
43
|
}
|
|
42
44
|
update(e) {
|
|
43
|
-
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) =>
|
|
50
|
+
provide: (e) => U.atomicRanges.of((t) => t.plugin(e)?.placeholders || w.none)
|
|
49
51
|
}
|
|
50
52
|
);
|
|
51
53
|
export {
|
|
52
|
-
|
|
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
|
|
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(/"/g, '\"').replace(/&/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,EA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,EAAW;AAAA,EAClC,MAAM;AAAA,IAEJ,YAAYlB,GAAkB;AAC5B,WAAK,eAAeF,EAAe,WAAWE,CAAI;AAAA,IACpD;AAAA,IACA,OAAOmB,GAAoB;AACzB,WAAK,eAAerB,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
|
|
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,"&").replace(/"/g,"""),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?``:`<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, \"&\").replace(/\"/g, \""\");\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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F,GAAQ,UAAY,WAC3B,MAAO,CAACI,EAAMC,EAAGC,EAAMC,IAAO,CAC5BJ,EAAaC,EAAMC,EAAGC,EAAMC,EAAIV,EAAAA,eAAe,QAAQ,CACzD,CAAA,EAEF,CACE,MAAOG,GAAQ,OAAS,QACxB,MAAO,CAACI,EAAMC,EAAGC,EAAMC,IAAO,CAC5BJ,EAAaC,EAAMC,EAAGC,EAAMC,EAAIV,EAAAA,eAAe,KAAK,CACtD,CAAA,EAEF,CACE,MAAOG,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, \"&\").replace(/\"/g, \""\");\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 ? ``\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":"oJAQMA,EAAuB,mBACvBC,EAAuB,IAAI,OAAO,IAAID,CAAoB,IAAK,GAAG,EAClEE,EAA8B,UAAUF,CAAoB,UAC5DG,EAAsB,MAEtBC,EAAiC,IACrC,IAAI,OAAOF,EAA6B,IAAI,EAExCG,EAAuBC,GAC3B,OAAOA,GAAS,UAAYL,EAAqB,KAAKK,CAAI,EAEtDC,EAAwBC,GAAoB,CAChD,GAAI,CAACA,EACH,MAAO,CAAA,EAET,MAAMC,EAAoB,CAAA,EACpBC,EAASN,EAAA,EACf,IAAIO,EAEJ,MAAQA,EAAQD,EAAO,KAAKF,CAAO,KAAO,MACxCC,EAAQ,KAAKE,EAAM,CAAC,CAAC,EAGvB,OAAOF,CACT,EAEMG,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,MAAO,CACL,aAAcD,EAAQ,KAAA,EAE1B,QACE,MAAO,CACL,YAAaA,EAAQ,KAAO,GAC5B,cAAeA,EAAQ,OAAS,EAAA,CAClC,CAEN,EAEA,SAASE,EACPC,EACAC,EAOA,CACA,OAAQC,GAAwD,CAC9D,MAAMC,EAAOD,EAAQ,YAAY,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AAiB,IAAIjC,CAAmB,GARhE,GAAGA,CAAmB,GAAGA,CAAmB,EASvD,EAEMkC,EAAqB7B,GAAoB,CAC7C,MAAM4B,EAAoB5B,EAAQ,KAAA,EAC5B8B,EAAiB,IAAI,OACzB,IAAInC,CAAmB,uBAAuBA,CAAmB,GAAA,EAGnE,OADciC,EAAkB,MAAME,CAAc,IACpC,CAAC,GAAKF,GAAmB,KAAA,CAC3C,EAEMG,EAA0B,CAAC,CAC/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
|
|
2
|
-
import { getVideoEmbedUrl as
|
|
3
|
-
const
|
|
4
|
-
if (!
|
|
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 = [],
|
|
7
|
-
let
|
|
8
|
-
for (; (
|
|
9
|
-
e.push(
|
|
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
|
-
},
|
|
12
|
-
switch (
|
|
13
|
-
case
|
|
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
|
|
19
|
+
case p.Video:
|
|
20
20
|
return {
|
|
21
21
|
resourceUrl: e.url,
|
|
22
22
|
resourceTitle: e.title
|
|
23
23
|
};
|
|
24
|
-
case
|
|
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
|
|
36
|
-
return (
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
changes: { from:
|
|
42
|
-
}),
|
|
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:
|
|
46
|
-
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: (
|
|
63
|
-
|
|
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: (
|
|
69
|
-
|
|
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: (
|
|
75
|
-
|
|
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
|
|
84
|
-
const
|
|
85
|
-
return
|
|
83
|
+
const w = (t) => g(t), m = (t) => t.replace(/&/g, "&").replace(/"/g, """), 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 ? `` : `<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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
A as
|
|
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, \"&\").replace(/\"/g, \""\");\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,U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;AAAA,QAEF;AAAA,UACE,OAAOG,GAAQ,SAAS;AAAA,UACxB,OAAO,CAACI,GAAMC,GAAGC,GAAMC,MAAO;AAC5B,YAAAJ,EAAaC,GAAMC,GAAGC,GAAMC,GAAIV,EAAe,KAAK;AAAA,UACtD;AAAA,QAAA;AAAA,QAEF;AAAA,UACE,OAAOG,GAAQ,SAAS;AAAA,UACxB,OAAO,CAACI,GAAMC,GAAGC,GAAMC,MAAO;AAC5B,YAAAJ,EAAaC,GAAMC,GAAGC,GAAMC,GAAIV,EAAe,KAAK;AAAA,UACtD;AAAA,QAAA;AAAA,MACF;AAAA,MAEF,QAAQ;AAAA,IAAA;AAAA,EAEZ;AACF;AAEA,MAAMY,IAAc,CAACC,MACZC,EAAiBD,CAAG,GAGvBE,IAA0B,CAC9BC,GACAC,MACG;AACH,QAAMC,IAAWN,EAAYI,CAAW,GAClCG,IAAa,CAACC,MAClBA,EAAM,QAAQ,MAAM,OAAO,EAAE,QAAQ,MAAM,QAAQ,GAC/CC,IAAiBJ,IAAgBE,EAAWF,CAAa,IAAI,IAC7DK,IAAuBH,EAAWH,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, \"&\").replace(/\"/g, \""\");\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 ? ``\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,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,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