@unseenco/theatre-core 0.2.1 → 0.2.3

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/index.d.ts CHANGED
@@ -1231,6 +1231,7 @@ type ISheetObjectOptions = {
1231
1231
  static?: readonly StaticPropPath[];
1232
1232
  __actions__THIS_API_IS_UNSTABLE_AND_WILL_CHANGE_IN_THE_NEXT_VERSION?: SheetObjectActionsConfig;
1233
1233
  };
1234
+ type ISheetPropsOptions = Omit<ISheetObjectOptions, 'visible' | 'showPropsOf'>;
1234
1235
  interface ISheet {
1235
1236
  /**
1236
1237
  * All sheets have `sheet.type === 'Theatre_Sheet_PublicAPI'`
@@ -1308,6 +1309,14 @@ interface ISheet {
1308
1309
  * ```
1309
1310
  */
1310
1311
  object<Props extends UnknownShorthandCompoundProps>(key: string, props: Props, options?: ISheetObjectOptions): ISheetObject<Props>;
1312
+ /**
1313
+ * Declares props scoped to the sheet (not a scene object). The returned handle
1314
+ * behaves like a sheet object for `props`, `value`, `onValuesChange`, and
1315
+ * Studio editing, but is hidden from {@link ISheet.getObjects} and the outline.
1316
+ *
1317
+ * Sheet props are shared across all sequence variants (static and sequenced).
1318
+ */
1319
+ props<Props extends UnknownShorthandCompoundProps>(config: Props, options?: ISheetPropsOptions): ISheetObject<Props>;
1311
1320
  /**
1312
1321
  * Detaches a previously created child object from the sheet.
1313
1322
  *
package/dist/index.js CHANGED
@@ -4193,6 +4193,14 @@ function setDeepImmutable(obj, path, replace) {
4193
4193
 
4194
4194
  // core/src/sequences/sequenceVariants.ts
4195
4195
  var import_theatre_dataverse5 = require("@unseenco/theatre-dataverse");
4196
+
4197
+ // shared/src/utils/sheetProps.ts
4198
+ var SHEET_PROPS_OBJECT_KEY = "__theatre_sheet_props__";
4199
+ function isSheetPropsObjectKey(objectKey) {
4200
+ return objectKey === SHEET_PROPS_OBJECT_KEY;
4201
+ }
4202
+
4203
+ // core/src/sequences/sequenceVariants.ts
4196
4204
  var DEFAULT_SEQUENCE_VARIANT = "default";
4197
4205
  function mergeSequenceTrackMaps(defaultTracks, overrideTracks, activeVariant) {
4198
4206
  const merged = {};
@@ -4222,6 +4230,9 @@ function getDefaultStaticOverridesByObject(sheetState) {
4222
4230
  return sheetState?.staticOverrides?.byObject;
4223
4231
  }
4224
4232
  function getEffectiveStaticOverrideForObject(sheetState, variantId, objectKey) {
4233
+ if (isSheetPropsObjectKey(objectKey)) {
4234
+ return getDefaultStaticOverridesByObject(sheetState)?.[objectKey];
4235
+ }
4225
4236
  const defaultOverrides = getDefaultStaticOverridesByObject(sheetState)?.[objectKey];
4226
4237
  if (variantId === DEFAULT_SEQUENCE_VARIANT) {
4227
4238
  return defaultOverrides;
@@ -4409,7 +4420,8 @@ var SheetObject = class {
4409
4420
  withAhistoricStaticsCache
4410
4421
  );
4411
4422
  const activeVariant = (0, import_theatre_dataverse6.val)(this.sheet.effectiveActiveSequenceVariantD);
4412
- const statics = (0, import_theatre_dataverse6.val)(this.template.getStaticValues(activeVariant));
4423
+ const staticVariant = isSheetPropsObjectKey(this.address.objectKey) ? DEFAULT_SEQUENCE_VARIANT : activeVariant;
4424
+ const statics = (0, import_theatre_dataverse6.val)(this.template.getStaticValues(staticVariant));
4413
4425
  const withStaticsCache = import_theatre_dataverse6.prism.memo(
4414
4426
  "withStatics",
4415
4427
  () => /* @__PURE__ */ new WeakMap(),
@@ -4484,10 +4496,11 @@ var SheetObject = class {
4484
4496
  getSequencedValues() {
4485
4497
  return (0, import_theatre_dataverse6.prism)(() => {
4486
4498
  const activeVariant = (0, import_theatre_dataverse6.val)(this.sheet.effectiveActiveSequenceVariantD);
4499
+ const sequenceVariant = isSheetPropsObjectKey(this.address.objectKey) ? DEFAULT_SEQUENCE_VARIANT : activeVariant;
4487
4500
  const tracksToProcessD = import_theatre_dataverse6.prism.memo(
4488
4501
  "tracksToProcess",
4489
- () => this.template.getArrayOfValidSequenceTracks(activeVariant),
4490
- [activeVariant]
4502
+ () => this.template.getArrayOfValidSequenceTracks(sequenceVariant),
4503
+ [sequenceVariant]
4491
4504
  );
4492
4505
  const tracksToProcess = (0, import_theatre_dataverse6.val)(tracksToProcessD);
4493
4506
  const valsAtom = new import_theatre_dataverse6.Atom({});
@@ -5424,6 +5437,9 @@ var SheetObjectTemplate = class {
5424
5437
  "getArrayOfValidSequenceTracks:".concat(sequenceVariant),
5425
5438
  () => (0, import_theatre_dataverse7.prism)(
5426
5439
  () => {
5440
+ const effectiveSequenceVariant = isSheetPropsObjectKey(
5441
+ this.address.objectKey
5442
+ ) ? DEFAULT_SEQUENCE_VARIANT : sequenceVariant;
5427
5443
  const pointerToSheetState = this.project.pointers.historic.sheetsById[this.address.sheetId];
5428
5444
  (0, import_theatre_dataverse7.val)(pointerToSheetState.variantObjectOverrides);
5429
5445
  const defaultTrackIdByPropPath = valTrackIdByPropPathForObject(
@@ -5431,19 +5447,19 @@ var SheetObjectTemplate = class {
5431
5447
  DEFAULT_SEQUENCE_VARIANT,
5432
5448
  this.address.objectKey
5433
5449
  );
5434
- const variantTrackIdByPropPath = sequenceVariant === DEFAULT_SEQUENCE_VARIANT ? void 0 : valTrackIdByPropPathForObject(
5450
+ const variantTrackIdByPropPath = effectiveSequenceVariant === DEFAULT_SEQUENCE_VARIANT ? void 0 : valTrackIdByPropPathForObject(
5435
5451
  pointerToSheetState,
5436
- sequenceVariant,
5452
+ effectiveSequenceVariant,
5437
5453
  this.address.objectKey
5438
5454
  );
5439
5455
  const mergedTrackMap = mergeSequenceTrackMaps(
5440
5456
  defaultTrackIdByPropPath,
5441
5457
  variantTrackIdByPropPath,
5442
- sequenceVariant
5458
+ effectiveSequenceVariant
5443
5459
  );
5444
- const unsequencedPropPaths = sequenceVariant === DEFAULT_SEQUENCE_VARIANT ? void 0 : valUnsequencedPropPathsForObject(
5460
+ const unsequencedPropPaths = effectiveSequenceVariant === DEFAULT_SEQUENCE_VARIANT ? void 0 : valUnsequencedPropPathsForObject(
5445
5461
  pointerToSheetState,
5446
- sequenceVariant,
5462
+ effectiveSequenceVariant,
5447
5463
  this.address.objectKey
5448
5464
  );
5449
5465
  const unsequencedPropPathSet = unsequencedPropPaths ? new Set(unsequencedPropPaths) : void 0;
@@ -6703,6 +6719,11 @@ var TheatreSheet = class {
6703
6719
  key,
6704
6720
  "sheet.object"
6705
6721
  );
6722
+ if (isSheetPropsObjectKey(sanitizedPath)) {
6723
+ throw new InvalidArgumentError(
6724
+ 'The key "'.concat(sanitizedPath, '" is reserved for sheet-level props. Use sheet.props() instead of sheet.object().')
6725
+ );
6726
+ }
6706
6727
  const existingObject = internal2.getObject(sanitizedPath);
6707
6728
  const nativeObject = null;
6708
6729
  const actions = opts?.__actions__THIS_API_IS_UNSTABLE_AND_WILL_CHANGE_IN_THE_NEXT_VERSION;
@@ -6799,6 +6820,74 @@ var TheatreSheet = class {
6799
6820
  return object.publicApi;
6800
6821
  }
6801
6822
  }
6823
+ props(config, opts) {
6824
+ const internal2 = privateAPI(this);
6825
+ const objectKey = SHEET_PROPS_OBJECT_KEY;
6826
+ const existingObject = internal2.getSheetPropsObject();
6827
+ const nativeObject = null;
6828
+ const actions = opts?.__actions__THIS_API_IS_UNSTABLE_AND_WILL_CHANGE_IN_THE_NEXT_VERSION;
6829
+ if (existingObject) {
6830
+ if (process.env.NODE_ENV !== "production") {
6831
+ const prevConfig = getUnsanitizedObjectProps(existingObject);
6832
+ if (prevConfig) {
6833
+ if (!(0, import_fast_deep_equal2.default)(config, prevConfig)) {
6834
+ if (opts?.reconfigure === true) {
6835
+ const sanitizedConfig2 = compound(config);
6836
+ existingObject.template.reconfigure(sanitizedConfig2);
6837
+ if (opts.transient !== void 0) {
6838
+ existingObject.template.setTransientPropPaths(
6839
+ opts.transient,
6840
+ sanitizedConfig2
6841
+ );
6842
+ }
6843
+ if (opts.static !== void 0) {
6844
+ existingObject.template.setStaticPropPaths(
6845
+ opts.static,
6846
+ sanitizedConfig2
6847
+ );
6848
+ }
6849
+ setUnsanitizedObjectProps(existingObject, config);
6850
+ return existingObject.publicApi;
6851
+ } else {
6852
+ throw new Error(
6853
+ "You seem to have called sheet.props(config) twice, with different values for `config`. Use the same config on repeat calls, or pass `{reconfigure: true}` to change the schema."
6854
+ );
6855
+ }
6856
+ }
6857
+ }
6858
+ }
6859
+ if (actions) {
6860
+ existingObject.template._temp_setActions(actions);
6861
+ }
6862
+ if (opts?.transient !== void 0) {
6863
+ existingObject.template.setTransientPropPaths(
6864
+ opts.transient,
6865
+ existingObject.template.staticConfig
6866
+ );
6867
+ }
6868
+ if (opts?.static !== void 0) {
6869
+ existingObject.template.setStaticPropPaths(
6870
+ opts.static,
6871
+ existingObject.template.staticConfig
6872
+ );
6873
+ }
6874
+ return existingObject.publicApi;
6875
+ }
6876
+ const sanitizedConfig = compound(config);
6877
+ const object = internal2.createObject(
6878
+ objectKey,
6879
+ nativeObject,
6880
+ sanitizedConfig,
6881
+ actions,
6882
+ false,
6883
+ opts?.transient,
6884
+ opts?.static
6885
+ );
6886
+ if (process.env.NODE_ENV !== "production") {
6887
+ setUnsanitizedObjectProps(object, config);
6888
+ }
6889
+ return object.publicApi;
6890
+ }
6802
6891
  get sequence() {
6803
6892
  return privateAPI(this).getSequence().publicApi;
6804
6893
  }
@@ -6823,6 +6912,11 @@ var TheatreSheet = class {
6823
6912
  key,
6824
6913
  'sheet.deleteObject("'.concat(key, '")')
6825
6914
  );
6915
+ if (isSheetPropsObjectKey(sanitizedPath)) {
6916
+ throw new InvalidArgumentError(
6917
+ "Sheet props cannot be detached. They are removed when the sheet instance is unloaded."
6918
+ );
6919
+ }
6826
6920
  const obj = internal2.getObject(sanitizedPath);
6827
6921
  if (!obj) {
6828
6922
  notify.warning(
@@ -6929,9 +7023,12 @@ var Sheet = class {
6929
7023
  }
6930
7024
  getObjects() {
6931
7025
  return Object.values(this._objects.get()).filter(
6932
- (obj) => !!obj
7026
+ (obj) => !!obj && !isSheetPropsObjectKey(obj.address.objectKey)
6933
7027
  );
6934
7028
  }
7029
+ getSheetPropsObject() {
7030
+ return this.getObject(SHEET_PROPS_OBJECT_KEY);
7031
+ }
6935
7032
  deleteObject(objectKey) {
6936
7033
  const obj = this._objects.get()[objectKey];
6937
7034
  this._objects.reduce((state) => {
@@ -8552,7 +8649,7 @@ var CoreBundle = class {
8552
8649
  return "Theatre_CoreBundle";
8553
8650
  }
8554
8651
  get version() {
8555
- return "0.2.1";
8652
+ return "0.2.3";
8556
8653
  }
8557
8654
  getBitsForStudio(studio, callback) {
8558
8655
  if (this._studio) {