@atlaskit/editor-plugin-expand 1.4.2 → 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 +16 -0
- package/dist/cjs/singlePlayerExpand/node-views/index.js +21 -6
- package/dist/cjs/singlePlayerExpand/pm-plugins/keymap.js +41 -16
- package/dist/cjs/singlePlayerExpand/ui/NodeView.js +1 -5
- package/dist/es2019/singlePlayerExpand/node-views/index.js +17 -4
- package/dist/es2019/singlePlayerExpand/pm-plugins/keymap.js +50 -19
- package/dist/es2019/singlePlayerExpand/ui/NodeView.js +1 -5
- package/dist/esm/singlePlayerExpand/node-views/index.js +21 -6
- package/dist/esm/singlePlayerExpand/pm-plugins/keymap.js +44 -19
- package/dist/esm/singlePlayerExpand/ui/NodeView.js +1 -5
- package/dist/types/singlePlayerExpand/node-views/index.d.ts +2 -1
- package/dist/types/singlePlayerExpand/ui/NodeView.d.ts +1 -1
- package/dist/types-ts4.5/singlePlayerExpand/node-views/index.d.ts +2 -1
- package/dist/types-ts4.5/singlePlayerExpand/ui/NodeView.d.ts +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
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
|
+
|
|
13
|
+
## 1.4.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#92468](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/92468) [`515df766c29c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/515df766c29c) - [ux] [ED-23066] Re-render expand toggle icon when the class name is updated so that the aria-expanded attribute gets updated to match.
|
|
18
|
+
|
|
3
19
|
## 1.4.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -21,7 +21,8 @@ var _commands = require("../commands");
|
|
|
21
21
|
var _NodeView = require("../ui/NodeView");
|
|
22
22
|
var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
|
|
23
23
|
function ExpandNodeView(node, view, getPos, getIntl, isMobile, selectNearNode, api) {
|
|
24
|
-
var _this = this
|
|
24
|
+
var _this = this,
|
|
25
|
+
_expandedState$get;
|
|
25
26
|
var allowInteractiveExpand = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : true;
|
|
26
27
|
var __livePage = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
|
|
27
28
|
(0, _classCallCheck2.default)(this, ExpandNodeView);
|
|
@@ -82,7 +83,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
|
|
|
82
83
|
pos: pos,
|
|
83
84
|
node: _this.node
|
|
84
85
|
})(_this.view.state, _this.view.dispatch);
|
|
85
|
-
_this.
|
|
86
|
+
_this.updateExpandToggleIcon();
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
88
89
|
if (target === _this.input) {
|
|
@@ -175,7 +176,7 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
|
|
|
175
176
|
pos: pos,
|
|
176
177
|
node: _this.node
|
|
177
178
|
})(state, dispatch);
|
|
178
|
-
_this.
|
|
179
|
+
_this.updateExpandToggleIcon();
|
|
179
180
|
}
|
|
180
181
|
});
|
|
181
182
|
(0, _defineProperty2.default)(this, "moveToOutsideOfTitle", function (event) {
|
|
@@ -334,10 +335,12 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
|
|
|
334
335
|
this.icon = this.dom.querySelector(".".concat(_styles.expandClassNames.icon));
|
|
335
336
|
this.input = this.dom.querySelector(".".concat(_styles.expandClassNames.titleInput));
|
|
336
337
|
this.titleContainer = this.dom.querySelector(".".concat(_styles.expandClassNames.titleContainer));
|
|
337
|
-
|
|
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();
|
|
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);
|
|
341
344
|
if (!this.input || !this.titleContainer || !this.icon) {
|
|
342
345
|
return;
|
|
343
346
|
}
|
|
@@ -400,11 +403,23 @@ var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
|
|
|
400
403
|
return false;
|
|
401
404
|
}
|
|
402
405
|
}, {
|
|
403
|
-
key: "
|
|
404
|
-
value: function
|
|
406
|
+
key: "updateExpandToggleIcon",
|
|
407
|
+
value: function updateExpandToggleIcon() {
|
|
405
408
|
var expanded = _expand.expandedState.get(this.node) ? _expand.expandedState.get(this.node) : false;
|
|
406
409
|
if (this.dom && expanded !== undefined) {
|
|
410
|
+
var _expandedState$get2;
|
|
407
411
|
this.dom.className = (0, _NodeView.buildExpandClassName)(this.node.type.name, expanded);
|
|
412
|
+
// Re-render the icon to update the aria-expanded attribute
|
|
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);
|
|
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');
|
|
408
423
|
}
|
|
409
424
|
}
|
|
410
425
|
}, {
|
|
@@ -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;
|
|
@@ -48,14 +48,10 @@ var toDOM = exports.toDOM = function toDOM(node, __livePage, intl) {
|
|
|
48
48
|
'class': _styles.expandClassNames.content
|
|
49
49
|
}, 0]];
|
|
50
50
|
};
|
|
51
|
-
var renderIcon = exports.renderIcon = function renderIcon(icon, allowInteractiveExpand,
|
|
51
|
+
var renderIcon = exports.renderIcon = function renderIcon(icon, allowInteractiveExpand, expanded, intl) {
|
|
52
52
|
if (!icon) {
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
var expanded = node ? _expand.expandedState.get(node) : true;
|
|
56
|
-
if (expanded === undefined) {
|
|
57
|
-
expanded = false;
|
|
58
|
-
}
|
|
59
55
|
_reactDom.default.render( /*#__PURE__*/_react.default.createElement(_ExpandButton.ExpandButton, {
|
|
60
56
|
intl: intl,
|
|
61
57
|
allowInteractiveExpand: allowInteractiveExpand,
|
|
@@ -11,6 +11,7 @@ import { deleteExpand, setSelectionInsideExpand, toggleExpandExpanded, updateExp
|
|
|
11
11
|
import { buildExpandClassName, renderIcon, toDOM } from '../ui/NodeView';
|
|
12
12
|
export class ExpandNodeView {
|
|
13
13
|
constructor(node, view, getPos, getIntl, isMobile, selectNearNode, api, allowInteractiveExpand = true, __livePage = false) {
|
|
14
|
+
var _expandedState$get;
|
|
14
15
|
_defineProperty(this, "allowInteractiveExpand", true);
|
|
15
16
|
_defineProperty(this, "isMobile", false);
|
|
16
17
|
_defineProperty(this, "focusTitle", () => {
|
|
@@ -69,7 +70,7 @@ export class ExpandNodeView {
|
|
|
69
70
|
pos,
|
|
70
71
|
node: this.node
|
|
71
72
|
})(this.view.state, this.view.dispatch);
|
|
72
|
-
this.
|
|
73
|
+
this.updateExpandToggleIcon();
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
75
76
|
if (target === this.input) {
|
|
@@ -167,7 +168,7 @@ export class ExpandNodeView {
|
|
|
167
168
|
pos,
|
|
168
169
|
node: this.node
|
|
169
170
|
})(state, dispatch);
|
|
170
|
-
this.
|
|
171
|
+
this.updateExpandToggleIcon();
|
|
171
172
|
}
|
|
172
173
|
});
|
|
173
174
|
_defineProperty(this, "moveToOutsideOfTitle", event => {
|
|
@@ -336,10 +337,12 @@ export class ExpandNodeView {
|
|
|
336
337
|
this.icon = this.dom.querySelector(`.${expandClassNames.icon}`);
|
|
337
338
|
this.input = this.dom.querySelector(`.${expandClassNames.titleInput}`);
|
|
338
339
|
this.titleContainer = this.dom.querySelector(`.${expandClassNames.titleContainer}`);
|
|
339
|
-
|
|
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();
|
|
345
|
+
renderIcon(this.icon, this.allowInteractiveExpand, (_expandedState$get = expandedState.get(this.node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false, this.intl);
|
|
343
346
|
if (!this.input || !this.titleContainer || !this.icon) {
|
|
344
347
|
return;
|
|
345
348
|
}
|
|
@@ -394,10 +397,20 @@ export class ExpandNodeView {
|
|
|
394
397
|
}
|
|
395
398
|
return false;
|
|
396
399
|
}
|
|
397
|
-
|
|
400
|
+
updateExpandToggleIcon() {
|
|
398
401
|
const expanded = expandedState.get(this.node) ? expandedState.get(this.node) : false;
|
|
399
402
|
if (this.dom && expanded !== undefined) {
|
|
403
|
+
var _expandedState$get2;
|
|
400
404
|
this.dom.className = buildExpandClassName(this.node.type.name, expanded);
|
|
405
|
+
// Re-render the icon to update the aria-expanded attribute
|
|
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);
|
|
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');
|
|
401
414
|
}
|
|
402
415
|
}
|
|
403
416
|
destroy() {
|
|
@@ -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;
|
|
@@ -41,14 +41,10 @@ export const toDOM = (node, __livePage, intl) => {
|
|
|
41
41
|
'class': expandClassNames.content
|
|
42
42
|
}, 0]];
|
|
43
43
|
};
|
|
44
|
-
export const renderIcon = (icon, allowInteractiveExpand,
|
|
44
|
+
export const renderIcon = (icon, allowInteractiveExpand, expanded, intl) => {
|
|
45
45
|
if (!icon) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
let expanded = node ? expandedState.get(node) : true;
|
|
49
|
-
if (expanded === undefined) {
|
|
50
|
-
expanded = false;
|
|
51
|
-
}
|
|
52
48
|
ReactDOM.render( /*#__PURE__*/React.createElement(ExpandButton, {
|
|
53
49
|
intl: intl,
|
|
54
50
|
allowInteractiveExpand: allowInteractiveExpand,
|
|
@@ -13,7 +13,8 @@ import { deleteExpand, setSelectionInsideExpand, toggleExpandExpanded, updateExp
|
|
|
13
13
|
import { buildExpandClassName, renderIcon, toDOM } from '../ui/NodeView';
|
|
14
14
|
export var ExpandNodeView = /*#__PURE__*/function () {
|
|
15
15
|
function ExpandNodeView(node, view, getPos, getIntl, isMobile, selectNearNode, api) {
|
|
16
|
-
var _this = this
|
|
16
|
+
var _this = this,
|
|
17
|
+
_expandedState$get;
|
|
17
18
|
var allowInteractiveExpand = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : true;
|
|
18
19
|
var __livePage = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
|
|
19
20
|
_classCallCheck(this, ExpandNodeView);
|
|
@@ -74,7 +75,7 @@ export var ExpandNodeView = /*#__PURE__*/function () {
|
|
|
74
75
|
pos: pos,
|
|
75
76
|
node: _this.node
|
|
76
77
|
})(_this.view.state, _this.view.dispatch);
|
|
77
|
-
_this.
|
|
78
|
+
_this.updateExpandToggleIcon();
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
80
81
|
if (target === _this.input) {
|
|
@@ -167,7 +168,7 @@ export var ExpandNodeView = /*#__PURE__*/function () {
|
|
|
167
168
|
pos: pos,
|
|
168
169
|
node: _this.node
|
|
169
170
|
})(state, dispatch);
|
|
170
|
-
_this.
|
|
171
|
+
_this.updateExpandToggleIcon();
|
|
171
172
|
}
|
|
172
173
|
});
|
|
173
174
|
_defineProperty(this, "moveToOutsideOfTitle", function (event) {
|
|
@@ -326,10 +327,12 @@ export var ExpandNodeView = /*#__PURE__*/function () {
|
|
|
326
327
|
this.icon = this.dom.querySelector(".".concat(expandClassNames.icon));
|
|
327
328
|
this.input = this.dom.querySelector(".".concat(expandClassNames.titleInput));
|
|
328
329
|
this.titleContainer = this.dom.querySelector(".".concat(expandClassNames.titleContainer));
|
|
329
|
-
|
|
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();
|
|
335
|
+
renderIcon(this.icon, this.allowInteractiveExpand, (_expandedState$get = expandedState.get(this.node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false, this.intl);
|
|
333
336
|
if (!this.input || !this.titleContainer || !this.icon) {
|
|
334
337
|
return;
|
|
335
338
|
}
|
|
@@ -392,11 +395,23 @@ export var ExpandNodeView = /*#__PURE__*/function () {
|
|
|
392
395
|
return false;
|
|
393
396
|
}
|
|
394
397
|
}, {
|
|
395
|
-
key: "
|
|
396
|
-
value: function
|
|
398
|
+
key: "updateExpandToggleIcon",
|
|
399
|
+
value: function updateExpandToggleIcon() {
|
|
397
400
|
var expanded = expandedState.get(this.node) ? expandedState.get(this.node) : false;
|
|
398
401
|
if (this.dom && expanded !== undefined) {
|
|
402
|
+
var _expandedState$get2;
|
|
399
403
|
this.dom.className = buildExpandClassName(this.node.type.name, expanded);
|
|
404
|
+
// Re-render the icon to update the aria-expanded attribute
|
|
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);
|
|
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');
|
|
400
415
|
}
|
|
401
416
|
}
|
|
402
417
|
}, {
|
|
@@ -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;
|
|
@@ -41,14 +41,10 @@ export var toDOM = function toDOM(node, __livePage, intl) {
|
|
|
41
41
|
'class': expandClassNames.content
|
|
42
42
|
}, 0]];
|
|
43
43
|
};
|
|
44
|
-
export var renderIcon = function renderIcon(icon, allowInteractiveExpand,
|
|
44
|
+
export var renderIcon = function renderIcon(icon, allowInteractiveExpand, expanded, intl) {
|
|
45
45
|
if (!icon) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
var expanded = node ? expandedState.get(node) : true;
|
|
49
|
-
if (expanded === undefined) {
|
|
50
|
-
expanded = false;
|
|
51
|
-
}
|
|
52
48
|
ReactDOM.render( /*#__PURE__*/React.createElement(ExpandButton, {
|
|
53
49
|
intl: intl,
|
|
54
50
|
allowInteractiveExpand: allowInteractiveExpand,
|
|
@@ -44,7 +44,8 @@ export declare class ExpandNodeView implements NodeView {
|
|
|
44
44
|
target: Element;
|
|
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, }: {
|
|
@@ -2,4 +2,4 @@ import type { IntlShape } from 'react-intl-next';
|
|
|
2
2
|
import type { DOMOutputSpec, Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
export declare const buildExpandClassName: (type: string, expanded: boolean) => string;
|
|
4
4
|
export declare const toDOM: (node: PmNode, __livePage: boolean, intl?: IntlShape) => DOMOutputSpec;
|
|
5
|
-
export declare const renderIcon: (icon: HTMLElement | null, allowInteractiveExpand: boolean,
|
|
5
|
+
export declare const renderIcon: (icon: HTMLElement | null, allowInteractiveExpand: boolean, expanded: boolean, intl?: IntlShape) => void;
|
|
@@ -44,7 +44,8 @@ export declare class ExpandNodeView implements NodeView {
|
|
|
44
44
|
target: Element;
|
|
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, }: {
|
|
@@ -2,4 +2,4 @@ import type { IntlShape } from 'react-intl-next';
|
|
|
2
2
|
import type { DOMOutputSpec, Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
export declare const buildExpandClassName: (type: string, expanded: boolean) => string;
|
|
4
4
|
export declare const toDOM: (node: PmNode, __livePage: boolean, intl?: IntlShape) => DOMOutputSpec;
|
|
5
|
-
export declare const renderIcon: (icon: HTMLElement | null, allowInteractiveExpand: boolean,
|
|
5
|
+
export declare const renderIcon: (icon: HTMLElement | null, allowInteractiveExpand: boolean, expanded: boolean, intl?: IntlShape) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-expand",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Expand plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@atlaskit/adf-schema": "^35.9.0",
|
|
37
37
|
"@atlaskit/button": "^17.12.0",
|
|
38
|
-
"@atlaskit/editor-common": "^78.
|
|
38
|
+
"@atlaskit/editor-common": "^78.30.0",
|
|
39
39
|
"@atlaskit/editor-plugin-analytics": "^1.0.0",
|
|
40
40
|
"@atlaskit/editor-plugin-decorations": "^1.0.0",
|
|
41
41
|
"@atlaskit/editor-plugin-selection": "^1.1.0",
|