Skip to content

Commit 6902dfd

Browse files
committed
Merge reviewed contributions and add public block metadata APIs [all]
Integrate #110, #111, #112, #113, and #114 into 7.7.2 with rebuilt bundles, docs, and regression coverage. Preserve custom reset labels and row preferences; validate plural translations and locale switching. Fixes #115. Fixes #95.
5 parents d239992 + 35ff295 + c6a4fd6 + 66bbd54 + 229aae1 commit 6902dfd

66 files changed

Lines changed: 3983 additions & 90 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CLAUDE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ section markers in Markdown files.
147147
| `npm run catalog:blocks` | Run catalog block test |
148148
| `composer cs` | Check PHPCS |
149149
| `composer cs:fix` | Auto-fix PHPCS issues |
150+
| `npm run i18n` | Update `languages/` after changing translatable strings |
150151

151152
### Docs Commands
152153

‎blockstudio.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Requires PHP: 8.2
1010
* License: GPL2+
1111
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
12+
* Update URI: https://blockstudio.dev
1213
*
1314
* @package Blockstudio
1415
*/

‎docs/docs/blocks/assets/index.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,46 @@ Blockstudio provides a zero-config asset pipeline for your blocks. Drop CSS, SCS
1616
- [Registering Assets](/docs/blocks/assets/registering):File naming conventions and enqueue behavior
1717
- [Processing](/docs/blocks/assets/processing):SCSS compilation, ES module imports, and minification
1818
- [Code Field](/docs/blocks/assets/code-field):Inline code editing via the code field type
19+
20+
## Inspecting a Block's Assets
21+
22+
`bs_block_assets('theme/card')` returns the discovered frontend and editor-canvas
23+
assets of a registered Blockstudio block. Call it after block registration, on `init` or later.
24+
Unknown blocks, non-Blockstudio blocks, and blocks without assets return `[]`.
25+
The helper does not render the block, enqueue anything, or trigger compilation.
26+
27+
```php
28+
$assets = bs_block_assets('theme/card');
29+
30+
// Each entry has this shape:
31+
[
32+
'type' => 'style',
33+
'handle' => 'blockstudio-theme-card-style-css',
34+
'url' => '/wp-content/blockstudio/cache/.../style-123.css?ver=123',
35+
'inline' => false,
36+
'scope' => ['frontend', 'editor'],
37+
'html' => '<link ...>',
38+
];
39+
```
40+
41+
- `type` is `style` for CSS and `module` for JavaScript. Blockstudio's file-based
42+
JavaScript assets use ES modules, including inline scripts.
43+
- `handle` is the stable asset identifier used by Blockstudio's renderer and
44+
the `blockstudio/assets/disable` filter. It need not be enqueued in WordPress.
45+
- `url` is the resolved URL of the existing compiled asset, including its version,
46+
or the source URL when no compiled file exists. It is `null` for inline assets.
47+
- `inline` distinguishes inline `<style>`/`<script>` output from external files.
48+
- `scope` lists the contexts where the asset applies: `frontend` and `editor`
49+
for shared files, and only one for view/editor files.
50+
- `html` contains the ready-to-use tag from the normal asset renderer. Inline
51+
content, scoped CSS, UI style layers, and render-time disable filters are
52+
handled the same way as ordinary block output.
53+
54+
Missing, empty, disabled, and uncompiled SCSS files are omitted. WordPress-enqueued
55+
admin and block-editor parent-document assets are excluded. The list is
56+
limited to the block's own discovered files. It is not a dependency closure:
57+
nested blocks, code-field values, WordPress-enqueued handles, module CSS imports,
58+
Tailwind, and shared UI/Interactivity runtimes may depend on rendered content.
59+
Use [`Render::document()`](/docs/blocks/rendering#structured-compositions-and-complete-documents)
60+
for a complete self-contained preview. Use `bs_block_fields()` to inspect
61+
the registered field definitions.

‎docs/docs/blocks/attributes/field-types.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ Renders a set of fields that can be repeated.
604604
|----------|------|-------------|
605605
| `min` | `number` | Minimum amount of rows. |
606606
| `max` | `number` | Maximum amount of rows. |
607+
| `minimized` | `boolean` | Collapse the existing rows when the editor opens. Rows added in the editor start expanded. |
607608
| `textButton` | `string` | Text for the add button. |
608609
| `textMinimized` | `string \| object` | Text that will be displayed when rows are minimized. |
609610
| `textRemove` | `string \| boolean` | Text to display in alert when removing repeater row. |

‎docs/docs/blocks/rendering.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,34 @@ render several independent documents in one request should call
104104
`Blockstudio\Batch_Render::reset()` between them; `Canvas::documents()` does
105105
this automatically.
106106

107+
## Inspecting Blocks
108+
109+
Use `bs_block_fields()` after block registration (on `init` or later) to get
110+
the resolved field definitions without reading internal registries:
111+
112+
```php
113+
$fields = bs_block_fields('theme/card');
114+
115+
if ($fields === null) {
116+
// Unknown block, or not a Blockstudio block.
117+
}
118+
```
119+
120+
The return value is the registered field-definition array, including attribute
121+
filters, expanded custom fields, overrides, and nested groups, tabs, and
122+
repeaters. A Blockstudio block with no fields returns `[]`. The result is a
123+
copy: changing it does not change the registered block.
124+
125+
These are definitions, not saved values or an automatic content validator.
126+
When validating saved block markup, read values from
127+
`attrs.blockstudio.attributes` and walk the definitions according to each
128+
field's structure and type. WordPress-owned attributes remain separate.
129+
130+
Use [`bs_block_assets()`](/docs/blocks/assets#inspecting-a-blocks-assets) to
131+
inspect the block's discovered CSS and JavaScript. For a complete preview
132+
document, including nested blocks and shared runtime dependencies, use
133+
`Render::document()` as described above.
134+
107135
## PHP Functions
108136

109137
### Without Data

‎docs/docs/general/meta.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"title": "General",
3-
"pages": ["getting-started", "settings"]
3+
"pages": ["getting-started", "settings", "translations"]
44
}

‎docs/docs/general/translations.md‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Translations
3+
description: Use Blockstudio in your language and help translate it.
4+
path: 'general/translations'
5+
order: 3
6+
section: "Start"
7+
subsection: 'Setup'
8+
meta_title: 'Translations'
9+
meta_description: 'Use Blockstudio in your language and help translate it.'
10+
---
11+
12+
# Translations
13+
14+
Blockstudio ships its translations in the `languages` folder. WordPress uses them whenever the site language, or the language in a user profile, matches one of them. This works the same way when Blockstudio runs as a plugin, a must-use plugin, or a Composer package.
15+
16+
## Available languages
17+
18+
| Language | Locale |
19+
| --- | --- |
20+
| German | `de_DE` |
21+
| German (formal) | `de_DE_formal` |
22+
23+
The translations cover the field controls in the block editor, the admin page, the canvas, the devtools overlay, and the messages of the REST endpoints. Labels and help texts in your own `block.json` files belong to your theme or plugin and use its text domain.
24+
25+
## Override a translation
26+
27+
Translation files in `wp-content/languages/plugins` take precedence over the bundled ones, for the PHP strings (`blockstudio-de_DE.mo` or `blockstudio-de_DE.l10n.php`) as well as for the scripts (one file per script handle, for example `blockstudio-de_DE-blockstudio-blocks.json`).
28+
29+
## Contribute a translation
30+
31+
Every language is a `.po` file that you can edit with any text editor or with a translation tool such as Poedit. Corrections and new languages are welcome as pull requests.
32+
33+
1. To add a language, copy `languages/blockstudio.pot` to `languages/blockstudio-<locale>.po`, for example `blockstudio-fr_FR.po`, and set the `Language` and `Plural-Forms` headers. To improve a language, edit its existing `.po` file.
34+
2. Translate the strings. Keep placeholders such as `%1$s` in the translation.
35+
3. Run `npm run i18n`. It writes the `.mo`, `.l10n.php`, and `.json` files that WordPress loads.
36+
4. Commit the `.po` file together with the generated files and open a pull request.
37+
38+
If you cannot run `npm`, a pull request with the `.po` file alone is fine. The generated files can be added before the merge.
39+
40+
## Translatable strings in the code
41+
42+
- PHP: use the WordPress functions with the `blockstudio` text domain, for example `__( 'Invalid block.', 'blockstudio' )`.
43+
- JavaScript: import `__` from `@/utils/__` and pass a literal string, for example `__( 'Add row' )`. A string that is assembled at runtime cannot be translated, so use one literal string per variant.
44+
- A new script bundle with translatable strings needs an entry in `scripts/i18n.ts` and a call to `wp_set_script_translations()` with the same handle and `Translations::script_path()`.
45+
46+
After changing strings, run `npm run i18n`. It updates `languages/blockstudio.pot` and every `.po` file. New strings stay in English until a translator fills them in. `npm run check` runs `npm run i18n:check`, which fails when the translation files are out of date or a string cannot be extracted.

‎docs/guides/field-patterns.md‎

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -479,42 +479,14 @@ When a condition inside a repeater needs to check a field outside the repeater,
479479

480480
Without `"context": "main"`, the condition would look for a `showDescriptions` field inside the repeater row. With it, the condition checks the root-level toggle.
481481

482-
### Repeater with tabs inside
482+
### Tabs inside repeaters
483483

484-
Tabs work inside repeaters to organize complex row content:
484+
Tabs are not available inside repeaters: a `tabs` field inside a repeater row renders an empty row. Keep the fields of a row flat instead. For long rows, a custom row label (`textMinimized`) keeps collapsed rows readable, and conditions inside the row can hide fields that only some rows need, as shown in the patterns above.
485485

486-
```json
487-
{
488-
"id": "slides",
489-
"type": "repeater",
490-
"label": "Slides",
491-
"textMinimized": { "id": "title", "fallback": "Slide" },
492-
"attributes": [
493-
{
494-
"type": "tabs",
495-
"attributes": [
496-
{
497-
"type": "group",
498-
"title": "Content",
499-
"attributes": [
500-
{ "id": "title", "type": "text", "label": "Title" },
501-
{ "id": "body", "type": "textarea", "label": "Body" }
502-
]
503-
},
504-
{
505-
"type": "group",
506-
"title": "Media",
507-
"attributes": [
508-
{ "id": "image", "type": "files", "label": "Image", "multiple": false }
509-
]
510-
}
511-
]
512-
}
513-
]
514-
}
515-
```
516-
517-
Each slide row has its own tabbed interface with Content and Media tabs.
486+
Set `"minimized": true` on a repeater to start existing rows collapsed. Newly
487+
added rows open immediately. Expanded exceptions are remembered in this browser
488+
across editor reloads; this is an editing preference, not saved post content.
489+
Repeaters without `minimized` keep their existing expanded-by-default behavior.
518490

519491
## Media Patterns
520492

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-primitives'), 'version' => '6dcbff0c7d82e20929e3');
1+
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-primitives'), 'version' => '3883f89443b4008d7f2d');

‎includes/admin/assets/blocks/index.tsx.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)