@atlaskit/editor-toolbar-model 0.2.2 → 0.2.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.
- package/CHANGELOG.md +12 -1
- package/dist/cjs/ui/toolbar-model-renderer/ToolbarRendererNew.js +95 -0
- package/dist/cjs/ui/toolbar-model-renderer/ToolbarRendererOld.js +180 -0
- package/dist/cjs/ui/toolbar-model-renderer/common.js +26 -0
- package/dist/cjs/ui/toolbar-model-renderer/index.js +14 -171
- package/dist/cjs/ui/toolbar-model-renderer/types.js +5 -0
- package/dist/es2019/ui/toolbar-model-renderer/ToolbarRendererNew.js +83 -0
- package/dist/es2019/ui/toolbar-model-renderer/ToolbarRendererOld.js +162 -0
- package/dist/es2019/ui/toolbar-model-renderer/common.js +8 -0
- package/dist/es2019/ui/toolbar-model-renderer/index.js +14 -157
- package/dist/es2019/ui/toolbar-model-renderer/types.js +1 -0
- package/dist/esm/ui/toolbar-model-renderer/ToolbarRendererNew.js +88 -0
- package/dist/esm/ui/toolbar-model-renderer/ToolbarRendererOld.js +173 -0
- package/dist/esm/ui/toolbar-model-renderer/common.js +20 -0
- package/dist/esm/ui/toolbar-model-renderer/index.js +14 -171
- package/dist/esm/ui/toolbar-model-renderer/types.js +1 -0
- package/dist/types/ui/toolbar-model-renderer/ToolbarRendererNew.d.ts +3 -0
- package/dist/types/ui/toolbar-model-renderer/ToolbarRendererOld.d.ts +3 -0
- package/dist/types/ui/toolbar-model-renderer/common.d.ts +9 -0
- package/dist/types/ui/toolbar-model-renderer/index.d.ts +1 -20
- package/dist/types/ui/toolbar-model-renderer/types.d.ts +19 -0
- package/dist/types-ts4.5/ui/toolbar-model-renderer/ToolbarRendererNew.d.ts +3 -0
- package/dist/types-ts4.5/ui/toolbar-model-renderer/ToolbarRendererOld.d.ts +3 -0
- package/dist/types-ts4.5/ui/toolbar-model-renderer/common.d.ts +9 -0
- package/dist/types-ts4.5/ui/toolbar-model-renderer/index.d.ts +1 -20
- package/dist/types-ts4.5/ui/toolbar-model-renderer/types.d.ts +19 -0
- package/package.json +12 -6
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { isSection, NoOp } from './common';
|
|
3
|
+
const isGroup = component => {
|
|
4
|
+
return component.type === 'group';
|
|
5
|
+
};
|
|
6
|
+
const isToolbarItem = component => {
|
|
7
|
+
return component.type === 'button' || component.type === 'menu';
|
|
8
|
+
};
|
|
9
|
+
const isToolbarMenuSection = component => {
|
|
10
|
+
return component.type === 'menu-section';
|
|
11
|
+
};
|
|
12
|
+
const isToolbarMenuItem = component => {
|
|
13
|
+
return component.type === 'menu-item' || component.type === 'menu-section';
|
|
14
|
+
};
|
|
15
|
+
const isToolbarMenuItemOrNestedMenu = component => {
|
|
16
|
+
return component.type === 'menu-item' || component.type === 'menu-section' || component.type === 'nested-menu';
|
|
17
|
+
};
|
|
18
|
+
const getSortedChildren = (components, parentKey) => components.filter(component => component.parents.some(parent => parent.key === parentKey)).sort((a, b) => {
|
|
19
|
+
var _a$parents$find, _b$parents$find;
|
|
20
|
+
return (((_a$parents$find = a.parents.find(p => p.key === parentKey)) === null || _a$parents$find === void 0 ? void 0 : _a$parents$find.rank) || 0) - (((_b$parents$find = b.parents.find(p => p.key === parentKey)) === null || _b$parents$find === void 0 ? void 0 : _b$parents$find.rank) || 0);
|
|
21
|
+
});
|
|
22
|
+
export const ToolbarModelRenderer = ({
|
|
23
|
+
toolbar,
|
|
24
|
+
components,
|
|
25
|
+
fallbacks
|
|
26
|
+
}) => {
|
|
27
|
+
const sections = getSortedChildren(components.filter(isSection), toolbar.key);
|
|
28
|
+
const groups = components.filter(isGroup);
|
|
29
|
+
const toolbarItems = components.filter(isToolbarItem);
|
|
30
|
+
const menuSections = components.filter(isToolbarMenuSection);
|
|
31
|
+
const menuItems = components.filter(isToolbarMenuItem);
|
|
32
|
+
const menuItemsAndNestedMenus = components.filter(isToolbarMenuItemOrNestedMenu);
|
|
33
|
+
const renderToolbarItem = ({
|
|
34
|
+
item,
|
|
35
|
+
index,
|
|
36
|
+
parents
|
|
37
|
+
}) => {
|
|
38
|
+
if (item.type === 'menu') {
|
|
39
|
+
const menuComponents = getSortedChildren(menuSections, item.key);
|
|
40
|
+
if (menuComponents.length === 0) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const Menu = item.component || NoOp;
|
|
44
|
+
return /*#__PURE__*/React.createElement(Menu, {
|
|
45
|
+
key: item.key,
|
|
46
|
+
parents: parents
|
|
47
|
+
}, menuComponents.map(menuSection => {
|
|
48
|
+
const menuItemsInSection = getSortedChildren(menuItemsAndNestedMenus, menuSection.key);
|
|
49
|
+
const MenuSection = menuSection.component || fallbacks.menuSection;
|
|
50
|
+
return /*#__PURE__*/React.createElement(MenuSection, {
|
|
51
|
+
key: menuSection.key,
|
|
52
|
+
parents: [...parents, {
|
|
53
|
+
key: item.key,
|
|
54
|
+
type: item.type
|
|
55
|
+
}]
|
|
56
|
+
}, menuItemsInSection.map(menuItem => {
|
|
57
|
+
if (menuItem.type === 'nested-menu') {
|
|
58
|
+
const nestedMenuComponents = getSortedChildren(menuSections, menuItem.key);
|
|
59
|
+
const NestedMenu = menuItem.component;
|
|
60
|
+
return /*#__PURE__*/React.createElement(NestedMenu, {
|
|
61
|
+
key: menuItem.key,
|
|
62
|
+
parents: [...parents, {
|
|
63
|
+
key: item.key,
|
|
64
|
+
type: item.type
|
|
65
|
+
}, {
|
|
66
|
+
key: menuSection.key,
|
|
67
|
+
type: menuSection.type
|
|
68
|
+
}]
|
|
69
|
+
}, nestedMenuComponents.map(nestedMenuSection => {
|
|
70
|
+
const menuItemsInNestedMenuSection = getSortedChildren(menuItems, nestedMenuSection.key);
|
|
71
|
+
const NestedMenuSection = nestedMenuSection.component || fallbacks.menuSection;
|
|
72
|
+
return /*#__PURE__*/React.createElement(NestedMenuSection, {
|
|
73
|
+
key: nestedMenuSection.key,
|
|
74
|
+
parents: [...parents, {
|
|
75
|
+
key: item.key,
|
|
76
|
+
type: item.type
|
|
77
|
+
}, {
|
|
78
|
+
key: menuSection.key,
|
|
79
|
+
type: menuSection.type
|
|
80
|
+
}, {
|
|
81
|
+
key: menuItem.key,
|
|
82
|
+
type: menuItem.type
|
|
83
|
+
}]
|
|
84
|
+
}, menuItemsInNestedMenuSection.map(nestedMenuItem => {
|
|
85
|
+
const NestedMenuItem = nestedMenuItem.component || NoOp;
|
|
86
|
+
return /*#__PURE__*/React.createElement(NestedMenuItem, {
|
|
87
|
+
key: nestedMenuItem.key,
|
|
88
|
+
parents: [...parents, {
|
|
89
|
+
key: item.key,
|
|
90
|
+
type: item.type
|
|
91
|
+
}, {
|
|
92
|
+
key: menuSection.key,
|
|
93
|
+
type: menuSection.type
|
|
94
|
+
}, {
|
|
95
|
+
key: menuItem.key,
|
|
96
|
+
type: menuItem.type
|
|
97
|
+
}, {
|
|
98
|
+
key: nestedMenuSection.key,
|
|
99
|
+
type: nestedMenuSection.type
|
|
100
|
+
}]
|
|
101
|
+
});
|
|
102
|
+
}));
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
const MenuItem = menuItem.component || NoOp;
|
|
106
|
+
return /*#__PURE__*/React.createElement(MenuItem, {
|
|
107
|
+
key: menuItem.key,
|
|
108
|
+
parents: [...parents, {
|
|
109
|
+
key: item.key,
|
|
110
|
+
type: item.type
|
|
111
|
+
}, {
|
|
112
|
+
key: menuSection.key,
|
|
113
|
+
type: menuSection.type
|
|
114
|
+
}]
|
|
115
|
+
});
|
|
116
|
+
}));
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
const Button = item.component || NoOp;
|
|
120
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
121
|
+
key: item.key,
|
|
122
|
+
parents: parents
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const renderGroup = (group, parents) => {
|
|
126
|
+
const groupItems = getSortedChildren(toolbarItems, group.key);
|
|
127
|
+
if (groupItems.length === 0) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const Group = group.component || fallbacks.group;
|
|
131
|
+
return /*#__PURE__*/React.createElement(Group, {
|
|
132
|
+
key: group.key,
|
|
133
|
+
parents: parents
|
|
134
|
+
}, groupItems.map((item, index) => {
|
|
135
|
+
return renderToolbarItem({
|
|
136
|
+
item,
|
|
137
|
+
index,
|
|
138
|
+
parents: [...parents, {
|
|
139
|
+
key: group.key,
|
|
140
|
+
type: group.type
|
|
141
|
+
}]
|
|
142
|
+
});
|
|
143
|
+
}));
|
|
144
|
+
};
|
|
145
|
+
const renderSection = section => {
|
|
146
|
+
const sectionGroups = getSortedChildren(groups, section.key);
|
|
147
|
+
const Section = section.component || fallbacks.section;
|
|
148
|
+
const parents = [{
|
|
149
|
+
key: toolbar.key,
|
|
150
|
+
type: toolbar.type
|
|
151
|
+
}];
|
|
152
|
+
return /*#__PURE__*/React.createElement(Section, {
|
|
153
|
+
key: section.key,
|
|
154
|
+
parents: parents
|
|
155
|
+
}, sectionGroups.map(group => renderGroup(group, [...parents, {
|
|
156
|
+
key: section.key,
|
|
157
|
+
type: section.type
|
|
158
|
+
}])));
|
|
159
|
+
};
|
|
160
|
+
const ToolbarComponent = toolbar.component || NoOp;
|
|
161
|
+
return /*#__PURE__*/React.createElement(ToolbarComponent, null, sections.map(renderSection));
|
|
162
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const getSortedChildren = (components, parentKey) => components.filter(component => component.parents.some(parent => parent.key === parentKey)).sort((a, b) => {
|
|
2
|
+
var _a$parents$find, _b$parents$find;
|
|
3
|
+
return (((_a$parents$find = a.parents.find(p => p.key === parentKey)) === null || _a$parents$find === void 0 ? void 0 : _a$parents$find.rank) || 0) - (((_b$parents$find = b.parents.find(p => p.key === parentKey)) === null || _b$parents$find === void 0 ? void 0 : _b$parents$find.rank) || 0);
|
|
4
|
+
});
|
|
5
|
+
export const NoOp = props => null;
|
|
6
|
+
export const isSection = component => {
|
|
7
|
+
return component.type === 'section';
|
|
8
|
+
};
|
|
@@ -1,165 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
const isGroup = component => {
|
|
7
|
-
return component.type === 'group';
|
|
8
|
-
};
|
|
9
|
-
const isToolbarItem = component => {
|
|
10
|
-
return component.type === 'button' || component.type === 'menu';
|
|
11
|
-
};
|
|
12
|
-
const isToolbarMenuSection = component => {
|
|
13
|
-
return component.type === 'menu-section';
|
|
14
|
-
};
|
|
15
|
-
const isToolbarMenuItem = component => {
|
|
16
|
-
return component.type === 'menu-item' || component.type === 'menu-section';
|
|
17
|
-
};
|
|
18
|
-
const isToolbarMenuItemOrNestedMenu = component => {
|
|
19
|
-
return component.type === 'menu-item' || component.type === 'menu-section' || component.type === 'nested-menu';
|
|
20
|
-
};
|
|
21
|
-
const getSortedChildren = (components, parentKey) => components.filter(component => component.parents.some(parent => parent.key === parentKey)).sort((a, b) => {
|
|
22
|
-
var _a$parents$find, _b$parents$find;
|
|
23
|
-
return (((_a$parents$find = a.parents.find(p => p.key === parentKey)) === null || _a$parents$find === void 0 ? void 0 : _a$parents$find.rank) || 0) - (((_b$parents$find = b.parents.find(p => p.key === parentKey)) === null || _b$parents$find === void 0 ? void 0 : _b$parents$find.rank) || 0);
|
|
24
|
-
});
|
|
2
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
|
+
import { ToolbarModelRenderer as ToolbarModelRendererNew } from './ToolbarRendererNew';
|
|
4
|
+
import { ToolbarModelRenderer as ToolbarModelRendererOld } from './ToolbarRendererOld';
|
|
25
5
|
export const ToolbarModelRenderer = ({
|
|
26
6
|
toolbar,
|
|
27
7
|
components,
|
|
28
8
|
fallbacks
|
|
29
9
|
}) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const menuItemsAndNestedMenus = components.filter(isToolbarMenuItemOrNestedMenu);
|
|
36
|
-
const renderToolbarItem = ({
|
|
37
|
-
item,
|
|
38
|
-
index,
|
|
39
|
-
parents
|
|
40
|
-
}) => {
|
|
41
|
-
if (item.type === 'menu') {
|
|
42
|
-
const menuComponents = getSortedChildren(menuSections, item.key);
|
|
43
|
-
if (menuComponents.length === 0) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
const Menu = item.component || NoOp;
|
|
47
|
-
return /*#__PURE__*/React.createElement(Menu, {
|
|
48
|
-
key: item.key,
|
|
49
|
-
parents: parents
|
|
50
|
-
}, menuComponents.map(menuSection => {
|
|
51
|
-
const menuItemsInSection = getSortedChildren(menuItemsAndNestedMenus, menuSection.key);
|
|
52
|
-
const MenuSection = menuSection.component || fallbacks.menuSection;
|
|
53
|
-
return /*#__PURE__*/React.createElement(MenuSection, {
|
|
54
|
-
key: menuSection.key,
|
|
55
|
-
parents: [...parents, {
|
|
56
|
-
key: item.key,
|
|
57
|
-
type: item.type
|
|
58
|
-
}]
|
|
59
|
-
}, menuItemsInSection.map(menuItem => {
|
|
60
|
-
if (menuItem.type === 'nested-menu') {
|
|
61
|
-
const nestedMenuComponents = getSortedChildren(menuSections, menuItem.key);
|
|
62
|
-
const NestedMenu = menuItem.component;
|
|
63
|
-
return /*#__PURE__*/React.createElement(NestedMenu, {
|
|
64
|
-
key: menuItem.key,
|
|
65
|
-
parents: [...parents, {
|
|
66
|
-
key: item.key,
|
|
67
|
-
type: item.type
|
|
68
|
-
}, {
|
|
69
|
-
key: menuSection.key,
|
|
70
|
-
type: menuSection.type
|
|
71
|
-
}]
|
|
72
|
-
}, nestedMenuComponents.map(nestedMenuSection => {
|
|
73
|
-
const menuItemsInNestedMenuSection = getSortedChildren(menuItems, nestedMenuSection.key);
|
|
74
|
-
const NestedMenuSection = nestedMenuSection.component || fallbacks.menuSection;
|
|
75
|
-
return /*#__PURE__*/React.createElement(NestedMenuSection, {
|
|
76
|
-
key: nestedMenuSection.key,
|
|
77
|
-
parents: [...parents, {
|
|
78
|
-
key: item.key,
|
|
79
|
-
type: item.type
|
|
80
|
-
}, {
|
|
81
|
-
key: menuSection.key,
|
|
82
|
-
type: menuSection.type
|
|
83
|
-
}, {
|
|
84
|
-
key: menuItem.key,
|
|
85
|
-
type: menuItem.type
|
|
86
|
-
}]
|
|
87
|
-
}, menuItemsInNestedMenuSection.map(nestedMenuItem => {
|
|
88
|
-
const NestedMenuItem = nestedMenuItem.component || NoOp;
|
|
89
|
-
return /*#__PURE__*/React.createElement(NestedMenuItem, {
|
|
90
|
-
key: nestedMenuItem.key,
|
|
91
|
-
parents: [...parents, {
|
|
92
|
-
key: item.key,
|
|
93
|
-
type: item.type
|
|
94
|
-
}, {
|
|
95
|
-
key: menuSection.key,
|
|
96
|
-
type: menuSection.type
|
|
97
|
-
}, {
|
|
98
|
-
key: menuItem.key,
|
|
99
|
-
type: menuItem.type
|
|
100
|
-
}, {
|
|
101
|
-
key: nestedMenuSection.key,
|
|
102
|
-
type: nestedMenuSection.type
|
|
103
|
-
}]
|
|
104
|
-
});
|
|
105
|
-
}));
|
|
106
|
-
}));
|
|
107
|
-
}
|
|
108
|
-
const MenuItem = menuItem.component || NoOp;
|
|
109
|
-
return /*#__PURE__*/React.createElement(MenuItem, {
|
|
110
|
-
key: menuItem.key,
|
|
111
|
-
parents: [...parents, {
|
|
112
|
-
key: item.key,
|
|
113
|
-
type: item.type
|
|
114
|
-
}, {
|
|
115
|
-
key: menuSection.key,
|
|
116
|
-
type: menuSection.type
|
|
117
|
-
}]
|
|
118
|
-
});
|
|
119
|
-
}));
|
|
120
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
const Button = item.component || NoOp;
|
|
123
|
-
return /*#__PURE__*/React.createElement(Button, {
|
|
124
|
-
key: item.key,
|
|
125
|
-
parents: parents
|
|
10
|
+
if (fg('platform_editor_toolbar_aifc_renderer_rewrite')) {
|
|
11
|
+
return /*#__PURE__*/React.createElement(ToolbarModelRendererNew, {
|
|
12
|
+
toolbar: toolbar,
|
|
13
|
+
components: components,
|
|
14
|
+
fallbacks: fallbacks
|
|
126
15
|
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const Group = group.component || fallbacks.group;
|
|
134
|
-
return /*#__PURE__*/React.createElement(Group, {
|
|
135
|
-
key: group.key,
|
|
136
|
-
parents: parents
|
|
137
|
-
}, groupItems.map((item, index) => {
|
|
138
|
-
return renderToolbarItem({
|
|
139
|
-
item,
|
|
140
|
-
index,
|
|
141
|
-
parents: [...parents, {
|
|
142
|
-
key: group.key,
|
|
143
|
-
type: group.type
|
|
144
|
-
}]
|
|
145
|
-
});
|
|
146
|
-
}));
|
|
147
|
-
};
|
|
148
|
-
const renderSection = section => {
|
|
149
|
-
const sectionGroups = getSortedChildren(groups, section.key);
|
|
150
|
-
const Section = section.component || fallbacks.section;
|
|
151
|
-
const parents = [{
|
|
152
|
-
key: toolbar.key,
|
|
153
|
-
type: toolbar.type
|
|
154
|
-
}];
|
|
155
|
-
return /*#__PURE__*/React.createElement(Section, {
|
|
156
|
-
key: section.key,
|
|
157
|
-
parents: parents
|
|
158
|
-
}, sectionGroups.map(group => renderGroup(group, [...parents, {
|
|
159
|
-
key: section.key,
|
|
160
|
-
type: section.type
|
|
161
|
-
}])));
|
|
162
|
-
};
|
|
163
|
-
const ToolbarComponent = toolbar.component || NoOp;
|
|
164
|
-
return /*#__PURE__*/React.createElement(ToolbarComponent, null, sections.map(renderSection));
|
|
16
|
+
}
|
|
17
|
+
return /*#__PURE__*/React.createElement(ToolbarModelRendererOld, {
|
|
18
|
+
toolbar: toolbar,
|
|
19
|
+
components: components,
|
|
20
|
+
fallbacks: fallbacks
|
|
21
|
+
});
|
|
165
22
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { getSortedChildren, isSection, NoOp } from './common';
|
|
4
|
+
var hasParents = function hasParents(component) {
|
|
5
|
+
return component.type !== 'toolbar';
|
|
6
|
+
};
|
|
7
|
+
var getChildTypesForParent = function getChildTypesForParent(parentType) {
|
|
8
|
+
switch (parentType) {
|
|
9
|
+
case 'toolbar':
|
|
10
|
+
return ['section'];
|
|
11
|
+
case 'section':
|
|
12
|
+
return ['group'];
|
|
13
|
+
case 'group':
|
|
14
|
+
return ['button', 'menu'];
|
|
15
|
+
case 'menu':
|
|
16
|
+
case 'nested-menu':
|
|
17
|
+
return ['menu-section'];
|
|
18
|
+
case 'menu-section':
|
|
19
|
+
return ['menu-item', 'nested-menu'];
|
|
20
|
+
default:
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var getFallbackComponent = function getFallbackComponent(type, fallbacks) {
|
|
25
|
+
switch (type) {
|
|
26
|
+
case 'group':
|
|
27
|
+
return fallbacks.group;
|
|
28
|
+
case 'menu-section':
|
|
29
|
+
return fallbacks.menuSection;
|
|
30
|
+
case 'section':
|
|
31
|
+
return fallbacks.section;
|
|
32
|
+
default:
|
|
33
|
+
return NoOp;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var _ComponentRenderer = function ComponentRenderer(_ref) {
|
|
37
|
+
var component = _ref.component,
|
|
38
|
+
parents = _ref.parents,
|
|
39
|
+
allComponents = _ref.allComponents,
|
|
40
|
+
fallbacks = _ref.fallbacks;
|
|
41
|
+
var childTypes = getChildTypesForParent(component.type);
|
|
42
|
+
var children = getSortedChildren(allComponents.filter(function (comp) {
|
|
43
|
+
return childTypes.includes(comp.type);
|
|
44
|
+
}), component.key);
|
|
45
|
+
if ((component.type === 'menu' || component.type === 'group' || component.type === 'nested-menu' || component.type === 'menu-section') && children.length === 0) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
var Component = component.component || getFallbackComponent(component.type, fallbacks);
|
|
49
|
+
var newParents = [].concat(_toConsumableArray(parents), [{
|
|
50
|
+
key: component.key,
|
|
51
|
+
type: component.type
|
|
52
|
+
}]);
|
|
53
|
+
if (children.length === 0) {
|
|
54
|
+
return /*#__PURE__*/React.createElement(Component, {
|
|
55
|
+
parents: parents
|
|
56
|
+
}, null);
|
|
57
|
+
}
|
|
58
|
+
return /*#__PURE__*/React.createElement(Component, {
|
|
59
|
+
parents: parents
|
|
60
|
+
}, children.map(function (child) {
|
|
61
|
+
return /*#__PURE__*/React.createElement(_ComponentRenderer, {
|
|
62
|
+
key: child.key,
|
|
63
|
+
component: child,
|
|
64
|
+
parents: newParents,
|
|
65
|
+
allComponents: allComponents,
|
|
66
|
+
fallbacks: fallbacks
|
|
67
|
+
});
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
export var ToolbarModelRenderer = function ToolbarModelRenderer(_ref2) {
|
|
71
|
+
var toolbar = _ref2.toolbar,
|
|
72
|
+
components = _ref2.components,
|
|
73
|
+
fallbacks = _ref2.fallbacks;
|
|
74
|
+
var ToolbarComponent = toolbar.component || NoOp;
|
|
75
|
+
var sections = getSortedChildren(components.filter(isSection), toolbar.key);
|
|
76
|
+
return /*#__PURE__*/React.createElement(ToolbarComponent, null, sections.map(function (section) {
|
|
77
|
+
return /*#__PURE__*/React.createElement(_ComponentRenderer, {
|
|
78
|
+
key: section.key,
|
|
79
|
+
component: section,
|
|
80
|
+
parents: [{
|
|
81
|
+
key: toolbar.key,
|
|
82
|
+
type: toolbar.type
|
|
83
|
+
}],
|
|
84
|
+
allComponents: components.filter(hasParents),
|
|
85
|
+
fallbacks: fallbacks
|
|
86
|
+
});
|
|
87
|
+
}));
|
|
88
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { isSection, NoOp } from './common';
|
|
4
|
+
var isGroup = function isGroup(component) {
|
|
5
|
+
return component.type === 'group';
|
|
6
|
+
};
|
|
7
|
+
var isToolbarItem = function isToolbarItem(component) {
|
|
8
|
+
return component.type === 'button' || component.type === 'menu';
|
|
9
|
+
};
|
|
10
|
+
var isToolbarMenuSection = function isToolbarMenuSection(component) {
|
|
11
|
+
return component.type === 'menu-section';
|
|
12
|
+
};
|
|
13
|
+
var isToolbarMenuItem = function isToolbarMenuItem(component) {
|
|
14
|
+
return component.type === 'menu-item' || component.type === 'menu-section';
|
|
15
|
+
};
|
|
16
|
+
var isToolbarMenuItemOrNestedMenu = function isToolbarMenuItemOrNestedMenu(component) {
|
|
17
|
+
return component.type === 'menu-item' || component.type === 'menu-section' || component.type === 'nested-menu';
|
|
18
|
+
};
|
|
19
|
+
var getSortedChildren = function getSortedChildren(components, parentKey) {
|
|
20
|
+
return components.filter(function (component) {
|
|
21
|
+
return component.parents.some(function (parent) {
|
|
22
|
+
return parent.key === parentKey;
|
|
23
|
+
});
|
|
24
|
+
}).sort(function (a, b) {
|
|
25
|
+
var _a$parents$find, _b$parents$find;
|
|
26
|
+
return (((_a$parents$find = a.parents.find(function (p) {
|
|
27
|
+
return p.key === parentKey;
|
|
28
|
+
})) === null || _a$parents$find === void 0 ? void 0 : _a$parents$find.rank) || 0) - (((_b$parents$find = b.parents.find(function (p) {
|
|
29
|
+
return p.key === parentKey;
|
|
30
|
+
})) === null || _b$parents$find === void 0 ? void 0 : _b$parents$find.rank) || 0);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
export var ToolbarModelRenderer = function ToolbarModelRenderer(_ref) {
|
|
34
|
+
var toolbar = _ref.toolbar,
|
|
35
|
+
components = _ref.components,
|
|
36
|
+
fallbacks = _ref.fallbacks;
|
|
37
|
+
var sections = getSortedChildren(components.filter(isSection), toolbar.key);
|
|
38
|
+
var groups = components.filter(isGroup);
|
|
39
|
+
var toolbarItems = components.filter(isToolbarItem);
|
|
40
|
+
var menuSections = components.filter(isToolbarMenuSection);
|
|
41
|
+
var menuItems = components.filter(isToolbarMenuItem);
|
|
42
|
+
var menuItemsAndNestedMenus = components.filter(isToolbarMenuItemOrNestedMenu);
|
|
43
|
+
var renderToolbarItem = function renderToolbarItem(_ref2) {
|
|
44
|
+
var item = _ref2.item,
|
|
45
|
+
index = _ref2.index,
|
|
46
|
+
parents = _ref2.parents;
|
|
47
|
+
if (item.type === 'menu') {
|
|
48
|
+
var menuComponents = getSortedChildren(menuSections, item.key);
|
|
49
|
+
if (menuComponents.length === 0) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
var Menu = item.component || NoOp;
|
|
53
|
+
return /*#__PURE__*/React.createElement(Menu, {
|
|
54
|
+
key: item.key,
|
|
55
|
+
parents: parents
|
|
56
|
+
}, menuComponents.map(function (menuSection) {
|
|
57
|
+
var menuItemsInSection = getSortedChildren(menuItemsAndNestedMenus, menuSection.key);
|
|
58
|
+
var MenuSection = menuSection.component || fallbacks.menuSection;
|
|
59
|
+
return /*#__PURE__*/React.createElement(MenuSection, {
|
|
60
|
+
key: menuSection.key,
|
|
61
|
+
parents: [].concat(_toConsumableArray(parents), [{
|
|
62
|
+
key: item.key,
|
|
63
|
+
type: item.type
|
|
64
|
+
}])
|
|
65
|
+
}, menuItemsInSection.map(function (menuItem) {
|
|
66
|
+
if (menuItem.type === 'nested-menu') {
|
|
67
|
+
var nestedMenuComponents = getSortedChildren(menuSections, menuItem.key);
|
|
68
|
+
var NestedMenu = menuItem.component;
|
|
69
|
+
return /*#__PURE__*/React.createElement(NestedMenu, {
|
|
70
|
+
key: menuItem.key,
|
|
71
|
+
parents: [].concat(_toConsumableArray(parents), [{
|
|
72
|
+
key: item.key,
|
|
73
|
+
type: item.type
|
|
74
|
+
}, {
|
|
75
|
+
key: menuSection.key,
|
|
76
|
+
type: menuSection.type
|
|
77
|
+
}])
|
|
78
|
+
}, nestedMenuComponents.map(function (nestedMenuSection) {
|
|
79
|
+
var menuItemsInNestedMenuSection = getSortedChildren(menuItems, nestedMenuSection.key);
|
|
80
|
+
var NestedMenuSection = nestedMenuSection.component || fallbacks.menuSection;
|
|
81
|
+
return /*#__PURE__*/React.createElement(NestedMenuSection, {
|
|
82
|
+
key: nestedMenuSection.key,
|
|
83
|
+
parents: [].concat(_toConsumableArray(parents), [{
|
|
84
|
+
key: item.key,
|
|
85
|
+
type: item.type
|
|
86
|
+
}, {
|
|
87
|
+
key: menuSection.key,
|
|
88
|
+
type: menuSection.type
|
|
89
|
+
}, {
|
|
90
|
+
key: menuItem.key,
|
|
91
|
+
type: menuItem.type
|
|
92
|
+
}])
|
|
93
|
+
}, menuItemsInNestedMenuSection.map(function (nestedMenuItem) {
|
|
94
|
+
var NestedMenuItem = nestedMenuItem.component || NoOp;
|
|
95
|
+
return /*#__PURE__*/React.createElement(NestedMenuItem, {
|
|
96
|
+
key: nestedMenuItem.key,
|
|
97
|
+
parents: [].concat(_toConsumableArray(parents), [{
|
|
98
|
+
key: item.key,
|
|
99
|
+
type: item.type
|
|
100
|
+
}, {
|
|
101
|
+
key: menuSection.key,
|
|
102
|
+
type: menuSection.type
|
|
103
|
+
}, {
|
|
104
|
+
key: menuItem.key,
|
|
105
|
+
type: menuItem.type
|
|
106
|
+
}, {
|
|
107
|
+
key: nestedMenuSection.key,
|
|
108
|
+
type: nestedMenuSection.type
|
|
109
|
+
}])
|
|
110
|
+
});
|
|
111
|
+
}));
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
var MenuItem = menuItem.component || NoOp;
|
|
115
|
+
return /*#__PURE__*/React.createElement(MenuItem, {
|
|
116
|
+
key: menuItem.key,
|
|
117
|
+
parents: [].concat(_toConsumableArray(parents), [{
|
|
118
|
+
key: item.key,
|
|
119
|
+
type: item.type
|
|
120
|
+
}, {
|
|
121
|
+
key: menuSection.key,
|
|
122
|
+
type: menuSection.type
|
|
123
|
+
}])
|
|
124
|
+
});
|
|
125
|
+
}));
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
var Button = item.component || NoOp;
|
|
129
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
130
|
+
key: item.key,
|
|
131
|
+
parents: parents
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
var renderGroup = function renderGroup(group, parents) {
|
|
135
|
+
var groupItems = getSortedChildren(toolbarItems, group.key);
|
|
136
|
+
if (groupItems.length === 0) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
var Group = group.component || fallbacks.group;
|
|
140
|
+
return /*#__PURE__*/React.createElement(Group, {
|
|
141
|
+
key: group.key,
|
|
142
|
+
parents: parents
|
|
143
|
+
}, groupItems.map(function (item, index) {
|
|
144
|
+
return renderToolbarItem({
|
|
145
|
+
item: item,
|
|
146
|
+
index: index,
|
|
147
|
+
parents: [].concat(_toConsumableArray(parents), [{
|
|
148
|
+
key: group.key,
|
|
149
|
+
type: group.type
|
|
150
|
+
}])
|
|
151
|
+
});
|
|
152
|
+
}));
|
|
153
|
+
};
|
|
154
|
+
var renderSection = function renderSection(section) {
|
|
155
|
+
var sectionGroups = getSortedChildren(groups, section.key);
|
|
156
|
+
var Section = section.component || fallbacks.section;
|
|
157
|
+
var parents = [{
|
|
158
|
+
key: toolbar.key,
|
|
159
|
+
type: toolbar.type
|
|
160
|
+
}];
|
|
161
|
+
return /*#__PURE__*/React.createElement(Section, {
|
|
162
|
+
key: section.key,
|
|
163
|
+
parents: parents
|
|
164
|
+
}, sectionGroups.map(function (group) {
|
|
165
|
+
return renderGroup(group, [].concat(parents, [{
|
|
166
|
+
key: section.key,
|
|
167
|
+
type: section.type
|
|
168
|
+
}]));
|
|
169
|
+
}));
|
|
170
|
+
};
|
|
171
|
+
var ToolbarComponent = toolbar.component || NoOp;
|
|
172
|
+
return /*#__PURE__*/React.createElement(ToolbarComponent, null, sections.map(renderSection));
|
|
173
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export var getSortedChildren = function getSortedChildren(components, parentKey) {
|
|
2
|
+
return components.filter(function (component) {
|
|
3
|
+
return component.parents.some(function (parent) {
|
|
4
|
+
return parent.key === parentKey;
|
|
5
|
+
});
|
|
6
|
+
}).sort(function (a, b) {
|
|
7
|
+
var _a$parents$find, _b$parents$find;
|
|
8
|
+
return (((_a$parents$find = a.parents.find(function (p) {
|
|
9
|
+
return p.key === parentKey;
|
|
10
|
+
})) === null || _a$parents$find === void 0 ? void 0 : _a$parents$find.rank) || 0) - (((_b$parents$find = b.parents.find(function (p) {
|
|
11
|
+
return p.key === parentKey;
|
|
12
|
+
})) === null || _b$parents$find === void 0 ? void 0 : _b$parents$find.rank) || 0);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export var NoOp = function NoOp(props) {
|
|
16
|
+
return null;
|
|
17
|
+
};
|
|
18
|
+
export var isSection = function isSection(component) {
|
|
19
|
+
return component.type === 'section';
|
|
20
|
+
};
|