@atlaskit/editor-plugin-floating-toolbar 0.5.1 → 0.6.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 (135) hide show
  1. package/CHANGELOG.md +22 -10
  2. package/README.md +1 -1
  3. package/dist/cjs/index.js +8 -1
  4. package/dist/cjs/plugin.js +385 -0
  5. package/dist/cjs/pm-plugins/force-focus/index.js +73 -0
  6. package/dist/cjs/pm-plugins/toolbar-data/commands.js +26 -0
  7. package/dist/cjs/pm-plugins/toolbar-data/plugin-factory.js +16 -0
  8. package/dist/cjs/pm-plugins/toolbar-data/plugin-key.js +9 -0
  9. package/dist/cjs/pm-plugins/toolbar-data/plugin.js +16 -0
  10. package/dist/cjs/pm-plugins/toolbar-data/reducer.js +25 -0
  11. package/dist/cjs/pm-plugins/toolbar-data/types.js +5 -0
  12. package/dist/cjs/ui/CheckboxModal.js +83 -0
  13. package/dist/cjs/ui/ConfirmationModal.js +22 -0
  14. package/dist/cjs/ui/Dropdown.js +212 -0
  15. package/dist/cjs/ui/DropdownMenu.js +218 -0
  16. package/dist/cjs/ui/EditorEmojiAddIcon.js +32 -0
  17. package/dist/cjs/ui/EmojiPickerButton.js +121 -0
  18. package/dist/cjs/ui/ExtensionsPlaceholder.js +179 -0
  19. package/dist/cjs/ui/Input.js +80 -0
  20. package/dist/cjs/ui/ScrollButtons.js +155 -0
  21. package/dist/cjs/ui/Select.js +74 -0
  22. package/dist/cjs/ui/Separator.js +9 -0
  23. package/dist/cjs/ui/SimpleModal.js +42 -0
  24. package/dist/cjs/ui/Toolbar.js +436 -0
  25. package/dist/cjs/ui/ToolbarLoader.js +25 -0
  26. package/dist/cjs/ui/messages.js +55 -0
  27. package/dist/cjs/ui/styles.js +79 -0
  28. package/dist/cjs/utils.js +22 -0
  29. package/dist/es2019/index.js +1 -1
  30. package/dist/es2019/plugin.js +366 -0
  31. package/dist/es2019/pm-plugins/force-focus/index.js +63 -0
  32. package/dist/es2019/pm-plugins/toolbar-data/commands.js +10 -0
  33. package/dist/es2019/pm-plugins/toolbar-data/plugin-factory.js +8 -0
  34. package/dist/es2019/pm-plugins/toolbar-data/plugin-key.js +2 -0
  35. package/dist/es2019/pm-plugins/toolbar-data/plugin.js +9 -0
  36. package/dist/es2019/pm-plugins/toolbar-data/reducer.js +16 -0
  37. package/dist/es2019/pm-plugins/toolbar-data/types.js +1 -0
  38. package/dist/es2019/ui/CheckboxModal.js +71 -0
  39. package/dist/es2019/ui/ConfirmationModal.js +13 -0
  40. package/dist/es2019/ui/Dropdown.js +185 -0
  41. package/dist/es2019/ui/DropdownMenu.js +205 -0
  42. package/dist/es2019/ui/EditorEmojiAddIcon.js +25 -0
  43. package/dist/es2019/ui/EmojiPickerButton.js +108 -0
  44. package/dist/es2019/ui/ExtensionsPlaceholder.js +100 -0
  45. package/dist/es2019/ui/Input.js +54 -0
  46. package/dist/es2019/ui/ScrollButtons.js +141 -0
  47. package/dist/es2019/ui/Select.js +62 -0
  48. package/dist/es2019/ui/Separator.js +2 -0
  49. package/dist/es2019/ui/SimpleModal.js +35 -0
  50. package/dist/es2019/ui/Toolbar.js +428 -0
  51. package/dist/es2019/ui/ToolbarLoader.js +6 -0
  52. package/dist/es2019/ui/messages.js +48 -0
  53. package/dist/es2019/ui/styles.js +64 -0
  54. package/dist/es2019/utils.js +16 -0
  55. package/dist/esm/index.js +1 -1
  56. package/dist/esm/plugin.js +373 -0
  57. package/dist/esm/pm-plugins/force-focus/index.js +64 -0
  58. package/dist/esm/pm-plugins/toolbar-data/commands.js +18 -0
  59. package/dist/esm/pm-plugins/toolbar-data/plugin-factory.js +8 -0
  60. package/dist/esm/pm-plugins/toolbar-data/plugin-key.js +2 -0
  61. package/dist/esm/pm-plugins/toolbar-data/plugin.js +9 -0
  62. package/dist/esm/pm-plugins/toolbar-data/reducer.js +17 -0
  63. package/dist/esm/pm-plugins/toolbar-data/types.js +1 -0
  64. package/dist/esm/ui/CheckboxModal.js +72 -0
  65. package/dist/esm/ui/ConfirmationModal.js +14 -0
  66. package/dist/esm/ui/Dropdown.js +204 -0
  67. package/dist/esm/ui/DropdownMenu.js +211 -0
  68. package/dist/esm/ui/EditorEmojiAddIcon.js +25 -0
  69. package/dist/esm/ui/EmojiPickerButton.js +114 -0
  70. package/dist/esm/ui/ExtensionsPlaceholder.js +168 -0
  71. package/dist/esm/ui/Input.js +72 -0
  72. package/dist/esm/ui/ScrollButtons.js +145 -0
  73. package/dist/esm/ui/Select.js +64 -0
  74. package/dist/esm/ui/Separator.js +2 -0
  75. package/dist/esm/ui/SimpleModal.js +31 -0
  76. package/dist/esm/ui/Toolbar.js +426 -0
  77. package/dist/esm/ui/ToolbarLoader.js +12 -0
  78. package/dist/esm/ui/messages.js +48 -0
  79. package/dist/esm/ui/styles.js +68 -0
  80. package/dist/esm/utils.js +16 -0
  81. package/dist/types/index.d.ts +1 -0
  82. package/dist/types/plugin.d.ts +12 -0
  83. package/dist/types/pm-plugins/force-focus/index.d.ts +21 -0
  84. package/dist/types/pm-plugins/toolbar-data/commands.d.ts +3 -0
  85. package/dist/types/pm-plugins/toolbar-data/plugin-factory.d.ts +1 -0
  86. package/dist/types/pm-plugins/toolbar-data/plugin-key.d.ts +3 -0
  87. package/dist/types/pm-plugins/toolbar-data/plugin.d.ts +3 -0
  88. package/dist/types/pm-plugins/toolbar-data/reducer.d.ts +3 -0
  89. package/dist/types/pm-plugins/toolbar-data/types.d.ts +8 -0
  90. package/dist/types/ui/CheckboxModal.d.ts +4 -0
  91. package/dist/types/ui/ConfirmationModal.d.ts +6 -0
  92. package/dist/types/ui/Dropdown.d.ts +41 -0
  93. package/dist/types/ui/DropdownMenu.d.ts +29 -0
  94. package/dist/types/ui/EditorEmojiAddIcon.d.ts +2 -0
  95. package/dist/types/ui/EmojiPickerButton.d.ts +16 -0
  96. package/dist/types/ui/ExtensionsPlaceholder.d.ts +16 -0
  97. package/dist/types/ui/Input.d.ts +23 -0
  98. package/dist/types/ui/ScrollButtons.d.ts +13 -0
  99. package/dist/types/ui/Select.d.ts +21 -0
  100. package/dist/types/ui/Separator.d.ts +2 -0
  101. package/dist/types/ui/SimpleModal.d.ts +4 -0
  102. package/dist/types/ui/Toolbar.d.ts +44 -0
  103. package/dist/types/ui/ToolbarLoader.d.ts +4 -0
  104. package/dist/types/ui/messages.d.ts +48 -0
  105. package/dist/types/ui/styles.d.ts +20 -0
  106. package/dist/types/utils.d.ts +2 -0
  107. package/dist/types-ts4.5/index.d.ts +1 -0
  108. package/dist/types-ts4.5/plugin.d.ts +12 -0
  109. package/dist/types-ts4.5/pm-plugins/force-focus/index.d.ts +21 -0
  110. package/dist/types-ts4.5/pm-plugins/toolbar-data/commands.d.ts +3 -0
  111. package/dist/types-ts4.5/pm-plugins/toolbar-data/plugin-factory.d.ts +1 -0
  112. package/dist/types-ts4.5/pm-plugins/toolbar-data/plugin-key.d.ts +3 -0
  113. package/dist/types-ts4.5/pm-plugins/toolbar-data/plugin.d.ts +3 -0
  114. package/dist/types-ts4.5/pm-plugins/toolbar-data/reducer.d.ts +3 -0
  115. package/dist/types-ts4.5/pm-plugins/toolbar-data/types.d.ts +8 -0
  116. package/dist/types-ts4.5/ui/CheckboxModal.d.ts +4 -0
  117. package/dist/types-ts4.5/ui/ConfirmationModal.d.ts +6 -0
  118. package/dist/types-ts4.5/ui/Dropdown.d.ts +41 -0
  119. package/dist/types-ts4.5/ui/DropdownMenu.d.ts +29 -0
  120. package/dist/types-ts4.5/ui/EditorEmojiAddIcon.d.ts +2 -0
  121. package/dist/types-ts4.5/ui/EmojiPickerButton.d.ts +16 -0
  122. package/dist/types-ts4.5/ui/ExtensionsPlaceholder.d.ts +16 -0
  123. package/dist/types-ts4.5/ui/Input.d.ts +23 -0
  124. package/dist/types-ts4.5/ui/ScrollButtons.d.ts +13 -0
  125. package/dist/types-ts4.5/ui/Select.d.ts +21 -0
  126. package/dist/types-ts4.5/ui/Separator.d.ts +2 -0
  127. package/dist/types-ts4.5/ui/SimpleModal.d.ts +4 -0
  128. package/dist/types-ts4.5/ui/Toolbar.d.ts +44 -0
  129. package/dist/types-ts4.5/ui/ToolbarLoader.d.ts +4 -0
  130. package/dist/types-ts4.5/ui/messages.d.ts +48 -0
  131. package/dist/types-ts4.5/ui/styles.d.ts +20 -0
  132. package/dist/types-ts4.5/utils.d.ts +2 -0
  133. package/package.json +32 -3
  134. package/report.api.md +3 -0
  135. package/tmp/api-report-tmp.d.ts +3 -0
@@ -0,0 +1,48 @@
1
+ import { defineMessages } from 'react-intl-next';
2
+ export default defineMessages({
3
+ confirmModalDefaultHeading: {
4
+ id: 'fabric.editor.floatingToolbar.confirmModalHeading',
5
+ defaultMessage: 'Are you sure?',
6
+ description: 'Default heading of floating toolbar confirmation modal.'
7
+ },
8
+ confirmModalOK: {
9
+ id: 'fabric.editor.floatingToolbar.confirmModalOK',
10
+ defaultMessage: 'OK',
11
+ description: 'OK button for floating toolbar confirmation modal.'
12
+ },
13
+ confirmModalCancel: {
14
+ id: 'fabric.editor.floatingToolbar.confirmModalCancel',
15
+ defaultMessage: 'Cancel',
16
+ description: 'Cancel button for floating toolbar confirmation modal.'
17
+ },
18
+ confirmModalListUnit: {
19
+ id: 'fabric.editor.floatingToolbar.confirmModalConnectedUnit',
20
+ defaultMessage: '{name}{amount, plural, =0 {} one { (+1 connected element)} other { (+# connected elements)}}',
21
+ description: 'Text displayed in confirmation modal which highlights the nodes and the amount of connected nodes that will be deleted'
22
+ },
23
+ confirmDeleteLinkedModalMessage: {
24
+ id: 'fabric.editor.extension.confirmDeleteLinkedModalMessage',
25
+ defaultMessage: 'Deleting {nodeName} will break anything connected to it.',
26
+ description: 'Message for confirm modal when deleting a extension linked to an data consumer.'
27
+ },
28
+ floatingToolbarAriaLabel: {
29
+ id: 'fabric.editor.floatingToolbar.floatingToolbarAriaLabel',
30
+ defaultMessage: 'Floating Toolbar',
31
+ description: "a floating toolbar's aria label"
32
+ },
33
+ floatingToolbarAnnouncer: {
34
+ id: 'fabric.editor.floatingToolbar.floatingToolbarAnnouncer',
35
+ defaultMessage: 'Floating toolbar controls have been opened',
36
+ description: 'message that will be announced to screenreaders that the floating toolbar is opened'
37
+ },
38
+ floatingToolbarScrollLeft: {
39
+ id: 'fabric.editor.floatingToolbar.scrollLeft',
40
+ defaultMessage: 'Scroll left',
41
+ description: 'Button to scroll left when the toolbar is in the overflow state'
42
+ },
43
+ floatingToolbarScrollRight: {
44
+ id: 'fabric.editor.floatingToolbar.scrollRight',
45
+ defaultMessage: 'Scroll right',
46
+ description: 'Button to scroll right when the toolbar is in the overflow state'
47
+ }
48
+ });
@@ -0,0 +1,64 @@
1
+ import { hexToRgba } from '@atlaskit/adf-schema';
2
+ import * as colors from '@atlaskit/theme/colors';
3
+ const background = {
4
+ danger: {
5
+ default: {
6
+ light: 'inherit',
7
+ dark: 'inherit'
8
+ },
9
+ hover: {
10
+ light: `var(--ds-background-neutral-subtle-hovered, ${colors.N30A})`,
11
+ dark: `var(--ds-background-neutral-subtle-hovered, ${colors.N30A})`
12
+ },
13
+ active: {
14
+ light: `var(--ds-background-neutral-pressed, ${`${hexToRgba(colors.B75, 0.6)}`})`,
15
+ dark: `var(--ds-background-neutral-pressed, ${`${hexToRgba(colors.B75, 0.6)}`})`
16
+ }
17
+ }
18
+ };
19
+ const color = {
20
+ danger: {
21
+ default: {
22
+ light: `var(--ds-icon, ${colors.N400})`,
23
+ dark: `var(--ds-icon, ${colors.DN400})`
24
+ },
25
+ hover: {
26
+ light: `var(--ds-icon-danger, ${colors.R400})`,
27
+ dark: `var(--ds-icon-danger, ${colors.R400})`
28
+ },
29
+ active: {
30
+ light: `var(--ds-icon-danger, ${colors.R400})`,
31
+ dark: `var(--ds-icon-danger, ${colors.R400})`
32
+ }
33
+ }
34
+ };
35
+ const getStyles = (property, {
36
+ appearance = 'default',
37
+ state = 'default',
38
+ mode = 'light'
39
+ }) => {
40
+ if (!property[appearance] || !property[appearance][state]) {
41
+ return 'initial';
42
+ }
43
+ return property[appearance][state][mode];
44
+ };
45
+ export const iconOnlySpacing = {
46
+ '&&': {
47
+ padding: '0px',
48
+ /**
49
+ Increased specificity here because css for .hyperlink-open-link defined in
50
+ packages/editor/editor-core/src/ui/ContentStyles/index.tsx file
51
+ overrides padding left-right 2px with 4px.
52
+ */
53
+ '&&[href]': {
54
+ padding: '0 2px'
55
+ }
56
+ },
57
+ '& > span': {
58
+ margin: '0px'
59
+ }
60
+ };
61
+ export const getButtonStyles = props => ({
62
+ background: getStyles(background, props),
63
+ color: getStyles(color, props)
64
+ });
@@ -0,0 +1,16 @@
1
+ // find node in descendants by condition
2
+ export function findNode(parent, predicate) {
3
+ let matchedNode;
4
+ parent.descendants(node => {
5
+ // dont run predicate if node already found
6
+ if (matchedNode) {
7
+ return false;
8
+ }
9
+ if (predicate(node)) {
10
+ matchedNode = node;
11
+ return false;
12
+ }
13
+ return true;
14
+ });
15
+ return matchedNode;
16
+ }
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export { floatingToolbarPlugin } from './plugin';
@@ -0,0 +1,373 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ import React from 'react';
5
+ import camelCase from 'lodash/camelCase';
6
+ import { ACTION, ACTION_SUBJECT, CONTENT_COMPONENT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
7
+ import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
8
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
9
+ import { WithProviders } from '@atlaskit/editor-common/provider-factory';
10
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
11
+ import { Popup } from '@atlaskit/editor-common/ui';
12
+ import { AllSelection, PluginKey } from '@atlaskit/editor-prosemirror/state';
13
+ import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
14
+ import forceFocusPlugin, { forceFocusSelector } from './pm-plugins/force-focus';
15
+ import { hideConfirmDialog } from './pm-plugins/toolbar-data/commands';
16
+ import { createPlugin as floatingToolbarDataPluginFactory } from './pm-plugins/toolbar-data/plugin';
17
+ import { pluginKey as dataPluginKey } from './pm-plugins/toolbar-data/plugin-key';
18
+ import { ConfirmationModal } from './ui/ConfirmationModal';
19
+ import { ToolbarLoader } from './ui/ToolbarLoader';
20
+ import { findNode } from './utils';
21
+
22
+ // AFP-2532 TODO: Fix automatic suppressions below
23
+ export var getRelevantConfig = function getRelevantConfig(selection, configs) {
24
+ // node selections always take precedence, see if
25
+ var configPair;
26
+ configs.find(function (config) {
27
+ var node = findSelectedNodeOfType(config.nodeType)(selection);
28
+ if (node) {
29
+ configPair = {
30
+ node: node.node,
31
+ pos: node.pos,
32
+ config: config
33
+ };
34
+ }
35
+ return !!node;
36
+ });
37
+ if (configPair) {
38
+ return configPair;
39
+ }
40
+
41
+ // create mapping of node type name to configs
42
+ var configByNodeType = {};
43
+ configs.forEach(function (config) {
44
+ if (Array.isArray(config.nodeType)) {
45
+ config.nodeType.forEach(function (nodeType) {
46
+ configByNodeType[nodeType.name] = config;
47
+ });
48
+ } else {
49
+ configByNodeType[config.nodeType.name] = config;
50
+ }
51
+ });
52
+
53
+ // search up the tree from selection
54
+ var $from = selection.$from;
55
+ for (var i = $from.depth; i > 0; i--) {
56
+ var node = $from.node(i);
57
+ var matchedConfig = configByNodeType[node.type.name];
58
+ if (matchedConfig) {
59
+ return {
60
+ config: matchedConfig,
61
+ node: node,
62
+ pos: $from.pos
63
+ };
64
+ }
65
+ }
66
+
67
+ // if it is AllSelection (can be result of Cmd+A) - use first node
68
+ if (selection instanceof AllSelection) {
69
+ var docNode = $from.node(0);
70
+ var _matchedConfig = null;
71
+ var firstChild = findNode(docNode, function (node) {
72
+ _matchedConfig = configByNodeType[node.type.name];
73
+ return !!_matchedConfig;
74
+ });
75
+ if (firstChild && _matchedConfig) {
76
+ return {
77
+ config: _matchedConfig,
78
+ node: firstChild,
79
+ pos: $from.pos
80
+ };
81
+ }
82
+ }
83
+ return;
84
+ };
85
+ var getDomRefFromSelection = function getDomRefFromSelection(view, dispatchAnalyticsEvent) {
86
+ try {
87
+ return findDomRefAtPos(view.state.selection.from, view.domAtPos.bind(view));
88
+ } catch (error) {
89
+ // eslint-disable-next-line no-console
90
+ console.warn(error);
91
+ if (dispatchAnalyticsEvent) {
92
+ var payload = {
93
+ action: ACTION.ERRORED,
94
+ actionSubject: ACTION_SUBJECT.CONTENT_COMPONENT,
95
+ eventType: EVENT_TYPE.OPERATIONAL,
96
+ attributes: {
97
+ component: CONTENT_COMPONENT.FLOATING_TOOLBAR,
98
+ selection: view.state.selection.toJSON(),
99
+ position: view.state.selection.from,
100
+ docSize: view.state.doc.nodeSize,
101
+ error: error.toString(),
102
+ errorStack: error.stack || undefined
103
+ }
104
+ };
105
+ dispatchAnalyticsEvent(payload);
106
+ }
107
+ }
108
+ };
109
+ function filterUndefined(x) {
110
+ return !!x;
111
+ }
112
+ export var floatingToolbarPlugin = function floatingToolbarPlugin(_ref) {
113
+ var api = _ref.api;
114
+ return {
115
+ name: 'floatingToolbar',
116
+ pmPlugins: function pmPlugins() {
117
+ var floatingToolbarHandlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
118
+ return [{
119
+ // Should be after all toolbar plugins
120
+ name: 'floatingToolbar',
121
+ plugin: function plugin(_ref2) {
122
+ var dispatch = _ref2.dispatch,
123
+ providerFactory = _ref2.providerFactory,
124
+ getIntl = _ref2.getIntl;
125
+ return floatingToolbarPluginFactory({
126
+ floatingToolbarHandlers: floatingToolbarHandlers,
127
+ dispatch: dispatch,
128
+ providerFactory: providerFactory,
129
+ getIntl: getIntl
130
+ });
131
+ }
132
+ }, {
133
+ name: 'floatingToolbarData',
134
+ plugin: function plugin(_ref3) {
135
+ var dispatch = _ref3.dispatch;
136
+ return floatingToolbarDataPluginFactory(dispatch);
137
+ }
138
+ }, {
139
+ name: 'forceFocus',
140
+ plugin: function plugin() {
141
+ return forceFocusPlugin();
142
+ }
143
+ }];
144
+ },
145
+ actions: {
146
+ forceFocusSelector: forceFocusSelector
147
+ },
148
+ getSharedState: function getSharedState(editorState) {
149
+ var _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
150
+ if (!editorState) {
151
+ return undefined;
152
+ }
153
+ var configWithNodeInfo = (_pluginKey$getState$g = (_pluginKey$getState = pluginKey.getState(editorState)) === null || _pluginKey$getState === void 0 ? void 0 : (_pluginKey$getState$g2 = _pluginKey$getState.getConfigWithNodeInfo) === null || _pluginKey$getState$g2 === void 0 ? void 0 : _pluginKey$getState$g2.call(_pluginKey$getState, editorState)) !== null && _pluginKey$getState$g !== void 0 ? _pluginKey$getState$g : undefined;
154
+ return {
155
+ configWithNodeInfo: configWithNodeInfo,
156
+ floatingToolbarData: dataPluginKey.getState(editorState)
157
+ };
158
+ },
159
+ contentComponent: function contentComponent(_ref4) {
160
+ var popupsMountPoint = _ref4.popupsMountPoint,
161
+ popupsBoundariesElement = _ref4.popupsBoundariesElement,
162
+ popupsScrollableElement = _ref4.popupsScrollableElement,
163
+ editorView = _ref4.editorView,
164
+ providerFactory = _ref4.providerFactory,
165
+ dispatchAnalyticsEvent = _ref4.dispatchAnalyticsEvent;
166
+ return /*#__PURE__*/React.createElement(ContentComponent, {
167
+ editorView: editorView,
168
+ pluginInjectionApi: api,
169
+ popupsMountPoint: popupsMountPoint,
170
+ popupsBoundariesElement: popupsBoundariesElement,
171
+ popupsScrollableElement: popupsScrollableElement,
172
+ providerFactory: providerFactory,
173
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent
174
+ });
175
+ }
176
+ };
177
+ };
178
+ function ContentComponent(_ref5) {
179
+ var _pluginInjectionApi$f, _configWithNodeInfo$c, _configWithNodeInfo$c2;
180
+ var pluginInjectionApi = _ref5.pluginInjectionApi,
181
+ editorView = _ref5.editorView,
182
+ popupsMountPoint = _ref5.popupsMountPoint,
183
+ popupsBoundariesElement = _ref5.popupsBoundariesElement,
184
+ popupsScrollableElement = _ref5.popupsScrollableElement,
185
+ providerFactory = _ref5.providerFactory,
186
+ dispatchAnalyticsEvent = _ref5.dispatchAnalyticsEvent;
187
+ var featureFlags = (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$f = pluginInjectionApi.featureFlags) === null || _pluginInjectionApi$f === void 0 ? void 0 : _pluginInjectionApi$f.sharedState.currentState()) || {};
188
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['floatingToolbar', 'editorDisabled']),
189
+ floatingToolbarState = _useSharedPluginState.floatingToolbarState,
190
+ editorDisabledState = _useSharedPluginState.editorDisabledState;
191
+ var _ref6 = floatingToolbarState !== null && floatingToolbarState !== void 0 ? floatingToolbarState : {},
192
+ configWithNodeInfo = _ref6.configWithNodeInfo,
193
+ floatingToolbarData = _ref6.floatingToolbarData;
194
+ if (!configWithNodeInfo || !configWithNodeInfo.config || typeof ((_configWithNodeInfo$c = configWithNodeInfo.config) === null || _configWithNodeInfo$c === void 0 ? void 0 : _configWithNodeInfo$c.visible) !== 'undefined' && !((_configWithNodeInfo$c2 = configWithNodeInfo.config) !== null && _configWithNodeInfo$c2 !== void 0 && _configWithNodeInfo$c2.visible)) {
195
+ return null;
196
+ }
197
+ var config = configWithNodeInfo.config,
198
+ node = configWithNodeInfo.node;
199
+ var title = config.title,
200
+ _config$getDomRef = config.getDomRef,
201
+ getDomRef = _config$getDomRef === void 0 ? getDomRefFromSelection : _config$getDomRef,
202
+ items = config.items,
203
+ _config$align = config.align,
204
+ align = _config$align === void 0 ? 'center' : _config$align,
205
+ _config$className = config.className,
206
+ className = _config$className === void 0 ? '' : _config$className,
207
+ height = config.height,
208
+ width = config.width,
209
+ zIndex = config.zIndex,
210
+ _config$offset = config.offset,
211
+ offset = _config$offset === void 0 ? [0, 12] : _config$offset,
212
+ forcePlacement = config.forcePlacement,
213
+ preventPopupOverflow = config.preventPopupOverflow,
214
+ onPositionCalculated = config.onPositionCalculated,
215
+ _config$absoluteOffse = config.absoluteOffset,
216
+ absoluteOffset = _config$absoluteOffse === void 0 ? {
217
+ top: 0,
218
+ left: 0,
219
+ right: 0,
220
+ bottom: 0
221
+ } : _config$absoluteOffse,
222
+ focusTrap = config.focusTrap;
223
+ var targetRef = getDomRef(editorView, dispatchAnalyticsEvent);
224
+ if (!targetRef || editorDisabledState && editorDisabledState.editorDisabled) {
225
+ return null;
226
+ }
227
+ var customPositionCalculation;
228
+ var toolbarItems = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.copyButton.actions.processCopyButtonItems(editorView.state)(Array.isArray(items) ? items : items(node), pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.decorations.actions.hoverDecoration);
229
+ if (onPositionCalculated) {
230
+ customPositionCalculation = function customPositionCalculation(nextPos) {
231
+ return onPositionCalculated(editorView, nextPos);
232
+ };
233
+ }
234
+ var dispatchCommand = function dispatchCommand(fn) {
235
+ return fn && fn(editorView.state, editorView.dispatch, editorView);
236
+ };
237
+
238
+ // Confirm dialog
239
+ var _ref7 = floatingToolbarData || {},
240
+ confirmDialogForItem = _ref7.confirmDialogForItem;
241
+ var confirmButtonItem = confirmDialogForItem ? toolbarItems[confirmDialogForItem] : undefined;
242
+ var scrollable = config.scrollable;
243
+ var confirmDialogOptions = typeof (confirmButtonItem === null || confirmButtonItem === void 0 ? void 0 : confirmButtonItem.confirmDialog) === 'function' ? confirmButtonItem === null || confirmButtonItem === void 0 ? void 0 : confirmButtonItem.confirmDialog() : confirmButtonItem === null || confirmButtonItem === void 0 ? void 0 : confirmButtonItem.confirmDialog;
244
+ return /*#__PURE__*/React.createElement(ErrorBoundary, {
245
+ component: ACTION_SUBJECT.FLOATING_TOOLBAR_PLUGIN,
246
+ componentId: camelCase(title),
247
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
248
+ fallbackComponent: null
249
+ }, /*#__PURE__*/React.createElement(Popup, {
250
+ ariaLabel: title,
251
+ offset: offset,
252
+ target: targetRef,
253
+ alignY: "bottom",
254
+ forcePlacement: forcePlacement,
255
+ fitHeight: height,
256
+ fitWidth: width,
257
+ absoluteOffset: absoluteOffset,
258
+ alignX: align,
259
+ stick: true,
260
+ zIndex: zIndex,
261
+ mountTo: popupsMountPoint,
262
+ boundariesElement: popupsBoundariesElement,
263
+ scrollableElement: popupsScrollableElement,
264
+ onPositionCalculated: customPositionCalculation,
265
+ style: scrollable ? {
266
+ maxWidth: '100%'
267
+ } : {},
268
+ focusTrap: focusTrap,
269
+ preventOverflow: preventPopupOverflow
270
+ }, /*#__PURE__*/React.createElement(WithProviders, {
271
+ providerFactory: providerFactory,
272
+ providers: ['extensionProvider'],
273
+ renderNode: function renderNode(providers) {
274
+ return /*#__PURE__*/React.createElement(ToolbarLoader, {
275
+ target: targetRef,
276
+ items: toolbarItems,
277
+ node: node,
278
+ dispatchCommand: dispatchCommand,
279
+ editorView: editorView,
280
+ className: className,
281
+ focusEditor: function focusEditor() {
282
+ return editorView.focus();
283
+ },
284
+ providerFactory: providerFactory,
285
+ popupsMountPoint: popupsMountPoint,
286
+ popupsBoundariesElement: popupsBoundariesElement,
287
+ popupsScrollableElement: popupsScrollableElement,
288
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
289
+ extensionsProvider: providers.extensionProvider,
290
+ scrollable: scrollable,
291
+ featureFlags: featureFlags,
292
+ api: pluginInjectionApi
293
+ });
294
+ }
295
+ })), /*#__PURE__*/React.createElement(ConfirmationModal, {
296
+ testId: "ak-floating-toolbar-confirmation-modal",
297
+ options: confirmDialogOptions,
298
+ onConfirm: function onConfirm() {
299
+ var isChecked = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
300
+ if (!!confirmDialogOptions.onConfirm) {
301
+ dispatchCommand(confirmDialogOptions.onConfirm(isChecked));
302
+ } else {
303
+ dispatchCommand(confirmButtonItem.onClick);
304
+ }
305
+ },
306
+ onClose: function onClose() {
307
+ dispatchCommand(hideConfirmDialog());
308
+ // Need to set focus to Editor here,
309
+ // As when the Confirmation dialog pop up, and user interacts with the dialog, Editor loses focus.
310
+ // So when Confirmation dialog is closed, Editor does not have the focus, then cursor goes to the position 1 of the doc,
311
+ // instead of the cursor position before the dialog pop up.
312
+ if (!editorView.hasFocus()) {
313
+ editorView.focus();
314
+ }
315
+ }
316
+ }));
317
+ }
318
+
319
+ /**
320
+ *
321
+ * ProseMirror Plugin
322
+ *
323
+ */
324
+ // We throttle update of this plugin with RAF.
325
+ // So from other plugins you will always get the previous state.
326
+ export var pluginKey = new PluginKey('floatingToolbarPluginKey');
327
+
328
+ /**
329
+ * Clean up floating toolbar configs from undesired properties.
330
+ */
331
+ function sanitizeFloatingToolbarConfig(config) {
332
+ // Cleanup from non existing node types
333
+ if (Array.isArray(config.nodeType)) {
334
+ return _objectSpread(_objectSpread({}, config), {}, {
335
+ nodeType: config.nodeType.filter(filterUndefined)
336
+ });
337
+ }
338
+ return config;
339
+ }
340
+ function floatingToolbarPluginFactory(options) {
341
+ var floatingToolbarHandlers = options.floatingToolbarHandlers,
342
+ providerFactory = options.providerFactory,
343
+ getIntl = options.getIntl;
344
+ var intl = getIntl();
345
+ var getConfigWithNodeInfo = function getConfigWithNodeInfo(editorState) {
346
+ var activeConfigs = floatingToolbarHandlers.map(function (handler) {
347
+ return handler(editorState, intl, providerFactory);
348
+ }).filter(filterUndefined).map(function (config) {
349
+ return sanitizeFloatingToolbarConfig(config);
350
+ });
351
+ var relevantConfig = activeConfigs && getRelevantConfig(editorState.selection, activeConfigs);
352
+ return relevantConfig;
353
+ };
354
+ var apply = function apply(tr, pluginState) {
355
+ var newPluginState = {
356
+ getConfigWithNodeInfo: getConfigWithNodeInfo
357
+ };
358
+ return newPluginState;
359
+ };
360
+ return new SafePlugin({
361
+ key: pluginKey,
362
+ state: {
363
+ init: function init() {
364
+ // Use this point to preload the UI
365
+ ToolbarLoader.preload();
366
+ return {
367
+ getConfigWithNodeInfo: getConfigWithNodeInfo
368
+ };
369
+ },
370
+ apply: apply
371
+ }
372
+ });
373
+ }
@@ -0,0 +1,64 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ export var forceFocusStateKey = new PluginKey('forceFocusStatePlugin');
4
+ /**
5
+ * Used in cases where a floating toolbar button opens a submenu which destroys
6
+ * the button, but the user has pressed ESC to close the submenu and focus needs
7
+ * to move back to the button. */
8
+ export default (function () {
9
+ return new SafePlugin({
10
+ key: forceFocusStateKey,
11
+ state: {
12
+ init: function init() {
13
+ return {
14
+ selector: null
15
+ };
16
+ },
17
+ apply: function apply(tr, prevState) {
18
+ var meta = tr.getMeta(forceFocusStateKey);
19
+ if (meta && 'selector' in meta) {
20
+ return {
21
+ selector: meta.selector
22
+ };
23
+ }
24
+ return prevState;
25
+ }
26
+ }
27
+ });
28
+ });
29
+
30
+ /**
31
+ * The provided selector should be the floating toolbar button that needs focus.
32
+ */
33
+ export var forceFocusSelector = function forceFocusSelector(selector) {
34
+ return function (tr) {
35
+ return tr.setMeta(forceFocusStateKey, {
36
+ selector: selector
37
+ });
38
+ };
39
+ };
40
+
41
+ /**
42
+ * If a selector is set and the element exists, focus it.
43
+ */
44
+ export function checkShouldForceFocusAndApply(view) {
45
+ var state = view === null || view === void 0 ? void 0 : view.state;
46
+ if (state) {
47
+ var _forceFocusStateKey$g = forceFocusStateKey.getState(state),
48
+ selector = _forceFocusStateKey$g.selector;
49
+ if (selector) {
50
+ var focusableElement = document.querySelector(selector);
51
+ if (focusableElement) {
52
+ focusableElement.scrollIntoView({
53
+ behavior: 'smooth',
54
+ block: 'center',
55
+ inline: 'nearest'
56
+ });
57
+ focusableElement.focus();
58
+ var tr = view.state.tr,
59
+ dispatch = view.dispatch;
60
+ dispatch(forceFocusSelector(null)(tr));
61
+ }
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,18 @@
1
+ import { createCommand } from './plugin-factory';
2
+ export var showConfirmDialog = function showConfirmDialog(buttonIndex) {
3
+ return createCommand({
4
+ type: 'SHOW_CONFIRM_DIALOG',
5
+ data: {
6
+ buttonIndex: buttonIndex
7
+ }
8
+ }, function (tr) {
9
+ return tr.setMeta('addToHistory', false);
10
+ });
11
+ };
12
+ export var hideConfirmDialog = function hideConfirmDialog() {
13
+ return createCommand({
14
+ type: 'HIDE_CONFIRM_DIALOG'
15
+ }, function (tr) {
16
+ return tr.setMeta('addToHistory', false);
17
+ });
18
+ };
@@ -0,0 +1,8 @@
1
+ import { pluginFactory } from '@atlaskit/editor-common/utils';
2
+ import { pluginKey } from './plugin-key';
3
+ import { reducer } from './reducer';
4
+ var _pluginFactory = pluginFactory(pluginKey, reducer),
5
+ createPluginState = _pluginFactory.createPluginState,
6
+ createCommand = _pluginFactory.createCommand,
7
+ getPluginState = _pluginFactory.getPluginState;
8
+ export { createPluginState, createCommand, getPluginState };
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export var pluginKey = new PluginKey('floatingToolbarData');
@@ -0,0 +1,9 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { createPluginState } from './plugin-factory';
3
+ import { pluginKey } from './plugin-key';
4
+ export var createPlugin = function createPlugin(dispatch) {
5
+ return new SafePlugin({
6
+ state: createPluginState(dispatch, {}),
7
+ key: pluginKey
8
+ });
9
+ };
@@ -0,0 +1,17 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ export var reducer = function reducer(pluginState, action) {
5
+ switch (action.type) {
6
+ case 'SHOW_CONFIRM_DIALOG':
7
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
8
+ confirmDialogForItem: action.data.buttonIndex
9
+ });
10
+ case 'HIDE_CONFIRM_DIALOG':
11
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
12
+ confirmDialogForItem: undefined
13
+ });
14
+ default:
15
+ return pluginState;
16
+ }
17
+ };
@@ -0,0 +1 @@
1
+ export {};