PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / trunk
Code Block Pro – Beautiful Syntax Highlighting vtrunk
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / src / util / errors.ts

errors.ts in Code Block Pro – Beautiful Syntax Highlighting trunk, at src/util/errors.ts

46 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { subscribe } from '@wordpress/data';
2 import { __ } from '@wordpress/i18n';
3
4 export const debounce = <T extends (...args: unknown[]) => void>(
5 fn: T,
6 delay: number,
7 ) => {
8 let timeout: ReturnType<typeof setTimeout> | null = null;
9 return (...args: Parameters<T>) => {
10 if (timeout) clearTimeout(timeout);
11 timeout = setTimeout(() => fn(...args), delay);
12 };
13 };
14
15 export const handleValidationErrors = () => {
16 const debouncedUnsub = debounce(() => unsub(), 5000);
17
18 const unsub = subscribe(() => {
19 const editor = document.querySelector(
20 '#editor, iframe[name="editor-canvas"]',
21 );
22 const blockErrors = editor?.querySelectorAll(
23 '.wp-block-kevinbatdorf-code-block-pro .block-editor-warning',
24 );
25 if (!blockErrors?.length) return;
26 blockErrors.forEach((blockError) => {
27 const message = blockError.querySelector(
28 '.block-editor-warning__message',
29 );
30 if (message) {
31 message.textContent = __(
32 'This block has been updated. Press update to refresh.',
33 'code-block-pro',
34 );
35 }
36 const button = blockError.querySelector(
37 '.block-editor-warning__action button',
38 );
39 if (button) {
40 button.textContent = __('Update', 'code-block-pro');
41 }
42 });
43 debouncedUnsub();
44 });
45 };
46