mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-05-26 20:04:08 +03:00
rollup config improvement
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
// eslint-disable-next-line
|
||||
const noop = <T>(): T => {
|
||||
return {} as T;
|
||||
};
|
||||
const getSelectOptions = (selectElement: HTMLSelectElement) => Array.from(selectElement.options).map((option) => option.value);
|
||||
|
||||
export const generateSelectCallback = (targetElm: HTMLElement | null) => (event: Event) => {
|
||||
const target = event.target as HTMLSelectElement;
|
||||
const selectedOption = target.value;
|
||||
const selectOptions = getSelectOptions(target);
|
||||
|
||||
if (targetElm) {
|
||||
targetElm.classList.remove(...selectOptions);
|
||||
targetElm.classList.add(selectedOption);
|
||||
}
|
||||
};
|
||||
|
||||
export const selectOption = (select: HTMLSelectElement | null, selectedOption: string | number): boolean => {
|
||||
if (!select) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const options = getSelectOptions(select);
|
||||
const currValue = select.value;
|
||||
|
||||
if (selectedOption === currValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof selectedOption === 'string' && options.includes(selectedOption)) {
|
||||
select.value = selectedOption;
|
||||
} else if (typeof selectedOption === 'number' && options.length < selectedOption && selectedOption > -1) {
|
||||
select.selectedIndex = selectedOption;
|
||||
}
|
||||
|
||||
let event;
|
||||
if (typeof Event === 'function') {
|
||||
event = new Event('change');
|
||||
} else {
|
||||
event = document.createEvent('Event');
|
||||
event.initEvent('change', true, true);
|
||||
}
|
||||
select.dispatchEvent(event);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const iterateSelect = async <T>(
|
||||
select: HTMLSelectElement | null,
|
||||
options?: {
|
||||
beforeEach?: () => T | Promise<T>;
|
||||
check?: (input: T) => void | Promise<void>;
|
||||
afterEach?: () => void | Promise<void>;
|
||||
}
|
||||
) => {
|
||||
if (select) {
|
||||
const { beforeEach = noop, check = noop, afterEach = noop } = options || {};
|
||||
const selectOptions = getSelectOptions(select);
|
||||
const selectOptionsReversed = getSelectOptions(select).reverse();
|
||||
const iterateOptions = [...selectOptions, ...selectOptionsReversed];
|
||||
for (let i = 0; i < iterateOptions.length; i++) {
|
||||
const option = iterateOptions[i];
|
||||
// eslint-disable-next-line
|
||||
const beforeEachObj: T = await beforeEach();
|
||||
if (selectOption(select, option)) {
|
||||
// eslint-disable-next-line
|
||||
await check(beforeEachObj);
|
||||
// eslint-disable-next-line
|
||||
await afterEach();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -23,7 +23,7 @@ const rollupConfigDefaults = {
|
||||
sourcemap: true,
|
||||
esmBuild: true,
|
||||
exports: 'auto',
|
||||
pipeline: ['resolve', 'typescript', 'inject', 'commonjs', 'babel'],
|
||||
pipeline: ['typescript', 'resolve', 'inject', 'commonjs', 'babel'],
|
||||
};
|
||||
|
||||
const legacyBabelConfig = {
|
||||
@@ -152,14 +152,6 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
|
||||
|
||||
const genConfig = ({ esm, typeDeclaration }) => {
|
||||
const pipelineMap = {
|
||||
resolve: rollupResolve({
|
||||
mainFields: ['browser', 'umd:main', 'module', 'main'],
|
||||
extensions: resolve.extensions,
|
||||
rootDir: srcPath,
|
||||
customResolveOptions: {
|
||||
moduleDirectory: [...resolve.directories.map((dir) => path.resolve(projectPath, dir)), path.resolve(__dirname, 'node_modules')],
|
||||
},
|
||||
}),
|
||||
typescript: isTypeScriptProject
|
||||
? rollupTypescript({
|
||||
check: !fast,
|
||||
@@ -179,6 +171,14 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
|
||||
exclude: ['*.d.ts', '**/*.d.ts'].map(prependBackPath),
|
||||
})
|
||||
: {},
|
||||
resolve: rollupResolve({
|
||||
mainFields: ['browser', 'umd:main', 'module', 'main'],
|
||||
extensions: resolve.extensions,
|
||||
rootDir: srcPath,
|
||||
customResolveOptions: {
|
||||
moduleDirectory: [...resolve.directories.map((dir) => path.resolve(projectPath, dir)), path.resolve(__dirname, 'node_modules')],
|
||||
},
|
||||
}),
|
||||
inject: rollupInject({
|
||||
...(typeof inject === 'object' ? inject : {}),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user