@blocklet/editor 2.4.21 → 2.4.22

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.
@@ -1,8 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- export default function EmojiPickerPlugin(): import("react/jsx-runtime").JSX.Element;
@@ -1,86 +0,0 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- /**
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- *
8
- */
9
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
10
- import { $createTextNode, $getSelection, $isRangeSelection } from 'lexical';
11
- import { useCallback, useEffect, useMemo, useState } from 'react';
12
- import { LexicalTypeaheadMenuPlugin, TypeaheadOption, useBasicTypeaheadTriggerMatch, } from '../LexicalTypeaheadMenuPlugin';
13
- import createPortal from '../../../components/createPortal';
14
- class EmojiOption extends TypeaheadOption {
15
- title;
16
- emoji;
17
- keywords;
18
- constructor(title, emoji, options) {
19
- super(title);
20
- this.title = title;
21
- this.emoji = emoji;
22
- this.keywords = options.keywords || [];
23
- }
24
- }
25
- function EmojiMenuItem({ index, isSelected, onClick, onMouseEnter, option, }) {
26
- let className = 'item';
27
- if (isSelected) {
28
- className += ' selected';
29
- }
30
- return (_jsx("li", { tabIndex: -1, className: className, ref: option.setRefElement, role: "option", "aria-selected": isSelected, id: `typeahead-item-${index}`, onMouseEnter: onMouseEnter, onClick: onClick, children: _jsxs("span", { className: "text", children: [option.emoji, " ", option.title] }) }, option.key));
31
- }
32
- const MAX_EMOJI_SUGGESTION_COUNT = 10;
33
- export default function EmojiPickerPlugin() {
34
- const [editor] = useLexicalComposerContext();
35
- const [queryString, setQueryString] = useState(null);
36
- const [emojis, setEmojis] = useState([]);
37
- useEffect(() => {
38
- // @ts-ignore
39
- import('./emoji-list').then((file) => setEmojis(file.default));
40
- }, []);
41
- const emojiOptions = useMemo(() => emojis != null
42
- ? emojis.map(({ emoji, aliases, tags }) => new EmojiOption(aliases[0], emoji, {
43
- keywords: [...aliases, ...tags],
44
- }))
45
- : [], [emojis]);
46
- const checkForTriggerMatch = useBasicTypeaheadTriggerMatch(':', {
47
- minLength: 0,
48
- });
49
- const options = useMemo(() => {
50
- return emojiOptions
51
- .filter((option) => {
52
- return queryString != null
53
- ? new RegExp(queryString, 'gi').exec(option.title) || option.keywords != null
54
- ? option.keywords.some((keyword) => new RegExp(queryString, 'gi').exec(keyword))
55
- : false
56
- : emojiOptions;
57
- })
58
- .slice(0, MAX_EMOJI_SUGGESTION_COUNT);
59
- }, [emojiOptions, queryString]);
60
- const onSelectOption = useCallback((selectedOption, nodeToRemove, closeMenu) => {
61
- editor.update(() => {
62
- const selection = $getSelection();
63
- if (!$isRangeSelection(selection) || selectedOption == null) {
64
- return;
65
- }
66
- if (nodeToRemove) {
67
- nodeToRemove.remove();
68
- }
69
- selection.insertNodes([$createTextNode(selectedOption.emoji)]);
70
- closeMenu();
71
- });
72
- }, [editor]);
73
- return (_jsx(LexicalTypeaheadMenuPlugin, { onQueryChange: setQueryString, onSelectOption: onSelectOption, triggerFn: checkForTriggerMatch, options: options, menuRenderFn: (anchorElementRef, { selectedIndex, selectOptionAndCleanUp, setHighlightedIndex }) => {
74
- if (anchorElementRef.current == null || options.length === 0) {
75
- return null;
76
- }
77
- return anchorElementRef.current && options.length
78
- ? createPortal(_jsx("div", { className: "typeahead-popover emoji-menu", children: _jsx("ul", { children: options.map((option, index) => (_jsx("div", { children: _jsx(EmojiMenuItem, { index: index, isSelected: selectedIndex === index, onClick: () => {
79
- setHighlightedIndex(index);
80
- selectOptionAndCleanUp(option);
81
- }, onMouseEnter: () => {
82
- setHighlightedIndex(index);
83
- }, option: option }) }, option.key))) }) }), anchorElementRef.current)
84
- : null;
85
- } }));
86
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- import { type JSX } from 'react';
9
- export default function StickyPlugin(): JSX.Element | null;
@@ -1,19 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
9
- import { useEffect } from 'react';
10
- import { StickyNode } from '../../nodes/StickyNode';
11
- export default function StickyPlugin() {
12
- const [editor] = useLexicalComposerContext();
13
- useEffect(() => {
14
- if (!editor.hasNodes([StickyNode])) {
15
- throw new Error('StickyPlugin: StickyNode not registered on editor');
16
- }
17
- }, [editor]);
18
- return null;
19
- }