@widgentic/designer 0.1.0
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/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/action-designer.d.ts +35 -0
- package/dist/action-designer.d.ts.map +1 -0
- package/dist/action-designer.js +294 -0
- package/dist/action-designer.js.map +1 -0
- package/dist/action-editor.d.ts +49 -0
- package/dist/action-editor.d.ts.map +1 -0
- package/dist/action-editor.js +515 -0
- package/dist/action-editor.js.map +1 -0
- package/dist/browser/widgentic-designer.js +433 -0
- package/dist/browser/widgentic-designer.js.map +7 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +12 -0
- package/dist/browser.js.map +1 -0
- package/dist/dom.d.ts +37 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +387 -0
- package/dist/dom.js.map +1 -0
- package/dist/element.d.ts +12 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +131 -0
- package/dist/element.js.map +1 -0
- package/dist/highlight.d.ts +30 -0
- package/dist/highlight.d.ts.map +1 -0
- package/dist/highlight.js +123 -0
- package/dist/highlight.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +6 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +10 -0
- package/dist/internal.js.map +1 -0
- package/dist/io.d.ts +32 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +155 -0
- package/dist/io.js.map +1 -0
- package/dist/json-tree-editor.d.ts +8 -0
- package/dist/json-tree-editor.d.ts.map +1 -0
- package/dist/json-tree-editor.js +186 -0
- package/dist/json-tree-editor.js.map +1 -0
- package/dist/panels.d.ts +13 -0
- package/dist/panels.d.ts.map +1 -0
- package/dist/panels.js +414 -0
- package/dist/panels.js.map +1 -0
- package/dist/preview.d.ts +40 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +138 -0
- package/dist/preview.js.map +1 -0
- package/dist/record-editor.d.ts +11 -0
- package/dist/record-editor.d.ts.map +1 -0
- package/dist/record-editor.js +70 -0
- package/dist/record-editor.js.map +1 -0
- package/dist/schema-builder.d.ts +8 -0
- package/dist/schema-builder.d.ts.map +1 -0
- package/dist/schema-builder.js +235 -0
- package/dist/schema-builder.js.map +1 -0
- package/dist/schema-designer.d.ts +33 -0
- package/dist/schema-designer.d.ts.map +1 -0
- package/dist/schema-designer.js +251 -0
- package/dist/schema-designer.js.map +1 -0
- package/dist/schema-form.d.ts +8 -0
- package/dist/schema-form.d.ts.map +1 -0
- package/dist/schema-form.js +181 -0
- package/dist/schema-form.js.map +1 -0
- package/dist/schema-paths.d.ts +18 -0
- package/dist/schema-paths.d.ts.map +1 -0
- package/dist/schema-paths.js +75 -0
- package/dist/schema-paths.js.map +1 -0
- package/dist/seed.d.ts +18 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +299 -0
- package/dist/seed.js.map +1 -0
- package/dist/shell.d.ts +59 -0
- package/dist/shell.d.ts.map +1 -0
- package/dist/shell.js +102 -0
- package/dist/shell.js.map +1 -0
- package/dist/store.d.ts +44 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +71 -0
- package/dist/store.js.map +1 -0
- package/dist/styles-editor.d.ts +8 -0
- package/dist/styles-editor.d.ts.map +1 -0
- package/dist/styles-editor.js +100 -0
- package/dist/styles-editor.js.map +1 -0
- package/dist/template-panel.d.ts +19 -0
- package/dist/template-panel.d.ts.map +1 -0
- package/dist/template-panel.js +585 -0
- package/dist/template-panel.js.map +1 -0
- package/dist/theme-designer.d.ts +35 -0
- package/dist/theme-designer.d.ts.map +1 -0
- package/dist/theme-designer.js +336 -0
- package/dist/theme-designer.js.map +1 -0
- package/dist/theme-panel.d.ts +20 -0
- package/dist/theme-panel.d.ts.map +1 -0
- package/dist/theme-panel.js +96 -0
- package/dist/theme-panel.js.map +1 -0
- package/dist/validate.d.ts +57 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +131 -0
- package/dist/validate.js.map +1 -0
- package/package.json +49 -0
package/dist/seed.js
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seeding: start a new draft as a COPY of something that exists — a stored
|
|
3
|
+
* widget, a stored theme, a built-in kind, or a theme preset. A seed is a
|
|
4
|
+
* copy at creation time with a distinct identity; it never links back to
|
|
5
|
+
* its source and never mutates it. Pure functions: the app wires buttons,
|
|
6
|
+
* the demo designer can reuse them, tests need no DOM.
|
|
7
|
+
*/
|
|
8
|
+
import { TOKEN_DEFAULTS, darkTheme } from "@widgentic/core";
|
|
9
|
+
import { cloneDraft } from "./store.js";
|
|
10
|
+
/** Built-in kinds that have a starter template (custom/group do not). */
|
|
11
|
+
export const SEEDABLE_BUILTINS = ["card", "table", "tree"];
|
|
12
|
+
const RESERVED_THEME_NAMES = new Set(["light", "dark"]);
|
|
13
|
+
/**
|
|
14
|
+
* Deterministic distinct identity: `<base>-copy`, then `-copy2`, … The
|
|
15
|
+
* base itself is never returned — a seed keeping its source's identity
|
|
16
|
+
* would OVERWRITE the source on first save (the store keys by kind/name).
|
|
17
|
+
*/
|
|
18
|
+
function distinctIdentity(base, taken) {
|
|
19
|
+
let candidate = `${base}-copy`;
|
|
20
|
+
for (let n = 2; taken.has(candidate); n++)
|
|
21
|
+
candidate = `${base}-copy${n}`;
|
|
22
|
+
return candidate;
|
|
23
|
+
}
|
|
24
|
+
/** Fresh identity for a from-scratch starter (`my-card`, `my-card2`, …). */
|
|
25
|
+
function starterIdentity(base, taken) {
|
|
26
|
+
let candidate = `my-${base}`;
|
|
27
|
+
for (let n = 2; taken.has(candidate); n++)
|
|
28
|
+
candidate = `my-${base}${n}`;
|
|
29
|
+
return candidate;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Starter drafts approximating the renderable built-ins. They wear the
|
|
33
|
+
* built-in `wg-*` classes so the base stylesheet and themes make the seed
|
|
34
|
+
* look like the original from the first preview. Fixed bindings stand in
|
|
35
|
+
* for the built-ins' dynamic behavior (the template DSL binds NAMED
|
|
36
|
+
* properties — a seed is a starting point, not a re-implementation).
|
|
37
|
+
*/
|
|
38
|
+
function builtinStarter(kind) {
|
|
39
|
+
switch (kind) {
|
|
40
|
+
case "card":
|
|
41
|
+
return {
|
|
42
|
+
template: {
|
|
43
|
+
tag: "div",
|
|
44
|
+
attrs: { class: "wg-card" },
|
|
45
|
+
children: [
|
|
46
|
+
{
|
|
47
|
+
when: "title",
|
|
48
|
+
template: {
|
|
49
|
+
tag: "div",
|
|
50
|
+
attrs: { class: "wg-card-title" },
|
|
51
|
+
children: [{ bind: "title" }]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
when: "subtitle",
|
|
56
|
+
template: {
|
|
57
|
+
tag: "div",
|
|
58
|
+
attrs: { class: "wg-card-subtitle" },
|
|
59
|
+
children: [{ bind: "subtitle" }]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
tag: "dl",
|
|
64
|
+
attrs: { class: "wg-card-fields" },
|
|
65
|
+
children: ["price", "rating", "stock"].map((field) => ({
|
|
66
|
+
tag: "div",
|
|
67
|
+
attrs: { class: "wg-card-field" },
|
|
68
|
+
children: [
|
|
69
|
+
{ tag: "dt", attrs: { class: "wg-card-field-key" }, children: [field] },
|
|
70
|
+
{
|
|
71
|
+
tag: "dd",
|
|
72
|
+
attrs: { class: "wg-card-field-value" },
|
|
73
|
+
children: [{ bind: field }]
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}))
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
descriptor: {
|
|
81
|
+
description: "Card seeded from the built-in: title/subtitle chrome over fixed " +
|
|
82
|
+
"field rows. Rename the fields to your data.",
|
|
83
|
+
dataShape: "{ title?, subtitle?, price, rating, stock }",
|
|
84
|
+
dataExample: {
|
|
85
|
+
title: "Essence Mascara",
|
|
86
|
+
subtitle: "beauty",
|
|
87
|
+
price: 9.99,
|
|
88
|
+
rating: 2.56,
|
|
89
|
+
stock: 99
|
|
90
|
+
},
|
|
91
|
+
dataSchema: {
|
|
92
|
+
type: "object",
|
|
93
|
+
required: ["price", "rating", "stock"],
|
|
94
|
+
properties: {
|
|
95
|
+
title: { type: "string" },
|
|
96
|
+
subtitle: { type: "string" },
|
|
97
|
+
price: { type: "number" },
|
|
98
|
+
rating: { type: "number" },
|
|
99
|
+
stock: { type: "integer" }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
case "table":
|
|
105
|
+
return {
|
|
106
|
+
template: {
|
|
107
|
+
tag: "table",
|
|
108
|
+
attrs: { class: "wg-table" },
|
|
109
|
+
children: [
|
|
110
|
+
{
|
|
111
|
+
tag: "thead",
|
|
112
|
+
attrs: { class: "wg-table-head" },
|
|
113
|
+
children: [
|
|
114
|
+
{
|
|
115
|
+
tag: "tr",
|
|
116
|
+
children: ["name", "role"].map((column) => ({
|
|
117
|
+
tag: "th",
|
|
118
|
+
attrs: { class: "wg-table-header" },
|
|
119
|
+
children: [column]
|
|
120
|
+
}))
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
tag: "tbody",
|
|
126
|
+
attrs: { class: "wg-table-body" },
|
|
127
|
+
children: [
|
|
128
|
+
{
|
|
129
|
+
each: "rows",
|
|
130
|
+
template: {
|
|
131
|
+
tag: "tr",
|
|
132
|
+
attrs: { class: "wg-table-row" },
|
|
133
|
+
children: [
|
|
134
|
+
{
|
|
135
|
+
tag: "td",
|
|
136
|
+
attrs: { class: "wg-table-cell" },
|
|
137
|
+
children: [{ bind: "name" }]
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
tag: "td",
|
|
141
|
+
attrs: { class: "wg-table-cell" },
|
|
142
|
+
children: [{ bind: "role" }]
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
descriptor: {
|
|
152
|
+
description: "Table seeded from the built-in: fixed columns over a named rows " +
|
|
153
|
+
"array (templates bind named properties; the built-in's dynamic " +
|
|
154
|
+
"column union stays with the built-in). Rename the columns to " +
|
|
155
|
+
"your data.",
|
|
156
|
+
dataShape: "{ rows: { name, role }[] }",
|
|
157
|
+
dataExample: {
|
|
158
|
+
rows: [
|
|
159
|
+
{ name: "Ada", role: "eng" },
|
|
160
|
+
{ name: "Lin", role: "ops" }
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
dataSchema: {
|
|
164
|
+
type: "object",
|
|
165
|
+
required: ["rows"],
|
|
166
|
+
properties: {
|
|
167
|
+
rows: {
|
|
168
|
+
type: "array",
|
|
169
|
+
items: {
|
|
170
|
+
type: "object",
|
|
171
|
+
required: ["name", "role"],
|
|
172
|
+
properties: {
|
|
173
|
+
name: { type: "string" },
|
|
174
|
+
role: { type: "string" }
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
case "tree":
|
|
183
|
+
return {
|
|
184
|
+
template: {
|
|
185
|
+
tag: "ul",
|
|
186
|
+
attrs: { class: "wg-tree" },
|
|
187
|
+
children: [
|
|
188
|
+
{
|
|
189
|
+
each: "nodes",
|
|
190
|
+
template: {
|
|
191
|
+
tag: "li",
|
|
192
|
+
attrs: { class: "wg-tree-node", "data-expanded": "true" },
|
|
193
|
+
children: [
|
|
194
|
+
{
|
|
195
|
+
tag: "span",
|
|
196
|
+
attrs: { class: "wg-tree-label" },
|
|
197
|
+
children: [{ bind: "label" }]
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
tag: "ul",
|
|
201
|
+
attrs: { class: "wg-tree-children" },
|
|
202
|
+
children: [
|
|
203
|
+
{
|
|
204
|
+
each: "children",
|
|
205
|
+
template: {
|
|
206
|
+
tag: "li",
|
|
207
|
+
attrs: { class: "wg-tree-node" },
|
|
208
|
+
children: [
|
|
209
|
+
{
|
|
210
|
+
tag: "span",
|
|
211
|
+
attrs: { class: "wg-tree-label" },
|
|
212
|
+
children: [{ bind: "label" }]
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
},
|
|
224
|
+
descriptor: {
|
|
225
|
+
description: "Tree seeded from the built-in: two fixed levels of labeled nodes " +
|
|
226
|
+
"(templates cannot recurse; the built-in stays the choice for " +
|
|
227
|
+
"arbitrary depth). Reshape the levels to your data.",
|
|
228
|
+
dataShape: "{ nodes: { label, children: { label }[] }[] }",
|
|
229
|
+
dataExample: {
|
|
230
|
+
nodes: [
|
|
231
|
+
{ label: "root", children: [{ label: "leaf" }, { label: "leaf 2" }] }
|
|
232
|
+
]
|
|
233
|
+
},
|
|
234
|
+
dataSchema: {
|
|
235
|
+
type: "object",
|
|
236
|
+
required: ["nodes"],
|
|
237
|
+
properties: {
|
|
238
|
+
nodes: {
|
|
239
|
+
type: "array",
|
|
240
|
+
items: {
|
|
241
|
+
type: "object",
|
|
242
|
+
required: ["label"],
|
|
243
|
+
properties: {
|
|
244
|
+
label: { type: "string" },
|
|
245
|
+
children: {
|
|
246
|
+
type: "array",
|
|
247
|
+
items: {
|
|
248
|
+
type: "object",
|
|
249
|
+
required: ["label"],
|
|
250
|
+
properties: { label: { type: "string" } }
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Seed a widget draft from a stored definition or a built-in kind name.
|
|
264
|
+
* The result always carries an identity distinct from the source AND from
|
|
265
|
+
* every entry in `taken`.
|
|
266
|
+
*/
|
|
267
|
+
export function seedWidgetDraft(source, taken = []) {
|
|
268
|
+
const takenSet = new Set(taken);
|
|
269
|
+
if (typeof source === "string") {
|
|
270
|
+
return { kind: starterIdentity(source, takenSet), ...builtinStarter(source) };
|
|
271
|
+
}
|
|
272
|
+
const copy = cloneDraft(source);
|
|
273
|
+
takenSet.add(source.kind);
|
|
274
|
+
copy.kind = distinctIdentity(source.kind, takenSet);
|
|
275
|
+
return copy;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Seed a theme entry from a stored entry or a preset name. Preset sources:
|
|
279
|
+
* `light` = the token defaults, `dark` = the dark preset. The result's
|
|
280
|
+
* name is distinct from the source, never reserved, and avoids `taken`.
|
|
281
|
+
*/
|
|
282
|
+
export function seedThemeEntry(source, taken = []) {
|
|
283
|
+
const takenSet = new Set(taken);
|
|
284
|
+
for (const reserved of RESERVED_THEME_NAMES)
|
|
285
|
+
takenSet.add(reserved);
|
|
286
|
+
if (typeof source === "string") {
|
|
287
|
+
const tokens = source === "dark" ? { ...darkTheme } : { ...TOKEN_DEFAULTS };
|
|
288
|
+
return {
|
|
289
|
+
name: starterIdentity(source, takenSet),
|
|
290
|
+
label: source === "dark" ? "My dark theme" : "My light theme",
|
|
291
|
+
tokens
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
const copy = JSON.parse(JSON.stringify(source));
|
|
295
|
+
takenSet.add(source.name);
|
|
296
|
+
copy.name = distinctIdentity(source.name, takenSet);
|
|
297
|
+
return copy;
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=seed.js.map
|
package/dist/seed.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.js","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AA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AAE,QAAQ,CAAC;YACvC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,gBAAgB;YAC7D,MAAM;SACP,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAe,CAAC;IAC9D,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/shell.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ThemeEntry, WidgetTheme } from "@widgentic/core";
|
|
2
|
+
import type { WidgetDefinition } from "./io.js";
|
|
3
|
+
import type { SchemaEntry } from "./schema-designer.js";
|
|
4
|
+
import type { StoredAction } from "@widgentic/core";
|
|
5
|
+
import type { WidgetDraft } from "./store.js";
|
|
6
|
+
import type { DesignerDiagnostics } from "./validate.js";
|
|
7
|
+
export type { WidgetDefinition } from "./io.js";
|
|
8
|
+
export interface DesignerOptions {
|
|
9
|
+
initialWidget?: WidgetDefinition;
|
|
10
|
+
initialTheme?: WidgetTheme;
|
|
11
|
+
/**
|
|
12
|
+
* Named themes offered as preview options. Theme authoring belongs to
|
|
13
|
+
* the standalone theme designer; the widget designer only selects.
|
|
14
|
+
*/
|
|
15
|
+
themes?: ThemeEntry[];
|
|
16
|
+
/**
|
|
17
|
+
* Shared data schemas the draft may reference by name (the Data schema
|
|
18
|
+
* section's "use shared" mode). Schema authoring belongs to the
|
|
19
|
+
* standalone schema designer; the widget designer only selects.
|
|
20
|
+
*/
|
|
21
|
+
schemas?: SchemaEntry[];
|
|
22
|
+
/**
|
|
23
|
+
* Shared actions the draft may bind by name (element `action` bindings
|
|
24
|
+
* and the widget-level `load`). Action authoring belongs to the
|
|
25
|
+
* standalone action designer; the widget designer only binds.
|
|
26
|
+
*/
|
|
27
|
+
actions?: StoredAction[];
|
|
28
|
+
/** Secret names offered when an inline http action needs a header or query secret. */
|
|
29
|
+
secretNames?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Designer chrome appearance. "auto" (default) follows the host's
|
|
32
|
+
* `prefers-color-scheme`; the explicit values pin it. This is the
|
|
33
|
+
* designer's own UI — the widget preview uses the draft's theme.
|
|
34
|
+
*/
|
|
35
|
+
appearance?: "auto" | "light" | "dark";
|
|
36
|
+
/**
|
|
37
|
+
* Mount with editing disabled: panels stay visible but inert, only the
|
|
38
|
+
* preview and its theme selector operate. Toggle later via
|
|
39
|
+
* `setReadOnly`.
|
|
40
|
+
*/
|
|
41
|
+
readOnly?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export type LoadResult = {
|
|
44
|
+
ok: true;
|
|
45
|
+
} | {
|
|
46
|
+
ok: false;
|
|
47
|
+
errors: string[];
|
|
48
|
+
};
|
|
49
|
+
export interface DesignerHandle {
|
|
50
|
+
getDraft(): WidgetDraft;
|
|
51
|
+
loadWidget(definition: unknown): LoadResult;
|
|
52
|
+
loadTheme(theme: unknown): LoadResult;
|
|
53
|
+
/** Disable/enable editing; the preview and theme selector stay live. */
|
|
54
|
+
setReadOnly(readOnly: boolean): void;
|
|
55
|
+
subscribe(listener: (draft: WidgetDraft, diagnostics: DesignerDiagnostics) => void): () => void;
|
|
56
|
+
dispose(): void;
|
|
57
|
+
}
|
|
58
|
+
export declare function createDesigner(container: Element, options?: DesignerOptions): DesignerHandle;
|
|
59
|
+
//# sourceMappingURL=shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../src/shell.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,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I,GACvE,MAAM,IAAI,CAAC;IACd,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,OAAO,EAClB,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAqGhB"}
|
package/dist/shell.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The designer shell: layout, store wiring, and the embedding handle.
|
|
3
|
+
* Panels and the preview are plain modules receiving the store — every
|
|
4
|
+
* designer instance is fully closure-scoped so multiple instances coexist
|
|
5
|
+
* in one document.
|
|
6
|
+
*/
|
|
7
|
+
import { validateTheme } from "@widgentic/core";
|
|
8
|
+
import { h, injectDesignerStyles } from "./dom.js";
|
|
9
|
+
import { applyDefinition, checkDefinition } from "./io.js";
|
|
10
|
+
import { mountPanels } from "./panels.js";
|
|
11
|
+
import { createPreview } from "./preview.js";
|
|
12
|
+
import { cloneDraft, createDraftStore, starterDraft } from "./store.js";
|
|
13
|
+
import { deriveDiagnostics } from "./validate.js";
|
|
14
|
+
export function createDesigner(container, options = {}) {
|
|
15
|
+
injectDesignerStyles(document);
|
|
16
|
+
const base = options.initialWidget
|
|
17
|
+
? cloneDraft({ ...options.initialWidget })
|
|
18
|
+
: starterDraft();
|
|
19
|
+
const initial = options.initialTheme !== undefined ? { ...base, theme: options.initialTheme } : base;
|
|
20
|
+
const store = createDraftStore(initial);
|
|
21
|
+
const listeners = new Set();
|
|
22
|
+
const preview = createPreview({ actions: options.actions ?? [] });
|
|
23
|
+
const leftColumn = h("div", { class: "wgd-panels" });
|
|
24
|
+
const rightSections = h("div", { class: "wgd-preview-pane" });
|
|
25
|
+
const rightColumn = h("div", { class: "wgd-side" }, [preview.pane, rightSections]);
|
|
26
|
+
const root = h("div", { class: "wgd-root" }, [leftColumn, rightColumn]);
|
|
27
|
+
if (options.appearance === "light" || options.appearance === "dark") {
|
|
28
|
+
root.setAttribute("data-wgd-theme", options.appearance);
|
|
29
|
+
}
|
|
30
|
+
container.appendChild(root);
|
|
31
|
+
const actionContext = {
|
|
32
|
+
actions: options.actions ?? [],
|
|
33
|
+
secretNames: options.secretNames ?? [],
|
|
34
|
+
schemas: options.schemas ?? []
|
|
35
|
+
};
|
|
36
|
+
const panels = mountPanels(store, { left: leftColumn, right: rightSections }, options.themes ?? [], options.schemas ?? [], actionContext);
|
|
37
|
+
function refresh(draft) {
|
|
38
|
+
const diagnostics = deriveDiagnostics(draft, {
|
|
39
|
+
schemas: options.schemas ?? [],
|
|
40
|
+
actions: options.actions ?? []
|
|
41
|
+
});
|
|
42
|
+
preview.update(draft, diagnostics);
|
|
43
|
+
for (const listener of [...listeners])
|
|
44
|
+
listener(draft, diagnostics);
|
|
45
|
+
}
|
|
46
|
+
const unsubscribe = store.subscribe(refresh);
|
|
47
|
+
refresh(store.get());
|
|
48
|
+
/**
|
|
49
|
+
* Read-only: every editing surface goes inert (visible, inoperable —
|
|
50
|
+
* section summaries stay clickable so content can still be inspected),
|
|
51
|
+
* while the preview and the theme panel's selector keep working. inert
|
|
52
|
+
* is applied to section BODIES, which are stable elements: panel
|
|
53
|
+
* re-renders replace children inside them, never the bodies themselves.
|
|
54
|
+
*/
|
|
55
|
+
function setReadOnly(readOnly) {
|
|
56
|
+
root.classList.toggle("wgd-readonly", readOnly);
|
|
57
|
+
// Complex selectors inside :not() are not universally supported, so
|
|
58
|
+
// the view-only exclusion is filtered here rather than in the query.
|
|
59
|
+
const bodies = [
|
|
60
|
+
...root.querySelectorAll(".wgd-panels .wgd-section-body, .wgd-edit-only > .wgd-section-body")
|
|
61
|
+
].filter((body) => !body.parentElement?.classList.contains("wgd-view-only"));
|
|
62
|
+
for (const body of bodies) {
|
|
63
|
+
if (readOnly)
|
|
64
|
+
body.setAttribute("inert", "");
|
|
65
|
+
else
|
|
66
|
+
body.removeAttribute("inert");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (options.readOnly === true)
|
|
70
|
+
setReadOnly(true);
|
|
71
|
+
return {
|
|
72
|
+
getDraft: () => cloneDraft(store.get()),
|
|
73
|
+
setReadOnly,
|
|
74
|
+
loadWidget(definition) {
|
|
75
|
+
const errors = checkDefinition(definition);
|
|
76
|
+
if (errors.length > 0)
|
|
77
|
+
return { ok: false, errors };
|
|
78
|
+
applyDefinition(store, definition);
|
|
79
|
+
return { ok: true };
|
|
80
|
+
},
|
|
81
|
+
loadTheme(theme) {
|
|
82
|
+
const validated = validateTheme(theme);
|
|
83
|
+
if (!validated.ok) {
|
|
84
|
+
return { ok: false, errors: [validated.error.message] };
|
|
85
|
+
}
|
|
86
|
+
store.update((draft) => ({ ...draft, theme: validated.theme }));
|
|
87
|
+
return { ok: true };
|
|
88
|
+
},
|
|
89
|
+
subscribe(listener) {
|
|
90
|
+
listeners.add(listener);
|
|
91
|
+
return () => listeners.delete(listener);
|
|
92
|
+
},
|
|
93
|
+
dispose() {
|
|
94
|
+
unsubscribe();
|
|
95
|
+
panels.dispose();
|
|
96
|
+
preview.dispose();
|
|
97
|
+
listeners.clear();
|
|
98
|
+
root.remove();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../src/shell.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,CAAC,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CA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YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO;YACL,WAAW,EAAE,CAAC;YACd,MAAM,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,CAAC,OAAO,EAAE,CAAC;YAClB,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Designer draft store: one micro-store per designer instance — get,
|
|
3
|
+
* immutable update, subscribe, and a bounded undo stack. Deliberately
|
|
4
|
+
* framework-free (the "Arrow JS direction": fine-grained subscriptions,
|
|
5
|
+
* no VDOM) so the designer stays a zero-dependency embeddable.
|
|
6
|
+
*/
|
|
7
|
+
import type { WidgetDescriptorInput } from "@widgentic/core";
|
|
8
|
+
import type { WidgetTemplate } from "@widgentic/core";
|
|
9
|
+
import type { WidgetTheme } from "@widgentic/core";
|
|
10
|
+
import type { ActionBinding } from "@widgentic/core";
|
|
11
|
+
/** The draft being designed — the server's `CustomWidget` shape plus session extras. */
|
|
12
|
+
export interface WidgetDraft {
|
|
13
|
+
kind: string;
|
|
14
|
+
template: WidgetTemplate;
|
|
15
|
+
/**
|
|
16
|
+
* Mirrors the store's shape: `dataSchemaRef` names a shared schema in
|
|
17
|
+
* place of an inline `dataSchema` (never both). Export carries the ref
|
|
18
|
+
* as authored — resolution belongs to the server's composition.
|
|
19
|
+
*/
|
|
20
|
+
descriptor: WidgetDescriptorInput & {
|
|
21
|
+
dataSchemaRef?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Optional http GET action run once when the widget first renders. */
|
|
24
|
+
load?: ActionBinding;
|
|
25
|
+
/** Optional preview data overriding `descriptor.dataExample`. */
|
|
26
|
+
sampleData?: unknown;
|
|
27
|
+
/** Preview theme (also the theme-designer working copy). */
|
|
28
|
+
theme?: WidgetTheme;
|
|
29
|
+
}
|
|
30
|
+
export type DraftListener = (draft: WidgetDraft) => void;
|
|
31
|
+
export interface DraftStore {
|
|
32
|
+
get(): WidgetDraft;
|
|
33
|
+
/** Replace the draft via an updater; records undo history. */
|
|
34
|
+
update(updater: (draft: WidgetDraft) => WidgetDraft): void;
|
|
35
|
+
/** Replace wholesale (imports/loads); clears history. */
|
|
36
|
+
replace(draft: WidgetDraft): void;
|
|
37
|
+
undo(): boolean;
|
|
38
|
+
subscribe(listener: DraftListener): () => void;
|
|
39
|
+
}
|
|
40
|
+
/** Structured-clone with JSON semantics — drafts are serializable by contract. */
|
|
41
|
+
export declare function cloneDraft(draft: WidgetDraft): WidgetDraft;
|
|
42
|
+
export declare function starterDraft(): WidgetDraft;
|
|
43
|
+
export declare function createDraftStore(initial?: WidgetDraft): DraftStore;
|
|
44
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,wFAAwF;AACxF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,cAAc,CAAC;IACzB;;;;OAIG;IACH,UAAU,EAAE,qBAAqB,GAAG;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/D,uEAAuE;IACvE,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,iEAAiE;IACjE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;AAIzD,MAAM,WAAW,UAAU;IACzB,GAAG,IAAI,WAAW,CAAC;IACnB,8DAA8D;IAC9D,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,WAAW,GAAG,IAAI,CAAC;IAC3D,yDAAyD;IACzD,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAClC,IAAI,IAAI,OAAO,CAAC;IAChB,SAAS,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,IAAI,CAAC;CAChD;AAED,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAE1D;AAED,wBAAgB,YAAY,IAAI,WAAW,CA4B1C;AAED,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,UAAU,CAkClE"}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const UNDO_LIMIT = 50;
|
|
2
|
+
/** Structured-clone with JSON semantics — drafts are serializable by contract. */
|
|
3
|
+
export function cloneDraft(draft) {
|
|
4
|
+
return JSON.parse(JSON.stringify(draft));
|
|
5
|
+
}
|
|
6
|
+
export function starterDraft() {
|
|
7
|
+
// Everything the starter binds is DECLARED in its dataSchema — the
|
|
8
|
+
// preferred pattern: schema-declared properties validate, `$meta.*`
|
|
9
|
+
// paths do not, so new drafts start on the validated side.
|
|
10
|
+
return {
|
|
11
|
+
kind: "my-widget",
|
|
12
|
+
template: {
|
|
13
|
+
tag: "div",
|
|
14
|
+
attrs: { class: "wg-template" },
|
|
15
|
+
children: [{ tag: "h2", children: [{ bind: "title" }] }, { bind: "message" }]
|
|
16
|
+
},
|
|
17
|
+
descriptor: {
|
|
18
|
+
description: "Describe what this widget is for.",
|
|
19
|
+
dataShape: "{ title?, message }",
|
|
20
|
+
dataExample: {
|
|
21
|
+
title: "My widget",
|
|
22
|
+
message: "Hello from the widgentic designer"
|
|
23
|
+
},
|
|
24
|
+
dataSchema: {
|
|
25
|
+
type: "object",
|
|
26
|
+
required: ["message"],
|
|
27
|
+
properties: {
|
|
28
|
+
title: { type: "string" },
|
|
29
|
+
message: { type: "string" }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function createDraftStore(initial) {
|
|
36
|
+
let current = cloneDraft(initial ?? starterDraft());
|
|
37
|
+
const history = [];
|
|
38
|
+
const listeners = new Set();
|
|
39
|
+
function notify() {
|
|
40
|
+
for (const listener of [...listeners])
|
|
41
|
+
listener(current);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
get: () => current,
|
|
45
|
+
update(updater) {
|
|
46
|
+
history.push(current);
|
|
47
|
+
if (history.length > UNDO_LIMIT)
|
|
48
|
+
history.shift();
|
|
49
|
+
current = cloneDraft(updater(cloneDraft(current)));
|
|
50
|
+
notify();
|
|
51
|
+
},
|
|
52
|
+
replace(draft) {
|
|
53
|
+
history.length = 0;
|
|
54
|
+
current = cloneDraft(draft);
|
|
55
|
+
notify();
|
|
56
|
+
},
|
|
57
|
+
undo() {
|
|
58
|
+
const previous = history.pop();
|
|
59
|
+
if (previous === undefined)
|
|
60
|
+
return false;
|
|
61
|
+
current = previous;
|
|
62
|
+
notify();
|
|
63
|
+
return true;
|
|
64
|
+
},
|
|
65
|
+
subscribe(listener) {
|
|
66
|
+
listeners.add(listener);
|
|
67
|
+
return () => listeners.delete(listener);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AA+BA,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AC;IAC3D,CAAC;IAED,OAAO;QACL,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO;QAClB,MAAM,CAAC,OAAO;YACZ,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtB,IAAI,OAAO,CAAC,MAAM,GAAG,UAAU;gBAAE,OAAO,CAAC,KAAK,EAAE,CAAC;YACjD,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACnD,MAAM,EAAE,CAAC;QACX,CAAC;QACD,OAAO,CAAC,KAAK;YACX,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;YACnB,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;YAC5B,MAAM,EAAE,CAAC;QACX,CAAC;QACD,IAAI;YACF,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;YAC/B,IAAI,QAAQ,KAAK,SAAS;gBAAE,OAAO,KAAK,CAAC;YACzC,OAAO,GAAG,QAAQ,CAAC;YACnB,MAAM,EAAE,CAAC;YACT,OAAO,IAAI,CAAC;QACd,CAAC;QACD,SAAS,CAAC,QAAQ;YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type WidgetStylesValue = Record<string, Record<string, string>>;
|
|
2
|
+
export interface StylesEditor {
|
|
3
|
+
element: HTMLElement;
|
|
4
|
+
getValue(): WidgetStylesValue | undefined;
|
|
5
|
+
setValue(styles: WidgetStylesValue | undefined): void;
|
|
6
|
+
}
|
|
7
|
+
export declare function createStylesEditor(initial: WidgetStylesValue | undefined, onChange: (styles: WidgetStylesValue | undefined) => void): StylesEditor;
|
|
8
|
+
//# sourceMappingURL=styles-editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles-editor.d.ts","sourceRoot":"","sources":["../src/styles-editor.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvE,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,WAAW,CAAC;IACrB,QAAQ,IAAI,iBAAiB,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI,CAAC;CACvD;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,QAAQ,EAAE,CAAC,MAAM,EAAE,iBAAiB,GAAG,SAAS,KAAK,IAAI,GACxD,YAAY,CAkJd"}
|