@atlaskit/editor-plugin-block-menu 5.2.10 → 5.2.12
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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +2 -2
- package/dist/cjs/editor-commands/transform-node-utils/utils.js +24 -4
- package/dist/cjs/editor-commands/transform-node-utils/wrapStep.js +20 -1
- package/dist/cjs/ui/block-menu-components.js +30 -20
- package/dist/cjs/ui/block-menu-renderer/BlockMenuComponent.js +37 -0
- package/dist/cjs/ui/block-menu-renderer/BlockMenuComponents.js +29 -0
- package/dist/cjs/ui/block-menu-renderer/BlockMenuRenderer.js +33 -0
- package/dist/cjs/ui/block-menu-renderer/fallbacks.js +32 -0
- package/dist/cjs/ui/block-menu-renderer/types.js +5 -0
- package/dist/cjs/ui/block-menu-renderer/utils.js +127 -0
- package/dist/cjs/ui/block-menu.js +7 -20
- package/dist/cjs/ui/hooks/useSuggestedItems.js +57 -0
- package/dist/cjs/ui/suggested-items-menu-section.js +21 -0
- package/dist/cjs/ui/suggested-menu-items.js +19 -0
- package/dist/cjs/ui/utils/suggested-items-rank.js +1 -1
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +2 -2
- package/dist/es2019/editor-commands/transform-node-utils/utils.js +23 -3
- package/dist/es2019/editor-commands/transform-node-utils/wrapStep.js +21 -1
- package/dist/es2019/ui/block-menu-components.js +12 -4
- package/dist/es2019/ui/block-menu-renderer/BlockMenuComponent.js +31 -0
- package/dist/es2019/ui/block-menu-renderer/BlockMenuComponents.js +21 -0
- package/dist/es2019/ui/block-menu-renderer/BlockMenuRenderer.js +24 -0
- package/dist/es2019/ui/block-menu-renderer/fallbacks.js +21 -0
- package/dist/es2019/ui/block-menu-renderer/types.js +1 -0
- package/dist/es2019/ui/block-menu-renderer/utils.js +93 -0
- package/dist/es2019/ui/block-menu.js +6 -13
- package/dist/es2019/ui/hooks/useSuggestedItems.js +45 -0
- package/dist/es2019/ui/suggested-items-menu-section.js +15 -0
- package/dist/es2019/ui/suggested-menu-items.js +13 -0
- package/dist/es2019/ui/utils/suggested-items-rank.js +31 -43
- package/dist/esm/editor-commands/transform-node-utils/transform.js +2 -2
- package/dist/esm/editor-commands/transform-node-utils/utils.js +23 -3
- package/dist/esm/editor-commands/transform-node-utils/wrapStep.js +21 -1
- package/dist/esm/ui/block-menu-components.js +30 -20
- package/dist/esm/ui/block-menu-renderer/BlockMenuComponent.js +30 -0
- package/dist/esm/ui/block-menu-renderer/BlockMenuComponents.js +22 -0
- package/dist/esm/ui/block-menu-renderer/BlockMenuRenderer.js +25 -0
- package/dist/esm/ui/block-menu-renderer/fallbacks.js +25 -0
- package/dist/esm/ui/block-menu-renderer/types.js +1 -0
- package/dist/esm/ui/block-menu-renderer/utils.js +121 -0
- package/dist/esm/ui/block-menu.js +6 -19
- package/dist/esm/ui/hooks/useSuggestedItems.js +51 -0
- package/dist/esm/ui/suggested-items-menu-section.js +14 -0
- package/dist/esm/ui/suggested-menu-items.js +12 -0
- package/dist/esm/ui/utils/suggested-items-rank.js +2 -2
- package/dist/types/blockMenuPluginType.d.ts +3 -2
- package/dist/types/editor-commands/transform-node-utils/utils.d.ts +11 -0
- package/dist/types/editor-commands/transform-node-utils/wrapStep.d.ts +5 -0
- package/dist/types/ui/block-menu-renderer/BlockMenuComponent.d.ts +11 -0
- package/dist/types/ui/block-menu-renderer/BlockMenuComponents.d.ts +12 -0
- package/dist/types/ui/block-menu-renderer/BlockMenuRenderer.d.ts +12 -0
- package/dist/types/ui/block-menu-renderer/fallbacks.d.ts +2 -0
- package/dist/types/ui/block-menu-renderer/types.d.ts +27 -0
- package/dist/types/ui/block-menu-renderer/utils.d.ts +37 -0
- package/dist/types/ui/hooks/useSuggestedItems.d.ts +3 -0
- package/dist/types/ui/suggested-items-menu-section.d.ts +9 -0
- package/dist/types/ui/{suggested-items-renderer.d.ts → suggested-menu-items.d.ts} +2 -2
- package/dist/types-ts4.5/blockMenuPluginType.d.ts +3 -2
- package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +11 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/wrapStep.d.ts +5 -0
- package/dist/types-ts4.5/ui/block-menu-renderer/BlockMenuComponent.d.ts +11 -0
- package/dist/types-ts4.5/ui/block-menu-renderer/BlockMenuComponents.d.ts +12 -0
- package/dist/types-ts4.5/ui/block-menu-renderer/BlockMenuRenderer.d.ts +12 -0
- package/dist/types-ts4.5/ui/block-menu-renderer/fallbacks.d.ts +2 -0
- package/dist/types-ts4.5/ui/block-menu-renderer/types.d.ts +27 -0
- package/dist/types-ts4.5/ui/block-menu-renderer/utils.d.ts +37 -0
- package/dist/types-ts4.5/ui/hooks/useSuggestedItems.d.ts +3 -0
- package/dist/types-ts4.5/ui/suggested-items-menu-section.d.ts +9 -0
- package/dist/types-ts4.5/ui/{suggested-items-renderer.d.ts → suggested-menu-items.d.ts} +2 -2
- package/package.json +3 -3
- package/dist/cjs/ui/block-menu-renderer.js +0 -104
- package/dist/cjs/ui/suggested-items-renderer.js +0 -62
- package/dist/es2019/ui/block-menu-renderer.js +0 -83
- package/dist/es2019/ui/suggested-items-renderer.js +0 -48
- package/dist/esm/ui/block-menu-renderer.js +0 -95
- package/dist/esm/ui/suggested-items-renderer.js +0 -54
- package/dist/types/ui/block-menu-renderer.d.ts +0 -18
- package/dist/types-ts4.5/ui/block-menu-renderer.d.ts +0 -18
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { RegisterBlockMenuComponent } from '../../blockMenuPluginType';
|
|
3
|
+
import type { BlockMenuRenderingContext } from './types';
|
|
4
|
+
type BlockMenuComponentProps = BlockMenuRenderingContext & {
|
|
5
|
+
registeredComponent: RegisterBlockMenuComponent;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Renders the given registered component based on its type
|
|
9
|
+
*/
|
|
10
|
+
export declare const BlockMenuComponent: ({ registeredComponent, childrenMap, fallbacks, }: BlockMenuComponentProps) => React.JSX.Element | null;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { RegisterBlockMenuComponent } from '../../blockMenuPluginType';
|
|
3
|
+
import type { BlockMenuRenderingContext } from './types';
|
|
4
|
+
type BlockMenuComponentsProps = BlockMenuRenderingContext & {
|
|
5
|
+
registeredComponents?: RegisterBlockMenuComponent[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Renders the given registered components
|
|
9
|
+
* Returns null if no components are rendered
|
|
10
|
+
*/
|
|
11
|
+
export declare const BlockMenuComponents: ({ registeredComponents, childrenMap, fallbacks, }: BlockMenuComponentsProps) => React.JSX.Element | null;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { RegisterBlockMenuComponent } from '../../blockMenuPluginType';
|
|
3
|
+
import type { BlockMenuFallbacks } from './types';
|
|
4
|
+
type BlockMenuProps = {
|
|
5
|
+
allRegisteredComponents: RegisterBlockMenuComponent[];
|
|
6
|
+
fallbacks?: BlockMenuFallbacks;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* BlockMenuRenderer orchestrates the rendering of the entire block menu hierarchy
|
|
10
|
+
*/
|
|
11
|
+
export declare const BlockMenuRenderer: ({ allRegisteredComponents, fallbacks, }: BlockMenuProps) => React.JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BlockMenuItemComponent, BlockMenuNestedComponent, BlockMenuSectionComponent, RegisterBlockMenuComponent } from '../../blockMenuPluginType';
|
|
2
|
+
/**
|
|
3
|
+
* Fallback components used as defaults when specific components aren't provided
|
|
4
|
+
*/
|
|
5
|
+
export type BlockMenuFallbacks = {
|
|
6
|
+
'block-menu-item': BlockMenuItemComponent;
|
|
7
|
+
'block-menu-nested': BlockMenuNestedComponent;
|
|
8
|
+
'block-menu-section': BlockMenuSectionComponent;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Map of parent keys to their sorted children components
|
|
12
|
+
* Used to efficiently organize and render hierarchical menu structures
|
|
13
|
+
*/
|
|
14
|
+
export type ChildrenMap = Map<string, RegisterBlockMenuComponent[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Props shared across multiple block menu rendering components
|
|
17
|
+
*/
|
|
18
|
+
export type BlockMenuRenderingContext = {
|
|
19
|
+
/**
|
|
20
|
+
* Lookup map for child components organized by parent key
|
|
21
|
+
*/
|
|
22
|
+
childrenMap: ChildrenMap;
|
|
23
|
+
/**
|
|
24
|
+
* Fallback components when specific components aren't registered
|
|
25
|
+
*/
|
|
26
|
+
fallbacks: BlockMenuFallbacks;
|
|
27
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RegisterBlockMenuComponent, RegisterBlockMenuComponentType, RegisterBlockMenuSection } from '../../blockMenuPluginType';
|
|
2
|
+
import type { ChildrenMap } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Gets all top-level sections (those without a parent) sorted by rank
|
|
5
|
+
*
|
|
6
|
+
* @param components All registered block menu components
|
|
7
|
+
* @returns Sorted array of top-level sections
|
|
8
|
+
*/
|
|
9
|
+
export declare const getSortedTopLevelSections: (components: RegisterBlockMenuComponent[]) => RegisterBlockMenuSection[];
|
|
10
|
+
/**
|
|
11
|
+
* Generates a unique key from a key and type
|
|
12
|
+
* Used to lookup children in the childrenMap
|
|
13
|
+
*
|
|
14
|
+
* @param key The component's key
|
|
15
|
+
* @param type The component's type
|
|
16
|
+
* @returns A unique string key combining type and key
|
|
17
|
+
*/
|
|
18
|
+
export declare const getChildrenMapKey: (key: string, type: Omit<RegisterBlockMenuComponentType, "block-menu-item">) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Builds a map of parent keys to their sorted children
|
|
21
|
+
* This enables efficient hierarchical rendering of the menu structure
|
|
22
|
+
*
|
|
23
|
+
* @param components All registered block menu components
|
|
24
|
+
* @returns Map where keys are parent identifiers and values are sorted child components
|
|
25
|
+
*/
|
|
26
|
+
export declare const buildChildrenMap: (components: RegisterBlockMenuComponent[]) => ChildrenMap;
|
|
27
|
+
/**
|
|
28
|
+
* Determines whether a component will render based on its type and children
|
|
29
|
+
*
|
|
30
|
+
* Rules:
|
|
31
|
+
* - An item will not render if has a component that returns null
|
|
32
|
+
* - A nested menu will render if it has at least one registered child component
|
|
33
|
+
* - A section will render if it has at least one registered child component that will render
|
|
34
|
+
*
|
|
35
|
+
* NOTE: This requires invoking each item's component function to check for null return
|
|
36
|
+
*/
|
|
37
|
+
export declare const willComponentRender: (registeredComponent: RegisterBlockMenuComponent, childrenMap: ChildrenMap) => boolean;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { BlockMenuPlugin, RegisterBlockMenuItem } from '../../blockMenuPluginType';
|
|
3
|
+
export declare const useSuggestedItems: (api: ExtractInjectionAPI<BlockMenuPlugin> | undefined) => RegisterBlockMenuItem[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { BlockMenuPlugin } from '../blockMenuPluginType';
|
|
4
|
+
type SuggestedItemsMenuSectionProps = {
|
|
5
|
+
api: ExtractInjectionAPI<BlockMenuPlugin> | undefined;
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export declare const SuggestedItemsMenuSection: React.NamedExoticComponent<SuggestedItemsMenuSectionProps>;
|
|
9
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { BlockMenuPlugin } from '../blockMenuPluginType';
|
|
4
|
-
type
|
|
4
|
+
type SuggestedMenuItemsProps = {
|
|
5
5
|
api: ExtractInjectionAPI<BlockMenuPlugin> | undefined;
|
|
6
6
|
};
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const SuggestedMenuItems: React.NamedExoticComponent<SuggestedMenuItemsProps>;
|
|
8
8
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NextEditorPlugin, OptionalPlugin
|
|
1
|
+
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
3
|
import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls';
|
|
4
4
|
import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
@@ -84,7 +84,7 @@ type BlockMenuNested = {
|
|
|
84
84
|
key: string;
|
|
85
85
|
type: 'block-menu-nested';
|
|
86
86
|
};
|
|
87
|
-
export type BlockMenuNestedComponent = (props
|
|
87
|
+
export type BlockMenuNestedComponent = (props: {
|
|
88
88
|
children: React.ReactNode;
|
|
89
89
|
}) => React.ReactNode;
|
|
90
90
|
export type BlockMenuSectionComponent = (props: {
|
|
@@ -108,4 +108,5 @@ export type RegisterBlockMenuItem = BlockMenuItem & {
|
|
|
108
108
|
parent: Parent<BlockMenuSection>;
|
|
109
109
|
};
|
|
110
110
|
export type RegisterBlockMenuComponent = RegisterBlockMenuNested | RegisterBlockMenuSection | RegisterBlockMenuItem;
|
|
111
|
+
export type RegisterBlockMenuComponentType = RegisterBlockMenuComponent['type'];
|
|
111
112
|
export {};
|
|
@@ -14,6 +14,11 @@ export declare const getTargetNodeTypeNameInContext: (nodeTypeName: NodeTypeName
|
|
|
14
14
|
export declare const expandSelectionToBlockRange: (selection: Selection, schema: Schema) => {
|
|
15
15
|
$from: import("prosemirror-model").ResolvedPos;
|
|
16
16
|
$to: import("prosemirror-model").ResolvedPos;
|
|
17
|
+
range: NodeRange | null;
|
|
18
|
+
} | {
|
|
19
|
+
$from: import("prosemirror-model").ResolvedPos;
|
|
20
|
+
$to: import("prosemirror-model").ResolvedPos;
|
|
21
|
+
range?: undefined;
|
|
17
22
|
};
|
|
18
23
|
export declare const isListType: (node: PMNode, schema: Schema) => boolean;
|
|
19
24
|
/**
|
|
@@ -22,4 +27,10 @@ export declare const isListType: (node: PMNode, schema: Schema) => boolean;
|
|
|
22
27
|
* in containers that don't support nesting, they must be converted.
|
|
23
28
|
*/
|
|
24
29
|
export declare const convertNestedExpandToExpand: (node: PMNode, schema: Schema) => PMNode | null;
|
|
30
|
+
/**
|
|
31
|
+
* Converts an expand to a nestedExpand node.
|
|
32
|
+
* When placing an expand inside another expand, it must become a nestedExpand
|
|
33
|
+
* since expand cannot be a direct child of expand.
|
|
34
|
+
*/
|
|
35
|
+
export declare const convertExpandToNestedExpand: (node: PMNode, schema: Schema) => PMNode | null;
|
|
25
36
|
export declare const getBlockNodesInRange: (range: NodeRange) => PMNode[];
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import type { TransformStep } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps nodes into the target container type.
|
|
4
|
+
* When wrapping into expand, any expand children are converted to nestedExpand
|
|
5
|
+
* since expand cannot be a direct child of expand.
|
|
6
|
+
*/
|
|
2
7
|
export declare const wrapStep: TransformStep;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { RegisterBlockMenuComponent } from '../../blockMenuPluginType';
|
|
3
|
+
import type { BlockMenuRenderingContext } from './types';
|
|
4
|
+
type BlockMenuComponentProps = BlockMenuRenderingContext & {
|
|
5
|
+
registeredComponent: RegisterBlockMenuComponent;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Renders the given registered component based on its type
|
|
9
|
+
*/
|
|
10
|
+
export declare const BlockMenuComponent: ({ registeredComponent, childrenMap, fallbacks, }: BlockMenuComponentProps) => React.JSX.Element | null;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { RegisterBlockMenuComponent } from '../../blockMenuPluginType';
|
|
3
|
+
import type { BlockMenuRenderingContext } from './types';
|
|
4
|
+
type BlockMenuComponentsProps = BlockMenuRenderingContext & {
|
|
5
|
+
registeredComponents?: RegisterBlockMenuComponent[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Renders the given registered components
|
|
9
|
+
* Returns null if no components are rendered
|
|
10
|
+
*/
|
|
11
|
+
export declare const BlockMenuComponents: ({ registeredComponents, childrenMap, fallbacks, }: BlockMenuComponentsProps) => React.JSX.Element | null;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { RegisterBlockMenuComponent } from '../../blockMenuPluginType';
|
|
3
|
+
import type { BlockMenuFallbacks } from './types';
|
|
4
|
+
type BlockMenuProps = {
|
|
5
|
+
allRegisteredComponents: RegisterBlockMenuComponent[];
|
|
6
|
+
fallbacks?: BlockMenuFallbacks;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* BlockMenuRenderer orchestrates the rendering of the entire block menu hierarchy
|
|
10
|
+
*/
|
|
11
|
+
export declare const BlockMenuRenderer: ({ allRegisteredComponents, fallbacks, }: BlockMenuProps) => React.JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BlockMenuItemComponent, BlockMenuNestedComponent, BlockMenuSectionComponent, RegisterBlockMenuComponent } from '../../blockMenuPluginType';
|
|
2
|
+
/**
|
|
3
|
+
* Fallback components used as defaults when specific components aren't provided
|
|
4
|
+
*/
|
|
5
|
+
export type BlockMenuFallbacks = {
|
|
6
|
+
'block-menu-item': BlockMenuItemComponent;
|
|
7
|
+
'block-menu-nested': BlockMenuNestedComponent;
|
|
8
|
+
'block-menu-section': BlockMenuSectionComponent;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Map of parent keys to their sorted children components
|
|
12
|
+
* Used to efficiently organize and render hierarchical menu structures
|
|
13
|
+
*/
|
|
14
|
+
export type ChildrenMap = Map<string, RegisterBlockMenuComponent[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Props shared across multiple block menu rendering components
|
|
17
|
+
*/
|
|
18
|
+
export type BlockMenuRenderingContext = {
|
|
19
|
+
/**
|
|
20
|
+
* Lookup map for child components organized by parent key
|
|
21
|
+
*/
|
|
22
|
+
childrenMap: ChildrenMap;
|
|
23
|
+
/**
|
|
24
|
+
* Fallback components when specific components aren't registered
|
|
25
|
+
*/
|
|
26
|
+
fallbacks: BlockMenuFallbacks;
|
|
27
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RegisterBlockMenuComponent, RegisterBlockMenuComponentType, RegisterBlockMenuSection } from '../../blockMenuPluginType';
|
|
2
|
+
import type { ChildrenMap } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Gets all top-level sections (those without a parent) sorted by rank
|
|
5
|
+
*
|
|
6
|
+
* @param components All registered block menu components
|
|
7
|
+
* @returns Sorted array of top-level sections
|
|
8
|
+
*/
|
|
9
|
+
export declare const getSortedTopLevelSections: (components: RegisterBlockMenuComponent[]) => RegisterBlockMenuSection[];
|
|
10
|
+
/**
|
|
11
|
+
* Generates a unique key from a key and type
|
|
12
|
+
* Used to lookup children in the childrenMap
|
|
13
|
+
*
|
|
14
|
+
* @param key The component's key
|
|
15
|
+
* @param type The component's type
|
|
16
|
+
* @returns A unique string key combining type and key
|
|
17
|
+
*/
|
|
18
|
+
export declare const getChildrenMapKey: (key: string, type: Omit<RegisterBlockMenuComponentType, "block-menu-item">) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Builds a map of parent keys to their sorted children
|
|
21
|
+
* This enables efficient hierarchical rendering of the menu structure
|
|
22
|
+
*
|
|
23
|
+
* @param components All registered block menu components
|
|
24
|
+
* @returns Map where keys are parent identifiers and values are sorted child components
|
|
25
|
+
*/
|
|
26
|
+
export declare const buildChildrenMap: (components: RegisterBlockMenuComponent[]) => ChildrenMap;
|
|
27
|
+
/**
|
|
28
|
+
* Determines whether a component will render based on its type and children
|
|
29
|
+
*
|
|
30
|
+
* Rules:
|
|
31
|
+
* - An item will not render if has a component that returns null
|
|
32
|
+
* - A nested menu will render if it has at least one registered child component
|
|
33
|
+
* - A section will render if it has at least one registered child component that will render
|
|
34
|
+
*
|
|
35
|
+
* NOTE: This requires invoking each item's component function to check for null return
|
|
36
|
+
*/
|
|
37
|
+
export declare const willComponentRender: (registeredComponent: RegisterBlockMenuComponent, childrenMap: ChildrenMap) => boolean;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { BlockMenuPlugin, RegisterBlockMenuItem } from '../../blockMenuPluginType';
|
|
3
|
+
export declare const useSuggestedItems: (api: ExtractInjectionAPI<BlockMenuPlugin> | undefined) => RegisterBlockMenuItem[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { BlockMenuPlugin } from '../blockMenuPluginType';
|
|
4
|
+
type SuggestedItemsMenuSectionProps = {
|
|
5
|
+
api: ExtractInjectionAPI<BlockMenuPlugin> | undefined;
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export declare const SuggestedItemsMenuSection: React.NamedExoticComponent<SuggestedItemsMenuSectionProps>;
|
|
9
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { BlockMenuPlugin } from '../blockMenuPluginType';
|
|
4
|
-
type
|
|
4
|
+
type SuggestedMenuItemsProps = {
|
|
5
5
|
api: ExtractInjectionAPI<BlockMenuPlugin> | undefined;
|
|
6
6
|
};
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const SuggestedMenuItems: React.NamedExoticComponent<SuggestedMenuItemsProps>;
|
|
8
8
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-menu",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.12",
|
|
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": "^15.
|
|
47
|
+
"@atlaskit/tmp-editor-statsig": "^15.11.0",
|
|
48
48
|
"@atlaskit/tokens": "^8.5.0",
|
|
49
49
|
"@babel/runtime": "^7.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@atlaskit/editor-common": "^110.
|
|
52
|
+
"@atlaskit/editor-common": "^110.44.0",
|
|
53
53
|
"react": "^18.2.0",
|
|
54
54
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
55
55
|
},
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.BlockMenuRenderer = void 0;
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
12
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
13
|
-
var NoOp = function NoOp() {
|
|
14
|
-
return null;
|
|
15
|
-
};
|
|
16
|
-
var isNonNestedMenuSection = function isNonNestedMenuSection(component) {
|
|
17
|
-
return component.type === 'block-menu-section' && !('parent' in component);
|
|
18
|
-
};
|
|
19
|
-
var isMenuItem = function isMenuItem(component) {
|
|
20
|
-
return component.type === 'block-menu-item';
|
|
21
|
-
};
|
|
22
|
-
var isNestedMenu = function isNestedMenu(component) {
|
|
23
|
-
return component.type === 'block-menu-nested';
|
|
24
|
-
};
|
|
25
|
-
var isNestedMenuSection = function isNestedMenuSection(component) {
|
|
26
|
-
return 'parent' in component && component.parent !== undefined && component.parent.type === 'block-menu-nested';
|
|
27
|
-
};
|
|
28
|
-
var getSortedChildren = function getSortedChildren(components, parentKey) {
|
|
29
|
-
return components.filter(function (component) {
|
|
30
|
-
return 'parent' in component && component.parent !== undefined && component.parent.key === parentKey;
|
|
31
|
-
}).sort(function (a, b) {
|
|
32
|
-
return (a.parent.rank || 0) - (b.parent.rank || 0);
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
var getSortedNestedSections = function getSortedNestedSections(components, parentKey) {
|
|
36
|
-
var nestedMenuSections = components.filter(isNestedMenuSection);
|
|
37
|
-
var nestedMenuSectionsWithParent = nestedMenuSections.filter(function (section) {
|
|
38
|
-
return section.parent !== undefined;
|
|
39
|
-
});
|
|
40
|
-
return getSortedChildren(nestedMenuSectionsWithParent, parentKey);
|
|
41
|
-
};
|
|
42
|
-
var getSortedNonNestedSections = function getSortedNonNestedSections(components) {
|
|
43
|
-
return components.filter(isNonNestedMenuSection).sort(function (a, b) {
|
|
44
|
-
return (a.rank || 0) - (b.rank || 0);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
var BlockMenuRenderer = exports.BlockMenuRenderer = function BlockMenuRenderer(_ref) {
|
|
48
|
-
var components = _ref.components,
|
|
49
|
-
fallbacks = _ref.fallbacks;
|
|
50
|
-
var menuSections = getSortedNonNestedSections(components);
|
|
51
|
-
var menuItems = components.filter(isMenuItem);
|
|
52
|
-
var nestedMenus = components.filter(isNestedMenu);
|
|
53
|
-
var renderMenu = function renderMenu() {
|
|
54
|
-
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, menuSections.map(function (section) {
|
|
55
|
-
// Get all items for the current section, including nested menus, and sort them by rank
|
|
56
|
-
var currentSectionItemsSorted = getSortedChildren([].concat((0, _toConsumableArray2.default)(menuItems), (0, _toConsumableArray2.default)(nestedMenus)), section.key);
|
|
57
|
-
if (currentSectionItemsSorted.length === 0) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// iterate over the current section items, if it is nested menu, get their children, sort them
|
|
62
|
-
// if they are menu items, just render as they are sorted above
|
|
63
|
-
var getChildrenWithNestedItems = function getChildrenWithNestedItems(items) {
|
|
64
|
-
return items.map(function (item) {
|
|
65
|
-
if (isNestedMenu(item)) {
|
|
66
|
-
var sortedNestedSections = getSortedNestedSections(components, item.key);
|
|
67
|
-
var sections = sortedNestedSections.map(function (section) {
|
|
68
|
-
var sortedNestedMenuItems = getSortedChildren(menuItems, section.key);
|
|
69
|
-
if (sortedNestedMenuItems.length === 0) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
var NestedSection = section.component || fallbacks.section || NoOp;
|
|
73
|
-
return /*#__PURE__*/_react.default.createElement(NestedSection, {
|
|
74
|
-
key: section.key
|
|
75
|
-
}, sortedNestedMenuItems.map(function (nestedItem) {
|
|
76
|
-
var NestedMenuItemComponent = nestedItem.component || fallbacks.item || NoOp;
|
|
77
|
-
return /*#__PURE__*/_react.default.createElement(NestedMenuItemComponent, {
|
|
78
|
-
key: nestedItem.key
|
|
79
|
-
});
|
|
80
|
-
}));
|
|
81
|
-
});
|
|
82
|
-
var NestedMenuComponent = item.component || fallbacks.nestedMenu || NoOp;
|
|
83
|
-
return /*#__PURE__*/_react.default.createElement(NestedMenuComponent, {
|
|
84
|
-
key: item.key
|
|
85
|
-
}, sections);
|
|
86
|
-
} else {
|
|
87
|
-
var ItemComponent = item.component || fallbacks.item || NoOp;
|
|
88
|
-
return /*#__PURE__*/_react.default.createElement(ItemComponent, {
|
|
89
|
-
key: item.key
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
var children = getChildrenWithNestedItems(currentSectionItemsSorted);
|
|
95
|
-
var SectionComponent = section.component || fallbacks.section || NoOp;
|
|
96
|
-
return /*#__PURE__*/_react.default.createElement(SectionComponent, {
|
|
97
|
-
key: section.key
|
|
98
|
-
}, children);
|
|
99
|
-
}));
|
|
100
|
-
};
|
|
101
|
-
return /*#__PURE__*/_react.default.createElement(_uiMenu.ArrowKeyNavigationProvider, {
|
|
102
|
-
type: _uiMenu.ArrowKeyNavigationType.MENU
|
|
103
|
-
}, renderMenu());
|
|
104
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.SuggestedItemsRenderer = void 0;
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
10
|
-
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
11
|
-
var _utils = require("../editor-commands/transform-node-utils/utils");
|
|
12
|
-
var _suggestedItemsRank = require("./utils/suggested-items-rank");
|
|
13
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
14
|
-
var SuggestedItemsRenderer = exports.SuggestedItemsRenderer = /*#__PURE__*/_react.default.memo(function (_ref) {
|
|
15
|
-
var _api$blockMenu;
|
|
16
|
-
var api = _ref.api;
|
|
17
|
-
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (states) {
|
|
18
|
-
var _states$blockControls;
|
|
19
|
-
return {
|
|
20
|
-
preservedSelection: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.preservedSelection
|
|
21
|
-
};
|
|
22
|
-
}),
|
|
23
|
-
preservedSelection = _useSharedPluginState.preservedSelection;
|
|
24
|
-
var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
|
|
25
|
-
var menuItemsMap = (0, _react.useMemo)(function () {
|
|
26
|
-
if (!blockMenuComponents) {
|
|
27
|
-
return new Map();
|
|
28
|
-
}
|
|
29
|
-
return new Map(blockMenuComponents.filter(function (c) {
|
|
30
|
-
return c.type === 'block-menu-item';
|
|
31
|
-
}).map(function (item) {
|
|
32
|
-
return [item.key, item];
|
|
33
|
-
}));
|
|
34
|
-
}, [blockMenuComponents]);
|
|
35
|
-
var suggestedItems = (0, _react.useMemo)(function () {
|
|
36
|
-
if (!preservedSelection || menuItemsMap.size === 0) {
|
|
37
|
-
return [];
|
|
38
|
-
}
|
|
39
|
-
var selectedNode = (0, _utils.getSelectedNode)(preservedSelection);
|
|
40
|
-
if (!selectedNode) {
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
var nodeTypeName = selectedNode.node.type.name;
|
|
44
|
-
var sortedKeys = (0, _suggestedItemsRank.getSortedSuggestedItems)(nodeTypeName);
|
|
45
|
-
return sortedKeys.map(function (key) {
|
|
46
|
-
return menuItemsMap.get(key);
|
|
47
|
-
}).filter(function (item) {
|
|
48
|
-
return item !== undefined;
|
|
49
|
-
});
|
|
50
|
-
}, [menuItemsMap, preservedSelection]);
|
|
51
|
-
if (suggestedItems.length === 0) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
55
|
-
title: "Suggested"
|
|
56
|
-
}, suggestedItems.map(function (item) {
|
|
57
|
-
var ItemComponent = item.component;
|
|
58
|
-
return ItemComponent ? /*#__PURE__*/_react.default.createElement(ItemComponent, {
|
|
59
|
-
key: item.key
|
|
60
|
-
}) : null;
|
|
61
|
-
}));
|
|
62
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import React, { Fragment } from 'react';
|
|
2
|
-
import { ArrowKeyNavigationProvider, ArrowKeyNavigationType } from '@atlaskit/editor-common/ui-menu';
|
|
3
|
-
const NoOp = () => null;
|
|
4
|
-
const isNonNestedMenuSection = component => {
|
|
5
|
-
return component.type === 'block-menu-section' && !('parent' in component);
|
|
6
|
-
};
|
|
7
|
-
const isMenuItem = component => {
|
|
8
|
-
return component.type === 'block-menu-item';
|
|
9
|
-
};
|
|
10
|
-
const isNestedMenu = component => {
|
|
11
|
-
return component.type === 'block-menu-nested';
|
|
12
|
-
};
|
|
13
|
-
const isNestedMenuSection = component => {
|
|
14
|
-
return 'parent' in component && component.parent !== undefined && component.parent.type === 'block-menu-nested';
|
|
15
|
-
};
|
|
16
|
-
const getSortedChildren = (components, parentKey) => components.filter(component => 'parent' in component && component.parent !== undefined && component.parent.key === parentKey).sort((a, b) => (a.parent.rank || 0) - (b.parent.rank || 0));
|
|
17
|
-
const getSortedNestedSections = (components, parentKey) => {
|
|
18
|
-
const nestedMenuSections = components.filter(isNestedMenuSection);
|
|
19
|
-
const nestedMenuSectionsWithParent = nestedMenuSections.filter(section => section.parent !== undefined);
|
|
20
|
-
return getSortedChildren(nestedMenuSectionsWithParent, parentKey);
|
|
21
|
-
};
|
|
22
|
-
const getSortedNonNestedSections = components => {
|
|
23
|
-
return components.filter(isNonNestedMenuSection).sort((a, b) => (a.rank || 0) - (b.rank || 0));
|
|
24
|
-
};
|
|
25
|
-
export const BlockMenuRenderer = ({
|
|
26
|
-
components,
|
|
27
|
-
fallbacks
|
|
28
|
-
}) => {
|
|
29
|
-
const menuSections = getSortedNonNestedSections(components);
|
|
30
|
-
const menuItems = components.filter(isMenuItem);
|
|
31
|
-
const nestedMenus = components.filter(isNestedMenu);
|
|
32
|
-
const renderMenu = () => {
|
|
33
|
-
return /*#__PURE__*/React.createElement(Fragment, null, menuSections.map(section => {
|
|
34
|
-
// Get all items for the current section, including nested menus, and sort them by rank
|
|
35
|
-
const currentSectionItemsSorted = getSortedChildren([...menuItems, ...nestedMenus], section.key);
|
|
36
|
-
if (currentSectionItemsSorted.length === 0) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// iterate over the current section items, if it is nested menu, get their children, sort them
|
|
41
|
-
// if they are menu items, just render as they are sorted above
|
|
42
|
-
const getChildrenWithNestedItems = items => {
|
|
43
|
-
return items.map(item => {
|
|
44
|
-
if (isNestedMenu(item)) {
|
|
45
|
-
const sortedNestedSections = getSortedNestedSections(components, item.key);
|
|
46
|
-
const sections = sortedNestedSections.map(section => {
|
|
47
|
-
const sortedNestedMenuItems = getSortedChildren(menuItems, section.key);
|
|
48
|
-
if (sortedNestedMenuItems.length === 0) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
const NestedSection = section.component || fallbacks.section || NoOp;
|
|
52
|
-
return /*#__PURE__*/React.createElement(NestedSection, {
|
|
53
|
-
key: section.key
|
|
54
|
-
}, sortedNestedMenuItems.map(nestedItem => {
|
|
55
|
-
const NestedMenuItemComponent = nestedItem.component || fallbacks.item || NoOp;
|
|
56
|
-
return /*#__PURE__*/React.createElement(NestedMenuItemComponent, {
|
|
57
|
-
key: nestedItem.key
|
|
58
|
-
});
|
|
59
|
-
}));
|
|
60
|
-
});
|
|
61
|
-
const NestedMenuComponent = item.component || fallbacks.nestedMenu || NoOp;
|
|
62
|
-
return /*#__PURE__*/React.createElement(NestedMenuComponent, {
|
|
63
|
-
key: item.key
|
|
64
|
-
}, sections);
|
|
65
|
-
} else {
|
|
66
|
-
const ItemComponent = item.component || fallbacks.item || NoOp;
|
|
67
|
-
return /*#__PURE__*/React.createElement(ItemComponent, {
|
|
68
|
-
key: item.key
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
const children = getChildrenWithNestedItems(currentSectionItemsSorted);
|
|
74
|
-
const SectionComponent = section.component || fallbacks.section || NoOp;
|
|
75
|
-
return /*#__PURE__*/React.createElement(SectionComponent, {
|
|
76
|
-
key: section.key
|
|
77
|
-
}, children);
|
|
78
|
-
}));
|
|
79
|
-
};
|
|
80
|
-
return /*#__PURE__*/React.createElement(ArrowKeyNavigationProvider, {
|
|
81
|
-
type: ArrowKeyNavigationType.MENU
|
|
82
|
-
}, renderMenu());
|
|
83
|
-
};
|