@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,165 @@
|
|
|
1
|
+
import { Button } from "@workspace/ui/components/button";
|
|
2
|
+
import {
|
|
3
|
+
FormControl,
|
|
4
|
+
FormDescription,
|
|
5
|
+
FormItem,
|
|
6
|
+
FormLabel,
|
|
7
|
+
FormMessage,
|
|
8
|
+
} from "@workspace/ui/components/form";
|
|
9
|
+
import { Input } from "@workspace/ui/components/input";
|
|
10
|
+
import { usePluginOverrides } from "@btst/stack/context";
|
|
11
|
+
import { Loader2, Upload } from "lucide-react";
|
|
12
|
+
import { useRef, useState } from "react";
|
|
13
|
+
import { toast } from "sonner";
|
|
14
|
+
import type { BlogPluginOverrides } from "../../overrides";
|
|
15
|
+
import { BLOG_LOCALIZATION } from "../../localization";
|
|
16
|
+
|
|
17
|
+
export function FeaturedImageField({
|
|
18
|
+
isRequired,
|
|
19
|
+
value,
|
|
20
|
+
onChange,
|
|
21
|
+
setFeaturedImageUploading,
|
|
22
|
+
}: {
|
|
23
|
+
isRequired?: boolean;
|
|
24
|
+
value?: string;
|
|
25
|
+
onChange: (value: string) => void;
|
|
26
|
+
setFeaturedImageUploading: (uploading: boolean) => void;
|
|
27
|
+
}) {
|
|
28
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
29
|
+
const [isUploading, setIsUploading] = useState(false);
|
|
30
|
+
|
|
31
|
+
const { uploadImage, Image, localization } = usePluginOverrides<
|
|
32
|
+
BlogPluginOverrides,
|
|
33
|
+
Partial<BlogPluginOverrides>
|
|
34
|
+
>("blog", { localization: BLOG_LOCALIZATION });
|
|
35
|
+
|
|
36
|
+
const ImageComponent = Image ? Image : DefaultImage;
|
|
37
|
+
|
|
38
|
+
const handleImageUpload = async (
|
|
39
|
+
event: React.ChangeEvent<HTMLInputElement>,
|
|
40
|
+
) => {
|
|
41
|
+
const file = event.target.files?.[0];
|
|
42
|
+
if (!file) return;
|
|
43
|
+
|
|
44
|
+
if (!file.type.startsWith("image/")) {
|
|
45
|
+
toast.error(localization.BLOG_FORMS_FEATURED_IMAGE_ERROR_NOT_IMAGE);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (file.size > 4 * 1024 * 1024) {
|
|
50
|
+
toast.error(localization.BLOG_FORMS_FEATURED_IMAGE_ERROR_TOO_LARGE);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
setIsUploading(true);
|
|
56
|
+
setFeaturedImageUploading(true);
|
|
57
|
+
const url = await uploadImage(file);
|
|
58
|
+
onChange(url);
|
|
59
|
+
toast.success(localization.BLOG_FORMS_FEATURED_IMAGE_TOAST_SUCCESS);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
toast.error(localization.BLOG_FORMS_FEATURED_IMAGE_TOAST_FAILURE);
|
|
62
|
+
console.error("Failed to upload image:", error);
|
|
63
|
+
toast.error(localization.BLOG_FORMS_FEATURED_IMAGE_TOAST_FAILURE);
|
|
64
|
+
} finally {
|
|
65
|
+
setIsUploading(false);
|
|
66
|
+
setFeaturedImageUploading(false);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<FormItem className="flex flex-col">
|
|
72
|
+
<FormLabel>
|
|
73
|
+
{localization.BLOG_FORMS_FEATURED_IMAGE_LABEL}
|
|
74
|
+
{isRequired && (
|
|
75
|
+
<span className="text-destructive">
|
|
76
|
+
{" "}
|
|
77
|
+
{localization.BLOG_FORMS_FEATURED_IMAGE_REQUIRED_ASTERISK}
|
|
78
|
+
</span>
|
|
79
|
+
)}
|
|
80
|
+
</FormLabel>
|
|
81
|
+
<FormControl>
|
|
82
|
+
<div className="space-y-2">
|
|
83
|
+
<div className="flex gap-2">
|
|
84
|
+
<Input
|
|
85
|
+
placeholder={
|
|
86
|
+
localization.BLOG_FORMS_FEATURED_IMAGE_INPUT_PLACEHOLDER
|
|
87
|
+
}
|
|
88
|
+
value={value || ""}
|
|
89
|
+
onChange={(e) => onChange(e.target.value)}
|
|
90
|
+
disabled={isUploading}
|
|
91
|
+
/>
|
|
92
|
+
<Button
|
|
93
|
+
type="button"
|
|
94
|
+
variant="outline"
|
|
95
|
+
onClick={() => fileInputRef.current?.click()}
|
|
96
|
+
disabled={isUploading}
|
|
97
|
+
>
|
|
98
|
+
{isUploading ? (
|
|
99
|
+
<>
|
|
100
|
+
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
101
|
+
{localization.BLOG_FORMS_FEATURED_IMAGE_UPLOADING_BUTTON}
|
|
102
|
+
</>
|
|
103
|
+
) : (
|
|
104
|
+
<>
|
|
105
|
+
<Upload className="mr-2 h-4 w-4" />
|
|
106
|
+
{localization.BLOG_FORMS_FEATURED_IMAGE_UPLOAD_BUTTON}
|
|
107
|
+
</>
|
|
108
|
+
)}
|
|
109
|
+
</Button>
|
|
110
|
+
</div>
|
|
111
|
+
<input
|
|
112
|
+
ref={fileInputRef}
|
|
113
|
+
type="file"
|
|
114
|
+
accept="image/*"
|
|
115
|
+
onChange={handleImageUpload}
|
|
116
|
+
className="hidden"
|
|
117
|
+
/>
|
|
118
|
+
{isUploading && (
|
|
119
|
+
<div className="flex items-center gap-2 text-muted-foreground text-sm">
|
|
120
|
+
<Loader2 className="h-4 w-4 animate-spin" />
|
|
121
|
+
{localization.BLOG_FORMS_FEATURED_IMAGE_UPLOADING_TEXT}
|
|
122
|
+
</div>
|
|
123
|
+
)}
|
|
124
|
+
{value && !isUploading && (
|
|
125
|
+
<div className="relative">
|
|
126
|
+
<ImageComponent
|
|
127
|
+
src={value}
|
|
128
|
+
alt={localization.BLOG_FORMS_FEATURED_IMAGE_PREVIEW_ALT}
|
|
129
|
+
className="h-auto w-full max-w-xs rounded-md border"
|
|
130
|
+
width={400}
|
|
131
|
+
height={400}
|
|
132
|
+
/>
|
|
133
|
+
</div>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
</FormControl>
|
|
137
|
+
<FormDescription />
|
|
138
|
+
<FormMessage />
|
|
139
|
+
</FormItem>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function DefaultImage({
|
|
144
|
+
src,
|
|
145
|
+
alt,
|
|
146
|
+
className,
|
|
147
|
+
width,
|
|
148
|
+
height,
|
|
149
|
+
}: {
|
|
150
|
+
src: string;
|
|
151
|
+
alt: string;
|
|
152
|
+
className?: string;
|
|
153
|
+
width?: number;
|
|
154
|
+
height?: number;
|
|
155
|
+
}) {
|
|
156
|
+
return (
|
|
157
|
+
<img
|
|
158
|
+
src={src}
|
|
159
|
+
alt={alt}
|
|
160
|
+
className={className}
|
|
161
|
+
width={width}
|
|
162
|
+
height={height}
|
|
163
|
+
/>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
.milkdown-custom .milkdown {
|
|
2
|
+
border-radius: calc(var(--radius) - 2px);
|
|
3
|
+
--crepe-color-background: var(--background);
|
|
4
|
+
--crepe-color-surface: var(--background);
|
|
5
|
+
--crepe-color-surface-low: var(--muted);
|
|
6
|
+
--crepe-color-on-background: var(--foreground);
|
|
7
|
+
--crepe-color-on-surface: var(--secondary-foreground);
|
|
8
|
+
--crepe-color-on-surface-variant: var(--muted-foreground);
|
|
9
|
+
--crepe-color-primary: var(--primary);
|
|
10
|
+
--crepe-color-secondary: var(--secondary);
|
|
11
|
+
--crepe-color-on-secondary: var(--secondary-foreground);
|
|
12
|
+
--crepe-color-outline: var(--muted-foreground);
|
|
13
|
+
--crepe-color-inverse: var(--popover);
|
|
14
|
+
--crepe-color-on-inverse: var(--popover-foreground);
|
|
15
|
+
--crepe-color-inline-code: var(--secondary-foreground);
|
|
16
|
+
--crepe-color-error: var(--destructive);
|
|
17
|
+
--crepe-color-hover: var(--accent);
|
|
18
|
+
--crepe-color-selected: var(--secondary);
|
|
19
|
+
--crepe-color-inline-area: var(--secondary);
|
|
20
|
+
--crepe-font-title: var(--font-sans);
|
|
21
|
+
--crepe-font-default: var(--font-sans);
|
|
22
|
+
--crepe-font-code: var(--font-mono);
|
|
23
|
+
--crepe-shadow-1:
|
|
24
|
+
0px 1px 3px 1px color-mix(in oklch, var(--ring) 28%, transparent), 0px 1px
|
|
25
|
+
2px 0px color-mix(in oklch, var(--ring) 22%, transparent);
|
|
26
|
+
--crepe-shadow-2:
|
|
27
|
+
0px 2px 6px 2px color-mix(in oklch, var(--ring) 28%, transparent), 0px 1px
|
|
28
|
+
2px 0px color-mix(in oklch, var(--ring) 22%, transparent);
|
|
29
|
+
height: inherit;
|
|
30
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Crepe, CrepeFeature } from "@milkdown/crepe";
|
|
3
|
+
import "@milkdown/crepe/theme/common/style.css";
|
|
4
|
+
import "./markdown-editor-styles.css";
|
|
5
|
+
|
|
6
|
+
import { cn, throttle } from "../../../utils";
|
|
7
|
+
import { editorViewCtx, parserCtx } from "@milkdown/kit/core";
|
|
8
|
+
import { listener, listenerCtx } from "@milkdown/kit/plugin/listener";
|
|
9
|
+
import { Slice } from "@milkdown/kit/prose/model";
|
|
10
|
+
import { Selection } from "@milkdown/kit/prose/state";
|
|
11
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
12
|
+
import { usePluginOverrides } from "@btst/stack/context";
|
|
13
|
+
import type { BlogPluginOverrides } from "../../overrides";
|
|
14
|
+
import { BLOG_LOCALIZATION } from "../../localization";
|
|
15
|
+
|
|
16
|
+
export function MarkdownEditor({
|
|
17
|
+
value,
|
|
18
|
+
onChange,
|
|
19
|
+
className,
|
|
20
|
+
}: {
|
|
21
|
+
value?: string;
|
|
22
|
+
onChange?: (markdown: string) => void;
|
|
23
|
+
className?: string;
|
|
24
|
+
}) {
|
|
25
|
+
const { uploadImage, localization } = usePluginOverrides<
|
|
26
|
+
BlogPluginOverrides,
|
|
27
|
+
Partial<BlogPluginOverrides>
|
|
28
|
+
>("blog", {
|
|
29
|
+
localization: BLOG_LOCALIZATION,
|
|
30
|
+
});
|
|
31
|
+
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
32
|
+
const crepeRef = useRef<Crepe | null>(null);
|
|
33
|
+
const isReadyRef = useRef(false);
|
|
34
|
+
const [isReady, setIsReady] = useState(false);
|
|
35
|
+
const onChangeRef = useRef<typeof onChange>(onChange);
|
|
36
|
+
const initialValueRef = useRef<string>(value ?? "");
|
|
37
|
+
type ThrottledFn = ((markdown: string) => void) & {
|
|
38
|
+
cancel?: () => void;
|
|
39
|
+
flush?: () => void;
|
|
40
|
+
};
|
|
41
|
+
const throttledOnChangeRef = useRef<ThrottledFn | null>(null);
|
|
42
|
+
|
|
43
|
+
onChangeRef.current = onChange;
|
|
44
|
+
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
if (crepeRef.current) return;
|
|
47
|
+
const container = containerRef.current;
|
|
48
|
+
if (!container) return;
|
|
49
|
+
|
|
50
|
+
const crepe = new Crepe({
|
|
51
|
+
root: container,
|
|
52
|
+
defaultValue: initialValueRef.current,
|
|
53
|
+
featureConfigs: {
|
|
54
|
+
[CrepeFeature.Placeholder]: {
|
|
55
|
+
text: localization.BLOG_FORMS_EDITOR_PLACEHOLDER,
|
|
56
|
+
},
|
|
57
|
+
[CrepeFeature.ImageBlock]: {
|
|
58
|
+
onUpload: async (file) => {
|
|
59
|
+
const url = await uploadImage(file);
|
|
60
|
+
return url;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Prepare throttled onChange once per editor instance
|
|
67
|
+
throttledOnChangeRef.current = throttle((markdown: string) => {
|
|
68
|
+
if (onChangeRef.current) onChangeRef.current(markdown);
|
|
69
|
+
}, 200);
|
|
70
|
+
|
|
71
|
+
crepe.editor
|
|
72
|
+
.config((ctx) => {
|
|
73
|
+
ctx.get(listenerCtx).markdownUpdated((_, markdown) => {
|
|
74
|
+
throttledOnChangeRef.current?.(markdown);
|
|
75
|
+
});
|
|
76
|
+
})
|
|
77
|
+
.use(listener);
|
|
78
|
+
|
|
79
|
+
crepe.create().then(() => {
|
|
80
|
+
isReadyRef.current = true;
|
|
81
|
+
setIsReady(true);
|
|
82
|
+
});
|
|
83
|
+
crepeRef.current = crepe;
|
|
84
|
+
|
|
85
|
+
return () => {
|
|
86
|
+
try {
|
|
87
|
+
isReadyRef.current = false;
|
|
88
|
+
throttledOnChangeRef.current?.cancel?.();
|
|
89
|
+
throttledOnChangeRef.current = null;
|
|
90
|
+
crepe.destroy();
|
|
91
|
+
} finally {
|
|
92
|
+
crepeRef.current = null;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}, []);
|
|
96
|
+
|
|
97
|
+
useLayoutEffect(() => {
|
|
98
|
+
if (!isReady) return;
|
|
99
|
+
if (!crepeRef.current) return;
|
|
100
|
+
if (typeof value !== "string") return;
|
|
101
|
+
|
|
102
|
+
let currentMarkdown: string | undefined;
|
|
103
|
+
try {
|
|
104
|
+
currentMarkdown = crepeRef.current?.getMarkdown?.();
|
|
105
|
+
} catch {
|
|
106
|
+
// Editor may not have finished initializing its view/state; skip sync for now
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (currentMarkdown === value) return;
|
|
111
|
+
|
|
112
|
+
crepeRef.current.editor.action((ctx) => {
|
|
113
|
+
const view = ctx.get(editorViewCtx);
|
|
114
|
+
if (view?.hasFocus?.() === true) return;
|
|
115
|
+
const parser = ctx.get(parserCtx);
|
|
116
|
+
const doc = parser(value);
|
|
117
|
+
if (!doc) return;
|
|
118
|
+
|
|
119
|
+
const state = view.state;
|
|
120
|
+
const selection = state.selection;
|
|
121
|
+
const from = selection.from;
|
|
122
|
+
|
|
123
|
+
let tr = state.tr;
|
|
124
|
+
tr = tr.replace(0, state.doc.content.size, new Slice(doc.content, 0, 0));
|
|
125
|
+
|
|
126
|
+
const docSize = doc.content.size;
|
|
127
|
+
const safeFrom = Math.max(1, Math.min(from, Math.max(1, docSize - 2)));
|
|
128
|
+
tr = tr.setSelection(Selection.near(tr.doc.resolve(safeFrom)));
|
|
129
|
+
view.dispatch(tr);
|
|
130
|
+
});
|
|
131
|
+
}, [value, isReady]);
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div ref={containerRef} className={cn("milkdown-custom", className)} />
|
|
135
|
+
);
|
|
136
|
+
}
|