@teamnovu/kit-shopware-composables 0.0.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/.env +2 -0
- package/api-gen.config.json +5 -0
- package/api-types/storeApiSchema.json +12187 -0
- package/api-types/storeApiSchema.localhost.http +1043 -0
- package/api-types/storeApiSchema.overrides.json +1 -0
- package/api-types/storeApiTypes.d.ts +5909 -0
- package/docker/boot_end.sh +12 -0
- package/docker/docker-compose.yaml +22 -0
- package/docker/types.sh +14 -0
- package/eslint.config.mjs +84 -0
- package/package.json +49 -0
- package/src/context/useContextOptions.ts +16 -0
- package/src/context/useContextUpdate.ts +16 -0
- package/src/general/useSeoUrl.ts +18 -0
- package/src/index.ts +24 -0
- package/src/inject.ts +16 -0
- package/src/keys.ts +42 -0
- package/src/products/useCategoryQueryOptions.ts +25 -0
- package/src/products/useProductListingQueryOptions.test.ts +24 -0
- package/src/products/useProductListingQueryOptions.ts +28 -0
- package/src/products/useProductPrice.ts +136 -0
- package/src/products/useProductQueryOptions.ts +28 -0
- package/src/products/useProductVariantForOptions.ts +21 -0
- package/src/types/query.ts +18 -0
- package/src/usePagination.ts +72 -0
- package/src/util/url.ts +8 -0
- package/tsconfig.json +23 -0
- package/vite.config.js +39 -0
- package/vitest.config.js +10 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Schemas } from '#store-types'
|
|
2
|
+
import type { MaybeRef } from 'vue'
|
|
3
|
+
import { computed, reactive, toRef, unref, watch } from 'vue'
|
|
4
|
+
|
|
5
|
+
interface PaginationOptions {
|
|
6
|
+
page?: MaybeRef<number>
|
|
7
|
+
total?: MaybeRef<number>
|
|
8
|
+
limit?: MaybeRef<number>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function usePagination(opts?: PaginationOptions) {
|
|
12
|
+
const { total, limit, page } = opts ?? {}
|
|
13
|
+
|
|
14
|
+
const state = reactive({
|
|
15
|
+
page: page ?? 1,
|
|
16
|
+
total: total ?? 0,
|
|
17
|
+
limit: limit,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const pageCount = computed(() => {
|
|
21
|
+
if (state.limit === undefined) return 1
|
|
22
|
+
return Math.max(1, Math.ceil(state.total / state.limit))
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const privatePage = computed<number, number>({
|
|
26
|
+
get() {
|
|
27
|
+
return state.page
|
|
28
|
+
},
|
|
29
|
+
set(value) {
|
|
30
|
+
// Clamp the value between 1 and totalPages
|
|
31
|
+
state.page = Math.max(1, Math.min(unref(pageCount), value))
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
watch(
|
|
36
|
+
[() => unref(pageCount), () => state],
|
|
37
|
+
([newPageCount, newState]) => {
|
|
38
|
+
// Reset the page to the last available page when the total pages change
|
|
39
|
+
state.page = Math.min(newPageCount, state.page)
|
|
40
|
+
state.total = newState.total ?? 0
|
|
41
|
+
state.limit = newState.limit
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
const isLastPage = computed(() => state.page === unref(pageCount))
|
|
46
|
+
const isFirstPage = computed(() => state.page === 1)
|
|
47
|
+
|
|
48
|
+
const queryOptions = computed(() => ({
|
|
49
|
+
p: state.page,
|
|
50
|
+
limit: state.limit,
|
|
51
|
+
}))
|
|
52
|
+
|
|
53
|
+
const usePaginationSync = (data: MaybeRef<Schemas['EntitySearchResult']>) => {
|
|
54
|
+
watch(() => unref(data), (newData) => {
|
|
55
|
+
state.total = newData?.total ?? 0
|
|
56
|
+
state.limit = newData?.limit ?? 0
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
page: unref(privatePage),
|
|
62
|
+
total: toRef(state, 'total'),
|
|
63
|
+
limit: toRef(state, 'limit'),
|
|
64
|
+
pageCount,
|
|
65
|
+
isLastPage,
|
|
66
|
+
isFirstPage,
|
|
67
|
+
usePaginationSync,
|
|
68
|
+
|
|
69
|
+
// This can be used to pass the pagination options directly to the query options
|
|
70
|
+
queryOptions,
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/util/url.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"types": [
|
|
6
|
+
"vue",
|
|
7
|
+
"vite/client",
|
|
8
|
+
"vitest/globals"
|
|
9
|
+
],
|
|
10
|
+
"paths": {
|
|
11
|
+
"#store-types": [
|
|
12
|
+
"./api-types/storeApiTypes.d.ts"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"typeRoots": [
|
|
16
|
+
"./node_modules"
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"src/**/*",
|
|
21
|
+
"../components/src/injects"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/vite.config.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import vue from '@vitejs/plugin-vue'
|
|
2
|
+
import { resolve } from 'path'
|
|
3
|
+
import { defineConfig } from 'vite'
|
|
4
|
+
import dts from 'vite-plugin-dts'
|
|
5
|
+
import pkg from './package.json'
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
plugins: [
|
|
9
|
+
vue(),
|
|
10
|
+
dts({
|
|
11
|
+
staticImport: true,
|
|
12
|
+
}),
|
|
13
|
+
],
|
|
14
|
+
build: {
|
|
15
|
+
emptyOutDir: false,
|
|
16
|
+
lib: {
|
|
17
|
+
formats: ['es'],
|
|
18
|
+
// Could also be a dictionary or array of multiple entry points
|
|
19
|
+
entry: {
|
|
20
|
+
index: resolve(__dirname, 'src/index.ts'),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
rollupOptions: {
|
|
24
|
+
// make sure to externalize deps that shouldn't be bundled
|
|
25
|
+
// into your library
|
|
26
|
+
external: [
|
|
27
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
28
|
+
...Object.keys(pkg.peerDependencies ?? {}),
|
|
29
|
+
],
|
|
30
|
+
output: {
|
|
31
|
+
// Provide global variables to use in the UMD build
|
|
32
|
+
// for externalized deps
|
|
33
|
+
globals: {
|
|
34
|
+
vue: 'Vue',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
})
|
package/vitest.config.js
ADDED