@atlaskit/editor-plugin-insert-block 2.2.12 → 2.3.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.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/plugin.js +66 -77
- package/dist/cjs/pm-plugins/toggleInsertBlock.js +30 -0
- package/dist/cjs/ui/ElementRail/MainToolBarIcon.js +0 -2
- package/dist/cjs/ui/ToolbarInsertBlock/index.js +13 -14
- package/dist/es2019/plugin.js +47 -56
- package/dist/es2019/pm-plugins/toggleInsertBlock.js +22 -0
- package/dist/es2019/ui/ElementRail/MainToolBarIcon.js +0 -2
- package/dist/es2019/ui/ToolbarInsertBlock/index.js +8 -8
- package/dist/esm/plugin.js +65 -73
- package/dist/esm/pm-plugins/toggleInsertBlock.js +24 -0
- package/dist/esm/ui/ElementRail/MainToolBarIcon.js +0 -2
- package/dist/esm/ui/ToolbarInsertBlock/index.js +13 -14
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugin.d.ts +7 -0
- package/dist/types/pm-plugins/toggleInsertBlock.d.ts +8 -0
- package/dist/types/ui/ElementRail/index.d.ts +1 -0
- package/dist/types/ui/ToolbarInsertBlock/index.d.ts +3 -9
- package/dist/types/ui/ToolbarInsertBlock/types.d.ts +1 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/plugin.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/toggleInsertBlock.d.ts +8 -0
- package/dist/types-ts4.5/ui/ElementRail/index.d.ts +1 -0
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/index.d.ts +3 -9
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/types.d.ts +1 -0
- package/package.json +23 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-insert-block
|
|
2
2
|
|
|
3
|
+
## 2.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 2.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`e961ab7307a56`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e961ab7307a56) -
|
|
14
|
+
Refactored toggle insert block logic
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 2.2.12
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.insertBlockPlugin = void 0;
|
|
9
|
-
var _react =
|
|
7
|
+
exports.toolbarSizeToButtons = exports.insertBlockPlugin = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
10
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
12
11
|
var _insert = require("@atlaskit/editor-common/insert");
|
|
@@ -20,13 +19,12 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
|
20
19
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
21
20
|
var _switch = _interopRequireDefault(require("./assets/switch"));
|
|
22
21
|
var _elementBrowser = require("./pm-plugins/elementBrowser");
|
|
22
|
+
var _toggleInsertBlock = require("./pm-plugins/toggleInsertBlock");
|
|
23
23
|
var _ElementRail = require("./ui/ElementRail");
|
|
24
24
|
var _templateOptions = require("./ui/templateOptions");
|
|
25
25
|
var _ToolbarInsertBlock = _interopRequireDefault(require("./ui/ToolbarInsertBlock"));
|
|
26
26
|
var _transformOptions = require("./ui/transformOptions");
|
|
27
|
-
|
|
28
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
29
|
-
var toolbarSizeToButtons = function toolbarSizeToButtons(toolbarSize, appearance) {
|
|
27
|
+
var toolbarSizeToButtons = exports.toolbarSizeToButtons = function toolbarSizeToButtons(toolbarSize, appearance) {
|
|
30
28
|
// Different button numbers for full-page to better match full page toolbar breakpoints
|
|
31
29
|
if (appearance === 'full-page' && (0, _platformFeatureFlags.fg)('platform_editor_toolbar_responsive_fixes')) {
|
|
32
30
|
switch (toolbarSize) {
|
|
@@ -92,18 +90,9 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
|
|
|
92
90
|
var _ref$config = _ref.config,
|
|
93
91
|
options = _ref$config === void 0 ? {} : _ref$config,
|
|
94
92
|
api = _ref.api;
|
|
95
|
-
var toggleDropdownMenuOptionsRef = {
|
|
96
|
-
current: null
|
|
97
|
-
};
|
|
98
93
|
var editorViewRef = {
|
|
99
94
|
current: null
|
|
100
95
|
};
|
|
101
|
-
var registerToggleDropdownMenuOptions = function registerToggleDropdownMenuOptions(cb) {
|
|
102
|
-
toggleDropdownMenuOptionsRef.current = cb;
|
|
103
|
-
return function () {
|
|
104
|
-
toggleDropdownMenuOptionsRef.current = null;
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
96
|
var primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
|
|
108
97
|
var editorView = _ref2.editorView,
|
|
109
98
|
editorActions = _ref2.editorActions,
|
|
@@ -132,7 +121,6 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
|
|
|
132
121
|
isLastItem: isLastItem,
|
|
133
122
|
providers: providers,
|
|
134
123
|
options: options,
|
|
135
|
-
registerToggleDropdownMenuOptions: registerToggleDropdownMenuOptions,
|
|
136
124
|
appearance: options.appearance
|
|
137
125
|
});
|
|
138
126
|
};
|
|
@@ -150,54 +138,62 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
|
|
|
150
138
|
name: 'insertBlock',
|
|
151
139
|
actions: {
|
|
152
140
|
toggleAdditionalMenu: function toggleAdditionalMenu() {
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
141
|
+
var _api$core;
|
|
142
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
|
|
143
|
+
var tr = _ref3.tr;
|
|
144
|
+
return tr.setMeta(_toggleInsertBlock.toggleInsertBlockPmKey, true);
|
|
145
|
+
});
|
|
158
146
|
}
|
|
159
147
|
},
|
|
160
|
-
/**
|
|
161
|
-
* For insert menu in right rail experiment - I don't want to expose state as it might not ship
|
|
162
|
-
* - Clean up ticket ED-24801
|
|
163
|
-
*/
|
|
164
|
-
// @ts-expect-error
|
|
165
148
|
getSharedState: function getSharedState(editorState) {
|
|
166
149
|
var _options$appearance;
|
|
167
|
-
if (!editorState ||
|
|
168
|
-
// @ts-ignore
|
|
169
|
-
!['full-page', 'full-width'].includes((_options$appearance = options.appearance) !== null && _options$appearance !== void 0 ? _options$appearance : '') || !(0, _experiments.editorExperiment)('insert-menu-in-right-rail', true)) {
|
|
150
|
+
if (!editorState || !['full-page', 'full-width'].includes((_options$appearance = options.appearance) !== null && _options$appearance !== void 0 ? _options$appearance : '')) {
|
|
170
151
|
return;
|
|
171
152
|
}
|
|
172
|
-
var
|
|
153
|
+
var toggleInsertBlockPluginState = _toggleInsertBlock.toggleInsertBlockPmKey.getState(editorState);
|
|
154
|
+
var elementBrowserPluginState = _elementBrowser.elementBrowserPmKey.getState(editorState);
|
|
173
155
|
return {
|
|
174
|
-
|
|
156
|
+
showElementBrowser: (toggleInsertBlockPluginState === null || toggleInsertBlockPluginState === void 0 ? void 0 : toggleInsertBlockPluginState.showElementBrowser) || false,
|
|
157
|
+
/**
|
|
158
|
+
* For insert menu in right rail experiment
|
|
159
|
+
* - Clean up ticket ED-24801
|
|
160
|
+
* Experiment: `insert-menu-in-right-rail`
|
|
161
|
+
*/
|
|
162
|
+
menuBrowserOpen: (0, _experiments.editorExperiment)('insert-menu-in-right-rail', true) ? elementBrowserPluginState === null || elementBrowserPluginState === void 0 ? void 0 : elementBrowserPluginState.menuBrowserOpen : false
|
|
175
163
|
};
|
|
176
164
|
},
|
|
177
165
|
pmPlugins: function pmPlugins() {
|
|
178
166
|
var _options$appearance2;
|
|
179
|
-
if (
|
|
180
|
-
// @ts-ignore
|
|
181
|
-
!['full-page', 'full-width'].includes((_options$appearance2 = options.appearance) !== null && _options$appearance2 !== void 0 ? _options$appearance2 : '') || !(0, _experiments.editorExperiment)('insert-menu-in-right-rail', true)) {
|
|
167
|
+
if (!['full-page', 'full-width'].includes((_options$appearance2 = options.appearance) !== null && _options$appearance2 !== void 0 ? _options$appearance2 : '')) {
|
|
182
168
|
[];
|
|
183
169
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
170
|
+
var plugins = [];
|
|
171
|
+
if ((0, _experiments.editorExperiment)('insert-menu-in-right-rail', true)) {
|
|
172
|
+
plugins.push({
|
|
173
|
+
name: 'elementBrowserPmPlugin',
|
|
174
|
+
plugin: function plugin() {
|
|
175
|
+
return (0, _elementBrowser.elementBrowserPmPlugin)();
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
name: 'elementBrowserEditorViewRef',
|
|
179
|
+
plugin: function plugin() {
|
|
180
|
+
return new _safePlugin.SafePlugin({
|
|
181
|
+
view: function view(editorView) {
|
|
182
|
+
// Workaround - need reference to editorView for contextPanel component
|
|
183
|
+
editorViewRef.current = editorView;
|
|
184
|
+
return {};
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
plugins.push({
|
|
191
|
+
name: 'toggleInsertBlockPmPlugin',
|
|
191
192
|
plugin: function plugin() {
|
|
192
|
-
return
|
|
193
|
-
view: function view(editorView) {
|
|
194
|
-
// Workaround - need reference to editorView for contextPanel component
|
|
195
|
-
editorViewRef.current = editorView;
|
|
196
|
-
return {};
|
|
197
|
-
}
|
|
198
|
-
});
|
|
193
|
+
return (0, _toggleInsertBlock.toggleInsertBlockPmPlugin)();
|
|
199
194
|
}
|
|
200
|
-
}
|
|
195
|
+
});
|
|
196
|
+
return plugins;
|
|
201
197
|
},
|
|
202
198
|
pluginsOptions: {
|
|
203
199
|
// This is added for basic text transformations experiment.
|
|
@@ -275,13 +271,6 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
|
|
|
275
271
|
return [];
|
|
276
272
|
}
|
|
277
273
|
},
|
|
278
|
-
usePluginHook: function usePluginHook() {
|
|
279
|
-
(0, _react.useLayoutEffect)(function () {
|
|
280
|
-
return function () {
|
|
281
|
-
toggleDropdownMenuOptionsRef.current = null;
|
|
282
|
-
};
|
|
283
|
-
}, []);
|
|
284
|
-
},
|
|
285
274
|
primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
|
|
286
275
|
};
|
|
287
276
|
if (
|
|
@@ -303,25 +292,24 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
|
|
|
303
292
|
}
|
|
304
293
|
return plugin;
|
|
305
294
|
};
|
|
306
|
-
function ToolbarInsertBlockWithInjectionApi(
|
|
307
|
-
var
|
|
308
|
-
var editorView =
|
|
309
|
-
editorActions =
|
|
310
|
-
dispatchAnalyticsEvent =
|
|
311
|
-
popupsMountPoint =
|
|
312
|
-
popupsBoundariesElement =
|
|
313
|
-
popupsScrollableElement =
|
|
314
|
-
toolbarSize =
|
|
315
|
-
disabled =
|
|
316
|
-
isToolbarReducedSpacing =
|
|
317
|
-
isLastItem =
|
|
318
|
-
providers =
|
|
319
|
-
pluginInjectionApi =
|
|
320
|
-
options =
|
|
321
|
-
|
|
322
|
-
appearance = _ref3.appearance;
|
|
295
|
+
function ToolbarInsertBlockWithInjectionApi(_ref4) {
|
|
296
|
+
var _ref5, _pluginInjectionApi$i, _pluginInjectionApi$c2, _pluginInjectionApi$p, _pluginInjectionApi$b, _pluginInjectionApi$e;
|
|
297
|
+
var editorView = _ref4.editorView,
|
|
298
|
+
editorActions = _ref4.editorActions,
|
|
299
|
+
dispatchAnalyticsEvent = _ref4.dispatchAnalyticsEvent,
|
|
300
|
+
popupsMountPoint = _ref4.popupsMountPoint,
|
|
301
|
+
popupsBoundariesElement = _ref4.popupsBoundariesElement,
|
|
302
|
+
popupsScrollableElement = _ref4.popupsScrollableElement,
|
|
303
|
+
toolbarSize = _ref4.toolbarSize,
|
|
304
|
+
disabled = _ref4.disabled,
|
|
305
|
+
isToolbarReducedSpacing = _ref4.isToolbarReducedSpacing,
|
|
306
|
+
isLastItem = _ref4.isLastItem,
|
|
307
|
+
providers = _ref4.providers,
|
|
308
|
+
pluginInjectionApi = _ref4.pluginInjectionApi,
|
|
309
|
+
options = _ref4.options,
|
|
310
|
+
appearance = _ref4.appearance;
|
|
323
311
|
var buttons = toolbarSizeToButtons(toolbarSize, appearance);
|
|
324
|
-
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention', 'emoji', 'blockType', 'media', 'typeAhead', 'placeholderText']),
|
|
312
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention', 'emoji', 'blockType', 'media', 'typeAhead', 'placeholderText', 'insertBlock']),
|
|
325
313
|
dateState = _useSharedPluginState.dateState,
|
|
326
314
|
hyperlinkState = _useSharedPluginState.hyperlinkState,
|
|
327
315
|
imageUploadState = _useSharedPluginState.imageUploadState,
|
|
@@ -330,7 +318,8 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
|
|
|
330
318
|
blockTypeState = _useSharedPluginState.blockTypeState,
|
|
331
319
|
mediaState = _useSharedPluginState.mediaState,
|
|
332
320
|
typeAheadState = _useSharedPluginState.typeAheadState,
|
|
333
|
-
placeholderTextState = _useSharedPluginState.placeholderTextState
|
|
321
|
+
placeholderTextState = _useSharedPluginState.placeholderTextState,
|
|
322
|
+
insertBlockState = _useSharedPluginState.insertBlockState;
|
|
334
323
|
var getEmojiProvider = function getEmojiProvider() {
|
|
335
324
|
if (emojiState !== null && emojiState !== void 0 && emojiState.emojiProvider) {
|
|
336
325
|
return Promise.resolve(emojiState === null || emojiState === void 0 ? void 0 : emojiState.emojiProvider);
|
|
@@ -349,6 +338,7 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
|
|
|
349
338
|
}
|
|
350
339
|
};
|
|
351
340
|
return /*#__PURE__*/_react.default.createElement(_ToolbarInsertBlock.default, {
|
|
341
|
+
showElementBrowser: (insertBlockState === null || insertBlockState === void 0 ? void 0 : insertBlockState.showElementBrowser) || false,
|
|
352
342
|
pluginInjectionApi: pluginInjectionApi,
|
|
353
343
|
buttons: buttons,
|
|
354
344
|
isReducedSpacing: isToolbarReducedSpacing,
|
|
@@ -365,7 +355,7 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
|
|
|
365
355
|
placeholderTextEnabled: placeholderTextState && placeholderTextState.allowInserting,
|
|
366
356
|
layoutSectionEnabled: Boolean(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.layout),
|
|
367
357
|
expandEnabled: !!options.allowExpand,
|
|
368
|
-
mediaUploadsEnabled: (
|
|
358
|
+
mediaUploadsEnabled: (_ref5 = mediaState && mediaState.allowsUploads) !== null && _ref5 !== void 0 ? _ref5 : undefined,
|
|
369
359
|
onShowMediaPicker: onShowMediaPicker,
|
|
370
360
|
mediaSupported: !!mediaState,
|
|
371
361
|
imageUploadSupported: !!(pluginInjectionApi !== null && pluginInjectionApi !== void 0 && pluginInjectionApi.imageUpload),
|
|
@@ -388,7 +378,6 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
|
|
|
388
378
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
389
379
|
showElementBrowserLink: options.showElementBrowserLink,
|
|
390
380
|
showSeparator: !isLastItem && toolbarSize <= _types.ToolbarSize.S,
|
|
391
|
-
registerToggleDropdownMenuOptions: registerToggleDropdownMenuOptions,
|
|
392
381
|
editorAppearance: options.appearance
|
|
393
382
|
});
|
|
394
383
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toggleInsertBlockPmPlugin = exports.toggleInsertBlockPmKey = void 0;
|
|
7
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
+
var toggleInsertBlockPmKey = exports.toggleInsertBlockPmKey = new _state.PluginKey('toggleInsertBlockPmKey');
|
|
10
|
+
var toggleInsertBlockPmPlugin = exports.toggleInsertBlockPmPlugin = function toggleInsertBlockPmPlugin() {
|
|
11
|
+
return new _safePlugin.SafePlugin({
|
|
12
|
+
key: toggleInsertBlockPmKey,
|
|
13
|
+
state: {
|
|
14
|
+
init: function init() {
|
|
15
|
+
return {
|
|
16
|
+
showElementBrowser: false
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
apply: function apply(tr, pluginState) {
|
|
20
|
+
var meta = tr.getMeta(toggleInsertBlockPmKey);
|
|
21
|
+
if (!meta) {
|
|
22
|
+
return pluginState;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
showElementBrowser: !pluginState.showElementBrowser
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
};
|
|
@@ -71,8 +71,6 @@ var RightRailIcon = exports.RightRailIcon = function RightRailIcon(_ref) {
|
|
|
71
71
|
formatMessage = _useIntl.formatMessage;
|
|
72
72
|
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['insertBlock']),
|
|
73
73
|
insertBlockState = _useSharedPluginState.insertBlockState;
|
|
74
|
-
|
|
75
|
-
// @ts-expect-error
|
|
76
74
|
var isOpen = insertBlockState === null || insertBlockState === void 0 ? void 0 : insertBlockState.menuBrowserOpen;
|
|
77
75
|
return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
|
|
78
76
|
xcss: [wrapperStyles]
|
|
@@ -68,6 +68,7 @@ var tableButtonWrapper = exports.tableButtonWrapper = function tableButtonWrappe
|
|
|
68
68
|
(0, _react2.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n\t\tdisplay: flex;\n\t\t", "\n\t\t", "\n\n .table-toolbar-btn {\n\t\t\tborder-top-right-radius: ", ";\n\t\t\tborder-bottom-right-radius: ", ";\n\t\t\tmargin-right: ", ";\n\t\t\tpadding: ", ";\n\t\t\t& > span {\n\t\t\t\tmin-width: 16px;\n\t\t\t\tmargin: ", ";\n\t\t\t}\n\t\t}\n\t\t.table-selector-toolbar-btn {\n\t\t\tpadding: ", ";\n\t\t\t& > span {\n\t\t\t\tmargin: ", ";\n\t\t\t\twidth: 16px !important;\n\t\t\t\tdisplay: flex;\n\t\t\t\tjustify-content: center;\n\t\t\t}\n\n\t\t\tborder-top-left-radius: ", " !important;\n\t\t\tborder-bottom-left-radius: ", " !important;\n\t\t}\n\t"])), !isTableSelectorOpen && !isButtonDisabled && getHoverStyles('.table-selector-toolbar-btn'), !isTableSelectorOpen && !isButtonDisabled && getHoverStyles('.table-toolbar-btn'), "var(--ds-border-radius-200, 0px)", "var(--ds-border-radius-200, 0px)", "var(--ds-space-025, 1px)", "var(--ds-space-0, 0px)", "var(--ds-space-0, 0px)", "var(--ds-space-0, 0px)", "var(--ds-space-0, 0px)", "var(--ds-border-radius-200, 0px)", "var(--ds-border-radius-200, 0px)")
|
|
69
69
|
);
|
|
70
70
|
};
|
|
71
|
+
|
|
71
72
|
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
72
73
|
var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
73
74
|
(0, _inherits2.default)(ToolbarInsertBlock, _React$PureComponent);
|
|
@@ -81,7 +82,6 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
|
|
|
81
82
|
_this = _super.call.apply(_super, [this].concat(_args));
|
|
82
83
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "tableButtonRef", /*#__PURE__*/_react.default.createRef());
|
|
83
84
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "tableSelectorButtonRef", /*#__PURE__*/_react.default.createRef());
|
|
84
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "unregisterToggleDropdownMenuOptions", null);
|
|
85
85
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
|
|
86
86
|
isPlusMenuOpen: false,
|
|
87
87
|
emojiPickerOpen: false,
|
|
@@ -214,13 +214,6 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
|
|
|
214
214
|
_this.toggleTableSelector(_analytics.INPUT_METHOD.TOOLBAR);
|
|
215
215
|
}
|
|
216
216
|
});
|
|
217
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "componentDidMount", function () {
|
|
218
|
-
_this.unregisterToggleDropdownMenuOptions = _this.props.registerToggleDropdownMenuOptions ? _this.props.registerToggleDropdownMenuOptions(_this.handleClick) : null;
|
|
219
|
-
});
|
|
220
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "componentWillUnmount", function () {
|
|
221
|
-
var _this$unregisterToggl, _this2;
|
|
222
|
-
(_this$unregisterToggl = (_this2 = _this).unregisterToggleDropdownMenuOptions) === null || _this$unregisterToggl === void 0 || _this$unregisterToggl.call(_this2);
|
|
223
|
-
});
|
|
224
217
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleClick", function () {
|
|
225
218
|
var _this$props$editorApp;
|
|
226
219
|
/**
|
|
@@ -572,11 +565,17 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
|
|
|
572
565
|
isTableSelectorOpenedByKeyboard: false
|
|
573
566
|
});
|
|
574
567
|
}
|
|
568
|
+
if (this.props.showElementBrowser !== prevProps.showElementBrowser) {
|
|
569
|
+
this.handleClick();
|
|
570
|
+
this.setState(_objectSpread(_objectSpread({}, this.state), {}, {
|
|
571
|
+
isPlusMenuOpen: this.props.showElementBrowser
|
|
572
|
+
}));
|
|
573
|
+
}
|
|
575
574
|
}
|
|
576
575
|
}, {
|
|
577
576
|
key: "renderPopup",
|
|
578
577
|
value: function renderPopup() {
|
|
579
|
-
var
|
|
578
|
+
var _this2 = this;
|
|
580
579
|
var emojiPickerOpen = this.state.emojiPickerOpen;
|
|
581
580
|
var _this$props11 = this.props,
|
|
582
581
|
popupsMountPoint = _this$props11.popupsMountPoint,
|
|
@@ -594,8 +593,8 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
|
|
|
594
593
|
}
|
|
595
594
|
var onUnmount = function onUnmount() {
|
|
596
595
|
requestAnimationFrame(function () {
|
|
597
|
-
var
|
|
598
|
-
return (
|
|
596
|
+
var _this2$props$pluginIn;
|
|
597
|
+
return (_this2$props$pluginIn = _this2.props.pluginInjectionApi) === null || _this2$props$pluginIn === void 0 || (_this2$props$pluginIn = _this2$props$pluginIn.core) === null || _this2$props$pluginIn === void 0 || (_this2$props$pluginIn = _this2$props$pluginIn.actions) === null || _this2$props$pluginIn === void 0 ? void 0 : _this2$props$pluginIn.focus();
|
|
599
598
|
});
|
|
600
599
|
};
|
|
601
600
|
return (0, _react2.jsx)(_ui.Popup, {
|
|
@@ -657,7 +656,7 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
|
|
|
657
656
|
}, {
|
|
658
657
|
key: "render",
|
|
659
658
|
value: function render() {
|
|
660
|
-
var
|
|
659
|
+
var _this3 = this,
|
|
661
660
|
_tableButton,
|
|
662
661
|
_tableButton2,
|
|
663
662
|
_tableButton3,
|
|
@@ -726,7 +725,7 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
|
|
|
726
725
|
return (0, _react2.jsx)(_uiMenu.ToolbarButton, {
|
|
727
726
|
item: btn,
|
|
728
727
|
testId: String(btn.content),
|
|
729
|
-
ref:
|
|
728
|
+
ref: _this3.handleToolbarRef(btn.value.name),
|
|
730
729
|
key: btn.value.name,
|
|
731
730
|
spacing: isReducedSpacing ? 'none' : 'default',
|
|
732
731
|
disabled: isDisabled || btn.isDisabled,
|
|
@@ -736,7 +735,7 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
|
|
|
736
735
|
"aria-label": btn['aria-label'],
|
|
737
736
|
"aria-haspopup": btn['aria-haspopup'],
|
|
738
737
|
"aria-keyshortcuts": btn['aria-keyshortcuts'],
|
|
739
|
-
onItemClick:
|
|
738
|
+
onItemClick: _this3.insertToolbarMenuItem
|
|
740
739
|
});
|
|
741
740
|
}), this.props.tableSelectorSupported && (isTableButtonVisible || isTableSizeVisible) && (0, _react2.jsx)("div", {
|
|
742
741
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { contentAllowedInCodeBlock, shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
|
|
@@ -12,11 +12,12 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
12
12
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
13
13
|
import SwitchIcon from './assets/switch';
|
|
14
14
|
import { elementBrowserPmKey, elementBrowserPmPlugin } from './pm-plugins/elementBrowser';
|
|
15
|
+
import { toggleInsertBlockPmKey, toggleInsertBlockPmPlugin } from './pm-plugins/toggleInsertBlock';
|
|
15
16
|
import { InsertMenuRail } from './ui/ElementRail';
|
|
16
17
|
import { templateOptions } from './ui/templateOptions';
|
|
17
18
|
import ToolbarInsertBlock from './ui/ToolbarInsertBlock';
|
|
18
19
|
import { transformationOptions } from './ui/transformOptions';
|
|
19
|
-
const toolbarSizeToButtons = (toolbarSize, appearance) => {
|
|
20
|
+
export const toolbarSizeToButtons = (toolbarSize, appearance) => {
|
|
20
21
|
// Different button numbers for full-page to better match full page toolbar breakpoints
|
|
21
22
|
if (appearance === 'full-page' && fg('platform_editor_toolbar_responsive_fixes')) {
|
|
22
23
|
switch (toolbarSize) {
|
|
@@ -80,18 +81,9 @@ export const insertBlockPlugin = ({
|
|
|
80
81
|
api
|
|
81
82
|
}) => {
|
|
82
83
|
var _api$primaryToolbar, _options$appearance4;
|
|
83
|
-
const toggleDropdownMenuOptionsRef = {
|
|
84
|
-
current: null
|
|
85
|
-
};
|
|
86
84
|
const editorViewRef = {
|
|
87
85
|
current: null
|
|
88
86
|
};
|
|
89
|
-
const registerToggleDropdownMenuOptions = cb => {
|
|
90
|
-
toggleDropdownMenuOptionsRef.current = cb;
|
|
91
|
-
return () => {
|
|
92
|
-
toggleDropdownMenuOptionsRef.current = null;
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
87
|
const primaryToolbarComponent = ({
|
|
96
88
|
editorView,
|
|
97
89
|
editorActions,
|
|
@@ -121,7 +113,6 @@ export const insertBlockPlugin = ({
|
|
|
121
113
|
isLastItem: isLastItem,
|
|
122
114
|
providers: providers,
|
|
123
115
|
options: options,
|
|
124
|
-
registerToggleDropdownMenuOptions: registerToggleDropdownMenuOptions,
|
|
125
116
|
appearance: options.appearance
|
|
126
117
|
});
|
|
127
118
|
};
|
|
@@ -139,52 +130,59 @@ export const insertBlockPlugin = ({
|
|
|
139
130
|
name: 'insertBlock',
|
|
140
131
|
actions: {
|
|
141
132
|
toggleAdditionalMenu: () => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
133
|
+
var _api$core;
|
|
134
|
+
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
|
|
135
|
+
tr
|
|
136
|
+
}) => {
|
|
137
|
+
return tr.setMeta(toggleInsertBlockPmKey, true);
|
|
138
|
+
});
|
|
147
139
|
}
|
|
148
140
|
},
|
|
149
|
-
/**
|
|
150
|
-
* For insert menu in right rail experiment - I don't want to expose state as it might not ship
|
|
151
|
-
* - Clean up ticket ED-24801
|
|
152
|
-
*/
|
|
153
|
-
// @ts-expect-error
|
|
154
141
|
getSharedState: editorState => {
|
|
155
142
|
var _options$appearance;
|
|
156
|
-
if (!editorState ||
|
|
157
|
-
// @ts-ignore
|
|
158
|
-
!['full-page', 'full-width'].includes((_options$appearance = options.appearance) !== null && _options$appearance !== void 0 ? _options$appearance : '') || !editorExperiment('insert-menu-in-right-rail', true)) {
|
|
143
|
+
if (!editorState || !['full-page', 'full-width'].includes((_options$appearance = options.appearance) !== null && _options$appearance !== void 0 ? _options$appearance : '')) {
|
|
159
144
|
return;
|
|
160
145
|
}
|
|
161
|
-
const
|
|
146
|
+
const toggleInsertBlockPluginState = toggleInsertBlockPmKey.getState(editorState);
|
|
147
|
+
const elementBrowserPluginState = elementBrowserPmKey.getState(editorState);
|
|
162
148
|
return {
|
|
163
|
-
|
|
149
|
+
showElementBrowser: (toggleInsertBlockPluginState === null || toggleInsertBlockPluginState === void 0 ? void 0 : toggleInsertBlockPluginState.showElementBrowser) || false,
|
|
150
|
+
/**
|
|
151
|
+
* For insert menu in right rail experiment
|
|
152
|
+
* - Clean up ticket ED-24801
|
|
153
|
+
* Experiment: `insert-menu-in-right-rail`
|
|
154
|
+
*/
|
|
155
|
+
menuBrowserOpen: editorExperiment('insert-menu-in-right-rail', true) ? elementBrowserPluginState === null || elementBrowserPluginState === void 0 ? void 0 : elementBrowserPluginState.menuBrowserOpen : false
|
|
164
156
|
};
|
|
165
157
|
},
|
|
166
158
|
pmPlugins: () => {
|
|
167
159
|
var _options$appearance2;
|
|
168
|
-
if (
|
|
169
|
-
// @ts-ignore
|
|
170
|
-
!['full-page', 'full-width'].includes((_options$appearance2 = options.appearance) !== null && _options$appearance2 !== void 0 ? _options$appearance2 : '') || !editorExperiment('insert-menu-in-right-rail', true)) {
|
|
160
|
+
if (!['full-page', 'full-width'].includes((_options$appearance2 = options.appearance) !== null && _options$appearance2 !== void 0 ? _options$appearance2 : '')) {
|
|
171
161
|
[];
|
|
172
162
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
163
|
+
const plugins = [];
|
|
164
|
+
if (editorExperiment('insert-menu-in-right-rail', true)) {
|
|
165
|
+
plugins.push({
|
|
166
|
+
name: 'elementBrowserPmPlugin',
|
|
167
|
+
plugin: () => elementBrowserPmPlugin()
|
|
168
|
+
}, {
|
|
169
|
+
name: 'elementBrowserEditorViewRef',
|
|
170
|
+
plugin: () => {
|
|
171
|
+
return new SafePlugin({
|
|
172
|
+
view: editorView => {
|
|
173
|
+
// Workaround - need reference to editorView for contextPanel component
|
|
174
|
+
editorViewRef.current = editorView;
|
|
175
|
+
return {};
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
plugins.push({
|
|
182
|
+
name: 'toggleInsertBlockPmPlugin',
|
|
183
|
+
plugin: () => toggleInsertBlockPmPlugin()
|
|
184
|
+
});
|
|
185
|
+
return plugins;
|
|
188
186
|
},
|
|
189
187
|
pluginsOptions: {
|
|
190
188
|
// This is added for basic text transformations experiment.
|
|
@@ -268,13 +266,6 @@ export const insertBlockPlugin = ({
|
|
|
268
266
|
return [];
|
|
269
267
|
}
|
|
270
268
|
},
|
|
271
|
-
usePluginHook: () => {
|
|
272
|
-
useLayoutEffect(() => {
|
|
273
|
-
return () => {
|
|
274
|
-
toggleDropdownMenuOptionsRef.current = null;
|
|
275
|
-
};
|
|
276
|
-
}, []);
|
|
277
|
-
},
|
|
278
269
|
primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
|
|
279
270
|
};
|
|
280
271
|
if (
|
|
@@ -310,7 +301,6 @@ function ToolbarInsertBlockWithInjectionApi({
|
|
|
310
301
|
providers,
|
|
311
302
|
pluginInjectionApi,
|
|
312
303
|
options,
|
|
313
|
-
registerToggleDropdownMenuOptions,
|
|
314
304
|
appearance
|
|
315
305
|
}) {
|
|
316
306
|
var _ref, _pluginInjectionApi$i, _pluginInjectionApi$c2, _pluginInjectionApi$p, _pluginInjectionApi$b, _pluginInjectionApi$e;
|
|
@@ -324,8 +314,9 @@ function ToolbarInsertBlockWithInjectionApi({
|
|
|
324
314
|
blockTypeState,
|
|
325
315
|
mediaState,
|
|
326
316
|
typeAheadState,
|
|
327
|
-
placeholderTextState
|
|
328
|
-
|
|
317
|
+
placeholderTextState,
|
|
318
|
+
insertBlockState
|
|
319
|
+
} = useSharedPluginState(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention', 'emoji', 'blockType', 'media', 'typeAhead', 'placeholderText', 'insertBlock']);
|
|
329
320
|
const getEmojiProvider = () => {
|
|
330
321
|
if (emojiState !== null && emojiState !== void 0 && emojiState.emojiProvider) {
|
|
331
322
|
return Promise.resolve(emojiState === null || emojiState === void 0 ? void 0 : emojiState.emojiProvider);
|
|
@@ -344,6 +335,7 @@ function ToolbarInsertBlockWithInjectionApi({
|
|
|
344
335
|
}
|
|
345
336
|
};
|
|
346
337
|
return /*#__PURE__*/React.createElement(ToolbarInsertBlock, {
|
|
338
|
+
showElementBrowser: (insertBlockState === null || insertBlockState === void 0 ? void 0 : insertBlockState.showElementBrowser) || false,
|
|
347
339
|
pluginInjectionApi: pluginInjectionApi,
|
|
348
340
|
buttons: buttons,
|
|
349
341
|
isReducedSpacing: isToolbarReducedSpacing,
|
|
@@ -383,7 +375,6 @@ function ToolbarInsertBlockWithInjectionApi({
|
|
|
383
375
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
384
376
|
showElementBrowserLink: options.showElementBrowserLink,
|
|
385
377
|
showSeparator: !isLastItem && toolbarSize <= ToolbarSize.S,
|
|
386
|
-
registerToggleDropdownMenuOptions: registerToggleDropdownMenuOptions,
|
|
387
378
|
editorAppearance: options.appearance
|
|
388
379
|
});
|
|
389
380
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
export const toggleInsertBlockPmKey = new PluginKey('toggleInsertBlockPmKey');
|
|
4
|
+
export const toggleInsertBlockPmPlugin = () => new SafePlugin({
|
|
5
|
+
key: toggleInsertBlockPmKey,
|
|
6
|
+
state: {
|
|
7
|
+
init() {
|
|
8
|
+
return {
|
|
9
|
+
showElementBrowser: false
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
apply(tr, pluginState) {
|
|
13
|
+
const meta = tr.getMeta(toggleInsertBlockPmKey);
|
|
14
|
+
if (!meta) {
|
|
15
|
+
return pluginState;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
showElementBrowser: !pluginState.showElementBrowser
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
@@ -67,8 +67,6 @@ export const RightRailIcon = ({
|
|
|
67
67
|
const {
|
|
68
68
|
insertBlockState
|
|
69
69
|
} = useSharedPluginState(api, ['insertBlock']);
|
|
70
|
-
|
|
71
|
-
// @ts-expect-error
|
|
72
70
|
const isOpen = insertBlockState === null || insertBlockState === void 0 ? void 0 : insertBlockState.menuBrowserOpen;
|
|
73
71
|
return /*#__PURE__*/React.createElement(Box, {
|
|
74
72
|
xcss: [wrapperStyles]
|
|
@@ -71,13 +71,13 @@ css`
|
|
|
71
71
|
border-bottom-left-radius: ${"var(--ds-border-radius-200, 0px)"} !important;
|
|
72
72
|
}
|
|
73
73
|
`;
|
|
74
|
+
|
|
74
75
|
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
75
76
|
export class ToolbarInsertBlock extends React.PureComponent {
|
|
76
77
|
constructor(..._args) {
|
|
77
78
|
super(..._args);
|
|
78
79
|
_defineProperty(this, "tableButtonRef", /*#__PURE__*/React.createRef());
|
|
79
80
|
_defineProperty(this, "tableSelectorButtonRef", /*#__PURE__*/React.createRef());
|
|
80
|
-
_defineProperty(this, "unregisterToggleDropdownMenuOptions", null);
|
|
81
81
|
_defineProperty(this, "state", {
|
|
82
82
|
isPlusMenuOpen: false,
|
|
83
83
|
emojiPickerOpen: false,
|
|
@@ -210,13 +210,6 @@ export class ToolbarInsertBlock extends React.PureComponent {
|
|
|
210
210
|
this.toggleTableSelector(INPUT_METHOD.TOOLBAR);
|
|
211
211
|
}
|
|
212
212
|
});
|
|
213
|
-
_defineProperty(this, "componentDidMount", () => {
|
|
214
|
-
this.unregisterToggleDropdownMenuOptions = this.props.registerToggleDropdownMenuOptions ? this.props.registerToggleDropdownMenuOptions(this.handleClick) : null;
|
|
215
|
-
});
|
|
216
|
-
_defineProperty(this, "componentWillUnmount", () => {
|
|
217
|
-
var _this$unregisterToggl;
|
|
218
|
-
(_this$unregisterToggl = this.unregisterToggleDropdownMenuOptions) === null || _this$unregisterToggl === void 0 ? void 0 : _this$unregisterToggl.call(this);
|
|
219
|
-
});
|
|
220
213
|
_defineProperty(this, "handleClick", () => {
|
|
221
214
|
var _this$props$editorApp;
|
|
222
215
|
/**
|
|
@@ -630,6 +623,13 @@ export class ToolbarInsertBlock extends React.PureComponent {
|
|
|
630
623
|
isTableSelectorOpenedByKeyboard: false
|
|
631
624
|
});
|
|
632
625
|
}
|
|
626
|
+
if (this.props.showElementBrowser !== prevProps.showElementBrowser) {
|
|
627
|
+
this.handleClick();
|
|
628
|
+
this.setState({
|
|
629
|
+
...this.state,
|
|
630
|
+
isPlusMenuOpen: this.props.showElementBrowser
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
633
|
}
|
|
634
634
|
renderPopup() {
|
|
635
635
|
const {
|