@atlaskit/editor-plugin-quick-insert 15.1.4 → 16.0.0

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/entry-points/registry-element-browser.js +12 -0
  3. package/dist/cjs/quickInsertPlugin.js +10 -3
  4. package/dist/cjs/ui/RegistryElementBrowser/RegistryElementBrowser.compiled.css +2 -0
  5. package/dist/cjs/ui/RegistryElementBrowser/RegistryElementBrowser.js +176 -0
  6. package/dist/cjs/ui/RegistryElementBrowser/RegistryElementBrowserCategories.compiled.css +2 -0
  7. package/dist/cjs/ui/RegistryElementBrowser/RegistryElementBrowserCategories.js +52 -0
  8. package/dist/cjs/ui/RegistryElementBrowser/RegistryElementBrowserFooter.js +40 -0
  9. package/dist/cjs/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.compiled.css +2 -0
  10. package/dist/cjs/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.js +123 -0
  11. package/dist/cjs/ui/RegistryElementBrowser/index.js +144 -0
  12. package/dist/cjs/ui/RegistryElementBrowser/model.js +129 -0
  13. package/dist/es2019/entry-points/registry-element-browser.js +2 -0
  14. package/dist/es2019/quickInsertPlugin.js +8 -3
  15. package/dist/es2019/ui/RegistryElementBrowser/RegistryElementBrowser.compiled.css +2 -0
  16. package/dist/es2019/ui/RegistryElementBrowser/RegistryElementBrowser.js +147 -0
  17. package/dist/es2019/ui/RegistryElementBrowser/RegistryElementBrowserCategories.compiled.css +2 -0
  18. package/dist/es2019/ui/RegistryElementBrowser/RegistryElementBrowserCategories.js +55 -0
  19. package/dist/es2019/ui/RegistryElementBrowser/RegistryElementBrowserFooter.js +35 -0
  20. package/dist/es2019/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.compiled.css +2 -0
  21. package/dist/es2019/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.js +112 -0
  22. package/dist/es2019/ui/RegistryElementBrowser/index.js +123 -0
  23. package/dist/es2019/ui/RegistryElementBrowser/model.js +97 -0
  24. package/dist/esm/entry-points/registry-element-browser.js +2 -0
  25. package/dist/esm/quickInsertPlugin.js +10 -3
  26. package/dist/esm/ui/RegistryElementBrowser/RegistryElementBrowser.compiled.css +2 -0
  27. package/dist/esm/ui/RegistryElementBrowser/RegistryElementBrowser.js +167 -0
  28. package/dist/esm/ui/RegistryElementBrowser/RegistryElementBrowserCategories.compiled.css +2 -0
  29. package/dist/esm/ui/RegistryElementBrowser/RegistryElementBrowserCategories.js +45 -0
  30. package/dist/esm/ui/RegistryElementBrowser/RegistryElementBrowserFooter.js +33 -0
  31. package/dist/esm/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.compiled.css +2 -0
  32. package/dist/esm/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.js +114 -0
  33. package/dist/esm/ui/RegistryElementBrowser/index.js +135 -0
  34. package/dist/esm/ui/RegistryElementBrowser/model.js +122 -0
  35. package/dist/types/entry-points/registry-element-browser.d.ts +1 -0
  36. package/dist/types/ui/RegistryElementBrowser/RegistryElementBrowser.d.ts +25 -0
  37. package/dist/types/ui/RegistryElementBrowser/RegistryElementBrowserCategories.d.ts +14 -0
  38. package/dist/types/ui/RegistryElementBrowser/RegistryElementBrowserFooter.d.ts +9 -0
  39. package/dist/types/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.d.ts +31 -0
  40. package/dist/types/ui/RegistryElementBrowser/index.d.ts +9 -0
  41. package/dist/types/ui/RegistryElementBrowser/model.d.ts +31 -0
  42. package/package.json +12 -7
  43. package/registry-element-browser/package.json +10 -0
@@ -0,0 +1,122 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ 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; }
4
+ 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; }
5
+ var compareRanks = function compareRanks(left, right) {
6
+ for (var index = 0; index < Math.max(left.length, right.length); index++) {
7
+ var _left$index, _right$index;
8
+ var difference = ((_left$index = left[index]) !== null && _left$index !== void 0 ? _left$index : 0) - ((_right$index = right[index]) !== null && _right$index !== void 0 ? _right$index : 0);
9
+ if (difference !== 0) {
10
+ return difference;
11
+ }
12
+ }
13
+ return 0;
14
+ };
15
+ var isVisible = function isVisible(registration) {
16
+ var _registration$isHidde;
17
+ return ((_registration$isHidde = registration.isHidden) === null || _registration$isHidde === void 0 ? void 0 : _registration$isHidde.call(registration)) !== true;
18
+ };
19
+ var getChildren = function getChildren(components, parentKey) {
20
+ return components.filter(function (component) {
21
+ var _component$parents;
22
+ return isVisible(component) && ((_component$parents = component.parents) === null || _component$parents === void 0 ? void 0 : _component$parents.some(function (parent) {
23
+ return parent.key === parentKey;
24
+ }));
25
+ });
26
+ };
27
+ var getParentRank = function getParentRank(registration, parentKey) {
28
+ var _registration$parents, _registration$parents2;
29
+ return (_registration$parents = (_registration$parents2 = registration.parents) === null || _registration$parents2 === void 0 || (_registration$parents2 = _registration$parents2.find(function (parent) {
30
+ return parent.key === parentKey;
31
+ })) === null || _registration$parents2 === void 0 ? void 0 : _registration$parents2.rank) !== null && _registration$parents !== void 0 ? _registration$parents : Number.MAX_SAFE_INTEGER;
32
+ };
33
+ var _getDescendantItems = function getDescendantItems(components, parentKey, ancestorRanks, sectionKey) {
34
+ return getChildren(components, parentKey).flatMap(function (component) {
35
+ var ranks = [].concat(_toConsumableArray(ancestorRanks), [getParentRank(component, parentKey)]);
36
+ if (component.type === 'menu-item') {
37
+ return component.component ? [{
38
+ ranks: ranks,
39
+ registration: component,
40
+ sectionKeys: [sectionKey]
41
+ }] : [];
42
+ }
43
+ return _getDescendantItems(components, component.key, ranks, sectionKey);
44
+ });
45
+ };
46
+
47
+ /**
48
+ * Builds the Element Browser's immutable open-time view of the Quick Insert registry.
49
+ * The caller provides only components rooted at the Quick Insert menu surface.
50
+ */
51
+ export var createRegistryElementBrowserModel = function createRegistryElementBrowserModel(components, _ref) {
52
+ var footerKey = _ref.footerKey,
53
+ overflowKeys = _ref.overflowKeys,
54
+ recommendedSectionKey = _ref.recommendedSectionKey,
55
+ rootKey = _ref.rootKey;
56
+ var excludedKeys = new Set([footerKey, recommendedSectionKey].concat(_toConsumableArray(overflowKeys)));
57
+ var visibleComponents = components.filter(function (component) {
58
+ return isVisible(component) && !excludedKeys.has(component.key);
59
+ });
60
+ var sections = getChildren(visibleComponents, rootKey).filter(function (component) {
61
+ return component.type === 'menu-section';
62
+ }).map(function (section) {
63
+ return {
64
+ key: section.key,
65
+ rank: getParentRank(section, rootKey)
66
+ };
67
+ }).sort(function (left, right) {
68
+ return left.rank - right.rank;
69
+ });
70
+ var itemByKey = new Map();
71
+ sections.forEach(function (section) {
72
+ _getDescendantItems(visibleComponents, section.key, [section.rank], section.key).forEach(function (item) {
73
+ var existing = itemByKey.get(item.registration.key);
74
+ if (!existing) {
75
+ itemByKey.set(item.registration.key, item);
76
+ return;
77
+ }
78
+ var sectionKeys = _toConsumableArray(new Set([].concat(_toConsumableArray(existing.sectionKeys), _toConsumableArray(item.sectionKeys))));
79
+ itemByKey.set(item.registration.key, compareRanks(item.ranks, existing.ranks) < 0 ? _objectSpread(_objectSpread({}, item), {}, {
80
+ sectionKeys: sectionKeys
81
+ }) : _objectSpread(_objectSpread({}, existing), {}, {
82
+ sectionKeys: sectionKeys
83
+ }));
84
+ });
85
+ });
86
+ return {
87
+ items: _toConsumableArray(itemByKey.values()).sort(function (left, right) {
88
+ return compareRanks(left.ranks, right.ranks);
89
+ }),
90
+ sections: sections
91
+ };
92
+ };
93
+ export var getInitialRegistryElementBrowserSection = function getInitialRegistryElementBrowserSection(model, requestedSection) {
94
+ return model.sections.some(function (section) {
95
+ return section.key === requestedSection;
96
+ }) ? requestedSection : undefined;
97
+ };
98
+ export var getRegistryElementBrowserItems = function getRegistryElementBrowserItems(_ref2) {
99
+ var formatMessage = _ref2.formatMessage,
100
+ model = _ref2.model,
101
+ query = _ref2.query,
102
+ section = _ref2.section;
103
+ var normalizedQuery = query.trim();
104
+ var items = section ? model.items.filter(function (item) {
105
+ return item.sectionKeys.includes(section);
106
+ }) : model.items;
107
+ if (!normalizedQuery) {
108
+ return items;
109
+ }
110
+ return items.flatMap(function (item) {
111
+ var _item$registration$ma, _item$registration;
112
+ var result = (_item$registration$ma = (_item$registration = item.registration).match) === null || _item$registration$ma === void 0 ? void 0 : _item$registration$ma.call(_item$registration, {
113
+ formatMessage: formatMessage,
114
+ query: normalizedQuery
115
+ });
116
+ return result ? [_objectSpread(_objectSpread({}, item), {}, {
117
+ score: Math.min(1, Math.max(0, result.score))
118
+ })] : [];
119
+ }).sort(function (left, right) {
120
+ return left.score - right.score || compareRanks(left.ranks, right.ranks) || left.registration.key.localeCompare(right.registration.key);
121
+ });
122
+ };
@@ -0,0 +1 @@
1
+ export { RegistryElementBrowser } from '../ui/RegistryElementBrowser/RegistryElementBrowser';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import React from 'react';
6
+ import type { QuickInsertSelectionHandler } from '@atlaskit/editor-common/quick-insert/context';
7
+ import type { EmptyStateHandler } from '@atlaskit/editor-common/types';
8
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
+ import type { RegisterComponent } from '@atlaskit/editor-ui-control-model/types';
10
+ type Props = {
11
+ components: RegisterComponent[];
12
+ defaultSection?: string;
13
+ editorView: EditorView;
14
+ emptyStateHandler?: EmptyStateHandler;
15
+ helpUrl?: string;
16
+ isOffline: boolean;
17
+ isOpen: boolean;
18
+ onClearSelection: () => void;
19
+ onClose: () => void;
20
+ onCloseComplete: () => void;
21
+ onConfirmInsert: () => void;
22
+ onSelect: (handler: QuickInsertSelectionHandler) => void;
23
+ };
24
+ export declare const RegistryElementBrowser: ({ components, emptyStateHandler, defaultSection, helpUrl, editorView, isOffline, isOpen, onClearSelection, onClose, onCloseComplete, onConfirmInsert, onSelect, }: Props) => React.JSX.Element | null;
25
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import React from 'react';
6
+ import type { RegistryElementBrowserSection } from './model';
7
+ type Props = {
8
+ onSectionClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
9
+ query: string;
10
+ section?: string;
11
+ sections: RegistryElementBrowserSection[];
12
+ };
13
+ export declare const RegistryElementBrowserCategories: ({ query, section, sections, onSectionClick, }: Props) => React.JSX.Element;
14
+ export {};
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ type Props = {
3
+ helpUrl?: string;
4
+ isInsertEnabled: boolean;
5
+ onClose: () => void;
6
+ onConfirmInsert: () => void;
7
+ };
8
+ export declare const RegistryElementBrowserFooter: ({ helpUrl, isInsertEnabled, onClose, onConfirmInsert, }: Props) => React.JSX.Element;
9
+ export {};
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import React from 'react';
6
+ import type { QuickInsertSelectionHandler } from '@atlaskit/editor-common/quick-insert/context';
7
+ import type { EmptyStateHandler } from '@atlaskit/editor-common/types';
8
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
+ import type { RegistryElementBrowserItem } from './model';
10
+ type Props = {
11
+ editorView: EditorView;
12
+ emptyStateHandler?: EmptyStateHandler;
13
+ isOffline: boolean;
14
+ items: RegistryElementBrowserItem[];
15
+ onKeyDown: (event: React.KeyboardEvent) => void;
16
+ onSearchChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
17
+ onSelect: (key: string, handler: QuickInsertSelectionHandler) => void;
18
+ query: string;
19
+ resultsId: string;
20
+ section?: string;
21
+ selectedKey?: string;
22
+ };
23
+ declare const RegistryElementBrowserItem: ({ editorView, isOffline, isSelected, item, onSelect, }: {
24
+ editorView: EditorView;
25
+ isOffline: boolean;
26
+ isSelected: boolean;
27
+ item: RegistryElementBrowserItem;
28
+ onSelect: (key: string, handler: QuickInsertSelectionHandler) => void;
29
+ }) => React.JSX.Element | null;
30
+ export declare const RegistryElementBrowserSearchResults: ({ editorView, emptyStateHandler, isOffline, items, query, resultsId, section, selectedKey, onKeyDown, onSearchChange, onSelect, }: Props) => React.JSX.Element;
31
+ export {};
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ import type { QuickInsertPlugin } from '../../quickInsertPluginType';
5
+ export declare const RegistryElementBrowserContainer: ({ editorView, pluginInjectionAPI, helpUrl, }: {
6
+ editorView: EditorView;
7
+ helpUrl?: string;
8
+ pluginInjectionAPI: ExtractInjectionAPI<QuickInsertPlugin> | undefined;
9
+ }) => React.JSX.Element;
@@ -0,0 +1,31 @@
1
+ import type { MenuItemMatchContext, RegisterComponent, RegisterMenuItem } from '@atlaskit/editor-ui-control-model/types';
2
+ export type RegistryElementBrowserSection = {
3
+ key: string;
4
+ rank: number;
5
+ };
6
+ export type RegistryElementBrowserItem = {
7
+ ranks: number[];
8
+ registration: RegisterMenuItem;
9
+ sectionKeys: string[];
10
+ };
11
+ export type RegistryElementBrowserModel = {
12
+ items: RegistryElementBrowserItem[];
13
+ sections: RegistryElementBrowserSection[];
14
+ };
15
+ /**
16
+ * Builds the Element Browser's immutable open-time view of the Quick Insert registry.
17
+ * The caller provides only components rooted at the Quick Insert menu surface.
18
+ */
19
+ export declare const createRegistryElementBrowserModel: (components: RegisterComponent[], { footerKey, overflowKeys, recommendedSectionKey, rootKey, }: {
20
+ footerKey: string;
21
+ overflowKeys: Set<string>;
22
+ recommendedSectionKey: string;
23
+ rootKey: string;
24
+ }) => RegistryElementBrowserModel;
25
+ export declare const getInitialRegistryElementBrowserSection: (model: RegistryElementBrowserModel, requestedSection?: string) => string | undefined;
26
+ export declare const getRegistryElementBrowserItems: ({ formatMessage, model, query, section, }: {
27
+ formatMessage: MenuItemMatchContext['formatMessage'];
28
+ model: RegistryElementBrowserModel;
29
+ query: string;
30
+ section?: string;
31
+ }) => RegistryElementBrowserItem[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-quick-insert",
3
- "version": "15.1.4",
3
+ "version": "16.0.0",
4
4
  "description": "Quick insert plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -22,24 +22,29 @@
22
22
  "atlaskit:src": "src/index.ts",
23
23
  "dependencies": {
24
24
  "@atlaskit/button": "^25.2.0",
25
- "@atlaskit/editor-plugin-analytics": "^15.0.0",
26
- "@atlaskit/editor-plugin-connectivity": "^15.0.0",
27
- "@atlaskit/editor-plugin-metrics": "^16.0.0",
28
- "@atlaskit/editor-plugin-type-ahead": "^16.1.0",
29
- "@atlaskit/editor-plugin-ui-control-registry": "^9.0.0",
25
+ "@atlaskit/css": "^1.0.0",
26
+ "@atlaskit/editor-plugin-analytics": "^16.0.0",
27
+ "@atlaskit/editor-plugin-connectivity": "^16.0.0",
28
+ "@atlaskit/editor-plugin-metrics": "^17.0.0",
29
+ "@atlaskit/editor-plugin-type-ahead": "^17.0.0",
30
+ "@atlaskit/editor-plugin-ui-control-registry": "^10.0.0",
30
31
  "@atlaskit/editor-prosemirror": "^8.0.0",
31
32
  "@atlaskit/editor-ui-control-model": "^2.8.0",
33
+ "@atlaskit/heading": "^7.1.0",
32
34
  "@atlaskit/icon": "^37.5.0",
33
35
  "@atlaskit/modal-dialog": "^16.5.0",
34
36
  "@atlaskit/platform-feature-experiments": "^0.3.0",
35
37
  "@atlaskit/platform-feature-flags": "^2.1.0",
38
+ "@atlaskit/primitives": "^22.4.0",
39
+ "@atlaskit/textfield": "^10.1.0",
36
40
  "@atlaskit/tmp-editor-statsig": "^160.0.0",
37
41
  "@atlaskit/tokens": "^16.8.0",
38
42
  "@babel/runtime": "^7.0.0",
43
+ "@compiled/react": "^1.0.2",
39
44
  "@emotion/react": "^11.7.1"
40
45
  },
41
46
  "peerDependencies": {
42
- "@atlaskit/editor-common": "^119.16.0",
47
+ "@atlaskit/editor-common": "^120.0.0",
43
48
  "react": "^18.2.0 || ^19.2.0",
44
49
  "react-dom": "^18.2.0 || ^19.2.0",
45
50
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@atlaskit/editor-plugin-quick-insert/registry-element-browser",
3
+ "main": "../dist/cjs/entry-points/registry-element-browser.js",
4
+ "module": "../dist/esm/entry-points/registry-element-browser.js",
5
+ "module:es2019": "../dist/es2019/entry-points/registry-element-browser.js",
6
+ "sideEffects": [
7
+ "*.compiled.css"
8
+ ],
9
+ "types": "../dist/types/entry-points/registry-element-browser.d.ts"
10
+ }