@t007/input 0.0.32 → 0.0.33

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/index.d.ts CHANGED
@@ -1,5 +1,73 @@
1
- import "@t007/utils";
2
- import { t007InputElement, BaseProps, CheckboxInputAddon, DateInputAddon, FileInputAddon, SelectElementAddon } from "../react";
1
+ import React from 'react';
2
+
3
+ /** Browser date-like input types supported by input field helpers. */
4
+ declare const dateTypes = ["date", "time", "datetime-local", "month"] as const;
5
+
6
+ /** Has native icon browser input types supported by input field helpers. */
7
+ declare const nativeIconTypes = [...dateTypes];
8
+
9
+ /** Union type for all input elements */
10
+ type t007InputElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
11
+
12
+ /** Define all possible `ValidityState` keys mapped to string messages */
13
+ interface HelperTextMap extends Partial<Record<keyof ValidityState, string>> {
14
+ /** Informational helper text shown when there is no validation violation. */
15
+ info?: string;
16
+ }
17
+
18
+ interface BaseProps {
19
+ /** Wrap the field in its own container. */
20
+ isWrapper?: boolean;
21
+ /** Visible label text. */
22
+ label?: React.ReactNode;
23
+ /** Custom tokens for feature presets. */
24
+ custom?: "confirm_password" | "password" | "onward_date" | "past_date";
25
+ /** Class applied to the root field control. */
26
+ fieldClassName?: string;
27
+ /** Helper text shown under the field. */
28
+ helperText?: HelperTextMap | boolean;
29
+ /** External resolver error text. When provided, the field is forced into error visuals even without native validity violations. */
30
+ error?: string;
31
+ /** Start icon rendered inside the field control. */
32
+ // startIcon?: React.ReactNode;
33
+ /** End icon rendered inside the field control. */
34
+ endIcon?: React.ReactNode;
35
+ // onFlagError?: (args: { violation: keyof ValidityState | null; helper: string }) => void;
36
+ /** Whether to activate bleeding edge CSS styles that augment native styles for input types, e.g. file, color, select, e.t.c */
37
+ bleedingEdge?: boolean;
38
+ }
39
+ interface FileInputAddon {
40
+ type: "file";
41
+ /** Maximum value length or count. */
42
+ maxSize?: number;
43
+ /** Minimum value length or count. */
44
+ minSize?: number;
45
+ /** Maximum total size allowed across the field value. */
46
+ maxTotalSize?: number;
47
+ /** Minimum total size allowed across the field value. */
48
+ minTotalSize?: number;
49
+ }
50
+ interface CheckboxInputAddon {
51
+ type: "checkbox";
52
+ /** Whether the checkbox is a multi-state checkbox. */
53
+ indeterminate?: boolean;
54
+ }
55
+ interface DateInputAddon {
56
+ type: DateType;
57
+ /** Native icon rendered by the browser control. */
58
+ nativeIcon?: React.ReactNode;
59
+ }
60
+ interface SelectElementAddon {
61
+ type: "select";
62
+ /** Options used by select-like fields. */
63
+ options?: string[] | readonly string[] | Array<{ value: string; option: string }>;
64
+ }
65
+
66
+ /** Union of all supported native date-like input types. */
67
+ type DateType = (typeof dateTypes)[number];
68
+
69
+ /** Union of all supported inputs with native icons types. */
70
+ type NativeIconType = (typeof nativeIconTypes)[number];
3
71
 
4
72
  interface BaseOptions extends Omit<BaseProps, "error"> {
5
73
  /** Visible label text. */
@@ -8,20 +76,20 @@ interface BaseOptions extends Omit<BaseProps, "error"> {
8
76
  children?: HTMLElement;
9
77
  }
10
78
  type InputAttrs = Partial<Omit<HTMLInputElement, "type" | "children">>;
11
- type SelectAttrs = Partial<Omit<HTMLSelectElement, "type" | "children">>;
79
+ type SelectAttrs = Partial<Omit<HTMLSelectElement, "type" | "children" | "options">>;
12
80
  type TextareaAttrs = Partial<Omit<HTMLTextAreaElement, "type" | "children">>;
13
81
  type PasswordFieldOptions = BaseOptions & InputAttrs & Omit<FileInputAddon, "passwordVisibleIcon" | "passwordHiddenIcon"> & { passwordVisibleIcon?: HTMLElement; passwordHiddenIcon?: HTMLElement };
14
82
  type FileFieldOptions = BaseOptions & InputAttrs & FileInputAddon;
15
83
  type CheckboxFieldOptions = BaseOptions & InputAttrs & CheckboxInputAddon;
16
84
  type DateFieldOptions = BaseOptions & InputAttrs & DateInputAddon;
17
- type GenericFieldOptions = BaseOptions & InputAttrs & { type?: Exclude<HTMLInputElement["type"], "password" | "file" | "checkbox" | NativeType> };
85
+ type GenericFieldOptions = BaseOptions & InputAttrs & { type?: Exclude<HTMLInputElement["type"], "password" | "file" | "checkbox" | DateType> };
18
86
  type TextareaFieldOptions = BaseOptions & TextareaAttrs & { type: "textarea" };
19
87
  type SelectFieldOptions = BaseOptions & SelectAttrs & SelectElementAddon;
20
88
  /** Configuration accepted by the field() helper. */
21
- export type FieldOptions = PasswordFieldOptions | FileFieldOptions | CheckboxFieldOptions | DateFieldOptions | GenericFieldOptions | TextareaFieldOptions | SelectFieldOptions;
89
+ type FieldOptions = PasswordFieldOptions | FileFieldOptions | CheckboxFieldOptions | DateFieldOptions | GenericFieldOptions | TextareaFieldOptions | SelectFieldOptions;
22
90
 
23
91
  /** Form-level manager used to build and validate inputs. */
24
- export interface FormManager {
92
+ interface FormManager {
25
93
  /** Live collection of managed forms. */
26
94
  forms: HTMLCollectionOf<HTMLFormElement>;
27
95
  /** Current validation violation keys. */
@@ -80,16 +148,16 @@ export interface FormManager {
80
148
  // BUNDLE EXPORTS & GLOBAL DECLARATIONS
81
149
 
82
150
  /** Shared field manager singleton exposed by the bundle. */
83
- export const formManager: FormManager;
151
+ declare const formManager: FormManager;
84
152
  /** Create a field element from field options.
85
153
  * @param options Field configuration.
86
154
  * @returns Created field element.
87
155
  */
88
- export const field: FormManager["field"];
156
+ declare const field: FormManager["field"];
89
157
  /** Attach validation hooks to a form element.
90
158
  * @param form Form element to validate.
91
159
  */
92
- export const handleFormValidation: FormManager["handleFormValidation"];
160
+ declare const handleFormValidation: FormManager["handleFormValidation"];
93
161
 
94
162
  declare global {
95
163
  interface T007Namespace {
@@ -117,3 +185,5 @@ declare global {
117
185
  toggleGlobalError?(bool: boolean): void;
118
186
  }
119
187
  }
188
+
189
+ export { type DateType, type FieldOptions, type FormManager, type NativeIconType, field, formManager, handleFormValidation };
@@ -1,50 +1,40 @@
1
1
  "use strict";
2
2
  (() => {
3
- // ../../../sia-reactor/dist/chunk-243U74PP.js
3
+ // ../../../sia-reactor/dist/chunk-ORK3EGB6.js
4
4
  function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
5
5
  return assignEl(el, props, dataset, styles);
6
6
  }
7
- function assignEl(el, props, dataset, styles) {
7
+ function assignEl(el, props, dataset, styles, nodiff = true) {
8
8
  if (!el) return null;
9
9
  if (props) {
10
- for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
10
+ for (const k of Object.keys(props)) if (props[k] !== void 0) {
11
+ if (nodiff || el[k] !== props[k]) el[k] = props[k];
12
+ }
11
13
  }
12
14
  if (dataset) {
13
- for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
15
+ for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) {
16
+ if (nodiff || el.dataset[k] !== dataset[k]) el.dataset[k] = String(dataset[k]);
17
+ }
14
18
  }
15
19
  if (styles) {
16
- for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
20
+ for (const k of Object.keys(styles)) if (styles[k] !== void 0) {
21
+ if (nodiff || el.style[k] !== styles[k]) el.style[k] = styles[k];
22
+ }
17
23
  }
18
24
  return el;
19
25
  }
20
26
 
21
- // ../../../sia-reactor/dist/chunk-2ZYYYSZ4.js
27
+ // ../../../sia-reactor/dist/chunk-SHWIAQD2.js
22
28
  var RTR_BATCH = "undefined" !== typeof window ? ("undefined" !== typeof queueMicrotask ? queueMicrotask : setTimeout).bind(window) : "undefined" !== typeof process && process.nextTick ? process.nextTick : setTimeout;
23
29
  var RTR_LOG = console.log.bind(console, "[S.I.A Reactor]");
24
30
  var NIL = Object.freeze({});
25
- var CTX = {
26
- /** Flag indicating whether the application is running in development mode. */
27
- isDevEnv: "undefined" !== typeof process ? process.env.NODE_ENV !== "production" : true,
28
- /** Flag indicating whether an operation is bypassing checks so reactors can allow all writes. */
29
- usingForce: false,
30
- /** Active `Autotracker` instance, override for automatic dependency collection on `Reactor` traps. */
31
- autotracker: null,
32
- /** Extensible meta context for payloads and cross-cutting concerns. */
33
- meta: null,
34
- /** Default configuration for new `Reactor` instances and also fallback for utils that need and are called without these options. */
35
- defaults: {
36
- crossRealms: false,
37
- smartCloning: false,
38
- eventBubbling: true,
39
- eventCapturing: "auto",
40
- lineageTracing: false,
41
- preserveContext: false,
42
- equalityFunction: Object.is,
43
- batchingFunction: RTR_BATCH
44
- }
45
- };
31
+ var isDevEnv = false;
32
+ try {
33
+ isDevEnv = process.env.NODE_ENV !== "production";
34
+ } catch (e) {
35
+ }
46
36
 
47
- // ../utils/dist/chunk-HGUYOV3P.js
37
+ // ../utils/dist/chunk-ZALPHCSJ.js
48
38
  var INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable],iframe,audio[controls],video[controls],[tabindex]):not([disabled],[tabindex='-1'],[data-focus-guard],[inert],[inert] *)";
49
39
  var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
50
40
  function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, win = window) {
package/dist/react.d.ts CHANGED
@@ -2,9 +2,113 @@ import React from 'react';
2
2
 
3
3
  /** Browser date-like input types supported by input field helpers. */
4
4
  declare const dateTypes: readonly ["date", "time", "datetime-local", "month"];
5
+
5
6
  /** Union of all supported native date-like input types. */
6
7
  type DateType = (typeof dateTypes)[number];
7
8
 
9
+ interface BaseOptions extends Omit<BaseProps, "error"> {
10
+ /** Visible label text. */
11
+ label?: string;
12
+ /** Optional child element rendered inside the field wrapper. */
13
+ children?: HTMLElement;
14
+ }
15
+ type InputAttrs = Partial<Omit<HTMLInputElement, "type" | "children">>;
16
+ type SelectAttrs = Partial<Omit<HTMLSelectElement, "type" | "children" | "options">>;
17
+ type TextareaAttrs = Partial<Omit<HTMLTextAreaElement, "type" | "children">>;
18
+ type PasswordFieldOptions = BaseOptions & InputAttrs & Omit<FileInputAddon, "passwordVisibleIcon" | "passwordHiddenIcon"> & { passwordVisibleIcon?: HTMLElement; passwordHiddenIcon?: HTMLElement };
19
+ type FileFieldOptions = BaseOptions & InputAttrs & FileInputAddon;
20
+ type CheckboxFieldOptions = BaseOptions & InputAttrs & CheckboxInputAddon;
21
+ type DateFieldOptions = BaseOptions & InputAttrs & DateInputAddon;
22
+ type GenericFieldOptions = BaseOptions & InputAttrs & { type?: Exclude<HTMLInputElement["type"], "password" | "file" | "checkbox" | DateType> };
23
+ type TextareaFieldOptions = BaseOptions & TextareaAttrs & { type: "textarea" };
24
+ type SelectFieldOptions = BaseOptions & SelectAttrs & SelectElementAddon;
25
+ /** Configuration accepted by the field() helper. */
26
+ type FieldOptions = PasswordFieldOptions | FileFieldOptions | CheckboxFieldOptions | DateFieldOptions | GenericFieldOptions | TextareaFieldOptions | SelectFieldOptions;
27
+
28
+ /** Form-level manager used to build and validate inputs. */
29
+ interface FormManager {
30
+ /** Live collection of managed forms. */
31
+ forms: HTMLCollectionOf<HTMLFormElement>;
32
+ /** Current validation violation keys. */
33
+ violationKeys: string[];
34
+ /** Initialize DOM observers and field bindings. */
35
+ init(): void;
36
+ /** Observe the DOM for field changes. */
37
+ observeDOMForFields(): void;
38
+ /** Normalize and validate uploaded files.
39
+ * @param files Files selected by the user.
40
+ * @param opts Validation options.
41
+ * @returns Violation information and user-facing message.
42
+ */
43
+ getFilesHelper(files: FileList | File[], opts: any): { violation: string | null; message: string };
44
+ /** Format a file size for display.
45
+ * @param size Size in bytes.
46
+ * @param decimals Decimal precision.
47
+ * @param base Size base, usually 1000 or 1024.
48
+ * @returns Human-readable size string.
49
+ */
50
+ formatSize(size: number, decimals?: number, base?: number): string;
51
+ /** Toggle an input between password and text mode.
52
+ * @param input Target password input.
53
+ */
54
+ togglePasswordType(input: HTMLInputElement): void;
55
+ /** Toggle the filled state on a supported field.
56
+ * @param input Supported form control.
57
+ */
58
+ toggleFilled(input: t007InputElement): void;
59
+ /** Attach a fallback helper node.
60
+ * @param field Field wrapper element.
61
+ */
62
+ setFallbackHelper(field: HTMLDivElement): void;
63
+ /** Wire listeners onto a managed field.
64
+ * @param field Field wrapper element.
65
+ */
66
+ setFieldListeners(field: HTMLDivElement): void;
67
+ /** Normalize field markup before use.
68
+ * @param field Field wrapper element.
69
+ */
70
+ setUpField(field: HTMLDivElement): void;
71
+ /** Create a field element from options.
72
+ * @param options Field configuration.
73
+ * @returns Created field element.
74
+ */
75
+ field(options: SelectFieldOptions): HTMLDivElement & { inputEl: HTMLSelectElement };
76
+ field(options: TextareaFieldOptions): HTMLDivElement & { inputEl: HTMLTextAreaElement };
77
+ field(options: PasswordFieldOptions | FileFieldOptions | CheckboxFieldOptions | DateFieldOptions | GenericFieldOptions): HTMLDivElement & { inputEl: HTMLInputElement };
78
+ field(options: FieldOptions): HTMLDivElement & { inputEl: t007InputElement };
79
+ /** Validate a form and attach the proper hooks.
80
+ * @param form Form element to validate.
81
+ */
82
+ handleFormValidation(form: HTMLFormElement): void;
83
+ }
84
+
85
+ declare global {
86
+ interface T007Namespace {
87
+ /** Form manager singleton attached by the bundle. */
88
+ FM: FormManager;
89
+ /** Public form manager singleton. */
90
+ formManager: FormManager;
91
+ /** Public field factory. */
92
+ field: FormManager["field"];
93
+ /** Public form validation helper. */
94
+ handleFormValidation: FormManager["handleFormValidation"];
95
+ }
96
+ interface Window {
97
+ field?: T007Namespace["field"];
98
+ handleFormValidation?: T007Namespace["handleFormValidation"];
99
+ }
100
+ interface HTMLFormElement {
101
+ /** Vanilla-only Client-side submit hook. Use instead of `onsubmit` to escape browser behavior. */
102
+ onSubmit?(e: Event): void;
103
+ /** Vanilla-only Check validation on the client. Reference to internals for manual use. */
104
+ validateOnClient?(): boolean;
105
+ /** Vanilla-only Check validation on the server. Assign custom server-side validation logic. */
106
+ validateOnServer?(): Promise<boolean>;
107
+ /** Vanilla-only Toggle the global error state. Reference to internals for manual use. */
108
+ toggleGlobalError?(bool: boolean): void;
109
+ }
110
+ }
111
+
8
112
  /** React change event alias used by input helpers. */
9
113
  type CE<T> = React.ChangeEvent<T>;
10
114
  /** React input event alias used by input helpers. */
@@ -138,4 +242,4 @@ declare function useFormManager(onSubmit?: (e: React.FormEvent<HTMLFormElement>)
138
242
  fireInput: (el?: t007InputElement | null) => boolean | undefined;
139
243
  };
140
244
 
141
- export { type BaseProps, type CE, type CEH, type HelperTextMap, type IE, type IEH, Input, type InputProps, WordsInput, type WordsInputBaseProps, type WordsInputLenientModeProps, type WordsInputProps, type WordsInputStrictModeProps, type t007InputElement, useFormManager };
245
+ export { type BaseProps, type CE, type CEH, type CheckboxInputAddon, type CheckboxInputProps, type DateInputAddon, type DateInputProps, type FileInputAddon, type FileInputProps, type GenericInputProps, type HelperTextMap, type IE, type IEH, Input, type InputAttributes, type InputProps, type PasswordInputAddon, type PasswordInputProps, type SelectAttributes, type SelectElementAddon, type SelectElementProps, type TextareaAttributes, type TextareaElementProps, WordsInput, type WordsInputBaseProps, type WordsInputLenientModeProps, type WordsInputProps, type WordsInputStrictModeProps, type t007InputElement, useFormManager };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/input",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
4
4
  "description": "A lightweight, pure JS input system.",
5
5
  "author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
6
6
  "license": "MIT",
@@ -69,7 +69,7 @@
69
69
  "react-dom": "^18.3.1"
70
70
  },
71
71
  "dependencies": {
72
- "@t007/utils": "^0.0.34"
72
+ "@t007/utils": "^0.0.35"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "react": "^18.0.0"