@atlaskit/editor-plugin-insert-block 2.4.23 → 2.4.24

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-insert-block
2
2
 
3
+ ## 2.4.24
4
+
5
+ ### Patch Changes
6
+
7
+ - [#179859](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/179859)
8
+ [`1a90382aae1c6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1a90382aae1c6) -
9
+ Optimise the insert menu dropdown by preloading it.
10
+
3
11
  ## 2.4.23
4
12
 
5
13
  ### Patch Changes
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.toolbarSizeToButtons = exports.insertBlockPlugin = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
+ var _react = _interopRequireWildcard(require("react"));
9
10
  var _analytics = require("@atlaskit/editor-common/analytics");
11
+ var _elementBrowser = require("@atlaskit/editor-common/element-browser");
10
12
  var _hooks = require("@atlaskit/editor-common/hooks");
11
13
  var _insert = require("@atlaskit/editor-common/insert");
12
14
  var _messages = require("@atlaskit/editor-common/messages");
@@ -18,12 +20,14 @@ var _consts = require("@atlaskit/editor-plugin-block-type/consts");
18
20
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
19
21
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
20
22
  var _switch = _interopRequireDefault(require("./assets/switch"));
21
- var _elementBrowser = require("./pm-plugins/elementBrowser");
23
+ var _elementBrowser2 = require("./pm-plugins/elementBrowser");
22
24
  var _toggleInsertBlock = require("./pm-plugins/toggleInsertBlock");
23
25
  var _ElementRail = require("./ui/ElementRail");
24
26
  var _templateOptions = require("./ui/templateOptions");
25
27
  var _ToolbarInsertBlock = _interopRequireDefault(require("./ui/ToolbarInsertBlock"));
26
28
  var _transformOptions = require("./ui/transformOptions");
29
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
30
+ 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; }
27
31
  var toolbarSizeToButtons = exports.toolbarSizeToButtons = function toolbarSizeToButtons(toolbarSize, appearance) {
28
32
  // Different button numbers for full-page to better match full page toolbar breakpoints
29
33
  if (appearance === 'full-page' && (0, _platformFeatureFlags.fg)('platform_editor_toolbar_responsive_fixes')) {
@@ -85,6 +89,23 @@ function handleInsertBlockType(insertCodeBlock, insertPanel, insertBlockQuote) {
85
89
  };
86
90
  };
87
91
  }
92
+ function delayUntilIdle(cb) {
93
+ if (typeof window === 'undefined') {
94
+ return;
95
+ }
96
+ // eslint-disable-next-line compat/compat
97
+ if (window.requestIdleCallback !== undefined) {
98
+ // eslint-disable-next-line compat/compat
99
+ return window.requestIdleCallback(function () {
100
+ return cb();
101
+ }, {
102
+ timeout: 500
103
+ });
104
+ }
105
+ return window.requestAnimationFrame(function () {
106
+ return cb();
107
+ });
108
+ }
88
109
  var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_ref) {
89
110
  var _api$primaryToolbar, _options$appearance4;
90
111
  var _ref$config = _ref.config,
@@ -151,7 +172,7 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
151
172
  return;
152
173
  }
153
174
  var toggleInsertBlockPluginState = _toggleInsertBlock.toggleInsertBlockPmKey.getState(editorState);
154
- var elementBrowserPluginState = _elementBrowser.elementBrowserPmKey.getState(editorState);
175
+ var elementBrowserPluginState = _elementBrowser2.elementBrowserPmKey.getState(editorState);
155
176
  return {
156
177
  showElementBrowser: (toggleInsertBlockPluginState === null || toggleInsertBlockPluginState === void 0 ? void 0 : toggleInsertBlockPluginState.showElementBrowser) || false,
157
178
  /**
@@ -162,6 +183,18 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
162
183
  menuBrowserOpen: (0, _experiments.editorExperiment)('insert-menu-in-right-rail', true) ? elementBrowserPluginState === null || elementBrowserPluginState === void 0 ? void 0 : elementBrowserPluginState.menuBrowserOpen : false
163
184
  };
164
185
  },
186
+ usePluginHook: function usePluginHook() {
187
+ (0, _react.useEffect)(function () {
188
+ // This is to optimise the UI so that when the user first clicks on the insert
189
+ // menu it opens instantly. As we're delaying the loading this won't affect the
190
+ // initial editor rendering metrics.
191
+ delayUntilIdle(function () {
192
+ if ((0, _platformFeatureFlags.fg)('platform_editor_preload_insert_menu')) {
193
+ _elementBrowser.ElementBrowser.preload();
194
+ }
195
+ });
196
+ }, []);
197
+ },
165
198
  pmPlugins: function pmPlugins() {
166
199
  var _options$appearance2;
167
200
  if (!['full-page', 'full-width'].includes((_options$appearance2 = options.appearance) !== null && _options$appearance2 !== void 0 ? _options$appearance2 : '')) {
@@ -172,7 +205,7 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
172
205
  plugins.push({
173
206
  name: 'elementBrowserPmPlugin',
174
207
  plugin: function plugin() {
175
- return (0, _elementBrowser.elementBrowserPmPlugin)();
208
+ return (0, _elementBrowser2.elementBrowserPmPlugin)();
176
209
  }
177
210
  }, {
178
211
  name: 'elementBrowserEditorViewRef',
@@ -279,7 +312,7 @@ var insertBlockPlugin = exports.insertBlockPlugin = function insertBlockPlugin(_
279
312
  plugin.pluginsOptions.contextPanel = function (state) {
280
313
  // api.getSharedState() will have an outdated reference to editorState on first mount of this component
281
314
  // so instead just rely on plugin key as we don't need to be reactive to changes here
282
- var pluginState = _elementBrowser.elementBrowserPmKey.getState(state);
315
+ var pluginState = _elementBrowser2.elementBrowserPmKey.getState(state);
283
316
  if (pluginState !== null && pluginState !== void 0 && pluginState.menuBrowserOpen && editorViewRef.current) {
284
317
  return /*#__PURE__*/_react.default.createElement(_ElementRail.InsertMenuRail, {
285
318
  editorView: editorViewRef.current,
@@ -1,5 +1,6 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import { ElementBrowser } from '@atlaskit/editor-common/element-browser';
3
4
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
5
  import { contentAllowedInCodeBlock, shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
5
6
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
@@ -76,6 +77,19 @@ function handleInsertBlockType(insertCodeBlock, insertPanel, insertBlockQuote) {
76
77
  return () => false;
77
78
  };
78
79
  }
80
+ function delayUntilIdle(cb) {
81
+ if (typeof window === 'undefined') {
82
+ return;
83
+ }
84
+ // eslint-disable-next-line compat/compat
85
+ if (window.requestIdleCallback !== undefined) {
86
+ // eslint-disable-next-line compat/compat
87
+ return window.requestIdleCallback(() => cb(), {
88
+ timeout: 500
89
+ });
90
+ }
91
+ return window.requestAnimationFrame(() => cb());
92
+ }
79
93
  export const insertBlockPlugin = ({
80
94
  config: options = {},
81
95
  api
@@ -155,6 +169,18 @@ export const insertBlockPlugin = ({
155
169
  menuBrowserOpen: editorExperiment('insert-menu-in-right-rail', true) ? elementBrowserPluginState === null || elementBrowserPluginState === void 0 ? void 0 : elementBrowserPluginState.menuBrowserOpen : false
156
170
  };
157
171
  },
172
+ usePluginHook() {
173
+ useEffect(() => {
174
+ // This is to optimise the UI so that when the user first clicks on the insert
175
+ // menu it opens instantly. As we're delaying the loading this won't affect the
176
+ // initial editor rendering metrics.
177
+ delayUntilIdle(() => {
178
+ if (fg('platform_editor_preload_insert_menu')) {
179
+ ElementBrowser.preload();
180
+ }
181
+ });
182
+ }, []);
183
+ },
158
184
  pmPlugins: () => {
159
185
  var _options$appearance2;
160
186
  if (!['full-page', 'full-width'].includes((_options$appearance2 = options.appearance) !== null && _options$appearance2 !== void 0 ? _options$appearance2 : '')) {
@@ -1,5 +1,6 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import { ElementBrowser } from '@atlaskit/editor-common/element-browser';
3
4
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
5
  import { contentAllowedInCodeBlock, shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
5
6
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
@@ -78,6 +79,23 @@ function handleInsertBlockType(insertCodeBlock, insertPanel, insertBlockQuote) {
78
79
  };
79
80
  };
80
81
  }
82
+ function delayUntilIdle(cb) {
83
+ if (typeof window === 'undefined') {
84
+ return;
85
+ }
86
+ // eslint-disable-next-line compat/compat
87
+ if (window.requestIdleCallback !== undefined) {
88
+ // eslint-disable-next-line compat/compat
89
+ return window.requestIdleCallback(function () {
90
+ return cb();
91
+ }, {
92
+ timeout: 500
93
+ });
94
+ }
95
+ return window.requestAnimationFrame(function () {
96
+ return cb();
97
+ });
98
+ }
81
99
  export var insertBlockPlugin = function insertBlockPlugin(_ref) {
82
100
  var _api$primaryToolbar, _options$appearance4;
83
101
  var _ref$config = _ref.config,
@@ -155,6 +173,18 @@ export var insertBlockPlugin = function insertBlockPlugin(_ref) {
155
173
  menuBrowserOpen: editorExperiment('insert-menu-in-right-rail', true) ? elementBrowserPluginState === null || elementBrowserPluginState === void 0 ? void 0 : elementBrowserPluginState.menuBrowserOpen : false
156
174
  };
157
175
  },
176
+ usePluginHook: function usePluginHook() {
177
+ useEffect(function () {
178
+ // This is to optimise the UI so that when the user first clicks on the insert
179
+ // menu it opens instantly. As we're delaying the loading this won't affect the
180
+ // initial editor rendering metrics.
181
+ delayUntilIdle(function () {
182
+ if (fg('platform_editor_preload_insert_menu')) {
183
+ ElementBrowser.preload();
184
+ }
185
+ });
186
+ }, []);
187
+ },
158
188
  pmPlugins: function pmPlugins() {
159
189
  var _options$appearance2;
160
190
  if (!['full-page', 'full-width'].includes((_options$appearance2 = options.appearance) !== null && _options$appearance2 !== void 0 ? _options$appearance2 : '')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-insert-block",
3
- "version": "2.4.23",
3
+ "version": "2.4.24",
4
4
  "description": "Insert block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,7 +36,7 @@
36
36
  "@atlaskit/editor-plugin-analytics": "^1.10.0",
37
37
  "@atlaskit/editor-plugin-block-type": "^4.0.0",
38
38
  "@atlaskit/editor-plugin-code-block": "^3.5.0",
39
- "@atlaskit/editor-plugin-connectivity": "^1.0.0",
39
+ "@atlaskit/editor-plugin-connectivity": "^1.1.0",
40
40
  "@atlaskit/editor-plugin-date": "^2.4.0",
41
41
  "@atlaskit/editor-plugin-emoji": "^2.7.0",
42
42
  "@atlaskit/editor-plugin-expand": "^2.10.0",
@@ -66,8 +66,8 @@
66
66
  "@atlaskit/platform-feature-flags": "^0.3.0",
67
67
  "@atlaskit/primitives": "^13.3.0",
68
68
  "@atlaskit/theme": "^14.0.0",
69
- "@atlaskit/tmp-editor-statsig": "^2.26.0",
70
- "@atlaskit/tokens": "^2.4.0",
69
+ "@atlaskit/tmp-editor-statsig": "^2.27.0",
70
+ "@atlaskit/tokens": "^2.5.0",
71
71
  "@atlaskit/tooltip": "19.0.0",
72
72
  "@babel/runtime": "^7.0.0",
73
73
  "@emotion/react": "^11.7.1",
@@ -130,6 +130,9 @@
130
130
  "platform_editor_consistent_insert_menu": {
131
131
  "type": "boolean"
132
132
  },
133
+ "platform_editor_preload_insert_menu": {
134
+ "type": "boolean"
135
+ },
133
136
  "platform_editor_reduce_element_browser_padding": {
134
137
  "type": "boolean"
135
138
  }