nuxt-strapi-blocks-renderer 0.0.5 → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Frederik Bußmann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,260 @@
1
1
  # Nuxt Strapi Blocks Renderer
2
2
 
3
- Renderer module for the Strapi CMS blocks text element.
3
+ [![Github Actions][github-actions-src]][github-actions-href]
4
+ [![NPM version][npm-version-src]][npm-version-href]
5
+ [![NPM downloads][npm-downloads-src]][npm-downloads-href]
6
+ [![License][license-src]][license-href]
7
+
8
+ A fully customizable Nuxt 3 module for rendering text with the new Blocks rich text editor element from Strapi CMS.
9
+
10
+ ## Installation
11
+
12
+ 1. Install the Blocks renderer:
13
+
14
+ ```bash
15
+ npm install nuxt-strapi-blocks-renderer
16
+ ```
17
+
18
+ 2. Add the module to `nuxt.config.{ts|js}`:
19
+
20
+ ```typescript
21
+ modules: ['nuxt-strapi-blocks-renderer']
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ To render text, use the `StrapiBlocksText` component:
27
+
28
+ ```vue
29
+ <StrapiBlocksText :nodes="blockNodes" />
30
+ ```
31
+
32
+ In this example, the `blockNodes` are taken from the JSON response which Strapi provides when using the Blocks rich
33
+ text editor element:
34
+
35
+ ```vue
36
+ <script setup lang="ts">
37
+ import type { BlockNode } from 'nuxt-strapi-blocks-renderer/dist/runtime/types';
38
+ import type { Restaurant } from '~/types';
39
+
40
+ const route = useRoute();
41
+ const { findOne } = useStrapi();
42
+
43
+ // Fetch restaurants data from Strapi
44
+ const response = await findOne<Restaurant>('restaurants', route.params.id);
45
+
46
+ // Obtain blocks text nodes from description field
47
+ const blockNodes: BlockNode[] = response.data.attributes.description;
48
+ </script>
49
+
50
+ <template>
51
+ <StrapiBlocksText :nodes="blockNodes" />
52
+ </template>
53
+ ```
54
+
55
+ To use the `useStrapi` composable, install the [Strapi Nuxt module](https://strapi.nuxtjs.org/).
56
+
57
+ ### Advanced Usage
58
+
59
+ In situations where your project requires specific styling or behavior for certain HTML tags such as `<a>`, `<p>`,
60
+ and others, you can override the default rendering components used by the Nuxt Strapi Blocks Renderer.
61
+ This flexibility allows you to tailor the rendering to align with your project's unique design and functional needs.
62
+
63
+ #### Global Component Registration
64
+
65
+ First, ensure that your components are globally registered in your Nuxt app.
66
+ This step is crucial for your custom components to be recognized and used by the renderer.
67
+
68
+ In your Nuxt configuration (`nuxt.config.{js|ts}`), add:
69
+
70
+ ```typescript
71
+ components: {
72
+ dirs: [
73
+ {
74
+ path: '~/components',
75
+ },
76
+ ],
77
+ global: true,
78
+ },
79
+ ```
80
+
81
+ #### Customizing the Paragraph Tag
82
+
83
+ To customize the rendering of the paragraph (`<p>`) tag, you need to create a corresponding Vue component.
84
+ The name of the component follows a predefined pattern: `'StrapiBlocksText' + [NodeName] + 'Node.vue'`.
85
+ To override the default paragraph tag, we create a file called `StrapiBlocksTextParagraphNode.vue`.
86
+
87
+ ```vue
88
+ <!-- components/StrapiBlocksTextParagraphNode.vue -->
89
+ <template>
90
+ <p class="my-custom-class-for-p">
91
+ <slot />
92
+ </p>
93
+ </template>
94
+ ```
95
+
96
+ This component assigns a custom class `my-custom-class-for-p` to the paragraph tag, which can be styled as needed.
97
+
98
+ #### Other Custom Tags
99
+
100
+ You can apply similar customizations to all other HTML tags used by the renderer.
101
+
102
+ ##### Headings
103
+
104
+ Custom heading tags (`<h1>`, `<h2>`, `<h3>`, etc.):
105
+
106
+ ```vue
107
+ <!-- components/StrapiBlocksTextHeading1Node.vue -->
108
+ <template>
109
+ <h1 class="my-custom-class-for-h1">
110
+ <slot />
111
+ </h1>
112
+ </template>
113
+
114
+ <!-- components/StrapiBlocksTextHeading2Node.vue -->
115
+ <template>
116
+ <h2 class="my-custom-class-for-h2">
117
+ <slot />
118
+ </h2>
119
+ </template>
120
+ ```
121
+
122
+ This pattern also extends to the `h3`, `h4`, `h5` and `h6` tags.
123
+
124
+ ##### Lists
125
+
126
+ Custom list tags (`<ol>`, `<ul>` and `<li>`):
127
+
128
+ ```vue
129
+ <!-- components/StrapiBlocksTextOrderedListNode.vue -->
130
+ <template>
131
+ <ol class="my-custom-class-for-ol">
132
+ <slot />
133
+ </ol>
134
+ </template>
135
+
136
+ <!-- components/StrapiBlocksTextUnorderedListNode.vue -->
137
+ <template>
138
+ <ul class="my-custom-class-for-ul">
139
+ <slot />
140
+ </ul>
141
+ </template>
142
+
143
+ <!-- components/StrapiBlocksTextListItemInlineNode.vue -->
144
+ <template>
145
+ <li class="my-custom-class-for-li">
146
+ <slot />
147
+ </li>
148
+ </template>
149
+ ```
150
+
151
+ ##### Blockquotes and Codes
152
+
153
+ Custom blockquote and code tags (`<blockquote>`, `<pre>`):
154
+
155
+ ```vue
156
+ <!-- components/StrapiBlocksTextQuoteNode.vue -->
157
+ <template>
158
+ <blockquote class="my-custom-class-for-blockquote">
159
+ <slot />
160
+ </blockquote>
161
+ </template>
162
+
163
+ <!-- components/StrapiBlocksTextCodeNode.vue -->
164
+ <template>
165
+ <pre class="my-custom-class-for-pre">
166
+ <slot />
167
+ </pre>
168
+ </template>
169
+ ```
170
+
171
+ ##### Inline text nodes
172
+
173
+ Custom inline text nodes (`<strong>`, `<em>`, `<u>`, `<del>`, `<code>`):
174
+
175
+ ```vue
176
+ <!-- components/StrapiBlocksTextBoldInlineNode.vue -->
177
+ <template>
178
+ <strong class="my-custom-class-for-strong">
179
+ <slot />
180
+ </strong>
181
+ </template>
182
+
183
+ <!-- components/StrapiBlocksTextItalicInlineNode.vue -->
184
+ <template>
185
+ <em class="my-custom-class-for-em">
186
+ <slot />
187
+ </em>
188
+ </template>
189
+
190
+ <!-- components/StrapiBlocksTextUnderlineInlineNode.vue -->
191
+ <template>
192
+ <u class="my-custom-class-for-u">
193
+ <slot />
194
+ </u>
195
+ </template>
196
+
197
+ <!-- components/StrapiBlocksTextStrikethroughInlineNode.vue -->
198
+ <template>
199
+ <del class="my-custom-class-for-del">
200
+ <slot />
201
+ </del>
202
+ </template>
203
+
204
+ <!-- components/StrapiBlocksTextCodeInlineNode.vue -->
205
+ <template>
206
+ <code class="my-custom-class-for-code">
207
+ <slot />
208
+ </code>
209
+ </template>
210
+ ```
211
+
212
+ ##### Links
213
+
214
+ Custom link tag (`<a>`):
215
+
216
+ ```vue
217
+ <!-- components/StrapiBlocksTextLinkInlineNode.vue -->
218
+ <script setup lang="ts">
219
+ const props = defineProps<{
220
+ url: string;
221
+ }>();
222
+ </script>
223
+
224
+ <template>
225
+ <a :href="props.url" class="my-custom-class-for-a">
226
+ <slot />
227
+ </a>
228
+ </template>
229
+ ```
230
+
231
+ When rendering a link tag, the url gets passed as the `url` component property.
232
+
233
+ ##### Images
234
+
235
+ Custom image tag (`<img>`):
236
+
237
+ ```vue
238
+ <!-- components/StrapiBlocksTextImageNode.vue -->
239
+ <script setup lang="ts">
240
+ const props = defineProps<{
241
+ image: any;
242
+ }>();
243
+ </script>
244
+
245
+ <template>
246
+ <img
247
+ class="my-custom-class-for-img"
248
+ :src="props.image.url"
249
+ :alt="props.image.alternativeText"
250
+ :width="props.image.width"
251
+ :height="props.image.height"
252
+ >
253
+ </template>
254
+ ```
255
+
256
+ When rendering an image tag, the image object gets passed as the `image` component property.
257
+ You can also use different image components here, i.e. `NuxtImg` or others.
4
258
 
5
259
  ## Development
6
260
 
@@ -11,15 +265,30 @@ npm install
11
265
  # Generate type stubs
12
266
  npm run dev:prepare
13
267
 
14
- # Develop with the playground
268
+ # Develop with the basic text components playground
15
269
  npm run dev
16
270
 
17
- # Build the playground
18
- npm run dev:build
271
+ # Develop with the custom text components playground
272
+ npm run dev:custom
19
273
 
20
274
  # Run ESLint
21
275
  npm run lint
22
276
 
277
+ # Run Vitest
278
+ npm run test
279
+
23
280
  # Release new version
24
281
  npm run release
25
282
  ```
283
+
284
+ [github-actions-src]: https://github.com/freb97/nuxt-strapi-blocks-renderer/actions/workflows/ci.yml/badge.svg
285
+ [github-actions-href]: https://github.com/freb97/nuxt-strapi-blocks-renderer/actions
286
+
287
+ [npm-version-src]: https://img.shields.io/npm/v/nuxt-strapi-blocks-renderer/latest.svg?style=flat&colorA=18181B&colorB=31C553
288
+ [npm-version-href]: https://npmjs.com/package/nuxt-strapi-blocks-renderer
289
+
290
+ [npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-strapi-blocks-renderer.svg?style=flat&colorA=18181B&colorB=31C553
291
+ [npm-downloads-href]: https://npmjs.com/package/nuxt-strapi-blocks-renderer
292
+
293
+ [license-src]: https://img.shields.io/github/license/freb97/nuxt-strapi-blocks-renderer.svg?style=flat&colorA=18181B&colorB=31C553
294
+ [license-href]: https://github.com/freb97/nuxt-strapi-blocks-renderer/blob/main/LICENSE
package/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "nuxt-strapi-blocks-renderer",
3
3
  "configKey": "strapiBlocksRenderer",
4
- "version": "0.0.5"
4
+ "version": "1.0.1"
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-strapi-blocks-renderer",
3
- "version": "0.0.5",
3
+ "version": "1.0.1",
4
4
  "description": "Renderer for the strapi blocks text element.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,9 +19,11 @@
19
19
  "scripts": {
20
20
  "prepack": "nuxt-module-build build",
21
21
  "dev": "npm run dev:basic",
22
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare",
22
23
  "dev:basic": "nuxi dev playground/basic",
23
24
  "dev:custom": "nuxi dev playground/custom",
24
25
  "release": "npm run lint && npm run test && npm run prepack && npm publish",
26
+ "release:ci": "npm run prepack && npm publish",
25
27
  "lint": "eslint './**/*.{js,ts,vue}' --max-warnings=0",
26
28
  "test": "vitest run",
27
29
  "test:watch": "vitest watch"