@novaprose/core 0.1.0 → 0.3.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 (53) hide show
  1. package/dist/advlist-DEJUHLI6.js +107 -0
  2. package/dist/advlist-DEJUHLI6.js.map +1 -0
  3. package/dist/autolink-ZVHNOOS7.js +89 -0
  4. package/dist/autolink-ZVHNOOS7.js.map +1 -0
  5. package/dist/autoresize-WT4ONZKK.js +26 -0
  6. package/dist/autoresize-WT4ONZKK.js.map +1 -0
  7. package/dist/autosave-2KI5WGV5.js +99 -0
  8. package/dist/autosave-2KI5WGV5.js.map +1 -0
  9. package/dist/charmap-3LM5LZCC.js +197 -0
  10. package/dist/charmap-3LM5LZCC.js.map +1 -0
  11. package/dist/chunk-6RJENZXT.js +104 -0
  12. package/dist/chunk-6RJENZXT.js.map +1 -0
  13. package/dist/chunk-BGG3UVGZ.js +5044 -0
  14. package/dist/chunk-BGG3UVGZ.js.map +1 -0
  15. package/dist/{chunk-ZF2JR3JH.js → chunk-F6TSOU5U.js} +1 -1
  16. package/dist/chunk-F6TSOU5U.js.map +1 -0
  17. package/dist/chunk-GHEFKKRC.js +268 -0
  18. package/dist/chunk-GHEFKKRC.js.map +1 -0
  19. package/dist/chunk-HZRIBOPW.js +52 -0
  20. package/dist/chunk-HZRIBOPW.js.map +1 -0
  21. package/dist/{chunk-TKR3C5IJ.js → chunk-PHRON5PL.js} +300 -681
  22. package/dist/chunk-PHRON5PL.js.map +1 -0
  23. package/dist/chunk-YZPJQB3I.js +490 -0
  24. package/dist/chunk-YZPJQB3I.js.map +1 -0
  25. package/dist/chunk-Z3ELZ77W.js +102 -0
  26. package/dist/chunk-Z3ELZ77W.js.map +1 -0
  27. package/dist/comments-panel-FYJE3U64.js +464 -0
  28. package/dist/comments-panel-FYJE3U64.js.map +1 -0
  29. package/dist/directionality-MTLAIFIQ.js +70 -0
  30. package/dist/directionality-MTLAIFIQ.js.map +1 -0
  31. package/dist/emoticons-YVGVA76P.js +216 -0
  32. package/dist/emoticons-YVGVA76P.js.map +1 -0
  33. package/dist/index.cjs +7545 -3199
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +470 -14
  36. package/dist/index.d.ts +470 -14
  37. package/dist/index.js +853 -4052
  38. package/dist/index.js.map +1 -1
  39. package/dist/{insertdatetime-C4MAC5L7.js → insertdatetime-QYWZUYO4.js} +2 -2
  40. package/dist/nonbreaking-SIACL5V6.js +46 -0
  41. package/dist/nonbreaking-SIACL5V6.js.map +1 -0
  42. package/dist/{quickbars-XK4QCQ6F.js → quickbars-TYJG6WTF.js} +7 -5
  43. package/dist/quickbars-TYJG6WTF.js.map +1 -0
  44. package/dist/revisionhistory-ZCRBPP33.js +457 -0
  45. package/dist/revisionhistory-ZCRBPP33.js.map +1 -0
  46. package/dist/visualblocks-WB6NAEGB.js +43 -0
  47. package/dist/visualblocks-WB6NAEGB.js.map +1 -0
  48. package/package.json +5 -2
  49. package/src/style.css +645 -0
  50. package/dist/chunk-TKR3C5IJ.js.map +0 -1
  51. package/dist/chunk-ZF2JR3JH.js.map +0 -1
  52. package/dist/quickbars-XK4QCQ6F.js.map +0 -1
  53. /package/dist/{insertdatetime-C4MAC5L7.js.map → insertdatetime-QYWZUYO4.js.map} +0 -0
@@ -1,604 +1,22 @@
1
- // src/url.ts
2
- var SAFE_LINK_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]);
3
- var SAFE_IMAGE_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "blob:"]);
4
- var SAFE_DATA_IMAGE = /^data:image\/(png|jpe?g|gif|webp|avif|bmp);base64,/i;
5
- function protocolOf(url) {
6
- const cleaned = url.replace(/[\u0000- \u007f-\u009f]/g, "");
7
- const match = cleaned.match(/^([a-z][a-z0-9+.-]*):/i);
8
- return match ? `${match[1].toLowerCase()}:` : null;
9
- }
10
- function isSafeLinkUrl(url) {
11
- const protocol = protocolOf(url);
12
- return protocol === null || SAFE_LINK_PROTOCOLS.has(protocol);
13
- }
14
- function isSafeImageUrl(url) {
15
- if (SAFE_DATA_IMAGE.test(url.trim())) return true;
16
- const protocol = protocolOf(url);
17
- return protocol === null || SAFE_IMAGE_PROTOCOLS.has(protocol);
18
- }
19
-
20
- // src/schema.ts
21
- import { Schema } from "prosemirror-model";
22
- import { tableNodes } from "prosemirror-tables";
23
- var ALIGNMENTS = ["left", "center", "right", "justify"];
24
- var COLOR_RE = /^(#[0-9a-f]{3,8}|rgba?\(\s*[\d.]+%?\s*,\s*[\d.]+%?\s*,\s*[\d.]+%?\s*(,\s*[\d.]+%?\s*)?\)|[a-z]{3,20})$/i;
25
- var LENGTH_RE = /^\d{1,4}(\.\d{1,3})?(px|pt|em|rem|%)$/;
26
- var LINE_HEIGHT_RE = /^\d{1,2}(\.\d{1,3})?(px|em|%)?$/;
27
- var FONT_FAMILY_RE = /^[\w\s,'"-]{1,200}$/;
28
- function normalizeColor(value) {
29
- const v = value.trim().toLowerCase();
30
- const rgb = v.match(
31
- /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(1|1\.0+)\s*)?\)$/
32
- );
33
- if (rgb) {
34
- return "#" + rgb.slice(1, 4).map((n) => Math.min(255, Number(n)).toString(16).padStart(2, "0")).join("");
35
- }
36
- const short = v.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/);
37
- if (short) return `#${short[1]}${short[1]}${short[2]}${short[2]}${short[3]}${short[3]}`;
38
- return v;
39
- }
40
- var cssValue = {
41
- color: (v) => typeof v === "string" && COLOR_RE.test(v.trim()) && !/^(inherit|initial|unset|currentcolor)$/i.test(v.trim()) ? normalizeColor(v) : null,
42
- length: (v) => typeof v === "string" && LENGTH_RE.test(v.trim()) ? v.trim() : null,
43
- lineHeight: (v) => typeof v === "string" && LINE_HEIGHT_RE.test(v.trim()) && v.trim() !== "normal" ? v.trim() : null,
44
- fontFamily: (v) => typeof v === "string" && FONT_FAMILY_RE.test(v.trim()) ? v.trim() : null
45
- };
46
- function readBlockStyle(dom) {
47
- const align = dom.style.textAlign;
48
- return {
49
- align: ALIGNMENTS.includes(align) ? align : null,
50
- lineHeight: cssValue.lineHeight(dom.style.lineHeight)
51
- };
52
- }
53
- function blockStyleAttrs(attrs) {
54
- const parts = [];
55
- const align = attrs.align;
56
- if (align && ALIGNMENTS.includes(align))
57
- parts.push(`text-align: ${align};`);
58
- const lineHeight = cssValue.lineHeight(attrs.lineHeight);
59
- if (lineHeight) parts.push(`line-height: ${lineHeight};`);
60
- return parts.length ? { style: parts.join(" ") } : {};
61
- }
62
- var blockStyleSpec = { align: { default: null }, lineHeight: { default: null } };
63
- var IMAGE_ALIGN_STYLES = {
64
- left: "float: left; margin: 0 1em 1em 0;",
65
- right: "float: right; margin: 0 0 1em 1em;",
66
- center: "display: block; margin-left: auto; margin-right: auto;"
67
- };
68
- function readImageAlign(el) {
69
- const float = el.style.float || el.getAttribute("align");
70
- if (float === "left" || float === "right") return float;
71
- if (el.style.display === "block" && el.style.marginLeft === "auto" && el.style.marginRight === "auto") {
72
- return "center";
73
- }
74
- return null;
75
- }
76
- function imageSize(value) {
77
- if (value === null || value === void 0 || value === "") return null;
78
- const match = String(value).trim().match(/^(\d{1,5})(px)?$/);
79
- if (!match) return null;
80
- const n = Number(match[1]);
81
- return n >= 1 && n <= 1e4 ? n : null;
82
- }
83
- var MAX_SPAN = 100;
84
- function buildTableNodes() {
85
- const specs = tableNodes({
86
- tableGroup: "block",
87
- cellContent: "block+",
88
- cellAttributes: {
89
- background: {
90
- default: null,
91
- // Фон заранее перенесён в data-атрибут (parser.ts → preprocessDOM); style — запасной путь.
92
- getFromDOM: (dom) => cssValue.color(
93
- dom.getAttribute("data-nova-cell-bg") ?? dom.style.backgroundColor
94
- ),
95
- setDOMAttr: (value, attrs) => {
96
- const color = cssValue.color(value);
97
- if (color)
98
- attrs.style = `${attrs.style ?? ""}background-color: ${color};`;
99
- }
100
- }
101
- }
102
- });
103
- for (const name of ["table_cell", "table_header"]) {
104
- const spec = specs[name];
105
- const rule = spec.parseDOM[0];
106
- const getAttrs = rule.getAttrs;
107
- rule.getAttrs = (dom) => {
108
- const attrs = getAttrs(dom);
109
- if (!attrs) return attrs;
110
- const clamp = (n) => Math.min(MAX_SPAN, Math.max(1, Number.isFinite(n) ? Math.floor(n) : 1));
111
- return { ...attrs, colspan: clamp(attrs.colspan), rowspan: clamp(attrs.rowspan) };
112
- };
113
- const toDOM = spec.toDOM;
114
- spec.toDOM = (node) => {
115
- const out = toDOM(node);
116
- const widths = node.attrs.colwidth;
117
- if (widths?.every((w) => w > 0)) {
118
- const total = widths.reduce((a, b) => a + b, 0);
119
- const rest = out[1].style ? ` ${out[1].style}` : "";
120
- out[1] = { ...out[1], style: `width: ${total}px;${rest}` };
121
- }
122
- return out;
123
- };
124
- }
125
- return specs;
126
- }
127
- var nodes = {
128
- doc: { content: "block+" },
129
- paragraph: {
130
- group: "block",
131
- content: "inline*",
132
- attrs: { ...blockStyleSpec },
133
- parseDOM: [{ tag: "p", getAttrs: (dom) => readBlockStyle(dom) }],
134
- toDOM: (node) => ["p", blockStyleAttrs(node.attrs), 0]
135
- },
136
- heading: {
137
- group: "block",
138
- content: "inline*",
139
- defining: true,
140
- attrs: { level: { default: 1 }, ...blockStyleSpec },
141
- parseDOM: [1, 2, 3, 4, 5, 6].map((level) => ({
142
- tag: `h${level}`,
143
- getAttrs: (dom) => ({ level, ...readBlockStyle(dom) })
144
- })),
145
- toDOM: (node) => [`h${node.attrs.level}`, blockStyleAttrs(node.attrs), 0]
146
- },
147
- blockquote: {
148
- group: "block",
149
- content: "block+",
150
- defining: true,
151
- parseDOM: [{ tag: "blockquote" }],
152
- toDOM: () => ["blockquote", 0]
153
- },
154
- horizontal_rule: {
155
- group: "block",
156
- parseDOM: [{ tag: "hr" }],
157
- toDOM: () => ["hr"]
158
- },
159
- code_block: {
160
- group: "block",
161
- content: "text*",
162
- marks: "",
163
- code: true,
164
- defining: true,
165
- attrs: { language: { default: null } },
166
- parseDOM: [
167
- {
168
- tag: "pre",
169
- preserveWhitespace: "full",
170
- getAttrs: (dom) => {
171
- const code = dom.querySelector("code");
172
- const match = code?.className.match(/language-([\w-]+)/);
173
- return { language: match?.[1] ?? null };
174
- }
175
- }
176
- ],
177
- toDOM: (node) => [
178
- "pre",
179
- ["code", node.attrs.language ? { class: `language-${node.attrs.language}` } : {}, 0]
180
- ]
181
- },
182
- bullet_list: {
183
- group: "block",
184
- content: "list_item+",
185
- parseDOM: [{ tag: "ul" }],
186
- toDOM: () => ["ul", 0]
187
- },
188
- ordered_list: {
189
- group: "block",
190
- content: "list_item+",
191
- attrs: { start: { default: 1 } },
192
- parseDOM: [
193
- {
194
- tag: "ol",
195
- getAttrs: (dom) => {
196
- const start = dom.getAttribute("start");
197
- return { start: start ? Number(start) : 1 };
198
- }
199
- }
200
- ],
201
- toDOM: (node) => node.attrs.start === 1 ? ["ol", 0] : ["ol", { start: node.attrs.start }, 0]
202
- },
203
- list_item: {
204
- content: "paragraph block*",
205
- defining: true,
206
- parseDOM: [{ tag: "li" }],
207
- toDOM: () => ["li", 0]
208
- },
209
- text: { group: "inline" },
210
- image: {
211
- group: "inline",
212
- inline: true,
213
- draggable: true,
214
- attrs: {
215
- src: {},
216
- alt: { default: null },
217
- title: { default: null },
218
- width: { default: null },
219
- height: { default: null },
220
- align: { default: null }
221
- },
222
- parseDOM: [
223
- {
224
- tag: "img[src]",
225
- getAttrs: (dom) => {
226
- const el = dom;
227
- if (!isSafeImageUrl(el.getAttribute("src") ?? "")) return false;
228
- return {
229
- src: el.getAttribute("src"),
230
- alt: el.getAttribute("alt"),
231
- title: el.getAttribute("title"),
232
- width: imageSize(el.getAttribute("width") ?? el.style.width),
233
- height: imageSize(el.getAttribute("height") ?? el.style.height),
234
- align: readImageAlign(el)
235
- };
236
- }
237
- }
238
- ],
239
- toDOM: (node) => {
240
- const { alt, title } = node.attrs;
241
- const src = isSafeImageUrl(node.attrs.src) ? node.attrs.src : "";
242
- const width = imageSize(node.attrs.width);
243
- const height = imageSize(node.attrs.height);
244
- const style = IMAGE_ALIGN_STYLES[node.attrs.align];
245
- return [
246
- "img",
247
- {
248
- src,
249
- ...alt ? { alt } : {},
250
- ...title ? { title } : {},
251
- ...width ? { width: String(width) } : {},
252
- ...height ? { height: String(height) } : {},
253
- ...style ? { style } : {}
254
- }
255
- ];
256
- }
257
- },
258
- hard_break: {
259
- group: "inline",
260
- inline: true,
261
- selectable: false,
262
- parseDOM: [{ tag: "br" }],
263
- toDOM: () => ["br"]
264
- },
265
- ...buildTableNodes()
266
- };
267
- var marks = {
268
- link: {
269
- attrs: { href: {}, title: { default: null }, target: { default: null } },
270
- inclusive: false,
271
- parseDOM: [
272
- {
273
- tag: "a[href]",
274
- getAttrs: (dom) => {
275
- const el = dom;
276
- if (!isSafeLinkUrl(el.getAttribute("href") ?? "")) return false;
277
- return {
278
- href: el.getAttribute("href"),
279
- title: el.getAttribute("title"),
280
- target: el.getAttribute("target")
281
- };
282
- }
283
- }
284
- ],
285
- toDOM: (mark) => {
286
- const { title, target } = mark.attrs;
287
- const href = isSafeLinkUrl(mark.attrs.href) ? mark.attrs.href : "#";
288
- return [
289
- "a",
290
- {
291
- href,
292
- ...title ? { title } : {},
293
- ...target ? { target, rel: "noopener noreferrer" } : {}
294
- },
295
- 0
296
- ];
297
- }
298
- },
299
- bold: {
300
- parseDOM: [
301
- { tag: "strong" },
302
- // <b style="font-weight: normal"> встречается при вставке из Google Docs — это не жирный.
303
- {
304
- tag: "b",
305
- getAttrs: (dom) => dom.style.fontWeight !== "normal" && null
306
- },
307
- {
308
- style: "font-weight",
309
- getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null
310
- }
311
- ],
312
- toDOM: () => ["strong", 0]
313
- },
314
- italic: {
315
- parseDOM: [{ tag: "em" }, { tag: "i" }, { style: "font-style=italic" }],
316
- toDOM: () => ["em", 0]
317
- },
318
- underline: {
319
- parseDOM: [{ tag: "u" }, { style: "text-decoration=underline" }],
320
- toDOM: () => ["u", 0]
321
- },
322
- strike: {
323
- parseDOM: [
324
- { tag: "s" },
325
- { tag: "del" },
326
- { tag: "strike" },
327
- { style: "text-decoration=line-through" }
328
- ],
329
- toDOM: () => ["s", 0]
330
- },
331
- code: {
332
- parseDOM: [{ tag: "code" }],
333
- toDOM: () => ["code", 0]
334
- },
335
- subscript: {
336
- excludes: "superscript",
337
- parseDOM: [{ tag: "sub" }],
338
- toDOM: () => ["sub", 0]
339
- },
340
- superscript: {
341
- excludes: "subscript",
342
- parseDOM: [{ tag: "sup" }],
343
- toDOM: () => ["sup", 0]
344
- },
345
- // ---------- текстовые стили (PRD §4.2): <span style="…"> как у TinyMCE ----------
346
- color: {
347
- attrs: { value: {} },
348
- parseDOM: [
349
- { style: "color", getAttrs: (v) => styleAttr(cssValue.color(v)) },
350
- {
351
- tag: "font[color]",
352
- getAttrs: (dom) => styleAttr(cssValue.color(dom.getAttribute("color")))
353
- }
354
- ],
355
- toDOM: (mark) => styleSpan("color", cssValue.color(mark.attrs.value))
356
- },
357
- background: {
358
- attrs: { value: {} },
359
- parseDOM: [
360
- { style: "background-color", getAttrs: (v) => styleAttr(cssValue.color(v)) },
361
- { tag: "mark", getAttrs: () => ({ value: "yellow" }) }
362
- ],
363
- toDOM: (mark) => styleSpan("background-color", cssValue.color(mark.attrs.value))
364
- },
365
- font_family: {
366
- attrs: { value: {} },
367
- parseDOM: [{ style: "font-family", getAttrs: (v) => styleAttr(cssValue.fontFamily(v)) }],
368
- toDOM: (mark) => styleSpan("font-family", cssValue.fontFamily(mark.attrs.value))
369
- },
370
- font_size: {
371
- attrs: { value: {} },
372
- parseDOM: [{ style: "font-size", getAttrs: (v) => styleAttr(cssValue.length(v)) }],
373
- toDOM: (mark) => styleSpan("font-size", cssValue.length(mark.attrs.value))
374
- }
375
- };
376
- function styleAttr(value) {
377
- return value ? { value } : false;
378
- }
379
- function styleSpan(property, value) {
380
- return value ? ["span", { style: `${property}: ${value};` }, 0] : ["span", 0];
381
- }
382
- var schema = new Schema({ nodes, marks });
383
-
384
- // src/commands.ts
385
- import { lift, setBlockType, toggleMark, wrapIn } from "prosemirror-commands";
386
- import { redo, undo } from "prosemirror-history";
387
- import { liftListItem, sinkListItem, wrapInList } from "prosemirror-schema-list";
388
- var { nodes: nodes2, marks: marks2 } = schema;
389
- function setAlign(align) {
390
- return (state, dispatch) => {
391
- const { from, to } = state.selection;
392
- let tr = state.tr;
393
- let applicable = false;
394
- state.doc.nodesBetween(from, to, (node, pos) => {
395
- if (node.type === nodes2.paragraph || node.type === nodes2.heading) {
396
- applicable = true;
397
- tr = tr.setNodeMarkup(pos, void 0, { ...node.attrs, align });
398
- }
399
- });
400
- if (!applicable) return false;
401
- dispatch?.(tr);
402
- return true;
403
- };
404
- }
405
- var insertHorizontalRule = (state, dispatch) => {
406
- dispatch?.(state.tr.replaceSelectionWith(nodes2.horizontal_rule.create()).scrollIntoView());
407
- return true;
408
- };
409
- var unlink = (state, dispatch) => {
410
- const { from, to, empty, $from } = state.selection;
411
- if (empty) {
412
- const range = markRange(state, marks2.link, $from.pos);
413
- if (!range) return false;
414
- dispatch?.(state.tr.removeMark(range.from, range.to, marks2.link));
415
- return true;
416
- }
417
- if (!state.doc.rangeHasMark(from, to, marks2.link)) return false;
418
- dispatch?.(state.tr.removeMark(from, to, marks2.link));
419
- return true;
420
- };
421
- var clearFormatting = (state, dispatch) => {
422
- const { from, to, empty } = state.selection;
423
- if (empty) return false;
424
- if (dispatch) {
425
- let tr = state.tr;
426
- for (const mark of Object.values(marks2)) {
427
- if (mark !== marks2.link) tr = tr.removeMark(from, to, mark);
428
- }
429
- dispatch(tr);
430
- }
431
- return true;
432
- };
433
- function setBlockKeepAlign(type, attrs = {}) {
434
- const base = setBlockType(type, attrs);
435
- return (state, dispatch) => {
436
- if (!base(state)) return false;
437
- if (dispatch) {
438
- const tr = state.tr;
439
- for (const range of state.selection.ranges) {
440
- tr.setBlockType(range.$from.pos, range.$to.pos, type, (old) => ({
441
- ...attrs,
442
- ..."align" in type.spec.attrs && old.attrs.align ? { align: old.attrs.align } : {},
443
- ..."lineHeight" in type.spec.attrs && old.attrs.lineHeight ? { lineHeight: old.attrs.lineHeight } : {}
444
- }));
445
- }
446
- dispatch(tr.scrollIntoView());
447
- }
448
- return true;
449
- };
450
- }
451
- function heading(level) {
452
- return setBlockKeepAlign(nodes2.heading, { level });
453
- }
454
- var commands = {
455
- bold: toggleMark(marks2.bold),
456
- italic: toggleMark(marks2.italic),
457
- underline: toggleMark(marks2.underline),
458
- strike: toggleMark(marks2.strike),
459
- code: toggleMark(marks2.code),
460
- subscript: toggleMark(marks2.subscript),
461
- superscript: toggleMark(marks2.superscript),
462
- paragraph: setBlockKeepAlign(nodes2.paragraph),
463
- h1: heading(1),
464
- h2: heading(2),
465
- h3: heading(3),
466
- h4: heading(4),
467
- h5: heading(5),
468
- h6: heading(6),
469
- blockquote: (state, dispatch) => isNodeActive(state, nodes2.blockquote) ? lift(state, dispatch) : wrapIn(nodes2.blockquote)(state, dispatch),
470
- codeBlock: setBlockType(nodes2.code_block),
471
- bulletList: toggleList(nodes2.bullet_list),
472
- orderedList: toggleList(nodes2.ordered_list),
473
- indent: sinkListItem(nodes2.list_item),
474
- outdent: liftListItem(nodes2.list_item),
475
- alignLeft: setAlign(null),
476
- alignCenter: setAlign("center"),
477
- alignRight: setAlign("right"),
478
- alignJustify: setAlign("justify"),
479
- horizontalRule: insertHorizontalRule,
480
- unlink,
481
- clearFormatting,
482
- undo,
483
- redo
484
- };
485
- function toggleList(listType) {
486
- return (state, dispatch) => {
487
- if (isNodeActive(state, listType)) return liftListItem(nodes2.list_item)(state, dispatch);
488
- return wrapInList(listType)(state, dispatch);
489
- };
490
- }
491
- function setLink(href, attrs = {}) {
492
- return (state, dispatch) => {
493
- if (!isSafeLinkUrl(href)) return false;
494
- const { from, to, empty, $from } = state.selection;
495
- const mark = marks2.link.create({
496
- href,
497
- title: attrs.title ?? null,
498
- target: attrs.target ?? null
499
- });
500
- if (empty) {
501
- const range = markRange(state, marks2.link, $from.pos);
502
- if (range) {
503
- dispatch?.(
504
- state.tr.removeMark(range.from, range.to, marks2.link).addMark(range.from, range.to, mark)
505
- );
506
- return true;
507
- }
508
- dispatch?.(state.tr.insert(from, schema.text(href, [mark])));
509
- return true;
510
- }
511
- dispatch?.(state.tr.removeMark(from, to, marks2.link).addMark(from, to, mark));
512
- return true;
513
- };
514
- }
515
- function insertImage(src, alt) {
516
- return (state, dispatch) => {
517
- if (!isSafeImageUrl(src)) return false;
518
- dispatch?.(
519
- state.tr.replaceSelectionWith(nodes2.image.create({ src, alt: alt ?? null })).scrollIntoView()
520
- );
521
- return true;
522
- };
523
- }
524
- function isMarkActive(state, type) {
525
- const { from, $from, to, empty } = state.selection;
526
- if (empty) return !!type.isInSet(state.storedMarks ?? $from.marks());
527
- return state.doc.rangeHasMark(from, to, type);
528
- }
529
- function isNodeActive(state, type, attrs) {
530
- const { $from, to } = state.selection;
531
- for (let depth = $from.depth; depth > 0; depth--) {
532
- const node = $from.node(depth);
533
- if (node.type === type && (!attrs || Object.entries(attrs).every(([k, v]) => node.attrs[k] === v))) {
534
- return to <= $from.end(depth);
535
- }
536
- }
537
- return false;
538
- }
539
- function getActiveAlign(state) {
540
- const parent = state.selection.$from.parent;
541
- return parent.attrs.align ?? "left";
542
- }
543
- function isCommandActive(state, command) {
544
- const parent = state.selection.$from.parent;
545
- switch (command) {
546
- case "bold":
547
- case "italic":
548
- case "underline":
549
- case "strike":
550
- case "code":
551
- case "subscript":
552
- case "superscript":
553
- return isMarkActive(state, marks2[command]);
554
- case "paragraph":
555
- return parent.type === nodes2.paragraph;
556
- case "h1":
557
- case "h2":
558
- case "h3":
559
- case "h4":
560
- case "h5":
561
- case "h6":
562
- return parent.type === nodes2.heading && parent.attrs.level === Number(command[1]);
563
- case "codeBlock":
564
- return parent.type === nodes2.code_block;
565
- case "blockquote":
566
- return isNodeActive(state, nodes2.blockquote);
567
- case "bulletList":
568
- return isNodeActive(state, nodes2.bullet_list);
569
- case "orderedList":
570
- return isNodeActive(state, nodes2.ordered_list);
571
- case "alignLeft":
572
- return getActiveAlign(state) === "left";
573
- case "alignCenter":
574
- return getActiveAlign(state) === "center";
575
- case "alignRight":
576
- return getActiveAlign(state) === "right";
577
- case "alignJustify":
578
- return getActiveAlign(state) === "justify";
579
- default:
580
- return false;
581
- }
582
- }
583
- function getLinkAt(state) {
584
- const { $from } = state.selection;
585
- const mark = marks2.link.isInSet($from.marks()) ?? marks2.link.isInSet($from.nodeAfter?.marks ?? []);
586
- return mark ? mark.attrs : null;
587
- }
588
- function markRange(state, type, pos) {
589
- const $pos = state.doc.resolve(pos);
590
- const base = $pos.start();
591
- const segments = [];
592
- $pos.parent.forEach((child, offset) => {
593
- if (!type.isInSet(child.marks)) return;
594
- const from = base + offset;
595
- const to = from + child.nodeSize;
596
- const last = segments[segments.length - 1];
597
- if (last && last.to === from) last.to = to;
598
- else segments.push({ from, to });
599
- });
600
- return segments.find((s) => s.from <= pos && pos <= s.to) ?? null;
601
- }
1
+ import {
2
+ cssValue,
3
+ schema
4
+ } from "./chunk-YZPJQB3I.js";
5
+ import {
6
+ FOCUSABLE,
7
+ h,
8
+ icon,
9
+ uniqueId
10
+ } from "./chunk-HZRIBOPW.js";
11
+ import {
12
+ getLinkAt,
13
+ insertImage,
14
+ isSafeImageUrl,
15
+ isSafeLinkUrl,
16
+ markRange,
17
+ marksOf,
18
+ nodesOf
19
+ } from "./chunk-GHEFKKRC.js";
602
20
 
603
21
  // src/ui/icons.ts
604
22
  var svg = (body) => `<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${body}</svg>`;
@@ -700,6 +118,13 @@ var icons = {
700
118
  colHeader: svg(
701
119
  '<rect x="3" y="4" width="18" height="16" rx="1.5"/><path d="M9.5 4v16"/><path d="M4 5h5v14H4z" fill="currentColor" opacity=".35" stroke="none"/>'
702
120
  ),
121
+ sort: svg('<path d="M7 4v16M4 17l3 3 3-3"/><path d="M14 6h7M14 11h5M14 16h3"/>'),
122
+ tableProps: svg(
123
+ '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 10h18M9 10v10"/><path d="M15 15h3"/>'
124
+ ),
125
+ cellProps: svg(
126
+ '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 10h18M9 4v16"/><rect x="11" y="12" width="8" height="6" rx="1"/>'
127
+ ),
703
128
  tableDelete: svg(
704
129
  '<rect x="3" y="4" width="13" height="12" rx="1"/><path d="M3 10h13M9.5 4v12"/><path d="m17 15 4 4M21 15l-4 4"/>'
705
130
  ),
@@ -748,50 +173,6 @@ import {
748
173
  PluginKey
749
174
  } from "prosemirror-state";
750
175
 
751
- // src/ui/dom.ts
752
- function h(tag, attrs = {}, ...children) {
753
- const el = document.createElement(tag);
754
- for (const [name, value] of Object.entries(attrs)) {
755
- if (value === null || value === void 0 || value === false) continue;
756
- if (typeof value === "function") {
757
- el.addEventListener(name.replace(/^on/, "").toLowerCase(), value);
758
- } else if (name === "className") {
759
- el.className = String(value);
760
- } else {
761
- el.setAttribute(name, value === true ? "" : String(value));
762
- }
763
- }
764
- for (const child of children.flat()) {
765
- if (child === null || child === void 0 || child === false) continue;
766
- el.append(child);
767
- }
768
- return el;
769
- }
770
- function icon(svg2) {
771
- const span = document.createElement("span");
772
- span.className = "nova-icon";
773
- span.innerHTML = svg2;
774
- return span;
775
- }
776
- var uid = 0;
777
- function uniqueId(prefix = "nova") {
778
- uid += 1;
779
- return `${prefix}-${uid}`;
780
- }
781
- var isMac = typeof navigator !== "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
782
- function formatShortcut(shortcut) {
783
- const parts = shortcut.split("-");
784
- const key = parts.pop();
785
- const keyLabel = key.length === 1 ? key.toUpperCase() : key;
786
- if (isMac) {
787
- const map2 = { Mod: "\u2318", Shift: "\u21E7", Alt: "\u2325", Ctrl: "\u2303" };
788
- return parts.map((p) => map2[p] ?? p).join("") + keyLabel;
789
- }
790
- const map = { Mod: "Ctrl", Shift: "Shift", Alt: "Alt", Ctrl: "Ctrl" };
791
- return [...parts.map((p) => map[p] ?? p), keyLabel].join("+");
792
- }
793
- var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
794
-
795
176
  // src/ui/dialog.ts
796
177
  function openDialog(options) {
797
178
  const titleId = uniqueId("nova-dialog-title");
@@ -928,6 +309,22 @@ function checkboxField(label, checked = false) {
928
309
  );
929
310
  return { el, input };
930
311
  }
312
+ function selectField(options) {
313
+ const id = uniqueId("nova-field");
314
+ const select = h(
315
+ "select",
316
+ { id, className: "nova-input nova-select" },
317
+ ...options.options.map((o) => h("option", { value: o.value }, o.label))
318
+ );
319
+ select.value = options.value;
320
+ const el = h(
321
+ "div",
322
+ { className: "nova-field" },
323
+ h("label", { for: id, className: "nova-label" }, options.label),
324
+ select
325
+ );
326
+ return { el, select };
327
+ }
931
328
 
932
329
  // src/image.ts
933
330
  var IMAGE_TYPES = /^image\/(png|jpe?g|gif|webp|avif|bmp)$/;
@@ -946,7 +343,7 @@ function findImage(view, src) {
946
343
  let found = null;
947
344
  view.state.doc.descendants((node, pos) => {
948
345
  if (found !== null) return false;
949
- if (node.type === schema.nodes.image && node.attrs.src === src) found = pos;
346
+ if (node.type === nodesOf(view.state).image && node.attrs.src === src) found = pos;
950
347
  return true;
951
348
  });
952
349
  return found;
@@ -956,7 +353,7 @@ function uploadImages(editor, files, pos) {
956
353
  const view = editor.view;
957
354
  for (const file of images) {
958
355
  const blobUrl = URL.createObjectURL(file);
959
- const node = schema.nodes.image.create({ src: blobUrl, alt: null });
356
+ const node = nodesOf(view.state).image.create({ src: blobUrl, alt: null });
960
357
  const tr = view.state.tr;
961
358
  if (pos !== void 0) tr.insert(Math.min(pos, tr.doc.content.size), node);
962
359
  else tr.replaceSelectionWith(node);
@@ -987,6 +384,74 @@ function uploadImages(editor, files, pos) {
987
384
  });
988
385
  }
989
386
  }
387
+ var DATA_IMAGE = /^data:(image\/(?:png|jpe?g|gif|webp|avif|bmp));base64,(.+)$/i;
388
+ function dataUrlToFile(src, name = "pasted-image") {
389
+ const match = src.match(DATA_IMAGE);
390
+ if (!match) return null;
391
+ const type = match[1].toLowerCase();
392
+ try {
393
+ const binary = atob(match[2]);
394
+ const bytes = new Uint8Array(binary.length);
395
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
396
+ const ext = type.split("/")[1].replace("jpeg", "jpg");
397
+ return new File([bytes], `${name}.${ext}`, { type });
398
+ } catch {
399
+ return null;
400
+ }
401
+ }
402
+ function replaceImageSrc(view, from, to) {
403
+ const tr = view.state.tr;
404
+ view.state.doc.descendants((node, pos) => {
405
+ if (node.type === nodesOf(view.state).image && node.attrs.src === from) {
406
+ tr.setNodeMarkup(pos, void 0, { ...node.attrs, src: to });
407
+ }
408
+ });
409
+ if (tr.docChanged) view.dispatch(tr.setMeta("addToHistory", false));
410
+ }
411
+ async function uploadEmbeddedImage(editor, src) {
412
+ const handler = editor.options.uploadImage;
413
+ const file = handler ? dataUrlToFile(src) : null;
414
+ if (!handler || !file) return;
415
+ const notice = editor.ui.notify({ text: editor.ui.t("image.uploading"), timeout: 0 });
416
+ try {
417
+ const url = await handler(
418
+ file,
419
+ (percent) => notice.setText(`${editor.ui.t("image.uploading")} ${Math.round(percent)}%`)
420
+ );
421
+ if (!isSafeImageUrl(url)) throw new Error(`Unsafe image URL returned: ${url}`);
422
+ replaceImageSrc(editor.view, src, url);
423
+ } catch (error) {
424
+ console.error("[nova] embedded image upload failed", error);
425
+ editor.ui.notify({ text: editor.ui.t("image.uploadFailed"), type: "error" });
426
+ } finally {
427
+ notice.close();
428
+ }
429
+ }
430
+ function dataImageSrcs(doc, type) {
431
+ const srcs = /* @__PURE__ */ new Set();
432
+ doc.descendants((node) => {
433
+ if (node.type === type && DATA_IMAGE.test(node.attrs.src)) srcs.add(node.attrs.src);
434
+ });
435
+ return srcs;
436
+ }
437
+ function embeddedImageUploadPlugin(editor) {
438
+ return new Plugin({
439
+ key: new PluginKey("nova-embedded-image-upload"),
440
+ appendTransaction(transactions, oldState, newState) {
441
+ if (!editor.options.uploadImage) return null;
442
+ const fromUser = transactions.some(
443
+ (tr) => ["paste", "drop"].includes(tr.getMeta("uiEvent"))
444
+ );
445
+ if (!fromUser || !transactions.some((tr) => tr.docChanged)) return null;
446
+ const type = nodesOf(newState).image;
447
+ const before = dataImageSrcs(oldState.doc, type);
448
+ const added = [...dataImageSrcs(newState.doc, type)].filter((src) => !before.has(src));
449
+ if (added.length)
450
+ queueMicrotask(() => added.forEach((src) => void uploadEmbeddedImage(editor, src)));
451
+ return null;
452
+ }
453
+ });
454
+ }
990
455
  function imageDropPastePlugin(editor) {
991
456
  return new Plugin({
992
457
  key: new PluginKey("nova-image-drop-paste"),
@@ -1075,7 +540,7 @@ function openImageDialog(editor) {
1075
540
  }
1076
541
  function getSelectedImage(state) {
1077
542
  const { selection } = state;
1078
- if (selection instanceof NodeSelection && selection.node.type === schema.nodes.image) {
543
+ if (selection instanceof NodeSelection && selection.node.type === nodesOf(state).image) {
1079
544
  return { node: selection.node, pos: selection.from };
1080
545
  }
1081
546
  return null;
@@ -1142,7 +607,7 @@ function normalizeUrl(input) {
1142
607
  }
1143
608
  function linkTarget(state) {
1144
609
  const { from, to, empty, $from } = state.selection;
1145
- if (empty) return markRange(state, schema.marks.link, $from.pos) ?? { from, to };
610
+ if (empty) return markRange(state, marksOf(state).link, $from.pos) ?? { from, to };
1146
611
  return { from, to };
1147
612
  }
1148
613
  function applyLink(attrs) {
@@ -1151,7 +616,7 @@ function applyLink(attrs) {
1151
616
  if (!href || !isSafeLinkUrl(href)) return false;
1152
617
  if (!dispatch) return true;
1153
618
  const { from, to } = linkTarget(state);
1154
- const linkMark = schema.marks.link.create({
619
+ const linkMark = marksOf(state).link.create({
1155
620
  href,
1156
621
  title: attrs.title || null,
1157
622
  target: attrs.target || null
@@ -1160,11 +625,11 @@ function applyLink(attrs) {
1160
625
  const text = attrs.text?.trim() ? attrs.text : null;
1161
626
  const tr = state.tr;
1162
627
  if (from === to || text !== null && text !== currentText) {
1163
- const baseMarks = schema.marks.link.removeFromSet(state.doc.resolve(from).marks());
1164
- const node = schema.text(text ?? (currentText || href), linkMark.addToSet(baseMarks));
628
+ const baseMarks = marksOf(state).link.removeFromSet(state.doc.resolve(from).marks());
629
+ const node = state.schema.text(text ?? (currentText || href), linkMark.addToSet(baseMarks));
1165
630
  tr.replaceWith(from, to, node);
1166
631
  } else {
1167
- tr.removeMark(from, to, schema.marks.link).addMark(from, to, linkMark);
632
+ tr.removeMark(from, to, marksOf(state).link).addMark(from, to, linkMark);
1168
633
  }
1169
634
  dispatch(tr.scrollIntoView());
1170
635
  return true;
@@ -1173,8 +638,8 @@ function applyLink(attrs) {
1173
638
  function removeLink() {
1174
639
  return (state, dispatch) => {
1175
640
  const { from, to } = linkTarget(state);
1176
- if (from === to || !state.doc.rangeHasMark(from, to, schema.marks.link)) return false;
1177
- dispatch?.(state.tr.removeMark(from, to, schema.marks.link));
641
+ if (from === to || !state.doc.rangeHasMark(from, to, marksOf(state).link)) return false;
642
+ dispatch?.(state.tr.removeMark(from, to, marksOf(state).link));
1178
643
  return true;
1179
644
  };
1180
645
  }
@@ -1230,6 +695,7 @@ function openLinkDialog(editor) {
1230
695
 
1231
696
  // src/table.ts
1232
697
  import { keymap } from "prosemirror-keymap";
698
+ import { Fragment } from "prosemirror-model";
1233
699
  import { TextSelection } from "prosemirror-state";
1234
700
  import {
1235
701
  addColumnAfter,
@@ -1249,11 +715,12 @@ import {
1249
715
  setCellAttr,
1250
716
  splitCell,
1251
717
  tableEditing,
718
+ TableView,
1252
719
  toggleHeader
1253
720
  } from "prosemirror-tables";
1254
721
  var MAX_GRID = 10;
1255
- function createTable(rows, cols, withHeader = true) {
1256
- const { table, table_row, table_cell, table_header, paragraph } = schema.nodes;
722
+ function createTable(rows, cols, withHeader = true, schema2 = schema) {
723
+ const { table, table_row, table_cell, table_header, paragraph } = schema2.nodes;
1257
724
  const rowNodes = [];
1258
725
  for (let r = 0; r < rows; r++) {
1259
726
  const cellType = withHeader && r === 0 ? table_header : table_cell;
@@ -1268,7 +735,7 @@ function insertTable(rows, cols, withHeader = true) {
1268
735
  if (rows < 1 || cols < 1 || rows > 100 || cols > 50) return false;
1269
736
  if (isInTable(state)) return false;
1270
737
  if (dispatch) {
1271
- const node = createTable(rows, cols, withHeader);
738
+ const node = createTable(rows, cols, withHeader, state.schema);
1272
739
  const tr = state.tr.replaceSelectionWith(node);
1273
740
  let tablePos = -1;
1274
741
  tr.doc.descendants((n, pos) => {
@@ -1294,7 +761,7 @@ var nextCellOrNewRow = (state, dispatch, view) => {
1294
761
  };
1295
762
  function tablePlugins() {
1296
763
  return [
1297
- columnResizing({ cellMinWidth: 48 }),
764
+ columnResizing({ cellMinWidth: 48, View: NovaTableView }),
1298
765
  tableEditing(),
1299
766
  keymap({
1300
767
  Tab: nextCellOrNewRow,
@@ -1325,7 +792,7 @@ function hasHeaderRow(state) {
1325
792
  if (!firstRow || firstRow.childCount === 0) return false;
1326
793
  let all = true;
1327
794
  firstRow.forEach((cell) => {
1328
- if (cell.type !== schema.nodes.table_header) all = false;
795
+ if (cell.type !== state.schema.nodes.table_header) all = false;
1329
796
  });
1330
797
  return all;
1331
798
  }
@@ -1335,7 +802,7 @@ function hasHeaderColumn(state) {
1335
802
  if (!table) return false;
1336
803
  let all = true;
1337
804
  table.forEach((row) => {
1338
- if (row.firstChild?.type !== schema.nodes.table_header) all = false;
805
+ if (row.firstChild?.type !== state.schema.nodes.table_header) all = false;
1339
806
  });
1340
807
  return all;
1341
808
  }
@@ -1400,31 +867,178 @@ function createTableGridPanel(onPick, label, gridLabel) {
1400
867
  paint();
1401
868
  return h("div", { className: "nova-grid-panel" }, grid, caption);
1402
869
  }
870
+ function numericValue(text) {
871
+ const cleaned = text.replace(/\s/g, "").replace(/^[^\d+-]+|[^\d]+$/g, "").replace(/,(?=\d{3}(?:\D|$))/g, "").replace(",", ".");
872
+ if (!/^[+-]?\d+(\.\d+)?$/.test(cleaned)) return null;
873
+ return Number(cleaned);
874
+ }
875
+ function sortTarget(state) {
876
+ if (!isInTable(state)) return null;
877
+ const rect = selectedRect(state);
878
+ const table = rect.table;
879
+ let merged = false;
880
+ table.descendants((node) => {
881
+ if (node.attrs.colspan > 1 || node.attrs.rowspan > 1) merged = true;
882
+ return !merged && node.type.spec.tableRole !== "cell" && node.type.spec.tableRole !== "header_cell";
883
+ });
884
+ if (merged) return null;
885
+ const nodes = state.schema.nodes;
886
+ let headerRows = 0;
887
+ for (let i = 0; i < table.childCount; i++) {
888
+ let allHeaders = true;
889
+ table.child(i).forEach((cell) => {
890
+ if (cell.type !== nodes.table_header) allHeaders = false;
891
+ });
892
+ if (!allHeaders) break;
893
+ headerRows++;
894
+ }
895
+ if (table.childCount - headerRows < 2) return null;
896
+ return { pos: rect.tableStart - 1, table, column: rect.left, headerRows };
897
+ }
898
+ function sortTable(direction, locale) {
899
+ return (state, dispatch) => {
900
+ const target = sortTarget(state);
901
+ if (!target) return false;
902
+ if (dispatch) {
903
+ const { table, column, headerRows, pos } = target;
904
+ const rows = [];
905
+ table.forEach((row) => rows.push(row));
906
+ const head = rows.slice(0, headerRows);
907
+ const body = rows.slice(headerRows);
908
+ const texts = body.map(
909
+ (row) => column < row.childCount ? row.child(column).textContent.trim() : ""
910
+ );
911
+ const numbers = texts.map(numericValue);
912
+ const numeric = texts.every((t, i) => t === "" || numbers[i] !== null);
913
+ const collator = new Intl.Collator(locale, { numeric: true, sensitivity: "base" });
914
+ const order = body.map((row, i) => ({ row, i })).sort((a, b) => {
915
+ const ta = texts[a.i];
916
+ const tb = texts[b.i];
917
+ if (!ta || !tb) return ta ? -1 : tb ? 1 : a.i - b.i;
918
+ const cmp = numeric ? numbers[a.i] - numbers[b.i] : collator.compare(ta, tb);
919
+ return (direction === "asc" ? cmp : -cmp) || a.i - b.i;
920
+ }).map(({ row }) => row);
921
+ const sorted = table.copy(Fragment.from([...head, ...order]));
922
+ dispatch(state.tr.replaceWith(pos, pos + table.nodeSize, sorted).scrollIntoView());
923
+ }
924
+ return true;
925
+ };
926
+ }
927
+ var NovaTableView = class extends TableView {
928
+ constructor(node, cellMinWidth) {
929
+ super(node, cellMinWidth);
930
+ this.apply(node);
931
+ }
932
+ update(node) {
933
+ if (!super.update(node)) return false;
934
+ this.apply(node);
935
+ return true;
936
+ }
937
+ apply(node) {
938
+ const width = cssValue.length(node.attrs.width);
939
+ if (width) {
940
+ this.table.style.width = width;
941
+ this.table.style.minWidth = "";
942
+ }
943
+ const align = node.attrs.align;
944
+ this.table.style.marginLeft = align ? "auto" : "";
945
+ this.table.style.marginRight = align === "center" ? "auto" : "";
946
+ }
947
+ };
948
+ function getTableProps(state) {
949
+ const found = findTable(state.selection.$from);
950
+ return found ? { width: found.node.attrs.width ?? null, align: found.node.attrs.align ?? null } : null;
951
+ }
952
+ function setTableProps(props) {
953
+ return (state, dispatch) => {
954
+ const found = findTable(state.selection.$from);
955
+ if (!found) return false;
956
+ if (props.width !== null && !cssValue.length(props.width)) return false;
957
+ dispatch?.(state.tr.setNodeMarkup(found.pos, void 0, { ...found.node.attrs, ...props }));
958
+ return true;
959
+ };
960
+ }
961
+ function selectedCells(state) {
962
+ const out = [];
963
+ if (state.selection instanceof CellSelection) {
964
+ state.selection.forEachCell((node, pos) => out.push({ node, pos }));
965
+ return out;
966
+ }
967
+ const { $from } = state.selection;
968
+ for (let depth = $from.depth; depth > 0; depth--) {
969
+ const node = $from.node(depth);
970
+ const role = node.type.spec.tableRole;
971
+ if (role === "cell" || role === "header_cell") {
972
+ out.push({ node, pos: $from.before(depth) });
973
+ break;
974
+ }
975
+ }
976
+ return out;
977
+ }
978
+ function getCellProps(state) {
979
+ const cell = selectedCells(state)[0];
980
+ if (!cell) return null;
981
+ const widths = cell.node.attrs.colwidth;
982
+ return {
983
+ valign: cell.node.attrs.valign ?? null,
984
+ header: cell.node.type === state.schema.nodes.table_header,
985
+ width: widths?.[0] ?? null
986
+ };
987
+ }
988
+ function setCellProps(props) {
989
+ return (state, dispatch) => {
990
+ const cells = selectedCells(state);
991
+ if (!cells.length) return false;
992
+ if (props.width != null && !(props.width >= 24 && props.width <= 4e3)) return false;
993
+ if (!dispatch) return true;
994
+ const nodes = state.schema.nodes;
995
+ const tr = state.tr;
996
+ for (const { pos, node } of cells) {
997
+ const type = props.header === void 0 ? node.type : props.header ? nodes.table_header : nodes.table_cell;
998
+ const attrs = {
999
+ ...node.attrs,
1000
+ ...props.valign !== void 0 ? { valign: props.valign } : {}
1001
+ };
1002
+ tr.setNodeMarkup(pos, type, attrs);
1003
+ }
1004
+ if (props.width !== void 0) {
1005
+ const rect = selectedRect(state);
1006
+ const map = rect.map;
1007
+ const seen = /* @__PURE__ */ new Set();
1008
+ for (let col = rect.left; col < rect.right; col++) {
1009
+ for (let row = 0; row < map.height; row++) {
1010
+ const cellPos = map.map[row * map.width + col];
1011
+ const key = cellPos * 1e3 + col;
1012
+ if (seen.has(key)) continue;
1013
+ seen.add(key);
1014
+ const absolute = rect.tableStart + cellPos;
1015
+ const cell = tr.doc.nodeAt(absolute);
1016
+ if (!cell) continue;
1017
+ const index = col - map.colCount(cellPos);
1018
+ const widths = [
1019
+ ...cell.attrs.colwidth ?? new Array(cell.attrs.colspan).fill(0)
1020
+ ];
1021
+ widths[index] = props.width ?? 0;
1022
+ tr.setNodeMarkup(absolute, void 0, {
1023
+ ...cell.attrs,
1024
+ colwidth: widths.every((w) => !w) ? null : widths
1025
+ });
1026
+ }
1027
+ }
1028
+ }
1029
+ dispatch(tr);
1030
+ return true;
1031
+ };
1032
+ }
1403
1033
 
1404
1034
  export {
1405
- isSafeLinkUrl,
1406
- isSafeImageUrl,
1407
- cssValue,
1408
- imageSize,
1409
- schema,
1410
- commands,
1411
- setLink,
1412
- insertImage,
1413
- isMarkActive,
1414
- isNodeActive,
1415
- getActiveAlign,
1416
- isCommandActive,
1417
- getLinkAt,
1418
- markRange,
1419
- h,
1420
- icon,
1421
- uniqueId,
1422
- formatShortcut,
1423
1035
  icons,
1424
1036
  openDialog,
1425
1037
  textField,
1038
+ selectField,
1426
1039
  isSupportedImage,
1427
1040
  uploadImages,
1041
+ embeddedImageUploadPlugin,
1428
1042
  imageDropPastePlugin,
1429
1043
  openImageDialog,
1430
1044
  getSelectedImage,
@@ -1444,6 +1058,11 @@ export {
1444
1058
  hasHeaderRow,
1445
1059
  hasHeaderColumn,
1446
1060
  tableRect,
1447
- createTableGridPanel
1061
+ createTableGridPanel,
1062
+ sortTable,
1063
+ getTableProps,
1064
+ setTableProps,
1065
+ getCellProps,
1066
+ setCellProps
1448
1067
  };
1449
- //# sourceMappingURL=chunk-TKR3C5IJ.js.map
1068
+ //# sourceMappingURL=chunk-PHRON5PL.js.map