@kahitsan/ksui 0.28.0 → 0.29.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kahitsan/ksui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "ksui is a standalone set of SolidJS UI components for KahitSan/Hilinga and any SolidJS app. Published to the public npm registry and consumed as a normal dependency. Ships source under a `solid` export condition so the consumer's vite-plugin-solid compiles it with only solid-js externalized; it depends on nothing but solid-js + lucide-solid and injects its own CSS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// route and render the resulting blob: (the proxy/blob pattern). s3_link is then
|
|
11
11
|
// ignored for rendering; a spinner shows while the bytes stream.
|
|
12
12
|
|
|
13
|
-
import { Show, type Component } from "solid-js";
|
|
13
|
+
import { Show, createSignal, type Component } from "solid-js";
|
|
14
14
|
import Paperclip from "lucide-solid/icons/paperclip";
|
|
15
15
|
import X from "lucide-solid/icons/x";
|
|
16
16
|
import TriangleAlert from "lucide-solid/icons/triangle-alert";
|
|
@@ -18,6 +18,7 @@ import Loader2 from "lucide-solid/icons/loader-2";
|
|
|
18
18
|
import { confirm } from "../../utils/confirm";
|
|
19
19
|
import { attachmentUrl, isResolvableAttachment } from "../../utils/attachments";
|
|
20
20
|
import { createObjectUrlResource } from "../../utils/object-url-resource";
|
|
21
|
+
import ImageViewer from "./ImageViewer";
|
|
21
22
|
|
|
22
23
|
export interface ExistingAttachment {
|
|
23
24
|
id: number;
|
|
@@ -50,6 +51,7 @@ export default function ExistingAttachmentTile(props: Props) {
|
|
|
50
51
|
const resolvable = () =>
|
|
51
52
|
isBlobMode() ? blob() != null : isResolvableAttachment(props.attachment.s3_link);
|
|
52
53
|
const loading = () => (isBlobMode() ? blob.loading : false);
|
|
54
|
+
const [viewerOpen, setViewerOpen] = createSignal(false);
|
|
53
55
|
|
|
54
56
|
const FallbackIcon = () => {
|
|
55
57
|
const Icon = props.fallbackIcon ?? Paperclip;
|
|
@@ -87,8 +89,7 @@ export default function ExistingAttachmentTile(props: Props) {
|
|
|
87
89
|
fallback={
|
|
88
90
|
<a
|
|
89
91
|
href={url()}
|
|
90
|
-
|
|
91
|
-
rel="noopener"
|
|
92
|
+
download={props.attachment.file_name}
|
|
92
93
|
class="flex w-24 h-24 flex-col items-center justify-center gap-1 rounded-lg border border-zinc-700 bg-zinc-800/50 px-2 text-xs text-zinc-300 hover:border-amber-500/30"
|
|
93
94
|
>
|
|
94
95
|
<FallbackIcon />
|
|
@@ -96,14 +97,13 @@ export default function ExistingAttachmentTile(props: Props) {
|
|
|
96
97
|
</a>
|
|
97
98
|
}
|
|
98
99
|
>
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
class="block rounded-lg border border-zinc-700 overflow-hidden hover:border-amber-500/30"
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
onClick={() => setViewerOpen(true)}
|
|
103
|
+
class="block rounded-lg border border-zinc-700 overflow-hidden hover:border-amber-500/30 cursor-pointer"
|
|
104
104
|
>
|
|
105
105
|
<img src={url()} alt={props.attachment.file_name} class="w-24 h-24 object-cover" />
|
|
106
|
-
</
|
|
106
|
+
</button>
|
|
107
107
|
</Show>
|
|
108
108
|
</Show>
|
|
109
109
|
<Show when={props.onDelete}>
|
|
@@ -124,6 +124,13 @@ export default function ExistingAttachmentTile(props: Props) {
|
|
|
124
124
|
<X size={12} />
|
|
125
125
|
</button>
|
|
126
126
|
</Show>
|
|
127
|
+
<Show when={viewerOpen() && url()}>
|
|
128
|
+
<ImageViewer
|
|
129
|
+
src={url()!}
|
|
130
|
+
alt={props.attachment.file_name}
|
|
131
|
+
onClose={() => setViewerOpen(false)}
|
|
132
|
+
/>
|
|
133
|
+
</Show>
|
|
127
134
|
</div>
|
|
128
135
|
);
|
|
129
136
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Fullscreen image lightbox (Facebook-style): the image centered on a near-opaque
|
|
2
|
+
// backdrop, dismissed by the X button, a backdrop click, or Escape. Built on the
|
|
3
|
+
// native <dialog> (showModal) for top-layer rendering + native Escape + focus
|
|
4
|
+
// containment — the same approach as Modal — but full-bleed with no card chrome,
|
|
5
|
+
// so the image fills the viewport.
|
|
6
|
+
//
|
|
7
|
+
// Why this exists: assets are now served as same-origin object URLs (blob:), which
|
|
8
|
+
// are revoked when their owning component unmounts — so opening one in a new tab
|
|
9
|
+
// (target="_blank") breaks the moment the source view closes. An in-page viewer
|
|
10
|
+
// renders the blob while it's still alive.
|
|
11
|
+
//
|
|
12
|
+
// Like the rest of ksui, no sidecar CSS: styles inject once via a runtime <style>
|
|
13
|
+
// with unscoped `ksui-imgviewer-*` class names. Mount === open, unmount === closed
|
|
14
|
+
// (wrap in `<Show when={…}>`).
|
|
15
|
+
|
|
16
|
+
import { onCleanup, onMount } from "solid-js";
|
|
17
|
+
import X from "lucide-solid/icons/x";
|
|
18
|
+
import { lockPullToRefresh, unlockPullToRefresh } from "../../utils/dom";
|
|
19
|
+
|
|
20
|
+
const STYLE_ID = "ksui-image-viewer-style";
|
|
21
|
+
|
|
22
|
+
function ensureStyle(): void {
|
|
23
|
+
if (typeof document === "undefined") return;
|
|
24
|
+
if (document.getElementById(STYLE_ID)) return;
|
|
25
|
+
const style = document.createElement("style");
|
|
26
|
+
style.id = STYLE_ID;
|
|
27
|
+
style.textContent = `
|
|
28
|
+
.ksui-imgviewer{position:fixed;inset:0;z-index:60;background:transparent;padding:0;margin:0;max-width:none;max-height:none;width:100vw;height:100vh;border:0;}
|
|
29
|
+
.ksui-imgviewer[open]{display:flex;align-items:center;justify-content:center;}
|
|
30
|
+
.ksui-imgviewer::backdrop{background:rgba(0,0,0,0.92);backdrop-filter:blur(2px);}
|
|
31
|
+
.ksui-imgviewer-img{max-width:96vw;max-height:96vh;object-fit:contain;border-radius:0.25rem;box-shadow:0 25px 50px -12px rgba(0,0,0,0.8);}
|
|
32
|
+
.ksui-imgviewer-close{position:absolute;top:1rem;right:1rem;display:flex;width:2.5rem;height:2.5rem;align-items:center;justify-content:center;border-radius:9999px;background:rgba(255,255,255,0.12);color:#fff;border:0;cursor:pointer;}
|
|
33
|
+
.ksui-imgviewer-close:hover{background:rgba(255,255,255,0.22);}
|
|
34
|
+
`;
|
|
35
|
+
document.head.appendChild(style);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Props {
|
|
39
|
+
/** Image URL to display (typically a blob: object URL or a public link). */
|
|
40
|
+
src: string;
|
|
41
|
+
/** Accessible name + img alt. */
|
|
42
|
+
alt?: string;
|
|
43
|
+
/** Fired on the X button, a backdrop click, or Escape. */
|
|
44
|
+
onClose: () => void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default function ImageViewer(props: Props) {
|
|
48
|
+
ensureStyle();
|
|
49
|
+
let dialogEl: HTMLDialogElement | undefined;
|
|
50
|
+
|
|
51
|
+
lockPullToRefresh();
|
|
52
|
+
onCleanup(unlockPullToRefresh);
|
|
53
|
+
|
|
54
|
+
onMount(() => {
|
|
55
|
+
if (dialogEl && !dialogEl.open) {
|
|
56
|
+
try {
|
|
57
|
+
dialogEl.showModal();
|
|
58
|
+
} catch {
|
|
59
|
+
// showModal throws if already open or detached; harmless to ignore.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
onCleanup(() => {
|
|
64
|
+
if (dialogEl?.open) dialogEl.close();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Escape fires the dialog's native `cancel`; intercept it to route through onClose.
|
|
68
|
+
const handleCancel = (e: Event) => {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
props.onClose();
|
|
71
|
+
};
|
|
72
|
+
// A click whose target IS the dialog landed on the backdrop (the image + button
|
|
73
|
+
// are inner elements and stop here), so close.
|
|
74
|
+
const handleClick = (e: MouseEvent) => {
|
|
75
|
+
if (e.target === dialogEl) props.onClose();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
|
|
80
|
+
<dialog
|
|
81
|
+
ref={dialogEl}
|
|
82
|
+
aria-modal="true"
|
|
83
|
+
aria-label={props.alt || "Image viewer"}
|
|
84
|
+
onCancel={handleCancel}
|
|
85
|
+
onClick={handleClick}
|
|
86
|
+
class="ksui-imgviewer"
|
|
87
|
+
>
|
|
88
|
+
<button
|
|
89
|
+
type="button"
|
|
90
|
+
aria-label="Close"
|
|
91
|
+
onClick={props.onClose}
|
|
92
|
+
class="ksui-imgviewer-close"
|
|
93
|
+
>
|
|
94
|
+
<X size={22} />
|
|
95
|
+
</button>
|
|
96
|
+
<img src={props.src} alt={props.alt || ""} class="ksui-imgviewer-img" />
|
|
97
|
+
</dialog>
|
|
98
|
+
);
|
|
99
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -52,6 +52,7 @@ export { default as FormField } from "./components/base/FormField";
|
|
|
52
52
|
export { default as DetailRow } from "./components/base/DetailRow";
|
|
53
53
|
export { default as Tooltip } from "./components/base/Tooltip";
|
|
54
54
|
export { default as ImageCropper } from "./components/base/ImageCropper";
|
|
55
|
+
export { default as ImageViewer } from "./components/base/ImageViewer";
|
|
55
56
|
export { default as ProgressBar, type ProgressBarProps } from "./components/base/ProgressBar";
|
|
56
57
|
export { default as ChartLegend } from "./components/base/ChartLegend";
|
|
57
58
|
|