@atlaskit/editor-plugin-panel 1.0.1 → 1.0.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/pm-plugins/main.js +12 -0
- package/dist/cjs/utils.js +33 -1
- package/dist/es2019/pm-plugins/main.js +10 -0
- package/dist/es2019/utils.js +35 -1
- package/dist/esm/pm-plugins/main.js +12 -0
- package/dist/esm/utils.js +33 -1
- package/dist/types/utils.d.ts +2 -0
- package/dist/types-ts4.5/utils.d.ts +2 -0
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-panel
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#70470](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70470) [`7d1629af0072`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7d1629af0072) - ED-21607 Fix issue with cutting nodes leading to panel deletion
|
|
8
|
+
|
|
3
9
|
## 1.0.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -7,13 +7,25 @@ exports.createPlugin = void 0;
|
|
|
7
7
|
var _panel = require("@atlaskit/editor-common/panel");
|
|
8
8
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
9
9
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
10
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
10
11
|
var _panel2 = require("../nodeviews/panel");
|
|
11
12
|
var _types = require("../types");
|
|
13
|
+
var _utils = require("../utils");
|
|
12
14
|
var createPlugin = exports.createPlugin = function createPlugin(dispatch, providerFactory, pluginOptions) {
|
|
13
15
|
var _pluginOptions$useLon = pluginOptions.useLongPressSelection,
|
|
14
16
|
useLongPressSelection = _pluginOptions$useLon === void 0 ? false : _pluginOptions$useLon;
|
|
15
17
|
return new _safePlugin.SafePlugin({
|
|
16
18
|
key: _types.pluginKey,
|
|
19
|
+
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
20
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.allow-custom-cut-for-panel')) {
|
|
21
|
+
var tr = transactions.find(function (tr) {
|
|
22
|
+
return tr.getMeta('uiEvent') === 'cut';
|
|
23
|
+
});
|
|
24
|
+
if (tr) {
|
|
25
|
+
return (0, _utils.handleCut)(newState, oldState);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
17
29
|
props: {
|
|
18
30
|
nodeViews: {
|
|
19
31
|
panel: (0, _panel2.getPanelNodeView)(pluginOptions, providerFactory)
|
package/dist/cjs/utils.js
CHANGED
|
@@ -4,11 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.panelAttrsToDom = exports.findPanel = void 0;
|
|
7
|
+
exports.panelContentCheck = exports.panelAttrsToDom = 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");
|
|
11
11
|
var _editorPalette = require("@atlaskit/editor-palette");
|
|
12
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
13
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
13
14
|
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; }
|
|
14
15
|
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; }
|
|
@@ -50,4 +51,35 @@ var panelAttrsToDom = exports.panelAttrsToDom = function panelAttrsToDom(attrs,
|
|
|
50
51
|
} else {
|
|
51
52
|
return ['div', panelAttrs, contentDiv];
|
|
52
53
|
}
|
|
54
|
+
};
|
|
55
|
+
var handleCut = exports.handleCut = function handleCut(newState, oldState) {
|
|
56
|
+
var newTr = newState.tr;
|
|
57
|
+
var schema = newState.doc.type.schema;
|
|
58
|
+
if (panelContentCheck(newState, oldState)) {
|
|
59
|
+
// Create a panel using oldState with an empty paragraph node
|
|
60
|
+
// and insert it in the same location when panel previously existed
|
|
61
|
+
var emptyParagraph = schema.nodes.paragraph.create();
|
|
62
|
+
var oldPanelNode = (0, _utils.findParentNode)(function (node) {
|
|
63
|
+
return node.type.name === 'panel';
|
|
64
|
+
})(oldState.tr.selection);
|
|
65
|
+
var clonedPanelNode = oldPanelNode === null || oldPanelNode === void 0 ? void 0 : oldPanelNode.node.copy();
|
|
66
|
+
var newPanelNode = schema.nodes.panel.create(_objectSpread({}, clonedPanelNode === null || clonedPanelNode === void 0 ? void 0 : clonedPanelNode.attrs), emptyParagraph);
|
|
67
|
+
var endPos = oldState.tr.selection.$from.pos;
|
|
68
|
+
if (oldPanelNode) {
|
|
69
|
+
newTr.insert(oldPanelNode.pos, newPanelNode).setSelection(new _state.TextSelection(newTr.doc.resolve(endPos)));
|
|
70
|
+
return newTr;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var panelContentCheck = exports.panelContentCheck = function panelContentCheck(newState, oldState) {
|
|
75
|
+
// The following fuctions checks if *
|
|
76
|
+
// a. old selection is a NodeSelection.
|
|
77
|
+
// b. parent element a panel and does it have only one child
|
|
78
|
+
// c. parent node has a decision list and that decision list only has one decision item
|
|
79
|
+
// OR old selection is a codeblock OR old selection is a rule
|
|
80
|
+
var isNodeSelection = oldState.tr.selection instanceof _state.NodeSelection;
|
|
81
|
+
var isNodeTypeRuleOrCodeBlock = isNodeSelection && ['codeBlock', 'rule'].includes(oldState.tr.selection.node.type.name);
|
|
82
|
+
var isParentTypePanel = (0, _utils.findParentNodeOfType)(newState.schema.nodes.panel)(oldState.tr.selection);
|
|
83
|
+
var isparentTypeDecision = (0, _utils.findParentNodeOfType)(newState.schema.nodes.decisionList)(oldState.tr.selection);
|
|
84
|
+
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));
|
|
53
85
|
};
|
|
@@ -1,14 +1,24 @@
|
|
|
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 { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
import { getPanelNodeView } from '../nodeviews/panel';
|
|
5
6
|
import { pluginKey } from '../types';
|
|
7
|
+
import { handleCut } from '../utils';
|
|
6
8
|
export const createPlugin = (dispatch, providerFactory, pluginOptions) => {
|
|
7
9
|
const {
|
|
8
10
|
useLongPressSelection = false
|
|
9
11
|
} = pluginOptions;
|
|
10
12
|
return new SafePlugin({
|
|
11
13
|
key: pluginKey,
|
|
14
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
15
|
+
if (getBooleanFF('platform.editor.allow-custom-cut-for-panel')) {
|
|
16
|
+
const tr = transactions.find(tr => tr.getMeta('uiEvent') === 'cut');
|
|
17
|
+
if (tr) {
|
|
18
|
+
return handleCut(newState, oldState);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
12
22
|
props: {
|
|
13
23
|
nodeViews: {
|
|
14
24
|
panel: getPanelNodeView(pluginOptions, providerFactory)
|
package/dist/es2019/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { PanelType } from '@atlaskit/adf-schema';
|
|
2
2
|
import { PanelSharedCssClassName } from '@atlaskit/editor-common/panel';
|
|
3
3
|
import { hexToEditorBackgroundPaletteColor } from '@atlaskit/editor-palette';
|
|
4
|
-
import {
|
|
4
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import { findParentNode, findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
5
6
|
export const findPanel = (state, selection) => {
|
|
6
7
|
const {
|
|
7
8
|
panel
|
|
@@ -45,4 +46,37 @@ export const panelAttrsToDom = (attrs, allowCustomPanel) => {
|
|
|
45
46
|
} else {
|
|
46
47
|
return ['div', panelAttrs, contentDiv];
|
|
47
48
|
}
|
|
49
|
+
};
|
|
50
|
+
export const handleCut = (newState, oldState) => {
|
|
51
|
+
const newTr = newState.tr;
|
|
52
|
+
const {
|
|
53
|
+
schema
|
|
54
|
+
} = newState.doc.type;
|
|
55
|
+
if (panelContentCheck(newState, oldState)) {
|
|
56
|
+
// Create a panel using oldState with an empty paragraph node
|
|
57
|
+
// and insert it in the same location when panel previously existed
|
|
58
|
+
const emptyParagraph = schema.nodes.paragraph.create();
|
|
59
|
+
const oldPanelNode = findParentNode(node => node.type.name === 'panel')(oldState.tr.selection);
|
|
60
|
+
const clonedPanelNode = oldPanelNode === null || oldPanelNode === void 0 ? void 0 : oldPanelNode.node.copy();
|
|
61
|
+
const newPanelNode = schema.nodes.panel.create({
|
|
62
|
+
...(clonedPanelNode === null || clonedPanelNode === void 0 ? void 0 : clonedPanelNode.attrs)
|
|
63
|
+
}, emptyParagraph);
|
|
64
|
+
const endPos = oldState.tr.selection.$from.pos;
|
|
65
|
+
if (oldPanelNode) {
|
|
66
|
+
newTr.insert(oldPanelNode.pos, newPanelNode).setSelection(new TextSelection(newTr.doc.resolve(endPos)));
|
|
67
|
+
return newTr;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
export const panelContentCheck = (newState, oldState) => {
|
|
72
|
+
// The following fuctions checks if *
|
|
73
|
+
// a. old selection is a NodeSelection.
|
|
74
|
+
// b. parent element a panel and does it have only one child
|
|
75
|
+
// c. parent node has a decision list and that decision list only has one decision item
|
|
76
|
+
// OR old selection is a codeblock OR old selection is a rule
|
|
77
|
+
const isNodeSelection = oldState.tr.selection instanceof NodeSelection;
|
|
78
|
+
const isNodeTypeRuleOrCodeBlock = isNodeSelection && ['codeBlock', 'rule'].includes(oldState.tr.selection.node.type.name);
|
|
79
|
+
const isParentTypePanel = findParentNodeOfType(newState.schema.nodes.panel)(oldState.tr.selection);
|
|
80
|
+
const isparentTypeDecision = findParentNodeOfType(newState.schema.nodes.decisionList)(oldState.tr.selection);
|
|
81
|
+
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));
|
|
48
82
|
};
|
|
@@ -1,13 +1,25 @@
|
|
|
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 { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
import { getPanelNodeView } from '../nodeviews/panel';
|
|
5
6
|
import { pluginKey } from '../types';
|
|
7
|
+
import { handleCut } from '../utils';
|
|
6
8
|
export var createPlugin = function createPlugin(dispatch, providerFactory, pluginOptions) {
|
|
7
9
|
var _pluginOptions$useLon = pluginOptions.useLongPressSelection,
|
|
8
10
|
useLongPressSelection = _pluginOptions$useLon === void 0 ? false : _pluginOptions$useLon;
|
|
9
11
|
return new SafePlugin({
|
|
10
12
|
key: pluginKey,
|
|
13
|
+
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
14
|
+
if (getBooleanFF('platform.editor.allow-custom-cut-for-panel')) {
|
|
15
|
+
var tr = transactions.find(function (tr) {
|
|
16
|
+
return tr.getMeta('uiEvent') === 'cut';
|
|
17
|
+
});
|
|
18
|
+
if (tr) {
|
|
19
|
+
return handleCut(newState, oldState);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
11
23
|
props: {
|
|
12
24
|
nodeViews: {
|
|
13
25
|
panel: getPanelNodeView(pluginOptions, providerFactory)
|
package/dist/esm/utils.js
CHANGED
|
@@ -4,7 +4,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
import { PanelType } from '@atlaskit/adf-schema';
|
|
5
5
|
import { PanelSharedCssClassName } from '@atlaskit/editor-common/panel';
|
|
6
6
|
import { hexToEditorBackgroundPaletteColor } from '@atlaskit/editor-palette';
|
|
7
|
-
import {
|
|
7
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import { findParentNode, findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
8
9
|
export var findPanel = function findPanel(state, selection) {
|
|
9
10
|
var panel = state.schema.nodes.panel;
|
|
10
11
|
return findSelectedNodeOfType(panel)(selection || state.selection) || findParentNodeOfType(panel)(selection || state.selection);
|
|
@@ -43,4 +44,35 @@ export var panelAttrsToDom = function panelAttrsToDom(attrs, allowCustomPanel) {
|
|
|
43
44
|
} else {
|
|
44
45
|
return ['div', panelAttrs, contentDiv];
|
|
45
46
|
}
|
|
47
|
+
};
|
|
48
|
+
export var handleCut = function handleCut(newState, oldState) {
|
|
49
|
+
var newTr = newState.tr;
|
|
50
|
+
var schema = newState.doc.type.schema;
|
|
51
|
+
if (panelContentCheck(newState, oldState)) {
|
|
52
|
+
// Create a panel using oldState with an empty paragraph node
|
|
53
|
+
// and insert it in the same location when panel previously existed
|
|
54
|
+
var emptyParagraph = schema.nodes.paragraph.create();
|
|
55
|
+
var oldPanelNode = findParentNode(function (node) {
|
|
56
|
+
return node.type.name === 'panel';
|
|
57
|
+
})(oldState.tr.selection);
|
|
58
|
+
var clonedPanelNode = oldPanelNode === null || oldPanelNode === void 0 ? void 0 : oldPanelNode.node.copy();
|
|
59
|
+
var newPanelNode = schema.nodes.panel.create(_objectSpread({}, clonedPanelNode === null || clonedPanelNode === void 0 ? void 0 : clonedPanelNode.attrs), emptyParagraph);
|
|
60
|
+
var endPos = oldState.tr.selection.$from.pos;
|
|
61
|
+
if (oldPanelNode) {
|
|
62
|
+
newTr.insert(oldPanelNode.pos, newPanelNode).setSelection(new TextSelection(newTr.doc.resolve(endPos)));
|
|
63
|
+
return newTr;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export var panelContentCheck = function panelContentCheck(newState, oldState) {
|
|
68
|
+
// The following fuctions checks if *
|
|
69
|
+
// a. old selection is a NodeSelection.
|
|
70
|
+
// b. parent element a panel and does it have only one child
|
|
71
|
+
// c. parent node has a decision list and that decision list only has one decision item
|
|
72
|
+
// OR old selection is a codeblock OR old selection is a rule
|
|
73
|
+
var isNodeSelection = oldState.tr.selection instanceof NodeSelection;
|
|
74
|
+
var isNodeTypeRuleOrCodeBlock = isNodeSelection && ['codeBlock', 'rule'].includes(oldState.tr.selection.node.type.name);
|
|
75
|
+
var isParentTypePanel = findParentNodeOfType(newState.schema.nodes.panel)(oldState.tr.selection);
|
|
76
|
+
var isparentTypeDecision = findParentNodeOfType(newState.schema.nodes.decisionList)(oldState.tr.selection);
|
|
77
|
+
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));
|
|
46
78
|
};
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -3,3 +3,5 @@ import type { DOMOutputSpec } from '@atlaskit/editor-prosemirror/model';
|
|
|
3
3
|
import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
export declare const findPanel: (state: EditorState, selection?: Selection | null) => import("prosemirror-utils/dist/types").FindResult;
|
|
5
5
|
export declare const panelAttrsToDom: (attrs: PanelAttributes, allowCustomPanel: boolean) => DOMOutputSpec;
|
|
6
|
+
export declare const handleCut: (newState: EditorState, oldState: EditorState) => import("prosemirror-state").Transaction | undefined;
|
|
7
|
+
export declare const panelContentCheck: (newState: EditorState, oldState: EditorState) => boolean;
|
|
@@ -3,3 +3,5 @@ import type { DOMOutputSpec } from '@atlaskit/editor-prosemirror/model';
|
|
|
3
3
|
import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
export declare const findPanel: (state: EditorState, selection?: Selection | null) => import("prosemirror-utils/dist/types").FindResult;
|
|
5
5
|
export declare const panelAttrsToDom: (attrs: PanelAttributes, allowCustomPanel: boolean) => DOMOutputSpec;
|
|
6
|
+
export declare const handleCut: (newState: EditorState, oldState: EditorState) => import("prosemirror-state").Transaction | undefined;
|
|
7
|
+
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": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Panel plugin for @atlaskit/editor-core.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@atlaskit/adf-schema": "^35.5.1",
|
|
37
|
-
"@atlaskit/editor-common": "^78.
|
|
37
|
+
"@atlaskit/editor-common": "^78.3.0",
|
|
38
38
|
"@atlaskit/editor-palette": "1.5.2",
|
|
39
39
|
"@atlaskit/editor-plugin-analytics": "^1.0.0",
|
|
40
40
|
"@atlaskit/editor-plugin-decorations": "^1.0.0",
|
|
@@ -100,6 +100,9 @@
|
|
|
100
100
|
},
|
|
101
101
|
"platform.editor.allow-extended-panel": {
|
|
102
102
|
"type": "boolean"
|
|
103
|
+
},
|
|
104
|
+
"platform.editor.allow-custom-cut-for-panel": {
|
|
105
|
+
"type": "boolean"
|
|
103
106
|
}
|
|
104
107
|
},
|
|
105
108
|
"stricter": {
|