@logixjs/form 0.0.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.
Files changed (101) hide show
  1. package/dist/Error-VvknI9Wj.d.cts +37 -0
  2. package/dist/Error-VvknI9Wj.d.ts +37 -0
  3. package/dist/Error.cjs +46 -0
  4. package/dist/Error.cjs.map +1 -0
  5. package/dist/Error.d.cts +1 -0
  6. package/dist/Error.d.ts +1 -0
  7. package/dist/Error.js +14 -0
  8. package/dist/Error.js.map +1 -0
  9. package/dist/Form.cjs +2455 -0
  10. package/dist/Form.cjs.map +1 -0
  11. package/dist/Form.d.cts +64 -0
  12. package/dist/Form.d.ts +64 -0
  13. package/dist/Form.js +25 -0
  14. package/dist/Form.js.map +1 -0
  15. package/dist/FormView-CAg9LVrf.d.cts +17 -0
  16. package/dist/FormView-CAg9LVrf.d.ts +17 -0
  17. package/dist/FormView.cjs +61 -0
  18. package/dist/FormView.cjs.map +1 -0
  19. package/dist/FormView.d.cts +1 -0
  20. package/dist/FormView.d.ts +1 -0
  21. package/dist/FormView.js +8 -0
  22. package/dist/FormView.js.map +1 -0
  23. package/dist/Path-DOjMkAS6.d.cts +42 -0
  24. package/dist/Path-DOjMkAS6.d.ts +42 -0
  25. package/dist/Path.cjs +132 -0
  26. package/dist/Path.cjs.map +1 -0
  27. package/dist/Path.d.cts +1 -0
  28. package/dist/Path.d.ts +1 -0
  29. package/dist/Path.js +22 -0
  30. package/dist/Path.js.map +1 -0
  31. package/dist/Rule-BOAiSVz9.d.cts +202 -0
  32. package/dist/Rule-BOAiSVz9.d.ts +202 -0
  33. package/dist/Rule.cjs +307 -0
  34. package/dist/Rule.cjs.map +1 -0
  35. package/dist/Rule.d.cts +2 -0
  36. package/dist/Rule.d.ts +2 -0
  37. package/dist/Rule.js +34 -0
  38. package/dist/Rule.js.map +1 -0
  39. package/dist/SchemaErrorMapping-Cu5gl7-Z.d.ts +50 -0
  40. package/dist/SchemaErrorMapping-DOrgLzii.d.cts +50 -0
  41. package/dist/SchemaErrorMapping.cjs +305 -0
  42. package/dist/SchemaErrorMapping.cjs.map +1 -0
  43. package/dist/SchemaErrorMapping.d.cts +2 -0
  44. package/dist/SchemaErrorMapping.d.ts +2 -0
  45. package/dist/SchemaErrorMapping.js +17 -0
  46. package/dist/SchemaErrorMapping.js.map +1 -0
  47. package/dist/SchemaPathMapping-BCoUW-_q.d.ts +16 -0
  48. package/dist/SchemaPathMapping-BUq2zm8W.d.cts +20 -0
  49. package/dist/SchemaPathMapping-BUq2zm8W.d.ts +20 -0
  50. package/dist/SchemaPathMapping-DJnExqM3.d.cts +16 -0
  51. package/dist/SchemaPathMapping.cjs +179 -0
  52. package/dist/SchemaPathMapping.cjs.map +1 -0
  53. package/dist/SchemaPathMapping.d.cts +2 -0
  54. package/dist/SchemaPathMapping.d.ts +2 -0
  55. package/dist/SchemaPathMapping.js +12 -0
  56. package/dist/SchemaPathMapping.js.map +1 -0
  57. package/dist/Trait-Bu794ROY.d.cts +49 -0
  58. package/dist/Trait-Bu794ROY.d.ts +49 -0
  59. package/dist/Trait.cjs +48 -0
  60. package/dist/Trait.cjs.map +1 -0
  61. package/dist/Trait.d.cts +2 -0
  62. package/dist/Trait.d.ts +2 -0
  63. package/dist/Trait.js +12 -0
  64. package/dist/Trait.js.map +1 -0
  65. package/dist/chunk-5DRI5UGD.js +105 -0
  66. package/dist/chunk-5DRI5UGD.js.map +1 -0
  67. package/dist/chunk-AD2ZA7KA.js +23 -0
  68. package/dist/chunk-AD2ZA7KA.js.map +1 -0
  69. package/dist/chunk-EOXJRCM6.js +146 -0
  70. package/dist/chunk-EOXJRCM6.js.map +1 -0
  71. package/dist/chunk-JZ5FZKPJ.js +71 -0
  72. package/dist/chunk-JZ5FZKPJ.js.map +1 -0
  73. package/dist/chunk-LNJJPZAG.js +46 -0
  74. package/dist/chunk-LNJJPZAG.js.map +1 -0
  75. package/dist/chunk-NAR5SIFP.js +22 -0
  76. package/dist/chunk-NAR5SIFP.js.map +1 -0
  77. package/dist/chunk-OJVEZKU7.js +117 -0
  78. package/dist/chunk-OJVEZKU7.js.map +1 -0
  79. package/dist/chunk-PZ5AY32C.js +10 -0
  80. package/dist/chunk-PZ5AY32C.js.map +1 -0
  81. package/dist/chunk-S5JTU2CM.js +31 -0
  82. package/dist/chunk-S5JTU2CM.js.map +1 -0
  83. package/dist/chunk-YHDEJ47V.js +1885 -0
  84. package/dist/chunk-YHDEJ47V.js.map +1 -0
  85. package/dist/chunk-YVHXLY63.js +315 -0
  86. package/dist/chunk-YVHXLY63.js.map +1 -0
  87. package/dist/impl-BfSlyM58.d.ts +225 -0
  88. package/dist/impl-Ccdm5eDF.d.cts +225 -0
  89. package/dist/index.cjs +2689 -0
  90. package/dist/index.cjs.map +1 -0
  91. package/dist/index.d.cts +12 -0
  92. package/dist/index.d.ts +12 -0
  93. package/dist/index.js +56 -0
  94. package/dist/index.js.map +1 -0
  95. package/dist/react/index.cjs +332 -0
  96. package/dist/react/index.cjs.map +1 -0
  97. package/dist/react/index.d.cts +43 -0
  98. package/dist/react/index.d.ts +43 -0
  99. package/dist/react/index.js +201 -0
  100. package/dist/react/index.js.map +1 -0
  101. package/package.json +62 -0
@@ -0,0 +1,225 @@
1
+ import * as Logix from '@logixjs/core';
2
+ import { Schema, Effect } from 'effect';
3
+ import { e as RulesDecl, f as RuleInput, L as ListIdentityPolicy, g as RootDecl, c as CanonicalListPath, C as CanonicalPath, d as CanonicalListItem, h as ListDecl, b as CanonicalValue, E as ErrorTarget, i as FieldDecl, A as AutoValidateOn } from './Rule-BOAiSVz9.cjs';
4
+ import { D as DerivedSpec } from './Trait-Bu794ROY.cjs';
5
+
6
+ /**
7
+ * RulesSpec: the input shape of `Form.make({ rules })`.
8
+ *
9
+ * - Task 028 compiles `rules` into an equivalent `StateTraitSpec`; `rules` itself does not introduce a second runtime.
10
+ */
11
+ type RulesSpec<TValues extends object> = Readonly<{
12
+ readonly _tag: 'FormRulesSpec';
13
+ readonly decls: ReadonlyArray<RulesDecl<TValues>>;
14
+ }>;
15
+ type RulesFieldNode = Readonly<{
16
+ readonly _tag: 'FormRulesNodeField';
17
+ readonly rule: RuleInput<any, any>;
18
+ }>;
19
+ type RulesObjectNode = Readonly<{
20
+ readonly _tag: 'FormRulesNodeObject';
21
+ readonly shape: Readonly<Record<string, RulesNode>>;
22
+ readonly refineRule?: RuleInput<any, any>;
23
+ readonly superRefineRule?: RuleInput<any, any>;
24
+ readonly refine: (rule: RuleInput<any, any>) => RulesObjectNode;
25
+ readonly superRefine: (rule: RuleInput<any, any>) => RulesObjectNode;
26
+ }>;
27
+ type RulesArrayNode = Readonly<{
28
+ readonly _tag: 'FormRulesNodeArray';
29
+ readonly item: RulesNode;
30
+ readonly identity: ListIdentityPolicy;
31
+ readonly refineRule?: RuleInput<any, any>;
32
+ readonly superRefineRule?: RuleInput<any, any>;
33
+ readonly refine: (rule: RuleInput<any, any>) => RulesArrayNode;
34
+ readonly superRefine: (rule: RuleInput<any, any>) => RulesArrayNode;
35
+ }>;
36
+ type RulesNode = RulesFieldNode | RulesObjectNode | RulesArrayNode;
37
+ type TrackByKey<Item> = Item extends object ? CanonicalPath<Item> extends never ? string : CanonicalPath<Item> : string;
38
+ type RulesDsl<TValues extends object> = {
39
+ (...decls: ReadonlyArray<RulesDecl<TValues>>): RulesSpec<TValues>;
40
+ (...decls: ReadonlyArray<RulesDecl<TValues> | ReadonlyArray<RulesDecl<TValues>>>): RulesSpec<TValues>;
41
+ readonly schema: (node: RulesNode) => RulesSpec<TValues>;
42
+ readonly at: (prefix: string) => RulesDsl<TValues>;
43
+ readonly root: <Ctx = unknown>(rule: RuleInput<TValues, Ctx>) => RootDecl<TValues, Ctx>;
44
+ readonly list: <P extends CanonicalListPath<TValues>, Ctx = unknown>(listPath: P, spec: {
45
+ readonly identity: Readonly<{
46
+ readonly mode: 'trackBy';
47
+ readonly trackBy: TrackByKey<CanonicalListItem<TValues, P>>;
48
+ }> | Readonly<{
49
+ readonly mode: 'store';
50
+ }> | Readonly<{
51
+ readonly mode: 'index';
52
+ }>;
53
+ readonly item?: RuleInput<CanonicalListItem<TValues, P>, Ctx>;
54
+ readonly list?: RuleInput<ReadonlyArray<CanonicalListItem<TValues, P>>, Ctx>;
55
+ }) => ListDecl<CanonicalListItem<TValues, P>, Ctx>;
56
+ readonly field: {
57
+ <P extends CanonicalPath<TValues>, Ctx = unknown>(valuePath: P, rule: RuleInput<CanonicalValue<TValues, P>, Ctx>, options?: {
58
+ readonly errorTarget?: ErrorTarget;
59
+ }): FieldDecl<CanonicalValue<TValues, P>, Ctx>;
60
+ (schema: Schema.Schema<any, any, never>): RulesFieldNode;
61
+ (rule: RuleInput<any, any>): RulesFieldNode;
62
+ };
63
+ readonly object: (shape: Readonly<Record<string, RulesNode>>) => RulesObjectNode;
64
+ readonly array: (item: RulesNode, options: {
65
+ readonly identity: ListIdentityPolicy;
66
+ }) => RulesArrayNode;
67
+ };
68
+ /**
69
+ * Form.rules:
70
+ * - `$.rules(...decls)`:decl list(`Form.Rule.field/list/root`)
71
+ * - `$.rules.schema(node)`: zod-like rules authoring (Phase 3 will be filled in gradually)
72
+ * - `$.rules.at(prefix)`: write relative paths under `prefix`
73
+ */
74
+ declare const rules: <TValues extends object, I>(_valuesSchema: Schema.Schema<TValues, I>) => RulesDsl<TValues>;
75
+
76
+ type RulesManifest = Readonly<{
77
+ readonly moduleId: string;
78
+ readonly lists: ReadonlyArray<Readonly<{
79
+ readonly path: ReadonlyArray<string>;
80
+ readonly identity: ListIdentityPolicy;
81
+ }>>;
82
+ readonly rules: ReadonlyArray<RuleDescriptor>;
83
+ }>;
84
+ type RuleScope = Readonly<{
85
+ readonly kind: 'root' | 'field' | 'list' | 'item';
86
+ readonly fieldPath: ReadonlyArray<string>;
87
+ readonly errorTarget?: ErrorTarget;
88
+ }>;
89
+ type RuleDescriptor = Readonly<{
90
+ readonly ruleId: string;
91
+ readonly scope: RuleScope;
92
+ readonly deps: ReadonlyArray<string>;
93
+ readonly validateOn?: ReadonlyArray<AutoValidateOn>;
94
+ readonly meta?: Logix.Observability.JsonValue;
95
+ }>;
96
+
97
+ type FormErrors = unknown;
98
+ type FormUiState = unknown;
99
+ type FormMeta = {
100
+ readonly submitCount: number;
101
+ readonly isSubmitting: boolean;
102
+ readonly isDirty: boolean;
103
+ /**
104
+ * errorCount:
105
+ * - Used for O(1) reads in `FormView.isValid/canSubmit`.
106
+ * - Semantics: the number of ErrorValue leaf nodes in the errors tree (including `$manual/$schema`).
107
+ */
108
+ readonly errorCount: number;
109
+ };
110
+ type FormState<TValues extends object> = TValues & {
111
+ readonly errors: FormErrors;
112
+ readonly ui: FormUiState;
113
+ readonly $form: FormMeta;
114
+ };
115
+ declare const FormActions: {
116
+ readonly setValue: Schema.Struct<{
117
+ path: typeof Schema.String;
118
+ value: typeof Schema.Unknown;
119
+ }>;
120
+ readonly blur: Schema.Struct<{
121
+ path: typeof Schema.String;
122
+ }>;
123
+ readonly submit: typeof Schema.Void;
124
+ readonly validate: typeof Schema.Void;
125
+ readonly validatePaths: Schema.Array$<typeof Schema.String>;
126
+ readonly submitAttempt: typeof Schema.Void;
127
+ readonly setSubmitting: typeof Schema.Boolean;
128
+ readonly reset: Schema.UndefinedOr<typeof Schema.Unknown>;
129
+ readonly setError: Schema.Struct<{
130
+ path: typeof Schema.String;
131
+ error: typeof Schema.Unknown;
132
+ }>;
133
+ readonly clearErrors: Schema.UndefinedOr<Schema.Array$<typeof Schema.String>>;
134
+ readonly arrayAppend: Schema.Struct<{
135
+ path: typeof Schema.String;
136
+ value: typeof Schema.Unknown;
137
+ }>;
138
+ readonly arrayPrepend: Schema.Struct<{
139
+ path: typeof Schema.String;
140
+ value: typeof Schema.Unknown;
141
+ }>;
142
+ readonly arrayRemove: Schema.Struct<{
143
+ path: typeof Schema.String;
144
+ index: typeof Schema.Number;
145
+ }>;
146
+ readonly arraySwap: Schema.Struct<{
147
+ path: typeof Schema.String;
148
+ indexA: typeof Schema.Number;
149
+ indexB: typeof Schema.Number;
150
+ }>;
151
+ readonly arrayMove: Schema.Struct<{
152
+ path: typeof Schema.String;
153
+ from: typeof Schema.Number;
154
+ to: typeof Schema.Number;
155
+ }>;
156
+ };
157
+ type FormShapeForActions = FormShape<Record<string, never>>;
158
+ type FormAction = Logix.ActionOf<FormShapeForActions>;
159
+ type FormShape<TValues extends object> = Logix.Shape<Schema.Schema<FormState<TValues>, any>, typeof FormActions>;
160
+ interface FormMakeConfig<TValues extends object> {
161
+ readonly values: Schema.Schema<TValues, any>;
162
+ readonly initialValues: TValues;
163
+ readonly validateOn?: ReadonlyArray<'onSubmit' | 'onChange' | 'onBlur'>;
164
+ readonly reValidateOn?: ReadonlyArray<'onSubmit' | 'onChange' | 'onBlur'>;
165
+ readonly debounceMs?: number;
166
+ /**
167
+ * rules:
168
+ * - Recommended: express validations using rules only (field/list/root rules).
169
+ * - The result will be compiled into an equivalent StateTraitSpec (does not introduce a second runtime).
170
+ */
171
+ readonly rules?: RulesSpec<TValues>;
172
+ readonly traits?: Logix.StateTrait.StateTraitSpec<TValues>;
173
+ /**
174
+ * derived:
175
+ * - The entry point for domain-level linkage/derivation (by default, only writes back to values/ui are allowed).
176
+ * - The result must be fully reducible to StateTraitSpec/IR (computed/link/source).
177
+ */
178
+ readonly derived?: DerivedSpec<TValues>;
179
+ }
180
+ type FormExtendDef<TValues extends object> = Omit<Logix.Module.MakeExtendDef<Schema.Schema<FormState<TValues>, any>, typeof FormActions, {}>, 'actions'> & {
181
+ readonly actions?: never;
182
+ };
183
+ interface FormController<TValues extends object> {
184
+ readonly runtime: Logix.ModuleRuntime<FormState<TValues>, FormAction>;
185
+ readonly getState: Effect.Effect<FormState<TValues>>;
186
+ readonly dispatch: (action: FormAction) => Effect.Effect<void>;
187
+ readonly submit: () => Effect.Effect<void>;
188
+ readonly controller: {
189
+ readonly validate: () => Effect.Effect<void, never, any>;
190
+ readonly validatePaths: (paths: ReadonlyArray<string> | string) => Effect.Effect<void, never, any>;
191
+ readonly reset: (values?: TValues) => Effect.Effect<void>;
192
+ readonly setError: (path: string, error: unknown) => Effect.Effect<void>;
193
+ readonly clearErrors: (paths?: ReadonlyArray<string> | string) => Effect.Effect<void>;
194
+ readonly handleSubmit: (handlers: {
195
+ readonly onValid: (values: TValues) => Effect.Effect<void, any, any>;
196
+ readonly onInvalid?: (errors: unknown) => Effect.Effect<void, any, any>;
197
+ }) => Effect.Effect<void, any, any>;
198
+ };
199
+ readonly field: (path: string) => {
200
+ readonly get: Effect.Effect<unknown>;
201
+ readonly set: (value: unknown) => Effect.Effect<void>;
202
+ readonly blur: () => Effect.Effect<void>;
203
+ };
204
+ readonly fieldArray: (path: string) => {
205
+ readonly get: Effect.Effect<ReadonlyArray<unknown>>;
206
+ readonly append: (value: unknown) => Effect.Effect<void>;
207
+ readonly prepend: (value: unknown) => Effect.Effect<void>;
208
+ readonly remove: (index: number) => Effect.Effect<void>;
209
+ readonly swap: (indexA: number, indexB: number) => Effect.Effect<void>;
210
+ readonly move: (from: number, to: number) => Effect.Effect<void>;
211
+ };
212
+ }
213
+ type FormHandleExt<TValues extends object> = {
214
+ readonly controller: FormController<TValues>['controller'];
215
+ readonly rulesManifest: () => RulesManifest;
216
+ readonly rulesManifestWarnings: () => ReadonlyArray<string>;
217
+ };
218
+ type FormModule<Id extends string, TValues extends object> = Logix.Module.Module<Id, FormShape<TValues>, FormHandleExt<TValues>, any> & {
219
+ readonly controller: {
220
+ readonly make: (runtime: Logix.ModuleRuntime<FormState<TValues>, FormAction>) => FormController<TValues>;
221
+ };
222
+ };
223
+ declare const make: <Id extends string, TValues extends object>(id: Id, config: FormMakeConfig<TValues>, extend?: FormExtendDef<TValues>) => FormModule<Id, TValues>;
224
+
225
+ export { type FormErrors as F, type RulesDsl as R, type RulesNode as a, type RulesSpec as b, type FormUiState as c, type FormMeta as d, type FormState as e, type FormAction as f, type FormShape as g, type FormMakeConfig as h, type FormExtendDef as i, type FormController as j, type FormHandleExt as k, type FormModule as l, make as m, type RuleDescriptor as n, type RuleScope as o, type RulesManifest as p, rules as r };