roosterjs-content-model-api 0.21.2 → 0.22.0
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 +0 -3
- package/lib/index.js +1 -7
- package/lib/index.js.map +1 -1
- package/lib/modelApi/list/setListType.js +25 -0
- package/lib/modelApi/list/setListType.js.map +1 -1
- package/lib/modelApi/selection/collapseTableSelection.d.ts +1 -2
- package/lib/modelApi/selection/collapseTableSelection.js +2 -2
- package/lib/modelApi/selection/collapseTableSelection.js.map +1 -1
- package/lib/modelApi/table/alignTableCell.js +2 -3
- package/lib/modelApi/table/alignTableCell.js.map +1 -1
- package/lib/modelApi/table/deleteTableColumn.js +6 -6
- package/lib/modelApi/table/deleteTableColumn.js.map +1 -1
- package/lib/modelApi/table/deleteTableRow.js +2 -2
- package/lib/modelApi/table/deleteTableRow.js.map +1 -1
- package/lib/modelApi/table/insertTableColumn.js +6 -6
- package/lib/modelApi/table/insertTableColumn.js.map +1 -1
- package/lib/modelApi/table/insertTableRow.js +3 -3
- package/lib/modelApi/table/insertTableRow.js.map +1 -1
- package/lib/modelApi/table/mergeTableCells.js +6 -5
- package/lib/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib/modelApi/table/mergeTableColumn.js +3 -3
- package/lib/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib/modelApi/table/mergeTableRow.js +3 -3
- package/lib/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib/modelApi/table/splitTableCellHorizontally.js +3 -3
- package/lib/modelApi/table/splitTableCellHorizontally.js.map +1 -1
- package/lib/modelApi/table/splitTableCellVertically.js +7 -5
- package/lib/modelApi/table/splitTableCellVertically.js.map +1 -1
- package/lib/publicApi/format/getFormatState.js +7 -1
- package/lib/publicApi/format/getFormatState.js.map +1 -1
- package/lib/publicApi/image/changeImage.js +1 -2
- package/lib/publicApi/image/changeImage.js.map +1 -1
- package/lib/publicApi/image/insertImage.js +1 -2
- package/lib/publicApi/image/insertImage.js.map +1 -1
- package/lib/publicApi/table/applyTableBorderFormat.js +29 -30
- package/lib/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib/publicApi/table/editTable.js +1 -2
- package/lib/publicApi/table/editTable.js.map +1 -1
- package/lib/publicApi/table/setTableCellShade.js +1 -2
- package/lib/publicApi/table/setTableCellShade.js.map +1 -1
- package/lib-amd/index.d.ts +0 -3
- package/lib-amd/index.js +2 -5
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/modelApi/list/setListType.js +25 -0
- package/lib-amd/modelApi/list/setListType.js.map +1 -1
- package/lib-amd/modelApi/selection/collapseTableSelection.d.ts +1 -2
- package/lib-amd/modelApi/selection/collapseTableSelection.js +2 -2
- package/lib-amd/modelApi/selection/collapseTableSelection.js.map +1 -1
- package/lib-amd/modelApi/table/alignTableCell.js +3 -3
- package/lib-amd/modelApi/table/alignTableCell.js.map +1 -1
- package/lib-amd/modelApi/table/deleteTableColumn.js +6 -6
- package/lib-amd/modelApi/table/deleteTableColumn.js.map +1 -1
- package/lib-amd/modelApi/table/deleteTableRow.js +2 -2
- package/lib-amd/modelApi/table/deleteTableRow.js.map +1 -1
- package/lib-amd/modelApi/table/insertTableColumn.js +6 -6
- package/lib-amd/modelApi/table/insertTableColumn.js.map +1 -1
- package/lib-amd/modelApi/table/insertTableRow.js +3 -3
- package/lib-amd/modelApi/table/insertTableRow.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableCells.js +6 -5
- package/lib-amd/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableColumn.js +3 -3
- package/lib-amd/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableRow.js +3 -3
- package/lib-amd/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib-amd/modelApi/table/splitTableCellHorizontally.js +3 -3
- package/lib-amd/modelApi/table/splitTableCellHorizontally.js.map +1 -1
- package/lib-amd/modelApi/table/splitTableCellVertically.js +7 -5
- package/lib-amd/modelApi/table/splitTableCellVertically.js.map +1 -1
- package/lib-amd/publicApi/format/getFormatState.js +7 -1
- package/lib-amd/publicApi/format/getFormatState.js.map +1 -1
- package/lib-amd/publicApi/image/changeImage.js +2 -2
- package/lib-amd/publicApi/image/changeImage.js.map +1 -1
- package/lib-amd/publicApi/image/insertImage.js +2 -2
- package/lib-amd/publicApi/image/insertImage.js.map +1 -1
- package/lib-amd/publicApi/table/applyTableBorderFormat.js +30 -30
- package/lib-amd/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib-amd/publicApi/table/editTable.js +2 -2
- package/lib-amd/publicApi/table/editTable.js.map +1 -1
- package/lib-amd/publicApi/table/setTableCellShade.js +2 -2
- package/lib-amd/publicApi/table/setTableCellShade.js.map +1 -1
- package/lib-mjs/index.d.ts +0 -3
- package/lib-mjs/index.js +0 -3
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/modelApi/list/setListType.js +25 -0
- package/lib-mjs/modelApi/list/setListType.js.map +1 -1
- package/lib-mjs/modelApi/selection/collapseTableSelection.d.ts +1 -2
- package/lib-mjs/modelApi/selection/collapseTableSelection.js +2 -2
- package/lib-mjs/modelApi/selection/collapseTableSelection.js.map +1 -1
- package/lib-mjs/modelApi/table/alignTableCell.js +2 -3
- package/lib-mjs/modelApi/table/alignTableCell.js.map +1 -1
- package/lib-mjs/modelApi/table/deleteTableColumn.js +5 -5
- package/lib-mjs/modelApi/table/deleteTableColumn.js.map +1 -1
- package/lib-mjs/modelApi/table/deleteTableRow.js +1 -1
- package/lib-mjs/modelApi/table/deleteTableRow.js.map +1 -1
- package/lib-mjs/modelApi/table/insertTableColumn.js +5 -5
- package/lib-mjs/modelApi/table/insertTableColumn.js.map +1 -1
- package/lib-mjs/modelApi/table/insertTableRow.js +2 -2
- package/lib-mjs/modelApi/table/insertTableRow.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableCells.js +5 -4
- package/lib-mjs/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableColumn.js +2 -2
- package/lib-mjs/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableRow.js +2 -2
- package/lib-mjs/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib-mjs/modelApi/table/splitTableCellHorizontally.js +2 -2
- package/lib-mjs/modelApi/table/splitTableCellHorizontally.js.map +1 -1
- package/lib-mjs/modelApi/table/splitTableCellVertically.js +6 -4
- package/lib-mjs/modelApi/table/splitTableCellVertically.js.map +1 -1
- package/lib-mjs/publicApi/format/getFormatState.js +8 -2
- package/lib-mjs/publicApi/format/getFormatState.js.map +1 -1
- package/lib-mjs/publicApi/image/changeImage.js +1 -2
- package/lib-mjs/publicApi/image/changeImage.js.map +1 -1
- package/lib-mjs/publicApi/image/insertImage.js +1 -2
- package/lib-mjs/publicApi/image/insertImage.js.map +1 -1
- package/lib-mjs/publicApi/table/applyTableBorderFormat.js +29 -30
- package/lib-mjs/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib-mjs/publicApi/table/editTable.js +1 -2
- package/lib-mjs/publicApi/table/editTable.js.map +1 -1
- package/lib-mjs/publicApi/table/setTableCellShade.js +1 -2
- package/lib-mjs/publicApi/table/setTableCellShade.js.map +1 -1
- package/package.json +4 -4
- package/lib/modelApi/domUtils/readFile.d.ts +0 -8
- package/lib/modelApi/domUtils/readFile.js +0 -24
- package/lib/modelApi/domUtils/readFile.js.map +0 -1
- package/lib/modelApi/table/getSelectedCells.d.ts +0 -14
- package/lib/modelApi/table/getSelectedCells.js +0 -32
- package/lib/modelApi/table/getSelectedCells.js.map +0 -1
- package/lib/publicApi/selection/hasSelectionInBlock.d.ts +0 -6
- package/lib/publicApi/selection/hasSelectionInBlock.js +0 -25
- package/lib/publicApi/selection/hasSelectionInBlock.js.map +0 -1
- package/lib/publicApi/selection/hasSelectionInBlockGroup.d.ts +0 -6
- package/lib/publicApi/selection/hasSelectionInBlockGroup.js +0 -18
- package/lib/publicApi/selection/hasSelectionInBlockGroup.js.map +0 -1
- package/lib/publicApi/selection/hasSelectionInSegment.d.ts +0 -6
- package/lib/publicApi/selection/hasSelectionInSegment.js +0 -13
- package/lib/publicApi/selection/hasSelectionInSegment.js.map +0 -1
- package/lib-amd/modelApi/domUtils/readFile.d.ts +0 -8
- package/lib-amd/modelApi/domUtils/readFile.js +0 -26
- package/lib-amd/modelApi/domUtils/readFile.js.map +0 -1
- package/lib-amd/modelApi/table/getSelectedCells.d.ts +0 -14
- package/lib-amd/modelApi/table/getSelectedCells.js +0 -33
- package/lib-amd/modelApi/table/getSelectedCells.js.map +0 -1
- package/lib-amd/publicApi/selection/hasSelectionInBlock.d.ts +0 -6
- package/lib-amd/publicApi/selection/hasSelectionInBlock.js +0 -25
- package/lib-amd/publicApi/selection/hasSelectionInBlock.js.map +0 -1
- package/lib-amd/publicApi/selection/hasSelectionInBlockGroup.d.ts +0 -6
- package/lib-amd/publicApi/selection/hasSelectionInBlockGroup.js +0 -19
- package/lib-amd/publicApi/selection/hasSelectionInBlockGroup.js.map +0 -1
- package/lib-amd/publicApi/selection/hasSelectionInSegment.d.ts +0 -6
- package/lib-amd/publicApi/selection/hasSelectionInSegment.js +0 -14
- package/lib-amd/publicApi/selection/hasSelectionInSegment.js.map +0 -1
- package/lib-mjs/modelApi/domUtils/readFile.d.ts +0 -8
- package/lib-mjs/modelApi/domUtils/readFile.js +0 -20
- package/lib-mjs/modelApi/domUtils/readFile.js.map +0 -1
- package/lib-mjs/modelApi/table/getSelectedCells.d.ts +0 -14
- package/lib-mjs/modelApi/table/getSelectedCells.js +0 -28
- package/lib-mjs/modelApi/table/getSelectedCells.js.map +0 -1
- package/lib-mjs/publicApi/selection/hasSelectionInBlock.d.ts +0 -6
- package/lib-mjs/publicApi/selection/hasSelectionInBlock.js +0 -22
- package/lib-mjs/publicApi/selection/hasSelectionInBlock.js.map +0 -1
- package/lib-mjs/publicApi/selection/hasSelectionInBlockGroup.d.ts +0 -6
- package/lib-mjs/publicApi/selection/hasSelectionInBlockGroup.js +0 -15
- package/lib-mjs/publicApi/selection/hasSelectionInBlockGroup.js.map +0 -1
- package/lib-mjs/publicApi/selection/hasSelectionInSegment.d.ts +0 -6
- package/lib-mjs/publicApi/selection/hasSelectionInSegment.js +0 -10
- package/lib-mjs/publicApi/selection/hasSelectionInSegment.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __read } from "tslib";
|
|
2
2
|
import { getSelectionRootNode } from 'roosterjs-content-model-core';
|
|
3
3
|
import { retrieveModelFormatState } from '../../modelApi/common/retrieveModelFormatState';
|
|
4
4
|
import { getRegularSelectionOffsets, handleRegularSelection, isNodeOfType, processChildNode, } from 'roosterjs-content-model-dom';
|
|
@@ -13,7 +13,13 @@ export default function getFormatState(editor) {
|
|
|
13
13
|
child: reducedModelChildProcessor,
|
|
14
14
|
},
|
|
15
15
|
});
|
|
16
|
-
var
|
|
16
|
+
var manager = editor.getSnapshotsManager();
|
|
17
|
+
var result = {
|
|
18
|
+
canUndo: manager.hasNewContent || manager.canMove(-1),
|
|
19
|
+
canRedo: manager.canMove(1),
|
|
20
|
+
isDarkMode: editor.isDarkMode(),
|
|
21
|
+
zoomScale: editor.getZoomScale(),
|
|
22
|
+
};
|
|
17
23
|
retrieveModelFormatState(model, pendingFormat, result);
|
|
18
24
|
return result;
|
|
19
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/format/getFormatState.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAQ1F,OAAO,EACH,0BAA0B,EAC1B,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,GACnB,MAAM,6BAA6B,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,MAAyB;IAC5D,IAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAChD,IAAM,KAAK,GAAG,MAAM,CAAC,kBAAkB,CAAC;QACpC,iBAAiB,EAAE;YACf,KAAK,EAAE,0BAA0B;SACpC;KACJ,CAAC,CAAC;IACH,IAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"getFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/format/getFormatState.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAQ1F,OAAO,EACH,0BAA0B,EAC1B,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,GACnB,MAAM,6BAA6B,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,MAAyB;IAC5D,IAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAChD,IAAM,KAAK,GAAG,MAAM,CAAC,kBAAkB,CAAC;QACpC,iBAAiB,EAAE;YACf,KAAK,EAAE,0BAA0B;SACpC;KACJ,CAAC,CAAC;IACH,IAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,EAAE,CAAC;IAC7C,IAAM,MAAM,GAA4B;QACpC,OAAO,EAAE,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACrD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;QAC/B,SAAS,EAAE,MAAM,CAAC,YAAY,EAAE;KACnC,CAAC;IAEF,wBAAwB,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IAEvD,OAAO,MAAM,CAAC;AAClB,CAAC;AAaD;;;;;;;GAOG;AACH,M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,GAAW,EAAE,CAAC;IAC1B,IAAI,IAAI,GAAgB,SAAS,CAAC;IAElC,OAAO,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QAChD,IAAI,YAAY,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,IAAI,CAAC,OAAO,IAAI,OAAO,EAAE;YAC/D,mGAAmG;YACnG,0EAA0E;YAC1E,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SACzC;aAAM;YACH,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACrB;QAED,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;KAC1B;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,aAAa,CAAC,MAAkB,EAAE,UAAgB;IACvD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC;IAE9B,OAAO,KAAK,IAAI,KAAK,IAAI,UAAU,EAAE;QACjC,KAAK,EAAE,CAAC;QACR,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC;KAC7B;IACD,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { getSelectionRootNode } from 'roosterjs-content-model-core';\nimport { retrieveModelFormatState } from '../../modelApi/common/retrieveModelFormatState';\nimport type {\n IStandaloneEditor,\n ContentModelBlockGroup,\n ContentModelFormatState,\n DomToModelContext,\n} from 'roosterjs-content-model-types';\n\nimport {\n getRegularSelectionOffsets,\n handleRegularSelection,\n isNodeOfType,\n processChildNode,\n} from 'roosterjs-content-model-dom';\n\n/**\n * Get current format state\n * @param editor The editor to get format from\n */\nexport default function getFormatState(editor: IStandaloneEditor): ContentModelFormatState {\n const pendingFormat = editor.getPendingFormat();\n const model = editor.createContentModel({\n processorOverride: {\n child: reducedModelChildProcessor,\n },\n });\n const manager = editor.getSnapshotsManager();\n const result: ContentModelFormatState = {\n canUndo: manager.hasNewContent || manager.canMove(-1),\n canRedo: manager.canMove(1),\n isDarkMode: editor.isDarkMode(),\n zoomScale: editor.getZoomScale(),\n };\n\n retrieveModelFormatState(model, pendingFormat, result);\n\n return result;\n}\n\n/**\n * @internal\n */\ninterface FormatStateContext extends DomToModelContext {\n /**\n * An optional stack of parent elements to process. When provided, the child nodes of current parent element will be ignored,\n * but use the top element in this stack instead in childProcessor.\n */\n nodeStack?: Node[];\n}\n\n/**\n * @internal\n * Export for test only\n * In order to get format, we can still use the regular child processor. However, to improve performance, we don't need to create\n * content model for the whole doc, instead we only need to traverse the tree path that can arrive current selected node.\n * This \"reduced\" child processor will first create a node stack that stores DOM node from root to current common ancestor node of selection,\n * then use this stack as a faked DOM tree to create a reduced content model which we can use to retrieve format state\n */\nexport function reducedModelChildProcessor(\n group: ContentModelBlockGroup,\n parent: ParentNode,\n context: FormatStateContext\n) {\n if (!context.nodeStack) {\n const selectionRootNode = getSelectionRootNode(context.selection);\n context.nodeStack = selectionRootNode ? createNodeStack(parent, selectionRootNode) : [];\n }\n\n const stackChild = context.nodeStack.pop();\n\n if (stackChild) {\n const [nodeStartOffset, nodeEndOffset] = getRegularSelectionOffsets(context, parent);\n\n // If selection is not on this node, skip getting node index to save some time since we don't need it here\n const index =\n nodeStartOffset >= 0 || nodeEndOffset >= 0 ? getChildIndex(parent, stackChild) : -1;\n\n if (index >= 0) {\n handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);\n }\n\n processChildNode(group, stackChild, context);\n\n if (index >= 0) {\n handleRegularSelection(index + 1, context, group, nodeStartOffset, nodeEndOffset);\n }\n } else {\n // No child node from node stack, that means we have reached the deepest node of selection.\n // Now we can use default child processor to perform full sub tree scanning for content model,\n // So that all selected node will be included.\n context.defaultElementProcessors.child(group, parent, context);\n }\n}\n\nfunction createNodeStack(root: Node, startNode: Node): Node[] {\n const result: Node[] = [];\n let node: Node | null = startNode;\n\n while (node && root != node && root.contains(node)) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && node.tagName == 'TABLE') {\n // For table, we can't do a reduced model creation since we need to handle their cells and indexes,\n // so clean up whatever we already have, and just put table into the stack\n result.splice(0, result.length, node);\n } else {\n result.push(node);\n }\n\n node = node.parentNode;\n }\n\n return result;\n}\n\nfunction getChildIndex(parent: ParentNode, stackChild: Node) {\n let index = 0;\n let child = parent.firstChild;\n\n while (child && child != stackChild) {\n index++;\n child = child.nextSibling;\n }\n return index;\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import formatImageWithContentModel from '../utils/formatImageWithContentModel';
|
|
2
|
-
import { readFile } from '
|
|
3
|
-
import { updateImageMetadata } from 'roosterjs-content-model-core';
|
|
2
|
+
import { readFile, updateImageMetadata } from 'roosterjs-content-model-core';
|
|
4
3
|
/**
|
|
5
4
|
* Change the selected image src
|
|
6
5
|
* @param editor The editor instance
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changeImage.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/image/changeImage.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,MAAM,sCAAsC,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"changeImage.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/image/changeImage.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,MAAM,sCAAsC,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAG7E;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,MAAyB,EAAE,IAAU;IACrE,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAC3C,QAAQ,CAAC,IAAI,EAAE,UAAA,OAAO;QAClB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,OAAO,EAAE;YAChE,2BAA2B,CAAC,MAAM,EAAE,aAAa,EAAE,UAAC,KAAwB;;gBACxE,IAAM,WAAW,GAAG,MAAA,MAAA,mBAAmB,CAAC,KAAK,CAAC,0CAAE,GAAG,mCAAI,EAAE,CAAC;gBAC1D,IAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC;gBAE9B,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC;gBACpB,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;gBACnB,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;gBACxB,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;gBACzB,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC;gBAEf,MAAM,CAAC,kBAAkB,qBAA4B;oBACjD,KAAK,EAAE,SAAS,CAAC,KAAK;oBACtB,WAAW,aAAA;oBACX,MAAM,EAAE,OAAO;oBACf,WAAW,aAAA;iBACd,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import formatImageWithContentModel from '../utils/formatImageWithContentModel';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport { readFile, updateImageMetadata } from 'roosterjs-content-model-core';\nimport type { ContentModelImage, IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Change the selected image src\n * @param editor The editor instance\n * @param file The image file\n */\nexport default function changeImage(editor: IStandaloneEditor, file: File) {\n editor.focus();\n\n const selection = editor.getDOMSelection();\n readFile(file, dataUrl => {\n if (dataUrl && !editor.isDisposed() && selection?.type === 'image') {\n formatImageWithContentModel(editor, 'changeImage', (image: ContentModelImage) => {\n const originalSrc = updateImageMetadata(image)?.src ?? '';\n const previousSrc = image.src;\n\n image.src = dataUrl;\n image.dataset = {};\n image.format.width = '';\n image.format.height = '';\n image.alt = '';\n\n editor.triggerPluginEvent(PluginEventType.EditImage, {\n image: selection.image,\n previousSrc,\n newSrc: dataUrl,\n originalSrc,\n });\n });\n }\n });\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { addSegment, createContentModelDocument, createImage } from 'roosterjs-content-model-dom';
|
|
2
|
-
import { mergeModel } from 'roosterjs-content-model-core';
|
|
3
|
-
import { readFile } from '../../modelApi/domUtils/readFile';
|
|
2
|
+
import { mergeModel, readFile } from 'roosterjs-content-model-core';
|
|
4
3
|
/**
|
|
5
4
|
* Insert an image into current selected position
|
|
6
5
|
* @param editor The editor to operate on
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertImage.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/image/insertImage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"insertImage.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/image/insertImage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGpE;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,MAAyB,EAAE,cAA6B;IACxF,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAI,OAAO,cAAc,IAAI,QAAQ,EAAE;QACnC,kBAAkB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;KAC9C;SAAM;QACH,QAAQ,CAAC,cAAc,EAAE,UAAA,OAAO;YAC5B,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE;gBACjC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;aACvC;QACL,CAAC,CAAC,CAAC;KACN;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAyB,EAAE,GAAW;IAC9D,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;QACxD,IAAM,GAAG,GAAG,0BAA0B,EAAE,CAAC;QAEzC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACvB,UAAU,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;YAC5B,WAAW,EAAE,UAAU;SAC1B,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IAChB,CAAC,EACD;QACI,OAAO,EAAE,aAAa;KACzB,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { addSegment, createContentModelDocument, createImage } from 'roosterjs-content-model-dom';\nimport { mergeModel, readFile } from 'roosterjs-content-model-core';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Insert an image into current selected position\n * @param editor The editor to operate on\n * @param file Image Blob file or source string\n */\nexport default function insertImage(editor: IStandaloneEditor, imageFileOrSrc: File | string) {\n editor.focus();\n\n if (typeof imageFileOrSrc == 'string') {\n insertImageWithSrc(editor, imageFileOrSrc);\n } else {\n readFile(imageFileOrSrc, dataUrl => {\n if (dataUrl && !editor.isDisposed()) {\n insertImageWithSrc(editor, dataUrl);\n }\n });\n }\n}\n\nfunction insertImageWithSrc(editor: IStandaloneEditor, src: string) {\n editor.formatContentModel(\n (model, context) => {\n const image = createImage(src, { backgroundColor: '' });\n const doc = createContentModelDocument();\n\n addSegment(doc, image);\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n\n return true;\n },\n {\n apiName: 'insertImage',\n }\n );\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __read } from "tslib";
|
|
2
|
-
import { getSelectedCells } from '../../modelApi/table/getSelectedCells';
|
|
3
2
|
import { parseValueWithUnit } from 'roosterjs-content-model-dom';
|
|
4
|
-
import { extractBorderValues, getFirstSelectedTable, updateTableCellMetadata, } from 'roosterjs-content-model-core';
|
|
3
|
+
import { extractBorderValues, getFirstSelectedTable, getSelectedCells, updateTableCellMetadata, } from 'roosterjs-content-model-core';
|
|
5
4
|
/**
|
|
6
5
|
* Operations to apply border
|
|
7
6
|
* @param editor The editor instance
|
|
@@ -68,7 +67,7 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
68
67
|
'borderRight',
|
|
69
68
|
];
|
|
70
69
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
71
|
-
for (var colIndex = sel.
|
|
70
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
72
71
|
var cell = tableModel.rows[rowIndex].cells[colIndex];
|
|
73
72
|
// Format cells - All borders
|
|
74
73
|
applyBorderFormat(cell, borderFormat, allBorders);
|
|
@@ -83,7 +82,7 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
83
82
|
case 'leftBorders':
|
|
84
83
|
var leftBorder = ['borderLeft'];
|
|
85
84
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
86
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
85
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
87
86
|
// Format cells - Left border
|
|
88
87
|
applyBorderFormat(cell, borderFormat, leftBorder);
|
|
89
88
|
}
|
|
@@ -93,7 +92,7 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
93
92
|
case 'rightBorders':
|
|
94
93
|
var rightBorder = ['borderRight'];
|
|
95
94
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
96
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
95
|
+
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
|
|
97
96
|
// Format cells - Right border
|
|
98
97
|
applyBorderFormat(cell, borderFormat, rightBorder);
|
|
99
98
|
}
|
|
@@ -102,7 +101,7 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
102
101
|
break;
|
|
103
102
|
case 'topBorders':
|
|
104
103
|
var topBorder = ['borderTop'];
|
|
105
|
-
for (var colIndex = sel.
|
|
104
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
106
105
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
107
106
|
// Format cells - Top border
|
|
108
107
|
applyBorderFormat(cell, borderFormat, topBorder);
|
|
@@ -112,7 +111,7 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
112
111
|
break;
|
|
113
112
|
case 'bottomBorders':
|
|
114
113
|
var bottomBorder = ['borderBottom'];
|
|
115
|
-
for (var colIndex = sel.
|
|
114
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
116
115
|
var cell = tableModel.rows[sel.lastRow].cells[colIndex];
|
|
117
116
|
// Format cells - Bottom border
|
|
118
117
|
applyBorderFormat(cell, borderFormat, bottomBorder);
|
|
@@ -122,7 +121,7 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
122
121
|
break;
|
|
123
122
|
case 'insideBorders':
|
|
124
123
|
// Format cells - Inside borders
|
|
125
|
-
var singleCol = sel.
|
|
124
|
+
var singleCol = sel.lastColumn == sel.firstColumn;
|
|
126
125
|
var singleRow = sel.lastRow == sel.firstRow;
|
|
127
126
|
// Single cell selection
|
|
128
127
|
if (singleCol && singleRow) {
|
|
@@ -130,41 +129,41 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
130
129
|
}
|
|
131
130
|
// Single column selection
|
|
132
131
|
if (singleCol) {
|
|
133
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
132
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom']);
|
|
134
133
|
for (var rowIndex = sel.firstRow + 1; rowIndex <= sel.lastRow - 1; rowIndex++) {
|
|
135
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
134
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
136
135
|
applyBorderFormat(cell, borderFormat, [
|
|
137
136
|
'borderTop',
|
|
138
137
|
'borderBottom',
|
|
139
138
|
]);
|
|
140
139
|
}
|
|
141
|
-
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.
|
|
140
|
+
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop']);
|
|
142
141
|
break;
|
|
143
142
|
}
|
|
144
143
|
// Single row selection
|
|
145
144
|
if (singleRow) {
|
|
146
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
147
|
-
for (var colIndex = sel.
|
|
145
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderRight']);
|
|
146
|
+
for (var colIndex = sel.firstColumn + 1; colIndex <= sel.lastColumn - 1; colIndex++) {
|
|
148
147
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
149
148
|
applyBorderFormat(cell, borderFormat, [
|
|
150
149
|
'borderLeft',
|
|
151
150
|
'borderRight',
|
|
152
151
|
]);
|
|
153
152
|
}
|
|
154
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
153
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.lastColumn], borderFormat, ['borderLeft']);
|
|
155
154
|
break;
|
|
156
155
|
}
|
|
157
156
|
// For multiple rows and columns selections
|
|
158
157
|
// Top left cell
|
|
159
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
158
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
|
|
160
159
|
// Top right cell
|
|
161
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
160
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
|
|
162
161
|
// Bottom left cell
|
|
163
|
-
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.
|
|
162
|
+
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
|
|
164
163
|
// Bottom right cell
|
|
165
|
-
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.
|
|
164
|
+
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
|
|
166
165
|
// First row
|
|
167
|
-
for (var colIndex = sel.
|
|
166
|
+
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
168
167
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
169
168
|
applyBorderFormat(cell, borderFormat, [
|
|
170
169
|
'borderBottom',
|
|
@@ -173,7 +172,7 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
173
172
|
]);
|
|
174
173
|
}
|
|
175
174
|
// Last row
|
|
176
|
-
for (var colIndex = sel.
|
|
175
|
+
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
177
176
|
var cell = tableModel.rows[sel.lastRow].cells[colIndex];
|
|
178
177
|
applyBorderFormat(cell, borderFormat, [
|
|
179
178
|
'borderTop',
|
|
@@ -183,7 +182,7 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
183
182
|
}
|
|
184
183
|
// First column
|
|
185
184
|
for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
|
|
186
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
185
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
187
186
|
applyBorderFormat(cell, borderFormat, [
|
|
188
187
|
'borderTop',
|
|
189
188
|
'borderBottom',
|
|
@@ -192,7 +191,7 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
192
191
|
}
|
|
193
192
|
// Last column
|
|
194
193
|
for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
|
|
195
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
194
|
+
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
|
|
196
195
|
applyBorderFormat(cell, borderFormat, [
|
|
197
196
|
'borderTop',
|
|
198
197
|
'borderBottom',
|
|
@@ -200,9 +199,9 @@ export default function applyTableBorderFormat(editor, border, operation) {
|
|
|
200
199
|
]);
|
|
201
200
|
}
|
|
202
201
|
// Inner cells
|
|
203
|
-
sel.
|
|
202
|
+
sel.firstColumn++;
|
|
204
203
|
sel.firstRow++;
|
|
205
|
-
sel.
|
|
204
|
+
sel.lastColumn--;
|
|
206
205
|
sel.lastRow--;
|
|
207
206
|
operations.push('allBorders');
|
|
208
207
|
break;
|
|
@@ -260,29 +259,29 @@ function applyBorderFormat(cell, borderFormat, positions) {
|
|
|
260
259
|
function modifyPerimeter(tableModel, sel, borderFormat, perimeter) {
|
|
261
260
|
// Top of selection
|
|
262
261
|
if (perimeter.Top && sel.firstRow - 1 >= 0) {
|
|
263
|
-
for (var colIndex = sel.
|
|
262
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
264
263
|
var cell = tableModel.rows[sel.firstRow - 1].cells[colIndex];
|
|
265
264
|
applyBorderFormat(cell, borderFormat, ['borderBottom']);
|
|
266
265
|
}
|
|
267
266
|
}
|
|
268
267
|
// Bottom of selection
|
|
269
268
|
if (perimeter.Bottom && sel.lastRow + 1 < tableModel.rows.length) {
|
|
270
|
-
for (var colIndex = sel.
|
|
269
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
271
270
|
var cell = tableModel.rows[sel.lastRow + 1].cells[colIndex];
|
|
272
271
|
applyBorderFormat(cell, borderFormat, ['borderTop']);
|
|
273
272
|
}
|
|
274
273
|
}
|
|
275
274
|
// Left of selection
|
|
276
|
-
if (perimeter.Left && sel.
|
|
275
|
+
if (perimeter.Left && sel.firstColumn - 1 >= 0) {
|
|
277
276
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
278
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
277
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];
|
|
279
278
|
applyBorderFormat(cell, borderFormat, ['borderRight']);
|
|
280
279
|
}
|
|
281
280
|
}
|
|
282
281
|
// Right of selection
|
|
283
|
-
if (perimeter.Right && sel.
|
|
282
|
+
if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {
|
|
284
283
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
285
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
284
|
+
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];
|
|
286
285
|
applyBorderFormat(cell, borderFormat, ['borderLeft']);
|
|
287
286
|
}
|
|
288
287
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,GAC1B,MAAM,8BAA8B,CAAC;AA4BtC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC1C,MAAyB,EACzB,MAAc,EACd,SAA2B;IAE3B,MAA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electedCells } from '../../modelApi/table/getSelectedCells';\nimport { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getFirstSelectedTable,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n IStandaloneEditor,\n Border,\n ContentModelTable,\n ContentModelTableCell,\n BorderOperations,\n} from 'roosterjs-content-model-types';\nimport type { TableSelectionCoordinates } from '../../modelApi/table/getSelectedCells';\n\n/**\n * @internal\n * Border positions\n */\ntype BorderPositions = 'borderTop' | 'borderBottom' | 'borderLeft' | 'borderRight';\n\n/**\n * @internal\n * Perimeter of the table selection\n * Used to determine where to apply border to the cells adjacent to the selection.\n */\ntype Perimeter = {\n Top: boolean;\n Bottom: boolean;\n Left: boolean;\n Right: boolean;\n};\n\n/**\n * Operations to apply border\n * @param editor The editor instance\n * @param border The border to apply\n * @param operation The operation to apply\n */\nexport default function applyTableBorderFormat(\n editor: IStandaloneEditor,\n border: Border,\n operation: BorderOperations\n) {\n editor.formatContentModel(\n model => {\n const [tableModel] = getFirstSelectedTable(model);\n\n if (tableModel) {\n const sel = getSelectedCells(tableModel);\n const perimeter: Perimeter = {\n Top: false,\n Bottom: false,\n Left: false,\n Right: false,\n };\n\n // Create border format with table format as backup\n let borderFormat = '';\n const format = tableModel.format;\n const { width, style, color } = border;\n const extractedBorder = extractBorderValues(format.borderTop);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n\n if (width) {\n borderFormat = parseValueWithUnit(width) + 'px';\n } else if (borderWidth) {\n borderFormat = borderWidth;\n } else {\n borderFormat = '1px';\n }\n\n if (style) {\n borderFormat = `${borderFormat} ${style}`;\n } else if (borderStyle) {\n borderFormat = `${borderFormat} ${borderStyle}`;\n } else {\n borderFormat = `${borderFormat} solid`;\n }\n\n if (color) {\n borderFormat = `${borderFormat} ${color}`;\n } else if (borderColor) {\n borderFormat = `${borderFormat} ${borderColor}`;\n }\n\n if (sel) {\n const operations: BorderOperations[] = [operation];\n while (operations.length) {\n switch (operations.pop()) {\n case 'noBorders':\n // Do All borders but with empty border format\n borderFormat = '';\n operations.push('allBorders');\n break;\n case 'allBorders':\n const allBorders: BorderPositions[] = [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n for (\n let colIndex = sel.firstCol;\n colIndex <= sel.lastCol;\n colIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[colIndex];\n // Format cells - All borders\n applyBorderFormat(cell, borderFormat, allBorders);\n }\n }\n\n // Format perimeter\n perimeter.Top = true;\n perimeter.Bottom = true;\n perimeter.Left = true;\n perimeter.Right = true;\n break;\n case 'leftBorders':\n const leftBorder: BorderPositions[] = ['borderLeft'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstCol];\n // Format cells - Left border\n applyBorderFormat(cell, borderFormat, leftBorder);\n }\n\n // Format perimeter\n perimeter.Left = true;\n break;\n case 'rightBorders':\n const rightBorder: BorderPositions[] = ['borderRight'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastCol];\n // Format cells - Right border\n applyBorderFormat(cell, borderFormat, rightBorder);\n }\n\n // Format perimeter\n perimeter.Right = true;\n break;\n case 'topBorders':\n const topBorder: BorderPositions[] = ['borderTop'];\n for (\n let colIndex = sel.firstCol;\n colIndex <= sel.lastCol;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n // Format cells - Top border\n applyBorderFormat(cell, borderFormat, topBorder);\n }\n\n // Format perimeter\n perimeter.Top = true;\n break;\n case 'bottomBorders':\n const bottomBorder: BorderPositions[] = ['borderBottom'];\n for (\n let colIndex = sel.firstCol;\n colIndex <= sel.lastCol;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n // Format cells - Bottom border\n applyBorderFormat(cell, borderFormat, bottomBorder);\n }\n\n // Format perimeter\n perimeter.Bottom = true;\n break;\n case 'insideBorders':\n // Format cells - Inside borders\n const singleCol = sel.lastCol == sel.firstCol;\n const singleRow = sel.lastRow == sel.firstRow;\n // Single cell selection\n if (singleCol && singleRow) {\n break;\n }\n // Single column selection\n if (singleCol) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstCol],\n borderFormat,\n ['borderBottom']\n );\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex <= sel.lastRow - 1;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstCol];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstCol],\n borderFormat,\n ['borderTop']\n );\n break;\n }\n // Single row selection\n if (singleRow) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstCol],\n borderFormat,\n ['borderRight']\n );\n for (\n let colIndex = sel.firstCol + 1;\n colIndex <= sel.lastCol - 1;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderLeft',\n 'borderRight',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.lastCol],\n borderFormat,\n ['borderLeft']\n );\n break;\n }\n\n // For multiple rows and columns selections\n // Top left cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstCol],\n borderFormat,\n ['borderBottom', 'borderRight']\n );\n // Top right cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.lastCol],\n borderFormat,\n ['borderBottom', 'borderLeft']\n );\n // Bottom left cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstCol],\n borderFormat,\n ['borderTop', 'borderRight']\n );\n // Bottom right cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.lastCol],\n borderFormat,\n ['borderTop', 'borderLeft']\n );\n // First row\n for (\n let colIndex = sel.firstCol + 1;\n colIndex < sel.lastCol;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // Last row\n for (\n let colIndex = sel.firstCol + 1;\n colIndex < sel.lastCol;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // First column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstCol];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n 'borderRight',\n ]);\n }\n // Last column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastCol];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n ]);\n }\n // Inner cells\n sel.firstCol++;\n sel.firstRow++;\n sel.lastCol--;\n sel.lastRow--;\n operations.push('allBorders');\n break;\n case 'outsideBorders':\n // Format cells - Outside borders\n operations.push('topBorders');\n operations.push('bottomBorders');\n operations.push('leftBorders');\n operations.push('rightBorders');\n break;\n default:\n break;\n }\n }\n\n //Format perimeter if necessary or possible\n modifyPerimeter(tableModel, sel, borderFormat, perimeter);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'tableBorder',\n }\n );\n}\n\n/**\n * @internal\n * Apply border format to a cell\n * @param cell The cell to apply border format\n * @param borderFormat The border format to apply\n * @param positions The positions to apply\n */\nfunction applyBorderFormat(\n cell: ContentModelTableCell,\n borderFormat: string,\n positions: BorderPositions[]\n) {\n positions.forEach(pos => {\n cell.format[pos] = borderFormat;\n });\n\n updateTableCellMetadata(cell, metadata => {\n metadata = metadata || {};\n metadata.borderOverride = true;\n return metadata;\n });\n\n // Cell was modified, so delete cached element\n delete cell.cachedElement;\n}\n\n/**\n * @internal\n * Modify the perimeter of the table selection\n * @param tableModel The table model\n * @param sel The table selection\n * @param borderFormat The border format to apply\n * If borderFormat is empty, the border will be removed\n * @param perimeter Where in the perimeter to apply\n */\nfunction modifyPerimeter(\n tableModel: ContentModelTable,\n sel: TableSelectionCoordinates,\n borderFormat: string,\n perimeter: Perimeter\n) {\n // Top of selection\n if (perimeter.Top && sel.firstRow - 1 >= 0) {\n for (let colIndex = sel.firstCol; colIndex <= sel.lastCol; colIndex++) {\n const cell = tableModel.rows[sel.firstRow - 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderBottom']);\n }\n }\n // Bottom of selection\n if (perimeter.Bottom && sel.lastRow + 1 < tableModel.rows.length) {\n for (let colIndex = sel.firstCol; colIndex <= sel.lastCol; colIndex++) {\n const cell = tableModel.rows[sel.lastRow + 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderTop']);\n }\n }\n // Left of selection\n if (perimeter.Left && sel.firstCol - 1 >= 0) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstCol - 1];\n applyBorderFormat(cell, borderFormat, ['borderRight']);\n }\n }\n // Right of selection\n if (perimeter.Right && sel.lastCol + 1 < tableModel.rows[0].cells.length) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastCol + 1];\n applyBorderFormat(cell, borderFormat, ['borderLeft']);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts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AE,EAAE;YACnE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;YACjE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;SACzD;KACJ;AACL,CAAC","sourcesContent":["import { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getFirstSelectedTable,\n getSelectedCells,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n IStandaloneEditor,\n Border,\n ContentModelTable,\n ContentModelTableCell,\n BorderOperations,\n TableSelectionCoordinates,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Border positions\n */\ntype BorderPositions = 'borderTop' | 'borderBottom' | 'borderLeft' | 'borderRight';\n\n/**\n * @internal\n * Perimeter of the table selection\n * Used to determine where to apply border to the cells adjacent to the selection.\n */\ntype Perimeter = {\n Top: boolean;\n Bottom: boolean;\n Left: boolean;\n Right: boolean;\n};\n\n/**\n * Operations to apply border\n * @param editor The editor instance\n * @param border The border to apply\n * @param operation The operation to apply\n */\nexport default function applyTableBorderFormat(\n editor: IStandaloneEditor,\n border: Border,\n operation: BorderOperations\n) {\n editor.formatContentModel(\n model => {\n const [tableModel] = getFirstSelectedTable(model);\n\n if (tableModel) {\n const sel = getSelectedCells(tableModel);\n const perimeter: Perimeter = {\n Top: false,\n Bottom: false,\n Left: false,\n Right: false,\n };\n\n // Create border format with table format as backup\n let borderFormat = '';\n const format = tableModel.format;\n const { width, style, color } = border;\n const extractedBorder = extractBorderValues(format.borderTop);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n\n if (width) {\n borderFormat = parseValueWithUnit(width) + 'px';\n } else if (borderWidth) {\n borderFormat = borderWidth;\n } else {\n borderFormat = '1px';\n }\n\n if (style) {\n borderFormat = `${borderFormat} ${style}`;\n } else if (borderStyle) {\n borderFormat = `${borderFormat} ${borderStyle}`;\n } else {\n borderFormat = `${borderFormat} solid`;\n }\n\n if (color) {\n borderFormat = `${borderFormat} ${color}`;\n } else if (borderColor) {\n borderFormat = `${borderFormat} ${borderColor}`;\n }\n\n if (sel) {\n const operations: BorderOperations[] = [operation];\n while (operations.length) {\n switch (operations.pop()) {\n case 'noBorders':\n // Do All borders but with empty border format\n borderFormat = '';\n operations.push('allBorders');\n break;\n case 'allBorders':\n const allBorders: BorderPositions[] = [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[colIndex];\n // Format cells - All borders\n applyBorderFormat(cell, borderFormat, allBorders);\n }\n }\n\n // Format perimeter\n perimeter.Top = true;\n perimeter.Bottom = true;\n perimeter.Left = true;\n perimeter.Right = true;\n break;\n case 'leftBorders':\n const leftBorder: BorderPositions[] = ['borderLeft'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn];\n // Format cells - Left border\n applyBorderFormat(cell, borderFormat, leftBorder);\n }\n\n // Format perimeter\n perimeter.Left = true;\n break;\n case 'rightBorders':\n const rightBorder: BorderPositions[] = ['borderRight'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn];\n // Format cells - Right border\n applyBorderFormat(cell, borderFormat, rightBorder);\n }\n\n // Format perimeter\n perimeter.Right = true;\n break;\n case 'topBorders':\n const topBorder: BorderPositions[] = ['borderTop'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n // Format cells - Top border\n applyBorderFormat(cell, borderFormat, topBorder);\n }\n\n // Format perimeter\n perimeter.Top = true;\n break;\n case 'bottomBorders':\n const bottomBorder: BorderPositions[] = ['borderBottom'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n // Format cells - Bottom border\n applyBorderFormat(cell, borderFormat, bottomBorder);\n }\n\n // Format perimeter\n perimeter.Bottom = true;\n break;\n case 'insideBorders':\n // Format cells - Inside borders\n const singleCol = sel.lastColumn == sel.firstColumn;\n const singleRow = sel.lastRow == sel.firstRow;\n // Single cell selection\n if (singleCol && singleRow) {\n break;\n }\n // Single column selection\n if (singleCol) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstColumn],\n borderFormat,\n ['borderBottom']\n );\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex <= sel.lastRow - 1;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[sel.firstColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstColumn],\n borderFormat,\n ['borderTop']\n );\n break;\n }\n // Single row selection\n if (singleRow) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstColumn],\n borderFormat,\n ['borderRight']\n );\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex <= sel.lastColumn - 1;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderLeft',\n 'borderRight',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.lastColumn],\n borderFormat,\n ['borderLeft']\n );\n break;\n }\n\n // For multiple rows and columns selections\n // Top left cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstColumn],\n borderFormat,\n ['borderBottom', 'borderRight']\n );\n // Top right cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.lastColumn],\n borderFormat,\n ['borderBottom', 'borderLeft']\n );\n // Bottom left cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstColumn],\n borderFormat,\n ['borderTop', 'borderRight']\n );\n // Bottom right cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.lastColumn],\n borderFormat,\n ['borderTop', 'borderLeft']\n );\n // First row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // Last row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // First column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n 'borderRight',\n ]);\n }\n // Last column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n ]);\n }\n // Inner cells\n sel.firstColumn++;\n sel.firstRow++;\n sel.lastColumn--;\n sel.lastRow--;\n operations.push('allBorders');\n break;\n case 'outsideBorders':\n // Format cells - Outside borders\n operations.push('topBorders');\n operations.push('bottomBorders');\n operations.push('leftBorders');\n operations.push('rightBorders');\n break;\n default:\n break;\n }\n }\n\n //Format perimeter if necessary or possible\n modifyPerimeter(tableModel, sel, borderFormat, perimeter);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'tableBorder',\n }\n );\n}\n\n/**\n * @internal\n * Apply border format to a cell\n * @param cell The cell to apply border format\n * @param borderFormat The border format to apply\n * @param positions The positions to apply\n */\nfunction applyBorderFormat(\n cell: ContentModelTableCell,\n borderFormat: string,\n positions: BorderPositions[]\n) {\n positions.forEach(pos => {\n cell.format[pos] = borderFormat;\n });\n\n updateTableCellMetadata(cell, metadata => {\n metadata = metadata || {};\n metadata.borderOverride = true;\n return metadata;\n });\n\n // Cell was modified, so delete cached element\n delete cell.cachedElement;\n}\n\n/**\n * @internal\n * Modify the perimeter of the table selection\n * @param tableModel The table model\n * @param sel The table selection\n * @param borderFormat The border format to apply\n * If borderFormat is empty, the border will be removed\n * @param perimeter Where in the perimeter to apply\n */\nfunction modifyPerimeter(\n tableModel: ContentModelTable,\n sel: TableSelectionCoordinates,\n borderFormat: string,\n perimeter: Perimeter\n) {\n // Top of selection\n if (perimeter.Top && sel.firstRow - 1 >= 0) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.firstRow - 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderBottom']);\n }\n }\n // Bottom of selection\n if (perimeter.Bottom && sel.lastRow + 1 < tableModel.rows.length) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.lastRow + 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderTop']);\n }\n }\n // Left of selection\n if (perimeter.Left && sel.firstColumn - 1 >= 0) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];\n applyBorderFormat(cell, borderFormat, ['borderRight']);\n }\n }\n // Right of selection\n if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];\n applyBorderFormat(cell, borderFormat, ['borderLeft']);\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { __read } from "tslib";
|
|
2
|
-
import hasSelectionInBlock from '../selection/hasSelectionInBlock';
|
|
3
2
|
import { alignTable } from '../../modelApi/table/alignTable';
|
|
4
3
|
import { deleteTable } from '../../modelApi/table/deleteTable';
|
|
5
4
|
import { deleteTableColumn } from '../../modelApi/table/deleteTableColumn';
|
|
@@ -12,7 +11,7 @@ import { mergeTableColumn } from '../../modelApi/table/mergeTableColumn';
|
|
|
12
11
|
import { mergeTableRow } from '../../modelApi/table/mergeTableRow';
|
|
13
12
|
import { splitTableCellHorizontally } from '../../modelApi/table/splitTableCellHorizontally';
|
|
14
13
|
import { splitTableCellVertically } from '../../modelApi/table/splitTableCellVertically';
|
|
15
|
-
import { applyTableFormat, getFirstSelectedTable, normalizeTable, setSelection, } from 'roosterjs-content-model-core';
|
|
14
|
+
import { hasSelectionInBlock, applyTableFormat, getFirstSelectedTable, normalizeTable, setSelection, } from 'roosterjs-content-model-core';
|
|
16
15
|
import { alignTableCellHorizontally, alignTableCellVertically, } from '../../modelApi/table/alignTableCell';
|
|
17
16
|
import { createSelectionMarker, hasMetadata, setParagraphNotImplicit, } from 'roosterjs-content-model-dom';
|
|
18
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editTable.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/editTable.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
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,MAA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AK,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,EAAE,WAAW;KACvB,CACJ,CAAC;AACN,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 { ensureFocusableParagraphForTable } from '../../modelApi/table/ensureFocusableParagraphForTable';\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';\n\nimport {\n hasSelectionInBlock,\n applyTableFormat,\n getFirstSelectedTable,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-core';\nimport type { TableOperation, IStandaloneEditor } from 'roosterjs-content-model-types';\nimport {\n alignTableCellHorizontally,\n alignTableCellVertically,\n} from '../../modelApi/table/alignTableCell';\nimport {\n createSelectionMarker,\n hasMetadata,\n setParagraphNotImplicit,\n} from 'roosterjs-content-model-dom';\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 editor.formatContentModel(\n model => {\n const [tableModel, path] = getFirstSelectedTable(model);\n\n if (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 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: 'editTable',\n }\n );\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { __read } from "tslib";
|
|
2
|
-
import hasSelectionInBlockGroup from '
|
|
3
|
-
import { getFirstSelectedTable, normalizeTable, setTableCellBackgroundColor, } from 'roosterjs-content-model-core';
|
|
2
|
+
import { hasSelectionInBlockGroup, getFirstSelectedTable, normalizeTable, setTableCellBackgroundColor, } from 'roosterjs-content-model-core';
|
|
4
3
|
/**
|
|
5
4
|
* Set table cell shade color
|
|
6
5
|
* @param editor The editor instance
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setTableCellShade.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/setTableCellShade.ts"],"names":[],"mappings":";AAAA,OAAO,wBAAwB,
|
|
1
|
+
{"version":3,"file":"setTableCellShade.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/setTableCellShade.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,wBAAwB,EACxB,qBAAqB,EACrB,cAAc,EACd,2BAA2B,GAC9B,MAAM,8BAA8B,CAAC;AAGtC;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,MAAyB,EAAE,KAAoB;IACrF,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;QACK,IAAA,KAAA,OAAU,qBAAqB,CAAC,KAAK,CAAC,IAAA,EAArC,KAAK,QAAgC,CAAC;QAE7C,IAAI,KAAK,EAAE;YACP,cAAc,CAAC,KAAK,CAAC,CAAC;YAEtB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;gBAClB,OAAA,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;oBAClB,IAAI,wBAAwB,CAAC,IAAI,CAAC,EAAE;wBAChC,2BAA2B,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;qBACtE;gBACL,CAAC,CAAC;YAJF,CAIE,CACL,CAAC;YAEF,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,EACD;QACI,OAAO,EAAE,mBAAmB;KAC/B,CACJ,CAAC;AACN,CAAC","sourcesContent":["import {\n hasSelectionInBlockGroup,\n getFirstSelectedTable,\n normalizeTable,\n setTableCellBackgroundColor,\n} from 'roosterjs-content-model-core';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Set table cell shade color\n * @param editor The editor instance\n * @param color The color to set. Pass null to remove existing shade color\n */\nexport default function setTableCellShade(editor: IStandaloneEditor, color: string | null) {\n editor.focus();\n\n editor.formatContentModel(\n model => {\n const [table] = getFirstSelectedTable(model);\n\n if (table) {\n normalizeTable(table);\n\n table.rows.forEach(row =>\n row.cells.forEach(cell => {\n if (hasSelectionInBlockGroup(cell)) {\n setTableCellBackgroundColor(cell, color, true /*isColorOverride*/);\n }\n })\n );\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'setTableCellShade',\n }\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
"tslib": "^2.3.1",
|
|
6
6
|
"roosterjs-editor-types": "^8.59.0",
|
|
7
7
|
"roosterjs-editor-dom": "^8.59.0",
|
|
8
|
-
"roosterjs-content-model-core": "^0.
|
|
9
|
-
"roosterjs-content-model-dom": "^0.
|
|
10
|
-
"roosterjs-content-model-types": "^0.
|
|
8
|
+
"roosterjs-content-model-core": "^0.22.0",
|
|
9
|
+
"roosterjs-content-model-dom": "^0.22.0",
|
|
10
|
+
"roosterjs-content-model-types": "^0.22.0"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.22.0",
|
|
13
13
|
"main": "./lib/index.js",
|
|
14
14
|
"typings": "./lib/index.d.ts",
|
|
15
15
|
"module": "./lib-mjs/index.js",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
* Read a file object and invoke a callback function with the data url of this file
|
|
4
|
-
* @param file The file to read
|
|
5
|
-
* @param callback the callback to invoke with data url of the file.
|
|
6
|
-
* If fail to read, dataUrl will be null
|
|
7
|
-
*/
|
|
8
|
-
export declare function readFile(file: File, callback: (dataUrl: string | null) => void): void;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readFile = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
* Read a file object and invoke a callback function with the data url of this file
|
|
7
|
-
* @param file The file to read
|
|
8
|
-
* @param callback the callback to invoke with data url of the file.
|
|
9
|
-
* If fail to read, dataUrl will be null
|
|
10
|
-
*/
|
|
11
|
-
function readFile(file, callback) {
|
|
12
|
-
if (file) {
|
|
13
|
-
var reader_1 = new FileReader();
|
|
14
|
-
reader_1.onload = function () {
|
|
15
|
-
callback(reader_1.result);
|
|
16
|
-
};
|
|
17
|
-
reader_1.onerror = function () {
|
|
18
|
-
callback(null);
|
|
19
|
-
};
|
|
20
|
-
reader_1.readAsDataURL(file);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.readFile = readFile;
|
|
24
|
-
//# sourceMappingURL=readFile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readFile.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/domUtils/readFile.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,IAAU,EAAE,QAA0C;IAC3E,IAAI,IAAI,EAAE;QACN,IAAM,QAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAChC,QAAM,CAAC,MAAM,GAAG;YACZ,QAAQ,CAAC,QAAM,CAAC,MAAgB,CAAC,CAAC;QACtC,CAAC,CAAC;QACF,QAAM,CAAC,OAAO,GAAG;YACb,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,CAAC;QACF,QAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;KAC9B;AACL,CAAC;AAXD,4BAWC","sourcesContent":["/**\n * @internal\n * Read a file object and invoke a callback function with the data url of this file\n * @param file The file to read\n * @param callback the callback to invoke with data url of the file.\n * If fail to read, dataUrl will be null\n */\nexport function readFile(file: File, callback: (dataUrl: string | null) => void) {\n if (file) {\n const reader = new FileReader();\n reader.onload = () => {\n callback(reader.result as string);\n };\n reader.onerror = () => {\n callback(null);\n };\n reader.readAsDataURL(file);\n }\n}\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ContentModelTable } from 'roosterjs-content-model-types';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export interface TableSelectionCoordinates {
|
|
6
|
-
firstRow: number;
|
|
7
|
-
firstCol: number;
|
|
8
|
-
lastRow: number;
|
|
9
|
-
lastCol: number;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export declare function getSelectedCells(table: ContentModelTable): TableSelectionCoordinates | null;
|