@hybridly/vue 0.4.4 → 0.4.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
@@ -236,19 +236,25 @@ const wrapper = vue.defineComponent({
236
236
  renderDialog()
237
237
  ];
238
238
  }
239
- function renderView() {
240
- utils.debug.adapter("vue:render:view", "Rendering view.");
241
- state.view.value.inheritAttrs = !!state.view.value.inheritAttrs;
242
- const actual = state.view.value?.mounted;
243
- state.view.value.mounted = () => {
239
+ function hijackOnMounted(component, type) {
240
+ if (!component) {
241
+ return;
242
+ }
243
+ const actual = component?.mounted;
244
+ component.mounted = () => {
244
245
  actual?.();
245
246
  vue.nextTick(() => {
246
- utils.debug.adapter("vue:render:view", "Calling mounted callbacks.");
247
+ utils.debug.adapter(`vue:render:${type}`, "Calling mounted callbacks.");
247
248
  while (onMountedCallbacks.length) {
248
249
  onMountedCallbacks.shift()?.();
249
250
  }
250
251
  });
251
252
  };
253
+ }
254
+ function renderView() {
255
+ utils.debug.adapter("vue:render:view", "Rendering view.");
256
+ state.view.value.inheritAttrs = !!state.view.value.inheritAttrs;
257
+ hijackOnMounted(state.view.value, "view");
252
258
  return vue.h(state.view.value, {
253
259
  ...state.properties.value,
254
260
  key: state.viewKey.value
@@ -257,6 +263,7 @@ const wrapper = vue.defineComponent({
257
263
  function renderDialog() {
258
264
  if (dialogStore.state.component.value && dialogStore.state.properties.value) {
259
265
  utils.debug.adapter("vue:render:dialog", "Rendering dialog.");
266
+ hijackOnMounted(dialogStore.state.component.value, "dialog");
260
267
  return vue.h(dialogStore.state.component.value, {
261
268
  ...dialogStore.state.properties.value,
262
269
  key: dialogStore.state.key.value
@@ -310,6 +317,11 @@ function setupDevtools(app) {
310
317
  key: "component",
311
318
  value: state.context.value?.view.component
312
319
  });
320
+ payload.instanceData.state.push({
321
+ type: hybridlyStateType,
322
+ key: "deferred",
323
+ value: state.context.value?.view.deferred
324
+ });
313
325
  payload.instanceData.state.push({
314
326
  type: hybridlyStateType,
315
327
  key: "dialog",
@@ -404,8 +416,8 @@ function viewTransition() {
404
416
  let domUpdated;
405
417
  return {
406
418
  name: "view-transition",
407
- navigating: async ({ isInitial }) => {
408
- if (isInitial) {
419
+ navigating: async ({ type, hasDialog }) => {
420
+ if (type === "initial" || hasDialog) {
409
421
  return;
410
422
  }
411
423
  return new Promise((confirmTransitionStarted) => document.startViewTransition(() => {
@@ -416,6 +428,10 @@ function viewTransition() {
416
428
  mounted: () => {
417
429
  domUpdated?.();
418
430
  domUpdated = void 0;
431
+ },
432
+ navigated: () => {
433
+ domUpdated?.();
434
+ domUpdated = void 0;
419
435
  }
420
436
  };
421
437
  }
@@ -444,12 +460,16 @@ async function initializeHybridly(options = {}) {
444
460
  state.setContext(context);
445
461
  },
446
462
  onViewSwap: async (options2) => {
447
- state.setView(options2.component);
463
+ if (options2.component) {
464
+ onMountedCallbacks.push(() => options2.onMounted?.({ isDialog: false }));
465
+ state.setView(options2.component);
466
+ }
448
467
  state.setProperties(options2.properties);
449
468
  if (!options2.preserveState && !options2.dialog) {
450
469
  state.setViewKey(utils.random());
451
470
  }
452
471
  if (options2.dialog) {
472
+ onMountedCallbacks.push(() => options2.onMounted?.({ isDialog: true }));
453
473
  dialogStore.setComponent(await resolve(options2.dialog.component));
454
474
  dialogStore.setProperties(options2.dialog.properties);
455
475
  dialogStore.setKey(options2.dialog.key);
@@ -880,7 +900,7 @@ function useHistoryState(key, initial) {
880
900
  function useBackForward() {
881
901
  const callbacks = [];
882
902
  core.registerHook("navigated", (options) => {
883
- if (options.isBackForward) {
903
+ if (options.type === "back-forward") {
884
904
  callbacks.forEach((fn) => fn(state.context.value));
885
905
  callbacks.splice(0, callbacks.length);
886
906
  }
package/dist/index.d.cts CHANGED
@@ -185,7 +185,7 @@ declare const RouterLink: vue.DefineComponent<{
185
185
  }, {}>;
186
186
 
187
187
  /** Accesses all current properties. */
188
- declare function useProperties<T extends object, Global extends GlobalHybridlyProperties>(): vue.DeepReadonly<vue.UnwrapNestedRefs<T & Global>>;
188
+ declare function useProperties<T extends object, Global extends GlobalHybridlyProperties = GlobalHybridlyProperties>(): vue.DeepReadonly<vue.UnwrapNestedRefs<T & Global>>;
189
189
  /** Accesses a property with a dot notation. */
190
190
  declare function useProperty<Override = never, T extends SearchableObject = GlobalHybridlyProperties, P extends Path<T> & string = Path<T> & string, ReturnType = [Override] extends [never] ? PathValue<T, P> : Override>(path: [Override] extends [never] ? P : string): ComputedRef<ReturnType>;
191
191
  /**
@@ -265,15 +265,21 @@ interface Hooks extends RequestHooks {
265
265
  /**
266
266
  * Called when a component navigation is being made.
267
267
  */
268
- navigating: (options: NavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
268
+ navigating: (options: InternalNavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
269
269
  /**
270
270
  * Called when a component has been navigated to.
271
271
  */
272
- navigated: (options: NavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
272
+ navigated: (options: InternalNavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
273
273
  /**
274
274
  * Called when a component has been navigated to and was mounted by the adapter.
275
275
  */
276
- mounted: (context: InternalRouterContext) => MaybePromise<any>;
276
+ mounted: (options: InternalNavigationOptions & MountedHookOptions, context: InternalRouterContext) => MaybePromise<any>;
277
+ }
278
+ interface MountedHookOptions {
279
+ /**
280
+ * Whether the component being mounted is a dialog.
281
+ */
282
+ isDialog: boolean;
277
283
  }
278
284
 
279
285
  interface RoutingConfiguration {
@@ -321,16 +327,22 @@ interface NavigationOptions {
321
327
  * @internal This is an advanced property meant to be used internally.
322
328
  */
323
329
  updateHistoryState?: boolean;
330
+ }
331
+ interface InternalNavigationOptions extends NavigationOptions {
324
332
  /**
325
- * Defines whether this navigation is a back/forward navigation from the popstate event.
326
- * @internal This is an advanced property meant to be used internally.
333
+ * Defines the kind of navigation being performed.
334
+ * - initial: the initial page load's navigation
335
+ * - server: a navigation initiated by a server round-trip
336
+ * - local: a navigation initiated by `router.local`
337
+ * - back-forward: a navigation initiated by the browser's `popstate` event
338
+ * @internal
327
339
  */
328
- isBackForward?: boolean;
340
+ type: 'initial' | 'local' | 'back-forward' | 'server';
329
341
  /**
330
- * Defines whether this navigation is the first to happen after a direct page load.
331
- * @internal This is an advanced property meant to be used internally.
342
+ * Defines whether this navigation opens a dialog.
343
+ * @internal
332
344
  */
333
- isInitial?: boolean;
345
+ hasDialog?: boolean;
334
346
  }
335
347
  type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
336
348
  interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
@@ -378,11 +390,13 @@ interface PendingNavigation {
378
390
  /** A page or dialog component. */
379
391
  interface View {
380
392
  /** Name of the component to use. */
381
- component: string;
393
+ component?: string;
382
394
  /** Properties to apply to the component. */
383
395
  properties: Properties;
396
+ /** Deferred properties for this view. */
397
+ deferred: string[];
384
398
  }
385
- interface Dialog extends View {
399
+ interface Dialog extends Required<View> {
386
400
  /** URL that is the base background page when navigating to the dialog directly. */
387
401
  baseUrl: string;
388
402
  /** URL to which the dialog should redirect when closed. */
@@ -403,6 +417,8 @@ interface SwapOptions<T> {
403
417
  preserveState?: boolean;
404
418
  /** Current dialog. */
405
419
  dialog?: Dialog;
420
+ /** On mounted callback. */
421
+ onMounted?: (options: MountedHookOptions) => void;
406
422
  }
407
423
  type ViewComponent = any;
408
424
  type ResolveComponent = (name: string) => Promise<ViewComponent>;
package/dist/index.d.mts CHANGED
@@ -185,7 +185,7 @@ declare const RouterLink: vue.DefineComponent<{
185
185
  }, {}>;
186
186
 
187
187
  /** Accesses all current properties. */
188
- declare function useProperties<T extends object, Global extends GlobalHybridlyProperties>(): vue.DeepReadonly<vue.UnwrapNestedRefs<T & Global>>;
188
+ declare function useProperties<T extends object, Global extends GlobalHybridlyProperties = GlobalHybridlyProperties>(): vue.DeepReadonly<vue.UnwrapNestedRefs<T & Global>>;
189
189
  /** Accesses a property with a dot notation. */
190
190
  declare function useProperty<Override = never, T extends SearchableObject = GlobalHybridlyProperties, P extends Path<T> & string = Path<T> & string, ReturnType = [Override] extends [never] ? PathValue<T, P> : Override>(path: [Override] extends [never] ? P : string): ComputedRef<ReturnType>;
191
191
  /**
@@ -265,15 +265,21 @@ interface Hooks extends RequestHooks {
265
265
  /**
266
266
  * Called when a component navigation is being made.
267
267
  */
268
- navigating: (options: NavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
268
+ navigating: (options: InternalNavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
269
269
  /**
270
270
  * Called when a component has been navigated to.
271
271
  */
272
- navigated: (options: NavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
272
+ navigated: (options: InternalNavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
273
273
  /**
274
274
  * Called when a component has been navigated to and was mounted by the adapter.
275
275
  */
276
- mounted: (context: InternalRouterContext) => MaybePromise<any>;
276
+ mounted: (options: InternalNavigationOptions & MountedHookOptions, context: InternalRouterContext) => MaybePromise<any>;
277
+ }
278
+ interface MountedHookOptions {
279
+ /**
280
+ * Whether the component being mounted is a dialog.
281
+ */
282
+ isDialog: boolean;
277
283
  }
278
284
 
279
285
  interface RoutingConfiguration {
@@ -321,16 +327,22 @@ interface NavigationOptions {
321
327
  * @internal This is an advanced property meant to be used internally.
322
328
  */
323
329
  updateHistoryState?: boolean;
330
+ }
331
+ interface InternalNavigationOptions extends NavigationOptions {
324
332
  /**
325
- * Defines whether this navigation is a back/forward navigation from the popstate event.
326
- * @internal This is an advanced property meant to be used internally.
333
+ * Defines the kind of navigation being performed.
334
+ * - initial: the initial page load's navigation
335
+ * - server: a navigation initiated by a server round-trip
336
+ * - local: a navigation initiated by `router.local`
337
+ * - back-forward: a navigation initiated by the browser's `popstate` event
338
+ * @internal
327
339
  */
328
- isBackForward?: boolean;
340
+ type: 'initial' | 'local' | 'back-forward' | 'server';
329
341
  /**
330
- * Defines whether this navigation is the first to happen after a direct page load.
331
- * @internal This is an advanced property meant to be used internally.
342
+ * Defines whether this navigation opens a dialog.
343
+ * @internal
332
344
  */
333
- isInitial?: boolean;
345
+ hasDialog?: boolean;
334
346
  }
335
347
  type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
336
348
  interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
@@ -378,11 +390,13 @@ interface PendingNavigation {
378
390
  /** A page or dialog component. */
379
391
  interface View {
380
392
  /** Name of the component to use. */
381
- component: string;
393
+ component?: string;
382
394
  /** Properties to apply to the component. */
383
395
  properties: Properties;
396
+ /** Deferred properties for this view. */
397
+ deferred: string[];
384
398
  }
385
- interface Dialog extends View {
399
+ interface Dialog extends Required<View> {
386
400
  /** URL that is the base background page when navigating to the dialog directly. */
387
401
  baseUrl: string;
388
402
  /** URL to which the dialog should redirect when closed. */
@@ -403,6 +417,8 @@ interface SwapOptions<T> {
403
417
  preserveState?: boolean;
404
418
  /** Current dialog. */
405
419
  dialog?: Dialog;
420
+ /** On mounted callback. */
421
+ onMounted?: (options: MountedHookOptions) => void;
406
422
  }
407
423
  type ViewComponent = any;
408
424
  type ResolveComponent = (name: string) => Promise<ViewComponent>;
package/dist/index.d.ts CHANGED
@@ -185,7 +185,7 @@ declare const RouterLink: vue.DefineComponent<{
185
185
  }, {}>;
186
186
 
187
187
  /** Accesses all current properties. */
188
- declare function useProperties<T extends object, Global extends GlobalHybridlyProperties>(): vue.DeepReadonly<vue.UnwrapNestedRefs<T & Global>>;
188
+ declare function useProperties<T extends object, Global extends GlobalHybridlyProperties = GlobalHybridlyProperties>(): vue.DeepReadonly<vue.UnwrapNestedRefs<T & Global>>;
189
189
  /** Accesses a property with a dot notation. */
190
190
  declare function useProperty<Override = never, T extends SearchableObject = GlobalHybridlyProperties, P extends Path<T> & string = Path<T> & string, ReturnType = [Override] extends [never] ? PathValue<T, P> : Override>(path: [Override] extends [never] ? P : string): ComputedRef<ReturnType>;
191
191
  /**
@@ -265,15 +265,21 @@ interface Hooks extends RequestHooks {
265
265
  /**
266
266
  * Called when a component navigation is being made.
267
267
  */
268
- navigating: (options: NavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
268
+ navigating: (options: InternalNavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
269
269
  /**
270
270
  * Called when a component has been navigated to.
271
271
  */
272
- navigated: (options: NavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
272
+ navigated: (options: InternalNavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
273
273
  /**
274
274
  * Called when a component has been navigated to and was mounted by the adapter.
275
275
  */
276
- mounted: (context: InternalRouterContext) => MaybePromise<any>;
276
+ mounted: (options: InternalNavigationOptions & MountedHookOptions, context: InternalRouterContext) => MaybePromise<any>;
277
+ }
278
+ interface MountedHookOptions {
279
+ /**
280
+ * Whether the component being mounted is a dialog.
281
+ */
282
+ isDialog: boolean;
277
283
  }
278
284
 
279
285
  interface RoutingConfiguration {
@@ -321,16 +327,22 @@ interface NavigationOptions {
321
327
  * @internal This is an advanced property meant to be used internally.
322
328
  */
323
329
  updateHistoryState?: boolean;
330
+ }
331
+ interface InternalNavigationOptions extends NavigationOptions {
324
332
  /**
325
- * Defines whether this navigation is a back/forward navigation from the popstate event.
326
- * @internal This is an advanced property meant to be used internally.
333
+ * Defines the kind of navigation being performed.
334
+ * - initial: the initial page load's navigation
335
+ * - server: a navigation initiated by a server round-trip
336
+ * - local: a navigation initiated by `router.local`
337
+ * - back-forward: a navigation initiated by the browser's `popstate` event
338
+ * @internal
327
339
  */
328
- isBackForward?: boolean;
340
+ type: 'initial' | 'local' | 'back-forward' | 'server';
329
341
  /**
330
- * Defines whether this navigation is the first to happen after a direct page load.
331
- * @internal This is an advanced property meant to be used internally.
342
+ * Defines whether this navigation opens a dialog.
343
+ * @internal
332
344
  */
333
- isInitial?: boolean;
345
+ hasDialog?: boolean;
334
346
  }
335
347
  type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
336
348
  interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
@@ -378,11 +390,13 @@ interface PendingNavigation {
378
390
  /** A page or dialog component. */
379
391
  interface View {
380
392
  /** Name of the component to use. */
381
- component: string;
393
+ component?: string;
382
394
  /** Properties to apply to the component. */
383
395
  properties: Properties;
396
+ /** Deferred properties for this view. */
397
+ deferred: string[];
384
398
  }
385
- interface Dialog extends View {
399
+ interface Dialog extends Required<View> {
386
400
  /** URL that is the base background page when navigating to the dialog directly. */
387
401
  baseUrl: string;
388
402
  /** URL to which the dialog should redirect when closed. */
@@ -403,6 +417,8 @@ interface SwapOptions<T> {
403
417
  preserveState?: boolean;
404
418
  /** Current dialog. */
405
419
  dialog?: Dialog;
420
+ /** On mounted callback. */
421
+ onMounted?: (options: MountedHookOptions) => void;
406
422
  }
407
423
  type ViewComponent = any;
408
424
  type ResolveComponent = (name: string) => Promise<ViewComponent>;
package/dist/index.mjs CHANGED
@@ -229,19 +229,25 @@ const wrapper = defineComponent({
229
229
  renderDialog()
230
230
  ];
231
231
  }
232
- function renderView() {
233
- debug.adapter("vue:render:view", "Rendering view.");
234
- state.view.value.inheritAttrs = !!state.view.value.inheritAttrs;
235
- const actual = state.view.value?.mounted;
236
- state.view.value.mounted = () => {
232
+ function hijackOnMounted(component, type) {
233
+ if (!component) {
234
+ return;
235
+ }
236
+ const actual = component?.mounted;
237
+ component.mounted = () => {
237
238
  actual?.();
238
239
  nextTick(() => {
239
- debug.adapter("vue:render:view", "Calling mounted callbacks.");
240
+ debug.adapter(`vue:render:${type}`, "Calling mounted callbacks.");
240
241
  while (onMountedCallbacks.length) {
241
242
  onMountedCallbacks.shift()?.();
242
243
  }
243
244
  });
244
245
  };
246
+ }
247
+ function renderView() {
248
+ debug.adapter("vue:render:view", "Rendering view.");
249
+ state.view.value.inheritAttrs = !!state.view.value.inheritAttrs;
250
+ hijackOnMounted(state.view.value, "view");
245
251
  return h(state.view.value, {
246
252
  ...state.properties.value,
247
253
  key: state.viewKey.value
@@ -250,6 +256,7 @@ const wrapper = defineComponent({
250
256
  function renderDialog() {
251
257
  if (dialogStore.state.component.value && dialogStore.state.properties.value) {
252
258
  debug.adapter("vue:render:dialog", "Rendering dialog.");
259
+ hijackOnMounted(dialogStore.state.component.value, "dialog");
253
260
  return h(dialogStore.state.component.value, {
254
261
  ...dialogStore.state.properties.value,
255
262
  key: dialogStore.state.key.value
@@ -303,6 +310,11 @@ function setupDevtools(app) {
303
310
  key: "component",
304
311
  value: state.context.value?.view.component
305
312
  });
313
+ payload.instanceData.state.push({
314
+ type: hybridlyStateType,
315
+ key: "deferred",
316
+ value: state.context.value?.view.deferred
317
+ });
306
318
  payload.instanceData.state.push({
307
319
  type: hybridlyStateType,
308
320
  key: "dialog",
@@ -397,8 +409,8 @@ function viewTransition() {
397
409
  let domUpdated;
398
410
  return {
399
411
  name: "view-transition",
400
- navigating: async ({ isInitial }) => {
401
- if (isInitial) {
412
+ navigating: async ({ type, hasDialog }) => {
413
+ if (type === "initial" || hasDialog) {
402
414
  return;
403
415
  }
404
416
  return new Promise((confirmTransitionStarted) => document.startViewTransition(() => {
@@ -409,6 +421,10 @@ function viewTransition() {
409
421
  mounted: () => {
410
422
  domUpdated?.();
411
423
  domUpdated = void 0;
424
+ },
425
+ navigated: () => {
426
+ domUpdated?.();
427
+ domUpdated = void 0;
412
428
  }
413
429
  };
414
430
  }
@@ -437,12 +453,16 @@ async function initializeHybridly(options = {}) {
437
453
  state.setContext(context);
438
454
  },
439
455
  onViewSwap: async (options2) => {
440
- state.setView(options2.component);
456
+ if (options2.component) {
457
+ onMountedCallbacks.push(() => options2.onMounted?.({ isDialog: false }));
458
+ state.setView(options2.component);
459
+ }
441
460
  state.setProperties(options2.properties);
442
461
  if (!options2.preserveState && !options2.dialog) {
443
462
  state.setViewKey(random());
444
463
  }
445
464
  if (options2.dialog) {
465
+ onMountedCallbacks.push(() => options2.onMounted?.({ isDialog: true }));
446
466
  dialogStore.setComponent(await resolve(options2.dialog.component));
447
467
  dialogStore.setProperties(options2.dialog.properties);
448
468
  dialogStore.setKey(options2.dialog.key);
@@ -873,7 +893,7 @@ function useHistoryState(key, initial) {
873
893
  function useBackForward() {
874
894
  const callbacks = [];
875
895
  registerHook$1("navigated", (options) => {
876
- if (options.isBackForward) {
896
+ if (options.type === "back-forward") {
877
897
  callbacks.forEach((fn) => fn(state.context.value));
878
898
  callbacks.splice(0, callbacks.length);
879
899
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybridly/vue",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Vue adapter for Hybridly",
5
5
  "keywords": [
6
6
  "hybridly",
@@ -44,11 +44,11 @@
44
44
  "lodash.isequal": "^4.5.0",
45
45
  "nprogress": "^0.2.0",
46
46
  "qs": "^6.11.2",
47
- "@hybridly/core": "0.4.4",
48
- "@hybridly/utils": "0.4.4"
47
+ "@hybridly/core": "0.4.5",
48
+ "@hybridly/utils": "0.4.5"
49
49
  },
50
50
  "devDependencies": {
51
- "@types/lodash": "^4.14.197",
51
+ "@types/lodash": "^4.14.198",
52
52
  "@types/lodash.clonedeep": "^4.5.7",
53
53
  "@types/lodash.isequal": "^4.5.6",
54
54
  "@types/nprogress": "^0.2.0",