@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.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { shallowRef, ref, unref, triggerRef, defineComponent, toRaw, h, nextTick, createApp, isRef, reactive, readonly, computed, toValue, watch, getCurrentInstance, onUnmounted } from 'vue';
2
2
  import { definePlugin, registerHook as registerHook$1, createRouter, makeUrl, router, route } from '@hybridly/core';
3
3
  export { can, route, router } from '@hybridly/core';
4
- import { debug, random, showViewComponentErrorModal, merge, clone, unsetPropertyAtPath, setValueAtPath } from '@hybridly/utils';
4
+ import { debug, clone, random, showViewComponentErrorModal, merge, unsetPropertyAtPath, setValueAtPath, debounce } from '@hybridly/utils';
5
5
  import nprogress from 'nprogress';
6
6
  import { setupDevtoolsPlugin } from '@vue/devtools-api';
7
7
  import qs from 'qs';
@@ -405,6 +405,16 @@ function viewTransition() {
405
405
  };
406
406
  }
407
407
 
408
+ const formStore = {
409
+ defaultConfig: {},
410
+ setDefaultConfig: (config) => {
411
+ formStore.defaultConfig = config;
412
+ },
413
+ getDefaultConfig: () => {
414
+ return clone(formStore.defaultConfig);
415
+ }
416
+ };
417
+
408
418
  async function initializeHybridly(options = {}) {
409
419
  const resolved = options;
410
420
  const { element, payload, resolve } = prepare(resolved);
@@ -465,7 +475,7 @@ async function initializeHybridly(options = {}) {
465
475
  if (resolved.devtools !== false) {
466
476
  app.use(devtools);
467
477
  }
468
- await options.enhanceVue?.(app);
478
+ await options.enhanceVue?.(app, payload);
469
479
  return app.mount(element);
470
480
  }
471
481
  function prepare(options) {
@@ -496,6 +506,9 @@ function prepare(options) {
496
506
  if (options.viewTransition !== false) {
497
507
  options.plugins.push(viewTransition());
498
508
  }
509
+ if (options.defaultFormOptions) {
510
+ formStore.setDefaultConfig(options.defaultFormOptions);
511
+ }
499
512
  return {
500
513
  isServer,
501
514
  element,
@@ -761,7 +774,8 @@ function useForm(options) {
761
774
  }
762
775
  function submit(optionsOverrides) {
763
776
  const { fields: _f, key: _k, ...optionsWithoutFields } = options;
764
- const optionsWithOverrides = optionsOverrides ? merge(optionsWithoutFields, optionsOverrides, { mergePlainObjects: true }) : optionsWithoutFields;
777
+ const resolvedOptions = optionsOverrides ? merge(optionsWithoutFields, optionsOverrides, { mergePlainObjects: true }) : optionsWithoutFields;
778
+ const optionsWithOverrides = merge(formStore.getDefaultConfig(), resolvedOptions, { mergePlainObjects: true });
765
779
  const url = typeof optionsWithOverrides.url === "function" ? optionsWithOverrides.url() : optionsWithOverrides.url;
766
780
  const data = typeof optionsWithOverrides.transform === "function" ? optionsWithOverrides.transform(fields) : fields;
767
781
  const preserveState = optionsWithOverrides.preserveState ?? optionsWithOverrides.method !== "GET";
@@ -1040,27 +1054,38 @@ function useRefinements(properties, refinementsKeys, defaultOptions = {}) {
1040
1054
  });
1041
1055
  }
1042
1056
  function bindFilter(name, options = {}) {
1043
- const debounce = options.debounce ?? 250;
1044
- const refDebounce = options.syncDebounce ?? 250;
1045
1057
  const transform = options?.transformValue ?? ((value) => value);
1046
1058
  const watchFn = options?.watch ?? watch;
1047
1059
  const getFilterValue = () => transform(refinements.value.filters.find((f) => f.name === name)?.value);
1048
- const _ref = ref(getFilterValue());
1049
- let _filterTimeout;
1050
- let _refTimeout;
1051
- watch(() => refinements.value.filters.find((f) => f.name === name), (filter) => {
1052
- clearTimeout(_refTimeout);
1053
- _refTimeout = setTimeout(() => _ref.value = transform(filter?.value), refDebounce);
1060
+ const _proxy = ref(getFilterValue());
1061
+ let filterIsBeingApplied = false;
1062
+ let proxyIsBeingUpdated = false;
1063
+ const debouncedApplyFilter = debounce(options.debounce ?? 250, async (value) => {
1064
+ await applyFilter(name, transform(value), options);
1065
+ nextTick(() => filterIsBeingApplied = false);
1066
+ });
1067
+ const debounceUpdateProxyValue = debounce(options.syncDebounce ?? 250, () => {
1068
+ const filter = refinements.value.filters.find((f) => f.name === name);
1069
+ if (filter) {
1070
+ _proxy.value = transform(filter?.value);
1071
+ }
1072
+ nextTick(() => proxyIsBeingUpdated = false);
1073
+ }, { atBegin: true });
1074
+ watch(() => refinements.value.filters.find((f) => f.name === name)?.value, () => {
1075
+ if (filterIsBeingApplied === true) {
1076
+ return;
1077
+ }
1078
+ proxyIsBeingUpdated = true;
1079
+ debounceUpdateProxyValue();
1054
1080
  }, { deep: true });
1055
- watchFn(_ref, (value) => {
1056
- clearTimeout(_refTimeout);
1057
- clearTimeout(_filterTimeout);
1058
- _filterTimeout = setTimeout(() => {
1059
- clearTimeout(_refTimeout);
1060
- applyFilter(name, transform(value), options);
1061
- }, debounce);
1081
+ watchFn(_proxy, async (value) => {
1082
+ if (proxyIsBeingUpdated === true) {
1083
+ return;
1084
+ }
1085
+ filterIsBeingApplied = true;
1086
+ debouncedApplyFilter(value);
1062
1087
  });
1063
- return _ref;
1088
+ return _proxy;
1064
1089
  }
1065
1090
  return {
1066
1091
  /**
@@ -1230,9 +1255,9 @@ function useTable(props, key, defaultOptions = {}) {
1230
1255
  return record;
1231
1256
  }
1232
1257
  if (Reflect.has(record, "__hybridId")) {
1233
- return Reflect.get(record, "__hybridId");
1258
+ return Reflect.get(record, "__hybridId").value;
1234
1259
  }
1235
- return Reflect.get(record, table.value.keyName);
1260
+ return Reflect.get(record, table.value.keyName).value;
1236
1261
  }
1237
1262
  function getActionName(action) {
1238
1263
  return typeof action === "string" ? action : action.name;
@@ -1325,14 +1350,14 @@ function useTable(props, key, defaultOptions = {}) {
1325
1350
  /** Clears the filter for this column. */
1326
1351
  clearFilter: (options) => refinements.clearFilter(column.name, options),
1327
1352
  /** Checks whether the column is sortable. */
1328
- isSortable: refinements.sorts.find((sort) => sort.name === column.name),
1353
+ isSortable: !!refinements.sorts.find((sort) => sort.name === column.name),
1329
1354
  /** Checks whether the column is filterable. */
1330
- isFilterable: refinements.filters.find((filters) => filters.name === column.name)
1355
+ isFilterable: !!refinements.filters.find((filters) => filters.name === column.name)
1331
1356
  }))),
1332
1357
  /** List of records for this table. */
1333
1358
  records: computed(() => table.value.records.map((record) => ({
1334
1359
  /** The actual record. */
1335
- record,
1360
+ record: Object.values(record).map((record2) => record2.value),
1336
1361
  /** The key of the record. Use this instead of `id`. */
1337
1362
  key: getRecordKey(record),
1338
1363
  /** Executes the given inline action. */
@@ -1352,7 +1377,9 @@ function useTable(props, key, defaultOptions = {}) {
1352
1377
  /** Checks whether this record is selected. */
1353
1378
  selected: bulk.selected(getRecordKey(record)),
1354
1379
  /** Gets the value of the record for the specified column. */
1355
- value: (column) => record[typeof column === "string" ? column : column.name]
1380
+ value: (column) => record[typeof column === "string" ? column : column.name].value,
1381
+ /** Gets the extra object of the record for the specified column. */
1382
+ extra: (column, path) => getByPath(record[typeof column === "string" ? column : column.name].extra, path)
1356
1383
  }))),
1357
1384
  /**
1358
1385
  * Paginated meta and links.
package/package.json CHANGED
@@ -1,63 +1,64 @@
1
1
  {
2
2
  "name": "@hybridly/vue",
3
- "version": "0.7.7",
3
+ "type": "module",
4
+ "version": "0.7.9",
4
5
  "description": "Vue adapter for Hybridly",
5
- "keywords": [
6
- "hybridly",
7
- "inertiajs",
8
- "vue",
9
- "vue-plugin"
10
- ],
11
- "homepage": "https://github.com/hybridly/hybridly/tree/main/packages/vue#readme",
12
- "bugs": {
13
- "url": "https://github.com/hybridly/hybridly/issues"
14
- },
6
+ "author": "Enzo Innocenzi <enzo@innocenzi.dev>",
15
7
  "license": "MIT",
8
+ "funding": "https://github.com/sponsors/innocenzi",
9
+ "homepage": "https://github.com/hybridly/hybridly/tree/main/packages/vue#readme",
16
10
  "repository": {
17
11
  "type": "git",
18
12
  "url": "git+https://github.com/hybridly/hybridly.git",
19
13
  "directory": "packages/vue"
20
14
  },
21
- "funding": "https://github.com/sponsors/innocenzi",
22
- "author": "Enzo Innocenzi <enzo@innocenzi.dev>",
15
+ "bugs": {
16
+ "url": "https://github.com/hybridly/hybridly/issues"
17
+ },
18
+ "keywords": [
19
+ "hybridly",
20
+ "inertiajs",
21
+ "vue",
22
+ "vue-plugin"
23
+ ],
23
24
  "publishConfig": {
24
25
  "provenance": true,
25
26
  "access": "public"
26
27
  },
27
28
  "sideEffects": false,
28
- "type": "module",
29
- "files": [
30
- "dist"
31
- ],
32
29
  "exports": {
33
30
  ".": {
34
- "require": "./dist/index.cjs",
31
+ "types": "./dist/index.d.ts",
35
32
  "import": "./dist/index.mjs",
36
- "types": "./dist/index.d.ts"
33
+ "require": "./dist/index.cjs"
37
34
  }
38
35
  },
39
36
  "main": "dist/index.cjs",
40
37
  "module": "dist/index.mjs",
41
38
  "types": "dist/index.d.ts",
39
+ "files": [
40
+ "dist"
41
+ ],
42
42
  "peerDependencies": {
43
43
  "vue": "^3.2.45"
44
44
  },
45
45
  "dependencies": {
46
46
  "@clickbar/dot-diver": "^1.0.6",
47
- "@vue/devtools-api": "^6.6.1",
47
+ "@vue/devtools-api": "^7.3.5",
48
48
  "defu": "^6.1.4",
49
49
  "lodash.isequal": "^4.5.0",
50
50
  "nprogress": "^0.2.0",
51
51
  "qs": "^6.12.1",
52
- "@hybridly/core": "0.7.7",
53
- "@hybridly/utils": "0.7.7"
52
+ "@hybridly/core": "0.7.9",
53
+ "@hybridly/utils": "0.7.9"
54
54
  },
55
55
  "devDependencies": {
56
- "@types/lodash": "^4.17.0",
56
+ "@types/lodash": "^4.17.6",
57
57
  "@types/lodash.isequal": "^4.5.8",
58
58
  "@types/nprogress": "^0.2.3",
59
- "@vue/test-utils": "^2.4.5",
60
- "vue": "^3.4.23"
59
+ "@vue/test-utils": "^2.4.6",
60
+ "axios": "^1.7.2",
61
+ "vue": "^3.4.31"
61
62
  },
62
63
  "scripts": {
63
64
  "build": "unbuild",