@atlaskit/editor-plugin-block-menu 5.1.3 → 5.1.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/editor-commands/transform-node-utils/flattenListStep.js +108 -0
  3. package/dist/cjs/editor-commands/transform-node-utils/flattenStep.js +21 -0
  4. package/dist/cjs/editor-commands/transform-node-utils/transform.js +33 -5
  5. package/dist/cjs/editor-commands/transform-node-utils/types.js +1 -1
  6. package/dist/cjs/editor-commands/transform-node-utils/unwrapExpandStep.js +44 -0
  7. package/dist/cjs/editor-commands/transform-node-utils/unwrapListStep.js +28 -0
  8. package/dist/cjs/editor-commands/transform-node-utils/unwrapStep.js +20 -0
  9. package/dist/cjs/editor-commands/transform-node-utils/utils.js +7 -1
  10. package/dist/cjs/editor-commands/transform-node-utils/wrapIntoLayoutStep.js +23 -0
  11. package/dist/cjs/editor-commands/transform-node-utils/wrapStep.js +16 -0
  12. package/dist/cjs/editor-commands/transformNode.js +12 -6
  13. package/dist/cjs/ui/block-menu.js +20 -7
  14. package/dist/es2019/editor-commands/transform-node-utils/flattenListStep.js +94 -0
  15. package/dist/es2019/editor-commands/transform-node-utils/flattenStep.js +15 -0
  16. package/dist/es2019/editor-commands/transform-node-utils/transform.js +34 -6
  17. package/dist/es2019/editor-commands/transform-node-utils/types.js +1 -1
  18. package/dist/es2019/editor-commands/transform-node-utils/unwrapExpandStep.js +38 -0
  19. package/dist/es2019/editor-commands/transform-node-utils/unwrapListStep.js +18 -0
  20. package/dist/es2019/editor-commands/transform-node-utils/unwrapStep.js +12 -0
  21. package/dist/es2019/editor-commands/transform-node-utils/utils.js +6 -0
  22. package/dist/es2019/editor-commands/transform-node-utils/wrapIntoLayoutStep.js +20 -0
  23. package/dist/es2019/editor-commands/transform-node-utils/wrapStep.js +12 -0
  24. package/dist/es2019/editor-commands/transformNode.js +12 -7
  25. package/dist/es2019/ui/block-menu.js +15 -7
  26. package/dist/esm/editor-commands/transform-node-utils/flattenListStep.js +102 -0
  27. package/dist/esm/editor-commands/transform-node-utils/flattenStep.js +15 -0
  28. package/dist/esm/editor-commands/transform-node-utils/transform.js +33 -5
  29. package/dist/esm/editor-commands/transform-node-utils/types.js +1 -1
  30. package/dist/esm/editor-commands/transform-node-utils/unwrapExpandStep.js +37 -0
  31. package/dist/esm/editor-commands/transform-node-utils/unwrapListStep.js +21 -0
  32. package/dist/esm/editor-commands/transform-node-utils/unwrapStep.js +13 -0
  33. package/dist/esm/editor-commands/transform-node-utils/utils.js +6 -0
  34. package/dist/esm/editor-commands/transform-node-utils/wrapIntoLayoutStep.js +17 -0
  35. package/dist/esm/editor-commands/transform-node-utils/wrapStep.js +10 -0
  36. package/dist/esm/editor-commands/transformNode.js +12 -6
  37. package/dist/esm/ui/block-menu.js +19 -7
  38. package/dist/types/editor-commands/transform-node-utils/flattenListStep.d.ts +49 -0
  39. package/dist/types/editor-commands/transform-node-utils/flattenStep.d.ts +2 -0
  40. package/dist/types/editor-commands/transform-node-utils/transform.d.ts +3 -2
  41. package/dist/types/editor-commands/transform-node-utils/types.d.ts +1 -1
  42. package/dist/types/editor-commands/transform-node-utils/unwrapExpandStep.d.ts +8 -0
  43. package/dist/types/editor-commands/transform-node-utils/unwrapListStep.d.ts +7 -0
  44. package/dist/types/editor-commands/transform-node-utils/unwrapStep.d.ts +2 -0
  45. package/dist/types/editor-commands/transform-node-utils/utils.d.ts +2 -0
  46. package/dist/types/editor-commands/transform-node-utils/wrapIntoLayoutStep.d.ts +2 -0
  47. package/dist/types/editor-commands/transform-node-utils/wrapStep.d.ts +2 -0
  48. package/dist/types/editor-commands/transforms/types.d.ts +1 -1
  49. package/dist/types-ts4.5/editor-commands/transform-node-utils/flattenListStep.d.ts +49 -0
  50. package/dist/types-ts4.5/editor-commands/transform-node-utils/flattenStep.d.ts +2 -0
  51. package/dist/types-ts4.5/editor-commands/transform-node-utils/transform.d.ts +3 -2
  52. package/dist/types-ts4.5/editor-commands/transform-node-utils/types.d.ts +1 -1
  53. package/dist/types-ts4.5/editor-commands/transform-node-utils/unwrapExpandStep.d.ts +8 -0
  54. package/dist/types-ts4.5/editor-commands/transform-node-utils/unwrapListStep.d.ts +7 -0
  55. package/dist/types-ts4.5/editor-commands/transform-node-utils/unwrapStep.d.ts +2 -0
  56. package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +2 -0
  57. package/dist/types-ts4.5/editor-commands/transform-node-utils/wrapIntoLayoutStep.d.ts +2 -0
  58. package/dist/types-ts4.5/editor-commands/transform-node-utils/wrapStep.d.ts +2 -0
  59. package/dist/types-ts4.5/editor-commands/transforms/types.d.ts +1 -1
  60. package/package.json +3 -3
@@ -1,4 +1,5 @@
1
1
  /* block-menu.tsx generated by @compiled/babel-plugin v0.38.1 */
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
3
  import "./block-menu.compiled.css";
3
4
  import { ax, ix } from "@compiled/react/runtime";
4
5
  import React, { useContext, useEffect, useRef } from 'react';
@@ -25,6 +26,7 @@ var styles = {
25
26
  };
26
27
  var DEFAULT_MENU_WIDTH = 230;
27
28
  var DRAG_HANDLE_OFFSET_PADDING = 5;
29
+ var FALLBACK_MENU_HEIGHT = 300;
28
30
  var PopupWithListeners = withReactEditorViewOuterListeners(Popup);
29
31
  var useConditionalBlockMenuEffect = conditionalHooksFactory(function () {
30
32
  return fg('platform_editor_toolbar_aifc_user_intent_fix');
@@ -155,6 +157,18 @@ var BlockMenu = function BlockMenu(_ref4) {
155
157
  var targetHandleRef = editorView === null || editorView === void 0 || (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(DRAG_HANDLE_SELECTOR);
156
158
  var prevIsMenuOpenRef = useRef(false);
157
159
  var popupRef = useRef(undefined);
160
+ var _React$useState = React.useState(0),
161
+ _React$useState2 = _slicedToArray(_React$useState, 2),
162
+ menuHeight = _React$useState2[0],
163
+ setMenuHeight = _React$useState2[1];
164
+ var targetHandleHeightOffset = -((targetHandleRef === null || targetHandleRef === void 0 ? void 0 : targetHandleRef.clientHeight) || 0);
165
+ React.useLayoutEffect(function () {
166
+ var _popupRef$current;
167
+ if (!isMenuOpen) {
168
+ return;
169
+ }
170
+ setMenuHeight(((_popupRef$current = popupRef.current) === null || _popupRef$current === void 0 ? void 0 : _popupRef$current.clientHeight) || FALLBACK_MENU_HEIGHT);
171
+ }, [isMenuOpen]);
158
172
  var hasFocus = (_ref5 = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) || document.activeElement === targetHandleRef || popupRef.current && (popupRef.current.contains(document.activeElement) || popupRef.current === document.activeElement)) !== null && _ref5 !== void 0 ? _ref5 : false;
159
173
  var selectedByShortcutOrDragHandle = !!isSelectedViaDragHandle || !!openedViaKeyboard;
160
174
 
@@ -218,8 +232,7 @@ var BlockMenu = function BlockMenu(_ref4) {
218
232
  fallbackComponent: null
219
233
  }, /*#__PURE__*/React.createElement(PopupWithListeners, {
220
234
  alignX: 'right',
221
- alignY: 'start' // respected when forcePlacement is true
222
- ,
235
+ alignY: 'start',
223
236
  handleClickOutside: closeMenu,
224
237
  handleEscapeKeydown: closeMenu,
225
238
  handleBackspaceDeleteKeydown: handleBackspaceDeleteKeydown,
@@ -229,16 +242,15 @@ var BlockMenu = function BlockMenu(_ref4) {
229
242
  target: targetHandleRef,
230
243
  zIndex: akEditorFloatingOverlapPanelZIndex,
231
244
  fitWidth: DEFAULT_MENU_WIDTH,
232
- forcePlacement: true,
233
- preventOverflow: true // disables forced horizontal placement when forcePlacement is on, so fitWidth controls flipping
234
- ,
245
+ fitHeight: menuHeight,
246
+ preventOverflow: true,
235
247
  stick: true,
248
+ offset: [DRAG_HANDLE_WIDTH + DRAG_HANDLE_OFFSET_PADDING, targetHandleHeightOffset],
236
249
  focusTrap: openedViaKeyboard ?
237
250
  // Only enable focus trap when opened via keyboard to make sure the focus is on the first focusable menu item
238
251
  {
239
252
  initialFocus: undefined
240
- } : undefined,
241
- offset: [DRAG_HANDLE_WIDTH + DRAG_HANDLE_OFFSET_PADDING, 0]
253
+ } : undefined
242
254
  }, /*#__PURE__*/React.createElement(BlockMenuContent, {
243
255
  api: api,
244
256
  setRef: setRef
@@ -0,0 +1,49 @@
1
+ import type { TransformStep } from './types';
2
+ /**
3
+ * Given an array of nodes, returns an array with the flattened children of any list node
4
+ * to it's first ancestor list, maintaining document order.
5
+ *
6
+ * @example
7
+ * Input:
8
+ * - bulletList
9
+ * - listItem "A"
10
+ * - listItem "B"
11
+ * - bulletList
12
+ * - listItem "C"
13
+ * - listItem "D"
14
+ * - listItem "E"
15
+ *
16
+ * Output:
17
+ * - bulletList
18
+ * - listItem "A"
19
+ * - listItem "B"
20
+ * - listItem "C"
21
+ * - listItem "D"
22
+ * - listItem "E"
23
+ *
24
+ * @example
25
+ * Input (deeply nested):
26
+ * - bulletList
27
+ * - listItem "1"
28
+ * - bulletList
29
+ * - listItem "1.1"
30
+ * - bulletList
31
+ * - listItem "1.1.1"
32
+ * - listItem "1.2"
33
+ * - listItem "2"
34
+ *
35
+ * Output:
36
+ * - bulletList
37
+ * - listItem "1"
38
+ * - listItem "1.1"
39
+ * - listItem "1.1.1"
40
+ * - listItem "1.2"
41
+ * - listItem "2"
42
+ *
43
+ * @param nodes
44
+ * @param context
45
+ * @returns
46
+ *
47
+ * TODO: Lists with mixed types (e.g. bulletList with a taskItem) doesn't full flatten
48
+ */
49
+ export declare const flattenListStep: TransformStep;
@@ -0,0 +1,2 @@
1
+ import type { TransformStep } from './types';
2
+ export declare const flattenStep: TransformStep;
@@ -1,8 +1,9 @@
1
- import type { Node as PMNode, NodeType, Schema } from '@atlaskit/editor-prosemirror/model';
1
+ import { type Node as PMNode, type NodeType, type Schema } from '@atlaskit/editor-prosemirror/model';
2
2
  interface GetOutputNodesArgs {
3
+ isNested: boolean;
3
4
  schema: Schema;
4
5
  sourceNode: PMNode;
5
6
  targetNodeType: NodeType;
6
7
  }
7
- export declare const getOutputNodes: ({ sourceNode, targetNodeType, schema, }: GetOutputNodesArgs) => PMNode[] | undefined;
8
+ export declare const getOutputNodes: ({ sourceNode, targetNodeType, schema, isNested, }: GetOutputNodesArgs) => PMNode[] | undefined;
8
9
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
2
- export type NodeTypeName = 'blockquote' | 'blockCard' | 'bodiedExtension' | 'bulletList' | 'codeBlock' | 'decisionList' | 'embedCard' | 'expand' | 'extension' | 'heading' | 'layout' | 'media' | 'mediaGroup' | 'mediaSingle' | 'multiBodiedExtension' | 'orderedList' | 'panel' | 'paragraph' | 'nestedExpand' | 'taskList' | 'table';
2
+ export type NodeTypeName = 'blockquote' | 'blockCard' | 'bodiedExtension' | 'bulletList' | 'codeBlock' | 'decisionList' | 'embedCard' | 'expand' | 'extension' | 'heading' | 'layoutSection' | 'media' | 'mediaGroup' | 'mediaSingle' | 'multiBodiedExtension' | 'orderedList' | 'panel' | 'paragraph' | 'nestedExpand' | 'taskList' | 'table';
3
3
  export type NodeCategory = 'atomic' | 'container' | 'list' | 'text';
4
4
  export declare const NODE_CATEGORY_BY_TYPE: Record<NodeTypeName, NodeCategory>;
5
5
  export declare const isNodeTypeName: (value: string) => value is NodeTypeName;
@@ -0,0 +1,8 @@
1
+ import type { TransformStep } from './types';
2
+ /**
3
+ * Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
4
+ * and prepending it to the children.
5
+ *
6
+ * Example: expand({ title: 'title' })(p('b')) → [p('title'), p('b')]
7
+ */
8
+ export declare const unwrapExpandStep: TransformStep;
@@ -0,0 +1,7 @@
1
+ import type { TransformStep } from './types';
2
+ /**
3
+ * Given an array of nodes, returns an array with the flattened children of any list nodes.
4
+ * @param nodes
5
+ * @returns
6
+ */
7
+ export declare const unwrapListStep: TransformStep;
@@ -0,0 +1,2 @@
1
+ import type { TransformStep } from './types';
2
+ export declare const unwrapStep: TransformStep;
@@ -1,3 +1,5 @@
1
1
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
2
  import { type ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
3
+ import type { NodeTypeName } from './types';
3
4
  export declare const getSelectedNode: (selection: Selection) => ContentNodeWithPos | undefined;
5
+ export declare const getTargetNodeTypeNameInContext: (nodeTypeName: NodeTypeName | null, isNested?: boolean) => NodeTypeName | null;
@@ -0,0 +1,2 @@
1
+ import type { TransformStep } from './types';
2
+ export declare const wrapIntoLayoutStep: TransformStep;
@@ -0,0 +1,2 @@
1
+ import type { TransformStep } from './types';
2
+ export declare const wrapStep: TransformStep;
@@ -1,7 +1,7 @@
1
1
  import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import type { TransformContext } from '@atlaskit/editor-common/transforms';
3
3
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
- export type FormatNodeTargetType = 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'blockquote' | 'expand' | 'layoutSection' | 'panel' | 'codeBlock' | 'bulletList' | 'orderedList' | 'taskList';
4
+ export type FormatNodeTargetType = 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'blockquote' | 'expand' | 'layoutSection' | 'panel' | 'codeBlock' | 'bulletList' | 'orderedList' | 'taskList' | 'decisionList';
5
5
  export type TransfromNodeTargetType = FormatNodeTargetType;
6
6
  export type FormatNodeAnalyticsAttrs = {
7
7
  inputMethod: INPUT_METHOD.BLOCK_MENU;
@@ -0,0 +1,49 @@
1
+ import type { TransformStep } from './types';
2
+ /**
3
+ * Given an array of nodes, returns an array with the flattened children of any list node
4
+ * to it's first ancestor list, maintaining document order.
5
+ *
6
+ * @example
7
+ * Input:
8
+ * - bulletList
9
+ * - listItem "A"
10
+ * - listItem "B"
11
+ * - bulletList
12
+ * - listItem "C"
13
+ * - listItem "D"
14
+ * - listItem "E"
15
+ *
16
+ * Output:
17
+ * - bulletList
18
+ * - listItem "A"
19
+ * - listItem "B"
20
+ * - listItem "C"
21
+ * - listItem "D"
22
+ * - listItem "E"
23
+ *
24
+ * @example
25
+ * Input (deeply nested):
26
+ * - bulletList
27
+ * - listItem "1"
28
+ * - bulletList
29
+ * - listItem "1.1"
30
+ * - bulletList
31
+ * - listItem "1.1.1"
32
+ * - listItem "1.2"
33
+ * - listItem "2"
34
+ *
35
+ * Output:
36
+ * - bulletList
37
+ * - listItem "1"
38
+ * - listItem "1.1"
39
+ * - listItem "1.1.1"
40
+ * - listItem "1.2"
41
+ * - listItem "2"
42
+ *
43
+ * @param nodes
44
+ * @param context
45
+ * @returns
46
+ *
47
+ * TODO: Lists with mixed types (e.g. bulletList with a taskItem) doesn't full flatten
48
+ */
49
+ export declare const flattenListStep: TransformStep;
@@ -0,0 +1,2 @@
1
+ import type { TransformStep } from './types';
2
+ export declare const flattenStep: TransformStep;
@@ -1,8 +1,9 @@
1
- import type { Node as PMNode, NodeType, Schema } from '@atlaskit/editor-prosemirror/model';
1
+ import { type Node as PMNode, type NodeType, type Schema } from '@atlaskit/editor-prosemirror/model';
2
2
  interface GetOutputNodesArgs {
3
+ isNested: boolean;
3
4
  schema: Schema;
4
5
  sourceNode: PMNode;
5
6
  targetNodeType: NodeType;
6
7
  }
7
- export declare const getOutputNodes: ({ sourceNode, targetNodeType, schema, }: GetOutputNodesArgs) => PMNode[] | undefined;
8
+ export declare const getOutputNodes: ({ sourceNode, targetNodeType, schema, isNested, }: GetOutputNodesArgs) => PMNode[] | undefined;
8
9
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
2
- export type NodeTypeName = 'blockquote' | 'blockCard' | 'bodiedExtension' | 'bulletList' | 'codeBlock' | 'decisionList' | 'embedCard' | 'expand' | 'extension' | 'heading' | 'layout' | 'media' | 'mediaGroup' | 'mediaSingle' | 'multiBodiedExtension' | 'orderedList' | 'panel' | 'paragraph' | 'nestedExpand' | 'taskList' | 'table';
2
+ export type NodeTypeName = 'blockquote' | 'blockCard' | 'bodiedExtension' | 'bulletList' | 'codeBlock' | 'decisionList' | 'embedCard' | 'expand' | 'extension' | 'heading' | 'layoutSection' | 'media' | 'mediaGroup' | 'mediaSingle' | 'multiBodiedExtension' | 'orderedList' | 'panel' | 'paragraph' | 'nestedExpand' | 'taskList' | 'table';
3
3
  export type NodeCategory = 'atomic' | 'container' | 'list' | 'text';
4
4
  export declare const NODE_CATEGORY_BY_TYPE: Record<NodeTypeName, NodeCategory>;
5
5
  export declare const isNodeTypeName: (value: string) => value is NodeTypeName;
@@ -0,0 +1,8 @@
1
+ import type { TransformStep } from './types';
2
+ /**
3
+ * Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
4
+ * and prepending it to the children.
5
+ *
6
+ * Example: expand({ title: 'title' })(p('b')) → [p('title'), p('b')]
7
+ */
8
+ export declare const unwrapExpandStep: TransformStep;
@@ -0,0 +1,7 @@
1
+ import type { TransformStep } from './types';
2
+ /**
3
+ * Given an array of nodes, returns an array with the flattened children of any list nodes.
4
+ * @param nodes
5
+ * @returns
6
+ */
7
+ export declare const unwrapListStep: TransformStep;
@@ -0,0 +1,2 @@
1
+ import type { TransformStep } from './types';
2
+ export declare const unwrapStep: TransformStep;
@@ -1,3 +1,5 @@
1
1
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
2
  import { type ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
3
+ import type { NodeTypeName } from './types';
3
4
  export declare const getSelectedNode: (selection: Selection) => ContentNodeWithPos | undefined;
5
+ export declare const getTargetNodeTypeNameInContext: (nodeTypeName: NodeTypeName | null, isNested?: boolean) => NodeTypeName | null;
@@ -0,0 +1,2 @@
1
+ import type { TransformStep } from './types';
2
+ export declare const wrapIntoLayoutStep: TransformStep;
@@ -0,0 +1,2 @@
1
+ import type { TransformStep } from './types';
2
+ export declare const wrapStep: TransformStep;
@@ -1,7 +1,7 @@
1
1
  import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import type { TransformContext } from '@atlaskit/editor-common/transforms';
3
3
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
- export type FormatNodeTargetType = 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'blockquote' | 'expand' | 'layoutSection' | 'panel' | 'codeBlock' | 'bulletList' | 'orderedList' | 'taskList';
4
+ export type FormatNodeTargetType = 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'paragraph' | 'blockquote' | 'expand' | 'layoutSection' | 'panel' | 'codeBlock' | 'bulletList' | 'orderedList' | 'taskList' | 'decisionList';
5
5
  export type TransfromNodeTargetType = FormatNodeTargetType;
6
6
  export type FormatNodeAnalyticsAttrs = {
7
7
  inputMethod: INPUT_METHOD.BLOCK_MENU;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "5.1.3",
3
+ "version": "5.1.5",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -44,12 +44,12 @@
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
45
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
46
46
  "@atlaskit/primitives": "^16.4.0",
47
- "@atlaskit/tmp-editor-statsig": "^14.4.0",
47
+ "@atlaskit/tmp-editor-statsig": "^14.6.0",
48
48
  "@atlaskit/tokens": "^8.4.0",
49
49
  "@babel/runtime": "^7.0.0"
50
50
  },
51
51
  "peerDependencies": {
52
- "@atlaskit/editor-common": "^110.37.0",
52
+ "@atlaskit/editor-common": "^110.38.0",
53
53
  "react": "^18.2.0",
54
54
  "react-intl-next": "npm:react-intl@^5.18.1"
55
55
  },