@atlaskit/editor-plugin-type-ahead 16.1.15 → 17.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.
- package/CHANGELOG.md +26 -0
- package/dist/cjs/ui/InputQuery.js +13 -65
- package/dist/cjs/ui/registered-menu/quick-insert/TypeAheadQuickInsertItem.js +1 -0
- package/dist/cjs/ui/registered-menu/quick-insert/TypeAheadQuickInsertProvider.js +5 -0
- package/dist/es2019/ui/InputQuery.js +3 -54
- package/dist/es2019/ui/registered-menu/quick-insert/TypeAheadQuickInsertItem.js +1 -0
- package/dist/es2019/ui/registered-menu/quick-insert/TypeAheadQuickInsertProvider.js +5 -0
- package/dist/esm/ui/InputQuery.js +11 -63
- package/dist/esm/ui/registered-menu/quick-insert/TypeAheadQuickInsertItem.js +1 -0
- package/dist/esm/ui/registered-menu/quick-insert/TypeAheadQuickInsertProvider.js +5 -0
- package/package.json +9 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-type-ahead
|
|
2
2
|
|
|
3
|
+
## 17.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b15691abab5dc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b15691abab5dc) -
|
|
8
|
+
Clean up feature gate `platform_editor_quick_insert_placeholder`
|
|
9
|
+
- [`82fd62dcd2841`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/82fd62dcd2841) -
|
|
10
|
+
Add the experiment-gated registry-native Element Browser treatment for
|
|
11
|
+
`platform_editor_slash_command`.
|
|
12
|
+
|
|
13
|
+
`QuickInsertProvider` values must now provide a `surface` of either `typeahead` or
|
|
14
|
+
`element-browser`.
|
|
15
|
+
|
|
16
|
+
Prepare surface-specific Quick Insert item renderers for the `platform_editor_slash_command`
|
|
17
|
+
experiment.
|
|
18
|
+
|
|
19
|
+
Fix the registry Element Browser opening from View more and localize its accessibility labels.
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
|
|
23
|
+
## 16.1.16
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
|
|
3
29
|
## 16.1.15
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -14,12 +14,10 @@ var _w3cKeyname = require("w3c-keyname");
|
|
|
14
14
|
var _browser = require("@atlaskit/editor-common/browser");
|
|
15
15
|
var _typeAhead = require("@atlaskit/editor-common/type-ahead");
|
|
16
16
|
var _ui = require("@atlaskit/editor-common/ui");
|
|
17
|
-
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
18
17
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
19
|
-
var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
20
18
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
21
19
|
var _constants = require("../pm-plugins/constants");
|
|
22
|
-
var
|
|
20
|
+
var _utils = require("../pm-plugins/utils");
|
|
23
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); }
|
|
24
22
|
/**
|
|
25
23
|
* @jsxRuntime classic
|
|
@@ -28,23 +26,6 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
28
26
|
|
|
29
27
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled, @typescript-eslint/consistent-type-imports
|
|
30
28
|
|
|
31
|
-
var placeholderStyles = (0, _react2.css)({
|
|
32
|
-
'&::after': {
|
|
33
|
-
content: 'attr(data-place-holder)',
|
|
34
|
-
color: "var(--ds-text-subtlest, #6B6E76)",
|
|
35
|
-
position: 'relative',
|
|
36
|
-
padding: "var(--ds-space-025, 2px)",
|
|
37
|
-
left: "var(--ds-space-negative-050, -4px)",
|
|
38
|
-
backgroundColor: "var(--ds-background-neutral, #0515240F)",
|
|
39
|
-
// eslint-disable-next-line @atlaskit/design-system/no-unsafe-design-token-usage
|
|
40
|
-
borderRadius: "var(--ds-radius-small, 3px)"
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
var queryWithoutPlaceholderStyles = (0, _react2.css)({
|
|
44
|
-
'&::after': {
|
|
45
|
-
content: "''"
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
29
|
var querySpanStyles = (0, _react2.css)({
|
|
49
30
|
outline: 'none',
|
|
50
31
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
|
|
@@ -117,16 +98,6 @@ var InputQuery = exports.InputQuery = /*#__PURE__*/_react.default.memo(function
|
|
|
117
98
|
query = _useState2[0],
|
|
118
99
|
setQuery = _useState2[1];
|
|
119
100
|
var isEditorControlsEnabled = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1');
|
|
120
|
-
var isSearchPlaceholderEnabled = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _fg.fg)('platform_editor_quick_insert_placeholder');
|
|
121
|
-
var selection = editorView.state.selection;
|
|
122
|
-
var table = editorView.state.schema.nodes.table;
|
|
123
|
-
var _useState3 = (0, _react.useState)(isSearchPlaceholderEnabled && triggerQueryPrefix === '/' &&
|
|
124
|
-
// When triggered in very narrow table column, placeholder becomes ellipsis only
|
|
125
|
-
// hence we disable it for now and revisit this scenario in ED-27480
|
|
126
|
-
!(0, _utils.findParentNodeOfType)(table)(selection)),
|
|
127
|
-
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
128
|
-
showPlaceholder = _useState4[0],
|
|
129
|
-
setShowPlaceholder = _useState4[1];
|
|
130
101
|
var cleanedInputContent = (0, _react.useCallback)(function () {
|
|
131
102
|
var _ref$current;
|
|
132
103
|
var raw = ((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.textContent) || '';
|
|
@@ -136,15 +107,10 @@ var InputQuery = exports.InputQuery = /*#__PURE__*/_react.default.memo(function
|
|
|
136
107
|
var text = cleanedInputContent();
|
|
137
108
|
onQueryChange(text);
|
|
138
109
|
}, [onQueryChange, cleanedInputContent]);
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}, [cleanedInputContent]);
|
|
144
|
-
var _useState5 = (0, _react.useState)(false),
|
|
145
|
-
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
146
|
-
isInFocus = _useState6[0],
|
|
147
|
-
setInFocus = _useState6[1];
|
|
110
|
+
var _useState3 = (0, _react.useState)(false),
|
|
111
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
112
|
+
isInFocus = _useState4[0],
|
|
113
|
+
setInFocus = _useState4[1];
|
|
148
114
|
var checkKeyEvent = (0, _react.useCallback)(function (event) {
|
|
149
115
|
var _ref$current2;
|
|
150
116
|
var key = (0, _w3cKeyname.keyName)(event);
|
|
@@ -152,7 +118,7 @@ var InputQuery = exports.InputQuery = /*#__PURE__*/_react.default.memo(function
|
|
|
152
118
|
var raw = ((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.textContent) || '';
|
|
153
119
|
var text = cleanedInputContent();
|
|
154
120
|
var stopDefault = false;
|
|
155
|
-
var _ref3 = (0,
|
|
121
|
+
var _ref3 = (0, _utils.getPluginState)(editorView.state) || {},
|
|
156
122
|
selectedIndex = _ref3.selectedIndex,
|
|
157
123
|
removePrefixTriggerOnCancel = _ref3.removePrefixTriggerOnCancel;
|
|
158
124
|
setInFocus(true);
|
|
@@ -241,7 +207,7 @@ var InputQuery = exports.InputQuery = /*#__PURE__*/_react.default.memo(function
|
|
|
241
207
|
}
|
|
242
208
|
var browser = (0, _browser.getBrowserInfo)();
|
|
243
209
|
var element = ref.current;
|
|
244
|
-
var _ref4 = (0,
|
|
210
|
+
var _ref4 = (0, _utils.getPluginState)(editorView.state) || {},
|
|
245
211
|
removePrefixTriggerOnCancel = _ref4.removePrefixTriggerOnCancel;
|
|
246
212
|
var onFocusIn = function onFocusIn(_event) {
|
|
247
213
|
onQueryFocus();
|
|
@@ -277,10 +243,10 @@ var InputQuery = exports.InputQuery = /*#__PURE__*/_react.default.memo(function
|
|
|
277
243
|
event.preventDefault();
|
|
278
244
|
|
|
279
245
|
// insert the plain text into the type-ahead input field
|
|
280
|
-
var
|
|
281
|
-
if (
|
|
282
|
-
if (
|
|
283
|
-
var range =
|
|
246
|
+
var selection = window.getSelection();
|
|
247
|
+
if (selection && ref.current) {
|
|
248
|
+
if (selection.rangeCount > 0) {
|
|
249
|
+
var range = selection.getRangeAt(0);
|
|
284
250
|
range.deleteContents();
|
|
285
251
|
range.insertNode(document.createTextNode(plainText));
|
|
286
252
|
range.collapse(false);
|
|
@@ -439,29 +405,14 @@ var InputQuery = exports.InputQuery = /*#__PURE__*/_react.default.memo(function
|
|
|
439
405
|
});
|
|
440
406
|
}
|
|
441
407
|
}, [forceFocus, reopenQuery]);
|
|
442
|
-
var classNames = (0, _react.useMemo)(function () {
|
|
443
|
-
var classes = [];
|
|
444
|
-
if (showPlaceholder) {
|
|
445
|
-
// to avoid the placeholder wrapped to next line when triggered at the end of the line
|
|
446
|
-
// see placeholderWrapStyles in editor-core/src/ui/ContentStyles/index.tsx
|
|
447
|
-
classes.push('placeholder-decoration-wrap');
|
|
448
|
-
if (selection.$from.depth > 1) {
|
|
449
|
-
// to hide placeholder overflow as ellipsis
|
|
450
|
-
// see placeholderWrapStyles in editor-core/src/ui/ContentStyles/index.tsx
|
|
451
|
-
classes.push('placeholder-decoration-hide-overflow');
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
return classes.join(' ');
|
|
455
|
-
}, [showPlaceholder, selection]);
|
|
456
408
|
var assistiveHintID = _constants.TYPE_AHEAD_DECORATION_ELEMENT_ID + '__assistiveHint';
|
|
457
409
|
var intl = (0, _reactIntl.useIntl)();
|
|
458
410
|
return (0, _react2.jsx)(_react.Fragment, null, triggerQueryPrefix, (0, _react2.jsx)("span", {
|
|
459
|
-
css: [querySpanStyles
|
|
411
|
+
css: [querySpanStyles],
|
|
460
412
|
contentEditable: true,
|
|
461
413
|
ref: ref,
|
|
462
414
|
onKeyUp: onKeyUp,
|
|
463
415
|
tabIndex: -1,
|
|
464
|
-
onInput: isSearchPlaceholderEnabled ? onInput : undefined,
|
|
465
416
|
role: "combobox",
|
|
466
417
|
"aria-activedescendant": activeDescendantId,
|
|
467
418
|
"aria-controls": listId !== null && listId !== void 0 ? listId : _constants.TYPE_AHEAD_DECORATION_ELEMENT_ID,
|
|
@@ -469,10 +420,7 @@ var InputQuery = exports.InputQuery = /*#__PURE__*/_react.default.memo(function
|
|
|
469
420
|
"aria-expanded": resolvedOptionCount !== 0,
|
|
470
421
|
"aria-labelledby": assistiveHintID,
|
|
471
422
|
suppressContentEditableWarning: true,
|
|
472
|
-
"data-query-prefix": triggerQueryPrefix
|
|
473
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
|
|
474
|
-
,
|
|
475
|
-
className: classNames,
|
|
423
|
+
"data-query-prefix": triggerQueryPrefix,
|
|
476
424
|
"data-place-holder": intl.formatMessage(_typeAhead.typeAheadListMessages.quickInsertInputPlaceholderLabel)
|
|
477
425
|
}, query === null ? (0, _react2.jsx)("input", {
|
|
478
426
|
ref: inputRef,
|
|
@@ -23,6 +23,7 @@ var TypeAheadQuickInsertItem = exports.TypeAheadQuickInsertItem = function TypeA
|
|
|
23
23
|
isOffline: quickInsertContext.isOffline,
|
|
24
24
|
menuOpenId: quickInsertContext.menuOpenId,
|
|
25
25
|
surfaceContext: quickInsertContext.surfaceContext,
|
|
26
|
+
surface: 'typeahead',
|
|
26
27
|
item: {
|
|
27
28
|
id: id,
|
|
28
29
|
isSelected: isSelected
|
|
@@ -46,6 +46,11 @@ var TypeAheadQuickInsertProvider = exports.TypeAheadQuickInsertProvider = functi
|
|
|
46
46
|
editorView: editorView,
|
|
47
47
|
isOffline: isOffline,
|
|
48
48
|
menuOpenId: menuOpenId,
|
|
49
|
+
item: {
|
|
50
|
+
id: 'typeahead-quick-insert',
|
|
51
|
+
isSelected: false
|
|
52
|
+
},
|
|
53
|
+
surface: 'typeahead',
|
|
49
54
|
select: select,
|
|
50
55
|
surfaceContext: surfaceContext
|
|
51
56
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @jsxRuntime classic
|
|
3
3
|
* @jsx jsx
|
|
4
4
|
*/
|
|
5
|
-
import React, { Fragment, useCallback, useLayoutEffect,
|
|
5
|
+
import React, { Fragment, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
7
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled, @typescript-eslint/consistent-type-imports
|
|
8
8
|
import { css, jsx } from '@emotion/react';
|
|
@@ -11,29 +11,10 @@ import { keyName as keyNameNormalized } from 'w3c-keyname';
|
|
|
11
11
|
import { getBrowserInfo } from '@atlaskit/editor-common/browser';
|
|
12
12
|
import { SelectItemMode, typeAheadListMessages } from '@atlaskit/editor-common/type-ahead';
|
|
13
13
|
import { AssistiveText } from '@atlaskit/editor-common/ui';
|
|
14
|
-
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
15
14
|
import { blockNodesVerticalMargin } from '@atlaskit/editor-shared-styles';
|
|
16
|
-
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
17
15
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
18
16
|
import { CloseSelectionOptions, TYPE_AHEAD_DECORATION_ELEMENT_ID, TYPE_AHEAD_POPUP_CONTENT_CLASS } from '../pm-plugins/constants';
|
|
19
17
|
import { getPluginState } from '../pm-plugins/utils';
|
|
20
|
-
const placeholderStyles = css({
|
|
21
|
-
'&::after': {
|
|
22
|
-
content: 'attr(data-place-holder)',
|
|
23
|
-
color: "var(--ds-text-subtlest, #6B6E76)",
|
|
24
|
-
position: 'relative',
|
|
25
|
-
padding: "var(--ds-space-025, 2px)",
|
|
26
|
-
left: "var(--ds-space-negative-050, -4px)",
|
|
27
|
-
backgroundColor: "var(--ds-background-neutral, #0515240F)",
|
|
28
|
-
// eslint-disable-next-line @atlaskit/design-system/no-unsafe-design-token-usage
|
|
29
|
-
borderRadius: "var(--ds-radius-small, 3px)"
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
const queryWithoutPlaceholderStyles = css({
|
|
33
|
-
'&::after': {
|
|
34
|
-
content: `''`
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
18
|
const querySpanStyles = css({
|
|
38
19
|
outline: 'none',
|
|
39
20
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
|
|
@@ -104,15 +85,6 @@ export const InputQuery = /*#__PURE__*/React.memo(({
|
|
|
104
85
|
const inputRef = useRef(null);
|
|
105
86
|
const [query, setQuery] = useState(null);
|
|
106
87
|
const isEditorControlsEnabled = editorExperiment('platform_editor_controls', 'variant1');
|
|
107
|
-
const isSearchPlaceholderEnabled = editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_quick_insert_placeholder');
|
|
108
|
-
const selection = editorView.state.selection;
|
|
109
|
-
const {
|
|
110
|
-
table
|
|
111
|
-
} = editorView.state.schema.nodes;
|
|
112
|
-
const [showPlaceholder, setShowPlaceholder] = useState(isSearchPlaceholderEnabled && triggerQueryPrefix === '/' &&
|
|
113
|
-
// When triggered in very narrow table column, placeholder becomes ellipsis only
|
|
114
|
-
// hence we disable it for now and revisit this scenario in ED-27480
|
|
115
|
-
!findParentNodeOfType(table)(selection));
|
|
116
88
|
const cleanedInputContent = useCallback(() => {
|
|
117
89
|
var _ref$current;
|
|
118
90
|
const raw = ((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.textContent) || '';
|
|
@@ -122,11 +94,6 @@ export const InputQuery = /*#__PURE__*/React.memo(({
|
|
|
122
94
|
const text = cleanedInputContent();
|
|
123
95
|
onQueryChange(text);
|
|
124
96
|
}, [onQueryChange, cleanedInputContent]);
|
|
125
|
-
const onInput = useCallback(() => {
|
|
126
|
-
if (cleanedInputContent()) {
|
|
127
|
-
setShowPlaceholder(false);
|
|
128
|
-
}
|
|
129
|
-
}, [cleanedInputContent]);
|
|
130
97
|
const [isInFocus, setInFocus] = useState(false);
|
|
131
98
|
const checkKeyEvent = useCallback(event => {
|
|
132
99
|
var _ref$current2;
|
|
@@ -432,29 +399,14 @@ export const InputQuery = /*#__PURE__*/React.memo(({
|
|
|
432
399
|
});
|
|
433
400
|
}
|
|
434
401
|
}, [forceFocus, reopenQuery]);
|
|
435
|
-
const classNames = useMemo(() => {
|
|
436
|
-
const classes = [];
|
|
437
|
-
if (showPlaceholder) {
|
|
438
|
-
// to avoid the placeholder wrapped to next line when triggered at the end of the line
|
|
439
|
-
// see placeholderWrapStyles in editor-core/src/ui/ContentStyles/index.tsx
|
|
440
|
-
classes.push('placeholder-decoration-wrap');
|
|
441
|
-
if (selection.$from.depth > 1) {
|
|
442
|
-
// to hide placeholder overflow as ellipsis
|
|
443
|
-
// see placeholderWrapStyles in editor-core/src/ui/ContentStyles/index.tsx
|
|
444
|
-
classes.push('placeholder-decoration-hide-overflow');
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
return classes.join(' ');
|
|
448
|
-
}, [showPlaceholder, selection]);
|
|
449
402
|
const assistiveHintID = TYPE_AHEAD_DECORATION_ELEMENT_ID + '__assistiveHint';
|
|
450
403
|
const intl = useIntl();
|
|
451
404
|
return jsx(Fragment, null, triggerQueryPrefix, jsx("span", {
|
|
452
|
-
css: [querySpanStyles
|
|
405
|
+
css: [querySpanStyles],
|
|
453
406
|
contentEditable: true,
|
|
454
407
|
ref: ref,
|
|
455
408
|
onKeyUp: onKeyUp,
|
|
456
409
|
tabIndex: -1,
|
|
457
|
-
onInput: isSearchPlaceholderEnabled ? onInput : undefined,
|
|
458
410
|
role: "combobox",
|
|
459
411
|
"aria-activedescendant": activeDescendantId,
|
|
460
412
|
"aria-controls": listId !== null && listId !== void 0 ? listId : TYPE_AHEAD_DECORATION_ELEMENT_ID,
|
|
@@ -462,10 +414,7 @@ export const InputQuery = /*#__PURE__*/React.memo(({
|
|
|
462
414
|
"aria-expanded": resolvedOptionCount !== 0,
|
|
463
415
|
"aria-labelledby": assistiveHintID,
|
|
464
416
|
suppressContentEditableWarning: true,
|
|
465
|
-
"data-query-prefix": triggerQueryPrefix
|
|
466
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
|
|
467
|
-
,
|
|
468
|
-
className: classNames,
|
|
417
|
+
"data-query-prefix": triggerQueryPrefix,
|
|
469
418
|
"data-place-holder": intl.formatMessage(typeAheadListMessages.quickInsertInputPlaceholderLabel)
|
|
470
419
|
}, query === null ? jsx("input", {
|
|
471
420
|
ref: inputRef,
|
|
@@ -39,6 +39,11 @@ export const TypeAheadQuickInsertProvider = ({
|
|
|
39
39
|
editorView,
|
|
40
40
|
isOffline,
|
|
41
41
|
menuOpenId,
|
|
42
|
+
item: {
|
|
43
|
+
id: 'typeahead-quick-insert',
|
|
44
|
+
isSelected: false
|
|
45
|
+
},
|
|
46
|
+
surface: 'typeahead',
|
|
42
47
|
select,
|
|
43
48
|
surfaceContext
|
|
44
49
|
}), [editorView, isOffline, menuOpenId, select, surfaceContext]);
|
|
@@ -3,7 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
3
3
|
* @jsxRuntime classic
|
|
4
4
|
* @jsx jsx
|
|
5
5
|
*/
|
|
6
|
-
import React, { Fragment, useCallback, useLayoutEffect,
|
|
6
|
+
import React, { Fragment, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled, @typescript-eslint/consistent-type-imports
|
|
9
9
|
import { css, jsx } from '@emotion/react';
|
|
@@ -12,29 +12,10 @@ import { keyName as keyNameNormalized } from 'w3c-keyname';
|
|
|
12
12
|
import { getBrowserInfo } from '@atlaskit/editor-common/browser';
|
|
13
13
|
import { SelectItemMode, typeAheadListMessages } from '@atlaskit/editor-common/type-ahead';
|
|
14
14
|
import { AssistiveText } from '@atlaskit/editor-common/ui';
|
|
15
|
-
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
16
15
|
import { blockNodesVerticalMargin } from '@atlaskit/editor-shared-styles';
|
|
17
|
-
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
18
16
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
19
17
|
import { CloseSelectionOptions, TYPE_AHEAD_DECORATION_ELEMENT_ID, TYPE_AHEAD_POPUP_CONTENT_CLASS } from '../pm-plugins/constants';
|
|
20
18
|
import { getPluginState } from '../pm-plugins/utils';
|
|
21
|
-
var placeholderStyles = css({
|
|
22
|
-
'&::after': {
|
|
23
|
-
content: 'attr(data-place-holder)',
|
|
24
|
-
color: "var(--ds-text-subtlest, #6B6E76)",
|
|
25
|
-
position: 'relative',
|
|
26
|
-
padding: "var(--ds-space-025, 2px)",
|
|
27
|
-
left: "var(--ds-space-negative-050, -4px)",
|
|
28
|
-
backgroundColor: "var(--ds-background-neutral, #0515240F)",
|
|
29
|
-
// eslint-disable-next-line @atlaskit/design-system/no-unsafe-design-token-usage
|
|
30
|
-
borderRadius: "var(--ds-radius-small, 3px)"
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
var queryWithoutPlaceholderStyles = css({
|
|
34
|
-
'&::after': {
|
|
35
|
-
content: "''"
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
19
|
var querySpanStyles = css({
|
|
39
20
|
outline: 'none',
|
|
40
21
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
|
|
@@ -107,16 +88,6 @@ export var InputQuery = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
107
88
|
query = _useState2[0],
|
|
108
89
|
setQuery = _useState2[1];
|
|
109
90
|
var isEditorControlsEnabled = editorExperiment('platform_editor_controls', 'variant1');
|
|
110
|
-
var isSearchPlaceholderEnabled = editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_quick_insert_placeholder');
|
|
111
|
-
var selection = editorView.state.selection;
|
|
112
|
-
var table = editorView.state.schema.nodes.table;
|
|
113
|
-
var _useState3 = useState(isSearchPlaceholderEnabled && triggerQueryPrefix === '/' &&
|
|
114
|
-
// When triggered in very narrow table column, placeholder becomes ellipsis only
|
|
115
|
-
// hence we disable it for now and revisit this scenario in ED-27480
|
|
116
|
-
!findParentNodeOfType(table)(selection)),
|
|
117
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
118
|
-
showPlaceholder = _useState4[0],
|
|
119
|
-
setShowPlaceholder = _useState4[1];
|
|
120
91
|
var cleanedInputContent = useCallback(function () {
|
|
121
92
|
var _ref$current;
|
|
122
93
|
var raw = ((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.textContent) || '';
|
|
@@ -126,15 +97,10 @@ export var InputQuery = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
126
97
|
var text = cleanedInputContent();
|
|
127
98
|
onQueryChange(text);
|
|
128
99
|
}, [onQueryChange, cleanedInputContent]);
|
|
129
|
-
var
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}, [cleanedInputContent]);
|
|
134
|
-
var _useState5 = useState(false),
|
|
135
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
136
|
-
isInFocus = _useState6[0],
|
|
137
|
-
setInFocus = _useState6[1];
|
|
100
|
+
var _useState3 = useState(false),
|
|
101
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
102
|
+
isInFocus = _useState4[0],
|
|
103
|
+
setInFocus = _useState4[1];
|
|
138
104
|
var checkKeyEvent = useCallback(function (event) {
|
|
139
105
|
var _ref$current2;
|
|
140
106
|
var key = keyNameNormalized(event);
|
|
@@ -267,10 +233,10 @@ export var InputQuery = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
267
233
|
event.preventDefault();
|
|
268
234
|
|
|
269
235
|
// insert the plain text into the type-ahead input field
|
|
270
|
-
var
|
|
271
|
-
if (
|
|
272
|
-
if (
|
|
273
|
-
var range =
|
|
236
|
+
var selection = window.getSelection();
|
|
237
|
+
if (selection && ref.current) {
|
|
238
|
+
if (selection.rangeCount > 0) {
|
|
239
|
+
var range = selection.getRangeAt(0);
|
|
274
240
|
range.deleteContents();
|
|
275
241
|
range.insertNode(document.createTextNode(plainText));
|
|
276
242
|
range.collapse(false);
|
|
@@ -429,29 +395,14 @@ export var InputQuery = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
429
395
|
});
|
|
430
396
|
}
|
|
431
397
|
}, [forceFocus, reopenQuery]);
|
|
432
|
-
var classNames = useMemo(function () {
|
|
433
|
-
var classes = [];
|
|
434
|
-
if (showPlaceholder) {
|
|
435
|
-
// to avoid the placeholder wrapped to next line when triggered at the end of the line
|
|
436
|
-
// see placeholderWrapStyles in editor-core/src/ui/ContentStyles/index.tsx
|
|
437
|
-
classes.push('placeholder-decoration-wrap');
|
|
438
|
-
if (selection.$from.depth > 1) {
|
|
439
|
-
// to hide placeholder overflow as ellipsis
|
|
440
|
-
// see placeholderWrapStyles in editor-core/src/ui/ContentStyles/index.tsx
|
|
441
|
-
classes.push('placeholder-decoration-hide-overflow');
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
return classes.join(' ');
|
|
445
|
-
}, [showPlaceholder, selection]);
|
|
446
398
|
var assistiveHintID = TYPE_AHEAD_DECORATION_ELEMENT_ID + '__assistiveHint';
|
|
447
399
|
var intl = useIntl();
|
|
448
400
|
return jsx(Fragment, null, triggerQueryPrefix, jsx("span", {
|
|
449
|
-
css: [querySpanStyles
|
|
401
|
+
css: [querySpanStyles],
|
|
450
402
|
contentEditable: true,
|
|
451
403
|
ref: ref,
|
|
452
404
|
onKeyUp: onKeyUp,
|
|
453
405
|
tabIndex: -1,
|
|
454
|
-
onInput: isSearchPlaceholderEnabled ? onInput : undefined,
|
|
455
406
|
role: "combobox",
|
|
456
407
|
"aria-activedescendant": activeDescendantId,
|
|
457
408
|
"aria-controls": listId !== null && listId !== void 0 ? listId : TYPE_AHEAD_DECORATION_ELEMENT_ID,
|
|
@@ -459,10 +410,7 @@ export var InputQuery = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
459
410
|
"aria-expanded": resolvedOptionCount !== 0,
|
|
460
411
|
"aria-labelledby": assistiveHintID,
|
|
461
412
|
suppressContentEditableWarning: true,
|
|
462
|
-
"data-query-prefix": triggerQueryPrefix
|
|
463
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
|
|
464
|
-
,
|
|
465
|
-
className: classNames,
|
|
413
|
+
"data-query-prefix": triggerQueryPrefix,
|
|
466
414
|
"data-place-holder": intl.formatMessage(typeAheadListMessages.quickInsertInputPlaceholderLabel)
|
|
467
415
|
}, query === null ? jsx("input", {
|
|
468
416
|
ref: inputRef,
|
|
@@ -15,6 +15,7 @@ export var TypeAheadQuickInsertItem = function TypeAheadQuickInsertItem(_ref) {
|
|
|
15
15
|
isOffline: quickInsertContext.isOffline,
|
|
16
16
|
menuOpenId: quickInsertContext.menuOpenId,
|
|
17
17
|
surfaceContext: quickInsertContext.surfaceContext,
|
|
18
|
+
surface: 'typeahead',
|
|
18
19
|
item: {
|
|
19
20
|
id: id,
|
|
20
21
|
isSelected: isSelected
|
|
@@ -38,6 +38,11 @@ export var TypeAheadQuickInsertProvider = function TypeAheadQuickInsertProvider(
|
|
|
38
38
|
editorView: editorView,
|
|
39
39
|
isOffline: isOffline,
|
|
40
40
|
menuOpenId: menuOpenId,
|
|
41
|
+
item: {
|
|
42
|
+
id: 'typeahead-quick-insert',
|
|
43
|
+
isSelected: false
|
|
44
|
+
},
|
|
45
|
+
surface: 'typeahead',
|
|
41
46
|
select: select,
|
|
42
47
|
surfaceContext: surfaceContext
|
|
43
48
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-type-ahead",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
4
|
"description": "Type-ahead plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
],
|
|
22
22
|
"atlaskit:src": "src/index.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@atlaskit/adf-schema": "^57.
|
|
24
|
+
"@atlaskit/adf-schema": "^57.1.0",
|
|
25
25
|
"@atlaskit/css": "^1.0.0",
|
|
26
|
-
"@atlaskit/editor-plugin-analytics": "^
|
|
27
|
-
"@atlaskit/editor-plugin-connectivity": "^
|
|
28
|
-
"@atlaskit/editor-plugin-context-panel": "^
|
|
29
|
-
"@atlaskit/editor-plugin-metrics": "^
|
|
30
|
-
"@atlaskit/editor-plugin-ui-control-registry": "^
|
|
26
|
+
"@atlaskit/editor-plugin-analytics": "^16.0.0",
|
|
27
|
+
"@atlaskit/editor-plugin-connectivity": "^16.0.0",
|
|
28
|
+
"@atlaskit/editor-plugin-context-panel": "^18.0.0",
|
|
29
|
+
"@atlaskit/editor-plugin-metrics": "^17.0.0",
|
|
30
|
+
"@atlaskit/editor-plugin-ui-control-registry": "^10.0.0",
|
|
31
31
|
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
32
32
|
"@atlaskit/editor-shared-styles": "^4.0.0",
|
|
33
33
|
"@atlaskit/editor-ui-control-model": "^2.8.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@atlaskit/primitives": "^22.4.0",
|
|
42
42
|
"@atlaskit/prosemirror-history": "^1.2.0",
|
|
43
43
|
"@atlaskit/prosemirror-input-rules": "^4.0.0",
|
|
44
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
44
|
+
"@atlaskit/tmp-editor-statsig": "^160.0.0",
|
|
45
45
|
"@atlaskit/tokens": "^16.8.0",
|
|
46
46
|
"@atlaskit/visually-hidden": "^4.3.0",
|
|
47
47
|
"@babel/runtime": "^7.0.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"w3c-keyname": "^2.1.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@atlaskit/editor-common": "^
|
|
56
|
+
"@atlaskit/editor-common": "^120.0.0",
|
|
57
57
|
"react": "^18.2.0 || ^19.2.0",
|
|
58
58
|
"react-dom": "^18.2.0 || ^19.2.0",
|
|
59
59
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
@@ -90,9 +90,6 @@
|
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
92
|
"platform-feature-flags": {
|
|
93
|
-
"platform_editor_quick_insert_placeholder": {
|
|
94
|
-
"type": "boolean"
|
|
95
|
-
},
|
|
96
93
|
"platform_editor_ease_of_use_metrics": {
|
|
97
94
|
"type": "boolean"
|
|
98
95
|
},
|