@histoire/app 0.10.3 → 0.10.6

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.
@@ -20,6 +20,14 @@ function useStoryDoc(story) {
20
20
  comp = comp.__asyncResolved;
21
21
  } else if (comp.__asyncLoader) {
22
22
  comp = await comp.__asyncLoader();
23
+ } else if (typeof comp === "function") {
24
+ try {
25
+ comp = await comp();
26
+ } catch (e) {
27
+ }
28
+ }
29
+ if (comp == null ? void 0 : comp.default) {
30
+ comp = comp.default;
23
31
  }
24
32
  renderedDoc.value = comp.doc;
25
33
  }
@@ -22,7 +22,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
22
22
  if (iframe.value && props.variant.previewReady) {
23
23
  iframe.value.contentWindow.postMessage({
24
24
  type: STATE_SYNC,
25
- state: toRawDeep(props.variant.state)
25
+ state: toRawDeep(props.variant.state, true)
26
26
  });
27
27
  }
28
28
  }
@@ -42,7 +42,7 @@ const app = createApp({
42
42
  }
43
43
  (_a = window.parent) == null ? void 0 : _a.postMessage({
44
44
  type: STATE_SYNC,
45
- state: toRawDeep(value)
45
+ state: toRawDeep(value, true)
46
46
  });
47
47
  }, {
48
48
  deep: true
@@ -1,8 +1,4 @@
1
1
 
2
- .bind-icon-color[data-v-25f7510c] {
3
- color: var(--353b213f);
4
- }
5
-
6
2
  .landscape > div > .dragger[data-v-328ea07c] {
7
3
  width: .625rem;
8
4
  }
@@ -28,6 +24,10 @@
28
24
  bottom: -.625rem;
29
25
  }
30
26
 
27
+ .bind-icon-color[data-v-25f7510c] {
28
+ color: var(--353b213f);
29
+ }
30
+
31
31
  .htw-base-empty[data-v-c242ab26]:not(.no-animation) {
32
32
  -webkit-animation: htw-base-empty-c242ab26 .15s .2s both;
33
33
  animation: htw-base-empty-c242ab26 .15s .2s both;
@@ -49,19 +49,23 @@
49
49
  }
50
50
  }
51
51
 
52
- .bind-icon-color[data-v-b9d4a640] {
53
- color: var(--10f93ca4);
52
+ .bind-tree-margin[data-v-d0757d50] {
53
+ margin-left: var(--9d1e9326);
54
+ }
55
+ .bind-icon-color[data-v-d0757d50] {
56
+ color: var(--411af7ae);
54
57
  }
55
58
 
56
59
  .bind-tree-padding[data-v-8eb31f6a] {
57
60
  padding-left: var(--7b519d4f);
58
61
  }
59
62
 
60
- .bind-tree-margin[data-v-d0757d50] {
61
- margin-left: var(--9d1e9326);
63
+ .bind-icon-color[data-v-b9d4a640] {
64
+ color: var(--10f93ca4);
62
65
  }
63
- .bind-icon-color[data-v-d0757d50] {
64
- color: var(--411af7ae);
66
+
67
+ .bind-icon-color[data-v-3fb261e4] {
68
+ color: var(--7333f29c);
65
69
  }
66
70
 
67
71
  .bind-icon-color[data-v-7f8cccbc] {
@@ -81,10 +85,6 @@
81
85
  color: var(--1eec3e4a);
82
86
  }
83
87
 
84
- .bind-icon-color[data-v-3fb261e4] {
85
- color: var(--7333f29c);
86
- }
87
-
88
88
  .bind-preview-bg[data-v-bc4883a4] {
89
89
  background-color: var(--6bcdf233);
90
90
  }
@@ -1,6 +1,6 @@
1
1
  import { isRef, unref } from "@histoire/vendors/vue";
2
2
  const isObject = (val) => val !== null && typeof val === "object";
3
- function toRawDeep(val, seen = /* @__PURE__ */ new WeakMap()) {
3
+ function toRawDeep(val, clean = false, seen = /* @__PURE__ */ new WeakMap()) {
4
4
  const unwrappedValue = isRef(val) ? unref(val) : val;
5
5
  if (typeof unwrappedValue === "symbol") {
6
6
  return unwrappedValue.toString();
@@ -14,18 +14,25 @@ function toRawDeep(val, seen = /* @__PURE__ */ new WeakMap()) {
14
14
  if (Array.isArray(unwrappedValue)) {
15
15
  const result = [];
16
16
  seen.set(unwrappedValue, result);
17
- result.push(...unwrappedValue.map((value) => toRawDeep(value, seen)));
17
+ let list = unwrappedValue.map((value) => toRawDeep(value, clean, seen));
18
+ if (clean) {
19
+ list = list.filter((value) => typeof value !== "function");
20
+ }
21
+ result.push(...list);
18
22
  return result;
19
23
  } else {
20
24
  const result = {};
21
25
  seen.set(unwrappedValue, result);
22
- toRawObject(unwrappedValue, result, seen);
26
+ toRawObject(unwrappedValue, result, clean, seen);
23
27
  return result;
24
28
  }
25
29
  }
26
- const toRawObject = (obj, target, seen = /* @__PURE__ */ new WeakMap()) => {
30
+ const toRawObject = (obj, target, clean = false, seen = /* @__PURE__ */ new WeakMap()) => {
27
31
  Object.keys(obj).forEach((key) => {
28
- target[key] = toRawDeep(obj[key], seen);
32
+ if (clean && typeof obj[key] === "function") {
33
+ return;
34
+ }
35
+ target[key] = toRawDeep(obj[key], clean, seen);
29
36
  });
30
37
  };
31
38
  export { toRawDeep };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@histoire/app",
3
- "version": "0.10.3",
3
+ "version": "0.10.6",
4
4
  "description": "Pre-bundled UI for Histoire",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -24,9 +24,9 @@
24
24
  },
25
25
  "types": "./src/index.ts",
26
26
  "dependencies": {
27
- "@histoire/controls": "^0.10.3",
28
- "@histoire/shared": "^0.10.3",
29
- "@histoire/vendors": "^0.10.3",
27
+ "@histoire/controls": "^0.10.6",
28
+ "@histoire/shared": "^0.10.6",
29
+ "@histoire/vendors": "^0.10.6",
30
30
  "@types/flexsearch": "^0.7.3",
31
31
  "flexsearch": "^0.7.21",
32
32
  "shiki": "0.10.1"
@@ -66,6 +66,7 @@ const model = computed({
66
66
 
67
67
  function reset () {
68
68
  if (props.variant.state._hPropState[props.component.index]) {
69
+ // eslint-disable-next-line vue/no-mutating-props
69
70
  delete props.variant.state._hPropState[props.component.index][props.definition.name]
70
71
  }
71
72
  }
@@ -16,7 +16,7 @@ export function useStoryDoc (story: Ref<Story>) {
16
16
  return
17
17
  }
18
18
 
19
- // Custom blocks (Vue 3)
19
+ // Custom blocks (Vue)
20
20
  // @TODO extract
21
21
  let comp = story.value.file?.component
22
22
  if (comp) {
@@ -24,6 +24,16 @@ export function useStoryDoc (story: Ref<Story>) {
24
24
  comp = comp.__asyncResolved
25
25
  } else if (comp.__asyncLoader) {
26
26
  comp = await comp.__asyncLoader()
27
+ } else if (typeof comp === 'function') {
28
+ try {
29
+ comp = await comp()
30
+ } catch (e) {
31
+ // Noop
32
+ // Could be a class that requires `new com()`
33
+ }
34
+ }
35
+ if (comp?.default) {
36
+ comp = comp.default
27
37
  }
28
38
  renderedDoc.value = comp.doc
29
39
  }
@@ -25,7 +25,7 @@ function syncState () {
25
25
  if (iframe.value && props.variant.previewReady) {
26
26
  iframe.value.contentWindow.postMessage({
27
27
  type: STATE_SYNC,
28
- state: toRawDeep(props.variant.state),
28
+ state: toRawDeep(props.variant.state, true),
29
29
  })
30
30
  }
31
31
  }
@@ -45,7 +45,7 @@ const app = createApp({
45
45
  }
46
46
  window.parent?.postMessage({
47
47
  type: STATE_SYNC,
48
- state: toRawDeep(value),
48
+ state: toRawDeep(value, true),
49
49
  })
50
50
  }, {
51
51
  deep: true,
@@ -2,7 +2,7 @@ import { unref, isRef } from 'vue'
2
2
 
3
3
  const isObject = (val) => val !== null && typeof val === 'object'
4
4
 
5
- export function toRawDeep (val, seen = new WeakMap()) {
5
+ export function toRawDeep (val, clean = false, seen = new WeakMap()) {
6
6
  const unwrappedValue = isRef(val) ? unref(val) : val
7
7
 
8
8
  if (typeof unwrappedValue === 'symbol') {
@@ -20,18 +20,25 @@ export function toRawDeep (val, seen = new WeakMap()) {
20
20
  if (Array.isArray(unwrappedValue)) {
21
21
  const result = []
22
22
  seen.set(unwrappedValue, result)
23
- result.push(...unwrappedValue.map(value => toRawDeep(value, seen)))
23
+ let list = unwrappedValue.map(value => toRawDeep(value, clean, seen))
24
+ if (clean) {
25
+ list = list.filter(value => typeof value !== 'function')
26
+ }
27
+ result.push(...list)
24
28
  return result
25
29
  } else {
26
30
  const result = {}
27
31
  seen.set(unwrappedValue, result)
28
- toRawObject(unwrappedValue, result, seen)
32
+ toRawObject(unwrappedValue, result, clean, seen)
29
33
  return result
30
34
  }
31
35
  }
32
36
 
33
- const toRawObject = (obj: Record<any, any>, target: Record<any, any>, seen = new WeakMap()) => {
37
+ const toRawObject = (obj: Record<any, any>, target: Record<any, any>, clean = false, seen = new WeakMap()) => {
34
38
  Object.keys(obj).forEach((key) => {
35
- target[key] = toRawDeep(obj[key], seen)
39
+ if (clean && typeof obj[key] === 'function') {
40
+ return
41
+ }
42
+ target[key] = toRawDeep(obj[key], clean, seen)
36
43
  })
37
44
  }