@atlaskit/editor-plugin-expand 1.3.1 → 1.3.2
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 +6 -0
- package/dist/cjs/singlePlayerExpand/commands.js +134 -0
- package/dist/cjs/singlePlayerExpand/node-views/index.js +381 -0
- package/dist/cjs/singlePlayerExpand/plugin.js +72 -9
- package/dist/cjs/singlePlayerExpand/pm-plugins/keymap.js +121 -0
- package/dist/cjs/singlePlayerExpand/pm-plugins/main.js +68 -0
- package/dist/cjs/singlePlayerExpand/toolbar.js +59 -0
- package/dist/cjs/singlePlayerExpand/ui/ExpandButton.js +87 -0
- package/dist/cjs/singlePlayerExpand/ui/NodeView.js +59 -0
- package/dist/cjs/singlePlayerExpand/utils.js +35 -0
- package/dist/es2019/index.js +0 -2
- package/dist/es2019/legacyExpand/pm-plugins/keymap.js +1 -2
- package/dist/es2019/singlePlayerExpand/commands.js +118 -0
- package/dist/es2019/singlePlayerExpand/node-views/index.js +370 -0
- package/dist/es2019/singlePlayerExpand/plugin.js +69 -10
- package/dist/es2019/singlePlayerExpand/pm-plugins/keymap.js +137 -0
- package/dist/es2019/singlePlayerExpand/pm-plugins/main.js +53 -0
- package/dist/es2019/singlePlayerExpand/toolbar.js +51 -0
- package/dist/es2019/singlePlayerExpand/ui/ExpandButton.js +77 -0
- package/dist/es2019/singlePlayerExpand/ui/NodeView.js +52 -0
- package/dist/es2019/singlePlayerExpand/utils.js +5 -0
- package/dist/esm/index.js +0 -2
- package/dist/esm/legacyExpand/pm-plugins/keymap.js +1 -2
- package/dist/esm/singlePlayerExpand/commands.js +128 -0
- package/dist/esm/singlePlayerExpand/node-views/index.js +373 -0
- package/dist/esm/singlePlayerExpand/plugin.js +71 -10
- package/dist/esm/singlePlayerExpand/pm-plugins/keymap.js +115 -0
- package/dist/esm/singlePlayerExpand/pm-plugins/main.js +60 -0
- package/dist/esm/singlePlayerExpand/toolbar.js +52 -0
- package/dist/esm/singlePlayerExpand/ui/ExpandButton.js +77 -0
- package/dist/esm/singlePlayerExpand/ui/NodeView.js +53 -0
- package/dist/esm/singlePlayerExpand/utils.js +5 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/legacyExpand/nodeviews/index.d.ts +1 -1
- package/dist/types/legacyExpand/plugin.d.ts +1 -1
- package/dist/types/legacyExpand/pm-plugins/keymap.d.ts +1 -1
- package/dist/types/legacyExpand/pm-plugins/main.d.ts +2 -2
- package/dist/types/legacyExpand/pm-plugins/plugin-factory.d.ts +1 -1
- package/dist/types/legacyExpand/reducer.d.ts +1 -1
- package/dist/types/legacyExpand/toolbar.d.ts +1 -1
- package/dist/types/plugin.d.ts +1 -1
- package/dist/types/singlePlayerExpand/commands.d.ts +15 -0
- package/dist/types/singlePlayerExpand/node-views/index.d.ts +51 -0
- package/dist/types/singlePlayerExpand/plugin.d.ts +1 -1
- package/dist/types/singlePlayerExpand/pm-plugins/keymap.d.ts +6 -0
- package/dist/types/singlePlayerExpand/pm-plugins/main.d.ts +9 -0
- package/dist/types/singlePlayerExpand/toolbar.d.ts +3 -0
- package/dist/types/singlePlayerExpand/ui/ExpandButton.d.ts +13 -0
- package/dist/types/singlePlayerExpand/ui/NodeView.d.ts +5 -0
- package/dist/types/singlePlayerExpand/utils.d.ts +3 -0
- package/dist/{types-ts4.5/legacyExpand → types}/types.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/nodeviews/index.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/plugin.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/pm-plugins/keymap.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/pm-plugins/main.d.ts +2 -2
- package/dist/types-ts4.5/legacyExpand/pm-plugins/plugin-factory.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/reducer.d.ts +1 -1
- package/dist/types-ts4.5/legacyExpand/toolbar.d.ts +1 -1
- package/dist/types-ts4.5/plugin.d.ts +1 -1
- package/dist/types-ts4.5/singlePlayerExpand/commands.d.ts +15 -0
- package/dist/types-ts4.5/singlePlayerExpand/node-views/index.d.ts +51 -0
- package/dist/types-ts4.5/singlePlayerExpand/plugin.d.ts +1 -1
- package/dist/types-ts4.5/singlePlayerExpand/pm-plugins/keymap.d.ts +6 -0
- package/dist/types-ts4.5/singlePlayerExpand/pm-plugins/main.d.ts +9 -0
- package/dist/types-ts4.5/singlePlayerExpand/toolbar.d.ts +3 -0
- package/dist/types-ts4.5/singlePlayerExpand/ui/ExpandButton.d.ts +13 -0
- package/dist/types-ts4.5/singlePlayerExpand/ui/NodeView.d.ts +5 -0
- package/dist/types-ts4.5/singlePlayerExpand/utils.d.ts +3 -0
- package/dist/{types/legacyExpand → types-ts4.5}/types.d.ts +1 -1
- package/package.json +1 -1
- /package/dist/cjs/{legacyExpand/types.js → types.js} +0 -0
- /package/dist/es2019/{legacyExpand/types.js → types.js} +0 -0
- /package/dist/esm/{legacyExpand/types.js → types.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-expand
|
|
2
2
|
|
|
3
|
+
## 1.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#89345](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/89345) [`80a9a5da9ce4`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/80a9a5da9ce4) - [ED-22840] Build the base functionality of the new single player expand which will be used for live view pages. Single player expand will only be used if `platform.editor.single-player-expand` is true and livePage is enabled.
|
|
8
|
+
|
|
3
9
|
## 1.3.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.updateExpandTitle = exports.setSelectionInsideExpand = exports.insertExpand = exports.focusTitle = exports.deleteExpandAtPos = exports.deleteExpand = exports.createExpandNode = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _steps = require("@atlaskit/adf-schema/steps");
|
|
10
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
|
+
var _transforms = require("@atlaskit/editor-common/transforms");
|
|
12
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
13
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
14
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
15
|
+
var _utils3 = require("@atlaskit/editor-tables/utils");
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
// Creates either an expand or a nestedExpand node based on the current selection
|
|
19
|
+
var createExpandNode = exports.createExpandNode = function createExpandNode(state) {
|
|
20
|
+
var _state$schema$nodes = state.schema.nodes,
|
|
21
|
+
expand = _state$schema$nodes.expand,
|
|
22
|
+
nestedExpand = _state$schema$nodes.nestedExpand;
|
|
23
|
+
var expandType = (0, _utils3.findTable)(state.selection) ? nestedExpand : expand;
|
|
24
|
+
return expandType.createAndFill({});
|
|
25
|
+
};
|
|
26
|
+
var insertExpand = exports.insertExpand = function insertExpand(editorAnalyticsAPI) {
|
|
27
|
+
return function (state, dispatch) {
|
|
28
|
+
var expandNode = createExpandNode(state);
|
|
29
|
+
if (!expandNode) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
var tr = state.selection.empty ? (0, _utils2.safeInsert)(expandNode)(state.tr).scrollIntoView() : (0, _utils.createWrapSelectionTransaction)({
|
|
33
|
+
state: state,
|
|
34
|
+
type: expandNode.type
|
|
35
|
+
});
|
|
36
|
+
var payload = {
|
|
37
|
+
action: _analytics.ACTION.INSERTED,
|
|
38
|
+
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
39
|
+
actionSubjectId: (expandNode === null || expandNode === void 0 ? void 0 : expandNode.type) === state.schema.nodes.expand ? _analytics.ACTION_SUBJECT_ID.EXPAND : _analytics.ACTION_SUBJECT_ID.NESTED_EXPAND,
|
|
40
|
+
attributes: {
|
|
41
|
+
inputMethod: _analytics.INPUT_METHOD.INSERT_MENU
|
|
42
|
+
},
|
|
43
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
44
|
+
};
|
|
45
|
+
if (dispatch && expandNode) {
|
|
46
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
|
|
47
|
+
dispatch(tr);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
var deleteExpand = exports.deleteExpand = function deleteExpand(editorAnalyticsAPI) {
|
|
53
|
+
return function (state, dispatch) {
|
|
54
|
+
var expandNode = (0, _transforms.findExpand)(state);
|
|
55
|
+
if (!expandNode) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return deleteExpandAtPos(editorAnalyticsAPI)(expandNode.pos, expandNode.node)(state, dispatch);
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
var deleteExpandAtPos = exports.deleteExpandAtPos = function deleteExpandAtPos(editorAnalyticsAPI) {
|
|
62
|
+
return function (expandNodePos, expandNode) {
|
|
63
|
+
return function (state, dispatch) {
|
|
64
|
+
if (!expandNode || isNaN(expandNodePos)) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
var payload = {
|
|
68
|
+
action: _analytics.ACTION.DELETED,
|
|
69
|
+
actionSubject: expandNode.type === state.schema.nodes.expand ? _analytics.ACTION_SUBJECT.EXPAND : _analytics.ACTION_SUBJECT.NESTED_EXPAND,
|
|
70
|
+
attributes: {
|
|
71
|
+
inputMethod: _analytics.INPUT_METHOD.TOOLBAR
|
|
72
|
+
},
|
|
73
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
74
|
+
};
|
|
75
|
+
if (expandNode && dispatch) {
|
|
76
|
+
var tr = state.tr;
|
|
77
|
+
tr.delete(expandNodePos, expandNodePos + expandNode.nodeSize);
|
|
78
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(tr);
|
|
79
|
+
dispatch(tr);
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Used to clear any node or cell selection when expand title is focused
|
|
87
|
+
var setSelectionInsideExpand = exports.setSelectionInsideExpand = function setSelectionInsideExpand(expandPos) {
|
|
88
|
+
return function (state, dispatch, editorView) {
|
|
89
|
+
if (editorView) {
|
|
90
|
+
if (!editorView.hasFocus()) {
|
|
91
|
+
editorView.focus();
|
|
92
|
+
}
|
|
93
|
+
var sel = _state.Selection.findFrom(editorView.state.doc.resolve(expandPos), 1, true);
|
|
94
|
+
if (sel && dispatch) {
|
|
95
|
+
dispatch(editorView.state.tr.setSelection(sel));
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
var updateExpandTitle = exports.updateExpandTitle = function updateExpandTitle(_ref) {
|
|
103
|
+
var title = _ref.title,
|
|
104
|
+
nodeType = _ref.nodeType,
|
|
105
|
+
pos = _ref.pos;
|
|
106
|
+
return function (state, dispatch) {
|
|
107
|
+
var node = state.doc.nodeAt(pos);
|
|
108
|
+
if (node && node.type === nodeType && dispatch) {
|
|
109
|
+
var tr = state.tr;
|
|
110
|
+
tr.step(new _steps.SetAttrsStep(pos, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
111
|
+
title: title
|
|
112
|
+
})));
|
|
113
|
+
dispatch(tr);
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
var focusTitle = exports.focusTitle = function focusTitle(pos) {
|
|
119
|
+
return function (state, dispatch, editorView) {
|
|
120
|
+
if (editorView) {
|
|
121
|
+
var dom = editorView.domAtPos(pos);
|
|
122
|
+
var expandWrapper = dom.node.parentElement;
|
|
123
|
+
if (expandWrapper) {
|
|
124
|
+
setSelectionInsideExpand(pos)(state, dispatch, editorView);
|
|
125
|
+
var input = expandWrapper.querySelector('input');
|
|
126
|
+
if (input) {
|
|
127
|
+
input.focus();
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
@@ -0,0 +1,381 @@
|
|
|
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 _reactDom = _interopRequireDefault(require("react-dom"));
|
|
13
|
+
var _w3cKeyname = require("w3c-keyname");
|
|
14
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
15
|
+
var _styles = require("@atlaskit/editor-common/styles");
|
|
16
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
17
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
18
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
19
|
+
var _commands = require("../commands");
|
|
20
|
+
var _NodeView = require("../ui/NodeView");
|
|
21
|
+
var ExpandNodeView = exports.ExpandNodeView = /*#__PURE__*/function () {
|
|
22
|
+
function ExpandNodeView(node, view, getPos, getIntl, isMobile, selectNearNode, api) {
|
|
23
|
+
var _this = this;
|
|
24
|
+
var allowInteractiveExpand = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : true;
|
|
25
|
+
var __livePage = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
|
|
26
|
+
(0, _classCallCheck2.default)(this, ExpandNodeView);
|
|
27
|
+
(0, _defineProperty2.default)(this, "allowInteractiveExpand", true);
|
|
28
|
+
(0, _defineProperty2.default)(this, "isMobile", false);
|
|
29
|
+
(0, _defineProperty2.default)(this, "focusTitle", function () {
|
|
30
|
+
if (_this.input) {
|
|
31
|
+
var _this$view = _this.view,
|
|
32
|
+
state = _this$view.state,
|
|
33
|
+
dispatch = _this$view.dispatch;
|
|
34
|
+
if (_this.selectNearNode) {
|
|
35
|
+
var tr = _this.selectNearNode({
|
|
36
|
+
selectionRelativeToNode: _selection.RelativeSelectionPos.Start
|
|
37
|
+
})(state);
|
|
38
|
+
if (dispatch) {
|
|
39
|
+
dispatch(tr);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
var pos = _this.getPos();
|
|
43
|
+
if (typeof pos === 'number') {
|
|
44
|
+
(0, _commands.setSelectionInsideExpand)(pos)(state, dispatch, _this.view);
|
|
45
|
+
}
|
|
46
|
+
_this.input.focus();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
(0, _defineProperty2.default)(this, "handleIconKeyDown", function (event) {
|
|
50
|
+
switch ((0, _w3cKeyname.keyName)(event)) {
|
|
51
|
+
case 'Tab':
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
_this.focusTitle();
|
|
54
|
+
break;
|
|
55
|
+
case 'Enter':
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
_this.handleClick(event);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
(0, _defineProperty2.default)(this, "handleClick", function (event) {
|
|
62
|
+
var pos = _this.getPos();
|
|
63
|
+
if (typeof pos !== 'number') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
var target = event.target;
|
|
67
|
+
if ((0, _utils.closestElement)(target, ".".concat(_styles.expandClassNames.icon))) {
|
|
68
|
+
if (!_this.allowInteractiveExpand) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
event.stopPropagation();
|
|
72
|
+
|
|
73
|
+
// We blur the editorView, to prevent any keyboard showing on mobile
|
|
74
|
+
// When we're interacting with the expand toggle
|
|
75
|
+
if (_this.view.dom instanceof HTMLElement) {
|
|
76
|
+
_this.view.dom.blur();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// TODO https://product-fabric.atlassian.net/browse/ED-22841
|
|
80
|
+
// call toggleExpandExpanded
|
|
81
|
+
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (target === _this.input) {
|
|
85
|
+
event.stopPropagation();
|
|
86
|
+
_this.focusTitle();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
(0, _defineProperty2.default)(this, "handleInput", function (event) {
|
|
91
|
+
var pos = _this.getPos();
|
|
92
|
+
if (typeof pos !== 'number') {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
var target = event.target;
|
|
96
|
+
if (target === _this.input) {
|
|
97
|
+
event.stopPropagation();
|
|
98
|
+
var _this$view2 = _this.view,
|
|
99
|
+
state = _this$view2.state,
|
|
100
|
+
dispatch = _this$view2.dispatch;
|
|
101
|
+
(0, _commands.updateExpandTitle)({
|
|
102
|
+
title: target.value,
|
|
103
|
+
pos: pos,
|
|
104
|
+
nodeType: _this.node.type
|
|
105
|
+
})(state, dispatch);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
(0, _defineProperty2.default)(this, "handleFocus", function (event) {
|
|
109
|
+
event.stopImmediatePropagation();
|
|
110
|
+
});
|
|
111
|
+
(0, _defineProperty2.default)(this, "handleTitleKeydown", function (event) {
|
|
112
|
+
switch ((0, _w3cKeyname.keyName)(event)) {
|
|
113
|
+
case 'Enter':
|
|
114
|
+
// TO-DO
|
|
115
|
+
break;
|
|
116
|
+
case 'Tab':
|
|
117
|
+
case 'ArrowDown':
|
|
118
|
+
_this.moveToOutsideOfTitle(event);
|
|
119
|
+
break;
|
|
120
|
+
case 'ArrowRight':
|
|
121
|
+
_this.handleArrowRightFromTitle(event);
|
|
122
|
+
break;
|
|
123
|
+
case 'ArrowLeft':
|
|
124
|
+
_this.handleArrowLeftFromTitle(event);
|
|
125
|
+
break;
|
|
126
|
+
case 'ArrowUp':
|
|
127
|
+
_this.setLeftGapCursor(event);
|
|
128
|
+
break;
|
|
129
|
+
case 'Backspace':
|
|
130
|
+
_this.deleteEmptyExpand();
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
(0, _defineProperty2.default)(this, "deleteEmptyExpand", function () {
|
|
135
|
+
var state = _this.view.state;
|
|
136
|
+
var expandNode = _this.node;
|
|
137
|
+
if (expandNode && (0, _utils.isEmptyNode)(state.schema)(expandNode)) {
|
|
138
|
+
var _this$api;
|
|
139
|
+
(0, _commands.deleteExpand)((_this$api = _this.api) === null || _this$api === void 0 || (_this$api = _this$api.analytics) === null || _this$api === void 0 ? void 0 : _this$api.actions)(state, _this.view.dispatch);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
(0, _defineProperty2.default)(this, "moveToOutsideOfTitle", function (event) {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
var _this$view3 = _this.view,
|
|
145
|
+
state = _this$view3.state,
|
|
146
|
+
dispatch = _this$view3.dispatch;
|
|
147
|
+
var expandPos = _this.getPos();
|
|
148
|
+
if (typeof expandPos !== 'number') {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
var pos = expandPos;
|
|
152
|
+
if (_this.isCollapsed()) {
|
|
153
|
+
pos = expandPos + _this.node.nodeSize;
|
|
154
|
+
}
|
|
155
|
+
var resolvedPos = state.doc.resolve(pos);
|
|
156
|
+
if (!resolvedPos) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (_this.isCollapsed() && resolvedPos.nodeAfter && ['expand', 'nestedExpand'].indexOf(resolvedPos.nodeAfter.type.name) > -1) {
|
|
160
|
+
return _this.setRightGapCursor(event);
|
|
161
|
+
}
|
|
162
|
+
var sel = _state.Selection.findFrom(resolvedPos, 1, true);
|
|
163
|
+
if (sel) {
|
|
164
|
+
// If the input has focus, ProseMirror doesn't
|
|
165
|
+
// Give PM focus back before changing our selection
|
|
166
|
+
_this.view.focus();
|
|
167
|
+
dispatch(state.tr.setSelection(sel));
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
// TODO: https://product-fabric.atlassian.net/browse/ED-22841
|
|
171
|
+
(0, _defineProperty2.default)(this, "isCollapsed", function () {
|
|
172
|
+
return false;
|
|
173
|
+
});
|
|
174
|
+
(0, _defineProperty2.default)(this, "setRightGapCursor", function (event) {
|
|
175
|
+
if (!_this.input) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
var pos = _this.getPos();
|
|
179
|
+
if (typeof pos !== 'number') {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
var _this$input = _this.input,
|
|
183
|
+
value = _this$input.value,
|
|
184
|
+
selectionStart = _this$input.selectionStart,
|
|
185
|
+
selectionEnd = _this$input.selectionEnd;
|
|
186
|
+
if (selectionStart === selectionEnd && selectionStart === value.length) {
|
|
187
|
+
var _this$view4 = _this.view,
|
|
188
|
+
state = _this$view4.state,
|
|
189
|
+
dispatch = _this$view4.dispatch;
|
|
190
|
+
event.preventDefault();
|
|
191
|
+
_this.view.focus();
|
|
192
|
+
dispatch(state.tr.setSelection(new _selection.GapCursorSelection(state.doc.resolve(_this.node.nodeSize + pos), _selection.Side.RIGHT)));
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
(0, _defineProperty2.default)(this, "setLeftGapCursor", function (event) {
|
|
196
|
+
if (!_this.input) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
var pos = _this.getPos();
|
|
200
|
+
if (typeof pos !== 'number') {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
var _this$input2 = _this.input,
|
|
204
|
+
selectionStart = _this$input2.selectionStart,
|
|
205
|
+
selectionEnd = _this$input2.selectionEnd;
|
|
206
|
+
if (selectionStart === selectionEnd && selectionStart === 0) {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
var _this$view5 = _this.view,
|
|
209
|
+
state = _this$view5.state,
|
|
210
|
+
dispatch = _this$view5.dispatch;
|
|
211
|
+
_this.view.focus();
|
|
212
|
+
dispatch(state.tr.setSelection(new _selection.GapCursorSelection(state.doc.resolve(pos), _selection.Side.LEFT)));
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
(0, _defineProperty2.default)(this, "handleArrowRightFromTitle", function (event) {
|
|
216
|
+
if (!_this.input || !_this.selectNearNode) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
var pos = _this.getPos();
|
|
220
|
+
if (typeof pos !== 'number') {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
var _this$input3 = _this.input,
|
|
224
|
+
value = _this$input3.value,
|
|
225
|
+
selectionStart = _this$input3.selectionStart,
|
|
226
|
+
selectionEnd = _this$input3.selectionEnd;
|
|
227
|
+
if (selectionStart === selectionEnd && selectionStart === value.length) {
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
var _this$view6 = _this.view,
|
|
230
|
+
state = _this$view6.state,
|
|
231
|
+
dispatch = _this$view6.dispatch;
|
|
232
|
+
_this.view.focus();
|
|
233
|
+
var tr = _this.selectNearNode({
|
|
234
|
+
selectionRelativeToNode: _selection.RelativeSelectionPos.End,
|
|
235
|
+
selection: _state.NodeSelection.create(state.doc, pos)
|
|
236
|
+
})(state);
|
|
237
|
+
if (dispatch) {
|
|
238
|
+
dispatch(tr);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
(0, _defineProperty2.default)(this, "handleArrowLeftFromTitle", function (event) {
|
|
243
|
+
if (!_this.input || !_this.selectNearNode) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
var pos = _this.getPos();
|
|
247
|
+
if (typeof pos !== 'number') {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
var _this$input4 = _this.input,
|
|
251
|
+
selectionStart = _this$input4.selectionStart,
|
|
252
|
+
selectionEnd = _this$input4.selectionEnd;
|
|
253
|
+
if (selectionStart === selectionEnd && selectionStart === 0) {
|
|
254
|
+
var _this$api2;
|
|
255
|
+
event.preventDefault();
|
|
256
|
+
var _this$view7 = _this.view,
|
|
257
|
+
state = _this$view7.state,
|
|
258
|
+
dispatch = _this$view7.dispatch;
|
|
259
|
+
_this.view.focus();
|
|
260
|
+
var selectionSharedState = ((_this$api2 = _this.api) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.selection) === null || _this$api2 === void 0 ? void 0 : _this$api2.sharedState.currentState()) || {};
|
|
261
|
+
// selectionRelativeToNode is undefined when user clicked to select node, then hit left to get focus in title
|
|
262
|
+
// This is a special case where we want to bypass node selection and jump straight to gap cursor
|
|
263
|
+
if ((selectionSharedState === null || selectionSharedState === void 0 ? void 0 : selectionSharedState.selectionRelativeToNode) === undefined) {
|
|
264
|
+
var tr = _this.selectNearNode({
|
|
265
|
+
selectionRelativeToNode: undefined,
|
|
266
|
+
selection: new _selection.GapCursorSelection(state.doc.resolve(pos), _selection.Side.LEFT)
|
|
267
|
+
})(state);
|
|
268
|
+
if (dispatch) {
|
|
269
|
+
dispatch(tr);
|
|
270
|
+
}
|
|
271
|
+
} else {
|
|
272
|
+
var _tr = _this.selectNearNode({
|
|
273
|
+
selectionRelativeToNode: _selection.RelativeSelectionPos.Start,
|
|
274
|
+
selection: _state.NodeSelection.create(state.doc, pos)
|
|
275
|
+
})(state);
|
|
276
|
+
if (dispatch) {
|
|
277
|
+
dispatch(_tr);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
this.selectNearNode = selectNearNode;
|
|
283
|
+
this.__livePage = __livePage;
|
|
284
|
+
this.intl = getIntl();
|
|
285
|
+
var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, (0, _NodeView.toDOM)(node, this.__livePage, this.intl)),
|
|
286
|
+
dom = _DOMSerializer$render.dom,
|
|
287
|
+
contentDOM = _DOMSerializer$render.contentDOM;
|
|
288
|
+
this.allowInteractiveExpand = allowInteractiveExpand;
|
|
289
|
+
this.getPos = getPos;
|
|
290
|
+
this.view = view;
|
|
291
|
+
this.node = node;
|
|
292
|
+
this.dom = dom;
|
|
293
|
+
this.contentDOM = contentDOM;
|
|
294
|
+
this.isMobile = isMobile;
|
|
295
|
+
this.api = api;
|
|
296
|
+
this.icon = this.dom.querySelector(".".concat(_styles.expandClassNames.icon));
|
|
297
|
+
this.input = this.dom.querySelector(".".concat(_styles.expandClassNames.titleInput));
|
|
298
|
+
this.titleContainer = this.dom.querySelector(".".concat(_styles.expandClassNames.titleContainer));
|
|
299
|
+
(0, _NodeView.renderIcon)(this.icon, this.allowInteractiveExpand, this.intl);
|
|
300
|
+
if (!this.input || !this.titleContainer || !this.icon) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Add event listeners
|
|
305
|
+
/* eslint-disable @repo/internal/dom-events/no-unsafe-event-listeners*/
|
|
306
|
+
this.dom.addEventListener('click', this.handleClick);
|
|
307
|
+
this.dom.addEventListener('input', this.handleInput);
|
|
308
|
+
this.input.addEventListener('keydown', this.handleTitleKeydown);
|
|
309
|
+
// If the user interacts in our title bar (either toggle or input)
|
|
310
|
+
// Prevent ProseMirror from getting a focus event (causes weird selection issues).
|
|
311
|
+
this.titleContainer.addEventListener('focus', this.handleFocus);
|
|
312
|
+
this.icon.addEventListener('keydown', this.handleIconKeyDown);
|
|
313
|
+
}
|
|
314
|
+
(0, _createClass2.default)(ExpandNodeView, [{
|
|
315
|
+
key: "stopEvent",
|
|
316
|
+
value: function stopEvent(event) {
|
|
317
|
+
var target = event.target;
|
|
318
|
+
return target === this.input || target === this.icon || !!(0, _utils.closestElement)(target, ".".concat(_styles.expandClassNames.icon));
|
|
319
|
+
}
|
|
320
|
+
}, {
|
|
321
|
+
key: "ignoreMutation",
|
|
322
|
+
value: function ignoreMutation(mutationRecord) {
|
|
323
|
+
// ME-1931: Mobile relies on composition which creates dom mutations. If we ignore them, prosemirror
|
|
324
|
+
// does not recognise the changes and reverts them.
|
|
325
|
+
if (this.isMobile && (mutationRecord.type === 'characterData' || mutationRecord.type === 'childList')) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
if (mutationRecord.type === 'selection') {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
}, {
|
|
334
|
+
key: "update",
|
|
335
|
+
value: function update(node, _decorations) {
|
|
336
|
+
var _this2 = this;
|
|
337
|
+
if (this.node.type === node.type) {
|
|
338
|
+
// TODO: https://product-fabric.atlassian.net/browse/ED-22841
|
|
339
|
+
// Handle toggling of the expand on update here
|
|
340
|
+
|
|
341
|
+
// During a collab session the title doesn't sync with other users
|
|
342
|
+
// since we're intentionally being less aggressive about re-rendering.
|
|
343
|
+
// We also apply a rAF to avoid abrupt continuous replacement of the title.
|
|
344
|
+
window.requestAnimationFrame(function () {
|
|
345
|
+
if (_this2.input && _this2.node.attrs.title !== _this2.input.value) {
|
|
346
|
+
_this2.input.value = _this2.node.attrs.title;
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
this.node = node;
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
}, {
|
|
355
|
+
key: "destroy",
|
|
356
|
+
value: function destroy() {
|
|
357
|
+
if (!this.dom || !this.input || !this.titleContainer || !this.icon) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
this.dom.removeEventListener('click', this.handleClick);
|
|
361
|
+
this.dom.removeEventListener('input', this.handleInput);
|
|
362
|
+
this.input.removeEventListener('keydown', this.handleTitleKeydown);
|
|
363
|
+
this.titleContainer.removeEventListener('focus', this.handleFocus);
|
|
364
|
+
this.icon.removeEventListener('keydown', this.handleIconKeyDown);
|
|
365
|
+
_reactDom.default.unmountComponentAtNode(this.icon);
|
|
366
|
+
}
|
|
367
|
+
}]);
|
|
368
|
+
return ExpandNodeView;
|
|
369
|
+
}();
|
|
370
|
+
function _default(_ref) {
|
|
371
|
+
var getIntl = _ref.getIntl,
|
|
372
|
+
isMobile = _ref.isMobile,
|
|
373
|
+
api = _ref.api,
|
|
374
|
+
_ref$allowInteractive = _ref.allowInteractiveExpand,
|
|
375
|
+
allowInteractiveExpand = _ref$allowInteractive === void 0 ? true : _ref$allowInteractive,
|
|
376
|
+
__livePage = _ref.__livePage;
|
|
377
|
+
return function (node, view, getPos) {
|
|
378
|
+
var _api$selection;
|
|
379
|
+
return new ExpandNodeView(node, view, getPos, getIntl, isMobile, 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, allowInteractiveExpand, __livePage);
|
|
380
|
+
};
|
|
381
|
+
}
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.expandPlugin = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
7
9
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
11
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
12
|
+
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
13
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
8
14
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
15
|
+
var _commands = require("./commands");
|
|
16
|
+
var _keymap = require("./pm-plugins/keymap");
|
|
17
|
+
var _main = require("./pm-plugins/main");
|
|
18
|
+
var _toolbar = require("./toolbar");
|
|
19
|
+
var expandPlugin = exports.expandPlugin = function expandPlugin(_ref) {
|
|
20
|
+
var _api$analytics;
|
|
21
|
+
var _ref$config = _ref.config,
|
|
22
|
+
options = _ref$config === void 0 ? {} : _ref$config,
|
|
23
|
+
api = _ref.api;
|
|
13
24
|
return {
|
|
14
25
|
name: 'expand',
|
|
15
26
|
nodes: function nodes() {
|
|
@@ -23,13 +34,65 @@ var expandPlugin = exports.expandPlugin = function expandPlugin() {
|
|
|
23
34
|
}];
|
|
24
35
|
},
|
|
25
36
|
actions: {
|
|
26
|
-
insertExpand:
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
37
|
+
insertExpand: (0, _commands.insertExpand)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)
|
|
29
38
|
},
|
|
30
39
|
pmPlugins: function pmPlugins() {
|
|
31
|
-
return [
|
|
40
|
+
return [{
|
|
41
|
+
name: 'expand',
|
|
42
|
+
plugin: function plugin(_ref2) {
|
|
43
|
+
var _options$allowInterac;
|
|
44
|
+
var dispatch = _ref2.dispatch,
|
|
45
|
+
getIntl = _ref2.getIntl;
|
|
46
|
+
return (0, _main.createPlugin)(dispatch, getIntl, options.appearance, options.useLongPressSelection, api, (_options$allowInterac = options.allowInteractiveExpand) !== null && _options$allowInterac !== void 0 ? _options$allowInterac : true, options.__livePage);
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
name: 'expandKeymap',
|
|
50
|
+
plugin: function plugin() {
|
|
51
|
+
return (0, _keymap.expandKeymap)(api, {
|
|
52
|
+
__livePage: options.__livePage
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}];
|
|
32
56
|
},
|
|
33
|
-
pluginsOptions: {
|
|
57
|
+
pluginsOptions: {
|
|
58
|
+
floatingToolbar: (0, _toolbar.getToolbarConfig)(api),
|
|
59
|
+
quickInsert: function quickInsert(_ref3) {
|
|
60
|
+
var formatMessage = _ref3.formatMessage;
|
|
61
|
+
if (options && options.allowInsertion !== true) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return [{
|
|
65
|
+
id: 'expand',
|
|
66
|
+
title: formatMessage(_messages.toolbarInsertBlockMessages.expand),
|
|
67
|
+
description: formatMessage(_messages.toolbarInsertBlockMessages.expandDescription),
|
|
68
|
+
keywords: ['accordion', 'collapse'],
|
|
69
|
+
priority: 600,
|
|
70
|
+
icon: function icon() {
|
|
71
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconExpand, null);
|
|
72
|
+
},
|
|
73
|
+
action: function action(insert, state) {
|
|
74
|
+
var _api$analytics2;
|
|
75
|
+
var node = (0, _commands.createExpandNode)(state);
|
|
76
|
+
if (!node) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
var tr = state.selection.empty ? insert(node) : (0, _utils.createWrapSelectionTransaction)({
|
|
80
|
+
state: state,
|
|
81
|
+
type: node.type
|
|
82
|
+
});
|
|
83
|
+
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.attachAnalyticsEvent({
|
|
84
|
+
action: _analytics.ACTION.INSERTED,
|
|
85
|
+
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
86
|
+
actionSubjectId: node.type === state.schema.nodes.nestedExpand ? _analytics.ACTION_SUBJECT_ID.NESTED_EXPAND : _analytics.ACTION_SUBJECT_ID.EXPAND,
|
|
87
|
+
attributes: {
|
|
88
|
+
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
|
|
89
|
+
},
|
|
90
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
91
|
+
})(tr);
|
|
92
|
+
return tr;
|
|
93
|
+
}
|
|
94
|
+
}];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
34
97
|
};
|
|
35
98
|
};
|