@siratik/wp-component-library 0.1.1 → 0.1.2
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/LICENSE +5 -0
- package/README.md +43 -5
- package/components/attachment-image/README.md +118 -0
- package/components/attachment-image/index.js +105 -0
- package/components/attributes-panel/README.md +92 -0
- package/components/attributes-panel/index.js +324 -0
- package/components/badge/README.md +61 -0
- package/components/badge/index.js +105 -0
- package/components/block-appender/README.md +158 -0
- package/components/block-appender/index.js +135 -0
- package/components/block-extension/index.js +214 -0
- package/components/business-hours/SpecialHoursControl.js +211 -0
- package/components/business-hours/WeeklyHoursControl.js +419 -0
- package/components/business-hours/index.js +8 -0
- package/components/button/README.md +172 -0
- package/components/button/index.js +84 -0
- package/components/captcha-placeholder/CloudflareTurnstile.js +111 -0
- package/components/captcha-placeholder/GoogleRecaptcha.js +132 -0
- package/components/captcha-placeholder/HCaptcha.js +99 -0
- package/components/captcha-placeholder/README.md +228 -0
- package/components/captcha-placeholder/index.js +39 -0
- package/components/captcha-placeholder/styles.js +33 -0
- package/components/geocoder/AddressEntryControl.js +390 -0
- package/components/geocoder/GeocoderSearchControl.js +353 -0
- package/components/geocoder/countryOptions.js +66 -0
- package/components/geocoder/geocoder.js +400 -0
- package/components/geocoder/index.js +16 -0
- package/components/icon-picker/Icon.js +53 -0
- package/components/icon-picker/IconPicker.js +70 -0
- package/components/icon-picker/IconPickerModal.js +474 -0
- package/components/icon-picker/IconPickerToolbarButton.js +60 -0
- package/components/icon-picker/InlineIconPicker.js +92 -0
- package/components/icon-picker/api.js +181 -0
- package/components/icon-picker/config-bootstrap.js +108 -0
- package/components/icon-picker/hooks.js +157 -0
- package/components/icon-picker/index.js +39 -0
- package/components/icon-picker/load-script.js +33 -0
- package/components/icon-picker/loaders.js +79 -0
- package/components/icon-picker/store.js +223 -0
- package/components/icon-picker/styles.js +232 -0
- package/components/icon-picker/utils.js +138 -0
- package/components/layout/README.md +268 -0
- package/components/link-tools-panel/README.md +49 -0
- package/components/link-tools-panel/index.js +198 -0
- package/components/link-tools-panel/styles.js +90 -0
- package/components/media/README.md +288 -0
- package/components/media/SettingsMediaUpload.js +187 -0
- package/components/media/editor-media-upload.js +65 -0
- package/components/media/image-controls.js +196 -0
- package/components/media/index.js +13 -0
- package/components/media/inspector-media-upload.js +290 -0
- package/components/media/toolbar-media-upload.js +53 -0
- package/components/media/utils/aspect-ratios.js +118 -0
- package/components/meta/MetaPanel.js +75 -0
- package/components/meta/README.md +46 -0
- package/components/meta/index.js +6 -0
- package/components/meta/meta-gated-editor.js +282 -0
- package/components/query/README.md +340 -0
- package/components/query/cardTemplatePartPanel.js +69 -0
- package/components/query/cardTemplatePartSelect.js +165 -0
- package/components/query/cardTemplatePartUtils.js +119 -0
- package/components/query/columnCountControl.js +63 -0
- package/components/query/displayTypeSelect.js +52 -0
- package/components/query/examples.js +166 -0
- package/components/query/hideCurrentPostControl.js +47 -0
- package/components/query/index.js +20 -0
- package/components/query/manualPostSelector.js +125 -0
- package/components/query/manualTermSelector.js +141 -0
- package/components/query/orderBySelect.js +95 -0
- package/components/query/postTypeSelect.js +67 -0
- package/components/query/postsPerPageControl.js +51 -0
- package/components/query/selectionModeControl.js +61 -0
- package/components/query/taxonomySelect.js +139 -0
- package/components/query/utils.js +75 -0
- package/components/repeater/README.md +159 -0
- package/components/repeater/index.js +829 -0
- package/components/segmented-bar/README.md +30 -0
- package/components/segmented-bar/index.js +68 -0
- package/components/sortable-select/README.md +153 -0
- package/components/sortable-select/custom-sortable-token.js +127 -0
- package/components/sortable-select/index.js +693 -0
- package/components/style-picker/README.md +36 -0
- package/components/style-picker/index.js +92 -0
- package/components/variable-field/README.md +299 -0
- package/components/variable-field/index.js +592 -0
- package/components/variable-field/value-to-chip-html.js +38 -0
- package/components/variable-inserter/README.md +68 -0
- package/components/variable-inserter/index.js +168 -0
- package/constants/statusColors.js +1 -1
- package/editor.js +16 -0
- package/index.js +127 -0
- package/package.json +21 -13
- package/utils/kitaris-localize.js +128 -0
- package/utils/slug-aware-color-setter.js +27 -0
- package/build/index.asset.php +0 -20
- package/build/index.js +0 -1242
package/LICENSE
ADDED
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# WP Component Library
|
|
1
|
+
# Siratik WP Component Library
|
|
2
2
|
|
|
3
3
|
A comprehensive library of reusable React components, hooks, and utilities for WordPress block development. Built for use with `@wordpress/scripts` and the Gutenberg block editor.
|
|
4
4
|
|
|
@@ -8,6 +8,14 @@ A comprehensive library of reusable React components, hooks, and utilities for W
|
|
|
8
8
|
npm install @siratik/wp-component-library
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
The package ships source (ES modules + JSX), so build it with `@wordpress/scripts` or another
|
|
12
|
+
bundler that transpiles dependencies. There are two entry points:
|
|
13
|
+
|
|
14
|
+
- `@siratik/wp-component-library`: everything below except the post-editor-only exports.
|
|
15
|
+
- `@siratik/wp-component-library/editor`: `MetaPanel`, `AttributesPanel`, `useAttributes` and the
|
|
16
|
+
meta-gated editor helpers, which need `@wordpress/editor`. Keeping them separate means screens
|
|
17
|
+
outside the post editor never load `@wordpress/editor`.
|
|
18
|
+
|
|
11
19
|
## Components
|
|
12
20
|
|
|
13
21
|
### Icons
|
|
@@ -161,8 +169,8 @@ Post query builder controls that compose into a consistent query panel.
|
|
|
161
169
|
|
|
162
170
|
| Export | Description |
|
|
163
171
|
|---|---|
|
|
164
|
-
| `AttributesPanel` | Dynamic HTML attribute editor (id, rel, title, etc.) |
|
|
165
|
-
| `useAttributes()` | Hook for managing the attributes array state |
|
|
172
|
+
| `AttributesPanel` | Dynamic HTML attribute editor (id, rel, title, etc.). From `/editor` |
|
|
173
|
+
| `useAttributes()` | Hook for managing the attributes array state. From `/editor` |
|
|
166
174
|
| `SortableSelect` | Token field with drag-to-reorder |
|
|
167
175
|
| `tokensToString()` | Utility — converts token array to comma string |
|
|
168
176
|
| `VariableField` | Text input with `@`-triggered variable autocomplete |
|
|
@@ -198,6 +206,8 @@ import { Repeater } from "@siratik/wp-component-library";
|
|
|
198
206
|
|
|
199
207
|
### Meta
|
|
200
208
|
|
|
209
|
+
Import these from `@siratik/wp-component-library/editor`.
|
|
210
|
+
|
|
201
211
|
| Export | Description |
|
|
202
212
|
|---|---|
|
|
203
213
|
| `MetaPanel` | Document sidebar modal for editing post meta |
|
|
@@ -236,11 +246,19 @@ Customisable appender buttons for inner blocks.
|
|
|
236
246
|
|
|
237
247
|
---
|
|
238
248
|
|
|
249
|
+
### StylePicker
|
|
250
|
+
|
|
251
|
+
| Export | Description |
|
|
252
|
+
|---|---|
|
|
253
|
+
| `StylePicker` | One of a few options, shown like core's block Styles panel (for a style-like attribute) |
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
239
257
|
### Button
|
|
240
258
|
|
|
241
259
|
| Export | Description |
|
|
242
260
|
|---|---|
|
|
243
|
-
| `ButtonFrontend` | Minimal frontend button — safe to use outside the editor |
|
|
261
|
+
| `ButtonFrontend` | Minimal frontend button — safe to use outside the editor. `style` (Fill / Outline) and `variant` (Primary, Secondary, Tertiary, Text Link) |
|
|
244
262
|
|
|
245
263
|
---
|
|
246
264
|
|
|
@@ -253,6 +271,26 @@ Customisable appender buttons for inner blocks.
|
|
|
253
271
|
|
|
254
272
|
Several patterns and ideas in this library were inspired by the excellent open-source work from **[10up](https://github.com/10up)**, particularly [`@10up/block-components`](https://github.com/10up/block-components). Their `registerBlockExtension` API and icon picker concepts were especially influential in shaping the equivalent features here. We're grateful for the work they've done for the WordPress developer community.
|
|
255
273
|
|
|
274
|
+
## License
|
|
275
|
+
|
|
276
|
+
GPL-3.0-or-later — see `LICENSE`.
|
|
277
|
+
|
|
256
278
|
## Disclaimer
|
|
257
279
|
|
|
258
|
-
This
|
|
280
|
+
This software is provided "as is", without warranty of any kind, express or
|
|
281
|
+
implied, including the warranties of merchantability and fitness for a
|
|
282
|
+
particular purpose. To the extent permitted by applicable law, the authors and
|
|
283
|
+
copyright holders, together with their parent, subsidiary, and affiliated
|
|
284
|
+
companies and contributors, are not liable for any direct, indirect,
|
|
285
|
+
incidental, or consequential damages arising from its use or inability to use
|
|
286
|
+
it, including loss of data, revenue, or site availability.
|
|
287
|
+
|
|
288
|
+
The software does not guarantee that your site is secure, ranks in search
|
|
289
|
+
results, or complies with privacy or other laws; that remains the site owner's
|
|
290
|
+
responsibility. AI-generated content can be inaccurate and should be reviewed
|
|
291
|
+
before publishing. Third-party services the software connects to are governed
|
|
292
|
+
by their own terms.
|
|
293
|
+
|
|
294
|
+
Keep a current backup and test changes on a staging site before applying them
|
|
295
|
+
to a live site. See sections 15 and 16 of the GNU General Public License,
|
|
296
|
+
version 3, for the full terms.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# AttachmentImage Component
|
|
2
|
+
|
|
3
|
+
A flexible image display component that fetches and renders WordPress media attachments with responsive features and caption support. This component serves as a JavaScript companion to WordPress's `wp_get_attachment()` function.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- WordPress media integration with automatic attachment fetching
|
|
8
|
+
- Responsive image handling with srcSet support
|
|
9
|
+
- Multiple WordPress image sizes support
|
|
10
|
+
- Flexible caption display (media caption or custom)
|
|
11
|
+
- BEM-style CSS class generation
|
|
12
|
+
- Graceful handling of missing images
|
|
13
|
+
- Figure element wrapping with optional disable
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```jsx
|
|
18
|
+
import { AttachmentImage } from '@siratik/wp-component-library/components/attachment-image';
|
|
19
|
+
|
|
20
|
+
// Basic usage
|
|
21
|
+
<AttachmentImage
|
|
22
|
+
imageId={123}
|
|
23
|
+
size="large"
|
|
24
|
+
/>
|
|
25
|
+
|
|
26
|
+
// With caption and custom styling
|
|
27
|
+
<AttachmentImage
|
|
28
|
+
imageId={456}
|
|
29
|
+
size="full"
|
|
30
|
+
showCaption={true}
|
|
31
|
+
className="hero-image"
|
|
32
|
+
wrapClass="hero-figure"
|
|
33
|
+
aspectRatio="16/9"
|
|
34
|
+
maxWidth="1200px"
|
|
35
|
+
/>
|
|
36
|
+
|
|
37
|
+
// Without figure wrapper
|
|
38
|
+
<AttachmentImage
|
|
39
|
+
imageId={789}
|
|
40
|
+
includeFigure={false}
|
|
41
|
+
customAlt="Custom alt text"
|
|
42
|
+
/>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Props
|
|
46
|
+
|
|
47
|
+
| Prop | Type | Default | Description |
|
|
48
|
+
|------|------|---------|-------------|
|
|
49
|
+
| `imageId` | `number` | Required | WordPress media attachment ID |
|
|
50
|
+
| `className` | `string` | `"image"` | CSS class for the img element |
|
|
51
|
+
| `customAlt` | `string` | - | Override default alt text from media library |
|
|
52
|
+
| `showCaption` | `boolean` | `false` | Display image caption below image |
|
|
53
|
+
| `wrapClass` | `string` | - | CSS class for the wrapper figure element |
|
|
54
|
+
| `includeFigure` | `boolean` | `true` | Wrap image in figure element |
|
|
55
|
+
| `size` | `string` | `"full"` | WordPress image size (thumbnail, medium, large, full, or custom) |
|
|
56
|
+
| `maxWidth` | `string` | `"100px"` | Maximum width for responsive sizing |
|
|
57
|
+
| `aspectRatio` | `string` | `"4/3"` | CSS aspect ratio value |
|
|
58
|
+
| `caption` | `string` | - | Custom caption text (overrides media caption) |
|
|
59
|
+
|
|
60
|
+
## WordPress Image Sizes
|
|
61
|
+
|
|
62
|
+
The component supports all registered WordPress image sizes:
|
|
63
|
+
- `thumbnail` - Small square crop
|
|
64
|
+
- `medium` - Medium size
|
|
65
|
+
- `large` - Large size
|
|
66
|
+
- `full` - Original uploaded size
|
|
67
|
+
- Custom sizes registered in your theme
|
|
68
|
+
|
|
69
|
+
## CSS Classes
|
|
70
|
+
|
|
71
|
+
The component generates BEM-style classes:
|
|
72
|
+
- Image: `{className}` (default: "image")
|
|
73
|
+
- Figure wrapper: `{wrapClass}` or `{className}__wrap`
|
|
74
|
+
- Caption: `{className}__caption`
|
|
75
|
+
|
|
76
|
+
## Examples
|
|
77
|
+
|
|
78
|
+
### Hero Image with Caption
|
|
79
|
+
```jsx
|
|
80
|
+
<AttachmentImage
|
|
81
|
+
imageId={heroImageId}
|
|
82
|
+
size="full"
|
|
83
|
+
showCaption={true}
|
|
84
|
+
className="hero"
|
|
85
|
+
aspectRatio="21/9"
|
|
86
|
+
maxWidth="100vw"
|
|
87
|
+
/>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Gallery Thumbnail
|
|
91
|
+
```jsx
|
|
92
|
+
<AttachmentImage
|
|
93
|
+
imageId={thumbnailId}
|
|
94
|
+
size="thumbnail"
|
|
95
|
+
className="gallery-item"
|
|
96
|
+
includeFigure={false}
|
|
97
|
+
/>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Responsive Card Image
|
|
101
|
+
```jsx
|
|
102
|
+
<AttachmentImage
|
|
103
|
+
imageId={cardImageId}
|
|
104
|
+
size="medium"
|
|
105
|
+
className="card-image"
|
|
106
|
+
aspectRatio="1/1"
|
|
107
|
+
maxWidth="400px"
|
|
108
|
+
customAlt="Product preview"
|
|
109
|
+
/>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Notes
|
|
113
|
+
|
|
114
|
+
- The component uses WordPress's `core` data store to fetch media information
|
|
115
|
+
- If the image is not found, the component returns `null` gracefully
|
|
116
|
+
- Alt text priority: `customAlt` prop > media library alt > empty string
|
|
117
|
+
- The component automatically generates responsive srcSet for better performance
|
|
118
|
+
- Additional props can be passed through to the img element
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useSelect } from "@wordpress/data";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AttachmentImage
|
|
5
|
+
*
|
|
6
|
+
* @param {object} props
|
|
7
|
+
* @param {number} props.id The ID of the image to display.
|
|
8
|
+
* @param {string} props.className Optional. The class to add to the image.
|
|
9
|
+
* @param {string} props.customAlt Optional. The custom alt text to use for the image.
|
|
10
|
+
* @param {boolean} props.showCaption Optional. Whether to show the caption.
|
|
11
|
+
* @param {string} props.wrapClass Optional. The class to add to the figure.
|
|
12
|
+
* @param {boolean} props.includeFigure Optional. Whether to include the figure.
|
|
13
|
+
* @param {string} props.size Optional. The size of the image.
|
|
14
|
+
* @param {string} props.maxWidth Optional. The maximum width of the image.
|
|
15
|
+
* @param {string} [props.objectFit] Optional CSS object-fit (e.g. "cover").
|
|
16
|
+
* @returns {*} React JSX
|
|
17
|
+
*/
|
|
18
|
+
function AttachmentImage({
|
|
19
|
+
imageId,
|
|
20
|
+
className = "image",
|
|
21
|
+
customAlt = null,
|
|
22
|
+
showCaption = false,
|
|
23
|
+
wrapClass = null,
|
|
24
|
+
includeFigure = true,
|
|
25
|
+
size = "full",
|
|
26
|
+
maxWidth = "100px",
|
|
27
|
+
aspectRatio = "4/3",
|
|
28
|
+
objectFit = null,
|
|
29
|
+
caption = null,
|
|
30
|
+
...overrideProps
|
|
31
|
+
}) {
|
|
32
|
+
const { image } = useSelect((select) => ({
|
|
33
|
+
image: select("core").getEntityRecord("postType", "attachment", imageId),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
if (!imageId || imageId === 0 || !image) { return null; }
|
|
37
|
+
|
|
38
|
+
const appendToFirstClass = (classString, appendix) => {
|
|
39
|
+
const classes = classString.split(" ");
|
|
40
|
+
if (classes.length > 0) {
|
|
41
|
+
classes[0] = `${classes[0]}${appendix}`;
|
|
42
|
+
}
|
|
43
|
+
return classes.join(" ");
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const imageAttributes = () => {
|
|
47
|
+
const attributes = {
|
|
48
|
+
className: appendToFirstClass(className, "__img"),
|
|
49
|
+
src: image.source_url,
|
|
50
|
+
alt: customAlt || image.alt_text,
|
|
51
|
+
width: image.media_details.width,
|
|
52
|
+
height: image.media_details.height,
|
|
53
|
+
sizes: `(max-width: ${maxWidth}) 100vw, ${maxWidth}`,
|
|
54
|
+
style: {
|
|
55
|
+
aspectRatio,
|
|
56
|
+
...(objectFit ? { objectFit } : {}),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (
|
|
61
|
+
image.media_details &&
|
|
62
|
+
image.media_details.sizes &&
|
|
63
|
+
image.media_details.sizes[size]
|
|
64
|
+
) {
|
|
65
|
+
attributes.src = image.media_details.sizes[size].source_url;
|
|
66
|
+
attributes.srcSet = image.media_details.sizes[size].source_url;
|
|
67
|
+
attributes.width = image.media_details.sizes[size].width;
|
|
68
|
+
attributes.height = image.media_details.sizes[size].height;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return { ...attributes, ...overrideProps };
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// eslint-disable-next-line jsx-a11y/alt-text -- alt comes from imageAttributes().
|
|
75
|
+
const imgElement = <img {...imageAttributes()} />;
|
|
76
|
+
const captionElement =
|
|
77
|
+
showCaption && caption ? (
|
|
78
|
+
<figcaption className={appendToFirstClass(className, "__caption")}>
|
|
79
|
+
{caption}
|
|
80
|
+
</figcaption>
|
|
81
|
+
) : null;
|
|
82
|
+
|
|
83
|
+
if (includeFigure) {
|
|
84
|
+
const figureClass = wrapClass
|
|
85
|
+
? `${appendToFirstClass(className, "__figure")} ${wrapClass}`
|
|
86
|
+
: appendToFirstClass(className, "__figure");
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<figure className={figureClass}>
|
|
90
|
+
{imgElement}
|
|
91
|
+
{captionElement}
|
|
92
|
+
</figure>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<>
|
|
98
|
+
{imgElement}
|
|
99
|
+
{captionElement}
|
|
100
|
+
</>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Export Component
|
|
105
|
+
export { AttachmentImage };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# AttributesPanel Component
|
|
2
|
+
|
|
3
|
+
A ToolsPanel-based component that provides attribute management for blocks in the Site Editor, with ComboboxControl for selecting from available meta fields and HTML attributes.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Uses WordPress ToolsPanel for consistent UI
|
|
8
|
+
- ComboboxControl populated with:
|
|
9
|
+
- Common HTML attributes (id, class, style, etc.)
|
|
10
|
+
- ARIA attributes
|
|
11
|
+
- Data attributes
|
|
12
|
+
- Available post meta fields
|
|
13
|
+
- Dynamic attribute addition/removal
|
|
14
|
+
- Per-attribute reset functionality
|
|
15
|
+
- Global reset all attributes
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
import { AttributesPanel, useAttributes } from '@siratik/wp-component-library/components/attributes-panel';
|
|
21
|
+
|
|
22
|
+
function MyComponent() {
|
|
23
|
+
const { attributes, setAttributes } = useAttributes([
|
|
24
|
+
{ id: 'id', label: 'ID', value: '' },
|
|
25
|
+
{ id: 'alt', label: 'Alt Text', value: '' }
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<AttributesPanel
|
|
30
|
+
attributes={attributes}
|
|
31
|
+
onChange={setAttributes}
|
|
32
|
+
panelId="my-attributes-panel"
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Props
|
|
39
|
+
|
|
40
|
+
### AttributesPanel
|
|
41
|
+
|
|
42
|
+
- `attributes` (Array): Array of attribute objects with `id`, `label`, and `value` properties
|
|
43
|
+
- `onChange` (Function): Callback when attributes change, receives updated attributes array
|
|
44
|
+
- `panelId` (string): Unique ID for the tools panel (default: 'attributes-panel')
|
|
45
|
+
|
|
46
|
+
### useAttributes Hook
|
|
47
|
+
|
|
48
|
+
Returns an object with:
|
|
49
|
+
- `attributes`: Current attributes array
|
|
50
|
+
- `setAttributes`: Set entire attributes array
|
|
51
|
+
- `updateAttribute(id, value)`: Update a specific attribute
|
|
52
|
+
- `addAttribute(label, value)`: Add new attribute
|
|
53
|
+
- `removeAttribute(id)`: Remove attribute by id
|
|
54
|
+
- `resetAttributes()`: Reset all attribute values
|
|
55
|
+
- `getAttributeValue(id)`: Get value for specific attribute
|
|
56
|
+
|
|
57
|
+
## Site Editor Integration
|
|
58
|
+
|
|
59
|
+
The component is integrated into the Site Editor for specific core blocks (image, paragraph, heading, button) via the block extension system. It automatically:
|
|
60
|
+
|
|
61
|
+
1. Detects when in Site Editor context
|
|
62
|
+
2. Shows appropriate default attributes for each block type
|
|
63
|
+
3. Populates ComboboxControl with available meta fields
|
|
64
|
+
4. Saves attributes to block's customAttributes array
|
|
65
|
+
|
|
66
|
+
## Available Attribute Options
|
|
67
|
+
|
|
68
|
+
The ComboboxControl is populated with:
|
|
69
|
+
|
|
70
|
+
### HTML Attributes
|
|
71
|
+
- id, class, style, title, alt, rel, target, href, src
|
|
72
|
+
|
|
73
|
+
### Data Attributes
|
|
74
|
+
- data-id, data-type, data-value
|
|
75
|
+
|
|
76
|
+
### ARIA Attributes
|
|
77
|
+
- aria-label, aria-describedby, aria-hidden
|
|
78
|
+
|
|
79
|
+
### Meta Fields
|
|
80
|
+
- All available post meta fields (prefixed with "Meta:")
|
|
81
|
+
- Common WordPress meta fields like _thumbnail_id, _wp_page_template
|
|
82
|
+
|
|
83
|
+
Users can also type custom attribute names not in the list.
|
|
84
|
+
|
|
85
|
+
## Security
|
|
86
|
+
|
|
87
|
+
The panel refuses event handler attribute names (anything starting with `on`, such as `onclick`) and `javascript:`, `vbscript:` and `data:` URLs in URL attributes (`href`, `src`, `srcset`, `action`, `formaction`, `poster`, `xlink:href`). This is only a guard in the editor UI. Saved attributes can still be changed by other means, so the code that outputs them must:
|
|
88
|
+
|
|
89
|
+
- allowlist the attribute names it renders, and
|
|
90
|
+
- escape every value on output (`esc_attr()`, and `esc_url()` for URL attributes).
|
|
91
|
+
|
|
92
|
+
`isUnsafeAttributeName()` and `isUnsafeAttributeValue()` are exported from this module so consumers can reuse the same checks.
|