@waline/client 2.15.0 → 2.15.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.15.0",
3
+ "version": "2.15.1",
4
4
  "description": "client for waline comment system",
5
5
  "keywords": [
6
6
  "valine",
@@ -207,6 +207,7 @@
207
207
  />
208
208
 
209
209
  <ImageWall
210
+ v-if="searchResults.list.length"
210
211
  :items="searchResults.list"
211
212
  :column-width="200"
212
213
  :gap="6"
@@ -313,10 +314,10 @@ import { addComment, login, updateComment, UserInfo } from '../api/index.js';
313
314
  import {
314
315
  useEditor,
315
316
  useReCaptcha,
317
+ useTurnstile,
316
318
  useUserInfo,
317
319
  useUserMeta,
318
320
  } from '../composables/index.js';
319
- import { useTurnstile } from '../composables/turnstile';
320
321
  import {
321
322
  type WalineComment,
322
323
  type WalineCommentData,
@@ -563,7 +564,9 @@ const submitComment = async (): Promise<void> => {
563
564
 
564
565
  try {
565
566
  if (recaptchaV3Key)
566
- comment.recaptchaV3 = await useReCaptcha(recaptchaV3Key).execute('social');
567
+ comment.recaptchaV3 = await useReCaptcha(recaptchaV3Key).execute(
568
+ 'social'
569
+ );
567
570
 
568
571
  if (turnstileKey)
569
572
  comment.turnstile = await useTurnstile(turnstileKey).execute('social');
@@ -2,4 +2,5 @@ export * from './inputs';
2
2
  export * from './like';
3
3
  export * from './reaction';
4
4
  export * from './recaptchaV3';
5
+ export * from './turnstile';
5
6
  export * from './userInfo';
@@ -1,3 +1,5 @@
1
+ import { useScriptTag } from '@vueuse/core';
2
+
1
3
  interface TurnstileOptions {
2
4
  sitekey: string;
3
5
  action?: string;
@@ -19,61 +21,29 @@ interface Turnstile {
19
21
  execute: (action: string) => Promise<string>;
20
22
  }
21
23
 
22
- interface LoadScriptParameters {
23
- src: string;
24
- async?: boolean;
25
- defer?: boolean;
26
- }
27
-
28
- const isBrowser =
29
- typeof window !== 'undefined' && typeof window.document !== 'undefined';
30
-
31
- async function loadScript(
32
- options: LoadScriptParameters
33
- ): Promise<Event | undefined> {
34
- if (!isBrowser) {
35
- return Promise.resolve(undefined);
36
- }
37
-
38
- const el = document.createElement('script');
39
-
40
- el.async = Boolean(options.async);
41
- el.defer = Boolean(options.defer);
42
-
43
- return new Promise((resolve, reject) => {
44
- el.onload = resolve;
45
- el.onerror = reject;
46
- el.src = options.src;
47
-
48
- document.head.appendChild(el);
49
- });
50
- }
51
-
52
- const turnstileScriptPromise = loadScript({
53
- src: 'https://challenges.cloudflare.com/turnstile/v0/api.js',
54
- async: false,
55
- });
56
-
57
24
  export const useTurnstile = (key: string): Turnstile => {
58
- async function execute(action: string): Promise<string> {
59
- await turnstileScriptPromise;
60
- const turnstile = window?.turnstile;
61
-
62
- return new Promise((resolve) => {
63
- const options: TurnstileOptions = {
64
- sitekey: key,
65
- action,
66
- size: 'compact',
67
- callback(token: string): void {
68
- resolve(token);
69
- },
70
- };
71
-
72
- turnstile?.ready(() =>
73
- turnstile?.render('.wl-captcha-container', options)
25
+ const execute = (action: string): Promise<string> =>
26
+ new Promise((resolve) => {
27
+ useScriptTag(
28
+ 'https://challenges.cloudflare.com/turnstile/v0/api.js',
29
+ () => {
30
+ const turnstile = window?.turnstile;
31
+
32
+ const options: TurnstileOptions = {
33
+ sitekey: key,
34
+ action,
35
+ size: 'compact',
36
+ callback(token: string): void {
37
+ resolve(token);
38
+ },
39
+ };
40
+
41
+ turnstile?.ready(() =>
42
+ turnstile?.render('.wl-captcha-container', options)
43
+ );
44
+ }
74
45
  );
75
46
  });
76
- }
77
47
 
78
48
  return { execute };
79
49
  };