svelte-multistyle-ui 0.0.6-alpha → 0.0.8-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/cli/bin.js +3 -0
- package/cli/emit.js +3 -5
- package/cli/fixtures/sample.expected.svelte +229 -56
- package/cli/fixtures/sample.yaml +254 -128
- package/cli/generate.js +438 -7
- package/dist/components/Accordion.svelte +3 -1
- package/dist/components/Accordion.svelte.d.ts +2 -0
- package/dist/components/Alert.svelte +5 -3
- package/dist/components/Alert.svelte.d.ts +4 -2
- package/dist/components/Avatar.svelte +3 -1
- package/dist/components/Avatar.svelte.d.ts +2 -0
- package/dist/components/Breadcrumb.svelte +3 -2
- package/dist/components/Breadcrumb.svelte.d.ts +2 -0
- package/dist/components/Button.svelte +3 -1
- package/dist/components/Button.svelte.d.ts +2 -0
- package/dist/components/ButtonGroup.svelte +3 -1
- package/dist/components/ButtonGroup.svelte.d.ts +2 -0
- package/dist/components/Card.svelte +2 -1
- package/dist/components/Carousel.svelte +3 -1
- package/dist/components/Carousel.svelte.d.ts +2 -0
- package/dist/components/Checkbox.svelte +3 -1
- package/dist/components/Checkbox.svelte.d.ts +2 -0
- package/dist/components/Chip.svelte +3 -1
- package/dist/components/Chip.svelte.d.ts +2 -0
- package/dist/components/Column.svelte +2 -1
- package/dist/components/CommandPalette.svelte +3 -1
- package/dist/components/CommandPalette.svelte.d.ts +2 -0
- package/dist/components/DatePicker.svelte +3 -1
- package/dist/components/DatePicker.svelte.d.ts +2 -0
- package/dist/components/Divider.svelte +3 -1
- package/dist/components/Divider.svelte.d.ts +2 -0
- package/dist/components/Drawer.svelte +3 -1
- package/dist/components/Drawer.svelte.d.ts +2 -0
- package/dist/components/DropdownMenu.svelte +3 -1
- package/dist/components/DropdownMenu.svelte.d.ts +2 -0
- package/dist/components/FAB.svelte +3 -1
- package/dist/components/FAB.svelte.d.ts +2 -0
- package/dist/components/FileUpload.svelte +3 -1
- package/dist/components/FileUpload.svelte.d.ts +2 -0
- package/dist/components/Grid.svelte +2 -1
- package/dist/components/IconButton.svelte +3 -1
- package/dist/components/IconButton.svelte.d.ts +2 -0
- package/dist/components/Input.svelte +3 -1
- package/dist/components/Input.svelte.d.ts +2 -0
- package/dist/components/Modal.svelte +3 -1
- package/dist/components/Modal.svelte.d.ts +2 -0
- package/dist/components/MultiSelect.svelte +3 -1
- package/dist/components/MultiSelect.svelte.d.ts +2 -0
- package/dist/components/Pagination.svelte +3 -1
- package/dist/components/Pagination.svelte.d.ts +2 -0
- package/dist/components/Popover.svelte +3 -1
- package/dist/components/Popover.svelte.d.ts +2 -0
- package/dist/components/ProgressBar.svelte +3 -1
- package/dist/components/ProgressBar.svelte.d.ts +2 -0
- package/dist/components/Radio.svelte +3 -1
- package/dist/components/Radio.svelte.d.ts +2 -0
- package/dist/components/Rating.svelte +3 -1
- package/dist/components/Rating.svelte.d.ts +2 -0
- package/dist/components/Row.svelte +2 -1
- package/dist/components/Select.svelte +3 -1
- package/dist/components/Select.svelte.d.ts +2 -0
- package/dist/components/Skeleton.svelte +3 -1
- package/dist/components/Skeleton.svelte.d.ts +2 -0
- package/dist/components/Slider.svelte +3 -1
- package/dist/components/Slider.svelte.d.ts +2 -0
- package/dist/components/SortableList.svelte +3 -1
- package/dist/components/SortableList.svelte.d.ts +2 -0
- package/dist/components/Spinner.svelte +3 -1
- package/dist/components/Spinner.svelte.d.ts +2 -0
- package/dist/components/Stepper.svelte +3 -1
- package/dist/components/Stepper.svelte.d.ts +2 -0
- package/dist/components/Table.svelte +3 -1
- package/dist/components/Table.svelte.d.ts +2 -0
- package/dist/components/Tabs.svelte +3 -1
- package/dist/components/Tabs.svelte.d.ts +2 -0
- package/dist/components/Textarea.svelte +3 -1
- package/dist/components/Textarea.svelte.d.ts +2 -0
- package/dist/components/Toast.svelte +7 -5
- package/dist/components/Toast.svelte.d.ts +2 -0
- package/dist/components/Toggle.svelte +3 -1
- package/dist/components/Toggle.svelte.d.ts +2 -0
- package/dist/components/Tooltip.svelte +3 -1
- package/dist/components/Tooltip.svelte.d.ts +2 -0
- package/dist/components/charts/BarChart.svelte +2 -2
- package/dist/components/charts/BarChart.svelte.d.ts +2 -0
- package/dist/components/charts/BubbleChart.svelte +2 -2
- package/dist/components/charts/BubbleChart.svelte.d.ts +2 -0
- package/dist/components/charts/Chart.svelte +3 -1
- package/dist/components/charts/Chart.svelte.d.ts +2 -0
- package/dist/components/charts/ComboChart.svelte +2 -2
- package/dist/components/charts/ComboChart.svelte.d.ts +2 -0
- package/dist/components/charts/DoughnutChart.svelte +2 -2
- package/dist/components/charts/DoughnutChart.svelte.d.ts +2 -0
- package/dist/components/charts/LineChart.svelte +2 -2
- package/dist/components/charts/LineChart.svelte.d.ts +2 -0
- package/dist/components/charts/PieChart.svelte +2 -2
- package/dist/components/charts/PieChart.svelte.d.ts +2 -0
- package/dist/components/charts/PolarAreaChart.svelte +2 -2
- package/dist/components/charts/PolarAreaChart.svelte.d.ts +2 -0
- package/dist/components/charts/RadarChart.svelte +2 -2
- package/dist/components/charts/RadarChart.svelte.d.ts +2 -0
- package/dist/components/charts/ScatterChart.svelte +2 -2
- package/dist/components/charts/ScatterChart.svelte.d.ts +2 -0
- package/dist/components/charts/StackedBarChart.svelte +2 -2
- package/dist/components/charts/StackedBarChart.svelte.d.ts +2 -0
- package/dist/components/charts/StackedLineChart.svelte +2 -2
- package/dist/components/charts/StackedLineChart.svelte.d.ts +2 -0
- package/dist/components/select-styles.css +6 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/utils/cn.d.ts +1 -0
- package/dist/utils/cn.js +9 -0
- package/package.json +4 -3
package/cli/generate.js
CHANGED
|
@@ -1,9 +1,96 @@
|
|
|
1
1
|
// Orchestrator: parse YAML -> validate -> emit Svelte -> write file (or stdout).
|
|
2
|
+
//
|
|
3
|
+
// Three input styles are auto-detected:
|
|
4
|
+
//
|
|
5
|
+
// 1. Verbose schema (has a `body` key):
|
|
6
|
+
// state:
|
|
7
|
+
// - { name: username, type: string, default: "" }
|
|
8
|
+
// body:
|
|
9
|
+
// - component: Input
|
|
10
|
+
// props:
|
|
11
|
+
// label: Username
|
|
12
|
+
// bind: username
|
|
13
|
+
//
|
|
14
|
+
// 2. Proper YAML tree (no `body` key):
|
|
15
|
+
// Card:
|
|
16
|
+
// - Row:
|
|
17
|
+
// - Input:
|
|
18
|
+
// label: Username
|
|
19
|
+
//
|
|
20
|
+
// 3. Indentation-based shorthand (fallback when YAML parse fails):
|
|
21
|
+
// Card
|
|
22
|
+
// Row
|
|
23
|
+
// Input: { label: Username }
|
|
24
|
+
//
|
|
25
|
+
// Responsibilities:
|
|
26
|
+
// - parse all DSL styles into a common AST
|
|
27
|
+
// - auto-convert string[] options to {value,label}[]
|
|
28
|
+
// - inject fake data for Select/MultiSelect/Table/Charts when missing
|
|
29
|
+
// - auto-declare $state vars and bind: props for bindable components
|
|
30
|
+
// - validate and emit Svelte 5 markup
|
|
31
|
+
|
|
2
32
|
import fs from "node:fs";
|
|
3
33
|
import path from "node:path";
|
|
4
34
|
import yaml from "js-yaml";
|
|
5
35
|
import { validate } from "./schema.js";
|
|
6
36
|
import { emitPage } from "./emit.js";
|
|
37
|
+
import { registry } from "./registry.js";
|
|
38
|
+
|
|
39
|
+
const DEFAULT_OPTIONS = [
|
|
40
|
+
{ value: "opt1", label: "Option 1" },
|
|
41
|
+
{ value: "opt2", label: "Option 2" },
|
|
42
|
+
{ value: "opt3", label: "Option 3" },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
const DEFAULT_TABLE_DATA = [
|
|
46
|
+
{ id: 1, name: "Alice", role: "Admin" },
|
|
47
|
+
{ id: 2, name: "Bob", role: "User" },
|
|
48
|
+
{ id: 3, name: "Cara", role: "Editor" },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const DEFAULT_CHART_DATA = [
|
|
52
|
+
{ label: "q1", value: 12 },
|
|
53
|
+
{ label: "q2", value: 19 },
|
|
54
|
+
{ label: "q3", value: 8 },
|
|
55
|
+
{ label: "q4", value: 15 },
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const CHART_NAMES = new Set([
|
|
59
|
+
"BarChart",
|
|
60
|
+
"LineChart",
|
|
61
|
+
"PieChart",
|
|
62
|
+
"DoughnutChart",
|
|
63
|
+
"RadarChart",
|
|
64
|
+
"PolarAreaChart",
|
|
65
|
+
"ScatterChart",
|
|
66
|
+
"BubbleChart",
|
|
67
|
+
"StackedBarChart",
|
|
68
|
+
"StackedLineChart",
|
|
69
|
+
"ComboChart",
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
const BIND_TYPE = {
|
|
73
|
+
Input: "string",
|
|
74
|
+
Textarea: "string",
|
|
75
|
+
Select: "string",
|
|
76
|
+
MultiSelect: "array",
|
|
77
|
+
Checkbox: "bool",
|
|
78
|
+
Toggle: "bool",
|
|
79
|
+
Radio: "string",
|
|
80
|
+
Slider: "number",
|
|
81
|
+
DatePicker: "string",
|
|
82
|
+
ButtonGroup: "string",
|
|
83
|
+
SortableList: "array",
|
|
84
|
+
Tabs: "number",
|
|
85
|
+
Pagination: "number",
|
|
86
|
+
Modal: "bool",
|
|
87
|
+
Drawer: "bool",
|
|
88
|
+
CommandPalette: "bool",
|
|
89
|
+
Popover: "bool",
|
|
90
|
+
Rating: "number",
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const CONFIG_KEYS = new Set(["style", "theme", "mode"]);
|
|
7
94
|
|
|
8
95
|
/**
|
|
9
96
|
* @param {object} opts
|
|
@@ -20,12 +107,7 @@ export async function generate(opts) {
|
|
|
20
107
|
|
|
21
108
|
const runOnce = () => {
|
|
22
109
|
const src = fs.readFileSync(input, "utf8");
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
doc = yaml.load(src);
|
|
26
|
-
} catch (e) {
|
|
27
|
-
throw new Error(`YAML parse error in ${input}:\n${e.message}`);
|
|
28
|
-
}
|
|
110
|
+
const doc = parseInput(src);
|
|
29
111
|
const { errors, warnings } = validate(doc);
|
|
30
112
|
for (const w of warnings) console.error(`! ${w}`);
|
|
31
113
|
if (errors.length) {
|
|
@@ -65,4 +147,353 @@ export async function generate(opts) {
|
|
|
65
147
|
});
|
|
66
148
|
console.error(`↻ Watching ${input} for changes (Ctrl+C to stop)`);
|
|
67
149
|
}
|
|
68
|
-
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// Input parsing
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
function parseInput(src) {
|
|
157
|
+
let doc;
|
|
158
|
+
try {
|
|
159
|
+
doc = yaml.load(src);
|
|
160
|
+
if (doc == null) {
|
|
161
|
+
doc = null;
|
|
162
|
+
} else if (Array.isArray(doc)) {
|
|
163
|
+
// Root-level list of component mappings: wrap into the tree DSL.
|
|
164
|
+
doc = parseYamlTree({ __rootList: doc });
|
|
165
|
+
} else if (typeof doc === "object" && Array.isArray(doc.body)) {
|
|
166
|
+
// Verbose schema with explicit body/state — leave state as declared.
|
|
167
|
+
doc.state = doc.state || [];
|
|
168
|
+
} else if (typeof doc === "object") {
|
|
169
|
+
// Parsed YAML object without a `body` key: treat it as the compact/proper YAML tree DSL.
|
|
170
|
+
doc = parseYamlTree(doc);
|
|
171
|
+
} else {
|
|
172
|
+
doc = null;
|
|
173
|
+
}
|
|
174
|
+
} catch (e) {
|
|
175
|
+
doc = null;
|
|
176
|
+
}
|
|
177
|
+
if (!doc) {
|
|
178
|
+
doc = parseCompact(src);
|
|
179
|
+
}
|
|
180
|
+
return doc;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function emptyDoc() {
|
|
184
|
+
return {
|
|
185
|
+
style: "material",
|
|
186
|
+
theme: "default",
|
|
187
|
+
mode: "system",
|
|
188
|
+
state: [],
|
|
189
|
+
body: [],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Convert a proper YAML object (already parsed by js-yaml) into the internal doc
|
|
195
|
+
* format used by validate.js / emit.js.
|
|
196
|
+
*/
|
|
197
|
+
function parseYamlTree(yamlDoc) {
|
|
198
|
+
const doc = emptyDoc();
|
|
199
|
+
const body = [];
|
|
200
|
+
|
|
201
|
+
if (Array.isArray(yamlDoc.__rootList)) {
|
|
202
|
+
for (const child of yamlDoc.__rootList) {
|
|
203
|
+
body.push(convertYamlChild(child));
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
for (const [key, value] of Object.entries(yamlDoc)) {
|
|
207
|
+
if (key === "__rootList" || CONFIG_KEYS.has(key)) {
|
|
208
|
+
if (CONFIG_KEYS.has(key)) doc[key] = String(value ?? "");
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
body.push(convertYamlNode(key, value));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
doc.body = body;
|
|
216
|
+
doc.state = buildAutoState(body);
|
|
217
|
+
return doc;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Indentation-based fallback parser.
|
|
222
|
+
*/
|
|
223
|
+
function parseCompact(src) {
|
|
224
|
+
const lines = readLines(src);
|
|
225
|
+
if (lines.length === 0) return emptyDoc();
|
|
226
|
+
|
|
227
|
+
const rootIndent = lines[0].indent;
|
|
228
|
+
const doc = emptyDoc();
|
|
229
|
+
const body = [];
|
|
230
|
+
const stack = [{ depth: rootIndent - 1, children: body }];
|
|
231
|
+
|
|
232
|
+
for (let i = 0; i < lines.length; i++) {
|
|
233
|
+
const { indent, text } = lines[i];
|
|
234
|
+
|
|
235
|
+
// Top-level configuration keys (style/theme/mode).
|
|
236
|
+
const cfg = tryConfigLine(text, indent === rootIndent);
|
|
237
|
+
if (cfg) {
|
|
238
|
+
if (CONFIG_KEYS.has(cfg.key)) doc[cfg.key] = cfg.value;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const node = parseNodeLine(text, i + 1);
|
|
243
|
+
|
|
244
|
+
// Pop to the correct parent based on indentation.
|
|
245
|
+
while (stack.length > 1 && stack[stack.length - 1].depth >= indent) {
|
|
246
|
+
stack.pop();
|
|
247
|
+
}
|
|
248
|
+
const parent = stack[stack.length - 1];
|
|
249
|
+
parent.children.push(node);
|
|
250
|
+
stack.push({ depth: indent, children: node.children });
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
doc.body = body;
|
|
254
|
+
doc.state = buildAutoState(body);
|
|
255
|
+
return doc;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function convertYamlNode(name, value) {
|
|
259
|
+
const entry = registry[name];
|
|
260
|
+
const node = { component: name, props: {} };
|
|
261
|
+
|
|
262
|
+
if (value == null) {
|
|
263
|
+
// No value: e.g. `Row:` or `Table:` — children/props stay empty.
|
|
264
|
+
} else if (typeof value === "string") {
|
|
265
|
+
node.children = [value];
|
|
266
|
+
} else if (Array.isArray(value)) {
|
|
267
|
+
node.children = value.map((child) => convertYamlChild(child)).filter((c) => c !== undefined);
|
|
268
|
+
} else if (typeof value === "object") {
|
|
269
|
+
node.props = { ...value };
|
|
270
|
+
const textContent = node.props.children ?? node.props.text;
|
|
271
|
+
if (textContent != null) {
|
|
272
|
+
delete node.props.children;
|
|
273
|
+
delete node.props.text;
|
|
274
|
+
if (typeof textContent === "string") {
|
|
275
|
+
node.children = [textContent];
|
|
276
|
+
} else if (Array.isArray(textContent)) {
|
|
277
|
+
node.children = textContent.map((child) => convertYamlChild(child)).filter((c) => c !== undefined);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (entry?.kind === "multi-snippet") {
|
|
283
|
+
const snippets = {};
|
|
284
|
+
for (const sn of entry.snippets || []) {
|
|
285
|
+
const raw = node.props[sn];
|
|
286
|
+
if (raw != null) {
|
|
287
|
+
if (typeof raw === "string") snippets[sn] = raw;
|
|
288
|
+
else if (Array.isArray(raw)) snippets[sn] = raw.map((child) => convertYamlChild(child)).filter((c) => c !== undefined);
|
|
289
|
+
delete node.props[sn];
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (Object.keys(snippets).length) {
|
|
293
|
+
node.snippets = snippets;
|
|
294
|
+
}
|
|
295
|
+
if (!node.snippets) node.snippets = {};
|
|
296
|
+
node.children = [];
|
|
297
|
+
} else if (node.children == null && (!entry || entry.kind !== "leaf")) {
|
|
298
|
+
node.children = [];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return node;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function convertYamlChild(child) {
|
|
305
|
+
if (child == null) return undefined;
|
|
306
|
+
if (typeof child === "string") return child;
|
|
307
|
+
if (Array.isArray(child)) {
|
|
308
|
+
throw new Error("Child list entries must be component mappings or strings, not nested lists.");
|
|
309
|
+
}
|
|
310
|
+
if (typeof child === "object") {
|
|
311
|
+
const keys = Object.keys(child);
|
|
312
|
+
if (keys.length === 0) {
|
|
313
|
+
throw new Error("Empty child mapping is not a valid component node.");
|
|
314
|
+
}
|
|
315
|
+
const name = keys[0];
|
|
316
|
+
return convertYamlNode(name, child[name]);
|
|
317
|
+
}
|
|
318
|
+
return String(child);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function readLines(src) {
|
|
322
|
+
const out = [];
|
|
323
|
+
const raw = src.split("\n");
|
|
324
|
+
for (let i = 0; i < raw.length; i++) {
|
|
325
|
+
const line = raw[i];
|
|
326
|
+
const pos = line.search(/\S/);
|
|
327
|
+
if (pos === -1) continue;
|
|
328
|
+
const text = line.trim();
|
|
329
|
+
if (text.startsWith("#")) continue;
|
|
330
|
+
out.push({ indent: pos, text, line: i + 1 });
|
|
331
|
+
}
|
|
332
|
+
return out;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function tryConfigLine(text, atRoot) {
|
|
336
|
+
if (!atRoot) return null;
|
|
337
|
+
const m = text.match(/^(style|theme|mode)\s*:\s*(.*)$/);
|
|
338
|
+
if (!m) return null;
|
|
339
|
+
const key = m[1];
|
|
340
|
+
let value = m[2].trim();
|
|
341
|
+
try {
|
|
342
|
+
value = yaml.load(value);
|
|
343
|
+
} catch {
|
|
344
|
+
// keep raw string
|
|
345
|
+
}
|
|
346
|
+
return { key, value: String(value ?? "") };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function parseNodeLine(text, lineNo) {
|
|
350
|
+
const m = text.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?::\s*(.*))?$/);
|
|
351
|
+
if (!m) {
|
|
352
|
+
throw new Error(`Invalid compact YAML line ${lineNo}: ${text}`);
|
|
353
|
+
}
|
|
354
|
+
const name = m[1];
|
|
355
|
+
const rest = m[2] ?? "";
|
|
356
|
+
let props = {};
|
|
357
|
+
if (rest.trim()) {
|
|
358
|
+
try {
|
|
359
|
+
const v = yaml.load(rest);
|
|
360
|
+
if (v != null && typeof v === "object" && !Array.isArray(v)) {
|
|
361
|
+
props = v;
|
|
362
|
+
} else {
|
|
363
|
+
throw new Error("component props must be a mapping `{...}`");
|
|
364
|
+
}
|
|
365
|
+
} catch (e) {
|
|
366
|
+
throw new Error(`Bad props at line ${lineNo}: ${rest} (${e.message})`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const entry = registry[name];
|
|
371
|
+
const node = { component: name, props: { ...props } };
|
|
372
|
+
|
|
373
|
+
const textContent = props.children ?? props.text;
|
|
374
|
+
if (textContent != null) {
|
|
375
|
+
delete node.props.children;
|
|
376
|
+
delete node.props.text;
|
|
377
|
+
if (typeof textContent === "string") {
|
|
378
|
+
node.children = [textContent];
|
|
379
|
+
} else if (Array.isArray(textContent)) {
|
|
380
|
+
node.children = textContent;
|
|
381
|
+
}
|
|
382
|
+
} else if (!entry || entry.kind !== "leaf") {
|
|
383
|
+
node.children = [];
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return node;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// ---------------------------------------------------------------------------
|
|
390
|
+
// Auto-state, fake data, and default children
|
|
391
|
+
// ---------------------------------------------------------------------------
|
|
392
|
+
|
|
393
|
+
function buildAutoState(nodes, used = new Set()) {
|
|
394
|
+
const state = [];
|
|
395
|
+
for (const node of nodes) {
|
|
396
|
+
const entry = registry[node.component];
|
|
397
|
+
if (entry?.bindable?.length) {
|
|
398
|
+
const name = makeStateName(node, entry, used);
|
|
399
|
+
used.add(name);
|
|
400
|
+
const type = BIND_TYPE[node.component] || "string";
|
|
401
|
+
state.push({ name, type, default: defaultValue(type) });
|
|
402
|
+
if (entry.primaryBindable) {
|
|
403
|
+
node.bind = name;
|
|
404
|
+
} else {
|
|
405
|
+
node.bind = { [entry.bindable[0]]: name };
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
injectFakeData(node);
|
|
410
|
+
defaultChildren(node, entry);
|
|
411
|
+
|
|
412
|
+
if (Array.isArray(node.children) && node.children.length) {
|
|
413
|
+
state.push(...buildAutoState(node.children, used));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return state;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function makeStateName(node, entry, used) {
|
|
420
|
+
const props = node.props || {};
|
|
421
|
+
const raw = props.label || props.placeholder || props.title || entry.importName;
|
|
422
|
+
const parts = String(raw)
|
|
423
|
+
.toLowerCase()
|
|
424
|
+
.replace(/[^a-z0-9_$]+/g, " ")
|
|
425
|
+
.trim()
|
|
426
|
+
.split(/\s+/)
|
|
427
|
+
.filter(Boolean);
|
|
428
|
+
if (parts.length === 0) parts = [entry.importName.toLowerCase()];
|
|
429
|
+
|
|
430
|
+
let base = parts[0];
|
|
431
|
+
for (let i = 1; i < parts.length; i++) {
|
|
432
|
+
base += parts[i][0].toUpperCase() + parts[i].slice(1);
|
|
433
|
+
}
|
|
434
|
+
if (!/^[a-z_$]/.test(base)) base = "x" + base;
|
|
435
|
+
|
|
436
|
+
if (entry.importName === "Select" || entry.importName === "MultiSelect") {
|
|
437
|
+
base = "selected" + base[0].toUpperCase() + base.slice(1);
|
|
438
|
+
} else if (
|
|
439
|
+
(entry.importName === "Checkbox" || entry.importName === "Toggle") &&
|
|
440
|
+
!props.label
|
|
441
|
+
) {
|
|
442
|
+
base = "checked";
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
let name = base;
|
|
446
|
+
let i = 1;
|
|
447
|
+
while (used.has(name)) name = base + ++i;
|
|
448
|
+
return name;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function defaultValue(type) {
|
|
452
|
+
switch (type) {
|
|
453
|
+
case "number":
|
|
454
|
+
return 0;
|
|
455
|
+
case "bool":
|
|
456
|
+
case "boolean":
|
|
457
|
+
return false;
|
|
458
|
+
case "array":
|
|
459
|
+
return [];
|
|
460
|
+
default:
|
|
461
|
+
return "";
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function injectFakeData(node) {
|
|
466
|
+
const name = node.component;
|
|
467
|
+
const props = node.props;
|
|
468
|
+
|
|
469
|
+
if (name === "Select" || name === "MultiSelect") {
|
|
470
|
+
if (!props.options) {
|
|
471
|
+
props.options = DEFAULT_OPTIONS;
|
|
472
|
+
} else if (
|
|
473
|
+
Array.isArray(props.options) &&
|
|
474
|
+
props.options.length > 0 &&
|
|
475
|
+
typeof props.options[0] === "string"
|
|
476
|
+
) {
|
|
477
|
+
props.options = props.options.map((s) => ({
|
|
478
|
+
value: String(s).toLowerCase(),
|
|
479
|
+
label: s,
|
|
480
|
+
}));
|
|
481
|
+
}
|
|
482
|
+
} else if (name === "Table" && !props.data) {
|
|
483
|
+
props.data = DEFAULT_TABLE_DATA;
|
|
484
|
+
} else if (CHART_NAMES.has(name) && !props.data) {
|
|
485
|
+
props.data = DEFAULT_CHART_DATA;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function defaultChildren(node, entry) {
|
|
490
|
+
if (!entry) return;
|
|
491
|
+
if (
|
|
492
|
+
entry.kind === "children" &&
|
|
493
|
+
Array.isArray(node.children) &&
|
|
494
|
+
node.children.length === 0 &&
|
|
495
|
+
Object.keys(node.props || {}).length === 0
|
|
496
|
+
) {
|
|
497
|
+
node.children = [entry.importName];
|
|
498
|
+
}
|
|
499
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import "./accordion-styles.css";
|
|
3
3
|
import { defaults } from "../config.js";
|
|
4
|
+
import { cn } from "../utils/cn.js";
|
|
4
5
|
|
|
5
6
|
let {
|
|
6
7
|
style: styleProp,
|
|
@@ -8,6 +9,7 @@
|
|
|
8
9
|
items = [],
|
|
9
10
|
multiple = false,
|
|
10
11
|
current = "",
|
|
12
|
+
class: className = "",
|
|
11
13
|
...rest
|
|
12
14
|
} = $props();
|
|
13
15
|
|
|
@@ -33,7 +35,7 @@
|
|
|
33
35
|
}
|
|
34
36
|
</script>
|
|
35
37
|
|
|
36
|
-
<div class="s-accordion
|
|
38
|
+
<div class={cn("s-accordion", styleClass, themeClass, className)} {...rest}>
|
|
37
39
|
{#each items as item}
|
|
38
40
|
<div class="s-accordion-item" class:open={openItems.has(item.id)}>
|
|
39
41
|
<button
|
|
@@ -9,6 +9,7 @@ declare const Accordion: import("svelte").Component<{
|
|
|
9
9
|
items?: any[];
|
|
10
10
|
multiple?: boolean;
|
|
11
11
|
current?: string;
|
|
12
|
+
class?: string;
|
|
12
13
|
} & Record<string, any>, {}, "">;
|
|
13
14
|
type $$ComponentProps = {
|
|
14
15
|
style: any;
|
|
@@ -16,4 +17,5 @@ type $$ComponentProps = {
|
|
|
16
17
|
items?: any[];
|
|
17
18
|
multiple?: boolean;
|
|
18
19
|
current?: string;
|
|
20
|
+
class?: string;
|
|
19
21
|
} & Record<string, any>;
|
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
import "./alert-styles.css";
|
|
3
3
|
import { defaults, iconClass } from "../config.js";
|
|
4
4
|
import { slide } from "svelte/transition";
|
|
5
|
+
import { cn } from "../utils/cn.js";
|
|
5
6
|
|
|
6
7
|
let {
|
|
7
8
|
style: styleProp,
|
|
8
9
|
theme: themeProp,
|
|
9
|
-
|
|
10
|
+
preset = "info",
|
|
10
11
|
title = "",
|
|
11
12
|
icon: iconProp,
|
|
12
13
|
children,
|
|
13
14
|
dismissible = false,
|
|
15
|
+
class: className = "",
|
|
14
16
|
...rest
|
|
15
17
|
} = $props();
|
|
16
18
|
|
|
@@ -27,7 +29,7 @@
|
|
|
27
29
|
error: "✕"
|
|
28
30
|
};
|
|
29
31
|
|
|
30
|
-
const icon = $derived(iconProp ?? defaultIcons[
|
|
32
|
+
const icon = $derived(iconProp ?? defaultIcons[preset] ?? null);
|
|
31
33
|
const iconEl = $derived(icon && icon.length === 1 ? icon : null);
|
|
32
34
|
const iconName = $derived(icon && icon.length > 1 ? icon : null);
|
|
33
35
|
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
|
|
37
39
|
{#if visible}
|
|
38
40
|
<div
|
|
39
|
-
class="s-alert
|
|
41
|
+
class={cn("s-alert", styleClass, themeClass, `s-alert-${preset}`, className)}
|
|
40
42
|
role="alert"
|
|
41
43
|
transition:slide={{ duration: 200 }}
|
|
42
44
|
{...rest}
|
|
@@ -6,18 +6,20 @@ type Alert = {
|
|
|
6
6
|
declare const Alert: import("svelte").Component<{
|
|
7
7
|
style: any;
|
|
8
8
|
theme: any;
|
|
9
|
-
|
|
9
|
+
preset?: string;
|
|
10
10
|
title?: string;
|
|
11
11
|
icon: any;
|
|
12
12
|
children: any;
|
|
13
13
|
dismissible?: boolean;
|
|
14
|
+
class?: string;
|
|
14
15
|
} & Record<string, any>, {}, "">;
|
|
15
16
|
type $$ComponentProps = {
|
|
16
17
|
style: any;
|
|
17
18
|
theme: any;
|
|
18
|
-
|
|
19
|
+
preset?: string;
|
|
19
20
|
title?: string;
|
|
20
21
|
icon: any;
|
|
21
22
|
children: any;
|
|
22
23
|
dismissible?: boolean;
|
|
24
|
+
class?: string;
|
|
23
25
|
} & Record<string, any>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import "./avatar-styles.css";
|
|
3
3
|
import { defaults } from "../config.js";
|
|
4
|
+
import { cn } from "../utils/cn.js";
|
|
4
5
|
|
|
5
6
|
let {
|
|
6
7
|
style: styleProp,
|
|
@@ -9,6 +10,7 @@
|
|
|
9
10
|
alt = "",
|
|
10
11
|
size = "md",
|
|
11
12
|
fallback = "",
|
|
13
|
+
class: className = "",
|
|
12
14
|
...rest
|
|
13
15
|
} = $props();
|
|
14
16
|
|
|
@@ -22,7 +24,7 @@
|
|
|
22
24
|
let imgError = $state(false);
|
|
23
25
|
</script>
|
|
24
26
|
|
|
25
|
-
<div class="s-avatar
|
|
27
|
+
<div class={cn("s-avatar", styleClass, themeClass, sizeClass, className)} {...rest}>
|
|
26
28
|
{#if src && !imgError}
|
|
27
29
|
<img {src} {alt} onerror={() => (imgError = true)} />
|
|
28
30
|
{:else}
|
|
@@ -10,6 +10,7 @@ declare const Avatar: import("svelte").Component<{
|
|
|
10
10
|
alt?: string;
|
|
11
11
|
size?: string;
|
|
12
12
|
fallback?: string;
|
|
13
|
+
class?: string;
|
|
13
14
|
} & Record<string, any>, {}, "">;
|
|
14
15
|
type $$ComponentProps = {
|
|
15
16
|
style: any;
|
|
@@ -18,4 +19,5 @@ type $$ComponentProps = {
|
|
|
18
19
|
alt?: string;
|
|
19
20
|
size?: string;
|
|
20
21
|
fallback?: string;
|
|
22
|
+
class?: string;
|
|
21
23
|
} & Record<string, any>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import "./breadcrumb-styles.css";
|
|
3
3
|
import { defaults } from "../config.js";
|
|
4
|
+
import { cn } from "../utils/cn.js";
|
|
4
5
|
|
|
5
|
-
let { style: styleProp, theme: themeProp, items = [], ...rest } = $props();
|
|
6
|
+
let { style: styleProp, theme: themeProp, items = [], class: className = "", ...rest } = $props();
|
|
6
7
|
|
|
7
8
|
const style = $derived(styleProp ?? defaults.style);
|
|
8
9
|
const theme = $derived(themeProp ?? defaults.theme);
|
|
@@ -12,7 +13,7 @@
|
|
|
12
13
|
</script>
|
|
13
14
|
|
|
14
15
|
<nav
|
|
15
|
-
class="s-breadcrumb
|
|
16
|
+
class={cn("s-breadcrumb", styleClass, themeClass, className)}
|
|
16
17
|
aria-label="Breadcrumb"
|
|
17
18
|
{...rest}
|
|
18
19
|
>
|
|
@@ -7,9 +7,11 @@ declare const Breadcrumb: import("svelte").Component<{
|
|
|
7
7
|
style: any;
|
|
8
8
|
theme: any;
|
|
9
9
|
items?: any[];
|
|
10
|
+
class?: string;
|
|
10
11
|
} & Record<string, any>, {}, "">;
|
|
11
12
|
type $$ComponentProps = {
|
|
12
13
|
style: any;
|
|
13
14
|
theme: any;
|
|
14
15
|
items?: any[];
|
|
16
|
+
class?: string;
|
|
15
17
|
} & Record<string, any>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import "./button-styles.css";
|
|
3
3
|
import { defaults, iconClass } from "../config.js";
|
|
4
|
+
import { cn } from "../utils/cn.js";
|
|
4
5
|
|
|
5
6
|
let {
|
|
6
7
|
style: styleProp,
|
|
@@ -12,6 +13,7 @@
|
|
|
12
13
|
icon,
|
|
13
14
|
children,
|
|
14
15
|
onclick,
|
|
16
|
+
class: className = "",
|
|
15
17
|
...rest
|
|
16
18
|
} = $props();
|
|
17
19
|
|
|
@@ -26,7 +28,7 @@
|
|
|
26
28
|
</script>
|
|
27
29
|
|
|
28
30
|
<button
|
|
29
|
-
class="s-button
|
|
31
|
+
class={cn("s-button", styleClass, themeClass, variantClass, presetClass, sizeClass, className)}
|
|
30
32
|
{disabled}
|
|
31
33
|
{onclick}
|
|
32
34
|
{...rest}
|
|
@@ -13,6 +13,7 @@ declare const Button: import("svelte").Component<{
|
|
|
13
13
|
icon: any;
|
|
14
14
|
children: any;
|
|
15
15
|
onclick: any;
|
|
16
|
+
class?: string;
|
|
16
17
|
} & Record<string, any>, {}, "">;
|
|
17
18
|
type $$ComponentProps = {
|
|
18
19
|
style: any;
|
|
@@ -24,4 +25,5 @@ type $$ComponentProps = {
|
|
|
24
25
|
icon: any;
|
|
25
26
|
children: any;
|
|
26
27
|
onclick: any;
|
|
28
|
+
class?: string;
|
|
27
29
|
} & Record<string, any>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import "./buttongroup-styles.css";
|
|
3
3
|
import { defaults } from "../config.js";
|
|
4
|
+
import { cn } from "../utils/cn.js";
|
|
4
5
|
|
|
5
6
|
let {
|
|
6
7
|
style: styleProp,
|
|
@@ -10,6 +11,7 @@
|
|
|
10
11
|
items = [],
|
|
11
12
|
value = $bindable(""),
|
|
12
13
|
orientation = "horizontal",
|
|
14
|
+
class: className = "",
|
|
13
15
|
...rest
|
|
14
16
|
} = $props();
|
|
15
17
|
|
|
@@ -25,7 +27,7 @@
|
|
|
25
27
|
</script>
|
|
26
28
|
|
|
27
29
|
<div
|
|
28
|
-
class="s-btn-group
|
|
30
|
+
class={cn("s-btn-group", styleClass, themeClass, `btn-group-${orientation}`, `btn-group-${variant}`, `btn-group-${size}`, className)}
|
|
29
31
|
role="group"
|
|
30
32
|
{...rest}
|
|
31
33
|
>
|