@atlaskit/editor-toolbar-model 0.2.7 → 0.2.9

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/editor-toolbar-model
2
2
 
3
+ ## 0.2.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [`5baa955ebe237`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5baa955ebe237) -
8
+ Add new menu section for all extensions (inc. loom and 1p, 3p extensions), add logic to hide menu
9
+ button completely when there are no menu-sections with no menu-items associated with it
10
+
11
+ ## 0.2.8
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 0.2.7
4
18
 
5
19
  ### Patch Changes
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.ToolbarModelRenderer = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _react = _interopRequireDefault(require("react"));
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
11
  var _common = require("./common");
11
12
  var hasParents = function hasParents(component) {
12
13
  return component.type !== 'toolbar';
@@ -40,6 +41,27 @@ var getFallbackComponent = function getFallbackComponent(type, fallbacks) {
40
41
  return _common.NoOp;
41
42
  }
42
43
  };
44
+ var hasMenuItems = function hasMenuItems(menuSections, allComponents) {
45
+ return menuSections.some(function (menuSection) {
46
+ return allComponents.some(function (component) {
47
+ return component.type === 'menu-item' && component.parents.some(function (parent) {
48
+ return parent.key === menuSection.key;
49
+ });
50
+ });
51
+ });
52
+ };
53
+ var shouldHideEmptyComponent = function shouldHideEmptyComponent(component, children, allComponents) {
54
+ if (component.type === 'menu') {
55
+ var menuSections = children.filter(function (child) {
56
+ return child.type === 'menu-section';
57
+ });
58
+ return menuSections.length === 0 || !hasMenuItems(menuSections, allComponents);
59
+ }
60
+ if (component.type === 'group' || component.type === 'nested-menu' || component.type === 'menu-section') {
61
+ return children.length === 0;
62
+ }
63
+ return false;
64
+ };
43
65
  var _ComponentRenderer = function ComponentRenderer(_ref) {
44
66
  var component = _ref.component,
45
67
  parents = _ref.parents,
@@ -49,8 +71,14 @@ var _ComponentRenderer = function ComponentRenderer(_ref) {
49
71
  var children = (0, _common.getSortedChildren)(allComponents.filter(function (comp) {
50
72
  return childTypes.includes(comp.type);
51
73
  }), component.key);
52
- if ((component.type === 'menu' || component.type === 'group' || component.type === 'nested-menu' || component.type === 'menu-section') && children.length === 0) {
53
- return null;
74
+ if ((0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_overflow_menu_update')) {
75
+ if (shouldHideEmptyComponent(component, children, allComponents)) {
76
+ return null;
77
+ }
78
+ } else {
79
+ if ((component.type === 'menu' || component.type === 'group' || component.type === 'nested-menu' || component.type === 'menu-section') && children.length === 0) {
80
+ return null;
81
+ }
54
82
  }
55
83
  var Component = component.component || getFallbackComponent(component.type, fallbacks);
56
84
  var newParents = [].concat((0, _toConsumableArray2.default)(parents), [{
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import { getSortedChildren, isSection, NoOp } from './common';
3
4
  const hasParents = component => {
4
5
  return component.type !== 'toolbar';
@@ -32,6 +33,21 @@ const getFallbackComponent = (type, fallbacks) => {
32
33
  return NoOp;
33
34
  }
34
35
  };
36
+ const hasMenuItems = (menuSections, allComponents) => {
37
+ return menuSections.some(menuSection => {
38
+ return allComponents.some(component => component.type === 'menu-item' && component.parents.some(parent => parent.key === menuSection.key));
39
+ });
40
+ };
41
+ const shouldHideEmptyComponent = (component, children, allComponents) => {
42
+ if (component.type === 'menu') {
43
+ const menuSections = children.filter(child => child.type === 'menu-section');
44
+ return menuSections.length === 0 || !hasMenuItems(menuSections, allComponents);
45
+ }
46
+ if (component.type === 'group' || component.type === 'nested-menu' || component.type === 'menu-section') {
47
+ return children.length === 0;
48
+ }
49
+ return false;
50
+ };
35
51
  const ComponentRenderer = ({
36
52
  component,
37
53
  parents,
@@ -40,8 +56,14 @@ const ComponentRenderer = ({
40
56
  }) => {
41
57
  const childTypes = getChildTypesForParent(component.type);
42
58
  const children = getSortedChildren(allComponents.filter(comp => childTypes.includes(comp.type)), component.key);
43
- if ((component.type === 'menu' || component.type === 'group' || component.type === 'nested-menu' || component.type === 'menu-section') && children.length === 0) {
44
- return null;
59
+ if (fg('platform_editor_toolbar_aifc_overflow_menu_update')) {
60
+ if (shouldHideEmptyComponent(component, children, allComponents)) {
61
+ return null;
62
+ }
63
+ } else {
64
+ if ((component.type === 'menu' || component.type === 'group' || component.type === 'nested-menu' || component.type === 'menu-section') && children.length === 0) {
65
+ return null;
66
+ }
45
67
  }
46
68
  const Component = component.component || getFallbackComponent(component.type, fallbacks);
47
69
  const newParents = [...parents, {
@@ -1,5 +1,6 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import React from 'react';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { getSortedChildren, isSection, NoOp } from './common';
4
5
  var hasParents = function hasParents(component) {
5
6
  return component.type !== 'toolbar';
@@ -33,6 +34,27 @@ var getFallbackComponent = function getFallbackComponent(type, fallbacks) {
33
34
  return NoOp;
34
35
  }
35
36
  };
37
+ var hasMenuItems = function hasMenuItems(menuSections, allComponents) {
38
+ return menuSections.some(function (menuSection) {
39
+ return allComponents.some(function (component) {
40
+ return component.type === 'menu-item' && component.parents.some(function (parent) {
41
+ return parent.key === menuSection.key;
42
+ });
43
+ });
44
+ });
45
+ };
46
+ var shouldHideEmptyComponent = function shouldHideEmptyComponent(component, children, allComponents) {
47
+ if (component.type === 'menu') {
48
+ var menuSections = children.filter(function (child) {
49
+ return child.type === 'menu-section';
50
+ });
51
+ return menuSections.length === 0 || !hasMenuItems(menuSections, allComponents);
52
+ }
53
+ if (component.type === 'group' || component.type === 'nested-menu' || component.type === 'menu-section') {
54
+ return children.length === 0;
55
+ }
56
+ return false;
57
+ };
36
58
  var _ComponentRenderer = function ComponentRenderer(_ref) {
37
59
  var component = _ref.component,
38
60
  parents = _ref.parents,
@@ -42,8 +64,14 @@ var _ComponentRenderer = function ComponentRenderer(_ref) {
42
64
  var children = getSortedChildren(allComponents.filter(function (comp) {
43
65
  return childTypes.includes(comp.type);
44
66
  }), component.key);
45
- if ((component.type === 'menu' || component.type === 'group' || component.type === 'nested-menu' || component.type === 'menu-section') && children.length === 0) {
46
- return null;
67
+ if (fg('platform_editor_toolbar_aifc_overflow_menu_update')) {
68
+ if (shouldHideEmptyComponent(component, children, allComponents)) {
69
+ return null;
70
+ }
71
+ } else {
72
+ if ((component.type === 'menu' || component.type === 'group' || component.type === 'nested-menu' || component.type === 'menu-section') && children.length === 0) {
73
+ return null;
74
+ }
47
75
  }
48
76
  var Component = component.component || getFallbackComponent(component.type, fallbacks);
49
77
  var newParents = [].concat(_toConsumableArray(parents), [{
package/package.json CHANGED
@@ -21,10 +21,8 @@
21
21
  ],
22
22
  "atlaskit:src": "src/index.ts",
23
23
  "dependencies": {
24
- "@atlaskit/css": "^0.16.0",
25
24
  "@atlaskit/platform-feature-flags": "^1.1.0",
26
- "@atlaskit/primitives": "^16.2.0",
27
- "@atlaskit/tokens": "^8.1.0",
25
+ "@atlaskit/tokens": "^8.4.0",
28
26
  "@babel/runtime": "^7.0.0",
29
27
  "@compiled/react": "^0.18.6"
30
28
  },
@@ -32,10 +30,7 @@
32
30
  "react": "^18.2.0"
33
31
  },
34
32
  "devDependencies": {
35
- "@af/integration-testing": "workspace:^",
36
- "@af/visual-regression": "workspace:^",
37
- "@atlaskit/editor-toolbar": "^0.17.0",
38
- "@atlaskit/ssr": "workspace:^",
33
+ "@atlaskit/editor-toolbar": "^0.18.0",
39
34
  "@testing-library/react": "^13.4.0",
40
35
  "react-dom": "^18.2.0"
41
36
  },
@@ -77,10 +72,13 @@
77
72
  "platform-feature-flags": {
78
73
  "platform_editor_toolbar_aifc_renderer_rewrite": {
79
74
  "type": "boolean"
75
+ },
76
+ "platform_editor_toolbar_aifc_overflow_menu_update": {
77
+ "type": "boolean"
80
78
  }
81
79
  },
82
80
  "name": "@atlaskit/editor-toolbar-model",
83
- "version": "0.2.7",
81
+ "version": "0.2.9",
84
82
  "description": "register and render toolbar component",
85
83
  "author": "Atlassian Pty Ltd",
86
84
  "license": "Apache-2.0",