@tachui/forms 0.8.0-alpha → 0.8.5-alpha

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 (42) hide show
  1. package/dist/DatePicker-D5nRFTUm.js +0 -1
  2. package/dist/Select-yZyKooXk.js +0 -1
  3. package/dist/Slider-0-oal5YR.js +0 -1
  4. package/dist/TextField-hX15dY3U.js +0 -1
  5. package/dist/components/advanced/index.js +0 -1
  6. package/dist/components/date-picker/index.js +0 -1
  7. package/dist/components/selection/index.js +0 -1
  8. package/dist/components/text-input/index.js +0 -1
  9. package/dist/index-D3WfkqVv.js +0 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +21 -17
  13. package/dist/modifiers/index.d.ts +11 -0
  14. package/dist/modifiers/index.d.ts.map +1 -0
  15. package/dist/modifiers/index.js +162 -0
  16. package/dist/modifiers/placeholder.d.ts +8 -0
  17. package/dist/modifiers/placeholder.d.ts.map +1 -0
  18. package/dist/modifiers/required.d.ts +10 -0
  19. package/dist/modifiers/required.d.ts.map +1 -0
  20. package/dist/modifiers/validation.d.ts +8 -0
  21. package/dist/modifiers/validation.d.ts.map +1 -0
  22. package/dist/validation/index.js +0 -1
  23. package/dist/version.d.ts +8 -0
  24. package/dist/version.d.ts.map +1 -0
  25. package/package.json +12 -3
  26. package/src/index.ts +8 -0
  27. package/src/modifiers/index.ts +70 -0
  28. package/src/modifiers/placeholder.ts +95 -0
  29. package/src/modifiers/required.ts +105 -0
  30. package/src/modifiers/validation.ts +138 -0
  31. package/src/version.ts +10 -0
  32. package/dist/DatePicker-D5nRFTUm.js.map +0 -1
  33. package/dist/Select-yZyKooXk.js.map +0 -1
  34. package/dist/Slider-0-oal5YR.js.map +0 -1
  35. package/dist/TextField-hX15dY3U.js.map +0 -1
  36. package/dist/components/advanced/index.js.map +0 -1
  37. package/dist/components/date-picker/index.js.map +0 -1
  38. package/dist/components/selection/index.js.map +0 -1
  39. package/dist/components/text-input/index.js.map +0 -1
  40. package/dist/index-D3WfkqVv.js.map +0 -1
  41. package/dist/index.js.map +0 -1
  42. package/dist/validation/index.js.map +0 -1
@@ -472,4 +472,3 @@ function w(D) {
472
472
  export {
473
473
  w as D
474
474
  };
475
- //# sourceMappingURL=DatePicker-D5nRFTUm.js.map
@@ -942,4 +942,3 @@ export {
942
942
  ue as c,
943
943
  U as d
944
944
  };
945
- //# sourceMappingURL=Select-yZyKooXk.js.map
@@ -641,4 +641,3 @@ export {
641
641
  k as S,
642
642
  w as a
643
643
  };
644
- //# sourceMappingURL=Slider-0-oal5YR.js.map
@@ -506,4 +506,3 @@ export {
506
506
  Be as e,
507
507
  Ie as f
508
508
  };
509
- //# sourceMappingURL=TextField-hX15dY3U.js.map
@@ -3,4 +3,3 @@ export {
3
3
  a as Slider,
4
4
  p as Stepper
5
5
  };
6
- //# sourceMappingURL=index.js.map
@@ -2,4 +2,3 @@ import { D as a } from "../../DatePicker-D5nRFTUm.js";
2
2
  export {
3
3
  a as DatePicker
4
4
  };
5
- //# sourceMappingURL=index.js.map
@@ -9,4 +9,3 @@ export {
9
9
  r as Select,
10
10
  x as Switch
11
11
  };
12
- //# sourceMappingURL=index.js.map
@@ -15,4 +15,3 @@ export {
15
15
  T as TimeField,
16
16
  x as URLField
17
17
  };
18
- //# sourceMappingURL=index.js.map
@@ -246,4 +246,3 @@ export {
246
246
  D as b,
247
247
  $ as c
248
248
  };
249
- //# sourceMappingURL=index-D3WfkqVv.js.map
package/dist/index.d.ts CHANGED
@@ -12,5 +12,6 @@ export * from './components/date-picker';
12
12
  export * from './state';
13
13
  export * from './validation';
14
14
  export * from './utils';
15
+ export { placeholder, required, validation, registerFormsModifiers, } from './modifiers';
15
16
  export type { ValidationRule, ValidationResult, FieldValidation, FieldState, TextFieldProps, NumberFieldProps, TextFieldFormatter, TextFieldParser, AutoCapitalization, KeyboardType, ReturnKeyType, } from './types';
16
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,6BAA6B,CAAA;AAG3C,cAAc,yBAAyB,CAAA;AAGvC,cAAc,wBAAwB,CAAA;AAGtC,cAAc,uBAAuB,CAAA;AAGrC,cAAc,0BAA0B,CAAA;AAGxC,cAAc,SAAS,CAAA;AAGvB,cAAc,cAAc,CAAA;AAG5B,cAAc,SAAS,CAAA;AAGvB,YAAY,EAEV,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,UAAU,EAGV,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,aAAa,GACd,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,6BAA6B,CAAA;AAG3C,cAAc,yBAAyB,CAAA;AAGvC,cAAc,wBAAwB,CAAA;AAGtC,cAAc,uBAAuB,CAAA;AAGrC,cAAc,0BAA0B,CAAA;AAGxC,cAAc,SAAS,CAAA;AAGvB,cAAc,cAAc,CAAA;AAG5B,cAAc,SAAS,CAAA;AAGvB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,UAAU,EACV,sBAAsB,GACvB,MAAM,aAAa,CAAA;AAGpB,YAAY,EAEV,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,UAAU,EAGV,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,aAAa,GACd,MAAM,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -1,14 +1,15 @@
1
- import { createSignal as n, createComputed as a } from "@tachui/core";
2
- import { c as o } from "./index-D3WfkqVv.js";
1
+ import { createSignal as o, createComputed as a } from "@tachui/core";
2
+ import { c as n } from "./index-D3WfkqVv.js";
3
3
  import { a as N, b as T } from "./index-D3WfkqVv.js";
4
4
  import { f as D, C as M, D as w, E as A, N as L, P, a as R, c as $, b as k, S as O, d as U, T as H, e as I, U as z } from "./TextField-hX15dY3U.js";
5
- import { C as _, a as j, c as Z, M as q, R as B, b as J, d as K, S as Q } from "./Select-yZyKooXk.js";
5
+ import { C as _, a as j, c as q, M as Z, R as B, b as J, d as K, S as Q } from "./Select-yZyKooXk.js";
6
6
  import { a as X, S as Y } from "./Slider-0-oal5YR.js";
7
7
  import { D as te } from "./DatePicker-D5nRFTUm.js";
8
- import { CrossFieldValidators as ie, FormsComponentValidation as se, FormsValidationError as ae, VALIDATION_RULES as ne, ValidationMessageFormatter as oe, ValidationPresets as de, ValidationUtils as pe, createDebouncedValidator as le, createFormsValidators as ce, defaultMessageFormatter as fe, getValidationRules as me, registerFormsValidators as he, registerValidationRule as ue, unregisterValidationRule as Se, validateField as xe, validateValue as ge, validateValueAsync as Ce } from "./validation/index.js";
8
+ import { CrossFieldValidators as ie, FormsComponentValidation as se, FormsValidationError as ae, VALIDATION_RULES as oe, ValidationMessageFormatter as ne, ValidationPresets as de, ValidationUtils as pe, createDebouncedValidator as le, createFormsValidators as ce, defaultMessageFormatter as fe, getValidationRules as me, registerFormsValidators as he, registerValidationRule as ue, unregisterValidationRule as Se, validateField as xe, validateValue as ge, validateValueAsync as Fe } from "./validation/index.js";
9
+ import { placeholder as Ee, registerFormsModifiers as ye, required as Ve, validation as be } from "./modifiers/index.js";
9
10
  class d {
10
11
  constructor(e) {
11
- this.properties = e, this.formState = o(e.initialValues || {}), e.validation && Object.entries(e.validation).forEach(
12
+ this.properties = e, this.formState = n(e.initialValues || {}), e.validation && Object.entries(e.validation).forEach(
12
13
  ([t, r]) => {
13
14
  this.formState.register(t, r);
14
15
  }
@@ -58,7 +59,7 @@ class d {
58
59
  class p {
59
60
  constructor(e) {
60
61
  this.properties = e;
61
- const [t, r] = n(
62
+ const [t, r] = o(
62
63
  e.defaultExpanded ?? !0
63
64
  );
64
65
  this.expanded = t, this.setExpanded = r;
@@ -128,10 +129,10 @@ function x(i) {
128
129
  function g(i) {
129
130
  return i.replace(/\D/g, "").replace(/(\d{3})(\d{2})(\d{4})/, "$1-$2-$3");
130
131
  }
131
- function C(i) {
132
+ function F(i) {
132
133
  return i.toUpperCase().replace(/[^A-Z0-9]/g, "");
133
134
  }
134
- function F(i, e = "yyyy-MM-dd") {
135
+ function C(i, e = "yyyy-MM-dd") {
135
136
  return i.toISOString().split("T")[0];
136
137
  }
137
138
  function E(i) {
@@ -144,7 +145,7 @@ export {
144
145
  _ as Checkbox,
145
146
  j as CheckboxGroup,
146
147
  D as ColorField,
147
- Z as Combobox,
148
+ q as Combobox,
148
149
  M as CreditCardField,
149
150
  ie as CrossFieldValidators,
150
151
  w as DateField,
@@ -154,7 +155,7 @@ export {
154
155
  p as FormSection,
155
156
  se as FormsComponentValidation,
156
157
  ae as FormsValidationError,
157
- q as MultiSelect,
158
+ Z as MultiSelect,
158
159
  L as NumberField,
159
160
  P as PasswordField,
160
161
  R as PhoneField,
@@ -171,33 +172,36 @@ export {
171
172
  H as TextField,
172
173
  I as TimeField,
173
174
  z as URLField,
174
- ne as VALIDATION_RULES,
175
- oe as ValidationMessageFormatter,
175
+ oe as VALIDATION_RULES,
176
+ ne as ValidationMessageFormatter,
176
177
  de as ValidationPresets,
177
178
  pe as ValidationUtils,
178
179
  le as createDebouncedValidator,
179
180
  N as createField,
180
- o as createFormState,
181
+ n as createFormState,
181
182
  ce as createFormsValidators,
182
183
  T as createMultiStepFormState,
183
184
  fe as defaultMessageFormatter,
184
185
  f as form,
185
186
  m as formSection,
186
187
  S as formatCreditCard,
187
- F as formatDate,
188
+ C as formatDate,
188
189
  x as formatPhoneNumber,
189
- C as formatPostalCode,
190
+ F as formatPostalCode,
190
191
  g as formatSSN,
191
192
  me as getValidationRules,
192
193
  y as isValidDate,
193
194
  E as parseDate,
195
+ Ee as placeholder,
196
+ ye as registerFormsModifiers,
194
197
  he as registerFormsValidators,
195
198
  ue as registerValidationRule,
199
+ Ve as required,
196
200
  Se as unregisterValidationRule,
197
201
  h as useFormState,
198
202
  u as useFormValidation,
199
203
  xe as validateField,
200
204
  ge as validateValue,
201
- Ce as validateValueAsync
205
+ Fe as validateValueAsync,
206
+ be as validation
202
207
  };
203
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ import type { ModifierRegistry, PluginInfo } from '@tachui/registry';
2
+ export interface RegisterFormsModifiersOptions {
3
+ registry?: ModifierRegistry;
4
+ plugin?: PluginInfo;
5
+ force?: boolean;
6
+ }
7
+ export declare function registerFormsModifiers(options?: RegisterFormsModifiersOptions): void;
8
+ export { validation, } from './validation';
9
+ export { placeholder, } from './placeholder';
10
+ export { required, } from './required';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/modifiers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AA0BpE,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,EAAE,gBAAgB,CAAA;IAC3B,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,wBAAgB,sBAAsB,CACpC,OAAO,CAAC,EAAE,6BAA6B,GACtC,IAAI,CAiBN;AAID,OAAO,EACL,UAAU,GACX,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,QAAQ,GACT,MAAM,YAAY,CAAA"}
@@ -0,0 +1,162 @@
1
+ import { registerModifierWithMetadata as s } from "@tachui/core/modifiers";
2
+ import { validateValue as h } from "../validation/index.js";
3
+ import { isSignal as T } from "@tachui/core";
4
+ const l = 74, c = /* @__PURE__ */ new WeakMap();
5
+ function p(t) {
6
+ const e = [];
7
+ return t.forEach((r) => {
8
+ Array.isArray(r) ? e.push(...r) : e.push(r);
9
+ }), e;
10
+ }
11
+ function m(t, e) {
12
+ t instanceof HTMLElement && ((t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement) && t.setCustomValidity(e.valid ? "" : e.message ?? "Invalid value"), e.valid ? (t.removeAttribute("aria-invalid"), t.classList.remove("tachui-invalid"), t.removeAttribute("data-validation-message")) : (t.setAttribute("aria-invalid", "true"), t.classList.add("tachui-invalid"), e.message && t.setAttribute("data-validation-message", e.message)));
13
+ }
14
+ function L(t, e) {
15
+ return () => {
16
+ const r = t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement ? t.value : t.textContent ?? "", i = h(r, e);
17
+ m(t, i);
18
+ };
19
+ }
20
+ function g(t) {
21
+ const e = t.length ? t : ["required"];
22
+ return {
23
+ type: "forms:validation",
24
+ priority: l,
25
+ properties: { rules: e },
26
+ apply(r, i) {
27
+ const n = i.element ?? r;
28
+ if (!n) return r;
29
+ const a = L(n, e), o = c.get(n);
30
+ return o && (n.removeEventListener("blur", o), n.removeEventListener("input", o)), n.addEventListener("blur", a), n.addEventListener("input", a), c.set(n, a), a(), r;
31
+ }
32
+ };
33
+ }
34
+ const v = {
35
+ category: "interaction",
36
+ priority: l,
37
+ signature: "(...rules: ValidationRule[]) => Modifier",
38
+ description: "Attaches validation rules to form inputs, wiring blur/input handlers and ARIA state."
39
+ };
40
+ function F(...t) {
41
+ const e = p(t);
42
+ return g(e);
43
+ }
44
+ function b(t, e) {
45
+ s(
46
+ "validation",
47
+ (...i) => g(p(i)),
48
+ v,
49
+ t,
50
+ e
51
+ );
52
+ }
53
+ const A = 70;
54
+ function H(t) {
55
+ return typeof t == "function" && T(t) || typeof t == "function" ? t() : t ?? "";
56
+ }
57
+ const u = /* @__PURE__ */ new WeakMap();
58
+ function d(t, e) {
59
+ const r = H(e);
60
+ t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement ? t.placeholder = r : t instanceof HTMLElement && t.setAttribute("placeholder", r), r ? t.setAttribute("data-placeholder", r) : t.removeAttribute("data-placeholder");
61
+ }
62
+ function y(t) {
63
+ return {
64
+ type: "forms:placeholder",
65
+ priority: A,
66
+ properties: { value: t },
67
+ apply(e, r) {
68
+ const i = r.element ?? e;
69
+ if (!i)
70
+ return e;
71
+ d(i, t);
72
+ const a = u.get(i);
73
+ a && i.removeEventListener("input", a);
74
+ const o = () => d(i, t);
75
+ return i.addEventListener("input", o), u.set(i, o), e;
76
+ }
77
+ };
78
+ }
79
+ const q = {
80
+ category: "accessibility",
81
+ priority: A,
82
+ signature: "(text: string) => Modifier",
83
+ description: "Sets placeholder text on form inputs and keeps a data attribute in sync."
84
+ };
85
+ function N(t) {
86
+ return y(t);
87
+ }
88
+ function I(t, e) {
89
+ s(
90
+ "placeholder",
91
+ (i) => y(i),
92
+ q,
93
+ t,
94
+ e
95
+ );
96
+ }
97
+ const M = 72;
98
+ function R(t) {
99
+ if (typeof t == "boolean")
100
+ return { enabled: t };
101
+ if (typeof t == "string")
102
+ return { message: t, enabled: !0 };
103
+ const e = { enabled: !0 };
104
+ return t && Object.assign(e, t), e;
105
+ }
106
+ function P(t, { enabled: e, message: r }) {
107
+ t instanceof HTMLElement && (e !== !1 ? (t.setAttribute("aria-required", "true"), t.classList.add("tachui-required"), t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement ? t.required = !0 : t.setAttribute("data-required", "true"), r && t.setAttribute("data-required-message", r)) : (t.removeAttribute("aria-required"), t.classList.remove("tachui-required"), t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement ? t.required = !1 : t.removeAttribute("data-required"), t.removeAttribute("data-required-message")));
108
+ }
109
+ function E(t) {
110
+ const e = R(t);
111
+ return {
112
+ type: "forms:required",
113
+ priority: M,
114
+ properties: e,
115
+ apply(r, i) {
116
+ const n = i.element ?? r;
117
+ return n && P(n, e), r;
118
+ }
119
+ };
120
+ }
121
+ const x = {
122
+ category: "accessibility",
123
+ priority: M,
124
+ signature: "(options?: boolean | string | { message?: string }) => Modifier",
125
+ description: "Marks form inputs as required, wiring ARIA attributes and optional custom messaging."
126
+ };
127
+ function U(t) {
128
+ return E(t);
129
+ }
130
+ function V(t, e) {
131
+ s(
132
+ "required",
133
+ (i) => E(i),
134
+ x,
135
+ t,
136
+ e
137
+ );
138
+ }
139
+ const S = "0.8.0-alpha", O = S, _ = {
140
+ name: "@tachui/forms",
141
+ version: O,
142
+ author: "TachUI Team",
143
+ verified: !0
144
+ }, z = [
145
+ b,
146
+ I,
147
+ V
148
+ ];
149
+ let f = !1;
150
+ function C(t) {
151
+ const e = t?.registry, r = t?.plugin ?? _, i = t?.force === !0, n = !!(e || t?.plugin);
152
+ !n && f && !i || (z.forEach(
153
+ (a) => a(e, r)
154
+ ), n || (f = !0));
155
+ }
156
+ C();
157
+ export {
158
+ N as placeholder,
159
+ C as registerFormsModifiers,
160
+ U as required,
161
+ F as validation
162
+ };
@@ -0,0 +1,8 @@
1
+ import type { Signal } from '@tachui/core';
2
+ import type { Modifier } from '@tachui/core/modifiers/types';
3
+ import type { ModifierRegistry, PluginInfo } from '@tachui/registry';
4
+ type PlaceholderValue = string | Signal<string>;
5
+ export declare function placeholder(value: PlaceholderValue): Modifier;
6
+ export declare function registerPlaceholderModifier(registry?: ModifierRegistry, plugin?: PluginInfo): void;
7
+ export {};
8
+ //# sourceMappingURL=placeholder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placeholder.d.ts","sourceRoot":"","sources":["../../src/modifiers/placeholder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EACV,QAAQ,EAET,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAKpE,KAAK,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;AAmE/C,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,QAAQ,CAE7D;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,CAAC,EAAE,gBAAgB,EAC3B,MAAM,CAAC,EAAE,UAAU,GAClB,IAAI,CASN"}
@@ -0,0 +1,10 @@
1
+ import type { Modifier } from '@tachui/core/modifiers/types';
2
+ import type { ModifierRegistry, PluginInfo } from '@tachui/registry';
3
+ interface RequiredModifierOptions {
4
+ message?: string;
5
+ enabled?: boolean;
6
+ }
7
+ export declare function required(options?: boolean | string | RequiredModifierOptions): Modifier;
8
+ export declare function registerRequiredModifier(registry?: ModifierRegistry, plugin?: PluginInfo): void;
9
+ export {};
10
+ //# sourceMappingURL=required.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"required.d.ts","sourceRoot":"","sources":["../../src/modifiers/required.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,8BAA8B,CAAA;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAKpE,UAAU,uBAAuB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AA2ED,wBAAgB,QAAQ,CACtB,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,uBAAuB,GACnD,QAAQ,CAEV;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,CAAC,EAAE,gBAAgB,EAC3B,MAAM,CAAC,EAAE,UAAU,GAClB,IAAI,CAWN"}
@@ -0,0 +1,8 @@
1
+ import type { Modifier } from '@tachui/core/modifiers/types';
2
+ import type { ModifierRegistry, PluginInfo } from '@tachui/registry';
3
+ import type { ValidationRule } from '../types';
4
+ type ValidationArgs = ValidationRule[] | ValidationRule;
5
+ export declare function validation(...rules: ValidationArgs[]): Modifier;
6
+ export declare function registerValidationModifier(registry?: ModifierRegistry, plugin?: PluginInfo): void;
7
+ export {};
8
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/modifiers/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,8BAA8B,CAAA;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAGpE,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,UAAU,CAAA;AAIhE,KAAK,cAAc,GACf,cAAc,EAAE,GAChB,cAAc,CAAA;AA0GlB,wBAAgB,UAAU,CACxB,GAAG,KAAK,EAAE,cAAc,EAAE,GACzB,QAAQ,CAGV;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,CAAC,EAAE,gBAAgB,EAC3B,MAAM,CAAC,EAAE,UAAU,GAClB,IAAI,CAWN"}
@@ -688,4 +688,3 @@ export {
688
688
  u as validateValue,
689
689
  f as validateValueAsync
690
690
  };
691
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Package Information
3
+ *
4
+ * Provides consistent package name and version exports for @tachui/forms.
5
+ */
6
+ export declare const TACHUI_PACKAGE: any;
7
+ export declare const TACHUI_PACKAGE_VERSION: any;
8
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,eAAO,MAAM,cAAc,KAA4B,CAAA;AACvD,eAAO,MAAM,sBAAsB,KAA+B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachui/forms",
3
- "version": "0.8.0-alpha",
3
+ "version": "0.8.5-alpha",
4
4
  "description": "Unified form components and validation system for tachUI (formerly @tachui/forms + @tachui/advanced-forms)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -35,10 +35,14 @@
35
35
  "./validation": {
36
36
  "types": "./dist/validation/index.d.ts",
37
37
  "import": "./dist/validation/index.js"
38
+ },
39
+ "./modifiers": {
40
+ "types": "./dist/modifiers/index.d.ts",
41
+ "import": "./dist/modifiers/index.js"
38
42
  }
39
43
  },
40
44
  "peerDependencies": {
41
- "@tachui/core": "0.8.0-alpha"
45
+ "@tachui/core": "0.8.5-alpha"
42
46
  },
43
47
  "devDependencies": {
44
48
  "@types/node": "^20.10.0",
@@ -62,11 +66,16 @@
62
66
  "directory": "packages/forms"
63
67
  },
64
68
  "dependencies": {
65
- "@tachui/primitives": "0.8.0-alpha"
69
+ "@tachui/core": "0.8.5-alpha",
70
+ "@tachui/primitives": "0.8.5-alpha",
71
+ "@tachui/modifiers": "0.8.5-alpha",
72
+ "@tachui/registry": "0.8.5-alpha"
66
73
  },
67
74
  "scripts": {
68
75
  "dev": "vite build --watch --mode development",
69
76
  "build": "vite build && pnpm build:types",
77
+ "build:dev": "vite build --mode development && pnpm build:types",
78
+ "build:prod": "vite build --mode production && pnpm build:types",
70
79
  "build:types": "tsc --project tsconfig.build.json",
71
80
  "valid": "clear && vitest run && pnpm type-check && pnpm lint && pnpm build",
72
81
  "test": "vitest --run",
package/src/index.ts CHANGED
@@ -29,6 +29,14 @@ export * from './validation'
29
29
  // Utilities and Helpers
30
30
  export * from './utils'
31
31
 
32
+ // Modifiers
33
+ export {
34
+ placeholder,
35
+ required,
36
+ validation,
37
+ registerFormsModifiers,
38
+ } from './modifiers'
39
+
32
40
  // Export specific types to avoid conflicts
33
41
  export type {
34
42
  // Core form types
@@ -0,0 +1,70 @@
1
+ import type { ModifierRegistry, PluginInfo } from '@tachui/registry'
2
+ import { registerValidationModifier } from './validation'
3
+ import { registerPlaceholderModifier } from './placeholder'
4
+ import { registerRequiredModifier } from './required'
5
+ import { TACHUI_PACKAGE_VERSION } from '../version'
6
+
7
+ type FormsModifierRegistration = (
8
+ registry?: ModifierRegistry,
9
+ plugin?: PluginInfo,
10
+ ) => void
11
+
12
+ const FORMS_PLUGIN_INFO: PluginInfo = {
13
+ name: '@tachui/forms',
14
+ version: TACHUI_PACKAGE_VERSION,
15
+ author: 'TachUI Team',
16
+ verified: true,
17
+ }
18
+
19
+ const registrations: FormsModifierRegistration[] = [
20
+ registerValidationModifier,
21
+ registerPlaceholderModifier,
22
+ registerRequiredModifier,
23
+ ]
24
+
25
+ let registered = false
26
+
27
+ export interface RegisterFormsModifiersOptions {
28
+ registry?: ModifierRegistry
29
+ plugin?: PluginInfo
30
+ force?: boolean
31
+ }
32
+
33
+ export function registerFormsModifiers(
34
+ options?: RegisterFormsModifiersOptions,
35
+ ): void {
36
+ const targetRegistry = options?.registry
37
+ const targetPlugin = options?.plugin ?? FORMS_PLUGIN_INFO
38
+ const shouldForce = options?.force === true
39
+ const isCustomTarget = Boolean(targetRegistry || options?.plugin)
40
+
41
+ if (!isCustomTarget && registered && !shouldForce) {
42
+ return
43
+ }
44
+
45
+ registrations.forEach(register =>
46
+ register(targetRegistry, targetPlugin),
47
+ )
48
+
49
+ if (!isCustomTarget) {
50
+ registered = true
51
+ }
52
+ }
53
+
54
+ registerFormsModifiers()
55
+
56
+ export {
57
+ validation,
58
+ } from './validation'
59
+ export {
60
+ placeholder,
61
+ } from './placeholder'
62
+ export {
63
+ required,
64
+ } from './required'
65
+
66
+ if (typeof import.meta !== 'undefined' && (import.meta as any).hot) {
67
+ ;(import.meta as any).hot.accept(() => {
68
+ registerFormsModifiers({ force: true })
69
+ })
70
+ }
@@ -0,0 +1,95 @@
1
+ import { isSignal } from '@tachui/core'
2
+ import type { Signal } from '@tachui/core'
3
+ import type {
4
+ Modifier,
5
+ ModifierContext,
6
+ } from '@tachui/core/modifiers/types'
7
+ import type { ModifierRegistry, PluginInfo } from '@tachui/registry'
8
+ import { registerModifierWithMetadata } from '@tachui/core/modifiers'
9
+
10
+ const placeholderPriority = 70
11
+
12
+ type PlaceholderValue = string | Signal<string>
13
+
14
+ function resolvePlaceholder(value: PlaceholderValue): string {
15
+ if (typeof value === 'function' && isSignal(value)) {
16
+ return value()
17
+ }
18
+ if (typeof value === 'function') {
19
+ return (value as () => string)()
20
+ }
21
+ return value ?? ''
22
+ }
23
+
24
+ const placeholderHandlers = new WeakMap<Element, () => void>()
25
+
26
+ function applyPlaceholder(
27
+ element: Element,
28
+ value: PlaceholderValue,
29
+ ): void {
30
+ const resolved = resolvePlaceholder(value)
31
+ if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement) {
32
+ element.placeholder = resolved
33
+ } else if (element instanceof HTMLElement) {
34
+ element.setAttribute('placeholder', resolved)
35
+ }
36
+ if (resolved) {
37
+ element.setAttribute('data-placeholder', resolved)
38
+ } else {
39
+ element.removeAttribute('data-placeholder')
40
+ }
41
+ }
42
+
43
+ function createPlaceholderModifier(value: PlaceholderValue): Modifier {
44
+ return {
45
+ type: 'forms:placeholder',
46
+ priority: placeholderPriority,
47
+ properties: { value },
48
+ apply(node: any, context: ModifierContext) {
49
+ const element = (context.element ?? node) as Element | undefined
50
+ if (!element) {
51
+ return node
52
+ }
53
+
54
+ const update = () => applyPlaceholder(element, value)
55
+ update()
56
+
57
+ const previous = placeholderHandlers.get(element)
58
+ if (previous) {
59
+ element.removeEventListener('input', previous)
60
+ }
61
+
62
+ const handler = () => applyPlaceholder(element, value)
63
+ element.addEventListener('input', handler)
64
+ placeholderHandlers.set(element, handler)
65
+
66
+ return node
67
+ },
68
+ }
69
+ }
70
+
71
+ const PLACEHOLDER_METADATA = {
72
+ category: 'accessibility' as const,
73
+ priority: placeholderPriority,
74
+ signature: '(text: string) => Modifier',
75
+ description:
76
+ 'Sets placeholder text on form inputs and keeps a data attribute in sync.',
77
+ }
78
+
79
+ export function placeholder(value: PlaceholderValue): Modifier {
80
+ return createPlaceholderModifier(value)
81
+ }
82
+
83
+ export function registerPlaceholderModifier(
84
+ registry?: ModifierRegistry,
85
+ plugin?: PluginInfo,
86
+ ): void {
87
+ const factory = (value: PlaceholderValue) => createPlaceholderModifier(value)
88
+ registerModifierWithMetadata(
89
+ 'placeholder',
90
+ factory,
91
+ PLACEHOLDER_METADATA,
92
+ registry,
93
+ plugin,
94
+ )
95
+ }