@atlaskit/editor-plugin-floating-toolbar 32.0.2 → 32.0.3

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,15 @@
1
1
  # @atlaskit/editor-plugin-floating-toolbar
2
2
 
3
+ ## 32.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`946472ca53135`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/946472ca53135) -
8
+ Behind platform_editor_improve_inp, memoize historical floating-toolbar shared-state reads inside
9
+ getSharedState. Keep current editor-state reads fresh, avoid adding public plugin APIs, and
10
+ release cached results when the editor view is destroyed.
11
+ - Updated dependencies
12
+
3
13
  ## 32.0.2
4
14
 
5
15
  ### Patch Changes
@@ -23,6 +23,7 @@ var _toolbarFlagCheck = require("@atlaskit/editor-common/toolbar-flag-check");
23
23
  var _useSharedPluginState2 = require("@atlaskit/editor-common/useSharedPluginState");
24
24
  var _state = require("@atlaskit/editor-prosemirror/state");
25
25
  var _utils = require("@atlaskit/editor-prosemirror/utils");
26
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
26
27
  var _fg = require("@atlaskit/platform-feature-flags/fg");
27
28
  var _useToolbarExternalStore = require("./hooks/useToolbarExternalStore");
28
29
  var _commands = require("./pm-plugins/commands");
@@ -143,6 +144,39 @@ function filterUndefined(x) {
143
144
  }
144
145
  var floatingToolbarPlugin = exports.floatingToolbarPlugin = function floatingToolbarPlugin(_ref) {
145
146
  var api = _ref.api;
147
+ var editorView;
148
+ var sharedStateCache;
149
+ var getSharedState = function getSharedState(editorState) {
150
+ var _api$interaction, _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
151
+ if (!editorState) {
152
+ return undefined;
153
+ }
154
+ var memoizePreviousState = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_improve_inp');
155
+ if (memoizePreviousState) {
156
+ // Current-state reads remain live: handlers can depend on mutable values
157
+ // outside EditorState. Only historical reads may reuse a computed result.
158
+ if (editorView && editorState !== editorView.state) {
159
+ var _sharedStateCache;
160
+ var cached = (_sharedStateCache = sharedStateCache) === null || _sharedStateCache === void 0 ? void 0 : _sharedStateCache.get(editorState);
161
+ if (cached) {
162
+ return cached;
163
+ }
164
+ }
165
+ } else {
166
+ sharedStateCache = undefined;
167
+ }
168
+ var interactionState = api === null || api === void 0 || (_api$interaction = api.interaction) === null || _api$interaction === void 0 || (_api$interaction = _api$interaction.sharedState.currentState()) === null || _api$interaction === void 0 ? void 0 : _api$interaction.interactionState;
169
+ var configWithNodeInfo = interactionState !== 'hasNotHadInteraction' ? (_pluginKey$getState$g = (_pluginKey$getState = pluginKey.getState(editorState)) === null || _pluginKey$getState === 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 : undefined;
170
+ var sharedState = {
171
+ configWithNodeInfo: configWithNodeInfo,
172
+ floatingToolbarData: _pluginKey.pluginKey.getState(editorState)
173
+ };
174
+ if (memoizePreviousState && editorView) {
175
+ sharedStateCache !== null && sharedStateCache !== void 0 ? sharedStateCache : sharedStateCache = new WeakMap();
176
+ sharedStateCache.set(editorState, sharedState);
177
+ }
178
+ return sharedState;
179
+ };
146
180
  return {
147
181
  name: 'floatingToolbar',
148
182
  pmPlugins: function pmPlugins() {
@@ -172,6 +206,25 @@ var floatingToolbarPlugin = exports.floatingToolbarPlugin = function floatingToo
172
206
  return (0, _forceFocus.default)();
173
207
  }
174
208
  }];
209
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_improve_inp')) {
210
+ plugins.push({
211
+ name: 'floatingToolbarSharedStateCache',
212
+ plugin: function plugin() {
213
+ return new _safePlugin.SafePlugin({
214
+ view: function view(_view) {
215
+ editorView = _view;
216
+ sharedStateCache = undefined;
217
+ return {
218
+ destroy: function destroy() {
219
+ editorView = undefined;
220
+ sharedStateCache = undefined;
221
+ }
222
+ };
223
+ }
224
+ });
225
+ }
226
+ });
227
+ }
175
228
  return plugins;
176
229
  },
177
230
  actions: {
@@ -183,18 +236,7 @@ var floatingToolbarPlugin = exports.floatingToolbarPlugin = function floatingToo
183
236
  return (0, _commands.copyNode)(nodeType, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, inputMethod);
184
237
  }
185
238
  },
186
- getSharedState: function getSharedState(editorState) {
187
- var _api$interaction, _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
188
- if (!editorState) {
189
- return undefined;
190
- }
191
- var interactionState = api === null || api === void 0 || (_api$interaction = api.interaction) === null || _api$interaction === void 0 || (_api$interaction = _api$interaction.sharedState.currentState()) === null || _api$interaction === void 0 ? void 0 : _api$interaction.interactionState;
192
- var configWithNodeInfo = interactionState !== 'hasNotHadInteraction' ? (_pluginKey$getState$g = (_pluginKey$getState = pluginKey.getState(editorState)) === null || _pluginKey$getState === 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 : undefined;
193
- return {
194
- configWithNodeInfo: configWithNodeInfo,
195
- floatingToolbarData: _pluginKey.pluginKey.getState(editorState)
196
- };
197
- },
239
+ getSharedState: getSharedState,
198
240
  contentComponent: function contentComponent(_ref4) {
199
241
  var popupsMountPoint = _ref4.popupsMountPoint,
200
242
  popupsBoundariesElement = _ref4.popupsBoundariesElement,
@@ -10,6 +10,7 @@ import { areToolbarFlagsEnabled } from '@atlaskit/editor-common/toolbar-flag-che
10
10
  import { useSharedPluginState } from '@atlaskit/editor-common/useSharedPluginState';
11
11
  import { AllSelection, PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
12
12
  import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
13
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
13
14
  import { fg } from '@atlaskit/platform-feature-flags/fg';
14
15
  import { useToolbarExternalStore } from './hooks/useToolbarExternalStore';
15
16
  import { copyNode } from './pm-plugins/commands';
@@ -130,6 +131,39 @@ function filterUndefined(x) {
130
131
  export const floatingToolbarPlugin = ({
131
132
  api
132
133
  }) => {
134
+ let editorView;
135
+ let sharedStateCache;
136
+ const getSharedState = editorState => {
137
+ var _api$interaction, _api$interaction$shar, _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
138
+ if (!editorState) {
139
+ return undefined;
140
+ }
141
+ const memoizePreviousState = isExperimentEnabled('platform_editor_improve_inp');
142
+ if (memoizePreviousState) {
143
+ // Current-state reads remain live: handlers can depend on mutable values
144
+ // outside EditorState. Only historical reads may reuse a computed result.
145
+ if (editorView && editorState !== editorView.state) {
146
+ var _sharedStateCache;
147
+ const cached = (_sharedStateCache = sharedStateCache) === null || _sharedStateCache === void 0 ? void 0 : _sharedStateCache.get(editorState);
148
+ if (cached) {
149
+ return cached;
150
+ }
151
+ }
152
+ } else {
153
+ sharedStateCache = undefined;
154
+ }
155
+ const interactionState = api === null || api === void 0 ? void 0 : (_api$interaction = api.interaction) === null || _api$interaction === void 0 ? void 0 : (_api$interaction$shar = _api$interaction.sharedState.currentState()) === null || _api$interaction$shar === void 0 ? void 0 : _api$interaction$shar.interactionState;
156
+ const configWithNodeInfo = interactionState !== 'hasNotHadInteraction' ? (_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 : undefined;
157
+ const sharedState = {
158
+ configWithNodeInfo,
159
+ floatingToolbarData: dataPluginKey.getState(editorState)
160
+ };
161
+ if (memoizePreviousState && editorView) {
162
+ sharedStateCache ??= new WeakMap();
163
+ sharedStateCache.set(editorState, sharedState);
164
+ }
165
+ return sharedState;
166
+ };
133
167
  return {
134
168
  name: 'floatingToolbar',
135
169
  pmPlugins(floatingToolbarHandlers = []) {
@@ -154,6 +188,23 @@ export const floatingToolbarPlugin = ({
154
188
  name: 'forceFocus',
155
189
  plugin: () => forceFocusPlugin()
156
190
  }];
191
+ if (isExperimentEnabled('platform_editor_improve_inp')) {
192
+ plugins.push({
193
+ name: 'floatingToolbarSharedStateCache',
194
+ plugin: () => new SafePlugin({
195
+ view: view => {
196
+ editorView = view;
197
+ sharedStateCache = undefined;
198
+ return {
199
+ destroy: () => {
200
+ editorView = undefined;
201
+ sharedStateCache = undefined;
202
+ }
203
+ };
204
+ }
205
+ })
206
+ });
207
+ }
157
208
  return plugins;
158
209
  },
159
210
  actions: {
@@ -165,18 +216,7 @@ export const floatingToolbarPlugin = ({
165
216
  return copyNode(nodeType, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, inputMethod);
166
217
  }
167
218
  },
168
- getSharedState(editorState) {
169
- var _api$interaction, _api$interaction$shar, _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
170
- if (!editorState) {
171
- return undefined;
172
- }
173
- const interactionState = api === null || api === void 0 ? void 0 : (_api$interaction = api.interaction) === null || _api$interaction === void 0 ? void 0 : (_api$interaction$shar = _api$interaction.sharedState.currentState()) === null || _api$interaction$shar === void 0 ? void 0 : _api$interaction$shar.interactionState;
174
- const configWithNodeInfo = interactionState !== 'hasNotHadInteraction' ? (_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 : undefined;
175
- return {
176
- configWithNodeInfo,
177
- floatingToolbarData: dataPluginKey.getState(editorState)
178
- };
179
- },
219
+ getSharedState,
180
220
  contentComponent({
181
221
  popupsMountPoint,
182
222
  popupsBoundariesElement,
@@ -14,6 +14,7 @@ import { areToolbarFlagsEnabled } from '@atlaskit/editor-common/toolbar-flag-che
14
14
  import { useSharedPluginState } from '@atlaskit/editor-common/useSharedPluginState';
15
15
  import { AllSelection, PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
16
16
  import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
17
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
17
18
  import { fg } from '@atlaskit/platform-feature-flags/fg';
18
19
  import { useToolbarExternalStore } from './hooks/useToolbarExternalStore';
19
20
  import { copyNode as _copyNode } from './pm-plugins/commands';
@@ -131,6 +132,39 @@ function filterUndefined(x) {
131
132
  }
132
133
  export var floatingToolbarPlugin = function floatingToolbarPlugin(_ref) {
133
134
  var api = _ref.api;
135
+ var editorView;
136
+ var sharedStateCache;
137
+ var getSharedState = function getSharedState(editorState) {
138
+ var _api$interaction, _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
139
+ if (!editorState) {
140
+ return undefined;
141
+ }
142
+ var memoizePreviousState = isExperimentEnabled('platform_editor_improve_inp');
143
+ if (memoizePreviousState) {
144
+ // Current-state reads remain live: handlers can depend on mutable values
145
+ // outside EditorState. Only historical reads may reuse a computed result.
146
+ if (editorView && editorState !== editorView.state) {
147
+ var _sharedStateCache;
148
+ var cached = (_sharedStateCache = sharedStateCache) === null || _sharedStateCache === void 0 ? void 0 : _sharedStateCache.get(editorState);
149
+ if (cached) {
150
+ return cached;
151
+ }
152
+ }
153
+ } else {
154
+ sharedStateCache = undefined;
155
+ }
156
+ var interactionState = api === null || api === void 0 || (_api$interaction = api.interaction) === null || _api$interaction === void 0 || (_api$interaction = _api$interaction.sharedState.currentState()) === null || _api$interaction === void 0 ? void 0 : _api$interaction.interactionState;
157
+ var configWithNodeInfo = interactionState !== 'hasNotHadInteraction' ? (_pluginKey$getState$g = (_pluginKey$getState = pluginKey.getState(editorState)) === null || _pluginKey$getState === 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 : undefined;
158
+ var sharedState = {
159
+ configWithNodeInfo: configWithNodeInfo,
160
+ floatingToolbarData: dataPluginKey.getState(editorState)
161
+ };
162
+ if (memoizePreviousState && editorView) {
163
+ sharedStateCache !== null && sharedStateCache !== void 0 ? sharedStateCache : sharedStateCache = new WeakMap();
164
+ sharedStateCache.set(editorState, sharedState);
165
+ }
166
+ return sharedState;
167
+ };
134
168
  return {
135
169
  name: 'floatingToolbar',
136
170
  pmPlugins: function pmPlugins() {
@@ -160,6 +194,25 @@ export var floatingToolbarPlugin = function floatingToolbarPlugin(_ref) {
160
194
  return forceFocusPlugin();
161
195
  }
162
196
  }];
197
+ if (isExperimentEnabled('platform_editor_improve_inp')) {
198
+ plugins.push({
199
+ name: 'floatingToolbarSharedStateCache',
200
+ plugin: function plugin() {
201
+ return new SafePlugin({
202
+ view: function view(_view) {
203
+ editorView = _view;
204
+ sharedStateCache = undefined;
205
+ return {
206
+ destroy: function destroy() {
207
+ editorView = undefined;
208
+ sharedStateCache = undefined;
209
+ }
210
+ };
211
+ }
212
+ });
213
+ }
214
+ });
215
+ }
163
216
  return plugins;
164
217
  },
165
218
  actions: {
@@ -171,18 +224,7 @@ export var floatingToolbarPlugin = function floatingToolbarPlugin(_ref) {
171
224
  return _copyNode(nodeType, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, inputMethod);
172
225
  }
173
226
  },
174
- getSharedState: function getSharedState(editorState) {
175
- var _api$interaction, _pluginKey$getState$g, _pluginKey$getState, _pluginKey$getState$g2;
176
- if (!editorState) {
177
- return undefined;
178
- }
179
- var interactionState = api === null || api === void 0 || (_api$interaction = api.interaction) === null || _api$interaction === void 0 || (_api$interaction = _api$interaction.sharedState.currentState()) === null || _api$interaction === void 0 ? void 0 : _api$interaction.interactionState;
180
- var configWithNodeInfo = interactionState !== 'hasNotHadInteraction' ? (_pluginKey$getState$g = (_pluginKey$getState = pluginKey.getState(editorState)) === null || _pluginKey$getState === 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 : undefined;
181
- return {
182
- configWithNodeInfo: configWithNodeInfo,
183
- floatingToolbarData: dataPluginKey.getState(editorState)
184
- };
185
- },
227
+ getSharedState: getSharedState,
186
228
  contentComponent: function contentComponent(_ref4) {
187
229
  var popupsMountPoint = _ref4.popupsMountPoint,
188
230
  popupsBoundariesElement = _ref4.popupsBoundariesElement,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-floating-toolbar",
3
- "version": "32.0.2",
3
+ "version": "32.0.3",
4
4
  "description": "Floating toolbar plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",