@atlaskit/editor-plugin-selection-extension 3.3.1 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/pm-plugins/actions/insertAdfAtEndOfDoc.js +27 -0
  3. package/dist/cjs/pm-plugins/actions/replaceWithAdf.js +50 -0
  4. package/dist/cjs/selectionExtensionPlugin.js +90 -34
  5. package/dist/cjs/ui/LegacyToolbarComponent.js +120 -0
  6. package/dist/cjs/ui/extensions.js +60 -0
  7. package/dist/cjs/ui/selectionToolbar.js +32 -5
  8. package/dist/es2019/pm-plugins/actions/insertAdfAtEndOfDoc.js +21 -0
  9. package/dist/es2019/pm-plugins/actions/replaceWithAdf.js +44 -0
  10. package/dist/es2019/selectionExtensionPlugin.js +80 -26
  11. package/dist/es2019/ui/LegacyToolbarComponent.js +109 -0
  12. package/dist/es2019/ui/extensions.js +54 -0
  13. package/dist/es2019/ui/selectionToolbar.js +38 -14
  14. package/dist/esm/pm-plugins/actions/insertAdfAtEndOfDoc.js +21 -0
  15. package/dist/esm/pm-plugins/actions/replaceWithAdf.js +44 -0
  16. package/dist/esm/selectionExtensionPlugin.js +90 -34
  17. package/dist/esm/ui/LegacyToolbarComponent.js +111 -0
  18. package/dist/esm/ui/extensions.js +54 -0
  19. package/dist/esm/ui/selectionToolbar.js +31 -5
  20. package/dist/types/index.d.ts +1 -1
  21. package/dist/types/pm-plugins/actions/insertAdfAtEndOfDoc.d.ts +5 -0
  22. package/dist/types/pm-plugins/actions/replaceWithAdf.d.ts +5 -0
  23. package/dist/types/selectionExtensionPluginType.d.ts +5 -1
  24. package/dist/types/types/index.d.ts +44 -1
  25. package/dist/types/ui/LegacyToolbarComponent.d.ts +16 -0
  26. package/dist/types/ui/extensions.d.ts +27 -0
  27. package/dist/types/ui/selectionToolbar.d.ts +7 -17
  28. package/dist/types-ts4.5/index.d.ts +1 -1
  29. package/dist/types-ts4.5/pm-plugins/actions/insertAdfAtEndOfDoc.d.ts +5 -0
  30. package/dist/types-ts4.5/pm-plugins/actions/replaceWithAdf.d.ts +5 -0
  31. package/dist/types-ts4.5/selectionExtensionPluginType.d.ts +5 -1
  32. package/dist/types-ts4.5/types/index.d.ts +44 -1
  33. package/dist/types-ts4.5/ui/LegacyToolbarComponent.d.ts +16 -0
  34. package/dist/types-ts4.5/ui/extensions.d.ts +27 -0
  35. package/dist/types-ts4.5/ui/selectionToolbar.d.ts +7 -17
  36. package/package.json +7 -6
@@ -0,0 +1,111 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useState } from 'react';
3
+ import { ArrowKeyNavigationType, DropdownMenuWithKeyboardNavigation as DropdownMenu, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
4
+ export var LegacyPrimaryToolbarComponent = function LegacyPrimaryToolbarComponent(_ref) {
5
+ var primaryToolbarItemExtensions = _ref.primaryToolbarItemExtensions;
6
+ // NEXT PR: need to render a separator after – if there are extensions added
7
+ return /*#__PURE__*/React.createElement(React.Fragment, null, primaryToolbarItemExtensions.map(function (toolbarItemExtension, i) {
8
+ var toolbarItem = toolbarItemExtension.getToolbarItem();
9
+ return /*#__PURE__*/React.createElement(LegacyExtensionToolbarItem, {
10
+ key: toolbarItem.tooltip,
11
+ toolbarItem: toolbarItem
12
+ });
13
+ }));
14
+ };
15
+ export var LegacyExtensionToolbarItem = function LegacyExtensionToolbarItem(_ref2) {
16
+ var toolbarItem = _ref2.toolbarItem,
17
+ getMenuItems = _ref2.getMenuItems;
18
+ var _useState = useState(false),
19
+ _useState2 = _slicedToArray(_useState, 2),
20
+ isOpen = _useState2[0],
21
+ setIsOpen = _useState2[1];
22
+ var Icon = toolbarItem.icon,
23
+ tooltip = toolbarItem.tooltip,
24
+ isDisabled = toolbarItem.isDisabled,
25
+ onClick = toolbarItem.onClick,
26
+ _label = toolbarItem.label;
27
+ if (!getMenuItems) {
28
+ return /*#__PURE__*/React.createElement(ToolbarButton, {
29
+ spacing: "default",
30
+ disabled: isDisabled,
31
+ selected: isOpen,
32
+ title: tooltip,
33
+ "aria-label": tooltip,
34
+ "aria-expanded": isOpen,
35
+ "aria-haspopup": true,
36
+ onClick: onClick,
37
+ iconBefore: /*#__PURE__*/React.createElement(Icon, {
38
+ label: tooltip
39
+ })
40
+ });
41
+ }
42
+ var toggleOpen = function toggleOpen() {
43
+ setIsOpen(function (prev) {
44
+ return !prev;
45
+ });
46
+ };
47
+ var toggleOpenByKeyboard = function toggleOpenByKeyboard(event) {
48
+ if (event.key === 'Enter' || event.key === ' ') {
49
+ event.preventDefault();
50
+ toggleOpen();
51
+ }
52
+ };
53
+ var handleItemActivated = function handleItemActivated(_ref3) {
54
+ var _item$onClick;
55
+ var item = _ref3.item,
56
+ _ref3$shouldCloseMenu = _ref3.shouldCloseMenu,
57
+ shouldCloseMenu = _ref3$shouldCloseMenu === void 0 ? true : _ref3$shouldCloseMenu;
58
+ (_item$onClick = item.onClick) === null || _item$onClick === void 0 || _item$onClick.call(item);
59
+ if (shouldCloseMenu) {
60
+ setIsOpen(false);
61
+ }
62
+ };
63
+ var handleOnOpenChange = function handleOnOpenChange(attrs) {
64
+ setIsOpen(!!(attrs !== null && attrs !== void 0 && attrs.isOpen));
65
+ };
66
+ var items = isOpen ? getMenuItems().map(function (menuItem, i) {
67
+ return {
68
+ key: "menu-item-".concat(i),
69
+ content: menuItem.label,
70
+ elemBefore: /*#__PURE__*/React.createElement(menuItem.icon, {
71
+ label: menuItem.label
72
+ }),
73
+ onClick: function onClick() {
74
+ var _menuItem$onClick;
75
+ (_menuItem$onClick = menuItem.onClick) === null || _menuItem$onClick === void 0 || _menuItem$onClick.call(menuItem);
76
+ // NEXT PR: here we need to set the active extension so the contentComponent can render
77
+ // menuItem.contentComponent
78
+ },
79
+ isDisabled: menuItem.isDisabled,
80
+ 'aria-label': menuItem.label,
81
+ value: {
82
+ name: menuItem.label
83
+ }
84
+ };
85
+ }) : [];
86
+ return /*#__PURE__*/React.createElement(DropdownMenu, {
87
+ arrowKeyNavigationProviderOptions: {
88
+ type: ArrowKeyNavigationType.MENU
89
+ },
90
+ items: [{
91
+ items: items
92
+ }],
93
+ isOpen: isOpen,
94
+ onItemActivated: handleItemActivated,
95
+ onOpenChange: handleOnOpenChange,
96
+ fitWidth: 200
97
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
98
+ spacing: "default",
99
+ disabled: isDisabled,
100
+ selected: isOpen,
101
+ title: tooltip,
102
+ "aria-label": tooltip,
103
+ "aria-expanded": isOpen,
104
+ "aria-haspopup": true,
105
+ onClick: toggleOpen,
106
+ onKeyDown: toggleOpenByKeyboard,
107
+ iconBefore: /*#__PURE__*/React.createElement(Icon, {
108
+ label: tooltip
109
+ })
110
+ }));
111
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * From the full list of extensions, extract only those that have a toolbar item configuration
3
+ * for the specified type (either 'primaryToolbar' or 'inlineToolbar').
4
+ *
5
+ * @param extensionList - List of all extensions
6
+ * @param toolbarType - Type of toolbar ('primaryToolbar' or 'inlineToolbar')
7
+ * @returns Array of ToolbarItemExtension objects
8
+ * @example
9
+ */
10
+ export var getToolbarItemExtensions = function getToolbarItemExtensions(extensionList, toolbarType) {
11
+ return extensionList.reduce(function (acc, extension) {
12
+ var toolbarConfig = extension[toolbarType];
13
+ if (toolbarConfig !== null && toolbarConfig !== void 0 && toolbarConfig.getToolbarItem) {
14
+ acc.push({
15
+ getToolbarItem: toolbarConfig.getToolbarItem,
16
+ getMenuItems: toolbarConfig.getMenuItems
17
+ });
18
+ }
19
+ return acc;
20
+ }, []);
21
+ };
22
+
23
+ /**
24
+ * From the full list of extensions, extract only those that have a menu item configuration
25
+ * for the specified source (either 'first-party' or 'external').
26
+ *
27
+ * Map each to the legacy format for SelectionExtensionConfig.
28
+ *
29
+ * @param extensionList - List of all extensions
30
+ * @param targetSource - Source of the extensions ('first-party' or 'external')
31
+ * @returns Array of SelectionExtensionConfig objects
32
+ * @example
33
+ */
34
+ export var getMenuItemExtensions = function getMenuItemExtensions(extensionList, targetSource) {
35
+ return extensionList.reduce(function (acc, extension) {
36
+ var source = extension.source,
37
+ inlineToolbar = extension.inlineToolbar;
38
+ if (source === targetSource && inlineToolbar !== null && inlineToolbar !== void 0 && inlineToolbar.getMenuItems && !inlineToolbar.getToolbarItem) {
39
+ var menuItems = inlineToolbar.getMenuItems();
40
+ menuItems.forEach(function (menuItem) {
41
+ acc.push({
42
+ name: menuItem.label,
43
+ icon: menuItem.icon,
44
+ onClick: menuItem.onClick,
45
+ isDisabled: function isDisabled() {
46
+ return !!menuItem.isDisabled;
47
+ },
48
+ component: menuItem.contentComponent
49
+ });
50
+ });
51
+ }
52
+ return acc;
53
+ }, []);
54
+ };
@@ -1,7 +1,33 @@
1
- export var selectionToolbar = function selectionToolbar(options) {
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import React from 'react';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
4
+ import { getToolbarItemExtensions } from './extensions';
5
+ import { LegacyExtensionToolbarItem } from './LegacyToolbarComponent';
6
+ export var selectionToolbar = function selectionToolbar(_ref) {
7
+ var overflowOptions = _ref.overflowOptions,
8
+ _ref$extensionList = _ref.extensionList,
9
+ extensionList = _ref$extensionList === void 0 ? [] : _ref$extensionList;
10
+ var inlineToolbarItemExtensions = fg('platform_editor_selection_extension_api_v2') ? getToolbarItemExtensions(extensionList, 'inlineToolbar') : [];
2
11
  return {
3
- isToolbarAbove: true,
4
- items: [{
12
+ items: [].concat(_toConsumableArray(inlineToolbarItemExtensions.length ? [{
13
+ type: 'separator',
14
+ fullHeight: true,
15
+ supportsViewMode: true
16
+ }].concat(_toConsumableArray(inlineToolbarItemExtensions.map(function (_ref2) {
17
+ var getToolbarItem = _ref2.getToolbarItem,
18
+ getMenuItems = _ref2.getMenuItems;
19
+ return {
20
+ type: 'custom',
21
+ render: function render() {
22
+ return /*#__PURE__*/React.createElement(LegacyExtensionToolbarItem, {
23
+ toolbarItem: getToolbarItem(),
24
+ getMenuItems: getMenuItems
25
+ });
26
+ },
27
+ fallback: [],
28
+ supportsViewMode: true
29
+ };
30
+ }))) : []), [{
5
31
  type: 'separator',
6
32
  fullHeight: true,
7
33
  supportsViewMode: true
@@ -9,8 +35,8 @@ export var selectionToolbar = function selectionToolbar(options) {
9
35
  type: 'overflow-dropdown',
10
36
  dropdownWidth: 240,
11
37
  supportsViewMode: true,
12
- options: options
13
- }],
38
+ options: overflowOptions
39
+ }]),
14
40
  rank: -6
15
41
  };
16
42
  };
@@ -1,3 +1,3 @@
1
1
  export { selectionExtensionPlugin } from './selectionExtensionPlugin';
2
2
  export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
3
- export type { SelectionExtensionComponentProps, SelectionExtensionPluginOptions, SelectionExtension, LinkInsertionOption, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, DynamicSelectionExtension, } from './types';
3
+ export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, } from './types';
@@ -0,0 +1,5 @@
1
+ import { type ADFEntity } from '@atlaskit/adf-utils/types';
2
+ import type { CommandDispatch } from '@atlaskit/editor-common/types';
3
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
+ import { type InsertAdfAtEndOfDocResult } from '../../types';
5
+ export declare const insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => InsertAdfAtEndOfDocResult;
@@ -0,0 +1,5 @@
1
+ import { type ADFEntity } from '@atlaskit/adf-utils/types';
2
+ import type { CommandDispatch } from '@atlaskit/editor-common/types';
3
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
+ import { type ReplaceWithAdfResult } from '../../types';
5
+ export declare const replaceWithAdf: (nodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => ReplaceWithAdfResult;
@@ -2,13 +2,15 @@ import { type ADFEntity } from '@atlaskit/adf-utils/types';
2
2
  import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
3
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
4
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
5
+ import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
5
6
  import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
6
- import type { DynamicSelectionExtension, LinkInsertionOption, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
7
+ import type { DynamicSelectionExtension, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
7
8
  export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
8
9
  pluginConfiguration: SelectionExtensionPluginOptions | undefined;
9
10
  dependencies: [
10
11
  OptionalPlugin<AnalyticsPlugin>,
11
12
  OptionalPlugin<EditorViewModePlugin>,
13
+ OptionalPlugin<PrimaryToolbarPlugin>,
12
14
  SelectionToolbarPlugin
13
15
  ];
14
16
  sharedState: SelectionExtensionPluginState | null;
@@ -24,5 +26,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
24
26
  status: 'success' | 'error';
25
27
  message?: string;
26
28
  };
29
+ replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
30
+ insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
27
31
  };
28
32
  }>;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { ADFEntity } from '@atlaskit/adf-utils/types';
3
- import { type MenuItem } from '@atlaskit/editor-common/ui-menu';
3
+ import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
4
4
  import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
5
5
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
6
6
  export type MenuItemsType = Array<{
@@ -61,6 +61,7 @@ type SelectionExtensionModes = ViewMode;
61
61
  export type SelectionExtensionPluginOptions = {
62
62
  pageModes?: SelectionExtensionModes | SelectionExtensionModes[];
63
63
  extensions?: SelectionExtensions;
64
+ extensionList?: ExtensionConfiguration[];
64
65
  };
65
66
  /**
66
67
  * @private
@@ -110,4 +111,46 @@ export type SelectionExtensionPluginState = {
110
111
  startTrackChanges?: boolean;
111
112
  docChangedAfterClick?: boolean;
112
113
  };
114
+ export type ReplaceWithAdfStatus = 'success' | 'document-changed' | 'failed-to-replace';
115
+ export type ReplaceWithAdfResult = {
116
+ status: ReplaceWithAdfStatus;
117
+ };
118
+ export type InsertAdfAtEndOfDocResult = {
119
+ status: 'success' | 'failed';
120
+ };
121
+ export type ExtensionSource = 'first-party' | 'external';
122
+ export type ExtensionConfiguration = {
123
+ key: string;
124
+ source: ExtensionSource;
125
+ inlineToolbar?: ToolbarExtensionConfiguration;
126
+ primaryToolbar?: ToolbarExtensionConfiguration;
127
+ blockMenu?: BlockMenuExtensionConfiguration;
128
+ };
129
+ export type GetToolbarItemFn = () => ExtensionToolbarItemConfiguration;
130
+ export type GetMenuItemsFn = () => ExtensionMenuItemConfiguration[];
131
+ export type ToolbarExtensionConfiguration = {
132
+ getToolbarItem?: GetToolbarItemFn;
133
+ getMenuItems?: GetMenuItemsFn;
134
+ };
135
+ export type BlockMenuExtensionConfiguration = {
136
+ getMenuItems?: GetMenuItemsFn;
137
+ };
138
+ export type ExtensionToolbarItemConfiguration = {
139
+ icon: React.ComponentType<React.PropsWithChildren<{
140
+ label: string;
141
+ }>>;
142
+ tooltip: string;
143
+ isDisabled?: boolean;
144
+ onClick?: () => void;
145
+ label?: string;
146
+ };
147
+ export type ExtensionMenuItemConfiguration = {
148
+ label: string;
149
+ icon: React.ComponentType<React.PropsWithChildren<{
150
+ label: string;
151
+ }>>;
152
+ onClick?: () => void;
153
+ isDisabled?: boolean;
154
+ contentComponent?: React.ComponentType<SelectionExtensionComponentProps>;
155
+ };
113
156
  export {};
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { ExtensionToolbarItemConfiguration, GetMenuItemsFn, GetToolbarItemFn } from '../types';
3
+ export type ToolbarItemExtension = {
4
+ getToolbarItem: GetToolbarItemFn;
5
+ getMenuItems?: GetMenuItemsFn;
6
+ };
7
+ type LegacyPrimaryToolbarComponentProps = {
8
+ primaryToolbarItemExtensions: ToolbarItemExtension[];
9
+ };
10
+ export declare const LegacyPrimaryToolbarComponent: ({ primaryToolbarItemExtensions, }: LegacyPrimaryToolbarComponentProps) => React.JSX.Element;
11
+ type LegacyExtensionToolbarItemProps = {
12
+ toolbarItem: ExtensionToolbarItemConfiguration;
13
+ getMenuItems?: GetMenuItemsFn;
14
+ };
15
+ export declare const LegacyExtensionToolbarItem: ({ toolbarItem, getMenuItems, }: LegacyExtensionToolbarItemProps) => React.JSX.Element;
16
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { ExtensionConfiguration, ExtensionSource, GetMenuItemsFn, GetToolbarItemFn, SelectionExtensionConfig } from '../types';
2
+ export type ToolbarItemExtension = {
3
+ getToolbarItem: GetToolbarItemFn;
4
+ getMenuItems?: GetMenuItemsFn;
5
+ };
6
+ /**
7
+ * From the full list of extensions, extract only those that have a toolbar item configuration
8
+ * for the specified type (either 'primaryToolbar' or 'inlineToolbar').
9
+ *
10
+ * @param extensionList - List of all extensions
11
+ * @param toolbarType - Type of toolbar ('primaryToolbar' or 'inlineToolbar')
12
+ * @returns Array of ToolbarItemExtension objects
13
+ * @example
14
+ */
15
+ export declare const getToolbarItemExtensions: (extensionList: ExtensionConfiguration[], toolbarType: 'primaryToolbar' | 'inlineToolbar') => ToolbarItemExtension[];
16
+ /**
17
+ * From the full list of extensions, extract only those that have a menu item configuration
18
+ * for the specified source (either 'first-party' or 'external').
19
+ *
20
+ * Map each to the legacy format for SelectionExtensionConfig.
21
+ *
22
+ * @param extensionList - List of all extensions
23
+ * @param targetSource - Source of the extensions ('first-party' or 'external')
24
+ * @returns Array of SelectionExtensionConfig objects
25
+ * @example
26
+ */
27
+ export declare const getMenuItemExtensions: (extensionList: ExtensionConfiguration[], targetSource: ExtensionSource) => SelectionExtensionConfig[];
@@ -1,18 +1,8 @@
1
- import { type Command, type FloatingToolbarOverflowDropdownOptions } from '@atlaskit/editor-common/types';
2
- export declare const selectionToolbar: (options: FloatingToolbarOverflowDropdownOptions<Command>) => {
3
- isToolbarAbove: boolean;
4
- items: ({
5
- type: "separator";
6
- fullHeight: boolean;
7
- supportsViewMode: boolean;
8
- dropdownWidth?: undefined;
9
- options?: undefined;
10
- } | {
11
- type: "overflow-dropdown";
12
- dropdownWidth: number;
13
- supportsViewMode: boolean;
14
- options: FloatingToolbarOverflowDropdownOptions<Command>;
15
- fullHeight?: undefined;
16
- })[];
17
- rank: number;
1
+ import type { Command, FloatingToolbarOverflowDropdownOptions, SelectionToolbarGroup } from '@atlaskit/editor-common/types';
2
+ import type { ExtensionConfiguration } from '../types';
3
+ type SelectionToolbarOptions = {
4
+ overflowOptions: FloatingToolbarOverflowDropdownOptions<Command>;
5
+ extensionList?: ExtensionConfiguration[];
18
6
  };
7
+ export declare const selectionToolbar: ({ overflowOptions, extensionList, }: SelectionToolbarOptions) => SelectionToolbarGroup;
8
+ export {};
@@ -1,3 +1,3 @@
1
1
  export { selectionExtensionPlugin } from './selectionExtensionPlugin';
2
2
  export type { SelectionExtensionPlugin } from './selectionExtensionPluginType';
3
- export type { SelectionExtensionComponentProps, SelectionExtensionPluginOptions, SelectionExtension, LinkInsertionOption, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, DynamicSelectionExtension, } from './types';
3
+ export type { BlockMenuExtensionConfiguration, DynamicSelectionExtension, ExtensionConfiguration, ExtensionMenuItemConfiguration, ExtensionToolbarItemConfiguration, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionComponentProps, SelectionExtensionConfig, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo, ToolbarExtensionConfiguration, } from './types';
@@ -0,0 +1,5 @@
1
+ import { type ADFEntity } from '@atlaskit/adf-utils/types';
2
+ import type { CommandDispatch } from '@atlaskit/editor-common/types';
3
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
+ import { type InsertAdfAtEndOfDocResult } from '../../types';
5
+ export declare const insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => InsertAdfAtEndOfDocResult;
@@ -0,0 +1,5 @@
1
+ import { type ADFEntity } from '@atlaskit/adf-utils/types';
2
+ import type { CommandDispatch } from '@atlaskit/editor-common/types';
3
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
+ import { type ReplaceWithAdfResult } from '../../types';
5
+ export declare const replaceWithAdf: (nodeAdf: ADFEntity) => (state: EditorState, dispatch: CommandDispatch) => ReplaceWithAdfResult;
@@ -2,13 +2,15 @@ import { type ADFEntity } from '@atlaskit/adf-utils/types';
2
2
  import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
3
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
4
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
5
+ import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
5
6
  import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
6
- import type { DynamicSelectionExtension, LinkInsertionOption, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
7
+ import type { DynamicSelectionExtension, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
7
8
  export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
8
9
  pluginConfiguration: SelectionExtensionPluginOptions | undefined;
9
10
  dependencies: [
10
11
  OptionalPlugin<AnalyticsPlugin>,
11
12
  OptionalPlugin<EditorViewModePlugin>,
13
+ OptionalPlugin<PrimaryToolbarPlugin>,
12
14
  SelectionToolbarPlugin
13
15
  ];
14
16
  sharedState: SelectionExtensionPluginState | null;
@@ -24,5 +26,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
24
26
  status: 'success' | 'error';
25
27
  message?: string;
26
28
  };
29
+ replaceWithAdf: (nodeAdf: ADFEntity) => ReplaceWithAdfResult;
30
+ insertAdfAtEndOfDoc: (nodeAdf: ADFEntity) => InsertAdfAtEndOfDocResult;
27
31
  };
28
32
  }>;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { ADFEntity } from '@atlaskit/adf-utils/types';
3
- import { type MenuItem } from '@atlaskit/editor-common/ui-menu';
3
+ import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
4
4
  import type { ViewMode } from '@atlaskit/editor-plugin-editor-viewmode';
5
5
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
6
6
  export type MenuItemsType = Array<{
@@ -61,6 +61,7 @@ type SelectionExtensionModes = ViewMode;
61
61
  export type SelectionExtensionPluginOptions = {
62
62
  pageModes?: SelectionExtensionModes | SelectionExtensionModes[];
63
63
  extensions?: SelectionExtensions;
64
+ extensionList?: ExtensionConfiguration[];
64
65
  };
65
66
  /**
66
67
  * @private
@@ -110,4 +111,46 @@ export type SelectionExtensionPluginState = {
110
111
  startTrackChanges?: boolean;
111
112
  docChangedAfterClick?: boolean;
112
113
  };
114
+ export type ReplaceWithAdfStatus = 'success' | 'document-changed' | 'failed-to-replace';
115
+ export type ReplaceWithAdfResult = {
116
+ status: ReplaceWithAdfStatus;
117
+ };
118
+ export type InsertAdfAtEndOfDocResult = {
119
+ status: 'success' | 'failed';
120
+ };
121
+ export type ExtensionSource = 'first-party' | 'external';
122
+ export type ExtensionConfiguration = {
123
+ key: string;
124
+ source: ExtensionSource;
125
+ inlineToolbar?: ToolbarExtensionConfiguration;
126
+ primaryToolbar?: ToolbarExtensionConfiguration;
127
+ blockMenu?: BlockMenuExtensionConfiguration;
128
+ };
129
+ export type GetToolbarItemFn = () => ExtensionToolbarItemConfiguration;
130
+ export type GetMenuItemsFn = () => ExtensionMenuItemConfiguration[];
131
+ export type ToolbarExtensionConfiguration = {
132
+ getToolbarItem?: GetToolbarItemFn;
133
+ getMenuItems?: GetMenuItemsFn;
134
+ };
135
+ export type BlockMenuExtensionConfiguration = {
136
+ getMenuItems?: GetMenuItemsFn;
137
+ };
138
+ export type ExtensionToolbarItemConfiguration = {
139
+ icon: React.ComponentType<React.PropsWithChildren<{
140
+ label: string;
141
+ }>>;
142
+ tooltip: string;
143
+ isDisabled?: boolean;
144
+ onClick?: () => void;
145
+ label?: string;
146
+ };
147
+ export type ExtensionMenuItemConfiguration = {
148
+ label: string;
149
+ icon: React.ComponentType<React.PropsWithChildren<{
150
+ label: string;
151
+ }>>;
152
+ onClick?: () => void;
153
+ isDisabled?: boolean;
154
+ contentComponent?: React.ComponentType<SelectionExtensionComponentProps>;
155
+ };
113
156
  export {};
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { ExtensionToolbarItemConfiguration, GetMenuItemsFn, GetToolbarItemFn } from '../types';
3
+ export type ToolbarItemExtension = {
4
+ getToolbarItem: GetToolbarItemFn;
5
+ getMenuItems?: GetMenuItemsFn;
6
+ };
7
+ type LegacyPrimaryToolbarComponentProps = {
8
+ primaryToolbarItemExtensions: ToolbarItemExtension[];
9
+ };
10
+ export declare const LegacyPrimaryToolbarComponent: ({ primaryToolbarItemExtensions, }: LegacyPrimaryToolbarComponentProps) => React.JSX.Element;
11
+ type LegacyExtensionToolbarItemProps = {
12
+ toolbarItem: ExtensionToolbarItemConfiguration;
13
+ getMenuItems?: GetMenuItemsFn;
14
+ };
15
+ export declare const LegacyExtensionToolbarItem: ({ toolbarItem, getMenuItems, }: LegacyExtensionToolbarItemProps) => React.JSX.Element;
16
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { ExtensionConfiguration, ExtensionSource, GetMenuItemsFn, GetToolbarItemFn, SelectionExtensionConfig } from '../types';
2
+ export type ToolbarItemExtension = {
3
+ getToolbarItem: GetToolbarItemFn;
4
+ getMenuItems?: GetMenuItemsFn;
5
+ };
6
+ /**
7
+ * From the full list of extensions, extract only those that have a toolbar item configuration
8
+ * for the specified type (either 'primaryToolbar' or 'inlineToolbar').
9
+ *
10
+ * @param extensionList - List of all extensions
11
+ * @param toolbarType - Type of toolbar ('primaryToolbar' or 'inlineToolbar')
12
+ * @returns Array of ToolbarItemExtension objects
13
+ * @example
14
+ */
15
+ export declare const getToolbarItemExtensions: (extensionList: ExtensionConfiguration[], toolbarType: 'primaryToolbar' | 'inlineToolbar') => ToolbarItemExtension[];
16
+ /**
17
+ * From the full list of extensions, extract only those that have a menu item configuration
18
+ * for the specified source (either 'first-party' or 'external').
19
+ *
20
+ * Map each to the legacy format for SelectionExtensionConfig.
21
+ *
22
+ * @param extensionList - List of all extensions
23
+ * @param targetSource - Source of the extensions ('first-party' or 'external')
24
+ * @returns Array of SelectionExtensionConfig objects
25
+ * @example
26
+ */
27
+ export declare const getMenuItemExtensions: (extensionList: ExtensionConfiguration[], targetSource: ExtensionSource) => SelectionExtensionConfig[];
@@ -1,18 +1,8 @@
1
- import { type Command, type FloatingToolbarOverflowDropdownOptions } from '@atlaskit/editor-common/types';
2
- export declare const selectionToolbar: (options: FloatingToolbarOverflowDropdownOptions<Command>) => {
3
- isToolbarAbove: boolean;
4
- items: ({
5
- type: "separator";
6
- fullHeight: boolean;
7
- supportsViewMode: boolean;
8
- dropdownWidth?: undefined;
9
- options?: undefined;
10
- } | {
11
- type: "overflow-dropdown";
12
- dropdownWidth: number;
13
- supportsViewMode: boolean;
14
- options: FloatingToolbarOverflowDropdownOptions<Command>;
15
- fullHeight?: undefined;
16
- })[];
17
- rank: number;
1
+ import type { Command, FloatingToolbarOverflowDropdownOptions, SelectionToolbarGroup } from '@atlaskit/editor-common/types';
2
+ import type { ExtensionConfiguration } from '../types';
3
+ type SelectionToolbarOptions = {
4
+ overflowOptions: FloatingToolbarOverflowDropdownOptions<Command>;
5
+ extensionList?: ExtensionConfiguration[];
18
6
  };
7
+ export declare const selectionToolbar: ({ overflowOptions, extensionList, }: SelectionToolbarOptions) => SelectionToolbarGroup;
8
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-extension",
3
- "version": "3.3.1",
3
+ "version": "3.4.1",
4
4
  "description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,23 +36,24 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@atlaskit/adf-utils": "^19.20.0",
39
- "@atlaskit/editor-json-transformer": "^8.24.0",
39
+ "@atlaskit/editor-json-transformer": "^8.25.0",
40
40
  "@atlaskit/editor-plugin-analytics": "^3.0.0",
41
41
  "@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
42
+ "@atlaskit/editor-plugin-primary-toolbar": "^4.1.0",
42
43
  "@atlaskit/editor-plugin-selection-toolbar": "^4.2.0",
43
44
  "@atlaskit/editor-prosemirror": "7.0.0",
44
45
  "@atlaskit/editor-tables": "^2.9.0",
45
- "@atlaskit/icon": "^27.7.0",
46
+ "@atlaskit/icon": "^27.8.0",
46
47
  "@atlaskit/platform-feature-flags": "^1.1.0",
47
- "@atlaskit/primitives": "^14.10.0",
48
- "@atlaskit/tmp-editor-statsig": "^9.16.0",
48
+ "@atlaskit/primitives": "^14.11.0",
49
+ "@atlaskit/tmp-editor-statsig": "^9.17.0",
49
50
  "@babel/runtime": "^7.0.0",
50
51
  "lodash": "^4.17.21",
51
52
  "react-intl-next": "npm:react-intl@^5.18.1",
52
53
  "uuid": "^3.1.0"
53
54
  },
54
55
  "peerDependencies": {
55
- "@atlaskit/editor-common": "^107.12.0",
56
+ "@atlaskit/editor-common": "^107.13.0",
56
57
  "react": "^18.2.0"
57
58
  },
58
59
  "devDependencies": {