@bbki.ng/site 2.0.17 → 2.0.19

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 2.0.19
4
+
5
+ ## 2.0.18
6
+
3
7
  ## 2.0.17
4
8
 
5
9
  ## 2.0.16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "2.0.17",
3
+ "version": "2.0.19",
4
4
  "description": "code behind bbki.ng",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/blog/app.tsx CHANGED
@@ -26,6 +26,8 @@ import { PluginInit } from "@/components/plugin/PluginInit";
26
26
  import { BBContext } from "@/context/bbcontext";
27
27
  import { PluginContentPage } from "@/components/plugin/PluginContentPage";
28
28
  import { PluginRoutes } from "@/components/plugin/PluginRoutes";
29
+ import {useClipboardToPost} from "@/hooks/use_clipboard_to_post";
30
+ import {useSharedStringToPost} from "@/hooks/use_shared_string_to_post";
29
31
 
30
32
  const Layout = () => {
31
33
  const { isLoading, isFontLoading } = useContext(GlobalLoadingContext);
@@ -54,7 +56,6 @@ const Layout = () => {
54
56
 
55
57
  const NowInMidCol = threeColWrapper(NowPage);
56
58
  const ContentInMidCol = threeColWrapper(Txt);
57
- const ProjectsInMidCol = threeColWrapper(Png);
58
59
  const ArticleInMidCol = threeColWrapper(ArticlePage);
59
60
  const TagsInMidCol = threeColWrapper(Tags);
60
61
  const LoginInMidCol = threeColWrapper(Login);
@@ -62,7 +63,12 @@ const TagsResultInMidCol = threeColWrapper(TagsResult);
62
63
  const CoverInMidCol = threeColWrapper(Cover);
63
64
 
64
65
  export const App = () => {
65
- return (
66
+
67
+ useClipboardToPost();
68
+
69
+ useSharedStringToPost();
70
+
71
+ return (
66
72
  <SWR>
67
73
  {/*<EffectContextProvider>*/}
68
74
  <HotKeyNav>
@@ -0,0 +1,22 @@
1
+ import { ContextMenuItem } from "@bbki.ng/components";
2
+ import React from "react";
3
+ import {useAuthedStringPost} from "@/hooks/use_authed_string_post";
4
+
5
+ export const PostMenuItem = () => {
6
+
7
+ const post = useAuthedStringPost();
8
+
9
+ const postFromClipboard = () => {
10
+ navigator.clipboard
11
+ .readText()
12
+ .then(post);
13
+ }
14
+
15
+ return (
16
+ <ContextMenuItem onClick={postFromClipboard}
17
+ inset
18
+ >
19
+ post from clipboard
20
+ </ContextMenuItem>
21
+ );
22
+ };
@@ -13,6 +13,7 @@ import { ViewSourceMenuItem } from "@/components/app_ctx_menu/ViewSourceMenuItem
13
13
  import { PluginsMenuItem } from "@/components/plugin/PluginsMenuItem";
14
14
  import { PluginManager } from "@/plugin/PluginManager";
15
15
  import { PluginEvent } from "@/plugin/PluginEvent";
16
+ import {PostMenuItem} from "@/components/app_ctx_menu/PostMenuItem";
16
17
 
17
18
  export const AppCtxMenu = (props: { children: ReactElement }) => {
18
19
  const [showPluginEntry, setShowPluginEntry] = React.useState(false);
@@ -35,6 +36,7 @@ export const AppCtxMenu = (props: { children: ReactElement }) => {
35
36
  <ContextMenuContent className="w-256">
36
37
  <LoginMenuItem />
37
38
  <ViewSourceMenuItem />
39
+ <PostMenuItem />
38
40
  {/*{showPluginEntry && <PluginsMenuItem />}*/}
39
41
  </ContextMenuContent>
40
42
  </ContextMenu>
@@ -0,0 +1,42 @@
1
+ import {useSWRConfig} from "swr";
2
+ import {useAuthed} from "@/hooks/use_authed";
3
+ import {useContext} from "react";
4
+ import {GlobalLoadingContext} from "@/context/global_loading_state_provider";
5
+ import {usePost} from "@/hooks/use_post";
6
+ import {splitPost} from "@/utils";
7
+ import {API} from "@/constants/routes";
8
+
9
+ export const useAuthedStringPost = () => {
10
+ const { mutate } = useSWRConfig();
11
+
12
+ const isKing = useAuthed();
13
+
14
+ const { setIsLoading } = useContext(GlobalLoadingContext);
15
+
16
+ const post = usePost();
17
+
18
+ return (content: string) => {
19
+ if (!content) {
20
+ return;
21
+ }
22
+
23
+ if (!isKing) {
24
+ return;
25
+ }
26
+
27
+ const postObj = splitPost(content);
28
+ if (!postObj?.content || !postObj?.title) {
29
+ return;
30
+ }
31
+
32
+ setIsLoading(true);
33
+
34
+ post(postObj.title, postObj.content)
35
+ .then((r) => {
36
+ mutate(API.POSTS).then();
37
+ })
38
+ .finally(() => {
39
+ setIsLoading(false);
40
+ });
41
+ }
42
+ }
@@ -5,6 +5,7 @@ export const useClipboardContent = () => {
5
5
 
6
6
  React.useEffect(() => {
7
7
  const handlePaste = (event: ClipboardEvent) => {
8
+
8
9
  if (event.clipboardData) {
9
10
  setClipboardContent(event.clipboardData.getData("text/plain"));
10
11
  }
@@ -17,5 +18,7 @@ export const useClipboardContent = () => {
17
18
  };
18
19
  }, []);
19
20
 
21
+ console.log(clipboardContent);
22
+
20
23
  return clipboardContent;
21
24
  }
@@ -0,0 +1,23 @@
1
+ import {useEffect} from "react";
2
+ import {useAuthedStringPost} from "@/hooks/use_authed_string_post";
3
+
4
+ export const useSharedStringToPost = () => {
5
+ const post = useAuthedStringPost();
6
+
7
+ useEffect(() => {
8
+ const handleSharedString = (event: MessageEvent) => {
9
+ if (event.data && typeof event.data === "string") {
10
+ const content = event.data;
11
+ if (content) {
12
+ post(content);
13
+ }
14
+ }
15
+ }
16
+
17
+ window.addEventListener("message", handleSharedString);
18
+
19
+ return () => {
20
+ window.removeEventListener("message", handleSharedString);
21
+ }
22
+ }, []);
23
+ }
@@ -5,7 +5,6 @@ import { usePosts } from "@/hooks/use_posts";
5
5
  import { CenterLinkList } from "@/components";
6
6
  import { useAuthed } from "@/hooks/use_authed";
7
7
  import { useFile2Post } from "@/hooks/use_file_to_post";
8
- import { DelayFadeIn } from "@/components/DelayFadeIn/DelayFadeIn";
9
8
  import { useSafeArticleLoading } from "@/hooks/use_safe_loading";
10
9
  import {useClipboardToPost} from "@/hooks/use_clipboard_to_post";
11
10
 
@@ -41,13 +40,8 @@ export default (props: TxtProps) => {
41
40
  const reader = useFile2Post();
42
41
  const isKing = useAuthed();
43
42
 
44
- useClipboardToPost();
45
-
46
43
  return (
47
44
  <DropZone onDrop={reader} disabled={!isKing}>
48
- {isKing && (
49
- <div contentEditable={true} className="p-2 focus-visible:outline-0" />
50
- )}
51
45
  <Posts {...props} />
52
46
  </DropZone>
53
47
  );
@@ -173,6 +173,18 @@ export const confirm = (message: string, exec: () => void) => {
173
173
  });
174
174
  };
175
175
 
176
+ export const splitPost= (wholeString: string ) => {
177
+ const firstLine = wholeString ? wholeString .split("\n")[0] : "";
178
+ const title = firstLine ? firstLine.trim() : "";
179
+
180
+ const restContent = wholeString ? wholeString.slice(title.length).trim() : "";
181
+
182
+ return {
183
+ title,
184
+ content: restContent,
185
+ };
186
+ }
187
+
176
188
  export const changeFont = (type: FontType) => {
177
189
  const rootDiv = document.getElementById("root");
178
190
  if (rootDiv == null) {
package/vite.config.js CHANGED
@@ -84,6 +84,19 @@ export default defineConfig({
84
84
  },
85
85
  },
86
86
  },
87
+ {
88
+ urlPattern: /new-content-handler/,
89
+ method: "GET",
90
+ handler: ({ event, data }) => {
91
+ const url = new URL(event.request.url);
92
+ const sharedContent = url.searchParams.get("content");
93
+
94
+ // post the shared content to the main thread
95
+ if (sharedContent) {
96
+ window.postMessage(sharedContent, {})
97
+ }
98
+ },
99
+ },
87
100
  {
88
101
  urlPattern: /^https:\/\/fonts\.gstatic.com\.com\/.*/i,
89
102
  handler: "CacheFirst",
@@ -102,8 +115,15 @@ export default defineConfig({
102
115
  },
103
116
  manifest: {
104
117
  name: "bbki.ng",
105
- description: "words, pictures.",
118
+ description: "A personal blog.",
106
119
  theme_color: "#ffffff",
120
+ "share_target": {
121
+ "action": "/new-content-handler/",
122
+ "method": "GET",
123
+ "params": {
124
+ "text": "content",
125
+ }
126
+ },
107
127
  icons: [
108
128
  {
109
129
  src: "pwa-192x192.png",