@atlaskit/editor-common 93.4.3 → 93.5.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.
@@ -1,9 +1,12 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _extends from "@babel/runtime/helpers/extends";
2
3
  import React from 'react';
3
4
  import PropTypes from 'prop-types';
5
+ import { fg } from '@atlaskit/platform-feature-flags';
4
6
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '../analytics';
5
7
  import { createDispatch } from '../event-dispatcher';
6
8
  import { startMeasure, stopMeasure } from '../performance-measures';
9
+ import { EditorContext } from '../ui/EditorContext';
7
10
  import { analyticsEventKey } from '../utils';
8
11
  const DEFAULT_SAMPLING_RATE = 100;
9
12
  const DEFAULT_SLOW_THRESHOLD = 4;
@@ -50,6 +53,215 @@ const DEFAULT_SLOW_THRESHOLD = 4;
50
53
  *
51
54
  */
52
55
  class WithPluginState extends React.Component {
56
+ constructor(props) {
57
+ super(props);
58
+ }
59
+ render() {
60
+ if (fg('platform_editor_react18_phase2')) {
61
+ return /*#__PURE__*/React.createElement(WithPluginStateNew, this.props);
62
+ }
63
+ return /*#__PURE__*/React.createElement(WithPluginStateOld, this.props);
64
+ }
65
+ }
66
+ function WithPluginStateNew(props) {
67
+ const context = React.useContext(EditorContext);
68
+ return /*#__PURE__*/React.createElement(WithPluginStateInner, _extends({}, props, {
69
+ editorActions: context === null || context === void 0 ? void 0 : context.editorActions
70
+ }));
71
+ }
72
+ export class WithPluginStateInner extends React.Component {
73
+ constructor(props) {
74
+ super(props);
75
+ _defineProperty(this, "listeners", {});
76
+ _defineProperty(this, "debounce", null);
77
+ _defineProperty(this, "notAppliedState", {});
78
+ _defineProperty(this, "isSubscribed", false);
79
+ _defineProperty(this, "callsCount", 0);
80
+ _defineProperty(this, "handlePluginStateChange", (propName, pluginName, performanceOptions, skipEqualityCheck) => pluginState => {
81
+ // skipEqualityCheck is being used for old plugins since they are mutating plugin state instead of creating a new one
82
+ if (this.state[propName] !== pluginState || skipEqualityCheck) {
83
+ this.updateState({
84
+ stateSubset: {
85
+ [propName]: pluginState
86
+ },
87
+ pluginName,
88
+ performanceOptions
89
+ });
90
+ }
91
+ });
92
+ /**
93
+ * Debounces setState calls in order to reduce number of re-renders caused by several plugin state changes.
94
+ */
95
+ _defineProperty(this, "updateState", ({
96
+ stateSubset,
97
+ pluginName,
98
+ performanceOptions
99
+ }) => {
100
+ this.notAppliedState = {
101
+ ...this.notAppliedState,
102
+ ...stateSubset
103
+ };
104
+ if (this.debounce) {
105
+ window.clearTimeout(this.debounce);
106
+ }
107
+ const debounce = this.props.debounce !== false ? fn => window.setTimeout(fn, 0) : fn => fn();
108
+ this.debounce = debounce(() => {
109
+ const measure = `🦉${pluginName}::WithPluginState`;
110
+ performanceOptions.trackingEnabled && startMeasure(measure);
111
+ this.setState(this.notAppliedState, () => {
112
+ performanceOptions.trackingEnabled && stopMeasure(measure, duration => {
113
+ // Each WithPluginState component will fire analytics event no more than once every `samplingLimit` times
114
+ if (++this.callsCount % performanceOptions.samplingRate === 0 && duration > performanceOptions.slowThreshold) {
115
+ this.dispatchAnalyticsEvent({
116
+ action: ACTION.WITH_PLUGIN_STATE_CALLED,
117
+ actionSubject: ACTION_SUBJECT.EDITOR,
118
+ eventType: EVENT_TYPE.OPERATIONAL,
119
+ attributes: {
120
+ plugin: pluginName,
121
+ duration
122
+ }
123
+ });
124
+ }
125
+ });
126
+ });
127
+ this.debounce = null;
128
+ this.notAppliedState = {};
129
+ });
130
+ });
131
+ _defineProperty(this, "dispatchAnalyticsEvent", payload => {
132
+ const eventDispatcher = this.getEventDispatcher();
133
+ if (eventDispatcher) {
134
+ const dispatch = createDispatch(eventDispatcher);
135
+ dispatch(analyticsEventKey, {
136
+ payload
137
+ });
138
+ }
139
+ });
140
+ this.state = this.getPluginsStates(this.props.plugins, this.getEditorView(props));
141
+ }
142
+ getEditorView(maybeProps) {
143
+ const props = maybeProps || this.props;
144
+ const editorActions = props.editorActions;
145
+ return props.editorView || (editorActions === null || editorActions === void 0 ? void 0 : editorActions._privateGetEditorView());
146
+ }
147
+ getEventDispatcher(maybeProps) {
148
+ var _props$editorActions;
149
+ const props = maybeProps || this.props;
150
+ return props.eventDispatcher || ((_props$editorActions = props.editorActions) === null || _props$editorActions === void 0 ? void 0 : _props$editorActions._privateGetEventDispatcher());
151
+ }
152
+ getPluginsStates(plugins, editorView) {
153
+ if (!editorView || !plugins) {
154
+ return {};
155
+ }
156
+ const keys = Object.keys(plugins);
157
+ return keys.reduce((acc, propName) => {
158
+ const pluginKey = plugins[propName];
159
+ if (!pluginKey) {
160
+ return acc;
161
+ }
162
+ acc[propName] = pluginKey.getState(editorView.state);
163
+ return acc;
164
+ }, {});
165
+ }
166
+ subscribe(props) {
167
+ var _uiTracking$samplingR, _uiTracking$slowThres;
168
+ const plugins = props.plugins;
169
+ const eventDispatcher = this.getEventDispatcher(props);
170
+ const editorView = this.getEditorView(props);
171
+ if (!eventDispatcher || !editorView || this.isSubscribed) {
172
+ return;
173
+ }
174
+
175
+ // TODO: ED-15663
176
+ // Please, do not copy or use this kind of code below
177
+ // @ts-ignore
178
+ const fakePluginKey = {
179
+ key: 'analyticsPlugin$',
180
+ getState: state => {
181
+ return state['analyticsPlugin$'];
182
+ }
183
+ };
184
+ const analyticsPlugin = fakePluginKey.getState(editorView.state);
185
+ const uiTracking = analyticsPlugin && analyticsPlugin.performanceTracking ? analyticsPlugin.performanceTracking.uiTracking || {} : {};
186
+ const trackingEnabled = uiTracking.enabled === true;
187
+ const samplingRate = (_uiTracking$samplingR = uiTracking.samplingRate) !== null && _uiTracking$samplingR !== void 0 ? _uiTracking$samplingR : DEFAULT_SAMPLING_RATE;
188
+ const slowThreshold = (_uiTracking$slowThres = uiTracking.slowThreshold) !== null && _uiTracking$slowThres !== void 0 ? _uiTracking$slowThres : DEFAULT_SLOW_THRESHOLD;
189
+ this.isSubscribed = true;
190
+ const pluginsStates = this.getPluginsStates(plugins, editorView);
191
+ this.setState(pluginsStates);
192
+ Object.keys(plugins).forEach(propName => {
193
+ const pluginKey = plugins[propName];
194
+ if (!pluginKey) {
195
+ return;
196
+ }
197
+ const pluginName = pluginKey.key;
198
+ const pluginState = pluginsStates[propName];
199
+ const isPluginWithSubscribe = pluginState && pluginState.subscribe;
200
+ const handler = this.handlePluginStateChange(propName, pluginName, {
201
+ samplingRate,
202
+ slowThreshold,
203
+ trackingEnabled
204
+ }, isPluginWithSubscribe);
205
+ if (isPluginWithSubscribe) {
206
+ pluginState.subscribe(handler);
207
+ } else {
208
+ eventDispatcher.on(pluginKey.key, handler);
209
+ }
210
+ this.listeners[pluginKey.key] = {
211
+ handler,
212
+ pluginKey
213
+ };
214
+ });
215
+ }
216
+ unsubscribe() {
217
+ const eventDispatcher = this.getEventDispatcher();
218
+ const editorView = this.getEditorView();
219
+ if (!eventDispatcher || !editorView || !this.isSubscribed) {
220
+ return;
221
+ }
222
+ Object.keys(this.listeners).forEach(key => {
223
+ const pluginState = this.listeners[key].pluginKey.getState(editorView.state);
224
+ if (pluginState && pluginState.unsubscribe) {
225
+ pluginState.unsubscribe(this.listeners[key].handler);
226
+ } else {
227
+ eventDispatcher.off(key, this.listeners[key].handler);
228
+ }
229
+ });
230
+ this.listeners = [];
231
+ }
232
+ subscribeToContextUpdates() {
233
+ var _this$props$editorAct;
234
+ (_this$props$editorAct = this.props.editorActions) === null || _this$props$editorAct === void 0 ? void 0 : _this$props$editorAct._privateSubscribe(() => this.subscribe(this.props));
235
+ }
236
+ unsubscribeFromContextUpdates() {
237
+ var _this$props$editorAct2;
238
+ (_this$props$editorAct2 = this.props.editorActions) === null || _this$props$editorAct2 === void 0 ? void 0 : _this$props$editorAct2._privateUnsubscribe(() => this.subscribe(this.props));
239
+ }
240
+ componentDidMount() {
241
+ this.subscribe(this.props);
242
+ this.subscribeToContextUpdates();
243
+ }
244
+ UNSAFE_componentWillReceiveProps(nextProps) {
245
+ if (!this.isSubscribed) {
246
+ this.subscribe(nextProps);
247
+ }
248
+ }
249
+ componentWillUnmount() {
250
+ if (this.debounce) {
251
+ window.clearTimeout(this.debounce);
252
+ }
253
+ this.unsubscribeFromContextUpdates();
254
+ this.unsubscribe();
255
+ }
256
+ render() {
257
+ const {
258
+ render
259
+ } = this.props;
260
+ return render(this.state);
261
+ }
262
+ }
263
+ _defineProperty(WithPluginStateInner, "displayName", 'WithPluginState');
264
+ export class WithPluginStateOld extends React.Component {
53
265
  constructor(props, context) {
54
266
  super(props, context);
55
267
  _defineProperty(this, "listeners", {});
@@ -146,7 +358,7 @@ class WithPluginState extends React.Component {
146
358
  }, {});
147
359
  }
148
360
  subscribe(props) {
149
- var _uiTracking$samplingR, _uiTracking$slowThres;
361
+ var _uiTracking$samplingR2, _uiTracking$slowThres2;
150
362
  const plugins = props.plugins;
151
363
  const eventDispatcher = this.getEventDispatcher(props);
152
364
  const editorView = this.getEditorView(props);
@@ -166,8 +378,8 @@ class WithPluginState extends React.Component {
166
378
  const analyticsPlugin = fakePluginKey.getState(editorView.state);
167
379
  const uiTracking = analyticsPlugin && analyticsPlugin.performanceTracking ? analyticsPlugin.performanceTracking.uiTracking || {} : {};
168
380
  const trackingEnabled = uiTracking.enabled === true;
169
- const samplingRate = (_uiTracking$samplingR = uiTracking.samplingRate) !== null && _uiTracking$samplingR !== void 0 ? _uiTracking$samplingR : DEFAULT_SAMPLING_RATE;
170
- const slowThreshold = (_uiTracking$slowThres = uiTracking.slowThreshold) !== null && _uiTracking$slowThres !== void 0 ? _uiTracking$slowThres : DEFAULT_SLOW_THRESHOLD;
381
+ const samplingRate = (_uiTracking$samplingR2 = uiTracking.samplingRate) !== null && _uiTracking$samplingR2 !== void 0 ? _uiTracking$samplingR2 : DEFAULT_SAMPLING_RATE;
382
+ const slowThreshold = (_uiTracking$slowThres2 = uiTracking.slowThreshold) !== null && _uiTracking$slowThres2 !== void 0 ? _uiTracking$slowThres2 : DEFAULT_SLOW_THRESHOLD;
171
383
  this.isSubscribed = true;
172
384
  const pluginsStates = this.getPluginsStates(plugins, editorView);
173
385
  this.setState(pluginsStates);
@@ -244,8 +456,8 @@ class WithPluginState extends React.Component {
244
456
  return render(this.state);
245
457
  }
246
458
  }
247
- _defineProperty(WithPluginState, "displayName", 'WithPluginState');
248
- _defineProperty(WithPluginState, "contextTypes", {
459
+ _defineProperty(WithPluginStateOld, "displayName", 'WithPluginState');
460
+ _defineProperty(WithPluginStateOld, "contextTypes", {
249
461
  editorActions: PropTypes.object,
250
462
  editorSharedConfig: PropTypes.object
251
463
  });
@@ -7,7 +7,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
7
7
  import { isFedRamp } from './environment';
8
8
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
9
9
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
10
- var packageVersion = "93.4.3";
10
+ var packageVersion = "93.5.0";
11
11
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
12
12
  // Remove URL as it has UGC
13
13
  // TODO: Sanitise the URL instead of just removing it
@@ -21,7 +21,7 @@ import withAnalyticsContext from '@atlaskit/analytics-next/withAnalyticsContext'
21
21
  import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
22
22
  import Layer from '../Layer';
23
23
  var packageName = "@atlaskit/editor-common";
24
- var packageVersion = "93.4.3";
24
+ var packageVersion = "93.5.0";
25
25
  var halfFocusRing = 1;
26
26
  var dropOffset = '0, 8';
27
27
  var DropList = /*#__PURE__*/function (_Component) {
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export var EditorContext = /*#__PURE__*/React.createContext({});
@@ -10,7 +10,9 @@ import { css, jsx } from '@emotion/react';
10
10
  import withAnalyticsContext from '@atlaskit/analytics-next/withAnalyticsContext';
11
11
  import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
12
12
  import Button from '@atlaskit/button/standard-button';
13
- import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
13
+ import LegacyExpandIcon from '@atlaskit/icon/glyph/chevron-down';
14
+ import ChevronDownIcon from '@atlaskit/icon/utility/chevron-down';
15
+ import { Box, xcss } from '@atlaskit/primitives';
14
16
  import Tooltip from '@atlaskit/tooltip';
15
17
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, editorAnalyticsChannel, EVENT_TYPE } from '../../analytics';
16
18
  import { ColorPalette, DEFAULT_BORDER_COLOR, getSelectedRowAndColumnFromPalette } from '../../ui-color';
@@ -23,8 +25,11 @@ import { ArrowKeyNavigationType } from '../ArrowKeyNavigationProvider/types';
23
25
  var colorPickerButtonWrapper = css({
24
26
  position: 'relative'
25
27
  });
26
- var colorPickerExpandContainer = css({
27
- margin: "0px ".concat("var(--ds-space-negative-050, -4px)")
28
+ var colorPickerExpandContainer = xcss({
29
+ marginTop: 'space.0',
30
+ marginBottom: 'space.0',
31
+ marginLeft: 'space.negative.050',
32
+ marginRight: 'space.negative.050'
28
33
  });
29
34
 
30
35
  // Control the size of color picker buttons and preview
@@ -221,10 +226,13 @@ var ColorPickerButton = function ColorPickerButton(props) {
221
226
  // TODO: (from codemod) Buttons with "component", "css" or "style" prop can't be automatically migrated with codemods. Please migrate it manually.
222
227
  ,
223
228
  css: buttonStyle,
224
- iconAfter: jsx("span", {
225
- css: colorPickerExpandContainer
226
- }, jsx(ExpandIcon, {
227
- label: ""
229
+ iconAfter: jsx(Box, {
230
+ xcss: colorPickerExpandContainer
231
+ }, jsx(ChevronDownIcon, {
232
+ color: "currentColor",
233
+ spacing: "spacious",
234
+ LEGACY_fallbackIcon: LegacyExpandIcon,
235
+ label: "color-picker-chevron-down"
228
236
  })),
229
237
  "data-selected-color": props.currentColor
230
238
  })), renderPopup());
@@ -2,14 +2,14 @@
2
2
  * @jsxRuntime classic
3
3
  * @jsx jsx
4
4
  */
5
- /* eslint-disable no-console */
6
5
 
7
6
  import React, { useCallback, useLayoutEffect, useRef } from 'react';
8
7
 
9
8
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
10
9
  import { css, jsx } from '@emotion/react';
11
10
  import { ELEMENT_BROWSER_ID } from '../../element-browser';
12
- import { fullPageMessages as messages } from '../../messages';
11
+ import { fullPageMessages } from '../../messages';
12
+ import { mediaInsertMessages } from '../../messages/media-insert';
13
13
  import { EDIT_AREA_ID } from '../../ui';
14
14
  /*
15
15
  ** The context is used to handle the keydown events of submenus.
@@ -135,6 +135,11 @@ export var ToolbarArrowKeyNavigationProvider = function ToolbarArrowKeyNavigatio
135
135
  if (!filteredFocusableElements || (filteredFocusableElements === null || filteredFocusableElements === void 0 ? void 0 : filteredFocusableElements.length) === 0) {
136
136
  return;
137
137
  }
138
+
139
+ // If the target element is the media picker then navigation is handled by the media picker
140
+ if (targetElement instanceof HTMLElement && targetElement.closest("[aria-label=\"".concat(intl.formatMessage(mediaInsertMessages.mediaPickerPopupAriaLabel), "\"]"))) {
141
+ return;
142
+ }
138
143
  if (targetElement instanceof HTMLElement && !((_wrapperRef$current2 = wrapperRef.current) !== null && _wrapperRef$current2 !== void 0 && _wrapperRef$current2.contains(targetElement))) {
139
144
  selectedItemIndex.current = -1;
140
145
  } else {
@@ -187,7 +192,7 @@ export var ToolbarArrowKeyNavigationProvider = function ToolbarArrowKeyNavigatio
187
192
  editorViewDom === null || editorViewDom === void 0 || editorViewDom.removeEventListener('keydown', globalKeyDownHandler);
188
193
  }
189
194
  };
190
- }, [selectedItemIndex, wrapperRef, editorView, disableArrowKeyNavigation, handleEscape, childComponentSelector, incrementIndex, decrementIndex, isShortcutToFocusToolbar, editorAppearance, useStickyToolbar]);
195
+ }, [selectedItemIndex, wrapperRef, editorView, disableArrowKeyNavigation, handleEscape, childComponentSelector, incrementIndex, decrementIndex, isShortcutToFocusToolbar, editorAppearance, useStickyToolbar, intl]);
191
196
  return jsx("div", {
192
197
  css: editorAppearance === 'comment' && centeredToolbarContainer
193
198
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
@@ -195,7 +200,7 @@ export var ToolbarArrowKeyNavigationProvider = function ToolbarArrowKeyNavigatio
195
200
  className: "custom-key-handler-wrapper",
196
201
  ref: wrapperRef,
197
202
  role: "toolbar",
198
- "aria-label": intl.formatMessage(messages.toolbarLabel),
203
+ "aria-label": intl.formatMessage(fullPageMessages.toolbarLabel),
199
204
  "aria-controls": EDIT_AREA_ID
200
205
  }, jsx(KeyDownHandlerContext.Provider, {
201
206
  value: submenuKeydownHandleContext