@hybridly/vue 0.4.0 → 0.4.1

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
@@ -127,7 +127,9 @@ const wrapper = vue.defineComponent({
127
127
  actual?.();
128
128
  vue.nextTick(() => {
129
129
  utils.debug.adapter("vue:render:view", "Calling mounted callbacks.");
130
- onMountedCallbacks.pop()?.();
130
+ while (onMountedCallbacks.length) {
131
+ onMountedCallbacks.shift()?.();
132
+ }
131
133
  });
132
134
  };
133
135
  return vue.h(state.view.value, {
@@ -288,7 +290,7 @@ async function initializeHybridly(options = {}) {
288
290
  routing: resolved.routing,
289
291
  adapter: {
290
292
  resolveComponent: resolve,
291
- onWaitingForMount: (callback) => {
293
+ executeOnMounted: (callback) => {
292
294
  onMountedCallbacks.push(callback);
293
295
  },
294
296
  onDialogClose: async () => {
@@ -391,6 +393,7 @@ const RouterLink = vue.defineComponent({
391
393
  setup(_, { slots, attrs }) {
392
394
  return (props) => {
393
395
  let data = props.data ?? {};
396
+ const preloads = props.preload ?? false;
394
397
  const url = core.makeUrl(props.href ?? "");
395
398
  const method = props.method?.toUpperCase() ?? "GET";
396
399
  const as = typeof props.as === "object" ? props.as : props.as?.toLowerCase() ?? "a";
@@ -413,6 +416,24 @@ Please specify a more appropriate element using the "as" attribute. For example:
413
416
  ...attrs,
414
417
  ...as === "a" ? { href: url } : {},
415
418
  ...props.disabled ? { disabled: props.disabled } : {},
419
+ onMouseenter: () => {
420
+ if (!preloads) {
421
+ return;
422
+ }
423
+ if (props.external) {
424
+ return;
425
+ }
426
+ if (props.disabled) {
427
+ return;
428
+ }
429
+ if (method !== "GET") {
430
+ return;
431
+ }
432
+ core.router.preload(url, {
433
+ data,
434
+ ...props.options
435
+ });
436
+ },
416
437
  onClick: (event) => {
417
438
  if (props.external) {
418
439
  return;
@@ -469,6 +490,10 @@ Please specify a more appropriate element using the "as" attribute. For example:
469
490
  type: String,
470
491
  required: false,
471
492
  default: void 0
493
+ },
494
+ preload: {
495
+ type: Boolean,
496
+ default: false
472
497
  }
473
498
  }
474
499
  });
package/dist/index.d.ts CHANGED
@@ -85,6 +85,10 @@ declare const RouterLink: vue.DefineComponent<{
85
85
  required: false;
86
86
  default: undefined;
87
87
  };
88
+ preload: {
89
+ type: BooleanConstructor;
90
+ default: boolean;
91
+ };
88
92
  }, (props: _vue_shared.LooseRequired<{
89
93
  readonly data: RequestData;
90
94
  readonly method: "delete" | Method$1 | "get" | "post" | "put" | "patch";
@@ -92,6 +96,7 @@ declare const RouterLink: vue.DefineComponent<{
92
96
  readonly as: string | Record<string, any>;
93
97
  readonly external: boolean;
94
98
  readonly disabled: boolean;
99
+ readonly preload: boolean;
95
100
  readonly text?: string | undefined;
96
101
  readonly href?: string | undefined;
97
102
  } & {}>) => vue.VNode<vue.RendererNode, vue.RendererElement, {
@@ -131,6 +136,10 @@ declare const RouterLink: vue.DefineComponent<{
131
136
  required: false;
132
137
  default: undefined;
133
138
  };
139
+ preload: {
140
+ type: BooleanConstructor;
141
+ default: boolean;
142
+ };
134
143
  }>>, {
135
144
  data: RequestData;
136
145
  text: string;
@@ -140,6 +149,7 @@ declare const RouterLink: vue.DefineComponent<{
140
149
  as: string | Record<string, any>;
141
150
  external: boolean;
142
151
  disabled: boolean;
152
+ preload: boolean;
143
153
  }, {}>;
144
154
 
145
155
  /** Accesses all current properties. */
@@ -223,6 +233,10 @@ interface Hooks extends RequestHooks {
223
233
  * Called when a component has been navigated to.
224
234
  */
225
235
  navigated: (options: NavigationOptions, context: InternalRouterContext) => MaybePromise<any>;
236
+ /**
237
+ * Called when a component has been navigated to and was mounted by the adapter.
238
+ */
239
+ mounted: (context: InternalRouterContext) => MaybePromise<any>;
226
240
  }
227
241
 
228
242
  interface RoutingConfiguration {
@@ -405,6 +419,8 @@ interface InternalRouterContext {
405
419
  routing?: RoutingConfiguration;
406
420
  /** Whether to display response error modals. */
407
421
  responseErrorModals?: boolean;
422
+ /** Cache of preload requests. */
423
+ preloadCache: Map<string, AxiosResponse>;
408
424
  }
409
425
  /** Adapter-specific functions. */
410
426
  interface Adapter {
@@ -417,7 +433,7 @@ interface Adapter {
417
433
  /** Called when a dialog is closed. */
418
434
  onDialogClose?: (context: InternalRouterContext) => void;
419
435
  /** Called when Hybridly is waiting for a component to be mounted. The given callback should be executed after the view component is mounted. */
420
- onWaitingForMount: (callback: Function) => void;
436
+ executeOnMounted: (callback: Function) => void;
421
437
  }
422
438
  interface ResolvedAdapter extends Adapter {
423
439
  updateRoutingConfiguration: (routing?: RoutingConfiguration) => void;
package/dist/index.mjs CHANGED
@@ -119,7 +119,9 @@ const wrapper = defineComponent({
119
119
  actual?.();
120
120
  nextTick(() => {
121
121
  debug.adapter("vue:render:view", "Calling mounted callbacks.");
122
- onMountedCallbacks.pop()?.();
122
+ while (onMountedCallbacks.length) {
123
+ onMountedCallbacks.shift()?.();
124
+ }
123
125
  });
124
126
  };
125
127
  return h(state.view.value, {
@@ -280,7 +282,7 @@ async function initializeHybridly(options = {}) {
280
282
  routing: resolved.routing,
281
283
  adapter: {
282
284
  resolveComponent: resolve,
283
- onWaitingForMount: (callback) => {
285
+ executeOnMounted: (callback) => {
284
286
  onMountedCallbacks.push(callback);
285
287
  },
286
288
  onDialogClose: async () => {
@@ -383,6 +385,7 @@ const RouterLink = defineComponent({
383
385
  setup(_, { slots, attrs }) {
384
386
  return (props) => {
385
387
  let data = props.data ?? {};
388
+ const preloads = props.preload ?? false;
386
389
  const url = makeUrl(props.href ?? "");
387
390
  const method = props.method?.toUpperCase() ?? "GET";
388
391
  const as = typeof props.as === "object" ? props.as : props.as?.toLowerCase() ?? "a";
@@ -405,6 +408,24 @@ Please specify a more appropriate element using the "as" attribute. For example:
405
408
  ...attrs,
406
409
  ...as === "a" ? { href: url } : {},
407
410
  ...props.disabled ? { disabled: props.disabled } : {},
411
+ onMouseenter: () => {
412
+ if (!preloads) {
413
+ return;
414
+ }
415
+ if (props.external) {
416
+ return;
417
+ }
418
+ if (props.disabled) {
419
+ return;
420
+ }
421
+ if (method !== "GET") {
422
+ return;
423
+ }
424
+ router.preload(url, {
425
+ data,
426
+ ...props.options
427
+ });
428
+ },
408
429
  onClick: (event) => {
409
430
  if (props.external) {
410
431
  return;
@@ -461,6 +482,10 @@ Please specify a more appropriate element using the "as" attribute. For example:
461
482
  type: String,
462
483
  required: false,
463
484
  default: void 0
485
+ },
486
+ preload: {
487
+ type: Boolean,
488
+ default: false
464
489
  }
465
490
  }
466
491
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybridly/vue",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Vue adapter for Hybridly",
5
5
  "keywords": [
6
6
  "hybridly",
@@ -44,9 +44,9 @@
44
44
  "lodash.isequal": "^4.5.0",
45
45
  "nprogress": "^0.2.0",
46
46
  "qs": "^6.11.2",
47
- "@hybridly/core": "0.4.0",
48
- "@hybridly/utils": "0.4.0",
49
- "@hybridly/progress-plugin": "0.4.0"
47
+ "@hybridly/core": "0.4.1",
48
+ "@hybridly/progress-plugin": "0.4.1",
49
+ "@hybridly/utils": "0.4.1"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/lodash": "^4.14.195",