@threlte/theatre 2.1.7 → 3.0.0-next.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.
@@ -1,4 +1,5 @@
1
1
  /// <reference types="svelte" />
2
+ /// <reference types="svelte" />
2
3
  import type { ISequence } from '@theatre/core';
3
4
  import type { Readable, Subscriber, Writable } from 'svelte/store';
4
5
  import { onChange } from '../theatre';
@@ -4,27 +4,24 @@
4
4
  - Potentially Providing a sheet object
5
5
  -->
6
6
  <script>import { useStudio } from '../studio/useStudio';
7
- import { createRawEventDispatcher, currentWritable, watch, useThrelte } from '@threlte/core';
8
- import { getContext, onDestroy, onMount } from 'svelte';
7
+ import { currentWritable, watch, useThrelte } from '@threlte/core';
8
+ import { getContext, onDestroy, onMount, setContext } from 'svelte';
9
9
  import Declare from './declare/Declare.svelte';
10
10
  import Sync from './sync/Sync.svelte';
11
11
  import Transform from './transform/Transform.svelte';
12
- export let key;
13
- export let detach = false;
14
- export let props = undefined;
12
+ let { key, detach = false, props, selected = $bindable(false), ...restProps } = $props();
15
13
  const { invalidate } = useThrelte();
16
14
  let aggregatedProps = { ...props };
17
15
  const { sheet } = getContext('theatre-sheet');
18
16
  const sheetObject = currentWritable(sheet.object(key, aggregatedProps, {
19
17
  reconfigure: true
20
18
  }));
21
- const dispatch = createRawEventDispatcher();
22
19
  onMount(() => {
23
20
  // Because the sheet object value subscription is not running before any
24
21
  // values change, we're emitting the initial value here. Doing this in
25
22
  // onMount also means that child components which might add props to the
26
23
  // sheet object have already been mounted.
27
- dispatch('change', sheetObject.current.value);
24
+ restProps.$$events?.change?.(sheetObject.current.value);
28
25
  });
29
26
  // This flag is used to prevent the sheet object from being created after it
30
27
  // has been detached.
@@ -72,36 +69,15 @@ const removeProps = (propNames) => {
72
69
  updateSheetObject();
73
70
  }
74
71
  };
75
- const augmentConstructorArgs = (args) => {
76
- return {
77
- ...args,
78
- props: {
79
- ...args.props,
80
- sheetObject,
81
- addProps,
82
- removeProps
83
- }
84
- };
85
- };
86
- const proxySyncComponent = new Proxy(Sync, {
87
- construct(_target, [args]) {
88
- return new Sync(augmentConstructorArgs(args));
89
- }
90
- });
91
- const proxyTransformComponent = new Proxy(Transform, {
92
- construct(_target, [args]) {
93
- return new Transform(augmentConstructorArgs(args));
94
- }
95
- });
96
- const proxyDeclareComponent = new Proxy(Declare, {
97
- construct(_target, [args]) {
98
- return new Declare(augmentConstructorArgs(args));
99
- }
72
+ setContext('threlte-theater-sheet-context', {
73
+ sheetObject,
74
+ addProps,
75
+ removeProps
100
76
  });
101
77
  let values = $sheetObject?.value;
102
78
  watch(sheetObject, (sheetObject) => {
103
79
  return sheetObject.onValuesChange((newValues) => {
104
- dispatch('change', newValues);
80
+ restProps.$$events?.change?.(newValues);
105
81
  values = newValues;
106
82
  // this invalidation also invalidates changes catched by slotted
107
83
  // components such as <Sync> or <Declare>.
@@ -111,7 +87,6 @@ watch(sheetObject, (sheetObject) => {
111
87
  // Provide a flag to indicate whether this sheet object is selected in the
112
88
  // Theatre.js studio.
113
89
  const studio = useStudio();
114
- export let selected = false;
115
90
  watch([studio, sheetObject], ([studio, sheetObject]) => {
116
91
  return studio?.onSelectionChange((selection) => {
117
92
  selected = selection.includes(sheetObject);
@@ -135,7 +110,7 @@ const deselect = () => {
135
110
  {select}
136
111
  {deselect}
137
112
  sheetObject={$sheetObject}
138
- Sync={proxySyncComponent}
139
- Transform={proxyTransformComponent}
140
- Declare={proxyDeclareComponent}
113
+ {Sync}
114
+ {Transform}
115
+ {Declare}
141
116
  />
@@ -1,19 +1,14 @@
1
- <script>import { watch } from '@threlte/core';
2
- import { onDestroy } from 'svelte';
1
+ <script>import { watch, currentWritable } from '@threlte/core';
2
+ import { onDestroy, getContext } from 'svelte';
3
3
  export let props;
4
- /** @package */
5
- export let sheetObject;
6
- /** @package */
7
- export let addProps;
8
- /** @package */
9
- export let removeProps;
4
+ const { sheetObject, addProps, removeProps } = getContext('threlte-theater-sheet-context');
10
5
  let values = $sheetObject?.value;
11
6
  addProps(props);
12
7
  onDestroy(() => {
13
8
  removeProps(Object.keys(props));
14
9
  });
15
10
  watch(sheetObject, (sheetObject) => {
16
- return sheetObject.onValuesChange((v) => {
11
+ return sheetObject?.onValuesChange((v) => {
17
12
  values = v;
18
13
  });
19
14
  });
@@ -1,5 +1,5 @@
1
1
  <script>import { resolvePropertyPath, useParent, watch } from '@threlte/core';
2
- import { onDestroy } from 'svelte';
2
+ import { onDestroy, getContext } from 'svelte';
3
3
  import { getInitialValue } from './utils/getInitialValue';
4
4
  import { isComplexProp } from './utils/isComplexProp';
5
5
  import { makeAlphanumeric } from './utils/makeAlphanumeric';
@@ -8,12 +8,7 @@ import { isStringProp } from './utils/isStringProp';
8
8
  import { useStudio } from '../../studio/useStudio';
9
9
  // used for type hinting auto props
10
10
  export let type = undefined;
11
- /** @package */
12
- export let sheetObject;
13
- /** @package */
14
- export let addProps;
15
- /** @package */
16
- export let removeProps;
11
+ const { sheetObject, addProps, removeProps } = getContext('threlte-theater-sheet-context');
17
12
  const parent = useParent();
18
13
  // serves as a map to map (custom) prop names to object target properties
19
14
  let propMappings = {};
@@ -1,7 +1,7 @@
1
1
  <script>import { types } from '../../theatre';
2
- import { T, watch } from '@threlte/core';
2
+ import { T, watch, currentWritable } from '@threlte/core';
3
3
  import { TransformControls } from '@threlte/extras';
4
- import { onMount } from 'svelte';
4
+ import { onMount, getContext } from 'svelte';
5
5
  import { Group } from 'three';
6
6
  import { RAD2DEG } from 'three/src/math/MathUtils.js';
7
7
  import { useStudio } from '../../studio/useStudio';
@@ -13,12 +13,7 @@ export let space = undefined;
13
13
  export let translationSnap = undefined;
14
14
  export let rotationSnap = undefined;
15
15
  export let scaleSnap = undefined;
16
- /** @package */
17
- export let sheetObject;
18
- /** @package */
19
- export let addProps;
20
- /** @package */
21
- export let removeProps;
16
+ const { sheetObject, addProps, removeProps } = getContext('threlte-theater-sheet-context');
22
17
  let controls;
23
18
  $: if (controls) {
24
19
  if (translationSnap) {
@@ -139,13 +134,10 @@ const onMouseUp = () => {
139
134
  const groupRef = group;
140
135
  </script>
141
136
 
142
- <T
143
- is={groupRef}
144
- let:ref
145
- >
137
+ <T is={groupRef}>
146
138
  {#if isSelected}
147
139
  <TransformControls
148
- object={ref}
140
+ object={groupRef}
149
141
  {mode}
150
142
  {space}
151
143
  bind:controls
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threlte/theatre",
3
- "version": "2.1.7",
3
+ "version": "3.0.0-next.0",
4
4
  "author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
5
5
  "license": "MIT",
6
6
  "devDependencies": {
@@ -29,14 +29,14 @@
29
29
  "type-fest": "^4.10.1",
30
30
  "typescript": "^5.3.3",
31
31
  "vite": "^5.0.12",
32
- "@threlte/core": "7.2.1",
33
- "@threlte/extras": "8.10.1"
32
+ "@threlte/core": "8.0.0-next.0",
33
+ "@threlte/extras": "9.0.0-next.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "svelte": ">=4",
37
37
  "three": ">=0.152",
38
- "@threlte/core": ">=6.0.3",
39
- "@threlte/extras": ">=5.1.0",
38
+ "@threlte/core": ">=8.0.0-next.0",
39
+ "@threlte/extras": ">=9.0.0-next.0",
40
40
  "@theatre/core": ">=0.6",
41
41
  "@theatre/studio": ">=0.6"
42
42
  },