roosterjs-content-model-api 9.45.1 → 9.45.2

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 (28) hide show
  1. package/lib/modelApi/list/setListType.js +6 -2
  2. package/lib/modelApi/list/setListType.js.map +1 -1
  3. package/lib/modelApi/table/copyPreviousCellSegmentFormat.d.ts +5 -0
  4. package/lib/modelApi/table/copyPreviousCellSegmentFormat.js +24 -0
  5. package/lib/modelApi/table/copyPreviousCellSegmentFormat.js.map +1 -0
  6. package/lib/modelApi/table/insertTableColumn.js +2 -0
  7. package/lib/modelApi/table/insertTableColumn.js.map +1 -1
  8. package/lib/modelApi/table/insertTableRow.js +2 -0
  9. package/lib/modelApi/table/insertTableRow.js.map +1 -1
  10. package/lib-amd/modelApi/list/setListType.js +6 -2
  11. package/lib-amd/modelApi/list/setListType.js.map +1 -1
  12. package/lib-amd/modelApi/table/copyPreviousCellSegmentFormat.d.ts +5 -0
  13. package/lib-amd/modelApi/table/copyPreviousCellSegmentFormat.js +25 -0
  14. package/lib-amd/modelApi/table/copyPreviousCellSegmentFormat.js.map +1 -0
  15. package/lib-amd/modelApi/table/insertTableColumn.js +2 -1
  16. package/lib-amd/modelApi/table/insertTableColumn.js.map +1 -1
  17. package/lib-amd/modelApi/table/insertTableRow.js +2 -1
  18. package/lib-amd/modelApi/table/insertTableRow.js.map +1 -1
  19. package/lib-mjs/modelApi/list/setListType.js +6 -2
  20. package/lib-mjs/modelApi/list/setListType.js.map +1 -1
  21. package/lib-mjs/modelApi/table/copyPreviousCellSegmentFormat.d.ts +5 -0
  22. package/lib-mjs/modelApi/table/copyPreviousCellSegmentFormat.js +20 -0
  23. package/lib-mjs/modelApi/table/copyPreviousCellSegmentFormat.js.map +1 -0
  24. package/lib-mjs/modelApi/table/insertTableColumn.js +2 -0
  25. package/lib-mjs/modelApi/table/insertTableColumn.js.map +1 -1
  26. package/lib-mjs/modelApi/table/insertTableRow.js +2 -0
  27. package/lib-mjs/modelApi/table/insertTableRow.js.map +1 -1
  28. package/package.json +4 -4
@@ -50,13 +50,17 @@ function setListType(model, listType, removeMargins) {
50
50
  }
51
51
  else {
52
52
  var index = parent.blocks.indexOf(block);
53
+ var isInsideTableCell = parent.blockGroupType == 'TableCell';
53
54
  if (index >= 0) {
54
- if (paragraphOrListItems.length == 1 || !shouldIgnoreBlock(block)) {
55
+ if (paragraphOrListItems.length == 1 ||
56
+ !shouldIgnoreBlock(block) ||
57
+ isInsideTableCell) {
55
58
  var prevBlock = parent.blocks[index - 1];
56
59
  var segmentFormat = (block.blockType == 'Paragraph' && ((_b = block.segments[0]) === null || _b === void 0 ? void 0 : _b.format)) || {};
57
60
  var newListItem = (0, roosterjs_content_model_dom_1.createListItem)([
58
61
  (0, roosterjs_content_model_dom_1.createListLevel)(listType, {
59
- startNumberOverride: itemIndex > 0 ||
62
+ startNumberOverride: isInsideTableCell ||
63
+ itemIndex > 0 ||
60
64
  ((prevBlock === null || prevBlock === void 0 ? void 0 : prevBlock.blockType) == 'BlockGroup' &&
61
65
  prevBlock.blockGroupType == 'ListItem' &&
62
66
  ((_c = prevBlock.levels[0]) === null || _c === void 0 ? void 0 : _c.listType) == 'OL')
@@ -1 +1 @@
1
- {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;AAAA,iEAAoE;AACpE,kFAAiF;AACjF,2EAaqC;AASrC;;;;;GAKG;AACH,SAAgB,WAAW,CACvB,KAAmC,EACnC,QAAqB,EACrB,aAA8B;IAA9B,8BAAA,EAAA,qBAA8B;IAE9B,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;IAElC,IAAM,oBAAoB,GAAG,IAAA,kDAAoB,EAC7C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,EAAE,CAAC,8IAA8I;KACpJ,CAAC;IACF,IAAM,qBAAqB,GAAG,oBAAoB,CAAC,KAAK,CAAC,UAAC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AAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAtD,CAAsD,CAC9D,CAAC;oBACF,iBAAiB,GAAG,EAAE,CAAC;iBAC1B;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AA5HD,kCA4HC;AAED,SAAS,iBAAiB,CAAC,KAAgC;IACvD,QAAQ,KAAK,CAAC,SAAS,EAAE;QACrB,KAAK,OAAO;YACR,OAAO,KAAK,CAAC;QACjB,KAAK,WAAW;YACZ,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;QACN;YACI,OAAO,IAAI,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\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 * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.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 copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\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: ShallowMutableContentModelListItem = 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 marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\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 const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\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/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;AAAA,iEAAoE;AACpE,kFAAiF;AACjF,2EAaqC;AASrC;;;;;GAKG;AACH,SAAgB,WAAW,CACvB,KAAmC,EACnC,QAAqB,EACrB,aAA8B;IAA9B,8BAAA,EAAA,qBAA8B;IAE9B,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;IAElC,IAAM,oBAAoB,GAAG,IAAA,kDAAoB,EAC7C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,EAAE,CAAC,8IAA8I;KACpJ,CAAC;IACF,I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ChC,CAAC;wBAFF,CAEE,CACL,CAAC;qBACL;iBACJ;qBAAM;oBACH,iBAAiB,CAAC,OAAO,CACrB,UAAA,CAAC,IAAI,OAAA,CAAC,IAAA,yCAAW,EAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAtD,CAAsD,CAC9D,CAAC;oBACF,iBAAiB,GAAG,EAAE,CAAC;iBAC1B;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AAlID,kCAkIC;AAED,SAAS,iBAAiB,CAAC,KAAgC;IACvD,QAAQ,KAAK,CAAC,SAAS,EAAE;QACrB,KAAK,OAAO;YACR,OAAO,KAAK,CAAC;QACjB,KAAK,WAAW;YACZ,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;QACN;YACI,OAAO,IAAI,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\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 * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.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 copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n const isInsideTableCell = parent.blockGroupType == 'TableCell';\n\n if (index >= 0) {\n if (\n paragraphOrListItems.length == 1 ||\n !shouldIgnoreBlock(block) ||\n isInsideTableCell\n ) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n isInsideTableCell ||\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 marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\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 const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\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,5 @@
1
+ import type { ReadonlyContentModelTableCell } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function copyPreviousCellSegmentFormat(cell: ReadonlyContentModelTableCell, newCell: ReadonlyContentModelTableCell): void;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.copyPreviousCellSegmentFormat = void 0;
4
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
5
+ /**
6
+ * @internal
7
+ */
8
+ function copyPreviousCellSegmentFormat(cell, newCell) {
9
+ var block = cell.blocks[0];
10
+ if (block && (block === null || block === void 0 ? void 0 : block.blockType) == 'Paragraph') {
11
+ var firstSegment = block.segments[0];
12
+ if (firstSegment &&
13
+ (firstSegment.segmentType == 'Text' ||
14
+ firstSegment.segmentType == 'Br' ||
15
+ firstSegment.segmentType == 'SelectionMarker')) {
16
+ var newCellParagraph = (0, roosterjs_content_model_dom_1.createParagraph)(false /* isImplicit */, block.format, block.segmentFormat);
17
+ var br = (0, roosterjs_content_model_dom_1.createBr)(firstSegment.format);
18
+ newCellParagraph.segments.push(br);
19
+ (0, roosterjs_content_model_dom_1.mutateBlock)(newCell).blocks.push(newCellParagraph);
20
+ }
21
+ }
22
+ }
23
+ exports.copyPreviousCellSegmentFormat = copyPreviousCellSegmentFormat;
24
+ //# sourceMappingURL=copyPreviousCellSegmentFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copyPreviousCellSegmentFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/copyPreviousCellSegmentFormat.ts"],"names":[],"mappings":";;;AAAA,2EAAqF;AAGrF;;GAEG;AACH,SAAgB,6BAA6B,CACzC,IAAmC,EACnC,OAAsC;IAEtC,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,KAAK,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,WAAW,EAAE;QAC1C,IAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACvC,IACI,YAAY;YACZ,CAAC,YAAY,CAAC,WAAW,IAAI,MAAM;gBAC/B,YAAY,CAAC,WAAW,IAAI,IAAI;gBAChC,YAAY,CAAC,WAAW,IAAI,iBAAiB,CAAC,EACpD;YACE,IAAM,gBAAgB,GAAG,IAAA,6CAAe,EACpC,KAAK,CAAC,gBAAgB,EACtB,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,aAAa,CACtB,CAAC;YACF,IAAM,EAAE,GAAG,IAAA,sCAAQ,EAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YACzC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACnC,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;SACtD;KACJ;AACL,CAAC;AAvBD,sEAuBC","sourcesContent":["import { createBr, createParagraph, mutateBlock } from 'roosterjs-content-model-dom';\nimport type { ReadonlyContentModelTableCell } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function copyPreviousCellSegmentFormat(\n cell: ReadonlyContentModelTableCell,\n newCell: ReadonlyContentModelTableCell\n) {\n const block = cell.blocks[0];\n if (block && block?.blockType == 'Paragraph') {\n const firstSegment = block.segments[0];\n if (\n firstSegment &&\n (firstSegment.segmentType == 'Text' ||\n firstSegment.segmentType == 'Br' ||\n firstSegment.segmentType == 'SelectionMarker')\n ) {\n const newCellParagraph = createParagraph(\n false /* isImplicit */,\n block.format,\n block.segmentFormat\n );\n const br = createBr(firstSegment.format);\n newCellParagraph.segments.push(br);\n mutateBlock(newCell).blocks.push(newCellParagraph);\n }\n }\n}\n"]}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.insertTableColumn = void 0;
4
4
  var clearSelectedCells_1 = require("./clearSelectedCells");
5
+ var copyPreviousCellSegmentFormat_1 = require("./copyPreviousCellSegmentFormat");
5
6
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
7
  /**
7
8
  * Insert a column to the table
@@ -17,6 +18,7 @@ function insertTableColumn(table, operation) {
17
18
  table.rows.forEach(function (row) {
18
19
  var cell = row.cells[insertLeft ? sel.firstColumn : sel.lastColumn];
19
20
  var newCell = (0, roosterjs_content_model_dom_1.createTableCell)(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format, cell.dataset);
21
+ (0, copyPreviousCellSegmentFormat_1.copyPreviousCellSegmentFormat)(cell, newCell);
20
22
  newCell.isSelected = true;
21
23
  row.cells.splice(insertLeft ? sel.firstColumn : sel.lastColumn + 1, 0, newCell);
22
24
  });
@@ -1 +1 @@
1
- {"version":3,"file":"insertTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableColumn.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAC1D,2EAAgF;AAMhF;;;;GAIG;AACH,SAAgB,iBAAiB,CAC7B,KAAsC,EACtC,SAAyC;IAEzC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;IACpC,IAAM,UAAU,GAAG,SAAS,IAAI,YAAY,CAAC;IAE7C,IAAI,GAAG,EAAE;QACL,IAAA,uCAAkB,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC/B,KAAK,IAAI,CAAC,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,EAAE,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE;YACrD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;gBAClB,IAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBAEtE,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;gBACF,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;gBAE1B,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;YACpF,CAAC,CAAC,CAAC;YACH,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;SACL;KACJ;AACL,CAAC;AA/BD,8CA+BC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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: ShallowMutableContentModelTable,\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
+ {"version":3,"file":"insertTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableColumn.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAC1D,iFAAgF;AAChF,2EAAgF;AAMhF;;;;GAIG;AACH,SAAgB,iBAAiB,CAC7B,KAAsC,EACtC,SAAyC;IAEzC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;IACpC,IAAM,UAAU,GAAG,SAAS,IAAI,YAAY,CAAC;IAE7C,IAAI,GAAG,EAAE;QACL,IAAA,uCAAkB,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC/B,KAAK,IAAI,CAAC,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,EAAE,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE;YACrD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;gBAClB,IAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBAEtE,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;gBACF,IAAA,6DAA6B,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBAC7C,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;gBAE1B,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;YACpF,CAAC,CAAC,CAAC;YACH,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;SACL;KACJ;AACL,CAAC;AAhCD,8CAgCC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { copyPreviousCellSegmentFormat } from './copyPreviousCellSegmentFormat';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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: ShallowMutableContentModelTable,\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 copyPreviousCellSegmentFormat(cell, newCell);\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"]}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.insertTableRow = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var clearSelectedCells_1 = require("./clearSelectedCells");
6
+ var copyPreviousCellSegmentFormat_1 = require("./copyPreviousCellSegmentFormat");
6
7
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
7
8
  /**
8
9
  * Insert a row to the table
@@ -20,6 +21,7 @@ function insertTableRow(table, operation) {
20
21
  format: (0, tslib_1.__assign)({}, sourceRow.format),
21
22
  cells: sourceRow.cells.map(function (cell) {
22
23
  var newCell = (0, roosterjs_content_model_dom_1.createTableCell)(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format, cell.dataset);
24
+ (0, copyPreviousCellSegmentFormat_1.copyPreviousCellSegmentFormat)(cell, newCell);
23
25
  newCell.isSelected = true;
24
26
  return newCell;
25
27
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"insertTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableRow.ts"],"names":[],"mappings":";;;;AAAA,2DAA0D;AAC1D,2EAAgF;AAMhF;;;;GAIG;AACH,SAAgB,cAAc,CAC1B,KAAsC,EACtC,SAAuC;IAEvC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;IACpC,IAAM,WAAW,GAAG,SAAS,IAAI,aAAa,CAAC;IAE/C,IAAI,GAAG,EAAE;QACL,IAAA,uCAAkB,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE/B,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE;YAC9C,IAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAEvE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC,EAAE;gBAC/D,MAAM,4BAAO,SAAS,CAAC,MAAM,CAAE;gBAC/B,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI;oBAC3B,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;oBAC1B,OAAO,OAAO,CAAC;gBACnB,CAAC,CAAC;gBACF,MAAM,EAAE,SAAS,CAAC,MAAM;aAC3B,CAAC,CAAC;SACN;KACJ;AACL,CAAC;AA9BD,wCA8BC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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(\n table: ShallowMutableContentModelTable,\n operation: TableVerticalInsertOperation\n) {\n const sel = getSelectedCells(table);\n const insertAbove = operation == 'insertAbove';\n\n if (sel) {\n clearSelectedCells(table, sel);\n\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"]}
1
+ {"version":3,"file":"insertTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableRow.ts"],"names":[],"mappings":";;;;AAAA,2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clearSelectedCells } from './clearSelectedCells';\nimport { copyPreviousCellSegmentFormat } from './copyPreviousCellSegmentFormat';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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(\n table: ShallowMutableContentModelTable,\n operation: TableVerticalInsertOperation\n) {\n const sel = getSelectedCells(table);\n const insertAbove = operation == 'insertAbove';\n\n if (sel) {\n clearSelectedCells(table, sel);\n\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 copyPreviousCellSegmentFormat(cell, newCell);\n newCell.isSelected = true;\n return newCell;\n }),\n height: sourceRow.height,\n });\n }\n }\n}\n"]}
@@ -48,13 +48,17 @@ define(["require", "exports", "../common/adjustIndentation", "../block/splitSele
48
48
  }
49
49
  else {
50
50
  var index = parent.blocks.indexOf(block);
51
+ var isInsideTableCell = parent.blockGroupType == 'TableCell';
51
52
  if (index >= 0) {
52
- if (paragraphOrListItems.length == 1 || !shouldIgnoreBlock(block)) {
53
+ if (paragraphOrListItems.length == 1 ||
54
+ !shouldIgnoreBlock(block) ||
55
+ isInsideTableCell) {
53
56
  var prevBlock = parent.blocks[index - 1];
54
57
  var segmentFormat = (block.blockType == 'Paragraph' && ((_b = block.segments[0]) === null || _b === void 0 ? void 0 : _b.format)) || {};
55
58
  var newListItem = (0, roosterjs_content_model_dom_1.createListItem)([
56
59
  (0, roosterjs_content_model_dom_1.createListLevel)(listType, {
57
- startNumberOverride: itemIndex > 0 ||
60
+ startNumberOverride: isInsideTableCell ||
61
+ itemIndex > 0 ||
58
62
  ((prevBlock === null || prevBlock === void 0 ? void 0 : prevBlock.blockType) == 'BlockGroup' &&
59
63
  prevBlock.blockGroupType == 'ListItem' &&
60
64
  ((_c = prevBlock.levels[0]) === null || _c === void 0 ? void 0 : _c.listType) == 'OL')
@@ -1 +1 @@
1
- {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;;IAwBA;;;;;OAKG;IACH,SAAgB,WAAW,CACvB,KAAmC,EACnC,QAAqB,EACrB,aAA8B;QAA9B,8BAAA,EAAA,qBAA8B;QAE9B,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,oBAAoB,GAAG,IAAA,kDAAoB,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,gDAAkB,EAA+B,KAAK,EAAE,UAAU,CAAC;gBAC/D,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,GAAmC,EAAE,CAAC;QAE3D,oBAAoB,CAAC,OAAO,CAAC,UAAC,EAAiB,EAAE,SAAS;;gBAA1B,KAAK,WAAA,EAAE,MAAM,YAAA;YACzC,IAAI,IAAA,gDAAkB,EAA+B,KAAK,EAAE,UAAU,CAAC,EAAE;gBACrE,IAAM,YAAY,GAAG,IAAA,yCAAW,EAAC,KAAK,CAAC,CAAC;gBACxC,IAAM,KAAK,GAAG,YAAY,CA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,iBAAiB,EAA3D,CAA2D,CACnE,CAAC;YACN;gBACI,OAAO,IAAI,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\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 * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.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 copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\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: ShallowMutableContentModelListItem = 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 marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\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 const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\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/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":";;;;IAwBA;;;;;OAKG;IACH,SAAgB,WAAW,CACvB,KAAmC,EACnC,QAAqB,EACrB,aAA8B;QAA9B,8BAAA,EAAA,qBAA8B;QAE9B,IAAA,uDAA0B,EAAC,KAAK,CAAC,CAAC;QAElC,IAAM,oBAAoB,GAAG,IAAA,kDAAoB,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,gDAAkB,EAA+B,KAAK,EAAE,UAAU,CAAC;gBAC/D,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,GAAmC,EAAE,CAAC;QAE3D,oBAAoB,CAAC,OAAO,CAAC,UAAC,EAAiB,EAAE,SAAS;;gBAA1B,KAAK,WAAA,EAAE,MAAM,YAAA;YACzC,IAAI,IAAA,gDAAkB,EAA+B,KAAK,EAAE,UAAU,CAAC,EAAE;gBACrE,IAAM,YAAY,GAAG,IAAA,yCAAW,EAAC,KAAK,CAAC,CAAC;gB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AO,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 { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\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 * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.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 copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n const isInsideTableCell = parent.blockGroupType == 'TableCell';\n\n if (index >= 0) {\n if (\n paragraphOrListItems.length == 1 ||\n !shouldIgnoreBlock(block) ||\n isInsideTableCell\n ) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n isInsideTableCell ||\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 marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\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 const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\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,5 @@
1
+ import type { ReadonlyContentModelTableCell } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function copyPreviousCellSegmentFormat(cell: ReadonlyContentModelTableCell, newCell: ReadonlyContentModelTableCell): void;
@@ -0,0 +1,25 @@
1
+ define(["require", "exports", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_dom_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.copyPreviousCellSegmentFormat = void 0;
5
+ /**
6
+ * @internal
7
+ */
8
+ function copyPreviousCellSegmentFormat(cell, newCell) {
9
+ var block = cell.blocks[0];
10
+ if (block && (block === null || block === void 0 ? void 0 : block.blockType) == 'Paragraph') {
11
+ var firstSegment = block.segments[0];
12
+ if (firstSegment &&
13
+ (firstSegment.segmentType == 'Text' ||
14
+ firstSegment.segmentType == 'Br' ||
15
+ firstSegment.segmentType == 'SelectionMarker')) {
16
+ var newCellParagraph = (0, roosterjs_content_model_dom_1.createParagraph)(false /* isImplicit */, block.format, block.segmentFormat);
17
+ var br = (0, roosterjs_content_model_dom_1.createBr)(firstSegment.format);
18
+ newCellParagraph.segments.push(br);
19
+ (0, roosterjs_content_model_dom_1.mutateBlock)(newCell).blocks.push(newCellParagraph);
20
+ }
21
+ }
22
+ }
23
+ exports.copyPreviousCellSegmentFormat = copyPreviousCellSegmentFormat;
24
+ });
25
+ //# sourceMappingURL=copyPreviousCellSegmentFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copyPreviousCellSegmentFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/copyPreviousCellSegmentFormat.ts"],"names":[],"mappings":";;;;IAGA;;OAEG;IACH,SAAgB,6BAA6B,CACzC,IAAmC,EACnC,OAAsC;QAEtC,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,KAAK,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,WAAW,EAAE;YAC1C,IAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YACvC,IACI,YAAY;gBACZ,CAAC,YAAY,CAAC,WAAW,IAAI,MAAM;oBAC/B,YAAY,CAAC,WAAW,IAAI,IAAI;oBAChC,YAAY,CAAC,WAAW,IAAI,iBAAiB,CAAC,EACpD;gBACE,IAAM,gBAAgB,GAAG,IAAA,6CAAe,EACpC,KAAK,CAAC,gBAAgB,EACtB,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,aAAa,CACtB,CAAC;gBACF,IAAM,EAAE,GAAG,IAAA,sCAAQ,EAAC,YAAY,CAAC,MAAM,CAAC,CAAC;gBACzC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACnC,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;aACtD;SACJ;IACL,CAAC;IAvBD,sEAuBC","sourcesContent":["import { createBr, createParagraph, mutateBlock } from 'roosterjs-content-model-dom';\nimport type { ReadonlyContentModelTableCell } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function copyPreviousCellSegmentFormat(\n cell: ReadonlyContentModelTableCell,\n newCell: ReadonlyContentModelTableCell\n) {\n const block = cell.blocks[0];\n if (block && block?.blockType == 'Paragraph') {\n const firstSegment = block.segments[0];\n if (\n firstSegment &&\n (firstSegment.segmentType == 'Text' ||\n firstSegment.segmentType == 'Br' ||\n firstSegment.segmentType == 'SelectionMarker')\n ) {\n const newCellParagraph = createParagraph(\n false /* isImplicit */,\n block.format,\n block.segmentFormat\n );\n const br = createBr(firstSegment.format);\n newCellParagraph.segments.push(br);\n mutateBlock(newCell).blocks.push(newCellParagraph);\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "./clearSelectedCells", "roosterjs-content-model-dom"], function (require, exports, clearSelectedCells_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "./clearSelectedCells", "./copyPreviousCellSegmentFormat", "roosterjs-content-model-dom"], function (require, exports, clearSelectedCells_1, copyPreviousCellSegmentFormat_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.insertTableColumn = void 0;
@@ -16,6 +16,7 @@ define(["require", "exports", "./clearSelectedCells", "roosterjs-content-model-d
16
16
  table.rows.forEach(function (row) {
17
17
  var cell = row.cells[insertLeft ? sel.firstColumn : sel.lastColumn];
18
18
  var newCell = (0, roosterjs_content_model_dom_1.createTableCell)(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format, cell.dataset);
19
+ (0, copyPreviousCellSegmentFormat_1.copyPreviousCellSegmentFormat)(cell, newCell);
19
20
  newCell.isSelected = true;
20
21
  row.cells.splice(insertLeft ? sel.firstColumn : sel.lastColumn + 1, 0, newCell);
21
22
  });
@@ -1 +1 @@
1
- {"version":3,"file":"insertTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableColumn.ts"],"names":[],"mappings":";;;;IAOA;;;;OAIG;IACH,SAAgB,iBAAiB,CAC7B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IACL,CAAC;IA/BD,8CA+BC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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: ShallowMutableContentModelTable,\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
+ {"version":3,"file":"insertTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableColumn.ts"],"names":[],"mappings":";;;;IAQA;;;;OAIG;IACH,SAAgB,iBAAiB,CAC7B,KAAsC,EACtC,SAAyC;QAEzC,IAAM,GAAG,GAAG,IAAA,8CAAgB,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,IAAA,6DAA6B,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;oBAC7C,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;IAhCD,8CAgCC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { copyPreviousCellSegmentFormat } from './copyPreviousCellSegmentFormat';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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: ShallowMutableContentModelTable,\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 copyPreviousCellSegmentFormat(cell, newCell);\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,4 +1,4 @@
1
- define(["require", "exports", "tslib", "./clearSelectedCells", "roosterjs-content-model-dom"], function (require, exports, tslib_1, clearSelectedCells_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "tslib", "./clearSelectedCells", "./copyPreviousCellSegmentFormat", "roosterjs-content-model-dom"], function (require, exports, tslib_1, clearSelectedCells_1, copyPreviousCellSegmentFormat_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.insertTableRow = void 0;
@@ -18,6 +18,7 @@ define(["require", "exports", "tslib", "./clearSelectedCells", "roosterjs-conten
18
18
  format: (0, tslib_1.__assign)({}, sourceRow.format),
19
19
  cells: sourceRow.cells.map(function (cell) {
20
20
  var newCell = (0, roosterjs_content_model_dom_1.createTableCell)(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format, cell.dataset);
21
+ (0, copyPreviousCellSegmentFormat_1.copyPreviousCellSegmentFormat)(cell, newCell);
21
22
  newCell.isSelected = true;
22
23
  return newCell;
23
24
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"insertTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableRow.ts"],"names":[],"mappings":";;;;IAOA;;;;OAIG;IACH,SAAgB,cAAc,CAC1B,KAAsC,EACtC,SAAuC;QAEvC,IAAM,GAAG,GAAG,IAAA,8CAAgB,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;YAE/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;IA9BD,wCA8BC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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(\n table: ShallowMutableContentModelTable,\n operation: TableVerticalInsertOperation\n) {\n const sel = getSelectedCells(table);\n const insertAbove = operation == 'insertAbove';\n\n if (sel) {\n clearSelectedCells(table, sel);\n\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"]}
1
+ {"version":3,"file":"insertTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableRow.ts"],"names":[],"mappings":";;;;IAQA;;;;OAIG;IACH,SAAgB,cAAc,CAC1B,KAAsC,EACtC,SAAuC;QAEvC,IAAM,GAAG,GAAG,IAAA,8CAAgB,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;YAE/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,IAAA,6DAA6B,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;wBAC7C,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;IA/BD,wCA+BC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { copyPreviousCellSegmentFormat } from './copyPreviousCellSegmentFormat';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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(\n table: ShallowMutableContentModelTable,\n operation: TableVerticalInsertOperation\n) {\n const sel = getSelectedCells(table);\n const insertAbove = operation == 'insertAbove';\n\n if (sel) {\n clearSelectedCells(table, sel);\n\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 copyPreviousCellSegmentFormat(cell, newCell);\n newCell.isSelected = true;\n return newCell;\n }),\n height: sourceRow.height,\n });\n }\n }\n}\n"]}
@@ -47,13 +47,17 @@ export function setListType(model, listType, removeMargins) {
47
47
  }
48
48
  else {
49
49
  var index = parent.blocks.indexOf(block);
50
+ var isInsideTableCell = parent.blockGroupType == 'TableCell';
50
51
  if (index >= 0) {
51
- if (paragraphOrListItems.length == 1 || !shouldIgnoreBlock(block)) {
52
+ if (paragraphOrListItems.length == 1 ||
53
+ !shouldIgnoreBlock(block) ||
54
+ isInsideTableCell) {
52
55
  var prevBlock = parent.blocks[index - 1];
53
56
  var segmentFormat = (block.blockType == 'Paragraph' && ((_b = block.segments[0]) === null || _b === void 0 ? void 0 : _b.format)) || {};
54
57
  var newListItem = createListItem([
55
58
  createListLevel(listType, {
56
- startNumberOverride: itemIndex > 0 ||
59
+ startNumberOverride: isInsideTableCell ||
60
+ itemIndex > 0 ||
57
61
  ((prevBlock === null || prevBlock === void 0 ? void 0 : prevBlock.blockType) == 'BlockGroup' &&
58
62
  prevBlock.blockGroupType == 'ListItem' &&
59
63
  ((_c = prevBlock.levels[0]) === null || _c === void 0 ? void 0 : _c.listType) == 'OL')
@@ -1 +1 @@
1
- {"version":3,"file":"setListType.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EACH,UAAU,EACV,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACX,qBAAqB,EACrB,uBA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,UAAA,QAAQ;4BAC9B,OAAA,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE;gCACxB,uBAAuB,EAAE,IAAI;6BAChC,CAAC;wBAFF,CAEE,CACL,CAAC;qBACL;iBACJ;qBAAM;oBACH,iBAAiB,CAAC,OAAO,CACrB,UAAA,CAAC,IAAI,OAAA,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAtD,CAAsD,CAC9D,CAAC;oBACF,iBAAiB,GAAG,EAAE,CAAC;iBAC1B;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAgC;IACvD,QAAQ,KAAK,CAAC,SAAS,EAAE;QACrB,KAAK,OAAO;YACR,OAAO,KAAK,CAAC;QACjB,KAAK,WAAW;YACZ,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;QACN;YACI,OAAO,IAAI,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\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 * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.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 copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\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: ShallowMutableContentModelListItem = 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 marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\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 const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\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/roosterjs-content-model-api/lib/modelApi/list/setListType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qC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AC,IAAI,CAAC,WAAW,CAAC,CAAC;oBAEpC,IAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;oBACjD,IAAM,KAAK,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;oBAE1D,IAAI,KAAK,EAAE;wBACP,kBAAkB,CAAC,KAAK,EAAE,UAAA,QAAQ;4BAC9B,OAAA,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE;gCACxB,uBAAuB,EAAE,IAAI;6BAChC,CAAC;wBAFF,CAEE,CACL,CAAC;qBACL;iBACJ;qBAAM;oBACH,iBAAiB,CAAC,OAAO,CACrB,UAAA,CAAC,IAAI,OAAA,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,EAAtD,CAAsD,CAC9D,CAAC;oBACF,iBAAiB,GAAG,EAAE,CAAC;iBAC1B;aACJ;SACJ;IACL,CAAC,CAAC,CAAC;IAEH,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAE7B,OAAO,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAgC;IACvD,QAAQ,KAAK,CAAC,SAAS,EAAE;QACrB,KAAK,OAAO;YACR,OAAO,KAAK,CAAC;QACjB,KAAK,WAAW;YACZ,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;QACN;YACI,OAAO,IAAI,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { adjustListIndentation } from '../common/adjustIndentation';\nimport { splitSelectedParagraphByBr } from '../block/splitSelectedParagraphByBr';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n ListFormats,\n ListFormatsToKeep,\n ListFormatsToMove,\n mutateBlock,\n normalizeContentModel,\n setParagraphNotImplicit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ReadonlyContentModelBlock,\n ReadonlyContentModelDocument,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\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 * @param removeMargins true to remove margins, false to keep margins @default false\n */\nexport function setListType(\n model: ReadonlyContentModelDocument,\n listType: 'OL' | 'UL',\n removeMargins: boolean = false\n) {\n splitSelectedParagraphByBr(model);\n\n const paragraphOrListItems = getOperationalBlocks<ReadonlyContentModelListItem>(\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<ReadonlyContentModelListItem>(block, 'ListItem')\n ? block.levels[block.levels.length - 1]?.listType == listType\n : shouldIgnoreBlock(block)\n );\n let existingListItems: ReadonlyContentModelListItem[] = [];\n\n paragraphOrListItems.forEach(({ block, parent }, itemIndex) => {\n if (isBlockGroupOfType<ReadonlyContentModelListItem>(block, 'ListItem')) {\n const mutableBlock = mutateBlock(block);\n const level = mutableBlock.levels.pop();\n\n if (!alreadyInExpectedType && level) {\n level.listType = listType;\n\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n\n mutableBlock.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 copyFormat<ContentModelBlockFormat>(x.format, block.format, ListFormats);\n });\n }\n } else {\n const index = parent.blocks.indexOf(block);\n const isInsideTableCell = parent.blockGroupType == 'TableCell';\n\n if (index >= 0) {\n if (\n paragraphOrListItems.length == 1 ||\n !shouldIgnoreBlock(block) ||\n isInsideTableCell\n ) {\n const prevBlock = parent.blocks[index - 1];\n const segmentFormat =\n (block.blockType == 'Paragraph' && block.segments[0]?.format) || {};\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n [\n createListLevel(listType, {\n startNumberOverride:\n isInsideTableCell ||\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 marginBottom: removeMargins ? '0px' : undefined,\n marginTop: removeMargins ? '0px' : undefined,\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 const mutableBlock = mutateBlock(block);\n\n newListItem.blocks.push(mutableBlock);\n\n adjustListIndentation(newListItem);\n\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToMove,\n true /*deleteOriginalFormat*/\n );\n copyFormat<ContentModelBlockFormat>(\n newListItem.format,\n mutableBlock.format,\n ListFormatsToKeep\n );\n\n mutateBlock(parent).blocks.splice(index, 1, newListItem);\n existingListItems.push(newListItem);\n\n const levelIndex = newListItem.levels.length - 1;\n const level = mutateBlock(newListItem).levels[levelIndex];\n\n if (level) {\n updateListMetadata(level, metadata =>\n Object.assign({}, metadata, {\n applyListStyleFromLevel: true,\n })\n );\n }\n } else {\n existingListItems.forEach(\n x => (mutateBlock(x).levels[0].format.marginBottom = '0px')\n );\n existingListItems = [];\n }\n }\n }\n });\n\n normalizeContentModel(model);\n\n return paragraphOrListItems.length > 0;\n}\n\nfunction shouldIgnoreBlock(block: ReadonlyContentModelBlock) {\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,5 @@
1
+ import type { ReadonlyContentModelTableCell } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function copyPreviousCellSegmentFormat(cell: ReadonlyContentModelTableCell, newCell: ReadonlyContentModelTableCell): void;
@@ -0,0 +1,20 @@
1
+ import { createBr, createParagraph, mutateBlock } from 'roosterjs-content-model-dom';
2
+ /**
3
+ * @internal
4
+ */
5
+ export function copyPreviousCellSegmentFormat(cell, newCell) {
6
+ var block = cell.blocks[0];
7
+ if (block && (block === null || block === void 0 ? void 0 : block.blockType) == 'Paragraph') {
8
+ var firstSegment = block.segments[0];
9
+ if (firstSegment &&
10
+ (firstSegment.segmentType == 'Text' ||
11
+ firstSegment.segmentType == 'Br' ||
12
+ firstSegment.segmentType == 'SelectionMarker')) {
13
+ var newCellParagraph = createParagraph(false /* isImplicit */, block.format, block.segmentFormat);
14
+ var br = createBr(firstSegment.format);
15
+ newCellParagraph.segments.push(br);
16
+ mutateBlock(newCell).blocks.push(newCellParagraph);
17
+ }
18
+ }
19
+ }
20
+ //# sourceMappingURL=copyPreviousCellSegmentFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copyPreviousCellSegmentFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/copyPreviousCellSegmentFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAGrF;;GAEG;AACH,MAAM,UAAU,6BAA6B,CACzC,IAAmC,EACnC,OAAsC;IAEtC,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,KAAK,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,WAAW,EAAE;QAC1C,IAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACvC,IACI,YAAY;YACZ,CAAC,YAAY,CAAC,WAAW,IAAI,MAAM;gBAC/B,YAAY,CAAC,WAAW,IAAI,IAAI;gBAChC,YAAY,CAAC,WAAW,IAAI,iBAAiB,CAAC,EACpD;YACE,IAAM,gBAAgB,GAAG,eAAe,CACpC,KAAK,CAAC,gBAAgB,EACtB,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,aAAa,CACtB,CAAC;YACF,IAAM,EAAE,GAAG,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YACzC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACnC,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;SACtD;KACJ;AACL,CAAC","sourcesContent":["import { createBr, createParagraph, mutateBlock } from 'roosterjs-content-model-dom';\nimport type { ReadonlyContentModelTableCell } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function copyPreviousCellSegmentFormat(\n cell: ReadonlyContentModelTableCell,\n newCell: ReadonlyContentModelTableCell\n) {\n const block = cell.blocks[0];\n if (block && block?.blockType == 'Paragraph') {\n const firstSegment = block.segments[0];\n if (\n firstSegment &&\n (firstSegment.segmentType == 'Text' ||\n firstSegment.segmentType == 'Br' ||\n firstSegment.segmentType == 'SelectionMarker')\n ) {\n const newCellParagraph = createParagraph(\n false /* isImplicit */,\n block.format,\n block.segmentFormat\n );\n const br = createBr(firstSegment.format);\n newCellParagraph.segments.push(br);\n mutateBlock(newCell).blocks.push(newCellParagraph);\n }\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { clearSelectedCells } from './clearSelectedCells';
2
+ import { copyPreviousCellSegmentFormat } from './copyPreviousCellSegmentFormat';
2
3
  import { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';
3
4
  /**
4
5
  * Insert a column to the table
@@ -14,6 +15,7 @@ export function insertTableColumn(table, operation) {
14
15
  table.rows.forEach(function (row) {
15
16
  var cell = row.cells[insertLeft ? sel.firstColumn : sel.lastColumn];
16
17
  var newCell = createTableCell(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format, cell.dataset);
18
+ copyPreviousCellSegmentFormat(cell, newCell);
17
19
  newCell.isSelected = true;
18
20
  row.cells.splice(insertLeft ? sel.firstColumn : sel.lastColumn + 1, 0, newCell);
19
21
  });
@@ -1 +1 @@
1
- {"version":3,"file":"insertTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableColumn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAMhF;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC7B,KAAsC,EACtC,SAAyC;IAEzC,IAAM,GAAG,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACpC,IAAM,UAAU,GAAG,SAAS,IAAI,YAAY,CAAC;IAE7C,IAAI,GAAG,EAAE;QACL,kBAAkB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC/B,KAAK,IAAI,CAAC,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,EAAE,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE;YACrD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;gBAClB,IAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBAEtE,IAAM,OAAO,GAAG,eAAe,CAC3B,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,CACf,CAAC;gBACF,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;gBAE1B,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;YACpF,CAAC,CAAC,CAAC;YACH,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;SACL;KACJ;AACL,CAAC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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: ShallowMutableContentModelTable,\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
+ {"version":3,"file":"insertTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableColumn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAMhF;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC7B,KAAsC,EACtC,SAAyC;IAEzC,IAAM,GAAG,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACpC,IAAM,UAAU,GAAG,SAAS,IAAI,YAAY,CAAC;IAE7C,IAAI,GAAG,EAAE;QACL,kBAAkB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC/B,KAAK,IAAI,CAAC,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,EAAE,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE;YACrD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;gBAClB,IAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBAEtE,IAAM,OAAO,GAAG,eAAe,CAC3B,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,CACf,CAAC;gBACF,6BAA6B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBAC7C,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;gBAE1B,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;YACpF,CAAC,CAAC,CAAC;YACH,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;SACL;KACJ;AACL,CAAC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { copyPreviousCellSegmentFormat } from './copyPreviousCellSegmentFormat';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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: ShallowMutableContentModelTable,\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 copyPreviousCellSegmentFormat(cell, newCell);\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,6 @@
1
1
  import { __assign } from "tslib";
2
2
  import { clearSelectedCells } from './clearSelectedCells';
3
+ import { copyPreviousCellSegmentFormat } from './copyPreviousCellSegmentFormat';
3
4
  import { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';
4
5
  /**
5
6
  * Insert a row to the table
@@ -17,6 +18,7 @@ export function insertTableRow(table, operation) {
17
18
  format: __assign({}, sourceRow.format),
18
19
  cells: sourceRow.cells.map(function (cell) {
19
20
  var newCell = createTableCell(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format, cell.dataset);
21
+ copyPreviousCellSegmentFormat(cell, newCell);
20
22
  newCell.isSelected = true;
21
23
  return newCell;
22
24
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"insertTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableRow.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAMhF;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC1B,KAAsC,EACtC,SAAuC;IAEvC,IAAM,GAAG,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACpC,IAAM,WAAW,GAAG,SAAS,IAAI,aAAa,CAAC;IAE/C,IAAI,GAAG,EAAE;QACL,kBAAkB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE/B,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE;YAC9C,IAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAEvE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC,EAAE;gBAC/D,MAAM,eAAO,SAAS,CAAC,MAAM,CAAE;gBAC/B,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI;oBAC3B,IAAM,OAAO,GAAG,eAAe,CAC3B,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;oBAC1B,OAAO,OAAO,CAAC;gBACnB,CAAC,CAAC;gBACF,MAAM,EAAE,SAAS,CAAC,MAAM;aAC3B,CAAC,CAAC;SACN;KACJ;AACL,CAAC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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(\n table: ShallowMutableContentModelTable,\n operation: TableVerticalInsertOperation\n) {\n const sel = getSelectedCells(table);\n const insertAbove = operation == 'insertAbove';\n\n if (sel) {\n clearSelectedCells(table, sel);\n\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"]}
1
+ {"version":3,"file":"insertTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/insertTableRow.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAMhF;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC1B,KAAsC,EACtC,SAAuC;IAEvC,IAAM,GAAG,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACpC,IAAM,WAAW,GAAG,SAAS,IAAI,aAAa,CAAC;IAE/C,IAAI,GAAG,EAAE;QACL,kBAAkB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE/B,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE;YAC9C,IAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAEvE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC,EAAE;gBAC/D,MAAM,eAAO,SAAS,CAAC,MAAM,CAAE;gBAC/B,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI;oBAC3B,IAAM,OAAO,GAAG,eAAe,CAC3B,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,CACf,CAAC;oBACF,6BAA6B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;oBAC7C,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;oBAC1B,OAAO,OAAO,CAAC;gBACnB,CAAC,CAAC;gBACF,MAAM,EAAE,SAAS,CAAC,MAAM;aAC3B,CAAC,CAAC;SACN;KACJ;AACL,CAAC","sourcesContent":["import { clearSelectedCells } from './clearSelectedCells';\nimport { copyPreviousCellSegmentFormat } from './copyPreviousCellSegmentFormat';\nimport { createTableCell, getSelectedCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\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(\n table: ShallowMutableContentModelTable,\n operation: TableVerticalInsertOperation\n) {\n const sel = getSelectedCells(table);\n const insertAbove = operation == 'insertAbove';\n\n if (sel) {\n clearSelectedCells(table, sel);\n\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 copyPreviousCellSegmentFormat(cell, newCell);\n newCell.isSelected = true;\n return newCell;\n }),\n height: sourceRow.height,\n });\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -3,16 +3,16 @@
3
3
  "description": "Format API for roosterjs",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.1",
6
- "roosterjs-content-model-dom": "^9.45.1",
7
- "roosterjs-content-model-types": "^9.45.1"
6
+ "roosterjs-content-model-dom": "^9.45.2",
7
+ "roosterjs-content-model-types": "^9.45.2"
8
8
  },
9
- "version": "9.45.1",
9
+ "version": "9.45.2",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",
13
13
  "license": "MIT",
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "git+https://github.com/Microsoft/roosterjs.git"
16
+ "url": "https://github.com/Microsoft/roosterjs"
17
17
  }
18
18
  }