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.
- package/lib/index.d.ts +5 -0
- package/lib/index.js +11 -1
- package/lib/index.js.map +1 -1
- package/lib/modelApi/block/setModelIndentation.d.ts +4 -1
- package/lib/modelApi/block/setModelIndentation.js +114 -23
- package/lib/modelApi/block/setModelIndentation.js.map +1 -1
- package/lib/modelApi/block/toggleModelBlockQuote.js.map +1 -1
- package/lib/modelApi/entity/insertEntityModel.d.ts +2 -2
- package/lib/modelApi/entity/insertEntityModel.js +4 -0
- package/lib/modelApi/entity/insertEntityModel.js.map +1 -1
- package/lib/modelApi/list/findListItemsInSameThread.d.ts +3 -1
- package/lib/modelApi/list/findListItemsInSameThread.js +3 -1
- package/lib/modelApi/list/findListItemsInSameThread.js.map +1 -1
- package/lib/modelApi/list/setListType.js +1 -1
- package/lib/modelApi/list/setListType.js.map +1 -1
- package/lib/modelApi/table/clearSelectedCells.d.ts +8 -0
- package/lib/modelApi/table/clearSelectedCells.js +27 -0
- package/lib/modelApi/table/clearSelectedCells.js.map +1 -0
- package/lib/modelApi/table/insertTableColumn.d.ts +3 -1
- package/lib/modelApi/table/insertTableColumn.js +8 -2
- package/lib/modelApi/table/insertTableColumn.js.map +1 -1
- package/lib/modelApi/table/insertTableRow.d.ts +3 -1
- package/lib/modelApi/table/insertTableRow.js +8 -2
- package/lib/modelApi/table/insertTableRow.js.map +1 -1
- package/lib/publicApi/entity/insertEntity.js +7 -2
- package/lib/publicApi/entity/insertEntity.js.map +1 -1
- package/lib/publicApi/format/getFormatState.js +2 -2
- package/lib/publicApi/format/getFormatState.js.map +1 -1
- package/lib/publicApi/table/editTable.js +52 -77
- package/lib/publicApi/table/editTable.js.map +1 -1
- package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/lib/publicApi/utils/formatTableWithContentModel.d.ts +9 -0
- package/lib/publicApi/utils/formatTableWithContentModel.js +44 -0
- package/lib/publicApi/utils/formatTableWithContentModel.js.map +1 -0
- package/lib-amd/index.d.ts +5 -0
- package/lib-amd/index.js +7 -2
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/modelApi/block/setModelIndentation.d.ts +4 -1
- package/lib-amd/modelApi/block/setModelIndentation.js +114 -24
- package/lib-amd/modelApi/block/setModelIndentation.js.map +1 -1
- package/lib-amd/modelApi/block/toggleModelBlockQuote.js.map +1 -1
- package/lib-amd/modelApi/entity/insertEntityModel.d.ts +2 -2
- package/lib-amd/modelApi/entity/insertEntityModel.js +4 -0
- package/lib-amd/modelApi/entity/insertEntityModel.js.map +1 -1
- package/lib-amd/modelApi/list/findListItemsInSameThread.d.ts +3 -1
- package/lib-amd/modelApi/list/findListItemsInSameThread.js +3 -1
- package/lib-amd/modelApi/list/findListItemsInSameThread.js.map +1 -1
- package/lib-amd/modelApi/list/setListType.js +1 -1
- package/lib-amd/modelApi/list/setListType.js.map +1 -1
- package/lib-amd/modelApi/table/clearSelectedCells.d.ts +8 -0
- package/lib-amd/modelApi/table/clearSelectedCells.js +28 -0
- package/lib-amd/modelApi/table/clearSelectedCells.js.map +1 -0
- package/lib-amd/modelApi/table/insertTableColumn.d.ts +3 -1
- package/lib-amd/modelApi/table/insertTableColumn.js +8 -3
- package/lib-amd/modelApi/table/insertTableColumn.js.map +1 -1
- package/lib-amd/modelApi/table/insertTableRow.d.ts +3 -1
- package/lib-amd/modelApi/table/insertTableRow.js +8 -3
- package/lib-amd/modelApi/table/insertTableRow.js.map +1 -1
- package/lib-amd/publicApi/entity/insertEntity.js +7 -2
- package/lib-amd/publicApi/entity/insertEntity.js.map +1 -1
- package/lib-amd/publicApi/format/getFormatState.js +2 -2
- package/lib-amd/publicApi/format/getFormatState.js.map +1 -1
- package/lib-amd/publicApi/table/editTable.js +52 -74
- package/lib-amd/publicApi/table/editTable.js.map +1 -1
- package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/lib-amd/publicApi/utils/formatTableWithContentModel.d.ts +9 -0
- package/lib-amd/publicApi/utils/formatTableWithContentModel.js +42 -0
- package/lib-amd/publicApi/utils/formatTableWithContentModel.js.map +1 -0
- package/lib-mjs/index.d.ts +5 -0
- package/lib-mjs/index.js +5 -0
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/modelApi/block/setModelIndentation.d.ts +4 -1
- package/lib-mjs/modelApi/block/setModelIndentation.js +115 -24
- package/lib-mjs/modelApi/block/setModelIndentation.js.map +1 -1
- package/lib-mjs/modelApi/block/toggleModelBlockQuote.js.map +1 -1
- package/lib-mjs/modelApi/entity/insertEntityModel.d.ts +2 -2
- package/lib-mjs/modelApi/entity/insertEntityModel.js +4 -0
- package/lib-mjs/modelApi/entity/insertEntityModel.js.map +1 -1
- package/lib-mjs/modelApi/list/findListItemsInSameThread.d.ts +3 -1
- package/lib-mjs/modelApi/list/findListItemsInSameThread.js +3 -1
- package/lib-mjs/modelApi/list/findListItemsInSameThread.js.map +1 -1
- package/lib-mjs/modelApi/list/setListType.js +1 -1
- package/lib-mjs/modelApi/list/setListType.js.map +1 -1
- package/lib-mjs/modelApi/table/clearSelectedCells.d.ts +8 -0
- package/lib-mjs/modelApi/table/clearSelectedCells.js +23 -0
- package/lib-mjs/modelApi/table/clearSelectedCells.js.map +1 -0
- package/lib-mjs/modelApi/table/insertTableColumn.d.ts +3 -1
- package/lib-mjs/modelApi/table/insertTableColumn.js +8 -2
- package/lib-mjs/modelApi/table/insertTableColumn.js.map +1 -1
- package/lib-mjs/modelApi/table/insertTableRow.d.ts +3 -1
- package/lib-mjs/modelApi/table/insertTableRow.js +8 -2
- package/lib-mjs/modelApi/table/insertTableRow.js.map +1 -1
- package/lib-mjs/publicApi/entity/insertEntity.js +7 -2
- package/lib-mjs/publicApi/entity/insertEntity.js.map +1 -1
- package/lib-mjs/publicApi/format/getFormatState.js +1 -1
- package/lib-mjs/publicApi/format/getFormatState.js.map +1 -1
- package/lib-mjs/publicApi/table/editTable.js +52 -77
- package/lib-mjs/publicApi/table/editTable.js.map +1 -1
- package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/lib-mjs/publicApi/utils/formatTableWithContentModel.d.ts +9 -0
- package/lib-mjs/publicApi/utils/formatTableWithContentModel.js +40 -0
- package/lib-mjs/publicApi/utils/formatTableWithContentModel.js.map +1 -0
- package/package.json +4 -4
- package/lib/modelApi/common/retrieveModelFormatState.d.ts +0 -5
- package/lib/modelApi/common/retrieveModelFormatState.js +0 -171
- package/lib/modelApi/common/retrieveModelFormatState.js.map +0 -1
- package/lib-amd/modelApi/common/retrieveModelFormatState.d.ts +0 -5
- package/lib-amd/modelApi/common/retrieveModelFormatState.js +0 -171
- package/lib-amd/modelApi/common/retrieveModelFormatState.js.map +0 -1
- package/lib-mjs/modelApi/common/retrieveModelFormatState.d.ts +0 -5
- package/lib-mjs/modelApi/common/retrieveModelFormatState.js +0 -167
- package/lib-mjs/modelApi/common/retrieveModelFormatState.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editTable.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/editTable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"editTable.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/editTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;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M;YAEV,KAAK,YAAY,CAAC;YAClB,KAAK,aAAa;gBACd,iBAAiB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;gBACzC,MAAM;YAEV,KAAK,YAAY,CAAC;YAClB,KAAK,YAAY;gBACb,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;gBACrC,MAAM;YAEV,KAAK,YAAY;gBACb,eAAe,CAAC,UAAU,CAAC,CAAC;gBAC5B,MAAM;YAEV,KAAK,WAAW,CAAC;YACjB,KAAK,YAAY;gBACb,gBAAgB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;gBACxC,MAAM;YAEV,KAAK,mBAAmB;gBACpB,0BAA0B,CAAC,UAAU,CAAC,CAAC;gBACvC,MAAM;YAEV,KAAK,iBAAiB;gBAClB,wBAAwB,CAAC,UAAU,CAAC,CAAC;gBACrC,MAAM;SACb;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { alignTable } from '../../modelApi/table/alignTable';\nimport { deleteTable } from '../../modelApi/table/deleteTable';\nimport { deleteTableColumn } from '../../modelApi/table/deleteTableColumn';\nimport { deleteTableRow } from '../../modelApi/table/deleteTableRow';\nimport { formatTableWithContentModel } from '../utils/formatTableWithContentModel';\nimport { insertTableColumn } from '../../modelApi/table/insertTableColumn';\nimport { insertTableRow } from '../../modelApi/table/insertTableRow';\nimport { mergeTableCells } from '../../modelApi/table/mergeTableCells';\nimport { mergeTableColumn } from '../../modelApi/table/mergeTableColumn';\nimport { mergeTableRow } from '../../modelApi/table/mergeTableRow';\nimport { splitTableCellHorizontally } from '../../modelApi/table/splitTableCellHorizontally';\nimport { splitTableCellVertically } from '../../modelApi/table/splitTableCellVertically';\nimport type { TableOperation, IStandaloneEditor } from 'roosterjs-content-model-types';\nimport {\n alignTableCellHorizontally,\n alignTableCellVertically,\n} from '../../modelApi/table/alignTableCell';\n\n/**\n * Format current focused table with the given format\n * @param editor The editor instance\n * @param operation The table operation to apply\n */\nexport default function editTable(editor: IStandaloneEditor, operation: TableOperation) {\n editor.focus();\n\n formatTableWithContentModel(editor, 'editTable', tableModel => {\n switch (operation) {\n case 'alignCellLeft':\n case 'alignCellCenter':\n case 'alignCellRight':\n alignTableCellHorizontally(tableModel, operation);\n break;\n case 'alignCellTop':\n case 'alignCellMiddle':\n case 'alignCellBottom':\n alignTableCellVertically(tableModel, operation);\n break;\n case 'alignCenter':\n case 'alignLeft':\n case 'alignRight':\n alignTable(tableModel, operation);\n break;\n\n case 'deleteColumn':\n deleteTableColumn(tableModel);\n break;\n\n case 'deleteRow':\n deleteTableRow(tableModel);\n break;\n\n case 'deleteTable':\n deleteTable(tableModel);\n break;\n\n case 'insertAbove':\n case 'insertBelow':\n insertTableRow(tableModel, operation);\n break;\n\n case 'insertLeft':\n case 'insertRight':\n insertTableColumn(tableModel, operation);\n break;\n\n case 'mergeAbove':\n case 'mergeBelow':\n mergeTableRow(tableModel, operation);\n break;\n\n case 'mergeCells':\n mergeTableCells(tableModel);\n break;\n\n case 'mergeLeft':\n case 'mergeRight':\n mergeTableColumn(tableModel, operation);\n break;\n\n case 'splitHorizontally':\n splitTableCellHorizontally(tableModel);\n break;\n\n case 'splitVertically':\n splitTableCellVertically(tableModel);\n break;\n }\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,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AuB,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC;YAAnD,CAAmD,CACtD;YACH,CAAC,CAAC,KAAK,CAAC;QAEZ,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAA4B;gBAA5B,KAAA,aAA4B,EAA3B,MAAM,QAAA,EAAE,OAAO,QAAA,EAAE,SAAS,QAAA;YACnD,OAAA,mBAAmB,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,SAAS,CAAC;QAA9D,CAA8D,CACjE,CAAC;QAEF,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAG,KAAK,CAAC,CAAC;QAE7B,IAAI,oBAAoB,EAAE;YACtB,OAAO,CAAC,gBAAgB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;SAChB;aAAM;YACH,OAAO,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;SACxC;IACL,CAAC,EACD;QACI,OAAO,SAAA;KACV,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelSegment,\n ContentModelSegmentFormat,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function formatSegmentWithContentModel(\n editor: IStandaloneEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length == 1 &&\n segmentAndParagraphs[0][0].segmentType == 'SelectionMarker';\n\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ContentModelSegment | null,\n ContentModelParagraph | null\n ][] = segmentAndParagraphs.map(item => [item[0].format, item[0], item[1]]);\n\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n formatsAndSegments.forEach(([format, segment, paragraph]) =>\n toggleStyleCallback(format, !isTurningOff, segment, paragraph)\n );\n\n afterFormatCallback?.(model);\n\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ContentModelTable, IStandaloneEditor, TableSelection } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* Invoke a callback to format the selected table using Content Model
|
|
4
|
+
* @param editor The editor object
|
|
5
|
+
* @param apiName Name of API this calling this function. This is mostly for logging.
|
|
6
|
+
* @param callback The callback to format the table. It will be called with current selected table. If no table is selected, it will not be called.
|
|
7
|
+
* @param selectionOverride Override the current selection. If we want to format a table even currently it is not selected, we can use this parameter to override current selection
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatTableWithContentModel(editor: IStandaloneEditor, apiName: string, callback: (tableModel: ContentModelTable) => void, selectionOverride?: TableSelection): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { __read } from "tslib";
|
|
2
|
+
import { ensureFocusableParagraphForTable } from '../../modelApi/table/ensureFocusableParagraphForTable';
|
|
3
|
+
import { createSelectionMarker, hasMetadata, setParagraphNotImplicit, } from 'roosterjs-content-model-dom';
|
|
4
|
+
import { hasSelectionInBlock, applyTableFormat, getFirstSelectedTable, normalizeTable, setSelection, } from 'roosterjs-content-model-core';
|
|
5
|
+
/**
|
|
6
|
+
* Invoke a callback to format the selected table using Content Model
|
|
7
|
+
* @param editor The editor object
|
|
8
|
+
* @param apiName Name of API this calling this function. This is mostly for logging.
|
|
9
|
+
* @param callback The callback to format the table. It will be called with current selected table. If no table is selected, it will not be called.
|
|
10
|
+
* @param selectionOverride Override the current selection. If we want to format a table even currently it is not selected, we can use this parameter to override current selection
|
|
11
|
+
*/
|
|
12
|
+
export function formatTableWithContentModel(editor, apiName, callback, selectionOverride) {
|
|
13
|
+
editor.formatContentModel(function (model) {
|
|
14
|
+
var _a = __read(getFirstSelectedTable(model), 2), tableModel = _a[0], path = _a[1];
|
|
15
|
+
if (tableModel) {
|
|
16
|
+
callback(tableModel);
|
|
17
|
+
if (!hasSelectionInBlock(tableModel)) {
|
|
18
|
+
var paragraph = ensureFocusableParagraphForTable(model, path, tableModel);
|
|
19
|
+
if (paragraph) {
|
|
20
|
+
var marker = createSelectionMarker(model.format);
|
|
21
|
+
paragraph.segments.unshift(marker);
|
|
22
|
+
setParagraphNotImplicit(paragraph);
|
|
23
|
+
setSelection(model, marker);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
normalizeTable(tableModel, model.format);
|
|
27
|
+
if (hasMetadata(tableModel)) {
|
|
28
|
+
applyTableFormat(tableModel, undefined /*newFormat*/, true /*keepCellShade*/);
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}, {
|
|
36
|
+
apiName: apiName,
|
|
37
|
+
selectionOverride: selectionOverride,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=formatTableWithContentModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatTableWithContentModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/utils/formatTableWithContentModel.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,uDAAuD,CAAC;AACzG,OAAO,EACH,qBAAqB,EACrB,WAAW,EACX,uBAAuB,GAC1B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACH,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,cAAc,EACd,YAAY,GACf,MAAM,8BAA8B,CAAC;AAOtC;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CACvC,MAAyB,EACzB,OAAe,EACf,QAAiD,EACjD,iBAAkC;IAElC,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;QACK,IAAA,KAAA,OAAqB,qBAAqB,CAAC,KAAK,CAAC,IAAA,EAAhD,UAAU,QAAA,EAAE,IAAI,QAAgC,CAAC;QAExD,IAAI,UAAU,EAAE;YACZ,QAAQ,CAAC,UAAU,CAAC,CAAC;YAErB,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,EAAE;gBAClC,IAAM,SAAS,GAAG,gCAAgC,CAAC,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;gBAE5E,IAAI,SAAS,EAAE;oBACX,IAAM,MAAM,GAAG,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;oBAEnD,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACnC,uBAAuB,CAAC,SAAS,CAAC,CAAC;oBACnC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;iBAC/B;aACJ;YAED,cAAc,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YAEzC,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE;gBACzB,gBAAgB,CAAC,UAAU,EAAE,SAAS,CAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;aACjF;YAED,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,EACD;QACI,OAAO,SAAA;QACP,iBAAiB,mBAAA;KACpB,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { ensureFocusableParagraphForTable } from '../../modelApi/table/ensureFocusableParagraphForTable';\nimport {\n createSelectionMarker,\n hasMetadata,\n setParagraphNotImplicit,\n} from 'roosterjs-content-model-dom';\nimport {\n hasSelectionInBlock,\n applyTableFormat,\n getFirstSelectedTable,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-core';\nimport type {\n ContentModelTable,\n IStandaloneEditor,\n TableSelection,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected table using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param callback The callback to format the table. It will be called with current selected table. If no table is selected, it will not be called.\n * @param selectionOverride Override the current selection. If we want to format a table even currently it is not selected, we can use this parameter to override current selection\n */\nexport function formatTableWithContentModel(\n editor: IStandaloneEditor,\n apiName: string,\n callback: (tableModel: ContentModelTable) => void,\n selectionOverride?: TableSelection\n) {\n editor.formatContentModel(\n model => {\n const [tableModel, path] = getFirstSelectedTable(model);\n\n if (tableModel) {\n callback(tableModel);\n\n if (!hasSelectionInBlock(tableModel)) {\n const paragraph = ensureFocusableParagraphForTable(model, path, tableModel);\n\n if (paragraph) {\n const marker = createSelectionMarker(model.format);\n\n paragraph.segments.unshift(marker);\n setParagraphNotImplicit(paragraph);\n setSelection(model, marker);\n }\n }\n\n normalizeTable(tableModel, model.format);\n\n if (hasMetadata(tableModel)) {\n applyTableFormat(tableModel, undefined /*newFormat*/, true /*keepCellShade*/);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName,\n selectionOverride,\n }\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
"description": "Content Model for roosterjs (Under development)",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.1",
|
|
6
|
-
"roosterjs-content-model-core": "^0.
|
|
7
|
-
"roosterjs-content-model-dom": "^0.
|
|
8
|
-
"roosterjs-content-model-types": "^0.
|
|
6
|
+
"roosterjs-content-model-core": "^0.26.1",
|
|
7
|
+
"roosterjs-content-model-dom": "^0.26.1",
|
|
8
|
+
"roosterjs-content-model-types": "^0.26.1"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.26.1",
|
|
11
11
|
"main": "./lib/index.js",
|
|
12
12
|
"typings": "./lib/index.d.ts",
|
|
13
13
|
"module": "./lib-mjs/index.js",
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ContentModelFormatState, ContentModelDocument, ContentModelSegmentFormat } from 'roosterjs-content-model-types';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export declare function retrieveModelFormatState(model: ContentModelDocument, pendingFormat: ContentModelSegmentFormat | null, formatState: ContentModelFormatState): void;
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.retrieveModelFormatState = void 0;
|
|
4
|
-
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
|
-
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
function retrieveModelFormatState(model, pendingFormat, formatState) {
|
|
10
|
-
var firstTableContext;
|
|
11
|
-
var firstBlock;
|
|
12
|
-
var isFirst = true;
|
|
13
|
-
var isFirstImage = true;
|
|
14
|
-
var isFirstSegment = true;
|
|
15
|
-
(0, roosterjs_content_model_core_1.iterateSelections)(model, function (path, tableContext, block, segments) {
|
|
16
|
-
// Structure formats
|
|
17
|
-
retrieveStructureFormat(formatState, path, isFirst);
|
|
18
|
-
// Multiple line format
|
|
19
|
-
if (block) {
|
|
20
|
-
if (firstBlock) {
|
|
21
|
-
formatState.isMultilineSelection = true;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
firstBlock = block;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if ((block === null || block === void 0 ? void 0 : block.blockType) == 'Paragraph') {
|
|
28
|
-
// Paragraph formats
|
|
29
|
-
retrieveParagraphFormat(formatState, block, isFirst);
|
|
30
|
-
// Segment formats
|
|
31
|
-
segments === null || segments === void 0 ? void 0 : segments.forEach(function (segment) {
|
|
32
|
-
var _a, _b, _c;
|
|
33
|
-
if (isFirstSegment || segment.segmentType != 'SelectionMarker') {
|
|
34
|
-
var modelFormat = Object.assign({}, model.format);
|
|
35
|
-
modelFormat === null || modelFormat === void 0 ? true : delete modelFormat.italic;
|
|
36
|
-
modelFormat === null || modelFormat === void 0 ? true : delete modelFormat.underline;
|
|
37
|
-
modelFormat === null || modelFormat === void 0 ? true : delete modelFormat.fontWeight;
|
|
38
|
-
retrieveSegmentFormat(formatState, isFirst, Object.assign({}, modelFormat, block.format, (_a = block.decorator) === null || _a === void 0 ? void 0 : _a.format, segment.format, (_b = segment.code) === null || _b === void 0 ? void 0 : _b.format, (_c = segment.link) === null || _c === void 0 ? void 0 : _c.format, pendingFormat));
|
|
39
|
-
mergeValue(formatState, 'isCodeInline', !!(segment === null || segment === void 0 ? void 0 : segment.code), isFirst);
|
|
40
|
-
}
|
|
41
|
-
// We only care the format of selection marker when it is the first selected segment. This is because when selection marker
|
|
42
|
-
// is after some other selected segments, it mostly like appears at the beginning of a seconde line when the whole first line
|
|
43
|
-
// is selected (e.g. triple-click on a line) then the second selection marker doesn't contain a correct format, so we need to
|
|
44
|
-
// ignore it
|
|
45
|
-
isFirstSegment = false;
|
|
46
|
-
formatState.canUnlink = formatState.canUnlink || !!segment.link;
|
|
47
|
-
formatState.canAddImageAltText =
|
|
48
|
-
formatState.canAddImageAltText ||
|
|
49
|
-
segments.some(function (segment) { return segment.segmentType == 'Image'; });
|
|
50
|
-
isFirst = false;
|
|
51
|
-
if (segment.segmentType === 'Image') {
|
|
52
|
-
if (isFirstImage) {
|
|
53
|
-
retrieveImageFormat(segment, formatState);
|
|
54
|
-
isFirstImage = false;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
formatState.imageFormat = undefined;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
isFirst = false;
|
|
62
|
-
}
|
|
63
|
-
if (tableContext) {
|
|
64
|
-
if (firstTableContext) {
|
|
65
|
-
var table = firstTableContext.table, colIndex = firstTableContext.colIndex, rowIndex = firstTableContext.rowIndex;
|
|
66
|
-
// Merge table format
|
|
67
|
-
if (tableContext.table == table &&
|
|
68
|
-
(tableContext.colIndex != colIndex || tableContext.rowIndex != rowIndex)) {
|
|
69
|
-
formatState.canMergeTableCell = true;
|
|
70
|
-
formatState.isMultilineSelection = true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// Table formats
|
|
75
|
-
retrieveTableFormat(tableContext, formatState);
|
|
76
|
-
firstTableContext = tableContext;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}, {
|
|
80
|
-
includeListFormatHolder: 'never',
|
|
81
|
-
});
|
|
82
|
-
if (formatState.fontSize) {
|
|
83
|
-
formatState.fontSize = px2Pt(formatState.fontSize);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.retrieveModelFormatState = retrieveModelFormatState;
|
|
87
|
-
function retrieveSegmentFormat(result, isFirst, mergedFormat) {
|
|
88
|
-
var _a, _b;
|
|
89
|
-
var superOrSubscript = (_b = (_a = mergedFormat.superOrSubScriptSequence) === null || _a === void 0 ? void 0 : _a.split(' ')) === null || _b === void 0 ? void 0 : _b.pop();
|
|
90
|
-
mergeValue(result, 'isBold', (0, roosterjs_content_model_core_1.isBold)(mergedFormat.fontWeight), isFirst);
|
|
91
|
-
mergeValue(result, 'isItalic', mergedFormat.italic, isFirst);
|
|
92
|
-
mergeValue(result, 'isUnderline', mergedFormat.underline, isFirst);
|
|
93
|
-
mergeValue(result, 'isStrikeThrough', mergedFormat.strikethrough, isFirst);
|
|
94
|
-
mergeValue(result, 'isSuperscript', superOrSubscript == 'super', isFirst);
|
|
95
|
-
mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);
|
|
96
|
-
mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);
|
|
97
|
-
mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);
|
|
98
|
-
mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst, function (val) { return (0, roosterjs_content_model_dom_1.parseValueWithUnit)(val, undefined, 'pt') + 'pt'; });
|
|
99
|
-
mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);
|
|
100
|
-
mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);
|
|
101
|
-
mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);
|
|
102
|
-
mergeValue(result, 'lineHeight', mergedFormat.lineHeight, isFirst);
|
|
103
|
-
}
|
|
104
|
-
function retrieveParagraphFormat(result, paragraph, isFirst) {
|
|
105
|
-
var _a;
|
|
106
|
-
var headingLevel = parseInt((((_a = paragraph.decorator) === null || _a === void 0 ? void 0 : _a.tagName) || '').substring(1));
|
|
107
|
-
var validHeadingLevel = headingLevel >= 1 && headingLevel <= 6 ? headingLevel : undefined;
|
|
108
|
-
mergeValue(result, 'marginBottom', paragraph.format.marginBottom, isFirst);
|
|
109
|
-
mergeValue(result, 'marginTop', paragraph.format.marginTop, isFirst);
|
|
110
|
-
mergeValue(result, 'headingLevel', validHeadingLevel, isFirst);
|
|
111
|
-
mergeValue(result, 'textAlign', paragraph.format.textAlign, isFirst);
|
|
112
|
-
mergeValue(result, 'direction', paragraph.format.direction, isFirst);
|
|
113
|
-
}
|
|
114
|
-
function retrieveStructureFormat(result, path, isFirst) {
|
|
115
|
-
var _a, _b;
|
|
116
|
-
var listItemIndex = (0, roosterjs_content_model_core_1.getClosestAncestorBlockGroupIndex)(path, ['ListItem'], []);
|
|
117
|
-
var containerIndex = (0, roosterjs_content_model_core_1.getClosestAncestorBlockGroupIndex)(path, ['FormatContainer'], []);
|
|
118
|
-
if (listItemIndex >= 0) {
|
|
119
|
-
var listItem = path[listItemIndex];
|
|
120
|
-
var listType = (_a = listItem === null || listItem === void 0 ? void 0 : listItem.levels[listItem.levels.length - 1]) === null || _a === void 0 ? void 0 : _a.listType;
|
|
121
|
-
mergeValue(result, 'isBullet', listType == 'UL', isFirst);
|
|
122
|
-
mergeValue(result, 'isNumbering', listType == 'OL', isFirst);
|
|
123
|
-
}
|
|
124
|
-
mergeValue(result, 'isBlockQuote', containerIndex >= 0 &&
|
|
125
|
-
((_b = path[containerIndex]) === null || _b === void 0 ? void 0 : _b.tagName) == 'blockquote', isFirst);
|
|
126
|
-
}
|
|
127
|
-
function retrieveTableFormat(tableContext, result) {
|
|
128
|
-
var tableFormat = (0, roosterjs_content_model_core_1.updateTableMetadata)(tableContext.table);
|
|
129
|
-
result.isInTable = true;
|
|
130
|
-
result.tableHasHeader = tableContext.table.rows.some(function (row) {
|
|
131
|
-
return row.cells.some(function (cell) { return cell.isHeader; });
|
|
132
|
-
});
|
|
133
|
-
if (tableFormat) {
|
|
134
|
-
result.tableFormat = tableFormat;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function retrieveImageFormat(image, result) {
|
|
138
|
-
var format = image.format;
|
|
139
|
-
var borderKey = 'borderTop';
|
|
140
|
-
var extractedBorder = (0, roosterjs_content_model_core_1.extractBorderValues)(format[borderKey]);
|
|
141
|
-
var borderColor = extractedBorder.color;
|
|
142
|
-
var borderWidth = extractedBorder.width;
|
|
143
|
-
var borderStyle = extractedBorder.style;
|
|
144
|
-
result.imageFormat = {
|
|
145
|
-
borderColor: borderColor,
|
|
146
|
-
borderWidth: borderWidth,
|
|
147
|
-
borderStyle: borderStyle,
|
|
148
|
-
boxShadow: format.boxShadow,
|
|
149
|
-
borderRadius: format.borderRadius,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function mergeValue(format, key, newValue, isFirst, parseFn) {
|
|
153
|
-
if (parseFn === void 0) { parseFn = function (val) { return val; }; }
|
|
154
|
-
if (isFirst) {
|
|
155
|
-
if (newValue !== undefined) {
|
|
156
|
-
format[key] = newValue;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
else if (parseFn(newValue) !== parseFn(format[key])) {
|
|
160
|
-
delete format[key];
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
function px2Pt(px) {
|
|
164
|
-
if (px && px.indexOf('px') == px.length - 2) {
|
|
165
|
-
// Edge may not handle the floating computing well which causes the calculated value is a little less than actual value
|
|
166
|
-
// So add 0.05 to fix it
|
|
167
|
-
return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';
|
|
168
|
-
}
|
|
169
|
-
return px;
|
|
170
|
-
}
|
|
171
|
-
//# sourceMappingURL=retrieveModelFormatState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retrieveModelFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/common/retrieveModelFormatState.ts"],"names":[],"mappings":";;;AAAA,2EAAiE;AACjE,6EAMsC;AActC;;GAEG;AACH,SAAgB,wBAAwB,CACpC,KAA2B,EAC3B,aAA+C,EAC/C,WAAoC;IAEpC,IAAI,iBAAoD,CAAC;IACzD,IAAI,UAAyC,CAAC;IAC9C,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,IAAI,cAAc,GAAG,IAAI,CAAC;IAE1B,IAAA,gDAAiB,EACb,KAAK,EACL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AwB;QACxB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;KAC9D;IACD,OAAO,EAAE,CAAC;AACd,CAAC","sourcesContent":["import { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getClosestAncestorBlockGroupIndex,\n isBold,\n iterateSelections,\n updateTableMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n ContentModelFormatState,\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelImage,\n ContentModelListItem,\n ContentModelParagraph,\n ContentModelSegmentFormat,\n TableSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function retrieveModelFormatState(\n model: ContentModelDocument,\n pendingFormat: ContentModelSegmentFormat | null,\n formatState: ContentModelFormatState\n) {\n let firstTableContext: TableSelectionContext | undefined;\n let firstBlock: ContentModelBlock | undefined;\n let isFirst = true;\n let isFirstImage = true;\n let isFirstSegment = true;\n\n iterateSelections(\n model,\n (path, tableContext, block, segments) => {\n // Structure formats\n retrieveStructureFormat(formatState, path, isFirst);\n\n // Multiple line format\n if (block) {\n if (firstBlock) {\n formatState.isMultilineSelection = true;\n } else {\n firstBlock = block;\n }\n }\n\n if (block?.blockType == 'Paragraph') {\n // Paragraph formats\n retrieveParagraphFormat(formatState, block, isFirst);\n\n // Segment formats\n segments?.forEach(segment => {\n if (isFirstSegment || segment.segmentType != 'SelectionMarker') {\n const modelFormat = Object.assign({}, model.format);\n delete modelFormat?.italic;\n delete modelFormat?.underline;\n delete modelFormat?.fontWeight;\n\n retrieveSegmentFormat(\n formatState,\n isFirst,\n Object.assign(\n {},\n modelFormat,\n block.format,\n block.decorator?.format,\n segment.format,\n segment.code?.format,\n segment.link?.format,\n pendingFormat\n )\n );\n\n mergeValue(formatState, 'isCodeInline', !!segment?.code, isFirst);\n }\n\n // We only care the format of selection marker when it is the first selected segment. This is because when selection marker\n // is after some other selected segments, it mostly like appears at the beginning of a seconde line when the whole first line\n // is selected (e.g. triple-click on a line) then the second selection marker doesn't contain a correct format, so we need to\n // ignore it\n isFirstSegment = false;\n\n formatState.canUnlink = formatState.canUnlink || !!segment.link;\n formatState.canAddImageAltText =\n formatState.canAddImageAltText ||\n segments.some(segment => segment.segmentType == 'Image');\n\n isFirst = false;\n\n if (segment.segmentType === 'Image') {\n if (isFirstImage) {\n retrieveImageFormat(segment, formatState);\n isFirstImage = false;\n } else {\n formatState.imageFormat = undefined;\n }\n }\n });\n\n isFirst = false;\n }\n\n if (tableContext) {\n if (firstTableContext) {\n const { table, colIndex, rowIndex } = firstTableContext;\n\n // Merge table format\n if (\n tableContext.table == table &&\n (tableContext.colIndex != colIndex || tableContext.rowIndex != rowIndex)\n ) {\n formatState.canMergeTableCell = true;\n formatState.isMultilineSelection = true;\n }\n } else {\n // Table formats\n retrieveTableFormat(tableContext, formatState);\n firstTableContext = tableContext;\n }\n }\n },\n {\n includeListFormatHolder: 'never',\n }\n );\n\n if (formatState.fontSize) {\n formatState.fontSize = px2Pt(formatState.fontSize);\n }\n}\n\nfunction retrieveSegmentFormat(\n result: ContentModelFormatState,\n isFirst: boolean,\n mergedFormat: ContentModelSegmentFormat\n) {\n const superOrSubscript = mergedFormat.superOrSubScriptSequence?.split(' ')?.pop();\n\n mergeValue(result, 'isBold', isBold(mergedFormat.fontWeight), isFirst);\n mergeValue(result, 'isItalic', mergedFormat.italic, isFirst);\n mergeValue(result, 'isUnderline', mergedFormat.underline, isFirst);\n mergeValue(result, 'isStrikeThrough', mergedFormat.strikethrough, isFirst);\n mergeValue(result, 'isSuperscript', superOrSubscript == 'super', isFirst);\n mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);\n mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);\n\n mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);\n mergeValue(\n result,\n 'fontSize',\n mergedFormat.fontSize,\n isFirst,\n val => parseValueWithUnit(val, undefined, 'pt') + 'pt'\n );\n mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);\n mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);\n mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);\n mergeValue(result, 'lineHeight', mergedFormat.lineHeight, isFirst);\n}\n\nfunction retrieveParagraphFormat(\n result: ContentModelFormatState,\n paragraph: ContentModelParagraph,\n isFirst: boolean\n) {\n const headingLevel = parseInt((paragraph.decorator?.tagName || '').substring(1));\n const validHeadingLevel = headingLevel >= 1 && headingLevel <= 6 ? headingLevel : undefined;\n\n mergeValue(result, 'marginBottom', paragraph.format.marginBottom, isFirst);\n mergeValue(result, 'marginTop', paragraph.format.marginTop, isFirst);\n mergeValue(result, 'headingLevel', validHeadingLevel, isFirst);\n mergeValue(result, 'textAlign', paragraph.format.textAlign, isFirst);\n mergeValue(result, 'direction', paragraph.format.direction, isFirst);\n}\n\nfunction retrieveStructureFormat(\n result: ContentModelFormatState,\n path: ContentModelBlockGroup[],\n isFirst: boolean\n) {\n const listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem'], []);\n const containerIndex = getClosestAncestorBlockGroupIndex(path, ['FormatContainer'], []);\n\n if (listItemIndex >= 0) {\n const listItem = path[listItemIndex] as ContentModelListItem;\n const listType = listItem?.levels[listItem.levels.length - 1]?.listType;\n\n mergeValue(result, 'isBullet', listType == 'UL', isFirst);\n mergeValue(result, 'isNumbering', listType == 'OL', isFirst);\n }\n\n mergeValue(\n result,\n 'isBlockQuote',\n containerIndex >= 0 &&\n (path[containerIndex] as ContentModelFormatContainer)?.tagName == 'blockquote',\n isFirst\n );\n}\n\nfunction retrieveTableFormat(tableContext: TableSelectionContext, result: ContentModelFormatState) {\n const tableFormat = updateTableMetadata(tableContext.table);\n\n result.isInTable = true;\n result.tableHasHeader = tableContext.table.rows.some(row =>\n row.cells.some(cell => cell.isHeader)\n );\n\n if (tableFormat) {\n result.tableFormat = tableFormat;\n }\n}\n\nfunction retrieveImageFormat(image: ContentModelImage, result: ContentModelFormatState) {\n const { format } = image;\n const borderKey = 'borderTop';\n const extractedBorder = extractBorderValues(format[borderKey]);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n result.imageFormat = {\n borderColor,\n borderWidth,\n borderStyle,\n boxShadow: format.boxShadow,\n borderRadius: format.borderRadius,\n };\n}\n\nfunction mergeValue<K extends keyof ContentModelFormatState>(\n format: ContentModelFormatState,\n key: K,\n newValue: ContentModelFormatState[K] | undefined,\n isFirst: boolean,\n parseFn: (val: ContentModelFormatState[K]) => ContentModelFormatState[K] = val => val\n) {\n if (isFirst) {\n if (newValue !== undefined) {\n format[key] = newValue;\n }\n } else if (parseFn(newValue) !== parseFn(format[key])) {\n delete format[key];\n }\n}\n\nfunction px2Pt(px: string) {\n if (px && px.indexOf('px') == px.length - 2) {\n // Edge may not handle the floating computing well which causes the calculated value is a little less than actual value\n // So add 0.05 to fix it\n return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';\n }\n return px;\n}\n"]}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ContentModelFormatState, ContentModelDocument, ContentModelSegmentFormat } from 'roosterjs-content-model-types';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export declare function retrieveModelFormatState(model: ContentModelDocument, pendingFormat: ContentModelSegmentFormat | null, formatState: ContentModelFormatState): void;
|
|
@@ -1,171 +0,0 @@
|
|
|
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) {
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.retrieveModelFormatState = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
function retrieveModelFormatState(model, pendingFormat, formatState) {
|
|
9
|
-
var firstTableContext;
|
|
10
|
-
var firstBlock;
|
|
11
|
-
var isFirst = true;
|
|
12
|
-
var isFirstImage = true;
|
|
13
|
-
var isFirstSegment = true;
|
|
14
|
-
(0, roosterjs_content_model_core_1.iterateSelections)(model, function (path, tableContext, block, segments) {
|
|
15
|
-
// Structure formats
|
|
16
|
-
retrieveStructureFormat(formatState, path, isFirst);
|
|
17
|
-
// Multiple line format
|
|
18
|
-
if (block) {
|
|
19
|
-
if (firstBlock) {
|
|
20
|
-
formatState.isMultilineSelection = true;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
firstBlock = block;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if ((block === null || block === void 0 ? void 0 : block.blockType) == 'Paragraph') {
|
|
27
|
-
// Paragraph formats
|
|
28
|
-
retrieveParagraphFormat(formatState, block, isFirst);
|
|
29
|
-
// Segment formats
|
|
30
|
-
segments === null || segments === void 0 ? void 0 : segments.forEach(function (segment) {
|
|
31
|
-
var _a, _b, _c;
|
|
32
|
-
if (isFirstSegment || segment.segmentType != 'SelectionMarker') {
|
|
33
|
-
var modelFormat = Object.assign({}, model.format);
|
|
34
|
-
modelFormat === null || modelFormat === void 0 ? true : delete modelFormat.italic;
|
|
35
|
-
modelFormat === null || modelFormat === void 0 ? true : delete modelFormat.underline;
|
|
36
|
-
modelFormat === null || modelFormat === void 0 ? true : delete modelFormat.fontWeight;
|
|
37
|
-
retrieveSegmentFormat(formatState, isFirst, Object.assign({}, modelFormat, block.format, (_a = block.decorator) === null || _a === void 0 ? void 0 : _a.format, segment.format, (_b = segment.code) === null || _b === void 0 ? void 0 : _b.format, (_c = segment.link) === null || _c === void 0 ? void 0 : _c.format, pendingFormat));
|
|
38
|
-
mergeValue(formatState, 'isCodeInline', !!(segment === null || segment === void 0 ? void 0 : segment.code), isFirst);
|
|
39
|
-
}
|
|
40
|
-
// We only care the format of selection marker when it is the first selected segment. This is because when selection marker
|
|
41
|
-
// is after some other selected segments, it mostly like appears at the beginning of a seconde line when the whole first line
|
|
42
|
-
// is selected (e.g. triple-click on a line) then the second selection marker doesn't contain a correct format, so we need to
|
|
43
|
-
// ignore it
|
|
44
|
-
isFirstSegment = false;
|
|
45
|
-
formatState.canUnlink = formatState.canUnlink || !!segment.link;
|
|
46
|
-
formatState.canAddImageAltText =
|
|
47
|
-
formatState.canAddImageAltText ||
|
|
48
|
-
segments.some(function (segment) { return segment.segmentType == 'Image'; });
|
|
49
|
-
isFirst = false;
|
|
50
|
-
if (segment.segmentType === 'Image') {
|
|
51
|
-
if (isFirstImage) {
|
|
52
|
-
retrieveImageFormat(segment, formatState);
|
|
53
|
-
isFirstImage = false;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
formatState.imageFormat = undefined;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
isFirst = false;
|
|
61
|
-
}
|
|
62
|
-
if (tableContext) {
|
|
63
|
-
if (firstTableContext) {
|
|
64
|
-
var table = firstTableContext.table, colIndex = firstTableContext.colIndex, rowIndex = firstTableContext.rowIndex;
|
|
65
|
-
// Merge table format
|
|
66
|
-
if (tableContext.table == table &&
|
|
67
|
-
(tableContext.colIndex != colIndex || tableContext.rowIndex != rowIndex)) {
|
|
68
|
-
formatState.canMergeTableCell = true;
|
|
69
|
-
formatState.isMultilineSelection = true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
// Table formats
|
|
74
|
-
retrieveTableFormat(tableContext, formatState);
|
|
75
|
-
firstTableContext = tableContext;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}, {
|
|
79
|
-
includeListFormatHolder: 'never',
|
|
80
|
-
});
|
|
81
|
-
if (formatState.fontSize) {
|
|
82
|
-
formatState.fontSize = px2Pt(formatState.fontSize);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.retrieveModelFormatState = retrieveModelFormatState;
|
|
86
|
-
function retrieveSegmentFormat(result, isFirst, mergedFormat) {
|
|
87
|
-
var _a, _b;
|
|
88
|
-
var superOrSubscript = (_b = (_a = mergedFormat.superOrSubScriptSequence) === null || _a === void 0 ? void 0 : _a.split(' ')) === null || _b === void 0 ? void 0 : _b.pop();
|
|
89
|
-
mergeValue(result, 'isBold', (0, roosterjs_content_model_core_1.isBold)(mergedFormat.fontWeight), isFirst);
|
|
90
|
-
mergeValue(result, 'isItalic', mergedFormat.italic, isFirst);
|
|
91
|
-
mergeValue(result, 'isUnderline', mergedFormat.underline, isFirst);
|
|
92
|
-
mergeValue(result, 'isStrikeThrough', mergedFormat.strikethrough, isFirst);
|
|
93
|
-
mergeValue(result, 'isSuperscript', superOrSubscript == 'super', isFirst);
|
|
94
|
-
mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);
|
|
95
|
-
mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);
|
|
96
|
-
mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);
|
|
97
|
-
mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst, function (val) { return (0, roosterjs_content_model_dom_1.parseValueWithUnit)(val, undefined, 'pt') + 'pt'; });
|
|
98
|
-
mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);
|
|
99
|
-
mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);
|
|
100
|
-
mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);
|
|
101
|
-
mergeValue(result, 'lineHeight', mergedFormat.lineHeight, isFirst);
|
|
102
|
-
}
|
|
103
|
-
function retrieveParagraphFormat(result, paragraph, isFirst) {
|
|
104
|
-
var _a;
|
|
105
|
-
var headingLevel = parseInt((((_a = paragraph.decorator) === null || _a === void 0 ? void 0 : _a.tagName) || '').substring(1));
|
|
106
|
-
var validHeadingLevel = headingLevel >= 1 && headingLevel <= 6 ? headingLevel : undefined;
|
|
107
|
-
mergeValue(result, 'marginBottom', paragraph.format.marginBottom, isFirst);
|
|
108
|
-
mergeValue(result, 'marginTop', paragraph.format.marginTop, isFirst);
|
|
109
|
-
mergeValue(result, 'headingLevel', validHeadingLevel, isFirst);
|
|
110
|
-
mergeValue(result, 'textAlign', paragraph.format.textAlign, isFirst);
|
|
111
|
-
mergeValue(result, 'direction', paragraph.format.direction, isFirst);
|
|
112
|
-
}
|
|
113
|
-
function retrieveStructureFormat(result, path, isFirst) {
|
|
114
|
-
var _a, _b;
|
|
115
|
-
var listItemIndex = (0, roosterjs_content_model_core_1.getClosestAncestorBlockGroupIndex)(path, ['ListItem'], []);
|
|
116
|
-
var containerIndex = (0, roosterjs_content_model_core_1.getClosestAncestorBlockGroupIndex)(path, ['FormatContainer'], []);
|
|
117
|
-
if (listItemIndex >= 0) {
|
|
118
|
-
var listItem = path[listItemIndex];
|
|
119
|
-
var listType = (_a = listItem === null || listItem === void 0 ? void 0 : listItem.levels[listItem.levels.length - 1]) === null || _a === void 0 ? void 0 : _a.listType;
|
|
120
|
-
mergeValue(result, 'isBullet', listType == 'UL', isFirst);
|
|
121
|
-
mergeValue(result, 'isNumbering', listType == 'OL', isFirst);
|
|
122
|
-
}
|
|
123
|
-
mergeValue(result, 'isBlockQuote', containerIndex >= 0 &&
|
|
124
|
-
((_b = path[containerIndex]) === null || _b === void 0 ? void 0 : _b.tagName) == 'blockquote', isFirst);
|
|
125
|
-
}
|
|
126
|
-
function retrieveTableFormat(tableContext, result) {
|
|
127
|
-
var tableFormat = (0, roosterjs_content_model_core_1.updateTableMetadata)(tableContext.table);
|
|
128
|
-
result.isInTable = true;
|
|
129
|
-
result.tableHasHeader = tableContext.table.rows.some(function (row) {
|
|
130
|
-
return row.cells.some(function (cell) { return cell.isHeader; });
|
|
131
|
-
});
|
|
132
|
-
if (tableFormat) {
|
|
133
|
-
result.tableFormat = tableFormat;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function retrieveImageFormat(image, result) {
|
|
137
|
-
var format = image.format;
|
|
138
|
-
var borderKey = 'borderTop';
|
|
139
|
-
var extractedBorder = (0, roosterjs_content_model_core_1.extractBorderValues)(format[borderKey]);
|
|
140
|
-
var borderColor = extractedBorder.color;
|
|
141
|
-
var borderWidth = extractedBorder.width;
|
|
142
|
-
var borderStyle = extractedBorder.style;
|
|
143
|
-
result.imageFormat = {
|
|
144
|
-
borderColor: borderColor,
|
|
145
|
-
borderWidth: borderWidth,
|
|
146
|
-
borderStyle: borderStyle,
|
|
147
|
-
boxShadow: format.boxShadow,
|
|
148
|
-
borderRadius: format.borderRadius,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function mergeValue(format, key, newValue, isFirst, parseFn) {
|
|
152
|
-
if (parseFn === void 0) { parseFn = function (val) { return val; }; }
|
|
153
|
-
if (isFirst) {
|
|
154
|
-
if (newValue !== undefined) {
|
|
155
|
-
format[key] = newValue;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else if (parseFn(newValue) !== parseFn(format[key])) {
|
|
159
|
-
delete format[key];
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function px2Pt(px) {
|
|
163
|
-
if (px && px.indexOf('px') == px.length - 2) {
|
|
164
|
-
// Edge may not handle the floating computing well which causes the calculated value is a little less than actual value
|
|
165
|
-
// So add 0.05 to fix it
|
|
166
|
-
return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';
|
|
167
|
-
}
|
|
168
|
-
return px;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
//# sourceMappingURL=retrieveModelFormatState.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retrieveModelFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/common/retrieveModelFormatState.ts"],"names":[],"mappings":";;;;IAqBA;;OAEG;IACH,SAAgB,wBAAwB,CACpC,KAA2B,EAC3B,aAA+C,EAC/C,WAAoC;QAEpC,IAAI,iBA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,CAAC,GAAG,CAAC,CAAC;SACtB;IACL,CAAC;IAED,SAAS,KAAK,CAAC,EAAU;QACrB,IAAI,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE;YACzC,uHAAuH;YACvH,wBAAwB;YACxB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;SAC9D;QACD,OAAO,EAAE,CAAC;IACd,CAAC","sourcesContent":["import { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getClosestAncestorBlockGroupIndex,\n isBold,\n iterateSelections,\n updateTableMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n ContentModelFormatState,\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelImage,\n ContentModelListItem,\n ContentModelParagraph,\n ContentModelSegmentFormat,\n TableSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function retrieveModelFormatState(\n model: ContentModelDocument,\n pendingFormat: ContentModelSegmentFormat | null,\n formatState: ContentModelFormatState\n) {\n let firstTableContext: TableSelectionContext | undefined;\n let firstBlock: ContentModelBlock | undefined;\n let isFirst = true;\n let isFirstImage = true;\n let isFirstSegment = true;\n\n iterateSelections(\n model,\n (path, tableContext, block, segments) => {\n // Structure formats\n retrieveStructureFormat(formatState, path, isFirst);\n\n // Multiple line format\n if (block) {\n if (firstBlock) {\n formatState.isMultilineSelection = true;\n } else {\n firstBlock = block;\n }\n }\n\n if (block?.blockType == 'Paragraph') {\n // Paragraph formats\n retrieveParagraphFormat(formatState, block, isFirst);\n\n // Segment formats\n segments?.forEach(segment => {\n if (isFirstSegment || segment.segmentType != 'SelectionMarker') {\n const modelFormat = Object.assign({}, model.format);\n delete modelFormat?.italic;\n delete modelFormat?.underline;\n delete modelFormat?.fontWeight;\n\n retrieveSegmentFormat(\n formatState,\n isFirst,\n Object.assign(\n {},\n modelFormat,\n block.format,\n block.decorator?.format,\n segment.format,\n segment.code?.format,\n segment.link?.format,\n pendingFormat\n )\n );\n\n mergeValue(formatState, 'isCodeInline', !!segment?.code, isFirst);\n }\n\n // We only care the format of selection marker when it is the first selected segment. This is because when selection marker\n // is after some other selected segments, it mostly like appears at the beginning of a seconde line when the whole first line\n // is selected (e.g. triple-click on a line) then the second selection marker doesn't contain a correct format, so we need to\n // ignore it\n isFirstSegment = false;\n\n formatState.canUnlink = formatState.canUnlink || !!segment.link;\n formatState.canAddImageAltText =\n formatState.canAddImageAltText ||\n segments.some(segment => segment.segmentType == 'Image');\n\n isFirst = false;\n\n if (segment.segmentType === 'Image') {\n if (isFirstImage) {\n retrieveImageFormat(segment, formatState);\n isFirstImage = false;\n } else {\n formatState.imageFormat = undefined;\n }\n }\n });\n\n isFirst = false;\n }\n\n if (tableContext) {\n if (firstTableContext) {\n const { table, colIndex, rowIndex } = firstTableContext;\n\n // Merge table format\n if (\n tableContext.table == table &&\n (tableContext.colIndex != colIndex || tableContext.rowIndex != rowIndex)\n ) {\n formatState.canMergeTableCell = true;\n formatState.isMultilineSelection = true;\n }\n } else {\n // Table formats\n retrieveTableFormat(tableContext, formatState);\n firstTableContext = tableContext;\n }\n }\n },\n {\n includeListFormatHolder: 'never',\n }\n );\n\n if (formatState.fontSize) {\n formatState.fontSize = px2Pt(formatState.fontSize);\n }\n}\n\nfunction retrieveSegmentFormat(\n result: ContentModelFormatState,\n isFirst: boolean,\n mergedFormat: ContentModelSegmentFormat\n) {\n const superOrSubscript = mergedFormat.superOrSubScriptSequence?.split(' ')?.pop();\n\n mergeValue(result, 'isBold', isBold(mergedFormat.fontWeight), isFirst);\n mergeValue(result, 'isItalic', mergedFormat.italic, isFirst);\n mergeValue(result, 'isUnderline', mergedFormat.underline, isFirst);\n mergeValue(result, 'isStrikeThrough', mergedFormat.strikethrough, isFirst);\n mergeValue(result, 'isSuperscript', superOrSubscript == 'super', isFirst);\n mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);\n mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);\n\n mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);\n mergeValue(\n result,\n 'fontSize',\n mergedFormat.fontSize,\n isFirst,\n val => parseValueWithUnit(val, undefined, 'pt') + 'pt'\n );\n mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);\n mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);\n mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);\n mergeValue(result, 'lineHeight', mergedFormat.lineHeight, isFirst);\n}\n\nfunction retrieveParagraphFormat(\n result: ContentModelFormatState,\n paragraph: ContentModelParagraph,\n isFirst: boolean\n) {\n const headingLevel = parseInt((paragraph.decorator?.tagName || '').substring(1));\n const validHeadingLevel = headingLevel >= 1 && headingLevel <= 6 ? headingLevel : undefined;\n\n mergeValue(result, 'marginBottom', paragraph.format.marginBottom, isFirst);\n mergeValue(result, 'marginTop', paragraph.format.marginTop, isFirst);\n mergeValue(result, 'headingLevel', validHeadingLevel, isFirst);\n mergeValue(result, 'textAlign', paragraph.format.textAlign, isFirst);\n mergeValue(result, 'direction', paragraph.format.direction, isFirst);\n}\n\nfunction retrieveStructureFormat(\n result: ContentModelFormatState,\n path: ContentModelBlockGroup[],\n isFirst: boolean\n) {\n const listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem'], []);\n const containerIndex = getClosestAncestorBlockGroupIndex(path, ['FormatContainer'], []);\n\n if (listItemIndex >= 0) {\n const listItem = path[listItemIndex] as ContentModelListItem;\n const listType = listItem?.levels[listItem.levels.length - 1]?.listType;\n\n mergeValue(result, 'isBullet', listType == 'UL', isFirst);\n mergeValue(result, 'isNumbering', listType == 'OL', isFirst);\n }\n\n mergeValue(\n result,\n 'isBlockQuote',\n containerIndex >= 0 &&\n (path[containerIndex] as ContentModelFormatContainer)?.tagName == 'blockquote',\n isFirst\n );\n}\n\nfunction retrieveTableFormat(tableContext: TableSelectionContext, result: ContentModelFormatState) {\n const tableFormat = updateTableMetadata(tableContext.table);\n\n result.isInTable = true;\n result.tableHasHeader = tableContext.table.rows.some(row =>\n row.cells.some(cell => cell.isHeader)\n );\n\n if (tableFormat) {\n result.tableFormat = tableFormat;\n }\n}\n\nfunction retrieveImageFormat(image: ContentModelImage, result: ContentModelFormatState) {\n const { format } = image;\n const borderKey = 'borderTop';\n const extractedBorder = extractBorderValues(format[borderKey]);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n result.imageFormat = {\n borderColor,\n borderWidth,\n borderStyle,\n boxShadow: format.boxShadow,\n borderRadius: format.borderRadius,\n };\n}\n\nfunction mergeValue<K extends keyof ContentModelFormatState>(\n format: ContentModelFormatState,\n key: K,\n newValue: ContentModelFormatState[K] | undefined,\n isFirst: boolean,\n parseFn: (val: ContentModelFormatState[K]) => ContentModelFormatState[K] = val => val\n) {\n if (isFirst) {\n if (newValue !== undefined) {\n format[key] = newValue;\n }\n } else if (parseFn(newValue) !== parseFn(format[key])) {\n delete format[key];\n }\n}\n\nfunction px2Pt(px: string) {\n if (px && px.indexOf('px') == px.length - 2) {\n // Edge may not handle the floating computing well which causes the calculated value is a little less than actual value\n // So add 0.05 to fix it\n return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';\n }\n return px;\n}\n"]}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ContentModelFormatState, ContentModelDocument, ContentModelSegmentFormat } from 'roosterjs-content-model-types';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export declare function retrieveModelFormatState(model: ContentModelDocument, pendingFormat: ContentModelSegmentFormat | null, formatState: ContentModelFormatState): void;
|