Skip to content

Commit d18bc59

Browse files
committed
Properly fix issues with CustomRegion
- Proper relations to other parts of LSF like `object` and types - Remove some excess functions and fields breaking the LSF - Add missing AreaMixin
1 parent 661cec0 commit d18bc59

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

web/libs/editor/src/components/App/App.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import { TreeValidation } from "../TreeValidation/TreeValidation";
1515
/**
1616
* Tags
1717
*/
18+
// Custom tags should be registered first so all MST models will use their parts like regions and results
19+
import "../../tags/custom";
20+
1821
import "../../tags/object";
1922
import "../../tags/control";
2023
import "../../tags/visual";
21-
import "../../tags/custom";
2224

2325
/**
2426
* Utils and common components

web/libs/editor/src/tags/custom/Custom.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import ControlBase from "../control/Base";
77
import ClassificationBase from "../control/ClassificationBase";
88

99
import { AnnotationMixin } from "../../mixins/AnnotationMixin";
10-
import { CustomRegionModel } from "./CustomRegion";
1110
import { errorBuilder } from "../../core/DataValidator/ConfigValidator";
1211
import { parseValue, tryToParseJSON } from "../../utils/data";
1312

@@ -26,7 +25,6 @@ const TagAttrs = types.model("CustomIntrefaceAttrs", {
2625
const Model = types
2726
.model({
2827
type: "custominterface",
29-
regions: types.array(CustomRegionModel),
3028
globalState: types.optional(types.frozen(), {}),
3129
globalMetadata: types.optional(types.array(types.frozen()), []),
3230
})
@@ -124,7 +122,8 @@ const Model = types
124122
}
125123
},
126124
createRegion(value, pid) {
127-
const r = CustomRegionModel.create({ pid, _value: value });
125+
return;
126+
// const r = CustomRegionModel.create({ pid, _value: value });
128127
self.regions.push(r);
129128
// create a simple area/result in the annotation to integrate with store
130129
try {

web/libs/editor/src/tags/custom/CustomRegion.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@ import { observer } from "mobx-react";
22
import { types, getParent } from "mobx-state-tree";
33

44
import NormalizationMixin from "../../mixins/Normalization";
5+
import { AreaMixin } from "../../mixins/AreaMixin";
56
import RegionsMixin from "../../mixins/Regions";
67
import { guidGenerator } from "../../core/Helpers";
78

89
import { HtxTextBox } from "../../components/HtxTextBox/HtxTextBox";
910
import { cn } from "../../utils/bem";
11+
import { CustomInterfaceModel } from "./Custom";
12+
import { IconGrid } from "@humansignal/icons";
1013

1114
const Model = types
1215
.model("CustomRegionModel", {
13-
id: types.optional(types.identifier, guidGenerator),
14-
pid: types.optional(types.string, guidGenerator),
15-
type: "customregion",
16+
type: "custominterface",
17+
object: types.late(() => types.reference(CustomInterfaceModel)),
1618

1719
// Main payload for this region; matches result type name
1820
custominterface: types.frozen(),
1921

2022
_value: types.frozen(),
2123
// states: types.array(types.union(ChoicesModel)),
2224
})
23-
.volatile(() => ({
24-
classification: true,
25-
perRegionTags: [],
26-
results: [],
27-
selected: false,
28-
}))
2925
.views((self) => ({
3026
get parent() {
3127
return getParent(self);
3228
},
29+
30+
get noLabelView() {
31+
return "Custom region";
32+
},
33+
3334
getRegionElement() {
3435
return document.querySelector(`#CustomRegion-${self.id}`);
3536
},
@@ -58,17 +59,9 @@ const Model = types
5859
deleteRegion() {
5960
self.parent.remove(self);
6061
},
61-
62-
selectRegion() {
63-
self.selected = true;
64-
},
65-
66-
afterUnselectRegion() {
67-
self.selected = false;
68-
},
6962
}));
7063

71-
const CustomRegionModel = types.compose("CustomRegionModel", RegionsMixin, NormalizationMixin, Model);
64+
const CustomRegionModel = types.compose("CustomRegionModel", RegionsMixin, AreaMixin, NormalizationMixin, Model);
7265

7366
const HtxCustomRegionView = ({ item, onFocus }) => {
7467
const classes = [styles.mark];
@@ -139,6 +132,17 @@ const HtxCustomRegionView = ({ item, onFocus }) => {
139132

140133
const HtxCustomRegion = observer(HtxCustomRegionView);
141134

135+
// required for NodeViews
136+
CustomRegionModel.nodeView = {
137+
name: "CustomRegion",
138+
icon: IconGrid,
139+
fullContent: (node) => (
140+
<span style={{ color: "#5a5a5a" }}>
141+
{JSON.stringify(node.custominterface)}
142+
</span>
143+
),
144+
};
145+
142146
export { CustomRegionModel, HtxCustomRegion };
143147

144148

web/libs/editor/src/tags/custom/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Registry.addCustomTag("CustomInterface", {
77
tag: "CustomInterface",
88
description: "Embed custom React UI with stateful results",
99
isObject: true,
10-
model: (CustomInterfaceModel as unknown) as { name: string },
11-
view: (CustomInterfaceComponent as unknown) as any,
10+
model: CustomInterfaceModel,
11+
view: CustomInterfaceComponent,
1212
result: types.frozen(),
1313
resultName: "custominterface",
1414
detector: (sn: any) => Boolean(sn?.value?.custominterface || sn?.custominterface),
15-
region: CustomRegionModel as unknown as { name: string },
15+
region: CustomRegionModel as any,
1616
});
1717

1818
export {};

0 commit comments

Comments
 (0)