@multiplatform.one/frappe-ui 7.90.6 → 8.1.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/dist/cjs/FrappeListView.cjs +0 -2
- package/dist/cjs/FrappeListView.native.js +0 -2
- package/dist/cjs/FrappeListView.native.js.map +1 -1
- package/dist/cjs/desk/index.cjs +41 -0
- package/dist/cjs/desk/index.native.js +44 -0
- package/dist/cjs/desk/index.native.js.map +1 -0
- package/dist/cjs/fields/Link.cjs +0 -4
- package/dist/cjs/fields/Link.native.js +0 -4
- package/dist/cjs/fields/Link.native.js.map +1 -1
- package/dist/cjs/index.cjs +0 -2
- package/dist/cjs/index.gnome.cjs +203 -0
- package/dist/cjs/index.gnome.native.js +206 -0
- package/dist/cjs/index.gnome.native.js.map +1 -0
- package/dist/cjs/index.native.js +0 -2
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/FrappeListView.mjs +0 -2
- package/dist/esm/FrappeListView.mjs.map +1 -1
- package/dist/esm/FrappeListView.native.js +0 -2
- package/dist/esm/FrappeListView.native.js.map +1 -1
- package/dist/esm/desk/index.mjs +8 -0
- package/dist/esm/desk/index.mjs.map +1 -0
- package/dist/esm/desk/index.native.js +8 -0
- package/dist/esm/desk/index.native.js.map +1 -0
- package/dist/esm/fields/Link.mjs +0 -4
- package/dist/esm/fields/Link.mjs.map +1 -1
- package/dist/esm/fields/Link.native.js +0 -4
- package/dist/esm/fields/Link.native.js.map +1 -1
- package/dist/esm/index.gnome.mjs +59 -0
- package/dist/esm/index.gnome.mjs.map +1 -0
- package/dist/esm/index.gnome.native.js +59 -0
- package/dist/esm/index.gnome.native.js.map +1 -0
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +1 -2
- package/dist/esm/index.native.js.map +1 -1
- package/dist/jsx/ChartCard.native.js.map +1 -1
- package/dist/jsx/FileBrowser/AttachLibrary.native.js.map +1 -1
- package/dist/jsx/FileBrowser/folderTree.native.js.map +1 -1
- package/dist/jsx/FileBrowser/index.native.js.map +1 -1
- package/dist/jsx/FileBrowser/types.native.js.map +1 -1
- package/dist/jsx/FileBrowser/viewPersistence.native.js.map +1 -1
- package/dist/jsx/FormSidebar.native.js.map +1 -1
- package/dist/jsx/FrappeAssignment.native.js.map +1 -1
- package/dist/jsx/FrappeCalendar.native.js.map +1 -1
- package/dist/jsx/FrappeChartCard.native.js.map +1 -1
- package/dist/jsx/FrappeConnectionIndicator.native.js.map +1 -1
- package/dist/jsx/FrappeDashboard.native.js.map +1 -1
- package/dist/jsx/FrappeForm.native.js +1 -1
- package/dist/jsx/FrappeForm.native.js.map +1 -1
- package/dist/jsx/FrappeFormActions.native.js.map +1 -1
- package/dist/jsx/FrappeFormConnections.native.js.map +1 -1
- package/dist/jsx/FrappeGantt.native.js.map +1 -1
- package/dist/jsx/FrappeImageView.native.js.map +1 -1
- package/dist/jsx/FrappeInsights.native.js.map +1 -1
- package/dist/jsx/FrappeKPICard.native.js.map +1 -1
- package/dist/jsx/FrappeKanban.native.js.map +1 -1
- package/dist/jsx/FrappeLikedBy.native.js.map +1 -1
- package/dist/jsx/FrappeList.native.js.map +1 -1
- package/dist/jsx/FrappeListView.mjs +0 -2
- package/dist/jsx/FrappeListView.mjs.map +1 -1
- package/dist/jsx/FrappeListView.native.js +0 -2
- package/dist/jsx/FrappeListView.native.js.map +1 -1
- package/dist/jsx/FrappeNotConfigured.native.js.map +1 -1
- package/dist/jsx/FrappeProvider.native.js.map +1 -1
- package/dist/jsx/FrappeReconnectIndicator.native.js.map +1 -1
- package/dist/jsx/FrappeRecordView.native.js.map +1 -1
- package/dist/jsx/FrappeReportBuilder.native.js.map +1 -1
- package/dist/jsx/FrappeReportView.native.js +3 -3
- package/dist/jsx/FrappeReportView.native.js.map +1 -1
- package/dist/jsx/FrappeRowsReader.native.js.map +1 -1
- package/dist/jsx/FrappeTable.native.js.map +1 -1
- package/dist/jsx/FrappeTreeView.native.js.map +1 -1
- package/dist/jsx/SyncErrorNotice.native.js.map +1 -1
- package/dist/jsx/commentActions.native.js.map +1 -1
- package/dist/jsx/components/attachments.native.js.map +1 -1
- package/dist/jsx/components/tags.native.js.map +1 -1
- package/dist/jsx/components/timeline.native.js.map +1 -1
- package/dist/jsx/dependsOn.native.js.map +1 -1
- package/dist/jsx/desk/DeskFormPage.native.js.map +1 -1
- package/dist/jsx/desk/DeskFormSidebar.native.js.map +1 -1
- package/dist/jsx/desk/DeskListPage.native.js.map +1 -1
- package/dist/jsx/desk/DeskShell.native.js.map +1 -1
- package/dist/jsx/desk/DeskSidebar.native.js.map +1 -1
- package/dist/jsx/desk/awesomebar.native.js.map +1 -1
- package/dist/jsx/desk/index.mjs +8 -0
- package/dist/jsx/desk/index.mjs.map +1 -0
- package/dist/jsx/desk/index.native.js +44 -0
- package/dist/jsx/desk/index.native.js.map +1 -0
- package/dist/jsx/fieldOverrides.native.js.map +1 -1
- package/dist/jsx/fieldRegistry.native.js +31 -31
- package/dist/jsx/fieldRegistry.native.js.map +1 -1
- package/dist/jsx/fields/Barcode/index.native.js.map +1 -1
- package/dist/jsx/fields/Check/index.native.js.map +1 -1
- package/dist/jsx/fields/CodeEditor/index.native.js.map +1 -1
- package/dist/jsx/fields/Color/index.native.js.map +1 -1
- package/dist/jsx/fields/Data/index.native.js.map +1 -1
- package/dist/jsx/fields/Date/catalog.native.js +1 -1
- package/dist/jsx/fields/Date/catalog.native.js.map +1 -1
- package/dist/jsx/fields/Date/index.native.js.map +1 -1
- package/dist/jsx/fields/Date/types.native.js.map +1 -1
- package/dist/jsx/fields/Date/wire.native.js.map +1 -1
- package/dist/jsx/fields/DateRange/index.native.js.map +1 -1
- package/dist/jsx/fields/Duration/index.native.js.map +1 -1
- package/dist/jsx/fields/DynamicLink.native.js.map +1 -1
- package/dist/jsx/fields/FileUploadField/index.native.js.map +1 -1
- package/dist/jsx/fields/Geolocation/index.native.js.map +1 -1
- package/dist/jsx/fields/HTML/index.native.js.map +1 -1
- package/dist/jsx/fields/Heading/index.native.js.map +1 -1
- package/dist/jsx/fields/Icon/index.native.js.map +1 -1
- package/dist/jsx/fields/Link.mjs +0 -4
- package/dist/jsx/fields/Link.mjs.map +1 -1
- package/dist/jsx/fields/Link.native.js +0 -4
- package/dist/jsx/fields/Link.native.js.map +1 -1
- package/dist/jsx/fields/LinkTree.native.js.map +1 -1
- package/dist/jsx/fields/LongText/index.native.js.map +1 -1
- package/dist/jsx/fields/MentionInput/index.native.js.map +1 -1
- package/dist/jsx/fields/Numeric/index.native.js.map +1 -1
- package/dist/jsx/fields/OTPInput/index.native.js.map +1 -1
- package/dist/jsx/fields/Password/index.native.js.map +1 -1
- package/dist/jsx/fields/Phone/index.native.js.map +1 -1
- package/dist/jsx/fields/Progress/index.native.js.map +1 -1
- package/dist/jsx/fields/RadioGroup/index.native.js.map +1 -1
- package/dist/jsx/fields/Rating/index.native.js.map +1 -1
- package/dist/jsx/fields/ReadOnly/index.native.js.map +1 -1
- package/dist/jsx/fields/Select/index.native.js.map +1 -1
- package/dist/jsx/fields/Signature/index.native.js.map +1 -1
- package/dist/jsx/fields/Slider/index.native.js.map +1 -1
- package/dist/jsx/fields/SmallText/index.native.js.map +1 -1
- package/dist/jsx/fields/Switch/index.native.js.map +1 -1
- package/dist/jsx/fields/TableMultiSelect.native.js.map +1 -1
- package/dist/jsx/fields/TextEditor/types.native.js.map +1 -1
- package/dist/jsx/fields/TimePicker/index.native.js.map +1 -1
- package/dist/jsx/fields/ToggleGroup/index.native.js.map +1 -1
- package/dist/jsx/fields/shared/EditorPreviewPanes.native.js.map +1 -1
- package/dist/jsx/filterFields.native.js.map +1 -1
- package/dist/jsx/formEngine/createPrefill.native.js.map +1 -1
- package/dist/jsx/formEngine/dirtyTracking.native.js.map +1 -1
- package/dist/jsx/formEngine/docLifecycle.native.js.map +1 -1
- package/dist/jsx/formEngine/docPermissions.native.js.map +1 -1
- package/dist/jsx/formEngine/doctypeMeta.native.js.map +1 -1
- package/dist/jsx/formEngine/fetchFrom.native.js.map +1 -1
- package/dist/jsx/formEngine/fieldPermissions.native.js.map +1 -1
- package/dist/jsx/formEngine/formActions.native.js.map +1 -1
- package/dist/jsx/formEngine/formLayout.native.js.map +1 -1
- package/dist/jsx/formEngine/index.native.js.map +1 -1
- package/dist/jsx/formEngine/useAmendedAs.native.js.map +1 -1
- package/dist/jsx/formEngine/useDocRights.native.js.map +1 -1
- package/dist/jsx/formEngine/useFormEngine.native.js.map +1 -1
- package/dist/jsx/formEngine/useSessionRoles.native.js.map +1 -1
- package/dist/jsx/frappeConnections.native.js.map +1 -1
- package/dist/jsx/frappeEventColor.native.js.map +1 -1
- package/dist/jsx/frappeNavigation.native.js.map +1 -1
- package/dist/jsx/frappeStoryTarget.native.js.map +1 -1
- package/dist/jsx/frappeUsers.native.js.map +1 -1
- package/dist/jsx/index.gnome.mjs +59 -0
- package/dist/jsx/index.gnome.mjs.map +1 -0
- package/dist/jsx/index.gnome.native.js +206 -0
- package/dist/jsx/index.gnome.native.js.map +1 -0
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/index.native.js +34 -36
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/insights/InsightsFacetTags.native.js.map +1 -1
- package/dist/jsx/insights/InsightsKpiBand.native.js.map +1 -1
- package/dist/jsx/insights/InsightsLeaders.native.js.map +1 -1
- package/dist/jsx/insights/InsightsRecords.native.js.map +1 -1
- package/dist/jsx/insights/InsightsTable.native.js.map +1 -1
- package/dist/jsx/insights/insightsData.native.js.map +1 -1
- package/dist/jsx/insights/insightsRecord.native.js.map +1 -1
- package/dist/jsx/list/BandFilters.native.js.map +1 -1
- package/dist/jsx/list/FacetBadge.native.js.map +1 -1
- package/dist/jsx/list/FacetList.native.js.map +1 -1
- package/dist/jsx/list/FacetRail.native.js.map +1 -1
- package/dist/jsx/list/ImageWell.native.js.map +1 -1
- package/dist/jsx/list/ListControls.native.js.map +1 -1
- package/dist/jsx/list/ListControlsSheet.native.js.map +1 -1
- package/dist/jsx/list/ListFilterPanel.native.js.map +1 -1
- package/dist/jsx/list/ListFiltersButton.native.js.map +1 -1
- package/dist/jsx/list/ListSidebarToolbar.native.js.map +1 -1
- package/dist/jsx/list/ListToastHost.native.js.map +1 -1
- package/dist/jsx/list/ListToolsSheet.native.js.map +1 -1
- package/dist/jsx/list/RangeFilter.native.js.map +1 -1
- package/dist/jsx/list/ShufflePanel.native.js.map +1 -1
- package/dist/jsx/list/defaultProjection.native.js.map +1 -1
- package/dist/jsx/list/facetBadgeSteps.native.js.map +1 -1
- package/dist/jsx/list/facetReading.native.js.map +1 -1
- package/dist/jsx/list/favorites.native.js.map +1 -1
- package/dist/jsx/list/listColumns.native.js.map +1 -1
- package/dist/jsx/list/listControls.fixture.native.js.map +1 -1
- package/dist/jsx/list/listFields.native.js.map +1 -1
- package/dist/jsx/list/listFormat.native.js.map +1 -1
- package/dist/jsx/list/listState.native.js.map +1 -1
- package/dist/jsx/list/recordLook.native.js.map +1 -1
- package/dist/jsx/list/statusColors.native.js.map +1 -1
- package/dist/jsx/list/useListControls.native.js.map +1 -1
- package/dist/jsx/liveErrors.native.js.map +1 -1
- package/dist/jsx/measures.native.js.map +1 -1
- package/dist/jsx/record/RecordBars.native.js.map +1 -1
- package/dist/jsx/record/RecordGallery.native.js.map +1 -1
- package/dist/jsx/record/RecordHero.native.js.map +1 -1
- package/dist/jsx/record/RecordPage.native.js.map +1 -1
- package/dist/jsx/record/RecordPager.native.js.map +1 -1
- package/dist/jsx/record/RecordRows.native.js.map +1 -1
- package/dist/jsx/record/recordData.native.js.map +1 -1
- package/dist/jsx/record/recordSections.native.js.map +1 -1
- package/dist/jsx/recordShape.native.js.map +1 -1
- package/dist/jsx/report/ReportGrid.native.js.map +1 -1
- package/dist/jsx/report/ReportViewToolbar.native.js.map +1 -1
- package/dist/jsx/report/exportCsv.native.js.map +1 -1
- package/dist/jsx/report/queryReport.native.js.map +1 -1
- package/dist/jsx/report/queryReportColumns.native.js.map +1 -1
- package/dist/jsx/report/reportViewModel.native.js.map +1 -1
- package/dist/jsx/report/savedReports.native.js.map +1 -1
- package/dist/jsx/report/useFrappeReport.native.js.map +1 -1
- package/dist/jsx/report/useQueryReport.native.js.map +1 -1
- package/dist/jsx/resolveControl.native.js.map +1 -1
- package/dist/jsx/schemaForm/SchemaWizard.native.js.map +1 -1
- package/dist/jsx/schemaForm/applyFieldOrder.native.js.map +1 -1
- package/dist/jsx/schemaForm/index.native.js +1 -1
- package/dist/jsx/schemaForm/index.native.js.map +1 -1
- package/dist/jsx/sessionUser.native.js.map +1 -1
- package/dist/jsx/shared/devWarn.native.js.map +1 -1
- package/dist/jsx/shared/useKeyboardInset.native.js.map +1 -1
- package/dist/jsx/syncError.native.js.map +1 -1
- package/dist/jsx/useConnectionFilters.native.js.map +1 -1
- package/dist/jsx/useFrappeAggregate.native.js.map +1 -1
- package/dist/jsx/useFrappeFacets.native.js.map +1 -1
- package/dist/jsx/useFrappeForm.native.js.map +1 -1
- package/dist/jsx/useFrappePagination.native.js.map +1 -1
- package/dist/jsx/useFrappeRows.native.js.map +1 -1
- package/package.json +35 -15
- package/src/FrappeListView.tsx +0 -4
- package/src/desk/index.ts +18 -0
- package/src/fields/Link.tsx +0 -12
- package/src/formEngine/index.ts +2 -2
- package/src/index.gnome.ts +191 -0
- package/src/index.ts +2 -7
- package/types/FrappeListView.d.ts +0 -2
- package/types/FrappeListView.d.ts.map +1 -1
- package/types/desk/index.d.ts +12 -0
- package/types/desk/index.d.ts.map +1 -0
- package/types/fields/Link.d.ts +0 -8
- package/types/fields/Link.d.ts.map +1 -1
- package/types/formEngine/index.d.ts +2 -2
- package/types/index.d.ts +0 -1
- package/types/index.d.ts.map +1 -1
- package/types/index.gnome.d.ts +105 -0
- package/types/index.gnome.d.ts.map +1 -0
- package/dist/cjs/fields/FileUpload.cjs +0 -404
- package/dist/cjs/fields/FileUpload.native.js +0 -431
- package/dist/cjs/fields/FileUpload.native.js.map +0 -1
- package/dist/esm/fields/FileUpload.mjs +0 -379
- package/dist/esm/fields/FileUpload.mjs.map +0 -1
- package/dist/esm/fields/FileUpload.native.js +0 -403
- package/dist/esm/fields/FileUpload.native.js.map +0 -1
- package/dist/jsx/fields/FileUpload.mjs +0 -379
- package/dist/jsx/fields/FileUpload.mjs.map +0 -1
- package/dist/jsx/fields/FileUpload.native.js +0 -431
- package/dist/jsx/fields/FileUpload.native.js.map +0 -1
- package/src/fields/FileUpload.spec.tsx +0 -351
- package/src/fields/FileUpload.tsx +0 -472
- package/src/fields/FrappeFileUpload.stories.tsx +0 -139
- package/types/fields/FileUpload.d.ts +0 -27
- package/types/fields/FileUpload.d.ts.map +0 -1
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all) __defProp(target, name, {
|
|
7
|
-
get: all[name],
|
|
8
|
-
enumerable: true
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
-
get: () => from[key],
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
23
|
-
var FileUpload_exports = {};
|
|
24
|
-
__export(FileUpload_exports, {
|
|
25
|
-
FileUpload: () => FileUpload
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(FileUpload_exports);
|
|
28
|
-
var import_frappe = require("@multiplatform.one/frappe");
|
|
29
|
-
var import_forms = require("@multiplatform.one/forms");
|
|
30
|
-
var import_react = require("@phosphor-icons/react");
|
|
31
|
-
var import_theme = require("@multiplatform.one/theme");
|
|
32
|
-
var import_react2 = require("react");
|
|
33
|
-
var import_react_i18next = require("react-i18next");
|
|
34
|
-
var import_tamagui = require("tamagui");
|
|
35
|
-
var import_FrappeProvider = require("../FrappeProvider.cjs");
|
|
36
|
-
var import_components = require("@multiplatform.one/components");
|
|
37
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
38
|
-
function formatFileSize(bytes) {
|
|
39
|
-
if (bytes === 0) return "0 Bytes";
|
|
40
|
-
const k = 1024;
|
|
41
|
-
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
42
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
43
|
-
return `${Number.parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`;
|
|
44
|
-
}
|
|
45
|
-
function readFileAsDataUrl(file, {
|
|
46
|
-
onProgress,
|
|
47
|
-
signal
|
|
48
|
-
}) {
|
|
49
|
-
return new Promise((resolve, reject) => {
|
|
50
|
-
const reader = new FileReader();
|
|
51
|
-
const onAbort = () => {
|
|
52
|
-
reader.abort();
|
|
53
|
-
reject(new DOMException("Aborted", "AbortError"));
|
|
54
|
-
};
|
|
55
|
-
if (signal.aborted) {
|
|
56
|
-
onAbort();
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
signal.addEventListener("abort", onAbort);
|
|
60
|
-
reader.onprogress = event => {
|
|
61
|
-
if (event.lengthComputable && event.total > 0) {
|
|
62
|
-
onProgress(Math.round(event.loaded / event.total * 100));
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
reader.onload = () => {
|
|
66
|
-
signal.removeEventListener("abort", onAbort);
|
|
67
|
-
onProgress(100);
|
|
68
|
-
resolve(reader.result);
|
|
69
|
-
};
|
|
70
|
-
reader.onerror = () => {
|
|
71
|
-
signal.removeEventListener("abort", onAbort);
|
|
72
|
-
reject(new Error("Failed to read file"));
|
|
73
|
-
};
|
|
74
|
-
reader.onabort = () => {
|
|
75
|
-
signal.removeEventListener("abort", onAbort);
|
|
76
|
-
reject(new DOMException("Aborted", "AbortError"));
|
|
77
|
-
};
|
|
78
|
-
reader.readAsDataURL(file);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function FileUpload({
|
|
82
|
-
label,
|
|
83
|
-
value,
|
|
84
|
-
onChange,
|
|
85
|
-
accept,
|
|
86
|
-
isImage = false,
|
|
87
|
-
disabled = false,
|
|
88
|
-
required = false,
|
|
89
|
-
maxSize = 5 * 1024 * 1024,
|
|
90
|
-
baseURL,
|
|
91
|
-
auth,
|
|
92
|
-
helperText,
|
|
93
|
-
readOnly = false,
|
|
94
|
-
skeleton = false,
|
|
95
|
-
onUpload
|
|
96
|
-
}) {
|
|
97
|
-
const {
|
|
98
|
-
t
|
|
99
|
-
} = (0, import_react_i18next.useTranslation)();
|
|
100
|
-
const {
|
|
101
|
-
knobProps
|
|
102
|
-
} = (0, import_theme.useResolvedKnobs)();
|
|
103
|
-
const small = (0, import_theme.sizeTokenStep)(knobProps.sizeToken) < 0;
|
|
104
|
-
const config = (0, import_FrappeProvider.useFrappeConfig)();
|
|
105
|
-
const fileInputRef = (0, import_react2.useRef)(null);
|
|
106
|
-
const [transfer, setTransfer] = (0, import_react2.useState)(null);
|
|
107
|
-
const [error, setError] = (0, import_react2.useState)(null);
|
|
108
|
-
const transferRef = (0, import_react2.useRef)(null);
|
|
109
|
-
const onUploadRef = (0, import_react2.useRef)(onUpload);
|
|
110
|
-
onUploadRef.current = onUpload;
|
|
111
|
-
const isLocked = disabled || readOnly;
|
|
112
|
-
const minHeight = small ? 40 : 56;
|
|
113
|
-
const previewSize = small ? 120 : 200;
|
|
114
|
-
const uploading = transfer?.status === "uploading";
|
|
115
|
-
const finalBaseURL = baseURL ?? config?.baseURL ?? "";
|
|
116
|
-
const finalConfig = finalBaseURL ? {
|
|
117
|
-
baseURL: finalBaseURL,
|
|
118
|
-
socketPort: config?.socketPort,
|
|
119
|
-
siteName: config?.siteName,
|
|
120
|
-
socketBaseURL: config?.socketBaseURL,
|
|
121
|
-
auth: auth ?? config?.auth,
|
|
122
|
-
syncOptions: config?.syncOptions,
|
|
123
|
-
realtime: config?.realtime,
|
|
124
|
-
fixtures: config?.fixtures
|
|
125
|
-
} : void 0;
|
|
126
|
-
const fileCollection = (0, import_frappe.useFrappeCollection)(finalConfig, "File", {
|
|
127
|
-
fields: ["name", "file_name", "file_url", "is_private"]
|
|
128
|
-
});
|
|
129
|
-
(0, import_react2.useEffect)(() => {
|
|
130
|
-
return () => {
|
|
131
|
-
transferRef.current?.controller.abort();
|
|
132
|
-
};
|
|
133
|
-
}, []);
|
|
134
|
-
const defaultUpload = (0, import_react2.useCallback)(async (file, ctx) => {
|
|
135
|
-
const base64 = await readFileAsDataUrl(file, ctx);
|
|
136
|
-
if (fileCollection) {
|
|
137
|
-
const tx = fileCollection.insert({
|
|
138
|
-
doctype: "File",
|
|
139
|
-
name: `new-${Date.now()}`,
|
|
140
|
-
file_name: file.name,
|
|
141
|
-
file_url: base64,
|
|
142
|
-
is_private: 0
|
|
143
|
-
});
|
|
144
|
-
await tx.isPersisted.promise;
|
|
145
|
-
}
|
|
146
|
-
return base64;
|
|
147
|
-
}, [fileCollection]);
|
|
148
|
-
const runTransfer = (0, import_react2.useCallback)(async (file, controller) => {
|
|
149
|
-
const upload = onUploadRef.current ?? defaultUpload;
|
|
150
|
-
try {
|
|
151
|
-
const url = await upload(file, {
|
|
152
|
-
onProgress: percent => {
|
|
153
|
-
const n = Math.min(100, Math.max(0, Math.round(Number(percent) || 0)));
|
|
154
|
-
setTransfer(prev => prev ? {
|
|
155
|
-
...prev,
|
|
156
|
-
progress: n
|
|
157
|
-
} : prev);
|
|
158
|
-
},
|
|
159
|
-
signal: controller.signal
|
|
160
|
-
});
|
|
161
|
-
if (controller.signal.aborted) return;
|
|
162
|
-
setTransfer(null);
|
|
163
|
-
transferRef.current = null;
|
|
164
|
-
setError(null);
|
|
165
|
-
onChange(url);
|
|
166
|
-
} catch (err) {
|
|
167
|
-
if (controller.signal.aborted || err instanceof Error && err.name === "AbortError" || typeof DOMException !== "undefined" && err instanceof DOMException && err.name === "AbortError") {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const problem = err instanceof Error && err.message ? err.message : t("Upload failed");
|
|
171
|
-
setTransfer(prev => prev ? {
|
|
172
|
-
...prev,
|
|
173
|
-
status: "failed",
|
|
174
|
-
problem,
|
|
175
|
-
action: t("Try again or remove the file")
|
|
176
|
-
} : prev);
|
|
177
|
-
setError(null);
|
|
178
|
-
}
|
|
179
|
-
}, [defaultUpload, onChange, t]);
|
|
180
|
-
const startTransfer = (0, import_react2.useCallback)(file => {
|
|
181
|
-
transferRef.current?.controller.abort();
|
|
182
|
-
const controller = new AbortController();
|
|
183
|
-
const next = {
|
|
184
|
-
file,
|
|
185
|
-
status: "uploading",
|
|
186
|
-
progress: 0,
|
|
187
|
-
controller
|
|
188
|
-
};
|
|
189
|
-
transferRef.current = next;
|
|
190
|
-
setTransfer(next);
|
|
191
|
-
setError(null);
|
|
192
|
-
void runTransfer(file, controller);
|
|
193
|
-
}, [runTransfer]);
|
|
194
|
-
const handleFileSelect = event => {
|
|
195
|
-
if (isLocked) return;
|
|
196
|
-
const file = event.target.files?.[0];
|
|
197
|
-
if (!file) return;
|
|
198
|
-
if (maxSize && file.size > maxSize) {
|
|
199
|
-
setError(`File size exceeds ${Math.round(maxSize / 1024 / 1024)}MB limit`);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
startTransfer(file);
|
|
203
|
-
};
|
|
204
|
-
const handleCancel = () => {
|
|
205
|
-
transferRef.current?.controller.abort();
|
|
206
|
-
transferRef.current = null;
|
|
207
|
-
setTransfer(null);
|
|
208
|
-
if (fileInputRef.current) fileInputRef.current.value = "";
|
|
209
|
-
};
|
|
210
|
-
const handleRetry = () => {
|
|
211
|
-
if (!transfer) return;
|
|
212
|
-
startTransfer(transfer.file);
|
|
213
|
-
};
|
|
214
|
-
const handleRemove = () => {
|
|
215
|
-
if (isLocked) return;
|
|
216
|
-
handleCancel();
|
|
217
|
-
onChange("");
|
|
218
|
-
if (fileInputRef.current) {
|
|
219
|
-
fileInputRef.current.value = "";
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
const handleRemoveFailed = () => {
|
|
223
|
-
handleCancel();
|
|
224
|
-
};
|
|
225
|
-
const handleClick = () => {
|
|
226
|
-
if (isLocked || uploading) return;
|
|
227
|
-
fileInputRef.current?.click();
|
|
228
|
-
};
|
|
229
|
-
if (skeleton) {
|
|
230
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
|
|
231
|
-
...knobProps.gap,
|
|
232
|
-
children: [label && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Skeleton, {
|
|
233
|
-
variant: "text",
|
|
234
|
-
width: "30%",
|
|
235
|
-
height: (0, import_theme.sizeRecipeForToken)(knobProps.sizeToken).fontSize
|
|
236
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.Skeleton, {
|
|
237
|
-
variant: "rounded",
|
|
238
|
-
width: "100%",
|
|
239
|
-
height: minHeight
|
|
240
|
-
})]
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
const fileActions = !readOnly && !transfer ? overMedia => /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
244
|
-
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.ActionButton, {
|
|
245
|
-
kind: "replace",
|
|
246
|
-
overMedia,
|
|
247
|
-
disabled: isLocked,
|
|
248
|
-
onPress: handleClick
|
|
249
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.ActionButton, {
|
|
250
|
-
kind: "remove",
|
|
251
|
-
overMedia,
|
|
252
|
-
disabled: isLocked,
|
|
253
|
-
onPress: handleRemove
|
|
254
|
-
})]
|
|
255
|
-
}) : void 0;
|
|
256
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
|
|
257
|
-
...knobProps.gap,
|
|
258
|
-
children: [label && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.Label, {
|
|
259
|
-
...knobProps.label,
|
|
260
|
-
children: [label, required && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
|
|
261
|
-
color: "$red10",
|
|
262
|
-
children: " *"
|
|
263
|
-
})]
|
|
264
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)("input", {
|
|
265
|
-
ref: fileInputRef,
|
|
266
|
-
type: "file",
|
|
267
|
-
accept: accept || (isImage ? "image/*" : void 0),
|
|
268
|
-
style: {
|
|
269
|
-
display: "none"
|
|
270
|
-
},
|
|
271
|
-
onChange: handleFileSelect,
|
|
272
|
-
disabled: isLocked || uploading
|
|
273
|
-
}), transfer ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
|
|
274
|
-
"data-file-upload": "transfer",
|
|
275
|
-
"data-transfer-status": transfer.status,
|
|
276
|
-
...knobProps.gap,
|
|
277
|
-
...knobProps.panelPadding,
|
|
278
|
-
children: [/* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
|
|
279
|
-
gap: "$2",
|
|
280
|
-
alignItems: "center",
|
|
281
|
-
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.FileIcon, {
|
|
282
|
-
size: 20
|
|
283
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
|
|
284
|
-
flex: 1,
|
|
285
|
-
gap: "$1",
|
|
286
|
-
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.Text, {
|
|
287
|
-
numberOfLines: 1,
|
|
288
|
-
children: transfer.file.name
|
|
289
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.Text, {
|
|
290
|
-
numberOfLines: 1,
|
|
291
|
-
fontWeight: "700",
|
|
292
|
-
fontSize: "$2",
|
|
293
|
-
children: formatFileSize(transfer.file.size)
|
|
294
|
-
})]
|
|
295
|
-
}), transfer.status === "uploading" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.ActionButton, {
|
|
296
|
-
kind: "cancel",
|
|
297
|
-
label: t("Cancel {{name}}", {
|
|
298
|
-
name: transfer.file.name
|
|
299
|
-
}),
|
|
300
|
-
disabled: isLocked,
|
|
301
|
-
onPress: handleCancel
|
|
302
|
-
}) : null]
|
|
303
|
-
}), transfer.status === "uploading" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
|
|
304
|
-
"data-file-upload": "progress",
|
|
305
|
-
role: "progressbar",
|
|
306
|
-
"aria-valuemin": 0,
|
|
307
|
-
"aria-valuemax": 100,
|
|
308
|
-
"aria-valuenow": transfer.progress,
|
|
309
|
-
"aria-label": t("Uploading {{name}}", {
|
|
310
|
-
name: transfer.file.name
|
|
311
|
-
}),
|
|
312
|
-
height: 11,
|
|
313
|
-
width: "100%",
|
|
314
|
-
borderRadius: 1e3,
|
|
315
|
-
backgroundColor: "$color4",
|
|
316
|
-
overflow: "hidden",
|
|
317
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
|
|
318
|
-
height: "100%",
|
|
319
|
-
width: `${transfer.progress}%`,
|
|
320
|
-
backgroundColor: import_components.componentColors.indicator.mark
|
|
321
|
-
})
|
|
322
|
-
}) : null, transfer.status === "failed" ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
|
|
323
|
-
...knobProps.gap,
|
|
324
|
-
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.Text, {
|
|
325
|
-
color: "$red11",
|
|
326
|
-
fontSize: "$2",
|
|
327
|
-
children: transfer.problem
|
|
328
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.Text, {
|
|
329
|
-
color: "$color11",
|
|
330
|
-
fontSize: "$2",
|
|
331
|
-
children: transfer.action
|
|
332
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
|
|
333
|
-
...knobProps.gap,
|
|
334
|
-
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.ActionButton, {
|
|
335
|
-
kind: "retry",
|
|
336
|
-
label: t("Retry {{name}}", {
|
|
337
|
-
name: transfer.file.name
|
|
338
|
-
}),
|
|
339
|
-
disabled: isLocked,
|
|
340
|
-
onPress: handleRetry
|
|
341
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.ActionButton, {
|
|
342
|
-
kind: "remove",
|
|
343
|
-
label: t("Remove {{name}}", {
|
|
344
|
-
name: transfer.file.name
|
|
345
|
-
}),
|
|
346
|
-
disabled: isLocked,
|
|
347
|
-
onPress: handleRemoveFailed
|
|
348
|
-
})]
|
|
349
|
-
})]
|
|
350
|
-
}) : null]
|
|
351
|
-
}) : null, !value && !transfer ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Button, {
|
|
352
|
-
size: "$3",
|
|
353
|
-
icon: import_react.UploadIcon,
|
|
354
|
-
disabled: isLocked,
|
|
355
|
-
onPress: handleClick,
|
|
356
|
-
...knobProps.borderRadius,
|
|
357
|
-
children: t("Choose File")
|
|
358
|
-
}) : null, value ? isImage ? /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
|
|
359
|
-
position: "relative",
|
|
360
|
-
alignSelf: "flex-start",
|
|
361
|
-
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Image, {
|
|
362
|
-
src: value,
|
|
363
|
-
alt: t("Uploaded file preview"),
|
|
364
|
-
width: previewSize,
|
|
365
|
-
height: previewSize,
|
|
366
|
-
...knobProps.borderRadius,
|
|
367
|
-
objectFit: "cover"
|
|
368
|
-
}), fileActions ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
|
|
369
|
-
"data-file-upload": "preview-actions",
|
|
370
|
-
position: "absolute",
|
|
371
|
-
top: "$2",
|
|
372
|
-
right: "$2",
|
|
373
|
-
zIndex: 1,
|
|
374
|
-
...knobProps.gap,
|
|
375
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_forms.IconButtonGroup, {
|
|
376
|
-
plate: "media",
|
|
377
|
-
children: fileActions(true)
|
|
378
|
-
})
|
|
379
|
-
}) : null]
|
|
380
|
-
}) : /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
|
|
381
|
-
gap: "$2",
|
|
382
|
-
alignItems: "center",
|
|
383
|
-
...knobProps.panelPadding,
|
|
384
|
-
...{
|
|
385
|
-
backgroundColor: "$color2"
|
|
386
|
-
},
|
|
387
|
-
children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_react.FileIcon, {
|
|
388
|
-
size: 20
|
|
389
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.Text, {
|
|
390
|
-
flex: 1,
|
|
391
|
-
numberOfLines: 1,
|
|
392
|
-
children: value.split("/").pop() || value
|
|
393
|
-
}), fileActions?.(false)]
|
|
394
|
-
}) : null, helperText && !error && !transfer ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.Text, {
|
|
395
|
-
color: "$color11",
|
|
396
|
-
fontSize: "$2",
|
|
397
|
-
children: helperText
|
|
398
|
-
}) : null, error ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_components.Text, {
|
|
399
|
-
color: "$red11",
|
|
400
|
-
fontSize: "$2",
|
|
401
|
-
children: error
|
|
402
|
-
}) : null]
|
|
403
|
-
});
|
|
404
|
-
}
|