@atlaskit/editor-plugin-block-controls 31.0.3 → 31.0.5

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,22 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 31.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`7efec208f3bb4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7efec208f3bb4) -
8
+ Remove unused runtime dependencies
9
+ - Updated dependencies
10
+
11
+ ## 31.0.4
12
+
13
+ ### Patch Changes
14
+
15
+ - [`c5b599e3bc90a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c5b599e3bc90a) -
16
+ Remove unused internal code and replace loose plugin state return types with PluginState. No
17
+ behaviour change.
18
+ - Updated dependencies
19
+
3
20
  ## 31.0.3
4
21
 
5
22
  ### Patch Changes
@@ -887,7 +887,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
887
887
  if (flags.toolbarFlagsEnabled) {
888
888
  isSelectedViaDragHandle = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined ? meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle : isSelectedViaDragHandle;
889
889
  } else {
890
- isSelectedViaDragHandle = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && flags.toolbarFlagsEnabled && (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle);
890
+ isSelectedViaDragHandle = false;
891
891
  }
892
892
  return {
893
893
  decorations: decorations,
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setCursorPositionAtMovedNode = exports.selectNode = exports.rootTaskListDepth = exports.rootListDepth = exports.newGetSelection = exports.isNodeWithCodeBlock = exports.isHandleCorrelatedToSelection = exports.getSelection = exports.getInlineNodePos = void 0;
6
+ exports.setCursorPositionAtMovedNode = exports.selectNode = exports.rootTaskListDepth = exports.rootListDepth = exports.newGetSelection = exports.isHandleCorrelatedToSelection = exports.getSelection = exports.getInlineNodePos = void 0;
7
7
  var _nodeSelection = require("@atlaskit/editor-common/node-selection");
8
8
  var _selection2 = require("@atlaskit/editor-common/selection");
9
9
  var _selection3 = require("@atlaskit/editor-common/selection/gap-cursor/selection");
@@ -34,16 +34,6 @@ var getInlineNodePos = exports.getInlineNodePos = function getInlineNodePos(doc,
34
34
  inlineNodeEndPos: inlineNodeEndPos
35
35
  };
36
36
  };
37
- var isNodeWithCodeBlock = exports.isNodeWithCodeBlock = function isNodeWithCodeBlock(tr, start, nodeSize) {
38
- var $startPos = tr.doc.resolve(start);
39
- var hasCodeBlock = false;
40
- tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n) {
41
- if (['codeBlock'].includes(n.type.name)) {
42
- hasCodeBlock = true;
43
- }
44
- });
45
- return hasCodeBlock;
46
- };
47
37
 
48
38
  /**
49
39
  * Gets the appropriate selection for the node at the given start position.
@@ -4,8 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.topPositionAdjustment = exports.spacingBetweenNodesForPreview = exports.spaceLookupMap = exports.rootElementGap = exports.nodeMargins = exports.getNestedNodeLeftPaddingMargin = exports.dropTargetMarginMap = exports.dragHandleGap = exports.STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER = exports.STICKY_CONTROLS_TOP_MARGIN = exports.QUICK_INSERT_WIDTH = exports.QUICK_INSERT_LEFT_OFFSET = exports.QUICK_INSERT_HEIGHT = exports.QUICK_INSERT_DIMENSIONS = exports.DRAG_HANDLE_ZINDEX = exports.DRAG_HANDLE_WRAPPED_MEDIA_EMBED_TOP_ADJUSTMENT = exports.DRAG_HANDLE_SYNCED_BLOCK_GAP = exports.DRAG_HANDLE_PARAGRAPH_TOP_ADJUSTMENT = exports.DRAG_HANDLE_PARAGRAPH_SMALL_TOP_ADJUSTMENT = exports.DRAG_HANDLE_NARROW_GAP = exports.DRAG_HANDLE_MAX_WIDTH_PLUS_GAP = exports.DRAG_HANDLE_MAX_GAP = exports.DRAG_HANDLE_LAYOUT_SECTION_TOP_ADJUSTMENT = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_H6_TOP_ADJUSTMENT = exports.DRAG_HANDLE_H5_TOP_ADJUSTMENT = exports.DRAG_HANDLE_H4_TOP_ADJUSTMENT = exports.DRAG_HANDLE_H3_TOP_ADJUSTMENT = exports.DRAG_HANDLE_H2_TOP_ADJUSTMENT = exports.DRAG_HANDLE_H1_TOP_ADJUSTMENT = exports.DRAG_HANDLE_DIVIDER_TOP_ADJUSTMENT = exports.DRAG_HANDLE_BORDER_RADIUS = exports.DEFAULT_COLUMN_DISTRIBUTIONS = exports.BLOCK_CONTROLS_SURFACE_SELECTOR = exports.ACTIVE_QUICK_INSERT_FALLBACK_ANCHOR_NAME = exports.ACTIVE_QUICK_INSERT_ATTR = exports.ACTIVE_DRAG_HANDLE_FALLBACK_ANCHOR_NAME = exports.ACTIVE_DRAG_HANDLE_ATTR = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
+ exports.topPositionAdjustment = exports.spacingBetweenNodesForPreview = exports.rootElementGap = exports.nodeMargins = exports.getNestedNodeLeftPaddingMargin = exports.dragHandleGap = exports.STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER = exports.STICKY_CONTROLS_TOP_MARGIN = exports.QUICK_INSERT_WIDTH = exports.QUICK_INSERT_LEFT_OFFSET = exports.QUICK_INSERT_HEIGHT = exports.QUICK_INSERT_DIMENSIONS = exports.DRAG_HANDLE_ZINDEX = exports.DRAG_HANDLE_WRAPPED_MEDIA_EMBED_TOP_ADJUSTMENT = exports.DRAG_HANDLE_SYNCED_BLOCK_GAP = exports.DRAG_HANDLE_PARAGRAPH_TOP_ADJUSTMENT = exports.DRAG_HANDLE_PARAGRAPH_SMALL_TOP_ADJUSTMENT = exports.DRAG_HANDLE_NARROW_GAP = exports.DRAG_HANDLE_MAX_WIDTH_PLUS_GAP = exports.DRAG_HANDLE_MAX_GAP = exports.DRAG_HANDLE_LAYOUT_SECTION_TOP_ADJUSTMENT = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_H6_TOP_ADJUSTMENT = exports.DRAG_HANDLE_H5_TOP_ADJUSTMENT = exports.DRAG_HANDLE_H4_TOP_ADJUSTMENT = exports.DRAG_HANDLE_H3_TOP_ADJUSTMENT = exports.DRAG_HANDLE_H2_TOP_ADJUSTMENT = exports.DRAG_HANDLE_H1_TOP_ADJUSTMENT = exports.DRAG_HANDLE_DIVIDER_TOP_ADJUSTMENT = exports.DRAG_HANDLE_BORDER_RADIUS = exports.DEFAULT_COLUMN_DISTRIBUTIONS = exports.BLOCK_CONTROLS_SURFACE_SELECTOR = exports.ACTIVE_QUICK_INSERT_FALLBACK_ANCHOR_NAME = exports.ACTIVE_QUICK_INSERT_ATTR = exports.ACTIVE_DRAG_HANDLE_FALLBACK_ANCHOR_NAME = exports.ACTIVE_DRAG_HANDLE_ATTR = void 0;
9
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
9
  var _dragHandle = require("@atlaskit/editor-common/styles/drag-handle");
11
10
  var _utils = require("@atlaskit/editor-common/utils");
@@ -14,7 +13,6 @@ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-ex
14
13
  var _editorExperiment = require("@atlaskit/tmp-editor-statsig/editor-experiment");
15
14
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
16
15
  var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
17
- var _dropTargetMarginMap;
18
16
  var ACTIVE_DRAG_HANDLE_ATTR = exports.ACTIVE_DRAG_HANDLE_ATTR = 'data-active-drag-handle';
19
17
  var ACTIVE_QUICK_INSERT_ATTR = exports.ACTIVE_QUICK_INSERT_ATTR = 'data-active-quick-insert';
20
18
  var BLOCK_CONTROLS_SURFACE_SELECTOR = exports.BLOCK_CONTROLS_SURFACE_SELECTOR = '[data-editor-block-controls-surface]';
@@ -165,25 +163,6 @@ var topPositionAdjustment = exports.topPositionAdjustment = function topPosition
165
163
  return 0;
166
164
  }
167
165
  };
168
- var dropTargetMarginMap = exports.dropTargetMarginMap = (_dropTargetMarginMap = {}, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)(_dropTargetMarginMap, -24, "var(--ds-space-negative-300, -24px)"), -20, "var(--ds-space-negative-250, -20px)"), -16, "var(--ds-space-negative-200, -16px)"), -12, "var(--ds-space-negative-150, -12px)"), -8, "var(--ds-space-negative-100, -8px)"), -6, "var(--ds-space-negative-075, -6px)"), -4, "var(--ds-space-negative-050, -4px)"), -2, "var(--ds-space-negative-025, -2px)"), 0, "var(--ds-space-0, 0px)"), 2, "var(--ds-space-025, 2px)"), (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)(_dropTargetMarginMap, 4, "var(--ds-space-050, 4px)"), 6, "var(--ds-space-075, 6px)"), 8, "var(--ds-space-100, 8px)"), 12, "var(--ds-space-150, 12px)"), 16, "var(--ds-space-200, 16px)"), 20, "var(--ds-space-250, 20px)"), 24, "var(--ds-space-300, 24px)"));
169
-
170
- /**
171
- * This document serves as a quick reference map for correlating various space matches
172
- * to the table provided above.
173
- * For instance, the number 1 will correspond to \{0: token('space.0', '0')\}.
174
- */
175
- var spaceLookupMap = exports.spaceLookupMap = Object.fromEntries(
176
- // 49 = -24 -> 0 -> 24 totaling 49 entries.
177
- Array.from({
178
- length: 49
179
- }, function (_, index) {
180
- var currKeyValue = index - 24;
181
- var keyValues = Object.keys(dropTargetMarginMap).map(Number);
182
- var value = keyValues.reduce(function (acc, curr) {
183
- return Math.abs(currKeyValue - curr) < Math.abs(currKeyValue - acc) ? curr : acc;
184
- }, 1000);
185
- return [currKeyValue, dropTargetMarginMap[value]];
186
- }));
187
166
  var spacingBetweenNodesForPreview = exports.spacingBetweenNodesForPreview = {
188
167
  paragraph: {
189
168
  top: '0.75rem',
@@ -790,7 +790,7 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
790
790
  if (flags.toolbarFlagsEnabled) {
791
791
  isSelectedViaDragHandle = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined ? meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle : isSelectedViaDragHandle;
792
792
  } else {
793
- isSelectedViaDragHandle = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && flags.toolbarFlagsEnabled && (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle);
793
+ isSelectedViaDragHandle = false;
794
794
  }
795
795
  return {
796
796
  decorations,
@@ -28,16 +28,6 @@ export const getInlineNodePos = (doc, start, nodeSize) => {
28
28
  inlineNodeEndPos
29
29
  };
30
30
  };
31
- export const isNodeWithCodeBlock = (tr, start, nodeSize) => {
32
- const $startPos = tr.doc.resolve(start);
33
- let hasCodeBlock = false;
34
- tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, n => {
35
- if (['codeBlock'].includes(n.type.name)) {
36
- hasCodeBlock = true;
37
- }
38
- });
39
- return hasCodeBlock;
40
- };
41
31
 
42
32
  /**
43
33
  * Gets the appropriate selection for the node at the given start position.
@@ -153,43 +153,6 @@ export const topPositionAdjustment = (nodeType, layout) => {
153
153
  return 0;
154
154
  }
155
155
  };
156
- export const dropTargetMarginMap = {
157
- [-24]: "var(--ds-space-negative-300, -24px)",
158
- [-20]: "var(--ds-space-negative-250, -20px)",
159
- [-16]: "var(--ds-space-negative-200, -16px)",
160
- [-12]: "var(--ds-space-negative-150, -12px)",
161
- [-8]: "var(--ds-space-negative-100, -8px)",
162
- [-6]: "var(--ds-space-negative-075, -6px)",
163
- [-4]: "var(--ds-space-negative-050, -4px)",
164
- [-2]: "var(--ds-space-negative-025, -2px)",
165
- 0: "var(--ds-space-0, 0px)",
166
- 2: "var(--ds-space-025, 2px)",
167
- 4: "var(--ds-space-050, 4px)",
168
- 6: "var(--ds-space-075, 6px)",
169
- 8: "var(--ds-space-100, 8px)",
170
- 12: "var(--ds-space-150, 12px)",
171
- 16: "var(--ds-space-200, 16px)",
172
- 20: "var(--ds-space-250, 20px)",
173
- 24: "var(--ds-space-300, 24px)"
174
- };
175
-
176
- /**
177
- * This document serves as a quick reference map for correlating various space matches
178
- * to the table provided above.
179
- * For instance, the number 1 will correspond to \{0: token('space.0', '0')\}.
180
- */
181
- export const spaceLookupMap = Object.fromEntries(
182
- // 49 = -24 -> 0 -> 24 totaling 49 entries.
183
- Array.from({
184
- length: 49
185
- }, (_, index) => {
186
- const currKeyValue = index - 24;
187
- const keyValues = Object.keys(dropTargetMarginMap).map(Number);
188
- const value = keyValues.reduce((acc, curr) => {
189
- return Math.abs(currKeyValue - curr) < Math.abs(currKeyValue - acc) ? curr : acc;
190
- }, 1000);
191
- return [currKeyValue, dropTargetMarginMap[value]];
192
- }));
193
156
  export const spacingBetweenNodesForPreview = {
194
157
  paragraph: {
195
158
  top: '0.75rem',
@@ -880,7 +880,7 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
880
880
  if (flags.toolbarFlagsEnabled) {
881
881
  isSelectedViaDragHandle = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined ? meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle : isSelectedViaDragHandle;
882
882
  } else {
883
- isSelectedViaDragHandle = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && flags.toolbarFlagsEnabled && (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle);
883
+ isSelectedViaDragHandle = false;
884
884
  }
885
885
  return {
886
886
  decorations: decorations,
@@ -28,16 +28,6 @@ export var getInlineNodePos = function getInlineNodePos(doc, start, nodeSize) {
28
28
  inlineNodeEndPos: inlineNodeEndPos
29
29
  };
30
30
  };
31
- export var isNodeWithCodeBlock = function isNodeWithCodeBlock(tr, start, nodeSize) {
32
- var $startPos = tr.doc.resolve(start);
33
- var hasCodeBlock = false;
34
- tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n) {
35
- if (['codeBlock'].includes(n.type.name)) {
36
- hasCodeBlock = true;
37
- }
38
- });
39
- return hasCodeBlock;
40
- };
41
31
 
42
32
  /**
43
33
  * Gets the appropriate selection for the node at the given start position.
@@ -1,6 +1,4 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
- var _dropTargetMarginMap;
4
2
  import { DRAG_HANDLE_WIDTH } from '@atlaskit/editor-common/styles/drag-handle';
5
3
  import { breakoutResizableNodes, getBreakoutResizableNodes } from '@atlaskit/editor-common/utils';
6
4
  import { akEditorUnitZIndex, akRichMediaResizeZIndex } from '@atlaskit/editor-shared-styles/constants';
@@ -158,25 +156,6 @@ export var topPositionAdjustment = function topPositionAdjustment(nodeType, layo
158
156
  return 0;
159
157
  }
160
158
  };
161
- export var dropTargetMarginMap = (_dropTargetMarginMap = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_dropTargetMarginMap, -24, "var(--ds-space-negative-300, -24px)"), -20, "var(--ds-space-negative-250, -20px)"), -16, "var(--ds-space-negative-200, -16px)"), -12, "var(--ds-space-negative-150, -12px)"), -8, "var(--ds-space-negative-100, -8px)"), -6, "var(--ds-space-negative-075, -6px)"), -4, "var(--ds-space-negative-050, -4px)"), -2, "var(--ds-space-negative-025, -2px)"), 0, "var(--ds-space-0, 0px)"), 2, "var(--ds-space-025, 2px)"), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_dropTargetMarginMap, 4, "var(--ds-space-050, 4px)"), 6, "var(--ds-space-075, 6px)"), 8, "var(--ds-space-100, 8px)"), 12, "var(--ds-space-150, 12px)"), 16, "var(--ds-space-200, 16px)"), 20, "var(--ds-space-250, 20px)"), 24, "var(--ds-space-300, 24px)"));
162
-
163
- /**
164
- * This document serves as a quick reference map for correlating various space matches
165
- * to the table provided above.
166
- * For instance, the number 1 will correspond to \{0: token('space.0', '0')\}.
167
- */
168
- export var spaceLookupMap = Object.fromEntries(
169
- // 49 = -24 -> 0 -> 24 totaling 49 entries.
170
- Array.from({
171
- length: 49
172
- }, function (_, index) {
173
- var currKeyValue = index - 24;
174
- var keyValues = Object.keys(dropTargetMarginMap).map(Number);
175
- var value = keyValues.reduce(function (acc, curr) {
176
- return Math.abs(currKeyValue - curr) < Math.abs(currKeyValue - acc) ? curr : acc;
177
- }, 1000);
178
- return [currKeyValue, dropTargetMarginMap[value]];
179
- }));
180
159
  export var spacingBetweenNodesForPreview = {
181
160
  paragraph: {
182
161
  top: '0.75rem',
@@ -5,11 +5,6 @@ export declare const TYPE_SURFACE_ANCHOR_DEC = "block-controls-surface-anchor";
5
5
  export declare const SURFACE_ANCHOR_ATTR = "data-block-controls-surface-anchor";
6
6
  export declare const SURFACE_NODE_TYPE_ATTR = "data-block-controls-surface-node-type";
7
7
  export declare const SURFACE_ANCHOR_VARIABLE = "--block-controls-surface-anchor-name";
8
- export type SurfaceAnchorDecorationSpec = {
9
- anchorName: string;
10
- nodeType: string;
11
- type: typeof TYPE_SURFACE_ANCHOR_DEC;
12
- };
13
8
  export type SurfaceAnchorDecorationResult = {
14
9
  anchors: ReadonlyMap<number, string>;
15
10
  decorations: DecorationSet;
@@ -5,7 +5,7 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types/next-edi
5
5
  import type { EditorState, ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
6
6
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
7
7
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
- import type { ActiveDropTargetNode, BlockControlsMeta, BlockControlsPlugin, MultiSelectDnD, NodeDecorationFactory, PluginState } from '../blockControlsPluginType';
8
+ import type { BlockControlsMeta, BlockControlsPlugin, NodeDecorationFactory, PluginState } from '../blockControlsPluginType';
9
9
  import { AnchorRectCache } from './utils/anchor-utils';
10
10
  export declare const key: PluginKey<PluginState>;
11
11
  export interface FlagType {
@@ -14,52 +14,6 @@ export interface FlagType {
14
14
  export declare const getDecorations: (state: EditorState) => DecorationSet | undefined;
15
15
  export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean, anchorRectCache?: AnchorRectCache, resizeObserverWidth?: ResizeObserver, pragmaticCleanup?: (() => void) | null, limitedModeTeardown?: {
16
16
  done: boolean;
17
- }) => PluginState | {
18
- activeDropTargetNode: ActiveDropTargetNode | undefined;
19
- activeNode: any;
20
- blockMenuOptions: {
21
- canMoveDown: any;
22
- canMoveUp: any;
23
- openedViaKeyboard: any;
24
- } | undefined;
25
- decorations: DecorationSet;
26
- editorHeight: any;
27
- editorWidthLeft: any;
28
- editorWidthRight: any;
29
- isDocSizeLimitEnabled: boolean | null;
30
- isDragging: any;
31
- isMenuOpen: boolean | undefined;
32
- isPMDragging: any;
33
- isResizerResizing: boolean;
34
- isSelectedViaDragHandle: any;
35
- lastDragCancelled: any;
36
- menuTriggerBy: any;
37
- menuTriggerByNode: any;
38
- multiSelectDnD: MultiSelectDnD | undefined;
39
- surfaceNodePositions: number[];
40
- };
41
- export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean) => SafePlugin<PluginState | {
42
- activeDropTargetNode: ActiveDropTargetNode | undefined;
43
- activeNode: any;
44
- blockMenuOptions: {
45
- canMoveDown: any;
46
- canMoveUp: any;
47
- openedViaKeyboard: any;
48
- } | undefined;
49
- decorations: DecorationSet;
50
- editorHeight: any;
51
- editorWidthLeft: any;
52
- editorWidthRight: any;
53
- isDocSizeLimitEnabled: boolean | null;
54
- isDragging: any;
55
- isMenuOpen: boolean | undefined;
56
- isPMDragging: any;
57
- isResizerResizing: boolean;
58
- isSelectedViaDragHandle: any;
59
- lastDragCancelled: any;
60
- menuTriggerBy: any;
61
- menuTriggerByNode: any;
62
- multiSelectDnD: MultiSelectDnD | undefined;
63
- surfaceNodePositions: number[];
64
- }>;
17
+ }) => PluginState;
18
+ export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean) => SafePlugin<PluginState>;
65
19
  export declare const getBlockControlsMeta: (tr: Transaction | ReadonlyTransaction) => BlockControlsMeta | undefined;
@@ -7,7 +7,6 @@ export declare const getInlineNodePos: (doc: PMNode, start: number, nodeSize: nu
7
7
  inlineNodeEndPos: number;
8
8
  inlineNodePos: number;
9
9
  };
10
- export declare const isNodeWithCodeBlock: (tr: Transaction, start: number, nodeSize: number) => boolean;
11
10
  /**
12
11
  * Gets the appropriate selection for the node at the given start position.
13
12
  *
@@ -34,17 +34,6 @@ export declare const dragHandleGap: (nodeType: string, parentNodeType?: string)
34
34
  export declare const rootElementGap: (nodeType: string) => number;
35
35
  export declare const getNestedNodeLeftPaddingMargin: (nodeType?: string) => '24px' | '8px' | '16px' | '20px' | '28px' | '40px';
36
36
  export declare const topPositionAdjustment: (nodeType: string, layout?: string) => number;
37
- export declare const dropTargetMarginMap: {
38
- [key: number]: string;
39
- };
40
- /**
41
- * This document serves as a quick reference map for correlating various space matches
42
- * to the table provided above.
43
- * For instance, the number 1 will correspond to \{0: token('space.0', '0')\}.
44
- */
45
- export declare const spaceLookupMap: {
46
- [k: string]: string;
47
- };
48
37
  export declare const spacingBetweenNodesForPreview: {
49
38
  [key: string]: {
50
39
  bottom: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "31.0.3",
3
+ "version": "31.0.5",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -40,7 +40,7 @@
40
40
  "@atlaskit/editor-plugin-metrics": "^31.0.0",
41
41
  "@atlaskit/editor-plugin-quick-insert": "^30.0.0",
42
42
  "@atlaskit/editor-plugin-selection": "^30.0.0",
43
- "@atlaskit/editor-plugin-show-diff": "^28.0.0",
43
+ "@atlaskit/editor-plugin-show-diff": "^29.0.0",
44
44
  "@atlaskit/editor-plugin-toolbar": "^27.0.0",
45
45
  "@atlaskit/editor-plugin-type-ahead": "^31.0.0",
46
46
  "@atlaskit/editor-plugin-ui-control-registry": "^24.0.0",
@@ -51,7 +51,6 @@
51
51
  "@atlaskit/editor-tables": "^3.2.0",
52
52
  "@atlaskit/editor-ui-control-model": "^3.0.0",
53
53
  "@atlaskit/icon": "^38.0.0",
54
- "@atlaskit/icon-lab": "^7.11.0",
55
54
  "@atlaskit/link": "^5.1.0",
56
55
  "@atlaskit/platform-feature-experiments": "^0.3.0",
57
56
  "@atlaskit/platform-feature-flags": "^2.2.0",
@@ -73,7 +72,7 @@
73
72
  "uuid": "^11.1.1"
74
73
  },
75
74
  "peerDependencies": {
76
- "@atlaskit/editor-common": "^134.1.0",
75
+ "@atlaskit/editor-common": "^134.2.0",
77
76
  "react": "^18.2.0 || ^19.2.0",
78
77
  "react-dom": "^18.2.0 || ^19.2.0",
79
78
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
@@ -1,215 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createVanillaButton = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _cssHelper = require("@atlaskit/editor-common/css-helper");
10
- var _blockControls = require("@atlaskit/editor-common/messages/block-controls");
11
- var _vanillaTooltip = require("@atlaskit/editor-common/vanilla-tooltip");
12
- var _model = require("@atlaskit/editor-prosemirror/model");
13
- var _state = require("@atlaskit/editor-prosemirror/state");
14
- var _utils = require("@atlaskit/editor-prosemirror/utils");
15
- var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
16
- var _documentChecks = require("../ui/utils/document-checks");
17
- var _editorCommands = require("../ui/utils/editor-commands");
18
- var _quickInsertCalculatePosition = require("./quick-insert-calculate-position");
19
- 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; }
20
- 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; }
21
- // Based on platform/packages/design-system/icon/svgs/utility/add.svg
22
- var plusButtonDOM = ['http://www.w3.org/2000/svg svg', {
23
- width: '12',
24
- height: '12',
25
- fill: 'none',
26
- viewBox: '0 0 12 12',
27
- style: 'pointer-events: none;'
28
- }, ['http://www.w3.org/2000/svg path', {
29
- fill: 'currentcolor',
30
- 'fill-rule': 'evenodd',
31
- d: 'M5.25 6.75V11h1.5V6.75H11v-1.5H6.75V1h-1.5v4.25H1v1.5z',
32
- 'clip-rule': 'evenodd',
33
- style: 'pointer-events: none;'
34
- }]];
35
- var vanillaQuickInsert = function vanillaQuickInsert(_ref) {
36
- var _api$featureFlags$sha, _api$featureFlags;
37
- var view = _ref.view,
38
- getPos = _ref.getPos,
39
- rootNodeType = _ref.rootNodeType,
40
- anchorRectCache = _ref.anchorRectCache,
41
- anchorName = _ref.anchorName,
42
- rootAnchorName = _ref.rootAnchorName,
43
- api = _ref.api;
44
- return ['div', {
45
- style: (0, _cssHelper.convertToInlineCss)(_objectSpread({
46
- position: 'absolute'
47
- }, (0, _quickInsertCalculatePosition.calculatePosition)({
48
- rootAnchorName: rootAnchorName,
49
- anchorName: anchorName,
50
- view: view,
51
- getPos: getPos,
52
- rootNodeType: rootNodeType,
53
- macroInteractionUpdates: (_api$featureFlags$sha = api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 || (_api$featureFlags = _api$featureFlags.sharedState.currentState()) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.macroInteractionUpdates) !== null && _api$featureFlags$sha !== void 0 ? _api$featureFlags$sha : false,
54
- anchorRectCache: anchorRectCache
55
- })))
56
- }, ['button', {
57
- class: 'blocks-quick-insert-button',
58
- 'data-testid': 'editor-quick-insert-button'
59
- }, plusButtonDOM]];
60
- };
61
-
62
- /**
63
- * Create a Node which contains the quick insert button
64
- */
65
- var createVanillaButton = exports.createVanillaButton = function createVanillaButton(props) {
66
- var _props$api$typeAhead, _props$api$blockContr, _props$api$blockContr2, _props$api$blockContr3, _props$api$blockContr4, _props$api$editorView, _props$api$typeAhead2, _props$api$blockContr5;
67
- var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, vanillaQuickInsert(props)),
68
- dom = _DOMSerializer$render.dom;
69
- if (dom instanceof HTMLElement) {
70
- var button = dom.querySelector('button[data-testid="editor-quick-insert-button"]');
71
- if (button instanceof HTMLButtonElement) {
72
- button.onclick = function () {
73
- return handleQuickInsert(props);
74
- };
75
-
76
- // Flag-on (platform-dst-top-layer), positioning is async via a React root;
77
- // safe here as VanillaTooltip stays hidden until positioned.
78
- var tooltip = new _vanillaTooltip.VanillaTooltip(button, props.formatMessage(_blockControls.messages.insert), 'quick-insert-button-tooltip', 'blocks-quick-insert-tooltip');
79
- props.cleanupCallbacks.push(function () {
80
- tooltip.destroy();
81
- });
82
- }
83
- }
84
-
85
- // Dynamically control the visibility of the node
86
- var isTypeAheadOpen = (_props$api$typeAhead = props.api.typeAhead) === null || _props$api$typeAhead === void 0 || (_props$api$typeAhead = _props$api$typeAhead.sharedState.currentState()) === null || _props$api$typeAhead === void 0 ? void 0 : _props$api$typeAhead.isOpen;
87
- var isEditing = (_props$api$blockContr = props.api.blockControls) === null || _props$api$blockContr === void 0 || (_props$api$blockContr = _props$api$blockContr.sharedState.currentState()) === null || _props$api$blockContr === void 0 ? void 0 : _props$api$blockContr.isEditing;
88
- var hoverSide = (_props$api$blockContr2 = props.api.blockControls) === null || _props$api$blockContr2 === void 0 || (_props$api$blockContr2 = _props$api$blockContr2.sharedState.currentState()) === null || _props$api$blockContr2 === void 0 ? void 0 : _props$api$blockContr2.hoverSide;
89
- var rightSideControlsEnabled = (_props$api$blockContr3 = (_props$api$blockContr4 = props.api.blockControls) === null || _props$api$blockContr4 === void 0 || (_props$api$blockContr4 = _props$api$blockContr4.sharedState.currentState()) === null || _props$api$blockContr4 === void 0 ? void 0 : _props$api$blockContr4.rightSideControlsEnabled) !== null && _props$api$blockContr3 !== void 0 ? _props$api$blockContr3 : false;
90
- var editorViewMode = (_props$api$editorView = props.api.editorViewMode) === null || _props$api$editorView === void 0 || (_props$api$editorView = _props$api$editorView.sharedState.currentState()) === null || _props$api$editorView === void 0 ? void 0 : _props$api$editorView.mode;
91
- var changeDOMVisibility = function changeDOMVisibility() {
92
- if (!(dom instanceof HTMLElement)) {
93
- return;
94
- }
95
- var isViewMode = editorViewMode === 'view';
96
- var shouldRestrictBySide = rightSideControlsEnabled && !isViewMode;
97
- // Only restrict by side when hoverSide is known. When undefined, show quick insert.
98
- var sideHidden = shouldRestrictBySide && hoverSide !== undefined ? hoverSide !== 'left' : false;
99
- if (isTypeAheadOpen || isEditing || sideHidden) {
100
- dom.classList.add('blocks-quick-insert-invisible-container');
101
- dom.classList.remove('blocks-quick-insert-visible-container');
102
- } else {
103
- dom.classList.add('blocks-quick-insert-visible-container');
104
- dom.classList.remove('blocks-quick-insert-invisible-container');
105
- }
106
- };
107
- changeDOMVisibility();
108
- props.cleanupCallbacks.push((_props$api$typeAhead2 = props.api.typeAhead) === null || _props$api$typeAhead2 === void 0 ? void 0 : _props$api$typeAhead2.sharedState.onChange(function (_ref2) {
109
- var nextSharedState = _ref2.nextSharedState;
110
- isTypeAheadOpen = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isOpen;
111
- changeDOMVisibility();
112
- }));
113
- props.cleanupCallbacks.push((_props$api$blockContr5 = props.api.blockControls) === null || _props$api$blockContr5 === void 0 ? void 0 : _props$api$blockContr5.sharedState.onChange(function (_ref3) {
114
- var _nextSharedState$righ;
115
- var nextSharedState = _ref3.nextSharedState;
116
- isEditing = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isEditing;
117
- hoverSide = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.hoverSide;
118
- rightSideControlsEnabled = (_nextSharedState$righ = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.rightSideControlsEnabled) !== null && _nextSharedState$righ !== void 0 ? _nextSharedState$righ : false;
119
- changeDOMVisibility();
120
- }));
121
- // Only subscribe to view mode when right-side controls are enabled (editorViewMode affects side restriction)
122
- if (rightSideControlsEnabled) {
123
- var _props$api$editorView2, _props$api$editorView3, _props$api$editorView4;
124
- var unsubscribeViewMode = (_props$api$editorView2 = props.api.editorViewMode) === null || _props$api$editorView2 === void 0 || (_props$api$editorView3 = (_props$api$editorView4 = _props$api$editorView2.sharedState).onChange) === null || _props$api$editorView3 === void 0 ? void 0 : _props$api$editorView3.call(_props$api$editorView4, function (_ref4) {
125
- var nextSharedState = _ref4.nextSharedState;
126
- editorViewMode = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mode;
127
- changeDOMVisibility();
128
- });
129
- if (unsubscribeViewMode) {
130
- props.cleanupCallbacks.push(unsubscribeViewMode);
131
- }
132
- }
133
- return dom;
134
- };
135
- var TEXT_PARENT_TYPES = ['paragraph', 'heading', 'blockquote', 'taskItem', 'decisionItem'];
136
- var handleQuickInsert = function handleQuickInsert(_ref5) {
137
- var _api$quickInsert;
138
- var api = _ref5.api,
139
- view = _ref5.view,
140
- getPos = _ref5.getPos;
141
- // if the selection is not within the node this decoration is rendered at
142
- // then insert a newline and trigger quick insert
143
- var start = getPos();
144
- if (start !== undefined) {
145
- // if the selection is not within the node this decoration is rendered at
146
- // or the node is non-editable, then insert a newline and trigger quick insert
147
- var isSelectionInsideNode = (0, _documentChecks.isSelectionInNode)(start, view);
148
- if (!isSelectionInsideNode || (0, _documentChecks.isNonEditableBlock)(start, view)) {
149
- api.core.actions.execute((0, _editorCommands.createNewLine)(start));
150
- }
151
- var codeBlock = view.state.schema.nodes.codeBlock;
152
- var selection = view.state.selection;
153
- var codeBlockParentNode = (0, _utils.findParentNodeOfType)(codeBlock)(selection);
154
- if (codeBlockParentNode) {
155
- // Slash command is not meant to be triggered inside code block, hence always insert slash in a new line following
156
- api.core.actions.execute((0, _editorCommands.createNewLine)(codeBlockParentNode.pos));
157
- } else if (isSelectionInsideNode) {
158
- // text or element with be deselected and the / added immediately after the paragraph
159
- // unless the selection is empty
160
- var currentSelection = view.state.selection;
161
- if ((0, _documentChecks.isInTextSelection)(view) && currentSelection.from !== currentSelection.to) {
162
- var currentParagraphNode = (0, _utils.findParentNode)(function (node) {
163
- return TEXT_PARENT_TYPES.includes(node.type.name);
164
- })(currentSelection);
165
- if (currentParagraphNode) {
166
- var newPos =
167
- //if the current selection is selected from right to left, then set the selection to the start of the paragraph
168
- currentSelection.anchor === currentSelection.to ? currentParagraphNode.pos : currentParagraphNode.pos + currentParagraphNode.node.nodeSize - 1;
169
- api.core.actions.execute(function (_ref6) {
170
- var tr = _ref6.tr;
171
- tr.setSelection(_state.TextSelection.create(view.state.selection.$from.doc, newPos));
172
- return tr;
173
- });
174
- }
175
- }
176
- if ((0, _documentChecks.isNestedNodeSelected)(view)) {
177
- // if the nested selected node is non-editable, then insert a newline below the selected node
178
- if ((0, _documentChecks.isNonEditableBlock)(view.state.selection.from, view)) {
179
- api.core.actions.execute((0, _editorCommands.createNewLine)(view.state.selection.from));
180
- } else {
181
- // otherwise need to force the selection to be at the start of the node, because
182
- // prosemirror is keeping it as NodeSelection for nested nodes. Do this to keep it
183
- // consistent NodeSelection for root level nodes.
184
- api.core.actions.execute(function (_ref7) {
185
- var tr = _ref7.tr;
186
- (0, _editorCommands.createNewLine)(view.state.selection.from)({
187
- tr: tr
188
- });
189
- tr.setSelection(_state.TextSelection.create(tr.doc, view.state.selection.from));
190
- return tr;
191
- });
192
- }
193
- }
194
- if (currentSelection instanceof _cellSelection.CellSelection) {
195
- // find the last inline position in the selection
196
- var lastInlinePosition = _state.TextSelection.near(view.state.selection.$to, -1);
197
- lastInlinePosition && api.core.actions.execute(function (_ref8) {
198
- var tr = _ref8.tr;
199
- if (!(lastInlinePosition instanceof _state.TextSelection)) {
200
- // this will create a new line after the node
201
- (0, _editorCommands.createNewLine)(lastInlinePosition.from)({
202
- tr: tr
203
- });
204
- // this will find the next valid text position after the node
205
- tr.setSelection(_state.TextSelection.create(tr.doc, lastInlinePosition.to));
206
- } else {
207
- tr.setSelection(lastInlinePosition);
208
- }
209
- return tr;
210
- });
211
- }
212
- }
213
- }
214
- (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 || _api$quickInsert.actions.openTypeAhead('blockControl', true);
215
- };
@@ -1,215 +0,0 @@
1
- import { convertToInlineCss } from '@atlaskit/editor-common/css-helper';
2
- import { messages } from '@atlaskit/editor-common/messages/block-controls';
3
- import { VanillaTooltip } from '@atlaskit/editor-common/vanilla-tooltip';
4
- import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
5
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
6
- import { findParentNode, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
7
- import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
8
- import { isInTextSelection, isNestedNodeSelected, isNonEditableBlock, isSelectionInNode } from '../ui/utils/document-checks';
9
- import { createNewLine } from '../ui/utils/editor-commands';
10
- import { calculatePosition } from './quick-insert-calculate-position';
11
- // Based on platform/packages/design-system/icon/svgs/utility/add.svg
12
- const plusButtonDOM = ['http://www.w3.org/2000/svg svg', {
13
- width: '12',
14
- height: '12',
15
- fill: 'none',
16
- viewBox: '0 0 12 12',
17
- style: 'pointer-events: none;'
18
- }, ['http://www.w3.org/2000/svg path', {
19
- fill: 'currentcolor',
20
- 'fill-rule': 'evenodd',
21
- d: 'M5.25 6.75V11h1.5V6.75H11v-1.5H6.75V1h-1.5v4.25H1v1.5z',
22
- 'clip-rule': 'evenodd',
23
- style: 'pointer-events: none;'
24
- }]];
25
- const vanillaQuickInsert = ({
26
- view,
27
- getPos,
28
- rootNodeType,
29
- anchorRectCache,
30
- anchorName,
31
- rootAnchorName,
32
- api
33
- }) => {
34
- var _api$featureFlags$sha, _api$featureFlags, _api$featureFlags$sha2;
35
- return ['div', {
36
- style: convertToInlineCss({
37
- position: 'absolute',
38
- ...calculatePosition({
39
- rootAnchorName,
40
- anchorName,
41
- view,
42
- getPos,
43
- rootNodeType: rootNodeType,
44
- macroInteractionUpdates: (_api$featureFlags$sha = api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : (_api$featureFlags$sha2 = _api$featureFlags.sharedState.currentState()) === null || _api$featureFlags$sha2 === void 0 ? void 0 : _api$featureFlags$sha2.macroInteractionUpdates) !== null && _api$featureFlags$sha !== void 0 ? _api$featureFlags$sha : false,
45
- anchorRectCache
46
- })
47
- })
48
- }, ['button', {
49
- class: 'blocks-quick-insert-button',
50
- 'data-testid': 'editor-quick-insert-button'
51
- }, plusButtonDOM]];
52
- };
53
-
54
- /**
55
- * Create a Node which contains the quick insert button
56
- */
57
- export const createVanillaButton = props => {
58
- var _props$api$typeAhead, _props$api$typeAhead$, _props$api$blockContr, _props$api$blockContr2, _props$api$blockContr3, _props$api$blockContr4, _props$api$blockContr5, _props$api$blockContr6, _props$api$blockContr7, _props$api$editorView, _props$api$editorView2, _props$api$typeAhead2, _props$api$blockContr8;
59
- const {
60
- dom
61
- } = DOMSerializer.renderSpec(document, vanillaQuickInsert(props));
62
- if (dom instanceof HTMLElement) {
63
- const button = dom.querySelector('button[data-testid="editor-quick-insert-button"]');
64
- if (button instanceof HTMLButtonElement) {
65
- button.onclick = () => handleQuickInsert(props);
66
-
67
- // Flag-on (platform-dst-top-layer), positioning is async via a React root;
68
- // safe here as VanillaTooltip stays hidden until positioned.
69
- const tooltip = new VanillaTooltip(button, props.formatMessage(messages.insert), 'quick-insert-button-tooltip', 'blocks-quick-insert-tooltip');
70
- props.cleanupCallbacks.push(() => {
71
- tooltip.destroy();
72
- });
73
- }
74
- }
75
-
76
- // Dynamically control the visibility of the node
77
- let isTypeAheadOpen = (_props$api$typeAhead = props.api.typeAhead) === null || _props$api$typeAhead === void 0 ? void 0 : (_props$api$typeAhead$ = _props$api$typeAhead.sharedState.currentState()) === null || _props$api$typeAhead$ === void 0 ? void 0 : _props$api$typeAhead$.isOpen;
78
- let isEditing = (_props$api$blockContr = props.api.blockControls) === null || _props$api$blockContr === void 0 ? void 0 : (_props$api$blockContr2 = _props$api$blockContr.sharedState.currentState()) === null || _props$api$blockContr2 === void 0 ? void 0 : _props$api$blockContr2.isEditing;
79
- let hoverSide = (_props$api$blockContr3 = props.api.blockControls) === null || _props$api$blockContr3 === void 0 ? void 0 : (_props$api$blockContr4 = _props$api$blockContr3.sharedState.currentState()) === null || _props$api$blockContr4 === void 0 ? void 0 : _props$api$blockContr4.hoverSide;
80
- let rightSideControlsEnabled = (_props$api$blockContr5 = (_props$api$blockContr6 = props.api.blockControls) === null || _props$api$blockContr6 === void 0 ? void 0 : (_props$api$blockContr7 = _props$api$blockContr6.sharedState.currentState()) === null || _props$api$blockContr7 === void 0 ? void 0 : _props$api$blockContr7.rightSideControlsEnabled) !== null && _props$api$blockContr5 !== void 0 ? _props$api$blockContr5 : false;
81
- let editorViewMode = (_props$api$editorView = props.api.editorViewMode) === null || _props$api$editorView === void 0 ? void 0 : (_props$api$editorView2 = _props$api$editorView.sharedState.currentState()) === null || _props$api$editorView2 === void 0 ? void 0 : _props$api$editorView2.mode;
82
- const changeDOMVisibility = () => {
83
- if (!(dom instanceof HTMLElement)) {
84
- return;
85
- }
86
- const isViewMode = editorViewMode === 'view';
87
- const shouldRestrictBySide = rightSideControlsEnabled && !isViewMode;
88
- // Only restrict by side when hoverSide is known. When undefined, show quick insert.
89
- const sideHidden = shouldRestrictBySide && hoverSide !== undefined ? hoverSide !== 'left' : false;
90
- if (isTypeAheadOpen || isEditing || sideHidden) {
91
- dom.classList.add('blocks-quick-insert-invisible-container');
92
- dom.classList.remove('blocks-quick-insert-visible-container');
93
- } else {
94
- dom.classList.add('blocks-quick-insert-visible-container');
95
- dom.classList.remove('blocks-quick-insert-invisible-container');
96
- }
97
- };
98
- changeDOMVisibility();
99
- props.cleanupCallbacks.push((_props$api$typeAhead2 = props.api.typeAhead) === null || _props$api$typeAhead2 === void 0 ? void 0 : _props$api$typeAhead2.sharedState.onChange(({
100
- nextSharedState
101
- }) => {
102
- isTypeAheadOpen = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isOpen;
103
- changeDOMVisibility();
104
- }));
105
- props.cleanupCallbacks.push((_props$api$blockContr8 = props.api.blockControls) === null || _props$api$blockContr8 === void 0 ? void 0 : _props$api$blockContr8.sharedState.onChange(({
106
- nextSharedState
107
- }) => {
108
- var _nextSharedState$righ;
109
- isEditing = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isEditing;
110
- hoverSide = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.hoverSide;
111
- rightSideControlsEnabled = (_nextSharedState$righ = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.rightSideControlsEnabled) !== null && _nextSharedState$righ !== void 0 ? _nextSharedState$righ : false;
112
- changeDOMVisibility();
113
- }));
114
- // Only subscribe to view mode when right-side controls are enabled (editorViewMode affects side restriction)
115
- if (rightSideControlsEnabled) {
116
- var _props$api$editorView3, _props$api$editorView4, _props$api$editorView5;
117
- const unsubscribeViewMode = (_props$api$editorView3 = props.api.editorViewMode) === null || _props$api$editorView3 === void 0 ? void 0 : (_props$api$editorView4 = (_props$api$editorView5 = _props$api$editorView3.sharedState).onChange) === null || _props$api$editorView4 === void 0 ? void 0 : _props$api$editorView4.call(_props$api$editorView5, ({
118
- nextSharedState
119
- }) => {
120
- editorViewMode = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mode;
121
- changeDOMVisibility();
122
- });
123
- if (unsubscribeViewMode) {
124
- props.cleanupCallbacks.push(unsubscribeViewMode);
125
- }
126
- }
127
- return dom;
128
- };
129
- const TEXT_PARENT_TYPES = ['paragraph', 'heading', 'blockquote', 'taskItem', 'decisionItem'];
130
- const handleQuickInsert = ({
131
- api,
132
- view,
133
- getPos
134
- }) => {
135
- var _api$quickInsert;
136
- // if the selection is not within the node this decoration is rendered at
137
- // then insert a newline and trigger quick insert
138
- const start = getPos();
139
- if (start !== undefined) {
140
- // if the selection is not within the node this decoration is rendered at
141
- // or the node is non-editable, then insert a newline and trigger quick insert
142
- const isSelectionInsideNode = isSelectionInNode(start, view);
143
- if (!isSelectionInsideNode || isNonEditableBlock(start, view)) {
144
- api.core.actions.execute(createNewLine(start));
145
- }
146
- const {
147
- codeBlock
148
- } = view.state.schema.nodes;
149
- const {
150
- selection
151
- } = view.state;
152
- const codeBlockParentNode = findParentNodeOfType(codeBlock)(selection);
153
- if (codeBlockParentNode) {
154
- // Slash command is not meant to be triggered inside code block, hence always insert slash in a new line following
155
- api.core.actions.execute(createNewLine(codeBlockParentNode.pos));
156
- } else if (isSelectionInsideNode) {
157
- // text or element with be deselected and the / added immediately after the paragraph
158
- // unless the selection is empty
159
- const currentSelection = view.state.selection;
160
- if (isInTextSelection(view) && currentSelection.from !== currentSelection.to) {
161
- const currentParagraphNode = findParentNode(node => TEXT_PARENT_TYPES.includes(node.type.name))(currentSelection);
162
- if (currentParagraphNode) {
163
- const newPos =
164
- //if the current selection is selected from right to left, then set the selection to the start of the paragraph
165
- currentSelection.anchor === currentSelection.to ? currentParagraphNode.pos : currentParagraphNode.pos + currentParagraphNode.node.nodeSize - 1;
166
- api.core.actions.execute(({
167
- tr
168
- }) => {
169
- tr.setSelection(TextSelection.create(view.state.selection.$from.doc, newPos));
170
- return tr;
171
- });
172
- }
173
- }
174
- if (isNestedNodeSelected(view)) {
175
- // if the nested selected node is non-editable, then insert a newline below the selected node
176
- if (isNonEditableBlock(view.state.selection.from, view)) {
177
- api.core.actions.execute(createNewLine(view.state.selection.from));
178
- } else {
179
- // otherwise need to force the selection to be at the start of the node, because
180
- // prosemirror is keeping it as NodeSelection for nested nodes. Do this to keep it
181
- // consistent NodeSelection for root level nodes.
182
- api.core.actions.execute(({
183
- tr
184
- }) => {
185
- createNewLine(view.state.selection.from)({
186
- tr
187
- });
188
- tr.setSelection(TextSelection.create(tr.doc, view.state.selection.from));
189
- return tr;
190
- });
191
- }
192
- }
193
- if (currentSelection instanceof CellSelection) {
194
- // find the last inline position in the selection
195
- const lastInlinePosition = TextSelection.near(view.state.selection.$to, -1);
196
- lastInlinePosition && api.core.actions.execute(({
197
- tr
198
- }) => {
199
- if (!(lastInlinePosition instanceof TextSelection)) {
200
- // this will create a new line after the node
201
- createNewLine(lastInlinePosition.from)({
202
- tr
203
- });
204
- // this will find the next valid text position after the node
205
- tr.setSelection(TextSelection.create(tr.doc, lastInlinePosition.to));
206
- } else {
207
- tr.setSelection(lastInlinePosition);
208
- }
209
- return tr;
210
- });
211
- }
212
- }
213
- }
214
- (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 ? void 0 : _api$quickInsert.actions.openTypeAhead('blockControl', true);
215
- };
@@ -1,208 +0,0 @@
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; }
4
- import { convertToInlineCss } from '@atlaskit/editor-common/css-helper';
5
- import { messages } from '@atlaskit/editor-common/messages/block-controls';
6
- import { VanillaTooltip } from '@atlaskit/editor-common/vanilla-tooltip';
7
- import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
8
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
9
- import { findParentNode, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
10
- import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
11
- import { isInTextSelection, isNestedNodeSelected, isNonEditableBlock, isSelectionInNode } from '../ui/utils/document-checks';
12
- import { createNewLine } from '../ui/utils/editor-commands';
13
- import { calculatePosition } from './quick-insert-calculate-position';
14
- // Based on platform/packages/design-system/icon/svgs/utility/add.svg
15
- var plusButtonDOM = ['http://www.w3.org/2000/svg svg', {
16
- width: '12',
17
- height: '12',
18
- fill: 'none',
19
- viewBox: '0 0 12 12',
20
- style: 'pointer-events: none;'
21
- }, ['http://www.w3.org/2000/svg path', {
22
- fill: 'currentcolor',
23
- 'fill-rule': 'evenodd',
24
- d: 'M5.25 6.75V11h1.5V6.75H11v-1.5H6.75V1h-1.5v4.25H1v1.5z',
25
- 'clip-rule': 'evenodd',
26
- style: 'pointer-events: none;'
27
- }]];
28
- var vanillaQuickInsert = function vanillaQuickInsert(_ref) {
29
- var _api$featureFlags$sha, _api$featureFlags;
30
- var view = _ref.view,
31
- getPos = _ref.getPos,
32
- rootNodeType = _ref.rootNodeType,
33
- anchorRectCache = _ref.anchorRectCache,
34
- anchorName = _ref.anchorName,
35
- rootAnchorName = _ref.rootAnchorName,
36
- api = _ref.api;
37
- return ['div', {
38
- style: convertToInlineCss(_objectSpread({
39
- position: 'absolute'
40
- }, calculatePosition({
41
- rootAnchorName: rootAnchorName,
42
- anchorName: anchorName,
43
- view: view,
44
- getPos: getPos,
45
- rootNodeType: rootNodeType,
46
- macroInteractionUpdates: (_api$featureFlags$sha = api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 || (_api$featureFlags = _api$featureFlags.sharedState.currentState()) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.macroInteractionUpdates) !== null && _api$featureFlags$sha !== void 0 ? _api$featureFlags$sha : false,
47
- anchorRectCache: anchorRectCache
48
- })))
49
- }, ['button', {
50
- class: 'blocks-quick-insert-button',
51
- 'data-testid': 'editor-quick-insert-button'
52
- }, plusButtonDOM]];
53
- };
54
-
55
- /**
56
- * Create a Node which contains the quick insert button
57
- */
58
- export var createVanillaButton = function createVanillaButton(props) {
59
- var _props$api$typeAhead, _props$api$blockContr, _props$api$blockContr2, _props$api$blockContr3, _props$api$blockContr4, _props$api$editorView, _props$api$typeAhead2, _props$api$blockContr5;
60
- var _DOMSerializer$render = DOMSerializer.renderSpec(document, vanillaQuickInsert(props)),
61
- dom = _DOMSerializer$render.dom;
62
- if (dom instanceof HTMLElement) {
63
- var button = dom.querySelector('button[data-testid="editor-quick-insert-button"]');
64
- if (button instanceof HTMLButtonElement) {
65
- button.onclick = function () {
66
- return handleQuickInsert(props);
67
- };
68
-
69
- // Flag-on (platform-dst-top-layer), positioning is async via a React root;
70
- // safe here as VanillaTooltip stays hidden until positioned.
71
- var tooltip = new VanillaTooltip(button, props.formatMessage(messages.insert), 'quick-insert-button-tooltip', 'blocks-quick-insert-tooltip');
72
- props.cleanupCallbacks.push(function () {
73
- tooltip.destroy();
74
- });
75
- }
76
- }
77
-
78
- // Dynamically control the visibility of the node
79
- var isTypeAheadOpen = (_props$api$typeAhead = props.api.typeAhead) === null || _props$api$typeAhead === void 0 || (_props$api$typeAhead = _props$api$typeAhead.sharedState.currentState()) === null || _props$api$typeAhead === void 0 ? void 0 : _props$api$typeAhead.isOpen;
80
- var isEditing = (_props$api$blockContr = props.api.blockControls) === null || _props$api$blockContr === void 0 || (_props$api$blockContr = _props$api$blockContr.sharedState.currentState()) === null || _props$api$blockContr === void 0 ? void 0 : _props$api$blockContr.isEditing;
81
- var hoverSide = (_props$api$blockContr2 = props.api.blockControls) === null || _props$api$blockContr2 === void 0 || (_props$api$blockContr2 = _props$api$blockContr2.sharedState.currentState()) === null || _props$api$blockContr2 === void 0 ? void 0 : _props$api$blockContr2.hoverSide;
82
- var rightSideControlsEnabled = (_props$api$blockContr3 = (_props$api$blockContr4 = props.api.blockControls) === null || _props$api$blockContr4 === void 0 || (_props$api$blockContr4 = _props$api$blockContr4.sharedState.currentState()) === null || _props$api$blockContr4 === void 0 ? void 0 : _props$api$blockContr4.rightSideControlsEnabled) !== null && _props$api$blockContr3 !== void 0 ? _props$api$blockContr3 : false;
83
- var editorViewMode = (_props$api$editorView = props.api.editorViewMode) === null || _props$api$editorView === void 0 || (_props$api$editorView = _props$api$editorView.sharedState.currentState()) === null || _props$api$editorView === void 0 ? void 0 : _props$api$editorView.mode;
84
- var changeDOMVisibility = function changeDOMVisibility() {
85
- if (!(dom instanceof HTMLElement)) {
86
- return;
87
- }
88
- var isViewMode = editorViewMode === 'view';
89
- var shouldRestrictBySide = rightSideControlsEnabled && !isViewMode;
90
- // Only restrict by side when hoverSide is known. When undefined, show quick insert.
91
- var sideHidden = shouldRestrictBySide && hoverSide !== undefined ? hoverSide !== 'left' : false;
92
- if (isTypeAheadOpen || isEditing || sideHidden) {
93
- dom.classList.add('blocks-quick-insert-invisible-container');
94
- dom.classList.remove('blocks-quick-insert-visible-container');
95
- } else {
96
- dom.classList.add('blocks-quick-insert-visible-container');
97
- dom.classList.remove('blocks-quick-insert-invisible-container');
98
- }
99
- };
100
- changeDOMVisibility();
101
- props.cleanupCallbacks.push((_props$api$typeAhead2 = props.api.typeAhead) === null || _props$api$typeAhead2 === void 0 ? void 0 : _props$api$typeAhead2.sharedState.onChange(function (_ref2) {
102
- var nextSharedState = _ref2.nextSharedState;
103
- isTypeAheadOpen = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isOpen;
104
- changeDOMVisibility();
105
- }));
106
- props.cleanupCallbacks.push((_props$api$blockContr5 = props.api.blockControls) === null || _props$api$blockContr5 === void 0 ? void 0 : _props$api$blockContr5.sharedState.onChange(function (_ref3) {
107
- var _nextSharedState$righ;
108
- var nextSharedState = _ref3.nextSharedState;
109
- isEditing = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isEditing;
110
- hoverSide = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.hoverSide;
111
- rightSideControlsEnabled = (_nextSharedState$righ = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.rightSideControlsEnabled) !== null && _nextSharedState$righ !== void 0 ? _nextSharedState$righ : false;
112
- changeDOMVisibility();
113
- }));
114
- // Only subscribe to view mode when right-side controls are enabled (editorViewMode affects side restriction)
115
- if (rightSideControlsEnabled) {
116
- var _props$api$editorView2, _props$api$editorView3, _props$api$editorView4;
117
- var unsubscribeViewMode = (_props$api$editorView2 = props.api.editorViewMode) === null || _props$api$editorView2 === void 0 || (_props$api$editorView3 = (_props$api$editorView4 = _props$api$editorView2.sharedState).onChange) === null || _props$api$editorView3 === void 0 ? void 0 : _props$api$editorView3.call(_props$api$editorView4, function (_ref4) {
118
- var nextSharedState = _ref4.nextSharedState;
119
- editorViewMode = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mode;
120
- changeDOMVisibility();
121
- });
122
- if (unsubscribeViewMode) {
123
- props.cleanupCallbacks.push(unsubscribeViewMode);
124
- }
125
- }
126
- return dom;
127
- };
128
- var TEXT_PARENT_TYPES = ['paragraph', 'heading', 'blockquote', 'taskItem', 'decisionItem'];
129
- var handleQuickInsert = function handleQuickInsert(_ref5) {
130
- var _api$quickInsert;
131
- var api = _ref5.api,
132
- view = _ref5.view,
133
- getPos = _ref5.getPos;
134
- // if the selection is not within the node this decoration is rendered at
135
- // then insert a newline and trigger quick insert
136
- var start = getPos();
137
- if (start !== undefined) {
138
- // if the selection is not within the node this decoration is rendered at
139
- // or the node is non-editable, then insert a newline and trigger quick insert
140
- var isSelectionInsideNode = isSelectionInNode(start, view);
141
- if (!isSelectionInsideNode || isNonEditableBlock(start, view)) {
142
- api.core.actions.execute(createNewLine(start));
143
- }
144
- var codeBlock = view.state.schema.nodes.codeBlock;
145
- var selection = view.state.selection;
146
- var codeBlockParentNode = findParentNodeOfType(codeBlock)(selection);
147
- if (codeBlockParentNode) {
148
- // Slash command is not meant to be triggered inside code block, hence always insert slash in a new line following
149
- api.core.actions.execute(createNewLine(codeBlockParentNode.pos));
150
- } else if (isSelectionInsideNode) {
151
- // text or element with be deselected and the / added immediately after the paragraph
152
- // unless the selection is empty
153
- var currentSelection = view.state.selection;
154
- if (isInTextSelection(view) && currentSelection.from !== currentSelection.to) {
155
- var currentParagraphNode = findParentNode(function (node) {
156
- return TEXT_PARENT_TYPES.includes(node.type.name);
157
- })(currentSelection);
158
- if (currentParagraphNode) {
159
- var newPos =
160
- //if the current selection is selected from right to left, then set the selection to the start of the paragraph
161
- currentSelection.anchor === currentSelection.to ? currentParagraphNode.pos : currentParagraphNode.pos + currentParagraphNode.node.nodeSize - 1;
162
- api.core.actions.execute(function (_ref6) {
163
- var tr = _ref6.tr;
164
- tr.setSelection(TextSelection.create(view.state.selection.$from.doc, newPos));
165
- return tr;
166
- });
167
- }
168
- }
169
- if (isNestedNodeSelected(view)) {
170
- // if the nested selected node is non-editable, then insert a newline below the selected node
171
- if (isNonEditableBlock(view.state.selection.from, view)) {
172
- api.core.actions.execute(createNewLine(view.state.selection.from));
173
- } else {
174
- // otherwise need to force the selection to be at the start of the node, because
175
- // prosemirror is keeping it as NodeSelection for nested nodes. Do this to keep it
176
- // consistent NodeSelection for root level nodes.
177
- api.core.actions.execute(function (_ref7) {
178
- var tr = _ref7.tr;
179
- createNewLine(view.state.selection.from)({
180
- tr: tr
181
- });
182
- tr.setSelection(TextSelection.create(tr.doc, view.state.selection.from));
183
- return tr;
184
- });
185
- }
186
- }
187
- if (currentSelection instanceof CellSelection) {
188
- // find the last inline position in the selection
189
- var lastInlinePosition = TextSelection.near(view.state.selection.$to, -1);
190
- lastInlinePosition && api.core.actions.execute(function (_ref8) {
191
- var tr = _ref8.tr;
192
- if (!(lastInlinePosition instanceof TextSelection)) {
193
- // this will create a new line after the node
194
- createNewLine(lastInlinePosition.from)({
195
- tr: tr
196
- });
197
- // this will find the next valid text position after the node
198
- tr.setSelection(TextSelection.create(tr.doc, lastInlinePosition.to));
199
- } else {
200
- tr.setSelection(lastInlinePosition);
201
- }
202
- return tr;
203
- });
204
- }
205
- }
206
- }
207
- (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 || _api$quickInsert.actions.openTypeAhead('blockControl', true);
208
- };
@@ -1,21 +0,0 @@
1
- import type { IntlShape } from 'react-intl';
2
- import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types/next-editor-plugin';
3
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
- import type { BlockControlsPlugin } from '../blockControlsPluginType';
5
- import type { AnchorRectCache } from './utils/anchor-utils';
6
- type VanillaQuickInsertProps = {
7
- anchorName: string;
8
- anchorRectCache?: AnchorRectCache;
9
- api: ExtractInjectionAPI<BlockControlsPlugin>;
10
- cleanupCallbacks: ((() => void) | undefined)[];
11
- formatMessage: IntlShape['formatMessage'];
12
- getPos: () => number | undefined;
13
- rootAnchorName: string;
14
- rootNodeType: string;
15
- view: EditorView;
16
- };
17
- /**
18
- * Create a Node which contains the quick insert button
19
- */
20
- export declare const createVanillaButton: (props: VanillaQuickInsertProps) => Node;
21
- export {};