Skip to content

Commit

Permalink
Fixed order in IControlType.list as Array
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed May 11, 2024
1 parent 09cd82f commit 3b05074
Show file tree
Hide file tree
Showing 63 changed files with 150 additions and 132 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ module.exports = {
'jodit/types',
'jodit/.*\\u0000$',
'jodit/core',
'jodit/config',
'jodit/modules'
],

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ examples/build/
/playwright-report/
/blob-report/
/playwright/.cache/
stack.md
64 changes: 59 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,60 @@
> - :house: [Internal]
> - :nail_care: [Polish]
## 4.2.14

#### :house: Internal

- Removed conversion of list arrays into objects when creating a button in the toolbar. Previously the code looked like:

```js
Jodit.make('#editor', {
constrols: {
lineHeight: {
list: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 2]
}
}
});
```

was implicitly transformed into an object of the form:

```js
Jodit.make('#editor', {
constrols: {
lineHeight: {
list: {
1: '1',
2: '2',
1.1: '1.1',
1.2: '1.2',
1.3: '1.3',
1.4: '1.4',
1.5: '1.5'
}
}
}
});
```

Thus, due to the nature of integer keys, the order of the elements was lost. Now such a transformation does not occur.
In your code you clearly need to check what came into `list` and if it is an array, then use it as is.

```js
Jodit.make('#editor', {
constrols: {
lineHeight: {
list: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 2],
update(editor: IJodit, button): boolean {
if (Array.isArray(button.control)) {
// Work with array
}
}
}
}
});
```

## 4.2.13

### :bug: Bug Fix
Expand Down Expand Up @@ -2620,11 +2674,11 @@ Related with https://github.com/xdan/jodit/issues/574. In some cases need to lim
- @property {IUIOption[]} link.selectOptionsClassName=[] The list of the option for the select (to use with
modeClassName="select")
- ex: [
- { value: "", text: "" },
- { value: "val1", text: "text1" },
- { value: "val2", text: "text2" },
- { value: "val3", text: "text3" }
- ]
- { value: "", text: "" },
- { value: "val1", text: "text1" },
- { value: "val2", text: "text2" },
- { value: "val3", text: "text3" }
- ]
PR: https://github.com/xdan/jodit/pull/577 Thanks @s-renier-taonix-fr
##### New option `statusbar: boolean = true`
Expand Down
1 change: 0 additions & 1 deletion src/core/helpers/string/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
defaultLanguage as defineLanguage,
error
} from 'jodit/core/helpers/utils';

import { Config } from 'jodit/config';

/**
Expand Down
3 changes: 1 addition & 2 deletions src/core/helpers/utils/config-proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import { isArray } from 'jodit/core/helpers/checker/is-array';
import { isPlainObject } from 'jodit/core/helpers/checker/is-plain-object';
import { isString } from 'jodit/core/helpers/checker/is-string';
import { isVoid } from 'jodit/core/helpers/checker/is-void';
import { Config } from 'jodit/config';

import { isAtom } from './extend';
import { keys } from './utils';

import { Config } from 'jodit/config';

/**
* @example
* ```js
Expand Down
3 changes: 1 addition & 2 deletions src/core/request/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ import {
parseQuery
} from 'jodit/core/helpers';
import * as error from 'jodit/core/helpers/utils/error';
import { Config } from 'jodit/config';

import './config';

import { Response } from './response';

import { Config } from 'jodit/config';

export class Ajax<T extends object = any> implements IAjax<T> {
className(): string {
return 'Ajax';
Expand Down
1 change: 0 additions & 1 deletion src/core/request/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

import type { AjaxOptions } from 'jodit/types';

import { Config } from 'jodit/config';

declare module 'jodit/config' {
Expand Down
31 changes: 15 additions & 16 deletions src/core/ui/helpers/get-control-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import type {
IControlTypeStrong,
IDictionary
} from 'jodit/types';
import { ConfigFlatten, isArray, isString } from 'jodit/core/helpers';

import { ConfigFlatten, /*isArray,*/ isString } from 'jodit/core/helpers';
import { Config } from 'jodit/config';

/**
Expand Down Expand Up @@ -73,24 +72,24 @@ export function findControlType(
key = namespaceOrKey;
}

const list = store[key]?.list;
// const list = store[key]?.list;

return store[key]
? {
name: key,
...ConfigFlatten(store[key]),
list: isArray(list)
? (<Array<string>>list).reduce(
(
acc: IDictionary<string | number>,
k: string | number
) => {
acc[k] = k;
return acc;
},
{}
)
: list
...ConfigFlatten(store[key])
// list: isArray(list)
// ? (<Array<string>>list).reduce(
// (
// acc: IDictionary<string | number>,
// k: string | number
// ) => {
// acc[String(k)] = k;
// return acc;
// },
// {}
// )
// : list
}
: undefined;
}
3 changes: 1 addition & 2 deletions src/core/ui/helpers/get-strong-control-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import type {
} from 'jodit/types';
import { isArray } from 'jodit/core/helpers/checker/is-array';
import { ConfigProto, keys } from 'jodit/core/helpers/utils';
import { Config } from 'jodit/config';

import { getControlType } from './get-control-type';

import { Config } from 'jodit/config';

/**
* @private
*/
Expand Down
3 changes: 1 addition & 2 deletions src/jodit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
} from 'jodit/core/helpers';
import { Ajax } from 'jodit/core/request';
import { Dlgs } from 'jodit/core/traits/dlgs';
import { Config } from 'jodit/config';
import {
Create,
Dom,
Expand All @@ -80,8 +81,6 @@ import {
ViewWithToolbar
} from 'jodit/modules';

import { Config } from 'jodit/config';

const __defaultStyleDisplayKey = 'data-jodit-default-style-display';
const __defaultClassesKey = 'data-jodit-default-classes';

Expand Down
3 changes: 1 addition & 2 deletions src/modules/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ import { assert } from 'jodit/core/helpers/utils/assert';
import { Icon } from 'jodit/core/ui';
import { View } from 'jodit/core/view/view';
import { ViewWithToolbar } from 'jodit/core/view/view-with-toolbar';
import { Config } from 'jodit/config';

import './dialog.less';

import { Config } from 'jodit/config';

declare module 'jodit/config' {
interface Config {
dialog: IDialogOptions;
Expand Down
1 change: 0 additions & 1 deletion src/modules/file-browser/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import 'jodit/core/request/config';
import { isArray, isString } from 'jodit/core/helpers/checker';
import { humanSizeToBytes } from 'jodit/core/helpers/utils/human-size-to-bytes';
import { UIFileInput } from 'jodit/core/ui/form/inputs/file/file';

import { Config } from 'jodit/config';

declare module 'jodit/config' {
Expand Down
3 changes: 1 addition & 2 deletions src/modules/file-browser/file-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import { Storage } from 'jodit/core/storage';
import { Dlgs } from 'jodit/core/traits/dlgs';
import { ViewWithToolbar } from 'jodit/core/view/view-with-toolbar';
import { Config } from 'jodit/config';

import './config';

Expand All @@ -57,8 +58,6 @@ import { FileBrowserFiles, FileBrowserTree } from './ui';

import './styles/index.less';

import { Config } from 'jodit/config';

export interface FileBrowser extends Dlgs {}

@derive(Dlgs)
Expand Down
3 changes: 1 addition & 2 deletions src/modules/history/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import type {
} from 'jodit/types';
import { ViewComponent } from 'jodit/core/component';
import { debounce } from 'jodit/core/decorators';
import { Config } from 'jodit/config';

import { Command } from './command';
import { Snapshot } from './snapshot';
import { Stack } from './stack';

import { Config } from 'jodit/config';

declare module 'jodit/config' {
interface Config {
history: {
Expand Down
3 changes: 1 addition & 2 deletions src/modules/image-editor/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

import type { ImageEditorOptions } from 'jodit/types';
import { Icon } from 'jodit/core/ui/icon';
import { Config } from 'jodit/config';

import cropIcon from './icons/crop.svg';
import resizeIcon from './icons/resize.svg';

import { Config } from 'jodit/config';

declare module 'jodit/config' {
interface Config {
imageeditor: ImageEditorOptions;
Expand Down
3 changes: 1 addition & 2 deletions src/modules/image-editor/image-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ import { autobind, component, debounce, throttle } from 'jodit/core/decorators';
import { Dom } from 'jodit/core/dom';
import { $$, attr, call, css, refs, toArray, trim } from 'jodit/core/helpers';
import { Button } from 'jodit/core/ui/button';
import { Config } from 'jodit/config';

import './config';

import { form } from './templates/form';

import './image-editor.less';

import { Config } from 'jodit/config';

interface onSave {
(
/**
Expand Down
4 changes: 2 additions & 2 deletions src/modules/toolbar/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ export class ToolbarButton<T extends IViewBased = IViewBased>
@cacheHTML
protected override createContainer(): HTMLElement {
const cn = this.componentName;
const container = this.j.c.span(cn),
button = super.createContainer();
const container = this.j.c.span(cn);
const button = super.createContainer();

attr(container, 'role', 'listitem');

Expand Down
5 changes: 4 additions & 1 deletion src/modules/toolbar/button/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import type { IViewBased } from 'jodit/types';
import { component } from 'jodit/core/decorators';
import { isPlainObject } from 'jodit/core/helpers/checker/is-plain-object';
import { isString } from 'jodit/core/helpers/checker/is-string';

import { ToolbarButton } from '../button';
Expand Down Expand Up @@ -43,7 +44,9 @@ export class ToolbarSelect<
key = keys[0];
}

const text = (list[key.toString()] || key).toString();
const text = (
isPlainObject(list) ? list[key.toString()] || key : key
).toString();

this.state.text =
this.control.textTemplate?.(this.jodit, text) ?? text;
Expand Down
1 change: 0 additions & 1 deletion src/modules/uploader/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type {
} from 'jodit/types';
import { isArray } from 'jodit/core/helpers/checker/is-array';
import { isJoditObject } from 'jodit/core/helpers/checker/is-jodit-object';

import { Config } from 'jodit/config';

declare module 'jodit/config' {
Expand Down
3 changes: 1 addition & 2 deletions src/modules/uploader/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isFunction,
isJoditObject
} from 'jodit/core/helpers';
import { Config } from 'jodit/config';
import {
ajaxInstances,
hasFiles,
Expand All @@ -39,8 +40,6 @@ import './config';

import './uploader.less';

import { Config } from 'jodit/config';

export class Uploader extends ViewComponent implements IUploader {
declare readonly jodit: IViewBased;

Expand Down
3 changes: 1 addition & 2 deletions src/plugins/about/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import { HOMEPAGE } from 'jodit/core/constants';
import { pluginSystem } from 'jodit/core/global';
import { css, isLicense, normalizeLicense } from 'jodit/core/helpers/';
import { Icon } from 'jodit/core/ui/icon';
import { Config } from 'jodit/config';

import aboutIcon from './about.svg';

import './about.less';

import { Config } from 'jodit/config';

Config.prototype.controls.about = {
exec: (editor: IJodit) => {
const dialog = editor.dlg({ closeOnClickOverlay: true }),
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/add-new-line/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

import type { HTMLTagNames } from 'jodit/types';
import { Icon } from 'jodit/core/ui/icon';
import { Config } from 'jodit/config';

import enterIcon from './enter.svg';

import { Config } from 'jodit/config';

declare module 'jodit/config' {
interface Config {
/**
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/ai-assistant/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

import type { IControlType, IJodit } from 'jodit/types';
import { Icon } from 'jodit/core/ui/icon';
import { Config } from 'jodit/config';

import magicWandIcon from './ai-assistant.svg';
import chatBotIcon from './chat-bot.svg';

import { Config } from 'jodit/config';

export interface AiAssistantSettings {
/** Callback function for AI assistant to process and return the result */
aiAssistantCallback?: (
Expand Down
Loading

0 comments on commit 3b05074

Please sign in to comment.