@atlaskit/editor-plugin-block-controls 2.2.1 → 2.3.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 (36) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/commands/move-node.js +2 -1
  3. package/dist/cjs/pm-plugins/decorations.js +127 -43
  4. package/dist/cjs/pm-plugins/main.js +8 -1
  5. package/dist/cjs/ui/consts.js +3 -3
  6. package/dist/cjs/ui/drop-target-v2.js +184 -0
  7. package/dist/cjs/utils/anchor-utils.js +70 -0
  8. package/dist/cjs/utils/getSelection.js +43 -16
  9. package/dist/cjs/utils/index.js +12 -0
  10. package/dist/es2019/commands/move-node.js +2 -1
  11. package/dist/es2019/pm-plugins/decorations.js +122 -33
  12. package/dist/es2019/pm-plugins/main.js +8 -1
  13. package/dist/es2019/ui/consts.js +3 -3
  14. package/dist/es2019/ui/drop-target-v2.js +171 -0
  15. package/dist/es2019/utils/anchor-utils.js +51 -0
  16. package/dist/es2019/utils/getSelection.js +44 -15
  17. package/dist/es2019/utils/index.js +1 -1
  18. package/dist/esm/commands/move-node.js +2 -1
  19. package/dist/esm/pm-plugins/decorations.js +126 -42
  20. package/dist/esm/pm-plugins/main.js +8 -1
  21. package/dist/esm/ui/consts.js +3 -3
  22. package/dist/esm/ui/drop-target-v2.js +176 -0
  23. package/dist/esm/utils/anchor-utils.js +63 -0
  24. package/dist/esm/utils/getSelection.js +42 -15
  25. package/dist/esm/utils/index.js +1 -1
  26. package/dist/types/pm-plugins/decorations.d.ts +6 -1
  27. package/dist/types/ui/drop-target-v2.d.ts +8 -0
  28. package/dist/types/utils/anchor-utils.d.ts +12 -0
  29. package/dist/types/utils/getSelection.d.ts +5 -0
  30. package/dist/types/utils/index.d.ts +1 -1
  31. package/dist/types-ts4.5/pm-plugins/decorations.d.ts +6 -1
  32. package/dist/types-ts4.5/ui/drop-target-v2.d.ts +8 -0
  33. package/dist/types-ts4.5/utils/anchor-utils.d.ts +12 -0
  34. package/dist/types-ts4.5/utils/getSelection.d.ts +5 -0
  35. package/dist/types-ts4.5/utils/index.d.ts +1 -1
  36. package/package.json +6 -3
@@ -1,5 +1,28 @@
1
+ import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
1
2
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
3
  import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
4
+ export var getInlineNodePos = function getInlineNodePos(tr, start, nodeSize) {
5
+ var $startPos = tr.doc.resolve(start);
6
+ // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
7
+ // Find the first inline node in the node
8
+ var inlineNodePos = start;
9
+ var foundInlineNode = false;
10
+ var inlineNodeEndPos = 0;
11
+ tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n, pos) {
12
+ if (n.isInline) {
13
+ inlineNodeEndPos = pos + n.nodeSize;
14
+ }
15
+ if (n.isInline && !foundInlineNode) {
16
+ inlineNodePos = pos;
17
+ foundInlineNode = true;
18
+ }
19
+ return true;
20
+ });
21
+ return {
22
+ inlineNodePos: inlineNodePos,
23
+ inlineNodeEndPos: inlineNodeEndPos
24
+ };
25
+ };
3
26
  export var getSelection = function getSelection(tr, start) {
4
27
  var node = tr.doc.nodeAt(start);
5
28
  var isNodeSelection = node && NodeSelection.isSelectable(node);
@@ -19,21 +42,9 @@ export var getSelection = function getSelection(tr, start) {
19
42
  nodeName === 'mediaGroup') {
20
43
  return new NodeSelection($startPos);
21
44
  } else {
22
- // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
23
- // Find the first inline node in the node
24
- var inlineNodePos = start;
25
- var foundInlineNode = false;
26
- var inlineNodeEndPos = 0;
27
- tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n, pos) {
28
- if (n.isInline) {
29
- inlineNodeEndPos = pos + n.nodeSize;
30
- }
31
- if (n.isInline && !foundInlineNode) {
32
- inlineNodePos = pos;
33
- foundInlineNode = true;
34
- }
35
- return true;
36
- });
45
+ var _getInlineNodePos = getInlineNodePos(tr, start, nodeSize),
46
+ inlineNodePos = _getInlineNodePos.inlineNodePos,
47
+ inlineNodeEndPos = _getInlineNodePos.inlineNodeEndPos;
37
48
  return new TextSelection(tr.doc.resolve(inlineNodeEndPos), tr.doc.resolve(inlineNodePos));
38
49
  }
39
50
  };
@@ -45,4 +56,20 @@ export var selectNode = function selectNode(tr, start, nodeType) {
45
56
  tr.setSelection(getSelection(tr, start));
46
57
  }
47
58
  return tr;
59
+ };
60
+ export var setCursorPositionAtMovedNode = function setCursorPositionAtMovedNode(tr, start) {
61
+ var node = tr.doc.nodeAt(start);
62
+ var isNodeSelection = node && NodeSelection.isSelectable(node);
63
+ var nodeSize = node ? node.nodeSize : 1;
64
+ var selection;
65
+ // decisionList node is not selectable, but we want to select the whole node not just text
66
+ if (isNodeSelection || (node === null || node === void 0 ? void 0 : node.type.name) === 'decisionList') {
67
+ selection = new GapCursorSelection(tr.doc.resolve(start + node.nodeSize), Side.RIGHT);
68
+ } else {
69
+ var _getInlineNodePos2 = getInlineNodePos(tr, start, nodeSize),
70
+ inlineNodeEndPos = _getInlineNodePos2.inlineNodeEndPos;
71
+ selection = new TextSelection(tr.doc.resolve(inlineNodeEndPos));
72
+ }
73
+ tr.setSelection(selection);
74
+ return tr;
48
75
  };
@@ -1,2 +1,2 @@
1
- export { getSelection, selectNode } from './getSelection';
1
+ export { getInlineNodePos, getSelection, selectNode, setCursorPositionAtMovedNode } from './getSelection';
2
2
  export { getNestedNodePosition } from './getNestedNodePosition';
@@ -1,9 +1,14 @@
1
1
  import { type IntlShape } from 'react-intl-next';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
5
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
6
  import type { ActiveNode, BlockControlsPlugin, HandleOptions } from '../types';
6
- export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode) => Decoration[];
7
+ import { type DropTargetProps } from '../ui/drop-target';
8
+ import { type AnchorHeightsCache } from '../utils/anchor-utils';
9
+ export declare const getNodeAnchor: (node: PMNode) => string;
10
+ 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[];
7
12
  export declare const emptyParagraphNodeDecorations: () => Decoration;
8
13
  export declare const nodeDecorations: (newState: EditorState) => Decoration[];
9
14
  export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, getIntl: () => IntlShape, pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
@@ -0,0 +1,8 @@
1
+ import { jsx } from '@emotion/react';
2
+ import { type AnchorHeightsCache } from '../utils/anchor-utils';
3
+ import { type DropTargetProps } from './drop-target';
4
+ export declare const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = "--editor-block-controls-drop-indicator-offset";
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 & {
7
+ anchorHeightsCache?: AnchorHeightsCache | undefined;
8
+ }) => jsx.JSX.Element;
@@ -0,0 +1,12 @@
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ export declare const isAnchorSupported: import("memoize-one").MemoizedFn<() => boolean>;
3
+ export declare class AnchorHeightsCache {
4
+ private anchorHeightsMap;
5
+ private isAnchorSupported;
6
+ private isDirty;
7
+ private view;
8
+ clear(): void;
9
+ private getHeights;
10
+ setEditorView(view: EditorView): void;
11
+ getHeight(anchorName: string): number | null;
12
+ }
@@ -1,3 +1,8 @@
1
1
  import { NodeSelection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize: number) => {
3
+ inlineNodePos: number;
4
+ inlineNodeEndPos: number;
5
+ };
2
6
  export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
3
7
  export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
8
+ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
@@ -1,2 +1,2 @@
1
- export { getSelection, selectNode } from './getSelection';
1
+ export { getInlineNodePos, getSelection, selectNode, setCursorPositionAtMovedNode, } from './getSelection';
2
2
  export { getNestedNodePosition } from './getNestedNodePosition';
@@ -1,9 +1,14 @@
1
1
  import { type IntlShape } from 'react-intl-next';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
4
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
5
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
6
  import type { ActiveNode, BlockControlsPlugin, HandleOptions } from '../types';
6
- export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode) => Decoration[];
7
+ import { type DropTargetProps } from '../ui/drop-target';
8
+ import { type AnchorHeightsCache } from '../utils/anchor-utils';
9
+ export declare const getNodeAnchor: (node: PMNode) => string;
10
+ 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[];
7
12
  export declare const emptyParagraphNodeDecorations: () => Decoration;
8
13
  export declare const nodeDecorations: (newState: EditorState) => Decoration[];
9
14
  export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, getIntl: () => IntlShape, pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
@@ -0,0 +1,8 @@
1
+ import { jsx } from '@emotion/react';
2
+ import { type AnchorHeightsCache } from '../utils/anchor-utils';
3
+ import { type DropTargetProps } from './drop-target';
4
+ export declare const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = "--editor-block-controls-drop-indicator-offset";
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 & {
7
+ anchorHeightsCache?: AnchorHeightsCache | undefined;
8
+ }) => jsx.JSX.Element;
@@ -0,0 +1,12 @@
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ export declare const isAnchorSupported: import("memoize-one").MemoizedFn<() => boolean>;
3
+ export declare class AnchorHeightsCache {
4
+ private anchorHeightsMap;
5
+ private isAnchorSupported;
6
+ private isDirty;
7
+ private view;
8
+ clear(): void;
9
+ private getHeights;
10
+ setEditorView(view: EditorView): void;
11
+ getHeight(anchorName: string): number | null;
12
+ }
@@ -1,3 +1,8 @@
1
1
  import { NodeSelection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize: number) => {
3
+ inlineNodePos: number;
4
+ inlineNodeEndPos: number;
5
+ };
2
6
  export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
3
7
  export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
8
+ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
@@ -1,2 +1,2 @@
1
- export { getSelection, selectNode } from './getSelection';
1
+ export { getInlineNodePos, getSelection, selectNode, setCursorPositionAtMovedNode, } from './getSelection';
2
2
  export { getNestedNodePosition } from './getNestedNodePosition';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@atlaskit/adf-schema": "^40.9.0",
34
- "@atlaskit/editor-common": "^93.1.0",
34
+ "@atlaskit/editor-common": "^93.2.0",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.8.0",
37
37
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
@@ -43,7 +43,7 @@
43
43
  "@atlaskit/editor-tables": "^2.8.0",
44
44
  "@atlaskit/icon": "^22.22.0",
45
45
  "@atlaskit/platform-feature-flags": "^0.3.0",
46
- "@atlaskit/pragmatic-drag-and-drop": "^1.3.0",
46
+ "@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
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",
@@ -150,6 +150,9 @@
150
150
  },
151
151
  "platform_editor_element_dnd_nested_a11y": {
152
152
  "type": "boolean"
153
+ },
154
+ "platform_editor_drag_and_drop_target_v2": {
155
+ "type": "boolean"
153
156
  }
154
157
  }
155
158
  }