roosterjs-content-model-core 0.20.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/LICENSE +25 -0
- package/README.md +262 -0
- package/lib/constants/ChangeSource.d.ts +59 -0
- package/lib/constants/ChangeSource.js +63 -0
- package/lib/constants/ChangeSource.js.map +1 -0
- package/lib/coreApi/createContentModel.d.ts +9 -0
- package/lib/coreApi/createContentModel.js +40 -0
- package/lib/coreApi/createContentModel.js.map +1 -0
- package/lib/coreApi/createEditorContext.d.ts +6 -0
- package/lib/coreApi/createEditorContext.js +38 -0
- package/lib/coreApi/createEditorContext.js.map +1 -0
- package/lib/coreApi/formatContentModel.d.ts +12 -0
- package/lib/coreApi/formatContentModel.js +128 -0
- package/lib/coreApi/formatContentModel.js.map +1 -0
- package/lib/coreApi/getDOMSelection.d.ts +5 -0
- package/lib/coreApi/getDOMSelection.js +41 -0
- package/lib/coreApi/getDOMSelection.js.map +1 -0
- package/lib/coreApi/setContentModel.d.ts +9 -0
- package/lib/coreApi/setContentModel.js +33 -0
- package/lib/coreApi/setContentModel.js.map +1 -0
- package/lib/coreApi/setDOMSelection.d.ts +5 -0
- package/lib/coreApi/setDOMSelection.js +41 -0
- package/lib/coreApi/setDOMSelection.js.map +1 -0
- package/lib/coreApi/switchShadowEdit.d.ts +8 -0
- package/lib/coreApi/switchShadowEdit.js +54 -0
- package/lib/coreApi/switchShadowEdit.js.map +1 -0
- package/lib/corePlugin/ContentModelCachePlugin.d.ts +53 -0
- package/lib/corePlugin/ContentModelCachePlugin.js +169 -0
- package/lib/corePlugin/ContentModelCachePlugin.js.map +1 -0
- package/lib/corePlugin/ContentModelCopyPastePlugin.d.ts +46 -0
- package/lib/corePlugin/ContentModelCopyPastePlugin.js +233 -0
- package/lib/corePlugin/ContentModelCopyPastePlugin.js.map +1 -0
- package/lib/corePlugin/ContentModelFormatPlugin.d.ts +59 -0
- package/lib/corePlugin/ContentModelFormatPlugin.js +147 -0
- package/lib/corePlugin/ContentModelFormatPlugin.js.map +1 -0
- package/lib/corePlugin/ContentModelTypeInContainerPlugin.d.ts +23 -0
- package/lib/corePlugin/ContentModelTypeInContainerPlugin.js +32 -0
- package/lib/corePlugin/ContentModelTypeInContainerPlugin.js.map +1 -0
- package/lib/corePlugin/utils/addRangeToSelection.d.ts +4 -0
- package/lib/corePlugin/utils/addRangeToSelection.js +16 -0
- package/lib/corePlugin/utils/addRangeToSelection.js.map +1 -0
- package/lib/corePlugin/utils/applyDefaultFormat.d.ts +9 -0
- package/lib/corePlugin/utils/applyDefaultFormat.js +79 -0
- package/lib/corePlugin/utils/applyDefaultFormat.js.map +1 -0
- package/lib/corePlugin/utils/applyPendingFormat.d.ts +8 -0
- package/lib/corePlugin/utils/applyPendingFormat.js +51 -0
- package/lib/corePlugin/utils/applyPendingFormat.js.map +1 -0
- package/lib/corePlugin/utils/areSameSelection.d.ts +6 -0
- package/lib/corePlugin/utils/areSameSelection.js +36 -0
- package/lib/corePlugin/utils/areSameSelection.js.map +1 -0
- package/lib/corePlugin/utils/contentModelDomIndexer.d.ts +6 -0
- package/lib/corePlugin/utils/contentModelDomIndexer.js +190 -0
- package/lib/corePlugin/utils/contentModelDomIndexer.js.map +1 -0
- package/lib/editor/createContentModelEditorCore.d.ts +6 -0
- package/lib/editor/createContentModelEditorCore.js +50 -0
- package/lib/editor/createContentModelEditorCore.js.map +1 -0
- package/lib/editor/promoteToContentModelEditorCore.d.ts +8 -0
- package/lib/editor/promoteToContentModelEditorCore.js +72 -0
- package/lib/editor/promoteToContentModelEditorCore.js.map +1 -0
- package/lib/index.d.ts +29 -0
- package/lib/index.js +71 -0
- package/lib/index.js.map +1 -0
- package/lib/metadata/definitionCreators.d.ts +48 -0
- package/lib/metadata/definitionCreators.js +95 -0
- package/lib/metadata/definitionCreators.js.map +1 -0
- package/lib/metadata/updateImageMetadata.d.ts +7 -0
- package/lib/metadata/updateImageMetadata.js +28 -0
- package/lib/metadata/updateImageMetadata.js.map +1 -0
- package/lib/metadata/updateListMetadata.d.ts +15 -0
- package/lib/metadata/updateListMetadata.js +181 -0
- package/lib/metadata/updateListMetadata.js.map +1 -0
- package/lib/metadata/updateTableCellMetadata.d.ts +7 -0
- package/lib/metadata/updateTableCellMetadata.js +20 -0
- package/lib/metadata/updateTableCellMetadata.js.map +1 -0
- package/lib/metadata/updateTableMetadata.d.ts +7 -0
- package/lib/metadata/updateTableMetadata.js +32 -0
- package/lib/metadata/updateTableMetadata.js.map +1 -0
- package/lib/modelApi/edit/deleteExpandedSelection.d.ts +7 -0
- package/lib/modelApi/edit/deleteExpandedSelection.js +99 -0
- package/lib/modelApi/edit/deleteExpandedSelection.js.map +1 -0
- package/lib/modelApi/edit/deleteSingleChar.d.ts +4 -0
- package/lib/modelApi/edit/deleteSingleChar.js +36 -0
- package/lib/modelApi/edit/deleteSingleChar.js.map +1 -0
- package/lib/override/tablePreProcessor.d.ts +5 -0
- package/lib/override/tablePreProcessor.js +25 -0
- package/lib/override/tablePreProcessor.js.map +1 -0
- package/lib/publicApi/domUtils/borderValues.d.ts +13 -0
- package/lib/publicApi/domUtils/borderValues.js +48 -0
- package/lib/publicApi/domUtils/borderValues.js.map +1 -0
- package/lib/publicApi/domUtils/eventUtils.d.ts +13 -0
- package/lib/publicApi/domUtils/eventUtils.js +29 -0
- package/lib/publicApi/domUtils/eventUtils.js.map +1 -0
- package/lib/publicApi/domUtils/stringUtil.d.ts +18 -0
- package/lib/publicApi/domUtils/stringUtil.js +35 -0
- package/lib/publicApi/domUtils/stringUtil.js.map +1 -0
- package/lib/publicApi/model/cloneModel.d.ts +30 -0
- package/lib/publicApi/model/cloneModel.js +207 -0
- package/lib/publicApi/model/cloneModel.js.map +1 -0
- package/lib/publicApi/model/getClosestAncestorBlockGroupIndex.d.ts +12 -0
- package/lib/publicApi/model/getClosestAncestorBlockGroupIndex.js +28 -0
- package/lib/publicApi/model/getClosestAncestorBlockGroupIndex.js.map +1 -0
- package/lib/publicApi/model/isBlockGroupOfType.d.ts +8 -0
- package/lib/publicApi/model/isBlockGroupOfType.js +14 -0
- package/lib/publicApi/model/isBlockGroupOfType.js.map +1 -0
- package/lib/publicApi/model/mergeModel.d.ts +36 -0
- package/lib/publicApi/model/mergeModel.js +262 -0
- package/lib/publicApi/model/mergeModel.js.map +1 -0
- package/lib/publicApi/model/paste.d.ts +14 -0
- package/lib/publicApi/model/paste.js +150 -0
- package/lib/publicApi/model/paste.js.map +1 -0
- package/lib/publicApi/selection/collectSelections.d.ts +50 -0
- package/lib/publicApi/selection/collectSelections.js +182 -0
- package/lib/publicApi/selection/collectSelections.js.map +1 -0
- package/lib/publicApi/selection/deleteBlock.d.ts +11 -0
- package/lib/publicApi/selection/deleteBlock.js +56 -0
- package/lib/publicApi/selection/deleteBlock.js.map +1 -0
- package/lib/publicApi/selection/deleteSegment.d.ts +10 -0
- package/lib/publicApi/selection/deleteSegment.js +88 -0
- package/lib/publicApi/selection/deleteSegment.js.map +1 -0
- package/lib/publicApi/selection/deleteSelection.d.ts +9 -0
- package/lib/publicApi/selection/deleteSelection.js +44 -0
- package/lib/publicApi/selection/deleteSelection.js.map +1 -0
- package/lib/publicApi/selection/getSelectionRootNode.d.ts +9 -0
- package/lib/publicApi/selection/getSelectionRootNode.js +23 -0
- package/lib/publicApi/selection/getSelectionRootNode.js.map +1 -0
- package/lib/publicApi/selection/iterateSelections.d.ts +48 -0
- package/lib/publicApi/selection/iterateSelections.js +147 -0
- package/lib/publicApi/selection/iterateSelections.js.map +1 -0
- package/lib/publicApi/selection/setSelection.d.ts +8 -0
- package/lib/publicApi/selection/setSelection.js +131 -0
- package/lib/publicApi/selection/setSelection.js.map +1 -0
- package/lib/publicApi/table/applyTableFormat.d.ts +8 -0
- package/lib/publicApi/table/applyTableFormat.js +241 -0
- package/lib/publicApi/table/applyTableFormat.js.map +1 -0
- package/lib/publicApi/table/normalizeTable.d.ts +13 -0
- package/lib/publicApi/table/normalizeTable.js +121 -0
- package/lib/publicApi/table/normalizeTable.js.map +1 -0
- package/lib/publicApi/table/setTableCellBackgroundColor.d.ts +15 -0
- package/lib/publicApi/table/setTableCellBackgroundColor.js +105 -0
- package/lib/publicApi/table/setTableCellBackgroundColor.js.map +1 -0
- package/lib-amd/constants/ChangeSource.d.ts +59 -0
- package/lib-amd/constants/ChangeSource.js +65 -0
- package/lib-amd/constants/ChangeSource.js.map +1 -0
- package/lib-amd/coreApi/createContentModel.d.ts +9 -0
- package/lib-amd/coreApi/createContentModel.js +39 -0
- package/lib-amd/coreApi/createContentModel.js.map +1 -0
- package/lib-amd/coreApi/createEditorContext.d.ts +6 -0
- package/lib-amd/coreApi/createEditorContext.js +40 -0
- package/lib-amd/coreApi/createEditorContext.js.map +1 -0
- package/lib-amd/coreApi/formatContentModel.d.ts +12 -0
- package/lib-amd/coreApi/formatContentModel.js +128 -0
- package/lib-amd/coreApi/formatContentModel.js.map +1 -0
- package/lib-amd/coreApi/getDOMSelection.d.ts +5 -0
- package/lib-amd/coreApi/getDOMSelection.js +43 -0
- package/lib-amd/coreApi/getDOMSelection.js.map +1 -0
- package/lib-amd/coreApi/setContentModel.d.ts +9 -0
- package/lib-amd/coreApi/setContentModel.js +33 -0
- package/lib-amd/coreApi/setContentModel.js.map +1 -0
- package/lib-amd/coreApi/setDOMSelection.d.ts +5 -0
- package/lib-amd/coreApi/setDOMSelection.js +43 -0
- package/lib-amd/coreApi/setDOMSelection.js.map +1 -0
- package/lib-amd/coreApi/switchShadowEdit.d.ts +8 -0
- package/lib-amd/coreApi/switchShadowEdit.js +55 -0
- package/lib-amd/coreApi/switchShadowEdit.js.map +1 -0
- package/lib-amd/corePlugin/ContentModelCachePlugin.d.ts +53 -0
- package/lib-amd/corePlugin/ContentModelCachePlugin.js +169 -0
- package/lib-amd/corePlugin/ContentModelCachePlugin.js.map +1 -0
- package/lib-amd/corePlugin/ContentModelCopyPastePlugin.d.ts +46 -0
- package/lib-amd/corePlugin/ContentModelCopyPastePlugin.js +226 -0
- package/lib-amd/corePlugin/ContentModelCopyPastePlugin.js.map +1 -0
- package/lib-amd/corePlugin/ContentModelFormatPlugin.d.ts +59 -0
- package/lib-amd/corePlugin/ContentModelFormatPlugin.js +145 -0
- package/lib-amd/corePlugin/ContentModelFormatPlugin.js.map +1 -0
- package/lib-amd/corePlugin/ContentModelTypeInContainerPlugin.d.ts +23 -0
- package/lib-amd/corePlugin/ContentModelTypeInContainerPlugin.js +34 -0
- package/lib-amd/corePlugin/ContentModelTypeInContainerPlugin.js.map +1 -0
- package/lib-amd/corePlugin/utils/addRangeToSelection.d.ts +4 -0
- package/lib-amd/corePlugin/utils/addRangeToSelection.js +18 -0
- package/lib-amd/corePlugin/utils/addRangeToSelection.js.map +1 -0
- package/lib-amd/corePlugin/utils/applyDefaultFormat.d.ts +9 -0
- package/lib-amd/corePlugin/utils/applyDefaultFormat.js +78 -0
- package/lib-amd/corePlugin/utils/applyDefaultFormat.js.map +1 -0
- package/lib-amd/corePlugin/utils/applyPendingFormat.d.ts +8 -0
- package/lib-amd/corePlugin/utils/applyPendingFormat.js +50 -0
- package/lib-amd/corePlugin/utils/applyPendingFormat.js.map +1 -0
- package/lib-amd/corePlugin/utils/areSameSelection.d.ts +6 -0
- package/lib-amd/corePlugin/utils/areSameSelection.js +38 -0
- package/lib-amd/corePlugin/utils/areSameSelection.js.map +1 -0
- package/lib-amd/corePlugin/utils/contentModelDomIndexer.d.ts +6 -0
- package/lib-amd/corePlugin/utils/contentModelDomIndexer.js +189 -0
- package/lib-amd/corePlugin/utils/contentModelDomIndexer.js.map +1 -0
- package/lib-amd/editor/createContentModelEditorCore.d.ts +6 -0
- package/lib-amd/editor/createContentModelEditorCore.js +44 -0
- package/lib-amd/editor/createContentModelEditorCore.js.map +1 -0
- package/lib-amd/editor/promoteToContentModelEditorCore.d.ts +8 -0
- package/lib-amd/editor/promoteToContentModelEditorCore.js +64 -0
- package/lib-amd/editor/promoteToContentModelEditorCore.js.map +1 -0
- package/lib-amd/index.d.ts +29 -0
- package/lib-amd/index.js +44 -0
- package/lib-amd/index.js.map +1 -0
- package/lib-amd/metadata/definitionCreators.d.ts +48 -0
- package/lib-amd/metadata/definitionCreators.js +97 -0
- package/lib-amd/metadata/definitionCreators.js.map +1 -0
- package/lib-amd/metadata/updateImageMetadata.d.ts +7 -0
- package/lib-amd/metadata/updateImageMetadata.js +28 -0
- package/lib-amd/metadata/updateImageMetadata.js.map +1 -0
- package/lib-amd/metadata/updateListMetadata.d.ts +15 -0
- package/lib-amd/metadata/updateListMetadata.js +179 -0
- package/lib-amd/metadata/updateListMetadata.js.map +1 -0
- package/lib-amd/metadata/updateTableCellMetadata.d.ts +7 -0
- package/lib-amd/metadata/updateTableCellMetadata.js +20 -0
- package/lib-amd/metadata/updateTableCellMetadata.js.map +1 -0
- package/lib-amd/metadata/updateTableMetadata.d.ts +7 -0
- package/lib-amd/metadata/updateTableMetadata.js +31 -0
- package/lib-amd/metadata/updateTableMetadata.js.map +1 -0
- package/lib-amd/modelApi/edit/deleteExpandedSelection.d.ts +7 -0
- package/lib-amd/modelApi/edit/deleteExpandedSelection.js +96 -0
- package/lib-amd/modelApi/edit/deleteExpandedSelection.js.map +1 -0
- package/lib-amd/modelApi/edit/deleteSingleChar.d.ts +4 -0
- package/lib-amd/modelApi/edit/deleteSingleChar.js +37 -0
- package/lib-amd/modelApi/edit/deleteSingleChar.js.map +1 -0
- package/lib-amd/override/tablePreProcessor.d.ts +5 -0
- package/lib-amd/override/tablePreProcessor.js +25 -0
- package/lib-amd/override/tablePreProcessor.js.map +1 -0
- package/lib-amd/publicApi/domUtils/borderValues.d.ts +13 -0
- package/lib-amd/publicApi/domUtils/borderValues.js +50 -0
- package/lib-amd/publicApi/domUtils/borderValues.js.map +1 -0
- package/lib-amd/publicApi/domUtils/eventUtils.d.ts +13 -0
- package/lib-amd/publicApi/domUtils/eventUtils.js +31 -0
- package/lib-amd/publicApi/domUtils/eventUtils.js.map +1 -0
- package/lib-amd/publicApi/domUtils/stringUtil.d.ts +18 -0
- package/lib-amd/publicApi/domUtils/stringUtil.js +37 -0
- package/lib-amd/publicApi/domUtils/stringUtil.js.map +1 -0
- package/lib-amd/publicApi/model/cloneModel.d.ts +30 -0
- package/lib-amd/publicApi/model/cloneModel.js +208 -0
- package/lib-amd/publicApi/model/cloneModel.js.map +1 -0
- package/lib-amd/publicApi/model/getClosestAncestorBlockGroupIndex.d.ts +12 -0
- package/lib-amd/publicApi/model/getClosestAncestorBlockGroupIndex.js +30 -0
- package/lib-amd/publicApi/model/getClosestAncestorBlockGroupIndex.js.map +1 -0
- package/lib-amd/publicApi/model/isBlockGroupOfType.d.ts +8 -0
- package/lib-amd/publicApi/model/isBlockGroupOfType.js +16 -0
- package/lib-amd/publicApi/model/isBlockGroupOfType.js.map +1 -0
- package/lib-amd/publicApi/model/mergeModel.d.ts +36 -0
- package/lib-amd/publicApi/model/mergeModel.js +258 -0
- package/lib-amd/publicApi/model/mergeModel.js.map +1 -0
- package/lib-amd/publicApi/model/paste.d.ts +14 -0
- package/lib-amd/publicApi/model/paste.js +146 -0
- package/lib-amd/publicApi/model/paste.js.map +1 -0
- package/lib-amd/publicApi/selection/collectSelections.d.ts +50 -0
- package/lib-amd/publicApi/selection/collectSelections.js +180 -0
- package/lib-amd/publicApi/selection/collectSelections.js.map +1 -0
- package/lib-amd/publicApi/selection/deleteBlock.d.ts +11 -0
- package/lib-amd/publicApi/selection/deleteBlock.js +58 -0
- package/lib-amd/publicApi/selection/deleteBlock.js.map +1 -0
- package/lib-amd/publicApi/selection/deleteSegment.d.ts +10 -0
- package/lib-amd/publicApi/selection/deleteSegment.js +87 -0
- package/lib-amd/publicApi/selection/deleteSegment.js.map +1 -0
- package/lib-amd/publicApi/selection/deleteSelection.d.ts +9 -0
- package/lib-amd/publicApi/selection/deleteSelection.js +44 -0
- package/lib-amd/publicApi/selection/deleteSelection.js.map +1 -0
- package/lib-amd/publicApi/selection/getSelectionRootNode.d.ts +9 -0
- package/lib-amd/publicApi/selection/getSelectionRootNode.js +25 -0
- package/lib-amd/publicApi/selection/getSelectionRootNode.js.map +1 -0
- package/lib-amd/publicApi/selection/iterateSelections.d.ts +48 -0
- package/lib-amd/publicApi/selection/iterateSelections.js +148 -0
- package/lib-amd/publicApi/selection/iterateSelections.js.map +1 -0
- package/lib-amd/publicApi/selection/setSelection.d.ts +8 -0
- package/lib-amd/publicApi/selection/setSelection.js +132 -0
- package/lib-amd/publicApi/selection/setSelection.js.map +1 -0
- package/lib-amd/publicApi/table/applyTableFormat.d.ts +8 -0
- package/lib-amd/publicApi/table/applyTableFormat.js +236 -0
- package/lib-amd/publicApi/table/applyTableFormat.js.map +1 -0
- package/lib-amd/publicApi/table/normalizeTable.d.ts +13 -0
- package/lib-amd/publicApi/table/normalizeTable.js +121 -0
- package/lib-amd/publicApi/table/normalizeTable.js.map +1 -0
- package/lib-amd/publicApi/table/setTableCellBackgroundColor.d.ts +15 -0
- package/lib-amd/publicApi/table/setTableCellBackgroundColor.js +105 -0
- package/lib-amd/publicApi/table/setTableCellBackgroundColor.js.map +1 -0
- package/lib-mjs/constants/ChangeSource.d.ts +59 -0
- package/lib-mjs/constants/ChangeSource.js +60 -0
- package/lib-mjs/constants/ChangeSource.js.map +1 -0
- package/lib-mjs/coreApi/createContentModel.d.ts +9 -0
- package/lib-mjs/coreApi/createContentModel.js +36 -0
- package/lib-mjs/coreApi/createContentModel.js.map +1 -0
- package/lib-mjs/coreApi/createEditorContext.d.ts +6 -0
- package/lib-mjs/coreApi/createEditorContext.js +34 -0
- package/lib-mjs/coreApi/createEditorContext.js.map +1 -0
- package/lib-mjs/coreApi/formatContentModel.d.ts +12 -0
- package/lib-mjs/coreApi/formatContentModel.js +124 -0
- package/lib-mjs/coreApi/formatContentModel.js.map +1 -0
- package/lib-mjs/coreApi/getDOMSelection.d.ts +5 -0
- package/lib-mjs/coreApi/getDOMSelection.js +37 -0
- package/lib-mjs/coreApi/getDOMSelection.js.map +1 -0
- package/lib-mjs/coreApi/setContentModel.d.ts +9 -0
- package/lib-mjs/coreApi/setContentModel.js +29 -0
- package/lib-mjs/coreApi/setContentModel.js.map +1 -0
- package/lib-mjs/coreApi/setDOMSelection.d.ts +5 -0
- package/lib-mjs/coreApi/setDOMSelection.js +37 -0
- package/lib-mjs/coreApi/setDOMSelection.js.map +1 -0
- package/lib-mjs/coreApi/switchShadowEdit.d.ts +8 -0
- package/lib-mjs/coreApi/switchShadowEdit.js +50 -0
- package/lib-mjs/coreApi/switchShadowEdit.js.map +1 -0
- package/lib-mjs/corePlugin/ContentModelCachePlugin.d.ts +53 -0
- package/lib-mjs/corePlugin/ContentModelCachePlugin.js +165 -0
- package/lib-mjs/corePlugin/ContentModelCachePlugin.js.map +1 -0
- package/lib-mjs/corePlugin/ContentModelCopyPastePlugin.d.ts +46 -0
- package/lib-mjs/corePlugin/ContentModelCopyPastePlugin.js +228 -0
- package/lib-mjs/corePlugin/ContentModelCopyPastePlugin.js.map +1 -0
- package/lib-mjs/corePlugin/ContentModelFormatPlugin.d.ts +59 -0
- package/lib-mjs/corePlugin/ContentModelFormatPlugin.js +143 -0
- package/lib-mjs/corePlugin/ContentModelFormatPlugin.js.map +1 -0
- package/lib-mjs/corePlugin/ContentModelTypeInContainerPlugin.d.ts +23 -0
- package/lib-mjs/corePlugin/ContentModelTypeInContainerPlugin.js +29 -0
- package/lib-mjs/corePlugin/ContentModelTypeInContainerPlugin.js.map +1 -0
- package/lib-mjs/corePlugin/utils/addRangeToSelection.d.ts +4 -0
- package/lib-mjs/corePlugin/utils/addRangeToSelection.js +12 -0
- package/lib-mjs/corePlugin/utils/addRangeToSelection.js.map +1 -0
- package/lib-mjs/corePlugin/utils/applyDefaultFormat.d.ts +9 -0
- package/lib-mjs/corePlugin/utils/applyDefaultFormat.js +75 -0
- package/lib-mjs/corePlugin/utils/applyDefaultFormat.js.map +1 -0
- package/lib-mjs/corePlugin/utils/applyPendingFormat.d.ts +8 -0
- package/lib-mjs/corePlugin/utils/applyPendingFormat.js +47 -0
- package/lib-mjs/corePlugin/utils/applyPendingFormat.js.map +1 -0
- package/lib-mjs/corePlugin/utils/areSameSelection.d.ts +6 -0
- package/lib-mjs/corePlugin/utils/areSameSelection.js +32 -0
- package/lib-mjs/corePlugin/utils/areSameSelection.js.map +1 -0
- package/lib-mjs/corePlugin/utils/contentModelDomIndexer.d.ts +6 -0
- package/lib-mjs/corePlugin/utils/contentModelDomIndexer.js +187 -0
- package/lib-mjs/corePlugin/utils/contentModelDomIndexer.js.map +1 -0
- package/lib-mjs/editor/createContentModelEditorCore.d.ts +6 -0
- package/lib-mjs/editor/createContentModelEditorCore.js +46 -0
- package/lib-mjs/editor/createContentModelEditorCore.js.map +1 -0
- package/lib-mjs/editor/promoteToContentModelEditorCore.d.ts +8 -0
- package/lib-mjs/editor/promoteToContentModelEditorCore.js +68 -0
- package/lib-mjs/editor/promoteToContentModelEditorCore.js.map +1 -0
- package/lib-mjs/index.d.ts +29 -0
- package/lib-mjs/index.js +30 -0
- package/lib-mjs/index.js.map +1 -0
- package/lib-mjs/metadata/definitionCreators.d.ts +48 -0
- package/lib-mjs/metadata/definitionCreators.js +87 -0
- package/lib-mjs/metadata/definitionCreators.js.map +1 -0
- package/lib-mjs/metadata/updateImageMetadata.d.ts +7 -0
- package/lib-mjs/metadata/updateImageMetadata.js +24 -0
- package/lib-mjs/metadata/updateImageMetadata.js.map +1 -0
- package/lib-mjs/metadata/updateListMetadata.d.ts +15 -0
- package/lib-mjs/metadata/updateListMetadata.js +177 -0
- package/lib-mjs/metadata/updateListMetadata.js.map +1 -0
- package/lib-mjs/metadata/updateTableCellMetadata.d.ts +7 -0
- package/lib-mjs/metadata/updateTableCellMetadata.js +16 -0
- package/lib-mjs/metadata/updateTableCellMetadata.js.map +1 -0
- package/lib-mjs/metadata/updateTableMetadata.d.ts +7 -0
- package/lib-mjs/metadata/updateTableMetadata.js +28 -0
- package/lib-mjs/metadata/updateTableMetadata.js.map +1 -0
- package/lib-mjs/modelApi/edit/deleteExpandedSelection.d.ts +7 -0
- package/lib-mjs/modelApi/edit/deleteExpandedSelection.js +95 -0
- package/lib-mjs/modelApi/edit/deleteExpandedSelection.js.map +1 -0
- package/lib-mjs/modelApi/edit/deleteSingleChar.d.ts +4 -0
- package/lib-mjs/modelApi/edit/deleteSingleChar.js +32 -0
- package/lib-mjs/modelApi/edit/deleteSingleChar.js.map +1 -0
- package/lib-mjs/override/tablePreProcessor.d.ts +5 -0
- package/lib-mjs/override/tablePreProcessor.js +21 -0
- package/lib-mjs/override/tablePreProcessor.js.map +1 -0
- package/lib-mjs/publicApi/domUtils/borderValues.d.ts +13 -0
- package/lib-mjs/publicApi/domUtils/borderValues.js +43 -0
- package/lib-mjs/publicApi/domUtils/borderValues.js.map +1 -0
- package/lib-mjs/publicApi/domUtils/eventUtils.d.ts +13 -0
- package/lib-mjs/publicApi/domUtils/eventUtils.js +24 -0
- package/lib-mjs/publicApi/domUtils/eventUtils.js.map +1 -0
- package/lib-mjs/publicApi/domUtils/stringUtil.d.ts +18 -0
- package/lib-mjs/publicApi/domUtils/stringUtil.js +29 -0
- package/lib-mjs/publicApi/domUtils/stringUtil.js.map +1 -0
- package/lib-mjs/publicApi/model/cloneModel.d.ts +30 -0
- package/lib-mjs/publicApi/model/cloneModel.js +203 -0
- package/lib-mjs/publicApi/model/cloneModel.js.map +1 -0
- package/lib-mjs/publicApi/model/getClosestAncestorBlockGroupIndex.d.ts +12 -0
- package/lib-mjs/publicApi/model/getClosestAncestorBlockGroupIndex.js +24 -0
- package/lib-mjs/publicApi/model/getClosestAncestorBlockGroupIndex.js.map +1 -0
- package/lib-mjs/publicApi/model/isBlockGroupOfType.d.ts +8 -0
- package/lib-mjs/publicApi/model/isBlockGroupOfType.js +10 -0
- package/lib-mjs/publicApi/model/isBlockGroupOfType.js.map +1 -0
- package/lib-mjs/publicApi/model/mergeModel.d.ts +36 -0
- package/lib-mjs/publicApi/model/mergeModel.js +258 -0
- package/lib-mjs/publicApi/model/mergeModel.js.map +1 -0
- package/lib-mjs/publicApi/model/paste.d.ts +14 -0
- package/lib-mjs/publicApi/model/paste.js +145 -0
- package/lib-mjs/publicApi/model/paste.js.map +1 -0
- package/lib-mjs/publicApi/selection/collectSelections.d.ts +50 -0
- package/lib-mjs/publicApi/selection/collectSelections.js +173 -0
- package/lib-mjs/publicApi/selection/collectSelections.js.map +1 -0
- package/lib-mjs/publicApi/selection/deleteBlock.d.ts +11 -0
- package/lib-mjs/publicApi/selection/deleteBlock.js +52 -0
- package/lib-mjs/publicApi/selection/deleteBlock.js.map +1 -0
- package/lib-mjs/publicApi/selection/deleteSegment.d.ts +10 -0
- package/lib-mjs/publicApi/selection/deleteSegment.js +84 -0
- package/lib-mjs/publicApi/selection/deleteSegment.js.map +1 -0
- package/lib-mjs/publicApi/selection/deleteSelection.d.ts +9 -0
- package/lib-mjs/publicApi/selection/deleteSelection.js +40 -0
- package/lib-mjs/publicApi/selection/deleteSelection.js.map +1 -0
- package/lib-mjs/publicApi/selection/getSelectionRootNode.d.ts +9 -0
- package/lib-mjs/publicApi/selection/getSelectionRootNode.js +19 -0
- package/lib-mjs/publicApi/selection/getSelectionRootNode.js.map +1 -0
- package/lib-mjs/publicApi/selection/iterateSelections.d.ts +48 -0
- package/lib-mjs/publicApi/selection/iterateSelections.js +143 -0
- package/lib-mjs/publicApi/selection/iterateSelections.js.map +1 -0
- package/lib-mjs/publicApi/selection/setSelection.d.ts +8 -0
- package/lib-mjs/publicApi/selection/setSelection.js +127 -0
- package/lib-mjs/publicApi/selection/setSelection.js.map +1 -0
- package/lib-mjs/publicApi/table/applyTableFormat.d.ts +8 -0
- package/lib-mjs/publicApi/table/applyTableFormat.js +237 -0
- package/lib-mjs/publicApi/table/applyTableFormat.js.map +1 -0
- package/lib-mjs/publicApi/table/normalizeTable.d.ts +13 -0
- package/lib-mjs/publicApi/table/normalizeTable.js +117 -0
- package/lib-mjs/publicApi/table/normalizeTable.js.map +1 -0
- package/lib-mjs/publicApi/table/setTableCellBackgroundColor.d.ts +15 -0
- package/lib-mjs/publicApi/table/setTableCellBackgroundColor.js +100 -0
- package/lib-mjs/publicApi/table/setTableCellBackgroundColor.js.map +1 -0
- package/package.json +21 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ContentModelCachePluginState } from 'roosterjs-content-model-types';
|
|
2
|
+
import type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';
|
|
3
|
+
/**
|
|
4
|
+
* ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary
|
|
5
|
+
*/
|
|
6
|
+
export declare class ContentModelCachePlugin implements PluginWithState<ContentModelCachePluginState> {
|
|
7
|
+
private state;
|
|
8
|
+
private editor;
|
|
9
|
+
/**
|
|
10
|
+
* Construct a new instance of ContentModelEditPlugin class
|
|
11
|
+
* @param state State of this plugin
|
|
12
|
+
*/
|
|
13
|
+
constructor(state: ContentModelCachePluginState);
|
|
14
|
+
/**
|
|
15
|
+
* Get name of this plugin
|
|
16
|
+
*/
|
|
17
|
+
getName(): string;
|
|
18
|
+
/**
|
|
19
|
+
* The first method that editor will call to a plugin when editor is initializing.
|
|
20
|
+
* It will pass in the editor instance, plugin should take this chance to save the
|
|
21
|
+
* editor reference so that it can call to any editor method or format API later.
|
|
22
|
+
* @param editor The editor object
|
|
23
|
+
*/
|
|
24
|
+
initialize(editor: IEditor): void;
|
|
25
|
+
/**
|
|
26
|
+
* The last method that editor will call to a plugin before it is disposed.
|
|
27
|
+
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
28
|
+
* called, plugin should not call to any editor method since it will result in error.
|
|
29
|
+
*/
|
|
30
|
+
dispose(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get plugin state object
|
|
33
|
+
*/
|
|
34
|
+
getState(): ContentModelCachePluginState;
|
|
35
|
+
/**
|
|
36
|
+
* Core method for a plugin. Once an event happens in editor, editor will call this
|
|
37
|
+
* method of each plugin to handle the event as long as the event is not handled
|
|
38
|
+
* exclusively by another plugin.
|
|
39
|
+
* @param event The event to handle:
|
|
40
|
+
*/
|
|
41
|
+
onPluginEvent(event: PluginEvent): void;
|
|
42
|
+
private onNativeSelectionChange;
|
|
43
|
+
private invalidateCache;
|
|
44
|
+
private updateCachedModel;
|
|
45
|
+
private shouldClearCache;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
* Create a new instance of ContentModelCachePlugin class.
|
|
50
|
+
* This is mostly for unit test
|
|
51
|
+
* @param state State of this plugin
|
|
52
|
+
*/
|
|
53
|
+
export declare function createContentModelCachePlugin(state: ContentModelCachePluginState): ContentModelCachePlugin;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
define(["require", "exports", "./utils/areSameSelection", "../publicApi/domUtils/eventUtils"], function (require, exports, areSameSelection_1, eventUtils_1) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createContentModelCachePlugin = exports.ContentModelCachePlugin = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary
|
|
7
|
+
*/
|
|
8
|
+
var ContentModelCachePlugin = /** @class */ (function () {
|
|
9
|
+
/**
|
|
10
|
+
* Construct a new instance of ContentModelEditPlugin class
|
|
11
|
+
* @param state State of this plugin
|
|
12
|
+
*/
|
|
13
|
+
function ContentModelCachePlugin(state) {
|
|
14
|
+
var _this = this;
|
|
15
|
+
this.state = state;
|
|
16
|
+
this.editor = null;
|
|
17
|
+
this.onNativeSelectionChange = function () {
|
|
18
|
+
var _a;
|
|
19
|
+
if ((_a = _this.editor) === null || _a === void 0 ? void 0 : _a.hasFocus()) {
|
|
20
|
+
_this.updateCachedModel(_this.editor);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
// TODO: Remove tempState parameter once we have standalone Content Model editor
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get name of this plugin
|
|
27
|
+
*/
|
|
28
|
+
ContentModelCachePlugin.prototype.getName = function () {
|
|
29
|
+
return 'ContentModelCache';
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The first method that editor will call to a plugin when editor is initializing.
|
|
33
|
+
* It will pass in the editor instance, plugin should take this chance to save the
|
|
34
|
+
* editor reference so that it can call to any editor method or format API later.
|
|
35
|
+
* @param editor The editor object
|
|
36
|
+
*/
|
|
37
|
+
ContentModelCachePlugin.prototype.initialize = function (editor) {
|
|
38
|
+
// TODO: Later we may need a different interface for Content Model editor plugin
|
|
39
|
+
this.editor = editor;
|
|
40
|
+
this.editor.getDocument().addEventListener('selectionchange', this.onNativeSelectionChange);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The last method that editor will call to a plugin before it is disposed.
|
|
44
|
+
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
45
|
+
* called, plugin should not call to any editor method since it will result in error.
|
|
46
|
+
*/
|
|
47
|
+
ContentModelCachePlugin.prototype.dispose = function () {
|
|
48
|
+
if (this.editor) {
|
|
49
|
+
this.editor
|
|
50
|
+
.getDocument()
|
|
51
|
+
.removeEventListener('selectionchange', this.onNativeSelectionChange);
|
|
52
|
+
this.editor = null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Get plugin state object
|
|
57
|
+
*/
|
|
58
|
+
ContentModelCachePlugin.prototype.getState = function () {
|
|
59
|
+
return this.state;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Core method for a plugin. Once an event happens in editor, editor will call this
|
|
63
|
+
* method of each plugin to handle the event as long as the event is not handled
|
|
64
|
+
* exclusively by another plugin.
|
|
65
|
+
* @param event The event to handle:
|
|
66
|
+
*/
|
|
67
|
+
ContentModelCachePlugin.prototype.onPluginEvent = function (event) {
|
|
68
|
+
if (!this.editor) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
switch (event.eventType) {
|
|
72
|
+
case 0 /* KeyDown */:
|
|
73
|
+
if (this.shouldClearCache(event)) {
|
|
74
|
+
this.invalidateCache();
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case 3 /* Input */:
|
|
78
|
+
{
|
|
79
|
+
this.updateCachedModel(this.editor, true /*forceUpdate*/);
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case 22 /* SelectionChanged */:
|
|
83
|
+
this.updateCachedModel(this.editor);
|
|
84
|
+
break;
|
|
85
|
+
case 7 /* ContentChanged */:
|
|
86
|
+
{
|
|
87
|
+
var _a = event, contentModel = _a.contentModel, selection = _a.selection;
|
|
88
|
+
if (contentModel && this.state.domIndexer) {
|
|
89
|
+
this.state.cachedModel = contentModel;
|
|
90
|
+
this.state.cachedSelection = selection;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.invalidateCache();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
ContentModelCachePlugin.prototype.invalidateCache = function () {
|
|
100
|
+
var _a;
|
|
101
|
+
if (!((_a = this.editor) === null || _a === void 0 ? void 0 : _a.isInShadowEdit())) {
|
|
102
|
+
this.state.cachedModel = undefined;
|
|
103
|
+
this.state.cachedSelection = undefined;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
ContentModelCachePlugin.prototype.updateCachedModel = function (editor, forceUpdate) {
|
|
107
|
+
var _a;
|
|
108
|
+
var cachedSelection = this.state.cachedSelection;
|
|
109
|
+
this.state.cachedSelection = undefined; // Clear it to force getDOMSelection() retrieve the latest selection range
|
|
110
|
+
var newRangeEx = editor.getDOMSelection() || undefined;
|
|
111
|
+
var model = this.state.cachedModel;
|
|
112
|
+
var isSelectionChanged = forceUpdate ||
|
|
113
|
+
!cachedSelection ||
|
|
114
|
+
!newRangeEx ||
|
|
115
|
+
!(0, areSameSelection_1.areSameSelection)(newRangeEx, cachedSelection);
|
|
116
|
+
if (isSelectionChanged) {
|
|
117
|
+
if (!model ||
|
|
118
|
+
!newRangeEx ||
|
|
119
|
+
!((_a = this.state.domIndexer) === null || _a === void 0 ? void 0 : _a.reconcileSelection(model, newRangeEx, cachedSelection))) {
|
|
120
|
+
this.invalidateCache();
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this.state.cachedSelection = newRangeEx;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
this.state.cachedSelection = cachedSelection;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
ContentModelCachePlugin.prototype.shouldClearCache = function (event) {
|
|
131
|
+
var _a;
|
|
132
|
+
var rawEvent = event.rawEvent, handledByEditFeature = event.handledByEditFeature;
|
|
133
|
+
// In these cases we can't update the model, so clear cache:
|
|
134
|
+
// 1. It is already handled by Content Edit Features
|
|
135
|
+
if (handledByEditFeature) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
// 2. Default behavior is prevented, which means other plugins has handled the event
|
|
139
|
+
if (rawEvent.defaultPrevented) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
// 3. ENTER key is pressed. ENTER key will create new paragraph, so need to update cache to reflect this change
|
|
143
|
+
// TODO: Handle ENTER key to better reuse content model
|
|
144
|
+
if (rawEvent.key == 'Enter') {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
// 4. Current selection is image or table or expanded range selection, and is inputting some text
|
|
148
|
+
if ((((_a = this.state.cachedSelection) === null || _a === void 0 ? void 0 : _a.type) != 'range' ||
|
|
149
|
+
!this.state.cachedSelection.range.collapsed) &&
|
|
150
|
+
(0, eventUtils_1.isCharacterValue)(rawEvent)) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
return false;
|
|
154
|
+
};
|
|
155
|
+
return ContentModelCachePlugin;
|
|
156
|
+
}());
|
|
157
|
+
exports.ContentModelCachePlugin = ContentModelCachePlugin;
|
|
158
|
+
/**
|
|
159
|
+
* @internal
|
|
160
|
+
* Create a new instance of ContentModelCachePlugin class.
|
|
161
|
+
* This is mostly for unit test
|
|
162
|
+
* @param state State of this plugin
|
|
163
|
+
*/
|
|
164
|
+
function createContentModelCachePlugin(state) {
|
|
165
|
+
return new ContentModelCachePlugin(state);
|
|
166
|
+
}
|
|
167
|
+
exports.createContentModelCachePlugin = createContentModelCachePlugin;
|
|
168
|
+
});
|
|
169
|
+
//# sourceMappingURL=ContentModelCachePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentModelCachePlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/corePlugin/ContentModelCachePlugin.ts"],"names":[],"mappings":";;;;IAeA;;OAEG;IACH;QAGI;;;WAGG;QACH,iCAAoB,KAAmC;YAAvD,iBAEC;YAFmB,UAAK,GAAL,KAAK,CAA8B;YAN/C,WAAM,GAAyC,IAAI,CAAC;YA8FpD,4BAAuB,GAAG;;gBAC9B,IAAI,MAAA,KAAI,CAAC,MAAM,0CAAE,QAAQ,EAAE,EAAE;oBACzB,KAAI,CAAC,iBAAiB,CAAC,KAAI,CAAC,MAAM,CAAC,CAAC;iBACvC;YACL,CAAC,CAAC;YA3FE,gFAAgF;QACpF,CAAC;QAED;;WAEG;QACH,yCAAO,GAAP;YACI,OAAO,mBAAmB,CAAC;QAC/B,CAAC;QAED;;;;;WAKG;QACH,4CAAU,GAAV,UAAW,MAAe;YACtB,gFAAgF;YAChF,IAAI,CAAC,MAAM,GAAG,MAAqC,CAAC;YACpD,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAChG,CAAC;QAED;;;;WAIG;QACH,yCAAO,GAAP;YACI,IAAI,IAAI,CAAC,MAAM,EAAE;gBACb,IAAI,CAAC,MAAM;qBACN,WAAW,EAAE;qBACb,mBAAmB,CAAC,iBAAiB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;gBAC1E,IAAI,CAAC,MAAM,GAAG,I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IAAI,KAAI,OAAO;gBACxC,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC;gBAChD,IAAA,6BAAgB,EAAC,QAAQ,CAAC,EAC5B;gBACE,OAAO,IAAI,CAAC;aACf;YAED,OAAO,KAAK,CAAC;QACjB,CAAC;QACL,8BAAC;IAAD,CAAC,AAvKD,IAuKC;IAvKY,0DAAuB;IAyKpC;;;;;OAKG;IACH,SAAgB,6BAA6B,CAAC,KAAmC;QAC7E,OAAO,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAFD,sEAEC","sourcesContent":["import { areSameSelection } from './utils/areSameSelection';\nimport { isCharacterValue } from '../publicApi/domUtils/eventUtils';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport type {\n ContentModelCachePluginState,\n ContentModelContentChangedEvent,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\nimport type {\n IEditor,\n PluginEvent,\n PluginKeyDownEvent,\n PluginWithState,\n} from 'roosterjs-editor-types';\n\n/**\n * ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary\n */\nexport class ContentModelCachePlugin implements PluginWithState<ContentModelCachePluginState> {\n private editor: (IEditor & IStandaloneEditor) | null = null;\n\n /**\n * Construct a new instance of ContentModelEditPlugin class\n * @param state State of this plugin\n */\n constructor(private state: ContentModelCachePluginState) {\n // TODO: Remove tempState parameter once we have standalone Content Model editor\n }\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelCache';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n // TODO: Later we may need a different interface for Content Model editor plugin\n this.editor = editor as IEditor & IStandaloneEditor;\n this.editor.getDocument().addEventListener('selectionchange', this.onNativeSelectionChange);\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n if (this.editor) {\n this.editor\n .getDocument()\n .removeEventListener('selectionchange', this.onNativeSelectionChange);\n this.editor = null;\n }\n }\n\n /**\n * Get plugin state object\n */\n getState(): ContentModelCachePluginState {\n return this.state;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.editor) {\n return;\n }\n\n switch (event.eventType) {\n case PluginEventType.KeyDown:\n if (this.shouldClearCache(event)) {\n this.invalidateCache();\n }\n break;\n\n case PluginEventType.Input:\n {\n this.updateCachedModel(this.editor, true /*forceUpdate*/);\n }\n break;\n\n case PluginEventType.SelectionChanged:\n this.updateCachedModel(this.editor);\n break;\n\n case PluginEventType.ContentChanged:\n {\n const { contentModel, selection } = event as ContentModelContentChangedEvent;\n\n if (contentModel && this.state.domIndexer) {\n this.state.cachedModel = contentModel;\n this.state.cachedSelection = selection;\n } else {\n this.invalidateCache();\n }\n }\n\n break;\n }\n }\n\n private onNativeSelectionChange = () => {\n if (this.editor?.hasFocus()) {\n this.updateCachedModel(this.editor);\n }\n };\n\n private invalidateCache() {\n if (!this.editor?.isInShadowEdit()) {\n this.state.cachedModel = undefined;\n this.state.cachedSelection = undefined;\n }\n }\n\n private updateCachedModel(editor: IStandaloneEditor, forceUpdate?: boolean) {\n const cachedSelection = this.state.cachedSelection;\n this.state.cachedSelection = undefined; // Clear it to force getDOMSelection() retrieve the latest selection range\n\n const newRangeEx = editor.getDOMSelection() || undefined;\n const model = this.state.cachedModel;\n const isSelectionChanged =\n forceUpdate ||\n !cachedSelection ||\n !newRangeEx ||\n !areSameSelection(newRangeEx, cachedSelection);\n\n if (isSelectionChanged) {\n if (\n !model ||\n !newRangeEx ||\n !this.state.domIndexer?.reconcileSelection(model, newRangeEx, cachedSelection)\n ) {\n this.invalidateCache();\n } else {\n this.state.cachedSelection = newRangeEx;\n }\n } else {\n this.state.cachedSelection = cachedSelection;\n }\n }\n\n private shouldClearCache(event: PluginKeyDownEvent) {\n const { rawEvent, handledByEditFeature } = event;\n\n // In these cases we can't update the model, so clear cache:\n // 1. It is already handled by Content Edit Features\n if (handledByEditFeature) {\n return true;\n }\n\n // 2. Default behavior is prevented, which means other plugins has handled the event\n if (rawEvent.defaultPrevented) {\n return true;\n }\n\n // 3. ENTER key is pressed. ENTER key will create new paragraph, so need to update cache to reflect this change\n // TODO: Handle ENTER key to better reuse content model\n\n if (rawEvent.key == 'Enter') {\n return true;\n }\n\n // 4. Current selection is image or table or expanded range selection, and is inputting some text\n if (\n (this.state.cachedSelection?.type != 'range' ||\n !this.state.cachedSelection.range.collapsed) &&\n isCharacterValue(rawEvent)\n ) {\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * @internal\n * Create a new instance of ContentModelCachePlugin class.\n * This is mostly for unit test\n * @param state State of this plugin\n */\nexport function createContentModelCachePlugin(state: ContentModelCachePluginState) {\n return new ContentModelCachePlugin(state);\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { OnNodeCreated } from 'roosterjs-content-model-types';
|
|
2
|
+
import type { CopyPastePluginState, IEditor, PluginWithState } from 'roosterjs-editor-types';
|
|
3
|
+
/**
|
|
4
|
+
* Copy and paste plugin for handling onCopy and onPaste event
|
|
5
|
+
*/
|
|
6
|
+
export declare class ContentModelCopyPastePlugin implements PluginWithState<CopyPastePluginState> {
|
|
7
|
+
private state;
|
|
8
|
+
private editor;
|
|
9
|
+
private disposer;
|
|
10
|
+
/**
|
|
11
|
+
* Construct a new instance of CopyPastePlugin
|
|
12
|
+
* @param options The editor options
|
|
13
|
+
*/
|
|
14
|
+
constructor(state: CopyPastePluginState);
|
|
15
|
+
/**
|
|
16
|
+
* Get a friendly name of this plugin
|
|
17
|
+
*/
|
|
18
|
+
getName(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Initialize this plugin. This should only be called from Editor
|
|
21
|
+
* @param editor Editor instance
|
|
22
|
+
*/
|
|
23
|
+
initialize(editor: IEditor): void;
|
|
24
|
+
/**
|
|
25
|
+
* Dispose this plugin
|
|
26
|
+
*/
|
|
27
|
+
dispose(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get plugin state object
|
|
30
|
+
*/
|
|
31
|
+
getState(): CopyPastePluginState;
|
|
32
|
+
private onCutCopy;
|
|
33
|
+
private onPaste;
|
|
34
|
+
private getTempDiv;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
* Exported only for unit testing
|
|
39
|
+
*/
|
|
40
|
+
export declare const onNodeCreated: OnNodeCreated;
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
* Create a new instance of ContentModelCopyPastePlugin
|
|
44
|
+
* @param state The plugin state object
|
|
45
|
+
*/
|
|
46
|
+
export declare function createContentModelCopyPastePlugin(state: CopyPastePluginState): ContentModelCopyPastePlugin;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
define(["require", "exports", "tslib", "./utils/addRangeToSelection", "../constants/ChangeSource", "../publicApi/model/cloneModel", "../publicApi/selection/deleteSelection", "roosterjs-editor-dom", "../publicApi/selection/iterateSelections", "../publicApi/model/paste", "roosterjs-content-model-dom"], function (require, exports, tslib_1, addRangeToSelection_1, ChangeSource_1, cloneModel_1, deleteSelection_1, roosterjs_editor_dom_1, iterateSelections_1, paste_1, roosterjs_content_model_dom_1) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createContentModelCopyPastePlugin = exports.onNodeCreated = exports.ContentModelCopyPastePlugin = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Copy and paste plugin for handling onCopy and onPaste event
|
|
7
|
+
*/
|
|
8
|
+
var ContentModelCopyPastePlugin = /** @class */ (function () {
|
|
9
|
+
/**
|
|
10
|
+
* Construct a new instance of CopyPastePlugin
|
|
11
|
+
* @param options The editor options
|
|
12
|
+
*/
|
|
13
|
+
function ContentModelCopyPastePlugin(state) {
|
|
14
|
+
var _this = this;
|
|
15
|
+
this.state = state;
|
|
16
|
+
this.editor = null;
|
|
17
|
+
this.disposer = null;
|
|
18
|
+
this.onPaste = function (event) {
|
|
19
|
+
if (_this.editor && isClipboardEvent(event)) {
|
|
20
|
+
var editor_1 = _this.editor;
|
|
21
|
+
var dataTransfer = event.clipboardData;
|
|
22
|
+
if (dataTransfer === null || dataTransfer === void 0 ? void 0 : dataTransfer.items) {
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
(0, roosterjs_editor_dom_1.extractClipboardItems)((0, roosterjs_content_model_dom_1.toArray)(dataTransfer.items), {
|
|
25
|
+
allowedCustomPasteType: _this.state.allowedCustomPasteType,
|
|
26
|
+
}, true /*pasteNativeEvent*/).then(function (clipboardData) {
|
|
27
|
+
if (!editor_1.isDisposed()) {
|
|
28
|
+
(0, paste_1.paste)(editor_1, clipboardData);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get a friendly name of this plugin
|
|
37
|
+
*/
|
|
38
|
+
ContentModelCopyPastePlugin.prototype.getName = function () {
|
|
39
|
+
return 'ContentModelCopyPaste';
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Initialize this plugin. This should only be called from Editor
|
|
43
|
+
* @param editor Editor instance
|
|
44
|
+
*/
|
|
45
|
+
ContentModelCopyPastePlugin.prototype.initialize = function (editor) {
|
|
46
|
+
var _this = this;
|
|
47
|
+
this.editor = editor;
|
|
48
|
+
this.disposer = this.editor.addDomEventHandler({
|
|
49
|
+
paste: function (e) { return _this.onPaste(e); },
|
|
50
|
+
copy: function (e) { return _this.onCutCopy(e, false /*isCut*/); },
|
|
51
|
+
cut: function (e) { return _this.onCutCopy(e, true /*isCut*/); },
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Dispose this plugin
|
|
56
|
+
*/
|
|
57
|
+
ContentModelCopyPastePlugin.prototype.dispose = function () {
|
|
58
|
+
if (this.disposer) {
|
|
59
|
+
this.disposer();
|
|
60
|
+
}
|
|
61
|
+
this.disposer = null;
|
|
62
|
+
this.editor = null;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Get plugin state object
|
|
66
|
+
*/
|
|
67
|
+
ContentModelCopyPastePlugin.prototype.getState = function () {
|
|
68
|
+
return this.state;
|
|
69
|
+
};
|
|
70
|
+
ContentModelCopyPastePlugin.prototype.onCutCopy = function (event, isCut) {
|
|
71
|
+
var _this = this;
|
|
72
|
+
if (!this.editor) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var doc = this.editor.getDocument();
|
|
76
|
+
var selection = this.editor.getDOMSelection();
|
|
77
|
+
if (selection && (selection.type != 'range' || !selection.range.collapsed)) {
|
|
78
|
+
var model = this.editor.createContentModel();
|
|
79
|
+
var pasteModel = (0, cloneModel_1.cloneModel)(model, {
|
|
80
|
+
includeCachedElement: this.editor.isDarkMode()
|
|
81
|
+
? function (node, type) {
|
|
82
|
+
var _a;
|
|
83
|
+
if (type == 'cache') {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
var result = node.cloneNode(true /*deep*/);
|
|
88
|
+
(_a = _this.editor) === null || _a === void 0 ? void 0 : _a.transformToDarkColor(result, 1 /* DarkToLight */);
|
|
89
|
+
result.style.color = result.style.color || 'inherit';
|
|
90
|
+
result.style.backgroundColor =
|
|
91
|
+
result.style.backgroundColor || 'inherit';
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
: false,
|
|
96
|
+
});
|
|
97
|
+
if (selection.type === 'table') {
|
|
98
|
+
(0, iterateSelections_1.iterateSelections)(pasteModel, function (_, tableContext) {
|
|
99
|
+
if (tableContext === null || tableContext === void 0 ? void 0 : tableContext.table) {
|
|
100
|
+
var table = tableContext === null || tableContext === void 0 ? void 0 : tableContext.table;
|
|
101
|
+
table.rows = table.rows
|
|
102
|
+
.map(function (row) {
|
|
103
|
+
return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, row), { cells: row.cells.filter(function (cell) { return cell.isSelected; }) });
|
|
104
|
+
})
|
|
105
|
+
.filter(function (row) { return row.cells.length > 0; });
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
var tempDiv_1 = this.getTempDiv(this.editor);
|
|
112
|
+
var selectionForCopy = (0, roosterjs_content_model_dom_1.contentModelToDom)(tempDiv_1.ownerDocument, tempDiv_1, pasteModel, (0, roosterjs_content_model_dom_1.createModelToDomContext)(), exports.onNodeCreated);
|
|
113
|
+
var newRange = selectionForCopy
|
|
114
|
+
? domSelectionToRange(doc, selectionForCopy, tempDiv_1)
|
|
115
|
+
: null;
|
|
116
|
+
if (newRange) {
|
|
117
|
+
newRange = this.editor.triggerPluginEvent(9 /* BeforeCutCopy */, {
|
|
118
|
+
clonedRoot: tempDiv_1,
|
|
119
|
+
range: newRange,
|
|
120
|
+
rawEvent: event,
|
|
121
|
+
isCut: isCut,
|
|
122
|
+
}).range;
|
|
123
|
+
if (newRange) {
|
|
124
|
+
(0, addRangeToSelection_1.addRangeToSelection)(doc, newRange);
|
|
125
|
+
}
|
|
126
|
+
this.editor.runAsync(function (e) {
|
|
127
|
+
var editor = e;
|
|
128
|
+
cleanUpAndRestoreSelection(tempDiv_1);
|
|
129
|
+
editor.focus();
|
|
130
|
+
editor.setDOMSelection(selection);
|
|
131
|
+
if (isCut) {
|
|
132
|
+
editor.formatContentModel(function (model, context) {
|
|
133
|
+
if ((0, deleteSelection_1.deleteSelection)(model, [], context).deleteResult == 'range') {
|
|
134
|
+
(0, roosterjs_content_model_dom_1.normalizeContentModel)(model);
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}, {
|
|
138
|
+
apiName: 'cut',
|
|
139
|
+
changeSource: ChangeSource_1.ChangeSource.Cut,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
cleanUpAndRestoreSelection(tempDiv_1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
ContentModelCopyPastePlugin.prototype.getTempDiv = function (editor) {
|
|
150
|
+
var div = editor.getCustomData('CopyPasteTempDiv', function () {
|
|
151
|
+
var tempDiv = editor.getDocument().createElement('div');
|
|
152
|
+
tempDiv.style.width = '600px';
|
|
153
|
+
tempDiv.style.height = '1px';
|
|
154
|
+
tempDiv.style.overflow = 'hidden';
|
|
155
|
+
tempDiv.style.position = 'fixed';
|
|
156
|
+
tempDiv.style.top = '0';
|
|
157
|
+
tempDiv.style.left = '0';
|
|
158
|
+
tempDiv.style.userSelect = 'text';
|
|
159
|
+
tempDiv.contentEditable = 'true';
|
|
160
|
+
editor.getDocument().body.appendChild(tempDiv);
|
|
161
|
+
return tempDiv;
|
|
162
|
+
}, function (tempDiv) { var _a; return (_a = tempDiv.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(tempDiv); });
|
|
163
|
+
div.style.backgroundColor = 'white';
|
|
164
|
+
div.style.color = 'black';
|
|
165
|
+
div.childNodes.forEach(function (node) { return div.removeChild(node); });
|
|
166
|
+
div.style.display = '';
|
|
167
|
+
div.focus();
|
|
168
|
+
return div;
|
|
169
|
+
};
|
|
170
|
+
return ContentModelCopyPastePlugin;
|
|
171
|
+
}());
|
|
172
|
+
exports.ContentModelCopyPastePlugin = ContentModelCopyPastePlugin;
|
|
173
|
+
function cleanUpAndRestoreSelection(tempDiv) {
|
|
174
|
+
tempDiv.style.backgroundColor = '';
|
|
175
|
+
tempDiv.style.color = '';
|
|
176
|
+
tempDiv.style.display = 'none';
|
|
177
|
+
(0, roosterjs_content_model_dom_1.moveChildNodes)(tempDiv);
|
|
178
|
+
}
|
|
179
|
+
function isClipboardEvent(event) {
|
|
180
|
+
return !!event.clipboardData;
|
|
181
|
+
}
|
|
182
|
+
function domSelectionToRange(doc, selection, tempDiv) {
|
|
183
|
+
var _a;
|
|
184
|
+
var newRange = null;
|
|
185
|
+
if (selection.type === 'table') {
|
|
186
|
+
var table = tempDiv.querySelector("#" + selection.table.id);
|
|
187
|
+
var elementToSelect = ((_a = table.parentElement) === null || _a === void 0 ? void 0 : _a.childElementCount) == 1 ? table.parentElement : table;
|
|
188
|
+
newRange = doc.createRange();
|
|
189
|
+
newRange.selectNode(elementToSelect);
|
|
190
|
+
}
|
|
191
|
+
else if (selection.type === 'image') {
|
|
192
|
+
var image = tempDiv.querySelector('#' + selection.image.id);
|
|
193
|
+
if (image) {
|
|
194
|
+
newRange = doc.createRange();
|
|
195
|
+
newRange.selectNode(image);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
newRange = selection.range;
|
|
200
|
+
}
|
|
201
|
+
return newRange;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* @internal
|
|
205
|
+
* Exported only for unit testing
|
|
206
|
+
*/
|
|
207
|
+
var onNodeCreated = function (_, node) {
|
|
208
|
+
if ((0, roosterjs_content_model_dom_1.isNodeOfType)(node, 'ELEMENT_NODE') && (0, roosterjs_content_model_dom_1.isElementOfType)(node, 'table')) {
|
|
209
|
+
(0, roosterjs_content_model_dom_1.wrap)(node.ownerDocument, node, 'div');
|
|
210
|
+
}
|
|
211
|
+
if ((0, roosterjs_content_model_dom_1.isNodeOfType)(node, 'ELEMENT_NODE') && !node.isContentEditable) {
|
|
212
|
+
node.removeAttribute('contenteditable');
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
exports.onNodeCreated = onNodeCreated;
|
|
216
|
+
/**
|
|
217
|
+
* @internal
|
|
218
|
+
* Create a new instance of ContentModelCopyPastePlugin
|
|
219
|
+
* @param state The plugin state object
|
|
220
|
+
*/
|
|
221
|
+
function createContentModelCopyPastePlugin(state) {
|
|
222
|
+
return new ContentModelCopyPastePlugin(state);
|
|
223
|
+
}
|
|
224
|
+
exports.createContentModelCopyPastePlugin = createContentModelCopyPastePlugin;
|
|
225
|
+
});
|
|
226
|
+
//# sourceMappingURL=ContentModelCopyPastePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentModelCopyPastePlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/corePlugin/ContentModelCopyPastePlugin.ts"],"names":[],"mappings":";;;;IA0BA;;OAEG;IACH;QAII;;;WAGG;QACH,qCAAoB,KAA2B;YAA/C,iBAAmD;YAA/B,UAAK,GAAL,KAAK,CAAsB;YAPvC,WAAM,GAAyC,IAAI,CAAC;YACpD,aAAQ,GAAwB,IAAI,CAAC;YAqJrC,YAAO,GAAG,UAAC,KAAY;gBAC3B,IAAI,KAAI,CAAC,MAAM,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE;oBACxC,IAAM,QAAM,GAAG,KAAI,CAAC,MAAM,CAAC;oBAE3B,IAAM,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC;oBAEzC,IAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK,EAAE;wBACrB,KAAK,CAAC,cAAc,EAAE,CAAC;wBACvB,IAAA,4CAAqB,EACjB,IAAA,qCAAO,EAAC,YAAY,CAAC,KAAK,CAAC,EAC3B;4BACI,sBAAsB,EAAE,KAAI,CAAC,KAAK,CAAC,sBAAsB;yBAC5D,EACD,IAAI,CAAC,oBAAoB,CAC5B,CAAC,IAAI,CAAC,UAAC,aAA4B;4BAChC,IAAI,CAAC,QAAM,CAAC,UAAU,EAAE,EAAE;gCACtB,IAAA,aAAK,EAAC,QAAM,EAAE,aAAa,CAAC,CAAC;6BAChC;wBACL,CAAC,CAAC,CAAC;qBACN;iBACJ;YACL,CAAC,CAAC;QApKgD,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AC,IAAI,KAAK,OAAO,EAAE;YACnC,IAAM,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAE9D,IAAI,KAAK,EAAE;gBACP,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;gBAC7B,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aAC9B;SACJ;aAAM;YACH,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC;SAC9B;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;;OAGG;IACI,IAAM,aAAa,GAAkB,UAAC,CAAC,EAAE,IAAI;QAChD,IAAI,IAAA,0CAAY,EAAC,IAAI,EAAE,cAAc,CAAC,IAAI,IAAA,6CAAe,EAAC,IAAI,EAAE,OAAO,CAAC,EAAE;YACtE,IAAA,kCAAI,EAAC,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;SACzC;QACD,IAAI,IAAA,0CAAY,EAAC,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;YAC/D,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;SAC3C;IACL,CAAC,CAAC;IAPW,QAAA,aAAa,iBAOxB;IAEF;;;;OAIG;IACH,SAAgB,iCAAiC,CAAC,KAA2B;QACzE,OAAO,IAAI,2BAA2B,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAFD,8EAEC","sourcesContent":["import { addRangeToSelection } from './utils/addRangeToSelection';\nimport { ChangeSource } from '../constants/ChangeSource';\nimport { cloneModel } from '../publicApi/model/cloneModel';\nimport { ColorTransformDirection, PluginEventType } from 'roosterjs-editor-types';\nimport { deleteSelection } from '../publicApi/selection/deleteSelection';\nimport { extractClipboardItems } from 'roosterjs-editor-dom';\nimport { iterateSelections } from '../publicApi/selection/iterateSelections';\nimport { paste } from '../publicApi/model/paste';\nimport {\n contentModelToDom,\n createModelToDomContext,\n isElementOfType,\n isNodeOfType,\n moveChildNodes,\n normalizeContentModel,\n toArray,\n wrap,\n} from 'roosterjs-content-model-dom';\nimport type { DOMSelection, IStandaloneEditor, OnNodeCreated } from 'roosterjs-content-model-types';\nimport type {\n CopyPastePluginState,\n IEditor,\n PluginWithState,\n ClipboardData,\n} from 'roosterjs-editor-types';\n\n/**\n * Copy and paste plugin for handling onCopy and onPaste event\n */\nexport class ContentModelCopyPastePlugin implements PluginWithState<CopyPastePluginState> {\n private editor: (IStandaloneEditor & IEditor) | null = null;\n private disposer: (() => void) | null = null;\n\n /**\n * Construct a new instance of CopyPastePlugin\n * @param options The editor options\n */\n constructor(private state: CopyPastePluginState) {}\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'ContentModelCopyPaste';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.editor = editor as IStandaloneEditor & IEditor;\n this.disposer = this.editor.addDomEventHandler({\n paste: e => this.onPaste(e),\n copy: e => this.onCutCopy(e, false /*isCut*/),\n cut: e => this.onCutCopy(e, true /*isCut*/),\n });\n }\n\n /**\n * Dispose this plugin\n */\n dispose() {\n if (this.disposer) {\n this.disposer();\n }\n this.disposer = null;\n this.editor = null;\n }\n\n /**\n * Get plugin state object\n */\n getState() {\n return this.state;\n }\n\n private onCutCopy(event: Event, isCut: boolean) {\n if (!this.editor) {\n return;\n }\n\n const doc = this.editor.getDocument();\n const selection = this.editor.getDOMSelection();\n\n if (selection && (selection.type != 'range' || !selection.range.collapsed)) {\n const model = this.editor.createContentModel();\n\n const pasteModel = cloneModel(model, {\n includeCachedElement: this.editor.isDarkMode()\n ? (node, type) => {\n if (type == 'cache') {\n return undefined;\n } else {\n const result = node.cloneNode(true /*deep*/) as HTMLElement;\n\n this.editor?.transformToDarkColor(\n result,\n ColorTransformDirection.DarkToLight\n );\n\n result.style.color = result.style.color || 'inherit';\n result.style.backgroundColor =\n result.style.backgroundColor || 'inherit';\n\n return result;\n }\n }\n : false,\n });\n if (selection.type === 'table') {\n iterateSelections(pasteModel, (_, tableContext) => {\n if (tableContext?.table) {\n const table = tableContext?.table;\n table.rows = table.rows\n .map(row => {\n return {\n ...row,\n cells: row.cells.filter(cell => cell.isSelected),\n };\n })\n .filter(row => row.cells.length > 0);\n return true;\n }\n return false;\n });\n }\n const tempDiv = this.getTempDiv(this.editor);\n const selectionForCopy = contentModelToDom(\n tempDiv.ownerDocument,\n tempDiv,\n pasteModel,\n createModelToDomContext(),\n onNodeCreated\n );\n\n let newRange: Range | null = selectionForCopy\n ? domSelectionToRange(doc, selectionForCopy, tempDiv)\n : null;\n if (newRange) {\n newRange = this.editor.triggerPluginEvent(PluginEventType.BeforeCutCopy, {\n clonedRoot: tempDiv,\n range: newRange,\n rawEvent: event as ClipboardEvent,\n isCut,\n }).range;\n\n if (newRange) {\n addRangeToSelection(doc, newRange);\n }\n\n this.editor.runAsync(e => {\n const editor = e as IStandaloneEditor & IEditor;\n\n cleanUpAndRestoreSelection(tempDiv);\n editor.focus();\n editor.setDOMSelection(selection);\n\n if (isCut) {\n editor.formatContentModel(\n (model, context) => {\n if (deleteSelection(model, [], context).deleteResult == 'range') {\n normalizeContentModel(model);\n }\n\n return true;\n },\n {\n apiName: 'cut',\n changeSource: ChangeSource.Cut,\n }\n );\n }\n });\n } else {\n cleanUpAndRestoreSelection(tempDiv);\n }\n }\n }\n\n private onPaste = (event: Event) => {\n if (this.editor && isClipboardEvent(event)) {\n const editor = this.editor;\n\n const dataTransfer = event.clipboardData;\n\n if (dataTransfer?.items) {\n event.preventDefault();\n extractClipboardItems(\n toArray(dataTransfer.items),\n {\n allowedCustomPasteType: this.state.allowedCustomPasteType,\n },\n true /*pasteNativeEvent*/\n ).then((clipboardData: ClipboardData) => {\n if (!editor.isDisposed()) {\n paste(editor, clipboardData);\n }\n });\n }\n }\n };\n\n private getTempDiv(editor: IEditor) {\n const div = editor.getCustomData(\n 'CopyPasteTempDiv',\n () => {\n const tempDiv = editor.getDocument().createElement('div');\n\n tempDiv.style.width = '600px';\n tempDiv.style.height = '1px';\n tempDiv.style.overflow = 'hidden';\n tempDiv.style.position = 'fixed';\n tempDiv.style.top = '0';\n tempDiv.style.left = '0';\n tempDiv.style.userSelect = 'text';\n tempDiv.contentEditable = 'true';\n\n editor.getDocument().body.appendChild(tempDiv);\n\n return tempDiv;\n },\n tempDiv => tempDiv.parentNode?.removeChild(tempDiv)\n );\n\n div.style.backgroundColor = 'white';\n div.style.color = 'black';\n div.childNodes.forEach(node => div.removeChild(node));\n\n div.style.display = '';\n div.focus();\n\n return div;\n }\n}\n\nfunction cleanUpAndRestoreSelection(tempDiv: HTMLDivElement) {\n tempDiv.style.backgroundColor = '';\n tempDiv.style.color = '';\n tempDiv.style.display = 'none';\n moveChildNodes(tempDiv);\n}\n\nfunction isClipboardEvent(event: Event): event is ClipboardEvent {\n return !!(event as ClipboardEvent).clipboardData;\n}\n\nfunction domSelectionToRange(\n doc: Document,\n selection: DOMSelection,\n tempDiv: HTMLDivElement\n): Range | null {\n let newRange: Range | null = null;\n\n if (selection.type === 'table') {\n const table = tempDiv.querySelector(`#${selection.table.id}`) as HTMLTableElement;\n const elementToSelect =\n table.parentElement?.childElementCount == 1 ? table.parentElement : table;\n\n newRange = doc.createRange();\n newRange.selectNode(elementToSelect);\n } else if (selection.type === 'image') {\n const image = tempDiv.querySelector('#' + selection.image.id);\n\n if (image) {\n newRange = doc.createRange();\n newRange.selectNode(image);\n }\n } else {\n newRange = selection.range;\n }\n\n return newRange;\n}\n\n/**\n * @internal\n * Exported only for unit testing\n */\nexport const onNodeCreated: OnNodeCreated = (_, node): void => {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isElementOfType(node, 'table')) {\n wrap(node.ownerDocument, node, 'div');\n }\n if (isNodeOfType(node, 'ELEMENT_NODE') && !node.isContentEditable) {\n node.removeAttribute('contenteditable');\n }\n};\n\n/**\n * @internal\n * Create a new instance of ContentModelCopyPastePlugin\n * @param state The plugin state object\n */\nexport function createContentModelCopyPastePlugin(state: CopyPastePluginState) {\n return new ContentModelCopyPastePlugin(state);\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';
|
|
2
|
+
import type { ContentModelFormatPluginState } from 'roosterjs-content-model-types';
|
|
3
|
+
/**
|
|
4
|
+
* ContentModelFormat plugins helps editor to do formatting on top of content model.
|
|
5
|
+
* This includes:
|
|
6
|
+
* 1. Handle pending format changes when selection is collapsed
|
|
7
|
+
*/
|
|
8
|
+
export declare class ContentModelFormatPlugin implements PluginWithState<ContentModelFormatPluginState> {
|
|
9
|
+
private state;
|
|
10
|
+
private editor;
|
|
11
|
+
private hasDefaultFormat;
|
|
12
|
+
/**
|
|
13
|
+
* Construct a new instance of ContentModelEditPlugin class
|
|
14
|
+
* @param state State of this plugin
|
|
15
|
+
*/
|
|
16
|
+
constructor(state: ContentModelFormatPluginState);
|
|
17
|
+
/**
|
|
18
|
+
* Get name of this plugin
|
|
19
|
+
*/
|
|
20
|
+
getName(): string;
|
|
21
|
+
/**
|
|
22
|
+
* The first method that editor will call to a plugin when editor is initializing.
|
|
23
|
+
* It will pass in the editor instance, plugin should take this chance to save the
|
|
24
|
+
* editor reference so that it can call to any editor method or format API later.
|
|
25
|
+
* @param editor The editor object
|
|
26
|
+
*/
|
|
27
|
+
initialize(editor: IEditor): void;
|
|
28
|
+
/**
|
|
29
|
+
* The last method that editor will call to a plugin before it is disposed.
|
|
30
|
+
* Plugin can take this chance to clear the reference to editor. After this method is
|
|
31
|
+
* called, plugin should not call to any editor method since it will result in error.
|
|
32
|
+
*/
|
|
33
|
+
dispose(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get plugin state object
|
|
36
|
+
*/
|
|
37
|
+
getState(): ContentModelFormatPluginState;
|
|
38
|
+
/**
|
|
39
|
+
* Core method for a plugin. Once an event happens in editor, editor will call this
|
|
40
|
+
* method of each plugin to handle the event as long as the event is not handled
|
|
41
|
+
* exclusively by another plugin.
|
|
42
|
+
* @param event The event to handle:
|
|
43
|
+
*/
|
|
44
|
+
onPluginEvent(event: PluginEvent): void;
|
|
45
|
+
private checkAndApplyPendingFormat;
|
|
46
|
+
private clearPendingFormat;
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
* Check if this editor can apply pending format
|
|
50
|
+
* @param editor The editor to get format from
|
|
51
|
+
*/
|
|
52
|
+
private canApplyPendingFormat;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @internal
|
|
56
|
+
* Create a new instance of ContentModelFormatPlugin.
|
|
57
|
+
* This is mostly for unit test
|
|
58
|
+
*/
|
|
59
|
+
export declare function createContentModelFormatPlugin(state: ContentModelFormatPluginState): ContentModelFormatPlugin;
|