@buerli.io/core 0.10.0 → 0.11.0

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/README.md +12 -12
  3. package/build/cjs/geometry/ThreeGeometryCreator.js +320 -320
  4. package/build/cjs/geometry/index.js +17 -17
  5. package/build/cjs/graphic/filters.js +25 -25
  6. package/build/cjs/index.js +25 -25
  7. package/build/cjs/store/index.js +37 -37
  8. package/build/cjs/store/states/buerli.js +98 -98
  9. package/build/cjs/store/states/cad.js +47 -35
  10. package/build/cjs/store/states/drawing.js +49 -49
  11. package/build/cjs/store/states/geometry.js +137 -137
  12. package/build/cjs/store/states/graphic.js +112 -112
  13. package/build/cjs/store/states/interaction.js +55 -55
  14. package/build/cjs/store/states/message.js +25 -25
  15. package/build/cjs/store/states/plugin.js +115 -115
  16. package/build/cjs/store/states/selection.js +267 -267
  17. package/build/cjs/store/states/structure.js +250 -250
  18. package/build/cjs/store/store.js +9 -9
  19. package/build/cjs/store/subscribtion/selection.js +49 -49
  20. package/build/cjs/store/subscribtion/subscribeToDrawing.js +13 -13
  21. package/build/cjs/types/IGraphicPackage.js +46 -46
  22. package/build/cjs/types/IStructurePatch.js +2 -2
  23. package/build/cjs/types/IStructureTree.js +28 -28
  24. package/build/cjs/types/InteractionInfo.js +11 -11
  25. package/build/cjs/types/index.js +20 -20
  26. package/build/cjs/utils/Math.js +91 -91
  27. package/build/cjs/utils/Measure.js +576 -576
  28. package/build/cjs/utils/Timing.js +34 -34
  29. package/build/esm/geometry/ThreeGeometryCreator.js +291 -291
  30. package/build/esm/geometry/index.js +1 -1
  31. package/build/esm/graphic/filters.js +12 -12
  32. package/build/esm/index.js +9 -9
  33. package/build/esm/store/index.js +26 -26
  34. package/build/esm/store/states/buerli.js +92 -92
  35. package/build/esm/store/states/cad.js +42 -30
  36. package/build/esm/store/states/drawing.js +45 -45
  37. package/build/esm/store/states/geometry.js +109 -109
  38. package/build/esm/store/states/graphic.js +107 -107
  39. package/build/esm/store/states/interaction.js +50 -50
  40. package/build/esm/store/states/message.js +21 -21
  41. package/build/esm/store/states/plugin.js +109 -109
  42. package/build/esm/store/states/selection.js +261 -261
  43. package/build/esm/store/states/structure.js +219 -219
  44. package/build/esm/store/store.js +3 -3
  45. package/build/esm/store/subscribtion/selection.js +44 -44
  46. package/build/esm/store/subscribtion/subscribeToDrawing.js +9 -9
  47. package/build/esm/types/IGraphicPackage.js +43 -43
  48. package/build/esm/types/IStructurePatch.js +1 -1
  49. package/build/esm/types/IStructureTree.js +24 -24
  50. package/build/esm/types/InteractionInfo.js +6 -6
  51. package/build/esm/types/index.js +4 -4
  52. package/build/esm/utils/Math.js +65 -65
  53. package/build/esm/utils/Measure.js +550 -550
  54. package/build/esm/utils/Timing.js +31 -31
  55. package/build/types/geometry/ThreeGeometryCreator.d.ts +256 -256
  56. package/build/types/geometry/index.d.ts +1 -1
  57. package/build/types/graphic/filters.d.ts +11 -11
  58. package/build/types/index.d.ts +37 -37
  59. package/build/types/store/index.d.ts +16 -16
  60. package/build/types/store/states/buerli.d.ts +41 -41
  61. package/build/types/store/states/cad.d.ts +53 -42
  62. package/build/types/store/states/drawing.d.ts +45 -45
  63. package/build/types/store/states/geometry.d.ts +63 -63
  64. package/build/types/store/states/graphic.d.ts +22 -22
  65. package/build/types/store/states/interaction.d.ts +34 -34
  66. package/build/types/store/states/message.d.ts +30 -30
  67. package/build/types/store/states/plugin.d.ts +53 -53
  68. package/build/types/store/states/selection.d.ts +62 -62
  69. package/build/types/store/states/structure.d.ts +47 -47
  70. package/build/types/store/store.d.ts +2 -2
  71. package/build/types/store/subscribtion/selection.d.ts +7 -7
  72. package/build/types/store/subscribtion/subscribeToDrawing.d.ts +4 -4
  73. package/build/types/types/IGraphicPackage.d.ts +157 -155
  74. package/build/types/types/IStructurePatch.d.ts +6 -6
  75. package/build/types/types/IStructureTree.d.ts +80 -80
  76. package/build/types/types/InteractionInfo.d.ts +43 -43
  77. package/build/types/types/index.d.ts +4 -4
  78. package/build/types/utils/Math.d.ts +21 -21
  79. package/build/types/utils/Measure.d.ts +64 -64
  80. package/build/types/utils/Timing.d.ts +8 -8
  81. package/package.json +44 -44
@@ -1,17 +1,17 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./ThreeGeometryCreator"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ThreeGeometryCreator"), exports);
@@ -1,25 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.solidFilter = exports.loopFilter = exports.planeFilter = exports.meshFilter = exports.pointFilter = exports.arcCircleFilter = exports.circleFilter = exports.arcFilter = exports.edgeFilter = exports.lineFilter = void 0;
4
- const selection_1 = require("../store/states/selection");
5
- const IGraphicPackage_1 = require("../types/IGraphicPackage");
6
- const lineFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.LINE;
7
- exports.lineFilter = lineFilter;
8
- const edgeFilter = (scope, data) => scope === selection_1.BuerliScope && IGraphicPackage_1.EdgeTypes.includes(data);
9
- exports.edgeFilter = edgeFilter;
10
- const arcFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.ARC;
11
- exports.arcFilter = arcFilter;
12
- const circleFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.CIRCLE;
13
- exports.circleFilter = circleFilter;
14
- const arcCircleFilter = (scope, data) => scope === selection_1.BuerliScope && (data === IGraphicPackage_1.GraphicType.ARC || data === IGraphicPackage_1.GraphicType.CIRCLE);
15
- exports.arcCircleFilter = arcCircleFilter;
16
- const pointFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.POINT;
17
- exports.pointFilter = pointFilter;
18
- const meshFilter = (scope, data) => scope === selection_1.BuerliScope && IGraphicPackage_1.MeshTypes.includes(data);
19
- exports.meshFilter = meshFilter;
20
- const planeFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.PLANE;
21
- exports.planeFilter = planeFilter;
22
- const loopFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.LOOP;
23
- exports.loopFilter = loopFilter;
24
- const solidFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.BREP;
25
- exports.solidFilter = solidFilter;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.solidFilter = exports.loopFilter = exports.planeFilter = exports.meshFilter = exports.pointFilter = exports.arcCircleFilter = exports.circleFilter = exports.arcFilter = exports.edgeFilter = exports.lineFilter = void 0;
4
+ const selection_1 = require("../store/states/selection");
5
+ const IGraphicPackage_1 = require("../types/IGraphicPackage");
6
+ const lineFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.LINE;
7
+ exports.lineFilter = lineFilter;
8
+ const edgeFilter = (scope, data) => scope === selection_1.BuerliScope && IGraphicPackage_1.EdgeTypes.includes(data);
9
+ exports.edgeFilter = edgeFilter;
10
+ const arcFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.ARC;
11
+ exports.arcFilter = arcFilter;
12
+ const circleFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.CIRCLE;
13
+ exports.circleFilter = circleFilter;
14
+ const arcCircleFilter = (scope, data) => scope === selection_1.BuerliScope && (data === IGraphicPackage_1.GraphicType.ARC || data === IGraphicPackage_1.GraphicType.CIRCLE);
15
+ exports.arcCircleFilter = arcCircleFilter;
16
+ const pointFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.POINT;
17
+ exports.pointFilter = pointFilter;
18
+ const meshFilter = (scope, data) => scope === selection_1.BuerliScope && IGraphicPackage_1.MeshTypes.includes(data);
19
+ exports.meshFilter = meshFilter;
20
+ const planeFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.PLANE;
21
+ exports.planeFilter = planeFilter;
22
+ const loopFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.LOOP;
23
+ exports.loopFilter = loopFilter;
24
+ const solidFilter = (scope, data) => scope === selection_1.BuerliScope && data === IGraphicPackage_1.GraphicType.BREP;
25
+ exports.solidFilter = solidFilter;
@@ -1,25 +1,25 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./store"), exports);
18
- __exportStar(require("./geometry"), exports);
19
- __exportStar(require("./types"), exports);
20
- __exportStar(require("./utils/Math"), exports);
21
- __exportStar(require("./utils/Measure"), exports);
22
- __exportStar(require("./utils/Timing"), exports);
23
- __exportStar(require("./store/subscribtion/subscribeToDrawing"), exports);
24
- __exportStar(require("./graphic/filters"), exports);
25
- //#endregion Re-export type definitions
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./store"), exports);
18
+ __exportStar(require("./geometry"), exports);
19
+ __exportStar(require("./types"), exports);
20
+ __exportStar(require("./utils/Math"), exports);
21
+ __exportStar(require("./utils/Measure"), exports);
22
+ __exportStar(require("./utils/Timing"), exports);
23
+ __exportStar(require("./store/subscribtion/subscribeToDrawing"), exports);
24
+ __exportStar(require("./graphic/filters"), exports);
25
+ //#endregion Re-export type definitions
@@ -1,37 +1,37 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateMessage = exports.showMessage = exports.init = exports.getPlugin = exports.getDrawing = exports.api = exports.createGraphicItem = exports.BuerliScope = exports.BuerliMessageScope = void 0;
4
- const store_1 = require("./store");
5
- function getDrawing(id) {
6
- const { drawing } = store_1.api.getState();
7
- return drawing.refs[id];
8
- }
9
- exports.getDrawing = getDrawing;
10
- /**
11
- * @returns PluginState or undefined if either drawing or plugin don't exist
12
- */
13
- function getPlugin(drawingId, pluginId) {
14
- var _a;
15
- const { drawing } = store_1.api.getState();
16
- return (_a = drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.plugin.refs[pluginId];
17
- }
18
- exports.getPlugin = getPlugin;
19
- function init(options) {
20
- store_1.api.getState().api.init(options);
21
- }
22
- exports.init = init;
23
- function showMessage(message) {
24
- return store_1.api.getState().message.api.show(message);
25
- }
26
- exports.showMessage = showMessage;
27
- function updateMessage(id, message) {
28
- store_1.api.getState().message.api.update(id, message);
29
- }
30
- exports.updateMessage = updateMessage;
31
- var message_1 = require("./states/message");
32
- Object.defineProperty(exports, "BuerliMessageScope", { enumerable: true, get: function () { return message_1.BuerliMessageScope; } });
33
- var selection_1 = require("./states/selection");
34
- Object.defineProperty(exports, "BuerliScope", { enumerable: true, get: function () { return selection_1.BuerliScope; } });
35
- Object.defineProperty(exports, "createGraphicItem", { enumerable: true, get: function () { return selection_1.createGraphicItem; } });
36
- var store_2 = require("./store");
37
- Object.defineProperty(exports, "api", { enumerable: true, get: function () { return store_2.api; } });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateMessage = exports.showMessage = exports.init = exports.getPlugin = exports.getDrawing = exports.api = exports.createGraphicItem = exports.BuerliScope = exports.BuerliMessageScope = void 0;
4
+ const store_1 = require("./store");
5
+ function getDrawing(id) {
6
+ const { drawing } = store_1.api.getState();
7
+ return drawing.refs[id];
8
+ }
9
+ exports.getDrawing = getDrawing;
10
+ /**
11
+ * @returns PluginState or undefined if either drawing or plugin don't exist
12
+ */
13
+ function getPlugin(drawingId, pluginId) {
14
+ var _a;
15
+ const { drawing } = store_1.api.getState();
16
+ return (_a = drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.plugin.refs[pluginId];
17
+ }
18
+ exports.getPlugin = getPlugin;
19
+ function init(options) {
20
+ store_1.api.getState().api.init(options);
21
+ }
22
+ exports.init = init;
23
+ function showMessage(message) {
24
+ return store_1.api.getState().message.api.show(message);
25
+ }
26
+ exports.showMessage = showMessage;
27
+ function updateMessage(id, message) {
28
+ store_1.api.getState().message.api.update(id, message);
29
+ }
30
+ exports.updateMessage = updateMessage;
31
+ var message_1 = require("./states/message");
32
+ Object.defineProperty(exports, "BuerliMessageScope", { enumerable: true, get: function () { return message_1.BuerliMessageScope; } });
33
+ var selection_1 = require("./states/selection");
34
+ Object.defineProperty(exports, "BuerliScope", { enumerable: true, get: function () { return selection_1.BuerliScope; } });
35
+ Object.defineProperty(exports, "createGraphicItem", { enumerable: true, get: function () { return selection_1.createGraphicItem; } });
36
+ var store_2 = require("./store");
37
+ Object.defineProperty(exports, "api", { enumerable: true, get: function () { return store_2.api; } });
@@ -1,98 +1,98 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.drawingManagementApi = exports.generalApi = 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, buerliApi) => (Object.assign({ initDone: false, options: {
8
- elements: {},
9
- plugins: {},
10
- globalPlugins: [],
11
- theme: {
12
- primary: '#e36b7c',
13
- secondary: '#fcc7cb',
14
- dark: '#54545d',
15
- highlightedGeom: '#e36b7c',
16
- hoveredGeom: '#40a9ff',
17
- },
18
- config: {
19
- geometry: { points: { hidden: true }, edges: { color: 'black' } },
20
- },
21
- }, drawing: {
22
- ids: [],
23
- refs: {},
24
- active: null,
25
- }, api: Object.assign(Object.assign({}, (0, exports.generalApi)(set, get, buerliApi)), (0, exports.drawingManagementApi)(set, get, buerliApi)) }, (0, message_1.getInitialMessageState)(set, get, buerliApi)));
26
- exports.createState = createState;
27
- const generalApi = set => ({
28
- // TODO: rename init to setOptions and remove initDone if everything is ok
29
- /**
30
- * This api method initializes state. Considering user can accidentally ommit some important like elements,
31
- * there is a warning disaplying for these cases.
32
- *
33
- * @param options - options which will be set into state.options
34
- */
35
- init(options) {
36
- set(state => ({ options: Object.assign(Object.assign({}, state.options), options), initDone: true }));
37
- },
38
- });
39
- exports.generalApi = generalApi;
40
- const drawingManagementApi = (set, get, buerliApi) => ({
41
- async createDrawing(name) {
42
- const { initDone, drawing } = get();
43
- if (!initDone)
44
- throw new Error(initError);
45
- const drawingState = (0, 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], buerliApi, 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
- });
98
- exports.drawingManagementApi = drawingManagementApi;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.drawingManagementApi = exports.generalApi = 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, buerliApi) => (Object.assign({ initDone: false, options: {
8
+ elements: {},
9
+ plugins: {},
10
+ globalPlugins: [],
11
+ theme: {
12
+ primary: '#e36b7c',
13
+ secondary: '#fcc7cb',
14
+ dark: '#54545d',
15
+ highlightedGeom: '#e36b7c',
16
+ hoveredGeom: '#40a9ff',
17
+ },
18
+ config: {
19
+ geometry: { points: { hidden: true }, edges: { color: 'black' } },
20
+ },
21
+ }, drawing: {
22
+ ids: [],
23
+ refs: {},
24
+ active: null,
25
+ }, api: Object.assign(Object.assign({}, (0, exports.generalApi)(set, get, buerliApi)), (0, exports.drawingManagementApi)(set, get, buerliApi)) }, (0, message_1.getInitialMessageState)(set, get, buerliApi)));
26
+ exports.createState = createState;
27
+ const generalApi = set => ({
28
+ // TODO: rename init to setOptions and remove initDone if everything is ok
29
+ /**
30
+ * This api method initializes state. Considering user can accidentally ommit some important like elements,
31
+ * there is a warning disaplying for these cases.
32
+ *
33
+ * @param options - options which will be set into state.options
34
+ */
35
+ init(options) {
36
+ set(state => ({ options: Object.assign(Object.assign({}, state.options), options), initDone: true }));
37
+ },
38
+ });
39
+ exports.generalApi = generalApi;
40
+ const drawingManagementApi = (set, get, buerliApi) => ({
41
+ async createDrawing(name) {
42
+ const { initDone, drawing } = get();
43
+ if (!initDone)
44
+ throw new Error(initError);
45
+ const drawingState = (0, 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], buerliApi, 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
+ });
98
+ exports.drawingManagementApi = drawingManagementApi;
@@ -1,35 +1,47 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cadApi = exports.cadData = void 0;
4
- const uuid_1 = require("uuid");
5
- ////////////////////////////////////////////////////
6
- // DATA
7
- ////////////////////////////////////////////////////
8
- const cadData = () => ({
9
- connected: false,
10
- states: { current: 0, stack: [], captionMap: {} },
11
- pending: [],
12
- });
13
- exports.cadData = cadData;
14
- ////////////////////////////////////////////////////
15
- // API
16
- ////////////////////////////////////////////////////
17
- const cadApi = (set, get, buerliApi) => ({
18
- setStates: (current, stack, captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { current, stack, captionMap }) }) })),
19
- setCaptionMap: (captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { captionMap }) }) })),
20
- addPending: (name, options) => {
21
- const id = (0, uuid_1.v4)();
22
- set(state => ({
23
- cad: Object.assign(Object.assign({}, state.cad), { pending: [...state.cad.pending, Object.assign(Object.assign({}, options), { id, name, stamp: Date.now() })] }),
24
- }));
25
- return id;
26
- },
27
- removePending: (id) => {
28
- const newPending = get().cad.pending.filter(p => p.id !== id);
29
- set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { pending: newPending }) }));
30
- },
31
- setConnected: (connected) => {
32
- return set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { connected }) }));
33
- },
34
- });
35
- exports.cadApi = cadApi;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cadApi = exports.cadData = void 0;
4
+ const uuid_1 = require("uuid");
5
+ ////////////////////////////////////////////////////
6
+ // DATA
7
+ ////////////////////////////////////////////////////
8
+ const cadData = () => ({
9
+ connection: { active: false, connected: false },
10
+ states: { current: 0, stack: [], captionMap: {} },
11
+ pending: [],
12
+ });
13
+ exports.cadData = cadData;
14
+ ////////////////////////////////////////////////////
15
+ // API
16
+ ////////////////////////////////////////////////////
17
+ const cadApi = (set, get, buerliApi) => ({
18
+ setStates: (current, stack, captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { current, stack, captionMap }) }) })),
19
+ setCaptionMap: (captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { captionMap }) }) })),
20
+ addPending: (name, options) => {
21
+ const id = (0, uuid_1.v4)();
22
+ set(state => ({
23
+ cad: Object.assign(Object.assign({}, state.cad), { pending: [...state.cad.pending, Object.assign(Object.assign({}, options), { id, name, stamp: Date.now() })] }),
24
+ }));
25
+ return id;
26
+ },
27
+ removePending: (id) => {
28
+ const newPending = get().cad.pending.filter(p => p.id !== id);
29
+ set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { pending: newPending }) }));
30
+ },
31
+ setConnected: (connected) => {
32
+ return set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { connection: Object.assign(Object.assign({}, state.cad.connection), { connected }) }) }));
33
+ },
34
+ setActive: (active) => {
35
+ return set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { connection: Object.assign(Object.assign({}, state.cad.connection), { active }) }) }));
36
+ },
37
+ /**
38
+ * Clears the pending requests list.
39
+ *
40
+ * **This method is designed for interal usage only, please do not use it in user code!**
41
+ * **It will be removed in a future release!**
42
+ */
43
+ clearPending: () => {
44
+ set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { pending: [] }) }));
45
+ },
46
+ });
47
+ exports.cadApi = cadApi;
@@ -1,49 +1,49 @@
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 cad_1 = require("./cad");
15
- const geometry_1 = require("./geometry");
16
- const graphic_1 = require("./graphic");
17
- const interaction_1 = require("./interaction");
18
- const plugin_1 = require("./plugin");
19
- const selection_1 = require("./selection");
20
- const structure_1 = require("./structure");
21
- ////////////////////////////////////////////////////
22
- // DATA
23
- ////////////////////////////////////////////////////
24
- const createDrawingState = (set, get, buerliApi, drawingNumber, name) => {
25
- const drawingId = (0, uuid_1.v4)();
26
- const initialData = () => ({
27
- structure: (0, structure_1.structureData)(),
28
- selection: (0, selection_1.selectionData)(),
29
- interaction: (0, interaction_1.interactionData)(),
30
- plugin: (0, plugin_1.pluginData)(),
31
- geometry: (0, geometry_1.geometryData)(),
32
- graphic: (0, graphic_1.graphicData)(),
33
- cad: (0, cad_1.cadData)(),
34
- });
35
- return Object.assign(Object.assign({}, initialData()), { api: {
36
- structure: (0, structure_1.structureApi)(set, get, buerliApi),
37
- selection: (0, selection_1.selectionApi)(set, get, buerliApi),
38
- plugin: (0, plugin_1.pluginApi)(set, get, buerliApi),
39
- geometry: (0, geometry_1.geometryApi)(set, get, buerliApi),
40
- graphic: (0, graphic_1.graphicApi)(set, get, buerliApi),
41
- cad: (0, cad_1.cadApi)(set, get, buerliApi),
42
- interaction: (0, interaction_1.interactionApi)(set, get, buerliApi),
43
- reset: () => {
44
- set(state => (Object.assign(Object.assign({}, state), initialData())));
45
- buerliApi.getState().options.globalPlugins.forEach(def => get().api.plugin.createPlugin(def));
46
- },
47
- }, id: drawingId, name: name || `Drawing #${drawingNumber}` });
48
- };
49
- exports.createDrawingState = createDrawingState;
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 cad_1 = require("./cad");
15
+ const geometry_1 = require("./geometry");
16
+ const graphic_1 = require("./graphic");
17
+ const interaction_1 = require("./interaction");
18
+ const plugin_1 = require("./plugin");
19
+ const selection_1 = require("./selection");
20
+ const structure_1 = require("./structure");
21
+ ////////////////////////////////////////////////////
22
+ // DATA
23
+ ////////////////////////////////////////////////////
24
+ const createDrawingState = (set, get, buerliApi, drawingNumber, name) => {
25
+ const drawingId = (0, uuid_1.v4)();
26
+ const initialData = () => ({
27
+ structure: (0, structure_1.structureData)(),
28
+ selection: (0, selection_1.selectionData)(),
29
+ interaction: (0, interaction_1.interactionData)(),
30
+ plugin: (0, plugin_1.pluginData)(),
31
+ geometry: (0, geometry_1.geometryData)(),
32
+ graphic: (0, graphic_1.graphicData)(),
33
+ cad: (0, cad_1.cadData)(),
34
+ });
35
+ return Object.assign(Object.assign({}, initialData()), { api: {
36
+ structure: (0, structure_1.structureApi)(set, get, buerliApi),
37
+ selection: (0, selection_1.selectionApi)(set, get, buerliApi),
38
+ plugin: (0, plugin_1.pluginApi)(set, get, buerliApi),
39
+ geometry: (0, geometry_1.geometryApi)(set, get, buerliApi),
40
+ graphic: (0, graphic_1.graphicApi)(set, get, buerliApi),
41
+ cad: (0, cad_1.cadApi)(set, get, buerliApi),
42
+ interaction: (0, interaction_1.interactionApi)(set, get, buerliApi),
43
+ reset: () => {
44
+ set(state => (Object.assign(Object.assign({}, state), initialData())));
45
+ buerliApi.getState().options.globalPlugins.forEach(def => get().api.plugin.createPlugin(def));
46
+ },
47
+ }, id: drawingId, name: name || `Drawing #${drawingNumber}` });
48
+ };
49
+ exports.createDrawingState = createDrawingState;