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,11 @@
/*!
* 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/file-browser
*/
import type { IFileBrowser } from "../../../types/index";
declare const _default: (self: IFileBrowser) => ((e: DragEvent) => boolean | void);
export default _default;

View File

@@ -0,0 +1,161 @@
/*!
* 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 { Dom } from "../../../core/dom/index.js";
import { attr, error } from "../../../core/helpers/utils/index.js";
import { Icon } from "../../../core/ui/icon.js";
import { elementsMap } from "./elements-map.js";
import { makeContextMenu } from "../factories.js";
import { deleteFile } from "../fetch/delete-file.js";
import { loadTree } from "../fetch/load-tree.js";
import { elementToItem, getItem } from "../listeners/native-listeners.js";
import { openImageEditor } from "../../image-editor/image-editor.js";
const CLASS_PREVIEW = 'jodit-file-browser-preview', preview_tpl_next = (next = 'next', right = 'right') => `<div class="${CLASS_PREVIEW}__navigation ${CLASS_PREVIEW}__navigation_arrow_${next}">` +
'' +
Icon.get('angle-' + right) +
'</a>';
export default (self) => {
if (!self.o.contextMenu) {
return () => { };
}
const contextmenu = makeContextMenu(self);
return (e) => {
const a = getItem(e.target, self.container);
if (!a) {
return;
}
let item = a;
const opt = self.options, ga = (key) => attr(item, key) || '';
self.async.setTimeout(() => {
const selectedItem = elementToItem(a, elementsMap(self));
if (!selectedItem) {
return;
}
self.state.activeElements = [selectedItem];
contextmenu.show(e.clientX, e.clientY, [
ga('data-is-file') !== '1' &&
opt.editImage &&
(self.dataProvider.canI('ImageResize') ||
self.dataProvider.canI('ImageCrop'))
? {
icon: 'pencil',
title: 'Edit',
exec: () => openImageEditor.call(self, ga('href'), ga('data-name'), ga('data-path'), ga('data-source'))
}
: false,
self.dataProvider.canI('FileRename')
? {
icon: 'italic',
title: 'Rename',
exec: () => {
self.e.fire('fileRename.filebrowser', ga('data-name'), ga('data-path'), ga('data-source'));
}
}
: false,
self.dataProvider.canI('FileRemove')
? {
icon: 'bin',
title: 'Delete',
exec: async () => {
try {
await deleteFile(self, ga('data-name'), ga('data-source'));
}
catch (e) {
return self.status(e);
}
self.state.activeElements = [];
return loadTree(self).catch(self.status);
}
}
: false,
opt.preview
? {
icon: 'eye',
title: 'Preview',
exec: () => {
const preview = self.dlg({
buttons: ['fullsize', 'dialog.close']
}), temp_content = self.c.div(CLASS_PREVIEW, '<div class="jodit-icon_loader"></div>'), preview_box = self.c.div(CLASS_PREVIEW + '__box'), next = self.c.fromHTML(preview_tpl_next()), prev = self.c.fromHTML(preview_tpl_next('prev', 'left')), addLoadHandler = (src) => {
const image = self.c.element('img');
image.setAttribute('src', src);
const onload = () => {
var _a;
if (self.isInDestruct) {
return;
}
self.e.off(image, 'load');
Dom.detach(temp_content);
if (opt.showPreviewNavigation) {
if (Dom.prevWithClass(item, self.files.getFullElName('item'))) {
temp_content.appendChild(prev);
}
if (Dom.nextWithClass(item, self.files.getFullElName('item'))) {
temp_content.appendChild(next);
}
}
temp_content.appendChild(preview_box);
preview_box.appendChild(image);
preview.setPosition();
(_a = self === null || self === void 0 ? void 0 : self.events) === null || _a === void 0 ? void 0 : _a.fire('previewOpenedAndLoaded');
};
self.e.on(image, 'load', onload);
if (image.complete) {
onload();
}
};
self.e.on([next, prev], 'click', function () {
if (this === next) {
item = Dom.nextWithClass(item, self.files.getFullElName('item'));
}
else {
item = Dom.prevWithClass(item, self.files.getFullElName('item'));
}
if (!item) {
throw error('Need element');
}
Dom.detach(temp_content);
Dom.detach(preview_box);
temp_content.innerHTML =
'<div class="jodit-icon_loader"></div>';
addLoadHandler(ga('href'));
});
self.e.on('beforeDestruct', () => {
preview.destruct();
});
preview.container.classList.add(CLASS_PREVIEW + '__dialog');
preview.setContent(temp_content);
preview.setPosition();
preview.open();
addLoadHandler(ga('href'));
self.events
.on('beforeDestruct', () => {
preview.destruct();
})
.fire('previewOpened');
}
}
: false,
{
icon: 'upload',
title: 'Download',
exec: () => {
const url = ga('href');
if (url) {
self.ow.open(url);
}
}
}
]);
}, self.defaultTimeout);
self.e
.on('beforeClose', () => {
contextmenu.close();
})
.on('beforeDestruct', () => contextmenu.destruct());
e.stopPropagation();
e.preventDefault();
return false;
};
};

View File

@@ -0,0 +1,19 @@
/*!
* 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/file-browser
*/
import type { IDictionary, IFileBrowserItem, IViewBased } from "../../../types/index";
type ElementsMap = IDictionary<{
elm: HTMLElement;
item: IFileBrowserItem;
}>;
/**
* Returns a map of the file's key correspondence to its DOM element in the file browser
* @private
*/
export declare const elementsMap: (view: IViewBased) => ElementsMap;
export {};

View File

@@ -0,0 +1,18 @@
/*!
* 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
*/
const map = new WeakMap();
/**
* Returns a map of the file's key correspondence to its DOM element in the file browser
* @private
*/
export const elementsMap = (view) => {
let result = map.get(view);
if (!result) {
result = {};
map.set(view, result);
}
return result;
};

View File

@@ -0,0 +1,23 @@
/*!
* 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/file-browser
*/
import type { IFileBrowserItemElement, IFileBrowserItemWrapper, ISource } from "../../../types/index";
export declare class FileBrowserItem implements IFileBrowserItemWrapper {
readonly data: IFileBrowserItemElement;
source: ISource;
sourceName: string;
type: IFileBrowserItemWrapper['type'];
private constructor();
static create(data: IFileBrowserItemElement): FileBrowserItem & IFileBrowserItemElement;
get path(): string;
get imageURL(): string;
get fileURL(): string;
get time(): string;
get uniqueHashKey(): string;
toJSON(): object;
}

View File

@@ -0,0 +1,65 @@
/*!
* 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 { normalizePath, normalizeUrl } from "../../../core/helpers/index.js";
export class FileBrowserItem {
constructor(data) {
this.data = data;
// TODO Check with Object.assign
Object.keys(data).forEach(key => {
this[key] = data[key];
});
}
static create(data) {
if (data instanceof FileBrowserItem) {
return data;
}
return new FileBrowserItem(data);
}
get path() {
return normalizePath(this.data.source.path ? this.data.source.path + '/' : '/');
}
get imageURL() {
const timestamp = this.time || new Date().getTime().toString(), { thumbIsAbsolute, source, thumb, file } = this.data, path = thumb || file;
return thumbIsAbsolute && path
? path
: normalizeUrl(source.baseurl, source.path, path || '') +
'?_tmst=' +
encodeURIComponent(timestamp);
}
get fileURL() {
let { name } = this.data;
const { file, fileIsAbsolute, source } = this.data;
if (file !== undefined) {
name = file;
}
return fileIsAbsolute && name
? name
: normalizeUrl(source.baseurl, source.path, name || '');
}
get time() {
const { changed } = this.data;
return ((changed &&
(typeof changed === 'number'
? new Date(changed).toLocaleString()
: changed)) ||
'');
}
get uniqueHashKey() {
const data = this.data;
let key = [
data.sourceName,
data.name,
data.file,
this.time,
data.thumb
].join('_');
key = key.toLowerCase().replace(/[^0-9a-z\-.]/g, '-');
return key;
}
toJSON() {
return this.data;
}
}