mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-01 13:32:23 +02:00
Use deepmerge lib + store all defaults in DEFAULT_CONFIG
This commit is contained in:
parent
4824958e4d
commit
4431a0ec23
|
@ -77,6 +77,7 @@
|
||||||
"classnames": "^2.2.5",
|
"classnames": "^2.2.5",
|
||||||
"core-js": "^2.5.6",
|
"core-js": "^2.5.6",
|
||||||
"custom-event-polyfill": "^0.3.0",
|
"custom-event-polyfill": "^0.3.0",
|
||||||
|
"deepmerge": "^2.2.1",
|
||||||
"fuse.js": "^3.1.0",
|
"fuse.js": "^3.1.0",
|
||||||
"opn": "^5.1.0",
|
"opn": "^5.1.0",
|
||||||
"redux": "^3.3.1"
|
"redux": "^3.3.1"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Fuse from 'fuse.js';
|
import Fuse from 'fuse.js';
|
||||||
|
import merge from 'deepmerge';
|
||||||
|
|
||||||
import './lib/polyfills';
|
import './lib/polyfills';
|
||||||
import Store from './store/store';
|
import Store from './store/store';
|
||||||
|
@ -10,12 +11,7 @@ import {
|
||||||
WrappedInput,
|
WrappedInput,
|
||||||
WrappedSelect,
|
WrappedSelect,
|
||||||
} from './components';
|
} from './components';
|
||||||
import {
|
import { DEFAULT_CONFIG, EVENTS, KEY_CODES } from './constants';
|
||||||
DEFAULT_CONFIG,
|
|
||||||
DEFAULT_CLASSNAMES,
|
|
||||||
EVENTS,
|
|
||||||
KEY_CODES,
|
|
||||||
} from './constants';
|
|
||||||
import { TEMPLATES } from './templates';
|
import { TEMPLATES } from './templates';
|
||||||
import {
|
import {
|
||||||
addChoice,
|
addChoice,
|
||||||
|
@ -33,7 +29,6 @@ import {
|
||||||
isType,
|
isType,
|
||||||
strToEl,
|
strToEl,
|
||||||
extend,
|
extend,
|
||||||
sortByAlpha,
|
|
||||||
sortByScore,
|
sortByScore,
|
||||||
generateId,
|
generateId,
|
||||||
findAncestorByAttrName,
|
findAncestorByAttrName,
|
||||||
|
@ -60,7 +55,7 @@ class Choices {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.config = Choices._generateConfig(userConfig);
|
this.config = merge.all([DEFAULT_CONFIG, Choices.userDefaults, userConfig]);
|
||||||
|
|
||||||
if (!['auto', 'always'].includes(this.config.renderSelectedChoices)) {
|
if (!['auto', 'always'].includes(this.config.renderSelectedChoices)) {
|
||||||
this.config.renderSelectedChoices = 'auto';
|
this.config.renderSelectedChoices = 'auto';
|
||||||
|
@ -173,6 +168,7 @@ class Choices {
|
||||||
this._store.subscribe(this._render);
|
this._store.subscribe(this._render);
|
||||||
this._render();
|
this._render();
|
||||||
this._addEventListeners();
|
this._addEventListeners();
|
||||||
|
|
||||||
this.initialised = true;
|
this.initialised = true;
|
||||||
|
|
||||||
const { callbackOnInit } = this.config;
|
const { callbackOnInit } = this.config;
|
||||||
|
@ -2029,18 +2025,6 @@ class Choices {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static _generateConfig(userConfig) {
|
|
||||||
const defaultConfig = {
|
|
||||||
...DEFAULT_CONFIG,
|
|
||||||
items: [],
|
|
||||||
choices: [],
|
|
||||||
classNames: DEFAULT_CLASSNAMES,
|
|
||||||
sortFn: sortByAlpha,
|
|
||||||
};
|
|
||||||
|
|
||||||
return extend(defaultConfig, Choices.userDefaults, userConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
_generatePlaceholderValue() {
|
_generatePlaceholderValue() {
|
||||||
if (this._isSelectOneElement) {
|
if (this._isSelectOneElement) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { stripHTML } from './lib/utils';
|
import { stripHTML, sortByAlpha } from './lib/utils';
|
||||||
|
|
||||||
export const DEFAULT_CLASSNAMES = {
|
export const DEFAULT_CLASSNAMES = {
|
||||||
containerOuter: 'choices',
|
containerOuter: 'choices',
|
||||||
|
@ -52,6 +52,7 @@ export const DEFAULT_CONFIG = {
|
||||||
regexFilter: null,
|
regexFilter: null,
|
||||||
shouldSort: true,
|
shouldSort: true,
|
||||||
shouldSortItems: false,
|
shouldSortItems: false,
|
||||||
|
sortFn: sortByAlpha,
|
||||||
placeholder: true,
|
placeholder: true,
|
||||||
placeholderValue: null,
|
placeholderValue: null,
|
||||||
searchPlaceholderValue: null,
|
searchPlaceholderValue: null,
|
||||||
|
@ -71,6 +72,7 @@ export const DEFAULT_CONFIG = {
|
||||||
},
|
},
|
||||||
callbackOnInit: null,
|
callbackOnInit: null,
|
||||||
callbackOnCreateTemplates: null,
|
callbackOnCreateTemplates: null,
|
||||||
|
classNames: DEFAULT_CLASSNAMES,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EVENTS = {
|
export const EVENTS = {
|
||||||
|
|
Loading…
Reference in a new issue