@waline/client 2.4.0 → 2.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waline/client",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "client for waline comment system",
5
5
  "keywords": [
6
6
  "valine",
@@ -56,15 +56,6 @@
56
56
  "dist",
57
57
  "src"
58
58
  ],
59
- "scripts": {
60
- "build": "pnpm rollup && pnpm style",
61
- "clean": "rimraf ./dist",
62
- "dev": "vite -c config/vite.config.js",
63
- "lint": "eslint --ext .ts,.vue .",
64
- "prepublish": "pnpm clean && pnpm build",
65
- "rollup": "rollup -c ./config/rollup.config.js",
66
- "style": "sass ./src/styles/index.scss ./dist/waline.css --style=compressed"
67
- },
68
59
  "browserslist": {
69
60
  "production": [
70
61
  ">0.5%",
@@ -86,12 +77,36 @@
86
77
  "vue": "^3.2.33"
87
78
  },
88
79
  "devDependencies": {
80
+ "@babel/core": "^7.17.10",
81
+ "@babel/preset-env": "^7.17.10",
82
+ "@rollup/plugin-babel": "^5.3.1",
83
+ "@rollup/plugin-commonjs": "^22.0.0",
84
+ "@rollup/plugin-node-resolve": "^13.3.0",
85
+ "@rollup/plugin-replace": "^4.0.0",
89
86
  "@types/autosize": "^4.0.1",
90
87
  "@types/marked": "^4.0.3",
88
+ "@types/node": "^17.0.31",
91
89
  "@vitejs/plugin-vue": "^2.3.2",
90
+ "@vue/compiler-sfc": "^3.2.33",
91
+ "rimraf": "^3.0.2",
92
+ "rollup": "^2.72.1",
93
+ "rollup-plugin-dts": "^4.2.1",
94
+ "rollup-plugin-terser": "^7.0.2",
95
+ "rollup-plugin-ts": "^2.0.7",
96
+ "rollup-plugin-vue": "^6.0.0",
97
+ "typescript": "^4.6.4",
92
98
  "vite": "^2.9.8"
93
99
  },
94
100
  "engines": {
95
- "node": ">=12.20.0"
101
+ "node": ">=14"
102
+ },
103
+ "scripts": {
104
+ "build": "pnpm rollup && pnpm style",
105
+ "clean": "rimraf ./dist",
106
+ "dev": "vite -c config/vite.config.js",
107
+ "lint": "eslint --ext .ts,.vue .",
108
+ "prepublish": "pnpm clean && pnpm build",
109
+ "rollup": "rollup -c ./config/rollup.config.js",
110
+ "style": "sass ./src/styles/index.scss ./dist/waline.css --style=compressed"
96
111
  }
97
- }
112
+ }
@@ -31,31 +31,33 @@
31
31
  />
32
32
  <span class="wl-time" v-text="time" />
33
33
 
34
- <button
35
- class="wl-reply"
36
- :class="{ active: isReplyingCurrent }"
37
- :title="isReplyingCurrent ? locale.cancelReply : locale.reply"
38
- @click="$emit('reply', isReplyingCurrent ? null : comment)"
39
- >
40
- <ReplyIcon />
41
- </button>
34
+ <div class="wl-comment-actions">
35
+ <button
36
+ class="wl-delete"
37
+ v-if="isAdmin || isOwner"
38
+ @click="$emit('delete', comment)"
39
+ >
40
+ <DeleteIcon />
41
+ </button>
42
42
 
43
- <button
44
- class="wl-like"
45
- @click="$emit('like', comment)"
46
- :title="like ? locale.cancelLike : locale.like"
47
- >
48
- <LikeIcon :active="like" />
49
- <span v-if="'like' in comment" v-text="comment.like" />
50
- </button>
43
+ <button
44
+ class="wl-like"
45
+ @click="$emit('like', comment)"
46
+ :title="like ? locale.cancelLike : locale.like"
47
+ >
48
+ <LikeIcon :active="like" />
49
+ <span v-if="'like' in comment" v-text="comment.like" />
50
+ </button>
51
51
 
52
- <button
53
- class="wl-delete"
54
- v-if="isAdmin || isOwner"
55
- @click="$emit('delete', comment)"
56
- >
57
- <DeleteIcon />
58
- </button>
52
+ <button
53
+ class="wl-reply"
54
+ :class="{ active: isReplyingCurrent }"
55
+ :title="isReplyingCurrent ? locale.cancelReply : locale.reply"
56
+ @click="$emit('reply', isReplyingCurrent ? null : comment)"
57
+ >
58
+ <ReplyIcon />
59
+ </button>
60
+ </div>
59
61
  </div>
60
62
  <div class="wl-meta" aria-hidden="true">
61
63
  <span v-if="comment.addr" v-text="comment.addr" />
@@ -104,6 +106,7 @@
104
106
  @reply="$emit('reply', $event)"
105
107
  @submit="$emit('submit', $event)"
106
108
  @like="$emit('like', $event)"
109
+ @delete="$emit('delete', $event)"
107
110
  @status="$emit('status', $event)"
108
111
  @sticky="$emit('sticky', $event)"
109
112
  />
@@ -312,7 +312,8 @@ export default defineComponent({
312
312
  objectId: comment.objectId,
313
313
  status,
314
314
  });
315
- // todo: render comment list
315
+
316
+ comment.status = status;
316
317
  };
317
318
 
318
319
  const onSticky = async (comment: WalineComment): Promise<void> => {
@@ -327,10 +328,11 @@ export default defineComponent({
327
328
  objectId: comment.objectId,
328
329
  sticky: comment.sticky ? 0 : 1,
329
330
  });
330
- // todo: render comment list
331
+
332
+ comment.sticky = !comment.sticky;
331
333
  };
332
334
 
333
- const onDelete = async (comment: WalineComment): Promise<void> => {
335
+ const onDelete = async ({ objectId }: WalineComment): Promise<void> => {
334
336
  if (!confirm('Are you sure you want to delete this comment?')) return;
335
337
 
336
338
  const { serverURL, lang } = config.value;
@@ -339,30 +341,50 @@ export default defineComponent({
339
341
  serverURL,
340
342
  lang,
341
343
  token: userInfo.value?.token,
342
- objectId: comment.objectId,
344
+ objectId: objectId,
345
+ });
346
+
347
+ // delete comment from data
348
+ data.value.some((item, index) => {
349
+ if (item.objectId === objectId) {
350
+ data.value = data.value.filter((_item, i) => i !== index);
351
+
352
+ return true;
353
+ }
354
+
355
+ return item.children.some((child, childIndex) => {
356
+ if (child.objectId === objectId) {
357
+ data.value[index].children = item.children.filter(
358
+ (_item, i) => i !== childIndex
359
+ );
360
+
361
+ return true;
362
+ }
363
+
364
+ return false;
365
+ });
343
366
  });
344
- // todo render comment list
345
367
  };
346
368
 
347
369
  const onLike = async (comment: WalineComment): Promise<void> => {
348
370
  const { serverURL, lang } = config.value;
349
- const hasLiked = likeStorage.value.includes(comment.objectId);
371
+ const { objectId } = comment;
372
+ const hasLiked = likeStorage.value.includes(objectId);
350
373
 
351
374
  await likeComment({
352
375
  serverURL,
353
376
  lang,
354
- objectId: comment.objectId,
377
+ objectId,
355
378
  like: !hasLiked,
356
379
  });
357
380
 
358
381
  if (hasLiked)
359
- likeStorage.value = likeStorage.value.filter(
360
- (id) => id !== comment.objectId
361
- );
382
+ likeStorage.value = likeStorage.value.filter((id) => id !== objectId);
362
383
  else {
363
- likeStorage.value.push(comment.objectId);
384
+ likeStorage.value = [...likeStorage.value, objectId];
364
385
 
365
- if (likeStorage.value.length > 50) likeStorage.value.slice(-50);
386
+ if (likeStorage.value.length > 50)
387
+ likeStorage.value = likeStorage.value.slice(-50);
366
388
  }
367
389
 
368
390
  comment.like = (comment.like || 0) + (hasLiked ? -1 : 1);
@@ -1,4 +1,4 @@
1
1
  export * from './inputs';
2
2
  export * from './timeAgo';
3
3
  export * from './userInfo';
4
- export * from './likeStorage';
4
+ export * from './like';
@@ -8,4 +8,7 @@ export type LikeID = number | string;
8
8
 
9
9
  export type LikeRef = Ref<LikeID[]>;
10
10
 
11
- export const useLikeStorage = (): LikeRef => useStorage<LikeID[]>(LIKE_KEY, []);
11
+ let likeStorage: LikeRef | null = null;
12
+
13
+ export const useLikeStorage = (): LikeRef =>
14
+ likeStorage || (likeStorage = useStorage<LikeID[]>(LIKE_KEY, []));
@@ -18,5 +18,11 @@ export const USER_KEY = 'WALINE_USER';
18
18
 
19
19
  export type UserInfoRef = Ref<UserInfo | Record<string, never>>;
20
20
 
21
+ let userInfoStorage: UserInfoRef | null = null;
22
+
21
23
  export const useUserInfo = (): UserInfoRef =>
22
- useStorage<UserInfo | Record<string, never>>('USER_KEY', {});
24
+ userInfoStorage ||
25
+ (userInfoStorage = useStorage<UserInfo | Record<string, never>>(
26
+ 'USER_KEY',
27
+ {}
28
+ ));
@@ -18,13 +18,13 @@
18
18
  .wl-user {
19
19
  --avatar-size: var(--waline-avatar-size);
20
20
 
21
+ position: relative;
22
+ margin-right: 0.75em;
23
+
21
24
  @media (max-width: 720px) {
22
25
  --avatar-size: var(--waline-m-avatar-size);
23
26
  }
24
27
 
25
- position: relative;
26
- margin-right: 0.75em;
27
-
28
28
  img {
29
29
  width: var(--avatar-size);
30
30
  height: var(--avatar-size);
@@ -101,32 +101,6 @@
101
101
  font-size: 0.75em;
102
102
  }
103
103
 
104
- .wl-delete,
105
- .wl-like,
106
- .wl-reply {
107
- float: right;
108
-
109
- padding: 4px;
110
- border: none;
111
-
112
- background: transparent;
113
- color: var(--waline-color);
114
-
115
- line-height: 1;
116
-
117
- cursor: pointer;
118
-
119
- transition: color 0.2s ease;
120
-
121
- &:hover {
122
- color: var(--waline-theme-color);
123
- }
124
-
125
- &.active {
126
- color: var(--waline-active-color);
127
- }
128
- }
129
-
130
104
  .wl-meta {
131
105
  position: relative;
132
106
  line-height: 1;
@@ -154,6 +128,36 @@
154
128
  }
155
129
  }
156
130
 
131
+ .wl-comment-actions {
132
+ float: right;
133
+ }
134
+
135
+ .wl-delete,
136
+ .wl-like,
137
+ .wl-reply {
138
+ display: inline-flex;
139
+ align-items: center;
140
+ padding: 4px;
141
+ border: none;
142
+
143
+ background: transparent;
144
+ color: var(--waline-color);
145
+
146
+ line-height: 1;
147
+
148
+ cursor: pointer;
149
+
150
+ transition: color 0.2s ease;
151
+
152
+ &:hover {
153
+ color: var(--waline-theme-color);
154
+ }
155
+
156
+ &.active {
157
+ color: var(--waline-active-color);
158
+ }
159
+ }
160
+
157
161
  .wl-content {
158
162
  position: relative;
159
163
 
@@ -217,8 +221,8 @@
217
221
 
218
222
  .wl-admin-actions {
219
223
  margin: 8px 0;
220
- text-align: right;
221
224
  font-size: 12px;
225
+ text-align: right;
222
226
  }
223
227
 
224
228
  .wl-comment-status {
@@ -19,7 +19,6 @@
19
19
  color: var(--waline-theme-color);
20
20
 
21
21
  text-decoration: none;
22
-
23
22
  word-break: break-word;
24
23
 
25
24
  cursor: pointer;
@@ -196,7 +196,6 @@
196
196
  .wl-content {
197
197
  min-height: 1.25em;
198
198
  padding: 0.25em;
199
-
200
199
  word-break: break-word;
201
200
  hyphens: auto;
202
201