@programmerg/bs-elements 0.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/LICENSE.md +9 -0
- package/README.md +148 -0
- package/custom-elements.json +7773 -0
- package/dist/bs-elements.bundle.min.js +8 -0
- package/dist/bs-elements.bundle.min.js.map +1 -0
- package/dist/bs-elements.esm.js +1721 -0
- package/dist/bs-elements.esm.js.map +1 -0
- package/dist/bs-elements.min.js +2 -0
- package/dist/bs-elements.min.js.map +1 -0
- package/package.json +50 -0
- package/src/base/BsAccordion.js +116 -0
- package/src/base/BsAlert.js +91 -0
- package/src/base/BsButton.js +129 -0
- package/src/base/BsCarousel.js +216 -0
- package/src/base/BsCollapse.js +84 -0
- package/src/base/BsDropdown.js +98 -0
- package/src/base/BsModal.js +204 -0
- package/src/base/BsOffcanvas.js +157 -0
- package/src/base/BsPopover.js +31 -0
- package/src/base/BsTab.js +69 -0
- package/src/base/BsToast.js +163 -0
- package/src/base/BsTooltip.js +118 -0
- package/src/core/BsElement.js +81 -0
- package/src/core/ReactiveElement.js +183 -0
- package/src/extra/BsCalendar.js +14 -0
- package/src/extra/BsCombobox.js +14 -0
- package/src/extra/BsForm.js +152 -0
- package/src/extra/BsInput.js +209 -0
- package/src/extra/BsTable.js +210 -0
- package/src/extra/BsTabs.js +0 -0
- package/src/extra/BsToastManager.js +0 -0
- package/src/extra/BsTree.js +14 -0
- package/src/extra/BsUploader.js +154 -0
- package/src/index.js +12 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import BsElement from '../core/BsElement';
|
|
2
|
+
import Resumable from 'resumablejs';
|
|
3
|
+
|
|
4
|
+
export class BsUploader extends BsElement {
|
|
5
|
+
|
|
6
|
+
static get properties() {
|
|
7
|
+
return {
|
|
8
|
+
state: {type: String},
|
|
9
|
+
progress: {type: Number},
|
|
10
|
+
action: {type: String},
|
|
11
|
+
_files: {state: true},
|
|
12
|
+
_uploadHandler: {state: false},
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static get bs() {
|
|
17
|
+
return Resumable;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
firstUpdated() {
|
|
21
|
+
this._ensureResumable();
|
|
22
|
+
|
|
23
|
+
return html`
|
|
24
|
+
<bs-input type="file" ?multiple=${this.multiple}>
|
|
25
|
+
Drop video files here to upload or
|
|
26
|
+
<a id="browseButton"><u>select from your computer</u></a>
|
|
27
|
+
</bs-input>
|
|
28
|
+
|
|
29
|
+
<div class="progress" style="display:none">
|
|
30
|
+
<table class="table table-sm">
|
|
31
|
+
<tr>
|
|
32
|
+
<td></td>
|
|
33
|
+
<td></td>
|
|
34
|
+
<td style="width:100px">
|
|
35
|
+
<div class="progress" role="progressbar" aria-valuenow="${(this.progress*100)}" aria-valuemin="0" aria-valuemax="100">
|
|
36
|
+
<div class="progress-bar" style="${'width: ' + (this.progress*100) + '%'}"></div>
|
|
37
|
+
</div>
|
|
38
|
+
</td>
|
|
39
|
+
<td>
|
|
40
|
+
<button type="button" class="btn btn-default btn-sm" style="${((this._uploadHandler.isUploading() || this.files.length < 1) ? 'display:none' : '')}" $click=${this._uploadHandler.upload()}>Start/Resume</button>
|
|
41
|
+
<button type="button" class="btn btn-default btn-sm" style="${(!this._uploadHandler.isUploading() ? 'display:none' : '')}" $click=${this._uploadHandler.pause()}>Pause</button>
|
|
42
|
+
<button type="button" class="btn btn-default btn-sm" style="${(!this._uploadHandler.isUploading() ? 'display:none' : '')}" $click=${this._uploadHandler.cancel()}>Stop</button>
|
|
43
|
+
</td>
|
|
44
|
+
</tr>
|
|
45
|
+
${this.renderFiles ? this.files.map(this._renderFile) : nothing}
|
|
46
|
+
</table>
|
|
47
|
+
</div>
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_renderFile(file) {
|
|
52
|
+
return html`
|
|
53
|
+
<tr>
|
|
54
|
+
<td>${file.fileName}</td>
|
|
55
|
+
<td>${file.size}</td>
|
|
56
|
+
<td>
|
|
57
|
+
${file.isUploading() ? html`
|
|
58
|
+
<div class="progress" role="progressbar" aria-valuenow="${(file.progress()*100)}" aria-valuemin="0" aria-valuemax="100">
|
|
59
|
+
<div class="progress-bar" style="${'width: ' + (file.progress()*100) + '%'}"></div>
|
|
60
|
+
</div>
|
|
61
|
+
` : nothing}
|
|
62
|
+
</td>
|
|
63
|
+
<td>
|
|
64
|
+
<button type="button" class="btn btn-default btn-sm" style="${((!file.isUploading() && !file.isComplete()) ? 'display:none' : '')}" $click=${file.retry()}>Retry</button>
|
|
65
|
+
<button type="button" class="btn btn-default btn-sm" style="${((file.isUploading() && !file.isComplete()) ? 'display:none' : '')}" $click=${file.abort()}>Abort</button>
|
|
66
|
+
<button type="button" class="btn btn-default btn-sm" style="${((file.isUploading() && !file.isComplete()) ? 'display:none' : '')}" $click=${file.cancel()}>Cancel</button>
|
|
67
|
+
</td>
|
|
68
|
+
</tr>
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_ensureResumable() {
|
|
73
|
+
let target = '';
|
|
74
|
+
const form = this.closest('form');
|
|
75
|
+
if (form && form.action) target = form.action;
|
|
76
|
+
|
|
77
|
+
const headers = {};
|
|
78
|
+
const jwtToken = localStorage.getItem('token');
|
|
79
|
+
if (jwtToken) headers["Authorization"] = "Bearer " + jwtToken;
|
|
80
|
+
|
|
81
|
+
const uploadHandler = new Resumable({
|
|
82
|
+
target: target,
|
|
83
|
+
chunkSize: 5*1024*1024,
|
|
84
|
+
forceChunkSize: false,
|
|
85
|
+
simultaneousUploads: 4,
|
|
86
|
+
fileParameterName: 'file',
|
|
87
|
+
chunkNumberParameterName: 'chunkNumber',
|
|
88
|
+
totalChunksParameterName: 'totalChunks',
|
|
89
|
+
chunkSizeParameterName: 'chunkSize',
|
|
90
|
+
totalSizeParameterName: 'totalSize',
|
|
91
|
+
identifierParameterName: 'identifier',
|
|
92
|
+
fileNameParameterName: 'filename',
|
|
93
|
+
relativePathParameterName: 'relativePath',
|
|
94
|
+
currentChunkSizeParameterName: 'currentChunkSize',
|
|
95
|
+
typeParameterName: 'type',
|
|
96
|
+
query: {_token: csrfToken},
|
|
97
|
+
uploadMethod: 'POST',
|
|
98
|
+
headers: headers,
|
|
99
|
+
method: 'multipart', // octet
|
|
100
|
+
testChunks: false,
|
|
101
|
+
maxFiles: undefined,
|
|
102
|
+
maxFilesErrorCallback: (files, errorCount) => {},
|
|
103
|
+
maxFileSize: 5*1024*1024*1204,
|
|
104
|
+
maxFileSizeErrorCallback: (file, errorCount) => {},
|
|
105
|
+
fileType: ["image/jpeg"], // any
|
|
106
|
+
fileTypeErrorCallback: (file, errorCount) => {},
|
|
107
|
+
maxChunkRetries: 3,
|
|
108
|
+
withCredentials: false, // send cookies?
|
|
109
|
+
setChunkTypeFromFile: false, // Set content-type from original file or application/octet-stream
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
uploadHandler.on('uploadStart', () => {
|
|
113
|
+
this.state = 'UPLOADING';
|
|
114
|
+
});
|
|
115
|
+
uploadHandler.on('progress', () => {
|
|
116
|
+
this.progress = uploadHandler.progress();
|
|
117
|
+
});
|
|
118
|
+
uploadHandler.on('pause', () => {
|
|
119
|
+
this.state = 'PAUSED';
|
|
120
|
+
});
|
|
121
|
+
uploadHandler.on('cancel', () => {
|
|
122
|
+
this.state = 'IDLE';
|
|
123
|
+
});
|
|
124
|
+
uploadHandler.on('complete', () => {
|
|
125
|
+
this.state = 'COMPLETED';
|
|
126
|
+
});
|
|
127
|
+
uploadHandler.on('error', (msg, file) => {
|
|
128
|
+
this.state = 'FAILED';
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
uploadHandler.on('fileAdded', (file, event) => {
|
|
132
|
+
this._files = [...uploadHandler.files];
|
|
133
|
+
});
|
|
134
|
+
uploadHandler.on('fileProgress', (file, message) => {
|
|
135
|
+
this._files = [...uploadHandler.files];
|
|
136
|
+
});
|
|
137
|
+
uploadHandler.on('fileRetry', (file) => {
|
|
138
|
+
this._files = [...uploadHandler.files];
|
|
139
|
+
});
|
|
140
|
+
uploadHandler.on('fileSuccess', (file, message) => {
|
|
141
|
+
this._files = [...uploadHandler.files];
|
|
142
|
+
});
|
|
143
|
+
uploadHandler.on('fileError', (file, message) => {
|
|
144
|
+
this._files = [...uploadHandler.files];
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
uploadHandler.assignBrowse(this.getElementById('browseButton'));
|
|
148
|
+
uploadHandler.assignDrop(this.getElementById('dropTarget'));
|
|
149
|
+
|
|
150
|
+
this._uploadHandler = uploadHandler;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
customElements.define('bs-uploader', BsUploader);
|
package/src/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { default as BsAccordion } from "./base/BsAccordion.js"
|
|
2
|
+
export { default as BsAlert } from "./base/BsAlert.js"
|
|
3
|
+
export { default as BsButton } from "./base/BsButton.js"
|
|
4
|
+
export { default as BsCarousel } from "./base/BsCarousel.js"
|
|
5
|
+
export { default as BsCollapse } from "./base/BsCollapse.js"
|
|
6
|
+
export { default as BsDropdown } from "./base/BsDropdown.js"
|
|
7
|
+
export { default as BsModal } from "./base/BsModal.js"
|
|
8
|
+
export { default as BsOffcanvas } from "./base/BsOffcanvas.js"
|
|
9
|
+
export { default as BsPopover } from "./base/BsPopover.js"
|
|
10
|
+
export { default as BsTab } from "./base/BsTab.js"
|
|
11
|
+
export { default as BsToast } from "./base/BsToast.js"
|
|
12
|
+
export { default as BsTooltip } from "./base/BsTooltip.js"
|