Bin
2025-12-17 dcf780a91c16b6be28635b6e2e0e702060ee19f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { types } from "mobx-state-tree";
import { isValidElement } from "react";
 
export const CustomJSON = types.custom({
  name: "JSON",
  toSnapshot(value) {
    return JSON.stringify(value);
  },
  fromSnapshot(value) {
    try {
      return JSON.parse(value);
    } catch {
      return value;
    }
  },
  isTargetType(value) {
    return typeof value === "object" || typeof value === "string";
  },
  getValidationMessage() {
    return "Error parsing JSON";
  },
});
 
export const StringOrNumber = types.union(types.string, types.number);
 
export const StringOrNumberID = types.union(types.identifier, types.identifierNumber);
 
export const CustomCalback = types.custom({
  name: "callback",
  toSnapshot(value) {
    return value;
  },
  fromSnapshot(value) {
    return value;
  },
  isTargetType(value) {
    return typeof value === "function";
  },
  getValidationMessage() {
    return "is not a function";
  },
});
 
export const HtmlOrReact = types.custom({
  name: "validElement",
  toSnapshot(value) {
    return value;
  },
  fromSnapshot(value) {
    return value;
  },
  isTargetType(value) {
    return isValidElement(value);
  },
  getValidationMessage() {
    return "is not a valid element";
  },
});
 
export const ThresholdType = types.model("ThresholdType", {
  min: types.maybeNull(types.number),
  max: types.maybeNull(types.number),
});