@optiaxiom/proteus 1.1.5 → 1.1.6
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.
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { Box, Button, Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTrigger, Spinner } from "@optiaxiom/react";
|
|
2
|
+
import { Box, Spinner } from "@optiaxiom/react";
|
|
4
3
|
import { useState } from "react";
|
|
5
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
5
|
//#region src/proteus-image/ProteusImage.tsx
|
|
7
|
-
function ProteusImage(props) {
|
|
8
|
-
const { onEvent } = useProteusDocumentContext("@optiaxiom/proteus/ProteusImage");
|
|
9
|
-
const [open, setOpen] = useState(false);
|
|
10
|
-
const [isDownloading, setIsDownloading] = useState(false);
|
|
6
|
+
function ProteusImage({ ...props }) {
|
|
11
7
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
12
8
|
return /* @__PURE__ */ jsxs(Fragment, { children: [!isLoaded && /* @__PURE__ */ jsx(Box, {
|
|
13
9
|
alignItems: "center",
|
|
@@ -16,87 +12,32 @@ function ProteusImage(props) {
|
|
|
16
12
|
justifyContent: "center",
|
|
17
13
|
p: "24",
|
|
18
14
|
rounded: "md",
|
|
19
|
-
style: { aspectRatio: "16 / 9" },
|
|
20
15
|
w: "full",
|
|
21
16
|
...props,
|
|
22
17
|
children: /* @__PURE__ */ jsx(Spinner, {})
|
|
23
|
-
}), /* @__PURE__ */
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
mime_type: "image/*",
|
|
47
|
-
name: props.src?.split("/").pop()
|
|
48
|
-
}));
|
|
49
|
-
},
|
|
50
|
-
onLoad: () => setIsLoaded(true),
|
|
51
|
-
src: props.src
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
}), /* @__PURE__ */ jsxs(DialogContent, {
|
|
55
|
-
size: "fullscreen",
|
|
56
|
-
children: [
|
|
57
|
-
/* @__PURE__ */ jsx(DialogHeader, {
|
|
58
|
-
lineClamp: "1",
|
|
59
|
-
children: props.alt
|
|
60
|
-
}),
|
|
61
|
-
/* @__PURE__ */ jsx(DialogBody, {
|
|
62
|
-
overflow: "hidden",
|
|
63
|
-
children: /* @__PURE__ */ jsx(Box, {
|
|
64
|
-
asChild: true,
|
|
65
|
-
display: "block",
|
|
66
|
-
maxH: "full",
|
|
67
|
-
maxW: "full",
|
|
68
|
-
objectFit: "contain",
|
|
69
|
-
children: /* @__PURE__ */ jsx("img", {
|
|
70
|
-
alt: props.alt,
|
|
71
|
-
src: props.src
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
}),
|
|
75
|
-
/* @__PURE__ */ jsxs(DialogFooter, { children: [/* @__PURE__ */ jsx(DialogClose, { children: "Close" }), /* @__PURE__ */ jsx(Button, {
|
|
76
|
-
appearance: "primary",
|
|
77
|
-
asChild: true,
|
|
78
|
-
loading: isDownloading,
|
|
79
|
-
onClick: async (event) => {
|
|
80
|
-
event.preventDefault();
|
|
81
|
-
if (isDownloading) return;
|
|
82
|
-
setIsDownloading(true);
|
|
83
|
-
try {
|
|
84
|
-
await onEvent({
|
|
85
|
-
action: "download",
|
|
86
|
-
url: String(props.src)
|
|
87
|
-
});
|
|
88
|
-
} finally {
|
|
89
|
-
setIsDownloading(false);
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
children: /* @__PURE__ */ jsx("a", {
|
|
93
|
-
download: true,
|
|
94
|
-
href: props.src,
|
|
95
|
-
children: "Download"
|
|
96
|
-
})
|
|
97
|
-
})] })
|
|
98
|
-
]
|
|
99
|
-
})]
|
|
18
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
19
|
+
asChild: true,
|
|
20
|
+
display: isLoaded ? "flex" : "none",
|
|
21
|
+
objectFit: "contain",
|
|
22
|
+
overflow: "hidden",
|
|
23
|
+
rounded: "inherit",
|
|
24
|
+
size: "full",
|
|
25
|
+
...props,
|
|
26
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
27
|
+
alt: props.alt,
|
|
28
|
+
draggable: true,
|
|
29
|
+
onDragStart: (event) => {
|
|
30
|
+
event.stopPropagation();
|
|
31
|
+
event.dataTransfer.effectAllowed = "copy";
|
|
32
|
+
event.dataTransfer.setData("opal-chat-dnd-data", JSON.stringify({
|
|
33
|
+
link: props.src,
|
|
34
|
+
mime_type: "image/*",
|
|
35
|
+
name: props.src?.split("/").pop()
|
|
36
|
+
}));
|
|
37
|
+
},
|
|
38
|
+
onLoad: () => setIsLoaded(true),
|
|
39
|
+
src: props.src
|
|
40
|
+
})
|
|
100
41
|
})] });
|
|
101
42
|
}
|
|
102
43
|
ProteusImage.displayName = "@optiaxiom/proteus/ProteusImage";
|
|
@@ -24,8 +24,9 @@ function ProteusImageCarousel({ images, title }) {
|
|
|
24
24
|
const [canScrollNext, setCanScrollNext] = useState(false);
|
|
25
25
|
const onSelect = useCallback(() => {
|
|
26
26
|
if (!emblaMainApi || !emblaThumbsApi) return;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const index = emblaMainApi.selectedScrollSnap();
|
|
28
|
+
setSelectedIndex(index);
|
|
29
|
+
emblaThumbsApi.scrollTo(index);
|
|
29
30
|
setCanScrollPrev(emblaMainApi.canScrollPrev());
|
|
30
31
|
setCanScrollNext(emblaMainApi.canScrollNext());
|
|
31
32
|
}, [emblaMainApi, emblaThumbsApi]);
|
|
@@ -61,7 +62,11 @@ function ProteusImageCarousel({ images, title }) {
|
|
|
61
62
|
children: /* @__PURE__ */ jsx(Group, {
|
|
62
63
|
...slideContainer(),
|
|
63
64
|
children: images.map((image, index) => /* @__PURE__ */ jsx(ProteusImage, {
|
|
64
|
-
alt: image.alt,
|
|
65
|
+
alt: image.name ?? image.alt,
|
|
66
|
+
onClick: () => onEvent({
|
|
67
|
+
action: "preview",
|
|
68
|
+
file: toPreviewFile(image)
|
|
69
|
+
}),
|
|
65
70
|
src: image.src,
|
|
66
71
|
...slide()
|
|
67
72
|
}, index))
|
|
@@ -96,7 +101,7 @@ function ProteusImageCarousel({ images, title }) {
|
|
|
96
101
|
objectFit: "cover",
|
|
97
102
|
size: "full",
|
|
98
103
|
children: /* @__PURE__ */ jsx("img", {
|
|
99
|
-
alt: image.alt,
|
|
104
|
+
alt: image.name ?? image.alt,
|
|
100
105
|
src: image.thumb ?? image.src
|
|
101
106
|
})
|
|
102
107
|
})
|
|
@@ -122,13 +127,13 @@ function ProteusImageCarousel({ images, title }) {
|
|
|
122
127
|
options: [{
|
|
123
128
|
execute: () => onEvent({
|
|
124
129
|
action: "download",
|
|
125
|
-
url: images[selectedIndex].src
|
|
130
|
+
url: images[selectedIndex].file_link ?? images[selectedIndex].src
|
|
126
131
|
}),
|
|
127
132
|
label: "Download this image"
|
|
128
133
|
}, {
|
|
129
134
|
execute: () => onEvent({
|
|
130
135
|
action: "download",
|
|
131
|
-
url: images.map((image) => image.src)
|
|
136
|
+
url: images.map((image) => image.file_link ?? image.src)
|
|
132
137
|
}),
|
|
133
138
|
label: "Download all images"
|
|
134
139
|
}],
|
|
@@ -142,7 +147,7 @@ function ProteusImageCarousel({ images, title }) {
|
|
|
142
147
|
ml: "auto",
|
|
143
148
|
onClick: () => onEvent({
|
|
144
149
|
action: "download",
|
|
145
|
-
url: images[0].src
|
|
150
|
+
url: images[0].file_link ?? images[0].src
|
|
146
151
|
}),
|
|
147
152
|
children: "Download"
|
|
148
153
|
})]
|
|
@@ -150,6 +155,15 @@ function ProteusImageCarousel({ images, title }) {
|
|
|
150
155
|
]
|
|
151
156
|
});
|
|
152
157
|
}
|
|
158
|
+
function toPreviewFile({ alt, extension, file_link, full_name, mime_type, name, src }) {
|
|
159
|
+
return {
|
|
160
|
+
extension: extension ?? "JPG",
|
|
161
|
+
file_link: file_link ?? src,
|
|
162
|
+
full_name: full_name ?? alt ?? src,
|
|
163
|
+
mime_type: mime_type ?? "image/jpeg",
|
|
164
|
+
name: name ?? alt ?? src
|
|
165
|
+
};
|
|
166
|
+
}
|
|
153
167
|
ProteusImageCarousel.displayName = "@optiaxiom/proteus/ProteusImageCarousel";
|
|
154
168
|
//#endregion
|
|
155
169
|
export { ProteusImageCarousel };
|
package/dist/index.d.ts
CHANGED
|
@@ -153,9 +153,11 @@ declare namespace ProteusFileUpload {
|
|
|
153
153
|
//#region src/proteus-image-carousel/ProteusImageCarousel.d.ts
|
|
154
154
|
type ProteusImageCarouselProps = {
|
|
155
155
|
/**
|
|
156
|
-
* Array of image data to display in the carousel.
|
|
156
|
+
* Array of image data to display in the carousel. The host is responsible for
|
|
157
|
+
* supplying the preview metadata on each item.
|
|
157
158
|
*/
|
|
158
|
-
images: Array<{
|
|
159
|
+
images: Array<ProteusPreviewFile & {
|
|
160
|
+
[key: string]: unknown;
|
|
159
161
|
/**
|
|
160
162
|
* Alternative text for the image.
|
|
161
163
|
*/
|
|
@@ -184,7 +186,9 @@ declare namespace ProteusImageCarousel {
|
|
|
184
186
|
//#endregion
|
|
185
187
|
//#region src/proteus-image/ProteusImage.d.ts
|
|
186
188
|
type ProteusImageProps = BoxProps<"img">;
|
|
187
|
-
declare function ProteusImage(
|
|
189
|
+
declare function ProteusImage({
|
|
190
|
+
...props
|
|
191
|
+
}: ProteusImageProps): import("react/jsx-runtime").JSX.Element;
|
|
188
192
|
declare namespace ProteusImage {
|
|
189
193
|
var displayName: string;
|
|
190
194
|
}
|
|
@@ -436,7 +440,7 @@ type ProteusDocumentShellProps = Pick<ComponentPropsWithoutRef<typeof Disclosure
|
|
|
436
440
|
* Callback when user triggers a preview action.
|
|
437
441
|
* Receives the file object to preview.
|
|
438
442
|
*/
|
|
439
|
-
onPreview?: (file:
|
|
443
|
+
onPreview?: (file: ProteusPreviewFile) => Promise<void> | void;
|
|
440
444
|
/**
|
|
441
445
|
* Callback when an analytics event is fired
|
|
442
446
|
*/
|
|
@@ -507,7 +511,7 @@ type ProteusEventHandler = {
|
|
|
507
511
|
}) | string;
|
|
508
512
|
} | {
|
|
509
513
|
action: "preview";
|
|
510
|
-
file:
|
|
514
|
+
file: ProteusPreviewFile;
|
|
511
515
|
} | {
|
|
512
516
|
action: "pushValue";
|
|
513
517
|
path: string;
|
|
@@ -521,6 +525,13 @@ type ProteusEventHandler = {
|
|
|
521
525
|
} | {
|
|
522
526
|
message: string | StructuredMessage;
|
|
523
527
|
};
|
|
528
|
+
type ProteusPreviewFile = {
|
|
529
|
+
extension: string;
|
|
530
|
+
file_link: string;
|
|
531
|
+
full_name: string;
|
|
532
|
+
mime_type: string;
|
|
533
|
+
name: string;
|
|
534
|
+
};
|
|
524
535
|
type StructuredMessage<F extends FileUploadMetadata = FileUploadMetadata> = {
|
|
525
536
|
files?: F[];
|
|
526
537
|
parts: Array<{
|
|
@@ -621,4 +632,4 @@ declare namespace ProteusTextarea {
|
|
|
621
632
|
//#region src/use-proteus-value/useProteusValue.d.ts
|
|
622
633
|
declare function useProteusValue(element: ProteusValueProps): any;
|
|
623
634
|
//#endregion
|
|
624
|
-
export { type FileUploadMetadata, ProteusAction, ProteusBridge, ProteusChart, ProteusDataTable, ProteusDateInput, ProteusDocumentRenderer, ProteusDocumentRendererProps, ProteusDocumentShell, ProteusDocumentShellProps, ProteusFederated, ProteusFileUpload, ProteusFileUploadProps, ProteusImage, ProteusImageCarousel, ProteusInput, ProteusLength, ProteusMap, ProteusMapIndex, ProteusPillMenu, ProteusPillMenuProps, ProteusRichTextEditor, ProteusSelect, ProteusShow, ProteusTextarea, type StructuredMessage, type UploadFile, safeParseDocument, useProteusValue };
|
|
635
|
+
export { type FileUploadMetadata, ProteusAction, ProteusBridge, ProteusChart, ProteusDataTable, ProteusDateInput, ProteusDocumentRenderer, ProteusDocumentRendererProps, ProteusDocumentShell, ProteusDocumentShellProps, ProteusFederated, ProteusFileUpload, ProteusFileUploadProps, ProteusImage, ProteusImageCarousel, ProteusInput, ProteusLength, ProteusMap, ProteusMapIndex, ProteusPillMenu, ProteusPillMenuProps, type ProteusPreviewFile, ProteusRichTextEditor, ProteusSelect, ProteusShow, ProteusTextarea, type StructuredMessage, type UploadFile, safeParseDocument, useProteusValue };
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"url": "git+https://github.com/optimizely-axiom/optiaxiom.git"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
-
"version": "1.1.
|
|
10
|
+
"version": "1.1.6",
|
|
11
11
|
"files": [
|
|
12
12
|
"dist/**",
|
|
13
13
|
"LICENSE"
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"embla-carousel-react": "^8.6.0",
|
|
40
40
|
"jsonpointer": "^5.0.1",
|
|
41
41
|
"recharts": "^3.8.1",
|
|
42
|
-
"@optiaxiom/
|
|
43
|
-
"@optiaxiom/
|
|
42
|
+
"@optiaxiom/react": "^1.9.40",
|
|
43
|
+
"@optiaxiom/icons": "^1.1.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@emotion/hash": "^0.9.2",
|