@buerli.io/core 0.0.35-beta.1 → 0.0.35-beta.2
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/{types/geometry → geometry}/ThreeGeometryCreator.d.ts +0 -0
- package/build/{esm/geometry → geometry}/ThreeGeometryCreator.js +0 -0
- package/build/{types/geometry → geometry}/index.d.ts +0 -0
- package/build/{esm/geometry → geometry}/index.js +0 -0
- package/build/index.d.ts +36 -0
- package/build/{esm/index.js → index.js} +0 -0
- package/build/{types/store → store}/index.d.ts +0 -0
- package/build/{esm/store → store}/index.js +0 -0
- package/build/{types/store → store}/states/buerli.d.ts +0 -0
- package/build/{esm/store → store}/states/buerli.js +0 -0
- package/build/{types/store → store}/states/canvas.d.ts +0 -0
- package/build/{esm/store → store}/states/canvas.js +0 -0
- package/build/{types/store → store}/states/drawing.d.ts +2 -0
- package/build/{esm/store → store}/states/drawing.js +4 -0
- package/build/{types/store → store}/states/geometry.d.ts +0 -0
- package/build/{esm/store → store}/states/geometry.js +0 -0
- package/build/{types/store → store}/states/graphic.d.ts +0 -0
- package/build/{esm/store → store}/states/graphic.js +0 -0
- package/build/{types/store → store}/states/message.d.ts +0 -0
- package/build/{esm/store → store}/states/message.js +0 -0
- package/build/{types/store → store}/states/plugin.d.ts +0 -0
- package/build/{esm/store → store}/states/plugin.js +0 -0
- package/build/{types/store → store}/states/selection.d.ts +0 -0
- package/build/{esm/store → store}/states/selection.js +0 -0
- package/build/{types/store → store}/states/structure.d.ts +0 -0
- package/build/{esm/store → store}/states/structure.js +0 -0
- package/build/{types/store → store}/store.d.ts +0 -0
- package/build/{esm/store → store}/store.js +0 -0
- package/build/{types/store → store}/subscribtion/selection.d.ts +0 -0
- package/build/{esm/store → store}/subscribtion/selection.js +0 -0
- package/build/{types/store → store}/subscribtion/subscribeToDrawing.d.ts +0 -0
- package/build/{esm/store → store}/subscribtion/subscribeToDrawing.js +0 -0
- package/build/types/{types/ErrorTypes.d.ts → ErrorTypes.d.ts} +0 -0
- package/build/{esm/types → types}/ErrorTypes.js +0 -0
- package/build/types/{types/IGraphicPackage.d.ts → IGraphicPackage.d.ts} +0 -0
- package/build/{esm/types → types}/IGraphicPackage.js +0 -0
- package/build/types/{types/IStructurePatch.d.ts → IStructurePatch.d.ts} +0 -0
- package/build/{esm/types → types}/IStructurePatch.js +0 -0
- package/build/types/{types/IStructureTree.d.ts → IStructureTree.d.ts} +0 -0
- package/build/{esm/types → types}/IStructureTree.js +0 -0
- package/build/types/index.d.ts +4 -36
- package/build/{esm/types → types}/index.js +0 -0
- package/build/{types/utils → utils}/Math.d.ts +0 -0
- package/build/{esm/utils → utils}/Math.js +0 -0
- package/build/{types/utils → utils}/Measure.d.ts +0 -0
- package/build/{esm/utils → utils}/Measure.js +0 -0
- package/build/{types/utils → utils}/Timing.d.ts +0 -0
- package/build/{esm/utils → utils}/Timing.js +0 -0
- package/package.json +6 -9
- package/build/cjs/geometry/ThreeGeometryCreator.js +0 -284
- package/build/cjs/geometry/index.js +0 -13
- package/build/cjs/index.js +0 -20
- package/build/cjs/store/index.js +0 -46
- package/build/cjs/store/states/buerli.js +0 -97
- package/build/cjs/store/states/canvas.js +0 -18
- package/build/cjs/store/states/drawing.js +0 -44
- package/build/cjs/store/states/geometry.js +0 -110
- package/build/cjs/store/states/graphic.js +0 -87
- package/build/cjs/store/states/message.js +0 -25
- package/build/cjs/store/states/plugin.js +0 -113
- package/build/cjs/store/states/selection.js +0 -226
- package/build/cjs/store/states/structure.js +0 -203
- package/build/cjs/store/store.js +0 -14
- package/build/cjs/store/subscribtion/selection.js +0 -47
- package/build/cjs/store/subscribtion/subscribeToDrawing.js +0 -9
- package/build/cjs/types/ErrorTypes.js +0 -2
- package/build/cjs/types/IGraphicPackage.js +0 -24
- package/build/cjs/types/IStructurePatch.js +0 -2
- package/build/cjs/types/IStructureTree.js +0 -27
- package/build/cjs/types/index.js +0 -16
- package/build/cjs/utils/Math.js +0 -33
- package/build/cjs/utils/Measure.js +0 -576
- package/build/cjs/utils/Timing.js +0 -34
- package/build/types/types/index.d.ts +0 -4
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createState = void 0;
|
|
4
|
-
const drawing_1 = require("./drawing");
|
|
5
|
-
const message_1 = require("./message");
|
|
6
|
-
const initError = 'Please call the init action before you use the buerli store.';
|
|
7
|
-
const createState = (set, get, api) => (Object.assign({ initDone: false, options: {
|
|
8
|
-
url: '',
|
|
9
|
-
elements: {},
|
|
10
|
-
plugins: {},
|
|
11
|
-
globalPlugins: [],
|
|
12
|
-
theme: {
|
|
13
|
-
primary: '#e36b7c',
|
|
14
|
-
secondary: '#fcc7cb',
|
|
15
|
-
dark: '#54545d',
|
|
16
|
-
highlightedGeom: '#e36b7c',
|
|
17
|
-
hoveredGeom: '#40a9ff',
|
|
18
|
-
},
|
|
19
|
-
config: {
|
|
20
|
-
geometry: {},
|
|
21
|
-
},
|
|
22
|
-
}, drawing: {
|
|
23
|
-
ids: [],
|
|
24
|
-
refs: {},
|
|
25
|
-
active: null,
|
|
26
|
-
}, api: Object.assign(Object.assign({}, generalApi(set, get)), drawingManagementApi(set, get, api)) }, message_1.getInitialMessageState(set, get, api)));
|
|
27
|
-
exports.createState = createState;
|
|
28
|
-
const generalApi = (set, get) => ({
|
|
29
|
-
// TODO: rename init to setOptions and remove initDone if everything is ok
|
|
30
|
-
/**
|
|
31
|
-
* This api method initializes state. Considering user can accidentally ommit some important like elements,
|
|
32
|
-
* there is a warning disaplying for these cases.
|
|
33
|
-
*
|
|
34
|
-
* @param options - options which will be set into state.options
|
|
35
|
-
*/
|
|
36
|
-
init(options) {
|
|
37
|
-
set(state => ({ options: Object.assign(Object.assign({}, state.options), options), initDone: true }));
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
const drawingManagementApi = (set, get, api) => ({
|
|
41
|
-
async createDrawing(name) {
|
|
42
|
-
const { initDone, drawing } = get();
|
|
43
|
-
if (!initDone)
|
|
44
|
-
throw new Error(initError);
|
|
45
|
-
const drawingState = drawing_1.createDrawingState(sel => set(state => {
|
|
46
|
-
const newState = typeof sel === 'function' ? sel(state.drawing.refs[drawingState.id]) : sel;
|
|
47
|
-
return {
|
|
48
|
-
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) }) }),
|
|
49
|
-
};
|
|
50
|
-
}), () => get().drawing.refs[drawingState.id], api, drawing.ids.length, name);
|
|
51
|
-
set(state => ({
|
|
52
|
-
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 }),
|
|
53
|
-
}));
|
|
54
|
-
// Initialize global plugins
|
|
55
|
-
get().options.globalPlugins.forEach(def => get().drawing.refs[drawingState.id].api.plugin.createPlugin(def));
|
|
56
|
-
return drawingState;
|
|
57
|
-
},
|
|
58
|
-
removeDrawing(id) {
|
|
59
|
-
const { initDone } = get();
|
|
60
|
-
if (!initDone)
|
|
61
|
-
throw new Error(initError);
|
|
62
|
-
// Note:
|
|
63
|
-
// Since it can lead to unexpected behaviour because of updating everything at once
|
|
64
|
-
// split the state modification into two parts.
|
|
65
|
-
// 1. Reset active drawing
|
|
66
|
-
// 2. Remove drawing from state
|
|
67
|
-
// Give the listeners the possibility to handle the active drawing before it is removed.
|
|
68
|
-
// There was exactly such a situation in buerli-examples, where a cad instance of buerli-headless
|
|
69
|
-
// was destroyed (removes drawing as well) while a components is going to be unmounted, but an
|
|
70
|
-
// other component already binds to the active drawing before it is removed. Yes, it can be handled
|
|
71
|
-
// by the application but it makes sense to pay attention to this behaviour at this place already.
|
|
72
|
-
// 1.
|
|
73
|
-
// Calculate and set the active drawing before removing the drawing from the store.
|
|
74
|
-
set(state => {
|
|
75
|
-
const index = state.drawing.ids.indexOf(id);
|
|
76
|
-
// Pick close by drawing unless another drawing has been active all along
|
|
77
|
-
const active = index >= 0 && state.drawing.active === id
|
|
78
|
-
? state.drawing.ids[index + 1] || state.drawing.ids[index - 1] || null
|
|
79
|
-
: state.drawing.active;
|
|
80
|
-
return { drawing: Object.assign(Object.assign({}, state.drawing), { active }) };
|
|
81
|
-
});
|
|
82
|
-
// 2.
|
|
83
|
-
// Remove drawing from store.
|
|
84
|
-
set(state => {
|
|
85
|
-
const refs = Object.assign({}, state.drawing.refs);
|
|
86
|
-
const ids = state.drawing.ids.filter(d => d !== id);
|
|
87
|
-
delete refs[id];
|
|
88
|
-
return { drawing: Object.assign(Object.assign({}, state.drawing), { refs, ids }) };
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
setActiveDrawing(id) {
|
|
92
|
-
const { initDone, drawing } = get();
|
|
93
|
-
if (!initDone)
|
|
94
|
-
throw new Error(initError);
|
|
95
|
-
set({ drawing: Object.assign(Object.assign({}, drawing), { active: id }) });
|
|
96
|
-
},
|
|
97
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.canvasApi = exports.canvasData = void 0;
|
|
4
|
-
////////////////////////////////////////////////////
|
|
5
|
-
// DATA
|
|
6
|
-
////////////////////////////////////////////////////
|
|
7
|
-
const canvasData = () => ({
|
|
8
|
-
controls: { isInteracting: false, enabled: true },
|
|
9
|
-
});
|
|
10
|
-
exports.canvasData = canvasData;
|
|
11
|
-
////////////////////////////////////////////////////
|
|
12
|
-
// API
|
|
13
|
-
////////////////////////////////////////////////////
|
|
14
|
-
const canvasApi = (set, get) => ({
|
|
15
|
-
setInteraction: (isInteracting) => set(state => ({ canvas: Object.assign(Object.assign({}, state.canvas), { controls: Object.assign(Object.assign({}, state.canvas.controls), { isInteracting }) }) })),
|
|
16
|
-
setControlsEnabled: (enabled) => set(state => ({ canvas: Object.assign(Object.assign({}, state.canvas), { controls: Object.assign(Object.assign({}, state.canvas.controls), { enabled }) }) })),
|
|
17
|
-
});
|
|
18
|
-
exports.canvasApi = canvasApi;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**!
|
|
3
|
-
* The Drawing manages all necessary data that belong to a model.
|
|
4
|
-
*
|
|
5
|
-
* On the one hand these are the structure and graphic data by which the
|
|
6
|
-
* CAD model is defined, on the other hand it administers additional data
|
|
7
|
-
* for the support with the client-sided development.
|
|
8
|
-
*
|
|
9
|
-
* @image /doc/assets/core/drawing.png
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createDrawingState = void 0;
|
|
13
|
-
const uuid_1 = require("uuid");
|
|
14
|
-
const canvas_1 = require("./canvas");
|
|
15
|
-
const geometry_1 = require("./geometry");
|
|
16
|
-
const graphic_1 = require("./graphic");
|
|
17
|
-
const plugin_1 = require("./plugin");
|
|
18
|
-
const selection_1 = require("./selection");
|
|
19
|
-
const structure_1 = require("./structure");
|
|
20
|
-
////////////////////////////////////////////////////
|
|
21
|
-
// DATA
|
|
22
|
-
////////////////////////////////////////////////////
|
|
23
|
-
const createDrawingState = (set, get, api, drawingNumber, name) => {
|
|
24
|
-
const drawingId = uuid_1.v4();
|
|
25
|
-
return {
|
|
26
|
-
structure: structure_1.structureData(),
|
|
27
|
-
selection: selection_1.selectionData(),
|
|
28
|
-
plugin: plugin_1.pluginData(),
|
|
29
|
-
geometry: geometry_1.geometryData(),
|
|
30
|
-
graphic: graphic_1.graphicData(),
|
|
31
|
-
canvas: canvas_1.canvasData(),
|
|
32
|
-
api: {
|
|
33
|
-
structure: structure_1.structureApi(set, get),
|
|
34
|
-
selection: selection_1.selectionApi(set, get),
|
|
35
|
-
plugin: plugin_1.pluginApi(set, get),
|
|
36
|
-
geometry: geometry_1.geometryApi(set, get),
|
|
37
|
-
graphic: graphic_1.graphicApi(set, get),
|
|
38
|
-
canvas: canvas_1.canvasApi(set, get),
|
|
39
|
-
},
|
|
40
|
-
id: drawingId,
|
|
41
|
-
name: name || `Drawing #${drawingNumber}`,
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
exports.createDrawingState = createDrawingState;
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.geometryApi = exports.geometryData = void 0;
|
|
23
|
-
const THREE = __importStar(require("three"));
|
|
24
|
-
const ThreeGeometryCreator_1 = require("../../geometry/ThreeGeometryCreator");
|
|
25
|
-
////////////////////////////////////////////////////
|
|
26
|
-
// DATA
|
|
27
|
-
////////////////////////////////////////////////////
|
|
28
|
-
const geometryData = () => ({
|
|
29
|
-
cache: {},
|
|
30
|
-
stamp: -1,
|
|
31
|
-
bounds: {
|
|
32
|
-
center: new THREE.Vector3(0, 0, 0),
|
|
33
|
-
radius: 200,
|
|
34
|
-
min: new THREE.Vector3(-100, -100, -100),
|
|
35
|
-
max: new THREE.Vector3(100, 100, 100),
|
|
36
|
-
},
|
|
37
|
-
config: { product: {} },
|
|
38
|
-
});
|
|
39
|
-
exports.geometryData = geometryData;
|
|
40
|
-
////////////////////////////////////////////////////
|
|
41
|
-
// API
|
|
42
|
-
////////////////////////////////////////////////////
|
|
43
|
-
const geometryApi = (set, get) => ({
|
|
44
|
-
/**
|
|
45
|
-
* Updates the @see geometry.bounds depending on all products of the model.
|
|
46
|
-
* The update will only happen, if at least one solid of one product is available.
|
|
47
|
-
*/
|
|
48
|
-
updateBounds: () => {
|
|
49
|
-
const { api, structure } = get();
|
|
50
|
-
if (structure.visibleContainers.length > 0) {
|
|
51
|
-
const bb = api.structure.calculateProductBounds(structure.root);
|
|
52
|
-
set(state => ({ geometry: Object.assign(Object.assign({}, state.geometry), { stamp: Date.now(), bounds: bb }) }));
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
createGeometryIfNotCached: (containerId, color) => {
|
|
56
|
-
const { graphic, geometry } = get();
|
|
57
|
-
let geom = geometry.cache[containerId];
|
|
58
|
-
if (!geom) {
|
|
59
|
-
const container = graphic.containers[containerId];
|
|
60
|
-
if (container) {
|
|
61
|
-
geom = new ThreeGeometryCreator_1.ThreeGeometryCreator().createGeometry(container, color);
|
|
62
|
-
set(state => {
|
|
63
|
-
const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: geom });
|
|
64
|
-
return {
|
|
65
|
-
geometry: Object.assign(Object.assign({}, state.geometry), { cache: geometryCache, stamp: Date.now() }),
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return geom;
|
|
71
|
-
},
|
|
72
|
-
setColor: (containerId, r, g, b) => {
|
|
73
|
-
const thCol = new THREE.Color(r, g, b);
|
|
74
|
-
const cachedGeom = Object.assign({}, get().geometry.cache[containerId]);
|
|
75
|
-
cachedGeom.color = thCol;
|
|
76
|
-
cachedGeom.meshes.forEach(mesh => (mesh.color = thCol));
|
|
77
|
-
set(state => ({
|
|
78
|
-
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: cachedGeom }), stamp: Date.now() }),
|
|
79
|
-
}));
|
|
80
|
-
},
|
|
81
|
-
setOpacity: (containerId, opacity) => {
|
|
82
|
-
const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
|
|
83
|
-
cachedGeom.meshes.forEach(mesh => (mesh.opacity = opacity));
|
|
84
|
-
set(state => ({
|
|
85
|
-
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: cachedGeom }), stamp: Date.now() }),
|
|
86
|
-
}));
|
|
87
|
-
},
|
|
88
|
-
setConfig: (objId, config) => {
|
|
89
|
-
set(state => {
|
|
90
|
-
const productConfigs = Object.assign({}, state.geometry.config.product);
|
|
91
|
-
if (config) {
|
|
92
|
-
const newConfig = Object.assign({}, state.geometry.config.product[objId]);
|
|
93
|
-
if ('disabled' in config)
|
|
94
|
-
newConfig.disabled = config.disabled;
|
|
95
|
-
if ('edges' in config)
|
|
96
|
-
newConfig.edges = Object.assign(Object.assign({}, newConfig.edges), config.edges);
|
|
97
|
-
if ('meshes' in config)
|
|
98
|
-
newConfig.meshes = Object.assign(Object.assign({}, newConfig.meshes), config.meshes);
|
|
99
|
-
if ('points' in config)
|
|
100
|
-
newConfig.points = Object.assign(Object.assign({}, newConfig.points), config.points);
|
|
101
|
-
productConfigs[objId] = newConfig;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
delete productConfigs[objId];
|
|
105
|
-
}
|
|
106
|
-
return { geometry: Object.assign(Object.assign({}, state.geometry), { config: Object.assign(Object.assign({}, state.geometry.config), { product: productConfigs }) }) };
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
exports.geometryApi = geometryApi;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.graphicApi = exports.graphicData = void 0;
|
|
4
|
-
////////////////////////////////////////////////////
|
|
5
|
-
// DATA
|
|
6
|
-
////////////////////////////////////////////////////
|
|
7
|
-
const graphicData = () => ({
|
|
8
|
-
containers: {},
|
|
9
|
-
});
|
|
10
|
-
exports.graphicData = graphicData;
|
|
11
|
-
////////////////////////////////////////////////////
|
|
12
|
-
// API
|
|
13
|
-
////////////////////////////////////////////////////
|
|
14
|
-
const graphicApi = (set, get) => ({
|
|
15
|
-
addPackages: (packages) => {
|
|
16
|
-
// Timing.dump('load', `add graphic packages ${graphic.length} ${graphic[0].containers.length}`)
|
|
17
|
-
let cacheChanged = false;
|
|
18
|
-
const newChache = Object.assign({}, get().geometry.cache);
|
|
19
|
-
const addedContainers = {};
|
|
20
|
-
packages.forEach(gr => {
|
|
21
|
-
gr.containers.forEach(cont => {
|
|
22
|
-
addedContainers[cont.id] = cont;
|
|
23
|
-
// If the cached geometry for the added container already exist,
|
|
24
|
-
// it has to be removed from the cache to ensure geometry updates.
|
|
25
|
-
if (newChache[cont.id]) {
|
|
26
|
-
delete newChache[cont.id];
|
|
27
|
-
cacheChanged = true;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
set(state => ({
|
|
32
|
-
graphic: Object.assign(Object.assign({}, state.graphic), { containers: Object.assign(Object.assign({}, state.graphic.containers), addedContainers) }),
|
|
33
|
-
geometry: cacheChanged ? Object.assign(Object.assign({}, state.geometry), { cache: newChache, stamp: Date.now() }) : state.geometry,
|
|
34
|
-
}));
|
|
35
|
-
const { graphic, api } = get();
|
|
36
|
-
/**
|
|
37
|
-
* Update the bounds with the newly added graphic.
|
|
38
|
-
*/
|
|
39
|
-
api.geometry.updateBounds();
|
|
40
|
-
/**
|
|
41
|
-
* Create the geometry for the graphic packages.
|
|
42
|
-
* Only the geometry which does not already exist will be created (@see createGeometryIfNotCached).
|
|
43
|
-
*/
|
|
44
|
-
const containerIds = Object.getOwnPropertyNames(graphic.containers);
|
|
45
|
-
const createGeometry = async () => {
|
|
46
|
-
for (const id of containerIds) {
|
|
47
|
-
api.geometry.createGeometryIfNotCached(id);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
createGeometry().catch();
|
|
51
|
-
// console.log('graphicContainers after add:', Object.getOwnPropertyNames(get().graphic.containers))
|
|
52
|
-
},
|
|
53
|
-
cleanupGraphicRecords: () => {
|
|
54
|
-
const { graphic, geometry, api } = get();
|
|
55
|
-
// collect the used solid ids from the structure tree
|
|
56
|
-
const solidIds = api.structure.collectUsedSolidIds();
|
|
57
|
-
// console.log('solidIds before cleanup:', solidIds)
|
|
58
|
-
// cleanup the graphic containers in the state
|
|
59
|
-
const usedContainers = {};
|
|
60
|
-
const existingContainers = graphic.containers;
|
|
61
|
-
const existingContainerIds = Object.getOwnPropertyNames(existingContainers);
|
|
62
|
-
if (existingContainerIds.length > 0) {
|
|
63
|
-
existingContainerIds.forEach(contIdStr => {
|
|
64
|
-
const contId = Number(contIdStr);
|
|
65
|
-
if (solidIds.indexOf(contId) >= 0) {
|
|
66
|
-
usedContainers[contId] = existingContainers[contId];
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
set({ graphic: Object.assign(Object.assign({}, graphic), { containers: usedContainers }) });
|
|
70
|
-
// console.log('graphicContainers after cleanup:', Object.getOwnPropertyNames(get().graphic.ontainers))
|
|
71
|
-
}
|
|
72
|
-
// cleanup the cached geometry depending on the uses solids
|
|
73
|
-
const usedGeometry = {};
|
|
74
|
-
const existingGeometry = geometry.cache;
|
|
75
|
-
const existingGeometryIds = Object.getOwnPropertyNames(existingGeometry);
|
|
76
|
-
if (existingGeometryIds.length > 0) {
|
|
77
|
-
existingGeometryIds.forEach(contIdStr => {
|
|
78
|
-
const contId = Number(contIdStr);
|
|
79
|
-
if (solidIds.indexOf(contId) >= 0) {
|
|
80
|
-
usedGeometry[contId] = existingGeometry[contId];
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
set({ geometry: Object.assign(Object.assign({}, geometry), { cache: usedGeometry, stamp: Date.now() }) });
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
exports.graphicApi = graphicApi;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInitialMessageState = exports.BuerliMessageScope = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
exports.BuerliMessageScope = 'BuerliMessageScope';
|
|
6
|
-
const getInitialMessageState = (set, get, api) => ({
|
|
7
|
-
message: {
|
|
8
|
-
data: null,
|
|
9
|
-
timestamp: -1,
|
|
10
|
-
api: messageApi(set, get, api),
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
exports.getInitialMessageState = getInitialMessageState;
|
|
14
|
-
const messageApi = (set, get, api) => ({
|
|
15
|
-
show(message) {
|
|
16
|
-
const newId = uuid_1.v4();
|
|
17
|
-
const msg = get().message;
|
|
18
|
-
set({ message: Object.assign(Object.assign({}, msg), { data: Object.assign({ id: newId }, message), timestamp: Date.now() }) });
|
|
19
|
-
return newId;
|
|
20
|
-
},
|
|
21
|
-
update(id, message) {
|
|
22
|
-
const msg = get().message;
|
|
23
|
-
set({ message: Object.assign(Object.assign({}, msg), { data: Object.assign({ id }, message), timestamp: Date.now() }) });
|
|
24
|
-
},
|
|
25
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPromisePlugin = exports.pluginApi = exports.pluginData = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
const pluginData = () => ({
|
|
6
|
-
feature: [],
|
|
7
|
-
global: [],
|
|
8
|
-
refs: {},
|
|
9
|
-
active: {
|
|
10
|
-
feature: null,
|
|
11
|
-
global: [],
|
|
12
|
-
},
|
|
13
|
-
visible: [],
|
|
14
|
-
});
|
|
15
|
-
exports.pluginData = pluginData;
|
|
16
|
-
const pluginApi = (set, get) => ({
|
|
17
|
-
setActiveFeature: (id) => {
|
|
18
|
-
set(state => {
|
|
19
|
-
let plugins = state.plugin.refs;
|
|
20
|
-
const oldPlugin = state.plugin.active.feature !== null && state.plugin.refs[state.plugin.active.feature];
|
|
21
|
-
if (oldPlugin && state.plugin.active.feature !== id && !oldPlugin.persistent && id !== null) {
|
|
22
|
-
// Reset plugin-state when the plugin is re-activated, not persistent and has not been active all along
|
|
23
|
-
const initState = oldPlugin.initialState || {};
|
|
24
|
-
plugins = Object.assign(Object.assign({}, plugins), { [oldPlugin.id]: Object.assign(Object.assign({}, oldPlugin), { state: typeof initState === 'function' ? initState(get().id, id) : initState }) });
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
plugin: Object.assign(Object.assign({}, state.plugin), { active: Object.assign(Object.assign({}, state.plugin.active), { feature: id }), refs: plugins }),
|
|
28
|
-
selection: Object.assign(Object.assign({}, state.selection), { active: null }),
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
setVisiblePlugin: (id, visible) => {
|
|
33
|
-
set(currentState => {
|
|
34
|
-
const filtered = currentState.plugin.visible.filter(p => p !== id);
|
|
35
|
-
if (visible)
|
|
36
|
-
filtered.push(id);
|
|
37
|
-
return {
|
|
38
|
-
plugin: Object.assign(Object.assign({}, currentState.plugin), { visible: filtered }),
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
},
|
|
42
|
-
setActiveGlobal: (id, active) => {
|
|
43
|
-
set(currentState => {
|
|
44
|
-
if (currentState.plugin.global.indexOf(id) === -1) {
|
|
45
|
-
console.warn('Given plugin id does not exist.');
|
|
46
|
-
return currentState;
|
|
47
|
-
}
|
|
48
|
-
const filtered = currentState.plugin.active.global.filter(p => p !== id);
|
|
49
|
-
if (active)
|
|
50
|
-
filtered.push(id);
|
|
51
|
-
return {
|
|
52
|
-
plugin: Object.assign(Object.assign({}, currentState.plugin), { active: Object.assign(Object.assign({}, currentState.plugin.active), { global: filtered }) }),
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
// TODO remove defaultId and useEmbeddedPlugin ?
|
|
57
|
-
createPlugin: (def, defaultId, drawingId, objectId) => {
|
|
58
|
-
const id = defaultId !== void 0 ? defaultId : uuid_1.v4();
|
|
59
|
-
function init(definition) {
|
|
60
|
-
const { description, Root = null, View = null } = definition;
|
|
61
|
-
const initialState = description.initialState || {};
|
|
62
|
-
const localState = typeof initialState === 'function' ? initialState(drawingId, objectId) : initialState;
|
|
63
|
-
set(currentState => {
|
|
64
|
-
const newPlugin = Object.assign(Object.assign({ id }, description), { drawingId,
|
|
65
|
-
objectId, state: localState, Root,
|
|
66
|
-
View, set: (sel) => {
|
|
67
|
-
// set function can be called when drawing doesn't exist anymore, in this case nothing should be done.
|
|
68
|
-
if (get() === undefined)
|
|
69
|
-
return;
|
|
70
|
-
set(state => {
|
|
71
|
-
const newState = typeof sel === 'function' ? sel(state.plugin.refs[id].state) : sel;
|
|
72
|
-
return {
|
|
73
|
-
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) }) }) }),
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
} });
|
|
77
|
-
return {
|
|
78
|
-
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) }) }),
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
// Initialize plugin definition, which may be a promise or an object
|
|
83
|
-
if (isPromisePlugin(def)) {
|
|
84
|
-
// The definition is async, so we create a plugin slot right away and complete it later
|
|
85
|
-
init({
|
|
86
|
-
description: { author: '', name: '', persistent: false, global: false, version: '' },
|
|
87
|
-
Root: null,
|
|
88
|
-
View: null,
|
|
89
|
-
});
|
|
90
|
-
def.then(init).catch();
|
|
91
|
-
}
|
|
92
|
-
else
|
|
93
|
-
init(def);
|
|
94
|
-
// Return unsubscribe
|
|
95
|
-
return (deactivate = true) => {
|
|
96
|
-
// Use 'get' to check if the drawing still exists
|
|
97
|
-
get &&
|
|
98
|
-
get() &&
|
|
99
|
-
set(state => {
|
|
100
|
-
const newPlugins = Object.assign({}, state.plugin.refs);
|
|
101
|
-
delete newPlugins[id];
|
|
102
|
-
return {
|
|
103
|
-
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 }),
|
|
104
|
-
};
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
exports.pluginApi = pluginApi;
|
|
110
|
-
function isPromisePlugin(def) {
|
|
111
|
-
return def.then !== undefined;
|
|
112
|
-
}
|
|
113
|
-
exports.isPromisePlugin = isPromisePlugin;
|