roosterjs-content-model-api 0.25.0 → 0.26.1

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 (112) hide show
  1. package/lib/index.d.ts +5 -0
  2. package/lib/index.js +11 -1
  3. package/lib/index.js.map +1 -1
  4. package/lib/modelApi/block/setModelIndentation.d.ts +4 -1
  5. package/lib/modelApi/block/setModelIndentation.js +114 -23
  6. package/lib/modelApi/block/setModelIndentation.js.map +1 -1
  7. package/lib/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  8. package/lib/modelApi/entity/insertEntityModel.d.ts +2 -2
  9. package/lib/modelApi/entity/insertEntityModel.js +4 -0
  10. package/lib/modelApi/entity/insertEntityModel.js.map +1 -1
  11. package/lib/modelApi/list/findListItemsInSameThread.d.ts +3 -1
  12. package/lib/modelApi/list/findListItemsInSameThread.js +3 -1
  13. package/lib/modelApi/list/findListItemsInSameThread.js.map +1 -1
  14. package/lib/modelApi/list/setListType.js +1 -1
  15. package/lib/modelApi/list/setListType.js.map +1 -1
  16. package/lib/modelApi/table/clearSelectedCells.d.ts +8 -0
  17. package/lib/modelApi/table/clearSelectedCells.js +27 -0
  18. package/lib/modelApi/table/clearSelectedCells.js.map +1 -0
  19. package/lib/modelApi/table/insertTableColumn.d.ts +3 -1
  20. package/lib/modelApi/table/insertTableColumn.js +8 -2
  21. package/lib/modelApi/table/insertTableColumn.js.map +1 -1
  22. package/lib/modelApi/table/insertTableRow.d.ts +3 -1
  23. package/lib/modelApi/table/insertTableRow.js +8 -2
  24. package/lib/modelApi/table/insertTableRow.js.map +1 -1
  25. package/lib/publicApi/entity/insertEntity.js +7 -2
  26. package/lib/publicApi/entity/insertEntity.js.map +1 -1
  27. package/lib/publicApi/format/getFormatState.js +2 -2
  28. package/lib/publicApi/format/getFormatState.js.map +1 -1
  29. package/lib/publicApi/table/editTable.js +52 -77
  30. package/lib/publicApi/table/editTable.js.map +1 -1
  31. package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  32. package/lib/publicApi/utils/formatTableWithContentModel.d.ts +9 -0
  33. package/lib/publicApi/utils/formatTableWithContentModel.js +44 -0
  34. package/lib/publicApi/utils/formatTableWithContentModel.js.map +1 -0
  35. package/lib-amd/index.d.ts +5 -0
  36. package/lib-amd/index.js +7 -2
  37. package/lib-amd/index.js.map +1 -1
  38. package/lib-amd/modelApi/block/setModelIndentation.d.ts +4 -1
  39. package/lib-amd/modelApi/block/setModelIndentation.js +114 -24
  40. package/lib-amd/modelApi/block/setModelIndentation.js.map +1 -1
  41. package/lib-amd/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  42. package/lib-amd/modelApi/entity/insertEntityModel.d.ts +2 -2
  43. package/lib-amd/modelApi/entity/insertEntityModel.js +4 -0
  44. package/lib-amd/modelApi/entity/insertEntityModel.js.map +1 -1
  45. package/lib-amd/modelApi/list/findListItemsInSameThread.d.ts +3 -1
  46. package/lib-amd/modelApi/list/findListItemsInSameThread.js +3 -1
  47. package/lib-amd/modelApi/list/findListItemsInSameThread.js.map +1 -1
  48. package/lib-amd/modelApi/list/setListType.js +1 -1
  49. package/lib-amd/modelApi/list/setListType.js.map +1 -1
  50. package/lib-amd/modelApi/table/clearSelectedCells.d.ts +8 -0
  51. package/lib-amd/modelApi/table/clearSelectedCells.js +28 -0
  52. package/lib-amd/modelApi/table/clearSelectedCells.js.map +1 -0
  53. package/lib-amd/modelApi/table/insertTableColumn.d.ts +3 -1
  54. package/lib-amd/modelApi/table/insertTableColumn.js +8 -3
  55. package/lib-amd/modelApi/table/insertTableColumn.js.map +1 -1
  56. package/lib-amd/modelApi/table/insertTableRow.d.ts +3 -1
  57. package/lib-amd/modelApi/table/insertTableRow.js +8 -3
  58. package/lib-amd/modelApi/table/insertTableRow.js.map +1 -1
  59. package/lib-amd/publicApi/entity/insertEntity.js +7 -2
  60. package/lib-amd/publicApi/entity/insertEntity.js.map +1 -1
  61. package/lib-amd/publicApi/format/getFormatState.js +2 -2
  62. package/lib-amd/publicApi/format/getFormatState.js.map +1 -1
  63. package/lib-amd/publicApi/table/editTable.js +52 -74
  64. package/lib-amd/publicApi/table/editTable.js.map +1 -1
  65. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  66. package/lib-amd/publicApi/utils/formatTableWithContentModel.d.ts +9 -0
  67. package/lib-amd/publicApi/utils/formatTableWithContentModel.js +42 -0
  68. package/lib-amd/publicApi/utils/formatTableWithContentModel.js.map +1 -0
  69. package/lib-mjs/index.d.ts +5 -0
  70. package/lib-mjs/index.js +5 -0
  71. package/lib-mjs/index.js.map +1 -1
  72. package/lib-mjs/modelApi/block/setModelIndentation.d.ts +4 -1
  73. package/lib-mjs/modelApi/block/setModelIndentation.js +115 -24
  74. package/lib-mjs/modelApi/block/setModelIndentation.js.map +1 -1
  75. package/lib-mjs/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  76. package/lib-mjs/modelApi/entity/insertEntityModel.d.ts +2 -2
  77. package/lib-mjs/modelApi/entity/insertEntityModel.js +4 -0
  78. package/lib-mjs/modelApi/entity/insertEntityModel.js.map +1 -1
  79. package/lib-mjs/modelApi/list/findListItemsInSameThread.d.ts +3 -1
  80. package/lib-mjs/modelApi/list/findListItemsInSameThread.js +3 -1
  81. package/lib-mjs/modelApi/list/findListItemsInSameThread.js.map +1 -1
  82. package/lib-mjs/modelApi/list/setListType.js +1 -1
  83. package/lib-mjs/modelApi/list/setListType.js.map +1 -1
  84. package/lib-mjs/modelApi/table/clearSelectedCells.d.ts +8 -0
  85. package/lib-mjs/modelApi/table/clearSelectedCells.js +23 -0
  86. package/lib-mjs/modelApi/table/clearSelectedCells.js.map +1 -0
  87. package/lib-mjs/modelApi/table/insertTableColumn.d.ts +3 -1
  88. package/lib-mjs/modelApi/table/insertTableColumn.js +8 -2
  89. package/lib-mjs/modelApi/table/insertTableColumn.js.map +1 -1
  90. package/lib-mjs/modelApi/table/insertTableRow.d.ts +3 -1
  91. package/lib-mjs/modelApi/table/insertTableRow.js +8 -2
  92. package/lib-mjs/modelApi/table/insertTableRow.js.map +1 -1
  93. package/lib-mjs/publicApi/entity/insertEntity.js +7 -2
  94. package/lib-mjs/publicApi/entity/insertEntity.js.map +1 -1
  95. package/lib-mjs/publicApi/format/getFormatState.js +1 -1
  96. package/lib-mjs/publicApi/format/getFormatState.js.map +1 -1
  97. package/lib-mjs/publicApi/table/editTable.js +52 -77
  98. package/lib-mjs/publicApi/table/editTable.js.map +1 -1
  99. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  100. package/lib-mjs/publicApi/utils/formatTableWithContentModel.d.ts +9 -0
  101. package/lib-mjs/publicApi/utils/formatTableWithContentModel.js +40 -0
  102. package/lib-mjs/publicApi/utils/formatTableWithContentModel.js.map +1 -0
  103. package/package.json +4 -4
  104. package/lib/modelApi/common/retrieveModelFormatState.d.ts +0 -5
  105. package/lib/modelApi/common/retrieveModelFormatState.js +0 -171
  106. package/lib/modelApi/common/retrieveModelFormatState.js.map +0 -1
  107. package/lib-amd/modelApi/common/retrieveModelFormatState.d.ts +0 -5
  108. package/lib-amd/modelApi/common/retrieveModelFormatState.js +0 -171
  109. package/lib-amd/modelApi/common/retrieveModelFormatState.js.map +0 -1
  110. package/lib-mjs/modelApi/common/retrieveModelFormatState.d.ts +0 -5
  111. package/lib-mjs/modelApi/common/retrieveModelFormatState.js +0 -167
  112. package/lib-mjs/modelApi/common/retrieveModelFormatState.js.map +0 -1
@@ -1,48 +1,138 @@
1
- define(["require", "exports", "roosterjs-content-model-dom", "roosterjs-content-model-core"], function (require, exports, roosterjs_content_model_dom_1, roosterjs_content_model_core_1) {
1
+ define(["require", "exports", "roosterjs-content-model-dom", "../list/findListItemsInSameThread", "roosterjs-content-model-core"], function (require, exports, roosterjs_content_model_dom_1, findListItemsInSameThread_1, roosterjs_content_model_core_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.setModelIndentation = void 0;
5
5
  var IndentStepInPixel = 40;
6
6
  /**
7
- * @internal
7
+ * @param model The content model to set indentation
8
+ * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent
9
+ * @param length The length of indentation in pixel, default value is 40
10
+ * Set indentation for selected list items or paragraphs
8
11
  */
9
12
  function setModelIndentation(model, indentation, length) {
10
13
  if (length === void 0) { length = IndentStepInPixel; }
11
14
  var paragraphOrListItem = (0, roosterjs_content_model_core_1.getOperationalBlocks)(model, ['ListItem'], ['TableCell']);
12
15
  var isIndent = indentation == 'indent';
16
+ var modifiedBlocks = [];
13
17
  paragraphOrListItem.forEach(function (_a) {
14
- var block = _a.block;
18
+ var block = _a.block, parent = _a.parent, path = _a.path;
15
19
  if ((0, roosterjs_content_model_core_1.isBlockGroupOfType)(block, 'ListItem')) {
16
- if (isIndent) {
17
- var lastLevel = block.levels[block.levels.length - 1];
18
- var newLevel = (0, roosterjs_content_model_dom_1.createListLevel)((lastLevel === null || lastLevel === void 0 ? void 0 : lastLevel.listType) || 'UL', lastLevel === null || lastLevel === void 0 ? void 0 : lastLevel.format);
19
- // New level is totally new, no need to have these attributes for now
20
- delete newLevel.format.startNumberOverride;
21
- block.levels.push(newLevel);
20
+ var thread = (0, findListItemsInSameThread_1.findListItemsInSameThread)(model, block);
21
+ var firstItem = thread[0];
22
+ //if the first item is selected and has only one level, we should add margin to the whole list
23
+ if (isSelected(firstItem) && firstItem.levels.length == 1) {
24
+ var level = block.levels[0];
25
+ var format = level.format;
26
+ var marginLeft = format.marginLeft, marginRight = format.marginRight;
27
+ var newValue = calculateMarginValue(format, isIndent, length);
28
+ var isRtl = format.direction == 'rtl';
29
+ var originalValue = (0, roosterjs_content_model_dom_1.parseValueWithUnit)(isRtl ? marginRight : marginLeft);
30
+ if (!isIndent && originalValue == 0) {
31
+ block.levels.pop();
32
+ }
33
+ else if (newValue !== null) {
34
+ if (isRtl) {
35
+ level.format.marginRight = newValue + 'px';
36
+ }
37
+ else {
38
+ level.format.marginLeft = newValue + 'px';
39
+ }
40
+ }
41
+ //if block has only one level, there is not need to check if it is multilevel selection
22
42
  }
23
- else {
24
- block.levels.pop();
43
+ else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {
44
+ if (isIndent) {
45
+ var lastLevel = block.levels[block.levels.length - 1];
46
+ var newLevel = (0, roosterjs_content_model_dom_1.createListLevel)((lastLevel === null || lastLevel === void 0 ? void 0 : lastLevel.listType) || 'UL', lastLevel === null || lastLevel === void 0 ? void 0 : lastLevel.format);
47
+ (0, roosterjs_content_model_core_1.updateListMetadata)(newLevel, function (metadata) {
48
+ metadata = metadata || {};
49
+ metadata.applyListStyleFromLevel = true;
50
+ return metadata;
51
+ });
52
+ // New level is totally new, no need to have these attributes for now
53
+ delete newLevel.format.startNumberOverride;
54
+ block.levels.push(newLevel);
55
+ }
56
+ else {
57
+ block.levels.pop();
58
+ }
25
59
  }
26
60
  }
27
61
  else if (block) {
28
- var format = block.format;
29
- var marginLeft = format.marginLeft, marginRight = format.marginRight, direction = format.direction;
30
- var isRtl = direction == 'rtl';
31
- var originalValue = (0, roosterjs_content_model_dom_1.parseValueWithUnit)(isRtl ? marginRight : marginLeft);
32
- var newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;
33
- if (newValue == originalValue) {
34
- newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);
35
- }
36
- if (isRtl) {
37
- format.marginRight = newValue + 'px';
38
- }
39
- else {
40
- format.marginLeft = newValue + 'px';
62
+ var currentBlock = block;
63
+ var currentParent = parent;
64
+ while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {
65
+ var index = path.indexOf(currentParent);
66
+ var format = currentBlock.format;
67
+ var newValue = calculateMarginValue(format, isIndent, length);
68
+ if (newValue !== null) {
69
+ var isRtl = format.direction == 'rtl';
70
+ if (isRtl) {
71
+ format.marginRight = newValue + 'px';
72
+ }
73
+ else {
74
+ format.marginLeft = newValue + 'px';
75
+ }
76
+ modifiedBlocks.push(currentBlock);
77
+ break;
78
+ }
79
+ else if (currentParent.blockGroupType == 'FormatContainer' && index >= 0) {
80
+ delete currentParent.cachedElement;
81
+ currentBlock = currentParent;
82
+ currentParent = path[index + 1];
83
+ }
84
+ else {
85
+ break;
86
+ }
41
87
  }
42
88
  }
43
89
  });
44
90
  return paragraphOrListItem.length > 0;
45
91
  }
46
92
  exports.setModelIndentation = setModelIndentation;
93
+ function isSelected(listItem) {
94
+ return listItem.blocks.some(function (block) {
95
+ if (block.blockType == 'Paragraph') {
96
+ return block.segments.some(function (segment) { return segment.isSelected; });
97
+ }
98
+ });
99
+ }
100
+ /*
101
+ * Check if the selection has list items with different levels and the first item of the list is selected, do not create a sub list.
102
+ * Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.
103
+ */
104
+ function isMultilevelSelection(model, listItem, parent) {
105
+ var listIndex = parent.blocks.indexOf(listItem);
106
+ for (var i = listIndex - 1; i >= 0; i--) {
107
+ var block = parent.blocks[i];
108
+ if ((0, roosterjs_content_model_core_1.isBlockGroupOfType)(block, 'ListItem') &&
109
+ block.levels.length == 1 &&
110
+ isSelected(block)) {
111
+ var firstItem = (0, findListItemsInSameThread_1.findListItemsInSameThread)(model, block)[0];
112
+ return isSelected(firstItem);
113
+ }
114
+ if (!(0, roosterjs_content_model_core_1.isBlockGroupOfType)(block, 'ListItem')) {
115
+ return false;
116
+ }
117
+ }
118
+ return false;
119
+ }
120
+ function calculateMarginValue(format, isIndent, length) {
121
+ if (length === void 0) { length = IndentStepInPixel; }
122
+ var marginLeft = format.marginLeft, marginRight = format.marginRight, direction = format.direction;
123
+ var isRtl = direction == 'rtl';
124
+ var originalValue = (0, roosterjs_content_model_dom_1.parseValueWithUnit)(isRtl ? marginRight : marginLeft);
125
+ var newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;
126
+ if (newValue == originalValue) {
127
+ newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);
128
+ }
129
+ if (newValue == originalValue) {
130
+ // Return null to let caller know nothing is changed
131
+ return null;
132
+ }
133
+ else {
134
+ return newValue;
135
+ }
136
+ }
47
137
  });
48
138
  //# sourceMappingURL=setModelIndentation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"setModelIndentation.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelIndentation.ts"],"names":[],"mappings":";;;;IAQA,IAAM,iBAAiB,GAAG,EAAE,CAAC;IAE7B;;OAEG;IACH,SAAgB,mBAAmB,CAC/B,KAA2B,EAC3B,WAAiC,EACjC,MAAkC;QAAlC,uBAAA,EAAA,0BAAkC;QAElC,IAAM,mBAAmB,GAAG,IAAA,mDAAoB,EAC5C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;QACF,IAAM,QAAQ,GAAG,WAAW,IAAI,QAAQ,CAAC;QAEzC,mBAAmB,CAAC,OAAO,CAAC,UAAC,EAAS;gBAAP,KAAK,WAAA;YAChC,IAAI,IAAA,iDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;gBAC7D,IAAI,QAAQ,EAAE;oBACV,IAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;oBACxD,IAAM,QAAQ,GAA0B,IAAA,6CAAe,EACnD,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,QAAQ,KAAI,IAAI,EAC3B,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,CACpB,CAAC;oBAEF,qEAAqE;oBACrE,OAAO,QAAQ,CAAC,MAAM,CAAC,mBAAmB,CAAC;oBAE3C,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;iBAC/B;qBAAM;oBACH,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;iBACtB;aACJ;iBAAM,IAAI,KAAK,EAAE;gBACN,IAAA,MAAM,GAAK,KAAK,OAAV,CAAW;gBACjB,IAAA,UAAU,GAA6B,MAAM,WAAnC,EAAE,WAAW,GAAgB,MAAM,YAAtB,EAAE,SAAS,GAAK,MAAM,UAAX,CAAY;gBACtD,IAAM,KAAK,GAAG,SAAS,IAAI,KAAK,CAAC;gBACjC,IAAM,aAAa,GAAG,IAAA,gDAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;gBAC3E,IAAI,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;gBAEpF,IAAI,QAAQ,IAAI,aAAa,EAAE;oBAC3B,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;iBACnE;gBAED,IAAI,KAAK,EAAE;oBACP,MAAM,CAAC,WAAW,GAAG,QAAQ,GAAG,IAAI,CAAC;iBACxC;qBAAM;oBACH,MAAM,CAAC,UAAU,GAAG,QAAQ,GAAG,IAAI,CAAC;iBACvC;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,mBAAmB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1C,CAAC;IAhDD,kDAgDC","sourcesContent":["import { createListLevel, parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelListItem,\n ContentModelListLevel,\n} from 'roosterjs-content-model-types';\n\nconst IndentStepInPixel = 40;\n\n/**\n * @internal\n */\nexport function setModelIndentation(\n model: ContentModelDocument,\n indentation: 'indent' | 'outdent',\n length: number = IndentStepInPixel\n) {\n const paragraphOrListItem = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n const isIndent = indentation == 'indent';\n\n paragraphOrListItem.forEach(({ block }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n if (isIndent) {\n const lastLevel = block.levels[block.levels.length - 1];\n const newLevel: ContentModelListLevel = createListLevel(\n lastLevel?.listType || 'UL',\n lastLevel?.format\n );\n\n // New level is totally new, no need to have these attributes for now\n delete newLevel.format.startNumberOverride;\n\n block.levels.push(newLevel);\n } else {\n block.levels.pop();\n }\n } else if (block) {\n const { format } = block;\n const { marginLeft, marginRight, direction } = format;\n const isRtl = direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n let newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;\n\n if (newValue == originalValue) {\n newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);\n }\n\n if (isRtl) {\n format.marginRight = newValue + 'px';\n } else {\n format.marginLeft = newValue + 'px';\n }\n }\n });\n\n return paragraphOrListItem.length > 0;\n}\n"]}
1
+ {"version":3,"file":"setModelIndentation.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelIndentation.ts"],"names":[],"mappings":";;;;IAiBA,IAAM,iBAAiB,GAAG,EAAE,CAAC;IAE7B;;;;;OAKG;IACH,SAAgB,mBAAmB,CAC/B,KAA2B,EAC3B,WAAiC,EACjC,MAAkC;QAAlC,uBAAA,EAAA,0BAAkC;QAElC,IAAM,mBAAmB,GAAG,IAAA,mDAAoB,EAC5C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;QACF,IAAM,QAAQ,GAAG,WAAW,IAAI,QAAQ,CAAC;QACzC,IAAM,cAAc,GAAwB,EAAE,CAAC;QAE/C,mBAAmB,CAAC,OAAO,CAAC,UAAC,EAAuB;gBAArB,KAAK,WAAA,EAAE,MAAM,YAAA,EAAE,IAAI,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ACnB;IACL,CAAC","sourcesContent":["import { createListLevel, parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport {\n getOperationalBlocks,\n isBlockGroupOfType,\n updateListMetadata,\n} from 'roosterjs-content-model-core';\n\nimport type {\n ContentModelBlock,\n ContentModelBlockFormat,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelListItem,\n ContentModelListLevel,\n} from 'roosterjs-content-model-types';\n\nconst IndentStepInPixel = 40;\n\n/**\n * @param model The content model to set indentation\n * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent\n * @param length The length of indentation in pixel, default value is 40\n * Set indentation for selected list items or paragraphs\n */\nexport function setModelIndentation(\n model: ContentModelDocument,\n indentation: 'indent' | 'outdent',\n length: number = IndentStepInPixel\n) {\n const paragraphOrListItem = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n const isIndent = indentation == 'indent';\n const modifiedBlocks: ContentModelBlock[] = [];\n\n paragraphOrListItem.forEach(({ block, parent, path }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const thread = findListItemsInSameThread(model, block);\n const firstItem = thread[0];\n //if the first item is selected and has only one level, we should add margin to the whole list\n if (isSelected(firstItem) && firstItem.levels.length == 1) {\n const level = block.levels[0];\n const { format } = level;\n const { marginLeft, marginRight } = format;\n const newValue = calculateMarginValue(format, isIndent, length);\n const isRtl = format.direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n\n if (!isIndent && originalValue == 0) {\n block.levels.pop();\n } else if (newValue !== null) {\n if (isRtl) {\n level.format.marginRight = newValue + 'px';\n } else {\n level.format.marginLeft = newValue + 'px';\n }\n }\n //if block has only one level, there is not need to check if it is multilevel selection\n } else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {\n if (isIndent) {\n const lastLevel = block.levels[block.levels.length - 1];\n const newLevel: ContentModelListLevel = createListLevel(\n lastLevel?.listType || 'UL',\n lastLevel?.format\n );\n\n updateListMetadata(newLevel, metadata => {\n metadata = metadata || {};\n metadata.applyListStyleFromLevel = true;\n return metadata;\n });\n\n // New level is totally new, no need to have these attributes for now\n delete newLevel.format.startNumberOverride;\n\n block.levels.push(newLevel);\n } else {\n block.levels.pop();\n }\n }\n } else if (block) {\n let currentBlock: ContentModelBlock = block;\n let currentParent: ContentModelBlockGroup = parent;\n\n while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {\n const index = path.indexOf(currentParent);\n const { format } = currentBlock;\n const newValue = calculateMarginValue(format, isIndent, length);\n\n if (newValue !== null) {\n const isRtl = format.direction == 'rtl';\n\n if (isRtl) {\n format.marginRight = newValue + 'px';\n } else {\n format.marginLeft = newValue + 'px';\n }\n\n modifiedBlocks.push(currentBlock);\n\n break;\n } else if (currentParent.blockGroupType == 'FormatContainer' && index >= 0) {\n delete currentParent.cachedElement;\n\n currentBlock = currentParent;\n currentParent = path[index + 1];\n } else {\n break;\n }\n }\n }\n });\n\n return paragraphOrListItem.length > 0;\n}\n\nfunction isSelected(listItem: ContentModelListItem) {\n return listItem.blocks.some(block => {\n if (block.blockType == 'Paragraph') {\n return block.segments.some(segment => segment.isSelected);\n }\n });\n}\n\n/*\n * Check if the selection has list items with different levels and the first item of the list is selected, do not create a sub list.\n * Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.\n */\nfunction isMultilevelSelection(\n model: ContentModelDocument,\n listItem: ContentModelListItem,\n parent: ContentModelBlockGroup\n) {\n const listIndex = parent.blocks.indexOf(listItem);\n for (let i = listIndex - 1; i >= 0; i--) {\n const block = parent.blocks[i];\n if (\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem') &&\n block.levels.length == 1 &&\n isSelected(block)\n ) {\n const firstItem = findListItemsInSameThread(model, block)[0];\n return isSelected(firstItem);\n }\n\n if (!isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return false;\n }\n }\n return false;\n}\n\nfunction calculateMarginValue(\n format: ContentModelBlockFormat,\n isIndent: boolean,\n length: number = IndentStepInPixel\n): number | null {\n const { marginLeft, marginRight, direction } = format;\n const isRtl = direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n let newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;\n\n if (newValue == originalValue) {\n newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);\n }\n\n if (newValue == originalValue) {\n // Return null to let caller know nothing is changed\n return null;\n } else {\n return newValue;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"toggleModelBlockQuote.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/toggleModelBlockQuote.ts"],"names":[],"mappings":";;;;IAcA;;OAEG;IACH,SAAgB,qBAAqB,CACjC,KAA2B,EAC3B,SAA4C,EAC5C,SAA4C;QAE5C,IAAM,gBAAgB,GAAG,IAAA,mDAAoB,EAE3C,KAAK,EAAE,CAAC,iBAAiB,EAAE,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAE7E,IAAI,iBAAiB,CAAC,gBAAgB,CAAC,EAAE;YACrC,+DAA+D;YAC/D,gBAAgB,CAAC,OAAO,CAAC,UAAC,EAAiB;oBAAf,KAAK,WAAA,EAAE,MAAM,YAAA;gBACrC,IAAA,yCAAW,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;SACN;aAAM;YACH,IAAM,cAAY,GAAwD,EAAE,CAAC;YAC7E,IAAM,SAAO,GAAG,UAAC,KAAc;gBAC3B,OAAA,IAAA,mDAAqB,EAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;YAAlE,CAAkE,CAAC;YACvE,IAAM,UAAQ,GAAG,UACb,KAAc,EACd,MAAyB,EACzB,OAAqC;gBAErC,OAAA,aAAa,CAAC,MAAM,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YAAzE,CAAyE,CAAC;YAE9E,gBAAgB,CAAC,OAAO,CAAC,UAAC,EAAiB;oBAAf,KAAK,WAAA,EAAE,MAAM,YAAA;gBACrC,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;oBAChB,0BAA0B;iBAC7B;qBAAM;oBACH,IAAA,0BAAc,EAAC,cAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAO,EAAE,UAAQ,CAAC,CAAC;iBAClE;YACL,CAAC,CAAC,CAAC;YAEH,IAAA,0BAAc,EAAC,cAAY,EAAE,UAAQ,CAAC,CAAC;SAC1C;QAED,OAAO,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;IACvC,CAAC;IArCD,sDAqCC;IAED,SAAS,aAAa,CAClB,MAAyB,EACzB,MAAyC;QAEzC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,IAAA,4CAAc,EAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;IAED,SAAS,OAAO,CAAC,KAAwB;QACrC,OAAO,CACH,IAAA,iDAAkB,EAA8B,KAAK,EAAE,iBAAiB,CAAC;YACzE,KAAK,CAAC,OAAO,IAAI,YAAY,CAChC,CAAC;IACN,CAAC;IAED,SAAS,iBAAiB,CACtB,eAAwF;QAExF,OAAO,eAAe,CAAC,KAAK,CAAC,UAAA,cAAc,IAAI,OAAA,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,EAA7B,CAA6B,CAAC,CAAC;IAClF,CAAC","sourcesContent":["import { areSameFormats, createFormatContainer, unwrapBlock } from 'roosterjs-content-model-dom';\nimport { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';\nimport { wrapBlockStep1, wrapBlockStep2 } from '../common/wrapBlock';\nimport type { OperationalBlocks } from 'roosterjs-content-model-core';\nimport type { WrapBlockStep1Result } from '../common/wrapBlock';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelFormatContainerFormat,\n ContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function toggleModelBlockQuote(\n model: ContentModelDocument,\n formatLtr: ContentModelFormatContainerFormat,\n formatRtl: ContentModelFormatContainerFormat\n): boolean {\n const paragraphOfQuote = getOperationalBlocks<\n ContentModelFormatContainer | ContentModelListItem\n >(model, ['FormatContainer', 'ListItem'], ['TableCell'], true /*deepFirst*/);\n\n if (areAllBlockQuotes(paragraphOfQuote)) {\n // All selections are already in quote, we need to unquote them\n paragraphOfQuote.forEach(({ block, parent }) => {\n unwrapBlock(parent, block);\n });\n } else {\n const step1Results: WrapBlockStep1Result<ContentModelFormatContainer>[] = [];\n const creator = (isRtl: boolean) =>\n createFormatContainer('blockquote', isRtl ? formatRtl : formatLtr);\n const canMerge = (\n isRtl: boolean,\n target: ContentModelBlock,\n current?: ContentModelFormatContainer\n ): target is ContentModelFormatContainer =>\n canMergeQuote(target, current?.format || (isRtl ? formatRtl : formatLtr));\n\n paragraphOfQuote.forEach(({ block, parent }) => {\n if (isQuote(block)) {\n // Already in quote, no op\n } else {\n wrapBlockStep1(step1Results, parent, block, creator, canMerge);\n }\n });\n\n wrapBlockStep2(step1Results, canMerge);\n }\n\n return paragraphOfQuote.length > 0;\n}\n\nfunction canMergeQuote(\n target: ContentModelBlock,\n format: ContentModelFormatContainerFormat\n): target is ContentModelFormatContainer {\n return isQuote(target) && areSameFormats(format, target.format);\n}\n\nfunction isQuote(block: ContentModelBlock): block is ContentModelFormatContainer {\n return (\n isBlockGroupOfType<ContentModelFormatContainer>(block, 'FormatContainer') &&\n block.tagName == 'blockquote'\n );\n}\n\nfunction areAllBlockQuotes(\n blockAndParents: OperationalBlocks<ContentModelFormatContainer | ContentModelListItem>[]\n): blockAndParents is { block: ContentModelFormatContainer; parent: ContentModelBlockGroup }[] {\n return blockAndParents.every(blockAndParent => isQuote(blockAndParent.block));\n}\n"]}
1
+ {"version":3,"file":"toggleModelBlockQuote.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/toggleModelBlockQuote.ts"],"names":[],"mappings":";;;;IAcA;;OAEG;IACH,SAAgB,qBAAqB,CACjC,KAA2B,EAC3B,SAA4C,EAC5C,SAA4C;QAE5C,IAAM,gBAAgB,GAAG,IAAA,mDAAoB,EAE3C,KAAK,EAAE,CAAC,iBAAiB,EAAE,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAE7E,IAAI,iBAAiB,CAAC,gBAAgB,CAAC,EAAE;YACrC,+DAA+D;YAC/D,gBAAgB,CAAC,OAAO,CAAC,UAAC,EAAiB;oBAAf,KAAK,WAAA,EAAE,MAAM,YAAA;gBACrC,IAAA,yCAAW,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;SACN;aAAM;YACH,IAAM,cAAY,GAAwD,EAAE,CAAC;YAC7E,IAAM,SAAO,GAAG,UAAC,KAAc;gBAC3B,OAAA,IAAA,mDAAqB,EAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;YAAlE,CAAkE,CAAC;YACvE,IAAM,UAAQ,GAAG,UACb,KAAc,EACd,MAAyB,EACzB,OAAqC;gBAErC,OAAA,aAAa,CAAC,MAAM,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YAAzE,CAAyE,CAAC;YAE9E,gBAAgB,CAAC,OAAO,CAAC,UAAC,EAAiB;oBAAf,KAAK,WAAA,EAAE,MAAM,YAAA;gBACrC,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;oBAChB,0BAA0B;iBAC7B;qBAAM;oBACH,IAAA,0BAAc,EAAC,cAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAO,EAAE,UAAQ,CAAC,CAAC;iBAClE;YACL,CAAC,CAAC,CAAC;YAEH,IAAA,0BAAc,EAAC,cAAY,EAAE,UAAQ,CAAC,CAAC;SAC1C;QAED,OAAO,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;IACvC,CAAC;IArCD,sDAqCC;IAED,SAAS,aAAa,CAClB,MAAyB,EACzB,MAAyC;QAEzC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,IAAA,4CAAc,EAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;IAED,SAAS,OAAO,CAAC,KAAwB;QACrC,OAAO,CACH,IAAA,iDAAkB,EAA8B,KAAK,EAAE,iBAAiB,CAAC;YACzE,KAAK,CAAC,OAAO,IAAI,YAAY,CAChC,CAAC;IACN,CAAC;IAED,SAAS,iBAAiB,CACtB,eAAwF;QAMxF,OAAO,eAAe,CAAC,KAAK,CAAC,UAAA,cAAc,IAAI,OAAA,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,EAA7B,CAA6B,CAAC,CAAC;IAClF,CAAC","sourcesContent":["import { areSameFormats, createFormatContainer, unwrapBlock } from 'roosterjs-content-model-dom';\nimport { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';\nimport { wrapBlockStep1, wrapBlockStep2 } from '../common/wrapBlock';\nimport type { OperationalBlocks } from 'roosterjs-content-model-core';\nimport type { WrapBlockStep1Result } from '../common/wrapBlock';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelFormatContainerFormat,\n ContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function toggleModelBlockQuote(\n model: ContentModelDocument,\n formatLtr: ContentModelFormatContainerFormat,\n formatRtl: ContentModelFormatContainerFormat\n): boolean {\n const paragraphOfQuote = getOperationalBlocks<\n ContentModelFormatContainer | ContentModelListItem\n >(model, ['FormatContainer', 'ListItem'], ['TableCell'], true /*deepFirst*/);\n\n if (areAllBlockQuotes(paragraphOfQuote)) {\n // All selections are already in quote, we need to unquote them\n paragraphOfQuote.forEach(({ block, parent }) => {\n unwrapBlock(parent, block);\n });\n } else {\n const step1Results: WrapBlockStep1Result<ContentModelFormatContainer>[] = [];\n const creator = (isRtl: boolean) =>\n createFormatContainer('blockquote', isRtl ? formatRtl : formatLtr);\n const canMerge = (\n isRtl: boolean,\n target: ContentModelBlock,\n current?: ContentModelFormatContainer\n ): target is ContentModelFormatContainer =>\n canMergeQuote(target, current?.format || (isRtl ? formatRtl : formatLtr));\n\n paragraphOfQuote.forEach(({ block, parent }) => {\n if (isQuote(block)) {\n // Already in quote, no op\n } else {\n wrapBlockStep1(step1Results, parent, block, creator, canMerge);\n }\n });\n\n wrapBlockStep2(step1Results, canMerge);\n }\n\n return paragraphOfQuote.length > 0;\n}\n\nfunction canMergeQuote(\n target: ContentModelBlock,\n format: ContentModelFormatContainerFormat\n): target is ContentModelFormatContainer {\n return isQuote(target) && areSameFormats(format, target.format);\n}\n\nfunction isQuote(block: ContentModelBlock): block is ContentModelFormatContainer {\n return (\n isBlockGroupOfType<ContentModelFormatContainer>(block, 'FormatContainer') &&\n block.tagName == 'blockquote'\n );\n}\n\nfunction areAllBlockQuotes(\n blockAndParents: OperationalBlocks<ContentModelFormatContainer | ContentModelListItem>[]\n): blockAndParents is {\n block: ContentModelFormatContainer;\n parent: ContentModelBlockGroup;\n path: ContentModelBlockGroup[];\n}[] {\n return blockAndParents.every(blockAndParent => isQuote(blockAndParent.block));\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { ContentModelDocument, ContentModelEntity, FormatWithContentModelContext, InsertEntityPosition } from 'roosterjs-content-model-types';
1
+ import type { ContentModelDocument, ContentModelEntity, FormatContentModelContext, InsertEntityPosition } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export declare function insertEntityModel(model: ContentModelDocument, entityModel: ContentModelEntity, position: InsertEntityPosition, isBlock: boolean, focusAfterEntity?: boolean, context?: FormatWithContentModelContext): void;
5
+ export declare function insertEntityModel(model: ContentModelDocument, entityModel: ContentModelEntity, position: InsertEntityPosition, isBlock: boolean, focusAfterEntity?: boolean, context?: FormatContentModelContext): void;
@@ -14,6 +14,9 @@ define(["require", "exports", "tslib", "roosterjs-content-model-core", "roosterj
14
14
  if (position == 'begin' || position == 'end') {
15
15
  blockParent = model;
16
16
  blockIndex = position == 'begin' ? 0 : model.blocks.length;
17
+ if (!isBlock) {
18
+ Object.assign(entityModel.format, model.format);
19
+ }
17
20
  }
18
21
  else if ((deleteResult = (0, roosterjs_content_model_core_1.deleteSelection)(model, [], context)).insertPoint) {
19
22
  var _c = deleteResult.insertPoint, marker = _c.marker, paragraph = _c.paragraph, path = _c.path;
@@ -22,6 +25,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-core", "roosterj
22
25
  }
23
26
  if (!isBlock) {
24
27
  var index = paragraph.segments.indexOf(marker);
28
+ Object.assign(entityModel.format, marker.format);
25
29
  if (index >= 0) {
26
30
  paragraph.segments.splice(focusAfterEntity ? index : index + 1, 0, entityModel);
27
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"insertEntityModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/entity/insertEntityModel.ts"],"names":[],"mappings":";;;;IAsBA;;OAEG;IACH,SAAgB,iBAAiB,CAC7B,KAA2B,EAC3B,WAA+B,EAC/B,QAA8B,EAC9B,OAAgB,EAChB,gBAA0B,EAC1B,OAAuC;;;QAEvC,IAAI,WAA+C,CAAC;QACpD,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC;QACpB,IAAI,YAAmC,CAAC;QAExC,IAAI,QAAQ,IAAI,OAAO,IAAI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AC,WAAW,CAAC,CAAC;gBACzC,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aACtC;YAED,CAAA,KAAA,WAAW,CAAC,MAAM,CAAA,CAAC,MAAM,uCAAC,UAAU,EAAE,CAAC,uBAAK,cAAc,WAAE;YAE5D,IAAI,gBAAgB,IAAI,aAAa,EAAE;gBACnC,IAAM,MAAM,GAAG,IAAA,mDAAqB,EAAC,CAAA,MAAA,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,KAAI,KAAK,CAAC,MAAM,CAAC,CAAC;gBACxF,IAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC;gBAExC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC3D,IAAA,2CAAY,EAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;aACvC;SACJ;IACL,CAAC;IAnFD,8CAmFC","sourcesContent":["import {\n deleteSelection,\n getClosestAncestorBlockGroupIndex,\n setSelection,\n} from 'roosterjs-content-model-core';\nimport {\n createBr,\n createParagraph,\n createSelectionMarker,\n normalizeContentModel,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelEntity,\n ContentModelParagraph,\n DeleteSelectionResult,\n FormatWithContentModelContext,\n InsertEntityPosition,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function insertEntityModel(\n model: ContentModelDocument,\n entityModel: ContentModelEntity,\n position: InsertEntityPosition,\n isBlock: boolean,\n focusAfterEntity?: boolean,\n context?: FormatWithContentModelContext\n) {\n let blockParent: ContentModelBlockGroup | undefined;\n let blockIndex = -1;\n let deleteResult: DeleteSelectionResult;\n\n if (position == 'begin' || position == 'end') {\n blockParent = model;\n blockIndex = position == 'begin' ? 0 : model.blocks.length;\n } else if ((deleteResult = deleteSelection(model, [], context)).insertPoint) {\n const { marker, paragraph, path } = deleteResult.insertPoint;\n\n if (deleteResult.deleteResult == 'range') {\n normalizeContentModel(model);\n }\n\n if (!isBlock) {\n const index = paragraph.segments.indexOf(marker);\n\n if (index >= 0) {\n paragraph.segments.splice(focusAfterEntity ? index : index + 1, 0, entityModel);\n }\n } else {\n const pathIndex =\n position == 'root'\n ? getClosestAncestorBlockGroupIndex(path, ['TableCell', 'Document'])\n : 0;\n blockParent = path[pathIndex];\n const child = path[pathIndex - 1];\n const directChild: ContentModelBlock =\n child?.blockGroupType == 'FormatContainer' ||\n child?.blockGroupType == 'General' ||\n child?.blockGroupType == 'ListItem'\n ? child\n : paragraph;\n const childIndex = blockParent.blocks.indexOf(directChild);\n blockIndex = childIndex >= 0 ? childIndex + 1 : -1;\n }\n }\n\n if (blockIndex >= 0 && blockParent) {\n const blocksToInsert: ContentModelBlock[] = [];\n let nextParagraph: ContentModelParagraph | undefined;\n\n if (isBlock) {\n const nextBlock = blockParent.blocks[blockIndex];\n\n blocksToInsert.push(entityModel);\n\n if (nextBlock?.blockType == 'Paragraph') {\n nextParagraph = nextBlock;\n } else if (!nextBlock || nextBlock.blockType == 'Entity' || focusAfterEntity) {\n nextParagraph = createParagraph(false /*isImplicit*/, {}, model.format);\n nextParagraph.segments.push(createBr(model.format));\n blocksToInsert.push(nextParagraph);\n }\n } else {\n nextParagraph = createParagraph(\n false /*isImplicit*/,\n undefined /*format*/,\n model.format\n );\n\n nextParagraph.segments.push(entityModel);\n blocksToInsert.push(nextParagraph);\n }\n\n blockParent.blocks.splice(blockIndex, 0, ...blocksToInsert);\n\n if (focusAfterEntity && nextParagraph) {\n const marker = createSelectionMarker(nextParagraph.segments[0]?.format || model.format);\n const segments = nextParagraph.segments;\n\n isBlock ? segments.unshift(marker) : segments.push(marker);\n setSelection(model, marker, marker);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"insertEntityModel.js","sourceRoot":"","sources":["../../../../../packages-content-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'roosterjs-content-model-core';\nimport {\n createBr,\n createParagraph,\n createSelectionMarker,\n normalizeContentModel,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelEntity,\n ContentModelParagraph,\n DeleteSelectionResult,\n FormatContentModelContext,\n InsertEntityPosition,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function insertEntityModel(\n model: ContentModelDocument,\n entityModel: ContentModelEntity,\n position: InsertEntityPosition,\n isBlock: boolean,\n focusAfterEntity?: boolean,\n context?: FormatContentModelContext\n) {\n let blockParent: ContentModelBlockGroup | undefined;\n let blockIndex = -1;\n let deleteResult: DeleteSelectionResult;\n\n if (position == 'begin' || position == 'end') {\n blockParent = model;\n blockIndex = position == 'begin' ? 0 : model.blocks.length;\n\n if (!isBlock) {\n Object.assign(entityModel.format, model.format);\n }\n } else if ((deleteResult = deleteSelection(model, [], context)).insertPoint) {\n const { marker, paragraph, path } = deleteResult.insertPoint;\n\n if (deleteResult.deleteResult == 'range') {\n normalizeContentModel(model);\n }\n\n if (!isBlock) {\n const index = paragraph.segments.indexOf(marker);\n\n Object.assign(entityModel.format, marker.format);\n\n if (index >= 0) {\n paragraph.segments.splice(focusAfterEntity ? index : index + 1, 0, entityModel);\n }\n } else {\n const pathIndex =\n position == 'root'\n ? getClosestAncestorBlockGroupIndex(path, ['TableCell', 'Document'])\n : 0;\n blockParent = path[pathIndex];\n const child = path[pathIndex - 1];\n const directChild: ContentModelBlock =\n child?.blockGroupType == 'FormatContainer' ||\n child?.blockGroupType == 'General' ||\n child?.blockGroupType == 'ListItem'\n ? child\n : paragraph;\n const childIndex = blockParent.blocks.indexOf(directChild);\n blockIndex = childIndex >= 0 ? childIndex + 1 : -1;\n }\n }\n\n if (blockIndex >= 0 && blockParent) {\n const blocksToInsert: ContentModelBlock[] = [];\n let nextParagraph: ContentModelParagraph | undefined;\n\n if (isBlock) {\n const nextBlock = blockParent.blocks[blockIndex];\n\n blocksToInsert.push(entityModel);\n\n if (nextBlock?.blockType == 'Paragraph') {\n nextParagraph = nextBlock;\n } else if (!nextBlock || nextBlock.blockType == 'Entity' || focusAfterEntity) {\n nextParagraph = createParagraph(false /*isImplicit*/, {}, model.format);\n nextParagraph.segments.push(createBr(model.format));\n blocksToInsert.push(nextParagraph);\n }\n } else {\n nextParagraph = createParagraph(\n false /*isImplicit*/,\n undefined /*format*/,\n model.format\n );\n\n nextParagraph.segments.push(entityModel);\n blocksToInsert.push(nextParagraph);\n }\n\n blockParent.blocks.splice(blockIndex, 0, ...blocksToInsert);\n\n if (focusAfterEntity && nextParagraph) {\n const marker = createSelectionMarker(nextParagraph.segments[0]?.format || model.format);\n const segments = nextParagraph.segments;\n\n isBlock ? segments.unshift(marker) : segments.push(marker);\n setSelection(model, marker, marker);\n }\n }\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  import type { ContentModelDocument, ContentModelListItem } from 'roosterjs-content-model-types';
2
2
  /**
3
- * @internal
3
+ * @param model The content model
4
+ * @param currentItem The current list item
5
+ * Search for all list items in the same thread as the current list item
4
6
  */
5
7
  export declare function findListItemsInSameThread(model: ContentModelDocument, currentItem: ContentModelListItem): ContentModelListItem[];
@@ -3,7 +3,9 @@ define(["require", "exports"], function (require, exports) {
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.findListItemsInSameThread = void 0;
5
5
  /**
6
- * @internal
6
+ * @param model The content model
7
+ * @param currentItem The current list item
8
+ * Search for all list items in the same thread as the current list item
7
9
  */
8
10
  function findListItemsInSameThread(model, currentItem) {
9
11
  var items = [];
@@ -1 +1 @@
1
- {"version":3,"file":"findListItemsInSameThread.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/list/findListItemsInSameThread.ts"],"names":[],"mappings":";;;;IAMA;;OAEG;IACH,SAAgB,yBAAyB,CACrC,KAA2B,EAC3B,WAAiC;QAEjC,IAAM,KAAK,GAAoC,EAAE,CAAC;QA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ContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function findListItemsInSameThread(\n model: ContentModelDocument,\n currentItem: ContentModelListItem\n): ContentModelListItem[] {\n const items: (ContentModelListItem | null)[] = [];\n\n findListItems(model, items);\n\n return filterListItems(items, currentItem);\n}\n\nfunction findListItems(group: ContentModelBlockGroup, result: (ContentModelListItem | null)[]) {\n group.blocks.forEach(block => {\n switch (block.blockType) {\n case 'BlockGroup':\n if (block.blockGroupType == 'ListItem') {\n result.push(block);\n } else {\n pushNullIfNecessary(result);\n findListItems(block, result);\n pushNullIfNecessary(result);\n }\n break;\n\n case 'Paragraph':\n pushNullIfNecessary(result);\n\n block.segments.forEach(segment => {\n if (segment.segmentType == 'General') {\n findListItems(segment, result);\n }\n });\n\n pushNullIfNecessary(result);\n break;\n\n case 'Table':\n pushNullIfNecessary(result);\n\n block.rows.forEach(row =>\n row.cells.forEach(cell => {\n findListItems(cell, result);\n })\n );\n pushNullIfNecessary(result);\n\n break;\n }\n });\n}\n\nfunction pushNullIfNecessary(result: (ContentModelListItem | null)[]) {\n const last = result[result.length - 1];\n\n if (!last || last !== null) {\n result.push(null);\n }\n}\n\nfunction filterListItems(\n items: (ContentModelListItem | null)[],\n currentItem: ContentModelListItem\n) {\n const result: ContentModelListItem[] = [];\n const currentIndex = items.indexOf(currentItem);\n const levelLength = currentItem.levels.length;\n const isOrderedList = currentItem.levels[levelLength - 1]?.listType == 'OL';\n\n if (currentIndex >= 0) {\n for (let i = currentIndex; i >= 0; i--) {\n const item = items[i];\n\n if (!item) {\n if (isOrderedList) {\n continue;\n } else {\n break;\n }\n }\n\n const startNumberOverride = hasStartNumberOverride(item, levelLength);\n\n if (areListTypesCompatible(items, currentIndex, i)) {\n result.unshift(item);\n\n if (isOrderedList && startNumberOverride) {\n break;\n }\n } else if (!isOrderedList || startNumberOverride) {\n break;\n }\n }\n\n for (let i = currentIndex + 1; i < items.length; i++) {\n const item = items[i];\n\n if (!item) {\n if (isOrderedList) {\n continue;\n } else {\n break;\n }\n }\n\n const startNumberOverride = hasStartNumberOverride(item, levelLength);\n\n if (areListTypesCompatible(items, currentIndex, i) && !startNumberOverride) {\n result.push(item);\n } else if (!isOrderedList || startNumberOverride) {\n break;\n }\n }\n }\n\n return result;\n}\n\nfunction areListTypesCompatible(\n listItems: (ContentModelListItem | null)[],\n currentIndex: number,\n compareToIndex: number\n): boolean {\n const currentLevels = listItems[currentIndex]!.levels;\n const compareToLevels = listItems[compareToIndex]!.levels;\n\n return (\n currentLevels.length <= compareToLevels.length &&\n currentLevels.every(\n (currentLevel, i) => currentLevel.listType == compareToLevels[i].listType\n )\n );\n}\n\nfunction hasStartNumberOverride(item: ContentModelListItem, levelLength: number): boolean {\n return item.levels\n .slice(0, levelLength)\n .some(level => level.format.startNumberOverride !== undefined);\n}\n"]}
1
+ {"version":3,"file":"findListItemsInSameThread.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/list/findListItemsInSameThread.ts"],"names":[],"mappings":";;;;IAMA;;;;OAIG;IACH,SAAgB,yBAAyB,CACrC,KAA2B,EAC3B,WAAiC;QAEjC,IAAM,KAAK,GAAoC,EAAE,CAAC;QAElD,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAE5B,OAAO,eAAe,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IATD,8DASC;IAED,SAAS,aAAa,CAAC,KAA6B,EAAE,MAAuC;QACzF,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;YACtB,QAAQ,KAAK,CAAC,SAAS,EAAE;gBACrB,KAAK,YAAY;oBACb,IAAI,KAAK,CAAC,cAAc,IAAI,UAAU,EAAE;wBACpC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;qBACtB;yBAAM;wBACH,mBAAmB,CAAC,MAAM,CAAC,CAAC;wBAC5B,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;wBA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ED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,SAAS,sBAAsB,CAC3B,SAA0C,EAC1C,YAAoB,EACpB,cAAsB;QAEtB,IAAM,aAAa,GAAG,SAAS,CAAC,YAAY,CAAE,CAAC,MAAM,CAAC;QACtD,IAAM,eAAe,GAAG,SAAS,CAAC,cAAc,CAAE,CAAC,MAAM,CAAC;QAE1D,OAAO,CACH,aAAa,CAAC,MAAM,IAAI,eAAe,CAAC,MAAM;YAC9C,aAAa,CAAC,KAAK,CACf,UAAC,YAAY,EAAE,CAAC,IAAK,OAAA,YAAY,CAAC,QAAQ,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,QAAQ,EAApD,CAAoD,CAC5E,CACJ,CAAC;IACN,CAAC;IAED,SAAS,sBAAsB,CAAC,IAA0B,EAAE,WAAmB;QAC3E,OAAO,IAAI,CAAC,MAAM;aACb,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC;aACrB,IAAI,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,MAAM,CAAC,mBAAmB,KAAK,SAAS,EAA9C,CAA8C,CAAC,CAAC;IACvE,CAAC","sourcesContent":["import type {\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * @param model The content model\n * @param currentItem The current list item\n * Search for all list items in the same thread as the current list item\n */\nexport function findListItemsInSameThread(\n model: ContentModelDocument,\n currentItem: ContentModelListItem\n): ContentModelListItem[] {\n const items: (ContentModelListItem | null)[] = [];\n\n findListItems(model, items);\n\n return filterListItems(items, currentItem);\n}\n\nfunction findListItems(group: ContentModelBlockGroup, result: (ContentModelListItem | null)[]) {\n group.blocks.forEach(block => {\n switch (block.blockType) {\n case 'BlockGroup':\n if (block.blockGroupType == 'ListItem') {\n result.push(block);\n } else {\n pushNullIfNecessary(result);\n findListItems(block, result);\n pushNullIfNecessary(result);\n }\n break;\n\n case 'Paragraph':\n pushNullIfNecessary(result);\n\n block.segments.forEach(segment => {\n if (segment.segmentType == 'General') {\n findListItems(segment, result);\n }\n });\n\n pushNullIfNecessary(result);\n break;\n\n case 'Table':\n pushNullIfNecessary(result);\n\n block.rows.forEach(row =>\n row.cells.forEach(cell => {\n findListItems(cell, result);\n })\n );\n pushNullIfNecessary(result);\n\n break;\n }\n });\n}\n\nfunction pushNullIfNecessary(result: (ContentModelListItem | null)[]) {\n const last = result[result.length - 1];\n\n if (!last || last !== null) {\n result.push(null);\n }\n}\n\nfunction filterListItems(\n items: (ContentModelListItem | null)[],\n currentItem: ContentModelListItem\n) {\n const result: ContentModelListItem[] = [];\n const currentIndex = items.indexOf(currentItem);\n const levelLength = currentItem.levels.length;\n const isOrderedList = currentItem.levels[levelLength - 1]?.listType == 'OL';\n\n if (currentIndex >= 0) {\n for (let i = currentIndex; i >= 0; i--) {\n const item = items[i];\n\n if (!item) {\n if (isOrderedList) {\n continue;\n } else {\n break;\n }\n }\n\n const startNumberOverride = hasStartNumberOverride(item, levelLength);\n\n if (areListTypesCompatible(items, currentIndex, i)) {\n result.unshift(item);\n\n if (isOrderedList && startNumberOverride) {\n break;\n }\n } else if (!isOrderedList || startNumberOverride) {\n break;\n }\n }\n\n for (let i = currentIndex + 1; i < items.length; i++) {\n const item = items[i];\n\n if (!item) {\n if (isOrderedList) {\n continue;\n } else {\n break;\n }\n }\n\n const startNumberOverride = hasStartNumberOverride(item, levelLength);\n\n if (areListTypesCompatible(items, currentIndex, i) && !startNumberOverride) {\n result.push(item);\n } else if (!isOrderedList || startNumberOverride) {\n break;\n }\n }\n }\n\n return result;\n}\n\nfunction areListTypesCompatible(\n listItems: (ContentModelListItem | null)[],\n currentIndex: number,\n compareToIndex: number\n): boolean {\n const currentLevels = listItems[currentIndex]!.levels;\n const compareToLevels = listItems[compareToIndex]!.levels;\n\n return (\n currentLevels.length <= compareToLevels.length &&\n currentLevels.every(\n (currentLevel, i) => currentLevel.listType == compareToLevels[i].listType\n )\n );\n}\n\nfunction hasStartNumberOverride(item: ContentModelListItem, levelLength: number): boolean {\n return item.levels\n .slice(0, levelLength)\n .some(level => level.format.startNumberOverride !== undefined);\n}\n"]}
@@ -72,7 +72,7 @@ define(["require", "exports", "roosterjs-content-model-core", "roosterjs-content
72
72
  textColor: segmentFormat.textColor,
73
73
  });
74
74
  if (block.blockType == 'Paragraph') {
75
- block.isImplicit = true;
75
+ (0, roosterjs_content_model_dom_1.setParagraphNotImplicit)(block);
76
76
  }
77
77
  newListItem.blocks.push(block);
78
78
  if (block.format.marginRight) {
@@ -1 +1 @@
1
- {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;;IAaA;;;;OAIG;IACH,SAAgB,WAAW,CAAC,KAA2B,EAAE,QAAqB;QAC1E,IAAM,oBAAoB,GAAG,IAAA,mDAAoB,EAC7C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,EAAE,CAAC,8IAA8I;SACpJ,CAAC;QACF,IAAM,qBAAqB,GAAG,oBAAoB,CAAC,KAAK,CAAC,UAAC,EAAS;;gBAAP,KAAK,WAAA;YAC7D,OAAA,IAAA,iDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC;gBACvD,CAAC,CAAC,CAAA,MAAA,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,QAAQ,KAAI,QAAQ;gBAC7D,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA;SAAA,CACjC,CAAC;QACF,IAAI,iBAAiB,GAA2B,EAAE,CAAC;QAEnD,oBAAoB,CAAC,OAAO,CAAC,UAAC,EAAiB,EAAE,SAAS;;gBAA1B,KAAK,WAAA,EAAE,MAAM,YAAA;YACzC,IAAI,IAAA,iDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;gBAC7D,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;gBAEjC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AAC;4BACxD,KAAK,CAAC,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC;yBACvC;wBAED,IAAI,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE;4BACxB,WAAW,CAAC,MAAM,CAAC,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC;yBACzD;wBAED,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;wBAC5C,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;qBACvC;yBAAM;wBACH,iBAAiB,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAzC,CAAyC,CAAC,CAAC;wBAC1E,iBAAiB,GAAG,EAAE,CAAC;qBAC1B;iBACJ;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;QAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3C,CAAC;IAxGD,kCAwGC;IAED,SAAS,iBAAiB,CAAC,KAAwB;QAC/C,QAAQ,KAAK,CAAC,SAAS,EAAE;YACrB,KAAK,OAAO;gBACR,OAAO,KAAK,CAAC;YACjB,KAAK,WAAW;gBACZ,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CACvB,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,WAAW,IAAI,IAAI,IAAI,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAA3D,CAA2D,CACnE,CAAC;YACN;gBACI,OAAO,IAAI,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';\nimport {\n createListItem,\n createListLevel,\n normalizeContentModel,\n setParagraphNotImplicit,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelDocument,\n ContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n */\nexport function setListType(model: ContentModelDocument, listType: 'OL' | 'UL') {\n const paragraphOrListItems = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n [] // Set stop types to be empty so we can find list items even cross the boundary of table, then we can always operation on the list item if any\n );\n const alreadyInExpectedType = paragraphOrListItems.every(({ block }) =>\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const level = block.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n block.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n //if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n if (block.format.marginLeft) {\n x.format.marginLeft = block.format.marginLeft;\n }\n\n if (block.format.marginRight) {\n x.format.marginRight = block.format.marginRight;\n }\n\n if (block.format.textAlign) {\n x.format.textAlign = block.format.textAlign;\n }\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n\n if (index >= 0) {\n if (paragraphOrListItems.length == 1 || !shouldIgnoreBlock(block)) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginTop: '0px',\n marginBottom: '0px',\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (block.blockType == 'Paragraph') {\n block.isImplicit = true;\n }\n\n newListItem.blocks.push(block);\n\n if (block.format.marginRight) {\n newListItem.format.marginRight = block.format.marginRight;\n block.format.marginRight = undefined;\n }\n if (block.format.marginLeft) {\n newListItem.format.marginLeft = block.format.marginLeft;\n block.format.marginLeft = undefined;\n }\n\n if (block.format.textAlign) {\n newListItem.format.textAlign = block.format.textAlign;\n }\n\n parent.blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n } else {\n existingListItems.forEach(x => (x.levels[0].format.marginBottom = '0px'));\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;;IAaA;;;;OAIG;IACH,SAAgB,WAAW,CAAC,KAA2B,EAAE,QAAqB;QAC1E,IAAM,oBAAoB,GAAG,IAAA,mDAAoB,EAC7C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,EAAE,CAAC,8IAA8I;SACpJ,CAAC;QACF,IAAM,qBAAqB,GAAG,oBAAoB,CAAC,KAAK,CAAC,UAAC,EAAS;;gBAAP,KAAK,WAAA;YAC7D,OAAA,IAAA,iDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC;gBACvD,CAAC,CAAC,CAAA,MAAA,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,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;gBACZ,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CACvB,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,WAAW,IAAI,IAAI,IAAI,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAA3D,CAA2D,CACnE,CAAC;YACN;gBACI,OAAO,IAAI,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';\nimport {\n createListItem,\n createListLevel,\n normalizeContentModel,\n setParagraphNotImplicit,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelDocument,\n ContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Set a list type to content model\n * @param model the model document\n * @param listType the list type OL | UL\n */\nexport function setListType(model: ContentModelDocument, listType: 'OL' | 'UL') {\n const paragraphOrListItems = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n [] // Set stop types to be empty so we can find list items even cross the boundary of table, then we can always operation on the list item if any\n );\n const alreadyInExpectedType = paragraphOrListItems.every(({ block }) =>\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const level = block.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n block.levels.push(level);\n } else if (block.blocks.length == 1) {\n setParagraphNotImplicit(block.blocks[0]);\n }\n\n if (alreadyInExpectedType) {\n //if the list item has margins or textAlign, we need to apply them to the block to preserve the indention and alignment\n block.blocks.forEach(x => {\n if (block.format.marginLeft) {\n x.format.marginLeft = block.format.marginLeft;\n }\n\n if (block.format.marginRight) {\n x.format.marginRight = block.format.marginRight;\n }\n\n if (block.format.textAlign) {\n x.format.textAlign = block.format.textAlign;\n }\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n\n if (index >= 0) {\n if (paragraphOrListItems.length == 1 || !shouldIgnoreBlock(block)) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n itemIndex > 0 ||\n (prevBlock?.blockType == 'BlockGroup' &&\n prevBlock.blockGroupType == 'ListItem' &&\n prevBlock.levels[0]?.listType == 'OL')\n ? undefined\n : 1,\n direction: block.format.direction,\n textAlign: block.format.textAlign,\n marginTop: '0px',\n marginBottom: '0px',\n }),\n ],\n // For list bullet, we only want to carry over these formats from segments:\n {\n fontFamily: segmentFormat.fontFamily,\n fontSize: segmentFormat.fontSize,\n textColor: segmentFormat.textColor,\n }\n );\n\n if (block.blockType == 'Paragraph') {\n setParagraphNotImplicit(block);\n }\n\n newListItem.blocks.push(block);\n\n if (block.format.marginRight) {\n newListItem.format.marginRight = block.format.marginRight;\n block.format.marginRight = undefined;\n }\n if (block.format.marginLeft) {\n newListItem.format.marginLeft = block.format.marginLeft;\n block.format.marginLeft = undefined;\n }\n\n if (block.format.textAlign) {\n newListItem.format.textAlign = block.format.textAlign;\n }\n\n parent.blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n } else {\n existingListItems.forEach(x => (x.levels[0].format.marginBottom = '0px'));\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ContentModelBlock) {\n switch (block.blockType) {\n case 'Table':\n return false;\n case 'Paragraph':\n return block.segments.every(\n x => x.segmentType == 'Br' || x.segmentType == 'SelectionMarker'\n );\n default:\n return true;\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { ContentModelTable, TableSelectionCoordinates } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Clear selection of a table.
4
+ * @internal
5
+ * @param table The table model where the selection is to be cleared
6
+ * @param sel The selection coordinates to be cleared
7
+ */
8
+ export declare function clearSelectedCells(table: ContentModelTable, sel: TableSelectionCoordinates): void;
@@ -0,0 +1,28 @@
1
+ define(["require", "exports", "roosterjs-content-model-core"], function (require, exports, roosterjs_content_model_core_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.clearSelectedCells = void 0;
5
+ /**
6
+ * Clear selection of a table.
7
+ * @internal
8
+ * @param table The table model where the selection is to be cleared
9
+ * @param sel The selection coordinates to be cleared
10
+ */
11
+ function clearSelectedCells(table, sel) {
12
+ if (sel.firstColumn >= 0 &&
13
+ sel.firstRow >= 0 &&
14
+ sel.lastColumn < table.widths.length &&
15
+ sel.lastRow < table.rows.length) {
16
+ for (var i = sel.firstRow; i <= sel.lastRow; i++) {
17
+ var row = table.rows[i];
18
+ for (var j = sel.firstColumn; j <= sel.lastColumn; j++) {
19
+ var cell = row.cells[j];
20
+ cell.isSelected = false;
21
+ (0, roosterjs_content_model_core_1.setSelection)(cell);
22
+ }
23
+ }
24
+ }
25
+ }
26
+ exports.clearSelectedCells = clearSelectedCells;
27
+ });
28
+ //# sourceMappingURL=clearSelectedCells.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clearSelectedCells.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/table/clearSelectedCells.ts"],"names":[],"mappings":";;;;IAGA;;;;;OAKG;IACH,SAAgB,kBAAkB,CAAC,KAAwB,EAAE,GAA8B;QACvF,IACI,GAAG,CAAC,WAAW,IAAI,CAAC;YACpB,GAAG,CAAC,QAAQ,IAAI,CAAC;YACjB,GAAG,CAAC,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM;YACpC,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EACjC;YACE,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE;gBAC9C,IAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAC1B,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE;oBACpD,IAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBAC1B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;oBACxB,IAAA,2CAAY,EAAC,IAAI,CAAC,CAAC;iBACtB;aACJ;SACJ;IACL,CAAC;IAhBD,gDAgBC","sourcesContent":["import { setSelection } from 'roosterjs-content-model-core';\nimport type { ContentModelTable, TableSelectionCoordinates } from 'roosterjs-content-model-types';\n\n/**\n * Clear selection of a table.\n * @internal\n * @param table The table model where the selection is to be cleared\n * @param sel The selection coordinates to be cleared\n */\nexport function clearSelectedCells(table: ContentModelTable, sel: TableSelectionCoordinates) {\n if (\n sel.firstColumn >= 0 &&\n sel.firstRow >= 0 &&\n sel.lastColumn < table.widths.length &&\n sel.lastRow < table.rows.length\n ) {\n for (let i = sel.firstRow; i <= sel.lastRow; i++) {\n const row = table.rows[i];\n for (let j = sel.firstColumn; j <= sel.lastColumn; j++) {\n const cell = row.cells[j];\n cell.isSelected = false;\n setSelection(cell);\n }\n }\n }\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  import type { ContentModelTable, TableHorizontalInsertOperation } from 'roosterjs-content-model-types';
2
2
  /**
3
- * @internal
3
+ * Insert a column to the table
4
+ * @param table The table model where the column is to be inserted
5
+ * @param operation The operation to be performed
4
6
  */
5
7
  export declare function insertTableColumn(table: ContentModelTable, operation: TableHorizontalInsertOperation): void;
@@ -1,18 +1,23 @@
1
- define(["require", "exports", "roosterjs-content-model-dom", "roosterjs-content-model-core"], function (require, exports, roosterjs_content_model_dom_1, roosterjs_content_model_core_1) {
1
+ define(["require", "exports", "./clearSelectedCells", "roosterjs-content-model-dom", "roosterjs-content-model-core"], function (require, exports, clearSelectedCells_1, roosterjs_content_model_dom_1, roosterjs_content_model_core_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.insertTableColumn = void 0;
5
5
  /**
6
- * @internal
6
+ * Insert a column to the table
7
+ * @param table The table model where the column is to be inserted
8
+ * @param operation The operation to be performed
7
9
  */
8
10
  function insertTableColumn(table, operation) {
9
11
  var sel = (0, roosterjs_content_model_core_1.getSelectedCells)(table);
10
12
  var insertLeft = operation == 'insertLeft';
11
13
  if (sel) {
14
+ (0, clearSelectedCells_1.clearSelectedCells)(table, sel);
12
15
  for (var i = sel === null || sel === void 0 ? void 0 : sel.firstColumn; i <= sel.lastColumn; i++) {
13
16
  table.rows.forEach(function (row) {
14
17
  var cell = row.cells[insertLeft ? sel.firstColumn : sel.lastColumn];
15
- row.cells.splice(insertLeft ? sel.firstColumn : sel.lastColumn + 1, 0, (0, roosterjs_content_model_dom_1.createTableCell)(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format, cell.dataset));
18
+ var newCell = (0, roosterjs_content_model_dom_1.createTableCell)(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format, cell.dataset);
19
+ newCell.isSelected = true;
20
+ row.cells.splice(insertLeft ? sel.firstColumn : sel.lastColumn + 1, 0, newCell);
16
21
  });
17
22
  table.widths.splice(insertLeft ? sel.firstColumn : sel.lastColumn + 1, 0, table.widths[insertLeft ? sel.firstColumn : sel.lastColumn]);
18
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"insertTableColumn.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/table/insertTableColumn.ts"],"names":[],"mappings":";;;;IAOA;;OAEG;IACH,SAAgB,iBAAiB,CAC7B,KAAwB,EACxB,SAAyC;QAEzC,IAAM,GAAG,GAAG,IAAA,+CAAgB,EAAC,KAAK,CAAC,CAAC;QACpC,IAAM,UAAU,GAAG,SAAS,IAAI,YAAY,CAAC;QAE7C,IAAI,GAAG,EAAE;YACL,KAAK,IAAI,CAAC,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,EAAE,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE;gBACrD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;oBAClB,IAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;oBAEtE,GAAG,CAAC,KAAK,CAAC,MAAM,CACZ,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,EACjD,CAAC,EACD,IAAA,6CAAe,EACX,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,CACf,CACJ,CAAC;gBACN,CAAC,CAAC,CAAC;gBACH,KAAK,CAAC,MAAM,CAAC,MAAM,CACf,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,EACjD,CAAC,EACD,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAC9D,CAAC;aACL;SACJ;IACL,CAAC;IA/BD,8CA+BC","sourcesContent":["import { createTableCell } from 'roosterjs-content-model-dom';\nimport { getSelectedCells } from 'roosterjs-content-model-core';\nimport type {\n ContentModelTable,\n TableHorizontalInsertOperation,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function insertTableColumn(\n table: ContentModelTable,\n operation: TableHorizontalInsertOperation\n) {\n const sel = getSelectedCells(table);\n const insertLeft = operation == 'insertLeft';\n\n if (sel) {\n for (let i = sel?.firstColumn; i <= sel.lastColumn; i++) {\n table.rows.forEach(row => {\n const cell = row.cells[insertLeft ? sel.firstColumn : sel.lastColumn];\n\n row.cells.splice(\n insertLeft ? sel.firstColumn : sel.lastColumn + 1,\n 0,\n createTableCell(\n cell.spanLeft,\n cell.spanAbove,\n cell.isHeader,\n cell.format,\n cell.dataset\n )\n );\n });\n table.widths.splice(\n insertLeft ? sel.firstColumn : sel.lastColumn + 1,\n 0,\n table.widths[insertLeft ? sel.firstColumn : sel.lastColumn]\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"insertTableColumn.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/table/insertTableColumn.ts"],"names":[],"mappings":";;;;IAQA;;;;OAIG;IACH,SAAgB,iBAAiB,CAC7B,KAAwB,EACxB,SAAyC;QAEzC,IAAM,GAAG,GAAG,IAAA,+CAAgB,EAAC,KAAK,CAAC,CAAC;QACpC,IAAM,UAAU,GAAG,SAAS,IAAI,YAAY,CAAC;QAE7C,IAAI,GAAG,EAAE;YACL,IAAA,uCAAkB,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YAC/B,KAAK,IAAI,CAAC,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,EAAE,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE;gBACrD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;oBAClB,IAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;oBAEtE,IAAM,OAAO,GAAG,IAAA,6CAAe,EAC3B,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,CACf,CAAC;oBACF,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;oBAE1B,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;gBACpF,CAAC,CAAC,CAAC;gBACH,KAAK,CAAC,MAAM,CAAC,MAAM,CACf,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,EACjD,CAAC,EACD,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAC9D,CAAC;aACL;SACJ;IACL,CAAC;IA/BD,8CA+BC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { createTableCell } from 'roosterjs-content-model-dom';\nimport { getSelectedCells } from 'roosterjs-content-model-core';\nimport type {\n ContentModelTable,\n TableHorizontalInsertOperation,\n} from 'roosterjs-content-model-types';\n\n/**\n * Insert a column to the table\n * @param table The table model where the column is to be inserted\n * @param operation The operation to be performed\n */\nexport function insertTableColumn(\n table: ContentModelTable,\n operation: TableHorizontalInsertOperation\n) {\n const sel = getSelectedCells(table);\n const insertLeft = operation == 'insertLeft';\n\n if (sel) {\n clearSelectedCells(table, sel);\n for (let i = sel?.firstColumn; i <= sel.lastColumn; i++) {\n table.rows.forEach(row => {\n const cell = row.cells[insertLeft ? sel.firstColumn : sel.lastColumn];\n\n const newCell = createTableCell(\n cell.spanLeft,\n cell.spanAbove,\n cell.isHeader,\n cell.format,\n cell.dataset\n );\n newCell.isSelected = true;\n\n row.cells.splice(insertLeft ? sel.firstColumn : sel.lastColumn + 1, 0, newCell);\n });\n table.widths.splice(\n insertLeft ? sel.firstColumn : sel.lastColumn + 1,\n 0,\n table.widths[insertLeft ? sel.firstColumn : sel.lastColumn]\n );\n }\n }\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  import type { ContentModelTable, TableVerticalInsertOperation } from 'roosterjs-content-model-types';
2
2
  /**
3
- * @internal
3
+ * Insert a row to the table
4
+ * @param table The table model where the row is to be inserted
5
+ * @param operation The operation to be performed
4
6
  */
5
7
  export declare function insertTableRow(table: ContentModelTable, operation: TableVerticalInsertOperation): void;
@@ -1,20 +1,25 @@
1
- define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs-content-model-core"], function (require, exports, tslib_1, roosterjs_content_model_dom_1, roosterjs_content_model_core_1) {
1
+ define(["require", "exports", "tslib", "./clearSelectedCells", "roosterjs-content-model-dom", "roosterjs-content-model-core"], function (require, exports, tslib_1, clearSelectedCells_1, roosterjs_content_model_dom_1, roosterjs_content_model_core_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.insertTableRow = void 0;
5
5
  /**
6
- * @internal
6
+ * Insert a row to the table
7
+ * @param table The table model where the row is to be inserted
8
+ * @param operation The operation to be performed
7
9
  */
8
10
  function insertTableRow(table, operation) {
9
11
  var sel = (0, roosterjs_content_model_core_1.getSelectedCells)(table);
10
12
  var insertAbove = operation == 'insertAbove';
11
13
  if (sel) {
14
+ (0, clearSelectedCells_1.clearSelectedCells)(table, sel);
12
15
  for (var i = sel.firstRow; i <= sel.lastRow; i++) {
13
16
  var sourceRow = table.rows[insertAbove ? sel.firstRow : sel.lastRow];
14
17
  table.rows.splice(insertAbove ? sel.firstRow : sel.lastRow + 1, 0, {
15
18
  format: (0, tslib_1.__assign)({}, sourceRow.format),
16
19
  cells: sourceRow.cells.map(function (cell) {
17
- return (0, roosterjs_content_model_dom_1.createTableCell)(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format, cell.dataset);
20
+ var newCell = (0, roosterjs_content_model_dom_1.createTableCell)(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format, cell.dataset);
21
+ newCell.isSelected = true;
22
+ return newCell;
18
23
  }),
19
24
  height: sourceRow.height,
20
25
  });
@@ -1 +1 @@
1
- {"version":3,"file":"insertTableRow.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/table/insertTableRow.ts"],"names":[],"mappings":";;;;IAOA;;OAEG;IACH,SAAgB,cAAc,CAAC,KAAwB,EAAE,SAAuC;QAC5F,IAAM,GAAG,GAAG,IAAA,+CAAgB,EAAC,KAAK,CAAC,CAAC;QACpC,IAAM,WAAW,GAAG,SAAS,IAAI,aAAa,CAAC;QAE/C,IAAI,GAAG,EAAE;YACL,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE;gBAC9C,IAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAEvE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC,EAAE;oBAC/D,MAAM,4BAAO,SAAS,CAAC,MAAM,CAAE;oBAC/B,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI;wBAC3B,OAAA,IAAA,6CAAe,EACX,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,CACf;oBAND,CAMC,CACJ;oBACD,MAAM,EAAE,SAAS,CAAC,MAAM;iBAC3B,CAAC,CAAC;aACN;SACJ;IACL,CAAC;IAvBD,wCAuBC","sourcesContent":["import { createTableCell } from 'roosterjs-content-model-dom';\nimport { getSelectedCells } from 'roosterjs-content-model-core';\nimport type {\n ContentModelTable,\n TableVerticalInsertOperation,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function insertTableRow(table: ContentModelTable, operation: TableVerticalInsertOperation) {\n const sel = getSelectedCells(table);\n const insertAbove = operation == 'insertAbove';\n\n if (sel) {\n for (let i = sel.firstRow; i <= sel.lastRow; i++) {\n const sourceRow = table.rows[insertAbove ? sel.firstRow : sel.lastRow];\n\n table.rows.splice(insertAbove ? sel.firstRow : sel.lastRow + 1, 0, {\n format: { ...sourceRow.format },\n cells: sourceRow.cells.map(cell =>\n createTableCell(\n cell.spanLeft,\n cell.spanAbove,\n cell.isHeader,\n cell.format,\n cell.dataset\n )\n ),\n height: sourceRow.height,\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"insertTableRow.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/table/insertTableRow.ts"],"names":[],"mappings":";;;;IAQA;;;;OAIG;IACH,SAAgB,cAAc,CAAC,KAAwB,EAAE,SAAuC;QAC5F,IAAM,GAAG,GAAG,IAAA,+CAAgB,EAAC,KAAK,CAAC,CAAC;QACpC,IAAM,WAAW,GAAG,SAAS,IAAI,aAAa,CAAC;QAE/C,IAAI,GAAG,EAAE;YACL,IAAA,uCAAkB,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YAC/B,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE;gBAC9C,IAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAEvE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC,EAAE;oBAC/D,MAAM,4BAAO,SAAS,CAAC,MAAM,CAAE;oBAC/B,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI;wBAC3B,IAAM,OAAO,GAAG,IAAA,6CAAe,EAC3B,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,CACf,CAAC;wBACF,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;wBAC1B,OAAO,OAAO,CAAC;oBACnB,CAAC,CAAC;oBACF,MAAM,EAAE,SAAS,CAAC,MAAM;iBAC3B,CAAC,CAAC;aACN;SACJ;IACL,CAAC;IA1BD,wCA0BC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { createTableCell } from 'roosterjs-content-model-dom';\nimport { getSelectedCells } from 'roosterjs-content-model-core';\nimport type {\n ContentModelTable,\n TableVerticalInsertOperation,\n} from 'roosterjs-content-model-types';\n\n/**\n * Insert a row to the table\n * @param table The table model where the row is to be inserted\n * @param operation The operation to be performed\n */\nexport function insertTableRow(table: ContentModelTable, operation: TableVerticalInsertOperation) {\n const sel = getSelectedCells(table);\n const insertAbove = operation == 'insertAbove';\n\n if (sel) {\n clearSelectedCells(table, sel);\n for (let i = sel.firstRow; i <= sel.lastRow; i++) {\n const sourceRow = table.rows[insertAbove ? sel.firstRow : sel.lastRow];\n\n table.rows.splice(insertAbove ? sel.firstRow : sel.lastRow + 1, 0, {\n format: { ...sourceRow.format },\n cells: sourceRow.cells.map(cell => {\n const newCell = createTableCell(\n cell.spanLeft,\n cell.spanAbove,\n cell.isHeader,\n cell.format,\n cell.dataset\n );\n newCell.isSelected = true;\n return newCell;\n }),\n height: sourceRow.height,\n });\n }\n }\n}\n"]}
@@ -5,13 +5,18 @@ define(["require", "exports", "roosterjs-content-model-core", "roosterjs-content
5
5
  var InlineEntityTag = 'span';
6
6
  function insertEntity(editor, type, isBlock, position, options) {
7
7
  var _a = options || {}, contentNode = _a.contentNode, focusAfterEntity = _a.focusAfterEntity, wrapperDisplay = _a.wrapperDisplay, skipUndoSnapshot = _a.skipUndoSnapshot;
8
- var wrapper = editor.getDocument().createElement(isBlock ? BlockEntityTag : InlineEntityTag);
8
+ var document = editor.getDocument();
9
+ var wrapper = document.createElement(isBlock ? BlockEntityTag : InlineEntityTag);
9
10
  var display = wrapperDisplay !== null && wrapperDisplay !== void 0 ? wrapperDisplay : (isBlock ? undefined : 'inline-block');
10
11
  wrapper.style.setProperty('display', display || null);
12
+ if (display == undefined && isBlock) {
13
+ wrapper.style.setProperty('width', '100%');
14
+ wrapper.style.setProperty('display', 'inline-block');
15
+ }
11
16
  if (contentNode) {
12
17
  wrapper.appendChild(contentNode);
13
18
  }
14
- var entityModel = (0, roosterjs_content_model_dom_1.createEntity)(wrapper, true /*isReadonly*/, undefined /*format*/, type);
19
+ var entityModel = (0, roosterjs_content_model_dom_1.createEntity)(wrapper, true /* isReadonly */, undefined /*format*/, type);
15
20
  editor.formatContentModel(function (model, context) {
16
21
  (0, insertEntityModel_1.insertEntityModel)(model, entityModel, typeof position == 'string' ? position : 'focus', isBlock, focusAfterEntity, context);
17
22
  (0, roosterjs_content_model_dom_1.normalizeContentModel)(model);