@waline/client 2.0.2 → 2.0.5
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/dist/component.js +1 -1
- package/dist/component.js.map +1 -1
- package/dist/legacy.js +1 -1
- package/dist/legacy.js.map +1 -1
- package/dist/pageview.cjs.js +1 -1
- package/dist/pageview.cjs.js.map +1 -1
- package/dist/pageview.esm.js +1 -1
- package/dist/pageview.esm.js.map +1 -1
- package/dist/pageview.js +1 -1
- package/dist/pageview.js.map +1 -1
- package/dist/shim.esm.js +1 -1
- package/dist/shim.esm.js.map +1 -1
- package/dist/shim.js +1 -1
- package/dist/shim.js.map +1 -1
- package/dist/waline.cjs.js +1 -1
- package/dist/waline.cjs.js.map +1 -1
- package/dist/waline.esm.js +1 -1
- package/dist/waline.esm.js.map +1 -1
- package/dist/waline.js +1 -1
- package/dist/waline.js.map +1 -1
- package/package.json +16 -8
- package/src/comment.ts +1 -1
- package/src/compact/convert.ts +1 -1
- package/src/components/CommentBox.vue +56 -55
- package/src/components/CommentCard.vue +10 -5
- package/src/components/Waline.vue +3 -29
- package/src/composables/index.ts +1 -1
- package/src/composables/inputs.ts +11 -22
- package/src/composables/timeAgo.ts +61 -0
- package/src/composables/userInfo.ts +14 -21
- package/src/entrys/legacy.ts +1 -1
- package/src/init.ts +1 -1
- package/src/pageview.ts +1 -1
- package/src/utils/config.ts +17 -30
- package/src/utils/date.ts +17 -0
- package/src/utils/emoji.ts +11 -9
- package/src/utils/{data.ts → image.ts} +0 -0
- package/src/utils/index.ts +2 -3
- package/src/widgets/recentComments.ts +4 -2
- package/src/composables/store.ts +0 -38
- package/src/utils/timeAgo.ts +0 -75
- package/src/utils/userInfo.ts +0 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waline/client",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "client for waline comment system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"valine",
|
|
@@ -9,9 +9,15 @@
|
|
|
9
9
|
"blog"
|
|
10
10
|
],
|
|
11
11
|
"repository": {
|
|
12
|
-
"url": "https://github.com/walinejs/waline"
|
|
12
|
+
"url": "https://github.com/walinejs/waline",
|
|
13
|
+
"directory": "packages/client"
|
|
13
14
|
},
|
|
14
15
|
"license": "MIT",
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Mr.Hope",
|
|
18
|
+
"email": "mister-hope@outlook.com",
|
|
19
|
+
"url": "https://mrhope.site"
|
|
20
|
+
},
|
|
15
21
|
"exports": {
|
|
16
22
|
".": {
|
|
17
23
|
"import": "./dist/shim.esm.js",
|
|
@@ -21,6 +27,7 @@
|
|
|
21
27
|
"./dist": "./dist/shim.js",
|
|
22
28
|
"./dist/waline.css": "./dist/waline.css",
|
|
23
29
|
"./dist/*": "./dist/*.js",
|
|
30
|
+
"./src/*": "./src/*",
|
|
24
31
|
"./package.json": "./package.json"
|
|
25
32
|
},
|
|
26
33
|
"main": "./dist/shim.js",
|
|
@@ -53,14 +60,15 @@
|
|
|
53
60
|
]
|
|
54
61
|
},
|
|
55
62
|
"dependencies": {
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
63
|
+
"@vueuse/core": "^8.3.1",
|
|
64
|
+
"autosize": "^5.0.1",
|
|
65
|
+
"hanabi": "^0.4.0",
|
|
66
|
+
"marked": "^4.0.14",
|
|
67
|
+
"vue": "^3.2.33"
|
|
60
68
|
},
|
|
61
69
|
"devDependencies": {
|
|
62
|
-
"@types/autosize": "4.0.1",
|
|
63
|
-
"@types/marked": "4.0.3"
|
|
70
|
+
"@types/autosize": "^4.0.1",
|
|
71
|
+
"@types/marked": "^4.0.3"
|
|
64
72
|
},
|
|
65
73
|
"engines": {
|
|
66
74
|
"node": ">=12.20.0"
|
package/src/comment.ts
CHANGED
|
@@ -40,7 +40,7 @@ WalineCommentCountOptions): WalineAbort => {
|
|
|
40
40
|
// comment count
|
|
41
41
|
const elements = document.querySelectorAll<HTMLElement>(selector);
|
|
42
42
|
|
|
43
|
-
const
|
|
43
|
+
const userInfo = useUserInfo();
|
|
44
44
|
|
|
45
45
|
if (elements.length)
|
|
46
46
|
void fetchCommentCount({
|
package/src/compact/convert.ts
CHANGED
|
@@ -27,7 +27,7 @@ export const covertOptions = (
|
|
|
27
27
|
visitor,
|
|
28
28
|
|
|
29
29
|
pageview = visitor === true
|
|
30
|
-
? '.leancloud_visitors,.waline-visitor-count,.waline-pageview-count'
|
|
30
|
+
? '.leancloud_visitors,.leancloud-visitors,.waline-visitor-count,.waline-pageview-count'
|
|
31
31
|
: visitor,
|
|
32
32
|
locale = langMode,
|
|
33
33
|
emoji,
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
:class="['wl-input', `wl-${kind}`]"
|
|
43
43
|
:name="kind"
|
|
44
44
|
:type="kind === 'mail' ? 'email' : 'text'"
|
|
45
|
-
v-model="
|
|
45
|
+
v-model="userMeta[kind]"
|
|
46
46
|
/>
|
|
47
47
|
</div>
|
|
48
48
|
</div>
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
ref="editorRef"
|
|
53
53
|
id="wl-edit"
|
|
54
54
|
:placeholder="replyUser ? `@${replyUser}` : locale.placeholder"
|
|
55
|
-
v-model="
|
|
55
|
+
v-model="editor"
|
|
56
56
|
@keydown="onKeyDown"
|
|
57
57
|
@drop="onDrop"
|
|
58
58
|
@paste="onPaste"
|
|
@@ -228,18 +228,19 @@ import {
|
|
|
228
228
|
PreviewIcon,
|
|
229
229
|
LoadingIcon,
|
|
230
230
|
} from './Icons';
|
|
231
|
-
import {
|
|
231
|
+
import { useEditor, useUserMeta, useUserInfo } from '../composables';
|
|
232
232
|
import {
|
|
233
233
|
getImagefromDataTransfer,
|
|
234
234
|
parseMarkdown,
|
|
235
235
|
getWordNumber,
|
|
236
236
|
parseEmoji,
|
|
237
237
|
postComment,
|
|
238
|
+
getEmojis,
|
|
238
239
|
} from '../utils';
|
|
239
240
|
|
|
240
241
|
import type { ComputedRef, DeepReadonly } from 'vue';
|
|
241
242
|
import type { WalineCommentData, WalineImageUploader } from '../typings';
|
|
242
|
-
import type {
|
|
243
|
+
import type { WalineConfig, WalineEmojiConfig } from '../utils';
|
|
243
244
|
|
|
244
245
|
export default defineComponent({
|
|
245
246
|
name: 'CommentBox',
|
|
@@ -271,10 +272,13 @@ export default defineComponent({
|
|
|
271
272
|
emits: ['submit', 'cancel-reply'],
|
|
272
273
|
|
|
273
274
|
setup(props, { emit }) {
|
|
274
|
-
const config = inject<ComputedRef<
|
|
275
|
+
const config = inject<ComputedRef<WalineConfig>>(
|
|
276
|
+
'config'
|
|
277
|
+
) as ComputedRef<WalineConfig>;
|
|
275
278
|
|
|
276
|
-
const
|
|
277
|
-
const
|
|
279
|
+
const editor = useEditor();
|
|
280
|
+
const userMeta = useUserMeta();
|
|
281
|
+
const userInfo = useUserInfo();
|
|
278
282
|
|
|
279
283
|
const inputRefs = ref<Record<string, HTMLInputElement>>({});
|
|
280
284
|
const editorRef = ref<HTMLTextAreaElement | null>(null);
|
|
@@ -282,7 +286,7 @@ export default defineComponent({
|
|
|
282
286
|
const emojiButtonRef = ref<HTMLDivElement | null>(null);
|
|
283
287
|
const emojiPopupRef = ref<HTMLDivElement | null>(null);
|
|
284
288
|
|
|
285
|
-
const emoji = ref<DeepReadonly<
|
|
289
|
+
const emoji = ref<DeepReadonly<WalineEmojiConfig>>({ tabs: [], map: {} });
|
|
286
290
|
const emojiTabIndex = ref(0);
|
|
287
291
|
const showEmoji = ref(false);
|
|
288
292
|
const showPreview = ref(false);
|
|
@@ -308,7 +312,7 @@ export default defineComponent({
|
|
|
308
312
|
const endPosition = textArea.selectionEnd || 0;
|
|
309
313
|
const scrollTop = textArea.scrollTop;
|
|
310
314
|
|
|
311
|
-
|
|
315
|
+
editor.value =
|
|
312
316
|
textArea.value.substring(0, startPosition) +
|
|
313
317
|
content +
|
|
314
318
|
textArea.value.substring(endPosition, textArea.value.length);
|
|
@@ -333,7 +337,7 @@ export default defineComponent({
|
|
|
333
337
|
return Promise.resolve()
|
|
334
338
|
.then(() => (config.value.imageUploader as WalineImageUploader)(file))
|
|
335
339
|
.then((url) => {
|
|
336
|
-
|
|
340
|
+
editor.value = editor.value.replace(
|
|
337
341
|
uploadText,
|
|
338
342
|
`\r\n`
|
|
339
343
|
);
|
|
@@ -374,9 +378,9 @@ export default defineComponent({
|
|
|
374
378
|
|
|
375
379
|
const comment: WalineCommentData = {
|
|
376
380
|
comment: content.value,
|
|
377
|
-
nick:
|
|
378
|
-
mail:
|
|
379
|
-
link:
|
|
381
|
+
nick: userMeta.value.nick,
|
|
382
|
+
mail: userMeta.value.mail,
|
|
383
|
+
link: userMeta.value.link,
|
|
380
384
|
ua: navigator.userAgent,
|
|
381
385
|
url: config.value.path,
|
|
382
386
|
};
|
|
@@ -441,18 +445,12 @@ export default defineComponent({
|
|
|
441
445
|
.then((resp) => {
|
|
442
446
|
isSubmitting.value = false;
|
|
443
447
|
|
|
444
|
-
store.update({
|
|
445
|
-
nick: comment.nick,
|
|
446
|
-
link: comment.link,
|
|
447
|
-
mail: comment.mail,
|
|
448
|
-
});
|
|
449
|
-
|
|
450
448
|
if (resp.errmsg) return alert(resp.errmsg);
|
|
451
449
|
|
|
452
450
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
453
451
|
emit('submit', resp.data!);
|
|
454
452
|
|
|
455
|
-
|
|
453
|
+
editor.value = '';
|
|
456
454
|
|
|
457
455
|
previewText.value = '';
|
|
458
456
|
|
|
@@ -488,7 +486,7 @@ export default defineComponent({
|
|
|
488
486
|
|
|
489
487
|
if (data.data.token) {
|
|
490
488
|
handler?.close();
|
|
491
|
-
|
|
489
|
+
userInfo.value = data.data;
|
|
492
490
|
(data.data.remember ? localStorage : sessionStorage).setItem(
|
|
493
491
|
'WALINE_USER',
|
|
494
492
|
JSON.stringify(data.data)
|
|
@@ -502,7 +500,7 @@ export default defineComponent({
|
|
|
502
500
|
};
|
|
503
501
|
|
|
504
502
|
const onLogout = (): void => {
|
|
505
|
-
|
|
503
|
+
userInfo.value = {};
|
|
506
504
|
localStorage.setItem('WALINE_USER', 'null');
|
|
507
505
|
sessionStorage.setItem('WALINE_USER', 'null');
|
|
508
506
|
};
|
|
@@ -529,7 +527,8 @@ export default defineComponent({
|
|
|
529
527
|
const receiver = ({ data }: any): void => {
|
|
530
528
|
if (!data || data.type !== 'profile') return;
|
|
531
529
|
|
|
532
|
-
|
|
530
|
+
userInfo.value = { ...userInfo.value, ...data };
|
|
531
|
+
|
|
533
532
|
[localStorage, sessionStorage]
|
|
534
533
|
.filter((store) => store.getItem('WALINE_USER'))
|
|
535
534
|
.forEach((store) =>
|
|
@@ -549,37 +548,6 @@ export default defineComponent({
|
|
|
549
548
|
showEmoji.value = false;
|
|
550
549
|
};
|
|
551
550
|
|
|
552
|
-
// watch editor
|
|
553
|
-
watch(
|
|
554
|
-
() => inputs.editor,
|
|
555
|
-
(value) => {
|
|
556
|
-
const { highlighter, texRenderer } = config.value;
|
|
557
|
-
|
|
558
|
-
content.value = value;
|
|
559
|
-
previewText.value = parseMarkdown(value, {
|
|
560
|
-
emojiMap: emoji.value.map,
|
|
561
|
-
highlighter,
|
|
562
|
-
texRenderer,
|
|
563
|
-
});
|
|
564
|
-
wordNumber.value = getWordNumber(value);
|
|
565
|
-
|
|
566
|
-
if (editorRef.value)
|
|
567
|
-
if (value) autosize(editorRef.value);
|
|
568
|
-
else autosize.destroy(editorRef.value);
|
|
569
|
-
},
|
|
570
|
-
{ immediate: true }
|
|
571
|
-
);
|
|
572
|
-
|
|
573
|
-
// watch emoji value change
|
|
574
|
-
watch(
|
|
575
|
-
() => config.value.emoji,
|
|
576
|
-
(emojiConfig) =>
|
|
577
|
-
emojiConfig.then((config) => {
|
|
578
|
-
emoji.value = config;
|
|
579
|
-
}),
|
|
580
|
-
{ immediate: true }
|
|
581
|
-
);
|
|
582
|
-
|
|
583
551
|
// update wordNumber
|
|
584
552
|
watch(
|
|
585
553
|
[config, wordNumber],
|
|
@@ -607,6 +575,38 @@ export default defineComponent({
|
|
|
607
575
|
|
|
608
576
|
onMounted(() => {
|
|
609
577
|
document.body.addEventListener('click', popupHandler);
|
|
578
|
+
|
|
579
|
+
// watch editor
|
|
580
|
+
watch(
|
|
581
|
+
() => editor.value,
|
|
582
|
+
(value) => {
|
|
583
|
+
const { highlighter, texRenderer } = config.value;
|
|
584
|
+
|
|
585
|
+
content.value = value;
|
|
586
|
+
previewText.value = parseMarkdown(value, {
|
|
587
|
+
emojiMap: emoji.value.map,
|
|
588
|
+
highlighter,
|
|
589
|
+
texRenderer,
|
|
590
|
+
});
|
|
591
|
+
wordNumber.value = getWordNumber(value);
|
|
592
|
+
|
|
593
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
594
|
+
if (value) autosize(editorRef.value!);
|
|
595
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
596
|
+
else autosize.destroy(editorRef.value!);
|
|
597
|
+
},
|
|
598
|
+
{ immediate: true }
|
|
599
|
+
);
|
|
600
|
+
|
|
601
|
+
// watch emoji value change
|
|
602
|
+
watch(
|
|
603
|
+
() => config.value.emoji,
|
|
604
|
+
(emojiConfig) =>
|
|
605
|
+
getEmojis(emojiConfig).then((config) => {
|
|
606
|
+
emoji.value = config;
|
|
607
|
+
}),
|
|
608
|
+
{ immediate: true }
|
|
609
|
+
);
|
|
610
610
|
});
|
|
611
611
|
|
|
612
612
|
onUnmounted(() => {
|
|
@@ -639,7 +639,8 @@ export default defineComponent({
|
|
|
639
639
|
isWordNumberLegal,
|
|
640
640
|
|
|
641
641
|
// inputs
|
|
642
|
-
|
|
642
|
+
editor,
|
|
643
|
+
userMeta,
|
|
643
644
|
|
|
644
645
|
// emoji
|
|
645
646
|
emoji,
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
/>
|
|
25
25
|
<span v-if="comment.sticky" class="wl-badge" v-text="locale.sticky" />
|
|
26
26
|
|
|
27
|
-
<span class="wl-time" v-text="
|
|
27
|
+
<span class="wl-time" v-text="time" />
|
|
28
28
|
|
|
29
29
|
<button
|
|
30
30
|
class="wl-reply"
|
|
@@ -69,10 +69,11 @@
|
|
|
69
69
|
import { computed, defineComponent, inject } from 'vue';
|
|
70
70
|
import CommentBox from './CommentBox.vue';
|
|
71
71
|
import { ReplyIcon, VerifiedIcon } from './Icons';
|
|
72
|
-
import { isLinkHttp
|
|
72
|
+
import { isLinkHttp } from '../utils';
|
|
73
|
+
import { useTimeAgo } from '../composables';
|
|
73
74
|
|
|
74
75
|
import type { ComputedRef, PropType } from 'vue';
|
|
75
|
-
import type {
|
|
76
|
+
import type { WalineConfig } from '../utils';
|
|
76
77
|
import type { WalineComment } from '../typings';
|
|
77
78
|
|
|
78
79
|
export default defineComponent({
|
|
@@ -99,7 +100,9 @@ export default defineComponent({
|
|
|
99
100
|
emits: ['submit', 'reply'],
|
|
100
101
|
|
|
101
102
|
setup(props) {
|
|
102
|
-
const config = inject<ComputedRef<
|
|
103
|
+
const config = inject<ComputedRef<WalineConfig>>(
|
|
104
|
+
'config'
|
|
105
|
+
) as ComputedRef<WalineConfig>;
|
|
103
106
|
const locale = computed(() => config.value.locale);
|
|
104
107
|
|
|
105
108
|
const link = computed(() => {
|
|
@@ -108,6 +111,8 @@ export default defineComponent({
|
|
|
108
111
|
return link ? (isLinkHttp(link) ? link : `https://${link}`) : '';
|
|
109
112
|
});
|
|
110
113
|
|
|
114
|
+
const time = useTimeAgo(props.comment.insertedAt, locale.value);
|
|
115
|
+
|
|
111
116
|
const isReplyingCurrent = computed(
|
|
112
117
|
() => props.comment.objectId === props.reply?.objectId
|
|
113
118
|
);
|
|
@@ -118,7 +123,7 @@ export default defineComponent({
|
|
|
118
123
|
|
|
119
124
|
isReplyingCurrent,
|
|
120
125
|
link,
|
|
121
|
-
|
|
126
|
+
time,
|
|
122
127
|
};
|
|
123
128
|
},
|
|
124
129
|
});
|
|
@@ -114,7 +114,6 @@ export default defineComponent({
|
|
|
114
114
|
|
|
115
115
|
meta: {
|
|
116
116
|
type: Array,
|
|
117
|
-
// default: (): Meta[] => ['nick', 'mail', 'link'],
|
|
118
117
|
...(SHOULD_VALIDATE
|
|
119
118
|
? {
|
|
120
119
|
validator: (value: unknown): boolean =>
|
|
@@ -126,7 +125,6 @@ export default defineComponent({
|
|
|
126
125
|
|
|
127
126
|
requiredMeta: {
|
|
128
127
|
type: Array,
|
|
129
|
-
// default: (): Meta[] => [],
|
|
130
128
|
...(SHOULD_VALIDATE
|
|
131
129
|
? {
|
|
132
130
|
validator: (value: unknown): boolean =>
|
|
@@ -136,19 +134,12 @@ export default defineComponent({
|
|
|
136
134
|
: {}),
|
|
137
135
|
},
|
|
138
136
|
|
|
139
|
-
visitor: {
|
|
140
|
-
type: Boolean,
|
|
141
|
-
// default: false,
|
|
142
|
-
},
|
|
143
|
-
|
|
144
137
|
dark: {
|
|
145
138
|
type: [String, Boolean],
|
|
146
|
-
// default: false,
|
|
147
139
|
},
|
|
148
140
|
|
|
149
141
|
lang: {
|
|
150
142
|
type: String,
|
|
151
|
-
// default: 'zh-CN',
|
|
152
143
|
...(SHOULD_VALIDATE
|
|
153
144
|
? {
|
|
154
145
|
validator: (value: unknown): boolean =>
|
|
@@ -163,7 +154,6 @@ export default defineComponent({
|
|
|
163
154
|
|
|
164
155
|
pageSize: {
|
|
165
156
|
type: Number,
|
|
166
|
-
// default: 10,
|
|
167
157
|
},
|
|
168
158
|
|
|
169
159
|
wordLimit: {
|
|
@@ -182,9 +172,6 @@ export default defineComponent({
|
|
|
182
172
|
|
|
183
173
|
emoji: {
|
|
184
174
|
type: Array as PropType<(string | WalineEmojiInfo)[]>,
|
|
185
|
-
// default: (): string[] => [
|
|
186
|
-
// 'https://cdn.jsdelivr.net/gh/walinejs/emojis/weibo',
|
|
187
|
-
// ],
|
|
188
175
|
...(SHOULD_VALIDATE
|
|
189
176
|
? {
|
|
190
177
|
validator: (value: unknown): boolean =>
|
|
@@ -207,38 +194,25 @@ export default defineComponent({
|
|
|
207
194
|
|
|
208
195
|
login: {
|
|
209
196
|
type: String as PropType<'enable' | 'disable' | 'force'>,
|
|
210
|
-
// default: 'enable',
|
|
211
197
|
},
|
|
212
198
|
|
|
213
199
|
highlighter: {
|
|
214
200
|
type: Function as PropType<WalineHighlighter>,
|
|
215
|
-
// default: (text: string): string => text,
|
|
216
201
|
},
|
|
217
202
|
|
|
218
203
|
imageUploader: {
|
|
219
|
-
type: [Function,
|
|
220
|
-
// default: (file: File): Promise<string> =>
|
|
221
|
-
// new Promise((resolve, reject) => {
|
|
222
|
-
// const reader = new FileReader();
|
|
223
|
-
// reader.readAsDataURL(file);
|
|
224
|
-
// reader.onload = (): void => resolve(reader.result?.toString() || '');
|
|
225
|
-
// reader.onerror = reject;
|
|
226
|
-
// }),
|
|
204
|
+
type: [Function, Boolean] as PropType<WalineImageUploader | false>,
|
|
227
205
|
},
|
|
228
206
|
|
|
229
207
|
texRenderer: {
|
|
230
|
-
type: Function as PropType<WalineTexRenderer>,
|
|
231
|
-
// default: (blockMode: boolean): string =>
|
|
232
|
-
// blockMode === true
|
|
233
|
-
// ? '<p class="wl-tex">Tex is not available in preview</p>'
|
|
234
|
-
// : '<span class="wl-tex">Tex is not available in preview</span>',
|
|
208
|
+
type: [Function, Boolean] as PropType<WalineTexRenderer | false>,
|
|
235
209
|
},
|
|
236
210
|
},
|
|
237
211
|
|
|
238
212
|
setup(props) {
|
|
239
213
|
const config = computed(() => getConfig(props as WalineProps));
|
|
240
214
|
|
|
241
|
-
const
|
|
215
|
+
const userInfo = useUserInfo();
|
|
242
216
|
|
|
243
217
|
const status = ref<'loading' | 'success' | 'error'>('loading');
|
|
244
218
|
|
package/src/composables/index.ts
CHANGED
|
@@ -1,29 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useStorage } from '@vueuse/core';
|
|
2
|
+
import type { RemovableRef } from '@vueuse/core';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export interface Inputs {
|
|
4
|
+
export interface UserMeta {
|
|
7
5
|
nick: string;
|
|
8
6
|
mail: string;
|
|
9
7
|
link: string;
|
|
10
|
-
editor: string;
|
|
11
8
|
}
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
inputs = reactive({
|
|
21
|
-
nick: store.get<string>('nick') || '',
|
|
22
|
-
mail: store.get<string>('mail') || '',
|
|
23
|
-
link: store.get<string>('link') || '',
|
|
24
|
-
editor: '',
|
|
25
|
-
});
|
|
26
|
-
}
|
|
10
|
+
export const useUserMeta = (): RemovableRef<UserMeta> =>
|
|
11
|
+
useStorage<UserMeta>('WALINE_USER_META', {
|
|
12
|
+
nick: '',
|
|
13
|
+
mail: '',
|
|
14
|
+
link: '',
|
|
15
|
+
});
|
|
27
16
|
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
export const useEditor = (): RemovableRef<string> =>
|
|
18
|
+
useStorage<string>('WALINE_COMMENT_BOX_EDITOR', '');
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useNow } from '@vueuse/core';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { dateFormat } from '../utils';
|
|
4
|
+
|
|
5
|
+
import type { ComputedRef } from 'vue';
|
|
6
|
+
import type { WalineLocale } from '../typings';
|
|
7
|
+
|
|
8
|
+
export const useTimeAgo = (
|
|
9
|
+
date: Date | string,
|
|
10
|
+
locale: WalineLocale
|
|
11
|
+
): ComputedRef<string> => {
|
|
12
|
+
const now = useNow();
|
|
13
|
+
|
|
14
|
+
return computed(() => {
|
|
15
|
+
if (!date) return '';
|
|
16
|
+
|
|
17
|
+
const time =
|
|
18
|
+
typeof date === 'string'
|
|
19
|
+
? new Date(date.indexOf(' ') !== -1 ? date.replace(/-/g, '/') : date)
|
|
20
|
+
: date;
|
|
21
|
+
|
|
22
|
+
const timepassed = now.value.getTime() - time.getTime();
|
|
23
|
+
|
|
24
|
+
const days = Math.floor(timepassed / (24 * 3600 * 1000));
|
|
25
|
+
|
|
26
|
+
if (days === 0) {
|
|
27
|
+
// 计算相差小时数
|
|
28
|
+
|
|
29
|
+
// 计算天数后剩余的毫秒数
|
|
30
|
+
const leave1 = timepassed % (24 * 3600 * 1000);
|
|
31
|
+
const hours = Math.floor(leave1 / (3600 * 1000));
|
|
32
|
+
|
|
33
|
+
if (hours === 0) {
|
|
34
|
+
//计算相差分钟数
|
|
35
|
+
|
|
36
|
+
// 计算小时数后剩余的毫秒数
|
|
37
|
+
const leave2 = leave1 % (3600 * 1000);
|
|
38
|
+
const minutes = Math.floor(leave2 / (60 * 1000));
|
|
39
|
+
|
|
40
|
+
// 计算相差秒数
|
|
41
|
+
if (minutes === 0) {
|
|
42
|
+
// 计算分钟数后剩余的毫秒数
|
|
43
|
+
const leave3 = leave2 % (60 * 1000);
|
|
44
|
+
const seconds = Math.round(leave3 / 1000);
|
|
45
|
+
|
|
46
|
+
return `${seconds} ${locale.seconds}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return `${minutes} ${locale.minutes}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return `${hours} ${locale.hours}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (days < 0) return locale.now;
|
|
56
|
+
|
|
57
|
+
if (days < 8) return `${days} ${locale.days}`;
|
|
58
|
+
|
|
59
|
+
return dateFormat(time);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getUserInfo } from '../utils';
|
|
1
|
+
import { useStorage } from '@vueuse/core';
|
|
3
2
|
|
|
4
3
|
import type { Ref } from 'vue';
|
|
5
|
-
import type { UserInfo } from '../utils';
|
|
6
4
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
export interface UserInfo {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
display_name: string;
|
|
8
|
+
email: string;
|
|
9
|
+
url: string;
|
|
10
|
+
token: string;
|
|
11
|
+
avatar: string;
|
|
12
|
+
mailMd5: string;
|
|
13
|
+
}
|
|
10
14
|
|
|
11
|
-
export const
|
|
12
|
-
userInfo: UserInfoRef;
|
|
13
|
-
setUserInfo: (userInfo: UserInfo | Record<string, never>) => void;
|
|
14
|
-
} => {
|
|
15
|
-
if (!userInfo.value.token) {
|
|
16
|
-
const info = getUserInfo();
|
|
15
|
+
export const USER_KEY = 'WALINE_USER';
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
export type UserInfoRef = Ref<UserInfo | Record<string, never>>;
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
setUserInfo: (info: UserInfo | Record<string, never>): void => {
|
|
24
|
-
userInfo.value = info;
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
};
|
|
19
|
+
export const useUserInfo = (): UserInfoRef =>
|
|
20
|
+
useStorage<UserInfo | Record<string, never>>('USER_KEY', {});
|
package/src/entrys/legacy.ts
CHANGED
|
@@ -18,7 +18,7 @@ warning(
|
|
|
18
18
|
const link = document.createElement('link');
|
|
19
19
|
|
|
20
20
|
link.rel = 'stylesheet';
|
|
21
|
-
link.href = '//cdn.jsdelivr.net/npm/@waline/client/dist/waline.css';
|
|
21
|
+
link.href = '//cdn.jsdelivr.net/npm/@waline/client@v2/dist/waline.css';
|
|
22
22
|
|
|
23
23
|
document.head.appendChild(link);
|
|
24
24
|
|
package/src/init.ts
CHANGED
|
@@ -97,7 +97,7 @@ export const init = ({
|
|
|
97
97
|
path = window.location.pathname,
|
|
98
98
|
...newProps
|
|
99
99
|
}: Partial<Omit<WalineInitOptions, 'el'>>): void => {
|
|
100
|
-
Object.entries(newProps).
|
|
100
|
+
Object.entries(newProps).forEach(([key, value]) => {
|
|
101
101
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
102
102
|
// @ts-ignore
|
|
103
103
|
// eslint-disable-next-line
|