@atlaskit/editor-common 109.16.2 → 110.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-common
2
2
 
3
+ ## 110.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`dd82243801213`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/dd82243801213) -
8
+ Delete WithPluginState
9
+
10
+ ### Minor Changes
11
+
12
+ - [`133f7636e3a6c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/133f7636e3a6c) -
13
+ [ux] EDITOR-1750 Refactoring and improving delete key behaviours for block task item
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+
3
19
  ## 109.16.2
4
20
 
5
21
  ### Patch Changes
@@ -16,7 +16,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
16
16
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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 = "109.16.1";
19
+ var packageVersion = "109.16.2";
20
20
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
21
21
  // Remove URL as it has UGC
22
22
  // Ignored via go/ees007
@@ -24,7 +24,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
24
24
  * @jsx jsx
25
25
  */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
26
26
  var packageName = "@atlaskit/editor-common";
27
- var packageVersion = "109.16.1";
27
+ var packageVersion = "109.16.2";
28
28
  var halfFocusRing = 1;
29
29
  var dropOffset = '0, 8';
30
30
  var fadeIn = (0, _react2.keyframes)({
@@ -328,8 +328,40 @@ var isEmptySelectionAtStart = exports.isEmptySelectionAtStart = function isEmpty
328
328
  return empty && ($from.parentOffset === 0 || state.selection instanceof _selection.GapCursorSelection);
329
329
  };
330
330
  var isEmptySelectionAtEnd = exports.isEmptySelectionAtEnd = function isEmptySelectionAtEnd(state) {
331
+ var blockTaskItem = state.schema.nodes.blockTaskItem;
331
332
  var _state$selection5 = state.selection,
332
333
  empty = _state$selection5.empty,
333
334
  $from = _state$selection5.$from;
335
+
336
+ // If blockTaskItem is in the schema,
337
+ // we need to check if the selection is inside a blockTaskItem
338
+ if (blockTaskItem && empty && (0, _platformFeatureFlags.fg)('platform_editor_blocktaskitem_patch_3')) {
339
+ // If the parent is in a textblock,
340
+ // check if it's nested inside a blockTaskItem
341
+ if ($from.parent.isTextblock) {
342
+ var $posAtEndOfTextBlock = state.doc.resolve($from.end($from.depth - 1));
343
+ var parentOfTextBlock = $posAtEndOfTextBlock.parent;
344
+
345
+ // If the parent of the textblock is a blockTaskItem,
346
+ // we need to know if the textblock is the last node in the blockTaskItem
347
+ if (parentOfTextBlock.type === blockTaskItem) {
348
+ var lastChildOfBlockTaskItem = parentOfTextBlock.lastChild;
349
+ if (lastChildOfBlockTaskItem === $from.parent) {
350
+ // If the textblock is the last node in the blockTaskItem,
351
+ // check if the selection is at the end of the textblock
352
+ var lastTextPosInTextBlock = $from.end($from.depth);
353
+ return $from.pos === lastTextPosInTextBlock;
354
+ } else {
355
+ return false;
356
+ }
357
+ }
358
+ }
359
+ // Else, check if the parent is a blockTaskItem
360
+ else if ($from.parent.type === blockTaskItem) {
361
+ // Check if the selection is at the end of the blockTaskItem
362
+ var lastPosInBlockTaskItem = $from.end();
363
+ return $from.pos === lastPosInBlockTaskItem;
364
+ }
365
+ }
334
366
  return empty && ($from.end() === $from.pos || state.selection instanceof _selection.GapCursorSelection);
335
367
  };
@@ -1,7 +1,7 @@
1
1
  import { isFedRamp } from './environment';
2
2
  const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
3
3
  const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
4
- const packageVersion = "109.16.1";
4
+ const packageVersion = "109.16.2";
5
5
  const sanitiseSentryEvents = (data, _hint) => {
6
6
  // Remove URL as it has UGC
7
7
  // Ignored via go/ees007
@@ -14,7 +14,7 @@ import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
14
14
  import { fg } from '@atlaskit/platform-feature-flags';
15
15
  import Layer from '../Layer';
16
16
  const packageName = "@atlaskit/editor-common";
17
- const packageVersion = "109.16.1";
17
+ const packageVersion = "109.16.2";
18
18
  const halfFocusRing = 1;
19
19
  const dropOffset = '0, 8';
20
20
  const fadeIn = keyframes({
@@ -331,10 +331,44 @@ export const isEmptySelectionAtStart = state => {
331
331
  return empty && ($from.parentOffset === 0 || state.selection instanceof GapCursorSelection);
332
332
  };
333
333
  export const isEmptySelectionAtEnd = state => {
334
+ const {
335
+ blockTaskItem
336
+ } = state.schema.nodes;
334
337
  const {
335
338
  empty,
336
339
  $from
337
340
  } = state.selection;
341
+
342
+ // If blockTaskItem is in the schema,
343
+ // we need to check if the selection is inside a blockTaskItem
344
+ if (blockTaskItem && empty && fg('platform_editor_blocktaskitem_patch_3')) {
345
+ // If the parent is in a textblock,
346
+ // check if it's nested inside a blockTaskItem
347
+ if ($from.parent.isTextblock) {
348
+ const $posAtEndOfTextBlock = state.doc.resolve($from.end($from.depth - 1));
349
+ const parentOfTextBlock = $posAtEndOfTextBlock.parent;
350
+
351
+ // If the parent of the textblock is a blockTaskItem,
352
+ // we need to know if the textblock is the last node in the blockTaskItem
353
+ if (parentOfTextBlock.type === blockTaskItem) {
354
+ const lastChildOfBlockTaskItem = parentOfTextBlock.lastChild;
355
+ if (lastChildOfBlockTaskItem === $from.parent) {
356
+ // If the textblock is the last node in the blockTaskItem,
357
+ // check if the selection is at the end of the textblock
358
+ const lastTextPosInTextBlock = $from.end($from.depth);
359
+ return $from.pos === lastTextPosInTextBlock;
360
+ } else {
361
+ return false;
362
+ }
363
+ }
364
+ }
365
+ // Else, check if the parent is a blockTaskItem
366
+ else if ($from.parent.type === blockTaskItem) {
367
+ // Check if the selection is at the end of the blockTaskItem
368
+ const lastPosInBlockTaskItem = $from.end();
369
+ return $from.pos === lastPosInBlockTaskItem;
370
+ }
371
+ }
338
372
  return empty && ($from.end() === $from.pos || state.selection instanceof GapCursorSelection);
339
373
  };
340
374
  export { filter as filterCommand };
@@ -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 = "109.16.1";
10
+ var packageVersion = "109.16.2";
11
11
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
12
12
  // Remove URL as it has UGC
13
13
  // Ignored via go/ees007
@@ -21,7 +21,7 @@ import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
21
21
  import { fg } from '@atlaskit/platform-feature-flags';
22
22
  import Layer from '../Layer';
23
23
  var packageName = "@atlaskit/editor-common";
24
- var packageVersion = "109.16.1";
24
+ var packageVersion = "109.16.2";
25
25
  var halfFocusRing = 1;
26
26
  var dropOffset = '0, 8';
27
27
  var fadeIn = keyframes({
@@ -315,9 +315,41 @@ export var isEmptySelectionAtStart = function isEmptySelectionAtStart(state) {
315
315
  return empty && ($from.parentOffset === 0 || state.selection instanceof GapCursorSelection);
316
316
  };
317
317
  export var isEmptySelectionAtEnd = function isEmptySelectionAtEnd(state) {
318
+ var blockTaskItem = state.schema.nodes.blockTaskItem;
318
319
  var _state$selection5 = state.selection,
319
320
  empty = _state$selection5.empty,
320
321
  $from = _state$selection5.$from;
322
+
323
+ // If blockTaskItem is in the schema,
324
+ // we need to check if the selection is inside a blockTaskItem
325
+ if (blockTaskItem && empty && fg('platform_editor_blocktaskitem_patch_3')) {
326
+ // If the parent is in a textblock,
327
+ // check if it's nested inside a blockTaskItem
328
+ if ($from.parent.isTextblock) {
329
+ var $posAtEndOfTextBlock = state.doc.resolve($from.end($from.depth - 1));
330
+ var parentOfTextBlock = $posAtEndOfTextBlock.parent;
331
+
332
+ // If the parent of the textblock is a blockTaskItem,
333
+ // we need to know if the textblock is the last node in the blockTaskItem
334
+ if (parentOfTextBlock.type === blockTaskItem) {
335
+ var lastChildOfBlockTaskItem = parentOfTextBlock.lastChild;
336
+ if (lastChildOfBlockTaskItem === $from.parent) {
337
+ // If the textblock is the last node in the blockTaskItem,
338
+ // check if the selection is at the end of the textblock
339
+ var lastTextPosInTextBlock = $from.end($from.depth);
340
+ return $from.pos === lastTextPosInTextBlock;
341
+ } else {
342
+ return false;
343
+ }
344
+ }
345
+ }
346
+ // Else, check if the parent is a blockTaskItem
347
+ else if ($from.parent.type === blockTaskItem) {
348
+ // Check if the selection is at the end of the blockTaskItem
349
+ var lastPosInBlockTaskItem = $from.end();
350
+ return $from.pos === lastPosInBlockTaskItem;
351
+ }
352
+ }
321
353
  return empty && ($from.end() === $from.pos || state.selection instanceof GapCursorSelection);
322
354
  };
323
355
  export { filter as filterCommand };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "109.16.2",
3
+ "version": "110.0.0",
4
4
  "description": "A package that contains common classes and components for editor and renderer",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -33,8 +33,8 @@
33
33
  "@atlaskit/adf-schema": "^51.2.0",
34
34
  "@atlaskit/adf-utils": "^19.24.0",
35
35
  "@atlaskit/afm-i18n-platform-editor-editor-common": "2.7.0",
36
- "@atlaskit/analytics-listeners": "^9.0.0",
37
- "@atlaskit/analytics-namespaced-context": "^7.0.0",
36
+ "@atlaskit/analytics-listeners": "^9.1.0",
37
+ "@atlaskit/analytics-namespaced-context": "^7.1.0",
38
38
  "@atlaskit/analytics-next": "^11.1.0",
39
39
  "@atlaskit/atlassian-context": "^0.6.0",
40
40
  "@atlaskit/button": "^23.4.0",
@@ -175,6 +175,9 @@
175
175
  "platform_editor_blocktaskitem_patch_2": {
176
176
  "type": "boolean"
177
177
  },
178
+ "platform_editor_blocktaskitem_patch_3": {
179
+ "type": "boolean"
180
+ },
178
181
  "platform-visual-refresh-icons": {
179
182
  "type": "boolean"
180
183
  },
@@ -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
- });