@threlte/theatre 2.0.0 → 2.1.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.
@@ -1,4 +1,4 @@
1
- <script>import { getContext, onDestroy, onMount, setContext } from 'svelte';
1
+ <script>import { getContext, onDestroy, setContext } from 'svelte';
2
2
  // Parent context
3
3
  const { sequences } = getContext('theatre-sheet');
4
4
  // Props
@@ -1,5 +1,6 @@
1
- import { onChange, type ISequence } from '@theatre/core';
1
+ import type { ISequence } from '@theatre/core';
2
2
  import type { Readable, Subscriber, Writable } from 'svelte/store';
3
+ import { onChange } from '../theatre';
3
4
  import type { SequenceOptions } from './types';
4
5
  /**
5
6
  * ### `SequenceController`
@@ -1,5 +1,5 @@
1
- import { onChange, val } from '@theatre/core';
2
1
  import { get } from 'svelte/store';
2
+ import { onChange, val } from '../theatre';
3
3
  /**
4
4
  * ### `SequenceController`
5
5
  *
@@ -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} />
@@ -2,7 +2,7 @@ import type { SvelteComponent } from 'svelte'
2
2
  import type { Transformer } from '../transfomers/types'
3
3
  import type { ConditionalKeys, Primitive } from 'type-fest'
4
4
 
5
- /* COPIED FROM @theatre/core START */
5
+ /* COPIED FROM @threlte/core START */
6
6
  type OmittedPropKeys =
7
7
  | 'type'
8
8
  | 'args'
@@ -36,7 +36,7 @@ type InstanceProps<Type extends any> = Partial<
36
36
  ConditionalKeys<MaybeInstance<Type>, AnyFn> | OmittedPropKeys
37
37
  >
38
38
  >
39
- /* COPIED FROM @theatre/core END */
39
+ /* COPIED FROM @threlte/core END */
40
40
 
41
41
  type ObjectProp<T> = {
42
42
  type?: T
@@ -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> & ObjectProp<T> & Record<string, AnyProp | 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
- Record<string, any>
66
+ {
67
+ default: {
68
+ capture: () => void
69
+ }
70
+ }
63
71
  > {}
@@ -1,4 +1,4 @@
1
- import { types } from '@theatre/core';
1
+ import { types } from '../../../theatre';
2
2
  import { createTransformer } from '../createTransformer';
3
3
  export const color = createTransformer({
4
4
  transform(value) {
@@ -1,6 +1,6 @@
1
1
  import { DEG2RAD, RAD2DEG } from 'three/src/math/MathUtils';
2
2
  import { createTransformer } from '../createTransformer';
3
- import { types } from '@theatre/core';
3
+ import { types } from '../../../theatre';
4
4
  export const degrees = createTransformer({
5
5
  transform(target) {
6
6
  return types.number(target * RAD2DEG);
@@ -1,6 +1,6 @@
1
- import { types } from '@theatre/core';
2
1
  import { DEG2RAD, RAD2DEG } from 'three/src/math/MathUtils';
3
2
  import { createTransformer } from '../createTransformer';
3
+ import { types } from '../../../theatre';
4
4
  export const euler = createTransformer({
5
5
  transform(value) {
6
6
  return types.compound({
@@ -1,4 +1,4 @@
1
- import { types } from '@theatre/core';
1
+ import { types } from '../../../theatre';
2
2
  import { isPrimitive } from '../../sync/utils/isPrimitive';
3
3
  import { createTransformer } from '../createTransformer';
4
4
  export const generic = createTransformer({
@@ -1,4 +1,4 @@
1
- import { types } from '@theatre/core';
1
+ import { types } from '../../../theatre';
2
2
  import { createTransformer } from '../createTransformer';
3
3
  export const normalized = createTransformer({
4
4
  transform(value) {
@@ -1,4 +1,4 @@
1
- import { types } from '@theatre/core';
1
+ import { types } from '../../../theatre';
2
2
  import { createTransformer } from '../createTransformer';
3
3
  import { BackSide, DoubleSide, FrontSide } from 'three';
4
4
  export const side = createTransformer({
@@ -1,4 +1,4 @@
1
- <script>import { types } from '@theatre/core';
1
+ <script>import { types } from '../../theatre';
2
2
  import { T, watch } from '@threlte/core';
3
3
  import { TransformControls } from '@threlte/extras';
4
4
  import { onMount } from 'svelte';
@@ -1,4 +1,7 @@
1
- <script context="module">import Studio from '@theatre/studio';
1
+ <script
2
+
3
+ context="module"
4
+ >import Studio from '@theatre/studio';
2
5
  import { studio } from '../consts';
3
6
  Studio.initialize();
4
7
  studio.set(Studio);
@@ -5,7 +5,10 @@ const browser = typeof window !== 'undefined';
5
5
 
6
6
  {#if browser && enabled}
7
7
  {#await import('./InnerStudio.svelte') then Component}
8
- <svelte:component this={Component.default} {hide}>
8
+ <svelte:component
9
+ this={Component.default}
10
+ {hide}
11
+ >
9
12
  <slot />
10
13
  </svelte:component>
11
14
  {/await}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threlte/theatre",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
5
5
  "license": "MIT",
6
6
  "devDependencies": {
@@ -28,8 +28,8 @@
28
28
  "type-fest": "^2.13.0",
29
29
  "typescript": "^5.0.0",
30
30
  "vite": "^4.3.6",
31
- "@threlte/core": "6.0.3",
32
- "@threlte/extras": "5.1.0"
31
+ "@threlte/core": "6.0.5",
32
+ "@threlte/extras": "5.2.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "svelte": ">=4",