@atlaskit/editor-core 188.8.0 → 188.9.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 (95) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/composable-editor/editor-internal.js +2 -2
  3. package/dist/cjs/create-editor/ReactEditorView.js +796 -8
  4. package/dist/cjs/labs/next/presets/universal.js +7 -4
  5. package/dist/cjs/plugins/index.js +0 -21
  6. package/dist/cjs/version-wrapper.js +1 -1
  7. package/dist/es2019/composable-editor/editor-internal.js +1 -1
  8. package/dist/es2019/create-editor/ReactEditorView.js +753 -2
  9. package/dist/es2019/labs/next/presets/universal.js +4 -1
  10. package/dist/es2019/plugins/index.js +0 -3
  11. package/dist/es2019/version-wrapper.js +1 -1
  12. package/dist/esm/composable-editor/editor-internal.js +1 -1
  13. package/dist/esm/create-editor/ReactEditorView.js +797 -8
  14. package/dist/esm/labs/next/presets/universal.js +4 -1
  15. package/dist/esm/plugins/index.js +0 -3
  16. package/dist/esm/version-wrapper.js +1 -1
  17. package/dist/types/create-editor/ReactEditorView.d.ts +119 -5
  18. package/dist/types/plugins/index.d.ts +0 -3
  19. package/dist/types/plugins/insert-block/types.d.ts +1 -1
  20. package/dist/types/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.d.ts +1 -1
  21. package/dist/types-ts4.5/create-editor/ReactEditorView.d.ts +119 -5
  22. package/dist/types-ts4.5/plugins/index.d.ts +0 -3
  23. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +1 -1
  24. package/dist/types-ts4.5/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.d.ts +1 -1
  25. package/package.json +5 -3
  26. package/dist/cjs/create-editor/ReactEditorViewInternal.js +0 -812
  27. package/dist/cjs/create-editor/ReactEditorViewNext.js +0 -15
  28. package/dist/cjs/plugins/save-on-enter/index.js +0 -70
  29. package/dist/cjs/plugins/scroll-into-view/index.js +0 -55
  30. package/dist/cjs/plugins/status/actions.js +0 -158
  31. package/dist/cjs/plugins/status/analytics.js +0 -31
  32. package/dist/cjs/plugins/status/index.js +0 -143
  33. package/dist/cjs/plugins/status/keymap.js +0 -22
  34. package/dist/cjs/plugins/status/nodeviews/status.js +0 -58
  35. package/dist/cjs/plugins/status/plugin-key.js +0 -9
  36. package/dist/cjs/plugins/status/plugin.js +0 -133
  37. package/dist/cjs/plugins/status/types.js +0 -5
  38. package/dist/cjs/plugins/status/ui/statusPicker.js +0 -314
  39. package/dist/cjs/plugins/status/utils.js +0 -22
  40. package/dist/es2019/create-editor/ReactEditorViewInternal.js +0 -753
  41. package/dist/es2019/create-editor/ReactEditorViewNext.js +0 -7
  42. package/dist/es2019/plugins/save-on-enter/index.js +0 -63
  43. package/dist/es2019/plugins/scroll-into-view/index.js +0 -44
  44. package/dist/es2019/plugins/status/actions.js +0 -144
  45. package/dist/es2019/plugins/status/analytics.js +0 -18
  46. package/dist/es2019/plugins/status/index.js +0 -135
  47. package/dist/es2019/plugins/status/keymap.js +0 -13
  48. package/dist/es2019/plugins/status/nodeviews/status.js +0 -60
  49. package/dist/es2019/plugins/status/plugin-key.js +0 -3
  50. package/dist/es2019/plugins/status/plugin.js +0 -113
  51. package/dist/es2019/plugins/status/types.js +0 -1
  52. package/dist/es2019/plugins/status/ui/statusPicker.js +0 -293
  53. package/dist/es2019/plugins/status/utils.js +0 -12
  54. package/dist/esm/create-editor/ReactEditorViewInternal.js +0 -806
  55. package/dist/esm/create-editor/ReactEditorViewNext.js +0 -7
  56. package/dist/esm/plugins/save-on-enter/index.js +0 -63
  57. package/dist/esm/plugins/scroll-into-view/index.js +0 -50
  58. package/dist/esm/plugins/status/actions.js +0 -151
  59. package/dist/esm/plugins/status/analytics.js +0 -24
  60. package/dist/esm/plugins/status/index.js +0 -136
  61. package/dist/esm/plugins/status/keymap.js +0 -15
  62. package/dist/esm/plugins/status/nodeviews/status.js +0 -51
  63. package/dist/esm/plugins/status/plugin-key.js +0 -3
  64. package/dist/esm/plugins/status/plugin.js +0 -115
  65. package/dist/esm/plugins/status/types.js +0 -1
  66. package/dist/esm/plugins/status/ui/statusPicker.js +0 -308
  67. package/dist/esm/plugins/status/utils.js +0 -16
  68. package/dist/types/create-editor/ReactEditorViewInternal.d.ts +0 -119
  69. package/dist/types/create-editor/ReactEditorViewNext.d.ts +0 -8
  70. package/dist/types/plugins/save-on-enter/index.d.ts +0 -10
  71. package/dist/types/plugins/scroll-into-view/index.d.ts +0 -14
  72. package/dist/types/plugins/status/actions.d.ts +0 -16
  73. package/dist/types/plugins/status/analytics.d.ts +0 -4
  74. package/dist/types/plugins/status/index.d.ts +0 -15
  75. package/dist/types/plugins/status/keymap.d.ts +0 -3
  76. package/dist/types/plugins/status/nodeviews/status.d.ts +0 -25
  77. package/dist/types/plugins/status/plugin-key.d.ts +0 -4
  78. package/dist/types/plugins/status/plugin.d.ts +0 -7
  79. package/dist/types/plugins/status/types.d.ts +0 -18
  80. package/dist/types/plugins/status/ui/statusPicker.d.ts +0 -63
  81. package/dist/types/plugins/status/utils.d.ts +0 -5
  82. package/dist/types-ts4.5/create-editor/ReactEditorViewInternal.d.ts +0 -119
  83. package/dist/types-ts4.5/create-editor/ReactEditorViewNext.d.ts +0 -8
  84. package/dist/types-ts4.5/plugins/save-on-enter/index.d.ts +0 -10
  85. package/dist/types-ts4.5/plugins/scroll-into-view/index.d.ts +0 -14
  86. package/dist/types-ts4.5/plugins/status/actions.d.ts +0 -16
  87. package/dist/types-ts4.5/plugins/status/analytics.d.ts +0 -4
  88. package/dist/types-ts4.5/plugins/status/index.d.ts +0 -17
  89. package/dist/types-ts4.5/plugins/status/keymap.d.ts +0 -3
  90. package/dist/types-ts4.5/plugins/status/nodeviews/status.d.ts +0 -25
  91. package/dist/types-ts4.5/plugins/status/plugin-key.d.ts +0 -4
  92. package/dist/types-ts4.5/plugins/status/plugin.d.ts +0 -7
  93. package/dist/types-ts4.5/plugins/status/types.d.ts +0 -18
  94. package/dist/types-ts4.5/plugins/status/ui/statusPicker.d.ts +0 -63
  95. package/dist/types-ts4.5/plugins/status/utils.d.ts +0 -5
@@ -1,812 +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.ReactEditorView = void 0;
8
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
12
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
15
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
- var _react = _interopRequireDefault(require("react"));
17
- var _propTypes = _interopRequireDefault(require("prop-types"));
18
- var _state2 = require("@atlaskit/editor-prosemirror/state");
19
- var _view = require("@atlaskit/editor-prosemirror/view");
20
- var _messages = require("./messages");
21
- var _utils = require("@atlaskit/editor-common/utils");
22
- var _ufo = require("@atlaskit/editor-common/ufo");
23
- var _eventDispatcher = require("../event-dispatcher");
24
- var _saferTransactions = require("../utils/performance/safer-transactions");
25
- var _RenderTracking = require("../utils/performance/components/RenderTracking");
26
- var _nodes = require("../utils/nodes");
27
- var _analytics = require("@atlaskit/editor-common/analytics");
28
- var _featureFlagsFromProps = require("./feature-flags-from-props");
29
- var _normalizeFeatureFlags = require("@atlaskit/editor-common/normalize-feature-flags");
30
- var _createEditor = require("./create-editor");
31
- var _documentLogger = require("../utils/document-logger");
32
- var _isFullPage = require("../utils/is-full-page");
33
- var _measureEnum = _interopRequireDefault(require("../utils/performance/measure-enum"));
34
- var _document = require("../utils/document");
35
- var _createSchema = require("./create-schema");
36
- var _pluginPerformanceObserver = require("../utils/performance/plugin-performance-observer");
37
- var _getParticipantsCount = require("../plugins/collab-edit/get-participants-count");
38
- var _trackTransactions = require("../utils/performance/track-transactions");
39
- var _createPluginsList = _interopRequireDefault(require("./create-plugins-list"));
40
- var _consts = require("./consts");
41
- var _ReactEditorViewContext = _interopRequireDefault(require("./ReactEditorViewContext"));
42
- var _preset = require("@atlaskit/editor-common/preset");
43
- var _ui = require("@atlaskit/editor-common/ui");
44
- 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; }
45
- 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; }
46
- 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); }; }
47
- 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; } }
48
- function handleEditorFocus(view) {
49
- if (view.hasFocus()) {
50
- return;
51
- }
52
- return window.setTimeout(function () {
53
- if (view.hasFocus()) {
54
- return;
55
- }
56
- if (!window.getSelection) {
57
- view.focus();
58
- return;
59
- }
60
- var domSelection = window.getSelection();
61
- if (!domSelection || domSelection.rangeCount === 0) {
62
- view.focus();
63
- return;
64
- }
65
- var range = domSelection.getRangeAt(0);
66
- // if selection is outside editor focus and exit
67
- if (range.startContainer.contains(view.dom)) {
68
- view.focus();
69
- return;
70
- }
71
- // set cursor/selection and focus
72
- var anchor = view.posAtDOM(range.startContainer, range.startOffset);
73
- var head = view.posAtDOM(range.endContainer, range.endOffset);
74
- // if anchor or head < 0 focus and exit
75
- if (anchor < 0 || head < 0) {
76
- view.focus();
77
- return;
78
- }
79
- var selection = _state2.TextSelection.create(view.state.doc, anchor, head);
80
- var tr = view.state.tr.setSelection(selection);
81
- view.dispatch(tr);
82
- view.focus();
83
- }, 0);
84
- }
85
- var ReactEditorView = exports.ReactEditorView = /*#__PURE__*/function (_React$Component) {
86
- (0, _inherits2.default)(ReactEditorView, _React$Component);
87
- var _super = _createSuper(ReactEditorView);
88
- function ReactEditorView(props, context) {
89
- var _props$setEditorApi, _props$editorProps;
90
- var _this;
91
- (0, _classCallCheck2.default)(this, ReactEditorView);
92
- _this = _super.call(this, props, context);
93
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "editorRef", /*#__PURE__*/_react.default.createRef());
94
- // ProseMirror is instantiated prior to the initial React render cycle,
95
- // so we allow transactions by default, to avoid discarding the initial one.
96
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "canDispatchTransactions", true);
97
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onPluginObservation", function (report, editorState) {
98
- _this.dispatchAnalyticsEvent({
99
- action: _analytics.ACTION.TRANSACTION_DISPATCHED,
100
- actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
101
- eventType: _analytics.EVENT_TYPE.OPERATIONAL,
102
- attributes: {
103
- report: report,
104
- participants: (0, _getParticipantsCount.getParticipantsCount)(editorState)
105
- }
106
- });
107
- });
108
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getEditorState", function () {
109
- var _this$view;
110
- return (_this$view = _this.view) === null || _this$view === void 0 ? void 0 : _this$view.state;
111
- });
112
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getEditorView", function () {
113
- return _this.view;
114
- });
115
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "formatFullWidthAppearance", function (appearance) {
116
- if (appearance === 'full-width') {
117
- return _analytics.FULL_WIDTH_MODE.FULL_WIDTH;
118
- }
119
- return _analytics.FULL_WIDTH_MODE.FIXED_WIDTH;
120
- });
121
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "resetEditorState", function (_ref) {
122
- var _this$props$editorPro, _this$props$editorPro2;
123
- var doc = _ref.doc,
124
- shouldScrollToBottom = _ref.shouldScrollToBottom;
125
- if (!_this.view) {
126
- return;
127
- }
128
-
129
- // We cannot currently guarentee when all the portals will have re-rendered during a reconfigure
130
- // so we blur here to stop ProseMirror from trying to apply selection to detached nodes or
131
- // nodes that haven't been re-rendered to the document yet.
132
- _this.blur();
133
- _this.featureFlags = (0, _featureFlagsFromProps.createFeatureFlagsFromProps)(_this.props.editorProps);
134
- _this.editorState = _this.createEditorState({
135
- props: _this.props,
136
- context: _this.context,
137
- doc: doc,
138
- resetting: true,
139
- selectionAtStart: !shouldScrollToBottom
140
- });
141
- _this.view.updateState(_this.editorState);
142
- (_this$props$editorPro = (_this$props$editorPro2 = _this.props.editorProps).onChange) === null || _this$props$editorPro === void 0 || _this$props$editorPro.call(_this$props$editorPro2, _this.view, {
143
- source: 'local'
144
- });
145
- });
146
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "blur", function () {
147
- if (!_this.view) {
148
- return;
149
- }
150
- if (_this.view.dom instanceof HTMLElement && _this.view.hasFocus()) {
151
- _this.view.dom.blur();
152
- }
153
-
154
- // The selectionToDOM method uses the document selection to determine currently selected node
155
- // We need to mimic blurring this as it seems doing the above is not enough.
156
- // @ts-expect-error
157
- var sel = _this.view.root.getSelection();
158
- if (sel) {
159
- sel.removeAllRanges();
160
- }
161
- });
162
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleAnalyticsEvent", function (payload) {
163
- (0, _analytics.fireAnalyticsEvent)(_this.props.createAnalyticsEvent)(payload);
164
- });
165
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "editorPlugins", []);
166
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "createEditorState", function (options) {
167
- var schema;
168
- if (_this.view) {
169
- if (options.resetting) {
170
- /**
171
- * ReactEditorView currently does NOT handle dynamic schema,
172
- * We are reusing the existing schema, and rely on #reconfigureState
173
- * to update `this.config`
174
- */
175
- schema = _this.view.state.schema;
176
- } else {
177
- /**
178
- * There's presently a number of issues with changing the schema of a
179
- * editor inflight. A significant issue is that we lose the ability
180
- * to keep track of a user's history as the internal plugin state
181
- * keeps a list of Steps to undo/redo (which are tied to the schema).
182
- * Without a good way to do work around this, we prevent this for now.
183
- */
184
- // eslint-disable-next-line no-console
185
- console.warn('The editor does not support changing the schema dynamically.');
186
- return _this.editorState;
187
- }
188
- } else {
189
- _this.config = (0, _createEditor.processPluginsList)(_this.getPlugins(options.props.preset));
190
- schema = (0, _createSchema.createSchema)(_this.config);
191
- }
192
- var contentTransformerProvider = options.props.editorProps.contentTransformerProvider;
193
- var plugins = (0, _createEditor.createPMPlugins)({
194
- schema: schema,
195
- dispatch: _this.dispatch,
196
- errorReporter: _this.errorReporter,
197
- editorConfig: _this.config,
198
- eventDispatcher: _this.eventDispatcher,
199
- providerFactory: options.props.providerFactory,
200
- portalProviderAPI: _this.props.portalProviderAPI,
201
- reactContext: function reactContext() {
202
- return options.context;
203
- },
204
- dispatchAnalyticsEvent: _this.dispatchAnalyticsEvent,
205
- performanceTracking: _this.props.editorProps.performanceTracking,
206
- transactionTracker: _this.transactionTracker,
207
- featureFlags: _this.featureFlags,
208
- getIntl: function getIntl() {
209
- return _this.props.intl;
210
- }
211
- });
212
- _this.contentTransformer = contentTransformerProvider ? contentTransformerProvider(schema) : undefined;
213
- var doc;
214
- if (options.doc) {
215
- doc = (0, _utils.processRawValue)(schema, options.doc, options.props.providerFactory, options.props.editorProps.sanitizePrivateContent, _this.contentTransformer, _this.dispatchAnalyticsEvent);
216
- }
217
- var selection;
218
- if (doc) {
219
- selection = options.selectionAtStart ? _state2.Selection.atStart(doc) : _state2.Selection.atEnd(doc);
220
- }
221
- // Workaround for ED-3507: When media node is the last element, scrollIntoView throws an error
222
- var patchedSelection = selection ? _state2.Selection.findFrom(selection.$head, -1, true) || undefined : undefined;
223
- return _state2.EditorState.create({
224
- schema: schema,
225
- plugins: plugins,
226
- doc: doc,
227
- selection: patchedSelection
228
- });
229
- });
230
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onEditorViewStateUpdated", function (_ref2) {
231
- var originalTransaction = _ref2.originalTransaction,
232
- transactions = _ref2.transactions,
233
- oldEditorState = _ref2.oldEditorState,
234
- newEditorState = _ref2.newEditorState;
235
- var trackinEnabled = _this.transactionTracking.enabled;
236
- _this.config.onEditorViewStateUpdatedCallbacks.forEach(function (entry) {
237
- trackinEnabled && (0, _utils.startMeasure)("\uD83E\uDD89 ".concat(entry.pluginName, "::onEditorViewStateUpdated"));
238
- entry.callback({
239
- originalTransaction: originalTransaction,
240
- transactions: transactions,
241
- oldEditorState: oldEditorState,
242
- newEditorState: newEditorState
243
- });
244
- trackinEnabled && (0, _utils.stopMeasure)("\uD83E\uDD89 ".concat(entry.pluginName, "::onEditorViewStateUpdated"));
245
- });
246
- });
247
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "trackValidTransactions", function () {
248
- var editorProps = _this.props.editorProps;
249
- if (!_this.isTransactionTrackingExplicitlyDisabled() && editorProps !== null && editorProps !== void 0 && editorProps.trackValidTransactions) {
250
- _this.validTransactionCount++;
251
- var samplingRate = (0, _typeof2.default)(editorProps.trackValidTransactions) === 'object' && editorProps.trackValidTransactions.samplingRate || _consts.DEFAULT_SAMPLING_RATE_VALID_TRANSACTIONS;
252
- if (_this.validTransactionCount >= samplingRate) {
253
- _this.dispatchAnalyticsEvent({
254
- action: _analytics.ACTION.DISPATCHED_VALID_TRANSACTION,
255
- actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
256
- eventType: _analytics.EVENT_TYPE.OPERATIONAL
257
- });
258
- _this.validTransactionCount = 0;
259
- }
260
- }
261
- });
262
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "dispatchTransaction", function (unsafeTransaction) {
263
- if (!_this.view) {
264
- return;
265
- }
266
- _this.transactionTracker.bumpDispatchCounter(_this.transactionTracking);
267
- var _this$transactionTrac = _this.transactionTracker.getMeasureHelpers(_this.transactionTracking),
268
- startMeasure = _this$transactionTrac.startMeasure,
269
- stopMeasure = _this$transactionTrac.stopMeasure;
270
- startMeasure(_trackTransactions.EVENT_NAME_DISPATCH_TRANSACTION);
271
- if (_this.transactionTracker.shouldTrackTransaction(_this.transactionTracking)) {
272
- var _this$experienceStore;
273
- (_this$experienceStore = _this.experienceStore) === null || _this$experienceStore === void 0 || _this$experienceStore.start(_ufo.EditorExperience.interaction);
274
- }
275
- var nodes = (0, _nodes.findChangedNodesFromTransaction)(unsafeTransaction);
276
- var changedNodesValid = (0, _nodes.validateNodes)(nodes);
277
- var transaction = _this.featureFlags.saferDispatchedTransactions || _this.featureFlags.saferDispatchedTransactionsAnalyticsOnly ? new Proxy(unsafeTransaction, (0, _saferTransactions.freezeUnsafeTransactionProperties)({
278
- dispatchAnalyticsEvent: _this.dispatchAnalyticsEvent,
279
- pluginKey: 'unknown-reacteditorview',
280
- analyticsOnly: _this.featureFlags.saferDispatchedTransactionsAnalyticsOnly
281
- })) : unsafeTransaction;
282
- if (changedNodesValid) {
283
- var oldEditorState = _this.view.state;
284
-
285
- // go ahead and update the state now we know the transaction is good
286
- startMeasure(_trackTransactions.EVENT_NAME_STATE_APPLY);
287
- var _this$view$state$appl = _this.view.state.applyTransaction(transaction),
288
- editorState = _this$view$state$appl.state,
289
- transactions = _this$view$state$appl.transactions;
290
- stopMeasure(_trackTransactions.EVENT_NAME_STATE_APPLY, function (duration, startTime) {
291
- var _this$experienceStore2;
292
- (_this$experienceStore2 = _this.experienceStore) === null || _this$experienceStore2 === void 0 || _this$experienceStore2.mark(_ufo.EditorExperience.interaction, 'stateApply', startTime + duration);
293
- });
294
- _this.trackValidTransactions();
295
- if (editorState === oldEditorState) {
296
- return;
297
- }
298
- startMeasure(_trackTransactions.EVENT_NAME_UPDATE_STATE);
299
- _this.view.updateState(editorState);
300
- stopMeasure(_trackTransactions.EVENT_NAME_UPDATE_STATE, function (duration, startTime) {
301
- var _this$experienceStore3;
302
- (_this$experienceStore3 = _this.experienceStore) === null || _this$experienceStore3 === void 0 || _this$experienceStore3.mark(_ufo.EditorExperience.interaction, 'viewUpdateState', startTime + duration);
303
- });
304
- _this.pluginInjectionAPI.onEditorViewUpdated({
305
- newEditorState: editorState,
306
- oldEditorState: oldEditorState
307
- });
308
- startMeasure(_trackTransactions.EVENT_NAME_VIEW_STATE_UPDATED);
309
- _this.onEditorViewStateUpdated({
310
- originalTransaction: transaction,
311
- transactions: transactions,
312
- oldEditorState: oldEditorState,
313
- newEditorState: editorState
314
- });
315
- stopMeasure(_trackTransactions.EVENT_NAME_VIEW_STATE_UPDATED, function (duration, startTime) {
316
- var _this$experienceStore4;
317
- (_this$experienceStore4 = _this.experienceStore) === null || _this$experienceStore4 === void 0 || _this$experienceStore4.mark(_ufo.EditorExperience.interaction, 'onEditorViewStateUpdated', startTime + duration);
318
- });
319
- if (_this.props.editorProps.onChange && transaction.docChanged) {
320
- var source = transaction.getMeta('isRemote') ? 'remote' : 'local';
321
- startMeasure(_trackTransactions.EVENT_NAME_ON_CHANGE);
322
- _this.props.editorProps.onChange(_this.view, {
323
- source: source
324
- });
325
- stopMeasure(_trackTransactions.EVENT_NAME_ON_CHANGE, function (duration, startTime) {
326
- var _this$experienceStore5, _this$props$editorPro3;
327
- (_this$experienceStore5 = _this.experienceStore) === null || _this$experienceStore5 === void 0 || _this$experienceStore5.mark(_ufo.EditorExperience.interaction, 'onChange', startTime + duration);
328
- if (((_this$props$editorPro3 = _this.props.editorProps.performanceTracking) === null || _this$props$editorPro3 === void 0 || (_this$props$editorPro3 = _this$props$editorPro3.onChangeCallbackTracking) === null || _this$props$editorPro3 === void 0 ? void 0 : _this$props$editorPro3.enabled) !== true) {
329
- return;
330
- }
331
- _this.dispatchAnalyticsEvent({
332
- action: _analytics.ACTION.ON_CHANGE_CALLBACK,
333
- actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
334
- eventType: _analytics.EVENT_TYPE.OPERATIONAL,
335
- attributes: {
336
- duration: duration,
337
- startTime: startTime
338
- }
339
- });
340
- });
341
- }
342
- _this.editorState = editorState;
343
- stopMeasure(_trackTransactions.EVENT_NAME_DISPATCH_TRANSACTION, function (duration, startTime) {
344
- var _this$experienceStore6, _this$experienceStore7;
345
- (_this$experienceStore6 = _this.experienceStore) === null || _this$experienceStore6 === void 0 || _this$experienceStore6.mark(_ufo.EditorExperience.interaction, 'dispatchTransaction', startTime + duration);
346
- (_this$experienceStore7 = _this.experienceStore) === null || _this$experienceStore7 === void 0 || _this$experienceStore7.success(_ufo.EditorExperience.interaction);
347
- });
348
- } else {
349
- var _this$experienceStore8;
350
- var invalidNodes = nodes.filter(function (node) {
351
- return !(0, _nodes.validNode)(node);
352
- }).map(function (node) {
353
- return (0, _documentLogger.getDocStructure)(node, {
354
- compact: true
355
- });
356
- });
357
- if (!_this.isTransactionTrackingExplicitlyDisabled()) {
358
- _this.dispatchAnalyticsEvent({
359
- action: _analytics.ACTION.DISPATCHED_INVALID_TRANSACTION,
360
- actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
361
- eventType: _analytics.EVENT_TYPE.OPERATIONAL,
362
- attributes: {
363
- analyticsEventPayloads: (0, _analytics.getAnalyticsEventsFromTransaction)(transaction),
364
- invalidNodes: invalidNodes
365
- }
366
- });
367
- }
368
- (_this$experienceStore8 = _this.experienceStore) === null || _this$experienceStore8 === void 0 || _this$experienceStore8.fail(_ufo.EditorExperience.interaction, {
369
- reason: 'invalid transaction',
370
- invalidNodes: invalidNodes.toString()
371
- });
372
- }
373
- });
374
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getDirectEditorProps", function (state) {
375
- return {
376
- state: state || _this.editorState,
377
- dispatchTransaction: function dispatchTransaction(tr) {
378
- // Block stale transactions:
379
- // Prevent runtime exeptions from async transactions that would attempt to
380
- // update the DOM after React has unmounted the Editor.
381
- if (_this.canDispatchTransactions) {
382
- _this.dispatchTransaction(tr);
383
- }
384
- },
385
- // Disables the contentEditable attribute of the editor if the editor is disabled
386
- editable: function editable(_state) {
387
- return !_this.props.editorProps.disabled;
388
- },
389
- attributes: {
390
- 'data-gramm': 'false'
391
- }
392
- };
393
- });
394
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "createEditorView", function (node) {
395
- (0, _utils.measureRender)(_measureEnum.default.PROSEMIRROR_RENDERED, function (_ref3) {
396
- var _this$props$editorPro4, _proseMirrorRenderedT, _proseMirrorRenderedT2;
397
- var duration = _ref3.duration,
398
- startTime = _ref3.startTime,
399
- distortedDuration = _ref3.distortedDuration;
400
- var proseMirrorRenderedTracking = (_this$props$editorPro4 = _this.props.editorProps) === null || _this$props$editorPro4 === void 0 || (_this$props$editorPro4 = _this$props$editorPro4.performanceTracking) === null || _this$props$editorPro4 === void 0 ? void 0 : _this$props$editorPro4.proseMirrorRenderedTracking;
401
- var forceSeverityTracking = typeof proseMirrorRenderedTracking === 'undefined' && (0, _utils.shouldForceTracking)();
402
- _this.proseMirrorRenderedSeverity = !!forceSeverityTracking || proseMirrorRenderedTracking !== null && proseMirrorRenderedTracking !== void 0 && proseMirrorRenderedTracking.trackSeverity ? (0, _utils.getAnalyticsEventSeverity)(duration, (_proseMirrorRenderedT = proseMirrorRenderedTracking === null || proseMirrorRenderedTracking === void 0 ? void 0 : proseMirrorRenderedTracking.severityNormalThreshold) !== null && _proseMirrorRenderedT !== void 0 ? _proseMirrorRenderedT : _consts.PROSEMIRROR_RENDERED_NORMAL_SEVERITY_THRESHOLD, (_proseMirrorRenderedT2 = proseMirrorRenderedTracking === null || proseMirrorRenderedTracking === void 0 ? void 0 : proseMirrorRenderedTracking.severityDegradedThreshold) !== null && _proseMirrorRenderedT2 !== void 0 ? _proseMirrorRenderedT2 : _consts.PROSEMIRROR_RENDERED_DEGRADED_SEVERITY_THRESHOLD) : undefined;
403
- if (_this.view) {
404
- var _this$pluginInjection, _this$experienceStore10;
405
- var nodes = (0, _document.getNodesCount)(_this.view.state.doc);
406
- var ttfb = (0, _utils.getResponseEndTime)();
407
- var contextIdentifier = (_this$pluginInjection = _this.pluginInjectionAPI.api().base) === null || _this$pluginInjection === void 0 ? void 0 : _this$pluginInjection.sharedState.currentState();
408
- _this.dispatchAnalyticsEvent({
409
- action: _analytics.ACTION.PROSEMIRROR_RENDERED,
410
- actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
411
- attributes: {
412
- duration: duration,
413
- startTime: startTime,
414
- nodes: nodes,
415
- ttfb: ttfb,
416
- severity: _this.proseMirrorRenderedSeverity,
417
- objectId: contextIdentifier === null || contextIdentifier === void 0 ? void 0 : contextIdentifier.objectId,
418
- distortedDuration: distortedDuration
419
- },
420
- eventType: _analytics.EVENT_TYPE.OPERATIONAL
421
- });
422
- if (!distortedDuration) {
423
- var _this$experienceStore9;
424
- (_this$experienceStore9 = _this.experienceStore) === null || _this$experienceStore9 === void 0 || _this$experienceStore9.mark(_ufo.EditorExperience.loadEditor, _analytics.ACTION.PROSEMIRROR_RENDERED, startTime + duration);
425
- }
426
- (_this$experienceStore10 = _this.experienceStore) === null || _this$experienceStore10 === void 0 || _this$experienceStore10.addMetadata(_ufo.EditorExperience.loadEditor, {
427
- nodes: nodes,
428
- ttfb: ttfb
429
- });
430
- }
431
- });
432
-
433
- // Creates the editor-view from this.editorState. If an editor has been mounted
434
- // previously, this will contain the previous state of the editor.
435
- _this.view = new _view.EditorView({
436
- mount: node
437
- }, _this.getDirectEditorProps());
438
- _this.pluginInjectionAPI.onEditorViewUpdated({
439
- newEditorState: _this.view.state,
440
- oldEditorState: undefined
441
- });
442
- });
443
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleEditorViewRef", function (node) {
444
- if (!_this.view && node) {
445
- _this.createEditorView(node);
446
- var view = _this.view;
447
- _this.props.onEditorCreated({
448
- view: view,
449
- config: _this.config,
450
- eventDispatcher: _this.eventDispatcher,
451
- transformer: _this.contentTransformer
452
- });
453
- if (_this.props.editorProps.shouldFocus && view.props.editable && view.props.editable(view.state)) {
454
- _this.focusTimeoutId = handleEditorFocus(view);
455
- }
456
- if (_this.featureFlags.ufo) {
457
- _this.experienceStore = _ufo.ExperienceStore.getInstance(view);
458
- _this.experienceStore.start(_ufo.EditorExperience.editSession);
459
- _this.experienceStore.addMetadata(_ufo.EditorExperience.editSession, {
460
- reliabilityInterval: _ufo.RELIABILITY_INTERVAL
461
- });
462
- _this.reliabilityInterval = window.setInterval(function () {
463
- var _this$experienceStore11;
464
- (_this$experienceStore11 = _this.experienceStore) === null || _this$experienceStore11 === void 0 || (_this$experienceStore11 = _this$experienceStore11.success(_ufo.EditorExperience.editSession)) === null || _this$experienceStore11 === void 0 || _this$experienceStore11.finally(function () {
465
- var _this$experienceStore12, _this$experienceStore13;
466
- (_this$experienceStore12 = _this.experienceStore) === null || _this$experienceStore12 === void 0 || _this$experienceStore12.start(_ufo.EditorExperience.editSession);
467
- (_this$experienceStore13 = _this.experienceStore) === null || _this$experienceStore13 === void 0 || _this$experienceStore13.addMetadata(_ufo.EditorExperience.editSession, {
468
- reliabilityInterval: _ufo.RELIABILITY_INTERVAL
469
- });
470
- });
471
- var reliabilityEvent = {
472
- action: _analytics.ACTION.UFO_SESSION_COMPLETE,
473
- actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
474
- attributes: {
475
- interval: _ufo.RELIABILITY_INTERVAL
476
- },
477
- eventType: _analytics.EVENT_TYPE.OPERATIONAL
478
- };
479
- _this.dispatchAnalyticsEvent(reliabilityEvent);
480
- }, _ufo.RELIABILITY_INTERVAL);
481
- }
482
-
483
- // Force React to re-render so consumers get a reference to the editor view
484
- _this.forceUpdate();
485
- } else if (_this.view && !node) {
486
- // When the appearance is changed, React will call handleEditorViewRef with node === null
487
- // to destroy the old EditorView, before calling this method again with node === div to
488
- // create the new EditorView
489
- _this.props.onEditorDestroyed({
490
- view: _this.view,
491
- config: _this.config,
492
- eventDispatcher: _this.eventDispatcher,
493
- transformer: _this.contentTransformer
494
- });
495
-
496
- // Allows us to dispatch analytics within the plugin view.destory methods
497
- var analyticsConnected = _this.eventDispatcher.has(_utils.analyticsEventKey, _this.handleAnalyticsEvent);
498
- if (!analyticsConnected) {
499
- _this.eventDispatcher.on(_utils.analyticsEventKey, _this.handleAnalyticsEvent);
500
- }
501
- _this.view.destroy(); // Destroys the dom node & all node views
502
-
503
- if (!analyticsConnected) {
504
- _this.eventDispatcher.off(_utils.analyticsEventKey, _this.handleAnalyticsEvent);
505
- }
506
- _this.view = undefined;
507
- }
508
- });
509
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "dispatchAnalyticsEvent", function (payload) {
510
- if (_this.eventDispatcher) {
511
- var dispatch = (0, _eventDispatcher.createDispatch)(_this.eventDispatcher);
512
- dispatch(_utils.analyticsEventKey, {
513
- payload: payload
514
- });
515
- }
516
- });
517
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "createEditor", function (assistiveLabel) {
518
- return /*#__PURE__*/_react.default.createElement("div", {
519
- className: getUAPrefix(),
520
- key: "ProseMirror",
521
- ref: _this.handleEditorViewRef,
522
- "aria-label": assistiveLabel || _this.props.intl.formatMessage(_messages.editorMessages.editorAssistiveLabel)
523
- // setting aria-multiline to true when not mobile appearance.
524
- // because somehow mobile tests are failing when it set.
525
- // don't know why that is happening.
526
- // Created https://product-fabric.atlassian.net/jira/servicedesk/projects/DTR/queues/issue/DTR-1675
527
- // to investigate further.
528
- ,
529
- "aria-multiline": _this.props.editorProps.appearance !== 'mobile' ? true : false,
530
- role: "textbox",
531
- id: _ui.EDIT_AREA_ID
532
- });
533
- });
534
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "editor", _this.createEditor(_this.props.editorProps.assistiveLabel));
535
- _this.pluginInjectionAPI = new _preset.EditorPluginInjectionAPI({
536
- getEditorState: _this.getEditorState,
537
- getEditorView: _this.getEditorView
538
- });
539
- (_props$setEditorApi = props.setEditorApi) === null || _props$setEditorApi === void 0 || _props$setEditorApi.call(props, _this.pluginInjectionAPI.api());
540
- _this.eventDispatcher = new _eventDispatcher.EventDispatcher();
541
- _this.dispatch = (0, _eventDispatcher.createDispatch)(_this.eventDispatcher);
542
- _this.errorReporter = (0, _createEditor.createErrorReporter)(props.editorProps.errorReporterHandler);
543
- _this.transactionTracker = new _trackTransactions.TransactionTracker();
544
- _this.pluginPerformanceObserver = new _pluginPerformanceObserver.PluginPerformanceObserver(function (report) {
545
- return _this.onPluginObservation(report, _this.editorState);
546
- }).withPlugins(function () {
547
- return _this.getPluginNames();
548
- }).withNodeCounts(function () {
549
- return _this.countNodes();
550
- }).withOptions(function () {
551
- return _this.transactionTracking;
552
- }).withTransactionTracker(function () {
553
- return _this.transactionTracker;
554
- });
555
- _this.validTransactionCount = 0;
556
- _this.featureFlags = (0, _featureFlagsFromProps.createFeatureFlagsFromProps)(_this.props.editorProps);
557
- var featureFlagsEnabled = _this.featureFlags ? (0, _normalizeFeatureFlags.getEnabledFeatureFlagKeys)(_this.featureFlags) : [];
558
-
559
- // START TEMPORARY CODE ED-10584
560
- if (_this.props.createAnalyticsEvent) {
561
- _this.props.createAnalyticsEvent.__queueAnalytics = _this.featureFlags.queueAnalytics;
562
- }
563
- // END TEMPORARY CODE ED-10584
564
-
565
- // This needs to be before initialising editorState because
566
- // we dispatch analytics events in plugin initialisation
567
- _this.eventDispatcher.on(_utils.analyticsEventKey, _this.handleAnalyticsEvent);
568
- _this.eventDispatcher.on('resetEditorState', _this.resetEditorState);
569
- _this.editorState = _this.createEditorState({
570
- props: props,
571
- context: context,
572
- doc: props.editorProps.defaultValue,
573
- // ED-4759: Don't set selection at end for full-page editor - should be at start.
574
- selectionAtStart: (0, _isFullPage.isFullPage)(props.editorProps.appearance)
575
- });
576
-
577
- // ED-16320: Check for explicit disable so that by default
578
- // it will still be enabled as it currently is. Then we can
579
- // progressively opt out synthetic tenants.
580
- var isEditorStartedExplicitlyDisabled = ((_props$editorProps = props.editorProps) === null || _props$editorProps === void 0 || (_props$editorProps = _props$editorProps.performanceTracking) === null || _props$editorProps === void 0 || (_props$editorProps = _props$editorProps.startedTracking) === null || _props$editorProps === void 0 ? void 0 : _props$editorProps.enabled) === false;
581
- if (!isEditorStartedExplicitlyDisabled) {
582
- _this.dispatchAnalyticsEvent({
583
- action: _analytics.ACTION.STARTED,
584
- actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
585
- attributes: {
586
- platform: _analytics.PLATFORMS.WEB,
587
- featureFlags: featureFlagsEnabled
588
- },
589
- eventType: _analytics.EVENT_TYPE.UI
590
- });
591
- }
592
- return _this;
593
- }
594
- (0, _createClass2.default)(ReactEditorView, [{
595
- key: "transactionTracking",
596
- get: function get() {
597
- var _this$props$editorPro5, _this$props$editorPro6;
598
- return (_this$props$editorPro5 = (_this$props$editorPro6 = this.props.editorProps.performanceTracking) === null || _this$props$editorPro6 === void 0 ? void 0 : _this$props$editorPro6.transactionTracking) !== null && _this$props$editorPro5 !== void 0 ? _this$props$editorPro5 : {
599
- enabled: false
600
- };
601
- }
602
- }, {
603
- key: "getPluginNames",
604
- value: function getPluginNames() {
605
- return this.editorState.plugins.map(function (p) {
606
- return p.key;
607
- });
608
- }
609
- }, {
610
- key: "countNodes",
611
- value: function countNodes() {
612
- return (0, _utils.countNodes)(this.editorState);
613
- }
614
- }, {
615
- key: "isTransactionTrackingExplicitlyDisabled",
616
- value: function isTransactionTrackingExplicitlyDisabled() {
617
- var _this$props$editorPro7;
618
- // ED-16320: Check for explicit disable so that by default
619
- // it will still be enabled as it currently is. Then we can
620
- // progressively opt out synthetic tenants.
621
- return ((_this$props$editorPro7 = this.props.editorProps) === null || _this$props$editorPro7 === void 0 || (_this$props$editorPro7 = _this$props$editorPro7.performanceTracking) === null || _this$props$editorPro7 === void 0 || (_this$props$editorPro7 = _this$props$editorPro7.transactionTracking) === null || _this$props$editorPro7 === void 0 ? void 0 : _this$props$editorPro7.enabled) === false;
622
- }
623
- }, {
624
- key: "UNSAFE_componentWillReceiveProps",
625
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
626
- // START TEMPORARY CODE ED-10584
627
- if (nextProps.createAnalyticsEvent && nextProps.createAnalyticsEvent !== this.props.createAnalyticsEvent) {
628
- var featureFlags = (0, _featureFlagsFromProps.createFeatureFlagsFromProps)(nextProps.editorProps);
629
- nextProps.createAnalyticsEvent.__queueAnalytics = featureFlags.queueAnalytics;
630
- }
631
- // END TEMPORARY CODE ED-10584
632
-
633
- if (this.view && this.props.editorProps.disabled !== nextProps.editorProps.disabled) {
634
- // Disables the contentEditable attribute of the editor if the editor is disabled
635
- this.view.setProps({
636
- editable: function editable(_state) {
637
- return !nextProps.editorProps.disabled;
638
- }
639
- });
640
- if (!nextProps.editorProps.disabled && nextProps.editorProps.shouldFocus) {
641
- this.focusTimeoutId = handleEditorFocus(this.view);
642
- }
643
- }
644
- var appearance = this.props.editorProps.appearance;
645
- var nextAppearance = nextProps.editorProps.appearance;
646
- if (this.props.preset !== nextProps.preset) {
647
- this.reconfigureState(nextProps);
648
- }
649
- if (nextAppearance !== appearance) {
650
- if (nextAppearance === 'full-width' || appearance === 'full-width') {
651
- this.dispatchAnalyticsEvent({
652
- action: _analytics.ACTION.CHANGED_FULL_WIDTH_MODE,
653
- actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
654
- eventType: _analytics.EVENT_TYPE.TRACK,
655
- attributes: {
656
- previousMode: this.formatFullWidthAppearance(appearance),
657
- newMode: this.formatFullWidthAppearance(nextAppearance)
658
- }
659
- });
660
- }
661
- }
662
- if (!this.transactionTracking.enabled) {
663
- this.pluginPerformanceObserver.disconnect();
664
- }
665
- if (nextProps.editorProps.assistiveLabel !== this.props.editorProps.assistiveLabel) {
666
- this.editor = this.createEditor(nextProps.editorProps.assistiveLabel);
667
- }
668
- }
669
- }, {
670
- key: "reconfigureState",
671
- value: function reconfigureState(props) {
672
- var _this2 = this;
673
- if (!this.view) {
674
- return;
675
- }
676
-
677
- // We cannot currently guarentee when all the portals will have re-rendered during a reconfigure
678
- // so we blur here to stop ProseMirror from trying to apply selection to detached nodes or
679
- // nodes that haven't been re-rendered to the document yet.
680
- this.blur();
681
- var editorPlugins = this.getPlugins(props.preset);
682
- this.config = (0, _createEditor.processPluginsList)(editorPlugins);
683
- var state = this.editorState;
684
- var plugins = (0, _createEditor.createPMPlugins)({
685
- schema: state.schema,
686
- dispatch: this.dispatch,
687
- errorReporter: this.errorReporter,
688
- editorConfig: this.config,
689
- eventDispatcher: this.eventDispatcher,
690
- providerFactory: props.providerFactory,
691
- portalProviderAPI: props.portalProviderAPI,
692
- reactContext: function reactContext() {
693
- return _this2.context;
694
- },
695
- dispatchAnalyticsEvent: this.dispatchAnalyticsEvent,
696
- performanceTracking: props.editorProps.performanceTracking,
697
- transactionTracker: this.transactionTracker,
698
- featureFlags: (0, _featureFlagsFromProps.createFeatureFlagsFromProps)(props.editorProps),
699
- getIntl: function getIntl() {
700
- return _this2.props.intl;
701
- }
702
- });
703
- var newState = state.reconfigure({
704
- plugins: plugins
705
- });
706
-
707
- // need to update the state first so when the view builds the nodeviews it is
708
- // using the latest plugins
709
- this.view.updateState(newState);
710
- return this.view.update(_objectSpread(_objectSpread({}, this.view.props), {}, {
711
- state: newState
712
- }));
713
- }
714
- }, {
715
- key: "componentDidMount",
716
- value: function componentDidMount() {
717
- // Transaction dispatching is already enabled by default prior to
718
- // mounting, but we reset it here, just in case the editor view
719
- // instance is ever recycled (mounted again after unmounting) with
720
- // the same key.
721
- // Although storing mounted state is an anti-pattern in React,
722
- // we do so here so that we can intercept and abort asynchronous
723
- // ProseMirror transactions when a dismount is imminent.
724
- this.canDispatchTransactions = true;
725
- if (this.transactionTracking.enabled) {
726
- this.pluginPerformanceObserver.observe();
727
- }
728
- }
729
-
730
- /**
731
- * Clean up any non-PM resources when the editor is unmounted
732
- */
733
- }, {
734
- key: "componentWillUnmount",
735
- value: function componentWillUnmount() {
736
- // We can ignore any transactions from this point onwards.
737
- // This serves to avoid potential runtime exceptions which could arise
738
- // from an async dispatched transaction after it's unmounted.
739
- this.canDispatchTransactions = false;
740
- clearTimeout(this.focusTimeoutId);
741
- if (this.reliabilityInterval) {
742
- clearInterval(this.reliabilityInterval);
743
- }
744
- this.pluginPerformanceObserver.disconnect();
745
- if (this.view) {
746
- // Destroy the state if the Editor is being unmounted
747
- var editorState = this.view.state;
748
- editorState.plugins.forEach(function (plugin) {
749
- var state = plugin.getState(editorState);
750
- if (state && state.destroy) {
751
- state.destroy();
752
- }
753
- });
754
- }
755
- this.eventDispatcher.destroy();
756
- // this.view will be destroyed when React unmounts in handleEditorViewRef
757
- }
758
- }, {
759
- key: "getPlugins",
760
- value:
761
- // Helper to allow tests to inject plugins directly
762
- function getPlugins(preset) {
763
- var plugins = (0, _createPluginsList.default)(preset, this.props.editorProps, this.pluginInjectionAPI);
764
- this.editorPlugins = plugins;
765
- return this.editorPlugins;
766
- }
767
- }, {
768
- key: "render",
769
- value: function render() {
770
- var _this$props$editorPro8;
771
- var renderTracking = (_this$props$editorPro8 = this.props.editorProps.performanceTracking) === null || _this$props$editorPro8 === void 0 || (_this$props$editorPro8 = _this$props$editorPro8.renderTracking) === null || _this$props$editorPro8 === void 0 ? void 0 : _this$props$editorPro8.reactEditorView;
772
- var renderTrackingEnabled = renderTracking === null || renderTracking === void 0 ? void 0 : renderTracking.enabled;
773
- var useShallow = renderTracking === null || renderTracking === void 0 ? void 0 : renderTracking.useShallow;
774
- return /*#__PURE__*/_react.default.createElement(_ReactEditorViewContext.default.Provider, {
775
- value: {
776
- editorRef: this.editorRef,
777
- editorView: this.view
778
- }
779
- }, renderTrackingEnabled && /*#__PURE__*/_react.default.createElement(_RenderTracking.RenderTracking, {
780
- componentProps: this.props,
781
- action: _analytics.ACTION.RE_RENDERED,
782
- actionSubject: _analytics.ACTION_SUBJECT.REACT_EDITOR_VIEW,
783
- handleAnalyticsEvent: this.handleAnalyticsEvent,
784
- useShallow: useShallow
785
- }), this.props.render ? this.props.render({
786
- editor: this.editor,
787
- view: this.view,
788
- config: this.config,
789
- eventDispatcher: this.eventDispatcher,
790
- transformer: this.contentTransformer,
791
- dispatchAnalyticsEvent: this.dispatchAnalyticsEvent,
792
- editorRef: this.editorRef
793
- }) : this.editor);
794
- }
795
- }]);
796
- return ReactEditorView;
797
- }(_react.default.Component);
798
- (0, _defineProperty2.default)(ReactEditorView, "contextTypes", {
799
- getAtlaskitAnalyticsEventHandlers: _propTypes.default.func
800
- });
801
- function getUAPrefix() {
802
- if (_utils.browser.chrome) {
803
- return 'ua-chrome';
804
- } else if (_utils.browser.ie) {
805
- return 'ua-ie';
806
- } else if (_utils.browser.gecko) {
807
- return 'ua-firefox';
808
- } else if (_utils.browser.safari) {
809
- return 'ua-safari';
810
- }
811
- return '';
812
- }