@atlaskit/editor-core 203.11.6 → 203.11.8

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 +16 -0
  2. package/dist/cjs/composable-editor/editor-internal.js +2 -94
  3. package/dist/cjs/create-editor/ReactEditorViewNext.js +1 -0
  4. package/dist/cjs/ui/ContentStyles/code-block.js +1 -1
  5. package/dist/cjs/ui/ContentStyles/index.js +2 -2
  6. package/dist/cjs/version-wrapper.js +1 -1
  7. package/dist/es2019/composable-editor/editor-internal.js +3 -93
  8. package/dist/es2019/create-editor/ReactEditorViewNext.js +1 -1
  9. package/dist/es2019/ui/ContentStyles/code-block.js +2 -1
  10. package/dist/es2019/ui/ContentStyles/index.js +19 -8
  11. package/dist/es2019/version-wrapper.js +1 -1
  12. package/dist/esm/composable-editor/editor-internal.js +3 -95
  13. package/dist/esm/create-editor/ReactEditorViewNext.js +1 -1
  14. package/dist/esm/ui/ContentStyles/code-block.js +1 -1
  15. package/dist/esm/ui/ContentStyles/index.js +2 -2
  16. package/dist/esm/version-wrapper.js +1 -1
  17. package/dist/types/create-editor/ReactEditorViewNext.d.ts +1 -0
  18. package/dist/types/create-editor/create-universal-preset.d.ts +2 -6
  19. package/dist/types/presets/default.d.ts +4 -12
  20. package/dist/types/presets/universal.d.ts +2 -6
  21. package/dist/types/presets/useUniversalPreset.d.ts +2 -6
  22. package/dist/types-ts4.5/create-editor/ReactEditorViewNext.d.ts +1 -0
  23. package/dist/types-ts4.5/create-editor/create-universal-preset.d.ts +2 -6
  24. package/dist/types-ts4.5/presets/default.d.ts +4 -12
  25. package/dist/types-ts4.5/presets/universal.d.ts +2 -6
  26. package/dist/types-ts4.5/presets/useUniversalPreset.d.ts +2 -6
  27. package/package.json +5 -8
  28. package/dist/cjs/create-editor/ReactEditorView.js +0 -712
  29. package/dist/es2019/create-editor/ReactEditorView.js +0 -658
  30. package/dist/esm/create-editor/ReactEditorView.js +0 -705
  31. package/dist/types/create-editor/ReactEditorView.d.ts +0 -117
  32. package/dist/types-ts4.5/create-editor/ReactEditorView.d.ts +0 -117
@@ -1,705 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
- 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; }
8
- 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) { _defineProperty(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; }
9
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
10
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
- import React from 'react';
12
- import { injectIntl } from 'react-intl-next';
13
- import uuid from 'uuid/v4';
14
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, fireAnalyticsEvent, FULL_WIDTH_MODE, getAnalyticsEventsFromTransaction, PLATFORMS } from '@atlaskit/editor-common/analytics';
15
- import { browser } from '@atlaskit/editor-common/browser';
16
- import { getDocStructure } from '@atlaskit/editor-common/core-utils';
17
- import { countNodes as _countNodes } from '@atlaskit/editor-common/count-nodes';
18
- import { createDispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
19
- import { getEnabledFeatureFlagKeys } from '@atlaskit/editor-common/normalize-feature-flags';
20
- import { startMeasure, stopMeasure } from '@atlaskit/editor-common/performance-measures';
21
- import { measureRender } from '@atlaskit/editor-common/performance/measure-render';
22
- import { getResponseEndTime } from '@atlaskit/editor-common/performance/navigation';
23
- import { EditorPluginInjectionAPI } from '@atlaskit/editor-common/preset';
24
- import { processRawValue, processRawValueWithoutValidation } from '@atlaskit/editor-common/process-raw-value';
25
- import { ReactEditorViewContext } from '@atlaskit/editor-common/ui-react';
26
- import { analyticsEventKey, getAnalyticsEventSeverity } from '@atlaskit/editor-common/utils/analytics';
27
- import { EditorState, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
28
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
29
- import { fg } from '@atlaskit/platform-feature-flags';
30
- import { findChangedNodesFromTransaction } from '../utils/findChangedNodesFromTransaction';
31
- import { getNodesCount } from '../utils/getNodesCount';
32
- import { isFullPage } from '../utils/is-full-page';
33
- import { RenderTracking } from '../utils/performance/components/RenderTracking';
34
- import measurements from '../utils/performance/measure-enum';
35
- import { PluginPerformanceObserver } from '../utils/performance/plugin-performance-observer';
36
- import { freezeUnsafeTransactionProperties } from '../utils/performance/safer-transactions';
37
- import { EVENT_NAME_ON_CHANGE } from '../utils/performance/track-transactions';
38
- import { validateNodes, validNode } from '../utils/validateNodes';
39
- import { PROSEMIRROR_RENDERED_DEGRADED_SEVERITY_THRESHOLD, PROSEMIRROR_RENDERED_NORMAL_SEVERITY_THRESHOLD } from './consts';
40
- import { createErrorReporter, createPMPlugins, processPluginsList } from './create-editor';
41
- import createPluginsList from './create-plugins-list';
42
- import { createSchema } from './create-schema';
43
- import { createFeatureFlagsFromProps } from './feature-flags-from-props';
44
- import { editorMessages } from './messages';
45
- var EDIT_AREA_ID = 'ak-editor-textarea';
46
- function handleEditorFocus(view) {
47
- if (view.hasFocus()) {
48
- return;
49
- }
50
- return window.setTimeout(function () {
51
- if (view.hasFocus()) {
52
- return;
53
- }
54
- if (!window.getSelection) {
55
- view.focus();
56
- return;
57
- }
58
- var domSelection = window.getSelection();
59
- if (!domSelection || domSelection.rangeCount === 0) {
60
- view.focus();
61
- return;
62
- }
63
- var range = domSelection.getRangeAt(0);
64
- // if selection is outside editor focus and exit
65
- if (range.startContainer.contains(view.dom)) {
66
- view.focus();
67
- return;
68
- }
69
- // set cursor/selection and focus
70
- var anchor = view.posAtDOM(range.startContainer, range.startOffset);
71
- var head = view.posAtDOM(range.endContainer, range.endOffset);
72
- // if anchor or head < 0 focus and exit
73
- if (anchor < 0 || head < 0) {
74
- view.focus();
75
- return;
76
- }
77
- var selection = TextSelection.create(view.state.doc, anchor, head);
78
- var tr = view.state.tr.setSelection(selection);
79
- view.dispatch(tr);
80
- view.focus();
81
- }, 0);
82
- }
83
- // Ignored via go/ees005
84
- // eslint-disable-next-line @repo/internal/react/no-class-components
85
- export var ReactEditorView = /*#__PURE__*/function (_React$Component) {
86
- function ReactEditorView(props) {
87
- var _this$props$editorPro3, _props$setEditorAPI;
88
- var _this;
89
- _classCallCheck(this, ReactEditorView);
90
- _this = _callSuper(this, ReactEditorView, [props]);
91
- _defineProperty(_this, "editorRef", /*#__PURE__*/React.createRef());
92
- // ProseMirror is instantiated prior to the initial React render cycle,
93
- // so we allow transactions by default, to avoid discarding the initial one.
94
- _defineProperty(_this, "canDispatchTransactions", true);
95
- _defineProperty(_this, "onPluginObservation", function (report) {
96
- var _this$pluginInjection;
97
- _this.dispatchAnalyticsEvent({
98
- action: ACTION.TRANSACTION_DISPATCHED,
99
- actionSubject: ACTION_SUBJECT.EDITOR,
100
- eventType: EVENT_TYPE.OPERATIONAL,
101
- attributes: {
102
- report: report,
103
- participants: ((_this$pluginInjection = _this.pluginInjectionAPI.api().collabEdit) === null || _this$pluginInjection === void 0 || (_this$pluginInjection = _this$pluginInjection.sharedState.currentState()) === null || _this$pluginInjection === void 0 || (_this$pluginInjection = _this$pluginInjection.participants) === null || _this$pluginInjection === void 0 ? void 0 : _this$pluginInjection.size()) || 1
104
- }
105
- });
106
- });
107
- _defineProperty(_this, "getEditorState", function () {
108
- var _this$view;
109
- return (_this$view = _this.view) === null || _this$view === void 0 ? void 0 : _this$view.state;
110
- });
111
- _defineProperty(_this, "getEditorView", function () {
112
- return _this.view;
113
- });
114
- _defineProperty(_this, "formatFullWidthAppearance", function (appearance) {
115
- if (appearance === 'full-width') {
116
- return FULL_WIDTH_MODE.FULL_WIDTH;
117
- }
118
- return FULL_WIDTH_MODE.FIXED_WIDTH;
119
- });
120
- _defineProperty(_this, "resetEditorState", function (_ref) {
121
- var _this$props$editorPro, _this$props$editorPro2;
122
- var doc = _ref.doc,
123
- shouldScrollToBottom = _ref.shouldScrollToBottom;
124
- if (!_this.view) {
125
- return;
126
- }
127
-
128
- // We cannot currently guarentee when all the portals will have re-rendered during a reconfigure
129
- // so we blur here to stop ProseMirror from trying to apply selection to detached nodes or
130
- // nodes that haven't been re-rendered to the document yet.
131
- _this.blur();
132
- _this.featureFlags = createFeatureFlagsFromProps(_this.props.editorProps.featureFlags);
133
- _this.editorState = _this.createEditorState({
134
- props: _this.props,
135
- doc: doc,
136
- resetting: true,
137
- selectionAtStart: !shouldScrollToBottom
138
- });
139
- _this.view.updateState(_this.editorState);
140
- (_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, {
141
- source: 'local'
142
- });
143
- });
144
- _defineProperty(_this, "blur", function () {
145
- if (!_this.view) {
146
- return;
147
- }
148
- if (_this.view.dom instanceof HTMLElement && _this.view.hasFocus()) {
149
- _this.view.dom.blur();
150
- }
151
-
152
- // The selectionToDOM method uses the document selection to determine currently selected node
153
- // We need to mimic blurring this as it seems doing the above is not enough.
154
- // @ts-expect-error
155
- var sel = _this.view.root.getSelection();
156
- if (sel) {
157
- sel.removeAllRanges();
158
- }
159
- });
160
- _defineProperty(_this, "handleAnalyticsEvent", function (payload) {
161
- fireAnalyticsEvent(_this.props.createAnalyticsEvent)(payload);
162
- });
163
- _defineProperty(_this, "editorPlugins", []);
164
- _defineProperty(_this, "createEditorState", function (options) {
165
- var _api$editorViewMode;
166
- var schema;
167
- if (_this.view) {
168
- if (options.resetting) {
169
- /**
170
- * ReactEditorView currently does NOT handle dynamic schema,
171
- * We are reusing the existing schema, and rely on #reconfigureState
172
- * to update `this.config`
173
- */
174
- schema = _this.view.state.schema;
175
- } else {
176
- /**
177
- * There's presently a number of issues with changing the schema of a
178
- * editor inflight. A significant issue is that we lose the ability
179
- * to keep track of a user's history as the internal plugin state
180
- * keeps a list of Steps to undo/redo (which are tied to the schema).
181
- * Without a good way to do work around this, we prevent this for now.
182
- */
183
- // eslint-disable-next-line no-console
184
- console.warn('The editor does not support changing the schema dynamically.');
185
- return _this.editorState;
186
- }
187
- } else {
188
- _this.config = processPluginsList(_this.getPlugins(options.props.preset));
189
- schema = createSchema(_this.config);
190
- }
191
- var contentTransformerProvider = options.props.editorProps.contentTransformerProvider;
192
- var plugins = createPMPlugins({
193
- schema: schema,
194
- dispatch: _this.dispatch,
195
- errorReporter: _this.errorReporter,
196
- editorConfig: _this.config,
197
- eventDispatcher: _this.eventDispatcher,
198
- providerFactory: options.props.providerFactory,
199
- portalProviderAPI: _this.props.portalProviderAPI,
200
- nodeViewPortalProviderAPI: _this.props.nodeViewPortalProviderAPI,
201
- dispatchAnalyticsEvent: _this.dispatchAnalyticsEvent,
202
- featureFlags: _this.featureFlags,
203
- getIntl: function getIntl() {
204
- return _this.props.intl;
205
- },
206
- onEditorStateUpdated: fg('platform_editor_catch_missing_injection_states') ? _this.pluginInjectionAPI.onEditorViewUpdated : undefined
207
- });
208
- _this.contentTransformer = contentTransformerProvider ? contentTransformerProvider(schema) : undefined;
209
- var doc;
210
- var api = _this.pluginInjectionAPI.api();
211
- // If we have a doc prop, we need to process it into a PMNode
212
-
213
- if (options.doc) {
214
- // if the collabEdit API is set, skip this validation due to potential pm validation errors
215
- // from docs that end up with invalid marks after processing (See #hot-111702 for more details)
216
-
217
- if ((api === null || api === void 0 ? void 0 : api.collabEdit) !== undefined && fg('editor_load_conf_collab_docs_without_checks') || options.props.editorProps.skipValidation) {
218
- doc = processRawValueWithoutValidation(schema, options.doc, _this.dispatchAnalyticsEvent);
219
- } else {
220
- doc = processRawValue(schema, options.doc, options.props.providerFactory, options.props.editorProps.sanitizePrivateContent, _this.contentTransformer, _this.dispatchAnalyticsEvent);
221
- }
222
- }
223
- var isViewMode = (api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.currentState().mode) === 'view';
224
- var selection;
225
- if (doc) {
226
- if (isViewMode) {
227
- var emptySelection = new TextSelection(doc.resolve(0));
228
- return EditorState.create({
229
- schema: schema,
230
- plugins: plugins,
231
- doc: doc,
232
- selection: emptySelection
233
- });
234
- } else {
235
- selection = options.selectionAtStart ? Selection.atStart(doc) : Selection.atEnd(doc);
236
- }
237
- }
238
- // Workaround for ED-3507: When media node is the last element, scrollIntoView throws an error
239
- var patchedSelection = selection ? Selection.findFrom(selection.$head, -1, true) || undefined : undefined;
240
- return EditorState.create({
241
- schema: schema,
242
- plugins: plugins,
243
- doc: doc,
244
- selection: patchedSelection
245
- });
246
- });
247
- _defineProperty(_this, "onEditorViewStateUpdated", function (_ref2) {
248
- var originalTransaction = _ref2.originalTransaction,
249
- transactions = _ref2.transactions,
250
- oldEditorState = _ref2.oldEditorState,
251
- newEditorState = _ref2.newEditorState;
252
- _this.config.onEditorViewStateUpdatedCallbacks.forEach(function (entry) {
253
- entry.callback({
254
- originalTransaction: originalTransaction,
255
- transactions: transactions,
256
- oldEditorState: oldEditorState,
257
- newEditorState: newEditorState
258
- });
259
- });
260
- });
261
- _defineProperty(_this, "dispatchTransaction", function (unsafeTransaction) {
262
- if (!_this.view) {
263
- return;
264
- }
265
- var nodes = findChangedNodesFromTransaction(unsafeTransaction);
266
- var changedNodesValid = validateNodes(nodes);
267
- var transaction = new Proxy(unsafeTransaction, freezeUnsafeTransactionProperties({
268
- dispatchAnalyticsEvent: _this.dispatchAnalyticsEvent,
269
- pluginKey: 'unknown-reacteditorview'
270
- }));
271
- if (changedNodesValid) {
272
- var oldEditorState = _this.view.state;
273
-
274
- // go ahead and update the state now we know the transaction is good
275
- var _this$view$state$appl = _this.view.state.applyTransaction(transaction),
276
- editorState = _this$view$state$appl.state,
277
- transactions = _this$view$state$appl.transactions;
278
- if (editorState === oldEditorState) {
279
- return;
280
- }
281
- _this.view.updateState(editorState);
282
- if (!fg('platform_editor_catch_missing_injection_states')) {
283
- _this.pluginInjectionAPI.onEditorViewUpdated({
284
- newEditorState: editorState,
285
- oldEditorState: oldEditorState
286
- });
287
- }
288
-
289
- // ED-25839: Investigate if we also want to migrate this API to use `onEditorStateUpdated` in `createPMPlugins`
290
- _this.onEditorViewStateUpdated({
291
- originalTransaction: transaction,
292
- transactions: transactions,
293
- oldEditorState: oldEditorState,
294
- newEditorState: editorState
295
- });
296
- if (_this.props.editorProps.onChange && transaction.docChanged) {
297
- var source = transaction.getMeta('isRemote') ? 'remote' : 'local';
298
- startMeasure(EVENT_NAME_ON_CHANGE);
299
- _this.props.editorProps.onChange(_this.view, {
300
- source: source
301
- });
302
- stopMeasure(EVENT_NAME_ON_CHANGE, function (duration, startTime) {
303
- _this.dispatchAnalyticsEvent({
304
- action: ACTION.ON_CHANGE_CALLBACK,
305
- actionSubject: ACTION_SUBJECT.EDITOR,
306
- eventType: EVENT_TYPE.OPERATIONAL,
307
- attributes: {
308
- duration: duration,
309
- startTime: startTime
310
- }
311
- });
312
- });
313
- }
314
- _this.editorState = editorState;
315
- } else {
316
- var invalidNodes = nodes.filter(function (node) {
317
- return !validNode(node);
318
- }).map(function (node) {
319
- return getDocStructure(node, {
320
- compact: true
321
- });
322
- });
323
- _this.dispatchAnalyticsEvent({
324
- action: ACTION.DISPATCHED_INVALID_TRANSACTION,
325
- actionSubject: ACTION_SUBJECT.EDITOR,
326
- eventType: EVENT_TYPE.OPERATIONAL,
327
- attributes: {
328
- analyticsEventPayloads: getAnalyticsEventsFromTransaction(transaction),
329
- invalidNodes: invalidNodes
330
- }
331
- });
332
- }
333
- });
334
- _defineProperty(_this, "getDirectEditorProps", function (state) {
335
- return {
336
- state: state || _this.editorState,
337
- dispatchTransaction: function dispatchTransaction(tr) {
338
- // Block stale transactions:
339
- // Prevent runtime exeptions from async transactions that would attempt to
340
- // update the DOM after React has unmounted the Editor.
341
- if (_this.canDispatchTransactions) {
342
- _this.dispatchTransaction(tr);
343
- }
344
- },
345
- // Disables the contentEditable attribute of the editor if the editor is disabled
346
- editable: function editable(_state) {
347
- return !_this.props.editorProps.disabled;
348
- },
349
- attributes: {
350
- 'data-gramm': 'false'
351
- }
352
- };
353
- });
354
- _defineProperty(_this, "createEditorView", function (node) {
355
- measureRender(measurements.PROSEMIRROR_RENDERED, function (_ref3) {
356
- var duration = _ref3.duration,
357
- startTime = _ref3.startTime,
358
- distortedDuration = _ref3.distortedDuration;
359
- _this.proseMirrorRenderedSeverity = getAnalyticsEventSeverity(duration, PROSEMIRROR_RENDERED_NORMAL_SEVERITY_THRESHOLD, PROSEMIRROR_RENDERED_DEGRADED_SEVERITY_THRESHOLD);
360
- if (_this.view) {
361
- var _this$pluginInjection2;
362
- var nodes = getNodesCount(_this.view.state.doc);
363
- var ttfb = getResponseEndTime();
364
- var contextIdentifier = (_this$pluginInjection2 = _this.pluginInjectionAPI.api().base) === null || _this$pluginInjection2 === void 0 ? void 0 : _this$pluginInjection2.sharedState.currentState();
365
- _this.dispatchAnalyticsEvent({
366
- action: ACTION.PROSEMIRROR_RENDERED,
367
- actionSubject: ACTION_SUBJECT.EDITOR,
368
- attributes: {
369
- duration: duration,
370
- startTime: startTime,
371
- nodes: nodes,
372
- ttfb: ttfb,
373
- severity: _this.proseMirrorRenderedSeverity,
374
- objectId: contextIdentifier === null || contextIdentifier === void 0 ? void 0 : contextIdentifier.objectId,
375
- distortedDuration: distortedDuration
376
- },
377
- eventType: EVENT_TYPE.OPERATIONAL
378
- });
379
- }
380
- });
381
-
382
- // Creates the editor-view from this.editorState. If an editor has been mounted
383
- // previously, this will contain the previous state of the editor.
384
- _this.view = new EditorView({
385
- mount: node
386
- }, _this.getDirectEditorProps());
387
- _this.pluginInjectionAPI.onEditorViewUpdated({
388
- newEditorState: _this.view.state,
389
- oldEditorState: undefined
390
- });
391
- });
392
- _defineProperty(_this, "handleEditorViewRef", function (node) {
393
- if (!_this.view && node) {
394
- _this.createEditorView(node);
395
- // Ignored via go/ees005
396
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
397
- var view = _this.view;
398
- _this.props.onEditorCreated({
399
- view: view,
400
- config: _this.config,
401
- eventDispatcher: _this.eventDispatcher,
402
- transformer: _this.contentTransformer
403
- });
404
- if (_this.props.editorProps.shouldFocus && view.props.editable && view.props.editable(view.state)) {
405
- _this.focusTimeoutId = handleEditorFocus(view);
406
- }
407
-
408
- // Force React to re-render so consumers get a reference to the editor view
409
- _this.forceUpdate();
410
- } else if (_this.view && !node) {
411
- // When the appearance is changed, React will call handleEditorViewRef with node === null
412
- // to destroy the old EditorView, before calling this method again with node === div to
413
- // create the new EditorView
414
- _this.props.onEditorDestroyed({
415
- view: _this.view,
416
- config: _this.config,
417
- eventDispatcher: _this.eventDispatcher,
418
- transformer: _this.contentTransformer
419
- });
420
-
421
- // Allows us to dispatch analytics within the plugin view.destory methods
422
- var analyticsConnected = _this.eventDispatcher.has(analyticsEventKey, _this.handleAnalyticsEvent);
423
- if (!analyticsConnected) {
424
- _this.eventDispatcher.on(analyticsEventKey, _this.handleAnalyticsEvent);
425
- }
426
- _this.view.destroy(); // Destroys the dom node & all node views
427
-
428
- if (!analyticsConnected) {
429
- _this.eventDispatcher.off(analyticsEventKey, _this.handleAnalyticsEvent);
430
- }
431
- _this.view = undefined;
432
- }
433
- });
434
- _defineProperty(_this, "dispatchAnalyticsEvent", function (payload) {
435
- if (_this.eventDispatcher) {
436
- var dispatch = createDispatch(_this.eventDispatcher);
437
- dispatch(analyticsEventKey, {
438
- payload: payload
439
- });
440
- }
441
- });
442
- _defineProperty(_this, "editorId", uuid());
443
- _defineProperty(_this, "createEditor", function (assistiveLabel, assistiveDescribedBy) {
444
- return /*#__PURE__*/React.createElement("div", {
445
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
446
- className: getUAPrefix(),
447
- key: "ProseMirror",
448
- ref: _this.handleEditorViewRef,
449
- "aria-label": assistiveLabel || _this.props.intl.formatMessage(editorMessages.editorAssistiveLabel)
450
- // setting aria-multiline to true when not mobile appearance.
451
- // because somehow mobile tests are failing when it set.
452
- // don't know why that is happening.
453
- // Created https://product-fabric.atlassian.net/jira/servicedesk/projects/DTR/queues/issue/DTR-1675
454
- // to investigate further.
455
- ,
456
- "aria-multiline": true,
457
- role: "textbox",
458
- id: EDIT_AREA_ID,
459
- "aria-describedby": assistiveDescribedBy,
460
- "data-editor-id": _this.editorId
461
- });
462
- });
463
- _defineProperty(_this, "editor", _this.createEditor(_this.props.editorProps.assistiveLabel, (_this$props$editorPro3 = _this.props.editorProps) === null || _this$props$editorPro3 === void 0 ? void 0 : _this$props$editorPro3.assistiveDescribedBy));
464
- _this.pluginInjectionAPI = new EditorPluginInjectionAPI({
465
- getEditorState: _this.getEditorState,
466
- getEditorView: _this.getEditorView,
467
- fireAnalyticsEvent: _this.handleAnalyticsEvent
468
- });
469
- var _api = _this.pluginInjectionAPI.api();
470
- (_props$setEditorAPI = props.setEditorAPI) === null || _props$setEditorAPI === void 0 || _props$setEditorAPI.call(props, _api);
471
- _this.eventDispatcher = new EventDispatcher();
472
- _this.dispatch = createDispatch(_this.eventDispatcher);
473
- _this.errorReporter = createErrorReporter(props.editorProps.errorReporterHandler);
474
- _this.pluginPerformanceObserver = new PluginPerformanceObserver(function (report) {
475
- return _this.onPluginObservation(report);
476
- }).withPlugins(function () {
477
- return _this.getPluginNames();
478
- }).withNodeCounts(function () {
479
- return _this.countNodes();
480
- });
481
- _this.featureFlags = createFeatureFlagsFromProps(_this.props.editorProps.featureFlags);
482
- var featureFlagsEnabled = _this.featureFlags ? getEnabledFeatureFlagKeys(_this.featureFlags) : [];
483
-
484
- // This needs to be before initialising editorState because
485
- // we dispatch analytics events in plugin initialisation
486
- _this.eventDispatcher.on(analyticsEventKey, _this.handleAnalyticsEvent);
487
- _this.eventDispatcher.on('resetEditorState', _this.resetEditorState);
488
- _this.editorState = _this.createEditorState({
489
- props: props,
490
- doc: props.editorProps.defaultValue,
491
- // ED-4759: Don't set selection at end for full-page editor - should be at start.
492
- selectionAtStart: isFullPage(props.editorProps.appearance)
493
- });
494
- _this.dispatchAnalyticsEvent({
495
- action: ACTION.STARTED,
496
- actionSubject: ACTION_SUBJECT.EDITOR,
497
- attributes: {
498
- platform: PLATFORMS.WEB,
499
- featureFlags: featureFlagsEnabled
500
- },
501
- eventType: EVENT_TYPE.UI
502
- });
503
- return _this;
504
- }
505
- _inherits(ReactEditorView, _React$Component);
506
- return _createClass(ReactEditorView, [{
507
- key: "transactionTracking",
508
- get:
509
- //TODO: clean up
510
- function get() {
511
- return {
512
- enabled: false
513
- };
514
- }
515
- }, {
516
- key: "getPluginNames",
517
- value: function getPluginNames() {
518
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
519
- return this.editorState.plugins.map(function (p) {
520
- return p.key;
521
- });
522
- }
523
- }, {
524
- key: "countNodes",
525
- value: function countNodes() {
526
- return _countNodes(this.editorState);
527
- }
528
- }, {
529
- key: "UNSAFE_componentWillReceiveProps",
530
- value:
531
- // Ignored via go/ees005
532
- // eslint-disable-next-line react/no-unsafe
533
- function UNSAFE_componentWillReceiveProps(nextProps) {
534
- var _nextProps$editorProp, _this$props$editorPro4;
535
- if (this.view && this.props.editorProps.disabled !== nextProps.editorProps.disabled) {
536
- // Disables the contentEditable attribute of the editor if the editor is disabled
537
- this.view.setProps({
538
- editable: function editable(_state) {
539
- return !nextProps.editorProps.disabled;
540
- }
541
- });
542
- if (!nextProps.editorProps.disabled && nextProps.editorProps.shouldFocus) {
543
- this.focusTimeoutId = handleEditorFocus(this.view);
544
- }
545
- }
546
- var appearance = this.props.editorProps.appearance;
547
- var nextAppearance = nextProps.editorProps.appearance;
548
- if (this.props.preset !== nextProps.preset) {
549
- this.reconfigureState(nextProps);
550
- }
551
- if (nextAppearance !== appearance) {
552
- if (nextAppearance === 'full-width' || appearance === 'full-width') {
553
- this.dispatchAnalyticsEvent({
554
- action: ACTION.CHANGED_FULL_WIDTH_MODE,
555
- actionSubject: ACTION_SUBJECT.EDITOR,
556
- eventType: EVENT_TYPE.TRACK,
557
- attributes: {
558
- previousMode: this.formatFullWidthAppearance(appearance),
559
- newMode: this.formatFullWidthAppearance(nextAppearance)
560
- }
561
- });
562
- }
563
- }
564
- if (nextProps.editorProps.assistiveLabel !== this.props.editorProps.assistiveLabel || ((_nextProps$editorProp = nextProps.editorProps) === null || _nextProps$editorProp === void 0 ? void 0 : _nextProps$editorProp.assistiveDescribedBy) !== ((_this$props$editorPro4 = this.props.editorProps) === null || _this$props$editorPro4 === void 0 ? void 0 : _this$props$editorPro4.assistiveDescribedBy)) {
565
- var _nextProps$editorProp2;
566
- this.editor = this.createEditor(nextProps.editorProps.assistiveLabel, (_nextProps$editorProp2 = nextProps.editorProps) === null || _nextProps$editorProp2 === void 0 ? void 0 : _nextProps$editorProp2.assistiveDescribedBy);
567
- }
568
- }
569
- }, {
570
- key: "reconfigureState",
571
- value: function reconfigureState(props) {
572
- var _this2 = this;
573
- if (!this.view) {
574
- return;
575
- }
576
-
577
- // We cannot currently guarentee when all the portals will have re-rendered during a reconfigure
578
- // so we blur here to stop ProseMirror from trying to apply selection to detached nodes or
579
- // nodes that haven't been re-rendered to the document yet.
580
- this.blur();
581
- var editorPlugins = this.getPlugins(props.preset);
582
- this.config = processPluginsList(editorPlugins);
583
- var state = this.editorState;
584
- var plugins = createPMPlugins({
585
- schema: state.schema,
586
- dispatch: this.dispatch,
587
- errorReporter: this.errorReporter,
588
- editorConfig: this.config,
589
- eventDispatcher: this.eventDispatcher,
590
- providerFactory: props.providerFactory,
591
- portalProviderAPI: props.portalProviderAPI,
592
- nodeViewPortalProviderAPI: props.nodeViewPortalProviderAPI,
593
- dispatchAnalyticsEvent: this.dispatchAnalyticsEvent,
594
- featureFlags: createFeatureFlagsFromProps(props.editorProps.featureFlags),
595
- getIntl: function getIntl() {
596
- return _this2.props.intl;
597
- },
598
- onEditorStateUpdated: fg('platform_editor_catch_missing_injection_states') ? this.pluginInjectionAPI.onEditorViewUpdated : undefined
599
- });
600
- var newState = state.reconfigure({
601
- plugins: plugins
602
- });
603
-
604
- // need to update the state first so when the view builds the nodeviews it is
605
- // using the latest plugins
606
- this.view.updateState(newState);
607
- return this.view.update(_objectSpread(_objectSpread({}, this.view.props), {}, {
608
- state: newState
609
- }));
610
- }
611
- }, {
612
- key: "componentDidMount",
613
- value: function componentDidMount() {
614
- // Transaction dispatching is already enabled by default prior to
615
- // mounting, but we reset it here, just in case the editor view
616
- // instance is ever recycled (mounted again after unmounting) with
617
- // the same key.
618
- // Although storing mounted state is an anti-pattern in React,
619
- // we do so here so that we can intercept and abort asynchronous
620
- // ProseMirror transactions when a dismount is imminent.
621
- this.canDispatchTransactions = true;
622
- }
623
-
624
- /**
625
- * Clean up any non-PM resources when the editor is unmounted
626
- */
627
- }, {
628
- key: "componentWillUnmount",
629
- value: function componentWillUnmount() {
630
- // We can ignore any transactions from this point onwards.
631
- // This serves to avoid potential runtime exceptions which could arise
632
- // from an async dispatched transaction after it's unmounted.
633
- this.canDispatchTransactions = false;
634
- clearTimeout(this.focusTimeoutId);
635
- if (this.reliabilityInterval) {
636
- clearInterval(this.reliabilityInterval);
637
- }
638
- this.pluginPerformanceObserver.disconnect();
639
- if (this.view) {
640
- // Destroy the state if the Editor is being unmounted
641
- var editorState = this.view.state;
642
- editorState.plugins.forEach(function (plugin) {
643
- var state = plugin.getState(editorState);
644
- if (state && state.destroy) {
645
- state.destroy();
646
- }
647
- });
648
- }
649
- this.eventDispatcher.destroy();
650
- // this.view will be destroyed when React unmounts in handleEditorViewRef
651
- }
652
- }, {
653
- key: "getPlugins",
654
- value:
655
- // Helper to allow tests to inject plugins directly
656
- function getPlugins(preset) {
657
- var plugins = createPluginsList(preset, this.props.editorProps, this.pluginInjectionAPI);
658
- this.editorPlugins = plugins;
659
- return this.editorPlugins;
660
- }
661
- }, {
662
- key: "render",
663
- value: function render() {
664
- var _this$props$render, _this$props$render2, _this$props;
665
- // Render tracking is firing too many events in Jira so we are disabling them for now. See - https://product-fabric.atlassian.net/browse/ED-25616
666
- var renderTrackingEnabled = !fg('platform_editor_disable_rerender_tracking_jira');
667
- var useShallow = true;
668
- return /*#__PURE__*/React.createElement(ReactEditorViewContext.Provider, {
669
- value: {
670
- editorRef: this.editorRef,
671
- editorView: this.view,
672
- popupsMountPoint: this.props.editorProps.popupsMountPoint
673
- }
674
- }, renderTrackingEnabled && /*#__PURE__*/React.createElement(RenderTracking, {
675
- componentProps: this.props,
676
- action: ACTION.RE_RENDERED,
677
- actionSubject: ACTION_SUBJECT.REACT_EDITOR_VIEW,
678
- handleAnalyticsEvent: this.handleAnalyticsEvent,
679
- useShallow: useShallow
680
- }), this.props.render ? (_this$props$render = (_this$props$render2 = (_this$props = this.props).render) === null || _this$props$render2 === void 0 ? void 0 : _this$props$render2.call(_this$props, {
681
- editor: this.editor,
682
- view: this.view,
683
- config: this.config,
684
- eventDispatcher: this.eventDispatcher,
685
- transformer: this.contentTransformer,
686
- dispatchAnalyticsEvent: this.dispatchAnalyticsEvent,
687
- editorRef: this.editorRef,
688
- editorAPI: this.props.editorAPI
689
- })) !== null && _this$props$render !== void 0 ? _this$props$render : this.editor : this.editor);
690
- }
691
- }]);
692
- }(React.Component);
693
- function getUAPrefix() {
694
- if (browser.chrome) {
695
- return 'ua-chrome';
696
- } else if (browser.ie) {
697
- return 'ua-ie';
698
- } else if (browser.gecko) {
699
- return 'ua-firefox';
700
- } else if (browser.safari) {
701
- return 'ua-safari';
702
- }
703
- return '';
704
- }
705
- export default injectIntl(ReactEditorView);