@atlaskit/editor-core 148.0.0 → 149.0.3
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 +110 -0
- package/dist/cjs/create-editor/create-plugins-list.js +6 -1
- package/dist/cjs/editor.js +1 -4
- package/dist/cjs/index.js +24 -40
- package/dist/cjs/labs/next/presets/default.js +1 -1
- package/dist/cjs/messages.js +5 -0
- package/dist/cjs/nodeviews/SelectionBasedNodeView.js +1 -2
- package/dist/cjs/plugins/analytics/plugin.js +9 -7
- package/dist/cjs/plugins/analytics/types/enums.js +5 -0
- package/dist/cjs/plugins/analytics/types/type-ahead.js +5 -0
- package/dist/cjs/plugins/block-type/messages.js +10 -0
- package/dist/cjs/plugins/card/nodeviews/embedCard.js +1 -3
- package/dist/cjs/plugins/collab-edit/participants.js +15 -0
- package/dist/cjs/plugins/collab-edit/plugin-state.js +14 -0
- package/dist/cjs/plugins/collab-edit/ui/avatars-with-plugin-state.js +6 -4
- package/dist/cjs/plugins/collab-edit/ui/avatars.js +19 -2
- package/dist/cjs/plugins/collab-edit/utils.js +42 -2
- package/dist/cjs/plugins/date/actions.js +4 -2
- package/dist/cjs/plugins/date/index.js +1 -1
- package/dist/cjs/plugins/date/pm-plugins/utils.js +6 -1
- package/dist/cjs/plugins/emoji/index.js +143 -120
- package/dist/cjs/plugins/emoji/pm-plugins/ascii-input-rules.js +0 -14
- package/dist/cjs/plugins/expand/pm-plugins/keymap.js +3 -7
- package/dist/cjs/plugins/extension/actions.js +16 -16
- package/dist/cjs/plugins/extension/pm-plugins/main.js +4 -4
- package/dist/cjs/plugins/extension/ui/Extension/ExtensionComponent.js +5 -4
- package/dist/cjs/plugins/extension/ui/Extension/index.js +2 -2
- package/dist/cjs/plugins/feature-flags-context/feature-flags-from-props.js +3 -2
- package/dist/cjs/plugins/floating-toolbar/ui/ConfirmationModal.js +12 -14
- package/dist/cjs/plugins/floating-toolbar/ui/EditorEmojiAddIcon.js +35 -0
- package/dist/cjs/plugins/floating-toolbar/ui/EditorHideEmojiIcon.js +38 -0
- package/dist/cjs/plugins/floating-toolbar/ui/EmojiPickerButton.js +5 -7
- package/dist/cjs/plugins/help-dialog/ui/index.js +12 -18
- package/dist/cjs/plugins/help-dialog/ui/styles.js +2 -6
- package/dist/cjs/plugins/hyperlink/index.js +4 -10
- package/dist/cjs/plugins/insert-block/index.js +9 -8
- package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +7 -3
- package/dist/cjs/plugins/list/index.js +5 -0
- package/dist/cjs/plugins/macro/actions.js +14 -14
- package/dist/cjs/plugins/media/index.js +1 -0
- package/dist/cjs/plugins/media/nodeviews/mediaGroup.js +1 -0
- package/dist/cjs/plugins/media/pm-plugins/main.js +26 -14
- package/dist/cjs/plugins/media/styles.js +1 -1
- package/dist/cjs/plugins/media/toolbar/filePreviewItem.js +86 -0
- package/dist/cjs/plugins/media/toolbar/index.js +161 -44
- package/dist/cjs/plugins/media/toolbar/utils.js +77 -0
- package/dist/cjs/plugins/mentions/index.js +57 -602
- package/dist/cjs/plugins/mentions/pm-plugins/key.js +11 -0
- package/dist/cjs/plugins/mentions/pm-plugins/main.js +162 -0
- package/dist/cjs/plugins/mentions/pm-plugins/utils.js +12 -0
- package/dist/cjs/plugins/mentions/type-ahead/index.js +449 -0
- package/dist/cjs/plugins/mentions/ui/InviteItem/index.js +3 -1
- package/dist/cjs/plugins/mentions/ui/InviteItem/styles.js +8 -3
- package/dist/cjs/plugins/mentions/ui/ToolbarMention/index.js +3 -3
- package/dist/cjs/plugins/mentions/utils.js +24 -2
- package/dist/cjs/plugins/panel/index.js +46 -13
- package/dist/cjs/plugins/panel/nodeviews/panel.js +39 -25
- package/dist/cjs/plugins/panel/toolbar.js +94 -6
- package/dist/cjs/plugins/panel/toolbar.test.js +149 -16
- package/dist/cjs/plugins/paste/handlers.js +2 -2
- package/dist/cjs/plugins/paste/pm-plugins/analytics.js +6 -3
- package/dist/cjs/plugins/placeholder/index.js +6 -0
- package/dist/cjs/plugins/quick-insert/api.js +30 -0
- package/dist/cjs/plugins/quick-insert/assets/custom-panel.js +55 -0
- package/dist/cjs/plugins/quick-insert/assets/index.js +14 -1
- package/dist/cjs/plugins/quick-insert/index.js +10 -24
- package/dist/cjs/plugins/quick-insert/ui/ModalElementBrowser/index.js +1 -0
- package/dist/cjs/plugins/rank.js +1 -1
- package/dist/cjs/plugins/rule/index.js +1 -25
- package/dist/cjs/plugins/scroll-into-view/index.js +1 -4
- package/dist/cjs/plugins/selection/gap-cursor/actions.js +5 -6
- package/dist/cjs/plugins/selection/pm-plugins/selection-main.js +1 -3
- package/dist/cjs/plugins/status/actions.js +5 -2
- package/dist/cjs/plugins/status/plugin.js +1 -1
- package/dist/cjs/plugins/table/commands/selection.js +24 -24
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +8 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-state.js +14 -15
- package/dist/cjs/plugins/tasks-and-decisions/nodeviews/decisionItem.js +3 -1
- package/dist/cjs/plugins/tasks-and-decisions/nodeviews/taskItem.js +3 -1
- package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/keymaps.js +1 -2
- package/dist/cjs/plugins/text-formatting/pm-plugins/cursor.js +1 -4
- package/dist/cjs/plugins/type-ahead/api.js +243 -0
- package/dist/cjs/plugins/type-ahead/commands/insert-type-ahead-item.js +238 -0
- package/dist/cjs/plugins/type-ahead/commands/update-list-items.js +30 -0
- package/dist/cjs/plugins/type-ahead/commands/update-query.js +16 -18
- package/dist/cjs/plugins/type-ahead/commands/update-selected-index.js +36 -0
- package/dist/cjs/plugins/type-ahead/constants.js +25 -0
- package/dist/cjs/plugins/type-ahead/index.js +183 -52
- package/dist/cjs/plugins/type-ahead/insert-utils.js +132 -0
- package/dist/cjs/plugins/type-ahead/pm-plugins/actions.js +12 -9
- package/dist/cjs/plugins/type-ahead/pm-plugins/decorations.js +238 -0
- package/dist/cjs/plugins/type-ahead/pm-plugins/input-rules.js +20 -40
- package/dist/cjs/plugins/type-ahead/pm-plugins/insert-item-plugin.js +28 -0
- package/dist/cjs/plugins/type-ahead/pm-plugins/{plugin-key.js → key.js} +0 -0
- package/dist/cjs/plugins/type-ahead/pm-plugins/main.js +79 -424
- package/dist/cjs/plugins/type-ahead/pm-plugins/reducer.js +188 -0
- package/dist/cjs/plugins/type-ahead/pm-plugins/utils.js +26 -0
- package/dist/cjs/plugins/type-ahead/stats-modifier.js +49 -0
- package/dist/cjs/plugins/type-ahead/transforms/close-type-ahead.js +18 -0
- package/dist/cjs/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +51 -0
- package/dist/cjs/plugins/type-ahead/transforms/set-selection-before-query.js +24 -0
- package/dist/cjs/plugins/type-ahead/ui/DynamicHeightListItem.js +77 -0
- package/dist/cjs/plugins/type-ahead/ui/InputQuery.js +325 -0
- package/dist/cjs/plugins/type-ahead/ui/TypeAheadList.js +195 -0
- package/dist/cjs/plugins/type-ahead/ui/TypeAheadListItem.js +141 -0
- package/dist/cjs/plugins/type-ahead/ui/TypeAheadPopup.js +141 -0
- package/dist/cjs/plugins/type-ahead/ui/WrapperTypeAhead.js +151 -0
- package/dist/cjs/plugins/type-ahead/ui/hooks/use-dynamic-list-height-calculation.js +118 -0
- package/dist/cjs/plugins/type-ahead/ui/hooks/use-item-insert.js +132 -0
- package/dist/cjs/plugins/type-ahead/ui/hooks/use-load-items.js +61 -0
- package/dist/cjs/plugins/type-ahead/ui/hooks/use-on-force-select.js +50 -0
- package/dist/cjs/plugins/type-ahead/ui/hooks/use-resize-observer.js +70 -0
- package/dist/cjs/plugins/type-ahead/utils.js +127 -0
- package/dist/cjs/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +33 -2
- package/dist/cjs/plugins/view-update-subscription/index.js +19 -14
- package/dist/cjs/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +10 -3
- package/dist/cjs/plugins/view-update-subscription/subscribe/type-ahead-updates.js +46 -0
- package/dist/cjs/test-utils.js +17 -0
- package/dist/cjs/types/empty-state-handler.js +5 -0
- package/dist/cjs/ui/ConfigPanel/Fields/ColorPicker.js +4 -21
- package/dist/cjs/ui/ElementBrowser/ElementBrowser.js +4 -2
- package/dist/cjs/ui/ElementBrowser/InsertMenu.js +1 -0
- package/dist/cjs/ui/ElementBrowser/ModalElementBrowser.js +16 -23
- package/dist/cjs/ui/ElementBrowser/components/ElementList/ElementList.js +11 -4
- package/dist/cjs/ui/ElementBrowser/components/StatelessElementBrowser.js +12 -4
- package/dist/cjs/ui/PanelTextInput/index.js +1 -3
- package/dist/cjs/utils/compare.js +7 -7
- package/dist/cjs/utils/index.js +7 -8
- package/dist/cjs/utils/rich-media-utils.js +2 -2
- package/dist/cjs/utils/selection.js +6 -3
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/create-editor/create-plugins-list.js +6 -1
- package/dist/es2019/editor.js +1 -4
- package/dist/es2019/index.js +4 -6
- package/dist/es2019/labs/next/presets/default.js +2 -2
- package/dist/es2019/messages.js +5 -0
- package/dist/es2019/nodeviews/SelectionBasedNodeView.js +1 -2
- package/dist/es2019/plugins/analytics/plugin.js +5 -1
- package/dist/es2019/plugins/analytics/types/enums.js +5 -0
- package/dist/es2019/plugins/analytics/types/type-ahead.js +1 -0
- package/dist/es2019/plugins/block-type/messages.js +10 -0
- package/dist/es2019/plugins/card/nodeviews/embedCard.js +1 -3
- package/dist/es2019/plugins/collab-edit/participants.js +14 -0
- package/dist/es2019/plugins/collab-edit/plugin-state.js +17 -1
- package/dist/es2019/plugins/collab-edit/ui/avatars-with-plugin-state.js +6 -4
- package/dist/es2019/plugins/collab-edit/ui/avatars.js +17 -2
- package/dist/es2019/plugins/collab-edit/utils.js +34 -0
- package/dist/es2019/plugins/date/actions.js +4 -2
- package/dist/es2019/plugins/date/index.js +1 -1
- package/dist/es2019/plugins/date/pm-plugins/utils.js +6 -1
- package/dist/es2019/plugins/emoji/index.js +169 -146
- package/dist/es2019/plugins/emoji/pm-plugins/ascii-input-rules.js +0 -11
- package/dist/es2019/plugins/expand/pm-plugins/keymap.js +3 -6
- package/dist/es2019/plugins/extension/actions.js +16 -16
- package/dist/es2019/plugins/extension/pm-plugins/main.js +4 -4
- package/dist/es2019/plugins/extension/ui/Extension/ExtensionComponent.js +5 -4
- package/dist/es2019/plugins/extension/ui/Extension/index.js +2 -2
- package/dist/es2019/plugins/feature-flags-context/feature-flags-from-props.js +3 -2
- package/dist/es2019/plugins/floating-toolbar/ui/ConfirmationModal.js +12 -15
- package/dist/es2019/plugins/floating-toolbar/ui/EditorEmojiAddIcon.js +25 -0
- package/dist/es2019/plugins/floating-toolbar/ui/EditorHideEmojiIcon.js +28 -0
- package/dist/es2019/plugins/floating-toolbar/ui/EmojiPickerButton.js +3 -5
- package/dist/es2019/plugins/help-dialog/ui/index.js +20 -26
- package/dist/es2019/plugins/help-dialog/ui/styles.js +2 -2
- package/dist/es2019/plugins/hyperlink/index.js +4 -12
- package/dist/es2019/plugins/insert-block/index.js +4 -4
- package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +8 -4
- package/dist/es2019/plugins/list/index.js +20 -14
- package/dist/es2019/plugins/macro/actions.js +14 -14
- package/dist/es2019/plugins/media/index.js +1 -0
- package/dist/es2019/plugins/media/nodeviews/mediaGroup.js +1 -0
- package/dist/es2019/plugins/media/pm-plugins/main.js +27 -12
- package/dist/es2019/plugins/media/styles.js +7 -2
- package/dist/es2019/plugins/media/toolbar/filePreviewItem.js +59 -0
- package/dist/es2019/plugins/media/toolbar/index.js +158 -42
- package/dist/es2019/plugins/media/toolbar/utils.js +32 -0
- package/dist/es2019/plugins/mentions/index.js +34 -536
- package/dist/es2019/plugins/mentions/pm-plugins/key.js +2 -0
- package/dist/es2019/plugins/mentions/pm-plugins/main.js +138 -0
- package/dist/es2019/plugins/mentions/pm-plugins/utils.js +4 -0
- package/dist/es2019/plugins/mentions/type-ahead/index.js +394 -0
- package/dist/es2019/plugins/mentions/ui/InviteItem/index.js +2 -1
- package/dist/es2019/plugins/mentions/ui/InviteItem/styles.js +4 -2
- package/dist/es2019/plugins/mentions/ui/ToolbarMention/index.js +2 -2
- package/dist/es2019/plugins/mentions/utils.js +20 -1
- package/dist/es2019/plugins/panel/index.js +95 -62
- package/dist/es2019/plugins/panel/nodeviews/panel.js +7 -1
- package/dist/es2019/plugins/panel/toolbar.js +90 -6
- package/dist/es2019/plugins/panel/toolbar.test.js +131 -14
- package/dist/es2019/plugins/paste/handlers.js +2 -2
- package/dist/es2019/plugins/paste/pm-plugins/analytics.js +6 -3
- package/dist/es2019/plugins/placeholder/index.js +5 -0
- package/dist/es2019/plugins/quick-insert/api.js +18 -0
- package/dist/es2019/plugins/quick-insert/assets/custom-panel.js +45 -0
- package/dist/es2019/plugins/quick-insert/assets/index.js +6 -0
- package/dist/es2019/plugins/quick-insert/index.js +12 -23
- package/dist/es2019/plugins/quick-insert/search.js +1 -3
- package/dist/es2019/plugins/quick-insert/ui/ModalElementBrowser/index.js +1 -0
- package/dist/es2019/plugins/rank.js +1 -1
- package/dist/es2019/plugins/rule/index.js +1 -22
- package/dist/es2019/plugins/scroll-into-view/index.js +1 -3
- package/dist/es2019/plugins/selection/gap-cursor/actions.js +5 -6
- package/dist/es2019/plugins/selection/pm-plugins/selection-main.js +1 -3
- package/dist/es2019/plugins/status/actions.js +5 -2
- package/dist/es2019/plugins/status/plugin.js +1 -1
- package/dist/es2019/plugins/table/commands/selection.js +25 -25
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +8 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-state.js +14 -15
- package/dist/es2019/plugins/tasks-and-decisions/nodeviews/decisionItem.js +2 -1
- package/dist/es2019/plugins/tasks-and-decisions/nodeviews/taskItem.js +2 -1
- package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/keymaps.js +1 -2
- package/dist/es2019/plugins/text-formatting/pm-plugins/cursor.js +1 -4
- package/dist/es2019/plugins/type-ahead/api.js +224 -0
- package/dist/es2019/plugins/type-ahead/commands/insert-type-ahead-item.js +222 -0
- package/dist/es2019/plugins/type-ahead/commands/update-list-items.js +19 -0
- package/dist/es2019/plugins/type-ahead/commands/update-query.js +17 -15
- package/dist/es2019/plugins/type-ahead/commands/update-selected-index.js +25 -0
- package/dist/es2019/plugins/type-ahead/constants.js +15 -0
- package/dist/es2019/plugins/type-ahead/index.js +203 -78
- package/dist/es2019/plugins/type-ahead/insert-utils.js +119 -0
- package/dist/es2019/plugins/type-ahead/pm-plugins/actions.js +11 -8
- package/dist/es2019/plugins/type-ahead/pm-plugins/decorations.js +211 -0
- package/dist/es2019/plugins/type-ahead/pm-plugins/input-rules.js +18 -32
- package/dist/es2019/plugins/type-ahead/pm-plugins/insert-item-plugin.js +19 -0
- package/dist/es2019/plugins/type-ahead/pm-plugins/{plugin-key.js → key.js} +0 -0
- package/dist/es2019/plugins/type-ahead/pm-plugins/main.js +81 -401
- package/dist/es2019/plugins/type-ahead/pm-plugins/reducer.js +165 -0
- package/dist/es2019/plugins/type-ahead/pm-plugins/utils.js +16 -0
- package/dist/es2019/plugins/type-ahead/stats-modifier.js +41 -0
- package/dist/es2019/plugins/type-ahead/transforms/close-type-ahead.js +7 -0
- package/dist/es2019/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +40 -0
- package/dist/es2019/plugins/type-ahead/transforms/set-selection-before-query.js +11 -0
- package/dist/es2019/plugins/type-ahead/ui/DynamicHeightListItem.js +51 -0
- package/dist/es2019/plugins/type-ahead/ui/InputQuery.js +307 -0
- package/dist/es2019/plugins/type-ahead/ui/TypeAheadList.js +163 -0
- package/dist/es2019/plugins/type-ahead/ui/TypeAheadListItem.js +136 -0
- package/dist/es2019/plugins/type-ahead/ui/TypeAheadPopup.js +120 -0
- package/dist/es2019/plugins/type-ahead/ui/WrapperTypeAhead.js +110 -0
- package/dist/es2019/plugins/type-ahead/ui/hooks/use-dynamic-list-height-calculation.js +97 -0
- package/dist/es2019/plugins/type-ahead/ui/hooks/use-item-insert.js +126 -0
- package/dist/es2019/plugins/type-ahead/ui/hooks/use-load-items.js +43 -0
- package/dist/es2019/plugins/type-ahead/ui/hooks/use-on-force-select.js +41 -0
- package/dist/es2019/plugins/type-ahead/ui/hooks/use-resize-observer.js +53 -0
- package/dist/es2019/plugins/type-ahead/utils.js +93 -0
- package/dist/es2019/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +29 -2
- package/dist/es2019/plugins/view-update-subscription/index.js +19 -14
- package/dist/es2019/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +9 -3
- package/dist/es2019/plugins/view-update-subscription/subscribe/type-ahead-updates.js +34 -0
- package/dist/es2019/test-utils.js +7 -0
- package/dist/es2019/types/empty-state-handler.js +1 -0
- package/dist/es2019/ui/ConfigPanel/Fields/ColorPicker.js +4 -8
- package/dist/es2019/ui/ConfigPanel/transformers.js +9 -9
- package/dist/es2019/ui/ElementBrowser/ElementBrowser.js +4 -2
- package/dist/es2019/ui/ElementBrowser/InsertMenu.js +1 -0
- package/dist/es2019/ui/ElementBrowser/ModalElementBrowser.js +20 -21
- package/dist/es2019/ui/ElementBrowser/components/ElementList/ElementList.js +9 -2
- package/dist/es2019/ui/ElementBrowser/components/StatelessElementBrowser.js +12 -4
- package/dist/es2019/ui/PanelTextInput/index.js +1 -3
- package/dist/es2019/utils/compare.js +7 -7
- package/dist/es2019/utils/index.js +7 -8
- package/dist/es2019/utils/rich-media-utils.js +2 -2
- package/dist/es2019/utils/selection.js +6 -3
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/create-editor/create-plugins-list.js +6 -1
- package/dist/esm/editor.js +1 -4
- package/dist/esm/index.js +4 -6
- package/dist/esm/labs/next/presets/default.js +2 -2
- package/dist/esm/messages.js +5 -0
- package/dist/esm/nodeviews/SelectionBasedNodeView.js +1 -2
- package/dist/esm/plugins/analytics/plugin.js +8 -6
- package/dist/esm/plugins/analytics/types/enums.js +5 -0
- package/dist/esm/plugins/analytics/types/type-ahead.js +1 -0
- package/dist/esm/plugins/block-type/messages.js +10 -0
- package/dist/esm/plugins/card/nodeviews/embedCard.js +1 -3
- package/dist/esm/plugins/collab-edit/participants.js +15 -0
- package/dist/esm/plugins/collab-edit/plugin-state.js +15 -1
- package/dist/esm/plugins/collab-edit/ui/avatars-with-plugin-state.js +6 -4
- package/dist/esm/plugins/collab-edit/ui/avatars.js +17 -2
- package/dist/esm/plugins/collab-edit/utils.js +32 -0
- package/dist/esm/plugins/date/actions.js +4 -2
- package/dist/esm/plugins/date/index.js +1 -1
- package/dist/esm/plugins/date/pm-plugins/utils.js +6 -1
- package/dist/esm/plugins/emoji/index.js +136 -112
- package/dist/esm/plugins/emoji/pm-plugins/ascii-input-rules.js +0 -13
- package/dist/esm/plugins/expand/pm-plugins/keymap.js +3 -6
- package/dist/esm/plugins/extension/actions.js +16 -16
- package/dist/esm/plugins/extension/pm-plugins/main.js +4 -4
- package/dist/esm/plugins/extension/ui/Extension/ExtensionComponent.js +5 -4
- package/dist/esm/plugins/extension/ui/Extension/index.js +2 -2
- package/dist/esm/plugins/feature-flags-context/feature-flags-from-props.js +3 -2
- package/dist/esm/plugins/floating-toolbar/ui/ConfirmationModal.js +12 -15
- package/dist/esm/plugins/floating-toolbar/ui/EditorEmojiAddIcon.js +25 -0
- package/dist/esm/plugins/floating-toolbar/ui/EditorHideEmojiIcon.js +28 -0
- package/dist/esm/plugins/floating-toolbar/ui/EmojiPickerButton.js +3 -5
- package/dist/esm/plugins/help-dialog/ui/index.js +13 -19
- package/dist/esm/plugins/help-dialog/ui/styles.js +2 -6
- package/dist/esm/plugins/hyperlink/index.js +4 -10
- package/dist/esm/plugins/insert-block/index.js +5 -5
- package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +8 -4
- package/dist/esm/plugins/list/index.js +5 -0
- package/dist/esm/plugins/macro/actions.js +14 -14
- package/dist/esm/plugins/media/index.js +1 -0
- package/dist/esm/plugins/media/nodeviews/mediaGroup.js +1 -0
- package/dist/esm/plugins/media/pm-plugins/main.js +27 -14
- package/dist/esm/plugins/media/styles.js +2 -2
- package/dist/esm/plugins/media/toolbar/filePreviewItem.js +62 -0
- package/dist/esm/plugins/media/toolbar/index.js +154 -43
- package/dist/esm/plugins/media/toolbar/utils.js +60 -0
- package/dist/esm/plugins/mentions/index.js +45 -557
- package/dist/esm/plugins/mentions/pm-plugins/key.js +2 -0
- package/dist/esm/plugins/mentions/pm-plugins/main.js +145 -0
- package/dist/esm/plugins/mentions/pm-plugins/utils.js +4 -0
- package/dist/esm/plugins/mentions/type-ahead/index.js +415 -0
- package/dist/esm/plugins/mentions/ui/InviteItem/index.js +2 -1
- package/dist/esm/plugins/mentions/ui/InviteItem/styles.js +4 -2
- package/dist/esm/plugins/mentions/ui/ToolbarMention/index.js +2 -2
- package/dist/esm/plugins/mentions/utils.js +19 -0
- package/dist/esm/plugins/panel/index.js +44 -13
- package/dist/esm/plugins/panel/nodeviews/panel.js +36 -22
- package/dist/esm/plugins/panel/toolbar.js +92 -6
- package/dist/esm/plugins/panel/toolbar.test.js +148 -16
- package/dist/esm/plugins/paste/handlers.js +2 -2
- package/dist/esm/plugins/paste/pm-plugins/analytics.js +6 -3
- package/dist/esm/plugins/placeholder/index.js +5 -0
- package/dist/esm/plugins/quick-insert/api.js +20 -0
- package/dist/esm/plugins/quick-insert/assets/custom-panel.js +45 -0
- package/dist/esm/plugins/quick-insert/assets/index.js +12 -0
- package/dist/esm/plugins/quick-insert/index.js +10 -24
- package/dist/esm/plugins/quick-insert/search.js +1 -3
- package/dist/esm/plugins/quick-insert/ui/ModalElementBrowser/index.js +1 -0
- package/dist/esm/plugins/rank.js +1 -1
- package/dist/esm/plugins/rule/index.js +1 -22
- package/dist/esm/plugins/scroll-into-view/index.js +1 -3
- package/dist/esm/plugins/selection/gap-cursor/actions.js +5 -6
- package/dist/esm/plugins/selection/pm-plugins/selection-main.js +1 -3
- package/dist/esm/plugins/status/actions.js +5 -2
- package/dist/esm/plugins/status/plugin.js +1 -1
- package/dist/esm/plugins/table/commands/selection.js +24 -24
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +8 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-state.js +14 -15
- package/dist/esm/plugins/tasks-and-decisions/nodeviews/decisionItem.js +2 -1
- package/dist/esm/plugins/tasks-and-decisions/nodeviews/taskItem.js +2 -1
- package/dist/esm/plugins/tasks-and-decisions/pm-plugins/keymaps.js +1 -2
- package/dist/esm/plugins/text-formatting/pm-plugins/cursor.js +1 -4
- package/dist/esm/plugins/type-ahead/api.js +228 -0
- package/dist/esm/plugins/type-ahead/commands/insert-type-ahead-item.js +217 -0
- package/dist/esm/plugins/type-ahead/commands/update-list-items.js +19 -0
- package/dist/esm/plugins/type-ahead/commands/update-query.js +13 -13
- package/dist/esm/plugins/type-ahead/commands/update-selected-index.js +25 -0
- package/dist/esm/plugins/type-ahead/constants.js +15 -0
- package/dist/esm/plugins/type-ahead/index.js +173 -53
- package/dist/esm/plugins/type-ahead/insert-utils.js +116 -0
- package/dist/esm/plugins/type-ahead/pm-plugins/actions.js +11 -8
- package/dist/esm/plugins/type-ahead/pm-plugins/decorations.js +204 -0
- package/dist/esm/plugins/type-ahead/pm-plugins/input-rules.js +18 -33
- package/dist/esm/plugins/type-ahead/pm-plugins/insert-item-plugin.js +18 -0
- package/dist/esm/plugins/type-ahead/pm-plugins/{plugin-key.js → key.js} +0 -0
- package/dist/esm/plugins/type-ahead/pm-plugins/main.js +80 -393
- package/dist/esm/plugins/type-ahead/pm-plugins/reducer.js +168 -0
- package/dist/esm/plugins/type-ahead/pm-plugins/utils.js +16 -0
- package/dist/esm/plugins/type-ahead/stats-modifier.js +43 -0
- package/dist/esm/plugins/type-ahead/transforms/close-type-ahead.js +7 -0
- package/dist/esm/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +39 -0
- package/dist/esm/plugins/type-ahead/transforms/set-selection-before-query.js +13 -0
- package/dist/esm/plugins/type-ahead/ui/DynamicHeightListItem.js +51 -0
- package/dist/esm/plugins/type-ahead/ui/InputQuery.js +302 -0
- package/dist/esm/plugins/type-ahead/ui/TypeAheadList.js +168 -0
- package/dist/esm/plugins/type-ahead/ui/TypeAheadListItem.js +105 -0
- package/dist/esm/plugins/type-ahead/ui/TypeAheadPopup.js +114 -0
- package/dist/esm/plugins/type-ahead/ui/WrapperTypeAhead.js +125 -0
- package/dist/esm/plugins/type-ahead/ui/hooks/use-dynamic-list-height-calculation.js +101 -0
- package/dist/esm/plugins/type-ahead/ui/hooks/use-item-insert.js +118 -0
- package/dist/esm/plugins/type-ahead/ui/hooks/use-load-items.js +46 -0
- package/dist/esm/plugins/type-ahead/ui/hooks/use-on-force-select.js +38 -0
- package/dist/esm/plugins/type-ahead/ui/hooks/use-resize-observer.js +48 -0
- package/dist/esm/plugins/type-ahead/utils.js +88 -0
- package/dist/esm/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +33 -2
- package/dist/esm/plugins/view-update-subscription/index.js +19 -14
- package/dist/esm/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +10 -3
- package/dist/esm/plugins/view-update-subscription/subscribe/type-ahead-updates.js +33 -0
- package/dist/esm/test-utils.js +7 -0
- package/dist/esm/types/empty-state-handler.js +1 -0
- package/dist/esm/ui/ConfigPanel/Fields/ColorPicker.js +4 -14
- package/dist/esm/ui/ElementBrowser/ElementBrowser.js +4 -2
- package/dist/esm/ui/ElementBrowser/InsertMenu.js +1 -0
- package/dist/esm/ui/ElementBrowser/ModalElementBrowser.js +16 -23
- package/dist/esm/ui/ElementBrowser/components/ElementList/ElementList.js +10 -3
- package/dist/esm/ui/ElementBrowser/components/StatelessElementBrowser.js +12 -4
- package/dist/esm/ui/PanelTextInput/index.js +1 -3
- package/dist/esm/utils/compare.js +7 -7
- package/dist/esm/utils/index.js +7 -8
- package/dist/esm/utils/rich-media-utils.js +2 -2
- package/dist/esm/utils/selection.js +6 -3
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/commands/index.d.ts +1 -1
- package/dist/types/create-editor/ErrorBoundary.d.ts +1 -1
- package/dist/types/index.d.ts +3 -5
- package/dist/types/labs/next/full-page.d.ts +1 -1
- package/dist/types/labs/next/mobile.d.ts +1 -1
- package/dist/types/labs/next/presets/default.d.ts +2 -0
- package/dist/types/messages.d.ts +5 -0
- package/dist/types/plugins/alignment/commands/index.d.ts +2 -2
- package/dist/types/plugins/analytics/types/enums.d.ts +6 -1
- package/dist/types/plugins/analytics/types/events.d.ts +12 -2
- package/dist/types/plugins/analytics/types/general-events.d.ts +2 -23
- package/dist/types/plugins/analytics/types/type-ahead.d.ts +27 -0
- package/dist/types/plugins/block-type/messages.d.ts +10 -0
- package/dist/types/plugins/card/ui/ResizableEmbedCard.d.ts +1 -1
- package/dist/types/plugins/collab-edit/participants.d.ts +1 -0
- package/dist/types/plugins/collab-edit/ui/avatars.d.ts +3 -1
- package/dist/types/plugins/collab-edit/ui/invite-to-edit.d.ts +1 -1
- package/dist/types/plugins/collab-edit/utils.d.ts +4 -2
- package/dist/types/plugins/date/actions.d.ts +1 -1
- package/dist/types/plugins/date/pm-plugins/types.d.ts +1 -0
- package/dist/types/plugins/emoji/index.d.ts +2 -4
- package/dist/types/plugins/emoji/types.d.ts +2 -2
- package/dist/types/plugins/extension/ui/Extension/Extension/index.d.ts +2 -3
- package/dist/types/plugins/extension/ui/Extension/Extension/styles.d.ts +1 -1
- package/dist/types/plugins/extension/ui/Extension/ExtensionComponent.d.ts +2 -3
- package/dist/types/plugins/extension/ui/Extension/index.d.ts +2 -3
- package/dist/types/plugins/feature-flags-context/get-enabled-feature-flag-keys.d.ts +1 -1
- package/dist/types/plugins/find-replace/ui/styles.d.ts +3 -3
- package/dist/types/plugins/floating-toolbar/ui/EditorEmojiAddIcon.d.ts +1 -0
- package/dist/types/plugins/floating-toolbar/ui/EditorHideEmojiIcon.d.ts +1 -0
- package/dist/types/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.d.ts +1 -1
- package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/types.d.ts +0 -1
- package/dist/types/plugins/media/pm-plugins/main.d.ts +1 -0
- package/dist/types/plugins/media/toolbar/filePreviewItem.d.ts +7 -0
- package/dist/types/plugins/media/toolbar/utils.d.ts +4 -0
- package/dist/types/plugins/media/types.d.ts +3 -0
- package/dist/types/plugins/media/ui/ResizableMediaSingle/index.d.ts +1 -1
- package/dist/types/plugins/media/utils/media-single.d.ts +1 -1
- package/dist/types/plugins/mentions/analytics.d.ts +1 -1
- package/dist/types/plugins/mentions/index.d.ts +4 -30
- package/dist/types/plugins/mentions/pm-plugins/key.d.ts +3 -0
- package/dist/types/plugins/mentions/pm-plugins/main.d.ts +8 -0
- package/dist/types/plugins/mentions/pm-plugins/utils.d.ts +3 -0
- package/dist/types/plugins/mentions/type-ahead/index.d.ts +17 -0
- package/dist/types/plugins/mentions/types.d.ts +2 -0
- package/dist/types/plugins/mentions/ui/InviteItem/index.d.ts +1 -0
- package/dist/types/plugins/mentions/ui/InviteItem/styles.d.ts +2 -0
- package/dist/types/plugins/mentions/utils.d.ts +4 -0
- package/dist/types/plugins/panel/nodeviews/panel.d.ts +19 -3
- package/dist/types/plugins/paste/pm-plugins/analytics.d.ts +2 -0
- package/dist/types/plugins/quick-insert/api.d.ts +6 -0
- package/dist/types/plugins/quick-insert/assets/custom-panel.d.ts +1 -0
- package/dist/types/plugins/quick-insert/assets/index.d.ts +1 -0
- package/dist/types/plugins/quick-insert/search.d.ts +1 -1
- package/dist/types/plugins/quick-insert/types.d.ts +3 -0
- package/dist/types/plugins/status/actions.d.ts +3 -1
- package/dist/types/plugins/status/ui/statusPicker.d.ts +1 -1
- package/dist/types/plugins/type-ahead/api.d.ts +53 -0
- package/dist/types/plugins/type-ahead/commands/insert-type-ahead-item.d.ts +12 -0
- package/dist/types/plugins/type-ahead/commands/update-list-items.d.ts +3 -0
- package/dist/types/plugins/type-ahead/commands/update-query.d.ts +2 -2
- package/dist/types/plugins/type-ahead/commands/update-selected-index.d.ts +2 -0
- package/dist/types/plugins/type-ahead/constants.d.ts +10 -0
- package/dist/types/plugins/type-ahead/index.d.ts +5 -4
- package/dist/types/plugins/type-ahead/insert-utils.d.ts +18 -0
- package/dist/types/plugins/type-ahead/pm-plugins/actions.d.ts +9 -8
- package/dist/types/plugins/type-ahead/pm-plugins/decorations.d.ts +24 -0
- package/dist/types/plugins/type-ahead/pm-plugins/input-rules.d.ts +0 -1
- package/dist/types/plugins/type-ahead/pm-plugins/insert-item-plugin.d.ts +2 -0
- package/dist/types/plugins/type-ahead/pm-plugins/{plugin-key.d.ts → key.d.ts} +0 -0
- package/dist/types/plugins/type-ahead/pm-plugins/main.d.ts +12 -39
- package/dist/types/plugins/type-ahead/pm-plugins/reducer.d.ts +10 -0
- package/dist/types/plugins/type-ahead/pm-plugins/utils.d.ts +4 -0
- package/dist/types/plugins/type-ahead/stats-modifier.d.ts +20 -0
- package/dist/types/plugins/type-ahead/transforms/close-type-ahead.d.ts +2 -0
- package/dist/types/plugins/type-ahead/transforms/open-typeahead-at-cursor.d.ts +9 -0
- package/dist/types/plugins/type-ahead/transforms/set-selection-before-query.d.ts +2 -0
- package/dist/types/plugins/type-ahead/types.d.ts +95 -30
- package/dist/types/plugins/type-ahead/ui/DynamicHeightListItem.d.ts +21 -0
- package/dist/types/plugins/type-ahead/ui/InputQuery.d.ts +22 -0
- package/dist/types/plugins/type-ahead/ui/TypeAheadList.d.ts +11 -0
- package/dist/types/plugins/type-ahead/ui/TypeAheadListItem.d.ts +15 -0
- package/dist/types/plugins/type-ahead/ui/TypeAheadPopup.d.ts +22 -0
- package/dist/types/plugins/type-ahead/ui/WrapperTypeAhead.d.ts +20 -0
- package/dist/types/plugins/type-ahead/ui/hooks/use-dynamic-list-height-calculation.d.ts +25 -0
- package/dist/types/plugins/type-ahead/ui/hooks/use-item-insert.d.ts +3 -0
- package/dist/types/plugins/type-ahead/ui/hooks/use-load-items.d.ts +3 -0
- package/dist/types/plugins/type-ahead/ui/hooks/use-on-force-select.d.ts +11 -0
- package/dist/types/plugins/type-ahead/ui/hooks/use-resize-observer.d.ts +9 -0
- package/dist/types/plugins/type-ahead/utils.d.ts +18 -0
- package/dist/types/plugins/view-update-subscription/subscribe/type-ahead-updates.d.ts +9 -0
- package/dist/types/test-utils.d.ts +2 -0
- package/dist/types/types/editor-props.d.ts +2 -0
- package/dist/types/types/empty-state-handler.d.ts +7 -0
- package/dist/types/types/feature-flags.d.ts +8 -0
- package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
- package/dist/types/ui/ColorPickerButton/index.d.ts +1 -1
- package/dist/types/ui/ConfigPanel/ConfigPanel.d.ts +1 -1
- package/dist/types/ui/ConfigPanel/FormErrorBoundary.d.ts +1 -1
- package/dist/types/ui/ElementBrowser/ElementBrowser.d.ts +2 -0
- package/dist/types/ui/ElementBrowser/ModalElementBrowser.d.ts +2 -0
- package/dist/types/ui/ElementBrowser/components/CategoryList.d.ts +1 -1
- package/dist/types/ui/ElementBrowser/components/ElementList/ElementList.d.ts +5 -1
- package/dist/types/ui/ElementBrowser/components/StatelessElementBrowser.d.ts +3 -1
- package/dist/types/ui/LinkSearch/index.d.ts +20 -20
- package/dist/types/ui/PortalProvider/index.d.ts +1 -1
- package/dist/types/ui/ToolbarButton/index.d.ts +4 -4
- package/dist/types/ui/ToolbarButton/styles.d.ts +2 -2
- package/dist/types/utils/selection.d.ts +2 -2
- package/package.json +32 -29
- package/dist/cjs/plugins/emoji/commands/insert-emoji-query.js +0 -22
- package/dist/cjs/plugins/mentions/commands/insert-mention-query.js +0 -22
- package/dist/cjs/plugins/type-ahead/commands/dismiss.js +0 -44
- package/dist/cjs/plugins/type-ahead/commands/insert-query.js +0 -38
- package/dist/cjs/plugins/type-ahead/commands/items-list-updated.js +0 -25
- package/dist/cjs/plugins/type-ahead/commands/select-item.js +0 -163
- package/dist/cjs/plugins/type-ahead/commands/set-current-index.js +0 -25
- package/dist/cjs/plugins/type-ahead/pm-plugins/keymap.js +0 -115
- package/dist/cjs/plugins/type-ahead/ui/TypeAhead.js +0 -221
- package/dist/cjs/plugins/type-ahead/ui/TypeAheadItemsList.js +0 -239
- package/dist/cjs/plugins/type-ahead/utils/find-query-mark.js +0 -33
- package/dist/cjs/plugins/type-ahead/utils/is-query-active.js +0 -16
- package/dist/es2019/plugins/emoji/commands/insert-emoji-query.js +0 -13
- package/dist/es2019/plugins/mentions/commands/insert-mention-query.js +0 -13
- package/dist/es2019/plugins/type-ahead/commands/dismiss.js +0 -36
- package/dist/es2019/plugins/type-ahead/commands/insert-query.js +0 -26
- package/dist/es2019/plugins/type-ahead/commands/items-list-updated.js +0 -12
- package/dist/es2019/plugins/type-ahead/commands/select-item.js +0 -119
- package/dist/es2019/plugins/type-ahead/commands/set-current-index.js +0 -13
- package/dist/es2019/plugins/type-ahead/pm-plugins/keymap.js +0 -94
- package/dist/es2019/plugins/type-ahead/ui/TypeAhead.js +0 -175
- package/dist/es2019/plugins/type-ahead/ui/TypeAheadItemsList.js +0 -196
- package/dist/es2019/plugins/type-ahead/utils/find-query-mark.js +0 -29
- package/dist/es2019/plugins/type-ahead/utils/is-query-active.js +0 -9
- package/dist/esm/plugins/emoji/commands/insert-emoji-query.js +0 -13
- package/dist/esm/plugins/mentions/commands/insert-mention-query.js +0 -13
- package/dist/esm/plugins/type-ahead/commands/dismiss.js +0 -33
- package/dist/esm/plugins/type-ahead/commands/insert-query.js +0 -26
- package/dist/esm/plugins/type-ahead/commands/items-list-updated.js +0 -14
- package/dist/esm/plugins/type-ahead/commands/select-item.js +0 -132
- package/dist/esm/plugins/type-ahead/commands/set-current-index.js +0 -15
- package/dist/esm/plugins/type-ahead/pm-plugins/keymap.js +0 -94
- package/dist/esm/plugins/type-ahead/ui/TypeAhead.js +0 -202
- package/dist/esm/plugins/type-ahead/ui/TypeAheadItemsList.js +0 -204
- package/dist/esm/plugins/type-ahead/utils/find-query-mark.js +0 -24
- package/dist/esm/plugins/type-ahead/utils/is-query-active.js +0 -9
- package/dist/types/plugins/emoji/commands/insert-emoji-query.d.ts +0 -2
- package/dist/types/plugins/mentions/commands/insert-mention-query.d.ts +0 -2
- package/dist/types/plugins/type-ahead/commands/dismiss.d.ts +0 -2
- package/dist/types/plugins/type-ahead/commands/insert-query.d.ts +0 -2
- package/dist/types/plugins/type-ahead/commands/items-list-updated.d.ts +0 -3
- package/dist/types/plugins/type-ahead/commands/select-item.d.ts +0 -9
- package/dist/types/plugins/type-ahead/commands/set-current-index.d.ts +0 -2
- package/dist/types/plugins/type-ahead/pm-plugins/keymap.d.ts +0 -3
- package/dist/types/plugins/type-ahead/ui/TypeAhead.d.ts +0 -37
- package/dist/types/plugins/type-ahead/ui/TypeAheadItemsList.d.ts +0 -32
- package/dist/types/plugins/type-ahead/utils/find-query-mark.d.ts +0 -10
- package/dist/types/plugins/type-ahead/utils/is-query-active.d.ts +0 -2
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React, { useCallback, useMemo, useRef, useLayoutEffect } from 'react';
|
|
2
|
+
import { N200 } from '@atlaskit/theme/colors';
|
|
3
|
+
import { borderRadius } from '@atlaskit/theme/constants';
|
|
4
|
+
import Item from '@atlaskit/item';
|
|
5
|
+
import { relativeFontSizeToBase16 } from '@atlaskit/editor-shared-styles';
|
|
6
|
+
import styled from 'styled-components';
|
|
7
|
+
import IconFallback from '../../quick-insert/assets/fallback';
|
|
8
|
+
import { Shortcut } from '../../../ui/styles';
|
|
9
|
+
import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
|
|
10
|
+
export const ICON_HEIGHT = 40;
|
|
11
|
+
export const ICON_WIDTH = 40;
|
|
12
|
+
export const ItemIcon = styled.div`
|
|
13
|
+
width: ${ICON_WIDTH}px;
|
|
14
|
+
height: ${ICON_HEIGHT}px;
|
|
15
|
+
overflow: hidden;
|
|
16
|
+
border: 1px solid rgba(223, 225, 229, 0.5); /* N60 at 50% */
|
|
17
|
+
border-radius: ${borderRadius()}px;
|
|
18
|
+
box-sizing: border-box;
|
|
19
|
+
|
|
20
|
+
display: flex;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
align-items: center;
|
|
23
|
+
|
|
24
|
+
div {
|
|
25
|
+
width: ${ICON_WIDTH}px;
|
|
26
|
+
height: ${ICON_HEIGHT}px;
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
const ItemBody = styled.div`
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: row;
|
|
32
|
+
flex-wrap: nowrap;
|
|
33
|
+
justify-content: space-between;
|
|
34
|
+
line-height: 1.4;
|
|
35
|
+
`;
|
|
36
|
+
const ItemText = styled.div`
|
|
37
|
+
white-space: initial;
|
|
38
|
+
.item-description {
|
|
39
|
+
font-size: ${relativeFontSizeToBase16(11.67)};
|
|
40
|
+
color: ${N200};
|
|
41
|
+
margin-top: 4px;
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
const ItemAfter = styled.div`
|
|
45
|
+
flex: 0 0 auto;
|
|
46
|
+
`;
|
|
47
|
+
const hidden = {
|
|
48
|
+
overflow: 'hidden'
|
|
49
|
+
};
|
|
50
|
+
const FallbackIcon = /*#__PURE__*/React.memo(({
|
|
51
|
+
label
|
|
52
|
+
}) => {
|
|
53
|
+
return /*#__PURE__*/React.createElement(IconFallback, null);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const noop = () => {};
|
|
57
|
+
|
|
58
|
+
export const TypeAheadListItem = ({
|
|
59
|
+
item,
|
|
60
|
+
selectedIndex,
|
|
61
|
+
onItemHover,
|
|
62
|
+
onItemClick,
|
|
63
|
+
itemIndex
|
|
64
|
+
}) => {
|
|
65
|
+
const isSelected = itemIndex === selectedIndex; // It's possible for onMouseMove to be called multiple times in quick
|
|
66
|
+
// succession because the mousemove event can fire very rapidly. This
|
|
67
|
+
// provides an additional safety net to prevent that.
|
|
68
|
+
|
|
69
|
+
const mouseMoveCalled = useRef(false);
|
|
70
|
+
const onMouseMove = useCallback(() => {
|
|
71
|
+
if (isSelected || mouseMoveCalled.current) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
mouseMoveCalled.current = true;
|
|
76
|
+
onItemHover({
|
|
77
|
+
item,
|
|
78
|
+
index: itemIndex
|
|
79
|
+
});
|
|
80
|
+
}, [item, itemIndex, onItemHover, isSelected]);
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
if (!isSelected) {
|
|
83
|
+
mouseMoveCalled.current = false;
|
|
84
|
+
}
|
|
85
|
+
}, [isSelected]);
|
|
86
|
+
const {
|
|
87
|
+
icon,
|
|
88
|
+
title,
|
|
89
|
+
render: customRenderItem
|
|
90
|
+
} = item;
|
|
91
|
+
const elementIcon = useMemo(() => {
|
|
92
|
+
return /*#__PURE__*/React.createElement(ItemIcon, null, icon ? icon() : /*#__PURE__*/React.createElement(FallbackIcon, {
|
|
93
|
+
label: title
|
|
94
|
+
}));
|
|
95
|
+
}, [icon, title]);
|
|
96
|
+
const insertSelectedItem = useCallback(() => {
|
|
97
|
+
onItemClick(SelectItemMode.SELECTED, itemIndex);
|
|
98
|
+
}, [onItemClick, itemIndex]);
|
|
99
|
+
const customItem = useMemo(() => {
|
|
100
|
+
if (!customRenderItem) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const Comp = customRenderItem;
|
|
105
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
106
|
+
"aria-selected": isSelected,
|
|
107
|
+
"aria-label": title,
|
|
108
|
+
role: "option",
|
|
109
|
+
tabIndex: 0,
|
|
110
|
+
style: hidden,
|
|
111
|
+
onMouseMove: onMouseMove
|
|
112
|
+
}, /*#__PURE__*/React.createElement(Comp, {
|
|
113
|
+
onClick: insertSelectedItem,
|
|
114
|
+
isSelected: isSelected,
|
|
115
|
+
onHover: noop
|
|
116
|
+
}));
|
|
117
|
+
}, [customRenderItem, insertSelectedItem, onMouseMove, isSelected, title]);
|
|
118
|
+
|
|
119
|
+
if (customItem) {
|
|
120
|
+
return customItem;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return /*#__PURE__*/React.createElement(Item, {
|
|
124
|
+
onClick: insertSelectedItem,
|
|
125
|
+
onMouseMove: onMouseMove,
|
|
126
|
+
elemBefore: elementIcon,
|
|
127
|
+
isSelected: isSelected,
|
|
128
|
+
"aria-selected": isSelected,
|
|
129
|
+
"aria-label": item.title,
|
|
130
|
+
role: "option"
|
|
131
|
+
}, /*#__PURE__*/React.createElement(ItemBody, null, /*#__PURE__*/React.createElement(ItemText, null, /*#__PURE__*/React.createElement("div", {
|
|
132
|
+
className: "item-title"
|
|
133
|
+
}, item.title), item.description && /*#__PURE__*/React.createElement("div", {
|
|
134
|
+
className: "item-description"
|
|
135
|
+
}, item.description)), /*#__PURE__*/React.createElement(ItemAfter, null, item.keyshortcut && /*#__PURE__*/React.createElement(Shortcut, null, item.keyshortcut))));
|
|
136
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React, { useEffect, useMemo } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles';
|
|
4
|
+
import { Popup } from '@atlaskit/editor-common';
|
|
5
|
+
import { borderRadius, gridSize } from '@atlaskit/theme/constants';
|
|
6
|
+
import { N0, N60A, N50A } from '@atlaskit/theme/colors';
|
|
7
|
+
import { divide } from '@atlaskit/theme/math';
|
|
8
|
+
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '../../analytics';
|
|
9
|
+
import { TypeAheadList } from './TypeAheadList';
|
|
10
|
+
const TypeAheadContent = styled.div`
|
|
11
|
+
background: ${N0};
|
|
12
|
+
border-radius: ${borderRadius()}px;
|
|
13
|
+
box-shadow: 0 0 1px ${N60A}, 0 4px 8px -2px ${N50A};
|
|
14
|
+
padding: ${divide(gridSize, 2)}px 0;
|
|
15
|
+
width: 320px;
|
|
16
|
+
max-height: 380px; /* ~5.5 visibile items */
|
|
17
|
+
overflow-y: auto;
|
|
18
|
+
-ms-overflow-style: -ms-autohiding-scrollbar;
|
|
19
|
+
position: relative;
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
const Highlight = ({
|
|
23
|
+
state,
|
|
24
|
+
triggerHandler
|
|
25
|
+
}) => {
|
|
26
|
+
if (!(triggerHandler !== null && triggerHandler !== void 0 && triggerHandler.getHighlight)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const highlight = triggerHandler.getHighlight(state);
|
|
31
|
+
return highlight;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const OFFSET = [0, 8];
|
|
35
|
+
export const TypeAheadPopup = /*#__PURE__*/React.memo(props => {
|
|
36
|
+
const {
|
|
37
|
+
editorView,
|
|
38
|
+
triggerHandler,
|
|
39
|
+
anchorElement,
|
|
40
|
+
popupsMountPoint,
|
|
41
|
+
popupsBoundariesElement,
|
|
42
|
+
popupsScrollableElement,
|
|
43
|
+
items,
|
|
44
|
+
selectedIndex,
|
|
45
|
+
setSelectedItem,
|
|
46
|
+
onItemInsert,
|
|
47
|
+
fireAnalyticsCallback,
|
|
48
|
+
isEmptyQuery
|
|
49
|
+
} = props;
|
|
50
|
+
const startTime = useMemo(() => performance.now(), // In case those props changes
|
|
51
|
+
// we need to recreate the startTime
|
|
52
|
+
[items, isEmptyQuery, fireAnalyticsCallback, triggerHandler] // eslint-disable-line react-hooks/exhaustive-deps
|
|
53
|
+
);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!fireAnalyticsCallback) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const stopTime = performance.now();
|
|
60
|
+
const time = stopTime - startTime;
|
|
61
|
+
fireAnalyticsCallback({
|
|
62
|
+
payload: {
|
|
63
|
+
action: ACTION.RENDERED,
|
|
64
|
+
actionSubject: ACTION_SUBJECT.TYPEAHEAD,
|
|
65
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
66
|
+
attributes: {
|
|
67
|
+
time,
|
|
68
|
+
items: items.length,
|
|
69
|
+
initial: isEmptyQuery
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}, [startTime, items, fireAnalyticsCallback, isEmptyQuery, // In case the current triggerHandler changes
|
|
74
|
+
// e.g: Inserting a mention using the quick insert
|
|
75
|
+
// we need to send the event again
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
+
triggerHandler]);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!fireAnalyticsCallback) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fireAnalyticsCallback({
|
|
84
|
+
payload: {
|
|
85
|
+
action: ACTION.VIEWED,
|
|
86
|
+
actionSubject: ACTION_SUBJECT.TYPEAHEAD_ITEM,
|
|
87
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
88
|
+
attributes: {
|
|
89
|
+
index: selectedIndex,
|
|
90
|
+
items: items.length
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}, [items, fireAnalyticsCallback, selectedIndex, // In case the current triggerHandler changes
|
|
95
|
+
// e.g: Inserting a mention using the quick insert
|
|
96
|
+
// we need to send the event again
|
|
97
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
98
|
+
triggerHandler]);
|
|
99
|
+
return /*#__PURE__*/React.createElement(Popup, {
|
|
100
|
+
zIndex: akEditorFloatingDialogZIndex,
|
|
101
|
+
target: anchorElement,
|
|
102
|
+
mountTo: popupsMountPoint,
|
|
103
|
+
boundariesElement: popupsBoundariesElement,
|
|
104
|
+
scrollableElement: popupsScrollableElement,
|
|
105
|
+
fitHeight: 300,
|
|
106
|
+
fitWidth: 340,
|
|
107
|
+
offset: OFFSET
|
|
108
|
+
}, /*#__PURE__*/React.createElement(TypeAheadContent, {
|
|
109
|
+
className: "fabric-editor-typeahead"
|
|
110
|
+
}, /*#__PURE__*/React.createElement(Highlight, {
|
|
111
|
+
state: editorView.state,
|
|
112
|
+
triggerHandler: triggerHandler
|
|
113
|
+
}), /*#__PURE__*/React.createElement(TypeAheadList, {
|
|
114
|
+
items: items,
|
|
115
|
+
selectedIndex: selectedIndex,
|
|
116
|
+
onItemHover: setSelectedItem,
|
|
117
|
+
onItemClick: onItemInsert
|
|
118
|
+
})));
|
|
119
|
+
});
|
|
120
|
+
TypeAheadPopup.displayName = 'TypeAheadPopup';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React, { useMemo, useEffect, useLayoutEffect, useCallback, useRef, useState } from 'react';
|
|
2
|
+
import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
|
|
3
|
+
import { moveSelectedIndex, getPluginState } from '../utils';
|
|
4
|
+
import { updateQuery } from '../commands/update-query';
|
|
5
|
+
import { InputQuery } from './InputQuery';
|
|
6
|
+
import { useLoadItems } from './hooks/use-load-items';
|
|
7
|
+
import { useItemInsert } from './hooks/use-item-insert';
|
|
8
|
+
import { useOnForceSelect } from './hooks/use-on-force-select';
|
|
9
|
+
export const WrapperTypeAhead = /*#__PURE__*/React.memo(({
|
|
10
|
+
triggerHandler,
|
|
11
|
+
editorView,
|
|
12
|
+
anchorElement,
|
|
13
|
+
shouldFocusCursorInsideQuery,
|
|
14
|
+
popupsMountPoint,
|
|
15
|
+
popupsBoundariesElement,
|
|
16
|
+
popupsScrollableElement,
|
|
17
|
+
createAnalyticsEvent,
|
|
18
|
+
inputMethod,
|
|
19
|
+
getDecorationPosition,
|
|
20
|
+
reopenQuery,
|
|
21
|
+
onUndoRedo
|
|
22
|
+
}) => {
|
|
23
|
+
const [closed, setClosed] = useState(false);
|
|
24
|
+
const [query, setQuery] = useState(reopenQuery || '');
|
|
25
|
+
const queryRef = useRef(query);
|
|
26
|
+
const editorViewRef = useRef(editorView);
|
|
27
|
+
const items = useLoadItems(triggerHandler, editorView, query);
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
queryRef.current = query;
|
|
30
|
+
}, [query]);
|
|
31
|
+
const [onItemInsert, onTextInsert] = useItemInsert(triggerHandler, editorView, items);
|
|
32
|
+
const selectNextItem = useMemo(() => moveSelectedIndex({
|
|
33
|
+
editorView,
|
|
34
|
+
direction: 'next'
|
|
35
|
+
}), [editorView]);
|
|
36
|
+
const selectPreviousItem = useMemo(() => moveSelectedIndex({
|
|
37
|
+
editorView,
|
|
38
|
+
direction: 'previous'
|
|
39
|
+
}), [editorView]);
|
|
40
|
+
const cancel = useCallback(({
|
|
41
|
+
setSelectionAt,
|
|
42
|
+
addPrefixTrigger,
|
|
43
|
+
text,
|
|
44
|
+
forceFocusOnEditor
|
|
45
|
+
}) => {
|
|
46
|
+
setClosed(true);
|
|
47
|
+
const fullquery = addPrefixTrigger ? `${triggerHandler.trigger}${text}` : text;
|
|
48
|
+
onTextInsert({
|
|
49
|
+
forceFocusOnEditor,
|
|
50
|
+
setSelectionAt,
|
|
51
|
+
text: fullquery
|
|
52
|
+
});
|
|
53
|
+
}, [triggerHandler, onTextInsert]);
|
|
54
|
+
const insertSelectedItem = useCallback((mode = SelectItemMode.SELECTED) => {
|
|
55
|
+
const {
|
|
56
|
+
current: view
|
|
57
|
+
} = editorViewRef;
|
|
58
|
+
const {
|
|
59
|
+
selectedIndex
|
|
60
|
+
} = getPluginState(view.state);
|
|
61
|
+
setClosed(true);
|
|
62
|
+
queueMicrotask(() => {
|
|
63
|
+
onItemInsert({
|
|
64
|
+
mode,
|
|
65
|
+
index: selectedIndex,
|
|
66
|
+
query: queryRef.current
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}, [onItemInsert]);
|
|
70
|
+
const showTypeAheadPopupList = useCallback(() => {}, []);
|
|
71
|
+
const closePopup = useCallback(() => {
|
|
72
|
+
setClosed(true);
|
|
73
|
+
}, []);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const {
|
|
76
|
+
current: view
|
|
77
|
+
} = editorViewRef;
|
|
78
|
+
const pluginState = getPluginState(view.state);
|
|
79
|
+
|
|
80
|
+
if (query.length === 0 || query === pluginState.query || !pluginState.triggerHandler) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
updateQuery(query)(view.state, view.dispatch);
|
|
85
|
+
}, [query, reopenQuery]);
|
|
86
|
+
useOnForceSelect({
|
|
87
|
+
triggerHandler,
|
|
88
|
+
items,
|
|
89
|
+
query,
|
|
90
|
+
editorView,
|
|
91
|
+
closePopup
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (closed) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return /*#__PURE__*/React.createElement(InputQuery, {
|
|
99
|
+
triggerQueryPrefix: triggerHandler.trigger,
|
|
100
|
+
onQueryChange: setQuery,
|
|
101
|
+
onItemSelect: insertSelectedItem,
|
|
102
|
+
selectNextItem: selectNextItem,
|
|
103
|
+
selectPreviousItem: selectPreviousItem,
|
|
104
|
+
onQueryFocus: showTypeAheadPopupList,
|
|
105
|
+
cancel: cancel,
|
|
106
|
+
forceFocus: shouldFocusCursorInsideQuery,
|
|
107
|
+
onUndoRedo: onUndoRedo,
|
|
108
|
+
reopenQuery: reopenQuery
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { useMemo, useState, useRef, useCallback, useLayoutEffect } from 'react';
|
|
2
|
+
import throttle from 'lodash/throttle';
|
|
3
|
+
export const calcVisibleListHeight = ({
|
|
4
|
+
startIndex,
|
|
5
|
+
indexHeightMap,
|
|
6
|
+
limit,
|
|
7
|
+
listMaxHeight,
|
|
8
|
+
listItemEstimatedHeight
|
|
9
|
+
}) => {
|
|
10
|
+
let hasSpace = true;
|
|
11
|
+
let totalHeight = 0;
|
|
12
|
+
let i = startIndex;
|
|
13
|
+
|
|
14
|
+
while (hasSpace && i < limit) {
|
|
15
|
+
const nextHeight = indexHeightMap[i] || listItemEstimatedHeight;
|
|
16
|
+
|
|
17
|
+
if (totalHeight < listMaxHeight) {
|
|
18
|
+
totalHeight += nextHeight;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
i++;
|
|
22
|
+
hasSpace = totalHeight <= listMaxHeight;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return totalHeight;
|
|
26
|
+
};
|
|
27
|
+
export const useDynamicListHeightCalculation = ({
|
|
28
|
+
redrawListAtIndex,
|
|
29
|
+
getFirstVisibleIndex,
|
|
30
|
+
listLength,
|
|
31
|
+
listMaxHeight,
|
|
32
|
+
listItemEstimatedHeight
|
|
33
|
+
}) => {
|
|
34
|
+
const [renderedListHeight, setRenderedListHeight] = useState(null);
|
|
35
|
+
const indexHeightMap = useRef([]);
|
|
36
|
+
const resetScreenThrottled = useMemo(() => {
|
|
37
|
+
return throttle(() => {
|
|
38
|
+
requestAnimationFrame(() => {
|
|
39
|
+
const startIndex = getFirstVisibleIndex();
|
|
40
|
+
const lastItemRenderer = indexHeightMap.current[startIndex];
|
|
41
|
+
|
|
42
|
+
if (!lastItemRenderer) {
|
|
43
|
+
return;
|
|
44
|
+
} // This is an expensive method
|
|
45
|
+
// So, we are calling it only
|
|
46
|
+
// for the last top one visible
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
redrawListAtIndex(startIndex);
|
|
50
|
+
const nextListHeight = calcVisibleListHeight({
|
|
51
|
+
startIndex,
|
|
52
|
+
limit: listLength,
|
|
53
|
+
indexHeightMap: indexHeightMap.current,
|
|
54
|
+
listMaxHeight,
|
|
55
|
+
listItemEstimatedHeight
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (nextListHeight) {
|
|
59
|
+
setRenderedListHeight(nextListHeight);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}, 16 // wait for one frame
|
|
63
|
+
);
|
|
64
|
+
}, [redrawListAtIndex, listLength, listMaxHeight, listItemEstimatedHeight, getFirstVisibleIndex]);
|
|
65
|
+
const setListItemHeight = useCallback(({
|
|
66
|
+
index,
|
|
67
|
+
height
|
|
68
|
+
}) => {
|
|
69
|
+
if (typeof height !== 'number') {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
indexHeightMap.current[index] = height;
|
|
74
|
+
resetScreenThrottled();
|
|
75
|
+
}, [resetScreenThrottled]);
|
|
76
|
+
const getListItemHeight = useCallback(index => {
|
|
77
|
+
const result = indexHeightMap.current[index];
|
|
78
|
+
|
|
79
|
+
if (result && typeof result === 'number') {
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return listItemEstimatedHeight;
|
|
84
|
+
}, [listItemEstimatedHeight]);
|
|
85
|
+
useLayoutEffect(() => {
|
|
86
|
+
indexHeightMap.current = [];
|
|
87
|
+
return () => {
|
|
88
|
+
indexHeightMap.current = [];
|
|
89
|
+
};
|
|
90
|
+
}, [listLength]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
getListItemHeight,
|
|
94
|
+
setListItemHeight,
|
|
95
|
+
renderedListHeight
|
|
96
|
+
};
|
|
97
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { useLayoutEffect, useCallback, useRef } from 'react';
|
|
2
|
+
import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
|
|
3
|
+
import { closeTypeAhead } from '../../transforms/close-type-ahead';
|
|
4
|
+
import { setSelectionBeforeQuery } from '../../transforms/set-selection-before-query';
|
|
5
|
+
import { insertTypeAheadItem } from '../../commands/insert-type-ahead-item';
|
|
6
|
+
import { CloseSelectionOptions } from '../../constants';
|
|
7
|
+
|
|
8
|
+
const insertRawQuery = ({
|
|
9
|
+
view,
|
|
10
|
+
setSelectionAt,
|
|
11
|
+
text,
|
|
12
|
+
forceFocusOnEditor
|
|
13
|
+
}) => {
|
|
14
|
+
const {
|
|
15
|
+
tr,
|
|
16
|
+
schema
|
|
17
|
+
} = view.state;
|
|
18
|
+
closeTypeAhead(tr);
|
|
19
|
+
|
|
20
|
+
if (text.length > 0) {
|
|
21
|
+
tr.replaceSelectionWith(schema.text(text));
|
|
22
|
+
|
|
23
|
+
if (setSelectionAt === CloseSelectionOptions.BEFORE_TEXT_INSERTED) {
|
|
24
|
+
setSelectionBeforeQuery(text)(tr);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
view.dispatch(tr);
|
|
29
|
+
|
|
30
|
+
if (forceFocusOnEditor) {
|
|
31
|
+
view.focus();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const useItemInsert = (triggerHandler, editorView, items) => {
|
|
36
|
+
const editorViewRef = useRef(editorView);
|
|
37
|
+
const itemsRef = useRef(items);
|
|
38
|
+
const onTextInsert = useCallback(({
|
|
39
|
+
setSelectionAt,
|
|
40
|
+
text,
|
|
41
|
+
forceFocusOnEditor
|
|
42
|
+
}) => {
|
|
43
|
+
if (!triggerHandler) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
current: view
|
|
49
|
+
} = editorViewRef;
|
|
50
|
+
insertRawQuery({
|
|
51
|
+
view,
|
|
52
|
+
setSelectionAt,
|
|
53
|
+
text,
|
|
54
|
+
forceFocusOnEditor
|
|
55
|
+
});
|
|
56
|
+
}, [triggerHandler]);
|
|
57
|
+
const onItemInsert = useCallback(({
|
|
58
|
+
mode,
|
|
59
|
+
index,
|
|
60
|
+
query
|
|
61
|
+
}) => {
|
|
62
|
+
const sourceListItem = itemsRef.current;
|
|
63
|
+
|
|
64
|
+
if (sourceListItem.length === 0 || !triggerHandler) {
|
|
65
|
+
const text = `${triggerHandler.trigger}${query}`;
|
|
66
|
+
onTextInsert({
|
|
67
|
+
forceFocusOnEditor: true,
|
|
68
|
+
setSelectionAt: CloseSelectionOptions.AFTER_TEXT_INSERTED,
|
|
69
|
+
text
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const itemToInsert = sourceListItem[index];
|
|
75
|
+
|
|
76
|
+
if (!itemToInsert) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const {
|
|
81
|
+
current: view
|
|
82
|
+
} = editorViewRef;
|
|
83
|
+
insertTypeAheadItem(view)({
|
|
84
|
+
item: itemToInsert,
|
|
85
|
+
handler: triggerHandler,
|
|
86
|
+
mode,
|
|
87
|
+
query,
|
|
88
|
+
sourceListItem
|
|
89
|
+
});
|
|
90
|
+
}, [triggerHandler, onTextInsert]);
|
|
91
|
+
const onItemMatch = useCallback(({
|
|
92
|
+
mode,
|
|
93
|
+
query
|
|
94
|
+
}) => {
|
|
95
|
+
const _items = itemsRef.current;
|
|
96
|
+
|
|
97
|
+
if (_items && _items.length > 1) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (_items.length === 1) {
|
|
102
|
+
queueMicrotask(() => {
|
|
103
|
+
onItemInsert({
|
|
104
|
+
mode,
|
|
105
|
+
query,
|
|
106
|
+
index: 0
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
} else {
|
|
110
|
+
const text = `${triggerHandler.trigger}${query}`;
|
|
111
|
+
queueMicrotask(() => {
|
|
112
|
+
onTextInsert({
|
|
113
|
+
forceFocusOnEditor: true,
|
|
114
|
+
setSelectionAt: CloseSelectionOptions.AFTER_TEXT_INSERTED,
|
|
115
|
+
text: mode === SelectItemMode.SPACE ? text.concat(' ') : text
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return true;
|
|
121
|
+
}, [onItemInsert, triggerHandler, onTextInsert]);
|
|
122
|
+
useLayoutEffect(() => {
|
|
123
|
+
itemsRef.current = items;
|
|
124
|
+
}, [items]);
|
|
125
|
+
return [onItemInsert, onTextInsert, onItemMatch];
|
|
126
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useRef, useState, useEffect } from 'react';
|
|
2
|
+
import { updateListItem } from '../../commands/update-list-items';
|
|
3
|
+
const EMPTY_LIST_ITEM = [];
|
|
4
|
+
export const useLoadItems = (triggerHandler, editorView, query) => {
|
|
5
|
+
const [items, setItems] = useState(EMPTY_LIST_ITEM);
|
|
6
|
+
const componentIsMounted = useRef(true);
|
|
7
|
+
const editorViewRef = useRef(editorView);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const getItems = triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.getItems;
|
|
10
|
+
|
|
11
|
+
if (!getItems) {
|
|
12
|
+
setItems(EMPTY_LIST_ITEM);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const options = {
|
|
17
|
+
query: query || '',
|
|
18
|
+
editorState: editorView.state
|
|
19
|
+
};
|
|
20
|
+
const {
|
|
21
|
+
current: view
|
|
22
|
+
} = editorViewRef;
|
|
23
|
+
getItems(options).then(result => {
|
|
24
|
+
const list = result.length > 0 ? result : EMPTY_LIST_ITEM;
|
|
25
|
+
|
|
26
|
+
if (componentIsMounted.current) {
|
|
27
|
+
setItems(list);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
queueMicrotask(() => {
|
|
31
|
+
updateListItem(list)(view.state, view.dispatch);
|
|
32
|
+
});
|
|
33
|
+
}); // ignore because EditorView is mutable but we don't want to
|
|
34
|
+
// call loadItems when it changes, only when the query changes
|
|
35
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
|
+
}, [triggerHandler, query]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
return () => {
|
|
39
|
+
componentIsMounted.current = false;
|
|
40
|
+
};
|
|
41
|
+
}, []);
|
|
42
|
+
return items;
|
|
43
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef } from 'react';
|
|
2
|
+
import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
|
|
3
|
+
import { insertTypeAheadItem } from '../../commands/insert-type-ahead-item';
|
|
4
|
+
export const useOnForceSelect = ({
|
|
5
|
+
triggerHandler,
|
|
6
|
+
items,
|
|
7
|
+
query,
|
|
8
|
+
editorView,
|
|
9
|
+
closePopup
|
|
10
|
+
}) => {
|
|
11
|
+
const editorViewRef = useRef(editorView);
|
|
12
|
+
useLayoutEffect(() => {
|
|
13
|
+
if (!query || typeof triggerHandler.forceSelect !== 'function') {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const item = triggerHandler.forceSelect({
|
|
18
|
+
items,
|
|
19
|
+
query,
|
|
20
|
+
editorState: editorViewRef.current.state
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (!item) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
current: view
|
|
29
|
+
} = editorViewRef;
|
|
30
|
+
closePopup();
|
|
31
|
+
queueMicrotask(() => {
|
|
32
|
+
insertTypeAheadItem(view)({
|
|
33
|
+
item,
|
|
34
|
+
mode: SelectItemMode.SPACE,
|
|
35
|
+
query,
|
|
36
|
+
handler: triggerHandler,
|
|
37
|
+
sourceListItem: items
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}, [triggerHandler, closePopup, query, items]);
|
|
41
|
+
};
|