@livepreso/react-plugin-textfield 0.1.3 → 0.2.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/.rush/temp/shrinkwrap-deps.json +32 -27
- package/CHANGELOG.json +32 -0
- package/CHANGELOG.md +16 -1
- package/components/InsertTokenDialog.js +82 -0
- package/components/InsertTokenDialog.module.scss +166 -0
- package/components/editor-toolbars/EditorMenu.module.scss +1 -0
- package/components/editor-toolbars/SimpleButton.js +34 -0
- package/components/editor-toolbars/SimpleButton.module.scss +36 -0
- package/components/tiptap/token/Token.js +184 -0
- package/components/tiptap/token/Token.module.scss +28 -0
- package/components/tiptap/token/TokenList.js +93 -0
- package/components/tiptap/token/TokenList.module.scss +58 -0
- package/components/tiptap/token/utils.js +92 -0
- package/configs/generate-toolbar-configuration.js +14 -2
- package/configs/generate-toolbar-options.js +4 -2
- package/configs/toolbar-configuration.js +15 -0
- package/constants.js +23 -1
- package/icons/HelpCenter.js +13 -0
- package/icons/MoreVert.js +13 -0
- package/icons/WandStars.js +13 -0
- package/icons/help_center.svg +1 -0
- package/icons/index.js +9 -1
- package/icons/more_vert.svg +1 -0
- package/icons/wand_stars.svg +1 -0
- package/index.js +51 -2
- package/index.module.scss +9 -8
- package/package.json +30 -27
- package/scripts/extract-svg.js +3 -1
- package/variables.scss +6 -0
- package/icons/format_color_text.svg +0 -5
- package/icons/format_color_text_ungrouped.svg +0 -6
package/index.js
CHANGED
|
@@ -33,11 +33,19 @@ import {
|
|
|
33
33
|
DEFAULT_TOOLBAR_CONFIG,
|
|
34
34
|
DEFAULT_TABLE_TOOLBAR_CONFIG,
|
|
35
35
|
EDITABLE_OUTER_SELECTOR,
|
|
36
|
+
MODE_PREP,
|
|
37
|
+
MODE_CMS,
|
|
38
|
+
MODE_UNMANAGED,
|
|
36
39
|
} from "./constants.js";
|
|
37
40
|
import { TableCellMenu } from "./components/TableCellMenu.js";
|
|
38
41
|
import style from "./index.module.scss";
|
|
39
42
|
import { generateExtensionsFromTag } from "./utils/generateCustomExtensions.js";
|
|
40
43
|
import debounce from "lodash.debounce";
|
|
44
|
+
import {
|
|
45
|
+
convertTokensToTextNodes,
|
|
46
|
+
generateTokenInstance,
|
|
47
|
+
} from "./components/tiptap/token/Token.js";
|
|
48
|
+
import Fuse from "fuse.js";
|
|
41
49
|
|
|
42
50
|
function EditableTextField({
|
|
43
51
|
value,
|
|
@@ -46,6 +54,7 @@ function EditableTextField({
|
|
|
46
54
|
isEditable,
|
|
47
55
|
textStyles,
|
|
48
56
|
colors,
|
|
57
|
+
tokens,
|
|
49
58
|
toolbarConfig = DEFAULT_TOOLBAR_CONFIG,
|
|
50
59
|
tableToolbarConfig = DEFAULT_TABLE_TOOLBAR_CONFIG,
|
|
51
60
|
maskSelector,
|
|
@@ -53,14 +62,20 @@ function EditableTextField({
|
|
|
53
62
|
tag,
|
|
54
63
|
autofocus = false,
|
|
55
64
|
disableSpellcheck = false,
|
|
65
|
+
mode,
|
|
66
|
+
tokenConfig = {},
|
|
56
67
|
// TODO implement an equivalent to the EditableText handler
|
|
57
68
|
// for editables inside tab handlers / accordion headers etc
|
|
58
69
|
// stopPropagation = false,
|
|
59
70
|
...other
|
|
60
71
|
}) {
|
|
72
|
+
const { isPresomanager } = useModes();
|
|
73
|
+
const { isUserTemplateLibrary } = useSlide();
|
|
61
74
|
const [textColor, setTextColor] = useState(null);
|
|
62
75
|
const initialValue = useRef(value);
|
|
63
76
|
|
|
77
|
+
const isReallyPresoManager = isPresomanager && !isUserTemplateLibrary;
|
|
78
|
+
|
|
64
79
|
// a custom tag can result in a custom Document extension
|
|
65
80
|
// or you can pass custom extensions
|
|
66
81
|
const additionalExtensions = {
|
|
@@ -68,7 +83,30 @@ function EditableTextField({
|
|
|
68
83
|
...customExtensions,
|
|
69
84
|
};
|
|
70
85
|
|
|
71
|
-
|
|
86
|
+
// include Token here, because we need it for rendering even if its toolbar button is disabled
|
|
87
|
+
// elsewhere, we can kill its suggestion engine to disable its UI
|
|
88
|
+
|
|
89
|
+
const fuseInstance = useMemo(() => {
|
|
90
|
+
return new Fuse(tokens, { keys: ["label"] });
|
|
91
|
+
}, [tokens]);
|
|
92
|
+
|
|
93
|
+
const tokenOptions = {
|
|
94
|
+
tokens,
|
|
95
|
+
mode,
|
|
96
|
+
isEditable,
|
|
97
|
+
usePlaceholder: isReallyPresoManager,
|
|
98
|
+
...tokenConfig,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const baseExtensions = [
|
|
102
|
+
Text,
|
|
103
|
+
Paragraph,
|
|
104
|
+
HardBreak,
|
|
105
|
+
generateTokenInstance({
|
|
106
|
+
...tokenOptions,
|
|
107
|
+
fuse: fuseInstance,
|
|
108
|
+
}),
|
|
109
|
+
].filter(Boolean);
|
|
72
110
|
|
|
73
111
|
// it is your responsibility not to double-specify any extensions you need here
|
|
74
112
|
// vs those derived from the toolbar config
|
|
@@ -89,8 +127,9 @@ function EditableTextField({
|
|
|
89
127
|
tableToolbarConfig,
|
|
90
128
|
textStyles,
|
|
91
129
|
colors,
|
|
130
|
+
tokens,
|
|
92
131
|
}),
|
|
93
|
-
[textStyles, colors, toolbarConfig, tableToolbarConfig],
|
|
132
|
+
[textStyles, colors, tokens, toolbarConfig, tableToolbarConfig],
|
|
94
133
|
);
|
|
95
134
|
|
|
96
135
|
const groupedOptions = [
|
|
@@ -109,9 +148,16 @@ function EditableTextField({
|
|
|
109
148
|
],
|
|
110
149
|
editable: isEditable,
|
|
111
150
|
autofocus: false,
|
|
151
|
+
onCreate: ({ editor }) => {
|
|
152
|
+
// Burst any saved tokens (eg. added in PresoManager, editable in present)
|
|
153
|
+
if (tokenOptions.burstOnCreate) {
|
|
154
|
+
convertTokensToTextNodes(editor, tokenOptions);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
112
157
|
onUpdate: debounce(({ editor }) => {
|
|
113
158
|
onChange?.(editor.getHTML());
|
|
114
159
|
}, 100),
|
|
160
|
+
parseOptions: { preserveWhitespace: "full" },
|
|
115
161
|
});
|
|
116
162
|
|
|
117
163
|
const { refs } = useFloating({
|
|
@@ -265,6 +311,7 @@ function PrepEditableField({ id, prepId = id, children, isCompany, ...props }) {
|
|
|
265
311
|
value={value ?? renderToString(children)}
|
|
266
312
|
onChange={setPrepValue}
|
|
267
313
|
isEditable={isEditable}
|
|
314
|
+
mode={MODE_PREP}
|
|
268
315
|
/>
|
|
269
316
|
);
|
|
270
317
|
}
|
|
@@ -294,6 +341,7 @@ function CMSValField({ id, children, ...props }) {
|
|
|
294
341
|
value={value ?? renderToString(children)}
|
|
295
342
|
onChange={setCMSValue}
|
|
296
343
|
isEditable={isEditable}
|
|
344
|
+
mode={MODE_CMS}
|
|
297
345
|
/>
|
|
298
346
|
);
|
|
299
347
|
}
|
|
@@ -306,6 +354,7 @@ export function TextField(props) {
|
|
|
306
354
|
value={value ?? renderToString(children)}
|
|
307
355
|
onChange={onChange}
|
|
308
356
|
isEditable={!isReadOnly}
|
|
357
|
+
mode={MODE_UNMANAGED}
|
|
309
358
|
{...other}
|
|
310
359
|
/>
|
|
311
360
|
);
|
package/index.module.scss
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
$button-color: #f0f0f0;
|
|
3
|
-
$button-hover-color: #e0e0e0;
|
|
1
|
+
@import "./variables.scss";
|
|
4
2
|
|
|
5
3
|
:global(.sp-presenter-overlay) {
|
|
6
4
|
* {
|
|
@@ -11,20 +9,23 @@ $button-hover-color: #e0e0e0;
|
|
|
11
9
|
|
|
12
10
|
--sp-toolbar-color-white: #ffffff;
|
|
13
11
|
--sp-toolbar-bg-color: var(--sp-toolbar-color-white);
|
|
14
|
-
--sp-toolbar-color:
|
|
12
|
+
--sp-toolbar-color: #{$toolbar-color};
|
|
15
13
|
--sp-toolbar-modal-bg-color: rgba(255, 255, 255, 0.75);
|
|
16
14
|
--sp-toolbar-separator-color: rgba(0, 0, 0, 0.12);
|
|
17
15
|
--sp-toolbar-highlight-color: rgba(0, 0, 0, 0.38);
|
|
18
|
-
--sp-toolbar-interactive-color: $interactive-color;
|
|
16
|
+
--sp-toolbar-interactive-color: #{$interactive-color};
|
|
19
17
|
--sp-toolbar-focus-color: #006ce7;
|
|
20
|
-
--sp-toolbar-active-color: #
|
|
18
|
+
--sp-toolbar-active-color: #{$active-color};
|
|
21
19
|
--sp-toolbar-hover-color: #cce2fa;
|
|
22
20
|
--sp-toolbar-select-trigger: #f7f7f7;
|
|
23
21
|
// Buttons
|
|
24
|
-
--sp-toolbar-button: $button-color;
|
|
25
|
-
--sp-toolbar-button-hover: $button-hover-color;
|
|
22
|
+
--sp-toolbar-button: #{$button-color};
|
|
23
|
+
--sp-toolbar-button-hover: #{$button-hover-color};
|
|
26
24
|
--sp-toolbar-button-primary: var(--sp-toolbar-focus-color);
|
|
27
25
|
--sp-toolbar-button-primary-hover: #0060ce;
|
|
26
|
+
// tokens (for the dialog)
|
|
27
|
+
--sp-token-background-color: #{$active-color};
|
|
28
|
+
--sp-token-color: #{$toolbar-color};
|
|
28
29
|
|
|
29
30
|
a,
|
|
30
31
|
button,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livepreso/react-plugin-textfield",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -25,37 +25,40 @@
|
|
|
25
25
|
"react-dom": "18.x"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@floating-ui/react-dom": "~2.1.
|
|
28
|
+
"@floating-ui/react-dom": "~2.1.6",
|
|
29
29
|
"use-sync-external-store": "~1.5.0",
|
|
30
30
|
"classnames": "~2.5.1",
|
|
31
31
|
"radix-ui": "~1.4.2",
|
|
32
32
|
"@radix-ui/react-icons": "~1.3.2",
|
|
33
|
-
"@tiptap/core": "~3.
|
|
34
|
-
"@tiptap/react": "~3.
|
|
35
|
-
"@tiptap/pm": "~3.
|
|
36
|
-
"@tiptap/extension-document": "~3.
|
|
37
|
-
"@tiptap/extension-paragraph": "~3.
|
|
38
|
-
"@tiptap/extension-text": "~3.
|
|
39
|
-
"@tiptap/extension-hard-break": "~3.
|
|
40
|
-
"@tiptap/extension-heading": "~3.
|
|
41
|
-
"@tiptap/extension-bubble-menu": "~3.
|
|
42
|
-
"@tiptap/extension-table": "~3.
|
|
43
|
-
"@tiptap/extension-table-cell": "~3.
|
|
44
|
-
"@tiptap/extension-table-header": "~3.
|
|
45
|
-
"@tiptap/extension-table-row": "~3.
|
|
46
|
-
"@tiptap/extension-image": "~3.
|
|
47
|
-
"@tiptap/extension-text-align": "~3.
|
|
48
|
-
"@tiptap/extension-underline": "~3.
|
|
49
|
-
"@tiptap/extension-link": "~3.
|
|
50
|
-
"@tiptap/extension-bold": "~3.
|
|
51
|
-
"@tiptap/extension-italic": "~3.
|
|
52
|
-
"@tiptap/extension-list": "~3.
|
|
53
|
-
"@tiptap/extension-text-style": "~3.
|
|
54
|
-
"@tiptap/extensions": "~3.
|
|
55
|
-
"@tiptap/extension-subscript": "~3.
|
|
56
|
-
"@tiptap/extension-superscript": "~3.
|
|
33
|
+
"@tiptap/core": "~3.10.1",
|
|
34
|
+
"@tiptap/react": "~3.10.1",
|
|
35
|
+
"@tiptap/pm": "~3.10.1",
|
|
36
|
+
"@tiptap/extension-document": "~3.10.1",
|
|
37
|
+
"@tiptap/extension-paragraph": "~3.10.1",
|
|
38
|
+
"@tiptap/extension-text": "~3.10.1",
|
|
39
|
+
"@tiptap/extension-hard-break": "~3.10.1",
|
|
40
|
+
"@tiptap/extension-heading": "~3.10.1",
|
|
41
|
+
"@tiptap/extension-bubble-menu": "~3.10.1",
|
|
42
|
+
"@tiptap/extension-table": "~3.10.1",
|
|
43
|
+
"@tiptap/extension-table-cell": "~3.10.1",
|
|
44
|
+
"@tiptap/extension-table-header": "~3.10.1",
|
|
45
|
+
"@tiptap/extension-table-row": "~3.10.1",
|
|
46
|
+
"@tiptap/extension-image": "~3.10.1",
|
|
47
|
+
"@tiptap/extension-text-align": "~3.10.1",
|
|
48
|
+
"@tiptap/extension-underline": "~3.10.1",
|
|
49
|
+
"@tiptap/extension-link": "~3.10.1",
|
|
50
|
+
"@tiptap/extension-bold": "~3.10.1",
|
|
51
|
+
"@tiptap/extension-italic": "~3.10.1",
|
|
52
|
+
"@tiptap/extension-list": "~3.10.1",
|
|
53
|
+
"@tiptap/extension-text-style": "~3.10.1",
|
|
54
|
+
"@tiptap/extensions": "~3.10.1",
|
|
55
|
+
"@tiptap/extension-subscript": "~3.10.1",
|
|
56
|
+
"@tiptap/extension-superscript": "~3.10.1",
|
|
57
57
|
"lodash.debounce": "~4.0.8",
|
|
58
|
-
"@
|
|
58
|
+
"@tiptap/extension-mention": "~3.10.1",
|
|
59
|
+
"@tiptap/suggestion": "~3.10.1",
|
|
60
|
+
"fuse.js": "~7.1.0",
|
|
61
|
+
"@livepreso/content-react": "2.0.2"
|
|
59
62
|
},
|
|
60
63
|
"scripts": {
|
|
61
64
|
"build": ""
|
package/scripts/extract-svg.js
CHANGED
|
@@ -34,21 +34,23 @@ const SYMBOL_NAMES = [
|
|
|
34
34
|
"format_bold",
|
|
35
35
|
"format_clear",
|
|
36
36
|
"format_color_fill",
|
|
37
|
-
"format_color_text",
|
|
38
37
|
"format_italic",
|
|
39
38
|
"format_list_bulleted",
|
|
40
39
|
"format_list_numbered",
|
|
41
40
|
"format_strikethrough",
|
|
42
41
|
"format_underlined",
|
|
42
|
+
"help_center",
|
|
43
43
|
"horizontal_rule",
|
|
44
44
|
"link",
|
|
45
45
|
"link_off",
|
|
46
|
+
"more_vert",
|
|
46
47
|
"redo",
|
|
47
48
|
"undo",
|
|
48
49
|
"format_line_spacing",
|
|
49
50
|
"vertical_align_top",
|
|
50
51
|
"vertical_align_center",
|
|
51
52
|
"vertical_align_bottom",
|
|
53
|
+
"wand_stars",
|
|
52
54
|
];
|
|
53
55
|
|
|
54
56
|
/**
|
package/variables.scss
ADDED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 24 24">
|
|
3
|
-
<!-- Generator: Adobe Illustrator 29.3.1, SVG Export Plug-In . SVG Version: 2.1.0 Build 151) -->
|
|
4
|
-
<path d="M2.5,24v-3.7h19v3.7H2.5ZM5.9,17L11.1,3.5h1.7l5.3,13.5h-1.8l-1.3-3.6h-6l-1.4,3.6h-1.8ZM9.5,11.9h4.9l-2.4-6.3h-.1l-2.4,6.3Z"/>
|
|
5
|
-
</svg>
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 24 24">
|
|
3
|
-
<!-- Generator: Adobe Illustrator 29.3.1, SVG Export Plug-In . SVG Version: 2.1.0 Build 151) -->
|
|
4
|
-
<rect x="2.5" y="20.3" width="19" height="3.7"/>
|
|
5
|
-
<path d="M12.9,3.5h-1.7l-5.3,13.5h1.8l1.4-3.6h6l1.3,3.6h1.8L12.9,3.5ZM9.5,11.9l2.4-6.3h.1l2.4,6.3h-4.9Z"/>
|
|
6
|
-
</svg>
|