@sit-onyx/storybook-utils 1.0.0-alpha.163 → 1.0.0-alpha.165
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-alpha.
|
|
4
|
+
"version": "1.0.0-alpha.165",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Schwarz IT KG",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@storybook/vue3": ">= 8.0.0",
|
|
31
31
|
"storybook-dark-mode": ">= 4",
|
|
32
32
|
"@sit-onyx/icons": "^0.1.0-alpha.2",
|
|
33
|
-
"sit-onyx": "^1.0.0-alpha.
|
|
33
|
+
"sit-onyx": "^1.0.0-alpha.158"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"deepmerge-ts": "^7.0.3"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1
2
|
//
|
|
2
3
|
// This file is only a temporary copy of the improved source code generation for Storybook.
|
|
3
4
|
// It is intended to be deleted once its officially released in Storybook itself, see:
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
generatePropsSourceCode,
|
|
10
11
|
generateSlotSourceCode,
|
|
11
12
|
generateSourceCode,
|
|
13
|
+
getFunctionParamNames,
|
|
12
14
|
parseDocgenInfo,
|
|
13
15
|
type SourceCodeGeneratorContext,
|
|
14
16
|
} from "./source-code-generator";
|
|
@@ -234,3 +236,23 @@ test.each([
|
|
|
234
236
|
const docgenInfo = parseDocgenInfo({ __docgenInfo });
|
|
235
237
|
expect(docgenInfo.eventNames).toStrictEqual(eventNames);
|
|
236
238
|
});
|
|
239
|
+
|
|
240
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
241
|
+
test.each<{ fn: (...args: any[]) => unknown; expectedNames: string[] }>([
|
|
242
|
+
{ fn: () => ({}), expectedNames: [] },
|
|
243
|
+
{ fn: (a) => ({}), expectedNames: ["a"] },
|
|
244
|
+
{ fn: (a, b) => ({}), expectedNames: ["a", "b"] },
|
|
245
|
+
{ fn: (a, b, { c }) => ({}), expectedNames: ["a", "b", "{", "c", "}"] },
|
|
246
|
+
{ fn: ({ a, b }) => ({}), expectedNames: ["{", "a", "b", "}"] },
|
|
247
|
+
{
|
|
248
|
+
fn: {
|
|
249
|
+
// simulate minified function after running "storybook build"
|
|
250
|
+
toString: () => "({a:foo,b:bar})=>({})",
|
|
251
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
252
|
+
} as (...args: any[]) => unknown,
|
|
253
|
+
expectedNames: ["{", "a", "b", "}"],
|
|
254
|
+
},
|
|
255
|
+
])("should extract function parameter names", ({ fn, expectedNames }) => {
|
|
256
|
+
const paramNames = getFunctionParamNames(fn);
|
|
257
|
+
expect(paramNames).toStrictEqual(expectedNames);
|
|
258
|
+
});
|
|
@@ -478,13 +478,29 @@ const getVNodeName = (vnode: VNode) => {
|
|
|
478
478
|
* @see Based on https://stackoverflow.com/a/9924463
|
|
479
479
|
*/
|
|
480
480
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
481
|
-
const getFunctionParamNames = (func: Function): string[] => {
|
|
481
|
+
export const getFunctionParamNames = (func: Function): string[] => {
|
|
482
482
|
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
|
|
483
483
|
const ARGUMENT_NAMES = /([^\s,]+)/g;
|
|
484
484
|
|
|
485
485
|
const fnStr = func.toString().replace(STRIP_COMMENTS, "");
|
|
486
486
|
const result = fnStr.slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")")).match(ARGUMENT_NAMES);
|
|
487
|
-
|
|
487
|
+
if (!result) return [];
|
|
488
|
+
|
|
489
|
+
// when running "storybook build", the function will be minified, so result for e.g.
|
|
490
|
+
// `({ foo, bar }) => { // function body }` will be `["{foo:e", "bar:a}"]`
|
|
491
|
+
// therefore we need to remove the :e and :a mappings and extract the "{" and "}"" from the destructured object
|
|
492
|
+
// so the final result becomes `["{", "foo", "bar", "}"]`
|
|
493
|
+
return result.flatMap((param) => {
|
|
494
|
+
if (["{", "}"].includes(param)) return param;
|
|
495
|
+
const nonMinifiedName = param.split(":")[0].trim();
|
|
496
|
+
if (nonMinifiedName.startsWith("{")) {
|
|
497
|
+
return ["{", nonMinifiedName.substring(1)];
|
|
498
|
+
}
|
|
499
|
+
if (param.endsWith("}") && !nonMinifiedName.endsWith("}")) {
|
|
500
|
+
return [nonMinifiedName, "}"];
|
|
501
|
+
}
|
|
502
|
+
return nonMinifiedName;
|
|
503
|
+
});
|
|
488
504
|
};
|
|
489
505
|
|
|
490
506
|
/**
|