diff --git a/packages/Select.ts b/packages/Select.ts deleted file mode 100644 index a913b1b..0000000 --- a/packages/Select.ts +++ /dev/null @@ -1,73 +0,0 @@ -// eslint-disable-next-line -const noop = (): 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 ( - select: HTMLSelectElement | null, - options?: { - beforeEach?: () => T | Promise; - check?: (input: T) => void | Promise; - afterEach?: () => void | Promise; - } -) => { - 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(); - } - } - } -}; diff --git a/rollup.config.base.js b/rollup.config.base.js index e722b1f..0ad196b 100644 --- a/rollup.config.base.js +++ b/rollup.config.base.js @@ -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 : {}), }),