@buerli.io/core 0.0.34-beta.0 → 0.0.35-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.
Files changed (74) hide show
  1. package/build/cjs/geometry/ThreeGeometryCreator.js +284 -0
  2. package/build/cjs/geometry/index.js +13 -0
  3. package/build/cjs/index.js +20 -0
  4. package/build/cjs/store/index.js +46 -0
  5. package/build/cjs/store/states/buerli.js +97 -0
  6. package/build/cjs/store/states/canvas.js +18 -0
  7. package/build/cjs/store/states/drawing.js +44 -0
  8. package/build/cjs/store/states/geometry.js +110 -0
  9. package/build/cjs/store/states/graphic.js +87 -0
  10. package/build/cjs/store/states/message.js +25 -0
  11. package/build/cjs/store/states/plugin.js +113 -0
  12. package/build/cjs/store/states/selection.js +226 -0
  13. package/build/cjs/store/states/structure.js +203 -0
  14. package/build/cjs/store/store.js +14 -0
  15. package/build/cjs/store/subscribtion/selection.js +47 -0
  16. package/build/cjs/store/subscribtion/subscribeToDrawing.js +9 -0
  17. package/build/cjs/types/ErrorTypes.js +2 -0
  18. package/build/cjs/types/IGraphicPackage.js +24 -0
  19. package/build/cjs/types/IStructurePatch.js +2 -0
  20. package/build/cjs/types/IStructureTree.js +27 -0
  21. package/build/cjs/types/index.js +16 -0
  22. package/build/cjs/utils/Math.js +33 -0
  23. package/build/cjs/utils/Measure.js +576 -0
  24. package/build/cjs/utils/Timing.js +34 -0
  25. package/build/{geometry → esm/geometry}/ThreeGeometryCreator.js +0 -0
  26. package/build/{geometry → esm/geometry}/index.js +0 -0
  27. package/build/{index.js → esm/index.js} +1 -0
  28. package/build/{store → esm/store}/index.js +5 -1
  29. package/build/{store → esm/store}/states/buerli.js +0 -0
  30. package/build/{store → esm/store}/states/canvas.js +0 -0
  31. package/build/{store → esm/store}/states/drawing.js +0 -0
  32. package/build/{store → esm/store}/states/geometry.js +0 -0
  33. package/build/{store → esm/store}/states/graphic.js +0 -0
  34. package/build/{store → esm/store}/states/message.js +0 -0
  35. package/build/{store → esm/store}/states/plugin.js +1 -8
  36. package/build/{store → esm/store}/states/selection.js +35 -12
  37. package/build/{store → esm/store}/states/structure.js +0 -0
  38. package/build/{store → esm/store}/store.js +0 -0
  39. package/build/esm/store/subscribtion/selection.js +42 -0
  40. package/build/esm/store/subscribtion/subscribeToDrawing.js +5 -0
  41. package/build/{types → esm/types}/ErrorTypes.js +0 -0
  42. package/build/{types → esm/types}/IGraphicPackage.js +0 -0
  43. package/build/{types → esm/types}/IStructurePatch.js +0 -0
  44. package/build/{types → esm/types}/IStructureTree.js +0 -0
  45. package/build/{types → esm/types}/index.js +0 -0
  46. package/build/{utils → esm/utils}/Math.js +0 -0
  47. package/build/{utils → esm/utils}/Measure.js +0 -0
  48. package/build/{utils → esm/utils}/Timing.js +4 -0
  49. package/build/{geometry → types/geometry}/ThreeGeometryCreator.d.ts +0 -0
  50. package/build/{geometry → types/geometry}/index.d.ts +0 -0
  51. package/build/types/index.d.ts +36 -4
  52. package/build/{store → types/store}/index.d.ts +3 -0
  53. package/build/{store → types/store}/states/buerli.d.ts +0 -0
  54. package/build/{store → types/store}/states/canvas.d.ts +0 -0
  55. package/build/{store → types/store}/states/drawing.d.ts +0 -0
  56. package/build/{store → types/store}/states/geometry.d.ts +0 -0
  57. package/build/{store → types/store}/states/graphic.d.ts +0 -0
  58. package/build/{store → types/store}/states/message.d.ts +0 -0
  59. package/build/{store → types/store}/states/plugin.d.ts +1 -1
  60. package/build/{store → types/store}/states/selection.d.ts +1 -0
  61. package/build/{store → types/store}/states/structure.d.ts +0 -0
  62. package/build/{store → types/store}/store.d.ts +0 -0
  63. package/build/types/store/subscribtion/selection.d.ts +5 -0
  64. package/build/types/store/subscribtion/subscribeToDrawing.d.ts +2 -0
  65. package/build/types/{ErrorTypes.d.ts → types/ErrorTypes.d.ts} +0 -0
  66. package/build/types/{IGraphicPackage.d.ts → types/IGraphicPackage.d.ts} +0 -0
  67. package/build/types/{IStructurePatch.d.ts → types/IStructurePatch.d.ts} +0 -0
  68. package/build/types/{IStructureTree.d.ts → types/IStructureTree.d.ts} +0 -1
  69. package/build/types/types/index.d.ts +4 -0
  70. package/build/{utils → types/utils}/Math.d.ts +0 -0
  71. package/build/{utils → types/utils}/Measure.d.ts +0 -0
  72. package/build/{utils → types/utils}/Timing.d.ts +0 -0
  73. package/package.json +9 -6
  74. package/build/index.d.ts +0 -35
@@ -1,3 +1,4 @@
1
+ import { subscribeItems, unsubscribeItems } from '../subscribtion/selection';
1
2
  ////////////////////////////////////////////////////
2
3
  // CONSTANTS
3
4
  ////////////////////////////////////////////////////
@@ -8,8 +9,11 @@ export const selectionData = () => ({
8
9
  });
9
10
  export const selectionApi = (set, get) => ({
10
11
  unselectAll() {
12
+ const drawingId = get().id;
11
13
  const activeSelector = get().selection.active;
12
14
  if (activeSelector) {
15
+ const unselItems = get().selection.refs[activeSelector].items;
16
+ unsubscribeItems(drawingId, activeSelector, unselItems);
13
17
  set(state => {
14
18
  const selector = state.selection.refs[activeSelector];
15
19
  return {
@@ -19,12 +23,13 @@ export const selectionApi = (set, get) => ({
19
23
  }
20
24
  },
21
25
  unselect(...unselItems) {
22
- const { selection } = get();
26
+ const { selection, id: drawingId } = get();
23
27
  const activeSelectorId = selection.active;
24
28
  if (activeSelectorId) {
25
29
  // Remove unselItems from selector's items
26
30
  const selector = selection.refs[activeSelectorId];
27
31
  const newItems = selector.items.filter(item => unselItems.find(uItem => uItem.id === item.id) === undefined);
32
+ unsubscribeItems(drawingId, activeSelectorId, unselItems);
28
33
  if (selector.customUnSelect) {
29
34
  // Find recently unselected items
30
35
  const diff = selector.items.filter(item1 => {
@@ -43,7 +48,7 @@ export const selectionApi = (set, get) => ({
43
48
  }
44
49
  },
45
50
  select(...newItems) {
46
- const { selection, api } = get();
51
+ const { selection, api, id: drawingId } = get();
47
52
  const activeSelectorId = selection.active;
48
53
  const { isItemSelected } = api.selection;
49
54
  if (activeSelectorId) {
@@ -53,20 +58,25 @@ export const selectionApi = (set, get) => ({
53
58
  let filteredItems = newItems.filter((item1, idx) => newItems.findIndex(item2 => item2.id === item1.id) === idx);
54
59
  // Remove already selected items and duplicates
55
60
  filteredItems = filteredItems.filter(item => !isItemSelected(item, activeSelectorId));
61
+ let unsubItems = [];
56
62
  let result = [...curItems, ...filteredItems];
57
63
  if (selector.maxLen > 0) {
58
64
  if (filteredItems.length === selector.maxLen) {
59
65
  result = [...filteredItems];
66
+ unsubItems = [...curItems];
60
67
  }
61
68
  else if (filteredItems.length > selector.maxLen) {
62
69
  const extraItems = filteredItems.length - selector.maxLen;
63
70
  // If filteredItems has bigger length then selector.maxLen, remove last few items from filteredItems.
64
71
  result = filteredItems.slice(0, -extraItems);
72
+ unsubItems = [...curItems];
65
73
  }
66
74
  else if (filteredItems.length + curItems.length >= selector.maxLen) {
67
75
  const extraItems = filteredItems.length + curItems.length - selector.maxLen;
76
+ const allItems = [...curItems, ...filteredItems];
68
77
  // If filteredItems.len + curItems.len > selector.maxLen, remove first few items from union of curItems and filteredItems.
69
- result = [...curItems, ...filteredItems].slice(extraItems);
78
+ result = allItems.slice(extraItems);
79
+ unsubItems = allItems.slice(0, extraItems);
70
80
  }
71
81
  }
72
82
  if (selector.customSelect !== undefined) {
@@ -77,6 +87,10 @@ export const selectionApi = (set, get) => ({
77
87
  selector.customSelect(activeSelectorId, result, diff);
78
88
  }
79
89
  else {
90
+ // subscribe items which will be selected
91
+ subscribeItems(drawingId, activeSelectorId, result);
92
+ // unsubscribe items which will be unselected
93
+ unsubscribeItems(drawingId, activeSelectorId, unsubItems);
80
94
  set(state => {
81
95
  return {
82
96
  selection: Object.assign(Object.assign({}, state.selection), { refs: Object.assign(Object.assign({}, state.selection.refs), { [activeSelectorId]: Object.assign(Object.assign({}, selector), { items: result }) }) }),
@@ -121,15 +135,19 @@ export const selectionApi = (set, get) => ({
121
135
  customUnSelect,
122
136
  } }) }),
123
137
  }));
124
- return () => get &&
125
- get() &&
126
- set(state => {
127
- const refs = state.selection.refs;
128
- delete refs[selectorId];
129
- return {
130
- selection: Object.assign(Object.assign({}, state.selection), { active: state.selection.active === selectorId ? null : state.selection.active, refs }),
131
- };
132
- });
138
+ return () => {
139
+ if (get && get()) {
140
+ const drawingId = get().id;
141
+ unsubscribeItems(drawingId, selectorId);
142
+ set(state => {
143
+ const refs = state.selection.refs;
144
+ delete refs[selectorId];
145
+ return {
146
+ selection: Object.assign(Object.assign({}, state.selection), { active: state.selection.active === selectorId ? null : state.selection.active, refs }),
147
+ };
148
+ });
149
+ }
150
+ };
133
151
  },
134
152
  areItemsSelected: (items, selectorId) => {
135
153
  const { selection } = get();
@@ -155,6 +173,11 @@ export const selectionApi = (set, get) => ({
155
173
  return Boolean(selector.items.find(i => areItemsEqual(i, item)));
156
174
  },
157
175
  setItems(id, items) {
176
+ var _a;
177
+ const { selection, id: drawingId } = get();
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);
158
181
  set(state => {
159
182
  const selector = state.selection.refs[id];
160
183
  return {
File without changes
File without changes
@@ -0,0 +1,42 @@
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
+ import { subscribeToDrawing } from './subscribeToDrawing';
4
+ // This object contains unsubscibe function for all existing selections in all drawings
5
+ export const unsubs = {};
6
+ function getId(selectorId, itemId) {
7
+ return `${selectorId}_${itemId}`;
8
+ }
9
+ export function subscribeItems(drawingId, selectorId, items) {
10
+ const items_ = items || getDrawing(drawingId).selection.refs[selectorId].items;
11
+ items_.forEach(item => {
12
+ subscribeItem(drawingId, selectorId, item);
13
+ });
14
+ }
15
+ function subscribeItem(drawingId, selectorId, item) {
16
+ 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) => {
19
+ var _a;
20
+ // Unselect item whose removeCondition got true
21
+ if (removeCond) {
22
+ const newItems = ((_a = getDrawing(drawingId).selection.refs[selectorId]) === null || _a === void 0 ? void 0 : _a.items) || [];
23
+ selApi.setItems(selectorId, newItems.filter(item_ => item_.id !== item.id));
24
+ }
25
+ });
26
+ }
27
+ }
28
+ export function unsubscribeItems(drawingId, selectorId, items) {
29
+ const items_ = items || getDrawing(drawingId).selection.refs[selectorId].items;
30
+ items_.forEach(item => {
31
+ unsubscribeItem(selectorId, item);
32
+ });
33
+ }
34
+ function unsubscribeItem(selectorId, item) {
35
+ if (item.removeCondition) {
36
+ const id = getId(selectorId, item.id);
37
+ if (unsubs[id]) {
38
+ unsubs[id]();
39
+ delete unsubs[id];
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,5 @@
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]));
4
+ return unsub;
5
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -5,12 +5,16 @@ const start = (key = uuidv4()) => {
5
5
  return key;
6
6
  };
7
7
  const measure = (key, mode = 'fromStart') => {
8
+ if (!cache[key])
9
+ return Number.NaN;
8
10
  const curr = performance.now();
9
11
  const prev = mode === 'fromPrevious' ? cache[key].previousTime : cache[key].startTime;
10
12
  cache[key] = Object.assign(Object.assign({}, cache[key]), { previousTime: curr });
11
13
  return curr - prev;
12
14
  };
13
15
  const stop = (key) => {
16
+ if (!cache[key])
17
+ return Number.NaN;
14
18
  const curr = performance.now();
15
19
  const prev = cache[key].startTime;
16
20
  delete cache[key];
File without changes
@@ -1,4 +1,36 @@
1
- export * from './ErrorTypes';
2
- export * from './IGraphicPackage';
3
- export * from './IStructurePatch';
4
- export * from './IStructureTree';
1
+ export * from './store';
2
+ export * from './geometry';
3
+ export * from './types';
4
+ export * from './utils/Math';
5
+ export * from './utils/Measure';
6
+ export * from './utils/Timing';
7
+ export * from './store/subscribtion/subscribeToDrawing';
8
+ /**
9
+ * Because babel typescript tools can not handle the type definitions
10
+ * in an other way, they have to be re-exported as you can see in this code region.
11
+ *
12
+ * Please have a look at https://github.com/awv-informatik/buerli/pull/129 for more information.
13
+ */
14
+ import { BuerliState as BS } from './store/states/buerli';
15
+ export declare type BuerliState = BS;
16
+ import { DrawingAPI as DrawingAPI1, DrawingID as DrawingID1, DrawingState as DrawingState1 } from './store/states/drawing';
17
+ export declare type DrawingID = DrawingID1;
18
+ export declare type DrawingState = DrawingState1;
19
+ export declare type DrawingAPI = DrawingAPI1;
20
+ import { GeometryConfig as GeometryConfig1, GeometryBounds as GeometryBounds1 } from './store/states/geometry';
21
+ export declare type GeometryConfig = GeometryConfig1;
22
+ export declare type GeometryBounds = GeometryBounds1;
23
+ import { Plugin as Plugin1, PluginDescription as PluginDescription1, PluginID as PluginID1, PluginState as PluginState1 } from './store/states/plugin';
24
+ export declare type Plugin = Plugin1;
25
+ export declare type PluginDescription<InternalState = any> = PluginDescription1<InternalState>;
26
+ export declare type PluginID = PluginID1;
27
+ export declare type PluginState<InternalState = any> = PluginState1<InternalState>;
28
+ import { SeletedItemData, SelectedItem as SelectedItem1, SelectionFilter as SelectionFilter1, SelectionScope as SelectionScope1, Selector as Selector1, SelectorID as SelectorID1, CustomSelect as CustomSelect1 } from './store/states/selection';
29
+ export declare type SelectedItem<T extends SeletedItemData<any> = any> = SelectedItem1<T>;
30
+ export declare type SelectionFilter = SelectionFilter1;
31
+ export declare type SelectionScope = SelectionScope1;
32
+ export declare type Selector<T extends SeletedItemData<any> = any> = Selector1<T>;
33
+ export declare type SelectorID = SelectorID1;
34
+ export declare type CustomSelect = CustomSelect1;
35
+ import { Message as Message1 } from './store/states/message';
36
+ export declare type Message = Message1;
@@ -3,6 +3,9 @@ import { DrawingID, DrawingState } from './states/drawing';
3
3
  import { Message, MessageID } from './states/message';
4
4
  import { PluginID, PluginState } from './states/plugin';
5
5
  declare function getDrawing(id: DrawingID): DrawingState;
6
+ /**
7
+ * @returns PluginState or undefined if either drawing or plugin don't exist
8
+ */
6
9
  declare function getPlugin(drawingId: DrawingID, pluginId: PluginID): PluginState;
7
10
  declare function init(sel?: Partial<BuerliOptions> | ((state: BuerliState) => Partial<BuerliOptions>)): void;
8
11
  declare function showMessage(message: Message): MessageID;
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -43,7 +43,7 @@ export declare type PluginData = {
43
43
  export declare type PluginApi = ReturnType<typeof pluginApi>;
44
44
  export declare const pluginData: () => PluginData;
45
45
  export declare const pluginApi: (set: SetState<DrawingState>, get: GetState<DrawingState>) => {
46
- setActiveFeature: (id: PluginID | null) => void;
46
+ setActiveFeature: (id: ObjectID | null) => void;
47
47
  setVisiblePlugin: (id: PluginID, visible: boolean) => void;
48
48
  setActiveGlobal: (id: PluginID, active: boolean) => void;
49
49
  createPlugin: (def: PluginDef, defaultId?: string | number | undefined, drawingId?: string | number | undefined, objectId?: number | undefined) => (deactivate?: boolean) => void;
@@ -12,6 +12,7 @@ export declare type SelectedItem<T extends SeletedItemData<any> = any> = {
12
12
  readonly scope: SelectionScope;
13
13
  readonly data: T;
14
14
  readonly label?: any;
15
+ readonly removeCondition?: (d: DrawingState) => boolean;
15
16
  };
16
17
  export declare type SelectionFilter = (scope: SelectionScope, data: any) => boolean;
17
18
  export declare type CustomSelect = (selectorId: SelectorID, newItems: SelectedItem[], diff: SelectedItem[]) => void;
File without changes
@@ -0,0 +1,5 @@
1
+ import { SelectorID, DrawingID } from '../..';
2
+ import { SelectedItem } from '../states/selection';
3
+ 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;
@@ -0,0 +1,2 @@
1
+ import { DrawingID, DrawingState } from '../states/drawing';
2
+ export declare function subscribeToDrawing(drawingId: DrawingID, sel: (d: DrawingState) => any, callback: (arg: any) => void): () => void;
@@ -36,7 +36,6 @@ export interface IStructureObject {
36
36
  visible?: boolean;
37
37
  dimensions?: ObjectID[];
38
38
  expressionSet?: ObjectID;
39
- features?: ObjectID[];
40
39
  geometrySet?: ObjectID;
41
40
  solids?: number[];
42
41
  instances?: ObjectID[];
@@ -0,0 +1,4 @@
1
+ export * from './ErrorTypes';
2
+ export * from './IGraphicPackage';
3
+ export * from './IStructurePatch';
4
+ export * from './IStructureTree';
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "@buerli.io/core",
3
- "version": "0.0.34-beta.0",
3
+ "version": "0.0.35-beta.1",
4
4
  "description": "buerli state management",
5
5
  "author": "AWV Informatik AG <info@awv-informatik.ch>",
6
6
  "repository": {},
7
- "main": "build/index.js",
8
- "module": "build/index.js",
9
- "types": "build/index.d.ts",
7
+ "main": "build/cjs/index.js",
8
+ "module": "build/esm/index.js",
9
+ "types": "build/types/index.d.ts",
10
10
  "sideEffects": false,
11
11
  "scripts": {
12
12
  "ver": "npm version",
13
13
  "prepack": "npm run build:dist",
14
14
  "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",
15
+ "build": "npm run build:esm -- --sourceMap true --declaration true --declarationDir ./build/types",
16
+ "build:dist": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:types && echo DONE",
17
+ "build:esm": "tsc --target es2017 --module esNext --declaration false --declarationDir null --sourceMap false --outDir ./build/esm",
18
+ "build:cjs": "tsc --target es2017 --module commonjs --declaration false --declarationDir null --sourceMap false --outDir ./build/cjs",
19
+ "build:types": "tsc --declaration --emitDeclarationOnly --outDir ./build/types",
17
20
  "lint": "eslint \"./src/**/*.ts?(x)\"",
18
21
  "test": "jest",
19
22
  "coverage": "npm run clean && npm run build && npm run jestLite -- --coverage",
package/build/index.d.ts DELETED
@@ -1,35 +0,0 @@
1
- export * from './store';
2
- export * from './geometry';
3
- export * from './types';
4
- export * from './utils/Math';
5
- export * from './utils/Measure';
6
- export * from './utils/Timing';
7
- /**
8
- * Because babel typescript tools can not handle the type definitions
9
- * in an other way, they have to be re-exported as you can see in this code region.
10
- *
11
- * Please have a look at https://github.com/awv-informatik/buerli/pull/129 for more information.
12
- */
13
- import { BuerliState as BS } from './store/states/buerli';
14
- export declare type BuerliState = BS;
15
- import { DrawingAPI as DrawingAPI1, DrawingID as DrawingID1, DrawingState as DrawingState1 } from './store/states/drawing';
16
- export declare type DrawingID = DrawingID1;
17
- export declare type DrawingState = DrawingState1;
18
- export declare type DrawingAPI = DrawingAPI1;
19
- import { GeometryConfig as GeometryConfig1, GeometryBounds as GeometryBounds1 } from './store/states/geometry';
20
- export declare type GeometryConfig = GeometryConfig1;
21
- export declare type GeometryBounds = GeometryBounds1;
22
- import { Plugin as Plugin1, PluginDescription as PluginDescription1, PluginID as PluginID1, PluginState as PluginState1 } from './store/states/plugin';
23
- export declare type Plugin = Plugin1;
24
- export declare type PluginDescription<InternalState = any> = PluginDescription1<InternalState>;
25
- export declare type PluginID = PluginID1;
26
- export declare type PluginState<InternalState = any> = PluginState1<InternalState>;
27
- import { SeletedItemData, SelectedItem as SelectedItem1, SelectionFilter as SelectionFilter1, SelectionScope as SelectionScope1, Selector as Selector1, SelectorID as SelectorID1, CustomSelect as CustomSelect1 } from './store/states/selection';
28
- export declare type SelectedItem<T extends SeletedItemData<any> = any> = SelectedItem1<T>;
29
- export declare type SelectionFilter = SelectionFilter1;
30
- export declare type SelectionScope = SelectionScope1;
31
- export declare type Selector<T extends SeletedItemData<any> = any> = Selector1<T>;
32
- export declare type SelectorID = SelectorID1;
33
- export declare type CustomSelect = CustomSelect1;
34
- import { Message as Message1 } from './store/states/message';
35
- export declare type Message = Message1;