@2112-lab/central-plant 0.1.75 → 0.1.76

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.
@@ -18496,6 +18496,14 @@ var ComponentManager = /*#__PURE__*/function () {
18496
18496
  try {
18497
18497
  // Use the new utility function to find objects by hardcoded UUID
18498
18498
  var object = findObjectByHardcodedUuid(this.sceneViewer.scene, componentUuid);
18499
+
18500
+ // Fallback: If not found by utility, try direct UUID or name lookup
18501
+ if (!object) {
18502
+ object = this.sceneViewer.scene.getObjectByProperty('uuid', componentUuid);
18503
+ }
18504
+ if (!object) {
18505
+ object = this.sceneViewer.scene.getObjectByProperty('name', componentUuid);
18506
+ }
18499
18507
  if (!object) {
18500
18508
  console.warn('⚠️ Component not found:', componentUuid);
18501
18509
  return false;
@@ -34752,6 +34760,79 @@ var CentralPlantInternals = /*#__PURE__*/function () {
34752
34760
  }
34753
34761
  }
34754
34762
 
34763
+ /**
34764
+ * Delete a component from the scene by componentId (internal implementation)
34765
+ * @param {string} componentId - The UUID of the component to delete
34766
+ * @returns {boolean} True if deletion was successful, false otherwise
34767
+ */
34768
+ }, {
34769
+ key: "deleteComponent",
34770
+ value: function deleteComponent(componentId) {
34771
+ var _this$centralPlant$sc7;
34772
+ // Check if component manager is available
34773
+ var componentManager = (_this$centralPlant$sc7 = this.centralPlant.sceneViewer) === null || _this$centralPlant$sc7 === void 0 ? void 0 : _this$centralPlant$sc7.componentManager;
34774
+ if (!componentManager) {
34775
+ console.error('❌ deleteComponent(): Component manager not available');
34776
+ return false;
34777
+ }
34778
+ try {
34779
+ console.log("\uD83D\uDDD1\uFE0F deleteComponent(): Deleting component ".concat(componentId));
34780
+
34781
+ // Use componentManager to remove the component
34782
+ var success = componentManager.removeComponentFromScene(componentId);
34783
+ if (success) {
34784
+ // Also remove from scene data if available
34785
+ if (this.centralPlant.sceneViewer.sceneOperationsManager && this.centralPlant.sceneViewer.currentSceneData) {
34786
+ // Note: componentManager.removeComponentFromScene might not update sceneData
34787
+ // We should verify if sceneOperationsManager has a method for this or if we need to manually update
34788
+ // For now, assuming componentManager handles the scene object removal,
34789
+ // we might need to update the data structure manually if componentManager doesn't.
34790
+
34791
+ // Let's implement a safe removal from sceneData here just in case
34792
+ var sceneData = this.centralPlant.sceneViewer.currentSceneData;
34793
+ if (sceneData.scene && sceneData.scene.children) {
34794
+ var index = sceneData.scene.children.findIndex(function (c) {
34795
+ var _c$userData2;
34796
+ return c.uuid === componentId || ((_c$userData2 = c.userData) === null || _c$userData2 === void 0 ? void 0 : _c$userData2.originalUuid) === componentId;
34797
+ });
34798
+ if (index !== -1) {
34799
+ sceneData.scene.children.splice(index, 1);
34800
+ console.log('✅ Removed component from sceneData');
34801
+ }
34802
+ }
34803
+ }
34804
+
34805
+ // Deselect if the deleted component was selected
34806
+ // We check if the selected object matches the deleted ID, OR if the selected object is now detached from the scene (parent is null)
34807
+ var transformManager = this.centralPlant.sceneViewer.transformManager;
34808
+ if (transformManager && transformManager.selectedObjectForTransform) {
34809
+ var _selectedObj$userData;
34810
+ var selectedObj = transformManager.selectedObjectForTransform;
34811
+ if (selectedObj.uuid === componentId || selectedObj.name === componentId || ((_selectedObj$userData = selectedObj.userData) === null || _selectedObj$userData === void 0 ? void 0 : _selectedObj$userData.originalUuid) === componentId || selectedObj.parent === null) {
34812
+ console.log('🎯 deleteComponent(): Deselecting deleted object');
34813
+ transformManager.deselectObject();
34814
+ }
34815
+ }
34816
+
34817
+ // Emit component-removed event for UI updates
34818
+ if (this.centralPlant.sceneViewer.emit) {
34819
+ this.centralPlant.sceneViewer.emit('component-removed', {
34820
+ id: componentId
34821
+ });
34822
+ console.log("\uD83D\uDCE1 Emitted 'component-removed' event for ".concat(componentId));
34823
+ }
34824
+ console.log("\u2705 deleteComponent(): Component ".concat(componentId, " deleted successfully"));
34825
+ return true;
34826
+ } else {
34827
+ console.warn("\u26A0\uFE0F deleteComponent(): Failed to delete component ".concat(componentId));
34828
+ return false;
34829
+ }
34830
+ } catch (error) {
34831
+ console.error("\u274C deleteComponent(): Error deleting component ".concat(componentId, ":"), error);
34832
+ return false;
34833
+ }
34834
+ }
34835
+
34755
34836
  /**
34756
34837
  * Get all component IDs from the scene
34757
34838
  * @returns {Array<string>} Array of component UUIDs
@@ -34784,7 +34865,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
34784
34865
  * Initialize the CentralPlant manager
34785
34866
  *
34786
34867
  * @constructor
34787
- * @version 0.1.75
34868
+ * @version 0.1.76
34788
34869
  * @updated 2025-10-22
34789
34870
  *
34790
34871
  * @description Creates a new CentralPlant instance and initializes internal managers and utilities.
@@ -35037,6 +35118,23 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
35037
35118
  return this.internals.addComponent(libraryId, options);
35038
35119
  }
35039
35120
 
35121
+ /**
35122
+ * Delete a component from the scene by componentId
35123
+ * @param {string} componentId - The UUID of the component to delete
35124
+ * @returns {boolean} True if deletion was successful, false otherwise
35125
+ * @description Removes a 3D component from the scene and cleans up associated resources.
35126
+ * @example
35127
+ * const success = centralPlant.deleteComponent('component-uuid-123');
35128
+ * if (success) {
35129
+ * console.log('Component deleted successfully');
35130
+ * }
35131
+ */
35132
+ }, {
35133
+ key: "deleteComponent",
35134
+ value: function deleteComponent(componentId) {
35135
+ return this.internals.deleteComponent(componentId);
35136
+ }
35137
+
35040
35138
  /**
35041
35139
  * Translate a component by componentId
35042
35140
  * @param {string} componentId - The UUID of the component to translate
@@ -19,7 +19,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
19
19
  * Initialize the CentralPlant manager
20
20
  *
21
21
  * @constructor
22
- * @version 0.1.75
22
+ * @version 0.1.76
23
23
  * @updated 2025-10-22
24
24
  *
25
25
  * @description Creates a new CentralPlant instance and initializes internal managers and utilities.
@@ -272,6 +272,23 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
272
272
  return this.internals.addComponent(libraryId, options);
273
273
  }
274
274
 
275
+ /**
276
+ * Delete a component from the scene by componentId
277
+ * @param {string} componentId - The UUID of the component to delete
278
+ * @returns {boolean} True if deletion was successful, false otherwise
279
+ * @description Removes a 3D component from the scene and cleans up associated resources.
280
+ * @example
281
+ * const success = centralPlant.deleteComponent('component-uuid-123');
282
+ * if (success) {
283
+ * console.log('Component deleted successfully');
284
+ * }
285
+ */
286
+ }, {
287
+ key: "deleteComponent",
288
+ value: function deleteComponent(componentId) {
289
+ return this.internals.deleteComponent(componentId);
290
+ }
291
+
275
292
  /**
276
293
  * Translate a component by componentId
277
294
  * @param {string} componentId - The UUID of the component to translate
@@ -1105,6 +1105,79 @@ var CentralPlantInternals = /*#__PURE__*/function () {
1105
1105
  }
1106
1106
  }
1107
1107
 
1108
+ /**
1109
+ * Delete a component from the scene by componentId (internal implementation)
1110
+ * @param {string} componentId - The UUID of the component to delete
1111
+ * @returns {boolean} True if deletion was successful, false otherwise
1112
+ */
1113
+ }, {
1114
+ key: "deleteComponent",
1115
+ value: function deleteComponent(componentId) {
1116
+ var _this$centralPlant$sc7;
1117
+ // Check if component manager is available
1118
+ var componentManager = (_this$centralPlant$sc7 = this.centralPlant.sceneViewer) === null || _this$centralPlant$sc7 === void 0 ? void 0 : _this$centralPlant$sc7.componentManager;
1119
+ if (!componentManager) {
1120
+ console.error('❌ deleteComponent(): Component manager not available');
1121
+ return false;
1122
+ }
1123
+ try {
1124
+ console.log("\uD83D\uDDD1\uFE0F deleteComponent(): Deleting component ".concat(componentId));
1125
+
1126
+ // Use componentManager to remove the component
1127
+ var success = componentManager.removeComponentFromScene(componentId);
1128
+ if (success) {
1129
+ // Also remove from scene data if available
1130
+ if (this.centralPlant.sceneViewer.sceneOperationsManager && this.centralPlant.sceneViewer.currentSceneData) {
1131
+ // Note: componentManager.removeComponentFromScene might not update sceneData
1132
+ // We should verify if sceneOperationsManager has a method for this or if we need to manually update
1133
+ // For now, assuming componentManager handles the scene object removal,
1134
+ // we might need to update the data structure manually if componentManager doesn't.
1135
+
1136
+ // Let's implement a safe removal from sceneData here just in case
1137
+ var sceneData = this.centralPlant.sceneViewer.currentSceneData;
1138
+ if (sceneData.scene && sceneData.scene.children) {
1139
+ var index = sceneData.scene.children.findIndex(function (c) {
1140
+ var _c$userData2;
1141
+ return c.uuid === componentId || ((_c$userData2 = c.userData) === null || _c$userData2 === void 0 ? void 0 : _c$userData2.originalUuid) === componentId;
1142
+ });
1143
+ if (index !== -1) {
1144
+ sceneData.scene.children.splice(index, 1);
1145
+ console.log('✅ Removed component from sceneData');
1146
+ }
1147
+ }
1148
+ }
1149
+
1150
+ // Deselect if the deleted component was selected
1151
+ // We check if the selected object matches the deleted ID, OR if the selected object is now detached from the scene (parent is null)
1152
+ var transformManager = this.centralPlant.sceneViewer.transformManager;
1153
+ if (transformManager && transformManager.selectedObjectForTransform) {
1154
+ var _selectedObj$userData;
1155
+ var selectedObj = transformManager.selectedObjectForTransform;
1156
+ if (selectedObj.uuid === componentId || selectedObj.name === componentId || ((_selectedObj$userData = selectedObj.userData) === null || _selectedObj$userData === void 0 ? void 0 : _selectedObj$userData.originalUuid) === componentId || selectedObj.parent === null) {
1157
+ console.log('🎯 deleteComponent(): Deselecting deleted object');
1158
+ transformManager.deselectObject();
1159
+ }
1160
+ }
1161
+
1162
+ // Emit component-removed event for UI updates
1163
+ if (this.centralPlant.sceneViewer.emit) {
1164
+ this.centralPlant.sceneViewer.emit('component-removed', {
1165
+ id: componentId
1166
+ });
1167
+ console.log("\uD83D\uDCE1 Emitted 'component-removed' event for ".concat(componentId));
1168
+ }
1169
+ console.log("\u2705 deleteComponent(): Component ".concat(componentId, " deleted successfully"));
1170
+ return true;
1171
+ } else {
1172
+ console.warn("\u26A0\uFE0F deleteComponent(): Failed to delete component ".concat(componentId));
1173
+ return false;
1174
+ }
1175
+ } catch (error) {
1176
+ console.error("\u274C deleteComponent(): Error deleting component ".concat(componentId, ":"), error);
1177
+ return false;
1178
+ }
1179
+ }
1180
+
1108
1181
  /**
1109
1182
  * Get all component IDs from the scene
1110
1183
  * @returns {Array<string>} Array of component UUIDs
@@ -194,6 +194,14 @@ var ComponentManager = /*#__PURE__*/function () {
194
194
  try {
195
195
  // Use the new utility function to find objects by hardcoded UUID
196
196
  var object = nameUtils.findObjectByHardcodedUuid(this.sceneViewer.scene, componentUuid);
197
+
198
+ // Fallback: If not found by utility, try direct UUID or name lookup
199
+ if (!object) {
200
+ object = this.sceneViewer.scene.getObjectByProperty('uuid', componentUuid);
201
+ }
202
+ if (!object) {
203
+ object = this.sceneViewer.scene.getObjectByProperty('name', componentUuid);
204
+ }
197
205
  if (!object) {
198
206
  console.warn('⚠️ Component not found:', componentUuid);
199
207
  return false;
@@ -15,7 +15,7 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
15
15
  * Initialize the CentralPlant manager
16
16
  *
17
17
  * @constructor
18
- * @version 0.1.75
18
+ * @version 0.1.76
19
19
  * @updated 2025-10-22
20
20
  *
21
21
  * @description Creates a new CentralPlant instance and initializes internal managers and utilities.
@@ -268,6 +268,23 @@ var CentralPlant = /*#__PURE__*/function (_BaseDisposable) {
268
268
  return this.internals.addComponent(libraryId, options);
269
269
  }
270
270
 
271
+ /**
272
+ * Delete a component from the scene by componentId
273
+ * @param {string} componentId - The UUID of the component to delete
274
+ * @returns {boolean} True if deletion was successful, false otherwise
275
+ * @description Removes a 3D component from the scene and cleans up associated resources.
276
+ * @example
277
+ * const success = centralPlant.deleteComponent('component-uuid-123');
278
+ * if (success) {
279
+ * console.log('Component deleted successfully');
280
+ * }
281
+ */
282
+ }, {
283
+ key: "deleteComponent",
284
+ value: function deleteComponent(componentId) {
285
+ return this.internals.deleteComponent(componentId);
286
+ }
287
+
271
288
  /**
272
289
  * Translate a component by componentId
273
290
  * @param {string} componentId - The UUID of the component to translate
@@ -1081,6 +1081,79 @@ var CentralPlantInternals = /*#__PURE__*/function () {
1081
1081
  }
1082
1082
  }
1083
1083
 
1084
+ /**
1085
+ * Delete a component from the scene by componentId (internal implementation)
1086
+ * @param {string} componentId - The UUID of the component to delete
1087
+ * @returns {boolean} True if deletion was successful, false otherwise
1088
+ */
1089
+ }, {
1090
+ key: "deleteComponent",
1091
+ value: function deleteComponent(componentId) {
1092
+ var _this$centralPlant$sc7;
1093
+ // Check if component manager is available
1094
+ var componentManager = (_this$centralPlant$sc7 = this.centralPlant.sceneViewer) === null || _this$centralPlant$sc7 === void 0 ? void 0 : _this$centralPlant$sc7.componentManager;
1095
+ if (!componentManager) {
1096
+ console.error('❌ deleteComponent(): Component manager not available');
1097
+ return false;
1098
+ }
1099
+ try {
1100
+ console.log("\uD83D\uDDD1\uFE0F deleteComponent(): Deleting component ".concat(componentId));
1101
+
1102
+ // Use componentManager to remove the component
1103
+ var success = componentManager.removeComponentFromScene(componentId);
1104
+ if (success) {
1105
+ // Also remove from scene data if available
1106
+ if (this.centralPlant.sceneViewer.sceneOperationsManager && this.centralPlant.sceneViewer.currentSceneData) {
1107
+ // Note: componentManager.removeComponentFromScene might not update sceneData
1108
+ // We should verify if sceneOperationsManager has a method for this or if we need to manually update
1109
+ // For now, assuming componentManager handles the scene object removal,
1110
+ // we might need to update the data structure manually if componentManager doesn't.
1111
+
1112
+ // Let's implement a safe removal from sceneData here just in case
1113
+ var sceneData = this.centralPlant.sceneViewer.currentSceneData;
1114
+ if (sceneData.scene && sceneData.scene.children) {
1115
+ var index = sceneData.scene.children.findIndex(function (c) {
1116
+ var _c$userData2;
1117
+ return c.uuid === componentId || ((_c$userData2 = c.userData) === null || _c$userData2 === void 0 ? void 0 : _c$userData2.originalUuid) === componentId;
1118
+ });
1119
+ if (index !== -1) {
1120
+ sceneData.scene.children.splice(index, 1);
1121
+ console.log('✅ Removed component from sceneData');
1122
+ }
1123
+ }
1124
+ }
1125
+
1126
+ // Deselect if the deleted component was selected
1127
+ // We check if the selected object matches the deleted ID, OR if the selected object is now detached from the scene (parent is null)
1128
+ var transformManager = this.centralPlant.sceneViewer.transformManager;
1129
+ if (transformManager && transformManager.selectedObjectForTransform) {
1130
+ var _selectedObj$userData;
1131
+ var selectedObj = transformManager.selectedObjectForTransform;
1132
+ if (selectedObj.uuid === componentId || selectedObj.name === componentId || ((_selectedObj$userData = selectedObj.userData) === null || _selectedObj$userData === void 0 ? void 0 : _selectedObj$userData.originalUuid) === componentId || selectedObj.parent === null) {
1133
+ console.log('🎯 deleteComponent(): Deselecting deleted object');
1134
+ transformManager.deselectObject();
1135
+ }
1136
+ }
1137
+
1138
+ // Emit component-removed event for UI updates
1139
+ if (this.centralPlant.sceneViewer.emit) {
1140
+ this.centralPlant.sceneViewer.emit('component-removed', {
1141
+ id: componentId
1142
+ });
1143
+ console.log("\uD83D\uDCE1 Emitted 'component-removed' event for ".concat(componentId));
1144
+ }
1145
+ console.log("\u2705 deleteComponent(): Component ".concat(componentId, " deleted successfully"));
1146
+ return true;
1147
+ } else {
1148
+ console.warn("\u26A0\uFE0F deleteComponent(): Failed to delete component ".concat(componentId));
1149
+ return false;
1150
+ }
1151
+ } catch (error) {
1152
+ console.error("\u274C deleteComponent(): Error deleting component ".concat(componentId, ":"), error);
1153
+ return false;
1154
+ }
1155
+ }
1156
+
1084
1157
  /**
1085
1158
  * Get all component IDs from the scene
1086
1159
  * @returns {Array<string>} Array of component UUIDs
@@ -190,6 +190,14 @@ var ComponentManager = /*#__PURE__*/function () {
190
190
  try {
191
191
  // Use the new utility function to find objects by hardcoded UUID
192
192
  var object = findObjectByHardcodedUuid(this.sceneViewer.scene, componentUuid);
193
+
194
+ // Fallback: If not found by utility, try direct UUID or name lookup
195
+ if (!object) {
196
+ object = this.sceneViewer.scene.getObjectByProperty('uuid', componentUuid);
197
+ }
198
+ if (!object) {
199
+ object = this.sceneViewer.scene.getObjectByProperty('name', componentUuid);
200
+ }
193
201
  if (!object) {
194
202
  console.warn('⚠️ Component not found:', componentUuid);
195
203
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2112-lab/central-plant",
3
- "version": "0.1.75",
3
+ "version": "0.1.76",
4
4
  "description": "Utility modules for the Central Plant Application",
5
5
  "main": "dist/bundle/index.js",
6
6
  "module": "dist/esm/index.js",