@hybridly/vue 0.4.3 → 0.4.4

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
@@ -3,7 +3,7 @@
3
3
  const vue = require('vue');
4
4
  const core = require('@hybridly/core');
5
5
  const utils = require('@hybridly/utils');
6
- const progressPlugin = require('@hybridly/progress-plugin');
6
+ const nprogress = require('nprogress');
7
7
  const devtoolsApi = require('@vue/devtools-api');
8
8
  const qs = require('qs');
9
9
  const dotDiver = require('@clickbar/dot-diver');
@@ -12,9 +12,128 @@ const hybridly = require('hybridly');
12
12
 
13
13
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
14
 
15
+ const nprogress__default = /*#__PURE__*/_interopDefaultCompat(nprogress);
15
16
  const qs__default = /*#__PURE__*/_interopDefaultCompat(qs);
16
17
  const isEqual__default = /*#__PURE__*/_interopDefaultCompat(isEqual);
17
18
 
19
+ function progress(options) {
20
+ const resolved = {
21
+ delay: 250,
22
+ color: "#29d",
23
+ includeCSS: true,
24
+ spinner: false,
25
+ ...options
26
+ };
27
+ let timeout;
28
+ function startProgress() {
29
+ nprogress__default.start();
30
+ }
31
+ function finishProgress() {
32
+ if (nprogress__default.isStarted()) {
33
+ nprogress__default.done(true);
34
+ }
35
+ }
36
+ function cancelProgress() {
37
+ if (nprogress__default.isStarted()) {
38
+ nprogress__default.done(true);
39
+ nprogress__default.remove();
40
+ }
41
+ }
42
+ return core.definePlugin({
43
+ name: "hybridly:progress",
44
+ initialized() {
45
+ nprogress__default.configure({ showSpinner: resolved.spinner });
46
+ if (resolved.includeCSS) {
47
+ injectCSS(resolved.color);
48
+ }
49
+ },
50
+ start: (context) => {
51
+ if (context.pendingNavigation?.options.progress === false) {
52
+ return;
53
+ }
54
+ clearTimeout(timeout);
55
+ timeout = setTimeout(() => {
56
+ finishProgress();
57
+ startProgress();
58
+ }, resolved.delay);
59
+ },
60
+ progress: (progress2) => {
61
+ if (nprogress__default.isStarted() && progress2.percentage) {
62
+ nprogress__default.set(Math.max(nprogress__default.status, progress2.percentage / 100 * 0.9));
63
+ }
64
+ },
65
+ success: () => finishProgress(),
66
+ error: () => cancelProgress(),
67
+ fail: () => cancelProgress(),
68
+ after: () => clearTimeout(timeout)
69
+ });
70
+ }
71
+ function injectCSS(color) {
72
+ const element = document.createElement("style");
73
+ element.textContent = `
74
+ #nprogress {
75
+ pointer-events: none;
76
+ --progress-color: ${color};
77
+ }
78
+ #nprogress .bar {
79
+ background: var(--progress-color);
80
+ position: fixed;
81
+ z-index: 1031;
82
+ top: 0;
83
+ left: 0;
84
+ width: 100%;
85
+ height: 2px;
86
+ }
87
+ #nprogress .peg {
88
+ display: block;
89
+ position: absolute;
90
+ right: 0px;
91
+ width: 100px;
92
+ height: 100%;
93
+ box-shadow: 0 0 10px var(--progress-color), 0 0 5px var(--progress-color);
94
+ opacity: 1.0;
95
+ -webkit-transform: rotate(3deg) translate(0px, -4px);
96
+ -ms-transform: rotate(3deg) translate(0px, -4px);
97
+ transform: rotate(3deg) translate(0px, -4px);
98
+ }
99
+ #nprogress .spinner {
100
+ display: block;
101
+ position: fixed;
102
+ z-index: 1031;
103
+ top: 15px;
104
+ right: 15px;
105
+ }
106
+ #nprogress .spinner-icon {
107
+ width: 18px;
108
+ height: 18px;
109
+ box-sizing: border-box;
110
+ border: solid 2px transparent;
111
+ border-top-color: var(--progress-color);
112
+ border-left-color: var(--progress-color);
113
+ border-radius: 50%;
114
+ -webkit-animation: nprogress-spinner 400ms linear infinite;
115
+ animation: nprogress-spinner 400ms linear infinite;
116
+ }
117
+ .nprogress-custom-parent {
118
+ overflow: hidden;
119
+ position: relative;
120
+ }
121
+ .nprogress-custom-parent #nprogress .spinner,
122
+ .nprogress-custom-parent #nprogress .bar {
123
+ position: absolute;
124
+ }
125
+ @-webkit-keyframes nprogress-spinner {
126
+ 0% { -webkit-transform: rotate(0deg); }
127
+ 100% { -webkit-transform: rotate(360deg); }
128
+ }
129
+ @keyframes nprogress-spinner {
130
+ 0% { transform: rotate(0deg); }
131
+ 100% { transform: rotate(360deg); }
132
+ }
133
+ `;
134
+ document.head.appendChild(element);
135
+ }
136
+
18
137
  const DEBUG_KEY = "vue:state:dialog";
19
138
  const dialogStore = {
20
139
  state: {
@@ -278,6 +397,29 @@ const devtools = {
278
397
  }
279
398
  };
280
399
 
400
+ function viewTransition() {
401
+ if (!document.startViewTransition) {
402
+ return { name: "view-transition" };
403
+ }
404
+ let domUpdated;
405
+ return {
406
+ name: "view-transition",
407
+ navigating: async ({ isInitial }) => {
408
+ if (isInitial) {
409
+ return;
410
+ }
411
+ return new Promise((confirmTransitionStarted) => document.startViewTransition(() => {
412
+ confirmTransitionStarted(true);
413
+ return new Promise((resolve) => domUpdated = resolve);
414
+ }));
415
+ },
416
+ mounted: () => {
417
+ domUpdated?.();
418
+ domUpdated = void 0;
419
+ }
420
+ };
421
+ }
422
+
281
423
  async function initializeHybridly(options = {}) {
282
424
  const resolved = options;
283
425
  const { element, payload, resolve } = prepare(resolved);
@@ -363,11 +505,12 @@ function prepare(options) {
363
505
  }
364
506
  return await resolveViewComponent(name, options);
365
507
  };
508
+ options.plugins ?? (options.plugins = []);
366
509
  if (options.progress !== false) {
367
- options.plugins = [
368
- progressPlugin.progress(typeof options.progress === "object" ? options.progress : {}),
369
- ...options.plugins ?? []
370
- ];
510
+ options.plugins.push(progress(typeof options.progress === "object" ? options.progress : {}));
511
+ }
512
+ if (options.viewTransition !== false) {
513
+ options.plugins.push(viewTransition());
371
514
  }
372
515
  return {
373
516
  isServer,
package/dist/index.d.cts CHANGED
@@ -4,11 +4,38 @@ import * as _hybridly_core from '@hybridly/core';
4
4
  import { RouterContextOptions, Plugin as Plugin$1, RouterContext, Method as Method$1, HybridRequestOptions as HybridRequestOptions$1, UrlResolvable as UrlResolvable$1, registerHook as registerHook$1 } from '@hybridly/core';
5
5
  export { can, route, router } from '@hybridly/core';
6
6
  import { Axios, AxiosResponse, AxiosProgressEvent } from 'axios';
7
- import { ProgressOptions } from '@hybridly/progress-plugin';
8
7
  import * as _vue_shared from '@vue/shared';
9
8
  import { RequestData } from '@hybridly/utils';
10
9
  import { SearchableObject, Path, PathValue } from '@clickbar/dot-diver';
11
10
 
11
+ interface ProgressOptions {
12
+ /**
13
+ * The delay after which the progress bar will
14
+ * appear during navigation, in milliseconds.
15
+ *
16
+ * @default 250
17
+ */
18
+ delay: number;
19
+ /**
20
+ * The color of the progress bar.
21
+ *
22
+ * Defaults to #29d.
23
+ */
24
+ color: string;
25
+ /**
26
+ * Whether to include the default NProgress styles.
27
+ *
28
+ * Defaults to true.
29
+ */
30
+ includeCSS: boolean;
31
+ /**
32
+ * Whether the NProgress spinner will be shown.
33
+ *
34
+ * Defaults to false.
35
+ */
36
+ spinner: boolean;
37
+ }
38
+
12
39
  /**
13
40
  * Initializes Hybridly's router and context.
14
41
  */
@@ -34,6 +61,11 @@ interface InitializeOptions {
34
61
  plugins?: Plugin$1[];
35
62
  /** Custom Axios instance. */
36
63
  axios?: Axios;
64
+ /**
65
+ * Enables the View Transition API, if supported.
66
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition
67
+ */
68
+ viewTransition?: boolean;
37
69
  }
38
70
  interface SetupArguments {
39
71
  /** DOM element to mount Vue on. */
@@ -294,6 +326,11 @@ interface NavigationOptions {
294
326
  * @internal This is an advanced property meant to be used internally.
295
327
  */
296
328
  isBackForward?: boolean;
329
+ /**
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.
332
+ */
333
+ isInitial?: boolean;
297
334
  }
298
335
  type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
299
336
  interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
package/dist/index.d.mts CHANGED
@@ -4,11 +4,38 @@ import * as _hybridly_core from '@hybridly/core';
4
4
  import { RouterContextOptions, Plugin as Plugin$1, RouterContext, Method as Method$1, HybridRequestOptions as HybridRequestOptions$1, UrlResolvable as UrlResolvable$1, registerHook as registerHook$1 } from '@hybridly/core';
5
5
  export { can, route, router } from '@hybridly/core';
6
6
  import { Axios, AxiosResponse, AxiosProgressEvent } from 'axios';
7
- import { ProgressOptions } from '@hybridly/progress-plugin';
8
7
  import * as _vue_shared from '@vue/shared';
9
8
  import { RequestData } from '@hybridly/utils';
10
9
  import { SearchableObject, Path, PathValue } from '@clickbar/dot-diver';
11
10
 
11
+ interface ProgressOptions {
12
+ /**
13
+ * The delay after which the progress bar will
14
+ * appear during navigation, in milliseconds.
15
+ *
16
+ * @default 250
17
+ */
18
+ delay: number;
19
+ /**
20
+ * The color of the progress bar.
21
+ *
22
+ * Defaults to #29d.
23
+ */
24
+ color: string;
25
+ /**
26
+ * Whether to include the default NProgress styles.
27
+ *
28
+ * Defaults to true.
29
+ */
30
+ includeCSS: boolean;
31
+ /**
32
+ * Whether the NProgress spinner will be shown.
33
+ *
34
+ * Defaults to false.
35
+ */
36
+ spinner: boolean;
37
+ }
38
+
12
39
  /**
13
40
  * Initializes Hybridly's router and context.
14
41
  */
@@ -34,6 +61,11 @@ interface InitializeOptions {
34
61
  plugins?: Plugin$1[];
35
62
  /** Custom Axios instance. */
36
63
  axios?: Axios;
64
+ /**
65
+ * Enables the View Transition API, if supported.
66
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition
67
+ */
68
+ viewTransition?: boolean;
37
69
  }
38
70
  interface SetupArguments {
39
71
  /** DOM element to mount Vue on. */
@@ -294,6 +326,11 @@ interface NavigationOptions {
294
326
  * @internal This is an advanced property meant to be used internally.
295
327
  */
296
328
  isBackForward?: boolean;
329
+ /**
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.
332
+ */
333
+ isInitial?: boolean;
297
334
  }
298
335
  type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
299
336
  interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
package/dist/index.d.ts CHANGED
@@ -4,11 +4,38 @@ import * as _hybridly_core from '@hybridly/core';
4
4
  import { RouterContextOptions, Plugin as Plugin$1, RouterContext, Method as Method$1, HybridRequestOptions as HybridRequestOptions$1, UrlResolvable as UrlResolvable$1, registerHook as registerHook$1 } from '@hybridly/core';
5
5
  export { can, route, router } from '@hybridly/core';
6
6
  import { Axios, AxiosResponse, AxiosProgressEvent } from 'axios';
7
- import { ProgressOptions } from '@hybridly/progress-plugin';
8
7
  import * as _vue_shared from '@vue/shared';
9
8
  import { RequestData } from '@hybridly/utils';
10
9
  import { SearchableObject, Path, PathValue } from '@clickbar/dot-diver';
11
10
 
11
+ interface ProgressOptions {
12
+ /**
13
+ * The delay after which the progress bar will
14
+ * appear during navigation, in milliseconds.
15
+ *
16
+ * @default 250
17
+ */
18
+ delay: number;
19
+ /**
20
+ * The color of the progress bar.
21
+ *
22
+ * Defaults to #29d.
23
+ */
24
+ color: string;
25
+ /**
26
+ * Whether to include the default NProgress styles.
27
+ *
28
+ * Defaults to true.
29
+ */
30
+ includeCSS: boolean;
31
+ /**
32
+ * Whether the NProgress spinner will be shown.
33
+ *
34
+ * Defaults to false.
35
+ */
36
+ spinner: boolean;
37
+ }
38
+
12
39
  /**
13
40
  * Initializes Hybridly's router and context.
14
41
  */
@@ -34,6 +61,11 @@ interface InitializeOptions {
34
61
  plugins?: Plugin$1[];
35
62
  /** Custom Axios instance. */
36
63
  axios?: Axios;
64
+ /**
65
+ * Enables the View Transition API, if supported.
66
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition
67
+ */
68
+ viewTransition?: boolean;
37
69
  }
38
70
  interface SetupArguments {
39
71
  /** DOM element to mount Vue on. */
@@ -294,6 +326,11 @@ interface NavigationOptions {
294
326
  * @internal This is an advanced property meant to be used internally.
295
327
  */
296
328
  isBackForward?: boolean;
329
+ /**
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.
332
+ */
333
+ isInitial?: boolean;
297
334
  }
298
335
  type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
299
336
  interface HybridRequestOptions extends Omit<NavigationOptions, 'payload'> {
package/dist/index.mjs CHANGED
@@ -1,14 +1,132 @@
1
1
  import { shallowRef, ref, unref, triggerRef, defineComponent, toRaw, h, nextTick, createApp, isRef, reactive, readonly, computed, toValue, watch, getCurrentInstance, onUnmounted } from 'vue';
2
- import { registerHook as registerHook$1, createRouter, makeUrl, router } from '@hybridly/core';
2
+ import { definePlugin, registerHook as registerHook$1, createRouter, makeUrl, router } from '@hybridly/core';
3
3
  export { can, route, router } from '@hybridly/core';
4
4
  import { debug, random, showPageComponentErrorModal, merge, clone, unsetPropertyAtPath, setValueAtPath } from '@hybridly/utils';
5
- import { progress } from '@hybridly/progress-plugin';
5
+ import nprogress from 'nprogress';
6
6
  import { setupDevtoolsPlugin } from '@vue/devtools-api';
7
7
  import qs from 'qs';
8
8
  import { getByPath, setByPath } from '@clickbar/dot-diver';
9
9
  import isEqual from 'lodash.isequal';
10
10
  import { router as router$1 } from 'hybridly';
11
11
 
12
+ function progress(options) {
13
+ const resolved = {
14
+ delay: 250,
15
+ color: "#29d",
16
+ includeCSS: true,
17
+ spinner: false,
18
+ ...options
19
+ };
20
+ let timeout;
21
+ function startProgress() {
22
+ nprogress.start();
23
+ }
24
+ function finishProgress() {
25
+ if (nprogress.isStarted()) {
26
+ nprogress.done(true);
27
+ }
28
+ }
29
+ function cancelProgress() {
30
+ if (nprogress.isStarted()) {
31
+ nprogress.done(true);
32
+ nprogress.remove();
33
+ }
34
+ }
35
+ return definePlugin({
36
+ name: "hybridly:progress",
37
+ initialized() {
38
+ nprogress.configure({ showSpinner: resolved.spinner });
39
+ if (resolved.includeCSS) {
40
+ injectCSS(resolved.color);
41
+ }
42
+ },
43
+ start: (context) => {
44
+ if (context.pendingNavigation?.options.progress === false) {
45
+ return;
46
+ }
47
+ clearTimeout(timeout);
48
+ timeout = setTimeout(() => {
49
+ finishProgress();
50
+ startProgress();
51
+ }, resolved.delay);
52
+ },
53
+ progress: (progress2) => {
54
+ if (nprogress.isStarted() && progress2.percentage) {
55
+ nprogress.set(Math.max(nprogress.status, progress2.percentage / 100 * 0.9));
56
+ }
57
+ },
58
+ success: () => finishProgress(),
59
+ error: () => cancelProgress(),
60
+ fail: () => cancelProgress(),
61
+ after: () => clearTimeout(timeout)
62
+ });
63
+ }
64
+ function injectCSS(color) {
65
+ const element = document.createElement("style");
66
+ element.textContent = `
67
+ #nprogress {
68
+ pointer-events: none;
69
+ --progress-color: ${color};
70
+ }
71
+ #nprogress .bar {
72
+ background: var(--progress-color);
73
+ position: fixed;
74
+ z-index: 1031;
75
+ top: 0;
76
+ left: 0;
77
+ width: 100%;
78
+ height: 2px;
79
+ }
80
+ #nprogress .peg {
81
+ display: block;
82
+ position: absolute;
83
+ right: 0px;
84
+ width: 100px;
85
+ height: 100%;
86
+ box-shadow: 0 0 10px var(--progress-color), 0 0 5px var(--progress-color);
87
+ opacity: 1.0;
88
+ -webkit-transform: rotate(3deg) translate(0px, -4px);
89
+ -ms-transform: rotate(3deg) translate(0px, -4px);
90
+ transform: rotate(3deg) translate(0px, -4px);
91
+ }
92
+ #nprogress .spinner {
93
+ display: block;
94
+ position: fixed;
95
+ z-index: 1031;
96
+ top: 15px;
97
+ right: 15px;
98
+ }
99
+ #nprogress .spinner-icon {
100
+ width: 18px;
101
+ height: 18px;
102
+ box-sizing: border-box;
103
+ border: solid 2px transparent;
104
+ border-top-color: var(--progress-color);
105
+ border-left-color: var(--progress-color);
106
+ border-radius: 50%;
107
+ -webkit-animation: nprogress-spinner 400ms linear infinite;
108
+ animation: nprogress-spinner 400ms linear infinite;
109
+ }
110
+ .nprogress-custom-parent {
111
+ overflow: hidden;
112
+ position: relative;
113
+ }
114
+ .nprogress-custom-parent #nprogress .spinner,
115
+ .nprogress-custom-parent #nprogress .bar {
116
+ position: absolute;
117
+ }
118
+ @-webkit-keyframes nprogress-spinner {
119
+ 0% { -webkit-transform: rotate(0deg); }
120
+ 100% { -webkit-transform: rotate(360deg); }
121
+ }
122
+ @keyframes nprogress-spinner {
123
+ 0% { transform: rotate(0deg); }
124
+ 100% { transform: rotate(360deg); }
125
+ }
126
+ `;
127
+ document.head.appendChild(element);
128
+ }
129
+
12
130
  const DEBUG_KEY = "vue:state:dialog";
13
131
  const dialogStore = {
14
132
  state: {
@@ -272,6 +390,29 @@ const devtools = {
272
390
  }
273
391
  };
274
392
 
393
+ function viewTransition() {
394
+ if (!document.startViewTransition) {
395
+ return { name: "view-transition" };
396
+ }
397
+ let domUpdated;
398
+ return {
399
+ name: "view-transition",
400
+ navigating: async ({ isInitial }) => {
401
+ if (isInitial) {
402
+ return;
403
+ }
404
+ return new Promise((confirmTransitionStarted) => document.startViewTransition(() => {
405
+ confirmTransitionStarted(true);
406
+ return new Promise((resolve) => domUpdated = resolve);
407
+ }));
408
+ },
409
+ mounted: () => {
410
+ domUpdated?.();
411
+ domUpdated = void 0;
412
+ }
413
+ };
414
+ }
415
+
275
416
  async function initializeHybridly(options = {}) {
276
417
  const resolved = options;
277
418
  const { element, payload, resolve } = prepare(resolved);
@@ -357,11 +498,12 @@ function prepare(options) {
357
498
  }
358
499
  return await resolveViewComponent(name, options);
359
500
  };
501
+ options.plugins ?? (options.plugins = []);
360
502
  if (options.progress !== false) {
361
- options.plugins = [
362
- progress(typeof options.progress === "object" ? options.progress : {}),
363
- ...options.plugins ?? []
364
- ];
503
+ options.plugins.push(progress(typeof options.progress === "object" ? options.progress : {}));
504
+ }
505
+ if (options.viewTransition !== false) {
506
+ options.plugins.push(viewTransition());
365
507
  }
366
508
  return {
367
509
  isServer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hybridly/vue",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Vue adapter for Hybridly",
5
5
  "keywords": [
6
6
  "hybridly",
@@ -44,9 +44,8 @@
44
44
  "lodash.isequal": "^4.5.0",
45
45
  "nprogress": "^0.2.0",
46
46
  "qs": "^6.11.2",
47
- "@hybridly/core": "0.4.3",
48
- "@hybridly/progress-plugin": "0.4.3",
49
- "@hybridly/utils": "0.4.3"
47
+ "@hybridly/core": "0.4.4",
48
+ "@hybridly/utils": "0.4.4"
50
49
  },
51
50
  "devDependencies": {
52
51
  "@types/lodash": "^4.14.197",