@emeraldemperaur/vector-sigma 1.4.38 → 1.4.40

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.
@@ -5,7 +5,7 @@ import '../../styles/main.scss';
5
5
  export type ToggleTriggerDesign = 'conditionaltoggle' | 'conditionaltoggle-outline' | 'conditionaltoggle-material' | 'conditionaltoggle-neumorphic';
6
6
  export type CheckboxTriggerDesign = 'conditionalcheckbox' | 'conditionalcheckbox-outline' | 'conditionalcheckbox-material' | 'conditionalcheckbox-neumorphic';
7
7
  export type SelectTriggerDesign = 'conditionalselect' | 'conditionalselect-outline' | 'conditionalselect-material' | 'conditionalselect-neumorphic';
8
- export type TriggerType = 'conditionaltoggle' | 'conditionalcheckbox' | 'conditionalselect';
8
+ export type TriggerType = 'conditionaltoggle' | 'conditionalcheckbox' | 'conditionalselect' | 'conditional-toggle' | 'conditional-checkbox' | 'conditional-select';
9
9
  export interface ConditionalProps {
10
10
  /**
11
11
  * * The design variation of the Conditional Trigger input.
@@ -0,0 +1,9 @@
1
+ import { VectorSigma } from '../vectorSigma';
2
+ import { XFormType } from '../utils/voltron';
3
+ /**
4
+ * VΣ hook to securely initialize and persist a VectorSigma instance
5
+ * across React re-renders w/out losing internal VΣ tracking state.
6
+ * * @param initializer Optional JSON string, XFormType object, or undefined when constructing xForm schema object by builder methods.
7
+ * @returns Stateful VectorSigma class instance.
8
+ */
9
+ export declare const useVectorSigma: (initializer?: string | XFormType | unknown) => VectorSigma<Record<string, any>>;
File without changes
@@ -2,11 +2,29 @@ import React from 'react';
2
2
  import { XFormType, XFormQuery, SectionSchema } from './utils/voltron';
3
3
  import { Teletraan1Props } from './teletraan1';
4
4
  import { z } from "zod";
5
+ import { FormikHelpers } from 'formik';
5
6
  import './styles/main.scss';
6
- export declare class VectorSigma {
7
+ export interface VectorSigmaRenderProps<T extends Record<string, any> = Record<string, any>> extends Omit<Teletraan1Props, 'xFormModel'> {
8
+ /**
9
+ * * Optional callback fired when the form is submitted and passes validation.
10
+ * Receives normalized xForm form values, developer access to Formik action helper methods, and the VectorSigma class instance.
11
+ * * @example
12
+ * onSubmit={async (values, actions, instance) => {
13
+ // Send data to API
14
+ await axios.post('/api/upload', instance.getxForm());
15
+ await axios.post('/api/submit', values);
16
+ // Track completion time using 'instance'
17
+ console.log(`Form completed in ${(instance.timeSubmitted! - instance.timeCreated) / 1000}s`);
18
+ // Clear form after success
19
+ actions.resetForm();
20
+ }}
21
+ */
22
+ onSubmit?: (values: T, actions: FormikHelpers<T>, instance: VectorSigma<T>) => void | Promise<any>;
23
+ }
24
+ export declare class VectorSigma<T extends Record<string, any> = Record<string, any>> {
7
25
  isValid: boolean;
8
26
  formObject: XFormType;
9
- values: Record<string, any>;
27
+ values: Partial<T>;
10
28
  errors: Record<string, any>;
11
29
  statusCode: 0 | 1 | 2;
12
30
  timeCreated: number;
@@ -14,34 +32,154 @@ export declare class VectorSigma {
14
32
  timeSubmitted: number | null;
15
33
  isSubmitting: boolean;
16
34
  /**
17
- * Initializes the VectorSigma instance.
18
- * @param initializer A JSON string or a JavaScript object matching XFormType.
19
- * If left empty, initializes a blank form object for use with Builder methods.
35
+ * Initializes VectorSigma instance.
36
+ * @param initializer JSON string literal or a JavaScript {} matching XFormType.
37
+ * When undefined, initializes base xForm object scaffold for use with VectorSigma builder methods.
20
38
  */
21
39
  constructor(initializer?: string | XFormType | unknown);
22
40
  /**
23
- * Safely validates the input against the XFormSchema.
24
- * Throws developer-friendly errors if the JSON is malformed or violates the schema.
41
+ * Validates JSON juxtaposed with the XFormSchema.
42
+ * Raises DX (developer-friendly) errors if the JSON malformed or violates XFormSchema.
25
43
  */
26
44
  private validateAndSet;
27
45
  /**
28
- * Traverses the schema to extract Formik InitialValues and Yup Validation logic.
46
+ * Extrapolates Formik InitialValues and Yup Schema based on inputType value data type.
29
47
  */
30
48
  private buildFormikConfig;
49
+ /**
50
+ * Traverses xForm schema object and injects Formik values into their respective input queryResponse attributes by `inputAlias`.
51
+ */
52
+ private hydrateQueryResponses;
53
+ /**
54
+ * VΣ builder method to set the xForm model's unique universal identifier (uuid) attribute.
55
+ * @param uuid unique universal identifier for xForm object.
56
+ * @example
57
+ * const xForm97 = new VectorSigma()
58
+ * .setUUID("the-uuid-is-sahelanthropus")
59
+ */
31
60
  setUUID(uuid: string): this;
61
+ /**
62
+ * VΣ builder method to set the xForm model's name attribute.
63
+ * @param name name for xForm object.
64
+ * @example
65
+ * const xForm97 = new VectorSigma()
66
+ * .setName("Wakanda Citizenship Form")
67
+ */
32
68
  setName(name: string): this;
69
+ /**
70
+ * VΣ builder method to set the xForm model's branding attribute.
71
+ * @param color brand color hex string for xForm object.
72
+ * @param logo logo image url for xForm object.
73
+ * @param logoPosition logo position for xForm object.
74
+ * @example
75
+ * const xForm97 = new VectorSigma()
76
+ * .setBrand("#000000", brandLogoUrlRef, 'right')
77
+ */
33
78
  setBrand(color: string, logo?: string, logoPosition?: 'left' | 'center' | 'right'): this;
79
+ /**
80
+ * VΣ builder method to add a Section object to the xForm model.
81
+ * @param section valid schema section object for xForm model.
82
+ * @example
83
+ * const xForm97 = new VectorSigma()
84
+ * .setBrand("#000000", brandLogoUrlRef, 'right')
85
+ * .addSection({
86
+ sectionId: "bio-data",
87
+ title: "Personal Information",
88
+ icon: "user",
89
+ queries: [
90
+ {
91
+ queryId: 303,
92
+ inputType: "text-input",
93
+ inputAlias: "wakandanName",
94
+ inputLabel: "Wakandan Name",
95
+ inputWidth: 7,
96
+ newRow: false,
97
+ isRequired: true,
98
+ errorText: "Wakandan name is required for citizenship applications"
99
+ }
100
+ ]
101
+ })
102
+ */
34
103
  addSection(section: z.infer<typeof SectionSchema>): this;
104
+ /**
105
+ * VΣ builder method to create a Section object in the xForm model.
106
+ * @param sectionId sectionId string for the xForm model section.
107
+ * @param title title string for the xForm model section.
108
+ * @param icon xForm icon name for the xForm model section.
109
+ * @example
110
+ * const xForm97 = new VectorSigma()
111
+ * .setBrand("#000000", brandLogoUrlRef, 'right')
112
+ * .createSection('bio-data', 'Personal Information', 'user')
113
+ */
35
114
  createSection(sectionId: string, title: string, icon?: string): this;
115
+ /**
116
+ * VΣ builder method to add a Query object to the xForm model section by sectionId.
117
+ * @param sectionId sectionId string for the target xForm model section.
118
+ * @param query valid schema query object for the xForm model section.
119
+ * @example
120
+ * const xForm97 = new VectorSigma()
121
+ * .setBrand("#000000", brandLogoUrlRef, 'right')
122
+ * .createSection('bio-data', 'Personal Information', 'user')
123
+ * .addQueryToSection('bio-data', {
124
+ queryId: 100,
125
+ inputType: 'password-input',
126
+ inputAlias: 'wakanadaPassport',
127
+ inputLabel: 'Wakandan Passport Number',
128
+ inputWidth: 6,
129
+ newRow: false,
130
+ isRequired: true,
131
+ errorText: "A valid passport number is required for citizenship application"
132
+ })
133
+ */
36
134
  addQueryToSection(sectionId: string, query: XFormQuery): this;
37
135
  /**
38
- * Transforms the initialized xForm JSON/JS object by normalizing it and returning a `<Teletraan1/>` component.
136
+ * `transform()` method for use with initialized JSON/Object
137
+ * * Apt for integration with JSON data fetched from a backend API or localhost .json file.
138
+ * * Transforms the initialized xForm JSON/JS object, normalizing attribute fields and returning a `<Teletraan1/>` component.
139
+ * @param options VectorSigmaRenderProps -- `VectorSigma` and `Teletraan1` props for VΣ render matrix.
140
+ * @example .transform({
141
+ displayMode: 'codex',
142
+ readOnlyMode: false,
143
+ brandColor: '#800020',
144
+ onSubmit: async (values, actions, instance) => { // <-- onSubmit callback function passed into VectorSigma props
145
+ // Use Case: Send extant xForm object to API
146
+ await axios.post('/api/submit', instance.getxForm());
147
+ // Use Case: Submit and clear form after success
148
+ actions.submitForm();
149
+ actions.resetForm();
150
+ },
151
+ onFinish: () => handleFormFinish() // <-- onFinish callback function passed into Teletraan1 (Codex only) props
152
+ })})
153
+ */
154
+ transform(options?: VectorSigmaRenderProps<T>): React.ReactElement;
155
+ /**
156
+ * VΣ `render()` method for use with VectorSigma object builder
157
+ * * Apt for dynamically creating forms via code.
158
+ * * `render()` is the final method in the Vector Sigma builder pattern chain.
159
+ * @param options VectorSigmaRenderProps -- `VectorSigma` and `Teletraan1` props for VΣ render matrix.
160
+ * @example .render({
161
+ displayMode: 'dual',
162
+ brandColor: '#800020',
163
+ readOnlyMode: false,
164
+ onSubmit: async (values, actions, instance) => { // <-- onSubmit callback function passed into VectorSigma props
165
+ // Use Case: Send hydrated xForm object to API
166
+ await axios.post('/api/submit', instance.getxForm());
167
+ // Use Case: Submit and clear form after success
168
+ actions.submitForm();
169
+ actions.resetForm();
170
+ },
171
+ onFinish: () => handleFormFinish() // <-- onFinish callback function passed into Teletraan1 (Codex) props
172
+ })})
39
173
  */
40
- transform(teletraanProps?: Omit<Teletraan1Props, 'xFormModel'>): React.ReactElement;
174
+ render(options?: VectorSigmaRenderProps<T>): React.ReactElement;
41
175
  /**
42
- * `render()` is the final method in the builder pattern chain.
176
+ * `toJSON()` utility method for retrieving the extant VectorSigma xForm JSON string
177
+ * @example toJSON()
43
178
  */
44
- render(teletraanProps?: Omit<Teletraan1Props, 'xFormModel'>): React.ReactElement;
45
179
  toJSON(): string;
46
- getObject(): XFormType;
180
+ /**
181
+ * VΣ `getxForm()` utility method for retrieving the extant VectorSigma xForm {}
182
+ * @example getxForm()
183
+ */
184
+ getxForm(): XFormType;
47
185
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emeraldemperaur/vector-sigma",
3
- "version": "1.4.38",
3
+ "version": "1.4.40",
4
4
  "description": "Dynamic Form Orchestrator: NPM Package",
5
5
  "repository": {
6
6
  "type": "git",