@atlaskit/editor-core 189.3.13 → 189.3.15

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 (167) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/create-editor/ErrorBoundary.js +1 -1
  3. package/dist/cjs/nodeviews/getInlineNodeViewProducer.styles.js +1 -1
  4. package/dist/cjs/plugins/analytics/index.js +0 -6
  5. package/dist/cjs/plugins/analytics/utils.js +0 -29
  6. package/dist/cjs/plugins/breakout/index.js +3 -3
  7. package/dist/cjs/plugins/breakout/ui/LayoutButton.js +4 -4
  8. package/dist/cjs/plugins/find-replace/FindReplaceToolbarButtonWithState.js +32 -30
  9. package/dist/cjs/plugins/find-replace/commands-with-analytics.js +85 -71
  10. package/dist/cjs/plugins/find-replace/index.js +5 -2
  11. package/dist/cjs/plugins/find-replace/keymap.js +4 -4
  12. package/dist/cjs/plugins/index.js +1 -24
  13. package/dist/cjs/plugins/mobile-dimensions/index.js +6 -0
  14. package/dist/cjs/presets/context.js +5 -3
  15. package/dist/cjs/presets/universal.js +14 -4
  16. package/dist/cjs/ui/Appearance/Chromeless.js +18 -9
  17. package/dist/cjs/ui/Appearance/Comment/Comment.js +1 -1
  18. package/dist/cjs/ui/Appearance/FullPage/FullPageToolbar.js +3 -2
  19. package/dist/cjs/ui/AppearanceComponents/Mobile.js +7 -9
  20. package/dist/cjs/{plugins/expand/ui/styles.js → ui/ContentStyles/expand.js} +11 -8
  21. package/dist/cjs/ui/ContentStyles/index.js +4 -4
  22. package/dist/cjs/ui/ToolbarFeedback/index.js +1 -1
  23. package/dist/cjs/use-preset.js +0 -1
  24. package/dist/cjs/version-wrapper.js +1 -1
  25. package/dist/es2019/create-editor/ErrorBoundary.js +0 -2
  26. package/dist/es2019/nodeviews/getInlineNodeViewProducer.styles.js +1 -1
  27. package/dist/es2019/plugins/analytics/index.js +1 -1
  28. package/dist/es2019/plugins/analytics/utils.js +0 -24
  29. package/dist/es2019/plugins/breakout/index.js +1 -1
  30. package/dist/es2019/plugins/breakout/ui/LayoutButton.js +1 -1
  31. package/dist/es2019/plugins/find-replace/FindReplaceToolbarButtonWithState.js +20 -19
  32. package/dist/es2019/plugins/find-replace/commands-with-analytics.js +15 -15
  33. package/dist/es2019/plugins/find-replace/index.js +7 -2
  34. package/dist/es2019/plugins/find-replace/keymap.js +4 -4
  35. package/dist/es2019/plugins/index.js +0 -2
  36. package/dist/es2019/plugins/mobile-dimensions/index.js +6 -0
  37. package/dist/es2019/presets/context.js +2 -2
  38. package/dist/es2019/presets/universal.js +11 -1
  39. package/dist/es2019/ui/Appearance/Chromeless.js +17 -9
  40. package/dist/es2019/ui/Appearance/Comment/Comment.js +1 -1
  41. package/dist/es2019/ui/Appearance/FullPage/FullPageToolbar.js +3 -2
  42. package/dist/es2019/ui/AppearanceComponents/Mobile.js +8 -9
  43. package/dist/es2019/{plugins/expand/ui/styles.js → ui/ContentStyles/expand.js} +9 -4
  44. package/dist/es2019/ui/ContentStyles/index.js +1 -1
  45. package/dist/es2019/ui/ToolbarFeedback/index.js +2 -2
  46. package/dist/es2019/use-preset.js +0 -1
  47. package/dist/es2019/version-wrapper.js +1 -1
  48. package/dist/esm/create-editor/ErrorBoundary.js +0 -2
  49. package/dist/esm/nodeviews/getInlineNodeViewProducer.styles.js +1 -1
  50. package/dist/esm/plugins/analytics/index.js +1 -1
  51. package/dist/esm/plugins/analytics/utils.js +0 -28
  52. package/dist/esm/plugins/breakout/index.js +1 -1
  53. package/dist/esm/plugins/breakout/ui/LayoutButton.js +1 -1
  54. package/dist/esm/plugins/find-replace/FindReplaceToolbarButtonWithState.js +32 -30
  55. package/dist/esm/plugins/find-replace/commands-with-analytics.js +84 -70
  56. package/dist/esm/plugins/find-replace/index.js +5 -2
  57. package/dist/esm/plugins/find-replace/keymap.js +4 -4
  58. package/dist/esm/plugins/index.js +0 -2
  59. package/dist/esm/plugins/mobile-dimensions/index.js +6 -0
  60. package/dist/esm/presets/context.js +2 -2
  61. package/dist/esm/presets/universal.js +10 -1
  62. package/dist/esm/ui/Appearance/Chromeless.js +15 -9
  63. package/dist/esm/ui/Appearance/Comment/Comment.js +1 -1
  64. package/dist/esm/ui/Appearance/FullPage/FullPageToolbar.js +3 -2
  65. package/dist/esm/ui/AppearanceComponents/Mobile.js +7 -9
  66. package/dist/esm/{plugins/expand/ui/styles.js → ui/ContentStyles/expand.js} +9 -4
  67. package/dist/esm/ui/ContentStyles/index.js +1 -1
  68. package/dist/esm/ui/ToolbarFeedback/index.js +1 -1
  69. package/dist/esm/use-preset.js +0 -1
  70. package/dist/esm/version-wrapper.js +1 -1
  71. package/dist/types/plugins/analytics/index.d.ts +1 -1
  72. package/dist/types/plugins/analytics/utils.d.ts +0 -11
  73. package/dist/types/plugins/find-replace/FindReplaceToolbarButtonWithState.d.ts +4 -2
  74. package/dist/types/plugins/find-replace/commands-with-analytics.d.ts +9 -9
  75. package/dist/types/plugins/find-replace/index.d.ts +5 -3
  76. package/dist/types/plugins/find-replace/keymap.d.ts +2 -1
  77. package/dist/types/plugins/index.d.ts +0 -2
  78. package/dist/types/plugins/insert-block/types.d.ts +1 -1
  79. package/dist/types/plugins/mobile-dimensions/index.d.ts +5 -1
  80. package/dist/types/presets/context.d.ts +2 -2
  81. package/dist/types/presets/universal.d.ts +5 -0
  82. package/dist/types/ui/Appearance/Chromeless.d.ts +1 -1
  83. package/dist/types/{plugins/expand/ui/styles.d.ts → ui/ContentStyles/expand.d.ts} +1 -1
  84. package/dist/types-ts4.5/plugins/analytics/index.d.ts +1 -1
  85. package/dist/types-ts4.5/plugins/analytics/utils.d.ts +0 -11
  86. package/dist/types-ts4.5/plugins/find-replace/FindReplaceToolbarButtonWithState.d.ts +4 -2
  87. package/dist/types-ts4.5/plugins/find-replace/commands-with-analytics.d.ts +9 -9
  88. package/dist/types-ts4.5/plugins/find-replace/index.d.ts +6 -3
  89. package/dist/types-ts4.5/plugins/find-replace/keymap.d.ts +2 -1
  90. package/dist/types-ts4.5/plugins/index.d.ts +0 -2
  91. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +1 -1
  92. package/dist/types-ts4.5/plugins/mobile-dimensions/index.d.ts +5 -1
  93. package/dist/types-ts4.5/presets/context.d.ts +2 -2
  94. package/dist/types-ts4.5/presets/universal.d.ts +5 -0
  95. package/dist/types-ts4.5/ui/Appearance/Chromeless.d.ts +1 -1
  96. package/dist/types-ts4.5/{plugins/expand/ui/styles.d.ts → ui/ContentStyles/expand.d.ts} +1 -1
  97. package/package.json +6 -9
  98. package/dist/cjs/plugins/breakout/constants.js +0 -10
  99. package/dist/cjs/plugins/expand/commands.js +0 -184
  100. package/dist/cjs/plugins/expand/index.js +0 -111
  101. package/dist/cjs/plugins/expand/nodeviews/index.js +0 -485
  102. package/dist/cjs/plugins/expand/pm-plugins/keymap.js +0 -171
  103. package/dist/cjs/plugins/expand/pm-plugins/main.js +0 -85
  104. package/dist/cjs/plugins/expand/pm-plugins/plugin-factory.js +0 -15
  105. package/dist/cjs/plugins/expand/reducer.js +0 -20
  106. package/dist/cjs/plugins/expand/toolbar.js +0 -59
  107. package/dist/cjs/plugins/expand/types.js +0 -5
  108. package/dist/cjs/plugins/expand/ui/ExpandIconButton.js +0 -104
  109. package/dist/cjs/plugins/expand/ui/class-names.js +0 -20
  110. package/dist/cjs/plugins/expand/utils.js +0 -24
  111. package/dist/cjs/plugins/max-content-size/index.js +0 -44
  112. package/dist/es2019/plugins/breakout/constants.js +0 -4
  113. package/dist/es2019/plugins/expand/commands.js +0 -161
  114. package/dist/es2019/plugins/expand/index.js +0 -95
  115. package/dist/es2019/plugins/expand/nodeviews/index.js +0 -475
  116. package/dist/es2019/plugins/expand/pm-plugins/keymap.js +0 -197
  117. package/dist/es2019/plugins/expand/pm-plugins/main.js +0 -73
  118. package/dist/es2019/plugins/expand/pm-plugins/plugin-factory.js +0 -9
  119. package/dist/es2019/plugins/expand/reducer.js +0 -11
  120. package/dist/es2019/plugins/expand/toolbar.js +0 -52
  121. package/dist/es2019/plugins/expand/types.js +0 -1
  122. package/dist/es2019/plugins/expand/ui/ExpandIconButton.js +0 -85
  123. package/dist/es2019/plugins/expand/ui/class-names.js +0 -12
  124. package/dist/es2019/plugins/expand/utils.js +0 -1
  125. package/dist/es2019/plugins/max-content-size/index.js +0 -35
  126. package/dist/esm/plugins/breakout/constants.js +0 -4
  127. package/dist/esm/plugins/expand/commands.js +0 -177
  128. package/dist/esm/plugins/expand/index.js +0 -97
  129. package/dist/esm/plugins/expand/nodeviews/index.js +0 -477
  130. package/dist/esm/plugins/expand/pm-plugins/keymap.js +0 -165
  131. package/dist/esm/plugins/expand/pm-plugins/main.js +0 -77
  132. package/dist/esm/plugins/expand/pm-plugins/plugin-factory.js +0 -9
  133. package/dist/esm/plugins/expand/reducer.js +0 -13
  134. package/dist/esm/plugins/expand/toolbar.js +0 -52
  135. package/dist/esm/plugins/expand/types.js +0 -1
  136. package/dist/esm/plugins/expand/ui/ExpandIconButton.js +0 -95
  137. package/dist/esm/plugins/expand/ui/class-names.js +0 -14
  138. package/dist/esm/plugins/expand/utils.js +0 -1
  139. package/dist/esm/plugins/max-content-size/index.js +0 -37
  140. package/dist/types/plugins/breakout/constants.d.ts +0 -4
  141. package/dist/types/plugins/expand/commands.d.ts +0 -13
  142. package/dist/types/plugins/expand/index.d.ts +0 -31
  143. package/dist/types/plugins/expand/nodeviews/index.d.ts +0 -55
  144. package/dist/types/plugins/expand/pm-plugins/keymap.d.ts +0 -4
  145. package/dist/types/plugins/expand/pm-plugins/main.d.ts +0 -8
  146. package/dist/types/plugins/expand/pm-plugins/plugin-factory.d.ts +0 -3
  147. package/dist/types/plugins/expand/reducer.d.ts +0 -3
  148. package/dist/types/plugins/expand/toolbar.d.ts +0 -3
  149. package/dist/types/plugins/expand/types.d.ts +0 -9
  150. package/dist/types/plugins/expand/ui/ExpandIconButton.d.ts +0 -43
  151. package/dist/types/plugins/expand/ui/class-names.d.ts +0 -11
  152. package/dist/types/plugins/expand/utils.d.ts +0 -1
  153. package/dist/types/plugins/max-content-size/index.d.ts +0 -13
  154. package/dist/types-ts4.5/plugins/breakout/constants.d.ts +0 -4
  155. package/dist/types-ts4.5/plugins/expand/commands.d.ts +0 -13
  156. package/dist/types-ts4.5/plugins/expand/index.d.ts +0 -31
  157. package/dist/types-ts4.5/plugins/expand/nodeviews/index.d.ts +0 -55
  158. package/dist/types-ts4.5/plugins/expand/pm-plugins/keymap.d.ts +0 -4
  159. package/dist/types-ts4.5/plugins/expand/pm-plugins/main.d.ts +0 -8
  160. package/dist/types-ts4.5/plugins/expand/pm-plugins/plugin-factory.d.ts +0 -3
  161. package/dist/types-ts4.5/plugins/expand/reducer.d.ts +0 -3
  162. package/dist/types-ts4.5/plugins/expand/toolbar.d.ts +0 -3
  163. package/dist/types-ts4.5/plugins/expand/types.d.ts +0 -9
  164. package/dist/types-ts4.5/plugins/expand/ui/ExpandIconButton.d.ts +0 -43
  165. package/dist/types-ts4.5/plugins/expand/ui/class-names.d.ts +0 -11
  166. package/dist/types-ts4.5/plugins/expand/utils.d.ts +0 -1
  167. package/dist/types-ts4.5/plugins/max-content-size/index.d.ts +0 -13
@@ -1,485 +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.ExpandNodeView = void 0;
8
- exports.default = _default;
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
- var _react = _interopRequireDefault(require("react"));
13
- var _reactDom = _interopRequireDefault(require("react-dom"));
14
- var _state = require("@atlaskit/editor-prosemirror/state");
15
- var _ExpandIconButton = require("../ui/ExpandIconButton");
16
- var _w3cKeyname = require("w3c-keyname");
17
- var _model = require("@atlaskit/editor-prosemirror/model");
18
- var _ui = require("@atlaskit/editor-common/ui");
19
- var _utils = require("../../../utils");
20
- var _commands = require("../commands");
21
- var _classNames = require("../ui/class-names");
22
- var _selection = require("@atlaskit/editor-common/selection");
23
- var _dom = require("../../../utils/dom");
24
- function buildExpandClassName(type, expanded) {
25
- return "".concat(_classNames.expandClassNames.prefix, " ").concat(_classNames.expandClassNames.type(type), " ").concat(expanded ? _classNames.expandClassNames.expanded : '');
26
- }
27
- var toDOM = function toDOM(node, intl) {
28
- return ['div', {
29
- // prettier-ignore
30
- 'class': buildExpandClassName(node.type.name, node.attrs.__expanded),
31
- 'data-node-type': node.type.name,
32
- 'data-title': node.attrs.title
33
- }, ['div', {
34
- // prettier-ignore
35
- 'class': _classNames.expandClassNames.titleContainer,
36
- contenteditable: 'false',
37
- // Element gains access to focus events.
38
- // This is needed to prevent PM gaining access
39
- // on interacting with our controls.
40
- tabindex: '-1'
41
- },
42
- // prettier-ignore
43
- ['div', {
44
- 'class': _classNames.expandClassNames.icon
45
- }], ['div', {
46
- // prettier-ignore
47
- 'class': _classNames.expandClassNames.inputContainer
48
- }, ['input', {
49
- // prettier-ignore
50
- 'class': _classNames.expandClassNames.titleInput,
51
- value: node.attrs.title,
52
- placeholder: intl && intl.formatMessage(_ui.expandMessages.expandPlaceholderText) || _ui.expandMessages.expandPlaceholderText.defaultMessage,
53
- type: 'text'
54
- }]]],
55
- // prettier-ignore
56
- ['div', {
57
- 'class': _classNames.expandClassNames.content
58
- }, 0]];
59
- };
60
- var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
61
- function ExpandNodeView(node, view, getPos, getIntl, isMobile, featureFlags, selectNearNode, api) {
62
- var _this = this;
63
- (0, _classCallCheck2.default)(this, ExpandNodeView);
64
- (0, _defineProperty2.default)(this, "allowInteractiveExpand", true);
65
- (0, _defineProperty2.default)(this, "isMobile", false);
66
- (0, _defineProperty2.default)(this, "focusTitle", function () {
67
- if (_this.input) {
68
- var _this$view = _this.view,
69
- state = _this$view.state,
70
- dispatch = _this$view.dispatch;
71
- if (_this.selectNearNode) {
72
- var tr = _this.selectNearNode({
73
- selectionRelativeToNode: _selection.RelativeSelectionPos.Start
74
- })(state);
75
- if (dispatch) {
76
- dispatch(tr);
77
- }
78
- }
79
- var pos = _this.getPos();
80
- if (typeof pos === 'number') {
81
- (0, _commands.setSelectionInsideExpand)(pos)(state, dispatch, _this.view);
82
- }
83
- _this.input.focus();
84
- }
85
- });
86
- (0, _defineProperty2.default)(this, "handleIconKeyDown", function (event) {
87
- switch ((0, _w3cKeyname.keyName)(event)) {
88
- case 'Tab':
89
- event.preventDefault();
90
- _this.focusTitle();
91
- break;
92
- case 'Enter':
93
- event.preventDefault();
94
- _this.handleClick(event);
95
- break;
96
- }
97
- });
98
- (0, _defineProperty2.default)(this, "isAllowInteractiveExpandEnabled", function () {
99
- return _this.featureFlags && !!_this.featureFlags.interactiveExpand;
100
- });
101
- (0, _defineProperty2.default)(this, "handleClick", function (event) {
102
- var pos = _this.getPos();
103
- if (typeof pos !== 'number') {
104
- return;
105
- }
106
- var target = event.target;
107
- var _this$view2 = _this.view,
108
- state = _this$view2.state,
109
- dispatch = _this$view2.dispatch;
110
- if ((0, _dom.closestElement)(target, ".".concat(_classNames.expandClassNames.icon))) {
111
- var _this$api;
112
- if (!_this.isAllowInteractiveExpandEnabled()) {
113
- return;
114
- }
115
- event.stopPropagation();
116
-
117
- // We blur the editorView, to prevent any keyboard showing on mobile
118
- // When we're interacting with the expand toggle
119
- if (_this.view.dom instanceof HTMLElement) {
120
- _this.view.dom.blur();
121
- }
122
- (0, _commands.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);
123
- return;
124
- }
125
- if (target === _this.input) {
126
- event.stopPropagation();
127
- _this.focusTitle();
128
- return;
129
- }
130
- });
131
- (0, _defineProperty2.default)(this, "handleInput", function (event) {
132
- var pos = _this.getPos();
133
- if (typeof pos !== 'number') {
134
- return;
135
- }
136
- var target = event.target;
137
- if (target === _this.input) {
138
- event.stopPropagation();
139
- var _this$view3 = _this.view,
140
- state = _this$view3.state,
141
- dispatch = _this$view3.dispatch;
142
- (0, _commands.updateExpandTitle)(target.value, pos, _this.node.type)(state, dispatch);
143
- }
144
- });
145
- (0, _defineProperty2.default)(this, "handleFocus", function (event) {
146
- event.stopImmediatePropagation();
147
- });
148
- (0, _defineProperty2.default)(this, "handleTitleKeydown", function (event) {
149
- switch ((0, _w3cKeyname.keyName)(event)) {
150
- case 'Enter':
151
- _this.toggleExpand();
152
- break;
153
- case 'Tab':
154
- case 'ArrowDown':
155
- _this.moveToOutsideOfTitle(event);
156
- break;
157
- case 'ArrowRight':
158
- _this.handleArrowRightFromTitle(event);
159
- break;
160
- case 'ArrowLeft':
161
- _this.handleArrowLeftFromTitle(event);
162
- break;
163
- case 'ArrowUp':
164
- _this.setLeftGapCursor(event);
165
- break;
166
- case 'Backspace':
167
- _this.deleteExpand(event);
168
- break;
169
- }
170
- });
171
- (0, _defineProperty2.default)(this, "deleteExpand", function (event) {
172
- if (!_this.input) {
173
- return;
174
- }
175
- var pos = _this.getPos();
176
- if (typeof pos !== 'number') {
177
- return;
178
- }
179
- var _this$input = _this.input,
180
- selectionStart = _this$input.selectionStart,
181
- selectionEnd = _this$input.selectionEnd;
182
- if (selectionStart !== selectionEnd || selectionStart !== 0) {
183
- return;
184
- }
185
- var state = _this.view.state;
186
- var expandNode = _this.node;
187
- if (expandNode && (0, _utils.isEmptyNode)(state.schema)(expandNode)) {
188
- var _this$api2;
189
- (0, _commands.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);
190
- }
191
- });
192
- (0, _defineProperty2.default)(this, "toggleExpand", function () {
193
- var pos = _this.getPos();
194
- if (typeof pos !== 'number') {
195
- return;
196
- }
197
- if (_this.isAllowInteractiveExpandEnabled()) {
198
- var _this$api3;
199
- var _this$view4 = _this.view,
200
- state = _this$view4.state,
201
- dispatch = _this$view4.dispatch;
202
- (0, _commands.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);
203
- }
204
- });
205
- (0, _defineProperty2.default)(this, "moveToOutsideOfTitle", function (event) {
206
- event.preventDefault();
207
- var _this$view5 = _this.view,
208
- state = _this$view5.state,
209
- dispatch = _this$view5.dispatch;
210
- var expandPos = _this.getPos();
211
- if (typeof expandPos !== 'number') {
212
- return;
213
- }
214
- var pos = expandPos;
215
- if (_this.isCollapsed()) {
216
- pos = expandPos + _this.node.nodeSize;
217
- }
218
- var resolvedPos = state.doc.resolve(pos);
219
- if (!resolvedPos) {
220
- return;
221
- }
222
- if (_this.isCollapsed() && resolvedPos.nodeAfter && ['expand', 'nestedExpand'].indexOf(resolvedPos.nodeAfter.type.name) > -1) {
223
- return _this.setRightGapCursor(event);
224
- }
225
- var sel = _state.Selection.findFrom(resolvedPos, 1, true);
226
- if (sel) {
227
- // If the input has focus, ProseMirror doesn't
228
- // Give PM focus back before changing our selection
229
- _this.view.focus();
230
- dispatch(state.tr.setSelection(sel));
231
- }
232
- });
233
- (0, _defineProperty2.default)(this, "isCollapsed", function () {
234
- return !_this.node.attrs.__expanded;
235
- });
236
- (0, _defineProperty2.default)(this, "setRightGapCursor", function (event) {
237
- if (!_this.input) {
238
- return;
239
- }
240
- var pos = _this.getPos();
241
- if (typeof pos !== 'number') {
242
- return;
243
- }
244
- var _this$input2 = _this.input,
245
- value = _this$input2.value,
246
- selectionStart = _this$input2.selectionStart,
247
- selectionEnd = _this$input2.selectionEnd;
248
- if (selectionStart === selectionEnd && selectionStart === value.length) {
249
- var _this$view6 = _this.view,
250
- state = _this$view6.state,
251
- dispatch = _this$view6.dispatch;
252
- event.preventDefault();
253
- _this.view.focus();
254
- dispatch(state.tr.setSelection(new _selection.GapCursorSelection(state.doc.resolve(_this.node.nodeSize + pos), _selection.Side.RIGHT)));
255
- }
256
- });
257
- (0, _defineProperty2.default)(this, "setLeftGapCursor", function (event) {
258
- if (!_this.input) {
259
- return;
260
- }
261
- var pos = _this.getPos();
262
- if (typeof pos !== 'number') {
263
- return;
264
- }
265
- var _this$input3 = _this.input,
266
- selectionStart = _this$input3.selectionStart,
267
- selectionEnd = _this$input3.selectionEnd;
268
- if (selectionStart === selectionEnd && selectionStart === 0) {
269
- event.preventDefault();
270
- var _this$view7 = _this.view,
271
- state = _this$view7.state,
272
- dispatch = _this$view7.dispatch;
273
- _this.view.focus();
274
- dispatch(state.tr.setSelection(new _selection.GapCursorSelection(state.doc.resolve(pos), _selection.Side.LEFT)));
275
- }
276
- });
277
- (0, _defineProperty2.default)(this, "handleArrowRightFromTitle", function (event) {
278
- if (!_this.input || !_this.selectNearNode) {
279
- return;
280
- }
281
- var pos = _this.getPos();
282
- if (typeof pos !== 'number') {
283
- return;
284
- }
285
- var _this$input4 = _this.input,
286
- value = _this$input4.value,
287
- selectionStart = _this$input4.selectionStart,
288
- selectionEnd = _this$input4.selectionEnd;
289
- if (selectionStart === selectionEnd && selectionStart === value.length) {
290
- event.preventDefault();
291
- var _this$view8 = _this.view,
292
- state = _this$view8.state,
293
- dispatch = _this$view8.dispatch;
294
- _this.view.focus();
295
- var tr = _this.selectNearNode({
296
- selectionRelativeToNode: _selection.RelativeSelectionPos.End,
297
- selection: _state.NodeSelection.create(state.doc, pos)
298
- })(state);
299
- if (dispatch) {
300
- dispatch(tr);
301
- }
302
- }
303
- });
304
- (0, _defineProperty2.default)(this, "handleArrowLeftFromTitle", function (event) {
305
- if (!_this.input || !_this.selectNearNode) {
306
- return;
307
- }
308
- var pos = _this.getPos();
309
- if (typeof pos !== 'number') {
310
- return;
311
- }
312
- var _this$input5 = _this.input,
313
- selectionStart = _this$input5.selectionStart,
314
- selectionEnd = _this$input5.selectionEnd;
315
- if (selectionStart === selectionEnd && selectionStart === 0) {
316
- var _this$api4;
317
- event.preventDefault();
318
- var _this$view9 = _this.view,
319
- state = _this$view9.state,
320
- dispatch = _this$view9.dispatch;
321
- _this.view.focus();
322
- 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()) || {};
323
- // selectionRelativeToNode is undefined when user clicked to select node, then hit left to get focus in title
324
- // This is a special case where we want to bypass node selection and jump straight to gap cursor
325
- if ((selectionSharedState === null || selectionSharedState === void 0 ? void 0 : selectionSharedState.selectionRelativeToNode) === undefined) {
326
- var tr = _this.selectNearNode({
327
- selectionRelativeToNode: undefined,
328
- selection: new _selection.GapCursorSelection(state.doc.resolve(pos), _selection.Side.LEFT)
329
- })(state);
330
- if (dispatch) {
331
- dispatch(tr);
332
- }
333
- } else {
334
- var _tr = _this.selectNearNode({
335
- selectionRelativeToNode: _selection.RelativeSelectionPos.Start,
336
- selection: _state.NodeSelection.create(state.doc, pos)
337
- })(state);
338
- if (dispatch) {
339
- dispatch(_tr);
340
- }
341
- }
342
- }
343
- });
344
- this.selectNearNode = selectNearNode;
345
- this.intl = getIntl();
346
- var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, toDOM(node, this.intl)),
347
- dom = _DOMSerializer$render.dom,
348
- contentDOM = _DOMSerializer$render.contentDOM;
349
- this.getPos = getPos;
350
- this.view = view;
351
- this.node = node;
352
- this.dom = dom;
353
- this.contentDOM = contentDOM;
354
- this.isMobile = isMobile;
355
- this.featureFlags = featureFlags;
356
- this.api = api;
357
- this.icon = this.dom.querySelector(".".concat(_classNames.expandClassNames.icon));
358
- this.input = this.dom.querySelector(".".concat(_classNames.expandClassNames.titleInput));
359
- this.titleContainer = this.dom.querySelector(".".concat(_classNames.expandClassNames.titleContainer));
360
- this.content = this.dom.querySelector(".".concat(_classNames.expandClassNames.content));
361
- this.renderIcon(this.intl);
362
- this.initHandlers();
363
- }
364
- (0, _createClass2.default)(ExpandNodeView, [{
365
- key: "initHandlers",
366
- value: function initHandlers() {
367
- if (this.dom) {
368
- this.dom.addEventListener('click', this.handleClick);
369
- this.dom.addEventListener('input', this.handleInput);
370
- }
371
- if (this.input) {
372
- this.input.addEventListener('keydown', this.handleTitleKeydown);
373
- }
374
- if (this.titleContainer) {
375
- // If the user interacts in our title bar (either toggle or input)
376
- // Prevent ProseMirror from getting a focus event (causes weird selection issues).
377
- this.titleContainer.addEventListener('focus', this.handleFocus);
378
- }
379
- if (this.icon) {
380
- this.icon.addEventListener('keydown', this.handleIconKeyDown);
381
- }
382
- }
383
- }, {
384
- key: "renderIcon",
385
- value: function renderIcon(intl, node) {
386
- if (!this.icon) {
387
- return;
388
- }
389
- var _ref = node && node.attrs || this.node.attrs,
390
- __expanded = _ref.__expanded;
391
- _reactDom.default.render( /*#__PURE__*/_react.default.createElement(_ExpandIconButton.ExpandIconButton, {
392
- intl: intl,
393
- allowInteractiveExpand: this.isAllowInteractiveExpandEnabled(),
394
- expanded: __expanded
395
- }), this.icon);
396
- }
397
- }, {
398
- key: "stopEvent",
399
- value: function stopEvent(event) {
400
- var target = event.target;
401
- return target === this.input || target === this.icon || !!(0, _dom.closestElement)(target, ".".concat(_classNames.expandClassNames.icon));
402
- }
403
- }, {
404
- key: "ignoreMutation",
405
- value: function ignoreMutation(mutationRecord) {
406
- // ME-1931: Mobile relies on composition which creates dom mutations. If we ignore them, prosemirror
407
- // does not recognise the changes and reverts them.
408
- if (this.isMobile && (mutationRecord.type === 'characterData' || mutationRecord.type === 'childList')) {
409
- return false;
410
- }
411
- if (mutationRecord.type === 'selection') {
412
- return false;
413
- }
414
- return true;
415
- }
416
- }, {
417
- key: "update",
418
- value: function update(node, _decorations) {
419
- var _this2 = this;
420
- if (this.node.type === node.type) {
421
- if (this.node.attrs.__expanded !== node.attrs.__expanded) {
422
- // Instead of re-rendering the view on an expand toggle
423
- // we toggle a class name to hide the content and animate the chevron.
424
- if (this.dom) {
425
- this.dom.classList.toggle(_classNames.expandClassNames.expanded);
426
- this.renderIcon(this && this.intl, node);
427
- }
428
- if (this.content) {
429
- // Disallow interaction/selection inside when collapsed.
430
- this.content.setAttribute('contenteditable', node.attrs.__expanded);
431
- }
432
- }
433
-
434
- // During a collab session the title doesn't sync with other users
435
- // since we're intentionally being less aggressive about re-rendering.
436
- // We also apply a rAF to avoid abrupt continuous replacement of the title.
437
- window.requestAnimationFrame(function () {
438
- if (_this2.input && _this2.node.attrs.title !== _this2.input.value) {
439
- _this2.input.value = _this2.node.attrs.title;
440
- }
441
- });
442
- this.node = node;
443
- return true;
444
- }
445
- return false;
446
- }
447
- }, {
448
- key: "destroy",
449
- value: function destroy() {
450
- if (this.dom) {
451
- this.dom.removeEventListener('click', this.handleClick);
452
- this.dom.removeEventListener('input', this.handleInput);
453
- }
454
- if (this.input) {
455
- this.input.removeEventListener('keydown', this.handleTitleKeydown);
456
- }
457
- if (this.titleContainer) {
458
- this.titleContainer.removeEventListener('focus', this.handleFocus);
459
- }
460
- if (this.icon) {
461
- this.icon.removeEventListener('keydown', this.handleIconKeyDown);
462
- _reactDom.default.unmountComponentAtNode(this.icon);
463
- }
464
-
465
- // @ts-ignore - [unblock prosemirror bump] reset non optional prop to undefined to clear reference
466
- this.dom = undefined;
467
- this.contentDOM = undefined;
468
- this.icon = undefined;
469
- this.input = undefined;
470
- this.titleContainer = undefined;
471
- this.content = undefined;
472
- }
473
- }]);
474
- return ExpandNodeView;
475
- }();
476
- function _default(_ref2) {
477
- var getIntl = _ref2.getIntl,
478
- isMobile = _ref2.isMobile,
479
- featureFlags = _ref2.featureFlags,
480
- api = _ref2.api;
481
- return function (node, view, getPos) {
482
- var _api$selection;
483
- 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);
484
- };
485
- }
@@ -1,171 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.expandKeymap = expandKeymap;
7
- var _keymap = require("@atlaskit/editor-prosemirror/keymap");
8
- var _state = require("@atlaskit/editor-prosemirror/state");
9
- var _keymaps = require("@atlaskit/editor-common/keymaps");
10
- var _selection = require("@atlaskit/editor-common/selection");
11
- var _utils = require("../utils");
12
- var _utils2 = require("../../../utils");
13
- var _classNames = require("../ui/class-names");
14
- var _commands = require("../commands");
15
- var _utils3 = require("@atlaskit/editor-common/utils");
16
- var isExpandNode = function isExpandNode(node) {
17
- return (node === null || node === void 0 ? void 0 : node.type.name) === 'expand' || (node === null || node === void 0 ? void 0 : node.type.name) === 'nestedExpand';
18
- };
19
- var isExpandSelected = function isExpandSelected(selection) {
20
- return selection instanceof _state.NodeSelection && isExpandNode(selection.node);
21
- };
22
- function expandKeymap(api) {
23
- var list = {};
24
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveRight.common, function (state, dispatch, editorView) {
25
- if (!editorView) {
26
- return false;
27
- }
28
- var selection = state.selection;
29
- var selectionSharedState = (api === null || api === void 0 ? void 0 : api.selection.sharedState.currentState()) || {};
30
- var selectionRelativeToNode = selectionSharedState.selectionRelativeToNode;
31
- if (isExpandSelected(selection) && selectionRelativeToNode === _selection.RelativeSelectionPos.Start) {
32
- return (0, _commands.focusTitle)(selection.from + 1)(state, dispatch, editorView);
33
- }
34
- return false;
35
- }, list);
36
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveLeft.common, function (state, dispatch, editorView) {
37
- if (!editorView) {
38
- return false;
39
- }
40
- var selection = state.selection;
41
- var selectionSharedState = (api === null || api === void 0 ? void 0 : api.selection.sharedState.currentState()) || {};
42
- var selectionRelativeToNode = selectionSharedState.selectionRelativeToNode;
43
- if (isExpandSelected(selection) && (selectionRelativeToNode === undefined || selectionRelativeToNode === _selection.RelativeSelectionPos.End)) {
44
- return (0, _commands.focusTitle)(selection.from + 1)(state, dispatch, editorView);
45
- }
46
- return false;
47
- }, list);
48
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.tab.common, function (state, dispatch, editorView) {
49
- if (state.selection instanceof _state.NodeSelection && state.selection.node.type === state.schema.nodes.expand && editorView && editorView.dom instanceof HTMLElement) {
50
- var from = state.selection.from;
51
- var expand = editorView.nodeDOM(from);
52
- if (!expand || !(expand instanceof HTMLElement)) {
53
- return false;
54
- }
55
- var iconContainer = expand.querySelector(".".concat(_classNames.expandClassNames.iconContainer));
56
- if (iconContainer && iconContainer.focus) {
57
- var tr = state.tr;
58
- var pos = state.selection.from;
59
- tr.setSelection(new _state.TextSelection(tr.doc.resolve(pos)));
60
- if (dispatch) {
61
- dispatch(tr);
62
- }
63
- editorView.dom.blur();
64
- iconContainer.focus();
65
- }
66
- return true;
67
- }
68
- return false;
69
- }, list);
70
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveUp.common, function (state, dispatch, editorView) {
71
- if (!editorView) {
72
- return false;
73
- }
74
- var selection = state.selection,
75
- schema = state.schema;
76
- var nodeBefore = selection.$from.nodeBefore;
77
- if (selection instanceof _selection.GapCursorSelection && selection.side === _selection.Side.RIGHT && nodeBefore && (nodeBefore.type === schema.nodes.expand || nodeBefore.type === schema.nodes.nestedExpand) && !nodeBefore.attrs.__expanded) {
78
- var _$from = selection.$from;
79
- return (0, _commands.focusTitle)(Math.max(_$from.pos - 1, 0))(state, dispatch, editorView);
80
- }
81
- var $from = state.selection.$from;
82
- if (editorView.endOfTextblock('up')) {
83
- var expand = (0, _utils.findExpand)(state);
84
-
85
- // Moving UP in a table should move the cursor to the row above
86
- // however when an expand is in a table cell to the left of the
87
- // current table cell, arrow UP moves the cursor to the left
88
- // see ED-15425
89
- if ((0, _utils3.isPositionNearTableRow)($from, schema, 'before') && !expand) {
90
- return false;
91
- }
92
- var prevCursorPos = Math.max($from.pos - $from.parentOffset - 1, 0);
93
- // move cursor from expand's content to its title
94
- if (expand && expand.start === prevCursorPos) {
95
- return (0, _commands.focusTitle)(expand.start)(state, dispatch, editorView);
96
- }
97
- var sel = _state.Selection.findFrom(state.doc.resolve(prevCursorPos), -1);
98
- var expandBefore = (0, _utils.findExpand)(state, sel);
99
- if (sel && expandBefore) {
100
- // moving cursor from outside of an expand to the title when it is collapsed
101
- if (!expandBefore.node.attrs.__expanded) {
102
- return (0, _commands.focusTitle)(expandBefore.start)(state, dispatch, editorView);
103
- }
104
- // moving cursor from outside of an expand to the content when it is expanded
105
- else if (dispatch) {
106
- dispatch(state.tr.setSelection(sel));
107
- }
108
- return true;
109
- }
110
- }
111
- return false;
112
- }, list);
113
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveDown.common, function (state, dispatch, editorView) {
114
- if (!editorView) {
115
- return false;
116
- }
117
- var _state$schema$nodes = state.schema.nodes,
118
- expand = _state$schema$nodes.expand,
119
- nestedExpand = _state$schema$nodes.nestedExpand;
120
- var selection = state.selection;
121
- var nodeAfter = selection.$from.nodeAfter;
122
- if (selection instanceof _selection.GapCursorSelection && selection.side === _selection.Side.LEFT && nodeAfter && (nodeAfter.type === expand || nodeAfter.type === nestedExpand) && !nodeAfter.attrs.__expanded) {
123
- var $from = selection.$from;
124
- return (0, _commands.focusTitle)($from.pos + 1)(state, dispatch, editorView);
125
- }
126
- if (editorView.endOfTextblock('down')) {
127
- var _$from2 = state.selection.$from;
128
- if (_$from2.depth === 0) {
129
- return false;
130
- }
131
- var $after = state.doc.resolve(_$from2.after());
132
- if ($after.nodeAfter && ($after.nodeAfter.type === expand || $after.nodeAfter.type === nestedExpand)) {
133
- return (0, _commands.focusTitle)($after.pos + 1)(state, dispatch, editorView);
134
- }
135
- }
136
- return false;
137
- }, list);
138
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, function (state, dispatch, editorView) {
139
- var selection = state.selection;
140
- var $from = selection.$from;
141
- if (!editorView || !selection.empty) {
142
- return false;
143
- }
144
- var _state$schema$nodes2 = state.schema.nodes,
145
- expand = _state$schema$nodes2.expand,
146
- nestedExpand = _state$schema$nodes2.nestedExpand;
147
- var expandNode = (0, _utils.findExpand)(state);
148
- if (!expandNode) {
149
- // @see ED-7977
150
- var sel = _state.Selection.findFrom(state.doc.resolve(Math.max(selection.$from.pos - 1, 0)), -1);
151
- var expandBefore = (0, _utils.findExpand)(state, sel);
152
- if (expandBefore && (expandBefore.node.type === expand || expandBefore.node.type === nestedExpand) && !expandBefore.node.attrs.__expanded) {
153
- return (0, _commands.focusTitle)(expandBefore.start)(state, dispatch, editorView);
154
- }
155
- return false;
156
- }
157
- var parentNode = state.doc.nodeAt($from.before(Math.max($from.depth - 1, 1)));
158
- // ED-10012 catch cases where the expand has another node nested within it and
159
- // the backspace should be applied only to the inner node instead of the expand
160
- if (parentNode && !isExpandNode(parentNode)) {
161
- return false;
162
- }
163
- var textSel = _state.Selection.findFrom(state.doc.resolve(expandNode.pos), 1, true);
164
- if (textSel && selection.$from.pos === textSel.$from.pos && (0, _utils2.isEmptyNode)(state.schema)(expandNode.node) && dispatch) {
165
- var _api$analytics;
166
- return (0, _commands.deleteExpand)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(state, dispatch);
167
- }
168
- return false;
169
- }, list);
170
- return (0, _keymap.keymap)(list);
171
- }