@insync-stageplayer/annotations 0.5.34 → 0.5.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 (55) 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.d.ts.map +1 -1
  15. package/lib/components/MeasurementDisplayDataProvider.js +45 -45
  16. package/lib/components/MeasurementDisplayDataProvider.js.map +1 -1
  17. package/lib/components/MeasurementDisplayEditor.d.ts +19 -19
  18. package/lib/components/MeasurementDisplayEditor.js +136 -136
  19. package/lib/components/MeasurementDisplayElement.d.ts +18 -18
  20. package/lib/components/MeasurementDisplayElement.d.ts.map +1 -1
  21. package/lib/components/MeasurementDisplayElement.js +65 -97
  22. package/lib/components/MeasurementDisplayElement.js.map +1 -1
  23. package/lib/components/ModalAnnotationEditor.d.ts +12 -12
  24. package/lib/components/ModalAnnotationEditor.js +37 -37
  25. package/lib/formatNumber.d.ts +29 -29
  26. package/lib/formatNumber.js +12 -12
  27. package/lib/hooks/useMeasurementDisplayData.d.ts +15 -0
  28. package/lib/hooks/useMeasurementDisplayData.d.ts.map +1 -0
  29. package/lib/hooks/useMeasurementDisplayData.js +40 -0
  30. package/lib/hooks/useMeasurementDisplayData.js.map +1 -0
  31. package/lib/index.d.ts +8 -7
  32. package/lib/index.d.ts.map +1 -1
  33. package/lib/index.js +8 -7
  34. package/lib/index.js.map +1 -1
  35. package/lib/redux/actions.d.ts +1 -1
  36. package/lib/redux/actions.js +1 -1
  37. package/lib/redux/annotationEditor.slice.d.ts +37 -37
  38. package/lib/redux/annotationEditor.slice.d.ts.map +1 -1
  39. package/lib/redux/annotationEditor.slice.js +122 -122
  40. package/lib/redux/annotations.slice.d.ts +31 -31
  41. package/lib/redux/annotations.slice.d.ts.map +1 -1
  42. package/lib/redux/annotations.slice.js +65 -65
  43. package/lib/redux/measurementDisplayEditor.slice.d.ts +25 -25
  44. package/lib/redux/measurementDisplayEditor.slice.d.ts.map +1 -1
  45. package/lib/redux/measurementDisplayEditor.slice.js +36 -36
  46. package/lib/redux/measurementDisplays.slice.d.ts +25 -25
  47. package/lib/redux/measurementDisplays.slice.d.ts.map +1 -1
  48. package/lib/redux/measurementDisplays.slice.js +22 -22
  49. package/lib/redux/reducer.d.ts +51 -51
  50. package/lib/redux/reducer.js +65 -65
  51. package/lib/useBoundingRect.d.ts +8 -8
  52. package/lib/useBoundingRect.js +27 -27
  53. package/lib/util.d.ts +5 -5
  54. package/lib/util.js +7 -7
  55. package/package.json +5 -5
@@ -1,38 +1,38 @@
1
- import React from "react";
2
- import { Node } from "slate";
3
- import { RenderElementProps, ReactEditor } from "slate-react";
4
- export interface ContentElementRenderer extends RenderElementProps {
5
- editable: boolean;
6
- }
7
- /**
8
- * Keys represent element type strings
9
- */
10
- export declare type ContentElementMap = {
11
- [key: string]: {
12
- /**
13
- * Is element a void element (https://docs.slatejs.org/concepts/02-nodes#voids)
14
- */
15
- isVoid: boolean;
16
- /**
17
- * Is element an inline element (https://docs.slatejs.org/concepts/02-nodes#blocks-vs-inlines)
18
- */
19
- inline: boolean;
20
- /**
21
- * Renders JSX output for this element
22
- */
23
- renderer: <T extends ContentElementRenderer>(props: T) => JSX.Element;
24
- };
25
- };
26
- export interface AnnotationContentProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
27
- editable?: boolean;
28
- content: Node[] | undefined;
29
- onChange?: (newContent: Node[]) => void;
30
- editorRef?: React.RefObject<ReactEditor>;
31
- elements: ContentElementMap;
32
- }
33
- /**
34
- * Component that renders annotation content using slate.js.
35
- * @param props
36
- */
37
- export declare const AnnotationContent: React.FC<AnnotationContentProps>;
1
+ import React from "react";
2
+ import { Node } from "slate";
3
+ import { RenderElementProps, ReactEditor } from "slate-react";
4
+ export interface ContentElementRenderer extends RenderElementProps {
5
+ editable: boolean;
6
+ }
7
+ /**
8
+ * Keys represent element type strings
9
+ */
10
+ export declare type ContentElementMap = {
11
+ [key: string]: {
12
+ /**
13
+ * Is element a void element (https://docs.slatejs.org/concepts/02-nodes#voids)
14
+ */
15
+ isVoid: boolean;
16
+ /**
17
+ * Is element an inline element (https://docs.slatejs.org/concepts/02-nodes#blocks-vs-inlines)
18
+ */
19
+ inline: boolean;
20
+ /**
21
+ * Renders JSX output for this element
22
+ */
23
+ renderer: <T extends ContentElementRenderer>(props: T) => JSX.Element;
24
+ };
25
+ };
26
+ export interface AnnotationContentProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
27
+ editable?: boolean;
28
+ content: Node[] | undefined;
29
+ onChange?: (newContent: Node[]) => void;
30
+ editorRef?: React.RefObject<ReactEditor>;
31
+ elements: ContentElementMap;
32
+ }
33
+ /**
34
+ * Component that renders annotation content using slate.js.
35
+ * @param props
36
+ */
37
+ export declare const AnnotationContent: React.FC<AnnotationContentProps>;
38
38
  //# sourceMappingURL=AnnotationContent.d.ts.map
@@ -1,19 +1,19 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import React, { useMemo, useCallback } from "react";
13
- import { createEditor } from "slate";
14
- import { styled, css } from "@insync-stageplayer/ui-components";
15
- import { withReact, Slate, Editable, } from "slate-react";
16
- const emptyContent = [{ type: "paragraph", children: [{ text: "" }] }];
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React, { useMemo, useCallback } from "react";
13
+ import { createEditor } from "slate";
14
+ import { styled, css } from "@insync-stageplayer/ui-components";
15
+ import { withReact, Slate, Editable, } from "slate-react";
16
+ const emptyContent = [{ type: "paragraph", children: [{ text: "" }] }];
17
17
  const StyledEditable = styled(Editable) `
18
18
  height: 100%;
19
19
  width: 100%;
@@ -24,7 +24,7 @@ const StyledEditable = styled(Editable) `
24
24
  /**
25
25
  * Ugly hack to overwrite the default width of 0, which messes up the width in non-editing mode.
26
26
  */
27
- ${(props) => props.readOnly &&
27
+ ${(props) => props.readOnly &&
28
28
  css `
29
29
  [data-slate-leaf="true"] {
30
30
  > span {
@@ -32,46 +32,46 @@ const StyledEditable = styled(Editable) `
32
32
  }
33
33
  }
34
34
  `}
35
- `;
36
- /**
37
- * Higher order function to add custom elements to a slate editor through a ContentElementMap.
38
- * @param elements
39
- */
40
- const withElements = (elements = {}) => (editor) => {
41
- const { isInline, isVoid } = editor;
42
- editor.isInline = (element) => {
43
- var _a;
44
- return ((typeof element.type === "string" && ((_a = elements[element.type]) === null || _a === void 0 ? void 0 : _a.inline)) ||
45
- isInline(element));
46
- };
47
- editor.isVoid = (element) => {
48
- var _a;
49
- return ((typeof element.type === "string" && ((_a = elements[element.type]) === null || _a === void 0 ? void 0 : _a.isVoid)) ||
50
- isVoid(element));
51
- };
52
- return editor;
53
- };
54
- /**
55
- * Component that renders annotation content using slate.js.
56
- * @param props
57
- */
58
- export const AnnotationContent = (props) => {
59
- const { content = emptyContent, onChange = () => { }, editable = false, elements, editorRef } = props, rest = __rest(props, ["content", "onChange", "editable", "elements", "editorRef"]);
60
- const editor = useMemo(() => {
61
- return withElements(elements)(withReact(createEditor()));
62
- }, [elements]);
63
- if (editorRef) {
64
- editorRef.current = editor;
65
- }
66
- const renderElement = useCallback((props) => {
67
- const customElement = elements[props.element.type];
68
- if (customElement) {
69
- return customElement.renderer(Object.assign(Object.assign({}, props), { editable }));
70
- }
71
- return React.createElement("div", Object.assign({}, props.attributes), props.children);
72
- }, [elements, editable]);
73
- return (React.createElement("div", Object.assign({}, rest),
74
- React.createElement(Slate, { editor: editor, value: content, onChange: onChange },
75
- React.createElement(StyledEditable, { readOnly: !editable, renderElement: renderElement, placeholder: "Enter some text..." }))));
76
- };
35
+ `;
36
+ /**
37
+ * Higher order function to add custom elements to a slate editor through a ContentElementMap.
38
+ * @param elements
39
+ */
40
+ const withElements = (elements = {}) => (editor) => {
41
+ const { isInline, isVoid } = editor;
42
+ editor.isInline = (element) => {
43
+ var _a;
44
+ return ((typeof element.type === "string" && ((_a = elements[element.type]) === null || _a === void 0 ? void 0 : _a.inline)) ||
45
+ isInline(element));
46
+ };
47
+ editor.isVoid = (element) => {
48
+ var _a;
49
+ return ((typeof element.type === "string" && ((_a = elements[element.type]) === null || _a === void 0 ? void 0 : _a.isVoid)) ||
50
+ isVoid(element));
51
+ };
52
+ return editor;
53
+ };
54
+ /**
55
+ * Component that renders annotation content using slate.js.
56
+ * @param props
57
+ */
58
+ export const AnnotationContent = (props) => {
59
+ const { content = emptyContent, onChange = () => { }, editable = false, elements, editorRef } = props, rest = __rest(props, ["content", "onChange", "editable", "elements", "editorRef"]);
60
+ const editor = useMemo(() => {
61
+ return withElements(elements)(withReact(createEditor()));
62
+ }, [elements]);
63
+ if (editorRef) {
64
+ editorRef.current = editor;
65
+ }
66
+ const renderElement = useCallback((props) => {
67
+ const customElement = elements[props.element.type];
68
+ if (customElement) {
69
+ return customElement.renderer(Object.assign(Object.assign({}, props), { editable }));
70
+ }
71
+ return React.createElement("div", Object.assign({}, props.attributes), props.children);
72
+ }, [elements, editable]);
73
+ return (React.createElement("div", Object.assign({}, rest),
74
+ React.createElement(Slate, { editor: editor, value: content, onChange: onChange },
75
+ React.createElement(StyledEditable, { readOnly: !editable, renderElement: renderElement, placeholder: "Enter some text..." }))));
76
+ };
77
77
  //# sourceMappingURL=AnnotationContent.js.map
@@ -1,27 +1,27 @@
1
- import React from "react";
2
- import { Annotation } from "../redux/annotations.slice";
3
- export declare type AnnotationEditFormProps = {
4
- /**
5
- * The annotation being editted.
6
- */
7
- annotationId?: string;
8
- /**
9
- * Called when form is submitted.
10
- */
11
- onSubmit?: (annotation: Annotation) => void;
12
- /**
13
- * Called when form is cancelled.
14
- */
15
- onCancel?: () => void;
16
- /**
17
- * Called when annotation is deleted (using the button in this form).
18
- */
19
- onDelete?: () => void;
20
- };
21
- /**
22
- * Form that can be used to edit an annotation. Connected to redux for state management.
23
- * @param props
24
- * @returns
25
- */
26
- export declare const AnnotationEditForm: React.FC<AnnotationEditFormProps>;
1
+ import React from "react";
2
+ import { Annotation } from "../redux/annotations.slice";
3
+ export declare type AnnotationEditFormProps = {
4
+ /**
5
+ * The annotation being editted.
6
+ */
7
+ annotationId?: string;
8
+ /**
9
+ * Called when form is submitted.
10
+ */
11
+ onSubmit?: (annotation: Annotation) => void;
12
+ /**
13
+ * Called when form is cancelled.
14
+ */
15
+ onCancel?: () => void;
16
+ /**
17
+ * Called when annotation is deleted (using the button in this form).
18
+ */
19
+ onDelete?: () => void;
20
+ };
21
+ /**
22
+ * Form that can be used to edit an annotation. Connected to redux for state management.
23
+ * @param props
24
+ * @returns
25
+ */
26
+ export declare const AnnotationEditForm: React.FC<AnnotationEditFormProps>;
27
27
  //# sourceMappingURL=AnnotationEditForm.d.ts.map
@@ -1,147 +1,147 @@
1
- import { MeasurementsChooser } from "@insync-stageplayer/measurements";
2
- import { Popout, PopoutTargetContext, useTheme, } from "@insync-stageplayer/ui-components";
3
- import cx from "classnames";
4
- import React, { useRef, useCallback, useContext, useEffect, useMemo, } from "react";
5
- import { useDispatch, useSelector } from "react-redux";
6
- import { AnnotationContent, } from "./AnnotationContent";
7
- import { editDisplay, finishEditingDisplay, initEditor, pickMeasurement, pickMeasurementChoose, pickMeasurementClose, pickMeasurementSuccess, updateContent, } from "../redux/annotationEditor.slice";
8
- import { AnnotationsModuleContext } from "./AnnotationsModuleProvider";
9
- import MeasurementDisplayEditor from "./MeasurementDisplayEditor";
10
- import { MeasurementDisplayElement } from "./MeasurementDisplayElement";
11
- import { createMeasurementDisplay } from "../redux/measurementDisplays.slice";
12
- import { createId } from "../util";
13
- /**
14
- * A wrapper around the MeasurementDisplay. Provides entrypoint for editing MeasurementDisplays.
15
- * @param param
16
- * @returns
17
- */
18
- const MeasurementDisplayElementRenderer = ({ element, attributes, editable, children, }) => {
19
- const { measurementDisplayId } = element;
20
- const dispatch = useDispatch();
21
- const { selector } = useContext(AnnotationsModuleContext);
22
- const id = useSelector((s) => selector(s).annotationEditor.editingMeasurementDisplay);
23
- const editor = id ? (React.createElement(MeasurementDisplayEditor.Container, { id: id, className: "p-1", onClose: () => dispatch(finishEditingDisplay()) })) : null;
24
- return (React.createElement(Popout, { content: editor, visible: id === measurementDisplayId, placement: "right", onClickOutside: () => {
25
- dispatch(finishEditingDisplay());
26
- } }, ({ ref }) => (React.createElement("span", Object.assign({}, attributes),
27
- React.createElement(MeasurementDisplayElement, { ref: ref, onClick: () => {
28
- dispatch(editDisplay(measurementDisplayId));
29
- }, id: measurementDisplayId, editable: editable, xRange: { start: 0, duration: 50000 } }),
30
- children))));
31
- };
32
- const contentElements = {
33
- measurementDisplay: {
34
- isVoid: true,
35
- inline: true,
36
- renderer: MeasurementDisplayElementRenderer,
37
- },
38
- };
39
- /**
40
- * Form that can be used to edit an annotation. Connected to redux for state management.
41
- * @param props
42
- * @returns
43
- */
44
- export const AnnotationEditForm = (props) => {
45
- const theme = useTheme();
46
- const dispatch = useDispatch();
47
- const popoutTarget = useRef(null);
48
- const { selector, entitiesSelectors } = useContext(AnnotationsModuleContext);
49
- const { onSubmit, onCancel, onDelete } = props;
50
- const dirtyAnnotation = useSelector((s) => props.annotationId
51
- ? entitiesSelectors.annotations.selectById(s, props.annotationId)
52
- : undefined);
53
- const annotation = useMemo(() => {
54
- var _a;
55
- const go = (node) => {
56
- if ((node.type === "measurementDisplay" || node.type === "paragraph") &&
57
- !node.children) {
58
- return Object.assign(Object.assign({}, node), { text: undefined, children: [
59
- {
60
- text: "",
61
- },
62
- ] });
63
- }
64
- if (Array.isArray(node.children)) {
65
- return Object.assign(Object.assign({}, node), { children: node.children.map(go) });
66
- // return node.children.map(go);
67
- }
68
- return node;
69
- };
70
- return dirtyAnnotation
71
- ? Object.assign(Object.assign({}, dirtyAnnotation), { content: (_a = dirtyAnnotation === null || dirtyAnnotation === void 0 ? void 0 : dirtyAnnotation.content) === null || _a === void 0 ? void 0 : _a.map(go) }) : dirtyAnnotation;
72
- }, [dirtyAnnotation]);
73
- useEffect(() => {
74
- dispatch(initEditor(annotation));
75
- }, [annotation, dispatch]);
76
- const editorRef = useRef(null);
77
- const state = useSelector((s) => selector(s).annotationEditor);
78
- const handleChange = useCallback((newContent) => {
79
- dispatch(updateContent(newContent));
80
- }, [dispatch]);
81
- const handleSubmit = useCallback((e) => {
82
- var _a;
83
- e.preventDefault();
84
- if (!onSubmit)
85
- return;
86
- if (!state.annotation.id) {
87
- onSubmit(Object.assign(Object.assign({}, state.annotation), { id: createId() }));
88
- }
89
- ((_a = state.annotation.content) === null || _a === void 0 ? void 0 : _a.length) !== 0
90
- ? onSubmit(state.annotation)
91
- : onCancel;
92
- }, [state.annotation, onSubmit, onCancel]);
93
- const handleAddMeasurementDisplay = useCallback(() => {
94
- dispatch(pickMeasurement());
95
- }, [dispatch]);
96
- const handleCloseMeasurementPicker = useCallback(() => {
97
- dispatch(pickMeasurementClose());
98
- }, [dispatch]);
99
- const handleChooseMeasurement = useCallback(([measurementId]) => {
100
- dispatch(pickMeasurementChoose(measurementId));
101
- }, [dispatch]);
102
- const handleSubmitMeasurementPicker = useCallback(() => {
103
- var _a;
104
- if (!state.chosenMeasurement)
105
- return;
106
- const id = createId();
107
- dispatch(createMeasurementDisplay({
108
- id,
109
- measurementId: state.chosenMeasurement,
110
- showX: false,
111
- showY: true,
112
- showSignal: true,
113
- showSigColor: false,
114
- padYTo: 1,
115
- padXTo: 1,
116
- padXChar: " ",
117
- padYChar: " ",
118
- decimalsY: 2,
119
- decimalsX: 3,
120
- }));
121
- (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.insertNode({
122
- type: "measurementDisplay",
123
- measurementDisplayId: id,
124
- children: [{ text: "" }],
125
- });
126
- setTimeout(() => {
127
- dispatch(pickMeasurementSuccess(id));
128
- }, 0);
129
- }, [dispatch, state.chosenMeasurement]);
130
- return (React.createElement(React.Fragment, null,
131
- React.createElement("form", { onSubmit: (e) => e.preventDefault(), className: cx("card", theme.name === "light" && "bg-secondary", theme.name === "dark" && "bg-dark", "h-100", "flex-column", state.pickingMeasurement ? "d-none" : "d-flex") },
132
- React.createElement("div", { className: "card-header d-flex justify-content-between" },
133
- React.createElement("button", { className: "btn btn-primary", onClick: handleAddMeasurementDisplay }, "Add signal value")),
134
- React.createElement(PopoutTargetContext.Provider, { value: popoutTarget },
135
- React.createElement(AnnotationContent, { className: "card-body flex-1", "background-color": "slate-grey", editable: true, editorRef: editorRef, content: state.annotation.content, elements: contentElements, onChange: handleChange })),
136
- React.createElement("div", { className: "card-header d-flex justify-content-between" },
137
- React.createElement("button", { className: "btn btn-danger mr-1", onClick: onDelete }, "Delete Overlay"),
138
- React.createElement("button", { className: "btn btn-primary", onClick: handleSubmit }, "Ok")),
139
- React.createElement("div", { ref: popoutTarget })),
140
- state.pickingMeasurement && (React.createElement("div", { className: "d-flex flex-column h-100" },
141
- React.createElement("div", { className: "flex-grow-1" },
142
- React.createElement(MeasurementsChooser, { single: true, className: "h-100", onChange: handleChooseMeasurement, selected: state.chosenMeasurement ? [state.chosenMeasurement] : [], dataViewerId: state.chosenMeasurement ? state.chosenMeasurement : "" })),
143
- React.createElement("div", { className: "py-3 d-flex flex-row justify-content-end" },
144
- React.createElement("button", { className: "btn btn-danger mr-3", onClick: handleCloseMeasurementPicker }, "Cancel"),
145
- React.createElement("button", { className: "btn btn-primary", onClick: handleSubmitMeasurementPicker }, "Ok"))))));
146
- };
1
+ import { MeasurementsChooser } from "@insync-stageplayer/measurements";
2
+ import { Popout, PopoutTargetContext, useTheme, } from "@insync-stageplayer/ui-components";
3
+ import cx from "classnames";
4
+ import React, { useRef, useCallback, useContext, useEffect, useMemo, } from "react";
5
+ import { useDispatch, useSelector } from "react-redux";
6
+ import { AnnotationContent, } from "./AnnotationContent";
7
+ import { editDisplay, finishEditingDisplay, initEditor, pickMeasurement, pickMeasurementChoose, pickMeasurementClose, pickMeasurementSuccess, updateContent, } from "../redux/annotationEditor.slice";
8
+ import { AnnotationsModuleContext } from "./AnnotationsModuleProvider";
9
+ import MeasurementDisplayEditor from "./MeasurementDisplayEditor";
10
+ import { MeasurementDisplayElement } from "./MeasurementDisplayElement";
11
+ import { createMeasurementDisplay } from "../redux/measurementDisplays.slice";
12
+ import { createId } from "../util";
13
+ /**
14
+ * A wrapper around the MeasurementDisplay. Provides entrypoint for editing MeasurementDisplays.
15
+ * @param param
16
+ * @returns
17
+ */
18
+ const MeasurementDisplayElementRenderer = ({ element, attributes, editable, children, }) => {
19
+ const { measurementDisplayId } = element;
20
+ const dispatch = useDispatch();
21
+ const { selector } = useContext(AnnotationsModuleContext);
22
+ const id = useSelector((s) => selector(s).annotationEditor.editingMeasurementDisplay);
23
+ const editor = id ? (React.createElement(MeasurementDisplayEditor.Container, { id: id, className: "p-1", onClose: () => dispatch(finishEditingDisplay()) })) : null;
24
+ return (React.createElement(Popout, { content: editor, visible: id === measurementDisplayId, placement: "right", onClickOutside: () => {
25
+ dispatch(finishEditingDisplay());
26
+ } }, ({ ref }) => (React.createElement("span", Object.assign({}, attributes),
27
+ React.createElement(MeasurementDisplayElement, { ref: ref, onClick: () => {
28
+ dispatch(editDisplay(measurementDisplayId));
29
+ }, id: measurementDisplayId, editable: editable, xRange: { start: 0, duration: 50000 } }),
30
+ children))));
31
+ };
32
+ const contentElements = {
33
+ measurementDisplay: {
34
+ isVoid: true,
35
+ inline: true,
36
+ renderer: MeasurementDisplayElementRenderer,
37
+ },
38
+ };
39
+ /**
40
+ * Form that can be used to edit an annotation. Connected to redux for state management.
41
+ * @param props
42
+ * @returns
43
+ */
44
+ export const AnnotationEditForm = (props) => {
45
+ const theme = useTheme();
46
+ const dispatch = useDispatch();
47
+ const popoutTarget = useRef(null);
48
+ const { selector, entitiesSelectors } = useContext(AnnotationsModuleContext);
49
+ const { onSubmit, onCancel, onDelete } = props;
50
+ const dirtyAnnotation = useSelector((s) => props.annotationId
51
+ ? entitiesSelectors.annotations.selectById(s, props.annotationId)
52
+ : undefined);
53
+ const annotation = useMemo(() => {
54
+ var _a;
55
+ const go = (node) => {
56
+ if ((node.type === "measurementDisplay" || node.type === "paragraph") &&
57
+ !node.children) {
58
+ return Object.assign(Object.assign({}, node), { text: undefined, children: [
59
+ {
60
+ text: "",
61
+ },
62
+ ] });
63
+ }
64
+ if (Array.isArray(node.children)) {
65
+ return Object.assign(Object.assign({}, node), { children: node.children.map(go) });
66
+ // return node.children.map(go);
67
+ }
68
+ return node;
69
+ };
70
+ return dirtyAnnotation
71
+ ? Object.assign(Object.assign({}, dirtyAnnotation), { content: (_a = dirtyAnnotation === null || dirtyAnnotation === void 0 ? void 0 : dirtyAnnotation.content) === null || _a === void 0 ? void 0 : _a.map(go) }) : dirtyAnnotation;
72
+ }, [dirtyAnnotation]);
73
+ useEffect(() => {
74
+ dispatch(initEditor(annotation));
75
+ }, [annotation, dispatch]);
76
+ const editorRef = useRef(null);
77
+ const state = useSelector((s) => selector(s).annotationEditor);
78
+ const handleChange = useCallback((newContent) => {
79
+ dispatch(updateContent(newContent));
80
+ }, [dispatch]);
81
+ const handleSubmit = useCallback((e) => {
82
+ var _a;
83
+ e.preventDefault();
84
+ if (!onSubmit)
85
+ return;
86
+ if (!state.annotation.id) {
87
+ onSubmit(Object.assign(Object.assign({}, state.annotation), { id: createId() }));
88
+ }
89
+ ((_a = state.annotation.content) === null || _a === void 0 ? void 0 : _a.length) !== 0
90
+ ? onSubmit(state.annotation)
91
+ : onCancel;
92
+ }, [state.annotation, onSubmit, onCancel]);
93
+ const handleAddMeasurementDisplay = useCallback(() => {
94
+ dispatch(pickMeasurement());
95
+ }, [dispatch]);
96
+ const handleCloseMeasurementPicker = useCallback(() => {
97
+ dispatch(pickMeasurementClose());
98
+ }, [dispatch]);
99
+ const handleChooseMeasurement = useCallback(([measurementId]) => {
100
+ dispatch(pickMeasurementChoose(measurementId));
101
+ }, [dispatch]);
102
+ const handleSubmitMeasurementPicker = useCallback(() => {
103
+ var _a;
104
+ if (!state.chosenMeasurement)
105
+ return;
106
+ const id = createId();
107
+ dispatch(createMeasurementDisplay({
108
+ id,
109
+ measurementId: state.chosenMeasurement,
110
+ showX: false,
111
+ showY: true,
112
+ showSignal: true,
113
+ showSigColor: false,
114
+ padYTo: 1,
115
+ padXTo: 1,
116
+ padXChar: " ",
117
+ padYChar: " ",
118
+ decimalsY: 2,
119
+ decimalsX: 3,
120
+ }));
121
+ (_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.insertNode({
122
+ type: "measurementDisplay",
123
+ measurementDisplayId: id,
124
+ children: [{ text: "" }],
125
+ });
126
+ setTimeout(() => {
127
+ dispatch(pickMeasurementSuccess(id));
128
+ }, 0);
129
+ }, [dispatch, state.chosenMeasurement]);
130
+ return (React.createElement(React.Fragment, null,
131
+ React.createElement("form", { onSubmit: (e) => e.preventDefault(), className: cx("card", theme.name === "light" && "bg-secondary", theme.name === "dark" && "bg-dark", "h-100", "flex-column", state.pickingMeasurement ? "d-none" : "d-flex") },
132
+ React.createElement("div", { className: "card-header d-flex justify-content-between" },
133
+ React.createElement("button", { className: "btn btn-primary", onClick: handleAddMeasurementDisplay }, "Add signal value")),
134
+ React.createElement(PopoutTargetContext.Provider, { value: popoutTarget },
135
+ React.createElement(AnnotationContent, { className: "card-body flex-1", "background-color": "slate-grey", editable: true, editorRef: editorRef, content: state.annotation.content, elements: contentElements, onChange: handleChange })),
136
+ React.createElement("div", { className: "card-header d-flex justify-content-between" },
137
+ React.createElement("button", { className: "btn btn-danger mr-1", onClick: onDelete }, "Delete Overlay"),
138
+ React.createElement("button", { className: "btn btn-primary", onClick: handleSubmit }, "Ok")),
139
+ React.createElement("div", { ref: popoutTarget })),
140
+ state.pickingMeasurement && (React.createElement("div", { className: "d-flex flex-column h-100" },
141
+ React.createElement("div", { className: "flex-grow-1" },
142
+ React.createElement(MeasurementsChooser, { single: true, className: "h-100", onChange: handleChooseMeasurement, selected: state.chosenMeasurement ? [state.chosenMeasurement] : [], dataViewerId: state.chosenMeasurement ? state.chosenMeasurement : "" })),
143
+ React.createElement("div", { className: "py-3 d-flex flex-row justify-content-end" },
144
+ React.createElement("button", { className: "btn btn-danger mr-3", onClick: handleCloseMeasurementPicker }, "Cancel"),
145
+ React.createElement("button", { className: "btn btn-primary", onClick: handleSubmitMeasurementPicker }, "Ok"))))));
146
+ };
147
147
  //# sourceMappingURL=AnnotationEditForm.js.map
@@ -1,37 +1,37 @@
1
- import React from "react";
2
- import { annotationsAdapter } from "../redux/annotations.slice";
3
- import { measurementDisplaysAdapter } from "../redux/measurementDisplays.slice";
4
- import { AnnotationsModuleState } from "../redux/reducer";
5
- declare type AnnotationsModuleStateSelector = (state: any) => AnnotationsModuleState;
6
- declare type MeasurementsModuleValue = {
7
- /**
8
- * Selects the slice state from the redux state.
9
- */
10
- selector: AnnotationsModuleStateSelector;
11
- /**
12
- * Selectors for retrieving entities.
13
- */
14
- entitiesSelectors: {
15
- /**
16
- * Provides selectors for retrieving annotation entities from the state.
17
- */
18
- annotations: ReturnType<typeof annotationsAdapter.getSelectors>;
19
- /**
20
- * Provides selectors for retrieving measurementDisplays from the state.
21
- */
22
- measurementDisplays: ReturnType<typeof measurementDisplaysAdapter.getSelectors>;
23
- };
24
- };
25
- export declare const AnnotationsModuleContext: React.Context<MeasurementsModuleValue>;
26
- declare type MeasurementsModuleProviderProps = {
27
- selector: AnnotationsModuleStateSelector;
28
- };
29
- /**
30
- * Provides the functionalities in this module to its children components.
31
- *
32
- * @param props
33
- * @returns
34
- */
35
- export declare const AnnotationsModuleProvider: React.FC<MeasurementsModuleProviderProps>;
36
- export {};
1
+ import React from "react";
2
+ import { annotationsAdapter } from "../redux/annotations.slice";
3
+ import { measurementDisplaysAdapter } from "../redux/measurementDisplays.slice";
4
+ import { AnnotationsModuleState } from "../redux/reducer";
5
+ declare type AnnotationsModuleStateSelector = (state: any) => AnnotationsModuleState;
6
+ declare type MeasurementsModuleValue = {
7
+ /**
8
+ * Selects the slice state from the redux state.
9
+ */
10
+ selector: AnnotationsModuleStateSelector;
11
+ /**
12
+ * Selectors for retrieving entities.
13
+ */
14
+ entitiesSelectors: {
15
+ /**
16
+ * Provides selectors for retrieving annotation entities from the state.
17
+ */
18
+ annotations: ReturnType<typeof annotationsAdapter.getSelectors>;
19
+ /**
20
+ * Provides selectors for retrieving measurementDisplays from the state.
21
+ */
22
+ measurementDisplays: ReturnType<typeof measurementDisplaysAdapter.getSelectors>;
23
+ };
24
+ };
25
+ export declare const AnnotationsModuleContext: React.Context<MeasurementsModuleValue>;
26
+ declare type MeasurementsModuleProviderProps = {
27
+ selector: AnnotationsModuleStateSelector;
28
+ };
29
+ /**
30
+ * Provides the functionalities in this module to its children components.
31
+ *
32
+ * @param props
33
+ * @returns
34
+ */
35
+ export declare const AnnotationsModuleProvider: React.FC<MeasurementsModuleProviderProps>;
36
+ export {};
37
37
  //# sourceMappingURL=AnnotationsModuleProvider.d.ts.map