@atlaskit/editor-plugin-block-controls 30.1.1 → 30.1.2

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,18 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 30.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`0aef8124fd34f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0aef8124fd34f) -
8
+ Add an optional controlVisibility map to the block-control surface context. Visibility predicates
9
+ receive earlier controls' isHidden results in registry rank order, keyed by registered control
10
+ key. Behind the platform_editor_remix_control_priority experiment on the
11
+ platform_editor_block_control_migration path, use this context to let Remix yield to earlier
12
+ eligible controls on the same block without coupling it to suggestions. With the experiment
13
+ disabled, retain the original context and Remix rank and visibility.
14
+ - Updated dependencies
15
+
3
16
  ## 30.1.1
4
17
 
5
18
  ### Patch Changes
@@ -10,12 +10,18 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
12
12
  var _react = _interopRequireWildcard(require("react"));
13
+ var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/block-control-ui-context");
13
14
  var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
15
+ var _createSurfaceContext = require("@atlaskit/editor-ui-control-model/create-surface-context");
14
16
  var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
17
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
15
18
  var _partitionComponentsByPersistence = require("./utils/partition-components-by-persistence");
16
19
  var _visibilityContainer = require("./visibility-container");
17
20
  var _excluded = ["isHidden"];
18
21
  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); }
22
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
23
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
24
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
19
25
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
20
26
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
21
27
  var BlockControlsVisibilityContext = /*#__PURE__*/(0, _react.createContext)({
@@ -66,6 +72,21 @@ var withoutVisibilityPredicate = function withoutVisibilityPredicate(component)
66
72
  visibleComponent = (0, _objectWithoutProperties2.default)(component, _excluded);
67
73
  return visibleComponent;
68
74
  };
75
+ var withControlVisibility = function withControlVisibility(surfaceContext, controlVisibility) {
76
+ var context = surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT);
77
+ if (!context) {
78
+ return surfaceContext;
79
+ }
80
+ var controlContext = (0, _createSurfaceContext.createSurfaceContext)(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT, _objectSpread(_objectSpread({}, context), {}, {
81
+ controlVisibility: new Map(controlVisibility)
82
+ }));
83
+ return {
84
+ get: function get(token) {
85
+ var _controlContext$get;
86
+ return (_controlContext$get = controlContext.get(token)) !== null && _controlContext$get !== void 0 ? _controlContext$get : surfaceContext.get(token);
87
+ }
88
+ };
89
+ };
69
90
 
70
91
  /**
71
92
  * Replaces the shared surface group with one stable wrapper group per visible control. The wrappers
@@ -80,12 +101,27 @@ var getBlockControlsSurfaceComponents = function getBlockControlsSurfaceComponen
80
101
  var resolvedSurface = (0, _surfaceRenderer.resolveSurface)(components, surface);
81
102
  var groupIdentity = (0, _surfaceRenderer.getComponentIdentity)(group);
82
103
  var controls = (_resolvedSurface$chil = resolvedSurface.childrenMap.get(groupIdentity)) !== null && _resolvedSurface$chil !== void 0 ? _resolvedSurface$chil : [];
83
- var visibleControls = controls.filter(function (control) {
84
- var _control$isHidden, _control$isHidden2;
85
- return !((_control$isHidden = (_control$isHidden2 = control.isHidden) === null || _control$isHidden2 === void 0 ? void 0 : _control$isHidden2.call(control, {
86
- surfaceContext: surfaceContext
87
- })) !== null && _control$isHidden !== void 0 ? _control$isHidden : false);
88
- });
104
+ var visibleControls = [];
105
+ var controlVisibility = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_remix_control_priority') ? new Map() : undefined;
106
+ var _iterator = _createForOfIteratorHelper(controls),
107
+ _step;
108
+ try {
109
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
110
+ var _control$isHidden, _control$isHidden2;
111
+ var control = _step.value;
112
+ var isHidden = (_control$isHidden = (_control$isHidden2 = control.isHidden) === null || _control$isHidden2 === void 0 ? void 0 : _control$isHidden2.call(control, {
113
+ surfaceContext: controlVisibility ? withControlVisibility(surfaceContext, controlVisibility) : surfaceContext
114
+ })) !== null && _control$isHidden !== void 0 ? _control$isHidden : false;
115
+ controlVisibility === null || controlVisibility === void 0 || controlVisibility.set(control.key, isHidden);
116
+ if (!isHidden) {
117
+ visibleControls.push(control);
118
+ }
119
+ }
120
+ } catch (err) {
121
+ _iterator.e(err);
122
+ } finally {
123
+ _iterator.f();
124
+ }
89
125
  if (!resolvedSurface.root || visibleControls.length === 0) {
90
126
  return undefined;
91
127
  }
@@ -1,6 +1,9 @@
1
1
  import React, { createContext, useContext, useMemo } from 'react';
2
+ import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
2
3
  import { BLOCK_CONTROLS_LEFT_GROUP, BLOCK_CONTROLS_LEFT_SECTION, BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_GROUP, BLOCK_CONTROLS_RIGHT_SECTION, BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
4
+ import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
3
5
  import { getComponentIdentity, resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
6
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
4
7
  import { partitionComponentsByPersistence } from './utils/partition-components-by-persistence';
5
8
  import { VisibilityWrapper } from './visibility-container';
6
9
  const BlockControlsVisibilityContext = /*#__PURE__*/createContext({
@@ -55,6 +58,22 @@ const withoutVisibilityPredicate = component => {
55
58
  } = component;
56
59
  return visibleComponent;
57
60
  };
61
+ const withControlVisibility = (surfaceContext, controlVisibility) => {
62
+ const context = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
63
+ if (!context) {
64
+ return surfaceContext;
65
+ }
66
+ const controlContext = createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, {
67
+ ...context,
68
+ controlVisibility: new Map(controlVisibility)
69
+ });
70
+ return {
71
+ get: token => {
72
+ var _controlContext$get;
73
+ return (_controlContext$get = controlContext.get(token)) !== null && _controlContext$get !== void 0 ? _controlContext$get : surfaceContext.get(token);
74
+ }
75
+ };
76
+ };
58
77
 
59
78
  /**
60
79
  * Replaces the shared surface group with one stable wrapper group per visible control. The wrappers
@@ -70,12 +89,18 @@ const getBlockControlsSurfaceComponents = (components, {
70
89
  const resolvedSurface = resolveSurface(components, surface);
71
90
  const groupIdentity = getComponentIdentity(group);
72
91
  const controls = (_resolvedSurface$chil = resolvedSurface.childrenMap.get(groupIdentity)) !== null && _resolvedSurface$chil !== void 0 ? _resolvedSurface$chil : [];
73
- const visibleControls = controls.filter(control => {
92
+ const visibleControls = [];
93
+ const controlVisibility = isExperimentEnabled('platform_editor_remix_control_priority') ? new Map() : undefined;
94
+ for (const control of controls) {
74
95
  var _control$isHidden, _control$isHidden2;
75
- return !((_control$isHidden = (_control$isHidden2 = control.isHidden) === null || _control$isHidden2 === void 0 ? void 0 : _control$isHidden2.call(control, {
76
- surfaceContext
77
- })) !== null && _control$isHidden !== void 0 ? _control$isHidden : false);
78
- });
96
+ const isHidden = (_control$isHidden = (_control$isHidden2 = control.isHidden) === null || _control$isHidden2 === void 0 ? void 0 : _control$isHidden2.call(control, {
97
+ surfaceContext: controlVisibility ? withControlVisibility(surfaceContext, controlVisibility) : surfaceContext
98
+ })) !== null && _control$isHidden !== void 0 ? _control$isHidden : false;
99
+ controlVisibility === null || controlVisibility === void 0 ? void 0 : controlVisibility.set(control.key, isHidden);
100
+ if (!isHidden) {
101
+ visibleControls.push(control);
102
+ }
103
+ }
79
104
  if (!resolvedSurface.root || visibleControls.length === 0) {
80
105
  return undefined;
81
106
  }
@@ -2,11 +2,17 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
4
  var _excluded = ["isHidden"];
5
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
6
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
7
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
8
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
9
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
10
  import React, { createContext, useContext, useMemo } from 'react';
11
+ import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
8
12
  import { BLOCK_CONTROLS_LEFT_GROUP, BLOCK_CONTROLS_LEFT_SECTION, BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_GROUP, BLOCK_CONTROLS_RIGHT_SECTION, BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
13
+ import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
9
14
  import { getComponentIdentity, resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
15
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
10
16
  import { partitionComponentsByPersistence } from './utils/partition-components-by-persistence';
11
17
  import { VisibilityWrapper } from './visibility-container';
12
18
  var BlockControlsVisibilityContext = /*#__PURE__*/createContext({
@@ -57,6 +63,21 @@ var withoutVisibilityPredicate = function withoutVisibilityPredicate(component)
57
63
  visibleComponent = _objectWithoutProperties(component, _excluded);
58
64
  return visibleComponent;
59
65
  };
66
+ var withControlVisibility = function withControlVisibility(surfaceContext, controlVisibility) {
67
+ var context = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
68
+ if (!context) {
69
+ return surfaceContext;
70
+ }
71
+ var controlContext = createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, _objectSpread(_objectSpread({}, context), {}, {
72
+ controlVisibility: new Map(controlVisibility)
73
+ }));
74
+ return {
75
+ get: function get(token) {
76
+ var _controlContext$get;
77
+ return (_controlContext$get = controlContext.get(token)) !== null && _controlContext$get !== void 0 ? _controlContext$get : surfaceContext.get(token);
78
+ }
79
+ };
80
+ };
60
81
 
61
82
  /**
62
83
  * Replaces the shared surface group with one stable wrapper group per visible control. The wrappers
@@ -71,12 +92,27 @@ var getBlockControlsSurfaceComponents = function getBlockControlsSurfaceComponen
71
92
  var resolvedSurface = resolveSurface(components, surface);
72
93
  var groupIdentity = getComponentIdentity(group);
73
94
  var controls = (_resolvedSurface$chil = resolvedSurface.childrenMap.get(groupIdentity)) !== null && _resolvedSurface$chil !== void 0 ? _resolvedSurface$chil : [];
74
- var visibleControls = controls.filter(function (control) {
75
- var _control$isHidden, _control$isHidden2;
76
- return !((_control$isHidden = (_control$isHidden2 = control.isHidden) === null || _control$isHidden2 === void 0 ? void 0 : _control$isHidden2.call(control, {
77
- surfaceContext: surfaceContext
78
- })) !== null && _control$isHidden !== void 0 ? _control$isHidden : false);
79
- });
95
+ var visibleControls = [];
96
+ var controlVisibility = isExperimentEnabled('platform_editor_remix_control_priority') ? new Map() : undefined;
97
+ var _iterator = _createForOfIteratorHelper(controls),
98
+ _step;
99
+ try {
100
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
101
+ var _control$isHidden, _control$isHidden2;
102
+ var control = _step.value;
103
+ var isHidden = (_control$isHidden = (_control$isHidden2 = control.isHidden) === null || _control$isHidden2 === void 0 ? void 0 : _control$isHidden2.call(control, {
104
+ surfaceContext: controlVisibility ? withControlVisibility(surfaceContext, controlVisibility) : surfaceContext
105
+ })) !== null && _control$isHidden !== void 0 ? _control$isHidden : false;
106
+ controlVisibility === null || controlVisibility === void 0 || controlVisibility.set(control.key, isHidden);
107
+ if (!isHidden) {
108
+ visibleControls.push(control);
109
+ }
110
+ }
111
+ } catch (err) {
112
+ _iterator.e(err);
113
+ } finally {
114
+ _iterator.f();
115
+ }
80
116
  if (!resolvedSurface.root || visibleControls.length === 0) {
81
117
  return undefined;
82
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "30.1.1",
3
+ "version": "30.1.2",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -73,7 +73,7 @@
73
73
  "uuid": "^11.1.1"
74
74
  },
75
75
  "peerDependencies": {
76
- "@atlaskit/editor-common": "^133.5.0",
76
+ "@atlaskit/editor-common": "^133.6.0",
77
77
  "react": "^18.2.0 || ^19.2.0",
78
78
  "react-dom": "^18.2.0 || ^19.2.0",
79
79
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"