@aquera/nile-elements 1.0.1-beta-1.5 → 1.0.1-beta-1.6
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/README.md +28 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +679 -618
- package/dist/internal/resizable-table-helper.cjs.js +1 -1
- package/dist/internal/resizable-table-helper.cjs.js.map +1 -1
- package/dist/internal/resizable-table-helper.esm.js +1 -1
- package/dist/nile-code-editor/extensionSetup.cjs.js +5 -5
- package/dist/nile-code-editor/extensionSetup.cjs.js.map +1 -1
- package/dist/nile-code-editor/extensionSetup.esm.js +1 -1
- package/dist/nile-code-editor/nile-code-editor.cjs.js +2 -2
- package/dist/nile-code-editor/nile-code-editor.cjs.js.map +1 -1
- package/dist/nile-code-editor/nile-code-editor.esm.js +3 -3
- package/dist/nile-code-editor/theme.cjs.js +1 -1
- package/dist/nile-code-editor/theme.cjs.js.map +1 -1
- package/dist/nile-code-editor/theme.esm.js +1 -1
- package/dist/nile-file-preview/nile-file-preview.cjs.js +1 -1
- package/dist/nile-file-preview/nile-file-preview.cjs.js.map +1 -1
- package/dist/nile-file-preview/nile-file-preview.css.cjs.js +1 -1
- package/dist/nile-file-preview/nile-file-preview.css.cjs.js.map +1 -1
- package/dist/nile-file-preview/nile-file-preview.css.esm.js +203 -184
- package/dist/nile-file-preview/nile-file-preview.esm.js +1 -3
- package/dist/nile-file-preview/nile-file-preview.template.cjs.js +1 -1
- package/dist/nile-file-preview/nile-file-preview.template.cjs.js.map +1 -1
- package/dist/nile-file-preview/nile-file-preview.template.esm.js +66 -77
- package/dist/nile-file-preview/types/nile-file-preview.enums.cjs.js +1 -1
- package/dist/nile-file-preview/types/nile-file-preview.enums.cjs.js.map +1 -1
- package/dist/nile-file-preview/types/nile-file-preview.enums.esm.js +1 -1
- package/dist/nile-file-preview/utils/index.cjs.js +1 -1
- package/dist/nile-file-preview/utils/index.esm.js +1 -1
- package/dist/nile-file-preview/utils/nile-file-preview.util.cjs.js +1 -1
- package/dist/nile-file-preview/utils/nile-file-preview.util.cjs.js.map +1 -1
- package/dist/nile-file-preview/utils/nile-file-preview.util.esm.js +1 -1
- package/dist/nile-file-upload/index.cjs.js +1 -1
- package/dist/nile-file-upload/index.esm.js +1 -1
- package/dist/nile-file-upload/nile-file-upload.cjs.js +1 -1
- package/dist/nile-file-upload/nile-file-upload.cjs.js.map +1 -1
- package/dist/nile-file-upload/nile-file-upload.css.cjs.js +1 -1
- package/dist/nile-file-upload/nile-file-upload.css.cjs.js.map +1 -1
- package/dist/nile-file-upload/nile-file-upload.css.esm.js +142 -89
- package/dist/nile-file-upload/nile-file-upload.esm.js +2 -2
- package/dist/nile-file-upload/nile-file-upload.template.cjs.js +3 -3
- package/dist/nile-file-upload/nile-file-upload.template.cjs.js.map +1 -1
- package/dist/nile-file-upload/nile-file-upload.template.esm.js +50 -108
- package/dist/nile-file-upload/nile-file-upload.test.cjs.js +1 -1
- package/dist/nile-file-upload/nile-file-upload.test.esm.js +1 -1
- package/dist/nile-file-upload/types/file-upload.enums.cjs.js +1 -1
- package/dist/nile-file-upload/types/file-upload.enums.cjs.js.map +1 -1
- package/dist/nile-file-upload/types/file-upload.enums.esm.js +1 -1
- package/dist/nile-file-upload/utils/drag-drop.util.cjs.js +1 -1
- package/dist/nile-file-upload/utils/drag-drop.util.cjs.js.map +1 -1
- package/dist/nile-file-upload/utils/drag-drop.util.esm.js +1 -1
- package/dist/nile-file-upload/utils/file-validation.util.cjs.js +2 -1
- package/dist/nile-file-upload/utils/file-validation.util.cjs.js.map +1 -1
- package/dist/nile-file-upload/utils/file-validation.util.esm.js +1 -1
- package/dist/nile-option/nile-option.cjs.js +1 -1
- package/dist/nile-option/nile-option.cjs.js.map +1 -1
- package/dist/nile-option/nile-option.esm.js +3 -3
- package/dist/nile-option-group/index.cjs.js +2 -0
- package/dist/nile-option-group/index.cjs.js.map +1 -0
- package/dist/nile-option-group/index.esm.js +1 -0
- package/dist/nile-option-group/nile-option-group.cjs.js +2 -0
- package/dist/nile-option-group/nile-option-group.cjs.js.map +1 -0
- package/dist/nile-option-group/nile-option-group.css.cjs.js +2 -0
- package/dist/nile-option-group/nile-option-group.css.cjs.js.map +1 -0
- package/dist/nile-option-group/nile-option-group.css.esm.js +46 -0
- package/dist/nile-option-group/nile-option-group.esm.js +14 -0
- package/dist/nile-option-group/nile-option-group.interface.cjs.js +2 -0
- package/dist/nile-option-group/nile-option-group.interface.cjs.js.map +1 -0
- package/dist/nile-option-group/nile-option-group.interface.esm.js +1 -0
- package/dist/nile-select/nile-select.cjs.js +1 -1
- package/dist/nile-select/nile-select.cjs.js.map +1 -1
- package/dist/nile-select/nile-select.esm.js +2 -2
- package/dist/nile-select/nile-select.interface.cjs.js +2 -0
- package/dist/nile-select/nile-select.interface.cjs.js.map +1 -0
- package/dist/nile-select/nile-select.interface.esm.js +1 -0
- package/dist/nile-table-body/nile-table-body.cjs.js +1 -1
- package/dist/nile-table-body/nile-table-body.cjs.js.map +1 -1
- package/dist/nile-table-body/nile-table-body.esm.js +2 -1
- package/dist/nile-table-cell-item/nile-table-cell-item.cjs.js +1 -1
- package/dist/nile-table-cell-item/nile-table-cell-item.cjs.js.map +1 -1
- package/dist/nile-table-cell-item/nile-table-cell-item.esm.js +1 -1
- package/dist/nile-table-header-item/nile-table-header-item.cjs.js +1 -1
- package/dist/nile-table-header-item/nile-table-header-item.cjs.js.map +1 -1
- package/dist/nile-table-header-item/nile-table-header-item.esm.js +2 -2
- package/dist/nile-virtual-select/renderer.cjs.js +1 -1
- package/dist/nile-virtual-select/renderer.cjs.js.map +1 -1
- package/dist/nile-virtual-select/renderer.esm.js +13 -12
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal/resizable-table-helper.d.ts +5 -0
- package/dist/src/internal/resizable-table-helper.js +27 -4
- package/dist/src/internal/resizable-table-helper.js.map +1 -1
- package/dist/src/nile-code-editor/nile-code-editor.d.ts +5 -0
- package/dist/src/nile-code-editor/nile-code-editor.js +44 -7
- package/dist/src/nile-code-editor/nile-code-editor.js.map +1 -1
- package/dist/src/nile-code-editor/theme.d.ts +15 -0
- package/dist/src/nile-code-editor/theme.js +17 -2
- package/dist/src/nile-code-editor/theme.js.map +1 -1
- package/dist/src/nile-file-preview/nile-file-preview.css.js +201 -182
- package/dist/src/nile-file-preview/nile-file-preview.css.js.map +1 -1
- package/dist/src/nile-file-preview/nile-file-preview.d.ts +6 -2
- package/dist/src/nile-file-preview/nile-file-preview.js +49 -20
- package/dist/src/nile-file-preview/nile-file-preview.js.map +1 -1
- package/dist/src/nile-file-preview/nile-file-preview.template.d.ts +3 -2
- package/dist/src/nile-file-preview/nile-file-preview.template.js +58 -62
- package/dist/src/nile-file-preview/nile-file-preview.template.js.map +1 -1
- package/dist/src/nile-file-preview/types/nile-file-preview.enums.d.ts +4 -3
- package/dist/src/nile-file-preview/types/nile-file-preview.enums.js +3 -2
- package/dist/src/nile-file-preview/types/nile-file-preview.enums.js.map +1 -1
- package/dist/src/nile-file-preview/utils/nile-file-preview.util.d.ts +4 -0
- package/dist/src/nile-file-preview/utils/nile-file-preview.util.js +25 -0
- package/dist/src/nile-file-preview/utils/nile-file-preview.util.js.map +1 -1
- package/dist/src/nile-file-upload/nile-file-upload.css.js +140 -87
- package/dist/src/nile-file-upload/nile-file-upload.css.js.map +1 -1
- package/dist/src/nile-file-upload/nile-file-upload.d.ts +4 -1
- package/dist/src/nile-file-upload/nile-file-upload.js +30 -20
- package/dist/src/nile-file-upload/nile-file-upload.js.map +1 -1
- package/dist/src/nile-file-upload/nile-file-upload.template.d.ts +7 -5
- package/dist/src/nile-file-upload/nile-file-upload.template.js +69 -115
- package/dist/src/nile-file-upload/nile-file-upload.template.js.map +1 -1
- package/dist/src/nile-file-upload/types/file-upload.enums.d.ts +11 -4
- package/dist/src/nile-file-upload/types/file-upload.enums.js +8 -1
- package/dist/src/nile-file-upload/types/file-upload.enums.js.map +1 -1
- package/dist/src/nile-file-upload/utils/drag-drop.util.d.ts +2 -4
- package/dist/src/nile-file-upload/utils/drag-drop.util.js +18 -21
- package/dist/src/nile-file-upload/utils/drag-drop.util.js.map +1 -1
- package/dist/src/nile-file-upload/utils/file-validation.util.d.ts +3 -1
- package/dist/src/nile-file-upload/utils/file-validation.util.js +82 -32
- package/dist/src/nile-file-upload/utils/file-validation.util.js.map +1 -1
- package/dist/src/nile-option/nile-option.d.ts +1 -0
- package/dist/src/nile-option/nile-option.js +6 -1
- package/dist/src/nile-option/nile-option.js.map +1 -1
- package/dist/src/nile-option-group/index.d.ts +1 -0
- package/dist/src/nile-option-group/index.js +2 -0
- package/dist/src/nile-option-group/index.js.map +1 -0
- package/dist/src/nile-option-group/nile-option-group.css.d.ts +12 -0
- package/dist/src/nile-option-group/nile-option-group.css.js +58 -0
- package/dist/src/nile-option-group/nile-option-group.css.js.map +1 -0
- package/dist/src/nile-option-group/nile-option-group.d.ts +23 -0
- package/dist/src/nile-option-group/nile-option-group.interface.d.ts +22 -0
- package/dist/src/nile-option-group/nile-option-group.interface.js +2 -0
- package/dist/src/nile-option-group/nile-option-group.interface.js.map +1 -0
- package/dist/src/nile-option-group/nile-option-group.js +76 -0
- package/dist/src/nile-option-group/nile-option-group.js.map +1 -0
- package/dist/src/nile-select/nile-select.d.ts +6 -0
- package/dist/src/nile-select/nile-select.interface.d.ts +5 -0
- package/dist/src/nile-select/nile-select.interface.js +2 -0
- package/dist/src/nile-select/nile-select.interface.js.map +1 -0
- package/dist/src/nile-select/nile-select.js +59 -1
- package/dist/src/nile-select/nile-select.js.map +1 -1
- package/dist/src/nile-table-body/nile-table-body.d.ts +1 -0
- package/dist/src/nile-table-body/nile-table-body.js +4 -0
- package/dist/src/nile-table-body/nile-table-body.js.map +1 -1
- package/dist/src/nile-table-cell-item/nile-table-cell-item.d.ts +2 -1
- package/dist/src/nile-table-cell-item/nile-table-cell-item.js +12 -1
- package/dist/src/nile-table-cell-item/nile-table-cell-item.js.map +1 -1
- package/dist/src/nile-table-header-item/nile-table-header-item.d.ts +2 -1
- package/dist/src/nile-table-header-item/nile-table-header-item.js +12 -1
- package/dist/src/nile-table-header-item/nile-table-header-item.js.map +1 -1
- package/dist/src/nile-virtual-select/renderer.js +3 -0
- package/dist/src/nile-virtual-select/renderer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/index.ts +1 -1
- package/src/internal/resizable-table-helper.ts +31 -8
- package/src/nile-code-editor/nile-code-editor.ts +49 -9
- package/src/nile-code-editor/theme.ts +19 -3
- package/src/nile-file-preview/nile-file-preview.css.ts +202 -183
- package/src/nile-file-preview/nile-file-preview.template.ts +66 -63
- package/src/nile-file-preview/nile-file-preview.ts +54 -22
- package/src/nile-file-preview/types/nile-file-preview.enums.ts +4 -3
- package/src/nile-file-preview/utils/nile-file-preview.util.ts +25 -0
- package/src/nile-file-upload/nile-file-upload.css.ts +141 -88
- package/src/nile-file-upload/nile-file-upload.template.ts +133 -121
- package/src/nile-file-upload/nile-file-upload.ts +30 -18
- package/src/nile-file-upload/types/file-upload.enums.ts +9 -2
- package/src/nile-file-upload/utils/drag-drop.util.ts +25 -25
- package/src/nile-file-upload/utils/file-validation.util.ts +98 -45
- package/src/nile-option/nile-option.ts +4 -1
- package/src/nile-option-group/index.ts +1 -0
- package/src/nile-option-group/nile-option-group.css.ts +60 -0
- package/src/nile-option-group/nile-option-group.interface.ts +25 -0
- package/src/nile-option-group/nile-option-group.ts +84 -0
- package/src/nile-select/nile-select.interface.ts +5 -0
- package/src/nile-select/nile-select.ts +74 -2
- package/src/nile-table-body/nile-table-body.ts +2 -0
- package/src/nile-table-cell-item/nile-table-cell-item.ts +15 -1
- package/src/nile-table-header-item/nile-table-header-item.ts +15 -1
- package/src/nile-virtual-select/renderer.ts +3 -0
- package/vscode-html-custom-data.json +49 -13
@@ -2,204 +2,216 @@ import { html, TemplateResult } from 'lit';
|
|
2
2
|
import './nile-file-upload.css';
|
3
3
|
import { DragHandler } from './utils/drag-drop.util';
|
4
4
|
import { classMap } from 'lit-html/directives/class-map.js';
|
5
|
-
import { FileUploadState } from './types/file-upload.enums';
|
5
|
+
import { FileUploadDefaults, FileUploadState } from './types/file-upload.enums';
|
6
|
+
import { truncateString } from './utils/file-validation.util';
|
7
|
+
import { NileFileUpload } from './nile-file-upload';
|
6
8
|
|
7
|
-
|
8
|
-
export const getDragHandler = (dragHandler: DragHandler): void => {
|
9
|
-
dragHandlerInstance = dragHandler;
|
10
|
-
}
|
11
|
-
|
12
|
-
export const getHorizontalDefaultState = (
|
9
|
+
const baseHorizontalState = (
|
13
10
|
browseFiles: Function,
|
14
11
|
title: string,
|
15
12
|
subtitle: string,
|
13
|
+
disabled: boolean,
|
14
|
+
dragHandler: DragHandler,
|
15
|
+
state: FileUploadState,
|
16
16
|
errorMessage: string,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
allowedTypes: string[],
|
18
|
+
nileFileUpload: NileFileUpload
|
19
|
+
): TemplateResult => {
|
20
|
+
truncateString(nileFileUpload);
|
21
|
+
return html`
|
22
|
+
<div class="wrapper" part="horizontal-wrapper">
|
23
|
+
<div part="horizontal-div" class=${classMap({ 'hover-border': state === "hover", 'horizontal-div': true, 'disable': disabled })}>
|
24
|
+
<div part="inner-div" class="inner-div">
|
25
|
+
<slot class="upload-icon-slot" name="upload-icon">
|
26
|
+
<nile-icon name="upload" size="24"></nile-icon>
|
24
27
|
</slot>
|
25
|
-
<div class="content">
|
26
|
-
<
|
27
|
-
|
28
|
-
</slot>
|
29
|
-
<slot name="subtitle">
|
30
|
-
<p>${subtitle}</p>
|
31
|
-
</slot>
|
28
|
+
<div part="content" class="content">
|
29
|
+
<div class="title">${title}</div>
|
30
|
+
<div class="subtitle">${subtitle}</div>
|
32
31
|
</div>
|
33
32
|
</div>
|
34
33
|
<input
|
35
34
|
type="file"
|
36
|
-
|
35
|
+
?disabled=${disabled}
|
36
|
+
@change=${(e: Event | DragEvent) => { dragHandler.handleFiles(e) }}
|
37
37
|
multiple
|
38
|
+
accept=${allowedTypes.join(',')}
|
38
39
|
/>
|
39
|
-
<slot @click=${browseFiles} name="
|
40
|
-
<nile-button variant="tertiary">
|
40
|
+
<slot class="browse-file-button" @click=${disabled ? undefined : browseFiles} name="browse-file-button">
|
41
|
+
<nile-button variant="tertiary" ?disabled=${disabled}>
|
41
42
|
Browse File
|
42
43
|
</nile-button>
|
43
44
|
</slot>
|
44
45
|
</div>
|
45
|
-
${errorMessage ?
|
46
|
+
${errorMessage || nileFileUpload.state === FileUploadState.ERROR ?
|
46
47
|
html`<div class="upload-error">
|
47
|
-
<nile-icon name="
|
48
|
-
|
48
|
+
<nile-icon name="warning" size="12" color="var(--nile-colors-red-700)"></nile-icon>
|
49
|
+
${
|
50
|
+
nileFileUpload.isStringTruncated
|
51
|
+
? html`<nile-tooltip content=${errorMessage || FileUploadDefaults.CUSTOM_ERROR}>
|
52
|
+
<span>${errorMessage || FileUploadDefaults.CUSTOM_ERROR}</span>
|
53
|
+
</nile-tooltip>`
|
54
|
+
: html`<span>${errorMessage || FileUploadDefaults.CUSTOM_ERROR}</span>`
|
55
|
+
}
|
49
56
|
</div>` :
|
50
57
|
html``
|
51
58
|
}
|
52
59
|
</div>
|
53
|
-
`;
|
60
|
+
`;
|
61
|
+
}
|
54
62
|
|
55
|
-
export const
|
63
|
+
export const getHorizontalDefaultState = (
|
56
64
|
browseFiles: Function,
|
57
65
|
title: string,
|
58
|
-
subtitle: string
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
`;
|
66
|
+
subtitle: string,
|
67
|
+
dragHandler: DragHandler,
|
68
|
+
state: FileUploadState,
|
69
|
+
errorMessage: string,
|
70
|
+
allowedTypes: string[],
|
71
|
+
nileFileUpload: NileFileUpload
|
72
|
+
): TemplateResult => baseHorizontalState(browseFiles, title, subtitle, false, dragHandler, state, errorMessage, allowedTypes, nileFileUpload);
|
73
|
+
|
74
|
+
export const getHorizontalDisabledState = (
|
75
|
+
browseFiles: Function,
|
76
|
+
title: string,
|
77
|
+
subtitle: string,
|
78
|
+
dragHandler: DragHandler,
|
79
|
+
state: FileUploadState,
|
80
|
+
errorMessage: string,
|
81
|
+
allowedTypes: string[],
|
82
|
+
nileFileUpload: NileFileUpload
|
83
|
+
): TemplateResult => baseHorizontalState(browseFiles, title, subtitle, true, dragHandler, state, errorMessage, allowedTypes, nileFileUpload);
|
84
|
+
|
85
|
+
export const getHorizontalErrorState = (
|
86
|
+
browseFiles: Function,
|
87
|
+
title: string,
|
88
|
+
subtitle: string,
|
89
|
+
dragHandler: DragHandler,
|
90
|
+
state: FileUploadState,
|
91
|
+
errorMessage: string,
|
92
|
+
allowedTypes: string[],
|
93
|
+
nileFileUpload: NileFileUpload
|
94
|
+
): TemplateResult => baseHorizontalState(browseFiles, title, subtitle, false, dragHandler, state, errorMessage, allowedTypes, nileFileUpload);
|
88
95
|
|
89
96
|
export const getHorizontalDragState = (): TemplateResult => html`
|
90
|
-
<div class="horizontal-div dragging">
|
97
|
+
<div part="horizontal-drag-state" class="horizontal-div dragging">
|
91
98
|
<div class="icons-container">
|
92
99
|
<nile-icon
|
93
100
|
color="var(--nile-colors-blue-500)"
|
94
|
-
name="
|
95
|
-
method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"
|
101
|
+
name="general"
|
96
102
|
size="20"
|
97
103
|
class="general-icon"
|
98
104
|
></nile-icon>
|
99
105
|
<nile-icon
|
100
106
|
color="var(--nile-colors-blue-500)"
|
101
|
-
name="
|
102
|
-
method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"
|
107
|
+
name="image"
|
103
108
|
size="24"
|
104
109
|
class="image-icon"
|
105
110
|
></nile-icon>
|
106
111
|
</div>
|
107
|
-
<p
|
112
|
+
<p>${FileUploadDefaults.DRAG_STATE_DEFAULT}</p>
|
108
113
|
</div>
|
109
114
|
`;
|
110
115
|
|
111
116
|
// Vertical States
|
112
|
-
|
117
|
+
const baseVerticalState = (
|
113
118
|
browseFiles: Function,
|
114
119
|
title: string,
|
115
120
|
subtitle: string,
|
121
|
+
disabled: boolean,
|
122
|
+
dragHandler: DragHandler,
|
116
123
|
errorMessage: string,
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
124
|
+
allowedTypes: string[],
|
125
|
+
nileFileUpload: NileFileUpload
|
126
|
+
): TemplateResult => {
|
127
|
+
truncateString(nileFileUpload);
|
128
|
+
return html`
|
129
|
+
<div part="vertical-wrapper" class="wrapper">
|
130
|
+
<div part="vertical-default" class="vertical-default vertical-div ${disabled ? 'disable' : ''}">
|
131
|
+
<slot name="upload-icon">
|
132
|
+
<nile-icon name="upload" size="24"></nile-icon>
|
123
133
|
</slot>
|
124
|
-
<div class="content-container">
|
125
|
-
<
|
126
|
-
|
127
|
-
</slot>
|
128
|
-
<slot name="subtitle">
|
129
|
-
<p>${subtitle}</p>
|
130
|
-
</slot>
|
134
|
+
<div part="vertical-content-container" class="content-container">
|
135
|
+
<div class="title">${title}</div>
|
136
|
+
<div class="subtitle">${subtitle}</div>
|
131
137
|
</div>
|
132
138
|
<input
|
133
139
|
type="file"
|
134
|
-
|
140
|
+
?disabled=${disabled}
|
141
|
+
@change=${(e: Event | DragEvent) => dragHandler.handleFiles(e)}
|
135
142
|
multiple
|
143
|
+
accept=${allowedTypes.join(',')}
|
136
144
|
/>
|
137
|
-
<slot @click=${browseFiles} name="
|
138
|
-
<nile-button variant="tertiary">
|
145
|
+
<slot @click=${disabled ? undefined : browseFiles} name="browse-file-button">
|
146
|
+
<nile-button variant="tertiary" ?disabled=${disabled}>
|
139
147
|
Browse File
|
140
148
|
</nile-button>
|
141
149
|
</slot>
|
142
150
|
</div>
|
143
|
-
${errorMessage ?
|
144
|
-
html`<div class="upload-error">
|
145
|
-
<nile-icon name="
|
146
|
-
|
151
|
+
${errorMessage || nileFileUpload.state === FileUploadState.ERROR ?
|
152
|
+
html`<div class="vertical-upload-error">
|
153
|
+
<nile-icon name="warning" size="12" color="var(--nile-colors-red-700)"></nile-icon>
|
154
|
+
${
|
155
|
+
nileFileUpload.isStringTruncated
|
156
|
+
? html`<nile-tooltip content=${errorMessage || FileUploadDefaults.CUSTOM_ERROR}>
|
157
|
+
<span>${errorMessage || FileUploadDefaults.CUSTOM_ERROR}</span>
|
158
|
+
</nile-tooltip>`
|
159
|
+
: html`<span>${errorMessage || FileUploadDefaults.CUSTOM_ERROR}</span>`
|
160
|
+
}
|
147
161
|
</div>` :
|
148
162
|
html``
|
149
163
|
}
|
150
164
|
</div>
|
151
|
-
`;
|
165
|
+
`;
|
166
|
+
}
|
167
|
+
|
168
|
+
export const getVerticalDefaultState = (
|
169
|
+
browseFiles: Function,
|
170
|
+
title: string,
|
171
|
+
subtitle: string,
|
172
|
+
dragHandler: DragHandler,
|
173
|
+
errorMessage: string,
|
174
|
+
allowedTypes: string[],
|
175
|
+
nileFileUpload: NileFileUpload
|
176
|
+
): TemplateResult => baseVerticalState(browseFiles, title, subtitle, false, dragHandler, errorMessage, allowedTypes, nileFileUpload);
|
152
177
|
|
153
178
|
export const getVerticalDisabledState = (
|
154
179
|
browseFiles: Function,
|
155
180
|
title: string,
|
156
|
-
subtitle: string
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
type="file"
|
174
|
-
@change=${(e: Event | DragEvent) => dragHandlerInstance.handleFiles(e)}
|
175
|
-
multiple
|
176
|
-
/>
|
177
|
-
<slot @click=${browseFiles} name="browseFileButton">
|
178
|
-
<nile-button variant="tertiary">
|
179
|
-
Browse File
|
180
|
-
</nile-button>
|
181
|
-
</slot>
|
182
|
-
</div>
|
183
|
-
`;
|
181
|
+
subtitle: string,
|
182
|
+
dragHandler: DragHandler,
|
183
|
+
errorMessage: string,
|
184
|
+
allowedTypes: string[],
|
185
|
+
nileFileUpload: NileFileUpload
|
186
|
+
): TemplateResult => baseVerticalState(browseFiles, title, subtitle, true, dragHandler, errorMessage, allowedTypes, nileFileUpload);
|
187
|
+
|
188
|
+
export const getVerticalErrorState = (
|
189
|
+
browseFiles: Function,
|
190
|
+
title: string,
|
191
|
+
subtitle: string,
|
192
|
+
dragHandler: DragHandler,
|
193
|
+
errorMessage: string,
|
194
|
+
allowedTypes: string[],
|
195
|
+
nileFileUpload: NileFileUpload
|
196
|
+
): TemplateResult => baseVerticalState(browseFiles, title, subtitle, false, dragHandler, errorMessage, allowedTypes, nileFileUpload);
|
197
|
+
|
184
198
|
|
185
199
|
export const getVerticalDragState = (): TemplateResult => html`
|
186
|
-
<div class="vertical-div vertical-drag">
|
200
|
+
<div part="vertical-drag-state" class="vertical-div vertical-drag">
|
187
201
|
<div class="icons-container">
|
188
202
|
<nile-icon
|
189
203
|
color="var(--nile-colors-blue-500)"
|
190
|
-
name="
|
191
|
-
method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"
|
204
|
+
name="general"
|
192
205
|
size="20"
|
193
206
|
class="general-icon"
|
194
207
|
></nile-icon>
|
195
208
|
<nile-icon
|
196
209
|
color="var(--nile-colors-blue-500)"
|
197
|
-
name="
|
198
|
-
method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"
|
210
|
+
name="image"
|
199
211
|
size="24"
|
200
212
|
class="image-icon"
|
201
213
|
></nile-icon>
|
202
214
|
</div>
|
203
|
-
<p
|
215
|
+
<p>${FileUploadDefaults.DRAG_STATE_DEFAULT}</p>
|
204
216
|
</div>
|
205
217
|
`;
|
@@ -9,7 +9,6 @@ import { styles } from './nile-file-upload.css';
|
|
9
9
|
import { ChangedPropsInterface } from './types/file-upload.type'
|
10
10
|
import NileElement from '../internal/nile-element';
|
11
11
|
import { DragHandler } from './utils/drag-drop.util';
|
12
|
-
import { getDragHandler } from './nile-file-upload.template'
|
13
12
|
import { FileUploadDefaults } from './types/file-upload.enums';
|
14
13
|
import { LitElement, html, CSSResultArray, TemplateResult } from 'lit';
|
15
14
|
import { customElement, property, query, state } from 'lit/decorators.js';
|
@@ -17,11 +16,13 @@ import { FileUploadState, FileUploadVariant, FileUploadError, FileUploadEvent }
|
|
17
16
|
import { setUpDragHandler, addGlobalListeners, addInternalListeners, uploadFiles, cancelFileUpload } from './utils/file-validation.util';
|
18
17
|
import {
|
19
18
|
getHorizontalDefaultState,
|
20
|
-
getHorizontalDisabledtState,
|
21
19
|
getHorizontalDragState,
|
22
20
|
getVerticalDefaultState,
|
23
21
|
getVerticalDisabledState,
|
24
22
|
getVerticalDragState,
|
23
|
+
getHorizontalErrorState,
|
24
|
+
getVerticalErrorState,
|
25
|
+
getHorizontalDisabledState
|
25
26
|
} from './nile-file-upload.template';
|
26
27
|
|
27
28
|
/**
|
@@ -40,11 +41,12 @@ export class NileFileUpload extends NileElement {
|
|
40
41
|
return [styles];
|
41
42
|
}
|
42
43
|
|
43
|
-
@property({ type:
|
44
|
+
@property({ type: String }) size: string = "10MB";
|
44
45
|
@property({ type: Boolean}) error: boolean = false;
|
45
46
|
@property({ type: String }) errorMessage: string = "";
|
46
|
-
@property({ type: Boolean}) allowMultiple: boolean =
|
47
|
+
@property({ type: Boolean}) allowMultiple: boolean = false;
|
47
48
|
@property({ type: Boolean}) allowDuplicates: boolean = false;
|
49
|
+
@property({ type: Array }) allowedTypes: string[] = [];
|
48
50
|
@property({ type: Array }) uploadedFiles: File[] = [];
|
49
51
|
@property({ type: String }) title: string = FileUploadDefaults.TITLE;
|
50
52
|
@property({ type: String }) subtitle: string = FileUploadDefaults.SUBTITLE;
|
@@ -54,6 +56,8 @@ export class NileFileUpload extends NileElement {
|
|
54
56
|
@property({ type: Boolean}) autoUpload: boolean = true;
|
55
57
|
@query('input') input!: HTMLInputElement;
|
56
58
|
public uploadRequests = new Map<File, XMLHttpRequest>();
|
59
|
+
public fileSizeExceededFilesNumber: number = 0;
|
60
|
+
public isStringTruncated: boolean = false;
|
57
61
|
|
58
62
|
private dragHandler!: DragHandler;
|
59
63
|
|
@@ -66,7 +70,6 @@ export class NileFileUpload extends NileElement {
|
|
66
70
|
super.firstUpdated(changedProps);
|
67
71
|
|
68
72
|
this.dragHandler = new DragHandler();
|
69
|
-
getDragHandler(this.dragHandler);
|
70
73
|
setUpDragHandler(this, this.dragHandler);
|
71
74
|
addInternalListeners(this, this.dragHandler, this.uploadRequests);
|
72
75
|
addGlobalListeners(this.dragHandler);
|
@@ -76,16 +79,19 @@ export class NileFileUpload extends NileElement {
|
|
76
79
|
super.updated(changedProps);
|
77
80
|
|
78
81
|
if (changedProps.has('uploadedFiles')) {
|
79
|
-
if(this.
|
80
|
-
|
81
|
-
this.errorMessage = FileUploadError.UPLOAD_URL_REQUIRED;
|
82
|
-
return;
|
82
|
+
if(this.fileUploadUrl && this.autoUpload) {
|
83
|
+
uploadFiles(this);
|
83
84
|
}
|
84
|
-
uploadFiles(this);
|
85
85
|
this.emit(FileUploadEvent.NILE_CHANGE, { files: this.uploadedFiles });
|
86
|
-
|
87
86
|
} else if (changedProps.has('state')) {
|
88
|
-
this.dragHandler.setValuesInDragHandler(this.state
|
87
|
+
this.dragHandler.setValuesInDragHandler(this.state);
|
88
|
+
}
|
89
|
+
|
90
|
+
if(changedProps.has('autoUpload') && this.autoUpload) {
|
91
|
+
if(this.fileUploadUrl && this.autoUpload) {
|
92
|
+
uploadFiles(this);
|
93
|
+
}
|
94
|
+
this.emit(FileUploadEvent.NILE_CHANGE, { files: this.uploadedFiles });
|
89
95
|
}
|
90
96
|
}
|
91
97
|
|
@@ -114,32 +120,38 @@ export class NileFileUpload extends NileElement {
|
|
114
120
|
private getHorizontalState(): TemplateResult {
|
115
121
|
switch(this.state) {
|
116
122
|
case FileUploadState.DEFAULT:
|
117
|
-
return getHorizontalDefaultState(this.browseFiles, this.title, this.subtitle, this.errorMessage, this.
|
123
|
+
return getHorizontalDefaultState(this.browseFiles, this.title, this.subtitle, this.dragHandler, this.state, this.errorMessage, this.allowedTypes, this);
|
118
124
|
|
119
125
|
case FileUploadState.DISABLED:
|
120
|
-
return
|
126
|
+
return getHorizontalDisabledState(this.browseFiles, this.title, this.subtitle, this.dragHandler, this.state, this.errorMessage, this.allowedTypes, this);
|
121
127
|
|
122
128
|
case FileUploadState.DRAG:
|
123
129
|
return getHorizontalDragState();
|
124
130
|
|
131
|
+
case FileUploadState.ERROR:
|
132
|
+
return getHorizontalErrorState(this.browseFiles, this.title, this.subtitle, this.dragHandler, this.state, this.errorMessage, this.allowedTypes, this);
|
133
|
+
|
125
134
|
default:
|
126
|
-
return getHorizontalDefaultState(this.browseFiles, this.title, this.subtitle, this.errorMessage, this.
|
135
|
+
return getHorizontalDefaultState(this.browseFiles, this.title, this.subtitle, this.dragHandler, this.state, this.errorMessage, this.allowedTypes, this);
|
127
136
|
}
|
128
137
|
}
|
129
138
|
|
130
139
|
private getVerticalState(): TemplateResult {
|
131
140
|
switch(this.state) {
|
132
141
|
case FileUploadState.DEFAULT:
|
133
|
-
return getVerticalDefaultState(this.browseFiles, this.title, this.subtitle, this.errorMessage, this.
|
142
|
+
return getVerticalDefaultState(this.browseFiles, this.title, this.subtitle, this.dragHandler, this.errorMessage, this.allowedTypes, this);
|
134
143
|
|
135
144
|
case FileUploadState.DISABLED:
|
136
|
-
return getVerticalDisabledState(this.browseFiles, this.title, this.subtitle);
|
145
|
+
return getVerticalDisabledState(this.browseFiles, this.title, this.subtitle, this.dragHandler, this.errorMessage, this.allowedTypes, this);
|
137
146
|
|
138
147
|
case FileUploadState.DRAG:
|
139
148
|
return getVerticalDragState();
|
140
149
|
|
150
|
+
case FileUploadState.ERROR:
|
151
|
+
return getVerticalErrorState(this.browseFiles, this.title, this.subtitle, this.dragHandler, this.errorMessage, this.allowedTypes, this);
|
152
|
+
|
141
153
|
default:
|
142
|
-
return getVerticalDefaultState(this.browseFiles, this.title, this.subtitle, this.errorMessage, this.
|
154
|
+
return getVerticalDefaultState(this.browseFiles, this.title, this.subtitle, this.dragHandler, this.errorMessage, this.allowedTypes, this);
|
143
155
|
}
|
144
156
|
}
|
145
157
|
|
@@ -2,7 +2,8 @@ export enum FileUploadState {
|
|
2
2
|
DEFAULT = 'default',
|
3
3
|
DISABLED = 'disabled',
|
4
4
|
HOVER = 'hover',
|
5
|
-
DRAG = 'drag'
|
5
|
+
DRAG = 'drag',
|
6
|
+
ERROR = 'error'
|
6
7
|
}
|
7
8
|
|
8
9
|
export enum FileUploadVariant {
|
@@ -12,10 +13,12 @@ export enum FileUploadVariant {
|
|
12
13
|
|
13
14
|
export enum FileUploadError {
|
14
15
|
INVALID_FORMAT = "Invalid file format! Upload valid file.",
|
15
|
-
|
16
|
+
SIZE_LIMIT_EXCEEDED = "File exceeds size limit! Upload smaller file.",
|
16
17
|
MULTIPLE_NOT_ALLOWED = "Please Upload Single File!",
|
17
18
|
DUPLICATES_NOT_ALLOWED = "Duplicate Files Are Not Allowed!",
|
18
19
|
UPLOAD_URL_REQUIRED = "Upload URL is required!",
|
20
|
+
SERVER_SIDE_ERROR = "Error from server! Please try again later.",
|
21
|
+
NETWORK_ERROR = "Network error! Please try again later."
|
19
22
|
}
|
20
23
|
|
21
24
|
export enum FileUploadEvent {
|
@@ -23,9 +26,11 @@ export enum FileUploadEvent {
|
|
23
26
|
NILE_BROWSE = "nile-browse",
|
24
27
|
NILE_DRAG = "nile-drag",
|
25
28
|
NILE_CHANGE = "nile-change",
|
29
|
+
NILE_UPLOADING = "nile-uploading",
|
26
30
|
NILE_UPLOAD_PROGRESS = "nile-upload-progress",
|
27
31
|
NILE_UPLOAD_SUCCESS = "nile-upload-success",
|
28
32
|
NILE_UPLOAD_CANCELLED = "nile-upload-cancelled",
|
33
|
+
NILE_SIZE_EXCEED_FILES = "nile-size-exceed-files",
|
29
34
|
NILE_CANCEL_UPLOAD = "nile-cancel-upload",
|
30
35
|
NILE_NETWORK_ERROR = "nile-network-error",
|
31
36
|
SERVER_SIDE_ERROR = "nile-server-error",
|
@@ -36,4 +41,6 @@ export enum FileUploadDefaults {
|
|
36
41
|
TITLE = 'Drag and drop to upload',
|
37
42
|
SUBTITLE = 'PNG, JPG or SVG (upto 1MB) | 1:1 ratio',
|
38
43
|
ERROR_MESSAGE = 'Invalid File Format.',
|
44
|
+
DRAG_STATE_DEFAULT = 'Drop files here to upload',
|
45
|
+
CUSTOM_ERROR = 'Error Occured!'
|
39
46
|
};
|
@@ -1,9 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { preventDefaultAndStopPropagation } from "./file-validation.util";
|
2
|
+
import { FileUploadState } from "../types";
|
2
3
|
|
3
4
|
export class DragHandler {
|
4
5
|
private currentState: FileUploadState = FileUploadState.DEFAULT;
|
5
|
-
private size: number = 0;
|
6
|
-
private uploadedFiles: File[] = [];
|
7
6
|
|
8
7
|
private stateChangeCallback?: (state: FileUploadState) => void;
|
9
8
|
private fileDropCallback?: (files: File[]) => void;
|
@@ -15,10 +14,8 @@ export class DragHandler {
|
|
15
14
|
this.errorMessageCallback = callback;
|
16
15
|
}
|
17
16
|
|
18
|
-
public setValuesInDragHandler(state: FileUploadState
|
17
|
+
public setValuesInDragHandler(state: FileUploadState): void {
|
19
18
|
this.currentState = state;
|
20
|
-
this.size = size;
|
21
|
-
this.uploadedFiles = uploadedFiles;
|
22
19
|
}
|
23
20
|
|
24
21
|
public onFileDrop(callback: (files: File[]) => void): void {
|
@@ -37,31 +34,31 @@ export class DragHandler {
|
|
37
34
|
}
|
38
35
|
|
39
36
|
public dragEnter(e: DragEvent): void {
|
40
|
-
|
37
|
+
preventDefaultAndStopPropagation(e);
|
41
38
|
|
42
|
-
|
39
|
+
if (this.currentState === FileUploadState.DISABLED) return;
|
43
40
|
this.errorMessageCallback?.("");
|
44
41
|
this.setState(FileUploadState.DRAG);
|
45
42
|
}
|
46
43
|
|
47
44
|
public dragLeave(e: DragEvent): void {
|
45
|
+
preventDefaultAndStopPropagation(e);
|
46
|
+
|
48
47
|
if (this.currentState === FileUploadState.DISABLED) return;
|
49
48
|
|
50
|
-
e.preventDefault();
|
51
49
|
this.setState(FileUploadState.DEFAULT);
|
52
50
|
}
|
53
51
|
|
54
52
|
public dragOver(e: DragEvent): void {
|
53
|
+
preventDefaultAndStopPropagation(e);
|
54
|
+
|
55
55
|
if (this.currentState === FileUploadState.DISABLED) return;
|
56
|
-
|
57
|
-
e.preventDefault();
|
58
56
|
}
|
59
57
|
|
60
58
|
public drop(e: DragEvent): void {
|
59
|
+
preventDefaultAndStopPropagation(e);
|
60
|
+
|
61
61
|
if (this.currentState === FileUploadState.DISABLED) return;
|
62
|
-
|
63
|
-
e.preventDefault();
|
64
|
-
e.stopPropagation();
|
65
62
|
this.setState(FileUploadState.DEFAULT);
|
66
63
|
this.handleFiles(e);
|
67
64
|
}
|
@@ -69,32 +66,31 @@ export class DragHandler {
|
|
69
66
|
public handleDocumentDrop(e: DragEvent): void {
|
70
67
|
if (this.currentState === FileUploadState.DISABLED) return;
|
71
68
|
|
72
|
-
e
|
73
|
-
|
69
|
+
preventDefaultAndStopPropagation(e);
|
70
|
+
|
74
71
|
this.setState(FileUploadState.DEFAULT);
|
75
72
|
}
|
76
73
|
|
77
74
|
public preventDragOver(e: DragEvent): void {
|
78
|
-
e
|
75
|
+
preventDefaultAndStopPropagation(e);
|
79
76
|
}
|
80
77
|
|
81
78
|
public preventDrop(e: DragEvent): void {
|
82
|
-
e
|
83
|
-
e.stopPropagation();
|
79
|
+
preventDefaultAndStopPropagation(e);
|
84
80
|
}
|
85
81
|
|
86
|
-
public handleFiles(
|
82
|
+
public handleFiles(e: Event | DragEvent): void {
|
83
|
+
preventDefaultAndStopPropagation(e);
|
87
84
|
if (this.currentState === FileUploadState.DISABLED) return;
|
88
85
|
|
89
|
-
event.preventDefault?.();
|
90
86
|
let files: FileList | null = null;
|
91
87
|
|
92
|
-
if ('dataTransfer' in
|
93
|
-
files =
|
88
|
+
if ('dataTransfer' in e && e.dataTransfer) {
|
89
|
+
files = e.dataTransfer.files;
|
94
90
|
}
|
95
91
|
|
96
|
-
if (!files &&
|
97
|
-
files =
|
92
|
+
if (!files && e.target instanceof HTMLInputElement) {
|
93
|
+
files = e.target.files;
|
98
94
|
}
|
99
95
|
|
100
96
|
if (files && files.length > 0) {
|
@@ -102,5 +98,9 @@ export class DragHandler {
|
|
102
98
|
|
103
99
|
this.fileDropCallback?.(newFiles);
|
104
100
|
}
|
101
|
+
|
102
|
+
if(e.target instanceof HTMLInputElement) {
|
103
|
+
e.target.value = "";
|
104
|
+
}
|
105
105
|
}
|
106
106
|
}
|