@atlaskit/editor-plugin-block-controls 3.8.5 → 3.8.6

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,14 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 3.8.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#137780](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/137780)
8
+ [`6940941e679c5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6940941e679c5) -
9
+ Move style decoration to own plugin
10
+ - Updated dependencies
11
+
3
12
  ## 3.8.5
4
13
 
5
14
  ### Patch Changes
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.blockControlsPlugin = 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 _selection = require("@atlaskit/editor-common/selection");
11
12
  var _state = require("@atlaskit/editor-prosemirror/state");
@@ -13,6 +14,7 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
14
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
14
15
  var _moveNode = require("./editor-commands/move-node");
15
16
  var _moveToLayout = require("./editor-commands/move-to-layout");
17
+ var _firstNodeDecPlugin = require("./pm-plugins/first-node-dec-plugin");
16
18
  var _main = require("./pm-plugins/main");
17
19
  var _getSelection = require("./pm-plugins/utils/getSelection");
18
20
  var _blockMenu = _interopRequireDefault(require("./ui/block-menu"));
@@ -25,7 +27,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
25
27
  return {
26
28
  name: 'blockControls',
27
29
  pmPlugins: function pmPlugins() {
28
- return [{
30
+ var plugins = [{
29
31
  name: 'blockControlsPmPlugin',
30
32
  plugin: function plugin(_ref2) {
31
33
  var getIntl = _ref2.getIntl,
@@ -33,6 +35,13 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
33
35
  return (0, _main.createPlugin)(api, getIntl, nodeViewPortalProviderAPI);
34
36
  }
35
37
  }];
38
+ var controlsPlugins = [{
39
+ name: 'firstNodeDec',
40
+ plugin: function plugin() {
41
+ return (0, _firstNodeDecPlugin.firstNodeDecPlugin)();
42
+ }
43
+ }];
44
+ return [].concat(plugins, (0, _toConsumableArray2.default)((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? controlsPlugins : []));
36
45
  },
37
46
  commands: {
38
47
  moveNode: (0, _moveNode.moveNode)(api),
@@ -97,9 +97,7 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
97
97
  if (shouldIgnoreNode(node, ignore_nodes, depth, parent)) {
98
98
  return shouldDescend; //skip over, don't consider it a valid depth
99
99
  }
100
- var anchorStyles = pos === 0 && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? // why margin-top:0? well it's not possible using CSS to select the first node in the document while excluding n number of nodes, in this case
101
- // we're rendering quick insert button and drag handle. For now override margin-top to 0
102
- "anchor-name: ".concat(anchorName, ";margin-top:0px;") : "anchor-name: ".concat(anchorName, ";");
100
+ var anchorStyles = "anchor-name: ".concat(anchorName, ";");
103
101
  decs.push(_view.Decoration.node(pos, pos + node.nodeSize, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({
104
102
  style: anchorStyles
105
103
  }, 'data-drag-handler-anchor-name', anchorName), 'data-drag-handler-node-type', nodeTypeWithLevel), 'data-drag-handler-anchor-depth', "".concat(depth)), {
@@ -54,9 +54,9 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
54
54
  isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.parent.type.name) === 'doc';
55
55
  }
56
56
  /*
57
- * We disable mouseover event to fix flickering issue on hover
58
- * However, the tooltip for nested drag handle is no long working.
59
- */
57
+ * We disable mouseover event to fix flickering issue on hover
58
+ * However, the tooltip for nested drag handle is no long working.
59
+ */
60
60
  if (newPos === undefined || !isTopLevelNode) {
61
61
  // This will also hide the tooltip.
62
62
  unbind = (0, _bindEventListener.bind)(element, {
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.firstNodeDecPluginKey = exports.firstNodeDecPlugin = void 0;
7
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
+ var _state = require("@atlaskit/editor-prosemirror/state");
9
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
10
+ var _view = require("@atlaskit/editor-prosemirror/view");
11
+ var firstNodeDecPluginKey = exports.firstNodeDecPluginKey = new _state.PluginKey('firstNodeDec');
12
+ var createFirstNodeDecSet = function createFirstNodeDecSet(state) {
13
+ ;
14
+ var firstNode = state.doc.firstChild;
15
+ if (!firstNode) {
16
+ return _view.DecorationSet.empty;
17
+ }
18
+ return _view.DecorationSet.create(state.doc, [_view.Decoration.node(0, firstNode.nodeSize, {
19
+ style: 'margin-top: 0'
20
+ })]);
21
+ };
22
+ var firstNodeDecPlugin = exports.firstNodeDecPlugin = function firstNodeDecPlugin() {
23
+ return new _safePlugin.SafePlugin({
24
+ key: firstNodeDecPluginKey,
25
+ state: {
26
+ init: function init(_, state) {
27
+ return createFirstNodeDecSet(state);
28
+ },
29
+ apply: function apply(tr, currentState, _, newState) {
30
+ var isDocChanged = tr.docChanged && tr.steps.some(function (step) {
31
+ return step instanceof _transform.ReplaceStep || step instanceof _transform.ReplaceAroundStep;
32
+ });
33
+ // Reapply decorations if there are any steps that modify the document
34
+ if (isDocChanged) {
35
+ return createFirstNodeDecSet(newState);
36
+ }
37
+ return currentState;
38
+ }
39
+ },
40
+ props: {
41
+ decorations: function decorations(state) {
42
+ return firstNodeDecPluginKey.getState(state);
43
+ }
44
+ }
45
+ });
46
+ };
@@ -5,6 +5,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
5
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
6
  import { moveNode } from './editor-commands/move-node';
7
7
  import { moveToLayout } from './editor-commands/move-to-layout';
8
+ import { firstNodeDecPlugin } from './pm-plugins/first-node-dec-plugin';
8
9
  import { createPlugin, key } from './pm-plugins/main';
9
10
  import { selectNode } from './pm-plugins/utils/getSelection';
10
11
  import BlockMenu from './ui/block-menu';
@@ -15,13 +16,18 @@ export const blockControlsPlugin = ({
15
16
  }) => ({
16
17
  name: 'blockControls',
17
18
  pmPlugins() {
18
- return [{
19
+ const plugins = [{
19
20
  name: 'blockControlsPmPlugin',
20
21
  plugin: ({
21
22
  getIntl,
22
23
  nodeViewPortalProviderAPI
23
24
  }) => createPlugin(api, getIntl, nodeViewPortalProviderAPI)
24
25
  }];
26
+ const controlsPlugins = [{
27
+ name: 'firstNodeDec',
28
+ plugin: () => firstNodeDecPlugin()
29
+ }];
30
+ return [...plugins, ...(editorExperiment('platform_editor_controls', 'variant1') ? controlsPlugins : [])];
25
31
  },
26
32
  commands: {
27
33
  moveNode: moveNode(api),
@@ -87,10 +87,7 @@ export const nodeDecorations = (newState, from, to) => {
87
87
  if (shouldIgnoreNode(node, ignore_nodes, depth, parent)) {
88
88
  return shouldDescend; //skip over, don't consider it a valid depth
89
89
  }
90
- const anchorStyles = pos === 0 && editorExperiment('platform_editor_controls', 'variant1') ?
91
- // why margin-top:0? well it's not possible using CSS to select the first node in the document while excluding n number of nodes, in this case
92
- // we're rendering quick insert button and drag handle. For now override margin-top to 0
93
- `anchor-name: ${anchorName};margin-top:0px;` : `anchor-name: ${anchorName};`;
90
+ const anchorStyles = `anchor-name: ${anchorName};`;
94
91
  decs.push(Decoration.node(pos, pos + node.nodeSize, {
95
92
  style: anchorStyles,
96
93
  ['data-drag-handler-anchor-name']: anchorName,
@@ -45,9 +45,9 @@ export const dragHandleDecoration = (api, formatMessage, pos, anchorName, nodeTy
45
45
  isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.parent.type.name) === 'doc';
46
46
  }
47
47
  /*
48
- * We disable mouseover event to fix flickering issue on hover
49
- * However, the tooltip for nested drag handle is no long working.
50
- */
48
+ * We disable mouseover event to fix flickering issue on hover
49
+ * However, the tooltip for nested drag handle is no long working.
50
+ */
51
51
  if (newPos === undefined || !isTopLevelNode) {
52
52
  // This will also hide the tooltip.
53
53
  unbind = bind(element, {
@@ -0,0 +1,36 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
4
+ import { DecorationSet, Decoration } from '@atlaskit/editor-prosemirror/view';
5
+ export const firstNodeDecPluginKey = new PluginKey('firstNodeDec');
6
+ const createFirstNodeDecSet = state => {
7
+ ;
8
+ const firstNode = state.doc.firstChild;
9
+ if (!firstNode) {
10
+ return DecorationSet.empty;
11
+ }
12
+ return DecorationSet.create(state.doc, [Decoration.node(0, firstNode.nodeSize, {
13
+ style: 'margin-top: 0'
14
+ })]);
15
+ };
16
+ export const firstNodeDecPlugin = () => new SafePlugin({
17
+ key: firstNodeDecPluginKey,
18
+ state: {
19
+ init(_, state) {
20
+ return createFirstNodeDecSet(state);
21
+ },
22
+ apply(tr, currentState, _, newState) {
23
+ const isDocChanged = tr.docChanged && tr.steps.some(step => step instanceof ReplaceStep || step instanceof ReplaceAroundStep);
24
+ // Reapply decorations if there are any steps that modify the document
25
+ if (isDocChanged) {
26
+ return createFirstNodeDecSet(newState);
27
+ }
28
+ return currentState;
29
+ }
30
+ },
31
+ props: {
32
+ decorations(state) {
33
+ return firstNodeDecPluginKey.getState(state);
34
+ }
35
+ }
36
+ });
@@ -1,4 +1,5 @@
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';
@@ -8,6 +9,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
9
10
  import { moveNode } from './editor-commands/move-node';
10
11
  import { moveToLayout } from './editor-commands/move-to-layout';
12
+ import { firstNodeDecPlugin } from './pm-plugins/first-node-dec-plugin';
11
13
  import { createPlugin, key } from './pm-plugins/main';
12
14
  import { selectNode } from './pm-plugins/utils/getSelection';
13
15
  import BlockMenu from './ui/block-menu';
@@ -18,7 +20,7 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
18
20
  return {
19
21
  name: 'blockControls',
20
22
  pmPlugins: function pmPlugins() {
21
- return [{
23
+ var plugins = [{
22
24
  name: 'blockControlsPmPlugin',
23
25
  plugin: function plugin(_ref2) {
24
26
  var getIntl = _ref2.getIntl,
@@ -26,6 +28,13 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
26
28
  return createPlugin(api, getIntl, nodeViewPortalProviderAPI);
27
29
  }
28
30
  }];
31
+ var controlsPlugins = [{
32
+ name: 'firstNodeDec',
33
+ plugin: function plugin() {
34
+ return firstNodeDecPlugin();
35
+ }
36
+ }];
37
+ return [].concat(plugins, _toConsumableArray(editorExperiment('platform_editor_controls', 'variant1') ? controlsPlugins : []));
29
38
  },
30
39
  commands: {
31
40
  moveNode: moveNode(api),
@@ -90,9 +90,7 @@ export var nodeDecorations = function nodeDecorations(newState, from, to) {
90
90
  if (shouldIgnoreNode(node, ignore_nodes, depth, parent)) {
91
91
  return shouldDescend; //skip over, don't consider it a valid depth
92
92
  }
93
- var anchorStyles = pos === 0 && editorExperiment('platform_editor_controls', 'variant1') ? // why margin-top:0? well it's not possible using CSS to select the first node in the document while excluding n number of nodes, in this case
94
- // we're rendering quick insert button and drag handle. For now override margin-top to 0
95
- "anchor-name: ".concat(anchorName, ";margin-top:0px;") : "anchor-name: ".concat(anchorName, ";");
93
+ var anchorStyles = "anchor-name: ".concat(anchorName, ";");
96
94
  decs.push(Decoration.node(pos, pos + node.nodeSize, _defineProperty(_defineProperty(_defineProperty({
97
95
  style: anchorStyles
98
96
  }, 'data-drag-handler-anchor-name', anchorName), 'data-drag-handler-node-type', nodeTypeWithLevel), 'data-drag-handler-anchor-depth', "".concat(depth)), {
@@ -47,9 +47,9 @@ export var dragHandleDecoration = function dragHandleDecoration(api, formatMessa
47
47
  isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.parent.type.name) === 'doc';
48
48
  }
49
49
  /*
50
- * We disable mouseover event to fix flickering issue on hover
51
- * However, the tooltip for nested drag handle is no long working.
52
- */
50
+ * We disable mouseover event to fix flickering issue on hover
51
+ * However, the tooltip for nested drag handle is no long working.
52
+ */
53
53
  if (newPos === undefined || !isTopLevelNode) {
54
54
  // This will also hide the tooltip.
55
55
  unbind = bind(element, {
@@ -0,0 +1,40 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
4
+ import { DecorationSet, Decoration } from '@atlaskit/editor-prosemirror/view';
5
+ export var firstNodeDecPluginKey = new PluginKey('firstNodeDec');
6
+ var createFirstNodeDecSet = function createFirstNodeDecSet(state) {
7
+ ;
8
+ var firstNode = state.doc.firstChild;
9
+ if (!firstNode) {
10
+ return DecorationSet.empty;
11
+ }
12
+ return DecorationSet.create(state.doc, [Decoration.node(0, firstNode.nodeSize, {
13
+ style: 'margin-top: 0'
14
+ })]);
15
+ };
16
+ export var firstNodeDecPlugin = function firstNodeDecPlugin() {
17
+ return new SafePlugin({
18
+ key: firstNodeDecPluginKey,
19
+ state: {
20
+ init: function init(_, state) {
21
+ return createFirstNodeDecSet(state);
22
+ },
23
+ apply: function apply(tr, currentState, _, newState) {
24
+ var isDocChanged = tr.docChanged && tr.steps.some(function (step) {
25
+ return step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
26
+ });
27
+ // Reapply decorations if there are any steps that modify the document
28
+ if (isDocChanged) {
29
+ return createFirstNodeDecSet(newState);
30
+ }
31
+ return currentState;
32
+ }
33
+ },
34
+ props: {
35
+ decorations: function decorations(state) {
36
+ return firstNodeDecPluginKey.getState(state);
37
+ }
38
+ }
39
+ });
40
+ };
@@ -0,0 +1,5 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ export declare const firstNodeDecPluginKey: PluginKey<DecorationSet>;
5
+ export declare const firstNodeDecPlugin: () => SafePlugin<DecorationSet>;
@@ -0,0 +1,5 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ export declare const firstNodeDecPluginKey: PluginKey<DecorationSet>;
5
+ export declare const firstNodeDecPlugin: () => SafePlugin<DecorationSet>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "3.8.5",
3
+ "version": "3.8.6",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",