@atlaskit/editor-plugin-block-menu 5.2.11 → 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.
Files changed (42) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/ui/block-menu-renderer/BlockMenuComponent.js +37 -0
  3. package/dist/cjs/ui/block-menu-renderer/BlockMenuComponents.js +29 -0
  4. package/dist/cjs/ui/block-menu-renderer/BlockMenuRenderer.js +33 -0
  5. package/dist/cjs/ui/block-menu-renderer/fallbacks.js +32 -0
  6. package/dist/cjs/ui/block-menu-renderer/types.js +5 -0
  7. package/dist/cjs/ui/block-menu-renderer/utils.js +127 -0
  8. package/dist/cjs/ui/block-menu.js +7 -20
  9. package/dist/es2019/ui/block-menu-renderer/BlockMenuComponent.js +31 -0
  10. package/dist/es2019/ui/block-menu-renderer/BlockMenuComponents.js +21 -0
  11. package/dist/es2019/ui/block-menu-renderer/BlockMenuRenderer.js +24 -0
  12. package/dist/es2019/ui/block-menu-renderer/fallbacks.js +21 -0
  13. package/dist/es2019/ui/block-menu-renderer/types.js +1 -0
  14. package/dist/es2019/ui/block-menu-renderer/utils.js +93 -0
  15. package/dist/es2019/ui/block-menu.js +6 -13
  16. package/dist/esm/ui/block-menu-renderer/BlockMenuComponent.js +30 -0
  17. package/dist/esm/ui/block-menu-renderer/BlockMenuComponents.js +22 -0
  18. package/dist/esm/ui/block-menu-renderer/BlockMenuRenderer.js +25 -0
  19. package/dist/esm/ui/block-menu-renderer/fallbacks.js +25 -0
  20. package/dist/esm/ui/block-menu-renderer/types.js +1 -0
  21. package/dist/esm/ui/block-menu-renderer/utils.js +121 -0
  22. package/dist/esm/ui/block-menu.js +6 -19
  23. package/dist/types/blockMenuPluginType.d.ts +3 -2
  24. package/dist/types/ui/block-menu-renderer/BlockMenuComponent.d.ts +11 -0
  25. package/dist/types/ui/block-menu-renderer/BlockMenuComponents.d.ts +12 -0
  26. package/dist/types/ui/block-menu-renderer/BlockMenuRenderer.d.ts +12 -0
  27. package/dist/types/ui/block-menu-renderer/fallbacks.d.ts +2 -0
  28. package/dist/types/ui/block-menu-renderer/types.d.ts +27 -0
  29. package/dist/types/ui/block-menu-renderer/utils.d.ts +37 -0
  30. package/dist/types-ts4.5/blockMenuPluginType.d.ts +3 -2
  31. package/dist/types-ts4.5/ui/block-menu-renderer/BlockMenuComponent.d.ts +11 -0
  32. package/dist/types-ts4.5/ui/block-menu-renderer/BlockMenuComponents.d.ts +12 -0
  33. package/dist/types-ts4.5/ui/block-menu-renderer/BlockMenuRenderer.d.ts +12 -0
  34. package/dist/types-ts4.5/ui/block-menu-renderer/fallbacks.d.ts +2 -0
  35. package/dist/types-ts4.5/ui/block-menu-renderer/types.d.ts +27 -0
  36. package/dist/types-ts4.5/ui/block-menu-renderer/utils.d.ts +37 -0
  37. package/package.json +1 -1
  38. package/dist/cjs/ui/block-menu-renderer.js +0 -104
  39. package/dist/es2019/ui/block-menu-renderer.js +0 -83
  40. package/dist/esm/ui/block-menu-renderer.js +0 -95
  41. package/dist/types/ui/block-menu-renderer.d.ts +0 -18
  42. package/dist/types-ts4.5/ui/block-menu-renderer.d.ts +0 -18
@@ -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
- };
@@ -1,95 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import React, { Fragment } from 'react';
3
- import { ArrowKeyNavigationProvider, ArrowKeyNavigationType } from '@atlaskit/editor-common/ui-menu';
4
- var NoOp = function NoOp() {
5
- return null;
6
- };
7
- var isNonNestedMenuSection = function isNonNestedMenuSection(component) {
8
- return component.type === 'block-menu-section' && !('parent' in component);
9
- };
10
- var isMenuItem = function isMenuItem(component) {
11
- return component.type === 'block-menu-item';
12
- };
13
- var isNestedMenu = function isNestedMenu(component) {
14
- return component.type === 'block-menu-nested';
15
- };
16
- var isNestedMenuSection = function isNestedMenuSection(component) {
17
- return 'parent' in component && component.parent !== undefined && component.parent.type === 'block-menu-nested';
18
- };
19
- var getSortedChildren = function getSortedChildren(components, parentKey) {
20
- return components.filter(function (component) {
21
- return 'parent' in component && component.parent !== undefined && component.parent.key === parentKey;
22
- }).sort(function (a, b) {
23
- return (a.parent.rank || 0) - (b.parent.rank || 0);
24
- });
25
- };
26
- var getSortedNestedSections = function getSortedNestedSections(components, parentKey) {
27
- var nestedMenuSections = components.filter(isNestedMenuSection);
28
- var nestedMenuSectionsWithParent = nestedMenuSections.filter(function (section) {
29
- return section.parent !== undefined;
30
- });
31
- return getSortedChildren(nestedMenuSectionsWithParent, parentKey);
32
- };
33
- var getSortedNonNestedSections = function getSortedNonNestedSections(components) {
34
- return components.filter(isNonNestedMenuSection).sort(function (a, b) {
35
- return (a.rank || 0) - (b.rank || 0);
36
- });
37
- };
38
- export var BlockMenuRenderer = function BlockMenuRenderer(_ref) {
39
- var components = _ref.components,
40
- fallbacks = _ref.fallbacks;
41
- var menuSections = getSortedNonNestedSections(components);
42
- var menuItems = components.filter(isMenuItem);
43
- var nestedMenus = components.filter(isNestedMenu);
44
- var renderMenu = function renderMenu() {
45
- return /*#__PURE__*/React.createElement(Fragment, null, menuSections.map(function (section) {
46
- // Get all items for the current section, including nested menus, and sort them by rank
47
- var currentSectionItemsSorted = getSortedChildren([].concat(_toConsumableArray(menuItems), _toConsumableArray(nestedMenus)), section.key);
48
- if (currentSectionItemsSorted.length === 0) {
49
- return null;
50
- }
51
-
52
- // iterate over the current section items, if it is nested menu, get their children, sort them
53
- // if they are menu items, just render as they are sorted above
54
- var getChildrenWithNestedItems = function getChildrenWithNestedItems(items) {
55
- return items.map(function (item) {
56
- if (isNestedMenu(item)) {
57
- var sortedNestedSections = getSortedNestedSections(components, item.key);
58
- var sections = sortedNestedSections.map(function (section) {
59
- var sortedNestedMenuItems = getSortedChildren(menuItems, section.key);
60
- if (sortedNestedMenuItems.length === 0) {
61
- return null;
62
- }
63
- var NestedSection = section.component || fallbacks.section || NoOp;
64
- return /*#__PURE__*/React.createElement(NestedSection, {
65
- key: section.key
66
- }, sortedNestedMenuItems.map(function (nestedItem) {
67
- var NestedMenuItemComponent = nestedItem.component || fallbacks.item || NoOp;
68
- return /*#__PURE__*/React.createElement(NestedMenuItemComponent, {
69
- key: nestedItem.key
70
- });
71
- }));
72
- });
73
- var NestedMenuComponent = item.component || fallbacks.nestedMenu || NoOp;
74
- return /*#__PURE__*/React.createElement(NestedMenuComponent, {
75
- key: item.key
76
- }, sections);
77
- } else {
78
- var ItemComponent = item.component || fallbacks.item || NoOp;
79
- return /*#__PURE__*/React.createElement(ItemComponent, {
80
- key: item.key
81
- });
82
- }
83
- });
84
- };
85
- var children = getChildrenWithNestedItems(currentSectionItemsSorted);
86
- var SectionComponent = section.component || fallbacks.section || NoOp;
87
- return /*#__PURE__*/React.createElement(SectionComponent, {
88
- key: section.key
89
- }, children);
90
- }));
91
- };
92
- return /*#__PURE__*/React.createElement(ArrowKeyNavigationProvider, {
93
- type: ArrowKeyNavigationType.MENU
94
- }, renderMenu());
95
- };
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
- import type { RegisterBlockMenuComponent, BlockMenuNestedComponent, BlockMenuSectionComponent, BlockMenuItemComponent } from '../blockMenuPluginType';
3
- type BlockMenuProps = {
4
- /**
5
- * Every registered block menu component
6
- */
7
- components: RegisterBlockMenuComponent[];
8
- /**
9
- * Fallback components used in rendering
10
- */
11
- fallbacks: {
12
- item: BlockMenuItemComponent;
13
- nestedMenu: BlockMenuNestedComponent;
14
- section: BlockMenuSectionComponent;
15
- };
16
- };
17
- export declare const BlockMenuRenderer: ({ components, fallbacks }: BlockMenuProps) => React.JSX.Element;
18
- export {};
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
- import type { RegisterBlockMenuComponent, BlockMenuNestedComponent, BlockMenuSectionComponent, BlockMenuItemComponent } from '../blockMenuPluginType';
3
- type BlockMenuProps = {
4
- /**
5
- * Every registered block menu component
6
- */
7
- components: RegisterBlockMenuComponent[];
8
- /**
9
- * Fallback components used in rendering
10
- */
11
- fallbacks: {
12
- item: BlockMenuItemComponent;
13
- nestedMenu: BlockMenuNestedComponent;
14
- section: BlockMenuSectionComponent;
15
- };
16
- };
17
- export declare const BlockMenuRenderer: ({ components, fallbacks }: BlockMenuProps) => React.JSX.Element;
18
- export {};