Skip to content

Commit

Permalink
Refactoring in clipboard plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Aug 7, 2020
1 parent 52d80b0 commit e0b277d
Show file tree
Hide file tree
Showing 34 changed files with 1,584 additions and 685 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const path = require('path');
const webpack = require(path.resolve(process.cwd(), './webpack.config'));
const webpackConfig = (es = 'es5') =>
const webpackConfig = (es = 'es2015') =>
webpack([], {
mode: 'production',
isTest: true,
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"newversiongit": "git add --all && git commit -m \"New version $npm_package_version. Read more https://github.com/xdan/jodit/releases/tag/$npm_package_version \" && git tag $npm_package_version && git push --tags origin HEAD:master",
"start": "node server.js --port=2000",
"clean": "rm -rf build/*",
"build": "npm run clean && gulp build && npm run build-es5 && npm run build-es18 && npm run build-no-uglify-es5 && npm run build-no-uglify-es18",
"build-es5": "webpack --progress --mode production --es es5 --uglify true",
"build-es18": "webpack --progress --mode production --es es2018 --uglify true",
"build-no-uglify-es5": "webpack --progress --mode production --es es5",
"build-no-uglify-es18": "webpack --progress --mode production --es es2018",
"build": "npm run clean && gulp build && npm run build-es2015 && npm run build-es2018 && npm run build-no-uglify-es2015 && npm run build-no-uglify-es2018",
"build-es2015": "webpack --progress --mode production --es es2015 --uglify true",
"build-es2018": "webpack --progress --mode production --es es2018 --uglify true",
"build-no-uglify-es2015": "webpack --progress --mode production --es es2015",
"build-no-uglify-es2018": "webpack --progress --mode production --es es2018",
"test": "karma start --browsers FirefoxHeadless karma.conf.js",
"test-debug": "karma start --browsers Chrome karma.conf.js --single-run false",
"test-chrome": "karma start --browsers Chrome karma.conf.js",
Expand Down Expand Up @@ -95,7 +95,7 @@
"terser-webpack-plugin": "^3.1.0",
"ts-loader": "^7.0.5",
"ts-private-uglifier": "^1.0.2",
"tslib": "^2.0.0",
"tslib": "^2.0.1",
"typescript": "^3.9.7",
"uglifyjs-webpack-plugin": "^2.2.0",
"url-loader": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ process.argv.filter(a => reg.test(a)).forEach((c) => {
// gulptasks.watch();

const config = require(path.resolve(cwd, './webpack.config'))([], {
es: 'es5',
es: 'es2015',
isTest: true
}, cwd);

Expand Down
41 changes: 25 additions & 16 deletions src/core/events/observe-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ import { CallbackFunction, IDictionary } from '../../types';
import { isPlainObject, isFastEqual, isArray } from '../helpers';

export class ObserveObject {
#data!: IDictionary;
#prefix!: string[];
#onEvents!: IDictionary<CallbackFunction[]>;

protected constructor(
readonly data: IDictionary,
readonly prefix: string[] = [],
readonly onEvents: IDictionary<CallbackFunction[]> = {}
data: IDictionary,
prefix: string[] = [],
onEvents: IDictionary<CallbackFunction[]> = {}
) {
this.#data = data;
this.#prefix = prefix;
this.#onEvents = onEvents;

Object.keys(data).forEach(key => {
const prefix = this.prefix.concat(key).filter(a => a.length);
const prefix = this.#prefix.concat(key).filter(a => a.length);

Object.defineProperty(this, key, {
set: value => {
Expand All @@ -34,7 +42,7 @@ export class ObserveObject {
value = new ObserveObject(
value,
prefix,
this.onEvents
this.#onEvents
);
}

Expand All @@ -59,17 +67,18 @@ export class ObserveObject {
},
get: () => {
return data[key];
}
},
enumerable: true
});

if (isPlainObject(data[key])) {
data[key] = new ObserveObject(data[key], prefix, this.onEvents);
data[key] = new ObserveObject(data[key], prefix, this.#onEvents);
}
});
}

valueOf(): any {
return this.data;
return this.#data;
}

toString(): string {
Expand All @@ -87,16 +96,16 @@ export class ObserveObject {
return this;
}

if (!this.onEvents[event]) {
this.onEvents[event] = [];
if (!this.#onEvents[event]) {
this.#onEvents[event] = [];
}

this.onEvents[event].push(callback);
this.#onEvents[event].push(callback);

return this;
}

private __lockEvent: IDictionary<boolean> = {};
#__lockEvent: IDictionary<boolean> = {};

fire(event: string | string[], ...attr: any[]): void {
if (isArray(event)) {
Expand All @@ -105,12 +114,12 @@ export class ObserveObject {
}

try {
if (!this.__lockEvent[event] && this.onEvents[event]) {
this.__lockEvent[event] = true;
this.onEvents[event].forEach(clb => clb.call(this, ...attr));
if (!this.#__lockEvent[event] && this.#onEvents[event]) {
this.#__lockEvent[event] = true;
this.#onEvents[event].forEach(clb => clb.call(this, ...attr));
}
} finally {
this.__lockEvent[event] = false;
this.#__lockEvent[event] = false;
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/core/helpers/checker/is-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
* Copyright (c) 2013-2020 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/

import { isString } from './is-string';

/**
* Check if a string is html or not
*
* @method isHTML
* @param {string} str
* @return {boolean}
** @param str
*/
export const isHTML = (str: string): boolean =>
/<([A-Za-z][A-Za-z0-9]*)\b[^>]*>(.*?)<\/\1>/m.test(str);
export const isHTML = (str: unknown): str is string =>
isString(str) && /<([A-Za-z][A-Za-z0-9]*)\b[^>]*>(.*?)<\/\1>/m.test(str);
1 change: 1 addition & 0 deletions src/core/helpers/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './mark-deprecated';
export * from './utils';
export * from './get';
export * from './get-class-name';
export * from './stack';
30 changes: 30 additions & 0 deletions src/core/helpers/utils/stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2020 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
import { CanUndef } from '../../../types';

export class LimitedStack<T> {
private stack: T[] = [];

constructor(readonly limit: number) {}

push(item: T): this {
this.stack.push(item);

if (this.stack.length > this.limit) {
this.stack.shift();
}

return this;
}

pop(): CanUndef<T> {
return this.stack.pop();
}

find(clb: (item: T) => boolean): CanUndef<T> {
return this.stack.find(clb);
}
}
8 changes: 8 additions & 0 deletions src/core/ui/button/button.less
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@
.jodit_status(#007bff, #fff, #0069d9, #fff, #0062cc, #fff);
}

&_status_secondary {
.jodit_status(#d8d8d8, #212529, #c9cdd1, #212529, #dae0e5, #212529);
border-radius: 0;
}

&_status_success {
.jodit_status(#28a745, #fff, #218838, #fff, #1e7e34, #fff);
}
Expand Down Expand Up @@ -167,5 +172,8 @@

.jodit-ui-button-icon-text();

&:focus:not([disabled]) {
outline: 1px dashed var(--color-background-selection);
}
.jodit-ui-button-statuses();
}
2 changes: 2 additions & 0 deletions src/core/ui/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export const UIButtonState = (): IUIButtonState => ({
disabled: false,
activated: false,

data: {},

icon: {
name: 'empty',
fill: '',
Expand Down
5 changes: 4 additions & 1 deletion src/langs/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,8 @@ module.exports = {
"Quadrate": "المربعة",
"Find": "البحث",
"Find Previous": "تجد السابقة",
"Find Next": "تجد التالي"
"Find Next": "تجد التالي",
"The pasted content is coming from a Microsoft Word/Excel document. Do you want to keep the format or clean it up?": "للصق المحتوى قادم من Microsoft Word/Excel الوثيقة. هل تريد أن تبقي شكل أو تنظيفه ؟ ",
"Word Paste Detected": "كلمة لصق الكشف عن",
"Clean": "نظيفة"
};
5 changes: 5 additions & 0 deletions src/modules/context-menu/context-menu.less
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

.jodit-context-menu {
.jodit-popup();
z-index: var(--z-index-context-menu);

.jodit-ui-button {
display: flex;
}

&__actions {
.font();
Expand Down
1 change: 1 addition & 0 deletions src/modules/file-browser/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Config.prototype.filebrowser = {

createNewFolder: true,
deleteFolder: true,
renameFolder: true,
moveFolder: true,
moveFile: true,
showFoldersPanel: true,
Expand Down
25 changes: 7 additions & 18 deletions src/modules/file-browser/data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ export default class DataProvider implements IFileBrowserDataProvider {
);
}

currentPath: string = '';
currentSource: string = DEFAULT_SOURCE_NAME;
currentBaseUrl: string = '';

constructor(
readonly parent: IViewBased,
readonly options: IFileBrowserOptions
Expand Down Expand Up @@ -120,10 +116,7 @@ export default class DataProvider implements IFileBrowserDataProvider {
* @param path
* @param source
*/
async permissions(
path: string = this.currentPath,
source: string = this.currentSource
): Promise<void> {
async permissions(path: string, source: string): Promise<void> {
if (!this.o.permissions) {
return Promise.resolve();
}
Expand Down Expand Up @@ -164,8 +157,8 @@ export default class DataProvider implements IFileBrowserDataProvider {
* @param source
*/
async items(
path: string = this.currentPath,
source: string = this.currentSource
path: string,
source: string
): Promise<IFileBrowserAnswer> {
const opt = this.options;

Expand All @@ -180,8 +173,8 @@ export default class DataProvider implements IFileBrowserDataProvider {
}

async tree(
path: string = this.currentPath,
source: string = this.currentSource
path: string,
source: string
): Promise<IFileBrowserAnswer> {
path = normalizeRelativePath(path);

Expand Down Expand Up @@ -243,7 +236,7 @@ export default class DataProvider implements IFileBrowserDataProvider {
path: string,
source: string
): Promise<IFileBrowserAnswer> {
const {create} = this.o;
const { create } = this.o;

if (!create) {
return Promise.reject('Set Create api options');
Expand All @@ -253,11 +246,7 @@ export default class DataProvider implements IFileBrowserDataProvider {
create.data.path = path;
create.data.name = name;

return this.get('create').then(resp => {
this.currentPath = path;
this.currentSource = source;
return resp;
});
return this.get('create');
}

/**
Expand Down
Loading

0 comments on commit e0b277d

Please sign in to comment.