@atlaskit/editor-plugin-block-controls 6.1.1 → 6.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 (51) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/pm-plugins/decorations-anchor.js +7 -3
  3. package/dist/cjs/pm-plugins/decorations-drop-target-active.js +2 -1
  4. package/dist/cjs/pm-plugins/handle-mouse-over.js +36 -12
  5. package/dist/cjs/pm-plugins/main.js +3 -2
  6. package/dist/cjs/pm-plugins/quick-insert-calculate-position.js +2 -1
  7. package/dist/cjs/pm-plugins/utils/anchor-utils.js +3 -2
  8. package/dist/cjs/ui/block-menu.js +3 -2
  9. package/dist/cjs/ui/drag-handle.js +12 -10
  10. package/dist/cjs/ui/drop-target-layout.js +4 -2
  11. package/dist/cjs/ui/drop-target.js +20 -6
  12. package/dist/cjs/ui/global-styles.js +96 -1
  13. package/dist/cjs/ui/inline-drop-target.js +39 -5
  14. package/dist/cjs/ui/quick-insert-button.js +3 -2
  15. package/dist/cjs/ui/utils/anchor-name.js +4 -0
  16. package/dist/cjs/ui/utils/dom-attr-name.js +53 -0
  17. package/dist/es2019/pm-plugins/decorations-anchor.js +7 -3
  18. package/dist/es2019/pm-plugins/decorations-drop-target-active.js +2 -1
  19. package/dist/es2019/pm-plugins/handle-mouse-over.js +30 -12
  20. package/dist/es2019/pm-plugins/main.js +3 -2
  21. package/dist/es2019/pm-plugins/quick-insert-calculate-position.js +2 -1
  22. package/dist/es2019/pm-plugins/utils/anchor-utils.js +3 -2
  23. package/dist/es2019/ui/block-menu.js +3 -2
  24. package/dist/es2019/ui/drag-handle.js +12 -10
  25. package/dist/es2019/ui/drop-target-layout.js +4 -2
  26. package/dist/es2019/ui/drop-target.js +20 -6
  27. package/dist/es2019/ui/global-styles.js +131 -1
  28. package/dist/es2019/ui/inline-drop-target.js +39 -5
  29. package/dist/es2019/ui/quick-insert-button.js +4 -3
  30. package/dist/es2019/ui/utils/anchor-name.js +4 -0
  31. package/dist/es2019/ui/utils/dom-attr-name.js +47 -0
  32. package/dist/esm/pm-plugins/decorations-anchor.js +7 -3
  33. package/dist/esm/pm-plugins/decorations-drop-target-active.js +2 -1
  34. package/dist/esm/pm-plugins/handle-mouse-over.js +35 -12
  35. package/dist/esm/pm-plugins/main.js +3 -2
  36. package/dist/esm/pm-plugins/quick-insert-calculate-position.js +2 -1
  37. package/dist/esm/pm-plugins/utils/anchor-utils.js +3 -2
  38. package/dist/esm/ui/block-menu.js +3 -2
  39. package/dist/esm/ui/drag-handle.js +12 -10
  40. package/dist/esm/ui/drop-target-layout.js +4 -2
  41. package/dist/esm/ui/drop-target.js +20 -6
  42. package/dist/esm/ui/global-styles.js +96 -1
  43. package/dist/esm/ui/inline-drop-target.js +39 -5
  44. package/dist/esm/ui/quick-insert-button.js +4 -3
  45. package/dist/esm/ui/utils/anchor-name.js +4 -0
  46. package/dist/esm/ui/utils/dom-attr-name.js +47 -0
  47. package/dist/types/pm-plugins/decorations-anchor.d.ts +2 -0
  48. package/dist/types/ui/utils/dom-attr-name.d.ts +5 -0
  49. package/dist/types-ts4.5/pm-plugins/decorations-anchor.d.ts +2 -0
  50. package/dist/types-ts4.5/ui/utils/dom-attr-name.d.ts +5 -0
  51. package/package.json +8 -8
@@ -14,6 +14,7 @@ import { akEditorBreakoutPadding } from '@atlaskit/editor-shared-styles';
14
14
  import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
15
15
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
16
16
  import { B200 } from '@atlaskit/theme/colors';
17
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
17
18
  import { getNodeAnchor } from '../pm-plugins/decorations-common';
18
19
  import { useActiveAnchorTracker } from '../pm-plugins/utils/active-anchor-tracker';
19
20
  import { isAnchorSupported } from '../pm-plugins/utils/anchor-utils';
@@ -92,8 +93,11 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
92
93
  isDraggedOver = _useState2[0],
93
94
  setIsDraggedOver = _useState2[1];
94
95
  var anchorName = useMemo(function () {
96
+ if (expValEquals('platform_editor_native_anchor_support', 'isEnabled', true)) {
97
+ return nextNode ? (api === null || api === void 0 ? void 0 : api.core.actions.getAnchorIdForNode(nextNode, getPos() || -1)) || '' : '';
98
+ }
95
99
  return nextNode ? getNodeAnchor(nextNode) : '';
96
- }, [nextNode]);
100
+ }, [api, getPos, nextNode]);
97
101
  var _useActiveAnchorTrack = useActiveAnchorTracker(anchorName),
98
102
  _useActiveAnchorTrack2 = _slicedToArray(_useActiveAnchorTrack, 1),
99
103
  isActiveAnchor = _useActiveAnchorTrack2[0];
@@ -102,6 +106,7 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
102
106
  if (!nextNode) {
103
107
  return defaultNodeDimension;
104
108
  }
109
+ var nextNodePos = getPos();
105
110
  var innerContainerWidth = null;
106
111
  var targetAnchorName = anchorName;
107
112
  if (['blockCard', 'embedCard', 'extension'].includes(nextNode.type.name)) {
@@ -120,7 +125,7 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
120
125
  innerContainerWidth = "calc(var(--ak-editor--line-length) * ".concat(percentageWidth, ")");
121
126
  }
122
127
  } else if (nextNode.type.name === 'table' && nextNode.firstChild) {
123
- var tableWidthAnchor = getNodeAnchor(nextNode.firstChild);
128
+ var tableWidthAnchor = expValEquals('platform_editor_native_anchor_support', 'isEnabled', true) ? typeof nextNodePos === 'number' ? (api === null || api === void 0 ? void 0 : api.core.actions.getAnchorIdForNode(nextNode.firstChild, nextNodePos + 1)) || '' : '' : getNodeAnchor(nextNode.firstChild);
124
129
  var isNumberColumnEnabled = Boolean(nextNode.attrs.isNumberColumnEnabled);
125
130
  if (isAnchorSupported()) {
126
131
  innerContainerWidth = isNumberColumnEnabled ? "calc(anchor-size(".concat(tableWidthAnchor, " width) + ").concat(TABLE_NUMBERED_COLUMN_WIDTH, "px)") : "anchor-size(".concat(tableWidthAnchor, " width)");
@@ -133,13 +138,42 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
133
138
  innerContainerWidth = "min(".concat(nextNode.attrs.width, "px, ").concat(innerContainerWidth, ")");
134
139
  }
135
140
  } else if (nextNode.type.name === 'mediaSingle' && nextNode.firstChild) {
136
- targetAnchorName = getNodeAnchor(nextNode.firstChild);
141
+ if (expValEquals('platform_editor_native_anchor_support', 'isEnabled', true)) {
142
+ var _nextNode$firstChild;
143
+ // check pos is a number
144
+ if (typeof nextNodePos === 'number' && ((_nextNode$firstChild = nextNode.firstChild) === null || _nextNode$firstChild === void 0 ? void 0 : _nextNode$firstChild.type.name) === 'media') {
145
+ targetAnchorName = (api === null || api === void 0 ? void 0 : api.core.actions.getAnchorIdForNode(nextNode.firstChild, nextNodePos + 1)) || '';
146
+ }
147
+ } else {
148
+ targetAnchorName = getNodeAnchor(nextNode.firstChild);
149
+ }
137
150
  }
138
151
 
139
152
  // Set the height target anchor name to the first or last column of the layout section so that it also works for stacked layout
140
153
  var heightTargetAnchorName = targetAnchorName;
141
154
  if (nextNode.type.name === 'layoutSection' && nextNode.firstChild && nextNode.lastChild) {
142
- heightTargetAnchorName = isLeftPosition ? getNodeAnchor(nextNode.firstChild) : getNodeAnchor(nextNode.lastChild);
155
+ if (isLeftPosition) {
156
+ if (expValEquals('platform_editor_native_anchor_support', 'isEnabled', true)) {
157
+ if (typeof nextNodePos === 'number') {
158
+ heightTargetAnchorName = (api === null || api === void 0 ? void 0 : api.core.actions.getAnchorIdForNode(nextNode.firstChild, nextNodePos + 1)) || '';
159
+ } else {
160
+ heightTargetAnchorName = '';
161
+ }
162
+ } else {
163
+ heightTargetAnchorName = getNodeAnchor(nextNode.firstChild);
164
+ }
165
+ } else {
166
+ if (expValEquals('platform_editor_native_anchor_support', 'isEnabled', true)) {
167
+ if (typeof nextNodePos === 'number') {
168
+ var lastNodeStartPos = nextNode.content.size - nextNode.lastChild.nodeSize;
169
+ heightTargetAnchorName = (api === null || api === void 0 ? void 0 : api.core.actions.getAnchorIdForNode(nextNode.lastChild, lastNodeStartPos + 1)) || '';
170
+ } else {
171
+ heightTargetAnchorName = '';
172
+ }
173
+ } else {
174
+ heightTargetAnchorName = getNodeAnchor(nextNode.lastChild);
175
+ }
176
+ }
143
177
  }
144
178
  if (isAnchorSupported()) {
145
179
  var width = innerContainerWidth || "anchor-size(".concat(targetAnchorName, " width)");
@@ -171,7 +205,7 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
171
205
  };
172
206
  }
173
207
  return defaultNodeDimension;
174
- }, [anchorName, anchorRectCache, nextNode, position, isLeftPosition]);
208
+ }, [nextNode, anchorName, anchorRectCache, getPos, api, isLeftPosition, position]);
175
209
  var onDrop = useCallback(function () {
176
210
  var _api$blockControls;
177
211
  var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
@@ -25,9 +25,10 @@ import { Box, Pressable, xcss } from '@atlaskit/primitives';
25
25
  import Tooltip from '@atlaskit/tooltip';
26
26
  import { getControlBottomCSSValue, getControlHeightCSSValue, getNodeHeight, getTopPosition, shouldBeSticky } from '../pm-plugins/utils/drag-handle-positions';
27
27
  import { getLeftPositionForRootElement } from '../pm-plugins/utils/widget-positions';
28
- import { rootElementGap, topPositionAdjustment, QUICK_INSERT_DIMENSIONS, QUICK_INSERT_LEFT_OFFSET } from './consts';
28
+ import { QUICK_INSERT_DIMENSIONS, QUICK_INSERT_LEFT_OFFSET, rootElementGap, topPositionAdjustment } from './consts';
29
29
  import { refreshAnchorName } from './utils/anchor-name';
30
30
  import { isInTextSelection, isNestedNodeSelected, isNonEditableBlock, isSelectionInNode } from './utils/document-checks';
31
+ import { getAnchorAttrName } from './utils/dom-attr-name';
31
32
  import { createNewLine } from './utils/editor-commands';
32
33
  import { VisibilityContainer } from './visibility-container';
33
34
  var TEXT_PARENT_TYPES = ['paragraph', 'heading', 'blockquote', 'taskItem', 'decisionItem'];
@@ -116,7 +117,7 @@ export var TypeAheadControl = function TypeAheadControl(_ref) {
116
117
  view: view,
117
118
  anchorName: rootAnchorName
118
119
  });
119
- var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(safeAnchorName, "\"]"));
120
+ var dom = view.dom.querySelector("[".concat(getAnchorAttrName(), "=\"").concat(safeAnchorName, "\"]"));
120
121
  var hasResizer = rootNodeType === 'table' || rootNodeType === 'mediaSingle';
121
122
  var isExtension = rootNodeType === 'extension' || rootNodeType === 'bodiedExtension';
122
123
  var isBlockCard = rootNodeType === 'blockCard';
@@ -156,7 +157,7 @@ export var TypeAheadControl = function TypeAheadControl(_ref) {
156
157
  useEffect(function () {
157
158
  var cleanUpTransitionListener;
158
159
  if (rootNodeType === 'extension' || rootNodeType === 'embedCard') {
159
- var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(rootAnchorName, "\"]"));
160
+ var dom = view.dom.querySelector("[".concat(getAnchorAttrName(), "=\"").concat(rootAnchorName, "\"]"));
160
161
  if (!dom) {
161
162
  return;
162
163
  }
@@ -1,3 +1,4 @@
1
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
1
2
  import { findNodeDecs } from '../../pm-plugins/decorations-anchor';
2
3
  import { key } from '../../pm-plugins/main';
3
4
  /**
@@ -9,6 +10,9 @@ export var refreshAnchorName = function refreshAnchorName(_ref) {
9
10
  view = _ref.view,
10
11
  anchorName = _ref.anchorName;
11
12
  var newAnchorName = anchorName || '';
13
+ if (expValEquals('platform_editor_native_anchor_support', 'isEnabled', true)) {
14
+ return newAnchorName;
15
+ }
12
16
  var pos = getPos();
13
17
  if (anchorName || pos === undefined) {
14
18
  return newAnchorName;
@@ -0,0 +1,47 @@
1
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
2
+ export var NODE_ANCHOR_ATTR_NAME = 'data-node-anchor';
3
+ export var NODE_NODE_TYPE_ATTR_NAME = 'data-prosemirror-node-name';
4
+ export var getAnchorAttrName = function getAnchorAttrName() {
5
+ if (expValEquals('platform_editor_native_anchor_support', 'isEnabled', true)) {
6
+ return NODE_ANCHOR_ATTR_NAME;
7
+ }
8
+ return 'data-drag-handler-anchor-name';
9
+ };
10
+ export var getTypeNameAttrName = function getTypeNameAttrName() {
11
+ if (expValEquals('platform_editor_native_anchor_support', 'isEnabled', true)) {
12
+ return NODE_NODE_TYPE_ATTR_NAME;
13
+ }
14
+ return 'data-drag-handler-node-type';
15
+ };
16
+ var isHeadingElement = function isHeadingElement(element) {
17
+ var headingTags = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
18
+ return headingTags.includes(element.tagName);
19
+ };
20
+
21
+ // This function replicates the behavior of getNodeTypeWithLevel by returning the same value.
22
+ export var getTypeNameFromDom = function getTypeNameFromDom(element) {
23
+ if (!element) {
24
+ return '';
25
+ }
26
+ var nodeType = element === null || element === void 0 ? void 0 : element.getAttribute(NODE_NODE_TYPE_ATTR_NAME);
27
+ if (!nodeType) {
28
+ return '';
29
+ }
30
+ if (isHeadingElement(element)) {
31
+ switch (element.tagName) {
32
+ case 'H1':
33
+ return 'heading-1';
34
+ case 'H2':
35
+ return 'heading-2';
36
+ case 'H3':
37
+ return 'heading-3';
38
+ case 'H4':
39
+ return 'heading-4';
40
+ case 'H5':
41
+ return 'heading-5';
42
+ case 'H6':
43
+ return 'heading-6';
44
+ }
45
+ }
46
+ return nodeType;
47
+ };
@@ -1,6 +1,8 @@
1
1
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
3
  import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ export declare const IGNORE_NODES_NEXT: string[];
5
+ export declare const IGNORE_NODE_DESCENDANTS_ADVANCED_LAYOUT: string[];
4
6
  export declare const shouldDescendIntoNode: (node: PMNode) => boolean;
5
7
  /**
6
8
  * Find node decorations corresponding to nodes with starting position between from and to (non-inclusive)
@@ -0,0 +1,5 @@
1
+ export declare const NODE_ANCHOR_ATTR_NAME = "data-node-anchor";
2
+ export declare const NODE_NODE_TYPE_ATTR_NAME = "data-prosemirror-node-name";
3
+ export declare const getAnchorAttrName: () => "data-node-anchor" | "data-drag-handler-anchor-name";
4
+ export declare const getTypeNameAttrName: () => "data-prosemirror-node-name" | "data-drag-handler-node-type";
5
+ export declare const getTypeNameFromDom: (element?: Element | null) => string;
@@ -1,6 +1,8 @@
1
1
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
3
  import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ export declare const IGNORE_NODES_NEXT: string[];
5
+ export declare const IGNORE_NODE_DESCENDANTS_ADVANCED_LAYOUT: string[];
4
6
  export declare const shouldDescendIntoNode: (node: PMNode) => boolean;
5
7
  /**
6
8
  * Find node decorations corresponding to nodes with starting position between from and to (non-inclusive)
@@ -0,0 +1,5 @@
1
+ export declare const NODE_ANCHOR_ATTR_NAME = "data-node-anchor";
2
+ export declare const NODE_NODE_TYPE_ATTR_NAME = "data-prosemirror-node-name";
3
+ export declare const getAnchorAttrName: () => "data-node-anchor" | "data-drag-handler-anchor-name";
4
+ export declare const getTypeNameAttrName: () => "data-prosemirror-node-name" | "data-drag-handler-node-type";
5
+ export declare const getTypeNameFromDom: (element?: Element | null) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "6.1.1",
3
+ "version": "6.3.0",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -28,23 +28,23 @@
28
28
  ],
29
29
  "atlaskit:src": "src/index.ts",
30
30
  "dependencies": {
31
- "@atlaskit/adf-schema": "^51.1.1",
31
+ "@atlaskit/adf-schema": "^51.1.2",
32
32
  "@atlaskit/editor-plugin-accessibility-utils": "^5.0.0",
33
- "@atlaskit/editor-plugin-analytics": "^5.1.0",
33
+ "@atlaskit/editor-plugin-analytics": "^5.2.0",
34
34
  "@atlaskit/editor-plugin-editor-disabled": "^5.0.0",
35
35
  "@atlaskit/editor-plugin-feature-flags": "^4.0.0",
36
36
  "@atlaskit/editor-plugin-interaction": "^7.0.0",
37
37
  "@atlaskit/editor-plugin-limited-mode": "^2.0.0",
38
- "@atlaskit/editor-plugin-metrics": "^6.1.0",
38
+ "@atlaskit/editor-plugin-metrics": "^6.2.0",
39
39
  "@atlaskit/editor-plugin-quick-insert": "^5.0.0",
40
40
  "@atlaskit/editor-plugin-selection": "^5.0.0",
41
- "@atlaskit/editor-plugin-type-ahead": "^5.1.0",
41
+ "@atlaskit/editor-plugin-type-ahead": "^5.2.0",
42
42
  "@atlaskit/editor-plugin-user-intent": "^3.0.0",
43
43
  "@atlaskit/editor-plugin-width": "^6.0.0",
44
44
  "@atlaskit/editor-prosemirror": "7.0.0",
45
45
  "@atlaskit/editor-shared-styles": "^3.6.0",
46
46
  "@atlaskit/editor-tables": "^2.9.0",
47
- "@atlaskit/icon": "^28.1.0",
47
+ "@atlaskit/icon": "^28.2.0",
48
48
  "@atlaskit/link": "^3.2.0",
49
49
  "@atlaskit/platform-feature-flags": "^1.1.0",
50
50
  "@atlaskit/pragmatic-drag-and-drop": "^1.7.0",
@@ -52,7 +52,7 @@
52
52
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^3.2.0",
53
53
  "@atlaskit/primitives": "^14.14.0",
54
54
  "@atlaskit/theme": "^21.0.0",
55
- "@atlaskit/tmp-editor-statsig": "^12.17.0",
55
+ "@atlaskit/tmp-editor-statsig": "^12.22.0",
56
56
  "@atlaskit/tokens": "^6.3.0",
57
57
  "@atlaskit/tooltip": "^20.4.0",
58
58
  "@babel/runtime": "^7.0.0",
@@ -64,7 +64,7 @@
64
64
  "uuid": "^3.1.0"
65
65
  },
66
66
  "peerDependencies": {
67
- "@atlaskit/editor-common": "^109.3.0",
67
+ "@atlaskit/editor-common": "^109.7.0",
68
68
  "react": "^18.2.0",
69
69
  "react-dom": "^18.2.0",
70
70
  "react-intl-next": "npm:react-intl@^5.18.1"