@atlaskit/editor-plugin-type-ahead 0.6.0 → 0.7.1
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/.eslintrc.js +5 -0
- package/CHANGELOG.md +12 -0
- package/dist/cjs/api.js +215 -0
- package/dist/cjs/commands/insert-type-ahead-item.js +205 -0
- package/dist/cjs/commands/update-list-items.js +23 -0
- package/dist/cjs/commands/update-query.js +27 -0
- package/dist/cjs/commands/update-selected-index.js +27 -0
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/insert-utils.js +107 -0
- package/dist/cjs/messages.js +79 -0
- package/dist/cjs/plugin.js +382 -0
- package/dist/cjs/pm-plugins/actions.js +16 -0
- package/dist/cjs/pm-plugins/decorations.js +148 -0
- package/dist/cjs/pm-plugins/input-rules.js +36 -0
- package/dist/cjs/pm-plugins/insert-item-plugin.js +22 -0
- package/dist/cjs/pm-plugins/key.js +8 -0
- package/dist/cjs/pm-plugins/main.js +110 -0
- package/dist/cjs/pm-plugins/reducer.js +158 -0
- package/dist/cjs/pm-plugins/utils.js +18 -0
- package/dist/cjs/stats-modifier.js +42 -0
- package/dist/cjs/transforms/close-type-ahead.js +13 -0
- package/dist/cjs/transforms/open-typeahead-at-cursor.js +75 -0
- package/dist/cjs/transforms/set-selection-before-query.js +18 -0
- package/dist/cjs/ui/AssistiveText.js +120 -0
- package/dist/cjs/ui/InputQuery.js +400 -0
- package/dist/cjs/ui/TypeAheadList.js +285 -0
- package/dist/cjs/ui/TypeAheadListItem.js +175 -0
- package/dist/cjs/ui/TypeAheadPopup.js +230 -0
- package/dist/cjs/ui/WrapperTypeAhead.js +127 -0
- package/dist/cjs/ui/hooks/use-item-insert.js +109 -0
- package/dist/cjs/ui/hooks/use-load-items.js +50 -0
- package/dist/cjs/ui/hooks/use-on-force-select.js +41 -0
- package/dist/cjs/utils.js +130 -0
- package/dist/es2019/api.js +205 -0
- package/dist/es2019/commands/insert-type-ahead-item.js +204 -0
- package/dist/es2019/commands/update-list-items.js +17 -0
- package/dist/es2019/commands/update-query.js +21 -0
- package/dist/es2019/commands/update-selected-index.js +21 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/insert-utils.js +106 -0
- package/dist/es2019/messages.js +73 -0
- package/dist/es2019/plugin.js +381 -0
- package/dist/es2019/pm-plugins/actions.js +10 -0
- package/dist/es2019/pm-plugins/decorations.js +148 -0
- package/dist/es2019/pm-plugins/input-rules.js +29 -0
- package/dist/es2019/pm-plugins/insert-item-plugin.js +16 -0
- package/dist/es2019/pm-plugins/key.js +2 -0
- package/dist/es2019/pm-plugins/main.js +106 -0
- package/dist/es2019/pm-plugins/reducer.js +160 -0
- package/dist/es2019/pm-plugins/utils.js +12 -0
- package/dist/es2019/stats-modifier.js +33 -0
- package/dist/es2019/transforms/close-type-ahead.js +7 -0
- package/dist/es2019/transforms/open-typeahead-at-cursor.js +71 -0
- package/dist/es2019/transforms/set-selection-before-query.js +10 -0
- package/dist/es2019/ui/AssistiveText.js +88 -0
- package/dist/es2019/ui/InputQuery.js +392 -0
- package/dist/es2019/ui/TypeAheadList.js +273 -0
- package/dist/es2019/ui/TypeAheadListItem.js +212 -0
- package/dist/es2019/ui/TypeAheadPopup.js +233 -0
- package/dist/es2019/ui/WrapperTypeAhead.js +109 -0
- package/dist/es2019/ui/hooks/use-item-insert.js +112 -0
- package/dist/es2019/ui/hooks/use-load-items.js +41 -0
- package/dist/es2019/ui/hooks/use-on-force-select.js +38 -0
- package/dist/es2019/utils.js +126 -0
- package/dist/esm/api.js +209 -0
- package/dist/esm/commands/insert-type-ahead-item.js +198 -0
- package/dist/esm/commands/update-list-items.js +17 -0
- package/dist/esm/commands/update-query.js +21 -0
- package/dist/esm/commands/update-selected-index.js +21 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/insert-utils.js +101 -0
- package/dist/esm/messages.js +73 -0
- package/dist/esm/plugin.js +374 -0
- package/dist/esm/pm-plugins/actions.js +10 -0
- package/dist/esm/pm-plugins/decorations.js +141 -0
- package/dist/esm/pm-plugins/input-rules.js +29 -0
- package/dist/esm/pm-plugins/insert-item-plugin.js +16 -0
- package/dist/esm/pm-plugins/key.js +2 -0
- package/dist/esm/pm-plugins/main.js +104 -0
- package/dist/esm/pm-plugins/reducer.js +151 -0
- package/dist/esm/pm-plugins/utils.js +12 -0
- package/dist/esm/stats-modifier.js +35 -0
- package/dist/esm/transforms/close-type-ahead.js +7 -0
- package/dist/esm/transforms/open-typeahead-at-cursor.js +69 -0
- package/dist/esm/transforms/set-selection-before-query.js +12 -0
- package/dist/esm/ui/AssistiveText.js +115 -0
- package/dist/esm/ui/InputQuery.js +389 -0
- package/dist/esm/ui/TypeAheadList.js +276 -0
- package/dist/esm/ui/TypeAheadListItem.js +165 -0
- package/dist/esm/ui/TypeAheadPopup.js +220 -0
- package/dist/esm/ui/WrapperTypeAhead.js +117 -0
- package/dist/esm/ui/hooks/use-item-insert.js +103 -0
- package/dist/esm/ui/hooks/use-load-items.js +43 -0
- package/dist/esm/ui/hooks/use-on-force-select.js +35 -0
- package/dist/esm/utils.js +124 -0
- package/dist/types/api.d.ts +60 -0
- package/dist/types/commands/insert-type-ahead-item.d.ts +12 -0
- package/dist/types/commands/update-list-items.d.ts +3 -0
- package/dist/types/commands/update-query.d.ts +2 -0
- package/dist/types/commands/update-selected-index.d.ts +2 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/insert-utils.d.ts +18 -0
- package/dist/types/messages.d.ts +72 -0
- package/dist/types/plugin.d.ts +10 -0
- package/dist/types/pm-plugins/actions.d.ts +9 -0
- package/dist/types/pm-plugins/decorations.d.ts +14 -0
- package/dist/types/pm-plugins/input-rules.d.ts +6 -0
- package/dist/types/pm-plugins/insert-item-plugin.d.ts +2 -0
- package/dist/types/pm-plugins/key.d.ts +3 -0
- package/dist/types/pm-plugins/main.d.ts +14 -0
- package/dist/types/pm-plugins/reducer.d.ts +10 -0
- package/dist/types/pm-plugins/utils.d.ts +4 -0
- package/dist/types/stats-modifier.d.ts +20 -0
- package/dist/types/transforms/close-type-ahead.d.ts +2 -0
- package/dist/types/transforms/open-typeahead-at-cursor.d.ts +11 -0
- package/dist/types/transforms/set-selection-before-query.d.ts +2 -0
- package/dist/types/ui/AssistiveText.d.ts +33 -0
- package/dist/types/ui/InputQuery.d.ts +26 -0
- package/dist/types/ui/TypeAheadList.d.ts +25 -0
- package/dist/types/ui/TypeAheadListItem.d.ts +18 -0
- package/dist/types/ui/TypeAheadPopup.d.ts +29 -0
- package/dist/types/ui/WrapperTypeAhead.d.ts +20 -0
- package/dist/types/ui/hooks/use-item-insert.d.ts +3 -0
- package/dist/types/ui/hooks/use-load-items.d.ts +3 -0
- package/dist/types/ui/hooks/use-on-force-select.d.ts +11 -0
- package/dist/types/utils.d.ts +27 -0
- package/dist/types-ts4.5/api.d.ts +60 -0
- package/dist/types-ts4.5/commands/insert-type-ahead-item.d.ts +12 -0
- package/dist/types-ts4.5/commands/update-list-items.d.ts +3 -0
- package/dist/types-ts4.5/commands/update-query.d.ts +2 -0
- package/dist/types-ts4.5/commands/update-selected-index.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/insert-utils.d.ts +18 -0
- package/dist/types-ts4.5/messages.d.ts +72 -0
- package/dist/types-ts4.5/plugin.d.ts +10 -0
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +9 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +14 -0
- package/dist/types-ts4.5/pm-plugins/input-rules.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/insert-item-plugin.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/key.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +14 -0
- package/dist/types-ts4.5/pm-plugins/reducer.d.ts +10 -0
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +4 -0
- package/dist/types-ts4.5/stats-modifier.d.ts +20 -0
- package/dist/types-ts4.5/transforms/close-type-ahead.d.ts +2 -0
- package/dist/types-ts4.5/transforms/open-typeahead-at-cursor.d.ts +11 -0
- package/dist/types-ts4.5/transforms/set-selection-before-query.d.ts +2 -0
- package/dist/types-ts4.5/ui/AssistiveText.d.ts +33 -0
- package/dist/types-ts4.5/ui/InputQuery.d.ts +26 -0
- package/dist/types-ts4.5/ui/TypeAheadList.d.ts +25 -0
- package/dist/types-ts4.5/ui/TypeAheadListItem.d.ts +18 -0
- package/dist/types-ts4.5/ui/TypeAheadPopup.d.ts +29 -0
- package/dist/types-ts4.5/ui/WrapperTypeAhead.d.ts +20 -0
- package/dist/types-ts4.5/ui/hooks/use-item-insert.d.ts +7 -0
- package/dist/types-ts4.5/ui/hooks/use-load-items.d.ts +3 -0
- package/dist/types-ts4.5/ui/hooks/use-on-force-select.d.ts +11 -0
- package/dist/types-ts4.5/utils.d.ts +27 -0
- package/package.json +21 -25
- package/report.api.md +29 -1
- package/tmp/api-report-tmp.d.ts +26 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { normaliseNestedLayout, safeInsert } from '@atlaskit/editor-common/insert';
|
|
2
|
+
import { Fragment, Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
function findInsertPoint(doc, pos, nodeToInsert) {
|
|
5
|
+
var $pos = doc.resolve(pos);
|
|
6
|
+
var createInsertPosition = function createInsertPosition(from, to) {
|
|
7
|
+
return {
|
|
8
|
+
from: from,
|
|
9
|
+
to: to || from
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Search for a valid position for nodeToInsert in progressively higher levels
|
|
14
|
+
for (var level = $pos.depth; level >= 0; level--) {
|
|
15
|
+
var nodeAtLevel = $pos.node(level);
|
|
16
|
+
|
|
17
|
+
// Try to replace the empty paragraph in the level above
|
|
18
|
+
// Scenario:
|
|
19
|
+
// doc(
|
|
20
|
+
// table(
|
|
21
|
+
// row(
|
|
22
|
+
// cell(
|
|
23
|
+
// p('{<>}'),
|
|
24
|
+
// ),
|
|
25
|
+
// )
|
|
26
|
+
// )
|
|
27
|
+
// )
|
|
28
|
+
var levelAbove = Math.max(level - 1, 0);
|
|
29
|
+
var parentNode = $pos.node(levelAbove);
|
|
30
|
+
// Special case: when this is true, the 'to' position should be the end
|
|
31
|
+
// of the empty paragraph
|
|
32
|
+
var isNodeAtLevelEmptyParagraph = nodeAtLevel.type.name === 'paragraph' && nodeAtLevel.content.size === 0;
|
|
33
|
+
var indexAtLevelAbove = $pos.index(levelAbove);
|
|
34
|
+
var canReplaceNodeAtLevelAbove = parentNode.canReplaceWith(indexAtLevelAbove, indexAtLevelAbove, nodeToInsert.type);
|
|
35
|
+
if (isNodeAtLevelEmptyParagraph && canReplaceNodeAtLevelAbove) {
|
|
36
|
+
var from = $pos.posAtIndex(indexAtLevelAbove, levelAbove);
|
|
37
|
+
return createInsertPosition(from, from + nodeAtLevel.nodeSize);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Try to insert this node right after the node in the level above
|
|
41
|
+
// Scenario:
|
|
42
|
+
// doc(
|
|
43
|
+
// panel(
|
|
44
|
+
// p('{<>}'),
|
|
45
|
+
// )
|
|
46
|
+
// )
|
|
47
|
+
var indexAfterAtLevelAbove = $pos.indexAfter(levelAbove);
|
|
48
|
+
var canInsertNodeAtLevelAbove = parentNode.canReplaceWith(indexAfterAtLevelAbove, indexAfterAtLevelAbove, nodeToInsert.type);
|
|
49
|
+
if (canInsertNodeAtLevelAbove) {
|
|
50
|
+
return createInsertPosition($pos.posAtIndex(indexAfterAtLevelAbove, levelAbove));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return createInsertPosition(0);
|
|
54
|
+
}
|
|
55
|
+
export var insertBlockNode = function insertBlockNode(_ref) {
|
|
56
|
+
var node = _ref.node,
|
|
57
|
+
tr = _ref.tr,
|
|
58
|
+
position = _ref.position;
|
|
59
|
+
var start = position.start,
|
|
60
|
+
end = position.end;
|
|
61
|
+
if (node.isText) {
|
|
62
|
+
return tr.replaceWith(start, end, node);
|
|
63
|
+
}
|
|
64
|
+
if (node.isBlock) {
|
|
65
|
+
tr.delete(start, end);
|
|
66
|
+
var mappedStart = tr.mapping.map(start);
|
|
67
|
+
var nodeNormalized = normaliseNestedLayout(tr, node);
|
|
68
|
+
|
|
69
|
+
// Handle edge cases for hr and mediaSingle
|
|
70
|
+
var inserted = safeInsert(nodeNormalized, mappedStart)(tr);
|
|
71
|
+
if (inserted) {
|
|
72
|
+
return tr;
|
|
73
|
+
}
|
|
74
|
+
var sliceInserted = Slice.maxOpen(Fragment.from(nodeNormalized));
|
|
75
|
+
var _findInsertPoint = findInsertPoint(tr.doc, mappedStart, nodeNormalized),
|
|
76
|
+
from = _findInsertPoint.from,
|
|
77
|
+
to = _findInsertPoint.to;
|
|
78
|
+
tr.replaceWith(from, to, node);
|
|
79
|
+
var openPosition = Math.min(from + (node.isAtom ? node.nodeSize : sliceInserted.openStart), tr.doc.content.size);
|
|
80
|
+
var FORWARD_DIRECTION = 1;
|
|
81
|
+
var nextSelection = TextSelection.findFrom(tr.doc.resolve(openPosition), FORWARD_DIRECTION, true);
|
|
82
|
+
if (nextSelection) {
|
|
83
|
+
return tr.setSelection(nextSelection);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return tr;
|
|
87
|
+
};
|
|
88
|
+
export var insertInlineNodeOrFragment = function insertInlineNodeOrFragment(_ref2) {
|
|
89
|
+
var maybeFragment = _ref2.maybeFragment,
|
|
90
|
+
tr = _ref2.tr,
|
|
91
|
+
position = _ref2.position,
|
|
92
|
+
selectInlineNode = _ref2.selectInlineNode;
|
|
93
|
+
var start = position.start,
|
|
94
|
+
end = position.end;
|
|
95
|
+
var fragment = maybeFragment instanceof PMNode ? Fragment.from(maybeFragment) : maybeFragment;
|
|
96
|
+
tr.replaceWith(start, end, fragment);
|
|
97
|
+
if (selectInlineNode) {
|
|
98
|
+
return tr.setSelection(NodeSelection.create(tr.doc, start));
|
|
99
|
+
}
|
|
100
|
+
return tr.setSelection(TextSelection.near(tr.doc.resolve(start + fragment.size)));
|
|
101
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl-next';
|
|
2
|
+
export var typeAheadListMessages = defineMessages({
|
|
3
|
+
typeAheadPopupLabel: {
|
|
4
|
+
id: 'fabric.editor.typeAhead.popupLabel',
|
|
5
|
+
defaultMessage: 'Typeahead results',
|
|
6
|
+
description: 'the result of a typeahead, similar to autocomplete results+'
|
|
7
|
+
},
|
|
8
|
+
quickInsertPopupLabel: {
|
|
9
|
+
id: 'fabric.editor.typeAhead.quickInsertPopupLabel',
|
|
10
|
+
defaultMessage: 'Shortcuts for inserts and formatting',
|
|
11
|
+
description: 'the result of a quick insert typeahead, similar to autocomplete results+'
|
|
12
|
+
},
|
|
13
|
+
quickInsertInputLabel: {
|
|
14
|
+
id: 'fabric.editor.typeAhead.quickInsertInputLabel',
|
|
15
|
+
defaultMessage: 'Begin typing to search or filter shortcut options',
|
|
16
|
+
description: 'assisitve text for typeahed input field'
|
|
17
|
+
},
|
|
18
|
+
emojiPopupLabel: {
|
|
19
|
+
id: 'fabric.editor.typeahead.emojiPopupLabel',
|
|
20
|
+
defaultMessage: 'Emoji shortcuts',
|
|
21
|
+
description: 'the result of a emoji typeahead, similar to autocomplete results+'
|
|
22
|
+
},
|
|
23
|
+
emojiInputLabel: {
|
|
24
|
+
id: 'fabric.editor.typeahead.emojiInputLabel',
|
|
25
|
+
defaultMessage: 'Begin typing to search or filter emoji options',
|
|
26
|
+
description: 'assisitve text for typeahed input field'
|
|
27
|
+
},
|
|
28
|
+
mentionPopupLabel: {
|
|
29
|
+
id: 'fabric.editor.typeahead.mentionPopupLabel',
|
|
30
|
+
defaultMessage: 'Users you can tag',
|
|
31
|
+
description: 'the aria label of a mention typeahead popup'
|
|
32
|
+
},
|
|
33
|
+
mentionInputLabel: {
|
|
34
|
+
id: 'fabric.editor.typeahead.mentionInputLabel',
|
|
35
|
+
defaultMessage: 'Begin typing to search for users to tag',
|
|
36
|
+
description: 'assisitve text for typeahed input field'
|
|
37
|
+
},
|
|
38
|
+
metionListItemLabel: {
|
|
39
|
+
id: 'fabric.editor.typeahead.metionListItemLabel',
|
|
40
|
+
defaultMessage: 'User {name} @{shortName}',
|
|
41
|
+
description: 'assistive text for user mention items username and nickname'
|
|
42
|
+
},
|
|
43
|
+
emojiListItemLabel: {
|
|
44
|
+
id: 'fabric.editor.typeahead.emojiListItemLabel',
|
|
45
|
+
defaultMessage: 'Emoji {name} Text Shortcut {shortcut}',
|
|
46
|
+
description: 'assistive text for emoji name and shortcut'
|
|
47
|
+
},
|
|
48
|
+
inputQueryAssistiveLabel: {
|
|
49
|
+
id: 'fabric.editor.inputQueryAssistiveTxt',
|
|
50
|
+
defaultMessage: 'When autocomplete results are available use up and down arrows to review and enter to select. Touch device users, explore by touch or with swipe gestures.',
|
|
51
|
+
description: 'Assistive text to the user when using typeahead shortcut'
|
|
52
|
+
},
|
|
53
|
+
searchResultsLabel: {
|
|
54
|
+
id: 'fabric.editor.searchResults',
|
|
55
|
+
defaultMessage: '{itemsLength, plural, one {# search result} other {# search results}} available',
|
|
56
|
+
description: 'Assistive text to the user when using typeahead shortcut and it preceeds with a number - Ex: 10 search results available'
|
|
57
|
+
},
|
|
58
|
+
noSearchResultsLabel: {
|
|
59
|
+
id: 'fabric.editor.noSearchResults',
|
|
60
|
+
defaultMessage: 'No search results',
|
|
61
|
+
description: 'Assistive text to the user when using typeahead shortcut'
|
|
62
|
+
},
|
|
63
|
+
descriptionLabel: {
|
|
64
|
+
id: 'fabric.editor.description',
|
|
65
|
+
defaultMessage: 'Description',
|
|
66
|
+
description: 'Description'
|
|
67
|
+
},
|
|
68
|
+
shortcutLabel: {
|
|
69
|
+
id: 'fabric.editor.shortcut',
|
|
70
|
+
defaultMessage: 'Text shortcut',
|
|
71
|
+
description: 'Text shortcut'
|
|
72
|
+
}
|
|
73
|
+
});
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Revamped typeahead using decorations instead of the `typeAheadQuery` mark
|
|
5
|
+
*
|
|
6
|
+
* https://product-fabric.atlassian.net/wiki/spaces/E/pages/2992177582/Technical+TypeAhead+Data+Flow
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { typeAheadQuery } from '@atlaskit/adf-schema';
|
|
12
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, fireAnalyticsEvent, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
13
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
14
|
+
import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
|
|
15
|
+
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
16
|
+
import { insertTypeAheadItem } from './commands/insert-type-ahead-item';
|
|
17
|
+
import { updateSelectedIndex } from './commands/update-selected-index';
|
|
18
|
+
import { inputRulePlugin } from './pm-plugins/input-rules';
|
|
19
|
+
import { createPlugin as createInsertItemPlugin } from './pm-plugins/insert-item-plugin';
|
|
20
|
+
import { pluginKey as typeAheadPluginKey } from './pm-plugins/key';
|
|
21
|
+
import { createPlugin } from './pm-plugins/main';
|
|
22
|
+
import { StatsModifier } from './stats-modifier';
|
|
23
|
+
import { closeTypeAhead } from './transforms/close-type-ahead';
|
|
24
|
+
import { openTypeAheadAtCursor } from './transforms/open-typeahead-at-cursor';
|
|
25
|
+
import { useItemInsert } from './ui/hooks/use-item-insert';
|
|
26
|
+
import { TypeAheadPopup } from './ui/TypeAheadPopup';
|
|
27
|
+
import { findHandler, getPluginState, getTypeAheadHandler, getTypeAheadQuery, isTypeAheadAllowed, isTypeAheadOpen } from './utils';
|
|
28
|
+
var TypeAheadMenu = /*#__PURE__*/React.memo(function (_ref) {
|
|
29
|
+
var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
|
|
30
|
+
var editorView = _ref.editorView,
|
|
31
|
+
popupMountRef = _ref.popupMountRef,
|
|
32
|
+
typeAheadState = _ref.typeAheadState,
|
|
33
|
+
fireAnalyticsCallback = _ref.fireAnalyticsCallback;
|
|
34
|
+
var isOpen = typeAheadState.decorationSet.find().length > 0;
|
|
35
|
+
var triggerHandler = typeAheadState.triggerHandler,
|
|
36
|
+
items = typeAheadState.items,
|
|
37
|
+
selectedIndex = typeAheadState.selectedIndex,
|
|
38
|
+
decorationElement = typeAheadState.decorationElement,
|
|
39
|
+
decorationSet = typeAheadState.decorationSet,
|
|
40
|
+
query = typeAheadState.query;
|
|
41
|
+
var _useItemInsert = useItemInsert(triggerHandler, editorView, items),
|
|
42
|
+
_useItemInsert2 = _slicedToArray(_useItemInsert, 3),
|
|
43
|
+
onItemInsert = _useItemInsert2[0],
|
|
44
|
+
onTextInsert = _useItemInsert2[1],
|
|
45
|
+
onItemMatch = _useItemInsert2[2];
|
|
46
|
+
var setSelectedItem = React.useCallback(function (_ref2) {
|
|
47
|
+
var nextIndex = _ref2.index;
|
|
48
|
+
queueMicrotask(function () {
|
|
49
|
+
updateSelectedIndex(nextIndex)(editorView.state, editorView.dispatch);
|
|
50
|
+
});
|
|
51
|
+
}, [editorView]);
|
|
52
|
+
var insertItem = React.useCallback(function () {
|
|
53
|
+
var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SelectItemMode.SELECTED;
|
|
54
|
+
var index = arguments.length > 1 ? arguments[1] : undefined;
|
|
55
|
+
queueMicrotask(function () {
|
|
56
|
+
onItemInsert({
|
|
57
|
+
mode: mode,
|
|
58
|
+
index: index,
|
|
59
|
+
query: query
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}, [onItemInsert, query]);
|
|
63
|
+
var cancel = React.useCallback(function (_ref3) {
|
|
64
|
+
var setSelectionAt = _ref3.setSelectionAt,
|
|
65
|
+
addPrefixTrigger = _ref3.addPrefixTrigger,
|
|
66
|
+
forceFocusOnEditor = _ref3.forceFocusOnEditor;
|
|
67
|
+
var fullQuery = addPrefixTrigger ? "".concat(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger).concat(query) : query;
|
|
68
|
+
onTextInsert({
|
|
69
|
+
forceFocusOnEditor: forceFocusOnEditor,
|
|
70
|
+
setSelectionAt: setSelectionAt,
|
|
71
|
+
text: fullQuery
|
|
72
|
+
});
|
|
73
|
+
}, [triggerHandler, onTextInsert, query]);
|
|
74
|
+
React.useEffect(function () {
|
|
75
|
+
if (!isOpen || !query) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
var isLastCharSpace = query[query.length - 1] === ' ';
|
|
79
|
+
if (!isLastCharSpace) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
var result = onItemMatch({
|
|
83
|
+
mode: SelectItemMode.SPACE,
|
|
84
|
+
query: query.trim()
|
|
85
|
+
});
|
|
86
|
+
if (!result) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}, [isOpen, query, onItemMatch]);
|
|
90
|
+
if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || items.length === 0) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return /*#__PURE__*/React.createElement(TypeAheadPopup, {
|
|
94
|
+
editorView: editorView,
|
|
95
|
+
popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
|
|
96
|
+
popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
|
|
97
|
+
popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
|
|
98
|
+
anchorElement: decorationElement,
|
|
99
|
+
triggerHandler: triggerHandler,
|
|
100
|
+
fireAnalyticsCallback: fireAnalyticsCallback,
|
|
101
|
+
items: items,
|
|
102
|
+
selectedIndex: selectedIndex,
|
|
103
|
+
setSelectedItem: setSelectedItem,
|
|
104
|
+
onItemInsert: insertItem,
|
|
105
|
+
decorationSet: decorationSet,
|
|
106
|
+
isEmptyQuery: !query,
|
|
107
|
+
cancel: cancel
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
var createOpenAtTransaction = function createOpenAtTransaction(editorAnalyticsAPI) {
|
|
111
|
+
return function (props) {
|
|
112
|
+
return function (tr) {
|
|
113
|
+
var triggerHandler = props.triggerHandler,
|
|
114
|
+
inputMethod = props.inputMethod;
|
|
115
|
+
openTypeAheadAtCursor({
|
|
116
|
+
triggerHandler: triggerHandler,
|
|
117
|
+
inputMethod: inputMethod
|
|
118
|
+
})({
|
|
119
|
+
tr: tr
|
|
120
|
+
});
|
|
121
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
122
|
+
action: ACTION.INVOKED,
|
|
123
|
+
actionSubject: ACTION_SUBJECT.TYPEAHEAD,
|
|
124
|
+
actionSubjectId: triggerHandler.id,
|
|
125
|
+
attributes: {
|
|
126
|
+
inputMethod: inputMethod
|
|
127
|
+
},
|
|
128
|
+
eventType: EVENT_TYPE.UI
|
|
129
|
+
})(tr);
|
|
130
|
+
return true;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
var createOpenTypeAhead = function createOpenTypeAhead(editorViewRef, editorAnalyticsAPI) {
|
|
135
|
+
return function (props) {
|
|
136
|
+
if (!editorViewRef.current) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
var view = editorViewRef.current;
|
|
140
|
+
var tr = view.state.tr;
|
|
141
|
+
createOpenAtTransaction(editorAnalyticsAPI)(props)(tr);
|
|
142
|
+
view.dispatch(tr);
|
|
143
|
+
return true;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
var createInsertTypeAheadItem = function createInsertTypeAheadItem(editorViewRef) {
|
|
147
|
+
return function (props) {
|
|
148
|
+
if (!editorViewRef.current) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
var view = editorViewRef.current;
|
|
152
|
+
var triggerHandler = props.triggerHandler,
|
|
153
|
+
contentItem = props.contentItem,
|
|
154
|
+
query = props.query,
|
|
155
|
+
sourceListItem = props.sourceListItem,
|
|
156
|
+
mode = props.mode;
|
|
157
|
+
insertTypeAheadItem(view)({
|
|
158
|
+
handler: triggerHandler,
|
|
159
|
+
item: contentItem,
|
|
160
|
+
mode: mode || SelectItemMode.SELECTED,
|
|
161
|
+
query: query,
|
|
162
|
+
sourceListItem: sourceListItem
|
|
163
|
+
});
|
|
164
|
+
return true;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
var createFindHandlerByTrigger = function createFindHandlerByTrigger(editorViewRef) {
|
|
168
|
+
return function (trigger) {
|
|
169
|
+
if (!editorViewRef.current) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
var view = editorViewRef.current;
|
|
173
|
+
return findHandler(trigger, view.state);
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
var createCloseTypeAhead = function createCloseTypeAhead(editorViewRef) {
|
|
177
|
+
return function (options) {
|
|
178
|
+
if (!editorViewRef.current) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
var view = editorViewRef.current;
|
|
182
|
+
var currentQuery = getTypeAheadQuery(view.state) || '';
|
|
183
|
+
var state = view.state;
|
|
184
|
+
var tr = state.tr;
|
|
185
|
+
if (options.attachCommand) {
|
|
186
|
+
var fakeDispatch = function fakeDispatch(customTr) {
|
|
187
|
+
tr = customTr;
|
|
188
|
+
};
|
|
189
|
+
options.attachCommand(state, fakeDispatch);
|
|
190
|
+
}
|
|
191
|
+
closeTypeAhead(tr);
|
|
192
|
+
if (options.insertCurrentQueryAsRawText && currentQuery && currentQuery.length > 0) {
|
|
193
|
+
var handler = getTypeAheadHandler(state);
|
|
194
|
+
if (!handler) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
var text = handler.trigger.concat(currentQuery);
|
|
198
|
+
tr.replaceSelectionWith(state.schema.text(text));
|
|
199
|
+
}
|
|
200
|
+
view.dispatch(tr);
|
|
201
|
+
if (!view.hasFocus()) {
|
|
202
|
+
view.focus();
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
*
|
|
210
|
+
* Revamped typeahead using decorations instead of the `typeAheadQuery` mark
|
|
211
|
+
*
|
|
212
|
+
* https://product-fabric.atlassian.net/wiki/spaces/E/pages/2992177582/Technical+TypeAhead+Data+Flow
|
|
213
|
+
*
|
|
214
|
+
*
|
|
215
|
+
*/
|
|
216
|
+
export var typeAheadPlugin = function typeAheadPlugin(_ref4) {
|
|
217
|
+
var _api$analytics, _api$analytics2;
|
|
218
|
+
var options = _ref4.config,
|
|
219
|
+
api = _ref4.api;
|
|
220
|
+
var fireAnalyticsCallback = fireAnalyticsEvent(options === null || options === void 0 ? void 0 : options.createAnalyticsEvent);
|
|
221
|
+
var popupMountRef = {
|
|
222
|
+
current: null
|
|
223
|
+
};
|
|
224
|
+
var editorViewRef = {
|
|
225
|
+
current: null
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
name: 'typeAhead',
|
|
229
|
+
marks: function marks() {
|
|
230
|
+
// We need to keep this to make sure
|
|
231
|
+
// All documents with typeahead marks will be loaded normally
|
|
232
|
+
return [{
|
|
233
|
+
name: 'typeAheadQuery',
|
|
234
|
+
mark: typeAheadQuery
|
|
235
|
+
}];
|
|
236
|
+
},
|
|
237
|
+
pmPlugins: function pmPlugins() {
|
|
238
|
+
var typeAhead = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
239
|
+
return [{
|
|
240
|
+
name: 'typeAhead',
|
|
241
|
+
plugin: function plugin(_ref5) {
|
|
242
|
+
var dispatch = _ref5.dispatch,
|
|
243
|
+
getIntl = _ref5.getIntl;
|
|
244
|
+
return createPlugin({
|
|
245
|
+
getIntl: getIntl,
|
|
246
|
+
popupMountRef: popupMountRef,
|
|
247
|
+
reactDispatch: dispatch,
|
|
248
|
+
typeAheadHandlers: typeAhead,
|
|
249
|
+
createAnalyticsEvent: options === null || options === void 0 ? void 0 : options.createAnalyticsEvent
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}, {
|
|
253
|
+
name: 'typeAheadEditorViewRef',
|
|
254
|
+
plugin: function plugin() {
|
|
255
|
+
return new SafePlugin({
|
|
256
|
+
view: function view(_view) {
|
|
257
|
+
editorViewRef.current = _view;
|
|
258
|
+
return {
|
|
259
|
+
destroy: function destroy() {
|
|
260
|
+
editorViewRef.current = null;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}, {
|
|
267
|
+
name: 'typeAheadInsertItem',
|
|
268
|
+
plugin: createInsertItemPlugin
|
|
269
|
+
}, {
|
|
270
|
+
name: 'typeAheadInputRule',
|
|
271
|
+
plugin: function plugin(_ref6) {
|
|
272
|
+
var schema = _ref6.schema,
|
|
273
|
+
featureFlags = _ref6.featureFlags;
|
|
274
|
+
return inputRulePlugin(schema, typeAhead, featureFlags);
|
|
275
|
+
}
|
|
276
|
+
}];
|
|
277
|
+
},
|
|
278
|
+
getSharedState: function getSharedState(editorState) {
|
|
279
|
+
if (!editorState) {
|
|
280
|
+
return {
|
|
281
|
+
query: '',
|
|
282
|
+
isOpen: false,
|
|
283
|
+
isAllowed: false,
|
|
284
|
+
currentHandler: undefined
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
var isOpen = isTypeAheadOpen(editorState);
|
|
288
|
+
return {
|
|
289
|
+
query: getTypeAheadQuery(editorState) || '',
|
|
290
|
+
currentHandler: getTypeAheadHandler(editorState),
|
|
291
|
+
isOpen: isOpen,
|
|
292
|
+
isAllowed: !isOpen
|
|
293
|
+
};
|
|
294
|
+
},
|
|
295
|
+
actions: {
|
|
296
|
+
isOpen: isTypeAheadOpen,
|
|
297
|
+
isAllowed: isTypeAheadAllowed,
|
|
298
|
+
open: createOpenTypeAhead(editorViewRef, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
|
|
299
|
+
openAtTransaction: createOpenAtTransaction(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions),
|
|
300
|
+
findHandlerByTrigger: createFindHandlerByTrigger(editorViewRef),
|
|
301
|
+
insert: createInsertTypeAheadItem(editorViewRef),
|
|
302
|
+
close: createCloseTypeAhead(editorViewRef)
|
|
303
|
+
},
|
|
304
|
+
contentComponent: function contentComponent(_ref7) {
|
|
305
|
+
var editorView = _ref7.editorView,
|
|
306
|
+
containerElement = _ref7.containerElement,
|
|
307
|
+
popupsMountPoint = _ref7.popupsMountPoint,
|
|
308
|
+
popupsBoundariesElement = _ref7.popupsBoundariesElement,
|
|
309
|
+
popupsScrollableElement = _ref7.popupsScrollableElement,
|
|
310
|
+
wrapperElement = _ref7.wrapperElement;
|
|
311
|
+
popupMountRef.current = {
|
|
312
|
+
popupsMountPoint: popupsMountPoint || wrapperElement || undefined,
|
|
313
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
314
|
+
popupsScrollableElement: popupsScrollableElement || containerElement || undefined
|
|
315
|
+
};
|
|
316
|
+
return /*#__PURE__*/React.createElement(WithPluginState, {
|
|
317
|
+
plugins: {
|
|
318
|
+
typeAheadState: typeAheadPluginKey
|
|
319
|
+
},
|
|
320
|
+
render: function render(_ref8) {
|
|
321
|
+
var typeAheadState = _ref8.typeAheadState;
|
|
322
|
+
if (!typeAheadState) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
return /*#__PURE__*/React.createElement(TypeAheadMenu, {
|
|
326
|
+
editorView: editorView,
|
|
327
|
+
popupMountRef: popupMountRef,
|
|
328
|
+
typeAheadState: typeAheadState,
|
|
329
|
+
fireAnalyticsCallback: fireAnalyticsCallback
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
},
|
|
334
|
+
onEditorViewStateUpdated: function onEditorViewStateUpdated(_ref9) {
|
|
335
|
+
var originalTransaction = _ref9.originalTransaction,
|
|
336
|
+
oldEditorState = _ref9.oldEditorState,
|
|
337
|
+
newEditorState = _ref9.newEditorState;
|
|
338
|
+
var oldPluginState = getPluginState(oldEditorState);
|
|
339
|
+
var newPluginState = getPluginState(newEditorState);
|
|
340
|
+
if (!oldPluginState || !newPluginState) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
var oldTriggerHandler = oldPluginState.triggerHandler;
|
|
344
|
+
var newTriggerHandler = newPluginState.triggerHandler;
|
|
345
|
+
var isANewHandler = oldTriggerHandler !== newTriggerHandler;
|
|
346
|
+
if (oldTriggerHandler !== null && oldTriggerHandler !== void 0 && oldTriggerHandler.dismiss && isANewHandler) {
|
|
347
|
+
var typeAheadMessage = originalTransaction.getMeta(typeAheadPluginKey);
|
|
348
|
+
var wasItemInserted = typeAheadMessage && typeAheadMessage.action === 'INSERT_RAW_QUERY';
|
|
349
|
+
oldTriggerHandler.dismiss({
|
|
350
|
+
editorState: newEditorState,
|
|
351
|
+
query: oldPluginState.query,
|
|
352
|
+
stats: (oldPluginState.stats || new StatsModifier()).serialize(),
|
|
353
|
+
wasItemInserted: wasItemInserted
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
if (newTriggerHandler !== null && newTriggerHandler !== void 0 && newTriggerHandler.onOpen && isANewHandler) {
|
|
357
|
+
newTriggerHandler.onOpen(newEditorState);
|
|
358
|
+
}
|
|
359
|
+
if (newTriggerHandler && isANewHandler && options !== null && options !== void 0 && options.createAnalyticsEvent) {
|
|
360
|
+
fireAnalyticsCallback({
|
|
361
|
+
payload: {
|
|
362
|
+
action: ACTION.INVOKED,
|
|
363
|
+
actionSubject: ACTION_SUBJECT.TYPEAHEAD,
|
|
364
|
+
actionSubjectId: newTriggerHandler.id || 'not_set',
|
|
365
|
+
attributes: {
|
|
366
|
+
inputMethod: newPluginState.inputMethod || INPUT_METHOD.KEYBOARD
|
|
367
|
+
},
|
|
368
|
+
eventType: EVENT_TYPE.UI
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export var ACTIONS = /*#__PURE__*/function (ACTIONS) {
|
|
2
|
+
ACTIONS["OPEN_TYPEAHEAD_AT_CURSOR"] = "OPEN_TYPEAHEAD_AT_CURSOR";
|
|
3
|
+
ACTIONS["CLOSE_TYPE_AHEAD"] = "CLOSE_TYPE_AHEAD";
|
|
4
|
+
ACTIONS["CHANGE_QUERY"] = "CHANGE_QUERY";
|
|
5
|
+
ACTIONS["INSERT_ITEM"] = "INSERT_ITEM";
|
|
6
|
+
ACTIONS["INSERT_RAW_QUERY"] = "INSERT_RAW_QUERY";
|
|
7
|
+
ACTIONS["UPDATE_LIST_ITEMS"] = "UPDATE_LIST_ITEMS";
|
|
8
|
+
ACTIONS["UPDATE_SELECTED_INDEX"] = "UPDATE_SELECTED_INDEX";
|
|
9
|
+
return ACTIONS;
|
|
10
|
+
}({});
|