@macrostrat/feedback-components 1.0.1 → 1.1.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 (105) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/esm/feedback-components.3b3a5357.js +137 -0
  3. package/dist/esm/feedback-components.3b3a5357.js.map +1 -0
  4. package/dist/esm/feedback-components.46a7a347.js +269 -0
  5. package/dist/esm/feedback-components.46a7a347.js.map +1 -0
  6. package/dist/esm/{node.28634e40.js → feedback-components.5509fab3.js} +11 -6
  7. package/dist/esm/feedback-components.5509fab3.js.map +1 -0
  8. package/dist/esm/feedback-components.586103e8.js +578 -0
  9. package/dist/esm/feedback-components.586103e8.js.map +1 -0
  10. package/dist/esm/{extractions.65bb73cc.js → feedback-components.5df2a926.js} +46 -18
  11. package/dist/esm/feedback-components.5df2a926.js.map +1 -0
  12. package/dist/esm/{main.module.cd706d67.js → feedback-components.6d32ee91.js} +1 -1
  13. package/dist/esm/{main.module.cd706d67.js.map → feedback-components.6d32ee91.js.map} +1 -1
  14. package/dist/esm/feedback-components.95dbe7d7.js +82 -0
  15. package/dist/esm/feedback-components.95dbe7d7.js.map +1 -0
  16. package/dist/esm/{type-selector.6e8952d6.js → feedback-components.ad9f284e.js} +6 -5
  17. package/dist/esm/feedback-components.ad9f284e.js.map +1 -0
  18. package/dist/esm/{main.module.8d366b6e.css → feedback-components.bf93773c.css} +1 -1
  19. package/dist/esm/{main.module.8d366b6e.css.map → feedback-components.bf93773c.css.map} +1 -1
  20. package/dist/esm/{main.module.2f2972c8.css → feedback-components.e273ed5b.css} +1 -1
  21. package/dist/esm/{main.module.2f2972c8.css.map → feedback-components.e273ed5b.css.map} +1 -1
  22. package/dist/esm/{main.module.d2fbdf09.js → feedback-components.f9850d85.js} +1 -1
  23. package/dist/esm/{main.module.d2fbdf09.js.map → feedback-components.f9850d85.js.map} +1 -1
  24. package/dist/esm/{edit-state.c39d8466.js → feedback-components.fa1d3641.js} +125 -7
  25. package/dist/esm/feedback-components.fa1d3641.js.map +1 -0
  26. package/dist/esm/feedback-components.fb60c70d.css +180 -0
  27. package/dist/esm/feedback-components.fb60c70d.css.map +1 -0
  28. package/dist/esm/index.d.ts +10 -64
  29. package/dist/esm/index.d.ts.map +1 -1
  30. package/dist/esm/index.js +2 -2
  31. package/dist/node/feedback-components.2f391fa4.js +2 -0
  32. package/dist/node/feedback-components.2f391fa4.js.map +1 -0
  33. package/dist/node/feedback-components.561466ac.js +2 -0
  34. package/dist/node/feedback-components.561466ac.js.map +1 -0
  35. package/dist/node/feedback-components.571ee23c.js +2 -0
  36. package/dist/node/feedback-components.571ee23c.js.map +1 -0
  37. package/dist/node/{main.module.ebdf985b.js → feedback-components.794f429b.js} +2 -2
  38. package/dist/node/feedback-components.794f429b.js.map +1 -0
  39. package/dist/node/{main.module.1fdfe813.css → feedback-components.83c21466.css} +1 -1
  40. package/dist/node/feedback-components.83c21466.css.map +1 -0
  41. package/dist/node/feedback-components.8b03e8be.js +2 -0
  42. package/dist/node/feedback-components.8b03e8be.js.map +1 -0
  43. package/dist/node/{main.module.6bc7d51b.css → feedback-components.9eb1d41a.css} +1 -1
  44. package/dist/node/feedback-components.9eb1d41a.css.map +1 -0
  45. package/dist/node/feedback-components.a39f7653.js +2 -0
  46. package/dist/node/feedback-components.a39f7653.js.map +1 -0
  47. package/dist/node/feedback-components.acac789b.js +2 -0
  48. package/dist/node/feedback-components.acac789b.js.map +1 -0
  49. package/dist/node/feedback-components.b7946db4.js +2 -0
  50. package/dist/node/feedback-components.b7946db4.js.map +1 -0
  51. package/dist/node/feedback-components.c459cc27.js +2 -0
  52. package/dist/node/feedback-components.c459cc27.js.map +1 -0
  53. package/dist/node/feedback-components.c88cb37f.css +2 -0
  54. package/dist/node/feedback-components.c88cb37f.css.map +1 -0
  55. package/dist/node/feedback-components.ec54a1e7.js +2 -0
  56. package/dist/node/feedback-components.ec54a1e7.js.map +1 -0
  57. package/dist/node/index.js +1 -1
  58. package/dist/node/index.js.map +1 -1
  59. package/package.json +7 -6
  60. package/src/extractions/index.ts +76 -21
  61. package/src/extractions/types.ts +6 -1
  62. package/src/feedback/edit-state.ts +184 -16
  63. package/src/feedback/feedback.module.sass +121 -9
  64. package/src/feedback/graph.ts +90 -32
  65. package/src/feedback/index.ts +553 -146
  66. package/src/feedback/node.ts +7 -1
  67. package/src/feedback/text-visualizer.ts +286 -49
  68. package/src/feedback/type-selector/index.ts +4 -2
  69. package/dist/esm/edit-state.c39d8466.js.map +0 -1
  70. package/dist/esm/extractions.65bb73cc.js.map +0 -1
  71. package/dist/esm/feedback.5c86878e.js +0 -252
  72. package/dist/esm/feedback.5c86878e.js.map +0 -1
  73. package/dist/esm/feedback.module.55921afe.css +0 -44
  74. package/dist/esm/feedback.module.55921afe.css.map +0 -1
  75. package/dist/esm/feedback.module.765b1e58.js +0 -28
  76. package/dist/esm/feedback.module.765b1e58.js.map +0 -1
  77. package/dist/esm/graph.f4f65d79.js +0 -83
  78. package/dist/esm/graph.f4f65d79.js.map +0 -1
  79. package/dist/esm/node.28634e40.js.map +0 -1
  80. package/dist/esm/text-visualizer.198e27ff.js +0 -101
  81. package/dist/esm/text-visualizer.198e27ff.js.map +0 -1
  82. package/dist/esm/type-selector.6e8952d6.js.map +0 -1
  83. package/dist/node/edit-state.f50ca728.js +0 -2
  84. package/dist/node/edit-state.f50ca728.js.map +0 -1
  85. package/dist/node/extractions.e6ea2eb9.js +0 -2
  86. package/dist/node/extractions.e6ea2eb9.js.map +0 -1
  87. package/dist/node/feedback.8d3d1219.js +0 -2
  88. package/dist/node/feedback.8d3d1219.js.map +0 -1
  89. package/dist/node/feedback.module.a8744203.js +0 -2
  90. package/dist/node/feedback.module.a8744203.js.map +0 -1
  91. package/dist/node/feedback.module.c4eab97d.css +0 -2
  92. package/dist/node/feedback.module.c4eab97d.css.map +0 -1
  93. package/dist/node/graph.ca5b649f.js +0 -2
  94. package/dist/node/graph.ca5b649f.js.map +0 -1
  95. package/dist/node/main.module.1857be22.js +0 -2
  96. package/dist/node/main.module.1857be22.js.map +0 -1
  97. package/dist/node/main.module.1fdfe813.css.map +0 -1
  98. package/dist/node/main.module.6bc7d51b.css.map +0 -1
  99. package/dist/node/main.module.ebdf985b.js.map +0 -1
  100. package/dist/node/node.33108ccc.js +0 -2
  101. package/dist/node/node.33108ccc.js.map +0 -1
  102. package/dist/node/text-visualizer.1e770afa.js +0 -2
  103. package/dist/node/text-visualizer.1e770afa.js.map +0 -1
  104. package/dist/node/type-selector.0035ef7d.js +0 -2
  105. package/dist/node/type-selector.0035ef7d.js.map +0 -1
@@ -1,9 +1,10 @@
1
- import "./main.module.2f2972c8.css";
2
- import $9y0hV$mainmodulecd706d67js from "./main.module.cd706d67.js";
1
+ import "./feedback-components.e273ed5b.css";
2
+ import $9y0hV$feedbackcomponents6d32ee91js from "./feedback-components.6d32ee91.js";
3
3
  import $9y0hV$classnames from "classnames";
4
4
  import {Tag as $9y0hV$Tag} from "@blueprintjs/core";
5
5
  import {asChromaColor as $9y0hV$asChromaColor} from "@macrostrat/color-utils";
6
6
  import $9y0hV$macrostrathyper from "@macrostrat/hyper";
7
+ import {useDarkMode as $9y0hV$useDarkMode} from "@macrostrat/ui-components";
7
8
 
8
9
 
9
10
  function $parcel$interopDefault(a) {
@@ -14,7 +15,8 @@ function $parcel$interopDefault(a) {
14
15
 
15
16
 
16
17
 
17
- const $03d8811e9c9b360d$var$h = (0, $9y0hV$macrostrathyper).styled((0, ($parcel$interopDefault($9y0hV$mainmodulecd706d67js))));
18
+
19
+ const $03d8811e9c9b360d$var$h = (0, $9y0hV$macrostrathyper).styled((0, ($parcel$interopDefault($9y0hV$feedbackcomponents6d32ee91js))));
18
20
  function $03d8811e9c9b360d$export$c4b91360064ad200(entities, parent) {
19
21
  let highlights = [];
20
22
  let parents = [];
@@ -27,8 +29,8 @@ function $03d8811e9c9b360d$export$c4b91360064ad200(entities, parent) {
27
29
  start: entity.indices[0],
28
30
  end: entity.indices[1],
29
31
  text: entity.name,
30
- backgroundColor: entity.type.color ?? "#ddd",
31
- tag: entity.type.name,
32
+ backgroundColor: entity.type?.color,
33
+ tag: entity.type?.name ?? "lith",
32
34
  id: entity.id,
33
35
  parents: parents
34
36
  });
@@ -44,25 +46,32 @@ function $03d8811e9c9b360d$export$d60b563f571177d(extractionData, models, entity
44
46
  };
45
47
  }
46
48
  function $03d8811e9c9b360d$export$35baa338324d8550(baseColor, options) {
47
- const _baseColor = (0, $9y0hV$asChromaColor)(baseColor ?? "#ddd");
48
- const { highlighted: highlighted = true, inDarkMode: inDarkMode = false, active: active = false } = options;
49
+ const _baseColor = (0, $9y0hV$asChromaColor)(baseColor ?? "#fff");
50
+ const { highlighted: highlighted = true, inDarkMode: inDarkMode = (0, $9y0hV$useDarkMode)().isEnabled, active: active = false } = options;
49
51
  let mixAmount = highlighted ? 0.8 : 0.5;
50
52
  let backgroundAlpha = highlighted ? 0.8 : 0.2;
51
53
  if (active) {
52
54
  mixAmount = 1;
53
55
  backgroundAlpha = 1;
54
56
  }
55
- const mixTarget = inDarkMode ? "white" : "black";
56
- const color = _baseColor.mix(mixTarget, mixAmount).css();
57
- const borderColor = highlighted ? _baseColor.mix(mixTarget, mixAmount / 2).css() : "transparent";
57
+ const mixTarget = "black";
58
+ const color = active ? "#000" : _baseColor.mix(mixTarget, mixAmount).hex();
59
+ const borderColor = highlighted ? _baseColor.mix(mixTarget, mixAmount / 1.1).hex() : "transparent";
60
+ let backgroundColor = active ? _baseColor.alpha(backgroundAlpha).hex() : $03d8811e9c9b360d$var$normalizeColor(_baseColor.alpha(backgroundAlpha).hex());
61
+ // handle white backgrounds in light mode
62
+ if (!inDarkMode && backgroundColor === "#ffffff") {
63
+ console.log("Adjusting background color for light mode:", backgroundColor);
64
+ backgroundColor = "#f0f0f0";
65
+ }
58
66
  return {
59
67
  color: color,
60
- backgroundColor: _baseColor.alpha(backgroundAlpha).css(),
68
+ backgroundColor: backgroundColor,
61
69
  boxSizing: "border-box",
62
70
  borderStyle: "solid",
63
71
  borderColor: borderColor,
64
- borderWidth: "1px",
65
- fontWeight: active ? "bold" : "normal"
72
+ borderWidth: "1.5px",
73
+ fontWeight: active ? "bold" : "normal",
74
+ fontSize: "0.9em"
66
75
  };
67
76
  }
68
77
  function $03d8811e9c9b360d$var$enhanceEntity(entity, entityTypes) {
@@ -73,7 +82,7 @@ function $03d8811e9c9b360d$var$enhanceEntity(entity, entityTypes) {
73
82
  };
74
83
  }
75
84
  function $03d8811e9c9b360d$var$addColor(entityType, match = false) {
76
- const color = (0, $9y0hV$asChromaColor)(entityType.color ?? "#ddd").brighten(match ? 1 : 2);
85
+ const color = (0, $9y0hV$asChromaColor)(entityType.color ?? "#fff").brighten(match ? 1 : 2);
77
86
  return {
78
87
  ...entityType,
79
88
  color: color.css()
@@ -105,9 +114,9 @@ function $03d8811e9c9b360d$export$117e56c71b172cde({ data: data, highlighted: hi
105
114
  const { name: name, type: type, match: match } = data;
106
115
  const className = (0, $9y0hV$classnames)({
107
116
  matched: match != null,
108
- type: data.type.name
117
+ type: data.type?.name ?? "lith"
109
118
  }, "entity");
110
- const style = $03d8811e9c9b360d$export$35baa338324d8550(type.color ?? "#aaaaaa", {
119
+ const style = $03d8811e9c9b360d$export$35baa338324d8550(type?.color, {
111
120
  highlighted: highlighted,
112
121
  active: active
113
122
  });
@@ -129,7 +138,7 @@ function $03d8811e9c9b360d$export$117e56c71b172cde({ data: data, highlighted: hi
129
138
  }
130
139
  }
131
140
  }, [
132
- type.name,
141
+ type?.name,
133
142
  _matchLink
134
143
  ])
135
144
  ]);
@@ -171,7 +180,26 @@ function $03d8811e9c9b360d$var$HighlightedText(props) {
171
180
  parts.push(text.slice(start));
172
181
  return $03d8811e9c9b360d$var$h("span", parts);
173
182
  }
183
+ function $03d8811e9c9b360d$var$normalizeColor(hex8) {
184
+ const background = (0, $9y0hV$useDarkMode)().isEnabled ? "#000000" : "#ffffff";
185
+ const r = parseInt(hex8.slice(1, 3), 16);
186
+ const g = parseInt(hex8.slice(3, 5), 16);
187
+ const b = parseInt(hex8.slice(5, 7), 16);
188
+ const a = parseInt(hex8.slice(7, 9), 16) / 255;
189
+ const bgR = parseInt(background.slice(1, 3), 16);
190
+ const bgG = parseInt(background.slice(3, 5), 16);
191
+ const bgB = parseInt(background.slice(5, 7), 16);
192
+ const blend = (fg, bg)=>Math.round((1 - a) * bg + a * fg);
193
+ const blendedR = blend(r, bgR);
194
+ const blendedG = blend(g, bgG);
195
+ const blendedB = blend(b, bgB);
196
+ return "#" + blendedR.toString(16).padStart(2, "0") + blendedG.toString(16).padStart(2, "0") + blendedB.toString(16).padStart(2, "0");
197
+ }
198
+ function $03d8811e9c9b360d$var$isHighlighted(id, selectedNodes, nodes) {
199
+ if (selectedNodes?.length === 0) return true;
200
+ return selectedNodes?.includes(id) || nodes?.some((node)=>selectedNodes?.includes(node.id) && node.children.some((child)=>child.id === id));
201
+ }
174
202
 
175
203
 
176
204
  export {$03d8811e9c9b360d$export$c4b91360064ad200 as buildHighlights, $03d8811e9c9b360d$export$d60b563f571177d as enhanceData, $03d8811e9c9b360d$export$35baa338324d8550 as getTagStyle, $03d8811e9c9b360d$export$2b07158757c249e0 as ExtractionContext, $03d8811e9c9b360d$export$4eb2a0ce903ce967 as ModelInfo, $03d8811e9c9b360d$export$117e56c71b172cde as EntityTag};
177
- //# sourceMappingURL=extractions.65bb73cc.js.map
205
+ //# sourceMappingURL=feedback-components.5df2a926.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;AAWA,MAAM,0BAAI,CAAA,GAAA,sBAAI,EAAE,MAAM,CAAC,CAAA,GAAA,8EAAK;AAErB,SAAS,0CACd,QAAqB,EACrB,MAAwB;IAExB,IAAI,aAAa,EAAE;IACnB,IAAI,UAAU,EAAE;IAChB,IAAI,UAAU,MACZ,UAAU;QAAC,OAAO,EAAE;WAAM,OAAO,OAAO,IAAI,EAAE;KAAE;IAGlD,KAAK,MAAM,UAAU,SAAU;Q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Ae,SAAS,KAAK,EAAE,KAC/B,KAAK,QAAQ,CAAC,IAAI,CAAC,CAAC,QAAU,MAAM,EAAE,KAAK;AAGnD","sources":["packages/feedback-components/src/extractions/index.ts"],"sourcesContent":["import styles from \"./main.module.sass\";\nimport classNames from \"classnames\";\nimport { Tag } from \"@blueprintjs/core\";\nimport type { Entity, EntityExt, Highlight, EntityType } from \"./types\";\nimport { CSSProperties } from \"react\";\nimport { asChromaColor } from \"@macrostrat/color-utils\";\nimport hyper from \"@macrostrat/hyper\";\nimport { useDarkMode } from \"@macrostrat/ui-components\";\n\nexport type { Entity, EntityExt };\n\nconst h = hyper.styled(styles);\n\nexport function buildHighlights(\n entities: EntityExt[],\n parent: EntityExt | null,\n): Highlight[] {\n let highlights = [];\n let parents = [];\n if (parent != null) {\n parents = [parent.id, ...(parent.parents ?? [])];\n }\n\n for (const entity of entities) {\n highlights.push({\n start: entity.indices[0],\n end: entity.indices[1],\n text: entity.name,\n backgroundColor: entity.type?.color,\n tag: entity.type?.name ?? \"lith\",\n id: entity.id,\n parents,\n });\n highlights.push(...buildHighlights(entity.children ?? [], entity));\n }\n return highlights;\n}\n\nexport function enhanceData(extractionData, models, entityTypes) {\n return {\n ...extractionData,\n model: models.get(extractionData.model_id),\n entities: extractionData.entities?.map((d) =>\n enhanceEntity(d, entityTypes),\n ),\n };\n}\n\nexport function getTagStyle(\n baseColor: string,\n options: { highlighted?: boolean; inDarkMode?: boolean; active?: boolean },\n): CSSProperties {\n const _baseColor = asChromaColor(baseColor ?? \"#fff\");\n const {\n highlighted = true,\n inDarkMode = useDarkMode().isEnabled,\n active = false,\n } = options;\n\n let mixAmount = highlighted ? 0.8 : 0.5;\n let backgroundAlpha = highlighted ? 0.8 : 0.2;\n\n if (active) {\n mixAmount = 1;\n backgroundAlpha = 1;\n }\n\n const mixTarget = \"black\";\n\n const color = active ? \"#000\" : _baseColor.mix(mixTarget, mixAmount).hex();\n const borderColor = highlighted\n ? _baseColor.mix(mixTarget, mixAmount / 1.1).hex()\n : \"transparent\";\n\n let backgroundColor = active\n ? _baseColor.alpha(backgroundAlpha).hex()\n : normalizeColor(_baseColor.alpha(backgroundAlpha).hex());\n\n // handle white backgrounds in light mode\n if (!inDarkMode && backgroundColor === \"#ffffff\") {\n console.log(\"Adjusting background color for light mode:\", backgroundColor);\n backgroundColor = \"#f0f0f0\";\n }\n\n return {\n color,\n backgroundColor,\n boxSizing: \"border-box\",\n borderStyle: \"solid\",\n borderColor,\n borderWidth: \"1.5px\",\n fontWeight: active ? \"bold\" : \"normal\",\n fontSize: \"0.9em\",\n };\n}\n\nfunction enhanceEntity(\n entity: Entity,\n entityTypes: Map<number, EntityType>,\n): EntityExt {\n return {\n ...entity,\n type: addColor(entityTypes.get(entity.type), entity.match != null),\n children: entity.children?.map((d) => enhanceEntity(d, entityTypes)),\n };\n}\n\nfunction addColor(entityType: EntityType, match = false) {\n const color = asChromaColor(entityType.color ?? \"#fff\").brighten(\n match ? 1 : 2,\n );\n\n return { ...entityType, color: color.css() };\n}\n\nexport function ExtractionContext({\n data,\n entityTypes,\n matchComponent,\n}: {\n data: any;\n entityTypes: Map<number, EntityType>;\n matchComponent: MatchComponent;\n}) {\n const highlights = buildHighlights(data.entities, null);\n\n return h(\"div\", [\n h(\"p\", h(HighlightedText, { text: data.paragraph_text, highlights })),\n h(ModelInfo, { data: data.model }),\n h(\n \"ul.entities\",\n data.entities.map((d) => h(ExtractionInfo, { data: d, matchComponent })),\n ),\n ]);\n}\n\nexport function ModelInfo({ data }) {\n return h(\"p.model-name\", [\"Model: \", h(\"code.bp5-code\", data.name)]);\n}\n\nexport type MatchComponent = (props: { data: any }) => any;\n\ntype EntityTagProps = {\n data: EntityExt;\n highlighted?: boolean;\n active?: boolean;\n onClickType?: (type: EntityType) => void;\n matchComponent?: MatchComponent;\n};\n\nexport function EntityTag({\n data,\n highlighted = true,\n active = false,\n onClickType,\n matchComponent = null,\n}: EntityTagProps) {\n const { name, type, match } = data;\n\n const className = classNames(\n {\n matched: match != null,\n type: data.type?.name ?? \"lith\",\n },\n \"entity\",\n );\n\n const style = getTagStyle(type?.color, { highlighted, active });\n\n let _matchLink = null;\n if (match != null && matchComponent != null) {\n _matchLink = h(matchComponent, { data: match });\n }\n\n return h(Tag, { style, className }, [\n h(\"span.entity-name\", name),\n \" \",\n h(\n \"code.entity-type.bp5-code\",\n {\n onClick(evt) {\n if (active && onClickType != null) {\n onClickType(type);\n evt.stopPropagation();\n }\n },\n },\n [type?.name, _matchLink],\n ),\n ]);\n}\n\nfunction ExtractionInfo({\n data,\n matchComponent = null,\n}: {\n data: EntityExt;\n matchComponent: MatchComponent;\n}) {\n const children = data.children ?? [];\n\n return h(\"li.entity-row\", [\n h(EntityTag, { data, matchComponent }),\n h.if(children.length > 0)([\n h(\n \"ul.children\",\n children.map((d) => h(ExtractionInfo, { data: d, matchComponent })),\n ),\n ]),\n ]);\n}\n\nfunction HighlightedText(props: { text: string; highlights: Highlight[] }) {\n const { text, highlights = [] } = props;\n const parts = [];\n let start = 0;\n\n const sortedHighlights = highlights.sort((a, b) => a.start - b.start);\n const deconflictedHighlights = sortedHighlights.map((highlight, i) => {\n if (i === 0) return highlight;\n const prev = sortedHighlights[i - 1];\n if (highlight.start < prev.end) {\n highlight.start = prev.end;\n }\n return highlight;\n });\n\n for (const highlight of deconflictedHighlights) {\n const { start: s, end, ...rest } = highlight;\n parts.push(text.slice(start, s));\n parts.push(h(\"span.highlight\", { style: rest }, text.slice(s, end)));\n start = end;\n }\n parts.push(text.slice(start));\n return h(\"span\", parts);\n}\n\nfunction normalizeColor(hex8) {\n const background = useDarkMode().isEnabled ? \"#000000\" : \"#ffffff\";\n\n const r = parseInt(hex8.slice(1, 3), 16);\n const g = parseInt(hex8.slice(3, 5), 16);\n const b = parseInt(hex8.slice(5, 7), 16);\n const a = parseInt(hex8.slice(7, 9), 16) / 255;\n\n const bgR = parseInt(background.slice(1, 3), 16);\n const bgG = parseInt(background.slice(3, 5), 16);\n const bgB = parseInt(background.slice(5, 7), 16);\n\n const blend = (fg, bg) => Math.round((1 - a) * bg + a * fg);\n\n const blendedR = blend(r, bgR);\n const blendedG = blend(g, bgG);\n const blendedB = blend(b, bgB);\n\n return (\n \"#\" +\n blendedR.toString(16).padStart(2, \"0\") +\n blendedG.toString(16).padStart(2, \"0\") +\n blendedB.toString(16).padStart(2, \"0\")\n );\n}\n\nfunction isHighlighted(id: number, selectedNodes: number[], nodes: any[]) {\n if (selectedNodes?.length === 0) return true;\n return (\n selectedNodes?.includes(id) ||\n nodes?.some(\n (node) =>\n selectedNodes?.includes(node.id) &&\n node.children.some((child) => child.id === id),\n )\n );\n}\n"],"names":[],"version":3,"file":"feedback-components.5df2a926.js.map"}
@@ -13,4 +13,4 @@ $83cb1ce4a2b71eef$export$4b5127edceda427d = `UZr1Jq_entity`;
13
13
 
14
14
 
15
15
  export {$83cb1ce4a2b71eef$exports as default};
16
- //# sourceMappingURL=main.module.cd706d67.js.map
16
+ //# sourceMappingURL=feedback-components.6d32ee91.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA,IAAA;AACA,IAAA;AADA,4CAA6B,CAAC,eAAe,CAAC;AAC9C,4CAA2B,CAAC,aAAa,CAAC","sources":["packages/feedback-components/src/extractions/main.module.sass"],"sourcesContent":[".entities\n list-style: none\n padding-left: 0\n\n .entities ul\n list-style: none\n\n.entity\n margin: 0.2em 0 0.5em\n padding-right: 3px\n"],"names":[],"version":3,"file":"main.module.cd706d67.js.map"}
1
+ {"mappings":";;;;;;;;AAAA,IAAA;AACA,IAAA;AADA,4CAA6B,CAAC,eAAe,CAAC;AAC9C,4CAA2B,CAAC,aAAa,CAAC","sources":["packages/feedback-components/src/extractions/main.module.sass"],"sourcesContent":[".entities\n list-style: none\n padding-left: 0\n\n .entities ul\n list-style: none\n\n.entity\n margin: 0.2em 0 0.5em\n padding-right: 3px\n"],"names":[],"version":3,"file":"feedback-components.6d32ee91.js.map"}
@@ -0,0 +1,82 @@
1
+
2
+ function $parcel$export(e, n, v, s) {
3
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
4
+ }
5
+ var $49c87ee97f392268$exports = {};
6
+
7
+ $parcel$export($49c87ee97f392268$exports, "add-type", () => $49c87ee97f392268$export$cb889aaddfa2926c, (v) => $49c87ee97f392268$export$cb889aaddfa2926c = v);
8
+ $parcel$export($49c87ee97f392268$exports, "add-type-overlay", () => $49c87ee97f392268$export$5f8f750fd71deeed, (v) => $49c87ee97f392268$export$5f8f750fd71deeed = v);
9
+ $parcel$export($49c87ee97f392268$exports, "control-content", () => $49c87ee97f392268$export$42e8b5293e69631e, (v) => $49c87ee97f392268$export$42e8b5293e69631e = v);
10
+ $parcel$export($49c87ee97f392268$exports, "control-panel", () => $49c87ee97f392268$export$a0a23f31d5562853, (v) => $49c87ee97f392268$export$a0a23f31d5562853 = v);
11
+ $parcel$export($49c87ee97f392268$exports, "description", () => $49c87ee97f392268$export$6d59db4903f20f7d, (v) => $49c87ee97f392268$export$6d59db4903f20f7d = v);
12
+ $parcel$export($49c87ee97f392268$exports, "entity-panel", () => $49c87ee97f392268$export$38f2cd12e45697e, (v) => $49c87ee97f392268$export$38f2cd12e45697e = v);
13
+ $parcel$export($49c87ee97f392268$exports, "feedback-component", () => $49c87ee97f392268$export$579bd45c78bf5510, (v) => $49c87ee97f392268$export$579bd45c78bf5510 = v);
14
+ $parcel$export($49c87ee97f392268$exports, "feedback-container", () => $49c87ee97f392268$export$23889d205b405f6e, (v) => $49c87ee97f392268$export$23889d205b405f6e = v);
15
+ $parcel$export($49c87ee97f392268$exports, "feedback-text", () => $49c87ee97f392268$export$890489be1870bed5, (v) => $49c87ee97f392268$export$890489be1870bed5 = v);
16
+ $parcel$export($49c87ee97f392268$exports, "feedback-text-wrapper", () => $49c87ee97f392268$export$6bd0fd0a746c88f, (v) => $49c87ee97f392268$export$6bd0fd0a746c88f = v);
17
+ $parcel$export($49c87ee97f392268$exports, "form-group", () => $49c87ee97f392268$export$55a1f87a143fb302, (v) => $49c87ee97f392268$export$55a1f87a143fb302 = v);
18
+ $parcel$export($49c87ee97f392268$exports, "highlight", () => $49c87ee97f392268$export$e4043f67d36cbb26, (v) => $49c87ee97f392268$export$e4043f67d36cbb26 = v);
19
+ $parcel$export($49c87ee97f392268$exports, "icons", () => $49c87ee97f392268$export$df03f54e09e486fa, (v) => $49c87ee97f392268$export$df03f54e09e486fa = v);
20
+ $parcel$export($49c87ee97f392268$exports, "node", () => $49c87ee97f392268$export$35059013cd4a06db, (v) => $49c87ee97f392268$export$35059013cd4a06db = v);
21
+ $parcel$export($49c87ee97f392268$exports, "node-label", () => $49c87ee97f392268$export$75d14899fb692bb6, (v) => $49c87ee97f392268$export$75d14899fb692bb6 = v);
22
+ $parcel$export($49c87ee97f392268$exports, "overlay-container", () => $49c87ee97f392268$export$6a1093e41947f68e, (v) => $49c87ee97f392268$export$6a1093e41947f68e = v);
23
+ $parcel$export($49c87ee97f392268$exports, "page-wrapper", () => $49c87ee97f392268$export$7c414e944018fb15, (v) => $49c87ee97f392268$export$7c414e944018fb15 = v);
24
+ $parcel$export($49c87ee97f392268$exports, "selected", () => $49c87ee97f392268$export$d90250155de6d7e7, (v) => $49c87ee97f392268$export$d90250155de6d7e7 = v);
25
+ $parcel$export($49c87ee97f392268$exports, "selection-tree", () => $49c87ee97f392268$export$3ae1b51693c80a9c, (v) => $49c87ee97f392268$export$3ae1b51693c80a9c = v);
26
+ $parcel$export($49c87ee97f392268$exports, "text-inputs", () => $49c87ee97f392268$export$bc7581b048bdc9d, (v) => $49c87ee97f392268$export$bc7581b048bdc9d = v);
27
+ $parcel$export($49c87ee97f392268$exports, "title", () => $49c87ee97f392268$export$fb184b623420d9be, (v) => $49c87ee97f392268$export$fb184b623420d9be = v);
28
+ $parcel$export($49c87ee97f392268$exports, "type-container", () => $49c87ee97f392268$export$b2d17fca990bb66c, (v) => $49c87ee97f392268$export$b2d17fca990bb66c = v);
29
+ $parcel$export($49c87ee97f392268$exports, "type-list", () => $49c87ee97f392268$export$915fe2ca68846e4c, (v) => $49c87ee97f392268$export$915fe2ca68846e4c = v);
30
+ $parcel$export($49c87ee97f392268$exports, "type-tag", () => $49c87ee97f392268$export$5e5acbc770fb0e4, (v) => $49c87ee97f392268$export$5e5acbc770fb0e4 = v);
31
+ var $49c87ee97f392268$export$cb889aaddfa2926c;
32
+ var $49c87ee97f392268$export$5f8f750fd71deeed;
33
+ var $49c87ee97f392268$export$42e8b5293e69631e;
34
+ var $49c87ee97f392268$export$a0a23f31d5562853;
35
+ var $49c87ee97f392268$export$6d59db4903f20f7d;
36
+ var $49c87ee97f392268$export$38f2cd12e45697e;
37
+ var $49c87ee97f392268$export$579bd45c78bf5510;
38
+ var $49c87ee97f392268$export$23889d205b405f6e;
39
+ var $49c87ee97f392268$export$890489be1870bed5;
40
+ var $49c87ee97f392268$export$6bd0fd0a746c88f;
41
+ var $49c87ee97f392268$export$55a1f87a143fb302;
42
+ var $49c87ee97f392268$export$e4043f67d36cbb26;
43
+ var $49c87ee97f392268$export$df03f54e09e486fa;
44
+ var $49c87ee97f392268$export$35059013cd4a06db;
45
+ var $49c87ee97f392268$export$75d14899fb692bb6;
46
+ var $49c87ee97f392268$export$6a1093e41947f68e;
47
+ var $49c87ee97f392268$export$7c414e944018fb15;
48
+ var $49c87ee97f392268$export$d90250155de6d7e7;
49
+ var $49c87ee97f392268$export$3ae1b51693c80a9c;
50
+ var $49c87ee97f392268$export$bc7581b048bdc9d;
51
+ var $49c87ee97f392268$export$fb184b623420d9be;
52
+ var $49c87ee97f392268$export$b2d17fca990bb66c;
53
+ var $49c87ee97f392268$export$915fe2ca68846e4c;
54
+ var $49c87ee97f392268$export$5e5acbc770fb0e4;
55
+ $49c87ee97f392268$export$cb889aaddfa2926c = `QoX8-W_add-type`;
56
+ $49c87ee97f392268$export$5f8f750fd71deeed = `QoX8-W_add-type-overlay`;
57
+ $49c87ee97f392268$export$42e8b5293e69631e = `QoX8-W_control-content`;
58
+ $49c87ee97f392268$export$a0a23f31d5562853 = `QoX8-W_control-panel`;
59
+ $49c87ee97f392268$export$6d59db4903f20f7d = `QoX8-W_description`;
60
+ $49c87ee97f392268$export$38f2cd12e45697e = `QoX8-W_entity-panel`;
61
+ $49c87ee97f392268$export$579bd45c78bf5510 = `QoX8-W_feedback-component`;
62
+ $49c87ee97f392268$export$23889d205b405f6e = `QoX8-W_feedback-container`;
63
+ $49c87ee97f392268$export$890489be1870bed5 = `QoX8-W_feedback-text`;
64
+ $49c87ee97f392268$export$6bd0fd0a746c88f = `QoX8-W_feedback-text-wrapper`;
65
+ $49c87ee97f392268$export$55a1f87a143fb302 = `QoX8-W_form-group`;
66
+ $49c87ee97f392268$export$e4043f67d36cbb26 = `QoX8-W_highlight`;
67
+ $49c87ee97f392268$export$df03f54e09e486fa = `QoX8-W_icons`;
68
+ $49c87ee97f392268$export$35059013cd4a06db = `QoX8-W_node`;
69
+ $49c87ee97f392268$export$75d14899fb692bb6 = `QoX8-W_node-label`;
70
+ $49c87ee97f392268$export$6a1093e41947f68e = `QoX8-W_overlay-container`;
71
+ $49c87ee97f392268$export$7c414e944018fb15 = `QoX8-W_page-wrapper`;
72
+ $49c87ee97f392268$export$d90250155de6d7e7 = `QoX8-W_selected`;
73
+ $49c87ee97f392268$export$3ae1b51693c80a9c = `QoX8-W_selection-tree`;
74
+ $49c87ee97f392268$export$bc7581b048bdc9d = `QoX8-W_text-inputs`;
75
+ $49c87ee97f392268$export$fb184b623420d9be = `QoX8-W_title`;
76
+ $49c87ee97f392268$export$b2d17fca990bb66c = `QoX8-W_type-container`;
77
+ $49c87ee97f392268$export$915fe2ca68846e4c = `QoX8-W_type-list`;
78
+ $49c87ee97f392268$export$5e5acbc770fb0e4 = `QoX8-W_type-tag`;
79
+
80
+
81
+ export {$49c87ee97f392268$exports as default};
82
+ //# sourceMappingURL=feedback-components.95dbe7d7.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAvBA,4CAA6B,CAAC,eAAe,CAAC;AAC9C,4CAAqC,CAAC,uBAAuB,CAAC;AAC9D,4CAAoC,CAAC,sBAAsB,CAAC;AAC5D,4CAAkC,CAAC,oBAAoB,CAAC;AACxD,4CAAgC,CAAC,kBAAkB,CAAC;AACpD,2CAAiC,CAAC,mBAAmB,CAAC;AACtD,4CAAuC,CAAC,yBAAyB,CAAC;AAClE,4CAAuC,CAAC,yBAAyB,CAAC;AAClE,4CAAkC,CAAC,oBAAoB,CAAC;AACxD,2CAA0C,CAAC,4BAA4B,CAAC;AACxE,4CAA+B,CAAC,iBAAiB,CAAC;AAClD,4CAA8B,CAAC,gBAAgB,CAAC;AAChD,4CAA0B,CAAC,YAAY,CAAC;AACxC,4CAAyB,CAAC,WAAW,CAAC;AACtC,4CAA+B,CAAC,iBAAiB,CAAC;AAClD,4CAAsC,CAAC,wBAAwB,CAAC;AAChE,4CAAiC,CAAC,mBAAmB,CAAC;AACtD,4CAA6B,CAAC,eAAe,CAAC;AAC9C,4CAAmC,CAAC,qBAAqB,CAAC;AAC1D,2CAAgC,CAAC,kBAAkB,CAAC;AACpD,4CAA0B,CAAC,YAAY,CAAC;AACxC,4CAAmC,CAAC,qBAAqB,CAAC;AAC1D,4CAA8B,CAAC,gBAAgB,CAAC;AAChD,2CAA6B,CAAC,eAAe,CAAC","sources":["packages/feedback-components/src/feedback/feedback.module.sass"],"sourcesContent":[":root\n --text-line-height: 3em\n --main-extra-width: 200px\n\n.page-wrapper\n display: flex\n flex-direction: row\n position: relative\n gap: 2em\n align-items: flex-start // makes control-content lose stick\n\n.feedback-container\n flex: 4\n\n.control-panel\n flex: 1\n height: auto\n\n.control-content\n position: sticky\n top: 0\n\n.feedback-component\n position: relative\n width: 800px\n\n & > svg\n width: 800px\n\n.node\n cursor: pointer\n\ncircle\n cursor: pointer\n border: 1px solid black\n\n.selected\n border: 1px solid white\n \n.feedback-text\n margin-bottom: 2em\n\n.entity-panel\n position: relative\n max-height: 600px\n width: calc(100% - 2em)\n flex: 1\n min-height: 100px\n padding: 1em\n background: var(--panel-secondary-background-color)\n border-radius: 4px\n // Inset box shadow\n box-shadow: 0 0 0 1px var(--panel-border-color) inset\n\n.selection-tree\n margin: -1em 0\n padding: 1em 0\n \n.type-list\n display: grid\n grid-auto-flow: column\n grid-template-rows: repeat(10, auto)\n gap: 0.2em\n\n .type-tag\n padding: .2em .5em\n border-radius: .2em\n\n.description\n max-width: 300px\n padding: .5em\n\nmark\n border-radius: .2em\n cursor: pointer\n color: black !important\n\n[role=\"treeitem\"]\n width: auto !important\n\n.highlight\n cursor: pointer\n padding: .2em 0\n border-radius: .2em\n position: relative\n zIndex: 10\n\n.feedback-text-wrapper \n position: relative\n z-index: 0\n overflow: visible\n line-height: var(--text-line-height)\n\n.type-container\n display: flex\n justify-content: space-between\n align-items: center\n column-gap: 1em\n\n.add-type\n cursor: pointer\n display: flex\n justify-content: space-between\n padding: 0 .5em\n align-items: center\n\n p\n margin: 0\n\n.overlay-container\n height: 80vh\n width: 100vw\n display: flex\n justify-content: center\n align-items: center\n\n .add-type-overlay\n background-color: var(--secondary-color)\n padding: .5em 1em\n display: flex\n flex-direction: column\n gap: 1em\n border-radius: .2em\n\n .title\n display: flex\n justify-content: space-between\n align-items: center\n\n h2\n margin: 0\n\n .form-group\n display: flex\n gap: 3em\n\n .text-inputs\n display: flex\n flex-direction: column\n gap: 1em\n\n.icons\n display: flex\n gap: .25em\n\n.node-label\n fill: var(--text-emphasized-color)\n fontSize: 10px\n pointerEvents: none"],"names":[],"version":3,"file":"feedback-components.95dbe7d7.js.map"}
@@ -1,5 +1,5 @@
1
- import "./main.module.8d366b6e.css";
2
- import $N2zU5$mainmoduled2fbdf09js from "./main.module.d2fbdf09.js";
1
+ import "./feedback-components.bf93773c.css";
2
+ import $N2zU5$feedbackcomponentsf9850d85js from "./feedback-components.f9850d85.js";
3
3
  import $N2zU5$macrostrathyper from "@macrostrat/hyper";
4
4
  import $N2zU5$classnames from "classnames";
5
5
  import {Omnibar as $N2zU5$Omnibar} from "@blueprintjs/select";
@@ -16,7 +16,7 @@ function $parcel$interopDefault(a) {
16
16
 
17
17
 
18
18
 
19
- const $fda9ef5406c1cfb4$var$h = (0, $N2zU5$macrostrathyper).styled((0, ($parcel$interopDefault($N2zU5$mainmoduled2fbdf09js))));
19
+ const $fda9ef5406c1cfb4$var$h = (0, $N2zU5$macrostrathyper).styled((0, ($parcel$interopDefault($N2zU5$feedbackcomponentsf9850d85js))));
20
20
  const $fda9ef5406c1cfb4$var$TagListItem = (props)=>{
21
21
  /** Render a tag for the omnibox list */ let { active: active, selected: selected, className: className, onSelect: onSelect, item: item, children: children } = props;
22
22
  className = (0, $N2zU5$classnames)({
@@ -38,10 +38,11 @@ const $fda9ef5406c1cfb4$var$TagListItem = (props)=>{
38
38
  ]);
39
39
  };
40
40
  function $fda9ef5406c1cfb4$export$d8660660a589068c(props) {
41
- /** A general omnibox for annotation types */ const { onSelectItem: onSelectItem, items: items, isOpen: isOpen, onClose: onClose } = props;
41
+ /** A general omnibox for annotation types */ const { onSelectItem: onSelectItem, items: items, isOpen: isOpen, onClose: onClose, onQueryChange: onQueryChange } = props;
42
42
  return $fda9ef5406c1cfb4$var$h((0, $N2zU5$Omnibar), {
43
43
  onItemSelect: onSelectItem,
44
44
  items: items,
45
+ onQueryChange: onQueryChange,
45
46
  resetOnSelect: false,
46
47
  isOpen: isOpen,
47
48
  onClose: onClose,
@@ -59,4 +60,4 @@ function $fda9ef5406c1cfb4$export$d8660660a589068c(props) {
59
60
 
60
61
 
61
62
  export {$fda9ef5406c1cfb4$export$d8660660a589068c as OmniboxSelector};
62
- //# sourceMappingURL=type-selector.6e8952d6.js.map
63
+ //# sourceMappingURL=feedback-components.ad9f284e.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;AAAA;;CAEC;;;;;AAUD,MAAM,0BAAI,CAAA,GAAA,sBAAI,EAAE,MAAM,CAAC,CAAA,GAAA,8EAAK;AAa5B,MAAM,oCAAoD,CAAC;IACzD,sCAAsC,GACtC,IAAI,UAAE,MAAM,YAAE,QAAQ,aAAE,SAAS,YAAE,QAAQ,QAAE,IAAI,YAAE,QAAQ,EAAE,GAAG;IAChE,YAAY,CAAA,GAAA,iBAAS,EAAE;gBAAE;kBAAQ;IAAS,GAAG;IAC7C,MAAM,UAAU,IAAM,SAAS;IAE/B,OAAO,wBACL,sBACA;QACE,KAAK,KAAK,EAAE;mBACZ;iBACA;IACF,GACA;QACE,wBAAE,cAAc;YAAE,OAAO;gBAAE,iBAAiB,KAAK,KAAK;YAAC;QAAE;QACzD,wBAAE,YAAY,CAAC,GAAG,KAAK,IAAI;KAC5B;AAEL;AAYO,SAAS,0CAAmB,KAAsB;IACvD,2CAA2C,GAC3C,MAAM,gBAAE,YAAY,SAAE,KAAK,UAAE,MAAM,WAAE,OAAO,iBAAE,aAAa,EAAE,GAAG;IAEhE,OAAO,wBAAE,CAAA,GAAA,cAAM,GAAG;QAChB,cAAc;eACd;uBACA;QACA,eAAe;gBACf;iBACA;QACA,cAAa,IAAO,EAAE,eAAE,WAAW,aAAE,SAAS,EAAE;YAC9C,OAAO,wBAAE,mCAAa;gBACpB,KAAK,KAAK,EAAE;sBACZ;gBACA,UAAU;gBACV,QAAQ,UAAU,MAAM;gBACxB,UAAU,UAAU,MAAM;YAC5B;QACF;IACF;AACF","sources":["packages/feedback-components/src/feedback/type-selector/index.ts"],"sourcesContent":["/**\n * Entity type selector\n */\n\nimport styles from \"./main.module.sass\";\nimport hyper from \"@macrostrat/hyper\";\n\nimport classNames from \"classnames\";\nimport React from \"react\";\nimport { Omnibar, OmnibarProps } from \"@blueprintjs/select\";\nimport \"@blueprintjs/select/lib/css/blueprint-select.css\";\n\nconst h = hyper.styled(styles);\n\ninterface TagItemProps<T> {\n selected: boolean;\n active: boolean;\n className?: string;\n item: T;\n\n onSelect(t: T): void;\n\n children?: React.ReactElement;\n}\n\nconst TagListItem: React.ComponentType<TagItemProps<T>> = (props) => {\n /** Render a tag for the omnibox list */\n let { active, selected, className, onSelect, item, children } = props;\n className = classNames({ active, selected }, className);\n const onClick = () => onSelect(item);\n\n return h(\n \"div.item-container\",\n {\n key: item.id,\n className,\n onClick,\n },\n [\n h(\"div.swatch\", { style: { backgroundColor: item.color } }),\n h(\"div.item\", {}, item.name),\n ],\n );\n};\n\ntype BoxLifecycleProps<T> = Pick<OmnibarProps<T>, \"onClose\" | \"isOpen\">;\n\ninterface OmniboxProps<T> extends BoxLifecycleProps<T> {\n items: T[];\n selectedItem: T;\n onSelectItem: (t: T) => void;\n onQueryChange: (query: string) => void;\n listItemComponent?: React.ComponentType<TagItemProps<T>>;\n}\n\nexport function OmniboxSelector<T>(props: OmniboxProps<T>) {\n /** A general omnibox for annotation types */\n const { onSelectItem, items, isOpen, onClose, onQueryChange } = props;\n\n return h(Omnibar, {\n onItemSelect: onSelectItem,\n items,\n onQueryChange,\n resetOnSelect: false,\n isOpen,\n onClose,\n itemRenderer(item: T, { handleClick, modifiers }) {\n return h(TagListItem, {\n key: item.id,\n item,\n onSelect: handleClick,\n active: modifiers.active,\n selected: modifiers.active,\n });\n },\n });\n}\n"],"names":[],"version":3,"file":"feedback-components.ad9f284e.js.map"}
@@ -14,4 +14,4 @@
14
14
  width: 30px;
15
15
  height: 30px;
16
16
  }
17
- /*# sourceMappingURL=main.module.8d366b6e.css.map */
17
+ /*# sourceMappingURL=feedback-components.bf93773c.css.map */
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;AAME;;;;AAGF","sources":["packages/feedback-components/src/feedback/type-selector/main.module.sass"],"sourcesContent":[".item-container\n min-height: 40px\n display: flex\n align-items: center\n gap: 1em\n\n &.selected\n background-color: var(--panel-background-color)\n\n.swatch\n width: 30px\n height: 30px\n border-radius: 4px\n"],"names":[],"version":3,"file":"main.module.8d366b6e.css.map"}
1
+ {"mappings":"AAAA;;;;;;;AAME;;;;AAGF","sources":["packages/feedback-components/src/feedback/type-selector/main.module.sass"],"sourcesContent":[".item-container\n min-height: 40px\n display: flex\n align-items: center\n gap: 1em\n\n &.selected\n background-color: var(--panel-background-color)\n\n.swatch\n width: 30px\n height: 30px\n border-radius: 4px\n"],"names":[],"version":3,"file":"feedback-components.bf93773c.css.map"}
@@ -11,4 +11,4 @@
11
11
  margin: .2em 0 .5em;
12
12
  padding-right: 3px;
13
13
  }
14
- /*# sourceMappingURL=main.module.2f2972c8.css.map */
14
+ /*# sourceMappingURL=feedback-components.e273ed5b.css.map */
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;AAIE;;;;AAGF","sources":["packages/feedback-components/src/extractions/main.module.sass"],"sourcesContent":[".entities\n list-style: none\n padding-left: 0\n\n .entities ul\n list-style: none\n\n.entity\n margin: 0.2em 0 0.5em\n padding-right: 3px\n"],"names":[],"version":3,"file":"main.module.2f2972c8.css.map"}
1
+ {"mappings":"AAAA;;;;;AAIE;;;;AAGF","sources":["packages/feedback-components/src/extractions/main.module.sass"],"sourcesContent":[".entities\n list-style: none\n padding-left: 0\n\n .entities ul\n list-style: none\n\n.entity\n margin: 0.2em 0 0.5em\n padding-right: 3px\n"],"names":[],"version":3,"file":"feedback-components.e273ed5b.css.map"}
@@ -16,4 +16,4 @@ $f8bcd91cbf17e53f$export$c672d9950c40fe0a = `WofFTa_swatch`;
16
16
 
17
17
 
18
18
  export {$f8bcd91cbf17e53f$exports as default};
19
- //# sourceMappingURL=main.module.d2fbdf09.js.map
19
+ //# sourceMappingURL=feedback-components.f9850d85.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA,IAAA;AACA,IAAA;AACA,IAAA;AAFA,4CAAmC,CAAC,qBAAqB,CAAC;AAC1D,4CAA6B,CAAC,eAAe,CAAC;AAC9C,4CAA2B,CAAC,aAAa,CAAC","sources":["packages/feedback-components/src/feedback/type-selector/main.module.sass"],"sourcesContent":[".item-container\n min-height: 40px\n display: flex\n align-items: center\n gap: 1em\n\n &.selected\n background-color: var(--panel-background-color)\n\n.swatch\n width: 30px\n height: 30px\n border-radius: 4px\n"],"names":[],"version":3,"file":"main.module.d2fbdf09.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA,IAAA;AACA,IAAA;AACA,IAAA;AAFA,4CAAmC,CAAC,qBAAqB,CAAC;AAC1D,4CAA6B,CAAC,eAAe,CAAC;AAC9C,4CAA2B,CAAC,aAAa,CAAC","sources":["packages/feedback-components/src/feedback/type-selector/main.module.sass"],"sourcesContent":[".item-container\n min-height: 40px\n display: flex\n align-items: center\n gap: 1em\n\n &.selected\n background-color: var(--panel-background-color)\n\n.swatch\n width: 30px\n height: 30px\n border-radius: 4px\n"],"names":[],"version":3,"file":"feedback-components.f9850d85.js.map"}
@@ -10,6 +10,7 @@ var $b79bf29960412ca7$export$53ec42062883b2d4 = /*#__PURE__*/ function(ViewMode)
10
10
  }({});
11
11
  function $b79bf29960412ca7$export$911bb4b9c8065d3d(initialTree, entityTypes) {
12
12
  // Get the first entity type
13
+ // issue: grabs second entity instead of selected one
13
14
  const type = entityTypes.values().next().value;
14
15
  return (0, $abOVY$useReducer)($b79bf29960412ca7$var$treeReducer, {
15
16
  initialTree: initialTree,
@@ -29,8 +30,69 @@ function $b79bf29960412ca7$export$e1068f2d1c68f87e() {
29
30
  return dispatch;
30
31
  }
31
32
  function $b79bf29960412ca7$var$treeReducer(state, action) {
32
- console.log(action);
33
33
  switch(action.type){
34
+ case "add-entity-type":
35
+ {
36
+ // Add a new entity type to the map
37
+ const { name: name, description: description, color: color } = action.payload;
38
+ const newId = state.lastInternalId - 1;
39
+ const newType = {
40
+ id: newId,
41
+ name: name,
42
+ description: description === "" ? null : description,
43
+ color: color
44
+ };
45
+ const newEntityTypesMap = new Map(state.entityTypesMap);
46
+ newEntityTypesMap.set(newId, newType);
47
+ return {
48
+ ...state,
49
+ entityTypesMap: newEntityTypesMap,
50
+ selectedEntityType: newType,
51
+ lastInternalId: newId
52
+ };
53
+ }
54
+ case "update-entity-type":
55
+ {
56
+ // Update an existing entity type in the map
57
+ const { id: id, name: name, description: description, color: color } = action.payload;
58
+ const newEntityTypesMap = new Map(state.entityTypesMap);
59
+ const oldType = newEntityTypesMap.get(id);
60
+ if (!oldType) {
61
+ console.warn(`Entity type with id ${id} not found`);
62
+ return state;
63
+ }
64
+ const updatedType = {
65
+ ...oldType,
66
+ name: name,
67
+ description: description === "" ? null : description,
68
+ color: color
69
+ };
70
+ newEntityTypesMap.set(id, updatedType);
71
+ // Update the tree to reflect the new type
72
+ const newTree = $b79bf29960412ca7$var$updateTreeTypes(state.tree, oldType, updatedType);
73
+ return {
74
+ ...state,
75
+ tree: newTree,
76
+ entityTypesMap: newEntityTypesMap,
77
+ selectedEntityType: updatedType
78
+ };
79
+ }
80
+ case "select-range":
81
+ // Select a range of nodes by their IDs
82
+ const payloadIds = action.payload.ids;
83
+ const node1 = payloadIds[0];
84
+ const node2 = payloadIds[1];
85
+ // make list of nodes in order
86
+ const allNodes = $b79bf29960412ca7$var$flattenAndSort(state.tree);
87
+ // select all nodes between node1 and node2
88
+ const startIndex = allNodes.findIndex((node)=>node.id === node1);
89
+ const endIndex = allNodes.findIndex((node)=>node.id === node2);
90
+ const selectedNodes = allNodes.slice(startIndex, endIndex + 1);
91
+ console.log("Selecting range:", selectedNodes);
92
+ return {
93
+ ...state,
94
+ selectedNodes: selectedNodes.map((node)=>node.id)
95
+ };
34
96
  case "move-node":
35
97
  // For each node in the tree, if the node is in the dragIds, remove it from the tree and collect it
36
98
  const [newTree, removedNodes] = $b79bf29960412ca7$var$removeNodes(state.tree, action.payload.dragIds);
@@ -70,20 +132,24 @@ function $b79bf29960412ca7$var$treeReducer(state, action) {
70
132
  };
71
133
  case "select-node":
72
134
  const { ids: ids } = action.payload;
135
+ const type = action.payload.ids.length > 0 ? $b79bf29960412ca7$var$findNodeById(state.tree, ids[0])?.type : null;
73
136
  return {
74
137
  ...state,
75
- selectedNodes: ids
138
+ selectedNodes: ids,
139
+ selectedEntityType: type
76
140
  };
77
141
  // otherwise fall through to toggle-node-selected for a single ID
78
142
  case "toggle-node-selected":
79
143
  const nodesToAdd = action.payload.ids.filter((id)=>!state.selectedNodes.includes(id));
80
144
  const nodesToKeep = state.selectedNodes.filter((id)=>!action.payload.ids.includes(id));
145
+ const newType = action.payload.ids.length > 0 ? $b79bf29960412ca7$var$findNodeById(state.tree, action.payload.ids[0])?.type : null;
81
146
  return {
82
147
  ...state,
83
148
  selectedNodes: [
84
149
  ...nodesToKeep,
85
150
  ...nodesToAdd
86
- ]
151
+ ],
152
+ selectedEntityType: newType
87
153
  };
88
154
  case "create-node":
89
155
  const newId = state.lastInternalId - 1;
@@ -109,6 +175,23 @@ function $b79bf29960412ca7$var$treeReducer(state, action) {
109
175
  ],
110
176
  lastInternalId: newId
111
177
  };
178
+ case "delete-entity-type":
179
+ {
180
+ // Remove the entity type from the map
181
+ console.log("Deleting entity type:", action.payload.id);
182
+ const { id: id } = action.payload;
183
+ const newEntityTypesMap = new Map(state.entityTypesMap);
184
+ const oldType = newEntityTypesMap.get(id);
185
+ newEntityTypesMap.delete(id);
186
+ const defaultType = newEntityTypesMap.values().next().value;
187
+ const newTree = $b79bf29960412ca7$var$updateTreeTypes(state.tree, oldType, defaultType);
188
+ return {
189
+ ...state,
190
+ tree: newTree,
191
+ entityTypesMap: newEntityTypesMap,
192
+ selectedNodes: []
193
+ };
194
+ }
112
195
  /** Entity type selection */ case "toggle-entity-type-selector":
113
196
  return {
114
197
  ...state,
@@ -216,16 +299,18 @@ function $b79bf29960412ca7$export$8d9dbb7a64bf2a5e(tree) {
216
299
  // If we've already found an instance of this node, we don't need to record
217
300
  // it again
218
301
  if (nodeMap.has(node.id)) continue;
219
- const { indices: indices, id: id, name: name } = node;
302
+ const { indices: indices, id: id, name: name, type: type, children: children } = node;
220
303
  const nodeData = {
221
304
  id: id,
222
- type: node.type.id,
305
+ type: type.id,
306
+ color: type.color,
223
307
  name: name,
224
308
  txt_range: [
225
309
  indices
226
310
  ],
227
311
  reasoning: null,
228
- match: node.match
312
+ match: node.match,
313
+ children: children
229
314
  };
230
315
  nodeMap.set(node.id, node);
231
316
  nodes.push(nodeData);
@@ -245,7 +330,40 @@ function $b79bf29960412ca7$export$8d9dbb7a64bf2a5e(tree) {
245
330
  edges: edges
246
331
  };
247
332
  }
333
+ function $b79bf29960412ca7$var$findNodeById(tree, id) {
334
+ for (const node of tree){
335
+ if (node.id === id) return node;
336
+ if (node.children) {
337
+ const found = $b79bf29960412ca7$var$findNodeById(node.children, id);
338
+ if (found) return found;
339
+ }
340
+ }
341
+ return null;
342
+ }
343
+ function $b79bf29960412ca7$var$updateTreeTypes(tree, oldType, defaultType) {
344
+ return tree.map((node)=>$b79bf29960412ca7$var$updateNodeType(node, oldType, defaultType));
345
+ }
346
+ function $b79bf29960412ca7$var$updateNodeType(node, oldType, defaultType) {
347
+ const type = node.type.id === oldType.id ? defaultType : node.type;
348
+ return {
349
+ ...node,
350
+ type: type,
351
+ children: node.children ? $b79bf29960412ca7$var$updateTreeTypes(node.children, oldType, defaultType) : []
352
+ };
353
+ }
354
+ function $b79bf29960412ca7$var$flattenAndSort(nodes) {
355
+ const result = [];
356
+ function traverse(nodeList) {
357
+ for (const node of nodeList){
358
+ result.push(node);
359
+ if (Array.isArray(node.children) && node.children.length > 0) traverse(node.children);
360
+ }
361
+ }
362
+ traverse(nodes);
363
+ // sort by start
364
+ return result.sort((a, b)=>a.indices[0] - b.indices[0]);
365
+ }
248
366
 
249
367
 
250
368
  export {$b79bf29960412ca7$export$53ec42062883b2d4 as ViewMode, $b79bf29960412ca7$export$911bb4b9c8065d3d as useUpdatableTree, $b79bf29960412ca7$export$e5ce04c5b3f58533 as TreeDispatchContext, $b79bf29960412ca7$export$e1068f2d1c68f87e as useTreeDispatch, $b79bf29960412ca7$export$8d9dbb7a64bf2a5e as treeToGraph};
251
- //# sourceMappingURL=edit-state.c39d8466.js.map
369
+ //# sourceMappingURL=feedback-components.fa1d3641.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;AAKO,IAAA,AAAK,mEAAA;;;WAAA;;AAiDL,SAAS,0CACd,WAAuB,EACvB,WAAoC;IAEpC,4BAA4B;IAC5B,qDAAqD;IACrD,MAAM,OAAO,YAAY,MAAM,GAAG,IAAI,GAAG,KAAK;IAE9C,OAAO,CAAA,GAAA,iBAAS,EAAE,mCAAa;qBAC7B;QACA,MAAM;QACN,eAAe,EAAE;QACjB,gBAAgB;QAChB,oBAAoB;QACpB,gBAAgB;QAChB,uBAAuB;QACvB,QAAQ;IACV;AACF;AAEO,MAAM,4CAAsB,CAAA,GAAA,oBAAY,EAAuB;AAE/D,SAAS;IACd,MAAM,WAAW,CAAA,GAAA,iBAAS,EAAE;IAC5B,IAAI,YAAY,MACd,MAAM,IAAI,MAAM;IAElB,OAAO;AACT;AAEA,SAAS,kCAAY,KAAgB,EAAE,MAAkB;IACvD,OAAQ,OAAO,IAAI;QACjB,KAAK;YAAmB;gBACtB,mCAAmC;gBACnC,MAAM,QAAE,IAAI,eAAE,WAAW,SAAE,KAAK,EAAE,GAAG,OAAO,OAAO;gBACnD,MAAM,QAAQ,MAAM,cAAc,GAAG;gBACrC,MAAM,UAAsB;oBAC1B,IAAI;0BACJ;oBACA,aAAa,gBAAgB,KAAK,OAAO;2BACzC;gBACF;gBAEA,MAAM,oBAAoB,IAAI,IAAI,MAAM,cAAc;gBACtD,kBAAkB,GAAG,CAAC,OAAO;gBAE7B,OAAO;oBACL,GAAG,KAAK;oBACR,gBAAgB;oBAChB,oBAAoB;oBACpB,gBAAgB;gBAClB;YACF;QACA,KAAK;YAAsB;gBACzB,4CAA4C;gBAC5C,MAAM,MAAE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,GAAG,IAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE;AAC1D","sources":["packages/feedback-components/src/feedback/edit-state.ts"],"sourcesContent":["import { TreeData } from \"./types\";\nimport { createContext, Dispatch, useContext, useReducer } from \"react\";\nimport update, { Spec } from \"immutability-helper\";\nimport { EntityType } from \"../extractions/types\";\n\nexport enum ViewMode {\n Tree = \"tree\",\n Graph = \"graph\",\n}\n\ninterface TreeState {\n initialTree: TreeData[];\n tree: TreeData[];\n selectedNodes: number[];\n entityTypesMap: Map<number, EntityType>;\n selectedEntityType: EntityType;\n lastInternalId: number;\n isSelectingEntityType: boolean;\n viewMode: ViewMode;\n}\n\ntype TextRange = {\n start: number;\n end: number;\n text: string;\n};\n\ntype TreeAction =\n | {\n type: \"move-node\";\n payload: { dragIds: number[]; parentId: number; index: number };\n }\n | { type: \"delete-node\"; payload: { ids: number[] } }\n | { type: \"select-node\"; payload: { ids: number[] } }\n | { type: \"toggle-node-selected\"; payload: { ids: number[] } }\n | { type: \"set-view-mode\"; payload: ViewMode }\n | { type: \"create-node\"; payload: TextRange }\n | { type: \"select-entity-type\"; payload: EntityType }\n | { type: \"toggle-entity-type-selector\"; payload?: boolean | null }\n | { type: \"deselect\" }\n | { type: \"reset\" }\n | { type: \"delete-entity-type\"; payload: { id: number } }\n | {\n type: \"add-entity-type\";\n payload: { name: string; description: string; color: string };\n }\n | {\n type: \"update-entity-type\";\n payload: { id: number; name: string; description: string; color: string };\n }\n | { type: \"select-range\"; payload: { ids: number[] } };\n\nexport type TreeDispatch = Dispatch<TreeAction>;\n\nexport function useUpdatableTree(\n initialTree: TreeData[],\n entityTypes: Map<number, EntityType>,\n): [TreeState, TreeDispatch] {\n // Get the first entity type\n // issue: grabs second entity instead of selected one\n const type = entityTypes.values().next().value;\n\n return useReducer(treeReducer, {\n initialTree,\n tree: initialTree,\n selectedNodes: [],\n entityTypesMap: entityTypes,\n selectedEntityType: type,\n lastInternalId: 0,\n isSelectingEntityType: false,\n viewMode: ViewMode.Tree,\n });\n}\n\nexport const TreeDispatchContext = createContext<TreeDispatch | null>(null);\n\nexport function useTreeDispatch() {\n const dispatch = useContext(TreeDispatchContext);\n if (dispatch == null) {\n throw new Error(\"No dispatch context available\");\n }\n return dispatch;\n}\n\nfunction treeReducer(state: TreeState, action: TreeAction) {\n switch (action.type) {\n case \"add-entity-type\": {\n // Add a new entity type to the map\n const { name, description, color } = action.payload;\n const newId = state.lastInternalId - 1;\n const newType: EntityType = {\n id: newId,\n name,\n description: description === \"\" ? null : description,\n color,\n };\n\n const newEntityTypesMap = new Map(state.entityTypesMap);\n newEntityTypesMap.set(newId, newType);\n\n return {\n ...state,\n entityTypesMap: newEntityTypesMap,\n selectedEntityType: newType,\n lastInternalId: newId,\n };\n }\n case \"update-entity-type\": {\n // Update an existing entity type in the map\n const { id, name, description, color } = action.payload;\n const newEntityTypesMap = new Map(state.entityTypesMap);\n const oldType = newEntityTypesMap.get(id);\n\n if (!oldType) {\n console.warn(`Entity type with id ${id} not found`);\n return state;\n }\n\n const updatedType: EntityType = {\n ...oldType,\n name,\n description: description === \"\" ? null : description,\n color,\n };\n\n newEntityTypesMap.set(id, updatedType);\n\n // Update the tree to reflect the new type\n const newTree = updateTreeTypes(state.tree, oldType, updatedType);\n\n return {\n ...state,\n tree: newTree,\n entityTypesMap: newEntityTypesMap,\n selectedEntityType: updatedType,\n };\n }\n case \"select-range\":\n // Select a range of nodes by their IDs\n const payloadIds = action.payload.ids;\n const node1 = payloadIds[0];\n const node2 = payloadIds[1];\n\n // make list of nodes in order\n const allNodes = flattenAndSort(state.tree);\n\n // select all nodes between node1 and node2\n const startIndex = allNodes.findIndex((node) => node.id === node1);\n const endIndex = allNodes.findIndex((node) => node.id === node2);\n\n const selectedNodes = allNodes.slice(startIndex, endIndex + 1);\n\n console.log(\"Selecting range:\", selectedNodes);\n return {\n ...state,\n selectedNodes: selectedNodes.map((node) => node.id),\n };\n\n case \"move-node\":\n // For each node in the tree, if the node is in the dragIds, remove it from the tree and collect it\n const [newTree, removedNodes] = removeNodes(\n state.tree,\n action.payload.dragIds,\n );\n\n let keyPath: (number | \"children\")[] = [];\n if (action.payload.parentId) {\n keyPath = findNode(newTree, action.payload.parentId);\n keyPath.push(\"children\");\n }\n\n // Add removed nodes to the new tree at the correct location\n let updateSpec = buildNestedSpec(keyPath, {\n $splice: [[action.payload.index, 0, ...removedNodes]],\n });\n\n return { ...state, tree: update(newTree, updateSpec) };\n case \"delete-node\":\n // For each node in the tree, if the node is in the ids, remove it from the tree\n const [newTree2, _removedNodes] = removeNodes(\n state.tree,\n action.payload.ids,\n );\n // Get children of the removed nodes\n // If children are not present elsewhere in the tree, insert them\n\n const children = _removedNodes\n .flatMap((node) => node.children ?? [])\n .filter((child) => !nodeIsInTree(newTree2, child.id));\n\n // Reset the selection\n\n return {\n ...state,\n tree: [...newTree2, ...children],\n selectedNodes: state.selectedNodes.filter(\n (id) => !action.payload.ids.includes(id),\n ),\n };\n case \"select-node\":\n const { ids } = action.payload;\n\n const type =\n action.payload.ids.length > 0\n ? findNodeById(state.tree, ids[0])?.type\n : null;\n\n return { ...state, selectedNodes: ids, selectedEntityType: type };\n // otherwise fall through to toggle-node-selected for a single ID\n case \"toggle-node-selected\":\n const nodesToAdd = action.payload.ids.filter(\n (id) => !state.selectedNodes.includes(id),\n );\n const nodesToKeep = state.selectedNodes.filter(\n (id) => !action.payload.ids.includes(id),\n );\n\n const newType =\n action.payload.ids.length > 0\n ? findNodeById(state.tree, action.payload.ids[0])?.type\n : null;\n\n return {\n ...state,\n selectedNodes: [...nodesToKeep, ...nodesToAdd],\n selectedEntityType: newType,\n };\n\n case \"create-node\":\n const newId = state.lastInternalId - 1;\n const { text, start, end } = action.payload;\n const node: TreeData = {\n id: newId,\n name: text,\n children: [],\n indices: [start, end],\n type: state.selectedEntityType,\n };\n\n return {\n ...state,\n tree: [...state.tree, node],\n selectedNodes: [newId],\n lastInternalId: newId,\n };\n\n case \"delete-entity-type\": {\n // Remove the entity type from the map\n console.log(\"Deleting entity type:\", action.payload.id);\n const { id } = action.payload;\n const newEntityTypesMap = new Map(state.entityTypesMap);\n const oldType = newEntityTypesMap.get(id);\n newEntityTypesMap.delete(id);\n\n const defaultType = newEntityTypesMap.values().next().value;\n const newTree = updateTreeTypes(state.tree, oldType, defaultType);\n\n return {\n ...state,\n tree: newTree,\n entityTypesMap: newEntityTypesMap,\n selectedNodes: [],\n };\n }\n\n /** Entity type selection */\n case \"toggle-entity-type-selector\":\n return {\n ...state,\n isSelectingEntityType: action.payload ?? !state.isSelectingEntityType,\n };\n case \"select-entity-type\": {\n // For each selected node, update the type\n let newTree2 = state.tree;\n for (let id of state.selectedNodes) {\n const keyPath = findNode(state.tree, id);\n const nestedSpec = buildNestedSpec(keyPath, {\n type: { $set: action.payload },\n });\n newTree2 = update(newTree2, nestedSpec);\n }\n\n return {\n ...state,\n tree: newTree2,\n selectedEntityType: action.payload,\n };\n }\n case \"deselect\":\n return { ...state, selectedNodes: [] };\n case \"reset\":\n return {\n ...state,\n tree: state.initialTree,\n selectedNodes: [],\n };\n case \"set-view-mode\":\n return { ...state, viewMode: action.payload };\n }\n}\n\nfunction nodeIsInTree(tree: TreeData[], id: number): boolean {\n for (let node of tree) {\n if (node.id == id) {\n return true;\n } else if (node.children) {\n if (nodeIsInTree(node.children, id)) {\n return true;\n }\n }\n }\n return false;\n}\n\nfunction buildNestedSpec(\n keyPath: (number | \"children\")[],\n innerSpec: Spec<any>,\n): Spec<TreeData[]> {\n // Build a nested object from a key path\n\n let spec = innerSpec;\n for (let i = keyPath.length - 1; i >= 0; i--) {\n spec = { [keyPath[i]]: spec };\n }\n return spec as any;\n // Since we don't have a \"children\" key at the root, we make the top-level spec an array\n}\n\nfunction findNode(\n tree: TreeData[],\n id: number,\n): (number | \"children\")[] | null {\n // Find the index of the node with the given id in the tree, returning the key path\n for (let i = 0; i < tree.length; i++) {\n if (tree[i].id == id) {\n return [i];\n } else if (tree[i].children) {\n let path = findNode(tree[i].children, id);\n if (path != null) {\n return [i, \"children\", ...path];\n }\n }\n }\n return null;\n}\n\nfunction removeNodes(\n tree: TreeData[],\n ids: number[],\n): [TreeData[], TreeData[]] {\n /** Remove nodes with the given ids from the tree and return the new tree and the removed nodes */\n let newTree: TreeData[] = [];\n let removedNodes: TreeData[] = [];\n\n for (let node of tree) {\n if (ids.includes(node.id)) {\n removedNodes.push(node);\n } else {\n // Recurse into children\n if (node.children) {\n let [newChildren, removedChildren] = removeNodes(node.children, ids);\n node = { ...node, children: newChildren };\n removedNodes.push(...removedChildren);\n }\n newTree.push(node);\n }\n }\n\n return [newTree, removedNodes];\n}\n\nexport interface EntityOutput {\n id: number;\n type: number | null;\n txt_range: number[][];\n name: string;\n match: any | null;\n reasoning: string | null;\n color: string | null;\n children: any[] | null;\n}\n\nexport interface GraphData {\n nodes: EntityOutput[];\n edges: { source: number; dest: number }[];\n}\n\nexport function treeToGraph(tree: TreeData[]): GraphData {\n // Convert the tree to a graph\n let nodes: EntityOutput[] = [];\n let edges: { source: number; dest: number }[] = [];\n const nodeMap = new Map<number, TreeData>();\n\n for (let node of tree) {\n // If we've already found an instance of this node, we don't need to record\n // it again\n if (nodeMap.has(node.id)) {\n continue;\n }\n\n const { indices, id, name, type, children } = node;\n\n const nodeData: EntityOutput = {\n id,\n type: type.id,\n color: type.color,\n name,\n txt_range: [indices],\n reasoning: null,\n match: node.match,\n children,\n };\n\n nodeMap.set(node.id, node);\n nodes.push(nodeData);\n\n if (node.children) {\n for (let child of node.children) {\n edges.push({ source: node.id, dest: child.id });\n }\n\n // Now process the children\n const { nodes: childNodes, edges: childEdges } = treeToGraph(\n node.children,\n );\n nodes.push(...childNodes);\n edges.push(...childEdges);\n }\n }\n\n return { nodes, edges };\n}\n\nfunction findNodeById(tree, id) {\n for (const node of tree) {\n if (node.id === id) {\n return node;\n }\n if (node.children) {\n const found = findNodeById(node.children, id);\n if (found) return found;\n }\n }\n return null;\n}\n\nfunction updateTreeTypes(tree, oldType, defaultType) {\n return tree.map((node) => updateNodeType(node, oldType, defaultType));\n}\n\nfunction updateNodeType(node, oldType, defaultType) {\n const type = node.type.id === oldType.id ? defaultType : node.type;\n\n return {\n ...node,\n type,\n children: node.children\n ? updateTreeTypes(node.children, oldType, defaultType)\n : [],\n };\n}\n\nfunction flattenAndSort(nodes) {\n const result = [];\n\n function traverse(nodeList) {\n for (const node of nodeList) {\n result.push(node);\n if (Array.isArray(node.children) && node.children.length > 0) {\n traverse(node.children);\n }\n }\n }\n\n traverse(nodes);\n\n // sort by start\n return result.sort((a, b) => a.indices[0] - b.indices[0]);\n}\n"],"names":[],"version":3,"file":"feedback-components.fa1d3641.js.map"}