@buerli.io/core 0.4.0 → 0.5.0-beta.1

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
@@ -12,9 +12,8 @@ export * from './graphic/filters';
12
12
  *
13
13
  * Please have a look at https://github.com/awv-informatik/buerli/pull/129 for more information.
14
14
  */
15
- import { BuerliState as BS, BuerliOptions as BO } from './store/states/buerli';
15
+ import { BuerliState as BS } from './store/states/buerli';
16
16
  export declare type BuerliState = BS;
17
- export declare type BuerliOptions = BO;
18
17
  import { DrawingAPI as DrawingAPI1, DrawingID as DrawingID1, DrawingState as DrawingState1 } from './store/states/drawing';
19
18
  export declare type DrawingID = DrawingID1;
20
19
  export declare type DrawingState = DrawingState1;
@@ -26,7 +25,7 @@ import { Plugin as Plugin1, PluginDescription as PluginDescription1, PluginID as
26
25
  export declare type Plugin = Plugin1;
27
26
  export declare type PluginDescription<InternalState = any> = PluginDescription1<InternalState>;
28
27
  export declare type PluginID = PluginID1;
29
- export declare type PluginState<InternalState = any> = PluginState1<InternalState>;
28
+ export declare type PluginState<InternalState extends Record<any, any> = any> = PluginState1<InternalState>;
30
29
  import { SeletedItemData, SelectedItem as SelectedItem1, SelectionFilter as SelectionFilter1, SelectionScope as SelectionScope1, Selector as Selector1, SelectorID as SelectorID1, CustomSelect as CustomSelect1 } from './store/states/selection';
31
30
  export declare type SelectedItem<T extends SeletedItemData<any> = any> = SelectedItem1<T>;
32
31
  export declare type SelectionFilter = SelectionFilter1;
@@ -1,4 +1,4 @@
1
- import { BuerliOptions } from './states/buerli';
1
+ import { BuerliState } 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,7 +7,7 @@ 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(options?: Partial<BuerliOptions>): void;
10
+ declare function init(options?: Partial<BuerliState['options']>): 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';
@@ -1,50 +1,41 @@
1
- import { GetState, SetState } from 'zustand';
2
- import { BuerliStoreApi } from '../../store/store';
1
+ import { StateCreator } from 'zustand';
3
2
  import { DrawingID, DrawingState } from './drawing';
4
3
  import { GeometryConfig } from './geometry';
5
4
  import { MessageState } from './message';
6
5
  import { PluginDef, PluginImpl } from './plugin';
7
- declare type StateData = {
6
+ declare type GeneralApi = {
7
+ init(options?: Partial<BuerliState['options']>): void;
8
+ };
9
+ declare type DrawingManagementApi = {
10
+ createDrawing(name?: string): Promise<DrawingState>;
11
+ removeDrawing(id: DrawingID): void;
12
+ setActiveDrawing(id: DrawingID | null): void;
13
+ };
14
+ export declare type BuerliState = Readonly<{
8
15
  initDone: boolean;
9
- options: BuerliOptions;
16
+ options: {
17
+ elements: any;
18
+ plugins: Record<string, PluginImpl>;
19
+ globalPlugins: PluginDef[];
20
+ theme: {
21
+ primary: string;
22
+ secondary: string;
23
+ dark: string;
24
+ highlightedGeom: string;
25
+ hoveredGeom: string;
26
+ };
27
+ config: {
28
+ geometry: GeometryConfig;
29
+ };
30
+ };
10
31
  drawing: {
11
32
  ids: DrawingID[];
12
33
  refs: Record<DrawingID, DrawingState>;
13
34
  active: DrawingID | null;
14
35
  };
15
- } & MessageState;
16
- export declare type BuerliOptions = {
17
- elements: any;
18
- plugins: Record<string, PluginImpl>;
19
- globalPlugins: PluginDef[];
20
- theme: {
21
- primary: string;
22
- secondary: string;
23
- dark: string;
24
- highlightedGeom: string;
25
- hoveredGeom: string;
26
- };
27
- config: {
28
- geometry: GeometryConfig;
29
- };
30
- };
31
- declare type StateApi = ReturnType<typeof generalApi> & ReturnType<typeof drawingManagementApi>;
32
- export declare type BuerliState = Readonly<StateData> & Readonly<{
33
- api: StateApi;
34
- }>;
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
- /**
38
- * This api method initializes state. Considering user can accidentally ommit some important like elements,
39
- * there is a warning disaplying for these cases.
40
- *
41
- * @param options - options which will be set into state.options
42
- */
43
- init(options?: Partial<BuerliOptions> | undefined): void;
44
- };
45
- declare const drawingManagementApi: (set: SetState<BuerliState>, get: GetState<BuerliState>, buerliApi: BuerliStoreApi) => {
46
- createDrawing(name?: string | undefined): Promise<DrawingState>;
47
- removeDrawing(id: DrawingID): void;
48
- setActiveDrawing(id: DrawingID | null): void;
49
- };
36
+ api: GeneralApi & DrawingManagementApi;
37
+ }> & Readonly<MessageState>;
38
+ export declare const createState: StateCreator<BuerliState, [], [], BuerliState>;
39
+ export declare const generalApi: StateCreator<BuerliState, [], [], GeneralApi>;
40
+ export declare const drawingManagementApi: StateCreator<BuerliState, [], [], DrawingManagementApi>;
50
41
  export {};
@@ -20,7 +20,7 @@ export const createState = (set, get, buerliApi) => (Object.assign({ initDone: f
20
20
  refs: {},
21
21
  active: null,
22
22
  }, api: Object.assign(Object.assign({}, generalApi(set, get, buerliApi)), drawingManagementApi(set, get, buerliApi)) }, getInitialMessageState(set, get, buerliApi)));
23
- const generalApi = (set, get, buerliApi) => ({
23
+ export const generalApi = set => ({
24
24
  // TODO: rename init to setOptions and remove initDone if everything is ok
25
25
  /**
26
26
  * This api method initializes state. Considering user can accidentally ommit some important like elements,
@@ -32,7 +32,7 @@ const generalApi = (set, get, buerliApi) => ({
32
32
  set(state => ({ options: Object.assign(Object.assign({}, state.options), options), initDone: true }));
33
33
  },
34
34
  });
35
- const drawingManagementApi = (set, get, buerliApi) => ({
35
+ export const drawingManagementApi = (set, get, buerliApi) => ({
36
36
  async createDrawing(name) {
37
37
  const { initDone, drawing } = get();
38
38
  if (!initDone)
@@ -1,5 +1,5 @@
1
- import { GetState, SetState } from 'zustand';
2
- import { BuerliStoreApi } from '../../store/store';
1
+ import { StoreApi } from 'zustand';
2
+ import { BuerliState } from './buerli';
3
3
  import { DrawingState } from './drawing';
4
4
  declare type States = {
5
5
  current: number;
@@ -22,7 +22,7 @@ export declare type CadData = {
22
22
  };
23
23
  export declare type CadApi = ReturnType<typeof cadApi>;
24
24
  export declare const cadData: () => CadData;
25
- export declare const cadApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
25
+ export declare const cadApi: (set: StoreApi<DrawingState>['setState'], get: StoreApi<DrawingState>['getState'], buerliApi: StoreApi<BuerliState>) => {
26
26
  setStates: (current: number, stack: string[], captionMap: Record<string, {
27
27
  stateName: string;
28
28
  caption: string;
@@ -33,7 +33,7 @@ export declare const cadApi: (set: SetState<DrawingState>, get: GetState<Drawing
33
33
  }>) => void;
34
34
  addPending: (name: string, options?: {
35
35
  args?: any;
36
- } | undefined) => string;
36
+ }) => string;
37
37
  removePending: (id: string) => void;
38
38
  setConnected: (connected: boolean) => void;
39
39
  };
@@ -7,8 +7,8 @@
7
7
  *
8
8
  * @image /doc/assets/core/drawing.png
9
9
  */
10
- import { GetState, SetState } from 'zustand';
11
- import { BuerliStoreApi } from '../../store/store';
10
+ import { StoreApi } from 'zustand';
11
+ import { BuerliState } from './buerli';
12
12
  import { CadApi, CadData } from './cad';
13
13
  import { GeometryApi, GeometryData } from './geometry';
14
14
  import { GraphicApi, GraphicData } from './graphic';
@@ -40,5 +40,5 @@ declare type StateData = {
40
40
  export declare type DrawingState = Readonly<StateData> & Readonly<{
41
41
  api: DrawingAPI;
42
42
  }>;
43
- export declare const createDrawingState: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi, drawingNumber: number, name?: string) => DrawingState;
43
+ export declare const createDrawingState: (set: StoreApi<DrawingState>['setState'], get: StoreApi<DrawingState>['getState'], buerliApi: StoreApi<BuerliState>, drawingNumber: number, name?: string) => DrawingState;
44
44
  export {};
@@ -1,9 +1,9 @@
1
1
  import * as THREE from 'three';
2
- import { GetState, SetState } from 'zustand';
2
+ import { StoreApi } from 'zustand';
3
3
  import { ContainerGeometryT, GeometryElement } from '../../geometry/ThreeGeometryCreator';
4
- import { BuerliStoreApi } from '../../store/store';
5
4
  import { GraphicID } from '../../types/IGraphicPackage';
6
5
  import { ObjectID } from '../../types/IStructureTree';
6
+ import { BuerliState } from './buerli';
7
7
  import { DrawingState } from './drawing';
8
8
  export declare type GeometryBounds = {
9
9
  center: THREE.Vector3;
@@ -43,20 +43,20 @@ export declare type GeometryData = {
43
43
  };
44
44
  export declare type GeometryApi = ReturnType<typeof geometryApi>;
45
45
  export declare const geometryData: () => GeometryData;
46
- export declare const geometryApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
46
+ export declare const geometryApi: (set: StoreApi<DrawingState>['setState'], get: StoreApi<DrawingState>['getState'], buerliApi: StoreApi<BuerliState>) => {
47
47
  /**
48
48
  * Updates the @see geometry.bounds depending on all products of the model.
49
49
  * The update will only happen, if at least one solid of one product is available.
50
50
  */
51
51
  updateBounds: () => void;
52
- createGeometryIfNotCached: (containerId: number, color?: number[] | undefined) => ContainerGeometryT | undefined;
52
+ createGeometryIfNotCached: (containerId: number, color?: number[]) => ContainerGeometryT | undefined;
53
53
  setColor: (containerId: GraphicID, r: number, g: number, b: number) => void;
54
54
  setOpacity: (containerId: GraphicID, opacity: number) => void;
55
55
  setConfig: (objId: ObjectID | GraphicID, config: Partial<GeometryConfig> | null) => void;
56
56
  findDecorated: () => GeometryElement[];
57
57
  filter: (cb: (elem: GeometryElement) => boolean, options?: {
58
- onlyOne?: boolean | undefined;
59
- containerId?: number | undefined;
60
- } | undefined) => GeometryElement[];
58
+ onlyOne?: boolean;
59
+ containerId?: ObjectID;
60
+ }) => GeometryElement[];
61
61
  };
62
62
  export {};
@@ -1,20 +1,20 @@
1
- import { GetState, SetState } from 'zustand';
2
- import { BuerliStoreApi } from '../../store/store';
1
+ import { StoreApi } from 'zustand';
3
2
  import { IGraphicContainer, IGraphicElement, IGraphicPackage } from '../../types/IGraphicPackage';
4
3
  import { ObjectID } from '../../types/IStructureTree';
4
+ import { BuerliState } from './buerli';
5
5
  import { DrawingState } from './drawing';
6
6
  export declare type GraphicData = {
7
7
  containers: Record<number, IGraphicContainer>;
8
8
  };
9
9
  export declare type GraphicApi = ReturnType<typeof graphicApi>;
10
10
  export declare const graphicData: () => GraphicData;
11
- export declare const graphicApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
11
+ export declare const graphicApi: (set: StoreApi<DrawingState>['setState'], get: StoreApi<DrawingState>['getState'], buerliApi: StoreApi<BuerliState>) => {
12
12
  addPackages: (packages: IGraphicPackage[]) => void;
13
13
  cleanupGraphicRecords: () => void;
14
14
  filter: (cb: (elem: IGraphicElement) => boolean, options?: {
15
- onlyOne?: boolean | undefined;
16
- containerId?: number | undefined;
17
- } | undefined) => {
15
+ onlyOne?: boolean;
16
+ containerId?: ObjectID;
17
+ }) => {
18
18
  elem: IGraphicElement;
19
19
  containerId: ObjectID;
20
20
  solidId: ObjectID;
@@ -1,6 +1,6 @@
1
- import { GetState, SetState } from 'zustand';
2
- import { BuerliStoreApi } from '../../store/store';
1
+ import { StoreApi } from 'zustand';
3
2
  import { InteractionInfo } from '../../types';
3
+ import { BuerliState } from './buerli';
4
4
  import { DrawingState } from './drawing';
5
5
  export declare type InteractionData = {
6
6
  hovered?: InteractionInfo | null;
@@ -8,7 +8,7 @@ export declare type InteractionData = {
8
8
  };
9
9
  export declare type InteractionApi = ReturnType<typeof interactionApi>;
10
10
  export declare const interactionData: () => InteractionData;
11
- export declare const interactionApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
11
+ export declare const interactionApi: (set: StoreApi<DrawingState>['setState'], get: StoreApi<DrawingState>['getState'], buerliApi: StoreApi<BuerliState>) => {
12
12
  /**
13
13
  * Sets the hovered item in the store to the given item.
14
14
  *
@@ -30,5 +30,5 @@ export declare const interactionApi: (set: SetState<DrawingState>, get: GetState
30
30
  * @param item The item to select.
31
31
  * @param multi Do multi select.
32
32
  */
33
- select: (item: InteractionInfo, multi?: boolean | undefined) => void;
33
+ select: (item: InteractionInfo, multi?: boolean) => void;
34
34
  };
@@ -1,4 +1,4 @@
1
- import { GetState, SetState } from 'zustand';
1
+ import { StoreApi } from 'zustand';
2
2
  import { BuerliState } from './buerli';
3
3
  import { DrawingID } from './drawing';
4
4
  export declare type MessageScope = string | number;
@@ -22,8 +22,8 @@ export declare type MessageState = {
22
22
  api: ReturnType<typeof messageApi>;
23
23
  };
24
24
  };
25
- export declare const getInitialMessageState: (set: SetState<BuerliState>, get: GetState<BuerliState>, api: any) => MessageState;
26
- declare const messageApi: (set: SetState<BuerliState>, get: GetState<BuerliState>, api: any) => {
25
+ export declare const getInitialMessageState: (set: StoreApi<BuerliState>['setState'], get: StoreApi<BuerliState>['getState'], api: StoreApi<BuerliState>) => MessageState;
26
+ declare const messageApi: (set: StoreApi<BuerliState>['setState'], get: StoreApi<BuerliState>['getState'], api: StoreApi<BuerliState>) => {
27
27
  show(message: Message): MessageID;
28
28
  update(id: MessageID, message: Message): void;
29
29
  };
@@ -1,7 +1,7 @@
1
- import { GetState, PartialState, SetState } from 'zustand';
1
+ import { StoreApi } from 'zustand';
2
2
  import { ObjectID } from '../../types';
3
+ import { BuerliState } from './buerli';
3
4
  import { DrawingID, DrawingState } from './drawing';
4
- import { BuerliStoreApi } from '../../store/store';
5
5
  export declare type PluginDescription<InternalState = any> = {
6
6
  name: string;
7
7
  version: string;
@@ -18,7 +18,7 @@ declare type StateData<InternalState extends Record<any, any>> = PluginDescripti
18
18
  drawingId?: DrawingID;
19
19
  objectId?: ObjectID;
20
20
  state: InternalState;
21
- set: (sel: PartialState<InternalState>) => void;
21
+ set: (sel: Partial<InternalState> | ((state: InternalState) => Partial<InternalState>)) => void;
22
22
  };
23
23
  export declare type Plugin = {
24
24
  Root?: ((options?: any) => any) | null;
@@ -43,11 +43,11 @@ export declare type PluginData = {
43
43
  };
44
44
  export declare type PluginApi = ReturnType<typeof pluginApi>;
45
45
  export declare const pluginData: () => PluginData;
46
- export declare const pluginApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
46
+ export declare const pluginApi: (set: StoreApi<DrawingState>['setState'], get: StoreApi<DrawingState>['getState'], buerliApi: StoreApi<BuerliState>) => {
47
47
  setActiveFeature: (id: ObjectID | null) => void;
48
48
  setVisiblePlugin: (id: PluginID, visible: boolean) => void;
49
49
  setActiveGlobal: (id: PluginID, active: boolean) => void;
50
- createPlugin: (def: PluginDef, defaultId?: string | number | undefined, drawingId?: string | number | undefined, objectId?: number | undefined) => (deactivate?: boolean) => void;
50
+ createPlugin: (def: PluginDef, defaultId?: ObjectID | string, drawingId?: DrawingID, objectId?: ObjectID) => (deactivate?: boolean) => void;
51
51
  };
52
52
  export declare function isPromisePlugin(def: PluginDef): def is Promise<Plugin>;
53
53
  export {};
@@ -1,8 +1,8 @@
1
- import { GetState, SetState } from 'zustand';
2
- import { BuerliStoreApi } from '../../store/store';
1
+ import { StoreApi } from 'zustand';
3
2
  import { GraphicID } from '../../types/IGraphicPackage';
4
3
  import { ObjectID } from '../../types/IStructureTree';
5
4
  import { GeometryElement, ProductElement } from './../../geometry/ThreeGeometryCreator';
5
+ import { BuerliState } from './buerli';
6
6
  import { DrawingState } from './drawing';
7
7
  export declare const BuerliScope = "ClassCAD";
8
8
  export declare type SelectorID = string | number;
@@ -40,23 +40,23 @@ export declare type SelectionData = {
40
40
  };
41
41
  export declare type SelectionApi = ReturnType<typeof selectionApi>;
42
42
  export declare const selectionData: () => SelectionData;
43
- export declare const selectionApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
44
- unselectAll(selectorId?: string | number | undefined): void;
45
- unselect(items: SelectedItem | SelectedItem[], selectorId?: string | number | undefined): void;
46
- select(items: SelectedItem | SelectedItem[], selectorId?: string | number | undefined): void;
47
- setHovered(item: SelectedItem | null, selectorId?: string | number | undefined): void;
43
+ export declare const selectionApi: (set: StoreApi<DrawingState>['setState'], get: StoreApi<DrawingState>['getState'], buerliApi: StoreApi<BuerliState>) => {
44
+ unselectAll(selectorId?: SelectorID): void;
45
+ unselect(items: SelectedItem | SelectedItem[], selectorId?: SelectorID): void;
46
+ select(items: SelectedItem | SelectedItem[], selectorId?: SelectorID): void;
47
+ setHovered(item: SelectedItem | null, selectorId?: SelectorID): void;
48
48
  activateSelector(selectorId: SelectorID | null): void;
49
- createSelector(selectorId: SelectorID, filter: SelectionFilter, activate?: boolean, initialItems?: SelectedItem[], maxLen?: number, customSelect?: CustomSelect | undefined, customUnSelect?: CustomSelect | undefined): () => void;
50
- areItemsSelected: (items: SelectedItem[], selectorId?: string | number | undefined) => boolean;
51
- isItemSelected: (item: SelectedItem, selectorId?: string | number | undefined) => boolean;
49
+ createSelector(selectorId: SelectorID, filter: SelectionFilter, activate?: boolean, initialItems?: SelectedItem[], maxLen?: number, customSelect?: CustomSelect, customUnSelect?: CustomSelect): () => void;
50
+ areItemsSelected: (items: SelectedItem[], selectorId?: SelectorID) => boolean;
51
+ isItemSelected: (item: SelectedItem, selectorId?: SelectorID) => boolean;
52
52
  setItems(id: SelectorID, items: SelectedItem[]): void;
53
53
  selectGraphic: (selectorId: SelectorID, items: {
54
54
  productId: ObjectID;
55
55
  containerId: GraphicID;
56
56
  graphicId?: GraphicID;
57
57
  }[], options?: {
58
- unselectExisting?: boolean | undefined;
59
- } | undefined) => void;
60
- getGraphicItem: (productId: ObjectID, containerId: GraphicID, graphicId?: number | undefined) => SelectedItem<ProductElement> | null;
58
+ unselectExisting?: boolean;
59
+ }) => void;
60
+ getGraphicItem: (productId: ObjectID, containerId: GraphicID, graphicId?: GraphicID) => SelectedItem<ProductElement> | null;
61
61
  };
62
62
  export declare const createGraphicItem: (productId: ObjectID, el: GeometryElement) => SelectedItem<ProductElement>;
@@ -1,7 +1,7 @@
1
1
  import * as THREE from 'three';
2
- import { GetState, SetState } from 'zustand';
3
- import { BuerliStoreApi } from '../../store/store';
2
+ import { StoreApi } from 'zustand';
4
3
  import { GraphicID, IStructureObject, IStructurePatch, IStructureProtocol, IStructureTree, ObjectID } from '../../types';
4
+ import { BuerliState } from './buerli';
5
5
  import { DrawingState } from './drawing';
6
6
  export declare type StructureData = IStructureProtocol & {
7
7
  products: ObjectID[];
@@ -9,7 +9,7 @@ export declare type StructureData = IStructureProtocol & {
9
9
  };
10
10
  export declare type StructureApi = ReturnType<typeof structureApi>;
11
11
  export declare const structureData: () => StructureData;
12
- export declare const structureApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
12
+ export declare const structureApi: (set: StoreApi<DrawingState>['setState'], get: StoreApi<DrawingState>['getState'], buerliApi: StoreApi<BuerliState>) => {
13
13
  get: () => StructureData;
14
14
  set: (structure: IStructureProtocol) => void;
15
15
  applyPatches: (patches: IStructurePatch[]) => void;
@@ -29,7 +29,7 @@ export declare const structureApi: (set: SetState<DrawingState>, get: GetState<D
29
29
  calculateProductBounds: (productId: ObjectID, base?: {
30
30
  min: THREE.Vector3;
31
31
  max: THREE.Vector3;
32
- } | undefined) => {
32
+ }) => {
33
33
  center: THREE.Vector3;
34
34
  radius: number;
35
35
  max: THREE.Vector3;
@@ -1,5 +1,2 @@
1
- import { StoreApi } from 'zustand/vanilla';
2
1
  import { BuerliState } from './states/buerli';
3
- declare type BuerliStoreApi = StoreApi<BuerliState>;
4
- declare const api: StoreApi<BuerliState>;
5
- export { api, BuerliStoreApi };
2
+ export declare const api: import("zustand/vanilla").StoreApi<BuerliState>;
@@ -1,8 +1,3 @@
1
1
  import vanillaCreate from 'zustand/vanilla';
2
2
  import { createState } from './states/buerli';
3
- const store = (set, get, buerliApi) => createState(set, get, buerliApi);
4
- const wnd = typeof window !== 'undefined' ? window : null;
5
- const middleware = wnd ? wnd.BUERLI_MIDDLEWARE || (wnd.BUERLI_MIDDLEWARE = []) : [];
6
- const buerliStore = middleware.reduceRight((acc, cur) => cur(acc), store);
7
- const api = vanillaCreate(buerliStore);
8
- export { api };
3
+ export const api = vanillaCreate()(createState);
@@ -1,6 +1,7 @@
1
- import { DrawingID } from '../../store/states/drawing';
2
- import { BuerliStoreApi } from '../../store/store';
1
+ import { StoreApi } from 'zustand';
2
+ import { DrawingID } from '../states/drawing';
3
3
  import { SelectedItem, SelectorID } from '../states/selection';
4
+ import { BuerliState } from '../states/buerli';
4
5
  export declare const unsubs: Record<string, () => 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;
6
+ export declare function subscribeItems(buerliApi: StoreApi<BuerliState>, drawingId: DrawingID, selectorId: SelectorID, items?: SelectedItem[]): void;
7
+ export declare function unsubscribeItems(buerliApi: StoreApi<BuerliState>, drawingId: DrawingID, selectorId: SelectorID, items?: SelectedItem[]): void;
@@ -1,3 +1,4 @@
1
+ import { StoreApi } from 'zustand';
1
2
  import { DrawingID, DrawingState } from '../states/drawing';
2
- import { BuerliStoreApi } from '../store';
3
- export declare function subscribeToDrawing(buerliApi: BuerliStoreApi, drawingId: DrawingID, sel: (d: DrawingState) => any, callback: (arg: any) => void): () => void;
3
+ import { BuerliState } from '../states/buerli';
4
+ export declare function subscribeToDrawing<T = any>(buerliApi: StoreApi<BuerliState>, drawingId: DrawingID, sel: (d: DrawingState) => T, callback: (arg: T) => void): () => void;
@@ -1,4 +1,9 @@
1
1
  export function subscribeToDrawing(buerliApi, drawingId, sel, callback) {
2
- const unsub = buerliApi.subscribe(callback, state => state.drawing.refs[drawingId] && sel(state.drawing.refs[drawingId]));
2
+ const unsub = buerliApi.subscribe((state, prev) => {
3
+ const curDrawing = state.drawing.refs[drawingId] && sel(state.drawing.refs[drawingId]);
4
+ const prevDrawing = prev.drawing.refs[drawingId] && sel(prev.drawing.refs[drawingId]);
5
+ if (curDrawing !== prevDrawing)
6
+ callback(curDrawing);
7
+ });
3
8
  return unsub;
4
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buerli.io/core",
3
- "version": "0.4.0",
3
+ "version": "0.5.0-beta.1",
4
4
  "description": "buerli state management",
5
5
  "author": "AWV Informatik AG <info@awv-informatik.ch>",
6
6
  "license": "ISC",
@@ -21,7 +21,7 @@
21
21
  "prettify": "prettier --write \"./{src,tests}/**/*.{js,jsx,ts,tsx,json}\""
22
22
  },
23
23
  "devDependencies": {
24
- "@types/three": "^0.137",
24
+ "@types/three": "^0.143",
25
25
  "@babel/preset-env": "^7.10.4",
26
26
  "@babel/preset-typescript": "^7.10.4",
27
27
  "babel-jest": "^26.1.0",
@@ -29,14 +29,14 @@
29
29
  "babel-plugin-transform-class-properties": "^6.24.1",
30
30
  "jest": "^26.1.0",
31
31
  "rimraf": "^2.6.3",
32
- "three": "^0.138",
33
- "typescript": "4.1.2"
32
+ "three": "^0.143",
33
+ "typescript": "4.8.4"
34
34
  },
35
35
  "dependencies": {
36
36
  "fast-json-patch": "^3.1.1",
37
37
  "jsonpatch": "^3.1.0",
38
38
  "uuid": "^3.3.2",
39
- "zustand": "^3.5.7"
39
+ "zustand": "^4.1.4"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "three": ">=0.138"