@atlaskit/editor-plugin-expand 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +13 -0
  3. package/README.md +30 -0
  4. package/dist/cjs/commands.js +184 -0
  5. package/dist/cjs/index.js +12 -0
  6. package/dist/cjs/nodeviews/index.js +494 -0
  7. package/dist/cjs/plugin.js +101 -0
  8. package/dist/cjs/pm-plugins/keymap.js +170 -0
  9. package/dist/cjs/pm-plugins/main.js +85 -0
  10. package/dist/cjs/pm-plugins/plugin-factory.js +15 -0
  11. package/dist/cjs/reducer.js +20 -0
  12. package/dist/cjs/toolbar.js +59 -0
  13. package/dist/cjs/types.js +5 -0
  14. package/dist/cjs/ui/ExpandIconButton.js +107 -0
  15. package/dist/cjs/utils.js +24 -0
  16. package/dist/es2019/commands.js +161 -0
  17. package/dist/es2019/index.js +1 -0
  18. package/dist/es2019/nodeviews/index.js +484 -0
  19. package/dist/es2019/plugin.js +86 -0
  20. package/dist/es2019/pm-plugins/keymap.js +197 -0
  21. package/dist/es2019/pm-plugins/main.js +73 -0
  22. package/dist/es2019/pm-plugins/plugin-factory.js +9 -0
  23. package/dist/es2019/reducer.js +11 -0
  24. package/dist/es2019/toolbar.js +52 -0
  25. package/dist/es2019/types.js +1 -0
  26. package/dist/es2019/ui/ExpandIconButton.js +88 -0
  27. package/dist/es2019/utils.js +1 -0
  28. package/dist/esm/commands.js +177 -0
  29. package/dist/esm/index.js +1 -0
  30. package/dist/esm/nodeviews/index.js +486 -0
  31. package/dist/esm/plugin.js +88 -0
  32. package/dist/esm/pm-plugins/keymap.js +165 -0
  33. package/dist/esm/pm-plugins/main.js +77 -0
  34. package/dist/esm/pm-plugins/plugin-factory.js +9 -0
  35. package/dist/esm/reducer.js +13 -0
  36. package/dist/esm/toolbar.js +52 -0
  37. package/dist/esm/types.js +1 -0
  38. package/dist/esm/ui/ExpandIconButton.js +98 -0
  39. package/dist/esm/utils.js +1 -0
  40. package/dist/types/commands.d.ts +13 -0
  41. package/dist/types/index.d.ts +3 -0
  42. package/dist/types/nodeviews/index.d.ts +55 -0
  43. package/dist/types/plugin.d.ts +24 -0
  44. package/dist/types/pm-plugins/keymap.d.ts +4 -0
  45. package/dist/types/pm-plugins/main.d.ts +7 -0
  46. package/dist/types/pm-plugins/plugin-factory.d.ts +3 -0
  47. package/dist/types/reducer.d.ts +3 -0
  48. package/dist/types/toolbar.d.ts +3 -0
  49. package/dist/types/types.d.ts +31 -0
  50. package/dist/types/ui/ExpandIconButton.d.ts +43 -0
  51. package/dist/types/utils.d.ts +1 -0
  52. package/dist/types-ts4.5/commands.d.ts +13 -0
  53. package/dist/types-ts4.5/index.d.ts +3 -0
  54. package/dist/types-ts4.5/nodeviews/index.d.ts +55 -0
  55. package/dist/types-ts4.5/plugin.d.ts +24 -0
  56. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +4 -0
  57. package/dist/types-ts4.5/pm-plugins/main.d.ts +7 -0
  58. package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +3 -0
  59. package/dist/types-ts4.5/reducer.d.ts +3 -0
  60. package/dist/types-ts4.5/toolbar.d.ts +3 -0
  61. package/dist/types-ts4.5/types.d.ts +31 -0
  62. package/dist/types-ts4.5/ui/ExpandIconButton.d.ts +43 -0
  63. package/dist/types-ts4.5/utils.d.ts +1 -0
  64. package/package.json +104 -0
  65. package/report.api.md +93 -0
  66. package/tmp/api-report-tmp.d.ts +62 -0
@@ -0,0 +1,486 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ import React from 'react';
5
+ import ReactDOM from 'react-dom';
6
+ import { keyName } from 'w3c-keyname';
7
+ import { GapCursorSelection, RelativeSelectionPos, Side } from '@atlaskit/editor-common/selection';
8
+ import { expandClassNames } from '@atlaskit/editor-common/styles';
9
+ import { expandMessages } from '@atlaskit/editor-common/ui';
10
+ import { closestElement, isEmptyNode } from '@atlaskit/editor-common/utils';
11
+ import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
12
+ import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
13
+ import { deleteExpandAtPos, setSelectionInsideExpand, toggleExpandExpanded, updateExpandTitle } from '../commands';
14
+ import { ExpandIconButton } from '../ui/ExpandIconButton';
15
+ function buildExpandClassName(type, expanded) {
16
+ return "".concat(expandClassNames.prefix, " ").concat(expandClassNames.type(type), " ").concat(expanded ? expandClassNames.expanded : '');
17
+ }
18
+ var toDOM = function toDOM(node, intl) {
19
+ return ['div', {
20
+ // prettier-ignore
21
+ 'class': buildExpandClassName(node.type.name, node.attrs.__expanded),
22
+ 'data-node-type': node.type.name,
23
+ 'data-title': node.attrs.title
24
+ }, ['div', {
25
+ // prettier-ignore
26
+ 'class': expandClassNames.titleContainer,
27
+ contenteditable: 'false',
28
+ // Element gains access to focus events.
29
+ // This is needed to prevent PM gaining access
30
+ // on interacting with our controls.
31
+ tabindex: '-1'
32
+ },
33
+ // prettier-ignore
34
+ ['div', {
35
+ 'class': expandClassNames.icon
36
+ }], ['div', {
37
+ // prettier-ignore
38
+ 'class': expandClassNames.inputContainer
39
+ }, ['input', {
40
+ // prettier-ignore
41
+ 'class': expandClassNames.titleInput,
42
+ value: node.attrs.title,
43
+ placeholder: intl && intl.formatMessage(expandMessages.expandPlaceholderText) || expandMessages.expandPlaceholderText.defaultMessage,
44
+ type: 'text'
45
+ }]]],
46
+ // prettier-ignore
47
+ ['div', {
48
+ 'class': expandClassNames.content
49
+ }, 0]];
50
+ };
51
+ export var ExpandNodeView = /*#__PURE__*/function () {
52
+ function ExpandNodeView(node, view, getPos, getIntl, isMobile, featureFlags, selectNearNode, api) {
53
+ var _this = this;
54
+ _classCallCheck(this, ExpandNodeView);
55
+ _defineProperty(this, "allowInteractiveExpand", true);
56
+ _defineProperty(this, "isMobile", false);
57
+ _defineProperty(this, "focusTitle", function () {
58
+ if (_this.input) {
59
+ var _this$view = _this.view,
60
+ state = _this$view.state,
61
+ dispatch = _this$view.dispatch;
62
+ if (_this.selectNearNode) {
63
+ var tr = _this.selectNearNode({
64
+ selectionRelativeToNode: RelativeSelectionPos.Start
65
+ })(state);
66
+ if (dispatch) {
67
+ dispatch(tr);
68
+ }
69
+ }
70
+ var pos = _this.getPos();
71
+ if (typeof pos === 'number') {
72
+ setSelectionInsideExpand(pos)(state, dispatch, _this.view);
73
+ }
74
+ _this.input.focus();
75
+ }
76
+ });
77
+ _defineProperty(this, "handleIconKeyDown", function (event) {
78
+ switch (keyName(event)) {
79
+ case 'Tab':
80
+ event.preventDefault();
81
+ _this.focusTitle();
82
+ break;
83
+ case 'Enter':
84
+ event.preventDefault();
85
+ _this.handleClick(event);
86
+ break;
87
+ }
88
+ });
89
+ _defineProperty(this, "isAllowInteractiveExpandEnabled", function () {
90
+ return _this.featureFlags && !!_this.featureFlags.interactiveExpand;
91
+ });
92
+ _defineProperty(this, "handleClick", function (event) {
93
+ var pos = _this.getPos();
94
+ if (typeof pos !== 'number') {
95
+ return;
96
+ }
97
+ var target = event.target;
98
+ var _this$view2 = _this.view,
99
+ state = _this$view2.state,
100
+ dispatch = _this$view2.dispatch;
101
+ if (closestElement(target, ".".concat(expandClassNames.icon))) {
102
+ var _this$api;
103
+ if (!_this.isAllowInteractiveExpandEnabled()) {
104
+ return;
105
+ }
106
+ event.stopPropagation();
107
+
108
+ // We blur the editorView, to prevent any keyboard showing on mobile
109
+ // When we're interacting with the expand toggle
110
+ if (_this.view.dom instanceof HTMLElement) {
111
+ _this.view.dom.blur();
112
+ }
113
+ toggleExpandExpanded((_this$api = _this.api) === null || _this$api === void 0 || (_this$api = _this$api.analytics) === null || _this$api === void 0 ? void 0 : _this$api.actions)(pos, _this.node.type)(state, dispatch);
114
+ return;
115
+ }
116
+ if (target === _this.input) {
117
+ event.stopPropagation();
118
+ _this.focusTitle();
119
+ return;
120
+ }
121
+ });
122
+ _defineProperty(this, "handleInput", function (event) {
123
+ var pos = _this.getPos();
124
+ if (typeof pos !== 'number') {
125
+ return;
126
+ }
127
+ var target = event.target;
128
+ if (target === _this.input) {
129
+ event.stopPropagation();
130
+ var _this$view3 = _this.view,
131
+ state = _this$view3.state,
132
+ dispatch = _this$view3.dispatch;
133
+ updateExpandTitle(target.value, pos, _this.node.type)(state, dispatch);
134
+ }
135
+ });
136
+ _defineProperty(this, "handleFocus", function (event) {
137
+ event.stopImmediatePropagation();
138
+ });
139
+ _defineProperty(this, "handleTitleKeydown", function (event) {
140
+ switch (keyName(event)) {
141
+ case 'Enter':
142
+ _this.toggleExpand();
143
+ break;
144
+ case 'Tab':
145
+ case 'ArrowDown':
146
+ _this.moveToOutsideOfTitle(event);
147
+ break;
148
+ case 'ArrowRight':
149
+ _this.handleArrowRightFromTitle(event);
150
+ break;
151
+ case 'ArrowLeft':
152
+ _this.handleArrowLeftFromTitle(event);
153
+ break;
154
+ case 'ArrowUp':
155
+ _this.setLeftGapCursor(event);
156
+ break;
157
+ case 'Backspace':
158
+ _this.deleteExpand(event);
159
+ break;
160
+ }
161
+ });
162
+ _defineProperty(this, "deleteExpand", function (event) {
163
+ if (!_this.input) {
164
+ return;
165
+ }
166
+ var pos = _this.getPos();
167
+ if (typeof pos !== 'number') {
168
+ return;
169
+ }
170
+ var _this$input = _this.input,
171
+ selectionStart = _this$input.selectionStart,
172
+ selectionEnd = _this$input.selectionEnd;
173
+ if (selectionStart !== selectionEnd || selectionStart !== 0) {
174
+ return;
175
+ }
176
+ var state = _this.view.state;
177
+ var expandNode = _this.node;
178
+ if (expandNode && isEmptyNode(state.schema)(expandNode)) {
179
+ var _this$api2;
180
+ deleteExpandAtPos((_this$api2 = _this.api) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.analytics) === null || _this$api2 === void 0 ? void 0 : _this$api2.actions)(pos, expandNode)(state, _this.view.dispatch);
181
+ }
182
+ });
183
+ _defineProperty(this, "toggleExpand", function () {
184
+ var pos = _this.getPos();
185
+ if (typeof pos !== 'number') {
186
+ return;
187
+ }
188
+ if (_this.isAllowInteractiveExpandEnabled()) {
189
+ var _this$api3;
190
+ var _this$view4 = _this.view,
191
+ state = _this$view4.state,
192
+ dispatch = _this$view4.dispatch;
193
+ toggleExpandExpanded((_this$api3 = _this.api) === null || _this$api3 === void 0 || (_this$api3 = _this$api3.analytics) === null || _this$api3 === void 0 ? void 0 : _this$api3.actions)(pos, _this.node.type)(state, dispatch);
194
+ }
195
+ });
196
+ _defineProperty(this, "moveToOutsideOfTitle", function (event) {
197
+ event.preventDefault();
198
+ var _this$view5 = _this.view,
199
+ state = _this$view5.state,
200
+ dispatch = _this$view5.dispatch;
201
+ var expandPos = _this.getPos();
202
+ if (typeof expandPos !== 'number') {
203
+ return;
204
+ }
205
+ var pos = expandPos;
206
+ if (_this.isCollapsed()) {
207
+ pos = expandPos + _this.node.nodeSize;
208
+ }
209
+ var resolvedPos = state.doc.resolve(pos);
210
+ if (!resolvedPos) {
211
+ return;
212
+ }
213
+ if (_this.isCollapsed() && resolvedPos.nodeAfter && ['expand', 'nestedExpand'].indexOf(resolvedPos.nodeAfter.type.name) > -1) {
214
+ return _this.setRightGapCursor(event);
215
+ }
216
+ var sel = Selection.findFrom(resolvedPos, 1, true);
217
+ if (sel) {
218
+ // If the input has focus, ProseMirror doesn't
219
+ // Give PM focus back before changing our selection
220
+ _this.view.focus();
221
+ dispatch(state.tr.setSelection(sel));
222
+ }
223
+ });
224
+ _defineProperty(this, "isCollapsed", function () {
225
+ return !_this.node.attrs.__expanded;
226
+ });
227
+ _defineProperty(this, "setRightGapCursor", function (event) {
228
+ if (!_this.input) {
229
+ return;
230
+ }
231
+ var pos = _this.getPos();
232
+ if (typeof pos !== 'number') {
233
+ return;
234
+ }
235
+ var _this$input2 = _this.input,
236
+ value = _this$input2.value,
237
+ selectionStart = _this$input2.selectionStart,
238
+ selectionEnd = _this$input2.selectionEnd;
239
+ if (selectionStart === selectionEnd && selectionStart === value.length) {
240
+ var _this$view6 = _this.view,
241
+ state = _this$view6.state,
242
+ dispatch = _this$view6.dispatch;
243
+ event.preventDefault();
244
+ _this.view.focus();
245
+ dispatch(state.tr.setSelection(new GapCursorSelection(state.doc.resolve(_this.node.nodeSize + pos), Side.RIGHT)));
246
+ }
247
+ });
248
+ _defineProperty(this, "setLeftGapCursor", function (event) {
249
+ if (!_this.input) {
250
+ return;
251
+ }
252
+ var pos = _this.getPos();
253
+ if (typeof pos !== 'number') {
254
+ return;
255
+ }
256
+ var _this$input3 = _this.input,
257
+ selectionStart = _this$input3.selectionStart,
258
+ selectionEnd = _this$input3.selectionEnd;
259
+ if (selectionStart === selectionEnd && selectionStart === 0) {
260
+ event.preventDefault();
261
+ var _this$view7 = _this.view,
262
+ state = _this$view7.state,
263
+ dispatch = _this$view7.dispatch;
264
+ _this.view.focus();
265
+ dispatch(state.tr.setSelection(new GapCursorSelection(state.doc.resolve(pos), Side.LEFT)));
266
+ }
267
+ });
268
+ _defineProperty(this, "handleArrowRightFromTitle", function (event) {
269
+ if (!_this.input || !_this.selectNearNode) {
270
+ return;
271
+ }
272
+ var pos = _this.getPos();
273
+ if (typeof pos !== 'number') {
274
+ return;
275
+ }
276
+ var _this$input4 = _this.input,
277
+ value = _this$input4.value,
278
+ selectionStart = _this$input4.selectionStart,
279
+ selectionEnd = _this$input4.selectionEnd;
280
+ if (selectionStart === selectionEnd && selectionStart === value.length) {
281
+ event.preventDefault();
282
+ var _this$view8 = _this.view,
283
+ state = _this$view8.state,
284
+ dispatch = _this$view8.dispatch;
285
+ _this.view.focus();
286
+ var tr = _this.selectNearNode({
287
+ selectionRelativeToNode: RelativeSelectionPos.End,
288
+ selection: NodeSelection.create(state.doc, pos)
289
+ })(state);
290
+ if (dispatch) {
291
+ dispatch(tr);
292
+ }
293
+ }
294
+ });
295
+ _defineProperty(this, "handleArrowLeftFromTitle", function (event) {
296
+ if (!_this.input || !_this.selectNearNode) {
297
+ return;
298
+ }
299
+ var pos = _this.getPos();
300
+ if (typeof pos !== 'number') {
301
+ return;
302
+ }
303
+ var _this$input5 = _this.input,
304
+ selectionStart = _this$input5.selectionStart,
305
+ selectionEnd = _this$input5.selectionEnd;
306
+ if (selectionStart === selectionEnd && selectionStart === 0) {
307
+ var _this$api4;
308
+ event.preventDefault();
309
+ var _this$view9 = _this.view,
310
+ state = _this$view9.state,
311
+ dispatch = _this$view9.dispatch;
312
+ _this.view.focus();
313
+ var selectionSharedState = ((_this$api4 = _this.api) === null || _this$api4 === void 0 || (_this$api4 = _this$api4.selection) === null || _this$api4 === void 0 ? void 0 : _this$api4.sharedState.currentState()) || {};
314
+ // selectionRelativeToNode is undefined when user clicked to select node, then hit left to get focus in title
315
+ // This is a special case where we want to bypass node selection and jump straight to gap cursor
316
+ if ((selectionSharedState === null || selectionSharedState === void 0 ? void 0 : selectionSharedState.selectionRelativeToNode) === undefined) {
317
+ var tr = _this.selectNearNode({
318
+ selectionRelativeToNode: undefined,
319
+ selection: new GapCursorSelection(state.doc.resolve(pos), Side.LEFT)
320
+ })(state);
321
+ if (dispatch) {
322
+ dispatch(tr);
323
+ }
324
+ } else {
325
+ var _tr = _this.selectNearNode({
326
+ selectionRelativeToNode: RelativeSelectionPos.Start,
327
+ selection: NodeSelection.create(state.doc, pos)
328
+ })(state);
329
+ if (dispatch) {
330
+ dispatch(_tr);
331
+ }
332
+ }
333
+ }
334
+ });
335
+ this.selectNearNode = selectNearNode;
336
+ this.intl = getIntl();
337
+ var _DOMSerializer$render = DOMSerializer.renderSpec(document, toDOM(node, this.intl)),
338
+ dom = _DOMSerializer$render.dom,
339
+ contentDOM = _DOMSerializer$render.contentDOM;
340
+ this.getPos = getPos;
341
+ this.view = view;
342
+ this.node = node;
343
+ this.dom = dom;
344
+ this.contentDOM = contentDOM;
345
+ this.isMobile = isMobile;
346
+ this.featureFlags = featureFlags;
347
+ this.api = api;
348
+ this.icon = this.dom.querySelector(".".concat(expandClassNames.icon));
349
+ this.input = this.dom.querySelector(".".concat(expandClassNames.titleInput));
350
+ this.titleContainer = this.dom.querySelector(".".concat(expandClassNames.titleContainer));
351
+ this.content = this.dom.querySelector(".".concat(expandClassNames.content));
352
+ this.renderIcon(this.intl);
353
+ this.initHandlers();
354
+ }
355
+ _createClass(ExpandNodeView, [{
356
+ key: "initHandlers",
357
+ value: function initHandlers() {
358
+ if (this.dom) {
359
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
360
+ this.dom.addEventListener('click', this.handleClick);
361
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
362
+ this.dom.addEventListener('input', this.handleInput);
363
+ }
364
+ if (this.input) {
365
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
366
+ this.input.addEventListener('keydown', this.handleTitleKeydown);
367
+ }
368
+ if (this.titleContainer) {
369
+ // If the user interacts in our title bar (either toggle or input)
370
+ // Prevent ProseMirror from getting a focus event (causes weird selection issues).
371
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
372
+ this.titleContainer.addEventListener('focus', this.handleFocus);
373
+ }
374
+ if (this.icon) {
375
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
376
+ this.icon.addEventListener('keydown', this.handleIconKeyDown);
377
+ }
378
+ }
379
+ }, {
380
+ key: "renderIcon",
381
+ value: function renderIcon(intl, node) {
382
+ if (!this.icon) {
383
+ return;
384
+ }
385
+ var _ref = node && node.attrs || this.node.attrs,
386
+ __expanded = _ref.__expanded;
387
+ ReactDOM.render( /*#__PURE__*/React.createElement(ExpandIconButton, {
388
+ intl: intl,
389
+ allowInteractiveExpand: this.isAllowInteractiveExpandEnabled(),
390
+ expanded: __expanded
391
+ }), this.icon);
392
+ }
393
+ }, {
394
+ key: "stopEvent",
395
+ value: function stopEvent(event) {
396
+ var target = event.target;
397
+ return target === this.input || target === this.icon || !!closestElement(target, ".".concat(expandClassNames.icon));
398
+ }
399
+ }, {
400
+ key: "ignoreMutation",
401
+ value: function ignoreMutation(mutationRecord) {
402
+ // ME-1931: Mobile relies on composition which creates dom mutations. If we ignore them, prosemirror
403
+ // does not recognise the changes and reverts them.
404
+ if (this.isMobile && (mutationRecord.type === 'characterData' || mutationRecord.type === 'childList')) {
405
+ return false;
406
+ }
407
+ if (mutationRecord.type === 'selection') {
408
+ return false;
409
+ }
410
+ return true;
411
+ }
412
+ }, {
413
+ key: "update",
414
+ value: function update(node, _decorations) {
415
+ var _this2 = this;
416
+ if (this.node.type === node.type) {
417
+ if (this.node.attrs.__expanded !== node.attrs.__expanded) {
418
+ // Instead of re-rendering the view on an expand toggle
419
+ // we toggle a class name to hide the content and animate the chevron.
420
+ if (this.dom) {
421
+ this.dom.classList.toggle(expandClassNames.expanded);
422
+ this.renderIcon(this && this.intl, node);
423
+ }
424
+ if (this.content) {
425
+ // Disallow interaction/selection inside when collapsed.
426
+ this.content.setAttribute('contenteditable', node.attrs.__expanded);
427
+ }
428
+ }
429
+
430
+ // During a collab session the title doesn't sync with other users
431
+ // since we're intentionally being less aggressive about re-rendering.
432
+ // We also apply a rAF to avoid abrupt continuous replacement of the title.
433
+ window.requestAnimationFrame(function () {
434
+ if (_this2.input && _this2.node.attrs.title !== _this2.input.value) {
435
+ _this2.input.value = _this2.node.attrs.title;
436
+ }
437
+ });
438
+ this.node = node;
439
+ return true;
440
+ }
441
+ return false;
442
+ }
443
+ }, {
444
+ key: "destroy",
445
+ value: function destroy() {
446
+ if (this.dom) {
447
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
448
+ this.dom.removeEventListener('click', this.handleClick);
449
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
450
+ this.dom.removeEventListener('input', this.handleInput);
451
+ }
452
+ if (this.input) {
453
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
454
+ this.input.removeEventListener('keydown', this.handleTitleKeydown);
455
+ }
456
+ if (this.titleContainer) {
457
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
458
+ this.titleContainer.removeEventListener('focus', this.handleFocus);
459
+ }
460
+ if (this.icon) {
461
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
462
+ this.icon.removeEventListener('keydown', this.handleIconKeyDown);
463
+ ReactDOM.unmountComponentAtNode(this.icon);
464
+ }
465
+
466
+ // @ts-ignore - [unblock prosemirror bump] reset non optional prop to undefined to clear reference
467
+ this.dom = undefined;
468
+ this.contentDOM = undefined;
469
+ this.icon = undefined;
470
+ this.input = undefined;
471
+ this.titleContainer = undefined;
472
+ this.content = undefined;
473
+ }
474
+ }]);
475
+ return ExpandNodeView;
476
+ }();
477
+ export default function (_ref2) {
478
+ var getIntl = _ref2.getIntl,
479
+ isMobile = _ref2.isMobile,
480
+ featureFlags = _ref2.featureFlags,
481
+ api = _ref2.api;
482
+ return function (node, view, getPos) {
483
+ var _api$selection;
484
+ return new ExpandNodeView(node, view, getPos, getIntl, isMobile, featureFlags, api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.actions) === null || _api$selection === void 0 ? void 0 : _api$selection.selectNearNode, api);
485
+ };
486
+ }
@@ -0,0 +1,88 @@
1
+ import React from 'react';
2
+ import { expand, nestedExpand } from '@atlaskit/adf-schema';
3
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
5
+ import { IconExpand } from '@atlaskit/editor-common/quick-insert';
6
+ import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
7
+ import { createExpandNode, insertExpand } from './commands';
8
+ import { expandKeymap } from './pm-plugins/keymap';
9
+ import { createPlugin } from './pm-plugins/main';
10
+ import { getToolbarConfig } from './toolbar';
11
+ export var expandPlugin = function expandPlugin(_ref) {
12
+ var _api$featureFlags, _api$analytics;
13
+ var _ref$config = _ref.config,
14
+ options = _ref$config === void 0 ? {} : _ref$config,
15
+ api = _ref.api;
16
+ var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {};
17
+ return {
18
+ name: 'expand',
19
+ nodes: function nodes() {
20
+ return [{
21
+ name: 'expand',
22
+ node: expand
23
+ }, {
24
+ name: 'nestedExpand',
25
+ node: nestedExpand
26
+ }];
27
+ },
28
+ actions: {
29
+ insertExpand: insertExpand(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
30
+ },
31
+ pmPlugins: function pmPlugins() {
32
+ return [{
33
+ name: 'expand',
34
+ plugin: function plugin(_ref2) {
35
+ var dispatch = _ref2.dispatch,
36
+ getIntl = _ref2.getIntl;
37
+ return createPlugin(dispatch, getIntl, options.appearance, options.useLongPressSelection, featureFlags, api);
38
+ }
39
+ }, {
40
+ name: 'expandKeymap',
41
+ plugin: function plugin() {
42
+ return expandKeymap(api);
43
+ }
44
+ }];
45
+ },
46
+ pluginsOptions: {
47
+ floatingToolbar: getToolbarConfig(api),
48
+ quickInsert: function quickInsert(_ref3) {
49
+ var formatMessage = _ref3.formatMessage;
50
+ if (options && options.allowInsertion !== true) {
51
+ return [];
52
+ }
53
+ return [{
54
+ id: 'expand',
55
+ title: formatMessage(messages.expand),
56
+ description: formatMessage(messages.expandDescription),
57
+ keywords: ['accordion', 'collapse'],
58
+ priority: 600,
59
+ icon: function icon() {
60
+ return /*#__PURE__*/React.createElement(IconExpand, null);
61
+ },
62
+ action: function action(insert, state) {
63
+ var _api$analytics2;
64
+ var node = createExpandNode(state);
65
+ if (!node) {
66
+ return false;
67
+ }
68
+ var tr = state.selection.empty ? insert(node) : createWrapSelectionTransaction({
69
+ state: state,
70
+ type: node.type
71
+ });
72
+ api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.attachAnalyticsEvent({
73
+ action: ACTION.INSERTED,
74
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
75
+ actionSubjectId: node.type === state.schema.nodes.nestedExpand ? ACTION_SUBJECT_ID.NESTED_EXPAND : ACTION_SUBJECT_ID.EXPAND,
76
+ attributes: {
77
+ inputMethod: INPUT_METHOD.QUICK_INSERT
78
+ },
79
+ eventType: EVENT_TYPE.TRACK
80
+ })(tr);
81
+ return tr;
82
+ }
83
+ }];
84
+ }
85
+ }
86
+ };
87
+ };
88
+ export { pluginKey } from './pm-plugins/plugin-factory';