@poveste/plugin-svelte 0.15.0 → 0.16.1

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Poveste + Svelte 5 and SvelteKit
2
2
 
3
- Requires `svelte@^5.46.4` and `@sveltejs/vite-plugin-svelte@^7.0.0`. SvelteKit is supported
3
+ Requires `svelte@^5.46.4` and `@sveltejs/vite-plugin-svelte@^7.3.0`. SvelteKit is supported
4
4
  by this same package — there is no separate plugin — through an optional
5
5
  `@sveltejs/kit@^2.53.0` peer.
6
6
 
@@ -1 +1 @@
1
- import e from"./MountVariant.svelte";import{omitInheritStoryProps as t}from"@poveste/shared";import{getContext as n,setContext as r}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as i from"svelte/internal/client";function a(a,o){let s=i.sanitize_slots(o),c=i.legacy_rest_props(o,[`children`,`$$slots`,`$$events`,`$$legacy`]),l=i.legacy_rest_props(c,[]);i.push(o,!1);let u=n(`__pvtStory`);r(`__pvtIndex`,{value:0}),r(`__pvtSlots`,s),r(`__pvtStoryProps`,l);let d=Object.keys(u).filter(e=>!t.includes(e)).reduce((e,t)=>(e[t]=u[t],e),{});i.init();var f=i.comment(),p=i.first_child(f),m=t=>{e(t,i.spread_props(()=>d,()=>l,{implicit:!0,children:(e,t)=>{var n=i.comment(),r=i.first_child(n);i.slot(r,o,`default`,{},null),i.append(e,n)},$$slots:{default:!0,controls:(e,t)=>{var n=i.comment(),r=i.first_child(n);i.slot(r,o,`controls`,{},null),i.append(e,n)}}}))},h=e=>{var t=i.comment(),n=i.first_child(t);i.slot(n,o,`default`,{},null),i.append(e,t)};i.if(p,e=>{i.untrack(()=>u.variants.length===1&&u.variants[0].id===`_default`)?e(m):e(h,-1)}),i.append(a,f),i.pop()}export{a as default};
1
+ import{slotsContext as e,storyContext as t,storyPropsContext as n,variantIndexContext as r}from"../contexts.js";import i from"./MountVariant.svelte";import{omitInheritStoryProps as a}from"@poveste/shared";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as o from"svelte/internal/client";function s(s,c){let l=o.sanitize_slots(c),u=o.legacy_rest_props(c,[`children`,`$$slots`,`$$events`,`$$legacy`]),d=o.legacy_rest_props(u,[]);o.push(c,!1);let f=t.get(`<Story>`);r.set({value:0}),e.set(l),n.set(d);let p=Object.keys(f).filter(e=>!a.includes(e)).reduce((e,t)=>(e[t]=f[t],e),{});o.init();var m=o.comment(),h=o.first_child(m),g=e=>{i(e,o.spread_props(()=>p,()=>d,{implicit:!0,children:(e,t)=>{var n=o.comment(),r=o.first_child(n);o.slot(r,c,`default`,{},null),o.append(e,n)},$$slots:{default:!0,controls:(e,t)=>{var n=o.comment(),r=o.first_child(n);o.slot(r,c,`controls`,{},null),o.append(e,n)}}}))},_=e=>{var t=o.comment(),n=o.first_child(t);o.slot(n,c,`default`,{},null),o.append(e,t)};o.if(h,e=>{o.untrack(()=>f.variants.length===1&&f.variants[0].id===`_default`)?e(g):e(_,-1)}),o.append(s,m),o.pop()}export{s as default};
@@ -1,16 +1,16 @@
1
1
  <script>
2
2
  import { omitInheritStoryProps } from '@poveste/shared'
3
- import { getContext, setContext } from 'svelte'
3
+ import { slotsContext, storyContext, storyPropsContext, variantIndexContext } from '../contexts.js'
4
4
  import MountVariant from './MountVariant.svelte'
5
5
 
6
- const story = getContext('__pvtStory')
6
+ const story = storyContext.get('<Story>')
7
7
  const index = { value: 0 }
8
- setContext('__pvtIndex', index)
9
- setContext('__pvtSlots', $$slots)
8
+ variantIndexContext.set(index)
9
+ slotsContext.set($$slots)
10
10
  // Slots were given this treatment and props never were, so a story-level prop
11
11
  // reached an implicit variant and was dropped the moment a story declared
12
12
  // explicit ones — `$$restProps` is only spread in the branch below (#466).
13
- setContext('__pvtStoryProps', $$restProps)
13
+ storyPropsContext.set($$restProps)
14
14
 
15
15
  // Not `$:`: Svelte invalidates a reactive statement when a variable it
16
16
  // references is reassigned, and `story` is a const read from context that
@@ -1 +1 @@
1
- import{afterUpdate as e,getContext as t,onDestroy as n}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as r from"svelte/internal/client";r.from_html(`<!> <!>`,1);function i(i,a){let o=r.sanitize_slots(a);r.push(a,!1);let s=r.prop(a,`source`,8,null),c=r.prop(a,`responsiveDisabled`,8,null),l=r.prop(a,`autoPropsDisabled`,8,!1),u=r.prop(a,`setupApp`,8,null),d=r.prop(a,`implicit`,8,!1),f=t(`__pvtStory`),p=t(`__pvtIndex`),m=t(`__pvtSlots`),h=t(`__pvtStoryProps`)??{},g=t(`__pvtTargetVariantId`)??null,_=f.variants[p.value];p.value++;let v=!1;function y(){Object.assign(_,{slots:()=>({default:!0,controls:o.controls??m.controls}),source:s(),responsiveDisabled:c()??h.responsiveDisabled??!1,autoPropsDisabled:l(),setupApp:u()??h.setupApp??null,configReady:!0}),!d()&&!f.meta?.hasVariantChildComponents&&(f.meta=f.meta||{},Object.assign(f.meta,{hasVariantChildComponents:!0}))}function b(){v||(v=!0,y())}if(g===null)b();else{let e=g.subscribe(e=>{(e===null||_?.id===e)&&b()});n(e)}e(()=>{v&&y()}),r.init();var x=r.comment(),S=r.first_child(x);r.if(S,e=>{}),r.append(i,x),r.pop()}export{i as default};
1
+ import{slotsContext as e,storyContext as t,storyPropsContext as n,targetVariantIdContext as r,variantIndexContext as i}from"../contexts.js";import{afterUpdate as a,onDestroy as o}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as s from"svelte/internal/client";s.from_html(`<!> <!>`,1);function c(c,l){let u=s.sanitize_slots(l);s.push(l,!1);let d=s.prop(l,`source`,8,null),f=s.prop(l,`responsiveDisabled`,8,null),p=s.prop(l,`autoPropsDisabled`,8,!1),m=s.prop(l,`setupApp`,8,null),h=s.prop(l,`implicit`,8,!1),g=s.prop(l,`initState`,8,null),_=t.get(`<Variant>`),v=i.get(`<Variant>`),y=e.getOptional(),b=n.getOptional()??{},x=r.getOptional(),S=_.variants[v.value];v.value++;let C=!1;function w(){Object.assign(S,{slots:()=>({default:!0,controls:u.controls??y.controls}),source:d(),responsiveDisabled:f()??b.responsiveDisabled??!1,autoPropsDisabled:p(),setupApp:m()??b.setupApp??null,configReady:!0}),!h()&&!_.meta?.hasVariantChildComponents&&(_.meta=_.meta||{},Object.assign(_.meta,{hasVariantChildComponents:!0}))}function T(){let e=g()??b.initState??null;e&&S&&!S.__pvtStateSeeded&&(S.__pvtStateSeeded=!0,S.state={...S.state,...e()})}function E(){C||(C=!0,T(),w())}if(x===null)E();else{let e=x.subscribe(e=>{(e===null||S?.id===e)&&E()});o(e)}a(()=>{C&&w()}),s.init();var D=s.comment(),O=s.first_child(D);s.if(O,e=>{}),s.append(c,D),s.pop()}export{c as default};
@@ -1,5 +1,6 @@
1
1
  <script>
2
- import { afterUpdate, getContext, onDestroy } from 'svelte'
2
+ import { afterUpdate, onDestroy } from 'svelte'
3
+ import { slotsContext, storyContext, storyPropsContext, targetVariantIdContext, variantIndexContext } from '../contexts.js'
3
4
 
4
5
  export let source = null
5
6
  // `null` rather than `false`/a handler: these two inherit from the story, and
@@ -10,15 +11,16 @@
10
11
  export let autoPropsDisabled = false
11
12
  export let setupApp = null
12
13
  export let implicit = false
14
+ export let initState = null
13
15
 
14
- const story = getContext('__pvtStory')
15
- const index = getContext('__pvtIndex')
16
- const storySlots = getContext('__pvtSlots')
17
- const storyProps = getContext('__pvtStoryProps') ?? {}
16
+ const story = storyContext.get('<Variant>')
17
+ const index = variantIndexContext.get('<Variant>')
18
+ const storySlots = slotsContext.getOptional()
19
+ const storyProps = storyPropsContext.getOptional() ?? {}
18
20
  // A store: a sandbox sets it to the one variant this realm serves and changes
19
21
  // it when the realm is retargeted (#240). Null in the app realm, which keeps
20
22
  // every variant's bookkeeping.
21
- const targetVariantId = getContext('__pvtTargetVariantId') ?? null
23
+ const targetVariantId = targetVariantIdContext.getOptional()
22
24
 
23
25
  const variant = story.variants[index.value]
24
26
  index.value++
@@ -49,9 +51,35 @@
49
51
  }
50
52
  }
51
53
 
54
+ /**
55
+ * Seeds `variant.state`, which is not only the render mounts' business.
56
+ *
57
+ * The app mounts the current story hidden and never renders a slot for it
58
+ * unless the story has one — so a story with `initState` and no controls
59
+ * snippet left the state empty, and the panel, which builds a control per key
60
+ * out of it, said there were no controls at all. `plugin-vue` seeds from its
61
+ * mount pass for exactly this reason.
62
+ *
63
+ * Guarded by the flag the render mounts already share, so whichever pass
64
+ * arrives first wins and a reader's edit is never seeded over.
65
+ *
66
+ * Read off the story props as well as this variant's own, because a
67
+ * story-level `initState` reaches an explicit variant only through the
68
+ * context — the spread in `MountStory` covers the implicit one alone.
69
+ */
70
+ function seedState() {
71
+ const seed = initState ?? storyProps.initState ?? null
72
+
73
+ if (!seed || !variant || variant.__pvtStateSeeded) return
74
+
75
+ variant.__pvtStateSeeded = true
76
+ variant.state = { ...variant.state, ...seed() }
77
+ }
78
+
52
79
  function becomeTarget() {
53
80
  if (isTarget) return
54
81
  isTarget = true
82
+ seedState()
55
83
  updateVariant()
56
84
  }
57
85
 
@@ -1 +1 @@
1
- import{watch as e}from"@poveste/vendors/vue";import{getContext as t,onDestroy as n,setContext as r}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as i from"svelte/internal/client";var a=i.from_html(`<!> <!>`,1);function o(o,s){let c=i.sanitize_slots(s),l=i.legacy_rest_props(s,[`children`,`$$slots`,`$$events`,`$$legacy`]),u=i.legacy_rest_props(l,[`source`,`initState`]);i.push(s,!1);let d=t(`__pvtStory`),f=i.mutable_source(t(`__pvtVariant`)),p=t(`__pvtSlot`);r(`__pvtIndex`,{value:0}),r(`__pvtStoryProps`,u),i.get(f)&&d.variants.length===1&&d.variants[0].id===`_default`&&Object.assign(i.get(f),{setupApp:u.setupApp??null});let m=i.prop(s,`source`,8,null),h=i.prop(s,`initState`,8,null);h()&&i.get(f)&&!i.get(f).__pvtStateSeeded&&(i.mutate(f,i.get(f).__pvtStateSeeded=!0),i.mutate(f,i.get(f).state={...i.get(f).state,...h()()})),!h()&&p===`controls`&&c.controls&&i.get(f)&&!i.get(f).__pvtStateWarned&&(i.mutate(f,i.get(f).__pvtStateWarned=!0),console.error([`[poveste] Story "${d?.title??d?.id}" has a controls slot but no \`initState\`.`,`Controls will render and appear to work, but their edits cannot reach the story:`,`the story is mounted separately for each slot, so a component-local variable is not shared.`,"Pass `initState` and read state from the snippet —",`https://poveste.dev/guide/migration-from-histoire#svelte-story-state-moves-to-initstate`].join(` `)));let g=i.mutable_source(i.get(f)?.state),_=e(()=>i.get(f)?.state,()=>{i.set(g,i.get(f)?.state)},{deep:!0});n(_),i.legacy_pre_effect(()=>(i.deep_read_state(m()),i.get(g),i.get(f)),()=>{let e=typeof m()==`function`?m()(i.get(g)):m();e!=null&&Object.assign(i.get(f),{source:e})}),i.legacy_pre_effect_reset(),i.init();var v=a(),y=i.first_child(v),b=e=>{var t=i.comment(),n=i.first_child(t);i.slot(n,s,`controls`,{get state(){return i.get(g)}},null),i.append(e,t)};i.if(y,e=>{p===`controls`&&e(b)});var x=i.sibling(y,2),S=e=>{var t=i.comment(),n=i.first_child(t);i.slot(n,s,`default`,{get state(){return i.get(g)}},null),i.append(e,t)};i.if(x,e=>{i.untrack(()=>p==="default"||d.meta?.hasVariantChildComponents)&&e(S)}),i.append(o,v),i.pop()}export{o as default};
1
+ import{slotNameContext as e,storyContext as t,storyPropsContext as n,variantContext as r,variantIndexContext as i}from"../contexts.js";import{watch as a}from"@poveste/vendors/vue";import{onDestroy as o}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as s from"svelte/internal/client";var c=s.from_html(`<!> <!>`,1);function l(l,u){let d=s.sanitize_slots(u),f=s.legacy_rest_props(u,[`children`,`$$slots`,`$$events`,`$$legacy`]),p=s.legacy_rest_props(f,[`source`,`initState`]);s.push(u,!1);let m=t.get(`<Story>`),h=s.mutable_source(r.getOptional()),g=e.getOptional();i.set({value:0}),n.set(p),s.get(h)&&m.variants.length===1&&m.variants[0].id===`_default`&&Object.assign(s.get(h),{setupApp:p.setupApp??null});let _=s.prop(u,`source`,8,null),v=s.prop(u,`initState`,8,null);v()&&s.get(h)&&!s.get(h).__pvtStateSeeded&&(s.mutate(h,s.get(h).__pvtStateSeeded=!0),s.mutate(h,s.get(h).state={...s.get(h).state,...v()()})),!v()&&g===`controls`&&d.controls&&s.get(h)&&!s.get(h).__pvtStateWarned&&(s.mutate(h,s.get(h).__pvtStateWarned=!0),console.error([`[poveste] Story "${m?.title??m?.id}" has a controls slot but no \`initState\`.`,`Controls will render and appear to work, but their edits cannot reach the story:`,`the story is mounted separately for each slot, so a component-local variable is not shared.`,"Pass `initState` and read state from the snippet —",`https://poveste.dev/guide/migration-from-histoire#svelte-story-state-moves-to-initstate`].join(` `)));let y=s.mutable_source(s.get(h)?.state),b=a(()=>s.get(h)?.state,()=>{s.set(y,s.get(h)?.state)},{deep:!0});o(b),s.legacy_pre_effect(()=>(s.deep_read_state(_()),s.get(y),s.get(h)),()=>{let e=typeof _()==`function`?_()(s.get(y)):_();e!=null&&Object.assign(s.get(h),{source:e})}),s.legacy_pre_effect_reset(),s.init();var x=c(),S=s.first_child(x),C=e=>{var t=s.comment(),n=s.first_child(t);s.slot(n,u,`controls`,{get state(){return s.get(y)}},null),s.append(e,t)};s.if(S,e=>{g===`controls`&&e(C)});var w=s.sibling(S,2),T=e=>{var t=s.comment(),n=s.first_child(t);s.slot(n,u,`default`,{get state(){return s.get(y)}},null),s.append(e,t)};s.if(w,e=>{s.untrack(()=>g==="default"||m.meta?.hasVariantChildComponents)&&e(T)}),s.append(l,x),s.pop()}export{l as default};
@@ -1,18 +1,19 @@
1
1
  <script>
2
2
  import { watch as _watch } from '@poveste/vendors/vue'
3
- import { getContext, onDestroy, setContext } from 'svelte'
3
+ import { onDestroy } from 'svelte'
4
+ import { slotNameContext, storyContext, storyPropsContext, variantContext, variantIndexContext } from '../contexts.js'
4
5
 
5
- const story = getContext('__pvtStory')
6
- const currentVariant = getContext('__pvtVariant')
7
- const slotName = getContext('__pvtSlot')
6
+ const story = storyContext.get('<Story>')
7
+ const currentVariant = variantContext.getOptional()
8
+ const slotName = slotNameContext.getOptional()
8
9
 
9
10
  const index = { value: 0 }
10
- setContext('__pvtIndex', index)
11
+ variantIndexContext.set(index)
11
12
  // The sandbox realm's half of story-prop inheritance. `MountStory` does this
12
13
  // for the app realm, and the bridge carries only `variant.state` across the
13
14
  // iframe — so without it a story-level prop reaches the sandbox by accident,
14
15
  // when a grid cell happens to render in the same realm (#466).
15
- setContext('__pvtStoryProps', $$restProps)
16
+ storyPropsContext.set($$restProps)
16
17
 
17
18
  // A story with no `<Hst.Variant>` children has no `RenderVariant` to write the
18
19
  // handler, so the story is the only place it can come from — and without this
@@ -1 +1 @@
1
- import{shouldWarnAboutMissingInitState as e}from"../util/init-state-warning.js";import{watch as t}from"@poveste/vendors/vue";import{getContext as n,onDestroy as r}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as i from"svelte/internal/client";var a=i.from_html(`<!> <!>`,1);function o(o,s){let c=i.sanitize_slots(s);i.push(s,!1);let l=n(`__pvtStory`),u=i.mutable_source(n(`__pvtVariant`)),d=n(`__pvtSlot`),f=n(`__pvtIndex`),p=n(`__pvtStoryProps`)??{},m=l.variants[f.value];f.value++;let h=i.get(u).id===m.id,g=i.prop(s,`source`,8,null),_=i.prop(s,`initState`,8,null),v=i.prop(s,`setupApp`,8,null);h&&Object.assign(i.get(u),{setupApp:v()??p.setupApp??null}),_()&&h&&!i.get(u).__pvtStateSeeded&&(i.mutate(u,i.get(u).__pvtStateSeeded=!0),i.mutate(u,i.get(u).state={...i.get(u).state,..._()()})),h&&e({hasInitState:!!_(),seeded:!!i.get(u).__pvtStateSeeded,slotName:d,hasControlsSlot:!!c.controls,alreadyWarned:!!i.get(u).__pvtStateWarned})&&(i.mutate(u,i.get(u).__pvtStateWarned=!0),console.error([`[poveste] Variant "${m?.title??m?.id}" has a controls slot but no \`initState\`.`,`Controls will render and appear to work, but their edits cannot reach the story:`,`the story is mounted separately for each slot, so a component-local variable is not shared.`,"Pass `initState` and read state from the snippet —",`https://poveste.dev/guide/migration-from-histoire#svelte-story-state-moves-to-initstate`].join(` `)));let y=i.mutable_source(i.get(u)?.state),b=()=>{};h&&(b=t(()=>i.get(u)?.state,()=>{i.set(y,i.get(u)?.state)},{deep:!0})),r(()=>b()),i.legacy_pre_effect(()=>(i.deep_read_state(g()),i.get(y),i.get(u)),()=>{if(h){let e=typeof g()==`function`?g()(i.get(y)):g();e!=null&&Object.assign(i.get(u),{source:e})}}),i.legacy_pre_effect_reset(),i.init();var x=i.comment(),S=i.first_child(x),C=e=>{var t=a(),n=i.first_child(t),r=e=>{var t=i.comment(),n=i.first_child(t);i.slot(n,s,`default`,{get state(){return i.get(y)}},null),i.append(e,t)};i.if(n,e=>{d==="default"&&e(r)});var o=i.sibling(n,2),c=e=>{var t=i.comment(),n=i.first_child(t);i.slot(n,s,`controls`,{get state(){return i.get(y)}},null),i.append(e,t)};i.if(o,e=>{d===`controls`&&e(c)}),i.append(e,t)};i.if(S,e=>{h&&e(C)}),i.append(o,x),i.pop()}export{o as default};
1
+ import{slotNameContext as e,storyContext as t,storyPropsContext as n,variantContext as r,variantIndexContext as i}from"../contexts.js";import{shouldWarnAboutMissingInitState as a}from"../util/init-state-warning.js";import{watch as o}from"@poveste/vendors/vue";import{onDestroy as s}from"svelte";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as c from"svelte/internal/client";var l=c.from_html(`<!> <!>`,1);function u(u,d){let f=c.sanitize_slots(d);c.push(d,!1);let p=t.get(`<Variant>`),m=c.mutable_source(r.getOptional()),h=e.getOptional(),g=i.get(`<Variant>`),_=n.getOptional()??{},v=p.variants[g.value];g.value++;let y=c.get(m).id===v.id,b=c.prop(d,`source`,8,null),x=c.prop(d,`initState`,8,null),S=c.prop(d,`setupApp`,8,null);y&&Object.assign(c.get(m),{setupApp:S()??_.setupApp??null}),x()&&y&&!c.get(m).__pvtStateSeeded&&(c.mutate(m,c.get(m).__pvtStateSeeded=!0),c.mutate(m,c.get(m).state={...c.get(m).state,...x()()})),y&&a({hasInitState:!!x(),seeded:!!c.get(m).__pvtStateSeeded,slotName:h,hasControlsSlot:!!f.controls,alreadyWarned:!!c.get(m).__pvtStateWarned})&&(c.mutate(m,c.get(m).__pvtStateWarned=!0),console.error([`[poveste] Variant "${v?.title??v?.id}" has a controls slot but no \`initState\`.`,`Controls will render and appear to work, but their edits cannot reach the story:`,`the story is mounted separately for each slot, so a component-local variable is not shared.`,"Pass `initState` and read state from the snippet —",`https://poveste.dev/guide/migration-from-histoire#svelte-story-state-moves-to-initstate`].join(` `)));let C=c.mutable_source(c.get(m)?.state),w=()=>{};y&&(w=o(()=>c.get(m)?.state,()=>{c.set(C,c.get(m)?.state)},{deep:!0})),s(()=>w()),c.legacy_pre_effect(()=>(c.deep_read_state(b()),c.get(C),c.get(m)),()=>{if(y){let e=typeof b()==`function`?b()(c.get(C)):b();e!=null&&Object.assign(c.get(m),{source:e})}}),c.legacy_pre_effect_reset(),c.init();var T=c.comment(),E=c.first_child(T),D=e=>{var t=l(),n=c.first_child(t),r=e=>{var t=c.comment(),n=c.first_child(t);c.slot(n,d,`default`,{get state(){return c.get(C)}},null),c.append(e,t)};c.if(n,e=>{h==="default"&&e(r)});var i=c.sibling(n,2),a=e=>{var t=c.comment(),n=c.first_child(t);c.slot(n,d,`controls`,{get state(){return c.get(C)}},null),c.append(e,t)};c.if(i,e=>{h===`controls`&&e(a)}),c.append(e,t)};c.if(E,e=>{y&&e(D)}),c.append(u,T),c.pop()}export{u as default};
@@ -1,13 +1,14 @@
1
1
  <script>
2
2
  import { watch as _watch } from '@poveste/vendors/vue'
3
- import { getContext, onDestroy } from 'svelte'
3
+ import { onDestroy } from 'svelte'
4
+ import { slotNameContext, storyContext, storyPropsContext, variantContext, variantIndexContext } from '../contexts.js'
4
5
  import { shouldWarnAboutMissingInitState } from '../util/init-state-warning.js'
5
6
 
6
- const story = getContext('__pvtStory')
7
- const currentVariant = getContext('__pvtVariant')
8
- const slotName = getContext('__pvtSlot')
9
- const index = getContext('__pvtIndex')
10
- const storyProps = getContext('__pvtStoryProps') ?? {}
7
+ const story = storyContext.get('<Variant>')
8
+ const currentVariant = variantContext.getOptional()
9
+ const slotName = slotNameContext.getOptional()
10
+ const index = variantIndexContext.get('<Variant>')
11
+ const storyProps = storyPropsContext.getOptional() ?? {}
11
12
 
12
13
  const variant = story.variants[index.value]
13
14
  index.value++
@@ -1 +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:g.value,...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};
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:g.value,...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.only_child(v,!0);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};
@@ -1 +1 @@
1
- import{watch as e}from"@poveste/vendors/vue";import{readable as t}from"svelte/store";import{applyState as n}from"@poveste/shared";import{getContext as r}from"svelte";var i=Object.freeze({});function a(a){let l=r(`__pvtStory`),u=r(`__pvtVariant`),d=c(l,u),f=a.map(e=>Array.from({length:s(e)}).fill(i));if(d<0)return o(u),t(f);let p=a[d]??[],m=()=>{let e=f.slice();return e[d]=Array.from({length:s(p)},(e,t)=>u.state?._hPropState?.[t]??i),e},h=null;function g(){!u.state||h===u.state&&u.state._hPropDefs?.length||(h=u.state,n(u.state,{_hPropDefs:p}),u.state._hPropState||n(u.state,{_hPropState:{}}))}return t(m(),t=>{let n=()=>{g(),t(m())};n();let r=[e(()=>u.state,n),e(()=>u.state?._hPropState,n,{deep:!0}),e(()=>u.state?._hPropDefs?.length,n)];return()=>r.forEach(e=>e())})}function o(e){e?.state?._hPropDefs?.length&&n(e.state,{_hPropDefs:[]})}function s(e){return e.reduce((e,t)=>Math.max(e,t.index+1),0)}function c(e,t){return!e||!t||e.autoPropsDisabled||t.autoPropsDisabled?-1:e.variants?.findIndex(e=>e.id===t.id)??-1}export{a as autoProps,c as variantToDrive};
1
+ import{storyContext as e,variantContext as t}from"../contexts.js";import{watch as n}from"@poveste/vendors/vue";import{readable as r}from"svelte/store";import{applyState as i}from"@poveste/shared";var a=Object.freeze({});function o(o){let u=e.getOptional(),d=t.getOptional(),f=l(u,d),p=o.map(e=>Array.from({length:c(e)}).fill(a));if(f<0||!d)return s(d),r(p);let m=o[f]??[],h=()=>{let e=p.slice();return e[f]=Array.from({length:c(m)},(e,t)=>d.state?._hPropState?.[t]??a),e},g=null,_=()=>{!d.state||g===d.state&&d.state._hPropDefs?.length||(g=d.state,i(d.state,{_hPropDefs:m}),d.state._hPropState||i(d.state,{_hPropState:{}}))};return r(h(),e=>{let t=()=>{_(),e(h())};t();let r=[n(()=>d.state,t),n(()=>d.state?._hPropState,t,{deep:!0}),n(()=>d.state?._hPropDefs?.length,t)];return()=>r.forEach(e=>e())})}function s(e){e?.state?._hPropDefs?.length&&i(e.state,{_hPropDefs:[]})}function c(e){return e.reduce((e,t)=>Math.max(e,t.index+1),0)}function l(e,t){return!e||!t||e.autoPropsDisabled||t.autoPropsDisabled?-1:e.variants?.findIndex(e=>e.id===t.id)??-1}export{o as autoProps,l as variantToDrive};
@@ -1 +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{writable as f}from"svelte/store";import*as p from"virtual:$poveste-generated-global-setup";import*as m from"virtual:$poveste-setup";var h=o({name:`MountStory`,props:{story:{type:Object,required:!0},targetVariantId:{type:String,default:null}},setup(i){let a=u(),o,s=null,h=null,_=f(i.targetVariantId);d(()=>i.targetVariantId,e=>{_.set(e)});async function v(){if(!a.value||!i.story.file)return;s=document.createElement(`div`),a.value.appendChild(s);let c=await t(i.story.file.component,{target:s,props:{Hst:{Story:r,Variant:n,...g()}},context:new Map(Object.entries({__pvtStory:i.story,__pvtTargetVariantId:_}))},`client`,{storyId:i.story.id,variantId:i.targetVariantId??void 0});o=c.app,h=c.destroy;let l={app:o,story:i.story,variant:void 0};await e(p,m,l)}function y(){h?.(),h=null,s&&=(s.parentNode?.removeChild(s),null),o=null}return d(()=>i.story.id,async()=>{y(),await v()}),c(async()=>{await v()}),l(()=>{y()}),{el:a}},render(){return s(`div`,{ref:`el`})}});function g(){let e={};for(let t in a)e[t.substring(3)]=i;return e}export{h as default};
1
+ import{storyContext as e,targetVariantIdContext as t}from"../contexts.js";import{callSetupFunctions as n,mountSvelteComponent as r}from"../util/svelte.js";import i from"./MountVariant.svelte";import a from"./MountStory.svelte";import o from"./Stub.svelte";import{components as s}from"@poveste/controls";import{defineComponent as c,h as l,onMounted as u,onUnmounted as d,ref as f,watch as p}from"@poveste/vendors/vue";import{writable as m}from"svelte/store";import*as h from"virtual:$poveste-generated-global-setup";import*as g from"virtual:$poveste-setup";var _=c({name:`MountStory`,props:{story:{type:Object,required:!0},targetVariantId:{type:String,default:null}},setup(o){let s=f(),c,l=null,_=null,y=m(o.targetVariantId);p(()=>o.targetVariantId,e=>{y.set(e)});async function b(){if(!s.value||!o.story.file)return;l=document.createElement(`div`),s.value.appendChild(l);let u=await r(o.story.file.component,{target:l,props:{Hst:{Story:a,Variant:i,...v()}},context:new Map([[e.key,o.story],[t.key,y]])},`client`,{storyId:o.story.id,variantId:o.targetVariantId??void 0});c=u.app,_=u.destroy;let d={app:c,story:o.story,variant:void 0};await n(h,g,d)}function x(){_?.(),_=null,l&&=(l.parentNode?.removeChild(l),null),c=null}return p(()=>o.story.id,async()=>{x(),await b()}),u(async()=>{await b()}),d(()=>{x()}),{el:s}},render(){return l(`div`,{ref:`el`})}});function v(){let e={};for(let t in s)e[t.substring(3)]=o;return e}export{_ as default};
@@ -1 +1 @@
1
- import e from"./RenderStory.svelte";import t from"./RenderVariant.svelte";import{toRaw as n}from"@poveste/vendors/vue";import{getContext as r}from"svelte";function i(i,a){let o=n(i).variants.findIndex(({id:e})=>e===a.id),s=0;return{Story:(t,n)=>(s=0,e(t,n)),Variant:(e,n)=>{if(s++===o)return r(`__pvtIndex`).value=o,t(e,n)}}}export{i as renderStoryComponents};
1
+ import{variantIndexContext as e}from"../contexts.js";import t from"./RenderStory.svelte";import n from"./RenderVariant.svelte";import{toRaw as r}from"@poveste/vendors/vue";function i(i,a){let o=r(i).variants.findIndex(({id:e})=>e===a.id),s=0;return{Story:(e,n)=>(s=0,t(e,n)),Variant:(t,r)=>{if(s++===o)return e.get(`<Story>`).value=o,n(t,r)}}}export{i as renderStoryComponents};
@@ -1 +1 @@
1
- import{callSetupFunctions as e,createWrappedComponent as t,getLegacyStateApi as n,mountSvelteComponent as r}from"../util/svelte.js";import{renderStoryComponents as i}from"./render-story-components.js";import{syncState as a}from"./util.js";import o from"./Wrap.svelte";import{components as s}from"@poveste/controls";import{defineComponent as c,h as l,onMounted as u,onUnmounted as d,ref as f,watch as p}from"@poveste/vendors/vue";import*as m from"virtual:$poveste-generated-global-setup";import*as h from"virtual:$poveste-setup";var g=c({name:`RenderStory`,props:{variant:{type:Object,required:!0},story:{type:Object,required:!0},slotName:{type:String,default:`default`}},setup(t,{emit:o}){let s=f(),c,l=null,g=[];function v(e,t){document.addEventListener(e,t);let n=()=>document.removeEventListener(e,t);return g.push(n),{off:n}}async function y(){if(!s.value||!t.story.file)return;l=document.createElement(`div`),s.value.appendChild(l);let u=[],{off:d}=v(`SvelteRegisterComponent`,e=>{let{component:t}=e.detail;u.push(t)}),f=await r(t.story.file.component,{target:l,props:{Hst:{...i(t.story,t.variant),..._()}},context:new Map(Object.entries({__pvtStory:t.story,__pvtVariant:t.variant,__pvtSlot:t.slotName}))},`client`,{storyId:t.story.id,variantId:t.variant?.id});c=f.app,g.push(()=>{f.destroy()});let p=u.find(e=>e.$$&&c?.$$&&e.$$===c.$$)??c;d(),u=[];function y(){let e=p?.$replace;e&&(p.$replace=(...t)=>{let n=e.apply(p,t);return p=n??p,n})}y();let b=n(p);if(b){let{apply:e,stop:n}=a(t.variant.state,e=>{b.injectState(e)});g.push(n);let r,i=()=>{e(b.captureState()),r=requestAnimationFrame(i)};r=requestAnimationFrame(i),g.push(()=>{cancelAnimationFrame(r)}),e(b.captureState())}let x={app:c,story:t.story,variant:t.variant};await e(m,h,x,t.variant.setupApp),o(`ready`)}function b(){g.forEach(e=>e()),g=[],l&&=(l.parentNode?.removeChild(l),null),c=null}return p(()=>t.story.id,async()=>{b(),await y()}),u(async()=>{await y()}),d(()=>{b()}),{el:s}},render(){return l(`div`,{ref:`el`})}});function _(){let e={};for(let[t,n]of Object.entries(s))e[t.substring(3)]=v(n);return e}function v(e){return t(o,e)}export{g as default};
1
+ import{slotNameContext as e,storyContext as t,variantContext as n}from"../contexts.js";import{callSetupFunctions as r,createWrappedComponent as i,getLegacyStateApi as a,mountSvelteComponent as o}from"../util/svelte.js";import{renderStoryComponents as s}from"./render-story-components.js";import{syncState as c}from"./util.js";import l from"./Wrap.svelte";import{components as u}from"@poveste/controls";import{defineComponent as d,h as f,onMounted as p,onUnmounted as m,ref as h,watch as g}from"@poveste/vendors/vue";import*as _ from"virtual:$poveste-generated-global-setup";import*as v from"virtual:$poveste-setup";var y=d({name:`RenderStory`,props:{variant:{type:Object,required:!0},story:{type:Object,required:!0},slotName:{type:String,default:`default`}},setup(i,{emit:l}){let u=h(),d,f=null,y=[];function x(e,t){document.addEventListener(e,t);let n=()=>document.removeEventListener(e,t);return y.push(n),{off:n}}async function S(){if(!u.value||!i.story.file)return;f=document.createElement(`div`),u.value.appendChild(f);let p=[],{off:m}=x(`SvelteRegisterComponent`,e=>{let{component:t}=e.detail;p.push(t)}),h=await o(i.story.file.component,{target:f,props:{Hst:{...s(i.story,i.variant),...b()}},context:new Map([[t.key,i.story],[n.key,i.variant],[e.key,i.slotName]])},`client`,{storyId:i.story.id,variantId:i.variant?.id});d=h.app,y.push(()=>{h.destroy()});let g=p.find(e=>e.$$&&d?.$$&&e.$$===d.$$)??d;m(),p=[];function S(){let e=g?.$replace;e&&(g.$replace=(...t)=>{let n=e.apply(g,t);return g=n??g,n})}S();let C=a(g);if(C){let{apply:e,stop:t}=c(i.variant.state,e=>{C.injectState(e)});y.push(t);let n,r=()=>{e(C.captureState()),n=requestAnimationFrame(r)};n=requestAnimationFrame(r),y.push(()=>{cancelAnimationFrame(n)}),e(C.captureState())}let w={app:d,story:i.story,variant:i.variant};await r(_,v,w,i.variant.setupApp),l(`ready`)}function C(){y.forEach(e=>e()),y=[],f&&=(f.parentNode?.removeChild(f),null),d=null}return g(()=>i.story.id,async()=>{C(),await S()}),p(async()=>{await S()}),m(()=>{C()}),{el:u}},render(){return f(`div`,{ref:`el`})}});function b(){let e={};for(let[t,n]of Object.entries(u))e[t.substring(3)]=x(n);return e}function x(e){return i(l,e)}export{y as default};
@@ -1 +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=n.prop(i,`autoPropsDisabled`,8,null),p=n.prop(i,`initState`,8,null),m=e(`__pvtAddStory`),h=e(`__pvtStoryFile`),g={id:o()??h.id,title:a()??h.fileName,group:s(),layout:c(),icon:l(),iconColor:u(),docsOnly:d(),autoPropsDisabled:f(),variants:[]};m(g);let _=p()?p()():{};t(`__pvtStory`,g),t(`__pvtAddVariant`,e=>{g.variants.push(e)}),n.init();var v=n.comment(),y=n.first_child(v);n.slot(y,i,`default`,{get state(){return _}},null),n.append(r,v),n.pop()}export{r as default};
1
+ import{addStoryContext as e,addVariantContext as t,collectStoryContext as n,storyFileContext as r}from"../contexts.js";import"svelte/internal/disclose-version";import"svelte/internal/flags/legacy";import*as i from"svelte/internal/client";function a(a,o){i.push(o,!1);let s=i.prop(o,`title`,8,null),c=i.prop(o,`id`,8,null),l=i.prop(o,`group`,8,null),u=i.prop(o,`layout`,8,null),d=i.prop(o,`icon`,8,null),f=i.prop(o,`iconColor`,8,null),p=i.prop(o,`docsOnly`,8,!1),m=i.prop(o,`autoPropsDisabled`,8,null),h=i.prop(o,`initState`,8,null),g=e.getOptional(),_=r.getOptional(),v=c()??_?.id,y=s()??_?.fileName;if(!v||y===void 0)throw Error("[poveste] a <Story> collected outside a story file needs an `id` and a `title`");let b={id:v,title:y,group:l(),layout:u(),icon:d(),iconColor:f(),docsOnly:p(),autoPropsDisabled:m(),variants:[]};g?.(b);let x=h()?h()():{};n.set(b),t.set(e=>{b.variants.push(e)}),i.init();var S=i.comment(),C=i.first_child(S);i.slot(C,o,`default`,{get state(){return x}},null),i.append(a,S),i.pop()}export{a as default};
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { getContext, setContext } from 'svelte'
2
+ import { addStoryContext, addVariantContext, collectStoryContext, storyFileContext } from '../contexts.js'
3
3
 
4
4
  export let title = null
5
5
  export let id = null
@@ -11,12 +11,22 @@
11
11
  export let autoPropsDisabled = null
12
12
  export let initState = null
13
13
 
14
- const addStory = getContext('__pvtAddStory')
15
- const file = getContext('__pvtStoryFile')
14
+ const addStory = addStoryContext.getOptional()
15
+ const file = storyFileContext.getOptional()
16
+
17
+ // Guarded the way `plugin-vue` guards it: collected outside a run there is no
18
+ // file to fall back on, and reading `file.id` off `undefined` said nothing
19
+ // about stories (#981).
20
+ const storyId = id ?? file?.id
21
+ const storyTitle = title ?? file?.fileName
22
+
23
+ if (!storyId || storyTitle === undefined) {
24
+ throw new Error('[poveste] a <Story> collected outside a story file needs an `id` and a `title`')
25
+ }
16
26
 
17
27
  const story = {
18
- id: id ?? file.id,
19
- title: title ?? file.fileName,
28
+ id: storyId,
29
+ title: storyTitle,
20
30
  group,
21
31
  layout,
22
32
  icon,
@@ -29,7 +39,7 @@
29
39
  variants: [],
30
40
  }
31
41
 
32
- addStory(story)
42
+ addStory?.(story)
33
43
 
34
44
  // Collection renders the story's markup purely to discover its variants, but
35
45
  // that markup now reads `state`. Without a value here every expression
@@ -37,8 +47,8 @@
37
47
  // `Cannot read properties of undefined` (#81).
38
48
  const state = initState ? initState() : {}
39
49
 
40
- setContext('__pvtStory', story)
41
- setContext('__pvtAddVariant', (variant) => {
50
+ collectStoryContext.set(story)
51
+ addVariantContext.set((variant) => {
42
52
  story.variants.push(variant)
43
53
  })
44
54
  </script>
@@ -1 +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=t.prop(r,`autoPropsDisabled`,8,!1);t.prop(r,`initState`,8,null);let l=e(`__pvtStory`),u=e(`__pvtAddVariant`);function d(){return`${l.id}-${l.variants.length}`}u({id:a()??d(),title:i(),icon:o(),iconColor:s(),autoPropsDisabled:c()}),t.init(),t.pop()}export{n as default};
1
+ import{addVariantContext as e,collectStoryContext as t}from"../contexts.js";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,`untitled`),o=n.prop(i,`id`,8,null),s=n.prop(i,`icon`,8,null),c=n.prop(i,`iconColor`,8,null),l=n.prop(i,`autoPropsDisabled`,8,!1);n.prop(i,`initState`,8,null);let u=t.get(`<Variant>`);e.get(`<Variant>`)({id:o()??`${u.id}-${u.variants.length}`,title:a(),icon:s(),iconColor:c(),autoPropsDisabled:l()}),n.init(),n.pop()}export{r as default};
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { getContext } from 'svelte'
2
+ import { addVariantContext, collectStoryContext } from '../contexts.js'
3
3
 
4
4
  export let title = 'untitled'
5
5
  export let id = null
@@ -14,15 +14,15 @@
14
14
  // svelte-ignore export_let_unused
15
15
  export let initState = null
16
16
 
17
- const story = getContext('__pvtStory')
18
- const addVariant = getContext('__pvtAddVariant')
19
-
20
- function generateId() {
21
- return `${story.id}-${story.variants.length}`
22
- }
17
+ // Asked for before anything reads them, so a missing `<Story>` is reported
18
+ // once and the same way whether or not the variant carries an `id`. Reading
19
+ // `story.id` inside `generateId` meant the no-id path died on `undefined`
20
+ // and the id path died on `addVariant` not being a function (#981).
21
+ const story = collectStoryContext.get('<Variant>')
22
+ const addVariant = addVariantContext.get('<Variant>')
23
23
 
24
24
  const variant = {
25
- id: id ?? generateId(),
25
+ id: id ?? `${story.id}-${story.variants.length}`,
26
26
  title,
27
27
  icon,
28
28
  iconColor,
@@ -1 +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:$poveste-generated-global-setup";import*as a from"virtual:$poveste-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({__pvtAddStory(e){l.push(e)},__pvtStoryFile:s}))},`client`),f={app:d.app,story:void 0,variant:void 0};if(await e(i,a,f),await o(),!l[0]){d.destroy();return}l[0].variants.length||l[0].variants.push({id:`_default`,title:`default`}),d.destroy()}export{s as run};
1
+ import{addStoryContext as e,storyFileContext as t}from"../contexts.js";import{callSetupFunctions as n,mountSvelteComponent as r}from"../util/svelte.js";import i from"./Story.svelte";import a from"./Variant.svelte";import*as o from"virtual:$poveste-generated-global-setup";import*as s from"virtual:$poveste-setup";import{tick as c}from"svelte";async function l({file:l,el:u,storyData:d}){let{default:f}=await import(/* @vite-ignore */l.moduleId),p=await r(f,{target:u,props:{Hst:{Story:i,Variant:a}},context:new Map([[e.key,e=>{d.push(e)}],[t.key,l]])},`client`),m={app:p.app,story:void 0,variant:void 0};if(await n(o,s,m),await c(),!d[0]){p.destroy();return}d[0].variants.length||d[0].variants.push({id:`_default`,title:`default`}),p.destroy()}export{l as run};
@@ -0,0 +1,39 @@
1
+ /**
2
+ * A context keyed by a symbol, with its set and its get in one place.
3
+ *
4
+ * Ten of these were string keys carrying `any` (#981). Svelte's context map
5
+ * takes any key, so a symbol costs nothing and the type travels with it.
6
+ *
7
+ * `get` and `getOptional` are separate functions rather than one call with a
8
+ * default, because "nobody set this" and "this is allowed to be absent" are
9
+ * different questions that arrived as the same `undefined` — and the first is
10
+ * what an author hits when they nest a component wrongly.
11
+ *
12
+ * The same helper, the same split and the same sentence as `plugin-vue`'s, so
13
+ * the two plugins report a nesting mistake identically. Only the underlying
14
+ * primitive differs: `setContext`/`getContext` rather than `provide`/`inject`.
15
+ */
16
+ export interface Context<T> {
17
+ key: symbol;
18
+ set: (value: T) => void;
19
+ /** Throws, naming the provider, when nothing set it. */
20
+ get: (consumer: string) => T;
21
+ /** `null` when nothing set it, which the caller is expected to handle. */
22
+ getOptional: () => T | null;
23
+ }
24
+ /**
25
+ * `description` is what the symbol shows in a stack; `provider` is the
26
+ * component a reader has to go and add, and is the only part of the message
27
+ * they can act on.
28
+ *
29
+ * `key` is exposed because the collect runner seeds its contexts through a
30
+ * `Map` handed to `mount`, which is not a component and so cannot call `set`.
31
+ *
32
+ * The key comes from the global registry rather than being minted here, because
33
+ * this module is evaluated more than once. A collection worker's module graph is
34
+ * invalidated while a story is mid-run, so `set` and `get` can each hold their
35
+ * own instance of this file — a plain `Symbol()` then differs between them and
36
+ * the lookup misses. Every description here is unique, so the registry cannot
37
+ * put two contexts on one key.
38
+ */
39
+ export declare function createContext<T>(description: string, provider: string): Context<T>;
@@ -0,0 +1,35 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ /**
3
+ * `description` is what the symbol shows in a stack; `provider` is the
4
+ * component a reader has to go and add, and is the only part of the message
5
+ * they can act on.
6
+ *
7
+ * `key` is exposed because the collect runner seeds its contexts through a
8
+ * `Map` handed to `mount`, which is not a component and so cannot call `set`.
9
+ *
10
+ * The key comes from the global registry rather than being minted here, because
11
+ * this module is evaluated more than once. A collection worker's module graph is
12
+ * invalidated while a story is mid-run, so `set` and `get` can each hold their
13
+ * own instance of this file — a plain `Symbol()` then differs between them and
14
+ * the lookup misses. Every description here is unique, so the registry cannot
15
+ * put two contexts on one key.
16
+ */
17
+ export function createContext(description, provider) {
18
+ const key = Symbol.for(description);
19
+ return {
20
+ key,
21
+ set(value) {
22
+ setContext(key, value);
23
+ },
24
+ get(consumer) {
25
+ const value = getContext(key);
26
+ if (value === undefined || value === null) {
27
+ throw new Error(`[poveste] a ${consumer} has to be inside a ${provider}`);
28
+ }
29
+ return value;
30
+ },
31
+ getOptional() {
32
+ return getContext(key) ?? null;
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,17 @@
1
+ import type { ServerStory, ServerStoryFile, ServerVariant, Story, Variant } from '@poveste/shared';
2
+ /** Collect mode: the file being collected, seeded by `collect/index.ts`. */
3
+ export declare const storyFileContext: import("./context.js").Context<ServerStoryFile>;
4
+ /** Collect mode, optional: a `<Story>` collected outside a run has nowhere to report to. */
5
+ export declare const addStoryContext: import("./context.js").Context<(story: ServerStory) => void>;
6
+ /** Collect mode: what `<Variant>` reports itself to. */
7
+ export declare const collectStoryContext: import("./context.js").Context<ServerStory>;
8
+ export declare const addVariantContext: import("./context.js").Context<(variant: ServerVariant) => void>;
9
+ export declare const storyContext: import("./context.js").Context<Story>;
10
+ export declare const variantContext: import("./context.js").Context<Variant>;
11
+ export declare const slotNameContext: import("./context.js").Context<string>;
12
+ export declare const slotsContext: import("./context.js").Context<Record<string, any>>;
13
+ export declare const storyPropsContext: import("./context.js").Context<Record<string, any>>;
14
+ export declare const variantIndexContext: import("./context.js").Context<{
15
+ value: number;
16
+ }>;
17
+ export declare const targetVariantIdContext: import("./context.js").Context<string | null>;
@@ -0,0 +1,22 @@
1
+ import { createContext } from './context.js';
2
+ /*
3
+ * Every context this plugin passes, in one place (#981). Collect mode and the
4
+ * render path are separate keys even where they carry a story each, because
5
+ * they carry different shapes — the same mistake `plugin-vue` made with one
6
+ * string used in two realms.
7
+ */
8
+ /** Collect mode: the file being collected, seeded by `collect/index.ts`. */
9
+ export const storyFileContext = createContext('poveste-svelte-story-file', 'story file');
10
+ /** Collect mode, optional: a `<Story>` collected outside a run has nowhere to report to. */
11
+ export const addStoryContext = createContext('poveste-svelte-add-story', 'story file');
12
+ /** Collect mode: what `<Variant>` reports itself to. */
13
+ export const collectStoryContext = createContext('poveste-svelte-collect-story', '<Story>');
14
+ export const addVariantContext = createContext('poveste-svelte-add-variant', '<Story>');
15
+ /* The render path. */
16
+ export const storyContext = createContext('poveste-svelte-story', '<Story>');
17
+ export const variantContext = createContext('poveste-svelte-variant', '<Variant>');
18
+ export const slotNameContext = createContext('poveste-svelte-slot', '<Story>');
19
+ export const slotsContext = createContext('poveste-svelte-slots', '<Story>');
20
+ export const storyPropsContext = createContext('poveste-svelte-story-props', '<Story>');
21
+ export const variantIndexContext = createContext('poveste-svelte-variant-index', '<Story>');
22
+ export const targetVariantIdContext = createContext('poveste-svelte-target-variant-id', '<Story>');
package/dist/helpers.d.ts CHANGED
@@ -91,6 +91,15 @@ export interface Hst {
91
91
  options: HstControlOption[];
92
92
  title?: string;
93
93
  }>;
94
+ Color: Component<{
95
+ value?: string;
96
+ title?: string;
97
+ }>;
98
+ Date: Component<{
99
+ value?: string;
100
+ title?: string;
101
+ time?: boolean;
102
+ }>;
94
103
  Json: Component<{
95
104
  value: unknown;
96
105
  title: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@poveste/plugin-svelte",
3
3
  "type": "module",
4
- "version": "0.15.0",
4
+ "version": "0.16.1",
5
5
  "description": "Poveste plugin for Svelte 5 and SvelteKit support",
6
6
  "author": {
7
7
  "name": "Sorin Gitlan",
@@ -60,12 +60,12 @@
60
60
  "dist"
61
61
  ],
62
62
  "engines": {
63
- "node": "^22.22.2 || ^24.15.0 || >=26.0.0"
63
+ "node": ">=22.22.2"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@sveltejs/kit": "^2.53.0",
67
- "@sveltejs/vite-plugin-svelte": "^7.0.0",
68
- "poveste": "^0.15.0",
67
+ "@sveltejs/vite-plugin-svelte": "^7.3.0",
68
+ "poveste": "^0.16.1",
69
69
  "svelte": "^5.46.4"
70
70
  },
71
71
  "peerDependenciesMeta": {
@@ -74,26 +74,26 @@
74
74
  }
75
75
  },
76
76
  "dependencies": {
77
- "@poveste/controls": "^0.15.0",
78
- "@poveste/shared": "^0.15.0",
79
- "@poveste/vendors": "^0.15.0",
77
+ "@poveste/controls": "^0.16.1",
78
+ "@poveste/shared": "^0.16.1",
79
+ "@poveste/vendors": "^0.16.1",
80
80
  "change-case": "^5.4.4",
81
- "ignore": "^7.0.6",
81
+ "ignore": "^7.0.10",
82
82
  "launch-editor": "^2.9.1",
83
83
  "pathe": "^2.0.3",
84
84
  "tinyglobby": "^0.2.17"
85
85
  },
86
86
  "devDependencies": {
87
- "@sveltejs/vite-plugin-svelte": "^7.0.0",
88
- "@types/node": "^22.10.1",
87
+ "@sveltejs/vite-plugin-svelte": "^7.3.1",
88
+ "@types/node": "^26.6.3",
89
89
  "concurrently": "^10.0.5",
90
- "fs-extra": "^11.2.0",
91
- "poveste": "0.15.0",
92
- "svelte": "5.55.0",
93
- "svelte-preprocess": "^6.0.3",
90
+ "fs-extra": "^11.4.1",
91
+ "poveste": "0.16.1",
92
+ "svelte": "5.57.1",
93
+ "svelte-preprocess": "^6.0.5",
94
94
  "typescript": "6.0.3",
95
- "vite": "^8.0.0",
96
- "vitest": "^5.0.0"
95
+ "vite": "^8.3.1",
96
+ "vitest": "^5.0.2"
97
97
  },
98
98
  "scripts": {
99
99
  "build": "rimraf dist && vite build && tsc -d -P tsconfig.build.json && pnpm run build:types",