@2112-lab/central-plant 0.3.34 → 0.3.35

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.
@@ -35,7 +35,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
35
35
  * Initialize the CentralPlant manager
36
36
  *
37
37
  * @constructor
38
- * @version 0.3.34
38
+ * @version 0.3.35
39
39
  * @updated 2025-10-22
40
40
  *
41
41
  * @description Creates a new CentralPlant instance and initializes internal managers and utilities.
@@ -209,7 +209,8 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
209
209
  key: "setImportedSceneData",
210
210
  value: (function () {
211
211
  var _setImportedSceneData = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee2(sceneData) {
212
- var _this$importedSceneDa, _this$importedSceneDa2;
212
+ var _this$importedSceneDa, _this$importedSceneDa2, _this$importedSceneDa3, _this$sceneViewer;
213
+ var ioBehavMgr;
213
214
  return _rollupPluginBabelHelpers.regenerator().w(function (_context2) {
214
215
  while (1) switch (_context2.n) {
215
216
  case 0:
@@ -220,8 +221,19 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
220
221
  console.log('📥 Imported scene data stored in CentralPlant:', {
221
222
  connections: ((_this$importedSceneDa = this.importedSceneData.connections) === null || _this$importedSceneDa === void 0 ? void 0 : _this$importedSceneDa.length) || 0,
222
223
  sceneObjects: ((_this$importedSceneDa2 = this.importedSceneData.scene) === null || _this$importedSceneDa2 === void 0 || (_this$importedSceneDa2 = _this$importedSceneDa2.children) === null || _this$importedSceneDa2 === void 0 ? void 0 : _this$importedSceneDa2.length) || 0,
224
+ behaviors: ((_this$importedSceneDa3 = this.importedSceneData.behaviors) === null || _this$importedSceneDa3 === void 0 ? void 0 : _this$importedSceneDa3.length) || 0,
223
225
  timestamp: new Date().toISOString()
224
226
  });
227
+ console.log('[Behavior] Scene behaviors detail:', this.importedSceneData.behaviors);
228
+
229
+ // Register behaviors with IoBehaviorManager
230
+ ioBehavMgr = (_this$sceneViewer = this.sceneViewer) === null || _this$sceneViewer === void 0 || (_this$sceneViewer = _this$sceneViewer.managers) === null || _this$sceneViewer === void 0 ? void 0 : _this$sceneViewer.ioBehaviorManager;
231
+ if (ioBehavMgr) {
232
+ console.log('[Behavior] Calling setCrossComponentBehaviors with:', this.importedSceneData.behaviors || []);
233
+ ioBehavMgr.setCrossComponentBehaviors(this.importedSceneData.behaviors || []);
234
+ } else {
235
+ console.warn('[Behavior] ioBehaviorManager not available!');
236
+ }
225
237
 
226
238
  // Reset component counter based on imported components to avoid ID conflicts
227
239
  this.internals.resetComponentCounter();
@@ -402,8 +414,8 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
402
414
  }, {
403
415
  key: "selectObject",
404
416
  value: function selectObject(objectOrId) {
405
- var _this$sceneViewer, _object;
406
- if (!((_this$sceneViewer = this.sceneViewer) !== null && _this$sceneViewer !== void 0 && _this$sceneViewer.transformManager)) {
417
+ var _this$sceneViewer2, _object;
418
+ if (!((_this$sceneViewer2 = this.sceneViewer) !== null && _this$sceneViewer2 !== void 0 && _this$sceneViewer2.transformManager)) {
407
419
  console.warn('⚠️ Transform manager not initialized');
408
420
  return false;
409
421
  }
@@ -449,8 +461,8 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
449
461
  }, {
450
462
  key: "toggleObject",
451
463
  value: function toggleObject(objectOrId) {
452
- var _this$sceneViewer2, _object2;
453
- if (!((_this$sceneViewer2 = this.sceneViewer) !== null && _this$sceneViewer2 !== void 0 && _this$sceneViewer2.transformManager)) {
464
+ var _this$sceneViewer3, _object2;
465
+ if (!((_this$sceneViewer3 = this.sceneViewer) !== null && _this$sceneViewer3 !== void 0 && _this$sceneViewer3.transformManager)) {
454
466
  console.warn('⚠️ Transform manager not initialized');
455
467
  return false;
456
468
  }
@@ -486,8 +498,8 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
486
498
  }, {
487
499
  key: "deselectObject",
488
500
  value: function deselectObject() {
489
- var _this$sceneViewer3;
490
- if (!((_this$sceneViewer3 = this.sceneViewer) !== null && _this$sceneViewer3 !== void 0 && _this$sceneViewer3.transformManager)) {
501
+ var _this$sceneViewer4;
502
+ if (!((_this$sceneViewer4 = this.sceneViewer) !== null && _this$sceneViewer4 !== void 0 && _this$sceneViewer4.transformManager)) {
491
503
  console.warn('⚠️ Transform manager not initialized');
492
504
  return false;
493
505
  }
@@ -1101,9 +1113,9 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
1101
1113
  }, {
1102
1114
  key: "setIoDeviceState",
1103
1115
  value: function setIoDeviceState(attachmentId, stateId, value, parentUuid) {
1104
- var _this$sceneViewer4, _this$sceneViewer5, _this$sceneViewer6;
1116
+ var _this$sceneViewer5, _this$sceneViewer6, _this$sceneViewer7;
1105
1117
  // 1. Persist via state adapter if one has been configured
1106
- var stateAdapter = (_this$sceneViewer4 = this.sceneViewer) === null || _this$sceneViewer4 === void 0 || (_this$sceneViewer4 = _this$sceneViewer4.managers) === null || _this$sceneViewer4 === void 0 || (_this$sceneViewer4 = _this$sceneViewer4.componentTooltipManager) === null || _this$sceneViewer4 === void 0 ? void 0 : _this$sceneViewer4._stateAdapter;
1118
+ var stateAdapter = (_this$sceneViewer5 = this.sceneViewer) === null || _this$sceneViewer5 === void 0 || (_this$sceneViewer5 = _this$sceneViewer5.managers) === null || _this$sceneViewer5 === void 0 || (_this$sceneViewer5 = _this$sceneViewer5.componentTooltipManager) === null || _this$sceneViewer5 === void 0 ? void 0 : _this$sceneViewer5._stateAdapter;
1107
1119
  if (stateAdapter !== null && stateAdapter !== void 0 && stateAdapter.setState) {
1108
1120
  var scopedKey = parentUuid ? "".concat(parentUuid, "::").concat(attachmentId) : attachmentId;
1109
1121
  try {
@@ -1114,10 +1126,19 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
1114
1126
  }
1115
1127
 
1116
1128
  // 2. Apply io-behavior changes
1117
- (_this$sceneViewer5 = this.sceneViewer) === null || _this$sceneViewer5 === void 0 || (_this$sceneViewer5 = _this$sceneViewer5.managers) === null || _this$sceneViewer5 === void 0 || (_this$sceneViewer5 = _this$sceneViewer5.ioBehaviorManager) === null || _this$sceneViewer5 === void 0 || _this$sceneViewer5.triggerState(attachmentId, stateId, value, parentUuid);
1129
+ var ioBehavMgr = (_this$sceneViewer6 = this.sceneViewer) === null || _this$sceneViewer6 === void 0 || (_this$sceneViewer6 = _this$sceneViewer6.managers) === null || _this$sceneViewer6 === void 0 ? void 0 : _this$sceneViewer6.ioBehaviorManager;
1130
+ if (ioBehavMgr) {
1131
+ var _this$importedSceneDa4;
1132
+ ioBehavMgr.triggerState(attachmentId, stateId, value, parentUuid);
1133
+
1134
+ // Evaluate cross-component behaviors if they exist in the imported scene
1135
+ if ((_this$importedSceneDa4 = this.importedSceneData) !== null && _this$importedSceneDa4 !== void 0 && _this$importedSceneDa4.behaviors) {
1136
+ ioBehavMgr.triggerCrossComponentBehaviors(this.importedSceneData.behaviors, parentUuid, attachmentId, stateId, value);
1137
+ }
1138
+ }
1118
1139
 
1119
1140
  // 3. Emit event for host apps that don't use the state adapter (e.g. cp3d-viewer)
1120
- (_this$sceneViewer6 = this.sceneViewer) === null || _this$sceneViewer6 === void 0 || _this$sceneViewer6.emit('io-device-state-changed', {
1141
+ (_this$sceneViewer7 = this.sceneViewer) === null || _this$sceneViewer7 === void 0 || _this$sceneViewer7.emit('io-device-state-changed', {
1121
1142
  attachmentId: attachmentId,
1122
1143
  stateId: stateId,
1123
1144
  value: value,
@@ -1139,8 +1160,8 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
1139
1160
  }, {
1140
1161
  key: "getSceneAttachments",
1141
1162
  value: function getSceneAttachments() {
1142
- var _this$sceneViewer7;
1143
- var scene = (_this$sceneViewer7 = this.sceneViewer) === null || _this$sceneViewer7 === void 0 ? void 0 : _this$sceneViewer7.scene;
1163
+ var _this$sceneViewer8;
1164
+ var scene = (_this$sceneViewer8 = this.sceneViewer) === null || _this$sceneViewer8 === void 0 ? void 0 : _this$sceneViewer8.scene;
1144
1165
  if (!scene) return [];
1145
1166
  var results = [];
1146
1167
  scene.traverse(function (obj) {
@@ -2767,7 +2788,12 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
2767
2788
  }, {
2768
2789
  key: "clearScene",
2769
2790
  value: function clearScene() {
2791
+ var _this$sceneViewer9;
2770
2792
  this.importedSceneData = null;
2793
+ var ioBehavMgr = (_this$sceneViewer9 = this.sceneViewer) === null || _this$sceneViewer9 === void 0 || (_this$sceneViewer9 = _this$sceneViewer9.managers) === null || _this$sceneViewer9 === void 0 ? void 0 : _this$sceneViewer9.ioBehaviorManager;
2794
+ if (ioBehavMgr) {
2795
+ ioBehavMgr.setCrossComponentBehaviors([]);
2796
+ }
2771
2797
  if (this.sceneViewer && this.sceneViewer.scene) {
2772
2798
  this.sceneViewer.scene.clear();
2773
2799
  }
@@ -1174,6 +1174,12 @@ var CentralPlantInternals = /*#__PURE__*/function () {
1174
1174
  for (var _i = 0, _Object$entries = Object.entries(componentData.attachedDevices); _i < _Object$entries.length; _i++) {
1175
1175
  if (_loop()) continue;
1176
1176
  }
1177
+
1178
+ // Register component-level behaviors (intra-component io-device linking)
1179
+ if (componentData.behaviors && componentData.behaviors.length > 0) {
1180
+ console.log("[DragDrop] Registering ".concat(componentData.behaviors.length, " component-level behavior(s) for ").concat(componentId));
1181
+ ioBehavMgr.registerComponentBehaviors(componentId, componentData.behaviors);
1182
+ }
1177
1183
  }
1178
1184
  }
1179
1185
 
@@ -434,28 +434,10 @@ var sceneViewer = /*#__PURE__*/function (_BaseDisposable) {
434
434
  },
435
435
  onIODeviceDrag: function onIODeviceDrag(ioDeviceObject, signedDelta, isStart, hitMesh) {
436
436
  if (isStart) {
437
- var _ioDeviceObject$userD, _this4$managers$ioBeh, _this4$managers, _this4$managers2;
438
- // Resolve parentUuid by walking up to the host component.
439
- // Use userData.originalUuid (the custom componentId) because that
440
- // is what IoBehaviorManager uses as the map key NOT obj.uuid.
441
- var parentUuid = null;
442
- var obj = ioDeviceObject.parent;
443
- while (obj) {
444
- var _obj$userData;
445
- if (((_obj$userData = obj.userData) === null || _obj$userData === void 0 ? void 0 : _obj$userData.objectType) === 'component') {
446
- parentUuid = obj.userData.originalUuid || obj.uuid;
447
- break;
448
- }
449
- obj = obj.parent;
450
- }
451
- var attachmentId = (_ioDeviceObject$userD = ioDeviceObject.userData) === null || _ioDeviceObject$userD === void 0 ? void 0 : _ioDeviceObject$userD.attachmentId;
452
- // When animated meshes are available, outline ONLY them so their
453
- // silhouette is isolated and the outline ring is visible around
454
- // them specifically (not swallowed by the larger device body).
455
- // Fall back to the whole device group when none are registered.
456
- var animatedMeshes = attachmentId && parentUuid ? (_this4$managers$ioBeh = (_this4$managers = _this4.managers) === null || _this4$managers === void 0 || (_this4$managers = _this4$managers.ioBehaviorManager) === null || _this4$managers === void 0 ? void 0 : _this4$managers.getAnimatedMeshes(parentUuid, attachmentId)) !== null && _this4$managers$ioBeh !== void 0 ? _this4$managers$ioBeh : [] : [];
457
- var targets = animatedMeshes.length > 0 ? animatedMeshes : [ioDeviceObject];
458
- (_this4$managers2 = _this4.managers) === null || _this4$managers2 === void 0 || (_this4$managers2 = _this4$managers2.ioOutlineManager) === null || _this4$managers2 === void 0 || _this4$managers2.setTargets(targets);
437
+ var _this4$managers;
438
+ // Outline only the specific mesh that was clicked
439
+ var targets = hitMesh ? [hitMesh] : [ioDeviceObject];
440
+ (_this4$managers = _this4.managers) === null || _this4$managers === void 0 || (_this4$managers = _this4$managers.ioOutlineManager) === null || _this4$managers === void 0 || _this4$managers.setTargets(targets);
459
441
  }
460
442
  if (!_this4.componentTooltipManager) return;
461
443
  if (isStart) {
@@ -465,8 +447,8 @@ var sceneViewer = /*#__PURE__*/function (_BaseDisposable) {
465
447
  }
466
448
  },
467
449
  onIODeviceDragEnd: function onIODeviceDragEnd(ioDeviceObject) {
468
- var _this4$managers3;
469
- (_this4$managers3 = _this4.managers) === null || _this4$managers3 === void 0 || (_this4$managers3 = _this4$managers3.ioOutlineManager) === null || _this4$managers3 === void 0 || _this4$managers3.setTargets([]);
450
+ var _this4$managers2;
451
+ (_this4$managers2 = _this4.managers) === null || _this4$managers2 === void 0 || (_this4$managers2 = _this4$managers2.ioOutlineManager) === null || _this4$managers2 === void 0 || _this4$managers2.setTargets([]);
470
452
  if (_this4.componentTooltipManager) {
471
453
  _this4.componentTooltipManager.endIODeviceDrag();
472
454
  }