vendor: 13,782 bytes, lines 1-458
1/*! 2 * FilePondPluginImageEdit 1.6.3 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.FilePondPluginImageEdit = factory())); 15})(this, function() { 16 'use strict'; 17 18 var isPreviewableImage = function isPreviewableImage(file) { 19 return /^image/.test(file.type); 20 }; 21 22 /** 23 * Image Edit Proxy Plugin 24 */ 25 var plugin = function plugin(_) { 26 var addFilter = _.addFilter, 27 utils = _.utils, 28 views = _.views; 29 var Type = utils.Type, 30 createRoute = utils.createRoute, 31 _utils$createItemAPI = utils.createItemAPI, 32 createItemAPI = 33 _utils$createItemAPI === void 0 34 ? function(item) { 35 return item; 36 } 37 : _utils$createItemAPI; 38 var fileActionButton = views.fileActionButton; 39 40 addFilter('SHOULD_REMOVE_ON_REVERT', function(shouldRemove, _ref) { 41 var item = _ref.item, 42 query = _ref.query; 43 return new Promise(function(resolve) { 44 var file = item.file; 45 46 // if this file is editable it shouldn't be removed immidiately even when instant uploading 47 var canEdit = 48 query('GET_ALLOW_IMAGE_EDIT') && 49 query('GET_IMAGE_EDIT_ALLOW_EDIT') && 50 isPreviewableImage(file); 51 52 // if the file cannot be edited it should be removed on revert 53 resolve(!canEdit); 54 }); 55 }); 56 57 // open editor when loading a new item 58 addFilter('DID_LOAD_ITEM', function(item, _ref2) { 59 var query = _ref2.query, 60 dispatch = _ref2.dispatch; 61 return new Promise(function(resolve, reject) { 62 // if is temp or local file 63 if (item.origin > 1) { 64 resolve(item); 65 return; 66 } 67 68 // get file reference 69 var file = item.file; 70 if ( 71 !query('GET_ALLOW_IMAGE_EDIT') || 72 !query('GET_IMAGE_EDIT_INSTANT_EDIT') 73 ) { 74 resolve(item); 75 return; 76 } 77 78 // exit if this is not an image 79 if (!isPreviewableImage(file)) { 80 resolve(item); 81 return; 82 } 83 84 var createEditorResponseHandler = function createEditorResponseHandler( 85 item, 86 resolve, 87 reject 88 ) { 89 return function(userDidConfirm) { 90 // remove item 91 editRequestQueue.shift(); 92 93 // handle item 94 if (userDidConfirm) { 95 resolve(item); 96 } else { 97 reject(item); 98 } 99 100 // TODO: Fix, should not be needed to kick the internal loop in case no processes are running 101 dispatch('KICK'); 102 103 // handle next item! 104 requestEdit(); 105 }; 106 }; 107 108 var requestEdit = function requestEdit() { 109 if (!editRequestQueue.length) return; 110 var _editRequestQueue$ = editRequestQueue[0], 111 item = _editRequestQueue$.item, 112 resolve = _editRequestQueue$.resolve, 113 reject = _editRequestQueue$.reject; 114 115 dispatch('EDIT_ITEM', { 116 id: item.id, 117 handleEditorResponse: createEditorResponseHandler( 118 item, 119 resolve, 120 reject 121 ) 122 }); 123 }; 124 125 queueEditRequest({ item: item, resolve: resolve, reject: reject }); 126 127 if (editRequestQueue.length === 1) { 128 requestEdit(); 129 } 130 }); 131 }); 132 133 // extend item methods 134 addFilter('DID_CREATE_ITEM', function(item, _ref3) { 135 var query = _ref3.query, 136 dispatch = _ref3.dispatch; 137 item.extend('edit', function() { 138 dispatch('EDIT_ITEM', { id: item.id }); 139 }); 140 }); 141 142 var editRequestQueue = []; 143 var queueEditRequest = function queueEditRequest(editRequest) { 144 editRequestQueue.push(editRequest); 145 return editRequest; 146 }; 147 148 // called for each view that is created right after the 'create' method 149 addFilter('CREATE_VIEW', function(viewAPI) { 150 // get reference to created view 151 var is = viewAPI.is, 152 view = viewAPI.view, 153 query = viewAPI.query; 154 155 if (!query('GET_ALLOW_IMAGE_EDIT')) return; 156 157 var canShowImagePreview = query('GET_ALLOW_IMAGE_PREVIEW'); 158 159 // only run for either the file or the file info panel 160 var shouldExtendView = 161 (is('file-info') && !canShowImagePreview) || 162 (is('file') && canShowImagePreview); 163 164 if (!shouldExtendView) return; 165 166 // no editor defined, then exit 167 var editor = query('GET_IMAGE_EDIT_EDITOR'); 168 if (!editor) return; 169 170 // set default FilePond options and add bridge once 171 if (!editor.filepondCallbackBridge) { 172 editor.outputData = true; 173 editor.outputFile = false; 174 editor.filepondCallbackBridge = { 175 onconfirm: editor.onconfirm || function() {}, 176 oncancel: editor.oncancel || function() {} 177 }; 178 } 179 180 // opens the editor, if it does not already exist, it creates the editor 181 var openEditor = function openEditor(_ref4) { 182 var root = _ref4.root, 183 props = _ref4.props, 184 action = _ref4.action; 185 var id = props.id; 186 var handleEditorResponse = action.handleEditorResponse; 187 188 // update editor props that could have changed 189 editor.cropAspectRatio = 190 root.query('GET_IMAGE_CROP_ASPECT_RATIO') || editor.cropAspectRatio; 191 editor.outputCanvasBackgroundColor = 192 root.query('GET_IMAGE_TRANSFORM_CANVAS_BACKGROUND_COLOR') || 193 editor.outputCanvasBackgroundColor; 194 195 // get item 196 var item = root.query('GET_ITEM', id); 197 if (!item) return; 198 199 // file to open 200 var file = item.file; 201 202 // crop data to pass to editor 203 var crop = item.getMetadata('crop'); 204 var cropDefault = { 205 center: { 206 x: 0.5, 207 y: 0.5 208 }, 209 210 flip: { 211 horizontal: false, 212 vertical: false 213 }, 214 215 zoom: 1, 216 rotation: 0, 217 aspectRatio: null 218 }; 219 220 // size data to pass to editor 221 var resize = item.getMetadata('resize'); 222 223 // filter and color data to pass to editor 224 var filter = item.getMetadata('filter') || null; 225 var filters = item.getMetadata('filters') || null; 226 var colors = item.getMetadata('colors') || null; 227 var markup = item.getMetadata('markup') || null; 228 229 // build parameters object 230 var imageParameters = { 231 crop: crop || cropDefault, 232 size: resize 233 ? { 234 upscale: resize.upscale, 235 mode: resize.mode, 236 width: resize.size.width, 237 height: resize.size.height 238 } 239 : null, 240 filter: filters 241 ? filters.id || filters.matrix 242 : root.query('GET_ALLOW_IMAGE_FILTER') && 243 root.query('GET_IMAGE_FILTER_COLOR_MATRIX') && 244 !colors 245 ? filter 246 : null, 247 color: colors, 248 markup: markup 249 }; 250 251 editor.onconfirm = function(_ref5) { 252 var data = _ref5.data; 253 var crop = data.crop, 254 size = data.size, 255 filter = data.filter, 256 color = data.color, 257 colorMatrix = data.colorMatrix, 258 markup = data.markup; 259 260 // create new metadata object 261 var metadata = {}; 262 263 // append crop data 264 if (crop) { 265 metadata.crop = crop; 266 } 267 268 // append size data 269 if (size) { 270 var initialSize = (item.getMetadata('resize') || {}).size; 271 var targetSize = { 272 width: size.width, 273 height: size.height 274 }; 275 276 if (!(targetSize.width && targetSize.height) && initialSize) { 277 targetSize.width = initialSize.width; 278 targetSize.height = initialSize.height; 279 } 280 281 if (targetSize.width || targetSize.height) { 282 metadata.resize = { 283 upscale: size.upscale, 284 mode: size.mode, 285 size: targetSize 286 }; 287 } 288 } 289 290 if (markup) { 291 metadata.markup = markup; 292 } 293 294 // set filters and colors so we can restore them when re-editing the image 295 metadata.colors = color; 296 metadata.filters = filter; 297 298 // set merged color matrix to use in preview plugin 299 metadata.filter = colorMatrix; 300 301 // update crop metadata 302 item.setMetadata(metadata); 303 304 // call 305 editor.filepondCallbackBridge.onconfirm(data, createItemAPI(item)); 306 307 // used in instant edit mode 308 if (!handleEditorResponse) return; 309 editor.onclose = function() { 310 handleEditorResponse(true); 311 editor.onclose = null; 312 }; 313 }; 314 315 editor.oncancel = function() { 316 // call 317 editor.filepondCallbackBridge.oncancel(createItemAPI(item)); 318 319 // used in instant edit mode 320 if (!handleEditorResponse) return; 321 editor.onclose = function() { 322 handleEditorResponse(false); 323 editor.onclose = null; 324 }; 325 }; 326 327 editor.open(file, imageParameters); 328 }; 329 330 /** 331 * Image Preview related 332 */ 333 334 // create the image edit plugin, but only do so if the item is an image 335 var didLoadItem = function didLoadItem(_ref6) { 336 var root = _ref6.root, 337 props = _ref6.props; 338 339 if (!query('GET_IMAGE_EDIT_ALLOW_EDIT')) return; 340 var id = props.id; 341 342 // try to access item 343 var item = query('GET_ITEM', id); 344 if (!item) return; 345 346 // get the file object 347 var file = item.file; 348 349 // exit if this is not an image 350 if (!isPreviewableImage(file)) return; 351 352 // handle interactions 353 root.ref.handleEdit = function(e) { 354 e.stopPropagation(); 355 root.dispatch('EDIT_ITEM', { id: id }); 356 }; 357 358 if (canShowImagePreview) { 359 // add edit button to preview 360 var buttonView = view.createChildView(fileActionButton, { 361 label: 'edit', 362 icon: query('GET_IMAGE_EDIT_ICON_EDIT'), 363 opacity: 0 364 }); 365 366 // edit item classname 367 buttonView.element.classList.add('filepond--action-edit-item'); 368 buttonView.element.dataset.align = query( 369 'GET_STYLE_IMAGE_EDIT_BUTTON_EDIT_ITEM_POSITION' 370 ); 371 buttonView.on('click', root.ref.handleEdit); 372 373 root.ref.buttonEditItem = view.appendChildView(buttonView); 374 } else { 375 // view is file info 376 var filenameElement = view.element.querySelector( 377 '.filepond--file-info-main' 378 ); 379 var editButton = document.createElement('button'); 380 editButton.className = 'filepond--action-edit-item-alt'; 381 editButton.innerHTML = 382 query('GET_IMAGE_EDIT_ICON_EDIT') + '<span>edit</span>'; 383 editButton.addEventListener('click', root.ref.handleEdit); 384 filenameElement.appendChild(editButton); 385 386 root.ref.editButton = editButton; 387 } 388 }; 389 390 view.registerDestroyer(function(_ref7) { 391 var root = _ref7.root; 392 if (root.ref.buttonEditItem) { 393 root.ref.buttonEditItem.off('click', root.ref.handleEdit); 394 } 395 if (root.ref.editButton) { 396 root.ref.editButton.removeEventListener('click', root.ref.handleEdit); 397 } 398 }); 399 400 var routes = { 401 EDIT_ITEM: openEditor, 402 DID_LOAD_ITEM: didLoadItem 403 }; 404 405 if (canShowImagePreview) { 406 // view is file 407 var didPreviewUpdate = function didPreviewUpdate(_ref8) { 408 var root = _ref8.root; 409 if (!root.ref.buttonEditItem) return; 410 root.ref.buttonEditItem.opacity = 1; 411 }; 412 413 routes.DID_IMAGE_PREVIEW_SHOW = didPreviewUpdate; 414 } else { 415 } 416 417 // start writing 418 view.registerWriter(createRoute(routes)); 419 }); 420 421 // Expose plugin options 422 return { 423 options: { 424 // enable or disable image editing 425 allowImageEdit: [true, Type.BOOLEAN], 426 427 // location of processing button 428 styleImageEditButtonEditItemPosition: ['bottom center', Type.STRING], 429 430 // open editor when image is dropped 431 imageEditInstantEdit: [false, Type.BOOLEAN], 432 433 // allow editing 434 imageEditAllowEdit: [true, Type.BOOLEAN], 435 436 // the icon to use for the edit button 437 imageEditIconEdit: [ 438 '<svg width="26" height="26" viewBox="0 0 26 26" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M8.5 17h1.586l7-7L15.5 8.414l-7 7V17zm-1.707-2.707l8-8a1 1 0 0 1 1.414 0l3 3a1 1 0 0 1 0 1.414l-8 8A1 1 0 0 1 10.5 19h-3a1 1 0 0 1-1-1v-3a1 1 0 0 1 .293-.707z" fill="currentColor" fill-rule="nonzero"/></svg>', 439 Type.STRING 440 ], 441 442 // editor object 443 imageEditEditor: [null, Type.OBJECT] 444 } 445 }; 446 }; 447 448 // fire pluginloaded event if running in browser, this allows registering the plugin when using async script tags 449 var isBrowser = 450 typeof window !== 'undefined' && typeof window.document !== 'undefined'; 451 if (isBrowser) { 452 document.dispatchEvent( 453 new CustomEvent('FilePond:pluginloaded', { detail: plugin }) 454 ); 455 } 456 457 return plugin; 458});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.