@websline/system-components 1.3.11 → 1.3.12

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.
@@ -10,6 +10,13 @@ const moduleRegistry = import.meta.glob("./**/*.svelte", {
10
10
 
11
11
  const registry = {};
12
12
 
13
+ // e.g. for backwards compatibility
14
+ const synonyms = {
15
+ "checkbox-stack": "checkboxStack",
16
+ "file-pdf": "filePDF",
17
+ unlink: "connectCrossed",
18
+ };
19
+
13
20
  const addIconsToRegistry = (pathModuleRecord) => {
14
21
  const map = Object.fromEntries(
15
22
  Object.entries(pathModuleRecord).map(([path, module]) => {
@@ -28,26 +35,14 @@ const addIconsToRegistry = (pathModuleRecord) => {
28
35
  }),
29
36
  );
30
37
  Object.assign(registry, map);
31
- };
32
38
 
33
- // e.g. for backwards compatibility
34
- const synonyms = {
35
- "checkbox-stack": "checkboxStack",
36
- "file-pdf": "filePDF",
37
- unlink: "connectCrossed",
39
+ // attach synonyms to registry
40
+ Object.entries(synonyms).map(([k, v]) => {
41
+ if (registry[k]) return;
42
+ registry[k] = registry[v];
43
+ });
38
44
  };
39
45
 
40
46
  addIconsToRegistry(moduleRegistry);
41
47
 
42
- // attach synonyms to registry, with error handling for duplicates
43
- Object.entries(synonyms).map(([k, v]) => {
44
- if (registry[k]) {
45
- console.error(
46
- `skipping synonym "${k}" because it already exists in the registry`,
47
- );
48
- return;
49
- }
50
- registry[k] = registry[v];
51
- });
52
-
53
48
  export { addIconsToRegistry, registry, synonyms };
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { onMount, setContext } from "svelte";
2
+ import { setContext, untrack } from "svelte";
3
3
  import RichTextEditorToolbar from "./toolbar/RichTextEditorToolbar.svelte";
4
4
  import { richTextEditorVariants } from "./richTextEditor.variants.js";
5
5
 
@@ -42,9 +42,11 @@
42
42
  ...rest
43
43
  } = $props();
44
44
 
45
+ let DOMPurify;
45
46
  let element = $state();
46
- let htmlInputValue = $state();
47
+ /** @type {import("@tiptap/core").Editor} */
47
48
  let editor = $state.raw();
49
+ let htmlInputValue = $state();
48
50
 
49
51
  let styles = $derived(richTextEditorVariants({ hideToolbar, size }));
50
52
 
@@ -58,7 +60,7 @@
58
60
  const { TextStyle } = await import("@tiptap/extension-text-style");
59
61
  const Highlight = (await import("@tiptap/extension-highlight")).default;
60
62
  const Placeholder = (await import("@tiptap/extension-placeholder")).default;
61
- const DOMPurify = (await import("dompurify")).default;
63
+ DOMPurify = (await import("dompurify")).default;
62
64
 
63
65
  editor = new Editor({
64
66
  element: element,
@@ -86,24 +88,13 @@
86
88
  editorProps: {
87
89
  handlePaste(view, event) {
88
90
  const html = event.clipboardData.getData("text/html");
91
+ const sanitized = sanitizeContent(html);
92
+ if (!sanitized) return false;
89
93
 
90
- if (html) {
91
- const cleaned = DOMPurify.sanitize(html, {
92
- ALLOWED_TAGS: ["b", "strong", "i", "em", "u", "s", "strike", "p", "br"],
93
- ALLOWED_ATTR: [],
94
- });
95
-
96
- const normalized = cleanHTMLWhitespace(cleaned);
97
-
98
- editor.commands.insertContent(normalized);
99
-
100
- return true;
101
- }
102
-
103
- return false;
94
+ editor.commands.insertContent(sanitized);
95
+ return true;
104
96
  },
105
97
  },
106
- content,
107
98
  onUpdate: () => {
108
99
  htmlInputValue = editor.getHTML();
109
100
  oninput?.(htmlInputValue);
@@ -113,14 +104,24 @@
113
104
  editor.commands.focus("end");
114
105
  };
115
106
 
116
- onMount(() => {
117
- initEditor();
107
+ $effect(() => {
108
+ element;
109
+ placeholder;
110
+ untrack(initEditor);
118
111
 
119
112
  return () => {
120
113
  editor?.destroy();
121
114
  };
122
115
  });
123
116
 
117
+ $effect(() => {
118
+ content;
119
+ if (editor) {
120
+ const sanitized = untrack(() => sanitizeContent(content));
121
+ editor.commands.setContent(sanitized ?? "");
122
+ }
123
+ });
124
+
124
125
  const cleanHTMLWhitespace = (html) => {
125
126
  const dom = document.createElement("div");
126
127
  dom.innerHTML = html;
@@ -143,6 +144,17 @@
143
144
 
144
145
  return dom.innerHTML.trim();
145
146
  };
147
+
148
+ const sanitizeContent = (html) => {
149
+ if (typeof html !== "string" || !DOMPurify) return;
150
+
151
+ const cleaned = DOMPurify.sanitize(html, {
152
+ ALLOWED_TAGS: ["b", "strong", "i", "em", "u", "s", "strike", "p", "br"],
153
+ ALLOWED_ATTR: [],
154
+ });
155
+
156
+ return cleanHTMLWhitespace(cleaned);
157
+ };
146
158
  </script>
147
159
 
148
160
  <div class={styles.base({ class: classes.base })} {...rest}>
@@ -152,7 +164,7 @@
152
164
  </div>
153
165
  {/if}
154
166
  {#if fieldName}
155
- <input type="hidden" name={fieldName} bind:value={htmlInputValue} />
167
+ <input type="hidden" name={fieldName} value={htmlInputValue} />
156
168
  {/if}
157
169
  <div
158
170
  class={styles.field({ class: classes.field })}
@@ -7,12 +7,12 @@ const dialogVariants = tv({
7
7
  "my-4 grid max-h-[calc(100vh-32px)] w-[calc(100vw-32px)] min-w-xs grid-rows-[1fr_auto] gap-4 overflow-hidden rounded-lg bg-white px-4 py-3 leading-[1.486] shadow-sm dark:bg-neutral-800 dark:text-neutral-200",
8
8
  overlay: "fixed inset-0 z-modal-backdrop bg-black/25",
9
9
  positioner:
10
- "fixed inset-0 z-1 z-modal grid items-center justify-items-center overflow-auto",
10
+ "fixed inset-0 z-modal grid items-center justify-items-center overflow-auto",
11
11
  trigger: "cursor-pointer",
12
12
  formActions: [
13
- "[&>[data-role=dismiss]]:order-1 [&>[data-role=dismiss]]:mr-auto",
14
- "[&>[data-role=secondary]]:order-2",
15
- "[&>[data-role=cta]]:order-3",
13
+ "*:data-[role=dismiss]:order-1 *:data-[role=dismiss]:mr-auto",
14
+ "*:data-[role=secondary]:order-2",
15
+ "*:data-[role=cta]:order-3",
16
16
  ],
17
17
  },
18
18
  variants: {
@@ -9,7 +9,8 @@ const modalVariants = tv({
9
9
  "flex items-end border-b border-neutral-300 px-4 py-3 ui-title-2 dark:border-neutral-700",
10
10
  body: "h-full overflow-auto",
11
11
  overlay: "fixed inset-0 z-modal-backdrop bg-black/25",
12
- positioner: "fixed inset-0 z-modal grid items-center justify-items-center",
12
+ positioner:
13
+ "fixed inset-0 z-modal grid items-center justify-items-center overflow-auto",
13
14
  trigger: "cursor-pointer",
14
15
  },
15
16
  variants: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websline/system-components",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },