@dataverse-to-code/test 0.21.0 → 0.22.1

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/dist/sim.js CHANGED
@@ -1,5 +1,298 @@
1
1
  "use strict";
2
2
  (() => {
3
+ // ../../extension/src/core/appLook/css.ts
4
+ var widths = Array.from({ length: 20 }, (_, i) => (i + 1) * 5).map((w) => `.al-w-${w} { flex: 0 1 ${w}%; max-width: ${w}%; }`).join("\n");
5
+ var APP_LOOK_CSS = `
6
+ .al-app { --al-page: #FAFAFA; --al-card: #FFFFFF; --al-text: #242424; --al-muted: #616161; --al-stroke: #D1D1D1; --al-subtle: #E0E0E0;
7
+ font-family: "Segoe UI", "Segoe UI Web (West European)", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
8
+ font-size: 14px; color: var(--al-text); background: var(--al-page); border: 1px solid var(--al-stroke); border-radius: 4px; overflow: hidden;
9
+ box-sizing: border-box; max-width: 100%; margin: 0 auto; }
10
+ .al-app *, .al-app *::before, .al-app *::after { box-sizing: border-box; }
11
+ .al-size-tablet .al-app { width: 768px; }
12
+ .al-size-phone .al-app { width: 390px; font-size: 14px; }
13
+ .al-appbar { display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 16px; background: var(--al-header, #F0F0F0); color: var(--al-header-text, #242424); }
14
+ .al-waffle { width: 16px; height: 16px; background-image: radial-gradient(currentColor 1.5px, transparent 1.6px); background-size: 6px 6px; }
15
+ .al-appname { font-weight: 600; font-size: 16px; }
16
+ .al-commandbar { display: flex; gap: 4px; margin: 8px; padding: 6px 12px; background: var(--al-card); border-radius: 8px; box-shadow: 0 0 2px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.14); overflow: hidden; white-space: nowrap; }
17
+ .al-cmd { padding: 4px 8px; border-radius: 4px; color: var(--al-text); }
18
+ .al-back { color: var(--al-muted); border-right: 1px solid var(--al-subtle); border-radius: 0; padding-right: 12px; }
19
+ .al-record { margin: 0 8px 8px; background: var(--al-card); padding: 16px 20px 0; border-radius: 8px; box-shadow: 0 0 2px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.14); }
20
+ .al-recordhead { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
21
+ .al-entityicon { flex: 0 0 40px; height: 40px; border-radius: 50%; background: var(--al-subtle); }
22
+ .al-titleblock { flex: 1 1 0; min-width: 0; }
23
+ .al-unsaved { font-size: 14px; font-weight: 400; color: var(--al-muted); }
24
+ .al-title { font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }
25
+ .al-subtitle { color: var(--al-text); font-size: 14px; margin-top: 4px; }
26
+ .al-headerfields { display: flex; gap: 0; align-items: stretch; flex-wrap: wrap; }
27
+ .al-headerfield { padding: 0 16px; border-left: 1px solid var(--al-subtle); min-width: 96px; }
28
+ .al-headervalue { font-weight: 600; }
29
+ .al-headerlabel { color: var(--al-muted); font-size: 12px; }
30
+ .al-headerflyout { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 8px 0; padding-top: 8px; }
31
+ .al-headerflyout[hidden] { display: none; }
32
+ .al-headermore { background: none; border: none; color: var(--al-muted); cursor: pointer; font: inherit; padding: 0 8px; }
33
+ .al-tabs { display: flex; gap: 8px; margin-top: 8px; overflow-x: auto; }
34
+ .al-tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 10px 8px; font: inherit; color: var(--al-text); cursor: pointer; white-space: nowrap; }
35
+ .al-tab.selected { border-bottom-color: var(--al-accent, #0F6CBD); font-weight: 600; }
36
+ .al-body { padding: 0 8px 8px; }
37
+ .al-tabpanel { display: none; }
38
+ .al-tabpanel.selected { display: block; }
39
+ .al-tabcols { display: flex; gap: 16px; align-items: flex-start; }
40
+ .al-tabcol { min-width: 0; flex-shrink: 1; }
41
+ ${widths}
42
+ .al-section { background: var(--al-card); border-radius: 4px; box-shadow: 0 0 2px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.14); padding: 12px; margin-bottom: 8px; }
43
+ .al-sectiontitle { overflow-wrap: anywhere; font-size: 14px; font-weight: 600; margin: 0 0 8px; }
44
+ .al-row { display: grid; gap: 4px 24px; margin-bottom: 4px; }
45
+ .al-cols-1 { grid-template-columns: minmax(0, 1fr); }
46
+ .al-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
47
+ .al-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
48
+ .al-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
49
+ .al-span-2 { grid-column: span 2; } .al-span-3 { grid-column: span 3; } .al-span-4 { grid-column: span 4; }
50
+ .al-field { display: grid; grid-template-columns: minmax(0, 185px) minmax(0, 1fr); align-items: center; gap: 0; min-height: 48px; }
51
+ .al-field.al-block, .al-field.al-nolabel { grid-template-columns: minmax(0, 1fr); }
52
+ .al-nolabel .al-label { display: none; }
53
+ .al-label { color: var(--al-text); overflow-wrap: anywhere; padding-right: 8px; }
54
+ .al-req { color: #C50F1F; margin-left: 2px; }
55
+ .al-input { display: flex; align-items: center; justify-content: space-between; min-height: 32px; padding: 0 10px; background: #F5F5F5; border: none; border-radius: 4px; color: var(--al-muted); }
56
+ .al-textarea { min-height: 64px; align-items: flex-start; padding-top: 6px; }
57
+ .al-prefix { color: var(--al-text); margin-right: 6px; }
58
+ .al-icon { color: var(--al-muted); margin-left: 8px; }
59
+ .al-readonly .al-input { background: transparent; }
60
+ .al-toggle { display: inline-block; vertical-align: middle; width: 40px; height: 20px; border-radius: 10px; border: 1px solid #616161; position: relative; }
61
+ .al-knob { position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: #616161; }
62
+ .al-toggletext { margin-left: 8px; }
63
+ .al-image { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; background: var(--al-page); border-radius: 4px; }
64
+ .al-grid, .al-timeline, .al-quickview { border: 1px solid var(--al-subtle); border-radius: 4px; padding: 8px 12px; }
65
+ .al-gridbar, .al-timelinebar { display: flex; justify-content: space-between; margin-bottom: 8px; }
66
+ .al-gridtitle { overflow-wrap: anywhere; font-weight: 600; }
67
+ .al-gridcmd { color: var(--al-accent, #0F6CBD); }
68
+ .al-gridhead { display: grid; grid-template-columns: 1fr 1fr; padding: 6px 0; border-bottom: 1px solid var(--al-subtle); color: var(--al-muted); font-size: 12px; }
69
+ .al-gridempty, .al-timelineempty { color: var(--al-muted); text-align: center; padding: 16px 0; }
70
+ .al-qvrow { display: grid; grid-template-columns: 35% 1fr; gap: 8px; margin: 8px 0; }
71
+ .al-qvrow span { height: 10px; border-radius: 3px; background: var(--al-subtle); }
72
+ .al-placeholder { overflow-wrap: anywhere; color: var(--al-muted); text-align: center; padding: 16px 0; border: 1px dashed var(--al-stroke); border-radius: 4px; }
73
+ .al-footer { display: flex; gap: 24px; flex-wrap: wrap; padding: 8px 20px; background: var(--al-card); border-top: 1px solid var(--al-subtle); }
74
+ .al-libraries { color: var(--al-muted); font-size: 12px; padding: 8px 20px; }
75
+ .al-problem { color: var(--al-muted); padding: 24px 0; text-align: center; }
76
+ .al-edit .al-spacer { min-height: 32px; border: 1px dashed var(--al-stroke); border-radius: 4px; color: var(--al-muted); display: flex; align-items: center; justify-content: center; }
77
+ .al-edit .al-drop { height: 6px; margin: 1px 0; border-radius: 3px; }
78
+ .al-edit .al-hdrop { width: 6px; align-self: stretch; border-radius: 3px; }
79
+ .al-edit .al-hdrop.al-hempty { width: auto; padding: 8px 12px; border: 1px dashed var(--al-stroke); color: var(--al-muted); font-size: 12px; }
80
+ .al-edit .al-flyout { opacity: .6; border-left-style: dashed; }
81
+ .al-edit .al-sdrop { border: 1px dashed var(--al-stroke); color: var(--al-muted); padding: 8px; text-align: center; border-radius: 4px; font-size: 12px; }
82
+ /* Hidden elements stay visible while designing, dimmed and dashed, so you can see what is hidden. */
83
+ .al-hidden { opacity: .5; outline: 1px dashed var(--al-stroke); }
84
+ .al-size-tablet .al-tabcols,
85
+ .al-size-phone .al-tabcols { flex-direction: column; align-items: stretch; }
86
+ .al-size-tablet .al-tabcol, .al-size-phone .al-tabcol { max-width: 100%; flex-basis: auto; }
87
+ .al-size-phone .al-row { grid-template-columns: 1fr; }
88
+ .al-size-phone .al-span-2, .al-size-phone .al-span-3, .al-size-phone .al-span-4 { grid-column: auto; }
89
+ .al-size-phone .al-record { padding-left: 12px; padding-right: 12px; }
90
+ .al-size-phone .al-headerfields { flex-basis: 100%; }
91
+ .al-strip { display: flex; align-items: center; gap: 12px; margin: 8px 0; flex-wrap: wrap; }
92
+ .al-sizes button { font: inherit; padding: 2px 10px; border: 1px solid #D1D1D1; background: transparent; color: inherit; cursor: pointer; }
93
+ .al-sizes button[aria-pressed="true"] { background: #0F6CBD; border-color: #0F6CBD; color: #FFFFFF; }
94
+ .al-themesource { opacity: .75; font-size: 12px; }
95
+ `.trim();
96
+
97
+ // ../../extension/src/core/appLook/model.ts
98
+ var BY_CONTROL = {
99
+ text: "text",
100
+ url: "text",
101
+ email: "text",
102
+ phone: "text",
103
+ ticker: "text",
104
+ field: "text",
105
+ multiline: "multiline",
106
+ wholeNumber: "number",
107
+ decimal: "number",
108
+ float: "number",
109
+ number: "number",
110
+ money: "currency",
111
+ date: "date",
112
+ choice: "choice",
113
+ choices: "choices",
114
+ yesNo: "yesNo",
115
+ yesNoList: "yesNo",
116
+ lookup: "lookup",
117
+ subgrid: "subgrid",
118
+ quickView: "quickView",
119
+ timeline: "timeline",
120
+ webResource: "webResource",
121
+ iframe: "iframe",
122
+ map: "map"
123
+ };
124
+ var BY_TYPE = {
125
+ text: "text",
126
+ multiline: "multiline",
127
+ wholeNumber: "number",
128
+ decimal: "number",
129
+ float: "number",
130
+ bigInteger: "number",
131
+ currency: "currency",
132
+ date: "date",
133
+ dateTime: "date",
134
+ choice: "choice",
135
+ choices: "choices",
136
+ yesNo: "yesNo",
137
+ lookup: "lookup",
138
+ customer: "lookup",
139
+ owner: "lookup",
140
+ file: "file",
141
+ image: "image"
142
+ };
143
+ function lookKind(cellKind, columnType) {
144
+ if (cellKind) return BY_CONTROL[cellKind] ?? "other";
145
+ return columnType && BY_TYPE[columnType] || "other";
146
+ }
147
+ var round5 = (n) => Math.min(100, Math.max(5, Math.round(n / 5) * 5));
148
+ function fromFormDoc(doc, o) {
149
+ const columns = new Map(o.columns.map((c) => [c.name, c]));
150
+ const field2 = (c, sectionColumns, slotPrefix = "", where) => {
151
+ const col = c.field ? columns.get(c.field) : void 0;
152
+ const kind = c.spacer ? "spacer" : c.field && !col && !c.kind ? "other" : lookKind(c.kind, col?.type);
153
+ return {
154
+ label: c.label ?? col?.label ?? c.field ?? c.control ?? "",
155
+ ...c.field ? { column: c.field, slot: `${slotPrefix}${c.field}` } : {},
156
+ kind,
157
+ visible: c.visible !== false,
158
+ readOnly: c.readOnly === true,
159
+ required: col?.requiredLevel === "required",
160
+ showLabel: c.showLabel !== false,
161
+ span: Math.min(Math.max(1, c.colspan ?? 1), sectionColumns),
162
+ ...where ? { where } : {}
163
+ };
164
+ };
165
+ const area = (rows, prefix) => (rows ?? []).flat().map((c) => field2(c, 1, prefix));
166
+ return {
167
+ title: `New ${o.tableLabel || o.table}`,
168
+ subtitle: `${o.tableLabel || o.table} \xB7 ${o.formName}`,
169
+ header: (doc.header?.rows ?? []).flatMap((r, row) => r.map((c, cell) => field2(c, 1, "header_", { area: "header", tab: -1, section: -1, row, cell }))),
170
+ footer: area(doc.footer?.rows, "footer_"),
171
+ libraries: (doc.scripts?.libraries ?? []).map((l) => typeof l === "string" ? l : l.name),
172
+ tabs: doc.tabs.map((t, i) => {
173
+ const share = 100 / Math.max(1, t.columns.length);
174
+ return {
175
+ name: t.name ?? `tab_${i + 1}`,
176
+ label: t.label ?? t.name ?? "",
177
+ visible: t.visible !== false,
178
+ columns: (t.columns.length > 0 ? t.columns : ["100%"]).map((w, n) => ({
179
+ width: round5(parseFloat(w) || share),
180
+ sections: t.sections.map((s, j) => ({ s, j })).filter(({ s }) => (s.column ?? 1) === n + 1).map(({ s, j }) => {
181
+ const width = Math.max(1, s.columns ?? 1);
182
+ return {
183
+ name: s.name ?? `section_${j + 1}`,
184
+ label: s.label ?? "",
185
+ showLabel: s.showLabel !== false && (s.label ?? "") !== "",
186
+ visible: s.visible !== false,
187
+ columns: width,
188
+ index: j,
189
+ rows: s.rows.map((r, row) => r.map((c, cell) => field2(c, width, "", { tab: i, section: j, row, cell })))
190
+ };
191
+ })
192
+ }))
193
+ };
194
+ })
195
+ };
196
+ }
197
+
198
+ // ../../extension/src/core/appLook/render.ts
199
+ var SIZES = [{ size: "desktop", label: "Desktop" }, { size: "tablet", label: "Tablet" }, { size: "phone", label: "Phone" }];
200
+ var esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
201
+ var HEADER_FIELDS = 4;
202
+ function control(kind, label) {
203
+ switch (kind) {
204
+ case "multiline":
205
+ return '<span class="al-input al-textarea"></span>';
206
+ case "number":
207
+ return '<span class="al-input al-number">---</span>';
208
+ case "currency":
209
+ return '<span class="al-input al-currency"><span class="al-prefix">$</span>---</span>';
210
+ case "date":
211
+ return '<span class="al-input al-date">---<span class="al-icon" aria-hidden="true">\u{1F4C5}</span></span>';
212
+ case "choice":
213
+ return '<span class="al-input al-select">---<span class="al-icon" aria-hidden="true">\u2304</span></span>';
214
+ case "choices":
215
+ return '<span class="al-input al-select al-multi">---<span class="al-icon" aria-hidden="true">\u2304</span></span>';
216
+ case "yesNo":
217
+ return '<span class="al-toggle"><span class="al-knob"></span></span><span class="al-toggletext">No</span>';
218
+ case "lookup":
219
+ return '<span class="al-input al-lookup">---<span class="al-icon" aria-hidden="true">\u{1F50D}</span></span>';
220
+ case "file":
221
+ return '<span class="al-input al-file">Choose file</span>';
222
+ case "image":
223
+ return '<span class="al-image" aria-hidden="true">\u{1F5BC}</span>';
224
+ case "subgrid":
225
+ return `<div class="al-grid"><div class="al-gridbar"><span class="al-gridtitle">${esc(label)}</span><span class="al-gridcmd">+ New</span></div><div class="al-gridhead"><span>Name \u2191</span><span>Created On</span></div><div class="al-gridempty">No data available.</div></div>`;
226
+ case "timeline":
227
+ return '<div class="al-timeline"><div class="al-timelinebar"><span class="al-gridtitle">Timeline</span><span class="al-gridcmd">+</span></div><span class="al-input">Search timeline</span><div class="al-timelineempty">Get started by capturing data.</div></div>';
228
+ case "quickView":
229
+ return `<div class="al-quickview"><div class="al-gridtitle">${esc(label)}</div><div class="al-qvrow"><span></span><span></span></div><div class="al-qvrow"><span></span><span></span></div></div>`;
230
+ case "webResource":
231
+ return `<div class="al-placeholder">Web resource: ${esc(label)}</div>`;
232
+ case "iframe":
233
+ return `<div class="al-placeholder">Web page: ${esc(label)}</div>`;
234
+ case "map":
235
+ return '<div class="al-placeholder">Map</div>';
236
+ case "other":
237
+ return `<div class="al-placeholder">${esc(label)}</div>`;
238
+ default:
239
+ return '<span class="al-input">---</span>';
240
+ }
241
+ }
242
+ var BLOCKS = /* @__PURE__ */ new Set(["subgrid", "timeline", "quickView", "webResource", "iframe", "map"]);
243
+ function field(x, live, edit = false) {
244
+ const where = edit && x.where ? ` data-al-where="${x.where.tab},${x.where.section},${x.where.row},${x.where.cell}"` : "";
245
+ if (x.kind === "spacer") return `<div class="al-field al-spacer al-span-${x.span}"${where}>${edit ? "(spacer)" : ""}</div>`;
246
+ const classes = [
247
+ "al-field",
248
+ `al-kind-${x.kind}`,
249
+ ...BLOCKS.has(x.kind) ? ["al-block"] : [],
250
+ ...x.span > 1 ? [`al-span-${x.span}`] : [],
251
+ ...x.visible ? [] : ["al-hidden"],
252
+ ...x.readOnly ? ["al-readonly"] : [],
253
+ ...x.showLabel ? [] : ["al-nolabel"]
254
+ ];
255
+ const attrs = `${x.column ? ` data-al-column="${esc(x.column)}"` : ""}${x.slot && !BLOCKS.has(x.kind) ? ` data-al-slot="${esc(x.slot)}"` : ""}${BLOCKS.has(x.kind) ? ` data-al-label="${esc(x.label)}"` : ""}${where}`;
256
+ const label = BLOCKS.has(x.kind) ? "" : `<label class="al-label">${esc(x.label)}${x.required ? '<span class="al-req" title="Required">*</span>' : ""}</label>`;
257
+ const body = live && x.slot && !BLOCKS.has(x.kind) ? "" : control(x.kind, x.label);
258
+ return `<div class="${classes.join(" ")}"${attrs}>${label}<div class="al-control">${body}</div></div>`;
259
+ }
260
+ function section(s, tab, live, edit) {
261
+ const title = s.showLabel && s.label ? `<h2 class="al-sectiontitle">${esc(s.label)}</h2>` : "";
262
+ const marks = edit && s.index !== void 0;
263
+ const drop = (row) => marks ? `<div class="al-drop" data-al-drop="${tab},${s.index},${row},0"></div>` : "";
264
+ const rows = s.rows.map((r, i) => `${drop(i)}<div class="al-row al-cols-${Math.min(s.columns, 4)}">${r.map((x) => field(x, live, edit)).join("")}</div>`).join("") + drop(s.rows.length);
265
+ return `<section class="al-section${s.visible ? "" : " al-hidden"}" data-al-section="${esc(s.name)}"${marks ? ` data-al-index="${s.index}"` : ""}>${title}${rows}</section>`;
266
+ }
267
+ function tabPanel(t, i, selected, live, edit) {
268
+ const sdrop = (n) => edit ? `<div class="al-sdrop" data-al-tab="${i}" data-al-column="${n + 1}">+ drop a section here</div>` : "";
269
+ const cols = t.columns.map((c, n) => `<div class="al-tabcol al-w-${c.width}">${c.sections.map((s) => section(s, i, live, edit)).join("")}${sdrop(n)}</div>`).join("");
270
+ return `<div class="al-tabpanel${selected ? " selected" : ""}" data-al-tab="${i}"><div class="al-tabcols">${cols}</div></div>`;
271
+ }
272
+ function headerField(x, live, edit = false, flyout = false) {
273
+ const value = live && x.slot ? "" : "---";
274
+ const where = edit && x.where ? ` data-al-where="header,${x.where.row},${x.where.cell}"` : "";
275
+ const title = flyout ? ' title="Shows in the header&#39;s flyout: the app shows four fields in the header"' : "";
276
+ return `<div class="al-headerfield${x.visible ? "" : " al-hidden"}${flyout ? " al-flyout" : ""}"${x.slot && !edit ? ` data-al-slot="${esc(x.slot)}"` : ""}${where}${title}><div class="al-headervalue al-control">${value}</div><div class="al-headerlabel">${esc(x.label)}</div></div>`;
277
+ }
278
+ function renderForm(look, o = {}) {
279
+ const live = o.live === true;
280
+ const edit = o.edit === true;
281
+ const selected = Math.min(Math.max(0, o.selectedTab ?? 0), Math.max(0, look.tabs.length - 1));
282
+ const shown = look.header.slice(0, HEADER_FIELDS);
283
+ const more = look.header.length - shown.length;
284
+ const flyout = live && more > 0 ? `<div class="al-headerflyout" hidden>${look.header.slice(HEADER_FIELDS).map((x) => headerField(x, live)).join("")}</div>` : "";
285
+ const hdrop = (row, cell) => `<div class="al-hdrop" data-al-drop="header,${row},${cell}"></div>`;
286
+ const last = look.header.at(-1)?.where;
287
+ const editHeader = look.header.length === 0 ? '<div class="al-headerfields al-edit-header"><div class="al-hdrop al-hempty" data-al-drop="header,0,0">+ drop header fields here</div></div>' : `<div class="al-headerfields al-edit-header">${look.header.map((x, i) => `${x.where ? hdrop(x.where.row, x.where.cell) : ""}${headerField(x, live, true, i >= HEADER_FIELDS)}`).join("")}${last ? hdrop(last.row, last.cell + 1) : ""}</div>`;
288
+ const header = edit ? editHeader : `<div class="al-headerfields">${shown.map((x) => headerField(x, live)).join("")}${more > 0 ? `<button type="button" class="al-headermore" title="${more} more header field${more === 1 ? "" : "s"}">\u2304</button>` : ""}${flyout}</div>`;
289
+ const tabs = look.tabs.map((t, i) => `<button type="button" class="al-tab${i === selected ? " selected" : ""}${t.visible ? "" : " al-hidden"}" data-al-tab="${i}" data-al-name="${esc(t.name)}"${t.visible ? "" : ' title="Hidden tab"'}>${esc(t.label || t.name)}</button>`).join("");
290
+ const body = look.problem ? `<p class="al-problem">${esc(look.problem)}</p>` : look.tabs.length === 0 ? `<p class="al-problem">${edit ? "No tabs yet: add one from Layout." : "This form has no tabs."}</p>` : look.tabs.map((t, i) => tabPanel(t, i, i === selected, live, edit)).join("");
291
+ const footer = look.footer.length > 0 ? `<div class="al-footer">${look.footer.map((x) => field(x, live)).join("")}</div>` : "";
292
+ const libraries = look.libraries.length > 0 ? `<div class="al-libraries">Scripts: ${look.libraries.map(esc).join(", ")}</div>` : "";
293
+ return `<div class="al-app${edit ? " al-edit" : ""}"><header class="al-appbar"><span class="al-waffle" aria-hidden="true"></span><span class="al-appname">${esc(o.appName ?? "Power Apps")}</span></header><div class="al-commandbar"><span class="al-cmd al-back">\u2190</span><span class="al-cmd">Save</span><span class="al-cmd">Save &amp; Close</span><span class="al-cmd">+ New</span></div><div class="al-record"><div class="al-recordhead"><span class="al-entityicon" aria-hidden="true"></span><div class="al-titleblock"><div class="al-title">${esc(look.title)}<span class="al-unsaved"> - Unsaved</span></div><div class="al-subtitle">${esc(look.subtitle)}<span class="al-icon" aria-hidden="true">\u2304</span></div></div>${header}</div><nav class="al-tabs" role="tablist">${tabs}</nav></div><div class="al-body">${body}</div>${footer}${libraries}</div>`;
294
+ }
295
+
3
296
  // ../../node_modules/yaml/browser/dist/nodes/identity.js
4
297
  var ALIAS = /* @__PURE__ */ Symbol.for("yaml.alias");
5
298
  var DOC = /* @__PURE__ */ Symbol.for("yaml.document");
@@ -3198,8 +3491,8 @@ ${cn.comment}` : item.comment;
3198
3491
  visit2.REMOVE = REMOVE2;
3199
3492
  visit2.itemAtPath = (cst, path) => {
3200
3493
  let item = cst;
3201
- for (const [field, index] of path) {
3202
- const tok = item?.[field];
3494
+ for (const [field2, index] of path) {
3495
+ const tok = item?.[field2];
3203
3496
  if (tok && "items" in tok) {
3204
3497
  item = tok.items[index];
3205
3498
  } else
@@ -3209,8 +3502,8 @@ ${cn.comment}` : item.comment;
3209
3502
  };
3210
3503
  visit2.parentCollection = (cst, path) => {
3211
3504
  const parent = visit2.itemAtPath(cst, path.slice(0, -1));
3212
- const field = path[path.length - 1][0];
3213
- const coll = parent?.[field];
3505
+ const field2 = path[path.length - 1][0];
3506
+ const coll = parent?.[field2];
3214
3507
  if (coll && "items" in coll)
3215
3508
  return coll;
3216
3509
  throw new Error("Parent collection not found");
@@ -3219,11 +3512,11 @@ ${cn.comment}` : item.comment;
3219
3512
  let ctrl = visitor(item, path);
3220
3513
  if (typeof ctrl === "symbol")
3221
3514
  return ctrl;
3222
- for (const field of ["key", "value"]) {
3223
- const token = item[field];
3515
+ for (const field2 of ["key", "value"]) {
3516
+ const token = item[field2];
3224
3517
  if (token && "items" in token) {
3225
3518
  for (let i = 0; i < token.items.length; ++i) {
3226
- const ci = _visit(Object.freeze(path.concat([[field, i]])), token.items[i], visitor);
3519
+ const ci = _visit(Object.freeze(path.concat([[field2, i]])), token.items[i], visitor);
3227
3520
  if (typeof ci === "number")
3228
3521
  i = ci - 1;
3229
3522
  else if (ci === BREAK2)
@@ -3233,7 +3526,7 @@ ${cn.comment}` : item.comment;
3233
3526
  i -= 1;
3234
3527
  }
3235
3528
  }
3236
- if (typeof ctrl === "function" && field === "key")
3529
+ if (typeof ctrl === "function" && field2 === "key")
3237
3530
  ctrl = ctrl(item, path);
3238
3531
  }
3239
3532
  }
@@ -3406,15 +3699,15 @@ ${cn.comment}` : item.comment;
3406
3699
  saved;
3407
3700
  snapshot() {
3408
3701
  const s = /* @__PURE__ */ new Map();
3409
- for (const [field, value] of this.sim.state.values) {
3410
- const c = this.sim.state.controls.get(field);
3411
- s.set(field, { value: display(this.sim.state.columns.get(field), value), visible: c?.visible ?? true, disabled: c?.disabled ?? false, required: this.sim.state.required.get(field) ?? "none" });
3702
+ for (const [field2, value] of this.sim.state.values) {
3703
+ const c = this.sim.state.controls.get(field2);
3704
+ s.set(field2, { value: display(this.sim.state.columns.get(field2), value), visible: c?.visible ?? true, disabled: c?.disabled ?? false, required: this.sim.state.required.get(field2) ?? "none" });
3412
3705
  }
3413
3706
  return s;
3414
3707
  }
3415
3708
  /** A value as a test writes it: a choice by its label when only one option has it, a lookup by id, a date as text. */
3416
- written(field, value) {
3417
- const col = this.sim.state.columns.get(field);
3709
+ written(field2, value) {
3710
+ const col = this.sim.state.columns.get(field2);
3418
3711
  if (col.type === "choice" && typeof value === "number") {
3419
3712
  const option = col.options.find((o) => o.value === value);
3420
3713
  return option && col.options.filter((o) => o.label === option.label).length === 1 ? option.label : value;
@@ -3423,11 +3716,11 @@ ${cn.comment}` : item.comment;
3423
3716
  if (value instanceof Date) return display(col, value);
3424
3717
  return value;
3425
3718
  }
3426
- async set(field, value) {
3427
- await this.sim.userSet(field, value);
3719
+ async set(field2, value) {
3720
+ await this.sim.userSet(field2, value);
3428
3721
  const last = this.steps.at(-1);
3429
- if (last && "set" in last) last.set[field] = this.written(field, value);
3430
- else this.steps.push({ set: { [field]: this.written(field, value) } });
3722
+ if (last && "set" in last) last.set[field2] = this.written(field2, value);
3723
+ else this.steps.push({ set: { [field2]: this.written(field2, value) } });
3431
3724
  }
3432
3725
  async save() {
3433
3726
  this.saved = await this.sim.save();
@@ -3438,14 +3731,14 @@ ${cn.comment}` : item.comment;
3438
3731
  const end = this.snapshot();
3439
3732
  const setFields = new Set(this.steps.flatMap((s) => "set" in s ? Object.keys(s.set) : []));
3440
3733
  const expect = {};
3441
- for (const [field, after] of end) {
3442
- const before = this.start.get(field);
3734
+ for (const [field2, after] of end) {
3735
+ const before = this.start.get(field2);
3443
3736
  const changed = {};
3444
- if (after.value !== before.value && !setFields.has(field)) changed.value = this.written(field, this.sim.state.values.get(field) ?? null);
3737
+ if (after.value !== before.value && !setFields.has(field2)) changed.value = this.written(field2, this.sim.state.values.get(field2) ?? null);
3445
3738
  if (after.visible !== before.visible) changed.visible = after.visible;
3446
3739
  if (after.disabled !== before.disabled) changed.disabled = after.disabled;
3447
3740
  if (after.required !== before.required) changed.required = after.required === "required";
3448
- if (Object.keys(changed).length > 0) expect[field] = changed;
3741
+ if (Object.keys(changed).length > 0) expect[field2] = changed;
3449
3742
  }
3450
3743
  if (this.saved !== void 0) expect.saved = this.saved;
3451
3744
  const acted = new Set(this.sim.log.entries.slice(this.startedAt).filter((e) => e.kind === "rule").map((e) => /^rule "([^"]+)" →/.exec(e.message)?.[1]).filter((n) => !!n));
@@ -3605,17 +3898,17 @@ ${cn.comment}` : item.comment;
3605
3898
  depth = 0;
3606
3899
  chain = [];
3607
3900
  stopped = false;
3608
- watches(field) {
3609
- return this.simulated.some((r) => this.watched.get(r).has(field));
3901
+ watches(field2) {
3902
+ return this.simulated.some((r) => this.watched.get(r).has(field2));
3610
3903
  }
3611
3904
  onLoad() {
3612
3905
  for (const r of this.rules.filter((x) => x.notSimulated)) this.log.add("notSimulated", `rule "${r.name}": ${r.notSimulated}`);
3613
3906
  this.stopped = false;
3614
3907
  for (const r of this.simulated) this.run(r);
3615
3908
  }
3616
- onChange(field) {
3909
+ onChange(field2) {
3617
3910
  if (this.depth === 0) this.stopped = false;
3618
- for (const r of this.simulated.filter((x) => this.watched.get(x).has(field))) this.run(r);
3911
+ for (const r of this.simulated.filter((x) => this.watched.get(x).has(field2))) this.run(r);
3619
3912
  }
3620
3913
  /** A rule's error is showing on the form (it blocks save). */
3621
3914
  hasErrors() {
@@ -3706,23 +3999,23 @@ ${cn.comment}` : item.comment;
3706
3999
  }
3707
4000
  }
3708
4001
  apply(rule, a, onSave) {
3709
- const control = this.state.controls.get(a.column);
4002
+ const control2 = this.state.controls.get(a.column);
3710
4003
  const say = (what) => this.log.add("rule", `rule "${rule.name}" \u2192 ${what}`);
3711
4004
  switch (a.kind) {
3712
4005
  case "show":
3713
4006
  case "hide":
3714
- if (control) control.visible = a.kind === "show";
4007
+ if (control2) control2.visible = a.kind === "show";
3715
4008
  return say(`${a.kind} ${a.column}`);
3716
4009
  case "lock":
3717
4010
  case "unlock":
3718
- if (control) control.disabled = a.kind === "lock";
4011
+ if (control2) control2.disabled = a.kind === "lock";
3719
4012
  return say(`${a.kind} ${a.column}`);
3720
4013
  case "require":
3721
4014
  case "unrequire":
3722
4015
  this.state.required.set(a.column, a.kind === "require" ? "required" : "none");
3723
4016
  return say(`${a.kind} ${a.column}`);
3724
4017
  case "error":
3725
- control?.notifications.set(errorId(rule.name), a.message ?? "");
4018
+ control2?.notifications.set(errorId(rule.name), a.message ?? "");
3726
4019
  return say(`error on ${a.column}: ${a.message ?? ""}`);
3727
4020
  case "clear":
3728
4021
  case "set":
@@ -3758,7 +4051,7 @@ ${cn.comment}` : item.comment;
3758
4051
  if (!SUPPORTED.has(key2)) throw new NotSimulated(key2);
3759
4052
  if (key2 === "$select") q.select = value.split(",").map((s) => s.trim()).filter(Boolean);
3760
4053
  else if (key2 === "$top") q.top = Number(value);
3761
- else if (key2 === "$orderby") q.orderBy = value.split(",").map((s) => s.trim().split(/\s+/)).map(([field, dir]) => ({ field, desc: dir === "desc" }));
4054
+ else if (key2 === "$orderby") q.orderBy = value.split(",").map((s) => s.trim().split(/\s+/)).map(([field2, dir]) => ({ field: field2, desc: dir === "desc" }));
3762
4055
  else q.filter = parseFilter(value);
3763
4056
  }
3764
4057
  return q;
@@ -3822,21 +4115,21 @@ ${cn.comment}` : item.comment;
3822
4115
  if (!["contains", "startswith", "endswith"].includes(tok.v)) throw new NotSimulated(`the $filter function ${tok.v}`);
3823
4116
  const fn = take().v;
3824
4117
  take("(");
3825
- const field2 = take("id").v;
4118
+ const field3 = take("id").v;
3826
4119
  take(",");
3827
4120
  const text = String(value()).toLowerCase();
3828
4121
  take(")");
3829
4122
  return (r) => {
3830
- const v2 = String(r[field2] ?? "").toLowerCase();
4123
+ const v2 = String(r[field3] ?? "").toLowerCase();
3831
4124
  return fn === "contains" ? v2.includes(text) : fn === "startswith" ? v2.startsWith(text) : v2.endsWith(text);
3832
4125
  };
3833
4126
  }
3834
- const field = take("id").v;
4127
+ const field2 = take("id").v;
3835
4128
  const op = take("op").v;
3836
4129
  if (!["eq", "ne", "gt", "ge", "lt", "le"].includes(op)) fail();
3837
4130
  const v = value();
3838
4131
  return (r) => {
3839
- const x = r[field] ?? null;
4132
+ const x = r[field2] ?? null;
3840
4133
  if (op === "eq") return v === null ? x === null : x !== null && cmp(x, v) === 0;
3841
4134
  if (op === "ne") return v === null ? x !== null : x === null || cmp(x, v) !== 0;
3842
4135
  if (x === null || v === null) return false;
@@ -3966,7 +4259,7 @@ ${cn.comment}` : item.comment;
3966
4259
  forEach: (f) => items().forEach((n, i) => f(wrap(n), i)),
3967
4260
  getLength: () => items().length
3968
4261
  });
3969
- const control = (name) => {
4262
+ const control2 = (name) => {
3970
4263
  const c = state.controls.get(name);
3971
4264
  if (!c) return null;
3972
4265
  return g({
@@ -4010,7 +4303,7 @@ ${cn.comment}` : item.comment;
4010
4303
  }
4011
4304
  }, `formContext.getControl("${name}")`);
4012
4305
  };
4013
- const controlsOf = (field) => () => [...state.controls.entries()].filter(([, c]) => c.field === field).map(([n]) => n);
4306
+ const controlsOf = (field2) => () => [...state.controls.entries()].filter(([, c]) => c.field === field2).map(([n]) => n);
4014
4307
  const attribute = (name) => {
4015
4308
  const col = state.columns.get(name);
4016
4309
  if (!col || !state.values.has(name)) return null;
@@ -4053,7 +4346,7 @@ ${cn.comment}` : item.comment;
4053
4346
  state.onChange.set(name, (state.onChange.get(name) ?? []).filter((f) => f !== fn));
4054
4347
  },
4055
4348
  fireOnChange: () => hooks.fireOnChange(name),
4056
- controls: collection(controlsOf(name), control)
4349
+ controls: collection(controlsOf(name), control2)
4057
4350
  }, `formContext.getAttribute("${name}")`);
4058
4351
  };
4059
4352
  const tab = (name) => {
@@ -4100,7 +4393,7 @@ ${cn.comment}` : item.comment;
4100
4393
  };
4101
4394
  const formContext = g({
4102
4395
  getAttribute: (name) => name === void 0 ? [...state.values.keys()].map(attribute) : attribute(name),
4103
- getControl: (name) => name === void 0 ? [...state.controls.keys()].map(control) : control(name),
4396
+ getControl: (name) => name === void 0 ? [...state.controls.keys()].map(control2) : control2(name),
4104
4397
  data: g({
4105
4398
  entity: g({
4106
4399
  getId: () => state.recordId ? `{${state.recordId.toUpperCase()}}` : "",
@@ -4132,7 +4425,7 @@ ${cn.comment}` : item.comment;
4132
4425
  return true;
4133
4426
  },
4134
4427
  tabs: collection(() => [...state.tabs.keys()], tab),
4135
- controls: collection(() => [...state.controls.keys()], control),
4428
+ controls: collection(() => [...state.controls.keys()], control2),
4136
4429
  formSelector: {
4137
4430
  getCurrentItem: () => ({
4138
4431
  getId: () => typeof pkg.form.head.id === "string" ? pkg.form.head.id.replace(/[{}]/g, "").toLowerCase() : null,
@@ -4242,18 +4535,18 @@ ${cn.comment}` : item.comment;
4242
4535
  this.store = new Store(pkg.tables, pkg.records, host.newId, lookups);
4243
4536
  this.state = new FormState(pkg);
4244
4537
  const rules = new RuleEngine(pkg.rules, this.state, this.log, {
4245
- setValue: (field, value) => {
4246
- const col = this.state.columns.get(field);
4247
- const before = this.state.values.get(field) ?? null;
4538
+ setValue: (field2, value) => {
4539
+ const col = this.state.columns.get(field2);
4540
+ const before = this.state.values.get(field2) ?? null;
4248
4541
  const same = isEmpty(before) && isEmpty(value) || col !== void 0 && compare(col, before, value) === 0;
4249
- this.state.values.set(field, value);
4250
- this.state.dirty.add(field);
4251
- if (!same) rules.onChange(field);
4542
+ this.state.values.set(field2, value);
4543
+ this.state.dirty.add(field2);
4544
+ if (!same) rules.onChange(field2);
4252
4545
  }
4253
4546
  });
4254
4547
  this.rules = rules;
4255
4548
  const made = createXrm(this.state, this.store, this.log, pkg, {
4256
- fireOnChange: (field) => this.change(field),
4549
+ fireOnChange: (field2) => this.change(field2),
4257
4550
  save: () => this.save(),
4258
4551
  alert: () => {
4259
4552
  },
@@ -4314,14 +4607,14 @@ ${cn.comment}` : item.comment;
4314
4607
  this.invoke(event, h2.function, () => fn(...h2.passContext ? [this.context(eventSource, onSave)] : [], ...parseParameters(h2.parameters)));
4315
4608
  }
4316
4609
  /** A change the form reacts to: the field's OnChange handlers (scripts:, then addOnChange ones), then the rules that watch it. */
4317
- change(field) {
4318
- const source = this.attribute(field);
4319
- for (const h2 of this.pkg.form.scripts?.onChange?.[field] ?? []) this.call(`OnChange ${field}`, h2, void 0, source);
4320
- for (const fn of this.state.onChange.get(field) ?? []) {
4321
- this.log.add("handler", `OnChange ${field}: (added by a script)`);
4322
- this.invoke(`OnChange ${field}`, "a handler added by a script", () => fn(this.context(source)));
4323
- }
4324
- this.rules.onChange(field);
4610
+ change(field2) {
4611
+ const source = this.attribute(field2);
4612
+ for (const h2 of this.pkg.form.scripts?.onChange?.[field2] ?? []) this.call(`OnChange ${field2}`, h2, void 0, source);
4613
+ for (const fn of this.state.onChange.get(field2) ?? []) {
4614
+ this.log.add("handler", `OnChange ${field2}: (added by a script)`);
4615
+ this.invoke(`OnChange ${field2}`, "a handler added by a script", () => fn(this.context(source)));
4616
+ }
4617
+ this.rules.onChange(field2);
4325
4618
  this.state.changed();
4326
4619
  }
4327
4620
  async open(recordId) {
@@ -4335,8 +4628,8 @@ ${cn.comment}` : item.comment;
4335
4628
  if (id) {
4336
4629
  const record = this.store.get(this.pkg.table, id);
4337
4630
  if (!record) throw new Error(`No ${this.pkg.table} record ${id} in the offline data.`);
4338
- for (const field of this.state.values.keys()) {
4339
- this.state.values.set(field, fromRecord(this.state.columns.get(field), record.values, (t, i) => this.store.nameOf(t, i)));
4631
+ for (const field2 of this.state.values.keys()) {
4632
+ this.state.values.set(field2, fromRecord(this.state.columns.get(field2), record.values, (t, i) => this.store.nameOf(t, i)));
4340
4633
  }
4341
4634
  this.state.formType = 2;
4342
4635
  this.state.recordId = record.id;
@@ -4348,13 +4641,13 @@ ${cn.comment}` : item.comment;
4348
4641
  this.state.changed();
4349
4642
  }
4350
4643
  /** As a person changes a field: the value, its OnChange handlers, then rules; resolves once handlers' promises settle. */
4351
- async userSet(field, value) {
4352
- const col = this.state.columns.get(field);
4353
- if (!col || !this.state.values.has(field)) throw new Error(`${field} isn't on this form.`);
4354
- this.state.values.set(field, value);
4355
- this.state.dirty.add(field);
4356
- this.log.add("value", `${field} = ${display(col, value) || "(empty)"}`);
4357
- this.change(field);
4644
+ async userSet(field2, value) {
4645
+ const col = this.state.columns.get(field2);
4646
+ if (!col || !this.state.values.has(field2)) throw new Error(`${field2} isn't on this form.`);
4647
+ this.state.values.set(field2, value);
4648
+ this.state.dirty.add(field2);
4649
+ this.log.add("value", `${field2} = ${display(col, value) || "(empty)"}`);
4650
+ this.change(field2);
4358
4651
  await this.settle();
4359
4652
  }
4360
4653
  /** A person expanding or collapsing a tab (TabStateChange handlers are kept raw and not run offline). */
@@ -4384,9 +4677,9 @@ ${cn.comment}` : item.comment;
4384
4677
  }
4385
4678
  this.state.formNotifications.delete("required");
4386
4679
  const limits = [];
4387
- for (const [field, v] of this.state.values) {
4388
- const col = this.state.columns.get(field);
4389
- const label = this.state.controls.get(field)?.label ?? col.label;
4680
+ for (const [field2, v] of this.state.values) {
4681
+ const col = this.state.columns.get(field2);
4682
+ const label = this.state.controls.get(field2)?.label ?? col.label;
4390
4683
  if (typeof v === "string" && col.maxLength !== void 0 && v.length > col.maxLength) limits.push(`${label} is longer than ${col.maxLength} characters.`);
4391
4684
  if (typeof v === "number" && col.minValue !== void 0 && v < col.minValue) limits.push(`${label} must be at least ${col.minValue}.`);
4392
4685
  if (typeof v === "number" && col.maxValue !== void 0 && v > col.maxValue) limits.push(`${label} must be at most ${col.maxValue}.`);
@@ -4417,7 +4710,7 @@ ${cn.comment}` : item.comment;
4417
4710
  }
4418
4711
  this.state.formNotifications.delete("rules");
4419
4712
  const values = {};
4420
- for (const [field, v] of this.state.values) Object.assign(values, toRecord(this.state.columns.get(field), v));
4713
+ for (const [field2, v] of this.state.values) Object.assign(values, toRecord(this.state.columns.get(field2), v));
4421
4714
  if (this.state.recordId) this.store.update(this.pkg.table, this.state.recordId, values);
4422
4715
  else {
4423
4716
  this.state.recordId = this.store.create(this.pkg.table, values);
@@ -4472,6 +4765,7 @@ ${cn.comment}` : item.comment;
4472
4765
  return fromUser(col, el.value);
4473
4766
  }
4474
4767
  var testsText = "";
4768
+ var size = "desktop";
4475
4769
  var listening = false;
4476
4770
  function listenForTestStatus() {
4477
4771
  if (listening || typeof window === "undefined") return;
@@ -4494,7 +4788,8 @@ ${cn.comment}` : item.comment;
4494
4788
  const formRef = `${pkg.table}/${pkg.formType}/${pkg.formName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")}`;
4495
4789
  const page = { sim, recorder: new Recorder(sim, formRef), ready: Promise.resolve() };
4496
4790
  let currentTab = [...sim.state.tabs.keys()][0];
4497
- const formPane = h("div", { class: "sim-form" });
4791
+ let headerOpen = false;
4792
+ const formPane = h("div", { class: `sim-form al-size-${size}` });
4498
4793
  const dataPane = h("div", { class: "sim-data" });
4499
4794
  const logPane = h("ol", { class: "sim-log" });
4500
4795
  const button = (action, label) => h("button", { "data-sim-action": action, type: "button" }, label);
@@ -4506,6 +4801,8 @@ ${cn.comment}` : item.comment;
4506
4801
  button("reset", "Reset"),
4507
4802
  button("copyTest", "Copy as test"),
4508
4803
  button("loadSeed", "Load from seed"),
4804
+ h("span", { class: "al-sizes", role: "group", "aria-label": "Screen size" }, ...SIZES.map((s) => h("button", { type: "button", "data-al-size": s.size, "aria-pressed": String(s.size === size) }, s.label))),
4805
+ h("span", { class: "al-themesource" }, typeof document !== "undefined" ? document.body.dataset.themeSource ?? "" : ""),
4509
4806
  h("span", { class: "sim-tests", "data-tests-status": "" }, testsText),
4510
4807
  h("span", { class: "sim-note" }, "Offline: nothing is sent to Dataverse.")
4511
4808
  );
@@ -4519,60 +4816,85 @@ ${cn.comment}` : item.comment;
4519
4816
  logPane.replaceChildren(...sim.log.entries.map((e) => h("li", { "data-sim-log": e.kind, class: `log-${e.kind}` }, h("span", { class: "kind" }, e.kind), ` ${e.message}`)));
4520
4817
  logPane.scrollTop = logPane.scrollHeight;
4521
4818
  };
4522
- const cell = (field, controlName, kind, label) => {
4523
- if (!field) return h("div", { class: "sim-cell sim-placeholder" });
4524
- const col = sim.state.columns.get(field);
4525
- const control = sim.state.controls.get(controlName);
4526
- if (kind && ["subgrid", "quickView", "timeline", "webResource", "iframe", "map", "other"].includes(kind)) {
4527
- return h("div", { class: "sim-cell sim-placeholder" }, `${label ?? field} (${kind}; shown as a placeholder offline)`);
4528
- }
4529
- if (!col || !control) return h("div", { class: "sim-cell sim-placeholder" }, `${field} (a column the project doesn't describe; shown as a placeholder)`);
4530
- const input = inputFor(col, sim.state.values.get(field) ?? null, sim);
4531
- input.disabled = control.disabled;
4532
- input.addEventListener("change", () => void page.recorder.set(field, readInput(col, input, sim)));
4533
- const required = (sim.state.required.get(field) ?? "none") === "required";
4534
- return h(
4535
- "div",
4536
- {
4537
- class: `sim-cell${control.visible ? "" : " sim-hidden"}`,
4538
- "data-sim-control": controlName,
4539
- "data-sim-visible": String(control.visible),
4540
- "data-sim-disabled": String(control.disabled),
4541
- "data-sim-required": String(required)
4542
- },
4543
- h("label", { for: input.id }, control.label, required ? h("span", { class: "sim-req" }, " *") : ""),
4544
- input,
4545
- ...[...control.notifications.values()].map((n) => h("div", { class: "sim-notification", "data-sim-notification": controlName }, n))
4546
- );
4819
+ const look = () => {
4820
+ const columns = pkg.columns.map((c) => ({ name: c.name, label: c.label, type: c.type, requiredLevel: sim.state.required.get(c.name) ?? c.requiredLevel }));
4821
+ const base = fromFormDoc(pkg.form, { table: pkg.table, ...pkg.tableLabel ? { tableLabel: pkg.tableLabel } : {}, formName: pkg.formName, columns });
4822
+ for (const t of base.tabs) {
4823
+ const state = sim.state.tabs.get(t.name);
4824
+ if (!state) continue;
4825
+ t.label = state.label || state.name;
4826
+ t.visible = state.visible;
4827
+ for (const c of t.columns) {
4828
+ for (const s of c.sections) {
4829
+ const ss = state.sections.get(s.name);
4830
+ if (ss) {
4831
+ s.label = ss.label || ss.name;
4832
+ s.visible = ss.visible;
4833
+ }
4834
+ }
4835
+ }
4836
+ }
4837
+ return base;
4838
+ };
4839
+ const mount = (el) => {
4840
+ const controlName = el.getAttribute("data-al-slot");
4841
+ const field2 = el.getAttribute("data-al-column") ?? controlName.replace(/^(header|footer)_/, "");
4842
+ const col = sim.state.columns.get(field2);
4843
+ const control2 = sim.state.controls.get(controlName);
4844
+ const slot = el.querySelector(".al-control");
4845
+ if (!col || !control2) {
4846
+ slot.append(h("div", { class: "al-placeholder sim-placeholder" }, `${field2} (a column the project doesn't describe; shown as a placeholder)`));
4847
+ return;
4848
+ }
4849
+ const input = inputFor(col, sim.state.values.get(field2) ?? null, sim);
4850
+ input.disabled = control2.disabled;
4851
+ input.addEventListener("change", () => void page.recorder.set(field2, readInput(col, input, sim)));
4852
+ const required = (sim.state.required.get(field2) ?? "none") === "required";
4853
+ el.setAttribute("data-sim-control", controlName);
4854
+ el.setAttribute("data-sim-visible", String(control2.visible));
4855
+ el.setAttribute("data-sim-disabled", String(control2.disabled));
4856
+ el.setAttribute("data-sim-required", String(required));
4857
+ el.classList.toggle("sim-hidden", !control2.visible);
4858
+ el.classList.toggle("al-hidden", !control2.visible);
4859
+ const label = el.querySelector(".al-label, .al-headerlabel");
4860
+ if (label) {
4861
+ label.replaceChildren(control2.label, ...required ? [h("span", { class: "al-req sim-req", title: "Required" }, "*")] : []);
4862
+ if (label instanceof HTMLLabelElement) label.htmlFor = input.id;
4863
+ }
4864
+ slot.replaceChildren(input, ...[...control2.notifications.values()].map((n) => h("div", { class: "sim-notification", "data-sim-notification": controlName }, n)));
4547
4865
  };
4548
4866
  const draw = () => {
4549
4867
  const notes = [...sim.state.formNotifications.entries()].map(([id, n]) => h("div", { class: `sim-form-note level-${n.level.toLowerCase()}`, "data-sim-form-notification": id }, n.message));
4550
- const strip = h("div", { class: "sim-tabs" }, ...[...sim.state.tabs.values()].map((t) => {
4551
- const b = h("button", { type: "button", "data-sim-tab": t.name, class: `${t.name === currentTab ? "on" : ""}${t.visible ? "" : " sim-hidden"}` }, t.label || t.name);
4868
+ const tabNames = [...sim.state.tabs.keys()];
4869
+ const holder = h("div");
4870
+ holder.innerHTML = renderForm(look(), { selectedTab: Math.max(0, tabNames.indexOf(currentTab)), live: true });
4871
+ for (const b of Array.from(holder.querySelectorAll(".al-tab"))) {
4872
+ const name = b.getAttribute("data-al-name");
4873
+ b.setAttribute("data-sim-tab", name);
4874
+ b.classList.toggle("sim-hidden", b.classList.contains("al-hidden"));
4552
4875
  b.addEventListener("click", () => {
4553
- currentTab = t.name;
4876
+ currentTab = name;
4554
4877
  draw();
4555
4878
  });
4556
- return b;
4557
- }));
4558
- const tabIndex = [...sim.state.tabs.keys()].indexOf(currentTab);
4559
- const tab = pkg.form.tabs[tabIndex];
4560
- const columns = tab ? tab.columns.map((_, i) => h("div", { class: "sim-column" }, ...tab.sections.map((s, j) => ({ s, j })).filter(({ s }) => (s.column ?? 1) === i + 1).map(({ s, j }) => {
4561
- const state = sim.state.tabs.get(currentTab).sections.get(s.name ?? `section_${j + 1}`);
4562
- return h(
4563
- "fieldset",
4564
- { class: `sim-section${state.visible ? "" : " sim-hidden"}`, "data-sim-section": state.name },
4565
- h("legend", {}, state.label || state.name),
4566
- ...s.rows.map((row) => h("div", { class: `sim-row cols-${Math.min(row.length, 4)}` }, ...row.map((c) => cell(c.field, c.field ?? "", c.kind, c.label))))
4567
- );
4568
- }))) : [];
4569
- const header = (pkg.form.header?.rows ?? []).flat().map((c) => cell(c.field, `header_${c.field}`, c.kind, c.label));
4570
- formPane.replaceChildren(
4571
- ...notes,
4572
- ...header.length > 0 ? [h("div", { class: "sim-header" }, ...header)] : [],
4573
- strip,
4574
- h("div", { class: `sim-columns cols-${Math.min(tab?.columns.length ?? 1, 4)}` }, ...columns)
4575
- );
4879
+ }
4880
+ for (const s of Array.from(holder.querySelectorAll(".al-section"))) {
4881
+ s.setAttribute("data-sim-section", s.getAttribute("data-al-section"));
4882
+ s.classList.toggle("sim-hidden", s.classList.contains("al-hidden"));
4883
+ }
4884
+ for (const el of Array.from(holder.querySelectorAll("[data-al-slot]"))) mount(el);
4885
+ const flyout = holder.querySelector(".al-headerflyout");
4886
+ if (flyout) {
4887
+ flyout.hidden = !headerOpen;
4888
+ holder.querySelector(".al-headermore").addEventListener("click", () => {
4889
+ headerOpen = !headerOpen;
4890
+ flyout.hidden = !headerOpen;
4891
+ });
4892
+ }
4893
+ for (const el of Array.from(holder.querySelectorAll(".al-block"))) {
4894
+ const kind = [...el.classList].find((c) => c.startsWith("al-kind-")).slice("al-kind-".length);
4895
+ el.append(h("div", { class: "sim-placeholder" }, `${el.getAttribute("data-al-label") || el.getAttribute("data-al-column") || kind} (${kind}; shown as a placeholder offline)`));
4896
+ }
4897
+ formPane.replaceChildren(...notes, ...Array.from(holder.childNodes));
4576
4898
  dataPane.replaceChildren(...Object.keys(pkg.tables).map((t) => {
4577
4899
  const add = h("form", { "data-sim-add": t, class: "sim-add" }, h("input", { type: "text", placeholder: `New ${t}: ${pkg.tables[t].primaryName}` }), h("button", { type: "submit" }, "Add"));
4578
4900
  add.addEventListener("submit", (e) => {
@@ -4619,6 +4941,13 @@ ${cn.comment}` : item.comment;
4619
4941
  sim.state.listeners.push(draw);
4620
4942
  sim.log.onAdd(drawLog);
4621
4943
  toolbar.addEventListener("click", (e) => {
4944
+ const picked = e.target.getAttribute("data-al-size");
4945
+ if (picked) {
4946
+ size = picked;
4947
+ formPane.className = `sim-form al-size-${size}`;
4948
+ for (const b of Array.from(toolbar.querySelectorAll("[data-al-size]"))) b.setAttribute("aria-pressed", String(b === e.target));
4949
+ return;
4950
+ }
4622
4951
  const action = e.target.getAttribute("data-sim-action");
4623
4952
  if (action === "save") void page.recorder.save();
4624
4953
  else if (action === "new") restart();
@@ -4639,16 +4968,16 @@ ${cn.comment}` : item.comment;
4639
4968
  let saved;
4640
4969
  return {
4641
4970
  ready: () => current().ready,
4642
- async set(field, wire) {
4971
+ async set(field2, wire) {
4643
4972
  const { sim } = current();
4644
- const col = sim.state.columns.get(field);
4645
- if (!col || !sim.state.values.has(field)) throw new Error(`${field} isn't on the form.`);
4973
+ const col = sim.state.columns.get(field2);
4974
+ if (!col || !sim.state.values.has(field2)) throw new Error(`${field2} isn't on the form.`);
4646
4975
  let value = fromWire(wire);
4647
4976
  if (isLookup(col) && Array.isArray(value) && value.length > 0) {
4648
4977
  const v = value[0];
4649
4978
  value = [{ ...v, name: sim.store.nameOf(v.entityType, v.id) }];
4650
4979
  }
4651
- await sim.userSet(field, value);
4980
+ await sim.userSet(field2, value);
4652
4981
  },
4653
4982
  async save() {
4654
4983
  saved = await current().sim.save();
@@ -4660,16 +4989,16 @@ ${cn.comment}` : item.comment;
4660
4989
  const fields = {};
4661
4990
  for (const [name, value] of sim.state.values) {
4662
4991
  const col = sim.state.columns.get(name);
4663
- const control = sim.state.controls.get(name) ?? sim.state.controls.get(`header_${name}`) ?? sim.state.controls.get(`footer_${name}`);
4664
- if (!control) continue;
4992
+ const control2 = sim.state.controls.get(name) ?? sim.state.controls.get(`header_${name}`) ?? sim.state.controls.get(`footer_${name}`);
4993
+ if (!control2) continue;
4665
4994
  fields[name] = {
4666
4995
  value: toWire(value),
4667
4996
  text: display(col, value),
4668
4997
  required: sim.state.required.get(name) === "required",
4669
- visible: control.visible,
4670
- disabled: control.disabled,
4671
- label: control.label,
4672
- notifications: [...control.notifications.values()],
4998
+ visible: control2.visible,
4999
+ disabled: control2.disabled,
5000
+ label: control2.label,
5001
+ notifications: [...control2.notifications.values()],
4673
5002
  options: col.options.map((o) => o.label)
4674
5003
  };
4675
5004
  }