UNPKG

@muban/storybook

Version:
42 lines (41 loc) 1.87 kB
export function processStoryArgs(args, argumentTypes, argumentTypeOperators) { var _a, _b, _c; const storyArguments = Object.assign({}, args); for (const key of Object.keys(argumentTypes)) { if (storyArguments[key] === undefined) { continue; } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const argumentType = argumentTypes[key]; const { control, action } = argumentType; const controlType = ((_c = (_b = ((_a = control === null || control === void 0 ? void 0 : control.type) !== null && _a !== void 0 ? _a : control)) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : (Boolean(action) && 'action')); const argumentValue = storyArguments[key]; const processor = controlType && argumentTypeOperators[controlType]; if (processor) { if (processor === 'delete') { // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete storyArguments[key]; } else { storyArguments[key] = processor(argumentValue); } } } return storyArguments; } export function getServerTemplateArgs(args, argumentTypes) { // these _should_ be the same return getClientTemplateArgs(args, argumentTypes); // return processStoryArgs(args, argumentTypes, { // action: 'delete', // date: (value) => new Date(value).toISOString(), // }); } export function getClientTemplateArgs(args, argumentTypes) { return processStoryArgs(args, argumentTypes, { // actions should not be passed to templates action: 'delete', // booleans are not properly converted from the URL, so they might be passed as strings boolean: (value) => value === true || value === 'true', }); }