@waline/client 2.0.0 → 2.0.3

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.
Files changed (50) hide show
  1. package/dist/component.js +1 -1
  2. package/dist/component.js.map +1 -1
  3. package/dist/legacy.js +1 -1
  4. package/dist/legacy.js.map +1 -1
  5. package/dist/pageview.cjs.js +1 -1
  6. package/dist/pageview.d.ts +1 -1
  7. package/dist/pageview.esm.js +1 -1
  8. package/dist/pageview.js +1 -1
  9. package/dist/shim.d.ts +30 -5
  10. package/dist/shim.esm.d.ts +30 -5
  11. package/dist/shim.esm.js +1 -1
  12. package/dist/shim.esm.js.map +1 -1
  13. package/dist/shim.js +1 -1
  14. package/dist/shim.js.map +1 -1
  15. package/dist/waline.cjs.d.ts +30 -5
  16. package/dist/waline.cjs.js +1 -1
  17. package/dist/waline.cjs.js.map +1 -1
  18. package/dist/waline.css +1 -1
  19. package/dist/waline.css.map +1 -1
  20. package/dist/waline.d.ts +30 -5
  21. package/dist/waline.esm.d.ts +30 -5
  22. package/dist/waline.esm.js +1 -1
  23. package/dist/waline.esm.js.map +1 -1
  24. package/dist/waline.js +1 -1
  25. package/dist/waline.js.map +1 -1
  26. package/package.json +15 -8
  27. package/src/comment.ts +1 -1
  28. package/src/compact/convert.ts +1 -1
  29. package/src/components/CommentBox.vue +15 -22
  30. package/src/components/CommentCard.vue +6 -3
  31. package/src/components/Waline.vue +6 -28
  32. package/src/composables/index.ts +1 -1
  33. package/src/composables/inputs.ts +9 -21
  34. package/src/composables/timeAgo.ts +61 -0
  35. package/src/composables/userInfo.ts +14 -21
  36. package/src/config/default.ts +2 -2
  37. package/src/entrys/legacy.ts +2 -2
  38. package/src/init.ts +1 -1
  39. package/src/styles/layout.scss +1 -1
  40. package/src/styles/panel.scss +0 -2
  41. package/src/typings/options.ts +1 -1
  42. package/src/utils/date.ts +17 -0
  43. package/src/utils/emoji.ts +8 -6
  44. package/src/utils/{data.ts → image.ts} +0 -0
  45. package/src/utils/index.ts +2 -3
  46. package/src/utils/markdown.ts +1 -1
  47. package/src/widgets/recentComments.ts +35 -5
  48. package/src/composables/store.ts +0 -38
  49. package/src/utils/timeAgo.ts +0 -75
  50. package/src/utils/userInfo.ts +0 -26
@@ -1,15 +1,44 @@
1
- import { fetchRecentComment, getRoot, getUserInfo } from '../utils';
1
+ import { useUserInfo } from '../composables';
2
+ import { fetchRecentComment, getRoot } from '../utils';
2
3
 
3
4
  import type { WalineComment } from '../typings';
4
5
 
5
- export interface RecentCommentsOptions {
6
+ export interface WalineRecentCommentsOptions {
7
+ /**
8
+ * Waline 服务端地址
9
+ *
10
+ * Waline serverURL
11
+ */
6
12
  serverURL: string;
13
+
14
+ /**
15
+ * 获取最新评论的数量
16
+ *
17
+ * fetch number of latest comments
18
+ */
7
19
  count: number;
20
+
21
+ /**
22
+ * 需要挂载的元素
23
+ *
24
+ * Element to be mounted
25
+ */
8
26
  el?: string | HTMLElement;
9
27
  }
10
28
 
11
- export interface RecentCommentsResult {
29
+ export interface WalineRecentCommentsResult {
30
+ /**
31
+ * 评论数据
32
+ *
33
+ * Comment Data
34
+ */
12
35
  comments: WalineComment[];
36
+
37
+ /**
38
+ * 取消挂载挂件
39
+ *
40
+ * Umount widget
41
+ */
13
42
  destroy: () => void;
14
43
  }
15
44
 
@@ -17,7 +46,8 @@ export const RecentComments = ({
17
46
  el,
18
47
  serverURL,
19
48
  count,
20
- }: RecentCommentsOptions): Promise<RecentCommentsResult> => {
49
+ }: WalineRecentCommentsOptions): Promise<WalineRecentCommentsResult> => {
50
+ const userInfo = useUserInfo();
21
51
  const root = getRoot(el);
22
52
  const controller = new AbortController();
23
53
 
@@ -25,7 +55,7 @@ export const RecentComments = ({
25
55
  serverURL,
26
56
  count,
27
57
  signal: controller.signal,
28
- token: getUserInfo()?.token,
58
+ token: userInfo.value?.token,
29
59
  }).then((comments) => {
30
60
  if (root && comments.length) {
31
61
  root.innerHTML = `<ul class="wl-recent-list">${comments
@@ -1,38 +0,0 @@
1
- export interface Store {
2
- get: <T = unknown>(key: string) => T | null;
3
- set: <T = unknown>(key: string, content: T) => void;
4
- update: <T = unknown>(content: T) => void;
5
- }
6
-
7
- export const useStore = (cacheKey: string): Store => {
8
- let storage: Record<string, unknown> = {};
9
- const content = localStorage.getItem(cacheKey);
10
-
11
- if (content) {
12
- try {
13
- storage = JSON.parse(content) as Record<string, unknown>;
14
- } catch (err) {
15
- // do nothing
16
- }
17
- }
18
-
19
- return {
20
- get: <T>(key: string): T | null => (storage[key] as T) || null,
21
-
22
- set<T>(key: string, content: T): void {
23
- try {
24
- // make sure the content can be stringify and make a deep copy here
25
- storage[key] = JSON.parse(JSON.stringify(content));
26
- localStorage.setItem(cacheKey, JSON.stringify(storage));
27
- } catch (err) {
28
- // do nothing
29
- }
30
- },
31
-
32
- update<T>(content: T): void {
33
- // make sure the content can be stringify and make a deep copy here
34
- storage = JSON.parse(JSON.stringify(content)) as Record<string, unknown>;
35
- localStorage.setItem(cacheKey, JSON.stringify(storage));
36
- },
37
- };
38
- };
@@ -1,75 +0,0 @@
1
- import type { WalineLocale } from '../typings';
2
-
3
- const padWithZeros = (vNumber: number, width: number): string => {
4
- let numAsString = vNumber.toString();
5
-
6
- while (numAsString.length < width) {
7
- numAsString = '0' + numAsString;
8
- }
9
-
10
- return numAsString;
11
- };
12
-
13
- const dateFormat = (date: Date): string => {
14
- const vDay = padWithZeros(date.getDate(), 2);
15
- const vMonth = padWithZeros(date.getMonth() + 1, 2);
16
- const vYear = padWithZeros(date.getFullYear(), 2);
17
-
18
- return `${vYear}-${vMonth}-${vDay}`;
19
- };
20
-
21
- export const timeAgo = (date: Date | string, locale: WalineLocale): string => {
22
- if (date)
23
- try {
24
- if (typeof date === 'string') {
25
- // compat with mysql output date
26
- date = new Date(
27
- date.indexOf(' ') !== -1 ? date.replace(/-/g, '/') : date
28
- );
29
- }
30
- const oldTime = date.getTime();
31
- const currTime = new Date().getTime();
32
- const diffValue = currTime - oldTime;
33
-
34
- const days = Math.floor(diffValue / (24 * 3600 * 1000));
35
-
36
- // 计算相差小时数
37
- if (days === 0) {
38
- // 计算天数后剩余的毫秒数
39
- const leave1 = diffValue % (24 * 3600 * 1000);
40
- const hours = Math.floor(leave1 / (3600 * 1000));
41
-
42
- //计算相差分钟数
43
- if (hours === 0) {
44
- // 计算小时数后剩余的毫秒数
45
- const leave2 = leave1 % (3600 * 1000);
46
- const minutes = Math.floor(leave2 / (60 * 1000));
47
-
48
- // 计算相差秒数
49
- if (minutes === 0) {
50
- // 计算分钟数后剩余的毫秒数
51
- const leave3 = leave2 % (60 * 1000);
52
- const seconds = Math.round(leave3 / 1000);
53
-
54
- return `${seconds} ${locale.seconds}`;
55
- }
56
- return `${minutes} ${locale.minutes}`;
57
- }
58
- return `${hours} ${locale.hours}`;
59
- }
60
-
61
- if (days < 0) {
62
- return locale.now;
63
- }
64
-
65
- if (days < 8) {
66
- return `${days} ${locale.days}`;
67
- } else {
68
- return dateFormat(date);
69
- }
70
- } catch (error) {
71
- console.log(error);
72
- }
73
-
74
- return '';
75
- };
@@ -1,26 +0,0 @@
1
- export interface UserInfo {
2
- // eslint-disable-next-line @typescript-eslint/naming-convention
3
- display_name: string;
4
- email: string;
5
- url: string;
6
- token: string;
7
- avatar: string;
8
- mailMd5: string;
9
- }
10
-
11
- const USER_KEY = 'WALINE_USER';
12
-
13
- export const getUserInfo = (): UserInfo | null => {
14
- try {
15
- const localStorageData = localStorage.getItem(USER_KEY);
16
- const sessionStorageData = sessionStorage.getItem(USER_KEY);
17
-
18
- return localStorageData
19
- ? (JSON.parse(localStorageData) as UserInfo)
20
- : sessionStorageData
21
- ? (JSON.parse(sessionStorageData) as UserInfo)
22
- : null;
23
- } catch (err) {
24
- return null;
25
- }
26
- };