@threlte/theatre 2.0.0 → 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> & 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
  > {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threlte/theatre",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)",
5
5
  "license": "MIT",
6
6
  "devDependencies": {