@atlaskit/editor-plugin-insert-block 1.12.0 → 1.14.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/cjs/plugin.js +36 -5
  3. package/dist/cjs/ui/ElementBrowser/InsertMenu.js +47 -13
  4. package/dist/cjs/ui/ElementRail/index.js +186 -2
  5. package/dist/cjs/ui/ElementRail/useInsertMenuRailItems.js +63 -0
  6. package/dist/cjs/ui/templateOptions.js +128 -57
  7. package/dist/cjs/ui/templates.js +1130 -0
  8. package/dist/es2019/plugin.js +36 -5
  9. package/dist/es2019/ui/ElementBrowser/InsertMenu.js +61 -26
  10. package/dist/es2019/ui/ElementRail/index.js +189 -1
  11. package/dist/es2019/ui/ElementRail/useInsertMenuRailItems.js +54 -0
  12. package/dist/es2019/ui/templateOptions.js +78 -11
  13. package/dist/es2019/ui/templates.js +1118 -0
  14. package/dist/esm/plugin.js +36 -5
  15. package/dist/esm/ui/ElementBrowser/InsertMenu.js +47 -13
  16. package/dist/esm/ui/ElementRail/index.js +185 -2
  17. package/dist/esm/ui/ElementRail/useInsertMenuRailItems.js +56 -0
  18. package/dist/esm/ui/templateOptions.js +128 -57
  19. package/dist/esm/ui/templates.js +1124 -0
  20. package/dist/types/ui/ElementRail/index.d.ts +7 -4
  21. package/dist/types/ui/ElementRail/useInsertMenuRailItems.d.ts +4 -0
  22. package/dist/types/ui/ToolbarInsertBlock/create-items.d.ts +1 -1
  23. package/dist/types/ui/templateOptions.d.ts +3 -1
  24. package/dist/types/ui/templates.d.ts +522 -0
  25. package/dist/types-ts4.5/ui/ElementRail/index.d.ts +7 -4
  26. package/dist/types-ts4.5/ui/ElementRail/useInsertMenuRailItems.d.ts +4 -0
  27. package/dist/types-ts4.5/ui/ToolbarInsertBlock/create-items.d.ts +1 -1
  28. package/dist/types-ts4.5/ui/templateOptions.d.ts +3 -1
  29. package/dist/types-ts4.5/ui/templates.d.ts +522 -0
  30. package/package.json +14 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @atlaskit/editor-plugin-insert-block
2
2
 
3
+ ## 1.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#138136](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/138136)
8
+ [`35938ecf46ba7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/35938ecf46ba7) -
9
+ [ED-24755] Implement insert functionality of element templates and fire document inserted event
10
+ with template IDs
11
+
12
+ ### Patch Changes
13
+
14
+ - [#138270](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/138270)
15
+ [`0acb3673d32d9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0acb3673d32d9) -
16
+ Add insert menu to right rail for experiment
17
+ - Updated dependencies
18
+
19
+ ## 1.13.0
20
+
21
+ ### Minor Changes
22
+
23
+ - [#136891](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/136891)
24
+ [`388780c6348e9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/388780c6348e9) -
25
+ Pass emoji provider via preset
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies
30
+
3
31
  ## 1.12.0
4
32
 
5
33
  ### Minor Changes
@@ -12,9 +12,11 @@ var _hooks = require("@atlaskit/editor-common/hooks");
12
12
  var _insert = require("@atlaskit/editor-common/insert");
13
13
  var _messages = require("@atlaskit/editor-common/messages");
14
14
  var _providerFactory = require("@atlaskit/editor-common/provider-factory");
15
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
15
16
  var _types = require("@atlaskit/editor-common/types");
16
17
  var _utils = require("@atlaskit/editor-common/utils");
17
18
  var _consts = require("@atlaskit/editor-plugin-block-type/consts");
19
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
20
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
19
21
  var _switch = _interopRequireDefault(require("./assets/switch"));
20
22
  var _elementBrowser = require("./pm-plugins/elementBrowser");
@@ -65,6 +67,9 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
65
67
  var toggleDropdownMenuOptionsRef = {
66
68
  current: null
67
69
  };
70
+ var editorViewRef = {
71
+ current: null
72
+ };
68
73
  var registerToggleDropdownMenuOptions = function registerToggleDropdownMenuOptions(cb) {
69
74
  toggleDropdownMenuOptionsRef.current = cb;
70
75
  return function () {
@@ -132,6 +137,17 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
132
137
  plugin: function plugin() {
133
138
  return (0, _elementBrowser.elementBrowserPmPlugin)();
134
139
  }
140
+ }, {
141
+ name: 'elementBrowserEditorViewRef',
142
+ plugin: function plugin() {
143
+ return new _safePlugin.SafePlugin({
144
+ view: function view(editorView) {
145
+ // Workaround - need reference to editorView for contextPanel component
146
+ editorViewRef.current = editorView;
147
+ return {};
148
+ }
149
+ });
150
+ }
135
151
  }];
136
152
  },
137
153
  pluginsOptions: {
@@ -197,10 +213,13 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
197
213
  // If we decide to ship the feature, we will consider a separate plugin if needed.
198
214
  // Experiment one-pager: https://hello.atlassian.net/wiki/spaces/ETM/pages/3983684902/Experiment+Drive+element+usage+via+element+templates
199
215
  quickInsert: function quickInsert() {
200
- if ((0, _experiments.editorExperiment)('element-level-templates', true, {
216
+ var _options$UNSAFE_edito;
217
+ if (
218
+ // @ts-ignore
219
+ ['full-page', 'full-width'].includes((_options$UNSAFE_edito = options.UNSAFE_editorAppearance) !== null && _options$UNSAFE_edito !== void 0 ? _options$UNSAFE_edito : '') && (0, _experiments.editorExperiment)('element-level-templates', true, {
201
220
  exposure: true
202
221
  })) {
203
- return _templateOptions.templateOptions;
222
+ return (0, _templateOptions.templateOptions)(api);
204
223
  }
205
224
  return [];
206
225
  }
@@ -219,8 +238,10 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
219
238
  // api.getSharedState() will have an outdated reference to editorState on first mount of this component
220
239
  // so instead just rely on plugin key as we don't need to be reactive to changes here
221
240
  var pluginState = _elementBrowser.elementBrowserPmKey.getState(state);
222
- if (pluginState !== null && pluginState !== void 0 && pluginState.menuBrowserOpen) {
241
+ if (pluginState !== null && pluginState !== void 0 && pluginState.menuBrowserOpen && editorViewRef.current) {
223
242
  return /*#__PURE__*/_react.default.createElement(_ElementRail.InsertMenuRail, {
243
+ editorView: editorViewRef.current,
244
+ options: options,
224
245
  api: api
225
246
  });
226
247
  }
@@ -256,6 +277,16 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
256
277
  mediaState = _useSharedPluginState.mediaState,
257
278
  typeAheadState = _useSharedPluginState.typeAheadState,
258
279
  placeholderTextState = _useSharedPluginState.placeholderTextState;
280
+ var getEmojiProvider = function getEmojiProvider() {
281
+ if ((0, _platformFeatureFlags.fg)('platform_editor_get_emoji_provider_from_config')) {
282
+ if (emojiState !== null && emojiState !== void 0 && emojiState.emojiProvider) {
283
+ return Promise.resolve(emojiState === null || emojiState === void 0 ? void 0 : emojiState.emojiProvider);
284
+ }
285
+ } else {
286
+ return providers.emojiProvider;
287
+ }
288
+ };
289
+ var emojiProvider = getEmojiProvider();
259
290
  return /*#__PURE__*/_react.default.createElement(_ToolbarInsertBlock.default, {
260
291
  pluginInjectionApi: pluginInjectionApi,
261
292
  buttons: buttons,
@@ -282,8 +313,8 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
282
313
  availableWrapperBlockTypes: blockTypeState && blockTypeState.availableWrapperBlockTypes,
283
314
  linkSupported: !!hyperlinkState,
284
315
  linkDisabled: !hyperlinkState || !hyperlinkState.canInsertLink || !!hyperlinkState.activeLinkMark,
285
- emojiDisabled: !emojiState || !providers.emojiProvider,
286
- emojiProvider: providers.emojiProvider,
316
+ emojiDisabled: !emojiState || !emojiProvider,
317
+ emojiProvider: emojiProvider,
287
318
  nativeStatusSupported: options.nativeStatusSupported,
288
319
  horizontalRuleEnabled: options.horizontalRuleEnabled,
289
320
  onInsertBlockType: handleInsertBlockType(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.codeBlock) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions.insertCodeBlock, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$p = pluginInjectionApi.panel) === null || _pluginInjectionApi$p === void 0 ? void 0 : _pluginInjectionApi$p.actions.insertPanel, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$b = pluginInjectionApi.blockType) === null || _pluginInjectionApi$b === void 0 ? void 0 : _pluginInjectionApi$b.actions.insertBlockQuote),
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
12
  var _react = require("react");
12
13
  var _react2 = require("@emotion/react");
@@ -16,6 +17,7 @@ var _quickInsert = require("@atlaskit/editor-common/quick-insert");
16
17
  var _uiReact = require("@atlaskit/editor-common/ui-react");
17
18
  var _theme = require("@atlaskit/theme");
18
19
  var _colors = require("@atlaskit/theme/colors");
20
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
19
21
  var _excluded = ["children"];
20
22
  /**
21
23
  * @jsxRuntime classic
@@ -25,7 +27,7 @@ var _excluded = ["children"];
25
27
  // AFP-2532 TODO: Fix automatic suppressions below
26
28
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
27
29
  var InsertMenu = function InsertMenu(_ref) {
28
- var _pluginInjectionApi$q6, _pluginInjectionApi$q7;
30
+ var _pluginInjectionApi$q7, _pluginInjectionApi$q8;
29
31
  var editorView = _ref.editorView,
30
32
  dropdownItems = _ref.dropdownItems,
31
33
  showElementBrowserLink = _ref.showElementBrowserLink,
@@ -63,12 +65,19 @@ var InsertMenu = function InsertMenu(_ref) {
63
65
  var quickInsertDropdownItems = dropdownItems.map(transform);
64
66
  var viewMoreItem = showElementBrowserLink ? quickInsertDropdownItems.pop() : undefined;
65
67
  var onInsertItem = (0, _react.useCallback)(function (item) {
66
- var _pluginInjectionApi$q;
67
68
  toggleVisiblity();
68
69
  if (!editorView.hasFocus()) {
69
70
  editorView.focus();
70
71
  }
71
- pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q === void 0 || _pluginInjectionApi$q.actions.insertItem(item, _analytics.INPUT_METHOD.TOOLBAR)(editorView.state, editorView.dispatch);
72
+ if ((0, _experiments.editorExperiment)('insert-menu-in-right-rail', true)) {
73
+ var _pluginInjectionApi$q;
74
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q === void 0 || _pluginInjectionApi$q.actions.insertItem(item,
75
+ // @ts-expect-error
76
+ _analytics.INPUT_METHOD.INSERT_MENU_RIGHT_RAIL)(editorView.state, editorView.dispatch);
77
+ } else {
78
+ var _pluginInjectionApi$q2;
79
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q2 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q2 === void 0 || _pluginInjectionApi$q2.actions.insertItem(item, _analytics.INPUT_METHOD.TOOLBAR)(editorView.state, editorView.dispatch);
80
+ }
72
81
  }, [editorView, toggleVisiblity, pluginInjectionApi]);
73
82
  var getItems = (0, _react.useCallback)(function (query, category) {
74
83
  var result;
@@ -79,23 +88,35 @@ var InsertMenu = function InsertMenu(_ref) {
79
88
  * @see above transform function for more details.
80
89
  */
81
90
  if (query) {
82
- var _pluginInjectionApi$q2, _pluginInjectionApi$q3;
83
- result = (_pluginInjectionApi$q2 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q3 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q3 === void 0 ? void 0 : _pluginInjectionApi$q3.actions.getSuggestions({
91
+ var _pluginInjectionApi$q3, _pluginInjectionApi$q4;
92
+ result = (_pluginInjectionApi$q3 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q4 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q4 === void 0 ? void 0 : _pluginInjectionApi$q4.actions.getSuggestions({
84
93
  query: query,
85
94
  category: category
86
- })) !== null && _pluginInjectionApi$q2 !== void 0 ? _pluginInjectionApi$q2 : [];
95
+ })) !== null && _pluginInjectionApi$q3 !== void 0 ? _pluginInjectionApi$q3 : [];
87
96
  } else {
88
- var _pluginInjectionApi$q4, _pluginInjectionApi$q5;
89
- var featuredQuickInsertSuggestions = (_pluginInjectionApi$q4 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q5 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q5 === void 0 ? void 0 : _pluginInjectionApi$q5.actions.getSuggestions({
97
+ var _pluginInjectionApi$q5, _pluginInjectionApi$q6;
98
+ var featuredQuickInsertSuggestions = (_pluginInjectionApi$q5 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q6 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q6 === void 0 ? void 0 : _pluginInjectionApi$q6.actions.getSuggestions({
90
99
  category: category,
91
- featuredItems: true
92
- })) !== null && _pluginInjectionApi$q4 !== void 0 ? _pluginInjectionApi$q4 : [];
93
- result = quickInsertDropdownItems.concat(featuredQuickInsertSuggestions);
100
+ featuredItems: true,
101
+ // @ts-ignore
102
+ templateItems: (0, _experiments.editorExperiment)('element-level-templates', true)
103
+ })) !== null && _pluginInjectionApi$q5 !== void 0 ? _pluginInjectionApi$q5 : [];
104
+ if ((0, _experiments.editorExperiment)('element-level-templates', true)) {
105
+ // Make sure template options appear as top 5 items
106
+ featuredQuickInsertSuggestions.sort(function (a, b) {
107
+ var _b$priority, _a$priority;
108
+ return ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : 0) - ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : 0);
109
+ });
110
+ var templateItems = featuredQuickInsertSuggestions.splice(0, 5);
111
+ result = [].concat((0, _toConsumableArray2.default)(templateItems), (0, _toConsumableArray2.default)(quickInsertDropdownItems), (0, _toConsumableArray2.default)(featuredQuickInsertSuggestions));
112
+ } else {
113
+ result = quickInsertDropdownItems.concat(featuredQuickInsertSuggestions);
114
+ }
94
115
  }
95
116
  setItemCount(result.length);
96
117
  return result;
97
- }, [pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q6 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q6 === void 0 ? void 0 : _pluginInjectionApi$q6.actions, quickInsertDropdownItems]);
98
- var emptyStateHandler = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q7 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q7 === void 0 || (_pluginInjectionApi$q7 = _pluginInjectionApi$q7.sharedState.currentState()) === null || _pluginInjectionApi$q7 === void 0 ? void 0 : _pluginInjectionApi$q7.emptyStateHandler;
118
+ }, [pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q7 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q7 === void 0 ? void 0 : _pluginInjectionApi$q7.actions, quickInsertDropdownItems]);
119
+ var emptyStateHandler = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q8 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q8 === void 0 || (_pluginInjectionApi$q8 = _pluginInjectionApi$q8.sharedState.currentState()) === null || _pluginInjectionApi$q8 === void 0 ? void 0 : _pluginInjectionApi$q8.emptyStateHandler;
99
120
  return (
100
121
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
101
122
  (0, _react2.jsx)("div", {
@@ -144,6 +165,19 @@ var getInsertMenuHeight = function getInsertMenuHeight(_ref3) {
144
165
  return 560; // For showing 6 Elements.
145
166
  };
146
167
  var insertMenuWrapper = function insertMenuWrapper(itemCount) {
168
+ if ((0, _experiments.editorExperiment)('insert-menu-in-right-rail', true)) {
169
+ return (0, _react2.css)({
170
+ display: 'flex',
171
+ flexDirection: 'column',
172
+ width: '310px',
173
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
174
+ height: 'calc(100% - 32px)',
175
+ margin: "0 -10px",
176
+ backgroundColor: "".concat("var(--ds-surface-overlay, ".concat(_colors.N0, ")")),
177
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
178
+ borderRadius: "".concat((0, _theme.borderRadius)(), "px")
179
+ });
180
+ }
147
181
  return (0, _react2.css)({
148
182
  display: 'flex',
149
183
  flexDirection: 'column',
@@ -6,11 +6,195 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.InsertMenuRail = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _new = require("@atlaskit/button/new");
11
+ var _analytics = require("@atlaskit/editor-common/analytics");
12
+ var _messages = require("@atlaskit/editor-common/messages");
13
+ var _heading = _interopRequireDefault(require("@atlaskit/heading"));
14
+ var _cross = _interopRequireDefault(require("@atlaskit/icon/glyph/cross"));
15
+ var _primitives = require("@atlaskit/primitives");
16
+ var _commands = require("../../pm-plugins/commands");
17
+ var _InsertMenu = _interopRequireDefault(require("../ElementBrowser/InsertMenu"));
18
+ var _useInsertMenuRailItems = require("./useInsertMenuRailItems");
19
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
20
+
21
+ var panelWrapper = (0, _primitives.xcss)({
22
+ height: '100%'
23
+ });
24
+ var panelContentHeader = (0, _primitives.xcss)({
25
+ height: '32px',
26
+ display: 'flex',
27
+ justifyContent: 'space-between',
28
+ alignItems: 'center'
29
+ });
30
+
9
31
  /**
10
32
  * For insert menu in right rail experiment
11
33
  * - Clean up ticket ED-24801
12
34
  */
13
35
  var InsertMenuRail = exports.InsertMenuRail = function InsertMenuRail(_ref) {
14
- var api = _ref.api;
15
- return /*#__PURE__*/_react.default.createElement("div", null);
36
+ var editorView = _ref.editorView,
37
+ options = _ref.options,
38
+ api = _ref.api;
39
+ var dropdownItems = (0, _useInsertMenuRailItems.useInsertMenuRailItems)(editorView, options, api);
40
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
41
+ formatMessage = _useIntl.formatMessage;
42
+ var onInsert = function onInsert(_ref2) {
43
+ var _api$core, _api$hyperlink, _api$imageUpload, _api$media, _api$mention, _api$emoji, _api$codeBlock, _api$blockType, _api$panel, _api$taskDecision, _api$taskDecision2, _api$rule, _api$core2, _api$quickInsert, _api$core3, _api$date, _api$placeholderText, _api$layout, _api$core4, _api$status;
44
+ var item = _ref2.item;
45
+ var state = editorView.state,
46
+ dispatch = editorView.dispatch;
47
+ var inputMethod = _analytics.INPUT_METHOD.INSERT_MENU_RIGHT_RAIL;
48
+ if (!api) {
49
+ return;
50
+ }
51
+ if (!editorView.hasFocus()) {
52
+ editorView.focus();
53
+ }
54
+
55
+ // Below is duplicated from ToolbarInsertBlock/index.tsx - this function is only called
56
+ // for BlockMenuItem items, which are rendered in the insert menu when no search has been performed.
57
+ // When a search is performed, the list will be filled by QuickInsertItems, which handle their own insertion.
58
+ switch (item.value.name) {
59
+ case 'link':
60
+ // @ts-expect-error
61
+ (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$hyperlink = api.hyperlink) === null || _api$hyperlink === void 0 ? void 0 : _api$hyperlink.commands.showLinkToolbar(inputMethod));
62
+ break;
63
+ case 'table':
64
+ // workaround to solve race condition where cursor is not placed correctly inside table
65
+ queueMicrotask(function () {
66
+ var _api$table, _api$table$actions$in, _api$table$actions;
67
+ // @ts-expect-error
68
+ (_api$table = api.table) === null || _api$table === void 0 || (_api$table$actions$in = (_api$table$actions = _api$table.actions).insertTable) === null || _api$table$actions$in === void 0 || _api$table$actions$in.call(_api$table$actions, {
69
+ action: _analytics.ACTION.INSERTED,
70
+ actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
71
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.TABLE,
72
+ attributes: {
73
+ inputMethod: inputMethod
74
+ },
75
+ eventType: _analytics.EVENT_TYPE.TRACK
76
+ })(state, dispatch);
77
+ });
78
+ break;
79
+ case 'image upload':
80
+ (_api$imageUpload = api.imageUpload) === null || _api$imageUpload === void 0 || _api$imageUpload.actions.startUpload()(state, dispatch);
81
+ break;
82
+ case 'media':
83
+ var mediaState = (_api$media = api.media) === null || _api$media === void 0 ? void 0 : _api$media.sharedState.currentState();
84
+ if (mediaState) {
85
+ var _api$analytics;
86
+ mediaState.showMediaPicker();
87
+ // @ts-expect-error
88
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
89
+ action: _analytics.ACTION.OPENED,
90
+ actionSubject: _analytics.ACTION_SUBJECT.PICKER,
91
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.PICKER_CLOUD,
92
+ attributes: {
93
+ inputMethod: inputMethod
94
+ },
95
+ eventType: _analytics.EVENT_TYPE.UI
96
+ });
97
+ }
98
+ break;
99
+ case 'mention':
100
+ var pluginState = (_api$mention = api.mention) === null || _api$mention === void 0 ? void 0 : _api$mention.sharedState.currentState();
101
+ if (pluginState && pluginState.canInsertMention) {
102
+ var _api$mention2;
103
+ // @ts-expect-error
104
+ (_api$mention2 = api.mention) === null || _api$mention2 === void 0 || (_api$mention2 = _api$mention2.actions) === null || _api$mention2 === void 0 || _api$mention2.openTypeAhead(inputMethod);
105
+ }
106
+ break;
107
+ case 'emoji':
108
+ // @ts-expect-error
109
+ (_api$emoji = api.emoji) === null || _api$emoji === void 0 || _api$emoji.actions.openTypeAhead(inputMethod);
110
+ break;
111
+ case 'codeblock':
112
+ (_api$codeBlock = api.codeBlock) === null || _api$codeBlock === void 0 || _api$codeBlock.actions.insertCodeBlock(inputMethod);
113
+ break;
114
+ case 'blockquote':
115
+ // @ts-expect-error
116
+ (_api$blockType = api.blockType) === null || _api$blockType === void 0 || _api$blockType.actions.insertBlockQuote(inputMethod);
117
+ break;
118
+ case 'panel':
119
+ (_api$panel = api.panel) === null || _api$panel === void 0 || _api$panel.actions.insertPanel(inputMethod);
120
+ break;
121
+ case 'action':
122
+ // @ts-expect-error
123
+ (_api$taskDecision = api.taskDecision) === null || _api$taskDecision === void 0 || _api$taskDecision.actions.insertTaskDecision('taskList', inputMethod)(state, dispatch);
124
+ break;
125
+ case 'decision':
126
+ // @ts-expect-error
127
+ (_api$taskDecision2 = api.taskDecision) === null || _api$taskDecision2 === void 0 || _api$taskDecision2.actions.insertTaskDecision('decisionList', inputMethod)(state, dispatch);
128
+ break;
129
+ case 'horizontalrule':
130
+ // @ts-expect-error
131
+ (_api$rule = api.rule) === null || _api$rule === void 0 || _api$rule.actions.insertHorizontalRule(inputMethod)(state, dispatch);
132
+ break;
133
+ case 'macro':
134
+ (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute((_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 ? void 0 : _api$quickInsert.commands.openElementBrowserModal);
135
+ break;
136
+ case 'date':
137
+ (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute((_api$date = api.date) === null || _api$date === void 0 || (_api$date = _api$date.commands) === null || _api$date === void 0 ? void 0 : _api$date.insertDate({
138
+ // @ts-expect-error
139
+ inputMethod: inputMethod
140
+ }));
141
+ break;
142
+ case 'placeholder text':
143
+ (_api$placeholderText = api.placeholderText) === null || _api$placeholderText === void 0 || _api$placeholderText.actions.showPlaceholderFloatingToolbar(editorView.state, editorView.dispatch);
144
+ break;
145
+ case 'layout':
146
+ // @ts-expect-error
147
+ (_api$layout = api.layout) === null || _api$layout === void 0 || _api$layout.actions.insertLayoutColumns(inputMethod)(editorView.state, editorView.dispatch);
148
+ break;
149
+ case 'status':
150
+ // @ts-expect-error
151
+ (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute((_api$status = api.status) === null || _api$status === void 0 || (_api$status = _api$status.commands) === null || _api$status === void 0 ? void 0 : _api$status.insertStatus(inputMethod));
152
+ break;
153
+
154
+ // https://product-fabric.atlassian.net/browse/ED-8053
155
+ // @ts-ignore: OK to fallthrough to default
156
+ case 'expand':
157
+ if (options.allowExpand) {
158
+ var _api$expand;
159
+ (_api$expand = api.expand) === null || _api$expand === void 0 || _api$expand.actions.insertExpand(state, dispatch);
160
+ break;
161
+ }
162
+
163
+ // eslint-disable-next-line no-fallthrough
164
+ default:
165
+ // leaving this blank for now
166
+ }
167
+ };
168
+ return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
169
+ xcss: panelWrapper
170
+ }, /*#__PURE__*/_react.default.createElement(_primitives.Box, {
171
+ xcss: panelContentHeader
172
+ }, /*#__PURE__*/_react.default.createElement(_heading.default, {
173
+ size: "small",
174
+ as: "h2"
175
+ }, formatMessage(_messages.toolbarInsertBlockMessages.insertRightRailTitle)), /*#__PURE__*/_react.default.createElement(_new.IconButton, {
176
+ appearance: "subtle",
177
+ testId: "right-rail-insert-menu-close-button",
178
+ label: formatMessage(_messages.toolbarInsertBlockMessages.closeInsertRightRail),
179
+ icon: _cross.default,
180
+ onClick: function onClick() {
181
+ if (!api) {
182
+ return;
183
+ }
184
+ api.core.actions.execute(function (_ref3) {
185
+ var _api$contextPanel;
186
+ var tr = _ref3.tr;
187
+ (0, _commands.toggleInsertMenuRightRail)(tr);
188
+ (_api$contextPanel = api.contextPanel) === null || _api$contextPanel === void 0 || _api$contextPanel.actions.applyChange(tr);
189
+ return tr;
190
+ });
191
+ }
192
+ })), /*#__PURE__*/_react.default.createElement(_InsertMenu.default, {
193
+ editorView: editorView,
194
+ dropdownItems: dropdownItems,
195
+ onInsert: onInsert,
196
+ toggleVisiblity: function toggleVisiblity() {},
197
+ showElementBrowserLink: true,
198
+ pluginInjectionApi: api
199
+ }));
16
200
  };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useInsertMenuRailItems = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _reactIntlNext = require("react-intl-next");
11
+ var _hooks = require("@atlaskit/editor-common/hooks");
12
+ var _createItems = require("../ToolbarInsertBlock/create-items");
13
+ var useInsertMenuRailItems = exports.useInsertMenuRailItems = function useInsertMenuRailItems(editorView, options, api) {
14
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
15
+ formatMessage = _useIntl.formatMessage;
16
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['hyperlink', 'date', 'imageUpload', 'mention', 'emoji', 'blockType', 'media', 'typeAhead', 'placeholderText']),
17
+ dateState = _useSharedPluginState.dateState,
18
+ hyperlinkState = _useSharedPluginState.hyperlinkState,
19
+ imageUploadState = _useSharedPluginState.imageUploadState,
20
+ mentionState = _useSharedPluginState.mentionState,
21
+ emojiState = _useSharedPluginState.emojiState,
22
+ blockTypeState = _useSharedPluginState.blockTypeState,
23
+ mediaState = _useSharedPluginState.mediaState,
24
+ typeAheadState = _useSharedPluginState.typeAheadState,
25
+ placeholderTextState = _useSharedPluginState.placeholderTextState;
26
+ var _useMemo = (0, _react.useMemo)(function () {
27
+ var _ref;
28
+ return (0, _createItems.createItems)({
29
+ isTypeAheadAllowed: Boolean(typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isAllowed),
30
+ tableSupported: !!editorView.state.schema.nodes.table,
31
+ tableSelectorSupported: options.tableSelectorSupported && !!editorView.state.schema.nodes.table,
32
+ mediaUploadsEnabled: (_ref = mediaState && mediaState.allowsUploads) !== null && _ref !== void 0 ? _ref : undefined,
33
+ mediaSupported: !!mediaState,
34
+ imageUploadSupported: !!(api !== null && api !== void 0 && api.imageUpload),
35
+ imageUploadEnabled: imageUploadState === null || imageUploadState === void 0 ? void 0 : imageUploadState.enabled,
36
+ mentionsSupported: !!(mentionState && mentionState.mentionProvider),
37
+ mentionsDisabled: !!(mentionState && !mentionState.canInsertMention),
38
+ actionSupported: !!editorView.state.schema.nodes.taskItem,
39
+ decisionSupported: !!editorView.state.schema.nodes.decisionItem,
40
+ linkSupported: !!hyperlinkState,
41
+ linkDisabled: !hyperlinkState || !hyperlinkState.canInsertLink || !!hyperlinkState.activeLinkMark,
42
+ emojiDisabled: !emojiState || !emojiState.emojiProvider,
43
+ nativeStatusSupported: options.nativeStatusSupported,
44
+ dateEnabled: !!dateState,
45
+ placeholderTextEnabled: placeholderTextState && placeholderTextState.allowInserting,
46
+ horizontalRuleEnabled: options.horizontalRuleEnabled,
47
+ layoutSectionEnabled: Boolean(api === null || api === void 0 ? void 0 : api.layout),
48
+ expandEnabled: !!options.allowExpand,
49
+ showElementBrowserLink: options.showElementBrowserLink,
50
+ emojiProvider: emojiState === null || emojiState === void 0 ? void 0 : emojiState.emojiProvider,
51
+ availableWrapperBlockTypes: blockTypeState && blockTypeState.availableWrapperBlockTypes,
52
+ insertMenuItems: options.insertMenuItems,
53
+ schema: editorView.state.schema,
54
+ numberOfButtons: 10,
55
+ formatMessage: formatMessage,
56
+ isNewMenuEnabled: true
57
+ });
58
+ }, [api === null || api === void 0 ? void 0 : api.imageUpload, api === null || api === void 0 ? void 0 : api.layout, blockTypeState, dateState, editorView.state.schema, emojiState, formatMessage, hyperlinkState, imageUploadState === null || imageUploadState === void 0 ? void 0 : imageUploadState.enabled, mediaState, mentionState, options.allowExpand, options.horizontalRuleEnabled, options.insertMenuItems, options.nativeStatusSupported, options.showElementBrowserLink, options.tableSelectorSupported, placeholderTextState, typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isAllowed]),
59
+ _useMemo2 = (0, _slicedToArray2.default)(_useMemo, 2),
60
+ _ = _useMemo2[0],
61
+ dropdownItems = _useMemo2[1];
62
+ return dropdownItems;
63
+ };