@buerli.io/core 0.9.0-beta.1 → 0.9.1-beta.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.
@@ -16,14 +16,23 @@ const selectionApi = (set, get, buerliApi) => ({
16
16
  const { selection, id: drawingId } = get();
17
17
  const selId = (selectorId || selection.active);
18
18
  if (selId) {
19
- const unselItems = selection.refs[selId].items;
19
+ const selector = selection.refs[selId];
20
+ const unselItems = selector.items;
21
+ if (unselItems.length === 0) {
22
+ return;
23
+ }
20
24
  (0, selection_1.unsubscribeItems)(buerliApi, drawingId, selId, unselItems);
21
- set(state => {
22
- const selector = state.selection.refs[selId];
23
- return {
24
- selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [selId]: Object.assign(Object.assign({}, selector), { items: [] }) }) }),
25
- };
26
- });
25
+ if (selector.customUnSelect) {
26
+ selector.customUnSelect(selId, [], unselItems);
27
+ }
28
+ else {
29
+ set(state => {
30
+ const selector_ = state.selection.refs[selId];
31
+ return {
32
+ selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [selId]: Object.assign(Object.assign({}, selector_), { items: [] }) }) }),
33
+ };
34
+ });
35
+ }
27
36
  }
28
37
  },
29
38
  unselect(items, selectorId) {
@@ -114,14 +114,25 @@ const structureApi = (set, get, buerliApi) => ({
114
114
  },
115
115
  filterTree: (tree, filter) => {
116
116
  const objs = [];
117
- Object.getOwnPropertyNames(tree).forEach(name => {
118
- const obj = tree[name];
117
+ const keys = Object.getOwnPropertyNames(tree);
118
+ for (const key of keys) {
119
+ const obj = tree[key];
119
120
  if (filter(obj)) {
120
121
  objs.push(obj);
121
122
  }
122
- });
123
+ }
123
124
  return objs;
124
125
  },
126
+ findTree: (tree, filter) => {
127
+ const keys = Object.getOwnPropertyNames(tree);
128
+ for (const key of keys) {
129
+ const obj = tree[key];
130
+ if (filter(obj)) {
131
+ return obj;
132
+ }
133
+ }
134
+ return undefined;
135
+ },
125
136
  collectUsedSolidIds: () => {
126
137
  const { api, structure } = get();
127
138
  const solidObjs = api.structure.filterTree(structure.tree, obj => typeof obj.geometryIdList !== 'undefined');
@@ -12,14 +12,23 @@ export const selectionApi = (set, get, buerliApi) => ({
12
12
  const { selection, id: drawingId } = get();
13
13
  const selId = (selectorId || selection.active);
14
14
  if (selId) {
15
- const unselItems = selection.refs[selId].items;
15
+ const selector = selection.refs[selId];
16
+ const unselItems = selector.items;
17
+ if (unselItems.length === 0) {
18
+ return;
19
+ }
16
20
  unsubscribeItems(buerliApi, drawingId, selId, unselItems);
17
- set(state => {
18
- const selector = state.selection.refs[selId];
19
- return {
20
- selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [selId]: Object.assign(Object.assign({}, selector), { items: [] }) }) }),
21
- };
22
- });
21
+ if (selector.customUnSelect) {
22
+ selector.customUnSelect(selId, [], unselItems);
23
+ }
24
+ else {
25
+ set(state => {
26
+ const selector_ = state.selection.refs[selId];
27
+ return {
28
+ selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [selId]: Object.assign(Object.assign({}, selector_), { items: [] }) }) }),
29
+ };
30
+ });
31
+ }
23
32
  }
24
33
  },
25
34
  unselect(items, selectorId) {
@@ -84,14 +84,25 @@ export const structureApi = (set, get, buerliApi) => ({
84
84
  },
85
85
  filterTree: (tree, filter) => {
86
86
  const objs = [];
87
- Object.getOwnPropertyNames(tree).forEach(name => {
88
- const obj = tree[name];
87
+ const keys = Object.getOwnPropertyNames(tree);
88
+ for (const key of keys) {
89
+ const obj = tree[key];
89
90
  if (filter(obj)) {
90
91
  objs.push(obj);
91
92
  }
92
- });
93
+ }
93
94
  return objs;
94
95
  },
96
+ findTree: (tree, filter) => {
97
+ const keys = Object.getOwnPropertyNames(tree);
98
+ for (const key of keys) {
99
+ const obj = tree[key];
100
+ if (filter(obj)) {
101
+ return obj;
102
+ }
103
+ }
104
+ return undefined;
105
+ },
95
106
  collectUsedSolidIds: () => {
96
107
  const { api, structure } = get();
97
108
  const solidObjs = api.structure.filterTree(structure.tree, obj => typeof obj.geometryIdList !== 'undefined');
@@ -252,6 +252,5 @@ export declare type GeometryElement = MeshGeometry | PlaneGeometry | CylinderGeo
252
252
  export declare type ProductElement = GeometryElement & {
253
253
  productId: ObjectID;
254
254
  };
255
- export declare type AnyGeometryElement = CommonProps & Metadata & Partial<MeshGeometry> & Partial<PlaneGeometry> & Partial<CylinderGeometry> & Partial<ConeGeometry> & Partial<SphereGeometry> & Partial<LineGeometry> & Partial<EdgeGeometry> & Partial<ArcGeometry> & Partial<CircleGeometry> & Partial<PointGeometry>;
256
255
  export declare const isEqualGeometry: (a: GeometryElement, b: GeometryElement) => boolean;
257
256
  export {};
@@ -14,6 +14,7 @@ export declare const structureApi: (set: StoreApi<DrawingState>['setState'], get
14
14
  set: (structure: IStructureProtocol) => void;
15
15
  applyPatches: (patches: IStructurePatch[]) => void;
16
16
  filterTree: (tree: IStructureTree, filter: (obj: IStructureObject) => boolean) => IStructureObject[];
17
+ findTree: (tree: IStructureTree, filter: (obj: IStructureObject) => boolean) => IStructureObject | undefined;
17
18
  collectUsedSolidIds: () => ObjectID[];
18
19
  collectProducts: (root: ObjectID) => IStructureObject[];
19
20
  getProductSolidIds: (productId: ObjectID) => number[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buerli.io/core",
3
- "version": "0.9.0-beta.1",
3
+ "version": "0.9.1-beta.0",
4
4
  "description": "buerli state management",
5
5
  "author": "AWV Informatik AG <info@awv-informatik.ch>",
6
6
  "license": "ISC",
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "fast-json-patch": "^3.1.1",
37
37
  "jsonpatch": "^3.1.0",
38
- "uuid": "^3.3.2",
38
+ "uuid": "^9.0.0",
39
39
  "zustand": "^4.1.4"
40
40
  },
41
41
  "peerDependencies": {