@siratik/wp-component-library 0.0.0-stage → 0.1.0

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/README.md CHANGED
@@ -1,3 +1,250 @@
1
- # Temporary Holding Version
1
+ # WP Component Library
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @siratik/wp-component-library
9
+ ```
10
+
11
+ ## Components
12
+
13
+ ### Icons
14
+
15
+ A full icon registry and picker system. Includes a WordPress data store (`wpcl/icons`), a modal-based picker UI with fuzzy search, library grouping, and virtualized rendering.
16
+
17
+ | Export | Description |
18
+ |---|---|
19
+ | `registerIconSet(set)` | Register a named icon library (eager `icons` or lazy `load`) |
20
+ | `removeIconSet(id)` | Remove a registered library |
21
+ | `loadIconSet(name)` | Load one lazy library on demand |
22
+ | `loadAllIconSets()` | Load every pending lazy library (picker calls this) |
23
+ | `registerIcons(set)` | Legacy alias — prefer `registerIconSet` |
24
+ | `iconStore` / `ICON_STORE_NAME` | The underlying `@wordpress/data` store (`wpcl/icons`) |
25
+ | `useIconSets()` | Hook — returns all registered icon sets |
26
+ | `useAllIcons()` | Hook — returns every icon across all sets |
27
+ | `useIcons(setId)` | Hook — returns icons for a specific set |
28
+ | `useIcon(name)` | Hook — resolves a single icon by name |
29
+ | `useGroupedIcons()` | Hook — icons grouped by set with headers |
30
+ | `Icon` | Renders a single SVG icon |
31
+ | `IconPicker` | Inspector panel control (preview + modal trigger) |
32
+ | `IconPickerToolbarButton` | Toolbar button variant of the picker |
33
+ | `InlineIconPicker` | Inline block-canvas picker |
34
+ | `IconPickerModal` | The modal itself — embeddable standalone |
35
+
36
+ ```jsx
37
+ import { registerIconSet, IconPicker } from "@siratik/wp-component-library";
38
+
39
+ // Eager library
40
+ registerIconSet({
41
+ name: "my-icons",
42
+ label: "My Icons",
43
+ priority: 10,
44
+ icons: [{ name: "star", label: "Star", source: "<svg>...</svg>" }],
45
+ });
46
+
47
+ // Lazy library (code-split — loads when the picker opens)
48
+ registerIconSet({
49
+ name: "home-services",
50
+ label: "Home Services",
51
+ priority: 120,
52
+ load: () => import("./home-services.js").then((m) => m.homeServicesIcons),
53
+ });
54
+ ```
55
+
56
+ Theme editor bundles (separate webpack builds) should use `window.wpcl.icons.registerIconSet`
57
+ from the wp-blocks bootstrap — not a direct import — so the store is not duplicated.
58
+
59
+ ---
60
+
61
+ ### Block Extension
62
+
63
+ A drop-in replacement for `@10up/block-components` `registerBlockExtension`. Extends any block (or all blocks) with extra attributes and inspector controls using WordPress hook filters — no block source changes required.
64
+
65
+ | Export | Description |
66
+ |---|---|
67
+ | `registerBlockExtension(blockName, options)` | Extend one or more blocks with attributes and controls |
68
+ | `unregisterBlockExtension(blockName, extensionName)` | Remove a previously registered extension |
69
+
70
+ ```jsx
71
+ import { registerBlockExtension } from "@siratik/wp-component-library";
72
+ import { InspectorAdvancedControls } from "@wordpress/block-editor";
73
+ import { ToggleControl } from "@wordpress/components";
74
+
75
+ registerBlockExtension("core/paragraph", {
76
+ extensionName: "my-extension",
77
+ attributes: {
78
+ hideOnMobile: { type: "boolean", default: false },
79
+ },
80
+ classNameGenerator: ({ hideOnMobile }) =>
81
+ hideOnMobile ? "is-hidden-mobile" : "",
82
+ Edit: ({ attributes, setAttributes }) => (
83
+ <InspectorAdvancedControls>
84
+ <ToggleControl
85
+ label="Hide on mobile"
86
+ checked={attributes.hideOnMobile}
87
+ onChange={(value) => setAttributes({ hideOnMobile: value })}
88
+ />
89
+ </InspectorAdvancedControls>
90
+ ),
91
+ });
92
+ ```
93
+
94
+ **Options:**
95
+
96
+ | Option | Type | Description |
97
+ |---|---|---|
98
+ | `extensionName` | `string` | Unique identifier for this extension |
99
+ | `attributes` | `Object` | Extra attribute definitions (same shape as `block.json`) |
100
+ | `Edit` | `Component` | React component rendered in the block sidebar |
101
+ | `classNameGenerator` | `(attrs) => string` | Returns a CSS class string added to the block |
102
+ | `inlineStyleGenerator` | `(attrs) => Object` | Returns inline styles added to the block |
103
+ | `order` | `'before'\|'after'` | Whether `Edit` renders before or after the block's own controls. Default: `'after'` |
104
+
105
+ Pass `"*"` or `"all"` as `blockName` to extend every registered block. Arrays of block names are also supported.
106
+
107
+ ---
108
+
109
+ ### Media & Images
110
+
111
+ Consistent media upload controls across all editor contexts.
112
+
113
+ | Export | Description |
114
+ |---|---|
115
+ | `AttachmentImage` | Displays a WordPress attachment with responsive srcset support |
116
+ | `EditorMediaUpload` | Media upload for the block canvas |
117
+ | `InspectorMediaUpload` | Media upload for the inspector sidebar |
118
+ | `SettingsMediaUpload` | Media upload for settings pages |
119
+ | `ToolbarMediaUpload` | Media upload as a toolbar button |
120
+ | `ImageControls` | Focal point, object-fit, and aspect ratio controls |
121
+ | `useAspectRatioOptions()` | Hook — standard aspect ratio option set |
122
+
123
+ ```jsx
124
+ import { InspectorMediaUpload } from "@siratik/wp-component-library";
125
+
126
+ <InspectorMediaUpload
127
+ buttonTitle="Upload Logo"
128
+ onSelect={handleSelect}
129
+ onRemove={handleRemove}
130
+ imageId={attributes.logoId}
131
+ imageUrl={attributes.logoUrl}
132
+ />
133
+ ```
134
+
135
+ ---
136
+
137
+ ### Data & Query
138
+
139
+ Post query builder controls that compose into a consistent query panel.
140
+
141
+ | Export | Description |
142
+ |---|---|
143
+ | `PostTypeSelect` | Post type picker |
144
+ | `TaxonomySelect` | Taxonomy term picker |
145
+ | `PostsPerPageControl` | Per-page number control |
146
+ | `ColumnCountControl` | Grid column count control |
147
+ | `OrderBySelect` / `defaultOrderOptions` | Sort order selector |
148
+ | `DisplayTypeSelect` | Display mode picker |
149
+ | `SelectionModeControl` | Manual vs. automatic post selection toggle |
150
+ | `ManualPostSelector` | Searchable manual post picker |
151
+ | `ManualTermSelector` | Searchable manual term picker |
152
+ | `HideCurrentPostControl` | Toggle to exclude the current post |
153
+ | `CardTemplatePartSelect` / `CardTemplatePartPanel` | Card template part selector |
154
+ | `getDefaultCardSlugForPostType()` | Utility — resolves default card slug |
155
+ | `reorderByIds()` | Utility — reorders a post array to match a saved ID order |
156
+ | `useOrderedTerms()` | Hook — returns terms in stored sort order |
157
+
158
+ ---
159
+
160
+ ### Form & Input
161
+
162
+ | Export | Description |
163
+ |---|---|
164
+ | `AttributesPanel` | Dynamic HTML attribute editor (id, rel, title, etc.) |
165
+ | `useAttributes()` | Hook for managing the attributes array state |
166
+ | `SortableSelect` | Token field with drag-to-reorder |
167
+ | `tokensToString()` | Utility — converts token array to comma string |
168
+ | `VariableField` | Text input with `@`-triggered variable autocomplete |
169
+ | `VariableInserter` | Standalone variable insertion toolbar button |
170
+ | `CaptchaPlaceholder` | Editor placeholder for CAPTCHA fields (multi-provider) |
171
+
172
+ ---
173
+
174
+ ### Repeater
175
+
176
+ Drag-and-drop repeatable item list.
177
+
178
+ | Export | Description |
179
+ |---|---|
180
+ | `Repeater` | The repeater container |
181
+ | `DragHandle` | Drag handle sub-component |
182
+ | `RemoveButton` | Remove item sub-component |
183
+
184
+ ```jsx
185
+ import { Repeater } from "@siratik/wp-component-library";
186
+
187
+ <Repeater
188
+ items={items}
189
+ renderItem={renderItem}
190
+ onAdd={handleAdd}
191
+ onRemove={handleRemove}
192
+ onReorder={handleReorder}
193
+ addButtonText="Add Item"
194
+ />
195
+ ```
196
+
197
+ ---
198
+
199
+ ### Meta
200
+
201
+ | Export | Description |
202
+ |---|---|
203
+ | `MetaPanel` | Document sidebar modal for editing post meta |
204
+ | `useMetaGatedEditorVisibility` | Hide meta-gated blocks in loop previews when meta is empty |
205
+ | `isMetaValueEmpty` | Shared empty check for meta-gated visibility |
206
+ | `isTemplateEditorSurface` | Detect template / template-part editor context |
207
+
208
+ ---
209
+
210
+ ### Block Appender
211
+
212
+ Customisable appender buttons for inner blocks.
213
+
214
+ | Export | Description |
215
+ |---|---|
216
+ | `CustomBlockAppender` | Standard appender |
217
+ | `CustomColumnAppender` | Column-context appender |
218
+ | `CustomInlineAppender` | Inline canvas appender |
219
+ | `CustomInspectorAppender` | Inspector sidebar appender |
220
+
221
+ ---
222
+
223
+ ### Badge
224
+
225
+ | Export | Description |
226
+ |---|---|
227
+ | `Badge` | Small status/label badge component |
228
+
229
+ ---
230
+
231
+ ### Button
232
+
233
+ | Export | Description |
234
+ |---|---|
235
+ | `ButtonFrontend` | Minimal frontend button — safe to use outside the editor |
236
+
237
+ ---
238
+
239
+ ## Requirements
240
+
241
+ - WordPress 6.5+
242
+ - `@wordpress/scripts`
243
+
244
+ ## Credits
245
+
246
+ 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.
247
+
248
+ ## Disclaimer
249
+
250
+ This library is provided "as is" without warranty of any kind. Always test components in your specific environment before deploying to production.
@@ -0,0 +1,20 @@
1
+ <?php return array(
2
+ 'dependencies' => array(
3
+ 'react',
4
+ 'react-dom',
5
+ 'react-jsx-runtime',
6
+ 'wp-block-editor',
7
+ 'wp-blocks',
8
+ 'wp-components',
9
+ 'wp-compose',
10
+ 'wp-core-data',
11
+ 'wp-data',
12
+ 'wp-editor',
13
+ 'wp-element',
14
+ 'wp-hooks',
15
+ 'wp-i18n',
16
+ 'wp-keycodes',
17
+ 'wp-media-utils'
18
+ ),
19
+ 'version' => 'ddaddbc0f9b3a1701879'
20
+ );