@dragonmastery/zinia-forms-core 0.3.0 → 0.3.1

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
@@ -1506,6 +1506,10 @@ interface FilterValue {
1506
1506
  value: any;
1507
1507
  operator: 'eq' | 'contains' | 'gt' | 'lt' | 'in' | 'between';
1508
1508
  }
1509
+ type FilterOptionItem = {
1510
+ label: string;
1511
+ value: any;
1512
+ } | string | number;
1509
1513
  interface BaseActionItem<TData> {
1510
1514
  key: string;
1511
1515
  /**
@@ -1557,8 +1561,8 @@ interface ColumnDefinition<TData, TField extends keyof TData> {
1557
1561
  format?: (value: TData[TField], row: TData) => string;
1558
1562
  render?: (value: TData[TField], row: TData) => any;
1559
1563
  filterType?: 'text' | 'select' | 'number' | 'boolean';
1560
- filterOptions?: any[];
1561
- filterOptionsLoader?: () => Promise<any[]>;
1564
+ filterOptions?: FilterOptionItem[];
1565
+ filterOptionsLoader?: () => Promise<FilterOptionItem[]>;
1562
1566
  sortLabels?: {
1563
1567
  asc: string;
1564
1568
  desc: string;
@@ -2160,4 +2164,4 @@ declare const ActionIcons: {
2160
2164
  readonly dotsHorizontal: "<svg fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\"><path stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z\" /></svg>";
2161
2165
  };
2162
2166
 
2163
- export { ActionIcons, type ActionItem, type ActionsConfig, type ButtonActionItem, type ColumnDefinition, type CursorDataTableOptions, type CursorFetchParams, type CursorFetchResult, type DataTableColumns, type DataTableOptions, type DisplayComponentsType, type DisplayFieldComponent, ErrorDisplay, type FetchDataParams, type FetchDataResult, type FilterValue, type LinkActionItem, LoadingDisplay, NoDataDisplay, SCHEMA_ID_SYMBOL, type TypedSelectFieldComponent, type UseCursorDataTableType, type UseDataTableType, type UseDeleteModalType, type UseDisplayType, type UseFormType, type UseFormTyped, ZINIA_DATA_TABLE_ACTIONS_KEY, ZINIA_DATA_TABLE_COLUMNS_KEY, ZINIA_DATA_TABLE_FILTER_INPUTS_KEY, ZINIA_DATA_TABLE_FILTER_OPERATORS_KEY, ZINIA_DATA_TABLE_FILTER_OPTIONS_LOADING_KEY, ZINIA_DATA_TABLE_FILTER_OPTIONS_STATE_KEY, ZINIA_DATA_TABLE_KEY, ZINIA_DATA_TABLE_NAME_KEY, ZINIA_DATA_TABLE_OPTIONS_KEY, ZINIA_DATA_TABLE_SEARCH_INPUT_KEY, ZINIA_DELETE_MODAL_FIELDS_GENERIC_KEY, ZINIA_DELETE_MODAL_FIELDS_KEY, ZINIA_DELETE_MODAL_KEY, ZINIA_DELETE_MODAL_SCHEMA_KEY, ZINIA_DISPLAY_FIELDS_GENERIC_KEY, ZINIA_DISPLAY_FIELDS_KEY, ZINIA_DISPLAY_KEY, ZINIA_DISPLAY_SCHEMA_KEY, ZINIA_FIELDS_GENERIC_KEY, ZINIA_FIELDS_KEY, ZINIA_FORM_KEY, ZINIA_FORM_SCHEMA_KEY, type ZiniaDataTable, type ZiniaDeleteModal, type ZiniaDeleteModalFields, type ZiniaDeleteModalGenericFields, type ZiniaDisplay, type ZiniaDisplayFields, type ZiniaDisplayGenericFields, type ZiniaForm, type ZiniaFormFields, type ZiniaFormGenericFields, ZiniaPlugin, type ZiniaPluginOptions, clearAllMetadata, clearSchemaMetadata, createBaseComponents, createBaseDisplayComponents, createPartialStyle, createStyleTemplate, createTypedArrayField, createTypedSelectField, daisyUIStyle, extendStyle, generateDisplayComponents, generateFieldComponents, getAllSchemaMetadata, getDefaultStyle, getFieldMetadata, getRegisteredStyle, getRegisteredStyleNames, getSchemaId, hasRegisteredStyle, hasSchemaMetadata, mergeStyles, plainStyle, registerSchemaMetadata, registerStyle, setSchemaMetadata, useCursorDataTable, useDataTable, useDeleteModal, useDisplay, useForm, withMetadata };
2167
+ export { ActionIcons, type ActionItem, type ActionsConfig, type ButtonActionItem, type ColumnDefinition, type CursorDataTableOptions, type CursorFetchParams, type CursorFetchResult, type DataTableColumns, type DataTableOptions, type DisplayComponentsType, type DisplayFieldComponent, ErrorDisplay, type FetchDataParams, type FetchDataResult, type FilterOptionItem, type FilterValue, type LinkActionItem, LoadingDisplay, NoDataDisplay, SCHEMA_ID_SYMBOL, type TypedSelectFieldComponent, type UseCursorDataTableType, type UseDataTableType, type UseDeleteModalType, type UseDisplayType, type UseFormType, type UseFormTyped, ZINIA_DATA_TABLE_ACTIONS_KEY, ZINIA_DATA_TABLE_COLUMNS_KEY, ZINIA_DATA_TABLE_FILTER_INPUTS_KEY, ZINIA_DATA_TABLE_FILTER_OPERATORS_KEY, ZINIA_DATA_TABLE_FILTER_OPTIONS_LOADING_KEY, ZINIA_DATA_TABLE_FILTER_OPTIONS_STATE_KEY, ZINIA_DATA_TABLE_KEY, ZINIA_DATA_TABLE_NAME_KEY, ZINIA_DATA_TABLE_OPTIONS_KEY, ZINIA_DATA_TABLE_SEARCH_INPUT_KEY, ZINIA_DELETE_MODAL_FIELDS_GENERIC_KEY, ZINIA_DELETE_MODAL_FIELDS_KEY, ZINIA_DELETE_MODAL_KEY, ZINIA_DELETE_MODAL_SCHEMA_KEY, ZINIA_DISPLAY_FIELDS_GENERIC_KEY, ZINIA_DISPLAY_FIELDS_KEY, ZINIA_DISPLAY_KEY, ZINIA_DISPLAY_SCHEMA_KEY, ZINIA_FIELDS_GENERIC_KEY, ZINIA_FIELDS_KEY, ZINIA_FORM_KEY, ZINIA_FORM_SCHEMA_KEY, type ZiniaDataTable, type ZiniaDeleteModal, type ZiniaDeleteModalFields, type ZiniaDeleteModalGenericFields, type ZiniaDisplay, type ZiniaDisplayFields, type ZiniaDisplayGenericFields, type ZiniaForm, type ZiniaFormFields, type ZiniaFormGenericFields, ZiniaPlugin, type ZiniaPluginOptions, clearAllMetadata, clearSchemaMetadata, createBaseComponents, createBaseDisplayComponents, createPartialStyle, createStyleTemplate, createTypedArrayField, createTypedSelectField, daisyUIStyle, extendStyle, generateDisplayComponents, generateFieldComponents, getAllSchemaMetadata, getDefaultStyle, getFieldMetadata, getRegisteredStyle, getRegisteredStyleNames, getSchemaId, hasRegisteredStyle, hasSchemaMetadata, mergeStyles, plainStyle, registerSchemaMetadata, registerStyle, setSchemaMetadata, useCursorDataTable, useDataTable, useDeleteModal, useDisplay, useForm, withMetadata };
package/dist/index.js CHANGED
@@ -2486,7 +2486,12 @@ function useDataTable(schema, options) {
2486
2486
  filterOptionsLoading.value[field] = true;
2487
2487
  try {
2488
2488
  const options2 = await column.filterOptionsLoader();
2489
- filterOptionsState.value[field] = options2;
2489
+ filterOptionsState.value[field] = options2.map((opt) => {
2490
+ if (typeof opt === "object" && opt !== null && "label" in opt && "value" in opt) {
2491
+ return opt;
2492
+ }
2493
+ return { label: String(opt), value: opt };
2494
+ });
2490
2495
  } catch (error) {
2491
2496
  console.error(`Failed to load filter options for ${field}:`, error);
2492
2497
  } finally {
@@ -3046,7 +3051,12 @@ function useCursorDataTable(schema, options) {
3046
3051
  filterOptionsLoading.value[field] = true;
3047
3052
  try {
3048
3053
  const options2 = await column.filterOptionsLoader();
3049
- filterOptionsState.value[field] = options2;
3054
+ filterOptionsState.value[field] = options2.map((opt) => {
3055
+ if (typeof opt === "object" && opt !== null && "label" in opt && "value" in opt) {
3056
+ return opt;
3057
+ }
3058
+ return { label: String(opt), value: opt };
3059
+ });
3050
3060
  } catch (error) {
3051
3061
  console.error(`Failed to load filter options for ${field}:`, error);
3052
3062
  } finally {
@@ -6069,17 +6079,35 @@ function getFilterType(field, column, fieldsMetadata) {
6069
6079
  }
6070
6080
  function getFilterOptions(field, column, fieldsMetadata, filterOptionsState) {
6071
6081
  if (filterOptionsState && filterOptionsState[field]) {
6072
- return filterOptionsState[field];
6082
+ const options = filterOptionsState[field];
6083
+ return options.map((opt) => {
6084
+ if (typeof opt === "object" && opt !== null && "label" in opt && "value" in opt) {
6085
+ return opt;
6086
+ }
6087
+ return { label: String(opt), value: opt };
6088
+ });
6073
6089
  }
6074
6090
  if (column?.filterOptions) {
6075
- return column.filterOptions;
6091
+ const options = column.filterOptions;
6092
+ return options.map((opt) => {
6093
+ if (typeof opt === "object" && opt !== null && "label" in opt && "value" in opt) {
6094
+ return opt;
6095
+ }
6096
+ return { label: String(opt), value: opt };
6097
+ });
6076
6098
  }
6077
6099
  const fieldMetadata = fieldsMetadata[field];
6078
6100
  if (fieldMetadata?.options) {
6079
- return fieldMetadata.options.map((opt) => opt.value);
6101
+ return fieldMetadata.options.map((opt) => ({
6102
+ label: opt.label || String(opt.value),
6103
+ value: opt.value
6104
+ }));
6080
6105
  }
6081
6106
  if (fieldMetadata?.valueToLabel) {
6082
- return Object.keys(fieldMetadata.valueToLabel);
6107
+ return Object.entries(fieldMetadata.valueToLabel).map(([value, label]) => ({
6108
+ label: String(label),
6109
+ value
6110
+ }));
6083
6111
  }
6084
6112
  return [];
6085
6113
  }
@@ -6386,7 +6414,7 @@ var SelectFilter = (props) => {
6386
6414
  "data-testid": `datatable-filter-${props.field}-input`,
6387
6415
  children: [
6388
6416
  /* @__PURE__ */ jsx("option", { value: "", children: props.isOptionsLoading ? "Loading options..." : `All ${props.label}` }),
6389
- props.options.map((option) => /* @__PURE__ */ jsx("option", { value: option, children: typeof option === "string" ? option.charAt(0).toUpperCase() + option.slice(1) : option }, option))
6417
+ props.options.map((option) => /* @__PURE__ */ jsx("option", { value: option.value, children: option.label }, option.value))
6390
6418
  ]
6391
6419
  },
6392
6420
  props.field