flufi-ui 0.1.1 → 0.1.3

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.
@@ -32,6 +32,7 @@ function Button(props) {
32
32
  props.variant && `variant-${props.variant}`,
33
33
  props.centered && "centered",
34
34
  props.extraPadding && "extra-padding",
35
+ props.somePadding && "some-padding",
35
36
  props.noPadding && "no-padding",
36
37
  props.class
37
38
  ),
@@ -68,6 +69,7 @@ function LinkButton(props) {
68
69
  props.variant && `variant-${props.variant}`,
69
70
  props.centered && "centered",
70
71
  props.extraPadding && "extra-padding",
72
+ props.somePadding && "some-padding",
71
73
  props.noPadding && "no-padding",
72
74
  props.class
73
75
  ),
@@ -91,7 +93,7 @@ function TextIconLinkButton(props) {
91
93
 
92
94
  // src/components/CalendarInput/CalendarInput.tsx
93
95
  import { useSignal as useSignal3 } from "@preact/signals";
94
- import { useEffect as useEffect2, useState as useState2 } from "preact/hooks";
96
+ import { useEffect, useState } from "preact/hooks";
95
97
  import { Calendar, ChevronLeft, ChevronRight } from "lucide-preact";
96
98
 
97
99
  // src/components/Container/Container.tsx
@@ -127,19 +129,35 @@ function AsideContainer(props) {
127
129
 
128
130
  // src/components/Popout/Popout.tsx
129
131
  import { useSignal } from "@preact/signals";
130
- import { useEffect, useRef, useState } from "preact/hooks";
132
+ import { useLayoutEffect, useRef } from "preact/hooks";
131
133
  import { createPortal } from "preact/compat";
134
+
135
+ // src/components/Popout/position.ts
136
+ function getPopoutTop(anchor, height, viewportHeight) {
137
+ const gap = 5;
138
+ const below = anchor.bottom + gap;
139
+ return viewportHeight - (below + height) <= 10 ? anchor.top - height - gap : below;
140
+ }
141
+
142
+ // src/components/Popout/Popout.tsx
132
143
  import { jsx as jsx4, jsxs } from "preact/jsx-runtime";
133
144
  function PopoutContainer(props) {
134
145
  const open = props.open ?? useSignal(false);
135
- const [rect, setRect] = useState(null);
136
146
  const anchorRef = useRef(null);
137
147
  const popoutRef = useRef(null);
138
- useEffect(() => {
139
- if (!open)
148
+ useLayoutEffect(() => {
149
+ if (!open.value)
140
150
  return;
151
+ const popout = popoutRef.current;
141
152
  function updateRect() {
142
- setRect(anchorRef.current?.getBoundingClientRect() ?? null);
153
+ const rect = anchorRef.current?.getBoundingClientRect();
154
+ if (!rect)
155
+ return;
156
+ popout.style.left = `${rect.left}px`;
157
+ popout.style.width = `${Math.max(0, rect.width - 2)}px`;
158
+ const height = popout.getBoundingClientRect().height;
159
+ popout.style.top = `${getPopoutTop(rect, height, window.innerHeight)}px`;
160
+ popout.style.visibility = "visible";
143
161
  }
144
162
  function onPointerDown(e) {
145
163
  const target = e.target;
@@ -154,24 +172,28 @@ function PopoutContainer(props) {
154
172
  open.value = false;
155
173
  }
156
174
  updateRect();
175
+ const observer = new ResizeObserver(updateRect);
176
+ observer.observe(popout);
177
+ observer.observe(anchorRef.current);
157
178
  document.addEventListener("mousedown", onPointerDown);
158
179
  document.addEventListener("keydown", onKeyDown);
159
180
  window.addEventListener("resize", updateRect);
160
181
  window.addEventListener("scroll", updateRect, true);
161
182
  return () => {
183
+ observer.disconnect();
162
184
  document.removeEventListener("mousedown", onPointerDown);
163
185
  document.removeEventListener("keydown", onKeyDown);
164
186
  window.removeEventListener("resize", updateRect);
165
187
  window.removeEventListener("scroll", updateRect, true);
166
188
  };
167
- }, [open]);
189
+ }, [open.value]);
168
190
  return /* @__PURE__ */ jsxs("div", { ref: anchorRef, class: addClass(
169
191
  "popout-container",
170
192
  open.value && "open",
171
193
  props.class
172
194
  ), children: [
173
195
  props.children,
174
- open.value && rect && createPortal(
196
+ open.value && createPortal(
175
197
  /* @__PURE__ */ jsx4(
176
198
  "div",
177
199
  {
@@ -181,18 +203,7 @@ function PopoutContainer(props) {
181
203
  MOBILE.value && "mobile-popout",
182
204
  props.popoutClass
183
205
  ),
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
- },
206
+ style: { visibility: "hidden" },
196
207
  children: props.popout()
197
208
  }
198
209
  ),
@@ -209,6 +220,7 @@ function PopoutTextButton(props) {
209
220
  onClick: () => open.value = !open.peek(),
210
221
  disabled: props.disabled,
211
222
  extraPadding: props.extraPadding,
223
+ somePadding: props.somePadding,
212
224
  centered: props.centered,
213
225
  variant: props.variant,
214
226
  title: props.title,
@@ -225,6 +237,7 @@ function PopoutIconButton(props) {
225
237
  onClick: () => open.value = !open.peek(),
226
238
  disabled: props.disabled,
227
239
  extraPadding: props.extraPadding,
240
+ somePadding: props.somePadding,
228
241
  centered: props.centered,
229
242
  variant: props.variant,
230
243
  title: props.title,
@@ -241,6 +254,7 @@ function PopoutTextIconButton(props) {
241
254
  onClick: () => open.value = !open.peek(),
242
255
  disabled: props.disabled,
243
256
  extraPadding: props.extraPadding,
257
+ somePadding: props.somePadding,
244
258
  centered: props.centered,
245
259
  variant: props.variant,
246
260
  title: props.title,
@@ -324,15 +338,15 @@ function CalendarInput(props) {
324
338
  const popoutOpen = useSignal3(false);
325
339
  const now = /* @__PURE__ */ new Date();
326
340
  const initial = value.peek();
327
- const [viewYear, setViewYear] = useState2(initial?.year ?? now.getFullYear());
328
- const [viewMonth, setViewMonth] = useState2(initial?.month ?? now.getMonth() + 1);
341
+ const [viewYear, setViewYear] = useState(initial?.year ?? now.getFullYear());
342
+ const [viewMonth, setViewMonth] = useState(initial?.month ?? now.getMonth() + 1);
329
343
  const inputText = useSignal3(value.value?.toString() ?? "");
330
344
  function updateView() {
331
345
  const parts = (value.peek() ?? CalendarDate.now()).parts;
332
346
  setViewYear(parts.year);
333
347
  setViewMonth(parts.month);
334
348
  }
335
- useEffect2(() => {
349
+ useEffect(() => {
336
350
  updateView();
337
351
  }, [popoutOpen.value]);
338
352
  function commit(next, dontClose, dontSetInput) {
@@ -521,7 +535,7 @@ function Content(props) {
521
535
  // src/components/ContextMenu/ContextMenu.tsx
522
536
  import { render } from "preact";
523
537
  import { createPortal as createPortal2 } from "preact/compat";
524
- import { useLayoutEffect, useRef as useRef3 } from "preact/hooks";
538
+ import { useLayoutEffect as useLayoutEffect2, useRef as useRef3 } from "preact/hooks";
525
539
 
526
540
  // src/components/Text/Text.tsx
527
541
  import { jsx as jsx9 } from "preact/jsx-runtime";
@@ -540,7 +554,7 @@ function Text(props) {
540
554
 
541
555
  // src/components/ContextMenu/position.ts
542
556
  function getContextMenuPlacement(target, size, viewport) {
543
- const margin = 8;
557
+ const margin = 10;
544
558
  const gap = 6;
545
559
  const maxWidth = Math.max(0, viewport.width - margin * 2);
546
560
  const maxHeight = Math.max(0, viewport.height - margin * 2);
@@ -550,12 +564,12 @@ function getContextMenuPlacement(target, size, viewport) {
550
564
  const clampY = (y, h = height) => Math.max(margin, Math.min(y, viewport.height - margin - h));
551
565
  if (!("bottom" in target)) {
552
566
  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;
567
+ const top = target.y + height >= viewport.height - margin ? target.y - height : target.y;
554
568
  return { left: clampX(left), top: clampY(top), maxHeight };
555
569
  }
556
570
  const below = Math.max(0, viewport.height - margin - target.bottom - gap);
557
571
  const above = Math.max(0, target.top - margin - gap);
558
- if (height <= below)
572
+ if (height < below)
559
573
  return { left: clampX(target.left), top: clampY(target.bottom + gap), maxHeight: below };
560
574
  if (height <= above)
561
575
  return { left: clampX(target.left), top: clampY(target.top - gap - height), maxHeight: above };
@@ -620,7 +634,7 @@ function openContextMenuOn(items, element) {
620
634
  }
621
635
  function ContextMenu(props) {
622
636
  const menuRef = useRef3(null);
623
- useLayoutEffect(() => {
637
+ useLayoutEffect2(() => {
624
638
  const menu = menuRef.current;
625
639
  const anchor = props.target instanceof Element ? props.target : void 0;
626
640
  const getButtons = () => [...menu.querySelectorAll("button:not(:disabled)")];
@@ -920,12 +934,12 @@ function MiniHeader(props) {
920
934
  }
921
935
 
922
936
  // src/components/Image/Image.tsx
923
- import { useEffect as useEffect3, useRef as useRef4, useState as useState3 } from "preact/hooks";
937
+ import { useEffect as useEffect2, useRef as useRef4, useState as useState2 } from "preact/hooks";
924
938
  import { jsx as jsx17 } from "preact/jsx-runtime";
925
939
  function Image2(props) {
926
- const [src, setSrc] = useState3();
940
+ const [src, setSrc] = useState2();
927
941
  const lastSrc = useRef4();
928
- useEffect3(() => {
942
+ useEffect2(() => {
929
943
  if (lastSrc.current)
930
944
  URL.revokeObjectURL(lastSrc.current);
931
945
  const newSrc = resolveSignalish(props.src);
@@ -1055,7 +1069,7 @@ function Textarea(props) {
1055
1069
  }
1056
1070
 
1057
1071
  // src/components/Loading/Loading.tsx
1058
- import { useEffect as useEffect4, useState as useState4 } from "preact/hooks";
1072
+ import { useEffect as useEffect3, useState as useState3 } from "preact/hooks";
1059
1073
 
1060
1074
  // src/components/Throbber/Throbber.tsx
1061
1075
  import { Loader2 } from "lucide-preact";
@@ -1067,14 +1081,14 @@ function Throbber(props) {
1067
1081
  // src/components/Loading/Loading.tsx
1068
1082
  import { jsx as jsx21, jsxs as jsxs8 } from "preact/jsx-runtime";
1069
1083
  function Loading(props) {
1070
- const [loaded, setLoaded] = useState4(false);
1084
+ const [loaded, setLoaded] = useState3(false);
1071
1085
  {
1072
1086
  const out = resolveMaybeFunc(props.loaded);
1073
1087
  if (!(out instanceof Promise)) {
1074
1088
  setLoaded(resolveSignalish(out));
1075
1089
  }
1076
1090
  }
1077
- useEffect4(syncWrap(async () => {
1091
+ useEffect3(syncWrap(async () => {
1078
1092
  let data = resolveSignalish(await resolveMaybeAsyncFunc(props.loaded));
1079
1093
  setLoaded(data);
1080
1094
  }), [props.loaded]);
@@ -1087,7 +1101,7 @@ function Loading(props) {
1087
1101
  // src/components/PathInput/PathInput.tsx
1088
1102
  import { useSignal as useSignal7 } from "@preact/signals";
1089
1103
  import { Fragment as Fragment2 } from "preact";
1090
- import { useEffect as useEffect5, useRef as useRef7 } from "preact/hooks";
1104
+ import { useEffect as useEffect4, useRef as useRef7 } from "preact/hooks";
1091
1105
  import { ChevronRight as ChevronRight2 } from "lucide-preact";
1092
1106
  import { jsx as jsx22, jsxs as jsxs9 } from "preact/jsx-runtime";
1093
1107
  function PathInput(props) {
@@ -1118,13 +1132,13 @@ function PathInput(props) {
1118
1132
  const end = combined.peek().length;
1119
1133
  inputRef.current?.setSelectionRange(end, end);
1120
1134
  }
1121
- useEffect5(() => {
1135
+ useEffect4(() => {
1122
1136
  if (!isSignal(props.value)) return;
1123
1137
  return props.value.subscribe((val) => {
1124
1138
  if (!editing.peek()) parts.value = splitPath(val);
1125
1139
  });
1126
1140
  }, [props.value]);
1127
- useEffect5(() => {
1141
+ useEffect4(() => {
1128
1142
  const el = pathRef.current;
1129
1143
  if (!el) return;
1130
1144
  requestAnimationFrame(() => {
@@ -1243,7 +1257,7 @@ function Seperator() {
1243
1257
 
1244
1258
  // src/components/Slider/Slider.tsx
1245
1259
  import { useSignal as useSignal9 } from "@preact/signals";
1246
- import { useEffect as useEffect6, useRef as useRef8 } from "preact/hooks";
1260
+ import { useEffect as useEffect5, useRef as useRef8 } from "preact/hooks";
1247
1261
  import { jsx as jsx25, jsxs as jsxs11 } from "preact/jsx-runtime";
1248
1262
  function Slider(props) {
1249
1263
  let start = props.start ?? 0;
@@ -1257,7 +1271,7 @@ function Slider(props) {
1257
1271
  value = useSignal9(props.value);
1258
1272
  const ref = useRef8(null);
1259
1273
  const dragging = props.dragging ?? useSignal9(false);
1260
- useEffect6(() => {
1274
+ useEffect5(() => {
1261
1275
  dragging.subscribe((d) => {
1262
1276
  if (d)
1263
1277
  document.addEventListener("pointermove", updateFromEvent);
@@ -1418,7 +1432,7 @@ function Tag(props) {
1418
1432
 
1419
1433
  // src/components/TagList/TagListInput.tsx
1420
1434
  import { useSignal as useSignal11 } from "@preact/signals";
1421
- import { useRef as useRef9, useState as useState5 } from "preact/hooks";
1435
+ import { useRef as useRef9, useState as useState4 } from "preact/hooks";
1422
1436
  import { jsx as jsx29, jsxs as jsxs14 } from "preact/jsx-runtime";
1423
1437
  function TagListInput(props) {
1424
1438
  let value;
@@ -1429,7 +1443,7 @@ function TagListInput(props) {
1429
1443
  else
1430
1444
  value = useSignal11(props.value);
1431
1445
  const inputRef = useRef9();
1432
- const [inputValue, setInputValue] = useState5("");
1446
+ const [inputValue, setInputValue] = useState4("");
1433
1447
  return /* @__PURE__ */ jsxs14("div", { class: "tag-list", children: [
1434
1448
  value.value.map((t, i) => /* @__PURE__ */ jsx29(
1435
1449
  Tag,
@@ -1476,11 +1490,11 @@ function TagListInput(props) {
1476
1490
  }
1477
1491
 
1478
1492
  // src/components/UploadBox/UploadBox.tsx
1479
- import { useEffect as useEffect7, useRef as useRef10, useState as useState6 } from "preact/hooks";
1493
+ import { useEffect as useEffect6, useRef as useRef10, useState as useState5 } from "preact/hooks";
1480
1494
  import { jsx as jsx30, jsxs as jsxs15 } from "preact/jsx-runtime";
1481
1495
  function UploadBox(props) {
1482
1496
  const inputRef = useRef10(null);
1483
- const [dragging, setDragging] = useState6(false);
1497
+ const [dragging, setDragging] = useState5(false);
1484
1498
  function handleFiles(files) {
1485
1499
  files = Array.from(files);
1486
1500
  if (!props.addFile)
@@ -1490,7 +1504,7 @@ function UploadBox(props) {
1490
1504
  ;
1491
1505
  }
1492
1506
  }
1493
- useEffect7(() => {
1507
+ useEffect6(() => {
1494
1508
  const onPaste = (e) => {
1495
1509
  const files = e.clipboardData?.files;
1496
1510
  if (files && files.length > 0)
@@ -94,6 +94,9 @@
94
94
  padding-right: 14px !important;
95
95
  }
96
96
  }
97
+ .button.some-padding:not(.no-padding) {
98
+ padding: 2px !important;
99
+ }
97
100
  a.button {
98
101
  color: inherit;
99
102
  }
@@ -366,9 +369,9 @@ a.button {
366
369
  visibility: hidden;
367
370
  box-sizing: border-box;
368
371
  width: max-content;
369
- min-width: min(180px, calc(100vw - 16px));
370
- max-width: calc(100vw - 16px);
371
- max-height: calc(100vh - 16px);
372
+ min-width: min(180px, calc(100vw - 20px));
373
+ max-width: calc(100vw - 20px);
374
+ max-height: calc(100vh - 20px);
372
375
  overflow: auto;
373
376
  overscroll-behavior: contain;
374
377
  padding: 5px;
@@ -14,6 +14,7 @@ type ButtonProps = {
14
14
  title?: string;
15
15
  disabled?: boolean;
16
16
  extraPadding?: boolean;
17
+ somePadding?: boolean;
17
18
  noPadding?: boolean;
18
19
  centered?: boolean;
19
20
  role?: JSX.AriaRole;
@@ -33,6 +34,7 @@ type LinkButtonProps = {
33
34
  onClick?: (e: MouseEvent) => void;
34
35
  href: string;
35
36
  extraPadding?: boolean;
37
+ somePadding?: boolean;
36
38
  noPadding?: boolean;
37
39
  centered?: boolean;
38
40
  role?: JSX.AriaRole;
@@ -248,6 +250,7 @@ type PopoutButtonProps = {
248
250
  buttonClass?: string;
249
251
  disabled?: boolean;
250
252
  extraPadding?: boolean;
253
+ somePadding?: boolean;
251
254
  centered?: boolean;
252
255
  variant?: ButtonVariant;
253
256
  title?: string;
@@ -61,7 +61,7 @@ import {
61
61
  getFileIcon,
62
62
  openContextMenu,
63
63
  openContextMenuOn
64
- } from "../chunk-M6LQH7LY.js";
64
+ } from "../chunk-G343EGOL.js";
65
65
  import "../chunk-CE4YXNWV.js";
66
66
  import "../chunk-6G3G7N5D.js";
67
67
  export {
package/dist/index.css CHANGED
@@ -25,6 +25,8 @@
25
25
  --shadow: #0a0a0a45;
26
26
  --shadow-raised: 1px 4px 10px 0px var(--shadow);
27
27
  --transition-fast: .1s;
28
+ --transition-normal: .2s;
29
+ --transition-slow: .5s;
28
30
  --font-size: 14px;
29
31
  --font-size-medium: 12px;
30
32
  --font-size-small: 11px;
@@ -202,6 +204,9 @@ textarea {
202
204
  padding-right: 14px !important;
203
205
  }
204
206
  }
207
+ .button.some-padding:not(.no-padding) {
208
+ padding: 2px !important;
209
+ }
205
210
  a.button {
206
211
  color: inherit;
207
212
  }
@@ -474,9 +479,9 @@ a.button {
474
479
  visibility: hidden;
475
480
  box-sizing: border-box;
476
481
  width: max-content;
477
- min-width: min(180px, calc(100vw - 16px));
478
- max-width: calc(100vw - 16px);
479
- max-height: calc(100vh - 16px);
482
+ min-width: min(180px, calc(100vw - 20px));
483
+ max-width: calc(100vw - 20px);
484
+ max-height: calc(100vh - 20px);
480
485
  overflow: auto;
481
486
  overscroll-behavior: contain;
482
487
  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-G343EGOL.js";
66
66
  import {
67
67
  MOBILE,
68
68
  addClass,
package/dist/style.css CHANGED
@@ -25,6 +25,8 @@
25
25
  --shadow: #0a0a0a45;
26
26
  --shadow-raised: 1px 4px 10px 0px var(--shadow);
27
27
  --transition-fast: .1s;
28
+ --transition-normal: .2s;
29
+ --transition-slow: .5s;
28
30
  --font-size: 14px;
29
31
  --font-size-medium: 12px;
30
32
  --font-size-small: 11px;
@@ -202,6 +204,9 @@ textarea {
202
204
  padding-right: 14px !important;
203
205
  }
204
206
  }
207
+ .button.some-padding:not(.no-padding) {
208
+ padding: 2px !important;
209
+ }
205
210
  a.button {
206
211
  color: inherit;
207
212
  }
@@ -474,9 +479,9 @@ a.button {
474
479
  visibility: hidden;
475
480
  box-sizing: border-box;
476
481
  width: max-content;
477
- min-width: min(180px, calc(100vw - 16px));
478
- max-width: calc(100vw - 16px);
479
- max-height: calc(100vh - 16px);
482
+ min-width: min(180px, calc(100vw - 20px));
483
+ max-width: calc(100vw - 20px);
484
+ max-height: calc(100vh - 20px);
480
485
  overflow: auto;
481
486
  overscroll-behavior: contain;
482
487
  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.3",
4
4
  "type": "module",
5
5
  "source": "src/index.ts",
6
6
  "main": "./dist/index.js",