diff --git a/.gitignore b/.gitignore index 77d39444..ddab4e4a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ tests/_support/_generated/* tests/cache/* tests/error.log /crowdin.yaml +.vscode diff --git a/CHANGELOG.md b/CHANGELOG.md index da183e2e..9ab184f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.10.33.2 +## mm/dd/2022 + +1. [](#improved) + * Exposed `UriToMarkdown` util (`Grav.default.Utils.UriToMarkdown`) in admin, to convert links/images. + # v1.10.33.1 ## 04/25/2022 diff --git a/themes/grav/app/main.js b/themes/grav/app/main.js index 820c35d8..6edfca99 100644 --- a/themes/grav/app/main.js +++ b/themes/grav/app/main.js @@ -4,6 +4,7 @@ import '@babel/polyfill'; import $ from 'jquery'; import './utils/remodal'; import 'simplebar/dist/simplebar.min.js'; +import { UriToMarkdown } from './forms/fields/files.js'; import GPM, { Instance as gpm } from './utils/gpm'; import KeepAlive from './utils/keepalive'; import Updates, { Instance as updates, Notifications, Feed } from './updates'; @@ -68,5 +69,5 @@ export default { Instance: MediaFilterInstance }, Scrollbar: { Scrollbar: { deprecated: true }, Instance: { deprecated: true } }, - Utils: { request, toastr, Cookies } + Utils: { request, toastr, Cookies, UriToMarkdown } }; diff --git a/themes/grav/js/admin.min.js b/themes/grav/js/admin.min.js index a5583bad..3da9f860 100644 --- a/themes/grav/js/admin.min.js +++ b/themes/grav/js/admin.min.js @@ -711,6 +711,9 @@ var external_jQuery_default = /*#__PURE__*/__webpack_require__.n(external_jQuery }); // EXTERNAL MODULE: ./node_modules/simplebar/dist/simplebar.min.js var simplebar_min = __webpack_require__(85766); +// EXTERNAL MODULE: ./node_modules/dropzone/dist/dropzone.js +var dist_dropzone = __webpack_require__(32025); +var dropzone_default = /*#__PURE__*/__webpack_require__.n(dist_dropzone); // EXTERNAL MODULE: ./node_modules/toastr/toastr.js var toastr = __webpack_require__(8901); var toastr_default = /*#__PURE__*/__webpack_require__.n(toastr); @@ -847,17 +850,517 @@ function userFeedbackError(error) { external_jQuery_default()(__webpack_require__.g).on('beforeunload._ajax', function () { UNLOADING = true; }); +;// CONCATENATED MODULE: ./app/utils/request.js + + +var raw; + +var request = function request(url) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () { + return true; + }; + + if (typeof options === 'function') { + callback = options; + options = {}; + } + + if (options.method && options.method === 'post') { + var data = new FormData(); + options.body = Object.assign({ + 'admin-nonce': external_GravAdmin_namespaceObject.config.admin_nonce + }, options.body || {}); + Object.keys(options.body).map(function (key) { + return data.append(key, options.body[key]); + }); + options.body = data; + } + + options = Object.assign({ + credentials: 'same-origin', + headers: { + 'Accept': 'application/json' + } + }, options); + return fetch(url, options).then(function (response) { + raw = response; + return response; + }).then(parseStatus).then(parseJSON).then(userFeedback).then(function (response) { + return callback(response, raw); + })["catch"](userFeedbackError); +}; + +/* harmony default export */ const utils_request = (request); +;// CONCATENATED MODULE: ./app/forms/fields/files.js +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } + + + // import EXIF from 'exif-js'; + + + // translations + +var Dictionary = { + dictCancelUpload: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_CANCEL_UPLOAD, + dictCancelUploadConfirmation: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_CANCEL_UPLOAD_CONFIRMATION, + dictDefaultMessage: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_DEFAULT_MESSAGE, + dictFallbackMessage: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_FALLBACK_MESSAGE, + dictFallbackText: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_FALLBACK_TEXT, + dictFileTooBig: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_FILE_TOO_BIG, + dictInvalidFileType: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_INVALID_FILE_TYPE, + dictMaxFilesExceeded: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_MAX_FILES_EXCEEDED, + dictRemoveFile: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_REMOVE_FILE, + dictResponseError: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_RESPONSE_ERROR +}; +(dropzone_default()).autoDiscover = false; +(dropzone_default()).options.gravPageDropzone = {}; + +(dropzone_default()).confirm = function (question, accepted, rejected) { + var doc = external_jQuery_default()(document); + var modalSelector = '[data-remodal-id="delete-media"]'; + + var removeEvents = function removeEvents() { + doc.off('confirmation', modalSelector, accept); + doc.off('cancellation', modalSelector, reject); + external_jQuery_default()(modalSelector).find('.remodal-confirm').removeClass('pointer-events-disabled'); + }; + + var accept = function accept() { + accepted && accepted(); + removeEvents(); + }; + + var reject = function reject() { + rejected && rejected(); + removeEvents(); + }; + + (external_jQuery_default()).remodal.lookup[external_jQuery_default()(modalSelector).data('remodal')].open(); + doc.on('confirmation', modalSelector, accept); + doc.on('cancellation', modalSelector, reject); +}; + +var DropzoneMediaConfig = { + timeout: 0, + thumbnailWidth: 200, + thumbnailHeight: 150, + addRemoveLinks: false, + dictDefaultMessage: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROP_FILES_HERE_TO_UPLOAD.replace(/</g, '<').replace(/>/g, '>'), + dictRemoveFileConfirmation: '[placeholder]', + previewTemplate: "\n
\n
\n
\n
\n \n
\n
\n
\u2714
\n
\u2718
\n
\n ").concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.UNSET, "\n ").concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DELETE, "\n ").concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.METADATA, "\n ").concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.VIEW, "\n
").trim() +}; // global.EXIF = EXIF; + +var ACCEPT_FUNC = function ACCEPT_FUNC(file, done, settings) { + var resolution = settings.resolution; + if (!resolution) return done(); + var reader = new FileReader(); + var error = ''; + var hasMin = resolution.min && (resolution.min.width || resolution.min.height); + var hasMax = resolution.max && (resolution.max.width || resolution.max.height); + + if (hasMin || !(settings.resizeWidth || settings.resizeHeight) && hasMax) { + reader.onload = function (event) { + if (!/image\//.test(file.type)) { + done(); + return; + } + + var image = new Image(); + image.src = event.target.result; + + image.onerror = function () { + done(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.FILE_ERROR_UPLOAD); + }; + + image.onload = function () { + var _this = this; + + if (resolution.min) { + Object.keys(resolution.min).forEach(function (attr) { + if (resolution.min[attr] && _this[attr] < resolution.min[attr]) { + error += external_GravAdmin_namespaceObject.translations.PLUGIN_FORM.RESOLUTION_MIN.replace(/{{attr}}/g, attr).replace(/{{min}}/g, resolution.min[attr]); + } + }); + } + + if (!(settings.resizeWidth || settings.resizeHeight)) { + if (resolution.max) { + Object.keys(resolution.max).forEach(function (attr) { + if (resolution.max[attr] && _this[attr] > resolution.max[attr]) { + error += external_GravAdmin_namespaceObject.translations.PLUGIN_FORM.RESOLUTION_MAX.replace(/{{attr}}/g, attr).replace(/{{max}}/g, resolution.max[attr]); + } + }); + } + } + + URL.revokeObjectURL(image.src); // release memory + + return error ? done(error) : done(); + }; + }; + + reader.readAsDataURL(file); + } else { + return error ? done(error) : done(); + } +}; + +var FilesField = /*#__PURE__*/function () { + function FilesField() { + var _this2 = this; + + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$container = _ref.container, + container = _ref$container === void 0 ? '.dropzone.files-upload' : _ref$container, + _ref$options = _ref.options, + options = _ref$options === void 0 ? {} : _ref$options; + + _classCallCheck(this, FilesField); + + this.container = external_jQuery_default()(container); + + if (!this.container.length) { + return; + } + + this.urls = {}; + this.customPost = this.container.data('filePostAdd') || {}; + this.options = Object.assign({}, Dictionary, DropzoneMediaConfig, { + klass: this, + url: this.container.data('file-url-add') || external_GravAdmin_namespaceObject.config.current_url, + acceptedFiles: this.container.data('media-types'), + init: this.initDropzone + }, this.container.data('dropzone-options'), options); + this.options = Object.assign({}, this.options, { + accept: function accept(file, done) { + ACCEPT_FUNC(file, done, this.options); + } + }); + this.dropzone = new (dropzone_default())(container, this.options); + this.dropzone.on('complete', this.onDropzoneComplete.bind(this)); + this.dropzone.on('success', this.onDropzoneSuccess.bind(this)); + this.dropzone.on('addedfile', this.onDropzoneAddedFile.bind(this)); + this.dropzone.on('removedfile', this.onDropzoneRemovedFile.bind(this)); + this.dropzone.on('sending', this.onDropzoneSending.bind(this)); + this.dropzone.on('error', this.onDropzoneError.bind(this)); + this.container.on('mouseenter', '[data-dz-view]', function (e) { + var value = JSON.parse(_this2.container.find('[name][type="hidden"]').val() || '{}'); + var target = external_jQuery_default()(e.currentTarget); + var file = target.parent('.dz-preview').find('.dz-filename'); + var filename = encodeURI(file.text()); + var URL = Object.keys(value).filter(function (key) { + return value[key].name === filename; + }).shift(); + target.attr('href', "".concat(external_GravAdmin_namespaceObject.config.base_url_simple, "/").concat(URL)); + }); + } + + _createClass(FilesField, [{ + key: "initDropzone", + value: function initDropzone() { + var _this3 = this; + + var files = this.options.klass.container.find('[data-file]'); + var dropzone = this; + + if (!files.length) { + return; + } + + files.each(function (index, file) { + file = external_jQuery_default()(file); + var data = file.data('file'); + var mock = { + name: data.name, + size: data.size, + type: data.type, + status: (dropzone_default()).ADDED, + accepted: true, + url: _this3.options.url, + removeUrl: data.remove + }; + dropzone.files.push(mock); + dropzone.options.addedfile.call(dropzone, mock); + + if (mock.type.match(/^image\//)) { + dropzone.options.thumbnail.call(dropzone, mock, data.path); + dropzone.createThumbnailFromUrl(mock, data.path); + } + + file.remove(); + }); + } + }, { + key: "getURI", + value: function getURI() { + return this.container.data('mediaUri') || ''; + } + }, { + key: "onDropzoneSending", + value: function onDropzoneSending(file, xhr, formData) { + var _this4 = this; + + if (Object.keys(this.customPost).length) { + Object.keys(this.customPost).forEach(function (key) { + formData.append(key, _this4.customPost[key]); + }); + } else { + formData.append('name', this.options.dotNotation); + formData.append('task', 'filesupload'); + formData.append('uri', this.getURI()); + } + + formData.append('admin-nonce', external_GravAdmin_namespaceObject.config.admin_nonce); + } + }, { + key: "onDropzoneSuccess", + value: function onDropzoneSuccess(file, response, xhr) { + response = typeof response === 'string' ? JSON.parse(response) : response; + + if (this.options.reloadPage) { + __webpack_require__.g.location.reload(); + } // store params for removing file from session before it gets saved + + + if (response.session) { + file.sessionParams = response.session; + file.removeUrl = this.options.url; // Touch field value to force a mutation detection + + var input = this.container.find('[name][type="hidden"]'); + var value = input.val(); + input.val(value + ' '); + } + + return this.handleError({ + file: file, + data: response, + mode: 'removeFile', + msg: "

".concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.FILE_ERROR_UPLOAD, " {{fileName}}

\n
").concat(response.message, "
") + }); + } + }, { + key: "onDropzoneComplete", + value: function onDropzoneComplete(file) { + if (!file.accepted && !file.rejected) { + var data = { + status: 'error', + message: "".concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.FILE_UNSUPPORTED, ": ").concat(file.name.match(/\..+/).join('')) + }; + return this.handleError({ + file: file, + data: data, + mode: 'removeFile', + msg: "

".concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.FILE_ERROR_ADD, " {{fileName}}

\n
").concat(data.message, "
") + }); + } + + if (this.options.reloadPage) { + __webpack_require__.g.location.reload(); + } + } + }, { + key: "b64_to_utf8", + value: function b64_to_utf8(str) { + str = str.replace(/\s/g, ''); + return decodeURIComponent(escape(window.atob(str))); + } + }, { + key: "onDropzoneAddedFile", + value: function onDropzoneAddedFile(file) { + return this.dropzone.options.addedfile(file); + } + }, { + key: "onDropzoneRemovedFile", + value: function onDropzoneRemovedFile(file) { + var _this5 = this; + + if (!file.accepted || file.rejected) { + return; + } + + var url = file.removeUrl || this.urls["delete"] || this.options.url; + var path = (url || '').match(/path:(.*)\//); + var body = { + filename: file.name, + uri: this.getURI() + }; + + if (file.sessionParams) { + body.task = 'filessessionremove'; + body.session = file.sessionParams; + } + + var customPost = this.container.data('filePostRemove') || {}; + + if (Object.keys(customPost).length) { + body = {}; + Object.keys(customPost).forEach(function (key) { + body[key] = customPost[key]; + }); + } + + body['filename'] = file.name; + body['admin-nonce'] = external_GravAdmin_namespaceObject.config.admin_nonce; + utils_request(url, { + method: 'post', + body: body + }, function () { + if (!path) { + return; + } + + path = _this5.b64_to_utf8(path[1]); + + var input = _this5.container.find('[name][type="hidden"]'); + + var data = JSON.parse(input.val() || '{}'); + delete data[path]; + input.val(JSON.stringify(data)); + }); + } + }, { + key: "onDropzoneError", + value: function onDropzoneError(file, response, xhr) { + var message = xhr ? response.error.message : response; + external_jQuery_default()(file.previewElement).find('[data-dz-errormessage]').html(message); + return this.handleError({ + file: file, + data: { + status: 'error' + }, + msg: "
".concat(message, "
") + }); + } + }, { + key: "handleError", + value: function handleError(options) { + var file = options.file, + data = options.data, + mode = options.mode, + msg = options.msg; + + if (data.status !== 'error' && data.status !== 'unauthorized') { + return; + } + + switch (mode) { + case 'addBack': + if (file instanceof File) { + this.dropzone.addFile.call(this.dropzone, file); + } else { + this.dropzone.files.push(file); + this.dropzone.options.addedfile.call(this.dropzone, file); + this.dropzone.options.thumbnail.call(this.dropzone, file, file.extras.url); + } + + break; + + case 'removeFile': + default: + if (~this.dropzone.files.indexOf(file)) { + file.rejected = true; + this.dropzone.removeFile.call(this.dropzone, file, { + silent: true + }); + } + + break; + } + + var modal = external_jQuery_default()('[data-remodal-id="generic"]'); + var cleanName = file.name.replace('<', '<').replace('>', '>'); + modal.find('.error-content').html(msg.replace('{{fileName}}', cleanName)); + (external_jQuery_default()).remodal.lookup[modal.data('remodal')].open(); + } + }]); + + return FilesField; +}(); + + +function UriToMarkdown(uri) { + uri = uri.replace(/@3x|@2x|@1x/, ''); + uri = uri.replace(/\(/g, '%28'); + uri = uri.replace(/\)/g, '%29'); + var title = uri.split('.').slice(0, -1).join('.'); + return uri.match(/\.(jpe?g|png|gif|svg|webp|mp4|webm|ogv|mov)$/i) ? "![".concat(title, "](").concat(uri, " \"").concat(title, "\")") : "[".concat(decodeURI(uri), "](").concat(uri, ")"); +} +var instances = []; +var cache = external_jQuery_default()(); + +var onAddedNodes = function onAddedNodes(event, target +/* , record, instance */ +) { + var files = external_jQuery_default()(target).find('.dropzone.files-upload'); + + if (!files.length) { + return; + } + + files.each(function (index, file) { + file = external_jQuery_default()(file); + + if (!~cache.index(file)) { + addNode(file); + } + }); +}; + +var addNode = function addNode(container) { + container = external_jQuery_default()(container); + var input = container.find('input[type="file"]'); + var settings = container.data('grav-file-settings') || {}; + + if (settings.accept && ~settings.accept.indexOf('*')) { + settings.accept = ['']; + } + + var options = { + url: container.data('file-url-add') || (container.closest('form').attr('action') || external_GravAdmin_namespaceObject.config.current_url) + '.json', + paramName: settings.paramName || 'file', + dotNotation: settings.name || 'file', + acceptedFiles: settings.accept ? settings.accept.join(',') : input.attr('accept') || container.data('media-types'), + maxFilesize: typeof settings.filesize !== 'undefined' ? settings.filesize : 256, + maxFiles: settings.limit || null, + resizeWidth: settings.resizeWidth || null, + resizeHeight: settings.resizeHeight || null, + resizeQuality: settings.resizeQuality || null, + resolution: settings.resolution || null, + accept: function accept(file, done) { + ACCEPT_FUNC(file, done, settings); + } + }; + cache = cache.add(container); + container = container[0]; + instances.push(new FilesField({ + container: container, + options: options + })); +}; + +var Instance = function () { + external_jQuery_default()('.dropzone.files-upload').each(function (i, container) { + return addNode(container); + }); + external_jQuery_default()('body').on('mutation._grav', onAddedNodes); + return instances; +}(); // EXTERNAL MODULE: ./node_modules/events/events.js var events = __webpack_require__(17187); var events_default = /*#__PURE__*/__webpack_require__.n(events); ;// CONCATENATED MODULE: ./app/utils/gpm.js function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function gpm_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } +function gpm_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } +function gpm_createClass(Constructor, protoProps, staticProps) { if (protoProps) gpm_defineProperties(Constructor.prototype, protoProps); if (staticProps) gpm_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } @@ -887,7 +1390,7 @@ var GPM = /*#__PURE__*/function (_EventEmitter) { var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'getUpdates'; - _classCallCheck(this, GPM); + gpm_classCallCheck(this, GPM); _this = _super.call(this); _this.payload = {}; @@ -896,7 +1399,7 @@ var GPM = /*#__PURE__*/function (_EventEmitter) { return _this; } - _createClass(GPM, [{ + gpm_createClass(GPM, [{ key: "setPayload", value: function setPayload() { var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; @@ -966,7 +1469,7 @@ var GPM = /*#__PURE__*/function (_EventEmitter) { }((events_default())); -var Instance = new GPM(); +var gpm_Instance = new GPM(); ;// CONCATENATED MODULE: ./app/utils/keepalive.js function keepalive_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -1032,48 +1535,6 @@ var KeepAlive = /*#__PURE__*/function () { // EXTERNAL MODULE: ./node_modules/mout/array/unique.js var unique = __webpack_require__(79863); var unique_default = /*#__PURE__*/__webpack_require__.n(unique); -;// CONCATENATED MODULE: ./app/utils/request.js - - -var raw; - -var request = function request(url) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () { - return true; - }; - - if (typeof options === 'function') { - callback = options; - options = {}; - } - - if (options.method && options.method === 'post') { - var data = new FormData(); - options.body = Object.assign({ - 'admin-nonce': external_GravAdmin_namespaceObject.config.admin_nonce - }, options.body || {}); - Object.keys(options.body).map(function (key) { - return data.append(key, options.body[key]); - }); - options.body = data; - } - - options = Object.assign({ - credentials: 'same-origin', - headers: { - 'Accept': 'application/json' - } - }, options); - return fetch(url, options).then(function (response) { - raw = response; - return response; - }).then(parseStatus).then(parseJSON).then(userFeedback).then(function (response) { - return callback(response, raw); - })["catch"](userFeedbackError); -}; - -/* harmony default export */ const utils_request = (request); ;// CONCATENATED MODULE: ./app/updates/notifications.js function notifications_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -1378,7 +1839,7 @@ external_jQuery_default()(document).on('click', '[data-refresh="feed"]', functio external_jQuery_default()('[data-gpm-checkupdates]').on('click', function () { var element = external_jQuery_default()(this); element.find('i').addClass('fa-spin'); - Instance.fetch(function (response) { + gpm_Instance.fetch(function (response) { element.find('i').removeClass('fa-spin'); var payload = response.payload; @@ -1492,7 +1953,7 @@ var Updates = /*#__PURE__*/function () { var _this = this; var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; - Instance.fetch(function (response) { + gpm_Instance.fetch(function (response) { return _this.setPayload(response); }, force); return this; @@ -1639,13 +2100,13 @@ var Updates = /*#__PURE__*/function () { var updates_Instance = new Updates(); // automatically refresh UI for updates (graph, sidebar, plugin/themes pages) after every fetch -Instance.on('fetched', function (response, raw) { +gpm_Instance.on('fetched', function (response, raw) { updates_Instance.setPayload(response.payload || {}); updates_Instance.grav().resources(); }); if (external_GravAdmin_namespaceObject.config.enable_auto_updates_check === '1') { - Instance.fetch(); + gpm_Instance.fetch(); } // EXTERNAL MODULE: ./node_modules/chartist/dist/chartist.js var chartist = __webpack_require__(69259); @@ -1792,7 +2253,7 @@ var UpdatesChart = /*#__PURE__*/function (_Chart) { return _this2.draw(data); }); - Instance.on('fetched', function (response) { + gpm_Instance.on('fetched', function (response) { if (!response.payload) { return; } @@ -2803,467 +3264,6 @@ var factory = function factory(window) { __webpack_require__.g.Cookies = __webpack_require__.g && cookies_typeof(__webpack_require__.g.document) === 'object' ? factory(__webpack_require__.g) : factory; /* harmony default export */ const cookies = (__webpack_require__.g.Cookies); -// EXTERNAL MODULE: ./node_modules/dropzone/dist/dropzone.js -var dist_dropzone = __webpack_require__(32025); -var dropzone_default = /*#__PURE__*/__webpack_require__.n(dist_dropzone); -;// CONCATENATED MODULE: ./app/forms/fields/files.js -function files_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function files_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function files_createClass(Constructor, protoProps, staticProps) { if (protoProps) files_defineProperties(Constructor.prototype, protoProps); if (staticProps) files_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } - - - // import EXIF from 'exif-js'; - - - // translations - -var Dictionary = { - dictCancelUpload: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_CANCEL_UPLOAD, - dictCancelUploadConfirmation: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_CANCEL_UPLOAD_CONFIRMATION, - dictDefaultMessage: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_DEFAULT_MESSAGE, - dictFallbackMessage: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_FALLBACK_MESSAGE, - dictFallbackText: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_FALLBACK_TEXT, - dictFileTooBig: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_FILE_TOO_BIG, - dictInvalidFileType: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_INVALID_FILE_TYPE, - dictMaxFilesExceeded: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_MAX_FILES_EXCEEDED, - dictRemoveFile: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_REMOVE_FILE, - dictResponseError: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROPZONE_RESPONSE_ERROR -}; -(dropzone_default()).autoDiscover = false; -(dropzone_default()).options.gravPageDropzone = {}; - -(dropzone_default()).confirm = function (question, accepted, rejected) { - var doc = external_jQuery_default()(document); - var modalSelector = '[data-remodal-id="delete-media"]'; - - var removeEvents = function removeEvents() { - doc.off('confirmation', modalSelector, accept); - doc.off('cancellation', modalSelector, reject); - external_jQuery_default()(modalSelector).find('.remodal-confirm').removeClass('pointer-events-disabled'); - }; - - var accept = function accept() { - accepted && accepted(); - removeEvents(); - }; - - var reject = function reject() { - rejected && rejected(); - removeEvents(); - }; - - (external_jQuery_default()).remodal.lookup[external_jQuery_default()(modalSelector).data('remodal')].open(); - doc.on('confirmation', modalSelector, accept); - doc.on('cancellation', modalSelector, reject); -}; - -var DropzoneMediaConfig = { - timeout: 0, - thumbnailWidth: 200, - thumbnailHeight: 150, - addRemoveLinks: false, - dictDefaultMessage: external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DROP_FILES_HERE_TO_UPLOAD.replace(/</g, '<').replace(/>/g, '>'), - dictRemoveFileConfirmation: '[placeholder]', - previewTemplate: "\n
\n
\n
\n
\n \n
\n
\n
\u2714
\n
\u2718
\n
\n ").concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.UNSET, "\n ").concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.DELETE, "\n ").concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.METADATA, "\n ").concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.VIEW, "\n
").trim() -}; // global.EXIF = EXIF; - -var ACCEPT_FUNC = function ACCEPT_FUNC(file, done, settings) { - var resolution = settings.resolution; - if (!resolution) return done(); - var reader = new FileReader(); - var error = ''; - var hasMin = resolution.min && (resolution.min.width || resolution.min.height); - var hasMax = resolution.max && (resolution.max.width || resolution.max.height); - - if (hasMin || !(settings.resizeWidth || settings.resizeHeight) && hasMax) { - reader.onload = function (event) { - if (!/image\//.test(file.type)) { - done(); - return; - } - - var image = new Image(); - image.src = event.target.result; - - image.onerror = function () { - done(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.FILE_ERROR_UPLOAD); - }; - - image.onload = function () { - var _this = this; - - if (resolution.min) { - Object.keys(resolution.min).forEach(function (attr) { - if (resolution.min[attr] && _this[attr] < resolution.min[attr]) { - error += external_GravAdmin_namespaceObject.translations.PLUGIN_FORM.RESOLUTION_MIN.replace(/{{attr}}/g, attr).replace(/{{min}}/g, resolution.min[attr]); - } - }); - } - - if (!(settings.resizeWidth || settings.resizeHeight)) { - if (resolution.max) { - Object.keys(resolution.max).forEach(function (attr) { - if (resolution.max[attr] && _this[attr] > resolution.max[attr]) { - error += external_GravAdmin_namespaceObject.translations.PLUGIN_FORM.RESOLUTION_MAX.replace(/{{attr}}/g, attr).replace(/{{max}}/g, resolution.max[attr]); - } - }); - } - } - - URL.revokeObjectURL(image.src); // release memory - - return error ? done(error) : done(); - }; - }; - - reader.readAsDataURL(file); - } else { - return error ? done(error) : done(); - } -}; - -var FilesField = /*#__PURE__*/function () { - function FilesField() { - var _this2 = this; - - var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, - _ref$container = _ref.container, - container = _ref$container === void 0 ? '.dropzone.files-upload' : _ref$container, - _ref$options = _ref.options, - options = _ref$options === void 0 ? {} : _ref$options; - - files_classCallCheck(this, FilesField); - - this.container = external_jQuery_default()(container); - - if (!this.container.length) { - return; - } - - this.urls = {}; - this.customPost = this.container.data('filePostAdd') || {}; - this.options = Object.assign({}, Dictionary, DropzoneMediaConfig, { - klass: this, - url: this.container.data('file-url-add') || external_GravAdmin_namespaceObject.config.current_url, - acceptedFiles: this.container.data('media-types'), - init: this.initDropzone - }, this.container.data('dropzone-options'), options); - this.options = Object.assign({}, this.options, { - accept: function accept(file, done) { - ACCEPT_FUNC(file, done, this.options); - } - }); - this.dropzone = new (dropzone_default())(container, this.options); - this.dropzone.on('complete', this.onDropzoneComplete.bind(this)); - this.dropzone.on('success', this.onDropzoneSuccess.bind(this)); - this.dropzone.on('addedfile', this.onDropzoneAddedFile.bind(this)); - this.dropzone.on('removedfile', this.onDropzoneRemovedFile.bind(this)); - this.dropzone.on('sending', this.onDropzoneSending.bind(this)); - this.dropzone.on('error', this.onDropzoneError.bind(this)); - this.container.on('mouseenter', '[data-dz-view]', function (e) { - var value = JSON.parse(_this2.container.find('[name][type="hidden"]').val() || '{}'); - var target = external_jQuery_default()(e.currentTarget); - var file = target.parent('.dz-preview').find('.dz-filename'); - var filename = encodeURI(file.text()); - var URL = Object.keys(value).filter(function (key) { - return value[key].name === filename; - }).shift(); - target.attr('href', "".concat(external_GravAdmin_namespaceObject.config.base_url_simple, "/").concat(URL)); - }); - } - - files_createClass(FilesField, [{ - key: "initDropzone", - value: function initDropzone() { - var _this3 = this; - - var files = this.options.klass.container.find('[data-file]'); - var dropzone = this; - - if (!files.length) { - return; - } - - files.each(function (index, file) { - file = external_jQuery_default()(file); - var data = file.data('file'); - var mock = { - name: data.name, - size: data.size, - type: data.type, - status: (dropzone_default()).ADDED, - accepted: true, - url: _this3.options.url, - removeUrl: data.remove - }; - dropzone.files.push(mock); - dropzone.options.addedfile.call(dropzone, mock); - - if (mock.type.match(/^image\//)) { - dropzone.options.thumbnail.call(dropzone, mock, data.path); - dropzone.createThumbnailFromUrl(mock, data.path); - } - - file.remove(); - }); - } - }, { - key: "getURI", - value: function getURI() { - return this.container.data('mediaUri') || ''; - } - }, { - key: "onDropzoneSending", - value: function onDropzoneSending(file, xhr, formData) { - var _this4 = this; - - if (Object.keys(this.customPost).length) { - Object.keys(this.customPost).forEach(function (key) { - formData.append(key, _this4.customPost[key]); - }); - } else { - formData.append('name', this.options.dotNotation); - formData.append('task', 'filesupload'); - formData.append('uri', this.getURI()); - } - - formData.append('admin-nonce', external_GravAdmin_namespaceObject.config.admin_nonce); - } - }, { - key: "onDropzoneSuccess", - value: function onDropzoneSuccess(file, response, xhr) { - response = typeof response === 'string' ? JSON.parse(response) : response; - - if (this.options.reloadPage) { - __webpack_require__.g.location.reload(); - } // store params for removing file from session before it gets saved - - - if (response.session) { - file.sessionParams = response.session; - file.removeUrl = this.options.url; // Touch field value to force a mutation detection - - var input = this.container.find('[name][type="hidden"]'); - var value = input.val(); - input.val(value + ' '); - } - - return this.handleError({ - file: file, - data: response, - mode: 'removeFile', - msg: "

".concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.FILE_ERROR_UPLOAD, " {{fileName}}

\n
").concat(response.message, "
") - }); - } - }, { - key: "onDropzoneComplete", - value: function onDropzoneComplete(file) { - if (!file.accepted && !file.rejected) { - var data = { - status: 'error', - message: "".concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.FILE_UNSUPPORTED, ": ").concat(file.name.match(/\..+/).join('')) - }; - return this.handleError({ - file: file, - data: data, - mode: 'removeFile', - msg: "

".concat(external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.FILE_ERROR_ADD, " {{fileName}}

\n
").concat(data.message, "
") - }); - } - - if (this.options.reloadPage) { - __webpack_require__.g.location.reload(); - } - } - }, { - key: "b64_to_utf8", - value: function b64_to_utf8(str) { - str = str.replace(/\s/g, ''); - return decodeURIComponent(escape(window.atob(str))); - } - }, { - key: "onDropzoneAddedFile", - value: function onDropzoneAddedFile(file) { - return this.dropzone.options.addedfile(file); - } - }, { - key: "onDropzoneRemovedFile", - value: function onDropzoneRemovedFile(file) { - var _this5 = this; - - if (!file.accepted || file.rejected) { - return; - } - - var url = file.removeUrl || this.urls["delete"] || this.options.url; - var path = (url || '').match(/path:(.*)\//); - var body = { - filename: file.name, - uri: this.getURI() - }; - - if (file.sessionParams) { - body.task = 'filessessionremove'; - body.session = file.sessionParams; - } - - var customPost = this.container.data('filePostRemove') || {}; - - if (Object.keys(customPost).length) { - body = {}; - Object.keys(customPost).forEach(function (key) { - body[key] = customPost[key]; - }); - } - - body['filename'] = file.name; - body['admin-nonce'] = external_GravAdmin_namespaceObject.config.admin_nonce; - utils_request(url, { - method: 'post', - body: body - }, function () { - if (!path) { - return; - } - - path = _this5.b64_to_utf8(path[1]); - - var input = _this5.container.find('[name][type="hidden"]'); - - var data = JSON.parse(input.val() || '{}'); - delete data[path]; - input.val(JSON.stringify(data)); - }); - } - }, { - key: "onDropzoneError", - value: function onDropzoneError(file, response, xhr) { - var message = xhr ? response.error.message : response; - external_jQuery_default()(file.previewElement).find('[data-dz-errormessage]').html(message); - return this.handleError({ - file: file, - data: { - status: 'error' - }, - msg: "
".concat(message, "
") - }); - } - }, { - key: "handleError", - value: function handleError(options) { - var file = options.file, - data = options.data, - mode = options.mode, - msg = options.msg; - - if (data.status !== 'error' && data.status !== 'unauthorized') { - return; - } - - switch (mode) { - case 'addBack': - if (file instanceof File) { - this.dropzone.addFile.call(this.dropzone, file); - } else { - this.dropzone.files.push(file); - this.dropzone.options.addedfile.call(this.dropzone, file); - this.dropzone.options.thumbnail.call(this.dropzone, file, file.extras.url); - } - - break; - - case 'removeFile': - default: - if (~this.dropzone.files.indexOf(file)) { - file.rejected = true; - this.dropzone.removeFile.call(this.dropzone, file, { - silent: true - }); - } - - break; - } - - var modal = external_jQuery_default()('[data-remodal-id="generic"]'); - var cleanName = file.name.replace('<', '<').replace('>', '>'); - modal.find('.error-content').html(msg.replace('{{fileName}}', cleanName)); - (external_jQuery_default()).remodal.lookup[modal.data('remodal')].open(); - } - }]); - - return FilesField; -}(); - - -function UriToMarkdown(uri) { - uri = uri.replace(/@3x|@2x|@1x/, ''); - uri = uri.replace(/\(/g, '%28'); - uri = uri.replace(/\)/g, '%29'); - var title = uri.split('.').slice(0, -1).join('.'); - return uri.match(/\.(jpe?g|png|gif|svg|webp|mp4|webm|ogv|mov)$/i) ? "![".concat(title, "](").concat(uri, " \"").concat(title, "\")") : "[".concat(decodeURI(uri), "](").concat(uri, ")"); -} -var instances = []; -var cache = external_jQuery_default()(); - -var onAddedNodes = function onAddedNodes(event, target -/* , record, instance */ -) { - var files = external_jQuery_default()(target).find('.dropzone.files-upload'); - - if (!files.length) { - return; - } - - files.each(function (index, file) { - file = external_jQuery_default()(file); - - if (!~cache.index(file)) { - addNode(file); - } - }); -}; - -var addNode = function addNode(container) { - container = external_jQuery_default()(container); - var input = container.find('input[type="file"]'); - var settings = container.data('grav-file-settings') || {}; - - if (settings.accept && ~settings.accept.indexOf('*')) { - settings.accept = ['']; - } - - var options = { - url: container.data('file-url-add') || (container.closest('form').attr('action') || external_GravAdmin_namespaceObject.config.current_url) + '.json', - paramName: settings.paramName || 'file', - dotNotation: settings.name || 'file', - acceptedFiles: settings.accept ? settings.accept.join(',') : input.attr('accept') || container.data('media-types'), - maxFilesize: typeof settings.filesize !== 'undefined' ? settings.filesize : 256, - maxFiles: settings.limit || null, - resizeWidth: settings.resizeWidth || null, - resizeHeight: settings.resizeHeight || null, - resizeQuality: settings.resizeQuality || null, - resolution: settings.resolution || null, - accept: function accept(file, done) { - ACCEPT_FUNC(file, done, settings); - } - }; - cache = cache.add(container); - container = container[0]; - instances.push(new FilesField({ - container: container, - options: options - })); -}; - -var files_Instance = function () { - external_jQuery_default()('.dropzone.files-upload').each(function (i, container) { - return addNode(container); - }); - external_jQuery_default()('body').on('mutation._grav', onAddedNodes); - return instances; -}(); ;// CONCATENATED MODULE: ./app/forms/fields/editor/buttons.js @@ -9751,7 +9751,7 @@ external_jQuery_default()('[data-grav-elements] select').trigger('change'); }, FilesField: { FilesField: FilesField, - Instance: files_Instance + Instance: Instance }, FolderField: { Regenerate: fields_folder @@ -10119,7 +10119,7 @@ var Packages = /*#__PURE__*/function () { var current_version = ''; var available_version = ''; var _name = ''; - var resources = Instance.payload.payload.resources; + var resources = gpm_Instance.payload.payload.resources; if (resources.plugins[slug]) { available_version = resources.plugins[slug].available; @@ -10314,7 +10314,7 @@ var Packages = /*#__PURE__*/function () { var current_version = ''; var available_version = ''; var _name2 = ''; - var resources = Instance.payload.payload.resources; + var resources = gpm_Instance.payload.payload.resources; if (resources.plugins[slug]) { available_version = resources.plugins[slug].available; @@ -11799,6 +11799,7 @@ var sidebar_Instance = new Sidebar(); + // bootstrap jQuery extensions @@ -11823,7 +11824,7 @@ external_jQuery_default()(__webpack_require__.g).on('sidebar_state._grav', funct /* harmony default export */ const main = ({ GPM: { GPM: GPM, - Instance: Instance + Instance: gpm_Instance }, KeepAlive: keepalive, Dashboard: dashboard, @@ -11854,7 +11855,8 @@ external_jQuery_default()(__webpack_require__.g).on('sidebar_state._grav', funct Utils: { request: utils_request, toastr: utils_toastr, - Cookies: cookies + Cookies: cookies, + UriToMarkdown: UriToMarkdown } });