@ebay/nice-dag-react 1.0.8 → 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 +8 -8
- package/lib/index.d.ts +5 -0
- package/lib/index.js +299 -284
- package/lib/index.umd.cjs +9 -9
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("react"),vr=require("react-dom"),pr=require("@ebay/nice-dag-core"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("react"),vr=require("react-dom"),pr=require("@ebay/nice-dag-core"),oe=i=>i&&typeof i=="object"&&"default"in i?i:{default:i},V=oe(m),ie=oe(vr),gr=oe(pr);var ue={exports:{}},M={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var ke;function hr(){if(ke)return M;ke=1;var i=V.default,l=Symbol.for("react.element"),D=Symbol.for("react.fragment"),E=Object.prototype.hasOwnProperty,y=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,O={key:!0,ref:!0,__self:!0,__source:!0};function C(P,p,w){var g,s={},T=null,R=null;w!==void 0&&(T=""+w),p.key!==void 0&&(T=""+p.key),p.ref!==void 0&&(R=p.ref);for(g in p)E.call(p,g)&&!O.hasOwnProperty(g)&&(s[g]=p[g]);if(P&&P.defaultProps)for(g in p=P.defaultProps,p)s[g]===void 0&&(s[g]=p[g]);return{$$typeof:l,type:P,key:T,ref:R,props:s,_owner:y.current}}return M.Fragment=D,M.jsx=C,M.jsxs=C,M}var L={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+
|
|
17
|
+
*/var Fe;function mr(){return Fe||(Fe=1,process.env.NODE_ENV!=="production"&&function(){var i=V.default,l=Symbol.for("react.element"),D=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),y=Symbol.for("react.strict_mode"),O=Symbol.for("react.profiler"),C=Symbol.for("react.provider"),P=Symbol.for("react.context"),p=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),g=Symbol.for("react.suspense_list"),s=Symbol.for("react.memo"),T=Symbol.for("react.lazy"),R=Symbol.for("react.offscreen"),S=Symbol.iterator,K="@@iterator";function U(e){if(e===null||typeof e!="object")return null;var r=S&&e[S]||e[K];return typeof r=="function"?r:null}var b=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function f(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=b.ReactDebugCurrentFrame,u=n.getStackAddendum();u!==""&&(r+="%s",t=t.concat([u]));var c=t.map(function(o){return String(o)});c.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,c)}}var H=!1,$=!1,$e=!1,We=!1,Ye=!1,ce;ce=Symbol.for("react.module.reference");function Me(e){return!!(typeof e=="string"||typeof e=="function"||e===E||e===O||Ye||e===y||e===w||e===g||We||e===R||H||$||$e||typeof e=="object"&&e!==null&&(e.$$typeof===T||e.$$typeof===s||e.$$typeof===C||e.$$typeof===P||e.$$typeof===p||e.$$typeof===ce||e.getModuleId!==void 0))}function Le(e,r,t){var n=e.displayName;if(n)return n;var u=r.displayName||r.name||"";return u!==""?t+"("+u+")":t}function le(e){return e.displayName||"Context"}function j(e){if(e==null)return null;if(typeof e.tag=="number"&&f("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 E:return"Fragment";case D:return"Portal";case O:return"Profiler";case y:return"StrictMode";case w:return"Suspense";case g:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case P:var r=e;return le(r)+".Consumer";case C:var t=e;return le(t._context)+".Provider";case p:return Le(e,e.render,"ForwardRef");case s:var n=e.displayName||null;return n!==null?n:j(e.type)||"Memo";case T:{var u=e,c=u._payload,o=u._init;try{return j(o(c))}catch{return null}}}return null}var k=Object.assign,W=0,fe,de,ve,pe,ge,he,me;function Ee(){}Ee.__reactDisabledLog=!0;function Ve(){{if(W===0){fe=console.log,de=console.info,ve=console.warn,pe=console.error,ge=console.group,he=console.groupCollapsed,me=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Ee,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}W++}}function Ue(){{if(W--,W===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:k({},e,{value:fe}),info:k({},e,{value:de}),warn:k({},e,{value:ve}),error:k({},e,{value:pe}),group:k({},e,{value:ge}),groupCollapsed:k({},e,{value:he}),groupEnd:k({},e,{value:me})})}W<0&&f("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var X=b.ReactCurrentDispatcher,Z;function q(e,r,t){{if(Z===void 0)try{throw Error()}catch(u){var n=u.stack.trim().match(/\n( *(at )?)/);Z=n&&n[1]||""}return`
|
|
18
|
+
`+Z+e}}var Q=!1,B;{var qe=typeof WeakMap=="function"?WeakMap:Map;B=new qe}function be(e,r){if(!e||Q)return"";{var t=B.get(e);if(t!==void 0)return t}var n;Q=!0;var u=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var c;c=X.current,X.current=null,Ve();try{if(r){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(N){n=N}Reflect.construct(e,[],o)}else{try{o.call()}catch(N){n=N}e.call(o.prototype)}}else{try{throw Error()}catch(N){n=N}e()}}catch(N){if(N&&n&&typeof N.stack=="string"){for(var a=N.stack.split(`
|
|
19
19
|
`),h=n.stack.split(`
|
|
20
20
|
`),d=a.length-1,v=h.length-1;d>=1&&v>=0&&a[d]!==h[v];)v--;for(;d>=1&&v>=0;d--,v--)if(a[d]!==h[v]){if(d!==1||v!==1)do if(d--,v--,v<0||a[d]!==h[v]){var _=`
|
|
21
|
-
`+a[d].replace(" at new "," at ");return e.displayName&&_.includes("<anonymous>")&&(_=_.replace("<anonymous>",e.displayName)),typeof e=="function"&&
|
|
21
|
+
`+a[d].replace(" at new "," at ");return e.displayName&&_.includes("<anonymous>")&&(_=_.replace("<anonymous>",e.displayName)),typeof e=="function"&&B.set(e,_),_}while(d>=1&&v>=0);break}}}finally{Q=!1,X.current=c,Ue(),Error.prepareStackTrace=u}var A=e?e.displayName||e.name:"",Ne=A?q(A):"";return typeof e=="function"&&B.set(e,Ne),Ne}function Be(e,r,t){return be(e,!1)}function Je(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function J(e,r,t){if(e==null)return"";if(typeof e=="function")return be(e,Je(e));if(typeof e=="string")return q(e);switch(e){case w:return q("Suspense");case g:return q("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case p:return Be(e.render);case s:return J(e.type,r,t);case T:{var n=e,u=n._payload,c=n._init;try{return J(c(u),r,t)}catch{}}}return""}var G=Object.prototype.hasOwnProperty,Re={},_e=b.ReactDebugCurrentFrame;function z(e){if(e){var r=e._owner,t=J(e.type,e._source,r?r.type:null);_e.setExtraStackFrame(t)}else _e.setExtraStackFrame(null)}function Ge(e,r,t,n,u){{var c=Function.call.bind(G);for(var o in e)if(c(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var h=Error((n||"React class")+": "+t+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw h.name="Invariant Violation",h}a=e[o](r,o,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(d){a=d}a&&!(a instanceof Error)&&(z(u),f("%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,o,typeof a),z(null)),a instanceof Error&&!(a.message in Re)&&(Re[a.message]=!0,z(u),f("Failed %s type: %s",t,a.message),z(null))}}}var ze=Array.isArray;function ee(e){return ze(e)}function Ke(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function He(e){try{return ye(e),!1}catch{return!0}}function ye(e){return""+e}function Ce(e){if(He(e))return f("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ke(e)),ye(e)}var Y=b.ReactCurrentOwner,Xe={key:!0,ref:!0,__self:!0,__source:!0},Te,De,re;re={};function Ze(e){if(G.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function Qe(e){if(G.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function er(e,r){if(typeof e.ref=="string"&&Y.current&&r&&Y.current.stateNode!==r){var t=j(Y.current.type);re[t]||(f('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',j(Y.current.type),e.ref),re[t]=!0)}}function rr(e,r){{var t=function(){Te||(Te=!0,f("%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 tr(e,r){{var t=function(){De||(De=!0,f("%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 nr=function(e,r,t,n,u,c,o){var a={$$typeof:l,type:e,key:r,ref:t,props:o,_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 ar(e,r,t,n,u){{var c,o={},a=null,h=null;t!==void 0&&(Ce(t),a=""+t),Qe(r)&&(Ce(r.key),a=""+r.key),Ze(r)&&(h=r.ref,er(r,u));for(c in r)G.call(r,c)&&!Xe.hasOwnProperty(c)&&(o[c]=r[c]);if(e&&e.defaultProps){var d=e.defaultProps;for(c in d)o[c]===void 0&&(o[c]=d[c])}if(a||h){var v=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&rr(o,v),h&&tr(o,v)}return nr(e,a,h,u,n,Y.current,o)}}var te=b.ReactCurrentOwner,Oe=b.ReactDebugCurrentFrame;function F(e){if(e){var r=e._owner,t=J(e.type,e._source,r?r.type:null);Oe.setExtraStackFrame(t)}else Oe.setExtraStackFrame(null)}var ne;ne=!1;function ae(e){return typeof e=="object"&&e!==null&&e.$$typeof===l}function Pe(){{if(te.current){var e=j(te.current.type);if(e)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function or(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+r+":"+t+"."}return""}}var
|
|
25
|
+
Check your code at `+r+":"+t+"."}return""}}var we={};function ir(e){{var r=Pe();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+t+">.")}return r}}function
|
|
27
|
+
Check the top-level render call using <`+t+">.")}return r}}function Se(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=ir(r);if(we[t])return;we[t]=!0;var n="";e&&e._owner&&e._owner!==te.current&&(n=" It was passed a child from "+j(e._owner.type)+"."),F(e),f('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),F(null)}}function xe(e,r){{if(typeof e!="object")return;if(ee(e))for(var t=0;t<e.length;t++){var n=e[t];ae(n)&&Se(n,r)}else if(ae(e))e._store&&(e._store.validated=!0);else if(e){var u=U(e);if(typeof u=="function"&&u!==e.entries)for(var c=u.call(e),o;!(o=c.next()).done;)ae(o.value)&&Se(o.value,r)}}}function ur(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===p||r.$$typeof===s))t=r.propTypes;else return;if(t){var n=j(r);Ge(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ne){ne=!0;var u=j(r);f("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",u||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&f("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function sr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){F(e),f("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),F(null);break}}e.ref!==null&&(F(e),f("Invalid attribute `ref` supplied to `React.Fragment`."),F(null))}}function je(e,r,t,n,u,c){{var o=Me(e);if(!o){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 h=or(u);h?a+=h:a+=Pe();var d;e===null?d="null":ee(e)?d="array":e!==void 0&&e.$$typeof===l?(d="<"+(j(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):d=typeof e,f("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=ar(e,r,t,u,c);if(v==null)return v;if(o){var _=r.children;if(_!==void 0)if(n)if(ee(_)){for(var A=0;A<_.length;A++)xe(_[A],e);Object.freeze&&Object.freeze(_)}else f("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 xe(_,e)}return e===E?sr(v):ur(v),v}}function cr(e,r,t){return je(e,r,t,!0)}function lr(e,r,t){return je(e,r,t,!1)}var fr=lr,dr=cr;L.Fragment=E,L.jsx=fr,L.jsxs=dr}()),L}(function(i){process.env.NODE_ENV==="production"?i.exports=hr():i.exports=mr()})(ue);const se=ue.exports.Fragment,I=ue.exports.jsx;class Ae extends V.default.Component{render(){if(this.props.niceDag&&this.props.node.ref){const l=this.props.niceDag.getElementByNodeId(this.props.node.id);if(l)return ie.default.createPortal(I(se,{children:this.props.render(this.props)}),l)}return null}}class Ie extends V.default.Component{render(){return this.props.niceDag&&this.props.edge.ref?ie.default.createPortal(I(se,{children:this.props.render(this.props)}),this.props.edge.ref):null}}class Er extends V.default.Component{render(){if(this.props.niceDag){const l=this.props.niceDag.getRootContentElement();return ie.default.createPortal(I(se,{children:this.props.render(this.props.niceDag)}),l)}return null}}function br(i){const l=m.useCallback(()=>{i.remove()},[i]),D=m.useCallback((E,y=40)=>{i.insertNodes(E,y)},[i]);return{onEdgeRemove:l,onNodeInsert:D}}function Rr({node:i,niceDag:l}){const D=m.useCallback(()=>{i.remove()},[i]),E=m.useCallback(O=>{l.startEdgeDragging(i,O)},[l,i]),y=m.useCallback(O=>{l.startNodeDragging(i,O)},[l,i]);return{onNodeRemove:D,startEdgeDragging:E,startNodeDragging:y}}function _r(i){const{initNodes:l}=i;if(!l)throw new Error("initNodes can't be undefined!")}function yr(i){_r(i);const{onMount:l,renderNode:D,renderRootView:E,renderEdge:y,scrollPosition:O,initNodes:C,minimapConfig:P,...p}=i,w=m.useRef(null),g=m.useRef(null),s=m.useRef(null),T=m.useRef(),[R,S]=m.useState(0),K=m.useCallback(()=>{s.current&&s.current.destory()},[S]),U=m.useMemo(()=>({onChange:()=>{S(R+1)}}),[S,R]);return m.useEffect(()=>{if(T.current!==C){if(!s.current){const b=gr.default.init({container:w.current,minimapContainer:g.current,minimapConfig:P,...p},i.editable);s.current=b}s.current.withNodes(C).render(),S(R+1),T.current=C,l&&l()}return s.current.addNiceDagChangeListener(U),()=>{s.current.removeNiceDagChangeListener(U)}},[C,S,R,l]),m.useEffect(()=>(s.current&&s.current.isDestoried&&(s.current.withNodes(C).render(),S(R+1)),()=>{s.current&&s.current.destory()}),[]),{niceDag:s.current,niceDagEl:w,minimapEl:g,render:()=>{if(s.current){const b=s.current.getAllNodes();let f=(b==null?void 0:b.length)>0?b.map(x=>I(Ae,{render:D,node:x,niceDag:s.current,patchVersion:R},x.id)):null;if(E&&(f=[...f,I(Er,{niceDag:s.current,render:E})]),y){const x=s.current.getAllEdges(),H=(x==null?void 0:x.length)>0?x.map($=>I(Ie,{render:y,edge:$,patchVersion:R,niceDag:s.current},`edge-${$.source.id}-${$.target.id}`)):[];f=[...f,...H]}return f}return null},reset:K}}exports.NiceDagEdge=Ie;exports.NiceDagNode=Ae;exports.useNiceDag=yr;exports.useNiceDagEdge=br;exports.useNiceDagNode=Rr;
|
package/lib/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import NiceDagTypes, { IEdge, MinimapConfig } from '@ebay/nice-dag-core/lib/type
|
|
|
3
3
|
export declare type UseNiceDagArgs = Omit<NiceDagTypes.NiceDagInitArgs, 'container'> & {
|
|
4
4
|
renderNode: (props: NiceDagNodeProps) => React.Component<any, any, any>;
|
|
5
5
|
renderEdge?: (props: NiceDagEdgeProps) => React.Component<any, any, any>;
|
|
6
|
+
renderRootView?: (niceDag: NiceDagTypes.NiceDag) => React.Component<any, any, any>;
|
|
6
7
|
scrollPosition?: NiceDagTypes.Point;
|
|
7
8
|
initNodes?: NiceDagTypes.Node[];
|
|
8
9
|
onMount?: () => void;
|
|
@@ -30,6 +31,10 @@ export interface NiceDagEdgeProps {
|
|
|
30
31
|
render: RenderEdgeType;
|
|
31
32
|
patchVersion: number;
|
|
32
33
|
}
|
|
34
|
+
export interface NiceDagRootViewProps {
|
|
35
|
+
niceDag: NiceDagTypes.NiceDag;
|
|
36
|
+
render: (niceDag: NiceDagTypes.NiceDag) => React.Component<any, any, any>;
|
|
37
|
+
}
|
|
33
38
|
export declare class NiceDagNode extends React.Component<NiceDagNodeProps, any> {
|
|
34
39
|
render(): React.ReactPortal;
|
|
35
40
|
}
|