@uxf/core 11.60.1 → 11.67.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.
@@ -0,0 +1,7 @@
1
+ interface AutocompleteItem {
2
+ id: string | number;
3
+ label: string;
4
+ }
5
+ export type Autocomplete = (entityName: string, term: string) => Promise<AutocompleteItem[]>;
6
+ export declare const autocomplete: Autocomplete;
7
+ export {};
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.autocomplete = void 0;
4
+ const autocomplete = (name, term) => fetch(`/api/cms/autocomplete/${name}?term=${term}`).then((response) => response.json());
5
+ exports.autocomplete = autocomplete;
@@ -0,0 +1,3 @@
1
+ import { OnUploadFileHandler, UploadOptions } from "../types";
2
+ export declare function uploadFile(file: File, namespace: string, options?: UploadOptions): Promise<any>;
3
+ export declare function createUploadHandler(namespace: string): OnUploadFileHandler;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadFile = uploadFile;
4
+ exports.createUploadHandler = createUploadHandler;
5
+ function uploadFile(file, namespace, options) {
6
+ var _a;
7
+ const formData = new FormData();
8
+ formData.append("files[]", file);
9
+ return fetch(`/api/cms/files/upload?namespace=${namespace}`, {
10
+ method: "POST",
11
+ body: formData,
12
+ signal: (_a = options === null || options === void 0 ? void 0 : options.abortController) === null || _a === void 0 ? void 0 : _a.signal,
13
+ })
14
+ .then((response) => {
15
+ if (response.ok) {
16
+ return response.json();
17
+ }
18
+ throw new Error(`Server responded with ${response.status}`);
19
+ })
20
+ .then((data) => {
21
+ const firstFile = data.at(0);
22
+ if (firstFile) {
23
+ return firstFile;
24
+ }
25
+ throw new Error("Response is null");
26
+ })
27
+ .catch((error) => {
28
+ throw new Error(`Upload failed: ${error.message}`);
29
+ });
30
+ }
31
+ function createUploadHandler(namespace) {
32
+ return (file, options) => uploadFile(file, namespace, options);
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core",
3
- "version": "11.60.1",
3
+ "version": "11.67.0",
4
4
  "description": "UXF Core",
5
5
  "author": "Petr Vejvoda <vejvoda@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/core#readme",
package/types/index.d.ts CHANGED
@@ -8,3 +8,12 @@ export interface FileResponse {
8
8
  namespace: string | null;
9
9
  type?: string;
10
10
  }
11
+ export type UploadProgressEvent = Pick<ProgressEvent, "lengthComputable" | "loaded" | "total">;
12
+ export interface UploadOptions {
13
+ abortController?: AbortController;
14
+ onUploadProgress?: (progressEvent: UploadProgressEvent) => void;
15
+ }
16
+ export type OnUploadFileHandler = (file: File, options?: UploadOptions) => Promise<FileResponse>;
17
+ export interface FileUploadProps {
18
+ onUploadFile: OnUploadFileHandler;
19
+ }