@buerli.io/core 1.0.1 → 1.1.0-beta.8
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,109 +1,109 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
-
export const pluginData = () => ({
|
|
3
|
-
feature: [],
|
|
4
|
-
global: [],
|
|
5
|
-
refs: {},
|
|
6
|
-
active: {
|
|
7
|
-
feature: null,
|
|
8
|
-
global: [],
|
|
9
|
-
},
|
|
10
|
-
visible: [],
|
|
11
|
-
});
|
|
12
|
-
export const pluginApi = (set, get, buerliApi) => ({
|
|
13
|
-
setActiveFeature: (id) => {
|
|
14
|
-
set(state => {
|
|
15
|
-
let plugins = state.plugin.refs;
|
|
16
|
-
const oldPlugin = state.plugin.active.feature !== null && state.plugin.refs[state.plugin.active.feature];
|
|
17
|
-
if (oldPlugin && state.plugin.active.feature !== id && !oldPlugin.persistent && id !== null) {
|
|
18
|
-
// Reset plugin-state when the plugin is re-activated, not persistent and has not been active all along
|
|
19
|
-
const initState = oldPlugin.initialState || {};
|
|
20
|
-
plugins = Object.assign(Object.assign({}, plugins), { [oldPlugin.id]: Object.assign(Object.assign({}, oldPlugin), { state: typeof initState === 'function' ? initState(get().id, id) : initState }) });
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
plugin: Object.assign(Object.assign({}, state.plugin), { active: Object.assign(Object.assign({}, state.plugin.active), { feature: id }), refs: plugins }),
|
|
24
|
-
selection: Object.assign(Object.assign({}, state.selection), { active: null }),
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
setVisiblePlugin: (id, visible) => {
|
|
29
|
-
set(currentState => {
|
|
30
|
-
const filtered = currentState.plugin.visible.filter(p => p !== id);
|
|
31
|
-
if (visible)
|
|
32
|
-
filtered.push(id);
|
|
33
|
-
return {
|
|
34
|
-
plugin: Object.assign(Object.assign({}, currentState.plugin), { visible: filtered }),
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
setActiveGlobal: (id, active) => {
|
|
39
|
-
set(currentState => {
|
|
40
|
-
if (currentState.plugin.global.indexOf(id) === -1) {
|
|
41
|
-
console.warn('Given plugin id does not exist.');
|
|
42
|
-
return currentState;
|
|
43
|
-
}
|
|
44
|
-
const filtered = currentState.plugin.active.global.filter(p => p !== id);
|
|
45
|
-
if (active)
|
|
46
|
-
filtered.push(id);
|
|
47
|
-
return {
|
|
48
|
-
plugin: Object.assign(Object.assign({}, currentState.plugin), { active: Object.assign(Object.assign({}, currentState.plugin.active), { global: filtered }) }),
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
// TODO remove defaultId and useEmbeddedPlugin ?
|
|
53
|
-
createPlugin: (def, defaultId, drawingId, objectId) => {
|
|
54
|
-
const id = defaultId !== void 0 ? defaultId : uuidv4();
|
|
55
|
-
function init(definition) {
|
|
56
|
-
const { description, Root = null, View = null } = definition;
|
|
57
|
-
const initialState = description.initialState || {};
|
|
58
|
-
const localState = typeof initialState === 'function' ? initialState(drawingId, objectId) : initialState;
|
|
59
|
-
set(currentState => {
|
|
60
|
-
const newPlugin = Object.assign(Object.assign({ id }, description), { drawingId,
|
|
61
|
-
objectId, state: localState, Root,
|
|
62
|
-
View, set: (sel) => {
|
|
63
|
-
// set function can be called when drawing doesn't exist anymore, in this case nothing should be done.
|
|
64
|
-
if (get() === undefined)
|
|
65
|
-
return;
|
|
66
|
-
set(state => {
|
|
67
|
-
const newState = typeof sel === 'function' ? sel(state.plugin.refs[id].state) : sel;
|
|
68
|
-
return {
|
|
69
|
-
plugin: Object.assign(Object.assign({}, state.plugin), { refs: Object.assign(Object.assign({}, state.plugin.refs), { [id]: Object.assign(Object.assign({}, state.plugin.refs[id]), { state: Object.assign(Object.assign({}, state.plugin.refs[id].state), newState) }) }) }),
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
} });
|
|
73
|
-
return {
|
|
74
|
-
plugin: Object.assign(Object.assign({}, currentState.plugin), { feature: description.global
|
|
75
|
-
? currentState.plugin.feature
|
|
76
|
-
: [...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) }) }),
|
|
77
|
-
};
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
// Initialize plugin definition, which may be a promise or an object
|
|
81
|
-
if (isPromisePlugin(def)) {
|
|
82
|
-
// The definition is async, so we create a plugin slot right away and complete it later
|
|
83
|
-
init({
|
|
84
|
-
description: { author: '', name: '', persistent: false, global: false, version: '' },
|
|
85
|
-
Root: null,
|
|
86
|
-
View: null,
|
|
87
|
-
});
|
|
88
|
-
def.then(init).catch();
|
|
89
|
-
}
|
|
90
|
-
else
|
|
91
|
-
init(def);
|
|
92
|
-
// Return unsubscribe
|
|
93
|
-
return (deactivate = true) => {
|
|
94
|
-
// Use 'get' to check if the drawing still exists
|
|
95
|
-
get &&
|
|
96
|
-
get() &&
|
|
97
|
-
set(state => {
|
|
98
|
-
const newPlugins = Object.assign({}, state.plugin.refs);
|
|
99
|
-
delete newPlugins[id];
|
|
100
|
-
return {
|
|
101
|
-
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 }),
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
export function isPromisePlugin(def) {
|
|
108
|
-
return def.then !== undefined;
|
|
109
|
-
}
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
export const pluginData = () => ({
|
|
3
|
+
feature: [],
|
|
4
|
+
global: [],
|
|
5
|
+
refs: {},
|
|
6
|
+
active: {
|
|
7
|
+
feature: null,
|
|
8
|
+
global: [],
|
|
9
|
+
},
|
|
10
|
+
visible: [],
|
|
11
|
+
});
|
|
12
|
+
export const pluginApi = (set, get, buerliApi) => ({
|
|
13
|
+
setActiveFeature: (id) => {
|
|
14
|
+
set(state => {
|
|
15
|
+
let plugins = state.plugin.refs;
|
|
16
|
+
const oldPlugin = state.plugin.active.feature !== null && state.plugin.refs[state.plugin.active.feature];
|
|
17
|
+
if (oldPlugin && state.plugin.active.feature !== id && !oldPlugin.persistent && id !== null) {
|
|
18
|
+
// Reset plugin-state when the plugin is re-activated, not persistent and has not been active all along
|
|
19
|
+
const initState = oldPlugin.initialState || {};
|
|
20
|
+
plugins = Object.assign(Object.assign({}, plugins), { [oldPlugin.id]: Object.assign(Object.assign({}, oldPlugin), { state: typeof initState === 'function' ? initState(get().id, id) : initState }) });
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
plugin: Object.assign(Object.assign({}, state.plugin), { active: Object.assign(Object.assign({}, state.plugin.active), { feature: id }), refs: plugins }),
|
|
24
|
+
selection: Object.assign(Object.assign({}, state.selection), { active: null }),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
setVisiblePlugin: (id, visible) => {
|
|
29
|
+
set(currentState => {
|
|
30
|
+
const filtered = currentState.plugin.visible.filter(p => p !== id);
|
|
31
|
+
if (visible)
|
|
32
|
+
filtered.push(id);
|
|
33
|
+
return {
|
|
34
|
+
plugin: Object.assign(Object.assign({}, currentState.plugin), { visible: filtered }),
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
setActiveGlobal: (id, active) => {
|
|
39
|
+
set(currentState => {
|
|
40
|
+
if (currentState.plugin.global.indexOf(id) === -1) {
|
|
41
|
+
console.warn('Given plugin id does not exist.');
|
|
42
|
+
return currentState;
|
|
43
|
+
}
|
|
44
|
+
const filtered = currentState.plugin.active.global.filter(p => p !== id);
|
|
45
|
+
if (active)
|
|
46
|
+
filtered.push(id);
|
|
47
|
+
return {
|
|
48
|
+
plugin: Object.assign(Object.assign({}, currentState.plugin), { active: Object.assign(Object.assign({}, currentState.plugin.active), { global: filtered }) }),
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
// TODO remove defaultId and useEmbeddedPlugin ?
|
|
53
|
+
createPlugin: (def, defaultId, drawingId, objectId) => {
|
|
54
|
+
const id = defaultId !== void 0 ? defaultId : uuidv4();
|
|
55
|
+
function init(definition) {
|
|
56
|
+
const { description, Root = null, View = null } = definition;
|
|
57
|
+
const initialState = description.initialState || {};
|
|
58
|
+
const localState = typeof initialState === 'function' ? initialState(drawingId, objectId) : initialState;
|
|
59
|
+
set(currentState => {
|
|
60
|
+
const newPlugin = Object.assign(Object.assign({ id }, description), { drawingId,
|
|
61
|
+
objectId, state: localState, Root,
|
|
62
|
+
View, set: (sel) => {
|
|
63
|
+
// set function can be called when drawing doesn't exist anymore, in this case nothing should be done.
|
|
64
|
+
if (get() === undefined)
|
|
65
|
+
return;
|
|
66
|
+
set(state => {
|
|
67
|
+
const newState = typeof sel === 'function' ? sel(state.plugin.refs[id].state) : sel;
|
|
68
|
+
return {
|
|
69
|
+
plugin: Object.assign(Object.assign({}, state.plugin), { refs: Object.assign(Object.assign({}, state.plugin.refs), { [id]: Object.assign(Object.assign({}, state.plugin.refs[id]), { state: Object.assign(Object.assign({}, state.plugin.refs[id].state), newState) }) }) }),
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
} });
|
|
73
|
+
return {
|
|
74
|
+
plugin: Object.assign(Object.assign({}, currentState.plugin), { feature: description.global
|
|
75
|
+
? currentState.plugin.feature
|
|
76
|
+
: [...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) }) }),
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// Initialize plugin definition, which may be a promise or an object
|
|
81
|
+
if (isPromisePlugin(def)) {
|
|
82
|
+
// The definition is async, so we create a plugin slot right away and complete it later
|
|
83
|
+
init({
|
|
84
|
+
description: { author: '', name: '', persistent: false, global: false, version: '' },
|
|
85
|
+
Root: null,
|
|
86
|
+
View: null,
|
|
87
|
+
});
|
|
88
|
+
def.then(init).catch();
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
init(def);
|
|
92
|
+
// Return unsubscribe
|
|
93
|
+
return (deactivate = true) => {
|
|
94
|
+
// Use 'get' to check if the drawing still exists
|
|
95
|
+
get &&
|
|
96
|
+
get() &&
|
|
97
|
+
set(state => {
|
|
98
|
+
const newPlugins = Object.assign({}, state.plugin.refs);
|
|
99
|
+
delete newPlugins[id];
|
|
100
|
+
return {
|
|
101
|
+
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 }),
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
export function isPromisePlugin(def) {
|
|
108
|
+
return def.then !== undefined;
|
|
109
|
+
}
|