attachwave 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.
- checksums.yaml +7 -0
- data/app/assets/config/attachwave_manifest.js +2 -0
- data/app/assets/config/manifest.js +9 -0
- data/app/assets/javascripts/attachwave/attachwave.js +124 -0
- data/app/assets/javascripts/attachwave/controllers/filepond_controller.js +39 -0
- data/app/assets/javascripts/attachwave/controllers/index.js +6 -0
- data/app/assets/javascripts/attachwave/filepond-plugin-file-validate-size.min.js +9 -0
- data/app/assets/javascripts/attachwave/filepond-plugin-file-validate-type.js +231 -0
- data/app/assets/javascripts/attachwave/filepond-plugin-file-validate-type.min.js +9 -0
- data/app/assets/javascripts/attachwave/filepond.esm.js +9767 -0
- data/app/assets/javascripts/attachwave/filepond.esm.min.js +9 -0
- data/app/assets/javascripts/attachwave/filepond.js +12782 -0
- data/app/assets/javascripts/attachwave/filepond.min.js +9 -0
- data/app/assets/javascripts/attachwave/jquery.fileuploader.min.js +7 -0
- data/app/assets/stylesheets/attachwave/filepond.css +1049 -0
- data/app/assets/stylesheets/attachwave/filepond.min.css +8 -0
- data/app/assets/stylesheets/attachwave/jquery.fileuploader.min.css +8 -0
- data/app/controllers/attachwave/attachments_controller.rb +117 -0
- data/app/models/attachwave/adjunto.rb +78 -0
- data/app/uploaders/attachwave/attachments_uploader.rb +36 -0
- data/app/views/attachwave/attachments/_form.html.erb +12 -0
- data/app/views/attachwave/attachments/_form_simple.html.erb +20 -0
- data/app/views/attachwave/attachments/_index.html.erb +21 -0
- data/app/views/attachwave/attachments/_row.html.erb +26 -0
- data/app/views/attachwave/attachments/destroy.js.erb +5 -0
- data/app/views/attachwave/attachments/index.html.erb +11 -0
- data/app/views/attachwave/attachments/new.html.erb +1 -0
- data/app/views/attachwave/attachments/show.html.erb +1 -0
- data/config/routes.rb +22 -0
- data/lib/attachwave/engine.rb +66 -0
- data/lib/attachwave.rb +3 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1230691e6a9b38db9147f4b245eda8722e15c431b98813a2e85c7b96406a1db5
|
4
|
+
data.tar.gz: b6367e1e2218d5c1e85f8ede6062debf62dc67ef532932b065470986fc190e1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 891b690c3a0e7f6b5731090ae71423a728c89db6bd32c59950fa2c117b836cee9e2712d772b2cdaba8cbd68ad5cb171130dd3055800187d895444099733c8374
|
7
|
+
data.tar.gz: 01e8efe7cd9624f2d5a6cb625411f9601932b8115282e8a88bf375ab3b826274ff53b7067a0798fce0f3e0ad48afb7b985e652176a9910f6fa96415fdbb6ba68
|
@@ -0,0 +1,9 @@
|
|
1
|
+
//= link_directory ../javascripts/attachwave .js
|
2
|
+
//= link_directory ../stylesheets/attachwave .css
|
3
|
+
|
4
|
+
//= link attachwave/attachwave.js
|
5
|
+
//= link attachwave/filepond.min.js
|
6
|
+
//= link attachwave/filepond.min.css
|
7
|
+
//= link attachwave/filepond-plugin-file-validate-type.min.js
|
8
|
+
//= link attachwave/filepond-plugin-file-validate-size.min.js
|
9
|
+
//= link attachwave/controllers/filepond_controller.js
|
@@ -0,0 +1,124 @@
|
|
1
|
+
(function () {
|
2
|
+
console.log("📂 Attachwave inicializado (sin Stimulus)");
|
3
|
+
|
4
|
+
document.addEventListener("click", function (e) {
|
5
|
+
const btn = e.target.closest(".delete-attachment");
|
6
|
+
if (!btn) return;
|
7
|
+
|
8
|
+
e.preventDefault();
|
9
|
+
|
10
|
+
if (!confirm(btn.dataset.confirm || "¿Eliminar este archivo?")) return;
|
11
|
+
|
12
|
+
const id = btn.dataset.id;
|
13
|
+
const row = document.getElementById(`adjunto_${id}`);
|
14
|
+
|
15
|
+
// Marcar fila como "en proceso"
|
16
|
+
if (row) {
|
17
|
+
row.style.backgroundColor = "#f0f0f0"; // gris clarito
|
18
|
+
row.style.opacity = "0.6";
|
19
|
+
}
|
20
|
+
btn.disabled = true;
|
21
|
+
btn.textContent = "Eliminando…";
|
22
|
+
|
23
|
+
fetch(btn.href, {
|
24
|
+
method: "DELETE",
|
25
|
+
headers: {
|
26
|
+
"X-CSRF-Token": document.querySelector('meta[name="csrf-token"]').content,
|
27
|
+
"Accept": "application/json"
|
28
|
+
}
|
29
|
+
})
|
30
|
+
.then(resp => resp.json())
|
31
|
+
.then(data => {
|
32
|
+
if (data.success) {
|
33
|
+
if (row) row.remove();
|
34
|
+
} else {
|
35
|
+
alert(data.error || "❌ Error al eliminar el archivo.");
|
36
|
+
// restaurar estilos si falló
|
37
|
+
if (row) {
|
38
|
+
row.style.backgroundColor = "";
|
39
|
+
row.style.opacity = "1";
|
40
|
+
}
|
41
|
+
btn.disabled = false;
|
42
|
+
btn.textContent = "Eliminar";
|
43
|
+
}
|
44
|
+
})
|
45
|
+
.catch(err => {
|
46
|
+
console.error("Error:", err);
|
47
|
+
alert("❌ No se pudo eliminar el archivo.");
|
48
|
+
// restaurar estilos si falló
|
49
|
+
if (row) {
|
50
|
+
row.style.backgroundColor = "";
|
51
|
+
row.style.opacity = "1";
|
52
|
+
}
|
53
|
+
btn.disabled = false;
|
54
|
+
btn.textContent = "Eliminar";
|
55
|
+
});
|
56
|
+
});
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
function initFilepondUploader(el) {
|
63
|
+
const input = el.querySelector("input[type=file]");
|
64
|
+
if (!input) return;
|
65
|
+
|
66
|
+
if (typeof FilePond === "undefined") {
|
67
|
+
console.error("❌ Attachwave: FilePond no está cargado.");
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
|
71
|
+
// Registrar plugins
|
72
|
+
FilePond.registerPlugin(
|
73
|
+
FilePondPluginFileValidateType,
|
74
|
+
FilePondPluginFileValidateSize
|
75
|
+
);
|
76
|
+
|
77
|
+
// Crear instancia de FilePond
|
78
|
+
FilePond.create(input, {
|
79
|
+
allowMultiple: true,
|
80
|
+
server: {
|
81
|
+
process: {
|
82
|
+
url: el.dataset.uploadUrl,
|
83
|
+
headers: {
|
84
|
+
"X-CSRF-Token": document.querySelector(
|
85
|
+
'meta[name="csrf-token"]'
|
86
|
+
).content,
|
87
|
+
},
|
88
|
+
onload: () => {
|
89
|
+
console.info("✅ Archivo subido, refrescando tabla…");
|
90
|
+
const model = el.dataset.model;
|
91
|
+
const id = el.dataset.id;
|
92
|
+
|
93
|
+
fetch(`/attachwave/attachments/index/${model}/${id}`)
|
94
|
+
.then((resp) => resp.text())
|
95
|
+
.then((html) => {
|
96
|
+
const container = document.querySelector("#adjuntosTable");
|
97
|
+
if (container) container.innerHTML = html;
|
98
|
+
});
|
99
|
+
},
|
100
|
+
},
|
101
|
+
},
|
102
|
+
});
|
103
|
+
}
|
104
|
+
|
105
|
+
// Inicializar en todos los uploaders ya presentes
|
106
|
+
document.querySelectorAll("#filepond-uploader").forEach(initFilepondUploader);
|
107
|
+
|
108
|
+
// Escuchar cuando se agreguen dinámicamente al DOM
|
109
|
+
const observer = new MutationObserver((mutations) => {
|
110
|
+
mutations.forEach((m) => {
|
111
|
+
m.addedNodes.forEach((node) => {
|
112
|
+
if (
|
113
|
+
node.nodeType === 1 &&
|
114
|
+
node.matches &&
|
115
|
+
node.matches("#filepond-uploader")
|
116
|
+
) {
|
117
|
+
initFilepondUploader(node);
|
118
|
+
}
|
119
|
+
});
|
120
|
+
});
|
121
|
+
});
|
122
|
+
|
123
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
124
|
+
})();
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
2
|
+
import * as FilePond from "filepond";
|
3
|
+
import FilePondPluginFileValidateType from "filepond-plugin-file-validate-type";
|
4
|
+
import FilePondPluginFileValidateSize from "filepond-plugin-file-validate-size";
|
5
|
+
|
6
|
+
export default class extends Controller {
|
7
|
+
static values = { model: String, id: String }
|
8
|
+
|
9
|
+
connect() {
|
10
|
+
FilePond.registerPlugin(FilePondPluginFileValidateType, FilePondPluginFileValidateSize);
|
11
|
+
|
12
|
+
const inputElement = document.createElement("input");
|
13
|
+
inputElement.type = "file";
|
14
|
+
inputElement.multiple = true;
|
15
|
+
inputElement.name = "file";
|
16
|
+
this.element.appendChild(inputElement);
|
17
|
+
|
18
|
+
FilePond.create(inputElement, {
|
19
|
+
allowMultiple: true,
|
20
|
+
server: {
|
21
|
+
process: {
|
22
|
+
url: `/attachwave/attachments/direct_upload/${this.modelValue}/${this.idValue}`,
|
23
|
+
method: "POST",
|
24
|
+
headers: {
|
25
|
+
"X-CSRF-Token": document.querySelector('meta[name="csrf-token"]').getAttribute("content")
|
26
|
+
},
|
27
|
+
onload: () => {
|
28
|
+
fetch(`/attachwave/attachments/index/${this.modelValue}/${this.idValue}`)
|
29
|
+
.then(resp => resp.text())
|
30
|
+
.then(html => {
|
31
|
+
const container = document.querySelector("#adjuntosTable");
|
32
|
+
if (container) container.innerHTML = html;
|
33
|
+
});
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
});
|
38
|
+
}
|
39
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/*!
|
2
|
+
* FilePondPluginFileValidateSize 2.2.8
|
3
|
+
* Licensed under MIT, https://opensource.org/licenses/MIT/
|
4
|
+
* Please visit https://pqina.nl/filepond/ for details.
|
5
|
+
*/
|
6
|
+
|
7
|
+
/* eslint-disable */
|
8
|
+
|
9
|
+
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(e=e||self).FilePondPluginFileValidateSize=i()}(this,function(){"use strict";var e=function(e){var i=e.addFilter,E=e.utils,l=E.Type,_=E.replaceInString,n=E.toNaturalFileSize;return i("ALLOW_HOPPER_ITEM",function(e,i){var E=i.query;if(!E("GET_ALLOW_FILE_SIZE_VALIDATION"))return!0;var l=E("GET_MAX_FILE_SIZE");if(null!==l&&e.size>l)return!1;var _=E("GET_MIN_FILE_SIZE");return!(null!==_&&e.size<_)}),i("LOAD_FILE",function(e,i){var E=i.query;return new Promise(function(i,l){if(!E("GET_ALLOW_FILE_SIZE_VALIDATION"))return i(e);var I=E("GET_FILE_VALIDATE_SIZE_FILTER");if(I&&!I(e))return i(e);var t=E("GET_MAX_FILE_SIZE");if(null!==t&&e.size>t)l({status:{main:E("GET_LABEL_MAX_FILE_SIZE_EXCEEDED"),sub:_(E("GET_LABEL_MAX_FILE_SIZE"),{filesize:n(t,".",E("GET_FILE_SIZE_BASE"),E("GET_FILE_SIZE_LABELS",E))})}});else{var L=E("GET_MIN_FILE_SIZE");if(null!==L&&e.size<L)l({status:{main:E("GET_LABEL_MIN_FILE_SIZE_EXCEEDED"),sub:_(E("GET_LABEL_MIN_FILE_SIZE"),{filesize:n(L,".",E("GET_FILE_SIZE_BASE"),E("GET_FILE_SIZE_LABELS",E))})}});else{var a=E("GET_MAX_TOTAL_FILE_SIZE");if(null!==a)if(E("GET_ACTIVE_ITEMS").reduce(function(e,i){return e+i.fileSize},0)>a)return void l({status:{main:E("GET_LABEL_MAX_TOTAL_FILE_SIZE_EXCEEDED"),sub:_(E("GET_LABEL_MAX_TOTAL_FILE_SIZE"),{filesize:n(a,".",E("GET_FILE_SIZE_BASE"),E("GET_FILE_SIZE_LABELS",E))})}});i(e)}}})}),{options:{allowFileSizeValidation:[!0,l.BOOLEAN],maxFileSize:[null,l.INT],minFileSize:[null,l.INT],maxTotalFileSize:[null,l.INT],fileValidateSizeFilter:[null,l.FUNCTION],labelMinFileSizeExceeded:["File is too small",l.STRING],labelMinFileSize:["Minimum file size is {filesize}",l.STRING],labelMaxFileSizeExceeded:["File is too large",l.STRING],labelMaxFileSize:["Maximum file size is {filesize}",l.STRING],labelMaxTotalFileSizeExceeded:["Maximum total size exceeded",l.STRING],labelMaxTotalFileSize:["Maximum total file size is {filesize}",l.STRING]}}};return"undefined"!=typeof window&&void 0!==window.document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:e})),e});
|
@@ -0,0 +1,231 @@
|
|
1
|
+
/*!
|
2
|
+
* FilePondPluginFileValidateType 1.2.9
|
3
|
+
* Licensed under MIT, https://opensource.org/licenses/MIT/
|
4
|
+
* Please visit https://pqina.nl/filepond/ for details.
|
5
|
+
*/
|
6
|
+
|
7
|
+
/* eslint-disable */
|
8
|
+
|
9
|
+
(function(global, factory) {
|
10
|
+
typeof exports === 'object' && typeof module !== 'undefined'
|
11
|
+
? (module.exports = factory())
|
12
|
+
: typeof define === 'function' && define.amd
|
13
|
+
? define(factory)
|
14
|
+
: ((global = global || self), (global.FilePondPluginFileValidateType = factory()));
|
15
|
+
})(this, function() {
|
16
|
+
'use strict';
|
17
|
+
|
18
|
+
var plugin = function plugin(_ref) {
|
19
|
+
var addFilter = _ref.addFilter,
|
20
|
+
utils = _ref.utils;
|
21
|
+
// get quick reference to Type utils
|
22
|
+
var Type = utils.Type,
|
23
|
+
isString = utils.isString,
|
24
|
+
replaceInString = utils.replaceInString,
|
25
|
+
guesstimateMimeType = utils.guesstimateMimeType,
|
26
|
+
getExtensionFromFilename = utils.getExtensionFromFilename,
|
27
|
+
getFilenameFromURL = utils.getFilenameFromURL;
|
28
|
+
|
29
|
+
var mimeTypeMatchesWildCard = function mimeTypeMatchesWildCard(mimeType, wildcard) {
|
30
|
+
var mimeTypeGroup = (/^[^/]+/.exec(mimeType) || []).pop(); // image/png -> image
|
31
|
+
var wildcardGroup = wildcard.slice(0, -2); // image/* -> image
|
32
|
+
return mimeTypeGroup === wildcardGroup;
|
33
|
+
};
|
34
|
+
|
35
|
+
var isValidMimeType = function isValidMimeType(acceptedTypes, userInputType) {
|
36
|
+
return acceptedTypes.some(function(acceptedType) {
|
37
|
+
// accepted is wildcard mime type
|
38
|
+
if (/\*$/.test(acceptedType)) {
|
39
|
+
return mimeTypeMatchesWildCard(userInputType, acceptedType);
|
40
|
+
}
|
41
|
+
|
42
|
+
// is normal mime type
|
43
|
+
return acceptedType === userInputType;
|
44
|
+
});
|
45
|
+
};
|
46
|
+
|
47
|
+
var getItemType = function getItemType(item) {
|
48
|
+
// if the item is a url we guess the mime type by the extension
|
49
|
+
var type = '';
|
50
|
+
if (isString(item)) {
|
51
|
+
var filename = getFilenameFromURL(item);
|
52
|
+
var extension = getExtensionFromFilename(filename);
|
53
|
+
if (extension) {
|
54
|
+
type = guesstimateMimeType(extension);
|
55
|
+
}
|
56
|
+
} else {
|
57
|
+
type = item.type;
|
58
|
+
}
|
59
|
+
|
60
|
+
return type;
|
61
|
+
};
|
62
|
+
|
63
|
+
var validateFile = function validateFile(item, acceptedFileTypes, typeDetector) {
|
64
|
+
// no types defined, everything is allowed \o/
|
65
|
+
if (acceptedFileTypes.length === 0) {
|
66
|
+
return true;
|
67
|
+
}
|
68
|
+
|
69
|
+
// gets the item type
|
70
|
+
var type = getItemType(item);
|
71
|
+
|
72
|
+
// no type detector, test now
|
73
|
+
if (!typeDetector) {
|
74
|
+
return isValidMimeType(acceptedFileTypes, type);
|
75
|
+
}
|
76
|
+
|
77
|
+
// use type detector
|
78
|
+
return new Promise(function(resolve, reject) {
|
79
|
+
typeDetector(item, type)
|
80
|
+
.then(function(detectedType) {
|
81
|
+
if (isValidMimeType(acceptedFileTypes, detectedType)) {
|
82
|
+
resolve();
|
83
|
+
} else {
|
84
|
+
reject();
|
85
|
+
}
|
86
|
+
})
|
87
|
+
.catch(reject);
|
88
|
+
});
|
89
|
+
};
|
90
|
+
|
91
|
+
var applyMimeTypeMap = function applyMimeTypeMap(map) {
|
92
|
+
return function(acceptedFileType) {
|
93
|
+
return map[acceptedFileType] === null
|
94
|
+
? false
|
95
|
+
: map[acceptedFileType] || acceptedFileType;
|
96
|
+
};
|
97
|
+
};
|
98
|
+
|
99
|
+
// setup attribute mapping for accept
|
100
|
+
addFilter('SET_ATTRIBUTE_TO_OPTION_MAP', function(map) {
|
101
|
+
return Object.assign(map, {
|
102
|
+
accept: 'acceptedFileTypes',
|
103
|
+
});
|
104
|
+
});
|
105
|
+
|
106
|
+
// filtering if an item is allowed in hopper
|
107
|
+
addFilter('ALLOW_HOPPER_ITEM', function(file, _ref2) {
|
108
|
+
var query = _ref2.query;
|
109
|
+
// if we are not doing file type validation exit
|
110
|
+
if (!query('GET_ALLOW_FILE_TYPE_VALIDATION')) {
|
111
|
+
return true;
|
112
|
+
}
|
113
|
+
|
114
|
+
// we validate the file against the accepted file types
|
115
|
+
return validateFile(file, query('GET_ACCEPTED_FILE_TYPES'));
|
116
|
+
});
|
117
|
+
|
118
|
+
// called for each file that is loaded
|
119
|
+
// right before it is set to the item state
|
120
|
+
// should return a promise
|
121
|
+
addFilter('LOAD_FILE', function(file, _ref3) {
|
122
|
+
var query = _ref3.query;
|
123
|
+
return new Promise(function(resolve, reject) {
|
124
|
+
if (!query('GET_ALLOW_FILE_TYPE_VALIDATION')) {
|
125
|
+
resolve(file);
|
126
|
+
return;
|
127
|
+
}
|
128
|
+
|
129
|
+
var acceptedFileTypes = query('GET_ACCEPTED_FILE_TYPES');
|
130
|
+
|
131
|
+
// custom type detector method
|
132
|
+
var typeDetector = query('GET_FILE_VALIDATE_TYPE_DETECT_TYPE');
|
133
|
+
|
134
|
+
// if invalid, exit here
|
135
|
+
var validationResult = validateFile(file, acceptedFileTypes, typeDetector);
|
136
|
+
|
137
|
+
var handleRejection = function handleRejection() {
|
138
|
+
var acceptedFileTypesMapped = acceptedFileTypes
|
139
|
+
.map(
|
140
|
+
applyMimeTypeMap(
|
141
|
+
query('GET_FILE_VALIDATE_TYPE_LABEL_EXPECTED_TYPES_MAP')
|
142
|
+
)
|
143
|
+
)
|
144
|
+
.filter(function(label) {
|
145
|
+
return label !== false;
|
146
|
+
});
|
147
|
+
|
148
|
+
var acceptedFileTypesMappedUnique = acceptedFileTypesMapped.filter(function(
|
149
|
+
item,
|
150
|
+
index
|
151
|
+
) {
|
152
|
+
return acceptedFileTypesMapped.indexOf(item) === index;
|
153
|
+
});
|
154
|
+
|
155
|
+
reject({
|
156
|
+
status: {
|
157
|
+
main: query('GET_LABEL_FILE_TYPE_NOT_ALLOWED'),
|
158
|
+
sub: replaceInString(
|
159
|
+
query('GET_FILE_VALIDATE_TYPE_LABEL_EXPECTED_TYPES'),
|
160
|
+
{
|
161
|
+
allTypes: acceptedFileTypesMappedUnique.join(', '),
|
162
|
+
allButLastType: acceptedFileTypesMappedUnique
|
163
|
+
.slice(0, -1)
|
164
|
+
.join(', '),
|
165
|
+
lastType:
|
166
|
+
acceptedFileTypesMappedUnique[
|
167
|
+
acceptedFileTypesMappedUnique.length - 1
|
168
|
+
],
|
169
|
+
}
|
170
|
+
),
|
171
|
+
},
|
172
|
+
});
|
173
|
+
};
|
174
|
+
|
175
|
+
// has returned new filename immidiately
|
176
|
+
if (typeof validationResult === 'boolean') {
|
177
|
+
if (!validationResult) {
|
178
|
+
return handleRejection();
|
179
|
+
}
|
180
|
+
return resolve(file);
|
181
|
+
}
|
182
|
+
|
183
|
+
// is promise
|
184
|
+
validationResult
|
185
|
+
.then(function() {
|
186
|
+
resolve(file);
|
187
|
+
})
|
188
|
+
.catch(handleRejection);
|
189
|
+
});
|
190
|
+
});
|
191
|
+
|
192
|
+
// expose plugin
|
193
|
+
return {
|
194
|
+
// default options
|
195
|
+
options: {
|
196
|
+
// Enable or disable file type validation
|
197
|
+
allowFileTypeValidation: [true, Type.BOOLEAN],
|
198
|
+
|
199
|
+
// What file types to accept
|
200
|
+
acceptedFileTypes: [[], Type.ARRAY],
|
201
|
+
// - must be comma separated
|
202
|
+
// - mime types: image/png, image/jpeg, image/gif
|
203
|
+
// - extensions: .png, .jpg, .jpeg ( not enabled yet )
|
204
|
+
// - wildcards: image/*
|
205
|
+
|
206
|
+
// label to show when a type is not allowed
|
207
|
+
labelFileTypeNotAllowed: ['File is of invalid type', Type.STRING],
|
208
|
+
|
209
|
+
// nicer label
|
210
|
+
fileValidateTypeLabelExpectedTypes: [
|
211
|
+
'Expects {allButLastType} or {lastType}',
|
212
|
+
Type.STRING,
|
213
|
+
],
|
214
|
+
|
215
|
+
// map mime types to extensions
|
216
|
+
fileValidateTypeLabelExpectedTypesMap: [{}, Type.OBJECT],
|
217
|
+
|
218
|
+
// Custom function to detect type of file
|
219
|
+
fileValidateTypeDetectType: [null, Type.FUNCTION],
|
220
|
+
},
|
221
|
+
};
|
222
|
+
};
|
223
|
+
|
224
|
+
// fire pluginloaded event if running in browser, this allows registering the plugin when using async script tags
|
225
|
+
var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
226
|
+
if (isBrowser) {
|
227
|
+
document.dispatchEvent(new CustomEvent('FilePond:pluginloaded', { detail: plugin }));
|
228
|
+
}
|
229
|
+
|
230
|
+
return plugin;
|
231
|
+
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/*!
|
2
|
+
* FilePondPluginFileValidateType 1.2.9
|
3
|
+
* Licensed under MIT, https://opensource.org/licenses/MIT/
|
4
|
+
* Please visit https://pqina.nl/filepond/ for details.
|
5
|
+
*/
|
6
|
+
|
7
|
+
/* eslint-disable */
|
8
|
+
|
9
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).FilePondPluginFileValidateType=t()}(this,function(){"use strict";var e=function(e){var t=e.addFilter,n=e.utils,i=n.Type,T=n.isString,E=n.replaceInString,l=n.guesstimateMimeType,o=n.getExtensionFromFilename,r=n.getFilenameFromURL,u=function(e,t){return e.some(function(e){return/\*$/.test(e)?(n=e,(/^[^/]+/.exec(t)||[]).pop()===n.slice(0,-2)):e===t;var n})},a=function(e,t,n){if(0===t.length)return!0;var i=function(e){var t="";if(T(e)){var n=r(e),i=o(n);i&&(t=l(i))}else t=e.type;return t}(e);return n?new Promise(function(T,E){n(e,i).then(function(e){u(t,e)?T():E()}).catch(E)}):u(t,i)};return t("SET_ATTRIBUTE_TO_OPTION_MAP",function(e){return Object.assign(e,{accept:"acceptedFileTypes"})}),t("ALLOW_HOPPER_ITEM",function(e,t){var n=t.query;return!n("GET_ALLOW_FILE_TYPE_VALIDATION")||a(e,n("GET_ACCEPTED_FILE_TYPES"))}),t("LOAD_FILE",function(e,t){var n=t.query;return new Promise(function(t,i){if(n("GET_ALLOW_FILE_TYPE_VALIDATION")){var T=n("GET_ACCEPTED_FILE_TYPES"),l=n("GET_FILE_VALIDATE_TYPE_DETECT_TYPE"),o=a(e,T,l),r=function(){var e,t=T.map((e=n("GET_FILE_VALIDATE_TYPE_LABEL_EXPECTED_TYPES_MAP"),function(t){return null!==e[t]&&(e[t]||t)})).filter(function(e){return!1!==e}),l=t.filter(function(e,n){return t.indexOf(e)===n});i({status:{main:n("GET_LABEL_FILE_TYPE_NOT_ALLOWED"),sub:E(n("GET_FILE_VALIDATE_TYPE_LABEL_EXPECTED_TYPES"),{allTypes:l.join(", "),allButLastType:l.slice(0,-1).join(", "),lastType:l[l.length-1]})}})};if("boolean"==typeof o)return o?t(e):r();o.then(function(){t(e)}).catch(r)}else t(e)})}),{options:{allowFileTypeValidation:[!0,i.BOOLEAN],acceptedFileTypes:[[],i.ARRAY],labelFileTypeNotAllowed:["File is of invalid type",i.STRING],fileValidateTypeLabelExpectedTypes:["Expects {allButLastType} or {lastType}",i.STRING],fileValidateTypeLabelExpectedTypesMap:[{},i.OBJECT],fileValidateTypeDetectType:[null,i.FUNCTION]}}};return"undefined"!=typeof window&&void 0!==window.document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:e})),e});
|