svelte-multistyle-ui 0.0.8-alpha → 0.0.11-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 +59 -0
- package/dist/components/MultiSelect.svelte +38 -2
- package/dist/components/Select.svelte +178 -83
- package/dist/components/TextEditor.svelte +187 -0
- package/dist/components/TextEditor.svelte.d.ts +27 -0
- package/dist/components/charts/chart-config.d.ts +2 -2
- package/dist/components/input-styles.css +1 -0
- package/dist/components/multiselect-styles.css +335 -338
- package/dist/components/select-styles.css +309 -252
- package/dist/components/text-editor-core/dom-utils.d.ts +17 -0
- package/dist/components/text-editor-core/dom-utils.js +151 -0
- package/dist/components/text-editor-core/editor-core.d.ts +113 -0
- package/dist/components/text-editor-core/editor-core.js +800 -0
- package/dist/components/text-editor-core/history.d.ts +14 -0
- package/dist/components/text-editor-core/history.js +78 -0
- package/dist/components/text-editor-core/html-formatter.d.ts +4 -0
- package/dist/components/text-editor-core/html-formatter.js +80 -0
- package/dist/components/text-editor-core/index.d.ts +7 -0
- package/dist/components/text-editor-core/index.js +22 -0
- package/dist/components/text-editor-core/sanitizer.d.ts +3 -0
- package/dist/components/text-editor-core/sanitizer.js +161 -0
- package/dist/components/text-editor-core/selection-engine.d.ts +11 -0
- package/dist/components/text-editor-core/selection-engine.js +137 -0
- package/dist/components/text-editor-core/toolbar-config.d.ts +113 -0
- package/dist/components/text-editor-core/toolbar-config.js +138 -0
- package/dist/components/texteditor-styles.css +483 -0
- package/dist/config.svelte.d.ts +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/themes/presets.d.ts +21 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,6 +140,7 @@ pnpm install
|
|
|
140
140
|
pnpm dev # start the demo
|
|
141
141
|
pnpm build # build the demo (static HTML/CSS/JS) to docs/
|
|
142
142
|
pnpm build:lib # build the library for publishing (to dist/)
|
|
143
|
+
pnpm gen:sample # dry-run the CLI generator sample fixture
|
|
143
144
|
pnpm preview # preview the production demo
|
|
144
145
|
pnpm test # run Playwright visual tests
|
|
145
146
|
pnpm test:ui # open the Playwright UI runner
|
|
@@ -151,6 +152,64 @@ The demo supports URL parameters for quick visual regression checks:
|
|
|
151
152
|
/?style=brutalist&theme=midnight&mode=dark
|
|
152
153
|
```
|
|
153
154
|
|
|
155
|
+
## CLI page generator
|
|
156
|
+
|
|
157
|
+
`svelte-multistyle-ui` ships a YAML → Svelte 5 page generator. It auto-detects three YAML input styles and emits token-efficient markup with auto-bound state and fake data injection.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npx svelte-multistyle-ui generate --input page.yaml --output ./src/routes/demo/+page.svelte
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Supported YAML styles:**
|
|
164
|
+
|
|
165
|
+
1. **Compact tree DSL** (recommended):
|
|
166
|
+
```yaml
|
|
167
|
+
Card:
|
|
168
|
+
- Row:
|
|
169
|
+
- Input:
|
|
170
|
+
label: Username
|
|
171
|
+
placeholder: Enter name
|
|
172
|
+
- Button:
|
|
173
|
+
label: Submit
|
|
174
|
+
```
|
|
175
|
+
2. **Root-level card list**:
|
|
176
|
+
```yaml
|
|
177
|
+
- Card:
|
|
178
|
+
- Row:
|
|
179
|
+
- Input:
|
|
180
|
+
label: Username
|
|
181
|
+
- Card:
|
|
182
|
+
- Row:
|
|
183
|
+
- Button:
|
|
184
|
+
label: Submit
|
|
185
|
+
```
|
|
186
|
+
3. **Inline shorthand**:
|
|
187
|
+
```yaml
|
|
188
|
+
Card
|
|
189
|
+
Row
|
|
190
|
+
Input: { label: Username }
|
|
191
|
+
Button: { label: Submit }
|
|
192
|
+
```
|
|
193
|
+
4. **Verbose schema**:
|
|
194
|
+
```yaml
|
|
195
|
+
state:
|
|
196
|
+
- { name: username, type: string, default: "" }
|
|
197
|
+
body:
|
|
198
|
+
- component: Input
|
|
199
|
+
props:
|
|
200
|
+
label: Username
|
|
201
|
+
bind: username
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Features:**
|
|
205
|
+
|
|
206
|
+
- **Auto-binding** — `Input`, `Select`, `Checkbox`, `Toggle`, `Radio`, `Slider`, `DatePicker`, `ButtonGroup`, `Rating`, `Tabs`, `Pagination`, `Popover`, `Modal`, `Drawer`, and `CommandPalette` get automatic `$state` vars and the correct `bind:*` directive.
|
|
207
|
+
- **Fake data** — missing `options` for `Select`/`MultiSelect`, missing `data` for `Table`, and missing chart data are synthesized automatically.
|
|
208
|
+
- **Option conversion** — `options: [Apple, Banana]` becomes `[{value:"apple",label:"Apple"}, ...]`.
|
|
209
|
+
- **Lightweight output** — generated files import from `svelte-multistyle-ui`, declare `$state`, include an empty `onMount` stub, and emit markup only; dark/light mode is handled by `initMultistyleUI` in the app layout.
|
|
210
|
+
|
|
211
|
+
See `skill/references/generator-cli.md` for the full CLI reference.
|
|
212
|
+
|
|
154
213
|
## Architecture notes
|
|
155
214
|
|
|
156
215
|
- Each component uses a base class (`s-<component>`), a style override class (`s-<component>-<style>`), and a theme class (`theme-<theme>`).
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import "./multiselect-styles.css";
|
|
3
|
+
import { portal } from "../actions/portal.js";
|
|
3
4
|
import { defaults } from "../config.js";
|
|
4
5
|
import { cn } from "../utils/cn.js";
|
|
5
6
|
|
|
@@ -20,6 +21,8 @@
|
|
|
20
21
|
|
|
21
22
|
let open = $state(false);
|
|
22
23
|
let focused = $state(false);
|
|
24
|
+
let wrapperEl;
|
|
25
|
+
let dropdownEl;
|
|
23
26
|
let hasValue = $derived(selected.length > 0);
|
|
24
27
|
let floated = $derived(focused || hasValue);
|
|
25
28
|
|
|
@@ -55,15 +58,44 @@
|
|
|
55
58
|
return opt ? opt.label : val;
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
function positionDropdown() {
|
|
62
|
+
if (!wrapperEl || !dropdownEl) return;
|
|
63
|
+
const rect = wrapperEl.getBoundingClientRect();
|
|
64
|
+
const ddHeight = dropdownEl.offsetHeight || 200;
|
|
65
|
+
let top = rect.bottom + 4;
|
|
66
|
+
if (top + ddHeight > window.innerHeight - 8 && rect.top - ddHeight - 4 > 8) {
|
|
67
|
+
top = rect.top - ddHeight - 4;
|
|
68
|
+
}
|
|
69
|
+
dropdownEl.style.left = `${rect.left}px`;
|
|
70
|
+
dropdownEl.style.top = `${top}px`;
|
|
71
|
+
dropdownEl.style.width = `${rect.width}px`;
|
|
72
|
+
}
|
|
73
|
+
|
|
58
74
|
function handleBlur(e) {
|
|
59
|
-
if (
|
|
75
|
+
if (
|
|
76
|
+
wrapperEl && !wrapperEl.contains(e.relatedTarget) &&
|
|
77
|
+
!(dropdownEl && dropdownEl.contains(e.relatedTarget))
|
|
78
|
+
) {
|
|
60
79
|
open = false;
|
|
61
80
|
focused = false;
|
|
62
81
|
}
|
|
63
82
|
}
|
|
83
|
+
|
|
84
|
+
$effect(() => {
|
|
85
|
+
if (!open) return;
|
|
86
|
+
const reposition = () => positionDropdown();
|
|
87
|
+
window.addEventListener("scroll", reposition, true);
|
|
88
|
+
window.addEventListener("resize", reposition);
|
|
89
|
+
queueMicrotask(reposition);
|
|
90
|
+
return () => {
|
|
91
|
+
window.removeEventListener("scroll", reposition, true);
|
|
92
|
+
window.removeEventListener("resize", reposition);
|
|
93
|
+
};
|
|
94
|
+
});
|
|
64
95
|
</script>
|
|
65
96
|
|
|
66
97
|
<div
|
|
98
|
+
bind:this={wrapperEl}
|
|
67
99
|
class={cn("s-mselect-wrapper", styleClass, themeClass, className)}
|
|
68
100
|
class:disabled
|
|
69
101
|
class:focused
|
|
@@ -125,7 +157,11 @@
|
|
|
125
157
|
</span>
|
|
126
158
|
</div>
|
|
127
159
|
{#if open}
|
|
128
|
-
<div
|
|
160
|
+
<div
|
|
161
|
+
class="mselect-dropdown {styleClass} {themeClass}"
|
|
162
|
+
bind:this={dropdownEl}
|
|
163
|
+
use:portal
|
|
164
|
+
>
|
|
129
165
|
{#each options as opt}
|
|
130
166
|
<label
|
|
131
167
|
class="mselect-option"
|
|
@@ -1,83 +1,178 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import "./select-styles.css";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
<script>
|
|
2
|
+
import "./select-styles.css";
|
|
3
|
+
import { portal } from "../actions/portal.js";
|
|
4
|
+
import { defaults } from "../config.js";
|
|
5
|
+
import { cn } from "../utils/cn.js";
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
style: styleProp,
|
|
9
|
+
theme: themeProp,
|
|
10
|
+
value = $bindable(""),
|
|
11
|
+
options = [],
|
|
12
|
+
placeholder = "Select...",
|
|
13
|
+
label = "",
|
|
14
|
+
disabled = false,
|
|
15
|
+
class: className = "",
|
|
16
|
+
...rest
|
|
17
|
+
} = $props();
|
|
18
|
+
|
|
19
|
+
const style = $derived(styleProp ?? defaults.style);
|
|
20
|
+
const theme = $derived(themeProp ?? defaults.theme);
|
|
21
|
+
|
|
22
|
+
let open = $state(false);
|
|
23
|
+
let focused = $state(false);
|
|
24
|
+
let wrapperEl;
|
|
25
|
+
let dropdownEl;
|
|
26
|
+
let hasValue = $derived(
|
|
27
|
+
value !== "" && value !== null && value !== undefined,
|
|
28
|
+
);
|
|
29
|
+
let floated = $derived(focused || hasValue);
|
|
30
|
+
|
|
31
|
+
const styleClass = $derived(`s-select-${style}`);
|
|
32
|
+
const themeClass = $derived(`theme-${theme}`);
|
|
33
|
+
|
|
34
|
+
const floatingStyles = [
|
|
35
|
+
"material",
|
|
36
|
+
"material3",
|
|
37
|
+
"fluent",
|
|
38
|
+
"carbon",
|
|
39
|
+
"bootstrap",
|
|
40
|
+
];
|
|
41
|
+
const hasFloatingLabel = $derived(
|
|
42
|
+
floatingStyles.includes(style) && (label || placeholder),
|
|
43
|
+
);
|
|
44
|
+
const displayLabel = $derived(label || placeholder);
|
|
45
|
+
|
|
46
|
+
function getLabel(val) {
|
|
47
|
+
const opt = options.find((o) => o.value === val);
|
|
48
|
+
return opt ? opt.label : val;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function selectOption(val) {
|
|
52
|
+
value = val;
|
|
53
|
+
open = false;
|
|
54
|
+
focused = false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function handleBlur() {
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
open = false;
|
|
60
|
+
focused = false;
|
|
61
|
+
}, 150);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function handleKeydown(e) {
|
|
65
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
open = !open;
|
|
68
|
+
focused = true;
|
|
69
|
+
} else if (e.key === "Escape") {
|
|
70
|
+
open = false;
|
|
71
|
+
focused = false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function positionDropdown() {
|
|
76
|
+
if (!wrapperEl || !dropdownEl) return;
|
|
77
|
+
const rect = wrapperEl.getBoundingClientRect();
|
|
78
|
+
const ddHeight = dropdownEl.offsetHeight || 200;
|
|
79
|
+
let top = rect.bottom + 4;
|
|
80
|
+
// Flip above the field if it would overflow the bottom of the viewport.
|
|
81
|
+
if (top + ddHeight > window.innerHeight - 8 && rect.top - ddHeight - 4 > 8) {
|
|
82
|
+
top = rect.top - ddHeight - 4;
|
|
83
|
+
}
|
|
84
|
+
dropdownEl.style.left = `${rect.left}px`;
|
|
85
|
+
dropdownEl.style.top = `${top}px`;
|
|
86
|
+
dropdownEl.style.width = `${rect.width}px`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
$effect(() => {
|
|
90
|
+
if (open) {
|
|
91
|
+
const handler = (e) => {
|
|
92
|
+
if (
|
|
93
|
+
wrapperEl && !wrapperEl.contains(e.target) &&
|
|
94
|
+
!(dropdownEl && dropdownEl.contains(e.target))
|
|
95
|
+
) {
|
|
96
|
+
open = false;
|
|
97
|
+
focused = false;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
document.addEventListener("pointerdown", handler);
|
|
101
|
+
const reposition = () => positionDropdown();
|
|
102
|
+
window.addEventListener("scroll", reposition, true);
|
|
103
|
+
window.addEventListener("resize", reposition);
|
|
104
|
+
queueMicrotask(reposition);
|
|
105
|
+
return () => {
|
|
106
|
+
document.removeEventListener("pointerdown", handler);
|
|
107
|
+
window.removeEventListener("scroll", reposition, true);
|
|
108
|
+
window.removeEventListener("resize", reposition);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<div
|
|
115
|
+
bind:this={wrapperEl}
|
|
116
|
+
class={cn("s-select-wrapper", styleClass, themeClass, className)}
|
|
117
|
+
class:disabled
|
|
118
|
+
class:focused
|
|
119
|
+
class:has-value={hasValue}
|
|
120
|
+
class:floated
|
|
121
|
+
class:open
|
|
122
|
+
tabindex="-1"
|
|
123
|
+
role="listbox"
|
|
124
|
+
aria-label={displayLabel}
|
|
125
|
+
onfocusin={() => (focused = true)}
|
|
126
|
+
onfocusout={handleBlur}
|
|
127
|
+
{...rest}
|
|
128
|
+
>
|
|
129
|
+
{#if hasFloatingLabel}
|
|
130
|
+
<label class="s-select-floating-label"
|
|
131
|
+
>{displayLabel}</label
|
|
132
|
+
>
|
|
133
|
+
{/if}
|
|
134
|
+
<div
|
|
135
|
+
class="s-select-control"
|
|
136
|
+
role="button"
|
|
137
|
+
tabindex="0"
|
|
138
|
+
onclick={() => (open = !open)}
|
|
139
|
+
onkeydown={handleKeydown}
|
|
140
|
+
>
|
|
141
|
+
{#if hasValue && !hasFloatingLabel}
|
|
142
|
+
<span class="s-select-value">{getLabel(value)}</span>
|
|
143
|
+
{:else if !hasFloatingLabel}
|
|
144
|
+
<span class="s-select-placeholder">{placeholder}</span>
|
|
145
|
+
{/if}
|
|
146
|
+
{#if hasFloatingLabel && hasValue}
|
|
147
|
+
<span class="s-select-value">{getLabel(value)}</span>
|
|
148
|
+
{/if}
|
|
149
|
+
<span class="s-select-arrow">
|
|
150
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
|
|
151
|
+
<path
|
|
152
|
+
d="M2.5 4.5L6 8L9.5 4.5"
|
|
153
|
+
stroke="currentColor"
|
|
154
|
+
stroke-width="1.5"
|
|
155
|
+
stroke-linecap="round"
|
|
156
|
+
stroke-linejoin="round"
|
|
157
|
+
/>
|
|
158
|
+
</svg>
|
|
159
|
+
</span>
|
|
160
|
+
</div>
|
|
161
|
+
{#if open}
|
|
162
|
+
<div
|
|
163
|
+
class="s-select-dropdown {styleClass} {themeClass}"
|
|
164
|
+
bind:this={dropdownEl}
|
|
165
|
+
use:portal
|
|
166
|
+
>
|
|
167
|
+
{#each options as opt}
|
|
168
|
+
<div
|
|
169
|
+
class="s-select-option"
|
|
170
|
+
class:selected={value === opt.value}
|
|
171
|
+
onclick={() => selectOption(opt.value)}
|
|
172
|
+
>
|
|
173
|
+
{opt.label}
|
|
174
|
+
</div>
|
|
175
|
+
{/each}
|
|
176
|
+
</div>
|
|
177
|
+
{/if}
|
|
178
|
+
</div>
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import "./texteditor-styles.css";
|
|
3
|
+
import { defaults } from "../config.js";
|
|
4
|
+
import { cn } from "../utils/cn.js";
|
|
5
|
+
import { onMount, onDestroy } from "svelte";
|
|
6
|
+
import { TextEditorCore } from "./text-editor-core/index.js";
|
|
7
|
+
import { Modal, Button, Input, Textarea } from "../index.js";
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
style: styleProp,
|
|
11
|
+
theme: themeProp,
|
|
12
|
+
value = $bindable(""),
|
|
13
|
+
label = "",
|
|
14
|
+
placeholder = "",
|
|
15
|
+
disabled = false,
|
|
16
|
+
rows = 8,
|
|
17
|
+
toolbar,
|
|
18
|
+
class: className = "",
|
|
19
|
+
...rest
|
|
20
|
+
} = $props();
|
|
21
|
+
|
|
22
|
+
const style = $derived(styleProp ?? defaults.style);
|
|
23
|
+
const theme = $derived(themeProp ?? defaults.theme);
|
|
24
|
+
|
|
25
|
+
const styleClass = $derived(`s-texteditor-${style}`);
|
|
26
|
+
const themeClass = $derived(`theme-${theme}`);
|
|
27
|
+
|
|
28
|
+
let wrapper = $state(null);
|
|
29
|
+
let core = $state(null);
|
|
30
|
+
let previousDisabled = $state(disabled);
|
|
31
|
+
|
|
32
|
+
let dialog = $state({ open: false, type: null, data: null });
|
|
33
|
+
let imageFileInput = $state(null);
|
|
34
|
+
|
|
35
|
+
onMount(() => {
|
|
36
|
+
core = new TextEditorCore({
|
|
37
|
+
element: wrapper,
|
|
38
|
+
placeholder,
|
|
39
|
+
readOnly: disabled,
|
|
40
|
+
toolbar,
|
|
41
|
+
onChange: (html) => {
|
|
42
|
+
value = html;
|
|
43
|
+
},
|
|
44
|
+
onAction: (action) => {
|
|
45
|
+
if (action.type === "dialog") {
|
|
46
|
+
dialog = { open: true, type: action.dialog, data: { ...action.data } };
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
core.setHTML(value ?? "");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
$effect(() => {
|
|
55
|
+
if (!core) return;
|
|
56
|
+
// Don't overwrite code-view textarea from external value changes.
|
|
57
|
+
if (core.isCodeView()) return;
|
|
58
|
+
|
|
59
|
+
const html = value ?? "";
|
|
60
|
+
if (core.getHTML() !== html) {
|
|
61
|
+
core.setHTML(html);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
$effect(() => {
|
|
66
|
+
if (!core) return;
|
|
67
|
+
if (disabled !== previousDisabled) {
|
|
68
|
+
core.setReadOnly(disabled);
|
|
69
|
+
previousDisabled = disabled;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
onDestroy(() => {
|
|
74
|
+
core?.destroy();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
function applyLink() {
|
|
78
|
+
const { text, href, title, target } = dialog.data;
|
|
79
|
+
core?.insertLink({ text, href, title, target });
|
|
80
|
+
dialog = { open: false, type: null, data: null };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function applyImage() {
|
|
84
|
+
const { src, alt, width, align, caption } = dialog.data;
|
|
85
|
+
core?.insertImage({ src, alt, width, align, caption });
|
|
86
|
+
dialog = { open: false, type: null, data: null };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function applyVideo() {
|
|
90
|
+
const { src, width, height } = dialog.data;
|
|
91
|
+
core?.insertVideo({ src, width, height });
|
|
92
|
+
dialog = { open: false, type: null, data: null };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function applyTable() {
|
|
96
|
+
const { rows, cols } = dialog.data;
|
|
97
|
+
core?.insertTable({ rows, cols });
|
|
98
|
+
dialog = { open: false, type: null, data: null };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function onImageFileChange(e) {
|
|
102
|
+
const file = e.target.files?.[0];
|
|
103
|
+
if (!file) return;
|
|
104
|
+
const reader = new FileReader();
|
|
105
|
+
reader.onload = (ev) => {
|
|
106
|
+
dialog.data = { ...dialog.data, src: ev.target.result };
|
|
107
|
+
};
|
|
108
|
+
reader.readAsDataURL(file);
|
|
109
|
+
}
|
|
110
|
+
</script>
|
|
111
|
+
|
|
112
|
+
<div
|
|
113
|
+
class={cn("s-texteditor-wrapper", styleClass, themeClass, className)}
|
|
114
|
+
{...rest}
|
|
115
|
+
>
|
|
116
|
+
{#if label}
|
|
117
|
+
<label class="s-texteditor-label">{label}</label>
|
|
118
|
+
{/if}
|
|
119
|
+
<div
|
|
120
|
+
bind:this={wrapper}
|
|
121
|
+
class="s-texteditor-root"
|
|
122
|
+
data-placeholder={placeholder}
|
|
123
|
+
style:--texteditor-rows={rows}
|
|
124
|
+
aria-disabled={disabled}
|
|
125
|
+
></div>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
{#if dialog.open}
|
|
129
|
+
{#if dialog.type === "link"}
|
|
130
|
+
<Modal bind:open={dialog.open} title="Insert link" size="small">
|
|
131
|
+
<div class="s-texteditor-dialog">
|
|
132
|
+
<Input label="Text" bind:value={dialog.data.text} />
|
|
133
|
+
<Input label="URL" bind:value={dialog.data.href} />
|
|
134
|
+
<Input label="Title" bind:value={dialog.data.title} />
|
|
135
|
+
<Input label="Target" bind:value={dialog.data.target} />
|
|
136
|
+
<div class="s-texteditor-dialog-actions">
|
|
137
|
+
<Button onclick={applyLink}>Apply</Button>
|
|
138
|
+
<Button variant="outlined" onclick={() => (dialog.open = false)}>Cancel</Button>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</Modal>
|
|
142
|
+
{:else if dialog.type === "image"}
|
|
143
|
+
<Modal bind:open={dialog.open} title="Insert image" size="small">
|
|
144
|
+
<div class="s-texteditor-dialog">
|
|
145
|
+
<Input label="Image URL" bind:value={dialog.data.src} />
|
|
146
|
+
<div class="s-texteditor-dialog-row">
|
|
147
|
+
<input
|
|
148
|
+
bind:this={imageFileInput}
|
|
149
|
+
type="file"
|
|
150
|
+
accept="image/*"
|
|
151
|
+
onchange={onImageFileChange}
|
|
152
|
+
/>
|
|
153
|
+
</div>
|
|
154
|
+
<Input label="Alt text" bind:value={dialog.data.alt} />
|
|
155
|
+
<Input label="Width (e.g. 200px)" bind:value={dialog.data.width} />
|
|
156
|
+
<Input label="Caption" bind:value={dialog.data.caption} />
|
|
157
|
+
<div class="s-texteditor-dialog-actions">
|
|
158
|
+
<Button onclick={applyImage}>Insert</Button>
|
|
159
|
+
<Button variant="outlined" onclick={() => (dialog.open = false)}>Cancel</Button>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
</Modal>
|
|
163
|
+
{:else if dialog.type === "video"}
|
|
164
|
+
<Modal bind:open={dialog.open} title="Insert video" size="small">
|
|
165
|
+
<div class="s-texteditor-dialog">
|
|
166
|
+
<Textarea label="YouTube, Vimeo, or direct URL" rows={3} bind:value={dialog.data.src} />
|
|
167
|
+
<Input label="Width" bind:value={dialog.data.width} />
|
|
168
|
+
<Input label="Height" bind:value={dialog.data.height} />
|
|
169
|
+
<div class="s-texteditor-dialog-actions">
|
|
170
|
+
<Button onclick={applyVideo}>Insert</Button>
|
|
171
|
+
<Button variant="outlined" onclick={() => (dialog.open = false)}>Cancel</Button>
|
|
172
|
+
</div>
|
|
173
|
+
</div>
|
|
174
|
+
</Modal>
|
|
175
|
+
{:else if dialog.type === "table"}
|
|
176
|
+
<Modal bind:open={dialog.open} title="Insert table" size="small">
|
|
177
|
+
<div class="s-texteditor-dialog">
|
|
178
|
+
<Input label="Rows" type="number" bind:value={dialog.data.rows} />
|
|
179
|
+
<Input label="Columns" type="number" bind:value={dialog.data.cols} />
|
|
180
|
+
<div class="s-texteditor-dialog-actions">
|
|
181
|
+
<Button onclick={applyTable}>Insert</Button>
|
|
182
|
+
<Button variant="outlined" onclick={() => (dialog.open = false)}>Cancel</Button>
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
185
|
+
</Modal>
|
|
186
|
+
{/if}
|
|
187
|
+
{/if}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default TextEditor;
|
|
2
|
+
type TextEditor = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const TextEditor: import("svelte").Component<{
|
|
7
|
+
style: any;
|
|
8
|
+
theme: any;
|
|
9
|
+
value?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
rows?: number;
|
|
14
|
+
toolbar: any;
|
|
15
|
+
class?: string;
|
|
16
|
+
} & Record<string, any>, {}, "value">;
|
|
17
|
+
type $$ComponentProps = {
|
|
18
|
+
style: any;
|
|
19
|
+
theme: any;
|
|
20
|
+
value?: string;
|
|
21
|
+
label?: string;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
rows?: number;
|
|
25
|
+
toolbar: any;
|
|
26
|
+
class?: string;
|
|
27
|
+
} & Record<string, any>;
|
|
@@ -30,7 +30,7 @@ export function buildData(type: any, { data, series, labels }: {
|
|
|
30
30
|
labels: any;
|
|
31
31
|
}, tokens: any): {
|
|
32
32
|
datasets: {
|
|
33
|
-
label:
|
|
33
|
+
label: undefined;
|
|
34
34
|
data: any;
|
|
35
35
|
backgroundColor: any;
|
|
36
36
|
}[];
|
|
@@ -122,6 +122,6 @@ export function buildOptions(type: string, style: string, tokens: object, { titl
|
|
|
122
122
|
padding: {
|
|
123
123
|
bottom: number;
|
|
124
124
|
};
|
|
125
|
-
};
|
|
125
|
+
} | undefined;
|
|
126
126
|
};
|
|
127
127
|
};
|
|
@@ -383,6 +383,7 @@
|
|
|
383
383
|
-webkit-backdrop-filter: blur(24px) saturate(1.6);
|
|
384
384
|
box-shadow: var(--t-shadow-md), inset 0 1px 0 rgba(255,255,255,0.3);
|
|
385
385
|
transition: all 0.3s ease;
|
|
386
|
+
min-height: 59px;
|
|
386
387
|
}
|
|
387
388
|
.s-input-liquid-glass:hover {
|
|
388
389
|
background: rgba(255,255,255,0.15);
|