@rkosafo/cai.components 0.0.47 → 0.0.49
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/forms/FormFileUpload/FormFileUplad.svelte +134 -0
- package/dist/forms/FormFileUpload/FormFileUplad.svelte.d.ts +4 -0
- package/dist/forms/FormFileUpload/index.d.ts +1 -0
- package/dist/forms/FormFileUpload/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/ui/datatable/Datatable.svelte +2 -1
- package/dist/ui/table/Table.svelte +2 -3
- package/package.json +6 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { registerPlugin, supported } from 'svelte-filepond';
|
|
3
|
+
import FilePondPluginImageExifOrientation from 'filepond-plugin-image-exif-orientation';
|
|
4
|
+
import FilePondPluginImagePreview from 'filepond-plugin-image-preview';
|
|
5
|
+
import FilePondPluginFileValidateType from 'filepond-plugin-file-validate-type';
|
|
6
|
+
registerPlugin(
|
|
7
|
+
FilePondPluginImageExifOrientation,
|
|
8
|
+
FilePondPluginImagePreview,
|
|
9
|
+
FilePondPluginFileValidateType
|
|
10
|
+
);
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
import { key, Label } from '../../index.js';
|
|
15
|
+
import type { FormFileUploadProps } from '../../types/index.js';
|
|
16
|
+
import { nanoid } from 'nanoid';
|
|
17
|
+
import { getContext } from 'svelte';
|
|
18
|
+
import FilePond from 'svelte-filepond';
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
title = 'Click Browse or drop the file to upload',
|
|
22
|
+
subTitle = '',
|
|
23
|
+
url = '',
|
|
24
|
+
name = 'file',
|
|
25
|
+
allowMultiple = false,
|
|
26
|
+
acceptedFileTypes = [
|
|
27
|
+
'image/png',
|
|
28
|
+
'image/jpeg',
|
|
29
|
+
'application/pdf',
|
|
30
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
31
|
+
],
|
|
32
|
+
files = [],
|
|
33
|
+
label = '',
|
|
34
|
+
required = false,
|
|
35
|
+
showError = false,
|
|
36
|
+
imageOnly = false,
|
|
37
|
+
contextKey = null,
|
|
38
|
+
onChange
|
|
39
|
+
}: FormFileUploadProps = $props();
|
|
40
|
+
|
|
41
|
+
// State
|
|
42
|
+
let pond = $state<any>();
|
|
43
|
+
|
|
44
|
+
// Context
|
|
45
|
+
const { touched, errors, data, setData }: any = getContext(contextKey || key);
|
|
46
|
+
|
|
47
|
+
// Derived state
|
|
48
|
+
let id = nanoid();
|
|
49
|
+
let hasError = $derived($touched[name] && $errors[name]?.length);
|
|
50
|
+
let error = $derived($errors[name]?.join(', '));
|
|
51
|
+
|
|
52
|
+
// Constants
|
|
53
|
+
const uploadServerConfig = {};
|
|
54
|
+
|
|
55
|
+
// Effects
|
|
56
|
+
$effect(() => {
|
|
57
|
+
if (imageOnly && acceptedFileTypes?.length === 3) {
|
|
58
|
+
acceptedFileTypes = ['image/png', 'image/jpeg'];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
function checkFiles(files: any) {
|
|
63
|
+
if (files.length > 1) {
|
|
64
|
+
const newFiles = files.map((x: any) => x.file);
|
|
65
|
+
setData({ ...$data, [name]: newFiles });
|
|
66
|
+
onChange?.({ name, value: newFiles });
|
|
67
|
+
} else if (files.length === 1) {
|
|
68
|
+
const { file } = files[0];
|
|
69
|
+
setData({ ...$data, [name]: file });
|
|
70
|
+
onChange?.({ name, value: file });
|
|
71
|
+
} else if (files.length == 0) {
|
|
72
|
+
onChange?.(null);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function customFileTypeDetection(source: File, type: string) {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const fileName = source.name;
|
|
79
|
+
if (fileName.endsWith('.frx')) {
|
|
80
|
+
resolve('.frx');
|
|
81
|
+
} else {
|
|
82
|
+
resolve(type);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<div class="relative my-2 flex flex-grow flex-col">
|
|
89
|
+
<Label
|
|
90
|
+
>{label}
|
|
91
|
+
{#if required}
|
|
92
|
+
<span class="pl-1 text-red-500">*</span>
|
|
93
|
+
{/if}
|
|
94
|
+
</Label>
|
|
95
|
+
|
|
96
|
+
<FilePond
|
|
97
|
+
{name}
|
|
98
|
+
required={true}
|
|
99
|
+
allowReplace={true}
|
|
100
|
+
instantUpload={false}
|
|
101
|
+
server={uploadServerConfig}
|
|
102
|
+
{allowMultiple}
|
|
103
|
+
allowRevert={true}
|
|
104
|
+
allowImagePreview={true}
|
|
105
|
+
allowImageResize={true}
|
|
106
|
+
bind:this={pond}
|
|
107
|
+
onupdatefiles={checkFiles}
|
|
108
|
+
{files}
|
|
109
|
+
{acceptedFileTypes}
|
|
110
|
+
fileValidateTypeDetectType={customFileTypeDetection}
|
|
111
|
+
credits={false}
|
|
112
|
+
/>
|
|
113
|
+
|
|
114
|
+
{#if hasError}
|
|
115
|
+
<Label
|
|
116
|
+
class="v-error-container absolute top-9 right-2 flex items-center gap-1 text-sm {hasError &&
|
|
117
|
+
'text-red-600'}"
|
|
118
|
+
>
|
|
119
|
+
<span class="v-error-message hidden backdrop-blur-sm">
|
|
120
|
+
{error}
|
|
121
|
+
</span>
|
|
122
|
+
<iconify-icon
|
|
123
|
+
icon="solar:danger-circle-bold-duotone"
|
|
124
|
+
class="v-error-svg ml-auto cursor-pointer text-red-500 select-none hover:text-red-600"
|
|
125
|
+
style="font-size: 18px;"
|
|
126
|
+
></iconify-icon>
|
|
127
|
+
</Label>
|
|
128
|
+
{/if}
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<style>
|
|
132
|
+
@import 'filepond/dist/filepond.css';
|
|
133
|
+
@import 'filepond-plugin-image-preview/dist/filepond-plugin-image-preview.css';
|
|
134
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as FormFileUpload } from './FormFileUplad.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as FormFileUpload } from './FormFileUplad.svelte';
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export * from './forms/textarea/index.js';
|
|
|
35
35
|
export * from './forms/select/index.js';
|
|
36
36
|
export * from './forms/radio/index.js';
|
|
37
37
|
export * from './forms/checkbox/index.js';
|
|
38
|
+
export * from './forms/FormFileUpload/index.js';
|
|
38
39
|
export * from './forms/form/index.js';
|
|
39
40
|
export * from './forms/FormInput/index.js';
|
|
40
41
|
export * from './forms/FormDatepicker/index.js';
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ export * from './forms/textarea/index.js';
|
|
|
36
36
|
export * from './forms/select/index.js';
|
|
37
37
|
export * from './forms/radio/index.js';
|
|
38
38
|
export * from './forms/checkbox/index.js';
|
|
39
|
+
export * from './forms/FormFileUpload/index.js';
|
|
39
40
|
export * from './forms/form/index.js';
|
|
40
41
|
export * from './forms/FormInput/index.js';
|
|
41
42
|
export * from './forms/FormDatepicker/index.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -856,3 +856,18 @@ export interface IDocumentCanvasProps {
|
|
|
856
856
|
close: (val: IDocumentCanvasClose) => void;
|
|
857
857
|
toggleCollapse: (id: string) => void;
|
|
858
858
|
}
|
|
859
|
+
export interface FormFileUploadProps {
|
|
860
|
+
title: string;
|
|
861
|
+
subTitle?: string;
|
|
862
|
+
url?: string;
|
|
863
|
+
name: string;
|
|
864
|
+
allowMultiple?: boolean;
|
|
865
|
+
acceptedFileTypes?: string[];
|
|
866
|
+
files?: any[];
|
|
867
|
+
label: string;
|
|
868
|
+
required?: boolean;
|
|
869
|
+
showError?: boolean;
|
|
870
|
+
imageOnly?: boolean;
|
|
871
|
+
contextKey?: any;
|
|
872
|
+
onChange?: (val: any) => void;
|
|
873
|
+
}
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
onDelete,
|
|
68
68
|
editor,
|
|
69
69
|
customFilter,
|
|
70
|
+
handleCheckbox,
|
|
70
71
|
read = $bindable((skip?: number, take?: number, filter?: TableFilter<any>) => {
|
|
71
72
|
return null;
|
|
72
73
|
}),
|
|
@@ -474,7 +475,7 @@
|
|
|
474
475
|
onDelete={handleDelete}
|
|
475
476
|
onRowClicked={handleRowClicked}
|
|
476
477
|
{onActionClicked}
|
|
477
|
-
handleCheckbox
|
|
478
|
+
{handleCheckbox}
|
|
478
479
|
{...otherProps}
|
|
479
480
|
/>
|
|
480
481
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { Dropdown, DropdownItem, type TableProps } from '../../index.js';
|
|
2
|
+
import { Checkbox, Dropdown, DropdownItem, type TableProps } from '../../index.js';
|
|
3
3
|
import { clickOutsideAction } from '../../utils/svelte-legos.js';
|
|
4
4
|
import { createTable, Render, Subscribe } from 'svelte-headless-table';
|
|
5
5
|
import {
|
|
@@ -141,9 +141,8 @@
|
|
|
141
141
|
<th
|
|
142
142
|
class="px-6 py-2.5 text-left text-sm font-semibold whitespace-nowrap rtl:text-right"
|
|
143
143
|
>
|
|
144
|
-
<
|
|
144
|
+
<Checkbox
|
|
145
145
|
class="cursor-pointer"
|
|
146
|
-
type="checkbox"
|
|
147
146
|
checked={selectAllChecked}
|
|
148
147
|
onchange={handleSelectAllChange}
|
|
149
148
|
/>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rkosafo/cai.components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.49",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"!dist/**/*.test.*",
|
|
@@ -59,12 +59,17 @@
|
|
|
59
59
|
"date-fns": "^4.1.0",
|
|
60
60
|
"dayjs": "^1.11.18",
|
|
61
61
|
"felte": "^1.3.0",
|
|
62
|
+
"filepond": "^4.32.9",
|
|
63
|
+
"filepond-plugin-file-validate-type": "^1.2.9",
|
|
64
|
+
"filepond-plugin-image-exif-orientation": "^1.0.11",
|
|
65
|
+
"filepond-plugin-image-preview": "^4.6.12",
|
|
62
66
|
"iconify-icon": "^3.0.0",
|
|
63
67
|
"keycloak-js": "^26.2.0",
|
|
64
68
|
"lodash": "^4.17.21",
|
|
65
69
|
"mdsvex": "^0.12.6",
|
|
66
70
|
"nanoid": "^5.1.5",
|
|
67
71
|
"svelecte": "^5.3.0",
|
|
72
|
+
"svelte-filepond": "^0.2.2",
|
|
68
73
|
"svelte-french-toast": "^1.2.0",
|
|
69
74
|
"svelte-headless-table": "^0.18.3",
|
|
70
75
|
"svelte-meta-tags": "^4.4.0",
|