@threlte/theatre 1.0.5 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,6 +5,7 @@ import { isComplexProp } from './utils/isComplexProp';
|
|
|
5
5
|
import { makeAlphanumeric } from './utils/makeAlphanumeric';
|
|
6
6
|
import { parsePropLabel } from './utils/parsePropLabel';
|
|
7
7
|
import { isStringProp } from './utils/isStringProp';
|
|
8
|
+
import { useStudio } from '../../studio/useStudio';
|
|
8
9
|
// used for type hinting auto props
|
|
9
10
|
export let type = undefined;
|
|
10
11
|
/** @package */
|
|
@@ -76,7 +77,28 @@ watch([parent, sheetObject], ([parent, sheetObject]) => {
|
|
|
76
77
|
});
|
|
77
78
|
});
|
|
78
79
|
initProps();
|
|
80
|
+
const studio = useStudio();
|
|
81
|
+
export const capture = () => {
|
|
82
|
+
if (!$studio)
|
|
83
|
+
return;
|
|
84
|
+
const scrub = $studio.scrub();
|
|
85
|
+
Object.keys(sheetObject.current.value).forEach((key) => {
|
|
86
|
+
// first, check if the prop is mapped in this component
|
|
87
|
+
const propMapping = propMappings[key];
|
|
88
|
+
if (!propMapping)
|
|
89
|
+
return;
|
|
90
|
+
// we're using the addedProps map to infer the target property name from the property name on values
|
|
91
|
+
const { target, key: targetKey } = resolvePropertyPath($parent, propMapping.propertyPath);
|
|
92
|
+
const value = propMapping.transformer.transform(target[targetKey]).default;
|
|
93
|
+
scrub.capture(({ set }) => {
|
|
94
|
+
set(sheetObject.current.props[key], value);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
scrub.commit();
|
|
98
|
+
};
|
|
79
99
|
onDestroy(() => {
|
|
80
100
|
removeProps(Object.keys(propMappings));
|
|
81
101
|
});
|
|
82
102
|
</script>
|
|
103
|
+
|
|
104
|
+
<slot {capture} />
|
|
@@ -54,10 +54,18 @@ type AnyProps<T> = {
|
|
|
54
54
|
[P in keyof InstanceProps<T>]?: AnyProp
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
type AllProps<T> = AnyProps<T> &
|
|
57
|
+
type AllProps<T> = AnyProps<T> &
|
|
58
|
+
ObjectProp<T> &
|
|
59
|
+
Record<string, AnyProp | T> & {
|
|
60
|
+
capture?: () => void
|
|
61
|
+
}
|
|
58
62
|
|
|
59
63
|
export default class Sync<T> extends SvelteComponent<
|
|
60
64
|
AllProps<T>,
|
|
61
65
|
Record<string, any>,
|
|
62
|
-
|
|
66
|
+
{
|
|
67
|
+
default: {
|
|
68
|
+
capture: () => void
|
|
69
|
+
}
|
|
70
|
+
}
|
|
63
71
|
> {}
|
|
@@ -1,22 +1,14 @@
|
|
|
1
|
+
<script context="module">import Studio from '@theatre/studio';
|
|
2
|
+
import { studio } from '../consts';
|
|
3
|
+
Studio.initialize();
|
|
4
|
+
studio.set(Studio);
|
|
5
|
+
</script>
|
|
6
|
+
|
|
1
7
|
<script>import { watch } from '@threlte/core';
|
|
2
|
-
import { onMount } from 'svelte';
|
|
3
8
|
import { writable } from 'svelte/store';
|
|
4
|
-
import { studio } from '../consts';
|
|
5
9
|
export let hide;
|
|
6
10
|
const hideStore = writable(hide);
|
|
7
11
|
$: hideStore.set(hide);
|
|
8
|
-
let initialized = false;
|
|
9
|
-
onMount(async () => {
|
|
10
|
-
if ($studio) {
|
|
11
|
-
initialized = true;
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const pkg = await import('@theatre/studio');
|
|
15
|
-
const Studio = pkg.default;
|
|
16
|
-
Studio.initialize();
|
|
17
|
-
studio.set(Studio);
|
|
18
|
-
initialized = true;
|
|
19
|
-
});
|
|
20
12
|
watch([studio, hideStore], ([studio, hide]) => {
|
|
21
13
|
if (hide) {
|
|
22
14
|
studio?.ui.hide();
|
|
@@ -30,6 +22,4 @@ watch([studio, hideStore], ([studio, hide]) => {
|
|
|
30
22
|
});
|
|
31
23
|
</script>
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
<slot />
|
|
35
|
-
{/if}
|
|
25
|
+
<slot />
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
export let enabled = true;
|
|
1
|
+
<script>export let enabled = true;
|
|
3
2
|
export let hide = false;
|
|
4
3
|
const browser = typeof window !== 'undefined';
|
|
5
4
|
</script>
|
|
6
5
|
|
|
7
6
|
{#if browser && enabled}
|
|
8
|
-
|
|
9
|
-
<
|
|
10
|
-
|
|
7
|
+
{#await import('./InnerStudio.svelte') then Component}
|
|
8
|
+
<svelte:component this={Component.default} {hide}>
|
|
9
|
+
<slot />
|
|
10
|
+
</svelte:component>
|
|
11
|
+
{/await}
|
|
11
12
|
{:else}
|
|
12
13
|
<slot />
|
|
13
14
|
{/if}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threlte/theatre",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"devDependencies": {
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"typescript": "^5.0.0",
|
|
30
30
|
"vite": "^4.3.6",
|
|
31
31
|
"@threlte/core": "6.0.3",
|
|
32
|
-
"@threlte/extras": "5.0
|
|
32
|
+
"@threlte/extras": "5.1.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"svelte": ">=4",
|
|
36
36
|
"three": ">=0.133",
|
|
37
37
|
"@threlte/core": ">=6.0.3",
|
|
38
|
-
"@threlte/extras": ">=5.0
|
|
38
|
+
"@threlte/extras": ">=5.1.0",
|
|
39
39
|
"@theatre/core": ">=0.6",
|
|
40
40
|
"@theatre/studio": ">=0.6"
|
|
41
41
|
},
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"dist"
|
|
53
53
|
],
|
|
54
54
|
"scripts": {
|
|
55
|
+
"dev": "vite dev",
|
|
55
56
|
"package": "svelte-kit sync && svelte-package && node ./scripts/cleanupPackage.js && publint",
|
|
56
57
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
57
58
|
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
|