@solidxai/core-ui 0.1.14-beta.1 → 0.1.14-beta.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.
Files changed (41) hide show
  1. package/dist/components/core/common/PDFViewer.d.ts +15 -3
  2. package/dist/components/core/common/PDFViewer.d.ts.map +1 -1
  3. package/dist/components/core/common/PDFViewer.js +55 -39
  4. package/dist/components/core/common/PDFViewer.js.map +1 -1
  5. package/dist/components/core/common/PDFViewer.tsx +85 -89
  6. package/dist/components/core/extension/solid-core/media/relativeUri/MediaRelativeUriPreview.d.ts +4 -0
  7. package/dist/components/core/extension/solid-core/media/relativeUri/MediaRelativeUriPreview.d.ts.map +1 -0
  8. package/dist/components/core/extension/solid-core/media/relativeUri/MediaRelativeUriPreview.js +109 -0
  9. package/dist/components/core/extension/solid-core/media/relativeUri/MediaRelativeUriPreview.js.map +1 -0
  10. package/dist/components/core/extension/solid-core/media/relativeUri/MediaRelativeUriPreview.tsx +228 -0
  11. package/dist/components/core/form/SolidFormView.d.ts.map +1 -1
  12. package/dist/components/core/form/SolidFormView.js +3 -1
  13. package/dist/components/core/form/SolidFormView.js.map +1 -1
  14. package/dist/components/core/form/SolidFormView.tsx +3 -1
  15. package/dist/components/core/form/fields/ISolidField.d.ts +2 -0
  16. package/dist/components/core/form/fields/ISolidField.d.ts.map +1 -1
  17. package/dist/components/core/form/fields/ISolidField.js.map +1 -1
  18. package/dist/components/core/form/fields/ISolidField.tsx +2 -0
  19. package/dist/helpers/registry.d.ts.map +1 -1
  20. package/dist/helpers/registry.js +3 -0
  21. package/dist/helpers/registry.js.map +1 -1
  22. package/dist/helpers/registry.ts +3 -0
  23. package/dist/redux/api/mediaApi.d.ts +2 -1
  24. package/dist/redux/api/mediaApi.d.ts.map +1 -1
  25. package/dist/redux/api/mediaApi.js +8 -1
  26. package/dist/redux/api/mediaApi.js.map +1 -1
  27. package/dist/redux/api/mediaApi.ts +8 -1
  28. package/dist/redux/store/defaultStoreConfig.d.ts +1 -0
  29. package/dist/redux/store/defaultStoreConfig.d.ts.map +1 -1
  30. package/dist/resources/globals.css +121 -0
  31. package/dist/resources/solid-tailwind-generated.css +1 -1
  32. package/dist/routes/pages/admin/core/MediaUploadPage.d.ts +2 -0
  33. package/dist/routes/pages/admin/core/MediaUploadPage.d.ts.map +1 -0
  34. package/dist/routes/pages/admin/core/MediaUploadPage.js +205 -0
  35. package/dist/routes/pages/admin/core/MediaUploadPage.js.map +1 -0
  36. package/dist/routes/pages/admin/core/MediaUploadPage.tsx +272 -0
  37. package/dist/routes/solidRoutes.d.ts.map +1 -1
  38. package/dist/routes/solidRoutes.js +2 -0
  39. package/dist/routes/solidRoutes.js.map +1 -1
  40. package/dist/routes/solidRoutes.tsx +2 -0
  41. package/package.json +1 -2
@@ -0,0 +1,228 @@
1
+ import React, { useMemo, useState } from "react";
2
+ import { ExternalLink, FileText, Image as ImageIcon } from "lucide-react";
3
+ import PDFViewer from "../../../../common/PDFViewer";
4
+ import {
5
+ SolidDialog,
6
+ SolidDialogBody,
7
+ SolidDialogClose,
8
+ SolidDialogHeader,
9
+ SolidDialogTitle,
10
+ } from "../../../../../shad-cn-ui/SolidDialog";
11
+ import { SolidButton } from "../../../../../shad-cn-ui/SolidButton";
12
+ import { getMediaPreviewKind } from "../../../../../../helpers/mediaType";
13
+ import { openMediaInNewTab } from "../../../../../../helpers/mediaUrl";
14
+ import { SolidFormFieldWidgetProps, SolidMediaListFieldWidgetProps } from "../../../../../../types/solid-core";
15
+
16
+ type MediaPreviewDetails = {
17
+ url: string;
18
+ mimeType: string;
19
+ fileName: string;
20
+ previewKind: "image" | "video" | "audio" | "file";
21
+ isPdf: boolean;
22
+ };
23
+
24
+ const getFieldValue = (value: any): string => {
25
+ if (value === null || value === undefined) return "";
26
+ return typeof value === "string" ? value : String(value);
27
+ };
28
+
29
+ const getFileUrl = (rowData: any, value: string) => {
30
+ return rowData?._full_url || rowData?.fileUrl || value || "";
31
+ };
32
+
33
+ const isPdfMedia = ({ mimeType, fileName, url }: { mimeType?: string; fileName?: string; url?: string }) => {
34
+ const normalizedMimeType = String(mimeType || "").toLowerCase();
35
+ if (normalizedMimeType === "application/pdf") return true;
36
+
37
+ const cleanName = String(fileName || url || "").split("?")[0].toLowerCase();
38
+ return cleanName.endsWith(".pdf");
39
+ };
40
+
41
+ const buildPreviewDetails = ({
42
+ value,
43
+ rowData,
44
+ }: {
45
+ value: string;
46
+ rowData: any;
47
+ }): MediaPreviewDetails => {
48
+ const url = getFileUrl(rowData, value);
49
+ const mimeType = String(rowData?.mimeType || "").toLowerCase();
50
+ const fileName = getFieldValue(rowData?.originalFileName) || value.split("/").pop() || "media";
51
+ const previewKind = getMediaPreviewKind({ url, fileName, mimeType });
52
+
53
+ return {
54
+ url,
55
+ mimeType,
56
+ fileName,
57
+ previewKind,
58
+ isPdf: isPdfMedia({ mimeType, fileName, url }),
59
+ };
60
+ };
61
+
62
+ const MediaRelativeUriPreview = ({
63
+ value,
64
+ rowData,
65
+ showLabel,
66
+ label,
67
+ setLightboxUrls,
68
+ setOpenLightbox,
69
+ }: {
70
+ value: string;
71
+ rowData: any;
72
+ showLabel?: boolean;
73
+ label?: string;
74
+ setLightboxUrls?: any;
75
+ setOpenLightbox?: any;
76
+ }) => {
77
+ const [openPdfPreview, setOpenPdfPreview] = useState(false);
78
+ const details = useMemo(() => buildPreviewDetails({ value, rowData }), [value, rowData]);
79
+
80
+ const handlePreview = (event: React.MouseEvent) => {
81
+ event.stopPropagation();
82
+ if (!details.url) return;
83
+
84
+ if (details.previewKind === "image" || details.previewKind === "video") {
85
+ setLightboxUrls?.([
86
+ {
87
+ src: details.url,
88
+ downloadUrl: details.url,
89
+ type: details.previewKind === "video" ? "video" : undefined,
90
+ },
91
+ ]);
92
+ setOpenLightbox?.(true);
93
+ return;
94
+ }
95
+
96
+ if (details.isPdf) {
97
+ setOpenPdfPreview(true);
98
+ return;
99
+ }
100
+
101
+ openMediaInNewTab(details.url);
102
+ };
103
+
104
+ const handleOpenExternal = (event: React.MouseEvent) => {
105
+ event.stopPropagation();
106
+ if (!details.url) return;
107
+ openMediaInNewTab(details.url);
108
+ };
109
+
110
+ const Icon = details.isPdf ? FileText : details.previewKind === "image" ? ImageIcon : ExternalLink;
111
+ const buttonLabel = details.isPdf
112
+ ? "Preview PDF"
113
+ : details.previewKind === "image"
114
+ ? "Preview image"
115
+ : details.previewKind === "video"
116
+ ? "Preview video"
117
+ : "Open file";
118
+ const hasInlinePreview = details.isPdf || details.previewKind === "image" || details.previewKind === "video";
119
+
120
+ return (
121
+ <div className="solid-media-relative-uri-preview">
122
+ {showLabel !== false && label && (
123
+ <p className="form-field-label solid-media-relative-uri-preview__label">{label}</p>
124
+ )}
125
+ <div className="solid-media-relative-uri-preview__content">
126
+ {details.url ? (
127
+ <>
128
+ <SolidButton
129
+ type="button"
130
+ size="sm"
131
+ variant="outline"
132
+ className="solid-media-relative-uri-preview__button"
133
+ tooltip={details.fileName}
134
+ onClick={handlePreview}
135
+ >
136
+ <Icon size={14} aria-hidden />
137
+ <span>{buttonLabel}</span>
138
+ </SolidButton>
139
+ {hasInlinePreview && (
140
+ <SolidButton
141
+ type="button"
142
+ size="sm"
143
+ variant="ghost"
144
+ className="solid-media-relative-uri-preview__external solid-icon-button"
145
+ tooltip="Open in new tab"
146
+ aria-label="Open in new tab"
147
+ onClick={handleOpenExternal}
148
+ >
149
+ <ExternalLink size={14} aria-hidden />
150
+ </SolidButton>
151
+ )}
152
+ </>
153
+ ) : (
154
+ <SolidButton
155
+ type="button"
156
+ size="sm"
157
+ variant="outline"
158
+ className="solid-media-relative-uri-preview__button"
159
+ disabled
160
+ >
161
+ <span>No media</span>
162
+ </SolidButton>
163
+ )}
164
+ </div>
165
+
166
+ <SolidDialog
167
+ open={openPdfPreview}
168
+ onOpenChange={setOpenPdfPreview}
169
+ className="solid-confirm-dialog"
170
+ style={{ width: "80vw", maxHeight: "90vh" }}
171
+ >
172
+ <SolidDialogHeader className="p-1 form-wrapper-title">
173
+ <SolidDialogTitle>{details.fileName}</SolidDialogTitle>
174
+ <SolidDialogClose aria-label="Close preview" />
175
+ </SolidDialogHeader>
176
+ <SolidDialogBody className="p-0">
177
+ <div style={{ width: "100%", height: "75vh", overflow: "auto" }}>
178
+ <PDFViewer url={details.url} />
179
+ </div>
180
+ </SolidDialogBody>
181
+ </SolidDialog>
182
+ </div>
183
+ );
184
+ };
185
+
186
+ export const MediaRelativeUriListWidget = ({
187
+ rowData,
188
+ fieldMetadata,
189
+ column,
190
+ setLightboxUrls,
191
+ setOpenLightbox,
192
+ }: SolidMediaListFieldWidgetProps) => {
193
+ const fieldName = fieldMetadata.name;
194
+ const value = getFieldValue(rowData?.[fieldName]);
195
+
196
+ return (
197
+ <MediaRelativeUriPreview
198
+ value={value}
199
+ rowData={rowData}
200
+ showLabel={false}
201
+ label={column?.attrs?.label ?? fieldMetadata.displayName}
202
+ setLightboxUrls={setLightboxUrls}
203
+ setOpenLightbox={setOpenLightbox}
204
+ />
205
+ );
206
+ };
207
+
208
+ export const MediaRelativeUriFormViewWidget = ({ formik, fieldContext }: SolidFormFieldWidgetProps) => {
209
+ const fieldMetadata = fieldContext?.fieldMetadata;
210
+ const fieldLayoutInfo = fieldContext?.field;
211
+ const fieldName = fieldLayoutInfo?.attrs?.name;
212
+ const value = getFieldValue(formik.values[fieldName]);
213
+ const rowData = {
214
+ ...fieldContext?.data,
215
+ ...formik.values,
216
+ };
217
+
218
+ return (
219
+ <MediaRelativeUriPreview
220
+ value={value}
221
+ rowData={rowData}
222
+ showLabel={fieldLayoutInfo?.attrs?.showLabel}
223
+ label={fieldLayoutInfo?.attrs?.label ?? fieldMetadata?.displayName}
224
+ setLightboxUrls={fieldContext?.setLightboxUrls}
225
+ setOpenLightbox={fieldContext?.setOpenLightbox}
226
+ />
227
+ );
228
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"SolidFormView.d.ts","sourceRoot":"","sources":["../../../../src/components/core/form/SolidFormView.tsx"],"names":[],"mappings":"AA6DA,MAAM,MAAM,kBAAkB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,GAAG,CAAC;IACvB,mBAAmB,CAAC,EAAE,GAAG,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,gCAAgC,CAAC,EAAE,OAAO,CAAC;CAC9C,CAAC;AAgIF,eAAO,MAAM,uBAAuB,WAAY,GAAG,EAAE,KAAG,GAQvD,CAAA;AACD,eAAO,MAAM,sBAAsB,QAAS,MAAM,uBAAuB,OAAO,MAAM,EAAE,GAAG,CAAC,QAa3F,CAAC;AA+WF,QAAA,MAAM,aAAa,WAAY,kBAAkB,4CAu/ChD,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"SolidFormView.d.ts","sourceRoot":"","sources":["../../../../src/components/core/form/SolidFormView.tsx"],"names":[],"mappings":"AA6DA,MAAM,MAAM,kBAAkB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,GAAG,CAAC;IACvB,mBAAmB,CAAC,EAAE,GAAG,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;IAChC,gCAAgC,CAAC,EAAE,OAAO,CAAC;CAC9C,CAAC;AAgIF,eAAO,MAAM,uBAAuB,WAAY,GAAG,EAAE,KAAG,GAQvD,CAAA;AACD,eAAO,MAAM,sBAAsB,QAAS,MAAM,uBAAuB,OAAO,MAAM,EAAE,GAAG,CAAC,QAa3F,CAAC;AAiXF,QAAA,MAAM,aAAa,WAAY,kBAAkB,4CAu/ChD,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -310,7 +310,9 @@ var SolidField = function (_a) {
310
310
  readOnly: readOnly,
311
311
  viewMode: viewMode,
312
312
  onChange: onChange,
313
- onBlur: onBlur
313
+ onBlur: onBlur,
314
+ setLightboxUrls: setLightboxUrls,
315
+ setOpenLightbox: setOpenLightbox
314
316
  };
315
317
  if (parentData) {
316
318
  fieldContext.parentData = parentData;