@edv4h/usketch-plugin-shape-frame 3.0.1 → 3.1.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/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +11 -72
- package/dist/plugin.js.map +1 -1
- package/package.json +4 -4
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKX,aAAa,EACb,MAAM,uBAAuB,CAAC;AAiE/B,wBAAgB,iBAAiB,IAAI,aAAa,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKX,aAAa,EACb,MAAM,uBAAuB,CAAC;AAiE/B,wBAAgB,iBAAiB,IAAI,aAAa,CAsFjD"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { generateId } from "@edv4h/usketch-shared";
|
|
3
|
-
import {
|
|
3
|
+
import { createAddShapeCommand } from "@edv4h/usketch-store";
|
|
4
4
|
import { createDefaultFrame, getBoundsFrame, hitTestFrame, renderFrame, resizeFrame, } from "./shapes/frame.js";
|
|
5
5
|
/**
|
|
6
6
|
* LOD component: labeled empty frame — dashed border + top-left title.
|
|
@@ -50,6 +50,9 @@ export function createFramePlugin() {
|
|
|
50
50
|
renderTarget: "html",
|
|
51
51
|
minSize: { width: 50, height: 50 },
|
|
52
52
|
simplifiedComponent: SimplifiedFrame,
|
|
53
|
+
// Frames are containers whose children stay individually selectable
|
|
54
|
+
// and are auto-attached on overlap (handled by the container plugin).
|
|
55
|
+
container: { selectableChildren: true, autoAttach: true },
|
|
53
56
|
});
|
|
54
57
|
// Drawing tool state
|
|
55
58
|
let drawState = null;
|
|
@@ -104,77 +107,13 @@ export function createFramePlugin() {
|
|
|
104
107
|
},
|
|
105
108
|
});
|
|
106
109
|
// ── Auto-parenting ──
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
for (const shapeId of data.shapeIds) {
|
|
115
|
-
autoReparent(shapeId);
|
|
116
|
-
}
|
|
117
|
-
}, 0);
|
|
118
|
-
});
|
|
119
|
-
// On shape:added (e.g. drawing inside a frame)
|
|
120
|
-
const unsubAdded = ctx.store.onMutation((event) => {
|
|
121
|
-
if (event.type !== "shape:added")
|
|
122
|
-
return;
|
|
123
|
-
const payload = event.payload;
|
|
124
|
-
if (!payload?.id)
|
|
125
|
-
return;
|
|
126
|
-
const shape = ctx.store.getShape(payload.id);
|
|
127
|
-
if (!shape || shape.type === "frame" || shape.type === "connector")
|
|
128
|
-
return;
|
|
129
|
-
autoReparent(payload.id);
|
|
130
|
-
});
|
|
131
|
-
function autoReparent(shapeId) {
|
|
132
|
-
const shape = ctx.store.getShape(shapeId);
|
|
133
|
-
if (!shape || shape.type === "frame" || shape.type === "connector")
|
|
134
|
-
return;
|
|
135
|
-
const shapeBounds = { x: shape.x, y: shape.y, width: shape.width, height: shape.height };
|
|
136
|
-
// Find the smallest frame that fully contains this shape
|
|
137
|
-
let bestFrame = null;
|
|
138
|
-
for (const [id, candidate] of ctx.store.getShapes()) {
|
|
139
|
-
if (id === shapeId || candidate.type !== "frame")
|
|
140
|
-
continue;
|
|
141
|
-
const frameBounds = {
|
|
142
|
-
x: candidate.x,
|
|
143
|
-
y: candidate.y,
|
|
144
|
-
width: candidate.width,
|
|
145
|
-
height: candidate.height,
|
|
146
|
-
};
|
|
147
|
-
if (containsAABB(frameBounds, shapeBounds)) {
|
|
148
|
-
if (!bestFrame ||
|
|
149
|
-
candidate.width * candidate.height < bestFrame.width * bestFrame.height) {
|
|
150
|
-
bestFrame = candidate;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const currentParentId = shape.parentId;
|
|
155
|
-
const newParentId = bestFrame?.id;
|
|
156
|
-
if (currentParentId !== newParentId) {
|
|
157
|
-
ctx.commands.execute(createReparentCommand(ctx.store, [shapeId], newParentId ?? undefined));
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// ── Frame move: move all children along with the frame ──
|
|
161
|
-
const unsubMove = ctx.store.onMutation((event) => {
|
|
162
|
-
if (event.type !== "shape:updated")
|
|
163
|
-
return;
|
|
164
|
-
const payload = event.payload;
|
|
165
|
-
if (!payload?.id)
|
|
166
|
-
return;
|
|
167
|
-
const shape = ctx.store.getShape(payload.id);
|
|
168
|
-
if (!shape || shape.type !== "frame")
|
|
169
|
-
return;
|
|
170
|
-
// This is handled by the select tool which includes children in snapshots
|
|
171
|
-
// when moving a frame. No additional logic needed here.
|
|
172
|
-
});
|
|
173
|
-
return () => {
|
|
174
|
-
unsubMoveEnd();
|
|
175
|
-
unsubAdded();
|
|
176
|
-
unsubMove();
|
|
177
|
-
};
|
|
110
|
+
//
|
|
111
|
+
// Attaching shapes to a containing frame (and detaching on exit) is now
|
|
112
|
+
// handled generically by `usketch-plugin-container` via the frame's
|
|
113
|
+
// `container.autoAttach` flag, so no frame-specific reparent logic lives
|
|
114
|
+
// here. Frame moves also drag children along via the select tool's
|
|
115
|
+
// container-aware descendant snapshotting.
|
|
116
|
+
return () => { };
|
|
178
117
|
},
|
|
179
118
|
};
|
|
180
119
|
}
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.tsx"],"names":[],"mappings":";AAOA,OAAO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,SAAS,CAAC,OAAO,CAAC,CAAC;wBACzC,SAAS,GAAG,IAAI,CAAC;oBAClB,CAAC;gBACF,CAAC;aACD,CAAC,CAAC;YAEH,uBAAuB;YACvB,EAAE;YACF,wEAAwE;YACxE,oEAAoE;YACpE,yEAAyE;YACzE,mEAAmE;YACnE,2CAA2C;YAE3C,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;QACjB,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edv4h/usketch-plugin-shape-frame",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@edv4h/usketch-
|
|
16
|
-
"@edv4h/usketch-
|
|
17
|
-
"@edv4h/usketch-
|
|
15
|
+
"@edv4h/usketch-core": "2.0.3",
|
|
16
|
+
"@edv4h/usketch-shared": "4.2.0",
|
|
17
|
+
"@edv4h/usketch-store": "3.1.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"react": ">=19"
|