@hybridly/vue 0.1.0-alpha.4 → 0.1.0-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/LICENSE CHANGED
@@ -1,7 +1,5 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
4
-
5
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
4
  of this software and associated documentation files (the "Software"), to deal
7
5
  in the Software without restriction, including without limitation the rights
package/dist/index.cjs CHANGED
@@ -56,6 +56,8 @@ const dialogStore = {
56
56
  }
57
57
  };
58
58
 
59
+ const onMountedCallbacks = [];
60
+
59
61
  const state = {
60
62
  context: vue.ref(),
61
63
  view: vue.shallowRef(),
@@ -119,6 +121,14 @@ const wrapper = vue.defineComponent({
119
121
  function renderView() {
120
122
  utils.debug.adapter("vue:render:view", "Rendering view.");
121
123
  state.view.value.inheritAttrs = !!state.view.value.inheritAttrs;
124
+ const actual = state.view.value?.mounted;
125
+ state.view.value.mounted = () => {
126
+ actual?.();
127
+ vue.nextTick(() => {
128
+ utils.debug.adapter("vue:render:view", "Calling mounted callbacks.");
129
+ onMountedCallbacks.pop()?.();
130
+ });
131
+ };
122
132
  return vue.h(state.view.value, {
123
133
  ...state.properties.value,
124
134
  key: state.viewKey.value
@@ -279,6 +289,9 @@ async function initializeHybridly(options = {}) {
279
289
  responseErrorModals: resolved.responseErrorModals ?? process.env.NODE_ENV === "development",
280
290
  adapter: {
281
291
  resolveComponent: resolve,
292
+ onWaitingForMount: (callback) => {
293
+ onMountedCallbacks.push(callback);
294
+ },
282
295
  onDialogClose: async () => {
283
296
  dialogStore.hide();
284
297
  },
package/dist/index.d.ts CHANGED
@@ -182,7 +182,7 @@ declare const RouterLink: vue.DefineComponent<{
182
182
  /** Accesses all current properties. */
183
183
  declare function useProperties<T extends object, Global extends GlobalHybridlyProperties>(): vue.DeepReadonly<vue.UnwrapNestedRefs<T & Global>>;
184
184
  /** Accesses a property with a dot notation. */
185
- declare function useProperty<F = never, T = GlobalHybridlyProperties, P extends Path<T> = Path<T>>(path: [F] extends [never] ? [P] extends [never] ? string : P : string): ComputedRef<[F] extends [never] ? [PathValue<T, P>] extends [never] ? never : PathValue<T, P> : F>;
185
+ declare function useProperty<F = never, T = GlobalHybridlyProperties, P extends Path<T> = Path<T>>(path: [F] extends [never] ? ([P] extends [never] ? string : P) : string): ComputedRef<[F] extends [never] ? ([PathValue<T, P>] extends [never] ? never : PathValue<T, P>) : F>;
186
186
  type PathImpl<T, K extends keyof T> = K extends string ? T[K] extends undefined ? undefined : NonNullable<T[K]> extends Record<string, any> ? NonNullable<T[K]> extends ArrayLike<any> ? K | `${K}.${PathImpl<NonNullable<T[K]>, Exclude<keyof NonNullable<T[K]>, keyof any[]>>}` : K | `${K}.${PathImpl<NonNullable<T[K]>, keyof NonNullable<T[K]>>}` : K : never;
187
187
  type Path<T> = PathImpl<T, keyof T> | keyof T;
188
188
  type PathValue<T, P extends Path<T>> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? T[K] extends undefined ? undefined : Rest extends Path<T[K]> ? PathValue<T[K], Rest> : Rest extends Path<NonNullable<T[K]>> ? PathValue<NonNullable<T[K]>, Rest> | undefined : never : never : P extends keyof T ? T[P] extends undefined ? undefined : T[P] : never;
@@ -280,7 +280,7 @@ type BaseUrlTransformable = Partial<Omit<URL, 'searchParams' | 'toJSON' | 'toStr
280
280
  trailingSlash?: boolean;
281
281
  };
282
282
 
283
- type ConditionalNavigationOption = boolean | ((payload: HybridPayload) => boolean);
283
+ type ConditionalNavigationOption<T extends boolean | string> = T | ((payload: NavigationOptions) => T);
284
284
  interface NavigationOptions {
285
285
  /** View to navigate to. */
286
286
  payload?: HybridPayload;
@@ -288,13 +288,13 @@ interface NavigationOptions {
288
288
  * Whether to replace the current history state instead of adding
289
289
  * one. This affects the browser's "back" and "forward" features.
290
290
  */
291
- replace?: ConditionalNavigationOption;
292
- /** Whether to preserve the current scrollbar position. */
293
- preserveScroll?: ConditionalNavigationOption;
291
+ replace?: ConditionalNavigationOption<boolean>;
292
+ /** Whether to preserve the scrollbars positions on the page. */
293
+ preserveScroll?: ConditionalNavigationOption<boolean>;
294
294
  /** Whether to preserve the current page component's state. */
295
- preserveState?: ConditionalNavigationOption;
295
+ preserveState?: ConditionalNavigationOption<boolean>;
296
296
  /** Whether to preserve the current URL. */
297
- preserveUrl?: ConditionalNavigationOption;
297
+ preserveUrl?: ConditionalNavigationOption<boolean>;
298
298
  /**
299
299
  * Properties of the given URL to override.
300
300
  * @example
@@ -458,6 +458,8 @@ interface Adapter {
458
458
  onContextUpdate?: (context: InternalRouterContext) => void;
459
459
  /** Called when a dialog is closed. */
460
460
  onDialogClose?: (context: InternalRouterContext) => void;
461
+ /** Called when Hybridly is waiting for a component to be mounted. The given callback should be executed after the view component is mounted. */
462
+ onWaitingForMount: (callback: Function) => void;
461
463
  }
462
464
  interface ResolvedAdapter extends Adapter {
463
465
  updateRoutingConfiguration: (routing?: RoutingConfiguration) => void;
@@ -468,8 +470,8 @@ interface ScrollRegion {
468
470
  }
469
471
  /** Provides methods to serialize the state into the history state. */
470
472
  interface Serializer {
471
- serialize: <T>(view: T) => any;
472
- unserialize: <T>(state: any) => T;
473
+ serialize: <T>(view: T) => string;
474
+ unserialize: <T>(state?: string) => T | undefined;
473
475
  }
474
476
 
475
477
  /** Accesses the hybridly context. */
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { shallowRef, ref, unref, triggerRef, defineComponent, toRaw, h, createApp, isRef, reactive, readonly, computed, watch, getCurrentInstance, onUnmounted } from 'vue';
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
4
  import { debug, random, showDomainsDisabledErrorModal, showPageComponentErrorModal, merge, clone } from '@hybridly/utils';
@@ -48,6 +48,8 @@ const dialogStore = {
48
48
  }
49
49
  };
50
50
 
51
+ const onMountedCallbacks = [];
52
+
51
53
  const state = {
52
54
  context: ref(),
53
55
  view: shallowRef(),
@@ -111,6 +113,14 @@ const wrapper = defineComponent({
111
113
  function renderView() {
112
114
  debug.adapter("vue:render:view", "Rendering view.");
113
115
  state.view.value.inheritAttrs = !!state.view.value.inheritAttrs;
116
+ const actual = state.view.value?.mounted;
117
+ state.view.value.mounted = () => {
118
+ actual?.();
119
+ nextTick(() => {
120
+ debug.adapter("vue:render:view", "Calling mounted callbacks.");
121
+ onMountedCallbacks.pop()?.();
122
+ });
123
+ };
114
124
  return h(state.view.value, {
115
125
  ...state.properties.value,
116
126
  key: state.viewKey.value
@@ -271,6 +281,9 @@ async function initializeHybridly(options = {}) {
271
281
  responseErrorModals: resolved.responseErrorModals ?? process.env.NODE_ENV === "development",
272
282
  adapter: {
273
283
  resolveComponent: resolve,
284
+ onWaitingForMount: (callback) => {
285
+ onMountedCallbacks.push(callback);
286
+ },
274
287
  onDialogClose: async () => {
275
288
  dialogStore.hide();
276
289
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybridly/vue",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "Vue adapter for Hybridly",
5
5
  "keywords": [
6
6
  "hybridly",
@@ -42,11 +42,11 @@
42
42
  "defu": "^6.1.2",
43
43
  "lodash.isequal": "^4.5.0",
44
44
  "nprogress": "^0.2.0",
45
- "qs": "^6.11.0",
46
- "@hybridly/config": "0.1.0-alpha.4",
47
- "@hybridly/core": "0.1.0-alpha.4",
48
- "@hybridly/progress-plugin": "0.1.0-alpha.4",
49
- "@hybridly/utils": "0.1.0-alpha.4"
45
+ "qs": "^6.11.1",
46
+ "@hybridly/config": "0.1.0-alpha.6",
47
+ "@hybridly/core": "0.1.0-alpha.6",
48
+ "@hybridly/progress-plugin": "0.1.0-alpha.6",
49
+ "@hybridly/utils": "0.1.0-alpha.6"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/lodash": "^4.14.191",