@atlaskit/editor-common 75.3.0 → 75.4.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 (46) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/hooks/useSharedPluginState.js +39 -3
  3. package/dist/cjs/monitoring/error.js +1 -1
  4. package/dist/cjs/preset/builder.js +48 -48
  5. package/dist/cjs/ui/DropList/index.js +1 -1
  6. package/dist/cjs/ui-menu/ArrowKeyNavigationProvider/MenuArrowKeyNavigationProvider/index.js +6 -6
  7. package/dist/cjs/ui-menu/Dropdown/index.js +3 -2
  8. package/dist/cjs/ui-menu/DropdownMenu/index.js +2 -2
  9. package/dist/cjs/ui-menu/ToolbarArrowKeyNavigationProvider/index.js +8 -8
  10. package/dist/cjs/ui-menu/ToolbarButton/index.js +1 -1
  11. package/dist/cjs/ui-react/with-react-editor-view-outer-listeners.js +4 -5
  12. package/dist/es2019/hooks/useSharedPluginState.js +41 -5
  13. package/dist/es2019/monitoring/error.js +1 -1
  14. package/dist/es2019/preset/builder.js +48 -48
  15. package/dist/es2019/ui/DropList/index.js +1 -1
  16. package/dist/es2019/ui-menu/ArrowKeyNavigationProvider/MenuArrowKeyNavigationProvider/index.js +6 -6
  17. package/dist/es2019/ui-menu/Dropdown/index.js +3 -2
  18. package/dist/es2019/ui-menu/DropdownMenu/index.js +3 -2
  19. package/dist/es2019/ui-menu/ToolbarArrowKeyNavigationProvider/index.js +8 -8
  20. package/dist/es2019/ui-menu/ToolbarButton/index.js +1 -1
  21. package/dist/es2019/ui-react/with-react-editor-view-outer-listeners.js +4 -5
  22. package/dist/esm/hooks/useSharedPluginState.js +40 -4
  23. package/dist/esm/monitoring/error.js +1 -1
  24. package/dist/esm/preset/builder.js +48 -48
  25. package/dist/esm/ui/DropList/index.js +1 -1
  26. package/dist/esm/ui-menu/ArrowKeyNavigationProvider/MenuArrowKeyNavigationProvider/index.js +6 -6
  27. package/dist/esm/ui-menu/Dropdown/index.js +3 -2
  28. package/dist/esm/ui-menu/DropdownMenu/index.js +3 -2
  29. package/dist/esm/ui-menu/ToolbarArrowKeyNavigationProvider/index.js +8 -8
  30. package/dist/esm/ui-menu/ToolbarButton/index.js +1 -1
  31. package/dist/esm/ui-react/with-react-editor-view-outer-listeners.js +4 -5
  32. package/dist/types/analytics/types/inline-comment-events.d.ts +2 -2
  33. package/dist/types/hooks/useSharedPluginState.d.ts +29 -0
  34. package/dist/types/types/floating-toolbar.d.ts +4 -3
  35. package/dist/types/ui-menu/ArrowKeyNavigationProvider/MenuArrowKeyNavigationProvider/index.d.ts +1 -1
  36. package/dist/types/ui-menu/Dropdown/index.d.ts +3 -2
  37. package/dist/types/ui-menu/DropdownMenu/index.d.ts +1 -2
  38. package/dist/types/ui-menu/ToolbarButton/index.d.ts +3 -3
  39. package/dist/types-ts4.5/analytics/types/inline-comment-events.d.ts +2 -2
  40. package/dist/types-ts4.5/hooks/useSharedPluginState.d.ts +29 -0
  41. package/dist/types-ts4.5/types/floating-toolbar.d.ts +4 -3
  42. package/dist/types-ts4.5/ui-menu/ArrowKeyNavigationProvider/MenuArrowKeyNavigationProvider/index.d.ts +1 -1
  43. package/dist/types-ts4.5/ui-menu/Dropdown/index.d.ts +3 -2
  44. package/dist/types-ts4.5/ui-menu/DropdownMenu/index.d.ts +1 -2
  45. package/dist/types-ts4.5/ui-menu/ToolbarButton/index.d.ts +3 -3
  46. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-common
2
2
 
3
+ ## 75.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`21305ee6254`](https://bitbucket.org/atlassian/atlassian-frontend/commits/21305ee6254) - ED-19874 Align the dropdown with the floating toolbar if there is a single button in the toolbar
8
+
9
+ ### Patch Changes
10
+
11
+ - [`b092b2cb3b7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b092b2cb3b7) - Dummy change as workaround for product integrator pipeline. This change fixes comment spacing.
12
+
13
+ ## 75.3.1
14
+
15
+ ### Patch Changes
16
+
17
+ - [`32e751116bb`](https://bitbucket.org/atlassian/atlassian-frontend/commits/32e751116bb) - [ED-20088] Debounce updates into the useSharedPluginState to avoid blocking the main thread with unnecessary UI updates
18
+
3
19
  ## 75.3.0
4
20
 
5
21
  ### Minor Changes
@@ -8,6 +8,7 @@ exports.useSharedPluginState = useSharedPluginState;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _react = require("react");
11
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
11
12
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
13
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
14
  /**
@@ -39,6 +40,35 @@ function useStaticPlugins(plugins) {
39
40
  }
40
41
 
41
42
  /**
43
+ *
44
+ * ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
45
+ * If the plugins you are listening to generate multiple shared states while the user is typing,
46
+ * your React Component will get only the last one.
47
+ *
48
+ * Usually, for UI updates, you may need only the last state. But, if you have a specific scenario requiring you to access all states,
49
+ * do not use this hook. Instead, you can subscribe directly to the plugin sharedState API:
50
+ *
51
+ * ```typescript
52
+ *
53
+ * function ExampleSpecialCase({ api }: Props) {
54
+ * const [dogState, setDogState] = React.useState(null);
55
+ * useEffect(() => {
56
+ * const unsub = api.dog.sharedState.onChange(({ nextSharedState, prevSharedState }) => {
57
+ * setDogState(nextSharedState);
58
+ * });
59
+ *
60
+ * return unsub;
61
+ * }, [api]);
62
+ *
63
+ * useEffect(() => {
64
+ * someCriticalAndWeirdUseCase(dogState);
65
+ *
66
+ * }, [dogState]);
67
+ *
68
+ * return null;
69
+ * }
70
+ *
71
+ * ```
42
72
  *
43
73
  * Used to return the current plugin state of
44
74
  * input dependencies
@@ -88,7 +118,13 @@ function useSharedPluginStateInternal(externalPlugins) {
88
118
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
89
119
  pluginStates = _useState2[0],
90
120
  setPluginState = _useState2[1];
121
+ var refStates = (0, _react.useRef)({});
91
122
  (0, _react.useLayoutEffect)(function () {
123
+ var debouncedPluginStateUpdate = (0, _debounce.default)(function () {
124
+ setPluginState(function (currentPluginStates) {
125
+ return _objectSpread(_objectSpread({}, currentPluginStates), refStates.current);
126
+ });
127
+ });
92
128
  var unsubs = Object.entries(externalPlugins).map(function (_ref3) {
93
129
  var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
94
130
  pluginKey = _ref4[0],
@@ -99,12 +135,12 @@ function useSharedPluginStateInternal(externalPlugins) {
99
135
  if (prevSharedState === nextSharedState) {
100
136
  return;
101
137
  }
102
- setPluginState(function (currentPluginStates) {
103
- return _objectSpread(_objectSpread({}, currentPluginStates), {}, (0, _defineProperty2.default)({}, pluginKey, nextSharedState));
104
- });
138
+ refStates.current[pluginKey] = nextSharedState;
139
+ debouncedPluginStateUpdate();
105
140
  });
106
141
  });
107
142
  return function () {
143
+ refStates.current = {};
108
144
  unsubs.forEach(function (cb) {
109
145
  return cb === null || cb === void 0 ? void 0 : cb();
110
146
  });
@@ -16,7 +16,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
16
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
17
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
18
18
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
19
- var packageVersion = "75.3.0";
19
+ var packageVersion = "75.4.0";
20
20
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
21
21
  // Remove URL as it has UGC
22
22
  // TODO: Sanitise the URL instead of just removing it
@@ -34,21 +34,21 @@ var EditorPresetBuilder = /*#__PURE__*/function () {
34
34
  nextOrTuple].concat((0, _toConsumableArray2.default)(this.data)));
35
35
  }
36
36
 
37
- //hasPlugin<Plugin extends NextEditorPlugin<any, any>>(
38
- // pluginToAdd: Plugin,
39
- //): this is TryCastEditorPresetBuilderByCheckingPlugins<this, Plugin> {
40
- // const hasPluginQueryExists = this.data.find((pluginEntry) => {
41
- // const pluginFunction: NextEditorPlugin<any, any> = !Array.isArray(
42
- // pluginEntry,
43
- // )
44
- // ? pluginEntry
45
- // : pluginEntry[0];
37
+ // hasPlugin<Plugin extends NextEditorPlugin<any, any>>(
38
+ // pluginToAdd: Plugin,
39
+ // ): this is TryCastEditorPresetBuilderByCheckingPlugins<this, Plugin> {
40
+ // const hasPluginQueryExists = this.data.find((pluginEntry) => {
41
+ // const pluginFunction: NextEditorPlugin<any, any> = !Array.isArray(
42
+ // pluginEntry,
43
+ // )
44
+ // ? pluginEntry
45
+ // : pluginEntry[0];
46
46
 
47
- // return pluginFunction === pluginToAdd;
48
- // });
47
+ // return pluginFunction === pluginToAdd;
48
+ // });
49
49
 
50
- // return Boolean(hasPluginQueryExists);
51
- //}
50
+ // return Boolean(hasPluginQueryExists);
51
+ // }
52
52
  }, {
53
53
  key: "maybeAdd",
54
54
  value: function maybeAdd(pluginToAdd, add) {
@@ -145,41 +145,41 @@ var EditorPresetBuilder = /*#__PURE__*/function () {
145
145
  }
146
146
 
147
147
  // TODO: ED-17023 - Bring back type safety to the EditorPresetBuilder.add preset
148
- //import type {
149
- // ExtractPluginDependencies,
150
- //} from '../types/next-editor-plugin';
151
- //type TryCastEditorPresetBuilderByCheckingDependencies<MaybeEditorPresetBuilder, Plugin> =
152
- // MaybeEditorPresetBuilder extends EditorPresetBuilder<any, infer StackPlugins>
153
- // ? Plugin extends NextEditorPlugin<any, any>
154
- // ? ExtractPluginDependencies<Plugin>[number] extends StackPlugins[number]
155
- // ? MaybeEditorPresetBuilder
156
- // : never
157
- // : never
158
- // : never;
159
- // Because how our plugins are added in the preset, we can't use the type safe system
160
- // in the EditorPresetBuilder.
161
- // TODO: ED-17023 - Bring back type safety to the EditorPresetBuilder.add preset
162
- //maybeAdd<
163
- // MaybePlugin extends NextEditorPlugin<any, any>,
164
- // MaybePluginNames extends string[],
165
- // MaybeStackPlugins extends AllEditorPresetPluginTypes[],
166
- // MaybeEditorPresetBuilder extends EditorPresetBuilder<
167
- // MaybePluginNames,
168
- // MaybeStackPlugins
169
- // >,
170
- //>(
171
- // pluginToAdd: MaybePlugin,
172
- // add: (
173
- // pluginToAdd: MaybePlugin,
174
- // maybeEditorPresetBuilder: TryCastEditorPresetBuilderByCheckingDependencies<this, MaybePlugin>,
175
- // ) => MaybeEditorPresetBuilder,
176
- //): MaybeEditorPresetBuilder | this {
177
- // return add(
178
- // pluginToAdd,
179
- // // @ts-ignore
180
- // this as any,
181
- // );
182
- //}
148
+ // import type {
149
+ // ExtractPluginDependencies,
150
+ // } from '../types/next-editor-plugin';
151
+ // type TryCastEditorPresetBuilderByCheckingDependencies<MaybeEditorPresetBuilder, Plugin> =
152
+ // MaybeEditorPresetBuilder extends EditorPresetBuilder<any, infer StackPlugins>
153
+ // ? Plugin extends NextEditorPlugin<any, any>
154
+ // ? ExtractPluginDependencies<Plugin>[number] extends StackPlugins[number]
155
+ // ? MaybeEditorPresetBuilder
156
+ // : never
157
+ // : never
158
+ // : never;
159
+ // Because how our plugins are added in the preset, we can't use the type safe system
160
+ // in the EditorPresetBuilder.
161
+ // TODO: ED-17023 - Bring back type safety to the EditorPresetBuilder.add preset
162
+ // maybeAdd<
163
+ // MaybePlugin extends NextEditorPlugin<any, any>,
164
+ // MaybePluginNames extends string[],
165
+ // MaybeStackPlugins extends AllEditorPresetPluginTypes[],
166
+ // MaybeEditorPresetBuilder extends EditorPresetBuilder<
167
+ // MaybePluginNames,
168
+ // MaybeStackPlugins
169
+ // >,
170
+ // >(
171
+ // pluginToAdd: MaybePlugin,
172
+ // add: (
173
+ // pluginToAdd: MaybePlugin,
174
+ // maybeEditorPresetBuilder: TryCastEditorPresetBuilderByCheckingDependencies<this, MaybePlugin>,
175
+ // ) => MaybeEditorPresetBuilder,
176
+ // ): MaybeEditorPresetBuilder | this {
177
+ // return add(
178
+ // pluginToAdd,
179
+ // // @ts-ignore
180
+ // this as any,
181
+ // );
182
+ // }
183
183
  }]);
184
184
  return EditorPresetBuilder;
185
185
  }();
@@ -24,7 +24,7 @@ var _templateObject, _templateObject2, _templateObject3;
24
24
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
25
25
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /** @jsx jsx */
26
26
  var packageName = "@atlaskit/editor-common";
27
- var packageVersion = "75.3.0";
27
+ var packageVersion = "75.4.0";
28
28
  var halfFocusRing = 1;
29
29
  var dropOffset = '0, 8';
30
30
  var DropList = /*#__PURE__*/function (_Component) {
@@ -78,14 +78,14 @@ var MenuArrowKeyNavigationProvider = function MenuArrowKeyNavigationProvider(_re
78
78
  var _wrapperRef$current;
79
79
  var targetElement = event.target;
80
80
 
81
- //Tab key on menu items can be handled in the parent components of dropdown menus with KeydownHandlerContext
81
+ // Tab key on menu items can be handled in the parent components of dropdown menus with KeydownHandlerContext
82
82
  if (event.key === 'Tab' && closeOnTab) {
83
83
  handleClose(event);
84
84
  keyDownHandlerContext === null || keyDownHandlerContext === void 0 ? void 0 : keyDownHandlerContext.handleTab();
85
85
  return;
86
86
  }
87
87
 
88
- //To trap the focus inside the toolbar using left and right arrow keys
88
+ // To trap the focus inside the toolbar using left and right arrow keys
89
89
  var focusableElements = getFocusableElements(wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current);
90
90
  if (!focusableElements || (focusableElements === null || focusableElements === void 0 ? void 0 : focusableElements.length) === 0) {
91
91
  return;
@@ -111,10 +111,10 @@ var MenuArrowKeyNavigationProvider = function MenuArrowKeyNavigationProvider(_re
111
111
  break;
112
112
  }
113
113
 
114
- //ArrowLeft/Right on the menu should close the menus
115
- //then logic to retain the focus can be handled in the parent components with KeydownHandlerContext
114
+ // ArrowLeft/Right on the menu should close the menus
115
+ // then logic to retain the focus can be handled in the parent components with KeydownHandlerContext
116
116
  case 'ArrowLeft':
117
- //Filter out the events from outside the menu
117
+ // Filter out the events from outside the menu
118
118
  if (!targetElement.closest('.custom-key-handler-wrapper')) {
119
119
  return;
120
120
  }
@@ -124,7 +124,7 @@ var MenuArrowKeyNavigationProvider = function MenuArrowKeyNavigationProvider(_re
124
124
  }
125
125
  break;
126
126
  case 'ArrowRight':
127
- //Filter out the events from outside the menu
127
+ // Filter out the events from outside the menu
128
128
  if (!targetElement.closest('.custom-key-handler-wrapper')) {
129
129
  return;
130
130
  }
@@ -80,9 +80,10 @@ var Dropdown = /*#__PURE__*/function (_PureComponent) {
80
80
  fitWidth = _this$props.fitWidth,
81
81
  zIndex = _this$props.zIndex,
82
82
  arrowKeyNavigationProviderOptions = _this$props.arrowKeyNavigationProviderOptions,
83
- dropdownListId = _this$props.dropdownListId;
83
+ dropdownListId = _this$props.dropdownListId,
84
+ alignDropdownWithParentElement = _this$props.alignDropdownWithParentElement;
84
85
  return /*#__PURE__*/_react.default.createElement(_Popup.default, {
85
- target: target,
86
+ target: alignDropdownWithParentElement ? target === null || target === void 0 ? void 0 : target.closest("[data-testid='editor-floating-toolbar'") : target,
86
87
  mountTo: mountTo,
87
88
  boundariesElement: boundariesElement,
88
89
  scrollableElement: scrollableElement,
@@ -333,8 +333,8 @@ function DropdownMenuItem(_ref) {
333
333
  var DropdownMenuWithKeyboardNavigation = /*#__PURE__*/_react.default.memo(function (_ref2) {
334
334
  var props = (0, _extends2.default)({}, ((0, _objectDestructuringEmpty2.default)(_ref2), _ref2));
335
335
  var keyDownHandlerContext = (0, _react.useContext)(_ToolbarArrowKeyNavigationProvider.KeyDownHandlerContext);
336
- //This context is to handle the tab, Arrow Right/Left key events for dropdown.
337
- //Default context has the void callbacks for above key events
336
+ // This context is to handle the tab, Arrow Right/Left key events for dropdown.
337
+ // Default context has the void callbacks for above key events
338
338
  return (0, _react2.jsx)(DropdownMenuWrapper, (0, _extends2.default)({
339
339
  arrowKeyNavigationProviderOptions: _objectSpread(_objectSpread({}, props.arrowKeyNavigationProviderOptions), {}, {
340
340
  keyDownHandlerContext: keyDownHandlerContext
@@ -115,15 +115,15 @@ var ToolbarArrowKeyNavigationProvider = function ToolbarArrowKeyNavigationProvid
115
115
  */
116
116
  var handleKeyDown = function handleKeyDown(event) {
117
117
  var _document$querySelect, _document$querySelect2, _wrapperRef$current;
118
- //To trap the focus inside the horizontal toolbar for left and right arrow keys
118
+ // To trap the focus inside the horizontal toolbar for left and right arrow keys
119
119
  var targetElement = event.target;
120
120
 
121
- //To filter out the events outside the child component
121
+ // To filter out the events outside the child component
122
122
  if (!targetElement.closest("".concat(childComponentSelector))) {
123
123
  return;
124
124
  }
125
125
 
126
- //The key events are from child components such as dropdown menus / popups are ignored
126
+ // The key events are from child components such as dropdown menus / popups are ignored
127
127
  if ((_document$querySelect = document.querySelector('[data-role="droplistContent"], [data-test-id="color-picker-menu"], [data-emoji-picker-container="true"]')) !== null && _document$querySelect !== void 0 && _document$querySelect.contains(targetElement) || (_document$querySelect2 = document.querySelector('[data-test-id="color-picker-menu"]')) !== null && _document$querySelect2 !== void 0 && _document$querySelect2.contains(targetElement) || event.key === 'ArrowUp' || event.key === 'ArrowDown' || disableArrowKeyNavigation) {
128
128
  return;
129
129
  }
@@ -137,15 +137,15 @@ var ToolbarArrowKeyNavigationProvider = function ToolbarArrowKeyNavigationProvid
137
137
  return;
138
138
  }
139
139
 
140
- //This is kind of hack to reset the current focused toolbar item
141
- //to handle some use cases such as Tab in/out of main toolbar
140
+ // This is kind of hack to reset the current focused toolbar item
141
+ // to handle some use cases such as Tab in/out of main toolbar
142
142
  if (!((_wrapperRef$current = wrapperRef.current) !== null && _wrapperRef$current !== void 0 && _wrapperRef$current.contains(targetElement))) {
143
143
  selectedItemIndex.current = -1;
144
144
  } else {
145
145
  selectedItemIndex.current = filteredFocusableElements.indexOf(targetElement) > -1 ? filteredFocusableElements.indexOf(targetElement) : selectedItemIndex.current;
146
146
  }
147
147
 
148
- //do not scroll to focused element for sticky toolbar when navigating with arrows to avoid unnesessary scroll jump
148
+ // do not scroll to focused element for sticky toolbar when navigating with arrows to avoid unnesessary scroll jump
149
149
  var allowScrollToElement = !(editorAppearance === 'comment' && !!useStickyToolbar);
150
150
  switch (event.key) {
151
151
  case 'ArrowRight':
@@ -168,7 +168,7 @@ var ToolbarArrowKeyNavigationProvider = function ToolbarArrowKeyNavigationProvid
168
168
  }
169
169
  };
170
170
  var globalKeyDownHandler = function globalKeyDownHandler(event) {
171
- //To focus the first element in the toolbar
171
+ // To focus the first element in the toolbar
172
172
  if (isShortcutToFocusToolbar(event)) {
173
173
  var _filteredFocusableEle4, _filteredFocusableEle5;
174
174
  var filteredFocusableElements = getFilteredFocusableElements(wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current);
@@ -212,7 +212,7 @@ function getFocusableElements(rootNode) {
212
212
  return Array.from(focusableModalElements);
213
213
  }
214
214
  function getFilteredFocusableElements(rootNode) {
215
- //The focusable elements from child components such as dropdown menus / popups are ignored
215
+ // The focusable elements from child components such as dropdown menus / popups are ignored
216
216
  return getFocusableElements(rootNode).filter(function (elm) {
217
217
  var style = window.getComputedStyle(elm);
218
218
  // ignore invisible element to avoid losing focus
@@ -16,7 +16,7 @@ var _analytics = require("../../analytics");
16
16
  var _styles = _interopRequireDefault(require("./styles"));
17
17
  var _templateObject; // This file is copied to `packages/editor/editor-plugin-ai/src/ui/components/AtlassianIntelligenceToolbarButton/ToolbarButton/index.tsx`
18
18
  // If you make any change here, copy it to above file as well
19
- // and notify about the change in #team-fc-editor-ai-dev channel.
19
+ // and notify about the change in #team-fc-editor-ai-dev channel.
20
20
  /** @jsx jsx */
21
21
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -42,7 +42,7 @@ var WithOutsideClick = /*#__PURE__*/function (_PureComponent) {
42
42
  if (_this.props.handleClickOutside) {
43
43
  var _this$props$editorVie;
44
44
  _this.props.handleClickOutside(evt);
45
- //When the menus are closed by clicking outside the focus is set on editor.
45
+ // When the menus are closed by clicking outside the focus is set on editor.
46
46
  if (!((_this$props$editorVie = _this.props.editorView) !== null && _this$props$editorVie !== void 0 && _this$props$editorVie.hasFocus())) {
47
47
  var _this$props$editorVie2;
48
48
  (_this$props$editorVie2 = _this.props.editorView) === null || _this$props$editorVie2 === void 0 ? void 0 : _this$props$editorVie2.focus();
@@ -58,12 +58,12 @@ var WithOutsideClick = /*#__PURE__*/function (_PureComponent) {
58
58
  evt.preventDefault();
59
59
  evt.stopPropagation();
60
60
  _this.props.handleEscapeKeydown(evt);
61
- //on 'Esc', Focus is handled in 'handleEscapeKeydown'.
61
+ // on 'Esc', Focus is handled in 'handleEscapeKeydown'.
62
62
  return false;
63
63
  } else if (evt.code === 'Enter' && _this.props.handleEnterKeydown) {
64
64
  _this.props.handleEnterKeydown(evt);
65
65
  } else if (evt.code === 'Tab' && _this.props.handleEscapeKeydown && _this.props.closeOnTab) {
66
- //The menus should be closed when the tab is pressed as it takes the focus out of the menu
66
+ // The menus should be closed when the tab is pressed as it takes the focus out of the menu
67
67
  _this.props.handleEscapeKeydown(evt);
68
68
  }
69
69
  });
@@ -77,8 +77,7 @@ var WithOutsideClick = /*#__PURE__*/function (_PureComponent) {
77
77
  }
78
78
  if (this.props.handleEscapeKeydown) {
79
79
  var _this$props$editorRef;
80
- //
81
- //Attached event to the menu so that 'ESC' events from the opened menu also will be handled.
80
+ // Attached event to the menu so that 'ESC' events from the opened menu also will be handled.
82
81
  (((_this$props$editorRef = this.props.editorRef) === null || _this$props$editorRef === void 0 ? void 0 : _this$props$editorRef.current) || this.props.targetRef || document).addEventListener('keydown', this.handleKeydown, false);
83
82
  }
84
83
  }
@@ -1,4 +1,5 @@
1
- import { useLayoutEffect, useMemo, useState } from 'react';
1
+ import { useLayoutEffect, useMemo, useRef, useState } from 'react';
2
+ import debounce from 'lodash/debounce';
2
3
  /**
3
4
  *
4
5
  * Directly map object values
@@ -24,6 +25,35 @@ function useStaticPlugins(plugins) {
24
25
  }
25
26
 
26
27
  /**
28
+ *
29
+ * ⚠️⚠️⚠️ This is a debounced hook ⚠️⚠️⚠️
30
+ * If the plugins you are listening to generate multiple shared states while the user is typing,
31
+ * your React Component will get only the last one.
32
+ *
33
+ * Usually, for UI updates, you may need only the last state. But, if you have a specific scenario requiring you to access all states,
34
+ * do not use this hook. Instead, you can subscribe directly to the plugin sharedState API:
35
+ *
36
+ * ```typescript
37
+ *
38
+ * function ExampleSpecialCase({ api }: Props) {
39
+ * const [dogState, setDogState] = React.useState(null);
40
+ * useEffect(() => {
41
+ * const unsub = api.dog.sharedState.onChange(({ nextSharedState, prevSharedState }) => {
42
+ * setDogState(nextSharedState);
43
+ * });
44
+ *
45
+ * return unsub;
46
+ * }, [api]);
47
+ *
48
+ * useEffect(() => {
49
+ * someCriticalAndWeirdUseCase(dogState);
50
+ *
51
+ * }, [dogState]);
52
+ *
53
+ * return null;
54
+ * }
55
+ *
56
+ * ```
27
57
  *
28
58
  * Used to return the current plugin state of
29
59
  * input dependencies
@@ -67,7 +97,14 @@ export function useSharedPluginState(injectionApi, plugins) {
67
97
  }
68
98
  function useSharedPluginStateInternal(externalPlugins) {
69
99
  const [pluginStates, setPluginState] = useState(mapValues(externalPlugins, value => value === null || value === void 0 ? void 0 : value.sharedState.currentState()));
100
+ const refStates = useRef({});
70
101
  useLayoutEffect(() => {
102
+ const debouncedPluginStateUpdate = debounce(() => {
103
+ setPluginState(currentPluginStates => ({
104
+ ...currentPluginStates,
105
+ ...refStates.current
106
+ }));
107
+ });
71
108
  const unsubs = Object.entries(externalPlugins).map(([pluginKey, externalPlugin]) => {
72
109
  return externalPlugin === null || externalPlugin === void 0 ? void 0 : externalPlugin.sharedState.onChange(({
73
110
  nextSharedState,
@@ -76,13 +113,12 @@ function useSharedPluginStateInternal(externalPlugins) {
76
113
  if (prevSharedState === nextSharedState) {
77
114
  return;
78
115
  }
79
- setPluginState(currentPluginStates => ({
80
- ...currentPluginStates,
81
- [pluginKey]: nextSharedState
82
- }));
116
+ refStates.current[pluginKey] = nextSharedState;
117
+ debouncedPluginStateUpdate();
83
118
  });
84
119
  });
85
120
  return () => {
121
+ refStates.current = {};
86
122
  unsubs.forEach(cb => cb === null || cb === void 0 ? void 0 : cb());
87
123
  };
88
124
  // Do not re-render due to state changes, we only need to check this when
@@ -1,6 +1,6 @@
1
1
  const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
2
2
  const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
3
- const packageVersion = "75.3.0";
3
+ const packageVersion = "75.4.0";
4
4
  const sanitiseSentryEvents = (data, _hint) => {
5
5
  // Remove URL as it has UGC
6
6
  // TODO: Sanitise the URL instead of just removing it
@@ -14,21 +14,21 @@ export class EditorPresetBuilder {
14
14
  nextOrTuple, ...this.data);
15
15
  }
16
16
 
17
- //hasPlugin<Plugin extends NextEditorPlugin<any, any>>(
18
- // pluginToAdd: Plugin,
19
- //): this is TryCastEditorPresetBuilderByCheckingPlugins<this, Plugin> {
20
- // const hasPluginQueryExists = this.data.find((pluginEntry) => {
21
- // const pluginFunction: NextEditorPlugin<any, any> = !Array.isArray(
22
- // pluginEntry,
23
- // )
24
- // ? pluginEntry
25
- // : pluginEntry[0];
17
+ // hasPlugin<Plugin extends NextEditorPlugin<any, any>>(
18
+ // pluginToAdd: Plugin,
19
+ // ): this is TryCastEditorPresetBuilderByCheckingPlugins<this, Plugin> {
20
+ // const hasPluginQueryExists = this.data.find((pluginEntry) => {
21
+ // const pluginFunction: NextEditorPlugin<any, any> = !Array.isArray(
22
+ // pluginEntry,
23
+ // )
24
+ // ? pluginEntry
25
+ // : pluginEntry[0];
26
26
 
27
- // return pluginFunction === pluginToAdd;
28
- // });
27
+ // return pluginFunction === pluginToAdd;
28
+ // });
29
29
 
30
- // return Boolean(hasPluginQueryExists);
31
- //}
30
+ // return Boolean(hasPluginQueryExists);
31
+ // }
32
32
 
33
33
  maybeAdd(pluginToAdd, add) {
34
34
  return add(pluginToAdd,
@@ -106,39 +106,39 @@ export class EditorPresetBuilder {
106
106
  }
107
107
 
108
108
  // TODO: ED-17023 - Bring back type safety to the EditorPresetBuilder.add preset
109
- //import type {
110
- // ExtractPluginDependencies,
111
- //} from '../types/next-editor-plugin';
112
- //type TryCastEditorPresetBuilderByCheckingDependencies<MaybeEditorPresetBuilder, Plugin> =
113
- // MaybeEditorPresetBuilder extends EditorPresetBuilder<any, infer StackPlugins>
114
- // ? Plugin extends NextEditorPlugin<any, any>
115
- // ? ExtractPluginDependencies<Plugin>[number] extends StackPlugins[number]
116
- // ? MaybeEditorPresetBuilder
117
- // : never
118
- // : never
119
- // : never;
120
- // Because how our plugins are added in the preset, we can't use the type safe system
121
- // in the EditorPresetBuilder.
122
- // TODO: ED-17023 - Bring back type safety to the EditorPresetBuilder.add preset
123
- //maybeAdd<
124
- // MaybePlugin extends NextEditorPlugin<any, any>,
125
- // MaybePluginNames extends string[],
126
- // MaybeStackPlugins extends AllEditorPresetPluginTypes[],
127
- // MaybeEditorPresetBuilder extends EditorPresetBuilder<
128
- // MaybePluginNames,
129
- // MaybeStackPlugins
130
- // >,
131
- //>(
132
- // pluginToAdd: MaybePlugin,
133
- // add: (
134
- // pluginToAdd: MaybePlugin,
135
- // maybeEditorPresetBuilder: TryCastEditorPresetBuilderByCheckingDependencies<this, MaybePlugin>,
136
- // ) => MaybeEditorPresetBuilder,
137
- //): MaybeEditorPresetBuilder | this {
138
- // return add(
139
- // pluginToAdd,
140
- // // @ts-ignore
141
- // this as any,
142
- // );
143
- //}
109
+ // import type {
110
+ // ExtractPluginDependencies,
111
+ // } from '../types/next-editor-plugin';
112
+ // type TryCastEditorPresetBuilderByCheckingDependencies<MaybeEditorPresetBuilder, Plugin> =
113
+ // MaybeEditorPresetBuilder extends EditorPresetBuilder<any, infer StackPlugins>
114
+ // ? Plugin extends NextEditorPlugin<any, any>
115
+ // ? ExtractPluginDependencies<Plugin>[number] extends StackPlugins[number]
116
+ // ? MaybeEditorPresetBuilder
117
+ // : never
118
+ // : never
119
+ // : never;
120
+ // Because how our plugins are added in the preset, we can't use the type safe system
121
+ // in the EditorPresetBuilder.
122
+ // TODO: ED-17023 - Bring back type safety to the EditorPresetBuilder.add preset
123
+ // maybeAdd<
124
+ // MaybePlugin extends NextEditorPlugin<any, any>,
125
+ // MaybePluginNames extends string[],
126
+ // MaybeStackPlugins extends AllEditorPresetPluginTypes[],
127
+ // MaybeEditorPresetBuilder extends EditorPresetBuilder<
128
+ // MaybePluginNames,
129
+ // MaybeStackPlugins
130
+ // >,
131
+ // >(
132
+ // pluginToAdd: MaybePlugin,
133
+ // add: (
134
+ // pluginToAdd: MaybePlugin,
135
+ // maybeEditorPresetBuilder: TryCastEditorPresetBuilderByCheckingDependencies<this, MaybePlugin>,
136
+ // ) => MaybeEditorPresetBuilder,
137
+ // ): MaybeEditorPresetBuilder | this {
138
+ // return add(
139
+ // pluginToAdd,
140
+ // // @ts-ignore
141
+ // this as any,
142
+ // );
143
+ // }
144
144
  }
@@ -9,7 +9,7 @@ import { themed } from '@atlaskit/theme/components';
9
9
  import { borderRadius } from '@atlaskit/theme/constants';
10
10
  import Layer from '../Layer';
11
11
  const packageName = "@atlaskit/editor-common";
12
- const packageVersion = "75.3.0";
12
+ const packageVersion = "75.4.0";
13
13
  const halfFocusRing = 1;
14
14
  const dropOffset = '0, 8';
15
15
  class DropList extends Component {