@inertiajs/core 3.0.0-beta.2 → 3.0.0-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertiajs/core",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.4",
4
4
  "license": "MIT",
5
5
  "description": "A framework for creating server-driven single page apps.",
6
6
  "contributors": [
@@ -50,9 +50,8 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@jridgewell/trace-mapping": "^0.3.31",
53
- "@types/lodash-es": "^4.17.12",
54
- "laravel-precognition": "2.0.0-beta.3",
55
- "lodash-es": "^4.17.23"
53
+ "es-toolkit": "^1.33.0",
54
+ "laravel-precognition": "2.0.0-beta.5"
56
55
  },
57
56
  "peerDependencies": {
58
57
  "axios": "^1.13.2"
@@ -78,7 +77,7 @@
78
77
  "dev": "pnpx concurrently -c \"#ffcf00,#3178c6\" \"pnpm dev:build\" \"pnpm dev:types\" --names build,types",
79
78
  "dev:build": "./build.js --watch",
80
79
  "dev:types": "tsc --watch --preserveWatchOutput",
81
- "es2020-check": "pnpm build:with-deps && es-check es2020 \"dist/index.js\" --checkFeatures --module --noCache --verbose",
80
+ "es2022-check": "pnpm build:with-deps && es-check es2022 \"dist/index.js\" --checkFeatures --module --noCache --verbose",
82
81
  "test": "vitest run"
83
82
  }
84
83
  }
package/types/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export { default as createHeadManager } from './head';
11
11
  export { http } from './http';
12
12
  export { HttpCancelledError, HttpNetworkError, HttpResponseError } from './httpErrors';
13
13
  export { default as useInfiniteScroll } from './infiniteScroll';
14
- export { createLayoutPropsStore, mergeLayoutProps, normalizeLayouts, type LayoutDefinition, type LayoutPropsStore, } from './layout';
14
+ export { createLayoutPropsStore, normalizeLayouts, type LayoutDefinition, type LayoutPropsStore } from './layout';
15
15
  export { shouldIntercept, shouldNavigate } from './navigationEvents';
16
16
  export { progress, default as setupProgress } from './progress';
17
17
  export { FormComponentResetSymbol, resetFormFields } from './resetFormFields';
package/types/layout.d.ts CHANGED
@@ -1,11 +1,12 @@
1
+ import type { LayoutProps, NamedLayoutProps } from './types';
1
2
  export interface LayoutDefinition<Component> {
2
3
  component: Component;
3
4
  props: Record<string, unknown>;
4
5
  name?: string;
5
6
  }
6
7
  export interface LayoutPropsStore {
7
- set(props: Record<string, unknown>): void;
8
- setFor(name: string, props: Record<string, unknown>): void;
8
+ set(props: Partial<LayoutProps>): void;
9
+ setFor<K extends keyof NamedLayoutProps>(name: K, props: Partial<NamedLayoutProps[K]>): void;
9
10
  get(): {
10
11
  shared: Record<string, unknown>;
11
12
  named: Record<string, Record<string, unknown>>;
@@ -14,22 +15,6 @@ export interface LayoutPropsStore {
14
15
  subscribe(callback: () => void): () => void;
15
16
  }
16
17
  export declare function createLayoutPropsStore(): LayoutPropsStore;
17
- /**
18
- * Merges layout props from three sources with priority: dynamic > static > defaults.
19
- * Only keys present in `defaults` are included in the result.
20
- *
21
- * @example
22
- * ```ts
23
- * mergeLayoutProps(
24
- * { title: 'Default', showSidebar: true }, // defaults declared in useLayoutProps()
25
- * { title: 'My Page', color: 'blue' }, // static props from layout definition
26
- * { showSidebar: false, fontSize: 16 }, // dynamic props from setLayoutProps()
27
- * )
28
- * // => { title: 'My Page', showSidebar: false }
29
- * // 'color' and 'fontSize' are excluded because they're not declared in defaults
30
- * ```
31
- */
32
- export declare function mergeLayoutProps<T extends Record<string, unknown>>(defaults: T, staticProps: Record<string, unknown>, dynamicProps: Record<string, unknown>): T;
33
18
  type ComponentCheck<T> = (value: unknown) => value is T;
34
19
  /**
35
20
  * Normalizes layout definitions into a consistent structure.
package/types/page.d.ts CHANGED
@@ -13,6 +13,12 @@ declare class CurrentPage {
13
13
  protected cleared: boolean;
14
14
  protected pendingDeferredProps: Pick<Page, 'deferredProps' | 'url' | 'component'> | null;
15
15
  protected historyQuotaExceeded: boolean;
16
+ protected optimisticBaseline: Partial<Page['props']>;
17
+ protected pendingOptimistics: {
18
+ id: number;
19
+ callback: (props: Page['props']) => Partial<Page['props']> | void;
20
+ }[];
21
+ protected optimisticCounter: number;
16
22
  init<ComponentType = Component>({ initialPage, swapComponent, resolveComponent, onFlash, }: RouterInitParams<ComponentType>): this;
17
23
  set(page: Page, { replace, preserveScroll, preserveState, viewTransition, }?: {
18
24
  replace?: boolean;
@@ -40,8 +46,15 @@ declare class CurrentPage {
40
46
  viewTransition: Visit['viewTransition'];
41
47
  }): Promise<unknown>;
42
48
  resolve(component: string, page?: Page): Promise<Component>;
43
- recordOptimisticUpdate(keys: string[], updatedAt: number): void;
44
- shouldPreserveOptimistic(key: string, updatedAt: number): boolean;
49
+ nextOptimisticId(): number;
50
+ setBaseline(key: string, value: unknown): void;
51
+ updateBaseline(key: string, value: unknown): void;
52
+ hasBaseline(key: string): boolean;
53
+ registerOptimistic(id: number, callback: (props: Page['props']) => Partial<Page['props']> | void): void;
54
+ unregisterOptimistic(id: number): void;
55
+ replayOptimistics(): Partial<Page['props']>;
56
+ pendingOptimisticCount(): number;
57
+ clearOptimisticState(): void;
45
58
  isTheSame(page: Page): boolean;
46
59
  on(event: PageEvent, callback: VoidFunction): VoidFunction;
47
60
  fireEventsFor(event: PageEvent): void;
package/types/types.d.ts CHANGED
@@ -40,6 +40,8 @@ export type DefaultInertiaConfig = {
40
40
  errorValueType: string;
41
41
  flashDataType: PageFlashData;
42
42
  sharedPageProps: PageProps;
43
+ layoutProps: Record<string, unknown>;
44
+ namedLayoutProps: Record<string, Record<string, unknown>>;
43
45
  };
44
46
  /**
45
47
  * Designed to allow overriding of some core types using TypeScript
@@ -48,6 +50,9 @@ export type DefaultInertiaConfig = {
48
50
  * @see {@link DefaultInertiaConfig} for keys to override
49
51
  * @example
50
52
  * ```ts
53
+ * // global.d.ts
54
+ * import '@inertiajs/core'
55
+ *
51
56
  * declare module '@inertiajs/core' {
52
57
  * export interface InertiaConfig {
53
58
  * errorValueType: string[]
@@ -57,6 +62,14 @@ export type DefaultInertiaConfig = {
57
62
  * sharedPageProps: {
58
63
  * auth: { user: User | null }
59
64
  * }
65
+ * layoutProps: {
66
+ * title: string
67
+ * showSidebar: boolean
68
+ * }
69
+ * namedLayoutProps: {
70
+ * app: { title: string; theme: string }
71
+ * content: { padding: string; maxWidth: string }
72
+ * }
60
73
  * }
61
74
  * }
62
75
  * ```
@@ -67,6 +80,8 @@ export type InertiaConfigFor<Key extends keyof DefaultInertiaConfig> = Key exten
67
80
  export type ErrorValue = InertiaConfigFor<'errorValueType'>;
68
81
  export type FlashData = InertiaConfigFor<'flashDataType'>;
69
82
  export type SharedPageProps = InertiaConfigFor<'sharedPageProps'>;
83
+ export type LayoutProps = InertiaConfigFor<'layoutProps'>;
84
+ export type NamedLayoutProps = InertiaConfigFor<'namedLayoutProps'>;
70
85
  export type Errors = Record<string, ErrorValue>;
71
86
  export type ErrorBag = Record<string, Errors>;
72
87
  export type FormDataConvertibleValue = Blob | FormDataEntryValue | Date | boolean | number | null | undefined;
@@ -159,9 +174,9 @@ export interface ClientSideVisitOptions<TProps = Page['props']> {
159
174
  onError?: (errors: Errors) => void;
160
175
  onFinish?: (visit: ClientSideVisitOptions<TProps>) => void;
161
176
  onFlash?: (flash: FlashData) => void;
162
- onSuccess?: (page: Page) => void;
177
+ onSuccess?: (page: Page<SharedPageProps>) => void;
163
178
  }
164
- export type PageResolver = (name: string, page?: Page) => Component;
179
+ export type PageResolver = (name: string, page?: Page<SharedPageProps>) => Component;
165
180
  export type PageHandler<ComponentType = Component> = ({ component, page, preserveState, }: {
166
181
  component: ComponentType;
167
182
  page: Page;
@@ -177,7 +192,7 @@ export type CancelToken = {
177
192
  cancel: VoidFunction;
178
193
  };
179
194
  export type CancelTokenCallback = (cancelToken: CancelToken) => void;
180
- export type OptimisticCallback<TProps = Page['props']> = (props: TProps) => Partial<TProps> | void;
195
+ export type OptimisticCallback<TProps = Page<SharedPageProps>['props']> = (props: TProps) => Partial<TProps> | void;
181
196
  export type Visit<T extends RequestPayload = RequestPayload> = {
182
197
  method: Method;
183
198
  data: T;
@@ -238,23 +253,23 @@ export type GlobalEventsMap<T extends RequestPayload = RequestPayload> = {
238
253
  result: void;
239
254
  };
240
255
  beforeUpdate: {
241
- parameters: [Page];
256
+ parameters: [Page<SharedPageProps>];
242
257
  details: {
243
- page: Page;
258
+ page: Page<SharedPageProps>;
244
259
  };
245
260
  result: void;
246
261
  };
247
262
  navigate: {
248
- parameters: [Page];
263
+ parameters: [Page<SharedPageProps>];
249
264
  details: {
250
- page: Page;
265
+ page: Page<SharedPageProps>;
251
266
  };
252
267
  result: void;
253
268
  };
254
269
  success: {
255
- parameters: [Page];
270
+ parameters: [Page<SharedPageProps>];
256
271
  details: {
257
- page: Page;
272
+ page: Page<SharedPageProps>;
258
273
  };
259
274
  result: void;
260
275
  };
@@ -492,7 +507,7 @@ export type ProgressSettings = {
492
507
  export type UrlMethodPair = {
493
508
  url: string;
494
509
  method: Method;
495
- component?: string | string[];
510
+ component?: string | Record<string, string>;
496
511
  };
497
512
  export type UseFormTransformCallback<TForm> = (data: TForm) => object;
498
513
  export type UseFormWithPrecognitionArguments = [Method | (() => Method), string | (() => string)] | [UrlMethodPair | (() => UrlMethodPair)];
@@ -503,7 +518,7 @@ export type UseFormSubmitOptions = Omit<VisitOptions, 'data'>;
503
518
  export type UseFormSubmitArguments = [Method, string, UseFormSubmitOptions?] | [UrlMethodPair, UseFormSubmitOptions?] | [UseFormSubmitOptions?];
504
519
  export type UseHttpSubmitArguments<TResponse = unknown, TForm = unknown> = [Method, string, UseHttpSubmitOptions<TResponse, TForm>?] | [UrlMethodPair, UseHttpSubmitOptions<TResponse, TForm>?] | [UseHttpSubmitOptions<TResponse, TForm>?];
505
520
  export type FormComponentOptions = Pick<VisitOptions, 'preserveScroll' | 'preserveState' | 'preserveUrl' | 'replace' | 'only' | 'except' | 'reset' | 'viewTransition'>;
506
- export type FormComponentOptimisticCallback<TProps = Page['props']> = (props: TProps, formData: Record<string, FormDataConvertible>) => Partial<TProps> | void;
521
+ export type FormComponentOptimisticCallback<TProps = Page<SharedPageProps>['props']> = (props: TProps, formData: Record<string, FormDataConvertible>) => Partial<TProps> | void;
507
522
  export type FormComponentProps = Partial<Pick<Visit, 'headers' | 'queryStringArrayFormat' | 'errorBag' | 'showProgress' | 'invalidateCacheTags'> & Omit<VisitCallbacks, 'onPrefetched' | 'onPrefetching'>> & {
508
523
  method?: Method | Uppercase<Method>;
509
524
  action?: string | UrlMethodPair;