@atlaskit/editor-plugin-block-controls 2.27.1 → 2.27.4

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 (35) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/cjs/blockControlsPlugin.js +35 -6
  3. package/dist/cjs/pm-plugins/main.js +2 -1
  4. package/dist/cjs/ui/block-menu-items.js +103 -0
  5. package/dist/cjs/ui/block-menu.js +77 -0
  6. package/dist/cjs/ui/consts.js +101 -2
  7. package/dist/cjs/ui/drag-handle.js +146 -40
  8. package/dist/cjs/ui/drag-preview.js +83 -34
  9. package/dist/es2019/blockControlsPlugin.js +34 -3
  10. package/dist/es2019/pm-plugins/main.js +2 -1
  11. package/dist/es2019/ui/block-menu-items.js +92 -0
  12. package/dist/es2019/ui/block-menu.js +75 -0
  13. package/dist/es2019/ui/consts.js +100 -1
  14. package/dist/es2019/ui/drag-handle.js +150 -38
  15. package/dist/es2019/ui/drag-preview.js +83 -34
  16. package/dist/esm/blockControlsPlugin.js +35 -6
  17. package/dist/esm/pm-plugins/main.js +2 -1
  18. package/dist/esm/ui/block-menu-items.js +92 -0
  19. package/dist/esm/ui/block-menu.js +70 -0
  20. package/dist/esm/ui/consts.js +100 -1
  21. package/dist/esm/ui/drag-handle.js +147 -41
  22. package/dist/esm/ui/drag-preview.js +82 -34
  23. package/dist/types/blockControlsPluginType.d.ts +3 -0
  24. package/dist/types/pm-plugins/utils/getSelection.d.ts +2 -2
  25. package/dist/types/ui/block-menu-items.d.ts +17 -0
  26. package/dist/types/ui/block-menu.d.ts +16 -0
  27. package/dist/types/ui/consts.d.ts +7 -0
  28. package/dist/types/ui/drag-preview.d.ts +9 -1
  29. package/dist/types-ts4.5/blockControlsPluginType.d.ts +3 -0
  30. package/dist/types-ts4.5/pm-plugins/utils/getSelection.d.ts +2 -2
  31. package/dist/types-ts4.5/ui/block-menu-items.d.ts +17 -0
  32. package/dist/types-ts4.5/ui/block-menu.d.ts +16 -0
  33. package/dist/types-ts4.5/ui/consts.d.ts +7 -0
  34. package/dist/types-ts4.5/ui/drag-preview.d.ts +9 -1
  35. package/package.json +5 -5
@@ -1,3 +1,4 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
1
2
  import { browser } from '@atlaskit/editor-common/browser';
2
3
  import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { B200, N20, N30 } from '@atlaskit/theme/colors';
@@ -15,14 +16,8 @@ var previewStyleOld = {
15
16
  borderWidth: "var(--ds-border-width-outline, 2px)",
16
17
  backgroundColor: "var(--ds-blanket-selected, #388BFF14)"
17
18
  };
18
- export var dragPreview = function dragPreview(container, dom, nodeType) {
19
+ var getPreviewContainerDimensionsForSingle = function getPreviewContainerDimensionsForSingle(dom, nodeType) {
19
20
  var nodeContainer = dom;
20
- container.style.pointerEvents = 'none';
21
- var parent = document.createElement('div');
22
- // ProseMirror class is required to make sure the cloned dom is styled correctly
23
- parent.classList.add('ProseMirror', 'block-ctrl-drag-preview');
24
- var embedCard = dom.querySelector('.embedCardView-content-wrap');
25
- var shouldBeGenericPreview = nodeType === 'embedCard' || nodeType === 'extension' || !!embedCard;
26
21
  if (fg('platform_editor_elements_drag_and_drop_ed_23189')) {
27
22
  var iframeContainer = dom.querySelector('iframe');
28
23
  if (nodeType === 'embedCard') {
@@ -30,41 +25,94 @@ export var dragPreview = function dragPreview(container, dom, nodeType) {
30
25
  } else if (nodeType === 'extension' && iframeContainer) {
31
26
  nodeContainer = iframeContainer;
32
27
  }
33
- shouldBeGenericPreview = nodeType === 'embedCard' || !!embedCard || nodeType === 'extension' && !!iframeContainer;
34
28
  }
35
29
  var nodeContainerRect = nodeContainer.getBoundingClientRect();
36
- container.style.width = "".concat(nodeContainerRect.width, "px");
37
- container.style.height = "".concat(nodeContainerRect.height, "px");
30
+ return {
31
+ width: nodeContainerRect.width,
32
+ height: nodeContainerRect.height
33
+ };
34
+ };
35
+ var getPreviewContainerDimensions = function getPreviewContainerDimensions(dragPreviewContent) {
36
+ var maxWidth = 0;
37
+ var heightSum = 0;
38
+ for (var index = 0; index < dragPreviewContent.length; index++) {
39
+ var element = dragPreviewContent[index];
40
+ var _getPreviewContainerD = getPreviewContainerDimensionsForSingle(element.dom, element.nodeType),
41
+ width = _getPreviewContainerD.width,
42
+ height = _getPreviewContainerD.height;
43
+ if (width > maxWidth) {
44
+ maxWidth = width;
45
+ }
46
+ heightSum += height;
47
+ }
48
+ return {
49
+ width: maxWidth,
50
+ height: heightSum
51
+ };
52
+ };
53
+ var createGenericPreview = function createGenericPreview() {
54
+ var generalPreview = document.createElement('div');
55
+ // ProseMirror class is required to make sure the cloned dom is styled correctly
56
+ generalPreview.classList.add('ProseMirror', 'block-ctrl-drag-preview');
38
57
  var previewStyle = fg('platform_editor_elements_drag_and_drop_ed_23189') ? previewStyleNew : previewStyleOld;
58
+ generalPreview.style.border = "".concat(previewStyle.borderWidth, " ").concat(previewStyle.borderStyle, " ").concat(previewStyle.borderColor);
59
+ generalPreview.style.borderRadius = previewStyle.borderRadius;
60
+ generalPreview.style.backgroundColor = previewStyle.backgroundColor;
61
+ generalPreview.style.height = '100%';
62
+ generalPreview.setAttribute('data-testid', 'block-ctrl-generic-drag-preview');
63
+ return generalPreview;
64
+ };
65
+ var createContentPreviewElement = function createContentPreviewElement(dom, nodeType, nodeSpacing) {
66
+ var contentPreviewOneElement = document.createElement('div');
67
+ contentPreviewOneElement.classList.add('ProseMirror', 'block-ctrl-drag-preview');
68
+ var resizer = dom.querySelector('.resizer-item');
69
+ var clonedDom = resizer && ['mediaSingle', 'table'].includes(nodeType) ?
70
+ // Ignored via go/ees005
71
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
72
+ resizer.cloneNode(true) :
73
+ // Ignored via go/ees005
74
+ // eslint-disable-next-line @atlaskit/editor/no-as-casting
75
+ dom.cloneNode(true);
76
+ clonedDom.style.marginLeft = '0';
77
+ clonedDom.style.marginTop = nodeSpacing ? "".concat(nodeSpacing.top) : '0';
78
+ clonedDom.style.marginRight = '0';
79
+ clonedDom.style.marginBottom = nodeSpacing ? "".concat(nodeSpacing.bottom) : '0';
80
+ clonedDom.style.boxShadow = 'none';
81
+ clonedDom.style.opacity = browser.windows ? '1' : fg('platform_editor_elements_drag_and_drop_ed_23189') ? '0.31' : '0.4';
82
+ contentPreviewOneElement.appendChild(clonedDom);
83
+ return contentPreviewOneElement;
84
+ };
85
+ var isGenericPreview = function isGenericPreview(dom, nodeType) {
86
+ var embedCard = dom.querySelector('.embedCardView-content-wrap');
87
+ return fg('platform_editor_elements_drag_and_drop_ed_23189') ? nodeType === 'embedCard' || !!embedCard || nodeType === 'extension' && !!dom.querySelector('iframe') : nodeType === 'embedCard' || !!embedCard || nodeType === 'extension';
88
+ };
89
+ var createPreviewForElement = function createPreviewForElement(dom, nodeType, nodeSpacing) {
90
+ var shouldBeGenericPreview = isGenericPreview(dom, nodeType);
39
91
  if (shouldBeGenericPreview) {
40
- parent.style.border = "".concat(previewStyle.borderWidth, " ").concat(previewStyle.borderStyle, " ").concat(previewStyle.borderColor);
41
- parent.style.borderRadius = previewStyle.borderRadius;
42
- parent.style.backgroundColor = previewStyle.backgroundColor;
43
- parent.style.height = '100%';
44
- parent.setAttribute('data-testid', 'block-ctrl-generic-drag-preview');
92
+ return createGenericPreview();
45
93
  } else {
46
- var resizer = dom.querySelector('.resizer-item');
47
- var clonedDom = resizer && ['mediaSingle', 'table'].includes(nodeType) ?
48
- // Ignored via go/ees005
49
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
50
- resizer.cloneNode(true) :
51
- // Ignored via go/ees005
52
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
53
- dom.cloneNode(true);
54
-
55
- // Remove any margin from the cloned element to ensure is doesn't position incorrectly
56
- clonedDom.style.marginLeft = '0';
57
- clonedDom.style.marginTop = '0';
58
- clonedDom.style.marginRight = '0';
59
- clonedDom.style.marginBottom = '0';
60
- clonedDom.style.boxShadow = 'none';
61
- clonedDom.style.opacity = browser.windows ? '1' : fg('platform_editor_elements_drag_and_drop_ed_23189') ? '0.31' : '0.4';
62
- parent.appendChild(clonedDom);
94
+ return createContentPreviewElement(dom, nodeType, nodeSpacing);
95
+ }
96
+ };
97
+ export var dragPreview = function dragPreview(container, dragPreviewContent) {
98
+ container.style.pointerEvents = 'none';
99
+ if (!Array.isArray(dragPreviewContent) && _typeof(dragPreviewContent) === 'object') {
100
+ dragPreviewContent = [dragPreviewContent];
101
+ }
102
+ var _getPreviewContainerD2 = getPreviewContainerDimensions(dragPreviewContent),
103
+ maxWidth = _getPreviewContainerD2.width,
104
+ maxHeight = _getPreviewContainerD2.height;
105
+ container.style.width = "".concat(maxWidth, "px");
106
+ container.style.height = "".concat(maxHeight, "px");
107
+ var previewWrapperFragment = document.createDocumentFragment();
108
+ for (var index = 0; index < dragPreviewContent.length; index++) {
109
+ var element = dragPreviewContent[index];
110
+ var contentPreviewOneElement = createPreviewForElement(element.dom, element.nodeType, element.nodeSpacing);
111
+ previewWrapperFragment.appendChild(contentPreviewOneElement);
63
112
  }
64
- container.appendChild(parent);
113
+ container.appendChild(previewWrapperFragment);
65
114
  var scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
66
115
  var scrollParentClassNames = scrollParent === null || scrollParent === void 0 ? void 0 : scrollParent.className;
67
-
68
116
  // Add the scroll parent class to the container to ensure the cloned element is styled correctly
69
117
  container.className = scrollParentClassNames || '';
70
118
  container.classList.remove('fabric-editor-popup-scroll-parent');
@@ -86,6 +86,9 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
86
86
  }) => EditorCommand;
87
87
  moveNode: MoveNode;
88
88
  showDragHandleAt: (pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => EditorCommand;
89
+ toggleBlockMenu: (options?: {
90
+ closeMenu?: boolean;
91
+ }) => EditorCommand;
89
92
  setNodeDragged: (getPos: () => number | undefined, anchorName: string, nodeType: string) => EditorCommand;
90
93
  setMultiSelectPositions: (anchor?: number, head?: number) => EditorCommand;
91
94
  };
@@ -1,10 +1,10 @@
1
1
  import { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
- import { EditorState, NodeSelection, Selection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import { EditorState, NodeSelection, TextSelection, type Transaction, Selection } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize: number) => {
4
4
  inlineNodePos: number;
5
5
  inlineNodeEndPos: number;
6
6
  };
7
- export declare const getSelection: (tr: Transaction, start: number) => TextSelection | NodeSelection;
7
+ export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
8
8
  export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
9
9
  export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
10
10
  /**
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import type { IntlShape } from 'react-intl-next';
6
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
7
+ import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
8
+ import type { BlockControlsPlugin } from '../blockControlsPluginType';
9
+ export declare const getBlockMenuItems: (formatMessage: IntlShape['formatMessage']) => {
10
+ items: MenuItem[];
11
+ }[];
12
+ export declare const menuItemsCallback: {
13
+ moveUp: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage']) => import("@atlaskit/editor-common/types").Command;
14
+ moveDown: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage']) => import("@atlaskit/editor-common/types").Command;
15
+ copy: () => void;
16
+ delete: () => void;
17
+ };
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
5
+ import type { BlockControlsPlugin } from '../blockControlsPluginType';
6
+ type BlockMenuProps = {
7
+ editorView: EditorView | undefined;
8
+ mountPoint?: HTMLElement;
9
+ boundariesElement?: HTMLElement;
10
+ scrollableElement?: HTMLElement;
11
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
12
+ };
13
+ declare const _default: React.FC<import("react-intl-next").WithIntlProps<BlockMenuProps & WrappedComponentProps>> & {
14
+ WrappedComponent: React.ComponentType<BlockMenuProps & WrappedComponentProps>;
15
+ };
16
+ export default _default;
@@ -29,6 +29,12 @@ export declare const dropTargetMarginMap: {
29
29
  export declare const spaceLookupMap: {
30
30
  [k: string]: string;
31
31
  };
32
+ export declare const spacingBetweenNodesForPreview: {
33
+ [key: string]: {
34
+ top: string;
35
+ bottom: string;
36
+ };
37
+ };
32
38
  export declare const nodeMargins: {
33
39
  [key: string]: {
34
40
  top: number;
@@ -38,3 +44,4 @@ export declare const nodeMargins: {
38
44
  export declare const DEFAULT_COLUMN_DISTRIBUTIONS: {
39
45
  [key: number]: number;
40
46
  };
47
+ export declare const BLOCK_MENU_WIDTH = 220;
@@ -1 +1,9 @@
1
- export declare const dragPreview: (container: HTMLElement, dom: HTMLElement, nodeType: string) => () => HTMLElement;
1
+ export type DragPreviewContent = {
2
+ dom: HTMLElement;
3
+ nodeType: string;
4
+ nodeSpacing?: {
5
+ top: string;
6
+ bottom: string;
7
+ };
8
+ };
9
+ export declare const dragPreview: (container: HTMLElement, dragPreviewContent: DragPreviewContent | DragPreviewContent[]) => () => HTMLElement;
@@ -86,6 +86,9 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
86
86
  }) => EditorCommand;
87
87
  moveNode: MoveNode;
88
88
  showDragHandleAt: (pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => EditorCommand;
89
+ toggleBlockMenu: (options?: {
90
+ closeMenu?: boolean;
91
+ }) => EditorCommand;
89
92
  setNodeDragged: (getPos: () => number | undefined, anchorName: string, nodeType: string) => EditorCommand;
90
93
  setMultiSelectPositions: (anchor?: number, head?: number) => EditorCommand;
91
94
  };
@@ -1,10 +1,10 @@
1
1
  import { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
- import { EditorState, NodeSelection, Selection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import { EditorState, NodeSelection, TextSelection, type Transaction, Selection } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize: number) => {
4
4
  inlineNodePos: number;
5
5
  inlineNodeEndPos: number;
6
6
  };
7
- export declare const getSelection: (tr: Transaction, start: number) => TextSelection | NodeSelection;
7
+ export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
8
8
  export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
9
9
  export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
10
10
  /**
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import type { IntlShape } from 'react-intl-next';
6
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
7
+ import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
8
+ import type { BlockControlsPlugin } from '../blockControlsPluginType';
9
+ export declare const getBlockMenuItems: (formatMessage: IntlShape['formatMessage']) => {
10
+ items: MenuItem[];
11
+ }[];
12
+ export declare const menuItemsCallback: {
13
+ moveUp: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage']) => import("@atlaskit/editor-common/types").Command;
14
+ moveDown: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage']) => import("@atlaskit/editor-common/types").Command;
15
+ copy: () => void;
16
+ delete: () => void;
17
+ };
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
5
+ import type { BlockControlsPlugin } from '../blockControlsPluginType';
6
+ type BlockMenuProps = {
7
+ editorView: EditorView | undefined;
8
+ mountPoint?: HTMLElement;
9
+ boundariesElement?: HTMLElement;
10
+ scrollableElement?: HTMLElement;
11
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
12
+ };
13
+ declare const _default: React.FC<import("react-intl-next").WithIntlProps<BlockMenuProps & WrappedComponentProps>> & {
14
+ WrappedComponent: React.ComponentType<BlockMenuProps & WrappedComponentProps>;
15
+ };
16
+ export default _default;
@@ -29,6 +29,12 @@ export declare const dropTargetMarginMap: {
29
29
  export declare const spaceLookupMap: {
30
30
  [k: string]: string;
31
31
  };
32
+ export declare const spacingBetweenNodesForPreview: {
33
+ [key: string]: {
34
+ top: string;
35
+ bottom: string;
36
+ };
37
+ };
32
38
  export declare const nodeMargins: {
33
39
  [key: string]: {
34
40
  top: number;
@@ -38,3 +44,4 @@ export declare const nodeMargins: {
38
44
  export declare const DEFAULT_COLUMN_DISTRIBUTIONS: {
39
45
  [key: number]: number;
40
46
  };
47
+ export declare const BLOCK_MENU_WIDTH = 220;
@@ -1 +1,9 @@
1
- export declare const dragPreview: (container: HTMLElement, dom: HTMLElement, nodeType: string) => () => HTMLElement;
1
+ export type DragPreviewContent = {
2
+ dom: HTMLElement;
3
+ nodeType: string;
4
+ nodeSpacing?: {
5
+ top: string;
6
+ bottom: string;
7
+ };
8
+ };
9
+ export declare const dragPreview: (container: HTMLElement, dragPreviewContent: DragPreviewContent | DragPreviewContent[]) => () => HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "2.27.1",
3
+ "version": "2.27.4",
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": "^47.2.1",
34
- "@atlaskit/editor-common": "^99.16.0",
34
+ "@atlaskit/editor-common": "^99.17.0",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.4.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.12.0",
37
37
  "@atlaskit/editor-plugin-editor-disabled": "^1.5.0",
@@ -40,15 +40,15 @@
40
40
  "@atlaskit/editor-plugin-selection": "^1.8.0",
41
41
  "@atlaskit/editor-plugin-width": "^2.1.0",
42
42
  "@atlaskit/editor-prosemirror": "7.0.0",
43
- "@atlaskit/editor-shared-styles": "^3.2.0",
43
+ "@atlaskit/editor-shared-styles": "^3.3.0",
44
44
  "@atlaskit/editor-tables": "^2.9.0",
45
45
  "@atlaskit/icon": "^23.9.0",
46
- "@atlaskit/platform-feature-flags": "^1.0.0",
46
+ "@atlaskit/platform-feature-flags": "^1.1.0",
47
47
  "@atlaskit/pragmatic-drag-and-drop": "^1.5.0",
48
48
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.0",
49
49
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.2.0",
50
50
  "@atlaskit/primitives": "^13.5.0",
51
- "@atlaskit/theme": "^15.0.0",
51
+ "@atlaskit/theme": "^16.0.0",
52
52
  "@atlaskit/tmp-editor-statsig": "^2.46.0",
53
53
  "@atlaskit/tokens": "^3.3.0",
54
54
  "@atlaskit/tooltip": "^19.1.0",