| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | import { buildUrl } from '../urls' |
| 4 | 4 | import { parseSnippetObject } from './objects' |
| 5 | 5 | import type { CloudSnippetSchema } from '../../types/schema/CloudSnippetSchema' |
| 6 | 6 | import type { SnippetSchema } from '../../types/schema/SnippetSchema' |
| 7 | -import type { Snippet, SnippetScope, SnippetType } from '../../types/Snippet' | |
| 7 | +import type { Snippet, SnippetCodeScope, SnippetScope, SnippetType } from '../../types/Snippet' | |
| 8 | 8 | |
| 9 | 9 | const PRO_TYPES = new Set<SnippetType>(['css', 'js', 'cond']) |
| 10 | 10 | |
| 11 | 11 | export const SNIPPET_TYPE_LABELS: Record<SnippetType, string> = { |
| @@ -15,8 +15,38 @@ | ||
| 15 | 15 | js: __('Scripts', 'code-snippets'), |
| 16 | 16 | cond: __('Conditions', 'code-snippets') |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | +export const SNIPPET_SCOPE_ICONS: Record<SnippetCodeScope, string> = { | |
| 20 | + 'global': 'admin-site', | |
| 21 | + 'admin': 'admin-tools', | |
| 22 | + 'front-end': 'admin-appearance', | |
| 23 | + 'single-use': 'clock', | |
| 24 | + 'content': 'shortcode', | |
| 25 | + 'head-content': 'editor-code', | |
| 26 | + 'body-content': 'editor-code', | |
| 27 | + 'footer-content': 'editor-code', | |
| 28 | + 'admin-css': 'dashboard', | |
| 29 | + 'site-css': 'admin-customizer', | |
| 30 | + 'site-head-js': 'media-code', | |
| 31 | + 'site-footer-js': 'media-code' | |
| 32 | +} | |
| 33 | + | |
| 34 | +export const SNIPPET_SCOPE_DESCRIPTIONS: Record<SnippetCodeScope, string> = { | |
| 35 | + 'global': __('Run everywhere', 'code-snippets'), | |
| 36 | + 'admin': __('Only run in administration area', 'code-snippets'), | |
| 37 | + 'front-end': __('Only run on site front-end', 'code-snippets'), | |
| 38 | + 'single-use': __('Only run once', 'code-snippets'), | |
| 39 | + 'content': __('Where inserted in editor', 'code-snippets'), | |
| 40 | + 'head-content': __('In site header (<head> section)', 'code-snippets'), | |
| 41 | + 'body-content': __('In site content (start of <body>)', 'code-snippets'), | |
| 42 | + 'footer-content': __('In site footer (end of <body>)', 'code-snippets'), | |
| 43 | + 'site-css': __('Site front-end', 'code-snippets'), | |
| 44 | + 'admin-css': __('Administration area', 'code-snippets'), | |
| 45 | + 'site-head-js': __('In site header (<head> section)', 'code-snippets'), | |
| 46 | + 'site-footer-js': __('In site footer (end of <body>)', 'code-snippets') | |
| 47 | +} | |
| 48 | + | |
| 19 | 49 | export const createSnippetObject = (fields?: Partial<Snippet> | Partial<SnippetSchema>): Snippet => |
| 20 | 50 | parseSnippetObject(fields) |
| 21 | 51 | |
| 22 | 52 | export const cloneSnippetObject = (snippet: Snippet): Snippet => |
| @@ -100,9 +130,9 @@ | ||
| 100 | 130 | : snippet.active |
| 101 | 131 | |
| 102 | 132 | /** |
| 103 | 133 | * Whether the snippet belongs to the network and is not shared with subsites, |
| 104 | - * making it read-only outside of the network admin. | |
| 134 | + * making it read-only outside the network admin. | |
| 105 | 135 | */ |
| 106 | 136 | export const isNetworkOnlySnippet = (snippet: Snippet): boolean => |
| 107 | 137 | !isNetworkAdmin() && snippet.network && !snippet.shared_network |
| 108 | 138 | |