@btst/stack 1.0.1 → 1.1.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/README.md +156 -709
- package/dist/api/index.cjs +2 -1
- package/dist/api/index.d.cts +4 -3
- package/dist/api/index.d.mts +4 -3
- package/dist/api/index.d.ts +4 -3
- package/dist/api/index.mjs +1 -1
- package/dist/client/components/compose.cjs +68 -0
- package/dist/client/components/compose.mjs +65 -0
- package/dist/client/components/error-boundary.cjs +24 -0
- package/dist/client/components/error-boundary.mjs +22 -0
- package/dist/client/components/index.cjs +10 -0
- package/dist/client/components/index.d.cts +52 -0
- package/dist/client/components/index.d.mts +52 -0
- package/dist/client/components/index.d.ts +52 -0
- package/dist/client/components/index.mjs +2 -0
- package/dist/client/index.cjs +24 -5
- package/dist/client/index.d.cts +125 -8
- package/dist/client/index.d.mts +125 -8
- package/dist/client/index.d.ts +125 -8
- package/dist/client/index.mjs +21 -4
- package/dist/client/meta-utils.cjs +162 -0
- package/dist/client/meta-utils.mjs +160 -0
- package/dist/client/path-utils.cjs +15 -0
- package/dist/client/path-utils.mjs +13 -0
- package/dist/client/sitemap-utils.cjs +14 -0
- package/dist/client/sitemap-utils.mjs +12 -0
- package/dist/context/index.cjs +6 -63
- package/dist/context/index.d.cts +21 -24
- package/dist/context/index.d.mts +21 -24
- package/dist/context/index.d.ts +21 -24
- package/dist/context/index.mjs +1 -61
- package/dist/context/provider.cjs +51 -0
- package/dist/context/provider.mjs +46 -0
- package/dist/index.cjs +2 -3
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +1 -2
- package/dist/plugins/api/index.cjs +13 -0
- package/dist/plugins/api/index.d.cts +40 -0
- package/dist/plugins/api/index.d.mts +40 -0
- package/dist/plugins/api/index.d.ts +40 -0
- package/dist/plugins/api/index.mjs +8 -0
- package/dist/plugins/blog/api/index.cjs +11 -0
- package/dist/plugins/blog/api/index.d.cts +7 -0
- package/dist/plugins/blog/api/index.d.mts +7 -0
- package/dist/plugins/blog/api/index.d.ts +7 -0
- package/dist/plugins/blog/api/index.mjs +2 -0
- package/dist/plugins/blog/api/plugin.cjs +569 -0
- package/dist/plugins/blog/api/plugin.mjs +565 -0
- package/dist/plugins/blog/client/components/forms/image-field.cjs +133 -0
- package/dist/plugins/blog/client/components/forms/image-field.mjs +131 -0
- package/dist/plugins/blog/client/components/forms/markdown-editor-styles.css +30 -0
- package/dist/plugins/blog/client/components/forms/markdown-editor.cjs +106 -0
- package/dist/plugins/blog/client/components/forms/markdown-editor.mjs +104 -0
- package/dist/plugins/blog/client/components/forms/post-forms.cjs +401 -0
- package/dist/plugins/blog/client/components/forms/post-forms.mjs +398 -0
- package/dist/plugins/blog/client/components/forms/tags-multiselect.cjs +71 -0
- package/dist/plugins/blog/client/components/forms/tags-multiselect.mjs +65 -0
- package/dist/plugins/blog/client/components/index.cjs +17 -0
- package/dist/plugins/blog/client/components/index.d.cts +22 -0
- package/dist/plugins/blog/client/components/index.d.mts +22 -0
- package/dist/plugins/blog/client/components/index.d.ts +22 -0
- package/dist/plugins/blog/client/components/index.mjs +12 -0
- package/dist/plugins/blog/client/components/loading/form-page-skeleton.cjs +62 -0
- package/dist/plugins/blog/client/components/loading/form-page-skeleton.mjs +60 -0
- package/dist/plugins/blog/client/components/loading/index.cjs +20 -0
- package/dist/plugins/blog/client/components/loading/index.mjs +16 -0
- package/dist/plugins/blog/client/components/loading/list-page-skeleton.cjs +26 -0
- package/dist/plugins/blog/client/components/loading/list-page-skeleton.mjs +24 -0
- package/dist/plugins/blog/client/components/loading/page-header-skeleton.cjs +13 -0
- package/dist/plugins/blog/client/components/loading/page-header-skeleton.mjs +11 -0
- package/dist/plugins/blog/client/components/loading/post-card-skeleton.cjs +22 -0
- package/dist/plugins/blog/client/components/loading/post-card-skeleton.mjs +20 -0
- package/dist/plugins/blog/client/components/loading/post-page-skeleton.cjs +56 -0
- package/dist/plugins/blog/client/components/loading/post-page-skeleton.mjs +54 -0
- package/dist/plugins/blog/client/components/pages/404-page.cjs +19 -0
- package/dist/plugins/blog/client/components/pages/404-page.mjs +17 -0
- package/dist/plugins/blog/client/components/pages/edit-post-page.cjs +41 -0
- package/dist/plugins/blog/client/components/pages/edit-post-page.internal.cjs +57 -0
- package/dist/plugins/blog/client/components/pages/edit-post-page.internal.mjs +55 -0
- package/dist/plugins/blog/client/components/pages/edit-post-page.mjs +39 -0
- package/dist/plugins/blog/client/components/pages/home-page.cjs +41 -0
- package/dist/plugins/blog/client/components/pages/home-page.internal.cjs +61 -0
- package/dist/plugins/blog/client/components/pages/home-page.internal.mjs +59 -0
- package/dist/plugins/blog/client/components/pages/home-page.mjs +39 -0
- package/dist/plugins/blog/client/components/pages/new-post-page.cjs +37 -0
- package/dist/plugins/blog/client/components/pages/new-post-page.internal.cjs +53 -0
- package/dist/plugins/blog/client/components/pages/new-post-page.internal.mjs +51 -0
- package/dist/plugins/blog/client/components/pages/new-post-page.mjs +35 -0
- package/dist/plugins/blog/client/components/pages/post-page.cjs +39 -0
- package/dist/plugins/blog/client/components/pages/post-page.internal.cjs +101 -0
- package/dist/plugins/blog/client/components/pages/post-page.internal.mjs +99 -0
- package/dist/plugins/blog/client/components/pages/post-page.mjs +37 -0
- package/dist/plugins/blog/client/components/pages/tag-page.cjs +39 -0
- package/dist/plugins/blog/client/components/pages/tag-page.internal.cjs +61 -0
- package/dist/plugins/blog/client/components/pages/tag-page.internal.mjs +59 -0
- package/dist/plugins/blog/client/components/pages/tag-page.mjs +37 -0
- package/dist/plugins/blog/client/components/shared/better-blog-attribution.cjs +24 -0
- package/dist/plugins/blog/client/components/shared/better-blog-attribution.mjs +22 -0
- package/dist/plugins/blog/client/components/shared/default-error.cjs +18 -0
- package/dist/plugins/blog/client/components/shared/default-error.mjs +16 -0
- package/dist/plugins/blog/client/components/shared/defaults.cjs +13 -0
- package/dist/plugins/blog/client/components/shared/defaults.mjs +10 -0
- package/dist/plugins/blog/client/components/shared/empty-list.cjs +21 -0
- package/dist/plugins/blog/client/components/shared/empty-list.mjs +19 -0
- package/dist/plugins/blog/client/components/shared/error-placeholder.cjs +24 -0
- package/dist/plugins/blog/client/components/shared/error-placeholder.mjs +22 -0
- package/dist/plugins/blog/client/components/shared/highlight-text.cjs +53 -0
- package/dist/plugins/blog/client/components/shared/highlight-text.mjs +51 -0
- package/dist/plugins/blog/client/components/shared/markdown-content-styles.css +328 -0
- package/dist/plugins/blog/client/components/shared/markdown-content.cjs +324 -0
- package/dist/plugins/blog/client/components/shared/markdown-content.mjs +315 -0
- package/dist/plugins/blog/client/components/shared/on-this-page.cjs +161 -0
- package/dist/plugins/blog/client/components/shared/on-this-page.mjs +158 -0
- package/dist/plugins/blog/client/components/shared/page-header.cjs +40 -0
- package/dist/plugins/blog/client/components/shared/page-header.mjs +38 -0
- package/dist/plugins/blog/client/components/shared/page-layout.cjs +24 -0
- package/dist/plugins/blog/client/components/shared/page-layout.mjs +22 -0
- package/dist/plugins/blog/client/components/shared/page-wrapper.cjs +23 -0
- package/dist/plugins/blog/client/components/shared/page-wrapper.mjs +21 -0
- package/dist/plugins/blog/client/components/shared/post-card.cjs +279 -0
- package/dist/plugins/blog/client/components/shared/post-card.mjs +277 -0
- package/dist/plugins/blog/client/components/shared/post-navigation.cjs +74 -0
- package/dist/plugins/blog/client/components/shared/post-navigation.mjs +72 -0
- package/dist/plugins/blog/client/components/shared/posts-list.cjs +48 -0
- package/dist/plugins/blog/client/components/shared/posts-list.mjs +46 -0
- package/dist/plugins/blog/client/components/shared/recent-posts-carousel.cjs +59 -0
- package/dist/plugins/blog/client/components/shared/recent-posts-carousel.mjs +57 -0
- package/dist/plugins/blog/client/components/shared/search-input.cjs +136 -0
- package/dist/plugins/blog/client/components/shared/search-input.mjs +117 -0
- package/dist/plugins/blog/client/components/shared/search-modal.cjs +135 -0
- package/dist/plugins/blog/client/components/shared/search-modal.mjs +116 -0
- package/dist/plugins/blog/client/components/shared/tags-list.cjs +22 -0
- package/dist/plugins/blog/client/components/shared/tags-list.mjs +20 -0
- package/dist/plugins/blog/client/components/shared/use-route-lifecycle.cjs +50 -0
- package/dist/plugins/blog/client/components/shared/use-route-lifecycle.mjs +48 -0
- package/dist/plugins/blog/client/hooks/blog-hooks.cjs +380 -0
- package/dist/plugins/blog/client/hooks/blog-hooks.mjs +368 -0
- package/dist/plugins/blog/client/hooks/index.cjs +17 -0
- package/dist/plugins/blog/client/hooks/index.d.cts +150 -0
- package/dist/plugins/blog/client/hooks/index.d.mts +150 -0
- package/dist/plugins/blog/client/hooks/index.d.ts +150 -0
- package/dist/plugins/blog/client/hooks/index.mjs +1 -0
- package/dist/plugins/blog/client/hooks/use-debounce.cjs +16 -0
- package/dist/plugins/blog/client/hooks/use-debounce.mjs +14 -0
- package/dist/plugins/blog/client/index.cjs +7 -0
- package/dist/plugins/blog/client/index.d.cts +414 -0
- package/dist/plugins/blog/client/index.d.mts +414 -0
- package/dist/plugins/blog/client/index.d.ts +414 -0
- package/dist/plugins/blog/client/index.mjs +1 -0
- package/dist/plugins/blog/client/localization/blog-card.cjs +7 -0
- package/dist/plugins/blog/client/localization/blog-card.mjs +5 -0
- package/dist/plugins/blog/client/localization/blog-common.cjs +10 -0
- package/dist/plugins/blog/client/localization/blog-common.mjs +8 -0
- package/dist/plugins/blog/client/localization/blog-forms.cjs +40 -0
- package/dist/plugins/blog/client/localization/blog-forms.mjs +38 -0
- package/dist/plugins/blog/client/localization/blog-list.cjs +18 -0
- package/dist/plugins/blog/client/localization/blog-list.mjs +16 -0
- package/dist/plugins/blog/client/localization/blog-post.cjs +13 -0
- package/dist/plugins/blog/client/localization/blog-post.mjs +11 -0
- package/dist/plugins/blog/client/localization/index.cjs +17 -0
- package/dist/plugins/blog/client/localization/index.mjs +15 -0
- package/dist/plugins/blog/client/plugin.cjs +462 -0
- package/dist/plugins/blog/client/plugin.mjs +460 -0
- package/dist/plugins/blog/client.css +3 -0
- package/dist/plugins/blog/db.cjs +90 -0
- package/dist/plugins/blog/db.mjs +88 -0
- package/dist/plugins/blog/query-keys.cjs +181 -0
- package/dist/plugins/blog/query-keys.d.cts +530 -0
- package/dist/plugins/blog/query-keys.d.mts +530 -0
- package/dist/plugins/blog/query-keys.d.ts +530 -0
- package/dist/plugins/blog/query-keys.mjs +179 -0
- package/dist/plugins/blog/schemas.cjs +39 -0
- package/dist/plugins/blog/schemas.mjs +35 -0
- package/dist/plugins/blog/style.css +22 -0
- package/dist/plugins/blog/utils.cjs +97 -0
- package/dist/plugins/blog/utils.mjs +87 -0
- package/dist/plugins/client/index.cjs +15 -0
- package/dist/plugins/client/index.d.cts +57 -0
- package/dist/plugins/client/index.d.mts +57 -0
- package/dist/plugins/client/index.d.ts +57 -0
- package/dist/plugins/client/index.mjs +9 -0
- package/dist/{shared/stack.3OUyGp_E.mjs → plugins/utils.mjs} +1 -1
- package/dist/shared/{stack.DORw_1ps.d.cts → stack.ByOugz9d.d.cts} +17 -1
- package/dist/shared/{stack.DORw_1ps.d.mts → stack.ByOugz9d.d.mts} +17 -1
- package/dist/shared/{stack.DORw_1ps.d.ts → stack.ByOugz9d.d.ts} +17 -1
- package/dist/shared/stack.CoPoHVfV.d.cts +76 -0
- package/dist/shared/stack.CoPoHVfV.d.mts +76 -0
- package/dist/shared/stack.CoPoHVfV.d.ts +76 -0
- package/package.json +102 -14
- package/src/__tests__/plugins.test.tsx +539 -0
- package/src/__tests__/sitemap.test.ts +60 -0
- package/src/api/index.ts +75 -0
- package/src/client/components/compose.tsx +116 -0
- package/src/client/components/error-boundary.tsx +30 -0
- package/src/client/components/index.tsx +2 -0
- package/src/client/index.ts +109 -0
- package/src/client/meta-utils.ts +228 -0
- package/src/client/path-utils.ts +38 -0
- package/src/client/sitemap-utils.ts +46 -0
- package/src/context/index.ts +1 -0
- package/src/context/provider.tsx +157 -0
- package/src/index.ts +1 -0
- package/src/plugins/api/index.ts +50 -0
- package/src/plugins/blog/api/index.ts +2 -0
- package/src/plugins/blog/api/plugin.ts +759 -0
- package/src/plugins/blog/client/components/forms/image-field.tsx +165 -0
- package/src/plugins/blog/client/components/forms/markdown-editor-styles.css +30 -0
- package/src/plugins/blog/client/components/forms/markdown-editor.tsx +136 -0
- package/src/plugins/blog/client/components/forms/post-forms.tsx +531 -0
- package/src/plugins/blog/client/components/forms/tags-multiselect.tsx +79 -0
- package/src/plugins/blog/client/components/index.tsx +11 -0
- package/src/plugins/blog/client/components/loading/form-page-skeleton.tsx +75 -0
- package/src/plugins/blog/client/components/loading/index.tsx +27 -0
- package/src/plugins/blog/client/components/loading/list-page-skeleton.tsx +38 -0
- package/src/plugins/blog/client/components/loading/page-header-skeleton.tsx +10 -0
- package/src/plugins/blog/client/components/loading/post-card-skeleton.tsx +30 -0
- package/src/plugins/blog/client/components/loading/post-page-skeleton.tsx +75 -0
- package/src/plugins/blog/client/components/pages/404-page.tsx +23 -0
- package/src/plugins/blog/client/components/pages/edit-post-page.internal.tsx +60 -0
- package/src/plugins/blog/client/components/pages/edit-post-page.tsx +40 -0
- package/src/plugins/blog/client/components/pages/home-page.internal.tsx +71 -0
- package/src/plugins/blog/client/components/pages/home-page.tsx +42 -0
- package/src/plugins/blog/client/components/pages/new-post-page.internal.tsx +59 -0
- package/src/plugins/blog/client/components/pages/new-post-page.tsx +36 -0
- package/src/plugins/blog/client/components/pages/post-page.internal.tsx +142 -0
- package/src/plugins/blog/client/components/pages/post-page.tsx +38 -0
- package/src/plugins/blog/client/components/pages/tag-page.internal.tsx +74 -0
- package/src/plugins/blog/client/components/pages/tag-page.tsx +38 -0
- package/src/plugins/blog/client/components/shared/better-blog-attribution.tsx +19 -0
- package/src/plugins/blog/client/components/shared/default-error.tsx +20 -0
- package/src/plugins/blog/client/components/shared/defaults.tsx +9 -0
- package/src/plugins/blog/client/components/shared/empty-list.tsx +25 -0
- package/src/plugins/blog/client/components/shared/error-placeholder.tsx +20 -0
- package/src/plugins/blog/client/components/shared/highlight-text.tsx +80 -0
- package/src/plugins/blog/client/components/shared/markdown-content-styles.css +328 -0
- package/src/plugins/blog/client/components/shared/markdown-content.tsx +448 -0
- package/src/plugins/blog/client/components/shared/on-this-page.tsx +234 -0
- package/src/plugins/blog/client/components/shared/page-header.tsx +35 -0
- package/src/plugins/blog/client/components/shared/page-layout.tsx +23 -0
- package/src/plugins/blog/client/components/shared/page-wrapper.tsx +32 -0
- package/src/plugins/blog/client/components/shared/post-card.tsx +308 -0
- package/src/plugins/blog/client/components/shared/post-navigation.tsx +98 -0
- package/src/plugins/blog/client/components/shared/posts-list.tsx +67 -0
- package/src/plugins/blog/client/components/shared/recent-posts-carousel.tsx +79 -0
- package/src/plugins/blog/client/components/shared/search-input.tsx +146 -0
- package/src/plugins/blog/client/components/shared/search-modal.tsx +162 -0
- package/src/plugins/blog/client/components/shared/tags-list.tsx +34 -0
- package/src/plugins/blog/client/components/shared/use-route-lifecycle.tsx +68 -0
- package/src/plugins/blog/client/hooks/blog-hooks.tsx +623 -0
- package/src/plugins/blog/client/hooks/index.tsx +1 -0
- package/src/plugins/blog/client/hooks/use-debounce.ts +43 -0
- package/src/plugins/blog/client/index.ts +9 -0
- package/src/plugins/blog/client/localization/blog-card.ts +3 -0
- package/src/plugins/blog/client/localization/blog-common.ts +7 -0
- package/src/plugins/blog/client/localization/blog-forms.ts +45 -0
- package/src/plugins/blog/client/localization/blog-list.ts +14 -0
- package/src/plugins/blog/client/localization/blog-post.ts +9 -0
- package/src/plugins/blog/client/localization/index.ts +15 -0
- package/src/plugins/blog/client/overrides.ts +123 -0
- package/src/plugins/blog/client/plugin.tsx +672 -0
- package/src/plugins/blog/client.css +3 -0
- package/src/plugins/blog/db.ts +90 -0
- package/src/plugins/blog/query-keys.ts +267 -0
- package/src/plugins/blog/schemas.ts +39 -0
- package/src/plugins/blog/style.css +22 -0
- package/src/plugins/blog/types.ts +37 -0
- package/src/plugins/blog/utils.ts +144 -0
- package/src/plugins/client/index.ts +53 -0
- package/src/plugins/index.ts +0 -0
- package/src/plugins/utils.ts +35 -0
- package/src/types.ts +209 -0
- package/dist/plugins/index.cjs +0 -15
- package/dist/plugins/index.d.cts +0 -64
- package/dist/plugins/index.d.mts +0 -64
- package/dist/plugins/index.d.ts +0 -64
- package/dist/plugins/index.mjs +0 -11
- package/dist/shared/stack.DrUAVfIH.d.cts +0 -17
- package/dist/shared/stack.DrUAVfIH.d.mts +0 -17
- package/dist/shared/stack.DrUAVfIH.d.ts +0 -17
- /package/dist/{shared/stack.CktCg4PJ.cjs → plugins/utils.cjs} +0 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const client = require('@btst/stack/plugins/client');
|
|
5
|
+
const reactQuery = require('@tanstack/react-query');
|
|
6
|
+
const useDebounce = require('./use-debounce.cjs');
|
|
7
|
+
const React = require('react');
|
|
8
|
+
const reactIntersectionObserver = require('react-intersection-observer');
|
|
9
|
+
const plugins_blog_queryKeys = require('../../query-keys.cjs');
|
|
10
|
+
const context = require('@btst/stack/context');
|
|
11
|
+
|
|
12
|
+
const SHARED_QUERY_CONFIG = {
|
|
13
|
+
retry: false,
|
|
14
|
+
refetchOnWindowFocus: false,
|
|
15
|
+
refetchOnMount: false,
|
|
16
|
+
refetchOnReconnect: false,
|
|
17
|
+
staleTime: 1e3 * 60 * 5,
|
|
18
|
+
// 5 minutes
|
|
19
|
+
gcTime: 1e3 * 60 * 10
|
|
20
|
+
// 10 minutes
|
|
21
|
+
};
|
|
22
|
+
function usePosts(options = {}) {
|
|
23
|
+
const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
|
|
24
|
+
const client$1 = client.createApiClient({
|
|
25
|
+
baseURL: apiBaseURL,
|
|
26
|
+
basePath: apiBasePath
|
|
27
|
+
});
|
|
28
|
+
const {
|
|
29
|
+
tag,
|
|
30
|
+
tagSlug,
|
|
31
|
+
limit = 10,
|
|
32
|
+
enabled = true,
|
|
33
|
+
query,
|
|
34
|
+
published
|
|
35
|
+
} = options;
|
|
36
|
+
const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
|
|
37
|
+
const queryParams = {
|
|
38
|
+
tag,
|
|
39
|
+
tagSlug,
|
|
40
|
+
limit,
|
|
41
|
+
query,
|
|
42
|
+
published
|
|
43
|
+
};
|
|
44
|
+
const basePosts = queries.posts.list(queryParams);
|
|
45
|
+
const {
|
|
46
|
+
data,
|
|
47
|
+
isLoading,
|
|
48
|
+
error,
|
|
49
|
+
fetchNextPage,
|
|
50
|
+
hasNextPage,
|
|
51
|
+
isFetchingNextPage,
|
|
52
|
+
refetch
|
|
53
|
+
} = reactQuery.useInfiniteQuery({
|
|
54
|
+
...basePosts,
|
|
55
|
+
...SHARED_QUERY_CONFIG,
|
|
56
|
+
initialPageParam: 0,
|
|
57
|
+
getNextPageParam: (lastPage, allPages) => {
|
|
58
|
+
const posts2 = lastPage;
|
|
59
|
+
if (posts2.length < limit) return void 0;
|
|
60
|
+
return allPages.length * limit;
|
|
61
|
+
},
|
|
62
|
+
enabled: enabled && !!client$1
|
|
63
|
+
});
|
|
64
|
+
const posts = data?.pages?.flat() ?? [];
|
|
65
|
+
return {
|
|
66
|
+
posts,
|
|
67
|
+
isLoading,
|
|
68
|
+
error,
|
|
69
|
+
loadMore: fetchNextPage,
|
|
70
|
+
hasMore: !!hasNextPage,
|
|
71
|
+
isLoadingMore: isFetchingNextPage,
|
|
72
|
+
refetch
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function useSuspensePosts(options = {}) {
|
|
76
|
+
const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
|
|
77
|
+
const client$1 = client.createApiClient({
|
|
78
|
+
baseURL: apiBaseURL,
|
|
79
|
+
basePath: apiBasePath
|
|
80
|
+
});
|
|
81
|
+
const {
|
|
82
|
+
tag,
|
|
83
|
+
tagSlug,
|
|
84
|
+
limit = 10,
|
|
85
|
+
enabled = true,
|
|
86
|
+
query,
|
|
87
|
+
published
|
|
88
|
+
} = options;
|
|
89
|
+
const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
|
|
90
|
+
const queryParams = { tag, tagSlug, limit, query, published };
|
|
91
|
+
const basePosts = queries.posts.list(queryParams);
|
|
92
|
+
const {
|
|
93
|
+
data,
|
|
94
|
+
fetchNextPage,
|
|
95
|
+
hasNextPage,
|
|
96
|
+
isFetchingNextPage,
|
|
97
|
+
refetch,
|
|
98
|
+
error,
|
|
99
|
+
isFetching
|
|
100
|
+
} = reactQuery.useSuspenseInfiniteQuery({
|
|
101
|
+
...basePosts,
|
|
102
|
+
...SHARED_QUERY_CONFIG,
|
|
103
|
+
initialPageParam: 0,
|
|
104
|
+
getNextPageParam: (lastPage, allPages) => {
|
|
105
|
+
const posts2 = lastPage;
|
|
106
|
+
if (posts2.length < limit) return void 0;
|
|
107
|
+
return allPages.length * limit;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
if (error && !isFetching) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
const posts = data.pages?.flat() ?? [];
|
|
114
|
+
return {
|
|
115
|
+
posts,
|
|
116
|
+
loadMore: fetchNextPage,
|
|
117
|
+
hasMore: !!hasNextPage,
|
|
118
|
+
isLoadingMore: isFetchingNextPage,
|
|
119
|
+
refetch
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function usePost(slug) {
|
|
123
|
+
const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
|
|
124
|
+
const client$1 = client.createApiClient({
|
|
125
|
+
baseURL: apiBaseURL,
|
|
126
|
+
basePath: apiBasePath
|
|
127
|
+
});
|
|
128
|
+
const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
|
|
129
|
+
const basePost = queries.posts.detail(slug ?? "");
|
|
130
|
+
const { data, isLoading, error, refetch } = reactQuery.useQuery({
|
|
131
|
+
...basePost,
|
|
132
|
+
...SHARED_QUERY_CONFIG,
|
|
133
|
+
enabled: !!client$1 && !!slug
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
post: data || null,
|
|
137
|
+
isLoading,
|
|
138
|
+
error,
|
|
139
|
+
refetch
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function useSuspensePost(slug) {
|
|
143
|
+
const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
|
|
144
|
+
const client$1 = client.createApiClient({
|
|
145
|
+
baseURL: apiBaseURL,
|
|
146
|
+
basePath: apiBasePath
|
|
147
|
+
});
|
|
148
|
+
const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
|
|
149
|
+
const basePost = queries.posts.detail(slug);
|
|
150
|
+
const { data, refetch, error, isFetching } = reactQuery.useSuspenseQuery({
|
|
151
|
+
...basePost,
|
|
152
|
+
...SHARED_QUERY_CONFIG
|
|
153
|
+
});
|
|
154
|
+
if (error && !isFetching) {
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
return { post: data || null, refetch };
|
|
158
|
+
}
|
|
159
|
+
function useTags() {
|
|
160
|
+
const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
|
|
161
|
+
const client$1 = client.createApiClient({
|
|
162
|
+
baseURL: apiBaseURL,
|
|
163
|
+
basePath: apiBasePath
|
|
164
|
+
});
|
|
165
|
+
const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
|
|
166
|
+
const baseTags = queries.tags.list();
|
|
167
|
+
const { data, isLoading, error, refetch } = reactQuery.useQuery({
|
|
168
|
+
...baseTags,
|
|
169
|
+
...SHARED_QUERY_CONFIG,
|
|
170
|
+
enabled: !!client$1
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
tags: data ?? [],
|
|
174
|
+
isLoading,
|
|
175
|
+
error,
|
|
176
|
+
refetch
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function useSuspenseTags() {
|
|
180
|
+
const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
|
|
181
|
+
const client$1 = client.createApiClient({
|
|
182
|
+
baseURL: apiBaseURL,
|
|
183
|
+
basePath: apiBasePath
|
|
184
|
+
});
|
|
185
|
+
const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
|
|
186
|
+
const baseTags = queries.tags.list();
|
|
187
|
+
const { data, refetch, error, isFetching } = reactQuery.useSuspenseQuery({
|
|
188
|
+
...baseTags,
|
|
189
|
+
...SHARED_QUERY_CONFIG
|
|
190
|
+
});
|
|
191
|
+
if (error && !isFetching) {
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
tags: data ?? [],
|
|
196
|
+
refetch
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function useCreatePost() {
|
|
200
|
+
const { refresh, apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
|
|
201
|
+
const client$1 = client.createApiClient({
|
|
202
|
+
baseURL: apiBaseURL,
|
|
203
|
+
basePath: apiBasePath
|
|
204
|
+
});
|
|
205
|
+
const queryClient = reactQuery.useQueryClient();
|
|
206
|
+
const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
|
|
207
|
+
return reactQuery.useMutation({
|
|
208
|
+
mutationKey: [...queries.posts._def, "create"],
|
|
209
|
+
mutationFn: async (postData) => {
|
|
210
|
+
const response = await client$1("@post/posts", {
|
|
211
|
+
method: "POST",
|
|
212
|
+
body: postData
|
|
213
|
+
});
|
|
214
|
+
return response.data;
|
|
215
|
+
},
|
|
216
|
+
onSuccess: async (created) => {
|
|
217
|
+
if (created?.slug) {
|
|
218
|
+
queryClient.setQueryData(
|
|
219
|
+
queries.posts.detail(created.slug).queryKey,
|
|
220
|
+
created
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
await queryClient.invalidateQueries({
|
|
224
|
+
queryKey: queries.posts.list._def
|
|
225
|
+
});
|
|
226
|
+
await queryClient.invalidateQueries({
|
|
227
|
+
queryKey: queries.drafts.list._def
|
|
228
|
+
});
|
|
229
|
+
if (refresh) {
|
|
230
|
+
await refresh();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function useUpdatePost() {
|
|
236
|
+
const { refresh, apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
|
|
237
|
+
const client$1 = client.createApiClient({
|
|
238
|
+
baseURL: apiBaseURL,
|
|
239
|
+
basePath: apiBasePath
|
|
240
|
+
});
|
|
241
|
+
const queryClient = reactQuery.useQueryClient();
|
|
242
|
+
const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
|
|
243
|
+
return reactQuery.useMutation({
|
|
244
|
+
mutationKey: [...queries.posts._def, "update"],
|
|
245
|
+
mutationFn: async ({ id, data }) => {
|
|
246
|
+
const response = await client$1(`@put/posts/:id`, {
|
|
247
|
+
method: "PUT",
|
|
248
|
+
params: { id },
|
|
249
|
+
body: data
|
|
250
|
+
});
|
|
251
|
+
return response.data;
|
|
252
|
+
},
|
|
253
|
+
onSuccess: async (updated) => {
|
|
254
|
+
if (updated?.slug) {
|
|
255
|
+
queryClient.setQueryData(
|
|
256
|
+
queries.posts.detail(updated.slug).queryKey,
|
|
257
|
+
updated
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
await queryClient.invalidateQueries({
|
|
261
|
+
queryKey: queries.posts.list._def
|
|
262
|
+
});
|
|
263
|
+
await queryClient.invalidateQueries({
|
|
264
|
+
queryKey: queries.drafts.list._def
|
|
265
|
+
});
|
|
266
|
+
if (refresh) {
|
|
267
|
+
await refresh();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function usePostSearch({
|
|
273
|
+
query,
|
|
274
|
+
enabled = true,
|
|
275
|
+
debounceMs = 300,
|
|
276
|
+
limit = 10,
|
|
277
|
+
published = true
|
|
278
|
+
}) {
|
|
279
|
+
const debouncedQuery = useDebounce.useDebounce(query, debounceMs);
|
|
280
|
+
const shouldSearch = enabled && (query?.trim().length ?? 0) > 0;
|
|
281
|
+
const lastResultsRef = React.useRef([]);
|
|
282
|
+
const { posts, isLoading, error, refetch } = usePosts({
|
|
283
|
+
query: debouncedQuery,
|
|
284
|
+
limit,
|
|
285
|
+
enabled: shouldSearch && debouncedQuery.trim() !== "",
|
|
286
|
+
published
|
|
287
|
+
});
|
|
288
|
+
const effectivePosts = shouldSearch ? posts : [];
|
|
289
|
+
React.useEffect(() => {
|
|
290
|
+
if (!isLoading && posts && posts.length >= 0) {
|
|
291
|
+
lastResultsRef.current = posts;
|
|
292
|
+
}
|
|
293
|
+
}, [posts, isLoading]);
|
|
294
|
+
const isDebouncing = enabled && debounceMs > 0 && debouncedQuery !== query;
|
|
295
|
+
const effectiveLoading = isLoading || isDebouncing;
|
|
296
|
+
const dataToReturn = !shouldSearch ? [] : effectiveLoading ? lastResultsRef.current : effectivePosts;
|
|
297
|
+
return {
|
|
298
|
+
posts: dataToReturn,
|
|
299
|
+
// compatibility alias similar to tanstack useQuery
|
|
300
|
+
data: dataToReturn,
|
|
301
|
+
isLoading: effectiveLoading,
|
|
302
|
+
error,
|
|
303
|
+
refetch,
|
|
304
|
+
isSearching: effectiveLoading,
|
|
305
|
+
searchQuery: debouncedQuery
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function useNextPreviousPosts(createdAt, options = {}) {
|
|
309
|
+
const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
|
|
310
|
+
const client$1 = client.createApiClient({
|
|
311
|
+
baseURL: apiBaseURL,
|
|
312
|
+
basePath: apiBasePath
|
|
313
|
+
});
|
|
314
|
+
const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
|
|
315
|
+
const { ref, inView } = reactIntersectionObserver.useInView({
|
|
316
|
+
// start a little early so the data is ready as it scrolls in
|
|
317
|
+
rootMargin: "200px 0px",
|
|
318
|
+
// run once; keep data cached after
|
|
319
|
+
triggerOnce: true
|
|
320
|
+
});
|
|
321
|
+
const dateValue = typeof createdAt === "string" ? new Date(createdAt) : createdAt;
|
|
322
|
+
const baseQuery = queries.posts.nextPrevious(dateValue);
|
|
323
|
+
const { data, isLoading, error, refetch } = reactQuery.useQuery({
|
|
324
|
+
...baseQuery,
|
|
325
|
+
...SHARED_QUERY_CONFIG,
|
|
326
|
+
enabled: (options.enabled ?? true) && inView && !!client$1
|
|
327
|
+
});
|
|
328
|
+
return {
|
|
329
|
+
previousPost: data?.previous ?? null,
|
|
330
|
+
nextPost: data?.next ?? null,
|
|
331
|
+
isLoading,
|
|
332
|
+
error,
|
|
333
|
+
refetch,
|
|
334
|
+
ref,
|
|
335
|
+
inView
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function useRecentPosts(options = {}) {
|
|
339
|
+
const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
|
|
340
|
+
const client$1 = client.createApiClient({
|
|
341
|
+
baseURL: apiBaseURL,
|
|
342
|
+
basePath: apiBasePath
|
|
343
|
+
});
|
|
344
|
+
const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
|
|
345
|
+
const { ref, inView } = reactIntersectionObserver.useInView({
|
|
346
|
+
// start a little early so the data is ready as it scrolls in
|
|
347
|
+
rootMargin: "200px 0px",
|
|
348
|
+
// run once; keep data cached after
|
|
349
|
+
triggerOnce: true
|
|
350
|
+
});
|
|
351
|
+
const baseQuery = queries.posts.recent({
|
|
352
|
+
limit: options.limit ?? 5,
|
|
353
|
+
excludeSlug: options.excludeSlug
|
|
354
|
+
});
|
|
355
|
+
const { data, isLoading, error, refetch } = reactQuery.useQuery({
|
|
356
|
+
...baseQuery,
|
|
357
|
+
...SHARED_QUERY_CONFIG,
|
|
358
|
+
enabled: (options.enabled ?? true) && inView && !!client$1
|
|
359
|
+
});
|
|
360
|
+
return {
|
|
361
|
+
recentPosts: data ?? [],
|
|
362
|
+
isLoading,
|
|
363
|
+
error,
|
|
364
|
+
refetch,
|
|
365
|
+
ref,
|
|
366
|
+
inView
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
exports.useCreatePost = useCreatePost;
|
|
371
|
+
exports.useNextPreviousPosts = useNextPreviousPosts;
|
|
372
|
+
exports.usePost = usePost;
|
|
373
|
+
exports.usePostSearch = usePostSearch;
|
|
374
|
+
exports.usePosts = usePosts;
|
|
375
|
+
exports.useRecentPosts = useRecentPosts;
|
|
376
|
+
exports.useSuspensePost = useSuspensePost;
|
|
377
|
+
exports.useSuspensePosts = useSuspensePosts;
|
|
378
|
+
exports.useSuspenseTags = useSuspenseTags;
|
|
379
|
+
exports.useTags = useTags;
|
|
380
|
+
exports.useUpdatePost = useUpdatePost;
|