@buerli.io/core 0.0.36-beta.0 → 0.1.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.
package/build/index.d.ts CHANGED
@@ -11,8 +11,9 @@ export * from './store/subscribtion/subscribeToDrawing';
11
11
  *
12
12
  * Please have a look at https://github.com/awv-informatik/buerli/pull/129 for more information.
13
13
  */
14
- import { BuerliState as BS } from './store/states/buerli';
14
+ import { BuerliState as BS, BuerliOptions as BO } from './store/states/buerli';
15
15
  export declare type BuerliState = BS;
16
+ export declare type BuerliOptions = BO;
16
17
  import { DrawingAPI as DrawingAPI1, DrawingID as DrawingID1, DrawingState as DrawingState1 } from './store/states/drawing';
17
18
  export declare type DrawingID = DrawingID1;
18
19
  export declare type DrawingState = DrawingState1;
@@ -1,4 +1,4 @@
1
- import { BuerliOptions, BuerliState } from './states/buerli';
1
+ import { BuerliOptions } from './states/buerli';
2
2
  import { DrawingID, DrawingState } from './states/drawing';
3
3
  import { Message, MessageID } from './states/message';
4
4
  import { PluginID, PluginState } from './states/plugin';
@@ -7,10 +7,10 @@ declare function getDrawing(id: DrawingID): DrawingState;
7
7
  * @returns PluginState or undefined if either drawing or plugin don't exist
8
8
  */
9
9
  declare function getPlugin(drawingId: DrawingID, pluginId: PluginID): PluginState;
10
- declare function init(sel?: Partial<BuerliOptions> | ((state: BuerliState) => Partial<BuerliOptions>)): void;
10
+ declare function init(options?: Partial<BuerliOptions>): void;
11
11
  declare function showMessage(message: Message): MessageID;
12
12
  declare function updateMessage(id: MessageID, message: Message): void;
13
13
  export { BuerliMessageScope } from './states/message';
14
14
  export { BuerliScope, createGraphicItem } from './states/selection';
15
- export * from './store';
15
+ export { api } from './store';
16
16
  export { getDrawing, getPlugin, init, showMessage, updateMessage };
@@ -11,8 +11,8 @@ function getPlugin(drawingId, pluginId) {
11
11
  const { drawing } = api.getState();
12
12
  return (_a = drawing.refs[drawingId]) === null || _a === void 0 ? void 0 : _a.plugin.refs[pluginId];
13
13
  }
14
- function init(sel) {
15
- api.getState().api.init(typeof sel === 'function' ? sel(api.getState()) || {} : sel);
14
+ function init(options) {
15
+ api.getState().api.init(options);
16
16
  }
17
17
  function showMessage(message) {
18
18
  return api.getState().message.api.show(message);
@@ -22,5 +22,5 @@ function updateMessage(id, message) {
22
22
  }
23
23
  export { BuerliMessageScope } from './states/message';
24
24
  export { BuerliScope, createGraphicItem } from './states/selection';
25
- export * from './store';
25
+ export { api } from './store';
26
26
  export { getDrawing, getPlugin, init, showMessage, updateMessage };
@@ -1,4 +1,5 @@
1
1
  import { GetState, SetState } from 'zustand';
2
+ import { BuerliStoreApi } from '../../store/store';
2
3
  import { DrawingID, DrawingState } from './drawing';
3
4
  import { GeometryConfig } from './geometry';
4
5
  import { MessageState } from './message';
@@ -13,7 +14,6 @@ declare type StateData = {
13
14
  };
14
15
  } & MessageState;
15
16
  export declare type BuerliOptions = {
16
- url: string;
17
17
  elements: any;
18
18
  plugins: Record<string, PluginImpl>;
19
19
  globalPlugins: PluginDef[];
@@ -32,8 +32,8 @@ declare type StateApi = ReturnType<typeof generalApi> & ReturnType<typeof drawin
32
32
  export declare type BuerliState = Readonly<StateData> & Readonly<{
33
33
  api: StateApi;
34
34
  }>;
35
- export declare const createState: (set: SetState<BuerliState>, get: GetState<BuerliState>, api: any) => BuerliState;
36
- declare const generalApi: (set: SetState<BuerliState>, get: GetState<BuerliState>) => {
35
+ export declare const createState: (set: SetState<BuerliState>, get: GetState<BuerliState>, buerliApi: BuerliStoreApi) => BuerliState;
36
+ declare const generalApi: (set: SetState<BuerliState>, get: GetState<BuerliState>, buerliApi: BuerliStoreApi) => {
37
37
  /**
38
38
  * This api method initializes state. Considering user can accidentally ommit some important like elements,
39
39
  * there is a warning disaplying for these cases.
@@ -42,7 +42,7 @@ declare const generalApi: (set: SetState<BuerliState>, get: GetState<BuerliState
42
42
  */
43
43
  init(options?: Partial<BuerliOptions> | undefined): void;
44
44
  };
45
- declare const drawingManagementApi: (set: SetState<BuerliState>, get: GetState<BuerliState>, api: any) => {
45
+ declare const drawingManagementApi: (set: SetState<BuerliState>, get: GetState<BuerliState>, buerliApi: BuerliStoreApi) => {
46
46
  createDrawing(name?: string | undefined): Promise<DrawingState>;
47
47
  removeDrawing(id: DrawingID): void;
48
48
  setActiveDrawing(id: DrawingID | null): void;
@@ -1,8 +1,7 @@
1
1
  import { createDrawingState } from './drawing';
2
2
  import { getInitialMessageState } from './message';
3
3
  const initError = 'Please call the init action before you use the buerli store.';
4
- export const createState = (set, get, api) => (Object.assign({ initDone: false, options: {
5
- url: '',
4
+ export const createState = (set, get, buerliApi) => (Object.assign({ initDone: false, options: {
6
5
  elements: {},
7
6
  plugins: {},
8
7
  globalPlugins: [],
@@ -20,8 +19,8 @@ export const createState = (set, get, api) => (Object.assign({ initDone: false,
20
19
  ids: [],
21
20
  refs: {},
22
21
  active: null,
23
- }, api: Object.assign(Object.assign({}, generalApi(set, get)), drawingManagementApi(set, get, api)) }, getInitialMessageState(set, get, api)));
24
- const generalApi = (set, get) => ({
22
+ }, api: Object.assign(Object.assign({}, generalApi(set, get, buerliApi)), drawingManagementApi(set, get, buerliApi)) }, getInitialMessageState(set, get, buerliApi)));
23
+ const generalApi = (set, get, buerliApi) => ({
25
24
  // TODO: rename init to setOptions and remove initDone if everything is ok
26
25
  /**
27
26
  * This api method initializes state. Considering user can accidentally ommit some important like elements,
@@ -33,7 +32,7 @@ const generalApi = (set, get) => ({
33
32
  set(state => ({ options: Object.assign(Object.assign({}, state.options), options), initDone: true }));
34
33
  },
35
34
  });
36
- const drawingManagementApi = (set, get, api) => ({
35
+ const drawingManagementApi = (set, get, buerliApi) => ({
37
36
  async createDrawing(name) {
38
37
  const { initDone, drawing } = get();
39
38
  if (!initDone)
@@ -43,7 +42,7 @@ const drawingManagementApi = (set, get, api) => ({
43
42
  return {
44
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) }) }),
45
44
  };
46
- }), () => get().drawing.refs[drawingState.id], api, drawing.ids.length, name);
45
+ }), () => get().drawing.refs[drawingState.id], buerliApi, drawing.ids.length, name);
47
46
  set(state => ({
48
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 }),
49
48
  }));
@@ -0,0 +1,26 @@
1
+ import { GetState, SetState } from 'zustand';
2
+ import { BuerliStoreApi } from '../../store/store';
3
+ import { DrawingState } from './drawing';
4
+ export declare type States = {
5
+ current: number;
6
+ stack: string[];
7
+ captionMap: Record<string, {
8
+ stateName: string;
9
+ caption: string;
10
+ }>;
11
+ };
12
+ export declare type CadData = {
13
+ states: States;
14
+ };
15
+ export declare type CadApi = ReturnType<typeof cadApi>;
16
+ export declare const cadData: () => CadData;
17
+ export declare const cadApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
18
+ setStates: (current: number, stack: string[], captionMap: Record<string, {
19
+ stateName: string;
20
+ caption: string;
21
+ }>) => void;
22
+ setCaptionMap: (captionMap: Record<string, {
23
+ stateName: string;
24
+ caption: string;
25
+ }>) => void;
26
+ };
@@ -0,0 +1,13 @@
1
+ ////////////////////////////////////////////////////
2
+ // DATA
3
+ ////////////////////////////////////////////////////
4
+ export const cadData = () => ({
5
+ states: { current: 0, stack: [], captionMap: {} },
6
+ });
7
+ ////////////////////////////////////////////////////
8
+ // API
9
+ ////////////////////////////////////////////////////
10
+ export const cadApi = (set, get, buerliApi) => ({
11
+ setStates: (current, stack, captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { current, stack, captionMap }) }) })),
12
+ setCaptionMap: (captionMap) => set(state => ({ cad: Object.assign(Object.assign({}, state.cad), { states: Object.assign(Object.assign({}, state.cad.states), { captionMap }) }) })),
13
+ });
@@ -1,4 +1,5 @@
1
1
  import { GetState, SetState } from 'zustand';
2
+ import { BuerliStoreApi } from '../../store/store';
2
3
  import { DrawingState } from './drawing';
3
4
  declare type Controls = {
4
5
  isInteracting: boolean;
@@ -9,7 +10,7 @@ export declare type CanvasData = {
9
10
  };
10
11
  export declare type CanvasApi = ReturnType<typeof canvasApi>;
11
12
  export declare const canvasData: () => CanvasData;
12
- export declare const canvasApi: (set: SetState<DrawingState>, get: GetState<DrawingState>) => {
13
+ export declare const canvasApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
13
14
  setInteraction: (isInteracting: boolean) => void;
14
15
  setControlsEnabled: (enabled: boolean) => void;
15
16
  };
@@ -7,7 +7,7 @@ export const canvasData = () => ({
7
7
  ////////////////////////////////////////////////////
8
8
  // API
9
9
  ////////////////////////////////////////////////////
10
- export const canvasApi = (set, get) => ({
10
+ export const canvasApi = (set, get, buerliApi) => ({
11
11
  setInteraction: (isInteracting) => set(state => ({ canvas: Object.assign(Object.assign({}, state.canvas), { controls: Object.assign(Object.assign({}, state.canvas.controls), { isInteracting }) }) })),
12
12
  setControlsEnabled: (enabled) => set(state => ({ canvas: Object.assign(Object.assign({}, state.canvas), { controls: Object.assign(Object.assign({}, state.canvas.controls), { enabled }) }) })),
13
13
  });
@@ -8,6 +8,8 @@
8
8
  * @image /doc/assets/core/drawing.png
9
9
  */
10
10
  import { GetState, SetState } from 'zustand';
11
+ import { BuerliStoreApi } from '../../store/store';
12
+ import { CadApi, CadData } from './cad';
11
13
  import { CanvasApi, CanvasData } from './canvas';
12
14
  import { GeometryApi, GeometryData } from './geometry';
13
15
  import { GraphicApi, GraphicData } from './graphic';
@@ -22,6 +24,7 @@ export declare type DrawingAPI = {
22
24
  geometry: GeometryApi;
23
25
  graphic: GraphicApi;
24
26
  canvas: CanvasApi;
27
+ cad: CadApi;
25
28
  setCustom: (key: string, value: Record<string, any>) => void;
26
29
  };
27
30
  declare type StateData = {
@@ -33,10 +36,11 @@ declare type StateData = {
33
36
  canvas: CanvasData;
34
37
  selection: SelectionData;
35
38
  plugin: PluginData;
39
+ cad: CadData;
36
40
  custom: any;
37
41
  };
38
42
  export declare type DrawingState = Readonly<StateData> & Readonly<{
39
43
  api: DrawingAPI;
40
44
  }>;
41
- export declare const createDrawingState: (set: SetState<DrawingState>, get: GetState<DrawingState>, api: any, drawingNumber: number, name?: string) => DrawingState;
45
+ export declare const createDrawingState: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi, drawingNumber: number, name?: string) => DrawingState;
42
46
  export {};
@@ -8,6 +8,7 @@
8
8
  * @image /doc/assets/core/drawing.png
9
9
  */
10
10
  import { v4 as uuidv4 } from 'uuid';
11
+ import { cadApi, cadData } from './cad';
11
12
  import { canvasApi, canvasData } from './canvas';
12
13
  import { geometryApi, geometryData } from './geometry';
13
14
  import { graphicApi, graphicData } from './graphic';
@@ -17,7 +18,7 @@ import { structureApi, structureData } from './structure';
17
18
  ////////////////////////////////////////////////////
18
19
  // DATA
19
20
  ////////////////////////////////////////////////////
20
- export const createDrawingState = (set, get, api, drawingNumber, name) => {
21
+ export const createDrawingState = (set, get, buerliApi, drawingNumber, name) => {
21
22
  const drawingId = uuidv4();
22
23
  return {
23
24
  structure: structureData(),
@@ -26,14 +27,16 @@ export const createDrawingState = (set, get, api, drawingNumber, name) => {
26
27
  geometry: geometryData(),
27
28
  graphic: graphicData(),
28
29
  canvas: canvasData(),
30
+ cad: cadData(),
29
31
  custom: {},
30
32
  api: {
31
- structure: structureApi(set, get),
32
- selection: selectionApi(set, get),
33
- plugin: pluginApi(set, get),
34
- geometry: geometryApi(set, get),
35
- graphic: graphicApi(set, get),
36
- canvas: canvasApi(set, get),
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
+ canvas: canvasApi(set, get, buerliApi),
39
+ cad: cadApi(set, get, buerliApi),
37
40
  setCustom: (key, value) => {
38
41
  set(state => (Object.assign(Object.assign({}, state), { custom: Object.assign(Object.assign({}, state.custom), { [key]: Object.assign(Object.assign({}, state.custom[key]), value) }) })));
39
42
  },
@@ -1,6 +1,7 @@
1
1
  import * as THREE from 'three';
2
2
  import { GetState, SetState } from 'zustand';
3
3
  import { ContainerGeometryT } from '../../geometry/ThreeGeometryCreator';
4
+ import { BuerliStoreApi } from '../../store/store';
4
5
  import { GraphicID } from '../../types/IGraphicPackage';
5
6
  import { ObjectID } from '../../types/IStructureTree';
6
7
  import { DrawingState } from './drawing';
@@ -34,7 +35,7 @@ export declare type GeometryData = {
34
35
  };
35
36
  export declare type GeometryApi = ReturnType<typeof geometryApi>;
36
37
  export declare const geometryData: () => GeometryData;
37
- export declare const geometryApi: (set: SetState<DrawingState>, get: GetState<DrawingState>) => {
38
+ export declare const geometryApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
38
39
  /**
39
40
  * Updates the @see geometry.bounds depending on all products of the model.
40
41
  * The update will only happen, if at least one solid of one product is available.
@@ -17,7 +17,7 @@ export const geometryData = () => ({
17
17
  ////////////////////////////////////////////////////
18
18
  // API
19
19
  ////////////////////////////////////////////////////
20
- export const geometryApi = (set, get) => ({
20
+ export const geometryApi = (set, get, buerliApi) => ({
21
21
  /**
22
22
  * Updates the @see geometry.bounds depending on all products of the model.
23
23
  * The update will only happen, if at least one solid of one product is available.
@@ -1,12 +1,27 @@
1
1
  import { GetState, SetState } from 'zustand';
2
- import { IGraphicContainer, IGraphicPackage } from '../../types/IGraphicPackage';
2
+ import { BuerliStoreApi } from '../../store/store';
3
+ import { IGraphicContainer, IGraphicElement, IGraphicPackage } from '../../types/IGraphicPackage';
4
+ import { ObjectID } from '../../types/IStructureTree';
3
5
  import { DrawingState } from './drawing';
4
6
  export declare type GraphicData = {
5
7
  containers: Record<number, IGraphicContainer>;
6
8
  };
7
9
  export declare type GraphicApi = ReturnType<typeof graphicApi>;
8
10
  export declare const graphicData: () => GraphicData;
9
- export declare const graphicApi: (set: SetState<DrawingState>, get: GetState<DrawingState>) => {
11
+ export declare const graphicApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
10
12
  addPackages: (packages: IGraphicPackage[]) => void;
11
13
  cleanupGraphicRecords: () => void;
14
+ findDecorated: () => {
15
+ elem: IGraphicElement;
16
+ containerId: ObjectID;
17
+ solidId: ObjectID;
18
+ }[];
19
+ filter: (cb: (elem: IGraphicElement) => boolean, options?: {
20
+ onlyOne?: boolean | undefined;
21
+ containerId?: number | undefined;
22
+ } | undefined) => {
23
+ elem: IGraphicElement;
24
+ containerId: ObjectID;
25
+ solidId: ObjectID;
26
+ }[];
12
27
  };
@@ -7,7 +7,7 @@ export const graphicData = () => ({
7
7
  ////////////////////////////////////////////////////
8
8
  // API
9
9
  ////////////////////////////////////////////////////
10
- export const graphicApi = (set, get) => ({
10
+ export const graphicApi = (set, get, buerliApi) => ({
11
11
  addPackages: (packages) => {
12
12
  // Timing.dump('load', `add graphic packages ${graphic.length} ${graphic[0].containers.length}`)
13
13
  let cacheChanged = false;
@@ -79,4 +79,36 @@ export const graphicApi = (set, get) => ({
79
79
  set({ geometry: Object.assign(Object.assign({}, geometry), { cache: usedGeometry, stamp: Date.now() }) });
80
80
  }
81
81
  },
82
+ findDecorated: () => {
83
+ const { graphic: api } = get().api;
84
+ return api.filter(elem => { var _a, _b, _c; return Boolean((_a = elem.properties) === null || _a === void 0 ? void 0 : _a.label) || Boolean((_c = (_b = elem.properties) === null || _b === void 0 ? void 0 : _b.material) === null || _c === void 0 ? void 0 : _c.color); });
85
+ },
86
+ filter: (cb, options) => {
87
+ const result = [];
88
+ const { containers } = get().graphic;
89
+ const contIds = Object.getOwnPropertyNames(containers).map(n => Number(n));
90
+ for (const contId of contIds) {
91
+ if ((options === null || options === void 0 ? void 0 : options.containerId) && contId !== options.containerId) {
92
+ continue;
93
+ }
94
+ const cont = containers[contId];
95
+ const items = [
96
+ ...((cont === null || cont === void 0 ? void 0 : cont.arcs) || []),
97
+ ...((cont === null || cont === void 0 ? void 0 : cont.cones) || []),
98
+ ...((cont === null || cont === void 0 ? void 0 : cont.edges) || []),
99
+ ...((cont === null || cont === void 0 ? void 0 : cont.lines) || []),
100
+ ...((cont === null || cont === void 0 ? void 0 : cont.meshes) || []),
101
+ ...((cont === null || cont === void 0 ? void 0 : cont.vertices) || []),
102
+ ];
103
+ for (const elem of items) {
104
+ if (cb(elem)) {
105
+ result.push({ elem, solidId: cont.owner, containerId: cont.id });
106
+ if (options === null || options === void 0 ? void 0 : options.onlyOne) {
107
+ return result;
108
+ }
109
+ }
110
+ }
111
+ }
112
+ return result;
113
+ },
82
114
  });
@@ -1,6 +1,7 @@
1
1
  import { GetState, PartialState, SetState } from 'zustand';
2
2
  import { ObjectID } from '../../types';
3
3
  import { DrawingID, DrawingState } from './drawing';
4
+ import { BuerliStoreApi } from '../../store/store';
4
5
  export declare type PluginDescription<InternalState = any> = {
5
6
  name: string;
6
7
  version: string;
@@ -42,11 +43,11 @@ export declare type PluginData = {
42
43
  };
43
44
  export declare type PluginApi = ReturnType<typeof pluginApi>;
44
45
  export declare const pluginData: () => PluginData;
45
- export declare const pluginApi: (set: SetState<DrawingState>, get: GetState<DrawingState>) => {
46
+ export declare const pluginApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
46
47
  setActiveFeature: (id: ObjectID | null) => void;
47
48
  setVisiblePlugin: (id: PluginID, visible: boolean) => void;
48
49
  setActiveGlobal: (id: PluginID, active: boolean) => void;
49
- createPlugin: (def: PluginDef, defaultId?: string | number | undefined, drawingId?: string | number | undefined, objectId?: number | undefined) => (deactivate?: boolean) => void;
50
+ createPlugin: (def: PluginDef, defaultId?: string | number | undefined, drawingId?: DrawingID | undefined, objectId?: number | undefined) => (deactivate?: boolean) => void;
50
51
  };
51
52
  export declare function isPromisePlugin(def: PluginDef): def is Promise<Plugin>;
52
53
  export {};
@@ -9,7 +9,7 @@ export const pluginData = () => ({
9
9
  },
10
10
  visible: [],
11
11
  });
12
- export const pluginApi = (set, get) => ({
12
+ export const pluginApi = (set, get, buerliApi) => ({
13
13
  setActiveFeature: (id) => {
14
14
  set(state => {
15
15
  let plugins = state.plugin.refs;
@@ -71,7 +71,9 @@ export const pluginApi = (set, get) => ({
71
71
  });
72
72
  } });
73
73
  return {
74
- plugin: Object.assign(Object.assign({}, currentState.plugin), { feature: description.global ? currentState.plugin.feature : [...currentState.plugin.feature, id], global: description.global ? [...currentState.plugin.global, id] : currentState.plugin.global, refs: Object.assign(Object.assign({}, currentState.plugin.refs), { [id]: Object.assign(Object.assign({}, currentState.plugin.refs[id]), newPlugin) }) }),
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) }) }),
75
77
  };
76
78
  });
77
79
  }
@@ -1,4 +1,5 @@
1
1
  import { GetState, SetState } from 'zustand';
2
+ import { BuerliStoreApi } from '../../store/store';
2
3
  import { GraphicID } from '../../types/IGraphicPackage';
3
4
  import { ObjectID } from '../../types/IStructureTree';
4
5
  import { GeometryElement, ProductElement } from './../../geometry/ThreeGeometryCreator';
@@ -39,15 +40,15 @@ export declare type SelectionData = {
39
40
  };
40
41
  export declare type SelectionApi = ReturnType<typeof selectionApi>;
41
42
  export declare const selectionData: () => SelectionData;
42
- export declare const selectionApi: (set: SetState<DrawingState>, get: GetState<DrawingState>) => {
43
+ export declare const selectionApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
43
44
  unselectAll(): void;
44
45
  unselect(...unselItems: SelectedItem[]): void;
45
46
  select(...newItems: SelectedItem[]): void;
46
- setHovered(item: SelectedItem | null, selectorId?: string | number | undefined): void;
47
+ setHovered(item: SelectedItem | null, selectorId?: SelectorID | undefined): void;
47
48
  activateSelector(selectorId: SelectorID | null): void;
48
49
  createSelector(selectorId: SelectorID, filter: SelectionFilter, activate?: boolean, initialItems?: SelectedItem[], maxLen?: number, customSelect?: CustomSelect | undefined, customUnSelect?: CustomSelect | undefined): () => void;
49
- areItemsSelected: (items: SelectedItem[], selectorId?: string | number | undefined) => boolean;
50
- isItemSelected: (item: SelectedItem, selectorId?: string | number | undefined) => boolean;
50
+ areItemsSelected: (items: SelectedItem[], selectorId?: SelectorID | undefined) => boolean;
51
+ isItemSelected: (item: SelectedItem, selectorId?: SelectorID | undefined) => boolean;
51
52
  setItems(id: SelectorID, items: SelectedItem[]): void;
52
53
  getGraphicItem: (productId: ObjectID, containerId: GraphicID, graphicId?: number | undefined) => SelectedItem | null;
53
54
  };
@@ -7,13 +7,13 @@ export const selectionData = () => ({
7
7
  refs: {},
8
8
  active: null,
9
9
  });
10
- export const selectionApi = (set, get) => ({
10
+ export const selectionApi = (set, get, buerliApi) => ({
11
11
  unselectAll() {
12
12
  const drawingId = get().id;
13
13
  const activeSelector = get().selection.active;
14
14
  if (activeSelector) {
15
15
  const unselItems = get().selection.refs[activeSelector].items;
16
- unsubscribeItems(drawingId, activeSelector, unselItems);
16
+ unsubscribeItems(buerliApi, drawingId, activeSelector, unselItems);
17
17
  set(state => {
18
18
  const selector = state.selection.refs[activeSelector];
19
19
  return {
@@ -29,7 +29,7 @@ export const selectionApi = (set, get) => ({
29
29
  // Remove unselItems from selector's items
30
30
  const selector = selection.refs[activeSelectorId];
31
31
  const newItems = selector.items.filter(item => unselItems.find(uItem => uItem.id === item.id) === undefined);
32
- unsubscribeItems(drawingId, activeSelectorId, unselItems);
32
+ unsubscribeItems(buerliApi, drawingId, activeSelectorId, unselItems);
33
33
  if (selector.customUnSelect) {
34
34
  // Find recently unselected items
35
35
  const diff = selector.items.filter(item1 => {
@@ -88,9 +88,9 @@ export const selectionApi = (set, get) => ({
88
88
  }
89
89
  else {
90
90
  // subscribe items which will be selected
91
- subscribeItems(drawingId, activeSelectorId, result);
91
+ subscribeItems(buerliApi, drawingId, activeSelectorId, result);
92
92
  // unsubscribe items which will be unselected
93
- unsubscribeItems(drawingId, activeSelectorId, unsubItems);
93
+ unsubscribeItems(buerliApi, drawingId, activeSelectorId, unsubItems);
94
94
  set(state => {
95
95
  return {
96
96
  selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [activeSelectorId]: Object.assign(Object.assign({}, selector), { items: result }) }) }),
@@ -138,7 +138,7 @@ export const selectionApi = (set, get) => ({
138
138
  return () => {
139
139
  if (get && get()) {
140
140
  const drawingId = get().id;
141
- unsubscribeItems(drawingId, selectorId);
141
+ unsubscribeItems(buerliApi, drawingId, selectorId);
142
142
  set(state => {
143
143
  const refs = state.selection.refs;
144
144
  delete refs[selectorId];
@@ -176,8 +176,8 @@ export const selectionApi = (set, get) => ({
176
176
  var _a;
177
177
  const { selection, id: drawingId } = get();
178
178
  const curItems = ((_a = selection.refs[id]) === null || _a === void 0 ? void 0 : _a.items) || [];
179
- unsubscribeItems(drawingId, id, curItems);
180
- subscribeItems(drawingId, id, items);
179
+ unsubscribeItems(buerliApi, drawingId, id, curItems);
180
+ subscribeItems(buerliApi, drawingId, id, items);
181
181
  set(state => {
182
182
  const selector = state.selection.refs[id];
183
183
  return {
@@ -1,5 +1,6 @@
1
1
  import * as THREE from 'three';
2
2
  import { GetState, SetState } from 'zustand';
3
+ import { BuerliStoreApi } from '../../store/store';
3
4
  import { GraphicID, IStructureObject, IStructurePatch, IStructureProtocol, IStructureTree, ObjectID } from '../../types';
4
5
  import { DrawingState } from './drawing';
5
6
  export declare type StructureData = IStructureProtocol & {
@@ -8,7 +9,7 @@ export declare type StructureData = IStructureProtocol & {
8
9
  };
9
10
  export declare type StructureApi = ReturnType<typeof structureApi>;
10
11
  export declare const structureData: () => StructureData;
11
- export declare const structureApi: (set: SetState<DrawingState>, get: GetState<DrawingState>) => {
12
+ export declare const structureApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
12
13
  get: () => StructureData;
13
14
  set: (structure: IStructureProtocol) => void;
14
15
  applyPatches: (patches: IStructurePatch[]) => void;
@@ -11,7 +11,7 @@ export const structureData = () => {
11
11
  ////////////////////////////////////////////////////
12
12
  // API
13
13
  ////////////////////////////////////////////////////
14
- export const structureApi = (set, get) => ({
14
+ export const structureApi = (set, get, buerliApi) => ({
15
15
  get: () => {
16
16
  return get().structure;
17
17
  },
@@ -1,3 +1,5 @@
1
+ import { StoreApi } from 'zustand/vanilla';
1
2
  import { BuerliState } from './states/buerli';
2
- declare const api: import("zustand").StoreApi<BuerliState>;
3
- export { api };
3
+ declare type BuerliStoreApi = StoreApi<BuerliState>;
4
+ declare const api: StoreApi<BuerliState>;
5
+ export { api, BuerliStoreApi };
@@ -1,5 +1,6 @@
1
- import { SelectorID, DrawingID } from '../..';
2
- import { SelectedItem } from '../states/selection';
1
+ import { DrawingID } from '../../store/states/drawing';
2
+ import { BuerliStoreApi } from '../../store/store';
3
+ import { SelectedItem, SelectorID } from '../states/selection';
3
4
  export declare const unsubs: Record<string, () => void>;
4
- export declare function subscribeItems(drawingId: DrawingID, selectorId: SelectorID, items?: SelectedItem[]): void;
5
- export declare function unsubscribeItems(drawingId: DrawingID, selectorId: SelectorID, items?: SelectedItem[]): void;
5
+ export declare function subscribeItems(buerliApi: BuerliStoreApi, drawingId: DrawingID, selectorId: SelectorID, items?: SelectedItem[]): void;
6
+ export declare function unsubscribeItems(buerliApi: BuerliStoreApi, drawingId: DrawingID, selectorId: SelectorID, items?: SelectedItem[]): void;
@@ -1,32 +1,31 @@
1
1
  // This is the solution for cases when object was deleted from tree and we need to remove corresponding selectedItem.
2
- import { getDrawing } from '../..';
3
2
  import { subscribeToDrawing } from './subscribeToDrawing';
4
3
  // This object contains unsubscibe function for all existing selections in all drawings
5
4
  export const unsubs = {};
6
5
  function getId(selectorId, itemId) {
7
6
  return `${selectorId}_${itemId}`;
8
7
  }
9
- export function subscribeItems(drawingId, selectorId, items) {
10
- const items_ = items || getDrawing(drawingId).selection.refs[selectorId].items;
8
+ export function subscribeItems(buerliApi, drawingId, selectorId, items) {
9
+ const items_ = items || buerliApi.getState().drawing.refs[drawingId].selection.refs[selectorId].items;
11
10
  items_.forEach(item => {
12
- subscribeItem(drawingId, selectorId, item);
11
+ subscribeItem(buerliApi, drawingId, selectorId, item);
13
12
  });
14
13
  }
15
- function subscribeItem(drawingId, selectorId, item) {
14
+ function subscribeItem(buerliApi, drawingId, selectorId, item) {
16
15
  if (item.removeCondition && !unsubs[getId(selectorId, item.id)]) {
17
- const selApi = getDrawing(drawingId).api.selection;
18
- unsubs[getId(selectorId, item.id)] = subscribeToDrawing(drawingId, (d) => item.removeCondition && item.removeCondition(d), (removeCond) => {
16
+ const selApi = buerliApi.getState().drawing.refs[drawingId].api.selection;
17
+ unsubs[getId(selectorId, item.id)] = subscribeToDrawing(buerliApi, drawingId, (d) => item.removeCondition && item.removeCondition(d), (removeCond) => {
19
18
  var _a;
20
19
  // Unselect item whose removeCondition got true
21
20
  if (removeCond) {
22
- const newItems = ((_a = getDrawing(drawingId).selection.refs[selectorId]) === null || _a === void 0 ? void 0 : _a.items) || [];
21
+ const newItems = ((_a = buerliApi.getState().drawing.refs[drawingId].selection.refs[selectorId]) === null || _a === void 0 ? void 0 : _a.items) || [];
23
22
  selApi.setItems(selectorId, newItems.filter(item_ => item_.id !== item.id));
24
23
  }
25
24
  });
26
25
  }
27
26
  }
28
- export function unsubscribeItems(drawingId, selectorId, items) {
29
- const items_ = items || getDrawing(drawingId).selection.refs[selectorId].items;
27
+ export function unsubscribeItems(buerliApi, drawingId, selectorId, items) {
28
+ const items_ = items || buerliApi.getState().drawing.refs[drawingId].selection.refs[selectorId].items;
30
29
  items_.forEach(item => {
31
30
  unsubscribeItem(selectorId, item);
32
31
  });
@@ -1,2 +1,3 @@
1
1
  import { DrawingID, DrawingState } from '../states/drawing';
2
- export declare function subscribeToDrawing(drawingId: DrawingID, sel: (d: DrawingState) => any, callback: (arg: any) => void): () => void;
2
+ import { BuerliStoreApi } from '../store';
3
+ export declare function subscribeToDrawing(buerliApi: BuerliStoreApi, drawingId: DrawingID, sel: (d: DrawingState) => any, callback: (arg: any) => void): () => void;
@@ -1,5 +1,4 @@
1
- import { api } from '../store';
2
- export function subscribeToDrawing(drawingId, sel, callback) {
3
- const unsub = api.subscribe(callback, state => state.drawing.refs[drawingId] && sel(state.drawing.refs[drawingId]));
1
+ export function subscribeToDrawing(buerliApi, drawingId, sel, callback) {
2
+ const unsub = buerliApi.subscribe(callback, state => state.drawing.refs[drawingId] && sel(state.drawing.refs[drawingId]));
4
3
  return unsub;
5
4
  }
@@ -2,4 +2,5 @@ import * as THREE from 'three';
2
2
  export declare const MathUtils: {
3
3
  convertToMatrix4: (coordinateSystem: number[][]) => THREE.Matrix4;
4
4
  convertToMatrix3: (coordinateSystem: number[][]) => THREE.Matrix3;
5
+ convertToCoordinateSystem: (matrix: THREE.Matrix4) => number[][];
5
6
  };
@@ -8,4 +8,18 @@ export const MathUtils = {
8
8
  const [, vx, vy, vz] = coordinateSystem;
9
9
  return new THREE.Matrix3().fromArray([...vx, ...vy, ...vz]);
10
10
  },
11
+ convertToCoordinateSystem: function (matrix) {
12
+ const position = new THREE.Vector3();
13
+ const xAxis = new THREE.Vector3();
14
+ const yAxis = new THREE.Vector3();
15
+ const zAxis = new THREE.Vector3();
16
+ position.setFromMatrixPosition(matrix);
17
+ matrix.extractBasis(xAxis, yAxis, zAxis);
18
+ const coordSys = [];
19
+ coordSys[0] = [position.x, position.y, position.z];
20
+ coordSys[1] = [xAxis.x, xAxis.y, xAxis.z];
21
+ coordSys[2] = [yAxis.x, yAxis.y, yAxis.z];
22
+ coordSys[3] = [zAxis.x, zAxis.y, zAxis.z];
23
+ return coordSys;
24
+ },
11
25
  };
@@ -73,17 +73,11 @@ export const Measure = {
73
73
  .toArray()
74
74
  .map(n => Math.round(n * 100) / 100)
75
75
  .join(', ')} ]`;
76
- const dir = (start, end) => end
77
- .clone()
78
- .sub(start)
79
- .normalize();
76
+ const dir = (start, end) => end.clone().sub(start).normalize();
80
77
  const getPointOnCircumference = (center, axis, radius) => {
81
78
  const axisNormalized = axis.clone().normalize();
82
79
  const helperVec = axisNormalized.x !== 1 ? new THREE.Vector3(1, 0, 0) : new THREE.Vector3(0, 1, 0);
83
- const tangent = axisNormalized
84
- .clone()
85
- .cross(helperVec)
86
- .normalize();
80
+ const tangent = axisNormalized.clone().cross(helperVec).normalize();
87
81
  return center.clone().addScaledVector(tangent, radius);
88
82
  };
89
83
  for (const element of transformed) {
@@ -464,35 +458,22 @@ export const Measure = {
464
458
  return Math.round(value * factor) / factor;
465
459
  },
466
460
  areParallel(vec1, vec2) {
467
- const val = Math.abs(vec1
468
- .clone()
469
- .cross(vec2)
470
- .length());
461
+ const val = Math.abs(vec1.clone().cross(vec2).length());
471
462
  return val < tolerance;
472
463
  },
473
464
  arePerpendicular(vec1, vec2) {
474
- const val = Math.abs(vec1
475
- .clone()
476
- .normalize()
477
- .dot(vec2.clone().normalize()));
465
+ const val = Math.abs(vec1.clone().normalize().dot(vec2.clone().normalize()));
478
466
  return val < tolerance;
479
467
  },
480
468
  getPointLineMPoints(pointsPos, startPos, endPos) {
481
469
  const p1 = pointsPos.clone();
482
470
  const lineDir = endPos.clone().sub(startPos);
483
- const p2 = pointsPos
484
- .clone()
485
- .sub(startPos)
486
- .projectOnVector(lineDir)
487
- .add(startPos);
471
+ const p2 = pointsPos.clone().sub(startPos).projectOnVector(lineDir).add(startPos);
488
472
  return [p1, p2];
489
473
  },
490
474
  getPointPlaneMPoints(pointPos, pointOnPlane, normal) {
491
475
  const p1 = pointPos.clone();
492
- const offsetV = pointPos
493
- .clone()
494
- .sub(pointOnPlane)
495
- .projectOnVector(normal);
476
+ const offsetV = pointPos.clone().sub(pointOnPlane).projectOnVector(normal);
496
477
  const p2 = pointPos.clone().sub(offsetV);
497
478
  return [p1, p2];
498
479
  },
@@ -538,14 +519,8 @@ export const Measure = {
538
519
  },
539
520
  getPlanePlaneMDirs(normal1, normal2) {
540
521
  if (!Measure.areParallel(normal1, normal2)) {
541
- const tangent1 = normal1
542
- .clone()
543
- .projectOnPlane(normal2)
544
- .normalize();
545
- const tangent2 = normal2
546
- .clone()
547
- .projectOnPlane(normal1)
548
- .normalize();
522
+ const tangent1 = normal1.clone().projectOnPlane(normal2).normalize();
523
+ const tangent2 = normal2.clone().projectOnPlane(normal1).normalize();
549
524
  const angle = tangent1.angleTo(tangent2);
550
525
  return angle <= Math.PI / 2 ? [tangent1, tangent2] : [tangent1, tangent2.negate()];
551
526
  }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@buerli.io/core",
3
- "version": "0.0.36-beta.0",
3
+ "version": "0.1.0",
4
4
  "description": "buerli state management",
5
5
  "author": "AWV Informatik AG <info@awv-informatik.ch>",
6
+ "license": "ISC",
6
7
  "repository": {},
7
8
  "main": "build/index.js",
8
9
  "module": "build/index.js",
@@ -10,38 +11,17 @@
10
11
  "sideEffects": false,
11
12
  "scripts": {
12
13
  "ver": "npm version",
13
- "prepack": "npm run build:dist",
14
+ "prepack": "npm run clean && npm run build",
14
15
  "clean": "rimraf ./build && rimraf ./coverage",
15
- "build": "echo Typescript: && tsc --version && tsc && echo DONE",
16
- "build:dist": "npm run clean && echo Typescript: && tsc --version && tsc --sourceMap false && echo DONE",
16
+ "build": "tsc",
17
+ "build:dev": "tsc --sourceMap true --declarationMap true",
17
18
  "lint": "eslint \"./src/**/*.ts?(x)\"",
18
19
  "test": "jest",
19
20
  "coverage": "npm run clean && npm run build && npm run jestLite -- --coverage",
20
- "prettier": "prettier --write \"./{src,tests}/**/*.{js,jsx,ts,tsx,json}\""
21
- },
22
- "husky": {
23
- "hooks": {
24
- "pre-commit": "lint-staged"
25
- }
26
- },
27
- "prettier": {
28
- "semi": false,
29
- "arrowParens": "avoid",
30
- "trailingComma": "all",
31
- "singleQuote": true,
32
- "jsxBracketSameLine": true,
33
- "tabWidth": 2,
34
- "printWidth": 120
21
+ "prettify": "prettier --write \"./{src,tests}/**/*.{js,jsx,ts,tsx,json}\""
35
22
  },
36
- "lint-staged": {
37
- "*.{js,jsx,ts,tsx,json,md}": [
38
- "prettier --write",
39
- "git add"
40
- ]
41
- },
42
- "license": "ISC",
43
23
  "devDependencies": {
44
- "@types/three": "^0.130.1",
24
+ "@types/three": "^0.137",
45
25
  "@babel/preset-env": "^7.10.4",
46
26
  "@babel/preset-typescript": "^7.10.4",
47
27
  "babel-jest": "^26.1.0",
@@ -49,8 +29,7 @@
49
29
  "babel-plugin-transform-class-properties": "^6.24.1",
50
30
  "jest": "^26.1.0",
51
31
  "rimraf": "^2.6.3",
52
- "three": "^0.131.3",
53
- "typescript": "4.1.2"
32
+ "three": "^0.138"
54
33
  },
55
34
  "dependencies": {
56
35
  "jsonpatch": "^3.0.1",
@@ -58,6 +37,6 @@
58
37
  "zustand": "^3.5.7"
59
38
  },
60
39
  "peerDependencies": {
61
- "three": ">=0.128"
40
+ "three": ">=0.138"
62
41
  }
63
42
  }