@dragonmastery/zinia-forms-core 0.4.0 → 0.4.2

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
@@ -2059,6 +2059,7 @@ interface ActionsConfig<TData> {
2059
2059
  column?: {
2060
2060
  label?: string;
2061
2061
  align?: 'left' | 'center' | 'right';
2062
+ verticalAlign?: 'top' | 'middle' | 'bottom';
2062
2063
  width?: number;
2063
2064
  };
2064
2065
  items: ActionItem<TData>[];
@@ -2070,6 +2071,7 @@ interface ColumnDefinition<TData, TField extends keyof TData> {
2070
2071
  filterable?: boolean;
2071
2072
  searchable?: boolean;
2072
2073
  align?: 'left' | 'center' | 'right';
2074
+ verticalAlign?: 'top' | 'middle' | 'bottom';
2073
2075
  textWrap?: 'truncate' | 'wrap';
2074
2076
  format?: (value: TData[TField], row: TData) => string;
2075
2077
  render?: (value: TData[TField], row: TData) => any;
@@ -2077,6 +2079,8 @@ interface ColumnDefinition<TData, TField extends keyof TData> {
2077
2079
  filterOptions?: FilterOptionItem[];
2078
2080
  filterOptionsLoader?: () => Promise<FilterOptionItem[]>;
2079
2081
  filterAllowCreate?: boolean;
2082
+ filterAllOptionText?: string;
2083
+ filterShowAllOption?: boolean;
2080
2084
  sortLabels?: {
2081
2085
  asc: string;
2082
2086
  desc: string;
@@ -2124,6 +2128,7 @@ interface DataTableOptions<TData> {
2124
2128
  search?: {
2125
2129
  searchableFields?: Array<keyof TData>;
2126
2130
  };
2131
+ initialFilters?: Record<string, FilterValue>;
2127
2132
  renderStyle?: RegisteredStyleName;
2128
2133
  schemaId?: string;
2129
2134
  name?: string;
@@ -2292,6 +2297,7 @@ interface CursorDataTableOptions<TData> {
2292
2297
  search?: {
2293
2298
  searchableFields?: Array<keyof TData>;
2294
2299
  };
2300
+ initialFilters?: Record<string, FilterValue>;
2295
2301
  renderStyle?: RegisteredStyleName;
2296
2302
  schemaId?: string;
2297
2303
  name?: string;
package/dist/index.js CHANGED
@@ -3001,6 +3001,15 @@ function useDataTable(schema, options) {
3001
3001
  if (options.search?.searchableFields) {
3002
3002
  tableState.setSearch("", options.search.searchableFields);
3003
3003
  }
3004
+ if (options.initialFilters) {
3005
+ tableState.setFilters(options.initialFilters);
3006
+ Object.entries(options.initialFilters).forEach(([field, filter]) => {
3007
+ if (filter && filter.value !== "" && filter.value !== null && filter.value !== void 0) {
3008
+ filterInputValues.value[field] = String(filter.value);
3009
+ filterOperators.value[field] = filter.operator || "eq";
3010
+ }
3011
+ });
3012
+ }
3004
3013
  const extractActiveFilters = (filterState) => {
3005
3014
  const activeFilters = {};
3006
3015
  Object.entries(filterState).forEach(([key, filter]) => {
@@ -3571,6 +3580,15 @@ function useCursorDataTable(schema, options) {
3571
3580
  if (options.search?.searchableFields) {
3572
3581
  tableState.setSearch("", options.search.searchableFields);
3573
3582
  }
3583
+ if (options.initialFilters) {
3584
+ tableState.setFilters(options.initialFilters);
3585
+ Object.entries(options.initialFilters).forEach(([field, filter]) => {
3586
+ if (filter && filter.value !== "" && filter.value !== null && filter.value !== void 0) {
3587
+ filterInputValues.value[field] = String(filter.value);
3588
+ filterOperators.value[field] = filter.operator || "eq";
3589
+ }
3590
+ });
3591
+ }
3574
3592
  const extractActiveFilters = (filterState) => {
3575
3593
  const activeFilters = {};
3576
3594
  Object.entries(filterState).forEach(([key, filter]) => {
@@ -4282,7 +4300,12 @@ function createDaisyUIArrayField() {
4282
4300
  }
4283
4301
  const itemCopy = JSON.parse(JSON.stringify(item));
4284
4302
  const newArray = [...currentArray, itemCopy];
4285
- formState.addArrayItemId(props.name, newArray.length - 1);
4303
+ const newItemIndex = newArray.length - 1;
4304
+ formState.addArrayItemId(props.name, newItemIndex);
4305
+ const collapsedIndex = collapseState.collapsedItems.indexOf(newItemIndex);
4306
+ if (collapsedIndex > -1) {
4307
+ collapseState.collapsedItems.splice(collapsedIndex, 1);
4308
+ }
4286
4309
  formState.setValue(props.name, newArray);
4287
4310
  formState.validateField(props.name);
4288
4311
  if (props.onAddItem) {
@@ -4469,7 +4492,7 @@ function createDaisyUIArrayField() {
4469
4492
  "button",
4470
4493
  {
4471
4494
  type: "button",
4472
- class: "btn btn-sm btn-ghost min-h-[32px] sm:min-h-[36px] px-3 sm:px-4 text-xs sm:text-sm",
4495
+ class: "btn btn-sm btn-secondary min-h-[32px] sm:min-h-[36px] px-3 sm:px-4 text-xs sm:text-sm",
4473
4496
  onClick: () => cancelPendingOperation(index),
4474
4497
  "aria-label": "Undo removal",
4475
4498
  children: [
@@ -8097,6 +8120,7 @@ var DesktopTable = (props) => {
8097
8120
  ) }),
8098
8121
  props.columnKeys.map((field) => {
8099
8122
  if (field === "actions" && props.actions) {
8123
+ const verticalAlign2 = props.actions.column?.verticalAlign || "middle";
8100
8124
  return /* @__PURE__ */ jsx(
8101
8125
  "th",
8102
8126
  {
@@ -8104,6 +8128,7 @@ var DesktopTable = (props) => {
8104
8128
  props.actions.column?.align === "center" && "text-center",
8105
8129
  props.actions.column?.align === "right" && "text-right"
8106
8130
  ],
8131
+ style: { verticalAlign: verticalAlign2 },
8107
8132
  children: props.actions.column?.label || "Actions"
8108
8133
  },
8109
8134
  "actions"
@@ -8111,6 +8136,7 @@ var DesktopTable = (props) => {
8111
8136
  }
8112
8137
  const column = props.columns[field];
8113
8138
  if (!column) return null;
8139
+ const verticalAlign = column.verticalAlign || "middle";
8114
8140
  return /* @__PURE__ */ jsx(
8115
8141
  "th",
8116
8142
  {
@@ -8123,6 +8149,7 @@ var DesktopTable = (props) => {
8123
8149
  column.align === "right" && "text-right",
8124
8150
  props.isLoading && "opacity-50 cursor-not-allowed"
8125
8151
  ],
8152
+ style: { verticalAlign },
8126
8153
  onClick: () => props.onSort(field),
8127
8154
  "data-testid": column.sortable ? `${props.tableName || "datatable"}-sort-${field}` : void 0,
8128
8155
  children: /* @__PURE__ */ jsxs("div", { class: "flex items-center gap-2", children: [
@@ -8183,6 +8210,7 @@ var DesktopTable = (props) => {
8183
8210
  ) }),
8184
8211
  props.columnKeys.map((field) => {
8185
8212
  if (field === "actions" && props.actions) {
8213
+ const verticalAlign2 = props.actions.column?.verticalAlign || "middle";
8186
8214
  return /* @__PURE__ */ jsx(
8187
8215
  "td",
8188
8216
  {
@@ -8190,6 +8218,7 @@ var DesktopTable = (props) => {
8190
8218
  props.actions.column?.align === "center" && "text-center",
8191
8219
  props.actions.column?.align === "right" && "text-right"
8192
8220
  ],
8221
+ style: { verticalAlign: verticalAlign2 },
8193
8222
  children: /* @__PURE__ */ jsx("div", { class: "flex gap-1 justify-center", children: props.actions.items.map((action) => renderActionItem(action, row)) })
8194
8223
  },
8195
8224
  "actions"
@@ -8199,6 +8228,7 @@ var DesktopTable = (props) => {
8199
8228
  if (!column) return null;
8200
8229
  const value = row[field];
8201
8230
  const formattedValue = formatCellValue(value, field, row, column);
8231
+ const verticalAlign = column.verticalAlign || "middle";
8202
8232
  return /* @__PURE__ */ jsx(
8203
8233
  "td",
8204
8234
  {
@@ -8208,6 +8238,7 @@ var DesktopTable = (props) => {
8208
8238
  column.textWrap === "truncate" && "max-w-xs",
8209
8239
  column.textWrap === "wrap" && "whitespace-normal"
8210
8240
  ],
8241
+ style: { verticalAlign },
8211
8242
  children: props.slots[`cell-${field}`] ? props.slots[`cell-${field}`]?.({ value, row, field, formattedValue }) : /* @__PURE__ */ jsx("span", { class: column.textWrap === "truncate" ? "truncate block" : void 0, children: formattedValue })
8212
8243
  },
8213
8244
  field
@@ -8243,7 +8274,7 @@ var SelectFilter = (props) => {
8243
8274
  disabled: props.isLoading || props.isOptionsLoading,
8244
8275
  "data-testid": `datatable-filter-${props.field}-input`,
8245
8276
  children: [
8246
- /* @__PURE__ */ jsx("option", { value: "", children: props.isOptionsLoading ? "Loading options..." : `All ${props.label}` }),
8277
+ props.showAllOption !== false && /* @__PURE__ */ jsx("option", { value: "", children: props.isOptionsLoading ? "Loading options..." : props.allOptionText !== void 0 ? props.allOptionText : `All ${props.label}` }),
8247
8278
  props.options.map((option) => /* @__PURE__ */ jsx("option", { value: option.value, children: option.label }, option.value))
8248
8279
  ]
8249
8280
  }
@@ -8384,7 +8415,7 @@ var BooleanFilter = (props) => {
8384
8415
  disabled: props.isLoading,
8385
8416
  "data-testid": `datatable-filter-${props.field}-input`,
8386
8417
  children: [
8387
- /* @__PURE__ */ jsx("option", { value: "", children: "All" }),
8418
+ props.showAllOption !== false && /* @__PURE__ */ jsx("option", { value: "", children: props.allOptionText ?? "All" }),
8388
8419
  /* @__PURE__ */ jsx("option", { value: "true", children: "Yes" }),
8389
8420
  /* @__PURE__ */ jsx("option", { value: "false", children: "No" })
8390
8421
  ]
@@ -8862,6 +8893,8 @@ var FilterDrawer = (props) => {
8862
8893
  label: column.label,
8863
8894
  isLoading: props.isLoading,
8864
8895
  isOptionsLoading: filterOptionsLoading?.value?.[field] ?? false,
8896
+ allOptionText: column.filterAllOptionText,
8897
+ showAllOption: column.filterShowAllOption,
8865
8898
  onFilterChange: props.onFilterChange
8866
8899
  }
8867
8900
  ),
@@ -8894,6 +8927,8 @@ var FilterDrawer = (props) => {
8894
8927
  value: currentValue,
8895
8928
  label: column.label,
8896
8929
  isLoading: props.isLoading,
8930
+ allOptionText: column.filterAllOptionText,
8931
+ showAllOption: column.filterShowAllOption,
8897
8932
  onFilterChange: props.onFilterChange
8898
8933
  }
8899
8934
  ),