@buerli.io/core 1.0.1 → 1.1.0-beta.7
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/README.md +19 -19
- package/build/cjs/geometry/ThreeGeometryCreator.js +320 -320
- package/build/cjs/geometry/index.js +17 -17
- package/build/cjs/graphic/filters.js +25 -25
- package/build/cjs/index.js +26 -26
- package/build/cjs/re-export.js +29 -29
- package/build/cjs/store/index.js +41 -37
- package/build/cjs/store/states/buerli.js +98 -98
- package/build/cjs/store/states/cad.js +47 -47
- package/build/cjs/store/states/drawing.js +49 -49
- package/build/cjs/store/states/geometry.js +157 -157
- package/build/cjs/store/states/graphic.js +115 -115
- package/build/cjs/store/states/interaction.js +55 -55
- package/build/cjs/store/states/message.js +32 -25
- package/build/cjs/store/states/plugin.js +115 -115
- package/build/cjs/store/states/selection.js +267 -267
- package/build/cjs/store/states/structure.js +250 -250
- package/build/cjs/store/store.js +9 -9
- package/build/cjs/store/subscribtion/selection.js +49 -49
- package/build/cjs/store/subscribtion/subscribeToDrawing.js +13 -13
- package/build/cjs/types/InteractionInfo.js +11 -11
- package/build/cjs/types/index.js +34 -34
- package/build/cjs/utils/Math.js +91 -91
- package/build/cjs/utils/Measure.js +576 -576
- package/build/cjs/utils/Timing.js +34 -34
- package/build/esm/geometry/ThreeGeometryCreator.js +291 -291
- package/build/esm/geometry/index.js +1 -1
- package/build/esm/graphic/filters.js +12 -12
- package/build/esm/index.js +10 -10
- package/build/esm/re-export.js +23 -23
- package/build/esm/store/index.js +29 -26
- package/build/esm/store/states/buerli.js +92 -92
- package/build/esm/store/states/cad.js +42 -42
- package/build/esm/store/states/drawing.js +45 -45
- package/build/esm/store/states/geometry.js +129 -129
- package/build/esm/store/states/graphic.js +110 -110
- package/build/esm/store/states/interaction.js +50 -50
- package/build/esm/store/states/message.js +28 -21
- package/build/esm/store/states/plugin.js +109 -109
- package/build/esm/store/states/selection.js +261 -261
- package/build/esm/store/states/structure.js +219 -219
- package/build/esm/store/store.js +3 -3
- package/build/esm/store/subscribtion/selection.js +44 -44
- package/build/esm/store/subscribtion/subscribeToDrawing.js +9 -9
- package/build/esm/types/InteractionInfo.js +6 -6
- package/build/esm/types/index.js +16 -16
- package/build/esm/utils/Math.js +65 -65
- package/build/esm/utils/Measure.js +550 -550
- package/build/esm/utils/Timing.js +31 -31
- package/build/types/geometry/ThreeGeometryCreator.d.ts +256 -256
- package/build/types/geometry/index.d.ts +1 -1
- package/build/types/graphic/filters.d.ts +11 -11
- package/build/types/index.d.ts +38 -38
- package/build/types/re-export.d.ts +70 -70
- package/build/types/store/index.d.ts +17 -16
- package/build/types/store/states/buerli.d.ts +41 -41
- package/build/types/store/states/cad.d.ts +56 -56
- package/build/types/store/states/drawing.d.ts +45 -45
- package/build/types/store/states/geometry.d.ts +64 -64
- package/build/types/store/states/graphic.d.ts +21 -21
- package/build/types/store/states/interaction.d.ts +34 -34
- package/build/types/store/states/message.d.ts +32 -30
- package/build/types/store/states/plugin.d.ts +53 -53
- package/build/types/store/states/selection.d.ts +69 -69
- package/build/types/store/states/structure.d.ts +47 -47
- package/build/types/store/store.d.ts +2 -2
- package/build/types/store/subscribtion/selection.d.ts +7 -7
- package/build/types/store/subscribtion/subscribeToDrawing.d.ts +4 -4
- package/build/types/types/InteractionInfo.d.ts +42 -42
- package/build/types/types/index.d.ts +7 -7
- package/build/types/utils/Math.d.ts +21 -21
- package/build/types/utils/Measure.d.ts +64 -64
- package/build/types/utils/Timing.d.ts +8 -8
- package/package.json +2 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { EdgeTypes, GraphicType as GT, MeshTypes } from '../re-export';
|
|
2
|
-
import { BuerliScope } from '../store/states/selection';
|
|
3
|
-
export const lineFilter = (scope, data) => scope === BuerliScope && data === GT.LINE;
|
|
4
|
-
export const edgeFilter = (scope, data) => scope === BuerliScope && EdgeTypes.includes(data);
|
|
5
|
-
export const arcFilter = (scope, data) => scope === BuerliScope && data === GT.ARC;
|
|
6
|
-
export const circleFilter = (scope, data) => scope === BuerliScope && data === GT.CIRCLE;
|
|
7
|
-
export const arcCircleFilter = (scope, data) => scope === BuerliScope && (data === GT.ARC || data === GT.CIRCLE);
|
|
8
|
-
export const pointFilter = (scope, data) => scope === BuerliScope && data === GT.POINT;
|
|
9
|
-
export const meshFilter = (scope, data) => scope === BuerliScope && MeshTypes.includes(data);
|
|
10
|
-
export const planeFilter = (scope, data) => scope === BuerliScope && data === GT.PLANE;
|
|
11
|
-
export const loopFilter = (scope, data) => scope === BuerliScope && data === GT.LOOP;
|
|
12
|
-
export const solidFilter = (scope, data) => scope === BuerliScope && data === GT.BREP;
|
|
1
|
+
import { EdgeTypes, GraphicType as GT, MeshTypes } from '../re-export';
|
|
2
|
+
import { BuerliScope } from '../store/states/selection';
|
|
3
|
+
export const lineFilter = (scope, data) => scope === BuerliScope && data === GT.LINE;
|
|
4
|
+
export const edgeFilter = (scope, data) => scope === BuerliScope && EdgeTypes.includes(data);
|
|
5
|
+
export const arcFilter = (scope, data) => scope === BuerliScope && data === GT.ARC;
|
|
6
|
+
export const circleFilter = (scope, data) => scope === BuerliScope && data === GT.CIRCLE;
|
|
7
|
+
export const arcCircleFilter = (scope, data) => scope === BuerliScope && (data === GT.ARC || data === GT.CIRCLE);
|
|
8
|
+
export const pointFilter = (scope, data) => scope === BuerliScope && data === GT.POINT;
|
|
9
|
+
export const meshFilter = (scope, data) => scope === BuerliScope && MeshTypes.includes(data);
|
|
10
|
+
export const planeFilter = (scope, data) => scope === BuerliScope && data === GT.PLANE;
|
|
11
|
+
export const loopFilter = (scope, data) => scope === BuerliScope && data === GT.LOOP;
|
|
12
|
+
export const solidFilter = (scope, data) => scope === BuerliScope && data === GT.BREP;
|
package/build/esm/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from './store';
|
|
2
|
-
export * from './geometry';
|
|
3
|
-
export * from './types';
|
|
4
|
-
export * from './utils/Math';
|
|
5
|
-
export * from './utils/Measure';
|
|
6
|
-
export * from './utils/Timing';
|
|
7
|
-
export * from './store/subscribtion/subscribeToDrawing';
|
|
8
|
-
export * from './graphic/filters';
|
|
9
|
-
export * from './re-export';
|
|
10
|
-
//#endregion Re-export type definitions
|
|
1
|
+
export * from './store';
|
|
2
|
+
export * from './geometry';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * from './utils/Math';
|
|
5
|
+
export * from './utils/Measure';
|
|
6
|
+
export * from './utils/Timing';
|
|
7
|
+
export * from './store/subscribtion/subscribeToDrawing';
|
|
8
|
+
export * from './graphic/filters';
|
|
9
|
+
export * from './re-export';
|
|
10
|
+
//#endregion Re-export type definitions
|
package/build/esm/re-export.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { ScgClassInheritance, ScgClassType, ScgContainerType, ScgCurveTypes, ScgEdgeTypes, ScgEntityTypes, ScgGraphicType, ScgMemberType, ScgMeshTypes, ScgPointTypes, } from '@classcad/api-js';
|
|
2
|
-
export { BooleanOperationType, ChamferType, DataType, ExtrusionType, FlipType, NOID, OrientationType, ReorientedType, SVGModusType, ViewType, WorkAxisType, WorkCoordSystemType, WorkPlaneType, WorkPointType, } from '@classcad/api-js';
|
|
3
|
-
export {
|
|
4
|
-
/** @deprecated */
|
|
5
|
-
ScgClassType as CCClasses,
|
|
6
|
-
/** @deprecated */
|
|
7
|
-
ScgClassInheritance as classMap,
|
|
8
|
-
/** @deprecated */
|
|
9
|
-
ScgContainerType as ContainerType,
|
|
10
|
-
/** @deprecated */
|
|
11
|
-
ScgCurveTypes as CurveTypes,
|
|
12
|
-
/** @deprecated */
|
|
13
|
-
ScgEdgeTypes as EdgeTypes,
|
|
14
|
-
/** @deprecated */
|
|
15
|
-
ScgEntityTypes as EntityTypes,
|
|
16
|
-
/** @deprecated */
|
|
17
|
-
ScgGraphicType as GraphicType,
|
|
18
|
-
/** @deprecated */
|
|
19
|
-
ScgMemberType as MemberType,
|
|
20
|
-
/** @deprecated */
|
|
21
|
-
ScgMeshTypes as MeshTypes,
|
|
22
|
-
/** @deprecated */
|
|
23
|
-
ScgPointTypes as PointTypes, };
|
|
1
|
+
import { ScgClassInheritance, ScgClassType, ScgContainerType, ScgCurveTypes, ScgEdgeTypes, ScgEntityTypes, ScgGraphicType, ScgMemberType, ScgMeshTypes, ScgPointTypes, } from '@classcad/api-js';
|
|
2
|
+
export { BooleanOperationType, ChamferType, DataType, ExtrusionType, FlipType, NOID, OrientationType, ReorientedType, SVGModusType, ViewType, WorkAxisType, WorkCoordSystemType, WorkPlaneType, WorkPointType, } from '@classcad/api-js';
|
|
3
|
+
export {
|
|
4
|
+
/** @deprecated */
|
|
5
|
+
ScgClassType as CCClasses,
|
|
6
|
+
/** @deprecated */
|
|
7
|
+
ScgClassInheritance as classMap,
|
|
8
|
+
/** @deprecated */
|
|
9
|
+
ScgContainerType as ContainerType,
|
|
10
|
+
/** @deprecated */
|
|
11
|
+
ScgCurveTypes as CurveTypes,
|
|
12
|
+
/** @deprecated */
|
|
13
|
+
ScgEdgeTypes as EdgeTypes,
|
|
14
|
+
/** @deprecated */
|
|
15
|
+
ScgEntityTypes as EntityTypes,
|
|
16
|
+
/** @deprecated */
|
|
17
|
+
ScgGraphicType as GraphicType,
|
|
18
|
+
/** @deprecated */
|
|
19
|
+
ScgMemberType as MemberType,
|
|
20
|
+
/** @deprecated */
|
|
21
|
+
ScgMeshTypes as MeshTypes,
|
|
22
|
+
/** @deprecated */
|
|
23
|
+
ScgPointTypes as PointTypes, };
|
package/build/esm/store/index.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import { api } from './store';
|
|
2
|
-
function getDrawing(id) {
|
|
3
|
-
const { drawing } = api.getState();
|
|
4
|
-
return drawing.refs[id];
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* @returns PluginState or undefined if either drawing or plugin don't exist
|
|
8
|
-
*/
|
|
9
|
-
function getPlugin(drawingId, pluginId) {
|
|
10
|
-
var _a;
|
|
11
|
-
const { drawing } = api.getState();
|
|
12
|
-
return (_a = drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.plugin.refs[pluginId];
|
|
13
|
-
}
|
|
14
|
-
function init(options) {
|
|
15
|
-
api.getState().api.init(options);
|
|
16
|
-
}
|
|
17
|
-
function showMessage(message) {
|
|
18
|
-
return api.getState().message.api.show(message);
|
|
19
|
-
}
|
|
20
|
-
function updateMessage(id, message) {
|
|
21
|
-
api.getState().message.api.update(id, message);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export {
|
|
1
|
+
import { api } from './store';
|
|
2
|
+
function getDrawing(id) {
|
|
3
|
+
const { drawing } = api.getState();
|
|
4
|
+
return drawing.refs[id];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @returns PluginState or undefined if either drawing or plugin don't exist
|
|
8
|
+
*/
|
|
9
|
+
function getPlugin(drawingId, pluginId) {
|
|
10
|
+
var _a;
|
|
11
|
+
const { drawing } = api.getState();
|
|
12
|
+
return (_a = drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.plugin.refs[pluginId];
|
|
13
|
+
}
|
|
14
|
+
function init(options) {
|
|
15
|
+
api.getState().api.init(options);
|
|
16
|
+
}
|
|
17
|
+
function showMessage(message) {
|
|
18
|
+
return api.getState().message.api.show(message);
|
|
19
|
+
}
|
|
20
|
+
function updateMessage(id, message) {
|
|
21
|
+
api.getState().message.api.update(id, message);
|
|
22
|
+
}
|
|
23
|
+
function closeMessage(id) {
|
|
24
|
+
api.getState().message.api.close(id);
|
|
25
|
+
}
|
|
26
|
+
export { BuerliMessageScope } from './states/message';
|
|
27
|
+
export { BuerliScope, createGraphicItem } from './states/selection';
|
|
28
|
+
export { api } from './store';
|
|
29
|
+
export { getDrawing, getPlugin, init, showMessage, updateMessage, closeMessage };
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import { createDrawingState } from './drawing';
|
|
2
|
-
import { getInitialMessageState } from './message';
|
|
3
|
-
const initError = 'Please call the init action before you use the buerli store.';
|
|
4
|
-
export const createState = (set, get, buerliApi) => (Object.assign({ initDone: false, options: {
|
|
5
|
-
elements: {},
|
|
6
|
-
plugins: {},
|
|
7
|
-
globalPlugins: [],
|
|
8
|
-
theme: {
|
|
9
|
-
primary: '#e36b7c',
|
|
10
|
-
secondary: '#fcc7cb',
|
|
11
|
-
dark: '#54545d',
|
|
12
|
-
highlightedGeom: '#e36b7c',
|
|
13
|
-
hoveredGeom: '#40a9ff',
|
|
14
|
-
},
|
|
15
|
-
config: {
|
|
16
|
-
geometry: { points: { hidden: true }, edges: { color: 'black' } },
|
|
17
|
-
},
|
|
18
|
-
}, drawing: {
|
|
19
|
-
ids: [],
|
|
20
|
-
refs: {},
|
|
21
|
-
active: null,
|
|
22
|
-
}, api: Object.assign(Object.assign({}, generalApi(set, get, buerliApi)), drawingManagementApi(set, get, buerliApi)) }, getInitialMessageState(set, get, buerliApi)));
|
|
23
|
-
export const generalApi = set => ({
|
|
24
|
-
// TODO: rename init to setOptions and remove initDone if everything is ok
|
|
25
|
-
/**
|
|
26
|
-
* This api method initializes state. Considering user can accidentally ommit some important like elements,
|
|
27
|
-
* there is a warning disaplying for these cases.
|
|
28
|
-
*
|
|
29
|
-
* @param options - options which will be set into state.options
|
|
30
|
-
*/
|
|
31
|
-
init(options) {
|
|
32
|
-
set(state => ({ options: Object.assign(Object.assign({}, state.options), options), initDone: true }));
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
export const drawingManagementApi = (set, get, buerliApi) => ({
|
|
36
|
-
async createDrawing(name) {
|
|
37
|
-
const { initDone, drawing } = get();
|
|
38
|
-
if (!initDone)
|
|
39
|
-
throw new Error(initError);
|
|
40
|
-
const drawingState = createDrawingState(sel => set(state => {
|
|
41
|
-
const newState = typeof sel === 'function' ? sel(state.drawing.refs[drawingState.id]) : sel;
|
|
42
|
-
return {
|
|
43
|
-
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) }) }),
|
|
44
|
-
};
|
|
45
|
-
}), () => get().drawing.refs[drawingState.id], buerliApi, drawing.ids.length, name);
|
|
46
|
-
set(state => ({
|
|
47
|
-
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 }),
|
|
48
|
-
}));
|
|
49
|
-
// Initialize global plugins
|
|
50
|
-
get().options.globalPlugins.forEach(def => get().drawing.refs[drawingState.id].api.plugin.createPlugin(def));
|
|
51
|
-
return drawingState;
|
|
52
|
-
},
|
|
53
|
-
removeDrawing(id) {
|
|
54
|
-
const { initDone } = get();
|
|
55
|
-
if (!initDone)
|
|
56
|
-
throw new Error(initError);
|
|
57
|
-
// Note:
|
|
58
|
-
// Since it can lead to unexpected behaviour because of updating everything at once
|
|
59
|
-
// split the state modification into two parts.
|
|
60
|
-
// 1. Reset active drawing
|
|
61
|
-
// 2. Remove drawing from state
|
|
62
|
-
// Give the listeners the possibility to handle the active drawing before it is removed.
|
|
63
|
-
// There was exactly such a situation in buerli-examples, where a cad instance of buerli-headless
|
|
64
|
-
// was destroyed (removes drawing as well) while a components is going to be unmounted, but an
|
|
65
|
-
// other component already binds to the active drawing before it is removed. Yes, it can be handled
|
|
66
|
-
// by the application but it makes sense to pay attention to this behaviour at this place already.
|
|
67
|
-
// 1.
|
|
68
|
-
// Calculate and set the active drawing before removing the drawing from the store.
|
|
69
|
-
set(state => {
|
|
70
|
-
const index = state.drawing.ids.indexOf(id);
|
|
71
|
-
// Pick close by drawing unless another drawing has been active all along
|
|
72
|
-
const active = index >= 0 && state.drawing.active === id
|
|
73
|
-
? state.drawing.ids[index + 1] || state.drawing.ids[index - 1] || null
|
|
74
|
-
: state.drawing.active;
|
|
75
|
-
return { drawing: Object.assign(Object.assign({}, state.drawing), { active }) };
|
|
76
|
-
});
|
|
77
|
-
// 2.
|
|
78
|
-
// Remove drawing from store.
|
|
79
|
-
set(state => {
|
|
80
|
-
const refs = Object.assign({}, state.drawing.refs);
|
|
81
|
-
const ids = state.drawing.ids.filter(d => d !== id);
|
|
82
|
-
delete refs[id];
|
|
83
|
-
return { drawing: Object.assign(Object.assign({}, state.drawing), { refs, ids }) };
|
|
84
|
-
});
|
|
85
|
-
},
|
|
86
|
-
setActiveDrawing(id) {
|
|
87
|
-
const { initDone, drawing } = get();
|
|
88
|
-
if (!initDone)
|
|
89
|
-
throw new Error(initError);
|
|
90
|
-
set({ drawing: Object.assign(Object.assign({}, drawing), { active: id }) });
|
|
91
|
-
},
|
|
92
|
-
});
|
|
1
|
+
import { createDrawingState } from './drawing';
|
|
2
|
+
import { getInitialMessageState } from './message';
|
|
3
|
+
const initError = 'Please call the init action before you use the buerli store.';
|
|
4
|
+
export const createState = (set, get, buerliApi) => (Object.assign({ initDone: false, options: {
|
|
5
|
+
elements: {},
|
|
6
|
+
plugins: {},
|
|
7
|
+
globalPlugins: [],
|
|
8
|
+
theme: {
|
|
9
|
+
primary: '#e36b7c',
|
|
10
|
+
secondary: '#fcc7cb',
|
|
11
|
+
dark: '#54545d',
|
|
12
|
+
highlightedGeom: '#e36b7c',
|
|
13
|
+
hoveredGeom: '#40a9ff',
|
|
14
|
+
},
|
|
15
|
+
config: {
|
|
16
|
+
geometry: { points: { hidden: true }, edges: { color: 'black' } },
|
|
17
|
+
},
|
|
18
|
+
}, drawing: {
|
|
19
|
+
ids: [],
|
|
20
|
+
refs: {},
|
|
21
|
+
active: null,
|
|
22
|
+
}, api: Object.assign(Object.assign({}, generalApi(set, get, buerliApi)), drawingManagementApi(set, get, buerliApi)) }, getInitialMessageState(set, get, buerliApi)));
|
|
23
|
+
export const generalApi = set => ({
|
|
24
|
+
// TODO: rename init to setOptions and remove initDone if everything is ok
|
|
25
|
+
/**
|
|
26
|
+
* This api method initializes state. Considering user can accidentally ommit some important like elements,
|
|
27
|
+
* there is a warning disaplying for these cases.
|
|
28
|
+
*
|
|
29
|
+
* @param options - options which will be set into state.options
|
|
30
|
+
*/
|
|
31
|
+
init(options) {
|
|
32
|
+
set(state => ({ options: Object.assign(Object.assign({}, state.options), options), initDone: true }));
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
export const drawingManagementApi = (set, get, buerliApi) => ({
|
|
36
|
+
async createDrawing(name) {
|
|
37
|
+
const { initDone, drawing } = get();
|
|
38
|
+
if (!initDone)
|
|
39
|
+
throw new Error(initError);
|
|
40
|
+
const drawingState = createDrawingState(sel => set(state => {
|
|
41
|
+
const newState = typeof sel === 'function' ? sel(state.drawing.refs[drawingState.id]) : sel;
|
|
42
|
+
return {
|
|
43
|
+
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) }) }),
|
|
44
|
+
};
|
|
45
|
+
}), () => get().drawing.refs[drawingState.id], buerliApi, drawing.ids.length, name);
|
|
46
|
+
set(state => ({
|
|
47
|
+
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 }),
|
|
48
|
+
}));
|
|
49
|
+
// Initialize global plugins
|
|
50
|
+
get().options.globalPlugins.forEach(def => get().drawing.refs[drawingState.id].api.plugin.createPlugin(def));
|
|
51
|
+
return drawingState;
|
|
52
|
+
},
|
|
53
|
+
removeDrawing(id) {
|
|
54
|
+
const { initDone } = get();
|
|
55
|
+
if (!initDone)
|
|
56
|
+
throw new Error(initError);
|
|
57
|
+
// Note:
|
|
58
|
+
// Since it can lead to unexpected behaviour because of updating everything at once
|
|
59
|
+
// split the state modification into two parts.
|
|
60
|
+
// 1. Reset active drawing
|
|
61
|
+
// 2. Remove drawing from state
|
|
62
|
+
// Give the listeners the possibility to handle the active drawing before it is removed.
|
|
63
|
+
// There was exactly such a situation in buerli-examples, where a cad instance of buerli-headless
|
|
64
|
+
// was destroyed (removes drawing as well) while a components is going to be unmounted, but an
|
|
65
|
+
// other component already binds to the active drawing before it is removed. Yes, it can be handled
|
|
66
|
+
// by the application but it makes sense to pay attention to this behaviour at this place already.
|
|
67
|
+
// 1.
|
|
68
|
+
// Calculate and set the active drawing before removing the drawing from the store.
|
|
69
|
+
set(state => {
|
|
70
|
+
const index = state.drawing.ids.indexOf(id);
|
|
71
|
+
// Pick close by drawing unless another drawing has been active all along
|
|
72
|
+
const active = index >= 0 && state.drawing.active === id
|
|
73
|
+
? state.drawing.ids[index + 1] || state.drawing.ids[index - 1] || null
|
|
74
|
+
: state.drawing.active;
|
|
75
|
+
return { drawing: Object.assign(Object.assign({}, state.drawing), { active }) };
|
|
76
|
+
});
|
|
77
|
+
// 2.
|
|
78
|
+
// Remove drawing from store.
|
|
79
|
+
set(state => {
|
|
80
|
+
const refs = Object.assign({}, state.drawing.refs);
|
|
81
|
+
const ids = state.drawing.ids.filter(d => d !== id);
|
|
82
|
+
delete refs[id];
|
|
83
|
+
return { drawing: Object.assign(Object.assign({}, state.drawing), { refs, ids }) };
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
setActiveDrawing(id) {
|
|
87
|
+
const { initDone, drawing } = get();
|
|
88
|
+
if (!initDone)
|
|
89
|
+
throw new Error(initError);
|
|
90
|
+
set({ drawing: Object.assign(Object.assign({}, drawing), { active: id }) });
|
|
91
|
+
},
|
|
92
|
+
});
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { v4 } from 'uuid';
|
|
2
|
-
////////////////////////////////////////////////////
|
|
3
|
-
// DATA
|
|
4
|
-
////////////////////////////////////////////////////
|
|
5
|
-
export const cadData = () => ({
|
|
6
|
-
connection: { active: false, connected: false },
|
|
7
|
-
states: { current: 0, stack: [], captionMap: {} },
|
|
8
|
-
pending: [],
|
|
9
|
-
});
|
|
10
|
-
////////////////////////////////////////////////////
|
|
11
|
-
// API
|
|
12
|
-
////////////////////////////////////////////////////
|
|
13
|
-
export const cadApi = (set, get, buerliApi) => ({
|
|
14
|
-
setStates: (current, stack, captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { current, stack, captionMap }) }) })),
|
|
15
|
-
setCaptionMap: (captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { captionMap }) }) })),
|
|
16
|
-
addPending: (name, options) => {
|
|
17
|
-
const id = v4();
|
|
18
|
-
set(state => ({
|
|
19
|
-
cad: Object.assign(Object.assign({}, state.cad), { pending: [...state.cad.pending, Object.assign(Object.assign({}, options), { id, name, stamp: Date.now() })] }),
|
|
20
|
-
}));
|
|
21
|
-
return id;
|
|
22
|
-
},
|
|
23
|
-
removePending: (id) => {
|
|
24
|
-
const newPending = get().cad.pending.filter(p => p.id !== id);
|
|
25
|
-
set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { pending: newPending }) }));
|
|
26
|
-
},
|
|
27
|
-
setConnected: (connected) => {
|
|
28
|
-
return set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { connection: Object.assign(Object.assign({}, state.cad.connection), { connected }) }) }));
|
|
29
|
-
},
|
|
30
|
-
setActive: (active) => {
|
|
31
|
-
return set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { connection: Object.assign(Object.assign({}, state.cad.connection), { active }) }) }));
|
|
32
|
-
},
|
|
33
|
-
/**
|
|
34
|
-
* Clears the pending requests list.
|
|
35
|
-
*
|
|
36
|
-
* **This method is designed for interal usage only, please do not use it in user code!**
|
|
37
|
-
* **It will be removed in a future release!**
|
|
38
|
-
*/
|
|
39
|
-
clearPending: () => {
|
|
40
|
-
set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { pending: [] }) }));
|
|
41
|
-
},
|
|
42
|
-
});
|
|
1
|
+
import { v4 } from 'uuid';
|
|
2
|
+
////////////////////////////////////////////////////
|
|
3
|
+
// DATA
|
|
4
|
+
////////////////////////////////////////////////////
|
|
5
|
+
export const cadData = () => ({
|
|
6
|
+
connection: { active: false, connected: false },
|
|
7
|
+
states: { current: 0, stack: [], captionMap: {} },
|
|
8
|
+
pending: [],
|
|
9
|
+
});
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
// API
|
|
12
|
+
////////////////////////////////////////////////////
|
|
13
|
+
export const cadApi = (set, get, buerliApi) => ({
|
|
14
|
+
setStates: (current, stack, captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { current, stack, captionMap }) }) })),
|
|
15
|
+
setCaptionMap: (captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { captionMap }) }) })),
|
|
16
|
+
addPending: (name, options) => {
|
|
17
|
+
const id = v4();
|
|
18
|
+
set(state => ({
|
|
19
|
+
cad: Object.assign(Object.assign({}, state.cad), { pending: [...state.cad.pending, Object.assign(Object.assign({}, options), { id, name, stamp: Date.now() })] }),
|
|
20
|
+
}));
|
|
21
|
+
return id;
|
|
22
|
+
},
|
|
23
|
+
removePending: (id) => {
|
|
24
|
+
const newPending = get().cad.pending.filter(p => p.id !== id);
|
|
25
|
+
set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { pending: newPending }) }));
|
|
26
|
+
},
|
|
27
|
+
setConnected: (connected) => {
|
|
28
|
+
return set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { connection: Object.assign(Object.assign({}, state.cad.connection), { connected }) }) }));
|
|
29
|
+
},
|
|
30
|
+
setActive: (active) => {
|
|
31
|
+
return set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { connection: Object.assign(Object.assign({}, state.cad.connection), { active }) }) }));
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Clears the pending requests list.
|
|
35
|
+
*
|
|
36
|
+
* **This method is designed for interal usage only, please do not use it in user code!**
|
|
37
|
+
* **It will be removed in a future release!**
|
|
38
|
+
*/
|
|
39
|
+
clearPending: () => {
|
|
40
|
+
set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { pending: [] }) }));
|
|
41
|
+
},
|
|
42
|
+
});
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/**!
|
|
2
|
-
* The Drawing manages all necessary data that belong to a model.
|
|
3
|
-
*
|
|
4
|
-
* On the one hand these are the structure and graphic data by which the
|
|
5
|
-
* CAD model is defined, on the other hand it administers additional data
|
|
6
|
-
* for the support with the client-sided development.
|
|
7
|
-
*
|
|
8
|
-
* @image /doc/assets/core/drawing.png
|
|
9
|
-
*/
|
|
10
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
11
|
-
import { cadApi, cadData } from './cad';
|
|
12
|
-
import { geometryApi, geometryData } from './geometry';
|
|
13
|
-
import { graphicApi, graphicData } from './graphic';
|
|
14
|
-
import { interactionApi, interactionData } from './interaction';
|
|
15
|
-
import { pluginApi, pluginData } from './plugin';
|
|
16
|
-
import { selectionApi, selectionData } from './selection';
|
|
17
|
-
import { structureApi, structureData } from './structure';
|
|
18
|
-
////////////////////////////////////////////////////
|
|
19
|
-
// DATA
|
|
20
|
-
////////////////////////////////////////////////////
|
|
21
|
-
export const createDrawingState = (set, get, buerliApi, drawingNumber, name) => {
|
|
22
|
-
const drawingId = uuidv4();
|
|
23
|
-
const initialData = () => ({
|
|
24
|
-
structure: structureData(),
|
|
25
|
-
selection: selectionData(),
|
|
26
|
-
interaction: interactionData(),
|
|
27
|
-
plugin: pluginData(),
|
|
28
|
-
geometry: geometryData(),
|
|
29
|
-
graphic: graphicData(),
|
|
30
|
-
cad: cadData(),
|
|
31
|
-
});
|
|
32
|
-
return Object.assign(Object.assign({}, initialData()), { api: {
|
|
33
|
-
structure: structureApi(set, get, buerliApi),
|
|
34
|
-
selection: selectionApi(set, get, buerliApi),
|
|
35
|
-
plugin: pluginApi(set, get, buerliApi),
|
|
36
|
-
geometry: geometryApi(set, get, buerliApi),
|
|
37
|
-
graphic: graphicApi(set, get, buerliApi),
|
|
38
|
-
cad: cadApi(set, get, buerliApi),
|
|
39
|
-
interaction: interactionApi(set, get, buerliApi),
|
|
40
|
-
reset: () => {
|
|
41
|
-
set(state => (Object.assign(Object.assign({}, state), initialData())));
|
|
42
|
-
buerliApi.getState().options.globalPlugins.forEach(def => get().api.plugin.createPlugin(def));
|
|
43
|
-
},
|
|
44
|
-
}, id: drawingId, name: name || `Drawing #${drawingNumber}` });
|
|
45
|
-
};
|
|
1
|
+
/**!
|
|
2
|
+
* The Drawing manages all necessary data that belong to a model.
|
|
3
|
+
*
|
|
4
|
+
* On the one hand these are the structure and graphic data by which the
|
|
5
|
+
* CAD model is defined, on the other hand it administers additional data
|
|
6
|
+
* for the support with the client-sided development.
|
|
7
|
+
*
|
|
8
|
+
* @image /doc/assets/core/drawing.png
|
|
9
|
+
*/
|
|
10
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
11
|
+
import { cadApi, cadData } from './cad';
|
|
12
|
+
import { geometryApi, geometryData } from './geometry';
|
|
13
|
+
import { graphicApi, graphicData } from './graphic';
|
|
14
|
+
import { interactionApi, interactionData } from './interaction';
|
|
15
|
+
import { pluginApi, pluginData } from './plugin';
|
|
16
|
+
import { selectionApi, selectionData } from './selection';
|
|
17
|
+
import { structureApi, structureData } from './structure';
|
|
18
|
+
////////////////////////////////////////////////////
|
|
19
|
+
// DATA
|
|
20
|
+
////////////////////////////////////////////////////
|
|
21
|
+
export const createDrawingState = (set, get, buerliApi, drawingNumber, name) => {
|
|
22
|
+
const drawingId = uuidv4();
|
|
23
|
+
const initialData = () => ({
|
|
24
|
+
structure: structureData(),
|
|
25
|
+
selection: selectionData(),
|
|
26
|
+
interaction: interactionData(),
|
|
27
|
+
plugin: pluginData(),
|
|
28
|
+
geometry: geometryData(),
|
|
29
|
+
graphic: graphicData(),
|
|
30
|
+
cad: cadData(),
|
|
31
|
+
});
|
|
32
|
+
return Object.assign(Object.assign({}, initialData()), { api: {
|
|
33
|
+
structure: structureApi(set, get, buerliApi),
|
|
34
|
+
selection: selectionApi(set, get, buerliApi),
|
|
35
|
+
plugin: pluginApi(set, get, buerliApi),
|
|
36
|
+
geometry: geometryApi(set, get, buerliApi),
|
|
37
|
+
graphic: graphicApi(set, get, buerliApi),
|
|
38
|
+
cad: cadApi(set, get, buerliApi),
|
|
39
|
+
interaction: interactionApi(set, get, buerliApi),
|
|
40
|
+
reset: () => {
|
|
41
|
+
set(state => (Object.assign(Object.assign({}, state), initialData())));
|
|
42
|
+
buerliApi.getState().options.globalPlugins.forEach(def => get().api.plugin.createPlugin(def));
|
|
43
|
+
},
|
|
44
|
+
}, id: drawingId, name: name || `Drawing #${drawingNumber}` });
|
|
45
|
+
};
|