@buerli.io/headless 1.0.1-beta.2 → 1.0.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.
@@ -1,20 +1,20 @@
1
- /**
2
- * Get all meshes in a map, sorted by their color / opacity
3
- * @param entity entity to look for the meshes
4
- * @returns map (key = color/opacity as string, value = object containing the meshes, color and opacity)
5
- */
6
- export const getDifferentColoredMeshesFromEntity = (entity) => {
7
- const colorMeshesMap = {};
8
- entity.meshes.forEach(mesh => {
9
- const color = mesh.color ? mesh.color : entity.color;
10
- const opacity = mesh.opacity ? mesh.opacity : entity.opacity;
11
- const key = (color === null || color === void 0 ? void 0 : color.getHexString()) + (opacity === null || opacity === void 0 ? void 0 : opacity.toString());
12
- if (colorMeshesMap[key]) {
13
- colorMeshesMap[key].meshes.push(mesh);
14
- }
15
- else {
16
- colorMeshesMap[key] = { meshes: [mesh], color, opacity };
17
- }
18
- });
19
- return colorMeshesMap;
20
- };
1
+ /**
2
+ * Get all meshes in a map, sorted by their color / opacity
3
+ * @param entity entity to look for the meshes
4
+ * @returns map (key = color/opacity as string, value = object containing the meshes, color and opacity)
5
+ */
6
+ export const getDifferentColoredMeshesFromEntity = (entity) => {
7
+ const colorMeshesMap = {};
8
+ entity.meshes.forEach(mesh => {
9
+ const color = mesh.color ? mesh.color : entity.color;
10
+ const opacity = mesh.opacity ? mesh.opacity : entity.opacity;
11
+ const key = (color === null || color === void 0 ? void 0 : color.getHexString()) + (opacity === null || opacity === void 0 ? void 0 : opacity.toString());
12
+ if (colorMeshesMap[key]) {
13
+ colorMeshesMap[key].meshes.push(mesh);
14
+ }
15
+ else {
16
+ colorMeshesMap[key] = { meshes: [mesh], color, opacity };
17
+ }
18
+ });
19
+ return colorMeshesMap;
20
+ };
@@ -1,25 +1,25 @@
1
- import { api, getDrawing } from '@buerli.io/core';
2
- import { v4 } from 'uuid';
3
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4
- // @ts-ignore
5
- import createPromise from 'flat-promise';
6
- export async function waitForSelect(length, filter, onChange) {
7
- const id = v4();
8
- const activeDrawingId = api.getState().drawing.active;
9
- const selApi = activeDrawingId && getDrawing(activeDrawingId).api.selection;
10
- // Set up selection API
11
- const { promise, resolve } = createPromise();
12
- const change = (selId, items, diff) => {
13
- selApi && selApi.setItems(selId, items);
14
- if (onChange)
15
- onChange(resolve, items, diff);
16
- };
17
- const unsub = selApi && selApi.createSelector(id, filter, false, [], length, change, change);
18
- // Wait for user interaction
19
- selApi && selApi.activateSelector(id);
20
- const result = await promise;
21
- // Unsubscribe from all selections
22
- unsub && unsub();
23
- selApi && selApi.activateSelector(null);
24
- return result;
25
- }
1
+ import { api, getDrawing } from '@buerli.io/core';
2
+ import { v4 } from 'uuid';
3
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4
+ // @ts-ignore
5
+ import createPromise from 'flat-promise';
6
+ export async function waitForSelect(length, filter, onChange) {
7
+ const id = v4();
8
+ const activeDrawingId = api.getState().drawing.active;
9
+ const selApi = activeDrawingId && getDrawing(activeDrawingId).api.selection;
10
+ // Set up selection API
11
+ const { promise, resolve } = createPromise();
12
+ const change = (selId, items, diff) => {
13
+ selApi && selApi.setItems(selId, items);
14
+ if (onChange)
15
+ onChange(resolve, items, diff);
16
+ };
17
+ const unsub = selApi && selApi.createSelector(id, filter, false, [], length, change, change);
18
+ // Wait for user interaction
19
+ selApi && selApi.activateSelector(id);
20
+ const result = await promise;
21
+ // Unsubscribe from all selections
22
+ unsub && unsub();
23
+ selApi && selApi.activateSelector(null);
24
+ return result;
25
+ }