@poveste/plugin-svelte 0.2.1 → 0.3.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.
- package/dist/client/MountStory.js +1 -1
- package/dist/client/MountStory.svelte +14 -11
- package/dist/client/MountVariant.svelte +35 -35
- package/dist/client/RenderStory.js +1 -1
- package/dist/client/RenderStory.svelte +13 -13
- package/dist/client/RenderVariant.js +1 -1
- package/dist/client/RenderVariant.svelte +18 -15
- package/dist/client/Wrap.svelte +47 -46
- package/dist/client/mount.d.ts +4 -4
- package/dist/client/mount.js +1 -1
- package/dist/client/render.d.ts +4 -4
- package/dist/client/render.js +1 -1
- package/dist/client/util.js +1 -1
- package/dist/collect/Story.svelte +25 -25
- package/dist/collect/Variant.svelte +17 -17
- package/dist/collect/index.js +1 -1
- package/package.json +8 -8
- package/src/client/MountStory.svelte +14 -11
- package/src/client/MountVariant.svelte +35 -35
- package/src/client/RenderStory.svelte +13 -13
- package/src/client/RenderVariant.svelte +18 -15
- package/src/client/Wrap.svelte +47 -46
- package/src/client/util.ts +21 -10
- package/src/collect/Story.svelte +25 -25
- package/src/collect/Variant.svelte +17 -17
- package/tsconfig.json +1 -1
|
@@ -1 +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=
|
|
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=t(`__pvtStory`);n(`__pvtIndex`,{value:0}),n(`__pvtSlots`,s);let d=Object.keys(u).filter(e=>!i.includes(e)).reduce((e,t)=>(e[t]=u[t],e),{});r.init();var f=r.comment(),p=r.first_child(f),m=t=>{e(t,r.spread_props(()=>d,()=>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(()=>u.variants.length===1&&u.variants[0].id===`_default`)?e(m):e(h,-1)}),r.append(a,f),r.pop()}export{a as default};
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { omitInheritStoryProps } from '@poveste/shared'
|
|
3
|
-
import { getContext, setContext } from 'svelte'
|
|
4
|
-
import MountVariant from './MountVariant.svelte'
|
|
2
|
+
import { omitInheritStoryProps } from '@poveste/shared'
|
|
3
|
+
import { getContext, setContext } from 'svelte'
|
|
4
|
+
import MountVariant from './MountVariant.svelte'
|
|
5
5
|
|
|
6
|
-
const story = getContext('__pvtStory')
|
|
7
|
-
|
|
8
|
-
setContext('__pvtIndex', index)
|
|
9
|
-
setContext('__pvtSlots', $$slots)
|
|
6
|
+
const story = getContext('__pvtStory')
|
|
7
|
+
const index = { value: 0 }
|
|
8
|
+
setContext('__pvtIndex', index)
|
|
9
|
+
setContext('__pvtSlots', $$slots)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
// Not `$:`: Svelte invalidates a reactive statement when a variable it
|
|
12
|
+
// references is reassigned, and `story` is a const read from context that
|
|
13
|
+
// never is — so the statement ran exactly once whichever way it is written.
|
|
14
|
+
const inheritedFromStory = Object.keys(story).filter(key => !omitInheritStoryProps.includes(key)).reduce((acc, key) => {
|
|
15
|
+
acc[key] = story[key]
|
|
16
|
+
return acc
|
|
17
|
+
}, {})
|
|
15
18
|
</script>
|
|
16
19
|
|
|
17
20
|
{#if story.variants.length === 1 && story.variants[0].id === '_default'}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { afterUpdate, getContext } from 'svelte'
|
|
2
|
+
import { afterUpdate, getContext } from 'svelte'
|
|
3
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
|
|
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
9
|
|
|
10
|
-
const story = getContext('__pvtStory')
|
|
11
|
-
const index = getContext('__pvtIndex')
|
|
12
|
-
const storySlots = getContext('__pvtSlots')
|
|
10
|
+
const story = getContext('__pvtStory')
|
|
11
|
+
const index = getContext('__pvtIndex')
|
|
12
|
+
const storySlots = getContext('__pvtSlots')
|
|
13
13
|
|
|
14
|
-
const variant = story.variants[index.value]
|
|
15
|
-
index.value++
|
|
14
|
+
const variant = story.variants[index.value]
|
|
15
|
+
index.value++
|
|
16
16
|
|
|
17
|
-
function updateVariant
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
if (!implicit && !story.meta?.hasVariantChildComponents) {
|
|
31
|
-
story.meta = story.meta || {}
|
|
32
|
-
Object.assign(story.meta, {
|
|
33
|
-
hasVariantChildComponents: true,
|
|
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,
|
|
34
28
|
})
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
updateVariant()
|
|
38
29
|
|
|
39
|
-
|
|
30
|
+
if (!implicit && !story.meta?.hasVariantChildComponents) {
|
|
31
|
+
story.meta = story.meta || {}
|
|
32
|
+
Object.assign(story.meta, {
|
|
33
|
+
hasVariantChildComponents: true,
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
40
37
|
updateVariant()
|
|
41
|
-
|
|
38
|
+
|
|
39
|
+
afterUpdate(() => {
|
|
40
|
+
updateVariant()
|
|
41
|
+
})
|
|
42
42
|
</script>
|
|
43
43
|
|
|
44
44
|
{#if false}
|
|
45
|
-
<slot />
|
|
46
|
-
<slot name="controls" />
|
|
45
|
+
<slot />
|
|
46
|
+
<slot name="controls" />
|
|
47
47
|
{/if}
|
|
@@ -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";var r=n.from_html(`<!> <!>`,1);function i(i,a){n.push(a,!1);let o=e(`__pvtStory`),s=e(`__pvtVariant`),c=e(`__pvtSlot`);t(`__pvtIndex`,{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
|
|
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(`__pvtStory`),s=e(`__pvtVariant`),c=e(`__pvtSlot`);t(`__pvtIndex`,{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};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getContext, setContext } from 'svelte'
|
|
2
|
+
import { getContext, setContext } from 'svelte'
|
|
3
3
|
|
|
4
|
-
const story = getContext('__pvtStory')
|
|
5
|
-
const currentVariant = getContext('__pvtVariant')
|
|
6
|
-
const slotName = getContext('__pvtSlot')
|
|
4
|
+
const story = getContext('__pvtStory')
|
|
5
|
+
const currentVariant = getContext('__pvtVariant')
|
|
6
|
+
const slotName = getContext('__pvtSlot')
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
setContext('__pvtIndex', index)
|
|
8
|
+
const index = { value: 0 }
|
|
9
|
+
setContext('__pvtIndex', index)
|
|
10
10
|
|
|
11
|
-
export let source = null
|
|
11
|
+
export let source = null
|
|
12
12
|
|
|
13
|
-
$: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
$: {
|
|
14
|
+
if (source != null) {
|
|
15
|
+
Object.assign(currentVariant, {
|
|
16
|
+
source,
|
|
17
|
+
})
|
|
18
|
+
}
|
|
18
19
|
}
|
|
19
|
-
}
|
|
20
20
|
</script>
|
|
21
21
|
|
|
22
22
|
{#if slotName === 'controls'}
|
|
@@ -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";var n=t.from_html(`<!> <!>`,1);function r(r,i){t.push(i,!1);let a=
|
|
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=e(`__pvtStory`),o=e(`__pvtVariant`),s=e(`__pvtSlot`),c=e(`__pvtIndex`),l=a.variants[c.value];c.value++;let u=o.id===l.id,d=t.prop(i,`source`,8,null);t.legacy_pre_effect(()=>t.deep_read_state(d()),()=>{d()!=null&&Object.assign(o,{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=>{s==="default"&&e(o)});var c=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(c,e=>{s===`controls`&&e(l)}),t.append(e,r)};t.if(p,e=>{u&&e(m)}),t.append(r,f),t.pop()}export{r as default};
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
2
|
+
import { getContext } from 'svelte'
|
|
3
3
|
|
|
4
|
-
const story = getContext('__pvtStory')
|
|
5
|
-
const currentVariant = getContext('__pvtVariant')
|
|
6
|
-
const slotName = getContext('__pvtSlot')
|
|
7
|
-
const index = getContext('__pvtIndex')
|
|
4
|
+
const story = getContext('__pvtStory')
|
|
5
|
+
const currentVariant = getContext('__pvtVariant')
|
|
6
|
+
const slotName = getContext('__pvtSlot')
|
|
7
|
+
const index = getContext('__pvtIndex')
|
|
8
8
|
|
|
9
|
-
const variant = story.variants[index.value]
|
|
10
|
-
index.value++
|
|
9
|
+
const variant = story.variants[index.value]
|
|
10
|
+
index.value++
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
// Not `$:`: Svelte invalidates a reactive statement when a variable it
|
|
13
|
+
// references is reassigned, and both of these are consts that never are —
|
|
14
|
+
// so the statement ran exactly once whichever way it is written.
|
|
15
|
+
const shouldRender = currentVariant.id === variant.id
|
|
13
16
|
|
|
14
|
-
export let source = null
|
|
17
|
+
export let source = null
|
|
15
18
|
|
|
16
|
-
$: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
$: {
|
|
20
|
+
if (source != null) {
|
|
21
|
+
Object.assign(currentVariant, {
|
|
22
|
+
source,
|
|
23
|
+
})
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
|
-
}
|
|
23
26
|
</script>
|
|
24
27
|
|
|
25
28
|
{#if shouldRender}
|
package/dist/client/Wrap.svelte
CHANGED
|
@@ -1,61 +1,62 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
2
|
+
import {
|
|
3
|
+
createApp as _createApp,
|
|
4
|
+
h as _h,
|
|
5
|
+
reactive as _reactive,
|
|
6
|
+
} from '@poveste/vendors/vue'
|
|
7
|
+
import { createEventDispatcher, onMount } from 'svelte'
|
|
8
8
|
|
|
9
|
-
export let controlComponent
|
|
10
|
-
export let value
|
|
9
|
+
export let controlComponent
|
|
10
|
+
export let value
|
|
11
11
|
|
|
12
|
-
const dispatch = createEventDispatcher()
|
|
12
|
+
const dispatch = createEventDispatcher()
|
|
13
13
|
|
|
14
|
-
let el
|
|
14
|
+
let el
|
|
15
15
|
|
|
16
|
-
let app
|
|
16
|
+
let app
|
|
17
17
|
|
|
18
|
-
const state = _reactive({})
|
|
18
|
+
const state = _reactive({})
|
|
19
19
|
|
|
20
|
-
function updateState
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
onMount(() => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
dispatch(key, ...args)
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
47
|
+
|
|
48
|
+
return _h(controlComponent, {
|
|
49
|
+
modelValue: value,
|
|
50
|
+
...state.attrs,
|
|
51
|
+
...finalListeners,
|
|
52
|
+
key: 'component',
|
|
53
|
+
})
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
app.mount(el)
|
|
54
57
|
})
|
|
55
|
-
app.mount(el)
|
|
56
|
-
})
|
|
57
58
|
|
|
58
|
-
$: updateState(value, $$restProps)
|
|
59
|
+
$: updateState(value, $$restProps)
|
|
59
60
|
</script>
|
|
60
61
|
|
|
61
62
|
<div bind:this={el}>
|
package/dist/client/mount.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { Story } from '@poveste/shared';
|
|
2
2
|
import type { PropType as _PropType } from '@poveste/vendors/vue';
|
|
3
|
-
declare const _default: import("
|
|
3
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
4
4
|
story: {
|
|
5
5
|
type: _PropType<Story>;
|
|
6
6
|
required: true;
|
|
7
7
|
};
|
|
8
8
|
}>, {
|
|
9
|
-
el: import("
|
|
10
|
-
}, {}, {}, {}, import("
|
|
9
|
+
el: import("vue").Ref<HTMLDivElement, HTMLDivElement>;
|
|
10
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
11
11
|
story: {
|
|
12
12
|
type: _PropType<Story>;
|
|
13
13
|
required: true;
|
|
14
14
|
};
|
|
15
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("
|
|
15
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
16
16
|
export default _default;
|
package/dist/client/mount.js
CHANGED
|
@@ -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*as f from"virtual:$poveste-generated-global-setup";import*as p from"virtual:$poveste-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({__pvtStory:i.story}))},`client`);o=c.app,m=c.destroy
|
|
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:$poveste-generated-global-setup";import*as p from"virtual:$poveste-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({__pvtStory:i.story}))},`client`);o=c.app,m=c.destroy;let l={app:o,story:i.story,variant:null};await e(f,p,l)}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};
|
package/dist/client/render.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Story, Variant } from '@poveste/shared';
|
|
2
2
|
import type { PropType as _PropType } from '@poveste/vendors/vue';
|
|
3
|
-
declare const _default: import("
|
|
3
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
4
4
|
variant: {
|
|
5
5
|
type: _PropType<Variant>;
|
|
6
6
|
required: true;
|
|
@@ -14,8 +14,8 @@ declare const _default: import("@vue/runtime-core").DefineComponent<import("@vue
|
|
|
14
14
|
default: string;
|
|
15
15
|
};
|
|
16
16
|
}>, {
|
|
17
|
-
el: import("
|
|
18
|
-
}, {}, {}, {}, import("
|
|
17
|
+
el: import("vue").Ref<HTMLDivElement, HTMLDivElement>;
|
|
18
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
19
19
|
variant: {
|
|
20
20
|
type: _PropType<Variant>;
|
|
21
21
|
required: true;
|
|
@@ -30,5 +30,5 @@ declare const _default: import("@vue/runtime-core").DefineComponent<import("@vue
|
|
|
30
30
|
};
|
|
31
31
|
}>> & Readonly<{}>, {
|
|
32
32
|
slotName: string;
|
|
33
|
-
}, {}, {}, {}, string, import("
|
|
33
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
34
34
|
export default _default;
|
package/dist/client/render.js
CHANGED
|
@@ -1 +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:$poveste-generated-global-setup";import*as g from"virtual:$poveste-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({__pvtStory:t.story,__pvtVariant:t.variant,__pvtSlot: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())}
|
|
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:$poveste-generated-global-setup";import*as g from"virtual:$poveste-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({__pvtStory:t.story,__pvtVariant:t.variant,__pvtSlot: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())}let S={app:l,story:t.story,variant:t.variant};await e(h,g,S,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};
|
package/dist/client/util.js
CHANGED
|
@@ -1 +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
|
|
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=>{if(e!=null){if(o){o=!1;return}o=!0,a(r(e))}},{deep:!0,immediate:!0});function c(e){if(e!=null){if(o){o=!1;return}o=t(i,n(r(e)))}}return{apply:c,stop(){s()}}}export{i as syncState};
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getContext, setContext } from 'svelte'
|
|
2
|
+
import { getContext, setContext } from 'svelte'
|
|
3
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
|
|
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
11
|
|
|
12
|
-
const addStory = getContext('__pvtAddStory')
|
|
13
|
-
const file = getContext('__pvtStoryFile')
|
|
12
|
+
const addStory = getContext('__pvtAddStory')
|
|
13
|
+
const file = getContext('__pvtStoryFile')
|
|
14
14
|
|
|
15
|
-
const story = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
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
25
|
|
|
26
|
-
addStory(story)
|
|
26
|
+
addStory(story)
|
|
27
27
|
|
|
28
|
-
setContext('__pvtStory', story)
|
|
29
|
-
setContext('__pvtAddVariant', (variant) => {
|
|
30
|
-
|
|
31
|
-
})
|
|
28
|
+
setContext('__pvtStory', story)
|
|
29
|
+
setContext('__pvtAddVariant', (variant) => {
|
|
30
|
+
story.variants.push(variant)
|
|
31
|
+
})
|
|
32
32
|
</script>
|
|
33
33
|
|
|
34
34
|
<slot />
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
2
|
+
import { getContext } from 'svelte'
|
|
3
3
|
|
|
4
|
-
export let title = 'untitled'
|
|
5
|
-
export let id = null
|
|
6
|
-
export let icon = null
|
|
7
|
-
export let iconColor = null
|
|
4
|
+
export let title = 'untitled'
|
|
5
|
+
export let id = null
|
|
6
|
+
export let icon = null
|
|
7
|
+
export let iconColor = null
|
|
8
8
|
|
|
9
|
-
const story = getContext('__pvtStory')
|
|
10
|
-
const addVariant = getContext('__pvtAddVariant')
|
|
9
|
+
const story = getContext('__pvtStory')
|
|
10
|
+
const addVariant = getContext('__pvtAddVariant')
|
|
11
11
|
|
|
12
|
-
function generateId
|
|
13
|
-
|
|
14
|
-
}
|
|
12
|
+
function generateId() {
|
|
13
|
+
return `${story.id}-${story.variants.length}`
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
const variant = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
16
|
+
const variant = {
|
|
17
|
+
id: id ?? generateId(),
|
|
18
|
+
title,
|
|
19
|
+
icon,
|
|
20
|
+
iconColor,
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
addVariant(variant)
|
|
23
|
+
addVariant(variant)
|
|
24
24
|
</script>
|
package/dist/collect/index.js
CHANGED
|
@@ -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`)
|
|
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:null,variant:null};await e(i,a,f),await o(),l[0]?.variants.length||l[0].variants.push({id:`_default`,title:`default`}),d.destroy()}export{s as run};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poveste/plugin-svelte",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "Poveste plugin for Svelte
|
|
4
|
+
"version": "0.3.0",
|
|
5
|
+
"description": "Poveste plugin for Svelte 5 and SvelteKit support",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Sorin Gitlan"
|
|
8
8
|
},
|
|
@@ -25,17 +25,17 @@
|
|
|
25
25
|
"module": "./dist/index.node.js",
|
|
26
26
|
"types": "./dist/index.node.d.ts",
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"svelte": "^
|
|
29
|
-
"poveste": "^0.
|
|
28
|
+
"svelte": "^5.0.0",
|
|
29
|
+
"poveste": "^0.3.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"change-case": "^5.4.4",
|
|
33
33
|
"globby": "^14.0.2",
|
|
34
34
|
"launch-editor": "^2.9.1",
|
|
35
35
|
"pathe": "^1.1.2",
|
|
36
|
-
"@poveste/controls": "^0.
|
|
37
|
-
"@poveste/shared": "^0.
|
|
38
|
-
"@poveste/vendors": "^0.
|
|
36
|
+
"@poveste/controls": "^0.3.0",
|
|
37
|
+
"@poveste/shared": "^0.3.0",
|
|
38
|
+
"@poveste/vendors": "^0.3.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"svelte-preprocess": "^6.0.3",
|
|
48
48
|
"typescript": "5.6.3",
|
|
49
49
|
"vite": "^8.0.0",
|
|
50
|
-
"poveste": "0.
|
|
50
|
+
"poveste": "0.3.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "rimraf dist && vite build && tsc -d -P tsconfig.build.json && pnpm run build:types",
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { omitInheritStoryProps } from '@poveste/shared'
|
|
3
|
-
import { getContext, setContext } from 'svelte'
|
|
4
|
-
import MountVariant from './MountVariant.svelte'
|
|
2
|
+
import { omitInheritStoryProps } from '@poveste/shared'
|
|
3
|
+
import { getContext, setContext } from 'svelte'
|
|
4
|
+
import MountVariant from './MountVariant.svelte'
|
|
5
5
|
|
|
6
|
-
const story = getContext('__pvtStory')
|
|
7
|
-
|
|
8
|
-
setContext('__pvtIndex', index)
|
|
9
|
-
setContext('__pvtSlots', $$slots)
|
|
6
|
+
const story = getContext('__pvtStory')
|
|
7
|
+
const index = { value: 0 }
|
|
8
|
+
setContext('__pvtIndex', index)
|
|
9
|
+
setContext('__pvtSlots', $$slots)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
// Not `$:`: Svelte invalidates a reactive statement when a variable it
|
|
12
|
+
// references is reassigned, and `story` is a const read from context that
|
|
13
|
+
// never is — so the statement ran exactly once whichever way it is written.
|
|
14
|
+
const inheritedFromStory = Object.keys(story).filter(key => !omitInheritStoryProps.includes(key)).reduce((acc, key) => {
|
|
15
|
+
acc[key] = story[key]
|
|
16
|
+
return acc
|
|
17
|
+
}, {})
|
|
15
18
|
</script>
|
|
16
19
|
|
|
17
20
|
{#if story.variants.length === 1 && story.variants[0].id === '_default'}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { afterUpdate, getContext } from 'svelte'
|
|
2
|
+
import { afterUpdate, getContext } from 'svelte'
|
|
3
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
|
|
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
9
|
|
|
10
|
-
const story = getContext('__pvtStory')
|
|
11
|
-
const index = getContext('__pvtIndex')
|
|
12
|
-
const storySlots = getContext('__pvtSlots')
|
|
10
|
+
const story = getContext('__pvtStory')
|
|
11
|
+
const index = getContext('__pvtIndex')
|
|
12
|
+
const storySlots = getContext('__pvtSlots')
|
|
13
13
|
|
|
14
|
-
const variant = story.variants[index.value]
|
|
15
|
-
index.value++
|
|
14
|
+
const variant = story.variants[index.value]
|
|
15
|
+
index.value++
|
|
16
16
|
|
|
17
|
-
function updateVariant
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
if (!implicit && !story.meta?.hasVariantChildComponents) {
|
|
31
|
-
story.meta = story.meta || {}
|
|
32
|
-
Object.assign(story.meta, {
|
|
33
|
-
hasVariantChildComponents: true,
|
|
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,
|
|
34
28
|
})
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
updateVariant()
|
|
38
29
|
|
|
39
|
-
|
|
30
|
+
if (!implicit && !story.meta?.hasVariantChildComponents) {
|
|
31
|
+
story.meta = story.meta || {}
|
|
32
|
+
Object.assign(story.meta, {
|
|
33
|
+
hasVariantChildComponents: true,
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
40
37
|
updateVariant()
|
|
41
|
-
|
|
38
|
+
|
|
39
|
+
afterUpdate(() => {
|
|
40
|
+
updateVariant()
|
|
41
|
+
})
|
|
42
42
|
</script>
|
|
43
43
|
|
|
44
44
|
{#if false}
|
|
45
|
-
<slot />
|
|
46
|
-
<slot name="controls" />
|
|
45
|
+
<slot />
|
|
46
|
+
<slot name="controls" />
|
|
47
47
|
{/if}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getContext, setContext } from 'svelte'
|
|
2
|
+
import { getContext, setContext } from 'svelte'
|
|
3
3
|
|
|
4
|
-
const story = getContext('__pvtStory')
|
|
5
|
-
const currentVariant = getContext('__pvtVariant')
|
|
6
|
-
const slotName = getContext('__pvtSlot')
|
|
4
|
+
const story = getContext('__pvtStory')
|
|
5
|
+
const currentVariant = getContext('__pvtVariant')
|
|
6
|
+
const slotName = getContext('__pvtSlot')
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
setContext('__pvtIndex', index)
|
|
8
|
+
const index = { value: 0 }
|
|
9
|
+
setContext('__pvtIndex', index)
|
|
10
10
|
|
|
11
|
-
export let source = null
|
|
11
|
+
export let source = null
|
|
12
12
|
|
|
13
|
-
$: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
$: {
|
|
14
|
+
if (source != null) {
|
|
15
|
+
Object.assign(currentVariant, {
|
|
16
|
+
source,
|
|
17
|
+
})
|
|
18
|
+
}
|
|
18
19
|
}
|
|
19
|
-
}
|
|
20
20
|
</script>
|
|
21
21
|
|
|
22
22
|
{#if slotName === 'controls'}
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
2
|
+
import { getContext } from 'svelte'
|
|
3
3
|
|
|
4
|
-
const story = getContext('__pvtStory')
|
|
5
|
-
const currentVariant = getContext('__pvtVariant')
|
|
6
|
-
const slotName = getContext('__pvtSlot')
|
|
7
|
-
const index = getContext('__pvtIndex')
|
|
4
|
+
const story = getContext('__pvtStory')
|
|
5
|
+
const currentVariant = getContext('__pvtVariant')
|
|
6
|
+
const slotName = getContext('__pvtSlot')
|
|
7
|
+
const index = getContext('__pvtIndex')
|
|
8
8
|
|
|
9
|
-
const variant = story.variants[index.value]
|
|
10
|
-
index.value++
|
|
9
|
+
const variant = story.variants[index.value]
|
|
10
|
+
index.value++
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
// Not `$:`: Svelte invalidates a reactive statement when a variable it
|
|
13
|
+
// references is reassigned, and both of these are consts that never are —
|
|
14
|
+
// so the statement ran exactly once whichever way it is written.
|
|
15
|
+
const shouldRender = currentVariant.id === variant.id
|
|
13
16
|
|
|
14
|
-
export let source = null
|
|
17
|
+
export let source = null
|
|
15
18
|
|
|
16
|
-
$: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
$: {
|
|
20
|
+
if (source != null) {
|
|
21
|
+
Object.assign(currentVariant, {
|
|
22
|
+
source,
|
|
23
|
+
})
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
|
-
}
|
|
23
26
|
</script>
|
|
24
27
|
|
|
25
28
|
{#if shouldRender}
|
package/src/client/Wrap.svelte
CHANGED
|
@@ -1,61 +1,62 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
2
|
+
import {
|
|
3
|
+
createApp as _createApp,
|
|
4
|
+
h as _h,
|
|
5
|
+
reactive as _reactive,
|
|
6
|
+
} from '@poveste/vendors/vue'
|
|
7
|
+
import { createEventDispatcher, onMount } from 'svelte'
|
|
8
8
|
|
|
9
|
-
export let controlComponent
|
|
10
|
-
export let value
|
|
9
|
+
export let controlComponent
|
|
10
|
+
export let value
|
|
11
11
|
|
|
12
|
-
const dispatch = createEventDispatcher()
|
|
12
|
+
const dispatch = createEventDispatcher()
|
|
13
13
|
|
|
14
|
-
let el
|
|
14
|
+
let el
|
|
15
15
|
|
|
16
|
-
let app
|
|
16
|
+
let app
|
|
17
17
|
|
|
18
|
-
const state = _reactive({})
|
|
18
|
+
const state = _reactive({})
|
|
19
19
|
|
|
20
|
-
function updateState
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
onMount(() => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
dispatch(key, ...args)
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
47
|
+
|
|
48
|
+
return _h(controlComponent, {
|
|
49
|
+
modelValue: value,
|
|
50
|
+
...state.attrs,
|
|
51
|
+
...finalListeners,
|
|
52
|
+
key: 'component',
|
|
53
|
+
})
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
app.mount(el)
|
|
54
57
|
})
|
|
55
|
-
app.mount(el)
|
|
56
|
-
})
|
|
57
58
|
|
|
58
|
-
$: updateState(value, $$restProps)
|
|
59
|
+
$: updateState(value, $$restProps)
|
|
59
60
|
</script>
|
|
60
61
|
|
|
61
62
|
<div bind:this={el}>
|
package/src/client/util.ts
CHANGED
|
@@ -16,17 +16,30 @@ function cleanupState(state: Record<string, any>): Record<string, any> {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function syncState(variantState, onChange: (state) => unknown) {
|
|
19
|
+
// Same flag, same #95 caveat as `plugin-vue` and the sandbox bridge: `apply`
|
|
20
|
+
// may only claim the next firing when its write will actually cause one, and
|
|
21
|
+
// `applyState` reports that. It matters more here than anywhere else, because
|
|
22
|
+
// the render loop calls `apply` on *every animation frame* whether or not the
|
|
23
|
+
// story did anything — set the flag unconditionally and it is set through
|
|
24
|
+
// roughly every other frame, ready to eat whatever lands in it.
|
|
25
|
+
//
|
|
26
|
+
// The `onChange` direction below still sets it blind. Nothing here can see
|
|
27
|
+
// whether handing the state to the component changed anything, so the same
|
|
28
|
+
// hazard remains on that side. It cannot be exercised today: `syncState` is
|
|
29
|
+
// only reachable through `getLegacyStateApi`, which needs Svelte 4's
|
|
30
|
+
// `$capture_state`/`$inject_state`, and the Svelte example is on 5 with both
|
|
31
|
+
// state-sync specs already `fixme` under #81. Whoever revives that path
|
|
32
|
+
// inherits this note.
|
|
19
33
|
let syncing = false
|
|
20
34
|
|
|
21
35
|
const _stop = _watch(() => variantState, (value) => {
|
|
22
36
|
if (value == null) return
|
|
23
|
-
if (
|
|
24
|
-
syncing = true
|
|
25
|
-
onChange(cleanupState(value))
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
37
|
+
if (syncing) {
|
|
28
38
|
syncing = false
|
|
39
|
+
return
|
|
29
40
|
}
|
|
41
|
+
syncing = true
|
|
42
|
+
onChange(cleanupState(value))
|
|
30
43
|
}, {
|
|
31
44
|
deep: true,
|
|
32
45
|
immediate: true,
|
|
@@ -34,13 +47,11 @@ export function syncState(variantState, onChange: (state) => unknown) {
|
|
|
34
47
|
|
|
35
48
|
function apply(value) {
|
|
36
49
|
if (value == null) return
|
|
37
|
-
if (
|
|
38
|
-
syncing = true
|
|
39
|
-
applyState(variantState, clone(cleanupState(value)))
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
50
|
+
if (syncing) {
|
|
42
51
|
syncing = false
|
|
52
|
+
return
|
|
43
53
|
}
|
|
54
|
+
syncing = applyState(variantState, clone(cleanupState(value)))
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
return {
|
package/src/collect/Story.svelte
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getContext, setContext } from 'svelte'
|
|
2
|
+
import { getContext, setContext } from 'svelte'
|
|
3
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
|
|
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
11
|
|
|
12
|
-
const addStory = getContext('__pvtAddStory')
|
|
13
|
-
const file = getContext('__pvtStoryFile')
|
|
12
|
+
const addStory = getContext('__pvtAddStory')
|
|
13
|
+
const file = getContext('__pvtStoryFile')
|
|
14
14
|
|
|
15
|
-
const story = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
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
25
|
|
|
26
|
-
addStory(story)
|
|
26
|
+
addStory(story)
|
|
27
27
|
|
|
28
|
-
setContext('__pvtStory', story)
|
|
29
|
-
setContext('__pvtAddVariant', (variant) => {
|
|
30
|
-
|
|
31
|
-
})
|
|
28
|
+
setContext('__pvtStory', story)
|
|
29
|
+
setContext('__pvtAddVariant', (variant) => {
|
|
30
|
+
story.variants.push(variant)
|
|
31
|
+
})
|
|
32
32
|
</script>
|
|
33
33
|
|
|
34
34
|
<slot />
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getContext } from 'svelte'
|
|
2
|
+
import { getContext } from 'svelte'
|
|
3
3
|
|
|
4
|
-
export let title = 'untitled'
|
|
5
|
-
export let id = null
|
|
6
|
-
export let icon = null
|
|
7
|
-
export let iconColor = null
|
|
4
|
+
export let title = 'untitled'
|
|
5
|
+
export let id = null
|
|
6
|
+
export let icon = null
|
|
7
|
+
export let iconColor = null
|
|
8
8
|
|
|
9
|
-
const story = getContext('__pvtStory')
|
|
10
|
-
const addVariant = getContext('__pvtAddVariant')
|
|
9
|
+
const story = getContext('__pvtStory')
|
|
10
|
+
const addVariant = getContext('__pvtAddVariant')
|
|
11
11
|
|
|
12
|
-
function generateId
|
|
13
|
-
|
|
14
|
-
}
|
|
12
|
+
function generateId() {
|
|
13
|
+
return `${story.id}-${story.variants.length}`
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
const variant = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
16
|
+
const variant = {
|
|
17
|
+
id: id ?? generateId(),
|
|
18
|
+
title,
|
|
19
|
+
icon,
|
|
20
|
+
iconColor,
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
addVariant(variant)
|
|
23
|
+
addVariant(variant)
|
|
24
24
|
</script>
|