flufi-ui 0.1.1 → 0.1.2

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.
@@ -91,7 +91,7 @@ function TextIconLinkButton(props) {
91
91
 
92
92
  // src/components/CalendarInput/CalendarInput.tsx
93
93
  import { useSignal as useSignal3 } from "@preact/signals";
94
- import { useEffect as useEffect2, useState as useState2 } from "preact/hooks";
94
+ import { useEffect, useState } from "preact/hooks";
95
95
  import { Calendar, ChevronLeft, ChevronRight } from "lucide-preact";
96
96
 
97
97
  // src/components/Container/Container.tsx
@@ -127,19 +127,35 @@ function AsideContainer(props) {
127
127
 
128
128
  // src/components/Popout/Popout.tsx
129
129
  import { useSignal } from "@preact/signals";
130
- import { useEffect, useRef, useState } from "preact/hooks";
130
+ import { useLayoutEffect, useRef } from "preact/hooks";
131
131
  import { createPortal } from "preact/compat";
132
+
133
+ // src/components/Popout/position.ts
134
+ function getPopoutTop(anchor, height, viewportHeight) {
135
+ const gap = 5;
136
+ const below = anchor.bottom + gap;
137
+ return viewportHeight - (below + height) <= 10 ? anchor.top - height - gap : below;
138
+ }
139
+
140
+ // src/components/Popout/Popout.tsx
132
141
  import { jsx as jsx4, jsxs } from "preact/jsx-runtime";
133
142
  function PopoutContainer(props) {
134
143
  const open = props.open ?? useSignal(false);
135
- const [rect, setRect] = useState(null);
136
144
  const anchorRef = useRef(null);
137
145
  const popoutRef = useRef(null);
138
- useEffect(() => {
139
- if (!open)
146
+ useLayoutEffect(() => {
147
+ if (!open.value)
140
148
  return;
149
+ const popout = popoutRef.current;
141
150
  function updateRect() {
142
- setRect(anchorRef.current?.getBoundingClientRect() ?? null);
151
+ const rect = anchorRef.current?.getBoundingClientRect();
152
+ if (!rect)
153
+ return;
154
+ popout.style.left = `${rect.left}px`;
155
+ popout.style.width = `${Math.max(0, rect.width - 2)}px`;
156
+ const height = popout.getBoundingClientRect().height;
157
+ popout.style.top = `${getPopoutTop(rect, height, window.innerHeight)}px`;
158
+ popout.style.visibility = "visible";
143
159
  }
144
160
  function onPointerDown(e) {
145
161
  const target = e.target;
@@ -154,24 +170,28 @@ function PopoutContainer(props) {
154
170
  open.value = false;
155
171
  }
156
172
  updateRect();
173
+ const observer = new ResizeObserver(updateRect);
174
+ observer.observe(popout);
175
+ observer.observe(anchorRef.current);
157
176
  document.addEventListener("mousedown", onPointerDown);
158
177
  document.addEventListener("keydown", onKeyDown);
159
178
  window.addEventListener("resize", updateRect);
160
179
  window.addEventListener("scroll", updateRect, true);
161
180
  return () => {
181
+ observer.disconnect();
162
182
  document.removeEventListener("mousedown", onPointerDown);
163
183
  document.removeEventListener("keydown", onKeyDown);
164
184
  window.removeEventListener("resize", updateRect);
165
185
  window.removeEventListener("scroll", updateRect, true);
166
186
  };
167
- }, [open]);
187
+ }, [open.value]);
168
188
  return /* @__PURE__ */ jsxs("div", { ref: anchorRef, class: addClass(
169
189
  "popout-container",
170
190
  open.value && "open",
171
191
  props.class
172
192
  ), children: [
173
193
  props.children,
174
- open.value && rect && createPortal(
194
+ open.value && createPortal(
175
195
  /* @__PURE__ */ jsx4(
176
196
  "div",
177
197
  {
@@ -181,18 +201,7 @@ function PopoutContainer(props) {
181
201
  MOBILE.value && "mobile-popout",
182
202
  props.popoutClass
183
203
  ),
184
- style: {
185
- top: (() => {
186
- const popoutHeight = popoutRef.current?.getBoundingClientRect().height ?? 0;
187
- const spaceBelow = window.innerHeight - rect.bottom;
188
- const spaceAbove = rect.top;
189
- if (spaceBelow >= popoutHeight + 5 || spaceBelow >= spaceAbove)
190
- return rect.bottom + 5;
191
- return rect.top - popoutHeight - 5;
192
- })(),
193
- left: rect.left,
194
- width: rect.width - 2
195
- },
204
+ style: { visibility: "hidden" },
196
205
  children: props.popout()
197
206
  }
198
207
  ),
@@ -324,15 +333,15 @@ function CalendarInput(props) {
324
333
  const popoutOpen = useSignal3(false);
325
334
  const now = /* @__PURE__ */ new Date();
326
335
  const initial = value.peek();
327
- const [viewYear, setViewYear] = useState2(initial?.year ?? now.getFullYear());
328
- const [viewMonth, setViewMonth] = useState2(initial?.month ?? now.getMonth() + 1);
336
+ const [viewYear, setViewYear] = useState(initial?.year ?? now.getFullYear());
337
+ const [viewMonth, setViewMonth] = useState(initial?.month ?? now.getMonth() + 1);
329
338
  const inputText = useSignal3(value.value?.toString() ?? "");
330
339
  function updateView() {
331
340
  const parts = (value.peek() ?? CalendarDate.now()).parts;
332
341
  setViewYear(parts.year);
333
342
  setViewMonth(parts.month);
334
343
  }
335
- useEffect2(() => {
344
+ useEffect(() => {
336
345
  updateView();
337
346
  }, [popoutOpen.value]);
338
347
  function commit(next, dontClose, dontSetInput) {
@@ -521,7 +530,7 @@ function Content(props) {
521
530
  // src/components/ContextMenu/ContextMenu.tsx
522
531
  import { render } from "preact";
523
532
  import { createPortal as createPortal2 } from "preact/compat";
524
- import { useLayoutEffect, useRef as useRef3 } from "preact/hooks";
533
+ import { useLayoutEffect as useLayoutEffect2, useRef as useRef3 } from "preact/hooks";
525
534
 
526
535
  // src/components/Text/Text.tsx
527
536
  import { jsx as jsx9 } from "preact/jsx-runtime";
@@ -540,7 +549,7 @@ function Text(props) {
540
549
 
541
550
  // src/components/ContextMenu/position.ts
542
551
  function getContextMenuPlacement(target, size, viewport) {
543
- const margin = 8;
552
+ const margin = 10;
544
553
  const gap = 6;
545
554
  const maxWidth = Math.max(0, viewport.width - margin * 2);
546
555
  const maxHeight = Math.max(0, viewport.height - margin * 2);
@@ -550,12 +559,12 @@ function getContextMenuPlacement(target, size, viewport) {
550
559
  const clampY = (y, h = height) => Math.max(margin, Math.min(y, viewport.height - margin - h));
551
560
  if (!("bottom" in target)) {
552
561
  const left = target.x + width > viewport.width - margin ? target.x - width : target.x;
553
- const top = target.y + height > viewport.height - margin ? target.y - height : target.y;
562
+ const top = target.y + height >= viewport.height - margin ? target.y - height : target.y;
554
563
  return { left: clampX(left), top: clampY(top), maxHeight };
555
564
  }
556
565
  const below = Math.max(0, viewport.height - margin - target.bottom - gap);
557
566
  const above = Math.max(0, target.top - margin - gap);
558
- if (height <= below)
567
+ if (height < below)
559
568
  return { left: clampX(target.left), top: clampY(target.bottom + gap), maxHeight: below };
560
569
  if (height <= above)
561
570
  return { left: clampX(target.left), top: clampY(target.top - gap - height), maxHeight: above };
@@ -620,7 +629,7 @@ function openContextMenuOn(items, element) {
620
629
  }
621
630
  function ContextMenu(props) {
622
631
  const menuRef = useRef3(null);
623
- useLayoutEffect(() => {
632
+ useLayoutEffect2(() => {
624
633
  const menu = menuRef.current;
625
634
  const anchor = props.target instanceof Element ? props.target : void 0;
626
635
  const getButtons = () => [...menu.querySelectorAll("button:not(:disabled)")];
@@ -920,12 +929,12 @@ function MiniHeader(props) {
920
929
  }
921
930
 
922
931
  // src/components/Image/Image.tsx
923
- import { useEffect as useEffect3, useRef as useRef4, useState as useState3 } from "preact/hooks";
932
+ import { useEffect as useEffect2, useRef as useRef4, useState as useState2 } from "preact/hooks";
924
933
  import { jsx as jsx17 } from "preact/jsx-runtime";
925
934
  function Image2(props) {
926
- const [src, setSrc] = useState3();
935
+ const [src, setSrc] = useState2();
927
936
  const lastSrc = useRef4();
928
- useEffect3(() => {
937
+ useEffect2(() => {
929
938
  if (lastSrc.current)
930
939
  URL.revokeObjectURL(lastSrc.current);
931
940
  const newSrc = resolveSignalish(props.src);
@@ -1055,7 +1064,7 @@ function Textarea(props) {
1055
1064
  }
1056
1065
 
1057
1066
  // src/components/Loading/Loading.tsx
1058
- import { useEffect as useEffect4, useState as useState4 } from "preact/hooks";
1067
+ import { useEffect as useEffect3, useState as useState3 } from "preact/hooks";
1059
1068
 
1060
1069
  // src/components/Throbber/Throbber.tsx
1061
1070
  import { Loader2 } from "lucide-preact";
@@ -1067,14 +1076,14 @@ function Throbber(props) {
1067
1076
  // src/components/Loading/Loading.tsx
1068
1077
  import { jsx as jsx21, jsxs as jsxs8 } from "preact/jsx-runtime";
1069
1078
  function Loading(props) {
1070
- const [loaded, setLoaded] = useState4(false);
1079
+ const [loaded, setLoaded] = useState3(false);
1071
1080
  {
1072
1081
  const out = resolveMaybeFunc(props.loaded);
1073
1082
  if (!(out instanceof Promise)) {
1074
1083
  setLoaded(resolveSignalish(out));
1075
1084
  }
1076
1085
  }
1077
- useEffect4(syncWrap(async () => {
1086
+ useEffect3(syncWrap(async () => {
1078
1087
  let data = resolveSignalish(await resolveMaybeAsyncFunc(props.loaded));
1079
1088
  setLoaded(data);
1080
1089
  }), [props.loaded]);
@@ -1087,7 +1096,7 @@ function Loading(props) {
1087
1096
  // src/components/PathInput/PathInput.tsx
1088
1097
  import { useSignal as useSignal7 } from "@preact/signals";
1089
1098
  import { Fragment as Fragment2 } from "preact";
1090
- import { useEffect as useEffect5, useRef as useRef7 } from "preact/hooks";
1099
+ import { useEffect as useEffect4, useRef as useRef7 } from "preact/hooks";
1091
1100
  import { ChevronRight as ChevronRight2 } from "lucide-preact";
1092
1101
  import { jsx as jsx22, jsxs as jsxs9 } from "preact/jsx-runtime";
1093
1102
  function PathInput(props) {
@@ -1118,13 +1127,13 @@ function PathInput(props) {
1118
1127
  const end = combined.peek().length;
1119
1128
  inputRef.current?.setSelectionRange(end, end);
1120
1129
  }
1121
- useEffect5(() => {
1130
+ useEffect4(() => {
1122
1131
  if (!isSignal(props.value)) return;
1123
1132
  return props.value.subscribe((val) => {
1124
1133
  if (!editing.peek()) parts.value = splitPath(val);
1125
1134
  });
1126
1135
  }, [props.value]);
1127
- useEffect5(() => {
1136
+ useEffect4(() => {
1128
1137
  const el = pathRef.current;
1129
1138
  if (!el) return;
1130
1139
  requestAnimationFrame(() => {
@@ -1243,7 +1252,7 @@ function Seperator() {
1243
1252
 
1244
1253
  // src/components/Slider/Slider.tsx
1245
1254
  import { useSignal as useSignal9 } from "@preact/signals";
1246
- import { useEffect as useEffect6, useRef as useRef8 } from "preact/hooks";
1255
+ import { useEffect as useEffect5, useRef as useRef8 } from "preact/hooks";
1247
1256
  import { jsx as jsx25, jsxs as jsxs11 } from "preact/jsx-runtime";
1248
1257
  function Slider(props) {
1249
1258
  let start = props.start ?? 0;
@@ -1257,7 +1266,7 @@ function Slider(props) {
1257
1266
  value = useSignal9(props.value);
1258
1267
  const ref = useRef8(null);
1259
1268
  const dragging = props.dragging ?? useSignal9(false);
1260
- useEffect6(() => {
1269
+ useEffect5(() => {
1261
1270
  dragging.subscribe((d) => {
1262
1271
  if (d)
1263
1272
  document.addEventListener("pointermove", updateFromEvent);
@@ -1418,7 +1427,7 @@ function Tag(props) {
1418
1427
 
1419
1428
  // src/components/TagList/TagListInput.tsx
1420
1429
  import { useSignal as useSignal11 } from "@preact/signals";
1421
- import { useRef as useRef9, useState as useState5 } from "preact/hooks";
1430
+ import { useRef as useRef9, useState as useState4 } from "preact/hooks";
1422
1431
  import { jsx as jsx29, jsxs as jsxs14 } from "preact/jsx-runtime";
1423
1432
  function TagListInput(props) {
1424
1433
  let value;
@@ -1429,7 +1438,7 @@ function TagListInput(props) {
1429
1438
  else
1430
1439
  value = useSignal11(props.value);
1431
1440
  const inputRef = useRef9();
1432
- const [inputValue, setInputValue] = useState5("");
1441
+ const [inputValue, setInputValue] = useState4("");
1433
1442
  return /* @__PURE__ */ jsxs14("div", { class: "tag-list", children: [
1434
1443
  value.value.map((t, i) => /* @__PURE__ */ jsx29(
1435
1444
  Tag,
@@ -1476,11 +1485,11 @@ function TagListInput(props) {
1476
1485
  }
1477
1486
 
1478
1487
  // src/components/UploadBox/UploadBox.tsx
1479
- import { useEffect as useEffect7, useRef as useRef10, useState as useState6 } from "preact/hooks";
1488
+ import { useEffect as useEffect6, useRef as useRef10, useState as useState5 } from "preact/hooks";
1480
1489
  import { jsx as jsx30, jsxs as jsxs15 } from "preact/jsx-runtime";
1481
1490
  function UploadBox(props) {
1482
1491
  const inputRef = useRef10(null);
1483
- const [dragging, setDragging] = useState6(false);
1492
+ const [dragging, setDragging] = useState5(false);
1484
1493
  function handleFiles(files) {
1485
1494
  files = Array.from(files);
1486
1495
  if (!props.addFile)
@@ -1490,7 +1499,7 @@ function UploadBox(props) {
1490
1499
  ;
1491
1500
  }
1492
1501
  }
1493
- useEffect7(() => {
1502
+ useEffect6(() => {
1494
1503
  const onPaste = (e) => {
1495
1504
  const files = e.clipboardData?.files;
1496
1505
  if (files && files.length > 0)
@@ -366,9 +366,9 @@ a.button {
366
366
  visibility: hidden;
367
367
  box-sizing: border-box;
368
368
  width: max-content;
369
- min-width: min(180px, calc(100vw - 16px));
370
- max-width: calc(100vw - 16px);
371
- max-height: calc(100vh - 16px);
369
+ min-width: min(180px, calc(100vw - 20px));
370
+ max-width: calc(100vw - 20px);
371
+ max-height: calc(100vh - 20px);
372
372
  overflow: auto;
373
373
  overscroll-behavior: contain;
374
374
  padding: 5px;
@@ -61,7 +61,7 @@ import {
61
61
  getFileIcon,
62
62
  openContextMenu,
63
63
  openContextMenuOn
64
- } from "../chunk-M6LQH7LY.js";
64
+ } from "../chunk-GEOGVOJN.js";
65
65
  import "../chunk-CE4YXNWV.js";
66
66
  import "../chunk-6G3G7N5D.js";
67
67
  export {
package/dist/index.css CHANGED
@@ -474,9 +474,9 @@ a.button {
474
474
  visibility: hidden;
475
475
  box-sizing: border-box;
476
476
  width: max-content;
477
- min-width: min(180px, calc(100vw - 16px));
478
- max-width: calc(100vw - 16px);
479
- max-height: calc(100vh - 16px);
477
+ min-width: min(180px, calc(100vw - 20px));
478
+ max-width: calc(100vw - 20px);
479
+ max-height: calc(100vh - 20px);
480
480
  overflow: auto;
481
481
  overscroll-behavior: contain;
482
482
  padding: 5px;
package/dist/index.js CHANGED
@@ -62,7 +62,7 @@ import {
62
62
  getFileIcon,
63
63
  openContextMenu,
64
64
  openContextMenuOn
65
- } from "./chunk-M6LQH7LY.js";
65
+ } from "./chunk-GEOGVOJN.js";
66
66
  import {
67
67
  MOBILE,
68
68
  addClass,
package/dist/style.css CHANGED
@@ -474,9 +474,9 @@ a.button {
474
474
  visibility: hidden;
475
475
  box-sizing: border-box;
476
476
  width: max-content;
477
- min-width: min(180px, calc(100vw - 16px));
478
- max-width: calc(100vw - 16px);
479
- max-height: calc(100vh - 16px);
477
+ min-width: min(180px, calc(100vw - 20px));
478
+ max-width: calc(100vw - 20px);
479
+ max-height: calc(100vh - 20px);
480
480
  overflow: auto;
481
481
  overscroll-behavior: contain;
482
482
  padding: 5px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flufi-ui",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "source": "src/index.ts",
6
6
  "main": "./dist/index.js",