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

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