@harbour-enterprises/superdoc 0.12.36-next.7 → 0.12.36-next.9
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-X2sJyEa5.cjs → super-editor.es-DwRDhfnV.cjs} +329 -29
- package/dist/chunks/{super-editor.es-u7Bq9xUN.es.js → super-editor.es-TyCJrNNL.es.js} +329 -29
- package/dist/style.css +13 -0
- package/dist/super-editor/ai-writer.es.js +2 -2
- package/dist/super-editor/chunks/{converter-wbU2SP4i.js → converter-C4AZvpwi.js} +104 -7
- package/dist/super-editor/chunks/{docx-zipper-BL3thpAA.js → docx-zipper-CusiAenZ.js} +1 -1
- package/dist/super-editor/chunks/{editor-CrElllON.js → editor-BAC6cXVa.js} +227 -24
- package/dist/super-editor/chunks/{toolbar-DJBp5g7l.js → toolbar-BLLgDAAG.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.map +1 -1
- package/dist/super-editor/core/Schema.d.ts +2 -2
- package/dist/super-editor/core/helpers/findWordBounds.d.ts +5 -0
- package/dist/super-editor/core/helpers/findWordBounds.d.ts.map +1 -0
- package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
- package/dist/super-editor/core/super-converter/v2/importer/autoPageNumberImporter.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/page-number/page-number.d.ts +10 -0
- package/dist/super-editor/extensions/page-number/page-number.d.ts.map +1 -1
- package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +2 -1
- package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
- package/dist/super-editor/file-zipper.es.js +1 -1
- package/dist/super-editor/style.css +13 -0
- package/dist/super-editor/super-editor.es.js +6 -6
- 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 +2 -2
- package/dist/superdoc.es.js +3 -3
- package/dist/superdoc.umd.js +330 -30
- package/dist/superdoc.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -18862,7 +18862,9 @@ function exportSchemaToJson(params2) {
|
|
|
18862
18862
|
shapeContainer: translateShapeContainer,
|
|
18863
18863
|
shapeTextbox: translateShapeTextbox,
|
|
18864
18864
|
contentBlock: translateContentBlock,
|
|
18865
|
-
structuredContent: translateStructuredContent
|
|
18865
|
+
structuredContent: translateStructuredContent,
|
|
18866
|
+
"page-number": translatePageNumberNode,
|
|
18867
|
+
"total-page-number": translateTotalPageNumberNode
|
|
18866
18868
|
};
|
|
18867
18869
|
if (!router[type2]) {
|
|
18868
18870
|
console.error("No translation function found for node type:", type2);
|
|
@@ -20559,6 +20561,81 @@ function translateStructuredContent(params2) {
|
|
|
20559
20561
|
elements: nodeElements
|
|
20560
20562
|
};
|
|
20561
20563
|
}
|
|
20564
|
+
const translatePageNumberNode = (params2) => {
|
|
20565
|
+
const outputMarks = processOutputMarks(params2.node.attrs?.marksAsAttrs || []);
|
|
20566
|
+
return getAutoPageJson("PAGE", outputMarks);
|
|
20567
|
+
};
|
|
20568
|
+
const translateTotalPageNumberNode = (params2) => {
|
|
20569
|
+
const outputMarks = processOutputMarks(params2.node.attrs?.marksAsAttrs || []);
|
|
20570
|
+
return getAutoPageJson("NUMPAGES", outputMarks);
|
|
20571
|
+
};
|
|
20572
|
+
const getAutoPageJson = (type2, outputMarks = []) => {
|
|
20573
|
+
return [
|
|
20574
|
+
{
|
|
20575
|
+
"name": "w:r",
|
|
20576
|
+
"elements": [
|
|
20577
|
+
{
|
|
20578
|
+
"name": "w:rPr",
|
|
20579
|
+
"elements": outputMarks
|
|
20580
|
+
},
|
|
20581
|
+
{
|
|
20582
|
+
"name": "w:fldChar",
|
|
20583
|
+
"attributes": {
|
|
20584
|
+
"w:fldCharType": "begin"
|
|
20585
|
+
}
|
|
20586
|
+
}
|
|
20587
|
+
]
|
|
20588
|
+
},
|
|
20589
|
+
{
|
|
20590
|
+
"name": "w:r",
|
|
20591
|
+
"elements": [
|
|
20592
|
+
{
|
|
20593
|
+
"name": "w:rPr",
|
|
20594
|
+
"elements": outputMarks
|
|
20595
|
+
},
|
|
20596
|
+
{
|
|
20597
|
+
"name": "w:instrText",
|
|
20598
|
+
"elements": [
|
|
20599
|
+
{
|
|
20600
|
+
"type": "text",
|
|
20601
|
+
"text": ` ${type2}`
|
|
20602
|
+
}
|
|
20603
|
+
]
|
|
20604
|
+
}
|
|
20605
|
+
]
|
|
20606
|
+
},
|
|
20607
|
+
{
|
|
20608
|
+
"name": "w:r",
|
|
20609
|
+
"elements": [
|
|
20610
|
+
{
|
|
20611
|
+
"name": "w:rPr",
|
|
20612
|
+
"elements": outputMarks
|
|
20613
|
+
},
|
|
20614
|
+
{
|
|
20615
|
+
"name": "w:fldChar",
|
|
20616
|
+
"attributes": {
|
|
20617
|
+
"w:fldCharType": "separate"
|
|
20618
|
+
}
|
|
20619
|
+
}
|
|
20620
|
+
]
|
|
20621
|
+
},
|
|
20622
|
+
{
|
|
20623
|
+
"name": "w:r",
|
|
20624
|
+
"elements": [
|
|
20625
|
+
{
|
|
20626
|
+
"name": "w:rPr",
|
|
20627
|
+
"elements": outputMarks
|
|
20628
|
+
},
|
|
20629
|
+
{
|
|
20630
|
+
"name": "w:fldChar",
|
|
20631
|
+
"attributes": {
|
|
20632
|
+
"w:fldCharType": "end"
|
|
20633
|
+
}
|
|
20634
|
+
}
|
|
20635
|
+
]
|
|
20636
|
+
}
|
|
20637
|
+
];
|
|
20638
|
+
};
|
|
20562
20639
|
const defaultInitialXml = `<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14"><w:body></w:body></w:document>`;
|
|
20563
20640
|
const parseXmlToJson = (xml) => {
|
|
20564
20641
|
return JSON.parse(xmljs.xml2json(xml, null, 2));
|
|
@@ -22267,15 +22344,25 @@ const processCombinedNodesForFldChar = (nodesToCombine = []) => {
|
|
|
22267
22344
|
if (!isNumPages) isNumPages = instrText?.trim().startsWith("NUMPAGES");
|
|
22268
22345
|
const urlMatch = instrText?.match(/HYPERLINK\s+"([^"]+)"/);
|
|
22269
22346
|
if (hasPageMarker) {
|
|
22270
|
-
|
|
22347
|
+
const pageNumNode = {
|
|
22271
22348
|
name: "sd:autoPageNumber",
|
|
22272
22349
|
type: "element"
|
|
22350
|
+
};
|
|
22351
|
+
nodesToCombine.forEach((n) => {
|
|
22352
|
+
const rPrNode = n.elements.find((el) => el.name === "w:rPr");
|
|
22353
|
+
if (rPrNode) pageNumNode.elements = [rPrNode];
|
|
22273
22354
|
});
|
|
22355
|
+
processedNodes.push(pageNumNode);
|
|
22274
22356
|
} else if (isNumPages) {
|
|
22275
|
-
|
|
22357
|
+
const totalPageNumNode = {
|
|
22276
22358
|
name: "sd:totalPageNumber",
|
|
22277
22359
|
type: "element"
|
|
22360
|
+
};
|
|
22361
|
+
nodesToCombine.forEach((n) => {
|
|
22362
|
+
const rPrNode = n.elements.find((el) => el.name === "w:rPr");
|
|
22363
|
+
if (rPrNode) totalPageNumNode.elements = [rPrNode];
|
|
22278
22364
|
});
|
|
22365
|
+
processedNodes.push(totalPageNumNode);
|
|
22279
22366
|
} else if (urlMatch && urlMatch?.length >= 2) {
|
|
22280
22367
|
const url = urlMatch[1];
|
|
22281
22368
|
const textMarks = [];
|
|
@@ -22611,8 +22698,13 @@ const handleAutoPageNumber = (params2) => {
|
|
|
22611
22698
|
if (nodes.length === 0 || nodes[0].name !== "sd:autoPageNumber") {
|
|
22612
22699
|
return { nodes: [], consumed: 0 };
|
|
22613
22700
|
}
|
|
22701
|
+
const rPr = nodes[0].elements?.find((el) => el.name === "w:rPr");
|
|
22702
|
+
const marks = parseMarks(rPr || { elements: [] });
|
|
22614
22703
|
const processedNode = {
|
|
22615
|
-
type: "page-number"
|
|
22704
|
+
type: "page-number",
|
|
22705
|
+
attrs: {
|
|
22706
|
+
marksAsAttrs: marks
|
|
22707
|
+
}
|
|
22616
22708
|
};
|
|
22617
22709
|
return { nodes: [processedNode], consumed: 1 };
|
|
22618
22710
|
};
|
|
@@ -22625,8 +22717,13 @@ const handleAutoTotalPageNumber = (params2) => {
|
|
|
22625
22717
|
if (nodes.length === 0 || nodes[0].name !== "sd:totalPageNumber") {
|
|
22626
22718
|
return { nodes: [], consumed: 0 };
|
|
22627
22719
|
}
|
|
22720
|
+
const rPr = nodes[0].elements?.find((el) => el.name === "w:rPr");
|
|
22721
|
+
const marks = parseMarks(rPr || { elements: [] });
|
|
22628
22722
|
const processedNode = {
|
|
22629
|
-
type: "total-page-number"
|
|
22723
|
+
type: "total-page-number",
|
|
22724
|
+
attrs: {
|
|
22725
|
+
marksAsAttrs: marks
|
|
22726
|
+
}
|
|
22630
22727
|
};
|
|
22631
22728
|
return { nodes: [processedNode], consumed: 1 };
|
|
22632
22729
|
};
|
|
@@ -23311,7 +23408,7 @@ const _SuperConverter = class _SuperConverter2 {
|
|
|
23311
23408
|
return;
|
|
23312
23409
|
}
|
|
23313
23410
|
}
|
|
23314
|
-
static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.36-next.
|
|
23411
|
+
static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.36-next.9") {
|
|
23315
23412
|
const customLocation = "docProps/custom.xml";
|
|
23316
23413
|
if (!docx[customLocation]) {
|
|
23317
23414
|
docx[customLocation] = generateCustomXml();
|
|
@@ -23778,7 +23875,7 @@ function storeSuperdocVersion(docx) {
|
|
|
23778
23875
|
function generateCustomXml() {
|
|
23779
23876
|
return DEFAULT_CUSTOM_XML;
|
|
23780
23877
|
}
|
|
23781
|
-
function generateSuperdocVersion(pid = 2, version2 = "0.12.36-next.
|
|
23878
|
+
function generateSuperdocVersion(pid = 2, version2 = "0.12.36-next.9") {
|
|
23782
23879
|
return {
|
|
23783
23880
|
type: "element",
|
|
23784
23881
|
name: "property",
|
|
@@ -26311,7 +26408,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
|
|
|
26311
26408
|
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);
|
|
26312
26409
|
var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
|
|
26313
26410
|
var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
|
|
26314
|
-
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;
|
|
26411
|
+
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, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
|
|
26315
26412
|
function getMarksFromSelection(state2) {
|
|
26316
26413
|
const { from: from2, to, empty: empty2 } = state2.selection;
|
|
26317
26414
|
const marks = [];
|
|
@@ -39080,7 +39177,8 @@ const createHeaderFooterEditor = ({
|
|
|
39080
39177
|
appendToBody = true,
|
|
39081
39178
|
sectionId,
|
|
39082
39179
|
type: type2,
|
|
39083
|
-
availableHeight
|
|
39180
|
+
availableHeight,
|
|
39181
|
+
currentPageNumber
|
|
39084
39182
|
}) => {
|
|
39085
39183
|
const parentStyles = editor.converter.getDocumentDefaultStyles();
|
|
39086
39184
|
const { fontSizePt, typeface } = parentStyles;
|
|
@@ -39121,6 +39219,8 @@ const createHeaderFooterEditor = ({
|
|
|
39121
39219
|
fonts: editor.options.fonts,
|
|
39122
39220
|
isHeaderOrFooter: true,
|
|
39123
39221
|
annotations: true,
|
|
39222
|
+
currentPageNumber,
|
|
39223
|
+
parentEditor: editor,
|
|
39124
39224
|
onCreate: (evt) => setEditorToolbar(evt, editor),
|
|
39125
39225
|
onBlur: (evt) => onHeaderFooterDataUpdate(evt, editor, sectionId, type2)
|
|
39126
39226
|
});
|
|
@@ -40468,6 +40568,19 @@ function useHighContrastMode() {
|
|
|
40468
40568
|
setHighContrastMode
|
|
40469
40569
|
};
|
|
40470
40570
|
}
|
|
40571
|
+
const findWordBounds = (doc2, pos) => {
|
|
40572
|
+
const $pos = doc2.resolve(pos);
|
|
40573
|
+
const parent = $pos.parent;
|
|
40574
|
+
const offset2 = $pos.parentOffset;
|
|
40575
|
+
const text = parent.textContent;
|
|
40576
|
+
if (!text) return { from: pos, to: pos };
|
|
40577
|
+
let start2 = offset2, end2 = offset2;
|
|
40578
|
+
while (start2 > 0 && /\w/.test(text[start2 - 1])) start2--;
|
|
40579
|
+
while (end2 < text.length && /\w/.test(text[end2])) end2++;
|
|
40580
|
+
const from2 = $pos.start() + start2;
|
|
40581
|
+
const to = $pos.start() + end2;
|
|
40582
|
+
return { from: from2, to };
|
|
40583
|
+
};
|
|
40471
40584
|
const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
40472
40585
|
/**
|
|
40473
40586
|
* Create a new Editor instance
|
|
@@ -41119,7 +41232,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
41119
41232
|
* @returns {Object | void} Migration results
|
|
41120
41233
|
*/
|
|
41121
41234
|
processCollaborationMigrations() {
|
|
41122
|
-
console.debug("[checkVersionMigrations] Current editor version", "0.12.36-next.
|
|
41235
|
+
console.debug("[checkVersionMigrations] Current editor version", "0.12.36-next.9");
|
|
41123
41236
|
if (!this.options.ydoc) return;
|
|
41124
41237
|
const metaMap = this.options.ydoc.getMap("meta");
|
|
41125
41238
|
let docVersion = metaMap.get("version");
|
|
@@ -41484,6 +41597,10 @@ createView_fn = function() {
|
|
|
41484
41597
|
pm.classList.remove("header-footer-edit");
|
|
41485
41598
|
pm.setAttribute("aria-readonly", false);
|
|
41486
41599
|
}
|
|
41600
|
+
const { state: state22, dispatch } = view;
|
|
41601
|
+
const word = findWordBounds(state22.doc, pos);
|
|
41602
|
+
const tr = state22.tr.setSelection(TextSelection.create(state22.doc, word.from, word.to));
|
|
41603
|
+
dispatch(tr);
|
|
41487
41604
|
}
|
|
41488
41605
|
});
|
|
41489
41606
|
const newState = this.state.reconfigure({
|
|
@@ -48767,32 +48884,89 @@ const PageNumber = Node$1.create({
|
|
|
48767
48884
|
name: "page-number",
|
|
48768
48885
|
group: "inline",
|
|
48769
48886
|
inline: true,
|
|
48770
|
-
|
|
48887
|
+
atom: true,
|
|
48888
|
+
selectable: false,
|
|
48889
|
+
draggable: false,
|
|
48890
|
+
selectable: false,
|
|
48891
|
+
defining: true,
|
|
48892
|
+
content: "",
|
|
48771
48893
|
addOptions() {
|
|
48772
48894
|
return {
|
|
48773
48895
|
htmlAttributes: {
|
|
48896
|
+
contenteditable: false,
|
|
48774
48897
|
"data-id": "auto-page-number",
|
|
48775
48898
|
"aria-label": "Page number node"
|
|
48776
48899
|
}
|
|
48777
48900
|
};
|
|
48778
48901
|
},
|
|
48902
|
+
addAttributes() {
|
|
48903
|
+
return {
|
|
48904
|
+
marksAsAttrs: {
|
|
48905
|
+
default: null,
|
|
48906
|
+
rendered: false
|
|
48907
|
+
}
|
|
48908
|
+
};
|
|
48909
|
+
},
|
|
48910
|
+
addNodeView() {
|
|
48911
|
+
return ({ node: node2, editor, getPos, decorations }) => {
|
|
48912
|
+
const htmlAttributes = this.options.htmlAttributes;
|
|
48913
|
+
return new AutoPageNumberNodeView(node2, getPos, decorations, editor, htmlAttributes);
|
|
48914
|
+
};
|
|
48915
|
+
},
|
|
48779
48916
|
parseDOM() {
|
|
48780
48917
|
return [{ tag: 'span[data-id="auto-page-number"' }];
|
|
48781
48918
|
},
|
|
48782
48919
|
renderDOM({ htmlAttributes }) {
|
|
48783
|
-
return ["span", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes)
|
|
48920
|
+
return ["span", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
|
|
48921
|
+
},
|
|
48922
|
+
addCommands() {
|
|
48923
|
+
return {
|
|
48924
|
+
addAutoPageNumber: () => ({ tr, dispatch, state: state2, editor }) => {
|
|
48925
|
+
const { options: options2 } = editor;
|
|
48926
|
+
if (!options2.isHeaderOrFooter) return false;
|
|
48927
|
+
const { schema } = state2;
|
|
48928
|
+
const pageNumberType = schema?.nodes?.["page-number"];
|
|
48929
|
+
if (!pageNumberType) return false;
|
|
48930
|
+
const pageNumberNodeJSON = { type: "page-number" };
|
|
48931
|
+
const pageNumberNode = schema.nodeFromJSON(pageNumberNodeJSON);
|
|
48932
|
+
if (dispatch) {
|
|
48933
|
+
tr.replaceSelectionWith(pageNumberNode, false);
|
|
48934
|
+
tr.setMeta("forceUpdatePagination", true);
|
|
48935
|
+
}
|
|
48936
|
+
return true;
|
|
48937
|
+
}
|
|
48938
|
+
};
|
|
48939
|
+
},
|
|
48940
|
+
addShortcuts() {
|
|
48941
|
+
return {
|
|
48942
|
+
"Mod-Shift-alt-p": () => this.editor.commands.addAutoPageNumber()
|
|
48943
|
+
};
|
|
48784
48944
|
}
|
|
48785
48945
|
});
|
|
48786
48946
|
const TotalPageCount = Node$1.create({
|
|
48787
48947
|
name: "total-page-number",
|
|
48788
48948
|
group: "inline",
|
|
48789
48949
|
inline: true,
|
|
48950
|
+
atom: true,
|
|
48951
|
+
selectable: false,
|
|
48952
|
+
draggable: false,
|
|
48953
|
+
selectable: false,
|
|
48790
48954
|
content: "text*",
|
|
48791
48955
|
addOptions() {
|
|
48792
48956
|
return {
|
|
48793
48957
|
htmlAttributes: {
|
|
48958
|
+
contenteditable: false,
|
|
48794
48959
|
"data-id": "auto-total-pages",
|
|
48795
|
-
"aria-label": "Total page count node"
|
|
48960
|
+
"aria-label": "Total page count node",
|
|
48961
|
+
"class": "sd-editor-auto-total-pages"
|
|
48962
|
+
}
|
|
48963
|
+
};
|
|
48964
|
+
},
|
|
48965
|
+
addAttributes() {
|
|
48966
|
+
return {
|
|
48967
|
+
marksAsAttrs: {
|
|
48968
|
+
default: null,
|
|
48969
|
+
rendered: false
|
|
48796
48970
|
}
|
|
48797
48971
|
};
|
|
48798
48972
|
},
|
|
@@ -48801,8 +48975,139 @@ const TotalPageCount = Node$1.create({
|
|
|
48801
48975
|
},
|
|
48802
48976
|
renderDOM({ htmlAttributes }) {
|
|
48803
48977
|
return ["span", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
|
|
48978
|
+
},
|
|
48979
|
+
addCommands() {
|
|
48980
|
+
return {
|
|
48981
|
+
addTotalPageCount: () => ({ tr, dispatch, state: state2, editor }) => {
|
|
48982
|
+
const { options: options2 } = editor;
|
|
48983
|
+
if (!options2.isHeaderOrFooter) return false;
|
|
48984
|
+
const { schema } = state2;
|
|
48985
|
+
const pageNumberType = schema.nodes?.["total-page-number"];
|
|
48986
|
+
if (!pageNumberType) return false;
|
|
48987
|
+
const currentPages = editor?.options?.parentEditor?.currentTotalPages || 1;
|
|
48988
|
+
const pageNumberNode = {
|
|
48989
|
+
type: "total-page-number",
|
|
48990
|
+
content: [{ type: "text", text: String(currentPages) }]
|
|
48991
|
+
};
|
|
48992
|
+
const pageNode = schema.nodeFromJSON(pageNumberNode);
|
|
48993
|
+
if (dispatch) {
|
|
48994
|
+
tr.replaceSelectionWith(pageNode, false);
|
|
48995
|
+
}
|
|
48996
|
+
return true;
|
|
48997
|
+
}
|
|
48998
|
+
};
|
|
48999
|
+
},
|
|
49000
|
+
addShortcuts() {
|
|
49001
|
+
return {
|
|
49002
|
+
"Mod-Shift-alt-c": () => this.editor.commands.addTotalPageCount()
|
|
49003
|
+
};
|
|
48804
49004
|
}
|
|
48805
49005
|
});
|
|
49006
|
+
class AutoPageNumberNodeView {
|
|
49007
|
+
constructor(node2, getPos, decorations, editor, htmlAttributes = {}) {
|
|
49008
|
+
__privateAdd$1(this, _AutoPageNumberNodeView_instances);
|
|
49009
|
+
this.node = node2;
|
|
49010
|
+
this.editor = editor;
|
|
49011
|
+
this.view = editor.view;
|
|
49012
|
+
this.getPos = getPos;
|
|
49013
|
+
this.editor = editor;
|
|
49014
|
+
this.dom = __privateMethod$1(this, _AutoPageNumberNodeView_instances, renderDom_fn).call(this, node2, htmlAttributes);
|
|
49015
|
+
}
|
|
49016
|
+
update(node2) {
|
|
49017
|
+
if (node2.type !== this.node.type) return false;
|
|
49018
|
+
this.node = node2;
|
|
49019
|
+
return true;
|
|
49020
|
+
}
|
|
49021
|
+
}
|
|
49022
|
+
_AutoPageNumberNodeView_instances = /* @__PURE__ */ new WeakSet();
|
|
49023
|
+
renderDom_fn = function(node2, htmlAttributes) {
|
|
49024
|
+
const pageText = this.editor.options.currentPageNumber || "1";
|
|
49025
|
+
const content = document.createTextNode(String(pageText));
|
|
49026
|
+
const nodeContent = document.createElement("span");
|
|
49027
|
+
nodeContent.className = "sd-editor-auto-page-number";
|
|
49028
|
+
nodeContent.setAttribute("data-id", "auto-page-number");
|
|
49029
|
+
nodeContent.setAttribute("aria-label", "Page number node");
|
|
49030
|
+
const currentPos = this.getPos();
|
|
49031
|
+
const { styles, marks } = getMarksFromNeighbors(currentPos, this.view);
|
|
49032
|
+
__privateMethod$1(this, _AutoPageNumberNodeView_instances, scheduleUpdateNodeStyle_fn).call(this, currentPos, marks);
|
|
49033
|
+
Object.assign(nodeContent.style, styles);
|
|
49034
|
+
nodeContent.appendChild(content);
|
|
49035
|
+
Object.entries(htmlAttributes).forEach(([key, value]) => {
|
|
49036
|
+
if (value) nodeContent.setAttribute(key, value);
|
|
49037
|
+
});
|
|
49038
|
+
return nodeContent;
|
|
49039
|
+
};
|
|
49040
|
+
scheduleUpdateNodeStyle_fn = function(pos, marks) {
|
|
49041
|
+
setTimeout(() => {
|
|
49042
|
+
const { state: state2 } = this.editor;
|
|
49043
|
+
const { dispatch } = this.view;
|
|
49044
|
+
const node2 = state2.doc.nodeAt(pos);
|
|
49045
|
+
if (!node2) return;
|
|
49046
|
+
const currentMarks = node2.attrs.marksAsAttrs || [];
|
|
49047
|
+
const newMarks = marks.map((m) => ({ type: m.type.name, attrs: m.attrs }));
|
|
49048
|
+
const isEqual = JSON.stringify(currentMarks) === JSON.stringify(newMarks);
|
|
49049
|
+
if (isEqual) return;
|
|
49050
|
+
const newAttrs = {
|
|
49051
|
+
...node2.attrs,
|
|
49052
|
+
marksAsAttrs: newMarks
|
|
49053
|
+
};
|
|
49054
|
+
const tr = state2.tr.setNodeMarkup(pos, void 0, newAttrs);
|
|
49055
|
+
dispatch(tr);
|
|
49056
|
+
}, 0);
|
|
49057
|
+
};
|
|
49058
|
+
const getMarksFromNeighbors = (currentPos, view) => {
|
|
49059
|
+
const $pos = view.state.doc.resolve(currentPos);
|
|
49060
|
+
const styles = {};
|
|
49061
|
+
const marks = [];
|
|
49062
|
+
const before = $pos.nodeBefore;
|
|
49063
|
+
if (before) {
|
|
49064
|
+
Object.assign(styles, processMarks(before.marks));
|
|
49065
|
+
marks.push(...before.marks);
|
|
49066
|
+
}
|
|
49067
|
+
const after = $pos.nodeAfter;
|
|
49068
|
+
if (after) {
|
|
49069
|
+
Object.assign(styles, { ...styles, ...processMarks(after.marks) });
|
|
49070
|
+
marks.push(...after.marks);
|
|
49071
|
+
}
|
|
49072
|
+
return {
|
|
49073
|
+
styles,
|
|
49074
|
+
marks
|
|
49075
|
+
};
|
|
49076
|
+
};
|
|
49077
|
+
const processMarks = (marks) => {
|
|
49078
|
+
const styles = {};
|
|
49079
|
+
marks.forEach((mark) => {
|
|
49080
|
+
const { type: type2, attrs } = mark;
|
|
49081
|
+
switch (type2.name) {
|
|
49082
|
+
case "textStyle":
|
|
49083
|
+
if (attrs.fontFamily) styles["font-family"] = attrs.fontFamily;
|
|
49084
|
+
if (attrs.fontSize) styles["font-size"] = attrs.fontSize;
|
|
49085
|
+
if (attrs.color) styles["color"] = attrs.color;
|
|
49086
|
+
if (attrs.backgroundColor) styles["background-color"] = attrs.backgroundColor;
|
|
49087
|
+
break;
|
|
49088
|
+
case "bold":
|
|
49089
|
+
styles["font-weight"] = "bold";
|
|
49090
|
+
break;
|
|
49091
|
+
case "italic":
|
|
49092
|
+
styles["font-style"] = "italic";
|
|
49093
|
+
break;
|
|
49094
|
+
case "underline":
|
|
49095
|
+
styles["text-decoration"] = (styles["text-decoration"] || "") + " underline";
|
|
49096
|
+
break;
|
|
49097
|
+
case "strike":
|
|
49098
|
+
styles["text-decoration"] = (styles["text-decoration"] || "") + " line-through";
|
|
49099
|
+
break;
|
|
49100
|
+
default:
|
|
49101
|
+
if (attrs?.style) {
|
|
49102
|
+
Object.entries(attrs.style).forEach(([key, value]) => {
|
|
49103
|
+
styles[key] = value;
|
|
49104
|
+
});
|
|
49105
|
+
}
|
|
49106
|
+
break;
|
|
49107
|
+
}
|
|
49108
|
+
});
|
|
49109
|
+
return styles;
|
|
49110
|
+
};
|
|
48806
49111
|
const ShapeContainer = Node$1.create({
|
|
48807
49112
|
name: "shapeContainer",
|
|
48808
49113
|
group: "block",
|
|
@@ -52840,16 +53145,15 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
|
|
|
52840
53145
|
const decorations = [];
|
|
52841
53146
|
const { pageSize, pageMargins } = editor.converter.pageStyles;
|
|
52842
53147
|
const pageHeight = pageSize.height * 96;
|
|
52843
|
-
editor.options.scale;
|
|
52844
53148
|
let currentPageNumber = 1;
|
|
52845
53149
|
let pageHeightThreshold = pageHeight;
|
|
52846
53150
|
let footer = null, header = null;
|
|
52847
53151
|
const firstHeaderId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
|
|
52848
|
-
const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor);
|
|
53152
|
+
const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber);
|
|
52849
53153
|
const pageBreak = createPageBreak({ editor, header: firstHeader, isFirstHeader: true });
|
|
52850
53154
|
decorations.push(Decoration.widget(0, pageBreak, { key: "stable-key" }));
|
|
52851
53155
|
const lastFooterId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
|
|
52852
|
-
const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor);
|
|
53156
|
+
const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber);
|
|
52853
53157
|
pageHeightThreshold -= firstHeader.headerHeight + lastFooter.footerHeight;
|
|
52854
53158
|
let coords = view?.coordsAtPos(doc2.content.size);
|
|
52855
53159
|
if (!coords) return [];
|
|
@@ -52868,7 +53172,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
|
|
|
52868
53172
|
if (currentPageNumber === 1) {
|
|
52869
53173
|
const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor, currentNode);
|
|
52870
53174
|
decorations.pop();
|
|
52871
|
-
const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor);
|
|
53175
|
+
const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber - 1);
|
|
52872
53176
|
const pageBreak2 = createPageBreak({ editor, header: newFirstHeader, isFirstHeader: true });
|
|
52873
53177
|
decorations.push(Decoration.widget(0, pageBreak2, { key: "stable-key" }));
|
|
52874
53178
|
}
|
|
@@ -52897,7 +53201,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
|
|
|
52897
53201
|
const footerId2 = getHeaderFooterId(currentPageNumber, "footerIds", editor, currentNode);
|
|
52898
53202
|
currentPageNumber++;
|
|
52899
53203
|
const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor);
|
|
52900
|
-
header = createHeader(pageMargins, pageSize, sectionData, headerId2, editor);
|
|
53204
|
+
header = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber - 1);
|
|
52901
53205
|
footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor, currentPageNumber - 1);
|
|
52902
53206
|
const bufferHeight2 = pageHeightThreshold - actualBreakBottom;
|
|
52903
53207
|
const { node: spacingNode2 } = createFinalPagePadding(bufferHeight2);
|
|
@@ -52912,7 +53216,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
|
|
|
52912
53216
|
const lastNodeCoords = view.coordsAtPos(finalPos);
|
|
52913
53217
|
const headerId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
|
|
52914
53218
|
const footerId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
|
|
52915
|
-
header = createHeader(pageMargins, pageSize, sectionData, headerId, editor);
|
|
53219
|
+
header = createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber);
|
|
52916
53220
|
footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber);
|
|
52917
53221
|
const bufferHeight = pageHeightThreshold - lastNodeCoords.bottom;
|
|
52918
53222
|
const { node: spacingNode } = createFinalPagePadding(bufferHeight);
|
|
@@ -52929,6 +53233,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
|
|
|
52929
53233
|
totalPageNumber.innerText = currentPageNumber;
|
|
52930
53234
|
}
|
|
52931
53235
|
});
|
|
53236
|
+
editor.currentTotalPages = currentPageNumber;
|
|
52932
53237
|
return decorations;
|
|
52933
53238
|
}
|
|
52934
53239
|
function createFinalPagePadding(bufferHeight) {
|
|
@@ -52939,7 +53244,7 @@ function createFinalPagePadding(bufferHeight) {
|
|
|
52939
53244
|
div2.style.height = bufferHeight + "px";
|
|
52940
53245
|
return { nodeHeight: bufferHeight, node: div2 };
|
|
52941
53246
|
}
|
|
52942
|
-
function createHeader(pageMargins, pageSize, sectionData, headerId, editor) {
|
|
53247
|
+
function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber) {
|
|
52943
53248
|
const headerDef = sectionData.headers?.[headerId];
|
|
52944
53249
|
const minHeaderHeight = pageMargins.top * 96;
|
|
52945
53250
|
const headerMargin = pageMargins.header * 96;
|
|
@@ -52966,7 +53271,8 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor) {
|
|
|
52966
53271
|
appendToBody: false,
|
|
52967
53272
|
sectionId: headerId,
|
|
52968
53273
|
type: "header",
|
|
52969
|
-
availableHeight
|
|
53274
|
+
availableHeight,
|
|
53275
|
+
currentPageNumber
|
|
52970
53276
|
});
|
|
52971
53277
|
editor.converter.headerEditors.push({
|
|
52972
53278
|
id: headerId,
|
|
@@ -52992,13 +53298,6 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
|
|
|
52992
53298
|
const minFooterHeight = pageMargins.bottom * 96;
|
|
52993
53299
|
const footerPaddingFromEdge = pageMargins.footer * 96;
|
|
52994
53300
|
const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
|
|
52995
|
-
const sectionContainer = footerDef?.sectionContainer?.cloneNode(true);
|
|
52996
|
-
const autoPageNumber = sectionContainer?.querySelector('span[data-id="auto-page-number"]');
|
|
52997
|
-
if (autoPageNumber) {
|
|
52998
|
-
const fontSize2 = autoPageNumber.previousElementSibling?.style?.fontSize || autoPageNumber.nextElementSibling?.style?.fontSize;
|
|
52999
|
-
if (fontSize2) autoPageNumber.style.fontSize = fontSize2;
|
|
53000
|
-
autoPageNumber.innerText = currentPageNumber;
|
|
53001
|
-
}
|
|
53002
53301
|
const editorContainer = document.createElement("div");
|
|
53003
53302
|
if (!footerId && !editor.converter.footerIds["default"]) {
|
|
53004
53303
|
footerId = "rId" + generateDocxRandomId();
|
|
@@ -53018,7 +53317,8 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
|
|
|
53018
53317
|
appendToBody: false,
|
|
53019
53318
|
sectionId: footerId,
|
|
53020
53319
|
type: "footer",
|
|
53021
|
-
availableHeight: footerHeight
|
|
53320
|
+
availableHeight: footerHeight,
|
|
53321
|
+
currentPageNumber
|
|
53022
53322
|
});
|
|
53023
53323
|
editor.converter.footerEditors.push({
|
|
53024
53324
|
id: footerId,
|