nuxt-strapi-blocks-renderer 0.0.5 → 1.0.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,6 +1,253 @@
1
1
  # Nuxt Strapi Blocks Renderer
2
2
 
3
- Renderer module for the Strapi CMS blocks text element.
3
+ A fully customizable Nuxt module for rendering the 'blocks' text element from Strapi CMS.
4
+
5
+ ## Installation
6
+
7
+ 1. Install the npm package:
8
+
9
+ ```bash
10
+ npm install nuxt-strapi-blocks-renderer
11
+ ```
12
+
13
+ 2. Add the module to `nuxt.config.{ts|js}`:
14
+
15
+ ```typescript
16
+ modules: ['nuxt-strapi-blocks-renderer']
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ To render text, use the `StrapiBlocksText` component:
22
+
23
+ ```vue
24
+ <StrapiBlocksText :nodes="blockNodes" />
25
+ ```
26
+
27
+ In this example, the `blockNodes` are taken from the JSON response which Strapi provides when using the `blocks` text
28
+ element:
29
+
30
+ ```vue
31
+ <script setup lang="ts">
32
+ import type { BlockNode } from 'nuxt-strapi-blocks-renderer/dist/runtime/types';
33
+ import type { Restaurant } from '~/types';
34
+
35
+ const route = useRoute();
36
+ const { findOne } = useStrapi();
37
+
38
+ // Fetch restaurants data from Strapi
39
+ const response = await findOne<Restaurant>('restaurants', route.params.id);
40
+
41
+ // Obtain blocks text nodes from description field
42
+ const blockNodes: BlockNode[] = response.data.attributes.description;
43
+ </script>
44
+
45
+ <template>
46
+ <StrapiBlocksText :nodes="blockNodes" />
47
+ </template>
48
+ ```
49
+
50
+ ### Advanced Usage
51
+
52
+ In situations where your project requires specific styling or behavior for certain HTML tags such as `<a>`, `<p>`,
53
+ and others, you can override the default rendering components used by the Nuxt Strapi Blocks Renderer.
54
+ This flexibility allows you to tailor the rendering to align with your project's unique design and functional needs.
55
+
56
+ #### Global Component Registration
57
+
58
+ First, ensure that your components are globally registered in your Nuxt app.
59
+ This step is crucial for your custom components to be recognized and used by the renderer.
60
+
61
+ In your Nuxt configuration (`nuxt.config.{js|ts}`), add:
62
+
63
+ ```typescript
64
+ components: {
65
+ dirs: [
66
+ {
67
+ path: '~/components',
68
+ },
69
+ ],
70
+ global: true,
71
+ },
72
+ ```
73
+
74
+ #### Customizing the Paragraph Tag
75
+
76
+ To customize the rendering of the paragraph (`<p>`) tag, you need to create a corresponding Vue component.
77
+ The name of the component follows a predefined pattern: `'StrapiBlocksText' + [NodeName] + 'Node.vue'`.
78
+ To override the default paragraph tag, we create a file called `StrapiBlocksTextParagraphNode.vue`.
79
+
80
+ ```vue
81
+ <!-- components/StrapiBlocksTextParagraphNode.vue -->
82
+ <template>
83
+ <p class="my-custom-class-for-p">
84
+ <slot />
85
+ </p>
86
+ </template>
87
+ ```
88
+
89
+ This component assigns a custom class `my-custom-class-for-p` to the paragraph tag, which can be styled as needed.
90
+
91
+ #### Other Custom Tags
92
+
93
+ You can apply similar customizations to all other HTML tags used by the renderer.
94
+
95
+ ##### Headings
96
+
97
+ Custom heading tags (`<h1>`, `<h2>`, `<h3>`, etc.):
98
+
99
+ ```vue
100
+ <!-- components/StrapiBlocksTextHeading1Node.vue -->
101
+ <template>
102
+ <h1 class="my-custom-class-for-h1">
103
+ <slot />
104
+ </h1>
105
+ </template>
106
+
107
+ <!-- components/StrapiBlocksTextHeading2Node.vue -->
108
+ <template>
109
+ <h2 class="my-custom-class-for-h2">
110
+ <slot />
111
+ </h2>
112
+ </template>
113
+ ```
114
+
115
+ This pattern also extends to the `h3`, `h4`, `h5` and `h6` tags.
116
+
117
+ ##### Lists
118
+
119
+ Custom list tags (`<ol>`, `<ul>` and `<li>`):
120
+
121
+ ```vue
122
+ <!-- components/StrapiBlocksTextOrderedListNode.vue -->
123
+ <template>
124
+ <ol class="my-custom-class-for-ol">
125
+ <slot />
126
+ </ol>
127
+ </template>
128
+
129
+ <!-- components/StrapiBlocksTextUnorderedListNode.vue -->
130
+ <template>
131
+ <ul class="my-custom-class-for-ul">
132
+ <slot />
133
+ </ul>
134
+ </template>
135
+
136
+ <!-- components/StrapiBlocksTextListItemInlineNode.vue -->
137
+ <template>
138
+ <li class="my-custom-class-for-li">
139
+ <slot />
140
+ </li>
141
+ </template>
142
+ ```
143
+
144
+ ##### Blockquotes and Codes
145
+
146
+ Custom blockquote and code tags (`<blockquote>`, `<pre>`):
147
+
148
+ ```vue
149
+ <!-- components/StrapiBlocksTextQuoteNode.vue -->
150
+ <template>
151
+ <blockquote class="my-custom-class-for-blockquote">
152
+ <slot />
153
+ </blockquote>
154
+ </template>
155
+
156
+ <!-- components/StrapiBlocksTextCodeNode.vue -->
157
+ <template>
158
+ <pre class="my-custom-class-for-pre">
159
+ <slot />
160
+ </pre>
161
+ </template>
162
+ ```
163
+
164
+ ##### Inline text nodes
165
+
166
+ Custom inline text nodes (`<strong>`, `<em>`, `<u>`, `<del>`, `<code>`):
167
+
168
+ ```vue
169
+ <!-- components/StrapiBlocksTextBoldInlineNode.vue -->
170
+ <template>
171
+ <strong class="my-custom-class-for-strong">
172
+ <slot />
173
+ </strong>
174
+ </template>
175
+
176
+ <!-- components/StrapiBlocksTextItalicInlineNode.vue -->
177
+ <template>
178
+ <em class="my-custom-class-for-em">
179
+ <slot />
180
+ </em>
181
+ </template>
182
+
183
+ <!-- components/StrapiBlocksTextUnderlineInlineNode.vue -->
184
+ <template>
185
+ <u class="my-custom-class-for-u">
186
+ <slot />
187
+ </u>
188
+ </template>
189
+
190
+ <!-- components/StrapiBlocksTextStrikethroughInlineNode.vue -->
191
+ <template>
192
+ <del class="my-custom-class-for-del">
193
+ <slot />
194
+ </del>
195
+ </template>
196
+
197
+ <!-- components/StrapiBlocksTextCodeInlineNode.vue -->
198
+ <template>
199
+ <code class="my-custom-class-for-code">
200
+ <slot />
201
+ </code>
202
+ </template>
203
+ ```
204
+
205
+ ##### Links
206
+
207
+ Custom link tag (`<a>`):
208
+
209
+ ```vue
210
+ <!-- components/StrapiBlocksTextLinkInlineNode.vue -->
211
+ <script setup lang="ts">
212
+ const props = defineProps<{
213
+ url: string;
214
+ }>();
215
+ </script>
216
+
217
+ <template>
218
+ <a :href="props.url" class="my-custom-class-for-a">
219
+ <slot />
220
+ </a>
221
+ </template>
222
+ ```
223
+
224
+ When rendering a link tag, the url gets passed as the `url` component property.
225
+
226
+ ##### Images
227
+
228
+ Custom image tag (`<img>`):
229
+
230
+ ```vue
231
+ <!-- components/StrapiBlocksTextImageNode.vue -->
232
+ <script setup lang="ts">
233
+ const props = defineProps<{
234
+ image: any;
235
+ }>();
236
+ </script>
237
+
238
+ <template>
239
+ <img
240
+ class="my-custom-class-for-img"
241
+ :src="props.image.url"
242
+ :alt="props.image.alternativeText"
243
+ :width="props.image.width"
244
+ :height="props.image.height"
245
+ >
246
+ </template>
247
+ ```
248
+
249
+ When rendering an image tag, the image object gets passed as the `image` component property.
250
+ You can also use different image components here, i.e. `NuxtImg` or others.
4
251
 
5
252
  ## Development
6
253
 
@@ -11,15 +258,18 @@ npm install
11
258
  # Generate type stubs
12
259
  npm run dev:prepare
13
260
 
14
- # Develop with the playground
261
+ # Develop with the basic text components playground
15
262
  npm run dev
16
263
 
17
- # Build the playground
18
- npm run dev:build
264
+ # Develop with the custom text components playground
265
+ npm run dev:custom
19
266
 
20
267
  # Run ESLint
21
268
  npm run lint
22
269
 
270
+ # Run Vitest
271
+ npm run test
272
+
23
273
  # Release new version
24
274
  npm run release
25
275
  ```
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.0"
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.0",
4
4
  "description": "Renderer for the strapi blocks text element.",
5
5
  "license": "MIT",
6
6
  "type": "module",