@vueless/storybook 0.0.75-beta.12 → 0.0.75-beta.14

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.
@@ -1,8 +1,10 @@
1
1
  import { addons, makeDecorator, useArgs } from "storybook/preview-api";
2
+ import { SNIPPET_RENDERED } from "storybook/internal/docs-tools";
2
3
  import { h, onMounted, watch } from "vue";
3
4
 
4
5
  const params = new URLSearchParams(window.location.search);
5
6
  let previousStoryId = null;
7
+ let previousArgs = {};
6
8
 
7
9
  function getArgsFromUrl(storyId) {
8
10
  const isInIframe = params.toString().includes("globals=");
@@ -23,6 +25,7 @@ export const vue3SourceDecorator = makeDecorator({
23
25
  const story = storyFn(context);
24
26
  const [, updateArgs] = useArgs();
25
27
  const urlArgs = getArgsFromUrl(context.id);
28
+ const channel = addons.getChannel();
26
29
 
27
30
  previousStoryId = context.id;
28
31
 
@@ -35,13 +38,22 @@ export const vue3SourceDecorator = makeDecorator({
35
38
  onMounted(async () => {
36
39
  updateArgs({ ...context.args, ...urlArgs });
37
40
 
38
- await setSourceCode();
41
+ /* rerender code snippet by optimized source code */
42
+ channel.on(SNIPPET_RENDERED, async (payload) => {
43
+ if (payload.source.includes(`<script lang="ts" setup>`)) {
44
+ await setSourceCode();
45
+ }
46
+ });
39
47
  });
40
48
 
41
49
  watch(
42
50
  context.args,
43
- async () => {
51
+ async (newArgs) => {
52
+ if (JSON.stringify(previousArgs) === JSON.stringify(newArgs)) return;
53
+
54
+ previousArgs = { ...newArgs };
44
55
  updateArgs({ ...context.args });
56
+
45
57
  await setSourceCode();
46
58
  },
47
59
  { deep: true },
@@ -52,8 +64,6 @@ export const vue3SourceDecorator = makeDecorator({
52
64
  const src = context.originalStoryFn(context.args, context.argTypes).template;
53
65
  const code = preFormat(src, context.args, context.argTypes);
54
66
 
55
- const channel = addons.getChannel();
56
-
57
67
  const emitFormattedTemplate = async () => {
58
68
  const prettier = await import("prettier2");
59
69
  const prettierHtml = await import("prettier2/parser-html");
@@ -64,8 +74,8 @@ export const vue3SourceDecorator = makeDecorator({
64
74
  htmlWhitespaceSensitivity: "ignore",
65
75
  });
66
76
 
67
- // emits an event when the transformation is completed
68
- channel.emit("storybook/docs/snippet-rendered", {
77
+ // emits an event when the transformation is completed and content rendered
78
+ channel.emit(SNIPPET_RENDERED, {
69
79
  id: context.id,
70
80
  args: context.args,
71
81
  source: postFormat(formattedCode),
@@ -124,7 +134,9 @@ function preFormat(templateSource, args, argTypes) {
124
134
  // eslint-disable-next-line vue/max-len
125
135
  `</template><template v-else-if="slot === 'default' && args['defaultSlot']">{{ args['defaultSlot'] }}</template><template v-else-if="args[slot + 'Slot']">{{ args[slot + 'Slot'] }}</template></template>`;
126
136
 
127
- const modelValue = JSON.stringify(args["modelValue"])?.replaceAll('"', "'");
137
+ const modelValue = isPrimitive(args["modelValue"])
138
+ ? JSON.stringify(args["modelValue"])?.replaceAll('"', "")
139
+ : JSON.stringify(args["modelValue"])?.replaceAll('"', "'");
128
140
 
129
141
  templateSource = templateSource
130
142
  .replace(/>[\s]+</g, "><")
@@ -259,16 +271,17 @@ function generateEnumAttributes(args, option) {
259
271
 
260
272
  return enumKeys
261
273
  .map((key) => {
262
- const isNotPrimitive =
263
- Object.keys(args[key] || {}).length || (Array.isArray(args[key]) && args[key].length);
264
-
265
- return key in args && isNotPrimitive
274
+ return key in args && !isPrimitive(args[key])
266
275
  ? `${key}="${JSON.stringify(args[key]).replaceAll('"', "'").replaceAll("{enumValue}", option)}"`
267
276
  : `${key}="${option}"`;
268
277
  })
269
278
  .join(" ");
270
279
  }
271
280
 
281
+ function isPrimitive(value) {
282
+ return !(value && (typeof value === "object" || Array.isArray(value)));
283
+ }
284
+
272
285
  function propToSource(key, val, argType) {
273
286
  const defaultValue = argType.table?.defaultValue?.summary;
274
287
  const type = typeof val;
@@ -265,6 +265,11 @@ body {
265
265
  margin-top: 0.5rem; /* mt-2 */
266
266
  }
267
267
 
268
+ .sb-anchor > p {
269
+ margin-top: -0.5rem; /* mt-2 */
270
+ margin-bottom: -0.5rem; /* -mt-2 */
271
+ }
272
+
268
273
  .dark .sb-anchor > p > a {
269
274
  color: #4ade80; /* text-green-400 */
270
275
  text-decoration: underline dashed #4ade80;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vueless/storybook",
3
- "version": "0.0.75-beta.12",
3
+ "version": "0.0.75-beta.14",
4
4
  "description": "Simplifies Storybook configuration for Vueless UI library.",
5
5
  "homepage": "https://vueless.com",
6
6
  "author": "Johnny Grid",