@inertiajs/svelte 2.3.17 → 3.0.0-beta.1
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/components/App.svelte +120 -44
- package/dist/components/App.svelte.d.ts +10 -19
- package/dist/components/Deferred.svelte +68 -9
- package/dist/components/Deferred.svelte.d.ts +9 -20
- package/dist/components/Form.svelte +358 -242
- package/dist/components/Form.svelte.d.ts +51 -96
- package/dist/components/InfiniteScroll.svelte +227 -167
- package/dist/components/InfiniteScroll.svelte.d.ts +29 -116
- package/dist/components/Link.svelte +96 -48
- package/dist/components/Link.svelte.d.ts +49 -56
- package/dist/components/Render.svelte +62 -21
- package/dist/components/Render.svelte.d.ts +9 -25
- package/dist/components/WhenVisible.svelte +83 -66
- package/dist/components/WhenVisible.svelte.d.ts +11 -26
- package/dist/components/createForm.d.ts +8 -0
- package/dist/components/createForm.js +4 -0
- package/dist/components/formContext.d.ts +3 -3
- package/dist/components/formContext.js +9 -3
- package/dist/createInertiaApp.d.ts +12 -7
- package/dist/createInertiaApp.js +63 -24
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -5
- package/dist/layoutProps.svelte.d.ts +6 -0
- package/dist/layoutProps.svelte.js +25 -0
- package/dist/link.js +13 -2
- package/dist/page.svelte.d.ts +10 -0
- package/dist/page.svelte.js +14 -0
- package/dist/types.d.ts +11 -4
- package/dist/types.js +1 -1
- package/dist/{useForm.d.ts → useForm.svelte.d.ts} +4 -4
- package/dist/useForm.svelte.js +116 -0
- package/dist/useFormState.svelte.d.ts +84 -0
- package/dist/useFormState.svelte.js +290 -0
- package/dist/useHttp.svelte.d.ts +61 -0
- package/dist/useHttp.svelte.js +154 -0
- package/dist/usePrefetch.svelte.d.ts +7 -0
- package/dist/{usePrefetch.js → usePrefetch.svelte.js} +18 -13
- package/dist/useRemember.svelte.d.ts +1 -0
- package/dist/useRemember.svelte.js +10 -0
- package/package.json +11 -11
- package/dist/page.d.ts +0 -13
- package/dist/page.js +0 -8
- package/dist/useForm.js +0 -356
- package/dist/usePrefetch.d.ts +0 -7
- package/dist/useRemember.d.ts +0 -1
- package/dist/useRemember.js +0 -11
|
@@ -1,98 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type Errors, type Method, type FormDataConvertible } from '@inertiajs/core';
|
|
1
|
+
import { type FormComponentProps, type FormComponentSlotProps, type FormDataConvertible } from '@inertiajs/core';
|
|
3
2
|
import { type NamedInputEvent, type ValidationConfig, type Validator } from 'laravel-precognition';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
reset?: ((...fields: string[]) => void) | undefined;
|
|
36
|
-
clearErrors?: ((...fields: string[]) => void) | undefined;
|
|
37
|
-
resetAndClearErrors?: ((...fields: string[]) => void) | undefined;
|
|
38
|
-
setError?: ((fieldOrFields: string | Record<string, string>, maybeValue?: string) => void) | undefined;
|
|
39
|
-
defaults?: (() => void) | undefined;
|
|
40
|
-
validate?: ((field?: string | NamedInputEvent | ValidationConfig, config?: ValidationConfig) => import("svelte/store").Writable<import("../useForm").InertiaPrecognitiveForm<Record<string, any>>> & import("../useForm").InertiaFormProps<Record<string, any>> & Record<string, any> & import("../useForm").InertiaFormValidationProps<Record<string, any>>) | undefined;
|
|
41
|
-
valid?: ((field: string) => boolean) | undefined;
|
|
42
|
-
invalid?: ((field: string) => boolean) | undefined;
|
|
43
|
-
touch?: ((field: string | NamedInputEvent | string[], ...fields: string[]) => import("svelte/store").Writable<import("../useForm").InertiaPrecognitiveForm<Record<string, any>>> & import("../useForm").InertiaFormProps<Record<string, any>> & Record<string, any> & import("../useForm").InertiaFormValidationProps<Record<string, any>>) | undefined;
|
|
44
|
-
touched?: ((field?: string) => boolean) | undefined;
|
|
45
|
-
validator?: (() => Validator) | undefined;
|
|
46
|
-
};
|
|
47
|
-
events: {
|
|
48
|
-
[evt: string]: CustomEvent<any>;
|
|
49
|
-
};
|
|
50
|
-
slots: {
|
|
51
|
-
default: {
|
|
52
|
-
errors: Errors;
|
|
53
|
-
hasErrors: boolean;
|
|
54
|
-
processing: boolean;
|
|
55
|
-
progress: import("axios").AxiosProgressEvent | null;
|
|
56
|
-
wasSuccessful: boolean;
|
|
57
|
-
recentlySuccessful: boolean;
|
|
58
|
-
clearErrors: (...fields: string[]) => void;
|
|
59
|
-
resetAndClearErrors: (...fields: string[]) => void;
|
|
60
|
-
setError: (fieldOrFields: string | Record<string, string>, maybeValue?: string) => void;
|
|
61
|
-
isDirty: boolean;
|
|
62
|
-
submit: (submitter?: HTMLElement | null) => void;
|
|
63
|
-
defaults: () => void;
|
|
64
|
-
reset: (...fields: string[]) => void;
|
|
65
|
-
getData: (submitter?: HTMLElement | null) => Record<string, FormDataConvertible>;
|
|
66
|
-
getFormData: (submitter?: HTMLElement | null) => FormData;
|
|
67
|
-
validator: () => Validator;
|
|
68
|
-
validate: (field?: string | NamedInputEvent | ValidationConfig, config?: ValidationConfig) => import("svelte/store").Writable<import("../useForm").InertiaPrecognitiveForm<Record<string, any>>> & import("../useForm").InertiaFormProps<Record<string, any>> & Record<string, any> & import("../useForm").InertiaFormValidationProps<Record<string, any>>;
|
|
69
|
-
touch: (field: string | NamedInputEvent | string[], ...fields: string[]) => import("svelte/store").Writable<import("../useForm").InertiaPrecognitiveForm<Record<string, any>>> & import("../useForm").InertiaFormProps<Record<string, any>> & Record<string, any> & import("../useForm").InertiaFormValidationProps<Record<string, any>>;
|
|
70
|
-
validating: boolean;
|
|
71
|
-
valid: <K extends string>(field: K) => boolean;
|
|
72
|
-
invalid: <K extends string>(field: K) => boolean;
|
|
73
|
-
touched: <K extends string>(field?: K | undefined) => boolean;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
exports?: undefined;
|
|
77
|
-
bindings?: undefined;
|
|
78
|
-
};
|
|
79
|
-
export type FormProps = typeof __propDef.props;
|
|
80
|
-
export type FormEvents = typeof __propDef.events;
|
|
81
|
-
export type FormSlots = typeof __propDef.slots;
|
|
82
|
-
export default class Form extends SvelteComponent<FormProps, FormEvents, FormSlots> {
|
|
83
|
-
get getFormData(): (submitter?: HTMLElement | null) => FormData;
|
|
84
|
-
get getData(): (submitter?: HTMLElement | null) => Record<string, FormDataConvertible>;
|
|
85
|
-
get submit(): (submitter?: HTMLElement | null) => void;
|
|
86
|
-
get reset(): (...fields: string[]) => void;
|
|
87
|
-
get clearErrors(): (...fields: string[]) => void;
|
|
88
|
-
get resetAndClearErrors(): (...fields: string[]) => void;
|
|
89
|
-
get setError(): (fieldOrFields: string | Record<string, string>, maybeValue?: string) => void;
|
|
90
|
-
get defaults(): () => void;
|
|
91
|
-
get validate(): (field?: string | NamedInputEvent | ValidationConfig, config?: ValidationConfig) => import("svelte/store").Writable<import("../useForm").InertiaPrecognitiveForm<Record<string, any>>> & import("../useForm").InertiaFormProps<Record<string, any>> & Record<string, any> & import("../useForm").InertiaFormValidationProps<Record<string, any>>;
|
|
92
|
-
get valid(): (field: string) => boolean;
|
|
93
|
-
get invalid(): (field: string) => boolean;
|
|
94
|
-
get touch(): (field: string | NamedInputEvent | string[], ...fields: string[]) => import("svelte/store").Writable<import("../useForm").InertiaPrecognitiveForm<Record<string, any>>> & import("../useForm").InertiaFormProps<Record<string, any>> & Record<string, any> & import("../useForm").InertiaFormValidationProps<Record<string, any>>;
|
|
95
|
-
get touched(): (field?: string) => boolean;
|
|
96
|
-
get validator(): () => Validator;
|
|
3
|
+
interface Props {
|
|
4
|
+
action?: FormComponentProps['action'];
|
|
5
|
+
method?: FormComponentProps['method'];
|
|
6
|
+
headers?: FormComponentProps['headers'];
|
|
7
|
+
queryStringArrayFormat?: FormComponentProps['queryStringArrayFormat'];
|
|
8
|
+
errorBag?: FormComponentProps['errorBag'];
|
|
9
|
+
showProgress?: FormComponentProps['showProgress'];
|
|
10
|
+
transform?: FormComponentProps['transform'];
|
|
11
|
+
options?: FormComponentProps['options'];
|
|
12
|
+
onCancelToken?: FormComponentProps['onCancelToken'];
|
|
13
|
+
onBefore?: FormComponentProps['onBefore'];
|
|
14
|
+
onStart?: FormComponentProps['onStart'];
|
|
15
|
+
onProgress?: FormComponentProps['onProgress'];
|
|
16
|
+
onFinish?: FormComponentProps['onFinish'];
|
|
17
|
+
onCancel?: FormComponentProps['onCancel'];
|
|
18
|
+
onSuccess?: FormComponentProps['onSuccess'];
|
|
19
|
+
onError?: FormComponentProps['onError'];
|
|
20
|
+
onSubmitComplete?: FormComponentProps['onSubmitComplete'];
|
|
21
|
+
disableWhileProcessing?: boolean;
|
|
22
|
+
invalidateCacheTags?: FormComponentProps['invalidateCacheTags'];
|
|
23
|
+
resetOnError?: FormComponentProps['resetOnError'];
|
|
24
|
+
resetOnSuccess?: FormComponentProps['resetOnSuccess'];
|
|
25
|
+
setDefaultsOnSuccess?: FormComponentProps['setDefaultsOnSuccess'];
|
|
26
|
+
validateFiles?: FormComponentProps['validateFiles'];
|
|
27
|
+
validationTimeout?: FormComponentProps['validationTimeout'];
|
|
28
|
+
optimistic?: FormComponentProps['optimistic'];
|
|
29
|
+
withAllErrors?: FormComponentProps['withAllErrors'];
|
|
30
|
+
component?: FormComponentProps['component'];
|
|
31
|
+
instant?: FormComponentProps['instant'];
|
|
32
|
+
children?: import('svelte').Snippet<[FormComponentSlotProps]>;
|
|
33
|
+
[key: string]: any;
|
|
97
34
|
}
|
|
98
|
-
|
|
35
|
+
type FormSubmitter = HTMLElement | null;
|
|
36
|
+
declare const Form: import("svelte").Component<Props, {
|
|
37
|
+
getFormData: (submitter?: FormSubmitter) => FormData;
|
|
38
|
+
getData: (submitter?: FormSubmitter) => Record<string, FormDataConvertible>;
|
|
39
|
+
submit: (submitter?: FormSubmitter) => void;
|
|
40
|
+
reset: (...fields: string[]) => void;
|
|
41
|
+
clearErrors: (...fields: string[]) => void;
|
|
42
|
+
resetAndClearErrors: (...fields: string[]) => void;
|
|
43
|
+
setError: (fieldOrFields: string | Record<string, string>, maybeValue?: string) => void;
|
|
44
|
+
defaults: () => void;
|
|
45
|
+
validate: (field?: string | NamedInputEvent | ValidationConfig, config?: ValidationConfig) => import("../useForm.svelte").InertiaFormProps<Record<string, any>> & Record<string, any> & import("../useForm.svelte").InertiaFormValidationProps<Record<string, any>>;
|
|
46
|
+
valid: (field: string) => boolean;
|
|
47
|
+
invalid: (field: string) => boolean;
|
|
48
|
+
touch: (field: string | NamedInputEvent | string[], ...fields: string[]) => import("../useForm.svelte").InertiaFormProps<Record<string, any>> & Record<string, any> & import("../useForm.svelte").InertiaFormValidationProps<Record<string, any>>;
|
|
49
|
+
touched: (field?: string) => boolean;
|
|
50
|
+
validator: () => Validator;
|
|
51
|
+
}, "action">;
|
|
52
|
+
type Form = ReturnType<typeof Form>;
|
|
53
|
+
export default Form;
|
|
@@ -1,195 +1,255 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
getScrollableParent,
|
|
4
|
+
type InfiniteScrollActionSlotProps,
|
|
5
|
+
type InfiniteScrollComponentBaseProps,
|
|
6
|
+
type UseInfiniteScrollProps,
|
|
7
|
+
type InfiniteScrollSlotProps,
|
|
8
|
+
type ReloadOptions,
|
|
9
|
+
useInfiniteScroll,
|
|
10
|
+
} from '@inertiajs/core'
|
|
11
|
+
import { onDestroy, onMount } from 'svelte'
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
data: InfiniteScrollComponentBaseProps['data']
|
|
15
|
+
buffer?: InfiniteScrollComponentBaseProps['buffer']
|
|
16
|
+
as?: InfiniteScrollComponentBaseProps['as']
|
|
17
|
+
manual?: InfiniteScrollComponentBaseProps['manual']
|
|
18
|
+
manualAfter?: InfiniteScrollComponentBaseProps['manualAfter']
|
|
19
|
+
preserveUrl?: InfiniteScrollComponentBaseProps['preserveUrl']
|
|
20
|
+
reverse?: InfiniteScrollComponentBaseProps['reverse']
|
|
21
|
+
autoScroll?: InfiniteScrollComponentBaseProps['autoScroll']
|
|
22
|
+
startElement?: string | (() => HTMLElement | null) | null
|
|
23
|
+
endElement?: string | (() => HTMLElement | null) | null
|
|
24
|
+
itemsElement?: string | (() => HTMLElement | null) | null
|
|
25
|
+
params?: ReloadOptions
|
|
26
|
+
onlyNext?: boolean
|
|
27
|
+
onlyPrevious?: boolean
|
|
28
|
+
previous?: import('svelte').Snippet<[any]>
|
|
29
|
+
loading?: import('svelte').Snippet<[any]>
|
|
30
|
+
next?: import('svelte').Snippet<[any]>
|
|
31
|
+
children?: import('svelte').Snippet<[any]>
|
|
32
|
+
[key: string]: any
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let {
|
|
36
|
+
data,
|
|
37
|
+
buffer = 0,
|
|
38
|
+
as = 'div',
|
|
39
|
+
manual = false,
|
|
40
|
+
manualAfter = 0,
|
|
41
|
+
preserveUrl = false,
|
|
42
|
+
reverse = false,
|
|
43
|
+
autoScroll = undefined,
|
|
44
|
+
startElement = null,
|
|
45
|
+
endElement = null,
|
|
46
|
+
itemsElement = null,
|
|
47
|
+
params = {},
|
|
48
|
+
onlyNext = false,
|
|
49
|
+
onlyPrevious = false,
|
|
50
|
+
previous,
|
|
51
|
+
loading,
|
|
52
|
+
next,
|
|
53
|
+
children,
|
|
54
|
+
...rest
|
|
55
|
+
}: Props = $props()
|
|
56
|
+
|
|
57
|
+
let itemsElementRef: HTMLElement = $state(null!)
|
|
58
|
+
let startElementRef: HTMLElement = $state(null!)
|
|
59
|
+
let endElementRef: HTMLElement = $state(null!)
|
|
60
|
+
let loadingPrevious = $state(false)
|
|
61
|
+
let loadingNext = $state(false)
|
|
62
|
+
let requestCount = $state(0)
|
|
63
|
+
let hasPreviousPage = $state(false)
|
|
64
|
+
let hasNextPage = $state(false)
|
|
65
|
+
|
|
66
|
+
let infiniteScrollInstance: UseInfiniteScrollProps = $state(null!)
|
|
67
|
+
|
|
68
|
+
function resolveHTMLElement(
|
|
69
|
+
value: string | (() => HTMLElement | null) | null,
|
|
70
|
+
fallback: HTMLElement | null,
|
|
71
|
+
): HTMLElement | null {
|
|
72
|
+
if (!value) {
|
|
73
|
+
return fallback
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (typeof value === 'string') {
|
|
77
|
+
return document.querySelector(value) as HTMLElement | null
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (typeof value === 'function') {
|
|
81
|
+
return value() || null
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return fallback
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function scrollToBottom() {
|
|
88
|
+
if (scrollableParent) {
|
|
89
|
+
scrollableParent.scrollTo({
|
|
90
|
+
top: scrollableParent.scrollHeight,
|
|
91
|
+
behavior: 'instant',
|
|
92
|
+
})
|
|
93
|
+
} else {
|
|
94
|
+
window.scrollTo({
|
|
95
|
+
top: document.body.scrollHeight,
|
|
96
|
+
behavior: 'instant',
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function fetchPrevious(options?: any) {
|
|
102
|
+
infiniteScrollInstance?.dataManager.fetchPrevious(options)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function fetchNext(options?: any) {
|
|
106
|
+
infiniteScrollInstance?.dataManager.fetchNext(options)
|
|
60
107
|
}
|
|
61
|
-
|
|
62
|
-
|
|
108
|
+
|
|
109
|
+
export function hasPrevious(): boolean {
|
|
110
|
+
return infiniteScrollInstance?.dataManager.hasPrevious() || false
|
|
63
111
|
}
|
|
64
|
-
|
|
65
|
-
|
|
112
|
+
|
|
113
|
+
export function hasNext(): boolean {
|
|
114
|
+
return infiniteScrollInstance?.dataManager.hasNext() || false
|
|
66
115
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
window.scrollTo({
|
|
77
|
-
top: document.body.scrollHeight,
|
|
78
|
-
behavior: "instant"
|
|
79
|
-
});
|
|
116
|
+
|
|
117
|
+
onMount(() => {
|
|
118
|
+
setTimeout(setupInfiniteScrollInstance)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
function syncStateFromDataManager() {
|
|
122
|
+
requestCount = infiniteScrollInstance!.dataManager.getRequestCount()
|
|
123
|
+
hasPreviousPage = infiniteScrollInstance!.dataManager.hasPrevious()
|
|
124
|
+
hasNextPage = infiniteScrollInstance!.dataManager.hasNext()
|
|
80
125
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
onDataReset: syncStateFromDataManager
|
|
131
|
-
});
|
|
132
|
-
const { dataManager, elementManager } = infiniteScrollInstance;
|
|
133
|
-
syncStateFromDataManager();
|
|
134
|
-
elementManager.setupObservers();
|
|
135
|
-
elementManager.processServerLoadedElements(dataManager.getLastLoadedPage());
|
|
136
|
-
const shouldAutoScroll = autoScroll !== void 0 ? autoScroll : reverse;
|
|
137
|
-
if (shouldAutoScroll) {
|
|
138
|
-
scrollToBottom();
|
|
126
|
+
|
|
127
|
+
function setupInfiniteScrollInstance() {
|
|
128
|
+
const resolvedItemsElement = resolveHTMLElement(itemsElement, itemsElementRef)
|
|
129
|
+
const resolvedStartElement = resolveHTMLElement(startElement, startElementRef)
|
|
130
|
+
const resolvedEndElement = resolveHTMLElement(endElement, endElementRef)
|
|
131
|
+
|
|
132
|
+
infiniteScrollInstance = useInfiniteScroll({
|
|
133
|
+
// Data
|
|
134
|
+
getPropName: () => data,
|
|
135
|
+
inReverseMode: () => reverse ?? false,
|
|
136
|
+
shouldFetchNext: () => !onlyPrevious,
|
|
137
|
+
shouldFetchPrevious: () => !onlyNext,
|
|
138
|
+
shouldPreserveUrl: () => preserveUrl ?? false,
|
|
139
|
+
getReloadOptions: () => params,
|
|
140
|
+
|
|
141
|
+
// Elements
|
|
142
|
+
getTriggerMargin: () => buffer ?? 0,
|
|
143
|
+
getStartElement: () => resolvedStartElement!,
|
|
144
|
+
getEndElement: () => resolvedEndElement!,
|
|
145
|
+
getItemsElement: () => resolvedItemsElement!,
|
|
146
|
+
getScrollableParent: () => (resolvedItemsElement ? getScrollableParent(resolvedItemsElement) : null),
|
|
147
|
+
|
|
148
|
+
// Request callbacks
|
|
149
|
+
onBeforePreviousRequest: () => (loadingPrevious = true),
|
|
150
|
+
onBeforeNextRequest: () => (loadingNext = true),
|
|
151
|
+
onCompletePreviousRequest: () => {
|
|
152
|
+
loadingPrevious = false
|
|
153
|
+
syncStateFromDataManager()
|
|
154
|
+
},
|
|
155
|
+
onCompleteNextRequest: () => {
|
|
156
|
+
loadingNext = false
|
|
157
|
+
syncStateFromDataManager()
|
|
158
|
+
},
|
|
159
|
+
onDataReset: syncStateFromDataManager,
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
const { dataManager, elementManager } = infiniteScrollInstance
|
|
163
|
+
|
|
164
|
+
syncStateFromDataManager()
|
|
165
|
+
|
|
166
|
+
elementManager.setupObservers()
|
|
167
|
+
elementManager.processServerLoadedElements(dataManager.getLastLoadedPage())
|
|
168
|
+
|
|
169
|
+
// autoScroll defaults to reverse value if not explicitly set
|
|
170
|
+
const shouldAutoScroll = autoScroll !== undefined ? autoScroll : reverse
|
|
171
|
+
|
|
172
|
+
if (shouldAutoScroll) {
|
|
173
|
+
scrollToBottom()
|
|
174
|
+
}
|
|
139
175
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
176
|
+
|
|
177
|
+
onDestroy(() => infiniteScrollInstance?.flush())
|
|
178
|
+
let resolvedItemsElement = $derived(resolveHTMLElement(itemsElement, itemsElementRef))
|
|
179
|
+
let scrollableParent = $derived(resolvedItemsElement ? getScrollableParent(resolvedItemsElement) : null)
|
|
180
|
+
let sharedExposed = $derived({
|
|
181
|
+
loadingPrevious,
|
|
182
|
+
loadingNext,
|
|
183
|
+
hasPrevious: hasPreviousPage,
|
|
184
|
+
hasNext: hasNextPage,
|
|
185
|
+
} satisfies Pick<InfiniteScrollActionSlotProps, 'loadingPrevious' | 'loadingNext' | 'hasPrevious' | 'hasNext'>)
|
|
186
|
+
let manualMode = $derived(manual || (manualAfter !== undefined && manualAfter > 0 && requestCount >= manualAfter))
|
|
187
|
+
let autoLoad = $derived(!manualMode)
|
|
188
|
+
let headerAutoMode = $derived(autoLoad && !onlyNext)
|
|
189
|
+
let exposedPrevious = $derived({
|
|
190
|
+
loading: loadingPrevious,
|
|
191
|
+
fetch: fetchPrevious,
|
|
192
|
+
autoMode: headerAutoMode,
|
|
193
|
+
manualMode: !headerAutoMode,
|
|
194
|
+
hasMore: hasPreviousPage,
|
|
195
|
+
...sharedExposed,
|
|
196
|
+
} satisfies InfiniteScrollActionSlotProps)
|
|
197
|
+
let footerAutoMode = $derived(autoLoad && !onlyPrevious)
|
|
198
|
+
let exposedNext = $derived({
|
|
199
|
+
loading: loadingNext,
|
|
200
|
+
fetch: fetchNext,
|
|
201
|
+
autoMode: footerAutoMode,
|
|
202
|
+
manualMode: !footerAutoMode,
|
|
203
|
+
hasMore: hasNextPage,
|
|
204
|
+
...sharedExposed,
|
|
205
|
+
} satisfies InfiniteScrollActionSlotProps)
|
|
206
|
+
let exposedSlot = $derived({
|
|
207
|
+
loading: loadingPrevious || loadingNext,
|
|
208
|
+
loadingPrevious,
|
|
209
|
+
loadingNext,
|
|
210
|
+
} satisfies InfiniteScrollSlotProps)
|
|
211
|
+
$effect(() => {
|
|
212
|
+
// Make this block run whenever these change
|
|
213
|
+
;[autoLoad, onlyNext, onlyPrevious, reverse]
|
|
214
|
+
|
|
215
|
+
autoLoad
|
|
216
|
+
? infiniteScrollInstance?.elementManager.enableTriggers()
|
|
217
|
+
: infiniteScrollInstance?.elementManager.disableTriggers()
|
|
218
|
+
})
|
|
151
219
|
</script>
|
|
152
220
|
|
|
153
221
|
{#if !startElement && !reverse}
|
|
154
222
|
<div bind:this={startElementRef}>
|
|
155
|
-
|
|
156
|
-
{
|
|
157
|
-
|
|
158
|
-
{/if}
|
|
159
|
-
</slot>
|
|
223
|
+
{#if previous}{@render previous({ exposedPrevious, ...exposedPrevious })}{:else if loadingPrevious}
|
|
224
|
+
{@render loading?.({ exposedPrevious, ...exposedPrevious })}
|
|
225
|
+
{/if}
|
|
160
226
|
</div>
|
|
161
227
|
{/if}
|
|
162
228
|
|
|
163
229
|
{#if !endElement && reverse}
|
|
164
230
|
<div bind:this={endElementRef}>
|
|
165
|
-
|
|
166
|
-
{
|
|
167
|
-
|
|
168
|
-
{/if}
|
|
169
|
-
</slot>
|
|
231
|
+
{#if next}{@render next({ exposedNext, ...exposedNext })}{:else if loadingNext}
|
|
232
|
+
{@render loading?.({ exposedNext, ...exposedNext })}
|
|
233
|
+
{/if}
|
|
170
234
|
</div>
|
|
171
235
|
{/if}
|
|
172
236
|
|
|
173
|
-
<svelte:element this={as} bind:this={itemsElementRef} {
|
|
174
|
-
|
|
237
|
+
<svelte:element this={as} bind:this={itemsElementRef} {...rest}>
|
|
238
|
+
{@render children?.({ exposedSlot, ...exposedSlot })}
|
|
175
239
|
</svelte:element>
|
|
176
240
|
|
|
177
241
|
{#if !startElement && reverse}
|
|
178
242
|
<div bind:this={startElementRef}>
|
|
179
|
-
|
|
180
|
-
{
|
|
181
|
-
|
|
182
|
-
{/if}
|
|
183
|
-
</slot>
|
|
243
|
+
{#if previous}{@render previous({ exposedPrevious, ...exposedPrevious })}{:else if loadingPrevious}
|
|
244
|
+
{@render loading?.({ exposedPrevious, ...exposedPrevious })}
|
|
245
|
+
{/if}
|
|
184
246
|
</div>
|
|
185
247
|
{/if}
|
|
186
248
|
|
|
187
249
|
{#if !endElement && !reverse}
|
|
188
250
|
<div bind:this={endElementRef}>
|
|
189
|
-
|
|
190
|
-
{
|
|
191
|
-
|
|
192
|
-
{/if}
|
|
193
|
-
</slot>
|
|
251
|
+
{#if next}{@render next({ exposedNext, ...exposedNext })}{:else if loadingNext}
|
|
252
|
+
{@render loading?.({ exposedNext, ...exposedNext })}
|
|
253
|
+
{/if}
|
|
194
254
|
</div>
|
|
195
255
|
{/if}
|