@joint/react
Version:
React bindings and hooks for JointJS to build interactive diagrams and graphs.
3 lines (2 loc) • 1.37 kB
JavaScript
import{dia as u,shapes as y}from"@joint/core";import{listenToCellChange as f}from"../utils/cell/listen-to-cell-change";import{ReactElement as E}from"../models/react-element";import{setElements as C}from"../utils/cell/set-cells";import{subscribeHandler as g}from"../utils/subscriber-handler";import{createStoreData as S}from"./create-store-data";const p={...y,ReactElement:E};function b(o={}){const{cellModel:i,cellNamespace:e=p,graph:r}=o;return r??new u.Graph({},{cellNamespace:{...p,...e},cellModel:i})}function N(o){const{initialElements:i}=o||{},e=b(o);C({graph:e,initialElements:i});const r=S(),a=g(s),c=f(e,m);r.updateStore(e),e.on("batch:stop",d);const l=new Set;function s(){return r.updateStore(e)}function m(){e.hasActiveBatch()||a.notifySubscribers()}function d(){a.notifySubscribers()}function h(){c(),e.off("batch:stop",d),e.clear(),r.destroy(),l.clear()}return s(),{destroy:h,graph:e,subscribe:a.subscribe,getElements(){return r.elements},getLinks(){return r.links},getElement(t){const n=r.elements.get(t);if(!n)throw new Error(`Element with id ${t} not found`);return n},getLink(t){const n=r.links.get(t);if(!n)throw new Error(`Link with id ${t} not found`);return n},setMeasuredNode(t){return l.add(t),()=>{l.delete(t)}},hasMeasuredNode(t){return l.has(t)}}}export{p as DEFAULT_CELL_NAMESPACE,N as createStore};
//# sourceMappingURL=create-store.js.map