@2112-lab/central-plant 0.3.38 → 0.3.41
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/bundle/index.js +1096 -562
- package/dist/cjs/src/core/centralPlant.js +115 -68
- package/dist/cjs/src/core/centralPlantInternals.js +20 -36
- package/dist/cjs/src/index.js +23 -0
- package/dist/cjs/src/managers/behaviors/IoBehaviorManager.js +175 -234
- package/dist/cjs/src/managers/components/componentDataManager.js +63 -11
- package/dist/cjs/src/managers/scene/componentTooltipManager.js +95 -65
- package/dist/cjs/src/managers/scene/modelManager.js +93 -145
- package/dist/cjs/src/managers/scene/sceneOperationsManager.js +8 -3
- package/dist/cjs/src/utils/animationTransformUtils.js +82 -0
- package/dist/cjs/src/utils/behaviorDispatch.js +62 -0
- package/dist/cjs/src/utils/behaviorRegistration.js +76 -0
- package/dist/cjs/src/utils/behaviorSceneUtils.js +155 -0
- package/dist/cjs/src/utils/behaviorSchema.js +209 -0
- package/dist/esm/src/core/centralPlant.js +115 -68
- package/dist/esm/src/core/centralPlantInternals.js +21 -37
- package/dist/esm/src/index.js +5 -0
- package/dist/esm/src/managers/behaviors/IoBehaviorManager.js +176 -235
- package/dist/esm/src/managers/components/componentDataManager.js +63 -11
- package/dist/esm/src/managers/scene/componentTooltipManager.js +95 -65
- package/dist/esm/src/managers/scene/modelManager.js +94 -146
- package/dist/esm/src/managers/scene/sceneOperationsManager.js +8 -3
- package/dist/esm/src/utils/animationTransformUtils.js +56 -0
- package/dist/esm/src/utils/behaviorDispatch.js +56 -0
- package/dist/esm/src/utils/behaviorRegistration.js +71 -0
- package/dist/esm/src/utils/behaviorSceneUtils.js +147 -0
- package/dist/esm/src/utils/behaviorSchema.js +201 -0
- package/dist/index.d.ts +186 -1
- package/package.json +1 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Register mesh animations and intra-component state links when a smart
|
|
9
|
+
* component is placed or imported into the scene.
|
|
10
|
+
*
|
|
11
|
+
* @param {import('../managers/behaviors/IoBehaviorManager.js').IoBehaviorManager} ioBehavMgr
|
|
12
|
+
* @param {string} componentUuid - Instance UUID of the parent component
|
|
13
|
+
* @param {Object} componentData - Smart component dictionary entry
|
|
14
|
+
* @param {Object} componentModel - Root THREE.Object3D of the placed component
|
|
15
|
+
* @param {Object} componentDictionary - modelPreloader.componentDictionary
|
|
16
|
+
*/
|
|
17
|
+
function registerBehaviorsForComponent(ioBehavMgr, componentUuid, componentData, componentModel, componentDictionary) {
|
|
18
|
+
var _componentData$behavi;
|
|
19
|
+
if (!ioBehavMgr || !componentData || !componentModel) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (componentData.isSmart && componentData.attachedDevices) {
|
|
23
|
+
var _loop = function _loop() {
|
|
24
|
+
var _Object$entries$_i = _rollupPluginBabelHelpers.slicedToArray(_Object$entries[_i], 2),
|
|
25
|
+
attachmentId = _Object$entries$_i[0],
|
|
26
|
+
attachment = _Object$entries$_i[1];
|
|
27
|
+
var deviceData = componentDictionary === null || componentDictionary === void 0 ? void 0 : componentDictionary[attachment.deviceId];
|
|
28
|
+
if (!(deviceData !== null && deviceData !== void 0 && deviceData.behaviorConfig)) return 1; // continue
|
|
29
|
+
var deviceRoot = null;
|
|
30
|
+
componentModel.traverse(function (obj) {
|
|
31
|
+
var _obj$userData;
|
|
32
|
+
if (!deviceRoot && ((_obj$userData = obj.userData) === null || _obj$userData === void 0 ? void 0 : _obj$userData.attachmentId) === attachmentId) deviceRoot = obj;
|
|
33
|
+
});
|
|
34
|
+
if (deviceRoot) {
|
|
35
|
+
ioBehavMgr.loadBehaviors(attachmentId, deviceData.behaviorConfig, deviceRoot, componentUuid);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
for (var _i = 0, _Object$entries = Object.entries(componentData.attachedDevices); _i < _Object$entries.length; _i++) {
|
|
39
|
+
if (_loop()) continue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (((_componentData$behavi = componentData.behaviors) === null || _componentData$behavi === void 0 ? void 0 : _componentData$behavi.length) > 0) {
|
|
43
|
+
ioBehavMgr.registerComponentBehaviors(componentUuid, componentData.behaviors);
|
|
44
|
+
} else if (componentData.isSmart) {
|
|
45
|
+
ioBehavMgr.registerComponentBehaviors(componentUuid, []);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Reload mesh behaviorConfig for every placed instance of an I/O device asset.
|
|
51
|
+
* Call after the animation wizard saves updated behaviorConfig to the dictionary.
|
|
52
|
+
*
|
|
53
|
+
* @param {import('../managers/behaviors/IoBehaviorManager.js').IoBehaviorManager} ioBehavMgr
|
|
54
|
+
* @param {string} deviceAssetId - Dictionary / asset id of the I/O device
|
|
55
|
+
* @param {Object} componentDictionary
|
|
56
|
+
* @param {Object} centralPlant
|
|
57
|
+
*/
|
|
58
|
+
function reloadBehaviorsForDeviceAsset(ioBehavMgr, deviceAssetId, componentDictionary, centralPlant) {
|
|
59
|
+
var _centralPlant$sceneVi;
|
|
60
|
+
var scene = centralPlant === null || centralPlant === void 0 || (_centralPlant$sceneVi = centralPlant.sceneViewer) === null || _centralPlant$sceneVi === void 0 ? void 0 : _centralPlant$sceneVi.scene;
|
|
61
|
+
var deviceData = componentDictionary === null || componentDictionary === void 0 ? void 0 : componentDictionary[deviceAssetId];
|
|
62
|
+
if (!ioBehavMgr || !scene || !(deviceData !== null && deviceData !== void 0 && deviceData.behaviorConfig)) return;
|
|
63
|
+
scene.traverse(function (obj) {
|
|
64
|
+
var _obj$userData2, _obj$userData3, _obj$parent;
|
|
65
|
+
if (((_obj$userData2 = obj.userData) === null || _obj$userData2 === void 0 ? void 0 : _obj$userData2.objectType) !== 'io-device') return;
|
|
66
|
+
if (((_obj$userData3 = obj.userData) === null || _obj$userData3 === void 0 ? void 0 : _obj$userData3.deviceId) !== deviceAssetId) return;
|
|
67
|
+
var parentUuid = obj.userData.parentComponentId || ((_obj$parent = obj.parent) === null || _obj$parent === void 0 ? void 0 : _obj$parent.uuid);
|
|
68
|
+
var attachmentId = obj.userData.attachmentId;
|
|
69
|
+
if (!parentUuid || !attachmentId) return;
|
|
70
|
+
ioBehavMgr.unloadForAttachment(parentUuid, attachmentId);
|
|
71
|
+
ioBehavMgr.loadBehaviors(attachmentId, deviceData.behaviorConfig, obj, parentUuid);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
exports.registerBehaviorsForComponent = registerBehaviorsForComponent;
|
|
76
|
+
exports.reloadBehaviorsForDeviceAsset = reloadBehaviorsForDeviceAsset;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var behaviorRegistration = require('./behaviorRegistration.js');
|
|
6
|
+
var behaviorDispatch = require('./behaviorDispatch.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Scene-level behavior helpers: scan endpoints, register behaviors, cross-component links.
|
|
10
|
+
*/
|
|
11
|
+
function getComponentDictionary(centralPlant) {
|
|
12
|
+
var _centralPlant$getUtil, _centralPlant$manager;
|
|
13
|
+
return (centralPlant === null || centralPlant === void 0 || (_centralPlant$getUtil = centralPlant.getUtility) === null || _centralPlant$getUtil === void 0 || (_centralPlant$getUtil = _centralPlant$getUtil.call(centralPlant, 'modelPreloader')) === null || _centralPlant$getUtil === void 0 ? void 0 : _centralPlant$getUtil.componentDictionary) || (centralPlant === null || centralPlant === void 0 || (_centralPlant$manager = centralPlant.managers) === null || _centralPlant$manager === void 0 || (_centralPlant$manager = _centralPlant$manager.componentDataManager) === null || _centralPlant$manager === void 0 ? void 0 : _centralPlant$manager.componentDictionary) || null;
|
|
14
|
+
}
|
|
15
|
+
function statesFromBehaviorConfig(device) {
|
|
16
|
+
if (!(device !== null && device !== void 0 && device.behaviorConfig) || !Array.isArray(device.behaviorConfig)) return [];
|
|
17
|
+
return device.behaviorConfig.map(function (b) {
|
|
18
|
+
return b.stateVariable;
|
|
19
|
+
}).filter(Boolean).filter(function (v, i, arr) {
|
|
20
|
+
return arr.indexOf(v) === i;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function resolveStatesForDevice(ioObj, deviceId, componentDictionary) {
|
|
24
|
+
var _ioObj$userData;
|
|
25
|
+
var device = componentDictionary === null || componentDictionary === void 0 ? void 0 : componentDictionary[deviceId];
|
|
26
|
+
var fromBehaviorConfig = statesFromBehaviorConfig(device);
|
|
27
|
+
if (fromBehaviorConfig.length) return fromBehaviorConfig;
|
|
28
|
+
return (((_ioObj$userData = ioObj.userData) === null || _ioObj$userData === void 0 ? void 0 : _ioObj$userData.dataPoints) || []).map(function (dp) {
|
|
29
|
+
return dp.id || dp.name;
|
|
30
|
+
}).filter(Boolean).filter(function (v, i, arr) {
|
|
31
|
+
return arr.indexOf(v) === i;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Scan the live Three.js scene for smart-component io-device endpoints.
|
|
37
|
+
*/
|
|
38
|
+
function scanSceneIoEndpoints(centralPlant) {
|
|
39
|
+
var _centralPlant$sceneVi;
|
|
40
|
+
var scene = centralPlant === null || centralPlant === void 0 || (_centralPlant$sceneVi = centralPlant.sceneViewer) === null || _centralPlant$sceneVi === void 0 ? void 0 : _centralPlant$sceneVi.scene;
|
|
41
|
+
if (!scene) return [];
|
|
42
|
+
var dict = getComponentDictionary(centralPlant);
|
|
43
|
+
var endpoints = [];
|
|
44
|
+
scene.traverse(function (obj) {
|
|
45
|
+
var _obj$userData, _parent$userData, _parent$userData2;
|
|
46
|
+
if (((_obj$userData = obj.userData) === null || _obj$userData === void 0 ? void 0 : _obj$userData.objectType) !== 'io-device') return;
|
|
47
|
+
var parent = obj.parent;
|
|
48
|
+
var parentUuid = obj.userData.parentComponentId || (parent === null || parent === void 0 ? void 0 : parent.uuid) || '';
|
|
49
|
+
var parentName = (parent === null || parent === void 0 || (_parent$userData = parent.userData) === null || _parent$userData === void 0 ? void 0 : _parent$userData.hardcodedUuid) || (parent === null || parent === void 0 ? void 0 : parent.name) || parentUuid;
|
|
50
|
+
var libraryId = (parent === null || parent === void 0 || (_parent$userData2 = parent.userData) === null || _parent$userData2 === void 0 ? void 0 : _parent$userData2.libraryId) || '';
|
|
51
|
+
var attachmentId = obj.userData.attachmentId || obj.name || obj.uuid;
|
|
52
|
+
var deviceId = obj.userData.deviceId || '';
|
|
53
|
+
endpoints.push({
|
|
54
|
+
key: behaviorDispatch.getScopedAttachmentKey(attachmentId, parentUuid),
|
|
55
|
+
parentUuid: parentUuid,
|
|
56
|
+
parentName: parentName,
|
|
57
|
+
libraryId: libraryId,
|
|
58
|
+
attachmentId: attachmentId,
|
|
59
|
+
attachmentLabel: obj.userData.attachmentLabel || attachmentId,
|
|
60
|
+
deviceId: deviceId,
|
|
61
|
+
states: resolveStatesForDevice(obj, deviceId, dict)
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
return endpoints;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Load cross-component behaviors from scene data mirrors.
|
|
69
|
+
*/
|
|
70
|
+
function loadCrossComponentBehaviors(centralPlant) {
|
|
71
|
+
var _centralPlant$importe, _centralPlant$sceneVi2;
|
|
72
|
+
return (centralPlant === null || centralPlant === void 0 || (_centralPlant$importe = centralPlant.importedSceneData) === null || _centralPlant$importe === void 0 ? void 0 : _centralPlant$importe.behaviors) || (centralPlant === null || centralPlant === void 0 || (_centralPlant$sceneVi2 = centralPlant.sceneViewer) === null || _centralPlant$sceneVi2 === void 0 || (_centralPlant$sceneVi2 = _centralPlant$sceneVi2.currentSceneData) === null || _centralPlant$sceneVi2 === void 0 ? void 0 : _centralPlant$sceneVi2.behaviors) || [];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Persist cross-component behaviors to scene data mirrors and the runtime manager.
|
|
77
|
+
*/
|
|
78
|
+
function applyCrossComponentBehaviors(centralPlant, behaviors) {
|
|
79
|
+
var normalized = behaviors || [];
|
|
80
|
+
if (centralPlant.importedSceneData) {
|
|
81
|
+
if (normalized.length) {
|
|
82
|
+
centralPlant.importedSceneData.behaviors = normalized;
|
|
83
|
+
} else {
|
|
84
|
+
delete centralPlant.importedSceneData.behaviors;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
var sceneViewer = centralPlant.sceneViewer;
|
|
88
|
+
if (sceneViewer && !sceneViewer.currentSceneData) {
|
|
89
|
+
var _centralPlant$getConn;
|
|
90
|
+
sceneViewer.currentSceneData = {
|
|
91
|
+
version: '2.3',
|
|
92
|
+
connections: ((_centralPlant$getConn = centralPlant.getConnections) === null || _centralPlant$getConn === void 0 ? void 0 : _centralPlant$getConn.call(centralPlant)) || [],
|
|
93
|
+
scene: {
|
|
94
|
+
children: []
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
var currentSceneData = sceneViewer === null || sceneViewer === void 0 ? void 0 : sceneViewer.currentSceneData;
|
|
99
|
+
if (currentSceneData) {
|
|
100
|
+
if (normalized.length) {
|
|
101
|
+
currentSceneData.behaviors = normalized;
|
|
102
|
+
} else {
|
|
103
|
+
delete currentSceneData.behaviors;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
var ioBehavMgr = behaviorDispatch.getIoBehaviorManager(sceneViewer);
|
|
107
|
+
if (ioBehavMgr) {
|
|
108
|
+
ioBehavMgr.setCrossComponentBehaviors(normalized);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Re-register intra-component behaviors on all scene instances of a smart component.
|
|
114
|
+
*/
|
|
115
|
+
function refreshSceneIntraBehaviors(centralPlant, libraryId, behaviors) {
|
|
116
|
+
var _centralPlant$sceneVi3;
|
|
117
|
+
var ioBehavMgr = behaviorDispatch.getIoBehaviorManager(centralPlant === null || centralPlant === void 0 ? void 0 : centralPlant.sceneViewer);
|
|
118
|
+
var scene = centralPlant === null || centralPlant === void 0 || (_centralPlant$sceneVi3 = centralPlant.sceneViewer) === null || _centralPlant$sceneVi3 === void 0 ? void 0 : _centralPlant$sceneVi3.scene;
|
|
119
|
+
if (!ioBehavMgr || !scene || !libraryId) return;
|
|
120
|
+
scene.traverse(function (obj) {
|
|
121
|
+
var _obj$userData2, _obj$userData3;
|
|
122
|
+
if (((_obj$userData2 = obj.userData) === null || _obj$userData2 === void 0 ? void 0 : _obj$userData2.objectType) === 'component' && ((_obj$userData3 = obj.userData) === null || _obj$userData3 === void 0 ? void 0 : _obj$userData3.libraryId) === libraryId) {
|
|
123
|
+
ioBehavMgr.registerComponentBehaviors(obj.uuid, behaviors || []);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Re-register intra- and cross-component behaviors for all instances in the live scene.
|
|
130
|
+
*/
|
|
131
|
+
function reregisterSceneBehaviors(centralPlant) {
|
|
132
|
+
var _centralPlant$sceneVi4;
|
|
133
|
+
var ioBehavMgr = behaviorDispatch.getIoBehaviorManager(centralPlant === null || centralPlant === void 0 ? void 0 : centralPlant.sceneViewer);
|
|
134
|
+
var scene = centralPlant === null || centralPlant === void 0 || (_centralPlant$sceneVi4 = centralPlant.sceneViewer) === null || _centralPlant$sceneVi4 === void 0 ? void 0 : _centralPlant$sceneVi4.scene;
|
|
135
|
+
var dict = getComponentDictionary(centralPlant);
|
|
136
|
+
if (!ioBehavMgr || !scene) return;
|
|
137
|
+
var crossBehaviors = loadCrossComponentBehaviors(centralPlant);
|
|
138
|
+
ioBehavMgr.setCrossComponentBehaviors(crossBehaviors);
|
|
139
|
+
if (!dict) return;
|
|
140
|
+
scene.traverse(function (obj) {
|
|
141
|
+
var _obj$userData4, _obj$userData5;
|
|
142
|
+
if (((_obj$userData4 = obj.userData) === null || _obj$userData4 === void 0 ? void 0 : _obj$userData4.objectType) !== 'component') return;
|
|
143
|
+
var libraryId = (_obj$userData5 = obj.userData) === null || _obj$userData5 === void 0 ? void 0 : _obj$userData5.libraryId;
|
|
144
|
+
if (!libraryId) return;
|
|
145
|
+
var componentData = dict[libraryId];
|
|
146
|
+
if (!componentData) return;
|
|
147
|
+
behaviorRegistration.registerBehaviorsForComponent(ioBehavMgr, obj.uuid, componentData, obj, dict);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
exports.applyCrossComponentBehaviors = applyCrossComponentBehaviors;
|
|
152
|
+
exports.loadCrossComponentBehaviors = loadCrossComponentBehaviors;
|
|
153
|
+
exports.refreshSceneIntraBehaviors = refreshSceneIntraBehaviors;
|
|
154
|
+
exports.reregisterSceneBehaviors = reregisterSceneBehaviors;
|
|
155
|
+
exports.scanSceneIoEndpoints = scanSceneIoEndpoints;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Shared behavior schema helpers for runtime normalization and UI authoring.
|
|
9
|
+
* Used by IoBehaviorManager and sandbox BehaviorDialog.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Normalize behavior from shorthand to full format.
|
|
14
|
+
* Supports:
|
|
15
|
+
* - input: "attachment.state" → { attachment, state }
|
|
16
|
+
* - outputs: ["attachment.state", ...] → converted to _outputs array
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} behavior - Raw behavior from scene JSON
|
|
19
|
+
* @returns {Object} Normalized behavior
|
|
20
|
+
*/
|
|
21
|
+
function normalizeBehavior(behavior) {
|
|
22
|
+
var normalized = _rollupPluginBabelHelpers.objectSpread2({}, behavior);
|
|
23
|
+
if (typeof behavior.input === 'string') {
|
|
24
|
+
var _behavior$input$split = behavior.input.split('.'),
|
|
25
|
+
_behavior$input$split2 = _rollupPluginBabelHelpers.slicedToArray(_behavior$input$split, 2),
|
|
26
|
+
attachment = _behavior$input$split2[0],
|
|
27
|
+
state = _behavior$input$split2[1];
|
|
28
|
+
normalized.input = {
|
|
29
|
+
attachment: attachment,
|
|
30
|
+
state: state
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (behavior.outputs) {
|
|
34
|
+
normalized._outputs = behavior.outputs.map(function (out) {
|
|
35
|
+
if (typeof out === 'string') {
|
|
36
|
+
var _out$split = out.split('.'),
|
|
37
|
+
_out$split2 = _rollupPluginBabelHelpers.slicedToArray(_out$split, 2),
|
|
38
|
+
_attachment = _out$split2[0],
|
|
39
|
+
_state = _out$split2[1];
|
|
40
|
+
return {
|
|
41
|
+
attachment: _attachment,
|
|
42
|
+
state: _state
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
});
|
|
47
|
+
delete normalized.outputs;
|
|
48
|
+
} else if (typeof behavior.output === 'string') {
|
|
49
|
+
var _behavior$output$spli = behavior.output.split('.'),
|
|
50
|
+
_behavior$output$spli2 = _rollupPluginBabelHelpers.slicedToArray(_behavior$output$spli, 2),
|
|
51
|
+
_attachment2 = _behavior$output$spli2[0],
|
|
52
|
+
_state2 = _behavior$output$spli2[1];
|
|
53
|
+
normalized.output = {
|
|
54
|
+
attachment: _attachment2,
|
|
55
|
+
state: _state2
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return normalized;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Build intra-component shorthand behavior from form fields.
|
|
63
|
+
*/
|
|
64
|
+
function buildIntraBehavior(_ref) {
|
|
65
|
+
var id = _ref.id,
|
|
66
|
+
inputAttachment = _ref.inputAttachment,
|
|
67
|
+
inputState = _ref.inputState,
|
|
68
|
+
outputs = _ref.outputs;
|
|
69
|
+
return {
|
|
70
|
+
id: id || "behavior-".concat(Date.now()),
|
|
71
|
+
input: "".concat(inputAttachment, ".").concat(inputState),
|
|
72
|
+
outputs: outputs.filter(function (o) {
|
|
73
|
+
return o.attachment && o.state;
|
|
74
|
+
}).map(function (o) {
|
|
75
|
+
return "".concat(o.attachment, ".").concat(o.state);
|
|
76
|
+
})
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Parse intra-component shorthand into form fields.
|
|
82
|
+
*/
|
|
83
|
+
function parseIntraBehavior(behavior) {
|
|
84
|
+
var inputAttachment = null;
|
|
85
|
+
var inputState = null;
|
|
86
|
+
if (typeof behavior.input === 'string') {
|
|
87
|
+
var _behavior$input$split3 = behavior.input.split('.');
|
|
88
|
+
var _behavior$input$split4 = _rollupPluginBabelHelpers.slicedToArray(_behavior$input$split3, 2);
|
|
89
|
+
inputAttachment = _behavior$input$split4[0];
|
|
90
|
+
inputState = _behavior$input$split4[1];
|
|
91
|
+
} else if (behavior.input && _rollupPluginBabelHelpers["typeof"](behavior.input) === 'object') {
|
|
92
|
+
inputAttachment = behavior.input.attachment || null;
|
|
93
|
+
inputState = behavior.input.state || null;
|
|
94
|
+
}
|
|
95
|
+
var outputs = (behavior.outputs || []).map(function (out) {
|
|
96
|
+
if (typeof out === 'string') {
|
|
97
|
+
var _out$split3 = out.split('.'),
|
|
98
|
+
_out$split4 = _rollupPluginBabelHelpers.slicedToArray(_out$split3, 2),
|
|
99
|
+
attachment = _out$split4[0],
|
|
100
|
+
state = _out$split4[1];
|
|
101
|
+
return {
|
|
102
|
+
attachment: attachment,
|
|
103
|
+
state: state
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
attachment: (out === null || out === void 0 ? void 0 : out.attachment) || null,
|
|
108
|
+
state: (out === null || out === void 0 ? void 0 : out.state) || null
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
id: behavior.id || '',
|
|
113
|
+
inputAttachment: inputAttachment || null,
|
|
114
|
+
inputState: inputState || null,
|
|
115
|
+
outputs: outputs.length ? outputs : [{
|
|
116
|
+
attachment: null,
|
|
117
|
+
state: null
|
|
118
|
+
}]
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Build cross-component behavior with component instance scoping.
|
|
124
|
+
*/
|
|
125
|
+
function buildCrossBehavior(_ref2) {
|
|
126
|
+
var id = _ref2.id,
|
|
127
|
+
inputEndpoint = _ref2.inputEndpoint,
|
|
128
|
+
inputState = _ref2.inputState,
|
|
129
|
+
outputs = _ref2.outputs;
|
|
130
|
+
var _split = (inputEndpoint || '').split('::'),
|
|
131
|
+
_split2 = _rollupPluginBabelHelpers.slicedToArray(_split, 2),
|
|
132
|
+
inputComponent = _split2[0],
|
|
133
|
+
inputAttachment = _split2[1];
|
|
134
|
+
return {
|
|
135
|
+
id: id || "behavior-".concat(Date.now()),
|
|
136
|
+
input: {
|
|
137
|
+
component: inputComponent,
|
|
138
|
+
attachment: inputAttachment,
|
|
139
|
+
state: inputState
|
|
140
|
+
},
|
|
141
|
+
outputs: outputs.filter(function (o) {
|
|
142
|
+
return o.endpoint && o.state;
|
|
143
|
+
}).map(function (o) {
|
|
144
|
+
var _o$endpoint$split = o.endpoint.split('::'),
|
|
145
|
+
_o$endpoint$split2 = _rollupPluginBabelHelpers.slicedToArray(_o$endpoint$split, 2),
|
|
146
|
+
component = _o$endpoint$split2[0],
|
|
147
|
+
attachment = _o$endpoint$split2[1];
|
|
148
|
+
return {
|
|
149
|
+
component: component,
|
|
150
|
+
attachment: attachment,
|
|
151
|
+
state: o.state
|
|
152
|
+
};
|
|
153
|
+
})
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Parse cross-component behavior into form fields.
|
|
159
|
+
*/
|
|
160
|
+
function parseCrossBehavior(behavior) {
|
|
161
|
+
var inputComponent, inputAttachment, inputState;
|
|
162
|
+
if (typeof behavior.input === 'string') {
|
|
163
|
+
var _behavior$input$split5 = behavior.input.split('.'),
|
|
164
|
+
_behavior$input$split6 = _rollupPluginBabelHelpers.slicedToArray(_behavior$input$split5, 2),
|
|
165
|
+
attachment = _behavior$input$split6[0],
|
|
166
|
+
state = _behavior$input$split6[1];
|
|
167
|
+
inputAttachment = attachment;
|
|
168
|
+
inputState = state;
|
|
169
|
+
inputComponent = null;
|
|
170
|
+
} else if (behavior.input) {
|
|
171
|
+
inputComponent = behavior.input.component;
|
|
172
|
+
inputAttachment = behavior.input.attachment;
|
|
173
|
+
inputState = behavior.input.state;
|
|
174
|
+
}
|
|
175
|
+
var rawOutputs = behavior.outputs || (behavior.output ? [behavior.output] : behavior._outputs || []);
|
|
176
|
+
var outputs = rawOutputs.map(function (out) {
|
|
177
|
+
if (typeof out === 'string') {
|
|
178
|
+
var _out$split5 = out.split('.'),
|
|
179
|
+
_out$split6 = _rollupPluginBabelHelpers.slicedToArray(_out$split5, 2),
|
|
180
|
+
_attachment3 = _out$split6[0],
|
|
181
|
+
_state3 = _out$split6[1];
|
|
182
|
+
return {
|
|
183
|
+
endpoint: _attachment3 ? "::".concat(_attachment3) : null,
|
|
184
|
+
state: _state3
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
var endpoint = out.component && out.attachment ? "".concat(out.component, "::").concat(out.attachment) : out.attachment ? "::".concat(out.attachment) : null;
|
|
188
|
+
return {
|
|
189
|
+
endpoint: endpoint,
|
|
190
|
+
state: out.state || null
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
var inputEndpoint = inputComponent && inputAttachment ? "".concat(inputComponent, "::").concat(inputAttachment) : inputAttachment ? "::".concat(inputAttachment) : null;
|
|
194
|
+
return {
|
|
195
|
+
id: behavior.id || '',
|
|
196
|
+
inputEndpoint: inputEndpoint,
|
|
197
|
+
inputState: inputState || null,
|
|
198
|
+
outputs: outputs.length ? outputs : [{
|
|
199
|
+
endpoint: null,
|
|
200
|
+
state: null
|
|
201
|
+
}]
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
exports.buildCrossBehavior = buildCrossBehavior;
|
|
206
|
+
exports.buildIntraBehavior = buildIntraBehavior;
|
|
207
|
+
exports.normalizeBehavior = normalizeBehavior;
|
|
208
|
+
exports.parseCrossBehavior = parseCrossBehavior;
|
|
209
|
+
exports.parseIntraBehavior = parseIntraBehavior;
|