@inertiajs/vue3 2.1.11 → 2.2.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.esm.js CHANGED
@@ -361,6 +361,7 @@ function usePage() {
361
361
  clearHistory: computed(() => page.value?.clearHistory),
362
362
  deferredProps: computed(() => page.value?.deferredProps),
363
363
  mergeProps: computed(() => page.value?.mergeProps),
364
+ prependProps: computed(() => page.value?.prependProps),
364
365
  deepMergeProps: computed(() => page.value?.deepMergeProps),
365
366
  matchPropsOn: computed(() => page.value?.matchPropsOn),
366
367
  rememberedState: computed(() => page.value?.rememberedState),
@@ -788,6 +789,222 @@ var Head = defineComponent4({
788
789
  });
789
790
  var head_default = Head;
790
791
 
792
+ // src/infiniteScroll.ts
793
+ import {
794
+ getScrollableParent,
795
+ useInfiniteScroll
796
+ } from "@inertiajs/core";
797
+ import { computed as computed3, defineComponent as defineComponent5, Fragment, h as h4, onMounted as onMounted2, onUnmounted, ref as ref3, watch as watch2 } from "vue";
798
+ var resolveHTMLElement = (value, fallback) => {
799
+ if (!value) {
800
+ return fallback;
801
+ }
802
+ if (typeof value === "string") {
803
+ return document.querySelector(value);
804
+ }
805
+ if (typeof value === "function") {
806
+ return value() || null;
807
+ }
808
+ return fallback;
809
+ };
810
+ var InfiniteScroll = defineComponent5({
811
+ name: "InfiniteScroll",
812
+ props: {
813
+ data: {
814
+ type: String
815
+ },
816
+ buffer: {
817
+ type: Number,
818
+ default: 0
819
+ },
820
+ onlyNext: {
821
+ type: Boolean,
822
+ default: false
823
+ },
824
+ onlyPrevious: {
825
+ type: Boolean,
826
+ default: false
827
+ },
828
+ as: {
829
+ type: String,
830
+ default: "div"
831
+ },
832
+ manual: {
833
+ type: Boolean,
834
+ default: false
835
+ },
836
+ manualAfter: {
837
+ type: Number,
838
+ default: 0
839
+ },
840
+ preserveUrl: {
841
+ type: Boolean,
842
+ default: false
843
+ },
844
+ reverse: {
845
+ type: Boolean,
846
+ default: false
847
+ },
848
+ autoScroll: {
849
+ type: Boolean,
850
+ default: void 0
851
+ },
852
+ itemsElement: {
853
+ type: [String, Function, Object],
854
+ default: null
855
+ },
856
+ startElement: {
857
+ type: [String, Function, Object],
858
+ default: null
859
+ },
860
+ endElement: {
861
+ type: [String, Function, Object],
862
+ default: null
863
+ }
864
+ },
865
+ inheritAttrs: false,
866
+ setup(props, { slots, attrs, expose }) {
867
+ const itemsElementRef = ref3(null);
868
+ const startElementRef = ref3(null);
869
+ const endElementRef = ref3(null);
870
+ const itemsElement = computed3(
871
+ () => resolveHTMLElement(props.itemsElement, itemsElementRef.value)
872
+ );
873
+ const scrollableParent = computed3(() => getScrollableParent(itemsElement.value));
874
+ const startElement = computed3(
875
+ () => resolveHTMLElement(props.startElement, startElementRef.value)
876
+ );
877
+ const endElement = computed3(() => resolveHTMLElement(props.endElement, endElementRef.value));
878
+ const loadingPrevious = ref3(false);
879
+ const loadingNext = ref3(false);
880
+ const requestCount = ref3(0);
881
+ const autoLoad = computed3(() => !manualMode.value);
882
+ const manualMode = computed3(
883
+ () => props.manual || props.manualAfter > 0 && requestCount.value >= props.manualAfter
884
+ );
885
+ const { dataManager, elementManager } = useInfiniteScroll({
886
+ // Data
887
+ getPropName: () => props.data,
888
+ inReverseMode: () => props.reverse,
889
+ shouldFetchNext: () => !props.onlyPrevious,
890
+ shouldFetchPrevious: () => !props.onlyNext,
891
+ shouldPreserveUrl: () => props.preserveUrl,
892
+ // Elements
893
+ getTriggerMargin: () => props.buffer,
894
+ getStartElement: () => startElement.value,
895
+ getEndElement: () => endElement.value,
896
+ getItemsElement: () => itemsElement.value,
897
+ getScrollableParent: () => scrollableParent.value,
898
+ // Request callbacks
899
+ onBeforePreviousRequest: () => loadingPrevious.value = true,
900
+ onBeforeNextRequest: () => loadingNext.value = true,
901
+ onCompletePreviousRequest: () => {
902
+ requestCount.value += 1;
903
+ loadingPrevious.value = false;
904
+ },
905
+ onCompleteNextRequest: () => {
906
+ requestCount.value += 1;
907
+ loadingNext.value = false;
908
+ }
909
+ });
910
+ const scrollToBottom = () => {
911
+ if (scrollableParent.value) {
912
+ scrollableParent.value.scrollTo({
913
+ top: scrollableParent.value.scrollHeight,
914
+ behavior: "instant"
915
+ });
916
+ } else {
917
+ window.scrollTo({
918
+ top: document.body.scrollHeight,
919
+ behavior: "instant"
920
+ });
921
+ }
922
+ };
923
+ onMounted2(() => {
924
+ elementManager.setupObservers();
925
+ elementManager.processServerLoadedElements(dataManager.getLastLoadedPage());
926
+ const shouldAutoScroll = props.autoScroll !== void 0 ? props.autoScroll : props.reverse;
927
+ if (shouldAutoScroll) {
928
+ scrollToBottom();
929
+ }
930
+ if (autoLoad.value) {
931
+ elementManager.enableTriggers();
932
+ }
933
+ });
934
+ onUnmounted(elementManager.flushAll);
935
+ watch2(
936
+ () => [autoLoad.value, props.onlyNext, props.onlyPrevious],
937
+ ([enabled]) => {
938
+ enabled ? elementManager.enableTriggers() : elementManager.disableTriggers();
939
+ }
940
+ );
941
+ expose({
942
+ fetchNext: dataManager.fetchNext,
943
+ fetchPrevious: dataManager.fetchPrevious,
944
+ hasPrevious: dataManager.hasPrevious,
945
+ hasNext: dataManager.hasNext
946
+ });
947
+ return () => {
948
+ const renderElements = [];
949
+ const sharedExposed = {
950
+ loadingPrevious: loadingPrevious.value,
951
+ loadingNext: loadingNext.value,
952
+ hasPrevious: dataManager.hasPrevious(),
953
+ hasNext: dataManager.hasNext()
954
+ };
955
+ if (!props.startElement) {
956
+ const headerAutoMode = autoLoad.value && !props.onlyNext;
957
+ const exposedPrevious = {
958
+ loading: loadingPrevious.value,
959
+ fetch: dataManager.fetchPrevious,
960
+ autoMode: headerAutoMode,
961
+ manualMode: !headerAutoMode,
962
+ hasMore: dataManager.hasPrevious(),
963
+ ...sharedExposed
964
+ };
965
+ renderElements.push(
966
+ h4(
967
+ "div",
968
+ { ref: startElementRef },
969
+ slots.previous ? slots.previous(exposedPrevious) : loadingPrevious.value ? slots.loading?.(exposedPrevious) : null
970
+ )
971
+ );
972
+ }
973
+ renderElements.push(
974
+ h4(
975
+ props.as,
976
+ { ...attrs, ref: itemsElementRef },
977
+ slots.default?.({
978
+ loading: loadingPrevious.value || loadingNext.value,
979
+ loadingPrevious: loadingPrevious.value,
980
+ loadingNext: loadingNext.value
981
+ })
982
+ )
983
+ );
984
+ if (!props.endElement) {
985
+ const footerAutoMode = autoLoad.value && !props.onlyPrevious;
986
+ const exposedNext = {
987
+ loading: loadingNext.value,
988
+ fetch: dataManager.fetchNext,
989
+ autoMode: footerAutoMode,
990
+ manualMode: !footerAutoMode,
991
+ hasMore: dataManager.hasNext(),
992
+ ...sharedExposed
993
+ };
994
+ renderElements.push(
995
+ h4(
996
+ "div",
997
+ { ref: endElementRef },
998
+ slots.next ? slots.next(exposedNext) : loadingNext.value ? slots.loading?.(exposedNext) : null
999
+ )
1000
+ );
1001
+ }
1002
+ return h4(Fragment, {}, props.reverse ? [...renderElements].reverse() : renderElements);
1003
+ };
1004
+ }
1005
+ });
1006
+ var infiniteScroll_default = InfiniteScroll;
1007
+
791
1008
  // src/link.ts
792
1009
  import {
793
1010
  isUrlMethodPair as isUrlMethodPair2,
@@ -796,10 +1013,10 @@ import {
796
1013
  shouldIntercept,
797
1014
  shouldNavigate
798
1015
  } from "@inertiajs/core";
799
- import { computed as computed3, defineComponent as defineComponent5, h as h4, onMounted as onMounted2, onUnmounted, ref as ref3 } from "vue";
1016
+ import { computed as computed4, defineComponent as defineComponent6, h as h5, onMounted as onMounted3, onUnmounted as onUnmounted2, ref as ref4 } from "vue";
800
1017
  var noop2 = () => {
801
1018
  };
802
- var Link = defineComponent5({
1019
+ var Link = defineComponent6({
803
1020
  name: "Link",
804
1021
  props: {
805
1022
  as: {
@@ -904,9 +1121,9 @@ var Link = defineComponent5({
904
1121
  }
905
1122
  },
906
1123
  setup(props, { slots, attrs }) {
907
- const inFlightCount = ref3(0);
908
- const hoverTimeout = ref3(null);
909
- const prefetchModes = computed3(() => {
1124
+ const inFlightCount = ref4(0);
1125
+ const hoverTimeout = ref4(null);
1126
+ const prefetchModes = computed4(() => {
910
1127
  if (props.prefetch === true) {
911
1128
  return ["hover"];
912
1129
  }
@@ -918,7 +1135,7 @@ var Link = defineComponent5({
918
1135
  }
919
1136
  return [props.prefetch];
920
1137
  });
921
- const cacheForValue = computed3(() => {
1138
+ const cacheForValue = computed4(() => {
922
1139
  if (props.cacheFor !== 0) {
923
1140
  return props.cacheFor;
924
1141
  }
@@ -927,24 +1144,24 @@ var Link = defineComponent5({
927
1144
  }
928
1145
  return 3e4;
929
1146
  });
930
- onMounted2(() => {
1147
+ onMounted3(() => {
931
1148
  if (prefetchModes.value.includes("mount")) {
932
1149
  prefetch();
933
1150
  }
934
1151
  });
935
- onUnmounted(() => {
1152
+ onUnmounted2(() => {
936
1153
  clearTimeout(hoverTimeout.value);
937
1154
  });
938
- const method = computed3(
1155
+ const method = computed4(
939
1156
  () => isUrlMethodPair2(props.href) ? props.href.method : props.method.toLowerCase()
940
1157
  );
941
- const as = computed3(() => {
1158
+ const as = computed4(() => {
942
1159
  if (typeof props.as !== "string" || props.as.toLowerCase() !== "a") {
943
1160
  return props.as;
944
1161
  }
945
1162
  return method.value !== "get" ? "button" : props.as.toLowerCase();
946
1163
  });
947
- const mergeDataArray = computed3(
1164
+ const mergeDataArray = computed4(
948
1165
  () => mergeDataIntoQueryString2(
949
1166
  method.value,
950
1167
  isUrlMethodPair2(props.href) ? props.href.url : props.href,
@@ -952,9 +1169,9 @@ var Link = defineComponent5({
952
1169
  props.queryStringArrayFormat
953
1170
  )
954
1171
  );
955
- const href = computed3(() => mergeDataArray.value[0]);
956
- const data = computed3(() => mergeDataArray.value[1]);
957
- const elProps = computed3(() => {
1172
+ const href = computed4(() => mergeDataArray.value[0]);
1173
+ const data = computed4(() => mergeDataArray.value[1]);
1174
+ const elProps = computed4(() => {
958
1175
  if (as.value === "button") {
959
1176
  return { type: "button" };
960
1177
  }
@@ -963,7 +1180,7 @@ var Link = defineComponent5({
963
1180
  }
964
1181
  return {};
965
1182
  });
966
- const baseParams = computed3(() => ({
1183
+ const baseParams = computed4(() => ({
967
1184
  data: data.value,
968
1185
  method: method.value,
969
1186
  replace: props.replace,
@@ -974,7 +1191,7 @@ var Link = defineComponent5({
974
1191
  headers: props.headers,
975
1192
  async: props.async
976
1193
  }));
977
- const visitParams = computed3(() => ({
1194
+ const visitParams = computed4(() => ({
978
1195
  ...baseParams.value,
979
1196
  onCancelToken: props.onCancelToken,
980
1197
  onBefore: props.onBefore,
@@ -1054,7 +1271,7 @@ var Link = defineComponent5({
1054
1271
  }
1055
1272
  };
1056
1273
  return () => {
1057
- return h4(
1274
+ return h5(
1058
1275
  as.value,
1059
1276
  {
1060
1277
  ...attrs,
@@ -1079,7 +1296,7 @@ var link_default = Link;
1079
1296
 
1080
1297
  // src/usePoll.ts
1081
1298
  import { router as router6 } from "@inertiajs/core";
1082
- import { onMounted as onMounted3, onUnmounted as onUnmounted2 } from "vue";
1299
+ import { onMounted as onMounted4, onUnmounted as onUnmounted3 } from "vue";
1083
1300
  function usePoll(interval, requestOptions = {}, options = {
1084
1301
  keepAlive: false,
1085
1302
  autoStart: true
@@ -1088,12 +1305,12 @@ function usePoll(interval, requestOptions = {}, options = {
1088
1305
  ...options,
1089
1306
  autoStart: false
1090
1307
  });
1091
- onMounted3(() => {
1308
+ onMounted4(() => {
1092
1309
  if (options.autoStart ?? true) {
1093
1310
  start();
1094
1311
  }
1095
1312
  });
1096
- onUnmounted2(() => {
1313
+ onUnmounted3(() => {
1097
1314
  stop();
1098
1315
  });
1099
1316
  return {
@@ -1104,11 +1321,11 @@ function usePoll(interval, requestOptions = {}, options = {
1104
1321
 
1105
1322
  // src/usePrefetch.ts
1106
1323
  import { router as router7 } from "@inertiajs/core";
1107
- import { onMounted as onMounted4, onUnmounted as onUnmounted3, ref as ref4 } from "vue";
1324
+ import { onMounted as onMounted5, onUnmounted as onUnmounted4, ref as ref5 } from "vue";
1108
1325
  function usePrefetch(options = {}) {
1109
- const isPrefetching = ref4(false);
1110
- const lastUpdatedAt = ref4(null);
1111
- const isPrefetched = ref4(false);
1326
+ const isPrefetching = ref5(false);
1327
+ const lastUpdatedAt = ref5(null);
1328
+ const isPrefetched = ref5(false);
1112
1329
  const cached = typeof window === "undefined" ? null : router7.getCached(window.location.pathname, options);
1113
1330
  const inFlight = typeof window === "undefined" ? null : router7.getPrefetching(window.location.pathname, options);
1114
1331
  lastUpdatedAt.value = cached?.staleTimestamp || null;
@@ -1116,7 +1333,7 @@ function usePrefetch(options = {}) {
1116
1333
  isPrefetched.value = cached !== null;
1117
1334
  let onPrefetchedListener;
1118
1335
  let onPrefetchingListener;
1119
- onMounted4(() => {
1336
+ onMounted5(() => {
1120
1337
  onPrefetchingListener = router7.on("prefetching", (e) => {
1121
1338
  if (e.detail.visit.url.pathname === window.location.pathname) {
1122
1339
  isPrefetching.value = true;
@@ -1129,7 +1346,7 @@ function usePrefetch(options = {}) {
1129
1346
  }
1130
1347
  });
1131
1348
  });
1132
- onUnmounted3(() => {
1349
+ onUnmounted4(() => {
1133
1350
  onPrefetchedListener();
1134
1351
  onPrefetchingListener();
1135
1352
  });
@@ -1144,16 +1361,16 @@ function usePrefetch(options = {}) {
1144
1361
  // src/useRemember.ts
1145
1362
  import { router as router8 } from "@inertiajs/core";
1146
1363
  import { cloneDeep as cloneDeep3 } from "lodash-es";
1147
- import { isReactive, reactive as reactive3, ref as ref5, watch as watch2 } from "vue";
1364
+ import { isReactive, reactive as reactive3, ref as ref6, watch as watch3 } from "vue";
1148
1365
  function useRemember(data, key2) {
1149
1366
  if (typeof data === "object" && data !== null && data.__rememberable === false) {
1150
1367
  return data;
1151
1368
  }
1152
1369
  const restored = router8.restore(key2);
1153
- const type = isReactive(data) ? reactive3 : ref5;
1370
+ const type = isReactive(data) ? reactive3 : ref6;
1154
1371
  const hasCallbacks = typeof data.__remember === "function" && typeof data.__restore === "function";
1155
1372
  const remembered = type(restored === void 0 ? data : hasCallbacks ? data.__restore(restored) : restored);
1156
- watch2(
1373
+ watch3(
1157
1374
  remembered,
1158
1375
  (newValue) => {
1159
1376
  router8.remember(cloneDeep3(hasCallbacks ? data.__remember() : newValue), key2);
@@ -1165,8 +1382,8 @@ function useRemember(data, key2) {
1165
1382
 
1166
1383
  // src/whenVisible.ts
1167
1384
  import { router as router9 } from "@inertiajs/core";
1168
- import { defineComponent as defineComponent6, h as h5 } from "vue";
1169
- var whenVisible_default = defineComponent6({
1385
+ import { defineComponent as defineComponent7, h as h6 } from "vue";
1386
+ var whenVisible_default = defineComponent7({
1170
1387
  name: "WhenVisible",
1171
1388
  props: {
1172
1389
  data: {
@@ -1247,7 +1464,7 @@ var whenVisible_default = defineComponent6({
1247
1464
  render() {
1248
1465
  const els = [];
1249
1466
  if (this.$props.always || !this.loaded) {
1250
- els.push(h5(this.$props.as));
1467
+ els.push(h6(this.$props.as));
1251
1468
  }
1252
1469
  if (!this.loaded) {
1253
1470
  els.push(this.$slots.fallback ? this.$slots.fallback() : null);
@@ -1261,6 +1478,7 @@ export {
1261
1478
  deferred_default as Deferred,
1262
1479
  form_default as Form,
1263
1480
  head_default as Head,
1481
+ infiniteScroll_default as InfiniteScroll,
1264
1482
  link_default as Link,
1265
1483
  whenVisible_default as WhenVisible,
1266
1484
  createInertiaApp,