@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,131 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { Button } from '@workspace/ui/components/button';
|
|
3
|
+
import { FormItem, FormLabel, FormControl, FormDescription, FormMessage } from '@workspace/ui/components/form';
|
|
4
|
+
import { Input } from '@workspace/ui/components/input';
|
|
5
|
+
import { usePluginOverrides } from '@btst/stack/context';
|
|
6
|
+
import { Loader2, Upload } from 'lucide-react';
|
|
7
|
+
import { useRef, useState } from 'react';
|
|
8
|
+
import { toast } from 'sonner';
|
|
9
|
+
import { BLOG_LOCALIZATION } from '../../localization/index.mjs';
|
|
10
|
+
|
|
11
|
+
function FeaturedImageField({
|
|
12
|
+
isRequired,
|
|
13
|
+
value,
|
|
14
|
+
onChange,
|
|
15
|
+
setFeaturedImageUploading
|
|
16
|
+
}) {
|
|
17
|
+
const fileInputRef = useRef(null);
|
|
18
|
+
const [isUploading, setIsUploading] = useState(false);
|
|
19
|
+
const { uploadImage, Image, localization } = usePluginOverrides("blog", { localization: BLOG_LOCALIZATION });
|
|
20
|
+
const ImageComponent = Image ? Image : DefaultImage;
|
|
21
|
+
const handleImageUpload = async (event) => {
|
|
22
|
+
const file = event.target.files?.[0];
|
|
23
|
+
if (!file) return;
|
|
24
|
+
if (!file.type.startsWith("image/")) {
|
|
25
|
+
toast.error(localization.BLOG_FORMS_FEATURED_IMAGE_ERROR_NOT_IMAGE);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (file.size > 4 * 1024 * 1024) {
|
|
29
|
+
toast.error(localization.BLOG_FORMS_FEATURED_IMAGE_ERROR_TOO_LARGE);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
setIsUploading(true);
|
|
34
|
+
setFeaturedImageUploading(true);
|
|
35
|
+
const url = await uploadImage(file);
|
|
36
|
+
onChange(url);
|
|
37
|
+
toast.success(localization.BLOG_FORMS_FEATURED_IMAGE_TOAST_SUCCESS);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
toast.error(localization.BLOG_FORMS_FEATURED_IMAGE_TOAST_FAILURE);
|
|
40
|
+
console.error("Failed to upload image:", error);
|
|
41
|
+
toast.error(localization.BLOG_FORMS_FEATURED_IMAGE_TOAST_FAILURE);
|
|
42
|
+
} finally {
|
|
43
|
+
setIsUploading(false);
|
|
44
|
+
setFeaturedImageUploading(false);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return /* @__PURE__ */ jsxs(FormItem, { className: "flex flex-col", children: [
|
|
48
|
+
/* @__PURE__ */ jsxs(FormLabel, { children: [
|
|
49
|
+
localization.BLOG_FORMS_FEATURED_IMAGE_LABEL,
|
|
50
|
+
isRequired && /* @__PURE__ */ jsxs("span", { className: "text-destructive", children: [
|
|
51
|
+
" ",
|
|
52
|
+
localization.BLOG_FORMS_FEATURED_IMAGE_REQUIRED_ASTERISK
|
|
53
|
+
] })
|
|
54
|
+
] }),
|
|
55
|
+
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
56
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
57
|
+
/* @__PURE__ */ jsx(
|
|
58
|
+
Input,
|
|
59
|
+
{
|
|
60
|
+
placeholder: localization.BLOG_FORMS_FEATURED_IMAGE_INPUT_PLACEHOLDER,
|
|
61
|
+
value: value || "",
|
|
62
|
+
onChange: (e) => onChange(e.target.value),
|
|
63
|
+
disabled: isUploading
|
|
64
|
+
}
|
|
65
|
+
),
|
|
66
|
+
/* @__PURE__ */ jsx(
|
|
67
|
+
Button,
|
|
68
|
+
{
|
|
69
|
+
type: "button",
|
|
70
|
+
variant: "outline",
|
|
71
|
+
onClick: () => fileInputRef.current?.click(),
|
|
72
|
+
disabled: isUploading,
|
|
73
|
+
children: isUploading ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
74
|
+
/* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }),
|
|
75
|
+
localization.BLOG_FORMS_FEATURED_IMAGE_UPLOADING_BUTTON
|
|
76
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
77
|
+
/* @__PURE__ */ jsx(Upload, { className: "mr-2 h-4 w-4" }),
|
|
78
|
+
localization.BLOG_FORMS_FEATURED_IMAGE_UPLOAD_BUTTON
|
|
79
|
+
] })
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
] }),
|
|
83
|
+
/* @__PURE__ */ jsx(
|
|
84
|
+
"input",
|
|
85
|
+
{
|
|
86
|
+
ref: fileInputRef,
|
|
87
|
+
type: "file",
|
|
88
|
+
accept: "image/*",
|
|
89
|
+
onChange: handleImageUpload,
|
|
90
|
+
className: "hidden"
|
|
91
|
+
}
|
|
92
|
+
),
|
|
93
|
+
isUploading && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-muted-foreground text-sm", children: [
|
|
94
|
+
/* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
|
|
95
|
+
localization.BLOG_FORMS_FEATURED_IMAGE_UPLOADING_TEXT
|
|
96
|
+
] }),
|
|
97
|
+
value && !isUploading && /* @__PURE__ */ jsx("div", { className: "relative", children: /* @__PURE__ */ jsx(
|
|
98
|
+
ImageComponent,
|
|
99
|
+
{
|
|
100
|
+
src: value,
|
|
101
|
+
alt: localization.BLOG_FORMS_FEATURED_IMAGE_PREVIEW_ALT,
|
|
102
|
+
className: "h-auto w-full max-w-xs rounded-md border",
|
|
103
|
+
width: 400,
|
|
104
|
+
height: 400
|
|
105
|
+
}
|
|
106
|
+
) })
|
|
107
|
+
] }) }),
|
|
108
|
+
/* @__PURE__ */ jsx(FormDescription, {}),
|
|
109
|
+
/* @__PURE__ */ jsx(FormMessage, {})
|
|
110
|
+
] });
|
|
111
|
+
}
|
|
112
|
+
function DefaultImage({
|
|
113
|
+
src,
|
|
114
|
+
alt,
|
|
115
|
+
className,
|
|
116
|
+
width,
|
|
117
|
+
height
|
|
118
|
+
}) {
|
|
119
|
+
return /* @__PURE__ */ jsx(
|
|
120
|
+
"img",
|
|
121
|
+
{
|
|
122
|
+
src,
|
|
123
|
+
alt,
|
|
124
|
+
className,
|
|
125
|
+
width,
|
|
126
|
+
height
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { FeaturedImageField };
|
|
@@ -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,106 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const crepe = require('@milkdown/crepe');
|
|
6
|
+
require('@milkdown/crepe/theme/common/style.css');
|
|
7
|
+
const utils = require('../../../utils.cjs');
|
|
8
|
+
const core = require('@milkdown/kit/core');
|
|
9
|
+
const listener = require('@milkdown/kit/plugin/listener');
|
|
10
|
+
const model = require('@milkdown/kit/prose/model');
|
|
11
|
+
const state = require('@milkdown/kit/prose/state');
|
|
12
|
+
const React = require('react');
|
|
13
|
+
const context = require('@btst/stack/context');
|
|
14
|
+
const index = require('../../localization/index.cjs');
|
|
15
|
+
|
|
16
|
+
function MarkdownEditor({
|
|
17
|
+
value,
|
|
18
|
+
onChange,
|
|
19
|
+
className
|
|
20
|
+
}) {
|
|
21
|
+
const { uploadImage, localization } = context.usePluginOverrides("blog", {
|
|
22
|
+
localization: index.BLOG_LOCALIZATION
|
|
23
|
+
});
|
|
24
|
+
const containerRef = React.useRef(null);
|
|
25
|
+
const crepeRef = React.useRef(null);
|
|
26
|
+
const isReadyRef = React.useRef(false);
|
|
27
|
+
const [isReady, setIsReady] = React.useState(false);
|
|
28
|
+
const onChangeRef = React.useRef(onChange);
|
|
29
|
+
const initialValueRef = React.useRef(value ?? "");
|
|
30
|
+
const throttledOnChangeRef = React.useRef(null);
|
|
31
|
+
onChangeRef.current = onChange;
|
|
32
|
+
React.useLayoutEffect(() => {
|
|
33
|
+
if (crepeRef.current) return;
|
|
34
|
+
const container = containerRef.current;
|
|
35
|
+
if (!container) return;
|
|
36
|
+
const crepe$1 = new crepe.Crepe({
|
|
37
|
+
root: container,
|
|
38
|
+
defaultValue: initialValueRef.current,
|
|
39
|
+
featureConfigs: {
|
|
40
|
+
[crepe.CrepeFeature.Placeholder]: {
|
|
41
|
+
text: localization.BLOG_FORMS_EDITOR_PLACEHOLDER
|
|
42
|
+
},
|
|
43
|
+
[crepe.CrepeFeature.ImageBlock]: {
|
|
44
|
+
onUpload: async (file) => {
|
|
45
|
+
const url = await uploadImage(file);
|
|
46
|
+
return url;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
throttledOnChangeRef.current = utils.throttle((markdown) => {
|
|
52
|
+
if (onChangeRef.current) onChangeRef.current(markdown);
|
|
53
|
+
}, 200);
|
|
54
|
+
crepe$1.editor.config((ctx) => {
|
|
55
|
+
ctx.get(listener.listenerCtx).markdownUpdated((_, markdown) => {
|
|
56
|
+
throttledOnChangeRef.current?.(markdown);
|
|
57
|
+
});
|
|
58
|
+
}).use(listener.listener);
|
|
59
|
+
crepe$1.create().then(() => {
|
|
60
|
+
isReadyRef.current = true;
|
|
61
|
+
setIsReady(true);
|
|
62
|
+
});
|
|
63
|
+
crepeRef.current = crepe$1;
|
|
64
|
+
return () => {
|
|
65
|
+
try {
|
|
66
|
+
isReadyRef.current = false;
|
|
67
|
+
throttledOnChangeRef.current?.cancel?.();
|
|
68
|
+
throttledOnChangeRef.current = null;
|
|
69
|
+
crepe$1.destroy();
|
|
70
|
+
} finally {
|
|
71
|
+
crepeRef.current = null;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}, []);
|
|
75
|
+
React.useLayoutEffect(() => {
|
|
76
|
+
if (!isReady) return;
|
|
77
|
+
if (!crepeRef.current) return;
|
|
78
|
+
if (typeof value !== "string") return;
|
|
79
|
+
let currentMarkdown;
|
|
80
|
+
try {
|
|
81
|
+
currentMarkdown = crepeRef.current?.getMarkdown?.();
|
|
82
|
+
} catch {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (currentMarkdown === value) return;
|
|
86
|
+
crepeRef.current.editor.action((ctx) => {
|
|
87
|
+
const view = ctx.get(core.editorViewCtx);
|
|
88
|
+
if (view?.hasFocus?.() === true) return;
|
|
89
|
+
const parser = ctx.get(core.parserCtx);
|
|
90
|
+
const doc = parser(value);
|
|
91
|
+
if (!doc) return;
|
|
92
|
+
const state$1 = view.state;
|
|
93
|
+
const selection = state$1.selection;
|
|
94
|
+
const from = selection.from;
|
|
95
|
+
let tr = state$1.tr;
|
|
96
|
+
tr = tr.replace(0, state$1.doc.content.size, new model.Slice(doc.content, 0, 0));
|
|
97
|
+
const docSize = doc.content.size;
|
|
98
|
+
const safeFrom = Math.max(1, Math.min(from, Math.max(1, docSize - 2)));
|
|
99
|
+
tr = tr.setSelection(state.Selection.near(tr.doc.resolve(safeFrom)));
|
|
100
|
+
view.dispatch(tr);
|
|
101
|
+
});
|
|
102
|
+
}, [value, isReady]);
|
|
103
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: containerRef, className: utils.cn("milkdown-custom", className) });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
exports.MarkdownEditor = MarkdownEditor;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Crepe, CrepeFeature } from '@milkdown/crepe';
|
|
4
|
+
import '@milkdown/crepe/theme/common/style.css';
|
|
5
|
+
import { throttle, cn } from '../../../utils.mjs';
|
|
6
|
+
import { editorViewCtx, parserCtx } from '@milkdown/kit/core';
|
|
7
|
+
import { listenerCtx, listener } from '@milkdown/kit/plugin/listener';
|
|
8
|
+
import { Slice } from '@milkdown/kit/prose/model';
|
|
9
|
+
import { Selection } from '@milkdown/kit/prose/state';
|
|
10
|
+
import { useRef, useState, useLayoutEffect } from 'react';
|
|
11
|
+
import { usePluginOverrides } from '@btst/stack/context';
|
|
12
|
+
import { BLOG_LOCALIZATION } from '../../localization/index.mjs';
|
|
13
|
+
|
|
14
|
+
function MarkdownEditor({
|
|
15
|
+
value,
|
|
16
|
+
onChange,
|
|
17
|
+
className
|
|
18
|
+
}) {
|
|
19
|
+
const { uploadImage, localization } = usePluginOverrides("blog", {
|
|
20
|
+
localization: BLOG_LOCALIZATION
|
|
21
|
+
});
|
|
22
|
+
const containerRef = useRef(null);
|
|
23
|
+
const crepeRef = useRef(null);
|
|
24
|
+
const isReadyRef = useRef(false);
|
|
25
|
+
const [isReady, setIsReady] = useState(false);
|
|
26
|
+
const onChangeRef = useRef(onChange);
|
|
27
|
+
const initialValueRef = useRef(value ?? "");
|
|
28
|
+
const throttledOnChangeRef = useRef(null);
|
|
29
|
+
onChangeRef.current = onChange;
|
|
30
|
+
useLayoutEffect(() => {
|
|
31
|
+
if (crepeRef.current) return;
|
|
32
|
+
const container = containerRef.current;
|
|
33
|
+
if (!container) return;
|
|
34
|
+
const crepe = new Crepe({
|
|
35
|
+
root: container,
|
|
36
|
+
defaultValue: initialValueRef.current,
|
|
37
|
+
featureConfigs: {
|
|
38
|
+
[CrepeFeature.Placeholder]: {
|
|
39
|
+
text: localization.BLOG_FORMS_EDITOR_PLACEHOLDER
|
|
40
|
+
},
|
|
41
|
+
[CrepeFeature.ImageBlock]: {
|
|
42
|
+
onUpload: async (file) => {
|
|
43
|
+
const url = await uploadImage(file);
|
|
44
|
+
return url;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
throttledOnChangeRef.current = throttle((markdown) => {
|
|
50
|
+
if (onChangeRef.current) onChangeRef.current(markdown);
|
|
51
|
+
}, 200);
|
|
52
|
+
crepe.editor.config((ctx) => {
|
|
53
|
+
ctx.get(listenerCtx).markdownUpdated((_, markdown) => {
|
|
54
|
+
throttledOnChangeRef.current?.(markdown);
|
|
55
|
+
});
|
|
56
|
+
}).use(listener);
|
|
57
|
+
crepe.create().then(() => {
|
|
58
|
+
isReadyRef.current = true;
|
|
59
|
+
setIsReady(true);
|
|
60
|
+
});
|
|
61
|
+
crepeRef.current = crepe;
|
|
62
|
+
return () => {
|
|
63
|
+
try {
|
|
64
|
+
isReadyRef.current = false;
|
|
65
|
+
throttledOnChangeRef.current?.cancel?.();
|
|
66
|
+
throttledOnChangeRef.current = null;
|
|
67
|
+
crepe.destroy();
|
|
68
|
+
} finally {
|
|
69
|
+
crepeRef.current = null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}, []);
|
|
73
|
+
useLayoutEffect(() => {
|
|
74
|
+
if (!isReady) return;
|
|
75
|
+
if (!crepeRef.current) return;
|
|
76
|
+
if (typeof value !== "string") return;
|
|
77
|
+
let currentMarkdown;
|
|
78
|
+
try {
|
|
79
|
+
currentMarkdown = crepeRef.current?.getMarkdown?.();
|
|
80
|
+
} catch {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (currentMarkdown === value) return;
|
|
84
|
+
crepeRef.current.editor.action((ctx) => {
|
|
85
|
+
const view = ctx.get(editorViewCtx);
|
|
86
|
+
if (view?.hasFocus?.() === true) return;
|
|
87
|
+
const parser = ctx.get(parserCtx);
|
|
88
|
+
const doc = parser(value);
|
|
89
|
+
if (!doc) return;
|
|
90
|
+
const state = view.state;
|
|
91
|
+
const selection = state.selection;
|
|
92
|
+
const from = selection.from;
|
|
93
|
+
let tr = state.tr;
|
|
94
|
+
tr = tr.replace(0, state.doc.content.size, new Slice(doc.content, 0, 0));
|
|
95
|
+
const docSize = doc.content.size;
|
|
96
|
+
const safeFrom = Math.max(1, Math.min(from, Math.max(1, docSize - 2)));
|
|
97
|
+
tr = tr.setSelection(Selection.near(tr.doc.resolve(safeFrom)));
|
|
98
|
+
view.dispatch(tr);
|
|
99
|
+
});
|
|
100
|
+
}, [value, isReady]);
|
|
101
|
+
return /* @__PURE__ */ jsx("div", { ref: containerRef, className: cn("milkdown-custom", className) });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { MarkdownEditor };
|