@insync-stageplayer/annotations 0.4.7 → 0.4.8

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 (41) hide show
  1. package/lib/components/AnnotationContent.d.ts +37 -37
  2. package/lib/components/AnnotationContent.js +59 -59
  3. package/lib/components/AnnotationEditForm.d.ts +26 -26
  4. package/lib/components/AnnotationEditForm.js +146 -146
  5. package/lib/components/AnnotationsModuleProvider.d.ts +36 -36
  6. package/lib/components/AnnotationsModuleProvider.js +20 -20
  7. package/lib/components/AnnotationsViewer.d.ts +15 -15
  8. package/lib/components/AnnotationsViewer.js +107 -107
  9. package/lib/components/DraggablePosition.d.ts +31 -31
  10. package/lib/components/DraggablePosition.js +62 -62
  11. package/lib/components/MeasurementDisplayDataContext.d.ts +10 -10
  12. package/lib/components/MeasurementDisplayDataContext.js +2 -2
  13. package/lib/components/MeasurementDisplayDataProvider.d.ts +15 -15
  14. package/lib/components/MeasurementDisplayDataProvider.js +45 -45
  15. package/lib/components/MeasurementDisplayEditor.d.ts +19 -19
  16. package/lib/components/MeasurementDisplayEditor.js +136 -136
  17. package/lib/components/MeasurementDisplayElement.d.ts +18 -18
  18. package/lib/components/MeasurementDisplayElement.js +97 -97
  19. package/lib/components/ModalAnnotationEditor.d.ts +12 -12
  20. package/lib/components/ModalAnnotationEditor.js +37 -37
  21. package/lib/formatNumber.d.ts +29 -29
  22. package/lib/formatNumber.js +12 -12
  23. package/lib/index.d.ts +7 -7
  24. package/lib/index.js +7 -7
  25. package/lib/redux/actions.d.ts +1 -1
  26. package/lib/redux/actions.js +1 -1
  27. package/lib/redux/annotationEditor.slice.d.ts +37 -37
  28. package/lib/redux/annotationEditor.slice.js +122 -122
  29. package/lib/redux/annotations.slice.d.ts +31 -31
  30. package/lib/redux/annotations.slice.js +65 -65
  31. package/lib/redux/measurementDisplayEditor.slice.d.ts +25 -25
  32. package/lib/redux/measurementDisplayEditor.slice.js +36 -36
  33. package/lib/redux/measurementDisplays.slice.d.ts +25 -25
  34. package/lib/redux/measurementDisplays.slice.js +22 -22
  35. package/lib/redux/reducer.d.ts +51 -51
  36. package/lib/redux/reducer.js +65 -65
  37. package/lib/useBoundingRect.d.ts +8 -8
  38. package/lib/useBoundingRect.js +27 -27
  39. package/lib/util.d.ts +5 -5
  40. package/lib/util.js +7 -7
  41. package/package.json +5 -5
@@ -1,66 +1,66 @@
1
- import { isPosition2D, isUnknownObject, } from "@insync-stageplayer/common";
2
- import { createEntityAdapter, createSlice, } from "@reduxjs/toolkit";
3
- /**
4
- * Checks if an argument is a valid annotation.
5
- * @param arg
6
- * @returns
7
- */
8
- export function isAnnotation(arg) {
9
- return (isUnknownObject(arg) &&
10
- typeof arg.id === "string" &&
11
- Array.isArray(arg.content) &&
12
- isPosition2D(arg.position));
13
- }
14
- /**
15
- * Please read up https://redux-toolkit.js.org/usage/usage-with-typescript#createentityadapter to understand what this is.
16
- */
17
- export const annotationsAdapter = createEntityAdapter();
18
- const defaultAnnotation = {
19
- /**
20
- * Place the annotation in the center of the plane.
21
- */
22
- position: {
23
- x: 0.5,
24
- y: 0.5,
25
- },
26
- content: [
27
- {
28
- type: "paragraph",
29
- children: [{ text: "" }],
30
- },
31
- ],
32
- };
33
- const annotationsSlice = createSlice({
34
- name: "annotations",
35
- initialState: annotationsAdapter.getInitialState({
36
- editingAnnotation: undefined,
37
- }),
38
- reducers: {
39
- createAnnotations: annotationsAdapter.addMany,
40
- updateAnnotation: annotationsAdapter.updateOne,
41
- deleteAnnotation: annotationsAdapter.removeOne,
42
- createAnnotation: (state, action) => {
43
- annotationsAdapter.addOne(state, Object.assign({ id: action.payload }, defaultAnnotation));
44
- state.editingAnnotation = action.payload;
45
- },
46
- editAnnotation: (state, action) => {
47
- state.editingAnnotation = action.payload;
48
- },
49
- editAnnotationCancel: (state) => {
50
- state.editingAnnotation = undefined;
51
- },
52
- editAnnotationSubmit: (state, action) => {
53
- annotationsAdapter.upsertOne(state, action);
54
- state.editingAnnotation = undefined;
55
- },
56
- editAnnotationDelete: (state) => {
57
- if (state.editingAnnotation) {
58
- annotationsAdapter.removeOne(state, state.editingAnnotation);
59
- }
60
- state.editingAnnotation = undefined;
61
- },
62
- },
63
- });
64
- export const { editAnnotation, editAnnotationCancel, editAnnotationSubmit, editAnnotationDelete, createAnnotation, createAnnotations, updateAnnotation, deleteAnnotation, } = annotationsSlice.actions;
65
- export default annotationsSlice.reducer;
1
+ import { isPosition2D, isUnknownObject, } from "@insync-stageplayer/common";
2
+ import { createEntityAdapter, createSlice, } from "@reduxjs/toolkit";
3
+ /**
4
+ * Checks if an argument is a valid annotation.
5
+ * @param arg
6
+ * @returns
7
+ */
8
+ export function isAnnotation(arg) {
9
+ return (isUnknownObject(arg) &&
10
+ typeof arg.id === "string" &&
11
+ Array.isArray(arg.content) &&
12
+ isPosition2D(arg.position));
13
+ }
14
+ /**
15
+ * Please read up https://redux-toolkit.js.org/usage/usage-with-typescript#createentityadapter to understand what this is.
16
+ */
17
+ export const annotationsAdapter = createEntityAdapter();
18
+ const defaultAnnotation = {
19
+ /**
20
+ * Place the annotation in the center of the plane.
21
+ */
22
+ position: {
23
+ x: 0.5,
24
+ y: 0.5,
25
+ },
26
+ content: [
27
+ {
28
+ type: "paragraph",
29
+ children: [{ text: "" }],
30
+ },
31
+ ],
32
+ };
33
+ const annotationsSlice = createSlice({
34
+ name: "annotations",
35
+ initialState: annotationsAdapter.getInitialState({
36
+ editingAnnotation: undefined,
37
+ }),
38
+ reducers: {
39
+ createAnnotations: annotationsAdapter.addMany,
40
+ updateAnnotation: annotationsAdapter.updateOne,
41
+ deleteAnnotation: annotationsAdapter.removeOne,
42
+ createAnnotation: (state, action) => {
43
+ annotationsAdapter.addOne(state, Object.assign({ id: action.payload }, defaultAnnotation));
44
+ state.editingAnnotation = action.payload;
45
+ },
46
+ editAnnotation: (state, action) => {
47
+ state.editingAnnotation = action.payload;
48
+ },
49
+ editAnnotationCancel: (state) => {
50
+ state.editingAnnotation = undefined;
51
+ },
52
+ editAnnotationSubmit: (state, action) => {
53
+ annotationsAdapter.upsertOne(state, action);
54
+ state.editingAnnotation = undefined;
55
+ },
56
+ editAnnotationDelete: (state) => {
57
+ if (state.editingAnnotation) {
58
+ annotationsAdapter.removeOne(state, state.editingAnnotation);
59
+ }
60
+ state.editingAnnotation = undefined;
61
+ },
62
+ },
63
+ });
64
+ export const { editAnnotation, editAnnotationCancel, editAnnotationSubmit, editAnnotationDelete, createAnnotation, createAnnotations, updateAnnotation, deleteAnnotation, } = annotationsSlice.actions;
65
+ export default annotationsSlice.reducer;
66
66
  //# sourceMappingURL=annotations.slice.js.map
@@ -1,26 +1,26 @@
1
- declare const initialState: {
2
- editingDisplay: string | undefined;
3
- /**
4
- * Keeps track of the displays we deleted, if the form is submitted, we can delete these.
5
- */
6
- deletedDisplays: string[];
7
- /**
8
- * Keeps track of displays we created, if the form is cancelled, we can remove all created displays.
9
- */
10
- createdDisplays: string[];
11
- };
12
- export declare const editMeasurementDisplay: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>, finishEditMeasurementDisplay: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>;
13
- export declare type MeasurementDisplayEditorState = typeof initialState;
14
- declare const _default: import("redux").Reducer<{
15
- editingDisplay: string | undefined;
16
- /**
17
- * Keeps track of the displays we deleted, if the form is submitted, we can delete these.
18
- */
19
- deletedDisplays: string[];
20
- /**
21
- * Keeps track of displays we created, if the form is cancelled, we can remove all created displays.
22
- */
23
- createdDisplays: string[];
24
- }, import("redux").AnyAction>;
25
- export default _default;
1
+ declare const initialState: {
2
+ editingDisplay: string | undefined;
3
+ /**
4
+ * Keeps track of the displays we deleted, if the form is submitted, we can delete these.
5
+ */
6
+ deletedDisplays: string[];
7
+ /**
8
+ * Keeps track of displays we created, if the form is cancelled, we can remove all created displays.
9
+ */
10
+ createdDisplays: string[];
11
+ };
12
+ export declare const editMeasurementDisplay: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>, finishEditMeasurementDisplay: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>;
13
+ export declare type MeasurementDisplayEditorState = typeof initialState;
14
+ declare const _default: import("redux").Reducer<{
15
+ editingDisplay: string | undefined;
16
+ /**
17
+ * Keeps track of the displays we deleted, if the form is submitted, we can delete these.
18
+ */
19
+ deletedDisplays: string[];
20
+ /**
21
+ * Keeps track of displays we created, if the form is cancelled, we can remove all created displays.
22
+ */
23
+ createdDisplays: string[];
24
+ }, import("redux").AnyAction>;
25
+ export default _default;
26
26
  //# sourceMappingURL=measurementDisplayEditor.slice.d.ts.map
@@ -1,37 +1,37 @@
1
- import { createSlice } from "@reduxjs/toolkit";
2
- const initialState = {
3
- editingDisplay: undefined,
4
- /**
5
- * Keeps track of the displays we deleted, if the form is submitted, we can delete these.
6
- */
7
- deletedDisplays: [],
8
- /**
9
- * Keeps track of displays we created, if the form is cancelled, we can remove all created displays.
10
- */
11
- createdDisplays: [],
12
- };
13
- const measurementDisplayEditorSlice = createSlice({
14
- name: "measurementDisplayEditor",
15
- initialState,
16
- reducers: {
17
- editMeasurementDisplay: (state, action) => {
18
- state.editingDisplay = action.payload;
19
- },
20
- deleteMeasurementDisplay: (state, action) => {
21
- state.deletedDisplays.push(action.payload);
22
- },
23
- finishEditMeasurementDisplay: (state) => {
24
- state.editingDisplay = undefined;
25
- },
26
- },
27
- extraReducers: (builder) => {
28
- /*
29
- builder.addCase(finishEditAnnotation, (state, action) => {
30
- state.editingDisplay = undefined;
31
- });
32
- */
33
- },
34
- });
35
- export const { editMeasurementDisplay, finishEditMeasurementDisplay } = measurementDisplayEditorSlice.actions;
36
- export default measurementDisplayEditorSlice.reducer;
1
+ import { createSlice } from "@reduxjs/toolkit";
2
+ const initialState = {
3
+ editingDisplay: undefined,
4
+ /**
5
+ * Keeps track of the displays we deleted, if the form is submitted, we can delete these.
6
+ */
7
+ deletedDisplays: [],
8
+ /**
9
+ * Keeps track of displays we created, if the form is cancelled, we can remove all created displays.
10
+ */
11
+ createdDisplays: [],
12
+ };
13
+ const measurementDisplayEditorSlice = createSlice({
14
+ name: "measurementDisplayEditor",
15
+ initialState,
16
+ reducers: {
17
+ editMeasurementDisplay: (state, action) => {
18
+ state.editingDisplay = action.payload;
19
+ },
20
+ deleteMeasurementDisplay: (state, action) => {
21
+ state.deletedDisplays.push(action.payload);
22
+ },
23
+ finishEditMeasurementDisplay: (state) => {
24
+ state.editingDisplay = undefined;
25
+ },
26
+ },
27
+ extraReducers: (builder) => {
28
+ /*
29
+ builder.addCase(finishEditAnnotation, (state, action) => {
30
+ state.editingDisplay = undefined;
31
+ });
32
+ */
33
+ },
34
+ });
35
+ export const { editMeasurementDisplay, finishEditMeasurementDisplay } = measurementDisplayEditorSlice.actions;
36
+ export default measurementDisplayEditorSlice.reducer;
37
37
  //# sourceMappingURL=measurementDisplayEditor.slice.js.map
@@ -1,26 +1,26 @@
1
- /**
2
- * An annotation that can be placed on a 2D surface
3
- */
4
- export declare type MeasurementDisplay = {
5
- /**
6
- * Id of
7
- */
8
- id: string;
9
- showX: boolean;
10
- showY: boolean;
11
- showSignal: boolean;
12
- showSigColor: boolean;
13
- padXTo?: number;
14
- padXChar?: string;
15
- padYTo?: number;
16
- padYChar?: string;
17
- decimalsX?: number;
18
- decimalsY?: number;
19
- measurementId: string;
20
- };
21
- export declare const measurementDisplaysAdapter: import("@reduxjs/toolkit").EntityAdapter<MeasurementDisplay>;
22
- export declare const selectAllMeasurementDisplays: MeasurementDisplay[];
23
- export declare const createMeasurementDisplay: import("@reduxjs/toolkit").ActionCreatorWithPayload<MeasurementDisplay, string>, updateMeasurementDisplay: import("@reduxjs/toolkit").ActionCreatorWithPayload<import("@reduxjs/toolkit").Update<MeasurementDisplay>, string>, deleteMeasurementDisplay: import("@reduxjs/toolkit").ActionCreatorWithPayload<import("@reduxjs/toolkit").EntityId, string>, deleteMeasurementDisplays: import("@reduxjs/toolkit").ActionCreatorWithPayload<import("@reduxjs/toolkit").EntityId[], string>;
24
- declare const _default: import("redux").Reducer<import("@reduxjs/toolkit").EntityState<MeasurementDisplay>, import("redux").AnyAction>;
25
- export default _default;
1
+ /**
2
+ * An annotation that can be placed on a 2D surface
3
+ */
4
+ export declare type MeasurementDisplay = {
5
+ /**
6
+ * Id of
7
+ */
8
+ id: string;
9
+ showX: boolean;
10
+ showY: boolean;
11
+ showSignal: boolean;
12
+ showSigColor: boolean;
13
+ padXTo?: number;
14
+ padXChar?: string;
15
+ padYTo?: number;
16
+ padYChar?: string;
17
+ decimalsX?: number;
18
+ decimalsY?: number;
19
+ measurementId: string;
20
+ };
21
+ export declare const measurementDisplaysAdapter: import("@reduxjs/toolkit").EntityAdapter<MeasurementDisplay>;
22
+ export declare const selectAllMeasurementDisplays: MeasurementDisplay[];
23
+ export declare const createMeasurementDisplay: import("@reduxjs/toolkit").ActionCreatorWithPayload<MeasurementDisplay, string>, updateMeasurementDisplay: import("@reduxjs/toolkit").ActionCreatorWithPayload<import("@reduxjs/toolkit").Update<MeasurementDisplay>, string>, deleteMeasurementDisplay: import("@reduxjs/toolkit").ActionCreatorWithPayload<import("@reduxjs/toolkit").EntityId, string>, deleteMeasurementDisplays: import("@reduxjs/toolkit").ActionCreatorWithPayload<import("@reduxjs/toolkit").EntityId[], string>;
24
+ declare const _default: import("redux").Reducer<import("@reduxjs/toolkit").EntityState<MeasurementDisplay>, import("redux").AnyAction>;
25
+ export default _default;
26
26
  //# sourceMappingURL=measurementDisplays.slice.d.ts.map
@@ -1,23 +1,23 @@
1
- import { createEntityAdapter, createSlice, configureStore, } from "@reduxjs/toolkit";
2
- export const measurementDisplaysAdapter = createEntityAdapter();
3
- const measurementDisplaysSlice = createSlice({
4
- name: "measurementDisplays",
5
- initialState: measurementDisplaysAdapter.getInitialState(),
6
- reducers: {
7
- createMeasurementDisplay: measurementDisplaysAdapter.addOne,
8
- updateMeasurementDisplay: measurementDisplaysAdapter.updateOne,
9
- deleteMeasurementDisplay: measurementDisplaysAdapter.removeOne,
10
- deleteMeasurementDisplays: measurementDisplaysAdapter.removeMany,
11
- },
12
- });
13
- const store = configureStore({
14
- reducer: {
15
- measurementDisplays: measurementDisplaysSlice.reducer,
16
- },
17
- });
18
- const measurementDisplaySelectors = measurementDisplaysAdapter.getSelectors((state) => state.measurementDisplays);
19
- // And then use the selectors to retrieve values
20
- export const selectAllMeasurementDisplays = measurementDisplaySelectors.selectAll(store.getState());
21
- export const { createMeasurementDisplay, updateMeasurementDisplay, deleteMeasurementDisplay, deleteMeasurementDisplays, } = measurementDisplaysSlice.actions;
22
- export default measurementDisplaysSlice.reducer;
1
+ import { createEntityAdapter, createSlice, configureStore, } from "@reduxjs/toolkit";
2
+ export const measurementDisplaysAdapter = createEntityAdapter();
3
+ const measurementDisplaysSlice = createSlice({
4
+ name: "measurementDisplays",
5
+ initialState: measurementDisplaysAdapter.getInitialState(),
6
+ reducers: {
7
+ createMeasurementDisplay: measurementDisplaysAdapter.addOne,
8
+ updateMeasurementDisplay: measurementDisplaysAdapter.updateOne,
9
+ deleteMeasurementDisplay: measurementDisplaysAdapter.removeOne,
10
+ deleteMeasurementDisplays: measurementDisplaysAdapter.removeMany,
11
+ },
12
+ });
13
+ const store = configureStore({
14
+ reducer: {
15
+ measurementDisplays: measurementDisplaysSlice.reducer,
16
+ },
17
+ });
18
+ const measurementDisplaySelectors = measurementDisplaysAdapter.getSelectors((state) => state.measurementDisplays);
19
+ // And then use the selectors to retrieve values
20
+ export const selectAllMeasurementDisplays = measurementDisplaySelectors.selectAll(store.getState());
21
+ export const { createMeasurementDisplay, updateMeasurementDisplay, deleteMeasurementDisplay, deleteMeasurementDisplays, } = measurementDisplaysSlice.actions;
22
+ export default measurementDisplaysSlice.reducer;
23
23
  //# sourceMappingURL=measurementDisplays.slice.js.map
@@ -1,52 +1,52 @@
1
- import { Annotation } from "./annotations.slice";
2
- export declare type AnnotationsModuleState = ReturnType<typeof slicesReducer>;
3
- declare const slicesReducer: import("redux").Reducer<import("redux").CombinedState<{
4
- annotations: import("@reduxjs/toolkit").EntityState<Annotation> & {
5
- editingAnnotation: string | undefined;
6
- };
7
- measurementDisplays: import("@reduxjs/toolkit").EntityState<import("./measurementDisplays.slice").MeasurementDisplay>;
8
- annotationEditor: {
9
- annotation: Omit<Annotation, "id"> & {
10
- id: string | undefined;
11
- };
12
- displays: {
13
- added: string[];
14
- deleted: string[];
15
- };
16
- pickingMeasurement: boolean;
17
- chosenMeasurement: string | null;
18
- pickingMeasurementError: Error | null;
19
- editingMeasurementDisplay: string | null;
20
- };
21
- measurementDisplayEditor: {
22
- editingDisplay: string | undefined;
23
- deletedDisplays: string[];
24
- createdDisplays: string[];
25
- };
26
- }>, import("redux").AnyAction>;
27
- export declare const annotationsModuleReducer: import("reduce-reducers").Reducer<import("redux").CombinedState<{
28
- annotations: import("@reduxjs/toolkit").EntityState<Annotation> & {
29
- editingAnnotation: string | undefined;
30
- };
31
- measurementDisplays: import("@reduxjs/toolkit").EntityState<import("./measurementDisplays.slice").MeasurementDisplay>;
32
- annotationEditor: {
33
- annotation: Omit<Annotation, "id"> & {
34
- id: string | undefined;
35
- };
36
- displays: {
37
- added: string[];
38
- deleted: string[];
39
- };
40
- pickingMeasurement: boolean;
41
- chosenMeasurement: string | null;
42
- pickingMeasurementError: Error | null;
43
- editingMeasurementDisplay: string | null;
44
- };
45
- measurementDisplayEditor: {
46
- editingDisplay: string | undefined;
47
- deletedDisplays: string[];
48
- createdDisplays: string[];
49
- };
50
- }>>;
51
- export {};
1
+ import { Annotation } from "./annotations.slice";
2
+ export declare type AnnotationsModuleState = ReturnType<typeof slicesReducer>;
3
+ declare const slicesReducer: import("redux").Reducer<import("redux").CombinedState<{
4
+ annotations: import("@reduxjs/toolkit").EntityState<Annotation> & {
5
+ editingAnnotation: string | undefined;
6
+ };
7
+ measurementDisplays: import("@reduxjs/toolkit").EntityState<import("./measurementDisplays.slice").MeasurementDisplay>;
8
+ annotationEditor: {
9
+ annotation: Omit<Annotation, "id"> & {
10
+ id: string | undefined;
11
+ };
12
+ displays: {
13
+ added: string[];
14
+ deleted: string[];
15
+ };
16
+ pickingMeasurement: boolean;
17
+ chosenMeasurement: string | null;
18
+ pickingMeasurementError: Error | null;
19
+ editingMeasurementDisplay: string | null;
20
+ };
21
+ measurementDisplayEditor: {
22
+ editingDisplay: string | undefined;
23
+ deletedDisplays: string[];
24
+ createdDisplays: string[];
25
+ };
26
+ }>, import("redux").AnyAction>;
27
+ export declare const annotationsModuleReducer: import("reduce-reducers").Reducer<import("redux").CombinedState<{
28
+ annotations: import("@reduxjs/toolkit").EntityState<Annotation> & {
29
+ editingAnnotation: string | undefined;
30
+ };
31
+ measurementDisplays: import("@reduxjs/toolkit").EntityState<import("./measurementDisplays.slice").MeasurementDisplay>;
32
+ annotationEditor: {
33
+ annotation: Omit<Annotation, "id"> & {
34
+ id: string | undefined;
35
+ };
36
+ displays: {
37
+ added: string[];
38
+ deleted: string[];
39
+ };
40
+ pickingMeasurement: boolean;
41
+ chosenMeasurement: string | null;
42
+ pickingMeasurementError: Error | null;
43
+ editingMeasurementDisplay: string | null;
44
+ };
45
+ measurementDisplayEditor: {
46
+ editingDisplay: string | undefined;
47
+ deletedDisplays: string[];
48
+ createdDisplays: string[];
49
+ };
50
+ }>>;
51
+ export {};
52
52
  //# sourceMappingURL=reducer.d.ts.map
@@ -1,66 +1,66 @@
1
- import { combineReducers } from "redux";
2
- import { createReducer } from "@reduxjs/toolkit";
3
- import reduceReducers from "reduce-reducers";
4
- import annotationEditorSlice from "./annotationEditor.slice";
5
- import annotationsSlice, { editAnnotationCancel, editAnnotationDelete, editAnnotationSubmit, } from "./annotations.slice";
6
- import measurementDisplayEditorSlice from "./measurementDisplayEditor.slice";
7
- import measurementDisplaysSlice, { measurementDisplaysAdapter, } from "./measurementDisplays.slice";
8
- const slicesReducer = combineReducers({
9
- annotations: annotationsSlice,
10
- measurementDisplays: measurementDisplaysSlice,
11
- annotationEditor: annotationEditorSlice,
12
- measurementDisplayEditor: measurementDisplayEditorSlice,
13
- });
14
- /**
15
- * An annotation can contain measurementDisplay elements in its content. The content consists of SlateJS nodes which
16
- * is a nested structure. This function returns a list of all measurementDisplays contained in this annotation.
17
- * @param annotation
18
- * @returns The ids of the measurementDisplays contained in this Annotation.
19
- */
20
- const getMeasurementDisplaysForAnnotation = (annotation) => {
21
- // The recursive function that goes through the nodes.
22
- const go = (node) => {
23
- if (node.type === "measurementDisplay") {
24
- return [node.measurementDisplayId];
25
- }
26
- if (Array.isArray(node.children)) {
27
- return node.children.reduce((acc, c) => [...acc, ...go(c)], []);
28
- }
29
- return [];
30
- };
31
- // Transforming the Annotation to a SlateJS node.
32
- return go({ children: annotation.content });
33
- };
34
- /**
35
- * This reducer is in charge of cascading changes between entities.
36
- */
37
- const moduleReducer = createReducer({}, (builder) => {
38
- // When editing an annotation is canceled, any added measurement displays during editing should be deleted
39
- builder.addCase(editAnnotationCancel, (state) => {
40
- if (state.annotationEditor.displays.added.length > 0) {
41
- measurementDisplaysAdapter.removeMany(state.measurementDisplays, state.annotationEditor.displays.added);
42
- }
43
- });
44
- //When submitting an annotation after editing, any deletions of measurement displays during editing should be persisted.
45
- builder.addCase(editAnnotationSubmit, (state) => {
46
- if (state.annotationEditor.displays.deleted.length > 0) {
47
- measurementDisplaysAdapter.removeMany(state.measurementDisplays, state.annotationEditor.displays.deleted);
48
- }
49
- });
50
- // When an annotation is deleted, any measurement displays associated with it should also be deleted.
51
- builder.addCase(editAnnotationDelete, (state) => {
52
- if (!state.annotations.editingAnnotation)
53
- return;
54
- const annotation = state.annotations.entities[state.annotations.editingAnnotation];
55
- if (!annotation)
56
- return;
57
- const annotationDisplays = getMeasurementDisplaysForAnnotation(annotation);
58
- const allDisplays = [
59
- ...state.annotationEditor.displays.added,
60
- ...annotationDisplays,
61
- ];
62
- measurementDisplaysAdapter.removeMany(state.measurementDisplays, allDisplays);
63
- });
64
- });
65
- export const annotationsModuleReducer = reduceReducers(moduleReducer, slicesReducer);
1
+ import { combineReducers } from "redux";
2
+ import { createReducer } from "@reduxjs/toolkit";
3
+ import reduceReducers from "reduce-reducers";
4
+ import annotationEditorSlice from "./annotationEditor.slice";
5
+ import annotationsSlice, { editAnnotationCancel, editAnnotationDelete, editAnnotationSubmit, } from "./annotations.slice";
6
+ import measurementDisplayEditorSlice from "./measurementDisplayEditor.slice";
7
+ import measurementDisplaysSlice, { measurementDisplaysAdapter, } from "./measurementDisplays.slice";
8
+ const slicesReducer = combineReducers({
9
+ annotations: annotationsSlice,
10
+ measurementDisplays: measurementDisplaysSlice,
11
+ annotationEditor: annotationEditorSlice,
12
+ measurementDisplayEditor: measurementDisplayEditorSlice,
13
+ });
14
+ /**
15
+ * An annotation can contain measurementDisplay elements in its content. The content consists of SlateJS nodes which
16
+ * is a nested structure. This function returns a list of all measurementDisplays contained in this annotation.
17
+ * @param annotation
18
+ * @returns The ids of the measurementDisplays contained in this Annotation.
19
+ */
20
+ const getMeasurementDisplaysForAnnotation = (annotation) => {
21
+ // The recursive function that goes through the nodes.
22
+ const go = (node) => {
23
+ if (node.type === "measurementDisplay") {
24
+ return [node.measurementDisplayId];
25
+ }
26
+ if (Array.isArray(node.children)) {
27
+ return node.children.reduce((acc, c) => [...acc, ...go(c)], []);
28
+ }
29
+ return [];
30
+ };
31
+ // Transforming the Annotation to a SlateJS node.
32
+ return go({ children: annotation.content });
33
+ };
34
+ /**
35
+ * This reducer is in charge of cascading changes between entities.
36
+ */
37
+ const moduleReducer = createReducer({}, (builder) => {
38
+ // When editing an annotation is canceled, any added measurement displays during editing should be deleted
39
+ builder.addCase(editAnnotationCancel, (state) => {
40
+ if (state.annotationEditor.displays.added.length > 0) {
41
+ measurementDisplaysAdapter.removeMany(state.measurementDisplays, state.annotationEditor.displays.added);
42
+ }
43
+ });
44
+ //When submitting an annotation after editing, any deletions of measurement displays during editing should be persisted.
45
+ builder.addCase(editAnnotationSubmit, (state) => {
46
+ if (state.annotationEditor.displays.deleted.length > 0) {
47
+ measurementDisplaysAdapter.removeMany(state.measurementDisplays, state.annotationEditor.displays.deleted);
48
+ }
49
+ });
50
+ // When an annotation is deleted, any measurement displays associated with it should also be deleted.
51
+ builder.addCase(editAnnotationDelete, (state) => {
52
+ if (!state.annotations.editingAnnotation)
53
+ return;
54
+ const annotation = state.annotations.entities[state.annotations.editingAnnotation];
55
+ if (!annotation)
56
+ return;
57
+ const annotationDisplays = getMeasurementDisplaysForAnnotation(annotation);
58
+ const allDisplays = [
59
+ ...state.annotationEditor.displays.added,
60
+ ...annotationDisplays,
61
+ ];
62
+ measurementDisplaysAdapter.removeMany(state.measurementDisplays, allDisplays);
63
+ });
64
+ });
65
+ export const annotationsModuleReducer = reduceReducers(moduleReducer, slicesReducer);
66
66
  //# sourceMappingURL=reducer.js.map
@@ -1,9 +1,9 @@
1
- declare type MeasureCallback = (el: HTMLElement | null) => void;
2
- declare type UseMeasureHookValue = [MeasureCallback, DOMRect | undefined];
3
- /**
4
- * React hook that uses ResizeObserver to keep track of size of element.
5
- * @returns An array that with a callback to pass element, and the ClientRect for that element with it's current size.
6
- */
7
- export declare const useBoundingRect: () => UseMeasureHookValue;
8
- export {};
1
+ declare type MeasureCallback = (el: HTMLElement | null) => void;
2
+ declare type UseMeasureHookValue = [MeasureCallback, DOMRect | undefined];
3
+ /**
4
+ * React hook that uses ResizeObserver to keep track of size of element.
5
+ * @returns An array that with a callback to pass element, and the ClientRect for that element with it's current size.
6
+ */
7
+ export declare const useBoundingRect: () => UseMeasureHookValue;
8
+ export {};
9
9
  //# sourceMappingURL=useBoundingRect.d.ts.map