@hybridly/vue 0.0.1-alpha.4 → 0.0.1-alpha.6

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
@@ -21,6 +21,7 @@ const state = {
21
21
  context: vue.ref(),
22
22
  view: vue.shallowRef(),
23
23
  viewLayout: vue.shallowRef(),
24
+ viewLayoutProperties: vue.ref(),
24
25
  viewKey: vue.ref(),
25
26
  dialog: vue.shallowRef(),
26
27
  dialogKey: vue.ref(),
@@ -36,9 +37,13 @@ const state = {
36
37
  state.view.value = view;
37
38
  },
38
39
  setViewLayout(layout) {
39
- utils.debug.adapter("vue:state:view", "Setting layout:", layout);
40
+ utils.debug.adapter("vue:state:view", "Setting layout", layout);
40
41
  state.viewLayout.value = layout;
41
42
  },
43
+ setViewLayoutProperties(properties) {
44
+ utils.debug.adapter("vue:state:view", "Setting layout properties:", properties);
45
+ state.viewLayoutProperties.value = properties;
46
+ },
42
47
  setDialog(dialog) {
43
48
  utils.debug.adapter("vue:state:dialog", "Setting dialog:", dialog);
44
49
  state.dialog.value = dialog;
@@ -75,11 +80,17 @@ const wrapper = vue.defineComponent({
75
80
  if (Array.isArray(state.view.value?.layout)) {
76
81
  return state.view.value.layout.concat(child).reverse().reduce((child2, layout) => {
77
82
  layout.inheritAttrs = !!layout.inheritAttrs;
78
- return vue.h(layout, { ...state.context.value.view.properties }, () => child2);
83
+ return vue.h(layout, {
84
+ ...state.view.value?.layoutProperties ?? {},
85
+ ...state.context.value.view.properties
86
+ }, () => child2);
79
87
  });
80
88
  }
81
89
  return [
82
- vue.h(state.view.value?.layout, { ...state.context.value.view.properties }, () => child),
90
+ vue.h(state.view.value?.layout, {
91
+ ...state.view.value?.layoutProperties ?? {},
92
+ ...state.context.value.view.properties
93
+ }, () => child),
83
94
  renderDialog()
84
95
  ];
85
96
  }
@@ -107,6 +118,10 @@ const wrapper = vue.defineComponent({
107
118
  state.view.value.layout = state.viewLayout.value;
108
119
  state.viewLayout.value = void 0;
109
120
  }
121
+ if (state.viewLayoutProperties.value) {
122
+ state.view.value.layoutProperties = state.viewLayoutProperties.value;
123
+ state.viewLayoutProperties.value = void 0;
124
+ }
110
125
  if (state.view.value.layout) {
111
126
  return renderLayout(view);
112
127
  }
@@ -413,7 +428,8 @@ const HybridlyImports = {
413
428
  "useForm",
414
429
  "useHistoryState",
415
430
  "usePaginator",
416
- "useLayout",
431
+ "defineLayout",
432
+ "defineLayoutProperties",
417
433
  "route"
418
434
  ],
419
435
  "hybridly": [
@@ -504,8 +520,8 @@ function useForm(options) {
504
520
  recentlyFailed: void 0,
505
521
  recentlySuccessful: void 0
506
522
  };
507
- const initial = vue.readonly(safeClone(options.fields));
508
- const loaded = vue.readonly(safeClone(historyData?.fields ?? options.fields));
523
+ const initial = safeClone(options.fields);
524
+ const loaded = safeClone(historyData?.fields ?? options.fields);
509
525
  const fields = vue.reactive(safeClone(historyData?.fields ?? options.fields));
510
526
  const errors = vue.ref(historyData?.errors ?? {});
511
527
  const isDirty = vue.ref(false);
@@ -514,6 +530,7 @@ function useForm(options) {
514
530
  const recentlyFailed = vue.ref(false);
515
531
  const failed = vue.ref(false);
516
532
  const processing = vue.ref(false);
533
+ const progress = vue.ref();
517
534
  function reset(...keys) {
518
535
  if (keys.length === 0) {
519
536
  keys = Object.keys(fields);
@@ -525,6 +542,7 @@ function useForm(options) {
525
542
  const url = typeof options.url === "function" ? options.url() : options.url;
526
543
  const data = typeof options.transform === "function" ? options.transform?.(fields) : fields;
527
544
  return core.router.visit({
545
+ ...options,
528
546
  url: url ?? state.context.value?.url,
529
547
  method: options.method ?? "POST",
530
548
  ...optionsOverrides,
@@ -544,6 +562,10 @@ function useForm(options) {
544
562
  processing.value = true;
545
563
  return options.hooks?.start?.(context);
546
564
  },
565
+ progress: (incoming) => {
566
+ progress.value = incoming;
567
+ return options.hooks?.progress?.(incoming);
568
+ },
547
569
  error: (incoming) => {
548
570
  setErrors(incoming);
549
571
  failed.value = true;
@@ -561,6 +583,7 @@ function useForm(options) {
561
583
  return options.hooks?.success?.(payload);
562
584
  },
563
585
  after: (context) => {
586
+ progress.value = void 0;
564
587
  processing.value = false;
565
588
  return options.hooks?.after?.(context);
566
589
  }
@@ -587,21 +610,23 @@ function useForm(options) {
587
610
  }, { deep: true, immediate: true });
588
611
  return vue.reactive({
589
612
  reset,
590
- initial,
591
613
  fields,
592
- loaded,
593
- submit,
594
614
  abort,
595
615
  setErrors,
596
616
  clearErrors,
617
+ submitWithOptions: submit,
618
+ submit: () => submit(),
597
619
  hasErrors: vue.computed(() => Object.values(errors.value).length > 0),
598
- isDirty: vue.readonly(isDirty),
599
- errors: vue.readonly(errors),
600
- processing: vue.readonly(processing),
601
- successful: vue.readonly(successful),
602
- failed: vue.readonly(failed),
603
- recentlySuccessful: vue.readonly(recentlySuccessful),
604
- recentlyFailed: vue.readonly(recentlyFailed)
620
+ initial,
621
+ loaded,
622
+ progress,
623
+ isDirty,
624
+ errors,
625
+ processing,
626
+ successful,
627
+ failed,
628
+ recentlySuccessful,
629
+ recentlyFailed
605
630
  });
606
631
  }
607
632
 
@@ -660,8 +685,14 @@ function usePaginator(paginator) {
660
685
  return { pages, items, previous, next, first, last, total, from, to };
661
686
  }
662
687
 
663
- function defineLayout(layout) {
664
- state.setViewLayout(layout);
688
+ function defineLayout(...args) {
689
+ const layouts = args[0];
690
+ const properties = args[1];
691
+ state.setViewLayout(layouts);
692
+ state.setViewLayoutProperties(properties);
693
+ }
694
+ function defineLayoutProperties(properties) {
695
+ state.setViewLayoutProperties(properties);
665
696
  }
666
697
 
667
698
  class Route {
@@ -672,7 +703,7 @@ class Route {
672
703
  }
673
704
  static getDefinition(name) {
674
705
  if (!state.routes.value) {
675
- throw new Error("Routing is not initialized. Have you enabled the Vite plugin?");
706
+ throw new Error("Routing is not initialized. Make sure the Vite plugin is enabled and that `virtual:hybridly/router` is imported.");
676
707
  }
677
708
  const routes = state.routes.value;
678
709
  const route = routes?.routes?.[name];
@@ -788,11 +819,13 @@ function route(name, parameters, absolute) {
788
819
  return new Router(name, parameters, absolute).toString();
789
820
  }
790
821
 
822
+ exports.can = core.can;
791
823
  exports.router = core.router;
792
824
  exports.HybridlyImports = HybridlyImports;
793
825
  exports.HybridlyResolver = HybridlyResolver;
794
826
  exports.RouterLink = RouterLink;
795
827
  exports.defineLayout = defineLayout;
828
+ exports.defineLayoutProperties = defineLayoutProperties;
796
829
  exports.initializeHybridly = initializeHybridly;
797
830
  exports.route = route;
798
831
  exports.useBackForward = useBackForward;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as vue from 'vue';
2
- import { Plugin as Plugin$2, h, PropType, ComputedRef, ComponentOptions } from 'vue';
2
+ import { Plugin as Plugin$2, h, PropType, ComputedRef, DeepReadonly } from 'vue';
3
3
  import * as _hybridly_core from '@hybridly/core';
4
4
  import { VisitPayload as VisitPayload$1, ResolveComponent as ResolveComponent$1, RouterContextOptions, Plugin as Plugin$1, RouterContext, Method as Method$1, VisitOptions as VisitOptions$1, UrlResolvable as UrlResolvable$1 } from '@hybridly/core';
5
- export { router } from '@hybridly/core';
5
+ export { can, router } from '@hybridly/core';
6
6
  import { ProgressOptions } from '@hybridly/progress-plugin';
7
7
  import * as _vue_shared from '@vue/shared';
8
8
  import { RequestData } from '@hybridly/utils';
@@ -212,7 +212,7 @@ interface Hooks {
212
212
  */
213
213
  abort: (context: InternalRouterContext) => MaybePromise<any>;
214
214
  /**
215
- * Called when a response to a request is not a valid Hybridly response.
215
+ * Called when a response to a request is not a valid hybrid response.
216
216
  */
217
217
  invalid: (response: AxiosResponse) => MaybePromise<void>;
218
218
  /**
@@ -260,7 +260,7 @@ interface NavigationOptions {
260
260
  * }
261
261
  * ```
262
262
  */
263
- transformUrl?: UrlTransformable;
263
+ transformUrl?: UrlTransformable | ((url: string) => UrlTransformable);
264
264
  /**
265
265
  * Defines whether the history state should be updated.
266
266
  * @internal This is an advanced property meant to be used internally.
@@ -416,16 +416,30 @@ interface FormOptions<T extends Fields> extends Omit<VisitOptions$1, 'data' | 'u
416
416
  }
417
417
  declare function useForm<T extends Fields = Fields>(options: FormOptions<T>): {
418
418
  reset: (...keys: (keyof T)[]) => void;
419
- initial: vue.UnwrapRef<vue.DeepReadonly<vue.UnwrapNestedRefs<T>>>;
420
419
  fields: vue.UnwrapRef<vue.UnwrapNestedRefs<T>>;
421
- loaded: any;
422
- submit: (optionsOverrides?: Omit<VisitOptions$1, 'data'>) => Promise<_hybridly_core.VisitResponse>;
423
420
  abort: () => void;
424
421
  setErrors: (incoming: Record<string, string>) => void;
425
422
  clearErrors: () => void;
423
+ submitWithOptions: (optionsOverrides?: Omit<VisitOptions$1, 'data'>) => Promise<_hybridly_core.VisitResponse>;
424
+ submit: () => Promise<_hybridly_core.VisitResponse>;
426
425
  hasErrors: boolean;
426
+ initial: vue.UnwrapRef<DeepReadonly<T>>;
427
+ loaded: any;
428
+ progress: {
429
+ readonly event: {
430
+ readonly loaded: number;
431
+ readonly total?: number | undefined;
432
+ readonly progress?: number | undefined;
433
+ readonly bytes: number;
434
+ readonly rate?: number | undefined;
435
+ readonly estimated?: number | undefined;
436
+ readonly upload?: boolean | undefined;
437
+ readonly download?: boolean | undefined;
438
+ };
439
+ readonly percentage: number;
440
+ } | undefined;
427
441
  isDirty: boolean;
428
- errors: vue.UnwrapRef<vue.DeepReadonly<vue.UnwrapNestedRefs<[Record<keyof T, string>] extends [vue.Ref<any>] ? vue.Ref<any> & Record<keyof T, string> : vue.Ref<vue.UnwrapRef<Record<keyof T, string>>>>>>;
442
+ errors: vue.UnwrapRef<DeepReadonly<[Record<keyof T, string>] extends [vue.Ref<any>] ? vue.Ref<any> & Record<keyof T, string> : vue.Ref<vue.UnwrapRef<Record<keyof T, string>>>>>;
429
443
  processing: boolean;
430
444
  successful: boolean;
431
445
  failed: boolean;
@@ -521,11 +535,16 @@ declare function usePaginator<T = any>(paginator: UnwrappedPaginator<T> | Pagina
521
535
  to: number;
522
536
  };
523
537
 
524
- declare type Layout = ComponentOptions | (() => ComponentOptions) | [ComponentOptions];
538
+ declare type Layout = any;
525
539
  /**
526
540
  * Sets the persistent layout for this page.
527
541
  */
528
- declare function defineLayout(layout: Layout): void;
542
+ declare function defineLayout<T extends Record<string, K>, K = any>(layout: Layout, properties?: T): void;
543
+ declare function defineLayout(layouts: Layout[]): void;
544
+ /**
545
+ * Sets or gets the properties for the current persistent layout.
546
+ */
547
+ declare function defineLayoutProperties<T extends Record<string, K>, K = any>(properties: T): void;
529
548
 
530
549
  interface RouterConfiguration {
531
550
  url: string;
@@ -552,4 +571,4 @@ declare type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteColl
552
571
  */
553
572
  declare function route<T extends RouteName>(name: T, parameters?: RouteParameters<T>, absolute?: boolean): string;
554
573
 
555
- export { AutoImportResolverOptions, GlobalRouteCollection, HybridlyImports, HybridlyResolver, Layout, RouteCollection, RouteDefinition, RouteName, RouteParameters, RouterConfiguration, RouterLink, defineLayout, initializeHybridly, route, useBackForward, useContext, useForm, useHistoryState, usePaginator, useProperties, useProperty, useRouter };
574
+ export { AutoImportResolverOptions, GlobalRouteCollection, HybridlyImports, HybridlyResolver, Layout, RouteCollection, RouteDefinition, RouteName, RouteParameters, RouterConfiguration, RouterLink, defineLayout, defineLayoutProperties, initializeHybridly, route, useBackForward, useContext, useForm, useHistoryState, usePaginator, useProperties, useProperty, useRouter };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { ref, shallowRef, unref, triggerRef, defineComponent, h, isRef, reactive, readonly, computed, toRaw, watch } from 'vue';
1
+ import { ref, shallowRef, unref, triggerRef, defineComponent, h, isRef, reactive, readonly, computed, watch, toRaw } from 'vue';
2
2
  import { registerHook, registerHookOnce, createRouter, makeUrl, router } from '@hybridly/core';
3
- export { router } from '@hybridly/core';
3
+ export { can, router } from '@hybridly/core';
4
4
  import { debug, showPageComponentErrorModal, merge } from '@hybridly/utils';
5
5
  import { progress } from '@hybridly/progress-plugin';
6
6
  import { setupDevtoolsPlugin } from '@vue/devtools-api';
@@ -12,6 +12,7 @@ const state = {
12
12
  context: ref(),
13
13
  view: shallowRef(),
14
14
  viewLayout: shallowRef(),
15
+ viewLayoutProperties: ref(),
15
16
  viewKey: ref(),
16
17
  dialog: shallowRef(),
17
18
  dialogKey: ref(),
@@ -27,9 +28,13 @@ const state = {
27
28
  state.view.value = view;
28
29
  },
29
30
  setViewLayout(layout) {
30
- debug.adapter("vue:state:view", "Setting layout:", layout);
31
+ debug.adapter("vue:state:view", "Setting layout", layout);
31
32
  state.viewLayout.value = layout;
32
33
  },
34
+ setViewLayoutProperties(properties) {
35
+ debug.adapter("vue:state:view", "Setting layout properties:", properties);
36
+ state.viewLayoutProperties.value = properties;
37
+ },
33
38
  setDialog(dialog) {
34
39
  debug.adapter("vue:state:dialog", "Setting dialog:", dialog);
35
40
  state.dialog.value = dialog;
@@ -66,11 +71,17 @@ const wrapper = defineComponent({
66
71
  if (Array.isArray(state.view.value?.layout)) {
67
72
  return state.view.value.layout.concat(child).reverse().reduce((child2, layout) => {
68
73
  layout.inheritAttrs = !!layout.inheritAttrs;
69
- return h(layout, { ...state.context.value.view.properties }, () => child2);
74
+ return h(layout, {
75
+ ...state.view.value?.layoutProperties ?? {},
76
+ ...state.context.value.view.properties
77
+ }, () => child2);
70
78
  });
71
79
  }
72
80
  return [
73
- h(state.view.value?.layout, { ...state.context.value.view.properties }, () => child),
81
+ h(state.view.value?.layout, {
82
+ ...state.view.value?.layoutProperties ?? {},
83
+ ...state.context.value.view.properties
84
+ }, () => child),
74
85
  renderDialog()
75
86
  ];
76
87
  }
@@ -98,6 +109,10 @@ const wrapper = defineComponent({
98
109
  state.view.value.layout = state.viewLayout.value;
99
110
  state.viewLayout.value = void 0;
100
111
  }
112
+ if (state.viewLayoutProperties.value) {
113
+ state.view.value.layoutProperties = state.viewLayoutProperties.value;
114
+ state.viewLayoutProperties.value = void 0;
115
+ }
101
116
  if (state.view.value.layout) {
102
117
  return renderLayout(view);
103
118
  }
@@ -404,7 +419,8 @@ const HybridlyImports = {
404
419
  "useForm",
405
420
  "useHistoryState",
406
421
  "usePaginator",
407
- "useLayout",
422
+ "defineLayout",
423
+ "defineLayoutProperties",
408
424
  "route"
409
425
  ],
410
426
  "hybridly": [
@@ -495,8 +511,8 @@ function useForm(options) {
495
511
  recentlyFailed: void 0,
496
512
  recentlySuccessful: void 0
497
513
  };
498
- const initial = readonly(safeClone(options.fields));
499
- const loaded = readonly(safeClone(historyData?.fields ?? options.fields));
514
+ const initial = safeClone(options.fields);
515
+ const loaded = safeClone(historyData?.fields ?? options.fields);
500
516
  const fields = reactive(safeClone(historyData?.fields ?? options.fields));
501
517
  const errors = ref(historyData?.errors ?? {});
502
518
  const isDirty = ref(false);
@@ -505,6 +521,7 @@ function useForm(options) {
505
521
  const recentlyFailed = ref(false);
506
522
  const failed = ref(false);
507
523
  const processing = ref(false);
524
+ const progress = ref();
508
525
  function reset(...keys) {
509
526
  if (keys.length === 0) {
510
527
  keys = Object.keys(fields);
@@ -516,6 +533,7 @@ function useForm(options) {
516
533
  const url = typeof options.url === "function" ? options.url() : options.url;
517
534
  const data = typeof options.transform === "function" ? options.transform?.(fields) : fields;
518
535
  return router.visit({
536
+ ...options,
519
537
  url: url ?? state.context.value?.url,
520
538
  method: options.method ?? "POST",
521
539
  ...optionsOverrides,
@@ -535,6 +553,10 @@ function useForm(options) {
535
553
  processing.value = true;
536
554
  return options.hooks?.start?.(context);
537
555
  },
556
+ progress: (incoming) => {
557
+ progress.value = incoming;
558
+ return options.hooks?.progress?.(incoming);
559
+ },
538
560
  error: (incoming) => {
539
561
  setErrors(incoming);
540
562
  failed.value = true;
@@ -552,6 +574,7 @@ function useForm(options) {
552
574
  return options.hooks?.success?.(payload);
553
575
  },
554
576
  after: (context) => {
577
+ progress.value = void 0;
555
578
  processing.value = false;
556
579
  return options.hooks?.after?.(context);
557
580
  }
@@ -578,21 +601,23 @@ function useForm(options) {
578
601
  }, { deep: true, immediate: true });
579
602
  return reactive({
580
603
  reset,
581
- initial,
582
604
  fields,
583
- loaded,
584
- submit,
585
605
  abort,
586
606
  setErrors,
587
607
  clearErrors,
608
+ submitWithOptions: submit,
609
+ submit: () => submit(),
588
610
  hasErrors: computed(() => Object.values(errors.value).length > 0),
589
- isDirty: readonly(isDirty),
590
- errors: readonly(errors),
591
- processing: readonly(processing),
592
- successful: readonly(successful),
593
- failed: readonly(failed),
594
- recentlySuccessful: readonly(recentlySuccessful),
595
- recentlyFailed: readonly(recentlyFailed)
611
+ initial,
612
+ loaded,
613
+ progress,
614
+ isDirty,
615
+ errors,
616
+ processing,
617
+ successful,
618
+ failed,
619
+ recentlySuccessful,
620
+ recentlyFailed
596
621
  });
597
622
  }
598
623
 
@@ -651,8 +676,14 @@ function usePaginator(paginator) {
651
676
  return { pages, items, previous, next, first, last, total, from, to };
652
677
  }
653
678
 
654
- function defineLayout(layout) {
655
- state.setViewLayout(layout);
679
+ function defineLayout(...args) {
680
+ const layouts = args[0];
681
+ const properties = args[1];
682
+ state.setViewLayout(layouts);
683
+ state.setViewLayoutProperties(properties);
684
+ }
685
+ function defineLayoutProperties(properties) {
686
+ state.setViewLayoutProperties(properties);
656
687
  }
657
688
 
658
689
  class Route {
@@ -663,7 +694,7 @@ class Route {
663
694
  }
664
695
  static getDefinition(name) {
665
696
  if (!state.routes.value) {
666
- throw new Error("Routing is not initialized. Have you enabled the Vite plugin?");
697
+ throw new Error("Routing is not initialized. Make sure the Vite plugin is enabled and that `virtual:hybridly/router` is imported.");
667
698
  }
668
699
  const routes = state.routes.value;
669
700
  const route = routes?.routes?.[name];
@@ -779,4 +810,4 @@ function route(name, parameters, absolute) {
779
810
  return new Router(name, parameters, absolute).toString();
780
811
  }
781
812
 
782
- export { HybridlyImports, HybridlyResolver, RouterLink, defineLayout, initializeHybridly, route, useBackForward, useContext, useForm, useHistoryState, usePaginator, useProperties, useProperty, useRouter };
813
+ export { HybridlyImports, HybridlyResolver, RouterLink, defineLayout, defineLayoutProperties, initializeHybridly, route, useBackForward, useContext, useForm, useHistoryState, usePaginator, useProperties, useProperty, useRouter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybridly/vue",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.1-alpha.6",
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.4",
42
- "@hybridly/progress-plugin": "0.0.1-alpha.4",
43
- "@hybridly/utils": "0.0.1-alpha.4",
41
+ "@hybridly/core": "0.0.1-alpha.6",
42
+ "@hybridly/progress-plugin": "0.0.1-alpha.6",
43
+ "@hybridly/utils": "0.0.1-alpha.6",
44
44
  "@vue/devtools-api": "^6.4.4",
45
45
  "defu": "^6.1.0",
46
46
  "lodash.clonedeep": "^4.5.0",
@@ -53,7 +53,7 @@
53
53
  "@types/lodash.clonedeep": "^4.5.7",
54
54
  "@types/lodash.isequal": "^4.5.6",
55
55
  "@types/nprogress": "^0.2.0",
56
- "vue": "^3.2.40"
56
+ "vue": "^3.2.41"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "unbuild",