@buerli.io/core 0.0.35-beta.0 → 0.0.35-beta.1
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/build/esm/geometry/ThreeGeometryCreator.js +17 -47
- package/build/esm/store/index.js +2 -1
- package/build/esm/store/states/buerli.js +10 -33
- package/build/esm/store/states/canvas.js +2 -2
- package/build/esm/store/states/geometry.js +13 -25
- package/build/esm/store/states/graphic.js +5 -5
- package/build/esm/store/states/message.js +2 -2
- package/build/esm/store/states/plugin.js +13 -58
- package/build/esm/store/states/selection.js +13 -62
- package/build/esm/store/states/structure.js +4 -10
- package/build/esm/store/subscribtion/selection.js +2 -1
- package/build/esm/utils/Measure.js +1 -1
- package/build/esm/utils/Timing.js +1 -1
- package/package.json +2 -2
|
@@ -65,17 +65,14 @@ export class ThreeGeometryCreator {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
const points = Object.values(pointMap);
|
|
68
|
-
return {
|
|
69
|
-
graphicId,
|
|
68
|
+
return Object.assign({ graphicId,
|
|
70
69
|
map,
|
|
71
70
|
meshes,
|
|
72
71
|
lines,
|
|
73
72
|
edges,
|
|
74
73
|
arcs,
|
|
75
74
|
points,
|
|
76
|
-
box,
|
|
77
|
-
...this.getMetadata(null, container, color),
|
|
78
|
-
};
|
|
75
|
+
box }, this.getMetadata(null, container, color));
|
|
79
76
|
}
|
|
80
77
|
createSurface(mesh, container, color = [0, 0, 0]) {
|
|
81
78
|
let meshGeom = this.createMesh(mesh, container, color);
|
|
@@ -103,41 +100,38 @@ export class ThreeGeometryCreator {
|
|
|
103
100
|
geometry.setIndex(mesh.indices);
|
|
104
101
|
geometry.setAttribute('position', new THREE.Float32BufferAttribute(mesh.vertices, 3));
|
|
105
102
|
mesh.normals && geometry.setAttribute('normal', new THREE.Float32BufferAttribute(mesh.normals, 3));
|
|
106
|
-
return {
|
|
103
|
+
return Object.assign({
|
|
107
104
|
// TODO: The server should not send invalid meshes.
|
|
108
|
-
isValid: mesh.vertices && mesh.vertices.length > 0,
|
|
109
|
-
geometry,
|
|
105
|
+
isValid: mesh.vertices && mesh.vertices.length > 0, geometry,
|
|
110
106
|
graphicId,
|
|
111
107
|
type,
|
|
112
|
-
loops,
|
|
113
|
-
...this.getMetadata(mesh, container, color),
|
|
114
|
-
};
|
|
108
|
+
loops }, this.getMetadata(mesh, container, color));
|
|
115
109
|
}
|
|
116
110
|
createPlane(mesh, meshGeom) {
|
|
117
111
|
const type = GraphicType.PLANE;
|
|
118
112
|
const { normal: n, pointOnPlane: p } = mesh.properties.surface;
|
|
119
113
|
const pointOnPlane = new THREE.Vector3(p[0], p[1], p[2]);
|
|
120
114
|
const normal = new THREE.Vector3(n[0], n[1], n[2]).normalize();
|
|
121
|
-
return {
|
|
115
|
+
return Object.assign(Object.assign({}, meshGeom), { type, pointOnPlane, normal });
|
|
122
116
|
}
|
|
123
117
|
createCylinder(mesh, meshGeom) {
|
|
124
118
|
const type = GraphicType.CYLINDER;
|
|
125
119
|
const { origin: o, axis: a, height, radius } = mesh.properties.surface;
|
|
126
120
|
const origin = new THREE.Vector3(o[0], o[1], o[2]);
|
|
127
121
|
const axis = new THREE.Vector3(a[0], a[1], a[2]).normalize();
|
|
128
|
-
return {
|
|
122
|
+
return Object.assign(Object.assign({}, meshGeom), { type, origin, axis, height, radius });
|
|
129
123
|
}
|
|
130
124
|
createCone(mesh, meshGeom) {
|
|
131
125
|
const type = GraphicType.CONE;
|
|
132
126
|
const { origin: o, axis: a, height, radiusBottom, radiusTop } = mesh.properties.surface;
|
|
133
127
|
const origin = new THREE.Vector3(o[0], o[1], o[2]);
|
|
134
128
|
const axis = new THREE.Vector3(a[0], a[1], a[2]).normalize();
|
|
135
|
-
return {
|
|
129
|
+
return Object.assign(Object.assign({}, meshGeom), { type, origin, axis, height, radiusBottom, radiusTop });
|
|
136
130
|
}
|
|
137
131
|
createSphere(mesh, meshGeom) {
|
|
138
132
|
const type = GraphicType.SPHERE;
|
|
139
133
|
const { radius } = mesh.properties.surface;
|
|
140
|
-
return {
|
|
134
|
+
return Object.assign(Object.assign({}, meshGeom), { type, radius });
|
|
141
135
|
}
|
|
142
136
|
createLine(line, container, points, color = [0, 0, 0]) {
|
|
143
137
|
const graphicId = line.id;
|
|
@@ -149,14 +143,9 @@ export class ThreeGeometryCreator {
|
|
|
149
143
|
this.insertPoint(container, `${startId}|point`, startId, start.clone(), line.id, 'start', points);
|
|
150
144
|
this.insertPoint(container, `${endId}|point`, endId, end.clone(), line.id, 'end', points);
|
|
151
145
|
const geometry = new THREE.BufferGeometry().setFromPoints([start.clone(), end.clone()]);
|
|
152
|
-
return {
|
|
153
|
-
geometry,
|
|
146
|
+
return Object.assign(Object.assign({ geometry,
|
|
154
147
|
graphicId,
|
|
155
|
-
type,
|
|
156
|
-
...this.getMetadata(line, container, color),
|
|
157
|
-
start: start.clone(),
|
|
158
|
-
end: end.clone(),
|
|
159
|
-
};
|
|
148
|
+
type }, this.getMetadata(line, container, color)), { start: start.clone(), end: end.clone() });
|
|
160
149
|
}
|
|
161
150
|
createEdge(edge, container, points, color = [0, 0, 0]) {
|
|
162
151
|
const threePts = [];
|
|
@@ -182,14 +171,9 @@ export class ThreeGeometryCreator {
|
|
|
182
171
|
this.insertPoint(container, `${startId}|point`, startId, start, edge.id, 'start', points);
|
|
183
172
|
this.insertPoint(container, `${endId}|point`, endId, end, edge.id, 'end', points);
|
|
184
173
|
const geometry = new THREE.BufferGeometry().setFromPoints(threePts);
|
|
185
|
-
return {
|
|
186
|
-
geometry,
|
|
174
|
+
return Object.assign(Object.assign({ geometry,
|
|
187
175
|
graphicId,
|
|
188
|
-
type,
|
|
189
|
-
...this.getMetadata(edge, container, color),
|
|
190
|
-
start: start.clone(),
|
|
191
|
-
end: end.clone(),
|
|
192
|
-
};
|
|
176
|
+
type }, this.getMetadata(edge, container, color)), { start: start.clone(), end: end.clone() });
|
|
193
177
|
}
|
|
194
178
|
createArc(arc, container, points, color = [0, 0, 0]) {
|
|
195
179
|
const graphicId = arc.id;
|
|
@@ -233,27 +217,13 @@ export class ThreeGeometryCreator {
|
|
|
233
217
|
this.insertPoint(container, `${startId}|point`, startId, start, arc.id, 'start', points);
|
|
234
218
|
this.insertPoint(container, `${endId}|point`, endId, end, arc.id, 'end', points);
|
|
235
219
|
const geometry = new THREE.BufferGeometry().setFromPoints(threePts);
|
|
236
|
-
return {
|
|
237
|
-
geometry,
|
|
220
|
+
return Object.assign(Object.assign({ geometry,
|
|
238
221
|
graphicId,
|
|
239
|
-
type,
|
|
240
|
-
...this.getMetadata(arc, container, color),
|
|
241
|
-
normal: normal.clone(),
|
|
242
|
-
center: center.clone(),
|
|
243
|
-
radius: arc.radius,
|
|
244
|
-
angle: arc.angle,
|
|
245
|
-
};
|
|
222
|
+
type }, this.getMetadata(arc, container, color)), { normal: normal.clone(), center: center.clone(), radius: arc.radius, angle: arc.angle });
|
|
246
223
|
}
|
|
247
224
|
createPoint(container, key, graphicId, position, ownerId, type) {
|
|
248
|
-
return {
|
|
249
|
-
|
|
250
|
-
graphicId,
|
|
251
|
-
type: GraphicType.POINT,
|
|
252
|
-
...this.getMetadata(null, container),
|
|
253
|
-
position: position.clone(),
|
|
254
|
-
geometry: position.clone(),
|
|
255
|
-
owners: [{ ownerId, type }],
|
|
256
|
-
};
|
|
225
|
+
return Object.assign(Object.assign({ key,
|
|
226
|
+
graphicId, type: GraphicType.POINT }, this.getMetadata(null, container)), { position: position.clone(), geometry: position.clone(), owners: [{ ownerId, type }] });
|
|
257
227
|
}
|
|
258
228
|
insertPoint(container, key, graphicId, position, ownerId, type, points) {
|
|
259
229
|
const existingPoint = points[key];
|
package/build/esm/store/index.js
CHANGED
|
@@ -7,8 +7,9 @@ function getDrawing(id) {
|
|
|
7
7
|
* @returns PluginState or undefined if either drawing or plugin don't exist
|
|
8
8
|
*/
|
|
9
9
|
function getPlugin(drawingId, pluginId) {
|
|
10
|
+
var _a;
|
|
10
11
|
const { drawing } = api.getState();
|
|
11
|
-
return drawing.refs[drawingId]
|
|
12
|
+
return (_a = drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.plugin.refs[pluginId];
|
|
12
13
|
}
|
|
13
14
|
function init(sel) {
|
|
14
15
|
api.getState().api.init(typeof sel === 'function' ? sel(api.getState()) || {} : sel);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { createDrawingState } from './drawing';
|
|
2
2
|
import { getInitialMessageState } from './message';
|
|
3
3
|
const initError = 'Please call the init action before you use the buerli store.';
|
|
4
|
-
export const createState = (set, get, api) => ({
|
|
5
|
-
initDone: false,
|
|
6
|
-
options: {
|
|
4
|
+
export const createState = (set, get, api) => (Object.assign({ initDone: false, options: {
|
|
7
5
|
url: '',
|
|
8
6
|
elements: {},
|
|
9
7
|
plugins: {},
|
|
@@ -18,18 +16,11 @@ export const createState = (set, get, api) => ({
|
|
|
18
16
|
config: {
|
|
19
17
|
geometry: {},
|
|
20
18
|
},
|
|
21
|
-
},
|
|
22
|
-
drawing: {
|
|
19
|
+
}, drawing: {
|
|
23
20
|
ids: [],
|
|
24
21
|
refs: {},
|
|
25
22
|
active: null,
|
|
26
|
-
},
|
|
27
|
-
api: {
|
|
28
|
-
...generalApi(set, get),
|
|
29
|
-
...drawingManagementApi(set, get, api),
|
|
30
|
-
},
|
|
31
|
-
...getInitialMessageState(set, get, api),
|
|
32
|
-
});
|
|
23
|
+
}, api: Object.assign(Object.assign({}, generalApi(set, get)), drawingManagementApi(set, get, api)) }, getInitialMessageState(set, get, api)));
|
|
33
24
|
const generalApi = (set, get) => ({
|
|
34
25
|
// TODO: rename init to setOptions and remove initDone if everything is ok
|
|
35
26
|
/**
|
|
@@ -39,7 +30,7 @@ const generalApi = (set, get) => ({
|
|
|
39
30
|
* @param options - options which will be set into state.options
|
|
40
31
|
*/
|
|
41
32
|
init(options) {
|
|
42
|
-
set(state => ({ options: {
|
|
33
|
+
set(state => ({ options: Object.assign(Object.assign({}, state.options), options), initDone: true }));
|
|
43
34
|
},
|
|
44
35
|
});
|
|
45
36
|
const drawingManagementApi = (set, get, api) => ({
|
|
@@ -50,25 +41,11 @@ const drawingManagementApi = (set, get, api) => ({
|
|
|
50
41
|
const drawingState = createDrawingState(sel => set(state => {
|
|
51
42
|
const newState = typeof sel === 'function' ? sel(state.drawing.refs[drawingState.id]) : sel;
|
|
52
43
|
return {
|
|
53
|
-
drawing: {
|
|
54
|
-
...state.drawing,
|
|
55
|
-
refs: {
|
|
56
|
-
...state.drawing.refs,
|
|
57
|
-
[drawingState.id]: {
|
|
58
|
-
...state.drawing.refs[drawingState.id],
|
|
59
|
-
...newState,
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
},
|
|
44
|
+
drawing: Object.assign(Object.assign({}, state.drawing), { refs: Object.assign(Object.assign({}, state.drawing.refs), { [drawingState.id]: Object.assign(Object.assign({}, state.drawing.refs[drawingState.id]), newState) }) }),
|
|
63
45
|
};
|
|
64
46
|
}), () => get().drawing.refs[drawingState.id], api, drawing.ids.length, name);
|
|
65
47
|
set(state => ({
|
|
66
|
-
drawing: {
|
|
67
|
-
...state.drawing,
|
|
68
|
-
refs: { ...state.drawing.refs, [drawingState.id]: drawingState },
|
|
69
|
-
ids: [...state.drawing.ids, drawingState.id],
|
|
70
|
-
active: drawingState.id,
|
|
71
|
-
},
|
|
48
|
+
drawing: Object.assign(Object.assign({}, state.drawing), { refs: Object.assign(Object.assign({}, state.drawing.refs), { [drawingState.id]: drawingState }), ids: [...state.drawing.ids, drawingState.id], active: drawingState.id }),
|
|
72
49
|
}));
|
|
73
50
|
// Initialize global plugins
|
|
74
51
|
get().options.globalPlugins.forEach(def => get().drawing.refs[drawingState.id].api.plugin.createPlugin(def));
|
|
@@ -96,21 +73,21 @@ const drawingManagementApi = (set, get, api) => ({
|
|
|
96
73
|
const active = index >= 0 && state.drawing.active === id
|
|
97
74
|
? state.drawing.ids[index + 1] || state.drawing.ids[index - 1] || null
|
|
98
75
|
: state.drawing.active;
|
|
99
|
-
return { drawing: {
|
|
76
|
+
return { drawing: Object.assign(Object.assign({}, state.drawing), { active }) };
|
|
100
77
|
});
|
|
101
78
|
// 2.
|
|
102
79
|
// Remove drawing from store.
|
|
103
80
|
set(state => {
|
|
104
|
-
const refs = {
|
|
81
|
+
const refs = Object.assign({}, state.drawing.refs);
|
|
105
82
|
const ids = state.drawing.ids.filter(d => d !== id);
|
|
106
83
|
delete refs[id];
|
|
107
|
-
return { drawing: {
|
|
84
|
+
return { drawing: Object.assign(Object.assign({}, state.drawing), { refs, ids }) };
|
|
108
85
|
});
|
|
109
86
|
},
|
|
110
87
|
setActiveDrawing(id) {
|
|
111
88
|
const { initDone, drawing } = get();
|
|
112
89
|
if (!initDone)
|
|
113
90
|
throw new Error(initError);
|
|
114
|
-
set({ drawing: {
|
|
91
|
+
set({ drawing: Object.assign(Object.assign({}, drawing), { active: id }) });
|
|
115
92
|
},
|
|
116
93
|
});
|
|
@@ -8,6 +8,6 @@ export const canvasData = () => ({
|
|
|
8
8
|
// API
|
|
9
9
|
////////////////////////////////////////////////////
|
|
10
10
|
export const canvasApi = (set, get) => ({
|
|
11
|
-
setInteraction: (isInteracting) => set(state => ({ canvas: {
|
|
12
|
-
setControlsEnabled: (enabled) => set(state => ({ canvas: {
|
|
11
|
+
setInteraction: (isInteracting) => set(state => ({ canvas: Object.assign(Object.assign({}, state.canvas), { controls: Object.assign(Object.assign({}, state.canvas.controls), { isInteracting }) }) })),
|
|
12
|
+
setControlsEnabled: (enabled) => set(state => ({ canvas: Object.assign(Object.assign({}, state.canvas), { controls: Object.assign(Object.assign({}, state.canvas.controls), { enabled }) }) })),
|
|
13
13
|
});
|
|
@@ -26,7 +26,7 @@ export const geometryApi = (set, get) => ({
|
|
|
26
26
|
const { api, structure } = get();
|
|
27
27
|
if (structure.visibleContainers.length > 0) {
|
|
28
28
|
const bb = api.structure.calculateProductBounds(structure.root);
|
|
29
|
-
set(state => ({ geometry: {
|
|
29
|
+
set(state => ({ geometry: Object.assign(Object.assign({}, state.geometry), { stamp: Date.now(), bounds: bb }) }));
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
createGeometryIfNotCached: (containerId, color) => {
|
|
@@ -37,13 +37,9 @@ export const geometryApi = (set, get) => ({
|
|
|
37
37
|
if (container) {
|
|
38
38
|
geom = new ThreeGeometryCreator().createGeometry(container, color);
|
|
39
39
|
set(state => {
|
|
40
|
-
const geometryCache = {
|
|
40
|
+
const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: geom });
|
|
41
41
|
return {
|
|
42
|
-
geometry: {
|
|
43
|
-
...state.geometry,
|
|
44
|
-
cache: geometryCache,
|
|
45
|
-
stamp: Date.now(),
|
|
46
|
-
},
|
|
42
|
+
geometry: Object.assign(Object.assign({}, state.geometry), { cache: geometryCache, stamp: Date.now() }),
|
|
47
43
|
};
|
|
48
44
|
});
|
|
49
45
|
}
|
|
@@ -52,47 +48,39 @@ export const geometryApi = (set, get) => ({
|
|
|
52
48
|
},
|
|
53
49
|
setColor: (containerId, r, g, b) => {
|
|
54
50
|
const thCol = new THREE.Color(r, g, b);
|
|
55
|
-
const cachedGeom = {
|
|
51
|
+
const cachedGeom = Object.assign({}, get().geometry.cache[containerId]);
|
|
56
52
|
cachedGeom.color = thCol;
|
|
57
53
|
cachedGeom.meshes.forEach(mesh => (mesh.color = thCol));
|
|
58
54
|
set(state => ({
|
|
59
|
-
geometry: {
|
|
60
|
-
...state.geometry,
|
|
61
|
-
cache: { ...state.geometry.cache, [containerId]: cachedGeom },
|
|
62
|
-
stamp: Date.now(),
|
|
63
|
-
},
|
|
55
|
+
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: cachedGeom }), stamp: Date.now() }),
|
|
64
56
|
}));
|
|
65
57
|
},
|
|
66
58
|
setOpacity: (containerId, opacity) => {
|
|
67
|
-
const cachedGeom = {
|
|
59
|
+
const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
|
|
68
60
|
cachedGeom.meshes.forEach(mesh => (mesh.opacity = opacity));
|
|
69
61
|
set(state => ({
|
|
70
|
-
geometry: {
|
|
71
|
-
...state.geometry,
|
|
72
|
-
cache: { ...state.geometry.cache, [containerId]: cachedGeom },
|
|
73
|
-
stamp: Date.now(),
|
|
74
|
-
},
|
|
62
|
+
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: cachedGeom }), stamp: Date.now() }),
|
|
75
63
|
}));
|
|
76
64
|
},
|
|
77
65
|
setConfig: (objId, config) => {
|
|
78
66
|
set(state => {
|
|
79
|
-
const productConfigs = {
|
|
67
|
+
const productConfigs = Object.assign({}, state.geometry.config.product);
|
|
80
68
|
if (config) {
|
|
81
|
-
const newConfig = {
|
|
69
|
+
const newConfig = Object.assign({}, state.geometry.config.product[objId]);
|
|
82
70
|
if ('disabled' in config)
|
|
83
71
|
newConfig.disabled = config.disabled;
|
|
84
72
|
if ('edges' in config)
|
|
85
|
-
newConfig.edges = {
|
|
73
|
+
newConfig.edges = Object.assign(Object.assign({}, newConfig.edges), config.edges);
|
|
86
74
|
if ('meshes' in config)
|
|
87
|
-
newConfig.meshes = {
|
|
75
|
+
newConfig.meshes = Object.assign(Object.assign({}, newConfig.meshes), config.meshes);
|
|
88
76
|
if ('points' in config)
|
|
89
|
-
newConfig.points = {
|
|
77
|
+
newConfig.points = Object.assign(Object.assign({}, newConfig.points), config.points);
|
|
90
78
|
productConfigs[objId] = newConfig;
|
|
91
79
|
}
|
|
92
80
|
else {
|
|
93
81
|
delete productConfigs[objId];
|
|
94
82
|
}
|
|
95
|
-
return { geometry: {
|
|
83
|
+
return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
|
|
96
84
|
});
|
|
97
85
|
},
|
|
98
86
|
});
|
|
@@ -11,7 +11,7 @@ export const graphicApi = (set, get) => ({
|
|
|
11
11
|
addPackages: (packages) => {
|
|
12
12
|
// Timing.dump('load', `add graphic packages ${graphic.length} ${graphic[0].containers.length}`)
|
|
13
13
|
let cacheChanged = false;
|
|
14
|
-
const newChache = {
|
|
14
|
+
const newChache = Object.assign({}, get().geometry.cache);
|
|
15
15
|
const addedContainers = {};
|
|
16
16
|
packages.forEach(gr => {
|
|
17
17
|
gr.containers.forEach(cont => {
|
|
@@ -25,8 +25,8 @@ export const graphicApi = (set, get) => ({
|
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
27
|
set(state => ({
|
|
28
|
-
graphic: {
|
|
29
|
-
geometry: cacheChanged ? {
|
|
28
|
+
graphic: Object.assign(Object.assign({}, state.graphic), { containers: Object.assign(Object.assign({}, state.graphic.containers), addedContainers) }),
|
|
29
|
+
geometry: cacheChanged ? Object.assign(Object.assign({}, state.geometry), { cache: newChache, stamp: Date.now() }) : state.geometry,
|
|
30
30
|
}));
|
|
31
31
|
const { graphic, api } = get();
|
|
32
32
|
/**
|
|
@@ -62,7 +62,7 @@ export const graphicApi = (set, get) => ({
|
|
|
62
62
|
usedContainers[contId] = existingContainers[contId];
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
set({ graphic: {
|
|
65
|
+
set({ graphic: Object.assign(Object.assign({}, graphic), { containers: usedContainers }) });
|
|
66
66
|
// console.log('graphicContainers after cleanup:', Object.getOwnPropertyNames(get().graphic.ontainers))
|
|
67
67
|
}
|
|
68
68
|
// cleanup the cached geometry depending on the uses solids
|
|
@@ -76,7 +76,7 @@ export const graphicApi = (set, get) => ({
|
|
|
76
76
|
usedGeometry[contId] = existingGeometry[contId];
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
|
-
set({ geometry: {
|
|
79
|
+
set({ geometry: Object.assign(Object.assign({}, geometry), { cache: usedGeometry, stamp: Date.now() }) });
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
});
|
|
@@ -11,11 +11,11 @@ const messageApi = (set, get, api) => ({
|
|
|
11
11
|
show(message) {
|
|
12
12
|
const newId = uuidv4();
|
|
13
13
|
const msg = get().message;
|
|
14
|
-
set({ message: {
|
|
14
|
+
set({ message: Object.assign(Object.assign({}, msg), { data: Object.assign({ id: newId }, message), timestamp: Date.now() }) });
|
|
15
15
|
return newId;
|
|
16
16
|
},
|
|
17
17
|
update(id, message) {
|
|
18
18
|
const msg = get().message;
|
|
19
|
-
set({ message: {
|
|
19
|
+
set({ message: Object.assign(Object.assign({}, msg), { data: Object.assign({ id }, message), timestamp: Date.now() }) });
|
|
20
20
|
},
|
|
21
21
|
});
|
|
@@ -17,17 +17,11 @@ export const pluginApi = (set, get) => ({
|
|
|
17
17
|
if (oldPlugin && state.plugin.active.feature !== id && !oldPlugin.persistent && id !== null) {
|
|
18
18
|
// Reset plugin-state when the plugin is re-activated, not persistent and has not been active all along
|
|
19
19
|
const initState = oldPlugin.initialState || {};
|
|
20
|
-
plugins = {
|
|
21
|
-
...plugins,
|
|
22
|
-
[oldPlugin.id]: {
|
|
23
|
-
...oldPlugin,
|
|
24
|
-
state: typeof initState === 'function' ? initState(get().id, id) : initState,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
20
|
+
plugins = Object.assign(Object.assign({}, plugins), { [oldPlugin.id]: Object.assign(Object.assign({}, oldPlugin), { state: typeof initState === 'function' ? initState(get().id, id) : initState }) });
|
|
27
21
|
}
|
|
28
22
|
return {
|
|
29
|
-
plugin: {
|
|
30
|
-
selection: {
|
|
23
|
+
plugin: Object.assign(Object.assign({}, state.plugin), { active: Object.assign(Object.assign({}, state.plugin.active), { feature: id }), refs: plugins }),
|
|
24
|
+
selection: Object.assign(Object.assign({}, state.selection), { active: null }),
|
|
31
25
|
};
|
|
32
26
|
});
|
|
33
27
|
},
|
|
@@ -37,10 +31,7 @@ export const pluginApi = (set, get) => ({
|
|
|
37
31
|
if (visible)
|
|
38
32
|
filtered.push(id);
|
|
39
33
|
return {
|
|
40
|
-
plugin: {
|
|
41
|
-
...currentState.plugin,
|
|
42
|
-
visible: filtered,
|
|
43
|
-
},
|
|
34
|
+
plugin: Object.assign(Object.assign({}, currentState.plugin), { visible: filtered }),
|
|
44
35
|
};
|
|
45
36
|
});
|
|
46
37
|
},
|
|
@@ -54,13 +45,7 @@ export const pluginApi = (set, get) => ({
|
|
|
54
45
|
if (active)
|
|
55
46
|
filtered.push(id);
|
|
56
47
|
return {
|
|
57
|
-
plugin: {
|
|
58
|
-
...currentState.plugin,
|
|
59
|
-
active: {
|
|
60
|
-
...currentState.plugin.active,
|
|
61
|
-
global: filtered,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
48
|
+
plugin: Object.assign(Object.assign({}, currentState.plugin), { active: Object.assign(Object.assign({}, currentState.plugin.active), { global: filtered }) }),
|
|
64
49
|
};
|
|
65
50
|
});
|
|
66
51
|
},
|
|
@@ -72,42 +57,21 @@ export const pluginApi = (set, get) => ({
|
|
|
72
57
|
const initialState = description.initialState || {};
|
|
73
58
|
const localState = typeof initialState === 'function' ? initialState(drawingId, objectId) : initialState;
|
|
74
59
|
set(currentState => {
|
|
75
|
-
const newPlugin = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
drawingId,
|
|
79
|
-
objectId,
|
|
80
|
-
state: localState,
|
|
81
|
-
Root,
|
|
82
|
-
View,
|
|
83
|
-
set: (sel) => {
|
|
60
|
+
const newPlugin = Object.assign(Object.assign({ id }, description), { drawingId,
|
|
61
|
+
objectId, state: localState, Root,
|
|
62
|
+
View, set: (sel) => {
|
|
84
63
|
// set function can be called when drawing doesn't exist anymore, in this case nothing should be done.
|
|
85
64
|
if (get() === undefined)
|
|
86
65
|
return;
|
|
87
66
|
set(state => {
|
|
88
67
|
const newState = typeof sel === 'function' ? sel(state.plugin.refs[id].state) : sel;
|
|
89
68
|
return {
|
|
90
|
-
plugin: {
|
|
91
|
-
...state.plugin,
|
|
92
|
-
refs: {
|
|
93
|
-
...state.plugin.refs,
|
|
94
|
-
[id]: {
|
|
95
|
-
...state.plugin.refs[id],
|
|
96
|
-
state: { ...state.plugin.refs[id].state, ...newState },
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
69
|
+
plugin: Object.assign(Object.assign({}, state.plugin), { refs: Object.assign(Object.assign({}, state.plugin.refs), { [id]: Object.assign(Object.assign({}, state.plugin.refs[id]), { state: Object.assign(Object.assign({}, state.plugin.refs[id].state), newState) }) }) }),
|
|
100
70
|
};
|
|
101
71
|
});
|
|
102
|
-
}
|
|
103
|
-
};
|
|
72
|
+
} });
|
|
104
73
|
return {
|
|
105
|
-
plugin: {
|
|
106
|
-
...currentState.plugin,
|
|
107
|
-
feature: description.global ? currentState.plugin.feature : [...currentState.plugin.feature, id],
|
|
108
|
-
global: description.global ? [...currentState.plugin.global, id] : currentState.plugin.global,
|
|
109
|
-
refs: { ...currentState.plugin.refs, [id]: { ...currentState.plugin.refs[id], ...newPlugin } },
|
|
110
|
-
},
|
|
74
|
+
plugin: Object.assign(Object.assign({}, currentState.plugin), { feature: description.global ? currentState.plugin.feature : [...currentState.plugin.feature, id], global: description.global ? [...currentState.plugin.global, id] : currentState.plugin.global, refs: Object.assign(Object.assign({}, currentState.plugin.refs), { [id]: Object.assign(Object.assign({}, currentState.plugin.refs[id]), newPlugin) }) }),
|
|
111
75
|
};
|
|
112
76
|
});
|
|
113
77
|
}
|
|
@@ -129,19 +93,10 @@ export const pluginApi = (set, get) => ({
|
|
|
129
93
|
get &&
|
|
130
94
|
get() &&
|
|
131
95
|
set(state => {
|
|
132
|
-
const newPlugins = {
|
|
96
|
+
const newPlugins = Object.assign({}, state.plugin.refs);
|
|
133
97
|
delete newPlugins[id];
|
|
134
98
|
return {
|
|
135
|
-
plugin: {
|
|
136
|
-
...state.plugin,
|
|
137
|
-
active: {
|
|
138
|
-
...state.plugin.active,
|
|
139
|
-
feature: deactivate ? null : state.plugin.active.feature,
|
|
140
|
-
},
|
|
141
|
-
feature: state.plugin.feature.filter(pluginId => pluginId !== id),
|
|
142
|
-
global: state.plugin.global.filter(pluginId => pluginId !== id),
|
|
143
|
-
refs: newPlugins,
|
|
144
|
-
},
|
|
99
|
+
plugin: Object.assign(Object.assign({}, state.plugin), { active: Object.assign(Object.assign({}, state.plugin.active), { feature: deactivate ? null : state.plugin.active.feature }), feature: state.plugin.feature.filter(pluginId => pluginId !== id), global: state.plugin.global.filter(pluginId => pluginId !== id), refs: newPlugins }),
|
|
145
100
|
};
|
|
146
101
|
});
|
|
147
102
|
};
|
|
@@ -17,10 +17,7 @@ export const selectionApi = (set, get) => ({
|
|
|
17
17
|
set(state => {
|
|
18
18
|
const selector = state.selection.refs[activeSelector];
|
|
19
19
|
return {
|
|
20
|
-
selection: {
|
|
21
|
-
...state.selection,
|
|
22
|
-
refs: { ...state.selection.refs, [activeSelector]: { ...selector, items: [] } },
|
|
23
|
-
},
|
|
20
|
+
selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [activeSelector]: Object.assign(Object.assign({}, selector), { items: [] }) }) }),
|
|
24
21
|
};
|
|
25
22
|
});
|
|
26
23
|
}
|
|
@@ -43,16 +40,7 @@ export const selectionApi = (set, get) => ({
|
|
|
43
40
|
else {
|
|
44
41
|
set(state => {
|
|
45
42
|
return {
|
|
46
|
-
selection: {
|
|
47
|
-
...state.selection,
|
|
48
|
-
refs: {
|
|
49
|
-
...state.selection.refs,
|
|
50
|
-
[activeSelectorId]: {
|
|
51
|
-
...state.selection.refs[activeSelectorId],
|
|
52
|
-
items: newItems,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
43
|
+
selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [activeSelectorId]: Object.assign(Object.assign({}, state.selection.refs[activeSelectorId]), { items: newItems }) }) }),
|
|
56
44
|
};
|
|
57
45
|
});
|
|
58
46
|
}
|
|
@@ -105,10 +93,7 @@ export const selectionApi = (set, get) => ({
|
|
|
105
93
|
unsubscribeItems(drawingId, activeSelectorId, unsubItems);
|
|
106
94
|
set(state => {
|
|
107
95
|
return {
|
|
108
|
-
selection: {
|
|
109
|
-
...state.selection,
|
|
110
|
-
refs: { ...state.selection.refs, [activeSelectorId]: { ...selector, items: result } },
|
|
111
|
-
},
|
|
96
|
+
selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [activeSelectorId]: Object.assign(Object.assign({}, selector), { items: result }) }) }),
|
|
112
97
|
};
|
|
113
98
|
});
|
|
114
99
|
}
|
|
@@ -121,16 +106,7 @@ export const selectionApi = (set, get) => ({
|
|
|
121
106
|
return;
|
|
122
107
|
const selId = selection.active || selectorId;
|
|
123
108
|
set(state => ({
|
|
124
|
-
selection: {
|
|
125
|
-
...state.selection,
|
|
126
|
-
refs: {
|
|
127
|
-
...state.selection.refs,
|
|
128
|
-
[selId]: {
|
|
129
|
-
...state.selection.refs[selId],
|
|
130
|
-
hoveredItem: item,
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
},
|
|
109
|
+
selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [selId]: Object.assign(Object.assign({}, state.selection.refs[selId]), { hoveredItem: item }) }) }),
|
|
134
110
|
}));
|
|
135
111
|
},
|
|
136
112
|
activateSelector(selectorId) {
|
|
@@ -139,19 +115,10 @@ export const selectionApi = (set, get) => ({
|
|
|
139
115
|
const curSelectorId = state.selection.active;
|
|
140
116
|
if (curSelectorId) {
|
|
141
117
|
// Reset hoveredItem
|
|
142
|
-
refs[curSelectorId] = {
|
|
143
|
-
...refs[curSelectorId],
|
|
144
|
-
hoveredItem: null,
|
|
145
|
-
};
|
|
118
|
+
refs[curSelectorId] = Object.assign(Object.assign({}, refs[curSelectorId]), { hoveredItem: null });
|
|
146
119
|
}
|
|
147
120
|
return {
|
|
148
|
-
selection: {
|
|
149
|
-
...state.selection,
|
|
150
|
-
active: state.selection.active === selectorId ? null : selectorId,
|
|
151
|
-
refs: {
|
|
152
|
-
...refs,
|
|
153
|
-
},
|
|
154
|
-
},
|
|
121
|
+
selection: Object.assign(Object.assign({}, state.selection), { active: state.selection.active === selectorId ? null : selectorId, refs: Object.assign({}, refs) }),
|
|
155
122
|
};
|
|
156
123
|
});
|
|
157
124
|
},
|
|
@@ -159,21 +126,14 @@ export const selectionApi = (set, get) => ({
|
|
|
159
126
|
if (maxLen > 0 && initialItems.length > maxLen)
|
|
160
127
|
console.error('Number initialItems should be less or equal to selector.maxLen');
|
|
161
128
|
set(state => ({
|
|
162
|
-
selection: {
|
|
163
|
-
...state.selection,
|
|
164
|
-
active: activate ? selectorId : state.selection.active,
|
|
165
|
-
refs: {
|
|
166
|
-
...state.selection.refs,
|
|
167
|
-
[selectorId]: {
|
|
129
|
+
selection: Object.assign(Object.assign({}, state.selection), { active: activate ? selectorId : state.selection.active, refs: Object.assign(Object.assign({}, state.selection.refs), { [selectorId]: {
|
|
168
130
|
items: maxLen > 0 && initialItems.length > maxLen ? [] : initialItems,
|
|
169
131
|
hoveredItem: null,
|
|
170
132
|
isSelectable: filter,
|
|
171
133
|
maxLen,
|
|
172
134
|
customSelect,
|
|
173
135
|
customUnSelect,
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
},
|
|
136
|
+
} }) }),
|
|
177
137
|
}));
|
|
178
138
|
return () => {
|
|
179
139
|
if (get && get()) {
|
|
@@ -183,11 +143,7 @@ export const selectionApi = (set, get) => ({
|
|
|
183
143
|
const refs = state.selection.refs;
|
|
184
144
|
delete refs[selectorId];
|
|
185
145
|
return {
|
|
186
|
-
selection: {
|
|
187
|
-
...state.selection,
|
|
188
|
-
active: state.selection.active === selectorId ? null : state.selection.active,
|
|
189
|
-
refs,
|
|
190
|
-
},
|
|
146
|
+
selection: Object.assign(Object.assign({}, state.selection), { active: state.selection.active === selectorId ? null : state.selection.active, refs }),
|
|
191
147
|
};
|
|
192
148
|
});
|
|
193
149
|
}
|
|
@@ -217,14 +173,15 @@ export const selectionApi = (set, get) => ({
|
|
|
217
173
|
return Boolean(selector.items.find(i => areItemsEqual(i, item)));
|
|
218
174
|
},
|
|
219
175
|
setItems(id, items) {
|
|
176
|
+
var _a;
|
|
220
177
|
const { selection, id: drawingId } = get();
|
|
221
|
-
const curItems = selection.refs[id]
|
|
178
|
+
const curItems = ((_a = selection.refs[id]) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
222
179
|
unsubscribeItems(drawingId, id, curItems);
|
|
223
180
|
subscribeItems(drawingId, id, items);
|
|
224
181
|
set(state => {
|
|
225
182
|
const selector = state.selection.refs[id];
|
|
226
183
|
return {
|
|
227
|
-
selection: {
|
|
184
|
+
selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [id]: Object.assign(Object.assign({}, selector), { items }) }) }),
|
|
228
185
|
};
|
|
229
186
|
});
|
|
230
187
|
},
|
|
@@ -257,13 +214,7 @@ const createGraphicIdent = (productId, graphicId, type) => {
|
|
|
257
214
|
};
|
|
258
215
|
};
|
|
259
216
|
export const createGraphicItem = (productId, el) => {
|
|
260
|
-
return {
|
|
261
|
-
...createGraphicIdent(productId, el.graphicId, el.type),
|
|
262
|
-
data: {
|
|
263
|
-
...el,
|
|
264
|
-
productId,
|
|
265
|
-
},
|
|
266
|
-
};
|
|
217
|
+
return Object.assign(Object.assign({}, createGraphicIdent(productId, el.graphicId, el.type)), { data: Object.assign(Object.assign({}, el), { productId }) });
|
|
267
218
|
};
|
|
268
219
|
//#endregion GLOBAL FUNCTIONS
|
|
269
220
|
////////////////////////////////////////////////////
|
|
@@ -6,7 +6,7 @@ import { MathUtils } from '../../utils/Math';
|
|
|
6
6
|
// DATA
|
|
7
7
|
////////////////////////////////////////////////////
|
|
8
8
|
export const structureData = () => {
|
|
9
|
-
return {
|
|
9
|
+
return Object.assign(Object.assign({}, DEFAULT_STRUCTURE_TREE()), { visibleContainers: [], products: [] });
|
|
10
10
|
};
|
|
11
11
|
////////////////////////////////////////////////////
|
|
12
12
|
// API
|
|
@@ -20,10 +20,7 @@ export const structureApi = (set, get) => ({
|
|
|
20
20
|
// TODO: clear object selection if needed
|
|
21
21
|
// 1. set the state
|
|
22
22
|
set({
|
|
23
|
-
structure: {
|
|
24
|
-
...get().structure,
|
|
25
|
-
...structure,
|
|
26
|
-
},
|
|
23
|
+
structure: Object.assign(Object.assign({}, get().structure), structure),
|
|
27
24
|
});
|
|
28
25
|
// 2. collect and cleanup data
|
|
29
26
|
api.graphic.cleanupGraphicRecords();
|
|
@@ -42,10 +39,7 @@ export const structureApi = (set, get) => ({
|
|
|
42
39
|
console.error(e);
|
|
43
40
|
}
|
|
44
41
|
return {
|
|
45
|
-
structure: {
|
|
46
|
-
...get().structure,
|
|
47
|
-
...structure,
|
|
48
|
-
},
|
|
42
|
+
structure: Object.assign(Object.assign({}, get().structure), structure),
|
|
49
43
|
};
|
|
50
44
|
});
|
|
51
45
|
const { api } = get();
|
|
@@ -122,7 +116,7 @@ export const structureApi = (set, get) => ({
|
|
|
122
116
|
// 3. Add the result to the state
|
|
123
117
|
//////////
|
|
124
118
|
set(state => ({
|
|
125
|
-
structure: {
|
|
119
|
+
structure: Object.assign(Object.assign({}, state.structure), { visibleContainers: solidIds, products: productIds }),
|
|
126
120
|
}));
|
|
127
121
|
},
|
|
128
122
|
/**
|
|
@@ -16,9 +16,10 @@ function subscribeItem(drawingId, selectorId, item) {
|
|
|
16
16
|
if (item.removeCondition && !unsubs[getId(selectorId, item.id)]) {
|
|
17
17
|
const selApi = getDrawing(drawingId).api.selection;
|
|
18
18
|
unsubs[getId(selectorId, item.id)] = subscribeToDrawing(drawingId, (d) => item.removeCondition && item.removeCondition(d), (removeCond) => {
|
|
19
|
+
var _a;
|
|
19
20
|
// Unselect item whose removeCondition got true
|
|
20
21
|
if (removeCond) {
|
|
21
|
-
const newItems = getDrawing(drawingId).selection.refs[selectorId]
|
|
22
|
+
const newItems = ((_a = getDrawing(drawingId).selection.refs[selectorId]) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
22
23
|
selApi.setItems(selectorId, newItems.filter(item_ => item_.id !== item.id));
|
|
23
24
|
}
|
|
24
25
|
});
|
|
@@ -18,7 +18,7 @@ export const Measure = {
|
|
|
18
18
|
for (const item of items) {
|
|
19
19
|
const matrix = drawing.api.structure.calculateGlobalTransformation(item.productId);
|
|
20
20
|
const matrix3 = new THREE.Matrix3().setFromMatrix4(matrix);
|
|
21
|
-
const newItem = {
|
|
21
|
+
const newItem = Object.assign({}, item);
|
|
22
22
|
switch (newItem.type) {
|
|
23
23
|
case GraphicType.POINT:
|
|
24
24
|
const point = newItem;
|
|
@@ -9,7 +9,7 @@ const measure = (key, mode = 'fromStart') => {
|
|
|
9
9
|
return Number.NaN;
|
|
10
10
|
const curr = performance.now();
|
|
11
11
|
const prev = mode === 'fromPrevious' ? cache[key].previousTime : cache[key].startTime;
|
|
12
|
-
cache[key] = {
|
|
12
|
+
cache[key] = Object.assign(Object.assign({}, cache[key]), { previousTime: curr });
|
|
13
13
|
return curr - prev;
|
|
14
14
|
};
|
|
15
15
|
const stop = (key) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buerli.io/core",
|
|
3
|
-
"version": "0.0.35-beta.
|
|
3
|
+
"version": "0.0.35-beta.1",
|
|
4
4
|
"description": "buerli state management",
|
|
5
5
|
"author": "AWV Informatik AG <info@awv-informatik.ch>",
|
|
6
6
|
"repository": {},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"clean": "rimraf ./build && rimraf ./coverage",
|
|
15
15
|
"build": "npm run build:esm -- --sourceMap true --declaration true --declarationDir ./build/types",
|
|
16
16
|
"build:dist": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:types && echo DONE",
|
|
17
|
-
"build:esm": "tsc --target
|
|
17
|
+
"build:esm": "tsc --target es2017 --module esNext --declaration false --declarationDir null --sourceMap false --outDir ./build/esm",
|
|
18
18
|
"build:cjs": "tsc --target es2017 --module commonjs --declaration false --declarationDir null --sourceMap false --outDir ./build/cjs",
|
|
19
19
|
"build:types": "tsc --declaration --emitDeclarationOnly --outDir ./build/types",
|
|
20
20
|
"lint": "eslint \"./src/**/*.ts?(x)\"",
|