@atlaskit/editor-common 109.16.2 → 110.1.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 (32) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/cjs/monitoring/error.js +1 -1
  3. package/dist/cjs/toolbar/index.js +6 -0
  4. package/dist/cjs/toolbar/keys.js +6 -2
  5. package/dist/cjs/ui/DropList/index.js +1 -1
  6. package/dist/cjs/utils/commands.js +32 -0
  7. package/dist/es2019/monitoring/error.js +1 -1
  8. package/dist/es2019/toolbar/index.js +1 -1
  9. package/dist/es2019/toolbar/keys.js +4 -0
  10. package/dist/es2019/ui/DropList/index.js +1 -1
  11. package/dist/es2019/utils/commands.js +34 -0
  12. package/dist/esm/monitoring/error.js +1 -1
  13. package/dist/esm/toolbar/index.js +1 -1
  14. package/dist/esm/toolbar/keys.js +4 -0
  15. package/dist/esm/ui/DropList/index.js +1 -1
  16. package/dist/esm/utils/commands.js +32 -0
  17. package/dist/types/toolbar/index.d.ts +1 -1
  18. package/dist/types/toolbar/keys.d.ts +4 -0
  19. package/dist/types-ts4.5/toolbar/index.d.ts +1 -1
  20. package/dist/types-ts4.5/toolbar/keys.d.ts +4 -0
  21. package/package.json +9 -6
  22. package/dist/cjs/with-plugin-state/index.js +0 -350
  23. package/dist/cjs/with-plugin-state/types.js +0 -5
  24. package/dist/es2019/with-plugin-state/index.js +0 -295
  25. package/dist/es2019/with-plugin-state/types.js +0 -1
  26. package/dist/esm/with-plugin-state/index.js +0 -344
  27. package/dist/esm/with-plugin-state/types.js +0 -1
  28. package/dist/types/with-plugin-state/index.d.ts +0 -101
  29. package/dist/types/with-plugin-state/types.d.ts +0 -10
  30. package/dist/types-ts4.5/with-plugin-state/index.d.ts +0 -101
  31. package/dist/types-ts4.5/with-plugin-state/types.d.ts +0 -10
  32. package/with-plugin-state/package.json +0 -17
@@ -1,350 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.WithPluginStateInner = exports.WithPluginState = void 0;
8
- var _readOnlyError2 = _interopRequireDefault(require("@babel/runtime/helpers/readOnlyError"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
15
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
16
- var _react = _interopRequireDefault(require("react"));
17
- var _analytics = require("../analytics");
18
- var _eventDispatcher = require("../event-dispatcher");
19
- var _performanceMeasures = require("../performance-measures");
20
- var _EditorContext = require("../ui/EditorContext");
21
- var _utils = require("../utils");
22
- 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; }
23
- 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; }
24
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
25
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
26
- var DEFAULT_SAMPLING_RATE = 100;
27
- var DEFAULT_SLOW_THRESHOLD = 4;
28
-
29
- // That context was extract from the old WithPluginState from editor-core
30
- // It was using some private types from
31
- // - EditorAction: packages/editor/editor-core/src/actions/index.ts
32
- // - EditorSharedConfig: packages/editor/editor-core/src/labs/next/internal/context/shared-config.tsx
33
- /**
34
- * @private
35
- * @deprecated
36
- *
37
- * Using this component is deprecated. It should be replaced with `useSharedPluginState`.
38
- * This requires having access to the injection API from the plugin itself.
39
- *
40
- * An example of the refactor with the new hook (using hyperlink as an example) is:
41
- *
42
- * Before:
43
- * ```ts
44
- * <WithPluginState
45
- * editorView={editorView}
46
- * plugins={{
47
- * hyperlinkState: hyperlinkPluginKey
48
- * }}
49
- * render={({ hyperlinkState }) =>
50
- * renderComponent({ hyperlinkState })
51
- * }
52
- * />
53
- * ```
54
- *
55
- * After:
56
- * ```ts
57
- * import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
58
- * import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
59
- *
60
- * function ComponentWithState(
61
- * api: ExtractInjectionAPI<typeof hyperlinkPlugin> | undefined
62
- * ) {
63
- * const { hyperlinkState } = useSharedPluginState(api, ['hyperlink']);
64
- * return renderComponent({ hyperlinkState })
65
- * }
66
- * ```
67
- *
68
- */
69
- // Ignored via go/ees005
70
- // eslint-disable-next-line @repo/internal/react/no-class-components, react/prefer-stateless-function
71
- var WithPluginState = exports.WithPluginState = /*#__PURE__*/function (_React$Component) {
72
- function WithPluginState(props) {
73
- (0, _classCallCheck2.default)(this, WithPluginState);
74
- return _callSuper(this, WithPluginState, [props]);
75
- }
76
- (0, _inherits2.default)(WithPluginState, _React$Component);
77
- return (0, _createClass2.default)(WithPluginState, [{
78
- key: "render",
79
- value: function render() {
80
- // Ignored via go/ees005
81
- // eslint-disable-next-line react/jsx-props-no-spreading
82
- return /*#__PURE__*/_react.default.createElement(WithPluginStateEditionActionsWrapper, this.props);
83
- }
84
- }]);
85
- }(_react.default.Component);
86
- function WithPluginStateEditionActionsWrapper(props) {
87
- var context = _react.default.useContext(_EditorContext.EditorContext);
88
- return /*#__PURE__*/_react.default.createElement(WithPluginStateInner
89
- // Ignored via go/ees005
90
- // eslint-disable-next-line react/jsx-props-no-spreading
91
- , (0, _extends2.default)({}, props, {
92
- editorActions: context === null || context === void 0 ? void 0 : context.editorActions
93
- }));
94
- }
95
- // Ignored via go/ees005
96
- // eslint-disable-next-line @repo/internal/react/no-class-components
97
- var WithPluginStateInner = exports.WithPluginStateInner = /*#__PURE__*/function (_React$Component2) {
98
- function WithPluginStateInner(props) {
99
- var _this;
100
- (0, _classCallCheck2.default)(this, WithPluginStateInner);
101
- _this = _callSuper(this, WithPluginStateInner, [props]);
102
- (0, _defineProperty2.default)(_this, "listeners", {});
103
- (0, _defineProperty2.default)(_this, "debounce", null);
104
- (0, _defineProperty2.default)(_this, "notAppliedState", {});
105
- (0, _defineProperty2.default)(_this, "isSubscribed", false);
106
- (0, _defineProperty2.default)(_this, "callsCount", 0);
107
- (0, _defineProperty2.default)(_this, "handlePluginStateChange", function (propName, pluginName, performanceOptions, skipEqualityCheck) {
108
- return (
109
- // Ignored via go/ees005
110
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
- function (pluginState) {
112
- // skipEqualityCheck is being used for old plugins since they are mutating plugin state instead of creating a new one
113
- // Ignored via go/ees005
114
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
- if (_this.state[propName] !== pluginState || skipEqualityCheck) {
116
- _this.updateState({
117
- stateSubset: (0, _defineProperty2.default)({}, propName, pluginState),
118
- pluginName: pluginName,
119
- performanceOptions: performanceOptions
120
- });
121
- }
122
- }
123
- );
124
- });
125
- /**
126
- * Debounces setState calls in order to reduce number of re-renders caused by several plugin state changes.
127
- */
128
- (0, _defineProperty2.default)(_this, "updateState", function (_ref) {
129
- var stateSubset = _ref.stateSubset,
130
- pluginName = _ref.pluginName,
131
- performanceOptions = _ref.performanceOptions;
132
- _this.notAppliedState = _objectSpread(_objectSpread({}, _this.notAppliedState), stateSubset);
133
- if (_this.debounce) {
134
- window.clearTimeout(_this.debounce);
135
- }
136
- var debounce = _this.props.debounce !== false ? function (fn) {
137
- return window.setTimeout(fn, 0);
138
- } : function (fn) {
139
- return fn();
140
- };
141
- _this.debounce = debounce(function () {
142
- var measure = "\uD83E\uDD89".concat(pluginName, "::WithPluginState");
143
- performanceOptions.trackingEnabled && (0, _performanceMeasures.startMeasure)(measure);
144
- _this.setState(_this.notAppliedState, function () {
145
- performanceOptions.trackingEnabled && (0, _performanceMeasures.stopMeasure)(measure, function (duration) {
146
- // Each WithPluginState component will fire analytics event no more than once every `samplingLimit` times
147
- if (++_this.callsCount % performanceOptions.samplingRate === 0 && duration > performanceOptions.slowThreshold) {
148
- _this.dispatchAnalyticsEvent({
149
- action: _analytics.ACTION.WITH_PLUGIN_STATE_CALLED,
150
- actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
151
- eventType: _analytics.EVENT_TYPE.OPERATIONAL,
152
- attributes: {
153
- plugin: pluginName,
154
- duration: duration
155
- }
156
- });
157
- }
158
- });
159
- });
160
- _this.debounce = null;
161
- _this.notAppliedState = {};
162
- });
163
- });
164
- (0, _defineProperty2.default)(_this, "dispatchAnalyticsEvent", function (payload) {
165
- var eventDispatcher = _this.getEventDispatcher();
166
- if (eventDispatcher) {
167
- var dispatch = (0, _eventDispatcher.createDispatch)(eventDispatcher);
168
- dispatch(_utils.analyticsEventKey, {
169
- payload: payload
170
- });
171
- }
172
- });
173
- _this.state = _this.getPluginsStates(_this.props.plugins, _this.getEditorView(props));
174
- return _this;
175
- }
176
- (0, _inherits2.default)(WithPluginStateInner, _React$Component2);
177
- return (0, _createClass2.default)(WithPluginStateInner, [{
178
- key: "getEditorView",
179
- value: function getEditorView(maybeProps) {
180
- var props = maybeProps || this.props;
181
- var editorActions = props.editorActions;
182
- return props.editorView || (editorActions === null || editorActions === void 0 ? void 0 : editorActions._privateGetEditorView());
183
- }
184
- }, {
185
- key: "getEventDispatcher",
186
- value: function getEventDispatcher(maybeProps) {
187
- var _props$editorActions;
188
- var props = maybeProps || this.props;
189
- return props.eventDispatcher || ((_props$editorActions = props.editorActions) === null || _props$editorActions === void 0 ? void 0 : _props$editorActions._privateGetEventDispatcher());
190
- }
191
- }, {
192
- key: "getPluginsStates",
193
- value: function getPluginsStates(plugins, editorView) {
194
- if (!editorView || !plugins) {
195
- return {};
196
- }
197
- var keys = Object.keys(plugins);
198
- return keys.reduce(function (acc, propName) {
199
- var pluginKey = plugins[propName];
200
- if (!pluginKey) {
201
- return acc;
202
- }
203
- acc[propName] = pluginKey.getState(editorView.state);
204
- return acc;
205
- }, {});
206
- }
207
- }, {
208
- key: "subscribe",
209
- value: function subscribe(props) {
210
- var _uiTracking$samplingR,
211
- _uiTracking$slowThres,
212
- _this2 = this;
213
- var plugins = props.plugins;
214
- var eventDispatcher = this.getEventDispatcher(props);
215
- var editorView = this.getEditorView(props);
216
- if (!eventDispatcher || !editorView || this.isSubscribed) {
217
- return;
218
- }
219
-
220
- // Please, do not copy or use this kind of code below
221
- // @ts-ignore
222
- var fakePluginKey = {
223
- key: 'analyticsPlugin$',
224
- getState: function getState(state) {
225
- // Ignored via go/ees005
226
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
227
- return state['analyticsPlugin$'];
228
- }
229
- };
230
- var analyticsPlugin = fakePluginKey.getState(editorView.state);
231
- var uiTracking = analyticsPlugin && analyticsPlugin.performanceTracking ? analyticsPlugin.performanceTracking.uiTracking || {} : {};
232
- var trackingEnabled = uiTracking.enabled === true;
233
- var samplingRate = (_uiTracking$samplingR = uiTracking.samplingRate) !== null && _uiTracking$samplingR !== void 0 ? _uiTracking$samplingR : DEFAULT_SAMPLING_RATE;
234
- var slowThreshold = (_uiTracking$slowThres = uiTracking.slowThreshold) !== null && _uiTracking$slowThres !== void 0 ? _uiTracking$slowThres : DEFAULT_SLOW_THRESHOLD;
235
- this.isSubscribed = true;
236
- var pluginsStates = this.getPluginsStates(plugins, editorView);
237
- this.setState(pluginsStates);
238
- Object.keys(plugins).forEach(function (propName) {
239
- var pluginKey = plugins[propName];
240
- if (!pluginKey) {
241
- return;
242
- }
243
-
244
- // Ignored via go/ees005
245
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
246
- var pluginName = pluginKey.key;
247
- // Ignored via go/ees005
248
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
249
- var pluginState = pluginsStates[propName];
250
- var isPluginWithSubscribe = pluginState && pluginState.subscribe;
251
- var handler = _this2.handlePluginStateChange(propName, pluginName, {
252
- samplingRate: samplingRate,
253
- slowThreshold: slowThreshold,
254
- trackingEnabled: trackingEnabled
255
- }, isPluginWithSubscribe);
256
- if (isPluginWithSubscribe) {
257
- pluginState.subscribe(handler);
258
- } else {
259
- // Ignored via go/ees005
260
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
261
- eventDispatcher.on(pluginKey.key, handler);
262
- }
263
-
264
- // Ignored via go/ees005
265
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
266
- // Ignored via go/ees005
267
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
268
- _this2.listeners[pluginKey.key] = {
269
- handler: handler,
270
- pluginKey: pluginKey
271
- };
272
- });
273
- }
274
- }, {
275
- key: "unsubscribe",
276
- value: function unsubscribe() {
277
- var _this3 = this;
278
- var eventDispatcher = this.getEventDispatcher();
279
- var editorView = this.getEditorView();
280
- if (!eventDispatcher || !editorView || !this.isSubscribed) {
281
- return;
282
- }
283
- Object.keys(this.listeners).forEach(function (key) {
284
- // Ignored via go/ees005
285
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
286
- var pluginState = _this3.listeners[key].pluginKey.getState(editorView.state);
287
- if (pluginState && pluginState.unsubscribe) {
288
- // Ignored via go/ees005
289
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
290
- pluginState.unsubscribe(_this3.listeners[key].handler);
291
- } else {
292
- // Ignored via go/ees005
293
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
294
- eventDispatcher.off(key, _this3.listeners[key].handler);
295
- }
296
- });
297
- this.listeners = [];
298
- }
299
- }, {
300
- key: "subscribeToContextUpdates",
301
- value: function subscribeToContextUpdates() {
302
- var _this$props$editorAct,
303
- _this4 = this;
304
- (_this$props$editorAct = this.props.editorActions) === null || _this$props$editorAct === void 0 || _this$props$editorAct._privateSubscribe(function () {
305
- return _this4.subscribe(_this4.props);
306
- });
307
- }
308
- }, {
309
- key: "unsubscribeFromContextUpdates",
310
- value: function unsubscribeFromContextUpdates() {
311
- var _this$props$editorAct2,
312
- _this5 = this;
313
- (_this$props$editorAct2 = this.props.editorActions) === null || _this$props$editorAct2 === void 0 || _this$props$editorAct2._privateUnsubscribe(function () {
314
- return _this5.subscribe(_this5.props);
315
- });
316
- }
317
- }, {
318
- key: "componentDidMount",
319
- value: function componentDidMount() {
320
- this.subscribe(this.props);
321
- this.subscribeToContextUpdates();
322
- }
323
-
324
- // Ignored via go/ees005
325
- // eslint-disable-next-line react/no-unsafe
326
- }, {
327
- key: "UNSAFE_componentWillReceiveProps",
328
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
329
- if (!this.isSubscribed) {
330
- this.subscribe(nextProps);
331
- }
332
- }
333
- }, {
334
- key: "componentWillUnmount",
335
- value: function componentWillUnmount() {
336
- if (this.debounce) {
337
- window.clearTimeout(this.debounce);
338
- }
339
- this.unsubscribeFromContextUpdates();
340
- this.unsubscribe();
341
- }
342
- }, {
343
- key: "render",
344
- value: function render() {
345
- var render = this.props.render;
346
- return render(this.state);
347
- }
348
- }]);
349
- }(_react.default.Component);
350
- (0, _defineProperty2.default)(WithPluginStateInner, "displayName", 'WithPluginState');
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,295 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _extends from "@babel/runtime/helpers/extends";
3
- import React from 'react';
4
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '../analytics';
5
- import { createDispatch } from '../event-dispatcher';
6
- import { startMeasure, stopMeasure } from '../performance-measures';
7
- import { EditorContext } from '../ui/EditorContext';
8
- import { analyticsEventKey } from '../utils';
9
- const DEFAULT_SAMPLING_RATE = 100;
10
- const DEFAULT_SLOW_THRESHOLD = 4;
11
-
12
- // That context was extract from the old WithPluginState from editor-core
13
- // It was using some private types from
14
- // - EditorAction: packages/editor/editor-core/src/actions/index.ts
15
- // - EditorSharedConfig: packages/editor/editor-core/src/labs/next/internal/context/shared-config.tsx
16
-
17
- /**
18
- * @private
19
- * @deprecated
20
- *
21
- * Using this component is deprecated. It should be replaced with `useSharedPluginState`.
22
- * This requires having access to the injection API from the plugin itself.
23
- *
24
- * An example of the refactor with the new hook (using hyperlink as an example) is:
25
- *
26
- * Before:
27
- * ```ts
28
- * <WithPluginState
29
- * editorView={editorView}
30
- * plugins={{
31
- * hyperlinkState: hyperlinkPluginKey
32
- * }}
33
- * render={({ hyperlinkState }) =>
34
- * renderComponent({ hyperlinkState })
35
- * }
36
- * />
37
- * ```
38
- *
39
- * After:
40
- * ```ts
41
- * import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
42
- * import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
43
- *
44
- * function ComponentWithState(
45
- * api: ExtractInjectionAPI<typeof hyperlinkPlugin> | undefined
46
- * ) {
47
- * const { hyperlinkState } = useSharedPluginState(api, ['hyperlink']);
48
- * return renderComponent({ hyperlinkState })
49
- * }
50
- * ```
51
- *
52
- */
53
- // Ignored via go/ees005
54
- // eslint-disable-next-line @repo/internal/react/no-class-components, react/prefer-stateless-function
55
- class WithPluginState extends React.Component {
56
- constructor(props) {
57
- super(props);
58
- }
59
- render() {
60
- // Ignored via go/ees005
61
- // eslint-disable-next-line react/jsx-props-no-spreading
62
- return /*#__PURE__*/React.createElement(WithPluginStateEditionActionsWrapper, this.props);
63
- }
64
- }
65
- function WithPluginStateEditionActionsWrapper(props) {
66
- const context = React.useContext(EditorContext);
67
- return /*#__PURE__*/React.createElement(WithPluginStateInner
68
- // Ignored via go/ees005
69
- // eslint-disable-next-line react/jsx-props-no-spreading
70
- , _extends({}, props, {
71
- editorActions: context === null || context === void 0 ? void 0 : context.editorActions
72
- }));
73
- }
74
- // Ignored via go/ees005
75
- // eslint-disable-next-line @repo/internal/react/no-class-components
76
- export class WithPluginStateInner extends React.Component {
77
- constructor(props) {
78
- super(props);
79
- _defineProperty(this, "listeners", {});
80
- _defineProperty(this, "debounce", null);
81
- _defineProperty(this, "notAppliedState", {});
82
- _defineProperty(this, "isSubscribed", false);
83
- _defineProperty(this, "callsCount", 0);
84
- _defineProperty(this, "handlePluginStateChange", (propName, pluginName, performanceOptions, skipEqualityCheck) =>
85
- // Ignored via go/ees005
86
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- pluginState => {
88
- // skipEqualityCheck is being used for old plugins since they are mutating plugin state instead of creating a new one
89
- // Ignored via go/ees005
90
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
- if (this.state[propName] !== pluginState || skipEqualityCheck) {
92
- this.updateState({
93
- stateSubset: {
94
- [propName]: pluginState
95
- },
96
- pluginName,
97
- performanceOptions
98
- });
99
- }
100
- });
101
- /**
102
- * Debounces setState calls in order to reduce number of re-renders caused by several plugin state changes.
103
- */
104
- _defineProperty(this, "updateState", ({
105
- stateSubset,
106
- pluginName,
107
- performanceOptions
108
- }) => {
109
- this.notAppliedState = {
110
- ...this.notAppliedState,
111
- ...stateSubset
112
- };
113
- if (this.debounce) {
114
- window.clearTimeout(this.debounce);
115
- }
116
- const debounce = this.props.debounce !== false ? fn => window.setTimeout(fn, 0) : fn => fn();
117
- this.debounce = debounce(() => {
118
- const measure = `🦉${pluginName}::WithPluginState`;
119
- performanceOptions.trackingEnabled && startMeasure(measure);
120
- this.setState(this.notAppliedState, () => {
121
- performanceOptions.trackingEnabled && stopMeasure(measure, duration => {
122
- // Each WithPluginState component will fire analytics event no more than once every `samplingLimit` times
123
- if (++this.callsCount % performanceOptions.samplingRate === 0 && duration > performanceOptions.slowThreshold) {
124
- this.dispatchAnalyticsEvent({
125
- action: ACTION.WITH_PLUGIN_STATE_CALLED,
126
- actionSubject: ACTION_SUBJECT.EDITOR,
127
- eventType: EVENT_TYPE.OPERATIONAL,
128
- attributes: {
129
- plugin: pluginName,
130
- duration
131
- }
132
- });
133
- }
134
- });
135
- });
136
- this.debounce = null;
137
- this.notAppliedState = {};
138
- });
139
- });
140
- _defineProperty(this, "dispatchAnalyticsEvent", payload => {
141
- const eventDispatcher = this.getEventDispatcher();
142
- if (eventDispatcher) {
143
- const dispatch = createDispatch(eventDispatcher);
144
- dispatch(analyticsEventKey, {
145
- payload
146
- });
147
- }
148
- });
149
- this.state = this.getPluginsStates(this.props.plugins, this.getEditorView(props));
150
- }
151
- getEditorView(maybeProps) {
152
- const props = maybeProps || this.props;
153
- const editorActions = props.editorActions;
154
- return props.editorView || (editorActions === null || editorActions === void 0 ? void 0 : editorActions._privateGetEditorView());
155
- }
156
- getEventDispatcher(maybeProps) {
157
- var _props$editorActions;
158
- const props = maybeProps || this.props;
159
- return props.eventDispatcher || ((_props$editorActions = props.editorActions) === null || _props$editorActions === void 0 ? void 0 : _props$editorActions._privateGetEventDispatcher());
160
- }
161
- getPluginsStates(plugins, editorView) {
162
- if (!editorView || !plugins) {
163
- return {};
164
- }
165
- const keys = Object.keys(plugins);
166
- return keys.reduce((acc, propName) => {
167
- const pluginKey = plugins[propName];
168
- if (!pluginKey) {
169
- return acc;
170
- }
171
- acc[propName] = pluginKey.getState(editorView.state);
172
- return acc;
173
- }, {});
174
- }
175
- subscribe(props) {
176
- var _uiTracking$samplingR, _uiTracking$slowThres;
177
- const plugins = props.plugins;
178
- const eventDispatcher = this.getEventDispatcher(props);
179
- const editorView = this.getEditorView(props);
180
- if (!eventDispatcher || !editorView || this.isSubscribed) {
181
- return;
182
- }
183
-
184
- // Please, do not copy or use this kind of code below
185
- // @ts-ignore
186
- const fakePluginKey = {
187
- key: 'analyticsPlugin$',
188
- getState: state => {
189
- // Ignored via go/ees005
190
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
191
- return state['analyticsPlugin$'];
192
- }
193
- };
194
- const analyticsPlugin = fakePluginKey.getState(editorView.state);
195
- const uiTracking = analyticsPlugin && analyticsPlugin.performanceTracking ? analyticsPlugin.performanceTracking.uiTracking || {} : {};
196
- const trackingEnabled = uiTracking.enabled === true;
197
- const samplingRate = (_uiTracking$samplingR = uiTracking.samplingRate) !== null && _uiTracking$samplingR !== void 0 ? _uiTracking$samplingR : DEFAULT_SAMPLING_RATE;
198
- const slowThreshold = (_uiTracking$slowThres = uiTracking.slowThreshold) !== null && _uiTracking$slowThres !== void 0 ? _uiTracking$slowThres : DEFAULT_SLOW_THRESHOLD;
199
- this.isSubscribed = true;
200
- const pluginsStates = this.getPluginsStates(plugins, editorView);
201
- this.setState(pluginsStates);
202
- Object.keys(plugins).forEach(propName => {
203
- const pluginKey = plugins[propName];
204
- if (!pluginKey) {
205
- return;
206
- }
207
-
208
- // Ignored via go/ees005
209
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
210
- const pluginName = pluginKey.key;
211
- // Ignored via go/ees005
212
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
- const pluginState = pluginsStates[propName];
214
- const isPluginWithSubscribe = pluginState && pluginState.subscribe;
215
- const handler = this.handlePluginStateChange(propName, pluginName, {
216
- samplingRate,
217
- slowThreshold,
218
- trackingEnabled
219
- }, isPluginWithSubscribe);
220
- if (isPluginWithSubscribe) {
221
- pluginState.subscribe(handler);
222
- } else {
223
- // Ignored via go/ees005
224
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
225
- eventDispatcher.on(pluginKey.key, handler);
226
- }
227
-
228
- // Ignored via go/ees005
229
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
- // Ignored via go/ees005
231
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
232
- this.listeners[pluginKey.key] = {
233
- handler,
234
- pluginKey
235
- };
236
- });
237
- }
238
- unsubscribe() {
239
- const eventDispatcher = this.getEventDispatcher();
240
- const editorView = this.getEditorView();
241
- if (!eventDispatcher || !editorView || !this.isSubscribed) {
242
- return;
243
- }
244
- Object.keys(this.listeners).forEach(key => {
245
- // Ignored via go/ees005
246
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
247
- const pluginState = this.listeners[key].pluginKey.getState(editorView.state);
248
- if (pluginState && pluginState.unsubscribe) {
249
- // Ignored via go/ees005
250
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
251
- pluginState.unsubscribe(this.listeners[key].handler);
252
- } else {
253
- // Ignored via go/ees005
254
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
255
- eventDispatcher.off(key, this.listeners[key].handler);
256
- }
257
- });
258
- this.listeners = [];
259
- }
260
- subscribeToContextUpdates() {
261
- var _this$props$editorAct;
262
- (_this$props$editorAct = this.props.editorActions) === null || _this$props$editorAct === void 0 ? void 0 : _this$props$editorAct._privateSubscribe(() => this.subscribe(this.props));
263
- }
264
- unsubscribeFromContextUpdates() {
265
- var _this$props$editorAct2;
266
- (_this$props$editorAct2 = this.props.editorActions) === null || _this$props$editorAct2 === void 0 ? void 0 : _this$props$editorAct2._privateUnsubscribe(() => this.subscribe(this.props));
267
- }
268
- componentDidMount() {
269
- this.subscribe(this.props);
270
- this.subscribeToContextUpdates();
271
- }
272
-
273
- // Ignored via go/ees005
274
- // eslint-disable-next-line react/no-unsafe
275
- UNSAFE_componentWillReceiveProps(nextProps) {
276
- if (!this.isSubscribed) {
277
- this.subscribe(nextProps);
278
- }
279
- }
280
- componentWillUnmount() {
281
- if (this.debounce) {
282
- window.clearTimeout(this.debounce);
283
- }
284
- this.unsubscribeFromContextUpdates();
285
- this.unsubscribe();
286
- }
287
- render() {
288
- const {
289
- render
290
- } = this.props;
291
- return render(this.state);
292
- }
293
- }
294
- _defineProperty(WithPluginStateInner, "displayName", 'WithPluginState');
295
- export { WithPluginState };
@@ -1 +0,0 @@
1
- export {};