@hybridly/vue 0.6.1 → 0.7.0

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
@@ -8,7 +8,6 @@ const devtoolsApi = require('@vue/devtools-api');
8
8
  const qs = require('qs');
9
9
  const dotDiver = require('@clickbar/dot-diver');
10
10
  const isEqual = require('lodash.isequal');
11
- const hybridly = require('hybridly');
12
11
 
13
12
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
13
 
@@ -26,18 +25,16 @@ function progress(options) {
26
25
  };
27
26
  let timeout;
28
27
  function startProgress() {
28
+ nprogress__default.done();
29
+ nprogress__default.remove();
29
30
  nprogress__default.start();
30
31
  }
31
32
  function finishProgress() {
32
33
  if (nprogress__default.isStarted()) {
33
34
  nprogress__default.done(true);
35
+ setTimeout(() => nprogress__default.remove(), 1e3);
34
36
  }
35
- }
36
- function cancelProgress() {
37
- if (nprogress__default.isStarted()) {
38
- nprogress__default.done(true);
39
- nprogress__default.remove();
40
- }
37
+ clearTimeout(timeout);
41
38
  }
42
39
  return core.definePlugin({
43
40
  name: "hybridly:progress",
@@ -52,20 +49,14 @@ function progress(options) {
52
49
  return;
53
50
  }
54
51
  clearTimeout(timeout);
55
- timeout = setTimeout(() => {
56
- finishProgress();
57
- startProgress();
58
- }, resolved.delay);
52
+ timeout = setTimeout(() => startProgress(), resolved.delay);
59
53
  },
60
54
  progress: (progress2) => {
61
55
  if (nprogress__default.isStarted() && progress2.percentage) {
62
56
  nprogress__default.set(Math.max(nprogress__default.status, progress2.percentage / 100 * 0.9));
63
57
  }
64
58
  },
65
- success: () => finishProgress(),
66
- error: () => cancelProgress(),
67
- fail: () => cancelProgress(),
68
- after: () => clearTimeout(timeout)
59
+ after: () => finishProgress()
69
60
  });
70
61
  }
71
62
  function injectCSS(color) {
@@ -177,11 +168,9 @@ const dialogStore = {
177
168
  const onMountedCallbacks = [];
178
169
 
179
170
  const state = {
180
- context: vue.ref(),
171
+ context: vue.shallowRef(),
181
172
  view: vue.shallowRef(),
182
173
  properties: vue.ref(),
183
- viewLayout: vue.shallowRef(),
184
- viewLayoutProperties: vue.ref(),
185
174
  viewKey: vue.ref(),
186
175
  setView(view) {
187
176
  utils.debug.adapter("vue:state:view", "Storing view:", view);
@@ -191,18 +180,9 @@ const state = {
191
180
  utils.debug.adapter("vue:state:view", "Storing properties:", properties);
192
181
  state.properties.value = properties;
193
182
  },
194
- setViewLayout(layout) {
195
- utils.debug.adapter("vue:state:view", "Storing layout", layout);
196
- state.viewLayout.value = layout;
197
- },
198
- setViewLayoutProperties(properties) {
199
- utils.debug.adapter("vue:state:view", "Storing layout properties:", properties);
200
- state.viewLayoutProperties.value = properties;
201
- },
202
183
  setContext(context) {
203
184
  utils.debug.adapter("vue:state:context", "Storing context:", context);
204
185
  state.context.value = vue.unref(context);
205
- vue.triggerRef(state.context);
206
186
  },
207
187
  setViewKey(key) {
208
188
  utils.debug.adapter("vue:state:key", "Storing view key:", key);
@@ -222,7 +202,7 @@ const wrapper = vue.defineComponent({
222
202
  const layoutsAndView = state.view.value.layout.concat(view).reverse().reduce((child, layout) => {
223
203
  layout.inheritAttrs = !!layout.inheritAttrs;
224
204
  return vue.h(layout, {
225
- ...state.view.value?.layoutProperties ?? {},
205
+ ...state.view.value?.properties ?? {},
226
206
  ...state.properties.value
227
207
  }, () => child);
228
208
  });
@@ -230,7 +210,7 @@ const wrapper = vue.defineComponent({
230
210
  }
231
211
  return [
232
212
  vue.h(state.view.value?.layout, {
233
- ...state.view.value?.layoutProperties ?? {},
213
+ ...state.view.value?.properties ?? {},
234
214
  ...state.properties.value
235
215
  }, () => view),
236
216
  renderDialog()
@@ -276,13 +256,6 @@ const wrapper = vue.defineComponent({
276
256
  }
277
257
  utils.debug.adapter("vue:render:wrapper", "Rendering wrapper component.", a.map(vue.toRaw));
278
258
  const view = renderView();
279
- if (state.viewLayout.value) {
280
- state.view.value.layout = state.viewLayout.value;
281
- }
282
- if (state.viewLayoutProperties.value) {
283
- state.view.value.layoutProperties = state.viewLayoutProperties.value;
284
- state.viewLayoutProperties.value = void 0;
285
- }
286
259
  if (state.view.value.layout) {
287
260
  return renderLayout(view);
288
261
  }
@@ -488,7 +461,8 @@ async function initializeHybridly(options = {}) {
488
461
  wrapper,
489
462
  render,
490
463
  hybridly: devtools,
491
- props: { context: state.context.value }
464
+ props: { context: state.context.value },
465
+ payload
492
466
  });
493
467
  }
494
468
  const app = vue.createApp({ render });
@@ -729,10 +703,6 @@ function setProperty(path, value) {
729
703
  dotDiver.setByPath(state.context.value.view.properties, path, vue.toValue(value));
730
704
  }
731
705
 
732
- function useContext() {
733
- return vue.computed(() => state.context.value);
734
- }
735
-
736
706
  function safeClone(obj) {
737
707
  return utils.clone(vue.toRaw(obj));
738
708
  }
@@ -859,7 +829,7 @@ function useForm(options) {
859
829
  core.router.abort();
860
830
  }
861
831
  vue.watch([fields, processing, errors], () => {
862
- isDirty.value = !isEqual__default(vue.toRaw(loaded), vue.toRaw(fields));
832
+ isDirty.value = !isEqual__default(vue.toRaw(initial), vue.toRaw(fields));
863
833
  if (shouldRemember) {
864
834
  core.router.history.remember(historyKey, {
865
835
  fields: vue.toRaw(fields),
@@ -903,10 +873,10 @@ function useHistoryState(key, initial) {
903
873
  return value;
904
874
  }
905
875
 
906
- function useBackForward() {
876
+ function useBackForward(options) {
907
877
  const callbacks = [];
908
- core.registerHook("navigated", (options) => {
909
- if (options.type === "back-forward") {
878
+ core.registerHook("navigated", (options2) => {
879
+ if (options2.type === "back-forward") {
910
880
  callbacks.forEach((fn) => fn(state.context.value));
911
881
  callbacks.splice(0, callbacks.length);
912
882
  }
@@ -914,8 +884,11 @@ function useBackForward() {
914
884
  function onBackForward(fn) {
915
885
  callbacks.push(fn);
916
886
  }
917
- function reloadOnBackForward(options) {
918
- onBackForward(() => core.router.reload(options));
887
+ function reloadOnBackForward(options2) {
888
+ onBackForward(() => core.router.reload(options2));
889
+ }
890
+ if (options?.reload) {
891
+ reloadOnBackForward(options.reload === true ? void 0 : options.reload);
919
892
  }
920
893
  return {
921
894
  onBackForward,
@@ -923,16 +896,6 @@ function useBackForward() {
923
896
  };
924
897
  }
925
898
 
926
- function defineLayout(...args) {
927
- const layouts = args[0];
928
- const properties = args[1];
929
- state.setViewLayout(layouts);
930
- state.setViewLayoutProperties(properties);
931
- }
932
- function defineLayoutProperties(properties) {
933
- state.setViewLayoutProperties(properties);
934
- }
935
-
936
899
  const registerHook = (hook, fn, options) => {
937
900
  const unregister = core.registerHook(hook, fn, options);
938
901
  if (vue.getCurrentInstance()) {
@@ -944,9 +907,9 @@ const registerHook = (hook, fn, options) => {
944
907
  function useDialog() {
945
908
  return {
946
909
  /** Closes the dialog. */
947
- close: () => hybridly.router.dialog.close(),
910
+ close: () => core.router.dialog.close(),
948
911
  /** Closes the dialog without a server round-trip. */
949
- closeLocally: () => hybridly.router.dialog.close({ local: true }),
912
+ closeLocally: () => core.router.dialog.close({ local: true }),
950
913
  /** Unmounts the dialog. Should be called after its closing animations. */
951
914
  unmount: () => dialogStore.removeComponent(),
952
915
  /** Whether the dialog is shown. */
@@ -1175,12 +1138,12 @@ function useRefinements(properties, refinementsKeys, defaultOptions = {}) {
1175
1138
  }
1176
1139
 
1177
1140
  function useRoute() {
1178
- const current = vue.ref(hybridly.router.current());
1141
+ const current = vue.ref(core.router.current());
1179
1142
  function matches(name, parameters) {
1180
- return hybridly.router.matches(vue.toValue(name), parameters);
1143
+ return core.router.matches(vue.toValue(name), parameters);
1181
1144
  }
1182
1145
  registerHook("navigated", () => {
1183
- current.value = hybridly.router.current();
1146
+ current.value = core.router.current();
1184
1147
  });
1185
1148
  return {
1186
1149
  current: vue.readonly(current),
@@ -1258,9 +1221,9 @@ function useTable(props, key, defaultOptions = {}) {
1258
1221
  return typeof action === "string" ? action : action.name;
1259
1222
  }
1260
1223
  async function executeInlineAction(action, record) {
1261
- return await hybridly.router.navigate({
1224
+ return await core.router.navigate({
1262
1225
  method: "post",
1263
- url: hybridly.route(table.value.endpoint),
1226
+ url: core.route(table.value.endpoint),
1264
1227
  preserveState: true,
1265
1228
  data: {
1266
1229
  type: "action:inline",
@@ -1272,9 +1235,9 @@ function useTable(props, key, defaultOptions = {}) {
1272
1235
  }
1273
1236
  async function executeBulkAction(action, options) {
1274
1237
  const actionName = getActionName(action);
1275
- return await hybridly.router.navigate({
1238
+ return await core.router.navigate({
1276
1239
  method: "post",
1277
- url: hybridly.route(table.value.endpoint),
1240
+ url: core.route(table.value.endpoint),
1278
1241
  preserveState: true,
1279
1242
  data: {
1280
1243
  type: "action:bulk",
@@ -1388,7 +1351,7 @@ function useQueryParameters() {
1388
1351
  Array.from(unusedKeys).forEach((key) => delete state[key]);
1389
1352
  }
1390
1353
  updateState();
1391
- hybridly.registerHook("after", updateState);
1354
+ core.registerHook("after", updateState);
1392
1355
  return state;
1393
1356
  }
1394
1357
 
@@ -1396,14 +1359,11 @@ exports.can = core.can;
1396
1359
  exports.route = core.route;
1397
1360
  exports.router = core.router;
1398
1361
  exports.RouterLink = RouterLink;
1399
- exports.defineLayout = defineLayout;
1400
- exports.defineLayoutProperties = defineLayoutProperties;
1401
1362
  exports.initializeHybridly = initializeHybridly;
1402
1363
  exports.registerHook = registerHook;
1403
1364
  exports.setProperty = setProperty;
1404
1365
  exports.useBackForward = useBackForward;
1405
1366
  exports.useBulkSelect = useBulkSelect;
1406
- exports.useContext = useContext;
1407
1367
  exports.useDialog = useDialog;
1408
1368
  exports.useForm = useForm;
1409
1369
  exports.useHistoryState = useHistoryState;