@harbour-enterprises/superdoc 0.14.20-next.2 → 0.14.20-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/chunks/{super-editor.es-zSi7xcwW.es.js → super-editor.es-6N0UXlT4.es.js} +2249 -1832
  2. package/dist/chunks/{super-editor.es-BRwvL-Om.cjs → super-editor.es-CurvCFok.cjs} +2235 -1818
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/style.css +36 -0
  6. package/dist/super-editor/ai-writer.es.js +2 -2
  7. package/dist/super-editor/chunks/{converter-xOGyzvEn.js → converter-BjbkzPcQ.js} +1822 -1624
  8. package/dist/super-editor/chunks/{docx-zipper-DWNn8zuL.js → docx-zipper-CsN-Tc_o.js} +1 -1
  9. package/dist/super-editor/chunks/{editor-Djj4FIYh.js → editor-BEh4-OIY.js} +194 -4
  10. package/dist/super-editor/chunks/{toolbar-BTKDmnA4.js → toolbar-BN6rMmJ8.js} +8 -8
  11. package/dist/super-editor/components/slash-menu/constants.d.ts +4 -0
  12. package/dist/super-editor/components/slash-menu/constants.d.ts.map +1 -1
  13. package/dist/super-editor/components/slash-menu/menuItems.d.ts +2 -0
  14. package/dist/super-editor/components/slash-menu/menuItems.d.ts.map +1 -1
  15. package/dist/super-editor/converter.es.js +1 -1
  16. package/dist/super-editor/core/Attribute.d.ts +2 -2
  17. package/dist/super-editor/core/InputRule.d.ts +9 -0
  18. package/dist/super-editor/core/InputRule.d.ts.map +1 -1
  19. package/dist/super-editor/core/Schema.d.ts +2 -2
  20. package/dist/super-editor/core/helpers/documentSectionHelpers.d.ts +18 -0
  21. package/dist/super-editor/core/helpers/documentSectionHelpers.d.ts.map +1 -0
  22. package/dist/super-editor/core/helpers/index.d.ts +1 -0
  23. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  24. package/dist/super-editor/core/super-converter/v2/exporter/documentSectionExporter.d.ts +2 -0
  25. package/dist/super-editor/core/super-converter/v2/exporter/documentSectionExporter.d.ts.map +1 -0
  26. package/dist/super-editor/core/super-converter/v2/exporter/helpers/index.d.ts +3 -0
  27. package/dist/super-editor/core/super-converter/v2/exporter/helpers/index.d.ts.map +1 -0
  28. package/dist/super-editor/core/super-converter/v2/exporter/helpers/translateChildNodes.d.ts +8 -0
  29. package/dist/super-editor/core/super-converter/v2/exporter/helpers/translateChildNodes.d.ts.map +1 -0
  30. package/dist/super-editor/core/super-converter/v2/exporter/index.d.ts +3 -0
  31. package/dist/super-editor/core/super-converter/v2/exporter/index.d.ts.map +1 -0
  32. package/dist/super-editor/core/super-converter/v2/importer/structuredDocumentNodeImporter.d.ts.map +1 -1
  33. package/dist/super-editor/docx-zipper.es.js +2 -2
  34. package/dist/super-editor/editor.es.js +3 -3
  35. package/dist/super-editor/extensions/index.d.ts +2 -1
  36. package/dist/super-editor/extensions/index.d.ts.map +1 -1
  37. package/dist/super-editor/extensions/structured-content/document-section/DocumentSectionView.d.ts +16 -0
  38. package/dist/super-editor/extensions/structured-content/document-section/DocumentSectionView.d.ts.map +1 -0
  39. package/dist/super-editor/extensions/structured-content/document-section.d.ts +2 -0
  40. package/dist/super-editor/extensions/structured-content/document-section.d.ts.map +1 -0
  41. package/dist/super-editor/extensions/structured-content/index.d.ts +1 -0
  42. package/dist/super-editor/extensions/track-changes/trackChangesHelpers/markInsertion.d.ts +0 -1
  43. package/dist/super-editor/extensions/track-changes/trackChangesHelpers/markInsertion.d.ts.map +1 -1
  44. package/dist/super-editor/file-zipper.es.js +1 -1
  45. package/dist/super-editor/index.d.ts +1 -1
  46. package/dist/super-editor/style.css +36 -0
  47. package/dist/super-editor/super-editor.es.js +39 -8
  48. package/dist/super-editor/toolbar.es.js +2 -2
  49. package/dist/super-editor.cjs +2 -1
  50. package/dist/super-editor.es.js +16 -15
  51. package/dist/superdoc.cjs +3 -2
  52. package/dist/superdoc.es.js +739 -738
  53. package/dist/superdoc.umd.js +2236 -1819
  54. package/dist/superdoc.umd.js.map +1 -1
  55. package/package.json +1 -1
@@ -19168,1367 +19168,141 @@ const carbonCopy = (obj) => {
19168
19168
  return void 0;
19169
19169
  }
19170
19170
  };
19171
- const baseNumbering = {
19172
- declaration: {
19171
+ function translateCommentNode(params2, type2) {
19172
+ const { node: node2, commentsExportType, exportedCommentDefs = [] } = params2;
19173
+ if (!exportedCommentDefs.length || commentsExportType === "clean") return;
19174
+ const nodeId = node2.attrs["w:id"];
19175
+ const originalComment = params2.comments.find((comment) => {
19176
+ return comment.commentId == nodeId;
19177
+ });
19178
+ if (!originalComment) return;
19179
+ const commentIndex = params2.comments?.findIndex((comment) => comment.commentId === originalComment.commentId);
19180
+ const parentId = originalComment.parentCommentId;
19181
+ let parentComment;
19182
+ if (parentId) {
19183
+ parentComment = params2.comments.find((c2) => c2.commentId === parentId || c2.importedId === parentId);
19184
+ }
19185
+ const isInternal = parentComment?.isInternal || originalComment.isInternal;
19186
+ if (commentsExportType === "external" && isInternal) return;
19187
+ const isResolved = !!originalComment.resolvedTime;
19188
+ if (isResolved) return;
19189
+ let commentSchema = getCommentSchema(type2, commentIndex);
19190
+ if (type2 === "End") {
19191
+ const commentReference = {
19192
+ name: "w:r",
19193
+ elements: [{ name: "w:commentReference", attributes: { "w:id": String(commentIndex) } }]
19194
+ };
19195
+ commentSchema = [commentSchema, commentReference];
19196
+ }
19197
+ return commentSchema;
19198
+ }
19199
+ const getCommentSchema = (type2, commentId) => {
19200
+ return {
19201
+ name: `w:commentRange${type2}`,
19173
19202
  attributes: {
19174
- version: "1.0",
19175
- encoding: "UTF-8",
19176
- standalone: "yes"
19203
+ "w:id": String(commentId)
19177
19204
  }
19178
- },
19179
- elements: [
19180
- {
19205
+ };
19206
+ };
19207
+ const prepareCommentParaIds = (comment) => {
19208
+ const newComment = {
19209
+ ...comment,
19210
+ commentParaId: generateRandom32BitHex()
19211
+ };
19212
+ return newComment;
19213
+ };
19214
+ const getCommentDefinition = (comment, commentId, allComments, editor) => {
19215
+ const translatedText = translateParagraphNode({ editor, node: comment.commentJSON });
19216
+ const attributes = {
19217
+ "w:id": String(commentId),
19218
+ "w:author": comment.creatorName || comment.importedAuthor?.name,
19219
+ "w:email": comment.creatorEmail || comment.importedAuthor?.email,
19220
+ "w:date": toIsoNoFractional(comment.createdTime),
19221
+ "w:initials": getInitials(comment.creatorName),
19222
+ "w:done": comment.resolvedTime ? "1" : "0",
19223
+ "w15:paraId": comment.commentParaId,
19224
+ "custom:internalId": comment.commentId || comment.internalId,
19225
+ "custom:trackedChange": comment.trackedChange,
19226
+ "custom:trackedChangeText": comment.trackedChangeText || null,
19227
+ "custom:trackedChangeType": comment.trackedChangeType,
19228
+ "custom:trackedDeletedText": comment.deletedText || null
19229
+ };
19230
+ if (comment?.parentCommentId) {
19231
+ const parentComment = allComments.find((c2) => c2.commentId === comment.parentCommentId);
19232
+ attributes["w15:paraIdParent"] = parentComment.commentParaId;
19233
+ }
19234
+ return {
19235
+ type: "element",
19236
+ name: "w:comment",
19237
+ attributes,
19238
+ elements: [translatedText]
19239
+ };
19240
+ };
19241
+ const getInitials = (name) => {
19242
+ if (!name) return null;
19243
+ const preparedText = name.replace("(imported)", "").trim();
19244
+ const initials = preparedText.split(" ").map((word) => word[0]).join("");
19245
+ return initials;
19246
+ };
19247
+ const toIsoNoFractional = (unixMillis) => {
19248
+ const date = new Date(unixMillis || Date.now());
19249
+ return date.toISOString().replace(/\.\d{3}Z$/, "Z");
19250
+ };
19251
+ const updateCommentsXml = (commentDefs = [], commentsXml) => {
19252
+ const newCommentsXml = carbonCopy(commentsXml);
19253
+ commentDefs.forEach((commentDef) => {
19254
+ const elements = commentDef.elements[0].elements;
19255
+ elements.unshift(COMMENT_REF);
19256
+ const paraId = commentDef.attributes["w15:paraId"];
19257
+ commentDef.elements[0].attributes["w14:paraId"] = paraId;
19258
+ commentDef.attributes = {
19259
+ "w:id": commentDef.attributes["w:id"],
19260
+ "w:author": commentDef.attributes["w:author"],
19261
+ "w:email": commentDef.attributes["w:email"],
19262
+ "w:date": commentDef.attributes["w:date"],
19263
+ "w:initials": commentDef.attributes["w:initials"],
19264
+ "custom:internalId": commentDef.attributes["custom:internalId"],
19265
+ "custom:trackedChange": commentDef.attributes["custom:trackedChange"],
19266
+ "custom:trackedChangeText": commentDef.attributes["custom:trackedChangeText"],
19267
+ "custom:trackedChangeType": commentDef.attributes["custom:trackedChangeType"],
19268
+ "custom:trackedDeletedText": commentDef.attributes["custom:trackedDeletedText"],
19269
+ "xmlns:custom": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
19270
+ };
19271
+ });
19272
+ newCommentsXml.elements[0].elements = commentDefs;
19273
+ return newCommentsXml;
19274
+ };
19275
+ const updateCommentsExtendedXml = (comments = [], commentsExtendedXml) => {
19276
+ const xmlCopy = carbonCopy(commentsExtendedXml);
19277
+ const commentsEx = comments.map((comment) => {
19278
+ const attributes = {
19279
+ "w15:paraId": comment.commentParaId,
19280
+ "w15:done": comment.resolvedTime ? "1" : "0"
19281
+ };
19282
+ const parentId = comment.parentCommentId;
19283
+ if (parentId) {
19284
+ const parentComment = comments.find((c2) => c2.commentId === parentId);
19285
+ attributes["w15:paraIdParent"] = parentComment.commentParaId;
19286
+ }
19287
+ return {
19181
19288
  type: "element",
19182
- name: "w:numbering",
19183
- attributes: {
19184
- "xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
19185
- "xmlns:cx": "http://schemas.microsoft.com/office/drawing/2014/chartex",
19186
- "xmlns:cx1": "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex",
19187
- "xmlns:cx2": "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex",
19188
- "xmlns:cx3": "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex",
19189
- "xmlns:cx4": "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex",
19190
- "xmlns:cx5": "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex",
19191
- "xmlns:cx6": "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex",
19192
- "xmlns:cx7": "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex",
19193
- "xmlns:cx8": "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex",
19194
- "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
19195
- "xmlns:aink": "http://schemas.microsoft.com/office/drawing/2016/ink",
19196
- "xmlns:am3d": "http://schemas.microsoft.com/office/drawing/2017/model3d",
19197
- "xmlns:o": "urn:schemas-microsoft-com:office:office",
19198
- "xmlns:oel": "http://schemas.microsoft.com/office/2019/extlst",
19199
- "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
19200
- "xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
19201
- "xmlns:v": "urn:schemas-microsoft-com:vml",
19202
- "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
19203
- "xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
19204
- "xmlns:w10": "urn:schemas-microsoft-com:office:word",
19205
- "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
19206
- "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
19207
- "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
19208
- "xmlns:w16cex": "http://schemas.microsoft.com/office/word/2018/wordml/cex",
19209
- "xmlns:w16cid": "http://schemas.microsoft.com/office/word/2016/wordml/cid",
19210
- "xmlns:w16": "http://schemas.microsoft.com/office/word/2018/wordml",
19211
- "xmlns:w16du": "http://schemas.microsoft.com/office/word/2023/wordml/word16du",
19212
- "xmlns:w16sdtdh": "http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash",
19213
- "xmlns:w16se": "http://schemas.microsoft.com/office/word/2015/wordml/symex",
19214
- "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
19215
- "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
19216
- "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml",
19217
- "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
19218
- "mc:Ignorable": "w14 w15 w16se w16cid w16 w16cex w16sdtdh w16du wp14"
19219
- },
19220
- elements: [
19221
- {
19222
- type: "element",
19223
- name: "w:abstractNum",
19224
- attributes: {
19225
- "w:abstractNumId": "0",
19226
- "w15:restartNumberingAfterBreak": "0"
19227
- },
19228
- elements: [
19229
- {
19230
- type: "element",
19231
- name: "w:nsid",
19232
- attributes: {
19233
- "w:val": "16126B07"
19234
- }
19235
- },
19236
- {
19237
- type: "element",
19238
- name: "w:multiLevelType",
19239
- attributes: {
19240
- "w:val": "hybridMultilevel"
19241
- }
19242
- },
19243
- {
19244
- type: "element",
19245
- name: "w:lvl",
19246
- attributes: {
19247
- "w:ilvl": "0",
19248
- "w:tplc": "04090001"
19249
- },
19250
- elements: [
19251
- {
19252
- type: "element",
19253
- name: "w:start",
19254
- attributes: {
19255
- "w:val": "1"
19256
- }
19257
- },
19258
- {
19259
- type: "element",
19260
- name: "w:numFmt",
19261
- attributes: {
19262
- "w:val": "bullet"
19263
- }
19264
- },
19265
- {
19266
- type: "element",
19267
- name: "w:lvlText",
19268
- attributes: {
19269
- "w:val": ""
19270
- }
19271
- },
19272
- {
19273
- type: "element",
19274
- name: "w:lvlJc",
19275
- attributes: {
19276
- "w:val": "left"
19277
- }
19278
- },
19279
- {
19280
- type: "element",
19281
- name: "w:pPr",
19282
- elements: [
19283
- {
19284
- type: "element",
19285
- name: "w:ind",
19286
- attributes: {
19287
- "w:left": "720",
19288
- "w:hanging": "360"
19289
- }
19290
- }
19291
- ]
19292
- },
19293
- {
19294
- type: "element",
19295
- name: "w:rPr",
19296
- elements: [
19297
- {
19298
- type: "element",
19299
- name: "w:rFonts",
19300
- attributes: {
19301
- "w:ascii": "Symbol",
19302
- "w:hAnsi": "Symbol",
19303
- "w:hint": "default"
19304
- }
19305
- }
19306
- ]
19307
- }
19308
- ]
19309
- },
19310
- {
19311
- type: "element",
19312
- name: "w:lvl",
19313
- attributes: {
19314
- "w:ilvl": "1",
19315
- "w:tplc": "04090003",
19316
- "w:tentative": "1"
19317
- },
19318
- elements: [
19319
- {
19320
- type: "element",
19321
- name: "w:start",
19322
- attributes: {
19323
- "w:val": "1"
19324
- }
19325
- },
19326
- {
19327
- type: "element",
19328
- name: "w:numFmt",
19329
- attributes: {
19330
- "w:val": "bullet"
19331
- }
19332
- },
19333
- {
19334
- type: "element",
19335
- name: "w:lvlText",
19336
- attributes: {
19337
- "w:val": "o"
19338
- }
19339
- },
19340
- {
19341
- type: "element",
19342
- name: "w:lvlJc",
19343
- attributes: {
19344
- "w:val": "left"
19345
- }
19346
- },
19347
- {
19348
- type: "element",
19349
- name: "w:pPr",
19350
- elements: [
19351
- {
19352
- type: "element",
19353
- name: "w:ind",
19354
- attributes: {
19355
- "w:left": "1440",
19356
- "w:hanging": "360"
19357
- }
19358
- }
19359
- ]
19360
- },
19361
- {
19362
- type: "element",
19363
- name: "w:rPr",
19364
- elements: [
19365
- {
19366
- type: "element",
19367
- name: "w:rFonts",
19368
- attributes: {
19369
- "w:ascii": "Courier New",
19370
- "w:hAnsi": "Courier New",
19371
- "w:cs": "Courier New",
19372
- "w:hint": "default"
19373
- }
19374
- }
19375
- ]
19376
- }
19377
- ]
19378
- },
19379
- {
19380
- type: "element",
19381
- name: "w:lvl",
19382
- attributes: {
19383
- "w:ilvl": "2",
19384
- "w:tplc": "04090005",
19385
- "w:tentative": "1"
19386
- },
19387
- elements: [
19388
- {
19389
- type: "element",
19390
- name: "w:start",
19391
- attributes: {
19392
- "w:val": "1"
19393
- }
19394
- },
19395
- {
19396
- type: "element",
19397
- name: "w:numFmt",
19398
- attributes: {
19399
- "w:val": "bullet"
19400
- }
19401
- },
19402
- {
19403
- type: "element",
19404
- name: "w:lvlText",
19405
- attributes: {
19406
- "w:val": ""
19407
- }
19408
- },
19409
- {
19410
- type: "element",
19411
- name: "w:lvlJc",
19412
- attributes: {
19413
- "w:val": "left"
19414
- }
19415
- },
19416
- {
19417
- type: "element",
19418
- name: "w:pPr",
19419
- elements: [
19420
- {
19421
- type: "element",
19422
- name: "w:ind",
19423
- attributes: {
19424
- "w:left": "2160",
19425
- "w:hanging": "360"
19426
- }
19427
- }
19428
- ]
19429
- },
19430
- {
19431
- type: "element",
19432
- name: "w:rPr",
19433
- elements: [
19434
- {
19435
- type: "element",
19436
- name: "w:rFonts",
19437
- attributes: {
19438
- "w:ascii": "Wingdings",
19439
- "w:hAnsi": "Wingdings",
19440
- "w:hint": "default"
19441
- }
19442
- }
19443
- ]
19444
- }
19445
- ]
19446
- },
19447
- {
19448
- type: "element",
19449
- name: "w:lvl",
19450
- attributes: {
19451
- "w:ilvl": "3",
19452
- "w:tplc": "04090001",
19453
- "w:tentative": "1"
19454
- },
19455
- elements: [
19456
- {
19457
- type: "element",
19458
- name: "w:start",
19459
- attributes: {
19460
- "w:val": "1"
19461
- }
19462
- },
19463
- {
19464
- type: "element",
19465
- name: "w:numFmt",
19466
- attributes: {
19467
- "w:val": "bullet"
19468
- }
19469
- },
19470
- {
19471
- type: "element",
19472
- name: "w:lvlText",
19473
- attributes: {
19474
- "w:val": ""
19475
- }
19476
- },
19477
- {
19478
- type: "element",
19479
- name: "w:lvlJc",
19480
- attributes: {
19481
- "w:val": "left"
19482
- }
19483
- },
19484
- {
19485
- type: "element",
19486
- name: "w:pPr",
19487
- elements: [
19488
- {
19489
- type: "element",
19490
- name: "w:ind",
19491
- attributes: {
19492
- "w:left": "2880",
19493
- "w:hanging": "360"
19494
- }
19495
- }
19496
- ]
19497
- },
19498
- {
19499
- type: "element",
19500
- name: "w:rPr",
19501
- elements: [
19502
- {
19503
- type: "element",
19504
- name: "w:rFonts",
19505
- attributes: {
19506
- "w:ascii": "Symbol",
19507
- "w:hAnsi": "Symbol",
19508
- "w:hint": "default"
19509
- }
19510
- }
19511
- ]
19512
- }
19513
- ]
19514
- },
19515
- {
19516
- type: "element",
19517
- name: "w:lvl",
19518
- attributes: {
19519
- "w:ilvl": "4",
19520
- "w:tplc": "04090003",
19521
- "w:tentative": "1"
19522
- },
19523
- elements: [
19524
- {
19525
- type: "element",
19526
- name: "w:start",
19527
- attributes: {
19528
- "w:val": "1"
19529
- }
19530
- },
19531
- {
19532
- type: "element",
19533
- name: "w:numFmt",
19534
- attributes: {
19535
- "w:val": "bullet"
19536
- }
19537
- },
19538
- {
19539
- type: "element",
19540
- name: "w:lvlText",
19541
- attributes: {
19542
- "w:val": "o"
19543
- }
19544
- },
19545
- {
19546
- type: "element",
19547
- name: "w:lvlJc",
19548
- attributes: {
19549
- "w:val": "left"
19550
- }
19551
- },
19552
- {
19553
- type: "element",
19554
- name: "w:pPr",
19555
- elements: [
19556
- {
19557
- type: "element",
19558
- name: "w:ind",
19559
- attributes: {
19560
- "w:left": "3600",
19561
- "w:hanging": "360"
19562
- }
19563
- }
19564
- ]
19565
- },
19566
- {
19567
- type: "element",
19568
- name: "w:rPr",
19569
- elements: [
19570
- {
19571
- type: "element",
19572
- name: "w:rFonts",
19573
- attributes: {
19574
- "w:ascii": "Courier New",
19575
- "w:hAnsi": "Courier New",
19576
- "w:cs": "Courier New",
19577
- "w:hint": "default"
19578
- }
19579
- }
19580
- ]
19581
- }
19582
- ]
19583
- },
19584
- {
19585
- type: "element",
19586
- name: "w:lvl",
19587
- attributes: {
19588
- "w:ilvl": "5",
19589
- "w:tplc": "04090005",
19590
- "w:tentative": "1"
19591
- },
19592
- elements: [
19593
- {
19594
- type: "element",
19595
- name: "w:start",
19596
- attributes: {
19597
- "w:val": "1"
19598
- }
19599
- },
19600
- {
19601
- type: "element",
19602
- name: "w:numFmt",
19603
- attributes: {
19604
- "w:val": "bullet"
19605
- }
19606
- },
19607
- {
19608
- type: "element",
19609
- name: "w:lvlText",
19610
- attributes: {
19611
- "w:val": ""
19612
- }
19613
- },
19614
- {
19615
- type: "element",
19616
- name: "w:lvlJc",
19617
- attributes: {
19618
- "w:val": "left"
19619
- }
19620
- },
19621
- {
19622
- type: "element",
19623
- name: "w:pPr",
19624
- elements: [
19625
- {
19626
- type: "element",
19627
- name: "w:ind",
19628
- attributes: {
19629
- "w:left": "4320",
19630
- "w:hanging": "360"
19631
- }
19632
- }
19633
- ]
19634
- },
19635
- {
19636
- type: "element",
19637
- name: "w:rPr",
19638
- elements: [
19639
- {
19640
- type: "element",
19641
- name: "w:rFonts",
19642
- attributes: {
19643
- "w:ascii": "Wingdings",
19644
- "w:hAnsi": "Wingdings",
19645
- "w:hint": "default"
19646
- }
19647
- }
19648
- ]
19649
- }
19650
- ]
19651
- },
19652
- {
19653
- type: "element",
19654
- name: "w:lvl",
19655
- attributes: {
19656
- "w:ilvl": "6",
19657
- "w:tplc": "04090001",
19658
- "w:tentative": "1"
19659
- },
19660
- elements: [
19661
- {
19662
- type: "element",
19663
- name: "w:start",
19664
- attributes: {
19665
- "w:val": "1"
19666
- }
19667
- },
19668
- {
19669
- type: "element",
19670
- name: "w:numFmt",
19671
- attributes: {
19672
- "w:val": "bullet"
19673
- }
19674
- },
19675
- {
19676
- type: "element",
19677
- name: "w:lvlText",
19678
- attributes: {
19679
- "w:val": ""
19680
- }
19681
- },
19682
- {
19683
- type: "element",
19684
- name: "w:lvlJc",
19685
- attributes: {
19686
- "w:val": "left"
19687
- }
19688
- },
19689
- {
19690
- type: "element",
19691
- name: "w:pPr",
19692
- elements: [
19693
- {
19694
- type: "element",
19695
- name: "w:ind",
19696
- attributes: {
19697
- "w:left": "5040",
19698
- "w:hanging": "360"
19699
- }
19700
- }
19701
- ]
19702
- },
19703
- {
19704
- type: "element",
19705
- name: "w:rPr",
19706
- elements: [
19707
- {
19708
- type: "element",
19709
- name: "w:rFonts",
19710
- attributes: {
19711
- "w:ascii": "Symbol",
19712
- "w:hAnsi": "Symbol",
19713
- "w:hint": "default"
19714
- }
19715
- }
19716
- ]
19717
- }
19718
- ]
19719
- },
19720
- {
19721
- type: "element",
19722
- name: "w:lvl",
19723
- attributes: {
19724
- "w:ilvl": "7",
19725
- "w:tplc": "04090003",
19726
- "w:tentative": "1"
19727
- },
19728
- elements: [
19729
- {
19730
- type: "element",
19731
- name: "w:start",
19732
- attributes: {
19733
- "w:val": "1"
19734
- }
19735
- },
19736
- {
19737
- type: "element",
19738
- name: "w:numFmt",
19739
- attributes: {
19740
- "w:val": "bullet"
19741
- }
19742
- },
19743
- {
19744
- type: "element",
19745
- name: "w:lvlText",
19746
- attributes: {
19747
- "w:val": "o"
19748
- }
19749
- },
19750
- {
19751
- type: "element",
19752
- name: "w:lvlJc",
19753
- attributes: {
19754
- "w:val": "left"
19755
- }
19756
- },
19757
- {
19758
- type: "element",
19759
- name: "w:pPr",
19760
- elements: [
19761
- {
19762
- type: "element",
19763
- name: "w:ind",
19764
- attributes: {
19765
- "w:left": "5760",
19766
- "w:hanging": "360"
19767
- }
19768
- }
19769
- ]
19770
- },
19771
- {
19772
- type: "element",
19773
- name: "w:rPr",
19774
- elements: [
19775
- {
19776
- type: "element",
19777
- name: "w:rFonts",
19778
- attributes: {
19779
- "w:ascii": "Courier New",
19780
- "w:hAnsi": "Courier New",
19781
- "w:cs": "Courier New",
19782
- "w:hint": "default"
19783
- }
19784
- }
19785
- ]
19786
- }
19787
- ]
19788
- },
19789
- {
19790
- type: "element",
19791
- name: "w:lvl",
19792
- attributes: {
19793
- "w:ilvl": "8",
19794
- "w:tplc": "04090005",
19795
- "w:tentative": "1"
19796
- },
19797
- elements: [
19798
- {
19799
- type: "element",
19800
- name: "w:start",
19801
- attributes: {
19802
- "w:val": "1"
19803
- }
19804
- },
19805
- {
19806
- type: "element",
19807
- name: "w:numFmt",
19808
- attributes: {
19809
- "w:val": "bullet"
19810
- }
19811
- },
19812
- {
19813
- type: "element",
19814
- name: "w:lvlText",
19815
- attributes: {
19816
- "w:val": ""
19817
- }
19818
- },
19819
- {
19820
- type: "element",
19821
- name: "w:lvlJc",
19822
- attributes: {
19823
- "w:val": "left"
19824
- }
19825
- },
19826
- {
19827
- type: "element",
19828
- name: "w:pPr",
19829
- elements: [
19830
- {
19831
- type: "element",
19832
- name: "w:ind",
19833
- attributes: {
19834
- "w:left": "6480",
19835
- "w:hanging": "360"
19836
- }
19837
- }
19838
- ]
19839
- },
19840
- {
19841
- type: "element",
19842
- name: "w:rPr",
19843
- elements: [
19844
- {
19845
- type: "element",
19846
- name: "w:rFonts",
19847
- attributes: {
19848
- "w:ascii": "Wingdings",
19849
- "w:hAnsi": "Wingdings",
19850
- "w:hint": "default"
19851
- }
19852
- }
19853
- ]
19854
- }
19855
- ]
19856
- }
19857
- ]
19858
- },
19859
- {
19860
- type: "element",
19861
- name: "w:abstractNum",
19862
- attributes: {
19863
- "w:abstractNumId": "1",
19864
- "w15:restartNumberingAfterBreak": "0"
19865
- },
19866
- elements: [
19867
- {
19868
- type: "element",
19869
- name: "w:nsid",
19870
- attributes: {
19871
- "w:val": "587013BA"
19872
- }
19873
- },
19874
- {
19875
- type: "element",
19876
- name: "w:multiLevelType",
19877
- attributes: {
19878
- "w:val": "hybridMultilevel"
19879
- }
19880
- },
19881
- {
19882
- type: "element",
19883
- name: "w:lvl",
19884
- attributes: {
19885
- "w:ilvl": "0",
19886
- "w:tplc": "0409000F"
19887
- },
19888
- elements: [
19889
- {
19890
- type: "element",
19891
- name: "w:start",
19892
- attributes: {
19893
- "w:val": "1"
19894
- }
19895
- },
19896
- {
19897
- type: "element",
19898
- name: "w:numFmt",
19899
- attributes: {
19900
- "w:val": "decimal"
19901
- }
19902
- },
19903
- {
19904
- type: "element",
19905
- name: "w:lvlText",
19906
- attributes: {
19907
- "w:val": "%1."
19908
- }
19909
- },
19910
- {
19911
- type: "element",
19912
- name: "w:lvlJc",
19913
- attributes: {
19914
- "w:val": "left"
19915
- }
19916
- },
19917
- {
19918
- type: "element",
19919
- name: "w:pPr",
19920
- elements: [
19921
- {
19922
- type: "element",
19923
- name: "w:ind",
19924
- attributes: {
19925
- "w:left": "720",
19926
- "w:hanging": "360"
19927
- }
19928
- }
19929
- ]
19930
- }
19931
- ]
19932
- },
19933
- {
19934
- type: "element",
19935
- name: "w:lvl",
19936
- attributes: {
19937
- "w:ilvl": "1",
19938
- "w:tplc": "04090019",
19939
- "w:tentative": "1"
19940
- },
19941
- elements: [
19942
- {
19943
- type: "element",
19944
- name: "w:start",
19945
- attributes: {
19946
- "w:val": "1"
19947
- }
19948
- },
19949
- {
19950
- type: "element",
19951
- name: "w:numFmt",
19952
- attributes: {
19953
- "w:val": "lowerLetter"
19954
- }
19955
- },
19956
- {
19957
- type: "element",
19958
- name: "w:lvlText",
19959
- attributes: {
19960
- "w:val": "%2."
19961
- }
19962
- },
19963
- {
19964
- type: "element",
19965
- name: "w:lvlJc",
19966
- attributes: {
19967
- "w:val": "left"
19968
- }
19969
- },
19970
- {
19971
- type: "element",
19972
- name: "w:pPr",
19973
- elements: [
19974
- {
19975
- type: "element",
19976
- name: "w:ind",
19977
- attributes: {
19978
- "w:left": "1440",
19979
- "w:hanging": "360"
19980
- }
19981
- }
19982
- ]
19983
- }
19984
- ]
19985
- },
19986
- {
19987
- type: "element",
19988
- name: "w:lvl",
19989
- attributes: {
19990
- "w:ilvl": "2",
19991
- "w:tplc": "0409001B",
19992
- "w:tentative": "1"
19993
- },
19994
- elements: [
19995
- {
19996
- type: "element",
19997
- name: "w:start",
19998
- attributes: {
19999
- "w:val": "1"
20000
- }
20001
- },
20002
- {
20003
- type: "element",
20004
- name: "w:numFmt",
20005
- attributes: {
20006
- "w:val": "lowerRoman"
20007
- }
20008
- },
20009
- {
20010
- type: "element",
20011
- name: "w:lvlText",
20012
- attributes: {
20013
- "w:val": "%3."
20014
- }
20015
- },
20016
- {
20017
- type: "element",
20018
- name: "w:lvlJc",
20019
- attributes: {
20020
- "w:val": "right"
20021
- }
20022
- },
20023
- {
20024
- type: "element",
20025
- name: "w:pPr",
20026
- elements: [
20027
- {
20028
- type: "element",
20029
- name: "w:ind",
20030
- attributes: {
20031
- "w:left": "2160",
20032
- "w:hanging": "180"
20033
- }
20034
- }
20035
- ]
20036
- }
20037
- ]
20038
- },
20039
- {
20040
- type: "element",
20041
- name: "w:lvl",
20042
- attributes: {
20043
- "w:ilvl": "3",
20044
- "w:tplc": "0409000F",
20045
- "w:tentative": "1"
20046
- },
20047
- elements: [
20048
- {
20049
- type: "element",
20050
- name: "w:start",
20051
- attributes: {
20052
- "w:val": "1"
20053
- }
20054
- },
20055
- {
20056
- type: "element",
20057
- name: "w:numFmt",
20058
- attributes: {
20059
- "w:val": "decimal"
20060
- }
20061
- },
20062
- {
20063
- type: "element",
20064
- name: "w:lvlText",
20065
- attributes: {
20066
- "w:val": "%4."
20067
- }
20068
- },
20069
- {
20070
- type: "element",
20071
- name: "w:lvlJc",
20072
- attributes: {
20073
- "w:val": "left"
20074
- }
20075
- },
20076
- {
20077
- type: "element",
20078
- name: "w:pPr",
20079
- elements: [
20080
- {
20081
- type: "element",
20082
- name: "w:ind",
20083
- attributes: {
20084
- "w:left": "2880",
20085
- "w:hanging": "360"
20086
- }
20087
- }
20088
- ]
20089
- }
20090
- ]
20091
- },
20092
- {
20093
- type: "element",
20094
- name: "w:lvl",
20095
- attributes: {
20096
- "w:ilvl": "4",
20097
- "w:tplc": "04090019",
20098
- "w:tentative": "1"
20099
- },
20100
- elements: [
20101
- {
20102
- type: "element",
20103
- name: "w:start",
20104
- attributes: {
20105
- "w:val": "1"
20106
- }
20107
- },
20108
- {
20109
- type: "element",
20110
- name: "w:numFmt",
20111
- attributes: {
20112
- "w:val": "lowerLetter"
20113
- }
20114
- },
20115
- {
20116
- type: "element",
20117
- name: "w:lvlText",
20118
- attributes: {
20119
- "w:val": "%5."
20120
- }
20121
- },
20122
- {
20123
- type: "element",
20124
- name: "w:lvlJc",
20125
- attributes: {
20126
- "w:val": "left"
20127
- }
20128
- },
20129
- {
20130
- type: "element",
20131
- name: "w:pPr",
20132
- elements: [
20133
- {
20134
- type: "element",
20135
- name: "w:ind",
20136
- attributes: {
20137
- "w:left": "3600",
20138
- "w:hanging": "360"
20139
- }
20140
- }
20141
- ]
20142
- }
20143
- ]
20144
- },
20145
- {
20146
- type: "element",
20147
- name: "w:lvl",
20148
- attributes: {
20149
- "w:ilvl": "5",
20150
- "w:tplc": "0409001B",
20151
- "w:tentative": "1"
20152
- },
20153
- elements: [
20154
- {
20155
- type: "element",
20156
- name: "w:start",
20157
- attributes: {
20158
- "w:val": "1"
20159
- }
20160
- },
20161
- {
20162
- type: "element",
20163
- name: "w:numFmt",
20164
- attributes: {
20165
- "w:val": "lowerRoman"
20166
- }
20167
- },
20168
- {
20169
- type: "element",
20170
- name: "w:lvlText",
20171
- attributes: {
20172
- "w:val": "%6."
20173
- }
20174
- },
20175
- {
20176
- type: "element",
20177
- name: "w:lvlJc",
20178
- attributes: {
20179
- "w:val": "right"
20180
- }
20181
- },
20182
- {
20183
- type: "element",
20184
- name: "w:pPr",
20185
- elements: [
20186
- {
20187
- type: "element",
20188
- name: "w:ind",
20189
- attributes: {
20190
- "w:left": "4320",
20191
- "w:hanging": "180"
20192
- }
20193
- }
20194
- ]
20195
- }
20196
- ]
20197
- },
20198
- {
20199
- type: "element",
20200
- name: "w:lvl",
20201
- attributes: {
20202
- "w:ilvl": "6",
20203
- "w:tplc": "0409000F",
20204
- "w:tentative": "1"
20205
- },
20206
- elements: [
20207
- {
20208
- type: "element",
20209
- name: "w:start",
20210
- attributes: {
20211
- "w:val": "1"
20212
- }
20213
- },
20214
- {
20215
- type: "element",
20216
- name: "w:numFmt",
20217
- attributes: {
20218
- "w:val": "decimal"
20219
- }
20220
- },
20221
- {
20222
- type: "element",
20223
- name: "w:lvlText",
20224
- attributes: {
20225
- "w:val": "%7."
20226
- }
20227
- },
20228
- {
20229
- type: "element",
20230
- name: "w:lvlJc",
20231
- attributes: {
20232
- "w:val": "left"
20233
- }
20234
- },
20235
- {
20236
- type: "element",
20237
- name: "w:pPr",
20238
- elements: [
20239
- {
20240
- type: "element",
20241
- name: "w:ind",
20242
- attributes: {
20243
- "w:left": "5040",
20244
- "w:hanging": "360"
20245
- }
20246
- }
20247
- ]
20248
- }
20249
- ]
20250
- },
20251
- {
20252
- type: "element",
20253
- name: "w:lvl",
20254
- attributes: {
20255
- "w:ilvl": "7",
20256
- "w:tplc": "04090019",
20257
- "w:tentative": "1"
20258
- },
20259
- elements: [
20260
- {
20261
- type: "element",
20262
- name: "w:start",
20263
- attributes: {
20264
- "w:val": "1"
20265
- }
20266
- },
20267
- {
20268
- type: "element",
20269
- name: "w:numFmt",
20270
- attributes: {
20271
- "w:val": "lowerLetter"
20272
- }
20273
- },
20274
- {
20275
- type: "element",
20276
- name: "w:lvlText",
20277
- attributes: {
20278
- "w:val": "%8."
20279
- }
20280
- },
20281
- {
20282
- type: "element",
20283
- name: "w:lvlJc",
20284
- attributes: {
20285
- "w:val": "left"
20286
- }
20287
- },
20288
- {
20289
- type: "element",
20290
- name: "w:pPr",
20291
- elements: [
20292
- {
20293
- type: "element",
20294
- name: "w:ind",
20295
- attributes: {
20296
- "w:left": "5760",
20297
- "w:hanging": "360"
20298
- }
20299
- }
20300
- ]
20301
- }
20302
- ]
20303
- },
20304
- {
20305
- type: "element",
20306
- name: "w:lvl",
20307
- attributes: {
20308
- "w:ilvl": "8",
20309
- "w:tplc": "0409001B",
20310
- "w:tentative": "1"
20311
- },
20312
- elements: [
20313
- {
20314
- type: "element",
20315
- name: "w:start",
20316
- attributes: {
20317
- "w:val": "1"
20318
- }
20319
- },
20320
- {
20321
- type: "element",
20322
- name: "w:numFmt",
20323
- attributes: {
20324
- "w:val": "lowerRoman"
20325
- }
20326
- },
20327
- {
20328
- type: "element",
20329
- name: "w:lvlText",
20330
- attributes: {
20331
- "w:val": "%9."
20332
- }
20333
- },
20334
- {
20335
- type: "element",
20336
- name: "w:lvlJc",
20337
- attributes: {
20338
- "w:val": "right"
20339
- }
20340
- },
20341
- {
20342
- type: "element",
20343
- name: "w:pPr",
20344
- elements: [
20345
- {
20346
- type: "element",
20347
- name: "w:ind",
20348
- attributes: {
20349
- "w:left": "6480",
20350
- "w:hanging": "180"
20351
- }
20352
- }
20353
- ]
20354
- }
20355
- ]
20356
- }
20357
- ]
20358
- },
20359
- {
20360
- type: "element",
20361
- name: "w:num",
20362
- attributes: {
20363
- "w:numId": "1",
20364
- "w16cid:durableId": "100147962"
20365
- },
20366
- elements: [
20367
- {
20368
- type: "element",
20369
- name: "w:abstractNumId",
20370
- attributes: {
20371
- "w:val": "0"
20372
- }
20373
- }
20374
- ]
20375
- },
20376
- {
20377
- type: "element",
20378
- name: "w:num",
20379
- attributes: {
20380
- "w:numId": "2",
20381
- "w16cid:durableId": "485517411"
20382
- },
20383
- elements: [
20384
- {
20385
- type: "element",
20386
- name: "w:abstractNumId",
20387
- attributes: {
20388
- "w:val": "1"
20389
- }
20390
- }
20391
- ]
20392
- }
20393
- ]
20394
- }
20395
- ]
20396
- };
20397
- function translateCommentNode(params2, type2) {
20398
- const { node: node2, commentsExportType, exportedCommentDefs = [] } = params2;
20399
- if (!exportedCommentDefs.length || commentsExportType === "clean") return;
20400
- const nodeId = node2.attrs["w:id"];
20401
- const originalComment = params2.comments.find((comment) => {
20402
- return comment.commentId == nodeId;
20403
- });
20404
- if (!originalComment) return;
20405
- const commentIndex = params2.comments?.findIndex((comment) => comment.commentId === originalComment.commentId);
20406
- const parentId = originalComment.parentCommentId;
20407
- let parentComment;
20408
- if (parentId) {
20409
- parentComment = params2.comments.find((c2) => c2.commentId === parentId || c2.importedId === parentId);
20410
- }
20411
- const isInternal = parentComment?.isInternal || originalComment.isInternal;
20412
- if (commentsExportType === "external" && isInternal) return;
20413
- const isResolved = !!originalComment.resolvedTime;
20414
- if (isResolved) return;
20415
- let commentSchema = getCommentSchema(type2, commentIndex);
20416
- if (type2 === "End") {
20417
- const commentReference = {
20418
- name: "w:r",
20419
- elements: [{ name: "w:commentReference", attributes: { "w:id": String(commentIndex) } }]
20420
- };
20421
- commentSchema = [commentSchema, commentReference];
20422
- }
20423
- return commentSchema;
20424
- }
20425
- const getCommentSchema = (type2, commentId) => {
20426
- return {
20427
- name: `w:commentRange${type2}`,
20428
- attributes: {
20429
- "w:id": String(commentId)
20430
- }
20431
- };
20432
- };
20433
- const prepareCommentParaIds = (comment) => {
20434
- const newComment = {
20435
- ...comment,
20436
- commentParaId: generateRandom32BitHex()
20437
- };
20438
- return newComment;
20439
- };
20440
- const getCommentDefinition = (comment, commentId, allComments, editor) => {
20441
- const translatedText = translateParagraphNode({ editor, node: comment.commentJSON });
20442
- const attributes = {
20443
- "w:id": String(commentId),
20444
- "w:author": comment.creatorName || comment.importedAuthor?.name,
20445
- "w:email": comment.creatorEmail || comment.importedAuthor?.email,
20446
- "w:date": toIsoNoFractional(comment.createdTime),
20447
- "w:initials": getInitials(comment.creatorName),
20448
- "w:done": comment.resolvedTime ? "1" : "0",
20449
- "w15:paraId": comment.commentParaId,
20450
- "custom:internalId": comment.commentId || comment.internalId,
20451
- "custom:trackedChange": comment.trackedChange,
20452
- "custom:trackedChangeText": comment.trackedChangeText || null,
20453
- "custom:trackedChangeType": comment.trackedChangeType,
20454
- "custom:trackedDeletedText": comment.deletedText || null
20455
- };
20456
- if (comment?.parentCommentId) {
20457
- const parentComment = allComments.find((c2) => c2.commentId === comment.parentCommentId);
20458
- attributes["w15:paraIdParent"] = parentComment.commentParaId;
20459
- }
20460
- return {
20461
- type: "element",
20462
- name: "w:comment",
20463
- attributes,
20464
- elements: [translatedText]
20465
- };
20466
- };
20467
- const getInitials = (name) => {
20468
- if (!name) return null;
20469
- const preparedText = name.replace("(imported)", "").trim();
20470
- const initials = preparedText.split(" ").map((word) => word[0]).join("");
20471
- return initials;
20472
- };
20473
- const toIsoNoFractional = (unixMillis) => {
20474
- const date = new Date(unixMillis || Date.now());
20475
- return date.toISOString().replace(/\.\d{3}Z$/, "Z");
20476
- };
20477
- const updateCommentsXml = (commentDefs = [], commentsXml) => {
20478
- const newCommentsXml = carbonCopy(commentsXml);
20479
- commentDefs.forEach((commentDef) => {
20480
- const elements = commentDef.elements[0].elements;
20481
- elements.unshift(COMMENT_REF);
20482
- const paraId = commentDef.attributes["w15:paraId"];
20483
- commentDef.elements[0].attributes["w14:paraId"] = paraId;
20484
- commentDef.attributes = {
20485
- "w:id": commentDef.attributes["w:id"],
20486
- "w:author": commentDef.attributes["w:author"],
20487
- "w:email": commentDef.attributes["w:email"],
20488
- "w:date": commentDef.attributes["w:date"],
20489
- "w:initials": commentDef.attributes["w:initials"],
20490
- "custom:internalId": commentDef.attributes["custom:internalId"],
20491
- "custom:trackedChange": commentDef.attributes["custom:trackedChange"],
20492
- "custom:trackedChangeText": commentDef.attributes["custom:trackedChangeText"],
20493
- "custom:trackedChangeType": commentDef.attributes["custom:trackedChangeType"],
20494
- "custom:trackedDeletedText": commentDef.attributes["custom:trackedDeletedText"],
20495
- "xmlns:custom": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
20496
- };
20497
- });
20498
- newCommentsXml.elements[0].elements = commentDefs;
20499
- return newCommentsXml;
20500
- };
20501
- const updateCommentsExtendedXml = (comments = [], commentsExtendedXml) => {
20502
- const xmlCopy = carbonCopy(commentsExtendedXml);
20503
- const commentsEx = comments.map((comment) => {
20504
- const attributes = {
20505
- "w15:paraId": comment.commentParaId,
20506
- "w15:done": comment.resolvedTime ? "1" : "0"
20507
- };
20508
- const parentId = comment.parentCommentId;
20509
- if (parentId) {
20510
- const parentComment = comments.find((c2) => c2.commentId === parentId);
20511
- attributes["w15:paraIdParent"] = parentComment.commentParaId;
20512
- }
20513
- return {
20514
- type: "element",
20515
- name: "w15:commentEx",
20516
- attributes
20517
- };
20518
- });
20519
- xmlCopy.elements[0].elements = commentsEx;
20520
- return xmlCopy;
20521
- };
20522
- const updateCommentsIdsAndExtensible = (comments = [], commentsIds, extensible) => {
20523
- const documentIdsUpdated = carbonCopy(commentsIds);
20524
- const extensibleUpdated = carbonCopy(extensible);
20525
- documentIdsUpdated.elements[0].elements = [];
20526
- extensibleUpdated.elements[0].elements = [];
20527
- comments.forEach((comment) => {
20528
- const newDurableId = generateRandom32BitHex();
20529
- const newCommentIdDef = {
20530
- type: "element",
20531
- name: "w16cid:commentId",
19289
+ name: "w15:commentEx",
19290
+ attributes
19291
+ };
19292
+ });
19293
+ xmlCopy.elements[0].elements = commentsEx;
19294
+ return xmlCopy;
19295
+ };
19296
+ const updateCommentsIdsAndExtensible = (comments = [], commentsIds, extensible) => {
19297
+ const documentIdsUpdated = carbonCopy(commentsIds);
19298
+ const extensibleUpdated = carbonCopy(extensible);
19299
+ documentIdsUpdated.elements[0].elements = [];
19300
+ extensibleUpdated.elements[0].elements = [];
19301
+ comments.forEach((comment) => {
19302
+ const newDurableId = generateRandom32BitHex();
19303
+ const newCommentIdDef = {
19304
+ type: "element",
19305
+ name: "w16cid:commentId",
20532
19306
  attributes: {
20533
19307
  "w16cid:paraId": comment.commentParaId,
20534
19308
  "w16cid:durableId": newDurableId
@@ -24199,12 +22973,115 @@ const isInTable$1 = (state2) => {
24199
22973
  }
24200
22974
  return false;
24201
22975
  };
22976
+ const getAllSections = (editor) => {
22977
+ if (!editor) return [];
22978
+ const type2 = editor.schema.nodes.documentSection;
22979
+ if (!type2) return [];
22980
+ const sections = [];
22981
+ const { state: state2 } = editor;
22982
+ state2.doc.descendants((node2, pos) => {
22983
+ if (node2.type.name === type2.name) {
22984
+ sections.push({ node: node2, pos });
22985
+ }
22986
+ });
22987
+ return sections;
22988
+ };
22989
+ const exportSectionsToHTML = (editor) => {
22990
+ const sections = getAllSections(editor);
22991
+ const processedSections = /* @__PURE__ */ new Set();
22992
+ const result = [];
22993
+ sections.forEach(({ node: node2 }) => {
22994
+ const { attrs } = node2;
22995
+ const { id, title, description } = attrs;
22996
+ if (processedSections.has(id)) return;
22997
+ processedSections.add(id);
22998
+ const html = getHTMLFromNode(node2, editor);
22999
+ result.push({
23000
+ id,
23001
+ title,
23002
+ description,
23003
+ html
23004
+ });
23005
+ });
23006
+ return result;
23007
+ };
23008
+ const getHTMLFromNode = (node2, editor) => {
23009
+ const tempDocument = document.implementation.createHTMLDocument();
23010
+ const container = tempDocument.createElement("div");
23011
+ const fragment = DOMSerializer.fromSchema(editor.schema).serializeFragment(node2.content);
23012
+ container.appendChild(fragment);
23013
+ let html = container.innerHTML;
23014
+ return html;
23015
+ };
23016
+ const exportSectionsToJSON = (editor) => {
23017
+ const sections = getAllSections(editor);
23018
+ const processedSections = /* @__PURE__ */ new Set();
23019
+ const result = [];
23020
+ sections.forEach(({ node: node2 }) => {
23021
+ const { attrs } = node2;
23022
+ const { id, title, description } = attrs;
23023
+ if (processedSections.has(id)) return;
23024
+ processedSections.add(id);
23025
+ result.push({
23026
+ id,
23027
+ title,
23028
+ description,
23029
+ content: node2.toJSON()
23030
+ });
23031
+ });
23032
+ return result;
23033
+ };
23034
+ const getLinkedSectionEditor = (id, options, editor) => {
23035
+ const sections = getAllSections(editor);
23036
+ const section = sections.find((s) => s.node.attrs.id === id);
23037
+ if (!section) return null;
23038
+ const child = editor.createChildEditor({
23039
+ ...options,
23040
+ onUpdate: ({ editor: childEditor, transaction }) => {
23041
+ const isFromtLinkedParent = transaction.getMeta("fromLinkedParent");
23042
+ if (isFromtLinkedParent) return;
23043
+ const updatedContent = childEditor.state.doc.content;
23044
+ const sectionNode = getAllSections(editor)?.find((s) => s.node.attrs.id === id);
23045
+ if (!sectionNode) return;
23046
+ const { pos, node: node2 } = sectionNode;
23047
+ const newNode = node2.type.create(node2.attrs, updatedContent, node2.marks);
23048
+ const tr = editor.state.tr.replaceWith(pos, pos + node2.nodeSize, newNode);
23049
+ tr.setMeta("fromLinkedChild", true);
23050
+ editor.view.dispatch(tr);
23051
+ }
23052
+ });
23053
+ editor.on("update", ({ transaction }) => {
23054
+ const isFromLinkedChild = transaction.getMeta("fromLinkedChild");
23055
+ if (isFromLinkedChild) return;
23056
+ const sectionNode = getAllSections(editor)?.find((s) => s.node.attrs.id === id);
23057
+ if (!sectionNode) return;
23058
+ const sectionContent = sectionNode.node.content;
23059
+ const json = {
23060
+ type: "doc",
23061
+ content: sectionContent.content.map((node2) => node2.toJSON())
23062
+ };
23063
+ const childTr = child.state.tr;
23064
+ childTr.setMeta("fromLinkedParent", true);
23065
+ childTr.replaceWith(0, child.state.doc.content.size, child.schema.nodeFromJSON(json));
23066
+ child.view.dispatch(childTr);
23067
+ });
23068
+ return child;
23069
+ };
23070
+ const SectionHelpers = {
23071
+ getAllSections,
23072
+ exportSectionsToHTML,
23073
+ exportSectionsToJSON,
23074
+ getLinkedSectionEditor
23075
+ };
24202
23076
  const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
24203
23077
  __proto__: null,
23078
+ SectionHelpers,
24204
23079
  chainableEditorState,
24205
23080
  cleanSchemaItem,
24206
23081
  createDocument,
24207
23082
  defaultBlockAt: defaultBlockAt$1,
23083
+ exportSectionsToHTML,
23084
+ exportSectionsToJSON,
24208
23085
  findChildren: findChildren$4,
24209
23086
  findMark,
24210
23087
  findParentNode,
@@ -24214,6 +23091,7 @@ const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
24214
23091
  generateRandom32BitHex,
24215
23092
  getActiveFormatting,
24216
23093
  getExtensionConfigField,
23094
+ getLinkedSectionEditor,
24217
23095
  getMarkRange,
24218
23096
  getMarkType,
24219
23097
  getMarksBetween,
@@ -24544,472 +23422,1767 @@ const intToRoman = (num) => {
24544
23422
  }
24545
23423
  return result;
24546
23424
  };
24547
- const intToAlpha = (num) => {
24548
- let result = "";
24549
- const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
24550
- while (num > 0) {
24551
- let index2 = (num - 1) % 26;
24552
- result = alphabet[index2] + result;
24553
- num = Math.floor((num - 1) / 26);
23425
+ const intToAlpha = (num) => {
23426
+ let result = "";
23427
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
23428
+ while (num > 0) {
23429
+ let index2 = (num - 1) % 26;
23430
+ result = alphabet[index2] + result;
23431
+ num = Math.floor((num - 1) / 26);
23432
+ }
23433
+ return result;
23434
+ };
23435
+ function flattenListsInHtml(html, editor) {
23436
+ let parser, NodeInterface;
23437
+ if (editor.options.mockDocument) {
23438
+ const win = editor.options.mockDocument.defaultView;
23439
+ parser = new win.DOMParser();
23440
+ NodeInterface = win.Node;
23441
+ } else {
23442
+ parser = new DOMParser();
23443
+ NodeInterface = window.Node;
23444
+ }
23445
+ const doc2 = parser.parseFromString(html, "text/html");
23446
+ let foundList;
23447
+ while (foundList = findListToFlatten(doc2)) {
23448
+ flattenFoundList(foundList, editor, NodeInterface);
23449
+ }
23450
+ return doc2.body.innerHTML;
23451
+ }
23452
+ function findListToFlatten(doc2) {
23453
+ let list = doc2.querySelector("ol:not([data-list-id]), ul:not([data-list-id])");
23454
+ if (list) return list;
23455
+ const allLists = doc2.querySelectorAll("ol[data-list-id], ul[data-list-id]");
23456
+ for (const list2 of allLists) {
23457
+ const liChildren = Array.from(list2.children).filter((c2) => c2.tagName.toLowerCase() === "li");
23458
+ if (liChildren.length > 1) {
23459
+ return list2;
23460
+ }
23461
+ const nestedLists = list2.querySelectorAll("ol, ul");
23462
+ if (nestedLists.length > 0) {
23463
+ return list2;
23464
+ }
23465
+ }
23466
+ return null;
23467
+ }
23468
+ function flattenFoundList(listElem, editor, NodeInterface) {
23469
+ const localDoc = listElem.ownerDocument;
23470
+ const tag = listElem.tagName.toLowerCase();
23471
+ let rootNumId = listElem.getAttribute("data-list-id");
23472
+ if (!rootNumId) {
23473
+ rootNumId = ListHelpers.getNewListId(editor);
23474
+ ListHelpers.generateNewListDefinition({
23475
+ numId: rootNumId,
23476
+ listType: tag === "ol" ? "orderedList" : "bulletList",
23477
+ editor
23478
+ });
23479
+ }
23480
+ let level = 0;
23481
+ let ancestor = listElem.parentElement;
23482
+ while (ancestor && ancestor !== localDoc.body) {
23483
+ if (ancestor.tagName && ancestor.tagName.toLowerCase() === "li") {
23484
+ level++;
23485
+ }
23486
+ ancestor = ancestor.parentElement;
23487
+ }
23488
+ const items = Array.from(listElem.children).filter((c2) => c2.tagName.toLowerCase() === "li");
23489
+ const newLists = [];
23490
+ items.forEach((li, index2) => {
23491
+ const nestedLists = Array.from(li.querySelectorAll("ol, ul"));
23492
+ const nestedListsData = nestedLists.map((nl) => ({
23493
+ element: nl.cloneNode(true),
23494
+ parent: nl.parentNode
23495
+ }));
23496
+ nestedLists.forEach((nl) => nl.parentNode.removeChild(nl));
23497
+ const newList = createSingleItemList(li, tag, rootNumId, level, editor, NodeInterface);
23498
+ newLists.push(newList);
23499
+ nestedListsData.forEach((data) => {
23500
+ newLists.push(data.element);
23501
+ });
23502
+ });
23503
+ const parent = listElem.parentNode;
23504
+ const nextSibling = listElem.nextSibling;
23505
+ parent.removeChild(listElem);
23506
+ newLists.forEach((list) => {
23507
+ parent.insertBefore(list, nextSibling);
23508
+ });
23509
+ }
23510
+ function createSingleItemList(li, tag, rootNumId, level, editor, NodeInterface) {
23511
+ const localDoc = li.ownerDocument;
23512
+ const ELEMENT_NODE = NodeInterface.ELEMENT_NODE;
23513
+ const TEXT_NODE = NodeInterface.TEXT_NODE;
23514
+ const newList = localDoc.createElement(tag);
23515
+ const newLi = localDoc.createElement("li");
23516
+ Array.from(li.attributes).forEach((attr) => {
23517
+ if (!attr.name.startsWith("data-num-") && !attr.name.startsWith("data-level") && !attr.name.startsWith("data-list-")) {
23518
+ newLi.setAttribute(attr.name, attr.value);
23519
+ }
23520
+ });
23521
+ newList.setAttribute("data-list-id", rootNumId);
23522
+ newLi.setAttribute("data-num-id", rootNumId);
23523
+ newLi.setAttribute("data-level", String(level));
23524
+ const { listNumberingType, lvlText } = ListHelpers.getListDefinitionDetails({
23525
+ numId: rootNumId,
23526
+ level,
23527
+ editor
23528
+ });
23529
+ newLi.setAttribute("data-num-fmt", listNumberingType);
23530
+ newLi.setAttribute("data-lvl-text", lvlText || "");
23531
+ newLi.setAttribute("data-list-level", JSON.stringify([level + 1]));
23532
+ Array.from(li.childNodes).forEach((node2) => {
23533
+ if (node2.nodeType === ELEMENT_NODE || node2.nodeType === TEXT_NODE && node2.textContent.trim()) {
23534
+ newLi.appendChild(node2.cloneNode(true));
23535
+ }
23536
+ });
23537
+ if (newLi.childNodes.length === 0 || newLi.childNodes.length === 1 && newLi.childNodes[0].nodeType === TEXT_NODE) {
23538
+ const textContent2 = newLi.textContent.trim();
23539
+ if (textContent2) {
23540
+ newLi.innerHTML = "";
23541
+ const p = localDoc.createElement("p");
23542
+ p.textContent = textContent2;
23543
+ newLi.appendChild(p);
23544
+ }
23545
+ }
23546
+ newList.appendChild(newLi);
23547
+ return newList;
23548
+ }
23549
+ function unflattenListsInHtml(html) {
23550
+ const parser = new DOMParser();
23551
+ const doc2 = parser.parseFromString(html, "text/html");
23552
+ const allNodes = [...doc2.body.children];
23553
+ const listSequences = [];
23554
+ let currentSequence = null;
23555
+ allNodes.forEach((node2, index2) => {
23556
+ const isFlattenList = node2.tagName && (node2.tagName === "OL" || node2.tagName === "UL") && node2.hasAttribute("data-list-id");
23557
+ if (isFlattenList) {
23558
+ const listId = node2.getAttribute("data-list-id");
23559
+ if (currentSequence && currentSequence.id === listId) {
23560
+ currentSequence.lists.push({ element: node2, index: index2 });
23561
+ } else {
23562
+ currentSequence = {
23563
+ id: listId,
23564
+ lists: [{ element: node2, index: index2 }]
23565
+ };
23566
+ listSequences.push(currentSequence);
23567
+ }
23568
+ } else {
23569
+ currentSequence = null;
23570
+ }
23571
+ });
23572
+ listSequences.reverse().forEach((sequence) => {
23573
+ const sequenceLists = sequence.lists;
23574
+ if (sequenceLists.length === 0) {
23575
+ return;
23576
+ }
23577
+ const items = sequenceLists.map(({ element: list }) => {
23578
+ const liElement = list.querySelector("li");
23579
+ if (!liElement) return null;
23580
+ return {
23581
+ element: liElement,
23582
+ level: parseInt(liElement.getAttribute("data-level") || "0"),
23583
+ numFmt: liElement.getAttribute("data-num-fmt") || "bullet",
23584
+ listLevel: JSON.parse(liElement.getAttribute("data-list-level") || "[1]")
23585
+ };
23586
+ }).filter((item) => item !== null);
23587
+ if (items.length === 0) {
23588
+ return;
23589
+ }
23590
+ const rootList = buildNestedList({ items });
23591
+ const firstOriginalList = sequenceLists[0].element;
23592
+ firstOriginalList?.parentNode?.insertBefore(rootList, firstOriginalList);
23593
+ sequenceLists.forEach(({ element: list }) => {
23594
+ if (list.parentNode) list.parentNode.removeChild(list);
23595
+ });
23596
+ });
23597
+ return doc2.body.innerHTML;
23598
+ }
23599
+ function buildNestedList({ items }) {
23600
+ if (!items.length) {
23601
+ return null;
23602
+ }
23603
+ const [rootItem] = items;
23604
+ const doc2 = rootItem.element.ownerDocument;
23605
+ const isOrderedList = rootItem.numFmt && !["bullet", "none"].includes(rootItem.numFmt);
23606
+ const rootList = doc2.createElement(isOrderedList ? "ol" : "ul");
23607
+ if (isOrderedList && rootItem.listLevel?.[0] && rootItem.listLevel[0] > 1) {
23608
+ rootList.setAttribute("start", rootItem.listLevel[0]);
23609
+ }
23610
+ const lastLevelItem = /* @__PURE__ */ new Map();
23611
+ items.forEach((item) => {
23612
+ const { element: liElement, level, numFmt, listLevel } = item;
23613
+ const cleanLi = cleanListItem(liElement.cloneNode(true));
23614
+ if (level === 0) {
23615
+ rootList.append(cleanLi);
23616
+ lastLevelItem.set(0, cleanLi);
23617
+ } else {
23618
+ const parentLi = lastLevelItem.get(level - 1);
23619
+ if (!parentLi) {
23620
+ rootList.append(cleanLi);
23621
+ lastLevelItem.set(level, cleanLi);
23622
+ return;
23623
+ }
23624
+ let nestedList = null;
23625
+ [...parentLi.children].forEach((child) => {
23626
+ if (child.tagName && (child.tagName === "OL" || child.tagName === "UL")) {
23627
+ nestedList = child;
23628
+ }
23629
+ });
23630
+ if (!nestedList) {
23631
+ const listType = numFmt && !["bullet", "none"].includes(numFmt) ? "ol" : "ul";
23632
+ nestedList = doc2.createElement(listType);
23633
+ parentLi.append(nestedList);
23634
+ }
23635
+ nestedList.append(cleanLi);
23636
+ lastLevelItem.set(level, cleanLi);
23637
+ }
23638
+ });
23639
+ return rootList;
23640
+ }
23641
+ function cleanListItem(listItem) {
23642
+ const attrs = [
23643
+ "data-num-id",
23644
+ "data-level",
23645
+ "data-num-fmt",
23646
+ "data-lvl-text",
23647
+ "data-list-level",
23648
+ "data-marker-type",
23649
+ "aria-label"
23650
+ ];
23651
+ attrs.forEach((attr) => {
23652
+ listItem.removeAttribute(attr);
23653
+ });
23654
+ return listItem;
23655
+ }
23656
+ class InputRule {
23657
+ constructor(config) {
23658
+ __publicField$2(this, "match");
23659
+ __publicField$2(this, "handler");
23660
+ this.match = config.match;
23661
+ this.handler = config.handler;
23662
+ }
23663
+ }
23664
+ const inputRuleMatcherHandler = (text, match) => {
23665
+ if (isRegExp(match)) {
23666
+ return match.exec(text);
23667
+ }
23668
+ const inputRuleMatch = match(text);
23669
+ if (!inputRuleMatch) {
23670
+ return null;
23671
+ }
23672
+ const result = [inputRuleMatch.text];
23673
+ result.index = inputRuleMatch.index;
23674
+ result.input = text;
23675
+ result.data = inputRuleMatch.data;
23676
+ if (inputRuleMatch.replaceWith) {
23677
+ if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
23678
+ console.warn('[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".');
23679
+ }
23680
+ result.push(inputRuleMatch.replaceWith);
23681
+ }
23682
+ return result;
23683
+ };
23684
+ const run = (config) => {
23685
+ const { editor, from: from2, to, text, rules, plugin: plugin2 } = config;
23686
+ const { view } = editor;
23687
+ if (view.composing) {
23688
+ return false;
24554
23689
  }
24555
- return result;
23690
+ const $from = view.state.doc.resolve(from2);
23691
+ if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
23692
+ return false;
23693
+ }
23694
+ let matched = false;
23695
+ const textBefore = getTextContentFromNodes($from) + text;
23696
+ rules.forEach((rule) => {
23697
+ if (matched) {
23698
+ return;
23699
+ }
23700
+ const match = inputRuleMatcherHandler(textBefore, rule.match);
23701
+ if (!match) {
23702
+ return;
23703
+ }
23704
+ const tr = view.state.tr;
23705
+ const state2 = chainableEditorState(tr, view.state);
23706
+ const range2 = {
23707
+ from: from2 - (match[0].length - text.length),
23708
+ to
23709
+ };
23710
+ const { commands: commands2, chain, can } = new CommandService({
23711
+ editor,
23712
+ state: state2
23713
+ });
23714
+ const handler = rule.handler({
23715
+ state: state2,
23716
+ range: range2,
23717
+ match,
23718
+ commands: commands2,
23719
+ chain,
23720
+ can
23721
+ });
23722
+ if (handler === null || !tr.steps.length) {
23723
+ return;
23724
+ }
23725
+ tr.setMeta(plugin2, {
23726
+ transform: tr,
23727
+ from: from2,
23728
+ to,
23729
+ text
23730
+ });
23731
+ view.dispatch(tr);
23732
+ matched = true;
23733
+ });
23734
+ return matched;
24556
23735
  };
24557
- function flattenListsInHtml(html, editor) {
24558
- let parser, NodeInterface;
24559
- if (editor.options.mockDocument) {
24560
- const win = editor.options.mockDocument.defaultView;
24561
- parser = new win.DOMParser();
24562
- NodeInterface = win.Node;
23736
+ const inputRulesPlugin = ({ editor, rules }) => {
23737
+ const plugin2 = new Plugin({
23738
+ key: new PluginKey("inputRulesPlugin"),
23739
+ state: {
23740
+ init() {
23741
+ return null;
23742
+ },
23743
+ apply(tr, prev, state2) {
23744
+ const stored = tr.getMeta(plugin2);
23745
+ if (stored) {
23746
+ return stored;
23747
+ }
23748
+ const simulatedInputMeta = tr.getMeta("applyInputRules");
23749
+ const isSimulatedInput = !!simulatedInputMeta;
23750
+ if (isSimulatedInput) {
23751
+ setTimeout(() => {
23752
+ let { text } = simulatedInputMeta;
23753
+ if (typeof text !== "string") {
23754
+ text = getHTMLFromFragment(Fragment.from(text), state2.schema);
23755
+ }
23756
+ const { from: from2 } = simulatedInputMeta;
23757
+ const to = from2 + text.length;
23758
+ run({
23759
+ editor,
23760
+ from: from2,
23761
+ to,
23762
+ text,
23763
+ rules,
23764
+ plugin: plugin2
23765
+ });
23766
+ });
23767
+ }
23768
+ return tr.selectionSet || tr.docChanged ? null : prev;
23769
+ }
23770
+ },
23771
+ props: {
23772
+ handleTextInput(view, from2, to, text) {
23773
+ return run({
23774
+ editor,
23775
+ from: from2,
23776
+ to,
23777
+ text,
23778
+ rules,
23779
+ plugin: plugin2
23780
+ });
23781
+ },
23782
+ // add support for input rules to trigger on enter
23783
+ // this is useful for example for code blocks
23784
+ handleKeyDown(view, event) {
23785
+ if (event.key !== "Enter") {
23786
+ return false;
23787
+ }
23788
+ const { $cursor } = view.state.selection;
23789
+ if ($cursor) {
23790
+ return run({
23791
+ editor,
23792
+ from: $cursor.pos,
23793
+ to: $cursor.pos,
23794
+ text: "\n",
23795
+ rules,
23796
+ plugin: plugin2
23797
+ });
23798
+ }
23799
+ return false;
23800
+ },
23801
+ // Paste handler
23802
+ handlePaste(view, event, slice2) {
23803
+ const clipboard = event.clipboardData;
23804
+ const html = clipboard.getData("text/html");
23805
+ clipboard.getData("text/plain");
23806
+ const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
23807
+ if (fieldAnnotationContent.length) {
23808
+ return false;
23809
+ }
23810
+ return handleClipboardPaste({ editor, view }, html);
23811
+ }
23812
+ },
23813
+ isInputRules: true
23814
+ });
23815
+ return plugin2;
23816
+ };
23817
+ function isWordHtml(html) {
23818
+ return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(
23819
+ html
23820
+ );
23821
+ }
23822
+ function handleHtmlPaste(html, editor) {
23823
+ const cleanedHtml = htmlHandler(html, editor);
23824
+ const doc2 = DOMParser$1.fromSchema(editor.schema).parse(cleanedHtml);
23825
+ const { dispatch, state: state2 } = editor.view;
23826
+ if (!dispatch) return false;
23827
+ const { $from } = state2.selection;
23828
+ const isInParagraph = $from.parent.type.name === "paragraph";
23829
+ const isSingleParagraph = doc2.childCount === 1 && doc2.firstChild.type.name === "paragraph";
23830
+ if (isInParagraph && isSingleParagraph) {
23831
+ const paragraphContent = doc2.firstChild.content;
23832
+ const tr = state2.tr.replaceSelectionWith(paragraphContent, false);
23833
+ dispatch(tr);
24563
23834
  } else {
24564
- parser = new DOMParser();
24565
- NodeInterface = window.Node;
24566
- }
24567
- const doc2 = parser.parseFromString(html, "text/html");
24568
- let foundList;
24569
- while (foundList = findListToFlatten(doc2)) {
24570
- flattenFoundList(foundList, editor, NodeInterface);
23835
+ dispatch(state2.tr.replaceSelectionWith(doc2, true));
24571
23836
  }
24572
- return doc2.body.innerHTML;
23837
+ return true;
24573
23838
  }
24574
- function findListToFlatten(doc2) {
24575
- let list = doc2.querySelector("ol:not([data-list-id]), ul:not([data-list-id])");
24576
- if (list) return list;
24577
- const allLists = doc2.querySelectorAll("ol[data-list-id], ul[data-list-id]");
24578
- for (const list2 of allLists) {
24579
- const liChildren = Array.from(list2.children).filter((c2) => c2.tagName.toLowerCase() === "li");
24580
- if (liChildren.length > 1) {
24581
- return list2;
24582
- }
24583
- const nestedLists = list2.querySelectorAll("ol, ul");
24584
- if (nestedLists.length > 0) {
24585
- return list2;
23839
+ function htmlHandler(html, editor) {
23840
+ const flatHtml = flattenListsInHtml(html, editor);
23841
+ const htmlWithPtSizing = convertEmToPt(flatHtml);
23842
+ return sanitizeHtml(htmlWithPtSizing);
23843
+ }
23844
+ const convertEmToPt = (html) => {
23845
+ return html.replace(/font-size\s*:\s*([\d.]+)em/gi, (_, emValue) => {
23846
+ const em = parseFloat(emValue);
23847
+ const pt = Math.round(em * 12 * 100) / 100;
23848
+ return `font-size: ${pt}pt`;
23849
+ });
23850
+ };
23851
+ function cleanHtmlUnnecessaryTags(html) {
23852
+ return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
23853
+ }
23854
+ function sanitizeHtml(html, forbiddenTags = ["meta", "svg", "script", "style", "button"]) {
23855
+ const container = document.createElement("div");
23856
+ container.innerHTML = html;
23857
+ const walkAndClean = (node2) => {
23858
+ for (const child of [...node2.children]) {
23859
+ if (forbiddenTags.includes(child.tagName.toLowerCase())) {
23860
+ child.remove();
23861
+ continue;
23862
+ }
23863
+ if (child.hasAttribute("linebreaktype")) {
23864
+ child.removeAttribute("linebreaktype");
23865
+ }
23866
+ walkAndClean(child);
24586
23867
  }
24587
- }
24588
- return null;
23868
+ };
23869
+ walkAndClean(container);
23870
+ return container;
24589
23871
  }
24590
- function flattenFoundList(listElem, editor, NodeInterface) {
24591
- const localDoc = listElem.ownerDocument;
24592
- const tag = listElem.tagName.toLowerCase();
24593
- let rootNumId = listElem.getAttribute("data-list-id");
24594
- if (!rootNumId) {
24595
- rootNumId = ListHelpers.getNewListId(editor);
24596
- ListHelpers.generateNewListDefinition({
24597
- numId: rootNumId,
24598
- listType: tag === "ol" ? "orderedList" : "bulletList",
24599
- editor
24600
- });
23872
+ function handleClipboardPaste({ editor, view }, html, text) {
23873
+ let source;
23874
+ if (!html) {
23875
+ source = "plain-text";
23876
+ } else if (isWordHtml(html)) {
23877
+ source = "word-html";
23878
+ } else {
23879
+ source = "browser-html";
24601
23880
  }
24602
- let level = 0;
24603
- let ancestor = listElem.parentElement;
24604
- while (ancestor && ancestor !== localDoc.body) {
24605
- if (ancestor.tagName && ancestor.tagName.toLowerCase() === "li") {
24606
- level++;
24607
- }
24608
- ancestor = ancestor.parentElement;
23881
+ switch (source) {
23882
+ case "plain-text":
23883
+ return false;
23884
+ case "word-html":
23885
+ if (editor.options.mode === "docx") {
23886
+ return handleDocxPaste(html, editor, view);
23887
+ }
23888
+ // falls through to browser-html handling when not in DOCX mode
23889
+ case "browser-html":
23890
+ return handleHtmlPaste(html, editor);
24609
23891
  }
24610
- const items = Array.from(listElem.children).filter((c2) => c2.tagName.toLowerCase() === "li");
24611
- const newLists = [];
24612
- items.forEach((li, index2) => {
24613
- const nestedLists = Array.from(li.querySelectorAll("ol, ul"));
24614
- const nestedListsData = nestedLists.map((nl) => ({
24615
- element: nl.cloneNode(true),
24616
- parent: nl.parentNode
24617
- }));
24618
- nestedLists.forEach((nl) => nl.parentNode.removeChild(nl));
24619
- const newList = createSingleItemList(li, tag, rootNumId, level, editor, NodeInterface);
24620
- newLists.push(newList);
24621
- nestedListsData.forEach((data) => {
24622
- newLists.push(data.element);
24623
- });
24624
- });
24625
- const parent = listElem.parentNode;
24626
- const nextSibling = listElem.nextSibling;
24627
- parent.removeChild(listElem);
24628
- newLists.forEach((list) => {
24629
- parent.insertBefore(list, nextSibling);
23892
+ return false;
23893
+ }
23894
+ function translateChildNodes(params2) {
23895
+ const { content: nodes } = params2.node;
23896
+ if (!nodes) return [];
23897
+ const translatedNodes = [];
23898
+ nodes.forEach((node2) => {
23899
+ let translatedNode = exportSchemaToJson({ ...params2, node: node2 });
23900
+ if (translatedNode instanceof Array) translatedNodes.push(...translatedNode);
23901
+ else translatedNodes.push(translatedNode);
24630
23902
  });
23903
+ return translatedNodes.filter((n) => n);
24631
23904
  }
24632
- function createSingleItemList(li, tag, rootNumId, level, editor, NodeInterface) {
24633
- const localDoc = li.ownerDocument;
24634
- const ELEMENT_NODE = NodeInterface.ELEMENT_NODE;
24635
- const TEXT_NODE = NodeInterface.TEXT_NODE;
24636
- const newList = localDoc.createElement(tag);
24637
- const newLi = localDoc.createElement("li");
24638
- Array.from(li.attributes).forEach((attr) => {
24639
- if (!attr.name.startsWith("data-num-") && !attr.name.startsWith("data-level") && !attr.name.startsWith("data-list-")) {
24640
- newLi.setAttribute(attr.name, attr.value);
23905
+ const baseNumbering = {
23906
+ declaration: {
23907
+ attributes: {
23908
+ version: "1.0",
23909
+ encoding: "UTF-8",
23910
+ standalone: "yes"
23911
+ }
23912
+ },
23913
+ elements: [
23914
+ {
23915
+ type: "element",
23916
+ name: "w:numbering",
23917
+ attributes: {
23918
+ "xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
23919
+ "xmlns:cx": "http://schemas.microsoft.com/office/drawing/2014/chartex",
23920
+ "xmlns:cx1": "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex",
23921
+ "xmlns:cx2": "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex",
23922
+ "xmlns:cx3": "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex",
23923
+ "xmlns:cx4": "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex",
23924
+ "xmlns:cx5": "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex",
23925
+ "xmlns:cx6": "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex",
23926
+ "xmlns:cx7": "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex",
23927
+ "xmlns:cx8": "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex",
23928
+ "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
23929
+ "xmlns:aink": "http://schemas.microsoft.com/office/drawing/2016/ink",
23930
+ "xmlns:am3d": "http://schemas.microsoft.com/office/drawing/2017/model3d",
23931
+ "xmlns:o": "urn:schemas-microsoft-com:office:office",
23932
+ "xmlns:oel": "http://schemas.microsoft.com/office/2019/extlst",
23933
+ "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
23934
+ "xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
23935
+ "xmlns:v": "urn:schemas-microsoft-com:vml",
23936
+ "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
23937
+ "xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
23938
+ "xmlns:w10": "urn:schemas-microsoft-com:office:word",
23939
+ "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
23940
+ "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
23941
+ "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
23942
+ "xmlns:w16cex": "http://schemas.microsoft.com/office/word/2018/wordml/cex",
23943
+ "xmlns:w16cid": "http://schemas.microsoft.com/office/word/2016/wordml/cid",
23944
+ "xmlns:w16": "http://schemas.microsoft.com/office/word/2018/wordml",
23945
+ "xmlns:w16du": "http://schemas.microsoft.com/office/word/2023/wordml/word16du",
23946
+ "xmlns:w16sdtdh": "http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash",
23947
+ "xmlns:w16se": "http://schemas.microsoft.com/office/word/2015/wordml/symex",
23948
+ "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
23949
+ "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
23950
+ "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml",
23951
+ "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
23952
+ "mc:Ignorable": "w14 w15 w16se w16cid w16 w16cex w16sdtdh w16du wp14"
23953
+ },
23954
+ elements: [
23955
+ {
23956
+ type: "element",
23957
+ name: "w:abstractNum",
23958
+ attributes: {
23959
+ "w:abstractNumId": "0",
23960
+ "w15:restartNumberingAfterBreak": "0"
23961
+ },
23962
+ elements: [
23963
+ {
23964
+ type: "element",
23965
+ name: "w:nsid",
23966
+ attributes: {
23967
+ "w:val": "16126B07"
23968
+ }
23969
+ },
23970
+ {
23971
+ type: "element",
23972
+ name: "w:multiLevelType",
23973
+ attributes: {
23974
+ "w:val": "hybridMultilevel"
23975
+ }
23976
+ },
23977
+ {
23978
+ type: "element",
23979
+ name: "w:lvl",
23980
+ attributes: {
23981
+ "w:ilvl": "0",
23982
+ "w:tplc": "04090001"
23983
+ },
23984
+ elements: [
23985
+ {
23986
+ type: "element",
23987
+ name: "w:start",
23988
+ attributes: {
23989
+ "w:val": "1"
23990
+ }
23991
+ },
23992
+ {
23993
+ type: "element",
23994
+ name: "w:numFmt",
23995
+ attributes: {
23996
+ "w:val": "bullet"
23997
+ }
23998
+ },
23999
+ {
24000
+ type: "element",
24001
+ name: "w:lvlText",
24002
+ attributes: {
24003
+ "w:val": ""
24004
+ }
24005
+ },
24006
+ {
24007
+ type: "element",
24008
+ name: "w:lvlJc",
24009
+ attributes: {
24010
+ "w:val": "left"
24011
+ }
24012
+ },
24013
+ {
24014
+ type: "element",
24015
+ name: "w:pPr",
24016
+ elements: [
24017
+ {
24018
+ type: "element",
24019
+ name: "w:ind",
24020
+ attributes: {
24021
+ "w:left": "720",
24022
+ "w:hanging": "360"
24023
+ }
24024
+ }
24025
+ ]
24026
+ },
24027
+ {
24028
+ type: "element",
24029
+ name: "w:rPr",
24030
+ elements: [
24031
+ {
24032
+ type: "element",
24033
+ name: "w:rFonts",
24034
+ attributes: {
24035
+ "w:ascii": "Symbol",
24036
+ "w:hAnsi": "Symbol",
24037
+ "w:hint": "default"
24038
+ }
24039
+ }
24040
+ ]
24041
+ }
24042
+ ]
24043
+ },
24044
+ {
24045
+ type: "element",
24046
+ name: "w:lvl",
24047
+ attributes: {
24048
+ "w:ilvl": "1",
24049
+ "w:tplc": "04090003",
24050
+ "w:tentative": "1"
24051
+ },
24052
+ elements: [
24053
+ {
24054
+ type: "element",
24055
+ name: "w:start",
24056
+ attributes: {
24057
+ "w:val": "1"
24058
+ }
24059
+ },
24060
+ {
24061
+ type: "element",
24062
+ name: "w:numFmt",
24063
+ attributes: {
24064
+ "w:val": "bullet"
24065
+ }
24066
+ },
24067
+ {
24068
+ type: "element",
24069
+ name: "w:lvlText",
24070
+ attributes: {
24071
+ "w:val": "o"
24072
+ }
24073
+ },
24074
+ {
24075
+ type: "element",
24076
+ name: "w:lvlJc",
24077
+ attributes: {
24078
+ "w:val": "left"
24079
+ }
24080
+ },
24081
+ {
24082
+ type: "element",
24083
+ name: "w:pPr",
24084
+ elements: [
24085
+ {
24086
+ type: "element",
24087
+ name: "w:ind",
24088
+ attributes: {
24089
+ "w:left": "1440",
24090
+ "w:hanging": "360"
24091
+ }
24092
+ }
24093
+ ]
24094
+ },
24095
+ {
24096
+ type: "element",
24097
+ name: "w:rPr",
24098
+ elements: [
24099
+ {
24100
+ type: "element",
24101
+ name: "w:rFonts",
24102
+ attributes: {
24103
+ "w:ascii": "Courier New",
24104
+ "w:hAnsi": "Courier New",
24105
+ "w:cs": "Courier New",
24106
+ "w:hint": "default"
24107
+ }
24108
+ }
24109
+ ]
24110
+ }
24111
+ ]
24112
+ },
24113
+ {
24114
+ type: "element",
24115
+ name: "w:lvl",
24116
+ attributes: {
24117
+ "w:ilvl": "2",
24118
+ "w:tplc": "04090005",
24119
+ "w:tentative": "1"
24120
+ },
24121
+ elements: [
24122
+ {
24123
+ type: "element",
24124
+ name: "w:start",
24125
+ attributes: {
24126
+ "w:val": "1"
24127
+ }
24128
+ },
24129
+ {
24130
+ type: "element",
24131
+ name: "w:numFmt",
24132
+ attributes: {
24133
+ "w:val": "bullet"
24134
+ }
24135
+ },
24136
+ {
24137
+ type: "element",
24138
+ name: "w:lvlText",
24139
+ attributes: {
24140
+ "w:val": ""
24141
+ }
24142
+ },
24143
+ {
24144
+ type: "element",
24145
+ name: "w:lvlJc",
24146
+ attributes: {
24147
+ "w:val": "left"
24148
+ }
24149
+ },
24150
+ {
24151
+ type: "element",
24152
+ name: "w:pPr",
24153
+ elements: [
24154
+ {
24155
+ type: "element",
24156
+ name: "w:ind",
24157
+ attributes: {
24158
+ "w:left": "2160",
24159
+ "w:hanging": "360"
24160
+ }
24161
+ }
24162
+ ]
24163
+ },
24164
+ {
24165
+ type: "element",
24166
+ name: "w:rPr",
24167
+ elements: [
24168
+ {
24169
+ type: "element",
24170
+ name: "w:rFonts",
24171
+ attributes: {
24172
+ "w:ascii": "Wingdings",
24173
+ "w:hAnsi": "Wingdings",
24174
+ "w:hint": "default"
24175
+ }
24176
+ }
24177
+ ]
24178
+ }
24179
+ ]
24180
+ },
24181
+ {
24182
+ type: "element",
24183
+ name: "w:lvl",
24184
+ attributes: {
24185
+ "w:ilvl": "3",
24186
+ "w:tplc": "04090001",
24187
+ "w:tentative": "1"
24188
+ },
24189
+ elements: [
24190
+ {
24191
+ type: "element",
24192
+ name: "w:start",
24193
+ attributes: {
24194
+ "w:val": "1"
24195
+ }
24196
+ },
24197
+ {
24198
+ type: "element",
24199
+ name: "w:numFmt",
24200
+ attributes: {
24201
+ "w:val": "bullet"
24202
+ }
24203
+ },
24204
+ {
24205
+ type: "element",
24206
+ name: "w:lvlText",
24207
+ attributes: {
24208
+ "w:val": ""
24209
+ }
24210
+ },
24211
+ {
24212
+ type: "element",
24213
+ name: "w:lvlJc",
24214
+ attributes: {
24215
+ "w:val": "left"
24216
+ }
24217
+ },
24218
+ {
24219
+ type: "element",
24220
+ name: "w:pPr",
24221
+ elements: [
24222
+ {
24223
+ type: "element",
24224
+ name: "w:ind",
24225
+ attributes: {
24226
+ "w:left": "2880",
24227
+ "w:hanging": "360"
24228
+ }
24229
+ }
24230
+ ]
24231
+ },
24232
+ {
24233
+ type: "element",
24234
+ name: "w:rPr",
24235
+ elements: [
24236
+ {
24237
+ type: "element",
24238
+ name: "w:rFonts",
24239
+ attributes: {
24240
+ "w:ascii": "Symbol",
24241
+ "w:hAnsi": "Symbol",
24242
+ "w:hint": "default"
24243
+ }
24244
+ }
24245
+ ]
24246
+ }
24247
+ ]
24248
+ },
24249
+ {
24250
+ type: "element",
24251
+ name: "w:lvl",
24252
+ attributes: {
24253
+ "w:ilvl": "4",
24254
+ "w:tplc": "04090003",
24255
+ "w:tentative": "1"
24256
+ },
24257
+ elements: [
24258
+ {
24259
+ type: "element",
24260
+ name: "w:start",
24261
+ attributes: {
24262
+ "w:val": "1"
24263
+ }
24264
+ },
24265
+ {
24266
+ type: "element",
24267
+ name: "w:numFmt",
24268
+ attributes: {
24269
+ "w:val": "bullet"
24270
+ }
24271
+ },
24272
+ {
24273
+ type: "element",
24274
+ name: "w:lvlText",
24275
+ attributes: {
24276
+ "w:val": "o"
24277
+ }
24278
+ },
24279
+ {
24280
+ type: "element",
24281
+ name: "w:lvlJc",
24282
+ attributes: {
24283
+ "w:val": "left"
24284
+ }
24285
+ },
24286
+ {
24287
+ type: "element",
24288
+ name: "w:pPr",
24289
+ elements: [
24290
+ {
24291
+ type: "element",
24292
+ name: "w:ind",
24293
+ attributes: {
24294
+ "w:left": "3600",
24295
+ "w:hanging": "360"
24296
+ }
24297
+ }
24298
+ ]
24299
+ },
24300
+ {
24301
+ type: "element",
24302
+ name: "w:rPr",
24303
+ elements: [
24304
+ {
24305
+ type: "element",
24306
+ name: "w:rFonts",
24307
+ attributes: {
24308
+ "w:ascii": "Courier New",
24309
+ "w:hAnsi": "Courier New",
24310
+ "w:cs": "Courier New",
24311
+ "w:hint": "default"
24312
+ }
24313
+ }
24314
+ ]
24315
+ }
24316
+ ]
24317
+ },
24318
+ {
24319
+ type: "element",
24320
+ name: "w:lvl",
24321
+ attributes: {
24322
+ "w:ilvl": "5",
24323
+ "w:tplc": "04090005",
24324
+ "w:tentative": "1"
24325
+ },
24326
+ elements: [
24327
+ {
24328
+ type: "element",
24329
+ name: "w:start",
24330
+ attributes: {
24331
+ "w:val": "1"
24332
+ }
24333
+ },
24334
+ {
24335
+ type: "element",
24336
+ name: "w:numFmt",
24337
+ attributes: {
24338
+ "w:val": "bullet"
24339
+ }
24340
+ },
24341
+ {
24342
+ type: "element",
24343
+ name: "w:lvlText",
24344
+ attributes: {
24345
+ "w:val": ""
24346
+ }
24347
+ },
24348
+ {
24349
+ type: "element",
24350
+ name: "w:lvlJc",
24351
+ attributes: {
24352
+ "w:val": "left"
24353
+ }
24354
+ },
24355
+ {
24356
+ type: "element",
24357
+ name: "w:pPr",
24358
+ elements: [
24359
+ {
24360
+ type: "element",
24361
+ name: "w:ind",
24362
+ attributes: {
24363
+ "w:left": "4320",
24364
+ "w:hanging": "360"
24365
+ }
24366
+ }
24367
+ ]
24368
+ },
24369
+ {
24370
+ type: "element",
24371
+ name: "w:rPr",
24372
+ elements: [
24373
+ {
24374
+ type: "element",
24375
+ name: "w:rFonts",
24376
+ attributes: {
24377
+ "w:ascii": "Wingdings",
24378
+ "w:hAnsi": "Wingdings",
24379
+ "w:hint": "default"
24380
+ }
24381
+ }
24382
+ ]
24383
+ }
24384
+ ]
24385
+ },
24386
+ {
24387
+ type: "element",
24388
+ name: "w:lvl",
24389
+ attributes: {
24390
+ "w:ilvl": "6",
24391
+ "w:tplc": "04090001",
24392
+ "w:tentative": "1"
24393
+ },
24394
+ elements: [
24395
+ {
24396
+ type: "element",
24397
+ name: "w:start",
24398
+ attributes: {
24399
+ "w:val": "1"
24400
+ }
24401
+ },
24402
+ {
24403
+ type: "element",
24404
+ name: "w:numFmt",
24405
+ attributes: {
24406
+ "w:val": "bullet"
24407
+ }
24408
+ },
24409
+ {
24410
+ type: "element",
24411
+ name: "w:lvlText",
24412
+ attributes: {
24413
+ "w:val": ""
24414
+ }
24415
+ },
24416
+ {
24417
+ type: "element",
24418
+ name: "w:lvlJc",
24419
+ attributes: {
24420
+ "w:val": "left"
24421
+ }
24422
+ },
24423
+ {
24424
+ type: "element",
24425
+ name: "w:pPr",
24426
+ elements: [
24427
+ {
24428
+ type: "element",
24429
+ name: "w:ind",
24430
+ attributes: {
24431
+ "w:left": "5040",
24432
+ "w:hanging": "360"
24433
+ }
24434
+ }
24435
+ ]
24436
+ },
24437
+ {
24438
+ type: "element",
24439
+ name: "w:rPr",
24440
+ elements: [
24441
+ {
24442
+ type: "element",
24443
+ name: "w:rFonts",
24444
+ attributes: {
24445
+ "w:ascii": "Symbol",
24446
+ "w:hAnsi": "Symbol",
24447
+ "w:hint": "default"
24448
+ }
24449
+ }
24450
+ ]
24451
+ }
24452
+ ]
24453
+ },
24454
+ {
24455
+ type: "element",
24456
+ name: "w:lvl",
24457
+ attributes: {
24458
+ "w:ilvl": "7",
24459
+ "w:tplc": "04090003",
24460
+ "w:tentative": "1"
24461
+ },
24462
+ elements: [
24463
+ {
24464
+ type: "element",
24465
+ name: "w:start",
24466
+ attributes: {
24467
+ "w:val": "1"
24468
+ }
24469
+ },
24470
+ {
24471
+ type: "element",
24472
+ name: "w:numFmt",
24473
+ attributes: {
24474
+ "w:val": "bullet"
24475
+ }
24476
+ },
24477
+ {
24478
+ type: "element",
24479
+ name: "w:lvlText",
24480
+ attributes: {
24481
+ "w:val": "o"
24482
+ }
24483
+ },
24484
+ {
24485
+ type: "element",
24486
+ name: "w:lvlJc",
24487
+ attributes: {
24488
+ "w:val": "left"
24489
+ }
24490
+ },
24491
+ {
24492
+ type: "element",
24493
+ name: "w:pPr",
24494
+ elements: [
24495
+ {
24496
+ type: "element",
24497
+ name: "w:ind",
24498
+ attributes: {
24499
+ "w:left": "5760",
24500
+ "w:hanging": "360"
24501
+ }
24502
+ }
24503
+ ]
24504
+ },
24505
+ {
24506
+ type: "element",
24507
+ name: "w:rPr",
24508
+ elements: [
24509
+ {
24510
+ type: "element",
24511
+ name: "w:rFonts",
24512
+ attributes: {
24513
+ "w:ascii": "Courier New",
24514
+ "w:hAnsi": "Courier New",
24515
+ "w:cs": "Courier New",
24516
+ "w:hint": "default"
24517
+ }
24518
+ }
24519
+ ]
24520
+ }
24521
+ ]
24522
+ },
24523
+ {
24524
+ type: "element",
24525
+ name: "w:lvl",
24526
+ attributes: {
24527
+ "w:ilvl": "8",
24528
+ "w:tplc": "04090005",
24529
+ "w:tentative": "1"
24530
+ },
24531
+ elements: [
24532
+ {
24533
+ type: "element",
24534
+ name: "w:start",
24535
+ attributes: {
24536
+ "w:val": "1"
24537
+ }
24538
+ },
24539
+ {
24540
+ type: "element",
24541
+ name: "w:numFmt",
24542
+ attributes: {
24543
+ "w:val": "bullet"
24544
+ }
24545
+ },
24546
+ {
24547
+ type: "element",
24548
+ name: "w:lvlText",
24549
+ attributes: {
24550
+ "w:val": ""
24551
+ }
24552
+ },
24553
+ {
24554
+ type: "element",
24555
+ name: "w:lvlJc",
24556
+ attributes: {
24557
+ "w:val": "left"
24558
+ }
24559
+ },
24560
+ {
24561
+ type: "element",
24562
+ name: "w:pPr",
24563
+ elements: [
24564
+ {
24565
+ type: "element",
24566
+ name: "w:ind",
24567
+ attributes: {
24568
+ "w:left": "6480",
24569
+ "w:hanging": "360"
24570
+ }
24571
+ }
24572
+ ]
24573
+ },
24574
+ {
24575
+ type: "element",
24576
+ name: "w:rPr",
24577
+ elements: [
24578
+ {
24579
+ type: "element",
24580
+ name: "w:rFonts",
24581
+ attributes: {
24582
+ "w:ascii": "Wingdings",
24583
+ "w:hAnsi": "Wingdings",
24584
+ "w:hint": "default"
24585
+ }
24586
+ }
24587
+ ]
24588
+ }
24589
+ ]
24590
+ }
24591
+ ]
24592
+ },
24593
+ {
24594
+ type: "element",
24595
+ name: "w:abstractNum",
24596
+ attributes: {
24597
+ "w:abstractNumId": "1",
24598
+ "w15:restartNumberingAfterBreak": "0"
24599
+ },
24600
+ elements: [
24601
+ {
24602
+ type: "element",
24603
+ name: "w:nsid",
24604
+ attributes: {
24605
+ "w:val": "587013BA"
24606
+ }
24607
+ },
24608
+ {
24609
+ type: "element",
24610
+ name: "w:multiLevelType",
24611
+ attributes: {
24612
+ "w:val": "hybridMultilevel"
24613
+ }
24614
+ },
24615
+ {
24616
+ type: "element",
24617
+ name: "w:lvl",
24618
+ attributes: {
24619
+ "w:ilvl": "0",
24620
+ "w:tplc": "0409000F"
24621
+ },
24622
+ elements: [
24623
+ {
24624
+ type: "element",
24625
+ name: "w:start",
24626
+ attributes: {
24627
+ "w:val": "1"
24628
+ }
24629
+ },
24630
+ {
24631
+ type: "element",
24632
+ name: "w:numFmt",
24633
+ attributes: {
24634
+ "w:val": "decimal"
24635
+ }
24636
+ },
24637
+ {
24638
+ type: "element",
24639
+ name: "w:lvlText",
24640
+ attributes: {
24641
+ "w:val": "%1."
24642
+ }
24643
+ },
24644
+ {
24645
+ type: "element",
24646
+ name: "w:lvlJc",
24647
+ attributes: {
24648
+ "w:val": "left"
24649
+ }
24650
+ },
24651
+ {
24652
+ type: "element",
24653
+ name: "w:pPr",
24654
+ elements: [
24655
+ {
24656
+ type: "element",
24657
+ name: "w:ind",
24658
+ attributes: {
24659
+ "w:left": "720",
24660
+ "w:hanging": "360"
24661
+ }
24662
+ }
24663
+ ]
24664
+ }
24665
+ ]
24666
+ },
24667
+ {
24668
+ type: "element",
24669
+ name: "w:lvl",
24670
+ attributes: {
24671
+ "w:ilvl": "1",
24672
+ "w:tplc": "04090019",
24673
+ "w:tentative": "1"
24674
+ },
24675
+ elements: [
24676
+ {
24677
+ type: "element",
24678
+ name: "w:start",
24679
+ attributes: {
24680
+ "w:val": "1"
24681
+ }
24682
+ },
24683
+ {
24684
+ type: "element",
24685
+ name: "w:numFmt",
24686
+ attributes: {
24687
+ "w:val": "lowerLetter"
24688
+ }
24689
+ },
24690
+ {
24691
+ type: "element",
24692
+ name: "w:lvlText",
24693
+ attributes: {
24694
+ "w:val": "%2."
24695
+ }
24696
+ },
24697
+ {
24698
+ type: "element",
24699
+ name: "w:lvlJc",
24700
+ attributes: {
24701
+ "w:val": "left"
24702
+ }
24703
+ },
24704
+ {
24705
+ type: "element",
24706
+ name: "w:pPr",
24707
+ elements: [
24708
+ {
24709
+ type: "element",
24710
+ name: "w:ind",
24711
+ attributes: {
24712
+ "w:left": "1440",
24713
+ "w:hanging": "360"
24714
+ }
24715
+ }
24716
+ ]
24717
+ }
24718
+ ]
24719
+ },
24720
+ {
24721
+ type: "element",
24722
+ name: "w:lvl",
24723
+ attributes: {
24724
+ "w:ilvl": "2",
24725
+ "w:tplc": "0409001B",
24726
+ "w:tentative": "1"
24727
+ },
24728
+ elements: [
24729
+ {
24730
+ type: "element",
24731
+ name: "w:start",
24732
+ attributes: {
24733
+ "w:val": "1"
24734
+ }
24735
+ },
24736
+ {
24737
+ type: "element",
24738
+ name: "w:numFmt",
24739
+ attributes: {
24740
+ "w:val": "lowerRoman"
24741
+ }
24742
+ },
24743
+ {
24744
+ type: "element",
24745
+ name: "w:lvlText",
24746
+ attributes: {
24747
+ "w:val": "%3."
24748
+ }
24749
+ },
24750
+ {
24751
+ type: "element",
24752
+ name: "w:lvlJc",
24753
+ attributes: {
24754
+ "w:val": "right"
24755
+ }
24756
+ },
24757
+ {
24758
+ type: "element",
24759
+ name: "w:pPr",
24760
+ elements: [
24761
+ {
24762
+ type: "element",
24763
+ name: "w:ind",
24764
+ attributes: {
24765
+ "w:left": "2160",
24766
+ "w:hanging": "180"
24767
+ }
24768
+ }
24769
+ ]
24770
+ }
24771
+ ]
24772
+ },
24773
+ {
24774
+ type: "element",
24775
+ name: "w:lvl",
24776
+ attributes: {
24777
+ "w:ilvl": "3",
24778
+ "w:tplc": "0409000F",
24779
+ "w:tentative": "1"
24780
+ },
24781
+ elements: [
24782
+ {
24783
+ type: "element",
24784
+ name: "w:start",
24785
+ attributes: {
24786
+ "w:val": "1"
24787
+ }
24788
+ },
24789
+ {
24790
+ type: "element",
24791
+ name: "w:numFmt",
24792
+ attributes: {
24793
+ "w:val": "decimal"
24794
+ }
24795
+ },
24796
+ {
24797
+ type: "element",
24798
+ name: "w:lvlText",
24799
+ attributes: {
24800
+ "w:val": "%4."
24801
+ }
24802
+ },
24803
+ {
24804
+ type: "element",
24805
+ name: "w:lvlJc",
24806
+ attributes: {
24807
+ "w:val": "left"
24808
+ }
24809
+ },
24810
+ {
24811
+ type: "element",
24812
+ name: "w:pPr",
24813
+ elements: [
24814
+ {
24815
+ type: "element",
24816
+ name: "w:ind",
24817
+ attributes: {
24818
+ "w:left": "2880",
24819
+ "w:hanging": "360"
24820
+ }
24821
+ }
24822
+ ]
24823
+ }
24824
+ ]
24825
+ },
24826
+ {
24827
+ type: "element",
24828
+ name: "w:lvl",
24829
+ attributes: {
24830
+ "w:ilvl": "4",
24831
+ "w:tplc": "04090019",
24832
+ "w:tentative": "1"
24833
+ },
24834
+ elements: [
24835
+ {
24836
+ type: "element",
24837
+ name: "w:start",
24838
+ attributes: {
24839
+ "w:val": "1"
24840
+ }
24841
+ },
24842
+ {
24843
+ type: "element",
24844
+ name: "w:numFmt",
24845
+ attributes: {
24846
+ "w:val": "lowerLetter"
24847
+ }
24848
+ },
24849
+ {
24850
+ type: "element",
24851
+ name: "w:lvlText",
24852
+ attributes: {
24853
+ "w:val": "%5."
24854
+ }
24855
+ },
24856
+ {
24857
+ type: "element",
24858
+ name: "w:lvlJc",
24859
+ attributes: {
24860
+ "w:val": "left"
24861
+ }
24862
+ },
24863
+ {
24864
+ type: "element",
24865
+ name: "w:pPr",
24866
+ elements: [
24867
+ {
24868
+ type: "element",
24869
+ name: "w:ind",
24870
+ attributes: {
24871
+ "w:left": "3600",
24872
+ "w:hanging": "360"
24873
+ }
24874
+ }
24875
+ ]
24876
+ }
24877
+ ]
24878
+ },
24879
+ {
24880
+ type: "element",
24881
+ name: "w:lvl",
24882
+ attributes: {
24883
+ "w:ilvl": "5",
24884
+ "w:tplc": "0409001B",
24885
+ "w:tentative": "1"
24886
+ },
24887
+ elements: [
24888
+ {
24889
+ type: "element",
24890
+ name: "w:start",
24891
+ attributes: {
24892
+ "w:val": "1"
24893
+ }
24894
+ },
24895
+ {
24896
+ type: "element",
24897
+ name: "w:numFmt",
24898
+ attributes: {
24899
+ "w:val": "lowerRoman"
24900
+ }
24901
+ },
24902
+ {
24903
+ type: "element",
24904
+ name: "w:lvlText",
24905
+ attributes: {
24906
+ "w:val": "%6."
24907
+ }
24908
+ },
24909
+ {
24910
+ type: "element",
24911
+ name: "w:lvlJc",
24912
+ attributes: {
24913
+ "w:val": "right"
24914
+ }
24915
+ },
24916
+ {
24917
+ type: "element",
24918
+ name: "w:pPr",
24919
+ elements: [
24920
+ {
24921
+ type: "element",
24922
+ name: "w:ind",
24923
+ attributes: {
24924
+ "w:left": "4320",
24925
+ "w:hanging": "180"
24926
+ }
24927
+ }
24928
+ ]
24929
+ }
24930
+ ]
24931
+ },
24932
+ {
24933
+ type: "element",
24934
+ name: "w:lvl",
24935
+ attributes: {
24936
+ "w:ilvl": "6",
24937
+ "w:tplc": "0409000F",
24938
+ "w:tentative": "1"
24939
+ },
24940
+ elements: [
24941
+ {
24942
+ type: "element",
24943
+ name: "w:start",
24944
+ attributes: {
24945
+ "w:val": "1"
24946
+ }
24947
+ },
24948
+ {
24949
+ type: "element",
24950
+ name: "w:numFmt",
24951
+ attributes: {
24952
+ "w:val": "decimal"
24953
+ }
24954
+ },
24955
+ {
24956
+ type: "element",
24957
+ name: "w:lvlText",
24958
+ attributes: {
24959
+ "w:val": "%7."
24960
+ }
24961
+ },
24962
+ {
24963
+ type: "element",
24964
+ name: "w:lvlJc",
24965
+ attributes: {
24966
+ "w:val": "left"
24967
+ }
24968
+ },
24969
+ {
24970
+ type: "element",
24971
+ name: "w:pPr",
24972
+ elements: [
24973
+ {
24974
+ type: "element",
24975
+ name: "w:ind",
24976
+ attributes: {
24977
+ "w:left": "5040",
24978
+ "w:hanging": "360"
24979
+ }
24980
+ }
24981
+ ]
24982
+ }
24983
+ ]
24984
+ },
24985
+ {
24986
+ type: "element",
24987
+ name: "w:lvl",
24988
+ attributes: {
24989
+ "w:ilvl": "7",
24990
+ "w:tplc": "04090019",
24991
+ "w:tentative": "1"
24992
+ },
24993
+ elements: [
24994
+ {
24995
+ type: "element",
24996
+ name: "w:start",
24997
+ attributes: {
24998
+ "w:val": "1"
24999
+ }
25000
+ },
25001
+ {
25002
+ type: "element",
25003
+ name: "w:numFmt",
25004
+ attributes: {
25005
+ "w:val": "lowerLetter"
25006
+ }
25007
+ },
25008
+ {
25009
+ type: "element",
25010
+ name: "w:lvlText",
25011
+ attributes: {
25012
+ "w:val": "%8."
25013
+ }
25014
+ },
25015
+ {
25016
+ type: "element",
25017
+ name: "w:lvlJc",
25018
+ attributes: {
25019
+ "w:val": "left"
25020
+ }
25021
+ },
25022
+ {
25023
+ type: "element",
25024
+ name: "w:pPr",
25025
+ elements: [
25026
+ {
25027
+ type: "element",
25028
+ name: "w:ind",
25029
+ attributes: {
25030
+ "w:left": "5760",
25031
+ "w:hanging": "360"
25032
+ }
25033
+ }
25034
+ ]
25035
+ }
25036
+ ]
25037
+ },
25038
+ {
25039
+ type: "element",
25040
+ name: "w:lvl",
25041
+ attributes: {
25042
+ "w:ilvl": "8",
25043
+ "w:tplc": "0409001B",
25044
+ "w:tentative": "1"
25045
+ },
25046
+ elements: [
25047
+ {
25048
+ type: "element",
25049
+ name: "w:start",
25050
+ attributes: {
25051
+ "w:val": "1"
25052
+ }
25053
+ },
25054
+ {
25055
+ type: "element",
25056
+ name: "w:numFmt",
25057
+ attributes: {
25058
+ "w:val": "lowerRoman"
25059
+ }
25060
+ },
25061
+ {
25062
+ type: "element",
25063
+ name: "w:lvlText",
25064
+ attributes: {
25065
+ "w:val": "%9."
25066
+ }
25067
+ },
25068
+ {
25069
+ type: "element",
25070
+ name: "w:lvlJc",
25071
+ attributes: {
25072
+ "w:val": "right"
25073
+ }
25074
+ },
25075
+ {
25076
+ type: "element",
25077
+ name: "w:pPr",
25078
+ elements: [
25079
+ {
25080
+ type: "element",
25081
+ name: "w:ind",
25082
+ attributes: {
25083
+ "w:left": "6480",
25084
+ "w:hanging": "180"
25085
+ }
25086
+ }
25087
+ ]
25088
+ }
25089
+ ]
25090
+ }
25091
+ ]
25092
+ },
25093
+ {
25094
+ type: "element",
25095
+ name: "w:num",
25096
+ attributes: {
25097
+ "w:numId": "1",
25098
+ "w16cid:durableId": "100147962"
25099
+ },
25100
+ elements: [
25101
+ {
25102
+ type: "element",
25103
+ name: "w:abstractNumId",
25104
+ attributes: {
25105
+ "w:val": "0"
25106
+ }
25107
+ }
25108
+ ]
25109
+ },
25110
+ {
25111
+ type: "element",
25112
+ name: "w:num",
25113
+ attributes: {
25114
+ "w:numId": "2",
25115
+ "w16cid:durableId": "485517411"
25116
+ },
25117
+ elements: [
25118
+ {
25119
+ type: "element",
25120
+ name: "w:abstractNumId",
25121
+ attributes: {
25122
+ "w:val": "1"
25123
+ }
25124
+ }
25125
+ ]
25126
+ }
25127
+ ]
24641
25128
  }
24642
- });
24643
- newList.setAttribute("data-list-id", rootNumId);
24644
- newLi.setAttribute("data-num-id", rootNumId);
24645
- newLi.setAttribute("data-level", String(level));
24646
- const { listNumberingType, lvlText } = ListHelpers.getListDefinitionDetails({
24647
- numId: rootNumId,
24648
- level,
24649
- editor
24650
- });
24651
- newLi.setAttribute("data-num-fmt", listNumberingType);
24652
- newLi.setAttribute("data-lvl-text", lvlText || "");
24653
- newLi.setAttribute("data-list-level", JSON.stringify([level + 1]));
24654
- Array.from(li.childNodes).forEach((node2) => {
24655
- if (node2.nodeType === ELEMENT_NODE || node2.nodeType === TEXT_NODE && node2.textContent.trim()) {
24656
- newLi.appendChild(node2.cloneNode(true));
25129
+ ]
25130
+ };
25131
+ const translateDocumentSection = (params2) => {
25132
+ const { node: node2 } = params2;
25133
+ const { attrs = {} } = node2;
25134
+ const childContent = translateChildNodes({ ...params2, nodes: node2.content });
25135
+ const nodeElements = [
25136
+ {
25137
+ name: "w:sdtContent",
25138
+ elements: childContent
24657
25139
  }
25140
+ ];
25141
+ const exportedTag = JSON.stringify({
25142
+ type: "documentSection",
25143
+ description: attrs.description
24658
25144
  });
24659
- if (newLi.childNodes.length === 0 || newLi.childNodes.length === 1 && newLi.childNodes[0].nodeType === TEXT_NODE) {
24660
- const textContent2 = newLi.textContent.trim();
24661
- if (textContent2) {
24662
- newLi.innerHTML = "";
24663
- const p = localDoc.createElement("p");
24664
- p.textContent = textContent2;
24665
- newLi.appendChild(p);
24666
- }
24667
- }
24668
- newList.appendChild(newLi);
24669
- return newList;
24670
- }
24671
- function unflattenListsInHtml(html) {
24672
- const parser = new DOMParser();
24673
- const doc2 = parser.parseFromString(html, "text/html");
24674
- const allNodes = [...doc2.body.children];
24675
- const listSequences = [];
24676
- let currentSequence = null;
24677
- allNodes.forEach((node2, index2) => {
24678
- const isFlattenList = node2.tagName && (node2.tagName === "OL" || node2.tagName === "UL") && node2.hasAttribute("data-list-id");
24679
- if (isFlattenList) {
24680
- const listId = node2.getAttribute("data-list-id");
24681
- if (currentSequence && currentSequence.id === listId) {
24682
- currentSequence.lists.push({ element: node2, index: index2 });
24683
- } else {
24684
- currentSequence = {
24685
- id: listId,
24686
- lists: [{ element: node2, index: index2 }]
24687
- };
24688
- listSequences.push(currentSequence);
25145
+ const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
25146
+ const { isLocked } = attrs;
25147
+ if (isLocked) {
25148
+ sdtPr.elements.push({
25149
+ name: "w:lock",
25150
+ attributes: {
25151
+ "w:val": "sdtContentLocked"
24689
25152
  }
24690
- } else {
24691
- currentSequence = null;
24692
- }
24693
- });
24694
- listSequences.reverse().forEach((sequence) => {
24695
- const sequenceLists = sequence.lists;
24696
- if (sequenceLists.length === 0) {
24697
- return;
24698
- }
24699
- const items = sequenceLists.map(({ element: list }) => {
24700
- const liElement = list.querySelector("li");
24701
- if (!liElement) return null;
24702
- return {
24703
- element: liElement,
24704
- level: parseInt(liElement.getAttribute("data-level") || "0"),
24705
- numFmt: liElement.getAttribute("data-num-fmt") || "bullet",
24706
- listLevel: JSON.parse(liElement.getAttribute("data-list-level") || "[1]")
24707
- };
24708
- }).filter((item) => item !== null);
24709
- if (items.length === 0) {
24710
- return;
24711
- }
24712
- const rootList = buildNestedList({ items });
24713
- const firstOriginalList = sequenceLists[0].element;
24714
- firstOriginalList?.parentNode?.insertBefore(rootList, firstOriginalList);
24715
- sequenceLists.forEach(({ element: list }) => {
24716
- if (list.parentNode) list.parentNode.removeChild(list);
24717
25153
  });
24718
- });
24719
- return doc2.body.innerHTML;
24720
- }
24721
- function buildNestedList({ items }) {
24722
- if (!items.length) {
24723
- return null;
24724
- }
24725
- const [rootItem] = items;
24726
- const doc2 = rootItem.element.ownerDocument;
24727
- const isOrderedList = rootItem.numFmt && !["bullet", "none"].includes(rootItem.numFmt);
24728
- const rootList = doc2.createElement(isOrderedList ? "ol" : "ul");
24729
- if (isOrderedList && rootItem.listLevel?.[0] && rootItem.listLevel[0] > 1) {
24730
- rootList.setAttribute("start", rootItem.listLevel[0]);
24731
- }
24732
- const lastLevelItem = /* @__PURE__ */ new Map();
24733
- items.forEach((item) => {
24734
- const { element: liElement, level, numFmt, listLevel } = item;
24735
- const cleanLi = cleanListItem(liElement.cloneNode(true));
24736
- if (level === 0) {
24737
- rootList.append(cleanLi);
24738
- lastLevelItem.set(0, cleanLi);
24739
- } else {
24740
- const parentLi = lastLevelItem.get(level - 1);
24741
- if (!parentLi) {
24742
- rootList.append(cleanLi);
24743
- lastLevelItem.set(level, cleanLi);
24744
- return;
24745
- }
24746
- let nestedList = null;
24747
- [...parentLi.children].forEach((child) => {
24748
- if (child.tagName && (child.tagName === "OL" || child.tagName === "UL")) {
24749
- nestedList = child;
24750
- }
24751
- });
24752
- if (!nestedList) {
24753
- const listType = numFmt && !["bullet", "none"].includes(numFmt) ? "ol" : "ul";
24754
- nestedList = doc2.createElement(listType);
24755
- parentLi.append(nestedList);
24756
- }
24757
- nestedList.append(cleanLi);
24758
- lastLevelItem.set(level, cleanLi);
24759
- }
24760
- });
24761
- return rootList;
24762
- }
24763
- function cleanListItem(listItem) {
24764
- const attrs = [
24765
- "data-num-id",
24766
- "data-level",
24767
- "data-num-fmt",
24768
- "data-lvl-text",
24769
- "data-list-level",
24770
- "data-marker-type",
24771
- "aria-label"
24772
- ];
24773
- attrs.forEach((attr) => {
24774
- listItem.removeAttribute(attr);
24775
- });
24776
- return listItem;
24777
- }
24778
- class InputRule {
24779
- constructor(config) {
24780
- __publicField$2(this, "match");
24781
- __publicField$2(this, "handler");
24782
- this.match = config.match;
24783
- this.handler = config.handler;
24784
- }
24785
- }
24786
- const inputRuleMatcherHandler = (text, match) => {
24787
- if (isRegExp(match)) {
24788
- return match.exec(text);
24789
- }
24790
- const inputRuleMatch = match(text);
24791
- if (!inputRuleMatch) {
24792
- return null;
24793
- }
24794
- const result = [inputRuleMatch.text];
24795
- result.index = inputRuleMatch.index;
24796
- result.input = text;
24797
- result.data = inputRuleMatch.data;
24798
- if (inputRuleMatch.replaceWith) {
24799
- if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
24800
- console.warn('[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".');
24801
- }
24802
- result.push(inputRuleMatch.replaceWith);
24803
- }
24804
- return result;
24805
- };
24806
- const run = (config) => {
24807
- const { editor, from: from2, to, text, rules, plugin: plugin2 } = config;
24808
- const { view } = editor;
24809
- if (view.composing) {
24810
- return false;
24811
- }
24812
- const $from = view.state.doc.resolve(from2);
24813
- if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
24814
- return false;
24815
25154
  }
24816
- let matched = false;
24817
- const textBefore = getTextContentFromNodes($from) + text;
24818
- rules.forEach((rule) => {
24819
- if (matched) {
24820
- return;
24821
- }
24822
- const match = inputRuleMatcherHandler(textBefore, rule.match);
24823
- if (!match) {
24824
- return;
24825
- }
24826
- const tr = view.state.tr;
24827
- const state2 = chainableEditorState(tr, view.state);
24828
- const range2 = {
24829
- from: from2 - (match[0].length - text.length),
24830
- to
24831
- };
24832
- const { commands: commands2, chain, can } = new CommandService({
24833
- editor,
24834
- state: state2
24835
- });
24836
- const handler = rule.handler({
24837
- state: state2,
24838
- range: range2,
24839
- match,
24840
- commands: commands2,
24841
- chain,
24842
- can
24843
- });
24844
- if (handler === null || !tr.steps.length) {
24845
- return;
24846
- }
24847
- tr.setMeta(plugin2, {
24848
- transform: tr,
24849
- from: from2,
24850
- to,
24851
- text
24852
- });
24853
- view.dispatch(tr);
24854
- matched = true;
24855
- });
24856
- return matched;
25155
+ nodeElements.unshift(sdtPr);
25156
+ return {
25157
+ name: "w:sdt",
25158
+ elements: nodeElements
25159
+ };
24857
25160
  };
24858
- const inputRulesPlugin = ({ editor, rules }) => {
24859
- const plugin2 = new Plugin({
24860
- key: new PluginKey("inputRulesPlugin"),
24861
- state: {
24862
- init() {
24863
- return null;
24864
- },
24865
- apply(tr, prev, state2) {
24866
- const stored = tr.getMeta(plugin2);
24867
- if (stored) {
24868
- return stored;
24869
- }
24870
- const simulatedInputMeta = tr.getMeta("applyInputRules");
24871
- const isSimulatedInput = !!simulatedInputMeta;
24872
- if (isSimulatedInput) {
24873
- setTimeout(() => {
24874
- let { text } = simulatedInputMeta;
24875
- if (typeof text !== "string") {
24876
- text = getHTMLFromFragment(Fragment.from(text), state2.schema);
24877
- }
24878
- const { from: from2 } = simulatedInputMeta;
24879
- const to = from2 + text.length;
24880
- run({
24881
- editor,
24882
- from: from2,
24883
- to,
24884
- text,
24885
- rules,
24886
- plugin: plugin2
24887
- });
24888
- });
25161
+ const generateSdtPrTagForDocumentSection = (id, title, tag) => {
25162
+ return {
25163
+ name: "w:sdtPr",
25164
+ elements: [
25165
+ {
25166
+ name: "w:id",
25167
+ attributes: {
25168
+ "w:val": id
24889
25169
  }
24890
- return tr.selectionSet || tr.docChanged ? null : prev;
24891
- }
24892
- },
24893
- props: {
24894
- handleTextInput(view, from2, to, text) {
24895
- return run({
24896
- editor,
24897
- from: from2,
24898
- to,
24899
- text,
24900
- rules,
24901
- plugin: plugin2
24902
- });
24903
25170
  },
24904
- // add support for input rules to trigger on enter
24905
- // this is useful for example for code blocks
24906
- handleKeyDown(view, event) {
24907
- if (event.key !== "Enter") {
24908
- return false;
24909
- }
24910
- const { $cursor } = view.state.selection;
24911
- if ($cursor) {
24912
- return run({
24913
- editor,
24914
- from: $cursor.pos,
24915
- to: $cursor.pos,
24916
- text: "\n",
24917
- rules,
24918
- plugin: plugin2
24919
- });
25171
+ {
25172
+ name: "w:alias",
25173
+ attributes: {
25174
+ "w:val": title
24920
25175
  }
24921
- return false;
24922
25176
  },
24923
- // Paste handler
24924
- handlePaste(view, event, slice2) {
24925
- const clipboard = event.clipboardData;
24926
- const html = clipboard.getData("text/html");
24927
- clipboard.getData("text/plain");
24928
- const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
24929
- if (fieldAnnotationContent.length) {
24930
- return false;
25177
+ {
25178
+ name: "w:tag",
25179
+ attributes: {
25180
+ "w:val": tag
24931
25181
  }
24932
- return handleClipboardPaste({ editor, view }, html);
24933
- }
24934
- },
24935
- isInputRules: true
24936
- });
24937
- return plugin2;
24938
- };
24939
- function isWordHtml(html) {
24940
- return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(
24941
- html
24942
- );
24943
- }
24944
- function handleHtmlPaste(html, editor) {
24945
- const flatHtml = flattenListsInHtml(html, editor);
24946
- const htmlWithPtSizing = convertEmToPt(flatHtml);
24947
- const cleanedHtml = sanitizeHtml(htmlWithPtSizing);
24948
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(cleanedHtml);
24949
- const { dispatch, state: state2 } = editor.view;
24950
- if (!dispatch) return false;
24951
- const { $from } = state2.selection;
24952
- const isInParagraph = $from.parent.type.name === "paragraph";
24953
- const isSingleParagraph = doc2.childCount === 1 && doc2.firstChild.type.name === "paragraph";
24954
- if (isInParagraph && isSingleParagraph) {
24955
- const paragraphContent = doc2.firstChild.content;
24956
- const tr = state2.tr.replaceSelectionWith(paragraphContent, false);
24957
- dispatch(tr);
24958
- } else {
24959
- dispatch(state2.tr.replaceSelectionWith(doc2, true));
24960
- }
24961
- return true;
24962
- }
24963
- const convertEmToPt = (html) => {
24964
- return html.replace(/font-size\s*:\s*([\d.]+)em/gi, (_, emValue) => {
24965
- const em = parseFloat(emValue);
24966
- const pt = Math.round(em * 12 * 100) / 100;
24967
- return `font-size: ${pt}pt`;
24968
- });
24969
- };
24970
- function cleanHtmlUnnecessaryTags(html) {
24971
- return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/&nbsp;/gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
24972
- }
24973
- function sanitizeHtml(html, forbiddenTags = ["meta", "svg", "script", "style", "button"]) {
24974
- const container = document.createElement("div");
24975
- container.innerHTML = html;
24976
- const walkAndClean = (node2) => {
24977
- for (const child of [...node2.children]) {
24978
- if (forbiddenTags.includes(child.tagName.toLowerCase())) {
24979
- child.remove();
24980
- continue;
24981
25182
  }
24982
- if (child.hasAttribute("linebreaktype")) {
24983
- child.removeAttribute("linebreaktype");
24984
- }
24985
- walkAndClean(child);
24986
- }
25183
+ ]
24987
25184
  };
24988
- walkAndClean(container);
24989
- return container;
24990
- }
24991
- function handleClipboardPaste({ editor, view }, html, text) {
24992
- let source;
24993
- if (!html) {
24994
- source = "plain-text";
24995
- } else if (isWordHtml(html)) {
24996
- source = "word-html";
24997
- } else {
24998
- source = "browser-html";
24999
- }
25000
- switch (source) {
25001
- case "plain-text":
25002
- return false;
25003
- case "word-html":
25004
- if (editor.options.mode === "docx") {
25005
- return handleDocxPaste(html, editor, view);
25006
- }
25007
- // falls through to browser-html handling when not in DOCX mode
25008
- case "browser-html":
25009
- return handleHtmlPaste(html, editor);
25010
- }
25011
- return false;
25012
- }
25185
+ };
25013
25186
  function exportSchemaToJson(params2) {
25014
25187
  const { type: type2 } = params2.node || {};
25015
25188
  const router = {
@@ -25035,6 +25208,7 @@ function exportSchemaToJson(params2) {
25035
25208
  shapeTextbox: translateShapeTextbox,
25036
25209
  contentBlock: translateContentBlock,
25037
25210
  structuredContent: translateStructuredContent,
25211
+ documentSection: translateDocumentSection,
25038
25212
  "page-number": translatePageNumberNode,
25039
25213
  "total-page-number": translateTotalPageNumberNode
25040
25214
  };
@@ -25102,11 +25276,12 @@ function translateParagraphNode(params2) {
25102
25276
  if (params2.node.attrs?.rsidRDefault) {
25103
25277
  attributes["w:rsidRDefault"] = params2.node.attrs.rsidRDefault;
25104
25278
  }
25105
- return {
25279
+ const result = {
25106
25280
  name: "w:p",
25107
25281
  elements,
25108
25282
  attributes
25109
25283
  };
25284
+ return result;
25110
25285
  }
25111
25286
  function generateParagraphProperties(node2) {
25112
25287
  const { attrs = {} } = node2;
@@ -25226,18 +25401,6 @@ function translateDocumentNode(params2) {
25226
25401
  };
25227
25402
  return [node2, params2];
25228
25403
  }
25229
- function translateChildNodes(params2) {
25230
- const { content: nodes } = params2.node;
25231
- if (!nodes) return [];
25232
- const translatedNodes = [];
25233
- nodes.forEach((node2) => {
25234
- let translatedNode = exportSchemaToJson({ ...params2, node: node2 });
25235
- translatedNode?.name || translatedNode?.type;
25236
- if (translatedNode instanceof Array) translatedNodes.push(...translatedNode);
25237
- else translatedNodes.push(translatedNode);
25238
- });
25239
- return translatedNodes.filter((n) => n);
25240
- }
25241
25404
  function getTextNodeForExport(text, marks, params2) {
25242
25405
  const hasLeadingOrTrailingSpace = /^\s|\s$/.test(text);
25243
25406
  const space = hasLeadingOrTrailingSpace ? "preserve" : null;
@@ -27550,6 +27713,14 @@ const handleSdtNode = (params2) => {
27550
27713
  }
27551
27714
  const node2 = nodes[0];
27552
27715
  const sdtPr = node2.elements.find((el) => el.name === "w:sdtPr");
27716
+ const tag = sdtPr?.elements.find((el) => el.name === "w:tag");
27717
+ let tagValue = tag?.attributes?.["w:val"];
27718
+ try {
27719
+ tagValue = JSON.parse(tagValue);
27720
+ const { type: type2 } = tagValue;
27721
+ if (type2 === "documentSection") return handleDocumentSectionNode(params2, tagValue);
27722
+ } catch (e) {
27723
+ }
27553
27724
  const sdtContent = node2.elements.find((el) => el.name === "w:sdtContent");
27554
27725
  const { marks } = parseAnnotationMarks(sdtContent);
27555
27726
  const translatedContent = nodeListHandler2.handler({ ...params2, nodes: sdtContent?.elements });
@@ -27566,6 +27737,31 @@ const handleSdtNode = (params2) => {
27566
27737
  consumed: 1
27567
27738
  };
27568
27739
  };
27740
+ const handleDocumentSectionNode = (params2, tagValue) => {
27741
+ const { nodes, nodeListHandler: nodeListHandler2 } = params2;
27742
+ const node2 = nodes[0];
27743
+ const sdtPr = node2.elements.find((el) => el.name === "w:sdtPr");
27744
+ const idTag = sdtPr?.elements.find((el) => el.name === "w:id");
27745
+ const id = idTag?.attributes?.["w:val"] || tagValue.id || null;
27746
+ const titleTag = sdtPr?.elements.find((el) => el.name === "w:alias");
27747
+ const title = titleTag?.attributes?.["w:val"] || tagValue.title || null;
27748
+ const { description } = tagValue;
27749
+ const sdtContent = node2.elements.find((el) => el.name === "w:sdtContent");
27750
+ const translatedContent = nodeListHandler2.handler({ ...params2, nodes: sdtContent?.elements });
27751
+ const result = {
27752
+ type: "documentSection",
27753
+ content: translatedContent,
27754
+ attrs: {
27755
+ id,
27756
+ title,
27757
+ description
27758
+ }
27759
+ };
27760
+ return {
27761
+ nodes: [result],
27762
+ consumed: 1
27763
+ };
27764
+ };
27569
27765
  const sdtNodeHandlerEntity = {
27570
27766
  handlerName: "sdtNodeHandler",
27571
27767
  handler: handleSdtNode
@@ -28468,7 +28664,7 @@ const _SuperConverter = class _SuperConverter2 {
28468
28664
  return;
28469
28665
  }
28470
28666
  }
28471
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.14.20-next.2") {
28667
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.14.20-next.3") {
28472
28668
  const customLocation = "docProps/custom.xml";
28473
28669
  if (!docx[customLocation]) {
28474
28670
  docx[customLocation] = generateCustomXml();
@@ -28946,7 +29142,7 @@ function storeSuperdocVersion(docx) {
28946
29142
  function generateCustomXml() {
28947
29143
  return DEFAULT_CUSTOM_XML;
28948
29144
  }
28949
- function generateSuperdocVersion(pid = 2, version2 = "0.14.20-next.2") {
29145
+ function generateSuperdocVersion(pid = 2, version2 = "0.14.20-next.3") {
28950
29146
  return {
28951
29147
  type: "element",
28952
29148
  name: "property",
@@ -31495,7 +31691,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
31495
31691
  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);
31496
31692
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
31497
31693
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
31498
- 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, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _ListItemNodeView_instances, init_fn2, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
31694
+ 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, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _ListItemNodeView_instances, init_fn2, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn, _DocumentSectionView_instances, init_fn3, addToolTip_fn;
31499
31695
  var GOOD_LEAF_SIZE = 200;
31500
31696
  var RopeSequence = function RopeSequence2() {
31501
31697
  };
@@ -45060,7 +45256,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
45060
45256
  * @returns {Object | void} Migration results
45061
45257
  */
45062
45258
  processCollaborationMigrations() {
45063
- console.debug("[checkVersionMigrations] Current editor version", "0.14.20-next.2");
45259
+ console.debug("[checkVersionMigrations] Current editor version", "0.14.20-next.3");
45064
45260
  if (!this.options.ydoc) return;
45065
45261
  const metaMap = this.options.ydoc.getMap("meta");
45066
45262
  let docVersion = metaMap.get("version");
@@ -53549,6 +53745,195 @@ const StructuredContent = Node$1.create({
53549
53745
  };
53550
53746
  }
53551
53747
  });
53748
+ class DocumentSectionView {
53749
+ constructor(node2, getPos, decorations, editor) {
53750
+ __privateAdd$1(this, _DocumentSectionView_instances);
53751
+ this.node = node2;
53752
+ this.editor = editor;
53753
+ this.decorations = decorations;
53754
+ this.view = editor.view;
53755
+ this.getPos = getPos;
53756
+ __privateMethod$1(this, _DocumentSectionView_instances, init_fn3).call(this);
53757
+ }
53758
+ }
53759
+ _DocumentSectionView_instances = /* @__PURE__ */ new WeakSet();
53760
+ init_fn3 = function() {
53761
+ const { attrs } = this.node;
53762
+ const { id, title, description } = attrs;
53763
+ this.dom = document.createElement("div");
53764
+ this.dom.className = "sd-document-section-block";
53765
+ this.dom.setAttribute("data-id", id);
53766
+ this.dom.setAttribute("data-title", title);
53767
+ this.dom.setAttribute("data-description", description);
53768
+ this.dom.setAttribute("aria-label", "Document section");
53769
+ __privateMethod$1(this, _DocumentSectionView_instances, addToolTip_fn).call(this);
53770
+ this.contentDOM = document.createElement("div");
53771
+ this.contentDOM.className = "sd-document-section-block-content";
53772
+ this.contentDOM.setAttribute("contenteditable", "true");
53773
+ this.dom.appendChild(this.contentDOM);
53774
+ };
53775
+ addToolTip_fn = function() {
53776
+ const { title } = this.node.attrs;
53777
+ this.infoDiv = document.createElement("div");
53778
+ this.infoDiv.className = "sd-document-section-block-info";
53779
+ const textSpan = document.createElement("span");
53780
+ textSpan.textContent = title || "Document section";
53781
+ this.infoDiv.appendChild(textSpan);
53782
+ this.infoDiv.setAttribute("contenteditable", "false");
53783
+ this.dom.appendChild(this.infoDiv);
53784
+ };
53785
+ const DocumentSection = Node$1.create({
53786
+ name: "documentSection",
53787
+ group: "block",
53788
+ content: "block*",
53789
+ atom: true,
53790
+ isolating: true,
53791
+ addOptions() {
53792
+ return {
53793
+ htmlAttributes: {
53794
+ class: "sd-document-section-block",
53795
+ "aria-label": "Structured content block"
53796
+ }
53797
+ };
53798
+ },
53799
+ parseDOM() {
53800
+ return [
53801
+ {
53802
+ tag: "div.sd-document-section-block",
53803
+ priority: 60
53804
+ }
53805
+ ];
53806
+ },
53807
+ renderDOM({ htmlAttributes }) {
53808
+ return ["div", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
53809
+ },
53810
+ addAttributes() {
53811
+ return {
53812
+ id: {},
53813
+ title: {},
53814
+ description: {},
53815
+ sectionType: {},
53816
+ isLocked: { default: false }
53817
+ };
53818
+ },
53819
+ addNodeView() {
53820
+ return ({ node: node2, editor, getPos, decorations }) => {
53821
+ return new DocumentSectionView(node2, getPos, decorations, editor);
53822
+ };
53823
+ },
53824
+ addCommands() {
53825
+ return {
53826
+ /**
53827
+ * Create a new structured content block
53828
+ * You can pass in options like title, description, html, or json.
53829
+ * If html is provided, it will be parsed and converted to ProseMirror nodes.
53830
+ * If json is provided, it will be used to create the content of the block.
53831
+ * @param {Object} params - The command parameters
53832
+ * @returns {boolean} Returns true if the command was executed successfully
53833
+ */
53834
+ createDocumentSection: (options = {}) => ({ tr, state: state2, dispatch, editor }) => {
53835
+ const { selection } = state2;
53836
+ let { from: from2, to } = selection;
53837
+ let content = selection.content().content;
53838
+ const { html: optionsHTML, json: optionsJSON } = options;
53839
+ if (optionsHTML) {
53840
+ const html = htmlHandler(optionsHTML, this.editor);
53841
+ const doc2 = DOMParser$1.fromSchema(this.editor.schema).parse(html);
53842
+ content = doc2.content;
53843
+ }
53844
+ if (optionsJSON) {
53845
+ content = this.editor.schema.nodeFromJSON(optionsJSON);
53846
+ }
53847
+ if (!content?.content?.length) {
53848
+ content = this.editor.schema.nodeFromJSON({ type: "paragraph", content: [] });
53849
+ }
53850
+ if (!options.id) {
53851
+ const allSections = SectionHelpers.getAllSections(editor);
53852
+ options.id = allSections.length + 1;
53853
+ }
53854
+ if (!options.title) {
53855
+ options.title = "Document section";
53856
+ }
53857
+ const node2 = this.type.createAndFill(options, content);
53858
+ if (!node2) return false;
53859
+ const isAlreadyInSdtBlock = findParentNode((node22) => node22.type.name === "documentSection")(selection);
53860
+ if (isAlreadyInSdtBlock && isAlreadyInSdtBlock.node) {
53861
+ const insertPos = isAlreadyInSdtBlock.pos + isAlreadyInSdtBlock.node.nodeSize;
53862
+ from2 = insertPos;
53863
+ to = insertPos;
53864
+ }
53865
+ tr.replaceRangeWith(from2, to, node2);
53866
+ if (dispatch) {
53867
+ tr.setMeta("documentSection", { action: "create" });
53868
+ dispatch(tr);
53869
+ }
53870
+ return true;
53871
+ },
53872
+ /**
53873
+ * Remove the structured content block at the current selection, retaining contents.
53874
+ * This will remove the block node but keep its content in the document.
53875
+ * If the selection is not within a structured content block, it does nothing.
53876
+ * @param {Object} params - The command parameters
53877
+ * @returns {boolean} Returns true if the command was executed successfully
53878
+ */
53879
+ removeSectionAtSelection: () => ({ tr, dispatch }) => {
53880
+ const sdtNode = findParentNode((node22) => node22.type.name === "documentSection")(tr.selection);
53881
+ if (!sdtNode) return false;
53882
+ const { node: node2, pos } = sdtNode;
53883
+ const nodeStart = pos;
53884
+ const nodeEnd = nodeStart + node2.nodeSize;
53885
+ const contentToPreserve = node2.content;
53886
+ tr.delete(nodeStart, nodeEnd);
53887
+ if (contentToPreserve.size > 0) {
53888
+ tr.insert(nodeStart, contentToPreserve);
53889
+ }
53890
+ const newPos = Math.min(nodeStart, tr.doc.content.size);
53891
+ tr.setSelection(Selection.near(tr.doc.resolve(newPos)));
53892
+ if (dispatch) {
53893
+ tr.setMeta("documentSection", { action: "delete" });
53894
+ dispatch(tr);
53895
+ }
53896
+ return true;
53897
+ },
53898
+ /**
53899
+ * Remove a document section by its ID.
53900
+ * @param {string} id - The ID of the section to remove
53901
+ * @returns {Function} A command function that takes the editor state and dispatch function
53902
+ */
53903
+ removeSectionById: (id) => ({ tr, dispatch }) => {
53904
+ const sections = SectionHelpers.getAllSections(this.editor);
53905
+ const sectionToRemove = sections.find(({ node: node22 }) => node22.attrs.id === id);
53906
+ if (!sectionToRemove) return false;
53907
+ const { pos, node: node2 } = sectionToRemove;
53908
+ const nodeStart = pos;
53909
+ const nodeEnd = nodeStart + node2.nodeSize;
53910
+ tr.delete(nodeStart, nodeEnd);
53911
+ if (dispatch) {
53912
+ tr.setMeta("documentSection", { action: "delete", id });
53913
+ dispatch(tr);
53914
+ }
53915
+ return true;
53916
+ },
53917
+ /**
53918
+ * Lock a document section by its ID.
53919
+ * This command is a placeholder and does not perform any action yet.
53920
+ * @param {string} id - The ID of the section to lock
53921
+ * @returns {Function} A command function that takes the editor state and dispatch function
53922
+ */
53923
+ lockSectionById: (id) => ({ tr, dispatch }) => {
53924
+ const sections = SectionHelpers.getAllSections(this.editor);
53925
+ const sectionToLock = sections.find(({ node: node2 }) => node2.attrs.id === id);
53926
+ if (!sectionToLock) return false;
53927
+ tr.setNodeMarkup(sectionToLock.pos, null, { ...sectionToLock.node.attrs, isLocked: true });
53928
+ if (dispatch) {
53929
+ tr.setMeta("documentSection", { action: "lock", id });
53930
+ dispatch(tr);
53931
+ }
53932
+ return true;
53933
+ }
53934
+ };
53935
+ }
53936
+ });
53552
53937
  const TextStyle = Mark2.create({
53553
53938
  name: "textStyle",
53554
53939
  addOptions() {
@@ -59789,6 +60174,7 @@ const getStarterExtensions = () => {
59789
60174
  ContentBlock,
59790
60175
  Search,
59791
60176
  StructuredContent,
60177
+ DocumentSection,
59792
60178
  NodeResizer,
59793
60179
  CustomSelection
59794
60180
  ];
@@ -73532,7 +73918,9 @@ const ICONS = {
73532
73918
  table: tableIconSvg,
73533
73919
  cut: scissorsIconSvg,
73534
73920
  copy: copyIconSvg,
73535
- paste: pasteIconSvg
73921
+ paste: pasteIconSvg,
73922
+ addDocumentSection: plusIconSvg,
73923
+ removeDocumentSection: trashIconSvg
73536
73924
  };
73537
73925
  const TEXTS = {
73538
73926
  addRowBefore: "Insert row above",
@@ -73553,7 +73941,9 @@ const TEXTS = {
73553
73941
  editTable: "Edit table",
73554
73942
  cut: "Cut",
73555
73943
  copy: "Copy",
73556
- paste: "Paste"
73944
+ paste: "Paste",
73945
+ removeDocumentSection: "Remove section",
73946
+ createDocumentSection: "Create section"
73557
73947
  };
73558
73948
  const tableActionsOptions = [
73559
73949
  {
@@ -73858,6 +74248,7 @@ const isModuleEnabled = (editorOptions, moduleName) => {
73858
74248
  function getItems(context) {
73859
74249
  const { editor, selectedText, trigger: trigger2, clipboardContent } = context;
73860
74250
  const isInTable2 = selectionHasNodeOrMark(editor.view.state, "table", { requireEnds: true });
74251
+ const isInSectionNode = selectionHasNodeOrMark(editor.view.state, "documentSection", { requireEnds: true });
73861
74252
  const sections = [
73862
74253
  {
73863
74254
  id: "ai-content",
@@ -73877,6 +74268,30 @@ function getItems(context) {
73877
74268
  }
73878
74269
  ]
73879
74270
  },
74271
+ {
74272
+ id: "document-sections",
74273
+ items: [
74274
+ {
74275
+ id: "insert-document-section",
74276
+ label: TEXTS.createDocumentSection,
74277
+ icon: ICONS.addDocumentSection,
74278
+ action: (editor2) => {
74279
+ editor2.commands.createDocumentSection();
74280
+ },
74281
+ allowedTriggers: [TRIGGERS.click]
74282
+ },
74283
+ {
74284
+ id: "remove-section",
74285
+ label: TEXTS.removeDocumentSection,
74286
+ icon: ICONS.removeDocumentSection,
74287
+ action: (editor2) => {
74288
+ editor2.commands.removeSectionAtSelection();
74289
+ },
74290
+ allowedTriggers: [TRIGGERS.click],
74291
+ requiresSectionParent: true
74292
+ }
74293
+ ]
74294
+ },
73880
74295
  {
73881
74296
  id: "general",
73882
74297
  items: [
@@ -73975,6 +74390,7 @@ function getItems(context) {
73975
74390
  if (!item.allowedTriggers.includes(trigger2)) return false;
73976
74391
  if (item.requiresClipboard && !clipboardContent) return false;
73977
74392
  if (item.requiresTableParent && !isInTable2 || item.id === "insert-table" && isInTable2) return false;
74393
+ if (item.requiresSectionParent && !isInSectionNode) return false;
73978
74394
  return true;
73979
74395
  });
73980
74396
  return {
@@ -74957,23 +75373,24 @@ export {
74957
75373
  CommentsPluginKey as C,
74958
75374
  DocxZipper as D,
74959
75375
  Editor as E,
74960
- SuperConverter as S,
75376
+ SectionHelpers as S,
74961
75377
  Toolbar as T,
74962
75378
  _sfc_main$1 as _,
74963
75379
  AnnotatorHelpers as a,
74964
75380
  Extensions as b,
74965
75381
  _sfc_main$5 as c,
74966
- SuperEditor as d,
74967
- SuperInput as e,
74968
- SuperToolbar as f,
74969
- TrackChangesBasePluginKey as g,
74970
- createZip as h,
74971
- index$1 as i,
74972
- getActiveFormatting as j,
74973
- getAllowedImageDimensions as k,
74974
- getMarksFromSelection as l,
74975
- getRichTextExtensions as m,
74976
- getStarterExtensions as n,
74977
- helpers as o,
74978
- index as p
75382
+ SuperConverter as d,
75383
+ SuperEditor as e,
75384
+ SuperInput as f,
75385
+ SuperToolbar as g,
75386
+ TrackChangesBasePluginKey as h,
75387
+ createZip as i,
75388
+ index$1 as j,
75389
+ getActiveFormatting as k,
75390
+ getAllowedImageDimensions as l,
75391
+ getMarksFromSelection as m,
75392
+ getRichTextExtensions as n,
75393
+ getStarterExtensions as o,
75394
+ helpers as p,
75395
+ index as q
74979
75396
  };