lmdiagram 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 lmoraobando
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ ![GitHub](https://img.shields.io/github/license/lmoraobando/lmdiagram?color=green)
2
+ ![GitHub last commit](https://img.shields.io/github/last-commit/lmoraobando/lmdiagram)
3
+ ![GitHub top language](https://img.shields.io/github/languages/top/lmoraobando/lmdiagram)
4
+
5
+ This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
6
+
7
+ ![image](https://user-images.githubusercontent.com/11163835/133908185-0e1d3cc9-fdcf-4e65-b0b5-c30cda81c212.png)
8
+
9
+ ## A basic example shown on the gif
10
+
11
+ ![test](https://user-images.githubusercontent.com/11163835/133908159-bffd8e10-7386-4336-b008-9d7696b5bcee.gif)
12
+
13
+
14
+ ## Available Scripts
15
+
16
+ In the project directory, you can run:
17
+
18
+ ### `npm start`
19
+
20
+ Runs the app in the development mode.<br>
21
+ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
22
+
23
+ The page will reload if you make edits.<br>
24
+ You will also see any lint errors in the console.
25
+
26
+ ### `npm test`
27
+
28
+ Launches the test runner in the interactive watch mode.<br>
29
+ See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
30
+
31
+ ### `npm run build`
32
+
33
+ Builds the app for production to the `build` folder.<br>
34
+ It correctly bundles React in production mode and optimizes the build for the best performance.
35
+
36
+ The build is minified and the filenames include the hashes.<br>
37
+ Your app is ready to be deployed!
38
+
39
+ See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
40
+
41
+ ### `npm run eject`
42
+
43
+ **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
44
+
45
+ If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
46
+
47
+ Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
48
+
49
+ You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
50
+
51
+ ## Learn More
52
+
53
+ You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
54
+
55
+ To learn React, check out the [React documentation](https://reactjs.org/).
56
+
57
+ ### Code Splitting
58
+
59
+ This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
60
+
61
+ ### Analyzing the Bundle Size
62
+
63
+ This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
64
+
65
+ ### Making a Progressive Web App
66
+
67
+ This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
68
+
69
+ ### Advanced Configuration
70
+
71
+ This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
72
+
73
+ ### Deployment
74
+
75
+ This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
76
+
77
+ ### `npm run build` fails to minify
78
+
79
+ This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),I=require("react"),M="http://www.w3.org/2000/svg";function $(i,t,l,e,d){const o=1-i,n=o*o*o,r=3*o*o*i,u=3*o*i*i,g=i*i*i;return{x:n*t.x+r*l.x+u*e.x+g*d.x,y:n*t.y+r*l.y+u*e.y+g*d.y}}function C({associationModel:i}){const t=I.useRef(i);t.current=i;const l=I.useCallback(e=>{var d;if(e!=null&&e.AssociationModel)for(const o of e.AssociationModel){const n=document.getElementById(o.from),r=document.getElementById(o.to);if(!n||!r)continue;let u=0,g=0,s=0,h=0;const p=parseInt(((d=o.line_Associate_id)==null?void 0:d.substring(7))??"0",10);u=n.offsetLeft,g=n.offsetTop+n.offsetHeight/2,s=r.offsetLeft,h=r.offsetTop+r.offsetHeight/2;const f=document.getElementById(o.line_Associate_id);if(!f)continue;const c={x:u+150,y:g},y={x:s-100,y:g},x={x:s-20,y:h},v={x:s-10,y:h};f.setAttribute("d",`M${c.x},${c.y} C${y.x},${y.y} ${x.x},${x.y} ${v.x},${v.y}`);const A=`${o.line_Associate_id}_label`,b=document.getElementById(A);if(b&&o.label){const m=$(.5,c,y,x,v);b.setAttribute("x",m.x),b.setAttribute("y",m.y)}}},[]);return I.useEffect(()=>{var g;const e=i;if(!((g=e==null?void 0:e.AssociationModel)!=null&&g.length))return;const d=document.getElementById("gLines");if(!d)return;let o=0;const n=[],r=new Set,u=s=>{if(!s||r.has(s.id))return;r.add(s.id);let h=0,p=0,f=0,c=0;const y=m=>{m.preventDefault(),f=m.clientX,c=m.clientY,document.addEventListener("mouseup",v),document.addEventListener("mousemove",x)},x=m=>{const L=document.getElementById("lmDiagramSvg");if(!L)return;m.preventDefault(),h=f-m.clientX,p=c-m.clientY,f=m.clientX,c=m.clientY;const _=s.offsetTop-p,E=s.offsetLeft-h;m.clientY<=L.clientHeight&&m.clientY>=130&&E+s.clientWidth<=L.clientWidth&&E>=0&&(s.style.top=`${_}px`,s.style.left=`${E}px`),l(t.current)},v=()=>{document.removeEventListener("mouseup",v),document.removeEventListener("mousemove",x)},b=document.getElementById(`${s.id}header`)??s;b.addEventListener("mousedown",y),n.push(()=>{b.removeEventListener("mousedown",y),document.removeEventListener("mouseup",v),document.removeEventListener("mousemove",x)})};for(const s of e.AssociationModel){const h=`ulmLine${o}`,p=document.createElementNS(M,"g");p.setAttribute("class","lm-diagram-link");const f=document.createElementNS(M,"path");if(f.setAttribute("marker-end","url(#arrowhead)"),f.setAttribute("class","lm-diagram-path"),f.setAttribute("id",h),p.appendChild(f),s.label){const c=document.createElementNS(M,"text");c.setAttribute("id",`${h}_label`),c.setAttribute("class","lm-diagram-link-label"),c.setAttribute("text-anchor","middle"),c.setAttribute("dominant-baseline","middle"),c.textContent=s.label,p.appendChild(c)}d.appendChild(p),s.line_Associate_id=h,u(document.getElementById(s.from)),u(document.getElementById(s.to)),o++}return l(e),()=>{for(n.forEach(s=>s());d.firstChild;)d.removeChild(d.firstChild)}},[i,l]),null}function N({width:i="100%",height:t=350}){const l=I.useId().replace(/:/g,"");return a.jsxs("svg",{className:"lm-diagram-svg",id:"lmDiagramSvg",xmlns:"http://www.w3.org/2000/svg",width:i,height:t,"aria-labelledby":l,children:[a.jsx("title",{id:l,children:"Diagram connections"}),a.jsx("defs",{children:a.jsx("marker",{id:"arrowhead",viewBox:"0 0 10 10",refX:"3",refY:"5",markerWidth:"6",markerHeight:"6",orient:"auto",children:a.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--lm-arrow, #6366f1)"})})}),a.jsx("g",{fill:"none",stroke:"var(--lm-line, #6366f1)",id:"gLines",strokeWidth:"2",markerEnd:"url(#arrowhead)"})]})}function S({association:i}){var l;const t=((l=i==null?void 0:i.BuildDiagram)==null?void 0:l.listModels)??[];return a.jsxs("div",{className:"lm-diagram-canvas",children:[a.jsx("div",{className:"lm-diagram-nodes","aria-label":"Diagram models",children:t.map((e,d)=>a.jsxs("div",{className:"lm-diagram-node",style:{top:e.top,left:e.left,width:e.width,minHeight:e.height??102},id:e.Id,children:[a.jsx("div",{className:"lm-diagram-node__header",children:e.header}),a.jsx("div",{className:"lm-diagram-node__body",children:a.jsx("span",{className:"lm-diagram-node__label",children:e.body})})]},e.Id??d))}),a.jsx("div",{className:"lm-diagram-svg-wrap",children:a.jsx(N,{width:"100%",height:350})}),a.jsx(C,{associationModel:i==null?void 0:i.BuildDiagram})]})}class w{constructor(t,l){this.Id=0,this.top=0,this.bottom=0,this.left=100,this.right=0,this.width=172,this.height=100,this.header=t,this.body=l}setPosition(t,l){this.top=t,this.left=l}getPosition(){return{left:this.left,top:this.top}}setId(t){this.Id=t}}class D{constructor(){this.QId=0,this.AssociationModel=[],this.listModels=[],this.color=""}setLink(t,l,e){let d=this.QId,o=0;const n=[];for(const r of[t,l])r.Id===0?(r.Id=`lm${d}`,n[o]=r,this.listModels[this.listModels.length]=r,o++):n.multi=!0,d++;this.QId=d,n.from=t.Id,n.to=l.Id,e!=null&&String(e).trim()!==""&&(n.label=String(e).trim()),this.AssociationModel[this.AssociationModel.length]=n}setFrom(t){this.From=t}setTo(t){this.To=t}getAssociation(){return{From:this.from,To:this.to}}setId(t){this.Id=t}}class j{constructor(){this.BuildDiagram={}}setAssociations(t){this.BuildDiagram=t}getAssociation(){return this.BuildDiagram}}function B({datosMapa:i,buildDiagram:t,className:l}){const e=I.useMemo(()=>{if(t)return t();const d=new w("Model","Body1");d.setPosition(219,150);const o=new w("Model 1","Body2");o.setPosition(200,450);const n=new w("Model 2","Body3");n.setPosition(200,800);const r=new D;r.setLink(d,o,"Asociación"),r.setLink(o,n,"Continúa");const u=new j;return u.setAssociations(r),u},[t]);return a.jsx("div",{className:`lm-diagram-root ${l??""}`.trim(),id:"ModalDiagrama",role:"presentation",children:a.jsx(S,{association:e})})}exports.AssociationModel=D;exports.ControllerLM=j;exports.DiagramModel=w;exports.LMDiagram=B;exports.ModalDiagrama=B;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/components/DrawAssociation.jsx","../src/components/SvgDiagramLayer.jsx","../src/components/DrawComponent.jsx","../src/DiagramModel.js","../src/AssociationModel.js","../src/ControllerLM.js","../src/components/LMDiagram.jsx"],"sourcesContent":["import { useEffect, useRef, useCallback } from 'react';\r\n\r\nconst SVG_NS = 'http://www.w3.org/2000/svg';\r\n\r\n/** Punto en curva cúbica de Bézier en t ∈ [0,1] (mismo trazo que el path) */\r\nfunction cubicBezierPoint(t, p0, p1, p2, p3) {\r\n const mt = 1 - t;\r\n const a = mt * mt * mt;\r\n const b = 3 * mt * mt * t;\r\n const c = 3 * mt * t * t;\r\n const d = t * t * t;\r\n return {\r\n x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,\r\n y: a * p0.y + b * p1.y + c * p2.y + d * p3.y,\r\n };\r\n}\r\n\r\nfunction DrawAssociation({ associationModel }) {\r\n const associationRef = useRef(associationModel);\r\n associationRef.current = associationModel;\r\n\r\n const updateConnection = useCallback((pAssocModel) => {\r\n if (!pAssocModel?.AssociationModel) return;\r\n\r\n for (const lineItem of pAssocModel.AssociationModel) {\r\n const Model1 = document.getElementById(lineItem.from);\r\n const Model2 = document.getElementById(lineItem.to);\r\n if (!Model1 || !Model2) continue;\r\n\r\n let x1 = 0;\r\n let y1 = 0;\r\n let x2 = 0;\r\n let y2 = 0;\r\n\r\n const lineIdNum = parseInt(lineItem.line_Associate_id?.substring(7) ?? '0', 10);\r\n if (lineIdNum === 0) {\r\n x1 = Model1.offsetLeft;\r\n y1 = Model1.offsetTop + Model1.offsetHeight / 2;\r\n x2 = Model2.offsetLeft;\r\n y2 = Model2.offsetTop + Model2.offsetHeight / 2;\r\n } else {\r\n x1 = Model1.offsetLeft;\r\n y1 = Model1.offsetTop + Model1.offsetHeight / 2;\r\n x2 = Model2.offsetLeft;\r\n y2 = Model2.offsetTop + Model2.offsetHeight / 2;\r\n }\r\n\r\n const postline = document.getElementById(lineItem.line_Associate_id);\r\n if (!postline) continue;\r\n\r\n const p0 = { x: x1 + 150, y: y1 };\r\n const p1 = { x: x2 - 100, y: y1 };\r\n const p2 = { x: x2 - 20, y: y2 };\r\n const p3 = { x: x2 - 10, y: y2 };\r\n\r\n postline.setAttribute('d', `M${p0.x},${p0.y} C${p1.x},${p1.y} ${p2.x},${p2.y} ${p3.x},${p3.y}`);\r\n\r\n const labelId = `${lineItem.line_Associate_id}_label`;\r\n const labelEl = document.getElementById(labelId);\r\n if (labelEl && lineItem.label) {\r\n const mid = cubicBezierPoint(0.5, p0, p1, p2, p3);\r\n labelEl.setAttribute('x', mid.x);\r\n labelEl.setAttribute('y', mid.y);\r\n }\r\n }\r\n }, []);\r\n\r\n useEffect(() => {\r\n const pAssocModel = associationModel;\r\n if (!pAssocModel?.AssociationModel?.length) return undefined;\r\n\r\n const gLines = document.getElementById('gLines');\r\n if (!gLines) return undefined;\r\n\r\n let idLine = 0;\r\n const cleanups = [];\r\n const dragged = new Set();\r\n\r\n const dragElement = (elmnt) => {\r\n if (!elmnt || dragged.has(elmnt.id)) return;\r\n dragged.add(elmnt.id);\r\n\r\n let pos1 = 0;\r\n let pos2 = 0;\r\n let pos3 = 0;\r\n let pos4 = 0;\r\n\r\n const dragMouseDown = (e) => {\r\n e.preventDefault();\r\n pos3 = e.clientX;\r\n pos4 = e.clientY;\r\n document.addEventListener('mouseup', closeDragElement);\r\n document.addEventListener('mousemove', elementDrag);\r\n };\r\n\r\n const elementDrag = (e) => {\r\n const lmSvgArea = document.getElementById('lmDiagramSvg');\r\n if (!lmSvgArea) return;\r\n e.preventDefault();\r\n pos1 = pos3 - e.clientX;\r\n pos2 = pos4 - e.clientY;\r\n pos3 = e.clientX;\r\n pos4 = e.clientY;\r\n\r\n const top = elmnt.offsetTop - pos2;\r\n const left = elmnt.offsetLeft - pos1;\r\n if (\r\n e.clientY <= lmSvgArea.clientHeight &&\r\n e.clientY >= 130 &&\r\n left + elmnt.clientWidth <= lmSvgArea.clientWidth &&\r\n left >= 0\r\n ) {\r\n elmnt.style.top = `${top}px`;\r\n elmnt.style.left = `${left}px`;\r\n }\r\n updateConnection(associationRef.current);\r\n };\r\n\r\n const closeDragElement = () => {\r\n document.removeEventListener('mouseup', closeDragElement);\r\n document.removeEventListener('mousemove', elementDrag);\r\n };\r\n\r\n const header = document.getElementById(`${elmnt.id}header`);\r\n const target = header ?? elmnt;\r\n target.addEventListener('mousedown', dragMouseDown);\r\n cleanups.push(() => {\r\n target.removeEventListener('mousedown', dragMouseDown);\r\n document.removeEventListener('mouseup', closeDragElement);\r\n document.removeEventListener('mousemove', elementDrag);\r\n });\r\n };\r\n\r\n for (const AsocModel of pAssocModel.AssociationModel) {\r\n const lineId = `ulmLine${idLine}`;\r\n const group = document.createElementNS(SVG_NS, 'g');\r\n group.setAttribute('class', 'lm-diagram-link');\r\n\r\n const amElement = document.createElementNS(SVG_NS, 'path');\r\n amElement.setAttribute('marker-end', 'url(#arrowhead)');\r\n amElement.setAttribute('class', 'lm-diagram-path');\r\n amElement.setAttribute('id', lineId);\r\n group.appendChild(amElement);\r\n\r\n if (AsocModel.label) {\r\n const textEl = document.createElementNS(SVG_NS, 'text');\r\n textEl.setAttribute('id', `${lineId}_label`);\r\n textEl.setAttribute('class', 'lm-diagram-link-label');\r\n textEl.setAttribute('text-anchor', 'middle');\r\n textEl.setAttribute('dominant-baseline', 'middle');\r\n textEl.textContent = AsocModel.label;\r\n group.appendChild(textEl);\r\n }\r\n\r\n gLines.appendChild(group);\r\n AsocModel.line_Associate_id = lineId;\r\n\r\n dragElement(document.getElementById(AsocModel.from));\r\n dragElement(document.getElementById(AsocModel.to));\r\n idLine++;\r\n }\r\n\r\n updateConnection(pAssocModel);\r\n\r\n return () => {\r\n cleanups.forEach((fn) => fn());\r\n while (gLines.firstChild) {\r\n gLines.removeChild(gLines.firstChild);\r\n }\r\n };\r\n }, [associationModel, updateConnection]);\r\n\r\n return null;\r\n}\r\n\r\nexport default DrawAssociation;\r\n","import { useId } from 'react';\n\nexport default function SvgDiagramLayer({ width = '100%', height = 350 }) {\n const titleId = useId().replace(/:/g, '');\n return (\n <svg\n className=\"lm-diagram-svg\"\n id=\"lmDiagramSvg\"\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n aria-labelledby={titleId}\n >\n <title id={titleId}>Diagram connections</title>\n <defs>\n <marker id=\"arrowhead\" viewBox=\"0 0 10 10\" refX=\"3\" refY=\"5\" markerWidth=\"6\" markerHeight=\"6\" orient=\"auto\">\n <path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"var(--lm-arrow, #6366f1)\" />\n </marker>\n </defs>\n <g fill=\"none\" stroke=\"var(--lm-line, #6366f1)\" id=\"gLines\" strokeWidth=\"2\" markerEnd=\"url(#arrowhead)\" />\n </svg>\n );\n}\n","import DrawAssociation from './DrawAssociation.jsx';\r\nimport SvgDiagramLayer from './SvgDiagramLayer.jsx';\r\n\r\nexport default function DrawComponent({ association }) {\r\n const listModels = association?.BuildDiagram?.listModels ?? [];\r\n\r\n return (\r\n <div className=\"lm-diagram-canvas\">\r\n <div className=\"lm-diagram-nodes\" aria-label=\"Diagram models\">\r\n {listModels.map((model, i) => (\r\n <div\r\n className=\"lm-diagram-node\"\r\n style={{\r\n top: model.top,\r\n left: model.left,\r\n width: model.width,\r\n minHeight: model.height ?? 102,\r\n }}\r\n key={model.Id ?? i}\r\n id={model.Id}\r\n >\r\n <div className=\"lm-diagram-node__header\">{model.header}</div>\r\n <div className=\"lm-diagram-node__body\">\r\n <span className=\"lm-diagram-node__label\">{model.body}</span>\r\n </div>\r\n </div>\r\n ))}\r\n </div>\r\n\r\n <div className=\"lm-diagram-svg-wrap\">\r\n <SvgDiagramLayer width=\"100%\" height={350} />\r\n </div>\r\n\r\n <DrawAssociation associationModel={association?.BuildDiagram} />\r\n </div>\r\n );\r\n}\r\n","/**\n * Plain data model for a diagram node (not a React component).\n */\nexport class DiagramModel {\n constructor(header, body) {\n this.Id = 0;\n this.top = 0;\n this.bottom = 0;\n this.left = 100;\n this.right = 0;\n this.width = 172;\n this.height = 100;\n this.header = header;\n this.body = body;\n }\n\n setPosition(top, left) {\n this.top = top;\n this.left = left;\n }\n\n getPosition() {\n return { left: this.left, top: this.top };\n }\n\n setId(id) {\n this.Id = id;\n }\n}\n","class AssociationModel {\n constructor() {\n this.QId = 0;\n this.AssociationModel = [];\n this.listModels = [];\n this.color = '';\n }\n\n /**\n * @param {object} pmodel\n * @param {object} pmodel1\n * @param {string} [label] — texto opcional mostrado sobre el trazo de la asociación\n */\n setLink(pmodel, pmodel1, label) {\n let CountId = this.QId;\n let i = 0;\n const pairs = [];\n for (const item of [pmodel, pmodel1]) {\n if (item.Id === 0) {\n item.Id = `lm${CountId}`;\n pairs[i] = item;\n this.listModels[this.listModels.length] = item;\n i++;\n } else {\n pairs.multi = true;\n }\n CountId++;\n }\n this.QId = CountId;\n pairs.from = pmodel.Id;\n pairs.to = pmodel1.Id;\n if (label != null && String(label).trim() !== '') {\n pairs.label = String(label).trim();\n }\n this.AssociationModel[this.AssociationModel.length] = pairs;\n }\n\n setFrom(pFrom) {\n this.From = pFrom;\n }\n\n setTo(pto) {\n this.To = pto;\n }\n\n getAssociation() {\n return {\n From: this.from,\n To: this.to,\n };\n }\n\n setId(pId) {\n this.Id = pId;\n }\n}\n\nexport default AssociationModel;\n","class ControllerLM {\n constructor() {\n this.BuildDiagram = {};\n }\n\n setAssociations(pParam) {\n this.BuildDiagram = pParam;\n }\n\n getAssociation() {\n return this.BuildDiagram;\n }\n}\n\nexport default ControllerLM;\n","import { useMemo } from 'react';\nimport DrawComponent from './DrawComponent.jsx';\nimport { DiagramModel } from '../DiagramModel.js';\nimport AssociationModel from '../AssociationModel.js';\nimport ControllerLM from '../ControllerLM.js';\n\n/**\n * Diagram container. Builds the default demo graph once (same idea as the old componentWillMount).\n * Pass `buildDiagram` to override with your own ControllerLM + models.\n */\nexport default function LMDiagram({ datosMapa: _datosMapa, buildDiagram, className }) {\n const diagram = useMemo(() => {\n if (buildDiagram) {\n return buildDiagram();\n }\n const model1 = new DiagramModel('Model', 'Body1');\n model1.setPosition(219, 150);\n\n const model2 = new DiagramModel('Model 1', 'Body2');\n model2.setPosition(200, 450);\n\n const model3 = new DiagramModel('Model 2', 'Body3');\n model3.setPosition(200, 800);\n\n const association = new AssociationModel();\n association.setLink(model1, model2, 'Asociación');\n association.setLink(model2, model3, 'Continúa');\n\n const controllerLM = new ControllerLM();\n controllerLM.setAssociations(association);\n return controllerLM;\n }, [buildDiagram]);\n\n return (\n <div className={`lm-diagram-root ${className ?? ''}`.trim()} id=\"ModalDiagrama\" role=\"presentation\">\n <DrawComponent association={diagram} />\n </div>\n );\n}\n"],"names":["SVG_NS","cubicBezierPoint","t","p0","p1","p2","p3","mt","a","b","c","d","DrawAssociation","associationModel","associationRef","useRef","updateConnection","useCallback","pAssocModel","lineItem","Model1","Model2","x1","y1","x2","y2","lineIdNum","_a","postline","labelId","labelEl","mid","useEffect","gLines","idLine","cleanups","dragged","dragElement","elmnt","pos1","pos2","pos3","pos4","dragMouseDown","e","closeDragElement","elementDrag","lmSvgArea","top","left","target","AsocModel","lineId","group","amElement","textEl","fn","SvgDiagramLayer","width","height","titleId","useId","jsxs","jsx","DrawComponent","association","listModels","model","i","DiagramModel","header","body","id","AssociationModel","pmodel","pmodel1","label","CountId","pairs","item","pFrom","pto","pId","ControllerLM","pParam","LMDiagram","_datosMapa","buildDiagram","className","diagram","useMemo","model1","model2","model3","controllerLM"],"mappings":"wIAEMA,EAAS,6BAGf,SAASC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,EAAa,UAAW,OAAO,EAClDwB,EAAO,YAAY,IAAK,GAAG,EAE3B,MAAM5B,EAAc,IAAIQ,EACxBR,EAAY,QAAQ0B,EAAQC,EAAQ,YAAY,EAChD3B,EAAY,QAAQ2B,EAAQC,EAAQ,UAAU,EAE9C,MAAMC,EAAe,IAAIX,EACzB,OAAAW,EAAa,gBAAgB7B,CAAW,EACjC6B,CACT,EAAG,CAACP,CAAY,CAAC,EAEjB,aACG,MAAA,CAAI,UAAW,mBAAmBC,GAAa,EAAE,GAAG,KAAA,EAAQ,GAAG,gBAAgB,KAAK,eACnF,eAACxB,EAAA,CAAc,YAAayB,EAAS,EACvC,CAEJ"}
package/dist/index.js ADDED
@@ -0,0 +1,202 @@
1
+ import { jsxs as A, jsx as m } from "react/jsx-runtime";
2
+ import { useRef as D, useCallback as _, useEffect as $, useId as C, useMemo as N } from "react";
3
+ const E = "http://www.w3.org/2000/svg";
4
+ function k(i, t, l, e, d) {
5
+ const o = 1 - i, n = o * o * o, r = 3 * o * o * i, u = 3 * o * i * i, g = i * i * i;
6
+ return {
7
+ x: n * t.x + r * l.x + u * e.x + g * d.x,
8
+ y: n * t.y + r * l.y + u * e.y + g * d.y
9
+ };
10
+ }
11
+ function S({ associationModel: i }) {
12
+ const t = D(i);
13
+ t.current = i;
14
+ const l = _((e) => {
15
+ var d;
16
+ if (e != null && e.AssociationModel)
17
+ for (const o of e.AssociationModel) {
18
+ const n = document.getElementById(o.from), r = document.getElementById(o.to);
19
+ if (!n || !r) continue;
20
+ let u = 0, g = 0, s = 0, h = 0;
21
+ const p = parseInt(((d = o.line_Associate_id) == null ? void 0 : d.substring(7)) ?? "0", 10);
22
+ u = n.offsetLeft, g = n.offsetTop + n.offsetHeight / 2, s = r.offsetLeft, h = r.offsetTop + r.offsetHeight / 2;
23
+ const f = document.getElementById(o.line_Associate_id);
24
+ if (!f) continue;
25
+ const a = { x: u + 150, y: g }, I = { x: s - 100, y: g }, v = { x: s - 20, y: h }, y = { x: s - 10, y: h };
26
+ f.setAttribute("d", `M${a.x},${a.y} C${I.x},${I.y} ${v.x},${v.y} ${y.x},${y.y}`);
27
+ const M = `${o.line_Associate_id}_label`, w = document.getElementById(M);
28
+ if (w && o.label) {
29
+ const c = k(0.5, a, I, v, y);
30
+ w.setAttribute("x", c.x), w.setAttribute("y", c.y);
31
+ }
32
+ }
33
+ }, []);
34
+ return $(() => {
35
+ var g;
36
+ const e = i;
37
+ if (!((g = e == null ? void 0 : e.AssociationModel) != null && g.length)) return;
38
+ const d = document.getElementById("gLines");
39
+ if (!d) return;
40
+ let o = 0;
41
+ const n = [], r = /* @__PURE__ */ new Set(), u = (s) => {
42
+ if (!s || r.has(s.id)) return;
43
+ r.add(s.id);
44
+ let h = 0, p = 0, f = 0, a = 0;
45
+ const I = (c) => {
46
+ c.preventDefault(), f = c.clientX, a = c.clientY, document.addEventListener("mouseup", y), document.addEventListener("mousemove", v);
47
+ }, v = (c) => {
48
+ const b = document.getElementById("lmDiagramSvg");
49
+ if (!b) return;
50
+ c.preventDefault(), h = f - c.clientX, p = a - c.clientY, f = c.clientX, a = c.clientY;
51
+ const B = s.offsetTop - p, x = s.offsetLeft - h;
52
+ c.clientY <= b.clientHeight && c.clientY >= 130 && x + s.clientWidth <= b.clientWidth && x >= 0 && (s.style.top = `${B}px`, s.style.left = `${x}px`), l(t.current);
53
+ }, y = () => {
54
+ document.removeEventListener("mouseup", y), document.removeEventListener("mousemove", v);
55
+ }, w = document.getElementById(`${s.id}header`) ?? s;
56
+ w.addEventListener("mousedown", I), n.push(() => {
57
+ w.removeEventListener("mousedown", I), document.removeEventListener("mouseup", y), document.removeEventListener("mousemove", v);
58
+ });
59
+ };
60
+ for (const s of e.AssociationModel) {
61
+ const h = `ulmLine${o}`, p = document.createElementNS(E, "g");
62
+ p.setAttribute("class", "lm-diagram-link");
63
+ const f = document.createElementNS(E, "path");
64
+ if (f.setAttribute("marker-end", "url(#arrowhead)"), f.setAttribute("class", "lm-diagram-path"), f.setAttribute("id", h), p.appendChild(f), s.label) {
65
+ const a = document.createElementNS(E, "text");
66
+ a.setAttribute("id", `${h}_label`), a.setAttribute("class", "lm-diagram-link-label"), a.setAttribute("text-anchor", "middle"), a.setAttribute("dominant-baseline", "middle"), a.textContent = s.label, p.appendChild(a);
67
+ }
68
+ d.appendChild(p), s.line_Associate_id = h, u(document.getElementById(s.from)), u(document.getElementById(s.to)), o++;
69
+ }
70
+ return l(e), () => {
71
+ for (n.forEach((s) => s()); d.firstChild; )
72
+ d.removeChild(d.firstChild);
73
+ };
74
+ }, [i, l]), null;
75
+ }
76
+ function T({ width: i = "100%", height: t = 350 }) {
77
+ const l = C().replace(/:/g, "");
78
+ return /* @__PURE__ */ A(
79
+ "svg",
80
+ {
81
+ className: "lm-diagram-svg",
82
+ id: "lmDiagramSvg",
83
+ xmlns: "http://www.w3.org/2000/svg",
84
+ width: i,
85
+ height: t,
86
+ "aria-labelledby": l,
87
+ children: [
88
+ /* @__PURE__ */ m("title", { id: l, children: "Diagram connections" }),
89
+ /* @__PURE__ */ m("defs", { children: /* @__PURE__ */ m("marker", { id: "arrowhead", viewBox: "0 0 10 10", refX: "3", refY: "5", markerWidth: "6", markerHeight: "6", orient: "auto", children: /* @__PURE__ */ m("path", { d: "M 0 0 L 10 5 L 0 10 z", fill: "var(--lm-arrow, #6366f1)" }) }) }),
90
+ /* @__PURE__ */ m("g", { fill: "none", stroke: "var(--lm-line, #6366f1)", id: "gLines", strokeWidth: "2", markerEnd: "url(#arrowhead)" })
91
+ ]
92
+ }
93
+ );
94
+ }
95
+ function H({ association: i }) {
96
+ var l;
97
+ const t = ((l = i == null ? void 0 : i.BuildDiagram) == null ? void 0 : l.listModels) ?? [];
98
+ return /* @__PURE__ */ A("div", { className: "lm-diagram-canvas", children: [
99
+ /* @__PURE__ */ m("div", { className: "lm-diagram-nodes", "aria-label": "Diagram models", children: t.map((e, d) => /* @__PURE__ */ A(
100
+ "div",
101
+ {
102
+ className: "lm-diagram-node",
103
+ style: {
104
+ top: e.top,
105
+ left: e.left,
106
+ width: e.width,
107
+ minHeight: e.height ?? 102
108
+ },
109
+ id: e.Id,
110
+ children: [
111
+ /* @__PURE__ */ m("div", { className: "lm-diagram-node__header", children: e.header }),
112
+ /* @__PURE__ */ m("div", { className: "lm-diagram-node__body", children: /* @__PURE__ */ m("span", { className: "lm-diagram-node__label", children: e.body }) })
113
+ ]
114
+ },
115
+ e.Id ?? d
116
+ )) }),
117
+ /* @__PURE__ */ m("div", { className: "lm-diagram-svg-wrap", children: /* @__PURE__ */ m(T, { width: "100%", height: 350 }) }),
118
+ /* @__PURE__ */ m(S, { associationModel: i == null ? void 0 : i.BuildDiagram })
119
+ ] });
120
+ }
121
+ class L {
122
+ constructor(t, l) {
123
+ this.Id = 0, this.top = 0, this.bottom = 0, this.left = 100, this.right = 0, this.width = 172, this.height = 100, this.header = t, this.body = l;
124
+ }
125
+ setPosition(t, l) {
126
+ this.top = t, this.left = l;
127
+ }
128
+ getPosition() {
129
+ return { left: this.left, top: this.top };
130
+ }
131
+ setId(t) {
132
+ this.Id = t;
133
+ }
134
+ }
135
+ class P {
136
+ constructor() {
137
+ this.QId = 0, this.AssociationModel = [], this.listModels = [], this.color = "";
138
+ }
139
+ /**
140
+ * @param {object} pmodel
141
+ * @param {object} pmodel1
142
+ * @param {string} [label] — texto opcional mostrado sobre el trazo de la asociación
143
+ */
144
+ setLink(t, l, e) {
145
+ let d = this.QId, o = 0;
146
+ const n = [];
147
+ for (const r of [t, l])
148
+ r.Id === 0 ? (r.Id = `lm${d}`, n[o] = r, this.listModels[this.listModels.length] = r, o++) : n.multi = !0, d++;
149
+ this.QId = d, n.from = t.Id, n.to = l.Id, e != null && String(e).trim() !== "" && (n.label = String(e).trim()), this.AssociationModel[this.AssociationModel.length] = n;
150
+ }
151
+ setFrom(t) {
152
+ this.From = t;
153
+ }
154
+ setTo(t) {
155
+ this.To = t;
156
+ }
157
+ getAssociation() {
158
+ return {
159
+ From: this.from,
160
+ To: this.to
161
+ };
162
+ }
163
+ setId(t) {
164
+ this.Id = t;
165
+ }
166
+ }
167
+ class Y {
168
+ constructor() {
169
+ this.BuildDiagram = {};
170
+ }
171
+ setAssociations(t) {
172
+ this.BuildDiagram = t;
173
+ }
174
+ getAssociation() {
175
+ return this.BuildDiagram;
176
+ }
177
+ }
178
+ function F({ datosMapa: i, buildDiagram: t, className: l }) {
179
+ const e = N(() => {
180
+ if (t)
181
+ return t();
182
+ const d = new L("Model", "Body1");
183
+ d.setPosition(219, 150);
184
+ const o = new L("Model 1", "Body2");
185
+ o.setPosition(200, 450);
186
+ const n = new L("Model 2", "Body3");
187
+ n.setPosition(200, 800);
188
+ const r = new P();
189
+ r.setLink(d, o, "Asociación"), r.setLink(o, n, "Continúa");
190
+ const u = new Y();
191
+ return u.setAssociations(r), u;
192
+ }, [t]);
193
+ return /* @__PURE__ */ m("div", { className: `lm-diagram-root ${l ?? ""}`.trim(), id: "ModalDiagrama", role: "presentation", children: /* @__PURE__ */ m(H, { association: e }) });
194
+ }
195
+ export {
196
+ P as AssociationModel,
197
+ Y as ControllerLM,
198
+ L as DiagramModel,
199
+ F as LMDiagram,
200
+ F as ModalDiagrama
201
+ };
202
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/components/DrawAssociation.jsx","../src/components/SvgDiagramLayer.jsx","../src/components/DrawComponent.jsx","../src/DiagramModel.js","../src/AssociationModel.js","../src/ControllerLM.js","../src/components/LMDiagram.jsx"],"sourcesContent":["import { useEffect, useRef, useCallback } from 'react';\r\n\r\nconst SVG_NS = 'http://www.w3.org/2000/svg';\r\n\r\n/** Punto en curva cúbica de Bézier en t ∈ [0,1] (mismo trazo que el path) */\r\nfunction cubicBezierPoint(t, p0, p1, p2, p3) {\r\n const mt = 1 - t;\r\n const a = mt * mt * mt;\r\n const b = 3 * mt * mt * t;\r\n const c = 3 * mt * t * t;\r\n const d = t * t * t;\r\n return {\r\n x: a * p0.x + b * p1.x + c * p2.x + d * p3.x,\r\n y: a * p0.y + b * p1.y + c * p2.y + d * p3.y,\r\n };\r\n}\r\n\r\nfunction DrawAssociation({ associationModel }) {\r\n const associationRef = useRef(associationModel);\r\n associationRef.current = associationModel;\r\n\r\n const updateConnection = useCallback((pAssocModel) => {\r\n if (!pAssocModel?.AssociationModel) return;\r\n\r\n for (const lineItem of pAssocModel.AssociationModel) {\r\n const Model1 = document.getElementById(lineItem.from);\r\n const Model2 = document.getElementById(lineItem.to);\r\n if (!Model1 || !Model2) continue;\r\n\r\n let x1 = 0;\r\n let y1 = 0;\r\n let x2 = 0;\r\n let y2 = 0;\r\n\r\n const lineIdNum = parseInt(lineItem.line_Associate_id?.substring(7) ?? '0', 10);\r\n if (lineIdNum === 0) {\r\n x1 = Model1.offsetLeft;\r\n y1 = Model1.offsetTop + Model1.offsetHeight / 2;\r\n x2 = Model2.offsetLeft;\r\n y2 = Model2.offsetTop + Model2.offsetHeight / 2;\r\n } else {\r\n x1 = Model1.offsetLeft;\r\n y1 = Model1.offsetTop + Model1.offsetHeight / 2;\r\n x2 = Model2.offsetLeft;\r\n y2 = Model2.offsetTop + Model2.offsetHeight / 2;\r\n }\r\n\r\n const postline = document.getElementById(lineItem.line_Associate_id);\r\n if (!postline) continue;\r\n\r\n const p0 = { x: x1 + 150, y: y1 };\r\n const p1 = { x: x2 - 100, y: y1 };\r\n const p2 = { x: x2 - 20, y: y2 };\r\n const p3 = { x: x2 - 10, y: y2 };\r\n\r\n postline.setAttribute('d', `M${p0.x},${p0.y} C${p1.x},${p1.y} ${p2.x},${p2.y} ${p3.x},${p3.y}`);\r\n\r\n const labelId = `${lineItem.line_Associate_id}_label`;\r\n const labelEl = document.getElementById(labelId);\r\n if (labelEl && lineItem.label) {\r\n const mid = cubicBezierPoint(0.5, p0, p1, p2, p3);\r\n labelEl.setAttribute('x', mid.x);\r\n labelEl.setAttribute('y', mid.y);\r\n }\r\n }\r\n }, []);\r\n\r\n useEffect(() => {\r\n const pAssocModel = associationModel;\r\n if (!pAssocModel?.AssociationModel?.length) return undefined;\r\n\r\n const gLines = document.getElementById('gLines');\r\n if (!gLines) return undefined;\r\n\r\n let idLine = 0;\r\n const cleanups = [];\r\n const dragged = new Set();\r\n\r\n const dragElement = (elmnt) => {\r\n if (!elmnt || dragged.has(elmnt.id)) return;\r\n dragged.add(elmnt.id);\r\n\r\n let pos1 = 0;\r\n let pos2 = 0;\r\n let pos3 = 0;\r\n let pos4 = 0;\r\n\r\n const dragMouseDown = (e) => {\r\n e.preventDefault();\r\n pos3 = e.clientX;\r\n pos4 = e.clientY;\r\n document.addEventListener('mouseup', closeDragElement);\r\n document.addEventListener('mousemove', elementDrag);\r\n };\r\n\r\n const elementDrag = (e) => {\r\n const lmSvgArea = document.getElementById('lmDiagramSvg');\r\n if (!lmSvgArea) return;\r\n e.preventDefault();\r\n pos1 = pos3 - e.clientX;\r\n pos2 = pos4 - e.clientY;\r\n pos3 = e.clientX;\r\n pos4 = e.clientY;\r\n\r\n const top = elmnt.offsetTop - pos2;\r\n const left = elmnt.offsetLeft - pos1;\r\n if (\r\n e.clientY <= lmSvgArea.clientHeight &&\r\n e.clientY >= 130 &&\r\n left + elmnt.clientWidth <= lmSvgArea.clientWidth &&\r\n left >= 0\r\n ) {\r\n elmnt.style.top = `${top}px`;\r\n elmnt.style.left = `${left}px`;\r\n }\r\n updateConnection(associationRef.current);\r\n };\r\n\r\n const closeDragElement = () => {\r\n document.removeEventListener('mouseup', closeDragElement);\r\n document.removeEventListener('mousemove', elementDrag);\r\n };\r\n\r\n const header = document.getElementById(`${elmnt.id}header`);\r\n const target = header ?? elmnt;\r\n target.addEventListener('mousedown', dragMouseDown);\r\n cleanups.push(() => {\r\n target.removeEventListener('mousedown', dragMouseDown);\r\n document.removeEventListener('mouseup', closeDragElement);\r\n document.removeEventListener('mousemove', elementDrag);\r\n });\r\n };\r\n\r\n for (const AsocModel of pAssocModel.AssociationModel) {\r\n const lineId = `ulmLine${idLine}`;\r\n const group = document.createElementNS(SVG_NS, 'g');\r\n group.setAttribute('class', 'lm-diagram-link');\r\n\r\n const amElement = document.createElementNS(SVG_NS, 'path');\r\n amElement.setAttribute('marker-end', 'url(#arrowhead)');\r\n amElement.setAttribute('class', 'lm-diagram-path');\r\n amElement.setAttribute('id', lineId);\r\n group.appendChild(amElement);\r\n\r\n if (AsocModel.label) {\r\n const textEl = document.createElementNS(SVG_NS, 'text');\r\n textEl.setAttribute('id', `${lineId}_label`);\r\n textEl.setAttribute('class', 'lm-diagram-link-label');\r\n textEl.setAttribute('text-anchor', 'middle');\r\n textEl.setAttribute('dominant-baseline', 'middle');\r\n textEl.textContent = AsocModel.label;\r\n group.appendChild(textEl);\r\n }\r\n\r\n gLines.appendChild(group);\r\n AsocModel.line_Associate_id = lineId;\r\n\r\n dragElement(document.getElementById(AsocModel.from));\r\n dragElement(document.getElementById(AsocModel.to));\r\n idLine++;\r\n }\r\n\r\n updateConnection(pAssocModel);\r\n\r\n return () => {\r\n cleanups.forEach((fn) => fn());\r\n while (gLines.firstChild) {\r\n gLines.removeChild(gLines.firstChild);\r\n }\r\n };\r\n }, [associationModel, updateConnection]);\r\n\r\n return null;\r\n}\r\n\r\nexport default DrawAssociation;\r\n","import { useId } from 'react';\n\nexport default function SvgDiagramLayer({ width = '100%', height = 350 }) {\n const titleId = useId().replace(/:/g, '');\n return (\n <svg\n className=\"lm-diagram-svg\"\n id=\"lmDiagramSvg\"\n xmlns=\"http://www.w3.org/2000/svg\"\n width={width}\n height={height}\n aria-labelledby={titleId}\n >\n <title id={titleId}>Diagram connections</title>\n <defs>\n <marker id=\"arrowhead\" viewBox=\"0 0 10 10\" refX=\"3\" refY=\"5\" markerWidth=\"6\" markerHeight=\"6\" orient=\"auto\">\n <path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"var(--lm-arrow, #6366f1)\" />\n </marker>\n </defs>\n <g fill=\"none\" stroke=\"var(--lm-line, #6366f1)\" id=\"gLines\" strokeWidth=\"2\" markerEnd=\"url(#arrowhead)\" />\n </svg>\n );\n}\n","import DrawAssociation from './DrawAssociation.jsx';\r\nimport SvgDiagramLayer from './SvgDiagramLayer.jsx';\r\n\r\nexport default function DrawComponent({ association }) {\r\n const listModels = association?.BuildDiagram?.listModels ?? [];\r\n\r\n return (\r\n <div className=\"lm-diagram-canvas\">\r\n <div className=\"lm-diagram-nodes\" aria-label=\"Diagram models\">\r\n {listModels.map((model, i) => (\r\n <div\r\n className=\"lm-diagram-node\"\r\n style={{\r\n top: model.top,\r\n left: model.left,\r\n width: model.width,\r\n minHeight: model.height ?? 102,\r\n }}\r\n key={model.Id ?? i}\r\n id={model.Id}\r\n >\r\n <div className=\"lm-diagram-node__header\">{model.header}</div>\r\n <div className=\"lm-diagram-node__body\">\r\n <span className=\"lm-diagram-node__label\">{model.body}</span>\r\n </div>\r\n </div>\r\n ))}\r\n </div>\r\n\r\n <div className=\"lm-diagram-svg-wrap\">\r\n <SvgDiagramLayer width=\"100%\" height={350} />\r\n </div>\r\n\r\n <DrawAssociation associationModel={association?.BuildDiagram} />\r\n </div>\r\n );\r\n}\r\n","/**\n * Plain data model for a diagram node (not a React component).\n */\nexport class DiagramModel {\n constructor(header, body) {\n this.Id = 0;\n this.top = 0;\n this.bottom = 0;\n this.left = 100;\n this.right = 0;\n this.width = 172;\n this.height = 100;\n this.header = header;\n this.body = body;\n }\n\n setPosition(top, left) {\n this.top = top;\n this.left = left;\n }\n\n getPosition() {\n return { left: this.left, top: this.top };\n }\n\n setId(id) {\n this.Id = id;\n }\n}\n","class AssociationModel {\n constructor() {\n this.QId = 0;\n this.AssociationModel = [];\n this.listModels = [];\n this.color = '';\n }\n\n /**\n * @param {object} pmodel\n * @param {object} pmodel1\n * @param {string} [label] — texto opcional mostrado sobre el trazo de la asociación\n */\n setLink(pmodel, pmodel1, label) {\n let CountId = this.QId;\n let i = 0;\n const pairs = [];\n for (const item of [pmodel, pmodel1]) {\n if (item.Id === 0) {\n item.Id = `lm${CountId}`;\n pairs[i] = item;\n this.listModels[this.listModels.length] = item;\n i++;\n } else {\n pairs.multi = true;\n }\n CountId++;\n }\n this.QId = CountId;\n pairs.from = pmodel.Id;\n pairs.to = pmodel1.Id;\n if (label != null && String(label).trim() !== '') {\n pairs.label = String(label).trim();\n }\n this.AssociationModel[this.AssociationModel.length] = pairs;\n }\n\n setFrom(pFrom) {\n this.From = pFrom;\n }\n\n setTo(pto) {\n this.To = pto;\n }\n\n getAssociation() {\n return {\n From: this.from,\n To: this.to,\n };\n }\n\n setId(pId) {\n this.Id = pId;\n }\n}\n\nexport default AssociationModel;\n","class ControllerLM {\n constructor() {\n this.BuildDiagram = {};\n }\n\n setAssociations(pParam) {\n this.BuildDiagram = pParam;\n }\n\n getAssociation() {\n return this.BuildDiagram;\n }\n}\n\nexport default ControllerLM;\n","import { useMemo } from 'react';\nimport DrawComponent from './DrawComponent.jsx';\nimport { DiagramModel } from '../DiagramModel.js';\nimport AssociationModel from '../AssociationModel.js';\nimport ControllerLM from '../ControllerLM.js';\n\n/**\n * Diagram container. Builds the default demo graph once (same idea as the old componentWillMount).\n * Pass `buildDiagram` to override with your own ControllerLM + models.\n */\nexport default function LMDiagram({ datosMapa: _datosMapa, buildDiagram, className }) {\n const diagram = useMemo(() => {\n if (buildDiagram) {\n return buildDiagram();\n }\n const model1 = new DiagramModel('Model', 'Body1');\n model1.setPosition(219, 150);\n\n const model2 = new DiagramModel('Model 1', 'Body2');\n model2.setPosition(200, 450);\n\n const model3 = new DiagramModel('Model 2', 'Body3');\n model3.setPosition(200, 800);\n\n const association = new AssociationModel();\n association.setLink(model1, model2, 'Asociación');\n association.setLink(model2, model3, 'Continúa');\n\n const controllerLM = new ControllerLM();\n controllerLM.setAssociations(association);\n return controllerLM;\n }, [buildDiagram]);\n\n return (\n <div className={`lm-diagram-root ${className ?? ''}`.trim()} id=\"ModalDiagrama\" role=\"presentation\">\n <DrawComponent association={diagram} />\n </div>\n );\n}\n"],"names":["SVG_NS","cubicBezierPoint","t","p0","p1","p2","p3","mt","a","b","c","d","DrawAssociation","associationModel","associationRef","useRef","updateConnection","useCallback","pAssocModel","lineItem","Model1","Model2","x1","y1","x2","y2","lineIdNum","_a","postline","labelId","labelEl","mid","useEffect","gLines","idLine","cleanups","dragged","dragElement","elmnt","pos1","pos2","pos3","pos4","dragMouseDown","e","closeDragElement","elementDrag","lmSvgArea","top","left","target","AsocModel","lineId","group","amElement","textEl","fn","SvgDiagramLayer","width","height","titleId","useId","jsxs","jsx","DrawComponent","association","listModels","model","i","DiagramModel","header","body","id","AssociationModel","pmodel","pmodel1","label","CountId","pairs","item","pFrom","pto","pId","ControllerLM","pParam","LMDiagram","_datosMapa","buildDiagram","className","diagram","useMemo","model1","model2","model3","controllerLM"],"mappings":";;AAEA,MAAMA,IAAS;AAGf,SAASC,EAAiBC,GAAGC,GAAIC,GAAIC,GAAIC,GAAI;AAC3C,QAAMC,IAAK,IAAIL,GACTM,IAAID,IAAKA,IAAKA,GACdE,IAAI,IAAIF,IAAKA,IAAKL,GAClBQ,IAAI,IAAIH,IAAKL,IAAIA,GACjBS,IAAIT,IAAIA,IAAIA;AAClB,SAAO;AAAA,IACL,GAAGM,IAAIL,EAAG,IAAIM,IAAIL,EAAG,IAAIM,IAAIL,EAAG,IAAIM,IAAIL,EAAG;AAAA,IAC3C,GAAGE,IAAIL,EAAG,IAAIM,IAAIL,EAAG,IAAIM,IAAIL,EAAG,IAAIM,IAAIL,EAAG;AAAA,EAAA;AAE/C;AAEA,SAASM,EAAgB,EAAE,kBAAAC,KAAoB;AAC7C,QAAMC,IAAiBC,EAAOF,CAAgB;AAC9C,EAAAC,EAAe,UAAUD;AAEzB,QAAMG,IAAmBC,EAAY,CAACC,MAAgB;;AACpD,QAAKA,KAAA,QAAAA,EAAa;AAElB,iBAAWC,KAAYD,EAAY,kBAAkB;AACnD,cAAME,IAAS,SAAS,eAAeD,EAAS,IAAI,GAC9CE,IAAS,SAAS,eAAeF,EAAS,EAAE;AAClD,YAAI,CAACC,KAAU,CAACC,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GAAQC,GAAQ,YAAY,GAChD3B,EAAY,QAAQ2B,GAAQC,GAAQ,UAAU;AAE9C,UAAMC,IAAe,IAAIX,EAAA;AACzB,WAAAW,EAAa,gBAAgB7B,CAAW,GACjC6B;AAAA,EACT,GAAG,CAACP,CAAY,CAAC;AAEjB,2BACG,OAAA,EAAI,WAAW,mBAAmBC,KAAa,EAAE,GAAG,KAAA,GAAQ,IAAG,iBAAgB,MAAK,gBACnF,4BAACxB,GAAA,EAAc,aAAayB,GAAS,GACvC;AAEJ;"}
@@ -0,0 +1 @@
1
+ .lm-diagram-root{--lm-surface: #ffffff;--lm-surface-muted: #f8fafc;--lm-border: #e2e8f0;--lm-header: linear-gradient(135deg, #4f46e5 0%, #6366f1 55%, #818cf8 100%);--lm-text: #0f172a;--lm-text-muted: #64748b;--lm-line: #6366f1;--lm-arrow: #6366f1;--lm-shadow: 0 10px 15px -3px rgb(15 23 42 / .08), 0 4px 6px -4px rgb(15 23 42 / .06);--lm-radius: 12px;--lm-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;font-family:var(--lm-font);color:var(--lm-text);box-sizing:border-box}.lm-diagram-root *,.lm-diagram-root *:before,.lm-diagram-root *:after{box-sizing:border-box}.lm-diagram-canvas{position:relative;width:100%;min-height:360px;background:var(--lm-surface-muted);border-radius:var(--lm-radius);border:1px solid var(--lm-border);overflow:hidden}.lm-diagram-nodes{position:relative;min-height:320px}.lm-diagram-node{position:absolute;bottom:auto;right:auto;z-index:2;display:flex;flex-direction:column;border-radius:10px;background:var(--lm-surface);border:1px solid var(--lm-border);box-shadow:var(--lm-shadow);overflow:hidden;cursor:grab;transition:box-shadow .2s ease,transform .15s ease}.lm-diagram-node:active{cursor:grabbing}.lm-diagram-node:hover{box-shadow:0 20px 25px -5px #0f172a1f,0 8px 10px -6px #0f172a14}.lm-diagram-node__header{padding:10px 12px;font-weight:600;font-size:.875rem;letter-spacing:.02em;color:#fff;background:var(--lm-header);border-bottom:1px solid rgb(255 255 255 / .12);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;-webkit-user-select:none;user-select:none}.lm-diagram-node__body{flex:0 1 auto;padding:10px 12px;background:var(--lm-surface)}.lm-diagram-node__label{font-size:.8125rem;color:var(--lm-text-muted);line-height:1.4;word-break:break-word}.lm-diagram-svg-wrap{position:absolute;top:0;right:0;bottom:0;left:0;z-index:1;pointer-events:none}.lm-diagram-svg{display:block;width:100%;height:100%}.lm-diagram-path{stroke:var(--lm-line);fill:none}.lm-diagram-link-label{font-family:var(--lm-font);font-size:11px;font-weight:600;fill:var(--lm-link-label, #4338ca);paint-order:stroke fill;stroke:var(--lm-link-label-stroke, #ffffff);stroke-width:3px;stroke-linejoin:round;pointer-events:none}.lm-demo{min-height:100vh;padding:2rem 1.5rem;background:radial-gradient(1200px 600px at 10% -10%,#e0e7ff 0%,transparent 55%),radial-gradient(900px 500px at 100% 0%,#cffafe 0%,transparent 45%),#f1f5f9}.lm-demo__card{max-width:960px;margin:0 auto;padding:1.5rem 1.75rem;background:#fff;border-radius:16px;border:1px solid #e2e8f0;box-shadow:0 25px 50px -12px #0f172a26}.lm-demo__title{margin:0 0 .35rem;font-size:1.5rem;font-weight:700;letter-spacing:-.02em;color:#0f172a}.lm-demo__subtitle{margin:0 0 1.25rem;font-size:.9375rem;color:#64748b}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "lmdiagram",
3
+ "version": "0.2.0",
4
+ "description": "React diagram component for linked models and associations",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ },
13
+ "./styles.css": "./dist/lmdiagram.css"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "sideEffects": [
19
+ "**/*.css"
20
+ ],
21
+ "keywords": [
22
+ "react",
23
+ "diagram",
24
+ "flowchart",
25
+ "associations"
26
+ ],
27
+ "license": "MIT",
28
+ "peerDependencies": {
29
+ "react": ">=17.0.0",
30
+ "react-dom": ">=17.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@vitejs/plugin-react": "^4.3.4",
34
+ "react": "^18.3.1",
35
+ "react-dom": "^18.3.1",
36
+ "vite": "^5.4.14"
37
+ },
38
+ "scripts": {
39
+ "dev": "vite",
40
+ "build": "vite build --config vite.lib.config.js",
41
+ "build:demo": "vite build",
42
+ "preview": "vite preview",
43
+ "prepublishOnly": "npm run build"
44
+ }
45
+ }