ywana-core8 0.1.79 → 0.1.81

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.
Files changed (70) hide show
  1. package/dist/index.cjs +3493 -2320
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.css +2096 -1125
  4. package/dist/index.css.map +1 -1
  5. package/dist/index.modern.js +3493 -2320
  6. package/dist/index.modern.js.map +1 -1
  7. package/dist/index.umd.js +3493 -2320
  8. package/dist/index.umd.js.map +1 -1
  9. package/package.json +1 -1
  10. package/src/html/ExampleLayout.css +401 -0
  11. package/src/html/ExampleLayout.js +192 -0
  12. package/src/html/README-sidebar-navigation.md +195 -0
  13. package/src/html/accordion.example.js +123 -4
  14. package/src/html/accordion.example.js.backup +390 -0
  15. package/src/html/button.example.js +50 -3
  16. package/src/html/button.example.js.backup +374 -0
  17. package/src/html/button.example.new.js +416 -0
  18. package/src/html/button.js +22 -4
  19. package/src/html/checkbox.example.js +93 -4
  20. package/src/html/checkbox.example.js.backup +316 -0
  21. package/src/html/chip.example.js +108 -4
  22. package/src/html/chip.example.js.backup +355 -0
  23. package/src/html/color.example.js +108 -4
  24. package/src/html/color.example.js.backup +527 -0
  25. package/src/html/components.example.js +123 -4
  26. package/src/html/components.example.js.backup +492 -0
  27. package/src/html/convert-examples.js +183 -0
  28. package/src/html/demo-sidebar.html +410 -0
  29. package/src/html/form.example.js +93 -4
  30. package/src/html/form.example.js.backup +385 -0
  31. package/src/html/header.js +20 -3
  32. package/src/html/header2.example.js +108 -4
  33. package/src/html/header2.example.js.backup +411 -0
  34. package/src/html/icon.example.js +77 -3
  35. package/src/html/icon.example.js.backup +268 -0
  36. package/src/html/list.example.js +93 -4
  37. package/src/html/list.example.js.backup +404 -0
  38. package/src/html/progress.example.js +74 -4
  39. package/src/html/progress.example.js.backup +424 -0
  40. package/src/html/property.example.js +123 -4
  41. package/src/html/property.example.js.backup +553 -0
  42. package/src/html/radio.example.js +108 -4
  43. package/src/html/radio.example.js.backup +389 -0
  44. package/src/html/section.example.js +42 -3
  45. package/src/html/section.example.js.backup +99 -0
  46. package/src/html/switch.example.js +108 -4
  47. package/src/html/switch.example.js.backup +461 -0
  48. package/src/html/tab.example.js +93 -4
  49. package/src/html/tab.example.js.backup +446 -0
  50. package/src/html/table-export-utils.js +483 -0
  51. package/src/html/table-summary-functions.js +363 -0
  52. package/src/html/table2.css +1449 -479
  53. package/src/html/table2.example.js +2937 -512
  54. package/src/html/table2.example.js.broken +1226 -0
  55. package/src/html/table2.js +1426 -1000
  56. package/src/html/test-resize.html +279 -0
  57. package/src/html/test-selection.html +387 -0
  58. package/src/html/textfield.js +73 -7
  59. package/src/html/textfield2.example.js +108 -4
  60. package/src/html/textfield2.example.js.backup +1370 -0
  61. package/src/html/textfield2.js +19 -4
  62. package/src/html/tokenfield.example.js +108 -4
  63. package/src/html/tokenfield.example.js.backup +503 -0
  64. package/src/html/tooltip.js +21 -3
  65. package/src/html/tree.css +2 -4
  66. package/src/html/tree.example.js +93 -4
  67. package/src/html/tree.example.js.backup +475 -0
  68. package/src/html/tree.js +19 -3
  69. package/src/widgets/login/LoginBox.css +1 -0
  70. package/src/widgets/login/LoginBox.js +29 -6
@@ -0,0 +1,492 @@
1
+ import React, { useState } from 'react'
2
+ import { Thumbnail } from './thumbnail'
3
+ import { MultiSelector, ToggleButton } from './selector'
4
+ import { Text, TEXTFORMATS } from './text'
5
+ import { Button } from './button'
6
+
7
+ /**
8
+ * Ejemplos de los componentes Thumbnail, Selector y Text mejorados manteniendo 100% compatibilidad
9
+ */
10
+ export const ComponentsExamples = () => {
11
+ const [selectedOptions, setSelectedOptions] = useState(['option1'])
12
+ const [isLoading, setIsLoading] = useState(false)
13
+ const [showEmpty, setShowEmpty] = useState(false)
14
+
15
+ const sampleOptions = [
16
+ { label: 'Option 1', value: 'option1', icon: 'star' },
17
+ { label: 'Option 2', value: 'option2', icon: 'favorite' },
18
+ { label: 'Option 3', value: 'option3', icon: 'bookmark' },
19
+ { label: 'Option 4', value: 'option4', icon: 'thumb_up' },
20
+ { label: 'Option 5', value: 'option5', icon: 'check_circle' }
21
+ ]
22
+
23
+ const handleSelectorChange = (selections) => {
24
+ setSelectedOptions(selections)
25
+ console.log('Selected options:', selections)
26
+ }
27
+
28
+ const simulateLoading = () => {
29
+ setIsLoading(true)
30
+ setTimeout(() => setIsLoading(false), 2000)
31
+ }
32
+
33
+ return (
34
+ <div style={{ padding: '2rem', maxWidth: '1200px', maxHeight: '100vh', overflow: 'auto' }}>
35
+ <h1>Componentes Mejorados: Thumbnail, Selector y Text</h1>
36
+
37
+ <div style={{
38
+ background: '#f8f9fa',
39
+ padding: '1rem',
40
+ borderRadius: '8px',
41
+ marginBottom: '2rem',
42
+ border: '1px solid #e9ecef'
43
+ }}>
44
+ <h3>✅ Mejoras Implementadas (100% Compatibilidad):</h3>
45
+ <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: '1rem' }}>
46
+ <div>
47
+ <h4>🖼️ Thumbnail</h4>
48
+ <ul>
49
+ <li>PropTypes completos</li>
50
+ <li>Múltiples tamaños y formas</li>
51
+ <li>Estados loading/error</li>
52
+ <li>Placeholder y fallback</li>
53
+ <li>Clickable con overlay</li>
54
+ <li>Badges y tooltips</li>
55
+ <li>Lazy loading</li>
56
+ </ul>
57
+ </div>
58
+ <div>
59
+ <h4>🎛️ MultiSelector</h4>
60
+ <ul>
61
+ <li>Búsqueda integrada</li>
62
+ <li>Min/max selecciones</li>
63
+ <li>Variantes visuales</li>
64
+ <li>Estados loading/empty</li>
65
+ <li>Clear all button</li>
66
+ <li>Navegación por teclado</li>
67
+ <li>Accesibilidad completa</li>
68
+ </ul>
69
+ </div>
70
+ <div>
71
+ <h4>📝 Text</h4>
72
+ <ul>
73
+ <li>Nuevos formatos</li>
74
+ <li>Internacionalización</li>
75
+ <li>Copy to clipboard</li>
76
+ <li>Estados loading/skeleton</li>
77
+ <li>Truncate y styling</li>
78
+ <li>Múltiples elementos</li>
79
+ <li>Formateo avanzado</li>
80
+ </ul>
81
+ </div>
82
+ </div>
83
+ </div>
84
+
85
+ {/* Controles de demostración */}
86
+ <section style={{ marginBottom: '2rem' }}>
87
+ <h3>Controles de Demostración</h3>
88
+ <div style={{
89
+ background: '#fff',
90
+ padding: '1rem',
91
+ borderRadius: '8px',
92
+ border: '1px solid #ddd',
93
+ display: 'flex',
94
+ gap: '1rem',
95
+ alignItems: 'center',
96
+ flexWrap: 'wrap'
97
+ }}>
98
+ <Button
99
+ label="Simulate Loading"
100
+ icon="refresh"
101
+ action={simulateLoading}
102
+ disabled={isLoading}
103
+ />
104
+ <Button
105
+ label={showEmpty ? "Show Content" : "Show Empty"}
106
+ icon={showEmpty ? "visibility" : "visibility_off"}
107
+ action={() => setShowEmpty(!showEmpty)}
108
+ />
109
+ <span style={{ marginLeft: 'auto', color: '#666' }}>
110
+ Selected: [{selectedOptions.join(', ')}]
111
+ </span>
112
+ </div>
113
+ </section>
114
+
115
+ {/* Thumbnail Examples */}
116
+ <section style={{ marginBottom: '2rem' }}>
117
+ <h3>🖼️ Thumbnail Component</h3>
118
+
119
+ {/* Basic Thumbnails (Compatible) */}
120
+ <div style={{ marginBottom: '1.5rem' }}>
121
+ <h4>Básico (100% Compatible)</h4>
122
+ <div style={{ display: 'flex', gap: '1rem', alignItems: 'center', flexWrap: 'wrap' }}>
123
+ <Thumbnail
124
+ src="https://picsum.photos/200/200?random=1"
125
+ empty="https://via.placeholder.com/200x200/cccccc/666666?text=Empty"
126
+ />
127
+ <Thumbnail
128
+ src="https://picsum.photos/200/200?random=2"
129
+ objectFit="contain"
130
+ />
131
+ <Thumbnail
132
+ src=""
133
+ empty="https://via.placeholder.com/200x200/ffcccc/cc0000?text=Fallback"
134
+ />
135
+ </div>
136
+ </div>
137
+
138
+ {/* Enhanced Thumbnails */}
139
+ <div style={{ marginBottom: '1.5rem' }}>
140
+ <h4>Mejorado con Nuevas Características</h4>
141
+ <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(120px, 1fr))', gap: '1rem' }}>
142
+ <Thumbnail
143
+ src="https://picsum.photos/200/200?random=3"
144
+ size="small"
145
+ shape="circle"
146
+ bordered={true}
147
+ shadow={true}
148
+ alt="Small circular thumbnail"
149
+ />
150
+ <Thumbnail
151
+ src="https://picsum.photos/200/200?random=4"
152
+ size="medium"
153
+ shape="rounded"
154
+ clickable={true}
155
+ onClick={() => alert('Thumbnail clicked!')}
156
+ overlay={<span>Click me!</span>}
157
+ badge="NEW"
158
+ />
159
+ <Thumbnail
160
+ src="https://picsum.photos/200/200?random=5"
161
+ size="large"
162
+ shape="square"
163
+ loading="lazy"
164
+ placeholder="image"
165
+ title="Large square thumbnail"
166
+ />
167
+ <Thumbnail
168
+ src="invalid-url"
169
+ fallback="broken_image"
170
+ size="medium"
171
+ shape="circle"
172
+ onError={() => console.log('Image failed to load')}
173
+ />
174
+ </div>
175
+ </div>
176
+
177
+ {/* Thumbnail States */}
178
+ <div style={{ marginBottom: '1.5rem' }}>
179
+ <h4>Estados Especiales</h4>
180
+ <div style={{ display: 'flex', gap: '1rem', alignItems: 'center', flexWrap: 'wrap' }}>
181
+ <Thumbnail
182
+ src="https://picsum.photos/200/200?random=6"
183
+ disabled={true}
184
+ title="Disabled thumbnail"
185
+ />
186
+ <Thumbnail
187
+ src="https://picsum.photos/200/200?random=7"
188
+ loading={isLoading}
189
+ placeholder="hourglass_empty"
190
+ />
191
+ <Thumbnail
192
+ src="https://picsum.photos/200/200?random=8"
193
+ badge={42}
194
+ tooltip="Badge with number"
195
+ />
196
+ </div>
197
+ </div>
198
+ </section>
199
+
200
+ {/* MultiSelector Examples */}
201
+ <section style={{ marginBottom: '2rem' }}>
202
+ <h3>🎛️ MultiSelector Component</h3>
203
+
204
+ {/* Basic Selector (Compatible) */}
205
+ <div style={{ marginBottom: '1.5rem' }}>
206
+ <h4>Básico (100% Compatible)</h4>
207
+ <div style={{
208
+ background: '#fff',
209
+ border: '1px solid #ddd',
210
+ borderRadius: '8px',
211
+ overflow: 'hidden'
212
+ }}>
213
+ <MultiSelector
214
+ options={sampleOptions.slice(0, 3)}
215
+ onChange={handleSelectorChange}
216
+ className="basic-selector"
217
+ />
218
+ </div>
219
+ </div>
220
+
221
+ {/* Enhanced Selector */}
222
+ <div style={{ marginBottom: '1.5rem' }}>
223
+ <h4>Mejorado con Búsqueda y Controles</h4>
224
+ <div style={{
225
+ background: '#fff',
226
+ border: '1px solid #ddd',
227
+ borderRadius: '8px',
228
+ overflow: 'hidden'
229
+ }}>
230
+ <MultiSelector
231
+ options={sampleOptions}
232
+ onChange={handleSelectorChange}
233
+ searchable={true}
234
+ searchPlaceholder="Buscar opciones..."
235
+ allowClear={true}
236
+ onClear={() => console.log('Cleared all selections')}
237
+ maxSelections={3}
238
+ minSelections={1}
239
+ variant="outlined"
240
+ size="medium"
241
+ ariaLabel="Selector con búsqueda"
242
+ />
243
+ </div>
244
+ </div>
245
+
246
+ {/* Selector Variants */}
247
+ <div style={{ marginBottom: '1.5rem' }}>
248
+ <h4>Variantes Visuales</h4>
249
+ <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '1rem' }}>
250
+ <div style={{
251
+ background: '#fff',
252
+ border: '1px solid #ddd',
253
+ borderRadius: '8px',
254
+ overflow: 'hidden'
255
+ }}>
256
+ <h5 style={{ margin: '1rem', marginBottom: '0' }}>Filled Variant</h5>
257
+ <MultiSelector
258
+ options={sampleOptions.slice(0, 3)}
259
+ variant="filled"
260
+ size="small"
261
+ />
262
+ </div>
263
+ <div style={{
264
+ background: '#fff',
265
+ border: '1px solid #ddd',
266
+ borderRadius: '8px',
267
+ overflow: 'hidden'
268
+ }}>
269
+ <h5 style={{ margin: '1rem', marginBottom: '0' }}>Large Size</h5>
270
+ <MultiSelector
271
+ options={sampleOptions.slice(0, 3)}
272
+ variant="default"
273
+ size="large"
274
+ />
275
+ </div>
276
+ </div>
277
+ </div>
278
+
279
+ {/* Selector States */}
280
+ <div style={{ marginBottom: '1.5rem' }}>
281
+ <h4>Estados Especiales</h4>
282
+ <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '1rem' }}>
283
+ <div style={{
284
+ background: '#fff',
285
+ border: '1px solid #ddd',
286
+ borderRadius: '8px',
287
+ overflow: 'hidden'
288
+ }}>
289
+ <h5 style={{ margin: '1rem', marginBottom: '0' }}>Loading State</h5>
290
+ <MultiSelector
291
+ loading={isLoading}
292
+ options={[]}
293
+ />
294
+ </div>
295
+ <div style={{
296
+ background: '#fff',
297
+ border: '1px solid #ddd',
298
+ borderRadius: '8px',
299
+ overflow: 'hidden'
300
+ }}>
301
+ <h5 style={{ margin: '1rem', marginBottom: '0' }}>Empty State</h5>
302
+ <MultiSelector
303
+ empty={showEmpty}
304
+ emptyMessage="No hay opciones disponibles"
305
+ emptyIcon="inbox"
306
+ options={showEmpty ? [] : sampleOptions.slice(0, 2)}
307
+ />
308
+ </div>
309
+ </div>
310
+ </div>
311
+ </section>
312
+
313
+ {/* Text Examples */}
314
+ <section style={{ marginBottom: '2rem' }}>
315
+ <h3>📝 Text Component</h3>
316
+
317
+ {/* Basic Text (Compatible) */}
318
+ <div style={{ marginBottom: '1.5rem' }}>
319
+ <h4>Básico (100% Compatible)</h4>
320
+ <div style={{
321
+ background: '#fff',
322
+ padding: '1rem',
323
+ border: '1px solid #ddd',
324
+ borderRadius: '8px'
325
+ }}>
326
+ <Text format={TEXTFORMATS.HTML}>Este es texto HTML básico</Text><br />
327
+ <Text format={TEXTFORMATS.STRING}>Este es texto string</Text><br />
328
+ <Text className="custom-class">Texto con clase CSS</Text>
329
+ </div>
330
+ </div>
331
+
332
+ {/* Enhanced Text Formatting */}
333
+ <div style={{ marginBottom: '1.5rem' }}>
334
+ <h4>Formateo Mejorado</h4>
335
+ <div style={{
336
+ background: '#fff',
337
+ padding: '1rem',
338
+ border: '1px solid #ddd',
339
+ borderRadius: '8px',
340
+ display: 'grid',
341
+ gridTemplateColumns: '1fr 1fr',
342
+ gap: '1rem'
343
+ }}>
344
+ <div>
345
+ <Text format={TEXTFORMATS.NUMERIC}>1234567.89</Text><br />
346
+ <Text format={TEXTFORMATS.CURRENCY} currency="USD">1234.56</Text><br />
347
+ <Text format={TEXTFORMATS.PERCENTAGE}>0.75</Text><br />
348
+ <Text format={TEXTFORMATS.DATE}>2024-01-15</Text><br />
349
+ <Text format={TEXTFORMATS.TIME}>2024-01-15T14:30:00</Text><br />
350
+ </div>
351
+ <div>
352
+ <Text format={TEXTFORMATS.PHONE}>1234567890</Text><br />
353
+ <Text format={TEXTFORMATS.CAPITALIZE}>hello world</Text><br />
354
+ <Text format={TEXTFORMATS.UPPERCASE}>hello world</Text><br />
355
+ <Text format={TEXTFORMATS.LOWERCASE}>HELLO WORLD</Text><br />
356
+ <Text format={TEXTFORMATS.TRUNCATE} maxLength={20}>Este es un texto muy largo que será truncado</Text><br />
357
+ </div>
358
+ </div>
359
+ </div>
360
+
361
+ {/* Text Styling */}
362
+ <div style={{ marginBottom: '1.5rem' }}>
363
+ <h4>Estilos y Tamaños</h4>
364
+ <div style={{
365
+ background: '#fff',
366
+ padding: '1rem',
367
+ border: '1px solid #ddd',
368
+ borderRadius: '8px'
369
+ }}>
370
+ <Text size="xs">Extra small text</Text><br />
371
+ <Text size="sm">Small text</Text><br />
372
+ <Text size="md" weight="bold">Medium bold text</Text><br />
373
+ <Text size="lg" color="primary">Large primary text</Text><br />
374
+ <Text size="xl" weight="semibold" color="success">Extra large success text</Text><br />
375
+ <Text size="xxl" weight="bold" color="error" align="center">XXL error text centered</Text><br />
376
+ </div>
377
+ </div>
378
+
379
+ {/* Text Features */}
380
+ <div style={{ marginBottom: '1.5rem' }}>
381
+ <h4>Características Especiales</h4>
382
+ <div style={{
383
+ background: '#fff',
384
+ padding: '1rem',
385
+ border: '1px solid #ddd',
386
+ borderRadius: '8px'
387
+ }}>
388
+ <Text copyable={true}>Texto copiable - haz click para copiar</Text><br />
389
+ <Text loading={isLoading}>Texto con estado de carga</Text><br />
390
+ <Text skeleton={isLoading}>Texto con skeleton placeholder</Text><br />
391
+ <Text fallback="Texto por defecto">{showEmpty ? '' : 'Texto con fallback'}</Text><br />
392
+ <Text as="h3" size="lg" weight="bold">Texto renderizado como H3</Text><br />
393
+ <Text decoration="underline" transform="capitalize">texto subrayado y capitalizado</Text><br />
394
+ </div>
395
+ </div>
396
+
397
+ {/* Text States */}
398
+ <div style={{ marginBottom: '1.5rem' }}>
399
+ <h4>Estados y Casos Especiales</h4>
400
+ <div style={{
401
+ background: '#fff',
402
+ padding: '1rem',
403
+ border: '1px solid #ddd',
404
+ borderRadius: '8px',
405
+ display: 'grid',
406
+ gridTemplateColumns: '1fr 1fr',
407
+ gap: '1rem'
408
+ }}>
409
+ <div>
410
+ <Text>Texto normal</Text><br />
411
+ <Text selectable={false}>Texto no seleccionable</Text><br />
412
+ <Text truncate={true}>Texto con truncate automático que se corta</Text><br />
413
+ </div>
414
+ <div>
415
+ <Text format={TEXTFORMATS.EMAIL}>usuario@ejemplo.com</Text><br />
416
+ <Text format={TEXTFORMATS.URL}>https://www.ejemplo.com</Text><br />
417
+ <Text locale="es-ES" format={TEXTFORMATS.DATE}>2024-01-15</Text><br />
418
+ </div>
419
+ </div>
420
+ </div>
421
+ </section>
422
+
423
+ {/* Comparación antes/después */}
424
+ <section style={{ marginBottom: '2rem' }}>
425
+ <h3>Comparación: Componentes Originales vs Mejorados</h3>
426
+ <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '1rem' }}>
427
+ <div style={{
428
+ background: '#ffebee',
429
+ padding: '1rem',
430
+ borderRadius: '4px',
431
+ border: '1px solid #ffcdd2'
432
+ }}>
433
+ <h4>❌ Componentes Originales</h4>
434
+ <ul>
435
+ <li><strong>Thumbnail:</strong> Básico, sin estados</li>
436
+ <li><strong>Selector:</strong> Funcional pero limitado</li>
437
+ <li><strong>Text:</strong> Pocos formatos, sin styling</li>
438
+ <li>Sin PropTypes ni validación</li>
439
+ <li>Sin accesibilidad</li>
440
+ <li>Sin estados loading/error</li>
441
+ <li>CSS básico sin responsive</li>
442
+ </ul>
443
+ </div>
444
+ <div style={{
445
+ background: '#e8f5e8',
446
+ padding: '1rem',
447
+ borderRadius: '4px',
448
+ border: '1px solid #c8e6c9'
449
+ }}>
450
+ <h4>✅ Componentes Mejorados</h4>
451
+ <ul>
452
+ <li><strong>Thumbnail:</strong> Múltiples tamaños, formas, estados</li>
453
+ <li><strong>Selector:</strong> Búsqueda, límites, variantes</li>
454
+ <li><strong>Text:</strong> 15+ formatos, styling completo</li>
455
+ <li>PropTypes completos y validación</li>
456
+ <li>Accesibilidad total (WCAG 2.1 AA)</li>
457
+ <li>Estados loading, error, empty</li>
458
+ <li>CSS responsive con dark mode</li>
459
+ </ul>
460
+ </div>
461
+ </div>
462
+ </section>
463
+
464
+ {/* Garantía de compatibilidad */}
465
+ <section style={{ marginBottom: '2rem' }}>
466
+ <h3>🔒 Garantía de Compatibilidad</h3>
467
+ <div style={{
468
+ background: '#fff3cd',
469
+ padding: '1rem',
470
+ borderRadius: '4px',
471
+ border: '1px solid #ffeaa7'
472
+ }}>
473
+ <p><strong>100% Compatible con Código Existente:</strong></p>
474
+ <ul>
475
+ <li>✅ Todas las props originales funcionan exactamente igual</li>
476
+ <li>✅ Comportamiento de renderizado idéntico</li>
477
+ <li>✅ CSS original preservado y mejorado</li>
478
+ <li>✅ Nuevas características son opcionales</li>
479
+ <li>✅ No se rompe ningún código existente</li>
480
+ <li>✅ Migración automática sin cambios</li>
481
+ </ul>
482
+ <p style={{ marginTop: '1rem', fontSize: '0.9rem', color: '#856404' }}>
483
+ <strong>Migración:</strong> Simplemente reemplaza el import y todas las
484
+ mejoras se aplican automáticamente sin cambiar una línea de código existente.
485
+ </p>
486
+ </div>
487
+ </section>
488
+ </div>
489
+ )
490
+ }
491
+
492
+ export default ComponentsExamples
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Script para convertir archivos de ejemplos existentes al nuevo formato con ExampleLayout
5
+ */
6
+
7
+ import fs from 'fs'
8
+ import path from 'path'
9
+ import { fileURLToPath } from 'url'
10
+
11
+ const __filename = fileURLToPath(import.meta.url)
12
+ const __dirname = path.dirname(__filename)
13
+
14
+ // Función para obtener todos los archivos .example.js
15
+ function getExampleFiles() {
16
+ const htmlDir = path.join(__dirname)
17
+ return fs.readdirSync(htmlDir)
18
+ .filter(file => file.endsWith('.example.js'))
19
+ .filter(file => !file.includes('.new.js')) // Excluir archivos ya convertidos
20
+ .map(file => path.join(htmlDir, file))
21
+ }
22
+
23
+ // Función para extraer el nombre del componente del archivo
24
+ function getComponentName(filePath) {
25
+ const fileName = path.basename(filePath, '.example.js')
26
+ return fileName.charAt(0).toUpperCase() + fileName.slice(1)
27
+ }
28
+
29
+ // Función para generar secciones básicas basadas en el contenido
30
+ function generateSections(content, componentName) {
31
+ const sections = [
32
+ {
33
+ id: 'overview',
34
+ title: 'Introducción',
35
+ icon: 'info'
36
+ }
37
+ ]
38
+
39
+ // Buscar secciones comunes en el contenido
40
+ const commonSections = [
41
+ { pattern: /basic|básico|simple/i, id: 'basic-examples', title: 'Ejemplos Básicos', icon: 'widgets' },
42
+ { pattern: /advanced|avanzado/i, id: 'advanced-features', title: 'Características Avanzadas', icon: 'settings' },
43
+ { pattern: /variant|variante|theme|tema/i, id: 'variants', title: 'Variantes y Temas', icon: 'palette' },
44
+ { pattern: /state|estado|loading|carga/i, id: 'states', title: 'Estados', icon: 'toggle_on' },
45
+ { pattern: /size|tamaño|density|densidad/i, id: 'sizes', title: 'Tamaños', icon: 'format_size' },
46
+ { pattern: /api|reference|referencia/i, id: 'api-reference', title: 'Referencia API', icon: 'code' }
47
+ ]
48
+
49
+ commonSections.forEach(({ pattern, id, title, icon }) => {
50
+ if (pattern.test(content)) {
51
+ sections.push({ id, title, icon })
52
+ }
53
+ })
54
+
55
+ // Si no se encontraron secciones específicas, agregar secciones genéricas
56
+ if (sections.length === 1) {
57
+ sections.push(
58
+ { id: 'examples', title: 'Ejemplos', icon: 'widgets' },
59
+ { id: 'api-reference', title: 'Referencia API', icon: 'code' }
60
+ )
61
+ }
62
+
63
+ return sections
64
+ }
65
+
66
+ // Función para convertir un archivo
67
+ function convertFile(filePath) {
68
+ console.log(`Convirtiendo: ${filePath}`)
69
+
70
+ try {
71
+ const content = fs.readFileSync(filePath, 'utf8')
72
+ const componentName = getComponentName(filePath)
73
+
74
+ // Verificar si ya está convertido
75
+ if (content.includes('ExampleLayout')) {
76
+ console.log(` ⚠️ Ya convertido: ${filePath}`)
77
+ return
78
+ }
79
+
80
+ // Generar secciones basadas en el contenido
81
+ const sections = generateSections(content, componentName)
82
+
83
+ // Crear el nuevo contenido
84
+ let newContent = content
85
+
86
+ // 1. Agregar import del ExampleLayout
87
+ const importRegex = /(import.*from.*['"][^'"]*['"])/g
88
+ const imports = content.match(importRegex) || []
89
+ const lastImport = imports[imports.length - 1]
90
+
91
+ if (lastImport && !content.includes('ExampleLayout')) {
92
+ newContent = newContent.replace(
93
+ lastImport,
94
+ lastImport + '\nimport { ExampleLayout, ExampleSection, ExampleSubsection, CodeSnippet } from \'./ExampleLayout\''
95
+ )
96
+ }
97
+
98
+ // 2. Agregar definición de secciones antes del return
99
+ const returnMatch = newContent.match(/(\s+)return\s*\(/m)
100
+ if (returnMatch) {
101
+ const indent = returnMatch[1]
102
+ const sectionsCode = `${indent}// Definir secciones para el menú lateral
103
+ ${indent}const sections = ${JSON.stringify(sections, null, 8).replace(/^/gm, indent)}
104
+
105
+ ${indent}`
106
+
107
+ newContent = newContent.replace(
108
+ /(\s+)return\s*\(/m,
109
+ sectionsCode + 'return ('
110
+ )
111
+ }
112
+
113
+ // 3. Envolver el contenido principal con ExampleLayout
114
+ const mainDivRegex = /<div[^>]*style[^>]*>\s*<h1[^>]*>([^<]+)<\/h1>/
115
+ const mainDivMatch = newContent.match(mainDivRegex)
116
+
117
+ if (mainDivMatch) {
118
+ const title = mainDivMatch[1]
119
+ newContent = newContent.replace(
120
+ mainDivRegex,
121
+ `<ExampleLayout title="${componentName} Examples" sections={sections}>
122
+ <ExampleSection id="overview" title="${title}" icon="widgets">`
123
+ )
124
+ }
125
+
126
+ // 4. Cerrar las etiquetas al final
127
+ const lastClosingDiv = newContent.lastIndexOf('</div>')
128
+ if (lastClosingDiv !== -1) {
129
+ newContent = newContent.substring(0, lastClosingDiv) +
130
+ ' </ExampleSection>\n </ExampleLayout>' +
131
+ newContent.substring(lastClosingDiv + 6)
132
+ }
133
+
134
+ // 5. Crear archivo de respaldo
135
+ const backupPath = filePath + '.backup'
136
+ fs.writeFileSync(backupPath, content)
137
+
138
+ // 6. Escribir el nuevo contenido
139
+ fs.writeFileSync(filePath, newContent)
140
+
141
+ console.log(` ✅ Convertido exitosamente: ${filePath}`)
142
+ console.log(` 📁 Respaldo creado: ${backupPath}`)
143
+
144
+ } catch (error) {
145
+ console.error(` ❌ Error convirtiendo ${filePath}:`, error.message)
146
+ }
147
+ }
148
+
149
+ // Función principal
150
+ function main() {
151
+ console.log('🚀 Iniciando conversión de archivos de ejemplos...\n')
152
+
153
+ const exampleFiles = getExampleFiles()
154
+
155
+ if (exampleFiles.length === 0) {
156
+ console.log('No se encontraron archivos .example.js para convertir.')
157
+ return
158
+ }
159
+
160
+ console.log(`Encontrados ${exampleFiles.length} archivos para convertir:\n`)
161
+
162
+ exampleFiles.forEach(file => {
163
+ convertFile(file)
164
+ console.log() // Línea en blanco entre archivos
165
+ })
166
+
167
+ console.log('✨ Conversión completada!')
168
+ console.log('\n📝 Notas importantes:')
169
+ console.log('- Se crearon archivos .backup con el contenido original')
170
+ console.log('- Revisa los archivos convertidos y ajusta las secciones según sea necesario')
171
+ console.log('- Algunos archivos pueden requerir ajustes manuales adicionales')
172
+ }
173
+
174
+ // Ejecutar si se llama directamente
175
+ if (import.meta.url === `file://${process.argv[1]}`) {
176
+ main()
177
+ }
178
+
179
+ export {
180
+ convertFile,
181
+ getExampleFiles,
182
+ generateSections
183
+ }