@sit-onyx/storybook-utils 1.0.0-beta.100 → 1.0.0-beta.101

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sit-onyx/storybook-utils",
3
3
  "description": "Storybook utilities for Vue",
4
- "version": "1.0.0-beta.100",
4
+ "version": "1.0.0-beta.101",
5
5
  "type": "module",
6
6
  "author": "Schwarz IT KG",
7
7
  "license": "Apache-2.0",
@@ -28,10 +28,11 @@
28
28
  "peerDependencies": {
29
29
  "@storybook/vue3-vite": ">= 9.0.0",
30
30
  "@vueless/storybook-dark-mode": ">= 9.0.0",
31
+ "prettier": ">= 3.0.0",
31
32
  "storybook": ">= 9.0.0",
32
33
  "vue-component-type-helpers": ">= 2",
33
- "@sit-onyx/icons": "^1.0.0-beta.23",
34
- "@sit-onyx/shared": "^1.0.0-beta.4"
34
+ "@sit-onyx/shared": "^1.0.0-beta.4",
35
+ "@sit-onyx/icons": "^1.0.0-beta.23"
35
36
  },
36
37
  "dependencies": {
37
38
  "deepmerge-ts": "^7.1.5"
@@ -18,9 +18,13 @@ import { iconBellRing, iconCalendar, iconPlaceholder } from "@sit-onyx/icons";
18
18
  </script>
19
19
 
20
20
  <template>
21
- <OnyxTest :icon="iconPlaceholder" :test="iconBellRing" :obj="{foo:iconCalendar}" />
22
- <OnyxOtherComponent />
23
- <OnyxComp>Test</OnyxComp>
21
+ <OnyxTest
22
+ :icon="iconPlaceholder"
23
+ :test="iconBellRing"
24
+ :obj="{foo:iconCalendar}"
25
+ />
26
+ <OnyxOtherComponent />
27
+ <OnyxComp>Test</OnyxComp>
24
28
  </template>`);
25
29
  });
26
30
  });
package/src/preview.ts CHANGED
@@ -179,24 +179,42 @@ export const sourceCodeTransformer = async (originalSourceCode: string): Promise
179
179
  additionalImports.unshift(`import { ${usedOnyxComponents.join(", ")} } from "sit-onyx";`);
180
180
  }
181
181
 
182
- if (additionalImports.length === 0) return code;
183
-
184
- if (code.startsWith("<script")) {
185
- const index = code.indexOf("\n");
186
- const hasOtherImports = code.includes("import {");
187
- return (
188
- code.slice(0, index) +
189
- additionalImports.join("\n") +
190
- (!hasOtherImports ? "\n" : "") +
191
- code.slice(index)
192
- );
193
- }
194
-
195
- return `<script lang="ts" setup>
182
+ if (additionalImports.length > 1) {
183
+ if (code.startsWith("<script")) {
184
+ const index = code.indexOf("\n");
185
+ const hasOtherImports = code.includes("import {");
186
+ code =
187
+ code.slice(0, index) +
188
+ additionalImports.join("\n") +
189
+ (!hasOtherImports ? "\n" : "") +
190
+ code.slice(index);
191
+ } else {
192
+ code = `<script lang="ts" setup>
196
193
  ${additionalImports.join("\n")}
197
194
  </script>
198
195
 
199
196
  ${code}`;
197
+ }
198
+ }
199
+
200
+ try {
201
+ const { format } = await import("prettier/standalone");
202
+ const parserHtml = await import("prettier/parser-html");
203
+
204
+ code = await format(code, {
205
+ parser: "vue",
206
+ plugins: [parserHtml],
207
+ htmlWhitespaceSensitivity: "ignore",
208
+ });
209
+
210
+ // trim code to remove trailing newlines that are added by prettier
211
+ code = code.trim();
212
+ } catch (e) {
213
+ // eslint-disable-next-line no-console -- if the formatting fails, there is usually an issue with our code so we want to inform the user that the formatting failed
214
+ console.error("Error while formatting Storybook code snippet:", e);
215
+ }
216
+
217
+ return code;
200
218
  };
201
219
 
202
220
  /**