@hybridly/vue 0.0.1-alpha.7 → 0.0.1-alpha.8

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
@@ -248,6 +248,7 @@ async function initializeHybridly(options) {
248
248
  throw new Error("No payload. Are you using `@hybridly` or the `payload` option?");
249
249
  }
250
250
  state.setContext(await core.createRouter({
251
+ axios: options.axios,
251
252
  plugins: options.plugins,
252
253
  serializer: options.serializer,
253
254
  adapter: {
@@ -266,13 +267,20 @@ async function initializeHybridly(options) {
266
267
  },
267
268
  payload
268
269
  }));
269
- await options.setup({
270
- element,
271
- wrapper,
272
- hybridly: plugin,
273
- props: { context: state.context.value },
274
- render: () => vue.h(wrapper, { context: state.context.value })
275
- });
270
+ const render = () => vue.h(wrapper, { context: state.context.value });
271
+ if (options.setup) {
272
+ return await options.setup({
273
+ element,
274
+ wrapper,
275
+ render,
276
+ hybridly: plugin,
277
+ props: { context: state.context.value }
278
+ });
279
+ }
280
+ const app = vue.createApp({ render });
281
+ app.use(plugin);
282
+ await options.enhanceVue?.(app);
283
+ return app.mount(element);
276
284
  }
277
285
  function prepare(options) {
278
286
  utils.debug.adapter("vue", "Preparing Hybridly with options:", options);
@@ -530,8 +538,10 @@ function useForm(options) {
530
538
  if (keys.length === 0) {
531
539
  keys = Object.keys(fields);
532
540
  }
533
- keys.forEach((key) => Reflect.set(fields, key, safeClone(Reflect.get(initial, key))));
534
- clearErrors();
541
+ keys.forEach((key) => {
542
+ Reflect.set(fields, key, safeClone(Reflect.get(initial, key)));
543
+ clearError(key);
544
+ });
535
545
  }
536
546
  function submit(optionsOverrides) {
537
547
  const url = typeof options.url === "function" ? options.url() : options.url;
@@ -585,8 +595,16 @@ function useForm(options) {
585
595
  }
586
596
  });
587
597
  }
588
- function clearErrors() {
589
- errors.value = {};
598
+ function clearErrors(...keys) {
599
+ if (keys.length === 0) {
600
+ keys = Object.keys(fields);
601
+ }
602
+ keys.forEach((key) => {
603
+ clearError(key);
604
+ });
605
+ }
606
+ function clearError(key) {
607
+ errors.value[key] = void 0;
590
608
  }
591
609
  function setErrors(incoming) {
592
610
  errors.value = incoming;
@@ -609,6 +627,7 @@ function useForm(options) {
609
627
  abort,
610
628
  setErrors,
611
629
  clearErrors,
630
+ clearError,
612
631
  submitWithOptions: submit,
613
632
  submit: () => submit(),
614
633
  hasErrors: vue.computed(() => Object.values(errors.value).length > 0),
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import * as vue from 'vue';
2
- import { Plugin as Plugin$2, h, PropType, ComputedRef, DeepReadonly } from 'vue';
2
+ import { App, Plugin as Plugin$2, h, PropType, ComputedRef, DeepReadonly } from 'vue';
3
3
  import * as _hybridly_core from '@hybridly/core';
4
4
  import { HybridPayload as HybridPayload$1, ResolveComponent as ResolveComponent$1, RouterContextOptions, Plugin as Plugin$1, RouterContext, Method as Method$1, HybridRequestOptions as HybridRequestOptions$1, UrlResolvable as UrlResolvable$1 } from '@hybridly/core';
5
5
  export { can, router } from '@hybridly/core';
6
6
  import { ProgressOptions } from '@hybridly/progress-plugin';
7
+ import { Axios, AxiosResponse, AxiosProgressEvent } from 'axios';
7
8
  import * as _vue_shared from '@vue/shared';
8
9
  import { RequestData } from '@hybridly/utils';
9
- import { AxiosResponse, AxiosProgressEvent } from 'axios';
10
10
 
11
- declare function initializeHybridly(options: HybridlyOptions): Promise<void>;
11
+ declare function initializeHybridly(options: HybridlyOptions): Promise<any>;
12
12
  interface HybridlyOptions {
13
13
  /** ID of the app element. */
14
14
  id?: string;
@@ -27,9 +27,13 @@ interface HybridlyOptions {
27
27
  /** Progressbar options. */
28
28
  progress?: boolean | Partial<ProgressOptions>;
29
29
  /** Sets up the hybridly router. */
30
- setup: (options: SetupArguments) => any;
30
+ setup?: (options: SetupArguments) => any;
31
31
  /** List of Hybridly plugins. */
32
32
  plugins?: Plugin$1[];
33
+ /** Callback that gets executed before Vue is mounted. */
34
+ enhanceVue?: (vue: App<Element>) => any;
35
+ /** Custom Axios instance. */
36
+ axios?: Axios;
33
37
  }
34
38
  interface SetupArguments {
35
39
  /** DOM element to mount Vue on. */
@@ -56,7 +60,7 @@ declare const RouterLink: vue.DefineComponent<{
56
60
  default: string;
57
61
  };
58
62
  method: {
59
- type: PropType<Method$1 | "get" | "delete" | "post" | "put" | "patch">;
63
+ type: PropType<"get" | "delete" | "post" | "put" | "patch" | Method$1>;
60
64
  default: string;
61
65
  };
62
66
  data: {
@@ -85,7 +89,7 @@ declare const RouterLink: vue.DefineComponent<{
85
89
  default: string;
86
90
  };
87
91
  method: {
88
- type: PropType<Method$1 | "get" | "delete" | "post" | "put" | "patch">;
92
+ type: PropType<"get" | "delete" | "post" | "put" | "patch" | Method$1>;
89
93
  default: string;
90
94
  };
91
95
  data: {
@@ -116,7 +120,7 @@ declare const RouterLink: vue.DefineComponent<{
116
120
  default: string;
117
121
  };
118
122
  method: {
119
- type: PropType<Method$1 | "get" | "delete" | "post" | "put" | "patch">;
123
+ type: PropType<"get" | "delete" | "post" | "put" | "patch" | Method$1>;
120
124
  default: string;
121
125
  };
122
126
  data: {
@@ -137,7 +141,7 @@ declare const RouterLink: vue.DefineComponent<{
137
141
  };
138
142
  }>>, {
139
143
  data: RequestData;
140
- method: Method$1 | "get" | "delete" | "post" | "put" | "patch";
144
+ method: "get" | "delete" | "post" | "put" | "patch" | Method$1;
141
145
  options: Omit<HybridRequestOptions$1, "url" | "data" | "method">;
142
146
  as: string | Record<string, any>;
143
147
  external: boolean;
@@ -292,6 +296,11 @@ interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
292
296
  hooks?: Partial<Hooks>;
293
297
  /** If `true`, force the usage of a `FormData` object. */
294
298
  useFormData?: boolean;
299
+ /**
300
+ * If `false`, disable automatic form spoofing.
301
+ * @see https://laravel.com/docs/9.x/routing#form-method-spoofing
302
+ */
303
+ spoof?: boolean;
295
304
  }
296
305
  /** A navigation being made. */
297
306
  interface PendingNavigation {
@@ -376,6 +385,8 @@ interface InternalRouterContext {
376
385
  plugins: Plugin[];
377
386
  /** Global hooks. */
378
387
  hooks: Partial<Record<keyof Hooks, Array<Function>>>;
388
+ /** The Axios instance. */
389
+ axios: Axios;
379
390
  }
380
391
  /** Adapter-specific functions. */
381
392
  interface Adapter {
@@ -415,7 +426,8 @@ declare function useForm<T extends Fields = Fields>(options: FormOptions<T>): {
415
426
  fields: vue.UnwrapRef<vue.UnwrapNestedRefs<T>>;
416
427
  abort: () => void;
417
428
  setErrors: (incoming: Record<string, string>) => void;
418
- clearErrors: () => void;
429
+ clearErrors: (...keys: (keyof T)[]) => void;
430
+ clearError: (key: keyof T) => void;
419
431
  submitWithOptions: (optionsOverrides?: Omit<HybridRequestOptions$1, 'data'>) => Promise<_hybridly_core.NavigationResponse>;
420
432
  submit: () => Promise<_hybridly_core.NavigationResponse>;
421
433
  hasErrors: boolean;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ref, shallowRef, unref, triggerRef, defineComponent, h, isRef, reactive, readonly, computed, watch, toRaw } from 'vue';
1
+ import { ref, shallowRef, unref, triggerRef, defineComponent, h, createApp, isRef, reactive, readonly, computed, watch, toRaw } from 'vue';
2
2
  import { registerHook, createRouter, makeUrl, router } from '@hybridly/core';
3
3
  export { can, router } from '@hybridly/core';
4
4
  import { debug, showPageComponentErrorModal, merge, clone } from '@hybridly/utils';
@@ -240,6 +240,7 @@ async function initializeHybridly(options) {
240
240
  throw new Error("No payload. Are you using `@hybridly` or the `payload` option?");
241
241
  }
242
242
  state.setContext(await createRouter({
243
+ axios: options.axios,
243
244
  plugins: options.plugins,
244
245
  serializer: options.serializer,
245
246
  adapter: {
@@ -258,13 +259,20 @@ async function initializeHybridly(options) {
258
259
  },
259
260
  payload
260
261
  }));
261
- await options.setup({
262
- element,
263
- wrapper,
264
- hybridly: plugin,
265
- props: { context: state.context.value },
266
- render: () => h(wrapper, { context: state.context.value })
267
- });
262
+ const render = () => h(wrapper, { context: state.context.value });
263
+ if (options.setup) {
264
+ return await options.setup({
265
+ element,
266
+ wrapper,
267
+ render,
268
+ hybridly: plugin,
269
+ props: { context: state.context.value }
270
+ });
271
+ }
272
+ const app = createApp({ render });
273
+ app.use(plugin);
274
+ await options.enhanceVue?.(app);
275
+ return app.mount(element);
268
276
  }
269
277
  function prepare(options) {
270
278
  debug.adapter("vue", "Preparing Hybridly with options:", options);
@@ -522,8 +530,10 @@ function useForm(options) {
522
530
  if (keys.length === 0) {
523
531
  keys = Object.keys(fields);
524
532
  }
525
- keys.forEach((key) => Reflect.set(fields, key, safeClone(Reflect.get(initial, key))));
526
- clearErrors();
533
+ keys.forEach((key) => {
534
+ Reflect.set(fields, key, safeClone(Reflect.get(initial, key)));
535
+ clearError(key);
536
+ });
527
537
  }
528
538
  function submit(optionsOverrides) {
529
539
  const url = typeof options.url === "function" ? options.url() : options.url;
@@ -577,8 +587,16 @@ function useForm(options) {
577
587
  }
578
588
  });
579
589
  }
580
- function clearErrors() {
581
- errors.value = {};
590
+ function clearErrors(...keys) {
591
+ if (keys.length === 0) {
592
+ keys = Object.keys(fields);
593
+ }
594
+ keys.forEach((key) => {
595
+ clearError(key);
596
+ });
597
+ }
598
+ function clearError(key) {
599
+ errors.value[key] = void 0;
582
600
  }
583
601
  function setErrors(incoming) {
584
602
  errors.value = incoming;
@@ -601,6 +619,7 @@ function useForm(options) {
601
619
  abort,
602
620
  setErrors,
603
621
  clearErrors,
622
+ clearError,
604
623
  submitWithOptions: submit,
605
624
  submit: () => submit(),
606
625
  hasErrors: computed(() => Object.values(errors.value).length > 0),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybridly/vue",
3
- "version": "0.0.1-alpha.7",
3
+ "version": "0.0.1-alpha.8",
4
4
  "description": "A solution to develop server-driven, client-rendered applications",
5
5
  "keywords": [
6
6
  "hybridly",
@@ -38,9 +38,9 @@
38
38
  "vue": "^3.2.37"
39
39
  },
40
40
  "dependencies": {
41
- "@hybridly/core": "0.0.1-alpha.7",
42
- "@hybridly/progress-plugin": "0.0.1-alpha.7",
43
- "@hybridly/utils": "0.0.1-alpha.7",
41
+ "@hybridly/core": "0.0.1-alpha.8",
42
+ "@hybridly/progress-plugin": "0.0.1-alpha.8",
43
+ "@hybridly/utils": "0.0.1-alpha.8",
44
44
  "@vue/devtools-api": "^6.4.4",
45
45
  "defu": "^6.1.0",
46
46
  "lodash.isequal": "^4.5.0",