@poveste/plugin-svelte 0.1.0

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.
Files changed (71) hide show
  1. package/LICENSE +22 -0
  2. package/assets/histoire-svelte-text.svg +89 -0
  3. package/assets/histoire-svelte.svg +52 -0
  4. package/dist/client/MountStory.js +1 -0
  5. package/dist/client/MountStory.svelte +24 -0
  6. package/dist/client/MountVariant.js +1 -0
  7. package/dist/client/MountVariant.svelte +47 -0
  8. package/dist/client/RenderStory.js +1 -0
  9. package/dist/client/RenderStory.svelte +27 -0
  10. package/dist/client/RenderVariant.js +1 -0
  11. package/dist/client/RenderVariant.svelte +32 -0
  12. package/dist/client/Stub.js +1 -0
  13. package/dist/client/Stub.svelte +0 -0
  14. package/dist/client/Wrap.js +1 -0
  15. package/dist/client/Wrap.svelte +63 -0
  16. package/dist/client/index.d.ts +8 -0
  17. package/dist/client/index.js +1 -0
  18. package/dist/client/mount.d.ts +16 -0
  19. package/dist/client/mount.js +1 -0
  20. package/dist/client/render.d.ts +34 -0
  21. package/dist/client/render.js +1 -0
  22. package/dist/client/util.d.ts +4 -0
  23. package/dist/client/util.js +1 -0
  24. package/dist/collect/Story.js +1 -0
  25. package/dist/collect/Story.svelte +34 -0
  26. package/dist/collect/Variant.js +1 -0
  27. package/dist/collect/Variant.svelte +24 -0
  28. package/dist/collect/index.d.ts +2 -0
  29. package/dist/collect/index.js +1 -0
  30. package/dist/commands/generate-story.client.d.ts +3 -0
  31. package/dist/commands/generate-story.client.js +27 -0
  32. package/dist/commands/generate-story.server.d.ts +3 -0
  33. package/dist/commands/generate-story.server.js +52 -0
  34. package/dist/helpers.d.ts +87 -0
  35. package/dist/helpers.js +6 -0
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.js +1 -0
  38. package/dist/index.node.d.ts +3 -0
  39. package/dist/index.node.js +90 -0
  40. package/dist/util/list-components.d.ts +1 -0
  41. package/dist/util/list-components.js +15 -0
  42. package/dist/util/story-hmr.d.ts +7 -0
  43. package/dist/util/story-hmr.js +30 -0
  44. package/dist/util/svelte.d.ts +18 -0
  45. package/dist/util/svelte.js +102 -0
  46. package/package.json +57 -0
  47. package/src/client/MountStory.svelte +24 -0
  48. package/src/client/MountVariant.svelte +47 -0
  49. package/src/client/RenderStory.svelte +27 -0
  50. package/src/client/RenderVariant.svelte +32 -0
  51. package/src/client/Stub.svelte +0 -0
  52. package/src/client/Wrap.svelte +63 -0
  53. package/src/client/index.ts +12 -0
  54. package/src/client/mount.ts +113 -0
  55. package/src/client/render.ts +191 -0
  56. package/src/client/util.ts +52 -0
  57. package/src/collect/Story.svelte +34 -0
  58. package/src/collect/Variant.svelte +24 -0
  59. package/src/collect/index.ts +53 -0
  60. package/src/commands/generate-story.client.ts +29 -0
  61. package/src/commands/generate-story.server.ts +62 -0
  62. package/src/helpers.ts +96 -0
  63. package/src/index.node.ts +101 -0
  64. package/src/index.ts +1 -0
  65. package/src/util/list-components.ts +16 -0
  66. package/src/util/story-hmr.ts +52 -0
  67. package/src/util/svelte.ts +137 -0
  68. package/svelte.config.js +5 -0
  69. package/tsconfig.build.json +7 -0
  70. package/tsconfig.json +41 -0
  71. package/vite.config.ts +103 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Guillaume Chau (original "histoire" project)
4
+ Copyright (c) 2026 Sorin Gitlan (poveste fork)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,89 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Created with Inkscape (http://www.inkscape.org/) -->
3
+
4
+ <svg
5
+ width="1536"
6
+ height="512"
7
+ viewBox="0 0 1536 512"
8
+ version="1.1"
9
+ id="svg5"
10
+ xmlns="http://www.w3.org/2000/svg"
11
+ xmlns:svg="http://www.w3.org/2000/svg">
12
+ <defs
13
+ id="defs2" />
14
+ <g
15
+ id="layer1">
16
+ <rect
17
+ style="opacity:0.5;fill:#ff3e00;fill-opacity:1;stroke-width:1.00375"
18
+ id="rect1372"
19
+ width="314.30923"
20
+ height="406.60901"
21
+ x="-26.565063"
22
+ y="134.75079"
23
+ transform="rotate(-23.821262)"
24
+ ry="8" />
25
+ <rect
26
+ style="fill:#ff3e00;fill-opacity:1;stroke-width:1.00375"
27
+ id="rect850"
28
+ width="314.30923"
29
+ height="406.60901"
30
+ x="77.571838"
31
+ y="72.808708"
32
+ ry="8"
33
+ transform="rotate(-4.5744534)" />
34
+ </g>
35
+ <g
36
+ id="layer3">
37
+ <path
38
+ id="path1657-3"
39
+ style="display:inline;fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:8.34923;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
40
+ d="M 359.38947,355.95134 320.72935,176.52942 238.34613,238.94118 Z M 273.64124,273.06608 152.59788,156.05591 191.25804,335.47786 Z" />
41
+ <g
42
+ aria-label="Histoire"
43
+ id="text1821"
44
+ style="font-size:231.926px;line-height:1.25;font-family:Sen;-inkscape-font-specification:Sen;fill:#ff3e00;stroke-width:5.79813;fill-opacity:1"
45
+ transform="matrix(1.1500556,0,0,1.1500556,-105.40156,-38.414233)">
46
+ <path
47
+ d="M 693.87591,344.24783 V 181.89964 h 25.04801 v 162.34819 z m -105.99018,0 V 181.89964 h 25.04801 v 162.34819 z m 10.90052,-68.88202 v -24.1203 h 106.22211 v 24.1203 z"
48
+ style="font-family:'Lexend Deca';-inkscape-font-specification:'Lexend Deca';fill:#ff3e00;fill-opacity:1"
49
+ id="path16857" />
50
+ <path
51
+ d="M 762.294,344.24783 V 222.48669 h 23.88838 v 121.76114 z m 11.5963,-148.66456 q -7.65356,0 -11.82822,-3.94274 -4.17467,-3.94274 -4.17467,-11.13245 0,-6.72585 4.17467,-10.90052 4.40659,-4.17467 11.82822,-4.17467 7.65356,0 11.82823,3.94274 4.17466,3.94275 4.17466,11.13245 0,6.72585 -4.40659,10.90052 -4.17467,4.17467 -11.5963,4.17467 z"
52
+ style="font-family:'Lexend Deca';-inkscape-font-specification:'Lexend Deca';fill:#ff3e00;fill-opacity:1"
53
+ id="path16859" />
54
+ <path
55
+ d="m 863.41371,346.56709 q -15.30711,0 -27.59919,-5.33429 -12.29208,-5.3343 -20.40949,-15.77097 l 16.23482,-13.91556 q 6.95778,8.11741 15.07519,11.82822 8.34934,3.47889 18.78601,3.47889 4.17466,0 7.65355,-0.9277 3.71082,-1.15963 6.26201,-3.24696 2.78311,-2.08734 4.17466,-4.87045 1.39156,-3.01504 1.39156,-6.49393 0,-6.03007 -4.40659,-9.74089 -2.31926,-1.62348 -7.42164,-3.47889 -4.87044,-2.08733 -12.75593,-4.17467 -13.4517,-3.47889 -22.03297,-7.88548 -8.58126,-4.4066 -13.21978,-9.97282 -3.47889,-4.40659 -5.10237,-9.50897 -1.62348,-5.33429 -1.62348,-11.59629 0,-7.65356 3.24696,-13.91556 3.47889,-6.49393 9.27704,-11.13245 6.03008,-4.87045 13.91556,-7.42163 8.11741,-2.55119 17.16253,-2.55119 8.58126,0 16.93059,2.31926 8.58126,2.31926 15.77097,6.72585 7.18971,4.4066 12.06015,10.43667 l -13.68363,15.07519 q -4.4066,-4.40659 -9.74089,-7.65355 -5.10237,-3.47889 -10.43667,-5.3343 -5.3343,-1.85541 -9.74089,-1.85541 -4.87045,0 -8.81319,0.9277 -3.94274,0.92771 -6.72586,2.78312 -2.55118,1.8554 -3.94274,4.63852 -1.39155,2.78311 -1.39155,6.262 0.23192,3.01504 1.39155,5.79815 1.39156,2.55118 3.71082,4.40659 2.55118,1.85541 7.65356,3.94274 5.10237,2.08734 12.98785,3.94274 11.5963,3.01504 19.01793,6.72586 7.65356,3.47889 12.06015,8.11741 4.63852,4.40659 6.49393,10.20474 1.85541,5.79815 1.85541,12.98786 0,10.43667 -6.03008,18.786 -5.79815,8.11741 -15.77096,12.75593 -9.97282,4.63852 -22.2649,4.63852 z"
56
+ style="font-family:'Lexend Deca';-inkscape-font-specification:'Lexend Deca';fill:#ff3e00;fill-opacity:1"
57
+ id="path16861" />
58
+ <path
59
+ d="M 948.99398,344.24783 V 191.4086 h 23.88838 v 152.83923 z m -25.27993,-98.56854 v -23.1926 h 77.46325 v 23.1926 z"
60
+ style="font-family:'Lexend Deca';-inkscape-font-specification:'Lexend Deca';fill:#ff3e00;fill-opacity:1"
61
+ id="path16863" />
62
+ <path
63
+ d="m 1076.5528,346.56709 q -17.8583,0 -32.0058,-8.11741 -13.9156,-8.34933 -22.033,-22.49682 -8.1174,-14.37941 -8.1174,-32.70156 0,-18.32216 8.1174,-32.46964 8.1174,-14.37941 22.033,-22.49682 14.1475,-8.34934 32.0058,-8.34934 17.6263,0 31.5419,8.34934 14.1475,8.11741 22.2649,22.49682 8.1174,14.14748 8.1174,32.46964 0,18.32215 -8.1174,32.70156 -8.1174,14.14749 -22.2649,22.49682 -13.9156,8.11741 -31.5419,8.11741 z m 0,-21.80104 q 10.9005,0 19.4818,-5.3343 8.5812,-5.56622 13.4517,-14.84326 4.8704,-9.50897 4.6385,-21.33719 0.2319,-12.06016 -4.6385,-21.33719 -4.8705,-9.50897 -13.4517,-14.84327 -8.5813,-5.3343 -19.4818,-5.3343 -10.9005,0 -19.7137,5.56623 -8.5813,5.3343 -13.4517,14.84326 -4.8705,9.27704 -4.6386,21.10527 -0.2319,11.82822 4.6386,21.33719 4.8704,9.27704 13.4517,14.84326 8.8132,5.3343 19.7137,5.3343 z"
64
+ style="font-family:'Lexend Deca';-inkscape-font-specification:'Lexend Deca';fill:#ff3e00;fill-opacity:1"
65
+ id="path16865" />
66
+ <path
67
+ d="M 1168.3954,344.24783 V 222.48669 h 23.8884 v 121.76114 z m 11.5963,-148.66456 q -7.6536,0 -11.8282,-3.94274 -4.1747,-3.94274 -4.1747,-11.13245 0,-6.72585 4.1747,-10.90052 4.4065,-4.17467 11.8282,-4.17467 7.6535,0 11.8282,3.94274 4.1747,3.94275 4.1747,11.13245 0,6.72585 -4.4066,10.90052 -4.1747,4.17467 -11.5963,4.17467 z"
68
+ style="font-family:'Lexend Deca';-inkscape-font-specification:'Lexend Deca';fill:#ff3e00;fill-opacity:1"
69
+ id="path16867" />
70
+ <path
71
+ d="M 1228.928,344.24783 V 222.48669 h 24.1203 v 38.26779 l -2.3192,-9.27704 q 2.5512,-8.81319 8.5812,-16.0029 6.262,-7.1897 14.1475,-11.36437 8.1174,-4.17467 16.6987,-4.17467 3.9427,0 7.4216,0.69578 3.7109,0.69578 5.7982,1.62348 l -6.262,25.97571 q -2.7831,-1.15963 -6.262,-1.85541 -3.247,-0.9277 -6.4939,-0.9277 -6.262,0 -12.0602,2.55119 -5.5662,2.31926 -9.9728,6.72585 -4.1747,4.17467 -6.7259,9.97282 -2.5512,5.56622 -2.5512,12.29207 v 67.25854 z"
72
+ style="font-family:'Lexend Deca';-inkscape-font-specification:'Lexend Deca';fill:#ff3e00;fill-opacity:1"
73
+ id="path16869" />
74
+ <path
75
+ d="m 1374.1134,346.56709 q -18.786,0 -33.3973,-7.88548 -14.3794,-8.11741 -22.7288,-22.03297 -8.1174,-13.91556 -8.1174,-32.00579 0,-14.37941 4.6386,-26.20763 4.6385,-11.82823 12.7559,-20.40949 8.3493,-8.81319 19.7137,-13.45171 11.5963,-4.87045 25.048,-4.87045 11.8282,0 22.033,4.63852 10.2047,4.4066 17.6263,12.29208 7.6536,7.88549 11.5963,18.78601 4.1747,10.66859 3.9428,23.42452 l -0.2319,10.20475 h -99.4963 l -5.3343,-19.01794 h 84.1891 l -3.4788,3.94275 v -5.56623 q -0.6958,-7.65355 -5.1024,-13.68363 -4.4066,-6.03008 -11.1325,-9.50897 -6.7258,-3.47889 -14.6113,-3.47889 -12.524,0 -21.1053,4.87045 -8.5812,4.63852 -12.9878,13.91556 -4.4066,9.04511 -4.4066,22.49682 0,12.75593 5.3343,22.2649 5.3343,9.27704 15.0752,14.37941 9.7409,5.10237 22.4968,5.10237 9.0451,0 16.6987,-3.01504 7.8855,-3.01504 16.9306,-10.90052 l 12.0601,16.9306 q -5.5662,5.56622 -13.6836,9.74089 -7.8855,4.17467 -16.9306,6.72585 -8.8132,2.31926 -17.3945,2.31926 z"
76
+ style="font-family:'Lexend Deca';-inkscape-font-specification:'Lexend Deca';fill:#ff3e00;fill-opacity:1"
77
+ id="path16871" />
78
+ </g>
79
+ </g>
80
+ <g
81
+ id="layer2"
82
+ style="display:none">
83
+ <path
84
+ id="path1657"
85
+ style="fill:#b4fae2;fill-opacity:1;stroke:#b4fae2;stroke-width:8;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
86
+ d="m 296,103.98242 -135.53125,177.9668 h 88.70117 z M 262.83008,230.05078 216,408.01758 351.53125,230.05078 Z"
87
+ transform="rotate(-4.156553,256,256.00691)" />
88
+ </g>
89
+ </svg>
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Created with Inkscape (http://www.inkscape.org/) -->
3
+
4
+ <svg
5
+ width="512"
6
+ height="512"
7
+ viewBox="0 0 512 512"
8
+ version="1.1"
9
+ id="svg5"
10
+ xmlns="http://www.w3.org/2000/svg"
11
+ xmlns:svg="http://www.w3.org/2000/svg">
12
+ <defs
13
+ id="defs2" />
14
+ <g
15
+ id="layer1">
16
+ <rect
17
+ style="opacity:0.5;fill:#ff3e00;fill-opacity:1;stroke-width:1.00375"
18
+ id="rect1372"
19
+ width="314.30923"
20
+ height="406.60901"
21
+ x="-26.565063"
22
+ y="134.75079"
23
+ transform="rotate(-23.821262)"
24
+ ry="8" />
25
+ <rect
26
+ style="fill:#ff3e00;fill-opacity:1;stroke-width:1.00375"
27
+ id="rect850"
28
+ width="314.30923"
29
+ height="406.60901"
30
+ x="77.571838"
31
+ y="72.808708"
32
+ ry="8"
33
+ transform="rotate(-4.5744534)" />
34
+ </g>
35
+ <g
36
+ id="layer3"
37
+ style="display:inline">
38
+ <path
39
+ id="path1657-3"
40
+ style="display:inline;fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:8.34923;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
41
+ d="M 359.38947,355.95134 320.72935,176.52942 238.34613,238.94118 Z M 273.64124,273.06608 152.59788,156.05591 191.25804,335.47786 Z" />
42
+ </g>
43
+ <g
44
+ id="layer2"
45
+ style="display:none">
46
+ <path
47
+ id="path1657"
48
+ style="fill:#b4fae2;fill-opacity:1;stroke:#b4fae2;stroke-width:8;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
49
+ d="m 296,103.98242 -135.53125,177.9668 h 88.70117 z M 262.83008,230.05078 216,408.01758 351.53125,230.05078 Z"
50
+ transform="rotate(-4.156553,256,256.00691)" />
51
+ </g>
52
+ </svg>
@@ -0,0 +1 @@
1
+ import e from"./MountVariant.svelte";import{getContext as t,setContext as n}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as r from"svelte/internal/client";import{omitInheritStoryProps as i}from"@poveste/shared";function a(a,o){let s=r.sanitize_slots(o),c=r.legacy_rest_props(o,[`children`,`$$slots`,`$$events`,`$$legacy`]),l=r.legacy_rest_props(c,[]);r.push(o,!1);let u=r.mutable_source(),d=t(`__hstStory`);n(`__hstIndex`,{value:0}),n(`__hstSlots`,s),r.legacy_pre_effect(()=>i,()=>{r.set(u,Object.keys(d).filter(e=>!i.includes(e)).reduce((e,t)=>(e[t]=d[t],e),{}))}),r.legacy_pre_effect_reset(),r.init();var f=r.comment(),p=r.first_child(f),m=t=>{e(t,r.spread_props(()=>r.get(u),()=>l,{implicit:!0,children:(e,t)=>{var n=r.comment(),i=r.first_child(n);r.slot(i,o,`default`,{},null),r.append(e,n)},$$slots:{default:!0,controls:(e,t)=>{var n=r.comment(),i=r.first_child(n);r.slot(i,o,`controls`,{},null),r.append(e,n)}}}))},h=e=>{var t=r.comment(),n=r.first_child(t);r.slot(n,o,`default`,{},null),r.append(e,t)};r.if(p,e=>{r.untrack(()=>d.variants.length===1&&d.variants[0].id===`_default`)?e(m):e(h,-1)}),r.append(a,f),r.pop()}export{a as default};
@@ -0,0 +1,24 @@
1
+ <script>
2
+ import { omitInheritStoryProps } from '@poveste/shared'
3
+ import { getContext, setContext } from 'svelte'
4
+ import MountVariant from './MountVariant.svelte'
5
+
6
+ const story = getContext('__hstStory')
7
+ let index = { value: 0 }
8
+ setContext('__hstIndex', index)
9
+ setContext('__hstSlots', $$slots)
10
+
11
+ $: inheritedFromStory = Object.keys(story).filter(key => !omitInheritStoryProps.includes(key)).reduce((acc, key) => {
12
+ acc[key] = story[key]
13
+ return acc
14
+ }, {})
15
+ </script>
16
+
17
+ {#if story.variants.length === 1 && story.variants[0].id === '_default'}
18
+ <MountVariant {...inheritedFromStory} {...$$restProps} implicit>
19
+ <slot />
20
+ <slot name="controls" slot="controls" />
21
+ </MountVariant>
22
+ {:else}
23
+ <slot />
24
+ {/if}
@@ -0,0 +1 @@
1
+ import{afterUpdate as e,getContext as t}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as n from"svelte/internal/client";n.from_html(`<!> <!>`,1);function r(r,i){let a=n.sanitize_slots(i);n.push(i,!1);let o=n.prop(i,`source`,8,null),s=n.prop(i,`responsiveDisabled`,8,!1),c=n.prop(i,`autoPropsDisabled`,8,!1),l=n.prop(i,`setupApp`,8,null),u=n.prop(i,`implicit`,8,!1),d=t(`__hstStory`),f=t(`__hstIndex`),p=t(`__hstSlots`),m=d.variants[f.value];f.value++;function h(){Object.assign(m,{slots:()=>({default:!0,controls:a.controls??p.controls}),source:o(),responsiveDisabled:s(),autoPropsDisabled:c(),setupApp:l(),configReady:!0}),!u()&&!d.meta?.hasVariantChildComponents&&(d.meta=d.meta||{},Object.assign(d.meta,{hasVariantChildComponents:!0}))}h(),e(()=>{h()}),n.init();var g=n.comment(),_=n.first_child(g);n.if(_,e=>{}),n.append(r,g),n.pop()}export{r as default};
@@ -0,0 +1,47 @@
1
+ <script>
2
+ import { afterUpdate, getContext } from 'svelte'
3
+
4
+ export let source = null
5
+ export let responsiveDisabled = false
6
+ export let autoPropsDisabled = false
7
+ export let setupApp = null
8
+ export let implicit = false
9
+
10
+ const story = getContext('__hstStory')
11
+ const index = getContext('__hstIndex')
12
+ const storySlots = getContext('__hstSlots')
13
+
14
+ const variant = story.variants[index.value]
15
+ index.value++
16
+
17
+ function updateVariant () {
18
+ Object.assign(variant, {
19
+ slots: () => ({
20
+ default: true,
21
+ controls: $$slots.controls ?? storySlots.controls,
22
+ }),
23
+ source,
24
+ responsiveDisabled,
25
+ autoPropsDisabled,
26
+ setupApp,
27
+ configReady: true,
28
+ })
29
+
30
+ if (!implicit && !story.meta?.hasVariantChildComponents) {
31
+ story.meta = story.meta || {}
32
+ Object.assign(story.meta, {
33
+ hasVariantChildComponents: true,
34
+ })
35
+ }
36
+ }
37
+ updateVariant()
38
+
39
+ afterUpdate(() => {
40
+ updateVariant()
41
+ })
42
+ </script>
43
+
44
+ {#if false}
45
+ <slot />
46
+ <slot name="controls" />
47
+ {/if}
@@ -0,0 +1 @@
1
+ import{getContext as e,setContext as t}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as n from"svelte/internal/client";var r=n.from_html(`<!> <!>`,1);function i(i,a){n.push(a,!1);let o=e(`__hstStory`),s=e(`__hstVariant`),c=e(`__hstSlot`);t(`__hstIndex`,{value:0});let l=n.prop(a,`source`,8,null);n.legacy_pre_effect(()=>n.deep_read_state(l()),()=>{l()!=null&&Object.assign(s,{source:l()})}),n.legacy_pre_effect_reset(),n.init();var u=r(),d=n.first_child(u),f=e=>{var t=n.comment(),r=n.first_child(t);n.slot(r,a,`controls`,{},null),n.append(e,t)};n.if(d,e=>{c===`controls`&&e(f)});var p=n.sibling(d,2),m=e=>{var t=n.comment(),r=n.first_child(t);n.slot(r,a,`default`,{},null),n.append(e,t)};n.if(p,e=>{n.untrack(()=>c===`default`||o.meta?.hasVariantChildComponents)&&e(m)}),n.append(i,u),n.pop()}export{i as default};
@@ -0,0 +1,27 @@
1
+ <script>
2
+ import { getContext, setContext } from 'svelte'
3
+
4
+ const story = getContext('__hstStory')
5
+ const currentVariant = getContext('__hstVariant')
6
+ const slotName = getContext('__hstSlot')
7
+
8
+ let index = { value: 0 }
9
+ setContext('__hstIndex', index)
10
+
11
+ export let source = null
12
+
13
+ $: {
14
+ if (source != null) {
15
+ Object.assign(currentVariant, {
16
+ source,
17
+ })
18
+ }
19
+ }
20
+ </script>
21
+
22
+ {#if slotName === 'controls'}
23
+ <slot name="controls" />
24
+ {/if}
25
+ {#if slotName === 'default' || story.meta?.hasVariantChildComponents}
26
+ <slot />
27
+ {/if}
@@ -0,0 +1 @@
1
+ import{getContext as e}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as t from"svelte/internal/client";var n=t.from_html(`<!> <!>`,1);function r(r,i){t.push(i,!1);let a=t.mutable_source(),o=e(`__hstStory`),s=e(`__hstVariant`),c=e(`__hstSlot`),l=e(`__hstIndex`),u=o.variants[l.value];l.value++;let d=t.prop(i,`source`,8,null);t.legacy_pre_effect(()=>{},()=>{t.set(a,s.id===u.id)}),t.legacy_pre_effect(()=>t.deep_read_state(d()),()=>{d()!=null&&Object.assign(s,{source:d()})}),t.legacy_pre_effect_reset(),t.init();var f=t.comment(),p=t.first_child(f),m=e=>{var r=n(),a=t.first_child(r),o=e=>{var n=t.comment(),r=t.first_child(n);t.slot(r,i,`default`,{},null),t.append(e,n)};t.if(a,e=>{c===`default`&&e(o)});var s=t.sibling(a,2),l=e=>{var n=t.comment(),r=t.first_child(n);t.slot(r,i,`controls`,{},null),t.append(e,n)};t.if(s,e=>{c===`controls`&&e(l)}),t.append(e,r)};t.if(p,e=>{t.get(a)&&e(m)}),t.append(r,f),t.pop()}export{r as default};
@@ -0,0 +1,32 @@
1
+ <script>
2
+ import { getContext } from 'svelte'
3
+
4
+ const story = getContext('__hstStory')
5
+ const currentVariant = getContext('__hstVariant')
6
+ const slotName = getContext('__hstSlot')
7
+ const index = getContext('__hstIndex')
8
+
9
+ const variant = story.variants[index.value]
10
+ index.value++
11
+
12
+ $: shouldRender = currentVariant.id === variant.id
13
+
14
+ export let source = null
15
+
16
+ $: {
17
+ if (source != null) {
18
+ Object.assign(currentVariant, {
19
+ source,
20
+ })
21
+ }
22
+ }
23
+ </script>
24
+
25
+ {#if shouldRender}
26
+ {#if slotName === 'default'}
27
+ <slot />
28
+ {/if}
29
+ {#if slotName === 'controls'}
30
+ <slot name="controls" />
31
+ {/if}
32
+ {/if}
@@ -0,0 +1 @@
1
+ import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import"svelte/internal/client";function e(e){}export{e as default};
File without changes
@@ -0,0 +1 @@
1
+ import{createApp as e,h as t,reactive as n}from"@poveste/vendors/vue";import{createEventDispatcher as r,onMount as i}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as a from"svelte/internal/client";var o=a.from_html(`<div> </div>`);function s(s,c){let l=a.legacy_rest_props(c,[`children`,`$$slots`,`$$events`,`$$legacy`]),u=a.legacy_rest_props(l,[`controlComponent`,`value`]);a.push(c,!1);let d=a.prop(c,`controlComponent`,8),f=a.prop(c,`value`,12),p=r(),m=a.mutable_source(),h,g=n({});function _(e,t){Object.assign(g,{value:e,attrs:t})}i(()=>{_(f(),u),h=e({render(){let e={};if(d().emits)for(let t in d().emits){let n=Array.isArray(d().emits)?d().emits[t]:t,r=n===`input`?`update:modelValue`:n;e[`on${r.charAt(0).toUpperCase()}${r.substring(1)}`]=(...e)=>{n===`update:modelValue`?f(e[0]):p(n,...e)}}return t(d(),{modelValue:f(),...g.attrs,...e,key:`component`})}}),h.mount(a.get(m))}),a.legacy_pre_effect(()=>(a.deep_read_state(f()),a.deep_read_state(u)),()=>{_(f(),u)}),a.legacy_pre_effect_reset(),a.init();var v=o(),y=a.child(v,!0);a.reset(v),a.bind_this(v,e=>a.set(m,e),()=>a.get(m)),a.template_effect(()=>a.set_text(y,(a.deep_read_state(d()),a.untrack(()=>d().name)))),a.append(s,v),a.pop()}export{s as default};
@@ -0,0 +1,63 @@
1
+ <script>
2
+ import { onMount, createEventDispatcher } from 'svelte'
3
+ import {
4
+ createApp as _createApp,
5
+ h as _h,
6
+ reactive as _reactive,
7
+ } from '@poveste/vendors/vue'
8
+
9
+ export let controlComponent
10
+ export let value
11
+
12
+ const dispatch = createEventDispatcher()
13
+
14
+ let el
15
+
16
+ let app
17
+
18
+ const state = _reactive({})
19
+
20
+ function updateState (value, attrs) {
21
+ Object.assign(state, {
22
+ value,
23
+ attrs,
24
+ })
25
+ }
26
+
27
+ onMount(() => {
28
+ updateState(value, $$restProps)
29
+
30
+ app = _createApp({
31
+ render () {
32
+ const finalListeners = {}
33
+ if (controlComponent.emits) {
34
+ for (const k in controlComponent.emits) {
35
+ const key = Array.isArray(controlComponent.emits) ? controlComponent.emits[k] : k
36
+ const finalKey = key === 'input' ? 'update:modelValue' : key
37
+ finalListeners[`on${finalKey.charAt(0).toUpperCase()}${finalKey.substring(1)}`] = (...args) => {
38
+ if (key === 'update:modelValue') {
39
+ value = args[0]
40
+ } else {
41
+ dispatch(key, ...args)
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ return _h(controlComponent, {
48
+ modelValue: value,
49
+ ...state.attrs,
50
+ ...finalListeners,
51
+ key: 'component',
52
+ })
53
+ },
54
+ })
55
+ app.mount(el)
56
+ })
57
+
58
+ $: updateState(value, $$restProps)
59
+ </script>
60
+
61
+ <div bind:this={el}>
62
+ {controlComponent.name}
63
+ </div>
@@ -0,0 +1,8 @@
1
+ export { default as MountStory } from './mount';
2
+ export { default as RenderStory } from './render';
3
+ declare module '@poveste/shared' {
4
+ interface StoryMeta {
5
+ hasVariantChildComponents?: boolean;
6
+ }
7
+ }
8
+ export declare function generateSourceCode(): void;
@@ -0,0 +1 @@
1
+ import e from"./mount.js";import t from"./render.js";function n(){}export{e as MountStory,t as RenderStory,n as generateSourceCode};
@@ -0,0 +1,16 @@
1
+ import type { Story } from '@poveste/shared';
2
+ import type { PropType as _PropType } from '@poveste/vendors/vue';
3
+ declare const _default: import("@vue/runtime-core").DefineComponent<import("@vue/runtime-core").ExtractPropTypes<{
4
+ story: {
5
+ type: _PropType<Story>;
6
+ required: true;
7
+ };
8
+ }>, {
9
+ el: import("@vue/reactivity").Ref<HTMLDivElement, HTMLDivElement>;
10
+ }, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {}, string, import("@vue/runtime-core").PublicProps, Readonly<import("@vue/runtime-core").ExtractPropTypes<{
11
+ story: {
12
+ type: _PropType<Story>;
13
+ required: true;
14
+ };
15
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
16
+ export default _default;
@@ -0,0 +1 @@
1
+ import{callSetupFunctions as e,mountSvelteComponent as t}from"../util/svelte.js";import n from"./MountVariant.svelte";import r from"./MountStory.svelte";import i from"./Stub.svelte";import{components as a}from"@poveste/controls";import{defineComponent as o,h as s,onMounted as c,onUnmounted as l,ref as u,watch as d}from"@poveste/vendors/vue";import*as f from"virtual:$histoire-generated-global-setup";import*as p from"virtual:$histoire-setup";var m=o({name:`MountStory`,props:{story:{type:Object,required:!0}},setup(i){let a=u(),o,s,m=null;async function g(){s=document.createElement(`div`),a.value.appendChild(s);let c=await t(i.story.file.component,{target:s,props:{Hst:{Story:r,Variant:n,...h()}},context:new Map(Object.entries({__hstStory:i.story}))},`client`);o=c.app,m=c.destroy,await e(f,p,{app:o,story:i.story,variant:null})}function _(){m?.(),m=null,s&&=(s.parentNode?.removeChild(s),null),o=null}return d(()=>i.story.id,async()=>{_(),await g()}),c(async()=>{await g()}),l(()=>{_()}),{el:a}},render(){return s(`div`,{ref:`el`})}});function h(){let e={};for(let t in a)e[t.substring(3)]=i;return e}export{m as default};
@@ -0,0 +1,34 @@
1
+ import type { Story, Variant } from '@poveste/shared';
2
+ import type { PropType as _PropType } from '@poveste/vendors/vue';
3
+ declare const _default: import("@vue/runtime-core").DefineComponent<import("@vue/runtime-core").ExtractPropTypes<{
4
+ variant: {
5
+ type: _PropType<Variant>;
6
+ required: true;
7
+ };
8
+ story: {
9
+ type: _PropType<Story>;
10
+ required: true;
11
+ };
12
+ slotName: {
13
+ type: StringConstructor;
14
+ default: string;
15
+ };
16
+ }>, {
17
+ el: import("@vue/reactivity").Ref<HTMLDivElement, HTMLDivElement>;
18
+ }, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {}, string, import("@vue/runtime-core").PublicProps, Readonly<import("@vue/runtime-core").ExtractPropTypes<{
19
+ variant: {
20
+ type: _PropType<Variant>;
21
+ required: true;
22
+ };
23
+ story: {
24
+ type: _PropType<Story>;
25
+ required: true;
26
+ };
27
+ slotName: {
28
+ type: StringConstructor;
29
+ default: string;
30
+ };
31
+ }>> & Readonly<{}>, {
32
+ slotName: string;
33
+ }, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
34
+ export default _default;
@@ -0,0 +1 @@
1
+ import{callSetupFunctions as e,createWrappedComponent as t,getLegacyStateApi as n,mountSvelteComponent as r}from"../util/svelte.js";import i from"./RenderStory.svelte";import a from"./RenderVariant.svelte";import{syncState as o}from"./util.js";import s from"./Wrap.svelte";import{components as c}from"@poveste/controls";import{defineComponent as l,h as u,onMounted as d,onUnmounted as f,ref as p,watch as m}from"@poveste/vendors/vue";import*as h from"virtual:$histoire-generated-global-setup";import*as g from"virtual:$histoire-setup";var _=l({name:`RenderStory`,props:{variant:{type:Object,required:!0},story:{type:Object,required:!0},slotName:{type:String,default:`default`}},setup(t,{emit:s}){let c=p(),l,u,_=[];function y(e,t){document.addEventListener(e,t);let n=()=>document.removeEventListener(e,t);return _.push(n),{off:n}}async function b(){u=document.createElement(`div`),c.value.appendChild(u);let d=[],{off:f}=y(`SvelteRegisterComponent`,e=>{let{component:t}=e.detail;d.push(t)}),p=await r(t.story.file.component,{target:u,props:{Hst:{Story:i,Variant:a,...v()}},context:new Map(Object.entries({__hstStory:t.story,__hstVariant:t.variant,__hstSlot:t.slotName}))},`client`);l=p.app,_.push(()=>{p.destroy()});let m=d.find(e=>e.$$&&l?.$$&&e.$$===l.$$)??l;f(),d=[];function b(){let e=m?.$replace;e&&(m.$replace=(...t)=>{let n=e.apply(m,t);return m=n??m,n})}b();let x=n(m);if(x){let{apply:e,stop:n}=o(t.variant.state,e=>{x.injectState(e)});_.push(n);let r,i=()=>{e(x.captureState()),r=requestAnimationFrame(i)};r=requestAnimationFrame(i),_.push(()=>{cancelAnimationFrame(r)}),e(x.captureState())}await e(h,g,{app:l,story:t.story,variant:t.variant},t.variant.setupApp),s(`ready`)}function x(){_.forEach(e=>e()),_=[],u&&=(u.parentNode?.removeChild(u),null),l=null}return m(()=>t.story.id,async()=>{x(),await b()}),d(async()=>{await b()}),f(()=>{x()}),{el:c}},render(){return u(`div`,{ref:`el`})}});function v(){let e={};for(let t in c)e[t.substring(3)]=y(c[t]);return e}function y(e){return t(s,e)}export{_ as default};
@@ -0,0 +1,4 @@
1
+ export declare function syncState(variantState: any, onChange: (state: any) => unknown): {
2
+ apply: (value: any) => void;
3
+ stop(): void;
4
+ };
@@ -0,0 +1 @@
1
+ import{watch as e}from"@poveste/vendors/vue";import{applyState as t,clone as n}from"@poveste/shared";function r(e){let t={};for(let n in e){if(n===`Hst`)continue;let r=e[n];typeof r!=`function`&&r!==void 0&&(r instanceof HTMLElement||typeof r==`object`&&r?.$$||(t[n]=r))}return t}function i(i,a){let o=!1,s=e(()=>i,e=>{e!=null&&(o?o=!1:(o=!0,a(r(e))))},{deep:!0,immediate:!0});function c(e){e!=null&&(o?o=!1:(o=!0,t(i,n(r(e)))))}return{apply:c,stop(){s()}}}export{i as syncState};
@@ -0,0 +1 @@
1
+ import{getContext as e,setContext as t}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as n from"svelte/internal/client";function r(r,i){n.push(i,!1);let a=n.prop(i,`title`,8,null),o=n.prop(i,`id`,8,null),s=n.prop(i,`group`,8,null),c=n.prop(i,`layout`,8,null),l=n.prop(i,`icon`,8,null),u=n.prop(i,`iconColor`,8,null),d=n.prop(i,`docsOnly`,8,!1),f=e(`__hstAddStory`),p=e(`__hstStoryFile`),m={id:o()??p.id,title:a()??p.fileName,group:s(),layout:c(),icon:l(),iconColor:u(),docsOnly:d(),variants:[]};f(m),t(`__hstStory`,m),t(`__hstAddVariant`,e=>{m.variants.push(e)}),n.init();var h=n.comment(),g=n.first_child(h);n.slot(g,i,`default`,{},null),n.append(r,h),n.pop()}export{r as default};
@@ -0,0 +1,34 @@
1
+ <script>
2
+ import { getContext, setContext } from 'svelte'
3
+
4
+ export let title = null
5
+ export let id = null
6
+ export let group = null
7
+ export let layout = null
8
+ export let icon = null
9
+ export let iconColor = null
10
+ export let docsOnly = false
11
+
12
+ const addStory = getContext('__hstAddStory')
13
+ const file = getContext('__hstStoryFile')
14
+
15
+ const story = {
16
+ id: id ?? file.id,
17
+ title: title ?? file.fileName,
18
+ group,
19
+ layout,
20
+ icon,
21
+ iconColor,
22
+ docsOnly,
23
+ variants: [],
24
+ }
25
+
26
+ addStory(story)
27
+
28
+ setContext('__hstStory', story)
29
+ setContext('__hstAddVariant', (variant) => {
30
+ story.variants.push(variant)
31
+ })
32
+ </script>
33
+
34
+ <slot />
@@ -0,0 +1 @@
1
+ import{getContext as e}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as t from"svelte/internal/client";function n(n,r){t.push(r,!1);let i=t.prop(r,`title`,8,`untitled`),a=t.prop(r,`id`,8,null),o=t.prop(r,`icon`,8,null),s=t.prop(r,`iconColor`,8,null),c=e(`__hstStory`),l=e(`__hstAddVariant`);function u(){return`${c.id}-${c.variants.length}`}l({id:a()??u(),title:i(),icon:o(),iconColor:s()}),t.init(),t.pop()}export{n as default};
@@ -0,0 +1,24 @@
1
+ <script>
2
+ import { getContext } from 'svelte'
3
+
4
+ export let title = 'untitled'
5
+ export let id = null
6
+ export let icon = null
7
+ export let iconColor = null
8
+
9
+ const story = getContext('__hstStory')
10
+ const addVariant = getContext('__hstAddVariant')
11
+
12
+ function generateId () {
13
+ return `${story.id}-${story.variants.length}`
14
+ }
15
+
16
+ const variant = {
17
+ id: id ?? generateId(),
18
+ title,
19
+ icon,
20
+ iconColor,
21
+ }
22
+
23
+ addVariant(variant)
24
+ </script>
@@ -0,0 +1,2 @@
1
+ import type { ServerRunPayload } from '@poveste/shared';
2
+ export declare function run({ file, el, storyData }: ServerRunPayload): Promise<void>;
@@ -0,0 +1 @@
1
+ import{callSetupFunctions as e,mountSvelteComponent as t}from"../util/svelte.js";import n from"./Story.svelte";import r from"./Variant.svelte";import*as i from"virtual:$histoire-generated-global-setup";import*as a from"virtual:$histoire-setup";import{tick as o}from"svelte";async function s({file:s,el:c,storyData:l}){let{default:u}=await import(/* @vite-ignore */s.moduleId),d=await t(u,{target:c,props:{Hst:{Story:n,Variant:r}},context:new Map(Object.entries({__hstAddStory(e){l.push(e)},__hstStoryFile:s}))},`client`);await e(i,a,{app:d.app,story:null,variant:null}),await o(),l[0]?.variants.length||l[0].variants.push({id:`_default`,title:`default`}),d.destroy()}export{s as run};
@@ -0,0 +1,3 @@
1
+ import type { ClientCommandOptions } from 'poveste';
2
+ declare const _default: ClientCommandOptions;
3
+ export default _default;
@@ -0,0 +1,27 @@
1
+ import { kebabCase } from 'change-case';
2
+ import { openStory, sendEvent } from 'poveste/plugin';
3
+ export default {
4
+ prompts: [
5
+ {
6
+ field: 'component',
7
+ label: 'Choose a component',
8
+ type: 'select',
9
+ options: async (search) => sendEvent('listSvelteComponents', { search }),
10
+ required: true,
11
+ },
12
+ {
13
+ field: 'fileName',
14
+ label: 'File name',
15
+ type: 'text',
16
+ required: true,
17
+ defaultValue: answers => answers.component?.replace(/[^/]+\/([^/]+)\.svelte$/, '$1.story.svelte'),
18
+ },
19
+ ],
20
+ clientAction: (params) => {
21
+ const index = params.component.lastIndexOf('/');
22
+ const dirname = params.component.substring(0, index + 1);
23
+ const file = `${dirname}${params.fileName}`;
24
+ const storyId = kebabCase(file.toLowerCase());
25
+ openStory(storyId);
26
+ },
27
+ };
@@ -0,0 +1,3 @@
1
+ import type { PluginCommand } from 'poveste';
2
+ declare const _default: PluginCommand;
3
+ export default _default;