@pie-lib/plot 5.0.7-next.20261019183544 → 5.0.7-next.20261019223635
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/grid-draggable.d.ts +1 -0
- package/dist/grid-draggable.js +151 -141
- package/package.json +3 -3
package/dist/grid-draggable.d.ts
CHANGED
package/dist/grid-draggable.js
CHANGED
|
@@ -13,158 +13,168 @@ import u from "debug";
|
|
|
13
13
|
var d = /* @__PURE__ */ e(n(), 1), f = u("pie-lib:plot:grid-draggable"), p = (e, t, n) => (r) => {
|
|
14
14
|
let i = r + e(0);
|
|
15
15
|
return t(n + e.invert(i)).toFixed(4) * 1e3 / 1e3;
|
|
16
|
-
}, m = (e) => (n) =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
}, m = (e) => (n) => {
|
|
17
|
+
(0, d.default)(!!e && l(e.fromDelta) && l(e.bounds) && l(e.anchorPoint), "You must supply an object with: { anchorPoint: Function, fromDelta: Function, bounds: Function }");
|
|
18
|
+
let u = ({ dragNodeRef: e, ...t }) => /* @__PURE__ */ c("g", {
|
|
19
|
+
ref: e,
|
|
20
|
+
children: /* @__PURE__ */ c(n, { ...t })
|
|
21
|
+
});
|
|
22
|
+
return class extends a.Component {
|
|
23
|
+
static propTypes = {
|
|
24
|
+
disabled: o.bool,
|
|
25
|
+
onDragStart: o.func,
|
|
26
|
+
onDrag: o.func,
|
|
27
|
+
onDragStop: o.func,
|
|
28
|
+
onClick: o.func,
|
|
29
|
+
onMove: o.func,
|
|
30
|
+
graphProps: t.isRequired
|
|
30
31
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
nodeRef = a.createRef();
|
|
33
|
+
constructor(e) {
|
|
34
|
+
super(e), this.state = {
|
|
35
|
+
startX: null,
|
|
36
|
+
startY: null
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
grid = () => {
|
|
40
|
+
let { graphProps: e } = this.props, { scale: t, domain: n, range: r } = e;
|
|
41
|
+
return {
|
|
42
|
+
x: t.x(n.step) - t.x(0),
|
|
43
|
+
y: t.y(r.step) - t.y(0)
|
|
44
|
+
};
|
|
37
45
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
onStart = (e) => {
|
|
47
|
+
let { onDragStart: t } = this.props;
|
|
48
|
+
document.activeElement && document.activeElement.blur(), this._didDrag = !1, this.setState({
|
|
49
|
+
startX: e.clientX,
|
|
50
|
+
startY: e.clientY
|
|
51
|
+
});
|
|
52
|
+
let n = e.target, r = (e) => {
|
|
53
|
+
n.removeEventListener("click", r, !0), this._didDrag && (e.stopPropagation(), e.preventDefault());
|
|
54
|
+
};
|
|
55
|
+
n.addEventListener("click", r, !0), t && t();
|
|
47
56
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
y: p(i.y, a.y, n)
|
|
57
|
+
position = () => {
|
|
58
|
+
let { x: t, y: n } = e.anchorPoint(this.props), { graphProps: r } = this.props, { scale: i, snap: a } = r;
|
|
59
|
+
return {
|
|
60
|
+
anchorPoint: {
|
|
61
|
+
x: t,
|
|
62
|
+
y: n
|
|
63
|
+
},
|
|
64
|
+
x: p(i.x, a.x, t),
|
|
65
|
+
y: p(i.y, a.y, n)
|
|
66
|
+
};
|
|
59
67
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return f("[tiny] key: ", e, "delta: ", a, "out: ", o), o;
|
|
64
|
-
};
|
|
65
|
-
getScaledBounds = () => {
|
|
66
|
-
let t = e.bounds(this.props, this.props.graphProps);
|
|
67
|
-
f("bounds: ", t);
|
|
68
|
-
let n = this.grid(), r = {
|
|
69
|
-
left: t.left * n.x,
|
|
70
|
-
right: t.right * n.x,
|
|
71
|
-
top: t.top * n.y,
|
|
72
|
-
bottom: t.bottom * n.y
|
|
73
|
-
}, i = Math.abs(n.y);
|
|
74
|
-
return r = {
|
|
75
|
-
...r,
|
|
76
|
-
top: Math.min(0, r.top) - i,
|
|
77
|
-
bottom: Math.abs(r.bottom) + i
|
|
78
|
-
}, f("[getScaledBounds]: ", r), r;
|
|
79
|
-
};
|
|
80
|
-
getClientPoint = (e, t) => {
|
|
81
|
-
if (!e || !t) return null;
|
|
82
|
-
let n = e.ownerSVGElement || e;
|
|
83
|
-
if (n && n.createSVGPoint) {
|
|
84
|
-
let r = n.createSVGPoint();
|
|
85
|
-
if (t.touches && t.touches.length > 0) {
|
|
86
|
-
let e = t.touches[0];
|
|
87
|
-
r.x = e.clientX, r.y = e.clientY;
|
|
88
|
-
} else r.x = t.clientX, r.y = t.clientY;
|
|
89
|
-
return e.getScreenCTM ? (r = r.matrixTransform(e.getScreenCTM().inverse()), [r.x, r.y]) : null;
|
|
90
|
-
}
|
|
91
|
-
let r = e.getBoundingClientRect();
|
|
92
|
-
return r ? [t.clientX - r.left - e.clientLeft, t.clientY - r.top - e.clientTop] : null;
|
|
93
|
-
};
|
|
94
|
-
skipDragOutsideOfBounds = (e, t, n) => {
|
|
95
|
-
let r = n.getRootNode(), i = this.getClientPoint(r, t);
|
|
96
|
-
if (i === null) return !0;
|
|
97
|
-
let [a, o] = i, { scale: s, domain: c, range: l } = n, u = s.x.invert(a), d = s.y.invert(o), f = e.deltaX > 0 && u < c.min || e.deltaX < 0 && u > c.max, p = e.deltaY > 0 && d > l.max || e.deltaY < 0 && d < l.min;
|
|
98
|
-
return f || p;
|
|
99
|
-
};
|
|
100
|
-
onDrag = (e, t) => {
|
|
101
|
-
let { onDrag: n, graphProps: r, disabled: i } = this.props;
|
|
102
|
-
if ((Math.abs(t.deltaX) > 1 || Math.abs(t.deltaY) > 1) && (this._didDrag = !0), !n || i) return;
|
|
103
|
-
let a = this.getScaledBounds();
|
|
104
|
-
if (t.deltaX < 0 && t.deltaX < a.left || t.deltaX > 0 && t.deltaX > a.right || t.deltaY < 0 && t.deltaY < a.top || t.deltaY > 0 && t.deltaY > a.bottom || this.skipDragOutsideOfBounds(t, e, r)) return;
|
|
105
|
-
let o = this.applyDelta({
|
|
106
|
-
x: t.deltaX,
|
|
107
|
-
y: t.deltaY
|
|
108
|
-
});
|
|
109
|
-
(o !== void 0 || o !== null) && n(o);
|
|
110
|
-
};
|
|
111
|
-
getDelta = (e) => {
|
|
112
|
-
let t = this.position(), n = {
|
|
113
|
-
x: t.x(e.x),
|
|
114
|
-
y: t.y(e.y)
|
|
68
|
+
tiny = (e, t) => {
|
|
69
|
+
let n = e.toUpperCase(), r = t[`client${n}`], i = this.state[`start${n}`], a = Math.abs(r - i), o = a < Math.abs(this.grid()[e]) / 10;
|
|
70
|
+
return f("[tiny] key: ", e, "delta: ", a, "out: ", o), o;
|
|
115
71
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
72
|
+
getScaledBounds = () => {
|
|
73
|
+
let t = e.bounds(this.props, this.props.graphProps);
|
|
74
|
+
f("bounds: ", t);
|
|
75
|
+
let n = this.grid(), r = {
|
|
76
|
+
left: t.left * n.x,
|
|
77
|
+
right: t.right * n.x,
|
|
78
|
+
top: t.top * n.y,
|
|
79
|
+
bottom: t.bottom * n.y
|
|
80
|
+
}, i = Math.abs(n.y);
|
|
81
|
+
return r = {
|
|
82
|
+
...r,
|
|
83
|
+
top: Math.min(0, r.top) - i,
|
|
84
|
+
bottom: Math.abs(r.bottom) + i
|
|
85
|
+
}, f("[getScaledBounds]: ", r), r;
|
|
86
|
+
};
|
|
87
|
+
getClientPoint = (e, t) => {
|
|
88
|
+
if (!e || !t) return null;
|
|
89
|
+
let n = e.ownerSVGElement || e;
|
|
90
|
+
if (n && n.createSVGPoint) {
|
|
91
|
+
let r = n.createSVGPoint();
|
|
92
|
+
if (t.touches && t.touches.length > 0) {
|
|
93
|
+
let e = t.touches[0];
|
|
94
|
+
r.x = e.clientX, r.y = e.clientY;
|
|
95
|
+
} else r.x = t.clientX, r.y = t.clientY;
|
|
96
|
+
return e.getScreenCTM ? (r = r.matrixTransform(e.getScreenCTM().inverse()), [r.x, r.y]) : null;
|
|
97
|
+
}
|
|
98
|
+
let r = e.getBoundingClientRect();
|
|
99
|
+
return r ? [t.clientX - r.left - e.clientLeft, t.clientY - r.top - e.clientTop] : null;
|
|
100
|
+
};
|
|
101
|
+
skipDragOutsideOfBounds = (e, t, n) => {
|
|
102
|
+
let r = n.getRootNode(), i = this.getClientPoint(r, t);
|
|
103
|
+
if (i === null) return !0;
|
|
104
|
+
let [a, o] = i, { scale: s, domain: c, range: l } = n, u = s.x.invert(a), d = s.y.invert(o), f = e.deltaX > 0 && u < c.min || e.deltaX < 0 && u > c.max, p = e.deltaY > 0 && d > l.max || e.deltaY < 0 && d < l.min;
|
|
105
|
+
return f || p;
|
|
106
|
+
};
|
|
107
|
+
onDrag = (e, t) => {
|
|
108
|
+
let { onDrag: n, graphProps: r, disabled: i } = this.props;
|
|
109
|
+
if ((Math.abs(t.deltaX) > 1 || Math.abs(t.deltaY) > 1) && (this._didDrag = !0), !n || i) return;
|
|
110
|
+
let a = this.getScaledBounds();
|
|
111
|
+
if (t.deltaX < 0 && t.deltaX < a.left || t.deltaX > 0 && t.deltaX > a.right || t.deltaY < 0 && t.deltaY < a.top || t.deltaY > 0 && t.deltaY > a.bottom || this.skipDragOutsideOfBounds(t, e, r)) return;
|
|
112
|
+
let o = this.applyDelta({
|
|
113
|
+
x: t.deltaX,
|
|
114
|
+
y: t.deltaY
|
|
115
|
+
});
|
|
116
|
+
(o !== void 0 || o !== null) && n(o);
|
|
117
|
+
};
|
|
118
|
+
getDelta = (e) => {
|
|
119
|
+
let t = this.position(), n = {
|
|
120
|
+
x: t.x(e.x),
|
|
121
|
+
y: t.y(e.y)
|
|
122
|
+
};
|
|
123
|
+
return r(t.anchorPoint, n);
|
|
124
|
+
};
|
|
125
|
+
applyDelta = (t) => {
|
|
126
|
+
let n = this.getDelta(t);
|
|
127
|
+
return f("[applyDelta] delta:", n), e.fromDelta(this.props, n);
|
|
128
|
+
};
|
|
129
|
+
onStop = (e, t) => {
|
|
130
|
+
f("[onStop] dd:", t);
|
|
131
|
+
let { onDragStop: n, onClick: r, disabled: i } = this.props;
|
|
132
|
+
if (n && !i && n(), f("[onStop] lastX/Y: ", t.lastX, t.lastY), !this._didDrag) {
|
|
133
|
+
if (!i && typeof e?.stopPropagation == "function" && e.stopPropagation(), r) {
|
|
134
|
+
f("call onClick"), this.setState({
|
|
135
|
+
startX: null,
|
|
136
|
+
startY: null
|
|
137
|
+
});
|
|
138
|
+
let { graphProps: t } = this.props, { scale: n, snap: i } = t;
|
|
139
|
+
try {
|
|
140
|
+
let [t, a] = s(e, e.target), o = n.x.invert(t), c = n.y.invert(a);
|
|
141
|
+
o = i.x(o), c = i.y(c), r({
|
|
142
|
+
x: o,
|
|
143
|
+
y: c
|
|
144
|
+
});
|
|
145
|
+
} catch {
|
|
146
|
+
r({});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
this.setState({
|
|
128
150
|
startX: null,
|
|
129
151
|
startY: null
|
|
130
152
|
});
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
let [t, a] = s(e, e.target), o = n.x.invert(t), c = n.y.invert(a);
|
|
134
|
-
o = i.x(o), c = i.y(c), r({
|
|
135
|
-
x: o,
|
|
136
|
-
y: c
|
|
137
|
-
});
|
|
138
|
-
} catch {
|
|
139
|
-
r({});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
this.setState({
|
|
153
|
+
} else this.setState({
|
|
143
154
|
startX: null,
|
|
144
155
|
startY: null
|
|
145
156
|
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
157
|
+
};
|
|
158
|
+
render() {
|
|
159
|
+
let { disabled: t, onClick: n, ...r } = this.props, a = this.grid(), o = (e) => (e.nativeEvent || e).preventDefault(), s = this.state ? !!this.state.startX : !1;
|
|
160
|
+
return /* @__PURE__ */ c(i, {
|
|
161
|
+
nodeRef: this.nodeRef,
|
|
162
|
+
onMouseDown: o,
|
|
163
|
+
onStart: this.onStart,
|
|
164
|
+
onDrag: this.onDrag,
|
|
165
|
+
onStop: this.onStop,
|
|
166
|
+
axis: e.axis || "both",
|
|
167
|
+
grid: [a.x, a.y],
|
|
168
|
+
children: /* @__PURE__ */ c(u, {
|
|
169
|
+
dragNodeRef: this.nodeRef,
|
|
170
|
+
...r,
|
|
171
|
+
disabled: t,
|
|
172
|
+
isDragging: s,
|
|
173
|
+
onClick: s ? void 0 : n
|
|
174
|
+
})
|
|
175
|
+
});
|
|
176
|
+
}
|
|
150
177
|
};
|
|
151
|
-
|
|
152
|
-
let { disabled: t, onClick: r, ...a } = this.props, o = this.grid(), s = (e) => (e.nativeEvent || e).preventDefault(), l = this.state ? !!this.state.startX : !1;
|
|
153
|
-
return /* @__PURE__ */ c(i, {
|
|
154
|
-
onMouseDown: s,
|
|
155
|
-
onStart: this.onStart,
|
|
156
|
-
onDrag: this.onDrag,
|
|
157
|
-
onStop: this.onStop,
|
|
158
|
-
axis: e.axis || "both",
|
|
159
|
-
grid: [o.x, o.y],
|
|
160
|
-
children: /* @__PURE__ */ c(n, {
|
|
161
|
-
...a,
|
|
162
|
-
disabled: t,
|
|
163
|
-
isDragging: l,
|
|
164
|
-
onClick: l ? void 0 : r
|
|
165
|
-
})
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
});
|
|
178
|
+
};
|
|
169
179
|
//#endregion
|
|
170
180
|
export { p as deltaFn, m as gridDraggable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/plot",
|
|
3
|
-
"version": "5.0.7-next.
|
|
3
|
+
"version": "5.0.7-next.20261019223635",
|
|
4
4
|
"description": "Some underlying components for building charts/graphs",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"@mui/icons-material": "^7.3.4",
|
|
15
15
|
"@mui/material": "^7.3.4",
|
|
16
16
|
"@pie-element/shared-utils": "0.1.6-next.20261019151920",
|
|
17
|
-
"@pie-lib/editable-html-tip-tap": "3.1.2-next.
|
|
18
|
-
"@pie-lib/render-ui": "8.0.7-next.
|
|
17
|
+
"@pie-lib/editable-html-tip-tap": "3.1.2-next.20261019223635",
|
|
18
|
+
"@pie-lib/render-ui": "8.0.7-next.20261019223635",
|
|
19
19
|
"assert": "^2.1.0",
|
|
20
20
|
"d3-scale": "^4.0.2",
|
|
21
21
|
"d3-selection": "^3.0.0",
|