@funnest/charts-ui 0.11.6 → 0.11.7
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/components/keep-in-view.d.ts +9 -0
- package/dist/index.js +64 -36
- package/package.json +2 -2
|
@@ -5,3 +5,12 @@
|
|
|
5
5
|
* Attach the returned ref to the menu element.
|
|
6
6
|
*/
|
|
7
7
|
export declare function useKeepInView<T extends HTMLElement>(open: boolean): import("preact").RefObject<T | null>;
|
|
8
|
+
/**
|
|
9
|
+
* A menu that opens beside its button (the drawing bar's tool lists): placed in the viewport
|
|
10
|
+
* (position: fixed), so a drawing bar that scrolls — a short chart — can't clip it behind the chart.
|
|
11
|
+
* A transformed ancestor moves where fixed boxes land; that offset is measured and taken out. Kept
|
|
12
|
+
* on screen vertically, and moved along when the bar scrolls or the window changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useBesideAnchor<T extends HTMLElement>(open: boolean, anchor: {
|
|
15
|
+
current: HTMLElement | null;
|
|
16
|
+
}): import("preact").RefObject<T | null>;
|
package/dist/index.js
CHANGED
|
@@ -1183,6 +1183,66 @@ function IntervalVisibilityEditor({ t: t3, value, onChange }) {
|
|
|
1183
1183
|
}) });
|
|
1184
1184
|
}
|
|
1185
1185
|
|
|
1186
|
+
// src/components/keep-in-view.ts
|
|
1187
|
+
var MARGIN = 8;
|
|
1188
|
+
function useKeepInView(open) {
|
|
1189
|
+
const ref = T2(null);
|
|
1190
|
+
F2(() => {
|
|
1191
|
+
const el = ref.current;
|
|
1192
|
+
if (!open || !el) return;
|
|
1193
|
+
el.style.translate = "";
|
|
1194
|
+
const fit2 = () => {
|
|
1195
|
+
el.style.translate = "";
|
|
1196
|
+
el.style.maxHeight = "";
|
|
1197
|
+
const r3 = el.getBoundingClientRect();
|
|
1198
|
+
const root = el.closest(".fnc-root")?.getBoundingClientRect();
|
|
1199
|
+
const maxY = Math.min(document.documentElement.clientHeight, root?.bottom ?? Infinity) - MARGIN;
|
|
1200
|
+
if (r3.bottom > maxY) {
|
|
1201
|
+
el.style.maxHeight = `${Math.max(120, Math.floor(maxY - r3.top))}px`;
|
|
1202
|
+
el.style.overflowY = "auto";
|
|
1203
|
+
}
|
|
1204
|
+
const minX = Math.max(0, root?.left ?? 0) + MARGIN;
|
|
1205
|
+
const maxX = Math.min(document.documentElement.clientWidth, root?.right ?? Infinity) - MARGIN;
|
|
1206
|
+
let dx = 0;
|
|
1207
|
+
if (r3.right > maxX) dx = maxX - r3.right;
|
|
1208
|
+
if (r3.left + dx < minX) dx = minX - r3.left;
|
|
1209
|
+
if (dx) el.style.translate = `${Math.round(dx)}px 0`;
|
|
1210
|
+
};
|
|
1211
|
+
fit2();
|
|
1212
|
+
window.addEventListener("resize", fit2);
|
|
1213
|
+
return () => window.removeEventListener("resize", fit2);
|
|
1214
|
+
}, [open]);
|
|
1215
|
+
return ref;
|
|
1216
|
+
}
|
|
1217
|
+
function useBesideAnchor(open, anchor) {
|
|
1218
|
+
const ref = T2(null);
|
|
1219
|
+
F2(() => {
|
|
1220
|
+
const el = ref.current;
|
|
1221
|
+
const a4 = anchor.current;
|
|
1222
|
+
if (!open || !el || !a4) return;
|
|
1223
|
+
const place = () => {
|
|
1224
|
+
const r3 = a4.getBoundingClientRect();
|
|
1225
|
+
el.style.position = "fixed";
|
|
1226
|
+
el.style.left = "0px";
|
|
1227
|
+
el.style.top = "0px";
|
|
1228
|
+
const origin = el.getBoundingClientRect();
|
|
1229
|
+
const vh = document.documentElement.clientHeight;
|
|
1230
|
+
const top = Math.max(MARGIN, Math.min(r3.top, vh - MARGIN - el.offsetHeight));
|
|
1231
|
+
el.style.left = `${Math.round(r3.right + 8 - origin.left)}px`;
|
|
1232
|
+
el.style.top = `${Math.round(top - origin.top)}px`;
|
|
1233
|
+
};
|
|
1234
|
+
place();
|
|
1235
|
+
const bar = a4.closest(".fnc-drawbar");
|
|
1236
|
+
window.addEventListener("resize", place);
|
|
1237
|
+
bar?.addEventListener("scroll", place);
|
|
1238
|
+
return () => {
|
|
1239
|
+
window.removeEventListener("resize", place);
|
|
1240
|
+
bar?.removeEventListener("scroll", place);
|
|
1241
|
+
};
|
|
1242
|
+
}, [open]);
|
|
1243
|
+
return ref;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1186
1246
|
// src/icons.tsx
|
|
1187
1247
|
function Icon({ children, size = 20 }) {
|
|
1188
1248
|
return /* @__PURE__ */ a3(
|
|
@@ -1496,6 +1556,7 @@ function ToolGroup({
|
|
|
1496
1556
|
const current = armed ?? tools.find((d3) => d3.type === chosen) ?? tools[0];
|
|
1497
1557
|
const name = current.name[s3.locale];
|
|
1498
1558
|
const ref = T2(null);
|
|
1559
|
+
const menu = useBesideAnchor(open, ref);
|
|
1499
1560
|
A2(() => {
|
|
1500
1561
|
if (!open) return;
|
|
1501
1562
|
const close = (e3) => !ref.current?.contains(e3.target) && onOpen(false);
|
|
@@ -1518,7 +1579,7 @@ function ToolGroup({
|
|
|
1518
1579
|
/* @__PURE__ */ a3("span", { class: "fnc-tool-corner", children: /* @__PURE__ */ a3(CornerIcon, {}) }),
|
|
1519
1580
|
/* @__PURE__ */ a3("span", { class: "fnc-tool-chevron", children: /* @__PURE__ */ a3(ChevronRightIcon, {}) })
|
|
1520
1581
|
] }),
|
|
1521
|
-
open && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-tool-menu", role: "menu", children: tools.map((def, i3) => {
|
|
1582
|
+
open && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-tool-menu", role: "menu", ref: menu, children: tools.map((def, i3) => {
|
|
1522
1583
|
const section = def.section?.[s3.locale];
|
|
1523
1584
|
const heading = section && section !== tools[i3 - 1]?.section?.[s3.locale];
|
|
1524
1585
|
return /* @__PURE__ */ a3($, { children: [
|
|
@@ -1555,6 +1616,7 @@ function CursorGroup({ ctx, open, onOpen, onPick }) {
|
|
|
1555
1616
|
const s3 = useStore(ctx.store);
|
|
1556
1617
|
const t3 = stringsOf(s3);
|
|
1557
1618
|
const ref = T2(null);
|
|
1619
|
+
const menu = useBesideAnchor(open, ref);
|
|
1558
1620
|
const current = CURSORS.find((c3) => c3.mode === s3.cursorMode) ?? CURSORS[0];
|
|
1559
1621
|
A2(() => {
|
|
1560
1622
|
if (!open) return;
|
|
@@ -1574,7 +1636,7 @@ function CursorGroup({ ctx, open, onOpen, onPick }) {
|
|
|
1574
1636
|
/* @__PURE__ */ a3("span", { class: "fnc-tool-corner", children: /* @__PURE__ */ a3(CornerIcon, {}) }),
|
|
1575
1637
|
/* @__PURE__ */ a3("span", { class: "fnc-tool-chevron", children: /* @__PURE__ */ a3(ChevronRightIcon, {}) })
|
|
1576
1638
|
] }),
|
|
1577
|
-
open && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-tool-menu", role: "menu", children: [
|
|
1639
|
+
open && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-tool-menu", role: "menu", ref: menu, children: [
|
|
1578
1640
|
/* @__PURE__ */ a3("div", { class: "fnc-tool-section", role: "presentation", children: t3.cursorModes }),
|
|
1579
1641
|
CURSORS.map((c3) => /* @__PURE__ */ a3(
|
|
1580
1642
|
"button",
|
|
@@ -3438,40 +3500,6 @@ function Dialogs({ ctx }) {
|
|
|
3438
3500
|
|
|
3439
3501
|
// src/components/interval-picker.tsx
|
|
3440
3502
|
import { derivedBase as derivedBase2, resolutionToMs as resolutionToMs3 } from "@funnest/charts";
|
|
3441
|
-
|
|
3442
|
-
// src/components/keep-in-view.ts
|
|
3443
|
-
var MARGIN = 8;
|
|
3444
|
-
function useKeepInView(open) {
|
|
3445
|
-
const ref = T2(null);
|
|
3446
|
-
F2(() => {
|
|
3447
|
-
const el = ref.current;
|
|
3448
|
-
if (!open || !el) return;
|
|
3449
|
-
el.style.translate = "";
|
|
3450
|
-
const fit2 = () => {
|
|
3451
|
-
el.style.translate = "";
|
|
3452
|
-
el.style.maxHeight = "";
|
|
3453
|
-
const r3 = el.getBoundingClientRect();
|
|
3454
|
-
const root = el.closest(".fnc-root")?.getBoundingClientRect();
|
|
3455
|
-
const maxY = Math.min(document.documentElement.clientHeight, root?.bottom ?? Infinity) - MARGIN;
|
|
3456
|
-
if (r3.bottom > maxY) {
|
|
3457
|
-
el.style.maxHeight = `${Math.max(120, Math.floor(maxY - r3.top))}px`;
|
|
3458
|
-
el.style.overflowY = "auto";
|
|
3459
|
-
}
|
|
3460
|
-
const minX = Math.max(0, root?.left ?? 0) + MARGIN;
|
|
3461
|
-
const maxX = Math.min(document.documentElement.clientWidth, root?.right ?? Infinity) - MARGIN;
|
|
3462
|
-
let dx = 0;
|
|
3463
|
-
if (r3.right > maxX) dx = maxX - r3.right;
|
|
3464
|
-
if (r3.left + dx < minX) dx = minX - r3.left;
|
|
3465
|
-
if (dx) el.style.translate = `${Math.round(dx)}px 0`;
|
|
3466
|
-
};
|
|
3467
|
-
fit2();
|
|
3468
|
-
window.addEventListener("resize", fit2);
|
|
3469
|
-
return () => window.removeEventListener("resize", fit2);
|
|
3470
|
-
}, [open]);
|
|
3471
|
-
return ref;
|
|
3472
|
-
}
|
|
3473
|
-
|
|
3474
|
-
// src/components/interval-picker.tsx
|
|
3475
3503
|
var GROUP_LABEL = {
|
|
3476
3504
|
minutes: "intervalMinutes",
|
|
3477
3505
|
hours: "intervalHours",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnest/charts-ui",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.7",
|
|
4
4
|
"description": "Pro trading UI (toolbar, drawing tools, sheets) for Funnest Charts. Framework-agnostic.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chart",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"NOTICE"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@funnest/charts": "0.11.
|
|
45
|
+
"@funnest/charts": "0.11.7"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"preact": "^11.2.0"
|