@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
|
@@ -17322,16 +17322,6 @@ const carbonCopy = (obj) => {
|
|
|
17322
17322
|
return void 0;
|
|
17323
17323
|
}
|
|
17324
17324
|
};
|
|
17325
|
-
const baseOrderedListDef$1 = {
|
|
17326
|
-
"attributes": {
|
|
17327
|
-
"w:abstractNumId": "1"
|
|
17328
|
-
}
|
|
17329
|
-
};
|
|
17330
|
-
const baseBulletList$1 = {
|
|
17331
|
-
"attributes": {
|
|
17332
|
-
"w:abstractNumId": "0"
|
|
17333
|
-
}
|
|
17334
|
-
};
|
|
17335
17325
|
const baseNumbering = {
|
|
17336
17326
|
"declaration": {
|
|
17337
17327
|
"attributes": {
|
|
@@ -18950,7 +18940,7 @@ function generateParagraphProperties(node2) {
|
|
|
18950
18940
|
};
|
|
18951
18941
|
pPrElements.push(spacingElement);
|
|
18952
18942
|
}
|
|
18953
|
-
if (indent) {
|
|
18943
|
+
if (indent && Object.values(indent).some((v) => v !== 0)) {
|
|
18954
18944
|
const { left: left2, right: right2, firstLine, hanging } = indent;
|
|
18955
18945
|
const attributes = {};
|
|
18956
18946
|
if (left2 || left2 === 0) attributes["w:left"] = pixelsToTwips(left2);
|
|
@@ -18965,7 +18955,7 @@ function generateParagraphProperties(node2) {
|
|
|
18965
18955
|
attributes
|
|
18966
18956
|
};
|
|
18967
18957
|
pPrElements.push(indentElement);
|
|
18968
|
-
} else if (textIndent) {
|
|
18958
|
+
} else if (textIndent && textIndent !== "0in") {
|
|
18969
18959
|
const indentElement = {
|
|
18970
18960
|
name: "w:ind",
|
|
18971
18961
|
attributes: {
|
|
@@ -19014,6 +19004,9 @@ function generateParagraphProperties(node2) {
|
|
|
19014
19004
|
if (sectPr) {
|
|
19015
19005
|
pPrElements.push(sectPr);
|
|
19016
19006
|
}
|
|
19007
|
+
const numPr = node2.attrs?.paragraphProperties?.elements?.find((n) => n.name === "w:numPr");
|
|
19008
|
+
const hasNumPr = pPrElements.some((n) => n.name === "w:numPr");
|
|
19009
|
+
if (numPr && !hasNumPr) pPrElements.push(numPr);
|
|
19017
19010
|
if (!pPrElements.length) return null;
|
|
19018
19011
|
return {
|
|
19019
19012
|
name: "w:pPr",
|
|
@@ -19262,157 +19255,68 @@ function addNewImageRelationship(params2, imagePath) {
|
|
|
19262
19255
|
return newId;
|
|
19263
19256
|
}
|
|
19264
19257
|
function translateList(params2) {
|
|
19265
|
-
const {
|
|
19266
|
-
const
|
|
19267
|
-
|
|
19268
|
-
|
|
19269
|
-
|
|
19270
|
-
|
|
19271
|
-
|
|
19272
|
-
|
|
19273
|
-
|
|
19274
|
-
|
|
19275
|
-
|
|
19276
|
-
|
|
19277
|
-
|
|
19278
|
-
|
|
19279
|
-
|
|
19280
|
-
|
|
19281
|
-
|
|
19282
|
-
|
|
19283
|
-
|
|
19284
|
-
|
|
19285
|
-
|
|
19286
|
-
|
|
19287
|
-
|
|
19288
|
-
|
|
19289
|
-
|
|
19290
|
-
|
|
19291
|
-
|
|
19292
|
-
|
|
19293
|
-
|
|
19294
|
-
|
|
19295
|
-
|
|
19296
|
-
|
|
19297
|
-
|
|
19298
|
-
|
|
19299
|
-
|
|
19300
|
-
|
|
19301
|
-
|
|
19302
|
-
|
|
19303
|
-
|
|
19304
|
-
|
|
19305
|
-
if (el.name === "w:sdt") {
|
|
19306
|
-
const contentIndex = el.elements.findIndex((e) => e.name === "w:sdtContent");
|
|
19307
|
-
const content3 = el.elements[contentIndex];
|
|
19308
|
-
const innerContent = content3.elements[0];
|
|
19309
|
-
if (innerContent.name === "w:p") {
|
|
19310
|
-
content3.elements = innerContent.elements;
|
|
19311
|
-
}
|
|
19312
|
-
return {
|
|
19313
|
-
name: "w:r",
|
|
19314
|
-
type: "element",
|
|
19315
|
-
elements: [el]
|
|
19316
|
-
};
|
|
19317
|
-
} else {
|
|
19318
|
-
return el;
|
|
19319
|
-
}
|
|
19320
|
-
});
|
|
19321
|
-
const { attributes: generalAttributes } = attrs;
|
|
19322
|
-
const { originalInlineRunProps } = generalAttributes || {};
|
|
19323
|
-
if (originalInlineRunProps) pPr.elements.push(originalInlineRunProps);
|
|
19324
|
-
if (propsElementIndex === -1) {
|
|
19325
|
-
outputNode.elements.unshift(carbonCopy(pPr));
|
|
19326
|
-
} else {
|
|
19327
|
-
const resultProps = carbonCopy(pPr).elements.map((item) => {
|
|
19328
|
-
const isChanged = outputNode.elements[propsElementIndex].elements.find((e) => e.name === item.name);
|
|
19329
|
-
return isChanged ? isChanged : item;
|
|
19330
|
-
});
|
|
19331
|
-
outputNode.elements[propsElementIndex].elements = resultProps;
|
|
19332
|
-
}
|
|
19333
|
-
let importedFontSize;
|
|
19334
|
-
if (listNode.attrs?.importedFontSize) {
|
|
19335
|
-
const fontNoUnit = parseInt(listNode.attrs.importedFontSize.split("pt")[0]);
|
|
19336
|
-
importedFontSize = {
|
|
19337
|
-
name: "w:sz",
|
|
19338
|
-
attributes: { "w:val": fontNoUnit * 2 }
|
|
19339
|
-
};
|
|
19340
|
-
}
|
|
19341
|
-
let importedFontFamily;
|
|
19342
|
-
if (listNode.attrs?.importedFontFamily) {
|
|
19343
|
-
importedFontFamily = {
|
|
19344
|
-
name: "w:rFonts",
|
|
19345
|
-
attributes: { "w:ascii": listNode.attrs?.importedFontFamily, "w:hAnsi": listNode.attrs?.importedFontFamily }
|
|
19346
|
-
};
|
|
19347
|
-
}
|
|
19348
|
-
const rPrElement = outputNode.elements.find((e) => e.name === "w:rPr");
|
|
19349
|
-
if (rPrElement) {
|
|
19350
|
-
rPrElement.elements.push(fontSize);
|
|
19351
|
-
} else if (importedFontSize || importedFontFamily) {
|
|
19352
|
-
const elements = [];
|
|
19353
|
-
if (importedFontSize) elements.push(importedFontSize);
|
|
19354
|
-
if (importedFontFamily) elements.push(importedFontFamily);
|
|
19355
|
-
outputNode.elements.unshift({ name: "w:rPr", elements });
|
|
19356
|
-
}
|
|
19357
|
-
if (index2 !== 0) {
|
|
19358
|
-
const currentpPr = outputNode.elements.find((e) => e.name === "w:pPr");
|
|
19359
|
-
const numPrIndex = currentpPr.elements.findIndex((e) => e.name === "w:numPr");
|
|
19360
|
-
if (numPrIndex !== -1) currentpPr.elements.splice(numPrIndex, 1);
|
|
19361
|
-
}
|
|
19362
|
-
listNodes.push(outputNode);
|
|
19363
|
-
});
|
|
19364
|
-
});
|
|
19365
|
-
return listNodes;
|
|
19366
|
-
}
|
|
19367
|
-
function generateNewListDefinition$1(params2, listType) {
|
|
19368
|
-
const nextNumbering = getLargestListDefinitionIndex(params2.converter?.numbering?.definitions);
|
|
19369
|
-
const definition = listType === "bullet" ? baseBulletList$1 : baseOrderedListDef$1;
|
|
19370
|
-
const listId = nextNumbering;
|
|
19371
|
-
const abstractId = definition.attributes["w:abstractNumId"];
|
|
19372
|
-
const newNumDef = {
|
|
19258
|
+
const { node: node2 } = params2;
|
|
19259
|
+
const { attrs = {} } = node2;
|
|
19260
|
+
if (node2.content.length > 1) {
|
|
19261
|
+
flattenContent(params2);
|
|
19262
|
+
throw new Error("Multi list not supported yet");
|
|
19263
|
+
}
|
|
19264
|
+
const listItem = node2.content[0];
|
|
19265
|
+
const { numId, level } = listItem.attrs;
|
|
19266
|
+
let numPrTag;
|
|
19267
|
+
if (numId) {
|
|
19268
|
+
numPrTag = generateNumPrTag(numId, level);
|
|
19269
|
+
}
|
|
19270
|
+
const paragraphNode = node2.content[0]?.content[0];
|
|
19271
|
+
const outputNode = exportSchemaToJson({ ...params2, node: paragraphNode });
|
|
19272
|
+
const pPr = outputNode.elements.find((n) => n.name === "w:pPr");
|
|
19273
|
+
if (pPr && pPr.elements) pPr.elements.unshift(numPrTag);
|
|
19274
|
+
const indentTag = restoreIndent(listItem.attrs.indent);
|
|
19275
|
+
indentTag && pPr?.elements?.push(indentTag);
|
|
19276
|
+
const runNode = outputNode.elements?.find((n) => n.name === "w:r");
|
|
19277
|
+
const rPr = runNode?.elements?.find((n) => n.name === "w:rPr");
|
|
19278
|
+
if (rPr) pPr.elements.push(rPr);
|
|
19279
|
+
if (listItem.attrs.numPrType !== "inline") {
|
|
19280
|
+
const numPrIndex = pPr?.elements?.findIndex((e) => e.name === "w:numPr");
|
|
19281
|
+
if (numPrIndex !== -1) {
|
|
19282
|
+
pPr?.elements?.splice(numPrIndex, 1);
|
|
19283
|
+
}
|
|
19284
|
+
}
|
|
19285
|
+
return [outputNode];
|
|
19286
|
+
}
|
|
19287
|
+
const restoreIndent = (indent) => {
|
|
19288
|
+
const attributes = {};
|
|
19289
|
+
if (!indent) indent = {};
|
|
19290
|
+
if (indent.left || indent.left === 0) attributes["w:left"] = pixelsToTwips(indent.left);
|
|
19291
|
+
if (indent.right || indent.right === 0) attributes["w:right"] = pixelsToTwips(indent.right);
|
|
19292
|
+
if (indent.firstLine || indent.firstLine === 0) attributes["w:firstLine"] = pixelsToTwips(indent.firstLine);
|
|
19293
|
+
if (indent.hanging || indent.hanging === 0) attributes["w:hanging"] = pixelsToTwips(indent.hanging);
|
|
19294
|
+
if (indent.leftChars || indent.leftChars === 0) attributes["w:leftChars"] = pixelsToTwips(indent.leftChars);
|
|
19295
|
+
if (!Object.keys(attributes).length) return;
|
|
19296
|
+
return {
|
|
19297
|
+
name: "w:ind",
|
|
19373
19298
|
type: "element",
|
|
19374
|
-
|
|
19375
|
-
attributes: {
|
|
19376
|
-
"w:numId": String(listId),
|
|
19377
|
-
"w16cid:durableId": "485517411"
|
|
19378
|
-
},
|
|
19379
|
-
elements: [
|
|
19380
|
-
{ name: "w:abstractNumId", attributes: { "w:val": String(abstractId) } }
|
|
19381
|
-
]
|
|
19299
|
+
attributes
|
|
19382
19300
|
};
|
|
19383
|
-
params2.converter.numbering.definitions[listId] = newNumDef;
|
|
19384
|
-
return listId;
|
|
19385
|
-
}
|
|
19386
|
-
const getLargestListDefinitionIndex = (definitions) => {
|
|
19387
|
-
if (!definitions || !Object.keys(definitions).length) return 0;
|
|
19388
|
-
const maxKey = Math.max(...Object.keys(definitions).map((key) => parseInt(key, 10)));
|
|
19389
|
-
return maxKey + 1;
|
|
19390
19301
|
};
|
|
19391
|
-
|
|
19302
|
+
const generateNumPrTag = (numId, level) => {
|
|
19392
19303
|
return {
|
|
19393
|
-
name: "w:
|
|
19304
|
+
name: "w:numPr",
|
|
19394
19305
|
type: "element",
|
|
19395
19306
|
elements: [
|
|
19396
19307
|
{
|
|
19397
|
-
name: "w:
|
|
19308
|
+
name: "w:numId",
|
|
19398
19309
|
type: "element",
|
|
19399
|
-
|
|
19400
|
-
{
|
|
19401
|
-
name: "w:ilvl",
|
|
19402
|
-
type: "element",
|
|
19403
|
-
attributes: { "w:val": level }
|
|
19404
|
-
},
|
|
19405
|
-
{
|
|
19406
|
-
name: "w:numId",
|
|
19407
|
-
type: "element",
|
|
19408
|
-
attributes: { "w:val": numId }
|
|
19409
|
-
}
|
|
19410
|
-
]
|
|
19310
|
+
attributes: { "w:val": numId }
|
|
19411
19311
|
},
|
|
19412
|
-
|
|
19312
|
+
{
|
|
19313
|
+
name: "w:ilvl",
|
|
19314
|
+
type: "element",
|
|
19315
|
+
attributes: { "w:val": level }
|
|
19316
|
+
}
|
|
19413
19317
|
]
|
|
19414
19318
|
};
|
|
19415
|
-
}
|
|
19319
|
+
};
|
|
19416
19320
|
function flattenContent({ node: node2 }) {
|
|
19417
19321
|
const { content, attrs = {} } = node2;
|
|
19418
19322
|
const { listId, syncId } = node2.attrs || {};
|
|
@@ -19483,10 +19387,7 @@ function preProcessVerticalMergeCells(table, { editorSchema }) {
|
|
|
19483
19387
|
if (!row.content) continue;
|
|
19484
19388
|
for (let cellIndex = 0; cellIndex < row.content?.length; cellIndex++) {
|
|
19485
19389
|
const cell = row.content[cellIndex];
|
|
19486
|
-
if (!cell)
|
|
19487
|
-
console.log("no cell");
|
|
19488
|
-
continue;
|
|
19489
|
-
}
|
|
19390
|
+
if (!cell) continue;
|
|
19490
19391
|
const { attrs } = cell;
|
|
19491
19392
|
if (attrs.rowspan > 1) {
|
|
19492
19393
|
const rowsToChange = content.slice(rowIndex + 1, rowIndex + attrs.rowspan);
|
|
@@ -21215,11 +21116,6 @@ function getElementName(element) {
|
|
|
21215
21116
|
const isPropertiesElement = (element) => {
|
|
21216
21117
|
return !!SuperConverter.propertyTypes[element.name || element.type];
|
|
21217
21118
|
};
|
|
21218
|
-
function hasTextNode(elements) {
|
|
21219
|
-
const runs = elements.filter((el) => el.name === "w:r");
|
|
21220
|
-
const runsHaveText = runs.some((run2) => run2.elements.some((el) => el.name === "w:t"));
|
|
21221
|
-
return runsHaveText;
|
|
21222
|
-
}
|
|
21223
21119
|
const handleTrackChangeNode = (params2) => {
|
|
21224
21120
|
const { nodes, nodeListHandler: nodeListHandler2 } = params2;
|
|
21225
21121
|
if (nodes.length === 0 || !(nodes[0].name === "w:del" || nodes[0].name === "w:ins" || nodes[0].name === "w:sdt")) {
|
|
@@ -21421,219 +21317,118 @@ const areAttrsEqual = (attrsA = {}, attrsB = {}) => {
|
|
|
21421
21317
|
};
|
|
21422
21318
|
const handleListNode = (params2) => {
|
|
21423
21319
|
const { nodes, lists, docx } = params2;
|
|
21424
|
-
if (nodes.length === 0 || nodes[0].name !== "w:p") {
|
|
21320
|
+
if (nodes.length === 0 || nodes[0].name !== "w:p" || nodes[0].isList) {
|
|
21425
21321
|
return { nodes: [], consumed: 0 };
|
|
21426
21322
|
}
|
|
21427
21323
|
const node2 = carbonCopy(nodes[0]);
|
|
21428
|
-
const
|
|
21429
|
-
|
|
21430
|
-
|
|
21431
|
-
|
|
21432
|
-
const siblings = carbonCopy(nodes);
|
|
21433
|
-
const listItems = [];
|
|
21434
|
-
let possibleList = siblings.shift();
|
|
21435
|
-
while (possibleList && testForList(possibleList, docx)) {
|
|
21436
|
-
listItems.push(possibleList);
|
|
21437
|
-
possibleList = siblings.shift();
|
|
21438
|
-
if (possibleList?.elements && !hasTextNode(possibleList.elements)) {
|
|
21439
|
-
listItems.push(possibleList);
|
|
21440
|
-
possibleList = siblings.shift();
|
|
21441
|
-
}
|
|
21442
|
-
}
|
|
21443
|
-
const listNodes = handleListNodes({ listItems, params: params2, originalPpr });
|
|
21324
|
+
const isList2 = testForList(node2, docx);
|
|
21325
|
+
if (isList2) {
|
|
21326
|
+
node2.isList = true;
|
|
21327
|
+
const result = handleListNodes(params2, node2);
|
|
21444
21328
|
return {
|
|
21445
|
-
nodes: [
|
|
21446
|
-
consumed:
|
|
21447
|
-
lists
|
|
21329
|
+
nodes: [result],
|
|
21330
|
+
consumed: 1
|
|
21448
21331
|
};
|
|
21449
21332
|
} else {
|
|
21450
|
-
return { nodes: [], consumed: 0
|
|
21333
|
+
return { nodes: [], consumed: 0 };
|
|
21451
21334
|
}
|
|
21452
21335
|
};
|
|
21453
21336
|
const listHandlerEntity = {
|
|
21454
21337
|
handlerName: "listHandler",
|
|
21455
21338
|
handler: handleListNode
|
|
21456
21339
|
};
|
|
21457
|
-
function handleListNodes({
|
|
21458
|
-
listItems,
|
|
21459
|
-
originalPpr,
|
|
21460
|
-
params: params2,
|
|
21461
|
-
listLevel = 0,
|
|
21462
|
-
actualListLevel = 0,
|
|
21463
|
-
currentListNumId = null,
|
|
21464
|
-
path = "",
|
|
21465
|
-
isNested = false
|
|
21466
|
-
}) {
|
|
21340
|
+
function handleListNodes(params2, node2) {
|
|
21467
21341
|
const { docx, nodeListHandler: nodeListHandler2, lists } = params2;
|
|
21468
|
-
const
|
|
21469
|
-
let overallListType;
|
|
21470
|
-
let listStyleType;
|
|
21471
|
-
const handleStandardNode2 = nodeListHandler2.handlerEntities.find(
|
|
21472
|
-
(e) => e.handlerName === "standardNodeHandler"
|
|
21473
|
-
)?.handler;
|
|
21474
|
-
if (!handleStandardNode2) {
|
|
21475
|
-
console.error("Standard node handler not found");
|
|
21476
|
-
return { nodes: [], consumed: 0 };
|
|
21477
|
-
}
|
|
21478
|
-
const initialpPr = listItems[0].elements.find((el) => el.name === "w:pPr");
|
|
21342
|
+
const initialpPr = node2.elements.find((el) => el.name === "w:pPr");
|
|
21479
21343
|
const styleTag = initialpPr?.elements?.find((el) => el.name === "w:pStyle");
|
|
21480
21344
|
const styleId = styleTag?.attributes["w:val"];
|
|
21481
|
-
const numPrTag = getNumPrRecursive({ node:
|
|
21482
|
-
currentListNumId = getNumIdFromTag(numPrTag);
|
|
21483
|
-
|
|
21484
|
-
|
|
21485
|
-
|
|
21486
|
-
|
|
21487
|
-
|
|
21488
|
-
|
|
21489
|
-
|
|
21490
|
-
|
|
21491
|
-
|
|
21492
|
-
|
|
21493
|
-
|
|
21494
|
-
|
|
21495
|
-
|
|
21496
|
-
|
|
21497
|
-
|
|
21498
|
-
|
|
21499
|
-
|
|
21500
|
-
|
|
21501
|
-
|
|
21502
|
-
|
|
21503
|
-
|
|
21504
|
-
|
|
21505
|
-
const
|
|
21506
|
-
|
|
21507
|
-
|
|
21508
|
-
|
|
21509
|
-
|
|
21510
|
-
|
|
21511
|
-
|
|
21512
|
-
|
|
21513
|
-
|
|
21514
|
-
|
|
21515
|
-
|
|
21516
|
-
|
|
21517
|
-
|
|
21518
|
-
|
|
21519
|
-
|
|
21520
|
-
|
|
21521
|
-
|
|
21522
|
-
|
|
21523
|
-
|
|
21524
|
-
const schemaElements = [];
|
|
21525
|
-
const nodeContents = nodeListHandler2.handler({ ...params2, nodes: [attributes.paragraphProperties, ...elements] })?.filter((n) => n) || [];
|
|
21526
|
-
let parNode = {
|
|
21527
|
-
type: "paragraph",
|
|
21528
|
-
content: nodeContents
|
|
21529
|
-
};
|
|
21530
|
-
if (parNode.content) {
|
|
21531
|
-
parNode = {
|
|
21532
|
-
...parNode,
|
|
21533
|
-
attrs: {
|
|
21534
|
-
textAlign: textStyle?.attrs.textAlign || textStyleFromStyles?.attrs.textAlign || null,
|
|
21535
|
-
rsidRDefault: attributes?.["w:rsidRDefault"] || null,
|
|
21536
|
-
styleId
|
|
21537
|
-
},
|
|
21538
|
-
content: mergeTextNodes(parNode.content)
|
|
21539
|
-
};
|
|
21540
|
-
}
|
|
21541
|
-
schemaElements.push(parNode);
|
|
21542
|
-
lastNestedListLevel = listLevel;
|
|
21543
|
-
let thisItemPath = [];
|
|
21544
|
-
if (listStyleType !== "bullet") {
|
|
21545
|
-
thisItemPath = [...path, lists[currentListNumId][listLevel]];
|
|
21546
|
-
lists[currentListNumId][actualListLevel]++;
|
|
21547
|
-
}
|
|
21548
|
-
if (!path.length && actualListLevel > 0) {
|
|
21549
|
-
const currentDef = lists[currentListNumId];
|
|
21550
|
-
if (currentDef) {
|
|
21551
|
-
const newPath = [];
|
|
21552
|
-
Object.keys(currentDef).forEach((key) => {
|
|
21553
|
-
newPath.push(currentDef[key]);
|
|
21554
|
-
});
|
|
21555
|
-
thisItemPath = newPath;
|
|
21556
|
-
}
|
|
21557
|
-
}
|
|
21558
|
-
const pPr = item.elements.find((el) => el.name === "w:pPr");
|
|
21559
|
-
let indent = pPr?.elements.find((el) => el.name === "w:ind");
|
|
21560
|
-
const pPrFromStyles = matchedStyle?.elements?.find((style2) => style2.name === "w:pPr");
|
|
21561
|
-
const stylesIndent = pPrFromStyles?.elements?.find((el) => el.name === "w:ind");
|
|
21562
|
-
if (!indent) indent = stylesIndent;
|
|
21563
|
-
if (indent) {
|
|
21564
|
-
const indentAttrs = {};
|
|
21565
|
-
if (!indent.attributes) indent.attributes = {};
|
|
21566
|
-
if (indent.attributes["w:left"] !== void 0) indentAttrs.left = twipsToPixels(indent.attributes["w:left"]);
|
|
21567
|
-
if (indent.attributes["w:right"] !== void 0) indentAttrs.right = twipsToPixels(indent.attributes["w:right"]);
|
|
21568
|
-
if (indent.attributes["w:firstLine"] !== void 0) indentAttrs.firstLine = twipsToPixels(indent.attributes["w:firstLine"]);
|
|
21569
|
-
if (indent.attributes["w:hanging"] !== void 0) indentAttrs.hanging = twipsToPixels(indent.attributes["w:hanging"]);
|
|
21570
|
-
nodeAttributes["indent"] = indentAttrs;
|
|
21571
|
-
}
|
|
21572
|
-
if (listpPrs) nodeAttributes["listParagraphProperties"] = listpPrs;
|
|
21573
|
-
if (listrPrs) nodeAttributes["listRunProperties"] = listrPrs;
|
|
21574
|
-
nodeAttributes["textStyle"] = textStyle;
|
|
21575
|
-
nodeAttributes["order"] = start2;
|
|
21576
|
-
nodeAttributes["lvlText"] = lvlText;
|
|
21577
|
-
nodeAttributes["lvlJc"] = textStyle?.attrs.textAlign;
|
|
21578
|
-
nodeAttributes["listLevel"] = thisItemPath;
|
|
21579
|
-
nodeAttributes["listNumberingType"] = listOrderingType;
|
|
21580
|
-
nodeAttributes["attributes"] = {
|
|
21581
|
-
parentAttributes: item?.attributes || null
|
|
21582
|
-
};
|
|
21583
|
-
const originalRunProps = originalPpr?.elements?.find((el) => el.name === "w:rPr");
|
|
21584
|
-
if (originalRunProps) {
|
|
21585
|
-
nodeAttributes.attributes["originalInlineRunProps"] = originalRunProps;
|
|
21586
|
-
}
|
|
21587
|
-
nodeAttributes["numId"] = numId;
|
|
21588
|
-
if (docx) {
|
|
21589
|
-
nodeAttributes["spacing"] = getParagraphSpacing(item, docx, styleId);
|
|
21590
|
-
}
|
|
21591
|
-
const newListItem = createListItem(schemaElements, nodeAttributes, []);
|
|
21592
|
-
parsedListItems.push(newListItem);
|
|
21593
|
-
} else if (isNested2) {
|
|
21594
|
-
const newPath = [...path, lists[currentListNumId][listLevel]];
|
|
21595
|
-
const sublist = handleListNodes({
|
|
21596
|
-
listItems: listItems.slice(index2),
|
|
21597
|
-
originalPpr,
|
|
21598
|
-
params: params2,
|
|
21599
|
-
listLevel: listLevel + 1,
|
|
21600
|
-
actualListLevel: listLevel,
|
|
21601
|
-
currentListNumId: numId,
|
|
21602
|
-
path: newPath,
|
|
21603
|
-
isNested: true
|
|
21604
|
-
});
|
|
21605
|
-
lastNestedListLevel = sublist.lastNestedListLevel;
|
|
21606
|
-
delete sublist.lastNestedListLevel;
|
|
21607
|
-
const lastItem = parsedListItems[parsedListItems.length - 1];
|
|
21608
|
-
if (!lastItem) {
|
|
21609
|
-
parsedListItems.push(createListItem([sublist], nodeAttributes, []));
|
|
21610
|
-
} else {
|
|
21611
|
-
lastItem.content.push(sublist);
|
|
21612
|
-
}
|
|
21613
|
-
} else if (!numId) {
|
|
21614
|
-
item.seen = true;
|
|
21615
|
-
const n = handleStandardNode2({ ...params2, nodes: [item] }).nodes[0];
|
|
21616
|
-
parsedListItems[parsedListItems.length - 1]?.content.push(n);
|
|
21617
|
-
} else {
|
|
21618
|
-
lastNestedListLevel = listLevel;
|
|
21619
|
-
if (listLevel > 0 && item.elements[0].elements.find((el) => el.name === "w:numPr")) {
|
|
21620
|
-
lists[currentListNumId][listLevel] = 0;
|
|
21345
|
+
const { numPr: numPrTag, type: numPrType } = getNumPrRecursive({ node: node2, styleId, docx });
|
|
21346
|
+
const currentListNumId = getNumIdFromTag(numPrTag);
|
|
21347
|
+
const iLvlTag = numPrTag?.elements?.find((el) => el.name === "w:ilvl");
|
|
21348
|
+
let iLvl = Number(iLvlTag?.attributes["w:val"]);
|
|
21349
|
+
if (!iLvl && iLvl !== 0) iLvl = getOutlineLevelFromStyleTag(styleId, docx);
|
|
21350
|
+
const {
|
|
21351
|
+
listType,
|
|
21352
|
+
listOrderingType,
|
|
21353
|
+
listrPrs,
|
|
21354
|
+
listpPrs,
|
|
21355
|
+
start: start2,
|
|
21356
|
+
lvlText,
|
|
21357
|
+
lvlJc
|
|
21358
|
+
} = getNodeNumberingDefinition(node2, iLvl, docx);
|
|
21359
|
+
if (!listType) {
|
|
21360
|
+
const pPrIndex = node2.elements.findIndex((el) => el.name === "w:pPr");
|
|
21361
|
+
const pPr = node2.elements[pPrIndex];
|
|
21362
|
+
const numPrIndex2 = pPr?.elements?.findIndex((el) => el.name === "w:numPr");
|
|
21363
|
+
if (numPrIndex2 >= 0) {
|
|
21364
|
+
pPr?.elements?.splice(numPrIndex2, 1);
|
|
21365
|
+
node2.elements[pPrIndex] = pPr;
|
|
21366
|
+
}
|
|
21367
|
+
const styleIdIndex = pPr?.elements?.findIndex((el) => el.name === "w:pStyle");
|
|
21368
|
+
if (styleIdIndex >= 0) pPr?.elements?.splice(styleIdIndex, 1);
|
|
21369
|
+
const fallBack = nodeListHandler2.handler({ ...params2, nodes: [node2] })?.filter((n) => n);
|
|
21370
|
+
return fallBack[0];
|
|
21371
|
+
}
|
|
21372
|
+
if (!lists[currentListNumId]) lists[currentListNumId] = { levels: {} };
|
|
21373
|
+
const currentListByNumId = lists[currentListNumId];
|
|
21374
|
+
if (!currentListByNumId.levels[iLvl]) currentListByNumId.levels[iLvl] = Number(start2) || 1;
|
|
21375
|
+
else currentListByNumId.levels[iLvl]++;
|
|
21376
|
+
Object.keys(currentListByNumId.levels).forEach((key) => {
|
|
21377
|
+
const level = Number(key);
|
|
21378
|
+
if (level > iLvl) {
|
|
21379
|
+
delete currentListByNumId.levels[level];
|
|
21380
|
+
}
|
|
21381
|
+
});
|
|
21382
|
+
const path = [];
|
|
21383
|
+
if (iLvl > 0) {
|
|
21384
|
+
for (let i = iLvl; i >= 0; i--) {
|
|
21385
|
+
const { start: lvlStart } = getNodeNumberingDefinition(node2, i, docx);
|
|
21386
|
+
if (!currentListByNumId.levels[i]) {
|
|
21387
|
+
currentListByNumId.levels[i] = Number(lvlStart);
|
|
21621
21388
|
}
|
|
21622
|
-
|
|
21389
|
+
path.unshift(currentListByNumId.levels[i]);
|
|
21623
21390
|
}
|
|
21624
21391
|
}
|
|
21392
|
+
if (!path.length) path.push(currentListByNumId.levels[iLvl]);
|
|
21393
|
+
const attrs = {};
|
|
21394
|
+
attrs.lvlText = lvlText;
|
|
21395
|
+
attrs.listLevel = path;
|
|
21396
|
+
attrs.listNumberingType = listOrderingType;
|
|
21397
|
+
attrs.numId = currentListNumId;
|
|
21398
|
+
attrs.level = iLvl;
|
|
21399
|
+
attrs.numPrType = numPrType;
|
|
21400
|
+
attrs.styleId = styleId;
|
|
21401
|
+
node2.isList = true;
|
|
21402
|
+
const nodePpr = node2.attrs?.paragraphProperties?.elements?.find((el) => el.name === "w:pPr");
|
|
21403
|
+
const numPrIndex = node2.attrs?.paragraphProperties?.elements?.findIndex((el) => el.name === "w:numPr");
|
|
21404
|
+
nodePpr?.elements?.splice(numPrIndex, 1);
|
|
21405
|
+
const listContents = nodeListHandler2.handler({ ...params2, nodes: [node2] });
|
|
21406
|
+
const innerParagraph = listContents.find((el) => el.type === "paragraph");
|
|
21407
|
+
const firstElement = innerParagraph.content[0];
|
|
21408
|
+
firstElement?.marks?.find((mark) => mark.type === "textStyle");
|
|
21409
|
+
attrs.indent = listpPrs?.indent;
|
|
21410
|
+
const processedContents = listContents.map((el, index2) => {
|
|
21411
|
+
const { attrs: elementAttrs } = el;
|
|
21412
|
+
const { indent, textIndent, paragraphProperties, ...rest } = elementAttrs;
|
|
21413
|
+
if (index2 === 0 && !attrs.indent) attrs.indent = indent;
|
|
21414
|
+
return {
|
|
21415
|
+
...el,
|
|
21416
|
+
attrs: rest
|
|
21417
|
+
};
|
|
21418
|
+
});
|
|
21419
|
+
const listItem = {
|
|
21420
|
+
type: "listItem",
|
|
21421
|
+
content: processedContents || [],
|
|
21422
|
+
attrs
|
|
21423
|
+
};
|
|
21625
21424
|
const resultingList = {
|
|
21626
|
-
type:
|
|
21627
|
-
content:
|
|
21425
|
+
type: listType,
|
|
21426
|
+
content: [listItem],
|
|
21628
21427
|
attrs: {
|
|
21629
|
-
"list-style-type":
|
|
21630
|
-
listId: currentListNumId
|
|
21631
|
-
attributes: {
|
|
21632
|
-
parentAttributes: listItems[0]?.attributes || null
|
|
21633
|
-
}
|
|
21428
|
+
"list-style-type": listOrderingType,
|
|
21429
|
+
listId: currentListNumId
|
|
21634
21430
|
}
|
|
21635
21431
|
};
|
|
21636
|
-
if (isNested) resultingList.lastNestedListLevel = lastNestedListLevel;
|
|
21637
21432
|
return resultingList;
|
|
21638
21433
|
}
|
|
21639
21434
|
const getOutlineLevelFromStyleTag = (styleTag, docx) => {
|
|
@@ -21652,11 +21447,27 @@ function testForList(node2, docx) {
|
|
|
21652
21447
|
const paragraphStyle = pPr.elements?.find((el) => el.name === "w:pStyle");
|
|
21653
21448
|
let numPr = pPr.elements?.find((el) => el.name === "w:numPr");
|
|
21654
21449
|
let numId = getNumIdFromTag(numPr);
|
|
21450
|
+
const ilvlTag = numPr?.elements?.find((el) => el.name === "w:ilvl");
|
|
21451
|
+
let ilvl = ilvlTag?.attributes["w:val"];
|
|
21452
|
+
let outlinelvl;
|
|
21655
21453
|
const styleId = paragraphStyle?.attributes["w:val"];
|
|
21656
|
-
|
|
21657
|
-
|
|
21454
|
+
const styleTag = getStyleTagFromStyleId(styleId, docx);
|
|
21455
|
+
if (styleTag && !numId) {
|
|
21456
|
+
const { numPr: numPrRecursve, type: type2 } = getNumPrRecursive({ node: node2, styleId, docx });
|
|
21457
|
+
numPr = numPrRecursve;
|
|
21658
21458
|
numId = getNumIdFromTag(numPr);
|
|
21659
|
-
|
|
21459
|
+
const stylePpr = styleTag?.elements?.find((el) => el.name === "w:pPr");
|
|
21460
|
+
stylePpr?.elements?.find((el) => el.name === "w:numPr");
|
|
21461
|
+
ilvl = stylePpr?.elements?.find((el) => el.name === "w:ilvl")?.attributes["w:val"];
|
|
21462
|
+
outlinelvl = stylePpr?.elements?.find((el) => el.name === "w:outlineLvl")?.attributes["w:val"];
|
|
21463
|
+
ilvl = outlinelvl || ilvl;
|
|
21464
|
+
}
|
|
21465
|
+
const numbering = docx["word/numbering.xml"] || {};
|
|
21466
|
+
const numDefinition = numbering?.elements?.[0].elements?.find((el) => el.attributes?.["w:numId"] == numId);
|
|
21467
|
+
const abstractNumId = numDefinition?.elements?.find((el) => el.name === "w:abstractNumId")?.attributes["w:val"];
|
|
21468
|
+
const abstractNumDefinition = numbering?.elements?.[0].elements?.find((el) => el.attributes?.["w:abstractNumId"] == abstractNumId);
|
|
21469
|
+
const levelDefinition = abstractNumDefinition?.elements?.find((el) => el.name === "w:lvl" && el.attributes?.["w:ilvl"] == ilvl);
|
|
21470
|
+
if (!levelDefinition) return false;
|
|
21660
21471
|
return !!numId;
|
|
21661
21472
|
}
|
|
21662
21473
|
const getNumIdFromTag = (tag) => {
|
|
@@ -21664,20 +21475,19 @@ const getNumIdFromTag = (tag) => {
|
|
|
21664
21475
|
};
|
|
21665
21476
|
function getStyleTagFromStyleId(styleId, docx) {
|
|
21666
21477
|
const styles = docx["word/styles.xml"];
|
|
21667
|
-
if (!styles) {
|
|
21668
|
-
return {};
|
|
21669
|
-
}
|
|
21478
|
+
if (!styles) return {};
|
|
21670
21479
|
const styleEls = styles.elements;
|
|
21671
21480
|
const wStyles = styleEls.find((el) => el.name === "w:styles");
|
|
21672
21481
|
const styleTags = wStyles.elements.filter((style2) => style2.name === "w:style");
|
|
21673
|
-
|
|
21482
|
+
const styleDef = styleTags.find((tag) => tag.attributes["w:styleId"] === styleId);
|
|
21483
|
+
return styleDef;
|
|
21674
21484
|
}
|
|
21675
21485
|
function getNumPrRecursive({ node: node2, styleId, docx, seenStyleIds = /* @__PURE__ */ new Set() }) {
|
|
21676
21486
|
const initialPpr = node2?.elements?.find((el) => el.name === "w:pPr");
|
|
21677
21487
|
const initialNumPr = initialPpr?.elements?.find((el) => el.name === "w:numPr");
|
|
21678
21488
|
let numPr = initialNumPr;
|
|
21679
21489
|
let numId = getNumIdFromTag(numPr);
|
|
21680
|
-
if (numId) return numPr;
|
|
21490
|
+
if (numId) return { numPr, type: "inline" };
|
|
21681
21491
|
const matchedStyle = getStyleTagFromStyleId(styleId, docx);
|
|
21682
21492
|
const pPr = matchedStyle?.elements?.find((style2) => style2.name === "w:pPr");
|
|
21683
21493
|
numPr = pPr?.elements?.find((style2) => style2.name === "w:numPr");
|
|
@@ -21686,18 +21496,10 @@ function getNumPrRecursive({ node: node2, styleId, docx, seenStyleIds = /* @__PU
|
|
|
21686
21496
|
if (!numId && !seenStyleIds.has(styleId)) {
|
|
21687
21497
|
const basedOnStyleId = basedOn?.attributes["w:val"];
|
|
21688
21498
|
seenStyleIds.add(styleId);
|
|
21689
|
-
if (!basedOnStyleId) return
|
|
21499
|
+
if (!basedOnStyleId) return {};
|
|
21690
21500
|
return getNumPrRecursive({ styleId: basedOnStyleId, docx, seenStyleIds });
|
|
21691
21501
|
}
|
|
21692
|
-
return numPr;
|
|
21693
|
-
}
|
|
21694
|
-
function createListItem(content, attrs, marks) {
|
|
21695
|
-
return {
|
|
21696
|
-
type: "listItem",
|
|
21697
|
-
content,
|
|
21698
|
-
attrs,
|
|
21699
|
-
marks
|
|
21700
|
-
};
|
|
21502
|
+
return { numPr, type: "numbering" };
|
|
21701
21503
|
}
|
|
21702
21504
|
const orderedListTypes = [
|
|
21703
21505
|
"decimal",
|
|
@@ -21735,18 +21537,6 @@ const unorderedListTypes = [
|
|
|
21735
21537
|
"disc"
|
|
21736
21538
|
// Disc bullets (●)
|
|
21737
21539
|
];
|
|
21738
|
-
const isSameListLevelDefsExceptStart = ({ firstListId, secondListId, level, pStyleId, docx }) => {
|
|
21739
|
-
const { numFmt, lvlText, lvlJc } = getListLevelDefinitionTag(firstListId, level, pStyleId, docx);
|
|
21740
|
-
const {
|
|
21741
|
-
numFmt: numFmt2,
|
|
21742
|
-
lvlText: lvlText2,
|
|
21743
|
-
lvlJc: lvlJc2
|
|
21744
|
-
} = getListLevelDefinitionTag(secondListId, level, pStyleId, docx);
|
|
21745
|
-
const sameNumFmt = numFmt === numFmt2;
|
|
21746
|
-
const sameLvlText = lvlText === lvlText2;
|
|
21747
|
-
const sameLvlJc = lvlJc === lvlJc2;
|
|
21748
|
-
return sameNumFmt && sameLvlText && sameLvlJc;
|
|
21749
|
-
};
|
|
21750
21540
|
const getListNumIdFromStyleRef = (styleId, docx) => {
|
|
21751
21541
|
const styles = docx["word/styles.xml"];
|
|
21752
21542
|
if (!styles) return null;
|
|
@@ -21778,24 +21568,28 @@ const getListNumIdFromStyleRef = (styleId, docx) => {
|
|
|
21778
21568
|
}
|
|
21779
21569
|
return { numId, ilvl };
|
|
21780
21570
|
};
|
|
21781
|
-
const
|
|
21571
|
+
const getAbstractDefinition = (numId, docx) => {
|
|
21782
21572
|
const def = docx["word/numbering.xml"];
|
|
21783
21573
|
if (!def) return {};
|
|
21784
21574
|
const { elements } = def;
|
|
21785
21575
|
const listData = elements[0];
|
|
21786
|
-
if (pStyleId) {
|
|
21787
|
-
const { numId: numIdFromStyles, ilvl: iLvlFromStyles } = getListNumIdFromStyleRef(pStyleId, docx) || {};
|
|
21788
|
-
if (!numId && numIdFromStyles) numId = numIdFromStyles;
|
|
21789
|
-
if (!level && iLvlFromStyles) level = iLvlFromStyles ? parseInt(iLvlFromStyles) : null;
|
|
21790
|
-
}
|
|
21791
21576
|
const numberingElements = listData.elements;
|
|
21792
21577
|
const abstractDefinitions = numberingElements.filter((style2) => style2.name === "w:abstractNum");
|
|
21793
21578
|
const numDefinitions = numberingElements.filter((style2) => style2.name === "w:num");
|
|
21794
|
-
const numDefinition = numDefinitions.find((style2) => style2.attributes["w:numId"]
|
|
21579
|
+
const numDefinition = numDefinitions.find((style2) => style2.attributes["w:numId"] == numId);
|
|
21795
21580
|
const abstractNumId = numDefinition?.elements[0].attributes["w:val"];
|
|
21796
21581
|
const listDefinitionForThisNumId = abstractDefinitions?.find(
|
|
21797
21582
|
(style2) => style2.attributes["w:abstractNumId"] === abstractNumId
|
|
21798
21583
|
);
|
|
21584
|
+
return listDefinitionForThisNumId;
|
|
21585
|
+
};
|
|
21586
|
+
const getListLevelDefinitionTag = (numId, level, pStyleId, docx) => {
|
|
21587
|
+
if (pStyleId) {
|
|
21588
|
+
const { numId: numIdFromStyles, ilvl: iLvlFromStyles } = getListNumIdFromStyleRef(pStyleId, docx) || {};
|
|
21589
|
+
if (!numId && numIdFromStyles) numId = numIdFromStyles;
|
|
21590
|
+
if (!level && iLvlFromStyles) level = iLvlFromStyles ? parseInt(iLvlFromStyles) : null;
|
|
21591
|
+
}
|
|
21592
|
+
const listDefinitionForThisNumId = getAbstractDefinition(numId, docx);
|
|
21799
21593
|
const currentLevel = getDefinitionForLevel(listDefinitionForThisNumId, level);
|
|
21800
21594
|
const numStyleLink = listDefinitionForThisNumId?.elements?.find((style2) => style2.name === "w:numStyleLink");
|
|
21801
21595
|
const numStyleLinkId = numStyleLink?.attributes["w:val"];
|
|
@@ -21804,7 +21598,15 @@ const getListLevelDefinitionTag = (numId, level, pStyleId, docx) => {
|
|
|
21804
21598
|
return getListLevelDefinitionTag(current.numId, level, null, docx);
|
|
21805
21599
|
}
|
|
21806
21600
|
const start2 = currentLevel?.elements?.find((style2) => style2.name === "w:start")?.attributes["w:val"];
|
|
21807
|
-
|
|
21601
|
+
let numFmt = currentLevel?.elements?.find((style2) => style2.name === "w:numFmt")?.attributes["w:val"];
|
|
21602
|
+
if (!numFmt) {
|
|
21603
|
+
const altChoice = currentLevel?.elements.find((style2) => style2.name === "mc:AlternateContent");
|
|
21604
|
+
const choice = altChoice?.elements.find((style2) => style2.name === "mc:Choice");
|
|
21605
|
+
const choiceNumFmt = choice?.elements.find((style2) => style2.name === "w:numFmt")?.attributes["w:val"];
|
|
21606
|
+
if (choiceNumFmt) {
|
|
21607
|
+
numFmt = choiceNumFmt;
|
|
21608
|
+
}
|
|
21609
|
+
}
|
|
21808
21610
|
const lvlText = currentLevel?.elements?.find((style2) => style2.name === "w:lvlText").attributes["w:val"];
|
|
21809
21611
|
const lvlJc = currentLevel?.elements?.find((style2) => style2.name === "w:lvlJc").attributes["w:val"];
|
|
21810
21612
|
const pPr = currentLevel?.elements?.find((style2) => style2.name === "w:pPr");
|
|
@@ -21819,12 +21621,10 @@ function getNodeNumberingDefinition(item, level, docx) {
|
|
|
21819
21621
|
const initialPpr = item.elements.find((el) => el.name === "w:pPr");
|
|
21820
21622
|
const styleTag = initialPpr?.elements?.find((el) => el.name === "w:pStyle");
|
|
21821
21623
|
const styleId = styleTag?.attributes["w:val"];
|
|
21822
|
-
const numPrTag = getNumPrRecursive({ node: item, styleId, docx });
|
|
21624
|
+
const { numPr: numPrTag, type: type2 } = getNumPrRecursive({ node: item, styleId, docx });
|
|
21823
21625
|
if (!numPrTag) return {};
|
|
21824
21626
|
const numIdTag = numPrTag?.elements.find((style2) => style2.name === "w:numId");
|
|
21825
21627
|
const numId = numIdTag?.attributes["w:val"];
|
|
21826
|
-
const ilvlTag = numPrTag?.elements.find((style2) => style2.name === "w:ilvl");
|
|
21827
|
-
const ilvl = ilvlTag?.attributes["w:val"] || getOutlineLevelFromStyleTag(styleId, docx);
|
|
21828
21628
|
const pStyle = listStyles.find((style2) => style2.name === "w:pStyle");
|
|
21829
21629
|
const pStyleId = pStyle?.attributes["w:val"];
|
|
21830
21630
|
const {
|
|
@@ -21836,29 +21636,84 @@ function getNodeNumberingDefinition(item, level, docx) {
|
|
|
21836
21636
|
rPr
|
|
21837
21637
|
} = getListLevelDefinitionTag(numId, level, pStyleId, docx);
|
|
21838
21638
|
let listpPrs, listrPrs;
|
|
21839
|
-
if (pPr) listpPrs = _processListParagraphProperties(pPr);
|
|
21639
|
+
if (pPr) listpPrs = _processListParagraphProperties(pPr, initialPpr);
|
|
21840
21640
|
if (rPr) listrPrs = _processListRunProperties(rPr);
|
|
21841
21641
|
let listType;
|
|
21842
21642
|
if (unorderedListTypes.includes(listTypeDef?.toLowerCase())) listType = "bulletList";
|
|
21843
21643
|
else if (orderedListTypes.includes(listTypeDef)) listType = "orderedList";
|
|
21844
|
-
else
|
|
21845
|
-
|
|
21644
|
+
else if (listTypeDef === "custom") {
|
|
21645
|
+
listType = "orderedList";
|
|
21646
|
+
} else {
|
|
21647
|
+
return {};
|
|
21648
|
+
}
|
|
21649
|
+
return { listType, listOrderingType: listTypeDef, listrPrs, listpPrs, start: start2, lvlText, lvlJc };
|
|
21846
21650
|
}
|
|
21847
21651
|
function getDefinitionForLevel(data, level) {
|
|
21848
21652
|
return data?.elements?.find((item) => Number(item.attributes["w:ilvl"]) === level);
|
|
21849
21653
|
}
|
|
21850
|
-
function
|
|
21654
|
+
function parseIndentElement(indElem) {
|
|
21655
|
+
if (!indElem || !indElem.attributes) return {};
|
|
21656
|
+
const out = {};
|
|
21657
|
+
if (indElem.attributes["w:left"] != null) out.left = twipsToPixels(indElem.attributes["w:left"]);
|
|
21658
|
+
if (indElem.attributes["w:right"] != null) out.right = twipsToPixels(indElem.attributes["w:right"]);
|
|
21659
|
+
if (indElem.attributes["w:firstLine"] != null) out.firstLine = twipsToPixels(indElem.attributes["w:firstLine"]);
|
|
21660
|
+
if (indElem.attributes["w:hanging"] != null) out.hanging = twipsToPixels(indElem.attributes["w:hanging"]);
|
|
21661
|
+
if (indElem.attributes["w:leftChars"] != null) out.leftChars = twipsToPixels(indElem.attributes["w:leftChars"]);
|
|
21662
|
+
return out;
|
|
21663
|
+
}
|
|
21664
|
+
function combineIndents(ind1, ind2) {
|
|
21665
|
+
ind1 = ind1 && typeof ind1 === "object" ? ind1 : {};
|
|
21666
|
+
ind2 = ind2 && typeof ind2 === "object" ? ind2 : {};
|
|
21667
|
+
const indent = {};
|
|
21668
|
+
["left", "right", "firstLine", "hanging"].forEach((prop) => {
|
|
21669
|
+
const v1 = ind1[prop] !== void 0 ? Number(ind1[prop]) : null;
|
|
21670
|
+
const v2 = ind2[prop] !== void 0 ? Number(ind2[prop]) : null;
|
|
21671
|
+
if (v1 != null && v2 != null) {
|
|
21672
|
+
indent[prop] = prop === "left" || prop === "hanging" ? Math.max(v1, v2) : v1;
|
|
21673
|
+
} else if (v1 != null) {
|
|
21674
|
+
indent[prop] = v1;
|
|
21675
|
+
} else if (v2 != null) {
|
|
21676
|
+
indent[prop] = v2;
|
|
21677
|
+
}
|
|
21678
|
+
});
|
|
21679
|
+
return indent;
|
|
21680
|
+
}
|
|
21681
|
+
function _processListParagraphProperties(data, inlinePpr) {
|
|
21851
21682
|
const { elements } = data;
|
|
21852
21683
|
const expectedTypes = ["w:ind", "w:jc", "w:tabs"];
|
|
21853
21684
|
const paragraphProperties = {};
|
|
21854
21685
|
if (!elements) return paragraphProperties;
|
|
21855
21686
|
elements.forEach((item) => {
|
|
21856
|
-
if (!expectedTypes.includes(item.name))
|
|
21857
|
-
|
|
21858
|
-
|
|
21859
|
-
paragraphProperties[key] = attributes[key];
|
|
21860
|
-
});
|
|
21687
|
+
if (!expectedTypes.includes(item.name)) {
|
|
21688
|
+
console.warn(`[numbering.xml] Unexpected list paragraph prop found: ${item.name}`);
|
|
21689
|
+
}
|
|
21861
21690
|
});
|
|
21691
|
+
const inlineIndent = inlinePpr?.elements?.find((item) => item.name === "w:ind");
|
|
21692
|
+
const parsedInlineIndent = parseIndentElement(inlineIndent);
|
|
21693
|
+
const styleIndent = elements.find((item) => item.name === "w:ind");
|
|
21694
|
+
parseIndentElement(styleIndent);
|
|
21695
|
+
paragraphProperties.indent = parsedInlineIndent;
|
|
21696
|
+
const justify = elements.find((item) => item.name === "w:jc");
|
|
21697
|
+
if (justify) {
|
|
21698
|
+
const justifyAttrs = {};
|
|
21699
|
+
if (!justify.attributes) justify.attributes = {};
|
|
21700
|
+
if (justify.attributes["w:val"] !== void 0) justifyAttrs.val = justify.attributes["w:val"];
|
|
21701
|
+
paragraphProperties.justify = justifyAttrs;
|
|
21702
|
+
}
|
|
21703
|
+
const tabs = elements.find((item) => item.name === "w:tabs");
|
|
21704
|
+
if (tabs) {
|
|
21705
|
+
const tabElements = tabs.elements.filter((item) => item.name === "w:tab");
|
|
21706
|
+
const tabStops = [];
|
|
21707
|
+
tabElements.forEach((tab) => {
|
|
21708
|
+
const tabStop = {};
|
|
21709
|
+
if (!tab.attributes) tab.attributes = {};
|
|
21710
|
+
if (tab.attributes["w:val"] !== void 0) tabStop.val = tab.attributes["w:val"];
|
|
21711
|
+
if (tab.attributes["w:leader"] !== void 0) tabStop.leader = tab.attributes["w:leader"];
|
|
21712
|
+
if (tab.attributes["w:pos"] !== void 0) tabStop.pos = twipsToPixels(tab.attributes["w:pos"]);
|
|
21713
|
+
tabStops.push(tabStop);
|
|
21714
|
+
});
|
|
21715
|
+
paragraphProperties.tabStops = tabStops;
|
|
21716
|
+
}
|
|
21862
21717
|
return paragraphProperties;
|
|
21863
21718
|
}
|
|
21864
21719
|
function _processListRunProperties(data) {
|
|
@@ -21905,9 +21760,6 @@ const handleParagraphNode = (params2) => {
|
|
|
21905
21760
|
let schemaNode;
|
|
21906
21761
|
let processedElements = preProcessNodesForFldChar(node2.elements);
|
|
21907
21762
|
node2.elements = processedElements;
|
|
21908
|
-
if (testForList(node2, docx)) {
|
|
21909
|
-
return { nodes: [], consumed: 0 };
|
|
21910
|
-
}
|
|
21911
21763
|
const handleStandardNode2 = nodeListHandler2.handlerEntities.find(
|
|
21912
21764
|
(e) => e.handlerName === "standardNodeHandler"
|
|
21913
21765
|
)?.handler;
|
|
@@ -21977,6 +21829,14 @@ const handleParagraphNode = (params2) => {
|
|
|
21977
21829
|
schemaNode.attrs["spacing"] = getParagraphSpacing(node2, docx, styleId, schemaNode.attrs.marksAttrs);
|
|
21978
21830
|
schemaNode.attrs["rsidRDefault"] = defaultStyleId;
|
|
21979
21831
|
}
|
|
21832
|
+
if (docx) {
|
|
21833
|
+
const { justify: justify2 } = getDefaultParagraphStyle(docx, styleId);
|
|
21834
|
+
if (justify2) {
|
|
21835
|
+
schemaNode.attrs.justify = {
|
|
21836
|
+
val: justify2["w:val"]
|
|
21837
|
+
};
|
|
21838
|
+
}
|
|
21839
|
+
}
|
|
21980
21840
|
if (framePr && framePr.attributes["w:dropCap"]) {
|
|
21981
21841
|
schemaNode.attrs.dropcap = {
|
|
21982
21842
|
type: framePr.attributes["w:dropCap"],
|
|
@@ -21999,6 +21859,7 @@ const handleParagraphNode = (params2) => {
|
|
|
21999
21859
|
schemaNode.attrs.paragraphProperties.sectPr = sectPr;
|
|
22000
21860
|
schemaNode.attrs.pageBreakSource = "sectPr";
|
|
22001
21861
|
}
|
|
21862
|
+
console.debug("paragraphNodeHandler", schemaNode);
|
|
22002
21863
|
return { nodes: schemaNode ? [schemaNode] : [], consumed: 1 };
|
|
22003
21864
|
};
|
|
22004
21865
|
const getParagraphIndent = (node2, docx, styleId = "") => {
|
|
@@ -22903,8 +22764,8 @@ const defaultNodeListHandler = () => {
|
|
|
22903
22764
|
alternateChoiceHandler,
|
|
22904
22765
|
runNodeHandlerEntity,
|
|
22905
22766
|
pictNodeHandlerEntity,
|
|
22906
|
-
paragraphNodeHandlerEntity,
|
|
22907
22767
|
listHandlerEntity,
|
|
22768
|
+
paragraphNodeHandlerEntity,
|
|
22908
22769
|
textNodeHandlerEntity,
|
|
22909
22770
|
lineBreakNodeHandlerEntity,
|
|
22910
22771
|
annotationNodeHandlerEntity,
|
|
@@ -22918,7 +22779,7 @@ const defaultNodeListHandler = () => {
|
|
|
22918
22779
|
autoPageHandlerEntity,
|
|
22919
22780
|
autoTotalPageCountEntity,
|
|
22920
22781
|
standardNodeHandlerEntity
|
|
22921
|
-
//
|
|
22782
|
+
// This is the last one as it can handle everything
|
|
22922
22783
|
];
|
|
22923
22784
|
const handler = createNodeListHandler(entities);
|
|
22924
22785
|
return {
|
|
@@ -23150,6 +23011,8 @@ const importHeadersFooters = (docx, converter, editor) => {
|
|
|
23150
23011
|
converter.headers[rId] = { type: "doc", content: [...schema] };
|
|
23151
23012
|
sectionType && (converter.headerIds[sectionType] = rId);
|
|
23152
23013
|
});
|
|
23014
|
+
const titlePg = allSectPrElements?.find((el) => el.name === "w:titlePg");
|
|
23015
|
+
if (titlePg) converter.headerIds.titlePg = true;
|
|
23153
23016
|
footers.forEach((footer) => {
|
|
23154
23017
|
const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(footer, docx);
|
|
23155
23018
|
const sectPrFooter = allSectPrElements.find((el) => el.name === "w:footerReference" && el.attributes["r:id"] === rId);
|
|
@@ -23290,7 +23153,7 @@ const _SuperConverter = class _SuperConverter2 {
|
|
|
23290
23153
|
return;
|
|
23291
23154
|
}
|
|
23292
23155
|
}
|
|
23293
|
-
static updateDocumentVersion(docx = this.convertedXml, version2 = "0.
|
|
23156
|
+
static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.0-RC2") {
|
|
23294
23157
|
const customLocation = "docProps/custom.xml";
|
|
23295
23158
|
if (!docx[customLocation]) {
|
|
23296
23159
|
docx[customLocation] = generateCustomXml();
|
|
@@ -23447,7 +23310,7 @@ const _SuperConverter = class _SuperConverter2 {
|
|
|
23447
23310
|
const exporter = new DocxExporter(this);
|
|
23448
23311
|
return exporter.schemaToXml(data, debug);
|
|
23449
23312
|
}
|
|
23450
|
-
async exportToDocx(jsonData, editorSchema, documentMedia, isFinalDoc = false, commentsExportType, comments = [], editor) {
|
|
23313
|
+
async exportToDocx(jsonData, editorSchema, documentMedia, isFinalDoc = false, commentsExportType, comments = [], editor, exportJsonOnly = false) {
|
|
23451
23314
|
const commentsWithParaIds = comments.map((c2) => prepareCommentParaIds(c2));
|
|
23452
23315
|
const commentDefinitions = commentsWithParaIds.map((c2, index2) => getCommentDefinition(c2, index2, commentsWithParaIds, editor));
|
|
23453
23316
|
const { result, params: params2 } = this.exportToXmlJson({
|
|
@@ -23459,6 +23322,7 @@ const _SuperConverter = class _SuperConverter2 {
|
|
|
23459
23322
|
isFinalDoc,
|
|
23460
23323
|
editor
|
|
23461
23324
|
});
|
|
23325
|
+
if (exportJsonOnly) return result;
|
|
23462
23326
|
const exporter = new DocxExporter(this);
|
|
23463
23327
|
const xml = exporter.schemaToXml(result);
|
|
23464
23328
|
await __privateMethod$2(this, _SuperConverter_instances, exportProcessMediaFiles_fn).call(this, {
|
|
@@ -23756,7 +23620,7 @@ function storeSuperdocVersion(docx) {
|
|
|
23756
23620
|
function generateCustomXml() {
|
|
23757
23621
|
return DEFAULT_CUSTOM_XML;
|
|
23758
23622
|
}
|
|
23759
|
-
function generateSuperdocVersion(pid = 2, version2 = "0.
|
|
23623
|
+
function generateSuperdocVersion(pid = 2, version2 = "0.13.0-RC2") {
|
|
23760
23624
|
return {
|
|
23761
23625
|
type: "element",
|
|
23762
23626
|
name: "property",
|
|
@@ -26289,7 +26153,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
|
|
|
26289
26153
|
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);
|
|
26290
26154
|
var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
|
|
26291
26155
|
var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
|
|
26292
|
-
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;
|
|
26156
|
+
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;
|
|
26293
26157
|
function getMarksFromSelection(state2) {
|
|
26294
26158
|
const { from: from2, to, empty: empty2 } = state2.selection;
|
|
26295
26159
|
const marks = [];
|
|
@@ -27261,8 +27125,8 @@ class Attribute2 {
|
|
|
27261
27125
|
const type2 = getNodeType(typeOrName, state2.schema);
|
|
27262
27126
|
const { from: from2, to } = state2.selection;
|
|
27263
27127
|
const nodes = [];
|
|
27264
|
-
state2.doc.nodesBetween(from2, to, (
|
|
27265
|
-
nodes.push(
|
|
27128
|
+
state2.doc.nodesBetween(from2, to, (node3) => {
|
|
27129
|
+
nodes.push(node3);
|
|
27266
27130
|
});
|
|
27267
27131
|
const node2 = nodes.reverse().find((nodeItem) => nodeItem.type.name === type2.name);
|
|
27268
27132
|
if (!node2) return {};
|
|
@@ -30011,6 +29875,377 @@ const baseBulletList = {
|
|
|
30011
29875
|
}
|
|
30012
29876
|
]
|
|
30013
29877
|
};
|
|
29878
|
+
function createDocument(converter, schema, editor, { check = false } = {}) {
|
|
29879
|
+
const documentData = converter.getSchema(editor);
|
|
29880
|
+
if (documentData) {
|
|
29881
|
+
const documentNode = schema.nodeFromJSON(documentData);
|
|
29882
|
+
if (check) {
|
|
29883
|
+
documentNode.check();
|
|
29884
|
+
}
|
|
29885
|
+
return documentNode;
|
|
29886
|
+
}
|
|
29887
|
+
return schema.topNodeType.createAndFill();
|
|
29888
|
+
}
|
|
29889
|
+
function getSchemaTypeByName(name, schema) {
|
|
29890
|
+
return schema.nodes[name] || schema.marks[name] || null;
|
|
29891
|
+
}
|
|
29892
|
+
function generateDocxListAttributes(listType) {
|
|
29893
|
+
const listTypesMap = {
|
|
29894
|
+
bulletList: 1,
|
|
29895
|
+
orderedList: 2
|
|
29896
|
+
};
|
|
29897
|
+
return {
|
|
29898
|
+
attributes: {
|
|
29899
|
+
parentAttributes: {
|
|
29900
|
+
"w14:paraId": generateDocxRandomId(),
|
|
29901
|
+
"w14:textId": generateDocxRandomId(),
|
|
29902
|
+
"w:rsidR": generateDocxRandomId(),
|
|
29903
|
+
"w:rsidRDefault": generateDocxRandomId(),
|
|
29904
|
+
"w:rsidP": generateDocxRandomId(),
|
|
29905
|
+
paragraphProperties: {
|
|
29906
|
+
type: "element",
|
|
29907
|
+
name: "w:pPr",
|
|
29908
|
+
elements: [
|
|
29909
|
+
{
|
|
29910
|
+
type: "element",
|
|
29911
|
+
name: "w:pStyle",
|
|
29912
|
+
attributes: {
|
|
29913
|
+
"w:val": "ListParagraph"
|
|
29914
|
+
}
|
|
29915
|
+
},
|
|
29916
|
+
{
|
|
29917
|
+
type: "element",
|
|
29918
|
+
name: "w:numPr",
|
|
29919
|
+
elements: [
|
|
29920
|
+
{
|
|
29921
|
+
type: "element",
|
|
29922
|
+
name: "w:ilvl",
|
|
29923
|
+
attributes: {
|
|
29924
|
+
"w:val": "0"
|
|
29925
|
+
}
|
|
29926
|
+
},
|
|
29927
|
+
{
|
|
29928
|
+
type: "element",
|
|
29929
|
+
name: "w:numId",
|
|
29930
|
+
attributes: {
|
|
29931
|
+
"w:val": listTypesMap[listType] || 0
|
|
29932
|
+
}
|
|
29933
|
+
}
|
|
29934
|
+
]
|
|
29935
|
+
}
|
|
29936
|
+
]
|
|
29937
|
+
}
|
|
29938
|
+
}
|
|
29939
|
+
}
|
|
29940
|
+
};
|
|
29941
|
+
}
|
|
29942
|
+
function getMarksBetween(from2, to, doc2) {
|
|
29943
|
+
const marks = [];
|
|
29944
|
+
if (from2 === to) {
|
|
29945
|
+
doc2.resolve(from2).marks().forEach((mark) => {
|
|
29946
|
+
const $pos = doc2.resolve(from2 - 1);
|
|
29947
|
+
const range2 = getMarkRange($pos, mark.type);
|
|
29948
|
+
if (!range2) {
|
|
29949
|
+
return;
|
|
29950
|
+
}
|
|
29951
|
+
marks.push({
|
|
29952
|
+
mark,
|
|
29953
|
+
...range2
|
|
29954
|
+
});
|
|
29955
|
+
});
|
|
29956
|
+
} else {
|
|
29957
|
+
doc2.nodesBetween(from2, to, (node2, pos) => {
|
|
29958
|
+
if (!node2 || node2?.nodeSize === void 0) {
|
|
29959
|
+
return;
|
|
29960
|
+
}
|
|
29961
|
+
marks.push(
|
|
29962
|
+
...node2.marks.map((mark) => ({
|
|
29963
|
+
from: pos,
|
|
29964
|
+
to: pos + node2.nodeSize,
|
|
29965
|
+
mark
|
|
29966
|
+
}))
|
|
29967
|
+
);
|
|
29968
|
+
});
|
|
29969
|
+
}
|
|
29970
|
+
return marks;
|
|
29971
|
+
}
|
|
29972
|
+
function isActive(state2, name, attrs = {}) {
|
|
29973
|
+
if (!name) {
|
|
29974
|
+
return isNodeActive(state2, null, attrs) || isMarkActive(state2, null, attrs);
|
|
29975
|
+
}
|
|
29976
|
+
const schemaType = getSchemaTypeNameByName(name, state2.schema);
|
|
29977
|
+
if (schemaType === "node") {
|
|
29978
|
+
return isNodeActive(state2, name, attrs);
|
|
29979
|
+
}
|
|
29980
|
+
if (schemaType === "mark") {
|
|
29981
|
+
return isMarkActive(state2, name, attrs);
|
|
29982
|
+
}
|
|
29983
|
+
return false;
|
|
29984
|
+
}
|
|
29985
|
+
function findChildren$3(node2, predicate) {
|
|
29986
|
+
const nodesWithPos = [];
|
|
29987
|
+
node2.descendants((child, pos) => {
|
|
29988
|
+
if (predicate(child)) {
|
|
29989
|
+
nodesWithPos.push({
|
|
29990
|
+
node: child,
|
|
29991
|
+
pos
|
|
29992
|
+
});
|
|
29993
|
+
}
|
|
29994
|
+
});
|
|
29995
|
+
return nodesWithPos;
|
|
29996
|
+
}
|
|
29997
|
+
function posToDOMRect(view, from2, to) {
|
|
29998
|
+
const minPos = 0;
|
|
29999
|
+
const maxPos = view.state.doc.content.size;
|
|
30000
|
+
const resolvedFrom = minMax(from2, minPos, maxPos);
|
|
30001
|
+
const resolvedEnd = minMax(to, minPos, maxPos);
|
|
30002
|
+
const start2 = view.coordsAtPos(resolvedFrom);
|
|
30003
|
+
const end2 = view.coordsAtPos(resolvedEnd, -1);
|
|
30004
|
+
const top2 = Math.min(start2.top, end2.top);
|
|
30005
|
+
const bottom2 = Math.max(start2.bottom, end2.bottom);
|
|
30006
|
+
const left2 = Math.min(start2.left, end2.left);
|
|
30007
|
+
const right2 = Math.max(start2.right, end2.right);
|
|
30008
|
+
const width = right2 - left2;
|
|
30009
|
+
const height = bottom2 - top2;
|
|
30010
|
+
const x = left2;
|
|
30011
|
+
const y = top2;
|
|
30012
|
+
const data = {
|
|
30013
|
+
top: top2,
|
|
30014
|
+
bottom: bottom2,
|
|
30015
|
+
left: left2,
|
|
30016
|
+
right: right2,
|
|
30017
|
+
width,
|
|
30018
|
+
height,
|
|
30019
|
+
x,
|
|
30020
|
+
y
|
|
30021
|
+
};
|
|
30022
|
+
return {
|
|
30023
|
+
...data,
|
|
30024
|
+
toJSON: () => data
|
|
30025
|
+
};
|
|
30026
|
+
}
|
|
30027
|
+
const isInTable$1 = (state2) => {
|
|
30028
|
+
const { $head } = state2.selection;
|
|
30029
|
+
for (let d = $head.depth; d > 0; d -= 1) {
|
|
30030
|
+
if ($head.node(d).type?.spec?.tableRole === "row") {
|
|
30031
|
+
return true;
|
|
30032
|
+
}
|
|
30033
|
+
}
|
|
30034
|
+
return false;
|
|
30035
|
+
};
|
|
30036
|
+
const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
30037
|
+
__proto__: null,
|
|
30038
|
+
chainableEditorState,
|
|
30039
|
+
cleanSchemaItem,
|
|
30040
|
+
createDocument,
|
|
30041
|
+
defaultBlockAt,
|
|
30042
|
+
findChildren: findChildren$3,
|
|
30043
|
+
findMark,
|
|
30044
|
+
findParentNode,
|
|
30045
|
+
findParentNodeClosestToPos,
|
|
30046
|
+
generateDocxListAttributes,
|
|
30047
|
+
generateDocxRandomId,
|
|
30048
|
+
generateRandom32BitHex,
|
|
30049
|
+
getActiveFormatting,
|
|
30050
|
+
getExtensionConfigField,
|
|
30051
|
+
getMarkRange,
|
|
30052
|
+
getMarkType,
|
|
30053
|
+
getMarksBetween,
|
|
30054
|
+
getMarksFromSelection,
|
|
30055
|
+
getNodeType,
|
|
30056
|
+
getSchemaTypeByName,
|
|
30057
|
+
getSchemaTypeNameByName,
|
|
30058
|
+
isActive,
|
|
30059
|
+
isInTable: isInTable$1,
|
|
30060
|
+
isList,
|
|
30061
|
+
isMarkActive,
|
|
30062
|
+
isNodeActive,
|
|
30063
|
+
isTextSelection,
|
|
30064
|
+
posToDOMRect
|
|
30065
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
30066
|
+
const generateNewListDefinition = ({ numId, listType, editor }) => {
|
|
30067
|
+
const definition = listType.name === "orderedList" ? baseOrderedListDef : baseBulletList;
|
|
30068
|
+
const numbering = editor.converter.numbering;
|
|
30069
|
+
const newNumbering = { ...numbering };
|
|
30070
|
+
const newAbstractId = getNewListId(editor);
|
|
30071
|
+
const newAbstractDef = {
|
|
30072
|
+
...definition,
|
|
30073
|
+
attributes: {
|
|
30074
|
+
...definition.attributes,
|
|
30075
|
+
"w:abstractNumId": String(newAbstractId)
|
|
30076
|
+
}
|
|
30077
|
+
};
|
|
30078
|
+
newNumbering.abstracts[newAbstractId] = newAbstractDef;
|
|
30079
|
+
const newNumDef = {
|
|
30080
|
+
type: "element",
|
|
30081
|
+
name: "w:num",
|
|
30082
|
+
attributes: {
|
|
30083
|
+
"w:numId": String(numId),
|
|
30084
|
+
"w16cid:durableId": "485517411"
|
|
30085
|
+
},
|
|
30086
|
+
elements: [
|
|
30087
|
+
{ name: "w:abstractNumId", attributes: { "w:val": String(newAbstractId) } }
|
|
30088
|
+
]
|
|
30089
|
+
};
|
|
30090
|
+
newNumbering.definitions[numId] = newNumDef;
|
|
30091
|
+
editor.converter.numbering = newNumbering;
|
|
30092
|
+
return { abstract: newAbstractDef, definition: newNumDef };
|
|
30093
|
+
};
|
|
30094
|
+
const getNewListId = (editor) => Math.max(...Object.keys(editor.converter.numbering.definitions).map(Number)) + 1;
|
|
30095
|
+
const getListDefinitionDetails = ({ numId, level, editor }) => {
|
|
30096
|
+
const { definitions, abstracts } = editor.converter.numbering;
|
|
30097
|
+
const abstractId = definitions[numId]?.elements?.find((item) => item.name === "w:abstractNumId")?.attributes?.["w:val"];
|
|
30098
|
+
const abstract = abstracts[abstractId];
|
|
30099
|
+
const listDefinition = abstract?.elements?.find((item) => item.name === "w:lvl" && item.attributes["w:ilvl"] == level);
|
|
30100
|
+
const start2 = listDefinition?.elements?.find((item) => item.name === "w:start")?.attributes["w:val"];
|
|
30101
|
+
const numFmt = listDefinition?.elements?.find((item) => item.name === "w:numFmt")?.attributes["w:val"];
|
|
30102
|
+
const lvlText = listDefinition?.elements?.find((item) => item.name === "w:lvlText")?.attributes["w:val"];
|
|
30103
|
+
return { start: start2, numFmt, lvlText };
|
|
30104
|
+
};
|
|
30105
|
+
const removeListDefinitions = (listId, editor) => {
|
|
30106
|
+
const { numbering } = editor.converter;
|
|
30107
|
+
if (!numbering) return;
|
|
30108
|
+
const { definitions, abstracts } = numbering;
|
|
30109
|
+
const abstractId = definitions[listId].elements[0].attributes["w:val"];
|
|
30110
|
+
delete definitions[listId];
|
|
30111
|
+
delete abstracts[abstractId];
|
|
30112
|
+
editor.converter.numbering = {
|
|
30113
|
+
definitions,
|
|
30114
|
+
abstracts
|
|
30115
|
+
};
|
|
30116
|
+
};
|
|
30117
|
+
const createListItemNodeJSON = ({ level, lvlText, numId, numFmt, start: start2, contentNode }) => {
|
|
30118
|
+
start2 = Number(start2);
|
|
30119
|
+
if (!contentNode) {
|
|
30120
|
+
contentNode = {
|
|
30121
|
+
type: "paragraph",
|
|
30122
|
+
content: []
|
|
30123
|
+
};
|
|
30124
|
+
}
|
|
30125
|
+
const listLevel = new Array(level).fill(start2).map((_, i) => i);
|
|
30126
|
+
listLevel.push(start2);
|
|
30127
|
+
return {
|
|
30128
|
+
type: "listItem",
|
|
30129
|
+
attrs: {
|
|
30130
|
+
lvlText,
|
|
30131
|
+
listLevel,
|
|
30132
|
+
level,
|
|
30133
|
+
numId,
|
|
30134
|
+
numPrType: "inline",
|
|
30135
|
+
listNumberingType: numFmt
|
|
30136
|
+
},
|
|
30137
|
+
content: [contentNode]
|
|
30138
|
+
};
|
|
30139
|
+
};
|
|
30140
|
+
const createSchemaOrderedListNode = ({ level, numId, editor, contentNode }) => {
|
|
30141
|
+
level = Number(level);
|
|
30142
|
+
numId = Number(numId);
|
|
30143
|
+
const { start: start2, lvlText, numFmt } = ListHelpers.getListDefinitionDetails({ numId, level, editor });
|
|
30144
|
+
const listNodeJSON = createListItemNodeJSON({ level, lvlText, numFmt, numId, start: start2, contentNode });
|
|
30145
|
+
const node2 = {
|
|
30146
|
+
type: "orderedList",
|
|
30147
|
+
attrs: {
|
|
30148
|
+
"list-style-type": numFmt,
|
|
30149
|
+
listId: numId,
|
|
30150
|
+
order: level
|
|
30151
|
+
},
|
|
30152
|
+
content: [listNodeJSON]
|
|
30153
|
+
};
|
|
30154
|
+
return editor.schema.nodeFromJSON(node2);
|
|
30155
|
+
};
|
|
30156
|
+
const createNewList = ({ listType, editor, chain }) => {
|
|
30157
|
+
const numId = ListHelpers.getNewListId(editor);
|
|
30158
|
+
if (typeof node === "string") listType = editor.schema.nodes[listType];
|
|
30159
|
+
ListHelpers.generateNewListDefinition({ numId, listType, editor });
|
|
30160
|
+
const { state: state2 } = editor;
|
|
30161
|
+
const { $from } = state2.selection;
|
|
30162
|
+
const content = $from.parent;
|
|
30163
|
+
const level = 0;
|
|
30164
|
+
const listNode = ListHelpers.createSchemaOrderedListNode({
|
|
30165
|
+
level,
|
|
30166
|
+
numId,
|
|
30167
|
+
editor,
|
|
30168
|
+
contentNode: content?.toJSON()
|
|
30169
|
+
});
|
|
30170
|
+
const parentDepth = $from.depth;
|
|
30171
|
+
const replaceFrom = $from.before(parentDepth);
|
|
30172
|
+
const replaceTo = $from.after(parentDepth);
|
|
30173
|
+
return insertNewList(chain, replaceFrom, replaceTo, listNode);
|
|
30174
|
+
};
|
|
30175
|
+
const indentListItem = ({ chain, editor, node: currentNode }) => {
|
|
30176
|
+
const { state: state2 } = editor;
|
|
30177
|
+
const { $from } = state2.selection;
|
|
30178
|
+
const content = $from.parent;
|
|
30179
|
+
const numId = currentNode.node.attrs.numId;
|
|
30180
|
+
const level = currentNode.node.attrs.level + 1;
|
|
30181
|
+
const listNode = ListHelpers.createSchemaOrderedListNode({
|
|
30182
|
+
level,
|
|
30183
|
+
numId,
|
|
30184
|
+
editor,
|
|
30185
|
+
contentNode: content?.toJSON()
|
|
30186
|
+
});
|
|
30187
|
+
const parentList = findParentNode((node2) => node2.type.name === "orderedList")(state2.selection);
|
|
30188
|
+
const replaceFrom = parentList.pos;
|
|
30189
|
+
const replaceTo = parentList.node.nodeSize + parentList.pos;
|
|
30190
|
+
const newMarks = addInlineTextMarks(currentNode.node, []);
|
|
30191
|
+
return insertNewList(chain, replaceFrom, replaceTo, listNode, newMarks);
|
|
30192
|
+
};
|
|
30193
|
+
const outdentListItem = ({ chain, editor, node: currentNode }) => {
|
|
30194
|
+
const { state: state2 } = editor;
|
|
30195
|
+
const { $from } = state2.selection;
|
|
30196
|
+
const content = $from.parent;
|
|
30197
|
+
const numId = currentNode.node.attrs.numId;
|
|
30198
|
+
const level = currentNode.node.attrs.level - 1;
|
|
30199
|
+
const parentList = findParentNode((node2) => node2.type.name === "orderedList")(state2.selection);
|
|
30200
|
+
const replaceFrom = parentList.pos;
|
|
30201
|
+
const replaceTo = parentList.node.nodeSize + parentList.pos;
|
|
30202
|
+
if (level < 0) {
|
|
30203
|
+
return insertNewList(chain, replaceFrom, replaceTo, content);
|
|
30204
|
+
}
|
|
30205
|
+
const listNode = ListHelpers.createSchemaOrderedListNode({
|
|
30206
|
+
level,
|
|
30207
|
+
numId,
|
|
30208
|
+
editor,
|
|
30209
|
+
contentNode: content?.toJSON()
|
|
30210
|
+
});
|
|
30211
|
+
const newMarks = addInlineTextMarks(currentNode.node, []);
|
|
30212
|
+
return insertNewList(chain, replaceFrom, replaceTo, listNode, newMarks);
|
|
30213
|
+
};
|
|
30214
|
+
const insertNewList = (chain, replaceFrom, replaceTo, listNode, marks = []) => {
|
|
30215
|
+
return chain().command(({ tr, dispatch }) => {
|
|
30216
|
+
tr.replaceWith(replaceFrom, replaceTo, listNode);
|
|
30217
|
+
tr.ensureMarks(marks);
|
|
30218
|
+
dispatch(tr);
|
|
30219
|
+
return true;
|
|
30220
|
+
}).run();
|
|
30221
|
+
};
|
|
30222
|
+
const addInlineTextMarks = (currentNode, filteredMarks) => {
|
|
30223
|
+
const newMarks = [...filteredMarks];
|
|
30224
|
+
try {
|
|
30225
|
+
const textMarks = currentNode.children[0].children[0].marks;
|
|
30226
|
+
const inlineTextStyleFromSplitBlock = textMarks.find((m) => m.type.name === "textStyle");
|
|
30227
|
+
inlineTextStyleFromSplitBlock && newMarks.push(inlineTextStyleFromSplitBlock);
|
|
30228
|
+
} catch (e) {
|
|
30229
|
+
}
|
|
30230
|
+
return newMarks;
|
|
30231
|
+
};
|
|
30232
|
+
const ListHelpers = {
|
|
30233
|
+
// DOCX helpers
|
|
30234
|
+
getListDefinitionDetails,
|
|
30235
|
+
generateNewListDefinition,
|
|
30236
|
+
getNewListId,
|
|
30237
|
+
removeListDefinitions,
|
|
30238
|
+
// Schema helpers
|
|
30239
|
+
createNewList,
|
|
30240
|
+
createSchemaOrderedListNode,
|
|
30241
|
+
createListItemNodeJSON,
|
|
30242
|
+
indentListItem,
|
|
30243
|
+
outdentListItem,
|
|
30244
|
+
addInlineTextMarks,
|
|
30245
|
+
// Base list definitions
|
|
30246
|
+
baseOrderedListDef,
|
|
30247
|
+
baseBulletList
|
|
30248
|
+
};
|
|
30014
30249
|
const joinListBackwards = (tr, listType) => {
|
|
30015
30250
|
const list = findParentNode((node2) => node2.type === listType)(tr.selection);
|
|
30016
30251
|
if (!list) return true;
|
|
@@ -30048,7 +30283,7 @@ const toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {})
|
|
|
30048
30283
|
if (range2.depth >= 1 && parentList && range2.depth - parentList.depth <= 1) {
|
|
30049
30284
|
if (parentList.node.type === listType) {
|
|
30050
30285
|
const { listId } = parentList.node.attrs;
|
|
30051
|
-
if (editor.converter)
|
|
30286
|
+
if (editor.converter) ListHelpers.removeListDefinitions(listId, editor);
|
|
30052
30287
|
return commands2.liftListItem(itemType);
|
|
30053
30288
|
}
|
|
30054
30289
|
if (isList(parentList.node.type.name, extensions) && listType.validContent(parentList.node.content) && dispatch) {
|
|
@@ -30070,8 +30305,8 @@ const toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {})
|
|
|
30070
30305
|
return commands2.clearNodes();
|
|
30071
30306
|
};
|
|
30072
30307
|
};
|
|
30073
|
-
const newListId = numbering?.definitions ? getNewListId(
|
|
30074
|
-
if (editor.converter)
|
|
30308
|
+
const newListId = numbering?.definitions ? ListHelpers.getNewListId(editor) : null;
|
|
30309
|
+
if (editor.converter) ListHelpers.generateNewListDefinition(newListId, numbering, listType);
|
|
30075
30310
|
attributes.listId = newListId;
|
|
30076
30311
|
if (!keepMarks || !marks || !dispatch) {
|
|
30077
30312
|
const result2 = chain().command(createTryConvertNodeToDefault({ ensureMarks: false })).wrapInList(listType, attributes).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
|
|
@@ -30080,41 +30315,7 @@ const toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {})
|
|
|
30080
30315
|
const result = chain().command(createTryConvertNodeToDefault({ ensureMarks: true })).wrapInList(listType, attributes).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
|
|
30081
30316
|
return result;
|
|
30082
30317
|
};
|
|
30083
|
-
const
|
|
30084
|
-
const generateNewListDefinition = (newListId, numbering, listType) => {
|
|
30085
|
-
const definition = listType.name === "orderedList" ? baseOrderedListDef : baseBulletList;
|
|
30086
|
-
const newNumbering = { ...numbering };
|
|
30087
|
-
const newAbstractId = getNewListId(newNumbering.abstracts);
|
|
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(newListId),
|
|
30101
|
-
"w16cid:durableId": "485517411"
|
|
30102
|
-
},
|
|
30103
|
-
elements: [
|
|
30104
|
-
{ name: "w:abstractNumId", attributes: { "w:val": String(newAbstractId) } }
|
|
30105
|
-
]
|
|
30106
|
-
};
|
|
30107
|
-
newNumbering.definitions[newListId] = newNumDef;
|
|
30108
|
-
return newNumbering;
|
|
30109
|
-
};
|
|
30110
|
-
const removeListDefinitions = (listId, numbering) => {
|
|
30111
|
-
const { definitions, abstracts } = numbering;
|
|
30112
|
-
const abstractId = definitions[listId].elements[0].attributes["w:val"];
|
|
30113
|
-
delete definitions[listId];
|
|
30114
|
-
delete abstracts[abstractId];
|
|
30115
|
-
return numbering;
|
|
30116
|
-
};
|
|
30117
|
-
const splitListItem = (typeOrName) => (props) => {
|
|
30318
|
+
const splitListItem = (typeOrName, currentNode) => (props) => {
|
|
30118
30319
|
const { tr, state: state2, dispatch, editor } = props;
|
|
30119
30320
|
const type2 = getNodeType(typeOrName, state2.schema);
|
|
30120
30321
|
const { $from, $to, node: node2 } = state2.selection;
|
|
@@ -30143,8 +30344,8 @@ const splitListItem = (typeOrName) => (props) => {
|
|
|
30143
30344
|
$from.node().type.name,
|
|
30144
30345
|
$from.node().attrs
|
|
30145
30346
|
);
|
|
30146
|
-
const
|
|
30147
|
-
wrap2 = wrap2.append(Fragment.from(type2.createAndFill(null,
|
|
30347
|
+
const nextType = type2.contentMatch.defaultType?.createAndFill(newNextTypeAttrs) || void 0;
|
|
30348
|
+
wrap2 = wrap2.append(Fragment.from(type2.createAndFill(null, nextType) || void 0));
|
|
30148
30349
|
const start2 = $from.before($from.depth - (depthBefore - 1));
|
|
30149
30350
|
tr.replace(start2, $from.after(-depthAfter), new Slice(wrap2, 4 - depthBefore, 0));
|
|
30150
30351
|
let sel = -1;
|
|
@@ -30157,30 +30358,18 @@ const splitListItem = (typeOrName) => (props) => {
|
|
|
30157
30358
|
}
|
|
30158
30359
|
return true;
|
|
30159
30360
|
}
|
|
30160
|
-
const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
|
|
30161
|
-
const newTypeAttributes = Attribute2.getSplittedAttributes(extensionAttrs, grandParent.type.name, grandParent.attrs);
|
|
30162
|
-
const newNextTypeAttributes = Attribute2.getSplittedAttributes(
|
|
30163
|
-
extensionAttrs,
|
|
30164
|
-
$from.node().type.name,
|
|
30165
|
-
$from.node().attrs
|
|
30166
|
-
);
|
|
30167
30361
|
tr.delete($from.pos, $to.pos);
|
|
30168
|
-
|
|
30169
|
-
{ type: type2, attrs: newTypeAttributes },
|
|
30170
|
-
{ type: nextType, attrs: newNextTypeAttributes }
|
|
30171
|
-
] : [{ type: type2, attrs: newTypeAttributes }];
|
|
30172
|
-
if (!canSplit(tr.doc, $from.pos, 2)) {
|
|
30173
|
-
return false;
|
|
30174
|
-
}
|
|
30362
|
+
if (!canSplit(tr.doc, $from.pos, 3)) return false;
|
|
30175
30363
|
if (dispatch) {
|
|
30176
30364
|
const { selection, storedMarks } = state2;
|
|
30177
30365
|
const { splittableMarks } = editor.extensionService;
|
|
30178
30366
|
const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
|
|
30179
|
-
tr.split($from.pos,
|
|
30367
|
+
tr.split($from.pos, 3).scrollIntoView();
|
|
30180
30368
|
if (!marks || !dispatch) return true;
|
|
30181
30369
|
const filteredMarks = marks.filter((m) => splittableMarks.includes(m.type.name));
|
|
30182
|
-
|
|
30183
|
-
tr.
|
|
30370
|
+
const updatedMarks = ListHelpers.addInlineTextMarks(currentNode.node, filteredMarks);
|
|
30371
|
+
tr.ensureMarks(updatedMarks);
|
|
30372
|
+
tr.setMeta("splitListItem", updatedMarks);
|
|
30184
30373
|
}
|
|
30185
30374
|
return true;
|
|
30186
30375
|
};
|
|
@@ -30341,194 +30530,6 @@ const EditorFocus = Extension.create({
|
|
|
30341
30530
|
return [editorFocusPlugin];
|
|
30342
30531
|
}
|
|
30343
30532
|
});
|
|
30344
|
-
function createDocument(converter, schema, editor, { check = false } = {}) {
|
|
30345
|
-
const documentData = converter.getSchema(editor);
|
|
30346
|
-
if (documentData) {
|
|
30347
|
-
const documentNode = schema.nodeFromJSON(documentData);
|
|
30348
|
-
if (check) {
|
|
30349
|
-
documentNode.check();
|
|
30350
|
-
}
|
|
30351
|
-
return documentNode;
|
|
30352
|
-
}
|
|
30353
|
-
return schema.topNodeType.createAndFill();
|
|
30354
|
-
}
|
|
30355
|
-
function getSchemaTypeByName(name, schema) {
|
|
30356
|
-
return schema.nodes[name] || schema.marks[name] || null;
|
|
30357
|
-
}
|
|
30358
|
-
function generateDocxListAttributes(listType) {
|
|
30359
|
-
const listTypesMap = {
|
|
30360
|
-
bulletList: 1,
|
|
30361
|
-
orderedList: 2
|
|
30362
|
-
};
|
|
30363
|
-
return {
|
|
30364
|
-
attributes: {
|
|
30365
|
-
parentAttributes: {
|
|
30366
|
-
"w14:paraId": generateDocxRandomId(),
|
|
30367
|
-
"w14:textId": generateDocxRandomId(),
|
|
30368
|
-
"w:rsidR": generateDocxRandomId(),
|
|
30369
|
-
"w:rsidRDefault": generateDocxRandomId(),
|
|
30370
|
-
"w:rsidP": generateDocxRandomId(),
|
|
30371
|
-
paragraphProperties: {
|
|
30372
|
-
type: "element",
|
|
30373
|
-
name: "w:pPr",
|
|
30374
|
-
elements: [
|
|
30375
|
-
{
|
|
30376
|
-
type: "element",
|
|
30377
|
-
name: "w:pStyle",
|
|
30378
|
-
attributes: {
|
|
30379
|
-
"w:val": "ListParagraph"
|
|
30380
|
-
}
|
|
30381
|
-
},
|
|
30382
|
-
{
|
|
30383
|
-
type: "element",
|
|
30384
|
-
name: "w:numPr",
|
|
30385
|
-
elements: [
|
|
30386
|
-
{
|
|
30387
|
-
type: "element",
|
|
30388
|
-
name: "w:ilvl",
|
|
30389
|
-
attributes: {
|
|
30390
|
-
"w:val": "0"
|
|
30391
|
-
}
|
|
30392
|
-
},
|
|
30393
|
-
{
|
|
30394
|
-
type: "element",
|
|
30395
|
-
name: "w:numId",
|
|
30396
|
-
attributes: {
|
|
30397
|
-
"w:val": listTypesMap[listType] || 0
|
|
30398
|
-
}
|
|
30399
|
-
}
|
|
30400
|
-
]
|
|
30401
|
-
}
|
|
30402
|
-
]
|
|
30403
|
-
}
|
|
30404
|
-
}
|
|
30405
|
-
}
|
|
30406
|
-
};
|
|
30407
|
-
}
|
|
30408
|
-
function getMarksBetween(from2, to, doc2) {
|
|
30409
|
-
const marks = [];
|
|
30410
|
-
if (from2 === to) {
|
|
30411
|
-
doc2.resolve(from2).marks().forEach((mark) => {
|
|
30412
|
-
const $pos = doc2.resolve(from2 - 1);
|
|
30413
|
-
const range2 = getMarkRange($pos, mark.type);
|
|
30414
|
-
if (!range2) {
|
|
30415
|
-
return;
|
|
30416
|
-
}
|
|
30417
|
-
marks.push({
|
|
30418
|
-
mark,
|
|
30419
|
-
...range2
|
|
30420
|
-
});
|
|
30421
|
-
});
|
|
30422
|
-
} else {
|
|
30423
|
-
doc2.nodesBetween(from2, to, (node2, pos) => {
|
|
30424
|
-
if (!node2 || node2?.nodeSize === void 0) {
|
|
30425
|
-
return;
|
|
30426
|
-
}
|
|
30427
|
-
marks.push(
|
|
30428
|
-
...node2.marks.map((mark) => ({
|
|
30429
|
-
from: pos,
|
|
30430
|
-
to: pos + node2.nodeSize,
|
|
30431
|
-
mark
|
|
30432
|
-
}))
|
|
30433
|
-
);
|
|
30434
|
-
});
|
|
30435
|
-
}
|
|
30436
|
-
return marks;
|
|
30437
|
-
}
|
|
30438
|
-
function isActive(state2, name, attrs = {}) {
|
|
30439
|
-
if (!name) {
|
|
30440
|
-
return isNodeActive(state2, null, attrs) || isMarkActive(state2, null, attrs);
|
|
30441
|
-
}
|
|
30442
|
-
const schemaType = getSchemaTypeNameByName(name, state2.schema);
|
|
30443
|
-
if (schemaType === "node") {
|
|
30444
|
-
return isNodeActive(state2, name, attrs);
|
|
30445
|
-
}
|
|
30446
|
-
if (schemaType === "mark") {
|
|
30447
|
-
return isMarkActive(state2, name, attrs);
|
|
30448
|
-
}
|
|
30449
|
-
return false;
|
|
30450
|
-
}
|
|
30451
|
-
function findChildren$3(node2, predicate) {
|
|
30452
|
-
const nodesWithPos = [];
|
|
30453
|
-
node2.descendants((child, pos) => {
|
|
30454
|
-
if (predicate(child)) {
|
|
30455
|
-
nodesWithPos.push({
|
|
30456
|
-
node: child,
|
|
30457
|
-
pos
|
|
30458
|
-
});
|
|
30459
|
-
}
|
|
30460
|
-
});
|
|
30461
|
-
return nodesWithPos;
|
|
30462
|
-
}
|
|
30463
|
-
function posToDOMRect(view, from2, to) {
|
|
30464
|
-
const minPos = 0;
|
|
30465
|
-
const maxPos = view.state.doc.content.size;
|
|
30466
|
-
const resolvedFrom = minMax(from2, minPos, maxPos);
|
|
30467
|
-
const resolvedEnd = minMax(to, minPos, maxPos);
|
|
30468
|
-
const start2 = view.coordsAtPos(resolvedFrom);
|
|
30469
|
-
const end2 = view.coordsAtPos(resolvedEnd, -1);
|
|
30470
|
-
const top2 = Math.min(start2.top, end2.top);
|
|
30471
|
-
const bottom2 = Math.max(start2.bottom, end2.bottom);
|
|
30472
|
-
const left2 = Math.min(start2.left, end2.left);
|
|
30473
|
-
const right2 = Math.max(start2.right, end2.right);
|
|
30474
|
-
const width = right2 - left2;
|
|
30475
|
-
const height = bottom2 - top2;
|
|
30476
|
-
const x = left2;
|
|
30477
|
-
const y = top2;
|
|
30478
|
-
const data = {
|
|
30479
|
-
top: top2,
|
|
30480
|
-
bottom: bottom2,
|
|
30481
|
-
left: left2,
|
|
30482
|
-
right: right2,
|
|
30483
|
-
width,
|
|
30484
|
-
height,
|
|
30485
|
-
x,
|
|
30486
|
-
y
|
|
30487
|
-
};
|
|
30488
|
-
return {
|
|
30489
|
-
...data,
|
|
30490
|
-
toJSON: () => data
|
|
30491
|
-
};
|
|
30492
|
-
}
|
|
30493
|
-
const isInTable$1 = (state2) => {
|
|
30494
|
-
const { $head } = state2.selection;
|
|
30495
|
-
for (let d = $head.depth; d > 0; d -= 1) {
|
|
30496
|
-
if ($head.node(d).type?.spec?.tableRole === "row") {
|
|
30497
|
-
return true;
|
|
30498
|
-
}
|
|
30499
|
-
}
|
|
30500
|
-
return false;
|
|
30501
|
-
};
|
|
30502
|
-
const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
30503
|
-
__proto__: null,
|
|
30504
|
-
chainableEditorState,
|
|
30505
|
-
cleanSchemaItem,
|
|
30506
|
-
createDocument,
|
|
30507
|
-
defaultBlockAt,
|
|
30508
|
-
findChildren: findChildren$3,
|
|
30509
|
-
findMark,
|
|
30510
|
-
findParentNode,
|
|
30511
|
-
findParentNodeClosestToPos,
|
|
30512
|
-
generateDocxListAttributes,
|
|
30513
|
-
generateDocxRandomId,
|
|
30514
|
-
generateRandom32BitHex,
|
|
30515
|
-
getActiveFormatting,
|
|
30516
|
-
getExtensionConfigField,
|
|
30517
|
-
getMarkRange,
|
|
30518
|
-
getMarkType,
|
|
30519
|
-
getMarksBetween,
|
|
30520
|
-
getMarksFromSelection,
|
|
30521
|
-
getNodeType,
|
|
30522
|
-
getSchemaTypeByName,
|
|
30523
|
-
getSchemaTypeNameByName,
|
|
30524
|
-
isActive,
|
|
30525
|
-
isInTable: isInTable$1,
|
|
30526
|
-
isList,
|
|
30527
|
-
isMarkActive,
|
|
30528
|
-
isNodeActive,
|
|
30529
|
-
isTextSelection,
|
|
30530
|
-
posToDOMRect
|
|
30531
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
30532
30533
|
const global$1 = globalThis || void 0 || self;
|
|
30533
30534
|
const domIndex = function(node2) {
|
|
30534
30535
|
for (var index2 = 0; ; index2++) {
|
|
@@ -39560,8 +39561,8 @@ const getTrackedChangeText = ({
|
|
|
39560
39561
|
deletionText = node2?.text ?? "";
|
|
39561
39562
|
if (isDeletionInsertion) {
|
|
39562
39563
|
let { id } = marks.deletionMark.attrs;
|
|
39563
|
-
let deletionNode = findNode$1(state2.doc, (
|
|
39564
|
-
const { marks: marks2 = [] } =
|
|
39564
|
+
let deletionNode = findNode$1(state2.doc, (node3) => {
|
|
39565
|
+
const { marks: marks2 = [] } = node3;
|
|
39565
39566
|
const changeMarks = marks2.filter((mark2) => TRACK_CHANGE_MARKS.includes(mark2.type.name));
|
|
39566
39567
|
if (!changeMarks.length) return false;
|
|
39567
39568
|
const hasMatchingId = changeMarks.find((mark2) => mark2.attrs.id === id);
|
|
@@ -39584,12 +39585,12 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes
|
|
|
39584
39585
|
const node2 = nodes[0];
|
|
39585
39586
|
const isDeletionInsertion = !!(marks.insertedMark && marks.deletionMark);
|
|
39586
39587
|
let existingNode;
|
|
39587
|
-
newEditorState.doc.descendants((
|
|
39588
|
-
const { marks: marks2 = [] } =
|
|
39588
|
+
newEditorState.doc.descendants((node3, pos) => {
|
|
39589
|
+
const { marks: marks2 = [] } = node3;
|
|
39589
39590
|
const changeMarks = marks2.filter((mark) => TRACK_CHANGE_MARKS.includes(mark.type.name));
|
|
39590
39591
|
if (!changeMarks.length) return;
|
|
39591
39592
|
const hasMatchingId = changeMarks.find((mark) => mark.attrs.id === id);
|
|
39592
|
-
if (hasMatchingId) existingNode =
|
|
39593
|
+
if (hasMatchingId) existingNode = node3;
|
|
39593
39594
|
if (existingNode) return false;
|
|
39594
39595
|
});
|
|
39595
39596
|
const { deletionText, trackedChangeText } = getTrackedChangeText({
|
|
@@ -39622,8 +39623,8 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes
|
|
|
39622
39623
|
};
|
|
39623
39624
|
function findNode$1(node2, predicate) {
|
|
39624
39625
|
let found2 = null;
|
|
39625
|
-
node2.descendants((
|
|
39626
|
-
if (predicate(
|
|
39626
|
+
node2.descendants((node3, pos) => {
|
|
39627
|
+
if (predicate(node3)) found2 = { node: node3, pos };
|
|
39627
39628
|
if (found2) return false;
|
|
39628
39629
|
});
|
|
39629
39630
|
return found2;
|
|
@@ -40940,7 +40941,14 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
40940
40941
|
* @param {boolean} [options.getUpdatedDocs=false] - When set to true return only updated docx files
|
|
40941
40942
|
* @returns {Promise<Blob|ArrayBuffer|Object>} The exported DOCX file or updated docx files
|
|
40942
40943
|
*/
|
|
40943
|
-
async exportDocx({
|
|
40944
|
+
async exportDocx({
|
|
40945
|
+
isFinalDoc = false,
|
|
40946
|
+
commentsType = "external",
|
|
40947
|
+
exportJsonOnly = false,
|
|
40948
|
+
exportXmlOnly = false,
|
|
40949
|
+
comments = [],
|
|
40950
|
+
getUpdatedDocs = false
|
|
40951
|
+
} = {}) {
|
|
40944
40952
|
const json = __privateMethod$1(this, _Editor_instances, prepareDocumentForExport_fn).call(this, comments);
|
|
40945
40953
|
const documentXml = await this.converter.exportToDocx(
|
|
40946
40954
|
json,
|
|
@@ -40949,8 +40957,10 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
40949
40957
|
isFinalDoc,
|
|
40950
40958
|
commentsType,
|
|
40951
40959
|
comments,
|
|
40952
|
-
this
|
|
40960
|
+
this,
|
|
40961
|
+
exportJsonOnly
|
|
40953
40962
|
);
|
|
40963
|
+
if (exportXmlOnly || exportJsonOnly) return documentXml;
|
|
40954
40964
|
const customXml = this.converter.schemaToXml(this.converter.convertedXml["docProps/custom.xml"].elements[0]);
|
|
40955
40965
|
const styles = this.converter.schemaToXml(this.converter.convertedXml["word/styles.xml"].elements[0]);
|
|
40956
40966
|
const customSettings = this.converter.schemaToXml(this.converter.convertedXml["word/settings.xml"].elements[0]);
|
|
@@ -41033,7 +41043,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
41033
41043
|
* @returns {Object | void} Migration results
|
|
41034
41044
|
*/
|
|
41035
41045
|
processCollaborationMigrations() {
|
|
41036
|
-
console.debug("[checkVersionMigrations] Current editor version", "0.
|
|
41046
|
+
console.debug("[checkVersionMigrations] Current editor version", "0.13.0-RC2");
|
|
41037
41047
|
if (!this.options.ydoc) return;
|
|
41038
41048
|
const metaMap = this.options.ydoc.getMap("meta");
|
|
41039
41049
|
let docVersion = metaMap.get("version");
|
|
@@ -41436,7 +41446,6 @@ initPagination_fn = async function() {
|
|
|
41436
41446
|
if (this.options.isHeadless || !this.extensionService) return;
|
|
41437
41447
|
const pagination = this.options.extensions.find((e) => e.name === "pagination");
|
|
41438
41448
|
if (pagination && this.options.pagination) {
|
|
41439
|
-
console.debug("🔗 [super-editor] Initializing pagination");
|
|
41440
41449
|
const sectionData = await initPaginationData(this);
|
|
41441
41450
|
this.storage.pagination.sectionData = sectionData;
|
|
41442
41451
|
const { state: state2, dispatch } = this.view;
|
|
@@ -42971,7 +42980,7 @@ const OrderedList = Node$1.create({
|
|
|
42971
42980
|
// rendered: false,
|
|
42972
42981
|
},
|
|
42973
42982
|
listId: {
|
|
42974
|
-
|
|
42983
|
+
keepOnSplit: true,
|
|
42975
42984
|
parseDOM: (elem) => elem.getAttribute("data-list-id"),
|
|
42976
42985
|
renderDOM: (attrs) => {
|
|
42977
42986
|
if (!attrs.listId) return {};
|
|
@@ -43008,8 +43017,8 @@ const OrderedList = Node$1.create({
|
|
|
43008
43017
|
},
|
|
43009
43018
|
addCommands() {
|
|
43010
43019
|
return {
|
|
43011
|
-
toggleOrderedList: () => ({
|
|
43012
|
-
return
|
|
43020
|
+
toggleOrderedList: () => ({ tr, editor, chain }) => {
|
|
43021
|
+
return ListHelpers.createNewList({ listType: this, editor, chain });
|
|
43013
43022
|
},
|
|
43014
43023
|
getCurrentList: () => ({ state: state2 }) => {
|
|
43015
43024
|
return findParentNode((node2) => node2.type.name === this.name)(state2.selection);
|
|
@@ -43153,6 +43162,164 @@ const OrderedList = Node$1.create({
|
|
|
43153
43162
|
];
|
|
43154
43163
|
}
|
|
43155
43164
|
});
|
|
43165
|
+
const LinkedStylesPluginKey = new PluginKey("linkedStyles");
|
|
43166
|
+
const LinkedStyles = Extension.create({
|
|
43167
|
+
name: "linkedStyles",
|
|
43168
|
+
priority: 1,
|
|
43169
|
+
// We need this plugin to run before the list plugins
|
|
43170
|
+
addPmPlugins() {
|
|
43171
|
+
return [createLinkedStylesPlugin(this.editor)];
|
|
43172
|
+
},
|
|
43173
|
+
addCommands() {
|
|
43174
|
+
return {
|
|
43175
|
+
setLinkedStyle: (style2) => (params2) => {
|
|
43176
|
+
if (!style2) return;
|
|
43177
|
+
const { tr } = params2;
|
|
43178
|
+
const selection = tr.selection;
|
|
43179
|
+
const { from: from2, to } = selection;
|
|
43180
|
+
if (from2 === to) return;
|
|
43181
|
+
let pos = from2;
|
|
43182
|
+
let paragraphNode = tr.doc.nodeAt(from2);
|
|
43183
|
+
if (paragraphNode.type.name !== "paragraph") {
|
|
43184
|
+
const parentNode2 = findParentNode((node2) => node2.type.name === "paragraph")(tr.selection) || {};
|
|
43185
|
+
pos = parentNode2.pos;
|
|
43186
|
+
paragraphNode = parentNode2.node;
|
|
43187
|
+
}
|
|
43188
|
+
tr.setNodeMarkup(pos, void 0, {
|
|
43189
|
+
...paragraphNode.attrs,
|
|
43190
|
+
styleId: style2.id
|
|
43191
|
+
});
|
|
43192
|
+
}
|
|
43193
|
+
};
|
|
43194
|
+
}
|
|
43195
|
+
});
|
|
43196
|
+
const createLinkedStylesPlugin = (editor) => {
|
|
43197
|
+
return new Plugin({
|
|
43198
|
+
key: LinkedStylesPluginKey,
|
|
43199
|
+
state: {
|
|
43200
|
+
init(_, { doc: doc2, selection }) {
|
|
43201
|
+
if (!editor.converter || editor.options.mode !== "docx") return {};
|
|
43202
|
+
const styles = editor.converter?.linkedStyles || [];
|
|
43203
|
+
return {
|
|
43204
|
+
styles,
|
|
43205
|
+
decorations: generateDecorations(editor.state, styles)
|
|
43206
|
+
};
|
|
43207
|
+
},
|
|
43208
|
+
apply(tr, prev, oldEditorState, newEditorState) {
|
|
43209
|
+
if (!editor.converter || editor.options.mode !== "docx") return { ...prev };
|
|
43210
|
+
let decorations = prev.decorations || DecorationSet.empty;
|
|
43211
|
+
if (tr.docChanged) {
|
|
43212
|
+
const styles = LinkedStylesPluginKey.getState(editor.state).styles;
|
|
43213
|
+
decorations = generateDecorations(newEditorState, styles);
|
|
43214
|
+
}
|
|
43215
|
+
return { ...prev, decorations };
|
|
43216
|
+
}
|
|
43217
|
+
},
|
|
43218
|
+
props: {
|
|
43219
|
+
decorations(state2) {
|
|
43220
|
+
return LinkedStylesPluginKey.getState(state2)?.decorations;
|
|
43221
|
+
}
|
|
43222
|
+
}
|
|
43223
|
+
});
|
|
43224
|
+
};
|
|
43225
|
+
const generateDecorations = (state2, styles) => {
|
|
43226
|
+
const decorations = [];
|
|
43227
|
+
let lastStyleId = null;
|
|
43228
|
+
const doc2 = state2?.doc;
|
|
43229
|
+
doc2.descendants((node2, pos) => {
|
|
43230
|
+
const { name } = node2.type;
|
|
43231
|
+
if (node2?.attrs?.styleId) lastStyleId = node2.attrs.styleId;
|
|
43232
|
+
if (name === "paragraph" && !node2.attrs?.styleId) lastStyleId = null;
|
|
43233
|
+
if (name !== "text") return;
|
|
43234
|
+
const linkedStyle = getLinkedStyle(lastStyleId, styles);
|
|
43235
|
+
if (!linkedStyle) return;
|
|
43236
|
+
const $pos = state2.doc.resolve(pos);
|
|
43237
|
+
const parent = $pos.parent;
|
|
43238
|
+
const styleString = generateLinkedStyleString(linkedStyle, node2, parent);
|
|
43239
|
+
if (!styleString) return;
|
|
43240
|
+
const decoration = Decoration.inline(pos, pos + node2.nodeSize, { style: styleString });
|
|
43241
|
+
decorations.push(decoration);
|
|
43242
|
+
});
|
|
43243
|
+
return DecorationSet.create(doc2, decorations);
|
|
43244
|
+
};
|
|
43245
|
+
const generateLinkedStyleString = (linkedStyle, node2, parent, includeSpacing = true) => {
|
|
43246
|
+
if (!linkedStyle?.definition?.styles) return "";
|
|
43247
|
+
const markValue = {};
|
|
43248
|
+
Object.entries(linkedStyle.definition.styles).forEach(([k, value]) => {
|
|
43249
|
+
const key = kebabCase$1(k);
|
|
43250
|
+
const flattenedMarks = [];
|
|
43251
|
+
node2?.marks?.forEach((n) => {
|
|
43252
|
+
if (n.type.name === "textStyle") {
|
|
43253
|
+
Object.entries(n.attrs).forEach(([styleKey, value2]) => {
|
|
43254
|
+
const parsedKey = kebabCase$1(styleKey);
|
|
43255
|
+
if (!value2) return;
|
|
43256
|
+
flattenedMarks.push({ key: parsedKey, value: value2 });
|
|
43257
|
+
});
|
|
43258
|
+
return;
|
|
43259
|
+
}
|
|
43260
|
+
flattenedMarks.push({ key: n.type.name, value: n.attrs[key] });
|
|
43261
|
+
});
|
|
43262
|
+
const mark = flattenedMarks.find((n) => n.key === key);
|
|
43263
|
+
const hasParentIndent = Object.keys(parent?.attrs?.indent || {});
|
|
43264
|
+
const hasParentSpacing = Object.keys(parent?.attrs?.spacing || {});
|
|
43265
|
+
if (!mark) {
|
|
43266
|
+
if (key === "spacing" && includeSpacing && !hasParentSpacing) ;
|
|
43267
|
+
else if (key === "indent" && includeSpacing && !hasParentIndent) {
|
|
43268
|
+
const { leftIndent, rightIndent, firstLine } = value;
|
|
43269
|
+
if (leftIndent) markValue["margin-left"] = leftIndent + "px";
|
|
43270
|
+
if (rightIndent) markValue["margin-right"] = rightIndent + "px";
|
|
43271
|
+
if (firstLine) markValue["text-indent"] = firstLine + "px";
|
|
43272
|
+
} else if (key === "bold") {
|
|
43273
|
+
markValue["font-weight"] = "bold";
|
|
43274
|
+
} else if (typeof value === "string") markValue[key] = value;
|
|
43275
|
+
}
|
|
43276
|
+
});
|
|
43277
|
+
const final = Object.entries(markValue).map(([key, value]) => `${key}: ${value}`).join(";");
|
|
43278
|
+
return final;
|
|
43279
|
+
};
|
|
43280
|
+
const getLinkedStyle = (styleId, styles = []) => {
|
|
43281
|
+
return styles.find((style2) => style2.id === styleId);
|
|
43282
|
+
};
|
|
43283
|
+
const getSpacingStyleString = (spacing) => {
|
|
43284
|
+
const { lineSpaceBefore, lineSpaceAfter, line } = spacing;
|
|
43285
|
+
return `
|
|
43286
|
+
${lineSpaceBefore ? `margin-top: ${lineSpaceBefore}px;` : ""}
|
|
43287
|
+
${lineSpaceAfter ? `margin-bottom: ${lineSpaceAfter}px;` : ""}
|
|
43288
|
+
${line ? getLineHeightValueString(line, "") : ""}
|
|
43289
|
+
`.trim();
|
|
43290
|
+
};
|
|
43291
|
+
const getMarksStyle = (attrs) => {
|
|
43292
|
+
let styles = "";
|
|
43293
|
+
for (const attr of attrs) {
|
|
43294
|
+
switch (attr.type) {
|
|
43295
|
+
case "bold":
|
|
43296
|
+
styles += `font-weight: bold; `;
|
|
43297
|
+
break;
|
|
43298
|
+
case "italic":
|
|
43299
|
+
styles += `font-style: italic; `;
|
|
43300
|
+
break;
|
|
43301
|
+
case "underline":
|
|
43302
|
+
styles += `text-decoration: underline; `;
|
|
43303
|
+
break;
|
|
43304
|
+
case "highlight":
|
|
43305
|
+
styles += `background-color: ${attr.attrs.color}; `;
|
|
43306
|
+
break;
|
|
43307
|
+
case "textStyle":
|
|
43308
|
+
const { fontFamily: fontFamily2, fontSize: fontSize2 } = attr.attrs;
|
|
43309
|
+
styles += `${fontFamily2 ? `font-family: ${fontFamily2};` : ""} ${fontSize2 ? `font-size: ${fontSize2};` : ""}`;
|
|
43310
|
+
}
|
|
43311
|
+
}
|
|
43312
|
+
return styles.trim();
|
|
43313
|
+
};
|
|
43314
|
+
const getQuickFormatList = (editor) => {
|
|
43315
|
+
if (!editor?.converter) return [];
|
|
43316
|
+
const styles = editor.converter.linkedStyles || [];
|
|
43317
|
+
return styles.filter((style2) => {
|
|
43318
|
+
return style2.type === "paragraph" && style2.definition.attrs;
|
|
43319
|
+
}).sort((a, b) => {
|
|
43320
|
+
return a.definition.attrs?.name.localeCompare(b.definition.attrs?.name);
|
|
43321
|
+
});
|
|
43322
|
+
};
|
|
43156
43323
|
const generateOrderedListIndex = ({ listLevel, lvlText, listNumberingType }) => {
|
|
43157
43324
|
const handler = listIndexMap[listNumberingType];
|
|
43158
43325
|
return handler ? handler(listLevel, lvlText) : null;
|
|
@@ -43213,108 +43380,73 @@ const intToAlpha = (num) => {
|
|
|
43213
43380
|
}
|
|
43214
43381
|
return result;
|
|
43215
43382
|
};
|
|
43216
|
-
|
|
43217
|
-
|
|
43218
|
-
|
|
43219
|
-
|
|
43220
|
-
init(_, state2) {
|
|
43221
|
-
const decorations = [
|
|
43222
|
-
...getListMarkerDecorations(state2),
|
|
43223
|
-
...getListItemStylingFromParagraphProps(state2)
|
|
43224
|
-
];
|
|
43225
|
-
return DecorationSet.create(state2.doc, decorations);
|
|
43226
|
-
},
|
|
43227
|
-
apply(tr, oldDecorationSet, oldState, newState) {
|
|
43228
|
-
if (!tr.docChanged) return oldDecorationSet;
|
|
43229
|
-
const isOrderedListPlugin = tr.getMeta("orderedListMarker");
|
|
43230
|
-
if (isOrderedListPlugin) return oldDecorationSet;
|
|
43231
|
-
const marks = tr.getMeta("splitListItem");
|
|
43232
|
-
const decorations = [
|
|
43233
|
-
...getListMarkerDecorations(newState, marks),
|
|
43234
|
-
...getListItemStylingFromParagraphProps(newState)
|
|
43235
|
-
];
|
|
43236
|
-
return DecorationSet.create(newState.doc, decorations);
|
|
43237
|
-
}
|
|
43238
|
-
},
|
|
43239
|
-
props: {
|
|
43240
|
-
decorations(state2) {
|
|
43241
|
-
return this.getState(state2);
|
|
43242
|
-
}
|
|
43243
|
-
}
|
|
43244
|
-
});
|
|
43245
|
-
}
|
|
43246
|
-
function getListMarkerDecorations(state2, marks = []) {
|
|
43247
|
-
let { doc: doc2, storedMarks } = state2;
|
|
43248
|
-
let decorations = [];
|
|
43249
|
-
if (Array.isArray(storedMarks)) marks.push(...storedMarks);
|
|
43250
|
-
let listItems = findChildren$3(doc2, (node2) => node2.type.name === "listItem");
|
|
43251
|
-
if (!listItems.length) {
|
|
43252
|
-
return decorations;
|
|
43253
|
-
}
|
|
43254
|
-
listItems.forEach(({ node: node2, pos }) => {
|
|
43255
|
-
let textStyleType = getMarkType("textStyle", doc2.type.schema);
|
|
43256
|
-
let textStyleMarks = [...marks.filter((m) => m.type === textStyleType)];
|
|
43257
|
-
let isEmptyListItem = checkListItemEmpty(node2);
|
|
43258
|
-
if (isEmptyListItem && marks.length) {
|
|
43259
|
-
const textMarks = marks.filter((mark) => mark.type === textStyleType);
|
|
43260
|
-
textStyleMarks.push(...textMarks);
|
|
43261
|
-
} else {
|
|
43262
|
-
const itemMarks = getListItemTextStyleMarks(node2, doc2, textStyleType);
|
|
43263
|
-
textStyleMarks.push(...itemMarks);
|
|
43264
|
-
}
|
|
43265
|
-
let fontSize2 = null;
|
|
43266
|
-
let fontFamily2 = null;
|
|
43267
|
-
textStyleMarks.forEach((mark) => {
|
|
43268
|
-
let { attrs: attrs2 } = mark;
|
|
43269
|
-
if (attrs2.fontSize && !fontSize2) {
|
|
43270
|
-
let [value, unit] = parseSizeUnit(attrs2.fontSize);
|
|
43271
|
-
if (!Number.isNaN(value)) {
|
|
43272
|
-
unit = unit ?? "pt";
|
|
43273
|
-
fontSize2 = `${value}${unit}`;
|
|
43274
|
-
}
|
|
43275
|
-
}
|
|
43276
|
-
if (attrs2.fontFamily && !fontFamily2) {
|
|
43277
|
-
fontFamily2 = attrs2.fontFamily;
|
|
43278
|
-
}
|
|
43383
|
+
class ListItemNodeView {
|
|
43384
|
+
constructor(node2, getPos, decorations, editor) {
|
|
43385
|
+
__privateAdd$1(this, _ListItemNodeView_instances);
|
|
43386
|
+
__publicField$1(this, "handleNumberingClick", (event) => {
|
|
43279
43387
|
});
|
|
43280
|
-
|
|
43281
|
-
|
|
43282
|
-
|
|
43283
|
-
|
|
43284
|
-
|
|
43285
|
-
|
|
43286
|
-
|
|
43287
|
-
|
|
43288
|
-
|
|
43289
|
-
|
|
43290
|
-
|
|
43388
|
+
this.node = node2;
|
|
43389
|
+
this.editor = editor;
|
|
43390
|
+
this.decorations = decorations;
|
|
43391
|
+
this.view = editor.view;
|
|
43392
|
+
this.getPos = getPos;
|
|
43393
|
+
this.editor = editor;
|
|
43394
|
+
__privateMethod$1(this, _ListItemNodeView_instances, init_fn2).call(this);
|
|
43395
|
+
}
|
|
43396
|
+
update(node2) {
|
|
43397
|
+
if (node2.type !== this.node.type) return false;
|
|
43398
|
+
this.node = node2;
|
|
43399
|
+
return true;
|
|
43400
|
+
}
|
|
43401
|
+
destroy() {
|
|
43402
|
+
this.numberingDOM.removeEventListener("click", this.handleNumberingClick);
|
|
43403
|
+
}
|
|
43291
43404
|
}
|
|
43292
|
-
|
|
43293
|
-
|
|
43294
|
-
|
|
43295
|
-
|
|
43296
|
-
|
|
43297
|
-
|
|
43298
|
-
|
|
43299
|
-
|
|
43300
|
-
|
|
43301
|
-
|
|
43302
|
-
|
|
43303
|
-
|
|
43304
|
-
|
|
43305
|
-
|
|
43306
|
-
|
|
43307
|
-
|
|
43308
|
-
|
|
43309
|
-
style: style2
|
|
43310
|
-
};
|
|
43311
|
-
}
|
|
43312
|
-
let dec = Decoration.node(pos, pos + node2.nodeSize, spacingAttrs);
|
|
43313
|
-
decorations.push(dec);
|
|
43405
|
+
_ListItemNodeView_instances = /* @__PURE__ */ new WeakSet();
|
|
43406
|
+
init_fn2 = function() {
|
|
43407
|
+
const { attrs } = this.node;
|
|
43408
|
+
const { styleId, listLevel, listNumberingType, lvlText, numId, level, indent: inlineIndent } = attrs;
|
|
43409
|
+
let orderMarker = "";
|
|
43410
|
+
if (listLevel) {
|
|
43411
|
+
orderMarker = generateOrderedListIndex({
|
|
43412
|
+
listLevel,
|
|
43413
|
+
lvlText,
|
|
43414
|
+
listNumberingType
|
|
43415
|
+
});
|
|
43416
|
+
}
|
|
43417
|
+
const pos = this.getPos();
|
|
43418
|
+
const { fontSize: fontSize2, fontFamily: fontFamily2 } = getTextStyleMarksFromLinkedStyles({
|
|
43419
|
+
node: this.node,
|
|
43420
|
+
pos,
|
|
43421
|
+
editor: this.editor
|
|
43314
43422
|
});
|
|
43315
|
-
|
|
43316
|
-
|
|
43317
|
-
|
|
43423
|
+
const defs = getListItemStyleDefinitions({ styleId, node: this.node, numId, level, editor: this.editor });
|
|
43424
|
+
const visibleIndent = getVisibleIndent(defs.stylePpr, defs.numDefPpr, inlineIndent);
|
|
43425
|
+
console.debug("VISIBLEINDENT", visibleIndent, "\n\n\n\n");
|
|
43426
|
+
let absoluteLeft = visibleIndent.left - (visibleIndent.hanging || 0);
|
|
43427
|
+
if (!absoluteLeft && absoluteLeft !== 0) absoluteLeft = 0;
|
|
43428
|
+
this.dom = document.createElement("li");
|
|
43429
|
+
this.dom.className = "sd-editor-list-item-node-view";
|
|
43430
|
+
this.dom.style.fontSize = fontSize2;
|
|
43431
|
+
this.dom.style.fontFamily = fontFamily2;
|
|
43432
|
+
this.dom.setAttribute("data-marker-type", orderMarker);
|
|
43433
|
+
this.numberingDOM = document.createElement("span");
|
|
43434
|
+
this.numberingDOM.className = "sd-editor-list-item-numbering";
|
|
43435
|
+
this.numberingDOM.textContent = orderMarker;
|
|
43436
|
+
this.numberingDOM.setAttribute("contenteditable", "false");
|
|
43437
|
+
this.numberingDOM.addEventListener("click", this.handleNumberingClick);
|
|
43438
|
+
this.contentDOM = document.createElement("p");
|
|
43439
|
+
this.contentDOM.className = "sd-editor-list-item-content-dom";
|
|
43440
|
+
let contentLeft = visibleIndent.left;
|
|
43441
|
+
if (visibleIndent.left === absoluteLeft) {
|
|
43442
|
+
contentLeft = 48;
|
|
43443
|
+
}
|
|
43444
|
+
this.contentDOM.style.marginLeft = `${contentLeft}px`;
|
|
43445
|
+
this.numberingDOM.style.left = `${absoluteLeft}px`;
|
|
43446
|
+
this.dom.appendChild(this.numberingDOM);
|
|
43447
|
+
this.dom.appendChild(this.contentDOM);
|
|
43448
|
+
};
|
|
43449
|
+
function getListItemTextStyleMarks(listItem, markType) {
|
|
43318
43450
|
let textStyleMarks = [];
|
|
43319
43451
|
listItem.forEach((childNode) => {
|
|
43320
43452
|
if (childNode.type.name !== "paragraph") return;
|
|
@@ -43329,9 +43461,57 @@ function getListItemTextStyleMarks(listItem, doc2, markType) {
|
|
|
43329
43461
|
});
|
|
43330
43462
|
return textStyleMarks;
|
|
43331
43463
|
}
|
|
43332
|
-
function
|
|
43333
|
-
|
|
43334
|
-
|
|
43464
|
+
function getTextStyleMarksFromLinkedStyles({ node: node2, pos, editor }) {
|
|
43465
|
+
const { font: defaultFont, size: defaultSize } = getStylesFromLinkedStyles({ node: node2, pos, editor });
|
|
43466
|
+
const textStyleType = getMarkType("textStyle", editor.schema);
|
|
43467
|
+
const allMarks = getListItemTextStyleMarks(node2, textStyleType);
|
|
43468
|
+
const styleMarks = allMarks.filter((m) => m.type === textStyleType);
|
|
43469
|
+
const sizeMark = styleMarks.find((m) => m.attrs.fontSize);
|
|
43470
|
+
const familyMark = styleMarks.find((m) => m.attrs.fontFamily);
|
|
43471
|
+
const fontSize2 = sizeMark ? (() => {
|
|
43472
|
+
const [value, unit = "pt"] = parseSizeUnit(sizeMark.attrs.fontSize);
|
|
43473
|
+
return Number.isNaN(value) ? defaultSize : `${value}${unit}`;
|
|
43474
|
+
})() : defaultSize;
|
|
43475
|
+
const fontFamily2 = familyMark?.attrs.fontFamily ?? defaultFont;
|
|
43476
|
+
return { fontSize: fontSize2, fontFamily: fontFamily2 };
|
|
43477
|
+
}
|
|
43478
|
+
const getStylesFromLinkedStyles = ({ node: node2, pos, editor }) => {
|
|
43479
|
+
const { state: state2 } = editor.view;
|
|
43480
|
+
const linkedStyles = LinkedStylesPluginKey.getState(state2)?.decorations;
|
|
43481
|
+
const decorationsInPlace = linkedStyles?.find(pos, pos + node2.nodeSize);
|
|
43482
|
+
const styleDeco = decorationsInPlace?.find((dec) => dec.type.attrs?.style);
|
|
43483
|
+
const style2 = styleDeco?.type.attrs?.style;
|
|
43484
|
+
const stylesArray = style2?.split(";") || [];
|
|
43485
|
+
const fontSizeFromStyles = stylesArray.find((s) => s.includes("font-size"))?.split(":")[1].trim();
|
|
43486
|
+
const fontFamilyFromStyles = stylesArray.find((s) => s.includes("font-family"))?.split(":")[1].trim();
|
|
43487
|
+
return {
|
|
43488
|
+
font: fontFamilyFromStyles,
|
|
43489
|
+
size: fontSizeFromStyles
|
|
43490
|
+
};
|
|
43491
|
+
};
|
|
43492
|
+
const getVisibleIndent = (stylePpr, numDefPpr, inlineIndent) => {
|
|
43493
|
+
console.debug("[getVisibleIndent] inlineIndent", inlineIndent);
|
|
43494
|
+
const styleIndentTag = stylePpr?.elements?.find((el) => el.name === "w:ind") || {};
|
|
43495
|
+
const styleIndent = parseIndentElement(styleIndentTag);
|
|
43496
|
+
console.debug("[getVisibleIndent] styleIndent", styleIndent, styleIndentTag);
|
|
43497
|
+
const numDefIndentTag = numDefPpr?.elements?.find((el) => el.name === "w:ind") || {};
|
|
43498
|
+
const numDefIndent = parseIndentElement(numDefIndentTag);
|
|
43499
|
+
console.debug("[getVisibleIndent] numDefIndent", numDefIndent, numDefIndentTag, "\n\n");
|
|
43500
|
+
const indent = combineIndents(styleIndent, numDefIndent);
|
|
43501
|
+
return combineIndents(indent, inlineIndent);
|
|
43502
|
+
};
|
|
43503
|
+
const getListItemStyleDefinitions = ({ styleId, numId, level, editor }) => {
|
|
43504
|
+
const docx = editor?.converter?.convertedXml;
|
|
43505
|
+
const styleDefinition = getStyleTagFromStyleId(styleId, docx);
|
|
43506
|
+
const stylePpr = styleDefinition?.elements.find((el) => el.name === "w:pPr");
|
|
43507
|
+
const abstractDefinition = getAbstractDefinition(numId, docx);
|
|
43508
|
+
const numDefinition = getDefinitionForLevel(abstractDefinition, level);
|
|
43509
|
+
const numDefPpr = numDefinition?.elements.find((el) => el.name === "w:pPr");
|
|
43510
|
+
return {
|
|
43511
|
+
stylePpr,
|
|
43512
|
+
numDefPpr
|
|
43513
|
+
};
|
|
43514
|
+
};
|
|
43335
43515
|
const ListItem = Node$1.create({
|
|
43336
43516
|
name: "listItem",
|
|
43337
43517
|
content: "paragraph* block*",
|
|
@@ -43353,6 +43533,15 @@ const ListItem = Node$1.create({
|
|
|
43353
43533
|
renderDOM({ htmlAttributes }) {
|
|
43354
43534
|
return ["li", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
|
|
43355
43535
|
},
|
|
43536
|
+
/**
|
|
43537
|
+
* Important: The listItem node uses a custom node view.
|
|
43538
|
+
* @returns {import('@core/NodeView.js').NodeView}
|
|
43539
|
+
*/
|
|
43540
|
+
addNodeView() {
|
|
43541
|
+
return ({ node: node2, editor, getPos, decorations }) => {
|
|
43542
|
+
return new ListItemNodeView(node2, getPos, decorations, editor);
|
|
43543
|
+
};
|
|
43544
|
+
},
|
|
43356
43545
|
addAttributes() {
|
|
43357
43546
|
return {
|
|
43358
43547
|
// Virtual attribute.
|
|
@@ -43377,6 +43566,7 @@ const ListItem = Node$1.create({
|
|
|
43377
43566
|
},
|
|
43378
43567
|
lvlText: {
|
|
43379
43568
|
default: null,
|
|
43569
|
+
keepOnSplit: true,
|
|
43380
43570
|
parseDOM: (elem) => elem.getAttribute("data-lvl-text"),
|
|
43381
43571
|
renderDOM: (attrs) => {
|
|
43382
43572
|
if (!attrs.lvlText) return {};
|
|
@@ -43387,6 +43577,7 @@ const ListItem = Node$1.create({
|
|
|
43387
43577
|
},
|
|
43388
43578
|
listNumberingType: {
|
|
43389
43579
|
default: null,
|
|
43580
|
+
keepOnSplit: true,
|
|
43390
43581
|
parseDOM: (elem) => elem.getAttribute("data-num-fmt"),
|
|
43391
43582
|
renderDOM: (attrs) => {
|
|
43392
43583
|
if (!attrs.listNumberingType) return {};
|
|
@@ -43397,6 +43588,7 @@ const ListItem = Node$1.create({
|
|
|
43397
43588
|
},
|
|
43398
43589
|
listLevel: {
|
|
43399
43590
|
default: null,
|
|
43591
|
+
keepOnSplit: true,
|
|
43400
43592
|
parseDOM: (elem) => {
|
|
43401
43593
|
let listLevel = elem.getAttribute("data-list-level");
|
|
43402
43594
|
try {
|
|
@@ -43414,52 +43606,61 @@ const ListItem = Node$1.create({
|
|
|
43414
43606
|
},
|
|
43415
43607
|
// JC = justification. Expect left, right, center
|
|
43416
43608
|
lvlJc: {
|
|
43609
|
+
keepOnSplit: true,
|
|
43417
43610
|
default: null,
|
|
43418
43611
|
rendered: false
|
|
43419
43612
|
},
|
|
43420
43613
|
// This will contain indentation and space info.
|
|
43421
43614
|
// ie: w:left (left indent), w:hanging (hanging indent)
|
|
43422
43615
|
listParagraphProperties: {
|
|
43616
|
+
keepOnSplit: true,
|
|
43423
43617
|
default: null,
|
|
43424
43618
|
rendered: false
|
|
43425
43619
|
},
|
|
43426
43620
|
// This will contain run properties for the list item
|
|
43427
43621
|
listRunProperties: {
|
|
43622
|
+
keepOnSplit: true,
|
|
43428
43623
|
default: null,
|
|
43429
43624
|
rendered: false
|
|
43430
43625
|
},
|
|
43431
43626
|
numId: {
|
|
43627
|
+
keepOnSplit: true,
|
|
43432
43628
|
default: null,
|
|
43433
|
-
parseDOM: (elem) => elem.getAttribute("data-num-id")
|
|
43434
|
-
},
|
|
43435
|
-
attributes: {
|
|
43436
43629
|
rendered: false
|
|
43437
43630
|
},
|
|
43438
|
-
|
|
43439
|
-
|
|
43440
|
-
|
|
43441
|
-
|
|
43442
|
-
return {
|
|
43443
|
-
"data-font-size": attrs.importedFontSize
|
|
43444
|
-
};
|
|
43445
|
-
}
|
|
43631
|
+
numPrType: {
|
|
43632
|
+
rendered: false,
|
|
43633
|
+
default: null,
|
|
43634
|
+
keepOnSplit: true
|
|
43446
43635
|
},
|
|
43447
|
-
|
|
43448
|
-
|
|
43449
|
-
|
|
43450
|
-
|
|
43451
|
-
|
|
43452
|
-
|
|
43453
|
-
|
|
43454
|
-
|
|
43636
|
+
level: {
|
|
43637
|
+
default: null,
|
|
43638
|
+
rendered: false,
|
|
43639
|
+
keepOnSplit: true
|
|
43640
|
+
},
|
|
43641
|
+
attributes: {
|
|
43642
|
+
keepOnSplit: true,
|
|
43643
|
+
rendered: false
|
|
43455
43644
|
},
|
|
43456
43645
|
spacing: {
|
|
43646
|
+
keepOnSplit: true,
|
|
43457
43647
|
default: null,
|
|
43458
43648
|
rendered: false
|
|
43459
43649
|
},
|
|
43460
43650
|
indent: {
|
|
43651
|
+
keepOnSplit: true,
|
|
43461
43652
|
default: null,
|
|
43462
43653
|
rendered: false
|
|
43654
|
+
},
|
|
43655
|
+
markerStyle: {
|
|
43656
|
+
default: null,
|
|
43657
|
+
rendered: false,
|
|
43658
|
+
keepOnSplit: true
|
|
43659
|
+
},
|
|
43660
|
+
styleId: {
|
|
43661
|
+
rendered: false,
|
|
43662
|
+
keepOnSplit: true,
|
|
43663
|
+
keepOnSplit: true
|
|
43463
43664
|
}
|
|
43464
43665
|
};
|
|
43465
43666
|
},
|
|
@@ -43468,49 +43669,21 @@ const ListItem = Node$1.create({
|
|
|
43468
43669
|
getCurrentListNode: () => ({ state: state2 }) => {
|
|
43469
43670
|
return findParentNode((node2) => node2.type.name === this.name)(state2.selection);
|
|
43470
43671
|
},
|
|
43471
|
-
increaseListIndent: () => ({ commands: commands2 }) => {
|
|
43472
|
-
|
|
43473
|
-
|
|
43474
|
-
}
|
|
43475
|
-
commands2.updateNodeStyle();
|
|
43476
|
-
commands2.updateOrderedListStyleType();
|
|
43477
|
-
return true;
|
|
43478
|
-
},
|
|
43479
|
-
decreaseListIndent: () => ({ commands: commands2 }) => {
|
|
43480
|
-
const currentList = commands2.getCurrentList();
|
|
43481
|
-
const depth = currentList?.depth;
|
|
43482
|
-
if (depth === 1) return false;
|
|
43483
|
-
if (!commands2.liftListItem(this.name)) {
|
|
43484
|
-
return true;
|
|
43485
|
-
}
|
|
43486
|
-
if (!commands2.updateNodeStyle()) {
|
|
43487
|
-
return false;
|
|
43488
|
-
}
|
|
43489
|
-
const currentNode = commands2.getCurrentListNode();
|
|
43490
|
-
const currentNodeIndex = currentList?.node?.children.findIndex((child) => child === currentNode.node);
|
|
43491
|
-
const nextNodePos = currentNode?.pos + currentNode?.node.nodeSize;
|
|
43492
|
-
const followingNodes = currentList?.node?.children.slice(currentNodeIndex + 1) || [];
|
|
43493
|
-
commands2.updateOrderedListStyleType();
|
|
43494
|
-
commands2.restartListNodes(followingNodes, nextNodePos);
|
|
43495
|
-
return true;
|
|
43672
|
+
increaseListIndent: () => ({ commands: commands2, chain, editor }) => {
|
|
43673
|
+
const node2 = commands2.getCurrentListNode();
|
|
43674
|
+
return ListHelpers.indentListItem({ editor, chain, node: node2 });
|
|
43496
43675
|
},
|
|
43497
|
-
|
|
43498
|
-
|
|
43499
|
-
|
|
43500
|
-
if (!list) return false;
|
|
43501
|
-
const firstNodeAttrs = list?.node.children[0]?.attrs;
|
|
43502
|
-
const newPos = tr.mapping.map(current.pos);
|
|
43503
|
-
tr.setNodeMarkup(newPos, void 0, {
|
|
43504
|
-
...firstNodeAttrs
|
|
43505
|
-
});
|
|
43506
|
-
return true;
|
|
43676
|
+
decreaseListIndent: () => ({ commands: commands2, chain, editor }) => {
|
|
43677
|
+
const node2 = commands2.getCurrentListNode();
|
|
43678
|
+
return ListHelpers.outdentListItem({ editor, chain, node: node2 });
|
|
43507
43679
|
}
|
|
43508
43680
|
};
|
|
43509
43681
|
},
|
|
43510
43682
|
addShortcuts() {
|
|
43511
43683
|
return {
|
|
43512
43684
|
Enter: () => {
|
|
43513
|
-
|
|
43685
|
+
const node2 = this.editor.commands.getCurrentListNode();
|
|
43686
|
+
return this.editor.commands.splitListItem(this.name, node2);
|
|
43514
43687
|
},
|
|
43515
43688
|
"Shift-Enter": () => {
|
|
43516
43689
|
return this.editor.commands.first(({ commands: commands2 }) => [
|
|
@@ -43525,180 +43698,8 @@ const ListItem = Node$1.create({
|
|
|
43525
43698
|
return this.editor.commands.decreaseListIndent();
|
|
43526
43699
|
}
|
|
43527
43700
|
};
|
|
43528
|
-
},
|
|
43529
|
-
addPmPlugins() {
|
|
43530
|
-
return [styledListMarker()];
|
|
43531
43701
|
}
|
|
43532
43702
|
});
|
|
43533
|
-
const LinkedStylesPluginKey = new PluginKey("linkedStyles");
|
|
43534
|
-
const LinkedStyles = Extension.create({
|
|
43535
|
-
name: "linkedStyles",
|
|
43536
|
-
addPmPlugins() {
|
|
43537
|
-
return [createLinkedStylesPlugin(this.editor)];
|
|
43538
|
-
},
|
|
43539
|
-
addCommands() {
|
|
43540
|
-
return {
|
|
43541
|
-
setLinkedStyle: (style2) => (params2) => {
|
|
43542
|
-
if (!style2) return;
|
|
43543
|
-
const { tr } = params2;
|
|
43544
|
-
const selection = tr.selection;
|
|
43545
|
-
const { from: from2, to } = selection;
|
|
43546
|
-
if (from2 === to) return;
|
|
43547
|
-
let pos = from2;
|
|
43548
|
-
let paragraphNode = tr.doc.nodeAt(from2);
|
|
43549
|
-
if (paragraphNode.type.name !== "paragraph") {
|
|
43550
|
-
const parentNode2 = findParentNode((node2) => node2.type.name === "paragraph")(tr.selection) || {};
|
|
43551
|
-
pos = parentNode2.pos;
|
|
43552
|
-
paragraphNode = parentNode2.node;
|
|
43553
|
-
}
|
|
43554
|
-
tr.setNodeMarkup(pos, void 0, {
|
|
43555
|
-
...paragraphNode.attrs,
|
|
43556
|
-
styleId: style2.id
|
|
43557
|
-
});
|
|
43558
|
-
}
|
|
43559
|
-
};
|
|
43560
|
-
}
|
|
43561
|
-
});
|
|
43562
|
-
const createLinkedStylesPlugin = (editor) => {
|
|
43563
|
-
return new Plugin({
|
|
43564
|
-
key: LinkedStylesPluginKey,
|
|
43565
|
-
state: {
|
|
43566
|
-
init(_, { doc: doc2, selection }) {
|
|
43567
|
-
if (!editor.converter || editor.options.mode !== "docx") return {};
|
|
43568
|
-
const styles = editor.converter?.linkedStyles || [];
|
|
43569
|
-
return {
|
|
43570
|
-
styles,
|
|
43571
|
-
decorations: generateDecorations(editor.state, styles)
|
|
43572
|
-
};
|
|
43573
|
-
},
|
|
43574
|
-
apply(tr, prev, oldEditorState, newEditorState) {
|
|
43575
|
-
if (!editor.converter || editor.options.mode !== "docx") return { ...prev };
|
|
43576
|
-
let decorations = prev.decorations || DecorationSet.empty;
|
|
43577
|
-
if (tr.docChanged) {
|
|
43578
|
-
const styles = LinkedStylesPluginKey.getState(editor.state).styles;
|
|
43579
|
-
decorations = generateDecorations(newEditorState, styles);
|
|
43580
|
-
}
|
|
43581
|
-
return { ...prev, decorations };
|
|
43582
|
-
}
|
|
43583
|
-
},
|
|
43584
|
-
props: {
|
|
43585
|
-
decorations(state2) {
|
|
43586
|
-
return LinkedStylesPluginKey.getState(state2)?.decorations;
|
|
43587
|
-
}
|
|
43588
|
-
}
|
|
43589
|
-
});
|
|
43590
|
-
};
|
|
43591
|
-
const generateDecorations = (state2, styles) => {
|
|
43592
|
-
const decorations = [];
|
|
43593
|
-
let lastStyleId = null;
|
|
43594
|
-
const doc2 = state2?.doc;
|
|
43595
|
-
doc2.descendants((node2, pos) => {
|
|
43596
|
-
const { name } = node2.type;
|
|
43597
|
-
if (node2?.attrs?.styleId) lastStyleId = node2.attrs.styleId;
|
|
43598
|
-
if (name === "paragraph" && !node2.attrs?.styleId) lastStyleId = null;
|
|
43599
|
-
if (name !== "text") return;
|
|
43600
|
-
const linkedStyle = getLinkedStyle(lastStyleId, styles);
|
|
43601
|
-
if (!linkedStyle) return;
|
|
43602
|
-
const $pos = state2.doc.resolve(pos);
|
|
43603
|
-
const parent = $pos.parent;
|
|
43604
|
-
const styleString = generateLinkedStyleString(linkedStyle, node2, parent);
|
|
43605
|
-
if (!styleString) return;
|
|
43606
|
-
const decoration = Decoration.inline(pos, pos + node2.nodeSize, { style: styleString });
|
|
43607
|
-
decorations.push(decoration);
|
|
43608
|
-
});
|
|
43609
|
-
return DecorationSet.create(doc2, decorations);
|
|
43610
|
-
};
|
|
43611
|
-
const generateLinkedStyleString = (linkedStyle, node2, parent, includeSpacing = true) => {
|
|
43612
|
-
if (!linkedStyle?.definition?.styles) return "";
|
|
43613
|
-
const markValue = {};
|
|
43614
|
-
Object.entries(linkedStyle.definition.styles).forEach(([k, value]) => {
|
|
43615
|
-
const key = kebabCase$1(k);
|
|
43616
|
-
const flattenedMarks = [];
|
|
43617
|
-
node2?.marks?.forEach((n) => {
|
|
43618
|
-
if (n.type.name === "textStyle") {
|
|
43619
|
-
Object.entries(n.attrs).forEach(([styleKey, value2]) => {
|
|
43620
|
-
const parsedKey = kebabCase$1(styleKey);
|
|
43621
|
-
if (!value2) return;
|
|
43622
|
-
flattenedMarks.push({ key: parsedKey, value: value2 });
|
|
43623
|
-
});
|
|
43624
|
-
return;
|
|
43625
|
-
}
|
|
43626
|
-
flattenedMarks.push({ key: n.type.name, value: n.attrs[key] });
|
|
43627
|
-
});
|
|
43628
|
-
const mark = flattenedMarks.find((n) => n.key === key);
|
|
43629
|
-
const hasParentIndent = Object.keys(parent?.attrs?.indent || {});
|
|
43630
|
-
const hasParentSpacing = Object.keys(parent?.attrs?.spacing || {});
|
|
43631
|
-
if (!mark) {
|
|
43632
|
-
if (key === "spacing" && includeSpacing && !hasParentSpacing) {
|
|
43633
|
-
const space = getSpacingStyle(value);
|
|
43634
|
-
Object.entries(space).forEach(([k2, v]) => {
|
|
43635
|
-
markValue[k2] = v;
|
|
43636
|
-
});
|
|
43637
|
-
} else if (key === "indent" && includeSpacing && !hasParentIndent) {
|
|
43638
|
-
const { leftIndent, rightIndent, firstLine } = value;
|
|
43639
|
-
if (leftIndent) markValue["margin-left"] = leftIndent + "px";
|
|
43640
|
-
if (rightIndent) markValue["margin-right"] = rightIndent + "px";
|
|
43641
|
-
if (firstLine) markValue["text-indent"] = firstLine + "px";
|
|
43642
|
-
} else if (key === "bold") {
|
|
43643
|
-
markValue["font-weight"] = "bold";
|
|
43644
|
-
} else {
|
|
43645
|
-
markValue[key] = value;
|
|
43646
|
-
}
|
|
43647
|
-
}
|
|
43648
|
-
});
|
|
43649
|
-
return Object.entries(markValue).map(([key, value]) => `${key}: ${value}`).join(";");
|
|
43650
|
-
};
|
|
43651
|
-
const getLinkedStyle = (styleId, styles = []) => {
|
|
43652
|
-
return styles.find((style2) => style2.id === styleId);
|
|
43653
|
-
};
|
|
43654
|
-
const getSpacingStyle = (spacing) => {
|
|
43655
|
-
const { lineSpaceBefore, lineSpaceAfter, line, lineRule } = spacing;
|
|
43656
|
-
return {
|
|
43657
|
-
"margin-top": lineSpaceBefore + "px",
|
|
43658
|
-
"margin-bottom": lineSpaceAfter + "px",
|
|
43659
|
-
...getLineHeightValueString(line, "", lineRule, true)
|
|
43660
|
-
};
|
|
43661
|
-
};
|
|
43662
|
-
const getSpacingStyleString = (spacing) => {
|
|
43663
|
-
const { lineSpaceBefore, lineSpaceAfter, line } = spacing;
|
|
43664
|
-
return `
|
|
43665
|
-
${lineSpaceBefore ? `margin-top: ${lineSpaceBefore}px;` : ""}
|
|
43666
|
-
${lineSpaceAfter ? `margin-bottom: ${lineSpaceAfter}px;` : ""}
|
|
43667
|
-
${line ? getLineHeightValueString(line, "") : ""}
|
|
43668
|
-
`.trim();
|
|
43669
|
-
};
|
|
43670
|
-
const getMarksStyle = (attrs) => {
|
|
43671
|
-
let styles = "";
|
|
43672
|
-
for (const attr of attrs) {
|
|
43673
|
-
switch (attr.type) {
|
|
43674
|
-
case "bold":
|
|
43675
|
-
styles += `font-weight: bold; `;
|
|
43676
|
-
break;
|
|
43677
|
-
case "italic":
|
|
43678
|
-
styles += `font-style: italic; `;
|
|
43679
|
-
break;
|
|
43680
|
-
case "underline":
|
|
43681
|
-
styles += `text-decoration: underline; `;
|
|
43682
|
-
break;
|
|
43683
|
-
case "highlight":
|
|
43684
|
-
styles += `background-color: ${attr.attrs.color}; `;
|
|
43685
|
-
break;
|
|
43686
|
-
case "textStyle":
|
|
43687
|
-
const { fontFamily: fontFamily2, fontSize: fontSize2 } = attr.attrs;
|
|
43688
|
-
styles += `${fontFamily2 ? `font-family: ${fontFamily2};` : ""} ${fontSize2 ? `font-size: ${fontSize2};` : ""}`;
|
|
43689
|
-
}
|
|
43690
|
-
}
|
|
43691
|
-
return styles.trim();
|
|
43692
|
-
};
|
|
43693
|
-
const getQuickFormatList = (editor) => {
|
|
43694
|
-
if (!editor?.converter) return [];
|
|
43695
|
-
const styles = editor.converter.linkedStyles || [];
|
|
43696
|
-
return styles.filter((style2) => {
|
|
43697
|
-
return style2.type === "paragraph" && style2.definition.attrs;
|
|
43698
|
-
}).sort((a, b) => {
|
|
43699
|
-
return a.definition.attrs?.name.localeCompare(b.definition.attrs?.name);
|
|
43700
|
-
});
|
|
43701
|
-
};
|
|
43702
43703
|
const getDefaultSpacing = () => ({
|
|
43703
43704
|
lineSpaceAfter: 0,
|
|
43704
43705
|
lineSpaceBefore: 0,
|
|
@@ -43751,9 +43752,13 @@ const Paragraph = Node$1.create({
|
|
|
43751
43752
|
}
|
|
43752
43753
|
},
|
|
43753
43754
|
indent: {
|
|
43755
|
+
default: null,
|
|
43754
43756
|
renderDOM: ({ indent }) => {
|
|
43755
43757
|
if (!indent) return {};
|
|
43756
43758
|
const { left: left2, right: right2, firstLine, hanging } = indent;
|
|
43759
|
+
if (indent && Object.values(indent).every((v) => v === 0)) {
|
|
43760
|
+
return {};
|
|
43761
|
+
}
|
|
43757
43762
|
let style2 = "";
|
|
43758
43763
|
if (left2) style2 += `margin-left: ${left2}px;`;
|
|
43759
43764
|
if (right2) style2 += `margin-right: ${right2}px;`;
|
|
@@ -44100,8 +44105,8 @@ const getTabDecorations = (state2, view) => {
|
|
|
44100
44105
|
const prevNodeSize = $pos.nodeBefore?.nodeSize || 0;
|
|
44101
44106
|
let textWidth = 0;
|
|
44102
44107
|
try {
|
|
44103
|
-
state2.doc.nodesBetween(pos - prevNodeSize - 1, pos - 1, (
|
|
44104
|
-
if (
|
|
44108
|
+
state2.doc.nodesBetween(pos - prevNodeSize - 1, pos - 1, (node3, nodePos) => {
|
|
44109
|
+
if (node3.isText && node3.textContent !== " ") {
|
|
44105
44110
|
const textWidthForNode = calcTextWidth(view, nodePos);
|
|
44106
44111
|
textWidth += textWidthForNode;
|
|
44107
44112
|
}
|
|
@@ -47369,8 +47374,8 @@ function findFirstFieldAnnotationByFieldId(fieldId, state2) {
|
|
|
47369
47374
|
}
|
|
47370
47375
|
function findNode(node2, predicate) {
|
|
47371
47376
|
let found2 = null;
|
|
47372
|
-
node2.descendants((
|
|
47373
|
-
if (predicate(
|
|
47377
|
+
node2.descendants((node3, pos) => {
|
|
47378
|
+
if (predicate(node3)) found2 = { node: node3, pos };
|
|
47374
47379
|
if (found2) return false;
|
|
47375
47380
|
});
|
|
47376
47381
|
return found2;
|
|
@@ -52681,12 +52686,17 @@ const getHeaderFooterId = (currentPageNumber, sectionType, editor, node2 = null)
|
|
|
52681
52686
|
}
|
|
52682
52687
|
}
|
|
52683
52688
|
}
|
|
52684
|
-
|
|
52689
|
+
const { titlePg } = editor.converter.headerIds;
|
|
52690
|
+
if (sectionType === "headerIds" && titlePg && !sectionIds.first && currentPageNumber === 1) {
|
|
52691
|
+
return null;
|
|
52692
|
+
}
|
|
52685
52693
|
const even = sectionIds.even;
|
|
52686
52694
|
const odd = sectionIds.odd;
|
|
52687
52695
|
const first2 = sectionIds.first;
|
|
52688
52696
|
const defaultHeader = sectionIds.default;
|
|
52689
|
-
if (
|
|
52697
|
+
if (titlePg && sectionIds.first && currentPageNumber === 1) {
|
|
52698
|
+
return first2;
|
|
52699
|
+
}
|
|
52690
52700
|
let sectionId = sectionIds.default;
|
|
52691
52701
|
if (currentPageNumber === 1) sectionId = defaultHeader;
|
|
52692
52702
|
if (alternateHeaders) {
|
|
@@ -52789,7 +52799,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
|
|
|
52789
52799
|
}
|
|
52790
52800
|
if (isHardBreakNode || shouldAddPageBreak) {
|
|
52791
52801
|
const $currentPos = view.state.doc.resolve(currentPos);
|
|
52792
|
-
const tableRow = findParentNodeClosestToPos($currentPos, (
|
|
52802
|
+
const tableRow = findParentNodeClosestToPos($currentPos, (node3) => node3.type.name === "tableRow");
|
|
52793
52803
|
if (tableRow) {
|
|
52794
52804
|
currentNode = tableRow.node;
|
|
52795
52805
|
currentPos = tableRow.pos;
|
|
@@ -58985,13 +58995,13 @@ const commonVariables$2 = {
|
|
|
58985
58995
|
heightHuge: "46px"
|
|
58986
58996
|
};
|
|
58987
58997
|
const {
|
|
58988
|
-
fontSize
|
|
58998
|
+
fontSize,
|
|
58989
58999
|
fontFamily,
|
|
58990
59000
|
lineHeight
|
|
58991
59001
|
} = commonVariables$2;
|
|
58992
59002
|
const globalStyle = c$1("body", `
|
|
58993
59003
|
margin: 0;
|
|
58994
|
-
font-size: ${fontSize
|
|
59004
|
+
font-size: ${fontSize};
|
|
58995
59005
|
font-family: ${fontFamily};
|
|
58996
59006
|
line-height: ${lineHeight};
|
|
58997
59007
|
-webkit-text-size-adjust: 100%;
|