@qkix/strapi-plugin-better-blocks 0.23.0 → 0.23.1

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
@@ -9,10 +9,10 @@
9
9
  <a href="https://www.npmjs.com/package/@qkix/strapi-plugin-better-blocks">
10
10
  <img alt="npm downloads" src="https://img.shields.io/npm/dm/@qkix/strapi-plugin-better-blocks.svg" />
11
11
  </a>
12
- <a href="https://github.com/qkix/strapi-plugin-better-blocks/blob/main/LICENSE">
12
+ <a href="https://github.com/qkix/strapi-plugins/blob/main/LICENSE">
13
13
  <img alt="license" src="https://img.shields.io/npm/l/@qkix/strapi-plugin-better-blocks.svg" />
14
14
  </a>
15
- <a href="https://buymeacoffee.com/k11k">
15
+ <a href="https://buymeacoffee.com/qkix">
16
16
  <img alt="Buy Me a Coffee" src="https://img.shields.io/badge/Buy%20Me%20a%20Coffee-support-FFDD00?logo=buymeacoffee&logoColor=black" />
17
17
  </a>
18
18
  </p>
@@ -33,8 +33,9 @@
33
33
  6. [Custom Color Presets](#custom-color-presets)
34
34
  7. [Media Embeds (CSP Configuration)](#media-embeds-csp-configuration)
35
35
  8. [Frontend Rendering](#frontend-rendering)
36
- 9. [Contributing](#contributing)
37
- 10. [License](#license)
36
+ 9. [Adding Your Own Block Type](#adding-your-own-block-type)
37
+ 10. [Contributing](#contributing)
38
+ 11. [License](#license)
38
39
 
39
40
  ---
40
41
 
@@ -358,7 +359,7 @@ loop={player.loop} preload={player.preload}>` wrapped in an alignment container
358
359
  map to `flex-start`/`center`/`flex-end`; `none` flows full-width). Include fallback text and a download
359
360
  link inside `<audio>` for unsupported browsers, and associate the `caption` via `aria-describedby`.
360
361
  `file.url` is already backend-prefixed for Media Library assets, and the `title`/`caption` keys are
361
- omitted when empty. See the full React/Astro renderer contract on [issue #43](https://github.com/qkix/strapi-plugin-better-blocks/issues/43).
362
+ omitted when empty. See the full React/Astro renderer contract on [issue #43](https://github.com/qkix/strapi-plugins/issues/43).
362
363
 
363
364
  #### Embed JSON shape (for frontend renderers)
364
365
 
@@ -709,7 +710,7 @@ const MyComponent = ({ content }) => {
709
710
 
710
711
  The renderer supports all Better Blocks features including text colors, background highlights, images, and all standard block types.
711
712
 
712
- See the [@qkix/better-blocks-react-renderer](https://github.com/qkix/strapi-plugin-better-blocks/tree/main/packages/better-blocks-react-renderer) documentation for details.
713
+ See the [@qkix/better-blocks-react-renderer](https://github.com/qkix/strapi-plugins/tree/main/packages/better-blocks-react-renderer) documentation for details.
713
714
 
714
715
  ## Requirements
715
716
 
@@ -717,6 +718,78 @@ See the [@qkix/better-blocks-react-renderer](https://github.com/qkix/strapi-plug
717
718
  - **Strapi** v5.x
718
719
  - **Slate** 0.94.1 (bundled with Strapi)
719
720
 
721
+ ## Adding Your Own Block Type
722
+
723
+ Another Strapi plugin — or your own admin customization in
724
+ `src/admin/app.tsx` — can add a block type to the editor. Call `registerBlock`
725
+ from `register()`, which runs before any editor is mounted.
726
+
727
+ ```tsx
728
+ import { registerBlock } from '@qkix/strapi-plugin-better-blocks/strapi-admin';
729
+ import { Transforms } from 'slate';
730
+
731
+ export default {
732
+ register() {
733
+ registerBlock({
734
+ type: 'key-figure',
735
+ // What it holds: 'void' (attributes only, the default), 'inline' (text),
736
+ // or 'blocks' (nested blocks). Slate's void handling follows from this.
737
+ content: 'void',
738
+
739
+ // Needed to be offered in the "+" Insert menu and the slash command. A
740
+ // block without all three still renders, it just is not offered.
741
+ icon: KeyFigureIcon,
742
+ label: 'Key figure',
743
+ insert: (editor) => {
744
+ Transforms.insertNodes(editor, {
745
+ type: 'key-figure',
746
+ value: '42',
747
+ // Slate refuses a document whose nodes are not elements, and an
748
+ // element is something with a children array. A void block saved
749
+ // without this placeholder takes the whole editor down.
750
+ children: [{ type: 'text', text: '' }],
751
+ });
752
+ },
753
+
754
+ renderElement: ({ attributes, children, element }) => (
755
+ <div {...attributes} contentEditable={false}>
756
+ {element.value}
757
+ {children}
758
+ </div>
759
+ ),
760
+ });
761
+ },
762
+ };
763
+ ```
764
+
765
+ Registering is the only supported way in. Editing this package to add a block is
766
+ how the editor, both renderers and the validator ended up with four separate
767
+ hardcoded lists of block types in the first place.
768
+
769
+ `registerBlock` throws if the type shadows a built-in or is registered twice —
770
+ either one would otherwise surface much later as a block that mysteriously does
771
+ not appear.
772
+
773
+ ### The rest of the pipeline
774
+
775
+ The same definition object is understood by the core and both renderers, so a
776
+ package writes `type` and `content` once:
777
+
778
+ | Where | What it adds |
779
+ | ----------------------------------------------- | ------------------------------------------------- |
780
+ | `registerBlock` here | the editor: rendering, Insert menu, slash command |
781
+ | `validateDocument(doc, { blocks })` in the core | `validate`, so the block is not "unknown" |
782
+ | `migrateDocument(doc, { blocks })` in the core | `migrate`, called for every node of the type |
783
+ | `blockPlugins` on either renderer | `component`, so the front end draws it |
784
+
785
+ A renderer given no plugin for a type renders nothing for it — content authored
786
+ with a registered block is not lost, it is simply not drawn until the front end
787
+ knows about it too.
788
+
789
+ See [`@qkix/better-blocks-core`](https://github.com/qkix/strapi-plugins/tree/main/packages/better-blocks-core#registering-a-block-type)
790
+ for the definition shape, and `examples/strapi-app/src/admin/app.tsx` for a
791
+ working registration.
792
+
720
793
  ## Contributing
721
794
 
722
795
  Contributions are welcome! This package lives in a monorepo together with the
@@ -724,7 +797,7 @@ React and Astro renderers. The easiest way to get started is with Docker:
724
797
 
725
798
  ```bash
726
799
  # Clone the repository
727
- git clone https://github.com/qkix/strapi-plugin-better-blocks.git
800
+ git clone https://github.com/qkix/strapi-plugins.git
728
801
  cd strapi-plugin-better-blocks
729
802
 
730
803
  docker compose up --build
@@ -777,14 +850,14 @@ pnpm test
777
850
 
778
851
  ## Community & Support
779
852
 
780
- - [GitHub Issues](https://github.com/qkix/strapi-plugin-better-blocks/issues) &mdash; Bug reports and feature requests
781
- - [GitHub Discussions](https://github.com/qkix/strapi-plugin-better-blocks/discussions) &mdash; Questions and ideas
853
+ - [GitHub Issues](https://github.com/qkix/strapi-plugins/issues) &mdash; Bug reports and feature requests
854
+ - [GitHub Discussions](https://github.com/qkix/strapi-plugins/discussions) &mdash; Questions and ideas
782
855
 
783
856
  ## Support this project
784
857
 
785
858
  This plugin is built and maintained in my free time, and it's free for everyone. If it has saved you time on a project, you can help keep it caffeinated and actively developed:
786
859
 
787
- <a href="https://buymeacoffee.com/k11k">
860
+ <a href="https://buymeacoffee.com/qkix">
788
861
  <img alt="Buy Me a Coffee" src="https://img.shields.io/badge/Buy%20Me%20a%20Coffee-support-FFDD00?logo=buymeacoffee&logoColor=black&style=for-the-badge" />
789
862
  </a>
790
863