@umbra.ui/core 0.4.0 → 0.4.2
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/dist/components/inputs/AutogrowRichTextView/AutogrowRichTextView.vue +51 -25
- package/dist/components/inputs/AutogrowRichTextView/editor.css +8 -1
- package/package.json +1 -2
- package/src/components/inputs/AutogrowRichTextView/AutogrowRichTextView.vue +51 -25
- package/src/components/inputs/AutogrowRichTextView/editor.css +8 -1
|
@@ -5,7 +5,6 @@ import StarterKit from "@tiptap/starter-kit";
|
|
|
5
5
|
import { Markdown } from "@tiptap/markdown";
|
|
6
6
|
import Highlight from "@tiptap/extension-highlight";
|
|
7
7
|
import Placeholder from "@tiptap/extension-placeholder";
|
|
8
|
-
import Underline from "@tiptap/extension-underline";
|
|
9
8
|
import "./theme.css";
|
|
10
9
|
import "./editor.css";
|
|
11
10
|
|
|
@@ -24,24 +23,52 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
24
23
|
const isUpdatingFromProps = ref(false);
|
|
25
24
|
|
|
26
25
|
type MarkdownEditor = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
getMarkdown?: () => string;
|
|
31
|
-
serialize?: (doc: unknown) => string;
|
|
32
|
-
};
|
|
26
|
+
getMarkdown?: () => string;
|
|
27
|
+
markdown?: {
|
|
28
|
+
serialize?: (docOrContent: any) => string;
|
|
33
29
|
};
|
|
30
|
+
getJSON?: () => unknown;
|
|
31
|
+
getText?: () => string;
|
|
32
|
+
isEmpty?: boolean;
|
|
33
|
+
setOptions?: (options: {
|
|
34
|
+
editorProps: {
|
|
35
|
+
attributes: {
|
|
36
|
+
class: string;
|
|
37
|
+
spellcheck: string;
|
|
38
|
+
"data-placeholder": string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}) => void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const getEditorAttributes = (isEmpty: boolean) => ({
|
|
45
|
+
class: isEmpty ? "tiptap is-editor-empty" : "tiptap",
|
|
46
|
+
spellcheck: "true",
|
|
47
|
+
"data-placeholder": props.placeholder,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const updateEditorAttributes = (activeEditor: MarkdownEditor) => {
|
|
51
|
+
if (!activeEditor.setOptions) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const isEmpty = activeEditor.isEmpty ?? false;
|
|
55
|
+
activeEditor.setOptions({
|
|
56
|
+
editorProps: {
|
|
57
|
+
attributes: getEditorAttributes(isEmpty),
|
|
58
|
+
},
|
|
59
|
+
});
|
|
34
60
|
};
|
|
35
61
|
|
|
36
62
|
const getMarkdownFromEditor = (activeEditor: MarkdownEditor) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return storage.getMarkdown();
|
|
63
|
+
if (activeEditor.getMarkdown) {
|
|
64
|
+
return activeEditor.getMarkdown();
|
|
40
65
|
}
|
|
41
|
-
|
|
42
|
-
|
|
66
|
+
const markdownManager = activeEditor.markdown;
|
|
67
|
+
if (markdownManager?.serialize && activeEditor.getJSON) {
|
|
68
|
+
return markdownManager.serialize(activeEditor.getJSON());
|
|
43
69
|
}
|
|
44
|
-
|
|
70
|
+
const textFallback = activeEditor.getText?.();
|
|
71
|
+
return textFallback ?? "";
|
|
45
72
|
};
|
|
46
73
|
|
|
47
74
|
const editor = useEditor({
|
|
@@ -51,32 +78,33 @@ const editor = useEditor({
|
|
|
51
78
|
StarterKit,
|
|
52
79
|
Markdown,
|
|
53
80
|
Highlight,
|
|
54
|
-
Underline,
|
|
55
81
|
Placeholder.configure({
|
|
56
82
|
placeholder: props.placeholder,
|
|
83
|
+
emptyEditorClass: "is-editor-empty",
|
|
57
84
|
}),
|
|
58
85
|
],
|
|
59
86
|
editorProps: {
|
|
60
|
-
attributes:
|
|
61
|
-
class: "tiptap",
|
|
62
|
-
spellcheck: "true",
|
|
63
|
-
},
|
|
87
|
+
attributes: getEditorAttributes(!props.text),
|
|
64
88
|
},
|
|
65
|
-
|
|
89
|
+
onCreate: ({ editor: activeEditor }) => {
|
|
90
|
+
updateEditorAttributes(activeEditor);
|
|
91
|
+
},
|
|
92
|
+
onUpdate: ({ editor: activeEditor }) => {
|
|
93
|
+
updateEditorAttributes(activeEditor);
|
|
66
94
|
if (isUpdatingFromProps.value) {
|
|
67
95
|
return;
|
|
68
96
|
}
|
|
69
97
|
const markdown = getMarkdownFromEditor(activeEditor);
|
|
70
98
|
emit("update:text", markdown);
|
|
71
99
|
},
|
|
72
|
-
onBlur: ({ editor: activeEditor }
|
|
100
|
+
onBlur: ({ editor: activeEditor }) => {
|
|
73
101
|
const markdown = getMarkdownFromEditor(activeEditor);
|
|
74
102
|
emit("onBlur", markdown);
|
|
75
103
|
},
|
|
76
104
|
});
|
|
77
105
|
|
|
78
106
|
const editorMarkdown = computed(() =>
|
|
79
|
-
editor.value ? getMarkdownFromEditor(editor.value) : ""
|
|
107
|
+
editor.value ? getMarkdownFromEditor(editor.value) : "",
|
|
80
108
|
);
|
|
81
109
|
|
|
82
110
|
watch(
|
|
@@ -86,11 +114,9 @@ watch(
|
|
|
86
114
|
return;
|
|
87
115
|
}
|
|
88
116
|
isUpdatingFromProps.value = true;
|
|
89
|
-
editor.value.commands.setContent(newValue,
|
|
90
|
-
contentType: "markdown",
|
|
91
|
-
});
|
|
117
|
+
editor.value.commands.setContent(newValue, { contentType: "markdown" });
|
|
92
118
|
isUpdatingFromProps.value = false;
|
|
93
|
-
}
|
|
119
|
+
},
|
|
94
120
|
);
|
|
95
121
|
|
|
96
122
|
onBeforeUnmount(() => {
|
|
@@ -50,7 +50,6 @@
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
.tiptap {
|
|
53
|
-
min-height: 5.882rem;
|
|
54
53
|
width: 100%;
|
|
55
54
|
color: var(--autogrow-text-color);
|
|
56
55
|
outline: none;
|
|
@@ -74,6 +73,14 @@
|
|
|
74
73
|
pointer-events: none;
|
|
75
74
|
}
|
|
76
75
|
|
|
76
|
+
.tiptap.is-editor-empty::before {
|
|
77
|
+
color: var(--autogrow-placeholder-color);
|
|
78
|
+
content: attr(data-placeholder);
|
|
79
|
+
float: left;
|
|
80
|
+
height: 0;
|
|
81
|
+
pointer-events: none;
|
|
82
|
+
}
|
|
83
|
+
|
|
77
84
|
.tiptap strong {
|
|
78
85
|
font-weight: 700;
|
|
79
86
|
color: var(--autogrow-rt-strong);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umbra.ui/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Core components for Umbra UI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"@floating-ui/vue": "^1.1.7",
|
|
33
33
|
"@tiptap/extension-highlight": "^3.19.0",
|
|
34
34
|
"@tiptap/extension-placeholder": "^3.19.0",
|
|
35
|
-
"@tiptap/extension-underline": "^3.19.0",
|
|
36
35
|
"@tiptap/markdown": "^3.19.0",
|
|
37
36
|
"@tiptap/starter-kit": "^3.19.0",
|
|
38
37
|
"@tiptap/vue-3": "^3.19.0",
|
|
@@ -5,7 +5,6 @@ import StarterKit from "@tiptap/starter-kit";
|
|
|
5
5
|
import { Markdown } from "@tiptap/markdown";
|
|
6
6
|
import Highlight from "@tiptap/extension-highlight";
|
|
7
7
|
import Placeholder from "@tiptap/extension-placeholder";
|
|
8
|
-
import Underline from "@tiptap/extension-underline";
|
|
9
8
|
import "./theme.css";
|
|
10
9
|
import "./editor.css";
|
|
11
10
|
|
|
@@ -24,24 +23,52 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
24
23
|
const isUpdatingFromProps = ref(false);
|
|
25
24
|
|
|
26
25
|
type MarkdownEditor = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
getMarkdown?: () => string;
|
|
31
|
-
serialize?: (doc: unknown) => string;
|
|
32
|
-
};
|
|
26
|
+
getMarkdown?: () => string;
|
|
27
|
+
markdown?: {
|
|
28
|
+
serialize?: (docOrContent: any) => string;
|
|
33
29
|
};
|
|
30
|
+
getJSON?: () => unknown;
|
|
31
|
+
getText?: () => string;
|
|
32
|
+
isEmpty?: boolean;
|
|
33
|
+
setOptions?: (options: {
|
|
34
|
+
editorProps: {
|
|
35
|
+
attributes: {
|
|
36
|
+
class: string;
|
|
37
|
+
spellcheck: string;
|
|
38
|
+
"data-placeholder": string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}) => void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const getEditorAttributes = (isEmpty: boolean) => ({
|
|
45
|
+
class: isEmpty ? "tiptap is-editor-empty" : "tiptap",
|
|
46
|
+
spellcheck: "true",
|
|
47
|
+
"data-placeholder": props.placeholder,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const updateEditorAttributes = (activeEditor: MarkdownEditor) => {
|
|
51
|
+
if (!activeEditor.setOptions) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const isEmpty = activeEditor.isEmpty ?? false;
|
|
55
|
+
activeEditor.setOptions({
|
|
56
|
+
editorProps: {
|
|
57
|
+
attributes: getEditorAttributes(isEmpty),
|
|
58
|
+
},
|
|
59
|
+
});
|
|
34
60
|
};
|
|
35
61
|
|
|
36
62
|
const getMarkdownFromEditor = (activeEditor: MarkdownEditor) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return storage.getMarkdown();
|
|
63
|
+
if (activeEditor.getMarkdown) {
|
|
64
|
+
return activeEditor.getMarkdown();
|
|
40
65
|
}
|
|
41
|
-
|
|
42
|
-
|
|
66
|
+
const markdownManager = activeEditor.markdown;
|
|
67
|
+
if (markdownManager?.serialize && activeEditor.getJSON) {
|
|
68
|
+
return markdownManager.serialize(activeEditor.getJSON());
|
|
43
69
|
}
|
|
44
|
-
|
|
70
|
+
const textFallback = activeEditor.getText?.();
|
|
71
|
+
return textFallback ?? "";
|
|
45
72
|
};
|
|
46
73
|
|
|
47
74
|
const editor = useEditor({
|
|
@@ -51,32 +78,33 @@ const editor = useEditor({
|
|
|
51
78
|
StarterKit,
|
|
52
79
|
Markdown,
|
|
53
80
|
Highlight,
|
|
54
|
-
Underline,
|
|
55
81
|
Placeholder.configure({
|
|
56
82
|
placeholder: props.placeholder,
|
|
83
|
+
emptyEditorClass: "is-editor-empty",
|
|
57
84
|
}),
|
|
58
85
|
],
|
|
59
86
|
editorProps: {
|
|
60
|
-
attributes:
|
|
61
|
-
class: "tiptap",
|
|
62
|
-
spellcheck: "true",
|
|
63
|
-
},
|
|
87
|
+
attributes: getEditorAttributes(!props.text),
|
|
64
88
|
},
|
|
65
|
-
|
|
89
|
+
onCreate: ({ editor: activeEditor }) => {
|
|
90
|
+
updateEditorAttributes(activeEditor);
|
|
91
|
+
},
|
|
92
|
+
onUpdate: ({ editor: activeEditor }) => {
|
|
93
|
+
updateEditorAttributes(activeEditor);
|
|
66
94
|
if (isUpdatingFromProps.value) {
|
|
67
95
|
return;
|
|
68
96
|
}
|
|
69
97
|
const markdown = getMarkdownFromEditor(activeEditor);
|
|
70
98
|
emit("update:text", markdown);
|
|
71
99
|
},
|
|
72
|
-
onBlur: ({ editor: activeEditor }
|
|
100
|
+
onBlur: ({ editor: activeEditor }) => {
|
|
73
101
|
const markdown = getMarkdownFromEditor(activeEditor);
|
|
74
102
|
emit("onBlur", markdown);
|
|
75
103
|
},
|
|
76
104
|
});
|
|
77
105
|
|
|
78
106
|
const editorMarkdown = computed(() =>
|
|
79
|
-
editor.value ? getMarkdownFromEditor(editor.value) : ""
|
|
107
|
+
editor.value ? getMarkdownFromEditor(editor.value) : "",
|
|
80
108
|
);
|
|
81
109
|
|
|
82
110
|
watch(
|
|
@@ -86,11 +114,9 @@ watch(
|
|
|
86
114
|
return;
|
|
87
115
|
}
|
|
88
116
|
isUpdatingFromProps.value = true;
|
|
89
|
-
editor.value.commands.setContent(newValue,
|
|
90
|
-
contentType: "markdown",
|
|
91
|
-
});
|
|
117
|
+
editor.value.commands.setContent(newValue, { contentType: "markdown" });
|
|
92
118
|
isUpdatingFromProps.value = false;
|
|
93
|
-
}
|
|
119
|
+
},
|
|
94
120
|
);
|
|
95
121
|
|
|
96
122
|
onBeforeUnmount(() => {
|
|
@@ -50,7 +50,6 @@
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
.tiptap {
|
|
53
|
-
min-height: 5.882rem;
|
|
54
53
|
width: 100%;
|
|
55
54
|
color: var(--autogrow-text-color);
|
|
56
55
|
outline: none;
|
|
@@ -74,6 +73,14 @@
|
|
|
74
73
|
pointer-events: none;
|
|
75
74
|
}
|
|
76
75
|
|
|
76
|
+
.tiptap.is-editor-empty::before {
|
|
77
|
+
color: var(--autogrow-placeholder-color);
|
|
78
|
+
content: attr(data-placeholder);
|
|
79
|
+
float: left;
|
|
80
|
+
height: 0;
|
|
81
|
+
pointer-events: none;
|
|
82
|
+
}
|
|
83
|
+
|
|
77
84
|
.tiptap strong {
|
|
78
85
|
font-weight: 700;
|
|
79
86
|
color: var(--autogrow-rt-strong);
|