@vizel/core 0.0.1-alpha.1 → 0.0.1-alpha.3

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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.d.ts +13 -13
  3. package/dist/index.js +141 -141
  4. package/dist/index10.js +70 -110
  5. package/dist/index11.js +135 -168
  6. package/dist/index12.js +83 -74
  7. package/dist/index13.js +13 -134
  8. package/dist/index14.js +13 -146
  9. package/dist/index15.js +303 -15
  10. package/dist/index16.js +69 -14
  11. package/dist/index17.js +26 -295
  12. package/dist/index18.js +2 -2
  13. package/dist/index19.js +355 -24
  14. package/dist/index20.js +25 -264
  15. package/dist/index21.js +85 -68
  16. package/dist/index22.js +97 -353
  17. package/dist/index23.js +66 -84
  18. package/dist/index24.js +12 -36
  19. package/dist/index25.js +53 -92
  20. package/dist/index26.js +132 -96
  21. package/dist/index27.js +59 -126
  22. package/dist/index28.js +37 -53
  23. package/dist/index29.js +19 -62
  24. package/dist/index3.js +165 -60
  25. package/dist/index30.js +9 -37
  26. package/dist/index31.js +143 -19
  27. package/dist/index32.js +264 -11
  28. package/dist/index33.js +92 -9
  29. package/dist/index34.js +63 -16
  30. package/dist/index35.js +4 -58
  31. package/dist/index36.js +123 -15
  32. package/dist/index37.js +305 -42
  33. package/dist/index38.js +487 -4
  34. package/dist/index39.js +37 -112
  35. package/dist/index4.js +10 -86
  36. package/dist/index40.js +653 -301
  37. package/dist/index41.js +4 -487
  38. package/dist/index42.js +4 -48
  39. package/dist/index43.js +206 -642
  40. package/dist/index44.js +82 -4
  41. package/dist/index45.js +17 -4
  42. package/dist/index46.js +57 -237
  43. package/dist/index47.js +15 -82
  44. package/dist/index48.js +190 -274
  45. package/dist/index49.js +281 -1497
  46. package/dist/index5.js +132 -10
  47. package/dist/index50.js +1502 -5
  48. package/dist/index51.js +5 -1561
  49. package/dist/index52.js +1551 -192
  50. package/dist/index53.js +1 -1
  51. package/dist/index54.js +84 -21
  52. package/dist/index55.js +246 -10
  53. package/dist/index56.js +3 -7
  54. package/dist/index57.js +1231 -7
  55. package/dist/index58.js +731 -11
  56. package/dist/index59.js +21 -19
  57. package/dist/index6.js +48 -131
  58. package/dist/index60.js +10 -25
  59. package/dist/index61.js +6 -83
  60. package/dist/index62.js +7 -245
  61. package/dist/index63.js +11 -1229
  62. package/dist/index64.js +17 -732
  63. package/dist/index65.js +25 -3
  64. package/dist/index66.js +53 -1059
  65. package/dist/index67.js +1059 -53
  66. package/dist/index69.js +90 -3
  67. package/dist/index7.js +228 -409
  68. package/dist/index70.js +3 -90
  69. package/dist/index8.js +111 -45
  70. package/dist/index9.js +409 -228
  71. package/package.json +54 -80
package/dist/index9.js CHANGED
@@ -1,275 +1,456 @@
1
- import { Graphviz as H } from "@hpcc-js/wasm-graphviz";
2
- import { Node as G, mergeAttributes as S } from "@tiptap/core";
3
- import I from "mermaid";
4
- import { default as Q } from "mermaid";
5
- let $ = 0;
6
- function B() {
7
- return `vizel-diagram-${Date.now()}-${++$}`;
8
- }
9
- const O = {
10
- name: "diagram",
11
- start: "```",
12
- tokenize(e) {
13
- const a = e.match(/^```mermaid\n([\s\S]*?)```/);
14
- if (a?.[1] !== void 0)
15
- return {
16
- type: "diagram",
17
- raw: a[0],
18
- code: a[1].trim(),
19
- diagramType: "mermaid"
20
- };
21
- const i = e.match(/^```dot\n([\s\S]*?)```/);
22
- if (i?.[1] !== void 0)
23
- return {
24
- type: "diagram",
25
- raw: i[0],
26
- code: i[1].trim(),
27
- diagramType: "graphviz"
28
- };
29
- const r = e.match(/^```graphviz\n([\s\S]*?)```/);
30
- if (r?.[1] !== void 0)
31
- return {
32
- type: "diagram",
33
- raw: r[0],
34
- code: r[1].trim(),
35
- diagramType: "graphviz"
36
- };
1
+ import { Node as w, mergeAttributes as f } from "@tiptap/core";
2
+ import { PluginKey as b, Plugin as v } from "./index38.js";
3
+ const u = [
4
+ // Video - these providers support CORS on their oEmbed endpoints
5
+ {
6
+ name: "youtube",
7
+ patterns: [
8
+ /^https?:\/\/(www\.)?youtube\.com\/watch\?v=[\w-]+/,
9
+ /^https?:\/\/youtu\.be\/[\w-]+/,
10
+ /^https?:\/\/(www\.)?youtube\.com\/embed\/[\w-]+/,
11
+ /^https?:\/\/(www\.)?youtube\.com\/shorts\/[\w-]+/
12
+ ],
13
+ oEmbedEndpoint: "https://www.youtube.com/oembed",
14
+ supportsCors: !0
15
+ },
16
+ {
17
+ name: "vimeo",
18
+ patterns: [/^https?:\/\/(www\.)?vimeo\.com\/\d+/],
19
+ oEmbedEndpoint: "https://vimeo.com/api/oembed.json",
20
+ supportsCors: !0
21
+ },
22
+ {
23
+ name: "loom",
24
+ patterns: [/^https?:\/\/(www\.)?loom\.com\/share\/[\w-]+/],
25
+ oEmbedEndpoint: "https://www.loom.com/v1/oembed",
26
+ supportsCors: !0
27
+ },
28
+ {
29
+ name: "tiktok",
30
+ patterns: [/^https?:\/\/(www\.)?tiktok\.com\/@[\w.-]+\/video\/\d+/],
31
+ oEmbedEndpoint: "https://www.tiktok.com/oembed",
32
+ supportsCors: !0
33
+ },
34
+ // Social - these do NOT support CORS, require server-side proxy
35
+ {
36
+ name: "twitter",
37
+ patterns: [
38
+ /^https?:\/\/(twitter\.com|x\.com)\/\w+\/status\/\d+/,
39
+ /^https?:\/\/(twitter\.com|x\.com)\/\w+\/moments\/\d+/
40
+ ],
41
+ oEmbedEndpoint: "https://publish.twitter.com/oembed",
42
+ supportsCors: !1
43
+ },
44
+ {
45
+ name: "instagram",
46
+ patterns: [
47
+ /^https?:\/\/(www\.)?instagram\.com\/(p|reel)\/[\w-]+/,
48
+ /^https?:\/\/instagr\.am\/(p|reel)\/[\w-]+/
49
+ ],
50
+ oEmbedEndpoint: "https://graph.facebook.com/v10.0/instagram_oembed",
51
+ supportsCors: !1
52
+ },
53
+ // Dev - CodePen and CodeSandbox support CORS
54
+ {
55
+ name: "codepen",
56
+ patterns: [/^https?:\/\/(www\.)?codepen\.io\/[\w-]+\/pen\/[\w-]+/],
57
+ oEmbedEndpoint: "https://codepen.io/api/oembed",
58
+ supportsCors: !0
59
+ },
60
+ {
61
+ name: "codesandbox",
62
+ patterns: [/^https?:\/\/(www\.)?codesandbox\.io\/s\/[\w-]+/],
63
+ oEmbedEndpoint: "https://codesandbox.io/oembed",
64
+ supportsCors: !0
65
+ },
66
+ {
67
+ name: "github-gist",
68
+ patterns: [/^https?:\/\/gist\.github\.com\/[\w-]+\/[\w]+/],
69
+ supportsCors: !1
70
+ },
71
+ // Design
72
+ {
73
+ name: "figma",
74
+ patterns: [
75
+ /^https?:\/\/(www\.)?figma\.com\/(file|design)\/[\w-]+/,
76
+ /^https?:\/\/(www\.)?figma\.com\/proto\/[\w-]+/
77
+ ],
78
+ oEmbedEndpoint: "https://www.figma.com/api/oembed",
79
+ supportsCors: !0
80
+ },
81
+ {
82
+ name: "dribbble",
83
+ patterns: [/^https?:\/\/(www\.)?dribbble\.com\/shots\/[\w-]+/],
84
+ supportsCors: !1
85
+ },
86
+ // Music - Spotify and SoundCloud support CORS
87
+ {
88
+ name: "spotify",
89
+ patterns: [/^https?:\/\/open\.spotify\.com\/(track|album|playlist|episode|show)\/[\w]+/],
90
+ oEmbedEndpoint: "https://open.spotify.com/oembed",
91
+ supportsCors: !0
92
+ },
93
+ {
94
+ name: "soundcloud",
95
+ patterns: [/^https?:\/\/(www\.)?soundcloud\.com\/[\w-]+\/[\w-]+/],
96
+ oEmbedEndpoint: "https://soundcloud.com/oembed",
97
+ supportsCors: !0
98
+ },
99
+ // Other
100
+ {
101
+ name: "slideshare",
102
+ patterns: [/^https?:\/\/(www\.)?slideshare\.net\/[\w-]+\/[\w-]+/],
103
+ oEmbedEndpoint: "https://www.slideshare.net/api/oembed/2",
104
+ supportsCors: !1
37
105
  }
38
- };
39
- let A = !1;
40
- function P(e) {
41
- A || (I.initialize({
42
- startOnLoad: !1,
43
- securityLevel: "loose",
44
- theme: "default",
45
- fontFamily: "var(--vizel-font-sans)",
46
- ...e
47
- }), A = !0);
48
- }
49
- let L = null, C = !1, h = null;
50
- function R() {
51
- return L ? Promise.resolve(L) : (C && h || (C = !0, h = H.load().then((e) => (L = e, C = !1, e))), h);
106
+ ];
107
+ function c(t, e = u) {
108
+ for (const n of e)
109
+ for (const r of n.patterns)
110
+ if (r.test(t))
111
+ return n;
112
+ return null;
52
113
  }
53
- async function V(e) {
54
- if (!e.trim())
55
- return { svg: "", error: null };
114
+ function h(t) {
56
115
  try {
57
- const a = B(), { svg: i } = await I.render(a, e);
58
- return { svg: i, error: null };
59
- } catch (a) {
60
- return {
61
- svg: "",
62
- error: a instanceof Error ? a.message : "Invalid Mermaid syntax"
63
- };
116
+ return new URL(t), !0;
117
+ } catch {
118
+ return !1;
64
119
  }
65
120
  }
66
- async function K(e, a = "dot") {
67
- if (!e.trim())
68
- return { svg: "", error: null };
121
+ async function g(t, e) {
122
+ if (!(e.oEmbedEndpoint && e.supportsCors))
123
+ return null;
69
124
  try {
70
- return { svg: (await R()).layout(e, "svg", a), error: null };
71
- } catch (i) {
72
- return {
73
- svg: "",
74
- error: i instanceof Error ? i.message : "Invalid DOT syntax"
75
- };
125
+ const n = new URL(e.oEmbedEndpoint);
126
+ n.searchParams.set("url", t), n.searchParams.set("format", "json");
127
+ const r = await fetch(n.toString(), {
128
+ headers: {
129
+ Accept: "application/json"
130
+ }
131
+ });
132
+ return r.ok ? await r.json() : null;
133
+ } catch {
134
+ return null;
76
135
  }
77
136
  }
78
- const _ = `flowchart TD
79
- A[Start] --> B{Decision}
80
- B -->|Yes| C[Action 1]
81
- B -->|No| D[Action 2]
82
- C --> E[End]
83
- D --> E`, F = `digraph G {
84
- rankdir=LR
85
- node [shape=box, style=rounded]
86
-
87
- A [label="Start"]
88
- B [label="Process"]
89
- C [label="End"]
90
-
91
- A -> B -> C
92
- }`;
93
- function x(e) {
94
- switch (e) {
95
- case "mermaid":
96
- return "Mermaid";
97
- case "graphviz":
98
- return "GraphViz";
99
- default:
100
- return "Diagram";
137
+ function E(t, e) {
138
+ return t.html ? {
139
+ ...e,
140
+ type: "oembed",
141
+ html: t.html,
142
+ ...t.width !== void 0 && { width: t.width },
143
+ ...t.height !== void 0 && { height: t.height },
144
+ ...t.title !== void 0 && { title: t.title },
145
+ ...t.description !== void 0 && { description: t.description },
146
+ ...t.thumbnail_url !== void 0 && { image: t.thumbnail_url },
147
+ ...t.provider_name !== void 0 && { siteName: t.provider_name }
148
+ } : t.title || t.thumbnail_url ? {
149
+ ...e,
150
+ type: "ogp",
151
+ ...t.title !== void 0 && { title: t.title },
152
+ ...t.description !== void 0 && { description: t.description },
153
+ ...t.thumbnail_url !== void 0 && { image: t.thumbnail_url },
154
+ ...t.provider_name !== void 0 && { siteName: t.provider_name }
155
+ } : null;
156
+ }
157
+ function y(t = u) {
158
+ return async (e) => {
159
+ const n = c(e, t), r = {
160
+ url: e,
161
+ type: "link",
162
+ ...n?.name !== void 0 && { provider: n.name }
163
+ };
164
+ if (!(n?.oEmbedEndpoint && n.supportsCors))
165
+ return r;
166
+ const s = await g(e, n);
167
+ return s ? E(s, r) ?? r : r;
168
+ };
169
+ }
170
+ const C = new b("vizelEmbedPaste");
171
+ function k(t) {
172
+ const e = document.createElement("div");
173
+ e.className = "vizel-embed-loading", e.textContent = "Loading...", t.appendChild(e);
174
+ }
175
+ function z(t, e) {
176
+ t.innerHTML = e;
177
+ }
178
+ function N(t, e) {
179
+ const n = document.createElement("a");
180
+ if (n.href = e.url, n.target = "_blank", n.rel = "noopener noreferrer", n.className = "vizel-embed-card", e.image) {
181
+ const a = document.createElement("img");
182
+ a.src = e.image, a.alt = e.title ?? "", a.className = "vizel-embed-card-image", n.appendChild(a);
183
+ }
184
+ const r = document.createElement("div");
185
+ if (r.className = "vizel-embed-card-content", e.title) {
186
+ const a = document.createElement("div");
187
+ a.className = "vizel-embed-card-title", a.textContent = e.title, r.appendChild(a);
188
+ }
189
+ if (e.description) {
190
+ const a = document.createElement("div");
191
+ a.className = "vizel-embed-card-description", a.textContent = e.description, r.appendChild(a);
192
+ }
193
+ const s = document.createElement("div");
194
+ if (s.className = "vizel-embed-card-meta", e.favicon) {
195
+ const a = document.createElement("img");
196
+ a.src = e.favicon, a.alt = "", a.className = "vizel-embed-card-favicon", s.appendChild(a);
197
+ }
198
+ if (e.siteName) {
199
+ const a = document.createElement("span");
200
+ a.textContent = e.siteName, s.appendChild(a);
101
201
  }
202
+ s.hasChildNodes() && r.appendChild(s), n.appendChild(r), t.appendChild(n);
102
203
  }
103
- const N = G.create({
104
- name: "diagram",
105
- group: "block",
204
+ function D(t, e, n) {
205
+ const r = document.createElement("a");
206
+ r.href = e, r.target = "_blank", r.rel = "noopener noreferrer", r.className = "vizel-embed-link", r.textContent = n ?? e, t.appendChild(r);
207
+ }
208
+ const x = w.create({
209
+ name: "embed",
210
+ group() {
211
+ return this.options.inline ? "inline" : "block";
212
+ },
213
+ inline() {
214
+ return this.options.inline ?? !1;
215
+ },
106
216
  atom: !0,
107
- selectable: !0,
108
217
  draggable: !0,
109
- // Higher priority than codeBlock to ensure diagram code blocks are parsed first
110
- priority: 200,
111
218
  addOptions() {
112
219
  return {
113
- mermaidConfig: {},
114
- graphvizEngine: "dot",
115
- defaultType: "mermaid",
116
- defaultCode: _,
117
- defaultGraphvizCode: F
220
+ fetchEmbedData: y(),
221
+ providers: u,
222
+ HTMLAttributes: {
223
+ class: "vizel-embed"
224
+ },
225
+ pasteHandler: !0,
226
+ inline: !1
118
227
  };
119
228
  },
120
229
  addAttributes() {
121
230
  return {
122
- code: {
123
- default: "",
124
- parseHTML: (e) => e.getAttribute("data-code") || "",
125
- renderHTML: (e) => ({
126
- "data-code": e.code
127
- })
231
+ url: {
232
+ default: null
128
233
  },
129
234
  type: {
130
- default: "mermaid",
131
- parseHTML: (e) => e.getAttribute("data-diagram-type") || "mermaid",
132
- renderHTML: (e) => ({
133
- "data-diagram-type": e.type
134
- })
235
+ default: "link"
236
+ },
237
+ provider: {
238
+ default: null
239
+ },
240
+ html: {
241
+ default: null
242
+ },
243
+ width: {
244
+ default: null
245
+ },
246
+ height: {
247
+ default: null
248
+ },
249
+ title: {
250
+ default: null
251
+ },
252
+ description: {
253
+ default: null
254
+ },
255
+ image: {
256
+ default: null
257
+ },
258
+ siteName: {
259
+ default: null
260
+ },
261
+ favicon: {
262
+ default: null
263
+ },
264
+ loading: {
265
+ default: !1
135
266
  }
136
267
  };
137
268
  },
138
269
  parseHTML() {
139
270
  return [
140
271
  {
141
- tag: 'div[data-type="diagram"]'
272
+ tag: 'div[data-vizel-embed="true"]'
142
273
  }
143
274
  ];
144
275
  },
145
- renderHTML({ HTMLAttributes: e }) {
146
- return [
276
+ renderHTML({ HTMLAttributes: t }) {
277
+ const e = f(this.options.HTMLAttributes ?? {}, t, {
278
+ "data-vizel-embed": "true",
279
+ "data-embed-type": t.type,
280
+ "data-embed-provider": t.provider
281
+ });
282
+ return t.type === "oembed" && t.html ? ["div", e, ["div", { class: "vizel-embed-content" }]] : t.type === "ogp" ? [
147
283
  "div",
148
- S(e, {
149
- "data-type": "diagram",
150
- "data-vizel-diagram": "",
151
- class: "vizel-diagram"
152
- })
153
- ];
154
- },
155
- addNodeView() {
156
- return ({ node: e, getPos: a, editor: i }) => {
157
- P(this.options.mermaidConfig);
158
- const r = document.createElement("div");
159
- r.classList.add("vizel-diagram"), r.setAttribute("data-type", "diagram"), r.setAttribute("data-vizel-diagram", ""), r.setAttribute("contenteditable", "false");
160
- const m = document.createElement("div");
161
- m.classList.add("vizel-diagram-type"), m.textContent = x(e.attrs.type), r.appendChild(m);
162
- const l = document.createElement("div");
163
- l.classList.add("vizel-diagram-render"), r.appendChild(l);
164
- const o = document.createElement("div");
165
- o.classList.add("vizel-diagram-edit-container"), o.style.display = "none";
166
- const n = document.createElement("textarea");
167
- n.classList.add("vizel-diagram-textarea"), n.value = e.attrs.code, n.placeholder = "Enter diagram code...", n.spellcheck = !1, o.appendChild(n);
168
- const f = document.createElement("div");
169
- f.classList.add("vizel-diagram-preview"), o.appendChild(f);
170
- const z = document.createElement("div");
171
- z.classList.add("vizel-diagram-error"), z.style.display = "none", o.appendChild(z), r.appendChild(o);
172
- let u = !1, s = e.attrs.code, c = e.attrs.type;
173
- const y = async (t, d, g) => {
174
- if (!t.trim()) {
175
- g.innerHTML = '<div class="vizel-diagram-placeholder">Click to add diagram code</div>';
176
- return;
177
- }
178
- let v;
179
- d === "graphviz" ? v = await K(t, this.options.graphvizEngine) : v = await V(t), v.error ? g.innerHTML = `<div class="vizel-diagram-error-display">${v.error}</div>` : g.innerHTML = v.svg;
180
- }, T = () => {
181
- i.isEditable && (u = !0, r.classList.add("vizel-diagram-editing"), l.style.display = "none", m.style.display = "none", o.style.display = "", n.value = s, y(s, c, f), n.focus());
182
- }, E = () => {
183
- if (!u) return;
184
- u = !1, r.classList.remove("vizel-diagram-editing"), l.style.display = "", m.style.display = "", o.style.display = "none";
185
- const t = n.value.trim(), d = typeof a == "function" ? a() : null;
186
- d != null && (t === "" && s !== "" ? i.chain().focus().deleteRange({ from: d, to: d + e.nodeSize }).run() : t !== s && (s = t, i.chain().focus().updateAttributes("diagram", { code: t }).run()));
187
- }, M = (t) => {
188
- !u && t.target === r && (t.preventDefault(), t.stopPropagation(), T());
189
- }, D = (t) => {
190
- t.preventDefault(), t.stopPropagation(), T();
191
- }, w = (t) => {
192
- const d = t.relatedTarget;
193
- d instanceof HTMLElement && o.contains(d) || E();
194
- }, b = (t) => {
195
- t.key === "Escape" && (t.preventDefault(), n.value = s, E()), t.key === "Enter" && (t.ctrlKey || t.metaKey) && (t.preventDefault(), E());
196
- };
197
- let p = null;
198
- const k = () => {
199
- p && clearTimeout(p), p = setTimeout(() => {
200
- y(n.value, c, f);
201
- }, 300);
202
- };
203
- return r.addEventListener("click", M), l.addEventListener("click", D), n.addEventListener("blur", w), n.addEventListener("keydown", b), n.addEventListener("input", k), y(s, c, l), {
204
- dom: r,
205
- update(t) {
206
- if (t.type.name !== "diagram")
207
- return !1;
208
- const d = t.attrs.type !== c, g = t.attrs.code !== s;
209
- return d && (c = t.attrs.type, m.textContent = x(c)), !u && (g || d) && (s = t.attrs.code, y(s, c, l)), !0;
210
- },
211
- selectNode() {
212
- r.classList.add("vizel-diagram-selected");
284
+ e,
285
+ [
286
+ "a",
287
+ {
288
+ href: t.url,
289
+ target: "_blank",
290
+ rel: "noopener noreferrer",
291
+ class: "vizel-embed-card"
213
292
  },
214
- deselectNode() {
215
- r.classList.remove("vizel-diagram-selected");
293
+ t.title || t.url
294
+ ]
295
+ ] : [
296
+ "div",
297
+ e,
298
+ [
299
+ "a",
300
+ {
301
+ href: t.url,
302
+ target: "_blank",
303
+ rel: "noopener noreferrer",
304
+ class: "vizel-embed-link"
216
305
  },
217
- destroy() {
218
- p && clearTimeout(p), r.removeEventListener("click", M), l.removeEventListener("click", D), n.removeEventListener("blur", w), n.removeEventListener("keydown", b), n.removeEventListener("input", k);
219
- }
220
- };
221
- };
306
+ t.title || t.url
307
+ ]
308
+ ];
222
309
  },
223
310
  addCommands() {
224
311
  return {
225
- insertDiagram: ({ code: e, type: a = "mermaid" }) => ({ commands: i }) => {
226
- const r = a === "graphviz" ? this.options.defaultGraphvizCode : this.options.defaultCode;
227
- return i.insertContent({
312
+ setEmbed: ({ url: t }) => ({ commands: e, editor: n }) => {
313
+ if (!h(t))
314
+ return !1;
315
+ const r = c(t, this.options.providers), s = {
316
+ url: t,
317
+ type: "link",
318
+ loading: !0
319
+ };
320
+ r && (s.provider = r.name);
321
+ const a = e.insertContent({
228
322
  type: this.name,
229
- attrs: {
230
- code: e || r,
231
- type: a
232
- }
323
+ attrs: s
233
324
  });
325
+ return this.options.fetchEmbedData && this.options.fetchEmbedData(t).then((o) => {
326
+ n.state.doc.descendants((i, p) => i.type.name === this.name && i.attrs.url === t && i.attrs.loading ? (n.chain().focus().command(({ tr: l }) => (l.setNodeMarkup(p, void 0, {
327
+ ...i.attrs,
328
+ ...o,
329
+ loading: !1
330
+ }), !0)).run(), !1) : !0);
331
+ }).catch((o) => {
332
+ console.error("Failed to fetch embed data:", o), n.state.doc.descendants((i, p) => i.type.name === this.name && i.attrs.url === t && i.attrs.loading ? (n.chain().focus().command(({ tr: l }) => (l.setNodeMarkup(p, void 0, {
333
+ ...i.attrs,
334
+ type: "link",
335
+ loading: !1
336
+ }), !0)).run(), !1) : !0);
337
+ }), a;
338
+ },
339
+ updateEmbed: (t) => ({ state: e, tr: n }) => {
340
+ const { selection: r } = e, s = e.doc.nodeAt(r.from);
341
+ return s?.type.name !== this.name ? !1 : (n.setNodeMarkup(r.from, void 0, {
342
+ ...s.attrs,
343
+ ...t
344
+ }), !0);
234
345
  }
235
346
  };
236
347
  },
237
- addKeyboardShortcuts() {
238
- return {
239
- Backspace: () => {
240
- const { selection: e } = this.editor.state, { $anchor: a } = e;
241
- return a.node().type.name === "diagram" ? this.editor.commands.deleteSelection() : !1;
242
- }
243
- };
244
- },
245
- // Markdown support (GitHub compatible)
246
- // Single tokenizer handles mermaid, dot, and graphviz code blocks
247
- markdownTokenizer: O,
248
- parseMarkdown(e) {
249
- return {
250
- type: "diagram",
251
- attrs: {
252
- code: e.code || "",
253
- type: e.diagramType || "mermaid"
254
- }
348
+ addNodeView() {
349
+ return ({ node: t, HTMLAttributes: e }) => {
350
+ const n = document.createElement("div"), r = document.createElement("div");
351
+ r.className = "vizel-embed-content";
352
+ const s = f(this.options.HTMLAttributes ?? {}, e, {
353
+ "data-vizel-embed": "true",
354
+ "data-embed-type": t.attrs.type,
355
+ "data-embed-provider": t.attrs.provider,
356
+ contenteditable: "false",
357
+ draggable: "true"
358
+ });
359
+ for (const [o, i] of Object.entries(s))
360
+ i != null && n.setAttribute(o, String(i));
361
+ n.appendChild(r);
362
+ const a = () => {
363
+ if (r.innerHTML = "", t.attrs.loading) {
364
+ k(r);
365
+ return;
366
+ }
367
+ if (t.attrs.type === "oembed" && t.attrs.html) {
368
+ z(r, t.attrs.html);
369
+ return;
370
+ }
371
+ if (t.attrs.type === "ogp") {
372
+ N(r, {
373
+ url: t.attrs.url,
374
+ image: t.attrs.image,
375
+ title: t.attrs.title,
376
+ description: t.attrs.description,
377
+ favicon: t.attrs.favicon,
378
+ siteName: t.attrs.siteName
379
+ });
380
+ return;
381
+ }
382
+ D(r, t.attrs.url, t.attrs.title);
383
+ };
384
+ return a(), {
385
+ dom: n,
386
+ contentDOM: null,
387
+ // atom node, no editable content
388
+ update(o) {
389
+ return o.type.name !== t.type.name ? !1 : (t = o, n.setAttribute("data-embed-type", t.attrs.type), n.setAttribute("data-embed-provider", t.attrs.provider ?? ""), a(), !0);
390
+ }
391
+ };
255
392
  };
256
393
  },
257
- renderMarkdown(e) {
258
- const a = e.attrs?.code || "", i = e.attrs?.type || "mermaid";
259
- return i === "mermaid" ? `\`\`\`mermaid
260
- ${a}
261
- \`\`\`` : i === "graphviz" ? `\`\`\`dot
262
- ${a}
263
- \`\`\`` : `\`\`\`${i}
264
- ${a}
265
- \`\`\``;
394
+ addProseMirrorPlugins() {
395
+ if (!this.options.pasteHandler)
396
+ return [];
397
+ const t = this;
398
+ return [
399
+ new v({
400
+ key: C,
401
+ props: {
402
+ handlePaste(e, n) {
403
+ const r = n.clipboardData?.getData("text/plain");
404
+ if (!r) return !1;
405
+ const s = r.trim();
406
+ if (!h(s)) return !1;
407
+ const a = c(s, t.options.providers);
408
+ if (!a) return !1;
409
+ n.preventDefault();
410
+ const { state: o } = e, { selection: i } = o;
411
+ if (!i.empty)
412
+ return !1;
413
+ const p = o.schema.nodes[t.name];
414
+ return p ? (e.dispatch(
415
+ o.tr.replaceSelectionWith(
416
+ p.create({
417
+ url: s,
418
+ type: "link",
419
+ provider: a.name,
420
+ loading: !0
421
+ })
422
+ )
423
+ ), t.options.fetchEmbedData && t.options.fetchEmbedData(s).then((l) => {
424
+ e.state.doc.descendants((d, m) => d.type.name === t.name && d.attrs.url === s && d.attrs.loading ? (e.dispatch(
425
+ e.state.tr.setNodeMarkup(m, void 0, {
426
+ ...d.attrs,
427
+ ...l,
428
+ loading: !1
429
+ })
430
+ ), !1) : !0);
431
+ }).catch((l) => {
432
+ console.error("Failed to fetch embed data:", l), e.state.doc.descendants((d, m) => d.type.name === t.name && d.attrs.url === s && d.attrs.loading ? (e.dispatch(
433
+ e.state.tr.setNodeMarkup(m, void 0, {
434
+ ...d.attrs,
435
+ type: "link",
436
+ loading: !1
437
+ })
438
+ ), !1) : !0);
439
+ }), !0) : !1;
440
+ }
441
+ }
442
+ })
443
+ ];
266
444
  }
267
445
  });
268
- function j(e = {}) {
269
- return N.configure(e);
446
+ function O(t = {}) {
447
+ return x.configure(t);
270
448
  }
271
449
  export {
272
- N as VizelDiagram,
273
- j as createVizelDiagramExtension,
274
- Q as mermaid
450
+ x as VizelEmbed,
451
+ y as createVizelDefaultFetchEmbedData,
452
+ O as createVizelEmbedExtension,
453
+ c as detectVizelEmbedProvider,
454
+ u as vizelDefaultEmbedProviders,
455
+ C as vizelEmbedPastePluginKey
275
456
  };