@hybridly/vue 0.4.2 → 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
@@ -1,21 +1,138 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  const vue = require('vue');
6
4
  const core = require('@hybridly/core');
7
5
  const utils = require('@hybridly/utils');
8
- const progressPlugin = require('@hybridly/progress-plugin');
6
+ const nprogress = require('nprogress');
9
7
  const devtoolsApi = require('@vue/devtools-api');
10
8
  const qs = require('qs');
11
9
  const dotDiver = require('@clickbar/dot-diver');
12
10
  const isEqual = require('lodash.isequal');
13
11
  const hybridly = require('hybridly');
14
12
 
15
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
13
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
16
14
 
17
- const qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
18
- const isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
15
+ const nprogress__default = /*#__PURE__*/_interopDefaultCompat(nprogress);
16
+ const qs__default = /*#__PURE__*/_interopDefaultCompat(qs);
17
+ const isEqual__default = /*#__PURE__*/_interopDefaultCompat(isEqual);
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
+ }
19
136
 
20
137
  const DEBUG_KEY = "vue:state:dialog";
21
138
  const dialogStore = {
@@ -226,7 +343,9 @@ function setupDevtools(app) {
226
343
  });
227
344
  const listen = [
228
345
  "start",
346
+ "ready",
229
347
  "data",
348
+ "navigating",
230
349
  "navigated",
231
350
  "progress",
232
351
  "error",
@@ -235,7 +354,9 @@ function setupDevtools(app) {
235
354
  "invalid",
236
355
  "exception",
237
356
  "fail",
238
- "after"
357
+ "after",
358
+ "backForward",
359
+ "success"
239
360
  ];
240
361
  core.registerHook("before", (options) => {
241
362
  const groupId = (Math.random() + 1).toString(36).substring(7);
@@ -276,6 +397,29 @@ const devtools = {
276
397
  }
277
398
  };
278
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
+
279
423
  async function initializeHybridly(options = {}) {
280
424
  const resolved = options;
281
425
  const { element, payload, resolve } = prepare(resolved);
@@ -361,11 +505,12 @@ function prepare(options) {
361
505
  }
362
506
  return await resolveViewComponent(name, options);
363
507
  };
508
+ options.plugins ?? (options.plugins = []);
364
509
  if (options.progress !== false) {
365
- options.plugins = [
366
- progressPlugin.progress(typeof options.progress === "object" ? options.progress : {}),
367
- ...options.plugins ?? []
368
- ];
510
+ options.plugins.push(progress(typeof options.progress === "object" ? options.progress : {}));
511
+ }
512
+ if (options.viewTransition !== false) {
513
+ options.plugins.push(viewTransition());
369
514
  }
370
515
  return {
371
516
  isServer,
@@ -412,28 +557,36 @@ Please specify a more appropriate element using the "as" attribute. For example:
412
557
 
413
558
  <RouterLink href="${url}" method="${method}" as="button">...</RouterLink>`);
414
559
  }
560
+ function performPreload(type) {
561
+ if (!preloads) {
562
+ return;
563
+ }
564
+ if (props.external) {
565
+ return;
566
+ }
567
+ if (method !== "GET") {
568
+ return;
569
+ }
570
+ if (type !== "mount" && props.disabled) {
571
+ return;
572
+ }
573
+ if (type === "hover" && preloads === "mount") {
574
+ return;
575
+ }
576
+ if (type === "mount" && preloads !== "mount") {
577
+ return;
578
+ }
579
+ core.router.preload(url, {
580
+ data,
581
+ ...props.options
582
+ });
583
+ }
584
+ performPreload("mount");
415
585
  return vue.h(props.as, {
416
586
  ...attrs,
417
587
  ...as === "a" ? { href: url } : {},
418
588
  ...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
- },
589
+ onMouseenter: () => performPreload("hover"),
437
590
  onClick: (event) => {
438
591
  if (props.external) {
439
592
  return;
@@ -492,7 +645,7 @@ Please specify a more appropriate element using the "as" attribute. For example:
492
645
  default: void 0
493
646
  },
494
647
  preload: {
495
- type: Boolean,
648
+ type: [Boolean, String],
496
649
  default: false
497
650
  }
498
651
  }
@@ -698,6 +851,8 @@ function useForm(options) {
698
851
  clearError,
699
852
  setInitial,
700
853
  hasDirty,
854
+ submitWith: submit,
855
+ /** @deprecated Use `submitWith` instead */
701
856
  submitWithOptions: submit,
702
857
  submit: () => submit(),
703
858
  hasErrors: vue.computed(() => Object.values(errors.value ?? {}).length > 0),
@@ -789,10 +944,15 @@ const registerHook = (hook, fn, options) => {
789
944
 
790
945
  function useDialog() {
791
946
  return {
947
+ /** Closes the dialog. */
792
948
  close: () => hybridly.router.dialog.close(),
949
+ /** Closes the dialog without a server round-trip. */
793
950
  closeLocally: () => hybridly.router.dialog.close({ local: true }),
951
+ /** Unmounts the dialog. Should be called after its closing animations. */
794
952
  unmount: () => dialogStore.removeComponent(),
953
+ /** Whether the dialog is shown. */
795
954
  show: vue.computed(() => dialogStore.state.show.value),
955
+ /** Properties of the dialog. */
796
956
  properties: vue.computed(() => state.context.value?.dialog?.properties)
797
957
  };
798
958
  }
@@ -913,20 +1073,65 @@ function useRefinements(properties, refinementsKeys, defaultOptions = {}) {
913
1073
  return _ref;
914
1074
  }
915
1075
  return {
1076
+ /**
1077
+ * Binds a named filter to a ref, applying filters when it changes and updating the ref accordingly.
1078
+ */
916
1079
  bindFilter,
1080
+ /**
1081
+ * Available filters.
1082
+ */
917
1083
  filters: toReactive(refinements.value.filters),
1084
+ /**
1085
+ * Available sorts.
1086
+ */
918
1087
  sorts: toReactive(refinements.value.sorts),
1088
+ /**
1089
+ * Gets a filter by name.
1090
+ */
919
1091
  getFilter,
1092
+ /**
1093
+ * Gets a sort by name.
1094
+ */
920
1095
  getSort,
1096
+ /**
1097
+ * Resets all filters and sorts.
1098
+ */
921
1099
  reset,
1100
+ /**
1101
+ * Toggles the specified sort.
1102
+ */
922
1103
  toggleSort,
1104
+ /**
1105
+ * Whether a sort is active.
1106
+ */
923
1107
  isSorting,
1108
+ /**
1109
+ * Whether a filter is active.
1110
+ */
924
1111
  isFiltering,
1112
+ /**
1113
+ * The current sorts.
1114
+ */
925
1115
  currentSorts,
1116
+ /**
1117
+ * The current filters.
1118
+ */
926
1119
  currentFilters,
1120
+ /**
1121
+ * Clears the given filter.
1122
+ */
927
1123
  clearFilter,
1124
+ /**
1125
+ * Resets all sorts.
1126
+ */
928
1127
  clearSorts,
1128
+ /**
1129
+ * Resets all filters.
1130
+ */
929
1131
  clearFilters,
1132
+ /**
1133
+ * Applies the given filter.
1134
+ */
930
1135
  applyFilter
931
1136
  };
932
1137
  }