@atlaskit/editor-plugin-panel 12.1.3 → 12.2.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 +12 -0
- package/dist/cjs/editor-actions/actions.js +9 -6
- package/dist/cjs/panelPlugin.js +16 -5
- package/dist/cjs/pm-plugins/keymaps.js +10 -7
- package/dist/cjs/pm-plugins/main.js +10 -3
- package/dist/cjs/pm-plugins/utils/utils.js +37 -6
- package/dist/cjs/ui/toolbar.js +2 -1
- package/dist/es2019/editor-actions/actions.js +10 -7
- package/dist/es2019/panelPlugin.js +17 -8
- package/dist/es2019/pm-plugins/keymaps.js +7 -6
- package/dist/es2019/pm-plugins/main.js +6 -2
- package/dist/es2019/pm-plugins/utils/utils.js +38 -6
- package/dist/es2019/ui/toolbar.js +2 -1
- package/dist/esm/editor-actions/actions.js +10 -7
- package/dist/esm/panelPlugin.js +17 -6
- package/dist/esm/pm-plugins/keymaps.js +10 -7
- package/dist/esm/pm-plugins/main.js +9 -3
- package/dist/esm/pm-plugins/utils/utils.js +36 -5
- package/dist/esm/ui/toolbar.js +2 -1
- package/dist/types/pm-plugins/utils/utils.d.ts +6 -1
- package/dist/types-ts4.5/pm-plugins/utils/utils.d.ts +6 -1
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-panel
|
|
2
2
|
|
|
3
|
+
## 12.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`ad45394a4fed6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ad45394a4fed6) -
|
|
8
|
+
[ux] EDITOR-7171 add panel plugin support for new panel_c1 node variant which can have tables
|
|
9
|
+
nested inside
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 12.1.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -10,6 +10,7 @@ var _analytics = require("@atlaskit/editor-common/analytics");
|
|
|
10
10
|
var _panel = require("@atlaskit/editor-common/panel");
|
|
11
11
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
12
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
13
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
13
14
|
var _utils2 = require("../pm-plugins/utils/utils");
|
|
14
15
|
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; }
|
|
15
16
|
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; }
|
|
@@ -25,11 +26,12 @@ var removePanel = exports.removePanel = function removePanel(editorAnalyticsAPI)
|
|
|
25
26
|
},
|
|
26
27
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
27
28
|
};
|
|
29
|
+
var panelNodeTypes = (0, _utils2.panelTypes)(nodes);
|
|
28
30
|
var deleteTr = tr;
|
|
29
|
-
if ((0, _utils.findSelectedNodeOfType)(
|
|
31
|
+
if ((0, _utils.findSelectedNodeOfType)(panelNodeTypes)(tr.selection)) {
|
|
30
32
|
deleteTr = (0, _utils.removeSelectedNode)(tr);
|
|
31
|
-
} else if ((0, _utils.findParentNodeOfType)(
|
|
32
|
-
deleteTr = (0, _utils.removeParentNodeOfType)(
|
|
33
|
+
} else if ((0, _utils.findParentNodeOfType)(panelNodeTypes)(tr.selection)) {
|
|
34
|
+
deleteTr = (0, _utils.removeParentNodeOfType)(panelNodeTypes)(tr);
|
|
33
35
|
}
|
|
34
36
|
if (!deleteTr) {
|
|
35
37
|
return false;
|
|
@@ -55,6 +57,7 @@ var changePanelType = exports.changePanelType = function changePanelType(editorA
|
|
|
55
57
|
var newType = panelType;
|
|
56
58
|
var previousType = panelNode.node.attrs.panelType;
|
|
57
59
|
var newTr;
|
|
60
|
+
var panelNodeType = (0, _expValEquals.expValEquals)('platform_editor_nest_table_in_panel', 'isEnabled', true) ? panelNode.node.type : nodes.panel;
|
|
58
61
|
if (allowCustomPanel) {
|
|
59
62
|
var previousColor = panelNode.node.attrs.panelType === 'custom' ? panelNode.node.attrs.panelColor || 'none' : (0, _panel.getPanelTypeBackgroundNoTokens)(previousType);
|
|
60
63
|
var previousIcon = panelNode.node.attrs.panelIcon;
|
|
@@ -66,7 +69,7 @@ var changePanelType = exports.changePanelType = function changePanelType(editorA
|
|
|
66
69
|
emojiId: previousIconId,
|
|
67
70
|
emojiText: previousIconText
|
|
68
71
|
}, panelOptions);
|
|
69
|
-
newTr = tr.setNodeMarkup(panelNode.pos,
|
|
72
|
+
newTr = tr.setNodeMarkup(panelNode.pos, panelNodeType, {
|
|
70
73
|
panelIcon: newPanelOptions.emoji,
|
|
71
74
|
panelIconId: newPanelOptions.emojiId,
|
|
72
75
|
panelIconText: newPanelOptions.emojiText,
|
|
@@ -74,7 +77,7 @@ var changePanelType = exports.changePanelType = function changePanelType(editorA
|
|
|
74
77
|
panelType: panelType
|
|
75
78
|
});
|
|
76
79
|
} else {
|
|
77
|
-
newTr = tr.setNodeMarkup(panelNode.pos,
|
|
80
|
+
newTr = tr.setNodeMarkup(panelNode.pos, panelNodeType, {
|
|
78
81
|
panelType: panelType
|
|
79
82
|
});
|
|
80
83
|
}
|
|
@@ -89,7 +92,7 @@ var changePanelType = exports.changePanelType = function changePanelType(editorA
|
|
|
89
92
|
};
|
|
90
93
|
|
|
91
94
|
// Select the panel if it was previously selected
|
|
92
|
-
var newTrWithSelection = state.selection instanceof _state.NodeSelection && state.selection.node.type.name
|
|
95
|
+
var newTrWithSelection = state.selection instanceof _state.NodeSelection && (0, _utils2.isPanel)(state.selection.node.type.name) ? newTr.setSelection(new _state.NodeSelection(tr.doc.resolve(panelNode.pos))) : newTr;
|
|
93
96
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(newTrWithSelection);
|
|
94
97
|
newTrWithSelection.setMeta('scrollIntoView', false);
|
|
95
98
|
if (dispatch) {
|
package/dist/cjs/panelPlugin.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
10
|
var _react = _interopRequireDefault(require("react"));
|
|
10
11
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
11
12
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
@@ -15,9 +16,11 @@ var _messages = require("@atlaskit/editor-common/messages");
|
|
|
15
16
|
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
16
17
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
17
18
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
19
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
18
20
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
19
21
|
var _keymaps = _interopRequireDefault(require("./pm-plugins/keymaps"));
|
|
20
22
|
var _main = require("./pm-plugins/main");
|
|
23
|
+
var _utils2 = require("./pm-plugins/utils/utils");
|
|
21
24
|
var _panelBlockMenuItem = require("./ui/panelBlockMenuItem");
|
|
22
25
|
var _toolbar = require("./ui/toolbar");
|
|
23
26
|
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; }
|
|
@@ -57,12 +60,20 @@ var panelPlugin = function panelPlugin(_ref) {
|
|
|
57
60
|
node: _objectSpread(_objectSpread({}, (0, _adfSchema.extendedPanelWithLocalId)(!!allowCustomPanel)), {}, {
|
|
58
61
|
definingAsContext: true
|
|
59
62
|
})
|
|
60
|
-
}]
|
|
63
|
+
}].concat((0, _toConsumableArray2.default)((0, _expValEquals.expValEquals)('platform_editor_nest_table_in_panel', 'isEnabled', true) ? [{
|
|
64
|
+
name: 'panel_c1',
|
|
65
|
+
node: _objectSpread(_objectSpread({}, (0, _adfSchema.extendedPanelC1WithLocalId)(!!allowCustomPanel)), {}, {
|
|
66
|
+
definingAsContext: true
|
|
67
|
+
})
|
|
68
|
+
}] : []));
|
|
61
69
|
}
|
|
62
70
|
return [{
|
|
63
71
|
name: 'panel',
|
|
64
72
|
node: (0, _adfSchema.extendedPanel)(!!allowCustomPanel)
|
|
65
|
-
}]
|
|
73
|
+
}].concat((0, _toConsumableArray2.default)((0, _expValEquals.expValEquals)('platform_editor_nest_table_in_panel', 'isEnabled', true) ? [{
|
|
74
|
+
name: 'panel_c1',
|
|
75
|
+
node: (0, _adfSchema.extendedPanelC1)(!!allowCustomPanel)
|
|
76
|
+
}] : []));
|
|
66
77
|
},
|
|
67
78
|
pmPlugins: function pmPlugins() {
|
|
68
79
|
return [{
|
|
@@ -260,11 +271,11 @@ function createPanelAction(_ref4) {
|
|
|
260
271
|
typeAheadInsert = _ref4.typeAheadInsert,
|
|
261
272
|
_ref4$inputMethod = _ref4.inputMethod,
|
|
262
273
|
inputMethod = _ref4$inputMethod === void 0 ? _analytics.INPUT_METHOD.QUICK_INSERT : _ref4$inputMethod;
|
|
263
|
-
var
|
|
274
|
+
var panelNodeType = (0, _expValEquals.expValEquals)('platform_editor_nest_table_in_panel', 'isEnabled', true) ? (0, _utils2.pickPanelTypeForInsertion)(state) : state.schema.nodes.panel;
|
|
264
275
|
var tr;
|
|
265
276
|
// If the selection is empty, we want to insert the panel on a new line
|
|
266
277
|
if (state.selection.empty) {
|
|
267
|
-
var node =
|
|
278
|
+
var node = panelNodeType.createAndFill(_objectSpread({}, attributes));
|
|
268
279
|
if (!node) {
|
|
269
280
|
return false;
|
|
270
281
|
}
|
|
@@ -279,7 +290,7 @@ function createPanelAction(_ref4) {
|
|
|
279
290
|
} else {
|
|
280
291
|
tr = (0, _utils.createWrapSelectionTransaction)({
|
|
281
292
|
state: state,
|
|
282
|
-
type:
|
|
293
|
+
type: panelNodeType,
|
|
283
294
|
nodeAttributes: _objectSpread({}, attributes)
|
|
284
295
|
});
|
|
285
296
|
}
|
|
@@ -8,6 +8,7 @@ exports.keymapPlugin = keymapPlugin;
|
|
|
8
8
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
9
9
|
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
10
10
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
11
|
+
var _utils3 = require("./utils/utils");
|
|
11
12
|
function findParentNode(selection, nodeType) {
|
|
12
13
|
var parentPosition = (0, _utils2.findParentNodeOfType)(nodeType)(selection);
|
|
13
14
|
if (parentPosition) {
|
|
@@ -31,13 +32,13 @@ function keymapPlugin() {
|
|
|
31
32
|
var selection = state.selection,
|
|
32
33
|
nodes = state.schema.nodes,
|
|
33
34
|
tr = state.tr;
|
|
34
|
-
var
|
|
35
|
-
blockquote = nodes.blockquote,
|
|
35
|
+
var blockquote = nodes.blockquote,
|
|
36
36
|
orderedList = nodes.orderedList,
|
|
37
37
|
bulletList = nodes.bulletList,
|
|
38
38
|
mediaSingle = nodes.mediaSingle,
|
|
39
39
|
mediaGroup = nodes.mediaGroup,
|
|
40
40
|
extension = nodes.extension;
|
|
41
|
+
var panelNodeTypes = (0, _utils3.panelTypes)(nodes);
|
|
41
42
|
var $from = selection.$from,
|
|
42
43
|
$to = selection.$to;
|
|
43
44
|
// Don't do anything if selection is a range
|
|
@@ -52,8 +53,8 @@ function keymapPlugin() {
|
|
|
52
53
|
var $previousPos = tr.doc.resolve(Math.max(0, $from.before($from.depth) - 1));
|
|
53
54
|
var previousNodeType = $previousPos.pos > 0 && $previousPos.parent && $previousPos.parent.type;
|
|
54
55
|
var parentNodeType = $from.parent.type;
|
|
55
|
-
var isPreviousNodeAPanel = previousNodeType
|
|
56
|
-
var isParentNodeAPanel = parentNodeType
|
|
56
|
+
var isPreviousNodeAPanel = previousNodeType && (0, _utils3.isPanel)(previousNodeType.name);
|
|
57
|
+
var isParentNodeAPanel = (0, _utils3.isPanel)(parentNodeType.name);
|
|
57
58
|
var nodeBeforePanel = $previousPos === null || $previousPos === void 0 ? void 0 : $previousPos.nodeBefore;
|
|
58
59
|
var isPreviousNodeMedia = previousNodeType === mediaSingle || previousNodeType === mediaGroup;
|
|
59
60
|
var isPreviousNodeAList = previousNodeType === bulletList || previousNodeType === orderedList;
|
|
@@ -63,13 +64,15 @@ function keymapPlugin() {
|
|
|
63
64
|
|
|
64
65
|
// Stops merging panels when deleting empty paragraph in between
|
|
65
66
|
// Stops merging blockquotes with panels when deleting from start of blockquote
|
|
66
|
-
if (isPreviousNodeAPanel && !isParentNodeAPanel && !isPreviousPosAtExtension ||
|
|
67
|
+
if (isPreviousNodeAPanel && !isParentNodeAPanel && !isPreviousPosAtExtension || panelNodeTypes.some(function (type) {
|
|
68
|
+
return isInsideAnEmptyNode(selection, type, state.schema);
|
|
69
|
+
}) || (0, _utils2.hasParentNodeOfType)(blockquote)(selection) && !isPreviousNodeAList && !isPreviousNodeMedia && !isPreviousPosAtExtension ||
|
|
67
70
|
// Lift line of panel content up and out of the panel, when backspacing
|
|
68
71
|
// at the start of a panel, if the node before the panel is an 'isolating' node
|
|
69
72
|
// (for e.g. a table, or an expand), otherwise the default prosemirror backspace
|
|
70
73
|
// behaviour will fallback to 'select node backward' logic because the node
|
|
71
74
|
// before is an isolating node.
|
|
72
|
-
nodeBeforePanel !== null && nodeBeforePanel !== void 0 && (_nodeBeforePanel$type = nodeBeforePanel.type) !== null && _nodeBeforePanel$type !== void 0 && (_nodeBeforePanel$type = _nodeBeforePanel$type.spec) !== null && _nodeBeforePanel$type !== void 0 && _nodeBeforePanel$type.isolating && (0, _utils2.hasParentNodeOfType)(
|
|
75
|
+
nodeBeforePanel !== null && nodeBeforePanel !== void 0 && (_nodeBeforePanel$type = nodeBeforePanel.type) !== null && _nodeBeforePanel$type !== void 0 && (_nodeBeforePanel$type = _nodeBeforePanel$type.spec) !== null && _nodeBeforePanel$type !== void 0 && _nodeBeforePanel$type.isolating && (0, _utils2.hasParentNodeOfType)(panelNodeTypes)(selection)) {
|
|
73
76
|
var content = $from.node($from.depth).content;
|
|
74
77
|
var insertPos = $previousPos.pos;
|
|
75
78
|
deleteCurrentItem($from, tr).insert(insertPos, content);
|
|
@@ -79,7 +82,7 @@ function keymapPlugin() {
|
|
|
79
82
|
return true;
|
|
80
83
|
}
|
|
81
84
|
var nodeType = $from.node().type;
|
|
82
|
-
if (
|
|
85
|
+
if (!(0, _utils3.isPanel)(nodeType.name)) {
|
|
83
86
|
return false;
|
|
84
87
|
}
|
|
85
88
|
return true;
|
|
@@ -1,15 +1,20 @@
|
|
|
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.createPlugin = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
7
9
|
var _panel = require("@atlaskit/editor-common/panel");
|
|
8
10
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
9
11
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
12
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
10
13
|
var _panel2 = require("../nodeviews/panel");
|
|
11
14
|
var _panelPluginType = require("../panelPluginType");
|
|
12
15
|
var _utils = require("./utils/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; }
|
|
13
18
|
var createPlugin = exports.createPlugin = function createPlugin(dispatch, providerFactory, pluginOptions, api, nodeViewPortalProviderAPI) {
|
|
14
19
|
var _pluginOptions$useLon = pluginOptions.useLongPressSelection,
|
|
15
20
|
useLongPressSelection = _pluginOptions$useLon === void 0 ? false : _pluginOptions$useLon;
|
|
@@ -24,10 +29,12 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, provid
|
|
|
24
29
|
}
|
|
25
30
|
},
|
|
26
31
|
props: {
|
|
27
|
-
nodeViews: {
|
|
32
|
+
nodeViews: _objectSpread({
|
|
28
33
|
panel: (0, _panel2.getPanelNodeView)(pluginOptions, api, nodeViewPortalProviderAPI, providerFactory)
|
|
29
|
-
},
|
|
30
|
-
|
|
34
|
+
}, (0, _expValEquals.expValEquals)('platform_editor_nest_table_in_panel', 'isEnabled', true) ? {
|
|
35
|
+
panel_c1: (0, _panel2.getPanelNodeView)(pluginOptions, api, nodeViewPortalProviderAPI, providerFactory)
|
|
36
|
+
} : {}),
|
|
37
|
+
handleClickOn: (0, _selection.createSelectionClickHandler)((0, _expValEquals.expValEquals)('platform_editor_nest_table_in_panel', 'isEnabled', true) ? ['panel', 'panel_c1'] : ['panel'], function (target) {
|
|
31
38
|
return !!target.closest(".".concat(_panel.PanelSharedCssClassName.prefix));
|
|
32
39
|
}, {
|
|
33
40
|
useLongPressSelection: useLongPressSelection
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.panelContentCheck = exports.panelAttrsToDom = exports.handleCut = exports.findPanel = void 0;
|
|
7
|
+
exports.pickPanelTypeForInsertion = exports.panelTypes = exports.panelContentCheck = exports.panelAttrsToDom = exports.isPanel = exports.handleCut = exports.findPanel = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
10
|
var _panel = require("@atlaskit/editor-common/panel");
|
|
@@ -15,9 +15,38 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
|
15
15
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
16
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
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
|
+
var isPanel = exports.isPanel = function isPanel(nodeName) {
|
|
19
|
+
return (0, _expValEquals.expValEquals)('platform_editor_nest_table_in_panel', 'isEnabled', true) ? ['panel', 'panel_c1'].includes(nodeName) : nodeName === 'panel';
|
|
20
|
+
};
|
|
21
|
+
var panelTypes = exports.panelTypes = function panelTypes(nodes) {
|
|
22
|
+
var panel = nodes.panel,
|
|
23
|
+
panel_c1 = nodes.panel_c1;
|
|
24
|
+
return (0, _expValEquals.expValEquals)('platform_editor_nest_table_in_panel', 'isEnabled', true) ? [panel, panel_c1] : [panel];
|
|
25
|
+
};
|
|
18
26
|
var findPanel = exports.findPanel = function findPanel(state, selection) {
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
return (0, _utils.findSelectedNodeOfType)(panelTypes(state.schema.nodes))(selection || state.selection) || (0, _utils.findParentNodeOfType)(panelTypes(state.schema.nodes))(selection || state.selection);
|
|
28
|
+
};
|
|
29
|
+
var pickPanelTypeForInsertion = exports.pickPanelTypeForInsertion = function pickPanelTypeForInsertion(input) {
|
|
30
|
+
var selection = 'selection' in input ? input.selection : input;
|
|
31
|
+
var schema = selection.$from.doc.type.schema;
|
|
32
|
+
var _schema$nodes = schema.nodes,
|
|
33
|
+
panel = _schema$nodes.panel,
|
|
34
|
+
panel_c1 = _schema$nodes.panel_c1;
|
|
35
|
+
var $from = selection.$from;
|
|
36
|
+
for (var depth = $from.depth; depth >= 0; depth--) {
|
|
37
|
+
var parent = $from.node(depth);
|
|
38
|
+
var index = $from.index(depth);
|
|
39
|
+
if (parent.canReplaceWith(index, index, panel_c1)) {
|
|
40
|
+
return panel_c1;
|
|
41
|
+
}
|
|
42
|
+
var spec = parent.type.spec;
|
|
43
|
+
// Stop at isolating containers (e.g. expand, tableCell) — hard walls where
|
|
44
|
+
// the panel stays inside and should use the regular panel type.
|
|
45
|
+
if (spec.isolating) {
|
|
46
|
+
return panel;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return panel;
|
|
21
50
|
};
|
|
22
51
|
var panelAttrsToDom = exports.panelAttrsToDom = function panelAttrsToDom(attrs, allowCustomPanel) {
|
|
23
52
|
var panelColor = attrs.panelColor,
|
|
@@ -75,14 +104,16 @@ var handleCut = exports.handleCut = function handleCut(newState, oldState) {
|
|
|
75
104
|
var newTr = newState.tr;
|
|
76
105
|
var schema = newState.doc.type.schema;
|
|
77
106
|
if (panelContentCheck(newState, oldState)) {
|
|
107
|
+
var _oldPanelNode$node$ty;
|
|
78
108
|
// Create a panel using oldState with an empty paragraph node
|
|
79
109
|
// and insert it in the same location when panel previously existed
|
|
80
110
|
var emptyParagraph = schema.nodes.paragraph.create();
|
|
81
111
|
var oldPanelNode = (0, _utils.findParentNode)(function (node) {
|
|
82
|
-
return node.type.name
|
|
112
|
+
return isPanel(node.type.name);
|
|
83
113
|
})(oldState.tr.selection);
|
|
84
114
|
var clonedPanelNode = oldPanelNode === null || oldPanelNode === void 0 ? void 0 : oldPanelNode.node.copy();
|
|
85
|
-
var
|
|
115
|
+
var panelNodeType = (0, _expValEquals.expValEquals)('platform_editor_nest_table_in_panel', 'isEnabled', true) ? (_oldPanelNode$node$ty = oldPanelNode === null || oldPanelNode === void 0 ? void 0 : oldPanelNode.node.type) !== null && _oldPanelNode$node$ty !== void 0 ? _oldPanelNode$node$ty : schema.nodes.panel : schema.nodes.panel;
|
|
116
|
+
var newPanelNode = panelNodeType.create(_objectSpread({}, clonedPanelNode === null || clonedPanelNode === void 0 ? void 0 : clonedPanelNode.attrs), emptyParagraph);
|
|
86
117
|
var endPos = oldState.tr.selection.$from.pos;
|
|
87
118
|
if (oldPanelNode) {
|
|
88
119
|
newTr.insert(oldPanelNode.pos, newPanelNode).setSelection(new _state.TextSelection(newTr.doc.resolve(endPos)));
|
|
@@ -98,7 +129,7 @@ var panelContentCheck = exports.panelContentCheck = function panelContentCheck(n
|
|
|
98
129
|
// OR old selection is a codeblock OR old selection is a rule
|
|
99
130
|
var isNodeSelection = oldState.tr.selection instanceof _state.NodeSelection;
|
|
100
131
|
var isNodeTypeRuleOrCodeBlock = isNodeSelection && ['codeBlock', 'rule'].includes(oldState.tr.selection.node.type.name);
|
|
101
|
-
var isParentTypePanel = (0, _utils.findParentNodeOfType)(newState.schema.nodes
|
|
132
|
+
var isParentTypePanel = (0, _utils.findParentNodeOfType)(panelTypes(newState.schema.nodes))(oldState.tr.selection);
|
|
102
133
|
var isparentTypeDecision = (0, _utils.findParentNodeOfType)(newState.schema.nodes.decisionList)(oldState.tr.selection);
|
|
103
134
|
return Boolean(isNodeSelection && (isParentTypePanel === null || isParentTypePanel === void 0 ? void 0 : isParentTypePanel.node.childCount) === 1 && ((isparentTypeDecision === null || isparentTypeDecision === void 0 ? void 0 : isparentTypeDecision.node.childCount) === 1 || isNodeTypeRuleOrCodeBlock));
|
|
104
135
|
};
|
package/dist/cjs/ui/toolbar.js
CHANGED
|
@@ -26,6 +26,7 @@ var _statusDiscovery = _interopRequireDefault(require("@atlaskit/icon/core/statu
|
|
|
26
26
|
var _statusInformation = _interopRequireDefault(require("@atlaskit/icon/core/status-information"));
|
|
27
27
|
var _statusSuccess = _interopRequireDefault(require("@atlaskit/icon/core/status-success"));
|
|
28
28
|
var _statusWarning = _interopRequireDefault(require("@atlaskit/icon/core/status-warning"));
|
|
29
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
29
30
|
var _actions = require("../editor-actions/actions");
|
|
30
31
|
var _utils2 = require("../pm-plugins/utils/utils");
|
|
31
32
|
var _panelTypeDropdown = require("./panelTypeDropdown");
|
|
@@ -332,7 +333,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(stat
|
|
|
332
333
|
var panelObject = (0, _utils2.findPanel)(state);
|
|
333
334
|
if (panelObject) {
|
|
334
335
|
var _api$decorations, _api$analytics;
|
|
335
|
-
var nodeType = state.schema.nodes.panel;
|
|
336
|
+
var nodeType = (0, _expValEquals.expValEquals)('platform_editor_nest_table_in_panel', 'isEnabled', true) ? panelObject.node.type : state.schema.nodes.panel;
|
|
336
337
|
var _panelObject$node$att = panelObject.node.attrs,
|
|
337
338
|
panelType = _panelObject$node$att.panelType,
|
|
338
339
|
panelColor = _panelObject$node$att.panelColor,
|
|
@@ -2,7 +2,8 @@ import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/edit
|
|
|
2
2
|
import { getPanelTypeBackgroundNoTokens } from '@atlaskit/editor-common/panel';
|
|
3
3
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { findParentNodeOfType, findSelectedNodeOfType, removeParentNodeOfType, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
-
import {
|
|
5
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
6
|
+
import { findPanel, isPanel, panelTypes } from '../pm-plugins/utils/utils';
|
|
6
7
|
export const removePanel = editorAnalyticsAPI => (state, dispatch) => {
|
|
7
8
|
const {
|
|
8
9
|
schema: {
|
|
@@ -18,11 +19,12 @@ export const removePanel = editorAnalyticsAPI => (state, dispatch) => {
|
|
|
18
19
|
},
|
|
19
20
|
eventType: EVENT_TYPE.TRACK
|
|
20
21
|
};
|
|
22
|
+
const panelNodeTypes = panelTypes(nodes);
|
|
21
23
|
let deleteTr = tr;
|
|
22
|
-
if (findSelectedNodeOfType(
|
|
24
|
+
if (findSelectedNodeOfType(panelNodeTypes)(tr.selection)) {
|
|
23
25
|
deleteTr = removeSelectedNode(tr);
|
|
24
|
-
} else if (findParentNodeOfType(
|
|
25
|
-
deleteTr = removeParentNodeOfType(
|
|
26
|
+
} else if (findParentNodeOfType(panelNodeTypes)(tr.selection)) {
|
|
27
|
+
deleteTr = removeParentNodeOfType(panelNodeTypes)(tr);
|
|
26
28
|
}
|
|
27
29
|
if (!deleteTr) {
|
|
28
30
|
return false;
|
|
@@ -47,6 +49,7 @@ export const changePanelType = editorAnalyticsAPI => (panelType, panelOptions =
|
|
|
47
49
|
const newType = panelType;
|
|
48
50
|
const previousType = panelNode.node.attrs.panelType;
|
|
49
51
|
let newTr;
|
|
52
|
+
const panelNodeType = expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? panelNode.node.type : nodes.panel;
|
|
50
53
|
if (allowCustomPanel) {
|
|
51
54
|
const previousColor = panelNode.node.attrs.panelType === 'custom' ? panelNode.node.attrs.panelColor || 'none' : getPanelTypeBackgroundNoTokens(previousType);
|
|
52
55
|
const previousIcon = panelNode.node.attrs.panelIcon;
|
|
@@ -59,7 +62,7 @@ export const changePanelType = editorAnalyticsAPI => (panelType, panelOptions =
|
|
|
59
62
|
emojiText: previousIconText,
|
|
60
63
|
...panelOptions
|
|
61
64
|
};
|
|
62
|
-
newTr = tr.setNodeMarkup(panelNode.pos,
|
|
65
|
+
newTr = tr.setNodeMarkup(panelNode.pos, panelNodeType, {
|
|
63
66
|
panelIcon: newPanelOptions.emoji,
|
|
64
67
|
panelIconId: newPanelOptions.emojiId,
|
|
65
68
|
panelIconText: newPanelOptions.emojiText,
|
|
@@ -67,7 +70,7 @@ export const changePanelType = editorAnalyticsAPI => (panelType, panelOptions =
|
|
|
67
70
|
panelType
|
|
68
71
|
});
|
|
69
72
|
} else {
|
|
70
|
-
newTr = tr.setNodeMarkup(panelNode.pos,
|
|
73
|
+
newTr = tr.setNodeMarkup(panelNode.pos, panelNodeType, {
|
|
71
74
|
panelType
|
|
72
75
|
});
|
|
73
76
|
}
|
|
@@ -82,7 +85,7 @@ export const changePanelType = editorAnalyticsAPI => (panelType, panelOptions =
|
|
|
82
85
|
};
|
|
83
86
|
|
|
84
87
|
// Select the panel if it was previously selected
|
|
85
|
-
const newTrWithSelection = state.selection instanceof NodeSelection && state.selection.node.type.name
|
|
88
|
+
const newTrWithSelection = state.selection instanceof NodeSelection && isPanel(state.selection.node.type.name) ? newTr.setSelection(new NodeSelection(tr.doc.resolve(panelNode.pos))) : newTr;
|
|
86
89
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(payload)(newTrWithSelection);
|
|
87
90
|
newTrWithSelection.setMeta('scrollIntoView', false);
|
|
88
91
|
if (dispatch) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { extendedPanel, extendedPanelWithLocalId, PanelType } from '@atlaskit/adf-schema';
|
|
2
|
+
import { extendedPanel, extendedPanelC1, extendedPanelC1WithLocalId, extendedPanelWithLocalId, PanelType } from '@atlaskit/adf-schema';
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { TRANSFORM_STRUCTURE_PANEL_MENU_ITEM, TRANSFORM_STRUCTURE_MENU_SECTION, TRANSFORM_STRUCTURE_MENU_SECTION_RANK } from '@atlaskit/editor-common/block-menu';
|
|
5
5
|
import { insertSelectedItem } from '@atlaskit/editor-common/insert';
|
|
@@ -7,9 +7,11 @@ import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
|
7
7
|
import { IconCustomPanel, IconPanel, IconPanelError, IconPanelNote, IconPanelSuccess, IconPanelWarning } from '@atlaskit/editor-common/quick-insert';
|
|
8
8
|
import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
|
|
9
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
10
11
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
11
12
|
import keymap from './pm-plugins/keymaps';
|
|
12
13
|
import { createPlugin } from './pm-plugins/main';
|
|
14
|
+
import { pickPanelTypeForInsertion } from './pm-plugins/utils/utils';
|
|
13
15
|
import { createPanelBlockMenuItem } from './ui/panelBlockMenuItem';
|
|
14
16
|
import { getToolbarConfig } from './ui/toolbar';
|
|
15
17
|
const PANEL_NODE_NAME = 'panel';
|
|
@@ -47,12 +49,21 @@ const panelPlugin = ({
|
|
|
47
49
|
...extendedPanelWithLocalId(!!allowCustomPanel),
|
|
48
50
|
definingAsContext: true
|
|
49
51
|
}
|
|
50
|
-
}
|
|
52
|
+
}, ...(expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? [{
|
|
53
|
+
name: 'panel_c1',
|
|
54
|
+
node: {
|
|
55
|
+
...extendedPanelC1WithLocalId(!!allowCustomPanel),
|
|
56
|
+
definingAsContext: true
|
|
57
|
+
}
|
|
58
|
+
}] : [])];
|
|
51
59
|
}
|
|
52
60
|
return [{
|
|
53
61
|
name: 'panel',
|
|
54
62
|
node: extendedPanel(!!allowCustomPanel)
|
|
55
|
-
}
|
|
63
|
+
}, ...(expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? [{
|
|
64
|
+
name: 'panel_c1',
|
|
65
|
+
node: extendedPanelC1(!!allowCustomPanel)
|
|
66
|
+
}] : [])];
|
|
56
67
|
},
|
|
57
68
|
pmPlugins() {
|
|
58
69
|
return [{
|
|
@@ -235,13 +246,11 @@ function createPanelAction({
|
|
|
235
246
|
inputMethod = INPUT_METHOD.QUICK_INSERT
|
|
236
247
|
}) {
|
|
237
248
|
var _tr;
|
|
238
|
-
const
|
|
239
|
-
panel
|
|
240
|
-
} = state.schema.nodes;
|
|
249
|
+
const panelNodeType = expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? pickPanelTypeForInsertion(state) : state.schema.nodes.panel;
|
|
241
250
|
let tr;
|
|
242
251
|
// If the selection is empty, we want to insert the panel on a new line
|
|
243
252
|
if (state.selection.empty) {
|
|
244
|
-
const node =
|
|
253
|
+
const node = panelNodeType.createAndFill({
|
|
245
254
|
...attributes
|
|
246
255
|
});
|
|
247
256
|
if (!node) {
|
|
@@ -258,7 +267,7 @@ function createPanelAction({
|
|
|
258
267
|
} else {
|
|
259
268
|
tr = createWrapSelectionTransaction({
|
|
260
269
|
state,
|
|
261
|
-
type:
|
|
270
|
+
type: panelNodeType,
|
|
262
271
|
nodeAttributes: {
|
|
263
272
|
...attributes
|
|
264
273
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isEmptyNode } from '@atlaskit/editor-common/utils';
|
|
2
2
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
3
|
import { findParentNodeOfType, hasParentNodeOfType, setTextSelection } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
+
import { isPanel, panelTypes } from './utils/utils';
|
|
4
5
|
function findParentNode(selection, nodeType) {
|
|
5
6
|
const parentPosition = findParentNodeOfType(nodeType)(selection);
|
|
6
7
|
if (parentPosition) {
|
|
@@ -29,7 +30,6 @@ export function keymapPlugin() {
|
|
|
29
30
|
tr
|
|
30
31
|
} = state;
|
|
31
32
|
const {
|
|
32
|
-
panel,
|
|
33
33
|
blockquote,
|
|
34
34
|
orderedList,
|
|
35
35
|
bulletList,
|
|
@@ -37,6 +37,7 @@ export function keymapPlugin() {
|
|
|
37
37
|
mediaGroup,
|
|
38
38
|
extension
|
|
39
39
|
} = nodes;
|
|
40
|
+
const panelNodeTypes = panelTypes(nodes);
|
|
40
41
|
const {
|
|
41
42
|
$from,
|
|
42
43
|
$to
|
|
@@ -53,8 +54,8 @@ export function keymapPlugin() {
|
|
|
53
54
|
const $previousPos = tr.doc.resolve(Math.max(0, $from.before($from.depth) - 1));
|
|
54
55
|
const previousNodeType = $previousPos.pos > 0 && $previousPos.parent && $previousPos.parent.type;
|
|
55
56
|
const parentNodeType = $from.parent.type;
|
|
56
|
-
const isPreviousNodeAPanel = previousNodeType
|
|
57
|
-
const isParentNodeAPanel = parentNodeType
|
|
57
|
+
const isPreviousNodeAPanel = previousNodeType && isPanel(previousNodeType.name);
|
|
58
|
+
const isParentNodeAPanel = isPanel(parentNodeType.name);
|
|
58
59
|
const nodeBeforePanel = $previousPos === null || $previousPos === void 0 ? void 0 : $previousPos.nodeBefore;
|
|
59
60
|
const isPreviousNodeMedia = previousNodeType === mediaSingle || previousNodeType === mediaGroup;
|
|
60
61
|
const isPreviousNodeAList = previousNodeType === bulletList || previousNodeType === orderedList;
|
|
@@ -64,13 +65,13 @@ export function keymapPlugin() {
|
|
|
64
65
|
|
|
65
66
|
// Stops merging panels when deleting empty paragraph in between
|
|
66
67
|
// Stops merging blockquotes with panels when deleting from start of blockquote
|
|
67
|
-
if (isPreviousNodeAPanel && !isParentNodeAPanel && !isPreviousPosAtExtension || isInsideAnEmptyNode(selection,
|
|
68
|
+
if (isPreviousNodeAPanel && !isParentNodeAPanel && !isPreviousPosAtExtension || panelNodeTypes.some(type => isInsideAnEmptyNode(selection, type, state.schema)) || hasParentNodeOfType(blockquote)(selection) && !isPreviousNodeAList && !isPreviousNodeMedia && !isPreviousPosAtExtension ||
|
|
68
69
|
// Lift line of panel content up and out of the panel, when backspacing
|
|
69
70
|
// at the start of a panel, if the node before the panel is an 'isolating' node
|
|
70
71
|
// (for e.g. a table, or an expand), otherwise the default prosemirror backspace
|
|
71
72
|
// behaviour will fallback to 'select node backward' logic because the node
|
|
72
73
|
// before is an isolating node.
|
|
73
|
-
nodeBeforePanel !== null && nodeBeforePanel !== void 0 && (_nodeBeforePanel$type = nodeBeforePanel.type) !== null && _nodeBeforePanel$type !== void 0 && (_nodeBeforePanel$type2 = _nodeBeforePanel$type.spec) !== null && _nodeBeforePanel$type2 !== void 0 && _nodeBeforePanel$type2.isolating && hasParentNodeOfType(
|
|
74
|
+
nodeBeforePanel !== null && nodeBeforePanel !== void 0 && (_nodeBeforePanel$type = nodeBeforePanel.type) !== null && _nodeBeforePanel$type !== void 0 && (_nodeBeforePanel$type2 = _nodeBeforePanel$type.spec) !== null && _nodeBeforePanel$type2 !== void 0 && _nodeBeforePanel$type2.isolating && hasParentNodeOfType(panelNodeTypes)(selection)) {
|
|
74
75
|
const content = $from.node($from.depth).content;
|
|
75
76
|
const insertPos = $previousPos.pos;
|
|
76
77
|
deleteCurrentItem($from, tr).insert(insertPos, content);
|
|
@@ -80,7 +81,7 @@ export function keymapPlugin() {
|
|
|
80
81
|
return true;
|
|
81
82
|
}
|
|
82
83
|
const nodeType = $from.node().type;
|
|
83
|
-
if (nodeType
|
|
84
|
+
if (!isPanel(nodeType.name)) {
|
|
84
85
|
return false;
|
|
85
86
|
}
|
|
86
87
|
return true;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PanelSharedCssClassName } from '@atlaskit/editor-common/panel';
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
4
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
5
|
import { getPanelNodeView } from '../nodeviews/panel';
|
|
5
6
|
import { pluginKey } from '../panelPluginType';
|
|
6
7
|
import { handleCut } from './utils/utils';
|
|
@@ -18,9 +19,12 @@ export const createPlugin = (dispatch, providerFactory, pluginOptions, api, node
|
|
|
18
19
|
},
|
|
19
20
|
props: {
|
|
20
21
|
nodeViews: {
|
|
21
|
-
panel: getPanelNodeView(pluginOptions, api, nodeViewPortalProviderAPI, providerFactory)
|
|
22
|
+
panel: getPanelNodeView(pluginOptions, api, nodeViewPortalProviderAPI, providerFactory),
|
|
23
|
+
...(expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? {
|
|
24
|
+
panel_c1: getPanelNodeView(pluginOptions, api, nodeViewPortalProviderAPI, providerFactory)
|
|
25
|
+
} : {})
|
|
22
26
|
},
|
|
23
|
-
handleClickOn: createSelectionClickHandler(['panel'], target => !!target.closest(`.${PanelSharedCssClassName.prefix}`), {
|
|
27
|
+
handleClickOn: createSelectionClickHandler(expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? ['panel', 'panel_c1'] : ['panel'], target => !!target.closest(`.${PanelSharedCssClassName.prefix}`), {
|
|
24
28
|
useLongPressSelection
|
|
25
29
|
})
|
|
26
30
|
}
|
|
@@ -5,11 +5,41 @@ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state
|
|
|
5
5
|
import { findParentNode, findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
6
6
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
7
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
8
|
+
export const isPanel = nodeName => {
|
|
9
|
+
return expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? ['panel', 'panel_c1'].includes(nodeName) : nodeName === 'panel';
|
|
10
|
+
};
|
|
11
|
+
export const panelTypes = nodes => {
|
|
12
|
+
const {
|
|
13
|
+
panel,
|
|
14
|
+
panel_c1
|
|
15
|
+
} = nodes;
|
|
16
|
+
return expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? [panel, panel_c1] : [panel];
|
|
17
|
+
};
|
|
8
18
|
export const findPanel = (state, selection) => {
|
|
19
|
+
return findSelectedNodeOfType(panelTypes(state.schema.nodes))(selection || state.selection) || findParentNodeOfType(panelTypes(state.schema.nodes))(selection || state.selection);
|
|
20
|
+
};
|
|
21
|
+
export const pickPanelTypeForInsertion = input => {
|
|
22
|
+
const selection = 'selection' in input ? input.selection : input;
|
|
23
|
+
const schema = selection.$from.doc.type.schema;
|
|
9
24
|
const {
|
|
10
|
-
panel
|
|
11
|
-
|
|
12
|
-
|
|
25
|
+
panel,
|
|
26
|
+
panel_c1
|
|
27
|
+
} = schema.nodes;
|
|
28
|
+
const $from = selection.$from;
|
|
29
|
+
for (let depth = $from.depth; depth >= 0; depth--) {
|
|
30
|
+
const parent = $from.node(depth);
|
|
31
|
+
const index = $from.index(depth);
|
|
32
|
+
if (parent.canReplaceWith(index, index, panel_c1)) {
|
|
33
|
+
return panel_c1;
|
|
34
|
+
}
|
|
35
|
+
const spec = parent.type.spec;
|
|
36
|
+
// Stop at isolating containers (e.g. expand, tableCell) — hard walls where
|
|
37
|
+
// the panel stays inside and should use the regular panel type.
|
|
38
|
+
if (spec.isolating) {
|
|
39
|
+
return panel;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return panel;
|
|
13
43
|
};
|
|
14
44
|
export const panelAttrsToDom = (attrs, allowCustomPanel) => {
|
|
15
45
|
const {
|
|
@@ -74,12 +104,14 @@ export const handleCut = (newState, oldState) => {
|
|
|
74
104
|
schema
|
|
75
105
|
} = newState.doc.type;
|
|
76
106
|
if (panelContentCheck(newState, oldState)) {
|
|
107
|
+
var _oldPanelNode$node$ty;
|
|
77
108
|
// Create a panel using oldState with an empty paragraph node
|
|
78
109
|
// and insert it in the same location when panel previously existed
|
|
79
110
|
const emptyParagraph = schema.nodes.paragraph.create();
|
|
80
|
-
const oldPanelNode = findParentNode(node => node.type.name
|
|
111
|
+
const oldPanelNode = findParentNode(node => isPanel(node.type.name))(oldState.tr.selection);
|
|
81
112
|
const clonedPanelNode = oldPanelNode === null || oldPanelNode === void 0 ? void 0 : oldPanelNode.node.copy();
|
|
82
|
-
const
|
|
113
|
+
const panelNodeType = expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? (_oldPanelNode$node$ty = oldPanelNode === null || oldPanelNode === void 0 ? void 0 : oldPanelNode.node.type) !== null && _oldPanelNode$node$ty !== void 0 ? _oldPanelNode$node$ty : schema.nodes.panel : schema.nodes.panel;
|
|
114
|
+
const newPanelNode = panelNodeType.create({
|
|
83
115
|
...(clonedPanelNode === null || clonedPanelNode === void 0 ? void 0 : clonedPanelNode.attrs)
|
|
84
116
|
}, emptyParagraph);
|
|
85
117
|
const endPos = oldState.tr.selection.$from.pos;
|
|
@@ -97,7 +129,7 @@ export const panelContentCheck = (newState, oldState) => {
|
|
|
97
129
|
// OR old selection is a codeblock OR old selection is a rule
|
|
98
130
|
const isNodeSelection = oldState.tr.selection instanceof NodeSelection;
|
|
99
131
|
const isNodeTypeRuleOrCodeBlock = isNodeSelection && ['codeBlock', 'rule'].includes(oldState.tr.selection.node.type.name);
|
|
100
|
-
const isParentTypePanel = findParentNodeOfType(newState.schema.nodes
|
|
132
|
+
const isParentTypePanel = findParentNodeOfType(panelTypes(newState.schema.nodes))(oldState.tr.selection);
|
|
101
133
|
const isparentTypeDecision = findParentNodeOfType(newState.schema.nodes.decisionList)(oldState.tr.selection);
|
|
102
134
|
return Boolean(isNodeSelection && (isParentTypePanel === null || isParentTypePanel === void 0 ? void 0 : isParentTypePanel.node.childCount) === 1 && ((isparentTypeDecision === null || isparentTypeDecision === void 0 ? void 0 : isparentTypeDecision.node.childCount) === 1 || isNodeTypeRuleOrCodeBlock));
|
|
103
135
|
};
|
|
@@ -16,6 +16,7 @@ import StatusDiscoveryIcon from '@atlaskit/icon/core/status-discovery';
|
|
|
16
16
|
import InformationIcon from '@atlaskit/icon/core/status-information';
|
|
17
17
|
import SuccessIcon from '@atlaskit/icon/core/status-success';
|
|
18
18
|
import WarningIcon from '@atlaskit/icon/core/status-warning';
|
|
19
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
19
20
|
import { changePanelType, removePanel } from '../editor-actions/actions';
|
|
20
21
|
import { findPanel } from '../pm-plugins/utils/utils';
|
|
21
22
|
import { panelTypeDropdown } from './panelTypeDropdown';
|
|
@@ -311,7 +312,7 @@ export const getToolbarConfig = (state, intl, options = {}, providerFactory, api
|
|
|
311
312
|
const panelObject = findPanel(state);
|
|
312
313
|
if (panelObject) {
|
|
313
314
|
var _api$decorations, _api$analytics;
|
|
314
|
-
const nodeType = state.schema.nodes.panel;
|
|
315
|
+
const nodeType = expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? panelObject.node.type : state.schema.nodes.panel;
|
|
315
316
|
const {
|
|
316
317
|
panelType,
|
|
317
318
|
panelColor,
|
|
@@ -5,7 +5,8 @@ import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/edit
|
|
|
5
5
|
import { getPanelTypeBackgroundNoTokens } from '@atlaskit/editor-common/panel';
|
|
6
6
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
7
|
import { findParentNodeOfType, findSelectedNodeOfType, removeParentNodeOfType, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
|
|
8
|
-
import {
|
|
8
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
9
|
+
import { findPanel, isPanel, panelTypes } from '../pm-plugins/utils/utils';
|
|
9
10
|
export var removePanel = function removePanel(editorAnalyticsAPI) {
|
|
10
11
|
return function (state, dispatch) {
|
|
11
12
|
var nodes = state.schema.nodes,
|
|
@@ -18,11 +19,12 @@ export var removePanel = function removePanel(editorAnalyticsAPI) {
|
|
|
18
19
|
},
|
|
19
20
|
eventType: EVENT_TYPE.TRACK
|
|
20
21
|
};
|
|
22
|
+
var panelNodeTypes = panelTypes(nodes);
|
|
21
23
|
var deleteTr = tr;
|
|
22
|
-
if (findSelectedNodeOfType(
|
|
24
|
+
if (findSelectedNodeOfType(panelNodeTypes)(tr.selection)) {
|
|
23
25
|
deleteTr = removeSelectedNode(tr);
|
|
24
|
-
} else if (findParentNodeOfType(
|
|
25
|
-
deleteTr = removeParentNodeOfType(
|
|
26
|
+
} else if (findParentNodeOfType(panelNodeTypes)(tr.selection)) {
|
|
27
|
+
deleteTr = removeParentNodeOfType(panelNodeTypes)(tr);
|
|
26
28
|
}
|
|
27
29
|
if (!deleteTr) {
|
|
28
30
|
return false;
|
|
@@ -48,6 +50,7 @@ export var changePanelType = function changePanelType(editorAnalyticsAPI) {
|
|
|
48
50
|
var newType = panelType;
|
|
49
51
|
var previousType = panelNode.node.attrs.panelType;
|
|
50
52
|
var newTr;
|
|
53
|
+
var panelNodeType = expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? panelNode.node.type : nodes.panel;
|
|
51
54
|
if (allowCustomPanel) {
|
|
52
55
|
var previousColor = panelNode.node.attrs.panelType === 'custom' ? panelNode.node.attrs.panelColor || 'none' : getPanelTypeBackgroundNoTokens(previousType);
|
|
53
56
|
var previousIcon = panelNode.node.attrs.panelIcon;
|
|
@@ -59,7 +62,7 @@ export var changePanelType = function changePanelType(editorAnalyticsAPI) {
|
|
|
59
62
|
emojiId: previousIconId,
|
|
60
63
|
emojiText: previousIconText
|
|
61
64
|
}, panelOptions);
|
|
62
|
-
newTr = tr.setNodeMarkup(panelNode.pos,
|
|
65
|
+
newTr = tr.setNodeMarkup(panelNode.pos, panelNodeType, {
|
|
63
66
|
panelIcon: newPanelOptions.emoji,
|
|
64
67
|
panelIconId: newPanelOptions.emojiId,
|
|
65
68
|
panelIconText: newPanelOptions.emojiText,
|
|
@@ -67,7 +70,7 @@ export var changePanelType = function changePanelType(editorAnalyticsAPI) {
|
|
|
67
70
|
panelType: panelType
|
|
68
71
|
});
|
|
69
72
|
} else {
|
|
70
|
-
newTr = tr.setNodeMarkup(panelNode.pos,
|
|
73
|
+
newTr = tr.setNodeMarkup(panelNode.pos, panelNodeType, {
|
|
71
74
|
panelType: panelType
|
|
72
75
|
});
|
|
73
76
|
}
|
|
@@ -82,7 +85,7 @@ export var changePanelType = function changePanelType(editorAnalyticsAPI) {
|
|
|
82
85
|
};
|
|
83
86
|
|
|
84
87
|
// Select the panel if it was previously selected
|
|
85
|
-
var newTrWithSelection = state.selection instanceof NodeSelection && state.selection.node.type.name
|
|
88
|
+
var newTrWithSelection = state.selection instanceof NodeSelection && isPanel(state.selection.node.type.name) ? newTr.setSelection(new NodeSelection(tr.doc.resolve(panelNode.pos))) : newTr;
|
|
86
89
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(payload)(newTrWithSelection);
|
|
87
90
|
newTrWithSelection.setMeta('scrollIntoView', false);
|
|
88
91
|
if (dispatch) {
|
package/dist/esm/panelPlugin.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
3
|
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; }
|
|
3
4
|
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) { _defineProperty(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; }
|
|
4
5
|
import React from 'react';
|
|
5
|
-
import { extendedPanel, extendedPanelWithLocalId, PanelType } from '@atlaskit/adf-schema';
|
|
6
|
+
import { extendedPanel, extendedPanelC1, extendedPanelC1WithLocalId, extendedPanelWithLocalId, PanelType } from '@atlaskit/adf-schema';
|
|
6
7
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
7
8
|
import { TRANSFORM_STRUCTURE_PANEL_MENU_ITEM, TRANSFORM_STRUCTURE_MENU_SECTION, TRANSFORM_STRUCTURE_MENU_SECTION_RANK } from '@atlaskit/editor-common/block-menu';
|
|
8
9
|
import { insertSelectedItem } from '@atlaskit/editor-common/insert';
|
|
@@ -10,9 +11,11 @@ import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
|
10
11
|
import { IconCustomPanel, IconPanel, IconPanelError, IconPanelNote, IconPanelSuccess, IconPanelWarning } from '@atlaskit/editor-common/quick-insert';
|
|
11
12
|
import { createWrapSelectionTransaction } from '@atlaskit/editor-common/utils';
|
|
12
13
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
14
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
13
15
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
14
16
|
import keymap from './pm-plugins/keymaps';
|
|
15
17
|
import { createPlugin } from './pm-plugins/main';
|
|
18
|
+
import { pickPanelTypeForInsertion } from './pm-plugins/utils/utils';
|
|
16
19
|
import { createPanelBlockMenuItem } from './ui/panelBlockMenuItem';
|
|
17
20
|
import { getToolbarConfig } from './ui/toolbar';
|
|
18
21
|
var PANEL_NODE_NAME = 'panel';
|
|
@@ -50,12 +53,20 @@ var panelPlugin = function panelPlugin(_ref) {
|
|
|
50
53
|
node: _objectSpread(_objectSpread({}, extendedPanelWithLocalId(!!allowCustomPanel)), {}, {
|
|
51
54
|
definingAsContext: true
|
|
52
55
|
})
|
|
53
|
-
}]
|
|
56
|
+
}].concat(_toConsumableArray(expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? [{
|
|
57
|
+
name: 'panel_c1',
|
|
58
|
+
node: _objectSpread(_objectSpread({}, extendedPanelC1WithLocalId(!!allowCustomPanel)), {}, {
|
|
59
|
+
definingAsContext: true
|
|
60
|
+
})
|
|
61
|
+
}] : []));
|
|
54
62
|
}
|
|
55
63
|
return [{
|
|
56
64
|
name: 'panel',
|
|
57
65
|
node: extendedPanel(!!allowCustomPanel)
|
|
58
|
-
}]
|
|
66
|
+
}].concat(_toConsumableArray(expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? [{
|
|
67
|
+
name: 'panel_c1',
|
|
68
|
+
node: extendedPanelC1(!!allowCustomPanel)
|
|
69
|
+
}] : []));
|
|
59
70
|
},
|
|
60
71
|
pmPlugins: function pmPlugins() {
|
|
61
72
|
return [{
|
|
@@ -253,11 +264,11 @@ function createPanelAction(_ref4) {
|
|
|
253
264
|
typeAheadInsert = _ref4.typeAheadInsert,
|
|
254
265
|
_ref4$inputMethod = _ref4.inputMethod,
|
|
255
266
|
inputMethod = _ref4$inputMethod === void 0 ? INPUT_METHOD.QUICK_INSERT : _ref4$inputMethod;
|
|
256
|
-
var
|
|
267
|
+
var panelNodeType = expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? pickPanelTypeForInsertion(state) : state.schema.nodes.panel;
|
|
257
268
|
var tr;
|
|
258
269
|
// If the selection is empty, we want to insert the panel on a new line
|
|
259
270
|
if (state.selection.empty) {
|
|
260
|
-
var node =
|
|
271
|
+
var node = panelNodeType.createAndFill(_objectSpread({}, attributes));
|
|
261
272
|
if (!node) {
|
|
262
273
|
return false;
|
|
263
274
|
}
|
|
@@ -272,7 +283,7 @@ function createPanelAction(_ref4) {
|
|
|
272
283
|
} else {
|
|
273
284
|
tr = createWrapSelectionTransaction({
|
|
274
285
|
state: state,
|
|
275
|
-
type:
|
|
286
|
+
type: panelNodeType,
|
|
276
287
|
nodeAttributes: _objectSpread({}, attributes)
|
|
277
288
|
});
|
|
278
289
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isEmptyNode } from '@atlaskit/editor-common/utils';
|
|
2
2
|
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
3
|
import { findParentNodeOfType, hasParentNodeOfType, setTextSelection } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
+
import { isPanel, panelTypes } from './utils/utils';
|
|
4
5
|
function findParentNode(selection, nodeType) {
|
|
5
6
|
var parentPosition = findParentNodeOfType(nodeType)(selection);
|
|
6
7
|
if (parentPosition) {
|
|
@@ -24,13 +25,13 @@ export function keymapPlugin() {
|
|
|
24
25
|
var selection = state.selection,
|
|
25
26
|
nodes = state.schema.nodes,
|
|
26
27
|
tr = state.tr;
|
|
27
|
-
var
|
|
28
|
-
blockquote = nodes.blockquote,
|
|
28
|
+
var blockquote = nodes.blockquote,
|
|
29
29
|
orderedList = nodes.orderedList,
|
|
30
30
|
bulletList = nodes.bulletList,
|
|
31
31
|
mediaSingle = nodes.mediaSingle,
|
|
32
32
|
mediaGroup = nodes.mediaGroup,
|
|
33
33
|
extension = nodes.extension;
|
|
34
|
+
var panelNodeTypes = panelTypes(nodes);
|
|
34
35
|
var $from = selection.$from,
|
|
35
36
|
$to = selection.$to;
|
|
36
37
|
// Don't do anything if selection is a range
|
|
@@ -45,8 +46,8 @@ export function keymapPlugin() {
|
|
|
45
46
|
var $previousPos = tr.doc.resolve(Math.max(0, $from.before($from.depth) - 1));
|
|
46
47
|
var previousNodeType = $previousPos.pos > 0 && $previousPos.parent && $previousPos.parent.type;
|
|
47
48
|
var parentNodeType = $from.parent.type;
|
|
48
|
-
var isPreviousNodeAPanel = previousNodeType
|
|
49
|
-
var isParentNodeAPanel = parentNodeType
|
|
49
|
+
var isPreviousNodeAPanel = previousNodeType && isPanel(previousNodeType.name);
|
|
50
|
+
var isParentNodeAPanel = isPanel(parentNodeType.name);
|
|
50
51
|
var nodeBeforePanel = $previousPos === null || $previousPos === void 0 ? void 0 : $previousPos.nodeBefore;
|
|
51
52
|
var isPreviousNodeMedia = previousNodeType === mediaSingle || previousNodeType === mediaGroup;
|
|
52
53
|
var isPreviousNodeAList = previousNodeType === bulletList || previousNodeType === orderedList;
|
|
@@ -56,13 +57,15 @@ export function keymapPlugin() {
|
|
|
56
57
|
|
|
57
58
|
// Stops merging panels when deleting empty paragraph in between
|
|
58
59
|
// Stops merging blockquotes with panels when deleting from start of blockquote
|
|
59
|
-
if (isPreviousNodeAPanel && !isParentNodeAPanel && !isPreviousPosAtExtension ||
|
|
60
|
+
if (isPreviousNodeAPanel && !isParentNodeAPanel && !isPreviousPosAtExtension || panelNodeTypes.some(function (type) {
|
|
61
|
+
return isInsideAnEmptyNode(selection, type, state.schema);
|
|
62
|
+
}) || hasParentNodeOfType(blockquote)(selection) && !isPreviousNodeAList && !isPreviousNodeMedia && !isPreviousPosAtExtension ||
|
|
60
63
|
// Lift line of panel content up and out of the panel, when backspacing
|
|
61
64
|
// at the start of a panel, if the node before the panel is an 'isolating' node
|
|
62
65
|
// (for e.g. a table, or an expand), otherwise the default prosemirror backspace
|
|
63
66
|
// behaviour will fallback to 'select node backward' logic because the node
|
|
64
67
|
// before is an isolating node.
|
|
65
|
-
nodeBeforePanel !== null && nodeBeforePanel !== void 0 && (_nodeBeforePanel$type = nodeBeforePanel.type) !== null && _nodeBeforePanel$type !== void 0 && (_nodeBeforePanel$type = _nodeBeforePanel$type.spec) !== null && _nodeBeforePanel$type !== void 0 && _nodeBeforePanel$type.isolating && hasParentNodeOfType(
|
|
68
|
+
nodeBeforePanel !== null && nodeBeforePanel !== void 0 && (_nodeBeforePanel$type = nodeBeforePanel.type) !== null && _nodeBeforePanel$type !== void 0 && (_nodeBeforePanel$type = _nodeBeforePanel$type.spec) !== null && _nodeBeforePanel$type !== void 0 && _nodeBeforePanel$type.isolating && hasParentNodeOfType(panelNodeTypes)(selection)) {
|
|
66
69
|
var content = $from.node($from.depth).content;
|
|
67
70
|
var insertPos = $previousPos.pos;
|
|
68
71
|
deleteCurrentItem($from, tr).insert(insertPos, content);
|
|
@@ -72,7 +75,7 @@ export function keymapPlugin() {
|
|
|
72
75
|
return true;
|
|
73
76
|
}
|
|
74
77
|
var nodeType = $from.node().type;
|
|
75
|
-
if (nodeType
|
|
78
|
+
if (!isPanel(nodeType.name)) {
|
|
76
79
|
return false;
|
|
77
80
|
}
|
|
78
81
|
return true;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
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; }
|
|
3
|
+
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) { _defineProperty(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; }
|
|
1
4
|
import { PanelSharedCssClassName } from '@atlaskit/editor-common/panel';
|
|
2
5
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
6
|
import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
|
|
7
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
4
8
|
import { getPanelNodeView } from '../nodeviews/panel';
|
|
5
9
|
import { pluginKey } from '../panelPluginType';
|
|
6
10
|
import { handleCut } from './utils/utils';
|
|
@@ -18,10 +22,12 @@ export var createPlugin = function createPlugin(dispatch, providerFactory, plugi
|
|
|
18
22
|
}
|
|
19
23
|
},
|
|
20
24
|
props: {
|
|
21
|
-
nodeViews: {
|
|
25
|
+
nodeViews: _objectSpread({
|
|
22
26
|
panel: getPanelNodeView(pluginOptions, api, nodeViewPortalProviderAPI, providerFactory)
|
|
23
|
-
},
|
|
24
|
-
|
|
27
|
+
}, expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? {
|
|
28
|
+
panel_c1: getPanelNodeView(pluginOptions, api, nodeViewPortalProviderAPI, providerFactory)
|
|
29
|
+
} : {}),
|
|
30
|
+
handleClickOn: createSelectionClickHandler(expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? ['panel', 'panel_c1'] : ['panel'], function (target) {
|
|
25
31
|
return !!target.closest(".".concat(PanelSharedCssClassName.prefix));
|
|
26
32
|
}, {
|
|
27
33
|
useLongPressSelection: useLongPressSelection
|
|
@@ -8,9 +8,38 @@ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state
|
|
|
8
8
|
import { findParentNode, findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
9
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
10
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
11
|
+
export var isPanel = function isPanel(nodeName) {
|
|
12
|
+
return expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? ['panel', 'panel_c1'].includes(nodeName) : nodeName === 'panel';
|
|
13
|
+
};
|
|
14
|
+
export var panelTypes = function panelTypes(nodes) {
|
|
15
|
+
var panel = nodes.panel,
|
|
16
|
+
panel_c1 = nodes.panel_c1;
|
|
17
|
+
return expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? [panel, panel_c1] : [panel];
|
|
18
|
+
};
|
|
11
19
|
export var findPanel = function findPanel(state, selection) {
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
return findSelectedNodeOfType(panelTypes(state.schema.nodes))(selection || state.selection) || findParentNodeOfType(panelTypes(state.schema.nodes))(selection || state.selection);
|
|
21
|
+
};
|
|
22
|
+
export var pickPanelTypeForInsertion = function pickPanelTypeForInsertion(input) {
|
|
23
|
+
var selection = 'selection' in input ? input.selection : input;
|
|
24
|
+
var schema = selection.$from.doc.type.schema;
|
|
25
|
+
var _schema$nodes = schema.nodes,
|
|
26
|
+
panel = _schema$nodes.panel,
|
|
27
|
+
panel_c1 = _schema$nodes.panel_c1;
|
|
28
|
+
var $from = selection.$from;
|
|
29
|
+
for (var depth = $from.depth; depth >= 0; depth--) {
|
|
30
|
+
var parent = $from.node(depth);
|
|
31
|
+
var index = $from.index(depth);
|
|
32
|
+
if (parent.canReplaceWith(index, index, panel_c1)) {
|
|
33
|
+
return panel_c1;
|
|
34
|
+
}
|
|
35
|
+
var spec = parent.type.spec;
|
|
36
|
+
// Stop at isolating containers (e.g. expand, tableCell) — hard walls where
|
|
37
|
+
// the panel stays inside and should use the regular panel type.
|
|
38
|
+
if (spec.isolating) {
|
|
39
|
+
return panel;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return panel;
|
|
14
43
|
};
|
|
15
44
|
export var panelAttrsToDom = function panelAttrsToDom(attrs, allowCustomPanel) {
|
|
16
45
|
var panelColor = attrs.panelColor,
|
|
@@ -68,14 +97,16 @@ export var handleCut = function handleCut(newState, oldState) {
|
|
|
68
97
|
var newTr = newState.tr;
|
|
69
98
|
var schema = newState.doc.type.schema;
|
|
70
99
|
if (panelContentCheck(newState, oldState)) {
|
|
100
|
+
var _oldPanelNode$node$ty;
|
|
71
101
|
// Create a panel using oldState with an empty paragraph node
|
|
72
102
|
// and insert it in the same location when panel previously existed
|
|
73
103
|
var emptyParagraph = schema.nodes.paragraph.create();
|
|
74
104
|
var oldPanelNode = findParentNode(function (node) {
|
|
75
|
-
return node.type.name
|
|
105
|
+
return isPanel(node.type.name);
|
|
76
106
|
})(oldState.tr.selection);
|
|
77
107
|
var clonedPanelNode = oldPanelNode === null || oldPanelNode === void 0 ? void 0 : oldPanelNode.node.copy();
|
|
78
|
-
var
|
|
108
|
+
var panelNodeType = expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? (_oldPanelNode$node$ty = oldPanelNode === null || oldPanelNode === void 0 ? void 0 : oldPanelNode.node.type) !== null && _oldPanelNode$node$ty !== void 0 ? _oldPanelNode$node$ty : schema.nodes.panel : schema.nodes.panel;
|
|
109
|
+
var newPanelNode = panelNodeType.create(_objectSpread({}, clonedPanelNode === null || clonedPanelNode === void 0 ? void 0 : clonedPanelNode.attrs), emptyParagraph);
|
|
79
110
|
var endPos = oldState.tr.selection.$from.pos;
|
|
80
111
|
if (oldPanelNode) {
|
|
81
112
|
newTr.insert(oldPanelNode.pos, newPanelNode).setSelection(new TextSelection(newTr.doc.resolve(endPos)));
|
|
@@ -91,7 +122,7 @@ export var panelContentCheck = function panelContentCheck(newState, oldState) {
|
|
|
91
122
|
// OR old selection is a codeblock OR old selection is a rule
|
|
92
123
|
var isNodeSelection = oldState.tr.selection instanceof NodeSelection;
|
|
93
124
|
var isNodeTypeRuleOrCodeBlock = isNodeSelection && ['codeBlock', 'rule'].includes(oldState.tr.selection.node.type.name);
|
|
94
|
-
var isParentTypePanel = findParentNodeOfType(newState.schema.nodes
|
|
125
|
+
var isParentTypePanel = findParentNodeOfType(panelTypes(newState.schema.nodes))(oldState.tr.selection);
|
|
95
126
|
var isparentTypeDecision = findParentNodeOfType(newState.schema.nodes.decisionList)(oldState.tr.selection);
|
|
96
127
|
return Boolean(isNodeSelection && (isParentTypePanel === null || isParentTypePanel === void 0 ? void 0 : isParentTypePanel.node.childCount) === 1 && ((isparentTypeDecision === null || isparentTypeDecision === void 0 ? void 0 : isparentTypeDecision.node.childCount) === 1 || isNodeTypeRuleOrCodeBlock));
|
|
97
128
|
};
|
package/dist/esm/ui/toolbar.js
CHANGED
|
@@ -20,6 +20,7 @@ import StatusDiscoveryIcon from '@atlaskit/icon/core/status-discovery';
|
|
|
20
20
|
import InformationIcon from '@atlaskit/icon/core/status-information';
|
|
21
21
|
import SuccessIcon from '@atlaskit/icon/core/status-success';
|
|
22
22
|
import WarningIcon from '@atlaskit/icon/core/status-warning';
|
|
23
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
23
24
|
import { changePanelType, removePanel } from '../editor-actions/actions';
|
|
24
25
|
import { findPanel } from '../pm-plugins/utils/utils';
|
|
25
26
|
import { panelTypeDropdown } from './panelTypeDropdown';
|
|
@@ -323,7 +324,7 @@ export var getToolbarConfig = function getToolbarConfig(state, intl) {
|
|
|
323
324
|
var panelObject = findPanel(state);
|
|
324
325
|
if (panelObject) {
|
|
325
326
|
var _api$decorations, _api$analytics;
|
|
326
|
-
var nodeType = state.schema.nodes.panel;
|
|
327
|
+
var nodeType = expValEquals('platform_editor_nest_table_in_panel', 'isEnabled', true) ? panelObject.node.type : state.schema.nodes.panel;
|
|
327
328
|
var _panelObject$node$att = panelObject.node.attrs,
|
|
328
329
|
panelType = _panelObject$node$att.panelType,
|
|
329
330
|
panelColor = _panelObject$node$att.panelColor,
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { PanelAttributes } from '@atlaskit/adf-schema';
|
|
2
|
-
import type { DOMOutputSpec } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { DOMOutputSpec, NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
+
export declare const isPanel: (nodeName: string) => boolean;
|
|
6
|
+
export declare const panelTypes: (nodes: {
|
|
7
|
+
[key: string]: NodeType;
|
|
8
|
+
}) => NodeType[];
|
|
5
9
|
export declare const findPanel: (state: EditorState, selection?: Selection | null) => ReturnType<ReturnType<typeof findSelectedNodeOfType>> | ReturnType<ReturnType<typeof findParentNodeOfType>>;
|
|
10
|
+
export declare const pickPanelTypeForInsertion: (input: EditorState | Selection) => NodeType;
|
|
6
11
|
export declare const panelAttrsToDom: (attrs: PanelAttributes, allowCustomPanel: boolean) => DOMOutputSpec;
|
|
7
12
|
export declare const handleCut: (newState: EditorState, oldState: EditorState) => Transaction | undefined;
|
|
8
13
|
export declare const panelContentCheck: (newState: EditorState, oldState: EditorState) => boolean;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { PanelAttributes } from '@atlaskit/adf-schema';
|
|
2
|
-
import type { DOMOutputSpec } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { DOMOutputSpec, NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
+
export declare const isPanel: (nodeName: string) => boolean;
|
|
6
|
+
export declare const panelTypes: (nodes: {
|
|
7
|
+
[key: string]: NodeType;
|
|
8
|
+
}) => NodeType[];
|
|
5
9
|
export declare const findPanel: (state: EditorState, selection?: Selection | null) => ReturnType<ReturnType<typeof findSelectedNodeOfType>> | ReturnType<ReturnType<typeof findParentNodeOfType>>;
|
|
10
|
+
export declare const pickPanelTypeForInsertion: (input: EditorState | Selection) => NodeType;
|
|
6
11
|
export declare const panelAttrsToDom: (attrs: PanelAttributes, allowCustomPanel: boolean) => DOMOutputSpec;
|
|
7
12
|
export declare const handleCut: (newState: EditorState, oldState: EditorState) => Transaction | undefined;
|
|
8
13
|
export declare const panelContentCheck: (newState: EditorState, oldState: EditorState) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-panel",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "Panel plugin for @atlaskit/editor-core.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,17 +37,17 @@
|
|
|
37
37
|
"@atlaskit/editor-plugin-toolbar": "^7.3.0",
|
|
38
38
|
"@atlaskit/editor-prosemirror": "^7.3.0",
|
|
39
39
|
"@atlaskit/editor-shared-styles": "^3.11.0",
|
|
40
|
-
"@atlaskit/editor-toolbar": "^1.
|
|
40
|
+
"@atlaskit/editor-toolbar": "^1.7.0",
|
|
41
41
|
"@atlaskit/emoji": "^70.10.0",
|
|
42
42
|
"@atlaskit/icon": "^35.0.0",
|
|
43
43
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
44
|
-
"@atlaskit/tmp-editor-statsig": "^82.
|
|
44
|
+
"@atlaskit/tmp-editor-statsig": "^82.3.0",
|
|
45
45
|
"@atlaskit/tokens": "^13.0.0",
|
|
46
46
|
"@babel/runtime": "^7.0.0",
|
|
47
47
|
"uuid": "^3.1.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@atlaskit/editor-common": "^114.
|
|
50
|
+
"@atlaskit/editor-common": "^114.41.0",
|
|
51
51
|
"react": "^18.2.0",
|
|
52
52
|
"react-dom": "^18.2.0",
|
|
53
53
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
@@ -108,6 +108,8 @@
|
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
|
+
"react": "^18.2.0",
|
|
112
|
+
"react-dom": "^18.2.0",
|
|
111
113
|
"react-intl": "^6.6.2"
|
|
112
114
|
}
|
|
113
115
|
}
|