@qkix/strapi-plugin-better-blocks 0.23.0 → 0.23.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/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
 
@@ -93,13 +94,13 @@
93
94
  - **To-do Lists** &mdash; Checkbox list items with click-to-toggle and strikethrough on checked items
94
95
  - **Tables** &mdash; Insert tables with header row, add/remove rows and columns via hover toolbar
95
96
  - **Embeds (generic iframe / URL)** &mdash; Insert any third-party embed from the `+` Insert menu, the `/embed` slash command, or the toolbar's media button. Two modes: **URL** (YouTube, Vimeo, Loom, Wistia, Dailymotion and api.video are converted to an iframe automatically) and **Embed code** (paste any platform's `<iframe>` snippet). The pasted markup is never stored verbatim &mdash; the iframe is _rebuilt_ from an attribute allowlist over an https-only `src`, so scripts, event handlers and unknown attributes cannot survive into your frontend. Live preview in the editor, plus aspect ratio (16:9 / 21:9 / 4:3 / 1:1 / custom), alignment, caption and an accessible title. Supersedes the older YouTube/Vimeo-only **media embed** block, which still renders existing content but is no longer inserted
96
- - **Video (provider-aware)** &mdash; Insert a video from the `+` Insert menu or the `/video` slash command. Source it from the **Media Library**, a **direct URL**, or a hosting provider &mdash; Mux, api.video and Cloudinary URLs are detected automatically, and a bare **Mux playback ID** fills in the stream URL and poster frame for you. When [`strapi-plugin-mux-video-uploader`](https://github.com/muxinc/strapi-plugin-mux-video-uploader) is installed and configured, a **Mux** button lists and searches your Mux assets inline with thumbnails. Set a poster image, title, caption, WebVTT captions/transcript, alignment, aspect ratio, and player behaviour (controls, autoplay, muted, loop)
97
+ - **Video (provider-aware)** &mdash; Insert a video from the `+` Insert menu or the `/video` slash command. Source it from the **Media Library**, a **direct URL**, or a hosting provider &mdash; Mux, api.video and Cloudinary URLs are detected automatically, and a bare **Mux playback ID** fills in the stream URL and poster frame for you. When [`strapi-plugin-mux-video-uploader`](https://github.com/muxinc/strapi-plugin-mux-video-uploader) is installed and configured, a **Mux** button lists and searches your Mux assets inline with thumbnails. Set a poster image, title, caption, WebVTT captions/transcript, alignment, aspect ratio, and player behavior (controls, autoplay, muted, loop)
97
98
  - **Math (LaTeX / KaTeX)** &mdash; Inline and block math rendered with KaTeX; insert from the toolbar, the `/math` slash command, the blocks selector, or by typing `$$ ` (block) / `$…$ ` (inline), then edit in a full-screen modal with a side-by-side source editor and live preview. Block math supports multi-line equations via `\\` and LaTeX environments such as `aligned` and `cases`
98
99
  - **Diagrams (Mermaid)** &mdash; Block-level [Mermaid](https://mermaid.js.org/) diagrams (flowcharts, sequence, class, state, ER, pie, and more) rendered to SVG; insert from the blocks selector, the `/mermaid` slash command, or by typing ` ```mermaid ` then a space, then edit the definition in a full-screen modal with live preview and zoom controls. Theme follows Strapi's light/dark mode
99
100
  - **Callouts / Admonitions** &mdash; GitHub-style callouts in five variants (`Note`, `Tip`, `Important`, `Warning`, `Caution`) with an optional custom title and nested rich-text content (paragraphs, lists, links). Insert from the blocks selector or the `/note`, `/tip`, `/important`, `/warning`, `/caution` slash commands; switch variant, edit the title, or remove from the header popover. Colors follow Strapi's design tokens and adapt to light/dark mode
100
101
  - **Details / Collapsible** &mdash; GitHub-style collapsible `<details>` / `<summary>` sections for managing content density. Insert from the blocks selector or the `/details` slash command; edit the summary label and toggle open/closed-by-default (`defaultOpen`) from the header. Holds full rich-text block content (paragraphs, lists, tables, images) and supports nesting. Admins can set the default summary text and choose a GitHub-minimal (default) or Custom (bordered + background) style. Stored as `{ "type": "details", "summary": "…", "defaultOpen": false, "children": [...] }`
101
102
  - **Button (WordPress-style CTA)** &mdash; Insert a styled call-to-action button from the blocks selector or by typing `[button]` then a space. Two modes: **Link** (URL + open-in-new-tab + ARIA label) and **File** (pick any asset from the Media Library to render a download button with optional file size and type icon, and choose direct download or preview-in-new-tab). A full-screen editor with live preview controls alignment, background/text colors (including hover colors), border radius, font size/weight, padding presets, border, and a custom CSS class. One-click **style presets** (Primary / Secondary / Outline / Filled) keep CTAs on-brand. Admins can set default button colors and customize the presets. Stored as `{ "type": "button", "buttonType": "link" | "file", "label": "…", "alignment": "center", "link": {…} | "file": {…}, "style": {…} }`
102
- - **Audio (HTML5 player)** &mdash; Insert an audio block from the `+` Insert menu, the `/audio` slash command, or by typing `[audio]` then a space. Pick a file from the Media Library (upload included) or paste a direct URL, with a live native `<audio>` preview in the editor. Set an optional title and caption, block alignment (left / center / right / none), and player behaviour: controls, autoplay, loop, and preload (none / metadata / auto). Stored as `{ "type": "audio", "file": {…}, "title": "…", "caption": "…", "player": {…}, "alignment": "center" }`
103
+ - **Audio (HTML5 player)** &mdash; Insert an audio block from the `+` Insert menu, the `/audio` slash command, or by typing `[audio]` then a space. Pick a file from the Media Library (upload included) or paste a direct URL, with a live native `<audio>` preview in the editor. Set an optional title and caption, block alignment (left / center / right / none), and player behavior: controls, autoplay, loop, and preload (none / metadata / auto). Stored as `{ "type": "audio", "file": {…}, "title": "…", "caption": "…", "player": {…}, "alignment": "center" }`
103
104
  - **Horizontal Line** &mdash; Insert `<hr>` dividers between content blocks
104
105
  - **Text Alignment** &mdash; Per-block left, center, right, and justify alignment
105
106
  - **Undo / Redo** &mdash; Toolbar buttons wired to Slate's built-in history
@@ -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