@tempots/beatui 0.76.0 → 0.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.cjs.js +1 -1
- package/dist/auth/index.es.js +3 -3
- package/dist/beatui.css +11 -2
- package/dist/beatui.tailwind.css +11 -2
- package/dist/deep-merge-DBUbjJYt.cjs +1 -0
- package/dist/{deep-merge-CQQCMLwG.js → deep-merge-E6b9KE6l.js} +221 -223
- package/dist/{duration-input-D-SIoDoo.cjs → duration-input-CsygvJJ_.cjs} +1 -1
- package/dist/{duration-input-DKxZ6OCa.js → duration-input-j7bVks-S.js} +2 -2
- package/dist/index.cjs.js +2 -2
- package/dist/index.es.js +238 -237
- package/dist/json-schema/index.cjs.js +1 -1
- package/dist/json-schema/index.es.js +5 -5
- package/dist/json-structure/index.cjs.js +1 -1
- package/dist/json-structure/index.es.js +3 -3
- package/dist/{modal-MofsfmAe.js → modal--5-j6x0s.js} +1 -1
- package/dist/{modal-5P9mU_a4.cjs → modal-rLbLQYhb.cjs} +1 -1
- package/dist/{notice-DP209Ed8.cjs → notice-BGaJ4k0O.cjs} +1 -1
- package/dist/{notice-Cqq8g17n.js → notice-BvS1_9Va.js} +1 -1
- package/dist/types/components/form/controller/controller-validation.d.ts +41 -0
- package/dist/types/components/json-schema/widgets/widget-customization.d.ts +7 -7
- package/dist/use-form-B4D58mxd.cjs +2 -0
- package/dist/{use-form-B7A865EM.js → use-form-DzA1RSrN.js} +115 -88
- package/dist/{widget-customization-GaZB6sLP.cjs → widget-customization-DKlfR6Qb.cjs} +1 -1
- package/dist/{widget-customization-CobH7Rj_.js → widget-customization-DfBf7gGp.js} +3 -3
- package/package.json +1 -1
- package/dist/deep-merge-DZxfgKqX.cjs +0 -1
- package/dist/use-form-DVJXMMoN.cjs +0 -2
|
@@ -5,4 +5,45 @@ export type ControllerError = {
|
|
|
5
5
|
dependencies?: Record<PathSegment, ControllerError>;
|
|
6
6
|
};
|
|
7
7
|
export type ControllerValidation = Validation<ControllerError>;
|
|
8
|
+
/**
|
|
9
|
+
* Helper object for creating ControllerValidation instances.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Valid state
|
|
14
|
+
* ControllerValidation.valid
|
|
15
|
+
*
|
|
16
|
+
* // Invalid with a message
|
|
17
|
+
* ControllerValidation.invalid('Something went wrong')
|
|
18
|
+
*
|
|
19
|
+
* // Invalid with field-specific errors
|
|
20
|
+
* ControllerValidation.invalidFields({
|
|
21
|
+
* email: 'Invalid email format',
|
|
22
|
+
* password: 'Password too short',
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* // Invalid from a ControllerError object
|
|
26
|
+
* ControllerValidation.fromError({
|
|
27
|
+
* message: 'Form has errors',
|
|
28
|
+
* dependencies: { field: { message: 'Error' } }
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const ControllerValidation: {
|
|
33
|
+
/** A valid validation result */
|
|
34
|
+
readonly valid: ControllerValidation;
|
|
35
|
+
/**
|
|
36
|
+
* Create an invalid validation with a message
|
|
37
|
+
*/
|
|
38
|
+
readonly invalid: (message: string) => ControllerValidation;
|
|
39
|
+
/**
|
|
40
|
+
* Create an invalid validation with field-specific errors.
|
|
41
|
+
* Values can be error messages (strings) or full ControllerError objects.
|
|
42
|
+
*/
|
|
43
|
+
readonly invalidFields: (fields: Record<PathSegment, string | ControllerError>) => ControllerValidation;
|
|
44
|
+
/**
|
|
45
|
+
* Create an invalid validation from a ControllerError object
|
|
46
|
+
*/
|
|
47
|
+
readonly fromError: (error: ControllerError) => ControllerValidation;
|
|
48
|
+
};
|
|
8
49
|
export declare function makeMapValidation(fields: PathSegment[]): (status: ControllerValidation) => ControllerValidation;
|
|
@@ -87,9 +87,9 @@ export interface WidgetCustomization {
|
|
|
87
87
|
/**
|
|
88
88
|
* Custom widget registration for form-scoped widgets
|
|
89
89
|
*/
|
|
90
|
-
export interface CustomWidgetRegistration
|
|
90
|
+
export interface CustomWidgetRegistration {
|
|
91
91
|
/** Widget factory function */
|
|
92
|
-
factory: WidgetFactory
|
|
92
|
+
factory: WidgetFactory;
|
|
93
93
|
/** Custom matcher function for widget selection (required) */
|
|
94
94
|
matcher: (ctx: SchemaContext) => boolean;
|
|
95
95
|
/** Widget priority (higher = preferred, default: 50) */
|
|
@@ -173,7 +173,7 @@ export declare function registerWidget<T = unknown>(name: string, factory: Widge
|
|
|
173
173
|
* // Matches schema: { type: 'string', 'x:ui': 'fancy-email' }
|
|
174
174
|
* ```
|
|
175
175
|
*/
|
|
176
|
-
export declare function forXUI
|
|
176
|
+
export declare function forXUI(widgetName: string, factory: WidgetFactory, options?: Partial<Omit<CustomWidgetRegistration, 'factory' | 'matcher'>>): CustomWidgetRegistration;
|
|
177
177
|
/**
|
|
178
178
|
* Create a custom widget registration that matches by schema format
|
|
179
179
|
*
|
|
@@ -183,7 +183,7 @@ export declare function forXUI<T = unknown>(widgetName: string, factory: WidgetF
|
|
|
183
183
|
* // Matches ANY schema with: { format: 'email' }
|
|
184
184
|
* ```
|
|
185
185
|
*/
|
|
186
|
-
export declare function forFormat
|
|
186
|
+
export declare function forFormat(format: string, factory: WidgetFactory, options?: Partial<Omit<CustomWidgetRegistration, 'factory' | 'matcher'>>): CustomWidgetRegistration;
|
|
187
187
|
/**
|
|
188
188
|
* Create a custom widget registration that matches by type + format combination
|
|
189
189
|
*
|
|
@@ -193,7 +193,7 @@ export declare function forFormat<T = unknown>(format: string, factory: WidgetFa
|
|
|
193
193
|
* // Matches schema: { type: 'string', format: 'uuid' }
|
|
194
194
|
* ```
|
|
195
195
|
*/
|
|
196
|
-
export declare function forTypeAndFormat
|
|
196
|
+
export declare function forTypeAndFormat(type: string, format: string, factory: WidgetFactory, options?: Partial<Omit<CustomWidgetRegistration, 'factory' | 'matcher'>>): CustomWidgetRegistration;
|
|
197
197
|
/**
|
|
198
198
|
* Create a diagnostic custom widget registration for debugging custom widget matching.
|
|
199
199
|
*
|
|
@@ -217,7 +217,7 @@ export declare function forTypeAndFormat<T = unknown>(type: string, format: stri
|
|
|
217
217
|
* ]
|
|
218
218
|
* ```
|
|
219
219
|
*/
|
|
220
|
-
export declare function createDiagnosticWidget
|
|
220
|
+
export declare function createDiagnosticWidget(options?: {
|
|
221
221
|
/** Prefix for log messages (default: 'WIDGET_DIAG') */
|
|
222
222
|
logPrefix?: string;
|
|
223
223
|
/** Filter function to control which properties are logged */
|
|
@@ -230,4 +230,4 @@ export declare function createDiagnosticWidget<T = unknown>(options?: {
|
|
|
230
230
|
hasRegistry: boolean;
|
|
231
231
|
definition: unknown;
|
|
232
232
|
}) => void;
|
|
233
|
-
}): CustomWidgetRegistration
|
|
233
|
+
}): CustomWidgetRegistration;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const r=require("@tempots/dom"),V=require("./translations-hMQlZmD4.cjs"),P=new Map;function I(e){const t=P.get(e)??0;return P.set(e,t+1),`${e}-${t}`}const m={notAsked:{type:"NotAsked"},loading(e=void 0){return{type:"Loading",previousValue:e}},success(e){return{type:"AsyncSuccess",value:e}},failure(e){return{type:"AsyncFailure",error:e}},isSuccess(e){return e.type==="AsyncSuccess"},isFailure(e){return e.type==="AsyncFailure"},isNotAsked(e){return e.type==="NotAsked"},isLoading(e){return e.type==="Loading"},getOrElse(e,t){return m.isSuccess(e)?e.value:t},getOrElseLazy(e,t){return m.isSuccess(e)?e.value:t()},getOrNull(e){return m.isSuccess(e)?e.value:null},getOrUndefined(e){return m.isSuccess(e)?e.value:void 0},getUnsafe:e=>{if(m.isSuccess(e))return e.value;throw m.isFailure(e)?e.error:new Error("Cannot get value from a not-asked or loading result")},match:(e,{success:t,failure:s,loading:n,notAsked:a=n})=>m.isSuccess(e)?t(e.value):m.isFailure(e)?s(e.error):m.isNotAsked(e)?a():n(e.previousValue),whenSuccess:(e,t)=>(m.isSuccess(e)&&t(e.value),e),whenFailure:(e,t)=>(m.isFailure(e)&&t(e.error),e),equals:(e,t,s={valueEquals:(n,a)=>n===a,errorEquals:(n,a)=>n===a})=>e.type==="AsyncSuccess"&&t.type==="AsyncSuccess"?s.valueEquals(e.value,t.value):e.type==="AsyncFailure"&&t.type==="AsyncFailure"?s.errorEquals(e.error,t.error):e.type==="Loading"&&t.type==="Loading"?s.valueEquals(e.previousValue,t.previousValue):e.type==="NotAsked"&&t.type==="NotAsked",all:e=>{const t=[];for(const s of e)if(m.isSuccess(s))t.push(s.value);else return s;return m.success(t)},ofPromise:async e=>{try{const t=await e;return m.success(t)}catch(t){return m.failure(t instanceof Error?t:new Error(String(t)))}}},E=(e,t)=>e===t||e!==e&&t!==t,p={valid:{type:"valid"},invalid(e){return{type:"invalid",error:e}},isValid(e){return e.type==="valid"},isInvalid(e){return e.type==="invalid"},match:(e,t,s)=>p.isValid(e)?t():s(e.error),toResult:(e,t)=>p.match(e,()=>d.success(t),s=>d.failure(s)),whenValid:(e,t)=>(p.isValid(e)&&t(),e),whenInvalid:(e,t)=>(p.isInvalid(e)&&t(e.error),e)},d={success(e){return{type:"Success",value:e}},failure(e){return{type:"Failure",error:e}},map:(e,t)=>e.type==="Success"?d.success(t(e.value)):e,flatMap:(e,t)=>e.type==="Success"?t(e.value):e,toAsync(e){return d.match(e,t=>m.success(t),t=>m.failure(t))},toValidation(e){return d.match(e,()=>p.valid,t=>p.invalid(t))},isSuccess(e){return e.type==="Success"},isFailure(e){return e.type==="Failure"},getOrElse(e,t){return d.isSuccess(e)?e.value:t},getOrElseLazy(e,t){return d.isSuccess(e)?e.value:t()},getOrNull(e){return d.isSuccess(e)?e.value:null},getOrUndefined(e){return d.isSuccess(e)?e.value:void 0},getUnsafe:e=>{if(d.isSuccess(e))return e.value;throw e.error},match:(e,t,s)=>d.isSuccess(e)?t(e.value):s(e.error),whenSuccess:(e,t)=>(d.isSuccess(e)&&t(e.value),e),whenFailure:(e,t)=>(d.isFailure(e)&&t(e.error),e),combine:(e,t,s,n)=>d.match(e,a=>d.match(t,i=>d.success(s(a,i)),i=>d.failure(i)),a=>d.match(t,i=>d.failure(a),i=>d.failure(n(a,i)))),equals:(e,t,s={valueEquals:(n,a)=>n===a,errorEquals:(n,a)=>n===a})=>e.type==="Success"&&t.type==="Success"?s.valueEquals(e.value,t.value):e.type==="Failure"&&t.type==="Failure"?s.errorEquals(e.error,t.error):!1,all:e=>{const t=[];for(const s of e)if(d.isSuccess(s))t.push(s.value);else return s;return d.success(t)}};function Z({size:e="sm",icon:t="line-md:close",disabled:s,roundedness:n="full",color:a="base",onClick:i,label:o},...l){return r.Use(V.BeatUII18n,c=>{const f=r.coalesce(o,c.$.closeModal);return V.Button({variant:"text",size:e,roundedness:n,disabled:s,color:a,onClick:i},r.attr.title(f),r.aria.label(f),...l,V.Icon({icon:t,size:e??"sm"}))})}function A(e){return`bc-label bc-label--${e}`}const ee=(...e)=>r.html.span(r.attr.class(A("emphasis")),...e),$=(...e)=>r.html.span(r.attr.class(A("default")),...e),j=(...e)=>r.html.span(r.attr.class(A("muted")),...e),te=(...e)=>r.html.span(r.attr.class(A("danger")),...e),se=e=>{const{value:t,onBlur:s,onChange:n,placeholder:a,disabled:i,id:o,checkedIcon:l,uncheckedIcon:c,iconSize:f="lg"}=e,u=o??I("checkbox"),b=`${u}-label`,y=()=>{if(r.Value.get(i??!1))return;const h=r.Value.get(t);n?.(!h)},k=h=>{r.Value.get(i??!1)||(h.key===" "||h.key==="Enter")&&(h.preventDefault(),y())};return V.InputContainer({baseContainer:!0,growInput:!1,...e,input:r.html.span(r.attr.class("bc-checkbox-input"),r.html.span(r.attr.class("bc-checkbox-input__checkbox"),r.attr.class(r.Value.map(t,h=>h?"bc-checkbox-input__checkbox--checked":"bc-checkbox-input__checkbox--unchecked")),r.attr.class(r.Value.map(i??!1,h=>h?"bc-checkbox-input__checkbox--disabled":"")),r.attr.id(u),r.attr.role("checkbox"),r.attr.tabindex(r.Value.map(i??!1,h=>h?-1:0)),r.aria.checked(t),r.aria.disabled(i),a!=null?r.aria.labelledby(b):r.Empty,r.on.keydown(k),s!=null?r.on.blur(s):r.Empty,V.Icon({icon:r.computedOf(t,l,c)((h,g,w)=>h?g??"akar-icons/check-box-fill":w??"akar-icons/box"),accessibility:"decorative",size:f})),a!=null?r.html.label(r.attr.class("bc-checkbox-input__label"),r.attr.id(b),r.attr.for(u),j(a)):r.Empty)},r.on.click(y))},q=r.html.span(r.attr.class("bc-input-wrapper__required")," *");function re(e){const t=["bc-input-wrapper"];return e!=="vertical"&&t.push(`bc-input-wrapper--${e}`),t.join(" ")}function ne(e,t){const s=["bc-input-wrapper__label-text"];return e?s.push("bc-input-wrapper__label-text--error"):t?s.push("bc-input-wrapper__label-text--disabled"):s.push("bc-input-wrapper__label-text--default"),s.join(" ")}function ae(e,t){if(e==="horizontal-fixed"&&t!=null)return`--input-wrapper-label-width: ${t}`}const L=({fullWidth:e=!1,required:t,label:s,labelChildren:n,context:a,description:i,content:o,error:l,labelFor:c,hasError:f,disabled:u,layout:b,labelWidth:y},...k)=>{const h=f??l!=null,g=u??!1,w=b??"vertical",D=I("input-wrapper"),O=i?`${D}-description`:void 0,_=l!=null?`${D}-error`:void 0,N=r.computedOf(w)(v=>v!=="vertical"),Y=r.computedOf(w,y??void 0)((v,C)=>ae(v,C));return r.html.div(r.attr.class(r.Value.map(w,v=>re(v))),r.attr.class(r.Value.map(e,v=>v?"bc-input-wrapper--full-width":"")),r.attr.style(Y),s!=null||a!=null?r.html.div(r.attr.class("bc-input-wrapper__header"),r.html.div(r.attr.class("bc-input-wrapper__label-section"),r.html.label(r.attr.class("bc-input-wrapper__label"),c!=null?r.attr.for(c):r.Empty,r.html.span(r.attr.class(r.computedOf(h,g)((v,C)=>ne(v??!1,C??!1))),s),s!=null&&t?q:r.Empty),r.When(r.computedOf(N,i)((v,C)=>v&&C!=null),()=>r.html.div(r.attr.class("bc-input-wrapper__description bc-input-wrapper__description--under-label"),r.attr.id(O),i))),a!=null?$(a):r.Empty,n):r.Empty,r.html.div(r.attr.class("bc-input-wrapper__content"),[O,_].filter(Boolean).length>0?r.dataAttr.describedby([O,_].filter(Boolean).join(" ")):r.Empty,t?r.dataAttr.required("true"):r.Empty,r.When(h,()=>r.dataAttr.invalid("true")),o),r.When(r.computedOf(N,i)((v,C)=>!v&&C!=null),()=>r.html.div(r.attr.class("bc-input-wrapper__description"),r.attr.id(O),i)),r.When(h,()=>r.html.div(r.attr.class("bc-input-wrapper__error"),r.attr.id(_),r.aria.live("polite"),r.attr.role("alert"),l)),...k)};function ie(...e){return r.html.div(r.attr.class("bc-stack"),...e)}const H=(e,t)=>()=>{e.markTouched(),t?.()},M=(e,t)=>s=>{e.change(s),t?.(s)};function x(e,t){const{controller:s,onBlur:n,onChange:a,id:i,triggerOn:o,...l}=t;return e({id:i??s.name,disabled:s.disabled,value:s.signal,hasError:s.errorVisible,name:s.name,...l,onInput:o==="input"?M(s,a):void 0,onChange:o!=="input"?M(s,a):void 0,onBlur:H(s,n)})}function le(e,{id:t,labelFor:s,...n},...a){const i=t??n.controller.name??I("control"),o=s??i;return L({...n,hasError:n.controller.errorVisible,error:r.TextNode(n.controller.error.map(l=>l??"")),labelFor:o,content:x(l=>e({...l,id:i}),n)},...a)}function W(e,t){const{toInput:s,fromInput:n,controller:a,...i}=t,o=a.transform(s,n);return x(e,{...i,controller:o})}function oe(e,{id:t,labelFor:s,...n},...a){const i=t??n.controller.name??I("control");return L({...n,labelFor:s??i,content:W(e,{...n,id:i})},...a)}function ce(e){return e.split(".").map(s=>{const n=s.match(/^\[(\d+)\]$/);return n?Number(n[1]):s})}function z(e){return typeof e=="number"?`[${e}]`:`.${e}`}function U(e){if(e.length===0)return"";const[t,...s]=e;return[typeof t=="number"?`[${t}]`:t,...s.map(z)].join("")}const ue={valid:p.valid,invalid(e){return p.invalid({message:e})},invalidFields(e){const t={};for(const[s,n]of Object.entries(e))t[s]=typeof n=="string"?{message:n}:n;return p.invalid({dependencies:t})},fromError(e){return p.invalid(e)}};function T(e){return function(s){if(s.type==="valid")return s;let n=s.error;for(const a of e)if(n=n?.dependencies?.[a],n==null)return p.valid;return p.invalid(n)}}class S{path;change;signal;status;error;hasError;touched;errorVisible;dirty;dependencyErrors;#e={disabled:r.prop(!1),touched:r.prop(!1)};#s;#t=r.prop(void 0);parent;disabled;#r=[];disabledOrHasErrors;constructor(t,s,n,a,i,o=E){this.path=t,this.change=s,this.signal=n,this.status=a,this.#s=o,this.#t.set(n.value),this.error=a.map(l=>l?.type==="invalid"?l.error?.message:void 0),this.hasError=this.error.map(l=>l!=null),this.touched=this.#e.touched,i.validationMode?this.errorVisible=r.computedOf(this.hasError,this.touched,i.validationMode)((l,c,f)=>f==="eager"?!!l:!!l&&!!c):this.errorVisible=r.computedOf(this.hasError,this.touched)((l,c)=>!!l&&!!c),this.dirty=r.computedOf(this.signal,this.#t)((l,c)=>!this.#s(l,c)),this.dependencyErrors=a.map(l=>l?.type==="invalid"?l.error?.dependencies:void 0),this.parent=i,this.disabled=r.computedOf(this.#e.disabled,i.disabled)((l,c)=>l||c),this.disabledOrHasErrors=r.computedOf(this.disabled,this.hasError)((l,c)=>l||c),this.onDispose(()=>{this.#e.disabled.dispose(),this.#e.touched.dispose(),this.disabled.dispose(),this.error.dispose(),this.errorVisible.dispose(),this.dirty.dispose(),this.#t.dispose(),this.dependencyErrors.dispose(),this.disabledOrHasErrors.dispose()})}get name(){return U(this.path)}onDispose=t=>{this.#r.push(t)};dispose=()=>{for(const t of this.#r)try{t()}catch(s){console.error("Error in dispose callback:",s)}this.#r.length=0};setDisabled=t=>{this.#e.disabled.set(t)};disable=()=>this.setDisabled(!0);enable=()=>this.setDisabled(!1);markTouched=()=>{this.#e.touched.set(!0)};resetTouched=()=>{this.#e.touched.set(!1)};markPristine=()=>{this.#t.set(this.signal.value)};reset=()=>{this.change(this.#t.value)};array=(t=E)=>new K(this.path,this.change,this.signal,this.status,this.parent,t);object=(t=E)=>new R(this.path,this.change,this.signal,this.status,this.parent,t);transform=(t,s,n=[],a=E)=>new S([...this.path,...n],i=>this.change(s(i)),this.signal.map(t,a),this.status.map(T(n)),this.parent,a);asyncTransform=(t,s,n,a=[],i=E)=>new S([...this.path,...a],o=>{s(o).then(l=>this.change(l))},this.signal.mapAsync(t,n,void 0,i),this.status.map(T(a)),this.parent,i)}class R extends S{#e=new Map;#s=new Map;#t=new Map;#r=r.prop(!1);touchedDeep=this.#r;#a=new Map;#n=new Map;#l=r.prop(!1);dirtyDeep=this.#l;#c;#u;#o=()=>{let t=!1;for(const s of this.#s.values())if(s){t=!0;break}this.#r.set(this.touched.value||t)};constructor(t,s,n,a,i,o){super(t,s,n.map(c=>c??{},o),a,i,o),this.#c=this.touched.on(()=>{this.#o()}),this.#u=this.dirty.on(()=>{this.#i()});const l=this.signal.on(()=>this.#i());this.onDispose(()=>{for(const c of this.#e.values())c.dispose();this.#e.clear();for(const c of this.#t.values())c();this.#t.clear(),this.#s.clear(),this.#r.dispose();for(const c of this.#n.values())c();this.#n.clear(),this.#a.clear(),this.#l.dispose(),this.#c(),this.#u(),l()})}field=t=>{if(this.#e.has(t))return this.#e.get(t);const s=async o=>{this.change({...this.signal.value,[t]:o})},n=new S([...this.path,t],s,this.signal.map(o=>o[t]),this.status.map(T([t])),{disabled:this.disabled,validationMode:this.parent.validationMode});this.#e.set(t,n);const a=n.touched.on(o=>{this.#s.set(t,o),this.#o()});this.#t.set(t,a);const i=n.dirty.on(o=>{this.#a.set(t,o),this.#i()});return this.#n.set(t,i),n};markAllTouched=()=>{this.markTouched();const t=this.signal.value;for(const s of Object.keys(t))this.field(s).markTouched();for(const s of this.#e.values())s.markTouched()};markAllPristine=()=>{this.markPristine();const t=this.signal.value;for(const s of Object.keys(t))this.field(s).markPristine?.();for(const s of this.#e.values())s.markPristine?.()};#i=()=>{let t=!1;for(const s of this.#a.values())if(s){t=!0;break}this.#l.set(this.dirty.value||t)}}class K extends S{#e=new Array;length;#s=new Map;#t=new Map;#r=r.prop(!1);touchedDeep=this.#r;#a=new Map;#n=new Map;#l=r.prop(!1);dirtyDeep=this.#l;#c;#u;#o=()=>{let t=!1;for(const s of this.#s.values())if(s){t=!0;break}this.#r.set(this.touched.value||t)};constructor(t,s,n,a,i,o){const l=n.map(u=>u??[],o);super(t,s,l,a,i,o);const c=l.on(u=>{const b=this.#e.length-u.length;b>0&&(this.#e.splice(u.length,b).forEach((y,k)=>{const h=u.length+k;y.dispose(),this.#t.get(h)?.(),this.#t.delete(h),this.#s.delete(h),this.#n.get(h)?.(),this.#n.delete(h),this.#a.delete(h)}),this.#o(),this.#i())});this.length=l.map(u=>u.length),this.#c=this.touched.on(()=>{this.#o()}),this.#u=this.dirty.on(()=>{this.#i()});const f=this.signal.on(()=>this.#i());this.onDispose(()=>{for(const u of this.#e)u.dispose();this.length.dispose(),this.#e.length=0,c(),l.dispose();for(const u of this.#t.values())u();this.#t.clear(),this.#s.clear(),this.#r.dispose();for(const u of this.#n.values())u();this.#n.clear(),this.#a.clear(),this.#l.dispose(),this.#c(),this.#u(),f()})}item=t=>{if(this.#e[t])return this.#e[t];const s=async o=>{const l=this.signal.value.slice();l[t]=o,this.change(l)},n=new S([...this.path,t],s,this.signal.map(o=>o[t]),this.status.map(T([t])),{disabled:this.disabled,validationMode:this.parent.validationMode});this.#e[t]=n;const a=n.touched.on(o=>{this.#s.set(t,o),this.#o()});this.#t.set(t,a);const i=n.dirty.on(o=>{this.#a.set(t,o),this.#i()});return this.#n.set(t,i),n};push=(...t)=>{this.change([...this.signal.value,...t])};pop=()=>{this.splice(this.signal.value.length-1,1)};shift=()=>{this.splice(0,1)};unshift=(...t)=>{this.change([...t,...this.signal.value])};removeAt=t=>{this.splice(t,1)};splice=(t,s)=>{const n=this.signal.value.slice();n.splice(t,s),this.change(n)};move=(t,s,n=1)=>{if(n<1||t===s)return;const a=this.signal.value.slice(),i=a.splice(t,n);a.splice(s,0,...i),this.change(a)};markAllTouched=()=>{this.markTouched();const t=this.signal.value.length;for(let s=0;s<t;s++)this.item(s).markTouched()};markAllPristine=()=>{this.markPristine();const t=this.signal.value.length;for(let s=0;s<t;s++)this.item(s).markPristine?.()};#i=()=>{let t=!1;for(const s of this.#a.values())if(s){t=!0;break}this.#l.set(this.dirty.value||t)}}function G(e){function t(s){return typeof s=="number"?s:s.toString()}return e.map(s=>typeof s=="object"&&s.key!=null?t(s.key):t(s))}function J(e){const t=e.filter(a=>a.path==null||a.path.length===0).map(a=>a.message),s=e.filter(a=>a.path!=null&&a.path.length>0).reduce((a,i)=>{const o=G(i.path),l=o.pop();let c=a;for(const f of o)c.dependencies==null&&(c.dependencies={}),c.dependencies[f]==null&&(c.dependencies[f]={}),c=c.dependencies[f];return c.dependencies==null&&(c.dependencies={}),c.dependencies[l]={message:i.message},a},{}),n=t.join(`
|
|
2
|
+
`);return{...s,message:n!=""?n:void 0}}function Q({initialValue:e,onChange:t,validate:s,equals:n,validationMode:a,validateDebounceMs:i}){const o=r.Value.deriveProp(e),l=r.prop(p.valid),c=r.prop(!1),f=r.prop(a??"onTouched"),u=g=>{l.set(g)};let b;const y=async g=>{if(s!=null){const w=await s(g);u(w)}},k=async g=>{o.set(g),t?.(g);const w=f.value;if(s!=null){if(w==="onSubmit")return;const D=i??0;D>0?(b&&clearTimeout(b),b=setTimeout(()=>{y(g)},D)):await y(g)}},h=new S([],k,o,l,{disabled:c,validationMode:f},n??E);return h.onDispose(()=>{c.dispose(),o.dispose(),l.dispose(),f.dispose(),b&&clearTimeout(b)}),{controller:h,setStatus:u}}function B(e){return r.Fragment(r.attr.disabled(e.disabled),r.attr.name(e.name))}function he(e,{triggerOn:t="change"}={}){return r.Fragment(B(e),r.attr.value(e.signal),(t==="input"?r.on.input:r.on.change)(r.emitValue(e.change)))}function de(e,{triggerOn:t="change"}={}){return r.Fragment(B(e),r.attr.valueAsNumber(e.signal),(t==="input"?r.on.input:r.on.change)(r.emitValueAsNumber(e.change)))}function F(e){return e.issues!=null?p.invalid(J(e.issues)):p.valid}async function pe({task:e,errorMessage:t,errorPath:s=["root"],validation:n}){try{const a=await e();return n!=null?n(a):p.valid}catch(a){const i=t??(a instanceof Error?a.message:"Operation failed");return s.length===1&&s[0]==="root"?p.invalid({message:i}):p.invalid({dependencies:X(s,i)})}}function X(e,t){if(e.length===1)return{[e[0]]:{message:t}};const[s,...n]=e;return{[s]:{dependencies:X(n,t)}}}function fe({initialValue:e={},schema:t,onSubmit:s=async()=>p.valid,validationMode:n,validateDebounceMs:a}){const{controller:i,setStatus:o}=Q({initialValue:e,validationMode:n??"onTouched",validateDebounceMs:a,validate:(n??"onTouched")==="onSubmit"||t==null?void 0:async u=>F(await t["~standard"].validate(u))}),l=r.prop(!1),c=i.object();return c.onDispose(l.dispose),{controller:c,setStatus:o,submit:async u=>{if(l.set(!0),u?.preventDefault(),c.markAllTouched(),t!=null){const y=c.signal.value,k=F(await t["~standard"].validate(y));if(o(k),k.type==="invalid"){l.set(!1);return}}const b=await s(c.signal.value);l.set(!1),b.type==="invalid"&&o(b)},submitting:l}}exports.ArrayController=K;exports.BaseControl=x;exports.BaseMappedControl=W;exports.CheckboxInput=se;exports.CloseButton=Z;exports.Control=le;exports.Controller=S;exports.ControllerValidation=ue;exports.DangerLabel=te;exports.EmphasisLabel=ee;exports.InputWrapper=L;exports.Label=$;exports.MappedControl=oe;exports.MutedLabel=j;exports.O=E;exports.ObjectController=R;exports.RequiredSymbol=q;exports.Stack=ie;exports.a=p;exports.connectCommonAttributes=B;exports.connectNumberInput=de;exports.connectStringInput=he;exports.convertStandardSchemaIssues=J;exports.convertStandardSchemaPathToPath=G;exports.makeMapValidation=T;exports.makeOnBlurHandler=H;exports.makeOnChangeHandler=M;exports.parsePath=ce;exports.pathToString=U;exports.sessionId=I;exports.standardSchemaResultToValidation=F;exports.taskToValidation=pe;exports.useController=Q;exports.useForm=fe;exports.wrapSegment=z;
|