@ebay/nice-dag-react 1.0.7 → 1.0.9
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/lib/index.cjs +27 -0
- package/lib/{cjs/index.d.ts → index.d.ts} +6 -1
- package/lib/index.js +763 -0
- package/lib/index.umd.cjs +27 -0
- package/package.json +20 -13
- package/lib/cjs/index.js +0 -218
- package/lib/esm/index.d.ts +0 -60
- package/lib/esm/index.js +0 -186
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
(function(E,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("react"),require("react-dom"),require("@ebay/nice-dag-core")):typeof define=="function"&&define.amd?define(["exports","react","react-dom","@ebay/nice-dag-core"],p):(E=typeof globalThis<"u"?globalThis:E||self,p(E.niceDagReact={},E.React,E.ReactDOM,E.NiceDag))})(this,function(E,p,We,Ye){"use strict";const H=o=>o&&typeof o=="object"&&"default"in o?o:{default:o},W=H(p),X=H(We),Me=H(Ye);var Z={exports:{}},Y={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var fe;function Le(){if(fe)return Y;fe=1;var o=W.default,f=Symbol.for("react.element"),O=Symbol.for("react.fragment"),b=Object.prototype.hasOwnProperty,C=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,P={key:!0,ref:!0,__self:!0,__source:!0};function T(w,g,S){var h,s={},D=null,_=null;S!==void 0&&(D=""+S),g.key!==void 0&&(D=""+g.key),g.ref!==void 0&&(_=g.ref);for(h in g)b.call(g,h)&&!P.hasOwnProperty(h)&&(s[h]=g[h]);if(w&&w.defaultProps)for(h in g=w.defaultProps,g)s[h]===void 0&&(s[h]=g[h]);return{$$typeof:f,type:w,key:D,ref:_,props:s,_owner:C.current}}return Y.Fragment=O,Y.jsx=T,Y.jsxs=T,Y}var M={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var le;function Ve(){return le||(le=1,process.env.NODE_ENV!=="production"&&function(){var o=W.default,f=Symbol.for("react.element"),O=Symbol.for("react.portal"),b=Symbol.for("react.fragment"),C=Symbol.for("react.strict_mode"),P=Symbol.for("react.profiler"),T=Symbol.for("react.provider"),w=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),s=Symbol.for("react.memo"),D=Symbol.for("react.lazy"),_=Symbol.for("react.offscreen"),j=Symbol.iterator,ee="@@iterator";function q(e){if(e===null||typeof e!="object")return null;var r=j&&e[j]||e[ee];return typeof r=="function"?r:null}var y=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function l(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];x("error",e,t)}}function x(e,r,t){{var n=y.ReactDebugCurrentFrame,u=n.getStackAddendum();u!==""&&(r+="%s",t=t.concat([u]));var c=t.map(function(i){return String(i)});c.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,c)}}var re=!1,L=!1,ze=!1,Ke=!1,He=!1,pe;pe=Symbol.for("react.module.reference");function Xe(e){return!!(typeof e=="string"||typeof e=="function"||e===b||e===P||He||e===C||e===S||e===h||Ke||e===_||re||L||ze||typeof e=="object"&&e!==null&&(e.$$typeof===D||e.$$typeof===s||e.$$typeof===T||e.$$typeof===w||e.$$typeof===g||e.$$typeof===pe||e.getModuleId!==void 0))}function Ze(e,r,t){var n=e.displayName;if(n)return n;var u=r.displayName||r.name||"";return u!==""?t+"("+u+")":t}function ge(e){return e.displayName||"Context"}function N(e){if(e==null)return null;if(typeof e.tag=="number"&&l("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case b:return"Fragment";case O:return"Portal";case P:return"Profiler";case C:return"StrictMode";case S:return"Suspense";case h:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case w:var r=e;return ge(r)+".Consumer";case T:var t=e;return ge(t._context)+".Provider";case g:return Ze(e,e.render,"ForwardRef");case s:var n=e.displayName||null;return n!==null?n:N(e.type)||"Memo";case D:{var u=e,c=u._payload,i=u._init;try{return N(i(c))}catch{return null}}}return null}var F=Object.assign,V=0,he,me,Ee,be,ye,_e,Re;function Ce(){}Ce.__reactDisabledLog=!0;function Qe(){{if(V===0){he=console.log,me=console.info,Ee=console.warn,be=console.error,ye=console.group,_e=console.groupCollapsed,Re=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Ce,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}V++}}function er(){{if(V--,V===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:F({},e,{value:he}),info:F({},e,{value:me}),warn:F({},e,{value:Ee}),error:F({},e,{value:be}),group:F({},e,{value:ye}),groupCollapsed:F({},e,{value:_e}),groupEnd:F({},e,{value:Re})})}V<0&&l("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var te=y.ReactCurrentDispatcher,ne;function B(e,r,t){{if(ne===void 0)try{throw Error()}catch(u){var n=u.stack.trim().match(/\n( *(at )?)/);ne=n&&n[1]||""}return`
|
|
18
|
+
`+ne+e}}var ae=!1,J;{var rr=typeof WeakMap=="function"?WeakMap:Map;J=new rr}function Te(e,r){if(!e||ae)return"";{var t=J.get(e);if(t!==void 0)return t}var n;ae=!0;var u=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var c;c=te.current,te.current=null,Qe();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(k){n=k}Reflect.construct(e,[],i)}else{try{i.call()}catch(k){n=k}e.call(i.prototype)}}else{try{throw Error()}catch(k){n=k}e()}}catch(k){if(k&&n&&typeof k.stack=="string"){for(var a=k.stack.split(`
|
|
19
|
+
`),m=n.stack.split(`
|
|
20
|
+
`),d=a.length-1,v=m.length-1;d>=1&&v>=0&&a[d]!==m[v];)v--;for(;d>=1&&v>=0;d--,v--)if(a[d]!==m[v]){if(d!==1||v!==1)do if(d--,v--,v<0||a[d]!==m[v]){var R=`
|
|
21
|
+
`+a[d].replace(" at new "," at ");return e.displayName&&R.includes("<anonymous>")&&(R=R.replace("<anonymous>",e.displayName)),typeof e=="function"&&J.set(e,R),R}while(d>=1&&v>=0);break}}}finally{ae=!1,te.current=c,er(),Error.prepareStackTrace=u}var $=e?e.displayName||e.name:"",$e=$?B($):"";return typeof e=="function"&&J.set(e,$e),$e}function tr(e,r,t){return Te(e,!1)}function nr(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function G(e,r,t){if(e==null)return"";if(typeof e=="function")return Te(e,nr(e));if(typeof e=="string")return B(e);switch(e){case S:return B("Suspense");case h:return B("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case g:return tr(e.render);case s:return G(e.type,r,t);case D:{var n=e,u=n._payload,c=n._init;try{return G(c(u),r,t)}catch{}}}return""}var z=Object.prototype.hasOwnProperty,De={},Oe=y.ReactDebugCurrentFrame;function K(e){if(e){var r=e._owner,t=G(e.type,e._source,r?r.type:null);Oe.setExtraStackFrame(t)}else Oe.setExtraStackFrame(null)}function ar(e,r,t,n,u){{var c=Function.call.bind(z);for(var i in e)if(c(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var m=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw m.name="Invariant Violation",m}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(d){a=d}a&&!(a instanceof Error)&&(K(u),l("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof a),K(null)),a instanceof Error&&!(a.message in De)&&(De[a.message]=!0,K(u),l("Failed %s type: %s",t,a.message),K(null))}}}var ir=Array.isArray;function ie(e){return ir(e)}function or(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function ur(e){try{return Pe(e),!1}catch{return!0}}function Pe(e){return""+e}function we(e){if(ur(e))return l("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",or(e)),Pe(e)}var U=y.ReactCurrentOwner,sr={key:!0,ref:!0,__self:!0,__source:!0},Se,je,oe;oe={};function cr(e){if(z.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function fr(e){if(z.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function lr(e,r){if(typeof e.ref=="string"&&U.current&&r&&U.current.stateNode!==r){var t=N(U.current.type);oe[t]||(l('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',N(U.current.type),e.ref),oe[t]=!0)}}function dr(e,r){{var t=function(){Se||(Se=!0,l("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function vr(e,r){{var t=function(){je||(je=!0,l("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var pr=function(e,r,t,n,u,c,i){var a={$$typeof:f,type:e,key:r,ref:t,props:i,_owner:c};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:u}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function gr(e,r,t,n,u){{var c,i={},a=null,m=null;t!==void 0&&(we(t),a=""+t),fr(r)&&(we(r.key),a=""+r.key),cr(r)&&(m=r.ref,lr(r,u));for(c in r)z.call(r,c)&&!sr.hasOwnProperty(c)&&(i[c]=r[c]);if(e&&e.defaultProps){var d=e.defaultProps;for(c in d)i[c]===void 0&&(i[c]=d[c])}if(a||m){var v=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&dr(i,v),m&&vr(i,v)}return pr(e,a,m,u,n,U.current,i)}}var ue=y.ReactCurrentOwner,xe=y.ReactDebugCurrentFrame;function I(e){if(e){var r=e._owner,t=G(e.type,e._source,r?r.type:null);xe.setExtraStackFrame(t)}else xe.setExtraStackFrame(null)}var se;se=!1;function ce(e){return typeof e=="object"&&e!==null&&e.$$typeof===f}function Ne(){{if(ue.current){var e=N(ue.current.type);if(e)return`
|
|
22
|
+
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function hr(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
|
|
24
|
+
|
|
25
|
+
Check your code at `+r+":"+t+"."}return""}}var ke={};function mr(e){{var r=Ne();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
|
|
26
|
+
|
|
27
|
+
Check the top-level render call using <`+t+">.")}return r}}function Fe(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=mr(r);if(ke[t])return;ke[t]=!0;var n="";e&&e._owner&&e._owner!==ue.current&&(n=" It was passed a child from "+N(e._owner.type)+"."),I(e),l('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),I(null)}}function Ae(e,r){{if(typeof e!="object")return;if(ie(e))for(var t=0;t<e.length;t++){var n=e[t];ce(n)&&Fe(n,r)}else if(ce(e))e._store&&(e._store.validated=!0);else if(e){var u=q(e);if(typeof u=="function"&&u!==e.entries)for(var c=u.call(e),i;!(i=c.next()).done;)ce(i.value)&&Fe(i.value,r)}}}function Er(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===g||r.$$typeof===s))t=r.propTypes;else return;if(t){var n=N(r);ar(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!se){se=!0;var u=N(r);l("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",u||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&l("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function br(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){I(e),l("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),I(null);break}}e.ref!==null&&(I(e),l("Invalid attribute `ref` supplied to `React.Fragment`."),I(null))}}function Ie(e,r,t,n,u,c){{var i=Xe(e);if(!i){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var m=hr(u);m?a+=m:a+=Ne();var d;e===null?d="null":ie(e)?d="array":e!==void 0&&e.$$typeof===f?(d="<"+(N(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):d=typeof e,l("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",d,a)}var v=gr(e,r,t,u,c);if(v==null)return v;if(i){var R=r.children;if(R!==void 0)if(n)if(ie(R)){for(var $=0;$<R.length;$++)Ae(R[$],e);Object.freeze&&Object.freeze(R)}else l("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ae(R,e)}return e===b?br(v):Er(v),v}}function yr(e,r,t){return Ie(e,r,t,!0)}function _r(e,r,t){return Ie(e,r,t,!1)}var Rr=_r,Cr=yr;M.Fragment=b,M.jsx=Rr,M.jsxs=Cr}()),M}(function(o){process.env.NODE_ENV==="production"?o.exports=Le():o.exports=Ve()})(Z);const Q=Z.exports.Fragment,A=Z.exports.jsx;class de extends W.default.Component{render(){if(this.props.niceDag&&this.props.node.ref){const f=this.props.niceDag.getElementByNodeId(this.props.node.id);if(f)return X.default.createPortal(A(Q,{children:this.props.render(this.props)}),f)}return null}}class ve extends W.default.Component{render(){return this.props.niceDag&&this.props.edge.ref?X.default.createPortal(A(Q,{children:this.props.render(this.props)}),this.props.edge.ref):null}}class Ue extends W.default.Component{render(){if(this.props.niceDag){const f=this.props.niceDag.getRootContentElement();return X.default.createPortal(A(Q,{children:this.props.render(this.props.niceDag)}),f)}return null}}function qe(o){const f=p.useCallback(()=>{o.remove()},[o]),O=p.useCallback((b,C=40)=>{o.insertNodes(b,C)},[o]);return{onEdgeRemove:f,onNodeInsert:O}}function Be({node:o,niceDag:f}){const O=p.useCallback(()=>{o.remove()},[o]),b=p.useCallback(P=>{f.startEdgeDragging(o,P)},[f,o]),C=p.useCallback(P=>{f.startNodeDragging(o,P)},[f,o]);return{onNodeRemove:O,startEdgeDragging:b,startNodeDragging:C}}function Je(o){const{initNodes:f}=o;if(!f)throw new Error("initNodes can't be undefined!")}function Ge(o){Je(o);const{onMount:f,renderNode:O,renderRootView:b,renderEdge:C,scrollPosition:P,initNodes:T,minimapConfig:w,...g}=o,S=p.useRef(null),h=p.useRef(null),s=p.useRef(null),D=p.useRef(),[_,j]=p.useState(0),ee=p.useCallback(()=>{s.current&&s.current.destory()},[j]),q=p.useMemo(()=>({onChange:()=>{j(_+1)}}),[j,_]);return p.useEffect(()=>{if(D.current!==T){if(!s.current){const y=Me.default.init({container:S.current,minimapContainer:h.current,minimapConfig:w,...g},o.editable);s.current=y}s.current.withNodes(T).render(),j(_+1),D.current=T,f&&f()}return s.current.addNiceDagChangeListener(q),()=>{s.current.removeNiceDagChangeListener(q)}},[T,j,_,f]),p.useEffect(()=>(s.current&&s.current.isDestoried&&(s.current.withNodes(T).render(),j(_+1)),()=>{s.current&&s.current.destory()}),[]),{niceDag:s.current,niceDagEl:S,minimapEl:h,render:()=>{if(s.current){const y=s.current.getAllNodes();let l=(y==null?void 0:y.length)>0?y.map(x=>A(de,{render:O,node:x,niceDag:s.current,patchVersion:_},x.id)):null;if(b&&(l=[...l,A(Ue,{niceDag:s.current,render:b})]),C){const x=s.current.getAllEdges(),re=(x==null?void 0:x.length)>0?x.map(L=>A(ve,{render:C,edge:L,patchVersion:_,niceDag:s.current},`edge-${L.source.id}-${L.target.id}`)):[];l=[...l,...re]}return l}return null},reset:ee}}E.NiceDagEdge=ve,E.NiceDagNode=de,E.useNiceDag=Ge,E.useNiceDagEdge=qe,E.useNiceDagNode=Be,Object.defineProperties(E,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebay/nice-dag-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/index.cjs",
|
|
7
|
+
"module": "./lib/index.js",
|
|
8
|
+
"types": "./lib/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./lib/index.js",
|
|
12
|
+
"require": "./lib/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
8
15
|
"repository": "https://github.com/eBay/nice-dag",
|
|
9
16
|
"publishConfig": {
|
|
10
17
|
"access": "public",
|
|
@@ -62,6 +69,7 @@
|
|
|
62
69
|
"@types/react-dom": "18.0.6",
|
|
63
70
|
"@typescript-eslint/eslint-plugin": "^4.28.2",
|
|
64
71
|
"@typescript-eslint/parser": "^4.28.2",
|
|
72
|
+
"@vitejs/plugin-react": "^2.1.0",
|
|
65
73
|
"babel-preset-react-app": "^10.0.0",
|
|
66
74
|
"codecov": "^3.8.3",
|
|
67
75
|
"eslint": "^7.30.0",
|
|
@@ -75,13 +83,12 @@
|
|
|
75
83
|
"react-app-polyfill": "^3.0.0",
|
|
76
84
|
"react-dom": "^18.2.0",
|
|
77
85
|
"typedoc": "^0.21.7",
|
|
78
|
-
"typescript": "^4.3.5"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"glob-parent": "6.0.1"
|
|
86
|
+
"typescript": "^4.3.5",
|
|
87
|
+
"vite": "^3.1.8",
|
|
88
|
+
"vite-plugin-dts": "^1.6.6"
|
|
82
89
|
},
|
|
83
90
|
"dependencies": {
|
|
84
|
-
"@ebay/nice-dag-core": "^1.0.
|
|
91
|
+
"@ebay/nice-dag-core": "^1.0.9"
|
|
85
92
|
},
|
|
86
93
|
"peerDependencies": {
|
|
87
94
|
"react": ">16.8.0",
|
|
@@ -106,10 +113,10 @@
|
|
|
106
113
|
"dnd"
|
|
107
114
|
],
|
|
108
115
|
"scripts": {
|
|
109
|
-
"build": "rm -rf lib && pnpm build:esm && pnpm build:
|
|
110
|
-
"build:esm": "
|
|
111
|
-
"build:
|
|
112
|
-
"dev": "
|
|
116
|
+
"build": "rm -rf lib && pnpm build:esm && pnpm build:umd",
|
|
117
|
+
"build:esm": "vite build",
|
|
118
|
+
"build:umd": "vite build -c vite.config.umd.ts",
|
|
119
|
+
"dev": "vite build -w",
|
|
113
120
|
"codecov": "codecov",
|
|
114
121
|
"gendoc": "typedoc",
|
|
115
122
|
"test": "jest",
|
package/lib/cjs/index.js
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
-
if (k2 === undefined) k2 = k;
|
|
30
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
-
}
|
|
34
|
-
Object.defineProperty(o, k2, desc);
|
|
35
|
-
}) : (function(o, m, k, k2) {
|
|
36
|
-
if (k2 === undefined) k2 = k;
|
|
37
|
-
o[k2] = m[k];
|
|
38
|
-
}));
|
|
39
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
-
}) : function(o, v) {
|
|
42
|
-
o["default"] = v;
|
|
43
|
-
});
|
|
44
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
45
|
-
if (mod && mod.__esModule) return mod;
|
|
46
|
-
var result = {};
|
|
47
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
48
|
-
__setModuleDefault(result, mod);
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
52
|
-
var t = {};
|
|
53
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
54
|
-
t[p] = s[p];
|
|
55
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
56
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
57
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
58
|
-
t[p[i]] = s[p[i]];
|
|
59
|
-
}
|
|
60
|
-
return t;
|
|
61
|
-
};
|
|
62
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
63
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
64
|
-
if (ar || !(i in from)) {
|
|
65
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
66
|
-
ar[i] = from[i];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
70
|
-
};
|
|
71
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
72
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
73
|
-
};
|
|
74
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
|
-
exports.useNiceDag = exports.useNiceDagNode = exports.useNiceDagEdge = exports.NiceDagEdge = exports.NiceDagNode = void 0;
|
|
76
|
-
var react_1 = __importStar(require("react"));
|
|
77
|
-
var react_dom_1 = __importDefault(require("react-dom"));
|
|
78
|
-
var nice_dag_core_1 = __importDefault(require("@ebay/nice-dag-core"));
|
|
79
|
-
var NiceDagNode = /** @class */ (function (_super) {
|
|
80
|
-
__extends(NiceDagNode, _super);
|
|
81
|
-
function NiceDagNode() {
|
|
82
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
83
|
-
}
|
|
84
|
-
NiceDagNode.prototype.render = function () {
|
|
85
|
-
if (this.props.niceDag && this.props.node.ref) {
|
|
86
|
-
var domRef = this.props.niceDag.getElementByNodeId(this.props.node.id);
|
|
87
|
-
if (domRef) {
|
|
88
|
-
return react_dom_1.default.createPortal(react_1.default.createElement(react_1.default.Fragment, null, this.props.render(this.props)), domRef);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
};
|
|
93
|
-
return NiceDagNode;
|
|
94
|
-
}(react_1.default.Component));
|
|
95
|
-
exports.NiceDagNode = NiceDagNode;
|
|
96
|
-
;
|
|
97
|
-
var NiceDagEdge = /** @class */ (function (_super) {
|
|
98
|
-
__extends(NiceDagEdge, _super);
|
|
99
|
-
function NiceDagEdge() {
|
|
100
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
101
|
-
}
|
|
102
|
-
NiceDagEdge.prototype.render = function () {
|
|
103
|
-
if (this.props.niceDag && this.props.edge.ref) {
|
|
104
|
-
return react_dom_1.default.createPortal(react_1.default.createElement(react_1.default.Fragment, null, this.props.render(this.props)), this.props.edge.ref);
|
|
105
|
-
}
|
|
106
|
-
return null;
|
|
107
|
-
};
|
|
108
|
-
return NiceDagEdge;
|
|
109
|
-
}(react_1.default.Component));
|
|
110
|
-
exports.NiceDagEdge = NiceDagEdge;
|
|
111
|
-
;
|
|
112
|
-
function useNiceDagEdge(edge) {
|
|
113
|
-
var onEdgeRemove = (0, react_1.useCallback)(function () {
|
|
114
|
-
edge.remove();
|
|
115
|
-
}, [edge]);
|
|
116
|
-
var onNodeInsert = (0, react_1.useCallback)(function (nodes, offset) {
|
|
117
|
-
if (offset === void 0) { offset = 40; }
|
|
118
|
-
edge.insertNodes(nodes, offset);
|
|
119
|
-
}, [edge]);
|
|
120
|
-
return { onEdgeRemove: onEdgeRemove, onNodeInsert: onNodeInsert };
|
|
121
|
-
}
|
|
122
|
-
exports.useNiceDagEdge = useNiceDagEdge;
|
|
123
|
-
function useNiceDagNode(_a) {
|
|
124
|
-
var node = _a.node, niceDag = _a.niceDag;
|
|
125
|
-
var onNodeRemove = (0, react_1.useCallback)(function () {
|
|
126
|
-
node.remove();
|
|
127
|
-
}, [node]);
|
|
128
|
-
var startEdgeDragging = (0, react_1.useCallback)(function (e) {
|
|
129
|
-
niceDag.startEdgeDragging(node, e);
|
|
130
|
-
}, [niceDag, node]);
|
|
131
|
-
var startNodeDragging = (0, react_1.useCallback)(function (e) {
|
|
132
|
-
niceDag.startNodeDragging(node, e);
|
|
133
|
-
}, [niceDag, node]);
|
|
134
|
-
return { onNodeRemove: onNodeRemove, startEdgeDragging: startEdgeDragging, startNodeDragging: startNodeDragging };
|
|
135
|
-
}
|
|
136
|
-
exports.useNiceDagNode = useNiceDagNode;
|
|
137
|
-
function validateProps(args) {
|
|
138
|
-
var initNodes = args.initNodes;
|
|
139
|
-
if (!initNodes) {
|
|
140
|
-
throw new Error("initNodes can't be undefined!");
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function useNiceDag(args) {
|
|
144
|
-
validateProps(args);
|
|
145
|
-
var onMount = args.onMount, renderNode = args.renderNode, renderEdge = args.renderEdge, scrollPosition = args.scrollPosition, initNodes = args.initNodes, minimapConfig = args.minimapConfig, niceDagConfig = __rest(args, ["onMount", "renderNode", "renderEdge", "scrollPosition", "initNodes", "minimapConfig"]);
|
|
146
|
-
var niceDagEl = (0, react_1.useRef)(null);
|
|
147
|
-
var minimapEl = (0, react_1.useRef)(null);
|
|
148
|
-
var niceDagRef = (0, react_1.useRef)(null);
|
|
149
|
-
var prevInitNodesRef = (0, react_1.useRef)();
|
|
150
|
-
var _a = (0, react_1.useState)(0), patchVersion = _a[0], setPatchVersion = _a[1];
|
|
151
|
-
var reset = (0, react_1.useCallback)(function () {
|
|
152
|
-
if (niceDagRef.current) {
|
|
153
|
-
niceDagRef.current.destory();
|
|
154
|
-
}
|
|
155
|
-
}, [setPatchVersion]);
|
|
156
|
-
var onNiceDagChange = (0, react_1.useMemo)(function () {
|
|
157
|
-
return {
|
|
158
|
-
onChange: function () {
|
|
159
|
-
setPatchVersion(patchVersion + 1);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
}, [setPatchVersion, patchVersion]);
|
|
163
|
-
(0, react_1.useEffect)(function () {
|
|
164
|
-
if (prevInitNodesRef.current !== initNodes) {
|
|
165
|
-
if (!niceDagRef.current) {
|
|
166
|
-
var niceDag = nice_dag_core_1.default.init(__assign({ container: niceDagEl.current, minimapContainer: minimapEl.current, minimapConfig: minimapConfig }, niceDagConfig), args.editable);
|
|
167
|
-
niceDagRef.current = niceDag;
|
|
168
|
-
}
|
|
169
|
-
niceDagRef.current.withNodes(initNodes).render();
|
|
170
|
-
setPatchVersion(patchVersion + 1);
|
|
171
|
-
prevInitNodesRef.current = initNodes;
|
|
172
|
-
onMount && onMount();
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Add listener here is to pass onChange closure variables "patchVersion"
|
|
176
|
-
*/
|
|
177
|
-
niceDagRef.current.addNiceDagChangeListener(onNiceDagChange);
|
|
178
|
-
return function () {
|
|
179
|
-
niceDagRef.current.removeNiceDagChangeListener(onNiceDagChange);
|
|
180
|
-
};
|
|
181
|
-
}, [initNodes, setPatchVersion, patchVersion, onMount]);
|
|
182
|
-
/**
|
|
183
|
-
* Just clean when the component is removed
|
|
184
|
-
*/
|
|
185
|
-
(0, react_1.useEffect)(function () {
|
|
186
|
-
if (niceDagRef.current && niceDagRef.current.isDestoried) {
|
|
187
|
-
niceDagRef.current.withNodes(initNodes).render();
|
|
188
|
-
setPatchVersion(patchVersion + 1);
|
|
189
|
-
}
|
|
190
|
-
return function () {
|
|
191
|
-
if (niceDagRef.current) {
|
|
192
|
-
niceDagRef.current.destory();
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
}, []);
|
|
196
|
-
return {
|
|
197
|
-
niceDag: niceDagRef.current,
|
|
198
|
-
niceDagEl: niceDagEl,
|
|
199
|
-
minimapEl: minimapEl,
|
|
200
|
-
render: function () {
|
|
201
|
-
if (niceDagRef.current) {
|
|
202
|
-
var allNodes = niceDagRef.current.getAllNodes();
|
|
203
|
-
var elements = (allNodes === null || allNodes === void 0 ? void 0 : allNodes.length) > 0 ? allNodes.map(function (node) { return react_1.default.createElement(NiceDagNode, { render: renderNode, node: node, key: node.id, niceDag: niceDagRef.current, patchVersion: patchVersion }); }) : null;
|
|
204
|
-
if (renderEdge) {
|
|
205
|
-
var allEdges = niceDagRef.current.getAllEdges();
|
|
206
|
-
var edgeElements = (allEdges === null || allEdges === void 0 ? void 0 : allEdges.length) > 0 ? allEdges.map(function (edge) {
|
|
207
|
-
return react_1.default.createElement(NiceDagEdge, { render: renderEdge, edge: edge, patchVersion: patchVersion, key: "edge-".concat(edge.source.id, "-").concat(edge.target.id), niceDag: niceDagRef.current });
|
|
208
|
-
}) : [];
|
|
209
|
-
elements = __spreadArray(__spreadArray([], elements, true), edgeElements, true);
|
|
210
|
-
}
|
|
211
|
-
return elements;
|
|
212
|
-
}
|
|
213
|
-
return null;
|
|
214
|
-
},
|
|
215
|
-
reset: reset
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
exports.useNiceDag = useNiceDag;
|
package/lib/esm/index.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import React, { MutableRefObject } from 'react';
|
|
2
|
-
import NiceDagTypes, { IEdge, MinimapConfig } from '@ebay/nice-dag-core/lib/esm/types';
|
|
3
|
-
export declare type UseNiceDagArgs = Omit<NiceDagTypes.NiceDagInitArgs, 'container'> & {
|
|
4
|
-
renderNode: (props: NiceDagNodeProps) => React.Component<any, any, any>;
|
|
5
|
-
renderEdge?: (props: NiceDagEdgeProps) => React.Component<any, any, any>;
|
|
6
|
-
scrollPosition?: NiceDagTypes.Point;
|
|
7
|
-
initNodes?: NiceDagTypes.Node[];
|
|
8
|
-
onMount?: () => void;
|
|
9
|
-
editable?: boolean;
|
|
10
|
-
minimapConfig?: MinimapConfig;
|
|
11
|
-
};
|
|
12
|
-
declare type RenderNodeType = UseNiceDagArgs['renderNode'];
|
|
13
|
-
declare type RenderEdgeType = UseNiceDagArgs['renderEdge'];
|
|
14
|
-
export declare type UseNiceDagType = {
|
|
15
|
-
niceDagEl: MutableRefObject<any>;
|
|
16
|
-
minimapEl: MutableRefObject<any>;
|
|
17
|
-
niceDag: NiceDagTypes.NiceDag;
|
|
18
|
-
render: () => JSX.Element[];
|
|
19
|
-
reset: () => void;
|
|
20
|
-
};
|
|
21
|
-
export interface NiceDagNodeProps {
|
|
22
|
-
node: NiceDagTypes.IViewNode;
|
|
23
|
-
render: RenderNodeType;
|
|
24
|
-
niceDag: NiceDagTypes.NiceDag;
|
|
25
|
-
patchVersion: number;
|
|
26
|
-
}
|
|
27
|
-
export interface NiceDagEdgeProps {
|
|
28
|
-
niceDag: NiceDagTypes.NiceDag;
|
|
29
|
-
edge: NiceDagTypes.IEdge;
|
|
30
|
-
render: RenderEdgeType;
|
|
31
|
-
patchVersion: number;
|
|
32
|
-
}
|
|
33
|
-
export declare class NiceDagNode extends React.Component<NiceDagNodeProps, any> {
|
|
34
|
-
render(): React.ReactPortal;
|
|
35
|
-
}
|
|
36
|
-
export declare class NiceDagEdge extends React.Component<NiceDagEdgeProps, any> {
|
|
37
|
-
render(): React.ReactPortal;
|
|
38
|
-
}
|
|
39
|
-
export declare type DagViewProps = Omit<NiceDagTypes.NiceDagInitArgs, 'container'> & {
|
|
40
|
-
initNodes?: NiceDagTypes.Node[];
|
|
41
|
-
renderHeader: () => React.Component<any, any>;
|
|
42
|
-
renderFooter: () => React.Component<any, any>;
|
|
43
|
-
renderNode: (props: NiceDagNodeProps) => React.Component<any, any>;
|
|
44
|
-
onMount?: () => void;
|
|
45
|
-
editable?: boolean;
|
|
46
|
-
};
|
|
47
|
-
export declare function useNiceDagEdge(edge: IEdge): {
|
|
48
|
-
onEdgeRemove: () => void;
|
|
49
|
-
onNodeInsert: (nodes: NiceDagTypes.Node[], offset: number) => void;
|
|
50
|
-
};
|
|
51
|
-
export declare function useNiceDagNode({ node, niceDag }: {
|
|
52
|
-
node: NiceDagTypes.IViewNode;
|
|
53
|
-
niceDag: NiceDagTypes.IWritableNiceDag;
|
|
54
|
-
}): {
|
|
55
|
-
onNodeRemove: () => void;
|
|
56
|
-
startEdgeDragging: (e: MouseEvent) => void;
|
|
57
|
-
startNodeDragging: (e: MouseEvent) => void;
|
|
58
|
-
};
|
|
59
|
-
export declare function useNiceDag(args: UseNiceDagArgs): UseNiceDagType;
|
|
60
|
-
export {};
|
package/lib/esm/index.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
|
17
|
-
__assign = Object.assign || function(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
-
t[p] = s[p];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
return __assign.apply(this, arguments);
|
|
26
|
-
};
|
|
27
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
28
|
-
var t = {};
|
|
29
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
30
|
-
t[p] = s[p];
|
|
31
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
32
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
33
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
34
|
-
t[p[i]] = s[p[i]];
|
|
35
|
-
}
|
|
36
|
-
return t;
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
|
-
import React, { useEffect, useState, useRef, useCallback, useMemo } from 'react';
|
|
48
|
-
import ReactDOM from 'react-dom';
|
|
49
|
-
import NiceDag from '@ebay/nice-dag-core';
|
|
50
|
-
var NiceDagNode = /** @class */ (function (_super) {
|
|
51
|
-
__extends(NiceDagNode, _super);
|
|
52
|
-
function NiceDagNode() {
|
|
53
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
54
|
-
}
|
|
55
|
-
NiceDagNode.prototype.render = function () {
|
|
56
|
-
if (this.props.niceDag && this.props.node.ref) {
|
|
57
|
-
var domRef = this.props.niceDag.getElementByNodeId(this.props.node.id);
|
|
58
|
-
if (domRef) {
|
|
59
|
-
return ReactDOM.createPortal(React.createElement(React.Fragment, null, this.props.render(this.props)), domRef);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
};
|
|
64
|
-
return NiceDagNode;
|
|
65
|
-
}(React.Component));
|
|
66
|
-
export { NiceDagNode };
|
|
67
|
-
;
|
|
68
|
-
var NiceDagEdge = /** @class */ (function (_super) {
|
|
69
|
-
__extends(NiceDagEdge, _super);
|
|
70
|
-
function NiceDagEdge() {
|
|
71
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
72
|
-
}
|
|
73
|
-
NiceDagEdge.prototype.render = function () {
|
|
74
|
-
if (this.props.niceDag && this.props.edge.ref) {
|
|
75
|
-
return ReactDOM.createPortal(React.createElement(React.Fragment, null, this.props.render(this.props)), this.props.edge.ref);
|
|
76
|
-
}
|
|
77
|
-
return null;
|
|
78
|
-
};
|
|
79
|
-
return NiceDagEdge;
|
|
80
|
-
}(React.Component));
|
|
81
|
-
export { NiceDagEdge };
|
|
82
|
-
;
|
|
83
|
-
export function useNiceDagEdge(edge) {
|
|
84
|
-
var onEdgeRemove = useCallback(function () {
|
|
85
|
-
edge.remove();
|
|
86
|
-
}, [edge]);
|
|
87
|
-
var onNodeInsert = useCallback(function (nodes, offset) {
|
|
88
|
-
if (offset === void 0) { offset = 40; }
|
|
89
|
-
edge.insertNodes(nodes, offset);
|
|
90
|
-
}, [edge]);
|
|
91
|
-
return { onEdgeRemove: onEdgeRemove, onNodeInsert: onNodeInsert };
|
|
92
|
-
}
|
|
93
|
-
export function useNiceDagNode(_a) {
|
|
94
|
-
var node = _a.node, niceDag = _a.niceDag;
|
|
95
|
-
var onNodeRemove = useCallback(function () {
|
|
96
|
-
node.remove();
|
|
97
|
-
}, [node]);
|
|
98
|
-
var startEdgeDragging = useCallback(function (e) {
|
|
99
|
-
niceDag.startEdgeDragging(node, e);
|
|
100
|
-
}, [niceDag, node]);
|
|
101
|
-
var startNodeDragging = useCallback(function (e) {
|
|
102
|
-
niceDag.startNodeDragging(node, e);
|
|
103
|
-
}, [niceDag, node]);
|
|
104
|
-
return { onNodeRemove: onNodeRemove, startEdgeDragging: startEdgeDragging, startNodeDragging: startNodeDragging };
|
|
105
|
-
}
|
|
106
|
-
function validateProps(args) {
|
|
107
|
-
var initNodes = args.initNodes;
|
|
108
|
-
if (!initNodes) {
|
|
109
|
-
throw new Error("initNodes can't be undefined!");
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
export function useNiceDag(args) {
|
|
113
|
-
validateProps(args);
|
|
114
|
-
var onMount = args.onMount, renderNode = args.renderNode, renderEdge = args.renderEdge, scrollPosition = args.scrollPosition, initNodes = args.initNodes, minimapConfig = args.minimapConfig, niceDagConfig = __rest(args, ["onMount", "renderNode", "renderEdge", "scrollPosition", "initNodes", "minimapConfig"]);
|
|
115
|
-
var niceDagEl = useRef(null);
|
|
116
|
-
var minimapEl = useRef(null);
|
|
117
|
-
var niceDagRef = useRef(null);
|
|
118
|
-
var prevInitNodesRef = useRef();
|
|
119
|
-
var _a = useState(0), patchVersion = _a[0], setPatchVersion = _a[1];
|
|
120
|
-
var reset = useCallback(function () {
|
|
121
|
-
if (niceDagRef.current) {
|
|
122
|
-
niceDagRef.current.destory();
|
|
123
|
-
}
|
|
124
|
-
}, [setPatchVersion]);
|
|
125
|
-
var onNiceDagChange = useMemo(function () {
|
|
126
|
-
return {
|
|
127
|
-
onChange: function () {
|
|
128
|
-
setPatchVersion(patchVersion + 1);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}, [setPatchVersion, patchVersion]);
|
|
132
|
-
useEffect(function () {
|
|
133
|
-
if (prevInitNodesRef.current !== initNodes) {
|
|
134
|
-
if (!niceDagRef.current) {
|
|
135
|
-
var niceDag = NiceDag.init(__assign({ container: niceDagEl.current, minimapContainer: minimapEl.current, minimapConfig: minimapConfig }, niceDagConfig), args.editable);
|
|
136
|
-
niceDagRef.current = niceDag;
|
|
137
|
-
}
|
|
138
|
-
niceDagRef.current.withNodes(initNodes).render();
|
|
139
|
-
setPatchVersion(patchVersion + 1);
|
|
140
|
-
prevInitNodesRef.current = initNodes;
|
|
141
|
-
onMount && onMount();
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Add listener here is to pass onChange closure variables "patchVersion"
|
|
145
|
-
*/
|
|
146
|
-
niceDagRef.current.addNiceDagChangeListener(onNiceDagChange);
|
|
147
|
-
return function () {
|
|
148
|
-
niceDagRef.current.removeNiceDagChangeListener(onNiceDagChange);
|
|
149
|
-
};
|
|
150
|
-
}, [initNodes, setPatchVersion, patchVersion, onMount]);
|
|
151
|
-
/**
|
|
152
|
-
* Just clean when the component is removed
|
|
153
|
-
*/
|
|
154
|
-
useEffect(function () {
|
|
155
|
-
if (niceDagRef.current && niceDagRef.current.isDestoried) {
|
|
156
|
-
niceDagRef.current.withNodes(initNodes).render();
|
|
157
|
-
setPatchVersion(patchVersion + 1);
|
|
158
|
-
}
|
|
159
|
-
return function () {
|
|
160
|
-
if (niceDagRef.current) {
|
|
161
|
-
niceDagRef.current.destory();
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}, []);
|
|
165
|
-
return {
|
|
166
|
-
niceDag: niceDagRef.current,
|
|
167
|
-
niceDagEl: niceDagEl,
|
|
168
|
-
minimapEl: minimapEl,
|
|
169
|
-
render: function () {
|
|
170
|
-
if (niceDagRef.current) {
|
|
171
|
-
var allNodes = niceDagRef.current.getAllNodes();
|
|
172
|
-
var elements = (allNodes === null || allNodes === void 0 ? void 0 : allNodes.length) > 0 ? allNodes.map(function (node) { return React.createElement(NiceDagNode, { render: renderNode, node: node, key: node.id, niceDag: niceDagRef.current, patchVersion: patchVersion }); }) : null;
|
|
173
|
-
if (renderEdge) {
|
|
174
|
-
var allEdges = niceDagRef.current.getAllEdges();
|
|
175
|
-
var edgeElements = (allEdges === null || allEdges === void 0 ? void 0 : allEdges.length) > 0 ? allEdges.map(function (edge) {
|
|
176
|
-
return React.createElement(NiceDagEdge, { render: renderEdge, edge: edge, patchVersion: patchVersion, key: "edge-".concat(edge.source.id, "-").concat(edge.target.id), niceDag: niceDagRef.current });
|
|
177
|
-
}) : [];
|
|
178
|
-
elements = __spreadArray(__spreadArray([], elements, true), edgeElements, true);
|
|
179
|
-
}
|
|
180
|
-
return elements;
|
|
181
|
-
}
|
|
182
|
-
return null;
|
|
183
|
-
},
|
|
184
|
-
reset: reset
|
|
185
|
-
};
|
|
186
|
-
}
|