@atlaskit/editor-plugin-type-ahead 1.13.0 → 1.13.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 +17 -0
- package/dist/cjs/pm-plugins/decorations.js +9 -37
- package/dist/cjs/ui/ContentComponent.js +22 -7
- package/dist/cjs/ui/modern/TypeAheadMenu.js +77 -0
- package/dist/cjs/ui/modern/TypeAheadPopup.js +282 -0
- package/dist/es2019/pm-plugins/decorations.js +9 -37
- package/dist/es2019/ui/ContentComponent.js +21 -6
- package/dist/es2019/ui/modern/TypeAheadMenu.js +68 -0
- package/dist/es2019/ui/modern/TypeAheadPopup.js +275 -0
- package/dist/esm/pm-plugins/decorations.js +9 -37
- package/dist/esm/ui/ContentComponent.js +21 -6
- package/dist/esm/ui/modern/TypeAheadMenu.js +70 -0
- package/dist/esm/ui/modern/TypeAheadPopup.js +271 -0
- package/dist/types/ui/modern/TypeAheadMenu.d.ts +13 -0
- package/dist/types/ui/modern/TypeAheadPopup.d.ts +34 -0
- package/dist/types-ts4.5/ui/modern/TypeAheadMenu.d.ts +13 -0
- package/dist/types-ts4.5/ui/modern/TypeAheadPopup.d.ts +34 -0
- package/package.json +6 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-type-ahead
|
|
2
2
|
|
|
3
|
+
## 1.13.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#112186](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/112186)
|
|
8
|
+
[`9462d8ca2405a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9462d8ca2405a) -
|
|
9
|
+
Bump adf-schema to 47.2.1
|
|
10
|
+
|
|
11
|
+
## 1.13.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#112096](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/112096)
|
|
16
|
+
[`5d95afdd358ac`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5d95afdd358ac) -
|
|
17
|
+
[ux] Creates a package for new QuickInsert and Right Rail UI and adds it under a FF
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 1.13.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
|
@@ -6,14 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.factoryDecorations = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
10
9
|
var _reactIntlNext = require("react-intl-next");
|
|
11
10
|
var _uuid = _interopRequireDefault(require("uuid"));
|
|
12
11
|
var _w3cKeyname = require("w3c-keyname");
|
|
13
12
|
var _history = require("@atlaskit/editor-prosemirror/history");
|
|
14
13
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
15
14
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
16
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
15
|
var _colors = require("@atlaskit/theme/colors");
|
|
18
16
|
var _WrapperTypeAhead = require("../ui/WrapperTypeAhead");
|
|
19
17
|
var _closeTypeAhead = require("./commands/close-type-ahead");
|
|
@@ -86,31 +84,9 @@ var factoryDecorations = exports.factoryDecorations = function factoryDecoration
|
|
|
86
84
|
}
|
|
87
85
|
return false;
|
|
88
86
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return /*#__PURE__*/_react.default.createElement(_reactIntlNext.IntlProvider, {
|
|
93
|
-
locale: intl.locale || 'en',
|
|
94
|
-
messages: intl.messages,
|
|
95
|
-
formats: intl.formats
|
|
96
|
-
}, /*#__PURE__*/_react.default.createElement(_WrapperTypeAhead.WrapperTypeAhead, {
|
|
97
|
-
triggerHandler: triggerHandler,
|
|
98
|
-
editorView: editorView,
|
|
99
|
-
anchorElement: typeaheadComponent,
|
|
100
|
-
inputMethod: inputMethod,
|
|
101
|
-
getDecorationPosition: getDecorationPosition,
|
|
102
|
-
shouldFocusCursorInsideQuery: shouldFocusCursorInsideQuery,
|
|
103
|
-
popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
|
|
104
|
-
popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
|
|
105
|
-
popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
|
|
106
|
-
onUndoRedo: onUndoRedo,
|
|
107
|
-
reopenQuery: reopenQuery,
|
|
108
|
-
api: api
|
|
109
|
-
}));
|
|
110
|
-
}, typeaheadComponent, decorationId);
|
|
111
|
-
} else {
|
|
112
|
-
var _popupMountRef$curren4, _popupMountRef$curren5, _popupMountRef$curren6;
|
|
113
|
-
_reactDom.default.render( /*#__PURE__*/_react.default.createElement(_reactIntlNext.IntlProvider, {
|
|
87
|
+
nodeViewPortalProviderAPI.render(function () {
|
|
88
|
+
var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
|
|
89
|
+
return /*#__PURE__*/_react.default.createElement(_reactIntlNext.IntlProvider, {
|
|
114
90
|
locale: intl.locale || 'en',
|
|
115
91
|
messages: intl.messages,
|
|
116
92
|
formats: intl.formats
|
|
@@ -121,14 +97,14 @@ var factoryDecorations = exports.factoryDecorations = function factoryDecoration
|
|
|
121
97
|
inputMethod: inputMethod,
|
|
122
98
|
getDecorationPosition: getDecorationPosition,
|
|
123
99
|
shouldFocusCursorInsideQuery: shouldFocusCursorInsideQuery,
|
|
124
|
-
popupsMountPoint: (_popupMountRef$
|
|
125
|
-
popupsBoundariesElement: (_popupMountRef$
|
|
126
|
-
popupsScrollableElement: (_popupMountRef$
|
|
100
|
+
popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
|
|
101
|
+
popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
|
|
102
|
+
popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
|
|
127
103
|
onUndoRedo: onUndoRedo,
|
|
128
104
|
reopenQuery: reopenQuery,
|
|
129
105
|
api: api
|
|
130
|
-
}))
|
|
131
|
-
}
|
|
106
|
+
}));
|
|
107
|
+
}, typeaheadComponent, decorationId);
|
|
132
108
|
shouldFocusCursorInsideQuery = false;
|
|
133
109
|
return typeaheadComponent;
|
|
134
110
|
}, {
|
|
@@ -170,11 +146,7 @@ var factoryDecorations = exports.factoryDecorations = function factoryDecoration
|
|
|
170
146
|
if (!decoElement) {
|
|
171
147
|
return;
|
|
172
148
|
}
|
|
173
|
-
|
|
174
|
-
nodeViewPortalProviderAPI.remove(spec.key);
|
|
175
|
-
} else {
|
|
176
|
-
_reactDom.default.unmountComponentAtNode(decoElement);
|
|
177
|
-
}
|
|
149
|
+
nodeViewPortalProviderAPI.remove(spec.key);
|
|
178
150
|
});
|
|
179
151
|
return true;
|
|
180
152
|
};
|
|
@@ -7,8 +7,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.ContentComponent = ContentComponent;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
10
|
-
var
|
|
10
|
+
var _typeAhead = require("@atlaskit/editor-common/type-ahead");
|
|
11
|
+
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
12
|
+
var _TypeAheadMenu = require("./modern/TypeAheadMenu");
|
|
13
|
+
var _TypeAheadMenu2 = require("./TypeAheadMenu");
|
|
11
14
|
function ContentComponent(_ref) {
|
|
15
|
+
var _typeAheadState$trigg;
|
|
12
16
|
var api = _ref.api,
|
|
13
17
|
editorView = _ref.editorView,
|
|
14
18
|
popupMountRef = _ref.popupMountRef;
|
|
@@ -17,10 +21,21 @@ function ContentComponent(_ref) {
|
|
|
17
21
|
if (!typeAheadState) {
|
|
18
22
|
return null;
|
|
19
23
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
if (
|
|
25
|
+
// TODO: Also requires a check for editor appearance (needs to be enabled for full-page/full-width editor only ?)
|
|
26
|
+
!(0, _experiments.editorExperiment)('platform_editor_controls', 'control') && ((_typeAheadState$trigg = typeAheadState.triggerHandler) === null || _typeAheadState$trigg === void 0 ? void 0 : _typeAheadState$trigg.id) === _typeAhead.TypeAheadAvailableNodes.QUICK_INSERT) {
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement(_TypeAheadMenu.TypeAheadMenu, {
|
|
28
|
+
editorView: editorView,
|
|
29
|
+
popupMountRef: popupMountRef,
|
|
30
|
+
typeAheadState: typeAheadState,
|
|
31
|
+
api: api
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
return /*#__PURE__*/_react.default.createElement(_TypeAheadMenu2.TypeAheadMenu, {
|
|
35
|
+
editorView: editorView,
|
|
36
|
+
popupMountRef: popupMountRef,
|
|
37
|
+
typeAheadState: typeAheadState,
|
|
38
|
+
api: api
|
|
39
|
+
});
|
|
40
|
+
}
|
|
26
41
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.TypeAheadMenu = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _typeAhead = require("@atlaskit/editor-common/type-ahead");
|
|
11
|
+
var _useItemInsert3 = require("../hooks/use-item-insert");
|
|
12
|
+
var _TypeAheadPopup = require("./TypeAheadPopup");
|
|
13
|
+
var TypeAheadMenu = exports.TypeAheadMenu = /*#__PURE__*/_react.default.memo(function (_ref) {
|
|
14
|
+
var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
|
|
15
|
+
var editorView = _ref.editorView,
|
|
16
|
+
popupMountRef = _ref.popupMountRef,
|
|
17
|
+
typeAheadState = _ref.typeAheadState,
|
|
18
|
+
api = _ref.api;
|
|
19
|
+
var isOpen = typeAheadState.decorationSet.find().length > 0;
|
|
20
|
+
var triggerHandler = typeAheadState.triggerHandler,
|
|
21
|
+
items = typeAheadState.items,
|
|
22
|
+
errorInfo = typeAheadState.errorInfo,
|
|
23
|
+
decorationElement = typeAheadState.decorationElement,
|
|
24
|
+
decorationSet = typeAheadState.decorationSet,
|
|
25
|
+
query = typeAheadState.query;
|
|
26
|
+
var _useItemInsert = (0, _useItemInsert3.useItemInsert)(
|
|
27
|
+
// Ignored via go/ees005
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
29
|
+
triggerHandler, editorView, items, api),
|
|
30
|
+
_useItemInsert2 = (0, _slicedToArray2.default)(_useItemInsert, 2),
|
|
31
|
+
onItemInsert = _useItemInsert2[0],
|
|
32
|
+
onTextInsert = _useItemInsert2[1];
|
|
33
|
+
var insertItem = _react.default.useCallback(function () {
|
|
34
|
+
var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _typeAhead.SelectItemMode.SELECTED;
|
|
35
|
+
var index = arguments.length > 1 ? arguments[1] : undefined;
|
|
36
|
+
queueMicrotask(function () {
|
|
37
|
+
onItemInsert({
|
|
38
|
+
mode: mode,
|
|
39
|
+
index: index,
|
|
40
|
+
query: query
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}, [onItemInsert, query]);
|
|
44
|
+
var cancel = _react.default.useCallback(function (_ref2) {
|
|
45
|
+
var setSelectionAt = _ref2.setSelectionAt,
|
|
46
|
+
addPrefixTrigger = _ref2.addPrefixTrigger,
|
|
47
|
+
forceFocusOnEditor = _ref2.forceFocusOnEditor;
|
|
48
|
+
var fullQuery = addPrefixTrigger ? "".concat(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger).concat(query) : query;
|
|
49
|
+
onTextInsert({
|
|
50
|
+
forceFocusOnEditor: forceFocusOnEditor,
|
|
51
|
+
setSelectionAt: setSelectionAt,
|
|
52
|
+
text: fullQuery
|
|
53
|
+
});
|
|
54
|
+
}, [triggerHandler, onTextInsert, query]);
|
|
55
|
+
if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || items.length === 0 && !errorInfo) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return /*#__PURE__*/_react.default.createElement(_TypeAheadPopup.TypeAheadPopup, {
|
|
59
|
+
editorView: editorView,
|
|
60
|
+
popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
|
|
61
|
+
popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
|
|
62
|
+
popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
|
|
63
|
+
anchorElement: decorationElement,
|
|
64
|
+
triggerHandler: triggerHandler,
|
|
65
|
+
items: items,
|
|
66
|
+
errorInfo: errorInfo
|
|
67
|
+
// selectedIndex={selectedIndex}
|
|
68
|
+
// setSelectedItem={setSelectedItem}
|
|
69
|
+
,
|
|
70
|
+
onItemInsert: insertItem,
|
|
71
|
+
decorationSet: decorationSet,
|
|
72
|
+
isEmptyQuery: !query,
|
|
73
|
+
query: query,
|
|
74
|
+
cancel: cancel,
|
|
75
|
+
api: api
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.TypeAheadPopup = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _react2 = require("@emotion/react");
|
|
12
|
+
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
13
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
14
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
15
|
+
var _editorElementBrowser = require("@atlaskit/editor-element-browser");
|
|
16
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
17
|
+
var _primitives = require("@atlaskit/primitives");
|
|
18
|
+
var _colors = require("@atlaskit/theme/colors");
|
|
19
|
+
var _constants = require("../../pm-plugins/constants");
|
|
20
|
+
var _TypeAheadErrorFallback = require("../TypeAheadErrorFallback");
|
|
21
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
22
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
23
|
+
/**
|
|
24
|
+
* @jsxRuntime classic
|
|
25
|
+
* @jsx jsx
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
29
|
+
|
|
30
|
+
var DEFAULT_TYPEAHEAD_MENU_HEIGHT = 520;
|
|
31
|
+
// const DEFAULT_TYPEAHEAD_MENU_HEIGHT_NEW = 480;
|
|
32
|
+
|
|
33
|
+
var ITEM_PADDING = 12;
|
|
34
|
+
var typeAheadContent = (0, _react2.css)({
|
|
35
|
+
background: "var(--ds-surface-overlay, ".concat(_colors.N0, ")"),
|
|
36
|
+
borderRadius: "var(--ds-border-radius, 3px)",
|
|
37
|
+
boxShadow: "var(--ds-shadow-overlay, ".concat("0 0 1px ".concat(_colors.N60A, ", 0 4px 8px -2px ").concat(_colors.N50A), ")"),
|
|
38
|
+
padding: "var(--ds-space-050, 4px)".concat(" 0"),
|
|
39
|
+
width: '280px',
|
|
40
|
+
maxHeight: '520px' /* ~5.5 visibile items */,
|
|
41
|
+
overflowY: 'auto',
|
|
42
|
+
MsOverflowStyle: '-ms-autohiding-scrollbar',
|
|
43
|
+
position: 'relative'
|
|
44
|
+
});
|
|
45
|
+
// const typeAheadContentOverride = css({
|
|
46
|
+
// maxHeight: `${DEFAULT_TYPEAHEAD_MENU_HEIGHT_NEW}px`,
|
|
47
|
+
// });
|
|
48
|
+
|
|
49
|
+
var viewAllButtonStyles = (0, _primitives.xcss)({
|
|
50
|
+
background: "var(--ds-background-input-pressed, #FFFFFF)",
|
|
51
|
+
position: 'sticky',
|
|
52
|
+
bottom: '-4px',
|
|
53
|
+
width: '100%',
|
|
54
|
+
height: '40px',
|
|
55
|
+
color: 'color.text.subtle',
|
|
56
|
+
fontWeight: "var(--ds-font-weight-medium, 500)",
|
|
57
|
+
':hover': {
|
|
58
|
+
textDecoration: 'underline'
|
|
59
|
+
},
|
|
60
|
+
':active': {
|
|
61
|
+
color: 'color.text'
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
var OFFSET = [0, 8];
|
|
65
|
+
var TypeAheadPopup = exports.TypeAheadPopup = /*#__PURE__*/_react.default.memo(function (props) {
|
|
66
|
+
var triggerHandler = props.triggerHandler,
|
|
67
|
+
anchorElement = props.anchorElement,
|
|
68
|
+
popupsMountPoint = props.popupsMountPoint,
|
|
69
|
+
popupsBoundariesElement = props.popupsBoundariesElement,
|
|
70
|
+
popupsScrollableElement = props.popupsScrollableElement,
|
|
71
|
+
items = props.items,
|
|
72
|
+
errorInfo = props.errorInfo,
|
|
73
|
+
onItemInsert = props.onItemInsert,
|
|
74
|
+
isEmptyQuery = props.isEmptyQuery,
|
|
75
|
+
cancel = props.cancel,
|
|
76
|
+
api = props.api,
|
|
77
|
+
query = props.query;
|
|
78
|
+
var ref = (0, _react.useRef)(null);
|
|
79
|
+
var defaultMenuHeight = DEFAULT_TYPEAHEAD_MENU_HEIGHT;
|
|
80
|
+
var startTime = (0, _react.useMemo)(function () {
|
|
81
|
+
return performance.now();
|
|
82
|
+
},
|
|
83
|
+
// In case those props changes
|
|
84
|
+
// we need to recreate the startTime
|
|
85
|
+
[items, isEmptyQuery, triggerHandler] // eslint-disable-line react-hooks/exhaustive-deps
|
|
86
|
+
);
|
|
87
|
+
(0, _react.useEffect)(function () {
|
|
88
|
+
var _api$analytics, _api$analytics2;
|
|
89
|
+
if (!(api !== null && api !== void 0 && (_api$analytics = api.analytics) !== null && _api$analytics !== void 0 && (_api$analytics = _api$analytics.actions) !== null && _api$analytics !== void 0 && _api$analytics.fireAnalyticsEvent)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var stopTime = performance.now();
|
|
93
|
+
var time = stopTime - startTime;
|
|
94
|
+
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || (_api$analytics2 = _api$analytics2.actions) === null || _api$analytics2 === void 0 || _api$analytics2.fireAnalyticsEvent({
|
|
95
|
+
action: _analytics.ACTION.RENDERED,
|
|
96
|
+
actionSubject: _analytics.ACTION_SUBJECT.TYPEAHEAD,
|
|
97
|
+
eventType: _analytics.EVENT_TYPE.OPERATIONAL,
|
|
98
|
+
attributes: {
|
|
99
|
+
time: time,
|
|
100
|
+
items: items.length,
|
|
101
|
+
initial: isEmptyQuery
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}, [startTime, items, isEmptyQuery,
|
|
105
|
+
// In case the current triggerHandler changes
|
|
106
|
+
// e.g: Inserting a mention using the quick insert
|
|
107
|
+
// we need to send the event again
|
|
108
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
109
|
+
triggerHandler, api]);
|
|
110
|
+
|
|
111
|
+
// useEffect(() => {
|
|
112
|
+
// if (!api?.analytics?.actions?.fireAnalyticsEvent) {
|
|
113
|
+
// return;
|
|
114
|
+
// }
|
|
115
|
+
|
|
116
|
+
// api?.analytics?.actions?.fireAnalyticsEvent({
|
|
117
|
+
// action: ACTION.VIEWED,
|
|
118
|
+
// actionSubject: ACTION_SUBJECT.TYPEAHEAD_ITEM,
|
|
119
|
+
// eventType: EVENT_TYPE.OPERATIONAL,
|
|
120
|
+
// attributes: {
|
|
121
|
+
// index: selectedIndex,
|
|
122
|
+
// items: items.length,
|
|
123
|
+
// },
|
|
124
|
+
// });
|
|
125
|
+
// }, [
|
|
126
|
+
// items,
|
|
127
|
+
// api,
|
|
128
|
+
// selectedIndex,
|
|
129
|
+
// // In case the current triggerHandler changes
|
|
130
|
+
// // e.g: Inserting a mention using the quick insert
|
|
131
|
+
// // we need to send the event again
|
|
132
|
+
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
133
|
+
// triggerHandler,
|
|
134
|
+
// ]);
|
|
135
|
+
|
|
136
|
+
var _useState = (0, _react.useState)(defaultMenuHeight),
|
|
137
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
138
|
+
fitHeight = _useState2[0],
|
|
139
|
+
setFitHeight = _useState2[1];
|
|
140
|
+
var getFitHeight = (0, _react.useCallback)(function () {
|
|
141
|
+
if (!anchorElement || !popupsMountPoint) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
var target = anchorElement;
|
|
145
|
+
var _target$getBoundingCl = target.getBoundingClientRect(),
|
|
146
|
+
targetTop = _target$getBoundingCl.top,
|
|
147
|
+
targetHeight = _target$getBoundingCl.height;
|
|
148
|
+
var boundariesElement = popupsBoundariesElement || document.body;
|
|
149
|
+
var _boundariesElement$ge = boundariesElement.getBoundingClientRect(),
|
|
150
|
+
boundariesHeight = _boundariesElement$ge.height,
|
|
151
|
+
boundariesTop = _boundariesElement$ge.top;
|
|
152
|
+
|
|
153
|
+
// Calculating the space above and space below our decoration
|
|
154
|
+
var spaceAbove = targetTop - (boundariesTop - boundariesElement.scrollTop);
|
|
155
|
+
var spaceBelow = boundariesTop + boundariesHeight - (targetTop + targetHeight);
|
|
156
|
+
|
|
157
|
+
// Keep default height if more than enough space
|
|
158
|
+
if (spaceBelow >= defaultMenuHeight) {
|
|
159
|
+
return setFitHeight(defaultMenuHeight);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Determines whether typeahead will fit above or below decoration
|
|
163
|
+
// and return the space available.
|
|
164
|
+
var newFitHeight = spaceBelow >= spaceAbove ? spaceBelow : spaceAbove;
|
|
165
|
+
|
|
166
|
+
// Each typeahead item has some padding
|
|
167
|
+
// We want to leave some space at the top so first item
|
|
168
|
+
// is not partially cropped
|
|
169
|
+
var fitHeightWithSpace = newFitHeight - ITEM_PADDING * 2;
|
|
170
|
+
|
|
171
|
+
// Ensure typeahead height is max its default height
|
|
172
|
+
var minFitHeight = Math.min(defaultMenuHeight, fitHeightWithSpace);
|
|
173
|
+
return setFitHeight(minFitHeight);
|
|
174
|
+
}, [anchorElement, defaultMenuHeight, popupsBoundariesElement, popupsMountPoint]);
|
|
175
|
+
var getFitHeightDebounced = (0, _rafSchd.default)(getFitHeight);
|
|
176
|
+
(0, _react.useLayoutEffect)(function () {
|
|
177
|
+
// Ignored via go/ees005
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
179
|
+
var scrollableElement = popupsScrollableElement || (0, _ui.findOverflowScrollParent)(anchorElement);
|
|
180
|
+
getFitHeight();
|
|
181
|
+
// Ignored via go/ees005
|
|
182
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
183
|
+
window.addEventListener('resize', getFitHeightDebounced);
|
|
184
|
+
if (scrollableElement) {
|
|
185
|
+
// Ignored via go/ees005
|
|
186
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
187
|
+
scrollableElement.addEventListener('scroll', getFitHeightDebounced);
|
|
188
|
+
}
|
|
189
|
+
return function () {
|
|
190
|
+
// Ignored via go/ees005
|
|
191
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
192
|
+
window.removeEventListener('resize', getFitHeightDebounced);
|
|
193
|
+
if (scrollableElement) {
|
|
194
|
+
// Ignored via go/ees005
|
|
195
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
196
|
+
scrollableElement.removeEventListener('scroll', getFitHeightDebounced);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}, [anchorElement, popupsScrollableElement, getFitHeightDebounced, getFitHeight]);
|
|
200
|
+
(0, _react.useLayoutEffect)(function () {
|
|
201
|
+
var focusOut = function focusOut(event) {
|
|
202
|
+
var _window$getSelection;
|
|
203
|
+
var relatedTarget = event.relatedTarget;
|
|
204
|
+
|
|
205
|
+
// Given the user is changing the focus
|
|
206
|
+
// When the target is inside the TypeAhead Popup
|
|
207
|
+
// Then the popup should stay open
|
|
208
|
+
if (relatedTarget instanceof HTMLElement && relatedTarget.closest && (relatedTarget.closest(".".concat(_constants.TYPE_AHEAD_POPUP_CONTENT_CLASS)) || relatedTarget.closest("[data-type-ahead=\"".concat(_constants.TYPE_AHEAD_DECORATION_DATA_ATTRIBUTE, "\"]")))) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!(((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.type) === 'Range')) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
cancel({
|
|
215
|
+
addPrefixTrigger: true,
|
|
216
|
+
setSelectionAt: _constants.CloseSelectionOptions.AFTER_TEXT_INSERTED,
|
|
217
|
+
forceFocusOnEditor: false
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
var element = ref.current;
|
|
221
|
+
// Ignored via go/ees005
|
|
222
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
223
|
+
element === null || element === void 0 || element.addEventListener('focusout', focusOut);
|
|
224
|
+
return function () {
|
|
225
|
+
// Ignored via go/ees005
|
|
226
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
227
|
+
element === null || element === void 0 || element.removeEventListener('focusout', focusOut);
|
|
228
|
+
};
|
|
229
|
+
}, [ref, cancel]);
|
|
230
|
+
|
|
231
|
+
// ED-17443 When you press escape on typeahead panel, it should remove focus and close the panel
|
|
232
|
+
// This is the expected keyboard behaviour advised by the Accessibility team
|
|
233
|
+
(0, _react.useLayoutEffect)(function () {
|
|
234
|
+
var escape = function escape(event) {
|
|
235
|
+
if (event.key === 'Escape') {
|
|
236
|
+
cancel({
|
|
237
|
+
addPrefixTrigger: true,
|
|
238
|
+
setSelectionAt: _constants.CloseSelectionOptions.AFTER_TEXT_INSERTED,
|
|
239
|
+
forceFocusOnEditor: true
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
var element = ref.current;
|
|
244
|
+
// Ignored via go/ees005
|
|
245
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
246
|
+
element === null || element === void 0 || element.addEventListener('keydown', escape);
|
|
247
|
+
return function () {
|
|
248
|
+
// Ignored via go/ees005
|
|
249
|
+
// eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
|
|
250
|
+
element === null || element === void 0 || element.removeEventListener('keydown', escape);
|
|
251
|
+
};
|
|
252
|
+
}, [ref, cancel]);
|
|
253
|
+
return (0, _react2.jsx)(_ui.Popup, {
|
|
254
|
+
zIndex: _editorSharedStyles.akEditorFloatingDialogZIndex,
|
|
255
|
+
target: anchorElement,
|
|
256
|
+
mountTo: popupsMountPoint,
|
|
257
|
+
boundariesElement: popupsBoundariesElement,
|
|
258
|
+
scrollableElement: popupsScrollableElement,
|
|
259
|
+
fitHeight: fitHeight,
|
|
260
|
+
fitWidth: 280,
|
|
261
|
+
offset: OFFSET,
|
|
262
|
+
ariaLabel: null,
|
|
263
|
+
preventOverflow: true
|
|
264
|
+
}, (0, _react2.jsx)("div", {
|
|
265
|
+
css: [typeAheadContent]
|
|
266
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
267
|
+
,
|
|
268
|
+
tabIndex: 0
|
|
269
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
270
|
+
,
|
|
271
|
+
className: _constants.TYPE_AHEAD_POPUP_CONTENT_CLASS,
|
|
272
|
+
ref: ref
|
|
273
|
+
}, errorInfo ? (0, _react2.jsx)(_TypeAheadErrorFallback.TypeAheadErrorFallback, null) : (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)(_editorElementBrowser.QuickInsertPanel, {
|
|
274
|
+
items: items,
|
|
275
|
+
onItemInsert: onItemInsert,
|
|
276
|
+
query: query
|
|
277
|
+
}), (0, _react2.jsx)(_primitives.Pressable, {
|
|
278
|
+
xcss: viewAllButtonStyles
|
|
279
|
+
// onClick={() => api?.contextPanel?.actions.showPanel()}
|
|
280
|
+
}, "View all inserts"))));
|
|
281
|
+
});
|
|
282
|
+
TypeAheadPopup.displayName = 'TypeAheadPopup';
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
3
2
|
import { IntlProvider } from 'react-intl-next';
|
|
4
3
|
import uuid from 'uuid';
|
|
5
4
|
import { keyName as keyNameNormalized } from 'w3c-keyname';
|
|
6
5
|
import { redo, undo } from '@atlaskit/editor-prosemirror/history';
|
|
7
6
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
8
7
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
9
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
8
|
import { B400 } from '@atlaskit/theme/colors';
|
|
11
9
|
import { WrapperTypeAhead } from '../ui/WrapperTypeAhead';
|
|
12
10
|
import { closeTypeAhead } from './commands/close-type-ahead';
|
|
@@ -85,31 +83,9 @@ export const factoryDecorations = ({
|
|
|
85
83
|
}
|
|
86
84
|
return false;
|
|
87
85
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return /*#__PURE__*/React.createElement(IntlProvider, {
|
|
92
|
-
locale: intl.locale || 'en',
|
|
93
|
-
messages: intl.messages,
|
|
94
|
-
formats: intl.formats
|
|
95
|
-
}, /*#__PURE__*/React.createElement(WrapperTypeAhead, {
|
|
96
|
-
triggerHandler: triggerHandler,
|
|
97
|
-
editorView: editorView,
|
|
98
|
-
anchorElement: typeaheadComponent,
|
|
99
|
-
inputMethod: inputMethod,
|
|
100
|
-
getDecorationPosition: getDecorationPosition,
|
|
101
|
-
shouldFocusCursorInsideQuery: shouldFocusCursorInsideQuery,
|
|
102
|
-
popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
|
|
103
|
-
popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
|
|
104
|
-
popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
|
|
105
|
-
onUndoRedo: onUndoRedo,
|
|
106
|
-
reopenQuery: reopenQuery,
|
|
107
|
-
api: api
|
|
108
|
-
}));
|
|
109
|
-
}, typeaheadComponent, decorationId);
|
|
110
|
-
} else {
|
|
111
|
-
var _popupMountRef$curren4, _popupMountRef$curren5, _popupMountRef$curren6;
|
|
112
|
-
ReactDOM.render( /*#__PURE__*/React.createElement(IntlProvider, {
|
|
86
|
+
nodeViewPortalProviderAPI.render(() => {
|
|
87
|
+
var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
|
|
88
|
+
return /*#__PURE__*/React.createElement(IntlProvider, {
|
|
113
89
|
locale: intl.locale || 'en',
|
|
114
90
|
messages: intl.messages,
|
|
115
91
|
formats: intl.formats
|
|
@@ -120,14 +96,14 @@ export const factoryDecorations = ({
|
|
|
120
96
|
inputMethod: inputMethod,
|
|
121
97
|
getDecorationPosition: getDecorationPosition,
|
|
122
98
|
shouldFocusCursorInsideQuery: shouldFocusCursorInsideQuery,
|
|
123
|
-
popupsMountPoint: (_popupMountRef$
|
|
124
|
-
popupsBoundariesElement: (_popupMountRef$
|
|
125
|
-
popupsScrollableElement: (_popupMountRef$
|
|
99
|
+
popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
|
|
100
|
+
popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
|
|
101
|
+
popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
|
|
126
102
|
onUndoRedo: onUndoRedo,
|
|
127
103
|
reopenQuery: reopenQuery,
|
|
128
104
|
api: api
|
|
129
|
-
}))
|
|
130
|
-
}
|
|
105
|
+
}));
|
|
106
|
+
}, typeaheadComponent, decorationId);
|
|
131
107
|
shouldFocusCursorInsideQuery = false;
|
|
132
108
|
return typeaheadComponent;
|
|
133
109
|
}, {
|
|
@@ -170,11 +146,7 @@ export const factoryDecorations = ({
|
|
|
170
146
|
if (!decoElement) {
|
|
171
147
|
return;
|
|
172
148
|
}
|
|
173
|
-
|
|
174
|
-
nodeViewPortalProviderAPI.remove(spec.key);
|
|
175
|
-
} else {
|
|
176
|
-
ReactDOM.unmountComponentAtNode(decoElement);
|
|
177
|
-
}
|
|
149
|
+
nodeViewPortalProviderAPI.remove(spec.key);
|
|
178
150
|
});
|
|
179
151
|
return true;
|
|
180
152
|
};
|
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
3
|
+
import { TypeAheadAvailableNodes } from '@atlaskit/editor-common/type-ahead';
|
|
4
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
5
|
+
import { TypeAheadMenu as TypeAheadMenuModern } from './modern/TypeAheadMenu';
|
|
3
6
|
import { TypeAheadMenu } from './TypeAheadMenu';
|
|
4
7
|
export function ContentComponent({
|
|
5
8
|
api,
|
|
6
9
|
editorView,
|
|
7
10
|
popupMountRef
|
|
8
11
|
}) {
|
|
12
|
+
var _typeAheadState$trigg;
|
|
9
13
|
const {
|
|
10
14
|
typeAheadState
|
|
11
15
|
} = useSharedPluginState(api, ['typeAhead']);
|
|
12
16
|
if (!typeAheadState) {
|
|
13
17
|
return null;
|
|
14
18
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
if (
|
|
20
|
+
// TODO: Also requires a check for editor appearance (needs to be enabled for full-page/full-width editor only ?)
|
|
21
|
+
!editorExperiment('platform_editor_controls', 'control') && ((_typeAheadState$trigg = typeAheadState.triggerHandler) === null || _typeAheadState$trigg === void 0 ? void 0 : _typeAheadState$trigg.id) === TypeAheadAvailableNodes.QUICK_INSERT) {
|
|
22
|
+
return /*#__PURE__*/React.createElement(TypeAheadMenuModern, {
|
|
23
|
+
editorView: editorView,
|
|
24
|
+
popupMountRef: popupMountRef,
|
|
25
|
+
typeAheadState: typeAheadState,
|
|
26
|
+
api: api
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
return /*#__PURE__*/React.createElement(TypeAheadMenu, {
|
|
30
|
+
editorView: editorView,
|
|
31
|
+
popupMountRef: popupMountRef,
|
|
32
|
+
typeAheadState: typeAheadState,
|
|
33
|
+
api: api
|
|
34
|
+
});
|
|
35
|
+
}
|
|
21
36
|
}
|