@sypnia/ui 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sypnia/ui",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "The component library of Sypnia: tokens, CSS, React and Astro components.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://ui.sypnia.com",
@@ -41,6 +41,10 @@
41
41
  "types": "./dist/react/index.d.ts",
42
42
  "import": "./dist/react/index.js"
43
43
  },
44
+ "./react/code-editor": {
45
+ "types": "./dist/react/code-editor.d.ts",
46
+ "import": "./dist/react/code-editor.js"
47
+ },
44
48
  "./dom": {
45
49
  "types": "./dist/dom/index.d.ts",
46
50
  "import": "./dist/dom/index.js"
@@ -87,7 +91,14 @@
87
91
  }
88
92
  },
89
93
  "dependencies": {
94
+ "@codemirror/autocomplete": "^6.18.3",
95
+ "@codemirror/commands": "^6.7.1",
96
+ "@codemirror/lang-sql": "^6.8.0",
97
+ "@codemirror/language": "^6.10.6",
98
+ "@codemirror/state": "^6.4.1",
99
+ "@codemirror/view": "^6.35.0",
90
100
  "@internationalized/date": "^3.12.4",
101
+ "@lezer/highlight": "^1.2.1",
91
102
  "@tanstack/react-virtual": "^3.14.26",
92
103
  "react-aria-components": "^1.22.1"
93
104
  },
package/src/dom/search.ts CHANGED
@@ -18,12 +18,20 @@ export interface SearchHit extends SearchEntry { score: number }
18
18
  export const fold = (s: string) => s.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase();
19
19
  export const terms = (q: string) => fold(q).split(/[^\p{L}\p{N}_.-]+/u).filter((t) => t.length > 0);
20
20
 
21
+ // Each entry is folded once, not on every key.
22
+ const folded = new WeakMap<SearchEntry, { title: string; group: string; text: string; keys: string }>();
23
+ const foldedOf = (e: SearchEntry) => {
24
+ let f = folded.get(e);
25
+ if (!f) { f = { title: fold(e.title), group: fold(e.group ?? ''), text: fold(e.text ?? ''), keys: fold((e.keywords ?? []).join(' ')) }; folded.set(e, f); }
26
+ return f;
27
+ };
28
+
21
29
  export function searchEntries(entries: SearchEntry[], query: string, limit = 30): SearchHit[] {
22
30
  const words = terms(query);
23
31
  if (!words.length) return [];
24
32
  const hits: SearchHit[] = [];
25
33
  for (const e of entries) {
26
- const title = fold(e.title), group = fold(e.group ?? ''), text = fold(e.text ?? ''), keys = fold((e.keywords ?? []).join(' '));
34
+ const { title, group, text, keys } = foldedOf(e);
27
35
  let score = 0, all = true;
28
36
  for (const w of words) {
29
37
  const inTitle = title.includes(w), inKeys = keys.includes(w), inGroup = group.includes(w), inText = text.includes(w);
@@ -57,3 +65,14 @@ export function highlight(text: string, query: string): string {
57
65
  }
58
66
  return open ? `${out}</mark>` : out;
59
67
  }
68
+
69
+ /** A long text cut to about `size` characters around the first typed word, with «…» where it was cut. */
70
+ export function snippet(text: string, query: string, size = 170): string {
71
+ if (text.length <= size) return text;
72
+ const f = fold(text);
73
+ let first = -1;
74
+ for (const w of terms(query)) { const i = f.indexOf(w); if (i >= 0 && (first < 0 || i < first)) first = i; }
75
+ const from = first > 70 ? text.lastIndexOf(' ', first - 50) + 1 : 0;
76
+ const end = from + size;
77
+ return (from > 0 ? '… ' : '') + text.slice(from, end).trim() + (end < text.length ? ' …' : '');
78
+ }
package/src/i18n/index.ts CHANGED
@@ -32,7 +32,7 @@ export const strings = {
32
32
  deltaUp: 'Up {value}', deltaDown: 'Down {value}', deltaFlat: 'No change', itemsCount: '{count} items', keysCount: '{count} keys', itemsOne: '1 item', keysOne: '1 key', now: 'Now',
33
33
  primaryKey: 'Primary key', uniqueValue: 'Unique', nullable: 'Can be empty', pointsTo: 'Points to {target}', columnName: 'Column', columnType: 'Type', columnDefault: 'Default', columnRules: 'Rules',
34
34
  noLogs: 'No log lines yet', noActivity: 'Nothing has happened here yet', showExact: 'Show the exact date', showWhole: 'Show it whole',
35
- resize: 'Resize', onThisPage: 'On this page', docsNav: 'Documentation', openNav: 'Open the navigation', closeNav: 'Close the navigation', hideNav: 'Hide the navigation', showNav: 'Show the navigation', surface: 'Night or paper', language: 'Language', products: 'Products', searchDocs: 'Search the docs', searchHint: 'Search pages, sections and terms', noResultsFor: 'Nothing matches «{query}»', noResultsHint: 'Try fewer words, or another word for it.', toOpen: 'to open',
35
+ resize: 'Resize', onThisPage: 'On this page', docsNav: 'Documentation', pagesIn: 'Pages in {section}', openNav: 'Open the navigation', closeNav: 'Close the navigation', hideNav: 'Hide the navigation', showNav: 'Show the navigation', surface: 'Night or paper', language: 'Language', products: 'Products', searchDocs: 'Search the docs', searchHint: 'Search pages, sections and terms', noResultsFor: 'Nothing matches «{query}»', noResultsHint: 'Try fewer words, or another word for it.', toOpen: 'to open',
36
36
  breadcrumb: 'Breadcrumb', pager: 'Previous and next page', editPage: 'Edit this page', wasUseful: 'Was this page useful?', yes: 'Yes', no: 'No', thanks: 'Thank you. It helps us write better pages.', note: 'Note', tip: 'Tip', warning: 'Warning', danger: 'Danger', plainWords: 'In plain words',
37
37
  parameters: 'Parameters', noParams: 'It takes no parameters.', defaultValue: 'Default', errors: 'Errors', request: 'Request', response: 'Response', expected: 'You should see', authentication: 'Authentication', enlarge: 'Enlarge', inWords: 'This diagram in words', figure: 'Figure', glossary: 'Glossary', version: 'Version', changelog: 'Changes', added: 'Added', changed: 'Changed', fixed: 'Fixed', removed: 'Removed', install: 'Install', withAgent: 'With a coding agent', tool: 'Tool', setting: 'Setting', option: 'Option', envVar: 'Environment variable', type: 'Type', readOnly: 'Read only', changesData: 'Changes data',
38
38
  included: 'Included', notIncluded: 'Not included', recommended: 'Recommended', currentPlan: 'Your plan', imageFailed: 'The image could not be loaded.', linesAdded: '{count} lines added', linesRemoved: '{count} lines removed', lineAdded: 'added', lineRemoved: 'removed', linesHidden: 'Show {count} unchanged lines', noChanges: 'Both versions are the same', sortOrder: 'Order', peopleMore: '{count} more: {names}', openImage: 'Open {label}', exactValue: 'Exactly {value}', filesIn: '{count} files', checklistOf: '{done} of {total} done', markDone: 'Mark «{item}» as done', markTodo: 'Mark «{item}» as not done', diffBefore: 'Before', diffAfter: 'After', total: 'Total', activeDays: 'Days with activity', scaleLess: 'Less', scaleMore: 'More', selfTime: 'Self', share: 'Share', outOfMap: 'out of the map', casesMap: 'The use cases, in words', flowsTo: '{from} leads to {to}', flowsToWith: '{from} leads to {to}: {label}', messageFrom: '{n}. {from} to {to}: {label}', messageReply: '{n}. {from} answers {to}: {label}', relation: '{from} points to {to}', tablesCount: '{count} tables', columnsCount: '{count} columns',
@@ -68,7 +68,7 @@ export const strings = {
68
68
  deltaUp: 'Subió {value}', deltaDown: 'Bajó {value}', deltaFlat: 'Sin cambio', itemsCount: '{count} elementos', keysCount: '{count} claves', itemsOne: '1 elemento', keysOne: '1 clave', now: 'Ahora',
69
69
  primaryKey: 'Clave primaria', uniqueValue: 'Único', nullable: 'Puede quedar vacío', pointsTo: 'Apunta a {target}', columnName: 'Columna', columnType: 'Tipo', columnDefault: 'Valor por defecto', columnRules: 'Reglas',
70
70
  noLogs: 'Aún no hay líneas de registro', noActivity: 'Aún no ha pasado nada aquí', showExact: 'Mostrar la fecha exacta', showWhole: 'Mostrarlo completo',
71
- resize: 'Cambiar tamaño', onThisPage: 'En esta página', docsNav: 'Documentación', openNav: 'Abrir la navegación', closeNav: 'Cerrar la navegación', hideNav: 'Ocultar la navegación', showNav: 'Mostrar la navegación', surface: 'Noche o papel', language: 'Idioma', products: 'Productos', searchDocs: 'Buscar en la documentación', searchHint: 'Busca páginas, secciones y términos', noResultsFor: 'Nada coincide con «{query}»', noResultsHint: 'Prueba con menos palabras, o con otra palabra.', toOpen: 'para abrir',
71
+ resize: 'Cambiar tamaño', onThisPage: 'En esta página', docsNav: 'Documentación', pagesIn: 'Páginas de {section}', openNav: 'Abrir la navegación', closeNav: 'Cerrar la navegación', hideNav: 'Ocultar la navegación', showNav: 'Mostrar la navegación', surface: 'Noche o papel', language: 'Idioma', products: 'Productos', searchDocs: 'Buscar en la documentación', searchHint: 'Busca páginas, secciones y términos', noResultsFor: 'Nada coincide con «{query}»', noResultsHint: 'Prueba con menos palabras, o con otra palabra.', toOpen: 'para abrir',
72
72
  breadcrumb: 'Ruta', pager: 'Página anterior y siguiente', editPage: 'Editar esta página', wasUseful: '¿Te sirvió esta página?', yes: 'Sí', no: 'No', thanks: 'Gracias. Nos ayuda a escribir mejores páginas.', note: 'Nota', tip: 'Consejo', warning: 'Atención', danger: 'Peligro', plainWords: 'En palabras simples',
73
73
  parameters: 'Parámetros', noParams: 'No recibe parámetros.', defaultValue: 'Por defecto', errors: 'Errores', request: 'Solicitud', response: 'Respuesta', expected: 'Deberías ver', authentication: 'Autenticación', enlarge: 'Ampliar', inWords: 'Este diagrama en palabras', figure: 'Figura', glossary: 'Glosario', version: 'Versión', changelog: 'Cambios', added: 'Nuevo', changed: 'Cambió', fixed: 'Arreglado', removed: 'Quitado', install: 'Instalar', withAgent: 'Con un agente de código', tool: 'Herramienta', setting: 'Ajuste', option: 'Opción', envVar: 'Variable de entorno', type: 'Tipo', readOnly: 'Solo lee', changesData: 'Cambia datos',
74
74
  included: 'Incluido', notIncluded: 'No incluido', recommended: 'Recomendado', currentPlan: 'Tu plan', imageFailed: 'No se pudo cargar la imagen.', linesAdded: '{count} líneas agregadas', linesRemoved: '{count} líneas quitadas', lineAdded: 'agregada', lineRemoved: 'quitada', linesHidden: 'Mostrar {count} líneas sin cambios', noChanges: 'Las dos versiones son iguales', sortOrder: 'Orden', peopleMore: '{count} más: {names}', openImage: 'Abrir {label}', exactValue: 'Exactamente {value}', filesIn: '{count} archivos', checklistOf: '{done} de {total} hechos', markDone: 'Marcar «{item}» como hecho', markTodo: 'Marcar «{item}» como pendiente', diffBefore: 'Antes', diffAfter: 'Después', total: 'Total', activeDays: 'Días con actividad', scaleLess: 'Menos', scaleMore: 'Más', selfTime: 'Propio', share: 'Parte', outOfMap: 'fuera del mapa', casesMap: 'Los casos de uso, en palabras', flowsTo: '{from} lleva a {to}', flowsToWith: '{from} lleva a {to}: {label}', messageFrom: '{n}. {from} a {to}: {label}', messageReply: '{n}. {from} responde a {to}: {label}', relation: '{from} apunta a {to}', tablesCount: '{count} tablas', columnsCount: '{count} columnas',