storybook-addon-sdc 0.9.1 → 0.9.3
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 +17 -18
- package/dist/preset.js +9 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ You can view a [live example of the SDC Addon in Storybook](https://iberdinsky-s
|
|
|
37
37
|
|
|
38
38
|
The SDC Storybook Addon simplifies the integration of Drupal Single Directory Components (SDC) into Storybook, offering several key features:
|
|
39
39
|
|
|
40
|
-
- **Vite Plugin Integration**:
|
|
40
|
+
- **Vite Plugin Integration**: You can use either the vite-plugin-twig-drupal plugin (Twig.js) or the vite-plugin-twing-drupal plugin (Twing) to load and process Twig templates in SDC components.
|
|
41
41
|
- **Dynamic Path Resolution**: Utilizes namespaces to dynamically discover components within your project structure, eliminating the need for manual configuration.
|
|
42
42
|
- **Story Generation**: Automatically creates stories based on the YAML configurations of your SDC components, streamlining the story creation process.
|
|
43
43
|
- **JSON Schema Support**: Supports JSON Schema for props and slots, enabling the generation of mock data for missing values and ensuring data consistency.
|
|
@@ -78,13 +78,14 @@ While solutions like [SDC Styleguide](https://www.drupal.org/project/sdc_stylegu
|
|
|
78
78
|
- Embed **Drupal behaviors** (like `Drupal.attachBehaviors()`) directly into Storybook previews, ensuring consistent component behavior between Storybook and production.
|
|
79
79
|
- Supports `drupalSettings` and `once.js`, so components in Storybook behave identically to their Drupal counterparts.
|
|
80
80
|
|
|
81
|
-
### 7. Twig.js
|
|
81
|
+
### 7. Twig.js, Twing, and Drupal Twig
|
|
82
82
|
|
|
83
|
-
While using Drupal to render components offers tighter integration, there are strong reasons to
|
|
83
|
+
While using Drupal to render components offers tighter integration, there are strong reasons to use Twig.js or Twing in many scenarios:
|
|
84
84
|
|
|
85
|
-
- Many
|
|
86
|
-
- Twig.js
|
|
87
|
-
-
|
|
85
|
+
- Many components **don’t need full Drupal logic**. Basic components (buttons, cards, lists) rely on simple HTML and CSS, not on complex template logic. For such components, Twig.js or Twing provide sufficient rendering without the need for full Drupal preprocessing.
|
|
86
|
+
- **Twig.js** works well for most frontend-focused use cases.
|
|
87
|
+
- **Twing** is a modern, actively maintained Twig implementation for Node.js that offers better compatibility with Drupal's Twig features and syntax.
|
|
88
|
+
- Styling and behavior mismatches can be managed separately in the Drupal implementation phase.
|
|
88
89
|
|
|
89
90
|
## Quickstart Guide
|
|
90
91
|
|
|
@@ -133,11 +134,9 @@ While using Drupal to render components offers tighter integration, there are st
|
|
|
133
134
|
## Configuration
|
|
134
135
|
|
|
135
136
|
To configure the addon, update `.storybook/main.js` as shown below:
|
|
136
|
-
You can use this plugin either with
|
|
137
|
-
[Twig.js](https://github.com/twigjs/twig.js) or
|
|
138
|
-
[Twing.js](https://twing.nightlycommit.com/).
|
|
137
|
+
You can use this plugin either with [Twig.js](https://github.com/twigjs/twig.js) or [Twing.js](https://twing.nightlycommit.com/).
|
|
139
138
|
|
|
140
|
-
|
|
139
|
+
#### [Twig.js](https://github.com/twigjs/twig.js)
|
|
141
140
|
|
|
142
141
|
```js
|
|
143
142
|
import { join } from 'node:path' // 1. Add dependencies.
|
|
@@ -172,7 +171,7 @@ const config = {
|
|
|
172
171
|
export default config
|
|
173
172
|
```
|
|
174
173
|
|
|
175
|
-
|
|
174
|
+
#### [Twing.js](https://twing.nightlycommit.com/)
|
|
176
175
|
|
|
177
176
|
```js
|
|
178
177
|
import { join } from 'node:path' // 1. Add dependencies.
|
|
@@ -211,21 +210,20 @@ export default config
|
|
|
211
210
|
|
|
212
211
|
Sample twing hook file. See [twing.js documentation](https://twing.nightlycommit.com/) for more infos.
|
|
213
212
|
|
|
214
|
-
```
|
|
213
|
+
```js
|
|
215
214
|
import { createSynchronousFunction } from 'twing'
|
|
216
215
|
|
|
217
216
|
/**
|
|
218
|
-
* Simple test function.
|
|
219
|
-
*/
|
|
217
|
+
* Simple test function.
|
|
218
|
+
*/
|
|
220
219
|
function testFunction() {
|
|
221
220
|
return 'IT WORKS!'
|
|
222
221
|
}
|
|
223
222
|
|
|
224
223
|
export function initEnvironment(twingEnvironment, config = {}) {
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
const func = createSynchronousFunction('testFunction', testFunction, [])
|
|
225
|
+
twingEnvironment.addFunction(func)
|
|
227
226
|
}
|
|
228
|
-
|
|
229
227
|
```
|
|
230
228
|
|
|
231
229
|
## Setting Default Values
|
|
@@ -452,7 +450,8 @@ const config = {
|
|
|
452
450
|
|
|
453
451
|
## Dependencies
|
|
454
452
|
|
|
455
|
-
- [vite-plugin-twig-drupal](https://github.com/larowlan/vite-plugin-twig-drupal): Loads Twig with Drupal functions.
|
|
453
|
+
- [vite-plugin-twig-drupal](https://github.com/larowlan/vite-plugin-twig-drupal): Loads Twig with Drupal functions in twig.js.
|
|
454
|
+
- [vite-plugin-twing-drupal](https://github.com/christianwiedemann/vite-plugin-twing-drupal): Loads Twig with Drupal functions in Twing.
|
|
456
455
|
- [json-schema-faker](https://github.com/json-schema-faker/json-schema-faker): Generates mock data for missing props and
|
|
457
456
|
- [JSON Schema validator](https://www.npmjs.com/package/jsonschema)
|
|
458
457
|
|
package/dist/preset.js
CHANGED
|
@@ -345,8 +345,6 @@ var loadStoryFilesSync = (fileName) => {
|
|
|
345
345
|
};
|
|
346
346
|
|
|
347
347
|
// src/preset.ts
|
|
348
|
-
import twing from "vite-plugin-twing-drupal";
|
|
349
|
-
import twig from "vite-plugin-twig-drupal";
|
|
350
348
|
import { mergeConfig } from "vite";
|
|
351
349
|
import { resolve as resolve2 } from "path";
|
|
352
350
|
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
@@ -425,13 +423,20 @@ async function viteFinal(config, options) {
|
|
|
425
423
|
const { namespace, customDefs, externalDefs } = options.sdcStorybookOptions;
|
|
426
424
|
const globalDefs = await loadAndMergeDefinitions(externalDefs, customDefs);
|
|
427
425
|
const { nodePolyfills } = await import("vite-plugin-node-polyfills");
|
|
426
|
+
let twigPlugin = null;
|
|
427
|
+
if (options.sdcStorybookOptions.twigLib === "twing") {
|
|
428
|
+
const { default: twing } = await import("vite-plugin-twing-drupal");
|
|
429
|
+
twigPlugin = twing(options.vitePluginTwingDrupalOptions);
|
|
430
|
+
} else if (options.sdcStorybookOptions.twigLib === "twig") {
|
|
431
|
+
const { default: twig } = await import("vite-plugin-twig-drupal");
|
|
432
|
+
twigPlugin = twig(options.vitePluginTwigDrupalOptions);
|
|
433
|
+
}
|
|
428
434
|
return mergeConfig(config, {
|
|
429
435
|
plugins: [
|
|
430
436
|
nodePolyfills({
|
|
431
437
|
include: ["buffer", "stream", "path"]
|
|
432
438
|
}),
|
|
433
|
-
|
|
434
|
-
options.sdcStorybookOptions.twigLib === "twig" ? twig(options.vitePluginTwigDrupalOptions) : {},
|
|
439
|
+
...twigPlugin ? [twigPlugin] : [],
|
|
435
440
|
vite_plugin_storybook_yaml_stories_default({ ...options, globalDefs })
|
|
436
441
|
],
|
|
437
442
|
resolve: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storybook-addon-sdc",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Drupal Single Directory Components as stories",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"SDC",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"yaml": "^2.7.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@storybook/addon-links": "^9.
|
|
52
|
-
"@storybook/html-vite": "^9.
|
|
51
|
+
"@storybook/addon-links": "^9.1.2",
|
|
52
|
+
"@storybook/html-vite": "^9.1.2",
|
|
53
53
|
"@types/json-schema": "^7.0.15",
|
|
54
|
-
"@types/node": "^
|
|
54
|
+
"@types/node": "^24.2.1",
|
|
55
55
|
"@types/node-fetch": "^2.6.12",
|
|
56
56
|
"@types/twig": "^1.12.16",
|
|
57
57
|
"auto": "^11.3.0",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"prompts": "^2.4.2",
|
|
62
62
|
"react": "^19.1.0",
|
|
63
63
|
"react-dom": "^19.1.0",
|
|
64
|
-
"storybook": "^9.
|
|
64
|
+
"storybook": "^9.1.2",
|
|
65
65
|
"tsup": "^8.4.0",
|
|
66
66
|
"typescript": "^5.8.2",
|
|
67
67
|
"vite": "^6.2.3",
|