@crystallize/design-system 1.4.3 → 1.6.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/CHANGELOG.md +22 -0
- package/dist/index.css +85 -142
- package/dist/index.d.ts +25 -2
- package/dist/index.js +2438 -4457
- package/dist/index.mjs +2246 -4283
- package/package.json +19 -19
- package/src/iconography/app.tsx +38 -0
- package/src/iconography/billing-payments.tsx +62 -0
- package/src/iconography/cloud-with-key-hole.tsx +32 -0
- package/src/iconography/cloud.tsx +24 -0
- package/src/iconography/document.tsx +19 -0
- package/src/iconography/folder.tsx +30 -0
- package/src/iconography/frontends.tsx +49 -0
- package/src/iconography/index.ts +43 -2
- package/src/iconography/info.tsx +2 -2
- package/src/iconography/lock-closed.tsx +46 -0
- package/src/iconography/multilingual.tsx +38 -0
- package/src/iconography/people.tsx +62 -0
- package/src/iconography/plans-and-pricing.tsx +55 -0
- package/src/iconography/product.tsx +42 -0
- package/src/iconography/rocket.tsx +38 -0
- package/src/iconography/stock-location.tsx +77 -0
- package/src/iconography/subscription-contracts.tsx +52 -0
- package/src/iconography/subscription-plans.tsx +57 -0
- package/src/iconography/target.tsx +62 -0
- package/src/iconography/usage-meter.tsx +41 -0
- package/src/iconography/user-card.tsx +22 -0
- package/src/rich-text-editor/model/crystallize-to-lexical.ts +1 -1
- package/src/rich-text-editor/model/lexical-to-crystallize.ts +2 -2
- package/src/rich-text-editor/model/to-text.test.ts +97 -0
- package/src/rich-text-editor/model/to-text.ts +47 -0
- package/src/rich-text-editor/nodes/BaseNodes.ts +0 -3
- package/src/rich-text-editor/plugins/ActionsPlugin/index.tsx +1 -1
- package/src/rich-text-editor/plugins/CodeActionMenuPlugin/index.tsx +1 -1
- package/src/rich-text-editor/plugins/ComponentPickerPlugin/index.tsx +5 -5
- package/src/rich-text-editor/plugins/DraggableBlockPlugin/index.tsx +29 -50
- package/src/rich-text-editor/plugins/MaxLengthPlugin/index.tsx +34 -23
- package/src/rich-text-editor/plugins/ToolbarPlugin/index.tsx +8 -8
- package/src/rich-text-editor/rich-text-editor.css +3 -3
- package/src/rich-text-editor/rich-text-editor.stories.tsx +9 -1
- package/src/rich-text-editor/rich-text-editor.tsx +30 -24
- package/src/rich-text-editor/tests/rich-text-editor-basic-rendering.test.tsx +1 -1
- package/src/rich-text-editor/tests/rich-text-editor-model-basics.test.tsx +1 -1
- package/src/rich-text-editor/tests/rich-text-editor-model-conversions.test.tsx +1 -1
- package/src/rich-text-editor/tests/rich-text-editor-text-formats.test.tsx +1 -1
- package/src/rich-text-editor/themes/{PlaygroundEditorTheme.css → CrystallizeRTEditorTheme.css} +81 -85
- package/src/rich-text-editor/themes/CrystallizeRTEditorTheme.ts +113 -0
- package/dist/draggable-block-menu-KKHDNKJA.svg +0 -1
- package/src/rich-text-editor/appSettings.ts +0 -28
- package/src/rich-text-editor/context/SettingsContext.tsx +0 -71
- package/src/rich-text-editor/context/SharedAutocompleteContext.tsx +0 -60
- package/src/rich-text-editor/nodes/AutocompleteNode.tsx +0 -96
- package/src/rich-text-editor/plugins/AutocompletePlugin/index.tsx +0 -2536
- package/src/rich-text-editor/themes/PlaygroundEditorTheme.ts +0 -113
- /package/src/rich-text-editor/{model → types}/crystallize-rich-text-types/code.ts +0 -0
- /package/src/rich-text-editor/{model → types}/crystallize-rich-text-types/headings.ts +0 -0
- /package/src/rich-text-editor/{model → types}/crystallize-rich-text-types/index.ts +0 -0
- /package/src/rich-text-editor/{model → types}/crystallize-rich-text-types/link.ts +0 -0
- /package/src/rich-text-editor/{model → types}/crystallize-rich-text-types/table.ts +0 -0
- /package/src/rich-text-editor/{types.ts → types/types.ts} +0 -0
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
|
|
9
|
+
import type { EditorThemeClasses } from 'lexical';
|
|
10
|
+
|
|
11
|
+
import './CrystallizeRTEditorTheme.css';
|
|
12
|
+
|
|
13
|
+
const theme: EditorThemeClasses = {
|
|
14
|
+
blockCursor: 'CrystallizeRTEditorTheme__blockCursor',
|
|
15
|
+
characterLimit: 'CrystallizeRTEditorTheme__characterLimit',
|
|
16
|
+
code: 'CrystallizeRTEditorTheme__code',
|
|
17
|
+
codeHighlight: {
|
|
18
|
+
atrule: 'CrystallizeRTEditorTheme__tokenAttr',
|
|
19
|
+
attr: 'CrystallizeRTEditorTheme__tokenAttr',
|
|
20
|
+
boolean: 'CrystallizeRTEditorTheme__tokenProperty',
|
|
21
|
+
builtin: 'CrystallizeRTEditorTheme__tokenSelector',
|
|
22
|
+
cdata: 'CrystallizeRTEditorTheme__tokenComment',
|
|
23
|
+
char: 'CrystallizeRTEditorTheme__tokenSelector',
|
|
24
|
+
class: 'CrystallizeRTEditorTheme__tokenFunction',
|
|
25
|
+
'class-name': 'CrystallizeRTEditorTheme__tokenFunction',
|
|
26
|
+
comment: 'CrystallizeRTEditorTheme__tokenComment',
|
|
27
|
+
constant: 'CrystallizeRTEditorTheme__tokenProperty',
|
|
28
|
+
deleted: 'CrystallizeRTEditorTheme__tokenProperty',
|
|
29
|
+
doctype: 'CrystallizeRTEditorTheme__tokenComment',
|
|
30
|
+
entity: 'CrystallizeRTEditorTheme__tokenOperator',
|
|
31
|
+
function: 'CrystallizeRTEditorTheme__tokenFunction',
|
|
32
|
+
important: 'CrystallizeRTEditorTheme__tokenVariable',
|
|
33
|
+
inserted: 'CrystallizeRTEditorTheme__tokenSelector',
|
|
34
|
+
keyword: 'CrystallizeRTEditorTheme__tokenAttr',
|
|
35
|
+
namespace: 'CrystallizeRTEditorTheme__tokenVariable',
|
|
36
|
+
number: 'CrystallizeRTEditorTheme__tokenProperty',
|
|
37
|
+
operator: 'CrystallizeRTEditorTheme__tokenOperator',
|
|
38
|
+
prolog: 'CrystallizeRTEditorTheme__tokenComment',
|
|
39
|
+
property: 'CrystallizeRTEditorTheme__tokenProperty',
|
|
40
|
+
punctuation: 'CrystallizeRTEditorTheme__tokenPunctuation',
|
|
41
|
+
regex: 'CrystallizeRTEditorTheme__tokenVariable',
|
|
42
|
+
selector: 'CrystallizeRTEditorTheme__tokenSelector',
|
|
43
|
+
string: 'CrystallizeRTEditorTheme__tokenSelector',
|
|
44
|
+
symbol: 'CrystallizeRTEditorTheme__tokenProperty',
|
|
45
|
+
tag: 'CrystallizeRTEditorTheme__tokenProperty',
|
|
46
|
+
url: 'CrystallizeRTEditorTheme__tokenOperator',
|
|
47
|
+
variable: 'CrystallizeRTEditorTheme__tokenVariable',
|
|
48
|
+
},
|
|
49
|
+
embedBlock: {
|
|
50
|
+
base: 'CrystallizeRTEditorTheme__embedBlock',
|
|
51
|
+
focus: 'CrystallizeRTEditorTheme__embedBlockFocus',
|
|
52
|
+
},
|
|
53
|
+
hashtag: 'CrystallizeRTEditorTheme__hashtag',
|
|
54
|
+
heading: {
|
|
55
|
+
h1: 'CrystallizeRTEditorTheme__h1',
|
|
56
|
+
h2: 'CrystallizeRTEditorTheme__h2',
|
|
57
|
+
h3: 'CrystallizeRTEditorTheme__h3',
|
|
58
|
+
h4: 'CrystallizeRTEditorTheme__h4',
|
|
59
|
+
h5: 'CrystallizeRTEditorTheme__h5',
|
|
60
|
+
h6: 'CrystallizeRTEditorTheme__h6',
|
|
61
|
+
},
|
|
62
|
+
image: 'editor-image',
|
|
63
|
+
indent: 'CrystallizeRTEditorTheme__indent',
|
|
64
|
+
link: 'CrystallizeRTEditorTheme__link',
|
|
65
|
+
list: {
|
|
66
|
+
listitem: 'CrystallizeRTEditorTheme__listItem',
|
|
67
|
+
listitemChecked: 'CrystallizeRTEditorTheme__listItemChecked',
|
|
68
|
+
listitemUnchecked: 'CrystallizeRTEditorTheme__listItemUnchecked',
|
|
69
|
+
nested: {
|
|
70
|
+
listitem: 'CrystallizeRTEditorTheme__nestedListItem',
|
|
71
|
+
},
|
|
72
|
+
olDepth: [
|
|
73
|
+
'CrystallizeRTEditorTheme__ol1',
|
|
74
|
+
'CrystallizeRTEditorTheme__ol2',
|
|
75
|
+
'CrystallizeRTEditorTheme__ol3',
|
|
76
|
+
'CrystallizeRTEditorTheme__ol4',
|
|
77
|
+
'CrystallizeRTEditorTheme__ol5',
|
|
78
|
+
],
|
|
79
|
+
ul: 'CrystallizeRTEditorTheme__ul',
|
|
80
|
+
},
|
|
81
|
+
ltr: 'CrystallizeRTEditorTheme__ltr',
|
|
82
|
+
mark: 'CrystallizeRTEditorTheme__mark',
|
|
83
|
+
markOverlap: 'CrystallizeRTEditorTheme__markOverlap',
|
|
84
|
+
paragraph: 'CrystallizeRTEditorTheme__paragraph',
|
|
85
|
+
quote: 'CrystallizeRTEditorTheme__quote',
|
|
86
|
+
rtl: 'CrystallizeRTEditorTheme__rtl',
|
|
87
|
+
table: 'CrystallizeRTEditorTheme__table',
|
|
88
|
+
tableAddColumns: 'CrystallizeRTEditorTheme__tableAddColumns',
|
|
89
|
+
tableAddRows: 'CrystallizeRTEditorTheme__tableAddRows',
|
|
90
|
+
tableCell: 'CrystallizeRTEditorTheme__tableCell',
|
|
91
|
+
tableCellActionButton: 'CrystallizeRTEditorTheme__tableCellActionButton',
|
|
92
|
+
tableCellActionButtonContainer: 'CrystallizeRTEditorTheme__tableCellActionButtonContainer',
|
|
93
|
+
tableCellEditing: 'CrystallizeRTEditorTheme__tableCellEditing',
|
|
94
|
+
tableCellHeader: 'CrystallizeRTEditorTheme__tableCellHeader',
|
|
95
|
+
tableCellPrimarySelected: 'CrystallizeRTEditorTheme__tableCellPrimarySelected',
|
|
96
|
+
tableCellResizer: 'CrystallizeRTEditorTheme__tableCellResizer',
|
|
97
|
+
tableCellSelected: 'CrystallizeRTEditorTheme__tableCellSelected',
|
|
98
|
+
tableCellSortedIndicator: 'CrystallizeRTEditorTheme__tableCellSortedIndicator',
|
|
99
|
+
tableResizeRuler: 'CrystallizeRTEditorTheme__tableCellResizeRuler',
|
|
100
|
+
tableSelected: 'CrystallizeRTEditorTheme__tableSelected',
|
|
101
|
+
text: {
|
|
102
|
+
bold: 'CrystallizeRTEditorTheme__textBold',
|
|
103
|
+
code: 'CrystallizeRTEditorTheme__textCode',
|
|
104
|
+
italic: 'CrystallizeRTEditorTheme__textItalic',
|
|
105
|
+
strikethrough: 'CrystallizeRTEditorTheme__textStrikethrough',
|
|
106
|
+
subscript: 'CrystallizeRTEditorTheme__textSubscript',
|
|
107
|
+
superscript: 'CrystallizeRTEditorTheme__textSuperscript',
|
|
108
|
+
underline: 'CrystallizeRTEditorTheme__textUnderline',
|
|
109
|
+
underlineStrikethrough: 'CrystallizeRTEditorTheme__textUnderlineStrikethrough',
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export default theme;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" data-name="Layer 1" viewBox="0 0 24 24" fill="currentColor"><path stroke="currentColor" d="M8.5 10a2 2 0 1 0 2 2 2 2 0 0 0-2-2Zm0 7a2 2 0 1 0 2 2 2 2 0 0 0-2-2Zm7-10a2 2 0 1 0-2-2 2 2 0 0 0 2 2Zm-7-4a2 2 0 1 0 2 2 2 2 0 0 0-2-2Zm7 14a2 2 0 1 0 2 2 2 2 0 0 0-2-2Zm0-7a2 2 0 1 0 2 2 2 2 0 0 0-2-2Z"/></svg>
|
|
@@ -1,28 +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
|
-
|
|
9
|
-
export type SettingName =
|
|
10
|
-
| 'disableBeforeInput'
|
|
11
|
-
| 'measureTypingPerf'
|
|
12
|
-
| 'isCharLimit'
|
|
13
|
-
| 'isMaxLength'
|
|
14
|
-
| 'isCharLimitUtf8'
|
|
15
|
-
| 'isAutocomplete'
|
|
16
|
-
| 'showNestedEditorTreeView';
|
|
17
|
-
|
|
18
|
-
export type Settings = Record<SettingName, boolean>;
|
|
19
|
-
|
|
20
|
-
export const DEFAULT_SETTINGS: Settings = {
|
|
21
|
-
disableBeforeInput: false,
|
|
22
|
-
isAutocomplete: false,
|
|
23
|
-
isCharLimit: false,
|
|
24
|
-
isCharLimitUtf8: false,
|
|
25
|
-
isMaxLength: false,
|
|
26
|
-
measureTypingPerf: false,
|
|
27
|
-
showNestedEditorTreeView: false,
|
|
28
|
-
};
|
|
@@ -1,71 +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
|
-
|
|
9
|
-
import type { SettingName } from '../appSettings';
|
|
10
|
-
|
|
11
|
-
import { createContext, ReactNode, useCallback, useContext, useMemo, useState } from 'react';
|
|
12
|
-
|
|
13
|
-
import { DEFAULT_SETTINGS } from '../appSettings';
|
|
14
|
-
|
|
15
|
-
type SettingsContextShape = {
|
|
16
|
-
setOption: (name: SettingName, value: boolean) => void;
|
|
17
|
-
settings: Record<SettingName, boolean>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const Context: React.Context<SettingsContextShape> = createContext({
|
|
21
|
-
setOption: (name: SettingName, value: boolean) => {
|
|
22
|
-
// eslint-disable-next-line no-console
|
|
23
|
-
console.log({ name, value });
|
|
24
|
-
return;
|
|
25
|
-
},
|
|
26
|
-
settings: DEFAULT_SETTINGS,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
export const SettingsContext = ({ children }: { children: ReactNode }): JSX.Element => {
|
|
30
|
-
const [settings, setSettings] = useState(DEFAULT_SETTINGS);
|
|
31
|
-
|
|
32
|
-
const setOption = useCallback((setting: SettingName, value: boolean) => {
|
|
33
|
-
setSettings(options => ({
|
|
34
|
-
...options,
|
|
35
|
-
[setting as string]: value,
|
|
36
|
-
}));
|
|
37
|
-
if (DEFAULT_SETTINGS[setting] === value) {
|
|
38
|
-
setURLParam(setting, null);
|
|
39
|
-
} else {
|
|
40
|
-
setURLParam(setting, value);
|
|
41
|
-
}
|
|
42
|
-
}, []);
|
|
43
|
-
|
|
44
|
-
const contextValue = useMemo(() => {
|
|
45
|
-
return { setOption, settings };
|
|
46
|
-
}, [setOption, settings]);
|
|
47
|
-
|
|
48
|
-
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const useSettings = (): SettingsContextShape => {
|
|
52
|
-
return useContext(Context);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
function setURLParam(param: SettingName, value: null | boolean) {
|
|
56
|
-
const url = new URL(window.location.href);
|
|
57
|
-
const params = new URLSearchParams(url.search);
|
|
58
|
-
if (value !== null) {
|
|
59
|
-
if (params.has(param)) {
|
|
60
|
-
params.set(param, String(value));
|
|
61
|
-
} else {
|
|
62
|
-
params.append(param, String(value));
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
if (params.has(param)) {
|
|
66
|
-
params.delete(param);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
url.search = params.toString();
|
|
70
|
-
window.history.pushState(null, '', url.toString());
|
|
71
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
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
|
-
|
|
10
|
-
import { createContext, ReactNode, useContext, useEffect, useMemo, useState } from 'react';
|
|
11
|
-
|
|
12
|
-
type Suggestion = null | string;
|
|
13
|
-
type CallbackFn = (newSuggestion: Suggestion) => void;
|
|
14
|
-
type SubscribeFn = (callbackFn: CallbackFn) => () => void;
|
|
15
|
-
type PublishFn = (newSuggestion: Suggestion) => void;
|
|
16
|
-
type ContextShape = [SubscribeFn, PublishFn];
|
|
17
|
-
type HookShape = [suggestion: Suggestion, setSuggestion: PublishFn];
|
|
18
|
-
|
|
19
|
-
const Context: React.Context<ContextShape> = createContext([
|
|
20
|
-
_cb => () => {
|
|
21
|
-
return;
|
|
22
|
-
},
|
|
23
|
-
(_newSuggestion: Suggestion) => {
|
|
24
|
-
return;
|
|
25
|
-
},
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
export const SharedAutocompleteContext = ({ children }: { children: ReactNode }): JSX.Element => {
|
|
29
|
-
const context: ContextShape = useMemo(() => {
|
|
30
|
-
let suggestion: Suggestion | null = null;
|
|
31
|
-
const listeners: Set<CallbackFn> = new Set();
|
|
32
|
-
return [
|
|
33
|
-
(cb: (newSuggestion: Suggestion) => void) => {
|
|
34
|
-
cb(suggestion);
|
|
35
|
-
listeners.add(cb);
|
|
36
|
-
return () => {
|
|
37
|
-
listeners.delete(cb);
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
(newSuggestion: Suggestion) => {
|
|
41
|
-
suggestion = newSuggestion;
|
|
42
|
-
for (const listener of listeners) {
|
|
43
|
-
listener(newSuggestion);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
|
-
}, []);
|
|
48
|
-
return <Context.Provider value={context}>{children}</Context.Provider>;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const useSharedAutocompleteContext = (): HookShape => {
|
|
52
|
-
const [subscribe, publish]: ContextShape = useContext(Context);
|
|
53
|
-
const [suggestion, setSuggestion] = useState<Suggestion>(null);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
return subscribe((newSuggestion: Suggestion) => {
|
|
56
|
-
setSuggestion(newSuggestion);
|
|
57
|
-
});
|
|
58
|
-
}, [subscribe]);
|
|
59
|
-
return [suggestion, publish];
|
|
60
|
-
};
|
|
@@ -1,96 +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
|
-
|
|
9
|
-
import type { Spread } from 'lexical';
|
|
10
|
-
|
|
11
|
-
import { DecoratorNode, EditorConfig, NodeKey, SerializedLexicalNode } from 'lexical';
|
|
12
|
-
import * as React from 'react';
|
|
13
|
-
|
|
14
|
-
import { useSharedAutocompleteContext } from '../context/SharedAutocompleteContext';
|
|
15
|
-
import { uuid as UUID } from '../plugins/AutocompletePlugin';
|
|
16
|
-
|
|
17
|
-
declare global {
|
|
18
|
-
interface Navigator {
|
|
19
|
-
userAgentData?: {
|
|
20
|
-
mobile: boolean;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type SerializedAutocompleteNode = Spread<
|
|
26
|
-
{
|
|
27
|
-
type: 'autocomplete';
|
|
28
|
-
version: 1;
|
|
29
|
-
uuid: string;
|
|
30
|
-
},
|
|
31
|
-
SerializedLexicalNode
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
export class AutocompleteNode extends DecoratorNode<JSX.Element | null> {
|
|
35
|
-
// TODO add comment
|
|
36
|
-
__uuid: string;
|
|
37
|
-
|
|
38
|
-
static clone(node: AutocompleteNode): AutocompleteNode {
|
|
39
|
-
return new AutocompleteNode(node.__key);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static getType(): 'autocomplete' {
|
|
43
|
-
return 'autocomplete';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static importJSON(serializedNode: SerializedAutocompleteNode): AutocompleteNode {
|
|
47
|
-
const node = $createAutocompleteNode(serializedNode.uuid);
|
|
48
|
-
return node;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
exportJSON(): SerializedAutocompleteNode {
|
|
52
|
-
return {
|
|
53
|
-
...super.exportJSON(),
|
|
54
|
-
type: 'autocomplete',
|
|
55
|
-
uuid: this.__uuid,
|
|
56
|
-
version: 1,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
constructor(uuid: string, key?: NodeKey) {
|
|
61
|
-
super(key);
|
|
62
|
-
this.__uuid = uuid;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
updateDOM(prevNode: unknown, dom: HTMLElement, config: EditorConfig): boolean {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
createDOM(config: EditorConfig): HTMLElement {
|
|
70
|
-
return document.createElement('span');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
decorate(): JSX.Element | null {
|
|
74
|
-
if (this.__uuid !== UUID) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
return <AutocompleteComponent />;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function $createAutocompleteNode(uuid: string): AutocompleteNode {
|
|
82
|
-
return new AutocompleteNode(uuid);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function AutocompleteComponent(): JSX.Element {
|
|
86
|
-
const [suggestion] = useSharedAutocompleteContext();
|
|
87
|
-
const userAgentData = window.navigator.userAgentData;
|
|
88
|
-
const isMobile =
|
|
89
|
-
userAgentData !== undefined ? userAgentData.mobile : window.innerWidth <= 800 && window.innerHeight <= 600;
|
|
90
|
-
// TODO Move to theme
|
|
91
|
-
return (
|
|
92
|
-
<span style={{ color: '#ccc' }} spellCheck="false">
|
|
93
|
-
{suggestion} {isMobile ? '(SWIPE \u2B95)' : '(TAB)'}
|
|
94
|
-
</span>
|
|
95
|
-
);
|
|
96
|
-
}
|