@hybridly/vue 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.cjs +4 -4
- package/dist/index.d.ts +16 -16
- package/dist/index.mjs +5 -5
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -645,15 +645,15 @@ function useForm(options) {
|
|
|
645
645
|
if (keys.length === 0) {
|
|
646
646
|
return isDirty.value;
|
|
647
647
|
}
|
|
648
|
-
return keys.some((key) => !isEqual__default(vue.toRaw(fields
|
|
648
|
+
return keys.some((key) => !isEqual__default(vue.toRaw(dotDiver.getByPath(fields, key)), vue.toRaw(dotDiver.getByPath(initial, key))));
|
|
649
649
|
}
|
|
650
650
|
function clearError(key) {
|
|
651
|
-
|
|
651
|
+
utils.unsetPropertyAtPath(errors.value, key);
|
|
652
652
|
}
|
|
653
653
|
function setErrors(incoming) {
|
|
654
654
|
clearErrors();
|
|
655
|
-
Object.entries(incoming).forEach(([
|
|
656
|
-
errors.value
|
|
655
|
+
Object.entries(incoming).forEach(([path, value]) => {
|
|
656
|
+
utils.setValueAtPath(errors.value, path, value);
|
|
657
657
|
});
|
|
658
658
|
}
|
|
659
659
|
function abort() {
|
package/dist/index.d.ts
CHANGED
|
@@ -218,7 +218,7 @@ interface RequestHooks {
|
|
|
218
218
|
/**
|
|
219
219
|
* Called when a request is successful but there were errors.
|
|
220
220
|
*/
|
|
221
|
-
error: (errors: Errors, context: InternalRouterContext) => MaybePromise<any>;
|
|
221
|
+
error: (errors: Errors$1, context: InternalRouterContext) => MaybePromise<any>;
|
|
222
222
|
/**
|
|
223
223
|
* Called when a request has been aborted.
|
|
224
224
|
*/
|
|
@@ -406,9 +406,7 @@ interface Progress {
|
|
|
406
406
|
/** Computed percentage. */
|
|
407
407
|
percentage: Readonly<number>;
|
|
408
408
|
}
|
|
409
|
-
|
|
410
|
-
[key: string]: string;
|
|
411
|
-
}
|
|
409
|
+
type Errors$1 = any;
|
|
412
410
|
|
|
413
411
|
interface Plugin extends Partial<Hooks> {
|
|
414
412
|
/** Identifier of the plugin. */
|
|
@@ -475,8 +473,10 @@ interface Serializer {
|
|
|
475
473
|
/** Accesses the hybridly context. */
|
|
476
474
|
declare function useContext(): vue.ComputedRef<Readonly<InternalRouterContext> | undefined>;
|
|
477
475
|
|
|
478
|
-
type
|
|
479
|
-
|
|
476
|
+
type Errors<T extends SearchableObject> = {
|
|
477
|
+
[K in keyof T]?: T[K] extends Record<string, any> ? Errors<T[K]> : string;
|
|
478
|
+
};
|
|
479
|
+
interface FormOptions<T extends SearchableObject> extends Omit<HybridRequestOptions$1, 'data' | 'url'> {
|
|
480
480
|
fields: T;
|
|
481
481
|
url?: UrlResolvable$1 | (() => UrlResolvable$1);
|
|
482
482
|
key?: string | false;
|
|
@@ -497,18 +497,18 @@ interface FormOptions<T extends Fields> extends Omit<HybridRequestOptions$1, 'da
|
|
|
497
497
|
/**
|
|
498
498
|
* Callback executed before the form submission for transforming the fields.
|
|
499
499
|
*/
|
|
500
|
-
transform?: (fields: T) =>
|
|
500
|
+
transform?: (fields: T) => any;
|
|
501
501
|
}
|
|
502
|
-
declare function useForm<T extends
|
|
503
|
-
reset: (...keys:
|
|
504
|
-
clear: (...keys:
|
|
505
|
-
fields: vue.UnwrapRef<
|
|
502
|
+
declare function useForm<T extends SearchableObject, P extends Path<T> & string = Path<T> & string>(options: FormOptions<T>): {
|
|
503
|
+
reset: (...keys: P[]) => void;
|
|
504
|
+
clear: (...keys: P[]) => void;
|
|
505
|
+
fields: vue.UnwrapRef<T>;
|
|
506
506
|
abort: () => void;
|
|
507
|
-
setErrors: (incoming:
|
|
508
|
-
clearErrors: (...keys:
|
|
509
|
-
clearError: (key:
|
|
507
|
+
setErrors: (incoming: Errors<T>) => void;
|
|
508
|
+
clearErrors: (...keys: P[]) => void;
|
|
509
|
+
clearError: (key: P) => void;
|
|
510
510
|
setInitial: (newInitial: Partial<T>) => void;
|
|
511
|
-
hasDirty: (...keys:
|
|
511
|
+
hasDirty: (...keys: P[]) => boolean;
|
|
512
512
|
submitWithOptions: (optionsOverrides?: Omit<HybridRequestOptions$1, 'data'>) => Promise<_hybridly_core.NavigationResponse>;
|
|
513
513
|
submit: () => Promise<_hybridly_core.NavigationResponse>;
|
|
514
514
|
hasErrors: boolean;
|
|
@@ -529,7 +529,7 @@ declare function useForm<T extends Fields = Fields>(options: FormOptions<T>): {
|
|
|
529
529
|
readonly percentage: number;
|
|
530
530
|
} | undefined;
|
|
531
531
|
isDirty: boolean;
|
|
532
|
-
errors: vue.UnwrapRef<DeepReadonly<[
|
|
532
|
+
errors: vue.UnwrapRef<DeepReadonly<[Errors<T>] extends [vue.Ref<any>] ? vue.Ref<any> & Errors<T> : vue.Ref<vue.UnwrapRef<Errors<T>>>>>;
|
|
533
533
|
processing: boolean;
|
|
534
534
|
successful: boolean;
|
|
535
535
|
failed: boolean;
|
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, watch, getCurrentInstance, onUnmounted } from 'vue';
|
|
2
2
|
import { registerHook as registerHook$1, createRouter, makeUrl, router } from '@hybridly/core';
|
|
3
3
|
export { can, route, router } from '@hybridly/core';
|
|
4
|
-
import { debug, random, showDomainsDisabledErrorModal, showPageComponentErrorModal, merge, clone } from '@hybridly/utils';
|
|
4
|
+
import { debug, random, showDomainsDisabledErrorModal, showPageComponentErrorModal, merge, clone, unsetPropertyAtPath, setValueAtPath } from '@hybridly/utils';
|
|
5
5
|
import { progress } from '@hybridly/progress-plugin';
|
|
6
6
|
import { setupDevtoolsPlugin } from '@vue/devtools-api';
|
|
7
7
|
import qs from 'qs';
|
|
@@ -637,15 +637,15 @@ function useForm(options) {
|
|
|
637
637
|
if (keys.length === 0) {
|
|
638
638
|
return isDirty.value;
|
|
639
639
|
}
|
|
640
|
-
return keys.some((key) => !isEqual(toRaw(fields
|
|
640
|
+
return keys.some((key) => !isEqual(toRaw(getByPath(fields, key)), toRaw(getByPath(initial, key))));
|
|
641
641
|
}
|
|
642
642
|
function clearError(key) {
|
|
643
|
-
|
|
643
|
+
unsetPropertyAtPath(errors.value, key);
|
|
644
644
|
}
|
|
645
645
|
function setErrors(incoming) {
|
|
646
646
|
clearErrors();
|
|
647
|
-
Object.entries(incoming).forEach(([
|
|
648
|
-
errors.value
|
|
647
|
+
Object.entries(incoming).forEach(([path, value]) => {
|
|
648
|
+
setValueAtPath(errors.value, path, value);
|
|
649
649
|
});
|
|
650
650
|
}
|
|
651
651
|
function abort() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hybridly/vue",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Vue adapter for Hybridly",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hybridly",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"lodash.isequal": "^4.5.0",
|
|
45
45
|
"nprogress": "^0.2.0",
|
|
46
46
|
"qs": "^6.11.1",
|
|
47
|
-
"@hybridly/config": "0.3.
|
|
48
|
-
"@hybridly/core": "0.3.
|
|
49
|
-
"@hybridly/progress-plugin": "0.3.
|
|
50
|
-
"@hybridly/utils": "0.3.
|
|
47
|
+
"@hybridly/config": "0.3.1",
|
|
48
|
+
"@hybridly/core": "0.3.1",
|
|
49
|
+
"@hybridly/progress-plugin": "0.3.1",
|
|
50
|
+
"@hybridly/utils": "0.3.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/lodash": "^4.14.194",
|