@macrostrat/feedback-components 1.1.0 → 1.1.2

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 (58) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/esm/{feedback-components.7cd9b6cc.js → feedback-components.3b3a5357.js} +53 -30
  3. package/dist/esm/feedback-components.3b3a5357.js.map +1 -0
  4. package/dist/esm/{feedback-components.921dcd46.js → feedback-components.46a7a347.js} +42 -14
  5. package/dist/esm/feedback-components.46a7a347.js.map +1 -0
  6. package/dist/esm/{feedback-components.87533431.js → feedback-components.5509fab3.js} +5 -5
  7. package/dist/esm/{feedback-components.87533431.js.map → feedback-components.5509fab3.js.map} +1 -1
  8. package/dist/esm/{feedback-components.6a6c8af5.js → feedback-components.586103e8.js} +108 -82
  9. package/dist/esm/feedback-components.586103e8.js.map +1 -0
  10. package/dist/esm/{feedback-components.4359bc80.js → feedback-components.95dbe7d7.js} +13 -1
  11. package/dist/esm/feedback-components.95dbe7d7.js.map +1 -0
  12. package/dist/esm/{feedback-components.bf5f7cf7.js → feedback-components.fa1d3641.js} +29 -2
  13. package/dist/esm/feedback-components.fa1d3641.js.map +1 -0
  14. package/dist/esm/{feedback-components.b7d9b015.css → feedback-components.fb60c70d.css} +38 -14
  15. package/dist/esm/feedback-components.fb60c70d.css.map +1 -0
  16. package/dist/esm/index.d.ts +3 -82
  17. package/dist/esm/index.d.ts.map +1 -1
  18. package/dist/esm/index.js +1 -1
  19. package/dist/node/feedback-components.561466ac.js +2 -0
  20. package/dist/node/feedback-components.561466ac.js.map +1 -0
  21. package/dist/node/feedback-components.571ee23c.js +2 -0
  22. package/dist/node/feedback-components.571ee23c.js.map +1 -0
  23. package/dist/node/{feedback-components.e8aa70b8.js → feedback-components.a39f7653.js} +2 -2
  24. package/dist/node/{feedback-components.e8aa70b8.js.map → feedback-components.a39f7653.js.map} +1 -1
  25. package/dist/node/feedback-components.b7946db4.js +2 -0
  26. package/dist/node/feedback-components.b7946db4.js.map +1 -0
  27. package/dist/node/feedback-components.c459cc27.js +2 -0
  28. package/dist/node/feedback-components.c459cc27.js.map +1 -0
  29. package/dist/node/feedback-components.c88cb37f.css +2 -0
  30. package/dist/node/feedback-components.c88cb37f.css.map +1 -0
  31. package/dist/node/feedback-components.ec54a1e7.js +2 -0
  32. package/dist/node/feedback-components.ec54a1e7.js.map +1 -0
  33. package/dist/node/index.js +1 -1
  34. package/dist/node/index.js.map +1 -1
  35. package/package.json +3 -3
  36. package/src/feedback/edit-state.ts +41 -3
  37. package/src/feedback/feedback.module.sass +30 -10
  38. package/src/feedback/graph.ts +27 -10
  39. package/src/feedback/index.ts +146 -112
  40. package/src/feedback/text-visualizer.ts +43 -17
  41. package/dist/esm/feedback-components.4359bc80.js.map +0 -1
  42. package/dist/esm/feedback-components.6a6c8af5.js.map +0 -1
  43. package/dist/esm/feedback-components.7cd9b6cc.js.map +0 -1
  44. package/dist/esm/feedback-components.921dcd46.js.map +0 -1
  45. package/dist/esm/feedback-components.b7d9b015.css.map +0 -1
  46. package/dist/esm/feedback-components.bf5f7cf7.js.map +0 -1
  47. package/dist/node/feedback-components.15e1316d.js +0 -2
  48. package/dist/node/feedback-components.15e1316d.js.map +0 -1
  49. package/dist/node/feedback-components.65d8488e.js +0 -2
  50. package/dist/node/feedback-components.65d8488e.js.map +0 -1
  51. package/dist/node/feedback-components.6681dbde.js +0 -2
  52. package/dist/node/feedback-components.6681dbde.js.map +0 -1
  53. package/dist/node/feedback-components.77b6fc89.css +0 -2
  54. package/dist/node/feedback-components.77b6fc89.css.map +0 -1
  55. package/dist/node/feedback-components.7caa447a.js +0 -2
  56. package/dist/node/feedback-components.7caa447a.js.map +0 -1
  57. package/dist/node/feedback-components.e2f3c4b7.js +0 -2
  58. package/dist/node/feedback-components.e2f3c4b7.js.map +0 -1
@@ -1,18 +1,17 @@
1
- import "./feedback-components.b7d9b015.css";
2
- import $bvJLP$feedbackcomponents4359bc80js from "./feedback-components.4359bc80.js";
3
- import $b6b9741bf83336eb$export$2e2bcd8739ae039 from "./feedback-components.87533431.js";
4
- import {FeedbackText as $156a3efbc315814c$export$6e107db9091b8219} from "./feedback-components.921dcd46.js";
5
- import {ModelInfo as $03d8811e9c9b360d$export$4eb2a0ce903ce967} from "./feedback-components.5df2a926.js";
6
- import {TreeDispatchContext as $b79bf29960412ca7$export$e5ce04c5b3f58533, treeToGraph as $b79bf29960412ca7$export$8d9dbb7a64bf2a5e, useUpdatableTree as $b79bf29960412ca7$export$911bb4b9c8065d3d} from "./feedback-components.bf5f7cf7.js";
1
+ import "./feedback-components.fb60c70d.css";
2
+ import $bvJLP$feedbackcomponents95dbe7d7js from "./feedback-components.95dbe7d7.js";
3
+ import $b6b9741bf83336eb$export$2e2bcd8739ae039 from "./feedback-components.5509fab3.js";
4
+ import {FeedbackText as $156a3efbc315814c$export$6e107db9091b8219} from "./feedback-components.46a7a347.js";
5
+ import {getTagStyle as $03d8811e9c9b360d$export$35baa338324d8550, ModelInfo as $03d8811e9c9b360d$export$4eb2a0ce903ce967} from "./feedback-components.5df2a926.js";
6
+ import {TreeDispatchContext as $b79bf29960412ca7$export$e5ce04c5b3f58533, treeToGraph as $b79bf29960412ca7$export$8d9dbb7a64bf2a5e, useUpdatableTree as $b79bf29960412ca7$export$911bb4b9c8065d3d} from "./feedback-components.fa1d3641.js";
7
7
  import {OmniboxSelector as $fda9ef5406c1cfb4$export$d8660660a589068c} from "./feedback-components.ad9f284e.js";
8
- import {GraphView as $ff8c3e7f2bc22925$export$6a7fe3ef90e8d566} from "./feedback-components.7cd9b6cc.js";
8
+ import {GraphView as $ff8c3e7f2bc22925$export$6a7fe3ef90e8d566} from "./feedback-components.3b3a5357.js";
9
9
  import $bvJLP$macrostrathyper from "@macrostrat/hyper";
10
10
  import {Tree as $bvJLP$Tree} from "react-arborist";
11
11
  import {useState as $bvJLP$useState, useRef as $bvJLP$useRef, useCallback as $bvJLP$useCallback, useEffect as $bvJLP$useEffect} from "react";
12
12
  import {SegmentedControl as $bvJLP$SegmentedControl, Card as $bvJLP$Card, ButtonGroup as $bvJLP$ButtonGroup, Divider as $bvJLP$Divider, Icon as $bvJLP$Icon, Overlay2 as $bvJLP$Overlay2, Popover as $bvJLP$Popover} from "@blueprintjs/core";
13
13
  import {ErrorBoundary as $bvJLP$ErrorBoundary, FlexRow as $bvJLP$FlexRow, CancelButton as $bvJLP$CancelButton, SaveButton as $bvJLP$SaveButton, useInDarkMode as $bvJLP$useInDarkMode} from "@macrostrat/ui-components";
14
14
  import $bvJLP$useelementdimensions from "use-element-dimensions";
15
- import {asChromaColor as $bvJLP$asChromaColor} from "@macrostrat/color-utils";
16
15
  import {ColorPicker as $bvJLP$ColorPicker} from "@macrostrat/data-sheet";
17
16
 
18
17
 
@@ -33,8 +32,7 @@ function $parcel$interopDefault(a) {
33
32
 
34
33
 
35
34
 
36
-
37
- const $71d20dff35996763$var$h = (0, $bvJLP$macrostrathyper).styled((0, ($parcel$interopDefault($bvJLP$feedbackcomponents4359bc80js))));
35
+ const $71d20dff35996763$var$h = (0, $bvJLP$macrostrathyper).styled((0, ($parcel$interopDefault($bvJLP$feedbackcomponents95dbe7d7js))));
38
36
  function $71d20dff35996763$var$setsAreTheSame(a, b) {
39
37
  if (a.size !== b.size) return false;
40
38
  for (const item of a){
@@ -42,60 +40,78 @@ function $71d20dff35996763$var$setsAreTheSame(a, b) {
42
40
  }
43
41
  return true;
44
42
  }
45
- function $71d20dff35996763$export$a90600c9da52b40c({ entities: entities = [], text: text, model: model, entityTypes: entityTypes, matchComponent: matchComponent, onSave: onSave, lineHeight: lineHeight, allowOverlap: allowOverlap }) {
43
+ function $71d20dff35996763$export$a90600c9da52b40c({ entities: entities = [], text: text, model: model, entityTypes: entityTypes, matchComponent: matchComponent, onSave: onSave, allowOverlap: allowOverlap }) {
46
44
  // Get the input arguments
47
45
  const [state, dispatch] = (0, $b79bf29960412ca7$export$911bb4b9c8065d3d)(entities.map($71d20dff35996763$var$processEntity), entityTypes);
48
46
  const { selectedNodes: selectedNodes, tree: tree, selectedEntityType: selectedEntityType, isSelectingEntityType: isSelectingEntityType, entityTypesMap: entityTypesMap } = state;
49
47
  const [{ width: width, height: height }, ref] = (0, $bvJLP$useelementdimensions)();
50
- return $71d20dff35996763$var$h((0, $b79bf29960412ca7$export$e5ce04c5b3f58533).Provider, {
51
- value: dispatch
52
- }, [
53
- $71d20dff35996763$var$h((0, $bvJLP$ErrorBoundary), {
54
- description: "An error occurred while rendering the feedback text component."
55
- }, $71d20dff35996763$var$h((0, $156a3efbc315814c$export$6e107db9091b8219), {
56
- text: text,
57
- dispatch: dispatch,
58
- // @ts-ignore
59
- nodes: tree,
60
- selectedNodes: selectedNodes,
61
- lineHeight: lineHeight,
62
- allowOverlap: allowOverlap
63
- })),
64
- $71d20dff35996763$var$h((0, $bvJLP$FlexRow), {
65
- alignItems: "baseline",
66
- justifyContent: "space-between"
48
+ return $71d20dff35996763$var$h("div.page-wrapper", [
49
+ $71d20dff35996763$var$h("div.feedback-container", $71d20dff35996763$var$h((0, $b79bf29960412ca7$export$e5ce04c5b3f58533).Provider, {
50
+ value: dispatch
67
51
  }, [
68
- $71d20dff35996763$var$h((0, $03d8811e9c9b360d$export$4eb2a0ce903ce967), {
69
- data: model
70
- }),
71
- $71d20dff35996763$var$h((0, $bvJLP$SegmentedControl), {
72
- options: [
73
- {
74
- label: "Tree",
75
- value: "tree"
76
- },
77
- {
78
- label: "Graph",
79
- value: "graph"
52
+ $71d20dff35996763$var$h((0, $bvJLP$ErrorBoundary), {
53
+ description: "An error occurred while rendering the feedback text component."
54
+ }, $71d20dff35996763$var$h((0, $156a3efbc315814c$export$6e107db9091b8219), {
55
+ text: text,
56
+ dispatch: dispatch,
57
+ // @ts-ignore
58
+ nodes: tree,
59
+ selectedNodes: selectedNodes,
60
+ allowOverlap: allowOverlap
61
+ })),
62
+ $71d20dff35996763$var$h((0, $bvJLP$FlexRow), {
63
+ alignItems: "baseline",
64
+ justifyContent: "space-between"
65
+ }, [
66
+ $71d20dff35996763$var$h((0, $03d8811e9c9b360d$export$4eb2a0ce903ce967), {
67
+ data: model
68
+ }),
69
+ $71d20dff35996763$var$h((0, $bvJLP$SegmentedControl), {
70
+ options: [
71
+ {
72
+ label: "Tree",
73
+ value: "tree"
74
+ },
75
+ {
76
+ label: "Graph",
77
+ value: "graph"
78
+ }
79
+ ],
80
+ value: state.viewMode,
81
+ small: true,
82
+ onValueChange (value) {
83
+ console.log("Setting view mode", value);
84
+ dispatch({
85
+ type: "set-view-mode",
86
+ payload: value
87
+ });
80
88
  }
81
- ],
82
- value: state.viewMode,
83
- small: true,
84
- onValueChange (value) {
85
- console.log("Setting view mode", value);
86
- dispatch({
87
- type: "set-view-mode",
88
- payload: value
89
- });
90
- }
91
- })
92
- ]),
93
- $71d20dff35996763$var$h("div.entity-panel", {
94
- ref: ref
95
- }, [
96
- $71d20dff35996763$var$h((0, $bvJLP$Card), {
97
- className: "control-panel"
89
+ })
90
+ ]),
91
+ $71d20dff35996763$var$h("div.entity-panel", {
92
+ ref: ref
98
93
  }, [
94
+ $71d20dff35996763$var$h.if(state.viewMode == "tree")($71d20dff35996763$var$ManagedSelectionTree, {
95
+ selectedNodes: selectedNodes,
96
+ dispatch: dispatch,
97
+ tree: tree,
98
+ width: width,
99
+ height: height,
100
+ matchComponent: matchComponent
101
+ }),
102
+ $71d20dff35996763$var$h.if(state.viewMode == "graph")((0, $ff8c3e7f2bc22925$export$6a7fe3ef90e8d566), {
103
+ tree: tree,
104
+ width: width,
105
+ height: height,
106
+ dispatch: dispatch,
107
+ selectedNodes: selectedNodes
108
+ })
109
+ ])
110
+ ])),
111
+ $71d20dff35996763$var$h((0, $bvJLP$Card), {
112
+ className: "control-panel"
113
+ }, [
114
+ $71d20dff35996763$var$h("div.control-content", [
99
115
  $71d20dff35996763$var$h((0, $bvJLP$ButtonGroup), {
100
116
  vertical: true,
101
117
  fill: true,
@@ -137,22 +153,7 @@ function $71d20dff35996763$export$a90600c9da52b40c({ entities: entities = [], te
137
153
  payload: isOpen
138
154
  })
139
155
  })
140
- ]),
141
- $71d20dff35996763$var$h.if(state.viewMode == "tree")($71d20dff35996763$var$ManagedSelectionTree, {
142
- selectedNodes: selectedNodes,
143
- dispatch: dispatch,
144
- tree: tree,
145
- width: width,
146
- height: height,
147
- matchComponent: matchComponent
148
- }),
149
- $71d20dff35996763$var$h.if(state.viewMode == "graph")((0, $ff8c3e7f2bc22925$export$6a7fe3ef90e8d566), {
150
- tree: tree,
151
- width: width,
152
- height: height,
153
- dispatch: dispatch,
154
- selectedNodes: selectedNodes
155
- })
156
+ ])
156
157
  ])
157
158
  ]);
158
159
  }
@@ -240,18 +241,39 @@ function $71d20dff35996763$var$ManagedSelectionTree(props) {
240
241
  function handleClick() {
241
242
  clickedRef.current = true;
242
243
  }
244
+ const ctrlPressedRef = (0, $bvJLP$useRef)(false);
245
+ (0, $bvJLP$useEffect)(()=>{
246
+ const down = (e)=>{
247
+ if (e.ctrlKey || e.metaKey) ctrlPressedRef.current = true;
248
+ };
249
+ const up = ()=>ctrlPressedRef.current = false;
250
+ window.addEventListener("keydown", down);
251
+ window.addEventListener("keyup", up);
252
+ return ()=>{
253
+ window.removeEventListener("keydown", down);
254
+ window.removeEventListener("keyup", up);
255
+ };
256
+ }, []);
243
257
  const handleSelect = (0, $bvJLP$useCallback)((nodes)=>{
244
258
  if (!clickedRef.current) return;
245
259
  clickedRef.current = false;
246
- console.log("Clicked nodes:", nodes);
260
+ const isMultiSelect = ctrlPressedRef.current;
247
261
  let ids = nodes.map((d)=>parseInt(d.id));
248
- if (ids.length === 1 && ids[0] === selectedNodes[0]) ids = [];
249
- dispatch({
250
- type: "select-node",
262
+ if (isMultiSelect) dispatch({
263
+ type: "toggle-node-selected",
251
264
  payload: {
252
265
  ids: ids
253
266
  }
254
267
  });
268
+ else {
269
+ if (ids.length === 1 && ids[0] === selectedNodes[0]) ids = [];
270
+ dispatch({
271
+ type: "select-node",
272
+ payload: {
273
+ ids: ids
274
+ }
275
+ });
276
+ }
255
277
  }, [
256
278
  selectedNodes,
257
279
  dispatch
@@ -442,8 +464,12 @@ function $71d20dff35996763$var$TypeOverlay({ setOverlayOpen: setOverlayOpen, ove
442
464
  }
443
465
  function $71d20dff35996763$var$TypeTag({ type: type, luminance: luminance, selectedType: selectedType, setSelectedType: setSelectedType, dispatch: dispatch, tree: tree, selectedNodes: selectedNodes, selected: selected, isSelectedNodes: isSelectedNodes }) {
444
466
  const { color: color, name: name, id: id, description: description } = type;
445
- const chromaColor = (0, $bvJLP$asChromaColor)(color ?? "#000000");
446
467
  const darkMode = (0, $bvJLP$useInDarkMode)();
468
+ const isSelected = id === selected?.id && selectedNodes.length > 0;
469
+ const style = (0, $03d8811e9c9b360d$export$35baa338324d8550)(color, {
470
+ active: isSelected,
471
+ highlighted: selectedNodes.length === 0
472
+ });
447
473
  const payload = {
448
474
  id: id,
449
475
  name: name,
@@ -515,9 +541,9 @@ function $71d20dff35996763$var$TypeTag({ type: type, luminance: luminance, selec
515
541
  onClick: handleTagClick,
516
542
  style: {
517
543
  cursor: ids.length > 0 || isSelectedNodes && !selectedType ? "pointer" : "",
518
- color: darkMode ? "white" : "black",
519
- backgroundColor: chromaColor?.luminance(1 - luminance).hex(),
520
- border: id === selected?.id && selectedNodes.length > 0 ? `1px solid var(--text-emphasized-color)` : `1px solid var(--background-color)`
544
+ color: "black",
545
+ backgroundColor: style.backgroundColor,
546
+ border: isSelected ? `1px solid var(--text-emphasized-color)` : `1px solid var(--background-color)`
521
547
  }
522
548
  }, $71d20dff35996763$var$h("div.type-container", [
523
549
  $71d20dff35996763$var$h("div.type-name", name),
@@ -549,4 +575,4 @@ function $71d20dff35996763$var$TypeTag({ type: type, luminance: luminance, selec
549
575
 
550
576
 
551
577
  export {$71d20dff35996763$export$a90600c9da52b40c as FeedbackComponent, $b79bf29960412ca7$export$8d9dbb7a64bf2a5e as treeToGraph};
552
- //# sourceMappingURL=feedback-components.6a6c8af5.js.map
578
+ //#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AAM,GAAG,GAAG;gBAClB,gBAAgB;gBAChB,MAAM,SAAS,yCAAmB,MAAM,aAAa,EAAE;gBAEvD,SAAS;oBAAE,MAAM;oBAAwB,SAAS;wBAAE,KAAK;oBAAO;gBAAE;gBAClE,SAAS;oBAAE,MAAM;oBAAwB,SAAS;6BAAE;oBAAI;gBAAE;YAC5D;QAAA,OAEA,QAAQ,IAAI,CAAC,6CAA6C;6BACxD;0BACA;2BACA;iBACA;gBACA;sBACA;QACF;IAEJ;IAEA,OAAO,wBACL,CAAA,GAAA,cAAM,GACN;QACE,WAAW;QACX,SAAS,wBAAE,mBAAmB,eAAe;QAC7C,iBAAiB;IACnB,GACA,wBACE,gBACA;QACE,SAAS;QACT,OAAO;YACL,QACE,IAAI,MAAM,GAAG,KAAM,mBAAmB,CAAC,eACnC,YACA;YACN,OAAO;YACP,iBAAiB,MAAM,eAAe;YACtC,QAAQ,aACJ,CAAC,sCAAsC,CAAC,GACxC,CAAC,iCAAiC,CAAC;QACzC;IACF,GACA,wBAAE,sBAAsB;QACtB,wBAAE,iBAAiB;QACnB,wBAAE,aAAa;YACb,wBAAE,gCAAU;0BACV;sBACA;YACF;YACA,wBAAE,CAAA,GAAA,WAAG,GAAG;gBACN,MAAM;gBACN,WAAW;gBACX,OAAO;oBAAE,OAAO;oBAAO,QAAQ;gBAAU;gBACzC,SAAS,CAAC;oBACR,EAAE,eAAe;oBACjB,SAAS;wBACP,MAAM;wBACN,SAAS;gCAAE;wBAAG;oBAChB;gBACF;YACF;SACD;KACF;AAGP","sources":["packages/feedback-components/src/feedback/index.ts"],"sourcesContent":["import styles from \"./feedback.module.sass\";\nimport hyper from \"@macrostrat/hyper\";\n\nimport { Tree, TreeApi } from \"react-arborist\";\nimport Node from \"./node\";\nimport { FeedbackText } from \"./text-visualizer\";\nimport type { InternalEntity, TreeData } from \"./types\";\nimport type { Entity } from \"../extractions\";\nimport { getTagStyle, ModelInfo } from \"../extractions\";\nimport {\n TreeDispatchContext,\n treeToGraph,\n useUpdatableTree,\n ViewMode,\n} from \"./edit-state\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport {\n ButtonGroup,\n Card,\n SegmentedControl,\n Icon,\n Popover,\n Divider,\n Overlay2,\n} from \"@blueprintjs/core\";\nimport { OmniboxSelector } from \"./type-selector\";\nimport {\n CancelButton,\n DataField,\n ErrorBoundary,\n FlexBox,\n FlexRow,\n SaveButton,\n} from \"@macrostrat/ui-components\";\nimport useElementDimensions from \"use-element-dimensions\";\nimport { GraphView } from \"./graph\";\nimport { useInDarkMode } from \"@macrostrat/ui-components\";\nimport { asChromaColor } from \"@macrostrat/color-utils\";\nimport { ColorPicker } from \"@macrostrat/data-sheet\";\n\nexport type { GraphData } from \"./edit-state\";\nexport { treeToGraph } from \"./edit-state\";\nexport type { TreeData } from \"./types\";\n\nconst h = hyper.styled(styles);\n\nfunction setsAreTheSame<T>(a: Set<T>, b: Set<T>) {\n if (a.size !== b.size) return false;\n for (const item of a) {\n if (!b.has(item)) return false;\n }\n return true;\n}\n\nexport function FeedbackComponent({\n entities = [],\n text,\n model,\n entityTypes,\n matchComponent,\n onSave,\n allowOverlap,\n}) {\n // Get the input arguments\n const [state, dispatch] = useUpdatableTree(\n entities.map(processEntity) as any,\n entityTypes,\n );\n\n const {\n selectedNodes,\n tree,\n selectedEntityType,\n isSelectingEntityType,\n entityTypesMap,\n } = state;\n\n const [{ width, height }, ref] = useElementDimensions();\n\n return h(\"div.page-wrapper\", [\n h(\n \"div.feedback-container\",\n h(TreeDispatchContext.Provider, { value: dispatch }, [\n h(\n ErrorBoundary,\n {\n description:\n \"An error occurred while rendering the feedback text component.\",\n },\n h(FeedbackText, {\n text,\n dispatch,\n // @ts-ignore\n nodes: tree,\n selectedNodes,\n allowOverlap,\n }),\n ),\n h(\n FlexRow,\n { alignItems: \"baseline\", justifyContent: \"space-between\" },\n [\n h(ModelInfo, { data: model }),\n h(SegmentedControl, {\n options: [\n { label: \"Tree\", value: \"tree\" },\n { label: \"Graph\", value: \"graph\" },\n ],\n value: state.viewMode,\n small: true,\n onValueChange(value: ViewMode) {\n console.log(\"Setting view mode\", value);\n dispatch({ type: \"set-view-mode\", payload: value });\n },\n }),\n ],\n ),\n h(\n \"div.entity-panel\",\n {\n ref,\n },\n [\n h.if(state.viewMode == \"tree\")(ManagedSelectionTree, {\n selectedNodes,\n dispatch,\n tree,\n width,\n height,\n matchComponent,\n }),\n h.if(state.viewMode == \"graph\")(GraphView, {\n tree,\n width,\n height,\n dispatch,\n selectedNodes,\n }),\n ],\n ),\n ]),\n ),\n h(Card, { className: \"control-panel\" }, [\n h(\"div.control-content\", [\n h(\n ButtonGroup,\n {\n vertical: true,\n fill: true,\n minimal: true,\n alignText: \"left\",\n },\n [\n h(\n CancelButton,\n {\n icon: \"trash\",\n disabled: state.initialTree == state.tree,\n onClick() {\n dispatch({ type: \"reset\" });\n },\n },\n \"Reset\",\n ),\n h(\n SaveButton,\n {\n onClick() {\n onSave(state.tree);\n },\n disabled: state.initialTree == state.tree,\n },\n \"Save\",\n ),\n ],\n ),\n h(Divider),\n h(EntityTypeSelector, {\n entityTypes: entityTypesMap,\n selected: selectedEntityType,\n onChange(payload) {\n dispatch({ type: \"select-entity-type\", payload });\n },\n dispatch,\n tree,\n selectedNodes,\n isOpen: isSelectingEntityType,\n setOpen: (isOpen: boolean) =>\n dispatch({\n type: \"toggle-entity-type-selector\",\n payload: isOpen,\n }),\n }),\n ]),\n ]),\n ]);\n}\n\nfunction processEntity(entity: Entity): InternalEntity {\n // @ts-ignore\n return {\n ...entity,\n // @ts-ignore\n term_type: entity.type.name,\n txt_range: [entity.indices],\n children: entity.children?.map(processEntity) ?? [],\n };\n}\n\nfunction EntityTypeSelector({\n entityTypes,\n selected,\n isOpen,\n setOpen,\n onChange,\n tree,\n dispatch,\n selectedNodes = [],\n}) {\n // Show all entity types when selected is null\n const _selected = selected != null ? selected : undefined;\n const [inputValue, setInputValue] = useState(\"\");\n const types = Array.from(entityTypes.values());\n\n const items =\n inputValue !== \"\"\n ? types.filter((d) =>\n d.name.toLowerCase().includes(inputValue.toLowerCase()),\n )\n : types;\n\n return h(\"div.entity-type-selector\", [\n h(TypeList, {\n types: entityTypes,\n selected: _selected,\n dispatch,\n selectedNodes,\n tree,\n }),\n h(OmniboxSelector, {\n isOpen,\n items,\n selectedItem: _selected,\n onSelectItem(item) {\n setOpen(false);\n onChange(item);\n },\n onQueryChange(query) {\n setInputValue(query);\n },\n onClose() {\n setOpen(false);\n },\n }),\n ]);\n}\n\nfunction countNodes(tree) {\n if (!tree) return 0;\n let count = 0;\n\n function recurse(nodes) {\n for (const node of nodes) {\n count++;\n if (node.children && Array.isArray(node.children)) {\n recurse(node.children);\n }\n }\n }\n\n recurse(tree);\n return count;\n}\n\nfunction ManagedSelectionTree(props) {\n const { selectedNodes, dispatch, tree, height, width, matchComponent } =\n props;\n\n const ref = useRef<TreeApi<TreeData>>();\n // Use a ref to track clicks (won't cause rerender)\n const clickedRef = useRef(false);\n\n const _Node = useCallback(\n (props) => h(Node, { ...props, matchComponent }),\n [matchComponent],\n );\n\n // Update Tree selection when selectedNodes change\n useEffect(() => {\n if (ref.current == null) return;\n\n const selection = new Set(selectedNodes.map((d) => d.toString()));\n const currentSelection = ref.current.selectedIds;\n if (setsAreTheSame(selection, currentSelection)) return;\n\n ref.current.setSelection({\n ids: selectedNodes.map((d) => d.toString()),\n anchor: null,\n mostRecent: null,\n });\n }, [selectedNodes]);\n\n // Mark clicked when user clicks inside the tree container\n function handleClick() {\n clickedRef.current = true;\n }\n\n const ctrlPressedRef = useRef(false);\n\n useEffect(() => {\n const down = (e) => {\n if (e.ctrlKey || e.metaKey) ctrlPressedRef.current = true;\n };\n const up = () => (ctrlPressedRef.current = false);\n\n window.addEventListener(\"keydown\", down);\n window.addEventListener(\"keyup\", up);\n return () => {\n window.removeEventListener(\"keydown\", down);\n window.removeEventListener(\"keyup\", up);\n };\n }, []);\n\n const handleSelect = useCallback(\n (nodes) => {\n if (!clickedRef.current) return;\n clickedRef.current = false;\n const isMultiSelect = ctrlPressedRef.current;\n\n let ids = nodes.map((d) => parseInt(d.id));\n\n if (isMultiSelect) {\n dispatch({ type: \"toggle-node-selected\", payload: { ids } });\n } else {\n if (ids.length === 1 && ids[0] === selectedNodes[0]) {\n ids = [];\n }\n\n dispatch({ type: \"select-node\", payload: { ids } });\n }\n },\n [selectedNodes, dispatch],\n );\n\n return h(\n \"div.selection-tree-wrapper\",\n { onPointerDown: handleClick },\n h(Tree, {\n className: \"selection-tree\",\n height,\n width,\n ref,\n data: tree,\n onMove({ dragIds, parentId, index }) {\n dispatch({\n type: \"move-node\",\n payload: {\n dragIds: dragIds.map((d) => parseInt(d)),\n parentId: parentId ? parseInt(parentId) : null,\n index,\n },\n });\n },\n onDelete({ ids }) {\n dispatch({\n type: \"delete-node\",\n payload: { ids: ids.map((d) => parseInt(d)) },\n });\n },\n onSelect: handleSelect,\n children: _Node,\n idAccessor(d) {\n return d.id.toString();\n },\n }),\n );\n}\n\nfunction TypeList({ types, selected, dispatch, selectedNodes, tree }) {\n const [selectedType, setSelectedType] = useState(null);\n const isSelectedNodes = selectedNodes.length > 0;\n const darkMode = useInDarkMode();\n const luminance = darkMode ? 0.9 : 0.4;\n\n return h(\"div.type-list-container\", [\n h(\n \"div.type-list-header\",\n isSelectedNodes && !selectedType\n ? \"Change selected nodes to:\"\n : \"Entity Types\",\n ),\n h(\n \"div.type-list\",\n Array.from(types.values()).map((type) =>\n h(TypeTag, {\n type,\n luminance,\n selectedType,\n setSelectedType,\n dispatch,\n tree,\n selectedNodes,\n selected,\n isSelectedNodes,\n }),\n ),\n ),\n h(AddType, { dispatch }),\n ]);\n}\n\nfunction collectMatchingIds(tree, id) {\n const ids = [];\n\n function traverse(node) {\n if (node.type.id === id) {\n ids.push(node.id);\n }\n if (Array.isArray(node.children)) {\n node.children.forEach(traverse);\n }\n }\n\n tree.forEach(traverse);\n return ids;\n}\n\nfunction AddType({ dispatch }) {\n const [overlayOpen, setOverlayOpen] = useState(false);\n\n const saveHandler = (payload) => {\n dispatch({\n type: \"add-entity-type\",\n payload,\n });\n setOverlayOpen(false);\n };\n\n return h(\"div.add-type-container\", [\n h(\"div.add-type\", { onClick: () => setOverlayOpen(true) }, [\n h(\"p.add-type-text\", \"Add new type\"),\n h(Icon, { icon: \"plus\" }),\n ]),\n h(TypeOverlay, {\n setOverlayOpen,\n overlayOpen,\n title: \"Add New Type\",\n saveHandler,\n }),\n ]);\n}\n\nfunction EditType({ dispatch, type }) {\n const [editorOpen, setEditorOpen] = useState(false);\n\n const saveHandler = (payload) => {\n dispatch({\n type: \"update-entity-type\",\n payload,\n });\n setEditorOpen(false);\n };\n\n return h(\"div.edit-type\", [\n h(Icon, {\n icon: \"edit\",\n className: \"edit-icon\",\n onClick: (e) => {\n e.stopPropagation();\n setEditorOpen(true);\n },\n }),\n h(TypeOverlay, {\n setOverlayOpen: setEditorOpen,\n overlayOpen: editorOpen,\n originalType: type,\n title: \"Edit Type\",\n saveHandler,\n }),\n ]);\n}\n\nfunction TypeOverlay({\n setOverlayOpen,\n overlayOpen,\n originalType,\n title,\n saveHandler,\n}) {\n const { name, description, color, id } = originalType || {};\n\n const [nameInput, setNameInput] = useState(name || \"\");\n const [descriptionInput, setDescriptionInput] = useState(description || \"\");\n const [colorInput, setColorInput] = useState(color || \"#fff\");\n\n return h(\n Overlay2,\n {\n isOpen: overlayOpen,\n },\n h(\n \"div.overlay-container\",\n h(\"div.add-type-overlay\", [\n h(\"h2.title\", [\n title,\n h(Icon, {\n icon: \"cross\",\n className: \"close-icon\",\n onClick: () => {\n setOverlayOpen(false);\n },\n style: { cursor: \"pointer\", color: \"red\" },\n }),\n ]),\n h(\"div.form-group\", [\n h(\"div.text-inputs\", [\n h(\"div.form-field.name\", [\n h(\"p.label\", \"Name\"),\n h(\"input\", {\n type: \"text\",\n placeholder: \"Enter type name\",\n onChange: (e) => setNameInput(e.target.value),\n value: nameInput,\n }),\n ]),\n h(\"div.form-field.form-description\", [\n h(\"p.label\", \"Description\"),\n h(\"input\", {\n type: \"text\",\n placeholder: \"Enter type description\",\n onChange: (e) => setDescriptionInput(e.target.value),\n value: descriptionInput,\n }),\n ]),\n ]),\n h(\"div.form-field.color\", [\n h(\"p.label\", \"Color\"),\n h(ColorPicker, {\n value: colorInput,\n onChange: (color) => setColorInput(color),\n style: { width: \"100%\" },\n }),\n ]),\n ]),\n h(\n SaveButton,\n {\n className: \"save-btn\",\n small: true,\n onClick: () =>\n saveHandler({\n name: nameInput,\n description: descriptionInput,\n color: colorInput,\n id,\n }),\n },\n \"Save changes\",\n ),\n ]),\n ),\n );\n}\n\nfunction TypeTag({\n type,\n luminance,\n selectedType,\n setSelectedType,\n dispatch,\n tree,\n selectedNodes,\n selected,\n isSelectedNodes,\n}) {\n const { color, name, id, description } = type;\n const darkMode = useInDarkMode();\n const isSelected = id === selected?.id && selectedNodes.length > 0;\n\n const style = getTagStyle(color, {\n active: isSelected,\n highlighted: selectedNodes.length === 0,\n });\n\n const payload = {\n id,\n name,\n color,\n description,\n };\n\n const ids = collectMatchingIds(tree, id);\n\n const handleTagClick = () => {\n if (!isSelectedNodes && selectedType === null) {\n if (ids.length > 0) {\n setSelectedType(type);\n dispatch({ type: \"toggle-node-selected\", payload: { ids } });\n }\n } else if (isSelectedNodes && selectedType === null) {\n if (id === selected?.id && selectedNodes.length > 0) {\n dispatch({\n type: \"toggle-node-selected\",\n payload: { ids: selectedNodes },\n });\n } else {\n dispatch({ type: \"select-entity-type\", payload });\n }\n } else if (isSelectedNodes && selectedType.id === id) {\n setSelectedType(null);\n dispatch({ type: \"toggle-node-selected\", payload: { ids } });\n } else if (isSelectedNodes && selectedType.id !== id) {\n if (ids.length > 0) {\n setSelectedType(type);\n const oldIds = collectMatchingIds(tree, selectedType.id);\n\n dispatch({ type: \"toggle-node-selected\", payload: { ids: oldIds } });\n dispatch({ type: \"toggle-node-selected\", payload: { ids } });\n }\n } else {\n console.warn(\"Unexpected state in TypeTag click handler\", {\n isSelectedNodes,\n selectedType,\n selectedNodes,\n ids,\n id,\n selected,\n });\n }\n };\n\n return h(\n Popover,\n {\n autoFocus: false,\n content: h(\"div.description\", description || \"No description available\"),\n interactionKind: \"hover\",\n },\n h(\n \"div.type-tag\",\n {\n onClick: handleTagClick,\n style: {\n cursor:\n ids.length > 0 || (isSelectedNodes && !selectedType)\n ? \"pointer\"\n : \"\",\n color: \"black\",\n backgroundColor: style.backgroundColor,\n border: isSelected\n ? `1px solid var(--text-emphasized-color)`\n : `1px solid var(--background-color)`,\n },\n },\n h(\"div.type-container\", [\n h(\"div.type-name\", name),\n h(\"div.icons\", [\n h(EditType, {\n dispatch,\n type,\n }),\n h(Icon, {\n icon: \"cross\",\n className: \"delete-type-icon\",\n style: { color: \"red\", cursor: \"pointer\" },\n onClick: (e) => {\n e.stopPropagation();\n dispatch({\n type: \"delete-entity-type\",\n payload: { id },\n });\n },\n }),\n ]),\n ]),\n ),\n );\n}\n"],"names":[],"version":3,"file":"feedback-components.586103e8.js.map"}
@@ -6,17 +6,21 @@ var $49c87ee97f392268$exports = {};
6
6
 
7
7
  $parcel$export($49c87ee97f392268$exports, "add-type", () => $49c87ee97f392268$export$cb889aaddfa2926c, (v) => $49c87ee97f392268$export$cb889aaddfa2926c = v);
8
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);
9
10
  $parcel$export($49c87ee97f392268$exports, "control-panel", () => $49c87ee97f392268$export$a0a23f31d5562853, (v) => $49c87ee97f392268$export$a0a23f31d5562853 = v);
10
11
  $parcel$export($49c87ee97f392268$exports, "description", () => $49c87ee97f392268$export$6d59db4903f20f7d, (v) => $49c87ee97f392268$export$6d59db4903f20f7d = v);
11
12
  $parcel$export($49c87ee97f392268$exports, "entity-panel", () => $49c87ee97f392268$export$38f2cd12e45697e, (v) => $49c87ee97f392268$export$38f2cd12e45697e = v);
12
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);
13
15
  $parcel$export($49c87ee97f392268$exports, "feedback-text", () => $49c87ee97f392268$export$890489be1870bed5, (v) => $49c87ee97f392268$export$890489be1870bed5 = v);
14
16
  $parcel$export($49c87ee97f392268$exports, "feedback-text-wrapper", () => $49c87ee97f392268$export$6bd0fd0a746c88f, (v) => $49c87ee97f392268$export$6bd0fd0a746c88f = v);
15
17
  $parcel$export($49c87ee97f392268$exports, "form-group", () => $49c87ee97f392268$export$55a1f87a143fb302, (v) => $49c87ee97f392268$export$55a1f87a143fb302 = v);
16
18
  $parcel$export($49c87ee97f392268$exports, "highlight", () => $49c87ee97f392268$export$e4043f67d36cbb26, (v) => $49c87ee97f392268$export$e4043f67d36cbb26 = v);
17
19
  $parcel$export($49c87ee97f392268$exports, "icons", () => $49c87ee97f392268$export$df03f54e09e486fa, (v) => $49c87ee97f392268$export$df03f54e09e486fa = v);
18
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);
19
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);
20
24
  $parcel$export($49c87ee97f392268$exports, "selected", () => $49c87ee97f392268$export$d90250155de6d7e7, (v) => $49c87ee97f392268$export$d90250155de6d7e7 = v);
21
25
  $parcel$export($49c87ee97f392268$exports, "selection-tree", () => $49c87ee97f392268$export$3ae1b51693c80a9c, (v) => $49c87ee97f392268$export$3ae1b51693c80a9c = v);
22
26
  $parcel$export($49c87ee97f392268$exports, "text-inputs", () => $49c87ee97f392268$export$bc7581b048bdc9d, (v) => $49c87ee97f392268$export$bc7581b048bdc9d = v);
@@ -26,17 +30,21 @@ $parcel$export($49c87ee97f392268$exports, "type-list", () => $49c87ee97f392268$e
26
30
  $parcel$export($49c87ee97f392268$exports, "type-tag", () => $49c87ee97f392268$export$5e5acbc770fb0e4, (v) => $49c87ee97f392268$export$5e5acbc770fb0e4 = v);
27
31
  var $49c87ee97f392268$export$cb889aaddfa2926c;
28
32
  var $49c87ee97f392268$export$5f8f750fd71deeed;
33
+ var $49c87ee97f392268$export$42e8b5293e69631e;
29
34
  var $49c87ee97f392268$export$a0a23f31d5562853;
30
35
  var $49c87ee97f392268$export$6d59db4903f20f7d;
31
36
  var $49c87ee97f392268$export$38f2cd12e45697e;
32
37
  var $49c87ee97f392268$export$579bd45c78bf5510;
38
+ var $49c87ee97f392268$export$23889d205b405f6e;
33
39
  var $49c87ee97f392268$export$890489be1870bed5;
34
40
  var $49c87ee97f392268$export$6bd0fd0a746c88f;
35
41
  var $49c87ee97f392268$export$55a1f87a143fb302;
36
42
  var $49c87ee97f392268$export$e4043f67d36cbb26;
37
43
  var $49c87ee97f392268$export$df03f54e09e486fa;
38
44
  var $49c87ee97f392268$export$35059013cd4a06db;
45
+ var $49c87ee97f392268$export$75d14899fb692bb6;
39
46
  var $49c87ee97f392268$export$6a1093e41947f68e;
47
+ var $49c87ee97f392268$export$7c414e944018fb15;
40
48
  var $49c87ee97f392268$export$d90250155de6d7e7;
41
49
  var $49c87ee97f392268$export$3ae1b51693c80a9c;
42
50
  var $49c87ee97f392268$export$bc7581b048bdc9d;
@@ -46,17 +54,21 @@ var $49c87ee97f392268$export$915fe2ca68846e4c;
46
54
  var $49c87ee97f392268$export$5e5acbc770fb0e4;
47
55
  $49c87ee97f392268$export$cb889aaddfa2926c = `QoX8-W_add-type`;
48
56
  $49c87ee97f392268$export$5f8f750fd71deeed = `QoX8-W_add-type-overlay`;
57
+ $49c87ee97f392268$export$42e8b5293e69631e = `QoX8-W_control-content`;
49
58
  $49c87ee97f392268$export$a0a23f31d5562853 = `QoX8-W_control-panel`;
50
59
  $49c87ee97f392268$export$6d59db4903f20f7d = `QoX8-W_description`;
51
60
  $49c87ee97f392268$export$38f2cd12e45697e = `QoX8-W_entity-panel`;
52
61
  $49c87ee97f392268$export$579bd45c78bf5510 = `QoX8-W_feedback-component`;
62
+ $49c87ee97f392268$export$23889d205b405f6e = `QoX8-W_feedback-container`;
53
63
  $49c87ee97f392268$export$890489be1870bed5 = `QoX8-W_feedback-text`;
54
64
  $49c87ee97f392268$export$6bd0fd0a746c88f = `QoX8-W_feedback-text-wrapper`;
55
65
  $49c87ee97f392268$export$55a1f87a143fb302 = `QoX8-W_form-group`;
56
66
  $49c87ee97f392268$export$e4043f67d36cbb26 = `QoX8-W_highlight`;
57
67
  $49c87ee97f392268$export$df03f54e09e486fa = `QoX8-W_icons`;
58
68
  $49c87ee97f392268$export$35059013cd4a06db = `QoX8-W_node`;
69
+ $49c87ee97f392268$export$75d14899fb692bb6 = `QoX8-W_node-label`;
59
70
  $49c87ee97f392268$export$6a1093e41947f68e = `QoX8-W_overlay-container`;
71
+ $49c87ee97f392268$export$7c414e944018fb15 = `QoX8-W_page-wrapper`;
60
72
  $49c87ee97f392268$export$d90250155de6d7e7 = `QoX8-W_selected`;
61
73
  $49c87ee97f392268$export$3ae1b51693c80a9c = `QoX8-W_selection-tree`;
62
74
  $49c87ee97f392268$export$bc7581b048bdc9d = `QoX8-W_text-inputs`;
@@ -67,4 +79,4 @@ $49c87ee97f392268$export$5e5acbc770fb0e4 = `QoX8-W_type-tag`;
67
79
 
68
80
 
69
81
  export {$49c87ee97f392268$exports as default};
70
- //# sourceMappingURL=feedback-components.4359bc80.js.map
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"}
@@ -77,6 +77,22 @@ function $b79bf29960412ca7$var$treeReducer(state, action) {
77
77
  selectedEntityType: updatedType
78
78
  };
79
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
+ };
80
96
  case "move-node":
81
97
  // For each node in the tree, if the node is in the dragIds, remove it from the tree and collect it
82
98
  const [newTree, removedNodes] = $b79bf29960412ca7$var$removeNodes(state.tree, action.payload.dragIds);
@@ -117,7 +133,6 @@ function $b79bf29960412ca7$var$treeReducer(state, action) {
117
133
  case "select-node":
118
134
  const { ids: ids } = action.payload;
119
135
  const type = action.payload.ids.length > 0 ? $b79bf29960412ca7$var$findNodeById(state.tree, ids[0])?.type : null;
120
- console.log("Selecting nodes:", ids, "Type:", type);
121
136
  return {
122
137
  ...state,
123
138
  selectedNodes: ids,
@@ -336,7 +351,19 @@ function $b79bf29960412ca7$var$updateNodeType(node, oldType, defaultType) {
336
351
  children: node.children ? $b79bf29960412ca7$var$updateTreeTypes(node.children, oldType, defaultType) : []
337
352
  };
338
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
+ }
339
366
 
340
367
 
341
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};
342
- //# sourceMappingURL=feedback-components.bf5f7cf7.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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AQ,EAAE,SAAS,eACxC,EAAE;IACR;AACF;AAEA,SAAS,qCAAe,KAAK;IAC3B,MAAM,SAAS,EAAE;IAEjB,SAAS,SAAS,QAAQ;QACxB,KAAK,MAAM,QAAQ,SAAU;YAC3B,OAAO,IAAI,CAAC;YACZ,IAAI,MAAM,OAAO,CAAC,KAAK,QAAQ,KAAK,KAAK,QAAQ,CAAC,MAAM,GAAG,GACzD,SAAS,KAAK,QAAQ;QAE1B;IACF;IAEA,SAAS;IAET,gBAAgB;IAChB,OAAO,OAAO,IAAI,CAAC,CAAC,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"}
@@ -1,3 +1,30 @@
1
+ :root {
2
+ --text-line-height: 3em;
3
+ --main-extra-width: 200px;
4
+ }
5
+
6
+ .QoX8-W_page-wrapper {
7
+ flex-direction: row;
8
+ align-items: flex-start;
9
+ gap: 2em;
10
+ display: flex;
11
+ position: relative;
12
+ }
13
+
14
+ .QoX8-W_feedback-container {
15
+ flex: 4;
16
+ }
17
+
18
+ .QoX8-W_control-panel {
19
+ flex: 1;
20
+ height: auto;
21
+ }
22
+
23
+ .QoX8-W_control-content {
24
+ position: sticky;
25
+ top: 0;
26
+ }
27
+
1
28
  .QoX8-W_feedback-component {
2
29
  width: 800px;
3
30
  position: relative;
@@ -24,31 +51,21 @@ circle {
24
51
  margin-bottom: 2em;
25
52
  }
26
53
 
27
- .QoX8-W_entity-panel {
28
- max-height: 600px;
29
- position: relative;
30
- }
31
-
32
- .QoX8-W_control-panel {
33
- padding: .2em .5em;
34
- position: absolute;
35
- top: 1em;
36
- right: 1em;
37
- }
38
-
39
54
  .QoX8-W_entity-panel {
40
55
  background: var(--panel-secondary-background-color);
56
+ width: calc(100% - 2em);
41
57
  min-height: 100px;
58
+ max-height: 600px;
42
59
  box-shadow: 0 0 0 1px var(--panel-border-color) inset;
43
60
  border-radius: 4px;
44
61
  flex: 1;
45
62
  padding: 1em;
63
+ position: relative;
46
64
  }
47
65
 
48
66
  .QoX8-W_selection-tree {
49
67
  margin: -1em 0;
50
68
  padding: 1em 0;
51
- width: 70% !important;
52
69
  }
53
70
 
54
71
  .QoX8-W_type-list {
@@ -88,6 +105,7 @@ mark {
88
105
 
89
106
  .QoX8-W_feedback-text-wrapper {
90
107
  z-index: 0;
108
+ line-height: var(--text-line-height);
91
109
  position: relative;
92
110
  overflow: visible;
93
111
  }
@@ -153,4 +171,10 @@ mark {
153
171
  gap: .25em;
154
172
  display: flex;
155
173
  }
156
- /*# sourceMappingURL=feedback-components.b7d9b015.css.map */
174
+
175
+ .QoX8-W_node-label {
176
+ fill: var(--text-emphasized-color);
177
+ fontSize: 10px;
178
+ pointerEvents: none;
179
+ }
180
+ /*# sourceMappingURL=feedback-components.fb60c70d.css.map */
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA;;;;;AAIA;;;;;;;;AAOA;;;;AAGA;;;;;AAIA;;;;;AAIA;;;;;AAIE;;;;AAGF;;;;AAGA;;;;;AAIA;;;;AAGA;;;;AAGA;;;;;;;;;;;;AAYA;;;;;AAIA;;;;;;;AAME;;;;;AAIF;;;;;AAIA;;;;;;AAKA;;;;AAGA;;;;;;;;AAOA;;;;;;;AAMA;;;;;;;AAMA;;;;;;;;AAOE;;;;AAGF;;;;;;;;AAOE;;;;;;;;;AAQE;;;;;;AAKA;;;;AAGA;;;;;AAIE;;;;;;AAKN;;;;;AAIA","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.fb60c70d.css.map"}