@inertiajs/vue3 3.0.0-beta.2 → 3.0.0-beta.3

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.js CHANGED
@@ -676,7 +676,8 @@ async function createInertiaApp({
676
676
  render,
677
677
  defaults = {},
678
678
  http: http3,
679
- layout: layout2
679
+ layout: layout2,
680
+ withApp
680
681
  } = {}) {
681
682
  config.replace(defaults);
682
683
  if (http3) {
@@ -707,6 +708,9 @@ async function createInertiaApp({
707
708
  } else {
708
709
  vueApp2 = createSSRApp({ render: () => h2(app_default, props) });
709
710
  vueApp2.use(plugin);
711
+ if (withApp) {
712
+ withApp(vueApp2, { ssr: true });
713
+ }
710
714
  }
711
715
  const html = await renderToString(vueApp2);
712
716
  const body = buildSSRBody(id, page3, html);
@@ -748,10 +752,16 @@ async function createInertiaApp({
748
752
  if (el.hasAttribute("data-server-rendered")) {
749
753
  const app = createSSRApp({ render: () => h2(app_default, props) });
750
754
  app.use(plugin);
755
+ if (withApp) {
756
+ withApp(app, { ssr: false });
757
+ }
751
758
  app.mount(el);
752
759
  } else {
753
760
  const app = createApp({ render: () => h2(app_default, props) });
754
761
  app.use(plugin);
762
+ if (withApp) {
763
+ withApp(app, { ssr: false });
764
+ }
755
765
  app.mount(el);
756
766
  }
757
767
  });
@@ -790,6 +800,7 @@ var deferred_default = defineComponent3({
790
800
  setup(props, { slots }) {
791
801
  const reloading = ref3(false);
792
802
  const activeReloads = /* @__PURE__ */ new Set();
803
+ const page2 = usePage();
793
804
  let removeStartListener = null;
794
805
  let removeFinishListener = null;
795
806
  onMounted(() => {
@@ -814,14 +825,13 @@ var deferred_default = defineComponent3({
814
825
  removeFinishListener?.();
815
826
  activeReloads.clear();
816
827
  });
817
- return { reloading, slots };
818
- },
819
- render() {
820
- const keys = Array.isArray(this.$props.data) ? this.$props.data : [this.$props.data];
821
- if (!this.$slots.fallback) {
822
- throw new Error("`<Deferred>` requires a `<template #fallback>` slot");
823
- }
824
- return keys.every((key2) => get2(this.$page.props, key2) !== void 0) ? this.$slots.default?.({ reloading: this.reloading }) : this.$slots.fallback({});
828
+ return () => {
829
+ const keys = Array.isArray(props.data) ? props.data : [props.data];
830
+ if (!slots.fallback) {
831
+ throw new Error("`<Deferred>` requires a `<template #fallback>` slot");
832
+ }
833
+ return keys.every((key2) => get2(page2.props, key2) !== void 0) ? slots.default?.({ reloading: reloading.value }) : slots.fallback({});
834
+ };
825
835
  }
826
836
  });
827
837
 
@@ -1163,7 +1173,111 @@ var form_default = Form;
1163
1173
 
1164
1174
  // src/head.ts
1165
1175
  import { escape } from "lodash-es";
1166
- import { defineComponent as defineComponent5 } from "vue";
1176
+ import { defineComponent as defineComponent5, onBeforeUnmount as onBeforeUnmount2 } from "vue";
1177
+ function isUnaryTag(node) {
1178
+ return typeof node.type === "string" && [
1179
+ "area",
1180
+ "base",
1181
+ "br",
1182
+ "col",
1183
+ "embed",
1184
+ "hr",
1185
+ "img",
1186
+ "input",
1187
+ "keygen",
1188
+ "link",
1189
+ "meta",
1190
+ "param",
1191
+ "source",
1192
+ "track",
1193
+ "wbr"
1194
+ ].indexOf(node.type) > -1;
1195
+ }
1196
+ function renderTagStart(node) {
1197
+ node.props = node.props || {};
1198
+ node.props["data-inertia"] = node.props["head-key"] !== void 0 ? node.props["head-key"] : "";
1199
+ const attrs = Object.keys(node.props).reduce((carry, name) => {
1200
+ const value = String(node.props[name]);
1201
+ if (["key", "head-key"].includes(name)) {
1202
+ return carry;
1203
+ } else if (value === "") {
1204
+ return carry + ` ${name}`;
1205
+ } else {
1206
+ return carry + ` ${name}="${escape(value)}"`;
1207
+ }
1208
+ }, "");
1209
+ return `<${String(node.type)}${attrs}>`;
1210
+ }
1211
+ function renderTagChildren(node) {
1212
+ const { children } = node;
1213
+ if (typeof children === "string") {
1214
+ return children;
1215
+ }
1216
+ if (Array.isArray(children)) {
1217
+ return children.reduce((html, child) => {
1218
+ return html + renderTag(child);
1219
+ }, "");
1220
+ }
1221
+ return "";
1222
+ }
1223
+ function isFunctionNode(node) {
1224
+ return typeof node.type === "function";
1225
+ }
1226
+ function isComponentNode(node) {
1227
+ return typeof node.type === "object";
1228
+ }
1229
+ function isCommentNode(node) {
1230
+ return /(comment|cmt)/i.test(node.type.toString());
1231
+ }
1232
+ function isFragmentNode(node) {
1233
+ return /(fragment|fgt|symbol\(\))/i.test(node.type.toString());
1234
+ }
1235
+ function isTextNode(node) {
1236
+ return /(text|txt)/i.test(node.type.toString());
1237
+ }
1238
+ function renderTag(node) {
1239
+ if (isTextNode(node)) {
1240
+ return String(node.children);
1241
+ } else if (isFragmentNode(node)) {
1242
+ return "";
1243
+ } else if (isCommentNode(node)) {
1244
+ return "";
1245
+ }
1246
+ let html = renderTagStart(node);
1247
+ if (node.children) {
1248
+ html += renderTagChildren(node);
1249
+ }
1250
+ if (!isUnaryTag(node)) {
1251
+ html += `</${String(node.type)}>`;
1252
+ }
1253
+ return html;
1254
+ }
1255
+ function addTitleElement(elements, title) {
1256
+ if (title && !elements.find((tag) => tag.startsWith("<title"))) {
1257
+ elements.push(`<title data-inertia="">${title}</title>`);
1258
+ }
1259
+ return elements;
1260
+ }
1261
+ function renderNodes(nodes, title) {
1262
+ const elements = nodes.flatMap((node) => resolveNode(node)).map((node) => renderTag(node)).filter((node) => node);
1263
+ return addTitleElement(elements, title);
1264
+ }
1265
+ function resolveNode(node) {
1266
+ if (isFunctionNode(node)) {
1267
+ return resolveNode(node.type());
1268
+ } else if (isComponentNode(node)) {
1269
+ console.warn(`Using components in the <Head> component is not supported.`);
1270
+ return [];
1271
+ } else if (isTextNode(node) && node.children) {
1272
+ return node;
1273
+ } else if (isFragmentNode(node) && node.children) {
1274
+ return node.children.flatMap((child) => resolveNode(child));
1275
+ } else if (isCommentNode(node)) {
1276
+ return [];
1277
+ } else {
1278
+ return node;
1279
+ }
1280
+ }
1167
1281
  var Head = defineComponent5({
1168
1282
  props: {
1169
1283
  title: {
@@ -1171,122 +1285,14 @@ var Head = defineComponent5({
1171
1285
  required: false
1172
1286
  }
1173
1287
  },
1174
- data() {
1175
- return {
1176
- provider: this.$headManager.createProvider()
1288
+ setup(props, { slots }) {
1289
+ const provider = headManager.createProvider();
1290
+ onBeforeUnmount2(() => {
1291
+ provider.disconnect();
1292
+ });
1293
+ return () => {
1294
+ provider.update(renderNodes(slots.default ? slots.default() : [], props.title));
1177
1295
  };
1178
- },
1179
- beforeUnmount() {
1180
- this.provider.disconnect();
1181
- },
1182
- methods: {
1183
- isUnaryTag(node) {
1184
- return typeof node.type === "string" && [
1185
- "area",
1186
- "base",
1187
- "br",
1188
- "col",
1189
- "embed",
1190
- "hr",
1191
- "img",
1192
- "input",
1193
- "keygen",
1194
- "link",
1195
- "meta",
1196
- "param",
1197
- "source",
1198
- "track",
1199
- "wbr"
1200
- ].indexOf(node.type) > -1;
1201
- },
1202
- renderTagStart(node) {
1203
- node.props = node.props || {};
1204
- node.props["data-inertia"] = node.props["head-key"] !== void 0 ? node.props["head-key"] : "";
1205
- const attrs = Object.keys(node.props).reduce((carry, name) => {
1206
- const value = String(node.props[name]);
1207
- if (["key", "head-key"].includes(name)) {
1208
- return carry;
1209
- } else if (value === "") {
1210
- return carry + ` ${name}`;
1211
- } else {
1212
- return carry + ` ${name}="${escape(value)}"`;
1213
- }
1214
- }, "");
1215
- return `<${String(node.type)}${attrs}>`;
1216
- },
1217
- renderTagChildren(node) {
1218
- const { children } = node;
1219
- if (typeof children === "string") {
1220
- return children;
1221
- }
1222
- if (Array.isArray(children)) {
1223
- return children.reduce((html, child) => {
1224
- return html + this.renderTag(child);
1225
- }, "");
1226
- }
1227
- return "";
1228
- },
1229
- isFunctionNode(node) {
1230
- return typeof node.type === "function";
1231
- },
1232
- isComponentNode(node) {
1233
- return typeof node.type === "object";
1234
- },
1235
- isCommentNode(node) {
1236
- return /(comment|cmt)/i.test(node.type.toString());
1237
- },
1238
- isFragmentNode(node) {
1239
- return /(fragment|fgt|symbol\(\))/i.test(node.type.toString());
1240
- },
1241
- isTextNode(node) {
1242
- return /(text|txt)/i.test(node.type.toString());
1243
- },
1244
- renderTag(node) {
1245
- if (this.isTextNode(node)) {
1246
- return String(node.children);
1247
- } else if (this.isFragmentNode(node)) {
1248
- return "";
1249
- } else if (this.isCommentNode(node)) {
1250
- return "";
1251
- }
1252
- let html = this.renderTagStart(node);
1253
- if (node.children) {
1254
- html += this.renderTagChildren(node);
1255
- }
1256
- if (!this.isUnaryTag(node)) {
1257
- html += `</${String(node.type)}>`;
1258
- }
1259
- return html;
1260
- },
1261
- addTitleElement(elements) {
1262
- if (this.title && !elements.find((tag) => tag.startsWith("<title"))) {
1263
- elements.push(`<title data-inertia="">${this.title}</title>`);
1264
- }
1265
- return elements;
1266
- },
1267
- renderNodes(nodes) {
1268
- const elements = nodes.flatMap((node) => this.resolveNode(node)).map((node) => this.renderTag(node)).filter((node) => node);
1269
- return this.addTitleElement(elements);
1270
- },
1271
- resolveNode(node) {
1272
- if (this.isFunctionNode(node)) {
1273
- return this.resolveNode(node.type());
1274
- } else if (this.isComponentNode(node)) {
1275
- console.warn(`Using components in the <Head> component is not supported.`);
1276
- return [];
1277
- } else if (this.isTextNode(node) && node.children) {
1278
- return node;
1279
- } else if (this.isFragmentNode(node) && node.children) {
1280
- return node.children.flatMap((child) => this.resolveNode(child));
1281
- } else if (this.isCommentNode(node)) {
1282
- return [];
1283
- } else {
1284
- return node;
1285
- }
1286
- }
1287
- },
1288
- render() {
1289
- this.provider.update(this.renderNodes(this.$slots.default ? this.$slots.default() : []));
1290
1296
  }
1291
1297
  });
1292
1298
  var head_default = Head;
@@ -2119,7 +2125,7 @@ function useRemember(data, key2) {
2119
2125
  // src/whenVisible.ts
2120
2126
  import { router as router11 } from "@inertiajs/core";
2121
2127
  import { get as get3 } from "lodash-es";
2122
- import { defineComponent as defineComponent8, h as h6 } from "vue";
2128
+ import { computed as computed6, defineComponent as defineComponent8, h as h6, nextTick, onUnmounted as onUnmounted6, ref as ref9, watch as watch5 } from "vue";
2123
2129
  var whenVisible_default = defineComponent8({
2124
2130
  name: "WhenVisible",
2125
2131
  slots: Object,
@@ -2143,95 +2149,90 @@ var whenVisible_default = defineComponent8({
2143
2149
  default: false
2144
2150
  }
2145
2151
  },
2146
- data() {
2147
- return {
2148
- loaded: false,
2149
- fetching: false,
2150
- observer: null
2151
- };
2152
- },
2153
- unmounted() {
2154
- this.observer?.disconnect();
2155
- },
2156
- computed: {
2157
- keys() {
2158
- return this.data ? Array.isArray(this.data) ? this.data : [this.data] : [];
2159
- }
2160
- },
2161
- created() {
2152
+ setup(props, { slots }) {
2153
+ const loaded = ref9(false);
2154
+ const fetching = ref9(false);
2155
+ const observer = ref9(null);
2156
+ const elementRef = ref9(null);
2162
2157
  const page2 = usePage();
2163
- this.$watch(
2164
- () => this.keys.map((key2) => get3(page2.props, key2)),
2165
- () => {
2166
- const exists = this.keys.length > 0 && this.keys.every((key2) => get3(page2.props, key2) !== void 0);
2167
- this.loaded = exists;
2168
- if (exists && !this.always) {
2169
- return;
2170
- }
2171
- if (!this.observer || !exists) {
2172
- this.$nextTick(this.registerObserver);
2173
- }
2174
- },
2175
- { immediate: true }
2176
- );
2177
- },
2178
- methods: {
2179
- registerObserver() {
2180
- this.observer?.disconnect();
2181
- this.observer = new IntersectionObserver(
2158
+ const keys = computed6(() => {
2159
+ return props.data ? Array.isArray(props.data) ? props.data : [props.data] : [];
2160
+ });
2161
+ function getReloadParams() {
2162
+ const reloadParams = { preserveErrors: true, ...props.params };
2163
+ if (props.data) {
2164
+ reloadParams.only = Array.isArray(props.data) ? props.data : [props.data];
2165
+ }
2166
+ return reloadParams;
2167
+ }
2168
+ function registerObserver() {
2169
+ observer.value?.disconnect();
2170
+ observer.value = new IntersectionObserver(
2182
2171
  (entries) => {
2183
2172
  if (!entries[0].isIntersecting) {
2184
2173
  return;
2185
2174
  }
2186
- if (this.fetching) {
2175
+ if (fetching.value) {
2187
2176
  return;
2188
2177
  }
2189
- if (!this.always && this.loaded) {
2178
+ if (!props.always && loaded.value) {
2190
2179
  return;
2191
2180
  }
2192
- this.fetching = true;
2193
- const reloadParams = this.getReloadParams();
2181
+ fetching.value = true;
2182
+ const reloadParams = getReloadParams();
2194
2183
  router11.reload({
2195
2184
  ...reloadParams,
2196
2185
  onStart: (e) => {
2197
- this.fetching = true;
2186
+ fetching.value = true;
2198
2187
  reloadParams.onStart?.(e);
2199
2188
  },
2200
2189
  onFinish: (e) => {
2201
- this.loaded = true;
2202
- this.fetching = false;
2190
+ loaded.value = true;
2191
+ fetching.value = false;
2203
2192
  reloadParams.onFinish?.(e);
2204
- if (!this.always) {
2205
- this.observer?.disconnect();
2193
+ if (!props.always) {
2194
+ observer.value?.disconnect();
2206
2195
  }
2207
2196
  }
2208
2197
  });
2209
2198
  },
2210
2199
  {
2211
- rootMargin: `${this.$props.buffer}px`
2200
+ rootMargin: `${props.buffer}px`
2212
2201
  }
2213
2202
  );
2214
- this.observer.observe(this.$el.nextSibling);
2215
- },
2216
- getReloadParams() {
2217
- const reloadParams = { preserveErrors: true, ...this.$props.params };
2218
- if (this.$props.data) {
2219
- reloadParams.only = Array.isArray(this.$props.data) ? this.$props.data : [this.$props.data];
2203
+ if (elementRef.value) {
2204
+ observer.value.observe(elementRef.value);
2220
2205
  }
2221
- return reloadParams;
2222
- }
2223
- },
2224
- render() {
2225
- const els = [];
2226
- if (this.$props.always || !this.loaded) {
2227
- els.push(h6(this.$props.as));
2228
- }
2229
- if (!this.loaded) {
2230
- els.push(this.$slots.fallback ? this.$slots.fallback({}) : null);
2231
- } else if (this.$slots.default) {
2232
- els.push(this.$slots.default({ fetching: this.fetching }));
2233
2206
  }
2234
- return els;
2207
+ watch5(
2208
+ () => keys.value.map((key2) => get3(page2.props, key2)),
2209
+ () => {
2210
+ const exists = keys.value.length > 0 && keys.value.every((key2) => get3(page2.props, key2) !== void 0);
2211
+ loaded.value = exists;
2212
+ if (exists && !props.always) {
2213
+ return;
2214
+ }
2215
+ if (!observer.value || !exists) {
2216
+ nextTick(registerObserver);
2217
+ }
2218
+ },
2219
+ { immediate: true }
2220
+ );
2221
+ onUnmounted6(() => {
2222
+ observer.value?.disconnect();
2223
+ });
2224
+ return () => {
2225
+ const els = [];
2226
+ if (props.always || !loaded.value) {
2227
+ els.push(h6(props.as, { ref: elementRef }));
2228
+ }
2229
+ if (!loaded.value) {
2230
+ els.push(slots.fallback ? slots.fallback({}) : null);
2231
+ } else if (slots.default) {
2232
+ els.push(slots.default({ fetching: fetching.value }));
2233
+ }
2234
+ return els;
2235
+ };
2235
2236
  }
2236
2237
  });
2237
2238