@vizel/core 0.0.1-alpha.5 → 1.0.0

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 (75) hide show
  1. package/dist/components.css +1 -1
  2. package/dist/components.css.map +1 -1
  3. package/dist/index.d.ts +230 -15
  4. package/dist/index.js +78 -75
  5. package/dist/index10.js +1 -1
  6. package/dist/index11.js +4 -4
  7. package/dist/index14.js +1 -1
  8. package/dist/index15.js +134 -127
  9. package/dist/index17.js +2 -2
  10. package/dist/index18.js +1 -1
  11. package/dist/index19.js +86 -86
  12. package/dist/index20.js +2 -2
  13. package/dist/index21.js +2 -2
  14. package/dist/index22.js +16 -13
  15. package/dist/index24.js +164 -11
  16. package/dist/index25.js +12 -53
  17. package/dist/index26.js +49 -136
  18. package/dist/index27.js +132 -59
  19. package/dist/index28.js +66 -32
  20. package/dist/index29.js +35 -21
  21. package/dist/index3.js +91 -90
  22. package/dist/index30.js +23 -9
  23. package/dist/index31.js +9 -147
  24. package/dist/index32.js +138 -256
  25. package/dist/index33.js +258 -85
  26. package/dist/index34.js +84 -55
  27. package/dist/index35.js +64 -4
  28. package/dist/index36.js +4 -123
  29. package/dist/index37.js +111 -315
  30. package/dist/index38.js +321 -481
  31. package/dist/index39.js +12 -47
  32. package/dist/index4.js +1 -1
  33. package/dist/index40.js +463 -655
  34. package/dist/index41.js +48 -4
  35. package/dist/index42.js +694 -4
  36. package/dist/index43.js +4 -238
  37. package/dist/index44.js +4 -82
  38. package/dist/index45.js +237 -16
  39. package/dist/index46.js +81 -57
  40. package/dist/index47.js +17 -15
  41. package/dist/index48.js +57 -285
  42. package/dist/index49.js +15 -202
  43. package/dist/index5.js +78 -68
  44. package/dist/index50.js +281 -1497
  45. package/dist/index51.js +202 -5
  46. package/dist/index52.js +1408 -1467
  47. package/dist/index53.js +5 -723
  48. package/dist/index54.js +1109 -81
  49. package/dist/index55.js +703 -226
  50. package/dist/index56.js +84 -3
  51. package/dist/index57.js +219 -1205
  52. package/dist/index58.js +3 -734
  53. package/dist/index59.js +1232 -21
  54. package/dist/index6.js +1 -1
  55. package/dist/index60.js +734 -10
  56. package/dist/index61.js +21 -7
  57. package/dist/index62.js +10 -8
  58. package/dist/index63.js +6 -13
  59. package/dist/index64.js +7 -18
  60. package/dist/index65.js +12 -23
  61. package/dist/index66.js +17 -53
  62. package/dist/index67.js +23 -1059
  63. package/dist/index68.js +54 -90
  64. package/dist/index69.js +1061 -98
  65. package/dist/index7.js +108 -96
  66. package/dist/index70.js +98 -4
  67. package/dist/index71.js +93 -0
  68. package/dist/index72.js +6 -0
  69. package/dist/index8.js +1 -1
  70. package/dist/index9.js +75 -65
  71. package/dist/mathematics.css +1 -0
  72. package/dist/mathematics.css.map +1 -0
  73. package/dist/styles.css +1 -1
  74. package/dist/styles.css.map +1 -1
  75. package/package.json +90 -52
package/dist/index32.js CHANGED
@@ -1,268 +1,150 @@
1
- import l from "fuse.js";
2
- const h = [
3
- // Text group
4
- {
5
- title: "Heading 1",
6
- description: "Large section heading",
7
- icon: "heading1",
8
- group: "Text",
9
- keywords: ["h1", "title", "header", "big"],
10
- shortcut: "⌘⌥1",
11
- command: ({ editor: e, range: t }) => {
12
- e.chain().focus().deleteRange(t).setNode("heading", { level: 1 }).run();
13
- }
14
- },
15
- {
16
- title: "Heading 2",
17
- description: "Medium section heading",
18
- icon: "heading2",
19
- group: "Text",
20
- keywords: ["h2", "subtitle", "header"],
21
- shortcut: "⌘⌥2",
22
- command: ({ editor: e, range: t }) => {
23
- e.chain().focus().deleteRange(t).setNode("heading", { level: 2 }).run();
24
- }
25
- },
26
- {
27
- title: "Heading 3",
28
- description: "Small section heading",
29
- icon: "heading3",
30
- group: "Text",
31
- keywords: ["h3", "header", "section"],
32
- shortcut: "⌘⌥3",
33
- command: ({ editor: e, range: t }) => {
34
- e.chain().focus().deleteRange(t).setNode("heading", { level: 3 }).run();
35
- }
36
- },
37
- // Lists group
38
- {
39
- title: "Bullet List",
40
- description: "Create a simple bullet list",
41
- icon: "bulletList",
42
- group: "Lists",
43
- keywords: ["ul", "unordered", "bullets", "points"],
44
- shortcut: "⌘⇧8",
45
- command: ({ editor: e, range: t }) => {
46
- e.chain().focus().deleteRange(t).toggleBulletList().run();
47
- }
48
- },
49
- {
50
- title: "Numbered List",
51
- description: "Create a numbered list",
52
- icon: "orderedList",
53
- group: "Lists",
54
- keywords: ["ol", "ordered", "numbers", "steps"],
55
- shortcut: "⌘⇧7",
56
- command: ({ editor: e, range: t }) => {
57
- e.chain().focus().deleteRange(t).toggleOrderedList().run();
58
- }
59
- },
60
- {
61
- title: "Task List",
62
- description: "Create a task list with checkboxes",
63
- icon: "taskList",
64
- group: "Lists",
65
- keywords: ["todo", "checkbox", "checklist", "tasks"],
66
- command: ({ editor: e, range: t }) => {
67
- e.chain().focus().deleteRange(t).toggleTaskList().run();
68
- }
69
- },
70
- // Blocks group
71
- {
72
- title: "Quote",
73
- description: "Capture a quote",
74
- icon: "blockquote",
75
- group: "Blocks",
76
- keywords: ["blockquote", "citation", "cite"],
77
- shortcut: "⌘⇧B",
78
- command: ({ editor: e, range: t }) => {
79
- e.chain().focus().deleteRange(t).toggleBlockquote().run();
80
- }
81
- },
82
- {
83
- title: "Divider",
84
- description: "Insert a horizontal divider",
85
- icon: "horizontalRule",
86
- group: "Blocks",
87
- keywords: ["hr", "horizontal", "line", "separator", "break"],
88
- command: ({ editor: e, range: t }) => {
89
- e.chain().focus().deleteRange(t).setHorizontalRule().run();
90
- }
91
- },
92
- {
93
- title: "Details",
94
- description: "Collapsible content block",
95
- icon: "details",
96
- group: "Blocks",
97
- keywords: ["accordion", "toggle", "collapse", "expand", "summary", "details"],
98
- command: ({ editor: e, range: t }) => {
99
- e.can().setDetails?.() && e.chain().focus().deleteRange(t).setDetails().run();
100
- }
101
- },
102
- {
103
- title: "Code Block",
104
- description: "Insert a code snippet",
105
- icon: "codeBlock",
106
- group: "Blocks",
107
- keywords: ["pre", "code", "programming", "syntax", "snippet"],
108
- shortcut: "⌘⌥C",
109
- command: ({ editor: e, range: t }) => {
110
- e.chain().focus().deleteRange(t).toggleCodeBlock().run();
111
- }
112
- },
113
- {
114
- title: "Table",
115
- description: "Insert a table",
116
- icon: "table",
117
- group: "Blocks",
118
- keywords: ["grid", "spreadsheet", "columns", "rows"],
119
- command: ({ editor: e, range: t }) => {
120
- e.chain().focus().deleteRange(t).insertTable({ rows: 3, cols: 3, withHeaderRow: !0 }).run();
121
- }
122
- },
123
- // Media group
124
- {
125
- title: "Image",
126
- description: "Insert an image from URL",
127
- icon: "image",
128
- group: "Media",
129
- keywords: ["picture", "photo", "img", "url"],
130
- command: ({ editor: e, range: t }) => {
131
- const o = window.prompt("Enter image URL:");
132
- o && e.chain().focus().deleteRange(t).setImage({ src: o }).run();
133
- }
134
- },
135
- {
136
- title: "Upload Image",
137
- description: "Upload an image from your device",
138
- icon: "imageUpload",
139
- group: "Media",
140
- keywords: ["picture", "photo", "upload", "file"],
141
- command: ({ editor: e, range: t }) => {
142
- try {
143
- e.chain().focus().deleteRange(t).run();
144
- } catch {
1
+ import { PluginKey as S, Plugin as A } from "./index40.js";
2
+ import { DecorationSet as E, Decoration as M } from "./index52.js";
3
+ import { VIZEL_DEFAULT_IMAGE_MAX_FILE_SIZE as _, VIZEL_DEFAULT_FILE_MIME_TYPES as P } from "./index10.js";
4
+ const d = new S("vizel-image-upload"), U = (e) => typeof e == "object" && e !== null && "type" in e && (e.type === "add" || e.type === "remove");
5
+ function T(e) {
6
+ const { placeholderClass: o = "vizel-image-placeholder", imageClass: r = "vizel-image-uploading" } = e;
7
+ return new A({
8
+ key: d,
9
+ state: {
10
+ init() {
11
+ return E.empty;
12
+ },
13
+ apply(t, i) {
14
+ let a = i.map(t.mapping, t.doc);
15
+ const s = t.getMeta(d), n = U(s) ? s : void 0;
16
+ if (n?.type === "add") {
17
+ const { id: l, pos: g, previewSrc: p } = n, c = document.createElement("div");
18
+ c.setAttribute("class", o);
19
+ const u = document.createElement("img");
20
+ u.setAttribute("class", r), u.src = p, c.appendChild(u);
21
+ const m = document.createElement("div");
22
+ m.setAttribute("class", "vizel-image-spinner"), c.appendChild(m);
23
+ const f = M.widget(g, c, { id: l });
24
+ a = a.add(t.doc, [f]);
25
+ } else n?.type === "remove" && (a = a.remove(
26
+ a.find(void 0, void 0, (l) => l.id === n.id)
27
+ ));
28
+ return a;
145
29
  }
146
- const o = document.createElement("input");
147
- o.type = "file", o.accept = "image/*", o.onchange = () => {
148
- const i = o.files?.[0];
149
- if (i) {
150
- const n = new CustomEvent("vizel:upload-image", {
151
- detail: { file: i, editor: e }
152
- });
153
- document.dispatchEvent(n);
154
- }
155
- }, o.click();
156
- }
157
- },
158
- {
159
- title: "Embed",
160
- description: "Embed a URL (YouTube, Twitter, etc.)",
161
- icon: "embed",
162
- group: "Media",
163
- keywords: ["link", "url", "youtube", "video", "twitter", "embed", "iframe", "oembed"],
164
- command: ({ editor: e, range: t }) => {
165
- if (!(typeof e.commands.setEmbed == "function")) {
166
- const n = window.prompt("Enter URL:");
167
- n && e.chain().focus().deleteRange(t).setLink({ href: n }).run();
168
- return;
30
+ },
31
+ props: {
32
+ decorations(t) {
33
+ return d.getState(t) ?? E.empty;
169
34
  }
170
- const i = window.prompt("Enter URL to embed:");
171
- i && e.chain().focus().deleteRange(t).setEmbed({ url: i }).run();
172
- }
173
- },
174
- // Advanced group
175
- {
176
- title: "Math Equation",
177
- description: "Insert a mathematical expression",
178
- icon: "mathBlock",
179
- group: "Advanced",
180
- keywords: ["latex", "formula", "equation", "katex", "math"],
181
- command: ({ editor: e, range: t }) => {
182
- e.can().insertMathBlock?.({ latex: "" }) && e.chain().focus().deleteRange(t).insertMathBlock({ latex: "" }).run();
183
35
  }
184
- },
185
- {
186
- title: "Inline Math",
187
- description: "Insert an inline math expression",
188
- icon: "mathInline",
189
- group: "Advanced",
190
- keywords: ["latex", "formula", "inline", "katex", "math"],
191
- command: ({ editor: e, range: t }) => {
192
- e.can().insertMath?.({ latex: "" }) && e.chain().focus().deleteRange(t).insertMath({ latex: "" }).run();
193
- }
194
- },
195
- {
196
- title: "Mermaid Diagram",
197
- description: "Insert a Mermaid diagram",
198
- icon: "mermaid",
199
- group: "Advanced",
200
- keywords: ["diagram", "chart", "flowchart", "mermaid", "sequence", "graph", "uml"],
201
- command: ({ editor: e, range: t }) => {
202
- e.can().insertDiagram?.({ code: "" }) && e.chain().focus().deleteRange(t).insertDiagram({ code: "", type: "mermaid" }).run();
203
- }
204
- },
205
- {
206
- title: "GraphViz Diagram",
207
- description: "Insert a GraphViz (DOT) diagram",
208
- icon: "graphviz",
209
- group: "Advanced",
210
- keywords: ["diagram", "graphviz", "dot", "graph", "network", "nodes", "edges"],
211
- command: ({ editor: e, range: t }) => {
212
- e.can().insertDiagram?.({ code: "" }) && e.chain().focus().deleteRange(t).insertDiagram({ code: "", type: "graphviz" }).run();
213
- }
214
- }
215
- ], u = ["Text", "Lists", "Blocks", "Media", "Advanced"], m = {
216
- keys: [
217
- { name: "title", weight: 0.4 },
218
- { name: "description", weight: 0.2 },
219
- { name: "keywords", weight: 0.4 }
220
- ],
221
- threshold: 0.4,
222
- includeScore: !0,
223
- includeMatches: !0,
224
- minMatchCharLength: 1
225
- }, s = /* @__PURE__ */ new WeakMap();
226
- function c(e) {
227
- let t = s.get(e);
228
- return t || (t = new l(e, m), s.set(e, t)), t;
36
+ });
229
37
  }
230
- function p(e, t) {
231
- return t.trim() ? c(e).search(t).map((n) => n.item) : e;
38
+ function F(e, o) {
39
+ const r = d.getState(e);
40
+ if (!r)
41
+ return null;
42
+ const t = r.find(void 0, void 0, (i) => i.id === o);
43
+ return t.length > 0 ? t[0]?.from ?? null : null;
232
44
  }
233
- function f(e, t) {
234
- return t.trim() ? c(e).search(t).map((n) => {
235
- const r = n.matches?.find((d) => d.key === "title")?.indices;
45
+ function x(e, o) {
46
+ const r = o.maxFileSize ?? _, t = o.allowedTypes ?? P;
47
+ if (!t.includes(e.type))
236
48
  return {
237
- item: n.item,
238
- score: n.score ?? 0,
239
- titleMatches: r
49
+ type: "invalid_type",
50
+ message: `File type "${e.type}" is not allowed. Allowed types: ${t.join(", ")}`,
51
+ file: e
52
+ };
53
+ if (e.size > r) {
54
+ const i = (r / 1048576).toFixed(1);
55
+ return {
56
+ type: "file_too_large",
57
+ message: `File size (${(e.size / (1024 * 1024)).toFixed(1)}MB) exceeds maximum allowed size (${i}MB)`,
58
+ file: e
240
59
  };
241
- }) : e.map((n) => ({ item: n, score: 0 }));
242
- }
243
- function k(e, t = u) {
244
- const o = /* @__PURE__ */ new Map();
245
- for (const n of e) {
246
- const a = n.group ?? "Other", r = o.get(a) ?? [];
247
- r.push(n), o.set(a, r);
248
- }
249
- const i = [];
250
- for (const n of t) {
251
- const a = o.get(n);
252
- a && a.length > 0 && (i.push({ name: n, items: a }), o.delete(n));
253
60
  }
254
- for (const [n, a] of o)
255
- a.length > 0 && i.push({ name: n, items: a });
256
- return i;
61
+ return null;
62
+ }
63
+ function v(e) {
64
+ const { onUpload: o, maxFileSize: r, allowedTypes: t, onValidationError: i, onUploadError: a } = e;
65
+ return (s, n, l) => {
66
+ const g = x(s, {
67
+ ...r !== void 0 && { maxFileSize: r },
68
+ ...t !== void 0 && { allowedTypes: t }
69
+ });
70
+ if (g) {
71
+ i?.(g);
72
+ return;
73
+ }
74
+ const p = {}, c = new FileReader();
75
+ c.readAsDataURL(s), c.onload = () => {
76
+ if (typeof c.result != "string") return;
77
+ const u = c.result, m = n.state.tr;
78
+ m.selection.empty || m.deleteSelection(), m.setMeta(d, {
79
+ type: "add",
80
+ id: p,
81
+ pos: l,
82
+ previewSrc: u
83
+ }), n.dispatch(m), o(s).then((f) => {
84
+ const y = F(n.state, p);
85
+ if (y === null)
86
+ return;
87
+ const { schema: h } = n.state, z = h.nodes.image?.create({ src: f });
88
+ if (!z) {
89
+ console.warn("Image node type not found in schema");
90
+ return;
91
+ }
92
+ const I = n.state.tr.replaceWith(y, y, z).setMeta(d, {
93
+ type: "remove",
94
+ id: p
95
+ });
96
+ n.dispatch(I);
97
+ }).catch((f) => {
98
+ if (a?.(f, s), F(n.state, p) !== null) {
99
+ const h = n.state.tr.setMeta(d, {
100
+ type: "remove",
101
+ id: p
102
+ });
103
+ n.dispatch(h);
104
+ }
105
+ });
106
+ };
107
+ };
108
+ }
109
+ function b(e, o, r) {
110
+ const t = o.clipboardData?.files;
111
+ if (!t || t.length === 0)
112
+ return !1;
113
+ const i = Array.from(t).filter((s) => s.type.startsWith("image/"));
114
+ if (i.length === 0)
115
+ return !1;
116
+ o.preventDefault();
117
+ const a = e.state.selection.from;
118
+ for (const s of i)
119
+ r(s, e, a);
120
+ return !0;
121
+ }
122
+ function B(e, o, r, t) {
123
+ if (r)
124
+ return !1;
125
+ const i = o.dataTransfer?.files;
126
+ if (!i || i.length === 0)
127
+ return !1;
128
+ const a = Array.from(i).filter((l) => l.type.startsWith("image/"));
129
+ if (a.length === 0)
130
+ return !1;
131
+ o.preventDefault();
132
+ const n = e.posAtCoords({
133
+ left: o.clientX,
134
+ top: o.clientY
135
+ })?.pos ?? e.state.selection.from;
136
+ for (const l of a)
137
+ t(l, e, n);
138
+ return !0;
257
139
  }
258
- function w(e) {
259
- return e.flatMap((t) => t.items);
140
+ function C() {
141
+ return d;
260
142
  }
261
143
  export {
262
- u as defaultGroupOrder,
263
- h as defaultSlashCommands,
264
- p as filterSlashCommands,
265
- w as flattenSlashCommandGroups,
266
- k as groupSlashCommands,
267
- f as searchSlashCommands
144
+ T as createVizelImageUploadPlugin,
145
+ v as createVizelImageUploader,
146
+ C as getVizelImageUploadPluginKey,
147
+ B as handleVizelImageDrop,
148
+ b as handleVizelImagePaste,
149
+ x as validateVizelImageFile
268
150
  };