@harbour-enterprises/superdoc 0.15.7-next.1 → 0.15.7-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/chunks/{super-editor.es-wYUD2FbG.cjs → super-editor.es-BZl0f40H.cjs} +174 -81
  2. package/dist/chunks/{super-editor.es-DK_jRQOE.es.js → super-editor.es-CySS7Yji.es.js} +174 -81
  3. package/dist/core/SuperDoc.d.ts +0 -1
  4. package/dist/core/SuperDoc.d.ts.map +1 -1
  5. package/dist/super-editor/ai-writer.es.js +2 -2
  6. package/dist/super-editor/chunks/{converter-DeJTqjPR.js → converter-Cq8wkRD4.js} +173 -80
  7. package/dist/super-editor/chunks/{docx-zipper-vN19SPa8.js → docx-zipper-CXwmm6eO.js} +1 -1
  8. package/dist/super-editor/chunks/{editor-Dd9HYASE.js → editor-BwaURTck.js} +3 -3
  9. package/dist/super-editor/chunks/{toolbar-D0DQ38PV.js → toolbar-CCVzfOoQ.js} +2 -2
  10. package/dist/super-editor/converter.es.js +1 -1
  11. package/dist/super-editor/core/helpers/list-numbering-helpers.d.ts +1 -1
  12. package/dist/super-editor/core/helpers/list-numbering-helpers.d.ts.map +1 -1
  13. package/dist/super-editor/core/helpers/pasteListHelpers.d.ts +7 -0
  14. package/dist/super-editor/core/helpers/pasteListHelpers.d.ts.map +1 -0
  15. package/dist/super-editor/core/inputRules/docx-paste/docx-paste.d.ts.map +1 -1
  16. package/dist/super-editor/docx-zipper.es.js +2 -2
  17. package/dist/super-editor/editor.es.js +3 -3
  18. package/dist/super-editor/file-zipper.es.js +1 -1
  19. package/dist/super-editor/super-editor.es.js +6 -6
  20. package/dist/super-editor/toolbar.es.js +2 -2
  21. package/dist/super-editor.cjs +1 -1
  22. package/dist/super-editor.es.js +1 -1
  23. package/dist/superdoc.cjs +11 -11
  24. package/dist/superdoc.es.js +12 -12
  25. package/dist/superdoc.umd.js +184 -91
  26. package/dist/superdoc.umd.js.map +1 -1
  27. package/package.json +1 -1
@@ -22960,20 +22960,62 @@ const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
22960
22960
  isTextSelection,
22961
22961
  posToDOMRect
22962
22962
  }, Symbol.toStringTag, { value: "Module" }));
22963
- const generateNewListDefinition = ({ numId, listType, editor }) => {
22963
+ const generateNewListDefinition = ({ numId, listType, level, start: start2, text, fmt, editor }) => {
22964
22964
  if (typeof listType === "string") listType = editor.schema.nodes[listType];
22965
22965
  const definition = listType.name === "orderedList" ? baseOrderedListDef : baseBulletList;
22966
22966
  const numbering = editor.converter.numbering;
22967
22967
  const newNumbering = { ...numbering };
22968
- const newAbstractId = getNewListId(editor, "abstracts");
22969
- const newAbstractDef = {
22970
- ...definition,
22971
- attributes: {
22972
- ...definition.attributes,
22973
- "w:abstractNumId": String(newAbstractId)
22974
- }
22975
- };
22976
- newNumbering.abstracts[newAbstractId] = newAbstractDef;
22968
+ let skipAddingNewAbstract = false;
22969
+ let newAbstractId = getNewListId(editor, "abstracts");
22970
+ let newAbstractDef = JSON.parse(
22971
+ JSON.stringify({
22972
+ ...definition,
22973
+ attributes: {
22974
+ ...definition.attributes,
22975
+ "w:abstractNumId": String(newAbstractId)
22976
+ }
22977
+ })
22978
+ );
22979
+ if (level && start2 && text && fmt) {
22980
+ if (newNumbering.definitions[numId]) {
22981
+ const abstractId = newNumbering.definitions[numId]?.elements[0]?.attributes["w:val"];
22982
+ newAbstractId = abstractId;
22983
+ const abstract = editor.converter.numbering.abstracts[abstractId];
22984
+ newAbstractDef = { ...abstract };
22985
+ skipAddingNewAbstract = true;
22986
+ }
22987
+ const levelDefIndex = newAbstractDef.elements.findIndex(
22988
+ (el) => el.name === "w:lvl" && el.attributes["w:ilvl"] === level
22989
+ );
22990
+ const levelProps = newAbstractDef.elements[levelDefIndex];
22991
+ const elToFilter = ["w:numFmt", "w:lvlText", "w:start"];
22992
+ const oldElements = levelProps.elements.filter((el) => !elToFilter.includes(el.name));
22993
+ levelProps.elements = [
22994
+ ...oldElements,
22995
+ {
22996
+ type: "element",
22997
+ name: "w:start",
22998
+ attributes: {
22999
+ "w:val": start2
23000
+ }
23001
+ },
23002
+ {
23003
+ type: "element",
23004
+ name: "w:numFmt",
23005
+ attributes: {
23006
+ "w:val": fmt
23007
+ }
23008
+ },
23009
+ {
23010
+ type: "element",
23011
+ name: "w:lvlText",
23012
+ attributes: {
23013
+ "w:val": text
23014
+ }
23015
+ }
23016
+ ];
23017
+ }
23018
+ if (!skipAddingNewAbstract) newNumbering.abstracts[newAbstractId] = newAbstractDef;
22977
23019
  const newNumDef = getBasicNumIdTag(numId, newAbstractId);
22978
23020
  newNumbering.definitions[numId] = newNumDef;
22979
23021
  editor.converter.numbering = newNumbering;
@@ -23205,7 +23247,7 @@ const ListHelpers = {
23205
23247
  baseOrderedListDef,
23206
23248
  baseBulletList
23207
23249
  };
23208
- function extractListLevelStyles(cssText, listId, level) {
23250
+ const extractListLevelStyles = (cssText, listId, level) => {
23209
23251
  const pattern = new RegExp(`@list\\s+l${listId}:level${level}\\s*\\{([^}]+)\\}`, "i");
23210
23252
  const match = cssText.match(pattern);
23211
23253
  if (!match) return null;
@@ -23216,14 +23258,58 @@ function extractListLevelStyles(cssText, listId, level) {
23216
23258
  styleMap[key] = value;
23217
23259
  }
23218
23260
  return styleMap;
23219
- }
23261
+ };
23220
23262
  const numDefMap = /* @__PURE__ */ new Map([
23221
- ["decimal", { def: "decimal", abstractNum: 1 }],
23222
- ["alpha-lower", { def: "lowerLetter", abstractNum: 1 }],
23223
- ["alpha-upper", { def: "upperLetter", abstractNum: 1 }],
23224
- ["roman-lower", { def: "lowerRoman", abstractNum: 1 }],
23225
- ["roman-upper", { def: "upperRoman", abstractNum: 1 }],
23226
- ["bullet", { def: "bullet", abstractNum: 0 }]
23263
+ ["decimal", "decimal"],
23264
+ ["alpha-lower", "lowerLetter"],
23265
+ ["alpha-upper", "upperLetter"],
23266
+ ["roman-lower", "lowerRoman"],
23267
+ ["roman-upper", "upperRoman"],
23268
+ ["bullet", "bullet"]
23269
+ ]);
23270
+ const numDefByTypeMap = /* @__PURE__ */ new Map([
23271
+ ["1", "decimal"],
23272
+ ["a", "lowerLetter"],
23273
+ ["A", "upperLetter"],
23274
+ ["I", "upperRoman"],
23275
+ ["i", "lowerRoman"]
23276
+ ]);
23277
+ function getStartNumber(lvlText) {
23278
+ const match = lvlText.match(/^(\d+)/);
23279
+ if (match) return parseInt(match[1], 10);
23280
+ return null;
23281
+ }
23282
+ function letterToNumber(letter) {
23283
+ return letter.toLowerCase().charCodeAt(0) - "a".charCodeAt(0) + 1;
23284
+ }
23285
+ function getStartNumberFromAlpha(lvlText) {
23286
+ const match = lvlText.match(/^([a-zA-Z])/);
23287
+ if (match) return letterToNumber(match[1]);
23288
+ return null;
23289
+ }
23290
+ function romanToNumber(roman) {
23291
+ const map3 = { I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1e3 };
23292
+ let num = 0, prev = 0;
23293
+ for (let i = roman.length - 1; i >= 0; i--) {
23294
+ const curr = map3[roman[i].toUpperCase()] || 0;
23295
+ if (curr < prev) num -= curr;
23296
+ else num += curr;
23297
+ prev = curr;
23298
+ }
23299
+ return num;
23300
+ }
23301
+ function getStartNumberFromRoman(lvlText) {
23302
+ const match = lvlText.match(/^([ivxlcdmIVXLCDM]+)/);
23303
+ if (match) return romanToNumber(match[1]);
23304
+ return null;
23305
+ }
23306
+ const startHelperMap = /* @__PURE__ */ new Map([
23307
+ ["decimal", getStartNumber],
23308
+ ["lowerLetter", getStartNumberFromAlpha],
23309
+ ["upperLetter", getStartNumberFromAlpha],
23310
+ ["lowerRoman", getStartNumberFromRoman],
23311
+ ["upperRoman", getStartNumberFromRoman],
23312
+ ["bullet", () => 1]
23227
23313
  ]);
23228
23314
  const handleDocxPaste = (html, editor, view, plugin2) => {
23229
23315
  const { converter } = editor;
@@ -23232,35 +23318,50 @@ const handleDocxPaste = (html, editor, view, plugin2) => {
23232
23318
  cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
23233
23319
  const tempDiv = document.createElement("div");
23234
23320
  tempDiv.innerHTML = cleanedHtml;
23235
- const paragraphs = tempDiv.querySelectorAll("p");
23236
- paragraphs.forEach((p) => {
23237
- const innerHTML3 = p.innerHTML;
23238
- if (!innerHTML3.includes("<!--[if !supportLists]")) return;
23239
- const styleAttr = p.getAttribute("style") || "";
23321
+ const data = tempDiv.querySelectorAll("p, li");
23322
+ const startMap = {};
23323
+ data.forEach((item) => {
23324
+ let type2;
23325
+ if (item.localName === "li") {
23326
+ type2 = "listItem";
23327
+ } else {
23328
+ const html2 = item.innerHTML;
23329
+ type2 = "p";
23330
+ if (!html2.includes("<!--[if !supportLists]")) return;
23331
+ }
23332
+ const styleAttr = item.getAttribute("style") || "";
23240
23333
  const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)\s+lfo(\d+)/);
23241
23334
  const css = tempDiv.querySelector("style").innerHTML;
23242
23335
  if (msoListMatch) {
23243
23336
  const [, abstractId, level, numId] = msoListMatch;
23244
23337
  const styles = extractListLevelStyles(css, abstractId, level);
23245
- const msoNumFormat = styles["mso-level-number-format"] || "decimal";
23246
- const abstractOverride = numDefMap.get(msoNumFormat);
23247
- if (!numId) return;
23248
- const abstractDefinition = getListAbstractDefinition(
23249
- abstractOverride ? abstractOverride.abstractNum : numId,
23250
- editor
23251
- );
23252
- let { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level);
23253
- if (abstractOverride.abstractNum === 1) lvlText = `%${level}.`;
23254
- p.setAttribute("data-num-id", numId);
23255
- p.setAttribute("data-list-level", level - 1);
23256
- p.setAttribute("data-start", start2);
23257
- p.setAttribute("data-lvl-text", styles["mso-level-text"] || lvlText);
23258
- p.setAttribute("data-num-fmt", abstractOverride.def || numFmt);
23338
+ let start2, numFmt, lvlText;
23339
+ if (type2 === "listItem") {
23340
+ const listType = item.parentNode.getAttribute("type");
23341
+ const startAttr = item.parentNode.getAttribute("start");
23342
+ if (!startMap[numId]) startMap[numId] = startAttr;
23343
+ start2 = startMap[numId];
23344
+ numFmt = numDefByTypeMap.get(listType);
23345
+ lvlText = `%${level}.`;
23346
+ } else {
23347
+ const msoNumFormat = styles["mso-level-number-format"] || "decimal";
23348
+ numFmt = numDefMap.get(msoNumFormat);
23349
+ const punc = item.children[0]?.innerText?.slice(-1) || ".";
23350
+ lvlText = numFmt === "bullet" ? normalizeLvlTextChar(styles["mso-level-text"]) : `%${level}${punc}`;
23351
+ const startGetter = startHelperMap.get(numFmt);
23352
+ if (!startMap[numId]) startMap[numId] = startGetter(item.children[0]?.innerText || "1");
23353
+ start2 = startMap[numId];
23354
+ }
23355
+ item.setAttribute("data-num-id", numId);
23356
+ item.setAttribute("data-list-level", parseInt(level) - 1);
23357
+ item.setAttribute("data-start", start2);
23358
+ item.setAttribute("data-lvl-text", lvlText);
23359
+ item.setAttribute("data-num-fmt", numFmt);
23259
23360
  const ptToPxRatio = 1.333;
23260
23361
  const indent = parseInt(styles["margin-left"]) * ptToPxRatio || 0;
23261
- if (indent > 0) p.setAttribute("data-left-indent", indent);
23362
+ if (indent > 0) item.setAttribute("data-left-indent", indent);
23262
23363
  }
23263
- extractAndRemoveConditionalPrefix(p);
23364
+ extractAndRemoveConditionalPrefix(item);
23264
23365
  });
23265
23366
  transformWordLists(tempDiv, editor);
23266
23367
  const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
@@ -23270,37 +23371,29 @@ const handleDocxPaste = (html, editor, view, plugin2) => {
23270
23371
  dispatch(view.state.tr.replaceSelectionWith(doc2, true));
23271
23372
  return true;
23272
23373
  };
23273
- const getLevelDefinition = (abstractDefinition, level) => {
23274
- if (!abstractDefinition || !abstractDefinition.elements) return null;
23275
- const levelElement = abstractDefinition.elements.find((el) => {
23276
- return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
23277
- });
23278
- if (!levelElement) return null;
23279
- const { elements } = levelElement;
23280
- const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
23281
- const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
23282
- const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
23283
- return { lvlText, start: start2, numFmt, elements };
23284
- };
23285
- const getListAbstractDefinition = (abstractId, editor) => {
23286
- const { abstracts = {} } = editor?.converter?.numbering;
23287
- return abstracts[abstractId] || null;
23288
- };
23289
23374
  const transformWordLists = (container, editor) => {
23290
- const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
23375
+ const listItems = Array.from(container.querySelectorAll("[data-num-id]"));
23291
23376
  const lists = {};
23292
23377
  const mappedLists = {};
23293
- for (const p of paragraphs) {
23294
- const level = parseInt(p.getAttribute("data-list-level"));
23295
- const numFmt = p.getAttribute("data-num-fmt");
23296
- const start2 = p.getAttribute("data-start");
23297
- const lvlText = p.getAttribute("data-lvl-text");
23298
- const indent = p.getAttribute("data-left-indent");
23299
- const importedId = p.getAttribute("data-num-id");
23378
+ for (const item of listItems) {
23379
+ const level = parseInt(item.getAttribute("data-list-level"));
23380
+ const numFmt = item.getAttribute("data-num-fmt");
23381
+ const start2 = item.getAttribute("data-start");
23382
+ const lvlText = item.getAttribute("data-lvl-text");
23383
+ const indent = item.getAttribute("data-left-indent");
23384
+ const importedId = item.getAttribute("data-num-id");
23300
23385
  if (!mappedLists[importedId]) mappedLists[importedId] = ListHelpers.getNewListId(editor);
23301
23386
  const id = mappedLists[importedId];
23302
23387
  const listType = numFmt === "bullet" ? "bulletList" : "orderedList";
23303
- ListHelpers.generateNewListDefinition({ numId: id, listType, editor });
23388
+ ListHelpers.generateNewListDefinition({
23389
+ numId: id,
23390
+ listType,
23391
+ level: level.toString(),
23392
+ start: start2,
23393
+ fmt: numFmt,
23394
+ text: lvlText,
23395
+ editor
23396
+ });
23304
23397
  if (!lists[id]) lists[id] = { levels: {} };
23305
23398
  const currentListByNumId = lists[id];
23306
23399
  if (!currentListByNumId.levels[level]) currentListByNumId.levels[level] = Number(start2) || 1;
@@ -23314,28 +23407,28 @@ const transformWordLists = (container, editor) => {
23314
23407
  const path = generateListPath(level, currentListByNumId.levels, start2);
23315
23408
  if (!path.length) path.push(currentListByNumId.levels[level]);
23316
23409
  const li = document.createElement("li");
23317
- li.innerHTML = p.innerHTML;
23410
+ li.innerHTML = item.innerHTML;
23318
23411
  li.setAttribute("data-num-id", id);
23319
23412
  li.setAttribute("data-list-level", JSON.stringify(path));
23320
23413
  li.setAttribute("data-level", level);
23321
23414
  li.setAttribute("data-lvl-text", lvlText);
23322
23415
  li.setAttribute("data-num-fmt", numFmt);
23323
23416
  if (indent) li.setAttribute("data-indent", JSON.stringify({ left: indent }));
23324
- if (p.hasAttribute("data-font-family")) {
23325
- li.setAttribute("data-font-family", p.getAttribute("data-font-family"));
23417
+ if (item.hasAttribute("data-font-family")) {
23418
+ li.setAttribute("data-font-family", item.getAttribute("data-font-family"));
23326
23419
  }
23327
- if (p.hasAttribute("data-font-size")) {
23328
- li.setAttribute("data-font-size", p.getAttribute("data-font-size"));
23420
+ if (item.hasAttribute("data-font-size")) {
23421
+ li.setAttribute("data-font-size", item.getAttribute("data-font-size"));
23329
23422
  }
23330
- const parentNode2 = p.parentNode;
23423
+ const parentNode2 = item.parentNode;
23331
23424
  let listForLevel;
23332
23425
  const newList = numFmt === "bullet" ? document.createElement("ul") : document.createElement("ol");
23333
23426
  newList.setAttribute("data-list-id", id);
23334
23427
  newList.level = level;
23335
- parentNode2.insertBefore(newList, p);
23428
+ parentNode2.insertBefore(newList, item);
23336
23429
  listForLevel = newList;
23337
23430
  listForLevel.appendChild(li);
23338
- p.remove();
23431
+ item.remove();
23339
23432
  }
23340
23433
  };
23341
23434
  const generateListPath = (level, levels, start2) => {
@@ -23349,8 +23442,8 @@ const generateListPath = (level, levels, start2) => {
23349
23442
  }
23350
23443
  return path;
23351
23444
  };
23352
- function extractAndRemoveConditionalPrefix(p) {
23353
- const nodes = Array.from(p.childNodes);
23445
+ function extractAndRemoveConditionalPrefix(item) {
23446
+ const nodes = Array.from(item.childNodes);
23354
23447
  let fontFamily2 = null;
23355
23448
  let fontSize2 = null;
23356
23449
  let start2 = -1, end2 = -1;
@@ -23371,10 +23464,10 @@ function extractAndRemoveConditionalPrefix(p) {
23371
23464
  }
23372
23465
  }
23373
23466
  for (let i = end2; i >= start2; i--) {
23374
- p.removeChild(p.childNodes[i]);
23467
+ item.removeChild(item.childNodes[i]);
23375
23468
  }
23376
- if (fontFamily2) p.setAttribute("data-font-family", fontFamily2);
23377
- if (fontSize2) p.setAttribute("data-font-size", fontSize2);
23469
+ if (fontFamily2) item.setAttribute("data-font-family", fontFamily2);
23470
+ if (fontSize2) item.setAttribute("data-font-size", fontSize2);
23378
23471
  }
23379
23472
  }
23380
23473
  const generateOrderedListIndex = ({ listLevel, lvlText, listNumberingType, customFormat }) => {
@@ -26100,7 +26193,7 @@ function generateTableCellProperties(node2) {
26100
26193
  const cellBordersElement = {
26101
26194
  name: "w:tcBorders",
26102
26195
  elements: Object.entries(borders).map(([key, value]) => {
26103
- if (!value.size) {
26196
+ if (!value.size || value.val === "none") {
26104
26197
  return {
26105
26198
  name: `w:${key}`,
26106
26199
  attributes: {
@@ -28920,7 +29013,7 @@ const _SuperConverter = class _SuperConverter2 {
28920
29013
  return;
28921
29014
  }
28922
29015
  }
28923
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.15.7-next.1") {
29016
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.15.7-next.3") {
28924
29017
  const customLocation = "docProps/custom.xml";
28925
29018
  if (!docx[customLocation]) {
28926
29019
  docx[customLocation] = generateCustomXml();
@@ -29399,7 +29492,7 @@ function storeSuperdocVersion(docx) {
29399
29492
  function generateCustomXml() {
29400
29493
  return DEFAULT_CUSTOM_XML;
29401
29494
  }
29402
- function generateSuperdocVersion(pid = 2, version2 = "0.15.7-next.1") {
29495
+ function generateSuperdocVersion(pid = 2, version2 = "0.15.7-next.3") {
29403
29496
  return {
29404
29497
  type: "element",
29405
29498
  name: "property",
@@ -45726,7 +45819,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
45726
45819
  * @returns {Object | void} Migration results
45727
45820
  */
45728
45821
  processCollaborationMigrations() {
45729
- console.debug("[checkVersionMigrations] Current editor version", "0.15.7-next.1");
45822
+ console.debug("[checkVersionMigrations] Current editor version", "0.15.7-next.3");
45730
45823
  if (!this.options.ydoc) return;
45731
45824
  const metaMap = this.options.ydoc.getMap("meta");
45732
45825
  let docVersion = metaMap.get("version");