@harbour-enterprises/superdoc 0.13.3 → 0.13.4

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 (47) hide show
  1. package/dist/chunks/{index-B4J7wgs6.cjs → index-1MFGOw5E.cjs} +1 -1
  2. package/dist/chunks/{index-Cdsq63Xq.cjs → index-C7OD1PyE.cjs} +2 -2
  3. package/dist/chunks/{index-Diu6UKHt.es.js → index-DaN_owlg.es.js} +2 -2
  4. package/dist/chunks/{index-Hr3Um-Bg.es.js → index-DrDbu1Lu.es.js} +1 -1
  5. package/dist/chunks/{super-editor.es-D6IwM8Ss.cjs → super-editor.es-BHUbsUJ8.cjs} +1125 -831
  6. package/dist/chunks/{super-editor.es-Dr2PHXQw.es.js → super-editor.es-Dku_HwPp.es.js} +1125 -831
  7. package/dist/chunks/{url-CHayXMZH.es.js → url-CMRvONpz.es.js} +1 -1
  8. package/dist/chunks/{url-BIzg4y2i.cjs → url-CQY43xA2.cjs} +1 -1
  9. package/dist/chunks/{xml-js-BjqmFOSP.cjs → xml-js-BjAVbxT-.cjs} +11 -4
  10. package/dist/chunks/{xml-js-CfClL-1b.es.js → xml-js-DrozhLyq.es.js} +11 -4
  11. package/dist/style.css +2 -2
  12. package/dist/super-editor/ai-writer.es.js +2 -2
  13. package/dist/super-editor/chunks/{converter-BAzy5pWu.js → converter-C4o4RStl.js} +651 -56
  14. package/dist/super-editor/chunks/{docx-zipper-CHpW7qj4.js → docx-zipper-C02wYZX8.js} +1 -1
  15. package/dist/super-editor/chunks/{editor-DkYKMWgz.js → editor-BQxch2iC.js} +307 -605
  16. package/dist/super-editor/chunks/{toolbar-DUmK-BBL.js → toolbar-Cf-_NucR.js} +2 -2
  17. package/dist/super-editor/converter.es.js +2 -2
  18. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  19. package/dist/super-editor/core/InputRule.d.ts +7 -0
  20. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  21. package/dist/super-editor/core/helpers/annotator.d.ts +4 -0
  22. package/dist/super-editor/core/helpers/annotator.d.ts.map +1 -1
  23. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  24. package/dist/super-editor/docx-zipper.es.js +2 -2
  25. package/dist/super-editor/editor.es.js +3 -3
  26. package/dist/super-editor/extensions/field-annotation/field-annotation.d.ts.map +1 -1
  27. package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
  28. package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
  29. package/dist/super-editor/extensions/page-number/page-number.d.ts.map +1 -1
  30. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +6 -1
  31. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  32. package/dist/super-editor/extensions/table/table.d.ts.map +1 -1
  33. package/dist/super-editor/extensions/table/tableHelpers/cellAround.d.ts +2 -0
  34. package/dist/super-editor/extensions/table/tableHelpers/cellAround.d.ts.map +1 -0
  35. package/dist/super-editor/extensions/table/tableHelpers/cellWrapping.d.ts +2 -0
  36. package/dist/super-editor/extensions/table/tableHelpers/cellWrapping.d.ts.map +1 -0
  37. package/dist/super-editor/file-zipper.es.js +1 -1
  38. package/dist/super-editor/style.css +2 -2
  39. package/dist/super-editor/super-editor.es.js +7 -7
  40. package/dist/super-editor/toolbar.es.js +2 -2
  41. package/dist/super-editor.cjs +1 -1
  42. package/dist/super-editor.es.js +1 -1
  43. package/dist/superdoc.cjs +5 -5
  44. package/dist/superdoc.es.js +6 -6
  45. package/dist/superdoc.umd.js +1127 -833
  46. package/dist/superdoc.umd.js.map +1 -1
  47. package/package.json +1 -1
@@ -18318,7 +18318,7 @@
18318
18318
  }
18319
18319
  }
18320
18320
  const emptyAttrs = /* @__PURE__ */ Object.create(null);
18321
- let Node$2 = class Node2 {
18321
+ let Node$1$1 = class Node2 {
18322
18322
  /**
18323
18323
  @internal
18324
18324
  */
@@ -18719,8 +18719,8 @@
18719
18719
  return node2;
18720
18720
  }
18721
18721
  };
18722
- Node$2.prototype.text = void 0;
18723
- class TextNode extends Node$2 {
18722
+ Node$1$1.prototype.text = void 0;
18723
+ class TextNode extends Node$1$1 {
18724
18724
  /**
18725
18725
  @internal
18726
18726
  */
@@ -19307,7 +19307,7 @@
19307
19307
  create(attrs = null, content, marks) {
19308
19308
  if (this.isText)
19309
19309
  throw new Error("NodeType.create can't construct text nodes");
19310
- return new Node$2(this, this.computeAttrs(attrs), Fragment.from(content), Mark$1.setFrom(marks));
19310
+ return new Node$1$1(this, this.computeAttrs(attrs), Fragment.from(content), Mark$1.setFrom(marks));
19311
19311
  }
19312
19312
  /**
19313
19313
  Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content
@@ -19317,7 +19317,7 @@
19317
19317
  createChecked(attrs = null, content, marks) {
19318
19318
  content = Fragment.from(content);
19319
19319
  this.checkContent(content);
19320
- return new Node$2(this, this.computeAttrs(attrs), content, Mark$1.setFrom(marks));
19320
+ return new Node$1$1(this, this.computeAttrs(attrs), content, Mark$1.setFrom(marks));
19321
19321
  }
19322
19322
  /**
19323
19323
  Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is
@@ -19340,7 +19340,7 @@
19340
19340
  let after = matched && matched.fillBefore(Fragment.empty, true);
19341
19341
  if (!after)
19342
19342
  return null;
19343
- return new Node$2(this, attrs, content.append(after), Mark$1.setFrom(marks));
19343
+ return new Node$1$1(this, attrs, content.append(after), Mark$1.setFrom(marks));
19344
19344
  }
19345
19345
  /**
19346
19346
  Returns true if the given fragment is valid content for this node
@@ -19577,7 +19577,7 @@
19577
19577
  bound.
19578
19578
  */
19579
19579
  nodeFromJSON(json) {
19580
- return Node$2.fromJSON(this, json);
19580
+ return Node$1$1.fromJSON(this, json);
19581
19581
  }
19582
19582
  /**
19583
19583
  Deserialize a mark from its JSON representation. This method is
@@ -23137,7 +23137,7 @@
23137
23137
  let instance = new EditorState($config);
23138
23138
  $config.fields.forEach((field) => {
23139
23139
  if (field.name == "doc") {
23140
- instance.doc = Node$2.fromJSON(config.schema, json.doc);
23140
+ instance.doc = Node$1$1.fromJSON(config.schema, json.doc);
23141
23141
  } else if (field.name == "selection") {
23142
23142
  instance.selection = Selection.fromJSON(instance.doc, json.selection);
23143
23143
  } else if (field.name == "storedMarks") {
@@ -26198,6 +26198,583 @@
26198
26198
  colgroupValues
26199
26199
  };
26200
26200
  };
26201
+ function chainableEditorState(transaction, state2) {
26202
+ let { selection, doc: doc2, storedMarks } = transaction;
26203
+ return {
26204
+ ...state2,
26205
+ apply: state2.apply.bind(state2),
26206
+ applyTransaction: state2.applyTransaction.bind(state2),
26207
+ plugins: state2.plugins,
26208
+ schema: state2.schema,
26209
+ reconfigure: state2.reconfigure.bind(state2),
26210
+ toJSON: state2.toJSON.bind(state2),
26211
+ get storedMarks() {
26212
+ return storedMarks;
26213
+ },
26214
+ get selection() {
26215
+ return selection;
26216
+ },
26217
+ get doc() {
26218
+ return doc2;
26219
+ },
26220
+ get tr() {
26221
+ selection = transaction.selection;
26222
+ doc2 = transaction.doc;
26223
+ storedMarks = transaction.storedMarks;
26224
+ return transaction;
26225
+ }
26226
+ };
26227
+ }
26228
+ class CommandService {
26229
+ constructor(props) {
26230
+ __publicField$2(this, "editor");
26231
+ __publicField$2(this, "rawCommands");
26232
+ this.editor = props.editor;
26233
+ this.rawCommands = this.editor.extensionService.commands;
26234
+ }
26235
+ /**
26236
+ * Static method for creating a service.
26237
+ * @param args Arguments for the constructor.
26238
+ */
26239
+ static create(...args) {
26240
+ return new CommandService(...args);
26241
+ }
26242
+ /**
26243
+ * Get editor state.
26244
+ */
26245
+ get state() {
26246
+ return this.editor.state;
26247
+ }
26248
+ /**
26249
+ * Get all commands with wrapped command method.
26250
+ */
26251
+ get commands() {
26252
+ const { editor, state: state2 } = this;
26253
+ const { view } = editor;
26254
+ const { tr } = state2;
26255
+ const props = this.createProps(tr);
26256
+ const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
26257
+ const method = (...args) => {
26258
+ const fn = command2(...args)(props);
26259
+ if (!tr.getMeta("preventDispatch")) {
26260
+ view.dispatch(tr);
26261
+ }
26262
+ return fn;
26263
+ };
26264
+ return [name, method];
26265
+ });
26266
+ return Object.fromEntries(entries);
26267
+ }
26268
+ /**
26269
+ * Create a chain of commands to call multiple commands at once.
26270
+ */
26271
+ get chain() {
26272
+ return () => this.createChain();
26273
+ }
26274
+ /**
26275
+ * Check if a command or a chain of commands can be executed. Without executing it.
26276
+ */
26277
+ get can() {
26278
+ return () => this.createCan();
26279
+ }
26280
+ /**
26281
+ * Creates a chain of commands.
26282
+ * @param startTr Start transaction.
26283
+ * @param shouldDispatch Should dispatch or not.
26284
+ */
26285
+ createChain(startTr, shouldDispatch = true) {
26286
+ const { editor, state: state2, rawCommands } = this;
26287
+ const { view } = editor;
26288
+ const callbacks2 = [];
26289
+ const hasStartTr = !!startTr;
26290
+ const tr = startTr || state2.tr;
26291
+ const run2 = () => {
26292
+ if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
26293
+ view.dispatch(tr);
26294
+ }
26295
+ return callbacks2.every((cb) => cb === true);
26296
+ };
26297
+ const entries = Object.entries(rawCommands).map(([name, command2]) => {
26298
+ const chainedCommand = (...args) => {
26299
+ const props = this.createProps(tr, shouldDispatch);
26300
+ const callback = command2(...args)(props);
26301
+ callbacks2.push(callback);
26302
+ return chain;
26303
+ };
26304
+ return [name, chainedCommand];
26305
+ });
26306
+ const chain = {
26307
+ ...Object.fromEntries(entries),
26308
+ run: run2
26309
+ };
26310
+ return chain;
26311
+ }
26312
+ /**
26313
+ * Creates a can check for commands.
26314
+ * @param startTr Start transaction.
26315
+ */
26316
+ createCan(startTr) {
26317
+ const { rawCommands, state: state2 } = this;
26318
+ const dispatch = false;
26319
+ const tr = startTr || state2.tr;
26320
+ const props = this.createProps(tr, dispatch);
26321
+ const commands2 = Object.fromEntries(
26322
+ Object.entries(rawCommands).map(([name, command2]) => {
26323
+ return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
26324
+ })
26325
+ );
26326
+ return {
26327
+ ...commands2,
26328
+ chain: () => this.createChain(tr, dispatch)
26329
+ };
26330
+ }
26331
+ /**
26332
+ * Creates default props for the command method.
26333
+ * @param {*} tr Transaction.
26334
+ * @param {*} shouldDispatch Check if should dispatch.
26335
+ * @returns Object with props.
26336
+ */
26337
+ createProps(tr, shouldDispatch = true) {
26338
+ const { editor, state: state2, rawCommands } = this;
26339
+ const { view } = editor;
26340
+ const props = {
26341
+ tr,
26342
+ editor,
26343
+ view,
26344
+ state: chainableEditorState(tr, state2),
26345
+ dispatch: shouldDispatch ? () => void 0 : void 0,
26346
+ chain: () => this.createChain(tr, shouldDispatch),
26347
+ can: () => this.createCan(tr),
26348
+ get commands() {
26349
+ return Object.fromEntries(
26350
+ Object.entries(rawCommands).map(([name, command2]) => {
26351
+ return [name, (...args) => command2(...args)(props)];
26352
+ })
26353
+ );
26354
+ }
26355
+ };
26356
+ return props;
26357
+ }
26358
+ }
26359
+ function getHTMLFromFragment(fragment, schema) {
26360
+ const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
26361
+ const temporaryDocument = document.implementation.createHTMLDocument();
26362
+ const container = temporaryDocument.createElement("div");
26363
+ container.appendChild(documentFragment);
26364
+ return container.innerHTML;
26365
+ }
26366
+ const getTextContentFromNodes = ($from, maxMatch = 500) => {
26367
+ let textBefore = "";
26368
+ const sliceEndPos = $from.parentOffset;
26369
+ $from.parent.nodesBetween(
26370
+ Math.max(0, sliceEndPos - maxMatch),
26371
+ sliceEndPos,
26372
+ (node2, pos, parent, index2) => {
26373
+ const chunk = node2.type.spec.toText?.({
26374
+ node: node2,
26375
+ pos,
26376
+ parent,
26377
+ index: index2
26378
+ }) || node2.textContent || "%leaf%";
26379
+ textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
26380
+ }
26381
+ );
26382
+ return textBefore;
26383
+ };
26384
+ const handleDocxPaste = (html, editor, view, plugin2) => {
26385
+ const { converter } = editor;
26386
+ if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin2);
26387
+ let cleanedHtml = convertEmToPt(html);
26388
+ cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
26389
+ const tempDiv = document.createElement("div");
26390
+ tempDiv.innerHTML = cleanedHtml;
26391
+ const paragraphs = tempDiv.querySelectorAll("p");
26392
+ paragraphs.forEach((p2) => {
26393
+ const innerHTML2 = p2.innerHTML;
26394
+ if (!innerHTML2.includes("<!--[if !supportLists]")) return;
26395
+ const styleAttr = p2.getAttribute("style") || "";
26396
+ const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
26397
+ if (msoListMatch) {
26398
+ const [, abstractId, level] = msoListMatch;
26399
+ const listNumId = getListNumIdFromAbstract(abstractId, editor);
26400
+ if (!listNumId) return;
26401
+ const abstractDefinition = getListAbstractDefinition(abstractId, editor);
26402
+ const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
26403
+ p2.setAttribute("data-num-id", listNumId);
26404
+ p2.setAttribute("data-list-level", level - 1);
26405
+ p2.setAttribute("data-start", start2);
26406
+ p2.setAttribute("data-lvl-text", lvlText);
26407
+ p2.setAttribute("data-num-fmt", numFmt);
26408
+ }
26409
+ extractAndRemoveConditionalPrefix(p2);
26410
+ });
26411
+ transformWordLists(tempDiv);
26412
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
26413
+ tempDiv.remove();
26414
+ const { dispatch } = editor.view;
26415
+ if (!dispatch) return false;
26416
+ dispatch(view.state.tr.replaceSelectionWith(doc2, true));
26417
+ return true;
26418
+ };
26419
+ const getLevelDefinition = (abstractDefinition, level) => {
26420
+ if (!abstractDefinition || !abstractDefinition.elements) return null;
26421
+ const levelElement = abstractDefinition.elements.find((el) => {
26422
+ return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
26423
+ });
26424
+ if (!levelElement) return null;
26425
+ const { elements } = levelElement;
26426
+ const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
26427
+ const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
26428
+ const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
26429
+ return { lvlText, start: start2, numFmt, elements };
26430
+ };
26431
+ const getListNumIdFromAbstract = (abstractId, editor) => {
26432
+ const { definitions } = editor?.converter?.numbering;
26433
+ if (!definitions) return null;
26434
+ const matchedDefinition = Object.values(definitions).find((def2) => {
26435
+ return def2.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
26436
+ });
26437
+ return matchedDefinition?.attributes?.["w:numId"];
26438
+ };
26439
+ const getListAbstractDefinition = (abstractId, editor) => {
26440
+ const { abstracts = {} } = editor?.converter?.numbering;
26441
+ return abstracts[abstractId] || null;
26442
+ };
26443
+ const transformWordLists = (container) => {
26444
+ const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
26445
+ const listMap = /* @__PURE__ */ new Map();
26446
+ const listLevels = {};
26447
+ for (const p2 of paragraphs) {
26448
+ const listId = p2.getAttribute("data-num-id");
26449
+ const level = parseInt(p2.getAttribute("data-list-level"));
26450
+ const numFmt = p2.getAttribute("data-num-fmt");
26451
+ const start2 = p2.getAttribute("data-start");
26452
+ const lvlText = p2.getAttribute("data-lvl-text");
26453
+ if (!listMap.has(listId)) listMap.set(listId, []);
26454
+ listMap.get(listId).push({ p: p2, level, numFmt, start: start2, lvlText });
26455
+ }
26456
+ for (const [id, items] of listMap.entries()) {
26457
+ if (!listLevels[id]) {
26458
+ listLevels[id] = {
26459
+ stack: [],
26460
+ counts: {},
26461
+ prevLevel: null
26462
+ };
26463
+ }
26464
+ const parentStack = [];
26465
+ items.forEach(({ p: p2, level, numFmt, start: start2, lvlText }, index2) => {
26466
+ const listLevel = generateListNestingPath(listLevels, id, level);
26467
+ const li = document.createElement("li");
26468
+ li.innerHTML = p2.innerHTML;
26469
+ li.setAttribute("data-list-level", JSON.stringify(listLevel));
26470
+ li.setAttribute("data-num-id", id);
26471
+ li.setAttribute("data-lvl-text", lvlText);
26472
+ li.setAttribute("data-num-fmt", numFmt);
26473
+ if (p2.hasAttribute("data-font-family")) {
26474
+ li.setAttribute("data-font-family", p2.getAttribute("data-font-family"));
26475
+ }
26476
+ if (p2.hasAttribute("data-font-size")) {
26477
+ li.setAttribute("data-font-size", p2.getAttribute("data-font-size"));
26478
+ }
26479
+ const parentNode2 = p2.parentNode;
26480
+ let listForLevel = parentStack[level];
26481
+ if (!listForLevel) {
26482
+ const newList = document.createElement("ol");
26483
+ newList.setAttribute("data-list-id", id);
26484
+ newList.level = level;
26485
+ if (level > 0) {
26486
+ const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
26487
+ if (parentLi) parentLi.appendChild(newList);
26488
+ } else {
26489
+ parentNode2.insertBefore(newList, p2);
26490
+ }
26491
+ parentStack[level] = newList;
26492
+ parentStack.length = level + 1;
26493
+ listForLevel = newList;
26494
+ }
26495
+ listForLevel.appendChild(li);
26496
+ p2.remove();
26497
+ });
26498
+ }
26499
+ };
26500
+ function generateListNestingPath(listLevels, listId, currentLevel) {
26501
+ const levelState = listLevels[listId];
26502
+ if (!levelState.stack) levelState.stack = [];
26503
+ if (levelState.prevLevel === void 0) levelState.prevLevel = null;
26504
+ if (levelState.prevLevel === null) {
26505
+ levelState.stack = Array(currentLevel).fill(1).concat(1);
26506
+ } else {
26507
+ if (currentLevel > levelState.prevLevel) {
26508
+ levelState.stack.push(1);
26509
+ } else if (currentLevel === levelState.prevLevel) {
26510
+ levelState.stack[levelState.stack.length - 1]++;
26511
+ } else {
26512
+ levelState.stack = levelState.stack.slice(0, currentLevel + 1);
26513
+ levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
26514
+ }
26515
+ }
26516
+ levelState.prevLevel = currentLevel;
26517
+ return [...levelState.stack];
26518
+ }
26519
+ function extractAndRemoveConditionalPrefix(p2) {
26520
+ const nodes = Array.from(p2.childNodes);
26521
+ let fontFamily2 = null;
26522
+ let fontSize2 = null;
26523
+ let start2 = -1, end2 = -1;
26524
+ nodes.forEach((node2, index2) => {
26525
+ if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
26526
+ start2 = index2;
26527
+ }
26528
+ if (start2 !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
26529
+ end2 = index2;
26530
+ }
26531
+ });
26532
+ if (start2 !== -1 && end2 !== -1) {
26533
+ for (let i2 = start2 + 1; i2 < end2; i2++) {
26534
+ const node2 = nodes[i2];
26535
+ if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
26536
+ fontFamily2 = fontFamily2 || node2.style.fontFamily;
26537
+ fontSize2 = fontSize2 || node2.style.fontSize;
26538
+ }
26539
+ }
26540
+ for (let i2 = end2; i2 >= start2; i2--) {
26541
+ p2.removeChild(p2.childNodes[i2]);
26542
+ }
26543
+ if (fontFamily2) p2.setAttribute("data-font-family", fontFamily2);
26544
+ if (fontSize2) p2.setAttribute("data-font-size", fontSize2);
26545
+ }
26546
+ }
26547
+ class InputRule {
26548
+ constructor(config) {
26549
+ __publicField$2(this, "match");
26550
+ __publicField$2(this, "handler");
26551
+ this.match = config.match;
26552
+ this.handler = config.handler;
26553
+ }
26554
+ }
26555
+ const inputRuleMatcherHandler = (text, match) => {
26556
+ if (isRegExp(match)) {
26557
+ return match.exec(text);
26558
+ }
26559
+ const inputRuleMatch = match(text);
26560
+ if (!inputRuleMatch) {
26561
+ return null;
26562
+ }
26563
+ const result = [inputRuleMatch.text];
26564
+ result.index = inputRuleMatch.index;
26565
+ result.input = text;
26566
+ result.data = inputRuleMatch.data;
26567
+ if (inputRuleMatch.replaceWith) {
26568
+ if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
26569
+ console.warn(
26570
+ '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
26571
+ );
26572
+ }
26573
+ result.push(inputRuleMatch.replaceWith);
26574
+ }
26575
+ return result;
26576
+ };
26577
+ const run = (config) => {
26578
+ const {
26579
+ editor,
26580
+ from: from2,
26581
+ to,
26582
+ text,
26583
+ rules,
26584
+ plugin: plugin2
26585
+ } = config;
26586
+ const { view } = editor;
26587
+ if (view.composing) {
26588
+ return false;
26589
+ }
26590
+ const $from = view.state.doc.resolve(from2);
26591
+ if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
26592
+ return false;
26593
+ }
26594
+ let matched = false;
26595
+ const textBefore = getTextContentFromNodes($from) + text;
26596
+ rules.forEach((rule) => {
26597
+ if (matched) {
26598
+ return;
26599
+ }
26600
+ const match = inputRuleMatcherHandler(textBefore, rule.match);
26601
+ if (!match) {
26602
+ return;
26603
+ }
26604
+ const tr = view.state.tr;
26605
+ const state2 = chainableEditorState(tr, view.state);
26606
+ const range2 = {
26607
+ from: from2 - (match[0].length - text.length),
26608
+ to
26609
+ };
26610
+ const { commands: commands2, chain, can } = new CommandService({
26611
+ editor,
26612
+ state: state2
26613
+ });
26614
+ const handler = rule.handler({
26615
+ state: state2,
26616
+ range: range2,
26617
+ match,
26618
+ commands: commands2,
26619
+ chain,
26620
+ can
26621
+ });
26622
+ if (handler === null || !tr.steps.length) {
26623
+ return;
26624
+ }
26625
+ tr.setMeta(plugin2, {
26626
+ transform: tr,
26627
+ from: from2,
26628
+ to,
26629
+ text
26630
+ });
26631
+ view.dispatch(tr);
26632
+ matched = true;
26633
+ });
26634
+ return matched;
26635
+ };
26636
+ const inputRulesPlugin = ({ editor, rules }) => {
26637
+ const plugin2 = new Plugin({
26638
+ key: new PluginKey("inputRulesPlugin"),
26639
+ state: {
26640
+ init() {
26641
+ return null;
26642
+ },
26643
+ apply(tr, prev, state2) {
26644
+ const stored = tr.getMeta(plugin2);
26645
+ if (stored) {
26646
+ return stored;
26647
+ }
26648
+ const simulatedInputMeta = tr.getMeta("applyInputRules");
26649
+ const isSimulatedInput = !!simulatedInputMeta;
26650
+ if (isSimulatedInput) {
26651
+ setTimeout(() => {
26652
+ let { text } = simulatedInputMeta;
26653
+ if (typeof text !== "string") {
26654
+ text = getHTMLFromFragment(Fragment.from(text), state2.schema);
26655
+ }
26656
+ const { from: from2 } = simulatedInputMeta;
26657
+ const to = from2 + text.length;
26658
+ run({
26659
+ editor,
26660
+ from: from2,
26661
+ to,
26662
+ text,
26663
+ rules,
26664
+ plugin: plugin2
26665
+ });
26666
+ });
26667
+ }
26668
+ return tr.selectionSet || tr.docChanged ? null : prev;
26669
+ }
26670
+ },
26671
+ props: {
26672
+ handleTextInput(view, from2, to, text) {
26673
+ return run({
26674
+ editor,
26675
+ from: from2,
26676
+ to,
26677
+ text,
26678
+ rules,
26679
+ plugin: plugin2
26680
+ });
26681
+ },
26682
+ // add support for input rules to trigger on enter
26683
+ // this is useful for example for code blocks
26684
+ handleKeyDown(view, event) {
26685
+ if (event.key !== "Enter") {
26686
+ return false;
26687
+ }
26688
+ const { $cursor } = view.state.selection;
26689
+ if ($cursor) {
26690
+ return run({
26691
+ editor,
26692
+ from: $cursor.pos,
26693
+ to: $cursor.pos,
26694
+ text: "\n",
26695
+ rules,
26696
+ plugin: plugin2
26697
+ });
26698
+ }
26699
+ return false;
26700
+ },
26701
+ // Paste handler
26702
+ handlePaste(view, event, slice) {
26703
+ const clipboard = event.clipboardData;
26704
+ const html = clipboard.getData("text/html");
26705
+ clipboard.getData("text/plain");
26706
+ const fieldAnnotationContent = slice.content.content.filter((item) => item.type.name === "fieldAnnotation");
26707
+ if (fieldAnnotationContent.length) {
26708
+ return false;
26709
+ }
26710
+ let source;
26711
+ if (!html) {
26712
+ source = "plain-text";
26713
+ } else if (isWordHtml(html)) {
26714
+ source = "word-html";
26715
+ } else {
26716
+ source = "browser-html";
26717
+ }
26718
+ switch (source) {
26719
+ case "plain-text":
26720
+ break;
26721
+ case "word-html":
26722
+ if (editor.options.mode === "docx") {
26723
+ return handleDocxPaste(html, editor, view, plugin2);
26724
+ }
26725
+ case "browser-html":
26726
+ return handleHtmlPaste$1(html, editor);
26727
+ }
26728
+ return false;
26729
+ }
26730
+ },
26731
+ isInputRules: true
26732
+ });
26733
+ return plugin2;
26734
+ };
26735
+ function isWordHtml(html) {
26736
+ return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
26737
+ }
26738
+ const handleHtmlPaste$1 = (html, editor, plugin2) => {
26739
+ const htmlWithPtSizing = convertEmToPt(html);
26740
+ const cleanedHtml = sanitizeHtml(htmlWithPtSizing);
26741
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(cleanedHtml);
26742
+ const { dispatch } = editor.view;
26743
+ if (!dispatch) return false;
26744
+ dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
26745
+ return true;
26746
+ };
26747
+ const convertEmToPt = (html) => {
26748
+ return html.replace(
26749
+ /font-size\s*:\s*([\d.]+)em/gi,
26750
+ (_, emValue) => {
26751
+ const em = parseFloat(emValue);
26752
+ const pt = Math.round(em * 12 * 100) / 100;
26753
+ return `font-size: ${pt}pt`;
26754
+ }
26755
+ );
26756
+ };
26757
+ function cleanHtmlUnnecessaryTags(html) {
26758
+ return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
26759
+ }
26760
+ function sanitizeHtml(html, forbiddenTags = ["meta", "svg", "script", "style", "button"]) {
26761
+ const container = document.createElement("div");
26762
+ container.innerHTML = html;
26763
+ const walkAndClean = (node2) => {
26764
+ for (const child of [...node2.children]) {
26765
+ if (forbiddenTags.includes(child.tagName.toLowerCase())) {
26766
+ child.remove();
26767
+ continue;
26768
+ }
26769
+ if (child.hasAttribute("linebreaktype")) {
26770
+ child.removeAttribute("linebreaktype");
26771
+ }
26772
+ walkAndClean(child);
26773
+ }
26774
+ };
26775
+ walkAndClean(container);
26776
+ return container;
26777
+ }
26201
26778
  function exportSchemaToJson(params2) {
26202
26779
  const { type: type2 } = params2.node || {};
26203
26780
  const router = {
@@ -27316,7 +27893,7 @@
27316
27893
  attributes: {
27317
27894
  relativeFrom: attrs.anchorData.hRelativeFrom
27318
27895
  },
27319
- ...attrs.marginOffset.left && {
27896
+ ...attrs.marginOffset.left !== void 0 && {
27320
27897
  elements: [{
27321
27898
  name: "wp:posOffset",
27322
27899
  elements: [{
@@ -27340,7 +27917,7 @@
27340
27917
  attributes: {
27341
27918
  relativeFrom: attrs.anchorData.vRelativeFrom
27342
27919
  },
27343
- ...attrs.marginOffset.top && {
27920
+ ...attrs.marginOffset.top !== void 0 && {
27344
27921
  elements: [{
27345
27922
  name: "wp:posOffset",
27346
27923
  elements: [{
@@ -27541,12 +28118,11 @@
27541
28118
  node: { attrs = {}, marks = [] },
27542
28119
  editorSchema
27543
28120
  } = params2;
27544
- const parser = new window.DOMParser();
27545
- const paragraphHtml = parser.parseFromString(attrs.rawHtml || attrs.displayLabel, "text/html");
28121
+ const paragraphHtmlContainer = sanitizeHtml(attrs.rawHtml);
27546
28122
  const marksFromAttrs = translateFieldAttrsToMarks(attrs);
27547
28123
  const allMarks = [...marks, ...marksFromAttrs];
27548
28124
  let state2 = EditorState.create({
27549
- doc: DOMParser$1.fromSchema(editorSchema).parse(paragraphHtml)
28125
+ doc: DOMParser$1.fromSchema(editorSchema).parse(paragraphHtmlContainer)
27550
28126
  });
27551
28127
  if (allMarks.length) {
27552
28128
  state2 = applyMarksToHtmlAnnotation(state2, allMarks);
@@ -27635,6 +28211,7 @@
27635
28211
  sdtContentElements = [...processedNode.elements];
27636
28212
  }
27637
28213
  }
28214
+ sdtContentElements = [getFieldHighlightJson(), ...sdtContentElements];
27638
28215
  const customXmlns = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
27639
28216
  return {
27640
28217
  name: "w:sdt",
@@ -27996,6 +28573,21 @@
27996
28573
  }
27997
28574
  ];
27998
28575
  };
28576
+ const getFieldHighlightJson = () => {
28577
+ return {
28578
+ "name": "w:rPr",
28579
+ "elements": [
28580
+ {
28581
+ "name": "w:shd",
28582
+ "attributes": {
28583
+ "w:fill": "7AA6FF",
28584
+ "w:color": "auto",
28585
+ "w:val": "clear"
28586
+ }
28587
+ }
28588
+ ]
28589
+ };
28590
+ };
27999
28591
  const defaultInitialXml = `<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14"><w:body></w:body></w:document>`;
28000
28592
  const parseXmlToJson = (xml) => {
28001
28593
  return JSON.parse(xmljs.xml2json(xml, null, 2));
@@ -28380,10 +28972,10 @@
28380
28972
  const hRelativeFrom = positionHTag?.attributes.relativeFrom;
28381
28973
  const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
28382
28974
  const positionVTag = node2.elements.find((el) => el.name === "wp:positionV");
28383
- const positionV = positionVTag?.elements.find((el) => el.name === "wp:posOffset");
28975
+ const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
28384
28976
  const positionVValue = emuToPixels(positionV?.elements[0]?.text);
28385
28977
  const vRelativeFrom = positionVTag?.attributes.relativeFrom;
28386
- const alignV = positionVTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
28978
+ const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
28387
28979
  const simplePos = node2.elements.find((el) => el.name === "wp:simplePos");
28388
28980
  const wrapSquare = node2.elements.find((el) => el.name === "wp:wrapSquare");
28389
28981
  const wrapTopAndBottom = node2.elements.find((el) => el.name === "wp:wrapTopAndBottom");
@@ -30773,7 +31365,7 @@
30773
31365
  return;
30774
31366
  }
30775
31367
  }
30776
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.3") {
31368
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.4") {
30777
31369
  const customLocation = "docProps/custom.xml";
30778
31370
  if (!docx[customLocation]) {
30779
31371
  docx[customLocation] = generateCustomXml();
@@ -31240,7 +31832,7 @@
31240
31832
  function generateCustomXml() {
31241
31833
  return DEFAULT_CUSTOM_XML;
31242
31834
  }
31243
- function generateSuperdocVersion(pid = 2, version2 = "0.13.3") {
31835
+ function generateSuperdocVersion(pid = 2, version2 = "0.13.4") {
31244
31836
  return {
31245
31837
  type: "element",
31246
31838
  name: "property",
@@ -34962,164 +35554,6 @@
34962
35554
  };
34963
35555
  __privateAdd$1(_Schema, _Schema_static);
34964
35556
  let Schema = _Schema;
34965
- function chainableEditorState(transaction, state2) {
34966
- let { selection, doc: doc2, storedMarks } = transaction;
34967
- return {
34968
- ...state2,
34969
- apply: state2.apply.bind(state2),
34970
- applyTransaction: state2.applyTransaction.bind(state2),
34971
- plugins: state2.plugins,
34972
- schema: state2.schema,
34973
- reconfigure: state2.reconfigure.bind(state2),
34974
- toJSON: state2.toJSON.bind(state2),
34975
- get storedMarks() {
34976
- return storedMarks;
34977
- },
34978
- get selection() {
34979
- return selection;
34980
- },
34981
- get doc() {
34982
- return doc2;
34983
- },
34984
- get tr() {
34985
- selection = transaction.selection;
34986
- doc2 = transaction.doc;
34987
- storedMarks = transaction.storedMarks;
34988
- return transaction;
34989
- }
34990
- };
34991
- }
34992
- class CommandService {
34993
- constructor(props) {
34994
- __publicField$1(this, "editor");
34995
- __publicField$1(this, "rawCommands");
34996
- this.editor = props.editor;
34997
- this.rawCommands = this.editor.extensionService.commands;
34998
- }
34999
- /**
35000
- * Static method for creating a service.
35001
- * @param args Arguments for the constructor.
35002
- */
35003
- static create(...args) {
35004
- return new CommandService(...args);
35005
- }
35006
- /**
35007
- * Get editor state.
35008
- */
35009
- get state() {
35010
- return this.editor.state;
35011
- }
35012
- /**
35013
- * Get all commands with wrapped command method.
35014
- */
35015
- get commands() {
35016
- const { editor, state: state2 } = this;
35017
- const { view } = editor;
35018
- const { tr } = state2;
35019
- const props = this.createProps(tr);
35020
- const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
35021
- const method = (...args) => {
35022
- const fn2 = command2(...args)(props);
35023
- if (!tr.getMeta("preventDispatch")) {
35024
- view.dispatch(tr);
35025
- }
35026
- return fn2;
35027
- };
35028
- return [name, method];
35029
- });
35030
- return Object.fromEntries(entries);
35031
- }
35032
- /**
35033
- * Create a chain of commands to call multiple commands at once.
35034
- */
35035
- get chain() {
35036
- return () => this.createChain();
35037
- }
35038
- /**
35039
- * Check if a command or a chain of commands can be executed. Without executing it.
35040
- */
35041
- get can() {
35042
- return () => this.createCan();
35043
- }
35044
- /**
35045
- * Creates a chain of commands.
35046
- * @param startTr Start transaction.
35047
- * @param shouldDispatch Should dispatch or not.
35048
- */
35049
- createChain(startTr, shouldDispatch = true) {
35050
- const { editor, state: state2, rawCommands } = this;
35051
- const { view } = editor;
35052
- const callbacks2 = [];
35053
- const hasStartTr = !!startTr;
35054
- const tr = startTr || state2.tr;
35055
- const run2 = () => {
35056
- if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
35057
- view.dispatch(tr);
35058
- }
35059
- return callbacks2.every((cb) => cb === true);
35060
- };
35061
- const entries = Object.entries(rawCommands).map(([name, command2]) => {
35062
- const chainedCommand = (...args) => {
35063
- const props = this.createProps(tr, shouldDispatch);
35064
- const callback = command2(...args)(props);
35065
- callbacks2.push(callback);
35066
- return chain;
35067
- };
35068
- return [name, chainedCommand];
35069
- });
35070
- const chain = {
35071
- ...Object.fromEntries(entries),
35072
- run: run2
35073
- };
35074
- return chain;
35075
- }
35076
- /**
35077
- * Creates a can check for commands.
35078
- * @param startTr Start transaction.
35079
- */
35080
- createCan(startTr) {
35081
- const { rawCommands, state: state2 } = this;
35082
- const dispatch = false;
35083
- const tr = startTr || state2.tr;
35084
- const props = this.createProps(tr, dispatch);
35085
- const commands2 = Object.fromEntries(
35086
- Object.entries(rawCommands).map(([name, command2]) => {
35087
- return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
35088
- })
35089
- );
35090
- return {
35091
- ...commands2,
35092
- chain: () => this.createChain(tr, dispatch)
35093
- };
35094
- }
35095
- /**
35096
- * Creates default props for the command method.
35097
- * @param {*} tr Transaction.
35098
- * @param {*} shouldDispatch Check if should dispatch.
35099
- * @returns Object with props.
35100
- */
35101
- createProps(tr, shouldDispatch = true) {
35102
- const { editor, state: state2, rawCommands } = this;
35103
- const { view } = editor;
35104
- const props = {
35105
- tr,
35106
- editor,
35107
- view,
35108
- state: chainableEditorState(tr, state2),
35109
- dispatch: shouldDispatch ? () => void 0 : void 0,
35110
- chain: () => this.createChain(tr, shouldDispatch),
35111
- can: () => this.createCan(tr),
35112
- get commands() {
35113
- return Object.fromEntries(
35114
- Object.entries(rawCommands).map(([name, command2]) => {
35115
- return [name, (...args) => command2(...args)(props)];
35116
- })
35117
- );
35118
- }
35119
- };
35120
- return props;
35121
- }
35122
- }
35123
35557
  const first = (commands2) => (props) => {
35124
35558
  const items = typeof commands2 === "function" ? commands2(props) : commands2;
35125
35559
  for (let i2 = 0; i2 < items.length; i2 += 1) {
@@ -45134,630 +45568,227 @@
45134
45568
  * Remove a specific callback from event
45135
45569
  * or all event subscriptions.
45136
45570
  * @param {string} name Event name.
45137
- * @param {(...args: any[]) => void} fn Callback.
45138
- * @returns {void}
45139
- */
45140
- off(name, fn2) {
45141
- const callbacks2 = __privateGet$1(this, _events).get(name);
45142
- if (!callbacks2) return;
45143
- if (fn2) {
45144
- __privateGet$1(this, _events).set(
45145
- name,
45146
- callbacks2.filter((cb) => cb !== fn2)
45147
- );
45148
- } else {
45149
- __privateGet$1(this, _events).delete(name);
45150
- }
45151
- }
45152
- /**
45153
- * Subscribe to an event that will be called only once.
45154
- * @param {string} name Event name.
45155
- * @param {(...args: any[]) => void} fn Callback.
45156
- * @returns {void}
45157
- */
45158
- once(name, fn2) {
45159
- const wrapper = (...args) => {
45160
- this.off(name, wrapper);
45161
- fn2.apply(this, args);
45162
- };
45163
- this.on(name, wrapper);
45164
- }
45165
- /**
45166
- * Remove all registered events and subscriptions.
45167
- */
45168
- removeAllListeners() {
45169
- __privateSet(this, _events, /* @__PURE__ */ new Map());
45170
- }
45171
- };
45172
- _events = /* @__PURE__ */ new WeakMap();
45173
- var base$2 = {
45174
- 8: "Backspace",
45175
- 9: "Tab",
45176
- 10: "Enter",
45177
- 12: "NumLock",
45178
- 13: "Enter",
45179
- 16: "Shift",
45180
- 17: "Control",
45181
- 18: "Alt",
45182
- 20: "CapsLock",
45183
- 27: "Escape",
45184
- 32: " ",
45185
- 33: "PageUp",
45186
- 34: "PageDown",
45187
- 35: "End",
45188
- 36: "Home",
45189
- 37: "ArrowLeft",
45190
- 38: "ArrowUp",
45191
- 39: "ArrowRight",
45192
- 40: "ArrowDown",
45193
- 44: "PrintScreen",
45194
- 45: "Insert",
45195
- 46: "Delete",
45196
- 59: ";",
45197
- 61: "=",
45198
- 91: "Meta",
45199
- 92: "Meta",
45200
- 106: "*",
45201
- 107: "+",
45202
- 108: ",",
45203
- 109: "-",
45204
- 110: ".",
45205
- 111: "/",
45206
- 144: "NumLock",
45207
- 145: "ScrollLock",
45208
- 160: "Shift",
45209
- 161: "Shift",
45210
- 162: "Control",
45211
- 163: "Control",
45212
- 164: "Alt",
45213
- 165: "Alt",
45214
- 173: "-",
45215
- 186: ";",
45216
- 187: "=",
45217
- 188: ",",
45218
- 189: "-",
45219
- 190: ".",
45220
- 191: "/",
45221
- 192: "`",
45222
- 219: "[",
45223
- 220: "\\",
45224
- 221: "]",
45225
- 222: "'"
45226
- };
45227
- var shift = {
45228
- 48: ")",
45229
- 49: "!",
45230
- 50: "@",
45231
- 51: "#",
45232
- 52: "$",
45233
- 53: "%",
45234
- 54: "^",
45235
- 55: "&",
45236
- 56: "*",
45237
- 57: "(",
45238
- 59: ":",
45239
- 61: "+",
45240
- 173: "_",
45241
- 186: ":",
45242
- 187: "+",
45243
- 188: "<",
45244
- 189: "_",
45245
- 190: ">",
45246
- 191: "?",
45247
- 192: "~",
45248
- 219: "{",
45249
- 220: "|",
45250
- 221: "}",
45251
- 222: '"'
45252
- };
45253
- var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
45254
- var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
45255
- for (var i$1 = 0; i$1 < 10; i$1++) base$2[48 + i$1] = base$2[96 + i$1] = String(i$1);
45256
- for (var i$1 = 1; i$1 <= 24; i$1++) base$2[i$1 + 111] = "F" + i$1;
45257
- for (var i$1 = 65; i$1 <= 90; i$1++) {
45258
- base$2[i$1] = String.fromCharCode(i$1 + 32);
45259
- shift[i$1] = String.fromCharCode(i$1);
45260
- }
45261
- for (var code in base$2) if (!shift.hasOwnProperty(code)) shift[code] = base$2[code];
45262
- function keyName(event) {
45263
- var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified";
45264
- var name = !ignoreKey && event.key || (event.shiftKey ? shift : base$2)[event.keyCode] || event.key || "Unidentified";
45265
- if (name == "Esc") name = "Escape";
45266
- if (name == "Del") name = "Delete";
45267
- if (name == "Left") name = "ArrowLeft";
45268
- if (name == "Up") name = "ArrowUp";
45269
- if (name == "Right") name = "ArrowRight";
45270
- if (name == "Down") name = "ArrowDown";
45271
- return name;
45272
- }
45273
- const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
45274
- const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
45275
- function normalizeKeyName(name) {
45276
- let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
45277
- if (result == "Space")
45278
- result = " ";
45279
- let alt, ctrl, shift2, meta;
45280
- for (let i2 = 0; i2 < parts.length - 1; i2++) {
45281
- let mod = parts[i2];
45282
- if (/^(cmd|meta|m)$/i.test(mod))
45283
- meta = true;
45284
- else if (/^a(lt)?$/i.test(mod))
45285
- alt = true;
45286
- else if (/^(c|ctrl|control)$/i.test(mod))
45287
- ctrl = true;
45288
- else if (/^s(hift)?$/i.test(mod))
45289
- shift2 = true;
45290
- else if (/^mod$/i.test(mod)) {
45291
- if (mac)
45292
- meta = true;
45293
- else
45294
- ctrl = true;
45295
- } else
45296
- throw new Error("Unrecognized modifier name: " + mod);
45297
- }
45298
- if (alt)
45299
- result = "Alt-" + result;
45300
- if (ctrl)
45301
- result = "Ctrl-" + result;
45302
- if (meta)
45303
- result = "Meta-" + result;
45304
- if (shift2)
45305
- result = "Shift-" + result;
45306
- return result;
45307
- }
45308
- function normalize(map2) {
45309
- let copy2 = /* @__PURE__ */ Object.create(null);
45310
- for (let prop in map2)
45311
- copy2[normalizeKeyName(prop)] = map2[prop];
45312
- return copy2;
45313
- }
45314
- function modifiers(name, event, shift2 = true) {
45315
- if (event.altKey)
45316
- name = "Alt-" + name;
45317
- if (event.ctrlKey)
45318
- name = "Ctrl-" + name;
45319
- if (event.metaKey)
45320
- name = "Meta-" + name;
45321
- if (shift2 && event.shiftKey)
45322
- name = "Shift-" + name;
45323
- return name;
45324
- }
45325
- function keymap(bindings) {
45326
- return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
45327
- }
45328
- function keydownHandler(bindings) {
45329
- let map2 = normalize(bindings);
45330
- return function(view, event) {
45331
- let name = keyName(event), baseName, direct = map2[modifiers(name, event)];
45332
- if (direct && direct(view.state, view.dispatch, view))
45333
- return true;
45334
- if (name.length == 1 && name != " ") {
45335
- if (event.shiftKey) {
45336
- let noShift = map2[modifiers(name, event, false)];
45337
- if (noShift && noShift(view.state, view.dispatch, view))
45338
- return true;
45339
- }
45340
- if ((event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
45341
- !(windows && event.ctrlKey && event.altKey) && (baseName = base$2[event.keyCode]) && baseName != name) {
45342
- let fromCode = map2[modifiers(baseName, event)];
45343
- if (fromCode && fromCode(view.state, view.dispatch, view))
45344
- return true;
45345
- }
45346
- }
45347
- return false;
45348
- };
45349
- }
45350
- function isExtensionRulesEnabled(extension, enabled) {
45351
- if (Array.isArray(enabled)) {
45352
- return enabled.some((enabledExtension) => {
45353
- const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
45354
- return name === extension.name;
45355
- });
45356
- }
45357
- return enabled;
45358
- }
45359
- function getHTMLFromFragment(fragment, schema) {
45360
- const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
45361
- const temporaryDocument = document.implementation.createHTMLDocument();
45362
- const container = temporaryDocument.createElement("div");
45363
- container.appendChild(documentFragment);
45364
- return container.innerHTML;
45365
- }
45366
- const getTextContentFromNodes = ($from, maxMatch = 500) => {
45367
- let textBefore = "";
45368
- const sliceEndPos = $from.parentOffset;
45369
- $from.parent.nodesBetween(
45370
- Math.max(0, sliceEndPos - maxMatch),
45371
- sliceEndPos,
45372
- (node2, pos, parent, index2) => {
45373
- const chunk = node2.type.spec.toText?.({
45374
- node: node2,
45375
- pos,
45376
- parent,
45377
- index: index2
45378
- }) || node2.textContent || "%leaf%";
45379
- textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
45380
- }
45381
- );
45382
- return textBefore;
45383
- };
45384
- const handleDocxPaste = (html, editor, view, plugin2) => {
45385
- const { converter } = editor;
45386
- if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin2);
45387
- let cleanedHtml = convertEmToPt(html);
45388
- cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
45389
- const tempDiv = document.createElement("div");
45390
- tempDiv.innerHTML = cleanedHtml;
45391
- const paragraphs = tempDiv.querySelectorAll("p");
45392
- paragraphs.forEach((p2) => {
45393
- const innerHTML3 = p2.innerHTML;
45394
- if (!innerHTML3.includes("<!--[if !supportLists]")) return;
45395
- const styleAttr = p2.getAttribute("style") || "";
45396
- const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
45397
- if (msoListMatch) {
45398
- const [, abstractId, level] = msoListMatch;
45399
- const listNumId = getListNumIdFromAbstract(abstractId, editor);
45400
- if (!listNumId) return;
45401
- const abstractDefinition = getListAbstractDefinition(abstractId, editor);
45402
- const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
45403
- p2.setAttribute("data-num-id", listNumId);
45404
- p2.setAttribute("data-list-level", level - 1);
45405
- p2.setAttribute("data-start", start2);
45406
- p2.setAttribute("data-lvl-text", lvlText);
45407
- p2.setAttribute("data-num-fmt", numFmt);
45408
- }
45409
- extractAndRemoveConditionalPrefix(p2);
45410
- });
45411
- transformWordLists(tempDiv);
45412
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
45413
- tempDiv.remove();
45414
- const { dispatch } = editor.view;
45415
- if (!dispatch) return false;
45416
- dispatch(view.state.tr.replaceSelectionWith(doc2, true));
45417
- return true;
45418
- };
45419
- const getLevelDefinition = (abstractDefinition, level) => {
45420
- if (!abstractDefinition || !abstractDefinition.elements) return null;
45421
- const levelElement = abstractDefinition.elements.find((el) => {
45422
- return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
45423
- });
45424
- if (!levelElement) return null;
45425
- const { elements } = levelElement;
45426
- const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
45427
- const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
45428
- const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
45429
- return { lvlText, start: start2, numFmt, elements };
45430
- };
45431
- const getListNumIdFromAbstract = (abstractId, editor) => {
45432
- const { definitions } = editor?.converter?.numbering;
45433
- if (!definitions) return null;
45434
- const matchedDefinition = Object.values(definitions).find((def2) => {
45435
- return def2.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
45436
- });
45437
- return matchedDefinition?.attributes?.["w:numId"];
45438
- };
45439
- const getListAbstractDefinition = (abstractId, editor) => {
45440
- const { abstracts = {} } = editor?.converter?.numbering;
45441
- return abstracts[abstractId] || null;
45442
- };
45443
- const transformWordLists = (container) => {
45444
- const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
45445
- const listMap = /* @__PURE__ */ new Map();
45446
- const listLevels = {};
45447
- for (const p2 of paragraphs) {
45448
- const listId = p2.getAttribute("data-num-id");
45449
- const level = parseInt(p2.getAttribute("data-list-level"));
45450
- const numFmt = p2.getAttribute("data-num-fmt");
45451
- const start2 = p2.getAttribute("data-start");
45452
- const lvlText = p2.getAttribute("data-lvl-text");
45453
- if (!listMap.has(listId)) listMap.set(listId, []);
45454
- listMap.get(listId).push({ p: p2, level, numFmt, start: start2, lvlText });
45455
- }
45456
- for (const [id, items] of listMap.entries()) {
45457
- if (!listLevels[id]) {
45458
- listLevels[id] = {
45459
- stack: [],
45460
- counts: {},
45461
- prevLevel: null
45462
- };
45463
- }
45464
- const parentStack = [];
45465
- items.forEach(({ p: p2, level, numFmt, start: start2, lvlText }, index2) => {
45466
- const listLevel = generateListNestingPath(listLevels, id, level);
45467
- const li = document.createElement("li");
45468
- li.innerHTML = p2.innerHTML;
45469
- li.setAttribute("data-list-level", JSON.stringify(listLevel));
45470
- li.setAttribute("data-num-id", id);
45471
- li.setAttribute("data-lvl-text", lvlText);
45472
- li.setAttribute("data-num-fmt", numFmt);
45473
- if (p2.hasAttribute("data-font-family")) {
45474
- li.setAttribute("data-font-family", p2.getAttribute("data-font-family"));
45475
- }
45476
- if (p2.hasAttribute("data-font-size")) {
45477
- li.setAttribute("data-font-size", p2.getAttribute("data-font-size"));
45478
- }
45479
- const parentNode2 = p2.parentNode;
45480
- let listForLevel = parentStack[level];
45481
- if (!listForLevel) {
45482
- const newList = document.createElement("ol");
45483
- newList.setAttribute("data-list-id", id);
45484
- newList.level = level;
45485
- if (level > 0) {
45486
- const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
45487
- if (parentLi) parentLi.appendChild(newList);
45488
- } else {
45489
- parentNode2.insertBefore(newList, p2);
45490
- }
45491
- parentStack[level] = newList;
45492
- parentStack.length = level + 1;
45493
- listForLevel = newList;
45494
- }
45495
- listForLevel.appendChild(li);
45496
- p2.remove();
45497
- });
45498
- }
45499
- };
45500
- function generateListNestingPath(listLevels, listId, currentLevel) {
45501
- const levelState = listLevels[listId];
45502
- if (!levelState.stack) levelState.stack = [];
45503
- if (levelState.prevLevel === void 0) levelState.prevLevel = null;
45504
- if (levelState.prevLevel === null) {
45505
- levelState.stack = Array(currentLevel).fill(1).concat(1);
45506
- } else {
45507
- if (currentLevel > levelState.prevLevel) {
45508
- levelState.stack.push(1);
45509
- } else if (currentLevel === levelState.prevLevel) {
45510
- levelState.stack[levelState.stack.length - 1]++;
45511
- } else {
45512
- levelState.stack = levelState.stack.slice(0, currentLevel + 1);
45513
- levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
45514
- }
45515
- }
45516
- levelState.prevLevel = currentLevel;
45517
- return [...levelState.stack];
45518
- }
45519
- function extractAndRemoveConditionalPrefix(p2) {
45520
- const nodes = Array.from(p2.childNodes);
45521
- let fontFamily2 = null;
45522
- let fontSize2 = null;
45523
- let start2 = -1, end2 = -1;
45524
- nodes.forEach((node2, index2) => {
45525
- if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
45526
- start2 = index2;
45527
- }
45528
- if (start2 !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
45529
- end2 = index2;
45530
- }
45531
- });
45532
- if (start2 !== -1 && end2 !== -1) {
45533
- for (let i2 = start2 + 1; i2 < end2; i2++) {
45534
- const node2 = nodes[i2];
45535
- if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
45536
- fontFamily2 = fontFamily2 || node2.style.fontFamily;
45537
- fontSize2 = fontSize2 || node2.style.fontSize;
45538
- }
45539
- }
45540
- for (let i2 = end2; i2 >= start2; i2--) {
45541
- p2.removeChild(p2.childNodes[i2]);
45542
- }
45543
- if (fontFamily2) p2.setAttribute("data-font-family", fontFamily2);
45544
- if (fontSize2) p2.setAttribute("data-font-size", fontSize2);
45545
- }
45546
- }
45547
- class InputRule {
45548
- constructor(config) {
45549
- __publicField$1(this, "match");
45550
- __publicField$1(this, "handler");
45551
- this.match = config.match;
45552
- this.handler = config.handler;
45553
- }
45554
- }
45555
- const inputRuleMatcherHandler = (text, match) => {
45556
- if (isRegExp(match)) {
45557
- return match.exec(text);
45558
- }
45559
- const inputRuleMatch = match(text);
45560
- if (!inputRuleMatch) {
45561
- return null;
45562
- }
45563
- const result = [inputRuleMatch.text];
45564
- result.index = inputRuleMatch.index;
45565
- result.input = text;
45566
- result.data = inputRuleMatch.data;
45567
- if (inputRuleMatch.replaceWith) {
45568
- if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
45569
- console.warn(
45570
- '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
45571
+ * @param {(...args: any[]) => void} fn Callback.
45572
+ * @returns {void}
45573
+ */
45574
+ off(name, fn2) {
45575
+ const callbacks2 = __privateGet$1(this, _events).get(name);
45576
+ if (!callbacks2) return;
45577
+ if (fn2) {
45578
+ __privateGet$1(this, _events).set(
45579
+ name,
45580
+ callbacks2.filter((cb) => cb !== fn2)
45571
45581
  );
45582
+ } else {
45583
+ __privateGet$1(this, _events).delete(name);
45572
45584
  }
45573
- result.push(inputRuleMatch.replaceWith);
45574
45585
  }
45575
- return result;
45576
- };
45577
- const run = (config) => {
45578
- const {
45579
- editor,
45580
- from: from2,
45581
- to,
45582
- text,
45583
- rules,
45584
- plugin: plugin2
45585
- } = config;
45586
- const { view } = editor;
45587
- if (view.composing) {
45588
- return false;
45586
+ /**
45587
+ * Subscribe to an event that will be called only once.
45588
+ * @param {string} name Event name.
45589
+ * @param {(...args: any[]) => void} fn Callback.
45590
+ * @returns {void}
45591
+ */
45592
+ once(name, fn2) {
45593
+ const wrapper = (...args) => {
45594
+ this.off(name, wrapper);
45595
+ fn2.apply(this, args);
45596
+ };
45597
+ this.on(name, wrapper);
45589
45598
  }
45590
- const $from = view.state.doc.resolve(from2);
45591
- if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
45592
- return false;
45599
+ /**
45600
+ * Remove all registered events and subscriptions.
45601
+ */
45602
+ removeAllListeners() {
45603
+ __privateSet(this, _events, /* @__PURE__ */ new Map());
45593
45604
  }
45594
- let matched = false;
45595
- const textBefore = getTextContentFromNodes($from) + text;
45596
- rules.forEach((rule) => {
45597
- if (matched) {
45598
- return;
45599
- }
45600
- const match = inputRuleMatcherHandler(textBefore, rule.match);
45601
- if (!match) {
45602
- return;
45603
- }
45604
- const tr = view.state.tr;
45605
- const state2 = chainableEditorState(tr, view.state);
45606
- const range2 = {
45607
- from: from2 - (match[0].length - text.length),
45608
- to
45609
- };
45610
- const { commands: commands2, chain, can } = new CommandService({
45611
- editor,
45612
- state: state2
45613
- });
45614
- const handler = rule.handler({
45615
- state: state2,
45616
- range: range2,
45617
- match,
45618
- commands: commands2,
45619
- chain,
45620
- can
45621
- });
45622
- if (handler === null || !tr.steps.length) {
45623
- return;
45624
- }
45625
- tr.setMeta(plugin2, {
45626
- transform: tr,
45627
- from: from2,
45628
- to,
45629
- text
45630
- });
45631
- view.dispatch(tr);
45632
- matched = true;
45633
- });
45634
- return matched;
45635
45605
  };
45636
- const inputRulesPlugin = ({ editor, rules }) => {
45637
- const plugin2 = new Plugin({
45638
- key: new PluginKey("inputRulesPlugin"),
45639
- state: {
45640
- init() {
45641
- return null;
45642
- },
45643
- apply(tr, prev, state2) {
45644
- const stored = tr.getMeta(plugin2);
45645
- if (stored) {
45646
- return stored;
45647
- }
45648
- const simulatedInputMeta = tr.getMeta("applyInputRules");
45649
- const isSimulatedInput = !!simulatedInputMeta;
45650
- if (isSimulatedInput) {
45651
- setTimeout(() => {
45652
- let { text } = simulatedInputMeta;
45653
- if (typeof text !== "string") {
45654
- text = getHTMLFromFragment(Fragment.from(text), state2.schema);
45655
- }
45656
- const { from: from2 } = simulatedInputMeta;
45657
- const to = from2 + text.length;
45658
- run({
45659
- editor,
45660
- from: from2,
45661
- to,
45662
- text,
45663
- rules,
45664
- plugin: plugin2
45665
- });
45666
- });
45667
- }
45668
- return tr.selectionSet || tr.docChanged ? null : prev;
45669
- }
45670
- },
45671
- props: {
45672
- handleTextInput(view, from2, to, text) {
45673
- return run({
45674
- editor,
45675
- from: from2,
45676
- to,
45677
- text,
45678
- rules,
45679
- plugin: plugin2
45680
- });
45681
- },
45682
- // add support for input rules to trigger on enter
45683
- // this is useful for example for code blocks
45684
- handleKeyDown(view, event) {
45685
- if (event.key !== "Enter") {
45686
- return false;
45687
- }
45688
- const { $cursor } = view.state.selection;
45689
- if ($cursor) {
45690
- return run({
45691
- editor,
45692
- from: $cursor.pos,
45693
- to: $cursor.pos,
45694
- text: "\n",
45695
- rules,
45696
- plugin: plugin2
45697
- });
45698
- }
45699
- return false;
45700
- },
45701
- // Paste handler
45702
- handlePaste(view, event, slice2) {
45703
- const clipboard = event.clipboardData;
45704
- const html = clipboard.getData("text/html");
45705
- clipboard.getData("text/plain");
45706
- const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
45707
- if (fieldAnnotationContent.length) {
45708
- return false;
45709
- }
45710
- let source;
45711
- if (!html) {
45712
- source = "plain-text";
45713
- } else if (isWordHtml(html)) {
45714
- source = "word-html";
45715
- } else {
45716
- source = "browser-html";
45717
- }
45718
- switch (source) {
45719
- case "plain-text":
45720
- break;
45721
- case "word-html":
45722
- if (editor.options.mode === "docx") {
45723
- return handleDocxPaste(html, editor, view, plugin2);
45724
- }
45725
- case "browser-html":
45726
- return handleHtmlPaste$1(html, editor);
45727
- }
45728
- return false;
45729
- }
45730
- },
45731
- isInputRules: true
45732
- });
45733
- return plugin2;
45606
+ _events = /* @__PURE__ */ new WeakMap();
45607
+ var base$2 = {
45608
+ 8: "Backspace",
45609
+ 9: "Tab",
45610
+ 10: "Enter",
45611
+ 12: "NumLock",
45612
+ 13: "Enter",
45613
+ 16: "Shift",
45614
+ 17: "Control",
45615
+ 18: "Alt",
45616
+ 20: "CapsLock",
45617
+ 27: "Escape",
45618
+ 32: " ",
45619
+ 33: "PageUp",
45620
+ 34: "PageDown",
45621
+ 35: "End",
45622
+ 36: "Home",
45623
+ 37: "ArrowLeft",
45624
+ 38: "ArrowUp",
45625
+ 39: "ArrowRight",
45626
+ 40: "ArrowDown",
45627
+ 44: "PrintScreen",
45628
+ 45: "Insert",
45629
+ 46: "Delete",
45630
+ 59: ";",
45631
+ 61: "=",
45632
+ 91: "Meta",
45633
+ 92: "Meta",
45634
+ 106: "*",
45635
+ 107: "+",
45636
+ 108: ",",
45637
+ 109: "-",
45638
+ 110: ".",
45639
+ 111: "/",
45640
+ 144: "NumLock",
45641
+ 145: "ScrollLock",
45642
+ 160: "Shift",
45643
+ 161: "Shift",
45644
+ 162: "Control",
45645
+ 163: "Control",
45646
+ 164: "Alt",
45647
+ 165: "Alt",
45648
+ 173: "-",
45649
+ 186: ";",
45650
+ 187: "=",
45651
+ 188: ",",
45652
+ 189: "-",
45653
+ 190: ".",
45654
+ 191: "/",
45655
+ 192: "`",
45656
+ 219: "[",
45657
+ 220: "\\",
45658
+ 221: "]",
45659
+ 222: "'"
45734
45660
  };
45735
- function isWordHtml(html) {
45736
- return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
45737
- }
45738
- const handleHtmlPaste$1 = (html, editor, plugin2) => {
45739
- const cleanedHtml = convertEmToPt(html);
45740
- const tempDiv = document.createElement("div");
45741
- tempDiv.innerHTML = cleanedHtml;
45742
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
45743
- tempDiv.remove();
45744
- const { dispatch } = editor.view;
45745
- if (!dispatch) return false;
45746
- dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
45747
- return true;
45661
+ var shift = {
45662
+ 48: ")",
45663
+ 49: "!",
45664
+ 50: "@",
45665
+ 51: "#",
45666
+ 52: "$",
45667
+ 53: "%",
45668
+ 54: "^",
45669
+ 55: "&",
45670
+ 56: "*",
45671
+ 57: "(",
45672
+ 59: ":",
45673
+ 61: "+",
45674
+ 173: "_",
45675
+ 186: ":",
45676
+ 187: "+",
45677
+ 188: "<",
45678
+ 189: "_",
45679
+ 190: ">",
45680
+ 191: "?",
45681
+ 192: "~",
45682
+ 219: "{",
45683
+ 220: "|",
45684
+ 221: "}",
45685
+ 222: '"'
45748
45686
  };
45749
- const convertEmToPt = (html) => {
45750
- return html.replace(
45751
- /font-size\s*:\s*([\d.]+)em/gi,
45752
- (_, emValue) => {
45753
- const em = parseFloat(emValue);
45754
- const pt = Math.round(em * 12 * 100) / 100;
45755
- return `font-size: ${pt}pt`;
45687
+ var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
45688
+ var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
45689
+ for (var i$1 = 0; i$1 < 10; i$1++) base$2[48 + i$1] = base$2[96 + i$1] = String(i$1);
45690
+ for (var i$1 = 1; i$1 <= 24; i$1++) base$2[i$1 + 111] = "F" + i$1;
45691
+ for (var i$1 = 65; i$1 <= 90; i$1++) {
45692
+ base$2[i$1] = String.fromCharCode(i$1 + 32);
45693
+ shift[i$1] = String.fromCharCode(i$1);
45694
+ }
45695
+ for (var code in base$2) if (!shift.hasOwnProperty(code)) shift[code] = base$2[code];
45696
+ function keyName(event) {
45697
+ var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified";
45698
+ var name = !ignoreKey && event.key || (event.shiftKey ? shift : base$2)[event.keyCode] || event.key || "Unidentified";
45699
+ if (name == "Esc") name = "Escape";
45700
+ if (name == "Del") name = "Delete";
45701
+ if (name == "Left") name = "ArrowLeft";
45702
+ if (name == "Up") name = "ArrowUp";
45703
+ if (name == "Right") name = "ArrowRight";
45704
+ if (name == "Down") name = "ArrowDown";
45705
+ return name;
45706
+ }
45707
+ const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
45708
+ const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
45709
+ function normalizeKeyName(name) {
45710
+ let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
45711
+ if (result == "Space")
45712
+ result = " ";
45713
+ let alt, ctrl, shift2, meta;
45714
+ for (let i2 = 0; i2 < parts.length - 1; i2++) {
45715
+ let mod = parts[i2];
45716
+ if (/^(cmd|meta|m)$/i.test(mod))
45717
+ meta = true;
45718
+ else if (/^a(lt)?$/i.test(mod))
45719
+ alt = true;
45720
+ else if (/^(c|ctrl|control)$/i.test(mod))
45721
+ ctrl = true;
45722
+ else if (/^s(hift)?$/i.test(mod))
45723
+ shift2 = true;
45724
+ else if (/^mod$/i.test(mod)) {
45725
+ if (mac)
45726
+ meta = true;
45727
+ else
45728
+ ctrl = true;
45729
+ } else
45730
+ throw new Error("Unrecognized modifier name: " + mod);
45731
+ }
45732
+ if (alt)
45733
+ result = "Alt-" + result;
45734
+ if (ctrl)
45735
+ result = "Ctrl-" + result;
45736
+ if (meta)
45737
+ result = "Meta-" + result;
45738
+ if (shift2)
45739
+ result = "Shift-" + result;
45740
+ return result;
45741
+ }
45742
+ function normalize(map2) {
45743
+ let copy2 = /* @__PURE__ */ Object.create(null);
45744
+ for (let prop in map2)
45745
+ copy2[normalizeKeyName(prop)] = map2[prop];
45746
+ return copy2;
45747
+ }
45748
+ function modifiers(name, event, shift2 = true) {
45749
+ if (event.altKey)
45750
+ name = "Alt-" + name;
45751
+ if (event.ctrlKey)
45752
+ name = "Ctrl-" + name;
45753
+ if (event.metaKey)
45754
+ name = "Meta-" + name;
45755
+ if (shift2 && event.shiftKey)
45756
+ name = "Shift-" + name;
45757
+ return name;
45758
+ }
45759
+ function keymap(bindings) {
45760
+ return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
45761
+ }
45762
+ function keydownHandler(bindings) {
45763
+ let map2 = normalize(bindings);
45764
+ return function(view, event) {
45765
+ let name = keyName(event), baseName, direct = map2[modifiers(name, event)];
45766
+ if (direct && direct(view.state, view.dispatch, view))
45767
+ return true;
45768
+ if (name.length == 1 && name != " ") {
45769
+ if (event.shiftKey) {
45770
+ let noShift = map2[modifiers(name, event, false)];
45771
+ if (noShift && noShift(view.state, view.dispatch, view))
45772
+ return true;
45773
+ }
45774
+ if ((event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
45775
+ !(windows && event.ctrlKey && event.altKey) && (baseName = base$2[event.keyCode]) && baseName != name) {
45776
+ let fromCode = map2[modifiers(baseName, event)];
45777
+ if (fromCode && fromCode(view.state, view.dispatch, view))
45778
+ return true;
45779
+ }
45756
45780
  }
45757
- );
45758
- };
45759
- function cleanHtmlUnnecessaryTags(html) {
45760
- return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
45781
+ return false;
45782
+ };
45783
+ }
45784
+ function isExtensionRulesEnabled(extension, enabled) {
45785
+ if (Array.isArray(enabled)) {
45786
+ return enabled.some((enabledExtension) => {
45787
+ const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
45788
+ return name === extension.name;
45789
+ });
45790
+ }
45791
+ return enabled;
45761
45792
  }
45762
45793
  const _ExtensionService = class _ExtensionService2 {
45763
45794
  constructor(extensions, userExtensions, editor) {
@@ -46629,14 +46660,16 @@
46629
46660
  });
46630
46661
  });
46631
46662
  };
46632
- const toggleHeaderFooterEditMode = (editor, focusedSectionEditor, isEditMode) => {
46663
+ const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode, documentMode }) => {
46633
46664
  editor.converter.headerEditors.forEach((item) => {
46634
46665
  item.editor.setEditable(isEditMode, false);
46635
46666
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
46667
+ item.editor.view.dom.setAttribute("documentmode", documentMode);
46636
46668
  });
46637
46669
  editor.converter.footerEditors.forEach((item) => {
46638
46670
  item.editor.setEditable(isEditMode, false);
46639
46671
  item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
46672
+ item.editor.view.dom.setAttribute("documentmode", documentMode);
46640
46673
  });
46641
46674
  if (isEditMode) {
46642
46675
  const pm = document.querySelector(".ProseMirror");
@@ -47717,6 +47750,19 @@
47717
47750
  );
47718
47751
  });
47719
47752
  };
47753
+ const resetHeaderFooterFieldAnnotations = ({ editor }) => {
47754
+ if (!editor) return;
47755
+ const sectionEditors = getAllHeaderFooterEditors(editor);
47756
+ sectionEditors.forEach(({ editor: sectionEditor, sectionId, type: type2 }) => {
47757
+ sectionEditor.commands.resetFieldAnnotations();
47758
+ onHeaderFooterDataUpdate(
47759
+ { editor: sectionEditor },
47760
+ editor,
47761
+ sectionId,
47762
+ type2
47763
+ );
47764
+ });
47765
+ };
47720
47766
  const cleanUpListsWithAnnotations = (fieldsToDelete = [], editor) => {
47721
47767
  if (!Array.isArray(fieldsToDelete)) fieldsToDelete = [fieldsToDelete];
47722
47768
  const { doc: doc2 } = editor.state;
@@ -47787,6 +47833,7 @@
47787
47833
  getAllHeaderFooterEditors,
47788
47834
  updateHeaderFooterFieldAnnotations,
47789
47835
  deleteHeaderFooterFieldAnnotations,
47836
+ resetHeaderFooterFieldAnnotations,
47790
47837
  cleanUpListsWithAnnotations
47791
47838
  };
47792
47839
  const CollaborationPluginKey = new PluginKey("collaboration");
@@ -48155,7 +48202,12 @@
48155
48202
  this.commands.toggleTrackChangesShowOriginal();
48156
48203
  this.setEditable(false, false);
48157
48204
  this.setOptions({ documentMode: "viewing" });
48158
- toggleHeaderFooterEditMode(this, null, false);
48205
+ toggleHeaderFooterEditMode({
48206
+ editor: this,
48207
+ focusedSectionEditor: null,
48208
+ isEditMode: false,
48209
+ documentMode: cleanedMode
48210
+ });
48159
48211
  } else if (cleanedMode === "suggesting") {
48160
48212
  __privateMethod$1(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
48161
48213
  this.commands.disableTrackChangesShowOriginal();
@@ -48168,7 +48220,12 @@
48168
48220
  this.commands.disableTrackChanges();
48169
48221
  this.setEditable(true, false);
48170
48222
  this.setOptions({ documentMode: "editing" });
48171
- toggleHeaderFooterEditMode(this, null, false);
48223
+ toggleHeaderFooterEditMode({
48224
+ editor: this,
48225
+ focusedSectionEditor: null,
48226
+ isEditMode: false,
48227
+ documentMode: cleanedMode
48228
+ });
48172
48229
  }
48173
48230
  }
48174
48231
  /**
@@ -48620,7 +48677,7 @@
48620
48677
  * @returns {Object | void} Migration results
48621
48678
  */
48622
48679
  processCollaborationMigrations() {
48623
- console.debug("[checkVersionMigrations] Current editor version", "0.13.3");
48680
+ console.debug("[checkVersionMigrations] Current editor version", "0.13.4");
48624
48681
  if (!this.options.ydoc) return;
48625
48682
  const metaMap = this.options.ydoc.getMap("meta");
48626
48683
  let docVersion = metaMap.get("version");
@@ -49011,7 +49068,12 @@
49011
49068
  event.stopPropagation();
49012
49069
  if (!this.options.editable) {
49013
49070
  this.setEditable(true, false);
49014
- toggleHeaderFooterEditMode(this, null, false);
49071
+ toggleHeaderFooterEditMode({
49072
+ editor: this,
49073
+ focusedSectionEditor: null,
49074
+ isEditMode: false,
49075
+ documentMode: this.options.documentMode
49076
+ });
49015
49077
  const pm = document.querySelector(".ProseMirror");
49016
49078
  pm.classList.remove("header-footer-edit");
49017
49079
  pm.setAttribute("aria-readonly", false);
@@ -51831,7 +51893,16 @@
51831
51893
  };
51832
51894
  },
51833
51895
  parseDOM() {
51834
- return [{ tag: "span" }];
51896
+ return [{
51897
+ tag: 'span[linebreaktype="page"]',
51898
+ getAttrs: (dom) => {
51899
+ if (!(dom instanceof HTMLElement)) return false;
51900
+ return {
51901
+ pageBreakSource: dom.getAttribute("pagebreaksource") || null,
51902
+ pageBreakType: dom.getAttribute("linebreaktype") || null
51903
+ };
51904
+ }
51905
+ }];
51835
51906
  },
51836
51907
  renderDOM({ htmlAttributes }) {
51837
51908
  return ["span", Attribute.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
@@ -52261,13 +52332,13 @@
52261
52332
  return result;
52262
52333
  }
52263
52334
  var tableEditingKey = new PluginKey("selectingCells");
52264
- function cellAround($pos) {
52335
+ function cellAround$1($pos) {
52265
52336
  for (let d = $pos.depth - 1; d > 0; d--)
52266
52337
  if ($pos.node(d).type.spec.tableRole == "row")
52267
52338
  return $pos.node(0).resolve($pos.before(d + 1));
52268
52339
  return null;
52269
52340
  }
52270
- function cellWrapping($pos) {
52341
+ function cellWrapping$1($pos) {
52271
52342
  for (let d = $pos.depth; d > 0; d--) {
52272
52343
  const role = $pos.node(d).type.spec.tableRole;
52273
52344
  if (role === "cell" || role === "header_cell") return $pos.node(d);
@@ -52287,7 +52358,7 @@
52287
52358
  } else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") {
52288
52359
  return sel.$anchor;
52289
52360
  }
52290
- const $cell = cellAround(sel.$head) || cellNear(sel.$head);
52361
+ const $cell = cellAround$1(sel.$head) || cellNear(sel.$head);
52291
52362
  if ($cell) {
52292
52363
  return $cell;
52293
52364
  }
@@ -53026,22 +53097,22 @@
53026
53097
  }
53027
53098
  return true;
53028
53099
  }
53029
- function splitCell(state2, dispatch) {
53100
+ function splitCell$1(state2, dispatch) {
53030
53101
  const nodeTypes = tableNodeTypes(state2.schema);
53031
53102
  return splitCellWithType(({ node: node2 }) => {
53032
53103
  return nodeTypes[node2.type.spec.tableRole];
53033
53104
  })(state2, dispatch);
53034
53105
  }
53035
- function splitCellWithType(getCellType) {
53106
+ function splitCellWithType(getCellType2) {
53036
53107
  return (state2, dispatch) => {
53037
53108
  var _a;
53038
53109
  const sel = state2.selection;
53039
53110
  let cellNode;
53040
53111
  let cellPos;
53041
53112
  if (!(sel instanceof CellSelection)) {
53042
- cellNode = cellWrapping(sel.$from);
53113
+ cellNode = cellWrapping$1(sel.$from);
53043
53114
  if (!cellNode) return false;
53044
- cellPos = (_a = cellAround(sel.$from)) == null ? void 0 : _a.pos;
53115
+ cellPos = (_a = cellAround$1(sel.$from)) == null ? void 0 : _a.pos;
53045
53116
  } else {
53046
53117
  if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
53047
53118
  cellNode = sel.$anchorCell.nodeAfter;
@@ -53075,13 +53146,13 @@
53075
53146
  if (col == rect.left && row == rect.top) continue;
53076
53147
  tr.insert(
53077
53148
  lastCell = tr.mapping.map(pos + rect.tableStart, 1),
53078
- getCellType({ node: cellNode, row, col }).createAndFill(attrs[i2])
53149
+ getCellType2({ node: cellNode, row, col }).createAndFill(attrs[i2])
53079
53150
  );
53080
53151
  }
53081
53152
  }
53082
53153
  tr.setNodeMarkup(
53083
53154
  cellPos,
53084
- getCellType({ node: cellNode, row: rect.top, col: rect.left }),
53155
+ getCellType2({ node: cellNode, row: rect.top, col: rect.left }),
53085
53156
  attrs[0]
53086
53157
  );
53087
53158
  if (sel instanceof CellSelection)
@@ -53614,7 +53685,7 @@
53614
53685
  };
53615
53686
  }
53616
53687
  function handleTripleClick(view, pos) {
53617
- const doc2 = view.state.doc, $cell = cellAround(doc2.resolve(pos));
53688
+ const doc2 = view.state.doc, $cell = cellAround$1(doc2.resolve(pos));
53618
53689
  if (!$cell) return false;
53619
53690
  view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));
53620
53691
  return true;
@@ -53666,7 +53737,7 @@
53666
53737
  if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {
53667
53738
  setCellSelection(view.state.selection.$anchorCell, startEvent);
53668
53739
  startEvent.preventDefault();
53669
- } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_a = cellUnderMouse(view, startEvent)) == null ? void 0 : _a.pos) != $anchor.pos) {
53740
+ } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround$1(view.state.selection.$anchor)) != null && ((_a = cellUnderMouse(view, startEvent)) == null ? void 0 : _a.pos) != $anchor.pos) {
53670
53741
  setCellSelection($anchor, startEvent);
53671
53742
  startEvent.preventDefault();
53672
53743
  } else if (!startDOMCell) {
@@ -53737,7 +53808,7 @@
53737
53808
  top: event.clientY
53738
53809
  });
53739
53810
  if (!mousePos) return null;
53740
- return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null;
53811
+ return mousePos ? cellAround$1(view.state.doc.resolve(mousePos.pos)) : null;
53741
53812
  }
53742
53813
  var TableView = class {
53743
53814
  constructor(node2, defaultCellMinWidth) {
@@ -54002,7 +54073,7 @@
54002
54073
  });
54003
54074
  if (!found2) return -1;
54004
54075
  const { pos } = found2;
54005
- const $cell = cellAround(view.state.doc.resolve(pos));
54076
+ const $cell = cellAround$1(view.state.doc.resolve(pos));
54006
54077
  if (!$cell) return -1;
54007
54078
  if (side == "right") return $cell.pos;
54008
54079
  const map2 = TableMap.get($cell.node(-1)), start2 = $cell.start(-1);
@@ -54164,6 +54235,19 @@
54164
54235
  right: { size: size2, color }
54165
54236
  };
54166
54237
  };
54238
+ function cellAround($pos) {
54239
+ for (let d = $pos.depth - 1; d > 0; d--)
54240
+ if ($pos.node(d).type.spec.tableRole == "row")
54241
+ return $pos.node(0).resolve($pos.before(d + 1));
54242
+ return null;
54243
+ }
54244
+ function cellWrapping($pos) {
54245
+ for (let d = $pos.depth; d > 0; d--) {
54246
+ const role = $pos.node(d).type.spec.tableRole;
54247
+ if (role === "cell" || role === "header_cell") return $pos.node(d);
54248
+ }
54249
+ return null;
54250
+ }
54167
54251
  const Table = Node$1.create({
54168
54252
  name: "table",
54169
54253
  content: "tableRow+",
@@ -54261,9 +54345,7 @@
54261
54345
  addCommands() {
54262
54346
  return {
54263
54347
  insertTable: ({ rows = 3, cols = 3, withHeaderRow = false } = {}) => ({ tr, dispatch, editor }) => {
54264
- const zeroWidthText = editor.schema.text("​");
54265
- const emptyPar = getNodeType("paragraph", editor.schema).create(null, zeroWidthText);
54266
- const node2 = createTable(editor.schema, rows, cols, withHeaderRow, emptyPar);
54348
+ const node2 = createTable(editor.schema, rows, cols, withHeaderRow);
54267
54349
  if (dispatch) {
54268
54350
  const offset2 = tr.selection.from + 1;
54269
54351
  tr.replaceSelectionWith(node2).scrollIntoView().setSelection(TextSelection.near(tr.doc.resolve(offset2)));
@@ -54294,8 +54376,81 @@
54294
54376
  mergeCells: () => ({ state: state2, dispatch }) => {
54295
54377
  return mergeCells(state2, dispatch);
54296
54378
  },
54297
- splitCell: () => ({ state: state2, dispatch }) => {
54298
- return splitCell(state2, dispatch);
54379
+ splitCell: () => ({ state: state2, dispatch, commands: commands2 }) => {
54380
+ if (splitCell$1(state2, dispatch)) {
54381
+ return true;
54382
+ }
54383
+ return commands2.splitSingleCell();
54384
+ },
54385
+ splitSingleCell: () => ({ state: state2, dispatch, tr }) => {
54386
+ const sel = state2.selection;
54387
+ let cellNode;
54388
+ let cellPos;
54389
+ if (!(sel instanceof CellSelection)) {
54390
+ cellNode = cellWrapping(sel.$from);
54391
+ if (!cellNode) return false;
54392
+ cellPos = cellAround(sel.$from)?.pos;
54393
+ } else {
54394
+ if (sel.$anchorCell.pos != sel.$headCell.pos) return false;
54395
+ cellNode = sel.$anchorCell.nodeAfter;
54396
+ cellPos = sel.$anchorCell.pos;
54397
+ }
54398
+ if (cellNode == null || cellPos == null) {
54399
+ return false;
54400
+ }
54401
+ if (cellNode.attrs.colspan != 1 || cellNode.attrs.rowspan != 1) {
54402
+ return false;
54403
+ }
54404
+ if (dispatch) {
54405
+ let rect = selectedRect(state2);
54406
+ let currentRow = rect.top;
54407
+ let currentCol = rect.left;
54408
+ let baseAttrs = { ...cellNode.attrs };
54409
+ let currentColWidth2 = baseAttrs.colwidth;
54410
+ let newCellWidth = null;
54411
+ if (currentColWidth2 && currentColWidth2[0]) {
54412
+ newCellWidth = Math.ceil(currentColWidth2[0] / 2);
54413
+ }
54414
+ if (newCellWidth) {
54415
+ tr.setNodeMarkup(tr.mapping.map(cellPos, 1), null, { ...baseAttrs, colwidth: [newCellWidth] });
54416
+ }
54417
+ const newCellAttrs = { ...baseAttrs, colwidth: newCellWidth ? [newCellWidth] : null };
54418
+ const newCell = getCellType({ node: cellNode, state: state2 }).createAndFill(newCellAttrs);
54419
+ tr.insert(tr.mapping.map(cellPos + cellNode.nodeSize, 1), newCell);
54420
+ for (let row = 0; row < rect.map.height; row++) {
54421
+ if (row === currentRow) continue;
54422
+ let rowCells = /* @__PURE__ */ new Set();
54423
+ for (let col = 0; col < rect.map.width; col++) {
54424
+ let cellIndex = rect.map.map[row * rect.map.width + col];
54425
+ if (cellIndex != null) rowCells.add(cellIndex);
54426
+ }
54427
+ [...rowCells].forEach((cellIndex) => {
54428
+ let cellRect = rect.map.findCell(cellIndex);
54429
+ if (cellRect.left <= currentCol && cellRect.right > currentCol) {
54430
+ let cellPos2 = tr.mapping.map(rect.tableStart + cellIndex, 1);
54431
+ let cell = tr.doc.nodeAt(cellPos2);
54432
+ if (cell) {
54433
+ let newColspan = (cell.attrs.colspan || 1) + 1;
54434
+ let updatedColwidth = cell.attrs.colwidth;
54435
+ if (updatedColwidth && newCellWidth) {
54436
+ let originalColIndex = currentCol - cellRect.left;
54437
+ updatedColwidth = [
54438
+ ...updatedColwidth.slice(0, originalColIndex),
54439
+ newCellWidth,
54440
+ // current cell width
54441
+ newCellWidth,
54442
+ // new cell width
54443
+ ...updatedColwidth.slice(originalColIndex + 1)
54444
+ ];
54445
+ }
54446
+ let cellAttrs = { ...cell.attrs, colspan: newColspan, colwidth: updatedColwidth };
54447
+ tr.setNodeMarkup(cellPos2, null, cellAttrs);
54448
+ }
54449
+ }
54450
+ });
54451
+ }
54452
+ }
54453
+ return true;
54299
54454
  },
54300
54455
  mergeOrSplit: () => ({ state: state2, dispatch }) => {
54301
54456
  if (mergeCells(state2, dispatch)) {
@@ -54417,6 +54572,10 @@
54417
54572
  };
54418
54573
  }
54419
54574
  });
54575
+ function getCellType({ node: node2, state: state2 }) {
54576
+ const nodeTypes = tableNodeTypes(state2.schema);
54577
+ return nodeTypes[node2.type.spec.tableRole];
54578
+ }
54420
54579
  const TableHeader = Node$1.create({
54421
54580
  name: "tableHeader",
54422
54581
  content: "block+",
@@ -55239,8 +55398,18 @@
55239
55398
  };
55240
55399
  }
55241
55400
  },
55401
+ defaultDisplayLabel: {
55402
+ default: "",
55403
+ parseDOM: (elem) => elem.getAttribute("data-default-display-label"),
55404
+ renderDOM: (attrs) => {
55405
+ if (!attrs.defaultDisplayLabel) return {};
55406
+ return {
55407
+ "data-default-display-label": attrs.defaultDisplayLabel
55408
+ };
55409
+ }
55410
+ },
55242
55411
  displayLabel: {
55243
- default: "Text field",
55412
+ default: "",
55244
55413
  parseDOM: (elem) => elem.getAttribute("data-display-label"),
55245
55414
  renderDOM: (attrs) => {
55246
55415
  if (!attrs.displayLabel) return {};
@@ -55306,7 +55475,7 @@
55306
55475
  default: "#980043",
55307
55476
  parseDOM: (elem) => elem.getAttribute("data-field-color") || elem.style.backgroundColor || null,
55308
55477
  renderDOM: (attrs) => {
55309
- if (!attrs.fieldColor) return {};
55478
+ if (!attrs.fieldColor || attrs.fieldColor == "None") return {};
55310
55479
  let hexColor = toHex(attrs.fieldColor);
55311
55480
  let isSixValueSyntax = hexColor.slice(1).length === 6;
55312
55481
  if (isSixValueSyntax) {
@@ -55556,6 +55725,7 @@
55556
55725
  return renderer2();
55557
55726
  },
55558
55727
  addCommands() {
55728
+ const annotationTypes = this.options.types;
55559
55729
  return {
55560
55730
  /**
55561
55731
  * Add field annotation.
@@ -55577,7 +55747,12 @@
55577
55747
  let currentMarks = $pos.marks();
55578
55748
  currentMarks = currentMarks.length ? [...currentMarks] : null;
55579
55749
  let formatAttrs = getFormatAttrsFromMarks(currentMarks);
55580
- let node2 = schema.nodes[this.name].create({ ...attrs, ...formatAttrs }, null, null);
55750
+ let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
55751
+ let node2 = schema.nodes[this.name].create({
55752
+ ...attrs,
55753
+ ...formatAttrs,
55754
+ defaultDisplayLabel
55755
+ }, null, null);
55581
55756
  state2.tr.insert(newPos, node2).setSelection(Selection.near(tr.doc.resolve(newPos + node2.nodeSize)));
55582
55757
  if (editorFocus) {
55583
55758
  this.editor.view.focus();
@@ -55585,9 +55760,9 @@
55585
55760
  }
55586
55761
  return true;
55587
55762
  },
55588
- addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ editor, dispatch, state: state2, tr, commands: commands2 }) => {
55763
+ addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ state: state2, commands: commands2 }) => {
55589
55764
  const { from: from2 } = state2.selection;
55590
- commands2.addFieldAnnotation(from2, attrs, editorFocus);
55765
+ return commands2.addFieldAnnotation(from2, attrs, editorFocus);
55591
55766
  },
55592
55767
  /**
55593
55768
  * Replace field annotation.
@@ -55597,24 +55772,113 @@
55597
55772
  * from: 20,
55598
55773
  * to: 45,
55599
55774
  * attrs: {
55600
- * fieldType: 'TEXTINPUT'
55601
- * fieldColor: '#980043'
55775
+ * fieldType: 'TEXTINPUT'
55776
+ * fieldColor: '#980043'
55602
55777
  * }
55603
55778
  * ])
55604
55779
  */
55605
- replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, state: state2, tr }) => {
55780
+ replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, tr }) => {
55606
55781
  if (!dispatch) return true;
55607
- tr.setMeta("fieldAnnotationReplace", true);
55608
55782
  fieldsArray.forEach((annotation) => {
55609
55783
  let { from: from2, to, attrs } = annotation;
55610
55784
  let { schema } = editor;
55611
55785
  let newPosFrom = tr.mapping.map(from2);
55612
55786
  let newPosTo = tr.mapping.map(to);
55613
- let node2 = schema.nodes[this.name].create({ ...attrs }, null, null);
55787
+ let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
55788
+ let node2 = schema.nodes[this.name].create({
55789
+ ...attrs,
55790
+ defaultDisplayLabel
55791
+ }, null, null);
55614
55792
  tr.replaceWith(newPosFrom, newPosTo, node2);
55615
55793
  });
55616
55794
  return true;
55617
55795
  },
55796
+ /**
55797
+ * Replace annotations with a label (as text node) in selection.
55798
+ * @param options Additional options.
55799
+ * @example
55800
+ * editor.commands.replaceFieldAnnotationsWithLabelInSelection()
55801
+ */
55802
+ replaceFieldAnnotationsWithLabelInSelection: (options2 = {}) => ({ commands: commands2 }) => {
55803
+ return commands2.replaceFieldAnnotationsWithLabel(null, {
55804
+ ...options2,
55805
+ isInSelection: true
55806
+ });
55807
+ },
55808
+ /**
55809
+ * Replace annotations with a label (as text node).
55810
+ * @param fieldIdOrArray The field ID or array of field IDs.
55811
+ * @param options.isInSelection Find in selection instead of field IDs.
55812
+ * @param options.addToHistory Add to history or not.
55813
+ * @param options.types Annotation types to replace.
55814
+ * @example
55815
+ * editor.commands.replaceFieldAnnotationsWithLabel(['1', '2'])
55816
+ */
55817
+ replaceFieldAnnotationsWithLabel: (fieldIdOrArray, {
55818
+ isInSelection = false,
55819
+ addToHistory = false,
55820
+ types: types2 = annotationTypes
55821
+ } = {}) => ({ dispatch, state: state2, tr }) => {
55822
+ let { from: from2, to } = state2.selection;
55823
+ let annotations = isInSelection ? findFieldAnnotationsBetween(from2, to, state2.doc) : findFieldAnnotationsByFieldId(fieldIdOrArray, state2);
55824
+ annotations = types2.length ? annotations.filter(({ node: node2 }) => types2.includes(node2.attrs.type)) : annotations;
55825
+ if (!annotations.length) {
55826
+ return true;
55827
+ }
55828
+ if (!addToHistory) {
55829
+ tr.setMeta("addToHistory", false);
55830
+ }
55831
+ if (dispatch) {
55832
+ annotations.forEach((annotation) => {
55833
+ let { pos, node: node2 } = annotation;
55834
+ let newPosFrom = tr.mapping.map(pos);
55835
+ let newPosTo = tr.mapping.map(pos + node2.nodeSize);
55836
+ let currentNode = tr.doc.nodeAt(newPosFrom);
55837
+ let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
55838
+ let $newPosFrom = tr.doc.resolve(newPosFrom);
55839
+ let currentMarks = $newPosFrom.marks();
55840
+ currentMarks = currentMarks.length ? [...currentMarks] : null;
55841
+ if (nodeEqual) {
55842
+ let label = node2.attrs.displayLabel || " ";
55843
+ let textNode = state2.schema.text(label, currentMarks);
55844
+ tr.replaceWith(newPosFrom, newPosTo, textNode);
55845
+ }
55846
+ });
55847
+ }
55848
+ return true;
55849
+ },
55850
+ /**
55851
+ * Resets all annotations to default values.
55852
+ * @example
55853
+ * editor.commands.resetFieldAnnotations()
55854
+ */
55855
+ resetFieldAnnotations: () => ({ dispatch, state: state2, tr }) => {
55856
+ let annotations = getAllFieldAnnotations(state2);
55857
+ if (!annotations.length) {
55858
+ return true;
55859
+ }
55860
+ tr.setMeta("fieldAnnotationUpdate", true);
55861
+ if (dispatch) {
55862
+ annotations.forEach(({ pos, node: node2 }) => {
55863
+ let newPos = tr.mapping.map(pos);
55864
+ let currentNode = tr.doc.nodeAt(newPos);
55865
+ let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
55866
+ if (nodeEqual) {
55867
+ let displayLabel = node2.attrs.defaultDisplayLabel || node2.attrs.displayLabel || "";
55868
+ tr.setNodeMarkup(newPos, void 0, {
55869
+ ...node2.attrs,
55870
+ // reset displayLabel to default.
55871
+ displayLabel,
55872
+ // reset attrs ​​for specific types.
55873
+ imageSrc: null,
55874
+ rawHtml: null,
55875
+ linkUrl: null
55876
+ });
55877
+ }
55878
+ });
55879
+ }
55880
+ return true;
55881
+ },
55618
55882
  /**
55619
55883
  * Update annotations associated with a field.
55620
55884
  * @param fieldIdOrArray The field ID or array of field IDs.
@@ -56487,7 +56751,6 @@
56487
56751
  group: "inline",
56488
56752
  inline: true,
56489
56753
  atom: true,
56490
- selectable: false,
56491
56754
  draggable: false,
56492
56755
  selectable: false,
56493
56756
  defining: true,
@@ -56550,7 +56813,6 @@
56550
56813
  group: "inline",
56551
56814
  inline: true,
56552
56815
  atom: true,
56553
- selectable: false,
56554
56816
  draggable: false,
56555
56817
  selectable: false,
56556
56818
  content: "text*",
@@ -56572,6 +56834,12 @@
56572
56834
  }
56573
56835
  };
56574
56836
  },
56837
+ addNodeView() {
56838
+ return ({ node: node2, editor, getPos, decorations }) => {
56839
+ const htmlAttributes = this.options.htmlAttributes;
56840
+ return new AutoPageNumberNodeView(node2, getPos, decorations, editor, htmlAttributes);
56841
+ };
56842
+ },
56575
56843
  parseDOM() {
56576
56844
  return [{ tag: 'span[data-id="auto-total-pages"' }];
56577
56845
  },
@@ -56605,6 +56873,26 @@
56605
56873
  };
56606
56874
  }
56607
56875
  });
56876
+ const getNodeAttributes = (nodeName, editor) => {
56877
+ switch (nodeName) {
56878
+ case "page-number":
56879
+ return {
56880
+ text: editor.options.currentPageNumber || "1",
56881
+ className: "sd-editor-auto-page-number",
56882
+ dataId: "auto-page-number",
56883
+ ariaLabel: "Page number node"
56884
+ };
56885
+ case "total-page-number":
56886
+ return {
56887
+ text: editor.options.parentEditor?.currentTotalPages || "1",
56888
+ className: "sd-editor-auto-total-pages",
56889
+ dataId: "auto-total-pages",
56890
+ ariaLabel: "Total page count node"
56891
+ };
56892
+ default:
56893
+ return {};
56894
+ }
56895
+ };
56608
56896
  class AutoPageNumberNodeView {
56609
56897
  constructor(node2, getPos, decorations, editor, htmlAttributes = {}) {
56610
56898
  __privateAdd$1(this, _AutoPageNumberNodeView_instances);
@@ -56623,12 +56911,12 @@
56623
56911
  }
56624
56912
  _AutoPageNumberNodeView_instances = /* @__PURE__ */ new WeakSet();
56625
56913
  renderDom_fn = function(node2, htmlAttributes) {
56626
- const pageText = this.editor.options.currentPageNumber || "1";
56627
- const content = document.createTextNode(String(pageText));
56914
+ const attrs = getNodeAttributes(this.node.type.name, this.editor);
56915
+ const content = document.createTextNode(String(attrs.text));
56628
56916
  const nodeContent = document.createElement("span");
56629
- nodeContent.className = "sd-editor-auto-page-number";
56630
- nodeContent.setAttribute("data-id", "auto-page-number");
56631
- nodeContent.setAttribute("aria-label", "Page number node");
56917
+ nodeContent.className = attrs.className;
56918
+ nodeContent.setAttribute("data-id", attrs.dataId);
56919
+ nodeContent.setAttribute("aria-label", attrs.ariaLabel);
56632
56920
  const currentPos = this.getPos();
56633
56921
  const { styles, marks } = getMarksFromNeighbors(currentPos, this.view);
56634
56922
  __privateMethod$1(this, _AutoPageNumberNodeView_instances, scheduleUpdateNodeStyle_fn).call(this, currentPos, marks);
@@ -62020,7 +62308,12 @@
62020
62308
  const onHeaderFooterDblClick = (editor, currentFocusedSectionEditor) => {
62021
62309
  if (editor.options.documentMode !== "editing") return;
62022
62310
  editor.setEditable(false, false);
62023
- toggleHeaderFooterEditMode(editor, currentFocusedSectionEditor, true);
62311
+ toggleHeaderFooterEditMode({
62312
+ editor,
62313
+ focusedSectionEditor: currentFocusedSectionEditor,
62314
+ isEditMode: true,
62315
+ documentMode: editor.options.documentMode
62316
+ });
62024
62317
  };
62025
62318
  function createPageBreak({ editor, header, footer, footerBottom = null, isFirstHeader, isLastFooter, isInTable: isInTable2 = false }) {
62026
62319
  const { pageSize, pageMargins } = editor.converter.pageStyles;
@@ -62600,6 +62893,7 @@
62600
62893
  if (tr.getMeta(NodeResizerKey)) {
62601
62894
  return oldState;
62602
62895
  }
62896
+ if (typeof document === "undefined") return oldState;
62603
62897
  const decorations = [];
62604
62898
  const { selection } = newState;
62605
62899
  if (nodeNames.includes(selection.node?.type.name)) {
@@ -93320,7 +93614,7 @@ ${style2}
93320
93614
  this.config.colors = shuffleArray(this.config.colors);
93321
93615
  this.userColorMap = /* @__PURE__ */ new Map();
93322
93616
  this.colorIndex = 0;
93323
- this.version = "0.13.3";
93617
+ this.version = "0.13.4";
93324
93618
  console.debug("🦋 [superdoc] Using SuperDoc version:", this.version);
93325
93619
  this.superdocId = config.superdocId || v4();
93326
93620
  this.colors = this.config.colors;