inital commit

This commit is contained in:
2026-01-01 15:25:19 +05:30
commit f0ae49465a
36361 changed files with 4894111 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* @module modules/uploader
*/
import type { BuildDataResult, IDictionary, IUploader } from "../../../types/index";
export declare function buildData(uploader: IUploader, data: FormData | IDictionary<string> | string): BuildDataResult;

View File

@@ -0,0 +1,27 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
import { isFunction, isString } from "../../../core/helpers/index.js";
export function buildData(uploader, data) {
if (isFunction(uploader.o.buildData)) {
return uploader.o.buildData.call(uploader, data);
}
const FD = uploader.ow.FormData;
if (FD !== undefined) {
if (data instanceof FD) {
return data;
}
if (isString(data)) {
return data;
}
const newData = new FD();
const dict = data;
Object.keys(dict).forEach(key => {
newData.append(key, dict[key]);
});
return newData;
}
return data;
}

View File

@@ -0,0 +1,12 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* @module modules/uploader
*/
/**
* Convert dataURI to Blob
*/
export declare function dataURItoBlob(dataURI: string): Blob;

View File

@@ -0,0 +1,24 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* @module modules/uploader
*/
/**
* Convert dataURI to Blob
*/
export function dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
const byteString = atob(dataURI.split(',')[1]),
// separate out the mime component
mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0],
// write the bytes of the string to an ArrayBuffer
ab = new ArrayBuffer(byteString.length), ia = new Uint8Array(ab);
for (let i = 0; i < byteString.length; i += 1) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ia.buffer], { type: mimeString });
}

View File

@@ -0,0 +1,16 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* @module modules/uploader
*/
import type { Nullable } from "../../../types/index";
export * from "./build-data";
export * from "./data-uri-to-blob";
export * from "./process-old-browser-drag";
export * from "./send";
export * from "./send-files";
export declare function hasFiles(data: Nullable<DataTransfer>): data is DataTransfer;
export declare function hasItems(data: Nullable<DataTransfer>): data is DataTransfer;

View File

@@ -0,0 +1,16 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
export * from "./build-data.js";
export * from "./data-uri-to-blob.js";
export * from "./process-old-browser-drag.js";
export * from "./send.js";
export * from "./send-files.js";
export function hasFiles(data) {
return Boolean(data && data.files && data.files.length > 0);
}
export function hasItems(data) {
return Boolean(data && data.items && data.items.length > 0);
}

View File

@@ -0,0 +1,10 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* @module modules/uploader
*/
import type { HandlerError, HandlerSuccess, IUploader } from "../../../types/index";
export declare function processOldBrowserDrag(self: IUploader, cData: DataTransfer | null, handlerSuccess?: HandlerSuccess, handlerError?: HandlerError, onFinally?: () => void): void;

View File

@@ -0,0 +1,33 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
import { TEXT_PLAIN } from "../../../core/constants.js";
import { Dom } from "../../../core/dom/index.js";
import { getContainer } from "../../../core/global.js";
import { attr, isJoditObject } from "../../../core/helpers/index.js";
import { dataURItoBlob } from "./data-uri-to-blob.js";
import { sendFiles } from "./send-files.js";
export function processOldBrowserDrag(self, cData, handlerSuccess, handlerError, onFinally) {
if (cData && (!cData.types.length || cData.types[0] !== TEXT_PLAIN)) {
const div = self.j.c.div('', {
tabindex: -1,
style: 'left: -9999px; top: 0; width: 0; height: 100%;line-height: 140%; ' +
'overflow: hidden; position: fixed; z-index: 2147483647; word-break: break-all;',
contenteditable: true
});
getContainer(self.j, self.constructor).appendChild(div);
const selection = isJoditObject(self.j) ? self.j.s.save() : null, restore = () => selection && isJoditObject(self.j) && self.j.s.restore();
div.focus();
self.j.async.setTimeout(() => {
const child = div.firstChild;
Dom.safeRemove(div);
if (child && child.hasAttribute('src')) {
const src = attr(child, 'src') || '';
restore();
sendFiles(self, [dataURItoBlob(src)], handlerSuccess, handlerError).finally(onFinally);
}
}, self.j.defaultTimeout);
}
}

View File

@@ -0,0 +1,13 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* @module modules/uploader
*/
import type { HandlerError, HandlerSuccess, IUploader } from "../../../types/index";
/**
* Send files to server
*/
export declare function sendFiles(uploader: IUploader, files: FileList | File[] | null, handlerSuccess?: HandlerSuccess, handlerError?: HandlerError, process?: (form: FormData) => void): Promise<any>;

View File

@@ -0,0 +1,112 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
import { error, isFunction, isPlainObject, toArray } from "../../../core/helpers/index.js";
import { send } from "./send.js";
/**
* Send files to server
*/
export function sendFiles(uploader, files, handlerSuccess, handlerError, process) {
if (!files) {
return Promise.reject(error('Need files'));
}
const { o } = uploader;
let fileList = toArray(files);
if (!fileList.length) {
return Promise.reject(error('Need files'));
}
const promises = [];
if (o.insertImageAsBase64URI) {
readImagesWithReader(fileList, o.imagesExtensions, promises, uploader, handlerSuccess, o.defaultHandlerSuccess);
}
fileList = fileList.filter(a => a);
if (fileList.length) {
const form = new FormData();
form.append(o.pathVariableName, uploader.path);
form.append('source', uploader.source);
let file;
for (let i = 0; i < fileList.length; i += 1) {
file = fileList[i];
if (file) {
const hasRealExtension = /\.\w+$/.test(file.name);
const mime = file.type.match(/\/([a-z0-9]+)/i);
const extension = mime && mime[1] ? mime[1].toLowerCase() : '';
let newName = fileList[i].name ||
Math.random().toString().replace('.', '');
if (!hasRealExtension && extension) {
let extForReg = extension;
if (['jpeg', 'jpg'].includes(extForReg)) {
extForReg = 'jpeg|jpg';
}
const reEnd = new RegExp('.(' + extForReg + ')$', 'i');
if (!reEnd.test(newName)) {
newName += '.' + extension;
}
}
const [key, iFile, name] = o.processFileName.call(uploader, o.filesVariableName(i), fileList[i], newName);
form.append(key, iFile, name);
}
}
if (process) {
process(form);
}
if (o.data && isPlainObject(o.data)) {
Object.keys(o.data).forEach((key) => {
form.append(key, o.data[key]);
});
}
o.prepareData.call(uploader, form);
promises.push(send(uploader, form)
.then(resp => {
if (o.isSuccess.call(uploader, resp)) {
const handler = isFunction(handlerSuccess)
? handlerSuccess
: o.defaultHandlerSuccess;
handler.call(uploader, o.process.call(uploader, resp));
return resp;
}
const handler = isFunction(handlerError)
? handlerError
: o.defaultHandlerError;
handler.call(uploader, error(o.getMessage.call(uploader, resp)));
return resp;
})
.then(() => {
uploader.j.events && uploader.j.e.fire('filesWereUploaded');
}));
}
return Promise.all(promises);
}
function readImagesWithReader(fileList, imagesExtensions, promises, uploader, handlerSuccess, defaultHandlerSuccess) {
let file, i;
for (i = 0; i < fileList.length; i += 1) {
file = fileList[i];
if (file && file.type) {
const mime = file.type.match(/\/([a-z0-9]+)/i);
const extension = mime[1] ? mime[1].toLowerCase() : '';
if (!imagesExtensions.includes(extension)) {
continue;
}
const reader = new FileReader();
promises.push(uploader.j.async.promise((resolve, reject) => {
reader.onerror = reject;
reader.onloadend = () => {
const resp = {
baseurl: '',
files: [reader.result],
isImages: [true]
};
const handler = isFunction(handlerSuccess)
? handlerSuccess
: defaultHandlerSuccess;
handler.call(uploader, resp);
resolve(resp);
};
reader.readAsDataURL(file);
}));
fileList[i] = null;
}
}
}

View File

@@ -0,0 +1,12 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* @module modules/uploader
*/
import type { IDictionary, IUploader, IUploaderAnswer } from "../../../types/index";
import { Ajax } from "../../../core/request/index";
export declare const ajaxInstances: WeakMap<IUploader, Set<Ajax>>;
export declare function send(uploader: IUploader, data: FormData | IDictionary<string>): Promise<IUploaderAnswer>;

View File

@@ -0,0 +1,82 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
import { isFunction, isPromise } from "../../../core/helpers/index.js";
import { Ajax } from "../../../core/request/index.js";
import { buildData } from "./build-data.js";
export const ajaxInstances = new WeakMap();
export function send(uploader, data) {
const requestData = buildData(uploader, data);
const showProgress = (progress) => {
uploader.j.progressbar.show().progress(progress);
if (progress >= 100) {
uploader.j.progressbar.hide();
}
};
let sendData = (request, showProgress) => {
const ajax = new Ajax({
xhr: () => {
const xhr = new XMLHttpRequest();
if (uploader.j.ow.FormData !== undefined &&
xhr.upload) {
showProgress(10);
xhr.upload.addEventListener('progress', evt => {
if (evt.lengthComputable) {
let percentComplete = evt.loaded / evt.total;
percentComplete *= 100;
showProgress(percentComplete);
}
}, false);
}
else {
showProgress(100);
}
return xhr;
},
method: uploader.o.method || 'POST',
data: request,
url: isFunction(uploader.o.url)
? uploader.o.url(request)
: uploader.o.url,
headers: uploader.o.headers,
queryBuild: uploader.o.queryBuild,
contentType: uploader.o.contentType.call(uploader, request),
withCredentials: uploader.o.withCredentials || false
});
let instances = ajaxInstances.get(uploader);
if (!instances) {
instances = new Set();
ajaxInstances.set(uploader, instances);
}
instances.add(ajax);
uploader.j.e.one('beforeDestruct', ajax.destruct);
return ajax
.send()
.then(resp => resp.json())
.catch(error => {
return {
success: false,
data: {
messages: [error]
}
};
})
.finally(() => {
ajax.destruct();
instances === null || instances === void 0 ? void 0 : instances.delete(ajax);
});
};
if (isFunction(uploader.o.customUploadFunction)) {
sendData = uploader.o.customUploadFunction;
}
if (isPromise(requestData)) {
return requestData
.then(data => sendData(data, showProgress))
.catch(error => {
uploader.o.error.call(uploader, error);
});
}
return sendData(requestData, showProgress);
}