@atlaskit/editor-plugin-block-controls 2.4.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/cjs/commands/move-node.js +7 -6
  3. package/dist/cjs/commands/show-drag-handle.js +2 -1
  4. package/dist/cjs/pm-plugins/decorations.js +93 -32
  5. package/dist/cjs/pm-plugins/keymap.js +5 -2
  6. package/dist/cjs/pm-plugins/main.js +349 -203
  7. package/dist/cjs/ui/drag-handle.js +4 -6
  8. package/dist/cjs/ui/drop-target-v2.js +32 -6
  9. package/dist/cjs/ui/drop-target.js +2 -0
  10. package/dist/cjs/ui/global-styles.js +1 -7
  11. package/dist/cjs/utils/transactions.js +63 -0
  12. package/dist/cjs/utils/validation.js +17 -0
  13. package/dist/es2019/commands/move-node.js +7 -6
  14. package/dist/es2019/commands/show-drag-handle.js +2 -1
  15. package/dist/es2019/pm-plugins/decorations.js +86 -31
  16. package/dist/es2019/pm-plugins/keymap.js +5 -2
  17. package/dist/es2019/pm-plugins/main.js +332 -179
  18. package/dist/es2019/ui/drag-handle.js +4 -8
  19. package/dist/es2019/ui/drop-target-v2.js +32 -6
  20. package/dist/es2019/ui/drop-target.js +2 -0
  21. package/dist/es2019/ui/global-styles.js +1 -7
  22. package/dist/es2019/utils/transactions.js +57 -0
  23. package/dist/es2019/utils/validation.js +17 -0
  24. package/dist/esm/commands/move-node.js +7 -6
  25. package/dist/esm/commands/show-drag-handle.js +2 -1
  26. package/dist/esm/pm-plugins/decorations.js +92 -31
  27. package/dist/esm/pm-plugins/keymap.js +5 -2
  28. package/dist/esm/pm-plugins/main.js +350 -204
  29. package/dist/esm/ui/drag-handle.js +4 -6
  30. package/dist/esm/ui/drop-target-v2.js +32 -6
  31. package/dist/esm/ui/drop-target.js +2 -0
  32. package/dist/esm/ui/global-styles.js +1 -7
  33. package/dist/esm/utils/transactions.js +57 -0
  34. package/dist/esm/utils/validation.js +17 -0
  35. package/dist/types/pm-plugins/decorations.d.ts +24 -4
  36. package/dist/types/pm-plugins/main.d.ts +32 -0
  37. package/dist/types/ui/drag-handle.d.ts +5 -14
  38. package/dist/types/ui/drop-target-v2.d.ts +1 -1
  39. package/dist/types/ui/drop-target.d.ts +2 -0
  40. package/dist/types/utils/transactions.d.ts +29 -0
  41. package/dist/types-ts4.5/pm-plugins/decorations.d.ts +24 -4
  42. package/dist/types-ts4.5/pm-plugins/main.d.ts +32 -0
  43. package/dist/types-ts4.5/ui/drag-handle.d.ts +5 -14
  44. package/dist/types-ts4.5/ui/drop-target-v2.d.ts +1 -1
  45. package/dist/types-ts4.5/ui/drop-target.d.ts +2 -0
  46. package/dist/types-ts4.5/utils/transactions.d.ts +29 -0
  47. package/package.json +5 -8
@@ -8,7 +8,6 @@ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react
8
8
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
9
9
  import { css, jsx } from '@emotion/react';
10
10
  import { bind } from 'bind-event-listener';
11
- import { injectIntl } from 'react-intl-next';
12
11
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
13
12
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
14
13
  import { dragToMoveDown, dragToMoveLeft, dragToMoveRight, dragToMoveUp, getAriaKeyshortcuts, TooltipContentWithMultipleShortcuts } from '@atlaskit/editor-common/keymaps';
@@ -60,14 +59,14 @@ var selectedStyles = css({
60
59
  backgroundColor: "var(--ds-background-selected, #E9F2FF)",
61
60
  color: "var(--ds-icon-selected, #0C66E4)"
62
61
  });
63
- var DragHandleInternal = function DragHandleInternal(_ref) {
62
+ export var DragHandle = function DragHandle(_ref) {
64
63
  var _api$core2, _api$analytics2, _api$core4, _api$core6;
65
64
  var view = _ref.view,
66
65
  api = _ref.api,
66
+ formatMessage = _ref.formatMessage,
67
67
  getPos = _ref.getPos,
68
68
  anchorName = _ref.anchorName,
69
69
  nodeType = _ref.nodeType,
70
- formatMessage = _ref.intl.formatMessage,
71
70
  handleOptions = _ref.handleOptions,
72
71
  _ref$isTopLevelNode = _ref.isTopLevelNode,
73
72
  isTopLevelNode = _ref$isTopLevelNode === void 0 ? true : _ref$isTopLevelNode;
@@ -368,7 +367,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
368
367
  keymap: dragToMoveDown
369
368
  }];
370
369
  var isParentNodeOfTypeLayout;
371
- if (!isTopLevelNode && handleOptions !== null && handleOptions !== void 0 && handleOptions.isFocused && fg('platform_editor_element_dnd_nested_a11y')) {
370
+ if (!isTopLevelNode && handleOptions !== null && handleOptions !== void 0 && handleOptions.isFocused && editorExperiment('nested-dnd', true) && fg('platform_editor_element_dnd_nested_a11y')) {
372
371
  isParentNodeOfTypeLayout = nodeType === 'layoutSection' || view.state.doc.resolve(getNestedNodePosition(view.state)).node().type.name === 'layoutColumn';
373
372
  if (isParentNodeOfTypeLayout) {
374
373
  helpDescriptors = [].concat(_toConsumableArray(helpDescriptors), [{
@@ -415,5 +414,4 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
415
414
  });
416
415
  }
417
416
  }, renderButton()) : renderButton();
418
- };
419
- export var DragHandle = injectIntl(DragHandleInternal);
417
+ };
@@ -54,15 +54,28 @@ var nestedDropZoneStyle = css({
54
54
  width: 'unset'
55
55
  });
56
56
  var enableDropZone = ['paragraph', 'mediaSingle', 'heading', 'codeBlock', 'decisionList', 'bulletList', 'orderedList', 'taskList', 'extension', 'blockCard'];
57
+ var fullHeightStyle = css({
58
+ top: '4px',
59
+ bottom: '4px',
60
+ height: 'unset',
61
+ zIndex: 10
62
+ });
63
+
64
+ // This z index is used in container like layout
65
+ var fullHeightStyleAdjustZIndexStyle = css({
66
+ zIndex: 0
67
+ });
57
68
  var HoverZone = function HoverZone(_ref) {
58
69
  var onDragEnter = _ref.onDragEnter,
59
70
  onDragLeave = _ref.onDragLeave,
60
71
  onDrop = _ref.onDrop,
61
72
  node = _ref.node,
73
+ parent = _ref.parent,
62
74
  editorWidth = _ref.editorWidth,
63
75
  anchorHeightsCache = _ref.anchorHeightsCache,
64
76
  position = _ref.position,
65
- isNestedDropTarget = _ref.isNestedDropTarget;
77
+ isNestedDropTarget = _ref.isNestedDropTarget,
78
+ dropTargetStyle = _ref.dropTargetStyle;
66
79
  var ref = useRef(null);
67
80
  useEffect(function () {
68
81
  if (ref.current) {
@@ -89,14 +102,23 @@ var HoverZone = function HoverZone(_ref) {
89
102
  maxWidth: "".concat(editorWidth || 0, "px")
90
103
  });
91
104
  }, [anchorHeightsCache, editorWidth, node, position]);
105
+ var isFullHeight = useMemo(function () {
106
+ return dropTargetStyle === 'fullHeight';
107
+ }, [dropTargetStyle]);
108
+ var isFullHeightInLayout = useMemo(function () {
109
+ return isFullHeight && (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'layoutColumn';
110
+ }, [isFullHeight, parent === null || parent === void 0 ? void 0 : parent.type.name]);
92
111
  return jsx("div", {
93
112
  ref: ref
94
113
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
95
114
  ,
96
- className: "drop-target-hover-zone-".concat(position)
115
+ className: "drop-target-hover-zone-".concat(position),
116
+ "data-testid": "drop-target-zone-".concat(position)
97
117
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
98
118
  ,
99
- css: [dropZoneStyles, isNestedDropTarget && nestedDropZoneStyle, hoverZoneUpperStyle]
119
+ css: [dropZoneStyles, isNestedDropTarget && nestedDropZoneStyle,
120
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
121
+ hoverZoneUpperStyle, isFullHeight && fullHeightStyle, isFullHeightInLayout && fullHeightStyleAdjustZIndexStyle]
100
122
  });
101
123
  };
102
124
  export var DropTargetV2 = function DropTargetV2(_ref2) {
@@ -107,7 +129,8 @@ export var DropTargetV2 = function DropTargetV2(_ref2) {
107
129
  nextNode = _ref2.nextNode,
108
130
  parentNode = _ref2.parentNode,
109
131
  formatMessage = _ref2.formatMessage,
110
- anchorHeightsCache = _ref2.anchorHeightsCache;
132
+ anchorHeightsCache = _ref2.anchorHeightsCache,
133
+ dropTargetStyle = _ref2.dropTargetStyle;
111
134
  var _useState = useState(false),
112
135
  _useState2 = _slicedToArray(_useState, 2),
113
136
  isDraggedOver = _useState2[0],
@@ -129,10 +152,11 @@ export var DropTargetV2 = function DropTargetV2(_ref2) {
129
152
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.moveNode(start, pos, undefined, formatMessage));
130
153
  }
131
154
  };
155
+ var isFullHeight = dropTargetStyle === 'fullHeight';
132
156
  var dynamicStyle = (_dynamicStyle = {
133
157
  width: isNestedDropTarget ? 'unset' : '100%'
134
158
  }, _defineProperty(_dynamicStyle, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, isNestedDropTarget ? '100%' : "".concat((widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH, "px")), _defineProperty(_dynamicStyle, EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN, isNestedDropTarget ? getNestedNodeLeftPaddingMargin(parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) : '0'), _defineProperty(_dynamicStyle, EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX, editorExperiment('nested-dnd', true) ? layers.navigation() : layers.card()), _dynamicStyle);
135
- return jsx(Fragment, null, jsx(HoverZone, {
159
+ return jsx(Fragment, null, !isFullHeight && jsx(HoverZone, {
136
160
  onDragEnter: function onDragEnter() {
137
161
  return setIsDraggedOver(true);
138
162
  },
@@ -168,9 +192,11 @@ export var DropTargetV2 = function DropTargetV2(_ref2) {
168
192
  },
169
193
  onDrop: onDrop,
170
194
  node: nextNode,
195
+ parent: parentNode,
171
196
  editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
172
197
  anchorHeightsCache: anchorHeightsCache,
173
198
  position: "lower",
174
- isNestedDropTarget: isNestedDropTarget
199
+ isNestedDropTarget: isNestedDropTarget,
200
+ dropTargetStyle: dropTargetStyle
175
201
  }));
176
202
  };
@@ -112,6 +112,8 @@ export var DropTarget = function DropTarget(_ref3) {
112
112
  return;
113
113
  }
114
114
 
115
+ // This should be moved to platform/packages/editor/editor-plugin-block-controls/src/utils/validation.ts
116
+ // Since we are moved to drop-target-v2
115
117
  // Place experiments here instead of just inside move-node.ts as it stops the drag marker from appearing.
116
118
  if (editorExperiment('nest-media-and-codeblock-in-quote', false)) {
117
119
  var _api$blockControls;
@@ -120,18 +120,12 @@ var withFormatInLayoutStyleFixSelectors = ["".concat(dragHandleContainer, ":firs
120
120
  var withInlineNodeStyleWithChromeFix = css(_defineProperty({}, withInlineNodeStyleWithChromeFixSelectors, {
121
121
  transform: 'scale(0)'
122
122
  }));
123
- var globalStyles = editorExperiment('nested-dnd', true) ? css({
123
+ var globalStyles = css({
124
124
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
125
125
  '.ProseMirror-widget:first-child + *:not([data-panel-type], .code-block, [data-node-type="nestedExpand"])': {
126
126
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
127
127
  marginTop: '0 !important'
128
128
  }
129
- }) : css({
130
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
131
- '.ProseMirror-widget:first-child + *': {
132
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
133
- marginTop: '0 !important'
134
- }
135
129
  });
136
130
  var withDividerInPanelStyleFix = css(_defineProperty({}, "".concat(dividerBodiedInCustomPanelWithNoIconSelector), {
137
131
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles
@@ -0,0 +1,57 @@
1
+ import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
2
+ /**
3
+ * Checks if step adds inline char
4
+ * @param s
5
+ * @returns True if step adds inline char
6
+ */
7
+ export var isStepText = function isStepText(s) {
8
+ var content = s.slice.content.firstChild;
9
+ return s.from === s.to && s.slice.content.childCount === 1 && !!content && !!content.text;
10
+ };
11
+
12
+ /**
13
+ * Checks if step is an inline delete/backspace (replace range from -> from + 1 with empty content)
14
+ * @param s
15
+ * @returns True if delete/backspace
16
+ */
17
+ export var isStepDelete = function isStepDelete(s) {
18
+ var content = s.slice.content;
19
+ return s.to === s.from + 1 && content.size === 0;
20
+ };
21
+
22
+ /**
23
+ * Get metadata from the transaction.
24
+ * @param tr
25
+ * @returns Min 'from', max 'to' (from + slice size). If no steps, returns pos range of entire doc.
26
+ * Number of ReplaceStep and ReplaceAroundStep steps 'numReplaceSteps'.
27
+ * 'isAllText' if all steps are represent adding inline text or a backspace/delete or no-op
28
+ */
29
+ export var getTrMetadata = function getTrMetadata(tr) {
30
+ var from;
31
+ var to;
32
+ var numReplaceSteps = 0;
33
+ var isAllText = true;
34
+ tr.steps.forEach(function (s) {
35
+ if (s instanceof ReplaceStep || s instanceof ReplaceAroundStep) {
36
+ if (s instanceof ReplaceAroundStep || s instanceof ReplaceStep && !isStepText(s) && !isStepDelete(s)) {
37
+ isAllText = false;
38
+ }
39
+ var $to = s.from + s.slice.size;
40
+ from = from === undefined || from > s.from ? s.from : from;
41
+ to = to === undefined || to < $to ? $to : to;
42
+ numReplaceSteps++;
43
+ }
44
+ });
45
+ if (from === undefined) {
46
+ from = 0;
47
+ }
48
+ if (to === undefined || to > tr.doc.nodeSize - 2) {
49
+ to = tr.doc.nodeSize - 2;
50
+ }
51
+ return {
52
+ from: from,
53
+ to: to,
54
+ numReplaceSteps: numReplaceSteps,
55
+ isAllText: isAllText
56
+ };
57
+ };
@@ -1,5 +1,6 @@
1
1
  import memoizeOne from 'memoize-one';
2
2
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
3
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
3
4
  export var isInsideTable = function isInsideTable(nodeType) {
4
5
  var _nodeType$schema$node = nodeType.schema.nodes,
5
6
  tableCell = _nodeType$schema$node.tableCell,
@@ -62,6 +63,22 @@ export var memoizedTransformExpandToNestedExpand = memoizeOne(function (node) {
62
63
  });
63
64
  export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode) {
64
65
  var srcNodeType = srcNode.type;
66
+ var parentNodeType = destParent === null || destParent === void 0 ? void 0 : destParent.type.name;
67
+ var activeNodeType = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type.name;
68
+
69
+ // Place experiments here instead of just inside move-node.ts as it stops the drag marker from appearing.
70
+ if (editorExperiment('nest-media-and-codeblock-in-quote', false)) {
71
+ if (parentNodeType === 'blockquote' && (activeNodeType === 'mediaGroup' || activeNodeType === 'mediaSingle' || activeNodeType === 'codeBlock')) {
72
+ return false;
73
+ }
74
+ }
75
+
76
+ // Place experiments here instead of just inside move-node.ts as it stops the drag marker from appearing.
77
+ if (editorExperiment('nested-expand-in-expand', false)) {
78
+ if (parentNodeType === 'expand' && (activeNodeType === 'expand' || activeNodeType === 'nestedExpand')) {
79
+ return false;
80
+ }
81
+ }
65
82
  if (isInsideTable(destParent.type) && isExpand(srcNodeType)) {
66
83
  if (memoizedTransformExpandToNestedExpand(srcNode)) {
67
84
  srcNodeType = srcNodeType.schema.nodes.nestedExpand;
@@ -2,13 +2,33 @@ import { type IntlShape } from 'react-intl-next';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
+ import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
6
  import type { ActiveNode, BlockControlsPlugin, HandleOptions } from '../types';
7
7
  import { type DropTargetProps } from '../ui/drop-target';
8
8
  import { type AnchorHeightsCache } from '../utils/anchor-utils';
9
+ export declare const TYPE_DROP_TARGET_DEC = "drop-target-decoration";
10
+ export declare const TYPE_HANDLE_DEC = "drag-handle";
11
+ export declare const TYPE_NODE_DEC = "node-decoration";
9
12
  export declare const getNodeAnchor: (node: PMNode) => string;
13
+ /**
14
+ * Find drop target decorations in the pos range between from and to
15
+ * @param decorations
16
+ * @param from
17
+ * @param to
18
+ * @returns
19
+ */
20
+ export declare const findDropTargetDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
21
+ export declare const findHandleDec: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
22
+ /**
23
+ * Find node decorations in the pos range between from and to (non-inclusive)
24
+ * @param decorations
25
+ * @param from
26
+ * @param to
27
+ * @returns
28
+ */
29
+ export declare const findNodeDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
10
30
  export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorHeightsCache?: AnchorHeightsCache) => Decoration;
11
- export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorHeightsCache?: AnchorHeightsCache) => Decoration[];
31
+ export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorHeightsCache?: AnchorHeightsCache, from?: number, to?: number) => Decoration[];
12
32
  export declare const emptyParagraphNodeDecorations: () => Decoration;
13
- export declare const nodeDecorations: (newState: EditorState) => Decoration[];
14
- export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, getIntl: () => IntlShape, pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
33
+ export declare const nodeDecorations: (newState: EditorState, from?: number, to?: number) => Decoration[];
34
+ export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
@@ -1,7 +1,39 @@
1
1
  import { type IntlShape } from 'react-intl-next';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import type { EditorState, ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
4
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
7
  import type { BlockControlsPlugin, PluginState } from '../types';
8
+ import { AnchorHeightsCache } from '../utils/anchor-utils';
6
9
  export declare const key: PluginKey<PluginState>;
10
+ export interface FlagType {
11
+ isNestedEnabled: boolean;
12
+ isOptimisedApply: boolean;
13
+ isTitleEnterImprovementEnabled: boolean;
14
+ }
15
+ export declare const newApply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, anchorHeightsCache?: AnchorHeightsCache) => {
16
+ decorations: DecorationSet;
17
+ activeNode: any;
18
+ isDragging: any;
19
+ isMenuOpen: boolean | undefined;
20
+ editorHeight: any;
21
+ editorWidthLeft: any;
22
+ editorWidthRight: any;
23
+ isResizerResizing: boolean;
24
+ isDocSizeLimitEnabled: boolean | null;
25
+ isPMDragging: any;
26
+ };
27
+ export declare const oldApply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, oldState: EditorState, newState: EditorState, flags: FlagType, anchorHeightsCache?: AnchorHeightsCache) => {
28
+ decorations: DecorationSet;
29
+ activeNode: any;
30
+ isDragging: any;
31
+ isMenuOpen: boolean | undefined;
32
+ editorHeight: any;
33
+ editorWidthLeft: any;
34
+ editorWidthRight: any;
35
+ isResizerResizing: boolean;
36
+ isDocSizeLimitEnabled: boolean | null;
37
+ isPMDragging: any;
38
+ };
7
39
  export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape) => SafePlugin<PluginState>;
@@ -1,24 +1,15 @@
1
- /// <reference types="react" />
2
- import { type WrappedComponentProps } from 'react-intl-next';
1
+ import { jsx } from '@emotion/react';
2
+ import { type IntlShape } from 'react-intl-next';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { BlockControlsPlugin, HandleOptions } from '../types';
6
- export declare const DragHandle: import("react").FC<import("react-intl-next").WithIntlProps<{
6
+ export declare const DragHandle: ({ view, api, formatMessage, getPos, anchorName, nodeType, handleOptions, isTopLevelNode, }: {
7
7
  view: EditorView;
8
8
  api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
9
+ formatMessage: IntlShape['formatMessage'];
9
10
  getPos: () => number | undefined;
10
11
  anchorName: string;
11
12
  nodeType: string;
12
13
  handleOptions?: HandleOptions;
13
14
  isTopLevelNode?: Boolean | undefined;
14
- } & WrappedComponentProps>> & {
15
- WrappedComponent: import("react").ComponentType<{
16
- view: EditorView;
17
- api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
18
- getPos: () => number | undefined;
19
- anchorName: string;
20
- nodeType: string;
21
- handleOptions?: HandleOptions;
22
- isTopLevelNode?: Boolean | undefined;
23
- } & WrappedComponentProps>;
24
- };
15
+ }) => jsx.JSX.Element;
@@ -3,6 +3,6 @@ import { type AnchorHeightsCache } from '../utils/anchor-utils';
3
3
  import { type DropTargetProps } from './drop-target';
4
4
  export declare const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = "--editor-block-controls-drop-indicator-offset";
5
5
  export declare const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = "--editor-block-controls-drop-indicator-gap";
6
- export declare const DropTargetV2: ({ api, getPos, prevNode, nextNode, parentNode, formatMessage, anchorHeightsCache, }: DropTargetProps & {
6
+ export declare const DropTargetV2: ({ api, getPos, prevNode, nextNode, parentNode, formatMessage, anchorHeightsCache, dropTargetStyle, }: DropTargetProps & {
7
7
  anchorHeightsCache?: AnchorHeightsCache | undefined;
8
8
  }) => jsx.JSX.Element;
@@ -3,12 +3,14 @@ import { type IntlShape } from 'react-intl-next';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
4
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
5
  import type { BlockControlsPlugin } from '../types';
6
+ export type DropTargetStyle = 'default' | 'fullHeight';
6
7
  export type DropTargetProps = {
7
8
  api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
8
9
  getPos: () => number | undefined;
9
10
  prevNode?: PMNode;
10
11
  nextNode?: PMNode;
11
12
  parentNode?: PMNode;
13
+ dropTargetStyle?: DropTargetStyle;
12
14
  formatMessage?: IntlShape['formatMessage'];
13
15
  };
14
16
  export declare const DropTarget: ({ api, getPos, prevNode, nextNode, parentNode, formatMessage, }: DropTargetProps) => jsx.JSX.Element;
@@ -0,0 +1,29 @@
1
+ import type { ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
3
+ interface TransactionMetadata {
4
+ from: number;
5
+ to: number;
6
+ numReplaceSteps: number;
7
+ isAllText: boolean;
8
+ }
9
+ /**
10
+ * Checks if step adds inline char
11
+ * @param s
12
+ * @returns True if step adds inline char
13
+ */
14
+ export declare const isStepText: (s: ReplaceStep) => boolean;
15
+ /**
16
+ * Checks if step is an inline delete/backspace (replace range from -> from + 1 with empty content)
17
+ * @param s
18
+ * @returns True if delete/backspace
19
+ */
20
+ export declare const isStepDelete: (s: ReplaceStep) => boolean;
21
+ /**
22
+ * Get metadata from the transaction.
23
+ * @param tr
24
+ * @returns Min 'from', max 'to' (from + slice size). If no steps, returns pos range of entire doc.
25
+ * Number of ReplaceStep and ReplaceAroundStep steps 'numReplaceSteps'.
26
+ * 'isAllText' if all steps are represent adding inline text or a backspace/delete or no-op
27
+ */
28
+ export declare const getTrMetadata: (tr: Transaction | ReadonlyTransaction) => TransactionMetadata;
29
+ export {};
@@ -2,13 +2,33 @@ import { type IntlShape } from 'react-intl-next';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
5
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
+ import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
6
  import type { ActiveNode, BlockControlsPlugin, HandleOptions } from '../types';
7
7
  import { type DropTargetProps } from '../ui/drop-target';
8
8
  import { type AnchorHeightsCache } from '../utils/anchor-utils';
9
+ export declare const TYPE_DROP_TARGET_DEC = "drop-target-decoration";
10
+ export declare const TYPE_HANDLE_DEC = "drag-handle";
11
+ export declare const TYPE_NODE_DEC = "node-decoration";
9
12
  export declare const getNodeAnchor: (node: PMNode) => string;
13
+ /**
14
+ * Find drop target decorations in the pos range between from and to
15
+ * @param decorations
16
+ * @param from
17
+ * @param to
18
+ * @returns
19
+ */
20
+ export declare const findDropTargetDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
21
+ export declare const findHandleDec: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
22
+ /**
23
+ * Find node decorations in the pos range between from and to (non-inclusive)
24
+ * @param decorations
25
+ * @param from
26
+ * @param to
27
+ * @returns
28
+ */
29
+ export declare const findNodeDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
10
30
  export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorHeightsCache?: AnchorHeightsCache) => Decoration;
11
- export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorHeightsCache?: AnchorHeightsCache) => Decoration[];
31
+ export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorHeightsCache?: AnchorHeightsCache, from?: number, to?: number) => Decoration[];
12
32
  export declare const emptyParagraphNodeDecorations: () => Decoration;
13
- export declare const nodeDecorations: (newState: EditorState) => Decoration[];
14
- export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, getIntl: () => IntlShape, pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
33
+ export declare const nodeDecorations: (newState: EditorState, from?: number, to?: number) => Decoration[];
34
+ export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
@@ -1,7 +1,39 @@
1
1
  import { type IntlShape } from 'react-intl-next';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import type { EditorState, ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
4
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
7
  import type { BlockControlsPlugin, PluginState } from '../types';
8
+ import { AnchorHeightsCache } from '../utils/anchor-utils';
6
9
  export declare const key: PluginKey<PluginState>;
10
+ export interface FlagType {
11
+ isNestedEnabled: boolean;
12
+ isOptimisedApply: boolean;
13
+ isTitleEnterImprovementEnabled: boolean;
14
+ }
15
+ export declare const newApply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, anchorHeightsCache?: AnchorHeightsCache) => {
16
+ decorations: DecorationSet;
17
+ activeNode: any;
18
+ isDragging: any;
19
+ isMenuOpen: boolean | undefined;
20
+ editorHeight: any;
21
+ editorWidthLeft: any;
22
+ editorWidthRight: any;
23
+ isResizerResizing: boolean;
24
+ isDocSizeLimitEnabled: boolean | null;
25
+ isPMDragging: any;
26
+ };
27
+ export declare const oldApply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, oldState: EditorState, newState: EditorState, flags: FlagType, anchorHeightsCache?: AnchorHeightsCache) => {
28
+ decorations: DecorationSet;
29
+ activeNode: any;
30
+ isDragging: any;
31
+ isMenuOpen: boolean | undefined;
32
+ editorHeight: any;
33
+ editorWidthLeft: any;
34
+ editorWidthRight: any;
35
+ isResizerResizing: boolean;
36
+ isDocSizeLimitEnabled: boolean | null;
37
+ isPMDragging: any;
38
+ };
7
39
  export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape) => SafePlugin<PluginState>;
@@ -1,24 +1,15 @@
1
- /// <reference types="react" />
2
- import { type WrappedComponentProps } from 'react-intl-next';
1
+ import { jsx } from '@emotion/react';
2
+ import { type IntlShape } from 'react-intl-next';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { BlockControlsPlugin, HandleOptions } from '../types';
6
- export declare const DragHandle: import("react").FC<import("react-intl-next").WithIntlProps<{
6
+ export declare const DragHandle: ({ view, api, formatMessage, getPos, anchorName, nodeType, handleOptions, isTopLevelNode, }: {
7
7
  view: EditorView;
8
8
  api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
9
+ formatMessage: IntlShape['formatMessage'];
9
10
  getPos: () => number | undefined;
10
11
  anchorName: string;
11
12
  nodeType: string;
12
13
  handleOptions?: HandleOptions;
13
14
  isTopLevelNode?: Boolean | undefined;
14
- } & WrappedComponentProps>> & {
15
- WrappedComponent: import("react").ComponentType<{
16
- view: EditorView;
17
- api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
18
- getPos: () => number | undefined;
19
- anchorName: string;
20
- nodeType: string;
21
- handleOptions?: HandleOptions;
22
- isTopLevelNode?: Boolean | undefined;
23
- } & WrappedComponentProps>;
24
- };
15
+ }) => jsx.JSX.Element;
@@ -3,6 +3,6 @@ import { type AnchorHeightsCache } from '../utils/anchor-utils';
3
3
  import { type DropTargetProps } from './drop-target';
4
4
  export declare const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = "--editor-block-controls-drop-indicator-offset";
5
5
  export declare const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = "--editor-block-controls-drop-indicator-gap";
6
- export declare const DropTargetV2: ({ api, getPos, prevNode, nextNode, parentNode, formatMessage, anchorHeightsCache, }: DropTargetProps & {
6
+ export declare const DropTargetV2: ({ api, getPos, prevNode, nextNode, parentNode, formatMessage, anchorHeightsCache, dropTargetStyle, }: DropTargetProps & {
7
7
  anchorHeightsCache?: AnchorHeightsCache | undefined;
8
8
  }) => jsx.JSX.Element;
@@ -3,12 +3,14 @@ import { type IntlShape } from 'react-intl-next';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
4
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
5
  import type { BlockControlsPlugin } from '../types';
6
+ export type DropTargetStyle = 'default' | 'fullHeight';
6
7
  export type DropTargetProps = {
7
8
  api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
8
9
  getPos: () => number | undefined;
9
10
  prevNode?: PMNode;
10
11
  nextNode?: PMNode;
11
12
  parentNode?: PMNode;
13
+ dropTargetStyle?: DropTargetStyle;
12
14
  formatMessage?: IntlShape['formatMessage'];
13
15
  };
14
16
  export declare const DropTarget: ({ api, getPos, prevNode, nextNode, parentNode, formatMessage, }: DropTargetProps) => jsx.JSX.Element;
@@ -0,0 +1,29 @@
1
+ import type { ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
3
+ interface TransactionMetadata {
4
+ from: number;
5
+ to: number;
6
+ numReplaceSteps: number;
7
+ isAllText: boolean;
8
+ }
9
+ /**
10
+ * Checks if step adds inline char
11
+ * @param s
12
+ * @returns True if step adds inline char
13
+ */
14
+ export declare const isStepText: (s: ReplaceStep) => boolean;
15
+ /**
16
+ * Checks if step is an inline delete/backspace (replace range from -> from + 1 with empty content)
17
+ * @param s
18
+ * @returns True if delete/backspace
19
+ */
20
+ export declare const isStepDelete: (s: ReplaceStep) => boolean;
21
+ /**
22
+ * Get metadata from the transaction.
23
+ * @param tr
24
+ * @returns Min 'from', max 'to' (from + slice size). If no steps, returns pos range of entire doc.
25
+ * Number of ReplaceStep and ReplaceAroundStep steps 'numReplaceSteps'.
26
+ * 'isAllText' if all steps are represent adding inline text or a backspace/delete or no-op
27
+ */
28
+ export declare const getTrMetadata: (tr: Transaction | ReadonlyTransaction) => TransactionMetadata;
29
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "2.4.1",
3
+ "version": "2.6.0",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,9 +31,9 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@atlaskit/adf-schema": "^40.9.4",
34
- "@atlaskit/editor-common": "^93.3.0",
34
+ "@atlaskit/editor-common": "^93.4.0",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
36
- "@atlaskit/editor-plugin-analytics": "^1.9.0",
36
+ "@atlaskit/editor-plugin-analytics": "^1.10.0",
37
37
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
38
38
  "@atlaskit/editor-plugin-feature-flags": "^1.2.0",
39
39
  "@atlaskit/editor-plugin-quick-insert": "^1.4.0",
@@ -47,8 +47,8 @@
47
47
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.4.0",
48
48
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.1.0",
49
49
  "@atlaskit/primitives": "^12.2.0",
50
- "@atlaskit/theme": "^13.0.0",
51
- "@atlaskit/tmp-editor-statsig": "^2.3.0",
50
+ "@atlaskit/theme": "^13.1.0",
51
+ "@atlaskit/tmp-editor-statsig": "^2.4.0",
52
52
  "@atlaskit/tokens": "^2.0.0",
53
53
  "@atlaskit/tooltip": "^18.8.0",
54
54
  "@babel/runtime": "^7.0.0",
@@ -112,9 +112,6 @@
112
112
  "platform_editor_element_drag_and_drop_ed_23873": {
113
113
  "type": "boolean"
114
114
  },
115
- "platform_editor_elements_drag_and_drop_ed_23394": {
116
- "type": "boolean"
117
- },
118
115
  "platform_editor_element_controls_chrome_input_fix": {
119
116
  "type": "boolean"
120
117
  },