@wordpress-gcb/fields 0.2.1 → 0.2.3
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/dist/conditional-logic.js +83 -0
- package/{src → dist}/control-context.js +3 -2
- package/{src → dist}/controls/MediaCapabilityGate.js +12 -8
- package/dist/controls/MediaPicker.js +149 -0
- package/dist/controls/MediaTriggerBadges.js +35 -0
- package/{src → dist}/controls/PopoverOrModal.js +49 -43
- package/dist/controls/SortableItem.js +126 -0
- package/dist/controls/button-group.js +46 -0
- package/dist/controls/checkbox-group.js +65 -0
- package/dist/controls/checkbox.js +15 -0
- package/dist/controls/code.js +24 -0
- package/dist/controls/color.js +249 -0
- package/dist/controls/date.js +55 -0
- package/dist/controls/datetime.js +61 -0
- package/dist/controls/email.js +17 -0
- package/dist/controls/file.js +163 -0
- package/dist/controls/gallery.js +371 -0
- package/dist/controls/google-map.js +143 -0
- package/dist/controls/heading-level.js +93 -0
- package/dist/controls/icon.js +292 -0
- package/dist/controls/image.js +360 -0
- package/dist/controls/index.js +88 -0
- package/dist/controls/message.js +86 -0
- package/dist/controls/number.js +19 -0
- package/dist/controls/oembed.js +42 -0
- package/{src → dist}/controls/page-link.js +1 -2
- package/dist/controls/post-object.js +913 -0
- package/dist/controls/radio.js +19 -0
- package/dist/controls/range.js +108 -0
- package/{src → dist}/controls/relationship.js +12 -7
- package/dist/controls/repeater.js +277 -0
- package/dist/controls/richtext.js +494 -0
- package/dist/controls/select.js +144 -0
- package/dist/controls/size.js +59 -0
- package/dist/controls/spacing.js +172 -0
- package/dist/controls/taxonomy.js +569 -0
- package/dist/controls/text.js +16 -0
- package/dist/controls/textarea.js +17 -0
- package/dist/controls/toggle-group.js +28 -0
- package/dist/controls/toggle.js +15 -0
- package/dist/controls/url.js +235 -0
- package/dist/controls/user.js +383 -0
- package/{src → dist}/controls/wysiwyg.js +1 -1
- package/{src → dist}/hooks/useTokens.js +25 -21
- package/{src → dist}/index.js +2 -8
- package/dist/inspector.js +163 -0
- package/{src → dist}/provider.js +18 -17
- package/dist/utils/map-utils.js +54 -0
- package/dist/utils/token-helper.js +396 -0
- package/{src → dist}/validation-context.js +4 -4
- package/package.json +20 -13
- package/src/conditional-logic.js +0 -77
- package/src/controls/MediaPicker.js +0 -139
- package/src/controls/MediaTriggerBadges.js +0 -31
- package/src/controls/SortableItem.js +0 -110
- package/src/controls/button-group.js +0 -49
- package/src/controls/checkbox-group.js +0 -55
- package/src/controls/checkbox.js +0 -13
- package/src/controls/code.js +0 -21
- package/src/controls/color.js +0 -235
- package/src/controls/date.js +0 -37
- package/src/controls/datetime.js +0 -54
- package/src/controls/email.js +0 -15
- package/src/controls/file.js +0 -134
- package/src/controls/gallery.js +0 -338
- package/src/controls/google-map.js +0 -117
- package/src/controls/heading-level.js +0 -99
- package/src/controls/icon.js +0 -301
- package/src/controls/image.js +0 -334
- package/src/controls/index.js +0 -95
- package/src/controls/message.js +0 -56
- package/src/controls/number.js +0 -17
- package/src/controls/oembed.js +0 -32
- package/src/controls/post-object.js +0 -788
- package/src/controls/radio.js +0 -18
- package/src/controls/range.js +0 -110
- package/src/controls/repeater.js +0 -290
- package/src/controls/richtext.js +0 -505
- package/src/controls/select.js +0 -141
- package/src/controls/size.js +0 -49
- package/src/controls/spacing.js +0 -141
- package/src/controls/taxonomy.js +0 -488
- package/src/controls/text.js +0 -14
- package/src/controls/textarea.js +0 -15
- package/src/controls/toggle-group.js +0 -34
- package/src/controls/toggle.js +0 -13
- package/src/controls/url.js +0 -164
- package/src/controls/user.js +0 -343
- package/src/inspector.js +0 -174
- package/src/utils/map-utils.js +0 -51
- package/src/utils/token-helper.js +0 -243
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress-gcb/fields",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "GCB typed-field controls, inspector renderer, and schema — decoupled from the WordPress plugin so any Gutenberg/headless editor can use them.",
|
|
5
5
|
"license": "GPL-2.0-or-later",
|
|
6
6
|
"homepage": "https://gutenbergcontrolblocks.com",
|
|
@@ -18,27 +18,29 @@
|
|
|
18
18
|
"fields",
|
|
19
19
|
"gcb"
|
|
20
20
|
],
|
|
21
|
-
"//
|
|
22
|
-
"main": "./
|
|
21
|
+
"//build": "We PUBLISH compiled JS from dist/ (babel-transformed JSX), NOT raw src/. A published npm package shipping raw JSX breaks every consumer whose bundler excludes node_modules from babel (which is the default). src/ is the editable source; dist/ is what ships. Run `npm run build` before publishing — prepublishOnly enforces it.",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
23
|
"exports": {
|
|
24
|
-
".": "./
|
|
25
|
-
"./conditional-logic": "./
|
|
24
|
+
".": "./dist/index.js",
|
|
25
|
+
"./conditional-logic": "./dist/conditional-logic.js"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"
|
|
28
|
+
"dist"
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
|
+
"build": "babel src --out-dir dist --copy-files",
|
|
32
|
+
"prepublishOnly": "npm run build",
|
|
31
33
|
"test": "echo \"no tests yet\" && exit 0"
|
|
32
34
|
},
|
|
33
35
|
"//": "WordPress packages are provided by the host editor (externalised in wp-scripts builds) — peer deps, not bundled.",
|
|
34
36
|
"peerDependencies": {
|
|
35
|
-
"@wordpress/components": ">=27",
|
|
36
|
-
"@wordpress/element": ">=5",
|
|
37
|
-
"@wordpress/i18n": ">=4",
|
|
38
|
-
"@wordpress/block-editor": ">=12",
|
|
39
37
|
"@wordpress/api-fetch": ">=6",
|
|
38
|
+
"@wordpress/block-editor": ">=12",
|
|
40
39
|
"@wordpress/blocks": ">=12",
|
|
40
|
+
"@wordpress/components": ">=27",
|
|
41
41
|
"@wordpress/data": ">=9",
|
|
42
|
+
"@wordpress/element": ">=5",
|
|
43
|
+
"@wordpress/i18n": ">=4",
|
|
42
44
|
"@wordpress/icons": ">=9"
|
|
43
45
|
},
|
|
44
46
|
"//deps": "Bundled because they are NOT part of the WordPress runtime: the rich-control libraries.",
|
|
@@ -46,9 +48,14 @@
|
|
|
46
48
|
"@dnd-kit/core": "^6.3.1",
|
|
47
49
|
"@dnd-kit/sortable": "^10.0.0",
|
|
48
50
|
"@dnd-kit/utilities": "^3.2.2",
|
|
49
|
-
"@tiptap/
|
|
50
|
-
"@tiptap/starter-kit": "^3.23.6",
|
|
51
|
+
"@tiptap/extension-image": "^3.23.6",
|
|
51
52
|
"@tiptap/extension-link": "^3.23.6",
|
|
52
|
-
"@tiptap/
|
|
53
|
+
"@tiptap/react": "^3.23.6",
|
|
54
|
+
"@tiptap/starter-kit": "^3.23.6"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@babel/cli": "^7.29.7",
|
|
58
|
+
"@babel/core": "^7.29.7",
|
|
59
|
+
"@wordpress/babel-preset-default": "^8.48.0"
|
|
53
60
|
}
|
|
54
61
|
}
|
package/src/conditional-logic.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conditional logic — pure functions, no React, no @wordpress/* deps.
|
|
3
|
-
*
|
|
4
|
-
* Kept separate from inspector.js so unit tests can import without
|
|
5
|
-
* pulling in the whole control library. Keep in sync with PHP mirror:
|
|
6
|
-
* includes/PostFields/Conditional.php
|
|
7
|
-
*
|
|
8
|
-
* Config shape on a control:
|
|
9
|
-
*
|
|
10
|
-
* {
|
|
11
|
-
* conditionalLogic: {
|
|
12
|
-
* enabled: true,
|
|
13
|
-
* operator: 'and' | 'or', // default: 'and'
|
|
14
|
-
* rules: [
|
|
15
|
-
* { field: 'show_cta', operator: '==', value: true },
|
|
16
|
-
* { field: 'count', operator: '>', value: 0 },
|
|
17
|
-
* ],
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
// Structural control types (group, panel, tools-panel) render as panel
|
|
23
|
-
// containers, not as fields. Exported so callers that walk the control
|
|
24
|
-
// list can skip them consistently.
|
|
25
|
-
export const STRUCTURAL_TYPES = new Set(['group', 'panel', 'tools-panel']);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Decide whether a control should render against the current attribute
|
|
29
|
-
* values. A control with no `conditionalLogic` (or a disabled one) is
|
|
30
|
-
* always rendered.
|
|
31
|
-
*/
|
|
32
|
-
export function shouldRender(control, attributes) {
|
|
33
|
-
const cl = control.conditionalLogic;
|
|
34
|
-
if (!cl?.enabled || !Array.isArray(cl.rules) || cl.rules.length === 0) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
const op = cl.operator === 'or' ? 'or' : 'and';
|
|
38
|
-
const results = cl.rules.map((rule) => evalRule(rule, attributes));
|
|
39
|
-
return op === 'or' ? results.some(Boolean) : results.every(Boolean);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function evalRule(rule, attributes) {
|
|
43
|
-
const actual = attributes[rule.field];
|
|
44
|
-
switch (rule.operator) {
|
|
45
|
-
case '==': return actual == rule.value; // eslint-disable-line eqeqeq
|
|
46
|
-
case '!=': return actual != rule.value; // eslint-disable-line eqeqeq
|
|
47
|
-
case '>': return Number.isFinite(Number(actual)) && Number.isFinite(Number(rule.value)) && Number(actual) > Number(rule.value);
|
|
48
|
-
case '<': return Number.isFinite(Number(actual)) && Number.isFinite(Number(rule.value)) && Number(actual) < Number(rule.value);
|
|
49
|
-
case '>=': return Number.isFinite(Number(actual)) && Number.isFinite(Number(rule.value)) && Number(actual) >= Number(rule.value);
|
|
50
|
-
case '<=': return Number.isFinite(Number(actual)) && Number.isFinite(Number(rule.value)) && Number(actual) <= Number(rule.value);
|
|
51
|
-
case 'contains':
|
|
52
|
-
return typeof actual === 'string' && actual.includes(rule.value);
|
|
53
|
-
case 'in':
|
|
54
|
-
return Array.isArray(rule.value) && rule.value.includes(actual);
|
|
55
|
-
default:
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Walk controls and return the set of panel ids that contain at least one
|
|
62
|
-
* control whose attributeKey appears in `errors`. Used by the meta-box to
|
|
63
|
-
* auto-open panels that have validation errors.
|
|
64
|
-
*/
|
|
65
|
-
export function panelsContainingErrors(controls, errors) {
|
|
66
|
-
const errorKeys = new Set(Object.keys(errors || {}));
|
|
67
|
-
if (errorKeys.size === 0) return new Set();
|
|
68
|
-
|
|
69
|
-
const ids = new Set();
|
|
70
|
-
for (const c of controls) {
|
|
71
|
-
if (STRUCTURAL_TYPES.has(c.type)) continue;
|
|
72
|
-
if (c.attributeKey && errorKeys.has(c.attributeKey) && c.parentPanelId) {
|
|
73
|
-
ids.add(c.parentPanelId);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return ids;
|
|
77
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MediaPicker — a `MediaUpload`-shaped component that works on any
|
|
3
|
-
* admin screen.
|
|
4
|
-
*
|
|
5
|
-
* `@wordpress/block-editor`'s `MediaUpload` requires the `core/block-editor`
|
|
6
|
-
* data store, which is only initialised on screens that bootstrap the
|
|
7
|
-
* block editor itself (post.php, site-editor.php, widgets.php). On
|
|
8
|
-
* profile.php, term.php, options.php — anywhere we mount our post-fields
|
|
9
|
-
* bundle on a classic admin page — the store isn't there, so the
|
|
10
|
-
* MediaUpload modal silently fails to open and the image / gallery /
|
|
11
|
-
* file controls feel broken.
|
|
12
|
-
*
|
|
13
|
-
* This wrapper falls back to the lower-level `wp.media()` JS API on
|
|
14
|
-
* non-editor screens. wp.media is what WP's own avatar uploader uses
|
|
15
|
-
* and is loaded by wp_enqueue_media() — available on every admin page
|
|
16
|
-
* we care about. It's not React; we wrap it in the same render-prop
|
|
17
|
-
* shape MediaUpload exposes so callers don't need to know which path
|
|
18
|
-
* they're on.
|
|
19
|
-
*
|
|
20
|
-
* Shape:
|
|
21
|
-
* <MediaPicker
|
|
22
|
-
* onSelect={(media) => …} // single media object (or array)
|
|
23
|
-
* allowedTypes={['image']}
|
|
24
|
-
* value={123 | [123,124] | null}
|
|
25
|
-
* multiple={false}
|
|
26
|
-
* gallery={false}
|
|
27
|
-
* render={({ open }) => <button onClick={open}>Pick</button>}
|
|
28
|
-
* />
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
import { useContext } from '@wordpress/element';
|
|
32
|
-
import { MediaUpload } from '@wordpress/block-editor';
|
|
33
|
-
import { ControlContext } from '../control-context';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Translate a wp.media attachment model into the same plain object
|
|
37
|
-
* @wordpress/block-editor's MediaUpload onSelect receives.
|
|
38
|
-
*/
|
|
39
|
-
function toPlainAttachment(attachment) {
|
|
40
|
-
const a = attachment.toJSON ? attachment.toJSON() : attachment;
|
|
41
|
-
return {
|
|
42
|
-
id: a.id,
|
|
43
|
-
url: a.url,
|
|
44
|
-
alt: a.alt || '',
|
|
45
|
-
title: a.title || a.filename || '',
|
|
46
|
-
filename: a.filename || '',
|
|
47
|
-
caption: a.caption || '',
|
|
48
|
-
description: a.description || '',
|
|
49
|
-
mime: a.mime || a.type || '',
|
|
50
|
-
type: a.type || '',
|
|
51
|
-
subtype: a.subtype || '',
|
|
52
|
-
width: a.width,
|
|
53
|
-
height: a.height,
|
|
54
|
-
filesizeInBytes: a.filesizeInBytes,
|
|
55
|
-
sizes: a.sizes,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function openClassicMediaFrame({ allowedTypes, multiple, gallery, value, onSelect }) {
|
|
60
|
-
if (typeof window === 'undefined' || !window.wp || !window.wp.media) {
|
|
61
|
-
// eslint-disable-next-line no-console
|
|
62
|
-
console.warn('gcb-lite: wp.media not loaded — call wp_enqueue_media() on this screen.');
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// IMPORTANT: don't open directly into 'gallery-edit' — WP 7.0's
|
|
67
|
-
// media-views.js bootstraps menu/router state lazily, and asking for
|
|
68
|
-
// 'gallery-edit' before the menu state exists throws
|
|
69
|
-
// `Cannot read properties of undefined (reading 'get')` in
|
|
70
|
-
// setMenuTabPanelAriaAttributes. The supported gallery flow is to open
|
|
71
|
-
// the library with `multiple: true`, pre-select the existing images,
|
|
72
|
-
// and treat the result as a gallery on 'select'.
|
|
73
|
-
const isMulti = !!(gallery || multiple);
|
|
74
|
-
|
|
75
|
-
const frame = window.wp.media({
|
|
76
|
-
title: gallery ? 'Edit gallery' : (isMulti ? 'Select media' : 'Select media'),
|
|
77
|
-
button: { text: gallery ? 'Update gallery' : 'Use this media' },
|
|
78
|
-
library: allowedTypes ? { type: allowedTypes } : undefined,
|
|
79
|
-
multiple: isMulti,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Pre-select prior value so the user lands on the existing pick.
|
|
83
|
-
frame.on('open', () => {
|
|
84
|
-
const selection = frame.state().get('selection');
|
|
85
|
-
if (!selection) return;
|
|
86
|
-
const ids = Array.isArray(value) ? value : (value ? [value] : []);
|
|
87
|
-
ids.forEach((id) => {
|
|
88
|
-
if (!id) return;
|
|
89
|
-
const attachment = window.wp.media.attachment(id);
|
|
90
|
-
if (!attachment) return;
|
|
91
|
-
attachment.fetch();
|
|
92
|
-
selection.add([attachment]);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
frame.on('select', () => {
|
|
97
|
-
const selection = frame.state().get('selection');
|
|
98
|
-
if (!selection) return;
|
|
99
|
-
const picks = selection.toArray().map(toPlainAttachment);
|
|
100
|
-
if (isMulti) {
|
|
101
|
-
onSelect(picks);
|
|
102
|
-
} else {
|
|
103
|
-
onSelect(picks[0] || null);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
frame.open();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Decide which backend to use based on render surface:
|
|
112
|
-
*
|
|
113
|
-
* - Block Inspector ('sidebar' variant): MediaUpload from
|
|
114
|
-
* @wordpress/block-editor. That's the right tool inside the block
|
|
115
|
-
* editor — it integrates with the editor's upload flow + capability
|
|
116
|
-
* store.
|
|
117
|
-
*
|
|
118
|
-
* - Post-fields meta-box / Options / Taxonomy / User pages
|
|
119
|
-
* ('metabox' variant): wp.media() directly. These screens often DON'T
|
|
120
|
-
* bootstrap the block editor (we strip 'editor' support from
|
|
121
|
-
* field-only CPTs), and MediaUpload silently renders nothing when the
|
|
122
|
-
* editor stores aren't fully initialised. wp.media() is the lower-
|
|
123
|
-
* level JS API loaded by wp_enqueue_media() — works on any admin page.
|
|
124
|
-
*
|
|
125
|
-
* Surface decision is made via ControlContext, which post-fields.js
|
|
126
|
-
* sets to 'metabox' and the block Inspector leaves at 'sidebar'.
|
|
127
|
-
*/
|
|
128
|
-
export default function MediaPicker(props) {
|
|
129
|
-
const ctx = useContext(ControlContext);
|
|
130
|
-
|
|
131
|
-
if (ctx.variant !== 'metabox') {
|
|
132
|
-
return <MediaUpload {...props} />;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Metabox surface — synthesize the same render-prop shape with a
|
|
136
|
-
// wp.media() backend.
|
|
137
|
-
const open = () => openClassicMediaFrame(props);
|
|
138
|
-
return props.render ? props.render({ open }) : null;
|
|
139
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MediaTriggerBadges — places an inline clear (×) button to the right of
|
|
3
|
-
* a media-control toggle. Used by ImageField and FileField on the metabox
|
|
4
|
-
* surface. Edit affordance isn't needed — clicking the trigger itself
|
|
5
|
-
* opens the picker/popover.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { __ } from '@wordpress/i18n';
|
|
9
|
-
import { Button } from '@wordpress/components';
|
|
10
|
-
|
|
11
|
-
// Default sizing is content-width (inline-flex). In sidebar / Inspector
|
|
12
|
-
// contexts an external rule promotes it to full-width — see editor.scss
|
|
13
|
-
// "Sidebar / Inspector surface: media trigger fills width".
|
|
14
|
-
export default function MediaTriggerBadges({ children, onClear, hideClear }) {
|
|
15
|
-
return (
|
|
16
|
-
<span className="gcb-media-trigger-badges">
|
|
17
|
-
{children}
|
|
18
|
-
{!hideClear && (
|
|
19
|
-
<Button
|
|
20
|
-
variant="tertiary"
|
|
21
|
-
isDestructive
|
|
22
|
-
onClick={(e) => { e.stopPropagation(); e.preventDefault(); onClear?.(); }}
|
|
23
|
-
aria-label={__('Clear', 'gcblite')}
|
|
24
|
-
title={__('Clear', 'gcblite')}
|
|
25
|
-
>
|
|
26
|
-
✕
|
|
27
|
-
</Button>
|
|
28
|
-
)}
|
|
29
|
-
</span>
|
|
30
|
-
);
|
|
31
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sortable item — ported from the original GCB SortableItemComponent.
|
|
3
|
-
*
|
|
4
|
-
* Used by gallery, post-object (and any other future multi-select reorderable
|
|
5
|
-
* field) to render a draggable row with handle, title, and remove button.
|
|
6
|
-
*/
|
|
7
|
-
import { useSortable } from '@dnd-kit/sortable';
|
|
8
|
-
import { CSS } from '@dnd-kit/utilities';
|
|
9
|
-
import { __ } from '@wordpress/i18n';
|
|
10
|
-
|
|
11
|
-
const ICONS = {
|
|
12
|
-
post: {
|
|
13
|
-
viewBox: '0 0 24 24',
|
|
14
|
-
path: (
|
|
15
|
-
<>
|
|
16
|
-
<path d="M15.5 7.5h-7V9h7V7.5Zm-7 3.5h7v1.5h-7V11Zm7 3.5h-7V16h7v-1.5Z" />
|
|
17
|
-
<path d="M17 4H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2ZM7 5.5h10a.5.5 0 0 1 .5.5v12a.5.5 0 0 1-.5.5H7a.5.5 0 0 1-.5-.5V6a.5.5 0 0 1 .5-.5Z" />
|
|
18
|
-
</>
|
|
19
|
-
),
|
|
20
|
-
},
|
|
21
|
-
tag: {
|
|
22
|
-
viewBox: '0 0 24 24',
|
|
23
|
-
path: <path d="M12.5 4.5h-2v7h7v-2l-5-5zm-2.5 8.5v5h2v-5h-2zm5 5h2v-5h-2v5z" />,
|
|
24
|
-
},
|
|
25
|
-
image: {
|
|
26
|
-
viewBox: '0 0 24 24',
|
|
27
|
-
path: <path d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-4.86 8.86l-3 3.87L9 13.14 6 17h12l-3.86-5.14z" />,
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export default function SortableItem({ item, onRemove, icon = 'post', getTitle, thumb }) {
|
|
32
|
-
const {
|
|
33
|
-
attributes,
|
|
34
|
-
listeners,
|
|
35
|
-
setNodeRef,
|
|
36
|
-
transform,
|
|
37
|
-
transition,
|
|
38
|
-
isDragging,
|
|
39
|
-
} = useSortable({ id: item.id });
|
|
40
|
-
|
|
41
|
-
const style = {
|
|
42
|
-
transform: CSS.Transform.toString(transform),
|
|
43
|
-
transition,
|
|
44
|
-
opacity: isDragging ? 0.5 : 1,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const selectedIcon = ICONS[icon] || ICONS.post;
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<div
|
|
51
|
-
ref={setNodeRef}
|
|
52
|
-
style={style}
|
|
53
|
-
className="gcb-sortable-item"
|
|
54
|
-
{...attributes}
|
|
55
|
-
{...listeners}
|
|
56
|
-
>
|
|
57
|
-
<div className="gcb-sortable-drag-handle" aria-hidden>
|
|
58
|
-
<svg viewBox="0 0 20 20" width="12">
|
|
59
|
-
<path d="M7 2a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 2zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 8zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 14zm6-8a2 2 0 1 0-.001-4.001A2 2 0 0 0 13 6zm0 2a2 2 0 1 0 .001 4.001A2 2 0 0 0 13 8zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 13 14z" />
|
|
60
|
-
</svg>
|
|
61
|
-
</div>
|
|
62
|
-
|
|
63
|
-
{thumb ? (
|
|
64
|
-
<img
|
|
65
|
-
src={thumb}
|
|
66
|
-
alt=""
|
|
67
|
-
style={{
|
|
68
|
-
width: 28, height: 28, borderRadius: 2, objectFit: 'cover',
|
|
69
|
-
marginRight: 8, flexShrink: 0, border: '1px solid #ddd',
|
|
70
|
-
}}
|
|
71
|
-
/>
|
|
72
|
-
) : (
|
|
73
|
-
<svg
|
|
74
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
75
|
-
viewBox={selectedIcon.viewBox}
|
|
76
|
-
width="20"
|
|
77
|
-
height="20"
|
|
78
|
-
style={{ marginRight: 8, flexShrink: 0, opacity: 0.6 }}
|
|
79
|
-
>
|
|
80
|
-
{selectedIcon.path}
|
|
81
|
-
</svg>
|
|
82
|
-
)}
|
|
83
|
-
|
|
84
|
-
<span style={{
|
|
85
|
-
flex: 1,
|
|
86
|
-
overflow: 'hidden',
|
|
87
|
-
textOverflow: 'ellipsis',
|
|
88
|
-
whiteSpace: 'nowrap',
|
|
89
|
-
userSelect: 'none',
|
|
90
|
-
}}>
|
|
91
|
-
{getTitle ? getTitle(item) : (item.title?.rendered || item.name || __('(no title)', 'gcblite'))}
|
|
92
|
-
</span>
|
|
93
|
-
|
|
94
|
-
<button
|
|
95
|
-
type="button"
|
|
96
|
-
onClick={(e) => {
|
|
97
|
-
e.stopPropagation();
|
|
98
|
-
onRemove(item.id);
|
|
99
|
-
}}
|
|
100
|
-
onPointerDown={(e) => e.stopPropagation()}
|
|
101
|
-
className="gcb-sortable-remove"
|
|
102
|
-
aria-label={__('Remove', 'gcblite')}
|
|
103
|
-
>
|
|
104
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20">
|
|
105
|
-
<path d="M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z" />
|
|
106
|
-
</svg>
|
|
107
|
-
</button>
|
|
108
|
-
</div>
|
|
109
|
-
);
|
|
110
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ButtonGroup — multi-select shown as a row of toggle buttons. Each option
|
|
3
|
-
* looks like a pressable button; clicking toggles it on/off.
|
|
4
|
-
*
|
|
5
|
-
* Stored shape: array of selected values, same as checkbox-group.
|
|
6
|
-
* ['apple', 'cherry']
|
|
7
|
-
*
|
|
8
|
-
* Why not alias checkbox-group? Checkbox-group is checkboxes-in-a-column
|
|
9
|
-
* (vertical, ☑ ☐ ☐). ButtonGroup is buttons-in-a-row (horizontal, compact,
|
|
10
|
-
* visually weightier). Same data shape, different affordance.
|
|
11
|
-
*
|
|
12
|
-
* For single-select segmented controls use `toggle-group` instead.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { BaseControl, Button, __experimentalHStack as HStack } from '@wordpress/components';
|
|
16
|
-
|
|
17
|
-
export default function ButtonGroupField({ control, value, onChange }) {
|
|
18
|
-
const current = Array.isArray(value) ? value : [];
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<BaseControl
|
|
22
|
-
label={control.label}
|
|
23
|
-
help={control.helpText}
|
|
24
|
-
className="gcb-button-group-control components-base-control"
|
|
25
|
-
__nextHasNoMarginBottom
|
|
26
|
-
>
|
|
27
|
-
<HStack spacing={1} justify="flex-start" wrap>
|
|
28
|
-
{(control.options || []).map((option) => {
|
|
29
|
-
const isOn = current.includes(option.value);
|
|
30
|
-
return (
|
|
31
|
-
<Button
|
|
32
|
-
key={option.value}
|
|
33
|
-
variant={isOn ? 'primary' : 'secondary'}
|
|
34
|
-
onClick={() => {
|
|
35
|
-
const next = isOn
|
|
36
|
-
? current.filter((v) => v !== option.value)
|
|
37
|
-
: [...current, option.value];
|
|
38
|
-
onChange(next);
|
|
39
|
-
}}
|
|
40
|
-
aria-pressed={isOn}
|
|
41
|
-
>
|
|
42
|
-
{option.label}
|
|
43
|
-
</Button>
|
|
44
|
-
);
|
|
45
|
-
})}
|
|
46
|
-
</HStack>
|
|
47
|
-
</BaseControl>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CheckboxGroup — multi-select stored as an array of selected values.
|
|
3
|
-
*/
|
|
4
|
-
export default function CheckboxGroupField({ control, value, onChange }) {
|
|
5
|
-
const current = Array.isArray(value) ? value : [];
|
|
6
|
-
|
|
7
|
-
return (
|
|
8
|
-
<div className="components-base-control gcb-checkbox-group-control">
|
|
9
|
-
<div className="components-base-control__field">
|
|
10
|
-
<label className="components-base-control__label">{control.label}</label>
|
|
11
|
-
<div style={{
|
|
12
|
-
display: 'flex',
|
|
13
|
-
alignItems: 'stretch',
|
|
14
|
-
flexDirection: 'column',
|
|
15
|
-
gap: 6,
|
|
16
|
-
justifyContent: 'center',
|
|
17
|
-
}}>
|
|
18
|
-
{(control.options || []).map((option, index) => {
|
|
19
|
-
const isChecked = current.includes(option.value);
|
|
20
|
-
const id = `gcb-checkbox-${control.id || control.attributeKey}-${option.value}-${index}`;
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<div key={`${control.id || control.attributeKey}-${option.value}`} className="gcb-checkbox-item">
|
|
24
|
-
<label htmlFor={id} style={{
|
|
25
|
-
display: 'flex',
|
|
26
|
-
alignItems: 'center',
|
|
27
|
-
gap: 8,
|
|
28
|
-
cursor: 'pointer',
|
|
29
|
-
fontSize: 13,
|
|
30
|
-
}}>
|
|
31
|
-
<input
|
|
32
|
-
type="checkbox"
|
|
33
|
-
id={id}
|
|
34
|
-
checked={isChecked}
|
|
35
|
-
onChange={(e) => {
|
|
36
|
-
const next = e.target.checked
|
|
37
|
-
? [...current, option.value]
|
|
38
|
-
: current.filter((v) => v !== option.value);
|
|
39
|
-
onChange(next);
|
|
40
|
-
}}
|
|
41
|
-
style={{ width: 16, height: 16, cursor: 'pointer' }}
|
|
42
|
-
/>
|
|
43
|
-
<span>{option.label}</span>
|
|
44
|
-
</label>
|
|
45
|
-
</div>
|
|
46
|
-
);
|
|
47
|
-
})}
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
{control.helpText && (
|
|
51
|
-
<p className="components-base-control__help">{control.helpText}</p>
|
|
52
|
-
)}
|
|
53
|
-
</div>
|
|
54
|
-
);
|
|
55
|
-
}
|
package/src/controls/checkbox.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { CheckboxControl } from '@wordpress/components';
|
|
2
|
-
|
|
3
|
-
export default function CheckboxField({ control, value, onChange }) {
|
|
4
|
-
return (
|
|
5
|
-
<CheckboxControl
|
|
6
|
-
label={control.label}
|
|
7
|
-
help={control.helpText}
|
|
8
|
-
checked={!!value}
|
|
9
|
-
onChange={onChange}
|
|
10
|
-
__nextHasNoMarginBottom
|
|
11
|
-
/>
|
|
12
|
-
);
|
|
13
|
-
}
|
package/src/controls/code.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { TextareaControl } from '@wordpress/components';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Minimal code field — a monospace textarea. The original plugin used CodeMirror
|
|
5
|
-
* here; we can swap in once basic shape is proven. For now, monospace + tab-friendly
|
|
6
|
-
* is good enough for snippets.
|
|
7
|
-
*/
|
|
8
|
-
export default function CodeField({ control, value, onChange }) {
|
|
9
|
-
return (
|
|
10
|
-
<TextareaControl
|
|
11
|
-
label={control.label}
|
|
12
|
-
help={control.helpText}
|
|
13
|
-
placeholder={control.placeholder}
|
|
14
|
-
value={value ?? ''}
|
|
15
|
-
onChange={onChange}
|
|
16
|
-
rows={control.rows ?? 8}
|
|
17
|
-
className="gcblite-code-field"
|
|
18
|
-
__nextHasNoMarginBottom
|
|
19
|
-
/>
|
|
20
|
-
);
|
|
21
|
-
}
|