PluginProbe
BeyondWords – AI audio for publishers / 7.0.0
BeyondWords – AI audio for publishers v7.0.0
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / editor / components / inspect-panel / helpers.js

helpers.js in BeyondWords – AI audio for publishers 7.0.0, at src/editor/components/inspect-panel/helpers.js

56 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies
3 */
4 import { __ } from '@wordpress/i18n';
5
6 // Always-present diagnostics appended to the copied payload only — never counted
7 // as removable post data. The data-key lists stay in PHP (single source of truth).
8 export const SYSTEM_META_KEYS = [
9 'plugin_version',
10 'wp_version',
11 'wp_post_id',
12 ];
13
14 /**
15 * Does the post hold any BeyondWords data worth removing?
16 *
17 * Checks the data fields only (never the always-present system fields), so the
18 * Remove button tracks the post's current state, not a mount-time snapshot.
19 *
20 * @param {Object} meta Live custom-field values keyed by field name.
21 * @param {string[]} dataKeys Current + deprecated meta keys (sourced from PHP).
22 * @return {boolean} Whether any data field has a non-empty value.
23 */
24 export const hasBeyondwordsData = ( meta, dataKeys = [] ) =>
25 dataKeys.some( ( key ) => !! meta[ key ]?.length );
26
27 /**
28 * Build the plain-text diagnostics payload for the Copy button.
29 *
30 * Reads the same live `meta` as {@link hasBeyondwordsData} so Copy and Remove
31 * can never disagree; the key lists render in the order supplied.
32 *
33 * @param {Object} meta Live values keyed by field name (incl. system).
34 * @param {string[]} currentKeys Current meta keys, in display order.
35 * @param {string[]} deprecatedKeys Deprecated meta keys, in display order.
36 * @return {string} The clipboard payload.
37 */
38 export const getTextToCopy = (
39 meta,
40 currentKeys = [],
41 deprecatedKeys = []
42 ) => {
43 const line = ( key ) => `${ key }\r\n${ meta[ key ] }`;
44
45 return (
46 [
47 ...currentKeys.map( line ),
48 `=== ${ __( 'Deprecated', 'speechkit' ) } ===`,
49 ...deprecatedKeys.map( line ),
50 `=== ${ __( 'System', 'speechkit' ) } ===`,
51 ...SYSTEM_META_KEYS.map( line ),
52 `=== ${ __( 'Copied using the Block Editor', 'speechkit' ) } ===`,
53 ].join( '\r\n\r\n' ) + '\r\n\r\n'
54 );
55 };
56