@atlaskit/editor-plugin-type-ahead 18.0.6 → 18.0.7

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,25 @@
1
1
  # @atlaskit/editor-plugin-type-ahead
2
2
 
3
+ ## 18.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`df59babd59961`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/df59babd59961) -
8
+ Use registered Quick Insert items in both primary toolbar implementations when
9
+ `platform_editor_slash_command` is enabled, independently of the controls and AIFC experiments.
10
+ Share the registered menu model through an explicit editor-common subpath and use compact
11
+ presentation for typeahead and toolbar items.
12
+
13
+ Virtualize the toolbar menu, keep keyboard-selected items visible, and restore the bounded popup's
14
+ themed background and scrolling. Dismiss the popup on outside clicks and inset the search field
15
+ from its edges. When the experiment is enabled, ignore absent legacy Quick Insert handlers to
16
+ prevent suggestion crashes.
17
+
18
+ Provide persisted toolbar docking preferences in editor examples to support testing the primary
19
+ toolbar Insert menu.
20
+
21
+ - Updated dependencies
22
+
3
23
  ## 18.0.6
4
24
 
5
25
  ### Patch Changes
@@ -13,14 +13,13 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
13
13
  var _react = _interopRequireWildcard(require("react"));
14
14
  var _reactIntl = require("react-intl");
15
15
  var _typeAheadSurfaceContext = require("@atlaskit/editor-common/type-ahead-surface-context");
16
+ var _registeredMenuModel = require("@atlaskit/editor-common/quick-insert/registered-menu-model");
16
17
  var _typeAheadIsSectionOverflowItemKey = require("@atlaskit/editor-common/type-ahead-is-section-overflow-item-key");
17
18
  var _ui = require("@atlaskit/editor-common/ui");
18
19
  var _createSurfaceContext = require("@atlaskit/editor-ui-control-model/create-surface-context");
19
20
  var _constants = require("@atlaskit/editor-shared-styles/constants");
20
21
  var _compiled = require("@atlaskit/primitives/compiled");
21
22
  var _InputQuery = require("../InputQuery");
22
- var _buildTypeAheadMenuModel = require("./buildTypeAheadMenuModel");
23
- var _getMatchingComponents = require("./getMatchingComponents");
24
23
  var _getTypeAheadGlobalViewMoreId = require("./getTypeAheadGlobalViewMoreId");
25
24
  var _getTypeAheadItemId = require("./getTypeAheadItemId");
26
25
  var _TypeAheadMenuRenderer = require("./TypeAheadMenuRenderer");
@@ -80,7 +79,7 @@ var RegisteredTypeAheadMenu = exports.RegisteredTypeAheadMenu = function Registe
80
79
  });
81
80
  }, [components]);
82
81
  var menuModel = (0, _react.useMemo)(function () {
83
- return query === '' ? (0, _buildTypeAheadMenuModel.buildTypeAheadMenuModel)(components, surface.root, hasSectionOverflowItems ? SECTION_OVERFLOW_LIMIT : undefined, surfaceContext) : (0, _getMatchingComponents.getMatchingComponents)({
82
+ return query === '' ? (0, _registeredMenuModel.buildQuickInsertMenuModel)(components, surface.root, hasSectionOverflowItems ? SECTION_OVERFLOW_LIMIT : undefined, surfaceContext) : (0, _registeredMenuModel.getMatchingQuickInsertComponents)({
84
83
  components: components,
85
84
  rootComponent: surface.root,
86
85
  query: query,
@@ -1,75 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
- });
7
- exports.buildTypeAheadMenuModel = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _typeAheadIsMenuFooterSectionKey = require("@atlaskit/editor-common/type-ahead-is-menu-footer-section-key");
10
- var _typeAheadIsSectionOverflowItemKey = require("@atlaskit/editor-common/type-ahead-is-section-overflow-item-key");
11
- var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
12
- 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; } } }; }
13
- 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; } }
14
- 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; }
15
- var buildTypeAheadMenuModel = exports.buildTypeAheadMenuModel = function buildTypeAheadMenuModel(components, rootComponent, sectionOverflowLimit, surfaceContext) {
16
- var _resolveSurface = (0, _surfaceRenderer.resolveSurface)(components, rootComponent),
17
- root = _resolveSurface.root,
18
- childrenMap = _resolveSurface.childrenMap,
19
- topLevelChildren = _resolveSurface.topLevelChildren;
20
- if (!root || !(0, _surfaceRenderer.willComponentRender)(root, childrenMap, surfaceContext)) {
21
- return {
22
- footer: undefined,
23
- root: undefined,
24
- sections: []
25
- };
26
- }
27
- var sections = [];
28
- var footer;
29
- var _iterator = _createForOfIteratorHelper(topLevelChildren !== null && topLevelChildren !== void 0 ? topLevelChildren : []),
30
- _step;
31
- try {
32
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
33
- var _childrenMap$get;
34
- var section = _step.value;
35
- if (section.type !== 'menu-section' || !(0, _surfaceRenderer.willComponentRender)(section, childrenMap, surfaceContext)) {
36
- continue;
37
- }
38
- var children = (_childrenMap$get = childrenMap.get((0, _surfaceRenderer.getComponentIdentity)(section))) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : [];
39
- if ((0, _typeAheadIsMenuFooterSectionKey.isMenuFooterSectionKey)(section.key)) {
40
- footer = children.find(function (child) {
41
- return child.type === 'menu-item' && (0, _surfaceRenderer.willComponentRender)(child, childrenMap, surfaceContext);
42
- });
43
- continue;
44
- }
45
- var viewMoreItem = void 0;
46
- for (var index = children.length - 1; index >= 0; index--) {
47
- var child = children[index];
48
- if ((child === null || child === void 0 ? void 0 : child.type) === 'menu-item' && (0, _typeAheadIsSectionOverflowItemKey.isSectionOverflowItemKey)(child.key) && (0, _surfaceRenderer.willComponentRender)(child, childrenMap, surfaceContext)) {
49
- viewMoreItem = child;
50
- break;
51
- }
52
- }
53
- var items = children.filter(function (child) {
54
- return child.type === 'menu-item' && !(0, _typeAheadIsSectionOverflowItemKey.isSectionOverflowItemKey)(child.key) && (0, _surfaceRenderer.willComponentRender)(child, childrenMap, surfaceContext);
55
- });
56
- if (items.length === 0) {
57
- continue;
58
- }
59
- if (sectionOverflowLimit !== undefined && viewMoreItem !== undefined && items.length > sectionOverflowLimit) {
60
- sections.push([section].concat((0, _toConsumableArray2.default)(items.slice(0, sectionOverflowLimit)), [viewMoreItem]));
61
- continue;
62
- }
63
- sections.push([section].concat((0, _toConsumableArray2.default)(items)));
64
- }
65
- } catch (err) {
66
- _iterator.e(err);
67
- } finally {
68
- _iterator.f();
69
- }
70
- return {
71
- footer: footer,
72
- root: root,
73
- sections: sections
74
- };
75
- };
5
+ });
@@ -4,14 +4,13 @@ import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from 'react';
5
5
  import { useIntl } from 'react-intl';
6
6
  import { TYPE_AHEAD_SURFACE_CONTEXT } from '@atlaskit/editor-common/type-ahead-surface-context';
7
+ import { buildQuickInsertMenuModel, getMatchingQuickInsertComponents } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
7
8
  import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
8
9
  import { Popup } from '@atlaskit/editor-common/ui';
9
10
  import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
10
11
  import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles/constants';
11
12
  import { Box } from '@atlaskit/primitives/compiled';
12
13
  import { InputQuery } from '../InputQuery';
13
- import { buildTypeAheadMenuModel } from './buildTypeAheadMenuModel';
14
- import { getMatchingComponents } from './getMatchingComponents';
15
14
  import { getTypeAheadGlobalViewMoreId } from './getTypeAheadGlobalViewMoreId';
16
15
  import { getTypeAheadItemId } from './getTypeAheadItemId';
17
16
  import { TypeAheadMenuRenderer } from './TypeAheadMenuRenderer';
@@ -58,7 +57,7 @@ export const RegisteredTypeAheadMenu = ({
58
57
  const hasSectionOverflowItems = useMemo(() => components.some(({
59
58
  key
60
59
  }) => isSectionOverflowItemKey(key)), [components]);
61
- const menuModel = useMemo(() => query === '' ? buildTypeAheadMenuModel(components, surface.root, hasSectionOverflowItems ? SECTION_OVERFLOW_LIMIT : undefined, surfaceContext) : getMatchingComponents({
60
+ const menuModel = useMemo(() => query === '' ? buildQuickInsertMenuModel(components, surface.root, hasSectionOverflowItems ? SECTION_OVERFLOW_LIMIT : undefined, surfaceContext) : getMatchingQuickInsertComponents({
62
61
  components,
63
62
  rootComponent: surface.root,
64
63
  query,
@@ -1,52 +1 @@
1
- import { isMenuFooterSectionKey } from '@atlaskit/editor-common/type-ahead-is-menu-footer-section-key';
2
- import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
3
- import { getComponentIdentity, resolveSurface, willComponentRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
4
- export const buildTypeAheadMenuModel = (components, rootComponent, sectionOverflowLimit, surfaceContext) => {
5
- const {
6
- root,
7
- childrenMap,
8
- topLevelChildren
9
- } = resolveSurface(components, rootComponent);
10
- if (!root || !willComponentRender(root, childrenMap, surfaceContext)) {
11
- return {
12
- footer: undefined,
13
- root: undefined,
14
- sections: []
15
- };
16
- }
17
- const sections = [];
18
- let footer;
19
- for (const section of topLevelChildren !== null && topLevelChildren !== void 0 ? topLevelChildren : []) {
20
- var _childrenMap$get;
21
- if (section.type !== 'menu-section' || !willComponentRender(section, childrenMap, surfaceContext)) {
22
- continue;
23
- }
24
- const children = (_childrenMap$get = childrenMap.get(getComponentIdentity(section))) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : [];
25
- if (isMenuFooterSectionKey(section.key)) {
26
- footer = children.find(child => child.type === 'menu-item' && willComponentRender(child, childrenMap, surfaceContext));
27
- continue;
28
- }
29
- let viewMoreItem;
30
- for (let index = children.length - 1; index >= 0; index--) {
31
- const child = children[index];
32
- if ((child === null || child === void 0 ? void 0 : child.type) === 'menu-item' && isSectionOverflowItemKey(child.key) && willComponentRender(child, childrenMap, surfaceContext)) {
33
- viewMoreItem = child;
34
- break;
35
- }
36
- }
37
- const items = children.filter(child => child.type === 'menu-item' && !isSectionOverflowItemKey(child.key) && willComponentRender(child, childrenMap, surfaceContext));
38
- if (items.length === 0) {
39
- continue;
40
- }
41
- if (sectionOverflowLimit !== undefined && viewMoreItem !== undefined && items.length > sectionOverflowLimit) {
42
- sections.push([section, ...items.slice(0, sectionOverflowLimit), viewMoreItem]);
43
- continue;
44
- }
45
- sections.push([section, ...items]);
46
- }
47
- return {
48
- footer,
49
- root,
50
- sections
51
- };
52
- };
1
+ export {};
@@ -5,14 +5,13 @@ import { ax, ix } from "@compiled/react/runtime";
5
5
  import React, { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from 'react';
6
6
  import { useIntl } from 'react-intl';
7
7
  import { TYPE_AHEAD_SURFACE_CONTEXT } from '@atlaskit/editor-common/type-ahead-surface-context';
8
+ import { buildQuickInsertMenuModel, getMatchingQuickInsertComponents } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
8
9
  import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
9
10
  import { Popup } from '@atlaskit/editor-common/ui';
10
11
  import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
11
12
  import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles/constants';
12
13
  import { Box } from '@atlaskit/primitives/compiled';
13
14
  import { InputQuery } from '../InputQuery';
14
- import { buildTypeAheadMenuModel } from './buildTypeAheadMenuModel';
15
- import { getMatchingComponents } from './getMatchingComponents';
16
15
  import { getTypeAheadGlobalViewMoreId } from './getTypeAheadGlobalViewMoreId';
17
16
  import { getTypeAheadItemId } from './getTypeAheadItemId';
18
17
  import { TypeAheadMenuRenderer } from './TypeAheadMenuRenderer';
@@ -71,7 +70,7 @@ export var RegisteredTypeAheadMenu = function RegisteredTypeAheadMenu(_ref) {
71
70
  });
72
71
  }, [components]);
73
72
  var menuModel = useMemo(function () {
74
- return query === '' ? buildTypeAheadMenuModel(components, surface.root, hasSectionOverflowItems ? SECTION_OVERFLOW_LIMIT : undefined, surfaceContext) : getMatchingComponents({
73
+ return query === '' ? buildQuickInsertMenuModel(components, surface.root, hasSectionOverflowItems ? SECTION_OVERFLOW_LIMIT : undefined, surfaceContext) : getMatchingQuickInsertComponents({
75
74
  components: components,
76
75
  rootComponent: surface.root,
77
76
  query: query,
@@ -1,68 +1 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- 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; } } }; }
3
- 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; } }
4
- 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
- import { isMenuFooterSectionKey } from '@atlaskit/editor-common/type-ahead-is-menu-footer-section-key';
6
- import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
7
- import { getComponentIdentity, resolveSurface, willComponentRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
8
- export var buildTypeAheadMenuModel = function buildTypeAheadMenuModel(components, rootComponent, sectionOverflowLimit, surfaceContext) {
9
- var _resolveSurface = resolveSurface(components, rootComponent),
10
- root = _resolveSurface.root,
11
- childrenMap = _resolveSurface.childrenMap,
12
- topLevelChildren = _resolveSurface.topLevelChildren;
13
- if (!root || !willComponentRender(root, childrenMap, surfaceContext)) {
14
- return {
15
- footer: undefined,
16
- root: undefined,
17
- sections: []
18
- };
19
- }
20
- var sections = [];
21
- var footer;
22
- var _iterator = _createForOfIteratorHelper(topLevelChildren !== null && topLevelChildren !== void 0 ? topLevelChildren : []),
23
- _step;
24
- try {
25
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
26
- var _childrenMap$get;
27
- var section = _step.value;
28
- if (section.type !== 'menu-section' || !willComponentRender(section, childrenMap, surfaceContext)) {
29
- continue;
30
- }
31
- var children = (_childrenMap$get = childrenMap.get(getComponentIdentity(section))) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : [];
32
- if (isMenuFooterSectionKey(section.key)) {
33
- footer = children.find(function (child) {
34
- return child.type === 'menu-item' && willComponentRender(child, childrenMap, surfaceContext);
35
- });
36
- continue;
37
- }
38
- var viewMoreItem = void 0;
39
- for (var index = children.length - 1; index >= 0; index--) {
40
- var child = children[index];
41
- if ((child === null || child === void 0 ? void 0 : child.type) === 'menu-item' && isSectionOverflowItemKey(child.key) && willComponentRender(child, childrenMap, surfaceContext)) {
42
- viewMoreItem = child;
43
- break;
44
- }
45
- }
46
- var items = children.filter(function (child) {
47
- return child.type === 'menu-item' && !isSectionOverflowItemKey(child.key) && willComponentRender(child, childrenMap, surfaceContext);
48
- });
49
- if (items.length === 0) {
50
- continue;
51
- }
52
- if (sectionOverflowLimit !== undefined && viewMoreItem !== undefined && items.length > sectionOverflowLimit) {
53
- sections.push([section].concat(_toConsumableArray(items.slice(0, sectionOverflowLimit)), [viewMoreItem]));
54
- continue;
55
- }
56
- sections.push([section].concat(_toConsumableArray(items)));
57
- }
58
- } catch (err) {
59
- _iterator.e(err);
60
- } finally {
61
- _iterator.f();
62
- }
63
- return {
64
- footer: footer,
65
- root: root,
66
- sections: sections
67
- };
68
- };
1
+ export {};
@@ -1,9 +1,3 @@
1
- import type { SurfaceIdentifier } from '@atlaskit/editor-ui-control-model/surface-renderer/types';
2
- import type { RegisterComponent, RegisterMenuItem, RegisterMenuSection, SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
3
- export type TypeAheadMenuSection = [RegisterMenuSection, ...RegisterMenuItem[]];
4
- export type TypeAheadMenuModel = {
5
- footer: RegisterMenuItem | undefined;
6
- root: RegisterComponent | undefined;
7
- sections: TypeAheadMenuSection[];
8
- };
9
- export declare const buildTypeAheadMenuModel: (components: RegisterComponent[], rootComponent: SurfaceIdentifier, sectionOverflowLimit?: number, surfaceContext?: SurfaceContext) => TypeAheadMenuModel;
1
+ import type { QuickInsertMenuModel, QuickInsertMenuSection } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
2
+ export type TypeAheadMenuModel = QuickInsertMenuModel;
3
+ export type TypeAheadMenuSection = QuickInsertMenuSection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-type-ahead",
3
- "version": "18.0.6",
3
+ "version": "18.0.7",
4
4
  "description": "Type-ahead plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -29,7 +29,7 @@
29
29
  "@atlaskit/editor-plugin-metrics": "^18.0.0",
30
30
  "@atlaskit/editor-plugin-ui-control-registry": "^11.0.0",
31
31
  "@atlaskit/editor-prosemirror": "^8.0.0",
32
- "@atlaskit/editor-shared-styles": "^4.1.0",
32
+ "@atlaskit/editor-shared-styles": "^4.2.0",
33
33
  "@atlaskit/editor-ui-control-model": "^2.9.0",
34
34
  "@atlaskit/feature-gate-js-client": "^6.0.0",
35
35
  "@atlaskit/heading": "^7.2.0",
@@ -42,8 +42,8 @@
42
42
  "@atlaskit/primitives": "^22.5.0",
43
43
  "@atlaskit/prosemirror-history": "^1.2.0",
44
44
  "@atlaskit/prosemirror-input-rules": "^4.1.0",
45
- "@atlaskit/tmp-editor-statsig": "^185.0.0",
46
- "@atlaskit/tokens": "^16.11.0",
45
+ "@atlaskit/tmp-editor-statsig": "^186.0.0",
46
+ "@atlaskit/tokens": "^16.12.0",
47
47
  "@atlaskit/visually-hidden": "^4.4.0",
48
48
  "@babel/runtime": "^7.0.0",
49
49
  "@emotion/react": "^11.7.1",
@@ -54,7 +54,7 @@
54
54
  "w3c-keyname": "^2.1.8"
55
55
  },
56
56
  "peerDependencies": {
57
- "@atlaskit/editor-common": "^121.3.0",
57
+ "@atlaskit/editor-common": "^121.4.0",
58
58
  "react": "^18.2.0 || ^19.2.0",
59
59
  "react-dom": "^18.2.0 || ^19.2.0",
60
60
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
@@ -1,117 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getMatchingComponents = void 0;
7
- var _typeAheadIsMenuFooterSectionKey = require("@atlaskit/editor-common/type-ahead-is-menu-footer-section-key");
8
- var _typeAheadIsSectionOverflowItemKey = require("@atlaskit/editor-common/type-ahead-is-section-overflow-item-key");
9
- var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
10
- 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; } } }; }
11
- 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; } }
12
- 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; }
13
- var getRank = function getRank(component, parentKey) {
14
- var _component$parents$fi, _component$parents;
15
- return (_component$parents$fi = (_component$parents = component.parents) === null || _component$parents === void 0 || (_component$parents = _component$parents.find(function (parent) {
16
- return parent.key === parentKey;
17
- })) === null || _component$parents === void 0 ? void 0 : _component$parents.rank) !== null && _component$parents$fi !== void 0 ? _component$parents$fi : Number.MAX_SAFE_INTEGER;
18
- };
19
- var compareMatchedItems = function compareMatchedItems(a, b) {
20
- return a.score - b.score || a.sectionRank - b.sectionRank || a.itemRank - b.itemRank || a.identity.localeCompare(b.identity);
21
- };
22
-
23
- /**
24
- * Resolves registered menu items for a non-empty query. This intentionally has
25
- * no empty-query path so browse behavior remains owned by buildTypeAheadMenuModel.
26
- */
27
- var getMatchingComponents = exports.getMatchingComponents = function getMatchingComponents(_ref) {
28
- var components = _ref.components,
29
- rootComponent = _ref.rootComponent,
30
- query = _ref.query,
31
- formatMessage = _ref.formatMessage,
32
- surfaceContext = _ref.surfaceContext;
33
- var _resolveSurface = (0, _surfaceRenderer.resolveSurface)(components, rootComponent),
34
- childrenMap = _resolveSurface.childrenMap,
35
- root = _resolveSurface.root,
36
- topLevelChildren = _resolveSurface.topLevelChildren;
37
- if (!root || !(0, _surfaceRenderer.willComponentRender)(root, childrenMap, surfaceContext) || !topLevelChildren) {
38
- return {
39
- footer: undefined,
40
- root: undefined,
41
- sections: []
42
- };
43
- }
44
- var matches = new Map();
45
- var _iterator = _createForOfIteratorHelper(topLevelChildren),
46
- _step;
47
- try {
48
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
49
- var _childrenMap$get;
50
- var section = _step.value;
51
- if (section.type !== 'menu-section' || (0, _typeAheadIsMenuFooterSectionKey.isMenuFooterSectionKey)(section.key) || !(0, _surfaceRenderer.willComponentRender)(section, childrenMap, surfaceContext)) {
52
- continue;
53
- }
54
- var _iterator3 = _createForOfIteratorHelper((_childrenMap$get = childrenMap.get((0, _surfaceRenderer.getComponentIdentity)(section))) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : []),
55
- _step3;
56
- try {
57
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
58
- var _item$match, _match$score;
59
- var item = _step3.value;
60
- if (item.type !== 'menu-item' || (0, _typeAheadIsSectionOverflowItemKey.isSectionOverflowItemKey)(item.key) || !(0, _surfaceRenderer.willComponentRender)(item, childrenMap, surfaceContext)) {
61
- continue;
62
- }
63
- var match = (_item$match = item.match) === null || _item$match === void 0 ? void 0 : _item$match.call(item, {
64
- formatMessage: formatMessage,
65
- query: query
66
- });
67
- if (item.match && match === null) {
68
- continue;
69
- }
70
- var candidate = {
71
- identity: "".concat(item.type, ":").concat(item.key),
72
- item: item,
73
- itemRank: getRank(item, section.key),
74
- score: Math.min(1, Math.max(0, (_match$score = match === null || match === void 0 ? void 0 : match.score) !== null && _match$score !== void 0 ? _match$score : 0)),
75
- section: section,
76
- sectionRank: getRank(section, root.key)
77
- };
78
- var existing = matches.get(candidate.identity);
79
- if (!existing || compareMatchedItems(candidate, existing) < 0) {
80
- matches.set(candidate.identity, candidate);
81
- }
82
- }
83
- } catch (err) {
84
- _iterator3.e(err);
85
- } finally {
86
- _iterator3.f();
87
- }
88
- }
89
- } catch (err) {
90
- _iterator.e(err);
91
- } finally {
92
- _iterator.f();
93
- }
94
- var sectionsByKey = new Map();
95
- var _iterator2 = _createForOfIteratorHelper(Array.from(matches.values()).sort(compareMatchedItems)),
96
- _step2;
97
- try {
98
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
99
- var _match = _step2.value;
100
- var _existing = sectionsByKey.get(_match.section.key);
101
- if (_existing) {
102
- _existing.push(_match.item);
103
- } else {
104
- sectionsByKey.set(_match.section.key, [_match.section, _match.item]);
105
- }
106
- }
107
- } catch (err) {
108
- _iterator2.e(err);
109
- } finally {
110
- _iterator2.f();
111
- }
112
- return {
113
- footer: undefined,
114
- root: root,
115
- sections: Array.from(sectionsByKey.values())
116
- };
117
- };
@@ -1,78 +0,0 @@
1
- import { isMenuFooterSectionKey } from '@atlaskit/editor-common/type-ahead-is-menu-footer-section-key';
2
- import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
3
- import { getComponentIdentity, resolveSurface, willComponentRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
4
- const getRank = (component, parentKey) => {
5
- var _component$parents$fi, _component$parents, _component$parents$fi2;
6
- return (_component$parents$fi = (_component$parents = component.parents) === null || _component$parents === void 0 ? void 0 : (_component$parents$fi2 = _component$parents.find(parent => parent.key === parentKey)) === null || _component$parents$fi2 === void 0 ? void 0 : _component$parents$fi2.rank) !== null && _component$parents$fi !== void 0 ? _component$parents$fi : Number.MAX_SAFE_INTEGER;
7
- };
8
- const compareMatchedItems = (a, b) => a.score - b.score || a.sectionRank - b.sectionRank || a.itemRank - b.itemRank || a.identity.localeCompare(b.identity);
9
-
10
- /**
11
- * Resolves registered menu items for a non-empty query. This intentionally has
12
- * no empty-query path so browse behavior remains owned by buildTypeAheadMenuModel.
13
- */
14
- export const getMatchingComponents = ({
15
- components,
16
- rootComponent,
17
- query,
18
- formatMessage,
19
- surfaceContext
20
- }) => {
21
- const {
22
- childrenMap,
23
- root,
24
- topLevelChildren
25
- } = resolveSurface(components, rootComponent);
26
- if (!root || !willComponentRender(root, childrenMap, surfaceContext) || !topLevelChildren) {
27
- return {
28
- footer: undefined,
29
- root: undefined,
30
- sections: []
31
- };
32
- }
33
- const matches = new Map();
34
- for (const section of topLevelChildren) {
35
- if (section.type !== 'menu-section' || isMenuFooterSectionKey(section.key) || !willComponentRender(section, childrenMap, surfaceContext)) {
36
- continue;
37
- }
38
- for (const item of (_childrenMap$get = childrenMap.get(getComponentIdentity(section))) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : []) {
39
- var _childrenMap$get, _item$match, _match$score;
40
- if (item.type !== 'menu-item' || isSectionOverflowItemKey(item.key) || !willComponentRender(item, childrenMap, surfaceContext)) {
41
- continue;
42
- }
43
- const match = (_item$match = item.match) === null || _item$match === void 0 ? void 0 : _item$match.call(item, {
44
- formatMessage,
45
- query
46
- });
47
- if (item.match && match === null) {
48
- continue;
49
- }
50
- const candidate = {
51
- identity: `${item.type}:${item.key}`,
52
- item,
53
- itemRank: getRank(item, section.key),
54
- score: Math.min(1, Math.max(0, (_match$score = match === null || match === void 0 ? void 0 : match.score) !== null && _match$score !== void 0 ? _match$score : 0)),
55
- section,
56
- sectionRank: getRank(section, root.key)
57
- };
58
- const existing = matches.get(candidate.identity);
59
- if (!existing || compareMatchedItems(candidate, existing) < 0) {
60
- matches.set(candidate.identity, candidate);
61
- }
62
- }
63
- }
64
- const sectionsByKey = new Map();
65
- for (const match of Array.from(matches.values()).sort(compareMatchedItems)) {
66
- const existing = sectionsByKey.get(match.section.key);
67
- if (existing) {
68
- existing.push(match.item);
69
- } else {
70
- sectionsByKey.set(match.section.key, [match.section, match.item]);
71
- }
72
- }
73
- return {
74
- footer: undefined,
75
- root,
76
- sections: Array.from(sectionsByKey.values())
77
- };
78
- };
@@ -1,111 +0,0 @@
1
- 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; } } }; }
2
- 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; } }
3
- 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; }
4
- import { isMenuFooterSectionKey } from '@atlaskit/editor-common/type-ahead-is-menu-footer-section-key';
5
- import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
6
- import { getComponentIdentity, resolveSurface, willComponentRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
7
- var getRank = function getRank(component, parentKey) {
8
- var _component$parents$fi, _component$parents;
9
- return (_component$parents$fi = (_component$parents = component.parents) === null || _component$parents === void 0 || (_component$parents = _component$parents.find(function (parent) {
10
- return parent.key === parentKey;
11
- })) === null || _component$parents === void 0 ? void 0 : _component$parents.rank) !== null && _component$parents$fi !== void 0 ? _component$parents$fi : Number.MAX_SAFE_INTEGER;
12
- };
13
- var compareMatchedItems = function compareMatchedItems(a, b) {
14
- return a.score - b.score || a.sectionRank - b.sectionRank || a.itemRank - b.itemRank || a.identity.localeCompare(b.identity);
15
- };
16
-
17
- /**
18
- * Resolves registered menu items for a non-empty query. This intentionally has
19
- * no empty-query path so browse behavior remains owned by buildTypeAheadMenuModel.
20
- */
21
- export var getMatchingComponents = function getMatchingComponents(_ref) {
22
- var components = _ref.components,
23
- rootComponent = _ref.rootComponent,
24
- query = _ref.query,
25
- formatMessage = _ref.formatMessage,
26
- surfaceContext = _ref.surfaceContext;
27
- var _resolveSurface = resolveSurface(components, rootComponent),
28
- childrenMap = _resolveSurface.childrenMap,
29
- root = _resolveSurface.root,
30
- topLevelChildren = _resolveSurface.topLevelChildren;
31
- if (!root || !willComponentRender(root, childrenMap, surfaceContext) || !topLevelChildren) {
32
- return {
33
- footer: undefined,
34
- root: undefined,
35
- sections: []
36
- };
37
- }
38
- var matches = new Map();
39
- var _iterator = _createForOfIteratorHelper(topLevelChildren),
40
- _step;
41
- try {
42
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
43
- var _childrenMap$get;
44
- var section = _step.value;
45
- if (section.type !== 'menu-section' || isMenuFooterSectionKey(section.key) || !willComponentRender(section, childrenMap, surfaceContext)) {
46
- continue;
47
- }
48
- var _iterator3 = _createForOfIteratorHelper((_childrenMap$get = childrenMap.get(getComponentIdentity(section))) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : []),
49
- _step3;
50
- try {
51
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
52
- var _item$match, _match$score;
53
- var item = _step3.value;
54
- if (item.type !== 'menu-item' || isSectionOverflowItemKey(item.key) || !willComponentRender(item, childrenMap, surfaceContext)) {
55
- continue;
56
- }
57
- var match = (_item$match = item.match) === null || _item$match === void 0 ? void 0 : _item$match.call(item, {
58
- formatMessage: formatMessage,
59
- query: query
60
- });
61
- if (item.match && match === null) {
62
- continue;
63
- }
64
- var candidate = {
65
- identity: "".concat(item.type, ":").concat(item.key),
66
- item: item,
67
- itemRank: getRank(item, section.key),
68
- score: Math.min(1, Math.max(0, (_match$score = match === null || match === void 0 ? void 0 : match.score) !== null && _match$score !== void 0 ? _match$score : 0)),
69
- section: section,
70
- sectionRank: getRank(section, root.key)
71
- };
72
- var existing = matches.get(candidate.identity);
73
- if (!existing || compareMatchedItems(candidate, existing) < 0) {
74
- matches.set(candidate.identity, candidate);
75
- }
76
- }
77
- } catch (err) {
78
- _iterator3.e(err);
79
- } finally {
80
- _iterator3.f();
81
- }
82
- }
83
- } catch (err) {
84
- _iterator.e(err);
85
- } finally {
86
- _iterator.f();
87
- }
88
- var sectionsByKey = new Map();
89
- var _iterator2 = _createForOfIteratorHelper(Array.from(matches.values()).sort(compareMatchedItems)),
90
- _step2;
91
- try {
92
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
93
- var _match = _step2.value;
94
- var _existing = sectionsByKey.get(_match.section.key);
95
- if (_existing) {
96
- _existing.push(_match.item);
97
- } else {
98
- sectionsByKey.set(_match.section.key, [_match.section, _match.item]);
99
- }
100
- }
101
- } catch (err) {
102
- _iterator2.e(err);
103
- } finally {
104
- _iterator2.f();
105
- }
106
- return {
107
- footer: undefined,
108
- root: root,
109
- sections: Array.from(sectionsByKey.values())
110
- };
111
- };
@@ -1,15 +0,0 @@
1
- import type { IntlShape } from 'react-intl';
2
- import type { SurfaceIdentifier } from '@atlaskit/editor-ui-control-model/surface-renderer/types';
3
- import type { RegisterComponent, SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
4
- import type { TypeAheadMenuModel } from './buildTypeAheadMenuModel';
5
- /**
6
- * Resolves registered menu items for a non-empty query. This intentionally has
7
- * no empty-query path so browse behavior remains owned by buildTypeAheadMenuModel.
8
- */
9
- export declare const getMatchingComponents: ({ components, rootComponent, query, formatMessage, surfaceContext, }: {
10
- components: RegisterComponent[];
11
- formatMessage: IntlShape['formatMessage'];
12
- query: string;
13
- rootComponent: SurfaceIdentifier;
14
- surfaceContext?: SurfaceContext;
15
- }) => TypeAheadMenuModel;