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