@atlaskit/editor-plugin-expand 1.4.3 → 1.5.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 +10 -0
- package/dist/cjs/singlePlayerExpand/node-views/index.js +11 -0
- package/dist/cjs/singlePlayerExpand/pm-plugins/keymap.js +41 -16
- package/dist/es2019/singlePlayerExpand/node-views/index.js +9 -0
- package/dist/es2019/singlePlayerExpand/pm-plugins/keymap.js +50 -19
- package/dist/esm/singlePlayerExpand/node-views/index.js +11 -0
- package/dist/esm/singlePlayerExpand/pm-plugins/keymap.js +44 -19
- package/dist/types/singlePlayerExpand/node-views/index.d.ts +1 -0
- package/dist/types-ts4.5/singlePlayerExpand/node-views/index.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-expand
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#92831](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/92831) [`c8652f78a9ce`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c8652f78a9ce) - [ED-22991] add functionality for moving left and moving right with the single player expands. the single player expand is only used when live view is enabled and the platform.editor.single-player-expand FF is enabled.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#92956](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/92956) [`33ba4a1b556d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/33ba4a1b556d) - [ux] [ED-23085] Fix contenteditable being not set to false when expand closed for single player expand. This single player expand is only used when live view is enabled and the platform.editor.single-player-expand FF is enabled.
|
|
12
|
+
|
|
3
13
|
## 1.4.3
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -335,9 +335,11 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
|
|
|
335
335
|
this.icon = this.dom.querySelector(".".concat(_styles.expandClassNames.icon));
|
|
336
336
|
this.input = this.dom.querySelector(".".concat(_styles.expandClassNames.titleInput));
|
|
337
337
|
this.titleContainer = this.dom.querySelector(".".concat(_styles.expandClassNames.titleContainer));
|
|
338
|
+
this.content = this.dom.querySelector(".".concat(_styles.expandClassNames.content));
|
|
338
339
|
if (!_expand.expandedState.has(this.node)) {
|
|
339
340
|
_expand.expandedState.set(this.node, false);
|
|
340
341
|
}
|
|
342
|
+
this.updateExpandBodyContentEditable();
|
|
341
343
|
(0, _NodeView.renderIcon)(this.icon, this.allowInteractiveExpand, (_expandedState$get = _expand.expandedState.get(this.node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false, this.intl);
|
|
342
344
|
if (!this.input || !this.titleContainer || !this.icon) {
|
|
343
345
|
return;
|
|
@@ -410,6 +412,15 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
|
|
|
410
412
|
// Re-render the icon to update the aria-expanded attribute
|
|
411
413
|
(0, _NodeView.renderIcon)(this.icon ? this.icon : null, this.allowInteractiveExpand, (_expandedState$get2 = _expand.expandedState.get(this.node)) !== null && _expandedState$get2 !== void 0 ? _expandedState$get2 : false, this.intl);
|
|
412
414
|
}
|
|
415
|
+
this.updateExpandBodyContentEditable();
|
|
416
|
+
}
|
|
417
|
+
}, {
|
|
418
|
+
key: "updateExpandBodyContentEditable",
|
|
419
|
+
value: function updateExpandBodyContentEditable() {
|
|
420
|
+
// Disallow interaction/selection inside expand body when collapsed.
|
|
421
|
+
if (this.content) {
|
|
422
|
+
this.content.setAttribute('contenteditable', _expand.expandedState.get(this.node) ? 'true' : 'false');
|
|
423
|
+
}
|
|
413
424
|
}
|
|
414
425
|
}, {
|
|
415
426
|
key: "destroy",
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.expandKeymap = expandKeymap;
|
|
7
|
+
var _expand = require("@atlaskit/editor-common/expand");
|
|
7
8
|
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
8
9
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
9
10
|
var _transforms = require("@atlaskit/editor-common/transforms");
|
|
@@ -14,8 +15,37 @@ var _commands = require("../commands");
|
|
|
14
15
|
var isExpandNode = function isExpandNode(node) {
|
|
15
16
|
return (node === null || node === void 0 ? void 0 : node.type.name) === 'expand' || (node === null || node === void 0 ? void 0 : node.type.name) === 'nestedExpand';
|
|
16
17
|
};
|
|
18
|
+
var isExpandSelected = function isExpandSelected(selection) {
|
|
19
|
+
return selection instanceof _state.NodeSelection && isExpandNode(selection.node);
|
|
20
|
+
};
|
|
17
21
|
function expandKeymap(api, options) {
|
|
18
22
|
var list = {};
|
|
23
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveRight.common, function (state, dispatch, editorView) {
|
|
24
|
+
var _api$selection;
|
|
25
|
+
if (!editorView) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
var selection = state.selection;
|
|
29
|
+
var selectionSharedState = (api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === 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
|
+
var _api$selection2;
|
|
38
|
+
if (!editorView) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
var selection = state.selection;
|
|
42
|
+
var selectionSharedState = (api === null || api === void 0 || (_api$selection2 = api.selection) === null || _api$selection2 === void 0 ? void 0 : _api$selection2.sharedState.currentState()) || {};
|
|
43
|
+
var selectionRelativeToNode = selectionSharedState.selectionRelativeToNode;
|
|
44
|
+
if (isExpandSelected(selection) && (selectionRelativeToNode === undefined || selectionRelativeToNode === _selection.RelativeSelectionPos.End)) {
|
|
45
|
+
return (0, _commands.focusTitle)(selection.from + 1)(state, dispatch, editorView);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}, list);
|
|
19
49
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveUp.common, function (state, dispatch, editorView) {
|
|
20
50
|
if (!editorView) {
|
|
21
51
|
return false;
|
|
@@ -23,10 +53,7 @@ function expandKeymap(api, options) {
|
|
|
23
53
|
var selection = state.selection,
|
|
24
54
|
schema = state.schema;
|
|
25
55
|
var nodeBefore = selection.$from.nodeBefore;
|
|
26
|
-
if (selection instanceof _selection.GapCursorSelection && selection.side === _selection.Side.RIGHT && nodeBefore && (nodeBefore.type === schema.nodes.expand || nodeBefore.type === schema.nodes.nestedExpand)
|
|
27
|
-
// https://product-fabric.atlassian.net/browse/ED-22991
|
|
28
|
-
// TODO: add back in expanded logic
|
|
29
|
-
) {
|
|
56
|
+
if (selection instanceof _selection.GapCursorSelection && selection.side === _selection.Side.RIGHT && nodeBefore && (nodeBefore.type === schema.nodes.expand || nodeBefore.type === schema.nodes.nestedExpand) && (0, _expand.isExpandCollapsed)(nodeBefore)) {
|
|
30
57
|
var _$from = selection.$from;
|
|
31
58
|
return (0, _commands.focusTitle)(Math.max(_$from.pos - 1, 0))(state, dispatch, editorView);
|
|
32
59
|
}
|
|
@@ -50,10 +77,14 @@ function expandKeymap(api, options) {
|
|
|
50
77
|
var expandBefore = (0, _transforms.findExpand)(state, sel);
|
|
51
78
|
if (sel && expandBefore) {
|
|
52
79
|
// moving cursor from outside of an expand to the title when it is collapsed
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
80
|
+
if ((0, _expand.isExpandCollapsed)(expandBefore.node)) {
|
|
81
|
+
return (0, _commands.focusTitle)(expandBefore.start)(state, dispatch, editorView);
|
|
82
|
+
}
|
|
83
|
+
// moving cursor from outside of an expand to the content when it is expanded
|
|
84
|
+
else if (dispatch) {
|
|
85
|
+
dispatch(state.tr.setSelection(sel));
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
57
88
|
}
|
|
58
89
|
}
|
|
59
90
|
return false;
|
|
@@ -67,10 +98,7 @@ function expandKeymap(api, options) {
|
|
|
67
98
|
nestedExpand = _state$schema$nodes.nestedExpand;
|
|
68
99
|
var selection = state.selection;
|
|
69
100
|
var nodeAfter = selection.$from.nodeAfter;
|
|
70
|
-
if (selection instanceof _selection.GapCursorSelection && selection.side === _selection.Side.LEFT && nodeAfter && (nodeAfter.type === expand || nodeAfter.type === nestedExpand)
|
|
71
|
-
// https://product-fabric.atlassian.net/browse/ED-22991
|
|
72
|
-
// TODO: add back in expanded logic
|
|
73
|
-
) {
|
|
101
|
+
if (selection instanceof _selection.GapCursorSelection && selection.side === _selection.Side.LEFT && nodeAfter && (nodeAfter.type === expand || nodeAfter.type === nestedExpand) && (0, _expand.isExpandCollapsed)(nodeAfter)) {
|
|
74
102
|
var $from = selection.$from;
|
|
75
103
|
return (0, _commands.focusTitle)($from.pos + 1)(state, dispatch, editorView);
|
|
76
104
|
}
|
|
@@ -100,10 +128,7 @@ function expandKeymap(api, options) {
|
|
|
100
128
|
// @see ED-7977
|
|
101
129
|
var sel = _state.Selection.findFrom(state.doc.resolve(Math.max(selection.$from.pos - 1, 0)), -1);
|
|
102
130
|
var expandBefore = (0, _transforms.findExpand)(state, sel);
|
|
103
|
-
if (expandBefore && (expandBefore.node.type === expand || expandBefore.node.type === nestedExpand)
|
|
104
|
-
// https://product-fabric.atlassian.net/browse/ED-22991
|
|
105
|
-
// TODO: add back in expanded logic
|
|
106
|
-
) {
|
|
131
|
+
if (expandBefore && (expandBefore.node.type === expand || expandBefore.node.type === nestedExpand) && (0, _expand.isExpandCollapsed)(expandBefore.node)) {
|
|
107
132
|
return (0, _commands.focusTitle)(expandBefore.start)(state, dispatch, editorView);
|
|
108
133
|
}
|
|
109
134
|
return false;
|
|
@@ -337,9 +337,11 @@ export class ExpandNodeView {
|
|
|
337
337
|
this.icon = this.dom.querySelector(`.${expandClassNames.icon}`);
|
|
338
338
|
this.input = this.dom.querySelector(`.${expandClassNames.titleInput}`);
|
|
339
339
|
this.titleContainer = this.dom.querySelector(`.${expandClassNames.titleContainer}`);
|
|
340
|
+
this.content = this.dom.querySelector(`.${expandClassNames.content}`);
|
|
340
341
|
if (!expandedState.has(this.node)) {
|
|
341
342
|
expandedState.set(this.node, false);
|
|
342
343
|
}
|
|
344
|
+
this.updateExpandBodyContentEditable();
|
|
343
345
|
renderIcon(this.icon, this.allowInteractiveExpand, (_expandedState$get = expandedState.get(this.node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false, this.intl);
|
|
344
346
|
if (!this.input || !this.titleContainer || !this.icon) {
|
|
345
347
|
return;
|
|
@@ -403,6 +405,13 @@ export class ExpandNodeView {
|
|
|
403
405
|
// Re-render the icon to update the aria-expanded attribute
|
|
404
406
|
renderIcon(this.icon ? this.icon : null, this.allowInteractiveExpand, (_expandedState$get2 = expandedState.get(this.node)) !== null && _expandedState$get2 !== void 0 ? _expandedState$get2 : false, this.intl);
|
|
405
407
|
}
|
|
408
|
+
this.updateExpandBodyContentEditable();
|
|
409
|
+
}
|
|
410
|
+
updateExpandBodyContentEditable() {
|
|
411
|
+
// Disallow interaction/selection inside expand body when collapsed.
|
|
412
|
+
if (this.content) {
|
|
413
|
+
this.content.setAttribute('contenteditable', expandedState.get(this.node) ? 'true' : 'false');
|
|
414
|
+
}
|
|
406
415
|
}
|
|
407
416
|
destroy() {
|
|
408
417
|
var _this$decorationClean2;
|
|
@@ -1,15 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isExpandCollapsed } from '@atlaskit/editor-common/expand';
|
|
2
|
+
import { backspace, bindKeymapWithCommand, moveDown, moveLeft, moveRight, moveUp } from '@atlaskit/editor-common/keymaps';
|
|
3
|
+
import { GapCursorSelection, RelativeSelectionPos, Side } from '@atlaskit/editor-common/selection';
|
|
3
4
|
import { findExpand } from '@atlaskit/editor-common/transforms';
|
|
4
5
|
import { isEmptyNode, isPositionNearTableRow } from '@atlaskit/editor-common/utils';
|
|
5
6
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
6
|
-
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
7
8
|
import { deleteExpand, focusTitle } from '../commands';
|
|
8
9
|
const isExpandNode = node => {
|
|
9
10
|
return (node === null || node === void 0 ? void 0 : node.type.name) === 'expand' || (node === null || node === void 0 ? void 0 : node.type.name) === 'nestedExpand';
|
|
10
11
|
};
|
|
12
|
+
const isExpandSelected = selection => selection instanceof NodeSelection && isExpandNode(selection.node);
|
|
11
13
|
export function expandKeymap(api, options) {
|
|
12
14
|
const list = {};
|
|
15
|
+
bindKeymapWithCommand(moveRight.common, (state, dispatch, editorView) => {
|
|
16
|
+
var _api$selection;
|
|
17
|
+
if (!editorView) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const {
|
|
21
|
+
selection
|
|
22
|
+
} = state;
|
|
23
|
+
const selectionSharedState = (api === null || api === void 0 ? void 0 : (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.sharedState.currentState()) || {};
|
|
24
|
+
const {
|
|
25
|
+
selectionRelativeToNode
|
|
26
|
+
} = selectionSharedState;
|
|
27
|
+
if (isExpandSelected(selection) && selectionRelativeToNode === RelativeSelectionPos.Start) {
|
|
28
|
+
return focusTitle(selection.from + 1)(state, dispatch, editorView);
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}, list);
|
|
32
|
+
bindKeymapWithCommand(moveLeft.common, (state, dispatch, editorView) => {
|
|
33
|
+
var _api$selection2;
|
|
34
|
+
if (!editorView) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const {
|
|
38
|
+
selection
|
|
39
|
+
} = state;
|
|
40
|
+
const selectionSharedState = (api === null || api === void 0 ? void 0 : (_api$selection2 = api.selection) === null || _api$selection2 === void 0 ? void 0 : _api$selection2.sharedState.currentState()) || {};
|
|
41
|
+
const {
|
|
42
|
+
selectionRelativeToNode
|
|
43
|
+
} = selectionSharedState;
|
|
44
|
+
if (isExpandSelected(selection) && (selectionRelativeToNode === undefined || selectionRelativeToNode === RelativeSelectionPos.End)) {
|
|
45
|
+
return focusTitle(selection.from + 1)(state, dispatch, editorView);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}, list);
|
|
13
49
|
bindKeymapWithCommand(moveUp.common, (state, dispatch, editorView) => {
|
|
14
50
|
if (!editorView) {
|
|
15
51
|
return false;
|
|
@@ -21,10 +57,7 @@ export function expandKeymap(api, options) {
|
|
|
21
57
|
const {
|
|
22
58
|
nodeBefore
|
|
23
59
|
} = selection.$from;
|
|
24
|
-
if (selection instanceof GapCursorSelection && selection.side === Side.RIGHT && nodeBefore && (nodeBefore.type === schema.nodes.expand || nodeBefore.type === schema.nodes.nestedExpand)
|
|
25
|
-
// https://product-fabric.atlassian.net/browse/ED-22991
|
|
26
|
-
// TODO: add back in expanded logic
|
|
27
|
-
) {
|
|
60
|
+
if (selection instanceof GapCursorSelection && selection.side === Side.RIGHT && nodeBefore && (nodeBefore.type === schema.nodes.expand || nodeBefore.type === schema.nodes.nestedExpand) && isExpandCollapsed(nodeBefore)) {
|
|
28
61
|
const {
|
|
29
62
|
$from
|
|
30
63
|
} = selection;
|
|
@@ -52,10 +85,14 @@ export function expandKeymap(api, options) {
|
|
|
52
85
|
const expandBefore = findExpand(state, sel);
|
|
53
86
|
if (sel && expandBefore) {
|
|
54
87
|
// moving cursor from outside of an expand to the title when it is collapsed
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
88
|
+
if (isExpandCollapsed(expandBefore.node)) {
|
|
89
|
+
return focusTitle(expandBefore.start)(state, dispatch, editorView);
|
|
90
|
+
}
|
|
91
|
+
// moving cursor from outside of an expand to the content when it is expanded
|
|
92
|
+
else if (dispatch) {
|
|
93
|
+
dispatch(state.tr.setSelection(sel));
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
59
96
|
}
|
|
60
97
|
}
|
|
61
98
|
return false;
|
|
@@ -74,10 +111,7 @@ export function expandKeymap(api, options) {
|
|
|
74
111
|
const {
|
|
75
112
|
nodeAfter
|
|
76
113
|
} = selection.$from;
|
|
77
|
-
if (selection instanceof GapCursorSelection && selection.side === Side.LEFT && nodeAfter && (nodeAfter.type === expand || nodeAfter.type === nestedExpand)
|
|
78
|
-
// https://product-fabric.atlassian.net/browse/ED-22991
|
|
79
|
-
// TODO: add back in expanded logic
|
|
80
|
-
) {
|
|
114
|
+
if (selection instanceof GapCursorSelection && selection.side === Side.LEFT && nodeAfter && (nodeAfter.type === expand || nodeAfter.type === nestedExpand) && isExpandCollapsed(nodeAfter)) {
|
|
81
115
|
const {
|
|
82
116
|
$from
|
|
83
117
|
} = selection;
|
|
@@ -116,10 +150,7 @@ export function expandKeymap(api, options) {
|
|
|
116
150
|
// @see ED-7977
|
|
117
151
|
const sel = Selection.findFrom(state.doc.resolve(Math.max(selection.$from.pos - 1, 0)), -1);
|
|
118
152
|
const expandBefore = findExpand(state, sel);
|
|
119
|
-
if (expandBefore && (expandBefore.node.type === expand || expandBefore.node.type === nestedExpand)
|
|
120
|
-
// https://product-fabric.atlassian.net/browse/ED-22991
|
|
121
|
-
// TODO: add back in expanded logic
|
|
122
|
-
) {
|
|
153
|
+
if (expandBefore && (expandBefore.node.type === expand || expandBefore.node.type === nestedExpand) && isExpandCollapsed(expandBefore.node)) {
|
|
123
154
|
return focusTitle(expandBefore.start)(state, dispatch, editorView);
|
|
124
155
|
}
|
|
125
156
|
return false;
|
|
@@ -327,9 +327,11 @@ export var ExpandNodeView = /*#__PURE__*/function () {
|
|
|
327
327
|
this.icon = this.dom.querySelector(".".concat(expandClassNames.icon));
|
|
328
328
|
this.input = this.dom.querySelector(".".concat(expandClassNames.titleInput));
|
|
329
329
|
this.titleContainer = this.dom.querySelector(".".concat(expandClassNames.titleContainer));
|
|
330
|
+
this.content = this.dom.querySelector(".".concat(expandClassNames.content));
|
|
330
331
|
if (!expandedState.has(this.node)) {
|
|
331
332
|
expandedState.set(this.node, false);
|
|
332
333
|
}
|
|
334
|
+
this.updateExpandBodyContentEditable();
|
|
333
335
|
renderIcon(this.icon, this.allowInteractiveExpand, (_expandedState$get = expandedState.get(this.node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false, this.intl);
|
|
334
336
|
if (!this.input || !this.titleContainer || !this.icon) {
|
|
335
337
|
return;
|
|
@@ -402,6 +404,15 @@ export var ExpandNodeView = /*#__PURE__*/function () {
|
|
|
402
404
|
// Re-render the icon to update the aria-expanded attribute
|
|
403
405
|
renderIcon(this.icon ? this.icon : null, this.allowInteractiveExpand, (_expandedState$get2 = expandedState.get(this.node)) !== null && _expandedState$get2 !== void 0 ? _expandedState$get2 : false, this.intl);
|
|
404
406
|
}
|
|
407
|
+
this.updateExpandBodyContentEditable();
|
|
408
|
+
}
|
|
409
|
+
}, {
|
|
410
|
+
key: "updateExpandBodyContentEditable",
|
|
411
|
+
value: function updateExpandBodyContentEditable() {
|
|
412
|
+
// Disallow interaction/selection inside expand body when collapsed.
|
|
413
|
+
if (this.content) {
|
|
414
|
+
this.content.setAttribute('contenteditable', expandedState.get(this.node) ? 'true' : 'false');
|
|
415
|
+
}
|
|
405
416
|
}
|
|
406
417
|
}, {
|
|
407
418
|
key: "destroy",
|
|
@@ -1,15 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isExpandCollapsed } from '@atlaskit/editor-common/expand';
|
|
2
|
+
import { backspace, bindKeymapWithCommand, moveDown, moveLeft, moveRight, moveUp } from '@atlaskit/editor-common/keymaps';
|
|
3
|
+
import { GapCursorSelection, RelativeSelectionPos, Side } from '@atlaskit/editor-common/selection';
|
|
3
4
|
import { findExpand } from '@atlaskit/editor-common/transforms';
|
|
4
5
|
import { isEmptyNode, isPositionNearTableRow } from '@atlaskit/editor-common/utils';
|
|
5
6
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
6
|
-
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
7
8
|
import { deleteExpand, focusTitle } from '../commands';
|
|
8
9
|
var isExpandNode = function isExpandNode(node) {
|
|
9
10
|
return (node === null || node === void 0 ? void 0 : node.type.name) === 'expand' || (node === null || node === void 0 ? void 0 : node.type.name) === 'nestedExpand';
|
|
10
11
|
};
|
|
12
|
+
var isExpandSelected = function isExpandSelected(selection) {
|
|
13
|
+
return selection instanceof NodeSelection && isExpandNode(selection.node);
|
|
14
|
+
};
|
|
11
15
|
export function expandKeymap(api, options) {
|
|
12
16
|
var list = {};
|
|
17
|
+
bindKeymapWithCommand(moveRight.common, function (state, dispatch, editorView) {
|
|
18
|
+
var _api$selection;
|
|
19
|
+
if (!editorView) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
var selection = state.selection;
|
|
23
|
+
var selectionSharedState = (api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.sharedState.currentState()) || {};
|
|
24
|
+
var selectionRelativeToNode = selectionSharedState.selectionRelativeToNode;
|
|
25
|
+
if (isExpandSelected(selection) && selectionRelativeToNode === RelativeSelectionPos.Start) {
|
|
26
|
+
return focusTitle(selection.from + 1)(state, dispatch, editorView);
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}, list);
|
|
30
|
+
bindKeymapWithCommand(moveLeft.common, function (state, dispatch, editorView) {
|
|
31
|
+
var _api$selection2;
|
|
32
|
+
if (!editorView) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
var selection = state.selection;
|
|
36
|
+
var selectionSharedState = (api === null || api === void 0 || (_api$selection2 = api.selection) === null || _api$selection2 === void 0 ? void 0 : _api$selection2.sharedState.currentState()) || {};
|
|
37
|
+
var selectionRelativeToNode = selectionSharedState.selectionRelativeToNode;
|
|
38
|
+
if (isExpandSelected(selection) && (selectionRelativeToNode === undefined || selectionRelativeToNode === RelativeSelectionPos.End)) {
|
|
39
|
+
return focusTitle(selection.from + 1)(state, dispatch, editorView);
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}, list);
|
|
13
43
|
bindKeymapWithCommand(moveUp.common, function (state, dispatch, editorView) {
|
|
14
44
|
if (!editorView) {
|
|
15
45
|
return false;
|
|
@@ -17,10 +47,7 @@ export function expandKeymap(api, options) {
|
|
|
17
47
|
var selection = state.selection,
|
|
18
48
|
schema = state.schema;
|
|
19
49
|
var nodeBefore = selection.$from.nodeBefore;
|
|
20
|
-
if (selection instanceof GapCursorSelection && selection.side === Side.RIGHT && nodeBefore && (nodeBefore.type === schema.nodes.expand || nodeBefore.type === schema.nodes.nestedExpand)
|
|
21
|
-
// https://product-fabric.atlassian.net/browse/ED-22991
|
|
22
|
-
// TODO: add back in expanded logic
|
|
23
|
-
) {
|
|
50
|
+
if (selection instanceof GapCursorSelection && selection.side === Side.RIGHT && nodeBefore && (nodeBefore.type === schema.nodes.expand || nodeBefore.type === schema.nodes.nestedExpand) && isExpandCollapsed(nodeBefore)) {
|
|
24
51
|
var _$from = selection.$from;
|
|
25
52
|
return focusTitle(Math.max(_$from.pos - 1, 0))(state, dispatch, editorView);
|
|
26
53
|
}
|
|
@@ -44,10 +71,14 @@ export function expandKeymap(api, options) {
|
|
|
44
71
|
var expandBefore = findExpand(state, sel);
|
|
45
72
|
if (sel && expandBefore) {
|
|
46
73
|
// moving cursor from outside of an expand to the title when it is collapsed
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
74
|
+
if (isExpandCollapsed(expandBefore.node)) {
|
|
75
|
+
return focusTitle(expandBefore.start)(state, dispatch, editorView);
|
|
76
|
+
}
|
|
77
|
+
// moving cursor from outside of an expand to the content when it is expanded
|
|
78
|
+
else if (dispatch) {
|
|
79
|
+
dispatch(state.tr.setSelection(sel));
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
51
82
|
}
|
|
52
83
|
}
|
|
53
84
|
return false;
|
|
@@ -61,10 +92,7 @@ export function expandKeymap(api, options) {
|
|
|
61
92
|
nestedExpand = _state$schema$nodes.nestedExpand;
|
|
62
93
|
var selection = state.selection;
|
|
63
94
|
var nodeAfter = selection.$from.nodeAfter;
|
|
64
|
-
if (selection instanceof GapCursorSelection && selection.side === Side.LEFT && nodeAfter && (nodeAfter.type === expand || nodeAfter.type === nestedExpand)
|
|
65
|
-
// https://product-fabric.atlassian.net/browse/ED-22991
|
|
66
|
-
// TODO: add back in expanded logic
|
|
67
|
-
) {
|
|
95
|
+
if (selection instanceof GapCursorSelection && selection.side === Side.LEFT && nodeAfter && (nodeAfter.type === expand || nodeAfter.type === nestedExpand) && isExpandCollapsed(nodeAfter)) {
|
|
68
96
|
var $from = selection.$from;
|
|
69
97
|
return focusTitle($from.pos + 1)(state, dispatch, editorView);
|
|
70
98
|
}
|
|
@@ -94,10 +122,7 @@ export function expandKeymap(api, options) {
|
|
|
94
122
|
// @see ED-7977
|
|
95
123
|
var sel = Selection.findFrom(state.doc.resolve(Math.max(selection.$from.pos - 1, 0)), -1);
|
|
96
124
|
var expandBefore = findExpand(state, sel);
|
|
97
|
-
if (expandBefore && (expandBefore.node.type === expand || expandBefore.node.type === nestedExpand)
|
|
98
|
-
// https://product-fabric.atlassian.net/browse/ED-22991
|
|
99
|
-
// TODO: add back in expanded logic
|
|
100
|
-
) {
|
|
125
|
+
if (expandBefore && (expandBefore.node.type === expand || expandBefore.node.type === nestedExpand) && isExpandCollapsed(expandBefore.node)) {
|
|
101
126
|
return focusTitle(expandBefore.start)(state, dispatch, editorView);
|
|
102
127
|
}
|
|
103
128
|
return false;
|
|
@@ -45,6 +45,7 @@ export declare class ExpandNodeView implements NodeView {
|
|
|
45
45
|
}): boolean;
|
|
46
46
|
update(node: PmNode, _decorations: readonly Decoration[]): boolean;
|
|
47
47
|
updateExpandToggleIcon(): void;
|
|
48
|
+
updateExpandBodyContentEditable(): void;
|
|
48
49
|
destroy(): void;
|
|
49
50
|
}
|
|
50
51
|
export default function ({ getIntl, isMobile, api, allowInteractiveExpand, __livePage, }: {
|
|
@@ -45,6 +45,7 @@ export declare class ExpandNodeView implements NodeView {
|
|
|
45
45
|
}): boolean;
|
|
46
46
|
update(node: PmNode, _decorations: readonly Decoration[]): boolean;
|
|
47
47
|
updateExpandToggleIcon(): void;
|
|
48
|
+
updateExpandBodyContentEditable(): void;
|
|
48
49
|
destroy(): void;
|
|
49
50
|
}
|
|
50
51
|
export default function ({ getIntl, isMobile, api, allowInteractiveExpand, __livePage, }: {
|