first commit

This commit is contained in:
2026-08-07 12:52:33 +09:00
commit 7fb30dcd0d
1409 changed files with 473704 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
/**
* BlobCache.js
*
* Released under LGPL License.
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
* Hold blob info objects where a blob has extra internal information.
*
* @private
* @class tinymce.file.BlobCache
*/
define("tinymce/file/BlobCache", [
"tinymce/util/Arr",
"tinymce/util/Fun"
], function(Arr, Fun) {
return function() {
var cache = [], constant = Fun.constant;
function create(id, blob, base64) {
return {
id: constant(id),
blob: constant(blob),
base64: constant(base64),
blobUri: constant(URL.createObjectURL(blob))
};
}
function add(blobInfo) {
if (!get(blobInfo.id())) {
cache.push(blobInfo);
}
}
function get(id) {
return findFirst(function(cachedBlobInfo) {
return cachedBlobInfo.id() === id;
});
}
function findFirst(predicate) {
return Arr.filter(cache, predicate)[0];
}
function getByUri(blobUri) {
return findFirst(function(blobInfo) {
return blobInfo.blobUri() == blobUri;
});
}
function destroy() {
Arr.each(cache, function(cachedBlobInfo) {
URL.revokeObjectURL(cachedBlobInfo.blobUri());
});
cache = [];
}
return {
create: create,
add: add,
get: get,
getByUri: getByUri,
findFirst: findFirst,
destroy: destroy
};
};
});

View File

@@ -0,0 +1,106 @@
/**
* Conversions.js
*
* Released under LGPL License.
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
* Converts blob/uris back and forth.
*
* @private
* @class tinymce.file.Conversions
*/
define("tinymce/file/Conversions", [
"tinymce/util/Promise"
], function(Promise) {
function blobUriToBlob(url) {
return new Promise(function(resolve) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = function() {
if (this.status == 200) {
resolve(this.response);
}
};
xhr.send();
});
}
function parseDataUri(uri) {
var type, matches;
uri = decodeURIComponent(uri).split(',');
matches = /data:([^;]+)/.exec(uri[0]);
if (matches) {
type = matches[1];
}
return {
type: type,
data: uri[1]
};
}
function dataUriToBlob(uri) {
return new Promise(function(resolve) {
var str, arr, i;
uri = parseDataUri(uri);
// Might throw error if data isn't proper base64
try {
str = atob(uri.data);
} catch (e) {
resolve(new Blob([]));
return;
}
arr = new Uint8Array(str.length);
for (i = 0; i < arr.length; i++) {
arr[i] = str.charCodeAt(i);
}
resolve(new Blob([arr], {type: uri.type}));
});
}
function uriToBlob(url) {
if (url.indexOf('blob:') === 0) {
return blobUriToBlob(url);
}
if (url.indexOf('data:') === 0) {
return dataUriToBlob(url);
}
return null;
}
function blobToDataUri(blob) {
return new Promise(function(resolve) {
var reader = new FileReader();
reader.onloadend = function() {
resolve(reader.result);
};
reader.readAsDataURL(blob);
});
}
return {
uriToBlob: uriToBlob,
blobToDataUri: blobToDataUri,
parseDataUri: parseDataUri
};
});

View File

@@ -0,0 +1,145 @@
/**
* ImageScanner.js
*
* Released under LGPL License.
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
* Finds images with data uris or blob uris. If data uris are found it will convert them into blob uris.
*
* @private
* @class tinymce.file.ImageScanner
*/
define("tinymce/file/ImageScanner", [
"tinymce/util/Promise",
"tinymce/util/Arr",
"tinymce/util/Fun",
"tinymce/file/Conversions",
"tinymce/Env"
], function(Promise, Arr, Fun, Conversions, Env) {
var count = 0;
return function(blobCache) {
var cachedPromises = {};
function findAll(elm, predicate) {
var images, promises;
function imageToBlobInfo(img, resolve) {
var base64, blobInfo;
if (img.src.indexOf('blob:') === 0) {
blobInfo = blobCache.getByUri(img.src);
if (blobInfo) {
resolve({
image: img,
blobInfo: blobInfo
});
}
return;
}
base64 = Conversions.parseDataUri(img.src).data;
blobInfo = blobCache.findFirst(function(cachedBlobInfo) {
return cachedBlobInfo.base64() === base64;
});
if (blobInfo) {
resolve({
image: img,
blobInfo: blobInfo
});
} else {
Conversions.uriToBlob(img.src).then(function(blob) {
var blobInfoId = 'blobid' + (count++),
blobInfo = blobCache.create(blobInfoId, blob, base64);
blobCache.add(blobInfo);
resolve({
image: img,
blobInfo: blobInfo
});
});
}
}
if (!predicate) {
predicate = Fun.constant(true);
}
images = Arr.filter(elm.getElementsByTagName('img'), function(img) {
var src = img.src;
if (!Env.fileApi) {
return false;
}
if (img.hasAttribute('data-mce-bogus')) {
return false;
}
if (img.hasAttribute('data-mce-placeholder')) {
return false;
}
if (!src || src == Env.transparentSrc) {
return false;
}
if (src.indexOf('blob:') === 0) {
return true;
}
if (src.indexOf('data:') === 0) {
return predicate(img);
}
return false;
});
promises = Arr.map(images, function(img) {
var newPromise;
if (cachedPromises[img.src]) {
// Since the cached promise will return the cached image
// We need to wrap it and resolve with the actual image
return new Promise(function(resolve) {
cachedPromises[img.src].then(function(imageInfo) {
resolve({
image: img,
blobInfo: imageInfo.blobInfo
});
});
});
}
newPromise = new Promise(function(resolve) {
imageToBlobInfo(img, resolve);
}).then(function(result) {
delete cachedPromises[result.image.src];
return result;
})['catch'](function(error) {
delete cachedPromises[img.src];
return error;
});
cachedPromises[img.src] = newPromise;
return newPromise;
});
return Promise.all(promises);
}
return {
findAll: findAll
};
};
});

View File

@@ -0,0 +1,179 @@
/**
* Uploader.js
*
* Released under LGPL License.
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
* Upload blobs or blob infos to the specified URL or handler.
*
* @private
* @class tinymce.file.Uploader
* @example
* var uploader = new Uploader({
* url: '/upload.php',
* basePath: '/base/path',
* credentials: true,
* handler: function(data, success, failure) {
* ...
* }
* });
*
* uploader.upload(blobInfos).then(function(result) {
* ...
* });
*/
define("tinymce/file/Uploader", [
"tinymce/util/Promise",
"tinymce/util/Tools",
"tinymce/util/Fun"
], function(Promise, Tools, Fun) {
return function(settings) {
var cachedPromises = {};
function fileName(blobInfo) {
var ext, extensions;
extensions = {
'image/jpeg': 'jpg',
'image/jpg': 'jpg',
'image/gif': 'gif',
'image/png': 'png'
};
ext = extensions[blobInfo.blob().type.toLowerCase()] || 'dat';
return blobInfo.id() + '.' + ext;
}
function pathJoin(path1, path2) {
if (path1) {
return path1.replace(/\/$/, '') + '/' + path2.replace(/^\//, '');
}
return path2;
}
function blobInfoToData(blobInfo) {
return {
id: blobInfo.id,
blob: blobInfo.blob,
base64: blobInfo.base64,
filename: Fun.constant(fileName(blobInfo))
};
}
function defaultHandler(blobInfo, success, failure, openNotification) {
var xhr, formData, notification;
xhr = new XMLHttpRequest();
xhr.open('POST', settings.url);
xhr.withCredentials = settings.credentials;
notification = openNotification();
xhr.upload.onprogress = function(e) {
var percentLoaded = Math.round(e.loaded / e.total * 100);
notification.progressBar.value(percentLoaded);
};
xhr.onload = function() {
var json;
notification.close();
if (xhr.status != 200) {
failure("HTTP Error: " + xhr.status);
return;
}
json = JSON.parse(xhr.responseText);
if (!json || typeof json.location != "string") {
failure("Invalid JSON: " + xhr.responseText);
return;
}
success(pathJoin(settings.basePath, json.location));
};
formData = new FormData();
formData.append('file', blobInfo.blob(), fileName(blobInfo));
xhr.send(formData);
}
function noUpload() {
return new Promise(function(resolve) {
resolve([]);
});
}
function interpretResult(promise) {
return promise.then(function(result) {
return result;
})['catch'](function(error) {
return error;
});
}
function registerPromise(handler, id, blobInfo) {
var response = handler(blobInfo);
var promise = interpretResult(response);
delete cachedPromises[id];
cachedPromises[id] = promise;
return promise;
}
function collectUploads(blobInfos, uploadBlobInfo) {
return Tools.map(blobInfos, function(blobInfo) {
var id = blobInfo.id();
return cachedPromises[id] ? cachedPromises[id] : registerPromise(uploadBlobInfo, id, blobInfo);
});
}
function uploadBlobs(blobInfos, openNotification) {
function uploadBlobInfo(blobInfo) {
return new Promise(function(resolve) {
var handler = settings.handler;
handler(blobInfoToData(blobInfo), function(url) {
resolve({
url: url,
blobInfo: blobInfo,
status: true
});
}, function(failure) {
resolve({
url: '',
blobInfo: blobInfo,
status: false,
error: failure
});
}, openNotification);
});
}
var promises = collectUploads(blobInfos, uploadBlobInfo);
return Promise.all(promises);
}
function upload(blobInfos, openNotification) {
return (!settings.url && settings.handler === defaultHandler) ? noUpload() : uploadBlobs(blobInfos, openNotification);
}
settings = Tools.extend({
credentials: false,
// We are adding a notify argument to this (at the moment, until it doesn't work)
handler: defaultHandler
}, settings);
return {
upload: upload
};
};
});