PluginProbe
Parse.ly / 3.24.3
Parse.ly v3.24.3
3.24.3 3.24.2 3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 All 107 releases
wp-parsely / src / content-helper / common / utils / vocabulary.ts

vocabulary.ts in Parse.ly 3.24.3, at src/content-helper/common/utils/vocabulary.ts

36 lines 997 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * A tone or persona entry, as consumed by the selector components.
3 *
4 * @since 3.24.0
5 */
6 export type VocabularyEntry = {
7 label: string,
8 icon?: React.JSX.Element,
9 };
10
11 /**
12 * Converts a value => label record injected by PHP into selector metadata.
13 *
14 * PHP is the single source of the predefined tones and personas, so that the
15 * plugin's settings page can offer the same choices as the editor. The record
16 * is absent on screens that do not inject it, in which case only the custom
17 * entry defined by the selector remains.
18 *
19 * @since 3.24.0
20 *
21 * @param {Record<string, string>|undefined} labels The injected labels.
22 *
23 * @return {Record<string, VocabularyEntry>} The selector metadata.
24 */
25 export const toMetadata = (
26 labels: Record<string, string> | undefined
27 ): Record<string, VocabularyEntry> => {
28 if ( ! labels || 'object' !== typeof labels ) {
29 return {};
30 }
31
32 return Object.fromEntries(
33 Object.entries( labels ).map( ( [ value, label ] ) => [ value, { label } ] )
34 );
35 };
36