@hybridly/vue 0.7.7 → 0.7.9

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.cjs CHANGED
@@ -412,6 +412,16 @@ function viewTransition() {
412
412
  };
413
413
  }
414
414
 
415
+ const formStore = {
416
+ defaultConfig: {},
417
+ setDefaultConfig: (config) => {
418
+ formStore.defaultConfig = config;
419
+ },
420
+ getDefaultConfig: () => {
421
+ return utils.clone(formStore.defaultConfig);
422
+ }
423
+ };
424
+
415
425
  async function initializeHybridly(options = {}) {
416
426
  const resolved = options;
417
427
  const { element, payload, resolve } = prepare(resolved);
@@ -472,7 +482,7 @@ async function initializeHybridly(options = {}) {
472
482
  if (resolved.devtools !== false) {
473
483
  app.use(devtools);
474
484
  }
475
- await options.enhanceVue?.(app);
485
+ await options.enhanceVue?.(app, payload);
476
486
  return app.mount(element);
477
487
  }
478
488
  function prepare(options) {
@@ -503,6 +513,9 @@ function prepare(options) {
503
513
  if (options.viewTransition !== false) {
504
514
  options.plugins.push(viewTransition());
505
515
  }
516
+ if (options.defaultFormOptions) {
517
+ formStore.setDefaultConfig(options.defaultFormOptions);
518
+ }
506
519
  return {
507
520
  isServer,
508
521
  element,
@@ -768,7 +781,8 @@ function useForm(options) {
768
781
  }
769
782
  function submit(optionsOverrides) {
770
783
  const { fields: _f, key: _k, ...optionsWithoutFields } = options;
771
- const optionsWithOverrides = optionsOverrides ? utils.merge(optionsWithoutFields, optionsOverrides, { mergePlainObjects: true }) : optionsWithoutFields;
784
+ const resolvedOptions = optionsOverrides ? utils.merge(optionsWithoutFields, optionsOverrides, { mergePlainObjects: true }) : optionsWithoutFields;
785
+ const optionsWithOverrides = utils.merge(formStore.getDefaultConfig(), resolvedOptions, { mergePlainObjects: true });
772
786
  const url = typeof optionsWithOverrides.url === "function" ? optionsWithOverrides.url() : optionsWithOverrides.url;
773
787
  const data = typeof optionsWithOverrides.transform === "function" ? optionsWithOverrides.transform(fields) : fields;
774
788
  const preserveState = optionsWithOverrides.preserveState ?? optionsWithOverrides.method !== "GET";
@@ -1047,27 +1061,38 @@ function useRefinements(properties, refinementsKeys, defaultOptions = {}) {
1047
1061
  });
1048
1062
  }
1049
1063
  function bindFilter(name, options = {}) {
1050
- const debounce = options.debounce ?? 250;
1051
- const refDebounce = options.syncDebounce ?? 250;
1052
1064
  const transform = options?.transformValue ?? ((value) => value);
1053
1065
  const watchFn = options?.watch ?? vue.watch;
1054
1066
  const getFilterValue = () => transform(refinements.value.filters.find((f) => f.name === name)?.value);
1055
- const _ref = vue.ref(getFilterValue());
1056
- let _filterTimeout;
1057
- let _refTimeout;
1058
- vue.watch(() => refinements.value.filters.find((f) => f.name === name), (filter) => {
1059
- clearTimeout(_refTimeout);
1060
- _refTimeout = setTimeout(() => _ref.value = transform(filter?.value), refDebounce);
1067
+ const _proxy = vue.ref(getFilterValue());
1068
+ let filterIsBeingApplied = false;
1069
+ let proxyIsBeingUpdated = false;
1070
+ const debouncedApplyFilter = utils.debounce(options.debounce ?? 250, async (value) => {
1071
+ await applyFilter(name, transform(value), options);
1072
+ vue.nextTick(() => filterIsBeingApplied = false);
1073
+ });
1074
+ const debounceUpdateProxyValue = utils.debounce(options.syncDebounce ?? 250, () => {
1075
+ const filter = refinements.value.filters.find((f) => f.name === name);
1076
+ if (filter) {
1077
+ _proxy.value = transform(filter?.value);
1078
+ }
1079
+ vue.nextTick(() => proxyIsBeingUpdated = false);
1080
+ }, { atBegin: true });
1081
+ vue.watch(() => refinements.value.filters.find((f) => f.name === name)?.value, () => {
1082
+ if (filterIsBeingApplied === true) {
1083
+ return;
1084
+ }
1085
+ proxyIsBeingUpdated = true;
1086
+ debounceUpdateProxyValue();
1061
1087
  }, { deep: true });
1062
- watchFn(_ref, (value) => {
1063
- clearTimeout(_refTimeout);
1064
- clearTimeout(_filterTimeout);
1065
- _filterTimeout = setTimeout(() => {
1066
- clearTimeout(_refTimeout);
1067
- applyFilter(name, transform(value), options);
1068
- }, debounce);
1088
+ watchFn(_proxy, async (value) => {
1089
+ if (proxyIsBeingUpdated === true) {
1090
+ return;
1091
+ }
1092
+ filterIsBeingApplied = true;
1093
+ debouncedApplyFilter(value);
1069
1094
  });
1070
- return _ref;
1095
+ return _proxy;
1071
1096
  }
1072
1097
  return {
1073
1098
  /**
@@ -1237,9 +1262,9 @@ function useTable(props, key, defaultOptions = {}) {
1237
1262
  return record;
1238
1263
  }
1239
1264
  if (Reflect.has(record, "__hybridId")) {
1240
- return Reflect.get(record, "__hybridId");
1265
+ return Reflect.get(record, "__hybridId").value;
1241
1266
  }
1242
- return Reflect.get(record, table.value.keyName);
1267
+ return Reflect.get(record, table.value.keyName).value;
1243
1268
  }
1244
1269
  function getActionName(action) {
1245
1270
  return typeof action === "string" ? action : action.name;
@@ -1332,14 +1357,14 @@ function useTable(props, key, defaultOptions = {}) {
1332
1357
  /** Clears the filter for this column. */
1333
1358
  clearFilter: (options) => refinements.clearFilter(column.name, options),
1334
1359
  /** Checks whether the column is sortable. */
1335
- isSortable: refinements.sorts.find((sort) => sort.name === column.name),
1360
+ isSortable: !!refinements.sorts.find((sort) => sort.name === column.name),
1336
1361
  /** Checks whether the column is filterable. */
1337
- isFilterable: refinements.filters.find((filters) => filters.name === column.name)
1362
+ isFilterable: !!refinements.filters.find((filters) => filters.name === column.name)
1338
1363
  }))),
1339
1364
  /** List of records for this table. */
1340
1365
  records: vue.computed(() => table.value.records.map((record) => ({
1341
1366
  /** The actual record. */
1342
- record,
1367
+ record: Object.values(record).map((record2) => record2.value),
1343
1368
  /** The key of the record. Use this instead of `id`. */
1344
1369
  key: getRecordKey(record),
1345
1370
  /** Executes the given inline action. */
@@ -1359,7 +1384,9 @@ function useTable(props, key, defaultOptions = {}) {
1359
1384
  /** Checks whether this record is selected. */
1360
1385
  selected: bulk.selected(getRecordKey(record)),
1361
1386
  /** Gets the value of the record for the specified column. */
1362
- value: (column) => record[typeof column === "string" ? column : column.name]
1387
+ value: (column) => record[typeof column === "string" ? column : column.name].value,
1388
+ /** Gets the extra object of the record for the specified column. */
1389
+ extra: (column, path) => dotDiver.getByPath(record[typeof column === "string" ? column : column.name].extra, path)
1363
1390
  }))),
1364
1391
  /**
1365
1392
  * Paginated meta and links.