@websline/system-components 1.3.15 → 1.3.16
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.
|
@@ -42,7 +42,6 @@
|
|
|
42
42
|
...rest
|
|
43
43
|
} = $props();
|
|
44
44
|
|
|
45
|
-
let DOMPurify;
|
|
46
45
|
let element = $state();
|
|
47
46
|
/** @type {import("@tiptap/core").Editor} */
|
|
48
47
|
let editor = $state.raw();
|
|
@@ -61,7 +60,7 @@
|
|
|
61
60
|
const { TextStyle } = await import("@tiptap/extension-text-style");
|
|
62
61
|
const Highlight = (await import("@tiptap/extension-highlight")).default;
|
|
63
62
|
const Placeholder = (await import("@tiptap/extension-placeholder")).default;
|
|
64
|
-
DOMPurify = (await import("dompurify")).default;
|
|
63
|
+
const DOMPurify = (await import("dompurify")).default;
|
|
65
64
|
|
|
66
65
|
editor = new Editor({
|
|
67
66
|
element: element,
|
|
@@ -89,11 +88,21 @@
|
|
|
89
88
|
editorProps: {
|
|
90
89
|
handlePaste(view, event) {
|
|
91
90
|
const html = event.clipboardData.getData("text/html");
|
|
92
|
-
const sanitized = sanitizeContent(html);
|
|
93
|
-
if (!sanitized) return false;
|
|
94
91
|
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
if (html) {
|
|
93
|
+
const cleaned = DOMPurify.sanitize(html, {
|
|
94
|
+
ALLOWED_TAGS: ["b", "strong", "i", "em", "u", "s", "strike", "p", "br"],
|
|
95
|
+
ALLOWED_ATTR: [],
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const normalized = cleanHTMLWhitespace(cleaned);
|
|
99
|
+
|
|
100
|
+
editor.commands.insertContent(normalized);
|
|
101
|
+
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return false;
|
|
97
106
|
},
|
|
98
107
|
},
|
|
99
108
|
onUpdate: () => {
|
|
@@ -123,11 +132,9 @@
|
|
|
123
132
|
});
|
|
124
133
|
|
|
125
134
|
$effect(() => {
|
|
126
|
-
content;
|
|
127
135
|
if (editor) {
|
|
128
|
-
const sanitized = untrack(() => sanitizeContent(content));
|
|
129
136
|
isContentPropUpdate = true;
|
|
130
|
-
editor.commands.setContent(
|
|
137
|
+
editor.commands.setContent(content ?? "");
|
|
131
138
|
}
|
|
132
139
|
});
|
|
133
140
|
|
|
@@ -153,17 +160,6 @@
|
|
|
153
160
|
|
|
154
161
|
return dom.innerHTML.trim();
|
|
155
162
|
};
|
|
156
|
-
|
|
157
|
-
const sanitizeContent = (html) => {
|
|
158
|
-
if (typeof html !== "string" || !DOMPurify) return;
|
|
159
|
-
|
|
160
|
-
const cleaned = DOMPurify.sanitize(html, {
|
|
161
|
-
ALLOWED_TAGS: ["b", "strong", "i", "em", "u", "s", "strike", "p", "br"],
|
|
162
|
-
ALLOWED_ATTR: [],
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
return cleanHTMLWhitespace(cleaned);
|
|
166
|
-
};
|
|
167
163
|
</script>
|
|
168
164
|
|
|
169
165
|
<div class={styles.base({ class: classes.base })} {...rest}>
|
|
@@ -173,7 +169,7 @@
|
|
|
173
169
|
</div>
|
|
174
170
|
{/if}
|
|
175
171
|
{#if fieldName}
|
|
176
|
-
<input
|
|
172
|
+
<input name={fieldName} bind:value={content} />
|
|
177
173
|
{/if}
|
|
178
174
|
<div
|
|
179
175
|
class={styles.field({ class: classes.field })}
|