@dragonmastery/zinia-forms-core 0.3.13 → 0.3.15

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
@@ -1279,6 +1279,118 @@ interface StyleCreators {
1279
1279
  }, {}>;
1280
1280
  }
1281
1281
 
1282
+ /**
1283
+ * Form state management hook
1284
+ * Provides reactive form state with proper reactivity handling
1285
+ */
1286
+
1287
+ /**
1288
+ * Form state interface
1289
+ */
1290
+ interface FormState<T, CalcType = any, ExtraDataType = any> {
1291
+ data: T;
1292
+ calculatedValues: CalcType;
1293
+ touched: Record<string, boolean>;
1294
+ dirty: Record<string, boolean>;
1295
+ errors: Record<string, string>;
1296
+ focused: Record<string, boolean>;
1297
+ displayText: Record<string, string>;
1298
+ selectedIndex: Record<string, number>;
1299
+ collapsedFields: Record<string, {
1300
+ isFieldCollapsed: boolean;
1301
+ collapsedItems: number[];
1302
+ defaultCollapsedInitialized: boolean;
1303
+ }>;
1304
+ undoHistory: Record<string, {
1305
+ type: 'add' | 'remove' | 'swap';
1306
+ previousState: any;
1307
+ currentState: any;
1308
+ timestamp: number;
1309
+ }[]>;
1310
+ redoHistory: Record<string, {
1311
+ type: 'add' | 'remove' | 'swap';
1312
+ previousState: any;
1313
+ currentState: any;
1314
+ timestamp: number;
1315
+ }[]>;
1316
+ pendingOperations: Record<string, {
1317
+ type: 'add' | 'remove' | 'swap';
1318
+ index?: number;
1319
+ indexA?: number;
1320
+ indexB?: number;
1321
+ item?: any;
1322
+ previousState: any;
1323
+ currentState: any;
1324
+ timestamp: number;
1325
+ timeoutId?: number;
1326
+ }[]>;
1327
+ arrayItemIds: Record<string, string[]>;
1328
+ isSubmitting: boolean;
1329
+ hasAttemptedSubmit: boolean;
1330
+ submitAttemptsCount: number;
1331
+ submitError: string | null;
1332
+ isReady: boolean;
1333
+ isLoading: boolean;
1334
+ loadError: string | null;
1335
+ extraData: ExtraDataType;
1336
+ fetchedOptions: Record<string, any[]>;
1337
+ loadingOptions: Record<string, boolean>;
1338
+ asyncCascadingParents: Record<string, string>;
1339
+ loadingAutoPopulate: Record<string, boolean>;
1340
+ populatingFields: Record<string, boolean>;
1341
+ }
1342
+
1343
+ /**
1344
+ * Type definitions for async cascading selection and auto-population
1345
+ */
1346
+
1347
+ /**
1348
+ * Helper type to get the value type of a field path
1349
+ */
1350
+ type FieldValue<FormType, P extends Path<FormType>> = P extends keyof FormType ? FormType[P] : P extends `${infer K}.${infer Rest}` ? K extends keyof FormType ? FormType[K] extends Record<string, any> ? FieldValue<FormType[K], Rest & Path<FormType[K]>> : never : never : never;
1351
+ /**
1352
+ * Configuration for async cascading selection (parent → child options fetching via API)
1353
+ */
1354
+ interface AsyncCascadingSelectConfig<FormType, ParentField extends Path<FormType> = Path<FormType>, ChildField extends Path<FormType> = Path<FormType>> {
1355
+ /** Parent field that triggers child options fetch */
1356
+ parentField: ParentField;
1357
+ /** Child field that will be populated with fetched options */
1358
+ childField: ChildField;
1359
+ /** Async function to fetch child options based on parent value */
1360
+ fetchOptionsFn: (parentValue: FieldValue<FormType, ParentField>) => Promise<Array<SelectOption>>;
1361
+ /** Whether to clear child field when parent changes (default: true) */
1362
+ clearOnParentChange?: boolean;
1363
+ }
1364
+ /**
1365
+ * Type for the async cascading selects configuration object
1366
+ * Uses a mapped type to preserve field path type safety
1367
+ */
1368
+ type AsyncCascadingSelectsConfig<FormType> = {
1369
+ [K in string]: AsyncCascadingSelectConfig<FormType, Path<FormType>, Path<FormType>>;
1370
+ };
1371
+ /**
1372
+ * Configuration for auto-population (select/combobox → other fields)
1373
+ */
1374
+ interface AutoPopulateConfig<FormType, TData = any, SourceField extends Path<FormType> = Path<FormType>> {
1375
+ /**
1376
+ * Optional async function to fetch data when option is selected.
1377
+ * If provided, this will be called instead of using option.data.
1378
+ * Receives the selected option value and returns the data object.
1379
+ */
1380
+ fetchDataFn?: (selectedValue: FieldValue<FormType, SourceField>) => Promise<TData>;
1381
+ /** Mapping of form fields to data properties for auto-population */
1382
+ fields: {
1383
+ [TargetField in Path<FormType>]?: string | ((data: TData) => FieldValue<FormType, TargetField>);
1384
+ };
1385
+ }
1386
+ /**
1387
+ * Type for the auto-populate configuration object
1388
+ * Key is the select/combobox field name, value is the auto-populate config
1389
+ */
1390
+ type AutoPopulateConfigs<FormType> = Partial<{
1391
+ [SourceField in Path<FormType>]: AutoPopulateConfig<FormType, any>;
1392
+ }>;
1393
+
1282
1394
  /**
1283
1395
  * Options for merging server data with local changes
1284
1396
  */
@@ -1342,6 +1454,8 @@ declare function useForm<T extends z.ZodObject<any>, CalcType = (values: z.infer
1342
1454
  [K in keyof ExtraDataType]?: () => Promise<ExtraDataType[K]>;
1343
1455
  };
1344
1456
  fetchData?: () => Promise<z.infer<typeof schema>>;
1457
+ asyncCascadingSelects?: AsyncCascadingSelectsConfig<z.infer<T>>;
1458
+ autoPopulate?: AutoPopulateConfigs<z.infer<T>>;
1345
1459
  calculationFn?: (values: z.infer<T>, extraData?: ExtraDataType) => CalcType;
1346
1460
  debug?: {
1347
1461
  all?: boolean;
@@ -1355,6 +1469,7 @@ declare function useForm<T extends z.ZodObject<any>, CalcType = (values: z.infer
1355
1469
  form: {
1356
1470
  storeName: string;
1357
1471
  values: z.TypeOf<T>;
1472
+ state: FormState<z.TypeOf<T>, CalcType, ExtraDataType>;
1358
1473
  readonly calculatedValues: CalcType;
1359
1474
  readonly extraData: ExtraDataType;
1360
1475
  readonly isValid: boolean;
@@ -2056,6 +2171,9 @@ declare function useDataTable<TSchema extends z.ZodObject<any>>(schema: TSchema,
2056
2171
  sortDrawerOpen: vue.Ref<boolean, boolean>;
2057
2172
  openSortDrawer: () => boolean;
2058
2173
  closeSortDrawer: () => boolean;
2174
+ filterDrawerOpen: vue.Ref<boolean, boolean>;
2175
+ openFilterDrawer: () => boolean;
2176
+ closeFilterDrawer: () => boolean;
2059
2177
  };
2060
2178
  fieldsMetadata: Record<string, FieldMetadata>;
2061
2179
  columns: (z.TypeOf<TSchema> extends infer T ? { [K in keyof T]?: ColumnDefinition<z.TypeOf<TSchema>, K> | undefined; } : never) & {
@@ -2221,6 +2339,9 @@ declare function useCursorDataTable<TSchema extends z.ZodObject<any>>(schema: TS
2221
2339
  sortDrawerOpen: vue.Ref<boolean, boolean>;
2222
2340
  openSortDrawer: () => boolean;
2223
2341
  closeSortDrawer: () => boolean;
2342
+ filterDrawerOpen: vue.Ref<boolean, boolean>;
2343
+ openFilterDrawer: () => boolean;
2344
+ closeFilterDrawer: () => boolean;
2224
2345
  };
2225
2346
  fieldsMetadata: Record<string, FieldMetadata>;
2226
2347
  columns: (z.TypeOf<TSchema> extends infer T ? { [K in keyof T]?: ColumnDefinition<z.TypeOf<TSchema>, K> | undefined; } : never) & {