UNPKG

@atlaskit/editor-plugin-selection-extension

Version:

editor-plugin-selection-extension plugin for @atlaskit/editor-core

52 lines (50 loc) 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.migrateSelectionExtensionToMenuItem = void 0; /** * * TODO: ED-29157 - remove once Confluence migrates to `extensionList`API * * NOTES: * - This is temporary until we deprecate SelectionExtension and DynamicSelectionExtension. * - Only supporing SelectionExtension as DynamicSelectionExtension is not being used and will be deprecated. * * Converts a SelectionExtension -> ExtensionMenuItemConfiguration. This allows existing extensions to appear in the new toolbar. */ var migrateSelectionExtensionToMenuItem = exports.migrateSelectionExtensionToMenuItem = function migrateSelectionExtensionToMenuItem(extension, api) { if (!extension.icon) { return undefined; } // Warning! These are inlined because the onClick handler must have up to date references to selection (which is awkwaradly set during extension.onClick invocation). var getSelection = function getSelection() { var _sharedState$activeEx; var sharedState = api === null || api === void 0 ? void 0 : api.selectionExtension.sharedState.currentState(); return sharedState === null || sharedState === void 0 || (_sharedState$activeEx = sharedState.activeExtension) === null || _sharedState$activeEx === void 0 ? void 0 : _sharedState$activeEx.selection; }; return { label: extension.name, icon: extension.icon, isDisabled: extension.isDisabled && extension.isDisabled({ selection: getSelection(), // pass undefined as no consumers use this selectedNodeAdf: undefined, selectionRanges: undefined }), /** * SelectionExtension supports passing through selection, selectionAdf, and selectionRanges. * * To support backwards compatibility wrap the onClick with these parameters here and let MenuItem invoke onClick using its expected signature. */ onClick: function onClick() { var selectionAdf = api === null || api === void 0 ? void 0 : api.selectionExtension.actions.getSelectionAdf(); extension.onClick && extension.onClick({ selection: getSelection(), selectedNodeAdf: selectionAdf === null || selectionAdf === void 0 ? void 0 : selectionAdf.selectedNodeAdf, selectionRanges: selectionAdf === null || selectionAdf === void 0 ? void 0 : selectionAdf.selectionRanges }); }, contentComponent: extension.component }; };