@atlaskit/editor-toolbar-model 0.2.1 → 0.2.3
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 -0
- 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 +11 -5
|
@@ -1,178 +1,21 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
1
|
import React from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
var isSection = function isSection(component) {
|
|
7
|
-
return component.type === 'section';
|
|
8
|
-
};
|
|
9
|
-
var isGroup = function isGroup(component) {
|
|
10
|
-
return component.type === 'group';
|
|
11
|
-
};
|
|
12
|
-
var isToolbarItem = function isToolbarItem(component) {
|
|
13
|
-
return component.type === 'button' || component.type === 'menu';
|
|
14
|
-
};
|
|
15
|
-
var isToolbarMenuSection = function isToolbarMenuSection(component) {
|
|
16
|
-
return component.type === 'menu-section';
|
|
17
|
-
};
|
|
18
|
-
var isToolbarMenuItem = function isToolbarMenuItem(component) {
|
|
19
|
-
return component.type === 'menu-item' || component.type === 'menu-section';
|
|
20
|
-
};
|
|
21
|
-
var isToolbarMenuItemOrNestedMenu = function isToolbarMenuItemOrNestedMenu(component) {
|
|
22
|
-
return component.type === 'menu-item' || component.type === 'menu-section' || component.type === 'nested-menu';
|
|
23
|
-
};
|
|
24
|
-
var getSortedChildren = function getSortedChildren(components, parentKey) {
|
|
25
|
-
return components.filter(function (component) {
|
|
26
|
-
return component.parents.some(function (parent) {
|
|
27
|
-
return parent.key === parentKey;
|
|
28
|
-
});
|
|
29
|
-
}).sort(function (a, b) {
|
|
30
|
-
var _a$parents$find, _b$parents$find;
|
|
31
|
-
return (((_a$parents$find = a.parents.find(function (p) {
|
|
32
|
-
return p.key === parentKey;
|
|
33
|
-
})) === null || _a$parents$find === void 0 ? void 0 : _a$parents$find.rank) || 0) - (((_b$parents$find = b.parents.find(function (p) {
|
|
34
|
-
return p.key === parentKey;
|
|
35
|
-
})) === null || _b$parents$find === void 0 ? void 0 : _b$parents$find.rank) || 0);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
2
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
|
+
import { ToolbarModelRenderer as ToolbarModelRendererNew } from './ToolbarRendererNew';
|
|
4
|
+
import { ToolbarModelRenderer as ToolbarModelRendererOld } from './ToolbarRendererOld';
|
|
38
5
|
export var ToolbarModelRenderer = function ToolbarModelRenderer(_ref) {
|
|
39
6
|
var toolbar = _ref.toolbar,
|
|
40
7
|
components = _ref.components,
|
|
41
8
|
fallbacks = _ref.fallbacks;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var menuItemsAndNestedMenus = components.filter(isToolbarMenuItemOrNestedMenu);
|
|
48
|
-
var renderToolbarItem = function renderToolbarItem(_ref2) {
|
|
49
|
-
var item = _ref2.item,
|
|
50
|
-
index = _ref2.index,
|
|
51
|
-
parents = _ref2.parents;
|
|
52
|
-
if (item.type === 'menu') {
|
|
53
|
-
var menuComponents = getSortedChildren(menuSections, item.key);
|
|
54
|
-
if (menuComponents.length === 0) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
var Menu = item.component || NoOp;
|
|
58
|
-
return /*#__PURE__*/React.createElement(Menu, {
|
|
59
|
-
key: item.key,
|
|
60
|
-
parents: parents
|
|
61
|
-
}, menuComponents.map(function (menuSection) {
|
|
62
|
-
var menuItemsInSection = getSortedChildren(menuItemsAndNestedMenus, menuSection.key);
|
|
63
|
-
var MenuSection = menuSection.component || fallbacks.menuSection;
|
|
64
|
-
return /*#__PURE__*/React.createElement(MenuSection, {
|
|
65
|
-
key: menuSection.key,
|
|
66
|
-
parents: [].concat(_toConsumableArray(parents), [{
|
|
67
|
-
key: item.key,
|
|
68
|
-
type: item.type
|
|
69
|
-
}])
|
|
70
|
-
}, menuItemsInSection.map(function (menuItem) {
|
|
71
|
-
if (menuItem.type === 'nested-menu') {
|
|
72
|
-
var nestedMenuComponents = getSortedChildren(menuSections, menuItem.key);
|
|
73
|
-
var NestedMenu = menuItem.component;
|
|
74
|
-
return /*#__PURE__*/React.createElement(NestedMenu, {
|
|
75
|
-
key: menuItem.key,
|
|
76
|
-
parents: [].concat(_toConsumableArray(parents), [{
|
|
77
|
-
key: item.key,
|
|
78
|
-
type: item.type
|
|
79
|
-
}, {
|
|
80
|
-
key: menuSection.key,
|
|
81
|
-
type: menuSection.type
|
|
82
|
-
}])
|
|
83
|
-
}, nestedMenuComponents.map(function (nestedMenuSection) {
|
|
84
|
-
var menuItemsInNestedMenuSection = getSortedChildren(menuItems, nestedMenuSection.key);
|
|
85
|
-
var NestedMenuSection = nestedMenuSection.component || fallbacks.menuSection;
|
|
86
|
-
return /*#__PURE__*/React.createElement(NestedMenuSection, {
|
|
87
|
-
key: nestedMenuSection.key,
|
|
88
|
-
parents: [].concat(_toConsumableArray(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
|
-
}, menuItemsInNestedMenuSection.map(function (nestedMenuItem) {
|
|
99
|
-
var NestedMenuItem = nestedMenuItem.component || NoOp;
|
|
100
|
-
return /*#__PURE__*/React.createElement(NestedMenuItem, {
|
|
101
|
-
key: nestedMenuItem.key,
|
|
102
|
-
parents: [].concat(_toConsumableArray(parents), [{
|
|
103
|
-
key: item.key,
|
|
104
|
-
type: item.type
|
|
105
|
-
}, {
|
|
106
|
-
key: menuSection.key,
|
|
107
|
-
type: menuSection.type
|
|
108
|
-
}, {
|
|
109
|
-
key: menuItem.key,
|
|
110
|
-
type: menuItem.type
|
|
111
|
-
}, {
|
|
112
|
-
key: nestedMenuSection.key,
|
|
113
|
-
type: nestedMenuSection.type
|
|
114
|
-
}])
|
|
115
|
-
});
|
|
116
|
-
}));
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
var MenuItem = menuItem.component || NoOp;
|
|
120
|
-
return /*#__PURE__*/React.createElement(MenuItem, {
|
|
121
|
-
key: menuItem.key,
|
|
122
|
-
parents: [].concat(_toConsumableArray(parents), [{
|
|
123
|
-
key: item.key,
|
|
124
|
-
type: item.type
|
|
125
|
-
}, {
|
|
126
|
-
key: menuSection.key,
|
|
127
|
-
type: menuSection.type
|
|
128
|
-
}])
|
|
129
|
-
});
|
|
130
|
-
}));
|
|
131
|
-
}));
|
|
132
|
-
}
|
|
133
|
-
var Button = item.component || NoOp;
|
|
134
|
-
return /*#__PURE__*/React.createElement(Button, {
|
|
135
|
-
key: item.key,
|
|
136
|
-
parents: parents
|
|
9
|
+
if (fg('platform_editor_toolbar_aifc_renderer_rewrite')) {
|
|
10
|
+
return /*#__PURE__*/React.createElement(ToolbarModelRendererNew, {
|
|
11
|
+
toolbar: toolbar,
|
|
12
|
+
components: components,
|
|
13
|
+
fallbacks: fallbacks
|
|
137
14
|
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
var Group = group.component || fallbacks.group;
|
|
145
|
-
return /*#__PURE__*/React.createElement(Group, {
|
|
146
|
-
key: group.key,
|
|
147
|
-
parents: parents
|
|
148
|
-
}, groupItems.map(function (item, index) {
|
|
149
|
-
return renderToolbarItem({
|
|
150
|
-
item: item,
|
|
151
|
-
index: index,
|
|
152
|
-
parents: [].concat(_toConsumableArray(parents), [{
|
|
153
|
-
key: group.key,
|
|
154
|
-
type: group.type
|
|
155
|
-
}])
|
|
156
|
-
});
|
|
157
|
-
}));
|
|
158
|
-
};
|
|
159
|
-
var renderSection = function renderSection(section) {
|
|
160
|
-
var sectionGroups = getSortedChildren(groups, section.key);
|
|
161
|
-
var Section = section.component || fallbacks.section;
|
|
162
|
-
var parents = [{
|
|
163
|
-
key: toolbar.key,
|
|
164
|
-
type: toolbar.type
|
|
165
|
-
}];
|
|
166
|
-
return /*#__PURE__*/React.createElement(Section, {
|
|
167
|
-
key: section.key,
|
|
168
|
-
parents: parents
|
|
169
|
-
}, sectionGroups.map(function (group) {
|
|
170
|
-
return renderGroup(group, [].concat(parents, [{
|
|
171
|
-
key: section.key,
|
|
172
|
-
type: section.type
|
|
173
|
-
}]));
|
|
174
|
-
}));
|
|
175
|
-
};
|
|
176
|
-
var ToolbarComponent = toolbar.component || NoOp;
|
|
177
|
-
return /*#__PURE__*/React.createElement(ToolbarComponent, null, sections.map(renderSection));
|
|
15
|
+
}
|
|
16
|
+
return /*#__PURE__*/React.createElement(ToolbarModelRendererOld, {
|
|
17
|
+
toolbar: toolbar,
|
|
18
|
+
components: components,
|
|
19
|
+
fallbacks: fallbacks
|
|
20
|
+
});
|
|
178
21
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RegisterComponent, RegisterToolbarSection } from '../../types';
|
|
2
|
+
export declare const getSortedChildren: <T extends {
|
|
3
|
+
parents: Array<{
|
|
4
|
+
key: string;
|
|
5
|
+
rank: number;
|
|
6
|
+
}>;
|
|
7
|
+
}>(components: T[], parentKey: string) => T[];
|
|
8
|
+
export declare const NoOp: <T extends Record<string, unknown> = Record<string, unknown>>(props: T) => React.ReactNode;
|
|
9
|
+
export declare const isSection: (component: RegisterComponent) => component is RegisterToolbarSection;
|
|
@@ -1,22 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
type ToolbarProps = {
|
|
4
|
-
/**
|
|
5
|
-
* Every registered toolbar component
|
|
6
|
-
*/
|
|
7
|
-
components: RegisterComponent[];
|
|
8
|
-
/**
|
|
9
|
-
* Fallback components used in rendering
|
|
10
|
-
*/
|
|
11
|
-
fallbacks: {
|
|
12
|
-
group: ToolbarGroupComponent;
|
|
13
|
-
menuSection: ToolbarMenuSectionComponent;
|
|
14
|
-
section: ToolbarSectionComponent;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Toolbar component
|
|
18
|
-
*/
|
|
19
|
-
toolbar: RegisterToolbar;
|
|
20
|
-
};
|
|
2
|
+
import type { ToolbarProps } from './types';
|
|
21
3
|
export declare const ToolbarModelRenderer: ({ toolbar, components, fallbacks }: ToolbarProps) => React.JSX.Element;
|
|
22
|
-
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RegisterComponent, RegisterToolbar, ToolbarGroupComponent, ToolbarMenuSectionComponent, ToolbarSectionComponent } from '../../types';
|
|
2
|
+
export type ToolbarProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Every registered toolbar component
|
|
5
|
+
*/
|
|
6
|
+
components: RegisterComponent[];
|
|
7
|
+
/**
|
|
8
|
+
* Fallback components used in rendering
|
|
9
|
+
*/
|
|
10
|
+
fallbacks: {
|
|
11
|
+
group: ToolbarGroupComponent;
|
|
12
|
+
menuSection: ToolbarMenuSectionComponent;
|
|
13
|
+
section: ToolbarSectionComponent;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Toolbar component
|
|
17
|
+
*/
|
|
18
|
+
toolbar: RegisterToolbar;
|
|
19
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RegisterComponent, RegisterToolbarSection } from '../../types';
|
|
2
|
+
export declare const getSortedChildren: <T extends {
|
|
3
|
+
parents: Array<{
|
|
4
|
+
key: string;
|
|
5
|
+
rank: number;
|
|
6
|
+
}>;
|
|
7
|
+
}>(components: T[], parentKey: string) => T[];
|
|
8
|
+
export declare const NoOp: <T extends Record<string, unknown> = Record<string, unknown>>(props: T) => React.ReactNode;
|
|
9
|
+
export declare const isSection: (component: RegisterComponent) => component is RegisterToolbarSection;
|
|
@@ -1,22 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
type ToolbarProps = {
|
|
4
|
-
/**
|
|
5
|
-
* Every registered toolbar component
|
|
6
|
-
*/
|
|
7
|
-
components: RegisterComponent[];
|
|
8
|
-
/**
|
|
9
|
-
* Fallback components used in rendering
|
|
10
|
-
*/
|
|
11
|
-
fallbacks: {
|
|
12
|
-
group: ToolbarGroupComponent;
|
|
13
|
-
menuSection: ToolbarMenuSectionComponent;
|
|
14
|
-
section: ToolbarSectionComponent;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Toolbar component
|
|
18
|
-
*/
|
|
19
|
-
toolbar: RegisterToolbar;
|
|
20
|
-
};
|
|
2
|
+
import type { ToolbarProps } from './types';
|
|
21
3
|
export declare const ToolbarModelRenderer: ({ toolbar, components, fallbacks }: ToolbarProps) => React.JSX.Element;
|
|
22
|
-
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RegisterComponent, RegisterToolbar, ToolbarGroupComponent, ToolbarMenuSectionComponent, ToolbarSectionComponent } from '../../types';
|
|
2
|
+
export type ToolbarProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Every registered toolbar component
|
|
5
|
+
*/
|
|
6
|
+
components: RegisterComponent[];
|
|
7
|
+
/**
|
|
8
|
+
* Fallback components used in rendering
|
|
9
|
+
*/
|
|
10
|
+
fallbacks: {
|
|
11
|
+
group: ToolbarGroupComponent;
|
|
12
|
+
menuSection: ToolbarMenuSectionComponent;
|
|
13
|
+
section: ToolbarSectionComponent;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Toolbar component
|
|
17
|
+
*/
|
|
18
|
+
toolbar: RegisterToolbar;
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -21,9 +21,10 @@
|
|
|
21
21
|
],
|
|
22
22
|
"atlaskit:src": "src/index.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@atlaskit/css": "^0.
|
|
25
|
-
"@atlaskit/
|
|
26
|
-
"@atlaskit/
|
|
24
|
+
"@atlaskit/css": "^0.15.0",
|
|
25
|
+
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
26
|
+
"@atlaskit/primitives": "^15.0.0",
|
|
27
|
+
"@atlaskit/tokens": "^6.5.0",
|
|
27
28
|
"@babel/runtime": "^7.0.0",
|
|
28
29
|
"@compiled/react": "^0.18.3"
|
|
29
30
|
},
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@af/integration-testing": "workspace:^",
|
|
35
36
|
"@af/visual-regression": "workspace:^",
|
|
36
|
-
"@atlaskit/editor-toolbar": "^0.
|
|
37
|
+
"@atlaskit/editor-toolbar": "^0.15.0",
|
|
37
38
|
"@atlaskit/ssr": "workspace:^",
|
|
38
39
|
"@testing-library/react": "^13.4.0",
|
|
39
40
|
"react-dom": "^18.2.0"
|
|
@@ -73,8 +74,13 @@
|
|
|
73
74
|
]
|
|
74
75
|
}
|
|
75
76
|
},
|
|
77
|
+
"platform-feature-flags": {
|
|
78
|
+
"platform_editor_toolbar_aifc_renderer_rewrite": {
|
|
79
|
+
"type": "boolean"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
76
82
|
"name": "@atlaskit/editor-toolbar-model",
|
|
77
|
-
"version": "0.2.
|
|
83
|
+
"version": "0.2.3",
|
|
78
84
|
"description": "register and render toolbar component",
|
|
79
85
|
"author": "Atlassian Pty Ltd",
|
|
80
86
|
"license": "Apache-2.0",
|