@hybridly/vue 0.0.1-alpha.3 → 0.0.1-alpha.5

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": [
@@ -525,6 +541,7 @@ function useForm(options) {
525
541
  const url = typeof options.url === "function" ? options.url() : options.url;
526
542
  const data = typeof options.transform === "function" ? options.transform?.(fields) : fields;
527
543
  return core.router.visit({
544
+ ...options,
528
545
  url: url ?? state.context.value?.url,
529
546
  method: options.method ?? "POST",
530
547
  ...optionsOverrides,
@@ -590,7 +607,8 @@ function useForm(options) {
590
607
  initial,
591
608
  fields,
592
609
  loaded,
593
- submit,
610
+ submitWithOptions: submit,
611
+ submit: () => submit(),
594
612
  abort,
595
613
  setErrors,
596
614
  clearErrors,
@@ -660,8 +678,14 @@ function usePaginator(paginator) {
660
678
  return { pages, items, previous, next, first, last, total, from, to };
661
679
  }
662
680
 
663
- function useLayout(layout) {
664
- state.setViewLayout(layout);
681
+ function defineLayout(...args) {
682
+ const layouts = args[0];
683
+ const properties = args[1];
684
+ state.setViewLayout(layouts);
685
+ state.setViewLayoutProperties(properties);
686
+ }
687
+ function defineLayoutProperties(properties) {
688
+ state.setViewLayoutProperties(properties);
665
689
  }
666
690
 
667
691
  class Route {
@@ -672,7 +696,7 @@ class Route {
672
696
  }
673
697
  static getDefinition(name) {
674
698
  if (!state.routes.value) {
675
- throw new Error("Routing is not initialized. Have you enabled the Vite plugin?");
699
+ throw new Error("Routing is not initialized. Make sure the Vite plugin is enabled and that `virtual:hybridly/router` is imported.");
676
700
  }
677
701
  const routes = state.routes.value;
678
702
  const route = routes?.routes?.[name];
@@ -792,13 +816,14 @@ exports.router = core.router;
792
816
  exports.HybridlyImports = HybridlyImports;
793
817
  exports.HybridlyResolver = HybridlyResolver;
794
818
  exports.RouterLink = RouterLink;
819
+ exports.defineLayout = defineLayout;
820
+ exports.defineLayoutProperties = defineLayoutProperties;
795
821
  exports.initializeHybridly = initializeHybridly;
796
822
  exports.route = route;
797
823
  exports.useBackForward = useBackForward;
798
824
  exports.useContext = useContext;
799
825
  exports.useForm = useForm;
800
826
  exports.useHistoryState = useHistoryState;
801
- exports.useLayout = useLayout;
802
827
  exports.usePaginator = usePaginator;
803
828
  exports.useProperties = useProperties;
804
829
  exports.useProperty = useProperty;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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 } 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
5
  export { router } from '@hybridly/core';
@@ -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
  /**
@@ -419,7 +419,8 @@ declare function useForm<T extends Fields = Fields>(options: FormOptions<T>): {
419
419
  initial: vue.UnwrapRef<vue.DeepReadonly<vue.UnwrapNestedRefs<T>>>;
420
420
  fields: vue.UnwrapRef<vue.UnwrapNestedRefs<T>>;
421
421
  loaded: any;
422
- submit: (optionsOverrides?: Omit<VisitOptions$1, 'data'>) => Promise<_hybridly_core.VisitResponse>;
422
+ submitWithOptions: (optionsOverrides?: Omit<VisitOptions$1, 'data'>) => Promise<_hybridly_core.VisitResponse>;
423
+ submit: () => Promise<_hybridly_core.VisitResponse>;
423
424
  abort: () => void;
424
425
  setErrors: (incoming: Record<string, string>) => void;
425
426
  clearErrors: () => void;
@@ -521,11 +522,16 @@ declare function usePaginator<T = any>(paginator: UnwrappedPaginator<T> | Pagina
521
522
  to: number;
522
523
  };
523
524
 
524
- declare type Layout = ComponentOptions | (() => ComponentOptions) | [ComponentOptions];
525
+ declare type Layout = any;
525
526
  /**
526
527
  * Sets the persistent layout for this page.
527
528
  */
528
- declare function useLayout(layout: Layout): void;
529
+ declare function defineLayout<T extends Record<string, K>, K = any>(layout: Layout, properties?: T): void;
530
+ declare function defineLayout(layouts: Layout[]): void;
531
+ /**
532
+ * Sets or gets the properties for the current persistent layout.
533
+ */
534
+ declare function defineLayoutProperties<T extends Record<string, K>, K = any>(properties: T): void;
529
535
 
530
536
  interface RouterConfiguration {
531
537
  url: string;
@@ -552,4 +558,4 @@ declare type RouteParameters<T extends RouteName> = Record<keyof GlobalRouteColl
552
558
  */
553
559
  declare function route<T extends RouteName>(name: T, parameters?: RouteParameters<T>, absolute?: boolean): string;
554
560
 
555
- export { AutoImportResolverOptions, GlobalRouteCollection, HybridlyImports, HybridlyResolver, Layout, RouteCollection, RouteDefinition, RouteName, RouteParameters, RouterConfiguration, RouterLink, initializeHybridly, route, useBackForward, useContext, useForm, useHistoryState, useLayout, usePaginator, useProperties, useProperty, useRouter };
561
+ 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,4 +1,4 @@
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
3
  export { router } from '@hybridly/core';
4
4
  import { debug, showPageComponentErrorModal, merge } from '@hybridly/utils';
@@ -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": [
@@ -516,6 +532,7 @@ function useForm(options) {
516
532
  const url = typeof options.url === "function" ? options.url() : options.url;
517
533
  const data = typeof options.transform === "function" ? options.transform?.(fields) : fields;
518
534
  return router.visit({
535
+ ...options,
519
536
  url: url ?? state.context.value?.url,
520
537
  method: options.method ?? "POST",
521
538
  ...optionsOverrides,
@@ -581,7 +598,8 @@ function useForm(options) {
581
598
  initial,
582
599
  fields,
583
600
  loaded,
584
- submit,
601
+ submitWithOptions: submit,
602
+ submit: () => submit(),
585
603
  abort,
586
604
  setErrors,
587
605
  clearErrors,
@@ -651,8 +669,14 @@ function usePaginator(paginator) {
651
669
  return { pages, items, previous, next, first, last, total, from, to };
652
670
  }
653
671
 
654
- function useLayout(layout) {
655
- state.setViewLayout(layout);
672
+ function defineLayout(...args) {
673
+ const layouts = args[0];
674
+ const properties = args[1];
675
+ state.setViewLayout(layouts);
676
+ state.setViewLayoutProperties(properties);
677
+ }
678
+ function defineLayoutProperties(properties) {
679
+ state.setViewLayoutProperties(properties);
656
680
  }
657
681
 
658
682
  class Route {
@@ -663,7 +687,7 @@ class Route {
663
687
  }
664
688
  static getDefinition(name) {
665
689
  if (!state.routes.value) {
666
- throw new Error("Routing is not initialized. Have you enabled the Vite plugin?");
690
+ throw new Error("Routing is not initialized. Make sure the Vite plugin is enabled and that `virtual:hybridly/router` is imported.");
667
691
  }
668
692
  const routes = state.routes.value;
669
693
  const route = routes?.routes?.[name];
@@ -779,4 +803,4 @@ function route(name, parameters, absolute) {
779
803
  return new Router(name, parameters, absolute).toString();
780
804
  }
781
805
 
782
- export { HybridlyImports, HybridlyResolver, RouterLink, initializeHybridly, route, useBackForward, useContext, useForm, useHistoryState, useLayout, usePaginator, useProperties, useProperty, useRouter };
806
+ 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.3",
3
+ "version": "0.0.1-alpha.5",
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.3",
42
- "@hybridly/progress-plugin": "0.0.1-alpha.3",
43
- "@hybridly/utils": "0.0.1-alpha.3",
41
+ "@hybridly/core": "0.0.1-alpha.5",
42
+ "@hybridly/progress-plugin": "0.0.1-alpha.5",
43
+ "@hybridly/utils": "0.0.1-alpha.5",
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",