roosterjs-editor-adapter 0.26.3 → 0.27.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/corePlugins/BridgePlugin.d.ts +5 -3
- package/lib/corePlugins/BridgePlugin.js +26 -19
- package/lib/corePlugins/BridgePlugin.js.map +1 -1
- package/lib/editor/EditorAdapter.d.ts +5 -5
- package/lib/editor/EditorAdapter.js +28 -28
- package/lib/editor/EditorAdapter.js.map +1 -1
- package/lib/publicTypes/EditorAdapterOptions.d.ts +2 -2
- package/lib/publicTypes/EditorAdapterOptions.js.map +1 -1
- package/lib-amd/corePlugins/BridgePlugin.d.ts +5 -3
- package/lib-amd/corePlugins/BridgePlugin.js +26 -20
- package/lib-amd/corePlugins/BridgePlugin.js.map +1 -1
- package/lib-amd/editor/EditorAdapter.d.ts +5 -5
- package/lib-amd/editor/EditorAdapter.js +28 -28
- package/lib-amd/editor/EditorAdapter.js.map +1 -1
- package/lib-amd/publicTypes/EditorAdapterOptions.d.ts +2 -2
- package/lib-amd/publicTypes/EditorAdapterOptions.js.map +1 -1
- package/lib-mjs/corePlugins/BridgePlugin.d.ts +5 -3
- package/lib-mjs/corePlugins/BridgePlugin.js +26 -19
- package/lib-mjs/corePlugins/BridgePlugin.js.map +1 -1
- package/lib-mjs/editor/EditorAdapter.d.ts +5 -5
- package/lib-mjs/editor/EditorAdapter.js +29 -29
- package/lib-mjs/editor/EditorAdapter.js.map +1 -1
- package/lib-mjs/publicTypes/EditorAdapterOptions.d.ts +2 -2
- package/lib-mjs/publicTypes/EditorAdapterOptions.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EditorPlugin as LegacyEditorPlugin, ContextMenuProvider as LegacyContextMenuProvider, IEditor as ILegacyEditor, ExperimentalFeatures, SizeTransformer, EditPluginState, CustomData, DarkColorHandler } from 'roosterjs-editor-types';
|
|
2
|
-
import type { ContextMenuProvider,
|
|
2
|
+
import type { ContextMenuProvider, IEditor, PluginEvent } from 'roosterjs-content-model-types';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
* Represents the core data structure of a editor adapter
|
|
@@ -51,7 +51,7 @@ export declare class BridgePlugin implements ContextMenuProvider<any> {
|
|
|
51
51
|
* Initialize this plugin. This should only be called from Editor
|
|
52
52
|
* @param editor Editor instance
|
|
53
53
|
*/
|
|
54
|
-
initialize(editor:
|
|
54
|
+
initialize(editor: IEditor): void;
|
|
55
55
|
/**
|
|
56
56
|
* Dispose this plugin
|
|
57
57
|
*/
|
|
@@ -64,10 +64,12 @@ export declare class BridgePlugin implements ContextMenuProvider<any> {
|
|
|
64
64
|
* @returns An array of context menu items, or null means no items needed
|
|
65
65
|
*/
|
|
66
66
|
getContextMenuItems(target: Node): any[];
|
|
67
|
+
private cacheGetExclusivelyHandlePlugin;
|
|
68
|
+
private cacheGetOldEvent;
|
|
67
69
|
private createEditorCore;
|
|
68
70
|
}
|
|
69
71
|
/**
|
|
70
72
|
* @internal Export for test only. This function is only used for compatibility from older build
|
|
71
73
|
|
|
72
74
|
*/
|
|
73
|
-
export declare function createSizeTransformer(editor:
|
|
75
|
+
export declare function createSizeTransformer(editor: IEditor): SizeTransformer;
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSizeTransformer = exports.BridgePlugin = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
5
6
|
var DarkColorHandlerImpl_1 = require("../editor/DarkColorHandlerImpl");
|
|
6
7
|
var EditPlugin_1 = require("./EditPlugin");
|
|
7
8
|
var eventConverter_1 = require("../editor/utils/eventConverter");
|
|
8
9
|
var ExclusivelyHandleEventPluginKey = '__ExclusivelyHandleEventPlugin';
|
|
10
|
+
var OldEventKey = '__OldEventFromNewEvent';
|
|
9
11
|
/**
|
|
10
12
|
* @internal
|
|
11
13
|
* Act as a bridge between Standalone editor and Content Model editor, translate Standalone editor event type to legacy event type
|
|
@@ -46,29 +48,15 @@ var BridgePlugin = /** @class */ (function () {
|
|
|
46
48
|
}
|
|
47
49
|
};
|
|
48
50
|
BridgePlugin.prototype.willHandleEventExclusively = function (event) {
|
|
49
|
-
|
|
50
|
-
var oldEvent;
|
|
51
|
-
if (this.checkExclusivelyHandling && (oldEvent = (0, eventConverter_1.newEventToOldEvent)(event))) {
|
|
52
|
-
for (var i = 0; i < this.legacyPlugins.length; i++) {
|
|
53
|
-
var plugin = this.legacyPlugins[i];
|
|
54
|
-
if ((_a = plugin.willHandleEventExclusively) === null || _a === void 0 ? void 0 : _a.call(plugin, oldEvent)) {
|
|
55
|
-
if (!event.eventDataCache) {
|
|
56
|
-
event.eventDataCache = {};
|
|
57
|
-
}
|
|
58
|
-
event.eventDataCache[ExclusivelyHandleEventPluginKey] = plugin;
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return false;
|
|
51
|
+
return this.checkExclusivelyHandling && !!this.cacheGetExclusivelyHandlePlugin(event);
|
|
64
52
|
};
|
|
65
53
|
BridgePlugin.prototype.onPluginEvent = function (event) {
|
|
66
|
-
var _a
|
|
67
|
-
var oldEvent =
|
|
54
|
+
var _a;
|
|
55
|
+
var oldEvent = this.cacheGetOldEvent(event);
|
|
68
56
|
if (oldEvent) {
|
|
69
|
-
var exclusivelyHandleEventPlugin = (
|
|
57
|
+
var exclusivelyHandleEventPlugin = this.cacheGetExclusivelyHandlePlugin(event);
|
|
70
58
|
if (exclusivelyHandleEventPlugin) {
|
|
71
|
-
(
|
|
59
|
+
(_a = exclusivelyHandleEventPlugin.onPluginEvent) === null || _a === void 0 ? void 0 : _a.call(exclusivelyHandleEventPlugin, oldEvent);
|
|
72
60
|
}
|
|
73
61
|
else {
|
|
74
62
|
this.legacyPlugins.forEach(function (plugin) { var _a; return (_a = plugin.onPluginEvent) === null || _a === void 0 ? void 0 : _a.call(plugin, oldEvent); });
|
|
@@ -95,6 +83,25 @@ var BridgePlugin = /** @class */ (function () {
|
|
|
95
83
|
});
|
|
96
84
|
return allItems;
|
|
97
85
|
};
|
|
86
|
+
BridgePlugin.prototype.cacheGetExclusivelyHandlePlugin = function (event) {
|
|
87
|
+
var _this = this;
|
|
88
|
+
return (0, roosterjs_content_model_core_1.cacheGetEventData)(event, ExclusivelyHandleEventPluginKey, function (event) {
|
|
89
|
+
var _a;
|
|
90
|
+
var oldEvent = _this.cacheGetOldEvent(event);
|
|
91
|
+
if (oldEvent) {
|
|
92
|
+
for (var i = 0; i < _this.legacyPlugins.length; i++) {
|
|
93
|
+
var plugin = _this.legacyPlugins[i];
|
|
94
|
+
if ((_a = plugin.willHandleEventExclusively) === null || _a === void 0 ? void 0 : _a.call(plugin, oldEvent)) {
|
|
95
|
+
return plugin;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
BridgePlugin.prototype.cacheGetOldEvent = function (event) {
|
|
103
|
+
return (0, roosterjs_content_model_core_1.cacheGetEventData)(event, OldEventKey, eventConverter_1.newEventToOldEvent);
|
|
104
|
+
};
|
|
98
105
|
BridgePlugin.prototype.createEditorCore = function (editor) {
|
|
99
106
|
var _a;
|
|
100
107
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BridgePlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-editor-adapter/lib/corePlugins/BridgePlugin.ts"],"names":[],"mappings":";;;;AAAA,uEAAwE;AACxE,2CAAgD;AAChD,iEAAwF;AAkBxF,IAAM,+BAA+B,GAAG,gCAAgC,CAAC;AAuCzE;;;GAGG;AACH;IAMI,sBACY,YAAwD,EAChE,aAAwC,EAChC,oBAAiD;QADzD,8BAAA,EAAA,kBAAwC;QAChC,qCAAA,EAAA,yBAAiD;QAFjD,iBAAY,GAAZ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orHandler } from '../editor/DarkColorHandlerImpl';\nimport { createEditPlugin } from './EditPlugin';\nimport { newEventToOldEvent, oldEventToNewEvent } from '../editor/utils/eventConverter';\nimport type {\n EditorPlugin as LegacyEditorPlugin,\n PluginEvent as LegacyPluginEvent,\n ContextMenuProvider as LegacyContextMenuProvider,\n IEditor as ILegacyEditor,\n ExperimentalFeatures,\n SizeTransformer,\n EditPluginState,\n CustomData,\n DarkColorHandler,\n} from 'roosterjs-editor-types';\nimport type {\n ContextMenuProvider,\n IStandaloneEditor,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst ExclusivelyHandleEventPluginKey = '__ExclusivelyHandleEventPlugin';\n\n/**\n * @internal\n * Represents the core data structure of a editor adapter\n */\nexport interface EditorAdapterCore {\n /**\n * Custom data of this editor\n */\n readonly customData: Record<string, CustomData>;\n\n /**\n * Enabled experimental features\n */\n readonly experimentalFeatures: ExperimentalFeatures[];\n\n /**\n * Dark model handler for the editor, used for variable-based solution.\n * If keep it null, editor will still use original dataset-based dark mode solution.\n */\n readonly darkColorHandler: DarkColorHandler;\n\n /**\n * Plugin state of EditPlugin\n */\n readonly edit: EditPluginState;\n\n /**\n * Context Menu providers\n */\n readonly contextMenuProviders: LegacyContextMenuProvider<any>[];\n\n /**\n * @deprecated Use zoomScale instead\n */\n readonly sizeTransformer: SizeTransformer;\n}\n\n/**\n * @internal\n * Act as a bridge between Standalone editor and Content Model editor, translate Standalone editor event type to legacy event type\n */\nexport class BridgePlugin implements ContextMenuProvider<any> {\n private legacyPlugins: LegacyEditorPlugin[];\n private edit: EditPluginState;\n private contextMenuProviders: LegacyContextMenuProvider<any>[];\n private checkExclusivelyHandling: boolean;\n\n constructor(\n private onInitialize: (core: EditorAdapterCore) => ILegacyEditor,\n legacyPlugins: LegacyEditorPlugin[] = [],\n private experimentalFeatures: ExperimentalFeatures[] = []\n ) {\n const editPlugin = createEditPlugin();\n\n this.legacyPlugins = [editPlugin, ...legacyPlugins.filter(x => !!x)];\n this.edit = editPlugin.getState();\n this.contextMenuProviders = this.legacyPlugins.filter(isContextMenuProvider);\n this.checkExclusivelyHandling = this.legacyPlugins.some(\n plugin => plugin.willHandleEventExclusively\n );\n }\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'Bridge';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IStandaloneEditor) {\n const outerEditor = this.onInitialize(this.createEditorCore(editor));\n\n this.legacyPlugins.forEach(plugin => plugin.initialize(outerEditor));\n }\n\n /**\n * Dispose this plugin\n */\n dispose() {\n for (let i = this.legacyPlugins.length - 1; i >= 0; i--) {\n const plugin = this.legacyPlugins[i];\n\n plugin.dispose();\n }\n }\n\n willHandleEventExclusively(event: PluginEvent) {\n let oldEvent: LegacyPluginEvent | undefined;\n\n if (this.checkExclusivelyHandling && (oldEvent = newEventToOldEvent(event))) {\n for (let i = 0; i < this.legacyPlugins.length; i++) {\n const plugin = this.legacyPlugins[i];\n\n if (plugin.willHandleEventExclusively?.(oldEvent)) {\n if (!event.eventDataCache) {\n event.eventDataCache = {};\n }\n\n event.eventDataCache[ExclusivelyHandleEventPluginKey] = plugin;\n return true;\n }\n }\n }\n\n return false;\n }\n\n onPluginEvent(event: PluginEvent) {\n const oldEvent = newEventToOldEvent(event);\n\n if (oldEvent) {\n const exclusivelyHandleEventPlugin = event.eventDataCache?.[\n ExclusivelyHandleEventPluginKey\n ] as LegacyEditorPlugin | undefined;\n\n if (exclusivelyHandleEventPlugin) {\n exclusivelyHandleEventPlugin.onPluginEvent?.(oldEvent);\n } else {\n this.legacyPlugins.forEach(plugin => plugin.onPluginEvent?.(oldEvent));\n }\n\n Object.assign(event, oldEventToNewEvent(oldEvent, event));\n }\n }\n\n /**\n * A callback to return context menu items\n * @param target Target node that triggered a ContextMenu event\n * @returns An array of context menu items, or null means no items needed\n */\n getContextMenuItems(target: Node): any[] {\n const allItems: any[] = [];\n\n this.contextMenuProviders.forEach(provider => {\n const items = provider.getContextMenuItems(target) ?? [];\n if (items?.length > 0) {\n if (allItems.length > 0) {\n allItems.push(null);\n }\n\n allItems.push(...items);\n }\n });\n\n return allItems;\n }\n\n private createEditorCore(editor: IStandaloneEditor): EditorAdapterCore {\n return {\n customData: {},\n experimentalFeatures: this.experimentalFeatures ?? [],\n sizeTransformer: createSizeTransformer(editor),\n darkColorHandler: createDarkColorHandler(editor.getColorManager()),\n edit: this.edit,\n contextMenuProviders: this.contextMenuProviders,\n };\n }\n}\n\n/**\n * @internal Export for test only. This function is only used for compatibility from older build\n\n */\nexport function createSizeTransformer(editor: IStandaloneEditor): SizeTransformer {\n return size => size / editor.getDOMHelper().calculateZoomScale();\n}\n\nfunction isContextMenuProvider(\n source: LegacyEditorPlugin\n): source is LegacyContextMenuProvider<any> {\n return !!(<LegacyContextMenuProvider<any>>source)?.getContextMenuItems;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BridgePlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-editor-adapter/lib/corePlugins/BridgePlugin.ts"],"names":[],"mappings":";;;;AAAA,6EAAiE;AACjE,uEAAwE;AACxE,2CAAgD;AAChD,iEAAwF;AAaxF,IAAM,+BAA+B,GAAG,gCAAgC,CAAC;AACzE,IAAM,WAAW,GAAG,wBAAwB,CAAC;AAuC7C;;;GAGG;AACH;IAMI,sBACY,YAAwD,EAChE,aAAwC,EAChC,oBAAiD;QADzD,8BAAA,EAAA,kBAAwC;QAChC,qCAAA,EAAA,yBAAiD;QAFjD,iBAAY,GAAZ,YAAY,CAA4C;QAExD,yBAAoB,GAApB,oBAAoB,CAA6B;QAEzD,IAAM,UAAU,GAAG,IAAA,6BAAgB,GAAE,CAAC;QAEtC,IAAI,CAAC,aAAa,+BAAI,UAAU,uBAAK,aAAa,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,EAAH,CAAG,CAAC,SAAC,CAAC;QACrE,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,QAA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AAE,CAAC,EAAE,EAAE;oBAChD,IAAM,MAAM,GAAG,KAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;oBAErC,IAAI,MAAA,MAAM,CAAC,0BAA0B,+CAAjC,MAAM,EAA8B,QAAQ,CAAC,EAAE;wBAC/C,OAAO,MAAM,CAAC;qBACjB;iBACJ;aACJ;YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,uCAAgB,GAAxB,UAAyB,KAAkB;QACvC,OAAO,IAAA,gDAAiB,EAAC,KAAK,EAAE,WAAW,EAAE,mCAAkB,CAAC,CAAC;IACrE,CAAC;IAEO,uCAAgB,GAAxB,UAAyB,MAAe;;QACpC,OAAO;YACH,UAAU,EAAE,EAAE;YACd,oBAAoB,EAAE,MAAA,IAAI,CAAC,oBAAoB,mCAAI,EAAE;YACrD,eAAe,EAAE,qBAAqB,CAAC,MAAM,CAAC;YAC9C,gBAAgB,EAAE,IAAA,6CAAsB,EAAC,MAAM,CAAC,eAAe,EAAE,CAAC;YAClE,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;SAClD,CAAC;IACN,CAAC;IACL,mBAAC;AAAD,CAAC,AA3HD,IA2HC;AA3HY,oCAAY;AA6HzB;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,MAAe;IACjD,OAAO,UAAA,IAAI,IAAI,OAAA,IAAI,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,kBAAkB,EAAE,EAAjD,CAAiD,CAAC;AACrE,CAAC;AAFD,sDAEC;AAED,SAAS,qBAAqB,CAC1B,MAA0B;;IAE1B,OAAO,CAAC,CAAC,CAAA,MAAiC,MAAO,0CAAE,mBAAmB,CAAA,CAAC;AAC3E,CAAC","sourcesContent":["import { cacheGetEventData } from 'roosterjs-content-model-core';\nimport { createDarkColorHandler } from '../editor/DarkColorHandlerImpl';\nimport { createEditPlugin } from './EditPlugin';\nimport { newEventToOldEvent, oldEventToNewEvent } from '../editor/utils/eventConverter';\nimport type {\n EditorPlugin as LegacyEditorPlugin,\n ContextMenuProvider as LegacyContextMenuProvider,\n IEditor as ILegacyEditor,\n ExperimentalFeatures,\n SizeTransformer,\n EditPluginState,\n CustomData,\n DarkColorHandler,\n} from 'roosterjs-editor-types';\nimport type { ContextMenuProvider, IEditor, PluginEvent } from 'roosterjs-content-model-types';\n\nconst ExclusivelyHandleEventPluginKey = '__ExclusivelyHandleEventPlugin';\nconst OldEventKey = '__OldEventFromNewEvent';\n\n/**\n * @internal\n * Represents the core data structure of a editor adapter\n */\nexport interface EditorAdapterCore {\n /**\n * Custom data of this editor\n */\n readonly customData: Record<string, CustomData>;\n\n /**\n * Enabled experimental features\n */\n readonly experimentalFeatures: ExperimentalFeatures[];\n\n /**\n * Dark model handler for the editor, used for variable-based solution.\n * If keep it null, editor will still use original dataset-based dark mode solution.\n */\n readonly darkColorHandler: DarkColorHandler;\n\n /**\n * Plugin state of EditPlugin\n */\n readonly edit: EditPluginState;\n\n /**\n * Context Menu providers\n */\n readonly contextMenuProviders: LegacyContextMenuProvider<any>[];\n\n /**\n * @deprecated Use zoomScale instead\n */\n readonly sizeTransformer: SizeTransformer;\n}\n\n/**\n * @internal\n * Act as a bridge between Standalone editor and Content Model editor, translate Standalone editor event type to legacy event type\n */\nexport class BridgePlugin implements ContextMenuProvider<any> {\n private legacyPlugins: LegacyEditorPlugin[];\n private edit: EditPluginState;\n private contextMenuProviders: LegacyContextMenuProvider<any>[];\n private checkExclusivelyHandling: boolean;\n\n constructor(\n private onInitialize: (core: EditorAdapterCore) => ILegacyEditor,\n legacyPlugins: LegacyEditorPlugin[] = [],\n private experimentalFeatures: ExperimentalFeatures[] = []\n ) {\n const editPlugin = createEditPlugin();\n\n this.legacyPlugins = [editPlugin, ...legacyPlugins.filter(x => !!x)];\n this.edit = editPlugin.getState();\n this.contextMenuProviders = this.legacyPlugins.filter(isContextMenuProvider);\n this.checkExclusivelyHandling = this.legacyPlugins.some(\n plugin => plugin.willHandleEventExclusively\n );\n }\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'Bridge';\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 const outerEditor = this.onInitialize(this.createEditorCore(editor));\n\n this.legacyPlugins.forEach(plugin => plugin.initialize(outerEditor));\n }\n\n /**\n * Dispose this plugin\n */\n dispose() {\n for (let i = this.legacyPlugins.length - 1; i >= 0; i--) {\n const plugin = this.legacyPlugins[i];\n\n plugin.dispose();\n }\n }\n\n willHandleEventExclusively(event: PluginEvent) {\n return this.checkExclusivelyHandling && !!this.cacheGetExclusivelyHandlePlugin(event);\n }\n\n onPluginEvent(event: PluginEvent) {\n const oldEvent = this.cacheGetOldEvent(event);\n\n if (oldEvent) {\n const exclusivelyHandleEventPlugin = this.cacheGetExclusivelyHandlePlugin(event);\n\n if (exclusivelyHandleEventPlugin) {\n exclusivelyHandleEventPlugin.onPluginEvent?.(oldEvent);\n } else {\n this.legacyPlugins.forEach(plugin => plugin.onPluginEvent?.(oldEvent));\n }\n\n Object.assign(event, oldEventToNewEvent(oldEvent, event));\n }\n }\n\n /**\n * A callback to return context menu items\n * @param target Target node that triggered a ContextMenu event\n * @returns An array of context menu items, or null means no items needed\n */\n getContextMenuItems(target: Node): any[] {\n const allItems: any[] = [];\n\n this.contextMenuProviders.forEach(provider => {\n const items = provider.getContextMenuItems(target) ?? [];\n if (items?.length > 0) {\n if (allItems.length > 0) {\n allItems.push(null);\n }\n\n allItems.push(...items);\n }\n });\n\n return allItems;\n }\n\n private cacheGetExclusivelyHandlePlugin(event: PluginEvent) {\n return cacheGetEventData(event, ExclusivelyHandleEventPluginKey, event => {\n const oldEvent = this.cacheGetOldEvent(event);\n\n if (oldEvent) {\n for (let i = 0; i < this.legacyPlugins.length; i++) {\n const plugin = this.legacyPlugins[i];\n\n if (plugin.willHandleEventExclusively?.(oldEvent)) {\n return plugin;\n }\n }\n }\n\n return null;\n });\n }\n\n private cacheGetOldEvent(event: PluginEvent) {\n return cacheGetEventData(event, OldEventKey, newEventToOldEvent);\n }\n\n private createEditorCore(editor: IEditor): EditorAdapterCore {\n return {\n customData: {},\n experimentalFeatures: this.experimentalFeatures ?? [],\n sizeTransformer: createSizeTransformer(editor),\n darkColorHandler: createDarkColorHandler(editor.getColorManager()),\n edit: this.edit,\n contextMenuProviders: this.contextMenuProviders,\n };\n }\n}\n\n/**\n * @internal Export for test only. This function is only used for compatibility from older build\n\n */\nexport function createSizeTransformer(editor: IEditor): SizeTransformer {\n return size => size / editor.getDOMHelper().calculateZoomScale();\n}\n\nfunction isContextMenuProvider(\n source: LegacyEditorPlugin\n): source is LegacyContextMenuProvider<any> {\n return !!(<LegacyContextMenuProvider<any>>source)?.getContextMenuItems;\n}\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Editor } from 'roosterjs-content-model-core';
|
|
2
2
|
import { ChangeSource, ColorTransformDirection, ContentPosition, GetContentMode, PluginEventType, QueryScope, RegionType } from 'roosterjs-editor-types';
|
|
3
|
-
import type { BlockElement, ClipboardData, ContentChangedData, DOMEventHandler, DefaultFormat, EditorUndoState, ExperimentalFeatures, GenericContentEditFeature, IContentTraverser, IPositionContentSearcher, InsertOption, NodePosition, PendableFormatState, PluginEvent, PluginEventData, PluginEventFromType, PositionType, Region, SelectionPath, SelectionRangeEx, SizeTransformer, StyleBasedFormatState, TableSelection, DarkColorHandler, IEditor } from 'roosterjs-editor-types';
|
|
3
|
+
import type { BlockElement, ClipboardData, ContentChangedData, DOMEventHandler, DefaultFormat, EditorUndoState, ExperimentalFeatures, GenericContentEditFeature, IContentTraverser, IPositionContentSearcher, InsertOption, NodePosition, PendableFormatState, PluginEvent, PluginEventData, PluginEventFromType, PositionType, Region, SelectionPath, SelectionRangeEx, SizeTransformer, StyleBasedFormatState, TableSelection, DarkColorHandler, IEditor as ILegacyEditor } from 'roosterjs-editor-types';
|
|
4
4
|
import type { CompatibleChangeSource, CompatibleColorTransformDirection, CompatibleContentPosition, CompatibleExperimentalFeatures, CompatibleGetContentMode, CompatiblePluginEventType, CompatibleQueryScope, CompatibleRegionType } from 'roosterjs-editor-types/lib/compatibleTypes';
|
|
5
5
|
import type { EditorAdapterOptions } from '../publicTypes/EditorAdapterOptions';
|
|
6
|
-
import type {
|
|
6
|
+
import type { IEditor } from 'roosterjs-content-model-types';
|
|
7
7
|
/**
|
|
8
8
|
* Editor for Content Model.
|
|
9
9
|
* (This class is still under development, and may still be changed in the future with some breaking changes)
|
|
10
10
|
*/
|
|
11
|
-
export declare class EditorAdapter extends
|
|
11
|
+
export declare class EditorAdapter extends Editor implements ILegacyEditor {
|
|
12
12
|
private contentModelEditorCore;
|
|
13
13
|
/**
|
|
14
14
|
* Creates an instance of Editor
|
|
@@ -244,7 +244,7 @@ export declare class EditorAdapter extends StandaloneEditor implements IEditor {
|
|
|
244
244
|
* @param callback The callback function to run
|
|
245
245
|
* @returns a function to cancel this async run
|
|
246
246
|
*/
|
|
247
|
-
runAsync(callback: (editor:
|
|
247
|
+
runAsync(callback: (editor: ILegacyEditor & IEditor) => void): () => void;
|
|
248
248
|
/**
|
|
249
249
|
* Set DOM attribute of editor content DIV
|
|
250
250
|
* @param name Name of the attribute
|
|
@@ -90,18 +90,18 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
90
90
|
replaceSelection: true,
|
|
91
91
|
insertToRegionRoot: false,
|
|
92
92
|
};
|
|
93
|
-
var
|
|
93
|
+
var physicalRoot = this.getCore().physicalRoot;
|
|
94
94
|
if (option.updateCursor) {
|
|
95
95
|
this.focus();
|
|
96
96
|
}
|
|
97
97
|
if (option.position == 4 /* Outside */) {
|
|
98
|
-
(_a =
|
|
98
|
+
(_a = physicalRoot.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(node, physicalRoot.nextSibling);
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
101
|
if (this.isDarkMode()) {
|
|
102
102
|
(0, roosterjs_content_model_core_1.transformColor)(node, true /*includeSelf*/, 'lightToDark', this.getColorManager());
|
|
103
103
|
}
|
|
104
|
-
var selection = (0, insertNode_1.insertNode)(
|
|
104
|
+
var selection = (0, insertNode_1.insertNode)(physicalRoot, this.getDOMSelection(), node, option);
|
|
105
105
|
if (selection && option.updateCursor) {
|
|
106
106
|
this.setDOMSelection(selection);
|
|
107
107
|
}
|
|
@@ -151,13 +151,13 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
151
151
|
* @returns The BlockElement result
|
|
152
152
|
*/
|
|
153
153
|
EditorAdapter.prototype.getBlockElementAtNode = function (node) {
|
|
154
|
-
return (0, roosterjs_editor_dom_1.getBlockElementAtNode)(this.getCore().
|
|
154
|
+
return (0, roosterjs_editor_dom_1.getBlockElementAtNode)(this.getCore().logicalRoot, node);
|
|
155
155
|
};
|
|
156
156
|
EditorAdapter.prototype.contains = function (arg) {
|
|
157
157
|
if (!arg) {
|
|
158
158
|
return false;
|
|
159
159
|
}
|
|
160
|
-
return (0, roosterjs_editor_dom_1.contains)(this.getCore().
|
|
160
|
+
return (0, roosterjs_editor_dom_1.contains)(this.getCore().logicalRoot, arg);
|
|
161
161
|
};
|
|
162
162
|
EditorAdapter.prototype.queryElements = function (selector, scopeOrCallback, callback) {
|
|
163
163
|
if (scopeOrCallback === void 0) { scopeOrCallback = 0 /* Body */; }
|
|
@@ -168,11 +168,11 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
168
168
|
var selectionEx = scope == 0 /* Body */ ? null : this.getSelectionRangeEx();
|
|
169
169
|
if (selectionEx) {
|
|
170
170
|
selectionEx.ranges.forEach(function (range) {
|
|
171
|
-
result.push.apply(result, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((0, roosterjs_editor_dom_1.queryElements)(core.
|
|
171
|
+
result.push.apply(result, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((0, roosterjs_editor_dom_1.queryElements)(core.logicalRoot, selector, callback, scope, range)), false));
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
else {
|
|
175
|
-
return (0, roosterjs_editor_dom_1.queryElements)(core.
|
|
175
|
+
return (0, roosterjs_editor_dom_1.queryElements)(core.logicalRoot, selector, callback, scope, undefined /* range */);
|
|
176
176
|
}
|
|
177
177
|
return result;
|
|
178
178
|
};
|
|
@@ -188,7 +188,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
188
188
|
* otherwise just return start and end
|
|
189
189
|
*/
|
|
190
190
|
EditorAdapter.prototype.collapseNodes = function (start, end, canSplitParent) {
|
|
191
|
-
return (0, roosterjs_editor_dom_1.collapseNodes)(this.getCore().
|
|
191
|
+
return (0, roosterjs_editor_dom_1.collapseNodes)(this.getCore().physicalRoot, start, end, canSplitParent);
|
|
192
192
|
};
|
|
193
193
|
//#endregion
|
|
194
194
|
//#region Content API
|
|
@@ -198,7 +198,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
198
198
|
* @returns True if there's no visible content, otherwise false
|
|
199
199
|
*/
|
|
200
200
|
EditorAdapter.prototype.isEmpty = function (trim) {
|
|
201
|
-
return (0, roosterjs_editor_dom_1.isNodeEmpty)(this.getCore().
|
|
201
|
+
return (0, roosterjs_editor_dom_1.isNodeEmpty)(this.getCore().physicalRoot, trim);
|
|
202
202
|
};
|
|
203
203
|
/**
|
|
204
204
|
* Get current editor content as HTML string
|
|
@@ -217,7 +217,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
217
217
|
EditorAdapter.prototype.setContent = function (content, triggerContentChangedEvent) {
|
|
218
218
|
if (triggerContentChangedEvent === void 0) { triggerContentChangedEvent = true; }
|
|
219
219
|
var core = this.getCore();
|
|
220
|
-
var
|
|
220
|
+
var physicalRoot = core.physicalRoot, api = core.api, trustedHTMLHandler = core.trustedHTMLHandler, lifecycle = core.lifecycle, darkColorHandler = core.darkColorHandler;
|
|
221
221
|
api.triggerEvent(core, {
|
|
222
222
|
eventType: 'beforeSetContent',
|
|
223
223
|
newContent: content,
|
|
@@ -231,7 +231,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
231
231
|
}, false /*broadcast*/);
|
|
232
232
|
}
|
|
233
233
|
else if (lifecycle.isDarkMode) {
|
|
234
|
-
(0, roosterjs_content_model_core_1.transformColor)(
|
|
234
|
+
(0, roosterjs_content_model_core_1.transformColor)(physicalRoot, false /*includeSelf*/, 'lightToDark', darkColorHandler);
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
237
|
/**
|
|
@@ -266,7 +266,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
266
266
|
EditorAdapter.prototype.deleteSelectedContent = function () {
|
|
267
267
|
var range = this.getSelectionRange();
|
|
268
268
|
if (range && !range.collapsed) {
|
|
269
|
-
return (0, roosterjs_editor_dom_1.deleteSelectedContent)(this.getCore().
|
|
269
|
+
return (0, roosterjs_editor_dom_1.deleteSelectedContent)(this.getCore().physicalRoot, range);
|
|
270
270
|
}
|
|
271
271
|
return null;
|
|
272
272
|
};
|
|
@@ -322,11 +322,11 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
322
322
|
*/
|
|
323
323
|
EditorAdapter.prototype.getSelectionPath = function () {
|
|
324
324
|
var range = this.getSelectionRange();
|
|
325
|
-
return range && (0, roosterjs_editor_dom_1.getSelectionPath)(this.getCore().
|
|
325
|
+
return range && (0, roosterjs_editor_dom_1.getSelectionPath)(this.getCore().physicalRoot, range);
|
|
326
326
|
};
|
|
327
327
|
EditorAdapter.prototype.select = function (arg1, arg2, arg3, arg4) {
|
|
328
328
|
var core = this.getCore();
|
|
329
|
-
var rangeEx = (0, buildRangeEx_1.buildRangeEx)(core.
|
|
329
|
+
var rangeEx = (0, buildRangeEx_1.buildRangeEx)(core.physicalRoot, arg1, arg2, arg3, arg4);
|
|
330
330
|
var selection = (0, selectionConverter_1.convertRangeExToDomSelection)(rangeEx);
|
|
331
331
|
this.setDOMSelection(selection);
|
|
332
332
|
return true;
|
|
@@ -368,7 +368,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
368
368
|
startFrom = position === null || position === void 0 ? void 0 : position.node;
|
|
369
369
|
}
|
|
370
370
|
return (startFrom &&
|
|
371
|
-
(0, roosterjs_editor_dom_1.findClosestElementAncestor)(startFrom, _this.getCore().
|
|
371
|
+
(0, roosterjs_editor_dom_1.findClosestElementAncestor)(startFrom, _this.getCore().physicalRoot, selector));
|
|
372
372
|
})) !== null && _a !== void 0 ? _a : null);
|
|
373
373
|
};
|
|
374
374
|
/**
|
|
@@ -378,7 +378,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
378
378
|
* @returns True if position is at beginning of the editor, otherwise false
|
|
379
379
|
*/
|
|
380
380
|
EditorAdapter.prototype.isPositionAtBeginning = function (position) {
|
|
381
|
-
return (0, roosterjs_editor_dom_1.isPositionAtBeginningOf)(position, this.getCore().
|
|
381
|
+
return (0, roosterjs_editor_dom_1.isPositionAtBeginningOf)(position, this.getCore().logicalRoot);
|
|
382
382
|
};
|
|
383
383
|
/**
|
|
384
384
|
* Get impacted regions from selection
|
|
@@ -387,9 +387,9 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
387
387
|
if (type === void 0) { type = 0 /* Table */; }
|
|
388
388
|
var selection = this.getSelectionRangeEx();
|
|
389
389
|
var result = [];
|
|
390
|
-
var
|
|
390
|
+
var logicalRoot = this.getCore().logicalRoot;
|
|
391
391
|
selection.ranges.forEach(function (range) {
|
|
392
|
-
result.push.apply(result, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((range ? (0, roosterjs_editor_dom_1.getRegionsFromRange)(
|
|
392
|
+
result.push.apply(result, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((range ? (0, roosterjs_editor_dom_1.getRegionsFromRange)(logicalRoot, range, type) : [])), false));
|
|
393
393
|
});
|
|
394
394
|
return result.filter(function (value, index, self) {
|
|
395
395
|
return self.indexOf(value) === index;
|
|
@@ -583,7 +583,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
583
583
|
* @param startNode The node to start from. If not passed, it will start from the beginning of the body
|
|
584
584
|
*/
|
|
585
585
|
EditorAdapter.prototype.getBodyTraverser = function (startNode) {
|
|
586
|
-
return roosterjs_editor_dom_1.ContentTraverser.createBodyTraverser(this.getCore().
|
|
586
|
+
return roosterjs_editor_dom_1.ContentTraverser.createBodyTraverser(this.getCore().logicalRoot, startNode);
|
|
587
587
|
};
|
|
588
588
|
/**
|
|
589
589
|
* Get a content traverser for current selection
|
|
@@ -593,7 +593,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
593
593
|
var _a;
|
|
594
594
|
range = (_a = range !== null && range !== void 0 ? range : this.getSelectionRange()) !== null && _a !== void 0 ? _a : undefined;
|
|
595
595
|
return range
|
|
596
|
-
? roosterjs_editor_dom_1.ContentTraverser.createSelectionTraverser(this.getCore().
|
|
596
|
+
? roosterjs_editor_dom_1.ContentTraverser.createSelectionTraverser(this.getCore().logicalRoot, range)
|
|
597
597
|
: null;
|
|
598
598
|
};
|
|
599
599
|
/**
|
|
@@ -605,7 +605,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
605
605
|
if (startFrom === void 0) { startFrom = 3 /* SelectionStart */; }
|
|
606
606
|
var range = this.getSelectionRange();
|
|
607
607
|
return range
|
|
608
|
-
? roosterjs_editor_dom_1.ContentTraverser.createBlockTraverser(this.getCore().
|
|
608
|
+
? roosterjs_editor_dom_1.ContentTraverser.createBlockTraverser(this.getCore().logicalRoot, range, startFrom)
|
|
609
609
|
: null;
|
|
610
610
|
};
|
|
611
611
|
/**
|
|
@@ -619,7 +619,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
619
619
|
return (0, roosterjs_editor_dom_1.cacheGetEventData)(event !== null && event !== void 0 ? event : null, 'ContentSearcher', function () {
|
|
620
620
|
var range = _this.getSelectionRange();
|
|
621
621
|
return (range &&
|
|
622
|
-
new roosterjs_editor_dom_1.PositionContentSearcher(_this.getCore().
|
|
622
|
+
new roosterjs_editor_dom_1.PositionContentSearcher(_this.getCore().logicalRoot, roosterjs_editor_dom_1.Position.getStart(range)));
|
|
623
623
|
});
|
|
624
624
|
};
|
|
625
625
|
/**
|
|
@@ -629,7 +629,7 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
629
629
|
*/
|
|
630
630
|
EditorAdapter.prototype.runAsync = function (callback) {
|
|
631
631
|
var _this = this;
|
|
632
|
-
var win = this.getCore().
|
|
632
|
+
var win = this.getCore().physicalRoot.ownerDocument.defaultView || window;
|
|
633
633
|
var handle = win.requestAnimationFrame(function () {
|
|
634
634
|
if (!_this.isDisposed() && callback) {
|
|
635
635
|
callback(_this);
|
|
@@ -665,15 +665,15 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
665
665
|
*/
|
|
666
666
|
EditorAdapter.prototype.getRelativeDistanceToEditor = function (element, addScroll) {
|
|
667
667
|
if (this.contains(element)) {
|
|
668
|
-
var
|
|
669
|
-
var editorRect =
|
|
668
|
+
var physicalRoot = this.getCore().physicalRoot;
|
|
669
|
+
var editorRect = physicalRoot.getBoundingClientRect();
|
|
670
670
|
var elementRect = element.getBoundingClientRect();
|
|
671
671
|
if (editorRect && elementRect) {
|
|
672
672
|
var x = elementRect.left - (editorRect === null || editorRect === void 0 ? void 0 : editorRect.left);
|
|
673
673
|
var y = elementRect.top - (editorRect === null || editorRect === void 0 ? void 0 : editorRect.top);
|
|
674
674
|
if (addScroll) {
|
|
675
|
-
x +=
|
|
676
|
-
y +=
|
|
675
|
+
x += physicalRoot.scrollLeft;
|
|
676
|
+
y += physicalRoot.scrollTop;
|
|
677
677
|
}
|
|
678
678
|
return [x, y];
|
|
679
679
|
}
|
|
@@ -838,6 +838,6 @@ var EditorAdapter = /** @class */ (function (_super) {
|
|
|
838
838
|
return this.contentModelEditorCore;
|
|
839
839
|
};
|
|
840
840
|
return EditorAdapter;
|
|
841
|
-
}(roosterjs_content_model_core_1.
|
|
841
|
+
}(roosterjs_content_model_core_1.Editor));
|
|
842
842
|
exports.EditorAdapter = EditorAdapter;
|
|
843
843
|
//# sourceMappingURL=EditorAdapter.js.map
|