svelte-multistyle-ui 0.0.11-alpha → 0.0.14-alpha

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/README.md CHANGED
@@ -84,7 +84,7 @@ A Svelte action for portaling content to `document.body`:
84
84
  The library exports the following components from `svelte-multistyle-ui`:
85
85
 
86
86
  - Actions: `Button`, `IconButton`, `FAB`, `ButtonGroup`, `DropdownMenu`, `Popover`
87
- - Form: `Input`, `Textarea`, `Select`, `MultiSelect`, `Checkbox`, `Radio`, `Toggle`, `Slider`, `FileUpload`, `DatePicker`, `SortableList`
87
+ - Form: `Input`, `Textarea`, `TextEditor`, `Select`, `MultiSelect`, `Checkbox`, `Radio`, `Toggle`, `Slider`, `FileUpload`, `DatePicker`, `SortableList`
88
88
  - Layout: `Card`, `Divider`, `Tabs`, `Accordion`, `Modal`, `Drawer`, `CommandPalette`, `Row`, `Column`, `Grid`
89
89
  - Navigation: `Breadcrumb`, `Pagination`, `Stepper`
90
90
  - Data display: `Avatar`, `Chip`, `Tooltip`, `ProgressBar`, `Table`, `Spinner`, `Skeleton`, `Rating`
package/cli/registry.js CHANGED
@@ -23,6 +23,8 @@ const registry = {
23
23
  // ---------------- Form ----------------
24
24
  Input: { importName: "Input", kind: "leaf", bindable: ["value"], primaryBindable: "value" },
25
25
  Textarea: { importName: "Textarea", kind: "leaf", bindable: ["value"], primaryBindable: "value" },
26
+ TextEditor: { importName: "TextEditor", kind: "leaf", bindable: ["value"], primaryBindable: "value" },
27
+ CodeEditor: { importName: "CodeEditor", kind: "leaf", bindable: ["value"], primaryBindable: "value" },
26
28
  Select: { importName: "Select", kind: "leaf", bindable: ["value"], primaryBindable: "value", listProps: ["options"] },
27
29
  MultiSelect: { importName: "MultiSelect", kind: "leaf", bindable: ["selected"], primaryBindable: "selected", listProps: ["options"] },
28
30
  Checkbox: { importName: "Checkbox", kind: "leaf", bindable: ["checked"], primaryBindable: "checked" },
@@ -0,0 +1,130 @@
1
+ <script>
2
+ import "./codeeditor-styles.css";
3
+ import { defaults } from "../config.js";
4
+ import { cn } from "../utils/cn.js";
5
+ import Prism from "prismjs";
6
+ // Core ships markup, css, clike, javascript. Register the rest of the curated set.
7
+ import "prismjs/components/prism-typescript";
8
+ import "prismjs/components/prism-json";
9
+ import "prismjs/components/prism-bash";
10
+ import "prismjs/components/prism-python";
11
+
12
+ // prismjs does not ship a svelte component; alias it to markup (HTML-like)
13
+ // so Svelte code still gets tag/attribute/string highlighting.
14
+ if (!Prism.languages.svelte) {
15
+ Prism.languages.svelte = Prism.languages.markup;
16
+ }
17
+
18
+ let {
19
+ style: styleProp,
20
+ theme: themeProp,
21
+ value = $bindable(""),
22
+ language = "javascript",
23
+ editable = true,
24
+ label = "",
25
+ rows = 10,
26
+ class: className = "",
27
+ ...rest
28
+ } = $props();
29
+
30
+ const style = $derived(styleProp ?? defaults.style);
31
+ const theme = $derived(themeProp ?? defaults.theme);
32
+ const styleClass = $derived(`s-codeeditor-${style}`);
33
+ const themeClass = $derived(`theme-${theme}`);
34
+
35
+ const LANG_LABELS = {
36
+ javascript: "JS",
37
+ typescript: "TS",
38
+ markup: "HTML",
39
+ css: "CSS",
40
+ json: "JSON",
41
+ svelte: "Svelte",
42
+ bash: "Bash",
43
+ python: "Python",
44
+ };
45
+
46
+ function escapeHtml(s) {
47
+ return String(s)
48
+ .replace(/&/g, "&amp;")
49
+ .replace(/</g, "&lt;")
50
+ .replace(/>/g, "&gt;")
51
+ .replace(/"/g, "&quot;")
52
+ .replace(/'/g, "&#39;");
53
+ }
54
+
55
+ function highlight(code, lang) {
56
+ const grammar = Prism.languages[lang];
57
+ if (!grammar) return escapeHtml(code);
58
+ try {
59
+ return Prism.highlight(code, grammar, lang);
60
+ } catch {
61
+ return escapeHtml(code);
62
+ }
63
+ }
64
+
65
+ const highlighted = $derived(highlight(value, language));
66
+ const langLabel = $derived(
67
+ LANG_LABELS[language] ?? String(language).toUpperCase(),
68
+ );
69
+
70
+ let copyStatus = $state(""); // "" | "copied" | "failed"
71
+ async function copyCode() {
72
+ try {
73
+ await navigator.clipboard.writeText(value);
74
+ copyStatus = "copied";
75
+ } catch {
76
+ copyStatus = "failed";
77
+ }
78
+ setTimeout(() => (copyStatus = ""), 1800);
79
+ }
80
+ const copyLabel = $derived(
81
+ copyStatus === "copied"
82
+ ? "Copied!"
83
+ : copyStatus === "failed"
84
+ ? "Failed"
85
+ : "Copy",
86
+ );
87
+
88
+ // Scroll sync: keep the highlighted <pre> (behind) aligned with the
89
+ // transparent <textarea> (front) so the caret tracks the tokens.
90
+ let preEl = $state(null);
91
+ let taEl = $state(null);
92
+ function syncScroll() {
93
+ if (preEl && taEl) {
94
+ preEl.scrollTop = taEl.scrollTop;
95
+ preEl.scrollLeft = taEl.scrollLeft;
96
+ }
97
+ }
98
+ </script>
99
+
100
+ <div class={cn("s-codeeditor-wrapper", styleClass, themeClass, className)}>
101
+ {#if label}
102
+ <label class="s-codeeditor-label">{label}</label>
103
+ {/if}
104
+ <div class="s-codeeditor-toolbar">
105
+ <span class="s-codeeditor-lang">{langLabel}</span>
106
+ <button
107
+ type="button"
108
+ class={cn("s-codeeditor-copy-btn", copyStatus)}
109
+ onclick={copyCode}
110
+ aria-label="Copy code"
111
+ >
112
+ {copyLabel}
113
+ </button>
114
+ </div>
115
+ <div class="s-codeeditor-code" style:--codeeditor-rows={rows}>
116
+ <pre class="s-codeeditor-pre" bind:this={preEl} aria-hidden="true"><code
117
+ >{@html highlighted}</code></pre>
118
+ {#if editable}
119
+ <textarea
120
+ class="s-codeeditor-textarea"
121
+ bind:value
122
+ bind:this={taEl}
123
+ onscroll={syncScroll}
124
+ spellcheck="false"
125
+ aria-label={label || "code editor"}
126
+ {...rest}
127
+ ></textarea>
128
+ {/if}
129
+ </div>
130
+ </div>
@@ -0,0 +1,25 @@
1
+ export default CodeEditor;
2
+ type CodeEditor = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<$$ComponentProps>): void;
5
+ };
6
+ declare const CodeEditor: import("svelte").Component<{
7
+ style: any;
8
+ theme: any;
9
+ value?: string;
10
+ language?: string;
11
+ editable?: boolean;
12
+ label?: string;
13
+ rows?: number;
14
+ class?: string;
15
+ } & Record<string, any>, {}, "value">;
16
+ type $$ComponentProps = {
17
+ style: any;
18
+ theme: any;
19
+ value?: string;
20
+ language?: string;
21
+ editable?: boolean;
22
+ label?: string;
23
+ rows?: number;
24
+ class?: string;
25
+ } & Record<string, any>;