@macrostrat/feedback-components 1.1.4 → 1.1.5

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 (74) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/esm/{feedback-components.7e879290.js → feedback-components.03f08dc7.js} +10 -9
  3. package/dist/esm/feedback-components.03f08dc7.js.map +1 -0
  4. package/dist/esm/{feedback-components.204f7d2b.js → feedback-components.06a79c6a.js} +46 -21
  5. package/dist/esm/feedback-components.06a79c6a.js.map +1 -0
  6. package/dist/esm/{feedback-components.1c15f37f.js → feedback-components.3f59f2a5.js} +14 -97
  7. package/dist/esm/feedback-components.3f59f2a5.js.map +1 -0
  8. package/dist/esm/{feedback-components.d55a1d18.js → feedback-components.4cbd249a.js} +5 -5
  9. package/dist/esm/{feedback-components.d55a1d18.js.map → feedback-components.4cbd249a.js.map} +1 -1
  10. package/dist/esm/{feedback-components.d591ffec.css → feedback-components.5a8f0185.css} +11 -5
  11. package/dist/esm/feedback-components.5a8f0185.css.map +1 -0
  12. package/dist/esm/{feedback-components.f6605b83.js → feedback-components.6cec1102.js} +79 -46
  13. package/dist/esm/feedback-components.6cec1102.js.map +1 -0
  14. package/dist/esm/{feedback-components.00434ff7.js → feedback-components.7c2fe400.js} +7 -1
  15. package/dist/esm/feedback-components.7c2fe400.js.map +1 -0
  16. package/dist/esm/{feedback-components.28ba71be.js → feedback-components.939a3a9f.js} +7 -7
  17. package/dist/esm/feedback-components.939a3a9f.js.map +1 -0
  18. package/dist/esm/{feedback-components.fd8ac9ca.js → feedback-components.e53837d9.js} +114 -96
  19. package/dist/esm/feedback-components.e53837d9.js.map +1 -0
  20. package/dist/esm/index.d.ts +2 -1
  21. package/dist/esm/index.d.ts.map +1 -1
  22. package/dist/esm/index.js +1 -1
  23. package/dist/node/{feedback-components.2f740fc7.js → feedback-components.3888aa2a.js} +2 -2
  24. package/dist/node/{feedback-components.2f740fc7.js.map → feedback-components.3888aa2a.js.map} +1 -1
  25. package/dist/node/feedback-components.388de4ac.js +2 -0
  26. package/dist/node/feedback-components.388de4ac.js.map +1 -0
  27. package/dist/node/feedback-components.827f8d80.js +2 -0
  28. package/dist/node/feedback-components.827f8d80.js.map +1 -0
  29. package/dist/node/feedback-components.9e1d4e4c.js +2 -0
  30. package/dist/node/feedback-components.9e1d4e4c.js.map +1 -0
  31. package/dist/node/feedback-components.b8da3bce.js +2 -0
  32. package/dist/node/feedback-components.b8da3bce.js.map +1 -0
  33. package/dist/node/feedback-components.c31cf831.js +2 -0
  34. package/dist/node/feedback-components.c31cf831.js.map +1 -0
  35. package/dist/node/feedback-components.db4d0a14.css +2 -0
  36. package/dist/node/feedback-components.db4d0a14.css.map +1 -0
  37. package/dist/node/feedback-components.f91331e9.js +2 -0
  38. package/dist/node/feedback-components.f91331e9.js.map +1 -0
  39. package/dist/node/feedback-components.fc0395df.js +2 -0
  40. package/dist/node/feedback-components.fc0395df.js.map +1 -0
  41. package/dist/node/index.js +1 -1
  42. package/dist/node/index.js.map +1 -1
  43. package/package.json +2 -2
  44. package/src/feedback/edit-state.ts +96 -49
  45. package/src/feedback/feedback.module.sass +9 -5
  46. package/src/feedback/graph.ts +5 -2
  47. package/src/feedback/index.ts +29 -4
  48. package/src/feedback/matches.ts +123 -85
  49. package/src/feedback/text-visualizer.ts +32 -86
  50. package/src/feedback/typelist.ts +13 -4
  51. package/dist/esm/feedback-components.00434ff7.js.map +0 -1
  52. package/dist/esm/feedback-components.1c15f37f.js.map +0 -1
  53. package/dist/esm/feedback-components.204f7d2b.js.map +0 -1
  54. package/dist/esm/feedback-components.28ba71be.js.map +0 -1
  55. package/dist/esm/feedback-components.7e879290.js.map +0 -1
  56. package/dist/esm/feedback-components.d591ffec.css.map +0 -1
  57. package/dist/esm/feedback-components.f6605b83.js.map +0 -1
  58. package/dist/esm/feedback-components.fd8ac9ca.js.map +0 -1
  59. package/dist/node/feedback-components.0eef8d0c.js +0 -2
  60. package/dist/node/feedback-components.0eef8d0c.js.map +0 -1
  61. package/dist/node/feedback-components.41db283a.js +0 -2
  62. package/dist/node/feedback-components.41db283a.js.map +0 -1
  63. package/dist/node/feedback-components.69d0ccd0.js +0 -2
  64. package/dist/node/feedback-components.69d0ccd0.js.map +0 -1
  65. package/dist/node/feedback-components.a7b43cfa.js +0 -2
  66. package/dist/node/feedback-components.a7b43cfa.js.map +0 -1
  67. package/dist/node/feedback-components.b9317f9c.js +0 -2
  68. package/dist/node/feedback-components.b9317f9c.js.map +0 -1
  69. package/dist/node/feedback-components.e096504e.css +0 -2
  70. package/dist/node/feedback-components.e096504e.css.map +0 -1
  71. package/dist/node/feedback-components.e140ac86.js +0 -2
  72. package/dist/node/feedback-components.e140ac86.js.map +0 -1
  73. package/dist/node/feedback-components.f8373b58.js +0 -2
  74. package/dist/node/feedback-components.f8373b58.js.map +0 -1
@@ -8,7 +8,7 @@ var $b79bf29960412ca7$export$53ec42062883b2d4 = /*#__PURE__*/ function(ViewMode)
8
8
  ViewMode["Graph"] = "graph";
9
9
  return ViewMode;
10
10
  }({});
11
- function $b79bf29960412ca7$export$911bb4b9c8065d3d(initialTree, entityTypes) {
11
+ function $b79bf29960412ca7$export$911bb4b9c8065d3d(initialTree, entityTypes, viewOnly, matchMode) {
12
12
  // Get the first entity type
13
13
  // issue: grabs second entity instead of selected one
14
14
  const type = entityTypes.values().next().value;
@@ -20,7 +20,9 @@ function $b79bf29960412ca7$export$911bb4b9c8065d3d(initialTree, entityTypes) {
20
20
  selectedEntityType: type,
21
21
  lastInternalId: 0,
22
22
  isSelectingEntityType: false,
23
- viewMode: "tree"
23
+ viewMode: "tree",
24
+ viewOnly: viewOnly,
25
+ matchMode: matchMode
24
26
  });
25
27
  }
26
28
  const $b79bf29960412ca7$export$e5ce04c5b3f58533 = (0, $abOVY$createContext)(null);
@@ -30,6 +32,12 @@ function $b79bf29960412ca7$export$e1068f2d1c68f87e() {
30
32
  return dispatch;
31
33
  }
32
34
  function $b79bf29960412ca7$var$treeReducer(state, action) {
35
+ if (action.type === "toggle-match-mode") return {
36
+ ...state,
37
+ matchMode: !state.matchMode
38
+ };
39
+ if (state.viewOnly) return $b79bf29960412ca7$var$viewMode(state, action);
40
+ if (state.matchMode) return $b79bf29960412ca7$var$matchMode(state, action);
33
41
  switch(action.type){
34
42
  case "add-entity-type":
35
43
  {
@@ -191,49 +199,6 @@ function $b79bf29960412ca7$var$treeReducer(state, action) {
191
199
  selectedNodes: []
192
200
  };
193
201
  }
194
- case "add-match":
195
- {
196
- const { id: id } = action.payload;
197
- // Find the node path
198
- const keyPath = $b79bf29960412ca7$var$findNode(state.tree, id);
199
- if (!keyPath) {
200
- console.warn(`Node with id ${id} not found`);
201
- return state;
202
- }
203
- // Build update spec to set the `match` property
204
- const matchUpdateSpec = $b79bf29960412ca7$var$buildNestedSpec(keyPath, {
205
- match: {
206
- $set: action.payload.payload
207
- }
208
- });
209
- const updatedTree = (0, $abOVY$immutabilityhelper)(state.tree, matchUpdateSpec);
210
- return {
211
- ...state,
212
- tree: updatedTree
213
- };
214
- }
215
- case "remove-match":
216
- {
217
- const { id: id } = action.payload;
218
- console.log("Removing match for node with id:", id);
219
- // Find the node path
220
- const keyPath = $b79bf29960412ca7$var$findNode(state.tree, id);
221
- if (!keyPath) {
222
- console.warn(`Node with id ${id} not found`);
223
- return state;
224
- }
225
- // Build update spec to unset the `match` property
226
- const matchUpdateSpec = $b79bf29960412ca7$var$buildNestedSpec(keyPath, {
227
- match: {
228
- $set: null
229
- }
230
- });
231
- const updatedTree = (0, $abOVY$immutabilityhelper)(state.tree, matchUpdateSpec);
232
- return {
233
- ...state,
234
- tree: updatedTree
235
- };
236
- }
237
202
  /** Entity type selection */ case "toggle-entity-type-selector":
238
203
  return {
239
204
  ...state,
@@ -405,7 +370,75 @@ function $b79bf29960412ca7$var$flattenAndSort(nodes) {
405
370
  // sort by start
406
371
  return result.sort((a, b)=>a.indices[0] - b.indices[0]);
407
372
  }
373
+ function $b79bf29960412ca7$var$matchMode(state, action) {
374
+ if (action.type === "select-node" || action.type === "toggle-node-selected") {
375
+ const { ids: ids } = action.payload;
376
+ if (ids.length != 1) return state;
377
+ if (state.selectedNodes.length === 1) {
378
+ if (ids[0] === state.selectedNodes[0]) // If the selected node is the same as the current selection, deselect it
379
+ return {
380
+ ...state,
381
+ selectedNodes: []
382
+ };
383
+ }
384
+ const type = action.payload.ids.length > 0 ? $b79bf29960412ca7$export$e64eb58334357825(state.tree, ids[0])?.type : null;
385
+ return {
386
+ ...state,
387
+ selectedNodes: ids,
388
+ selectedEntityType: type
389
+ };
390
+ }
391
+ if (action.type === "add-match") {
392
+ const { id: id } = action.payload;
393
+ // Find the node path
394
+ const keyPath = $b79bf29960412ca7$var$findNode(state.tree, id);
395
+ if (!keyPath) {
396
+ console.warn(`Node with id ${id} not found`);
397
+ return state;
398
+ }
399
+ // Build update spec to set the `match` property
400
+ const matchUpdateSpec = $b79bf29960412ca7$var$buildNestedSpec(keyPath, {
401
+ match: {
402
+ $set: action.payload.payload
403
+ }
404
+ });
405
+ const updatedTree = (0, $abOVY$immutabilityhelper)(state.tree, matchUpdateSpec);
406
+ return {
407
+ ...state,
408
+ tree: updatedTree
409
+ };
410
+ }
411
+ if (action.type === "remove-match") {
412
+ const { id: id } = action.payload;
413
+ console.log("Removing match for node with id:", id);
414
+ // Find the node path
415
+ const keyPath = $b79bf29960412ca7$var$findNode(state.tree, id);
416
+ if (!keyPath) {
417
+ console.warn(`Node with id ${id} not found`);
418
+ return state;
419
+ }
420
+ // Build update spec to unset the `match` property
421
+ const matchUpdateSpec = $b79bf29960412ca7$var$buildNestedSpec(keyPath, {
422
+ match: {
423
+ $set: null
424
+ }
425
+ });
426
+ const updatedTree = (0, $abOVY$immutabilityhelper)(state.tree, matchUpdateSpec);
427
+ return {
428
+ ...state,
429
+ tree: updatedTree
430
+ };
431
+ }
432
+ return state;
433
+ }
434
+ function $b79bf29960412ca7$var$viewMode(state, action) {
435
+ if (action.type === "set-view-mode") return {
436
+ ...state,
437
+ viewMode: action.payload
438
+ };
439
+ return state;
440
+ }
408
441
 
409
442
 
410
443
  export {$b79bf29960412ca7$export$53ec42062883b2d4 as ViewMode, $b79bf29960412ca7$export$911bb4b9c8065d3d as useUpdatableTree, $b79bf29960412ca7$export$e5ce04c5b3f58533 as TreeDispatchContext, $b79bf29960412ca7$export$e1068f2d1c68f87e as useTreeDispatch, $b79bf29960412ca7$export$e64eb58334357825 as findNodeById, $b79bf29960412ca7$export$8d9dbb7a64bf2a5e as treeToGraph};
411
- //# sourceMappingURL=feedback-components.f6605b83.js.map
444
+ //# sourceMappingURL=feedback-components.6cec1102.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;AAKO,IAAA,AAAK,mEAAA;;;WAAA;;AAsDL,SAAS,0CACd,WAAuB,EACvB,WAAoC,EACpC,QAAiB,EACjB,SAAkB;IAElB,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;kBACR;mBACA;IACF;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,IAAI,OAAO,IAAI,KAAK,qBAClB,OAAO;QAAE,GAAG,KAAK;QAAE,WAAW,CAAC,MAAM,SAAS;IAAC;IAGjD,IAAI,MAAM,QAAQ,EAAE,OAAO,+BAAS,OAAO;IAE3C,IAAI,MAAM,SAAS,EAAE,OAAO,gCAAU,OAAO;IAE7C,OAAQ,OAAO,IAAI;QACjB,KAAK;YAA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Aa,EAAE,GAAG,UAAU,CAAC;YAC3C,OAAO;QACT;QAEA,gDAAgD;QAChD,MAAM,kBAAkB,sCAAgB,SAAS;YAC/C,OAAO;gBAAE,MAAM,OAAO,OAAO,CAAC,OAAO;YAAC;QACxC;QAEA,MAAM,cAAc,CAAA,GAAA,yBAAK,EAAE,MAAM,IAAI,EAAE;QAEvC,OAAO;YACL,GAAG,KAAK;YACR,MAAM;QACR;IACF;IAEA,IAAI,OAAO,IAAI,KAAK,gBAAgB;QAClC,MAAM,MAAE,EAAE,EAAE,GAAG,OAAO,OAAO;QAE7B,QAAQ,GAAG,CAAC,oCAAoC;QAEhD,qBAAqB;QACrB,MAAM,UAAU,+BAAS,MAAM,IAAI,EAAE;QACrC,IAAI,CAAC,SAAS;YACZ,QAAQ,IAAI,CAAC,CAAC,aAAa,EAAE,GAAG,UAAU,CAAC;YAC3C,OAAO;QACT;QAEA,kDAAkD;QAClD,MAAM,kBAAkB,sCAAgB,SAAS;YAC/C,OAAO;gBAAE,MAAM;YAAK;QACtB;QAEA,MAAM,cAAc,CAAA,GAAA,yBAAK,EAAE,MAAM,IAAI,EAAE;QAEvC,OAAO;YACL,GAAG,KAAK;YACR,MAAM;QACR;IACF;IAEA,OAAO;AACT;AAEA,SAAS,+BAAS,KAAK,EAAE,MAAM;IAC7B,IAAI,OAAO,IAAI,KAAK,iBAClB,OAAO;QAAE,GAAG,KAAK;QAAE,UAAU,OAAO,OAAO;IAAC;IAG9C,OAAO;AACT","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 viewOnly: boolean;\n matchMode: boolean;\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 | { type: \"add-match\"; payload: { id: number; payload: any } }\n | { type: \"remove-match\"; payload: { id: number } }\n | { type: \"toggle-match-mode\" };\n\nexport type TreeDispatch = Dispatch<TreeAction>;\n\nexport function useUpdatableTree(\n initialTree: TreeData[],\n entityTypes: Map<number, EntityType>,\n viewOnly: boolean,\n matchMode: boolean,\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 viewOnly,\n matchMode,\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 if (action.type === \"toggle-match-mode\") {\n return { ...state, matchMode: !state.matchMode };\n }\n\n if (state.viewOnly) return viewMode(state, action);\n\n if (state.matchMode) return matchMode(state, action);\n\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 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\nexport function 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\nfunction matchMode(state, action) {\n if (action.type === \"select-node\" || action.type === \"toggle-node-selected\") {\n const { ids } = action.payload;\n\n if (ids.length != 1) return state;\n\n if (state.selectedNodes.length === 1) {\n if (ids[0] === state.selectedNodes[0]) {\n // If the selected node is the same as the current selection, deselect it\n return { ...state, selectedNodes: [] };\n }\n }\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 }\n\n if (action.type === \"add-match\") {\n const { id } = action.payload;\n\n // Find the node path\n const keyPath = findNode(state.tree, id);\n if (!keyPath) {\n console.warn(`Node with id ${id} not found`);\n return state;\n }\n\n // Build update spec to set the `match` property\n const matchUpdateSpec = buildNestedSpec(keyPath, {\n match: { $set: action.payload.payload },\n });\n\n const updatedTree = update(state.tree, matchUpdateSpec);\n\n return {\n ...state,\n tree: updatedTree,\n };\n }\n\n if (action.type === \"remove-match\") {\n const { id } = action.payload;\n\n console.log(\"Removing match for node with id:\", id);\n\n // Find the node path\n const keyPath = findNode(state.tree, id);\n if (!keyPath) {\n console.warn(`Node with id ${id} not found`);\n return state;\n }\n\n // Build update spec to unset the `match` property\n const matchUpdateSpec = buildNestedSpec(keyPath, {\n match: { $set: null },\n });\n\n const updatedTree = update(state.tree, matchUpdateSpec);\n\n return {\n ...state,\n tree: updatedTree,\n };\n }\n\n return state;\n}\n\nfunction viewMode(state, action) {\n if (action.type === \"set-view-mode\") {\n return { ...state, viewMode: action.payload };\n }\n\n return state;\n}\n"],"names":[],"version":3,"file":"feedback-components.6cec1102.js.map"}
@@ -6,6 +6,7 @@ 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, "clickable", () => $49c87ee97f392268$export$60d5655c6babb2a0, (v) => $49c87ee97f392268$export$60d5655c6babb2a0 = v);
9
10
  $parcel$export($49c87ee97f392268$exports, "close-btn", () => $49c87ee97f392268$export$f5032a039312e50b, (v) => $49c87ee97f392268$export$f5032a039312e50b = v);
10
11
  $parcel$export($49c87ee97f392268$exports, "control-content", () => $49c87ee97f392268$export$42e8b5293e69631e, (v) => $49c87ee97f392268$export$42e8b5293e69631e = v);
11
12
  $parcel$export($49c87ee97f392268$exports, "control-panel", () => $49c87ee97f392268$export$a0a23f31d5562853, (v) => $49c87ee97f392268$export$a0a23f31d5562853 = v);
@@ -20,6 +21,7 @@ $parcel$export($49c87ee97f392268$exports, "highlight", () => $49c87ee97f392268$e
20
21
  $parcel$export($49c87ee97f392268$exports, "icons", () => $49c87ee97f392268$export$df03f54e09e486fa, (v) => $49c87ee97f392268$export$df03f54e09e486fa = v);
21
22
  $parcel$export($49c87ee97f392268$exports, "match-container", () => $49c87ee97f392268$export$864d1dadc1dd3f57, (v) => $49c87ee97f392268$export$864d1dadc1dd3f57 = v);
22
23
  $parcel$export($49c87ee97f392268$exports, "match-item", () => $49c87ee97f392268$export$a7bcc8ced81f8d07, (v) => $49c87ee97f392268$export$a7bcc8ced81f8d07 = v);
24
+ $parcel$export($49c87ee97f392268$exports, "match-label", () => $49c87ee97f392268$export$be49c8f7a120829f, (v) => $49c87ee97f392268$export$be49c8f7a120829f = v);
23
25
  $parcel$export($49c87ee97f392268$exports, "node", () => $49c87ee97f392268$export$35059013cd4a06db, (v) => $49c87ee97f392268$export$35059013cd4a06db = v);
24
26
  $parcel$export($49c87ee97f392268$exports, "node-label", () => $49c87ee97f392268$export$75d14899fb692bb6, (v) => $49c87ee97f392268$export$75d14899fb692bb6 = v);
25
27
  $parcel$export($49c87ee97f392268$exports, "overlay-container", () => $49c87ee97f392268$export$6a1093e41947f68e, (v) => $49c87ee97f392268$export$6a1093e41947f68e = v);
@@ -33,6 +35,7 @@ $parcel$export($49c87ee97f392268$exports, "type-list", () => $49c87ee97f392268$e
33
35
  $parcel$export($49c87ee97f392268$exports, "type-tag", () => $49c87ee97f392268$export$5e5acbc770fb0e4, (v) => $49c87ee97f392268$export$5e5acbc770fb0e4 = v);
34
36
  var $49c87ee97f392268$export$cb889aaddfa2926c;
35
37
  var $49c87ee97f392268$export$5f8f750fd71deeed;
38
+ var $49c87ee97f392268$export$60d5655c6babb2a0;
36
39
  var $49c87ee97f392268$export$f5032a039312e50b;
37
40
  var $49c87ee97f392268$export$42e8b5293e69631e;
38
41
  var $49c87ee97f392268$export$a0a23f31d5562853;
@@ -47,6 +50,7 @@ var $49c87ee97f392268$export$e4043f67d36cbb26;
47
50
  var $49c87ee97f392268$export$df03f54e09e486fa;
48
51
  var $49c87ee97f392268$export$864d1dadc1dd3f57;
49
52
  var $49c87ee97f392268$export$a7bcc8ced81f8d07;
53
+ var $49c87ee97f392268$export$be49c8f7a120829f;
50
54
  var $49c87ee97f392268$export$35059013cd4a06db;
51
55
  var $49c87ee97f392268$export$75d14899fb692bb6;
52
56
  var $49c87ee97f392268$export$6a1093e41947f68e;
@@ -60,6 +64,7 @@ var $49c87ee97f392268$export$915fe2ca68846e4c;
60
64
  var $49c87ee97f392268$export$5e5acbc770fb0e4;
61
65
  $49c87ee97f392268$export$cb889aaddfa2926c = `QoX8-W_add-type`;
62
66
  $49c87ee97f392268$export$5f8f750fd71deeed = `QoX8-W_add-type-overlay`;
67
+ $49c87ee97f392268$export$60d5655c6babb2a0 = `QoX8-W_clickable`;
63
68
  $49c87ee97f392268$export$f5032a039312e50b = `QoX8-W_close-btn`;
64
69
  $49c87ee97f392268$export$42e8b5293e69631e = `QoX8-W_control-content`;
65
70
  $49c87ee97f392268$export$a0a23f31d5562853 = `QoX8-W_control-panel`;
@@ -74,6 +79,7 @@ $49c87ee97f392268$export$e4043f67d36cbb26 = `QoX8-W_highlight`;
74
79
  $49c87ee97f392268$export$df03f54e09e486fa = `QoX8-W_icons`;
75
80
  $49c87ee97f392268$export$864d1dadc1dd3f57 = `QoX8-W_match-container`;
76
81
  $49c87ee97f392268$export$a7bcc8ced81f8d07 = `QoX8-W_match-item`;
82
+ $49c87ee97f392268$export$be49c8f7a120829f = `QoX8-W_match-label`;
77
83
  $49c87ee97f392268$export$35059013cd4a06db = `QoX8-W_node`;
78
84
  $49c87ee97f392268$export$75d14899fb692bb6 = `QoX8-W_node-label`;
79
85
  $49c87ee97f392268$export$6a1093e41947f68e = `QoX8-W_overlay-container`;
@@ -88,4 +94,4 @@ $49c87ee97f392268$export$5e5acbc770fb0e4 = `QoX8-W_type-tag`;
88
94
 
89
95
 
90
96
  export {$49c87ee97f392268$exports as default};
91
- //# sourceMappingURL=feedback-components.00434ff7.js.map
97
+ //# sourceMappingURL=feedback-components.7c2fe400.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;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AA5BA,4CAA6B,CAAC,eAAe,CAAC;AAC9C,4CAAqC,CAAC,uBAAuB,CAAC;AAC9D,4CAA8B,CAAC,gBAAgB,CAAC;AAChD,4CAA8B,CAAC,gBAAgB,CAAC;AAChD,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,4CAAoC,CAAC,sBAAsB,CAAC;AAC5D,4CAA+B,CAAC,iBAAiB,CAAC;AAClD,4CAAgC,CAAC,kBAAkB,CAAC;AACpD,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 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 padding: .2em 0\n border-radius: .2em\n position: relative\n zIndex: 10\n\n.clickable\n cursor: pointer\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(--tertiary-background)\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\n\n.match-item\n color: var(--text-emphasized-color)\n padding: .1em .2em\n border-radius: .2em\n margin-bottom: 4px\n cursor: pointer\n \n .match-label\n margin: 0\n color: var(--text-color)\n\n.match-container\n display: flex\n justify-content: space-between\n align-items: center\n\n .close-btn\n cursor: pointer\n"],"names":[],"version":3,"file":"feedback-components.7c2fe400.js.map"}
@@ -1,6 +1,6 @@
1
- import {treeToGraph as $b79bf29960412ca7$export$8d9dbb7a64bf2a5e} from "./feedback-components.f6605b83.js";
2
- import "./feedback-components.d591ffec.css";
3
- import $phGch$feedbackcomponents00434ff7js from "./feedback-components.00434ff7.js";
1
+ import {treeToGraph as $b79bf29960412ca7$export$8d9dbb7a64bf2a5e} from "./feedback-components.6cec1102.js";
2
+ import "./feedback-components.5a8f0185.css";
3
+ import $phGch$feedbackcomponents7c2fe400js from "./feedback-components.7c2fe400.js";
4
4
  import {getTagStyle as $03d8811e9c9b360d$export$35baa338324d8550} from "./feedback-components.707e3490.js";
5
5
  import $phGch$macrostrathyper from "@macrostrat/hyper";
6
6
  import {forceSimulation as $phGch$forceSimulation, forceLink as $phGch$forceLink, forceManyBody as $phGch$forceManyBody, forceCenter as $phGch$forceCenter, forceCollide as $phGch$forceCollide} from "d3-force";
@@ -20,11 +20,11 @@ function $parcel$interopDefault(a) {
20
20
 
21
21
 
22
22
 
23
- const $ff8c3e7f2bc22925$var$h = (0, $phGch$macrostrathyper).styled((0, ($parcel$interopDefault($phGch$feedbackcomponents00434ff7js))));
23
+ const $ff8c3e7f2bc22925$var$h = (0, $phGch$macrostrathyper).styled((0, ($parcel$interopDefault($phGch$feedbackcomponents7c2fe400js))));
24
24
  function $ff8c3e7f2bc22925$export$6a7fe3ef90e8d566(props) {
25
25
  // A graph view with react-flow
26
26
  // Get positions of nodes using force simulation
27
- const { tree: tree, width: width, height: height, dispatch: dispatch, selectedNodes: selectedNodes } = props;
27
+ const { tree: tree, width: width, height: height, dispatch: dispatch, selectedNodes: selectedNodes, viewOnly: viewOnly } = props;
28
28
  const [nodes, setNodes] = (0, $phGch$useState)(null);
29
29
  const [links, setLinks] = (0, $phGch$useState)(null);
30
30
  const [showLabels, setShowLabels] = (0, $phGch$useState)(false);
@@ -123,7 +123,7 @@ function $ff8c3e7f2bc22925$export$6a7fe3ef90e8d566(props) {
123
123
  }
124
124
  });
125
125
  },
126
- className: active ? "selected" : "",
126
+ className: active ? "selected" : "" + (viewOnly ? "" : " clickable"),
127
127
  stroke: stroke,
128
128
  strokeWidth: 2
129
129
  }),
@@ -145,4 +145,4 @@ function $ff8c3e7f2bc22925$var$isHighlighted(id, selectedNodes, nodes) {
145
145
 
146
146
 
147
147
  export {$ff8c3e7f2bc22925$export$6a7fe3ef90e8d566 as GraphView};
148
- //# sourceMappingURL=feedback-components.28ba71be.js.map
148
+ //# sourceMappingURL=feedback-components.939a3a9f.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,0BAAI,CAAA,GAAA,sBAAI,EAAE,MAAM,CAAC,CAAA,GAAA,8EAAK;AAErB,SAAS,0CAAU,KAOzB;IACC,+BAA+B;IAC/B,gDAAgD;IAChD,MAAM,QAAE,IAAI,SAAE,KAAK,UAAE,MAAM,YAAE,QAAQ,iBAAE,aAAa,YAAE,QAAQ,EAAE,GAAG;IAEnE,MAAM,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAO,EAAyB;IAC1D,MAAM,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAO,EAAyB;IAC1D,MAAM,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,eAAO,EAAE;IAE7C,CAAA,GAAA,gBAAQ,EAAE;QACR,MAAM,SAAE,KAAK,SAAE,KAAK,EAAE,GAAG,CAAA,GAAA,yCAAU,EAAE;QAErC,MAAM,WAAW,IAAI,IACnB,MAAM,GAAG,CAAC,CAAC,IAAM;gBAAC,EAAE,EAAE;gBAAE;aAAE;QAG5B,MAAM,QAAQ,MAAM,GAAG,CAAC,CAAC;YACvB,OAAO;gBACL,QAAQ,SAAS,GAAG,CAAC,EAAE,MAAM;gBAC7B,QAAQ,SAAS,GAAG,CAAC,EAAE,IAAI;gBAC3B,UAAU;YACZ;QACF;QAEA,MAAM,aAAa,CAAA,GAAA,sBAAc,EAAE,OACh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QAAQ,CAAC,IAAI,CAAC,CAAC,QAAU,MAAM,EAAE,KAAK;AAGnD","sources":["packages/feedback-components/src/feedback/graph.ts"],"sourcesContent":["import { TreeData } from \"./types\";\nimport { treeToGraph } from \"./edit-state\";\nimport styles from \"./feedback.module.sass\";\nimport hyper from \"@macrostrat/hyper\";\nimport {\n forceSimulation,\n SimulationNodeDatum,\n SimulationLinkDatum,\n forceCenter,\n forceLink,\n forceManyBody,\n forceCollide,\n} from \"d3-force\";\nimport { useEffect, useState } from \"react\";\nimport { Spinner, Switch } from \"@blueprintjs/core\";\nimport { ErrorBoundary } from \"@macrostrat/ui-components\";\nimport { getTagStyle } from \"../extractions\";\n\nconst h = hyper.styled(styles);\n\nexport function GraphView(props: {\n tree: TreeData[];\n width: number;\n height: number;\n dispatch: (action: any) => void;\n selectedNodes: number[];\n viewOnly?: boolean;\n}) {\n // A graph view with react-flow\n // Get positions of nodes using force simulation\n const { tree, width, height, dispatch, selectedNodes, viewOnly } = props;\n\n const [nodes, setNodes] = useState<SimulationNodeDatum[]>(null);\n const [links, setLinks] = useState<SimulationLinkDatum[]>(null);\n const [showLabels, setShowLabels] = useState(false);\n\n useEffect(() => {\n const { nodes, edges } = treeToGraph(tree);\n\n const nodesMap = new Map<number, SimulationNodeDatum>(\n nodes.map((d) => [d.id, d]),\n );\n\n const links = edges.map((d) => {\n return {\n source: nodesMap.get(d.source),\n target: nodesMap.get(d.dest),\n strength: 1,\n };\n });\n\n const simulation = forceSimulation(nodes)\n .force(\"link\", forceLink(links))\n .force(\"charge\", forceManyBody().strength(-50))\n .force(\"center\", forceCenter(width / 2, height / 2))\n .force(\"collide\", forceCollide().radius(20))\n .on(\"tick\", () => {\n // Update the positions of the nodes\n // setNodes(nodes);\n console.log(\"Simulation tick\");\n })\n .on(\"end\", () => {\n // Update the positions of the nodes\n setNodes(nodes);\n setLinks(links);\n });\n\n return () => {\n simulation.stop();\n };\n }, [tree, width, height]);\n\n if (nodes == null || links == null) {\n return h(Spinner);\n }\n\n console.log(\"Graph\", nodes, links, selectedNodes);\n\n return h(\n ErrorBoundary,\n {\n description: \"An error occurred while rendering the graph view.\",\n },\n h(\"div.graph-view\", { style: { width, height } }, [\n h(Switch, {\n className: \"show-labels-switch\",\n label: \"Show Labels\",\n checked: showLabels,\n onChange: (e) => setShowLabels(e.target.checked),\n }),\n h(\"svg\", { width, height }, [\n h(\n \"g.links\",\n links.map((d) => {\n return h(\"line\", {\n x1: d.source.x,\n y1: d.source.y,\n x2: d.target.x,\n y2: d.target.y,\n stroke: \"black\",\n });\n }),\n ),\n h(\n \"g.nodes\",\n nodes.map((d) => {\n const active = selectedNodes.includes(d.id);\n const stroke = active ? \"white\" : \"black\";\n const highlighted = isHighlighted(d.id, selectedNodes, nodes);\n const style = getTagStyle(d.color, { highlighted, active });\n\n return h(\"g\", [\n h(\"circle\", {\n cx: d.x,\n cy: d.y,\n r: 8,\n fill: style.backgroundColor || \"blue\",\n onClick: (e) => {\n e.stopPropagation();\n if (\n e.ctrlKey ||\n e.metaKey ||\n (selectedNodes[0] === d.id && selectedNodes.length === 1)\n ) {\n // Toggle selection on ctrl/cmd click or when node is only selected node\n e.stopPropagation();\n dispatch({\n type: \"toggle-node-selected\",\n payload: { ids: [d.id] },\n });\n } else {\n dispatch({\n type: \"select-node\",\n payload: { ids: [d.id] },\n });\n }\n },\n className: active\n ? \"selected\"\n : \"\" + (viewOnly ? \"\" : \" clickable\"),\n stroke,\n strokeWidth: 2,\n }),\n h.if(showLabels)(\n \"text\",\n {\n x: d.x + 10,\n y: d.y + 4,\n className: \"node-label\",\n },\n d.name || `Node ${d.id}`,\n ),\n h.if(!showLabels)(\"title\", d.name || `Node ${d.id}`),\n ]);\n }),\n ),\n ]),\n ]),\n );\n}\n\nfunction isHighlighted(id: number, selectedNodes: number[], nodes: TreeData[]) {\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.939a3a9f.js.map"}
@@ -1,11 +1,10 @@
1
- import {Match as $156a3efbc315814c$export$f421feb8fad20413} from "./feedback-components.1c15f37f.js";
2
- import "./feedback-components.d591ffec.css";
3
- import $1RKp1$feedbackcomponents00434ff7js from "./feedback-components.00434ff7.js";
1
+ import "./feedback-components.5a8f0185.css";
2
+ import $1RKp1$feedbackcomponents7c2fe400js from "./feedback-components.7c2fe400.js";
4
3
  import {Divider as $1RKp1$Divider, Switch as $1RKp1$Switch, Icon as $1RKp1$Icon, Overlay2 as $1RKp1$Overlay2} from "@blueprintjs/core";
5
4
  import {Select as $1RKp1$Select} from "@blueprintjs/select";
6
5
  import $1RKp1$macrostrathyper from "@macrostrat/hyper";
7
6
  import {useState as $1RKp1$useState} from "react";
8
- import {useAPIResult as $1RKp1$useAPIResult, DataField as $1RKp1$DataField, JSONView as $1RKp1$JSONView, SaveButton as $1RKp1$SaveButton} from "@macrostrat/ui-components";
7
+ import {useAPIResult as $1RKp1$useAPIResult, SaveButton as $1RKp1$SaveButton, DataField as $1RKp1$DataField, JSONView as $1RKp1$JSONView} from "@macrostrat/ui-components";
9
8
  import {LithologyTag as $1RKp1$LithologyTag} from "@macrostrat/data-components";
10
9
 
11
10
 
@@ -19,8 +18,7 @@ function $parcel$interopDefault(a) {
19
18
 
20
19
 
21
20
 
22
-
23
- const $a878a21b0c10bfdc$var$h = (0, $1RKp1$macrostrathyper).styled((0, ($parcel$interopDefault($1RKp1$feedbackcomponents00434ff7js))));
21
+ const $a878a21b0c10bfdc$var$h = (0, $1RKp1$macrostrathyper).styled((0, ($parcel$interopDefault($1RKp1$feedbackcomponents7c2fe400js))));
24
22
  function $a878a21b0c10bfdc$export$6479cfcac2b87c0({ match: match, setMatchLinks: setMatchLinks, matchLinks: matchLinks, selectedNodes: selectedNodes, tree: tree, dispatch: dispatch }) {
25
23
  const [overlayOpen, setOverlayOpen] = (0, $1RKp1$useState)(false);
26
24
  let nodeMatch = null;
@@ -28,13 +26,16 @@ function $a878a21b0c10bfdc$export$6479cfcac2b87c0({ match: match, setMatchLinks:
28
26
  return $a878a21b0c10bfdc$var$h.if(matchLinks)("div", [
29
27
  $a878a21b0c10bfdc$var$h((0, $1RKp1$Divider)),
30
28
  $a878a21b0c10bfdc$var$h((0, $1RKp1$Switch), {
31
- label: "Show matches",
29
+ label: "Match mode",
32
30
  checked: match !== null,
33
31
  onChange: (e)=>{
34
32
  setMatchLinks(match === null ? matchLinks || {} : null);
33
+ dispatch({
34
+ type: "toggle-match-mode"
35
+ });
35
36
  }
36
37
  }),
37
- $a878a21b0c10bfdc$var$h.if(nodeMatch && match)((0, $156a3efbc315814c$export$f421feb8fad20413), {
38
+ $a878a21b0c10bfdc$var$h.if(nodeMatch && match)($a878a21b0c10bfdc$var$Match, {
38
39
  data: nodeMatch?.match,
39
40
  matchLinks: matchLinks,
40
41
  dispatch: dispatch,
@@ -81,94 +82,10 @@ function $a878a21b0c10bfdc$var$MatchOverlay({ isOpen: isOpen, setOverlayOpen: se
81
82
  const [disabled, setDisabled] = (0, $1RKp1$useState)(true);
82
83
  const [payload, setPayload] = (0, $1RKp1$useState)({});
83
84
  const data = (0, $1RKp1$useAPIResult)("https://dev.macrostrat.org/api/pg/type_lookup?name=ilike.*" + inputValue + "*");
84
- const items = data?.map((data)=>{
85
- const type = data.type || "";
86
- if (type === "lith") return $a878a21b0c10bfdc$var$h("div", {
87
- onClick: ()=>{
88
- setPayload({
89
- lith_id: data.id,
90
- name: data.name
91
- });
92
- }
93
- }, $a878a21b0c10bfdc$var$h((0, $1RKp1$DataField), {
94
- className: "match-item",
95
- label: "Lithology",
96
- value: $a878a21b0c10bfdc$var$h((0, $1RKp1$LithologyTag), {
97
- data: {
98
- name: data.name,
99
- id: data.lith_id,
100
- color: data.color
101
- }
102
- })
103
- }));
104
- if (type === "strat_name") return $a878a21b0c10bfdc$var$h("div", {
105
- onClick: ()=>{
106
- setPayload({
107
- strat_name_id: data.id,
108
- name: data.name
109
- });
110
- }
111
- }, $a878a21b0c10bfdc$var$h((0, $1RKp1$DataField), {
112
- className: "match-item",
113
- label: "Stratigraphic name",
114
- value: $a878a21b0c10bfdc$var$h((0, $1RKp1$LithologyTag), {
115
- data: {
116
- name: data.name,
117
- id: data.id,
118
- color: data.color
119
- }
120
- })
121
- }));
122
- if (type === "lith_att") return $a878a21b0c10bfdc$var$h("div", {
123
- onClick: ()=>{
124
- setPayload({
125
- lith_att_id: data.lith_att_id,
126
- name: data.name
127
- });
128
- }
129
- }, $a878a21b0c10bfdc$var$h((0, $1RKp1$DataField), {
130
- className: "match-item",
131
- label: "Lithology attribute",
132
- value: $a878a21b0c10bfdc$var$h((0, $1RKp1$LithologyTag), {
133
- data: {
134
- name: data.name,
135
- id: data.lith_att_id
136
- }
137
- }),
138
- onClick: ()=>{
139
- setPayload({
140
- lith_att_id: data.lith_att_id,
141
- name: data.name
142
- });
143
- }
144
- }));
145
- if (type === "interval") $a878a21b0c10bfdc$var$h("div", {
146
- onClick: ()=>{
147
- setPayload({
148
- int_id: data.id,
149
- name: data.name
150
- });
151
- }
152
- }, $a878a21b0c10bfdc$var$h((0, $1RKp1$DataField), {
153
- label: "Interval",
154
- className: "match-item",
155
- value: $a878a21b0c10bfdc$var$h((0, $1RKp1$LithologyTag), {
156
- data: {
157
- name: data.name,
158
- id: data.id
159
- }
160
- }),
161
- onClick: ()=>{
162
- setPayload({
163
- int_id: data.id,
164
- name: data.name
165
- });
166
- }
85
+ const items = data?.map((data)=>$a878a21b0c10bfdc$var$h($a878a21b0c10bfdc$var$MatchTag, {
86
+ data: data,
87
+ setPayload: setPayload
167
88
  }));
168
- return $a878a21b0c10bfdc$var$h((0, $1RKp1$JSONView), {
169
- data: data
170
- });
171
- });
172
89
  return $a878a21b0c10bfdc$var$h((0, $1RKp1$Overlay2), {
173
90
  isOpen: isOpen
174
91
  }, $a878a21b0c10bfdc$var$h("div.overlay-container", $a878a21b0c10bfdc$var$h("div.add-type-overlay", [
@@ -224,7 +141,108 @@ function $a878a21b0c10bfdc$var$MatchOverlay({ isOpen: isOpen, setOverlayOpen: se
224
141
  }, "Save changes")
225
142
  ])));
226
143
  }
144
+ function $a878a21b0c10bfdc$var$Match({ data: data, matchLinks: matchLinks, dispatch: dispatch, nodeId: nodeId }) {
145
+ return $a878a21b0c10bfdc$var$h.if(data)("div.match-container", [
146
+ $a878a21b0c10bfdc$var$MatchTag({
147
+ data: data,
148
+ matchLinks: matchLinks
149
+ }),
150
+ $a878a21b0c10bfdc$var$h((0, $1RKp1$Icon), {
151
+ icon: "cross",
152
+ color: "red",
153
+ className: "close-btn",
154
+ onClick: ()=>{
155
+ dispatch({
156
+ type: "remove-match",
157
+ payload: {
158
+ id: nodeId
159
+ }
160
+ });
161
+ }
162
+ })
163
+ ]);
164
+ }
165
+ function $a878a21b0c10bfdc$var$MatchTag({ data: data, matchLinks: matchLinks, setPayload: setPayload }) {
166
+ if (!data || Object.keys(data).length === 0) return;
167
+ if (data.lith_id || data?.type === "lith") return $a878a21b0c10bfdc$var$h("div", {
168
+ onClick: ()=>{
169
+ data.type === "lith" && setPayload({
170
+ lith_id: data.id,
171
+ name: data.name
172
+ });
173
+ }
174
+ }, $a878a21b0c10bfdc$var$h((0, $1RKp1$DataField), {
175
+ className: "match-item",
176
+ label: "Stratigraphic name",
177
+ value: $a878a21b0c10bfdc$var$h((0, $1RKp1$LithologyTag), {
178
+ data: {
179
+ name: data.name,
180
+ id: data.id,
181
+ color: data.color
182
+ },
183
+ onClick: ()=>window.open(matchLinks.strat_name + "/" + data.strat_name_id, "_blank")
184
+ })
185
+ }));
186
+ if (data.strat_name_id || data?.type === "strat_name") return $a878a21b0c10bfdc$var$h("div", {
187
+ onClick: ()=>{
188
+ data.type === "strat_name" && setPayload({
189
+ strat_name_id: data.id,
190
+ name: data.name
191
+ });
192
+ }
193
+ }, $a878a21b0c10bfdc$var$h((0, $1RKp1$DataField), {
194
+ className: "match-item",
195
+ label: "Stratigraphic name",
196
+ value: $a878a21b0c10bfdc$var$h((0, $1RKp1$LithologyTag), {
197
+ data: {
198
+ name: data.name,
199
+ id: data.id,
200
+ color: data.color
201
+ },
202
+ onClick: ()=>window.open(matchLinks.strat_name + "/" + data.strat_name_id, "_blank")
203
+ })
204
+ }));
205
+ if (data.lith_att_id || data?.type === "lith_att") return $a878a21b0c10bfdc$var$h("div", {
206
+ onClick: ()=>{
207
+ data.type === "lith_att" && setPayload({
208
+ lith_att_id: data.id,
209
+ name: data.name
210
+ });
211
+ }
212
+ }, $a878a21b0c10bfdc$var$h((0, $1RKp1$DataField), {
213
+ className: "match-item",
214
+ label: "Lithology attribute",
215
+ value: $a878a21b0c10bfdc$var$h((0, $1RKp1$LithologyTag), {
216
+ data: {
217
+ name: data.name,
218
+ id: data.lith_att_id
219
+ },
220
+ onClick: ()=>window.open(matchLinks.lith_att + "/" + data.lith_att_id, "_blank")
221
+ })
222
+ }));
223
+ if (data.int_id || data?.type === "interval") return $a878a21b0c10bfdc$var$h("div", {
224
+ onClick: ()=>{
225
+ data.type === "interval" && setPayload({
226
+ int_id: data.id,
227
+ name: data.name
228
+ });
229
+ }
230
+ }, $a878a21b0c10bfdc$var$h((0, $1RKp1$DataField), {
231
+ label: "Interval",
232
+ className: "match-item",
233
+ value: $a878a21b0c10bfdc$var$h((0, $1RKp1$LithologyTag), {
234
+ data: {
235
+ name: data.name,
236
+ id: data.id
237
+ },
238
+ onClick: ()=>window.open(matchLinks.interval + "/" + data.int_id, "_blank")
239
+ })
240
+ }));
241
+ return $a878a21b0c10bfdc$var$h((0, $1RKp1$JSONView), {
242
+ data: data
243
+ });
244
+ }
227
245
 
228
246
 
229
247
  export {$a878a21b0c10bfdc$export$6479cfcac2b87c0 as Matches};
230
- //# sourceMappingURL=feedback-components.fd8ac9ca.js.map
248
+ //# sourceMappingURL=feedback-components.e53837d9.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;AAUA,MAAM,0BAAI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AAE;IAAK;AAC5B","sources":["packages/feedback-components/src/feedback/matches.ts"],"sourcesContent":["import { Switch } from \"@blueprintjs/core\";\nimport { Select } from \"@blueprintjs/select\";\nimport styles from \"./feedback.module.sass\";\nimport hyper from \"@macrostrat/hyper\";\nimport { useState } from \"react\";\nimport { Icon, Divider, Overlay2 } from \"@blueprintjs/core\";\nimport { JSONView, SaveButton } from \"@macrostrat/ui-components\";\nimport { useAPIResult, DataField } from \"@macrostrat/ui-components\";\nimport { LithologyTag } from \"@macrostrat/data-components\";\n\nconst h = hyper.styled(styles);\n\nexport function Matches({\n match,\n setMatchLinks,\n matchLinks,\n selectedNodes,\n tree,\n dispatch,\n}) {\n const [overlayOpen, setOverlayOpen] = useState(false);\n\n let nodeMatch = null;\n if (selectedNodes.length === 1) {\n nodeMatch = findMatchingNode(tree, selectedNodes[0]);\n }\n\n return h.if(matchLinks)(\"div\", [\n h(Divider),\n h(Switch, {\n label: \"Match mode\",\n checked: match !== null,\n onChange: (e) => {\n setMatchLinks(match === null ? matchLinks || {} : null);\n dispatch({ type: \"toggle-match-mode\" });\n },\n }),\n h.if(nodeMatch && match)(Match, {\n data: nodeMatch?.match,\n matchLinks: matchLinks,\n dispatch,\n nodeId: nodeMatch?.id,\n }),\n h.if(selectedNodes.length == 1 && !nodeMatch?.match && match)(\n \"div.add-match-container\",\n [\n h(\n \"div.add-type\",\n {\n onClick: () => {\n setOverlayOpen(true);\n },\n },\n [h(\"p.add-match-text\", \"Add match\"), h(Icon, { icon: \"plus\" })],\n ),\n h(MatchOverlay, {\n isOpen: overlayOpen,\n setOverlayOpen,\n nodeMatch,\n dispatch,\n }),\n ],\n ),\n ]);\n}\n\nfunction findMatchingNode(tree, nodeId) {\n let match = null;\n\n function traverse(node) {\n if (node.id === nodeId) {\n match = node;\n return true;\n }\n if (Array.isArray(node.children)) {\n for (const child of node.children) {\n if (traverse(child)) return true;\n }\n }\n return false;\n }\n\n tree.forEach(traverse);\n return match;\n}\n\nfunction MatchOverlay({ isOpen, setOverlayOpen, nodeMatch, dispatch }) {\n const [inputValue, setInputValue] = useState(nodeMatch?.name || \"\");\n const [selectedItem, setSelectedItem] = useState(h(\"div\", \"Select a match\"));\n const [disabled, setDisabled] = useState(true);\n const [payload, setPayload] = useState({});\n\n const data = useAPIResult(\n \"https://dev.macrostrat.org/api/pg/type_lookup?name=ilike.*\" +\n inputValue +\n \"*\",\n );\n const items = data?.map((data) => h(MatchTag, { data, setPayload }));\n\n return h(\n Overlay2,\n {\n isOpen,\n },\n h(\n \"div.overlay-container\",\n h(\"div.add-type-overlay\", [\n h(\"h2.title\", [\n \"Add match with \" + nodeMatch.name,\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(\n Select,\n {\n items: items || [],\n itemRenderer: (item, { handleClick }) => {\n return h(\"div.match-item\", { onClick: handleClick }, item);\n },\n onItemSelect: (item) => {\n setDisabled(false);\n setSelectedItem(item);\n },\n onQueryChange: (query) => setInputValue(query),\n popoverProps: { minimal: true },\n query: inputValue,\n placeholder: \"Enter match name\",\n },\n selectedItem,\n ),\n ]),\n h(\n SaveButton,\n {\n className: \"save-btn\",\n small: true,\n onClick: () => {\n // Handle save changes\n dispatch({\n type: \"add-match\",\n payload: { id: nodeMatch.id, payload },\n });\n setOverlayOpen(false);\n },\n disabled,\n },\n \"Save changes\",\n ),\n ]),\n ),\n );\n}\n\nfunction Match({ data, matchLinks, dispatch, nodeId }) {\n return h.if(data)(\"div.match-container\", [\n MatchTag({ data, matchLinks }),\n h(Icon, {\n icon: \"cross\",\n color: \"red\",\n className: \"close-btn\",\n onClick: () => {\n dispatch({ type: \"remove-match\", payload: { id: nodeId } });\n },\n }),\n ]);\n}\n\ninterface MatchTagProps {\n data: any;\n matchLinks?: Record<string, string>;\n setPayload?: (payload: Record<string, any>) => void;\n}\n\nfunction MatchTag({ data, matchLinks, setPayload }: MatchTagProps) {\n if (!data || Object.keys(data).length === 0) return;\n\n if (data.lith_id || data?.type === \"lith\") {\n return h(\n \"div\",\n {\n onClick: () => {\n data.type === \"lith\"\n ? setPayload({ lith_id: data.id, name: data.name })\n : null;\n },\n },\n h(DataField, {\n className: \"match-item\",\n label: \"Stratigraphic name\",\n value: h(LithologyTag, {\n data: { name: data.name, id: data.id, color: data.color },\n onClick: () =>\n window.open(\n matchLinks.strat_name + \"/\" + data.strat_name_id,\n \"_blank\",\n ),\n }),\n }),\n );\n }\n\n if (data.strat_name_id || data?.type === \"strat_name\") {\n return h(\n \"div\",\n {\n onClick: () => {\n data.type === \"strat_name\"\n ? setPayload({ strat_name_id: data.id, name: data.name })\n : null;\n },\n },\n h(DataField, {\n className: \"match-item\",\n label: \"Stratigraphic name\",\n value: h(LithologyTag, {\n data: { name: data.name, id: data.id, color: data.color },\n onClick: () =>\n window.open(\n matchLinks.strat_name + \"/\" + data.strat_name_id,\n \"_blank\",\n ),\n }),\n }),\n );\n }\n\n if (data.lith_att_id || data?.type === \"lith_att\") {\n return h(\n \"div\",\n {\n onClick: () => {\n data.type === \"lith_att\"\n ? setPayload({ lith_att_id: data.id, name: data.name })\n : null;\n },\n },\n h(DataField, {\n className: \"match-item\",\n label: \"Lithology attribute\",\n value: h(LithologyTag, {\n data: { name: data.name, id: data.lith_att_id },\n onClick: () =>\n window.open(matchLinks.lith_att + \"/\" + data.lith_att_id, \"_blank\"),\n }),\n }),\n );\n }\n\n if (data.int_id || data?.type === \"interval\") {\n return h(\n \"div\",\n {\n onClick: () => {\n data.type === \"interval\"\n ? setPayload({ int_id: data.id, name: data.name })\n : null;\n },\n },\n h(DataField, {\n label: \"Interval\",\n className: \"match-item\",\n value: h(LithologyTag, {\n data: { name: data.name, id: data.id },\n onClick: () =>\n window.open(matchLinks.interval + \"/\" + data.int_id, \"_blank\"),\n }),\n }),\n );\n }\n\n return h(JSONView, { data });\n}\n"],"names":[],"version":3,"file":"feedback-components.e53837d9.js.map"}
@@ -80,7 +80,7 @@ export interface GraphData {
80
80
  }[];
81
81
  }
82
82
  export function treeToGraph(tree: TreeData[]): GraphData;
83
- export function FeedbackComponent({ entities, text, model, entityTypes, matchComponent, onSave, allowOverlap, matchLinks, }: {
83
+ export function FeedbackComponent({ entities, text, model, entityTypes, matchComponent, onSave, allowOverlap, matchLinks, view, }: {
84
84
  entities?: any[];
85
85
  text: any;
86
86
  model: any;
@@ -89,6 +89,7 @@ export function FeedbackComponent({ entities, text, model, entityTypes, matchCom
89
89
  onSave: any;
90
90
  allowOverlap: any;
91
91
  matchLinks: any;
92
+ view?: boolean;
92
93
  }): DOMElement<DOMAttributes<Element>, Element>;
93
94
 
94
95
  //# sourceMappingURL=index.d.ts.map