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