@dtkt/protoform 0.0.0-stage → 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.
Files changed (56) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +221 -2
  3. package/dist/base.d.ts +19 -0
  4. package/dist/comments.d.ts +9 -0
  5. package/dist/components/enum.d.ts +24 -0
  6. package/dist/components/field.d.ts +16 -0
  7. package/dist/components/frame.d.ts +6 -0
  8. package/dist/components/group.d.ts +25 -0
  9. package/dist/components/hooks.d.ts +18 -0
  10. package/dist/components/index.d.ts +13 -0
  11. package/dist/components/index.js +14 -0
  12. package/dist/components/list.d.ts +7 -0
  13. package/dist/components/map.d.ts +7 -0
  14. package/dist/components/message.d.ts +17 -0
  15. package/dist/components/oneof.d.ts +8 -0
  16. package/dist/components/protoform.d.ts +20 -0
  17. package/dist/components/scalar.d.ts +34 -0
  18. package/dist/components/select.d.ts +1 -0
  19. package/dist/components/submit.d.ts +8 -0
  20. package/dist/components/wkt.d.ts +20 -0
  21. package/dist/context-DSrebuNf.js +1024 -0
  22. package/dist/element.d.ts +23 -0
  23. package/dist/enum.d.ts +17 -0
  24. package/dist/env.d.ts +28 -0
  25. package/dist/favicon.ico +0 -0
  26. package/dist/field.d.ts +17 -0
  27. package/dist/gen/dtkt/protoform/v1beta1/protoform_pb.d.ts +463 -0
  28. package/dist/gen/dtkt/protoform/v1beta1/protoform_pb.js +6 -0
  29. package/dist/gen/google/api/field_behavior_pb.d.ts +133 -0
  30. package/dist/gen/google/api/field_behavior_pb.js +5 -0
  31. package/dist/icons.svg +24 -0
  32. package/dist/kit/bare.d.ts +3 -0
  33. package/dist/kit/context.d.ts +56 -0
  34. package/dist/kit/index.d.ts +4 -0
  35. package/dist/kit/index.js +1 -0
  36. package/dist/kit/tailwind/index.d.ts +7 -0
  37. package/dist/kit/tailwind/index.js +327 -0
  38. package/dist/kit/types.d.ts +126 -0
  39. package/dist/list.d.ts +29 -0
  40. package/dist/main.d.ts +13 -0
  41. package/dist/main.js +3 -0
  42. package/dist/map.d.ts +36 -0
  43. package/dist/message.d.ts +61 -0
  44. package/dist/oneof.d.ts +27 -0
  45. package/dist/path.d.ts +8 -0
  46. package/dist/protoform-DmMJ7LSw.js +835 -0
  47. package/dist/providers/env.d.ts +4 -0
  48. package/dist/providers/index.d.ts +2 -0
  49. package/dist/providers/index.js +11 -0
  50. package/dist/providers/ui.d.ts +13 -0
  51. package/dist/scalar.d.ts +30 -0
  52. package/dist/store.d.ts +29 -0
  53. package/dist/styles.css +2 -0
  54. package/dist/ui-DGND0oTu.js +32 -0
  55. package/dist/wellknown.d.ts +10 -0
  56. package/package.json +141 -4
@@ -0,0 +1,835 @@
1
+ import { E as e, M as t, T as n, W as r, a as i, d as a, f as o, g as s, h as c, i as l, k as u, l as d, m as f, o as p, p as m, s as h, v as g, w as _, x as v, y as ee } from "./context-DSrebuNf.js";
2
+ import { t as te } from "./ui-DGND0oTu.js";
3
+ import { createElement as ne, useEffect as y, useId as b, useState as x, useSyncExternalStore as S } from "react";
4
+ import { ScalarType as C, create as w, equals as re, fromJson as ie, toJson as ae } from "@bufbuild/protobuf";
5
+ import { anyPack as T, anyUnpack as oe, timestampNow as se } from "@bufbuild/protobuf/wkt";
6
+ import { Fragment as E, jsx as D, jsxs as O } from "react/jsx-runtime";
7
+ // lib/components/enum.tsx
8
+ var ce = 4;
9
+ function k({ desc: e, value: t, onValue: n, compact: r, ...a }) {
10
+ let o = i(), s = e.values.map((t) => ({
11
+ value: String(t.number),
12
+ label: v(e, t.number)
13
+ }));
14
+ t in e.value || s.push({
15
+ value: String(t),
16
+ label: String(t)
17
+ });
18
+ let c = {
19
+ ...a,
20
+ value: String(t),
21
+ options: s,
22
+ onChange: (e) => n(Number(e))
23
+ };
24
+ return !r && s.length <= ce ? /* @__PURE__ */ D(o.RadioGroup, { ...c }) : /* @__PURE__ */ D(o.Select, { ...c });
25
+ }
26
+ function le({ field: e, mode: t, id: n, describedBy: r, invalid: i }) {
27
+ return /* @__PURE__ */ D(k, {
28
+ desc: e.desc.enum,
29
+ value: e.get(),
30
+ onValue: (t) => e.set(t),
31
+ id: n,
32
+ name: e.desc.localName,
33
+ describedBy: r,
34
+ invalid: i,
35
+ readOnly: t === "view",
36
+ required: e.elem.required
37
+ });
38
+ }
39
+ // lib/wellknown.ts
40
+ var A = "google.protobuf.", ue = /* @__PURE__ */ new Set([
41
+ `${A}Timestamp`,
42
+ `${A}Duration`,
43
+ `${A}FieldMask`
44
+ ]), j = /* @__PURE__ */ new Set([
45
+ `${A}Struct`,
46
+ `${A}Value`,
47
+ `${A}ListValue`
48
+ ]), de = new Set([
49
+ "DoubleValue",
50
+ "FloatValue",
51
+ "Int64Value",
52
+ "UInt64Value",
53
+ "Int32Value",
54
+ "UInt32Value",
55
+ "BoolValue",
56
+ "StringValue",
57
+ "BytesValue"
58
+ ].map((e) => A + e)), fe = `${A}Any`;
59
+ function M(e) {
60
+ return ue.has(e);
61
+ }
62
+ function N(e) {
63
+ return j.has(e);
64
+ }
65
+ function P(e) {
66
+ return ue.has(e) || j.has(e) || de.has(e);
67
+ }
68
+ // lib/components/hooks.ts
69
+ function pe(e) {
70
+ return S(e.store.subscribe, e.store.snapshot), e;
71
+ }
72
+ function F(e, t) {
73
+ let [n, r] = x(), i = e;
74
+ if (n) {
75
+ let r = t(n.text);
76
+ (r === void 0 ? n.base === e : r === e) && (i = n.text);
77
+ }
78
+ return {
79
+ text: i,
80
+ setText: (t) => r({
81
+ text: t,
82
+ base: e
83
+ }),
84
+ reset: () => r(void 0)
85
+ };
86
+ }
87
+ // lib/components/scalar.tsx
88
+ function I({ scalar: e, value: t, onValue: n, store: r, errorPath: a, multiline: o, ...l }) {
89
+ let u = i(), d = (t) => s(e) && (t === 0 || t === 0n) ? "" : f(e, t), p = F(d(t), (t) => {
90
+ let n = g(e, t);
91
+ return n.ok ? d(n.value) : void 0;
92
+ });
93
+ if (y(() => () => r.setLocalError(a, void 0), [r, a]), e === C.BOOL) return /* @__PURE__ */ D(u.Checkbox, {
94
+ variant: "switch",
95
+ id: l.id,
96
+ name: l.name,
97
+ checked: t,
98
+ readOnly: l.readOnly,
99
+ invalid: l.invalid,
100
+ describedBy: l.describedBy,
101
+ "aria-label": l["aria-label"],
102
+ onChange: (e) => r.setLocalError(a, n(e) ?? void 0)
103
+ });
104
+ let m = (t) => {
105
+ p.setText(t);
106
+ let i = g(e, t);
107
+ i.ok ? r.setLocalError(a, n(i.value) ?? void 0) : r.setLocalError(a, i.error);
108
+ }, h = () => {
109
+ r.localError(a) === void 0 && p.reset();
110
+ }, _ = l.invalid || r.localError(a) !== void 0, v = s(e) || e === C.BYTES;
111
+ return o && (e === C.STRING || e === C.BYTES) ? /* @__PURE__ */ D(u.TextArea, {
112
+ ...l,
113
+ invalid: _,
114
+ value: p.text,
115
+ mono: v,
116
+ onChange: m,
117
+ onBlur: h
118
+ }) : /* @__PURE__ */ D(u.TextInput, {
119
+ ...l,
120
+ invalid: _,
121
+ value: p.text,
122
+ mono: v,
123
+ placeholder: l.placeholder ?? (s(e) ? "0" : void 0),
124
+ inputMode: c(e) ? "numeric" : s(e) ? "decimal" : "text",
125
+ onChange: m,
126
+ onBlur: h
127
+ });
128
+ }
129
+ function L({ field: e, mode: t, id: n, describedBy: r, invalid: i, multiline: a }) {
130
+ return /* @__PURE__ */ D(I, {
131
+ scalar: e.desc.scalar,
132
+ value: e.get(),
133
+ onValue: (t) => e.set(t),
134
+ store: e.parent.store,
135
+ errorPath: e.path,
136
+ id: n,
137
+ name: e.desc.localName,
138
+ describedBy: r,
139
+ invalid: i,
140
+ readOnly: t === "view",
141
+ required: e.elem.required,
142
+ multiline: a
143
+ });
144
+ }
145
+ // lib/components/wkt.tsx
146
+ var R = "google.protobuf.";
147
+ function z(e) {
148
+ let t = e.message.value.desc.typeName;
149
+ return M(t) ? /* @__PURE__ */ D(B, {
150
+ ...e,
151
+ format: "text"
152
+ }) : N(t) ? /* @__PURE__ */ D(B, {
153
+ ...e,
154
+ format: "json"
155
+ }) : /* @__PURE__ */ D(he, { ...e });
156
+ }
157
+ var me = {
158
+ [`${R}Timestamp`]: "2024-01-31T12:00:00Z",
159
+ [`${R}Duration`]: "1.5s",
160
+ [`${R}FieldMask`]: "foo,bar.baz"
161
+ };
162
+ function B({ message: e, mode: t, id: r, describedBy: a, invalid: o, format: s, "aria-label": c }) {
163
+ let l = i(), u = p(), d = e.value.desc, f = e.store, m = (e) => e instanceof n ? !e.isSet() : re(d, e.get(), w(d)), h = (e) => {
164
+ let t = ae(d, e);
165
+ return typeof t == "string" && s === "text" ? t : JSON.stringify(t, null, 2);
166
+ }, g = (e) => ie(d, s === "text" ? e : JSON.parse(e)), _ = F(m(e) ? "" : h(e.get()), (e) => {
167
+ if (e.trim() === "") return "";
168
+ try {
169
+ return h(g(e));
170
+ } catch {
171
+ return;
172
+ }
173
+ });
174
+ y(() => () => f.setLocalError(e.path, void 0), [f, e.path]);
175
+ let v = {
176
+ id: r,
177
+ describedBy: a,
178
+ "aria-label": c,
179
+ invalid: o || f.localError(e.path) !== void 0,
180
+ readOnly: t === "view",
181
+ value: _.text,
182
+ mono: !0,
183
+ placeholder: me[d.typeName],
184
+ onChange: (t) => {
185
+ if (_.setText(t), t.trim() === "") e.clear(), f.setLocalError(e.path, void 0);
186
+ else try {
187
+ e.set(g(t)), e instanceof n && e.ensure(), f.setLocalError(e.path, void 0);
188
+ } catch (t) {
189
+ f.setLocalError(e.path, t instanceof Error ? t.message : String(t));
190
+ }
191
+ },
192
+ onBlur: () => {
193
+ f.localError(e.path) === void 0 && _.reset();
194
+ }
195
+ };
196
+ if (s === "json") return /* @__PURE__ */ D(l.TextArea, {
197
+ ...v,
198
+ rows: 6
199
+ });
200
+ let ee = d.typeName === `${R}Timestamp` && t !== "view";
201
+ return /* @__PURE__ */ D(l.Row, {
202
+ actions: ee && /* @__PURE__ */ D(l.Button, {
203
+ size: "sm",
204
+ variant: "secondary",
205
+ onClick: () => {
206
+ e.set(se()), e instanceof n && e.ensure(), f.setLocalError(e.path, void 0), _.reset();
207
+ },
208
+ children: u.now
209
+ }),
210
+ children: /* @__PURE__ */ D(l.TextInput, { ...v })
211
+ });
212
+ }
213
+ function he({ message: e, mode: t, id: n, describedBy: r, invalid: i, "aria-label": a }) {
214
+ let o = e.fields()[0];
215
+ return /* @__PURE__ */ D(I, {
216
+ scalar: o.desc.scalar,
217
+ value: o.get(),
218
+ onValue: (e) => o.set(e),
219
+ store: e.store,
220
+ errorPath: o.path,
221
+ id: n,
222
+ describedBy: r,
223
+ invalid: i,
224
+ readOnly: t === "view",
225
+ "aria-label": a
226
+ });
227
+ }
228
+ function V({ message: e, mode: t, depth: n = 0 }) {
229
+ let a = r(), o = i(), s = p(), c = e.get(), l = c.typeUrl.slice(c.typeUrl.lastIndexOf("/") + 1), u = l ? a.registry.getMessage(l) : void 0, d = /* @__PURE__ */ new Set();
230
+ for (let e of a.registry) e.kind === "message" && a.anyTypeFilter(e.typeName) && d.add(e.typeName);
231
+ l && d.add(l);
232
+ let f = [...d].sort().map((e) => ({
233
+ value: e,
234
+ label: e
235
+ })), m = (t) => {
236
+ let n = a.registry.getMessage(t);
237
+ n && (T(n, w(n), c), e.notify());
238
+ }, h;
239
+ if (u) {
240
+ let t = new _(u, oe(c, u) ?? w(u), {
241
+ owner: e,
242
+ path: `${e.path}[${l}]`,
243
+ onChange: () => T(u, t.get(), c)
244
+ });
245
+ h = t;
246
+ }
247
+ return /* @__PURE__ */ O(o.Stack, { children: [/* @__PURE__ */ D(o.Select, {
248
+ "aria-label": s.selectType,
249
+ placeholder: s.selectType,
250
+ value: l,
251
+ options: f,
252
+ readOnly: t === "view",
253
+ onChange: m
254
+ }), h && /* @__PURE__ */ D(H, {
255
+ message: h,
256
+ mode: t,
257
+ depth: n
258
+ })] });
259
+ }
260
+ // lib/components/message.tsx
261
+ function H({ message: e, mode: t, depth: n = 0, ...r }) {
262
+ let i = e.value.desc.typeName;
263
+ return P(i) ? /* @__PURE__ */ D(z, {
264
+ message: e,
265
+ mode: t,
266
+ ...r
267
+ }) : i === "google.protobuf.Any" ? /* @__PURE__ */ D(V, {
268
+ message: e,
269
+ mode: t,
270
+ depth: n
271
+ }) : /* @__PURE__ */ D(Z, {
272
+ fields: e.fields(),
273
+ mode: t,
274
+ depth: n
275
+ });
276
+ }
277
+ function U({ field: e, mode: t, depth: n = 0, id: r, describedBy: a, invalid: o }) {
278
+ let s = i(), c = p();
279
+ if (P(e.value.desc.typeName)) return /* @__PURE__ */ D(H, {
280
+ message: e,
281
+ mode: t,
282
+ id: r,
283
+ describedBy: a,
284
+ invalid: o
285
+ });
286
+ let l = e.isSet(), u = e.elem.title(), d;
287
+ return t !== "view" && (d = l ? /* @__PURE__ */ D(s.Button, {
288
+ variant: "ghost",
289
+ size: "sm",
290
+ "aria-label": `${c.clear} ${u}`,
291
+ onClick: () => e.clear(),
292
+ children: c.clear
293
+ }) : /* @__PURE__ */ D(s.Button, {
294
+ variant: "secondary",
295
+ size: "sm",
296
+ "aria-label": `${c.edit} ${u}`,
297
+ onClick: () => e.ensure(),
298
+ children: c.edit
299
+ })), /* @__PURE__ */ D($, {
300
+ field: e,
301
+ id: r,
302
+ depth: n,
303
+ actions: d,
304
+ collapsible: l && n > 0,
305
+ children: l ? /* @__PURE__ */ D(H, {
306
+ message: e,
307
+ mode: t,
308
+ depth: n + 1
309
+ }) : /* @__PURE__ */ D("p", {
310
+ "data-pf": "empty",
311
+ children: c.notSet
312
+ })
313
+ });
314
+ }
315
+ // lib/components/list.tsx
316
+ function W({ field: e, index: t, readOnly: n }) {
317
+ let r = i(), a = p();
318
+ if (n) return null;
319
+ let o = t + 1;
320
+ return /* @__PURE__ */ O(E, { children: [
321
+ /* @__PURE__ */ D(r.Button, {
322
+ variant: "ghost",
323
+ size: "sm",
324
+ "aria-label": a.moveItemUp(o),
325
+ disabled: t === 0,
326
+ onClick: () => e.move(t, t - 1),
327
+ children: "↑"
328
+ }),
329
+ /* @__PURE__ */ D(r.Button, {
330
+ variant: "ghost",
331
+ size: "sm",
332
+ "aria-label": a.moveItemDown(o),
333
+ disabled: t === e.size - 1,
334
+ onClick: () => e.move(t, t + 1),
335
+ children: "↓"
336
+ }),
337
+ /* @__PURE__ */ D(r.Button, {
338
+ variant: "ghost",
339
+ size: "sm",
340
+ "aria-label": a.removeItem(o),
341
+ onClick: () => e.removeAt(t),
342
+ children: "✕"
343
+ })
344
+ ] });
345
+ }
346
+ function G(e, t) {
347
+ return `${e.path}[${t}]`;
348
+ }
349
+ function ge({ field: e, index: t, readOnly: n, value: r }) {
350
+ let a = i(), o = p(), s = b(), c = e.parent.errorMessagesAt(G(e, t)), l = {
351
+ describedBy: c.length > 0 ? `${s}-errors` : void 0,
352
+ invalid: c.length > 0,
353
+ readOnly: n,
354
+ "aria-label": o.item(t + 1)
355
+ }, u;
356
+ switch (e.desc.listKind) {
357
+ case "scalar":
358
+ u = /* @__PURE__ */ D(I, {
359
+ ...l,
360
+ scalar: e.desc.scalar,
361
+ value: r,
362
+ onValue: (n) => e.setAt(t, n),
363
+ store: e.parent.store,
364
+ errorPath: G(e, t)
365
+ });
366
+ break;
367
+ case "enum":
368
+ u = /* @__PURE__ */ D(k, {
369
+ ...l,
370
+ compact: !0,
371
+ desc: e.desc.enum,
372
+ value: r,
373
+ onValue: (n) => e.setAt(t, n)
374
+ });
375
+ break;
376
+ default: return null;
377
+ }
378
+ return /* @__PURE__ */ D(a.Row, {
379
+ id: s,
380
+ errors: c,
381
+ actions: /* @__PURE__ */ D(W, {
382
+ field: e,
383
+ index: t,
384
+ readOnly: n
385
+ }),
386
+ children: u
387
+ });
388
+ }
389
+ function _e({ field: e, index: t, readOnly: n, item: r, depth: a, mode: o }) {
390
+ let s = i(), c = p(), l = b(), u = /* @__PURE__ */ D(W, {
391
+ field: e,
392
+ index: t,
393
+ readOnly: n
394
+ }), d = c.item(t + 1), f = e.parent.errorMessagesAt(G(e, t));
395
+ return P(r.value.desc.typeName) ? /* @__PURE__ */ D(s.Row, {
396
+ id: l,
397
+ errors: f,
398
+ actions: u,
399
+ children: /* @__PURE__ */ D(H, {
400
+ message: r,
401
+ mode: o,
402
+ "aria-label": d,
403
+ describedBy: f.length > 0 ? `${l}-errors` : void 0,
404
+ invalid: f.length > 0
405
+ })
406
+ }) : /* @__PURE__ */ D(s.Section, {
407
+ id: l,
408
+ title: d,
409
+ errors: f,
410
+ depth: a,
411
+ actions: u,
412
+ collapsible: !0,
413
+ children: /* @__PURE__ */ D(H, {
414
+ message: r,
415
+ mode: o,
416
+ depth: a + 1
417
+ })
418
+ });
419
+ }
420
+ function K({ field: e, mode: t, depth: n = 0, id: r }) {
421
+ let a = i(), o = p(), s = t === "view", c;
422
+ c = e.desc.listKind === "message" ? e.messages().map((r, i) => /* @__PURE__ */ D(_e, {
423
+ field: e,
424
+ index: i,
425
+ readOnly: s,
426
+ item: r,
427
+ depth: n + 1,
428
+ mode: t
429
+ }, i)) : e.items().map((t, n) => /* @__PURE__ */ D(ge, {
430
+ field: e,
431
+ index: n,
432
+ readOnly: s,
433
+ value: t
434
+ }, n));
435
+ let l = s ? void 0 : /* @__PURE__ */ D(a.Button, {
436
+ variant: "secondary",
437
+ size: "sm",
438
+ "aria-label": `${o.addItem}: ${e.elem.title()}`,
439
+ onClick: () => e.add(),
440
+ children: o.addItem
441
+ });
442
+ return /* @__PURE__ */ D($, {
443
+ field: e,
444
+ id: r,
445
+ depth: n,
446
+ actions: l,
447
+ children: c.length === 0 ? /* @__PURE__ */ D("p", {
448
+ "data-pf": "empty",
449
+ children: o.noItems
450
+ }) : /* @__PURE__ */ D(a.Stack, { children: c })
451
+ });
452
+ }
453
+ // lib/components/map.tsx
454
+ function q({ field: e, entryKey: t, readOnly: n }) {
455
+ let r = i(), a = p();
456
+ return n ? null : /* @__PURE__ */ D(r.Button, {
457
+ variant: "ghost",
458
+ size: "sm",
459
+ "aria-label": a.removeEntry(e.formatKey(t)),
460
+ onClick: () => e.delete(t),
461
+ children: "✕"
462
+ });
463
+ }
464
+ function J() {
465
+ return /* @__PURE__ */ D("span", {
466
+ "data-pf": "separator",
467
+ "aria-hidden": "true",
468
+ children: "="
469
+ });
470
+ }
471
+ function ve({ field: e, value: t, onValue: n, store: r, errorPath: i, ...a }) {
472
+ switch (e.desc.mapKind) {
473
+ case "enum": return /* @__PURE__ */ D(k, {
474
+ ...a,
475
+ compact: !0,
476
+ desc: e.desc.enum,
477
+ value: t,
478
+ onValue: n
479
+ });
480
+ case "scalar": return /* @__PURE__ */ D(I, {
481
+ ...a,
482
+ scalar: e.desc.scalar,
483
+ value: t,
484
+ onValue: (e) => n(e),
485
+ store: r,
486
+ errorPath: i
487
+ });
488
+ default: return null;
489
+ }
490
+ }
491
+ function ye({ field: e, entryKey: t, readOnly: n, value: r }) {
492
+ let a = i(), o = p(), s = b(), c = e.formatKey(t), l = u(e.path, t), d = e.parent.errorMessagesAt(l);
493
+ return /* @__PURE__ */ O(a.Row, {
494
+ id: s,
495
+ errors: d,
496
+ actions: /* @__PURE__ */ D(q, {
497
+ field: e,
498
+ entryKey: t,
499
+ readOnly: n
500
+ }),
501
+ children: [
502
+ /* @__PURE__ */ D(a.TextInput, {
503
+ value: c,
504
+ readOnly: !0,
505
+ mono: !0,
506
+ "aria-label": o.entryKey(c),
507
+ onChange: () => {}
508
+ }),
509
+ /* @__PURE__ */ D(J, {}),
510
+ /* @__PURE__ */ D(ve, {
511
+ field: e,
512
+ value: r,
513
+ onValue: (n) => e.setValue(t, n),
514
+ store: e.parent.store,
515
+ errorPath: l,
516
+ readOnly: n,
517
+ invalid: d.length > 0,
518
+ describedBy: d.length > 0 ? `${s}-errors` : void 0,
519
+ "aria-label": o.entryValue(c)
520
+ })
521
+ ]
522
+ });
523
+ }
524
+ function be({ field: e, entryKey: t, readOnly: n, item: r, depth: a, mode: o }) {
525
+ let s = i(), c = p(), l = b(), d = e.formatKey(t), f = e.parent.errorMessagesAt(u(e.path, t)), m = /* @__PURE__ */ D(q, {
526
+ field: e,
527
+ entryKey: t,
528
+ readOnly: n
529
+ });
530
+ return P(r.value.desc.typeName) ? /* @__PURE__ */ O(s.Row, {
531
+ id: l,
532
+ errors: f,
533
+ actions: m,
534
+ children: [
535
+ /* @__PURE__ */ D(s.TextInput, {
536
+ value: d,
537
+ readOnly: !0,
538
+ mono: !0,
539
+ "aria-label": c.entryKey(d),
540
+ onChange: () => {}
541
+ }),
542
+ /* @__PURE__ */ D(J, {}),
543
+ /* @__PURE__ */ D(H, {
544
+ message: r,
545
+ mode: o,
546
+ "aria-label": c.entryValue(d),
547
+ describedBy: f.length > 0 ? `${l}-errors` : void 0,
548
+ invalid: f.length > 0
549
+ })
550
+ ]
551
+ }) : /* @__PURE__ */ D(s.Section, {
552
+ id: l,
553
+ title: c.entry(d),
554
+ errors: f,
555
+ depth: a,
556
+ actions: m,
557
+ collapsible: !0,
558
+ children: /* @__PURE__ */ D(H, {
559
+ message: r,
560
+ mode: o,
561
+ depth: a + 1
562
+ })
563
+ });
564
+ }
565
+ function xe({ field: t }) {
566
+ let n = i(), r = p(), a = b(), o = t.desc.mapKind !== "message", [s, c] = x(""), [l, u] = x(), [d, f] = x(() => t.zeroValue()), [m] = x(() => new e());
567
+ S(m.subscribe, m.snapshot);
568
+ let h = m.localError("value"), g = [l, h].filter((e) => e !== void 0), _ = s !== "" && !m.hasLocalErrors(), v = () => {
569
+ if (_) try {
570
+ t.add(t.parseKey(s), o ? d : void 0) ? (c(""), u(void 0), f(t.zeroValue())) : u(r.duplicateKey);
571
+ } catch (e) {
572
+ u(e instanceof Error ? e.message : String(e));
573
+ }
574
+ };
575
+ return /* @__PURE__ */ O(n.Row, {
576
+ id: a,
577
+ errors: g,
578
+ actions: /* @__PURE__ */ D(n.Button, {
579
+ variant: "secondary",
580
+ size: "sm",
581
+ "aria-label": r.addEntry,
582
+ disabled: !_,
583
+ onClick: v,
584
+ children: r.addEntry
585
+ }),
586
+ children: [/* @__PURE__ */ D(n.TextInput, {
587
+ value: s,
588
+ mono: !0,
589
+ invalid: l !== void 0,
590
+ describedBy: g.length > 0 ? `${a}-errors` : void 0,
591
+ placeholder: r.key,
592
+ "aria-label": r.key,
593
+ onChange: (e) => {
594
+ c(e), u(void 0);
595
+ },
596
+ onEnter: v
597
+ }), o && /* @__PURE__ */ O(E, { children: [/* @__PURE__ */ D(J, {}), /* @__PURE__ */ D(ve, {
598
+ field: t,
599
+ value: d,
600
+ onValue: (e) => f(e),
601
+ store: m,
602
+ errorPath: "value",
603
+ readOnly: !1,
604
+ invalid: h !== void 0,
605
+ onEnter: v,
606
+ placeholder: r.value,
607
+ "aria-label": r.value
608
+ })] })]
609
+ });
610
+ }
611
+ function Se({ field: e, mode: t, depth: n = 0, id: r }) {
612
+ let a = i(), o = p(), s = t === "view", c;
613
+ return c = e.desc.mapKind === "message" ? e.messages().map(([r, i]) => /* @__PURE__ */ D(be, {
614
+ field: e,
615
+ entryKey: r,
616
+ readOnly: s,
617
+ item: i,
618
+ depth: n + 1,
619
+ mode: t
620
+ }, e.formatKey(r))) : e.entries().map(([t, n]) => /* @__PURE__ */ D(ye, {
621
+ field: e,
622
+ entryKey: t,
623
+ readOnly: s,
624
+ value: n
625
+ }, e.formatKey(t))), /* @__PURE__ */ O($, {
626
+ field: e,
627
+ id: r,
628
+ depth: n,
629
+ children: [c.length === 0 && s && /* @__PURE__ */ D("p", {
630
+ "data-pf": "empty",
631
+ children: o.noItems
632
+ }), (c.length > 0 || !s) && /* @__PURE__ */ O(a.Stack, { children: [c, !s && /* @__PURE__ */ D(xe, { field: e })] })]
633
+ });
634
+ }
635
+ // lib/components/oneof.tsx
636
+ function Ce({ field: e, mode: n, depth: r = 0, id: a }) {
637
+ let o = i(), s = p(), c = b(), l = e.active(), u = [{
638
+ value: "",
639
+ label: s.selectCase
640
+ }, ...e.oneOf.fields.map((e) => ({
641
+ value: e.name,
642
+ label: t(e).title()
643
+ }))];
644
+ return /* @__PURE__ */ D($, {
645
+ field: e,
646
+ id: a,
647
+ depth: r,
648
+ children: /* @__PURE__ */ O(o.Stack, { children: [/* @__PURE__ */ D(o.Select, {
649
+ id: c,
650
+ "aria-label": e.elem.title(),
651
+ value: l?.desc.name ?? "",
652
+ options: u,
653
+ readOnly: n === "view",
654
+ onChange: (t) => e.select(t || void 0)
655
+ }), l && /* @__PURE__ */ D(Q, {
656
+ field: l,
657
+ mode: n,
658
+ depth: r + 1
659
+ }, l.path)] })
660
+ });
661
+ }
662
+ // lib/components/field.tsx
663
+ function Y(e) {
664
+ let t = h(), n = l(t, e.field);
665
+ return n ? ne(n, e) : /* @__PURE__ */ D(X, { ...e });
666
+ }
667
+ function X(e) {
668
+ let { field: t } = e;
669
+ if (t instanceof d) return /* @__PURE__ */ D(Ce, {
670
+ ...e,
671
+ field: t
672
+ });
673
+ if (t instanceof o) return /* @__PURE__ */ D(K, {
674
+ ...e,
675
+ field: t
676
+ });
677
+ if (t instanceof a) return /* @__PURE__ */ D(Se, {
678
+ ...e,
679
+ field: t
680
+ });
681
+ if (t instanceof n) return /* @__PURE__ */ D(U, {
682
+ ...e,
683
+ field: t
684
+ });
685
+ if (t instanceof ee) return /* @__PURE__ */ D(le, {
686
+ ...e,
687
+ field: t
688
+ });
689
+ if (t instanceof m) {
690
+ let n = t.elem.type(), r = t.desc.scalar;
691
+ return n.case === "confirm" ? /* @__PURE__ */ D(we, {
692
+ ...e,
693
+ field: t
694
+ }) : n.case === "file" && (r === C.BYTES || r === C.STRING) ? /* @__PURE__ */ D(Te, {
695
+ ...e,
696
+ field: t
697
+ }) : /* @__PURE__ */ D(L, {
698
+ ...e,
699
+ field: t,
700
+ multiline: n.case === "input" && !!n.value.multilineText
701
+ });
702
+ }
703
+ return null;
704
+ }
705
+ function we({ field: e, mode: t, id: n, describedBy: r, invalid: a }) {
706
+ let o = i(), s = e.elem.type();
707
+ if (s.case !== "confirm") return null;
708
+ let c = e.desc.scalar === C.BOOL, l = c ? e.get() === !0 : e.toString() === s.value.approve;
709
+ return /* @__PURE__ */ D(o.Checkbox, {
710
+ id: n,
711
+ name: e.desc.localName,
712
+ checked: l,
713
+ readOnly: t === "view",
714
+ invalid: a,
715
+ describedBy: r,
716
+ onChange: (t) => {
717
+ c ? e.set(t) : e.parse(t ? s.value.approve : s.value.decline);
718
+ }
719
+ });
720
+ }
721
+ function Te({ field: e, mode: t, id: n, describedBy: r, invalid: a }) {
722
+ let o = i(), [s, c] = x(), l = e.elem.type(), u = async (t) => {
723
+ c(t?.name), t ? e.desc.scalar === C.BYTES ? e.set(new Uint8Array(await t.arrayBuffer())) : e.set(await t.text()) : e.parse("");
724
+ };
725
+ return /* @__PURE__ */ D(o.FileInput, {
726
+ id: n,
727
+ name: e.desc.localName,
728
+ accept: l.case === "file" ? l.value.allowedTypes : void 0,
729
+ fileName: s,
730
+ readOnly: t === "view",
731
+ invalid: a,
732
+ describedBy: r,
733
+ onFile: (e) => void u(e)
734
+ });
735
+ }
736
+ // lib/components/frame.ts
737
+ function Ee(e) {
738
+ return e instanceof d || e instanceof o || e instanceof a ? "section" : e instanceof n ? P(e.value.desc.typeName) ? "field" : "section" : "field";
739
+ }
740
+ // lib/components/group.tsx
741
+ function Z({ fields: e, mode: t, depth: n = 0 }) {
742
+ let r = i();
743
+ return /* @__PURE__ */ D(r.Stack, { children: e.filter((e) => !e.elem.hidden).map((e) => /* @__PURE__ */ D(Q, {
744
+ field: e,
745
+ mode: t,
746
+ depth: n
747
+ }, e.path)) });
748
+ }
749
+ function Q({ field: e, mode: t, depth: n = 0 }) {
750
+ let r = h(), { kit: i } = r, a = b(), o = l(r, e);
751
+ if (!(o ? (o.frame ?? "field") === "field" : Ee(e) === "field")) return /* @__PURE__ */ D(Y, {
752
+ field: e,
753
+ mode: t,
754
+ depth: n,
755
+ id: a
756
+ });
757
+ let s = e.errorMessages(), c = e.elem.documented, u = [c ? `${a}-description` : void 0, s.length > 0 ? `${a}-errors` : void 0].filter(Boolean).join(" ") || void 0;
758
+ return /* @__PURE__ */ D(i.Field, {
759
+ id: a,
760
+ label: e.elem.title(),
761
+ description: c || void 0,
762
+ errors: s,
763
+ required: e.elem.required,
764
+ children: /* @__PURE__ */ D(Y, {
765
+ field: e,
766
+ mode: t,
767
+ depth: n,
768
+ id: a,
769
+ describedBy: u,
770
+ invalid: s.length > 0
771
+ })
772
+ });
773
+ }
774
+ function $({ field: e, depth: t = 0, id: n, actions: r, collapsible: a, children: o }) {
775
+ let s = i(), c = b();
776
+ return /* @__PURE__ */ D(s.Section, {
777
+ id: n ?? c,
778
+ title: e.elem.title(),
779
+ description: e.elem.documented || void 0,
780
+ errors: e.errorMessages(),
781
+ depth: t,
782
+ actions: r,
783
+ collapsible: a,
784
+ children: o
785
+ });
786
+ }
787
+ // lib/components/protoform.tsx
788
+ function De({ kit: e, renderers: t, resolve: n, messages: r, ...i }) {
789
+ return /* @__PURE__ */ D(te, {
790
+ kit: e,
791
+ renderers: t,
792
+ resolve: n,
793
+ messages: r,
794
+ children: /* @__PURE__ */ D(ke, { ...i })
795
+ });
796
+ }
797
+ function Oe(e) {
798
+ return e.fields().filter((e) => e.elem.hidden).flatMap((e) => e.errorMessages().map((t) => `${e.elem.title()}: ${t}`));
799
+ }
800
+ function ke({ message: e, mode: t, validateOn: n = "submit", children: a, onSubmit: o, onInvalid: s }) {
801
+ let c = r(), l = i(), { store: u } = e;
802
+ S(u.subscribe, u.snapshot);
803
+ let d = S(u.subscribe, u.dataSnapshot);
804
+ y(() => {
805
+ (u.submitted || n === "load" || n === "change" && d > 0) && e.validate(c.validator);
806
+ }, [
807
+ u,
808
+ e,
809
+ c,
810
+ n,
811
+ d
812
+ ]);
813
+ let f = (t) => {
814
+ t.preventDefault(), u.markSubmitted(), e.validate(c.validator).kind === "valid" && !u.hasLocalErrors() ? o?.(t) : s?.();
815
+ }, p = [...Oe(e), ...e.errorMessages()];
816
+ return /* @__PURE__ */ O(l.Form, {
817
+ onSubmit: f,
818
+ children: [
819
+ p.length > 0 && /* @__PURE__ */ D("ul", {
820
+ "data-pf": "form-errors",
821
+ role: "alert",
822
+ children: p.map((e) => /* @__PURE__ */ D("li", { children: e }, e))
823
+ }),
824
+ /* @__PURE__ */ D(Z, {
825
+ fields: e.fields(),
826
+ mode: t
827
+ }),
828
+ a && /* @__PURE__ */ D("div", {
829
+ "data-pf": "actions",
830
+ children: a
831
+ })
832
+ ]
833
+ });
834
+ }
835
+ export { le as C, M as S, F as _, Ee as a, P as b, Ce as c, U as d, H as f, I as g, L as h, $ as i, Se as l, z as m, Z as n, X as o, V as p, Q as r, Y as s, De as t, K as u, pe as v, k as w, N as x, fe as y };