@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 +4 -3
- package/src/preview.spec.ts +7 -3
- package/src/preview.ts +32 -14
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.
|
|
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/
|
|
34
|
-
"@sit-onyx/
|
|
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"
|
package/src/preview.spec.ts
CHANGED
|
@@ -18,9 +18,13 @@ import { iconBellRing, iconCalendar, iconPlaceholder } from "@sit-onyx/icons";
|
|
|
18
18
|
</script>
|
|
19
19
|
|
|
20
20
|
<template>
|
|
21
|
-
<OnyxTest
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
/**
|