@atlaskit/editor-plugin-panel 1.0.1 → 1.0.3

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-plugin-panel
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#75775](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/75775) [`d0cee3285a1a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d0cee3285a1a) - ED-22287: Adding 16px right padding to panel for all elements. Also using 12px for the no-icon usecase.
8
+ - Updated dependencies
9
+
10
+ ## 1.0.2
11
+
12
+ ### Patch Changes
13
+
14
+ - [#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
15
+
3
16
  ## 1.0.1
4
17
 
5
18
  ### 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; }
@@ -26,7 +27,7 @@ var panelAttrsToDom = exports.panelAttrsToDom = function panelAttrsToDom(attrs,
26
27
  var hasIcon = !isCustomPanel || !!panelIcon || !!panelIconId;
27
28
  var tokenColor = panelColor && (0, _editorPalette.hexToEditorBackgroundPaletteColor)(panelColor);
28
29
  var panelBackgroundColor = tokenColor || panelColor;
29
- var style = ["".concat(panelColor && isCustomPanel ? "background-color: ".concat(panelBackgroundColor, ";") : ''), "".concat(hasIcon ? '' : 'padding-left: 12px;')].join('');
30
+ var style = ["".concat(panelColor && isCustomPanel ? "background-color: ".concat(panelBackgroundColor, ";") : ''), "".concat(hasIcon ? '' : 'padding-left: 12px;padding-right: 12px;')].join('');
30
31
  var panelAttrs = {
31
32
  class: _panel.PanelSharedCssClassName.prefix,
32
33
  'data-panel-type': panelType || _adfSchema.PanelType.INFO,
@@ -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)
@@ -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 { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
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
@@ -20,7 +21,7 @@ export const panelAttrsToDom = (attrs, allowCustomPanel) => {
20
21
  const hasIcon = !isCustomPanel || !!panelIcon || !!panelIconId;
21
22
  const tokenColor = panelColor && hexToEditorBackgroundPaletteColor(panelColor);
22
23
  const panelBackgroundColor = tokenColor || panelColor;
23
- const style = [`${panelColor && isCustomPanel ? `background-color: ${panelBackgroundColor};` : ''}`, `${hasIcon ? '' : 'padding-left: 12px;'}`].join('');
24
+ const style = [`${panelColor && isCustomPanel ? `background-color: ${panelBackgroundColor};` : ''}`, `${hasIcon ? '' : 'padding-left: 12px;padding-right: 12px;'}`].join('');
24
25
  let panelAttrs = {
25
26
  class: PanelSharedCssClassName.prefix,
26
27
  'data-panel-type': panelType || PanelType.INFO,
@@ -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 { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
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);
@@ -19,7 +20,7 @@ export var panelAttrsToDom = function panelAttrsToDom(attrs, allowCustomPanel) {
19
20
  var hasIcon = !isCustomPanel || !!panelIcon || !!panelIconId;
20
21
  var tokenColor = panelColor && hexToEditorBackgroundPaletteColor(panelColor);
21
22
  var panelBackgroundColor = tokenColor || panelColor;
22
- var style = ["".concat(panelColor && isCustomPanel ? "background-color: ".concat(panelBackgroundColor, ";") : ''), "".concat(hasIcon ? '' : 'padding-left: 12px;')].join('');
23
+ var style = ["".concat(panelColor && isCustomPanel ? "background-color: ".concat(panelBackgroundColor, ";") : ''), "".concat(hasIcon ? '' : 'padding-left: 12px;padding-right: 12px;')].join('');
23
24
  var panelAttrs = {
24
25
  class: PanelSharedCssClassName.prefix,
25
26
  'data-panel-type': panelType || PanelType.INFO,
@@ -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
  };
@@ -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.1",
3
+ "version": "1.0.3",
4
4
  "description": "Panel plugin for @atlaskit/editor-core.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,14 +34,14 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@atlaskit/adf-schema": "^35.5.1",
37
- "@atlaskit/editor-common": "^78.0.0",
37
+ "@atlaskit/editor-common": "^78.5.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",
41
41
  "@atlaskit/editor-prosemirror": "3.0.0",
42
42
  "@atlaskit/editor-shared-styles": "^2.9.0",
43
43
  "@atlaskit/emoji": "^67.6.0",
44
- "@atlaskit/icon": "^22.0.0",
44
+ "@atlaskit/icon": "^22.1.0",
45
45
  "@atlaskit/platform-feature-flags": "^0.2.0",
46
46
  "@atlaskit/theme": "^12.6.0",
47
47
  "@babel/runtime": "^7.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": {