diff --git a/components.d.ts b/components.d.ts index 5bbfae69..ecf244c7 100644 --- a/components.d.ts +++ b/components.d.ts @@ -239,10 +239,12 @@ declare module '@vue/runtime-core' { IcoConverter: typeof import('./src/tools/ico-converter/ico-converter.vue')['default'] 'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default'] 'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['default'] + IconMdiCheck: typeof import('~icons/mdi/check')['default'] IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default'] IconMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default'] IconMdiClose: typeof import('~icons/mdi/close')['default'] IconMdiContentCopy: typeof import('~icons/mdi/content-copy')['default'] + IconMdiDownload: typeof import('~icons/mdi/download')['default'] IconMdiEye: typeof import('~icons/mdi/eye')['default'] IconMdiEyeOff: typeof import('~icons/mdi/eye-off')['default'] IconMdiHeart: typeof import('~icons/mdi/heart')['default'] @@ -374,18 +376,29 @@ declare module '@vue/runtime-core' { NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] NButton: typeof import('naive-ui')['NButton'] NCard: typeof import('naive-ui')['NCard'] + NCheckbox: typeof import('naive-ui')['NCheckbox'] + NCheckboxGroup: typeof import('naive-ui')['NCheckboxGroup'] NCode: typeof import('naive-ui')['NCode'] + NColorPicker: typeof import('naive-ui')['NColorPicker'] NConfigProvider: typeof import('naive-ui')['NConfigProvider'] + NDataTable: typeof import('naive-ui')['NDataTable'] + NDatePicker: typeof import('naive-ui')['NDatePicker'] NDivider: typeof import('naive-ui')['NDivider'] + NDynamicInput: typeof import('naive-ui')['NDynamicInput'] NEllipsis: typeof import('naive-ui')['NEllipsis'] + NForm: typeof import('naive-ui')['NForm'] NFormItem: typeof import('naive-ui')['NFormItem'] + NGi: typeof import('naive-ui')['NGi'] NginxFormatter: typeof import('./src/tools/nginx-formatter/nginx-formatter.vue')['default'] NginxMemo: typeof import('./src/tools/nginx-memo/nginx-memo.vue')['default'] 'NginxMemo.content': typeof import('./src/tools/nginx-memo/nginx-memo.content.md')['default'] + NGrid: typeof import('naive-ui')['NGrid'] NH1: typeof import('naive-ui')['NH1'] NH3: typeof import('naive-ui')['NH3'] NicewareBytesToPassphrase: typeof import('./src/tools/niceware-bytes-to-passphrase/niceware-bytes-to-passphrase.vue')['default'] NIcon: typeof import('naive-ui')['NIcon'] + NImage: typeof import('naive-ui')['NImage'] + NInput: typeof import('naive-ui')['NInput'] NInputNumber: typeof import('naive-ui')['NInputNumber'] NInputNumberI18n: typeof import('./src/ui/n-input-number-i18n/n-input-number-i18n.vue')['default'] 'NInputNumberI18n.demo': typeof import('./src/ui/n-input-number-i18n/n-input-number-i18n.demo.vue')['default'] @@ -393,12 +406,18 @@ declare module '@vue/runtime-core' { NLayoutSider: typeof import('naive-ui')['NLayoutSider'] NMenu: typeof import('naive-ui')['NMenu'] NP: typeof import('naive-ui')['NP'] + NRadio: typeof import('naive-ui')['NRadio'] + NRadioGroup: typeof import('naive-ui')['NRadioGroup'] NScrollbar: typeof import('naive-ui')['NScrollbar'] NSelect: typeof import('naive-ui')['NSelect'] + NSlider: typeof import('naive-ui')['NSlider'] NSpace: typeof import('naive-ui')['NSpace'] + NSpin: typeof import('naive-ui')['NSpin'] NStatistic: typeof import('naive-ui')['NStatistic'] NSwitch: typeof import('naive-ui')['NSwitch'] NTable: typeof import('naive-ui')['NTable'] + NTabPane: typeof import('naive-ui')['NTabPane'] + NTabs: typeof import('naive-ui')['NTabs'] NText: typeof import('naive-ui')['NText'] NTooltip: typeof import('naive-ui')['NTooltip'] NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default'] diff --git a/locales/ar.yml b/locales/ar.yml index c144ed05..6b8ffa50 100644 --- a/locales/ar.yml +++ b/locales/ar.yml @@ -730,6 +730,7 @@ tools: label-remove-duplicates: إزالة التكرارات label-convert-to-lowercase: تحويل إلى أحرف صغيرة label-keep-line-breaks: الحفاظ على فواصل الأسطر + label-output-as-column: Output as column label-sort-list: قائمة الفرز placeholder-sort-alphabetically: فرز أبجديًا label-items-separator: فاصل العناصر diff --git a/locales/da.yml b/locales/da.yml index c279c393..aa3e0a4b 100644 --- a/locales/da.yml +++ b/locales/da.yml @@ -725,6 +725,7 @@ tools: label-remove-duplicates: Fjern dubletter label-convert-to-lowercase: Konvertér til små bogstaver label-keep-line-breaks: Behold linjeskift + label-output-as-column: Output as column label-sort-list: Sortér liste placeholder-sort-alphabetically: Sortér alfabetisk label-items-separator: Elementseparator diff --git a/locales/de.yml b/locales/de.yml index 5635db90..cc12e7b3 100644 --- a/locales/de.yml +++ b/locales/de.yml @@ -818,6 +818,7 @@ tools: label-remove-duplicates: Duplikate entfernen label-convert-to-lowercase: In Kleinbuchstaben umwandeln label-keep-line-breaks: Zeilenumbrüche beibehalten + label-output-as-column: Output as column label-sort-list: Liste sortieren placeholder-sort-alphabetically: Alphabetisch sortieren label-items-separator: Elementtrennzeichen diff --git a/locales/en.yml b/locales/en.yml index 33f8c18b..ca72bf40 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -479,6 +479,7 @@ tools: label-remove-duplicates: Remove duplicates label-convert-to-lowercase: Convert to lowercase label-keep-line-breaks: Keep line breaks + label-output-as-column: Output as column label-sort-list: Sort list placeholder-sort-alphabetically: Sort alphabetically label-items-separator: Items Separator diff --git a/locales/es.yml b/locales/es.yml index 6a207e05..6c3df5da 100644 --- a/locales/es.yml +++ b/locales/es.yml @@ -501,6 +501,7 @@ tools: label-remove-duplicates: Eliminar duplicados label-convert-to-lowercase: Convertir a minúsculas label-keep-line-breaks: Mantener saltos de línea + label-output-as-column: Output as column label-sort-list: Ordenar lista placeholder-sort-alphabetically: Ordenar alfabéticamente label-items-separator: Separador de artículos diff --git a/locales/fr.yml b/locales/fr.yml index 3e125301..4b624a97 100644 --- a/locales/fr.yml +++ b/locales/fr.yml @@ -3856,6 +3856,7 @@ tools: label-convert-to-lowercase: Convertir en minuscules label-items-separator: Séparateur d'articles label-keep-line-breaks: Gardez les pauses de ligne + label-output-as-column: Output as column label-no-sort: Pas de tri label-remove-duplicates: Supprimer les doublons label-sort-asc-binary: Trier ASC (binaire) diff --git a/locales/ga.yml b/locales/ga.yml index 14a404f7..1185b7c2 100644 --- a/locales/ga.yml +++ b/locales/ga.yml @@ -822,6 +822,7 @@ tools: label-remove-duplicates: Bain dúblaigh label-convert-to-lowercase: Tiontaigh go litreacha beaga label-keep-line-breaks: Coinnigh briseadh líne + label-output-as-column: Output as column label-sort-list: Liosta sórtála placeholder-sort-alphabetically: Sórtáil in ord aibítre label-items-separator: Deighilteoir Míreanna diff --git a/locales/it.yml b/locales/it.yml index 9a1e38ed..e51eb5ea 100644 --- a/locales/it.yml +++ b/locales/it.yml @@ -746,6 +746,7 @@ tools: label-remove-duplicates: Rimuovi i duplicati label-convert-to-lowercase: Converti in minuscolo label-keep-line-breaks: Mantieni le interruzioni di riga + label-output-as-column: Output as column label-sort-list: Ordina elenco placeholder-sort-alphabetically: Ordina alfabeticamente label-items-separator: Separatore di elementi diff --git a/locales/ko.yml b/locales/ko.yml index 7f98fd9d..b5e172b2 100644 --- a/locales/ko.yml +++ b/locales/ko.yml @@ -615,6 +615,7 @@ tools: label-remove-duplicates: 중복 제거 label-convert-to-lowercase: 소문자로 변환 label-keep-line-breaks: 줄 바꿈을 유지하세요 + label-output-as-column: Output as column label-sort-list: 목록 정렬 placeholder-sort-alphabetically: 알파벳순으로 정렬 label-items-separator: 항목 구분 기호 diff --git a/locales/nl.yml b/locales/nl.yml index e0de204b..5a321078 100644 --- a/locales/nl.yml +++ b/locales/nl.yml @@ -717,6 +717,7 @@ tools: label-remove-duplicates: Duplicaten verwijderen label-convert-to-lowercase: Omzetten naar kleine letters label-keep-line-breaks: Regeleinden behouden + label-output-as-column: Uitvoer als kolom label-sort-list: Lijst sorteren placeholder-sort-alphabetically: Alfabetisch sorteren label-items-separator: Items scheidingsteken diff --git a/locales/no.yml b/locales/no.yml index 7825e47a..7e04a436 100644 --- a/locales/no.yml +++ b/locales/no.yml @@ -775,6 +775,7 @@ tools: label-remove-duplicates: Fjern duplikater label-convert-to-lowercase: Konverter til små bokstaver label-keep-line-breaks: Behold linjeskift + label-output-as-column: Output as column label-sort-list: Sorter liste placeholder-sort-alphabetically: Sorter alfabetisk label-items-separator: Elementseparator diff --git a/locales/pl.yml b/locales/pl.yml index c9d2aaff..cb719e21 100644 --- a/locales/pl.yml +++ b/locales/pl.yml @@ -494,6 +494,7 @@ tools: label-remove-duplicates: Usuń duplikaty label-convert-to-lowercase: Zamień na małe litery label-keep-line-breaks: Zachowaj podziały wierszy + label-output-as-column: Output as column label-sort-list: Sortuj listę placeholder-sort-alphabetically: Sortuj alfabetycznie label-items-separator: Separator elementów diff --git a/locales/pt.yml b/locales/pt.yml index 5fa8e5f8..3923a245 100644 --- a/locales/pt.yml +++ b/locales/pt.yml @@ -500,6 +500,7 @@ tools: label-remove-duplicates: Remover duplicatas label-convert-to-lowercase: Converter para minúsculas label-keep-line-breaks: Manter quebras de linha + label-output-as-column: Output as column label-sort-list: Lista de classificação placeholder-sort-alphabetically: Classificar em ordem alfabética label-items-separator: Separador de Itens diff --git a/locales/ru.yml b/locales/ru.yml index e62ec92a..bfaf376c 100644 --- a/locales/ru.yml +++ b/locales/ru.yml @@ -765,6 +765,7 @@ tools: label-remove-duplicates: Удалить дубликаты label-convert-to-lowercase: Преобразовать в нижний регистр label-keep-line-breaks: Сохраняйте разрывы строк + label-output-as-column: Output as column label-sort-list: Сортировать список placeholder-sort-alphabetically: Сортировать по алфавиту label-items-separator: Разделитель элементов diff --git a/locales/tr.yml b/locales/tr.yml index 05ab144c..2d362e9a 100644 --- a/locales/tr.yml +++ b/locales/tr.yml @@ -696,6 +696,7 @@ tools: label-remove-duplicates: Yinelenenleri kaldır label-convert-to-lowercase: Küçük harfe dönüştür label-keep-line-breaks: Satır sonlarını koruyun + label-output-as-column: Output as column label-sort-list: Sıralama listesi placeholder-sort-alphabetically: Alfabetik olarak sırala label-items-separator: Öğe Ayırıcı diff --git a/locales/uk.yml b/locales/uk.yml index c74ed133..25d0f6a1 100644 --- a/locales/uk.yml +++ b/locales/uk.yml @@ -756,6 +756,7 @@ tools: label-remove-duplicates: Видалити дублікати label-convert-to-lowercase: Перетворити на малі регістри label-keep-line-breaks: Зберігати розриви рядків + label-output-as-column: Output as column label-sort-list: Сортувати список placeholder-sort-alphabetically: Сортувати за алфавітом label-items-separator: Роздільник елементів diff --git a/locales/vi.yml b/locales/vi.yml index 2776a414..559422ab 100644 --- a/locales/vi.yml +++ b/locales/vi.yml @@ -765,6 +765,7 @@ tools: label-remove-duplicates: Xóa các bản sao label-convert-to-lowercase: Chuyển đổi thành chữ thường label-keep-line-breaks: Giữ ngắt dòng + label-output-as-column: Output as column label-sort-list: Sắp xếp danh sách placeholder-sort-alphabetically: Sắp xếp theo thứ tự bảng chữ cái label-items-separator: Bộ phân tách mục diff --git a/locales/zh.yml b/locales/zh.yml index 8500ef48..95fca167 100644 --- a/locales/zh.yml +++ b/locales/zh.yml @@ -438,6 +438,7 @@ tools: label-remove-duplicates: 移除重复项 label-convert-to-lowercase: 转换为小写 label-keep-line-breaks: 保留换行符 + label-output-as-column: Output as column label-sort-list: 排序列表 placeholder-sort-alphabetically: 按字母顺序排序 label-items-separator: 项分隔符 diff --git a/src/components/FormatTransformer.vue b/src/components/FormatTransformer.vue index 1b374be0..45cbdd9a 100644 --- a/src/components/FormatTransformer.vue +++ b/src/components/FormatTransformer.vue @@ -5,6 +5,7 @@ import type { UseValidationRule } from '@/composable/validation'; import CInputText from '@/ui/c-input-text/c-input-text.vue'; import { useDownloadFileFromBase64 } from '@/composable/downloadBase64'; import { translate as t } from '@/plugins/i18n.plugin'; +import { useAppTheme } from '@/ui/theme/themes'; const props = withDefaults( defineProps<{ @@ -18,6 +19,9 @@ const props = withDefaults( downloadFileName?: string downloadButtonText?: string rows?: number + inputLineNumbers?: boolean + inputMaxRows?: number + inputAutosize?: boolean }>(), { transformer: _.identity, @@ -30,19 +34,125 @@ const props = withDefaults( downloadFileName: '', downloadButtonText: t('formatTransformer.download'), rows: 15, + inputLineNumbers: false, + inputMaxRows: undefined, + inputAutosize: true, }, ); const { transformer, inputValidationRules, inputLabel, outputLabel, outputLanguage, - inputPlaceholder, inputDefault, downloadFileName, downloadButtonText, rows, + inputPlaceholder, inputDefault, downloadFileName, downloadButtonText, rows, inputLineNumbers, inputMaxRows, inputAutosize, } = toRefs(props); +const appTheme = useAppTheme(); + const inputElement = ref(); +const textareaElement = computed(() => { + const textarea = inputElement.value?.textareaRef; + if (!textarea) { + return null; + } + + if (typeof textarea === 'object' && 'addEventListener' in textarea && 'scrollTop' in textarea) { + return textarea as HTMLTextAreaElement; + } + + if (typeof textarea === 'object' && 'value' in textarea) { + const element = (textarea as { value?: unknown }).value; + if (element && typeof element === 'object' && 'addEventListener' in element && 'scrollTop' in element) { + return element as HTMLTextAreaElement; + } + } + + return null; +}); const input = ref(inputDefault.value); const output = computed(() => transformer.value(input.value)); +const lineCount = computed(() => { + if (input.value === '') { + return 1; + } + + return input.value.split(/\r\n|\r|\n/).length; +}); + +const lineNumbersText = computed(() => { + if (!inputLineNumbers.value) { + return ''; + } + + return Array.from({ length: lineCount.value }, (_, index) => index + 1).join('\n'); +}); + +const lineNumberGutterWidth = computed(() => Math.max(1, `${lineCount.value}`.length)); +const lineNumbersOffset = ref(0); +const lineNumbersHeight = ref(0); +const lineNumbersPaddingTop = ref(''); +const lineNumbersPaddingBottom = ref(''); +const lineNumbersLineHeight = ref(''); +const lineNumbersFontSize = ref(''); + +watch( + () => ({ + textarea: textareaElement.value, + enabled: inputLineNumbers.value, + }), + ({ textarea, enabled }, _, onCleanup) => { + if (!enabled || !textarea) { + lineNumbersOffset.value = 0; + lineNumbersHeight.value = 0; + lineNumbersPaddingTop.value = ''; + lineNumbersPaddingBottom.value = ''; + lineNumbersLineHeight.value = ''; + lineNumbersFontSize.value = ''; + return; + } + + const updateSize = () => { + lineNumbersHeight.value = textarea.clientHeight; + lineNumbersOffset.value = textarea.scrollTop; + const computedStyle = window.getComputedStyle(textarea); + lineNumbersPaddingTop.value = computedStyle.paddingTop; + lineNumbersPaddingBottom.value = computedStyle.paddingBottom; + lineNumbersLineHeight.value = computedStyle.lineHeight; + lineNumbersFontSize.value = computedStyle.fontSize; + }; + + const handleScroll = () => { + lineNumbersOffset.value = textarea.scrollTop; + }; + + updateSize(); + const resizeObserver = new ResizeObserver(updateSize); + resizeObserver.observe(textarea); + textarea.addEventListener('scroll', handleScroll); + + onCleanup(() => { + textarea.removeEventListener('scroll', handleScroll); + resizeObserver.disconnect(); + }); + }, + { immediate: true }, +); + +watch( + input, + () => nextTick(() => { + const textarea = textareaElement.value; + if (textarea) { + lineNumbersOffset.value = textarea.scrollTop; + } + }), + { flush: 'post' }, +); + +function focusInput() { + inputElement.value?.focus?.(); +} + const outputBase64 = computed(() => Base64.encode(output.value)); const { download } = useDownloadFileFromBase64( { @@ -58,14 +168,33 @@ const { download } = useDownloadFileFromBase64( :placeholder="inputPlaceholder" :label="inputLabel" :rows="rows" - autosize + :max-rows="inputMaxRows" + :autosize="inputAutosize" raw-text multiline test-id="input" :validation-rules="inputValidationRules" monospace mb-1 - /> + > + +
@@ -80,3 +209,26 @@ const { download } = useDownloadFileFromBase64(
+ + diff --git a/src/tools/list-converter/list-converter.e2e.spec.ts b/src/tools/list-converter/list-converter.e2e.spec.ts index d470d4e3..d2b7ae48 100644 --- a/src/tools/list-converter/list-converter.e2e.spec.ts +++ b/src/tools/list-converter/list-converter.e2e.spec.ts @@ -36,4 +36,17 @@ test.describe('Tool - List converter', () => { const result = await page.getByTestId('area-content').innerText(); expect(result.trim()).toEqual('\'1\', \'2\', \'4\', \'3\', \'5\''); }); + + test('List input should be converted to column output and strip wrappers', async ({ page }) => { + await page.getByTestId('input').fill('(\'test\',\'test2\')'); + await page.getByTestId('outputAsColumn').check(); + await page.getByTestId('splitBySeparator').fill(','); + await page.getByTestId('itemPrefix').fill('\''); + await page.getByTestId('itemSuffix').fill('\''); + await page.getByTestId('listPrefix').fill('('); + await page.getByTestId('listSuffix').fill(')'); + + const result = await page.getByTestId('area-content').innerText(); + expect(result.trim()).toEqual('test\ntest2'); + }); }); diff --git a/src/tools/list-converter/list-converter.models.test.ts b/src/tools/list-converter/list-converter.models.test.ts index db264092..776f2cf4 100644 --- a/src/tools/list-converter/list-converter.models.test.ts +++ b/src/tools/list-converter/list-converter.models.test.ts @@ -85,6 +85,36 @@ describe('list-converter', () => { expect(convert(input, options)).toEqual(expected); }); + it('should output as column', () => { + const options: ConvertOptions = { + trimItems: true, + outputAsColumn: true, + splitBySeparator: ',', + }; + const input = '1,2,3'; + const expected = `1 +2 +3`; + expect(convert(input, options)).toEqual(expected); + }); + + it('should strip list and item wrappers when outputting as column', () => { + const options: ConvertOptions = { + trimItems: true, + outputAsColumn: true, + splitBySeparator: ',', + itemPrefix: '\'', + itemSuffix: '\'', + listPrefix: '(', + listSuffix: ')', + }; + const input = '(\'1\',\'2\',\'3\')'; + const expected = `1 +2 +3`; + expect(convert(input, options)).toEqual(expected); + }); + it('should sort by asc-num', () => { const options: ConvertOptions = { trimItems: true, diff --git a/src/tools/list-converter/list-converter.models.ts b/src/tools/list-converter/list-converter.models.ts index 489afae9..40947191 100644 --- a/src/tools/list-converter/list-converter.models.ts +++ b/src/tools/list-converter/list-converter.models.ts @@ -9,14 +9,51 @@ function whenever(condition: boolean | undefined, fn: (value: T) => R) { condition ? fn(value) : value; } +function escapeRegExp(value: string) { + return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +} + +function buildPrefixRegExp(userPattern?: string, autoLiteral?: string) { + const parts = [userPattern, autoLiteral ? escapeRegExp(autoLiteral) : undefined].filter(Boolean) as string[]; + if (parts.length === 0) { + return null; + } + return new RegExp(`^(?:${parts.join('|')})`, 'g'); +} + +function buildSuffixRegExp(userPattern?: string, autoLiteral?: string) { + const parts = [userPattern, autoLiteral ? escapeRegExp(autoLiteral) : undefined].filter(Boolean) as string[]; + if (parts.length === 0) { + return null; + } + return new RegExp(`(?:${parts.join('|')})$`, 'g'); +} + function convert(list: string, options: ConvertOptions): string { - const lineBreak = options.keepLineBreaks ? '\n' : ''; + const outputAsColumn = options.outputAsColumn ?? false; + const lineBreak = outputAsColumn || options.keepLineBreaks ? '\n' : ''; + const itemsSeparator = outputAsColumn ? '' : (options.itemsSeparator || ''); + const itemPrefix = outputAsColumn ? '' : (options.itemPrefix || ''); + const itemSuffix = outputAsColumn ? '' : (options.itemSuffix || ''); + const listPrefix = outputAsColumn ? '' : (options.listPrefix || ''); + const listSuffix = outputAsColumn ? '' : (options.listSuffix || ''); const splitSep = options.splitBySeparator ? `${options.splitBySeparator}|` : ''; const splitRegExp = new RegExp(`(?:${splitSep}\\n)`, 'g'); const filterRegExp = options.filterRegex ? new RegExp(options.filterRegex, 'v') : null; const notFilterRegExp = options.notFilterRegex ? new RegExp(options.notFilterRegex, 'v') : null; - return _.chain(list) + const removeItemPrefixRegExp = buildPrefixRegExp(options.removeItemPrefix, outputAsColumn ? options.itemPrefix : undefined); + const removeItemSuffixRegExp = buildSuffixRegExp(options.removeItemSuffix, outputAsColumn ? options.itemSuffix : undefined); + + let sourceList = list; + if (outputAsColumn && options.listPrefix) { + sourceList = sourceList.replace(new RegExp(`^${escapeRegExp(options.listPrefix)}`), ''); + } + if (outputAsColumn && options.listSuffix) { + sourceList = sourceList.replace(new RegExp(`${escapeRegExp(options.listSuffix)}$`), ''); + } + + return _.chain(sourceList) .thru(whenever(options.lowerCase, text => text.toLowerCase())) .split(splitRegExp) .thru(whenever(options.removeDuplicates, _.uniq)) @@ -26,10 +63,10 @@ function convert(list: string, options: ConvertOptions): string { .filter(text => notFilterRegExp === null || !notFilterRegExp?.test(text)) .thru(whenever(!!options.sortList, parts => parts.sort(byOrder({ order: options.sortList })))) .without('') - .map(p => options.removeItemPrefix ? p.replace(new RegExp(`^${options.removeItemPrefix}`, 'g'), '') : p) - .map(p => options.removeItemSuffix ? p.replace(new RegExp(`${options.removeItemSuffix}$`, 'g'), '') : p) - .map(p => (options.itemPrefix || '') + p + (options.itemSuffix || '')) - .join((options.itemsSeparator || '') + lineBreak) - .thru(text => [options.listPrefix, text, options.listSuffix].filter(l => l).join(lineBreak)) + .map(p => removeItemPrefixRegExp ? p.replace(removeItemPrefixRegExp, '') : p) + .map(p => removeItemSuffixRegExp ? p.replace(removeItemSuffixRegExp, '') : p) + .map(p => itemPrefix + p + itemSuffix) + .join(itemsSeparator + lineBreak) + .thru(text => [listPrefix, text, listSuffix].filter(l => l).join(lineBreak)) .value(); } diff --git a/src/tools/list-converter/list-converter.types.ts b/src/tools/list-converter/list-converter.types.ts index 3374078f..0b9e156c 100644 --- a/src/tools/list-converter/list-converter.types.ts +++ b/src/tools/list-converter/list-converter.types.ts @@ -17,4 +17,5 @@ export interface ConvertOptions { keepLineBreaks?: boolean filterRegex?: string notFilterRegex?: string + outputAsColumn?: boolean } diff --git a/src/tools/list-converter/list-converter.vue b/src/tools/list-converter/list-converter.vue index 5f0ebebc..01491aaa 100644 --- a/src/tools/list-converter/list-converter.vue +++ b/src/tools/list-converter/list-converter.vue @@ -51,6 +51,7 @@ const conversionConfig = useStorage('list-converter:conversionCo trimItems: true, removeDuplicates: true, keepLineBreaks: false, + outputAsColumn: false, itemPrefix: '', itemSuffix: '', removeItemPrefix: '', @@ -92,7 +93,10 @@ function transformer(value: string) { - + + + +
@@ -117,6 +121,8 @@ function transformer(value: string) { label-width="120px" label-align="right" mb-2 + :disabled="conversionConfig.outputAsColumn" + test-id="itemsSeparator" :placeholder="t('tools.list-converter.texts.placeholder-items-separator')" /> @@ -127,6 +133,7 @@ function transformer(value: string) { label-width="120px" label-align="right" mb-2 + test-id="splitBySeparator" :placeholder="t('tools.list-converter.texts.placeholder-separator-for-splitting')" /> @@ -191,5 +198,8 @@ function transformer(value: string) { :output-label="t('tools.list-converter.texts.output-label-your-transformed-data')" :transformer="transformer" download-file-name="output.txt" + input-line-numbers + :rows="25" + :input-autosize="false" /> diff --git a/src/ui/c-input-text/c-input-text.demo.vue b/src/ui/c-input-text/c-input-text.demo.vue index 0181e7c3..caefac9c 100644 --- a/src/ui/c-input-text/c-input-text.demo.vue +++ b/src/ui/c-input-text/c-input-text.demo.vue @@ -1,10 +1,53 @@ + + diff --git a/src/ui/c-input-text/c-input-text.vue b/src/ui/c-input-text/c-input-text.vue index 54fd1a98..4bb86f3f 100644 --- a/src/ui/c-input-text/c-input-text.vue +++ b/src/ui/c-input-text/c-input-text.vue @@ -28,6 +28,7 @@ const props = withDefaults( type?: 'text' | 'password' multiline?: boolean rows?: number | string + maxRows?: number | string autosize?: boolean autofocus?: boolean monospace?: boolean @@ -56,6 +57,7 @@ const props = withDefaults( type: 'text', multiline: false, rows: 3, + maxRows: undefined, autosize: false, autofocus: false, monospace: false, @@ -67,7 +69,7 @@ const emit = defineEmits(['update:value']); const value = useVModel(props, 'value', emit); const showPassword = ref(false); -const { id, placeholder, label, validationRules, labelPosition, labelWidth, labelAlign, autosize, readonly, disabled, clearable, type, multiline, rows, rawText, autofocus, monospace, pasteHtml } = toRefs(props); +const { id, placeholder, label, validationRules, labelPosition, labelWidth, labelAlign, autosize, readonly, disabled, clearable, type, multiline, rows, maxRows, rawText, autofocus, monospace, pasteHtml } = toRefs(props); const validation = props.validation @@ -107,7 +109,7 @@ function onPasteInputHtml(evt: ClipboardEvent) { } watch( - [value, autosize, multiline, inputWrapperRef, textareaRef], + [value, autosize, multiline, maxRows, inputWrapperRef, textareaRef], () => nextTick(() => { if (props.multiline && autosize.value) { resizeTextarea(); @@ -134,6 +136,26 @@ function checkOverflow(el: HTMLElement) { return isOverflowing; } +function getMaxHeight(textarea: HTMLTextAreaElement) { + const maxRowsValue = Number(maxRows.value); + if (!Number.isFinite(maxRowsValue) || maxRowsValue <= 0) { + return null; + } + + const computedStyle = window.getComputedStyle(textarea); + const lineHeight = Number.parseFloat(computedStyle.lineHeight); + const paddingTop = Number.parseFloat(computedStyle.paddingTop); + const paddingBottom = Number.parseFloat(computedStyle.paddingBottom); + const borderTop = Number.parseFloat(computedStyle.borderTopWidth); + const borderBottom = Number.parseFloat(computedStyle.borderBottomWidth); + + if (!Number.isFinite(lineHeight)) { + return null; + } + + return (lineHeight * maxRowsValue) + paddingTop + paddingBottom + borderTop + borderBottom; +} + function resizeTextarea() { if (textareaRef.value === undefined) { return; // cannot chnge textarea if element is not available @@ -143,13 +165,32 @@ function resizeTextarea() { return; // textarea wont be displayed if multiline === false } - if (!checkOverflow(textareaRef.value)) { + const textAreaElement = textareaRef.value!; + const maxHeight = getMaxHeight(textAreaElement); + + if (maxHeight !== null) { + textAreaElement.style.maxHeight = `${maxHeight}px`; + } + else { + textAreaElement.style.maxHeight = ''; + textAreaElement.style.overflowY = ''; + } + + if (!checkOverflow(textAreaElement)) { + if (maxHeight !== null) { + textAreaElement.style.overflowY = 'hidden'; + } return; } - const textAreaElement = textareaRef.value!; - const scrollHeight = textAreaElement.scrollHeight + 2; + if (maxHeight !== null) { + const cappedHeight = Math.min(scrollHeight, maxHeight); + textAreaElement.style.height = `${cappedHeight}px`; + textAreaElement.style.overflowY = scrollHeight > maxHeight ? 'auto' : 'hidden'; + return; + } + textAreaElement.style.height = `${scrollHeight}px`; }