storybook-addon-sdc 0.8.2 → 0.9.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
@@ -133,6 +133,11 @@ While using Drupal to render components offers tighter integration, there are st
133
133
  ## Configuration
134
134
 
135
135
  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/).
139
+
140
+ ### [Twig.js](https://github.com/twigjs/twig.js)
136
141
 
137
142
  ```js
138
143
  import { join } from 'node:path' // 1. Add dependencies.
@@ -167,6 +172,62 @@ const config = {
167
172
  export default config
168
173
  ```
169
174
 
175
+ ### [Twing.js](https://twing.nightlycommit.com/)
176
+
177
+ ```js
178
+ import { join } from 'node:path' // 1. Add dependencies.
179
+ import { cwd } from 'node:process'
180
+
181
+ const config = {
182
+ stories: ['../components/**/*.component.yml'], // 2. Set components glob.
183
+ addons: [
184
+ {
185
+ name: 'storybook-addon-sdc', // 3. Configure addon.
186
+ options: {
187
+ sdcStorybookOptions: {
188
+ twigLib: 'twing',
189
+ namespace: 'umami', // Your namespace.
190
+ },
191
+ vitePluginTwingDrupalOptions: {
192
+ namespaces: {
193
+ umami: [join(cwd(), './components')],
194
+ },
195
+ // (Optional) With twing hooks you can adjust twing environment.
196
+ hooks: join(cwd(), '.storybook/twing-hooks.js'),
197
+ },
198
+ jsonSchemaFakerOptions: {}, // json-schema-faker options.
199
+ },
200
+ },
201
+ // Any other addons.
202
+ '@chromatic-com/storybook',
203
+ ],
204
+ framework: {
205
+ name: '@storybook/html-vite',
206
+ options: {},
207
+ },
208
+ }
209
+ export default config
210
+ ```
211
+
212
+ Sample twing hook file. See [twing.js documentation](https://twing.nightlycommit.com/) for more infos.
213
+
214
+ ```
215
+ import { createSynchronousFunction } from 'twing'
216
+
217
+ /**
218
+ * Simple test function.
219
+ */
220
+ function testFunction() {
221
+ return 'IT WORKS!'
222
+ }
223
+
224
+ export function initEnvironment(twingEnvironment, config = {}) {
225
+ const func = createSynchronousFunction('testFunction', testFunction, [])
226
+ twingEnvironment.addFunction(func)
227
+ }
228
+
229
+ ```
230
+
170
231
  ## Setting Default Values
171
232
 
172
233
  For `json-schema-faker` to generate reliable data, use `default` or `examples` in your SDC schema:
package/dist/preset.js CHANGED
@@ -345,6 +345,7 @@ var loadStoryFilesSync = (fileName) => {
345
345
  };
346
346
 
347
347
  // src/preset.ts
348
+ import twing from "vite-plugin-twing-drupal";
348
349
  import twig from "vite-plugin-twig-drupal";
349
350
  import { mergeConfig } from "vite";
350
351
  import { resolve as resolve2 } from "path";
@@ -387,7 +388,8 @@ function resolveComponentPath2(namespace, component) {
387
388
  return resolvedPath;
388
389
  }
389
390
  var defaultOptions = {
390
- validate: false
391
+ validate: false,
392
+ twigLib: "twig"
391
393
  // validate:
392
394
  // 'https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json',
393
395
  };
@@ -422,9 +424,14 @@ async function viteFinal(config, options) {
422
424
  };
423
425
  const { namespace, customDefs, externalDefs } = options.sdcStorybookOptions;
424
426
  const globalDefs = await loadAndMergeDefinitions(externalDefs, customDefs);
427
+ const { nodePolyfills } = await import("vite-plugin-node-polyfills");
425
428
  return mergeConfig(config, {
426
429
  plugins: [
427
- twig(options.vitePluginTwigDrupalOptions),
430
+ nodePolyfills({
431
+ include: ["buffer", "stream", "path"]
432
+ }),
433
+ options.sdcStorybookOptions.twigLib === "twing" ? twing(options.vitePluginTwingDrupalOptions) : {},
434
+ options.sdcStorybookOptions.twigLib === "twig" ? twig(options.vitePluginTwigDrupalOptions) : {},
428
435
  vite_plugin_storybook_yaml_stories_default({ ...options, globalDefs })
429
436
  ],
430
437
  resolve: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-sdc",
3
- "version": "0.8.2",
3
+ "version": "0.9.1",
4
4
  "description": "Drupal Single Directory Components as stories",
5
5
  "keywords": [
6
6
  "SDC",
@@ -43,12 +43,13 @@
43
43
  "node-fetch": "^3.3.2",
44
44
  "pino": "^9.6.0",
45
45
  "pino-pretty": "^13.0.0",
46
- "vite-plugin-twig-drupal": "^1.6.0",
46
+ "vite-plugin-twing-drupal": "^1.0.13",
47
+ "vite-plugin-twig-drupal": "^1.6.1",
47
48
  "yaml": "^2.7.1"
48
49
  },
49
50
  "devDependencies": {
50
- "@storybook/addon-links": "^9.0.15",
51
- "@storybook/html-vite": "^9.0.15",
51
+ "@storybook/addon-links": "^9.0.17",
52
+ "@storybook/html-vite": "^9.0.17",
52
53
  "@types/json-schema": "^7.0.15",
53
54
  "@types/node": "^22.13.14",
54
55
  "@types/node-fetch": "^2.6.12",
@@ -60,7 +61,7 @@
60
61
  "prompts": "^2.4.2",
61
62
  "react": "^19.1.0",
62
63
  "react-dom": "^19.1.0",
63
- "storybook": "^9.0.15",
64
+ "storybook": "^9.0.17",
64
65
  "tsup": "^8.4.0",
65
66
  "typescript": "^5.8.2",
66
67
  "vite": "^6.2.3",