@sit-onyx/storybook-utils 1.0.0-alpha.150 → 1.0.0-alpha.152
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 +3 -3
- package/src/preview.spec.ts +3 -1
- package/src/preview.ts +8 -2
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-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.152",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Schwarz IT KG",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@storybook/theming": ">= 8.0.0",
|
|
30
30
|
"@storybook/vue3": ">= 8.0.0",
|
|
31
31
|
"storybook-dark-mode": ">= 4",
|
|
32
|
-
"
|
|
33
|
-
"sit-onyx": "^1.0
|
|
32
|
+
"sit-onyx": "^1.0.0-alpha.146",
|
|
33
|
+
"@sit-onyx/icons": "^0.1.0-alpha.2"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"deepmerge-ts": "^7.0.3"
|
package/src/preview.spec.ts
CHANGED
|
@@ -12,6 +12,7 @@ describe("preview.ts", () => {
|
|
|
12
12
|
.mockReturnValue(`<template>
|
|
13
13
|
<OnyxTest icon='${placeholder}' test='${bellRing}' :obj="{foo:'${replaceAll(calendar, '"', "\\'")}'}" />
|
|
14
14
|
<OnyxOtherComponent />
|
|
15
|
+
<OnyxComp>Test</OnyxComp>
|
|
15
16
|
</template>`);
|
|
16
17
|
|
|
17
18
|
// ACT
|
|
@@ -20,7 +21,7 @@ describe("preview.ts", () => {
|
|
|
20
21
|
// ASSERT
|
|
21
22
|
expect(generatorSpy).toHaveBeenCalledOnce();
|
|
22
23
|
expect(sourceCode).toBe(`<script lang="ts" setup>
|
|
23
|
-
import { OnyxOtherComponent, OnyxTest } from "sit-onyx";
|
|
24
|
+
import { OnyxComp, OnyxOtherComponent, OnyxTest } from "sit-onyx";
|
|
24
25
|
import bellRing from "@sit-onyx/icons/bell-ring.svg?raw";
|
|
25
26
|
import calendar from "@sit-onyx/icons/calendar.svg?raw";
|
|
26
27
|
import placeholder from "@sit-onyx/icons/placeholder.svg?raw";
|
|
@@ -29,6 +30,7 @@ import placeholder from "@sit-onyx/icons/placeholder.svg?raw";
|
|
|
29
30
|
<template>
|
|
30
31
|
<OnyxTest :icon="placeholder" :test="bellRing" :obj="{foo:calendar}" />
|
|
31
32
|
<OnyxOtherComponent />
|
|
33
|
+
<OnyxComp>Test</OnyxComp>
|
|
32
34
|
</template>`);
|
|
33
35
|
});
|
|
34
36
|
});
|
package/src/preview.ts
CHANGED
|
@@ -173,7 +173,7 @@ export const sourceCodeTransformer = (
|
|
|
173
173
|
// add imports for all used onyx components
|
|
174
174
|
// Set is used here to only include unique components if they are used multiple times
|
|
175
175
|
const usedOnyxComponents = [
|
|
176
|
-
...new Set(Array.from(code.matchAll(/<Onyx\
|
|
176
|
+
...new Set(Array.from(code.matchAll(/<(Onyx\w+)(?:\s*\/?)/g)).map((match) => match[1])),
|
|
177
177
|
].sort();
|
|
178
178
|
|
|
179
179
|
if (usedOnyxComponents.length > 0) {
|
|
@@ -184,7 +184,13 @@ export const sourceCodeTransformer = (
|
|
|
184
184
|
|
|
185
185
|
if (code.startsWith("<script")) {
|
|
186
186
|
const index = code.indexOf("\n");
|
|
187
|
-
|
|
187
|
+
const hasOtherImports = code.includes("import {");
|
|
188
|
+
return (
|
|
189
|
+
code.slice(0, index) +
|
|
190
|
+
additionalImports.join("\n") +
|
|
191
|
+
(!hasOtherImports ? "\n" : "") +
|
|
192
|
+
code.slice(index)
|
|
193
|
+
);
|
|
188
194
|
}
|
|
189
195
|
|
|
190
196
|
return `<script lang="ts" setup>
|