@pallasoft/ps-file-components 1.0.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/LICENSE +32 -0
- package/README.md +10 -0
- package/dist/components/ps-file-delete-confirm.d.ts +11 -0
- package/dist/components/ps-file-delete-confirm.js +8 -0
- package/dist/components/ps-file-kind-icon.d.ts +6 -0
- package/dist/components/ps-file-kind-icon.js +10 -0
- package/dist/components/ps-file-list.d.ts +12 -0
- package/dist/components/ps-file-list.js +27 -0
- package/dist/components/ps-file-picker.d.ts +18 -0
- package/dist/components/ps-file-picker.js +48 -0
- package/dist/components/ps-file-viewer-button.d.ts +10 -0
- package/dist/components/ps-file-viewer-button.js +7 -0
- package/dist/components/ps-file-viewer-content.d.ts +2 -0
- package/dist/components/ps-file-viewer-content.js +28 -0
- package/dist/components/ps-file-viewer.d.ts +14 -0
- package/dist/components/ps-file-viewer.js +102 -0
- package/dist/components/ps-progress-bar.d.ts +7 -0
- package/dist/components/ps-progress-bar.js +15 -0
- package/dist/components/ps-upload-modal.d.ts +10 -0
- package/dist/components/ps-upload-modal.js +19 -0
- package/dist/components/ps-upload-row.d.ts +11 -0
- package/dist/components/ps-upload-row.js +28 -0
- package/dist/components/viewers/ps-highlighted-text.d.ts +6 -0
- package/dist/components/viewers/ps-highlighted-text.js +8 -0
- package/dist/components/viewers/ps-image-viewer.d.ts +2 -0
- package/dist/components/viewers/ps-image-viewer.js +33 -0
- package/dist/components/viewers/ps-media-viewer.d.ts +2 -0
- package/dist/components/viewers/ps-media-viewer.js +8 -0
- package/dist/components/viewers/ps-pdf-page.d.ts +12 -0
- package/dist/components/viewers/ps-pdf-page.js +37 -0
- package/dist/components/viewers/ps-pdf-thumbnail.d.ts +11 -0
- package/dist/components/viewers/ps-pdf-thumbnail.js +28 -0
- package/dist/components/viewers/ps-pdf-viewer.d.ts +2 -0
- package/dist/components/viewers/ps-pdf-viewer.js +100 -0
- package/dist/components/viewers/ps-text-viewer.d.ts +2 -0
- package/dist/components/viewers/ps-text-viewer.js +42 -0
- package/dist/components/viewers/ps-unsupported-viewer.d.ts +2 -0
- package/dist/components/viewers/ps-unsupported-viewer.js +8 -0
- package/dist/constants/ps-file-kind-icons.d.ts +3 -0
- package/dist/constants/ps-file-kind-icons.js +14 -0
- package/dist/constants/ps-file-kind.d.ts +10 -0
- package/dist/constants/ps-file-kind.js +12 -0
- package/dist/constants/ps-file-list-labels.d.ts +6 -0
- package/dist/constants/ps-file-list-labels.js +9 -0
- package/dist/constants/ps-file-picker-labels.d.ts +7 -0
- package/dist/constants/ps-file-picker-labels.js +10 -0
- package/dist/constants/ps-file-type-config.d.ts +7 -0
- package/dist/constants/ps-file-type-config.js +30 -0
- package/dist/constants/ps-file-viewer-config.d.ts +9 -0
- package/dist/constants/ps-file-viewer-config.js +12 -0
- package/dist/constants/ps-file-viewer-kinds.d.ts +5 -0
- package/dist/constants/ps-file-viewer-kinds.js +9 -0
- package/dist/constants/ps-file-viewer-labels.d.ts +21 -0
- package/dist/constants/ps-file-viewer-labels.js +24 -0
- package/dist/constants/ps-upload-labels.d.ts +14 -0
- package/dist/constants/ps-upload-labels.js +17 -0
- package/dist/constants/ps-upload-messages.d.ts +4 -0
- package/dist/constants/ps-upload-messages.js +7 -0
- package/dist/constants/ps-upload-queue-config.d.ts +4 -0
- package/dist/constants/ps-upload-queue-config.js +7 -0
- package/dist/constants/ps-upload-status-tones.d.ts +2 -0
- package/dist/constants/ps-upload-status-tones.js +12 -0
- package/dist/constants/ps-upload-status.d.ts +9 -0
- package/dist/constants/ps-upload-status.js +11 -0
- package/dist/esm/components/ps-file-delete-confirm.js +4 -0
- package/dist/esm/components/ps-file-kind-icon.js +6 -0
- package/dist/esm/components/ps-file-list.js +23 -0
- package/dist/esm/components/ps-file-picker.js +44 -0
- package/dist/esm/components/ps-file-viewer-button.js +3 -0
- package/dist/esm/components/ps-file-viewer-content.js +24 -0
- package/dist/esm/components/ps-file-viewer.js +98 -0
- package/dist/esm/components/ps-progress-bar.js +11 -0
- package/dist/esm/components/ps-upload-modal.js +15 -0
- package/dist/esm/components/ps-upload-row.js +24 -0
- package/dist/esm/components/viewers/ps-highlighted-text.js +4 -0
- package/dist/esm/components/viewers/ps-image-viewer.js +29 -0
- package/dist/esm/components/viewers/ps-media-viewer.js +4 -0
- package/dist/esm/components/viewers/ps-pdf-page.js +33 -0
- package/dist/esm/components/viewers/ps-pdf-thumbnail.js +24 -0
- package/dist/esm/components/viewers/ps-pdf-viewer.js +96 -0
- package/dist/esm/components/viewers/ps-text-viewer.js +38 -0
- package/dist/esm/components/viewers/ps-unsupported-viewer.js +4 -0
- package/dist/esm/constants/ps-file-kind-icons.js +11 -0
- package/dist/esm/constants/ps-file-kind.js +9 -0
- package/dist/esm/constants/ps-file-list-labels.js +6 -0
- package/dist/esm/constants/ps-file-picker-labels.js +7 -0
- package/dist/esm/constants/ps-file-type-config.js +27 -0
- package/dist/esm/constants/ps-file-viewer-config.js +9 -0
- package/dist/esm/constants/ps-file-viewer-kinds.js +6 -0
- package/dist/esm/constants/ps-file-viewer-labels.js +21 -0
- package/dist/esm/constants/ps-upload-labels.js +14 -0
- package/dist/esm/constants/ps-upload-messages.js +4 -0
- package/dist/esm/constants/ps-upload-queue-config.js +4 -0
- package/dist/esm/constants/ps-upload-status-tones.js +9 -0
- package/dist/esm/constants/ps-upload-status.js +8 -0
- package/dist/esm/hooks/use-ps-active-match-scroll.js +8 -0
- package/dist/esm/hooks/use-ps-file-text.js +21 -0
- package/dist/esm/hooks/use-ps-in-view.js +17 -0
- package/dist/esm/hooks/use-ps-upload-queue.js +67 -0
- package/dist/esm/index.js +62 -0
- package/dist/esm/models/ps-file-rejection.js +1 -0
- package/dist/esm/models/ps-file-selection-rules.js +1 -0
- package/dist/esm/models/ps-file-selection.js +1 -0
- package/dist/esm/models/ps-file-text-state.js +1 -0
- package/dist/esm/models/ps-file-viewer-content-props.js +1 -0
- package/dist/esm/models/ps-label-set.js +1 -0
- package/dist/esm/models/ps-page-size.js +1 -0
- package/dist/esm/models/ps-pdf-match.js +1 -0
- package/dist/esm/models/ps-point.js +1 -0
- package/dist/esm/models/ps-text-match.js +1 -0
- package/dist/esm/models/ps-text-segment.js +1 -0
- package/dist/esm/models/ps-upload-handler-options.js +1 -0
- package/dist/esm/models/ps-upload-item.js +1 -0
- package/dist/esm/models/ps-upload-queue-options.js +1 -0
- package/dist/esm/models/ps-upload-queue-state.js +1 -0
- package/dist/esm/models/ps-upload-summary.js +1 -0
- package/dist/esm/models/ps-viewer-file.js +1 -0
- package/dist/esm/models/ps-xhr-upload-request.js +1 -0
- package/dist/esm/models/ps-xhr-upload-response.js +1 -0
- package/dist/esm/services/ps-csv-service.js +42 -0
- package/dist/esm/services/ps-file-selection-service.js +16 -0
- package/dist/esm/services/ps-file-size-service.js +14 -0
- package/dist/esm/services/ps-file-type-service.js +38 -0
- package/dist/esm/services/ps-pdf-service.js +59 -0
- package/dist/esm/services/ps-text-search-service.js +32 -0
- package/dist/esm/services/ps-upload-queue-service.js +37 -0
- package/dist/esm/services/ps-xhr-upload-service.js +52 -0
- package/dist/hooks/use-ps-active-match-scroll.d.ts +2 -0
- package/dist/hooks/use-ps-active-match-scroll.js +12 -0
- package/dist/hooks/use-ps-file-text.d.ts +2 -0
- package/dist/hooks/use-ps-file-text.js +25 -0
- package/dist/hooks/use-ps-in-view.d.ts +2 -0
- package/dist/hooks/use-ps-in-view.js +21 -0
- package/dist/hooks/use-ps-upload-queue.d.ts +3 -0
- package/dist/hooks/use-ps-upload-queue.js +71 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.js +78 -0
- package/dist/models/ps-file-rejection.d.ts +4 -0
- package/dist/models/ps-file-rejection.js +2 -0
- package/dist/models/ps-file-selection-rules.d.ts +6 -0
- package/dist/models/ps-file-selection-rules.js +2 -0
- package/dist/models/ps-file-selection.d.ts +5 -0
- package/dist/models/ps-file-selection.js +2 -0
- package/dist/models/ps-file-text-state.d.ts +4 -0
- package/dist/models/ps-file-text-state.js +2 -0
- package/dist/models/ps-file-viewer-content-props.d.ts +13 -0
- package/dist/models/ps-file-viewer-content-props.js +2 -0
- package/dist/models/ps-label-set.d.ts +3 -0
- package/dist/models/ps-label-set.js +2 -0
- package/dist/models/ps-page-size.d.ts +4 -0
- package/dist/models/ps-page-size.js +2 -0
- package/dist/models/ps-pdf-match.d.ts +7 -0
- package/dist/models/ps-pdf-match.js +2 -0
- package/dist/models/ps-point.d.ts +4 -0
- package/dist/models/ps-point.js +2 -0
- package/dist/models/ps-text-match.d.ts +4 -0
- package/dist/models/ps-text-match.js +2 -0
- package/dist/models/ps-text-segment.d.ts +5 -0
- package/dist/models/ps-text-segment.js +2 -0
- package/dist/models/ps-upload-handler-options.d.ts +4 -0
- package/dist/models/ps-upload-handler-options.js +2 -0
- package/dist/models/ps-upload-item.d.ts +8 -0
- package/dist/models/ps-upload-item.js +2 -0
- package/dist/models/ps-upload-queue-options.d.ts +6 -0
- package/dist/models/ps-upload-queue-options.js +2 -0
- package/dist/models/ps-upload-queue-state.d.ts +10 -0
- package/dist/models/ps-upload-queue-state.js +2 -0
- package/dist/models/ps-upload-summary.d.ts +5 -0
- package/dist/models/ps-upload-summary.js +2 -0
- package/dist/models/ps-viewer-file.d.ts +9 -0
- package/dist/models/ps-viewer-file.js +2 -0
- package/dist/models/ps-xhr-upload-request.d.ts +8 -0
- package/dist/models/ps-xhr-upload-request.js +2 -0
- package/dist/models/ps-xhr-upload-response.d.ts +4 -0
- package/dist/models/ps-xhr-upload-response.js +2 -0
- package/dist/services/ps-csv-service.d.ts +3 -0
- package/dist/services/ps-csv-service.js +46 -0
- package/dist/services/ps-file-selection-service.d.ts +5 -0
- package/dist/services/ps-file-selection-service.js +20 -0
- package/dist/services/ps-file-size-service.d.ts +3 -0
- package/dist/services/ps-file-size-service.js +18 -0
- package/dist/services/ps-file-type-service.d.ts +6 -0
- package/dist/services/ps-file-type-service.js +42 -0
- package/dist/services/ps-pdf-service.d.ts +11 -0
- package/dist/services/ps-pdf-service.js +96 -0
- package/dist/services/ps-text-search-service.d.ts +6 -0
- package/dist/services/ps-text-search-service.js +36 -0
- package/dist/services/ps-upload-queue-service.d.ts +10 -0
- package/dist/services/ps-upload-queue-service.js +41 -0
- package/dist/services/ps-xhr-upload-service.d.ts +7 -0
- package/dist/services/ps-xhr-upload-service.js +56 -0
- package/package.json +85 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.PsPdfService = void 0;
|
|
37
|
+
const ps_text_search_service_1 = require("./ps-text-search-service");
|
|
38
|
+
class PsPdfService {
|
|
39
|
+
static load(workerSrc) {
|
|
40
|
+
if (PsPdfService.library === null)
|
|
41
|
+
PsPdfService.library = Promise.resolve().then(() => __importStar(require('pdfjs-dist'))).then((library) => {
|
|
42
|
+
library.GlobalWorkerOptions.workerSrc = workerSrc;
|
|
43
|
+
return library;
|
|
44
|
+
});
|
|
45
|
+
return PsPdfService.library;
|
|
46
|
+
}
|
|
47
|
+
static async open(url, workerSrc) {
|
|
48
|
+
const library = await PsPdfService.load(workerSrc);
|
|
49
|
+
return await library.getDocument({ url, withCredentials: true }).promise;
|
|
50
|
+
}
|
|
51
|
+
static render(page, canvas, scale, rotation) {
|
|
52
|
+
const viewport = page.getViewport({ rotation: page.rotate + rotation, scale });
|
|
53
|
+
const ratio = typeof window === 'undefined' ? 1 : window.devicePixelRatio;
|
|
54
|
+
canvas.width = Math.floor(viewport.width * ratio);
|
|
55
|
+
canvas.height = Math.floor(viewport.height * ratio);
|
|
56
|
+
canvas.style.width = `${Math.floor(viewport.width)}px`;
|
|
57
|
+
canvas.style.height = `${Math.floor(viewport.height)}px`;
|
|
58
|
+
const task = page.render({
|
|
59
|
+
canvas,
|
|
60
|
+
transform: ratio === 1 ? undefined : [ratio, 0, 0, ratio, 0, 0],
|
|
61
|
+
viewport,
|
|
62
|
+
});
|
|
63
|
+
task.promise.catch(() => undefined);
|
|
64
|
+
return task;
|
|
65
|
+
}
|
|
66
|
+
static async search(document, query, rotation) {
|
|
67
|
+
const matches = [];
|
|
68
|
+
for (let pageNumber = 1; pageNumber <= document.numPages; pageNumber += 1) {
|
|
69
|
+
const page = await document.getPage(pageNumber);
|
|
70
|
+
const viewport = page.getViewport({ rotation: page.rotate + rotation, scale: 1 });
|
|
71
|
+
const content = await page.getTextContent();
|
|
72
|
+
content.items.forEach((item) => {
|
|
73
|
+
if (!('str' in item) || item.str.length === 0)
|
|
74
|
+
return;
|
|
75
|
+
ps_text_search_service_1.PsTextSearchService.find(item.str, query).forEach((found) => {
|
|
76
|
+
const [x, y] = [item.transform[4], item.transform[5]];
|
|
77
|
+
const height = item.height > 0 ? item.height : Math.hypot(item.transform[2], item.transform[3]);
|
|
78
|
+
const start = x + (item.width * found.start) / item.str.length;
|
|
79
|
+
const end = x + (item.width * found.end) / item.str.length;
|
|
80
|
+
const [x1, y1] = viewport.convertToViewportPoint(start, y);
|
|
81
|
+
const [x2, y2] = viewport.convertToViewportPoint(end, y + height);
|
|
82
|
+
matches.push({
|
|
83
|
+
height: Math.abs(y2 - y1) / viewport.height,
|
|
84
|
+
left: Math.min(x1, x2) / viewport.width,
|
|
85
|
+
pageNumber,
|
|
86
|
+
top: Math.min(y1, y2) / viewport.height,
|
|
87
|
+
width: Math.abs(x2 - x1) / viewport.width,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return matches;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.PsPdfService = PsPdfService;
|
|
96
|
+
PsPdfService.library = null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PsTextMatch } from '../models/ps-text-match';
|
|
2
|
+
import type { PsTextSegment } from '../models/ps-text-segment';
|
|
3
|
+
export declare class PsTextSearchService {
|
|
4
|
+
static find(text: string, query: string): PsTextMatch[];
|
|
5
|
+
static segments(text: string, matches: PsTextMatch[], firstIndex?: number): PsTextSegment[];
|
|
6
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsTextSearchService = void 0;
|
|
4
|
+
class PsTextSearchService {
|
|
5
|
+
static find(text, query) {
|
|
6
|
+
const needle = query.trim().toLowerCase();
|
|
7
|
+
if (needle.length === 0)
|
|
8
|
+
return [];
|
|
9
|
+
const haystack = text.toLowerCase();
|
|
10
|
+
const matches = [];
|
|
11
|
+
let from = haystack.indexOf(needle);
|
|
12
|
+
while (from !== -1) {
|
|
13
|
+
matches.push({ end: from + needle.length, start: from });
|
|
14
|
+
from = haystack.indexOf(needle, from + needle.length);
|
|
15
|
+
}
|
|
16
|
+
return matches;
|
|
17
|
+
}
|
|
18
|
+
static segments(text, matches, firstIndex = 0) {
|
|
19
|
+
const segments = [];
|
|
20
|
+
let cursor = 0;
|
|
21
|
+
matches.forEach((match, index) => {
|
|
22
|
+
if (match.start > cursor)
|
|
23
|
+
segments.push({ isMatch: false, matchIndex: null, text: text.slice(cursor, match.start) });
|
|
24
|
+
segments.push({
|
|
25
|
+
isMatch: true,
|
|
26
|
+
matchIndex: firstIndex + index,
|
|
27
|
+
text: text.slice(match.start, match.end),
|
|
28
|
+
});
|
|
29
|
+
cursor = match.end;
|
|
30
|
+
});
|
|
31
|
+
if (cursor < text.length)
|
|
32
|
+
segments.push({ isMatch: false, matchIndex: null, text: text.slice(cursor) });
|
|
33
|
+
return segments;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.PsTextSearchService = PsTextSearchService;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PsUploadItem } from '../models/ps-upload-item';
|
|
2
|
+
import type { PsUploadSummary } from '../models/ps-upload-summary';
|
|
3
|
+
export declare class PsUploadQueueService {
|
|
4
|
+
static isActive(item: PsUploadItem): boolean;
|
|
5
|
+
static isBusy(items: PsUploadItem[]): boolean;
|
|
6
|
+
static next(items: PsUploadItem[], concurrency: number): PsUploadItem[];
|
|
7
|
+
static itemsFor(files: File[]): PsUploadItem[];
|
|
8
|
+
static summary(items: PsUploadItem[]): PsUploadSummary;
|
|
9
|
+
private static id;
|
|
10
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsUploadQueueService = void 0;
|
|
4
|
+
const ps_upload_status_1 = require("../constants/ps-upload-status");
|
|
5
|
+
class PsUploadQueueService {
|
|
6
|
+
static isActive(item) {
|
|
7
|
+
return (item.status === ps_upload_status_1.PsUploadStatus.waiting ||
|
|
8
|
+
item.status === ps_upload_status_1.PsUploadStatus.uploading ||
|
|
9
|
+
item.status === ps_upload_status_1.PsUploadStatus.processing);
|
|
10
|
+
}
|
|
11
|
+
static isBusy(items) {
|
|
12
|
+
return items.some((item) => PsUploadQueueService.isActive(item));
|
|
13
|
+
}
|
|
14
|
+
static next(items, concurrency) {
|
|
15
|
+
const running = items.filter((item) => item.status === ps_upload_status_1.PsUploadStatus.uploading || item.status === ps_upload_status_1.PsUploadStatus.processing).length;
|
|
16
|
+
const slots = Math.max(0, concurrency - running);
|
|
17
|
+
return items.filter((item) => item.status === ps_upload_status_1.PsUploadStatus.waiting).slice(0, slots);
|
|
18
|
+
}
|
|
19
|
+
static itemsFor(files) {
|
|
20
|
+
return files.map((file) => ({
|
|
21
|
+
error: null,
|
|
22
|
+
file,
|
|
23
|
+
id: PsUploadQueueService.id(),
|
|
24
|
+
progress: 0,
|
|
25
|
+
status: ps_upload_status_1.PsUploadStatus.waiting,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
static summary(items) {
|
|
29
|
+
return {
|
|
30
|
+
done: items.filter((item) => item.status === ps_upload_status_1.PsUploadStatus.done).length,
|
|
31
|
+
failed: items.filter((item) => item.status === ps_upload_status_1.PsUploadStatus.failed).length,
|
|
32
|
+
total: items.length,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
static id() {
|
|
36
|
+
return typeof crypto !== 'undefined' && 'randomUUID' in crypto
|
|
37
|
+
? crypto.randomUUID()
|
|
38
|
+
: `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.PsUploadQueueService = PsUploadQueueService;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PsXhrUploadRequest } from '../models/ps-xhr-upload-request';
|
|
2
|
+
import type { PsXhrUploadResponse } from '../models/ps-xhr-upload-response';
|
|
3
|
+
export declare class PsXhrUploadService {
|
|
4
|
+
static parse(text: string): unknown;
|
|
5
|
+
static errorMessage(body: unknown): string;
|
|
6
|
+
static send(request: PsXhrUploadRequest): Promise<PsXhrUploadResponse>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsXhrUploadService = void 0;
|
|
4
|
+
const ps_upload_messages_1 = require("../constants/ps-upload-messages");
|
|
5
|
+
class PsXhrUploadService {
|
|
6
|
+
static parse(text) {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(text);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return text;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
static errorMessage(body) {
|
|
15
|
+
if (typeof body !== 'object' || body === null || !('error' in body))
|
|
16
|
+
return ps_upload_messages_1.PsUploadMessages.failed;
|
|
17
|
+
const error = body.error;
|
|
18
|
+
if (typeof error === 'string' && error.length > 0)
|
|
19
|
+
return error;
|
|
20
|
+
if (typeof error === 'object' && error !== null && 'message' in error) {
|
|
21
|
+
const message = error.message;
|
|
22
|
+
if (typeof message === 'string' && message.length > 0)
|
|
23
|
+
return message;
|
|
24
|
+
}
|
|
25
|
+
return ps_upload_messages_1.PsUploadMessages.failed;
|
|
26
|
+
}
|
|
27
|
+
static send(request) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const xhr = new XMLHttpRequest();
|
|
30
|
+
xhr.open(request.method === undefined ? 'POST' : request.method, request.url);
|
|
31
|
+
Object.entries(request.headers === undefined ? {} : request.headers).forEach(([name, value]) => xhr.setRequestHeader(name, value));
|
|
32
|
+
xhr.upload.onprogress = (event) => {
|
|
33
|
+
if (event.lengthComputable && request.onProgress)
|
|
34
|
+
request.onProgress(event.total === 0 ? 1 : event.loaded / event.total);
|
|
35
|
+
};
|
|
36
|
+
xhr.onload = () => {
|
|
37
|
+
const body = PsXhrUploadService.parse(xhr.responseText);
|
|
38
|
+
if (xhr.status >= 200 && xhr.status < 300)
|
|
39
|
+
resolve({ body, status: xhr.status });
|
|
40
|
+
else
|
|
41
|
+
reject(new Error(PsXhrUploadService.errorMessage(body)));
|
|
42
|
+
};
|
|
43
|
+
xhr.onerror = () => reject(new Error(ps_upload_messages_1.PsUploadMessages.failed));
|
|
44
|
+
xhr.onabort = () => reject(new Error(ps_upload_messages_1.PsUploadMessages.cancelled));
|
|
45
|
+
if (request.signal) {
|
|
46
|
+
if (request.signal.aborted) {
|
|
47
|
+
reject(new Error(ps_upload_messages_1.PsUploadMessages.cancelled));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
request.signal.addEventListener('abort', () => xhr.abort(), { once: true });
|
|
51
|
+
}
|
|
52
|
+
xhr.send(request.body);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.PsXhrUploadService = PsXhrUploadService;
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pallasoft/ps-file-components",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"module": "./dist/esm/index.js",
|
|
13
|
+
"require": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"/dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"husky:prepare": "npx husky",
|
|
22
|
+
"build": "tsc && tsc -p tsconfig.esm.json",
|
|
23
|
+
"setup:graphify": "sh scripts/graphify-setup.sh",
|
|
24
|
+
"update:graphify": "sh scripts/graphify-update.sh",
|
|
25
|
+
"lint": "npm run lint:eslint",
|
|
26
|
+
"lint:fix": "npm run lint:eslint:fix",
|
|
27
|
+
"format:check": "npx prettier --check --ignore-unknown \"src/**/*.{ts,tsx,json,md}\"",
|
|
28
|
+
"format:prettier": "npx prettier --write \"src/**/*.{ts,tsx,json,md}\"",
|
|
29
|
+
"lint:eslint": "npx eslint \"src/**/*.{ts,tsx}\"",
|
|
30
|
+
"lint:eslint:fix": "npx eslint --fix \"src/**/*.{ts,tsx}\"",
|
|
31
|
+
"release": "semantic-release",
|
|
32
|
+
"test": "vitest run"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@pallasoft/ps-core-components": "^2.13.0",
|
|
36
|
+
"@pallasoft/ps-design-system": "^1.7.0",
|
|
37
|
+
"@pallasoft/ps-icons": "^1.6.0",
|
|
38
|
+
"@pallasoft/ps-popovers": "^1.5.2",
|
|
39
|
+
"pdfjs-dist": "^6.3.289"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"react": "^18 || ^19",
|
|
43
|
+
"react-dom": "^18 || ^19"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@commitlint/cli": "^20.1.0",
|
|
47
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
48
|
+
"@eslint/compat": "^2.0.0",
|
|
49
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
|
|
50
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
51
|
+
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
52
|
+
"@semantic-release/git": "^10.0.1",
|
|
53
|
+
"@semantic-release/github": "^11.0.1",
|
|
54
|
+
"@semantic-release/npm": "^12.0.0",
|
|
55
|
+
"@semantic-release/release-notes-generator": "^14.0.1",
|
|
56
|
+
"@types/react": "^18.3.28",
|
|
57
|
+
"@types/react-dom": "^18.3.7",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^8.48.0",
|
|
59
|
+
"@typescript-eslint/parser": "^8.48.0",
|
|
60
|
+
"commitlint": "^20.1.0",
|
|
61
|
+
"conventional-changelog-conventionalcommits": "^7.0.2",
|
|
62
|
+
"eslint": "^9.39.1",
|
|
63
|
+
"eslint-config-prettier": "^10.1.8",
|
|
64
|
+
"eslint-plugin-import": "^2.32.0",
|
|
65
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
66
|
+
"husky": "^9.1.7",
|
|
67
|
+
"lint-staged": "^16.2.7",
|
|
68
|
+
"prettier": "^3.6.2",
|
|
69
|
+
"react": "^19.3.0",
|
|
70
|
+
"react-dom": "^19.3.0",
|
|
71
|
+
"semantic-release": "^24.2.0",
|
|
72
|
+
"ts-node": "^10.9.2",
|
|
73
|
+
"typescript": "^5.9.3",
|
|
74
|
+
"vitest": "^3.2.4"
|
|
75
|
+
},
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public",
|
|
78
|
+
"registry": "https://registry.npmjs.org/"
|
|
79
|
+
},
|
|
80
|
+
"repository": {
|
|
81
|
+
"type": "git",
|
|
82
|
+
"url": "git+https://github.com/pallasoft/ps-file-components.git"
|
|
83
|
+
},
|
|
84
|
+
"description": "Shared Pallasoft file components: picker, upload queue, file list and a multi-format viewer"
|
|
85
|
+
}
|