Compare commits

..
Author SHA1 Message Date
sharevb 98db1e7238 feat(new tool): Countries/ISO 3166 Searcher
Browser countries and iso 3166 codes (and more)
FIx #983
2024-10-06 12:26:45 +02:00
10 changed files with 560 additions and 655 deletions

No files matched your search

+2 -1
View File
@@ -107,6 +107,7 @@ declare module '@vue/runtime-core' {
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
Ipv6UlaGenerator: typeof import('./src/tools/ipv6-ula-generator/ipv6-ula-generator.vue')['default']
Iso3166Searcher: typeof import('./src/tools/iso-3166-searcher/iso-3166-searcher.vue')['default']
JsonDiff: typeof import('./src/tools/json-diff/json-diff.vue')['default']
JsonMinify: typeof import('./src/tools/json-minify/json-minify.vue')['default']
JsonToCsv: typeof import('./src/tools/json-to-csv/json-to-csv.vue')['default']
@@ -129,10 +130,10 @@ declare module '@vue/runtime-core' {
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
NA: typeof import('naive-ui')['NA']
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
NCheckbox: typeof import('naive-ui')['NCheckbox']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NColorPicker: typeof import('naive-ui')['NColorPicker']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
+5 -11
View File
@@ -40,17 +40,9 @@
"@it-tools/oggen": "^1.3.0",
"@regexper/render": "^1.0.0",
"@sindresorhus/slugify": "^2.2.1",
"@tiptap/extension-color": "^2.7.4",
"@tiptap/extension-gapcursor": "^2.7.4",
"@tiptap/extension-highlight": "^2.7.4",
"@tiptap/extension-table": "^2.7.4",
"@tiptap/extension-table-cell": "^2.7.4",
"@tiptap/extension-table-header": "^2.7.4",
"@tiptap/extension-table-row": "^2.7.4",
"@tiptap/extension-text-style": "^2.7.4",
"@tiptap/pm": "2.7.4",
"@tiptap/starter-kit": "2.7.4",
"@tiptap/vue-3": "2.7.4",
"@tiptap/pm": "2.1.6",
"@tiptap/starter-kit": "2.1.6",
"@tiptap/vue-3": "2.0.3",
"@types/figlet": "^1.5.8",
"@types/markdown-it": "^13.0.7",
"@vicons/material": "^0.12.0",
@@ -62,6 +54,7 @@
"change-case": "^4.1.2",
"colord": "^2.9.3",
"composerize-ts": "^0.6.2",
"countries-db": "^1.2.0",
"country-code-lookup": "^0.1.0",
"cron-validator": "^1.3.1",
"cronstrue": "^2.26.0",
@@ -76,6 +69,7 @@
"highlight.js": "^11.7.0",
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
"iso-639-1": "^3.1.3",
"js-base64": "^3.7.6",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
+388 -368
View File
File diff suppressed because it is too large. Load diff
@@ -3,13 +3,6 @@ import { tryOnBeforeUnmount, useVModel } from '@vueuse/core';
import { Editor, EditorContent } from '@tiptap/vue-3';
import StarterKit from '@tiptap/starter-kit';
import { useThemeVars } from 'naive-ui';
import { Color } from '@tiptap/extension-color';
import TextStyle from '@tiptap/extension-text-style';
import Highlight from '@tiptap/extension-highlight';
import Table from '@tiptap/extension-table';
import TableCell from '@tiptap/extension-table-cell';
import TableHeader from '@tiptap/extension-table-header';
import TableRow from '@tiptap/extension-table-row';
import MenuBar from './menu-bar.vue';
const props = defineProps<{ html: string }>();
@@ -19,18 +12,7 @@ const html = useVModel(props, 'html', emit);
const editor = new Editor({
content: html.value,
extensions: [
StarterKit,
TextStyle,
Color,
Highlight.configure({ multicolor: true }),
Table.configure({
resizable: true,
}),
TableRow,
TableHeader,
TableCell,
],
extensions: [StarterKit],
});
editor.on('update', ({ editor }) => emit('update:html', editor.getHTML()));
@@ -81,63 +63,6 @@ tryOnBeforeUnmount(() => {
line-height: 1.1;
}
/* Table-specific styling */
table {
border-collapse: collapse;
margin: 0;
overflow: hidden;
table-layout: fixed;
width: 100%;
td,
th {
border: 1px solid v-bind('themeVars.borderColor');
box-sizing: border-box;
min-width: 1em;
padding: 6px 8px;
position: relative;
vertical-align: top;
> * {
margin-bottom: 0;
}
}
th {
background-color: v-bind('themeVars.tableHeaderColor');
font-weight: bold;
text-align: left;
}
.selectedCell:after {
content: "";
left: 0; right: 0; top: 0; bottom: 0;
pointer-events: none;
position: absolute;
z-index: 2;
}
.column-resize-handle {
background-color: v-bind('themeVars.actionColor');
bottom: -2px;
pointer-events: none;
position: absolute;
right: -2px;
top: 0;
width: 4px;
}
}
.tableWrapper {
margin: 1.5rem 0;
overflow-x: auto;
}
&.resize-cursor {
cursor: ew-resize;
cursor: col-resize;
}
code {
background-color: v-bind('themeVars.codeColor');
padding: 2px 4px;
@@ -159,6 +84,10 @@ tryOnBeforeUnmount(() => {
}
}
mark {
background-color: #faf594;
}
img {
max-width: 100%;
height: auto;
@@ -1,13 +1,13 @@
<script setup lang="ts">
import type { Component } from 'vue';
const props = defineProps<{ icon: Component; title: string; action: () => void; isActive?: () => boolean; enabled?: () => boolean }>();
const { icon, title, action, isActive, enabled } = toRefs(props);
const props = defineProps<{ icon: Component; title: string; action: () => void; isActive?: () => boolean }>();
const { icon, title, action, isActive } = toRefs(props);
</script>
<template>
<c-tooltip :tooltip="title">
<c-button circle variant="text" :disabled="enabled && !enabled()" :type="isActive?.() ? 'primary' : 'default'" @click="action">
<c-button circle variant="text" :type="isActive?.() ? 'primary' : 'default'" @click="action">
<n-icon :component="icon" />
</c-button>
</c-tooltip>
@@ -8,25 +8,15 @@ import {
ClearFormatting,
Code,
CodePlus,
ColorPicker,
ColumnInsertLeft,
ColumnInsertRight,
Cross,
H1,
H2,
H3,
H4,
Heading,
Italic,
LayersIntersect2,
LayersUnion,
LayoutDistributeHorizontal,
LayoutDistributeVertical,
List,
ListNumbers,
RowInsertBottom,
RowInsertTop,
SeparatorVertical, Strikethrough, Table, TableOff, TextWrap, Tool,
Strikethrough,
TextWrap,
} from '@vicons/tabler';
import type { Component } from 'vue';
import MenuBarItem from './menu-bar-item.vue';
@@ -39,18 +29,9 @@ type MenuItem =
icon: Component
title: string
action: () => void
value?: () => string
isActive?: () => boolean
enabled?: () => boolean
type: 'button'
}
| {
icon: Component
title: string
action: (color: string) => void
value: () => string
type: 'color'
}
| { type: 'divider' };
const items: MenuItem[] = [
@@ -160,42 +141,7 @@ const items: MenuItem[] = [
title: 'Clear format',
action: () => editor.value.chain().focus().clearNodes().unsetAllMarks().run(),
},
{
type: 'divider',
},
{
type: 'color',
title: 'Forecolor',
icon: ColorPicker,
action: color => editor.value.chain().focus().setColor(color).run(),
value: () => editor.value.getAttributes('textStyle').color,
},
{
type: 'button',
icon: ClearFormatting,
title: 'Clear Forecolor',
action: () => editor.value.chain().focus().unsetColor().run(),
},
{
type: 'divider',
},
{
type: 'color',
title: 'Highlight color',
icon: ColorPicker,
action: color => editor.value.chain().focus().setHighlight({ color }).run(),
value: () => '#FAF594',
},
{
type: 'button',
icon: ClearFormatting,
title: 'Clear Highlight',
action: () => editor.value.chain().focus().unsetHighlight().run(),
isActive: () => editor.value.isActive('highlight'),
},
{
type: 'divider',
},
{
type: 'button',
icon: ArrowBack,
@@ -208,152 +154,14 @@ const items: MenuItem[] = [
title: 'Redo',
action: () => editor.value.chain().focus().redo().run(),
},
{
type: 'divider',
},
{
type: 'button',
action: () => editor.value.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),
enabled: () => editor.value.can().insertTable(),
title: 'Insert table',
icon: Table,
},
{
type: 'divider',
},
{
type: 'button',
action: () => editor.value.chain().focus().addColumnBefore().run(),
enabled: () => editor.value.can().addColumnBefore(),
title: 'Add column before',
icon: ColumnInsertLeft,
},
{
type: 'button',
action: () => editor.value.chain().focus().addColumnAfter().run(),
enabled: () => editor.value.can().addColumnAfter(),
title: 'Add column after',
icon: ColumnInsertRight,
},
{
type: 'button',
action: () => editor.value.chain().focus().deleteColumn().run(),
enabled: () => editor.value.can().deleteColumn(),
title: 'Delete column',
icon: Cross,
},
{
type: 'divider',
},
{
type: 'button',
action: () => editor.value.chain().focus().addRowBefore().run(),
enabled: () => editor.value.can().addRowBefore(),
title: 'Add row before',
icon: RowInsertTop,
},
{
type: 'button',
action: () => editor.value.chain().focus().addRowAfter().run(),
enabled: () => editor.value.can().addRowAfter(),
title: 'Add row after',
icon: RowInsertBottom,
},
{
type: 'button',
action: () => editor.value.chain().focus().deleteRow().run(),
enabled: () => editor.value.can().deleteRow(),
title: 'Delete row',
icon: Cross,
},
{
type: 'divider',
},
{
type: 'button',
action: () => editor.value.chain().focus().deleteTable().run(),
enabled: () => editor.value.can().deleteTable(),
title: 'Delete table',
icon: TableOff,
},
{
type: 'divider',
},
{
type: 'button',
action: () => editor.value.chain().focus().mergeCells().run(),
enabled: () => editor.value.can().mergeCells(),
title: 'Merge cells',
icon: LayersUnion,
},
{
type: 'button',
action: () => editor.value.chain().focus().splitCell().run(),
enabled: () => editor.value.can().splitCell(),
title: 'Split cell',
icon: SeparatorVertical,
},
{
type: 'button',
action: () => editor.value.chain().focus().mergeOrSplit().run(),
enabled: () => editor.value.can().mergeOrSplit(),
title: 'Merge or split',
icon: LayersIntersect2,
},
{
type: 'divider',
},
{
type: 'button',
action: () => editor.value.chain().focus().toggleHeaderColumn().run(),
enabled: () => editor.value.can().toggleHeaderColumn(),
title: 'Toggle header column',
icon: LayoutDistributeVertical,
},
{
type: 'button',
action: () => editor.value.chain().focus().toggleHeaderRow().run(),
enabled: () => editor.value.can().toggleHeaderRow(),
title: 'Toggle header row',
icon: LayoutDistributeHorizontal,
},
{
type: 'button',
action: () => editor.value.chain().focus().toggleHeaderCell().run(),
enabled: () => editor.value.can().toggleHeaderCell(),
title: 'Toggle header cell',
icon: Heading,
},
{
type: 'divider',
},
{
type: 'button',
action: () => editor.value.chain().focus().fixTables().run(),
enabled: () => editor.value.can().fixTables(),
title: 'Fix tables',
icon: Tool,
},
];
</script>
<template>
<div flex flex-wrap items-center>
<div flex items-center>
<template v-for="(item, index) in items">
<n-divider v-if="item.type === 'divider'" :key="`divider${index}`" vertical />
<MenuBarItem v-else-if="item.type === 'button'" :key="index" v-bind="item" />
<c-tooltip
v-if="item.type === 'color'" :key="`color${index}`"
:tooltip="item.title"
>
<n-color-picker
style="width: 120px"
:show-alpha="false"
:actions="['confirm']"
:value="item.value()"
@confirm="item.action"
/>
</c-tooltip>
</template>
</div>
</template>
+2
View File
@@ -12,6 +12,7 @@ import { tool as jsonToXml } from './json-to-xml';
import { tool as regexTester } from './regex-tester';
import { tool as regexMemo } from './regex-memo';
import { tool as markdownToHtml } from './markdown-to-html';
import { tool as iso3166Searcher } from './iso-3166-searcher';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -184,6 +185,7 @@ export const toolsByCategory: ToolCategory[] = [
textDiff,
numeronymGenerator,
asciiTextDrawer,
iso3166Searcher,
],
},
{
+35
View File
@@ -0,0 +1,35 @@
declare module 'countries-db'{
export interface CountryInfo {
id: string
name: string
officialName: string
emoji: string
emojiUnicode: string
iso2: string
iso3: string
isoNumeric: string
geonameId: number
continentId: string
population: number
elevation: number
areaSqKm: number
coordinates: {
latitude: number
longitude: number
},
timezones: Array<string>
domain: string
currencyCode: string
currencyName: string
postalCodeFormat: string
postalCodeRegex: string
phoneCode: string
neighborCountryIds: Array<string>
languages: Array<string>
locales: Array<string>
}
export function getAllCountries(): {[id:string]: CountryInfo};
export function getCountry(id: string, property: string): string | Array<string> | number;
export function getCountry(id: string): CountryInfo;
}
+12
View File
@@ -0,0 +1,12 @@
import { Flag } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'ISO 3166 Country Codes Searcher',
path: '/iso-3166-searcher',
description: 'Allow searching for Country Code (ISO 3166) and info',
keywords: ['iso', 'iso2', 'iso3', 'phone', 'currency', 'timezones', 'domain', 'lang', 'iso3166', 'country', 'ccltd', 'searcher'],
component: () => import('./iso-3166-searcher.vue'),
icon: Flag,
createdAt: new Date('2024-04-20'),
});
@@ -0,0 +1,104 @@
<script setup lang="ts">
import CountriesDB from 'countries-db';
import ISO6391 from 'iso-639-1';
import { useFuzzySearch } from '@/composable/fuzzySearch';
import useDebouncedRef from '@/composable/debouncedref';
const searchQuery = useDebouncedRef('', 500);
const countriesSearchData = Object.entries(CountriesDB.getAllCountries()).map(([_, info]) => {
return {
iso2: info.iso2,
iso3: info.iso3,
domain: info.domain,
name: `${info.name} ${info.officialName}`,
info,
};
});
const { searchResult } = useFuzzySearch({
search: searchQuery,
data: countriesSearchData,
options: {
keys: ['name', { name: 'iso3', weight: 3 }, { name: 'iso2', weight: 2 }, 'domain'],
threshold: 0.3,
isCaseSensitive: false,
useExtendedSearch: true,
},
});
function langToName(code: string) {
const name = ISO6391.getName(code);
if (!name) {
return code;
}
return `${code} (${name})`;
}
</script>
<template>
<div mx-auto max-w-2400px important:flex-1>
<div flex items-center gap-3>
<c-input-text
v-model:value="searchQuery"
placeholder="Search Countries by name, iso2, iso3..."
mx-auto max-w-600px
>
<template #prefix>
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
</template>
</c-input-text>
</div>
<div v-if="searchQuery.trim().length > 0">
<div
v-if="searchResult.length === 0"
mt-4
text-20px
font-bold
>
No results
</div>
<div v-else>
<div mt-4 text-20px font-bold>
Search result
</div>
<n-table>
<thead>
<th>Iso2/Iso3</th>
<th>Name and Info</th>
</thead>
<tbody>
<tr v-for="(result, ix) in searchResult" :key="ix">
<td style="vertical-align: top">
<input-copyable :value="result.iso2" />
<input-copyable :value="result.iso3" />
</td>
<td>
<input-copyable label-width="150px" label="Name" label-position="left" :value="result.name" mb-1 />
<input-copyable label-width="150px" label="Official Name" label-position="left" :value="result.info.officialName" mb-1 />
<input-copyable label-width="150px" label="Domain" label-position="left" :value="result.info.domain" mb-1 />
<input-copyable label-width="150px" label="Emoji" label-position="left" :value="`${result.info.emoji} (${result.info.emojiUnicode})`" mb-1 />
<input-copyable label-width="150px" label="ISO Num" label-position="left" :value="result.info.isoNumeric" mb-1 />
<input-copyable label-width="150px" label="Continent" label-position="left" :value="result.info.continentId" mb-1 />
<input-copyable label-width="150px" label="Elevation (m)" label-position="left" :value="result.info.elevation" mb-1 />
<input-copyable label-width="150px" label="Population" label-position="left" :value="result.info.population" mb-1 />
<input-copyable label-width="150px" label="Area (km²)" label-position="left" :value="result.info.areaSqKm" mb-1 />
<input-copyable label-width="150px" label="Timezones" label-position="left" :value="result.info.timezones.join('\n')" mb-1 />
<input-copyable label-width="150px" label="Currency" label-position="left" :value="`${result.info.currencyCode} / ${result.info.currencyName}`" mb-1 />
<input-copyable label-width="150px" label="Postal Code" label-position="left" :value="`${result.info.postalCodeFormat} / ${result.info.postalCodeRegex}`" mb-1 />
<input-copyable label-width="150px" label="Phone Code" label-position="left" :value="result.info.phoneCode" mb-1 />
<input-copyable label-width="150px" label="Neighbor Countries" label-position="left" :value="result.info.neighborCountryIds.map(id => CountriesDB.getCountry(id, 'name')?.toString() || id).join(', ')" mb-1 />
<input-copyable label-width="150px" label="Languages" label-position="left" :value="result.info.languages.map(langToName).join(', ')" mb-1 />
<input-copyable label-width="150px" label="Locales" label-position="left" :value="result.info.locales.map(langToName).join(', ')" mb-1 />
<!-- //NOSONAR --><n-a :href="`https://www.openstreetmap.org/#map=5/${result.info.coordinates.latitude}/${result.info.coordinates.longitude}`" target="_blank">
&gt; See on OpenStreetMap
</n-a>
</td>
</tr>
</tbody>
</n-table>
</div>
</div>
</div>
</template>