@harbour-enterprises/superdoc 0.12.34-next.3 → 0.13.0-RC2
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.
- package/dist/chunks/{super-editor.es-B9igwxv-.es.js → super-editor.es-B6M3d3ew.es.js} +1020 -1010
- package/dist/chunks/{super-editor.es-BbaXC2pT.cjs → super-editor.es-CG_E8Uh1.cjs} +1020 -1010
- package/dist/style.css +67 -54
- package/dist/super-editor/ai-writer.es.js +2 -2
- package/dist/super-editor/chunks/{converter-DzsjYmnd.js → converter-DdMoUfYl.js} +310 -441
- package/dist/super-editor/chunks/{docx-zipper-DQONSIAh.js → docx-zipper-CaPhHWh0.js} +1 -1
- package/dist/super-editor/chunks/{editor-CO-n6iZ8.js → editor-DfrK7LO9.js} +1653 -1507
- package/dist/super-editor/chunks/{toolbar-CNeu8BVd.js → toolbar-h35AzYvu.js} +2 -2
- package/dist/super-editor/converter.es.js +1 -1
- package/dist/super-editor/core/Attribute.d.ts +2 -2
- package/dist/super-editor/core/Editor.d.ts +8 -1
- package/dist/super-editor/core/Editor.d.ts.map +1 -1
- package/dist/super-editor/core/Schema.d.ts +2 -2
- package/dist/super-editor/core/commands/splitListItem.d.ts +1 -1
- package/dist/super-editor/core/commands/splitListItem.d.ts.map +1 -1
- package/dist/super-editor/core/helpers/list-numbering-helpers.d.ts +235 -0
- package/dist/super-editor/core/helpers/list-numbering-helpers.d.ts.map +1 -0
- package/dist/super-editor/core/super-converter/SuperConverter.d.ts +1 -1
- package/dist/super-editor/core/super-converter/SuperConverter.d.ts.map +1 -1
- package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
- package/dist/super-editor/core/super-converter/v2/importer/listImporter.d.ts +32 -5
- package/dist/super-editor/core/super-converter/v2/importer/listImporter.d.ts.map +1 -1
- package/dist/super-editor/core/super-converter/v2/importer/paragraphNodeImporter.d.ts.map +1 -1
- package/dist/super-editor/docx-zipper.es.js +2 -2
- package/dist/super-editor/editor.es.js +3 -3
- package/dist/super-editor/extensions/linked-styles/linked-styles.d.ts.map +1 -1
- package/dist/super-editor/extensions/list-item/ListItemNodeView.d.ts +56 -0
- package/dist/super-editor/extensions/list-item/ListItemNodeView.d.ts.map +1 -0
- package/dist/super-editor/extensions/list-item/list-item.d.ts.map +1 -1
- package/dist/super-editor/extensions/ordered-list/ordered-list.d.ts.map +1 -1
- package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
- package/dist/super-editor/file-zipper.es.js +1 -1
- package/dist/super-editor/style.css +40 -27
- package/dist/super-editor/super-editor.es.js +6 -6
- package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts +3 -0
- package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts.map +1 -0
- package/dist/super-editor/tests/e2e/test-app/vite.config.d.ts +1 -1
- package/dist/super-editor/tests/editor/listItemHelpers.test.d.ts +2 -0
- package/dist/super-editor/tests/editor/listItemHelpers.test.d.ts.map +1 -0
- package/dist/super-editor/tests/export/export-helpers/export-helpers.d.ts.map +1 -1
- package/dist/super-editor/toolbar.es.js +2 -2
- package/dist/super-editor.cjs +1 -1
- package/dist/super-editor.es.js +1 -1
- package/dist/superdoc.cjs +3 -5
- package/dist/superdoc.es.js +4 -6
- package/dist/superdoc.umd.js +1024 -1016
- package/dist/superdoc.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -17339,16 +17339,6 @@ const carbonCopy = (obj) => {
|
|
|
17339
17339
|
return void 0;
|
|
17340
17340
|
}
|
|
17341
17341
|
};
|
|
17342
|
-
const baseOrderedListDef$1 = {
|
|
17343
|
-
"attributes": {
|
|
17344
|
-
"w:abstractNumId": "1"
|
|
17345
|
-
}
|
|
17346
|
-
};
|
|
17347
|
-
const baseBulletList$1 = {
|
|
17348
|
-
"attributes": {
|
|
17349
|
-
"w:abstractNumId": "0"
|
|
17350
|
-
}
|
|
17351
|
-
};
|
|
17352
17342
|
const baseNumbering = {
|
|
17353
17343
|
"declaration": {
|
|
17354
17344
|
"attributes": {
|
|
@@ -18967,7 +18957,7 @@ function generateParagraphProperties(node2) {
|
|
|
18967
18957
|
};
|
|
18968
18958
|
pPrElements.push(spacingElement);
|
|
18969
18959
|
}
|
|
18970
|
-
if (indent) {
|
|
18960
|
+
if (indent && Object.values(indent).some((v) => v !== 0)) {
|
|
18971
18961
|
const { left: left2, right: right2, firstLine, hanging } = indent;
|
|
18972
18962
|
const attributes = {};
|
|
18973
18963
|
if (left2 || left2 === 0) attributes["w:left"] = pixelsToTwips(left2);
|
|
@@ -18982,7 +18972,7 @@ function generateParagraphProperties(node2) {
|
|
|
18982
18972
|
attributes
|
|
18983
18973
|
};
|
|
18984
18974
|
pPrElements.push(indentElement);
|
|
18985
|
-
} else if (textIndent) {
|
|
18975
|
+
} else if (textIndent && textIndent !== "0in") {
|
|
18986
18976
|
const indentElement = {
|
|
18987
18977
|
name: "w:ind",
|
|
18988
18978
|
attributes: {
|
|
@@ -19031,6 +19021,9 @@ function generateParagraphProperties(node2) {
|
|
|
19031
19021
|
if (sectPr) {
|
|
19032
19022
|
pPrElements.push(sectPr);
|
|
19033
19023
|
}
|
|
19024
|
+
const numPr = node2.attrs?.paragraphProperties?.elements?.find((n) => n.name === "w:numPr");
|
|
19025
|
+
const hasNumPr = pPrElements.some((n) => n.name === "w:numPr");
|
|
19026
|
+
if (numPr && !hasNumPr) pPrElements.push(numPr);
|
|
19034
19027
|
if (!pPrElements.length) return null;
|
|
19035
19028
|
return {
|
|
19036
19029
|
name: "w:pPr",
|
|
@@ -19279,157 +19272,68 @@ function addNewImageRelationship(params2, imagePath) {
|
|
|
19279
19272
|
return newId;
|
|
19280
19273
|
}
|
|
19281
19274
|
function translateList(params2) {
|
|
19282
|
-
const {
|
|
19283
|
-
const
|
|
19284
|
-
|
|
19285
|
-
|
|
19286
|
-
|
|
19287
|
-
|
|
19288
|
-
|
|
19289
|
-
|
|
19290
|
-
|
|
19291
|
-
|
|
19292
|
-
|
|
19293
|
-
|
|
19294
|
-
|
|
19295
|
-
|
|
19296
|
-
|
|
19297
|
-
|
|
19298
|
-
|
|
19299
|
-
|
|
19300
|
-
|
|
19301
|
-
|
|
19302
|
-
|
|
19303
|
-
|
|
19304
|
-
|
|
19305
|
-
|
|
19306
|
-
|
|
19307
|
-
|
|
19308
|
-
|
|
19309
|
-
|
|
19310
|
-
|
|
19311
|
-
|
|
19312
|
-
|
|
19313
|
-
|
|
19314
|
-
|
|
19315
|
-
|
|
19316
|
-
|
|
19317
|
-
|
|
19318
|
-
|
|
19319
|
-
|
|
19320
|
-
|
|
19321
|
-
|
|
19322
|
-
if (el.name === "w:sdt") {
|
|
19323
|
-
const contentIndex = el.elements.findIndex((e) => e.name === "w:sdtContent");
|
|
19324
|
-
const content3 = el.elements[contentIndex];
|
|
19325
|
-
const innerContent = content3.elements[0];
|
|
19326
|
-
if (innerContent.name === "w:p") {
|
|
19327
|
-
content3.elements = innerContent.elements;
|
|
19328
|
-
}
|
|
19329
|
-
return {
|
|
19330
|
-
name: "w:r",
|
|
19331
|
-
type: "element",
|
|
19332
|
-
elements: [el]
|
|
19333
|
-
};
|
|
19334
|
-
} else {
|
|
19335
|
-
return el;
|
|
19336
|
-
}
|
|
19337
|
-
});
|
|
19338
|
-
const { attributes: generalAttributes } = attrs;
|
|
19339
|
-
const { originalInlineRunProps } = generalAttributes || {};
|
|
19340
|
-
if (originalInlineRunProps) pPr.elements.push(originalInlineRunProps);
|
|
19341
|
-
if (propsElementIndex === -1) {
|
|
19342
|
-
outputNode.elements.unshift(carbonCopy(pPr));
|
|
19343
|
-
} else {
|
|
19344
|
-
const resultProps = carbonCopy(pPr).elements.map((item) => {
|
|
19345
|
-
const isChanged = outputNode.elements[propsElementIndex].elements.find((e) => e.name === item.name);
|
|
19346
|
-
return isChanged ? isChanged : item;
|
|
19347
|
-
});
|
|
19348
|
-
outputNode.elements[propsElementIndex].elements = resultProps;
|
|
19349
|
-
}
|
|
19350
|
-
let importedFontSize;
|
|
19351
|
-
if (listNode.attrs?.importedFontSize) {
|
|
19352
|
-
const fontNoUnit = parseInt(listNode.attrs.importedFontSize.split("pt")[0]);
|
|
19353
|
-
importedFontSize = {
|
|
19354
|
-
name: "w:sz",
|
|
19355
|
-
attributes: { "w:val": fontNoUnit * 2 }
|
|
19356
|
-
};
|
|
19357
|
-
}
|
|
19358
|
-
let importedFontFamily;
|
|
19359
|
-
if (listNode.attrs?.importedFontFamily) {
|
|
19360
|
-
importedFontFamily = {
|
|
19361
|
-
name: "w:rFonts",
|
|
19362
|
-
attributes: { "w:ascii": listNode.attrs?.importedFontFamily, "w:hAnsi": listNode.attrs?.importedFontFamily }
|
|
19363
|
-
};
|
|
19364
|
-
}
|
|
19365
|
-
const rPrElement = outputNode.elements.find((e) => e.name === "w:rPr");
|
|
19366
|
-
if (rPrElement) {
|
|
19367
|
-
rPrElement.elements.push(fontSize);
|
|
19368
|
-
} else if (importedFontSize || importedFontFamily) {
|
|
19369
|
-
const elements = [];
|
|
19370
|
-
if (importedFontSize) elements.push(importedFontSize);
|
|
19371
|
-
if (importedFontFamily) elements.push(importedFontFamily);
|
|
19372
|
-
outputNode.elements.unshift({ name: "w:rPr", elements });
|
|
19373
|
-
}
|
|
19374
|
-
if (index2 !== 0) {
|
|
19375
|
-
const currentpPr = outputNode.elements.find((e) => e.name === "w:pPr");
|
|
19376
|
-
const numPrIndex = currentpPr.elements.findIndex((e) => e.name === "w:numPr");
|
|
19377
|
-
if (numPrIndex !== -1) currentpPr.elements.splice(numPrIndex, 1);
|
|
19378
|
-
}
|
|
19379
|
-
listNodes.push(outputNode);
|
|
19380
|
-
});
|
|
19381
|
-
});
|
|
19382
|
-
return listNodes;
|
|
19383
|
-
}
|
|
19384
|
-
function generateNewListDefinition$1(params2, listType) {
|
|
19385
|
-
const nextNumbering = getLargestListDefinitionIndex(params2.converter?.numbering?.definitions);
|
|
19386
|
-
const definition = listType === "bullet" ? baseBulletList$1 : baseOrderedListDef$1;
|
|
19387
|
-
const listId = nextNumbering;
|
|
19388
|
-
const abstractId = definition.attributes["w:abstractNumId"];
|
|
19389
|
-
const newNumDef = {
|
|
19275
|
+
const { node: node2 } = params2;
|
|
19276
|
+
const { attrs = {} } = node2;
|
|
19277
|
+
if (node2.content.length > 1) {
|
|
19278
|
+
flattenContent(params2);
|
|
19279
|
+
throw new Error("Multi list not supported yet");
|
|
19280
|
+
}
|
|
19281
|
+
const listItem = node2.content[0];
|
|
19282
|
+
const { numId, level } = listItem.attrs;
|
|
19283
|
+
let numPrTag;
|
|
19284
|
+
if (numId) {
|
|
19285
|
+
numPrTag = generateNumPrTag(numId, level);
|
|
19286
|
+
}
|
|
19287
|
+
const paragraphNode = node2.content[0]?.content[0];
|
|
19288
|
+
const outputNode = exportSchemaToJson({ ...params2, node: paragraphNode });
|
|
19289
|
+
const pPr = outputNode.elements.find((n) => n.name === "w:pPr");
|
|
19290
|
+
if (pPr && pPr.elements) pPr.elements.unshift(numPrTag);
|
|
19291
|
+
const indentTag = restoreIndent(listItem.attrs.indent);
|
|
19292
|
+
indentTag && pPr?.elements?.push(indentTag);
|
|
19293
|
+
const runNode = outputNode.elements?.find((n) => n.name === "w:r");
|
|
19294
|
+
const rPr = runNode?.elements?.find((n) => n.name === "w:rPr");
|
|
19295
|
+
if (rPr) pPr.elements.push(rPr);
|
|
19296
|
+
if (listItem.attrs.numPrType !== "inline") {
|
|
19297
|
+
const numPrIndex = pPr?.elements?.findIndex((e) => e.name === "w:numPr");
|
|
19298
|
+
if (numPrIndex !== -1) {
|
|
19299
|
+
pPr?.elements?.splice(numPrIndex, 1);
|
|
19300
|
+
}
|
|
19301
|
+
}
|
|
19302
|
+
return [outputNode];
|
|
19303
|
+
}
|
|
19304
|
+
const restoreIndent = (indent) => {
|
|
19305
|
+
const attributes = {};
|
|
19306
|
+
if (!indent) indent = {};
|
|
19307
|
+
if (indent.left || indent.left === 0) attributes["w:left"] = pixelsToTwips(indent.left);
|
|
19308
|
+
if (indent.right || indent.right === 0) attributes["w:right"] = pixelsToTwips(indent.right);
|
|
19309
|
+
if (indent.firstLine || indent.firstLine === 0) attributes["w:firstLine"] = pixelsToTwips(indent.firstLine);
|
|
19310
|
+
if (indent.hanging || indent.hanging === 0) attributes["w:hanging"] = pixelsToTwips(indent.hanging);
|
|
19311
|
+
if (indent.leftChars || indent.leftChars === 0) attributes["w:leftChars"] = pixelsToTwips(indent.leftChars);
|
|
19312
|
+
if (!Object.keys(attributes).length) return;
|
|
19313
|
+
return {
|
|
19314
|
+
name: "w:ind",
|
|
19390
19315
|
type: "element",
|
|
19391
|
-
|
|
19392
|
-
attributes: {
|
|
19393
|
-
"w:numId": String(listId),
|
|
19394
|
-
"w16cid:durableId": "485517411"
|
|
19395
|
-
},
|
|
19396
|
-
elements: [
|
|
19397
|
-
{ name: "w:abstractNumId", attributes: { "w:val": String(abstractId) } }
|
|
19398
|
-
]
|
|
19316
|
+
attributes
|
|
19399
19317
|
};
|
|
19400
|
-
params2.converter.numbering.definitions[listId] = newNumDef;
|
|
19401
|
-
return listId;
|
|
19402
|
-
}
|
|
19403
|
-
const getLargestListDefinitionIndex = (definitions) => {
|
|
19404
|
-
if (!definitions || !Object.keys(definitions).length) return 0;
|
|
19405
|
-
const maxKey = Math.max(...Object.keys(definitions).map((key) => parseInt(key, 10)));
|
|
19406
|
-
return maxKey + 1;
|
|
19407
19318
|
};
|
|
19408
|
-
|
|
19319
|
+
const generateNumPrTag = (numId, level) => {
|
|
19409
19320
|
return {
|
|
19410
|
-
name: "w:
|
|
19321
|
+
name: "w:numPr",
|
|
19411
19322
|
type: "element",
|
|
19412
19323
|
elements: [
|
|
19413
19324
|
{
|
|
19414
|
-
name: "w:
|
|
19325
|
+
name: "w:numId",
|
|
19415
19326
|
type: "element",
|
|
19416
|
-
|
|
19417
|
-
{
|
|
19418
|
-
name: "w:ilvl",
|
|
19419
|
-
type: "element",
|
|
19420
|
-
attributes: { "w:val": level }
|
|
19421
|
-
},
|
|
19422
|
-
{
|
|
19423
|
-
name: "w:numId",
|
|
19424
|
-
type: "element",
|
|
19425
|
-
attributes: { "w:val": numId }
|
|
19426
|
-
}
|
|
19427
|
-
]
|
|
19327
|
+
attributes: { "w:val": numId }
|
|
19428
19328
|
},
|
|
19429
|
-
|
|
19329
|
+
{
|
|
19330
|
+
name: "w:ilvl",
|
|
19331
|
+
type: "element",
|
|
19332
|
+
attributes: { "w:val": level }
|
|
19333
|
+
}
|
|
19430
19334
|
]
|
|
19431
19335
|
};
|
|
19432
|
-
}
|
|
19336
|
+
};
|
|
19433
19337
|
function flattenContent({ node: node2 }) {
|
|
19434
19338
|
const { content, attrs = {} } = node2;
|
|
19435
19339
|
const { listId, syncId } = node2.attrs || {};
|
|
@@ -19500,10 +19404,7 @@ function preProcessVerticalMergeCells(table, { editorSchema }) {
|
|
|
19500
19404
|
if (!row.content) continue;
|
|
19501
19405
|
for (let cellIndex = 0; cellIndex < row.content?.length; cellIndex++) {
|
|
19502
19406
|
const cell = row.content[cellIndex];
|
|
19503
|
-
if (!cell)
|
|
19504
|
-
console.log("no cell");
|
|
19505
|
-
continue;
|
|
19506
|
-
}
|
|
19407
|
+
if (!cell) continue;
|
|
19507
19408
|
const { attrs } = cell;
|
|
19508
19409
|
if (attrs.rowspan > 1) {
|
|
19509
19410
|
const rowsToChange = content.slice(rowIndex + 1, rowIndex + attrs.rowspan);
|
|
@@ -21232,11 +21133,6 @@ function getElementName(element) {
|
|
|
21232
21133
|
const isPropertiesElement = (element) => {
|
|
21233
21134
|
return !!SuperConverter.propertyTypes[element.name || element.type];
|
|
21234
21135
|
};
|
|
21235
|
-
function hasTextNode(elements) {
|
|
21236
|
-
const runs = elements.filter((el) => el.name === "w:r");
|
|
21237
|
-
const runsHaveText = runs.some((run2) => run2.elements.some((el) => el.name === "w:t"));
|
|
21238
|
-
return runsHaveText;
|
|
21239
|
-
}
|
|
21240
21136
|
const handleTrackChangeNode = (params2) => {
|
|
21241
21137
|
const { nodes, nodeListHandler: nodeListHandler2 } = params2;
|
|
21242
21138
|
if (nodes.length === 0 || !(nodes[0].name === "w:del" || nodes[0].name === "w:ins" || nodes[0].name === "w:sdt")) {
|
|
@@ -21438,219 +21334,118 @@ const areAttrsEqual = (attrsA = {}, attrsB = {}) => {
|
|
|
21438
21334
|
};
|
|
21439
21335
|
const handleListNode = (params2) => {
|
|
21440
21336
|
const { nodes, lists, docx } = params2;
|
|
21441
|
-
if (nodes.length === 0 || nodes[0].name !== "w:p") {
|
|
21337
|
+
if (nodes.length === 0 || nodes[0].name !== "w:p" || nodes[0].isList) {
|
|
21442
21338
|
return { nodes: [], consumed: 0 };
|
|
21443
21339
|
}
|
|
21444
21340
|
const node2 = carbonCopy(nodes[0]);
|
|
21445
|
-
const
|
|
21446
|
-
|
|
21447
|
-
|
|
21448
|
-
|
|
21449
|
-
const siblings = carbonCopy(nodes);
|
|
21450
|
-
const listItems = [];
|
|
21451
|
-
let possibleList = siblings.shift();
|
|
21452
|
-
while (possibleList && testForList(possibleList, docx)) {
|
|
21453
|
-
listItems.push(possibleList);
|
|
21454
|
-
possibleList = siblings.shift();
|
|
21455
|
-
if (possibleList?.elements && !hasTextNode(possibleList.elements)) {
|
|
21456
|
-
listItems.push(possibleList);
|
|
21457
|
-
possibleList = siblings.shift();
|
|
21458
|
-
}
|
|
21459
|
-
}
|
|
21460
|
-
const listNodes = handleListNodes({ listItems, params: params2, originalPpr });
|
|
21341
|
+
const isList2 = testForList(node2, docx);
|
|
21342
|
+
if (isList2) {
|
|
21343
|
+
node2.isList = true;
|
|
21344
|
+
const result = handleListNodes(params2, node2);
|
|
21461
21345
|
return {
|
|
21462
|
-
nodes: [
|
|
21463
|
-
consumed:
|
|
21464
|
-
lists
|
|
21346
|
+
nodes: [result],
|
|
21347
|
+
consumed: 1
|
|
21465
21348
|
};
|
|
21466
21349
|
} else {
|
|
21467
|
-
return { nodes: [], consumed: 0
|
|
21350
|
+
return { nodes: [], consumed: 0 };
|
|
21468
21351
|
}
|
|
21469
21352
|
};
|
|
21470
21353
|
const listHandlerEntity = {
|
|
21471
21354
|
handlerName: "listHandler",
|
|
21472
21355
|
handler: handleListNode
|
|
21473
21356
|
};
|
|
21474
|
-
function handleListNodes({
|
|
21475
|
-
listItems,
|
|
21476
|
-
originalPpr,
|
|
21477
|
-
params: params2,
|
|
21478
|
-
listLevel = 0,
|
|
21479
|
-
actualListLevel = 0,
|
|
21480
|
-
currentListNumId = null,
|
|
21481
|
-
path = "",
|
|
21482
|
-
isNested = false
|
|
21483
|
-
}) {
|
|
21357
|
+
function handleListNodes(params2, node2) {
|
|
21484
21358
|
const { docx, nodeListHandler: nodeListHandler2, lists } = params2;
|
|
21485
|
-
const
|
|
21486
|
-
let overallListType;
|
|
21487
|
-
let listStyleType;
|
|
21488
|
-
const handleStandardNode2 = nodeListHandler2.handlerEntities.find(
|
|
21489
|
-
(e) => e.handlerName === "standardNodeHandler"
|
|
21490
|
-
)?.handler;
|
|
21491
|
-
if (!handleStandardNode2) {
|
|
21492
|
-
console.error("Standard node handler not found");
|
|
21493
|
-
return { nodes: [], consumed: 0 };
|
|
21494
|
-
}
|
|
21495
|
-
const initialpPr = listItems[0].elements.find((el) => el.name === "w:pPr");
|
|
21359
|
+
const initialpPr = node2.elements.find((el) => el.name === "w:pPr");
|
|
21496
21360
|
const styleTag = initialpPr?.elements?.find((el) => el.name === "w:pStyle");
|
|
21497
21361
|
const styleId = styleTag?.attributes["w:val"];
|
|
21498
|
-
const numPrTag = getNumPrRecursive({ node:
|
|
21499
|
-
currentListNumId = getNumIdFromTag(numPrTag);
|
|
21500
|
-
|
|
21501
|
-
|
|
21502
|
-
|
|
21503
|
-
|
|
21504
|
-
|
|
21505
|
-
|
|
21506
|
-
|
|
21507
|
-
|
|
21508
|
-
|
|
21509
|
-
|
|
21510
|
-
|
|
21511
|
-
|
|
21512
|
-
|
|
21513
|
-
|
|
21514
|
-
|
|
21515
|
-
|
|
21516
|
-
|
|
21517
|
-
|
|
21518
|
-
|
|
21519
|
-
|
|
21520
|
-
|
|
21521
|
-
|
|
21522
|
-
const
|
|
21523
|
-
|
|
21524
|
-
|
|
21525
|
-
|
|
21526
|
-
|
|
21527
|
-
|
|
21528
|
-
|
|
21529
|
-
|
|
21530
|
-
|
|
21531
|
-
|
|
21532
|
-
|
|
21533
|
-
|
|
21534
|
-
|
|
21535
|
-
|
|
21536
|
-
|
|
21537
|
-
|
|
21538
|
-
|
|
21539
|
-
|
|
21540
|
-
|
|
21541
|
-
const schemaElements = [];
|
|
21542
|
-
const nodeContents = nodeListHandler2.handler({ ...params2, nodes: [attributes.paragraphProperties, ...elements] })?.filter((n) => n) || [];
|
|
21543
|
-
let parNode = {
|
|
21544
|
-
type: "paragraph",
|
|
21545
|
-
content: nodeContents
|
|
21546
|
-
};
|
|
21547
|
-
if (parNode.content) {
|
|
21548
|
-
parNode = {
|
|
21549
|
-
...parNode,
|
|
21550
|
-
attrs: {
|
|
21551
|
-
textAlign: textStyle?.attrs.textAlign || textStyleFromStyles?.attrs.textAlign || null,
|
|
21552
|
-
rsidRDefault: attributes?.["w:rsidRDefault"] || null,
|
|
21553
|
-
styleId
|
|
21554
|
-
},
|
|
21555
|
-
content: mergeTextNodes(parNode.content)
|
|
21556
|
-
};
|
|
21557
|
-
}
|
|
21558
|
-
schemaElements.push(parNode);
|
|
21559
|
-
lastNestedListLevel = listLevel;
|
|
21560
|
-
let thisItemPath = [];
|
|
21561
|
-
if (listStyleType !== "bullet") {
|
|
21562
|
-
thisItemPath = [...path, lists[currentListNumId][listLevel]];
|
|
21563
|
-
lists[currentListNumId][actualListLevel]++;
|
|
21564
|
-
}
|
|
21565
|
-
if (!path.length && actualListLevel > 0) {
|
|
21566
|
-
const currentDef = lists[currentListNumId];
|
|
21567
|
-
if (currentDef) {
|
|
21568
|
-
const newPath = [];
|
|
21569
|
-
Object.keys(currentDef).forEach((key) => {
|
|
21570
|
-
newPath.push(currentDef[key]);
|
|
21571
|
-
});
|
|
21572
|
-
thisItemPath = newPath;
|
|
21573
|
-
}
|
|
21574
|
-
}
|
|
21575
|
-
const pPr = item.elements.find((el) => el.name === "w:pPr");
|
|
21576
|
-
let indent = pPr?.elements.find((el) => el.name === "w:ind");
|
|
21577
|
-
const pPrFromStyles = matchedStyle?.elements?.find((style2) => style2.name === "w:pPr");
|
|
21578
|
-
const stylesIndent = pPrFromStyles?.elements?.find((el) => el.name === "w:ind");
|
|
21579
|
-
if (!indent) indent = stylesIndent;
|
|
21580
|
-
if (indent) {
|
|
21581
|
-
const indentAttrs = {};
|
|
21582
|
-
if (!indent.attributes) indent.attributes = {};
|
|
21583
|
-
if (indent.attributes["w:left"] !== void 0) indentAttrs.left = twipsToPixels(indent.attributes["w:left"]);
|
|
21584
|
-
if (indent.attributes["w:right"] !== void 0) indentAttrs.right = twipsToPixels(indent.attributes["w:right"]);
|
|
21585
|
-
if (indent.attributes["w:firstLine"] !== void 0) indentAttrs.firstLine = twipsToPixels(indent.attributes["w:firstLine"]);
|
|
21586
|
-
if (indent.attributes["w:hanging"] !== void 0) indentAttrs.hanging = twipsToPixels(indent.attributes["w:hanging"]);
|
|
21587
|
-
nodeAttributes["indent"] = indentAttrs;
|
|
21588
|
-
}
|
|
21589
|
-
if (listpPrs) nodeAttributes["listParagraphProperties"] = listpPrs;
|
|
21590
|
-
if (listrPrs) nodeAttributes["listRunProperties"] = listrPrs;
|
|
21591
|
-
nodeAttributes["textStyle"] = textStyle;
|
|
21592
|
-
nodeAttributes["order"] = start2;
|
|
21593
|
-
nodeAttributes["lvlText"] = lvlText;
|
|
21594
|
-
nodeAttributes["lvlJc"] = textStyle?.attrs.textAlign;
|
|
21595
|
-
nodeAttributes["listLevel"] = thisItemPath;
|
|
21596
|
-
nodeAttributes["listNumberingType"] = listOrderingType;
|
|
21597
|
-
nodeAttributes["attributes"] = {
|
|
21598
|
-
parentAttributes: item?.attributes || null
|
|
21599
|
-
};
|
|
21600
|
-
const originalRunProps = originalPpr?.elements?.find((el) => el.name === "w:rPr");
|
|
21601
|
-
if (originalRunProps) {
|
|
21602
|
-
nodeAttributes.attributes["originalInlineRunProps"] = originalRunProps;
|
|
21603
|
-
}
|
|
21604
|
-
nodeAttributes["numId"] = numId;
|
|
21605
|
-
if (docx) {
|
|
21606
|
-
nodeAttributes["spacing"] = getParagraphSpacing(item, docx, styleId);
|
|
21607
|
-
}
|
|
21608
|
-
const newListItem = createListItem(schemaElements, nodeAttributes, []);
|
|
21609
|
-
parsedListItems.push(newListItem);
|
|
21610
|
-
} else if (isNested2) {
|
|
21611
|
-
const newPath = [...path, lists[currentListNumId][listLevel]];
|
|
21612
|
-
const sublist = handleListNodes({
|
|
21613
|
-
listItems: listItems.slice(index2),
|
|
21614
|
-
originalPpr,
|
|
21615
|
-
params: params2,
|
|
21616
|
-
listLevel: listLevel + 1,
|
|
21617
|
-
actualListLevel: listLevel,
|
|
21618
|
-
currentListNumId: numId,
|
|
21619
|
-
path: newPath,
|
|
21620
|
-
isNested: true
|
|
21621
|
-
});
|
|
21622
|
-
lastNestedListLevel = sublist.lastNestedListLevel;
|
|
21623
|
-
delete sublist.lastNestedListLevel;
|
|
21624
|
-
const lastItem = parsedListItems[parsedListItems.length - 1];
|
|
21625
|
-
if (!lastItem) {
|
|
21626
|
-
parsedListItems.push(createListItem([sublist], nodeAttributes, []));
|
|
21627
|
-
} else {
|
|
21628
|
-
lastItem.content.push(sublist);
|
|
21629
|
-
}
|
|
21630
|
-
} else if (!numId) {
|
|
21631
|
-
item.seen = true;
|
|
21632
|
-
const n = handleStandardNode2({ ...params2, nodes: [item] }).nodes[0];
|
|
21633
|
-
parsedListItems[parsedListItems.length - 1]?.content.push(n);
|
|
21634
|
-
} else {
|
|
21635
|
-
lastNestedListLevel = listLevel;
|
|
21636
|
-
if (listLevel > 0 && item.elements[0].elements.find((el) => el.name === "w:numPr")) {
|
|
21637
|
-
lists[currentListNumId][listLevel] = 0;
|
|
21362
|
+
const { numPr: numPrTag, type: numPrType } = getNumPrRecursive({ node: node2, styleId, docx });
|
|
21363
|
+
const currentListNumId = getNumIdFromTag(numPrTag);
|
|
21364
|
+
const iLvlTag = numPrTag?.elements?.find((el) => el.name === "w:ilvl");
|
|
21365
|
+
let iLvl = Number(iLvlTag?.attributes["w:val"]);
|
|
21366
|
+
if (!iLvl && iLvl !== 0) iLvl = getOutlineLevelFromStyleTag(styleId, docx);
|
|
21367
|
+
const {
|
|
21368
|
+
listType,
|
|
21369
|
+
listOrderingType,
|
|
21370
|
+
listrPrs,
|
|
21371
|
+
listpPrs,
|
|
21372
|
+
start: start2,
|
|
21373
|
+
lvlText,
|
|
21374
|
+
lvlJc
|
|
21375
|
+
} = getNodeNumberingDefinition(node2, iLvl, docx);
|
|
21376
|
+
if (!listType) {
|
|
21377
|
+
const pPrIndex = node2.elements.findIndex((el) => el.name === "w:pPr");
|
|
21378
|
+
const pPr = node2.elements[pPrIndex];
|
|
21379
|
+
const numPrIndex2 = pPr?.elements?.findIndex((el) => el.name === "w:numPr");
|
|
21380
|
+
if (numPrIndex2 >= 0) {
|
|
21381
|
+
pPr?.elements?.splice(numPrIndex2, 1);
|
|
21382
|
+
node2.elements[pPrIndex] = pPr;
|
|
21383
|
+
}
|
|
21384
|
+
const styleIdIndex = pPr?.elements?.findIndex((el) => el.name === "w:pStyle");
|
|
21385
|
+
if (styleIdIndex >= 0) pPr?.elements?.splice(styleIdIndex, 1);
|
|
21386
|
+
const fallBack = nodeListHandler2.handler({ ...params2, nodes: [node2] })?.filter((n) => n);
|
|
21387
|
+
return fallBack[0];
|
|
21388
|
+
}
|
|
21389
|
+
if (!lists[currentListNumId]) lists[currentListNumId] = { levels: {} };
|
|
21390
|
+
const currentListByNumId = lists[currentListNumId];
|
|
21391
|
+
if (!currentListByNumId.levels[iLvl]) currentListByNumId.levels[iLvl] = Number(start2) || 1;
|
|
21392
|
+
else currentListByNumId.levels[iLvl]++;
|
|
21393
|
+
Object.keys(currentListByNumId.levels).forEach((key) => {
|
|
21394
|
+
const level = Number(key);
|
|
21395
|
+
if (level > iLvl) {
|
|
21396
|
+
delete currentListByNumId.levels[level];
|
|
21397
|
+
}
|
|
21398
|
+
});
|
|
21399
|
+
const path = [];
|
|
21400
|
+
if (iLvl > 0) {
|
|
21401
|
+
for (let i = iLvl; i >= 0; i--) {
|
|
21402
|
+
const { start: lvlStart } = getNodeNumberingDefinition(node2, i, docx);
|
|
21403
|
+
if (!currentListByNumId.levels[i]) {
|
|
21404
|
+
currentListByNumId.levels[i] = Number(lvlStart);
|
|
21638
21405
|
}
|
|
21639
|
-
|
|
21406
|
+
path.unshift(currentListByNumId.levels[i]);
|
|
21640
21407
|
}
|
|
21641
21408
|
}
|
|
21409
|
+
if (!path.length) path.push(currentListByNumId.levels[iLvl]);
|
|
21410
|
+
const attrs = {};
|
|
21411
|
+
attrs.lvlText = lvlText;
|
|
21412
|
+
attrs.listLevel = path;
|
|
21413
|
+
attrs.listNumberingType = listOrderingType;
|
|
21414
|
+
attrs.numId = currentListNumId;
|
|
21415
|
+
attrs.level = iLvl;
|
|
21416
|
+
attrs.numPrType = numPrType;
|
|
21417
|
+
attrs.styleId = styleId;
|
|
21418
|
+
node2.isList = true;
|
|
21419
|
+
const nodePpr = node2.attrs?.paragraphProperties?.elements?.find((el) => el.name === "w:pPr");
|
|
21420
|
+
const numPrIndex = node2.attrs?.paragraphProperties?.elements?.findIndex((el) => el.name === "w:numPr");
|
|
21421
|
+
nodePpr?.elements?.splice(numPrIndex, 1);
|
|
21422
|
+
const listContents = nodeListHandler2.handler({ ...params2, nodes: [node2] });
|
|
21423
|
+
const innerParagraph = listContents.find((el) => el.type === "paragraph");
|
|
21424
|
+
const firstElement = innerParagraph.content[0];
|
|
21425
|
+
firstElement?.marks?.find((mark) => mark.type === "textStyle");
|
|
21426
|
+
attrs.indent = listpPrs?.indent;
|
|
21427
|
+
const processedContents = listContents.map((el, index2) => {
|
|
21428
|
+
const { attrs: elementAttrs } = el;
|
|
21429
|
+
const { indent, textIndent, paragraphProperties, ...rest } = elementAttrs;
|
|
21430
|
+
if (index2 === 0 && !attrs.indent) attrs.indent = indent;
|
|
21431
|
+
return {
|
|
21432
|
+
...el,
|
|
21433
|
+
attrs: rest
|
|
21434
|
+
};
|
|
21435
|
+
});
|
|
21436
|
+
const listItem = {
|
|
21437
|
+
type: "listItem",
|
|
21438
|
+
content: processedContents || [],
|
|
21439
|
+
attrs
|
|
21440
|
+
};
|
|
21642
21441
|
const resultingList = {
|
|
21643
|
-
type:
|
|
21644
|
-
content:
|
|
21442
|
+
type: listType,
|
|
21443
|
+
content: [listItem],
|
|
21645
21444
|
attrs: {
|
|
21646
|
-
"list-style-type":
|
|
21647
|
-
listId: currentListNumId
|
|
21648
|
-
attributes: {
|
|
21649
|
-
parentAttributes: listItems[0]?.attributes || null
|
|
21650
|
-
}
|
|
21445
|
+
"list-style-type": listOrderingType,
|
|
21446
|
+
listId: currentListNumId
|
|
21651
21447
|
}
|
|
21652
21448
|
};
|
|
21653
|
-
if (isNested) resultingList.lastNestedListLevel = lastNestedListLevel;
|
|
21654
21449
|
return resultingList;
|
|
21655
21450
|
}
|
|
21656
21451
|
const getOutlineLevelFromStyleTag = (styleTag, docx) => {
|
|
@@ -21669,11 +21464,27 @@ function testForList(node2, docx) {
|
|
|
21669
21464
|
const paragraphStyle = pPr.elements?.find((el) => el.name === "w:pStyle");
|
|
21670
21465
|
let numPr = pPr.elements?.find((el) => el.name === "w:numPr");
|
|
21671
21466
|
let numId = getNumIdFromTag(numPr);
|
|
21467
|
+
const ilvlTag = numPr?.elements?.find((el) => el.name === "w:ilvl");
|
|
21468
|
+
let ilvl = ilvlTag?.attributes["w:val"];
|
|
21469
|
+
let outlinelvl;
|
|
21672
21470
|
const styleId = paragraphStyle?.attributes["w:val"];
|
|
21673
|
-
|
|
21674
|
-
|
|
21471
|
+
const styleTag = getStyleTagFromStyleId(styleId, docx);
|
|
21472
|
+
if (styleTag && !numId) {
|
|
21473
|
+
const { numPr: numPrRecursve, type: type2 } = getNumPrRecursive({ node: node2, styleId, docx });
|
|
21474
|
+
numPr = numPrRecursve;
|
|
21675
21475
|
numId = getNumIdFromTag(numPr);
|
|
21676
|
-
|
|
21476
|
+
const stylePpr = styleTag?.elements?.find((el) => el.name === "w:pPr");
|
|
21477
|
+
stylePpr?.elements?.find((el) => el.name === "w:numPr");
|
|
21478
|
+
ilvl = stylePpr?.elements?.find((el) => el.name === "w:ilvl")?.attributes["w:val"];
|
|
21479
|
+
outlinelvl = stylePpr?.elements?.find((el) => el.name === "w:outlineLvl")?.attributes["w:val"];
|
|
21480
|
+
ilvl = outlinelvl || ilvl;
|
|
21481
|
+
}
|
|
21482
|
+
const numbering = docx["word/numbering.xml"] || {};
|
|
21483
|
+
const numDefinition = numbering?.elements?.[0].elements?.find((el) => el.attributes?.["w:numId"] == numId);
|
|
21484
|
+
const abstractNumId = numDefinition?.elements?.find((el) => el.name === "w:abstractNumId")?.attributes["w:val"];
|
|
21485
|
+
const abstractNumDefinition = numbering?.elements?.[0].elements?.find((el) => el.attributes?.["w:abstractNumId"] == abstractNumId);
|
|
21486
|
+
const levelDefinition = abstractNumDefinition?.elements?.find((el) => el.name === "w:lvl" && el.attributes?.["w:ilvl"] == ilvl);
|
|
21487
|
+
if (!levelDefinition) return false;
|
|
21677
21488
|
return !!numId;
|
|
21678
21489
|
}
|
|
21679
21490
|
const getNumIdFromTag = (tag) => {
|
|
@@ -21681,20 +21492,19 @@ const getNumIdFromTag = (tag) => {
|
|
|
21681
21492
|
};
|
|
21682
21493
|
function getStyleTagFromStyleId(styleId, docx) {
|
|
21683
21494
|
const styles = docx["word/styles.xml"];
|
|
21684
|
-
if (!styles) {
|
|
21685
|
-
return {};
|
|
21686
|
-
}
|
|
21495
|
+
if (!styles) return {};
|
|
21687
21496
|
const styleEls = styles.elements;
|
|
21688
21497
|
const wStyles = styleEls.find((el) => el.name === "w:styles");
|
|
21689
21498
|
const styleTags = wStyles.elements.filter((style2) => style2.name === "w:style");
|
|
21690
|
-
|
|
21499
|
+
const styleDef = styleTags.find((tag) => tag.attributes["w:styleId"] === styleId);
|
|
21500
|
+
return styleDef;
|
|
21691
21501
|
}
|
|
21692
21502
|
function getNumPrRecursive({ node: node2, styleId, docx, seenStyleIds = /* @__PURE__ */ new Set() }) {
|
|
21693
21503
|
const initialPpr = node2?.elements?.find((el) => el.name === "w:pPr");
|
|
21694
21504
|
const initialNumPr = initialPpr?.elements?.find((el) => el.name === "w:numPr");
|
|
21695
21505
|
let numPr = initialNumPr;
|
|
21696
21506
|
let numId = getNumIdFromTag(numPr);
|
|
21697
|
-
if (numId) return numPr;
|
|
21507
|
+
if (numId) return { numPr, type: "inline" };
|
|
21698
21508
|
const matchedStyle = getStyleTagFromStyleId(styleId, docx);
|
|
21699
21509
|
const pPr = matchedStyle?.elements?.find((style2) => style2.name === "w:pPr");
|
|
21700
21510
|
numPr = pPr?.elements?.find((style2) => style2.name === "w:numPr");
|
|
@@ -21703,18 +21513,10 @@ function getNumPrRecursive({ node: node2, styleId, docx, seenStyleIds = /* @__PU
|
|
|
21703
21513
|
if (!numId && !seenStyleIds.has(styleId)) {
|
|
21704
21514
|
const basedOnStyleId = basedOn?.attributes["w:val"];
|
|
21705
21515
|
seenStyleIds.add(styleId);
|
|
21706
|
-
if (!basedOnStyleId) return
|
|
21516
|
+
if (!basedOnStyleId) return {};
|
|
21707
21517
|
return getNumPrRecursive({ styleId: basedOnStyleId, docx, seenStyleIds });
|
|
21708
21518
|
}
|
|
21709
|
-
return numPr;
|
|
21710
|
-
}
|
|
21711
|
-
function createListItem(content, attrs, marks) {
|
|
21712
|
-
return {
|
|
21713
|
-
type: "listItem",
|
|
21714
|
-
content,
|
|
21715
|
-
attrs,
|
|
21716
|
-
marks
|
|
21717
|
-
};
|
|
21519
|
+
return { numPr, type: "numbering" };
|
|
21718
21520
|
}
|
|
21719
21521
|
const orderedListTypes = [
|
|
21720
21522
|
"decimal",
|
|
@@ -21752,18 +21554,6 @@ const unorderedListTypes = [
|
|
|
21752
21554
|
"disc"
|
|
21753
21555
|
// Disc bullets (●)
|
|
21754
21556
|
];
|
|
21755
|
-
const isSameListLevelDefsExceptStart = ({ firstListId, secondListId, level, pStyleId, docx }) => {
|
|
21756
|
-
const { numFmt, lvlText, lvlJc } = getListLevelDefinitionTag(firstListId, level, pStyleId, docx);
|
|
21757
|
-
const {
|
|
21758
|
-
numFmt: numFmt2,
|
|
21759
|
-
lvlText: lvlText2,
|
|
21760
|
-
lvlJc: lvlJc2
|
|
21761
|
-
} = getListLevelDefinitionTag(secondListId, level, pStyleId, docx);
|
|
21762
|
-
const sameNumFmt = numFmt === numFmt2;
|
|
21763
|
-
const sameLvlText = lvlText === lvlText2;
|
|
21764
|
-
const sameLvlJc = lvlJc === lvlJc2;
|
|
21765
|
-
return sameNumFmt && sameLvlText && sameLvlJc;
|
|
21766
|
-
};
|
|
21767
21557
|
const getListNumIdFromStyleRef = (styleId, docx) => {
|
|
21768
21558
|
const styles = docx["word/styles.xml"];
|
|
21769
21559
|
if (!styles) return null;
|
|
@@ -21795,24 +21585,28 @@ const getListNumIdFromStyleRef = (styleId, docx) => {
|
|
|
21795
21585
|
}
|
|
21796
21586
|
return { numId, ilvl };
|
|
21797
21587
|
};
|
|
21798
|
-
const
|
|
21588
|
+
const getAbstractDefinition = (numId, docx) => {
|
|
21799
21589
|
const def = docx["word/numbering.xml"];
|
|
21800
21590
|
if (!def) return {};
|
|
21801
21591
|
const { elements } = def;
|
|
21802
21592
|
const listData = elements[0];
|
|
21803
|
-
if (pStyleId) {
|
|
21804
|
-
const { numId: numIdFromStyles, ilvl: iLvlFromStyles } = getListNumIdFromStyleRef(pStyleId, docx) || {};
|
|
21805
|
-
if (!numId && numIdFromStyles) numId = numIdFromStyles;
|
|
21806
|
-
if (!level && iLvlFromStyles) level = iLvlFromStyles ? parseInt(iLvlFromStyles) : null;
|
|
21807
|
-
}
|
|
21808
21593
|
const numberingElements = listData.elements;
|
|
21809
21594
|
const abstractDefinitions = numberingElements.filter((style2) => style2.name === "w:abstractNum");
|
|
21810
21595
|
const numDefinitions = numberingElements.filter((style2) => style2.name === "w:num");
|
|
21811
|
-
const numDefinition = numDefinitions.find((style2) => style2.attributes["w:numId"]
|
|
21596
|
+
const numDefinition = numDefinitions.find((style2) => style2.attributes["w:numId"] == numId);
|
|
21812
21597
|
const abstractNumId = numDefinition?.elements[0].attributes["w:val"];
|
|
21813
21598
|
const listDefinitionForThisNumId = abstractDefinitions?.find(
|
|
21814
21599
|
(style2) => style2.attributes["w:abstractNumId"] === abstractNumId
|
|
21815
21600
|
);
|
|
21601
|
+
return listDefinitionForThisNumId;
|
|
21602
|
+
};
|
|
21603
|
+
const getListLevelDefinitionTag = (numId, level, pStyleId, docx) => {
|
|
21604
|
+
if (pStyleId) {
|
|
21605
|
+
const { numId: numIdFromStyles, ilvl: iLvlFromStyles } = getListNumIdFromStyleRef(pStyleId, docx) || {};
|
|
21606
|
+
if (!numId && numIdFromStyles) numId = numIdFromStyles;
|
|
21607
|
+
if (!level && iLvlFromStyles) level = iLvlFromStyles ? parseInt(iLvlFromStyles) : null;
|
|
21608
|
+
}
|
|
21609
|
+
const listDefinitionForThisNumId = getAbstractDefinition(numId, docx);
|
|
21816
21610
|
const currentLevel = getDefinitionForLevel(listDefinitionForThisNumId, level);
|
|
21817
21611
|
const numStyleLink = listDefinitionForThisNumId?.elements?.find((style2) => style2.name === "w:numStyleLink");
|
|
21818
21612
|
const numStyleLinkId = numStyleLink?.attributes["w:val"];
|
|
@@ -21821,7 +21615,15 @@ const getListLevelDefinitionTag = (numId, level, pStyleId, docx) => {
|
|
|
21821
21615
|
return getListLevelDefinitionTag(current.numId, level, null, docx);
|
|
21822
21616
|
}
|
|
21823
21617
|
const start2 = currentLevel?.elements?.find((style2) => style2.name === "w:start")?.attributes["w:val"];
|
|
21824
|
-
|
|
21618
|
+
let numFmt = currentLevel?.elements?.find((style2) => style2.name === "w:numFmt")?.attributes["w:val"];
|
|
21619
|
+
if (!numFmt) {
|
|
21620
|
+
const altChoice = currentLevel?.elements.find((style2) => style2.name === "mc:AlternateContent");
|
|
21621
|
+
const choice = altChoice?.elements.find((style2) => style2.name === "mc:Choice");
|
|
21622
|
+
const choiceNumFmt = choice?.elements.find((style2) => style2.name === "w:numFmt")?.attributes["w:val"];
|
|
21623
|
+
if (choiceNumFmt) {
|
|
21624
|
+
numFmt = choiceNumFmt;
|
|
21625
|
+
}
|
|
21626
|
+
}
|
|
21825
21627
|
const lvlText = currentLevel?.elements?.find((style2) => style2.name === "w:lvlText").attributes["w:val"];
|
|
21826
21628
|
const lvlJc = currentLevel?.elements?.find((style2) => style2.name === "w:lvlJc").attributes["w:val"];
|
|
21827
21629
|
const pPr = currentLevel?.elements?.find((style2) => style2.name === "w:pPr");
|
|
@@ -21836,12 +21638,10 @@ function getNodeNumberingDefinition(item, level, docx) {
|
|
|
21836
21638
|
const initialPpr = item.elements.find((el) => el.name === "w:pPr");
|
|
21837
21639
|
const styleTag = initialPpr?.elements?.find((el) => el.name === "w:pStyle");
|
|
21838
21640
|
const styleId = styleTag?.attributes["w:val"];
|
|
21839
|
-
const numPrTag = getNumPrRecursive({ node: item, styleId, docx });
|
|
21641
|
+
const { numPr: numPrTag, type: type2 } = getNumPrRecursive({ node: item, styleId, docx });
|
|
21840
21642
|
if (!numPrTag) return {};
|
|
21841
21643
|
const numIdTag = numPrTag?.elements.find((style2) => style2.name === "w:numId");
|
|
21842
21644
|
const numId = numIdTag?.attributes["w:val"];
|
|
21843
|
-
const ilvlTag = numPrTag?.elements.find((style2) => style2.name === "w:ilvl");
|
|
21844
|
-
const ilvl = ilvlTag?.attributes["w:val"] || getOutlineLevelFromStyleTag(styleId, docx);
|
|
21845
21645
|
const pStyle = listStyles.find((style2) => style2.name === "w:pStyle");
|
|
21846
21646
|
const pStyleId = pStyle?.attributes["w:val"];
|
|
21847
21647
|
const {
|
|
@@ -21853,29 +21653,84 @@ function getNodeNumberingDefinition(item, level, docx) {
|
|
|
21853
21653
|
rPr
|
|
21854
21654
|
} = getListLevelDefinitionTag(numId, level, pStyleId, docx);
|
|
21855
21655
|
let listpPrs, listrPrs;
|
|
21856
|
-
if (pPr) listpPrs = _processListParagraphProperties(pPr);
|
|
21656
|
+
if (pPr) listpPrs = _processListParagraphProperties(pPr, initialPpr);
|
|
21857
21657
|
if (rPr) listrPrs = _processListRunProperties(rPr);
|
|
21858
21658
|
let listType;
|
|
21859
21659
|
if (unorderedListTypes.includes(listTypeDef?.toLowerCase())) listType = "bulletList";
|
|
21860
21660
|
else if (orderedListTypes.includes(listTypeDef)) listType = "orderedList";
|
|
21861
|
-
else
|
|
21862
|
-
|
|
21661
|
+
else if (listTypeDef === "custom") {
|
|
21662
|
+
listType = "orderedList";
|
|
21663
|
+
} else {
|
|
21664
|
+
return {};
|
|
21665
|
+
}
|
|
21666
|
+
return { listType, listOrderingType: listTypeDef, listrPrs, listpPrs, start: start2, lvlText, lvlJc };
|
|
21863
21667
|
}
|
|
21864
21668
|
function getDefinitionForLevel(data, level) {
|
|
21865
21669
|
return data?.elements?.find((item) => Number(item.attributes["w:ilvl"]) === level);
|
|
21866
21670
|
}
|
|
21867
|
-
function
|
|
21671
|
+
function parseIndentElement(indElem) {
|
|
21672
|
+
if (!indElem || !indElem.attributes) return {};
|
|
21673
|
+
const out = {};
|
|
21674
|
+
if (indElem.attributes["w:left"] != null) out.left = twipsToPixels(indElem.attributes["w:left"]);
|
|
21675
|
+
if (indElem.attributes["w:right"] != null) out.right = twipsToPixels(indElem.attributes["w:right"]);
|
|
21676
|
+
if (indElem.attributes["w:firstLine"] != null) out.firstLine = twipsToPixels(indElem.attributes["w:firstLine"]);
|
|
21677
|
+
if (indElem.attributes["w:hanging"] != null) out.hanging = twipsToPixels(indElem.attributes["w:hanging"]);
|
|
21678
|
+
if (indElem.attributes["w:leftChars"] != null) out.leftChars = twipsToPixels(indElem.attributes["w:leftChars"]);
|
|
21679
|
+
return out;
|
|
21680
|
+
}
|
|
21681
|
+
function combineIndents(ind1, ind2) {
|
|
21682
|
+
ind1 = ind1 && typeof ind1 === "object" ? ind1 : {};
|
|
21683
|
+
ind2 = ind2 && typeof ind2 === "object" ? ind2 : {};
|
|
21684
|
+
const indent = {};
|
|
21685
|
+
["left", "right", "firstLine", "hanging"].forEach((prop) => {
|
|
21686
|
+
const v1 = ind1[prop] !== void 0 ? Number(ind1[prop]) : null;
|
|
21687
|
+
const v2 = ind2[prop] !== void 0 ? Number(ind2[prop]) : null;
|
|
21688
|
+
if (v1 != null && v2 != null) {
|
|
21689
|
+
indent[prop] = prop === "left" || prop === "hanging" ? Math.max(v1, v2) : v1;
|
|
21690
|
+
} else if (v1 != null) {
|
|
21691
|
+
indent[prop] = v1;
|
|
21692
|
+
} else if (v2 != null) {
|
|
21693
|
+
indent[prop] = v2;
|
|
21694
|
+
}
|
|
21695
|
+
});
|
|
21696
|
+
return indent;
|
|
21697
|
+
}
|
|
21698
|
+
function _processListParagraphProperties(data, inlinePpr) {
|
|
21868
21699
|
const { elements } = data;
|
|
21869
21700
|
const expectedTypes = ["w:ind", "w:jc", "w:tabs"];
|
|
21870
21701
|
const paragraphProperties = {};
|
|
21871
21702
|
if (!elements) return paragraphProperties;
|
|
21872
21703
|
elements.forEach((item) => {
|
|
21873
|
-
if (!expectedTypes.includes(item.name))
|
|
21874
|
-
|
|
21875
|
-
|
|
21876
|
-
paragraphProperties[key] = attributes[key];
|
|
21877
|
-
});
|
|
21704
|
+
if (!expectedTypes.includes(item.name)) {
|
|
21705
|
+
console.warn(`[numbering.xml] Unexpected list paragraph prop found: ${item.name}`);
|
|
21706
|
+
}
|
|
21878
21707
|
});
|
|
21708
|
+
const inlineIndent = inlinePpr?.elements?.find((item) => item.name === "w:ind");
|
|
21709
|
+
const parsedInlineIndent = parseIndentElement(inlineIndent);
|
|
21710
|
+
const styleIndent = elements.find((item) => item.name === "w:ind");
|
|
21711
|
+
parseIndentElement(styleIndent);
|
|
21712
|
+
paragraphProperties.indent = parsedInlineIndent;
|
|
21713
|
+
const justify = elements.find((item) => item.name === "w:jc");
|
|
21714
|
+
if (justify) {
|
|
21715
|
+
const justifyAttrs = {};
|
|
21716
|
+
if (!justify.attributes) justify.attributes = {};
|
|
21717
|
+
if (justify.attributes["w:val"] !== void 0) justifyAttrs.val = justify.attributes["w:val"];
|
|
21718
|
+
paragraphProperties.justify = justifyAttrs;
|
|
21719
|
+
}
|
|
21720
|
+
const tabs = elements.find((item) => item.name === "w:tabs");
|
|
21721
|
+
if (tabs) {
|
|
21722
|
+
const tabElements = tabs.elements.filter((item) => item.name === "w:tab");
|
|
21723
|
+
const tabStops = [];
|
|
21724
|
+
tabElements.forEach((tab) => {
|
|
21725
|
+
const tabStop = {};
|
|
21726
|
+
if (!tab.attributes) tab.attributes = {};
|
|
21727
|
+
if (tab.attributes["w:val"] !== void 0) tabStop.val = tab.attributes["w:val"];
|
|
21728
|
+
if (tab.attributes["w:leader"] !== void 0) tabStop.leader = tab.attributes["w:leader"];
|
|
21729
|
+
if (tab.attributes["w:pos"] !== void 0) tabStop.pos = twipsToPixels(tab.attributes["w:pos"]);
|
|
21730
|
+
tabStops.push(tabStop);
|
|
21731
|
+
});
|
|
21732
|
+
paragraphProperties.tabStops = tabStops;
|
|
21733
|
+
}
|
|
21879
21734
|
return paragraphProperties;
|
|
21880
21735
|
}
|
|
21881
21736
|
function _processListRunProperties(data) {
|
|
@@ -21922,9 +21777,6 @@ const handleParagraphNode = (params2) => {
|
|
|
21922
21777
|
let schemaNode;
|
|
21923
21778
|
let processedElements = preProcessNodesForFldChar(node2.elements);
|
|
21924
21779
|
node2.elements = processedElements;
|
|
21925
|
-
if (testForList(node2, docx)) {
|
|
21926
|
-
return { nodes: [], consumed: 0 };
|
|
21927
|
-
}
|
|
21928
21780
|
const handleStandardNode2 = nodeListHandler2.handlerEntities.find(
|
|
21929
21781
|
(e) => e.handlerName === "standardNodeHandler"
|
|
21930
21782
|
)?.handler;
|
|
@@ -21994,6 +21846,14 @@ const handleParagraphNode = (params2) => {
|
|
|
21994
21846
|
schemaNode.attrs["spacing"] = getParagraphSpacing(node2, docx, styleId, schemaNode.attrs.marksAttrs);
|
|
21995
21847
|
schemaNode.attrs["rsidRDefault"] = defaultStyleId;
|
|
21996
21848
|
}
|
|
21849
|
+
if (docx) {
|
|
21850
|
+
const { justify: justify2 } = getDefaultParagraphStyle(docx, styleId);
|
|
21851
|
+
if (justify2) {
|
|
21852
|
+
schemaNode.attrs.justify = {
|
|
21853
|
+
val: justify2["w:val"]
|
|
21854
|
+
};
|
|
21855
|
+
}
|
|
21856
|
+
}
|
|
21997
21857
|
if (framePr && framePr.attributes["w:dropCap"]) {
|
|
21998
21858
|
schemaNode.attrs.dropcap = {
|
|
21999
21859
|
type: framePr.attributes["w:dropCap"],
|
|
@@ -22016,6 +21876,7 @@ const handleParagraphNode = (params2) => {
|
|
|
22016
21876
|
schemaNode.attrs.paragraphProperties.sectPr = sectPr;
|
|
22017
21877
|
schemaNode.attrs.pageBreakSource = "sectPr";
|
|
22018
21878
|
}
|
|
21879
|
+
console.debug("paragraphNodeHandler", schemaNode);
|
|
22019
21880
|
return { nodes: schemaNode ? [schemaNode] : [], consumed: 1 };
|
|
22020
21881
|
};
|
|
22021
21882
|
const getParagraphIndent = (node2, docx, styleId = "") => {
|
|
@@ -22920,8 +22781,8 @@ const defaultNodeListHandler = () => {
|
|
|
22920
22781
|
alternateChoiceHandler,
|
|
22921
22782
|
runNodeHandlerEntity,
|
|
22922
22783
|
pictNodeHandlerEntity,
|
|
22923
|
-
paragraphNodeHandlerEntity,
|
|
22924
22784
|
listHandlerEntity,
|
|
22785
|
+
paragraphNodeHandlerEntity,
|
|
22925
22786
|
textNodeHandlerEntity,
|
|
22926
22787
|
lineBreakNodeHandlerEntity,
|
|
22927
22788
|
annotationNodeHandlerEntity,
|
|
@@ -22935,7 +22796,7 @@ const defaultNodeListHandler = () => {
|
|
|
22935
22796
|
autoPageHandlerEntity,
|
|
22936
22797
|
autoTotalPageCountEntity,
|
|
22937
22798
|
standardNodeHandlerEntity
|
|
22938
|
-
//
|
|
22799
|
+
// This is the last one as it can handle everything
|
|
22939
22800
|
];
|
|
22940
22801
|
const handler = createNodeListHandler(entities);
|
|
22941
22802
|
return {
|
|
@@ -23167,6 +23028,8 @@ const importHeadersFooters = (docx, converter, editor) => {
|
|
|
23167
23028
|
converter.headers[rId] = { type: "doc", content: [...schema] };
|
|
23168
23029
|
sectionType && (converter.headerIds[sectionType] = rId);
|
|
23169
23030
|
});
|
|
23031
|
+
const titlePg = allSectPrElements?.find((el) => el.name === "w:titlePg");
|
|
23032
|
+
if (titlePg) converter.headerIds.titlePg = true;
|
|
23170
23033
|
footers.forEach((footer) => {
|
|
23171
23034
|
const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(footer, docx);
|
|
23172
23035
|
const sectPrFooter = allSectPrElements.find((el) => el.name === "w:footerReference" && el.attributes["r:id"] === rId);
|
|
@@ -23307,7 +23170,7 @@ const _SuperConverter = class _SuperConverter2 {
|
|
|
23307
23170
|
return;
|
|
23308
23171
|
}
|
|
23309
23172
|
}
|
|
23310
|
-
static updateDocumentVersion(docx = this.convertedXml, version2 = "0.
|
|
23173
|
+
static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.0-RC2") {
|
|
23311
23174
|
const customLocation = "docProps/custom.xml";
|
|
23312
23175
|
if (!docx[customLocation]) {
|
|
23313
23176
|
docx[customLocation] = generateCustomXml();
|
|
@@ -23464,7 +23327,7 @@ const _SuperConverter = class _SuperConverter2 {
|
|
|
23464
23327
|
const exporter = new DocxExporter(this);
|
|
23465
23328
|
return exporter.schemaToXml(data, debug);
|
|
23466
23329
|
}
|
|
23467
|
-
async exportToDocx(jsonData, editorSchema, documentMedia, isFinalDoc = false, commentsExportType, comments = [], editor) {
|
|
23330
|
+
async exportToDocx(jsonData, editorSchema, documentMedia, isFinalDoc = false, commentsExportType, comments = [], editor, exportJsonOnly = false) {
|
|
23468
23331
|
const commentsWithParaIds = comments.map((c2) => prepareCommentParaIds(c2));
|
|
23469
23332
|
const commentDefinitions = commentsWithParaIds.map((c2, index2) => getCommentDefinition(c2, index2, commentsWithParaIds, editor));
|
|
23470
23333
|
const { result, params: params2 } = this.exportToXmlJson({
|
|
@@ -23476,6 +23339,7 @@ const _SuperConverter = class _SuperConverter2 {
|
|
|
23476
23339
|
isFinalDoc,
|
|
23477
23340
|
editor
|
|
23478
23341
|
});
|
|
23342
|
+
if (exportJsonOnly) return result;
|
|
23479
23343
|
const exporter = new DocxExporter(this);
|
|
23480
23344
|
const xml = exporter.schemaToXml(result);
|
|
23481
23345
|
await __privateMethod$2(this, _SuperConverter_instances, exportProcessMediaFiles_fn).call(this, {
|
|
@@ -23773,7 +23637,7 @@ function storeSuperdocVersion(docx) {
|
|
|
23773
23637
|
function generateCustomXml() {
|
|
23774
23638
|
return DEFAULT_CUSTOM_XML;
|
|
23775
23639
|
}
|
|
23776
|
-
function generateSuperdocVersion(pid = 2, version2 = "0.
|
|
23640
|
+
function generateSuperdocVersion(pid = 2, version2 = "0.13.0-RC2") {
|
|
23777
23641
|
return {
|
|
23778
23642
|
type: "element",
|
|
23779
23643
|
name: "property",
|
|
@@ -26306,7 +26170,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
|
|
|
26306
26170
|
var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
26307
26171
|
var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
|
|
26308
26172
|
var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
|
|
26309
|
-
var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _FieldAnnotationView_instances, createAnnotation_fn;
|
|
26173
|
+
var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _ListItemNodeView_instances, init_fn2, _FieldAnnotationView_instances, createAnnotation_fn;
|
|
26310
26174
|
function getMarksFromSelection(state2) {
|
|
26311
26175
|
const { from: from2, to, empty: empty2 } = state2.selection;
|
|
26312
26176
|
const marks = [];
|
|
@@ -27278,8 +27142,8 @@ class Attribute2 {
|
|
|
27278
27142
|
const type2 = getNodeType(typeOrName, state2.schema);
|
|
27279
27143
|
const { from: from2, to } = state2.selection;
|
|
27280
27144
|
const nodes = [];
|
|
27281
|
-
state2.doc.nodesBetween(from2, to, (
|
|
27282
|
-
nodes.push(
|
|
27145
|
+
state2.doc.nodesBetween(from2, to, (node3) => {
|
|
27146
|
+
nodes.push(node3);
|
|
27283
27147
|
});
|
|
27284
27148
|
const node2 = nodes.reverse().find((nodeItem) => nodeItem.type.name === type2.name);
|
|
27285
27149
|
if (!node2) return {};
|
|
@@ -30028,6 +29892,377 @@ const baseBulletList = {
|
|
|
30028
29892
|
}
|
|
30029
29893
|
]
|
|
30030
29894
|
};
|
|
29895
|
+
function createDocument(converter, schema, editor, { check = false } = {}) {
|
|
29896
|
+
const documentData = converter.getSchema(editor);
|
|
29897
|
+
if (documentData) {
|
|
29898
|
+
const documentNode = schema.nodeFromJSON(documentData);
|
|
29899
|
+
if (check) {
|
|
29900
|
+
documentNode.check();
|
|
29901
|
+
}
|
|
29902
|
+
return documentNode;
|
|
29903
|
+
}
|
|
29904
|
+
return schema.topNodeType.createAndFill();
|
|
29905
|
+
}
|
|
29906
|
+
function getSchemaTypeByName(name, schema) {
|
|
29907
|
+
return schema.nodes[name] || schema.marks[name] || null;
|
|
29908
|
+
}
|
|
29909
|
+
function generateDocxListAttributes(listType) {
|
|
29910
|
+
const listTypesMap = {
|
|
29911
|
+
bulletList: 1,
|
|
29912
|
+
orderedList: 2
|
|
29913
|
+
};
|
|
29914
|
+
return {
|
|
29915
|
+
attributes: {
|
|
29916
|
+
parentAttributes: {
|
|
29917
|
+
"w14:paraId": generateDocxRandomId(),
|
|
29918
|
+
"w14:textId": generateDocxRandomId(),
|
|
29919
|
+
"w:rsidR": generateDocxRandomId(),
|
|
29920
|
+
"w:rsidRDefault": generateDocxRandomId(),
|
|
29921
|
+
"w:rsidP": generateDocxRandomId(),
|
|
29922
|
+
paragraphProperties: {
|
|
29923
|
+
type: "element",
|
|
29924
|
+
name: "w:pPr",
|
|
29925
|
+
elements: [
|
|
29926
|
+
{
|
|
29927
|
+
type: "element",
|
|
29928
|
+
name: "w:pStyle",
|
|
29929
|
+
attributes: {
|
|
29930
|
+
"w:val": "ListParagraph"
|
|
29931
|
+
}
|
|
29932
|
+
},
|
|
29933
|
+
{
|
|
29934
|
+
type: "element",
|
|
29935
|
+
name: "w:numPr",
|
|
29936
|
+
elements: [
|
|
29937
|
+
{
|
|
29938
|
+
type: "element",
|
|
29939
|
+
name: "w:ilvl",
|
|
29940
|
+
attributes: {
|
|
29941
|
+
"w:val": "0"
|
|
29942
|
+
}
|
|
29943
|
+
},
|
|
29944
|
+
{
|
|
29945
|
+
type: "element",
|
|
29946
|
+
name: "w:numId",
|
|
29947
|
+
attributes: {
|
|
29948
|
+
"w:val": listTypesMap[listType] || 0
|
|
29949
|
+
}
|
|
29950
|
+
}
|
|
29951
|
+
]
|
|
29952
|
+
}
|
|
29953
|
+
]
|
|
29954
|
+
}
|
|
29955
|
+
}
|
|
29956
|
+
}
|
|
29957
|
+
};
|
|
29958
|
+
}
|
|
29959
|
+
function getMarksBetween(from2, to, doc2) {
|
|
29960
|
+
const marks = [];
|
|
29961
|
+
if (from2 === to) {
|
|
29962
|
+
doc2.resolve(from2).marks().forEach((mark) => {
|
|
29963
|
+
const $pos = doc2.resolve(from2 - 1);
|
|
29964
|
+
const range2 = getMarkRange($pos, mark.type);
|
|
29965
|
+
if (!range2) {
|
|
29966
|
+
return;
|
|
29967
|
+
}
|
|
29968
|
+
marks.push({
|
|
29969
|
+
mark,
|
|
29970
|
+
...range2
|
|
29971
|
+
});
|
|
29972
|
+
});
|
|
29973
|
+
} else {
|
|
29974
|
+
doc2.nodesBetween(from2, to, (node2, pos) => {
|
|
29975
|
+
if (!node2 || node2?.nodeSize === void 0) {
|
|
29976
|
+
return;
|
|
29977
|
+
}
|
|
29978
|
+
marks.push(
|
|
29979
|
+
...node2.marks.map((mark) => ({
|
|
29980
|
+
from: pos,
|
|
29981
|
+
to: pos + node2.nodeSize,
|
|
29982
|
+
mark
|
|
29983
|
+
}))
|
|
29984
|
+
);
|
|
29985
|
+
});
|
|
29986
|
+
}
|
|
29987
|
+
return marks;
|
|
29988
|
+
}
|
|
29989
|
+
function isActive(state2, name, attrs = {}) {
|
|
29990
|
+
if (!name) {
|
|
29991
|
+
return isNodeActive(state2, null, attrs) || isMarkActive(state2, null, attrs);
|
|
29992
|
+
}
|
|
29993
|
+
const schemaType = getSchemaTypeNameByName(name, state2.schema);
|
|
29994
|
+
if (schemaType === "node") {
|
|
29995
|
+
return isNodeActive(state2, name, attrs);
|
|
29996
|
+
}
|
|
29997
|
+
if (schemaType === "mark") {
|
|
29998
|
+
return isMarkActive(state2, name, attrs);
|
|
29999
|
+
}
|
|
30000
|
+
return false;
|
|
30001
|
+
}
|
|
30002
|
+
function findChildren$3(node2, predicate) {
|
|
30003
|
+
const nodesWithPos = [];
|
|
30004
|
+
node2.descendants((child, pos) => {
|
|
30005
|
+
if (predicate(child)) {
|
|
30006
|
+
nodesWithPos.push({
|
|
30007
|
+
node: child,
|
|
30008
|
+
pos
|
|
30009
|
+
});
|
|
30010
|
+
}
|
|
30011
|
+
});
|
|
30012
|
+
return nodesWithPos;
|
|
30013
|
+
}
|
|
30014
|
+
function posToDOMRect(view, from2, to) {
|
|
30015
|
+
const minPos = 0;
|
|
30016
|
+
const maxPos = view.state.doc.content.size;
|
|
30017
|
+
const resolvedFrom = minMax(from2, minPos, maxPos);
|
|
30018
|
+
const resolvedEnd = minMax(to, minPos, maxPos);
|
|
30019
|
+
const start2 = view.coordsAtPos(resolvedFrom);
|
|
30020
|
+
const end2 = view.coordsAtPos(resolvedEnd, -1);
|
|
30021
|
+
const top2 = Math.min(start2.top, end2.top);
|
|
30022
|
+
const bottom2 = Math.max(start2.bottom, end2.bottom);
|
|
30023
|
+
const left2 = Math.min(start2.left, end2.left);
|
|
30024
|
+
const right2 = Math.max(start2.right, end2.right);
|
|
30025
|
+
const width = right2 - left2;
|
|
30026
|
+
const height = bottom2 - top2;
|
|
30027
|
+
const x = left2;
|
|
30028
|
+
const y = top2;
|
|
30029
|
+
const data = {
|
|
30030
|
+
top: top2,
|
|
30031
|
+
bottom: bottom2,
|
|
30032
|
+
left: left2,
|
|
30033
|
+
right: right2,
|
|
30034
|
+
width,
|
|
30035
|
+
height,
|
|
30036
|
+
x,
|
|
30037
|
+
y
|
|
30038
|
+
};
|
|
30039
|
+
return {
|
|
30040
|
+
...data,
|
|
30041
|
+
toJSON: () => data
|
|
30042
|
+
};
|
|
30043
|
+
}
|
|
30044
|
+
const isInTable$1 = (state2) => {
|
|
30045
|
+
const { $head } = state2.selection;
|
|
30046
|
+
for (let d = $head.depth; d > 0; d -= 1) {
|
|
30047
|
+
if ($head.node(d).type?.spec?.tableRole === "row") {
|
|
30048
|
+
return true;
|
|
30049
|
+
}
|
|
30050
|
+
}
|
|
30051
|
+
return false;
|
|
30052
|
+
};
|
|
30053
|
+
const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
30054
|
+
__proto__: null,
|
|
30055
|
+
chainableEditorState,
|
|
30056
|
+
cleanSchemaItem,
|
|
30057
|
+
createDocument,
|
|
30058
|
+
defaultBlockAt,
|
|
30059
|
+
findChildren: findChildren$3,
|
|
30060
|
+
findMark,
|
|
30061
|
+
findParentNode,
|
|
30062
|
+
findParentNodeClosestToPos,
|
|
30063
|
+
generateDocxListAttributes,
|
|
30064
|
+
generateDocxRandomId,
|
|
30065
|
+
generateRandom32BitHex,
|
|
30066
|
+
getActiveFormatting,
|
|
30067
|
+
getExtensionConfigField,
|
|
30068
|
+
getMarkRange,
|
|
30069
|
+
getMarkType,
|
|
30070
|
+
getMarksBetween,
|
|
30071
|
+
getMarksFromSelection,
|
|
30072
|
+
getNodeType,
|
|
30073
|
+
getSchemaTypeByName,
|
|
30074
|
+
getSchemaTypeNameByName,
|
|
30075
|
+
isActive,
|
|
30076
|
+
isInTable: isInTable$1,
|
|
30077
|
+
isList,
|
|
30078
|
+
isMarkActive,
|
|
30079
|
+
isNodeActive,
|
|
30080
|
+
isTextSelection,
|
|
30081
|
+
posToDOMRect
|
|
30082
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
30083
|
+
const generateNewListDefinition = ({ numId, listType, editor }) => {
|
|
30084
|
+
const definition = listType.name === "orderedList" ? baseOrderedListDef : baseBulletList;
|
|
30085
|
+
const numbering = editor.converter.numbering;
|
|
30086
|
+
const newNumbering = { ...numbering };
|
|
30087
|
+
const newAbstractId = getNewListId(editor);
|
|
30088
|
+
const newAbstractDef = {
|
|
30089
|
+
...definition,
|
|
30090
|
+
attributes: {
|
|
30091
|
+
...definition.attributes,
|
|
30092
|
+
"w:abstractNumId": String(newAbstractId)
|
|
30093
|
+
}
|
|
30094
|
+
};
|
|
30095
|
+
newNumbering.abstracts[newAbstractId] = newAbstractDef;
|
|
30096
|
+
const newNumDef = {
|
|
30097
|
+
type: "element",
|
|
30098
|
+
name: "w:num",
|
|
30099
|
+
attributes: {
|
|
30100
|
+
"w:numId": String(numId),
|
|
30101
|
+
"w16cid:durableId": "485517411"
|
|
30102
|
+
},
|
|
30103
|
+
elements: [
|
|
30104
|
+
{ name: "w:abstractNumId", attributes: { "w:val": String(newAbstractId) } }
|
|
30105
|
+
]
|
|
30106
|
+
};
|
|
30107
|
+
newNumbering.definitions[numId] = newNumDef;
|
|
30108
|
+
editor.converter.numbering = newNumbering;
|
|
30109
|
+
return { abstract: newAbstractDef, definition: newNumDef };
|
|
30110
|
+
};
|
|
30111
|
+
const getNewListId = (editor) => Math.max(...Object.keys(editor.converter.numbering.definitions).map(Number)) + 1;
|
|
30112
|
+
const getListDefinitionDetails = ({ numId, level, editor }) => {
|
|
30113
|
+
const { definitions, abstracts } = editor.converter.numbering;
|
|
30114
|
+
const abstractId = definitions[numId]?.elements?.find((item) => item.name === "w:abstractNumId")?.attributes?.["w:val"];
|
|
30115
|
+
const abstract = abstracts[abstractId];
|
|
30116
|
+
const listDefinition = abstract?.elements?.find((item) => item.name === "w:lvl" && item.attributes["w:ilvl"] == level);
|
|
30117
|
+
const start2 = listDefinition?.elements?.find((item) => item.name === "w:start")?.attributes["w:val"];
|
|
30118
|
+
const numFmt = listDefinition?.elements?.find((item) => item.name === "w:numFmt")?.attributes["w:val"];
|
|
30119
|
+
const lvlText = listDefinition?.elements?.find((item) => item.name === "w:lvlText")?.attributes["w:val"];
|
|
30120
|
+
return { start: start2, numFmt, lvlText };
|
|
30121
|
+
};
|
|
30122
|
+
const removeListDefinitions = (listId, editor) => {
|
|
30123
|
+
const { numbering } = editor.converter;
|
|
30124
|
+
if (!numbering) return;
|
|
30125
|
+
const { definitions, abstracts } = numbering;
|
|
30126
|
+
const abstractId = definitions[listId].elements[0].attributes["w:val"];
|
|
30127
|
+
delete definitions[listId];
|
|
30128
|
+
delete abstracts[abstractId];
|
|
30129
|
+
editor.converter.numbering = {
|
|
30130
|
+
definitions,
|
|
30131
|
+
abstracts
|
|
30132
|
+
};
|
|
30133
|
+
};
|
|
30134
|
+
const createListItemNodeJSON = ({ level, lvlText, numId, numFmt, start: start2, contentNode }) => {
|
|
30135
|
+
start2 = Number(start2);
|
|
30136
|
+
if (!contentNode) {
|
|
30137
|
+
contentNode = {
|
|
30138
|
+
type: "paragraph",
|
|
30139
|
+
content: []
|
|
30140
|
+
};
|
|
30141
|
+
}
|
|
30142
|
+
const listLevel = new Array(level).fill(start2).map((_, i) => i);
|
|
30143
|
+
listLevel.push(start2);
|
|
30144
|
+
return {
|
|
30145
|
+
type: "listItem",
|
|
30146
|
+
attrs: {
|
|
30147
|
+
lvlText,
|
|
30148
|
+
listLevel,
|
|
30149
|
+
level,
|
|
30150
|
+
numId,
|
|
30151
|
+
numPrType: "inline",
|
|
30152
|
+
listNumberingType: numFmt
|
|
30153
|
+
},
|
|
30154
|
+
content: [contentNode]
|
|
30155
|
+
};
|
|
30156
|
+
};
|
|
30157
|
+
const createSchemaOrderedListNode = ({ level, numId, editor, contentNode }) => {
|
|
30158
|
+
level = Number(level);
|
|
30159
|
+
numId = Number(numId);
|
|
30160
|
+
const { start: start2, lvlText, numFmt } = ListHelpers.getListDefinitionDetails({ numId, level, editor });
|
|
30161
|
+
const listNodeJSON = createListItemNodeJSON({ level, lvlText, numFmt, numId, start: start2, contentNode });
|
|
30162
|
+
const node2 = {
|
|
30163
|
+
type: "orderedList",
|
|
30164
|
+
attrs: {
|
|
30165
|
+
"list-style-type": numFmt,
|
|
30166
|
+
listId: numId,
|
|
30167
|
+
order: level
|
|
30168
|
+
},
|
|
30169
|
+
content: [listNodeJSON]
|
|
30170
|
+
};
|
|
30171
|
+
return editor.schema.nodeFromJSON(node2);
|
|
30172
|
+
};
|
|
30173
|
+
const createNewList = ({ listType, editor, chain }) => {
|
|
30174
|
+
const numId = ListHelpers.getNewListId(editor);
|
|
30175
|
+
if (typeof node === "string") listType = editor.schema.nodes[listType];
|
|
30176
|
+
ListHelpers.generateNewListDefinition({ numId, listType, editor });
|
|
30177
|
+
const { state: state2 } = editor;
|
|
30178
|
+
const { $from } = state2.selection;
|
|
30179
|
+
const content = $from.parent;
|
|
30180
|
+
const level = 0;
|
|
30181
|
+
const listNode = ListHelpers.createSchemaOrderedListNode({
|
|
30182
|
+
level,
|
|
30183
|
+
numId,
|
|
30184
|
+
editor,
|
|
30185
|
+
contentNode: content?.toJSON()
|
|
30186
|
+
});
|
|
30187
|
+
const parentDepth = $from.depth;
|
|
30188
|
+
const replaceFrom = $from.before(parentDepth);
|
|
30189
|
+
const replaceTo = $from.after(parentDepth);
|
|
30190
|
+
return insertNewList(chain, replaceFrom, replaceTo, listNode);
|
|
30191
|
+
};
|
|
30192
|
+
const indentListItem = ({ chain, editor, node: currentNode }) => {
|
|
30193
|
+
const { state: state2 } = editor;
|
|
30194
|
+
const { $from } = state2.selection;
|
|
30195
|
+
const content = $from.parent;
|
|
30196
|
+
const numId = currentNode.node.attrs.numId;
|
|
30197
|
+
const level = currentNode.node.attrs.level + 1;
|
|
30198
|
+
const listNode = ListHelpers.createSchemaOrderedListNode({
|
|
30199
|
+
level,
|
|
30200
|
+
numId,
|
|
30201
|
+
editor,
|
|
30202
|
+
contentNode: content?.toJSON()
|
|
30203
|
+
});
|
|
30204
|
+
const parentList = findParentNode((node2) => node2.type.name === "orderedList")(state2.selection);
|
|
30205
|
+
const replaceFrom = parentList.pos;
|
|
30206
|
+
const replaceTo = parentList.node.nodeSize + parentList.pos;
|
|
30207
|
+
const newMarks = addInlineTextMarks(currentNode.node, []);
|
|
30208
|
+
return insertNewList(chain, replaceFrom, replaceTo, listNode, newMarks);
|
|
30209
|
+
};
|
|
30210
|
+
const outdentListItem = ({ chain, editor, node: currentNode }) => {
|
|
30211
|
+
const { state: state2 } = editor;
|
|
30212
|
+
const { $from } = state2.selection;
|
|
30213
|
+
const content = $from.parent;
|
|
30214
|
+
const numId = currentNode.node.attrs.numId;
|
|
30215
|
+
const level = currentNode.node.attrs.level - 1;
|
|
30216
|
+
const parentList = findParentNode((node2) => node2.type.name === "orderedList")(state2.selection);
|
|
30217
|
+
const replaceFrom = parentList.pos;
|
|
30218
|
+
const replaceTo = parentList.node.nodeSize + parentList.pos;
|
|
30219
|
+
if (level < 0) {
|
|
30220
|
+
return insertNewList(chain, replaceFrom, replaceTo, content);
|
|
30221
|
+
}
|
|
30222
|
+
const listNode = ListHelpers.createSchemaOrderedListNode({
|
|
30223
|
+
level,
|
|
30224
|
+
numId,
|
|
30225
|
+
editor,
|
|
30226
|
+
contentNode: content?.toJSON()
|
|
30227
|
+
});
|
|
30228
|
+
const newMarks = addInlineTextMarks(currentNode.node, []);
|
|
30229
|
+
return insertNewList(chain, replaceFrom, replaceTo, listNode, newMarks);
|
|
30230
|
+
};
|
|
30231
|
+
const insertNewList = (chain, replaceFrom, replaceTo, listNode, marks = []) => {
|
|
30232
|
+
return chain().command(({ tr, dispatch }) => {
|
|
30233
|
+
tr.replaceWith(replaceFrom, replaceTo, listNode);
|
|
30234
|
+
tr.ensureMarks(marks);
|
|
30235
|
+
dispatch(tr);
|
|
30236
|
+
return true;
|
|
30237
|
+
}).run();
|
|
30238
|
+
};
|
|
30239
|
+
const addInlineTextMarks = (currentNode, filteredMarks) => {
|
|
30240
|
+
const newMarks = [...filteredMarks];
|
|
30241
|
+
try {
|
|
30242
|
+
const textMarks = currentNode.children[0].children[0].marks;
|
|
30243
|
+
const inlineTextStyleFromSplitBlock = textMarks.find((m) => m.type.name === "textStyle");
|
|
30244
|
+
inlineTextStyleFromSplitBlock && newMarks.push(inlineTextStyleFromSplitBlock);
|
|
30245
|
+
} catch (e) {
|
|
30246
|
+
}
|
|
30247
|
+
return newMarks;
|
|
30248
|
+
};
|
|
30249
|
+
const ListHelpers = {
|
|
30250
|
+
// DOCX helpers
|
|
30251
|
+
getListDefinitionDetails,
|
|
30252
|
+
generateNewListDefinition,
|
|
30253
|
+
getNewListId,
|
|
30254
|
+
removeListDefinitions,
|
|
30255
|
+
// Schema helpers
|
|
30256
|
+
createNewList,
|
|
30257
|
+
createSchemaOrderedListNode,
|
|
30258
|
+
createListItemNodeJSON,
|
|
30259
|
+
indentListItem,
|
|
30260
|
+
outdentListItem,
|
|
30261
|
+
addInlineTextMarks,
|
|
30262
|
+
// Base list definitions
|
|
30263
|
+
baseOrderedListDef,
|
|
30264
|
+
baseBulletList
|
|
30265
|
+
};
|
|
30031
30266
|
const joinListBackwards = (tr, listType) => {
|
|
30032
30267
|
const list = findParentNode((node2) => node2.type === listType)(tr.selection);
|
|
30033
30268
|
if (!list) return true;
|
|
@@ -30065,7 +30300,7 @@ const toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {})
|
|
|
30065
30300
|
if (range2.depth >= 1 && parentList && range2.depth - parentList.depth <= 1) {
|
|
30066
30301
|
if (parentList.node.type === listType) {
|
|
30067
30302
|
const { listId } = parentList.node.attrs;
|
|
30068
|
-
if (editor.converter)
|
|
30303
|
+
if (editor.converter) ListHelpers.removeListDefinitions(listId, editor);
|
|
30069
30304
|
return commands2.liftListItem(itemType);
|
|
30070
30305
|
}
|
|
30071
30306
|
if (isList(parentList.node.type.name, extensions) && listType.validContent(parentList.node.content) && dispatch) {
|
|
@@ -30087,8 +30322,8 @@ const toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {})
|
|
|
30087
30322
|
return commands2.clearNodes();
|
|
30088
30323
|
};
|
|
30089
30324
|
};
|
|
30090
|
-
const newListId = numbering?.definitions ? getNewListId(
|
|
30091
|
-
if (editor.converter)
|
|
30325
|
+
const newListId = numbering?.definitions ? ListHelpers.getNewListId(editor) : null;
|
|
30326
|
+
if (editor.converter) ListHelpers.generateNewListDefinition(newListId, numbering, listType);
|
|
30092
30327
|
attributes.listId = newListId;
|
|
30093
30328
|
if (!keepMarks || !marks || !dispatch) {
|
|
30094
30329
|
const result2 = chain().command(createTryConvertNodeToDefault({ ensureMarks: false })).wrapInList(listType, attributes).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
|
|
@@ -30097,41 +30332,7 @@ const toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {})
|
|
|
30097
30332
|
const result = chain().command(createTryConvertNodeToDefault({ ensureMarks: true })).wrapInList(listType, attributes).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
|
|
30098
30333
|
return result;
|
|
30099
30334
|
};
|
|
30100
|
-
const
|
|
30101
|
-
const generateNewListDefinition = (newListId, numbering, listType) => {
|
|
30102
|
-
const definition = listType.name === "orderedList" ? baseOrderedListDef : baseBulletList;
|
|
30103
|
-
const newNumbering = { ...numbering };
|
|
30104
|
-
const newAbstractId = getNewListId(newNumbering.abstracts);
|
|
30105
|
-
const newAbstractDef = {
|
|
30106
|
-
...definition,
|
|
30107
|
-
attributes: {
|
|
30108
|
-
...definition.attributes,
|
|
30109
|
-
"w:abstractNumId": String(newAbstractId)
|
|
30110
|
-
}
|
|
30111
|
-
};
|
|
30112
|
-
newNumbering.abstracts[newAbstractId] = newAbstractDef;
|
|
30113
|
-
const newNumDef = {
|
|
30114
|
-
type: "element",
|
|
30115
|
-
name: "w:num",
|
|
30116
|
-
attributes: {
|
|
30117
|
-
"w:numId": String(newListId),
|
|
30118
|
-
"w16cid:durableId": "485517411"
|
|
30119
|
-
},
|
|
30120
|
-
elements: [
|
|
30121
|
-
{ name: "w:abstractNumId", attributes: { "w:val": String(newAbstractId) } }
|
|
30122
|
-
]
|
|
30123
|
-
};
|
|
30124
|
-
newNumbering.definitions[newListId] = newNumDef;
|
|
30125
|
-
return newNumbering;
|
|
30126
|
-
};
|
|
30127
|
-
const removeListDefinitions = (listId, numbering) => {
|
|
30128
|
-
const { definitions, abstracts } = numbering;
|
|
30129
|
-
const abstractId = definitions[listId].elements[0].attributes["w:val"];
|
|
30130
|
-
delete definitions[listId];
|
|
30131
|
-
delete abstracts[abstractId];
|
|
30132
|
-
return numbering;
|
|
30133
|
-
};
|
|
30134
|
-
const splitListItem = (typeOrName) => (props) => {
|
|
30335
|
+
const splitListItem = (typeOrName, currentNode) => (props) => {
|
|
30135
30336
|
const { tr, state: state2, dispatch, editor } = props;
|
|
30136
30337
|
const type2 = getNodeType(typeOrName, state2.schema);
|
|
30137
30338
|
const { $from, $to, node: node2 } = state2.selection;
|
|
@@ -30160,8 +30361,8 @@ const splitListItem = (typeOrName) => (props) => {
|
|
|
30160
30361
|
$from.node().type.name,
|
|
30161
30362
|
$from.node().attrs
|
|
30162
30363
|
);
|
|
30163
|
-
const
|
|
30164
|
-
wrap2 = wrap2.append(Fragment.from(type2.createAndFill(null,
|
|
30364
|
+
const nextType = type2.contentMatch.defaultType?.createAndFill(newNextTypeAttrs) || void 0;
|
|
30365
|
+
wrap2 = wrap2.append(Fragment.from(type2.createAndFill(null, nextType) || void 0));
|
|
30165
30366
|
const start2 = $from.before($from.depth - (depthBefore - 1));
|
|
30166
30367
|
tr.replace(start2, $from.after(-depthAfter), new Slice(wrap2, 4 - depthBefore, 0));
|
|
30167
30368
|
let sel = -1;
|
|
@@ -30174,30 +30375,18 @@ const splitListItem = (typeOrName) => (props) => {
|
|
|
30174
30375
|
}
|
|
30175
30376
|
return true;
|
|
30176
30377
|
}
|
|
30177
|
-
const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
|
|
30178
|
-
const newTypeAttributes = Attribute2.getSplittedAttributes(extensionAttrs, grandParent.type.name, grandParent.attrs);
|
|
30179
|
-
const newNextTypeAttributes = Attribute2.getSplittedAttributes(
|
|
30180
|
-
extensionAttrs,
|
|
30181
|
-
$from.node().type.name,
|
|
30182
|
-
$from.node().attrs
|
|
30183
|
-
);
|
|
30184
30378
|
tr.delete($from.pos, $to.pos);
|
|
30185
|
-
|
|
30186
|
-
{ type: type2, attrs: newTypeAttributes },
|
|
30187
|
-
{ type: nextType, attrs: newNextTypeAttributes }
|
|
30188
|
-
] : [{ type: type2, attrs: newTypeAttributes }];
|
|
30189
|
-
if (!canSplit(tr.doc, $from.pos, 2)) {
|
|
30190
|
-
return false;
|
|
30191
|
-
}
|
|
30379
|
+
if (!canSplit(tr.doc, $from.pos, 3)) return false;
|
|
30192
30380
|
if (dispatch) {
|
|
30193
30381
|
const { selection, storedMarks } = state2;
|
|
30194
30382
|
const { splittableMarks } = editor.extensionService;
|
|
30195
30383
|
const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
|
|
30196
|
-
tr.split($from.pos,
|
|
30384
|
+
tr.split($from.pos, 3).scrollIntoView();
|
|
30197
30385
|
if (!marks || !dispatch) return true;
|
|
30198
30386
|
const filteredMarks = marks.filter((m) => splittableMarks.includes(m.type.name));
|
|
30199
|
-
|
|
30200
|
-
tr.
|
|
30387
|
+
const updatedMarks = ListHelpers.addInlineTextMarks(currentNode.node, filteredMarks);
|
|
30388
|
+
tr.ensureMarks(updatedMarks);
|
|
30389
|
+
tr.setMeta("splitListItem", updatedMarks);
|
|
30201
30390
|
}
|
|
30202
30391
|
return true;
|
|
30203
30392
|
};
|
|
@@ -30358,194 +30547,6 @@ const EditorFocus = Extension.create({
|
|
|
30358
30547
|
return [editorFocusPlugin];
|
|
30359
30548
|
}
|
|
30360
30549
|
});
|
|
30361
|
-
function createDocument(converter, schema, editor, { check = false } = {}) {
|
|
30362
|
-
const documentData = converter.getSchema(editor);
|
|
30363
|
-
if (documentData) {
|
|
30364
|
-
const documentNode = schema.nodeFromJSON(documentData);
|
|
30365
|
-
if (check) {
|
|
30366
|
-
documentNode.check();
|
|
30367
|
-
}
|
|
30368
|
-
return documentNode;
|
|
30369
|
-
}
|
|
30370
|
-
return schema.topNodeType.createAndFill();
|
|
30371
|
-
}
|
|
30372
|
-
function getSchemaTypeByName(name, schema) {
|
|
30373
|
-
return schema.nodes[name] || schema.marks[name] || null;
|
|
30374
|
-
}
|
|
30375
|
-
function generateDocxListAttributes(listType) {
|
|
30376
|
-
const listTypesMap = {
|
|
30377
|
-
bulletList: 1,
|
|
30378
|
-
orderedList: 2
|
|
30379
|
-
};
|
|
30380
|
-
return {
|
|
30381
|
-
attributes: {
|
|
30382
|
-
parentAttributes: {
|
|
30383
|
-
"w14:paraId": generateDocxRandomId(),
|
|
30384
|
-
"w14:textId": generateDocxRandomId(),
|
|
30385
|
-
"w:rsidR": generateDocxRandomId(),
|
|
30386
|
-
"w:rsidRDefault": generateDocxRandomId(),
|
|
30387
|
-
"w:rsidP": generateDocxRandomId(),
|
|
30388
|
-
paragraphProperties: {
|
|
30389
|
-
type: "element",
|
|
30390
|
-
name: "w:pPr",
|
|
30391
|
-
elements: [
|
|
30392
|
-
{
|
|
30393
|
-
type: "element",
|
|
30394
|
-
name: "w:pStyle",
|
|
30395
|
-
attributes: {
|
|
30396
|
-
"w:val": "ListParagraph"
|
|
30397
|
-
}
|
|
30398
|
-
},
|
|
30399
|
-
{
|
|
30400
|
-
type: "element",
|
|
30401
|
-
name: "w:numPr",
|
|
30402
|
-
elements: [
|
|
30403
|
-
{
|
|
30404
|
-
type: "element",
|
|
30405
|
-
name: "w:ilvl",
|
|
30406
|
-
attributes: {
|
|
30407
|
-
"w:val": "0"
|
|
30408
|
-
}
|
|
30409
|
-
},
|
|
30410
|
-
{
|
|
30411
|
-
type: "element",
|
|
30412
|
-
name: "w:numId",
|
|
30413
|
-
attributes: {
|
|
30414
|
-
"w:val": listTypesMap[listType] || 0
|
|
30415
|
-
}
|
|
30416
|
-
}
|
|
30417
|
-
]
|
|
30418
|
-
}
|
|
30419
|
-
]
|
|
30420
|
-
}
|
|
30421
|
-
}
|
|
30422
|
-
}
|
|
30423
|
-
};
|
|
30424
|
-
}
|
|
30425
|
-
function getMarksBetween(from2, to, doc2) {
|
|
30426
|
-
const marks = [];
|
|
30427
|
-
if (from2 === to) {
|
|
30428
|
-
doc2.resolve(from2).marks().forEach((mark) => {
|
|
30429
|
-
const $pos = doc2.resolve(from2 - 1);
|
|
30430
|
-
const range2 = getMarkRange($pos, mark.type);
|
|
30431
|
-
if (!range2) {
|
|
30432
|
-
return;
|
|
30433
|
-
}
|
|
30434
|
-
marks.push({
|
|
30435
|
-
mark,
|
|
30436
|
-
...range2
|
|
30437
|
-
});
|
|
30438
|
-
});
|
|
30439
|
-
} else {
|
|
30440
|
-
doc2.nodesBetween(from2, to, (node2, pos) => {
|
|
30441
|
-
if (!node2 || node2?.nodeSize === void 0) {
|
|
30442
|
-
return;
|
|
30443
|
-
}
|
|
30444
|
-
marks.push(
|
|
30445
|
-
...node2.marks.map((mark) => ({
|
|
30446
|
-
from: pos,
|
|
30447
|
-
to: pos + node2.nodeSize,
|
|
30448
|
-
mark
|
|
30449
|
-
}))
|
|
30450
|
-
);
|
|
30451
|
-
});
|
|
30452
|
-
}
|
|
30453
|
-
return marks;
|
|
30454
|
-
}
|
|
30455
|
-
function isActive(state2, name, attrs = {}) {
|
|
30456
|
-
if (!name) {
|
|
30457
|
-
return isNodeActive(state2, null, attrs) || isMarkActive(state2, null, attrs);
|
|
30458
|
-
}
|
|
30459
|
-
const schemaType = getSchemaTypeNameByName(name, state2.schema);
|
|
30460
|
-
if (schemaType === "node") {
|
|
30461
|
-
return isNodeActive(state2, name, attrs);
|
|
30462
|
-
}
|
|
30463
|
-
if (schemaType === "mark") {
|
|
30464
|
-
return isMarkActive(state2, name, attrs);
|
|
30465
|
-
}
|
|
30466
|
-
return false;
|
|
30467
|
-
}
|
|
30468
|
-
function findChildren$3(node2, predicate) {
|
|
30469
|
-
const nodesWithPos = [];
|
|
30470
|
-
node2.descendants((child, pos) => {
|
|
30471
|
-
if (predicate(child)) {
|
|
30472
|
-
nodesWithPos.push({
|
|
30473
|
-
node: child,
|
|
30474
|
-
pos
|
|
30475
|
-
});
|
|
30476
|
-
}
|
|
30477
|
-
});
|
|
30478
|
-
return nodesWithPos;
|
|
30479
|
-
}
|
|
30480
|
-
function posToDOMRect(view, from2, to) {
|
|
30481
|
-
const minPos = 0;
|
|
30482
|
-
const maxPos = view.state.doc.content.size;
|
|
30483
|
-
const resolvedFrom = minMax(from2, minPos, maxPos);
|
|
30484
|
-
const resolvedEnd = minMax(to, minPos, maxPos);
|
|
30485
|
-
const start2 = view.coordsAtPos(resolvedFrom);
|
|
30486
|
-
const end2 = view.coordsAtPos(resolvedEnd, -1);
|
|
30487
|
-
const top2 = Math.min(start2.top, end2.top);
|
|
30488
|
-
const bottom2 = Math.max(start2.bottom, end2.bottom);
|
|
30489
|
-
const left2 = Math.min(start2.left, end2.left);
|
|
30490
|
-
const right2 = Math.max(start2.right, end2.right);
|
|
30491
|
-
const width = right2 - left2;
|
|
30492
|
-
const height = bottom2 - top2;
|
|
30493
|
-
const x = left2;
|
|
30494
|
-
const y = top2;
|
|
30495
|
-
const data = {
|
|
30496
|
-
top: top2,
|
|
30497
|
-
bottom: bottom2,
|
|
30498
|
-
left: left2,
|
|
30499
|
-
right: right2,
|
|
30500
|
-
width,
|
|
30501
|
-
height,
|
|
30502
|
-
x,
|
|
30503
|
-
y
|
|
30504
|
-
};
|
|
30505
|
-
return {
|
|
30506
|
-
...data,
|
|
30507
|
-
toJSON: () => data
|
|
30508
|
-
};
|
|
30509
|
-
}
|
|
30510
|
-
const isInTable$1 = (state2) => {
|
|
30511
|
-
const { $head } = state2.selection;
|
|
30512
|
-
for (let d = $head.depth; d > 0; d -= 1) {
|
|
30513
|
-
if ($head.node(d).type?.spec?.tableRole === "row") {
|
|
30514
|
-
return true;
|
|
30515
|
-
}
|
|
30516
|
-
}
|
|
30517
|
-
return false;
|
|
30518
|
-
};
|
|
30519
|
-
const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
30520
|
-
__proto__: null,
|
|
30521
|
-
chainableEditorState,
|
|
30522
|
-
cleanSchemaItem,
|
|
30523
|
-
createDocument,
|
|
30524
|
-
defaultBlockAt,
|
|
30525
|
-
findChildren: findChildren$3,
|
|
30526
|
-
findMark,
|
|
30527
|
-
findParentNode,
|
|
30528
|
-
findParentNodeClosestToPos,
|
|
30529
|
-
generateDocxListAttributes,
|
|
30530
|
-
generateDocxRandomId,
|
|
30531
|
-
generateRandom32BitHex,
|
|
30532
|
-
getActiveFormatting,
|
|
30533
|
-
getExtensionConfigField,
|
|
30534
|
-
getMarkRange,
|
|
30535
|
-
getMarkType,
|
|
30536
|
-
getMarksBetween,
|
|
30537
|
-
getMarksFromSelection,
|
|
30538
|
-
getNodeType,
|
|
30539
|
-
getSchemaTypeByName,
|
|
30540
|
-
getSchemaTypeNameByName,
|
|
30541
|
-
isActive,
|
|
30542
|
-
isInTable: isInTable$1,
|
|
30543
|
-
isList,
|
|
30544
|
-
isMarkActive,
|
|
30545
|
-
isNodeActive,
|
|
30546
|
-
isTextSelection,
|
|
30547
|
-
posToDOMRect
|
|
30548
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
30549
30550
|
const global$1 = globalThis || void 0 || self;
|
|
30550
30551
|
const domIndex = function(node2) {
|
|
30551
30552
|
for (var index2 = 0; ; index2++) {
|
|
@@ -39577,8 +39578,8 @@ const getTrackedChangeText = ({
|
|
|
39577
39578
|
deletionText = node2?.text ?? "";
|
|
39578
39579
|
if (isDeletionInsertion) {
|
|
39579
39580
|
let { id } = marks.deletionMark.attrs;
|
|
39580
|
-
let deletionNode = findNode$1(state2.doc, (
|
|
39581
|
-
const { marks: marks2 = [] } =
|
|
39581
|
+
let deletionNode = findNode$1(state2.doc, (node3) => {
|
|
39582
|
+
const { marks: marks2 = [] } = node3;
|
|
39582
39583
|
const changeMarks = marks2.filter((mark2) => TRACK_CHANGE_MARKS.includes(mark2.type.name));
|
|
39583
39584
|
if (!changeMarks.length) return false;
|
|
39584
39585
|
const hasMatchingId = changeMarks.find((mark2) => mark2.attrs.id === id);
|
|
@@ -39601,12 +39602,12 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes
|
|
|
39601
39602
|
const node2 = nodes[0];
|
|
39602
39603
|
const isDeletionInsertion = !!(marks.insertedMark && marks.deletionMark);
|
|
39603
39604
|
let existingNode;
|
|
39604
|
-
newEditorState.doc.descendants((
|
|
39605
|
-
const { marks: marks2 = [] } =
|
|
39605
|
+
newEditorState.doc.descendants((node3, pos) => {
|
|
39606
|
+
const { marks: marks2 = [] } = node3;
|
|
39606
39607
|
const changeMarks = marks2.filter((mark) => TRACK_CHANGE_MARKS.includes(mark.type.name));
|
|
39607
39608
|
if (!changeMarks.length) return;
|
|
39608
39609
|
const hasMatchingId = changeMarks.find((mark) => mark.attrs.id === id);
|
|
39609
|
-
if (hasMatchingId) existingNode =
|
|
39610
|
+
if (hasMatchingId) existingNode = node3;
|
|
39610
39611
|
if (existingNode) return false;
|
|
39611
39612
|
});
|
|
39612
39613
|
const { deletionText, trackedChangeText } = getTrackedChangeText({
|
|
@@ -39639,8 +39640,8 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes
|
|
|
39639
39640
|
};
|
|
39640
39641
|
function findNode$1(node2, predicate) {
|
|
39641
39642
|
let found2 = null;
|
|
39642
|
-
node2.descendants((
|
|
39643
|
-
if (predicate(
|
|
39643
|
+
node2.descendants((node3, pos) => {
|
|
39644
|
+
if (predicate(node3)) found2 = { node: node3, pos };
|
|
39644
39645
|
if (found2) return false;
|
|
39645
39646
|
});
|
|
39646
39647
|
return found2;
|
|
@@ -40957,7 +40958,14 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
40957
40958
|
* @param {boolean} [options.getUpdatedDocs=false] - When set to true return only updated docx files
|
|
40958
40959
|
* @returns {Promise<Blob|ArrayBuffer|Object>} The exported DOCX file or updated docx files
|
|
40959
40960
|
*/
|
|
40960
|
-
async exportDocx({
|
|
40961
|
+
async exportDocx({
|
|
40962
|
+
isFinalDoc = false,
|
|
40963
|
+
commentsType = "external",
|
|
40964
|
+
exportJsonOnly = false,
|
|
40965
|
+
exportXmlOnly = false,
|
|
40966
|
+
comments = [],
|
|
40967
|
+
getUpdatedDocs = false
|
|
40968
|
+
} = {}) {
|
|
40961
40969
|
const json = __privateMethod$1(this, _Editor_instances, prepareDocumentForExport_fn).call(this, comments);
|
|
40962
40970
|
const documentXml = await this.converter.exportToDocx(
|
|
40963
40971
|
json,
|
|
@@ -40966,8 +40974,10 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
40966
40974
|
isFinalDoc,
|
|
40967
40975
|
commentsType,
|
|
40968
40976
|
comments,
|
|
40969
|
-
this
|
|
40977
|
+
this,
|
|
40978
|
+
exportJsonOnly
|
|
40970
40979
|
);
|
|
40980
|
+
if (exportXmlOnly || exportJsonOnly) return documentXml;
|
|
40971
40981
|
const customXml = this.converter.schemaToXml(this.converter.convertedXml["docProps/custom.xml"].elements[0]);
|
|
40972
40982
|
const styles = this.converter.schemaToXml(this.converter.convertedXml["word/styles.xml"].elements[0]);
|
|
40973
40983
|
const customSettings = this.converter.schemaToXml(this.converter.convertedXml["word/settings.xml"].elements[0]);
|
|
@@ -41050,7 +41060,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
41050
41060
|
* @returns {Object | void} Migration results
|
|
41051
41061
|
*/
|
|
41052
41062
|
processCollaborationMigrations() {
|
|
41053
|
-
console.debug("[checkVersionMigrations] Current editor version", "0.
|
|
41063
|
+
console.debug("[checkVersionMigrations] Current editor version", "0.13.0-RC2");
|
|
41054
41064
|
if (!this.options.ydoc) return;
|
|
41055
41065
|
const metaMap = this.options.ydoc.getMap("meta");
|
|
41056
41066
|
let docVersion = metaMap.get("version");
|
|
@@ -41453,7 +41463,6 @@ initPagination_fn = async function() {
|
|
|
41453
41463
|
if (this.options.isHeadless || !this.extensionService) return;
|
|
41454
41464
|
const pagination = this.options.extensions.find((e) => e.name === "pagination");
|
|
41455
41465
|
if (pagination && this.options.pagination) {
|
|
41456
|
-
console.debug("🔗 [super-editor] Initializing pagination");
|
|
41457
41466
|
const sectionData = await initPaginationData(this);
|
|
41458
41467
|
this.storage.pagination.sectionData = sectionData;
|
|
41459
41468
|
const { state: state2, dispatch } = this.view;
|
|
@@ -42988,7 +42997,7 @@ const OrderedList = Node$1.create({
|
|
|
42988
42997
|
// rendered: false,
|
|
42989
42998
|
},
|
|
42990
42999
|
listId: {
|
|
42991
|
-
|
|
43000
|
+
keepOnSplit: true,
|
|
42992
43001
|
parseDOM: (elem) => elem.getAttribute("data-list-id"),
|
|
42993
43002
|
renderDOM: (attrs) => {
|
|
42994
43003
|
if (!attrs.listId) return {};
|
|
@@ -43025,8 +43034,8 @@ const OrderedList = Node$1.create({
|
|
|
43025
43034
|
},
|
|
43026
43035
|
addCommands() {
|
|
43027
43036
|
return {
|
|
43028
|
-
toggleOrderedList: () => ({
|
|
43029
|
-
return
|
|
43037
|
+
toggleOrderedList: () => ({ tr, editor, chain }) => {
|
|
43038
|
+
return ListHelpers.createNewList({ listType: this, editor, chain });
|
|
43030
43039
|
},
|
|
43031
43040
|
getCurrentList: () => ({ state: state2 }) => {
|
|
43032
43041
|
return findParentNode((node2) => node2.type.name === this.name)(state2.selection);
|
|
@@ -43170,6 +43179,164 @@ const OrderedList = Node$1.create({
|
|
|
43170
43179
|
];
|
|
43171
43180
|
}
|
|
43172
43181
|
});
|
|
43182
|
+
const LinkedStylesPluginKey = new PluginKey("linkedStyles");
|
|
43183
|
+
const LinkedStyles = Extension.create({
|
|
43184
|
+
name: "linkedStyles",
|
|
43185
|
+
priority: 1,
|
|
43186
|
+
// We need this plugin to run before the list plugins
|
|
43187
|
+
addPmPlugins() {
|
|
43188
|
+
return [createLinkedStylesPlugin(this.editor)];
|
|
43189
|
+
},
|
|
43190
|
+
addCommands() {
|
|
43191
|
+
return {
|
|
43192
|
+
setLinkedStyle: (style2) => (params2) => {
|
|
43193
|
+
if (!style2) return;
|
|
43194
|
+
const { tr } = params2;
|
|
43195
|
+
const selection = tr.selection;
|
|
43196
|
+
const { from: from2, to } = selection;
|
|
43197
|
+
if (from2 === to) return;
|
|
43198
|
+
let pos = from2;
|
|
43199
|
+
let paragraphNode = tr.doc.nodeAt(from2);
|
|
43200
|
+
if (paragraphNode.type.name !== "paragraph") {
|
|
43201
|
+
const parentNode2 = findParentNode((node2) => node2.type.name === "paragraph")(tr.selection) || {};
|
|
43202
|
+
pos = parentNode2.pos;
|
|
43203
|
+
paragraphNode = parentNode2.node;
|
|
43204
|
+
}
|
|
43205
|
+
tr.setNodeMarkup(pos, void 0, {
|
|
43206
|
+
...paragraphNode.attrs,
|
|
43207
|
+
styleId: style2.id
|
|
43208
|
+
});
|
|
43209
|
+
}
|
|
43210
|
+
};
|
|
43211
|
+
}
|
|
43212
|
+
});
|
|
43213
|
+
const createLinkedStylesPlugin = (editor) => {
|
|
43214
|
+
return new Plugin({
|
|
43215
|
+
key: LinkedStylesPluginKey,
|
|
43216
|
+
state: {
|
|
43217
|
+
init(_, { doc: doc2, selection }) {
|
|
43218
|
+
if (!editor.converter || editor.options.mode !== "docx") return {};
|
|
43219
|
+
const styles = editor.converter?.linkedStyles || [];
|
|
43220
|
+
return {
|
|
43221
|
+
styles,
|
|
43222
|
+
decorations: generateDecorations(editor.state, styles)
|
|
43223
|
+
};
|
|
43224
|
+
},
|
|
43225
|
+
apply(tr, prev, oldEditorState, newEditorState) {
|
|
43226
|
+
if (!editor.converter || editor.options.mode !== "docx") return { ...prev };
|
|
43227
|
+
let decorations = prev.decorations || DecorationSet.empty;
|
|
43228
|
+
if (tr.docChanged) {
|
|
43229
|
+
const styles = LinkedStylesPluginKey.getState(editor.state).styles;
|
|
43230
|
+
decorations = generateDecorations(newEditorState, styles);
|
|
43231
|
+
}
|
|
43232
|
+
return { ...prev, decorations };
|
|
43233
|
+
}
|
|
43234
|
+
},
|
|
43235
|
+
props: {
|
|
43236
|
+
decorations(state2) {
|
|
43237
|
+
return LinkedStylesPluginKey.getState(state2)?.decorations;
|
|
43238
|
+
}
|
|
43239
|
+
}
|
|
43240
|
+
});
|
|
43241
|
+
};
|
|
43242
|
+
const generateDecorations = (state2, styles) => {
|
|
43243
|
+
const decorations = [];
|
|
43244
|
+
let lastStyleId = null;
|
|
43245
|
+
const doc2 = state2?.doc;
|
|
43246
|
+
doc2.descendants((node2, pos) => {
|
|
43247
|
+
const { name } = node2.type;
|
|
43248
|
+
if (node2?.attrs?.styleId) lastStyleId = node2.attrs.styleId;
|
|
43249
|
+
if (name === "paragraph" && !node2.attrs?.styleId) lastStyleId = null;
|
|
43250
|
+
if (name !== "text") return;
|
|
43251
|
+
const linkedStyle = getLinkedStyle(lastStyleId, styles);
|
|
43252
|
+
if (!linkedStyle) return;
|
|
43253
|
+
const $pos = state2.doc.resolve(pos);
|
|
43254
|
+
const parent = $pos.parent;
|
|
43255
|
+
const styleString = generateLinkedStyleString(linkedStyle, node2, parent);
|
|
43256
|
+
if (!styleString) return;
|
|
43257
|
+
const decoration = Decoration.inline(pos, pos + node2.nodeSize, { style: styleString });
|
|
43258
|
+
decorations.push(decoration);
|
|
43259
|
+
});
|
|
43260
|
+
return DecorationSet.create(doc2, decorations);
|
|
43261
|
+
};
|
|
43262
|
+
const generateLinkedStyleString = (linkedStyle, node2, parent, includeSpacing = true) => {
|
|
43263
|
+
if (!linkedStyle?.definition?.styles) return "";
|
|
43264
|
+
const markValue = {};
|
|
43265
|
+
Object.entries(linkedStyle.definition.styles).forEach(([k, value]) => {
|
|
43266
|
+
const key = kebabCase$1(k);
|
|
43267
|
+
const flattenedMarks = [];
|
|
43268
|
+
node2?.marks?.forEach((n) => {
|
|
43269
|
+
if (n.type.name === "textStyle") {
|
|
43270
|
+
Object.entries(n.attrs).forEach(([styleKey, value2]) => {
|
|
43271
|
+
const parsedKey = kebabCase$1(styleKey);
|
|
43272
|
+
if (!value2) return;
|
|
43273
|
+
flattenedMarks.push({ key: parsedKey, value: value2 });
|
|
43274
|
+
});
|
|
43275
|
+
return;
|
|
43276
|
+
}
|
|
43277
|
+
flattenedMarks.push({ key: n.type.name, value: n.attrs[key] });
|
|
43278
|
+
});
|
|
43279
|
+
const mark = flattenedMarks.find((n) => n.key === key);
|
|
43280
|
+
const hasParentIndent = Object.keys(parent?.attrs?.indent || {});
|
|
43281
|
+
const hasParentSpacing = Object.keys(parent?.attrs?.spacing || {});
|
|
43282
|
+
if (!mark) {
|
|
43283
|
+
if (key === "spacing" && includeSpacing && !hasParentSpacing) ;
|
|
43284
|
+
else if (key === "indent" && includeSpacing && !hasParentIndent) {
|
|
43285
|
+
const { leftIndent, rightIndent, firstLine } = value;
|
|
43286
|
+
if (leftIndent) markValue["margin-left"] = leftIndent + "px";
|
|
43287
|
+
if (rightIndent) markValue["margin-right"] = rightIndent + "px";
|
|
43288
|
+
if (firstLine) markValue["text-indent"] = firstLine + "px";
|
|
43289
|
+
} else if (key === "bold") {
|
|
43290
|
+
markValue["font-weight"] = "bold";
|
|
43291
|
+
} else if (typeof value === "string") markValue[key] = value;
|
|
43292
|
+
}
|
|
43293
|
+
});
|
|
43294
|
+
const final = Object.entries(markValue).map(([key, value]) => `${key}: ${value}`).join(";");
|
|
43295
|
+
return final;
|
|
43296
|
+
};
|
|
43297
|
+
const getLinkedStyle = (styleId, styles = []) => {
|
|
43298
|
+
return styles.find((style2) => style2.id === styleId);
|
|
43299
|
+
};
|
|
43300
|
+
const getSpacingStyleString = (spacing) => {
|
|
43301
|
+
const { lineSpaceBefore, lineSpaceAfter, line } = spacing;
|
|
43302
|
+
return `
|
|
43303
|
+
${lineSpaceBefore ? `margin-top: ${lineSpaceBefore}px;` : ""}
|
|
43304
|
+
${lineSpaceAfter ? `margin-bottom: ${lineSpaceAfter}px;` : ""}
|
|
43305
|
+
${line ? getLineHeightValueString(line, "") : ""}
|
|
43306
|
+
`.trim();
|
|
43307
|
+
};
|
|
43308
|
+
const getMarksStyle = (attrs) => {
|
|
43309
|
+
let styles = "";
|
|
43310
|
+
for (const attr of attrs) {
|
|
43311
|
+
switch (attr.type) {
|
|
43312
|
+
case "bold":
|
|
43313
|
+
styles += `font-weight: bold; `;
|
|
43314
|
+
break;
|
|
43315
|
+
case "italic":
|
|
43316
|
+
styles += `font-style: italic; `;
|
|
43317
|
+
break;
|
|
43318
|
+
case "underline":
|
|
43319
|
+
styles += `text-decoration: underline; `;
|
|
43320
|
+
break;
|
|
43321
|
+
case "highlight":
|
|
43322
|
+
styles += `background-color: ${attr.attrs.color}; `;
|
|
43323
|
+
break;
|
|
43324
|
+
case "textStyle":
|
|
43325
|
+
const { fontFamily: fontFamily2, fontSize: fontSize2 } = attr.attrs;
|
|
43326
|
+
styles += `${fontFamily2 ? `font-family: ${fontFamily2};` : ""} ${fontSize2 ? `font-size: ${fontSize2};` : ""}`;
|
|
43327
|
+
}
|
|
43328
|
+
}
|
|
43329
|
+
return styles.trim();
|
|
43330
|
+
};
|
|
43331
|
+
const getQuickFormatList = (editor) => {
|
|
43332
|
+
if (!editor?.converter) return [];
|
|
43333
|
+
const styles = editor.converter.linkedStyles || [];
|
|
43334
|
+
return styles.filter((style2) => {
|
|
43335
|
+
return style2.type === "paragraph" && style2.definition.attrs;
|
|
43336
|
+
}).sort((a, b) => {
|
|
43337
|
+
return a.definition.attrs?.name.localeCompare(b.definition.attrs?.name);
|
|
43338
|
+
});
|
|
43339
|
+
};
|
|
43173
43340
|
const generateOrderedListIndex = ({ listLevel, lvlText, listNumberingType }) => {
|
|
43174
43341
|
const handler = listIndexMap[listNumberingType];
|
|
43175
43342
|
return handler ? handler(listLevel, lvlText) : null;
|
|
@@ -43230,108 +43397,73 @@ const intToAlpha = (num) => {
|
|
|
43230
43397
|
}
|
|
43231
43398
|
return result;
|
|
43232
43399
|
};
|
|
43233
|
-
|
|
43234
|
-
|
|
43235
|
-
|
|
43236
|
-
|
|
43237
|
-
init(_, state2) {
|
|
43238
|
-
const decorations = [
|
|
43239
|
-
...getListMarkerDecorations(state2),
|
|
43240
|
-
...getListItemStylingFromParagraphProps(state2)
|
|
43241
|
-
];
|
|
43242
|
-
return DecorationSet.create(state2.doc, decorations);
|
|
43243
|
-
},
|
|
43244
|
-
apply(tr, oldDecorationSet, oldState, newState) {
|
|
43245
|
-
if (!tr.docChanged) return oldDecorationSet;
|
|
43246
|
-
const isOrderedListPlugin = tr.getMeta("orderedListMarker");
|
|
43247
|
-
if (isOrderedListPlugin) return oldDecorationSet;
|
|
43248
|
-
const marks = tr.getMeta("splitListItem");
|
|
43249
|
-
const decorations = [
|
|
43250
|
-
...getListMarkerDecorations(newState, marks),
|
|
43251
|
-
...getListItemStylingFromParagraphProps(newState)
|
|
43252
|
-
];
|
|
43253
|
-
return DecorationSet.create(newState.doc, decorations);
|
|
43254
|
-
}
|
|
43255
|
-
},
|
|
43256
|
-
props: {
|
|
43257
|
-
decorations(state2) {
|
|
43258
|
-
return this.getState(state2);
|
|
43259
|
-
}
|
|
43260
|
-
}
|
|
43261
|
-
});
|
|
43262
|
-
}
|
|
43263
|
-
function getListMarkerDecorations(state2, marks = []) {
|
|
43264
|
-
let { doc: doc2, storedMarks } = state2;
|
|
43265
|
-
let decorations = [];
|
|
43266
|
-
if (Array.isArray(storedMarks)) marks.push(...storedMarks);
|
|
43267
|
-
let listItems = findChildren$3(doc2, (node2) => node2.type.name === "listItem");
|
|
43268
|
-
if (!listItems.length) {
|
|
43269
|
-
return decorations;
|
|
43270
|
-
}
|
|
43271
|
-
listItems.forEach(({ node: node2, pos }) => {
|
|
43272
|
-
let textStyleType = getMarkType("textStyle", doc2.type.schema);
|
|
43273
|
-
let textStyleMarks = [...marks.filter((m) => m.type === textStyleType)];
|
|
43274
|
-
let isEmptyListItem = checkListItemEmpty(node2);
|
|
43275
|
-
if (isEmptyListItem && marks.length) {
|
|
43276
|
-
const textMarks = marks.filter((mark) => mark.type === textStyleType);
|
|
43277
|
-
textStyleMarks.push(...textMarks);
|
|
43278
|
-
} else {
|
|
43279
|
-
const itemMarks = getListItemTextStyleMarks(node2, doc2, textStyleType);
|
|
43280
|
-
textStyleMarks.push(...itemMarks);
|
|
43281
|
-
}
|
|
43282
|
-
let fontSize2 = null;
|
|
43283
|
-
let fontFamily2 = null;
|
|
43284
|
-
textStyleMarks.forEach((mark) => {
|
|
43285
|
-
let { attrs: attrs2 } = mark;
|
|
43286
|
-
if (attrs2.fontSize && !fontSize2) {
|
|
43287
|
-
let [value, unit] = parseSizeUnit(attrs2.fontSize);
|
|
43288
|
-
if (!Number.isNaN(value)) {
|
|
43289
|
-
unit = unit ?? "pt";
|
|
43290
|
-
fontSize2 = `${value}${unit}`;
|
|
43291
|
-
}
|
|
43292
|
-
}
|
|
43293
|
-
if (attrs2.fontFamily && !fontFamily2) {
|
|
43294
|
-
fontFamily2 = attrs2.fontFamily;
|
|
43295
|
-
}
|
|
43400
|
+
class ListItemNodeView {
|
|
43401
|
+
constructor(node2, getPos, decorations, editor) {
|
|
43402
|
+
__privateAdd$1(this, _ListItemNodeView_instances);
|
|
43403
|
+
__publicField$1(this, "handleNumberingClick", (event) => {
|
|
43296
43404
|
});
|
|
43297
|
-
|
|
43298
|
-
|
|
43299
|
-
|
|
43300
|
-
|
|
43301
|
-
|
|
43302
|
-
|
|
43303
|
-
|
|
43304
|
-
|
|
43305
|
-
|
|
43306
|
-
|
|
43307
|
-
|
|
43405
|
+
this.node = node2;
|
|
43406
|
+
this.editor = editor;
|
|
43407
|
+
this.decorations = decorations;
|
|
43408
|
+
this.view = editor.view;
|
|
43409
|
+
this.getPos = getPos;
|
|
43410
|
+
this.editor = editor;
|
|
43411
|
+
__privateMethod$1(this, _ListItemNodeView_instances, init_fn2).call(this);
|
|
43412
|
+
}
|
|
43413
|
+
update(node2) {
|
|
43414
|
+
if (node2.type !== this.node.type) return false;
|
|
43415
|
+
this.node = node2;
|
|
43416
|
+
return true;
|
|
43417
|
+
}
|
|
43418
|
+
destroy() {
|
|
43419
|
+
this.numberingDOM.removeEventListener("click", this.handleNumberingClick);
|
|
43420
|
+
}
|
|
43308
43421
|
}
|
|
43309
|
-
|
|
43310
|
-
|
|
43311
|
-
|
|
43312
|
-
|
|
43313
|
-
|
|
43314
|
-
|
|
43315
|
-
|
|
43316
|
-
|
|
43317
|
-
|
|
43318
|
-
|
|
43319
|
-
|
|
43320
|
-
|
|
43321
|
-
|
|
43322
|
-
|
|
43323
|
-
|
|
43324
|
-
|
|
43325
|
-
|
|
43326
|
-
style: style2
|
|
43327
|
-
};
|
|
43328
|
-
}
|
|
43329
|
-
let dec = Decoration.node(pos, pos + node2.nodeSize, spacingAttrs);
|
|
43330
|
-
decorations.push(dec);
|
|
43422
|
+
_ListItemNodeView_instances = /* @__PURE__ */ new WeakSet();
|
|
43423
|
+
init_fn2 = function() {
|
|
43424
|
+
const { attrs } = this.node;
|
|
43425
|
+
const { styleId, listLevel, listNumberingType, lvlText, numId, level, indent: inlineIndent } = attrs;
|
|
43426
|
+
let orderMarker = "";
|
|
43427
|
+
if (listLevel) {
|
|
43428
|
+
orderMarker = generateOrderedListIndex({
|
|
43429
|
+
listLevel,
|
|
43430
|
+
lvlText,
|
|
43431
|
+
listNumberingType
|
|
43432
|
+
});
|
|
43433
|
+
}
|
|
43434
|
+
const pos = this.getPos();
|
|
43435
|
+
const { fontSize: fontSize2, fontFamily: fontFamily2 } = getTextStyleMarksFromLinkedStyles({
|
|
43436
|
+
node: this.node,
|
|
43437
|
+
pos,
|
|
43438
|
+
editor: this.editor
|
|
43331
43439
|
});
|
|
43332
|
-
|
|
43333
|
-
|
|
43334
|
-
|
|
43440
|
+
const defs = getListItemStyleDefinitions({ styleId, node: this.node, numId, level, editor: this.editor });
|
|
43441
|
+
const visibleIndent = getVisibleIndent(defs.stylePpr, defs.numDefPpr, inlineIndent);
|
|
43442
|
+
console.debug("VISIBLEINDENT", visibleIndent, "\n\n\n\n");
|
|
43443
|
+
let absoluteLeft = visibleIndent.left - (visibleIndent.hanging || 0);
|
|
43444
|
+
if (!absoluteLeft && absoluteLeft !== 0) absoluteLeft = 0;
|
|
43445
|
+
this.dom = document.createElement("li");
|
|
43446
|
+
this.dom.className = "sd-editor-list-item-node-view";
|
|
43447
|
+
this.dom.style.fontSize = fontSize2;
|
|
43448
|
+
this.dom.style.fontFamily = fontFamily2;
|
|
43449
|
+
this.dom.setAttribute("data-marker-type", orderMarker);
|
|
43450
|
+
this.numberingDOM = document.createElement("span");
|
|
43451
|
+
this.numberingDOM.className = "sd-editor-list-item-numbering";
|
|
43452
|
+
this.numberingDOM.textContent = orderMarker;
|
|
43453
|
+
this.numberingDOM.setAttribute("contenteditable", "false");
|
|
43454
|
+
this.numberingDOM.addEventListener("click", this.handleNumberingClick);
|
|
43455
|
+
this.contentDOM = document.createElement("p");
|
|
43456
|
+
this.contentDOM.className = "sd-editor-list-item-content-dom";
|
|
43457
|
+
let contentLeft = visibleIndent.left;
|
|
43458
|
+
if (visibleIndent.left === absoluteLeft) {
|
|
43459
|
+
contentLeft = 48;
|
|
43460
|
+
}
|
|
43461
|
+
this.contentDOM.style.marginLeft = `${contentLeft}px`;
|
|
43462
|
+
this.numberingDOM.style.left = `${absoluteLeft}px`;
|
|
43463
|
+
this.dom.appendChild(this.numberingDOM);
|
|
43464
|
+
this.dom.appendChild(this.contentDOM);
|
|
43465
|
+
};
|
|
43466
|
+
function getListItemTextStyleMarks(listItem, markType) {
|
|
43335
43467
|
let textStyleMarks = [];
|
|
43336
43468
|
listItem.forEach((childNode) => {
|
|
43337
43469
|
if (childNode.type.name !== "paragraph") return;
|
|
@@ -43346,9 +43478,57 @@ function getListItemTextStyleMarks(listItem, doc2, markType) {
|
|
|
43346
43478
|
});
|
|
43347
43479
|
return textStyleMarks;
|
|
43348
43480
|
}
|
|
43349
|
-
function
|
|
43350
|
-
|
|
43351
|
-
|
|
43481
|
+
function getTextStyleMarksFromLinkedStyles({ node: node2, pos, editor }) {
|
|
43482
|
+
const { font: defaultFont, size: defaultSize } = getStylesFromLinkedStyles({ node: node2, pos, editor });
|
|
43483
|
+
const textStyleType = getMarkType("textStyle", editor.schema);
|
|
43484
|
+
const allMarks = getListItemTextStyleMarks(node2, textStyleType);
|
|
43485
|
+
const styleMarks = allMarks.filter((m) => m.type === textStyleType);
|
|
43486
|
+
const sizeMark = styleMarks.find((m) => m.attrs.fontSize);
|
|
43487
|
+
const familyMark = styleMarks.find((m) => m.attrs.fontFamily);
|
|
43488
|
+
const fontSize2 = sizeMark ? (() => {
|
|
43489
|
+
const [value, unit = "pt"] = parseSizeUnit(sizeMark.attrs.fontSize);
|
|
43490
|
+
return Number.isNaN(value) ? defaultSize : `${value}${unit}`;
|
|
43491
|
+
})() : defaultSize;
|
|
43492
|
+
const fontFamily2 = familyMark?.attrs.fontFamily ?? defaultFont;
|
|
43493
|
+
return { fontSize: fontSize2, fontFamily: fontFamily2 };
|
|
43494
|
+
}
|
|
43495
|
+
const getStylesFromLinkedStyles = ({ node: node2, pos, editor }) => {
|
|
43496
|
+
const { state: state2 } = editor.view;
|
|
43497
|
+
const linkedStyles = LinkedStylesPluginKey.getState(state2)?.decorations;
|
|
43498
|
+
const decorationsInPlace = linkedStyles?.find(pos, pos + node2.nodeSize);
|
|
43499
|
+
const styleDeco = decorationsInPlace?.find((dec) => dec.type.attrs?.style);
|
|
43500
|
+
const style2 = styleDeco?.type.attrs?.style;
|
|
43501
|
+
const stylesArray = style2?.split(";") || [];
|
|
43502
|
+
const fontSizeFromStyles = stylesArray.find((s) => s.includes("font-size"))?.split(":")[1].trim();
|
|
43503
|
+
const fontFamilyFromStyles = stylesArray.find((s) => s.includes("font-family"))?.split(":")[1].trim();
|
|
43504
|
+
return {
|
|
43505
|
+
font: fontFamilyFromStyles,
|
|
43506
|
+
size: fontSizeFromStyles
|
|
43507
|
+
};
|
|
43508
|
+
};
|
|
43509
|
+
const getVisibleIndent = (stylePpr, numDefPpr, inlineIndent) => {
|
|
43510
|
+
console.debug("[getVisibleIndent] inlineIndent", inlineIndent);
|
|
43511
|
+
const styleIndentTag = stylePpr?.elements?.find((el) => el.name === "w:ind") || {};
|
|
43512
|
+
const styleIndent = parseIndentElement(styleIndentTag);
|
|
43513
|
+
console.debug("[getVisibleIndent] styleIndent", styleIndent, styleIndentTag);
|
|
43514
|
+
const numDefIndentTag = numDefPpr?.elements?.find((el) => el.name === "w:ind") || {};
|
|
43515
|
+
const numDefIndent = parseIndentElement(numDefIndentTag);
|
|
43516
|
+
console.debug("[getVisibleIndent] numDefIndent", numDefIndent, numDefIndentTag, "\n\n");
|
|
43517
|
+
const indent = combineIndents(styleIndent, numDefIndent);
|
|
43518
|
+
return combineIndents(indent, inlineIndent);
|
|
43519
|
+
};
|
|
43520
|
+
const getListItemStyleDefinitions = ({ styleId, numId, level, editor }) => {
|
|
43521
|
+
const docx = editor?.converter?.convertedXml;
|
|
43522
|
+
const styleDefinition = getStyleTagFromStyleId(styleId, docx);
|
|
43523
|
+
const stylePpr = styleDefinition?.elements.find((el) => el.name === "w:pPr");
|
|
43524
|
+
const abstractDefinition = getAbstractDefinition(numId, docx);
|
|
43525
|
+
const numDefinition = getDefinitionForLevel(abstractDefinition, level);
|
|
43526
|
+
const numDefPpr = numDefinition?.elements.find((el) => el.name === "w:pPr");
|
|
43527
|
+
return {
|
|
43528
|
+
stylePpr,
|
|
43529
|
+
numDefPpr
|
|
43530
|
+
};
|
|
43531
|
+
};
|
|
43352
43532
|
const ListItem = Node$1.create({
|
|
43353
43533
|
name: "listItem",
|
|
43354
43534
|
content: "paragraph* block*",
|
|
@@ -43370,6 +43550,15 @@ const ListItem = Node$1.create({
|
|
|
43370
43550
|
renderDOM({ htmlAttributes }) {
|
|
43371
43551
|
return ["li", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
|
|
43372
43552
|
},
|
|
43553
|
+
/**
|
|
43554
|
+
* Important: The listItem node uses a custom node view.
|
|
43555
|
+
* @returns {import('@core/NodeView.js').NodeView}
|
|
43556
|
+
*/
|
|
43557
|
+
addNodeView() {
|
|
43558
|
+
return ({ node: node2, editor, getPos, decorations }) => {
|
|
43559
|
+
return new ListItemNodeView(node2, getPos, decorations, editor);
|
|
43560
|
+
};
|
|
43561
|
+
},
|
|
43373
43562
|
addAttributes() {
|
|
43374
43563
|
return {
|
|
43375
43564
|
// Virtual attribute.
|
|
@@ -43394,6 +43583,7 @@ const ListItem = Node$1.create({
|
|
|
43394
43583
|
},
|
|
43395
43584
|
lvlText: {
|
|
43396
43585
|
default: null,
|
|
43586
|
+
keepOnSplit: true,
|
|
43397
43587
|
parseDOM: (elem) => elem.getAttribute("data-lvl-text"),
|
|
43398
43588
|
renderDOM: (attrs) => {
|
|
43399
43589
|
if (!attrs.lvlText) return {};
|
|
@@ -43404,6 +43594,7 @@ const ListItem = Node$1.create({
|
|
|
43404
43594
|
},
|
|
43405
43595
|
listNumberingType: {
|
|
43406
43596
|
default: null,
|
|
43597
|
+
keepOnSplit: true,
|
|
43407
43598
|
parseDOM: (elem) => elem.getAttribute("data-num-fmt"),
|
|
43408
43599
|
renderDOM: (attrs) => {
|
|
43409
43600
|
if (!attrs.listNumberingType) return {};
|
|
@@ -43414,6 +43605,7 @@ const ListItem = Node$1.create({
|
|
|
43414
43605
|
},
|
|
43415
43606
|
listLevel: {
|
|
43416
43607
|
default: null,
|
|
43608
|
+
keepOnSplit: true,
|
|
43417
43609
|
parseDOM: (elem) => {
|
|
43418
43610
|
let listLevel = elem.getAttribute("data-list-level");
|
|
43419
43611
|
try {
|
|
@@ -43431,52 +43623,61 @@ const ListItem = Node$1.create({
|
|
|
43431
43623
|
},
|
|
43432
43624
|
// JC = justification. Expect left, right, center
|
|
43433
43625
|
lvlJc: {
|
|
43626
|
+
keepOnSplit: true,
|
|
43434
43627
|
default: null,
|
|
43435
43628
|
rendered: false
|
|
43436
43629
|
},
|
|
43437
43630
|
// This will contain indentation and space info.
|
|
43438
43631
|
// ie: w:left (left indent), w:hanging (hanging indent)
|
|
43439
43632
|
listParagraphProperties: {
|
|
43633
|
+
keepOnSplit: true,
|
|
43440
43634
|
default: null,
|
|
43441
43635
|
rendered: false
|
|
43442
43636
|
},
|
|
43443
43637
|
// This will contain run properties for the list item
|
|
43444
43638
|
listRunProperties: {
|
|
43639
|
+
keepOnSplit: true,
|
|
43445
43640
|
default: null,
|
|
43446
43641
|
rendered: false
|
|
43447
43642
|
},
|
|
43448
43643
|
numId: {
|
|
43644
|
+
keepOnSplit: true,
|
|
43449
43645
|
default: null,
|
|
43450
|
-
parseDOM: (elem) => elem.getAttribute("data-num-id")
|
|
43451
|
-
},
|
|
43452
|
-
attributes: {
|
|
43453
43646
|
rendered: false
|
|
43454
43647
|
},
|
|
43455
|
-
|
|
43456
|
-
|
|
43457
|
-
|
|
43458
|
-
|
|
43459
|
-
return {
|
|
43460
|
-
"data-font-size": attrs.importedFontSize
|
|
43461
|
-
};
|
|
43462
|
-
}
|
|
43648
|
+
numPrType: {
|
|
43649
|
+
rendered: false,
|
|
43650
|
+
default: null,
|
|
43651
|
+
keepOnSplit: true
|
|
43463
43652
|
},
|
|
43464
|
-
|
|
43465
|
-
|
|
43466
|
-
|
|
43467
|
-
|
|
43468
|
-
|
|
43469
|
-
|
|
43470
|
-
|
|
43471
|
-
|
|
43653
|
+
level: {
|
|
43654
|
+
default: null,
|
|
43655
|
+
rendered: false,
|
|
43656
|
+
keepOnSplit: true
|
|
43657
|
+
},
|
|
43658
|
+
attributes: {
|
|
43659
|
+
keepOnSplit: true,
|
|
43660
|
+
rendered: false
|
|
43472
43661
|
},
|
|
43473
43662
|
spacing: {
|
|
43663
|
+
keepOnSplit: true,
|
|
43474
43664
|
default: null,
|
|
43475
43665
|
rendered: false
|
|
43476
43666
|
},
|
|
43477
43667
|
indent: {
|
|
43668
|
+
keepOnSplit: true,
|
|
43478
43669
|
default: null,
|
|
43479
43670
|
rendered: false
|
|
43671
|
+
},
|
|
43672
|
+
markerStyle: {
|
|
43673
|
+
default: null,
|
|
43674
|
+
rendered: false,
|
|
43675
|
+
keepOnSplit: true
|
|
43676
|
+
},
|
|
43677
|
+
styleId: {
|
|
43678
|
+
rendered: false,
|
|
43679
|
+
keepOnSplit: true,
|
|
43680
|
+
keepOnSplit: true
|
|
43480
43681
|
}
|
|
43481
43682
|
};
|
|
43482
43683
|
},
|
|
@@ -43485,49 +43686,21 @@ const ListItem = Node$1.create({
|
|
|
43485
43686
|
getCurrentListNode: () => ({ state: state2 }) => {
|
|
43486
43687
|
return findParentNode((node2) => node2.type.name === this.name)(state2.selection);
|
|
43487
43688
|
},
|
|
43488
|
-
increaseListIndent: () => ({ commands: commands2 }) => {
|
|
43489
|
-
|
|
43490
|
-
|
|
43491
|
-
}
|
|
43492
|
-
commands2.updateNodeStyle();
|
|
43493
|
-
commands2.updateOrderedListStyleType();
|
|
43494
|
-
return true;
|
|
43495
|
-
},
|
|
43496
|
-
decreaseListIndent: () => ({ commands: commands2 }) => {
|
|
43497
|
-
const currentList = commands2.getCurrentList();
|
|
43498
|
-
const depth = currentList?.depth;
|
|
43499
|
-
if (depth === 1) return false;
|
|
43500
|
-
if (!commands2.liftListItem(this.name)) {
|
|
43501
|
-
return true;
|
|
43502
|
-
}
|
|
43503
|
-
if (!commands2.updateNodeStyle()) {
|
|
43504
|
-
return false;
|
|
43505
|
-
}
|
|
43506
|
-
const currentNode = commands2.getCurrentListNode();
|
|
43507
|
-
const currentNodeIndex = currentList?.node?.children.findIndex((child) => child === currentNode.node);
|
|
43508
|
-
const nextNodePos = currentNode?.pos + currentNode?.node.nodeSize;
|
|
43509
|
-
const followingNodes = currentList?.node?.children.slice(currentNodeIndex + 1) || [];
|
|
43510
|
-
commands2.updateOrderedListStyleType();
|
|
43511
|
-
commands2.restartListNodes(followingNodes, nextNodePos);
|
|
43512
|
-
return true;
|
|
43689
|
+
increaseListIndent: () => ({ commands: commands2, chain, editor }) => {
|
|
43690
|
+
const node2 = commands2.getCurrentListNode();
|
|
43691
|
+
return ListHelpers.indentListItem({ editor, chain, node: node2 });
|
|
43513
43692
|
},
|
|
43514
|
-
|
|
43515
|
-
|
|
43516
|
-
|
|
43517
|
-
if (!list) return false;
|
|
43518
|
-
const firstNodeAttrs = list?.node.children[0]?.attrs;
|
|
43519
|
-
const newPos = tr.mapping.map(current.pos);
|
|
43520
|
-
tr.setNodeMarkup(newPos, void 0, {
|
|
43521
|
-
...firstNodeAttrs
|
|
43522
|
-
});
|
|
43523
|
-
return true;
|
|
43693
|
+
decreaseListIndent: () => ({ commands: commands2, chain, editor }) => {
|
|
43694
|
+
const node2 = commands2.getCurrentListNode();
|
|
43695
|
+
return ListHelpers.outdentListItem({ editor, chain, node: node2 });
|
|
43524
43696
|
}
|
|
43525
43697
|
};
|
|
43526
43698
|
},
|
|
43527
43699
|
addShortcuts() {
|
|
43528
43700
|
return {
|
|
43529
43701
|
Enter: () => {
|
|
43530
|
-
|
|
43702
|
+
const node2 = this.editor.commands.getCurrentListNode();
|
|
43703
|
+
return this.editor.commands.splitListItem(this.name, node2);
|
|
43531
43704
|
},
|
|
43532
43705
|
"Shift-Enter": () => {
|
|
43533
43706
|
return this.editor.commands.first(({ commands: commands2 }) => [
|
|
@@ -43542,180 +43715,8 @@ const ListItem = Node$1.create({
|
|
|
43542
43715
|
return this.editor.commands.decreaseListIndent();
|
|
43543
43716
|
}
|
|
43544
43717
|
};
|
|
43545
|
-
},
|
|
43546
|
-
addPmPlugins() {
|
|
43547
|
-
return [styledListMarker()];
|
|
43548
43718
|
}
|
|
43549
43719
|
});
|
|
43550
|
-
const LinkedStylesPluginKey = new PluginKey("linkedStyles");
|
|
43551
|
-
const LinkedStyles = Extension.create({
|
|
43552
|
-
name: "linkedStyles",
|
|
43553
|
-
addPmPlugins() {
|
|
43554
|
-
return [createLinkedStylesPlugin(this.editor)];
|
|
43555
|
-
},
|
|
43556
|
-
addCommands() {
|
|
43557
|
-
return {
|
|
43558
|
-
setLinkedStyle: (style2) => (params2) => {
|
|
43559
|
-
if (!style2) return;
|
|
43560
|
-
const { tr } = params2;
|
|
43561
|
-
const selection = tr.selection;
|
|
43562
|
-
const { from: from2, to } = selection;
|
|
43563
|
-
if (from2 === to) return;
|
|
43564
|
-
let pos = from2;
|
|
43565
|
-
let paragraphNode = tr.doc.nodeAt(from2);
|
|
43566
|
-
if (paragraphNode.type.name !== "paragraph") {
|
|
43567
|
-
const parentNode2 = findParentNode((node2) => node2.type.name === "paragraph")(tr.selection) || {};
|
|
43568
|
-
pos = parentNode2.pos;
|
|
43569
|
-
paragraphNode = parentNode2.node;
|
|
43570
|
-
}
|
|
43571
|
-
tr.setNodeMarkup(pos, void 0, {
|
|
43572
|
-
...paragraphNode.attrs,
|
|
43573
|
-
styleId: style2.id
|
|
43574
|
-
});
|
|
43575
|
-
}
|
|
43576
|
-
};
|
|
43577
|
-
}
|
|
43578
|
-
});
|
|
43579
|
-
const createLinkedStylesPlugin = (editor) => {
|
|
43580
|
-
return new Plugin({
|
|
43581
|
-
key: LinkedStylesPluginKey,
|
|
43582
|
-
state: {
|
|
43583
|
-
init(_, { doc: doc2, selection }) {
|
|
43584
|
-
if (!editor.converter || editor.options.mode !== "docx") return {};
|
|
43585
|
-
const styles = editor.converter?.linkedStyles || [];
|
|
43586
|
-
return {
|
|
43587
|
-
styles,
|
|
43588
|
-
decorations: generateDecorations(editor.state, styles)
|
|
43589
|
-
};
|
|
43590
|
-
},
|
|
43591
|
-
apply(tr, prev, oldEditorState, newEditorState) {
|
|
43592
|
-
if (!editor.converter || editor.options.mode !== "docx") return { ...prev };
|
|
43593
|
-
let decorations = prev.decorations || DecorationSet.empty;
|
|
43594
|
-
if (tr.docChanged) {
|
|
43595
|
-
const styles = LinkedStylesPluginKey.getState(editor.state).styles;
|
|
43596
|
-
decorations = generateDecorations(newEditorState, styles);
|
|
43597
|
-
}
|
|
43598
|
-
return { ...prev, decorations };
|
|
43599
|
-
}
|
|
43600
|
-
},
|
|
43601
|
-
props: {
|
|
43602
|
-
decorations(state2) {
|
|
43603
|
-
return LinkedStylesPluginKey.getState(state2)?.decorations;
|
|
43604
|
-
}
|
|
43605
|
-
}
|
|
43606
|
-
});
|
|
43607
|
-
};
|
|
43608
|
-
const generateDecorations = (state2, styles) => {
|
|
43609
|
-
const decorations = [];
|
|
43610
|
-
let lastStyleId = null;
|
|
43611
|
-
const doc2 = state2?.doc;
|
|
43612
|
-
doc2.descendants((node2, pos) => {
|
|
43613
|
-
const { name } = node2.type;
|
|
43614
|
-
if (node2?.attrs?.styleId) lastStyleId = node2.attrs.styleId;
|
|
43615
|
-
if (name === "paragraph" && !node2.attrs?.styleId) lastStyleId = null;
|
|
43616
|
-
if (name !== "text") return;
|
|
43617
|
-
const linkedStyle = getLinkedStyle(lastStyleId, styles);
|
|
43618
|
-
if (!linkedStyle) return;
|
|
43619
|
-
const $pos = state2.doc.resolve(pos);
|
|
43620
|
-
const parent = $pos.parent;
|
|
43621
|
-
const styleString = generateLinkedStyleString(linkedStyle, node2, parent);
|
|
43622
|
-
if (!styleString) return;
|
|
43623
|
-
const decoration = Decoration.inline(pos, pos + node2.nodeSize, { style: styleString });
|
|
43624
|
-
decorations.push(decoration);
|
|
43625
|
-
});
|
|
43626
|
-
return DecorationSet.create(doc2, decorations);
|
|
43627
|
-
};
|
|
43628
|
-
const generateLinkedStyleString = (linkedStyle, node2, parent, includeSpacing = true) => {
|
|
43629
|
-
if (!linkedStyle?.definition?.styles) return "";
|
|
43630
|
-
const markValue = {};
|
|
43631
|
-
Object.entries(linkedStyle.definition.styles).forEach(([k, value]) => {
|
|
43632
|
-
const key = kebabCase$1(k);
|
|
43633
|
-
const flattenedMarks = [];
|
|
43634
|
-
node2?.marks?.forEach((n) => {
|
|
43635
|
-
if (n.type.name === "textStyle") {
|
|
43636
|
-
Object.entries(n.attrs).forEach(([styleKey, value2]) => {
|
|
43637
|
-
const parsedKey = kebabCase$1(styleKey);
|
|
43638
|
-
if (!value2) return;
|
|
43639
|
-
flattenedMarks.push({ key: parsedKey, value: value2 });
|
|
43640
|
-
});
|
|
43641
|
-
return;
|
|
43642
|
-
}
|
|
43643
|
-
flattenedMarks.push({ key: n.type.name, value: n.attrs[key] });
|
|
43644
|
-
});
|
|
43645
|
-
const mark = flattenedMarks.find((n) => n.key === key);
|
|
43646
|
-
const hasParentIndent = Object.keys(parent?.attrs?.indent || {});
|
|
43647
|
-
const hasParentSpacing = Object.keys(parent?.attrs?.spacing || {});
|
|
43648
|
-
if (!mark) {
|
|
43649
|
-
if (key === "spacing" && includeSpacing && !hasParentSpacing) {
|
|
43650
|
-
const space = getSpacingStyle(value);
|
|
43651
|
-
Object.entries(space).forEach(([k2, v]) => {
|
|
43652
|
-
markValue[k2] = v;
|
|
43653
|
-
});
|
|
43654
|
-
} else if (key === "indent" && includeSpacing && !hasParentIndent) {
|
|
43655
|
-
const { leftIndent, rightIndent, firstLine } = value;
|
|
43656
|
-
if (leftIndent) markValue["margin-left"] = leftIndent + "px";
|
|
43657
|
-
if (rightIndent) markValue["margin-right"] = rightIndent + "px";
|
|
43658
|
-
if (firstLine) markValue["text-indent"] = firstLine + "px";
|
|
43659
|
-
} else if (key === "bold") {
|
|
43660
|
-
markValue["font-weight"] = "bold";
|
|
43661
|
-
} else {
|
|
43662
|
-
markValue[key] = value;
|
|
43663
|
-
}
|
|
43664
|
-
}
|
|
43665
|
-
});
|
|
43666
|
-
return Object.entries(markValue).map(([key, value]) => `${key}: ${value}`).join(";");
|
|
43667
|
-
};
|
|
43668
|
-
const getLinkedStyle = (styleId, styles = []) => {
|
|
43669
|
-
return styles.find((style2) => style2.id === styleId);
|
|
43670
|
-
};
|
|
43671
|
-
const getSpacingStyle = (spacing) => {
|
|
43672
|
-
const { lineSpaceBefore, lineSpaceAfter, line, lineRule } = spacing;
|
|
43673
|
-
return {
|
|
43674
|
-
"margin-top": lineSpaceBefore + "px",
|
|
43675
|
-
"margin-bottom": lineSpaceAfter + "px",
|
|
43676
|
-
...getLineHeightValueString(line, "", lineRule, true)
|
|
43677
|
-
};
|
|
43678
|
-
};
|
|
43679
|
-
const getSpacingStyleString = (spacing) => {
|
|
43680
|
-
const { lineSpaceBefore, lineSpaceAfter, line } = spacing;
|
|
43681
|
-
return `
|
|
43682
|
-
${lineSpaceBefore ? `margin-top: ${lineSpaceBefore}px;` : ""}
|
|
43683
|
-
${lineSpaceAfter ? `margin-bottom: ${lineSpaceAfter}px;` : ""}
|
|
43684
|
-
${line ? getLineHeightValueString(line, "") : ""}
|
|
43685
|
-
`.trim();
|
|
43686
|
-
};
|
|
43687
|
-
const getMarksStyle = (attrs) => {
|
|
43688
|
-
let styles = "";
|
|
43689
|
-
for (const attr of attrs) {
|
|
43690
|
-
switch (attr.type) {
|
|
43691
|
-
case "bold":
|
|
43692
|
-
styles += `font-weight: bold; `;
|
|
43693
|
-
break;
|
|
43694
|
-
case "italic":
|
|
43695
|
-
styles += `font-style: italic; `;
|
|
43696
|
-
break;
|
|
43697
|
-
case "underline":
|
|
43698
|
-
styles += `text-decoration: underline; `;
|
|
43699
|
-
break;
|
|
43700
|
-
case "highlight":
|
|
43701
|
-
styles += `background-color: ${attr.attrs.color}; `;
|
|
43702
|
-
break;
|
|
43703
|
-
case "textStyle":
|
|
43704
|
-
const { fontFamily: fontFamily2, fontSize: fontSize2 } = attr.attrs;
|
|
43705
|
-
styles += `${fontFamily2 ? `font-family: ${fontFamily2};` : ""} ${fontSize2 ? `font-size: ${fontSize2};` : ""}`;
|
|
43706
|
-
}
|
|
43707
|
-
}
|
|
43708
|
-
return styles.trim();
|
|
43709
|
-
};
|
|
43710
|
-
const getQuickFormatList = (editor) => {
|
|
43711
|
-
if (!editor?.converter) return [];
|
|
43712
|
-
const styles = editor.converter.linkedStyles || [];
|
|
43713
|
-
return styles.filter((style2) => {
|
|
43714
|
-
return style2.type === "paragraph" && style2.definition.attrs;
|
|
43715
|
-
}).sort((a, b) => {
|
|
43716
|
-
return a.definition.attrs?.name.localeCompare(b.definition.attrs?.name);
|
|
43717
|
-
});
|
|
43718
|
-
};
|
|
43719
43720
|
const getDefaultSpacing = () => ({
|
|
43720
43721
|
lineSpaceAfter: 0,
|
|
43721
43722
|
lineSpaceBefore: 0,
|
|
@@ -43768,9 +43769,13 @@ const Paragraph = Node$1.create({
|
|
|
43768
43769
|
}
|
|
43769
43770
|
},
|
|
43770
43771
|
indent: {
|
|
43772
|
+
default: null,
|
|
43771
43773
|
renderDOM: ({ indent }) => {
|
|
43772
43774
|
if (!indent) return {};
|
|
43773
43775
|
const { left: left2, right: right2, firstLine, hanging } = indent;
|
|
43776
|
+
if (indent && Object.values(indent).every((v) => v === 0)) {
|
|
43777
|
+
return {};
|
|
43778
|
+
}
|
|
43774
43779
|
let style2 = "";
|
|
43775
43780
|
if (left2) style2 += `margin-left: ${left2}px;`;
|
|
43776
43781
|
if (right2) style2 += `margin-right: ${right2}px;`;
|
|
@@ -44117,8 +44122,8 @@ const getTabDecorations = (state2, view) => {
|
|
|
44117
44122
|
const prevNodeSize = $pos.nodeBefore?.nodeSize || 0;
|
|
44118
44123
|
let textWidth = 0;
|
|
44119
44124
|
try {
|
|
44120
|
-
state2.doc.nodesBetween(pos - prevNodeSize - 1, pos - 1, (
|
|
44121
|
-
if (
|
|
44125
|
+
state2.doc.nodesBetween(pos - prevNodeSize - 1, pos - 1, (node3, nodePos) => {
|
|
44126
|
+
if (node3.isText && node3.textContent !== " ") {
|
|
44122
44127
|
const textWidthForNode = calcTextWidth(view, nodePos);
|
|
44123
44128
|
textWidth += textWidthForNode;
|
|
44124
44129
|
}
|
|
@@ -47386,8 +47391,8 @@ function findFirstFieldAnnotationByFieldId(fieldId, state2) {
|
|
|
47386
47391
|
}
|
|
47387
47392
|
function findNode(node2, predicate) {
|
|
47388
47393
|
let found2 = null;
|
|
47389
|
-
node2.descendants((
|
|
47390
|
-
if (predicate(
|
|
47394
|
+
node2.descendants((node3, pos) => {
|
|
47395
|
+
if (predicate(node3)) found2 = { node: node3, pos };
|
|
47391
47396
|
if (found2) return false;
|
|
47392
47397
|
});
|
|
47393
47398
|
return found2;
|
|
@@ -52698,12 +52703,17 @@ const getHeaderFooterId = (currentPageNumber, sectionType, editor, node2 = null)
|
|
|
52698
52703
|
}
|
|
52699
52704
|
}
|
|
52700
52705
|
}
|
|
52701
|
-
|
|
52706
|
+
const { titlePg } = editor.converter.headerIds;
|
|
52707
|
+
if (sectionType === "headerIds" && titlePg && !sectionIds.first && currentPageNumber === 1) {
|
|
52708
|
+
return null;
|
|
52709
|
+
}
|
|
52702
52710
|
const even = sectionIds.even;
|
|
52703
52711
|
const odd = sectionIds.odd;
|
|
52704
52712
|
const first2 = sectionIds.first;
|
|
52705
52713
|
const defaultHeader = sectionIds.default;
|
|
52706
|
-
if (
|
|
52714
|
+
if (titlePg && sectionIds.first && currentPageNumber === 1) {
|
|
52715
|
+
return first2;
|
|
52716
|
+
}
|
|
52707
52717
|
let sectionId = sectionIds.default;
|
|
52708
52718
|
if (currentPageNumber === 1) sectionId = defaultHeader;
|
|
52709
52719
|
if (alternateHeaders) {
|
|
@@ -52806,7 +52816,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
|
|
|
52806
52816
|
}
|
|
52807
52817
|
if (isHardBreakNode || shouldAddPageBreak) {
|
|
52808
52818
|
const $currentPos = view.state.doc.resolve(currentPos);
|
|
52809
|
-
const tableRow = findParentNodeClosestToPos($currentPos, (
|
|
52819
|
+
const tableRow = findParentNodeClosestToPos($currentPos, (node3) => node3.type.name === "tableRow");
|
|
52810
52820
|
if (tableRow) {
|
|
52811
52821
|
currentNode = tableRow.node;
|
|
52812
52822
|
currentPos = tableRow.pos;
|
|
@@ -59002,13 +59012,13 @@ const commonVariables$2 = {
|
|
|
59002
59012
|
heightHuge: "46px"
|
|
59003
59013
|
};
|
|
59004
59014
|
const {
|
|
59005
|
-
fontSize
|
|
59015
|
+
fontSize,
|
|
59006
59016
|
fontFamily,
|
|
59007
59017
|
lineHeight
|
|
59008
59018
|
} = commonVariables$2;
|
|
59009
59019
|
const globalStyle = c$1("body", `
|
|
59010
59020
|
margin: 0;
|
|
59011
|
-
font-size: ${fontSize
|
|
59021
|
+
font-size: ${fontSize};
|
|
59012
59022
|
font-family: ${fontFamily};
|
|
59013
59023
|
line-height: ${lineHeight};
|
|
59014
59024
|
-webkit-text-size-adjust: 100%;
|