@jsweb/ui 1.3.0 → 1.3.2

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/index.html DELETED
@@ -1,196 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>JS Web UI Test</title>
7
- <style>
8
- .box {
9
- padding: 20px;
10
- border-radius: 8px;
11
- transition: all 0.3s ease;
12
- margin-bottom: 10px;
13
- color: white;
14
- }
15
- .active {
16
- box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
17
- transform: scale(1.02);
18
- }
19
- </style>
20
- <script type="module">
21
- import { createScope, reactive } from './src/index.ts'
22
-
23
- const scope = reactive({
24
- count: 0,
25
- inc: 'Incremento',
26
- dec: 'Decremento',
27
- model: 'Exemplo',
28
- items: ['A', 'B', 'C'],
29
- active: false,
30
- color: '#42b883',
31
-
32
- get computedItems() {
33
- return this.items.map((value, index) => {
34
- return { value, index }
35
- })
36
- },
37
-
38
- increment() {
39
- this.count++
40
- },
41
- decrement() {
42
- this.count--
43
- },
44
- zero() {
45
- this.count = 0
46
- },
47
- addItem() {
48
- const value = Date.now()
49
- this.items.push(value)
50
- },
51
- removeItem() {
52
- this.items.pop()
53
- },
54
- logEvent(e, ...args) {
55
- console.log('Evento recebido:', e, args)
56
- this.items.push(`Evento ${e.type}`)
57
- },
58
- toggleActive() {
59
- this.active = !this.active
60
- },
61
- handleCustomEvent(e) {
62
- alert(`Custom event received: ${e.detail.message}`)
63
- this.items.push(`Custom Event: ${e.detail.message}`)
64
- },
65
- focusInputModel() {
66
- const input = this.$refs.get('inputModel')
67
- if (input) {
68
- input.focus()
69
- input.style.outline = '2px solid blue'
70
- console.log('Single ref resgatada com sucesso:', input)
71
- }
72
- },
73
- focusListItem(idx) {
74
- const inputMap = this.$refs.get('itemInput')
75
- console.log('Nested Map de refs da lista:', inputMap)
76
- const el = inputMap?.get(idx)
77
- if (el) {
78
- el.focus()
79
- el.select()
80
- console.log(`Elemento da chave ${idx} resgatado:`, el)
81
- }
82
- },
83
- logRefs() {
84
- console.log('Todas as $refs indexadas no Map:', this.$refs)
85
- alert(`Refs mapeadas: ${Array.from(this.$refs.keys()).join(', ')}`)
86
- },
87
- })
88
-
89
- window.scope = scope
90
-
91
- createScope('body', { scope })
92
- </script>
93
- </head>
94
- <body>
95
- <div :scope="scope">
96
- <h1>JS Web UI</h1>
97
- <p>Contador: <span :text="count"></span></p>
98
- <button :text="inc" @click="increment">+</button>
99
- <button :text="dec" @click="decrement">-</button>
100
-
101
- <div style="margin-top: 20px">
102
- <button @click="zero" :disabled="!count">Zerar</button>
103
- </div>
104
-
105
- <div
106
- :if="count > 0"
107
- style="margin-top: 20px; padding: 10px; border: 1px solid green"
108
- >
109
- O contador é maior que zero!
110
- </div>
111
-
112
- <div style="margin-top: 20px">
113
- <h3>Lista:</h3>
114
- <div style="margin-bottom: 10px">
115
- <input
116
- type="text"
117
- :bind="model"
118
- :ref="inputModel"
119
- placeholder="Digite algo..."
120
- />
121
- <p>Você vai adicionar: <strong :text="model"></strong></p>
122
- <button @click="addItem">Adicionar Item</button>
123
- <button @click="removeItem">Remover Item</button>
124
- <button @click="focusInputModel">
125
- Focar Campo via this.$refs.get('inputModel')
126
- </button>
127
- <button @click="logRefs">Inspecionar $refs no Console</button>
128
- <button @click="logEvent">Testar Evento (Sem Parênteses)</button>
129
- <button @click="logEvent($event, 'A', 'B', 'C')">
130
- Testar Evento (Com Parênteses)
131
- </button>
132
- </div>
133
- <ul>
134
- <li :for="item of computedItems" :key="item.index" :ref="itemRow">
135
- <span :text="item.index"></span>:
136
- <input type="text" :value="item.value" :ref="itemInput" />
137
- <button @click="focusListItem(item.index)">
138
- Focar este input ($refs.get('itemInput').get($key))
139
- </button>
140
- </li>
141
- </ul>
142
- </div>
143
-
144
- <hr />
145
-
146
- <div style="margin-top: 20px">
147
- <h3>Testes de :class e :style</h3>
148
- <div
149
- class="box"
150
- :class="{ active }"
151
- :style="{ backgroundColor: color, opacity: count ? 1 : 0.5 }"
152
- >
153
- Caixa de teste! Ativa: <strong :text="active"></strong>
154
- </div>
155
-
156
- <div style="margin-top: 10px">
157
- <button @click="toggleActive">Alternar Classe 'active'</button>
158
-
159
- <label style="margin-left: 10px">
160
- Cor de Fundo:
161
- <input type="color" :bind="color" />
162
- </label>
163
- </div>
164
- </div>
165
-
166
- <hr />
167
-
168
- <div style="margin-top: 20px" @custom-event="handleCustomEvent">
169
- <h3>Teste de $emit (Comunicação de Eventos)</h3>
170
- <p>A div pai está escutando <code>@custom-event</code>.</p>
171
-
172
- <!-- Escopo Filho Simulado -->
173
- <div
174
- :scope="{ component: 'Componente Interno' }"
175
- style="
176
- padding: 0 15px 15px 15px;
177
- border: 2px dashed silver;
178
- margin-top: 10px;
179
- "
180
- >
181
- <p>Nome interno: <strong :text="component"></strong></p>
182
- <button
183
- @click="
184
- $emit(
185
- 'custom-event',
186
- { message: `Mensagem enviada do ${component}` },
187
- )
188
- "
189
- >
190
- Disparar evento para o pai
191
- </button>
192
- </div>
193
- </div>
194
- </div>
195
- </body>
196
- </html>
package/publish.js DELETED
@@ -1,34 +0,0 @@
1
- import { resolve } from 'node:path'
2
- import { copyFileSync, readFileSync, writeFileSync } from 'node:fs'
3
-
4
- const root = process.cwd()
5
- const source = resolve(root, 'package.json')
6
- const target = resolve(root, 'dist/package.json')
7
- const pkgInfo = JSON.parse(readFileSync(source, 'utf8'))
8
-
9
- // 1. Remove campos que não são necessários no pacote publicado
10
- delete pkgInfo.scripts
11
- delete pkgInfo.devDependencies
12
-
13
- // 2. Ajusta os caminhos dos arquivos, pois o root do pacote agora será a pasta dist/
14
- pkgInfo.main = 'index.umd.js'
15
- pkgInfo.module = 'index.es.js'
16
- pkgInfo.types = 'index.d.ts'
17
- pkgInfo.exports = {
18
- '.': {
19
- import: './index.es.js',
20
- require: './index.umd.js',
21
- types: './index.d.ts',
22
- },
23
- }
24
-
25
- // 3. Salva o package.json modificado dentro da pasta dist/
26
- writeFileSync(target, JSON.stringify(pkgInfo, null, 2))
27
-
28
- // 4. Copia arquivos de metadados importantes para o NPM
29
- copyFileSync(resolve(root, 'README.md'), resolve(root, 'dist/README.md'))
30
- copyFileSync(resolve(root, 'LICENSE'), resolve(root, 'dist/LICENSE'))
31
-
32
- console.log(
33
- '✅ Arquivo package.json mínimo e metadados preparados na pasta dist/',
34
- )
package/src/evaluator.ts DELETED
@@ -1,29 +0,0 @@
1
- export function evaluate(
2
- expression: string,
3
- context: Record<string, any> = {},
4
- ) {
5
- try {
6
- const fn = new Function(`with(this) { return ${expression} }`)
7
- return fn.call(context)
8
- } catch {
9
- return undefined
10
- }
11
- }
12
-
13
- export function evaluateEvent(
14
- $event: Event,
15
- expression: string,
16
- context: Record<string, any> = {},
17
- ) {
18
- try {
19
- const exp = expression.trim()
20
- const isIdentifier = /^[a-zA-Z_$][0-9a-zA-Z_$.]*$/.test(exp)
21
- const code = `${exp} instanceof Function ? ${exp}.call(this, $event) : ${exp}`
22
- const result = isIdentifier ? code : exp
23
- const fn = new Function('$event', `with(this) { ${result} }`)
24
-
25
- fn.call(context, $event)
26
- } catch {
27
- console.warn(`[jsweb/ui] Error evaluating event: ${expression}`)
28
- }
29
- }
package/src/index.ts DELETED
@@ -1,10 +0,0 @@
1
- import { reactive, watch } from './reactivity'
2
- import { createScope } from './parser'
3
-
4
- export { reactive, watch, createScope }
5
-
6
- if (typeof window !== 'undefined') {
7
- const w = window as any
8
- w.jsweb = w.jsweb || {}
9
- w.jsweb.ui = { createScope, reactive, watch }
10
- }