@macrostrat/feedback-components 1.1.4 → 1.1.6
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.
- package/CHANGELOG.md +9 -0
- package/dist/esm/{feedback-components.7e879290.js → feedback-components.03f08dc7.js} +10 -9
- package/dist/esm/feedback-components.03f08dc7.js.map +1 -0
- package/dist/esm/{feedback-components.f6605b83.js → feedback-components.3d7fd2df.js} +83 -46
- package/dist/esm/feedback-components.3d7fd2df.js.map +1 -0
- package/dist/esm/{feedback-components.204f7d2b.js → feedback-components.47b7bf19.js} +49 -21
- package/dist/esm/feedback-components.47b7bf19.js.map +1 -0
- package/dist/esm/{feedback-components.d591ffec.css → feedback-components.5a8f0185.css} +11 -5
- package/dist/esm/feedback-components.5a8f0185.css.map +1 -0
- package/dist/esm/{feedback-components.1c15f37f.js → feedback-components.63a12d32.js} +14 -97
- package/dist/esm/feedback-components.63a12d32.js.map +1 -0
- package/dist/esm/{feedback-components.00434ff7.js → feedback-components.7c2fe400.js} +7 -1
- package/dist/esm/feedback-components.7c2fe400.js.map +1 -0
- package/dist/esm/{feedback-components.fd8ac9ca.js → feedback-components.a451f964.js} +116 -98
- package/dist/esm/feedback-components.a451f964.js.map +1 -0
- package/dist/esm/{feedback-components.d55a1d18.js → feedback-components.e068f453.js} +5 -5
- package/dist/esm/{feedback-components.d55a1d18.js.map → feedback-components.e068f453.js.map} +1 -1
- package/dist/esm/{feedback-components.28ba71be.js → feedback-components.e4935bf3.js} +7 -7
- package/dist/esm/feedback-components.e4935bf3.js.map +1 -0
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/node/feedback-components.2ad7d057.js +2 -0
- package/dist/node/feedback-components.2ad7d057.js.map +1 -0
- package/dist/node/feedback-components.441e2203.js +2 -0
- package/dist/node/feedback-components.441e2203.js.map +1 -0
- package/dist/node/{feedback-components.2f740fc7.js → feedback-components.67e60839.js} +2 -2
- package/dist/node/{feedback-components.2f740fc7.js.map → feedback-components.67e60839.js.map} +1 -1
- package/dist/node/feedback-components.76ed75d8.js +2 -0
- package/dist/node/feedback-components.76ed75d8.js.map +1 -0
- package/dist/node/feedback-components.827f8d80.js +2 -0
- package/dist/node/feedback-components.827f8d80.js.map +1 -0
- package/dist/node/feedback-components.8caef76e.js +2 -0
- package/dist/node/feedback-components.8caef76e.js.map +1 -0
- package/dist/node/feedback-components.c31cf831.js +2 -0
- package/dist/node/feedback-components.c31cf831.js.map +1 -0
- package/dist/node/feedback-components.ce5efb18.js +2 -0
- package/dist/node/feedback-components.ce5efb18.js.map +1 -0
- package/dist/node/feedback-components.db4d0a14.css +2 -0
- package/dist/node/feedback-components.db4d0a14.css.map +1 -0
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +2 -2
- package/src/feedback/edit-state.ts +101 -49
- package/src/feedback/feedback.module.sass +9 -5
- package/src/feedback/graph.ts +5 -2
- package/src/feedback/index.ts +30 -4
- package/src/feedback/matches.ts +125 -87
- package/src/feedback/text-visualizer.ts +32 -86
- package/src/feedback/typelist.ts +13 -4
- package/dist/esm/feedback-components.00434ff7.js.map +0 -1
- package/dist/esm/feedback-components.1c15f37f.js.map +0 -1
- package/dist/esm/feedback-components.204f7d2b.js.map +0 -1
- package/dist/esm/feedback-components.28ba71be.js.map +0 -1
- package/dist/esm/feedback-components.7e879290.js.map +0 -1
- package/dist/esm/feedback-components.d591ffec.css.map +0 -1
- package/dist/esm/feedback-components.f6605b83.js.map +0 -1
- package/dist/esm/feedback-components.fd8ac9ca.js.map +0 -1
- package/dist/node/feedback-components.0eef8d0c.js +0 -2
- package/dist/node/feedback-components.0eef8d0c.js.map +0 -1
- package/dist/node/feedback-components.41db283a.js +0 -2
- package/dist/node/feedback-components.41db283a.js.map +0 -1
- package/dist/node/feedback-components.69d0ccd0.js +0 -2
- package/dist/node/feedback-components.69d0ccd0.js.map +0 -1
- package/dist/node/feedback-components.a7b43cfa.js +0 -2
- package/dist/node/feedback-components.a7b43cfa.js.map +0 -1
- package/dist/node/feedback-components.b9317f9c.js +0 -2
- package/dist/node/feedback-components.b9317f9c.js.map +0 -1
- package/dist/node/feedback-components.e096504e.css +0 -2
- package/dist/node/feedback-components.e096504e.css.map +0 -1
- package/dist/node/feedback-components.e140ac86.js +0 -2
- package/dist/node/feedback-components.e140ac86.js.map +0 -1
- package/dist/node/feedback-components.f8373b58.js +0 -2
- package/dist/node/feedback-components.f8373b58.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useReducer as e,createContext as t,useContext as n}from"react";import l from"immutability-helper";var r,d=((r={}).Tree="tree",r.Graph="graph",r);function i(t,n,l,r){let d=n.values().next().value;return e(s,{initialTree:t,tree:t,selectedNodes:[],entityTypesMap:n,selectedEntityType:d,lastInternalId:0,isSelectingEntityType:!1,viewMode:"tree",viewOnly:l,matchMode:r})}let a=t(null);function o(){let e=n(a);if(null==e)throw Error("No dispatch context available");return e}function s(e,t){if("toggle-match-mode"===t.type)return{...e,matchMode:!e.matchMode};if("toggle-view-only"===t.type)return{...e,viewOnly:!e.viewOnly};if(e.viewOnly){var n,r;return n=e,"set-view-mode"===(r=t).type?{...n,viewMode:r.payload}:n}if(e.matchMode)return function(e,t){if("select-node"===t.type||"toggle-node-selected"===t.type){let{ids:n}=t.payload;if(1!=n.length)return e;if(1===e.selectedNodes.length&&n[0]===e.selectedNodes[0])return{...e,selectedNodes:[]};let l=t.payload.ids.length>0?f(e.tree,n[0])?.type:null;return{...e,selectedNodes:n,selectedEntityType:l}}if("add-match"===t.type){let{id:n}=t.payload,r=p(e.tree,n);if(!r)return console.warn(`Node with id ${n} not found`),e;let d=c(r,{match:{$set:t.payload.payload}}),i=l(e.tree,d);return{...e,tree:i}}if("remove-match"===t.type){let{id:n}=t.payload;console.log("Removing match for node with id:",n);let r=p(e.tree,n);if(!r)return console.warn(`Node with id ${n} not found`),e;let d=c(r,{match:{$set:null}}),i=l(e.tree,d);return{...e,tree:i}}return e}(e,t);switch(t.type){case"add-entity-type":{let{name:n,description:l,color:r}=t.payload,d=e.lastInternalId-1,i={id:d,name:n,description:""===l?null:l,color:r},a=new Map(e.entityTypesMap);return a.set(d,i),{...e,entityTypesMap:a,selectedEntityType:i,lastInternalId:d}}case"update-entity-type":{let{id:n,name:l,description:r,color:d}=t.payload,i=new Map(e.entityTypesMap),a=i.get(n);if(!a)return console.warn(`Entity type with id ${n} not found`),e;let o={...a,name:l,description:""===r?null:r,color:d};i.set(n,o);let s=h(e.tree,a,o);return{...e,tree:s,entityTypesMap:i,selectedEntityType:o}}case"select-range":let d=t.payload.ids,i=d[0],a=d[1],o=function(e){let t=[];return!function e(n){for(let l of n)t.push(l),Array.isArray(l.children)&&l.children.length>0&&e(l.children)}(e),t.sort((e,t)=>e.indices[0]-t.indices[0])}(e.tree),s=o.findIndex(e=>e.id===i),u=o.findIndex(e=>e.id===a),g=o.slice(s,u+1);return console.log("Selecting range:",g),{...e,selectedNodes:g.map(e=>e.id)};case"move-node":let[m,T]=y(e.tree,t.payload.dragIds),$=[];t.payload.parentId&&($=p(m,t.payload.parentId)).push("children");let w=c($,{$splice:[[t.payload.index,0,...T]]});return{...e,tree:l(m,w)};case"delete-node":let[N,v]=y(e.tree,t.payload.ids),M=v.flatMap(e=>e.children??[]).filter(e=>!function e(t,n){for(let l of t)if(l.id==n)return!0;else if(l.children&&e(l.children,n))return!0;return!1}(N,e.id));return{...e,tree:[...N,...M],selectedNodes:e.selectedNodes.filter(e=>!t.payload.ids.includes(e))};case"select-node":let{ids:x}=t.payload,I=t.payload.ids.length>0?f(e.tree,x[0])?.type:null;return{...e,selectedNodes:x,selectedEntityType:I};case"toggle-node-selected":let E=t.payload.ids.filter(t=>!e.selectedNodes.includes(t)),b=e.selectedNodes.filter(e=>!t.payload.ids.includes(e)),O=t.payload.ids.length>0?f(e.tree,t.payload.ids[0])?.type:null;return{...e,selectedNodes:[...b,...E],selectedEntityType:O};case"create-node":let S=e.lastInternalId-1,{text:C,start:A,end:D}=t.payload,G={id:S,name:C,children:[],indices:[A,D],type:e.selectedEntityType};return{...e,tree:[...e.tree,G],selectedNodes:[S],lastInternalId:S};case"delete-entity-type":{let{id:n}=t.payload,l=new Map(e.entityTypesMap),r=l.get(n);l.delete(n);let d=l.values().next().value,i=h(e.tree,r,d);return{...e,tree:i,entityTypesMap:l,selectedNodes:[]}}case"toggle-entity-type-selector":return{...e,isSelectingEntityType:t.payload??!e.isSelectingEntityType};case"select-entity-type":{let n=e.tree;for(let r of e.selectedNodes)n=l(n,c(p(e.tree,r),{type:{$set:t.payload}}));return{...e,tree:n,selectedEntityType:t.payload}}case"deselect":return{...e,selectedNodes:[]};case"reset":return{...e,tree:e.initialTree,selectedNodes:[]};case"set-view-mode":return{...e,viewMode:t.payload}}}function c(e,t){let n=t;for(let t=e.length-1;t>=0;t--)n={[e[t]]:n};return n}function p(e,t){for(let n=0;n<e.length;n++)if(e[n].id==t)return[n];else if(e[n].children){let l=p(e[n].children,t);if(null!=l)return[n,"children",...l]}return null}function y(e,t){let n=[],l=[];for(let r of e)if(t.includes(r.id))l.push(r);else{if(r.children){let[e,n]=y(r.children,t);r={...r,children:e},l.push(...n)}n.push(r)}return[n,l]}function u(e){let t=[],n=[],l=new Map;for(let r of e){if(l.has(r.id))continue;let{indices:e,id:d,name:i,type:a,children:o}=r,s={id:d,type:a.id,color:a.color,name:i,txt_range:[e],reasoning:null,match:r.match,children:o};if(l.set(r.id,r),t.push(s),r.children){for(let e of r.children)n.push({source:r.id,dest:e.id});let{nodes:e,edges:l}=u(r.children);t.push(...e),n.push(...l)}}return{nodes:t,edges:n}}function f(e,t){for(let n of e){if(n.id===t)return n;if(n.children){let e=f(n.children,t);if(e)return e}}return null}function h(e,t,n){return e.map(e=>(function(e,t,n){let l=e.type.id===t.id?n:e.type;return{...e,type:l,children:e.children?h(e.children,t,n):[]}})(e,t,n))}export{d as ViewMode,i as useUpdatableTree,a as TreeDispatchContext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y,C,K,W","sources":["<anon>","packages/feedback-components/src/feedback/edit-state.ts"],"sourcesContent":["import {useReducer as $eGztG$useReducer, createContext as $eGztG$createContext, useContext as $eGztG$useContext} from \"react\";\nimport $eGztG$immutabilityhelper from \"immutability-helper\";\n\n\n\nvar $330ae695507d96f5$export$53ec42062883b2d4 = /*#__PURE__*/ function(ViewMode) {\n ViewMode[\"Tree\"] = \"tree\";\n ViewMode[\"Graph\"] = \"graph\";\n return ViewMode;\n}({});\nfunction $330ae695507d96f5$export$911bb4b9c8065d3d(initialTree, entityTypes, viewOnly, matchMode) {\n // Get the first entity type\n // issue: grabs second entity instead of selected one\n const type = entityTypes.values().next().value;\n return (0, $eGztG$useReducer)($330ae695507d96f5$var$treeReducer, {\n initialTree: initialTree,\n tree: initialTree,\n selectedNodes: [],\n entityTypesMap: entityTypes,\n selectedEntityType: type,\n lastInternalId: 0,\n isSelectingEntityType: false,\n viewMode: \"tree\",\n viewOnly: viewOnly,\n matchMode: matchMode\n });\n}\nconst $330ae695507d96f5$export$e5ce04c5b3f58533 = (0, $eGztG$createContext)(null);\nfunction $330ae695507d96f5$export$e1068f2d1c68f87e() {\n const dispatch = (0, $eGztG$useContext)($330ae695507d96f5$export$e5ce04c5b3f58533);\n if (dispatch == null) throw new Error(\"No dispatch context available\");\n return dispatch;\n}\nfunction $330ae695507d96f5$var$treeReducer(state, action) {\n if (action.type === \"toggle-match-mode\") return {\n ...state,\n matchMode: !state.matchMode\n };\n if (action.type === \"toggle-view-only\") return {\n ...state,\n viewOnly: !state.viewOnly\n };\n if (state.viewOnly) return $330ae695507d96f5$var$viewMode(state, action);\n if (state.matchMode) return $330ae695507d96f5$var$matchMode(state, action);\n switch(action.type){\n case \"add-entity-type\":\n {\n // Add a new entity type to the map\n const { name: name, description: description, color: color } = action.payload;\n const newId = state.lastInternalId - 1;\n const newType = {\n id: newId,\n name: name,\n description: description === \"\" ? null : description,\n color: color\n };\n const newEntityTypesMap = new Map(state.entityTypesMap);\n newEntityTypesMap.set(newId, newType);\n return {\n ...state,\n entityTypesMap: newEntityTypesMap,\n selectedEntityType: newType,\n lastInternalId: newId\n };\n }\n case \"update-entity-type\":\n {\n // Update an existing entity type in the map\n const { id: id, name: name, description: description, color: color } = action.payload;\n const newEntityTypesMap = new Map(state.entityTypesMap);\n const oldType = newEntityTypesMap.get(id);\n if (!oldType) {\n console.warn(`Entity type with id ${id} not found`);\n return state;\n }\n const updatedType = {\n ...oldType,\n name: name,\n description: description === \"\" ? null : description,\n color: color\n };\n newEntityTypesMap.set(id, updatedType);\n // Update the tree to reflect the new type\n const newTree = $330ae695507d96f5$var$updateTreeTypes(state.tree, oldType, updatedType);\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 // make list of nodes in order\n const allNodes = $330ae695507d96f5$var$flattenAndSort(state.tree);\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 const selectedNodes = allNodes.slice(startIndex, endIndex + 1);\n console.log(\"Selecting range:\", selectedNodes);\n return {\n ...state,\n selectedNodes: selectedNodes.map((node)=>node.id)\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] = $330ae695507d96f5$var$removeNodes(state.tree, action.payload.dragIds);\n let keyPath = [];\n if (action.payload.parentId) {\n keyPath = $330ae695507d96f5$var$findNode(newTree, action.payload.parentId);\n keyPath.push(\"children\");\n }\n // Add removed nodes to the new tree at the correct location\n let updateSpec = $330ae695507d96f5$var$buildNestedSpec(keyPath, {\n $splice: [\n [\n action.payload.index,\n 0,\n ...removedNodes\n ]\n ]\n });\n return {\n ...state,\n tree: (0, $eGztG$immutabilityhelper)(newTree, updateSpec)\n };\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] = $330ae695507d96f5$var$removeNodes(state.tree, action.payload.ids);\n // Get children of the removed nodes\n // If children are not present elsewhere in the tree, insert them\n const children = _removedNodes.flatMap((node)=>node.children ?? []).filter((child)=>!$330ae695507d96f5$var$nodeIsInTree(newTree2, child.id));\n // Reset the selection\n return {\n ...state,\n tree: [\n ...newTree2,\n ...children\n ],\n selectedNodes: state.selectedNodes.filter((id)=>!action.payload.ids.includes(id))\n };\n case \"select-node\":\n const { ids: ids } = action.payload;\n const type = action.payload.ids.length > 0 ? $330ae695507d96f5$export$e64eb58334357825(state.tree, ids[0])?.type : null;\n return {\n ...state,\n selectedNodes: ids,\n selectedEntityType: type\n };\n // otherwise fall through to toggle-node-selected for a single ID\n case \"toggle-node-selected\":\n const nodesToAdd = action.payload.ids.filter((id)=>!state.selectedNodes.includes(id));\n const nodesToKeep = state.selectedNodes.filter((id)=>!action.payload.ids.includes(id));\n const newType = action.payload.ids.length > 0 ? $330ae695507d96f5$export$e64eb58334357825(state.tree, action.payload.ids[0])?.type : null;\n return {\n ...state,\n selectedNodes: [\n ...nodesToKeep,\n ...nodesToAdd\n ],\n selectedEntityType: newType\n };\n case \"create-node\":\n const newId = state.lastInternalId - 1;\n const { text: text, start: start, end: end } = action.payload;\n const node = {\n id: newId,\n name: text,\n children: [],\n indices: [\n start,\n end\n ],\n type: state.selectedEntityType\n };\n return {\n ...state,\n tree: [\n ...state.tree,\n node\n ],\n selectedNodes: [\n newId\n ],\n lastInternalId: newId\n };\n case \"delete-entity-type\":\n {\n // Remove the entity type from the map\n const { id: id } = action.payload;\n const newEntityTypesMap = new Map(state.entityTypesMap);\n const oldType = newEntityTypesMap.get(id);\n newEntityTypesMap.delete(id);\n const defaultType = newEntityTypesMap.values().next().value;\n const newTree = $330ae695507d96f5$var$updateTreeTypes(state.tree, oldType, defaultType);\n return {\n ...state,\n tree: newTree,\n entityTypesMap: newEntityTypesMap,\n selectedNodes: []\n };\n }\n /** Entity type selection */ case \"toggle-entity-type-selector\":\n return {\n ...state,\n isSelectingEntityType: action.payload ?? !state.isSelectingEntityType\n };\n case \"select-entity-type\":\n {\n // For each selected node, update the type\n let newTree2 = state.tree;\n for (let id of state.selectedNodes){\n const keyPath = $330ae695507d96f5$var$findNode(state.tree, id);\n const nestedSpec = $330ae695507d96f5$var$buildNestedSpec(keyPath, {\n type: {\n $set: action.payload\n }\n });\n newTree2 = (0, $eGztG$immutabilityhelper)(newTree2, nestedSpec);\n }\n return {\n ...state,\n tree: newTree2,\n selectedEntityType: action.payload\n };\n }\n case \"deselect\":\n return {\n ...state,\n selectedNodes: []\n };\n case \"reset\":\n return {\n ...state,\n tree: state.initialTree,\n selectedNodes: []\n };\n case \"set-view-mode\":\n return {\n ...state,\n viewMode: action.payload\n };\n }\n}\nfunction $330ae695507d96f5$var$nodeIsInTree(tree, id) {\n for (let node of tree){\n if (node.id == id) return true;\n else if (node.children) {\n if ($330ae695507d96f5$var$nodeIsInTree(node.children, id)) return true;\n }\n }\n return false;\n}\nfunction $330ae695507d96f5$var$buildNestedSpec(keyPath, innerSpec) {\n // Build a nested object from a key path\n let spec = innerSpec;\n for(let i = keyPath.length - 1; i >= 0; i--)spec = {\n [keyPath[i]]: spec\n };\n return spec;\n// Since we don't have a \"children\" key at the root, we make the top-level spec an array\n}\nfunction $330ae695507d96f5$var$findNode(tree, id) {\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) return [\n i\n ];\n else if (tree[i].children) {\n let path = $330ae695507d96f5$var$findNode(tree[i].children, id);\n if (path != null) return [\n i,\n \"children\",\n ...path\n ];\n }\n }\n return null;\n}\nfunction $330ae695507d96f5$var$removeNodes(tree, ids) {\n /** Remove nodes with the given ids from the tree and return the new tree and the removed nodes */ let newTree = [];\n let removedNodes = [];\n for (let node of tree)if (ids.includes(node.id)) removedNodes.push(node);\n else {\n // Recurse into children\n if (node.children) {\n let [newChildren, removedChildren] = $330ae695507d96f5$var$removeNodes(node.children, ids);\n node = {\n ...node,\n children: newChildren\n };\n removedNodes.push(...removedChildren);\n }\n newTree.push(node);\n }\n return [\n newTree,\n removedNodes\n ];\n}\nfunction $330ae695507d96f5$export$8d9dbb7a64bf2a5e(tree) {\n // Convert the tree to a graph\n let nodes = [];\n let edges = [];\n const nodeMap = new Map();\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)) continue;\n const { indices: indices, id: id, name: name, type: type, children: children } = node;\n const nodeData = {\n id: id,\n type: type.id,\n color: type.color,\n name: name,\n txt_range: [\n indices\n ],\n reasoning: null,\n match: node.match,\n children: children\n };\n nodeMap.set(node.id, node);\n nodes.push(nodeData);\n if (node.children) {\n for (let child of node.children)edges.push({\n source: node.id,\n dest: child.id\n });\n // Now process the children\n const { nodes: childNodes, edges: childEdges } = $330ae695507d96f5$export$8d9dbb7a64bf2a5e(node.children);\n nodes.push(...childNodes);\n edges.push(...childEdges);\n }\n }\n return {\n nodes: nodes,\n edges: edges\n };\n}\nfunction $330ae695507d96f5$export$e64eb58334357825(tree, id) {\n for (const node of tree){\n if (node.id === id) return node;\n if (node.children) {\n const found = $330ae695507d96f5$export$e64eb58334357825(node.children, id);\n if (found) return found;\n }\n }\n return null;\n}\nfunction $330ae695507d96f5$var$updateTreeTypes(tree, oldType, defaultType) {\n return tree.map((node)=>$330ae695507d96f5$var$updateNodeType(node, oldType, defaultType));\n}\nfunction $330ae695507d96f5$var$updateNodeType(node, oldType, defaultType) {\n const type = node.type.id === oldType.id ? defaultType : node.type;\n return {\n ...node,\n type: type,\n children: node.children ? $330ae695507d96f5$var$updateTreeTypes(node.children, oldType, defaultType) : []\n };\n}\nfunction $330ae695507d96f5$var$flattenAndSort(nodes) {\n const result = [];\n function traverse(nodeList) {\n for (const node of nodeList){\n result.push(node);\n if (Array.isArray(node.children) && node.children.length > 0) traverse(node.children);\n }\n }\n traverse(nodes);\n // sort by start\n return result.sort((a, b)=>a.indices[0] - b.indices[0]);\n}\nfunction $330ae695507d96f5$var$matchMode(state, action) {\n if (action.type === \"select-node\" || action.type === \"toggle-node-selected\") {\n const { ids: ids } = action.payload;\n if (ids.length != 1) return state;\n if (state.selectedNodes.length === 1) {\n if (ids[0] === state.selectedNodes[0]) // If the selected node is the same as the current selection, deselect it\n return {\n ...state,\n selectedNodes: []\n };\n }\n const type = action.payload.ids.length > 0 ? $330ae695507d96f5$export$e64eb58334357825(state.tree, ids[0])?.type : null;\n return {\n ...state,\n selectedNodes: ids,\n selectedEntityType: type\n };\n }\n if (action.type === \"add-match\") {\n const { id: id } = action.payload;\n // Find the node path\n const keyPath = $330ae695507d96f5$var$findNode(state.tree, id);\n if (!keyPath) {\n console.warn(`Node with id ${id} not found`);\n return state;\n }\n // Build update spec to set the `match` property\n const matchUpdateSpec = $330ae695507d96f5$var$buildNestedSpec(keyPath, {\n match: {\n $set: action.payload.payload\n }\n });\n const updatedTree = (0, $eGztG$immutabilityhelper)(state.tree, matchUpdateSpec);\n return {\n ...state,\n tree: updatedTree\n };\n }\n if (action.type === \"remove-match\") {\n const { id: id } = action.payload;\n console.log(\"Removing match for node with id:\", id);\n // Find the node path\n const keyPath = $330ae695507d96f5$var$findNode(state.tree, id);\n if (!keyPath) {\n console.warn(`Node with id ${id} not found`);\n return state;\n }\n // Build update spec to unset the `match` property\n const matchUpdateSpec = $330ae695507d96f5$var$buildNestedSpec(keyPath, {\n match: {\n $set: null\n }\n });\n const updatedTree = (0, $eGztG$immutabilityhelper)(state.tree, matchUpdateSpec);\n return {\n ...state,\n tree: updatedTree\n };\n }\n return state;\n}\nfunction $330ae695507d96f5$var$viewMode(state, action) {\n if (action.type === \"set-view-mode\") return {\n ...state,\n viewMode: action.payload\n };\n return state;\n}\n\n\nexport {$330ae695507d96f5$export$53ec42062883b2d4 as ViewMode, $330ae695507d96f5$export$911bb4b9c8065d3d as useUpdatableTree, $330ae695507d96f5$export$e5ce04c5b3f58533 as TreeDispatchContext, $330ae695507d96f5$export$e1068f2d1c68f87e as useTreeDispatch, $330ae695507d96f5$export$e64eb58334357825 as findNodeById, $330ae695507d96f5$export$8d9dbb7a64bf2a5e as treeToGraph};\n//# sourceMappingURL=feedback-components.8caef76e.js.map\n","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 | { type: \"toggle-view-only\" };\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 (action.type === \"toggle-view-only\") {\n return { ...state, viewOnly: !state.viewOnly };\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":["useReducer","$eGztG$useReducer","createContext","$eGztG$createContext","useContext","$eGztG$useContext","$eGztG$immutabilityhelper","ViewMode","$330ae695507d96f5$export$53ec42062883b2d4","$330ae695507d96f5$export$911bb4b9c8065d3d","initialTree","entityTypes","viewOnly","matchMode","type","values","next","value","$330ae695507d96f5$var$treeReducer","tree","selectedNodes","entityTypesMap","selectedEntityType","lastInternalId","isSelectingEntityType","viewMode","$330ae695507d96f5$export$e5ce04c5b3f58533","$330ae695507d96f5$export$e1068f2d1c68f87e","dispatch","Error","state","action","payload","$330ae695507d96f5$var$matchMode","ids","length","$330ae695507d96f5$export$e64eb58334357825","id","keyPath","$330ae695507d96f5$var$findNode","console","warn","matchUpdateSpec","$330ae695507d96f5$var$buildNestedSpec","match","$set","updatedTree","log","name","description","color","newId","newType","newEntityTypesMap","Map","set","oldType","get","updatedType","newTree","$330ae695507d96f5$var$updateTreeTypes","payloadIds","node1","node2","allNodes","$330ae695507d96f5$var$flattenAndSort","nodes","result","traverse","nodeList","node","push","Array","isArray","children","sort","a","b","indices","startIndex","findIndex","endIndex","slice","map","removedNodes","$330ae695507d96f5$var$removeNodes","dragIds","parentId","updateSpec","$splice","index","newTree2","_removedNodes","flatMap","filter","child","$330ae695507d96f5$var$nodeIsInTree","includes","nodesToAdd","nodesToKeep","text","start","end","delete","defaultType","innerSpec","spec","i","path","newChildren","removedChildren","$330ae695507d96f5$export$8d9dbb7a64bf2a5e","edges","nodeMap","has","nodeData","txt_range","reasoning","source","dest","childNodes","childEdges","found","$330ae695507d96f5$var$updateNodeType","useUpdatableTree","TreeDispatchContext","useTreeDispatch","findNodeById","treeToGraph"],"version":3,"file":"feedback-components.8caef76e.js.map","sourceRoot":"../../../../"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e,t,o,a){Object.defineProperty(e,t,{get:o,set:a,enumerable:!0,configurable:!0})}var t,o,a,n,c,l,r,i,p,Q,W,X,_,d,b,s,y,f,m,g,h,k,u,x,v,w,$,j,O,P={};e(P,"add-type",()=>t,e=>t=e),e(P,"add-type-overlay",()=>o,e=>o=e),e(P,"clickable",()=>a,e=>a=e),e(P,"close-btn",()=>n,e=>n=e),e(P,"control-content",()=>c,e=>c=e),e(P,"control-panel",()=>l,e=>l=e),e(P,"description",()=>r,e=>r=e),e(P,"entity-panel",()=>i,e=>i=e),e(P,"feedback-component",()=>p,e=>p=e),e(P,"feedback-container",()=>Q,e=>Q=e),e(P,"feedback-text",()=>W,e=>W=e),e(P,"feedback-text-wrapper",()=>X,e=>X=e),e(P,"form-group",()=>_,e=>_=e),e(P,"highlight",()=>d,e=>d=e),e(P,"icons",()=>b,e=>b=e),e(P,"match-container",()=>s,e=>s=e),e(P,"match-item",()=>y,e=>y=e),e(P,"match-label",()=>f,e=>f=e),e(P,"node",()=>m,e=>m=e),e(P,"node-label",()=>g,e=>g=e),e(P,"overlay-container",()=>h,e=>h=e),e(P,"page-wrapper",()=>k,e=>k=e),e(P,"selected",()=>u,e=>u=e),e(P,"selection-tree",()=>x,e=>x=e),e(P,"text-inputs",()=>v,e=>v=e),e(P,"title",()=>w,e=>w=e),e(P,"type-container",()=>$,e=>$=e),e(P,"type-list",()=>j,e=>j=e),e(P,"type-tag",()=>O,e=>O=e),t="QoX8-W_add-type",o="QoX8-W_add-type-overlay",a="QoX8-W_clickable",n="QoX8-W_close-btn",c="QoX8-W_control-content",l="QoX8-W_control-panel",r="QoX8-W_description",i="QoX8-W_entity-panel",p="QoX8-W_feedback-component",Q="QoX8-W_feedback-container",W="QoX8-W_feedback-text",X="QoX8-W_feedback-text-wrapper",_="QoX8-W_form-group",d="QoX8-W_highlight",b="QoX8-W_icons",s="QoX8-W_match-container",y="QoX8-W_match-item",f="QoX8-W_match-label",m="QoX8-W_node",g="QoX8-W_node-label",h="QoX8-W_overlay-container",k="QoX8-W_page-wrapper",u="QoX8-W_selected",x="QoX8-W_selection-tree",v="QoX8-W_text-inputs",w="QoX8-W_title",$="QoX8-W_type-container",j="QoX8-W_type-list",O="QoX8-W_type-tag";export{P as default};
|
|
2
|
+
//# sourceMappingURL=feedback-components.c31cf831.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"A,S,E,C,C,C,C,C,C,C,E,O,c,C,E,E,C,I,E,I,E,W,C,E,a,C,C,E,C,ICAA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,EACA,E,E,C,E,E,E,W,I,E,A,G,E,G,E,E,mB,I,E,A,G,E,G,E,E,Y,I,E,A,G,E,G,E,E,Y,I,E,A,G,E,G,E,E,kB,I,E,A,G,E,G,E,E,gB,I,E,A,G,E,G,E,E,c,I,E,A,G,E,G,E,E,e,I,E,A,G,E,G,E,E,qB,I,E,A,G,E,G,E,E,qB,I,E,A,G,E,G,E,E,gB,I,E,A,G,E,G,E,E,wB,I,E,A,G,E,G,E,E,a,I,E,A,G,E,G,E,E,Y,I,E,A,G,E,G,E,E,Q,I,E,A,G,E,G,E,E,kB,I,E,A,G,E,G,E,E,a,I,E,A,G,E,G,E,E,c,I,E,A,G,E,G,E,E,O,I,E,A,G,E,G,E,E,a,I,E,A,G,E,G,E,E,oB,I,E,A,G,E,G,E,E,e,I,E,A,G,E,G,E,E,W,I,E,A,G,E,G,E,E,iB,I,E,A,G,E,G,E,E,c,I,E,A,G,E,G,E,E,Q,I,E,A,G,E,G,E,E,iB,I,E,A,G,E,G,E,E,Y,I,E,A,G,E,G,E,E,W,I,E,A,G,E,GA5BA,EAA6B,kBAC7B,EAAqC,0BACrC,EAA8B,mBAC9B,EAA8B,mBAC9B,EAAoC,yBACpC,EAAkC,uBAClC,EAAgC,qBAChC,EAAiC,sBACjC,EAAuC,4BACvC,EAAuC,4BACvC,EAAkC,uBAClC,EAA0C,+BAC1C,EAA+B,oBAC/B,EAA8B,mBAC9B,EAA0B,eAC1B,EAAoC,yBACpC,EAA+B,oBAC/B,EAAgC,qBAChC,EAAyB,cACzB,EAA+B,oBAC/B,EAAsC,2BACtC,EAAiC,sBACjC,EAA6B,kBAC7B,EAAmC,wBACnC,EAAgC,qBAChC,EAA0B,eAC1B,EAAmC,wBACnC,EAA8B,mBAC9B,EAA6B,yB,K,O","sources":["<anon>","packages/feedback-components/src/feedback/feedback.module.sass"],"sourcesContent":["\nfunction $parcel$export(e, n, v, s) {\n Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});\n}\nvar $01ca2f1f49a3a114$exports = {};\n\n$parcel$export($01ca2f1f49a3a114$exports, \"add-type\", () => $01ca2f1f49a3a114$export$cb889aaddfa2926c, (v) => $01ca2f1f49a3a114$export$cb889aaddfa2926c = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"add-type-overlay\", () => $01ca2f1f49a3a114$export$5f8f750fd71deeed, (v) => $01ca2f1f49a3a114$export$5f8f750fd71deeed = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"clickable\", () => $01ca2f1f49a3a114$export$60d5655c6babb2a0, (v) => $01ca2f1f49a3a114$export$60d5655c6babb2a0 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"close-btn\", () => $01ca2f1f49a3a114$export$f5032a039312e50b, (v) => $01ca2f1f49a3a114$export$f5032a039312e50b = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"control-content\", () => $01ca2f1f49a3a114$export$42e8b5293e69631e, (v) => $01ca2f1f49a3a114$export$42e8b5293e69631e = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"control-panel\", () => $01ca2f1f49a3a114$export$a0a23f31d5562853, (v) => $01ca2f1f49a3a114$export$a0a23f31d5562853 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"description\", () => $01ca2f1f49a3a114$export$6d59db4903f20f7d, (v) => $01ca2f1f49a3a114$export$6d59db4903f20f7d = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"entity-panel\", () => $01ca2f1f49a3a114$export$38f2cd12e45697e, (v) => $01ca2f1f49a3a114$export$38f2cd12e45697e = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"feedback-component\", () => $01ca2f1f49a3a114$export$579bd45c78bf5510, (v) => $01ca2f1f49a3a114$export$579bd45c78bf5510 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"feedback-container\", () => $01ca2f1f49a3a114$export$23889d205b405f6e, (v) => $01ca2f1f49a3a114$export$23889d205b405f6e = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"feedback-text\", () => $01ca2f1f49a3a114$export$890489be1870bed5, (v) => $01ca2f1f49a3a114$export$890489be1870bed5 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"feedback-text-wrapper\", () => $01ca2f1f49a3a114$export$6bd0fd0a746c88f, (v) => $01ca2f1f49a3a114$export$6bd0fd0a746c88f = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"form-group\", () => $01ca2f1f49a3a114$export$55a1f87a143fb302, (v) => $01ca2f1f49a3a114$export$55a1f87a143fb302 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"highlight\", () => $01ca2f1f49a3a114$export$e4043f67d36cbb26, (v) => $01ca2f1f49a3a114$export$e4043f67d36cbb26 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"icons\", () => $01ca2f1f49a3a114$export$df03f54e09e486fa, (v) => $01ca2f1f49a3a114$export$df03f54e09e486fa = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"match-container\", () => $01ca2f1f49a3a114$export$864d1dadc1dd3f57, (v) => $01ca2f1f49a3a114$export$864d1dadc1dd3f57 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"match-item\", () => $01ca2f1f49a3a114$export$a7bcc8ced81f8d07, (v) => $01ca2f1f49a3a114$export$a7bcc8ced81f8d07 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"match-label\", () => $01ca2f1f49a3a114$export$be49c8f7a120829f, (v) => $01ca2f1f49a3a114$export$be49c8f7a120829f = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"node\", () => $01ca2f1f49a3a114$export$35059013cd4a06db, (v) => $01ca2f1f49a3a114$export$35059013cd4a06db = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"node-label\", () => $01ca2f1f49a3a114$export$75d14899fb692bb6, (v) => $01ca2f1f49a3a114$export$75d14899fb692bb6 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"overlay-container\", () => $01ca2f1f49a3a114$export$6a1093e41947f68e, (v) => $01ca2f1f49a3a114$export$6a1093e41947f68e = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"page-wrapper\", () => $01ca2f1f49a3a114$export$7c414e944018fb15, (v) => $01ca2f1f49a3a114$export$7c414e944018fb15 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"selected\", () => $01ca2f1f49a3a114$export$d90250155de6d7e7, (v) => $01ca2f1f49a3a114$export$d90250155de6d7e7 = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"selection-tree\", () => $01ca2f1f49a3a114$export$3ae1b51693c80a9c, (v) => $01ca2f1f49a3a114$export$3ae1b51693c80a9c = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"text-inputs\", () => $01ca2f1f49a3a114$export$bc7581b048bdc9d, (v) => $01ca2f1f49a3a114$export$bc7581b048bdc9d = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"title\", () => $01ca2f1f49a3a114$export$fb184b623420d9be, (v) => $01ca2f1f49a3a114$export$fb184b623420d9be = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"type-container\", () => $01ca2f1f49a3a114$export$b2d17fca990bb66c, (v) => $01ca2f1f49a3a114$export$b2d17fca990bb66c = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"type-list\", () => $01ca2f1f49a3a114$export$915fe2ca68846e4c, (v) => $01ca2f1f49a3a114$export$915fe2ca68846e4c = v);\n$parcel$export($01ca2f1f49a3a114$exports, \"type-tag\", () => $01ca2f1f49a3a114$export$5e5acbc770fb0e4, (v) => $01ca2f1f49a3a114$export$5e5acbc770fb0e4 = v);\nvar $01ca2f1f49a3a114$export$cb889aaddfa2926c;\nvar $01ca2f1f49a3a114$export$5f8f750fd71deeed;\nvar $01ca2f1f49a3a114$export$60d5655c6babb2a0;\nvar $01ca2f1f49a3a114$export$f5032a039312e50b;\nvar $01ca2f1f49a3a114$export$42e8b5293e69631e;\nvar $01ca2f1f49a3a114$export$a0a23f31d5562853;\nvar $01ca2f1f49a3a114$export$6d59db4903f20f7d;\nvar $01ca2f1f49a3a114$export$38f2cd12e45697e;\nvar $01ca2f1f49a3a114$export$579bd45c78bf5510;\nvar $01ca2f1f49a3a114$export$23889d205b405f6e;\nvar $01ca2f1f49a3a114$export$890489be1870bed5;\nvar $01ca2f1f49a3a114$export$6bd0fd0a746c88f;\nvar $01ca2f1f49a3a114$export$55a1f87a143fb302;\nvar $01ca2f1f49a3a114$export$e4043f67d36cbb26;\nvar $01ca2f1f49a3a114$export$df03f54e09e486fa;\nvar $01ca2f1f49a3a114$export$864d1dadc1dd3f57;\nvar $01ca2f1f49a3a114$export$a7bcc8ced81f8d07;\nvar $01ca2f1f49a3a114$export$be49c8f7a120829f;\nvar $01ca2f1f49a3a114$export$35059013cd4a06db;\nvar $01ca2f1f49a3a114$export$75d14899fb692bb6;\nvar $01ca2f1f49a3a114$export$6a1093e41947f68e;\nvar $01ca2f1f49a3a114$export$7c414e944018fb15;\nvar $01ca2f1f49a3a114$export$d90250155de6d7e7;\nvar $01ca2f1f49a3a114$export$3ae1b51693c80a9c;\nvar $01ca2f1f49a3a114$export$bc7581b048bdc9d;\nvar $01ca2f1f49a3a114$export$fb184b623420d9be;\nvar $01ca2f1f49a3a114$export$b2d17fca990bb66c;\nvar $01ca2f1f49a3a114$export$915fe2ca68846e4c;\nvar $01ca2f1f49a3a114$export$5e5acbc770fb0e4;\n$01ca2f1f49a3a114$export$cb889aaddfa2926c = `QoX8-W_add-type`;\n$01ca2f1f49a3a114$export$5f8f750fd71deeed = `QoX8-W_add-type-overlay`;\n$01ca2f1f49a3a114$export$60d5655c6babb2a0 = `QoX8-W_clickable`;\n$01ca2f1f49a3a114$export$f5032a039312e50b = `QoX8-W_close-btn`;\n$01ca2f1f49a3a114$export$42e8b5293e69631e = `QoX8-W_control-content`;\n$01ca2f1f49a3a114$export$a0a23f31d5562853 = `QoX8-W_control-panel`;\n$01ca2f1f49a3a114$export$6d59db4903f20f7d = `QoX8-W_description`;\n$01ca2f1f49a3a114$export$38f2cd12e45697e = `QoX8-W_entity-panel`;\n$01ca2f1f49a3a114$export$579bd45c78bf5510 = `QoX8-W_feedback-component`;\n$01ca2f1f49a3a114$export$23889d205b405f6e = `QoX8-W_feedback-container`;\n$01ca2f1f49a3a114$export$890489be1870bed5 = `QoX8-W_feedback-text`;\n$01ca2f1f49a3a114$export$6bd0fd0a746c88f = `QoX8-W_feedback-text-wrapper`;\n$01ca2f1f49a3a114$export$55a1f87a143fb302 = `QoX8-W_form-group`;\n$01ca2f1f49a3a114$export$e4043f67d36cbb26 = `QoX8-W_highlight`;\n$01ca2f1f49a3a114$export$df03f54e09e486fa = `QoX8-W_icons`;\n$01ca2f1f49a3a114$export$864d1dadc1dd3f57 = `QoX8-W_match-container`;\n$01ca2f1f49a3a114$export$a7bcc8ced81f8d07 = `QoX8-W_match-item`;\n$01ca2f1f49a3a114$export$be49c8f7a120829f = `QoX8-W_match-label`;\n$01ca2f1f49a3a114$export$35059013cd4a06db = `QoX8-W_node`;\n$01ca2f1f49a3a114$export$75d14899fb692bb6 = `QoX8-W_node-label`;\n$01ca2f1f49a3a114$export$6a1093e41947f68e = `QoX8-W_overlay-container`;\n$01ca2f1f49a3a114$export$7c414e944018fb15 = `QoX8-W_page-wrapper`;\n$01ca2f1f49a3a114$export$d90250155de6d7e7 = `QoX8-W_selected`;\n$01ca2f1f49a3a114$export$3ae1b51693c80a9c = `QoX8-W_selection-tree`;\n$01ca2f1f49a3a114$export$bc7581b048bdc9d = `QoX8-W_text-inputs`;\n$01ca2f1f49a3a114$export$fb184b623420d9be = `QoX8-W_title`;\n$01ca2f1f49a3a114$export$b2d17fca990bb66c = `QoX8-W_type-container`;\n$01ca2f1f49a3a114$export$915fe2ca68846e4c = `QoX8-W_type-list`;\n$01ca2f1f49a3a114$export$5e5acbc770fb0e4 = `QoX8-W_type-tag`;\n\n\nexport {$01ca2f1f49a3a114$exports as default};\n//# sourceMappingURL=feedback-components.c31cf831.js.map\n",null],"names":["$parcel$export","e","n","v","s","Object","defineProperty","get","set","enumerable","configurable","$01ca2f1f49a3a114$export$cb889aaddfa2926c","$01ca2f1f49a3a114$export$5f8f750fd71deeed","$01ca2f1f49a3a114$export$60d5655c6babb2a0","$01ca2f1f49a3a114$export$f5032a039312e50b","$01ca2f1f49a3a114$export$42e8b5293e69631e","$01ca2f1f49a3a114$export$a0a23f31d5562853","$01ca2f1f49a3a114$export$6d59db4903f20f7d","$01ca2f1f49a3a114$export$38f2cd12e45697e","$01ca2f1f49a3a114$export$579bd45c78bf5510","$01ca2f1f49a3a114$export$23889d205b405f6e","$01ca2f1f49a3a114$export$890489be1870bed5","$01ca2f1f49a3a114$export$6bd0fd0a746c88f","$01ca2f1f49a3a114$export$55a1f87a143fb302","$01ca2f1f49a3a114$export$e4043f67d36cbb26","$01ca2f1f49a3a114$export$df03f54e09e486fa","$01ca2f1f49a3a114$export$864d1dadc1dd3f57","$01ca2f1f49a3a114$export$a7bcc8ced81f8d07","$01ca2f1f49a3a114$export$be49c8f7a120829f","$01ca2f1f49a3a114$export$35059013cd4a06db","$01ca2f1f49a3a114$export$75d14899fb692bb6","$01ca2f1f49a3a114$export$6a1093e41947f68e","$01ca2f1f49a3a114$export$7c414e944018fb15","$01ca2f1f49a3a114$export$d90250155de6d7e7","$01ca2f1f49a3a114$export$3ae1b51693c80a9c","$01ca2f1f49a3a114$export$bc7581b048bdc9d","$01ca2f1f49a3a114$export$fb184b623420d9be","$01ca2f1f49a3a114$export$b2d17fca990bb66c","$01ca2f1f49a3a114$export$915fe2ca68846e4c","$01ca2f1f49a3a114$export$5e5acbc770fb0e4","$01ca2f1f49a3a114$exports","default"],"version":3,"file":"feedback-components.c31cf831.js.map","sourceRoot":"../../../../"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import"./feedback-components.8caef76e.js";import"./feedback-components.c31cf831.js";import"./feedback-components.b22d37d1.js";import e from"@macrostrat/hyper";import{forceSimulation as r,forceLink as t,forceManyBody as o,forceCenter as a,forceCollide as i}from"d3-force";import{useState as l,useEffect as s}from"react";import{Spinner as c,Switch as n}from"@blueprintjs/core";import{ErrorBoundary as d}from"@macrostrat/ui-components";var p=globalThis,h={},g={},f=p.parcelRequirea149;null==f&&((f=function(e){if(e in h)return h[e].exports;if(e in g){var r=g[e];delete g[e];var t={id:e,exports:{}};return h[e]=t,r.call(t.exports,t,t.exports),t.exports}var o=Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,r){g[e]=r},p.parcelRequirea149=f),f.register;var u=f("eedTh"),m=f("9wFEx"),y=f("edvRb");let b=e.styled(m&&m.__esModule?m.default:m);function k(e){let{tree:p,width:h,height:g,dispatch:f,selectedNodes:m,viewOnly:k}=e,[x,w]=l(null),[v,S]=l(null),[_,E]=l(!1);return(s(()=>{let{nodes:e,edges:l}=(0,u.treeToGraph)(p),s=new Map(e.map(e=>[e.id,e])),c=l.map(e=>({source:s.get(e.source),target:s.get(e.dest),strength:1})),n=r(e).force("link",t(c)).force("charge",o().strength(-50)).force("center",a(h/2,g/2)).force("collide",i().radius(20)).on("tick",()=>{console.log("Simulation tick")}).on("end",()=>{w(e),S(c)});return()=>{n.stop()}},[p,h,g]),null==x||null==v)?b(c):(console.log("Graph",x,v,m),b(d,{description:"An error occurred while rendering the graph view."},b("div.graph-view",{style:{width:h,height:g}},[b(n,{className:"show-labels-switch",label:"Show Labels",checked:_,onChange:e=>E(e.target.checked)}),b("svg",{width:h,height:g},[b("g.links",v.map(e=>b("line",{x1:e.source.x,y1:e.source.y,x2:e.target.x,y2:e.target.y,stroke:"black"}))),b("g.nodes",x.map(e=>{var r,t,o;let a=m.includes(e.id),i=(r=e.id,t=m,o=x,0===t.length||t.includes(r)||o.some(e=>t.includes(e.id)&&e.children.some(e=>e.id===r))),l=(0,y.getTagStyle)(e.color,{highlighted:i,active:a});return b("g",[b("circle",{cx:e.x,cy:e.y,r:8,fill:l.backgroundColor||"blue",onClick:r=>{r.stopPropagation(),r.ctrlKey||r.metaKey||m[0]===e.id&&1===m.length?(r.stopPropagation(),f({type:"toggle-node-selected",payload:{ids:[e.id]}})):f({type:"select-node",payload:{ids:[e.id]}})},className:a?"selected":k?"":" clickable",stroke:a?"white":"black",strokeWidth:2}),b.if(_)("text",{x:e.x+10,y:e.y+4,className:"node-label"},e.name||`Node ${e.id}`),b.if(!_)("title",e.name||`Node ${e.id}`)])}))])])))}export{k as GraphView};
|
|
2
|
+
//# sourceMappingURL=feedback-components.ce5efb18.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"A,M,oD,A,O,oD,A,O,oD,A,Q,M,mB,A,Q,mB,C,C,a,C,C,iB,C,C,e,C,C,gB,C,K,U,A,Q,Y,C,C,a,C,K,O,A,Q,W,C,C,U,C,K,mB,A,Q,iB,C,K,2B,C,I,E,W,E,C,E,E,C,E,E,E,iB,A,O,I,A,C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AAO,EAAE,IAAK,CACZ,EAAE,SAAU,CACV,GAAI,EAAE,CAAC,CACP,GAAI,EAAE,CAAC,CACP,EAAG,EACH,KAAM,EAAM,eAAe,EAAI,OAC/B,QAAS,AAAC,IACR,EAAE,eAAe,GAEf,EAAE,OAAO,EACT,EAAE,OAAO,EACR,CAAa,CAAC,EAAE,GAAK,EAAE,EAAE,EAAI,AAAyB,IAAzB,EAAc,MAAM,EAGlD,EAAE,eAAe,GACjB,EAAS,CACP,KAAM,uBACN,QAAS,CAAE,IAAK,CAAC,EAAE,EAAE,CAAC,AAAC,CACzB,IAEA,EAAS,CACP,KAAM,cACN,QAAS,CAAE,IAAK,CAAC,EAAE,EAAE,CAAC,AAAC,CACzB,EAEJ,EACA,UAAW,EACP,WACM,EAAW,GAAK,aAC1B,OAjCW,EAAS,QAAU,QAkC9B,YAAa,CACf,GACA,EAAE,EAAE,CAAC,GACH,OACA,CACE,EAAG,EAAE,CAAC,CAAG,GACT,EAAG,EAAE,CAAC,CAAG,EACT,UAAW,YACb,EACA,EAAE,IAAI,EAAI,CAAC,KAAK,EAAE,EAAE,EAAE,CAAA,CAAE,EAE1B,EAAE,EAAE,CAAC,CAAC,GAAY,QAAS,EAAE,IAAI,EAAI,CAAC,KAAK,EAAE,EAAE,EAAE,CAAA,CAAE,EACpD,CACH,IAEH,EACF,GAEL,Q,K,S","sources":["<anon>","packages/feedback-components/src/feedback/graph.ts"],"sourcesContent":["import \"./feedback-components.8caef76e.js\";\nimport \"./feedback-components.c31cf831.js\";\nimport \"./feedback-components.b22d37d1.js\";\nimport $9bqpz$macrostrathyper from \"@macrostrat/hyper\";\nimport {forceSimulation as $9bqpz$forceSimulation, forceLink as $9bqpz$forceLink, forceManyBody as $9bqpz$forceManyBody, forceCenter as $9bqpz$forceCenter, forceCollide as $9bqpz$forceCollide} from \"d3-force\";\nimport {useState as $9bqpz$useState, useEffect as $9bqpz$useEffect} from \"react\";\nimport {Spinner as $9bqpz$Spinner, Switch as $9bqpz$Switch} from \"@blueprintjs/core\";\nimport {ErrorBoundary as $9bqpz$ErrorBoundary} from \"@macrostrat/ui-components\";\n\n\nfunction $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\n var $parcel$global = globalThis;\n \nvar $parcel$modules = {};\nvar $parcel$inits = {};\n\nvar parcelRequire = $parcel$global[\"parcelRequirea149\"];\n\nif (parcelRequire == null) {\n parcelRequire = function(id) {\n if (id in $parcel$modules) {\n return $parcel$modules[id].exports;\n }\n if (id in $parcel$inits) {\n var init = $parcel$inits[id];\n delete $parcel$inits[id];\n var module = {id: id, exports: {}};\n $parcel$modules[id] = module;\n init.call(module.exports, module, module.exports);\n return module.exports;\n }\n var err = new Error(\"Cannot find module '\" + id + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n };\n\n parcelRequire.register = function register(id, init) {\n $parcel$inits[id] = init;\n };\n\n $parcel$global[\"parcelRequirea149\"] = parcelRequire;\n}\n\nvar parcelRegister = parcelRequire.register;\n\nvar $eedTh = parcelRequire(\"eedTh\");\n\nvar $9wFEx = parcelRequire(\"9wFEx\");\n\n\n\n\n\n\nvar $edvRb = parcelRequire(\"edvRb\");\nconst $8732cb0ae0ae3dfd$var$h = (0, $9bqpz$macrostrathyper).styled((0, (/*@__PURE__*/$parcel$interopDefault($9wFEx))));\nfunction $8732cb0ae0ae3dfd$export$6a7fe3ef90e8d566(props) {\n // A graph view with react-flow\n // Get positions of nodes using force simulation\n const { tree: tree, width: width, height: height, dispatch: dispatch, selectedNodes: selectedNodes, viewOnly: viewOnly } = props;\n const [nodes, setNodes] = (0, $9bqpz$useState)(null);\n const [links, setLinks] = (0, $9bqpz$useState)(null);\n const [showLabels, setShowLabels] = (0, $9bqpz$useState)(false);\n (0, $9bqpz$useEffect)(()=>{\n const { nodes: nodes, edges: edges } = (0, $eedTh.treeToGraph)(tree);\n const nodesMap = new Map(nodes.map((d)=>[\n d.id,\n d\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 const simulation = (0, $9bqpz$forceSimulation)(nodes).force(\"link\", (0, $9bqpz$forceLink)(links)).force(\"charge\", (0, $9bqpz$forceManyBody)().strength(-50)).force(\"center\", (0, $9bqpz$forceCenter)(width / 2, height / 2)).force(\"collide\", (0, $9bqpz$forceCollide)().radius(20)).on(\"tick\", ()=>{\n // Update the positions of the nodes\n // setNodes(nodes);\n console.log(\"Simulation tick\");\n }).on(\"end\", ()=>{\n // Update the positions of the nodes\n setNodes(nodes);\n setLinks(links);\n });\n return ()=>{\n simulation.stop();\n };\n }, [\n tree,\n width,\n height\n ]);\n if (nodes == null || links == null) return $8732cb0ae0ae3dfd$var$h((0, $9bqpz$Spinner));\n console.log(\"Graph\", nodes, links, selectedNodes);\n return $8732cb0ae0ae3dfd$var$h((0, $9bqpz$ErrorBoundary), {\n description: \"An error occurred while rendering the graph view.\"\n }, $8732cb0ae0ae3dfd$var$h(\"div.graph-view\", {\n style: {\n width: width,\n height: height\n }\n }, [\n $8732cb0ae0ae3dfd$var$h((0, $9bqpz$Switch), {\n className: \"show-labels-switch\",\n label: \"Show Labels\",\n checked: showLabels,\n onChange: (e)=>setShowLabels(e.target.checked)\n }),\n $8732cb0ae0ae3dfd$var$h(\"svg\", {\n width: width,\n height: height\n }, [\n $8732cb0ae0ae3dfd$var$h(\"g.links\", links.map((d)=>{\n return $8732cb0ae0ae3dfd$var$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 $8732cb0ae0ae3dfd$var$h(\"g.nodes\", nodes.map((d)=>{\n const active = selectedNodes.includes(d.id);\n const stroke = active ? \"white\" : \"black\";\n const highlighted = $8732cb0ae0ae3dfd$var$isHighlighted(d.id, selectedNodes, nodes);\n const style = (0, $edvRb.getTagStyle)(d.color, {\n highlighted: highlighted,\n active: active\n });\n return $8732cb0ae0ae3dfd$var$h(\"g\", [\n $8732cb0ae0ae3dfd$var$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 (e.ctrlKey || e.metaKey || selectedNodes[0] === d.id && selectedNodes.length === 1) {\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: {\n ids: [\n d.id\n ]\n }\n });\n } else dispatch({\n type: \"select-node\",\n payload: {\n ids: [\n d.id\n ]\n }\n });\n },\n className: active ? \"selected\" : \"\" + (viewOnly ? \"\" : \" clickable\"),\n stroke: stroke,\n strokeWidth: 2\n }),\n $8732cb0ae0ae3dfd$var$h.if(showLabels)(\"text\", {\n x: d.x + 10,\n y: d.y + 4,\n className: \"node-label\"\n }, d.name || `Node ${d.id}`),\n $8732cb0ae0ae3dfd$var$h.if(!showLabels)(\"title\", d.name || `Node ${d.id}`)\n ]);\n }))\n ])\n ]));\n}\nfunction $8732cb0ae0ae3dfd$var$isHighlighted(id, selectedNodes, nodes) {\n if (selectedNodes.length === 0) return true;\n return selectedNodes.includes(id) || nodes.some((node)=>selectedNodes.includes(node.id) && node.children.some((child)=>child.id === id));\n}\n\n\nexport {$8732cb0ae0ae3dfd$export$6a7fe3ef90e8d566 as GraphView};\n//# sourceMappingURL=feedback-components.ce5efb18.js.map\n","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":["$9bqpz$macrostrathyper","forceSimulation","$9bqpz$forceSimulation","forceLink","$9bqpz$forceLink","forceManyBody","$9bqpz$forceManyBody","forceCenter","$9bqpz$forceCenter","forceCollide","$9bqpz$forceCollide","useState","$9bqpz$useState","useEffect","$9bqpz$useEffect","Spinner","$9bqpz$Spinner","Switch","$9bqpz$Switch","ErrorBoundary","$9bqpz$ErrorBoundary","$parcel$global","globalThis","$parcel$modules","$parcel$inits","parcelRequire","id","exports","init","module","call","err","Error","code","register","$eedTh","$9wFEx","$edvRb","$8732cb0ae0ae3dfd$var$h","styled","a","__esModule","default","$8732cb0ae0ae3dfd$export$6a7fe3ef90e8d566","props","tree","width","height","dispatch","selectedNodes","viewOnly","nodes","setNodes","links","setLinks","showLabels","setShowLabels","edges","treeToGraph","nodesMap","Map","map","d","source","get","target","dest","strength","simulation","force","radius","on","console","log","stop","description","style","className","label","checked","onChange","e","x1","x","y1","y","x2","y2","stroke","active","includes","highlighted","length","some","node","children","child","getTagStyle","color","cx","cy","r","fill","backgroundColor","onClick","stopPropagation","ctrlKey","metaKey","type","payload","ids","strokeWidth","if","name","GraphView"],"version":3,"file":"feedback-components.ce5efb18.js.map","sourceRoot":"../../../../"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
:root{--text-line-height:3em;--main-extra-width:200px}.QoX8-W_page-wrapper{flex-direction:row;align-items:flex-start;gap:2em;display:flex;position:relative}.QoX8-W_feedback-container{flex:4}.QoX8-W_control-panel{flex:1;height:auto}.QoX8-W_control-content{position:sticky;top:0}.QoX8-W_feedback-component{width:800px;position:relative}.QoX8-W_feedback-component>svg{width:800px}.QoX8-W_node{cursor:pointer}circle{border:1px solid #000}.QoX8-W_selected{border:1px solid #fff}.QoX8-W_feedback-text{margin-bottom:2em}.QoX8-W_entity-panel{background:var(--panel-secondary-background-color);width:calc(100% - 2em);min-height:100px;max-height:600px;box-shadow:0 0 0 1px var(--panel-border-color)inset;border-radius:4px;flex:1;padding:1em;position:relative}.QoX8-W_selection-tree{margin:-1em 0;padding:1em 0}.QoX8-W_type-list{grid-template-rows:repeat(10,auto);grid-auto-flow:column;gap:.2em;display:grid}.QoX8-W_type-list .QoX8-W_type-tag{border-radius:.2em;padding:.2em .5em}.QoX8-W_description{max-width:300px;padding:.5em}mark{cursor:pointer;border-radius:.2em;color:#000!important}[role=treeitem]{width:auto!important}.QoX8-W_highlight{zIndex:10;border-radius:.2em;padding:.2em 0;position:relative}.QoX8-W_clickable{cursor:pointer}.QoX8-W_feedback-text-wrapper{z-index:0;line-height:var(--text-line-height);position:relative;overflow:visible}.QoX8-W_type-container{justify-content:space-between;align-items:center;column-gap:1em;display:flex}.QoX8-W_add-type{cursor:pointer;justify-content:space-between;align-items:center;padding:0 .5em;display:flex}.QoX8-W_add-type p{margin:0}.QoX8-W_overlay-container{justify-content:center;align-items:center;width:100vw;height:80vh;display:flex}.QoX8-W_overlay-container .QoX8-W_add-type-overlay{background-color:var(--tertiary-background);border-radius:.2em;flex-direction:column;gap:1em;padding:.5em 1em;display:flex}.QoX8-W_overlay-container .QoX8-W_add-type-overlay .QoX8-W_title{justify-content:space-between;align-items:center;display:flex}.QoX8-W_overlay-container .QoX8-W_add-type-overlay h2{margin:0}.QoX8-W_overlay-container .QoX8-W_add-type-overlay .QoX8-W_form-group{gap:3em;display:flex}.QoX8-W_overlay-container .QoX8-W_add-type-overlay .QoX8-W_form-group .QoX8-W_text-inputs{flex-direction:column;gap:1em;display:flex}.QoX8-W_icons{gap:.25em;display:flex}.QoX8-W_node-label{fill:var(--text-emphasized-color);fontSize:10px;pointerEvents:none}.QoX8-W_match-item{color:var(--text-emphasized-color);cursor:pointer;border-radius:.2em;margin-bottom:4px;padding:.1em .2em}.QoX8-W_match-item .QoX8-W_match-label{color:var(--text-color);margin:0}.QoX8-W_match-container{justify-content:space-between;align-items:center;display:flex}.QoX8-W_match-container .QoX8-W_close-btn{cursor:pointer}
|
|
2
|
+
/*# sourceMappingURL=feedback-components.db4d0a14.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"ACAA,sDAIA,sGAOA,kCAGA,yCAIA,8CAIA,yDAIE,2CAGF,4BAGA,6BAGA,uCAGA,wCAGA,4OAYA,mDAIA,iGAME,wEAIF,iDAIA,4DAKA,qCAGA,gFAMA,iCAGA,+GAMA,oGAMA,6GAOE,4BAGF,yGAOE,8KAQE,+HAKA,+DAGA,2FAIE,qIAKN,qCAIA,sFAKA,4HAOE,wEAIF,sFAKE","sources":["feedback-components.db4d0a14.css","packages/feedback-components/src/feedback/feedback.module.sass"],"sourcesContent":[":root {\n --text-line-height: 3em;\n --main-extra-width: 200px;\n}\n\n.QoX8-W_page-wrapper {\n flex-direction: row;\n align-items: flex-start;\n gap: 2em;\n display: flex;\n position: relative;\n}\n\n.QoX8-W_feedback-container {\n flex: 4;\n}\n\n.QoX8-W_control-panel {\n flex: 1;\n height: auto;\n}\n\n.QoX8-W_control-content {\n position: sticky;\n top: 0;\n}\n\n.QoX8-W_feedback-component {\n width: 800px;\n position: relative;\n}\n\n.QoX8-W_feedback-component > svg {\n width: 800px;\n}\n\n.QoX8-W_node {\n cursor: pointer;\n}\n\ncircle {\n border: 1px solid #000;\n}\n\n.QoX8-W_selected {\n border: 1px solid #fff;\n}\n\n.QoX8-W_feedback-text {\n margin-bottom: 2em;\n}\n\n.QoX8-W_entity-panel {\n background: var(--panel-secondary-background-color);\n width: calc(100% - 2em);\n min-height: 100px;\n max-height: 600px;\n box-shadow: 0 0 0 1px var(--panel-border-color) inset;\n border-radius: 4px;\n flex: 1;\n padding: 1em;\n position: relative;\n}\n\n.QoX8-W_selection-tree {\n margin: -1em 0;\n padding: 1em 0;\n}\n\n.QoX8-W_type-list {\n grid-template-rows: repeat(10, auto);\n grid-auto-flow: column;\n gap: .2em;\n display: grid;\n}\n\n.QoX8-W_type-list .QoX8-W_type-tag {\n border-radius: .2em;\n padding: .2em .5em;\n}\n\n.QoX8-W_description {\n max-width: 300px;\n padding: .5em;\n}\n\nmark {\n cursor: pointer;\n border-radius: .2em;\n color: #000 !important;\n}\n\n[role=\"treeitem\"] {\n width: auto !important;\n}\n\n.QoX8-W_highlight {\n zIndex: 10;\n border-radius: .2em;\n padding: .2em 0;\n position: relative;\n}\n\n.QoX8-W_clickable {\n cursor: pointer;\n}\n\n.QoX8-W_feedback-text-wrapper {\n z-index: 0;\n line-height: var(--text-line-height);\n position: relative;\n overflow: visible;\n}\n\n.QoX8-W_type-container {\n justify-content: space-between;\n align-items: center;\n column-gap: 1em;\n display: flex;\n}\n\n.QoX8-W_add-type {\n cursor: pointer;\n justify-content: space-between;\n align-items: center;\n padding: 0 .5em;\n display: flex;\n}\n\n.QoX8-W_add-type p {\n margin: 0;\n}\n\n.QoX8-W_overlay-container {\n justify-content: center;\n align-items: center;\n width: 100vw;\n height: 80vh;\n display: flex;\n}\n\n.QoX8-W_overlay-container .QoX8-W_add-type-overlay {\n background-color: var(--tertiary-background);\n border-radius: .2em;\n flex-direction: column;\n gap: 1em;\n padding: .5em 1em;\n display: flex;\n}\n\n.QoX8-W_overlay-container .QoX8-W_add-type-overlay .QoX8-W_title {\n justify-content: space-between;\n align-items: center;\n display: flex;\n}\n\n.QoX8-W_overlay-container .QoX8-W_add-type-overlay h2 {\n margin: 0;\n}\n\n.QoX8-W_overlay-container .QoX8-W_add-type-overlay .QoX8-W_form-group {\n gap: 3em;\n display: flex;\n}\n\n.QoX8-W_overlay-container .QoX8-W_add-type-overlay .QoX8-W_form-group .QoX8-W_text-inputs {\n flex-direction: column;\n gap: 1em;\n display: flex;\n}\n\n.QoX8-W_icons {\n gap: .25em;\n display: flex;\n}\n\n.QoX8-W_node-label {\n fill: var(--text-emphasized-color);\n fontSize: 10px;\n pointerEvents: none;\n}\n\n.QoX8-W_match-item {\n color: var(--text-emphasized-color);\n cursor: pointer;\n border-radius: .2em;\n margin-bottom: 4px;\n padding: .1em .2em;\n}\n\n.QoX8-W_match-item .QoX8-W_match-label {\n color: var(--text-color);\n margin: 0;\n}\n\n.QoX8-W_match-container {\n justify-content: space-between;\n align-items: center;\n display: flex;\n}\n\n.QoX8-W_match-container .QoX8-W_close-btn {\n cursor: pointer;\n}\n/*# sourceMappingURL=feedback-components.db4d0a14.css.map */\n",":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.db4d0a14.css.map","sourceRoot":"../../../../"}
|
package/dist/node/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"./feedback-components.b22d37d1.js";import"./feedback-components.
|
|
1
|
+
import"./feedback-components.b22d37d1.js";import"./feedback-components.441e2203.js";function e(e,a){return Object.keys(a).forEach(function(t){"default"===t||"__esModule"===t||Object.prototype.hasOwnProperty.call(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return a[t]}})}),e}var a=globalThis,t={},r={},c=a.parcelRequirea149;null==c&&((c=function(e){if(e in t)return t[e].exports;if(e in r){var a=r[e];delete r[e];var c={id:e,exports:{}};return t[e]=c,a.call(c.exports,c,c.exports),c.exports}var o=Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(e,a){r[e]=a},a.parcelRequirea149=c),c.register;var o={},n=c("edvRb"),d=c("aZPCw");e(o,n),e(o,d);export{$8c534c0378e15a46$export$c4b91360064ad200 as buildHighlights,$8c534c0378e15a46$export$d60b563f571177d as enhanceData,$8c534c0378e15a46$export$35baa338324d8550 as getTagStyle,$8c534c0378e15a46$export$2b07158757c249e0 as ExtractionContext,$8c534c0378e15a46$export$4eb2a0ce903ce967 as ModelInfo,$8c534c0378e15a46$export$117e56c71b172cde as EntityTag,$2c86488f2f3c1edd$export$a90600c9da52b40c as FeedbackComponent,$330ae695507d96f5$export$8d9dbb7a64bf2a5e as treeToGraph};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"A,M,oD,A,O,oD,C,S,E,C,C,C,E,O,O,I,C,G,O,C,S,C,E,Y,G,A,e,G,O,S,C,c,C,I,C,E,I,O,c,C,E,E,C,W,C,E,I,W,O,C,C,E,A,C,E,G,C,C,I,E,W,E,C,E,E,C,E,E,E,iB,A,O,I,A,C,E,S,C,E,G,K,E,O,C,C,E,C,O,C,G,K,E,C,I,E,C,C,E,A,Q,C,C,E,C,I,E,C,G,E,Q,C,C,E,O,C,C,E,C,E,E,I,C,E,O,C,E,E,O,E,E,O,A,C,I,E,A,M,uB,E,I,O,E,I,C,mB,C,C,E,Q,C,S,C,C,C,E,C,C,E,C,C,E,E,iB,C,G,E,Q,C,I,E,C,E,E,E,S,E,E,S,E,E,G,E,E,U,6C,e,C,4C,W,C,6C,W,C,6C,iB,C,6C,S,C,6C,S,C,6C,iB,C,6C,W","sources":["<anon>","packages/feedback-components/src/index.ts"],"sourcesContent":["import \"./feedback-components.b22d37d1.js\";\nimport \"./feedback-components.
|
|
1
|
+
{"mappings":"A,M,oD,A,O,oD,C,S,E,C,C,C,E,O,O,I,C,G,O,C,S,C,E,Y,G,A,e,G,O,S,C,c,C,I,C,E,I,O,c,C,E,E,C,W,C,E,I,W,O,C,C,E,A,C,E,G,C,C,I,E,W,E,C,E,E,C,E,E,E,iB,A,O,I,A,C,E,S,C,E,G,K,E,O,C,C,E,C,O,C,G,K,E,C,I,E,C,C,E,A,Q,C,C,E,C,I,E,C,G,E,Q,C,C,E,O,C,C,E,C,E,E,I,C,E,O,C,E,E,O,E,E,O,A,C,I,E,A,M,uB,E,I,O,E,I,C,mB,C,C,E,Q,C,S,C,C,C,E,C,C,E,C,C,E,E,iB,C,G,E,Q,C,I,E,C,E,E,E,S,E,E,S,E,E,G,E,E,U,6C,e,C,4C,W,C,6C,W,C,6C,iB,C,6C,S,C,6C,S,C,6C,iB,C,6C,W","sources":["<anon>","packages/feedback-components/src/index.ts"],"sourcesContent":["import \"./feedback-components.b22d37d1.js\";\nimport \"./feedback-components.441e2203.js\";\n\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n }\n });\n });\n\n return dest;\n}\n\n var $parcel$global = globalThis;\n \nvar $parcel$modules = {};\nvar $parcel$inits = {};\n\nvar parcelRequire = $parcel$global[\"parcelRequirea149\"];\n\nif (parcelRequire == null) {\n parcelRequire = function(id) {\n if (id in $parcel$modules) {\n return $parcel$modules[id].exports;\n }\n if (id in $parcel$inits) {\n var init = $parcel$inits[id];\n delete $parcel$inits[id];\n var module = {id: id, exports: {}};\n $parcel$modules[id] = module;\n init.call(module.exports, module, module.exports);\n return module.exports;\n }\n var err = new Error(\"Cannot find module '\" + id + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n };\n\n parcelRequire.register = function register(id, init) {\n $parcel$inits[id] = init;\n };\n\n $parcel$global[\"parcelRequirea149\"] = parcelRequire;\n}\n\nvar parcelRegister = parcelRequire.register;\nvar $c688386f08592f9c$exports = {};\n\nvar $edvRb = parcelRequire(\"edvRb\");\n\nvar $aZPCw = parcelRequire(\"aZPCw\");\n$parcel$exportWildcard($c688386f08592f9c$exports, $edvRb);\n$parcel$exportWildcard($c688386f08592f9c$exports, $aZPCw);\n\n\nexport {$8c534c0378e15a46$export$c4b91360064ad200 as buildHighlights, $8c534c0378e15a46$export$d60b563f571177d as enhanceData, $8c534c0378e15a46$export$35baa338324d8550 as getTagStyle, $8c534c0378e15a46$export$2b07158757c249e0 as ExtractionContext, $8c534c0378e15a46$export$4eb2a0ce903ce967 as ModelInfo, $8c534c0378e15a46$export$117e56c71b172cde as EntityTag, $2c86488f2f3c1edd$export$a90600c9da52b40c as FeedbackComponent, $330ae695507d96f5$export$8d9dbb7a64bf2a5e as treeToGraph};\n//# sourceMappingURL=index.js.map\n","export * from \"./extractions\";\nexport * from \"./feedback\";\n"],"names":["$parcel$exportWildcard","dest","source","Object","keys","forEach","key","prototype","hasOwnProperty","call","defineProperty","enumerable","get","$parcel$global","globalThis","$parcel$modules","$parcel$inits","parcelRequire","id","exports","init","module","err","Error","code","register","$c688386f08592f9c$exports","$edvRb","$aZPCw","$8c534c0378e15a46$export$c4b91360064ad200","buildHighlights","$8c534c0378e15a46$export$d60b563f571177d","enhanceData","$8c534c0378e15a46$export$35baa338324d8550","getTagStyle","$8c534c0378e15a46$export$2b07158757c249e0","ExtractionContext","$8c534c0378e15a46$export$4eb2a0ce903ce967","ModelInfo","$8c534c0378e15a46$export$117e56c71b172cde","EntityTag","$2c86488f2f3c1edd$export$a90600c9da52b40c","FeedbackComponent","$330ae695507d96f5$export$8d9dbb7a64bf2a5e","treeToGraph"],"version":3,"file":"index.js.map","sourceRoot":"../../../../"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macrostrat/feedback-components",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@macrostrat/data-components": "^0.2.0",
|
|
40
40
|
"@macrostrat/data-sheet": "^2.1.1",
|
|
41
41
|
"@macrostrat/hyper": "^3.0.6",
|
|
42
|
-
"@macrostrat/ui-components": "^4.4.
|
|
42
|
+
"@macrostrat/ui-components": "^4.4.4",
|
|
43
43
|
"@xyflow/react": "^12.3.6",
|
|
44
44
|
"classnames": "^2.5.1",
|
|
45
45
|
"d3-force": "^3.0.0",
|
|
@@ -17,6 +17,8 @@ interface TreeState {
|
|
|
17
17
|
lastInternalId: number;
|
|
18
18
|
isSelectingEntityType: boolean;
|
|
19
19
|
viewMode: ViewMode;
|
|
20
|
+
viewOnly: boolean;
|
|
21
|
+
matchMode: boolean;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
type TextRange = {
|
|
@@ -50,13 +52,17 @@ type TreeAction =
|
|
|
50
52
|
}
|
|
51
53
|
| { type: "select-range"; payload: { ids: number[] } }
|
|
52
54
|
| { type: "add-match"; payload: { id: number; payload: any } }
|
|
53
|
-
| { type: "remove-match"; payload: { id: number } }
|
|
55
|
+
| { type: "remove-match"; payload: { id: number } }
|
|
56
|
+
| { type: "toggle-match-mode" }
|
|
57
|
+
| { type: "toggle-view-only" };
|
|
54
58
|
|
|
55
59
|
export type TreeDispatch = Dispatch<TreeAction>;
|
|
56
60
|
|
|
57
61
|
export function useUpdatableTree(
|
|
58
62
|
initialTree: TreeData[],
|
|
59
63
|
entityTypes: Map<number, EntityType>,
|
|
64
|
+
viewOnly: boolean,
|
|
65
|
+
matchMode: boolean,
|
|
60
66
|
): [TreeState, TreeDispatch] {
|
|
61
67
|
// Get the first entity type
|
|
62
68
|
// issue: grabs second entity instead of selected one
|
|
@@ -71,6 +77,8 @@ export function useUpdatableTree(
|
|
|
71
77
|
lastInternalId: 0,
|
|
72
78
|
isSelectingEntityType: false,
|
|
73
79
|
viewMode: ViewMode.Tree,
|
|
80
|
+
viewOnly,
|
|
81
|
+
matchMode,
|
|
74
82
|
});
|
|
75
83
|
}
|
|
76
84
|
|
|
@@ -85,6 +93,18 @@ export function useTreeDispatch() {
|
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
function treeReducer(state: TreeState, action: TreeAction) {
|
|
96
|
+
if (action.type === "toggle-match-mode") {
|
|
97
|
+
return { ...state, matchMode: !state.matchMode };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (action.type === "toggle-view-only") {
|
|
101
|
+
return { ...state, viewOnly: !state.viewOnly };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (state.viewOnly) return viewMode(state, action);
|
|
105
|
+
|
|
106
|
+
if (state.matchMode) return matchMode(state, action);
|
|
107
|
+
|
|
88
108
|
switch (action.type) {
|
|
89
109
|
case "add-entity-type": {
|
|
90
110
|
// Add a new entity type to the map
|
|
@@ -264,54 +284,6 @@ function treeReducer(state: TreeState, action: TreeAction) {
|
|
|
264
284
|
};
|
|
265
285
|
}
|
|
266
286
|
|
|
267
|
-
case "add-match": {
|
|
268
|
-
const { id } = action.payload;
|
|
269
|
-
|
|
270
|
-
// Find the node path
|
|
271
|
-
const keyPath = findNode(state.tree, id);
|
|
272
|
-
if (!keyPath) {
|
|
273
|
-
console.warn(`Node with id ${id} not found`);
|
|
274
|
-
return state;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// Build update spec to set the `match` property
|
|
278
|
-
const matchUpdateSpec = buildNestedSpec(keyPath, {
|
|
279
|
-
match: { $set: action.payload.payload },
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
const updatedTree = update(state.tree, matchUpdateSpec);
|
|
283
|
-
|
|
284
|
-
return {
|
|
285
|
-
...state,
|
|
286
|
-
tree: updatedTree,
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
case "remove-match": {
|
|
291
|
-
const { id } = action.payload;
|
|
292
|
-
|
|
293
|
-
console.log("Removing match for node with id:", id);
|
|
294
|
-
|
|
295
|
-
// Find the node path
|
|
296
|
-
const keyPath = findNode(state.tree, id);
|
|
297
|
-
if (!keyPath) {
|
|
298
|
-
console.warn(`Node with id ${id} not found`);
|
|
299
|
-
return state;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Build update spec to unset the `match` property
|
|
303
|
-
const matchUpdateSpec = buildNestedSpec(keyPath, {
|
|
304
|
-
match: { $set: null },
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
const updatedTree = update(state.tree, matchUpdateSpec);
|
|
308
|
-
|
|
309
|
-
return {
|
|
310
|
-
...state,
|
|
311
|
-
tree: updatedTree,
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
|
|
315
287
|
/** Entity type selection */
|
|
316
288
|
case "toggle-entity-type-selector":
|
|
317
289
|
return {
|
|
@@ -526,3 +498,83 @@ function flattenAndSort(nodes) {
|
|
|
526
498
|
// sort by start
|
|
527
499
|
return result.sort((a, b) => a.indices[0] - b.indices[0]);
|
|
528
500
|
}
|
|
501
|
+
|
|
502
|
+
function matchMode(state, action) {
|
|
503
|
+
if (action.type === "select-node" || action.type === "toggle-node-selected") {
|
|
504
|
+
const { ids } = action.payload;
|
|
505
|
+
|
|
506
|
+
if (ids.length != 1) return state;
|
|
507
|
+
|
|
508
|
+
if (state.selectedNodes.length === 1) {
|
|
509
|
+
if (ids[0] === state.selectedNodes[0]) {
|
|
510
|
+
// If the selected node is the same as the current selection, deselect it
|
|
511
|
+
return { ...state, selectedNodes: [] };
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const type =
|
|
516
|
+
action.payload.ids.length > 0
|
|
517
|
+
? findNodeById(state.tree, ids[0])?.type
|
|
518
|
+
: null;
|
|
519
|
+
|
|
520
|
+
return { ...state, selectedNodes: ids, selectedEntityType: type };
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (action.type === "add-match") {
|
|
524
|
+
const { id } = action.payload;
|
|
525
|
+
|
|
526
|
+
// Find the node path
|
|
527
|
+
const keyPath = findNode(state.tree, id);
|
|
528
|
+
if (!keyPath) {
|
|
529
|
+
console.warn(`Node with id ${id} not found`);
|
|
530
|
+
return state;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// Build update spec to set the `match` property
|
|
534
|
+
const matchUpdateSpec = buildNestedSpec(keyPath, {
|
|
535
|
+
match: { $set: action.payload.payload },
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
const updatedTree = update(state.tree, matchUpdateSpec);
|
|
539
|
+
|
|
540
|
+
return {
|
|
541
|
+
...state,
|
|
542
|
+
tree: updatedTree,
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (action.type === "remove-match") {
|
|
547
|
+
const { id } = action.payload;
|
|
548
|
+
|
|
549
|
+
console.log("Removing match for node with id:", id);
|
|
550
|
+
|
|
551
|
+
// Find the node path
|
|
552
|
+
const keyPath = findNode(state.tree, id);
|
|
553
|
+
if (!keyPath) {
|
|
554
|
+
console.warn(`Node with id ${id} not found`);
|
|
555
|
+
return state;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// Build update spec to unset the `match` property
|
|
559
|
+
const matchUpdateSpec = buildNestedSpec(keyPath, {
|
|
560
|
+
match: { $set: null },
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
const updatedTree = update(state.tree, matchUpdateSpec);
|
|
564
|
+
|
|
565
|
+
return {
|
|
566
|
+
...state,
|
|
567
|
+
tree: updatedTree,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return state;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function viewMode(state, action) {
|
|
575
|
+
if (action.type === "set-view-mode") {
|
|
576
|
+
return { ...state, viewMode: action.payload };
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return state;
|
|
580
|
+
}
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
cursor: pointer
|
|
32
32
|
|
|
33
33
|
circle
|
|
34
|
-
cursor: pointer
|
|
35
34
|
border: 1px solid black
|
|
36
35
|
|
|
37
36
|
.selected
|
|
@@ -79,12 +78,14 @@ mark
|
|
|
79
78
|
width: auto !important
|
|
80
79
|
|
|
81
80
|
.highlight
|
|
82
|
-
cursor: pointer
|
|
83
81
|
padding: .2em 0
|
|
84
82
|
border-radius: .2em
|
|
85
83
|
position: relative
|
|
86
84
|
zIndex: 10
|
|
87
85
|
|
|
86
|
+
.clickable
|
|
87
|
+
cursor: pointer
|
|
88
|
+
|
|
88
89
|
.feedback-text-wrapper
|
|
89
90
|
position: relative
|
|
90
91
|
z-index: 0
|
|
@@ -115,7 +116,7 @@ mark
|
|
|
115
116
|
align-items: center
|
|
116
117
|
|
|
117
118
|
.add-type-overlay
|
|
118
|
-
background-color: var(--
|
|
119
|
+
background-color: var(--tertiary-background)
|
|
119
120
|
padding: .5em 1em
|
|
120
121
|
display: flex
|
|
121
122
|
flex-direction: column
|
|
@@ -149,12 +150,15 @@ mark
|
|
|
149
150
|
pointerEvents: none
|
|
150
151
|
|
|
151
152
|
.match-item
|
|
152
|
-
background-color: var(--background-color)
|
|
153
153
|
color: var(--text-emphasized-color)
|
|
154
154
|
padding: .1em .2em
|
|
155
155
|
border-radius: .2em
|
|
156
156
|
margin-bottom: 4px
|
|
157
157
|
cursor: pointer
|
|
158
|
+
|
|
159
|
+
.match-label
|
|
160
|
+
margin: 0
|
|
161
|
+
color: var(--text-color)
|
|
158
162
|
|
|
159
163
|
.match-container
|
|
160
164
|
display: flex
|
|
@@ -162,4 +166,4 @@ mark
|
|
|
162
166
|
align-items: center
|
|
163
167
|
|
|
164
168
|
.close-btn
|
|
165
|
-
cursor: pointer
|
|
169
|
+
cursor: pointer
|
package/src/feedback/graph.ts
CHANGED
|
@@ -24,10 +24,11 @@ export function GraphView(props: {
|
|
|
24
24
|
height: number;
|
|
25
25
|
dispatch: (action: any) => void;
|
|
26
26
|
selectedNodes: number[];
|
|
27
|
+
viewOnly?: boolean;
|
|
27
28
|
}) {
|
|
28
29
|
// A graph view with react-flow
|
|
29
30
|
// Get positions of nodes using force simulation
|
|
30
|
-
const { tree, width, height, dispatch, selectedNodes } = props;
|
|
31
|
+
const { tree, width, height, dispatch, selectedNodes, viewOnly } = props;
|
|
31
32
|
|
|
32
33
|
const [nodes, setNodes] = useState<SimulationNodeDatum[]>(null);
|
|
33
34
|
const [links, setLinks] = useState<SimulationLinkDatum[]>(null);
|
|
@@ -134,7 +135,9 @@ export function GraphView(props: {
|
|
|
134
135
|
});
|
|
135
136
|
}
|
|
136
137
|
},
|
|
137
|
-
className: active
|
|
138
|
+
className: active
|
|
139
|
+
? "selected"
|
|
140
|
+
: "" + (viewOnly ? "" : " clickable"),
|
|
138
141
|
stroke,
|
|
139
142
|
strokeWidth: 2,
|
|
140
143
|
}),
|