@waline/client 2.0.3 → 2.0.6

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.0.3",
3
+ "version": "2.0.6",
4
4
  "description": "client for waline comment system",
5
5
  "keywords": [
6
6
  "valine",
@@ -27,6 +27,7 @@
27
27
  "./dist": "./dist/shim.js",
28
28
  "./dist/waline.css": "./dist/waline.css",
29
29
  "./dist/*": "./dist/*.js",
30
+ "./src/*": "./src/*",
30
31
  "./package.json": "./package.json"
31
32
  },
32
33
  "main": "./dist/shim.js",
@@ -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="inputs[kind]"
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="inputs.editor"
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 { useInputs, useUserInfo } from '../composables';
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 { Config, EmojiConfig } from '../utils';
243
+ import type { WalineConfig, WalineEmojiConfig } from '../utils';
243
244
 
244
245
  export default defineComponent({
245
246
  name: 'CommentBox',
@@ -271,9 +272,12 @@ export default defineComponent({
271
272
  emits: ['submit', 'cancel-reply'],
272
273
 
273
274
  setup(props, { emit }) {
274
- const config = inject<ComputedRef<Config>>('config') as ComputedRef<Config>;
275
+ const config = inject<ComputedRef<WalineConfig>>(
276
+ 'config'
277
+ ) as ComputedRef<WalineConfig>;
275
278
 
276
- const inputs = useInputs();
279
+ const editor = useEditor();
280
+ const userMeta = useUserMeta();
277
281
  const userInfo = useUserInfo();
278
282
 
279
283
  const inputRefs = ref<Record<string, HTMLInputElement>>({});
@@ -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<EmojiConfig>>({ tabs: [], map: {} });
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
- inputs.value.editor =
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
- inputs.value.editor = inputs.value.editor.replace(
340
+ editor.value = editor.value.replace(
337
341
  uploadText,
338
342
  `\r\n![${file.name}](${url})`
339
343
  );
@@ -374,9 +378,9 @@ export default defineComponent({
374
378
 
375
379
  const comment: WalineCommentData = {
376
380
  comment: content.value,
377
- nick: inputs.value.nick,
378
- mail: inputs.value.mail,
379
- link: inputs.value.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
  };
@@ -446,7 +450,7 @@ export default defineComponent({
446
450
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
447
451
  emit('submit', resp.data!);
448
452
 
449
- inputs.value.editor = '';
453
+ editor.value = '';
450
454
 
451
455
  previewText.value = '';
452
456
 
@@ -544,37 +548,6 @@ export default defineComponent({
544
548
  showEmoji.value = false;
545
549
  };
546
550
 
547
- // watch editor
548
- watch(
549
- () => inputs.value.editor,
550
- (value) => {
551
- const { highlighter, texRenderer } = config.value;
552
-
553
- content.value = value;
554
- previewText.value = parseMarkdown(value, {
555
- emojiMap: emoji.value.map,
556
- highlighter,
557
- texRenderer,
558
- });
559
- wordNumber.value = getWordNumber(value);
560
-
561
- if (editorRef.value)
562
- if (value) autosize(editorRef.value);
563
- else autosize.destroy(editorRef.value);
564
- },
565
- { immediate: true }
566
- );
567
-
568
- // watch emoji value change
569
- watch(
570
- () => config.value.emoji,
571
- (emojiConfig) =>
572
- emojiConfig.then((config) => {
573
- emoji.value = config;
574
- }),
575
- { immediate: true }
576
- );
577
-
578
551
  // update wordNumber
579
552
  watch(
580
553
  [config, wordNumber],
@@ -602,6 +575,38 @@ export default defineComponent({
602
575
 
603
576
  onMounted(() => {
604
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
+ );
605
610
  });
606
611
 
607
612
  onUnmounted(() => {
@@ -634,7 +639,8 @@ export default defineComponent({
634
639
  isWordNumberLegal,
635
640
 
636
641
  // inputs
637
- inputs,
642
+ editor,
643
+ userMeta,
638
644
 
639
645
  // emoji
640
646
  emoji,
@@ -73,7 +73,7 @@ import { isLinkHttp } from '../utils';
73
73
  import { useTimeAgo } from '../composables';
74
74
 
75
75
  import type { ComputedRef, PropType } from 'vue';
76
- import type { Config } from '../utils';
76
+ import type { WalineConfig } from '../utils';
77
77
  import type { WalineComment } from '../typings';
78
78
 
79
79
  export default defineComponent({
@@ -100,7 +100,9 @@ export default defineComponent({
100
100
  emits: ['submit', 'reply'],
101
101
 
102
102
  setup(props) {
103
- const config = inject<ComputedRef<Config>>('config') as ComputedRef<Config>;
103
+ const config = inject<ComputedRef<WalineConfig>>(
104
+ 'config'
105
+ ) as ComputedRef<WalineConfig>;
104
106
  const locale = computed(() => config.value.locale);
105
107
 
106
108
  const link = computed(() => {
@@ -134,10 +134,6 @@ export default defineComponent({
134
134
  : {}),
135
135
  },
136
136
 
137
- visitor: {
138
- type: Boolean,
139
- },
140
-
141
137
  dark: {
142
138
  type: [String, Boolean],
143
139
  },
@@ -1,17 +1,18 @@
1
1
  import { useStorage } from '@vueuse/core';
2
2
  import type { RemovableRef } from '@vueuse/core';
3
3
 
4
- export interface Inputs {
4
+ export interface UserMeta {
5
5
  nick: string;
6
6
  mail: string;
7
7
  link: string;
8
- editor: string;
9
8
  }
10
9
 
11
- export const useInputs = (): RemovableRef<Inputs> =>
12
- useStorage<Inputs>('WALINE_USER_CACHE', {
10
+ export const useUserMeta = (): RemovableRef<UserMeta> =>
11
+ useStorage<UserMeta>('WALINE_USER_META', {
13
12
  nick: '',
14
13
  mail: '',
15
14
  link: '',
16
- editor: '',
17
15
  });
16
+
17
+ export const useEditor = (): RemovableRef<string> =>
18
+ useStorage<string>('WALINE_COMMENT_BOX_EDITOR', '');
@@ -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 = '//unpkg.com/@waline/client@v2/dist/waline.css';
22
22
 
23
23
  document.head.appendChild(link);
24
24
 
package/src/pageview.ts CHANGED
@@ -61,7 +61,7 @@ export const pageviewCount = ({
61
61
  const controller = new AbortController();
62
62
 
63
63
  const elements = Array.from(
64
- // visitor selectors
64
+ // pageview selectors
65
65
  document.querySelectorAll<HTMLElement>(selector)
66
66
  );
67
67
 
@@ -7,7 +7,6 @@ import {
7
7
  } from '../config';
8
8
 
9
9
  import { decodePath, isLinkHttp, removeEndingSplash } from './path';
10
- import { getEmojis } from './emoji';
11
10
 
12
11
  import type {
13
12
  WalineEmojiInfo,
@@ -17,31 +16,15 @@ import type {
17
16
  } from '../typings';
18
17
  import hanabi from 'hanabi';
19
18
 
20
- export interface EmojiConfig {
19
+ export interface WalineEmojiConfig {
21
20
  tabs: Pick<WalineEmojiInfo, 'name' | 'icon' | 'items'>[];
22
21
  map: WalineEmojiMaps;
23
22
  }
24
23
 
25
- export interface Config
26
- extends Required<
27
- Pick<
28
- WalineProps,
29
- | 'path'
30
- | 'lang'
31
- | 'meta'
32
- | 'pageSize'
33
- | 'requiredMeta'
34
- | 'imageUploader'
35
- | 'highlighter'
36
- | 'texRenderer'
37
- | 'copyright'
38
- | 'login'
39
- >
40
- >,
41
- Pick<WalineProps, 'dark' | 'serverURL'> {
24
+ export interface WalineConfig extends Required<Omit<WalineProps, 'wordLimit'>> {
42
25
  locale: WalineLocale;
43
26
  wordLimit: [number, number] | false;
44
- emoji: Promise<EmojiConfig>;
27
+ // emoji: Promise<EmojiConfig>;
45
28
  }
46
29
 
47
30
  const getServerURL = (serverURL: string): string => {
@@ -50,6 +33,11 @@ const getServerURL = (serverURL: string): string => {
50
33
  return isLinkHttp(result) ? result : `https://${result}`;
51
34
  };
52
35
 
36
+ const getWordLimit = (
37
+ wordLimit: WalineProps['wordLimit']
38
+ ): [number, number] | false =>
39
+ Array.isArray(wordLimit) ? wordLimit : wordLimit ? [0, wordLimit] : false;
40
+
53
41
  const fallback = <T = unknown>(
54
42
  value: T | false | undefined,
55
43
  fallback: T
@@ -62,9 +50,10 @@ export const getConfig = ({
62
50
  path = location.pathname,
63
51
  lang = defaultLang,
64
52
  locale,
65
- emoji = ['https://cdn.jsdelivr.net/gh/walinejs/emojis@1.0.0/weibo'],
53
+ emoji = ['//unpkg.com/@waline/emojis@1.0.1/weibo/info.json'],
66
54
  meta = ['nick', 'mail', 'link'],
67
55
  requiredMeta = [],
56
+ dark = false,
68
57
  pageSize = 10,
69
58
  wordLimit,
70
59
  imageUploader,
@@ -73,27 +62,25 @@ export const getConfig = ({
73
62
  copyright = true,
74
63
  login = 'enable',
75
64
  ...more
76
- }: WalineProps): Config => ({
65
+ }: WalineProps): WalineConfig => ({
77
66
  serverURL: getServerURL(serverURL),
78
67
  path: decodePath(path),
79
- lang,
80
68
  locale: {
81
69
  ...(locales[lang] || locales[defaultLang]),
82
70
  ...(typeof locale === 'object' ? locale : {}),
83
71
  },
84
- emoji: getEmojis(emoji),
85
- wordLimit: Array.isArray(wordLimit)
86
- ? wordLimit
87
- : wordLimit
88
- ? [0, wordLimit]
89
- : false,
72
+ // emoji: getEmojis(emoji),
73
+ wordLimit: getWordLimit(wordLimit),
90
74
  meta: getMeta(meta),
91
75
  requiredMeta: getMeta(requiredMeta),
92
- pageSize,
93
- login,
94
76
  imageUploader: fallback(imageUploader, defaultUploadImage),
95
77
  highlighter: fallback(highlighter, hanabi),
96
78
  texRenderer: fallback(texRenderer, defaultTexRenderer),
79
+ lang,
80
+ dark,
81
+ emoji,
82
+ pageSize,
83
+ login,
97
84
  copyright,
98
85
  ...more,
99
86
  });
@@ -1,7 +1,7 @@
1
1
  import { useStorage } from '@vueuse/core';
2
2
  import { removeEndingSplash } from './path';
3
3
 
4
- import type { EmojiConfig } from './config';
4
+ import type { WalineEmojiConfig } from './config';
5
5
  import type { WalineEmojiInfo } from '../typings';
6
6
 
7
7
  const hasVersion = (url: string): boolean =>
@@ -40,7 +40,7 @@ const getLink = (name: string, folder = '', prefix = '', type = ''): string =>
40
40
 
41
41
  export const getEmojis = (
42
42
  emojis: (string | WalineEmojiInfo)[]
43
- ): Promise<EmojiConfig> =>
43
+ ): Promise<WalineEmojiConfig> =>
44
44
  Promise.all(
45
45
  emojis.map((emoji) =>
46
46
  typeof emoji === 'string'
@@ -48,7 +48,7 @@ export const getEmojis = (
48
48
  : Promise.resolve(emoji)
49
49
  )
50
50
  ).then((emojiInfos) => {
51
- const emojiConfig: EmojiConfig = {
51
+ const emojiConfig: WalineEmojiConfig = {
52
52
  tabs: [],
53
53
  map: {},
54
54
  };