@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
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,222 @@
1
- # Temporary Holding Version
1
+ # @dtkt/protoform
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Generate editable forms from protobuf message descriptors. Built on
4
+ [protobuf-es](https://github.com/bufbuild/protobuf-es) reflection and
5
+ [protovalidate](https://github.com/bufbuild/protovalidate-es).
6
+
7
+ ```tsx
8
+ import { Message } from "@dtkt/protoform";
9
+ import { Protoform, SubmitButton } from "@dtkt/protoform/components";
10
+ import { tailwindKit } from "@dtkt/protoform/kit/tailwind";
11
+ import "@dtkt/protoform/styles.css";
12
+
13
+ const message = new Message(MySchema, { name: "example" });
14
+
15
+ <Protoform message={message} kit={tailwindKit} onSubmit={() => save(message.get())}>
16
+ <SubmitButton>Save</SubmitButton>
17
+ </Protoform>
18
+ ```
19
+
20
+ `SubmitButton` is drawn by the active kit, so it matches the form (and any kit you swap in).
21
+ Other children of `<Protoform>` are rendered as-is: the kit styles only its own elements.
22
+
23
+ `message.get()` is always the live protobuf message; edits apply immediately.
24
+ `onSubmit` only fires when protovalidate passes and no input is unparsable
25
+ (`onInvalid` fires otherwise). Errors show after the first submit attempt and
26
+ stay current as the user edits (`validateOn="change"` shows them from the first edit).
27
+
28
+ ## Install
29
+
30
+ ```sh
31
+ npm install @dtkt/protoform @bufbuild/protobuf @bufbuild/protovalidate react react-dom
32
+ npm install @headlessui/react # only if you use the Tailwind kit
33
+ ```
34
+
35
+ `@headlessui/react` is an *optional* peer dependency: the bare kit doesn't need it, but
36
+ `@dtkt/protoform/kit/tailwind` does, and **your app must install it** so it shares your copy of React.
37
+
38
+ ### Troubleshooting: `Cannot read properties of null (reading 'useId')`
39
+
40
+ This means Headless UI is running against a second copy of React ("Invalid hook call").
41
+ It happens when the library is **linked locally** (`npm link`, `file:`, workspaces): the
42
+ bundler resolves the library's imports from its real path, so it picks up the library's own
43
+ `node_modules` copies of `@headlessui/react` and `react` — even if your app has them
44
+ installed. Force a single copy in `vite.config.ts`, then restart with `vite --force` and
45
+ hard-reload:
46
+
47
+ ```ts
48
+ export default defineConfig({
49
+ resolve: {
50
+ dedupe: [
51
+ "react", "react-dom", "@headlessui/react",
52
+ "@bufbuild/protobuf", "@bufbuild/protovalidate",
53
+ "@connectrpc/connect", "@connectrpc/connect-web",
54
+ ],
55
+ },
56
+ });
57
+ ```
58
+
59
+ Regular installs from a registry or a packed tarball (`npm pack`) don't need this, but your
60
+ app must still install `@headlessui/react` for the Tailwind kit.
61
+
62
+ ## Annotations
63
+
64
+ Protoform works with any generated protobuf type; annotations only refine the defaults.
65
+ The `dtkt.protoform.v1beta1` annotation schema ships with this package (like
66
+ `@bufbuild/protovalidate/gen` does for `buf.validate`), so your own generated code can
67
+ use it without depending on `@dtkt/sdk`. With `buf.gen.yaml`:
68
+
69
+ ```yaml
70
+ - remote: buf.build/bufbuild/es
71
+ opt:
72
+ - map_imports=dtkt/protoform/:@dtkt/protoform/gen
73
+ ```
74
+
75
+ `@bufbuild/protobuf` and `@bufbuild/protovalidate` are peer dependencies so your generated
76
+ code, protovalidate and Protoform share a single copy.
77
+
78
+ ## What each type renders
79
+
80
+ | Proto type | Control |
81
+ |---|---|
82
+ | `string` | text input (`input.multilineText` hint → textarea) |
83
+ | `bool` | switch (`confirm` hint → checkbox) |
84
+ | `int32` family | text input, `inputmode=numeric`, range-checked |
85
+ | `int64` family | same, kept exact as `bigint` |
86
+ | `float`, `double` | text input, accepts `NaN`/`Infinity` |
87
+ | `bytes` | base64 text (`file` hint → file picker) |
88
+ | `enum` | radio group (≤ 4 values) or select |
89
+ | `message` | collapsible section, added/removed explicitly (unset ≠ empty) |
90
+ | `repeated` | rows with add, remove, move up/down |
91
+ | `map` | rows labelled by key; key input validated for the key type, duplicates rejected |
92
+ | `oneof` | case picker plus the selected member |
93
+ | `Timestamp`, `Duration`, `FieldMask` | RFC 3339 / `1.5s` / `a,b.c` text with validation (Timestamp has a "Now" button) |
94
+ | `Struct`, `Value`, `ListValue` | JSON editor |
95
+ | wrappers (`Int32Value`, …) | the wrapped scalar |
96
+ | `Any` | type picker from the `Env` registry, then the nested form |
97
+
98
+ The `select` / `multiSelect` hints (options loaded over RPC) are not implemented yet; those fields fall back to the control for their type.
99
+
100
+ ## Choosing a UI
101
+
102
+ Rendering goes through a `UIKit`: a small set of primitives (`Form`, `Stack`,
103
+ `Row`, `Field`, `Section`, `TextInput`, `TextArea`, `Checkbox`, `Select`,
104
+ `RadioGroup`, `FileInput`, `Button`). Three levels:
105
+
106
+ 1. **Tailwind + Headless UI** — `@dtkt/protoform/kit/tailwind` plus `@dtkt/protoform/styles.css`.
107
+ `@headlessui/react` is an optional peer dependency; Tailwind is *not* required in your app.
108
+ 2. **Bare** (the default when no kit is given) — unstyled, semantic HTML with `data-pf="…"`
109
+ attributes to style against. No CSS, no extra dependencies.
110
+ 3. **Your own** — pass any subset of primitives; the rest fall back to the enclosing
111
+ provider or the bare kit.
112
+
113
+ ```tsx
114
+ import { UIProvider } from "@dtkt/protoform/providers";
115
+
116
+ // Use MUI buttons everywhere, everything else bare
117
+ <UIProvider kit={{ Button: ({ children, onClick, disabled, type }) => (
118
+ <MuiButton type={type} onClick={onClick} disabled={disabled}>{children}</MuiButton>
119
+ ) }}>
120
+ <Protoform message={message} />
121
+ </UIProvider>
122
+ ```
123
+
124
+ `<Protoform kit={…}>` takes the same `kit`, `renderers`, `resolve` and `messages`
125
+ props as `UIProvider`. Providers nest; inner ones override per primitive.
126
+ `defineKit(a, b)` composes kits over the bare kit.
127
+
128
+ ### Theming and dark mode
129
+
130
+ `styles.css` is prebuilt: no Tailwind setup or global reset, only `.pf-*` classes in
131
+ the `protoform` cascade layer (your own unlayered CSS wins). Retheme with CSS custom
132
+ properties on the form or any ancestor:
133
+
134
+ ```css
135
+ .my-form { --pf-accent: #0d9488; --pf-radius: 0.75rem; }
136
+ ```
137
+
138
+ The form uses a system sans-serif font by default. To use your own stack, set
139
+ `--pf-font: "Inter", sans-serif;` on the form or any ancestor. To follow your app's
140
+ typography, use plain CSS (unlayered CSS beats the `protoform` layer):
141
+
142
+ ```css
143
+ .pf-form { font-family: inherit; }
144
+ ```
145
+
146
+ (`--pf-font: inherit` does *not* work: for a custom property, `inherit` means "take the
147
+ parent's `--pf-font`", not "inherit `font-family`".)
148
+
149
+ Dark mode follows `prefers-color-scheme`. Force it with `.dark` / `[data-theme="dark"]`
150
+ (or `.light` / `[data-theme="light"]`) on the form or any ancestor.
151
+
152
+ ### Custom renderers
153
+
154
+ Replace the editor for individual fields without touching the kit. Keys are a
155
+ field's full name (`pkg.Message.field`) or the type name of its message/enum:
156
+
157
+ ```tsx
158
+ const TimestampPicker: FieldRenderer = ({ field, id }) => <MyDatePicker id={id} field={field} />;
159
+
160
+ <Protoform
161
+ message={message}
162
+ renderers={{ "google.protobuf.Timestamp": TimestampPicker }}
163
+ resolve={(field) => field.desc.name === "secret" ? SecretInput : undefined}
164
+ />
165
+ ```
166
+
167
+ A renderer is wrapped in the standard labelled field frame; set `Renderer.frame = "none"`
168
+ to draw your own (see `FieldSection`).
169
+
170
+ ### Translating
171
+
172
+ All built-in strings live in `defaultMessages`; override any with the `messages` prop.
173
+
174
+ ## Environment
175
+
176
+ `Env` (via `EnvProvider`) supplies the type registry (needed for `Any`), validator and
177
+ transport. The default transport is created lazily, so importing the package has no side effects.
178
+
179
+ ```tsx
180
+ const env = new Env({ registry, anyTypeFilter: (name) => name.startsWith("acme.") });
181
+ ```
182
+
183
+ ## Development
184
+
185
+ ### Playground
186
+
187
+ An interactive playground lives in [`playground/`](./playground). It renders a form for a
188
+ fixture message covering every field type, with live JSON output beside it, and toggles for
189
+ kit (Tailwind / bare), theme (system / light / dark) and read-only mode.
190
+
191
+ ```sh
192
+ npm install
193
+ npm run dev # → http://localhost:5173
194
+ ```
195
+
196
+ Edits to `lib/` (components, kits, `lib/styles/protoform.css`) hot-reload. To try your own
197
+ message, change what `playground/main.tsx` renders — the fixture schema is in
198
+ `lib/test/fixture.ts`, or import any generated schema from your own protos.
199
+
200
+ `npm run build` produces the publishable package in `dist/`. (There is no `vite preview`
201
+ target: the build is a library, not an app. Use the playground to see it.)
202
+
203
+ ### Scripts
204
+
205
+ ```sh
206
+ npm run dev # playground with HMR
207
+ npm test # vitest (jsdom), single run
208
+ npm run test:watch # vitest in watch mode
209
+ npm run test:coverage # coverage report (v8) in the terminal and ./coverage
210
+ npm run lint # eslint
211
+ npm run gen # regenerate lib/gen (annotation schemas) from buf.build/datakit-dev/dtkt-sdk
212
+ npm run build # tsc, library (vite), then dist/styles.css (tailwind CLI)
213
+ ```
214
+
215
+ ### Tests
216
+
217
+ Tests are co-located with the code they cover (`foo.ts` → `foo.test.ts`,
218
+ `components/foo.tsx` → `components/foo.test.tsx`). Shared helpers live in
219
+ [`lib/test/`](./lib/test): `fixture.ts` builds a schema at runtime covering every field type
220
+ plus annotated ("hinted") fields, `render.tsx` renders a form with an `Env`, and
221
+ `helpers.ts` has the typed data accessors. UI tests run against **every shipped kit**
222
+ (`describe.each(kits)`), so a new kit or primitive is exercised by the whole suite.
package/dist/base.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { DescField } from '@bufbuild/protobuf';
2
+ import { Violation } from '@bufbuild/protovalidate';
3
+ import { Element } from './element';
4
+ import { Field } from './field';
5
+ import { Message } from './message';
6
+ /** Shared behavior for fields that live inside a parent `Message`. */
7
+ export declare abstract class BaseField<D extends DescField> implements Field {
8
+ readonly parent: Message;
9
+ readonly desc: D;
10
+ readonly path: string;
11
+ readonly elem: Element;
12
+ constructor(parent: Message, desc: D);
13
+ get errors(): Violation[];
14
+ errorMessages(): string[];
15
+ /** Marks the underlying message as changed so subscribed UI re-renders. */
16
+ protected changed(): void;
17
+ abstract toString(): string;
18
+ abstract parse(value: string): void;
19
+ }
@@ -0,0 +1,9 @@
1
+ import { DescEnum, DescEnumValue, DescField, DescMessage, DescOneof } from '@bufbuild/protobuf';
2
+ export type Commentable = DescMessage | DescEnum | DescEnumValue | DescField | DescOneof;
3
+ export type Comments = {
4
+ leadingDetached: string[];
5
+ leading?: string;
6
+ trailing?: string;
7
+ };
8
+ /** Comments attached to a descriptor in the .proto source, if the descriptor carries source info. */
9
+ export declare function getComments(desc: Commentable): Comments;
@@ -0,0 +1,24 @@
1
+ import { DescEnum } from '@bufbuild/protobuf';
2
+ import { EnumField } from '../enum';
3
+ import { FieldElementProps } from './field';
4
+ export type EnumInputProps = {
5
+ desc: DescEnum;
6
+ value: number;
7
+ onValue: (value: number) => void;
8
+ id?: string;
9
+ name?: string;
10
+ describedBy?: string;
11
+ invalid?: boolean;
12
+ readOnly?: boolean;
13
+ required?: boolean;
14
+ /** Always use a select (e.g. inside list rows). */
15
+ compact?: boolean;
16
+ "aria-label"?: string;
17
+ };
18
+ /** An editor for a single enum value; usable standalone (e.g. list items). */
19
+ export declare function EnumInput({ desc, value, onValue, compact, ...control }: EnumInputProps): import('react').JSX.Element;
20
+ type EnumElementProps = FieldElementProps & {
21
+ field: EnumField;
22
+ };
23
+ export declare function EnumElement({ field, mode, id, describedBy, invalid }: EnumElementProps): import('react').JSX.Element;
24
+ export {};
@@ -0,0 +1,16 @@
1
+ import { Field } from '../field';
2
+ /** `view` is read-only; `edit` and `auto` are editable (changes apply immediately). */
3
+ export type FieldDisplayMode = "edit" | "view" | "auto";
4
+ export type FieldElementProps = {
5
+ field: Field;
6
+ mode?: FieldDisplayMode;
7
+ depth?: number;
8
+ /** Id for the control, so a surrounding label can point at it. */
9
+ id?: string;
10
+ /** Id(s) of the description/error elements for `aria-describedby`. */
11
+ describedBy?: string;
12
+ invalid?: boolean;
13
+ };
14
+ /** Renders the editor for a field: a custom renderer if one matches, else the built-in. */
15
+ export declare function FieldElement(props: FieldElementProps): import('react').JSX.Element;
16
+ export declare function BuiltinFieldElement(props: FieldElementProps): import('react').JSX.Element | null;
@@ -0,0 +1,6 @@
1
+ import { Field } from '../field';
2
+ /**
3
+ * Whether a field is rendered inside a labelled `Field` frame (single
4
+ * controls) or draws its own `Section` (lists, maps, messages, oneofs).
5
+ */
6
+ export declare function frameOf(field: Field): "field" | "section";
@@ -0,0 +1,25 @@
1
+ import { PropsWithChildren, ReactNode } from 'react';
2
+ import { Field } from '../field';
3
+ import { FieldDisplayMode } from './field';
4
+ export type FieldGroupProps = {
5
+ fields: Field[];
6
+ mode?: FieldDisplayMode;
7
+ depth?: number;
8
+ };
9
+ export declare function FieldGroup({ fields, mode, depth, }: FieldGroupProps): import('react').JSX.Element;
10
+ export type FieldRowProps = {
11
+ field: Field;
12
+ mode?: FieldDisplayMode;
13
+ depth?: number;
14
+ };
15
+ /** Renders one field with its label, description and errors. */
16
+ export declare function FieldRow({ field, mode, depth }: FieldRowProps): import('react').JSX.Element;
17
+ export type FieldSectionProps = PropsWithChildren<{
18
+ field: Field;
19
+ depth?: number;
20
+ id?: string;
21
+ actions?: ReactNode;
22
+ collapsible?: boolean;
23
+ }>;
24
+ /** Frames the body of a composite field (message, list, map, oneof) with its title and errors. */
25
+ export declare function FieldSection({ field, depth, id, actions, collapsible, children }: FieldSectionProps): import('react').JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { Message } from '../message';
2
+ /**
3
+ * Subscribes to a message tree. Components that edit a `Message` re-render
4
+ * whenever its data or errors change. `Protoform` does this for you.
5
+ */
6
+ export declare function useMessage(message: Message): Message;
7
+ /**
8
+ * Keeps what the user typed while it is not yet (or no longer exactly) the
9
+ * canonical text of the value, so typing "1." or "-" isn't clobbered.
10
+ *
11
+ * `normalize` maps typed text to its canonical form, or `undefined` if the
12
+ * text is invalid.
13
+ */
14
+ export declare function useDraft(canonical: string, normalize: (text: string) => string | undefined): {
15
+ text: string;
16
+ setText: (next: string) => void;
17
+ reset: () => void;
18
+ };
@@ -0,0 +1,13 @@
1
+ export * from './enum';
2
+ export * from './field';
3
+ export * from './frame';
4
+ export * from './group';
5
+ export * from './hooks';
6
+ export * from './list';
7
+ export * from './map';
8
+ export * from './message';
9
+ export * from './oneof';
10
+ export * from './protoform';
11
+ export * from './scalar';
12
+ export * from './submit';
13
+ export * from './wkt';
@@ -0,0 +1,14 @@
1
+ import { a as e } from "../context-DSrebuNf.js";
2
+ import { C as t, _ as n, a as r, c as i, d as a, f as o, g as s, h as c, i as l, l as u, m as d, n as f, o as p, p as m, r as h, s as g, t as _, u as v, v as y, w as b } from "../protoform-DmMJ7LSw.js";
3
+ import { jsx as x } from "react/jsx-runtime";
4
+ // lib/components/submit.tsx
5
+ function S({ variant: t = "primary", children: n = "Submit", ...r }) {
6
+ let { Button: i } = e();
7
+ return /* @__PURE__ */ x(i, {
8
+ ...r,
9
+ variant: t,
10
+ type: "submit",
11
+ children: n
12
+ });
13
+ }
14
+ export { m as AnyEditor, p as BuiltinFieldElement, t as EnumElement, b as EnumInput, g as FieldElement, f as FieldGroup, h as FieldRow, l as FieldSection, v as ListElement, u as MapElement, a as MessageElement, o as MessageValue, i as OneOfFieldElement, _ as Protoform, c as ScalarElement, s as ScalarInput, S as SubmitButton, d as WellKnownEditor, r as frameOf, n as useDraft, y as useMessage };
@@ -0,0 +1,7 @@
1
+ import { ListField } from '../list';
2
+ import { FieldElementProps } from './field';
3
+ type ListElementProps = FieldElementProps & {
4
+ field: ListField;
5
+ };
6
+ export declare function ListElement({ field, mode, depth, id }: ListElementProps): import('react').JSX.Element;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import { MapField } from '../map';
2
+ import { FieldElementProps } from './field';
3
+ type MapElementProps = FieldElementProps & {
4
+ field: MapField;
5
+ };
6
+ export declare function MapElement({ field, mode, depth, id }: MapElementProps): import('react').JSX.Element;
7
+ export {};
@@ -0,0 +1,17 @@
1
+ import { Message, MessageField } from '../message';
2
+ import { FieldDisplayMode, FieldElementProps } from './field';
3
+ export type MessageValueProps = {
4
+ message: Message;
5
+ mode?: FieldDisplayMode;
6
+ depth?: number;
7
+ id?: string;
8
+ describedBy?: string;
9
+ invalid?: boolean;
10
+ "aria-label"?: string;
11
+ };
12
+ /** The editor for the contents of a message (a form, or a specialised well-known type editor). */
13
+ export declare function MessageValue({ message, mode, depth, ...control }: MessageValueProps): import('react').JSX.Element;
14
+ export type MessageElementProps = FieldElementProps & {
15
+ field: MessageField;
16
+ };
17
+ export declare function MessageElement({ field, mode, depth, id, describedBy, invalid }: MessageElementProps): import('react').JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { OneOfField } from '../oneof';
2
+ import { FieldElementProps } from './field';
3
+ type OneOfFieldElementProps = FieldElementProps & {
4
+ field: OneOfField;
5
+ };
6
+ /** A case picker plus the editor for the selected member. */
7
+ export declare function OneOfFieldElement({ field, mode, depth, id }: OneOfFieldElementProps): import('react').JSX.Element;
8
+ export {};
@@ -0,0 +1,20 @@
1
+ import { PropsWithChildren, SubmitEvent } from 'react';
2
+ import { Message } from '../message';
3
+ import { UIProviderProps } from '../providers/ui';
4
+ import { FieldDisplayMode } from './field';
5
+ export type ProtoformProps = UIProviderProps & {
6
+ message: Message;
7
+ /** `view` makes the form read-only. */
8
+ mode?: FieldDisplayMode;
9
+ /**
10
+ * When to show validation errors. Errors always appear (and then stay
11
+ * current) after a submit attempt; `"change"` also validates from the
12
+ * first edit.
13
+ */
14
+ validateOn?: "load" | "change" | "submit";
15
+ /** Called on submit when the message is valid. */
16
+ onSubmit?: (event: SubmitEvent<HTMLFormElement>) => void;
17
+ /** Called on submit when validation fails or an input can't be parsed. */
18
+ onInvalid?: () => void;
19
+ };
20
+ export declare function Protoform({ kit, renderers, resolve, messages, ...props }: PropsWithChildren<ProtoformProps>): import('react').JSX.Element;