@oottoo-core/oottoo-ui 0.0.4 → 0.0.6

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/README.md CHANGED
@@ -85,37 +85,45 @@ Requiere `@oottoo-core/oottoo-icons`:
85
85
 
86
86
  ### OVeChainLogin
87
87
 
88
- Componente para conectar wallet VeChain usando `@vechain/dapp-kit-ui`.
89
-
90
- **Instalación de dependencia peer:**
91
- ```bash
92
- npm install @vechain/dapp-kit-ui
93
- ```
88
+ Componente UI para login con wallet VeChain. Es un componente puro que requiere que la lógica de wallet se maneje desde la aplicación.
94
89
 
95
90
  **Uso:**
96
91
  ```vue
97
92
  <template>
98
- <o-vechain-login
93
+ <OVeChainLogin
99
94
  variant="primary"
100
95
  size="lg"
101
- network="mainnet"
102
- @connected="handleConnected"
103
- @disconnected="handleDisconnected"
104
- @error="handleError"
96
+ :is-connected="isConnected"
97
+ :is-connecting="isConnecting"
98
+ :address="address"
99
+ :shorten-address-fn="shortenAddress"
100
+ @click="handleWalletClick"
101
+ @disconnect="handleDisconnect"
105
102
  />
106
103
  </template>
107
104
 
108
105
  <script setup>
109
- const handleConnected = (address) => {
110
- console.log('Wallet conectada:', address)
106
+ import { ref } from 'vue'
107
+
108
+ const isConnected = ref(false)
109
+ const isConnecting = ref(false)
110
+ const address = ref(null)
111
+
112
+ const shortenAddress = (addr) => {
113
+ if (!addr || addr.length < 13) return addr
114
+ return `${addr.slice(0, 6)}...${addr.slice(-4)}`
111
115
  }
112
116
 
113
- const handleDisconnected = () => {
114
- console.log('Wallet desconectada')
117
+ const handleWalletClick = async () => {
118
+ // Aquí integrarías con @vechain/dapp-kit-ui o tu librería de wallet preferida
119
+ isConnecting.value = true
120
+ // ... lógica de conexión
115
121
  }
116
122
 
117
- const handleError = (error) => {
118
- console.error('Error:', error)
123
+ const handleDisconnect = () => {
124
+ // ... lógica de desconexión
125
+ isConnected.value = false
126
+ address.value = null
119
127
  }
120
128
  </script>
121
129
  ```
@@ -123,12 +131,16 @@ const handleError = (error) => {
123
131
  **Props:**
124
132
  - `variant`: 'primary' | 'secondary' | 'ghost' (default: 'primary')
125
133
  - `size`: 'sm' | 'md' | 'lg' (default: 'md')
126
- - `network`: 'mainnet' | 'testnet' (default: 'mainnet')
134
+ - `isConnected`: boolean (default: false) - Estado de conexión
135
+ - `isConnecting`: boolean (default: false) - Estado de carga
136
+ - `address`: string | null (default: null) - Dirección de la wallet
137
+ - `shortenAddressFn`: Function - Función para truncar la dirección
127
138
 
128
139
  **Events:**
129
- - `connected(address)`: Se emite al conectar una wallet
130
- - `disconnected`: Se emite al desconectar la wallet
131
- - `error(message)`: Se emite cuando hay un error de conexión
140
+ - `click`: Se emite al hacer click para conectar
141
+ - `disconnect`: Se emite al solicitar desconexión
142
+
143
+ **Nota:** Este componente es un UI puro. Para la integración completa con VeChain, usa `@vechain/dapp-kit-ui` en tu aplicación y pasa el estado al componente.
132
144
 
133
145
  ## 📄 Licencia
134
146
 
@@ -1,6 +1,5 @@
1
- import { computed as p, openBlock as l, createElementBlock as d, normalizeClass as x, renderSlot as S, onMounted as E, onUnmounted as L, createBlock as D, Teleport as W, createVNode as H, Transition as K, withCtx as T, withModifiers as R, normalizeStyle as f, createElementVNode as u, createCommentVNode as y, inject as j, ref as O, watch as U, unref as v, toDisplayString as q } from "vue";
2
- import { useVeChainWallet as F } from "@oottoo-core/oottoo-fns";
3
- const G = ["disabled", "type"], J = {
1
+ import { computed as d, openBlock as i, createElementBlock as a, normalizeClass as h, renderSlot as y, onMounted as f, onUnmounted as v, createBlock as _, Teleport as k, createVNode as C, Transition as w, withCtx as x, withModifiers as z, normalizeStyle as m, createElementVNode as r, createCommentVNode as p, inject as O, toDisplayString as b } from "vue";
2
+ const S = ["disabled", "type"], $ = {
4
3
  __name: "OButton",
5
4
  props: {
6
5
  /**
@@ -37,29 +36,29 @@ const G = ["disabled", "type"], J = {
37
36
  }
38
37
  },
39
38
  emits: ["click"],
40
- setup(e, { emit: i }) {
41
- const n = e, o = i, c = (r) => {
42
- n.disabled || o("click", r);
43
- }, t = p(() => [
39
+ setup(e, { emit: n }) {
40
+ const t = e, o = n, s = (c) => {
41
+ t.disabled || o("click", c);
42
+ }, l = d(() => [
44
43
  "o-button",
45
- `o-button--${n.variant}`,
46
- `o-button--${n.size}`
44
+ `o-button--${t.variant}`,
45
+ `o-button--${t.size}`
47
46
  ]);
48
- return (r, m) => (l(), d("button", {
49
- class: x(t.value),
47
+ return (c, g) => (i(), a("button", {
48
+ class: h(l.value),
50
49
  disabled: e.disabled,
51
50
  type: e.type,
52
- onClick: c
51
+ onClick: s
53
52
  }, [
54
- S(r.$slots, "default")
55
- ], 10, G));
53
+ y(c.$slots, "default")
54
+ ], 10, S));
56
55
  }
57
- }, P = (e, i) => {
58
- const n = e.__vccOpts || e;
59
- for (const [o, c] of i)
60
- n[o] = c;
61
- return n;
62
- }, Q = { class: "o-modal-content" }, X = {
56
+ }, B = (e, n) => {
57
+ const t = e.__vccOpts || e;
58
+ for (const [o, s] of n)
59
+ t[o] = s;
60
+ return t;
61
+ }, M = { class: "o-modal-content" }, L = {
63
62
  __name: "OModal",
64
63
  props: {
65
64
  /**
@@ -78,35 +77,35 @@ const G = ["disabled", "type"], J = {
78
77
  }
79
78
  },
80
79
  emits: ["close"],
81
- setup(e, { emit: i }) {
82
- const n = e, o = i, c = () => {
80
+ setup(e, { emit: n }) {
81
+ const t = e, o = n, s = () => {
83
82
  o("close");
84
- }, t = (r) => {
85
- r.key === "Escape" && n.isOpen && c();
83
+ }, l = (c) => {
84
+ c.key === "Escape" && t.isOpen && s();
86
85
  };
87
- return E(() => {
88
- document.addEventListener("keydown", t);
89
- }), L(() => {
90
- document.removeEventListener("keydown", t);
91
- }), (r, m) => (l(), D(W, { to: "body" }, [
92
- H(K, { name: "o-modal" }, {
93
- default: T(() => [
94
- e.isOpen ? (l(), d("div", {
86
+ return f(() => {
87
+ document.addEventListener("keydown", l);
88
+ }), v(() => {
89
+ document.removeEventListener("keydown", l);
90
+ }), (c, g) => (i(), _(k, { to: "body" }, [
91
+ C(w, { name: "o-modal" }, {
92
+ default: x(() => [
93
+ e.isOpen ? (i(), a("div", {
95
94
  key: 0,
96
95
  class: "o-modal-overlay",
97
- style: f({ zIndex: e.zIndex }),
98
- onClick: R(c, ["self"])
96
+ style: m({ zIndex: e.zIndex }),
97
+ onClick: z(s, ["self"])
99
98
  }, [
100
- u("div", Q, [
101
- S(r.$slots, "default", {}, void 0, !0)
99
+ r("div", M, [
100
+ y(c.$slots, "default", {}, void 0, !0)
102
101
  ])
103
- ], 4)) : y("", !0)
102
+ ], 4)) : p("", !0)
104
103
  ]),
105
104
  _: 3
106
105
  })
107
106
  ]));
108
107
  }
109
- }, Y = /* @__PURE__ */ P(X, [["__scopeId", "data-v-882f88c1"]]), Z = ["width", "height"], ee = {
108
+ }, I = /* @__PURE__ */ B(L, [["__scopeId", "data-v-882f88c1"]]), V = ["width", "height"], E = {
110
109
  __name: "OLoading",
111
110
  props: {
112
111
  /**
@@ -134,24 +133,24 @@ const G = ["disabled", "type"], J = {
134
133
  }
135
134
  },
136
135
  setup(e) {
137
- const i = e, n = {
136
+ const n = e, t = {
138
137
  sm: 16,
139
138
  md: 24,
140
139
  lg: 32
141
- }, o = p(() => n[i.size]);
142
- return (c, t) => e.loading ? (l(), d("div", {
140
+ }, o = d(() => t[n.size]);
141
+ return (s, l) => e.loading ? (i(), a("div", {
143
142
  key: 0,
144
143
  class: "o-loading",
145
- style: f({ color: e.color })
144
+ style: m({ color: e.color })
146
145
  }, [
147
- (l(), d("svg", {
146
+ (i(), a("svg", {
148
147
  width: o.value,
149
148
  height: o.value,
150
149
  viewBox: "0 0 24 24",
151
150
  fill: "none",
152
151
  xmlns: "http://www.w3.org/2000/svg"
153
- }, [...t[0] || (t[0] = [
154
- u("circle", {
152
+ }, [...l[0] || (l[0] = [
153
+ r("circle", {
155
154
  cx: "12",
156
155
  cy: "12",
157
156
  r: "10",
@@ -162,16 +161,16 @@ const G = ["disabled", "type"], J = {
162
161
  "stroke-dashoffset": "20",
163
162
  opacity: "0.25"
164
163
  }, null, -1),
165
- u("path", {
164
+ r("path", {
166
165
  d: "M12 2C6.477 2 2 6.477 2 12",
167
166
  stroke: "currentColor",
168
167
  "stroke-width": "4",
169
168
  "stroke-linecap": "round"
170
169
  }, null, -1)
171
- ])], 8, Z))
172
- ], 4)) : y("", !0);
170
+ ])], 8, V))
171
+ ], 4)) : p("", !0);
173
172
  }
174
- }, te = ["innerHTML"], ne = {
173
+ }, N = ["innerHTML"], H = {
175
174
  __name: "OIcon",
176
175
  props: {
177
176
  /**
@@ -197,32 +196,32 @@ const G = ["disabled", "type"], J = {
197
196
  }
198
197
  },
199
198
  setup(e) {
200
- const i = e, n = p(
201
- () => typeof i.size == "number" ? `${i.size}px` : i.size
202
- ), o = j("oIcons", void 0), c = p(() => o ? o(i.name) : "");
203
- return (t, r) => (l(), d("span", {
199
+ const n = e, t = d(
200
+ () => typeof n.size == "number" ? `${n.size}px` : n.size
201
+ ), o = O("oIcons", void 0), s = d(() => o ? o(n.name) : "");
202
+ return (l, c) => (i(), a("span", {
204
203
  class: "o-icon",
205
- style: f({
206
- width: n.value,
207
- height: n.value,
204
+ style: m({
205
+ width: t.value,
206
+ height: t.value,
208
207
  color: e.color
209
208
  }),
210
- innerHTML: c.value
211
- }, null, 12, te));
209
+ innerHTML: s.value
210
+ }, null, 12, N));
212
211
  }
213
- }, oe = ["disabled"], se = {
212
+ }, T = ["disabled"], A = {
214
213
  key: 0,
215
214
  class: "o-vechain-login__text"
216
- }, ie = {
215
+ }, F = {
217
216
  key: 1,
218
217
  class: "o-vechain-login__text"
219
- }, ae = {
218
+ }, j = {
220
219
  key: 2,
221
220
  class: "o-vechain-login__text"
222
- }, ce = {
221
+ }, q = {
223
222
  key: 3,
224
223
  class: "o-vechain-login__disconnect-icon"
225
- }, le = {
224
+ }, D = {
226
225
  __name: "OVeChainLogin",
227
226
  props: {
228
227
  /**
@@ -244,139 +243,100 @@ const G = ["disabled", "type"], J = {
244
243
  validator: (e) => ["sm", "md", "lg"].includes(e)
245
244
  },
246
245
  /**
247
- * Nodo VeChain a utilizar
248
- * @values 'mainnet', 'testnet'
246
+ * Estado de conexión de la wallet
249
247
  */
250
- network: {
248
+ isConnected: {
249
+ type: Boolean,
250
+ default: !1
251
+ },
252
+ /**
253
+ * Estado de carga durante conexión
254
+ */
255
+ isConnecting: {
256
+ type: Boolean,
257
+ default: !1
258
+ },
259
+ /**
260
+ * Dirección de la wallet conectada
261
+ */
262
+ address: {
251
263
  type: String,
252
- default: "mainnet",
253
- validator: (e) => ["mainnet", "testnet"].includes(e)
264
+ default: null
265
+ },
266
+ /**
267
+ * Función para truncar la dirección
268
+ */
269
+ shortenAddressFn: {
270
+ type: Function,
271
+ default: (e) => !e || e.length < 13 ? e : `${e.slice(0, 6)}...${e.slice(-4)}`
254
272
  }
255
273
  },
256
274
  emits: [
257
- /** Se emite cuando se conecta una wallet */
258
- "connected",
259
- /** Se emite cuando se desconecta la wallet */
260
- "disconnected",
261
- /** Se emite cuando hay un error de conexión */
262
- "error"
275
+ /** Se emite cuando se hace click en el botón (para conectar) */
276
+ "click",
277
+ /** Se emite cuando se solicita desconexión */
278
+ "disconnect"
263
279
  ],
264
- setup(e, { emit: i }) {
265
- const n = e, o = i, c = O(null), t = O(null), {
266
- address: r,
267
- isConnected: m,
268
- isConnecting: h,
269
- setAddress: $,
270
- clearWallet: k,
271
- setError: g,
272
- startConnecting: B,
273
- stopConnecting: _,
274
- shortenAddress: M
275
- } = F(), C = {
276
- mainnet: "https://mainnet.vechain.org",
277
- testnet: "https://testnet.vechain.org"
278
- }, A = async () => {
279
- try {
280
- const { DAppKit: s } = await import("./index-Bywq0IP9.js").then((a) => a.A);
281
- t.value || (t.value = document.createElement("vdk-button"), t.value.setAttribute("node-url", C[n.network]), document.addEventListener("vdk-connected", w), document.addEventListener("vdk-disconnected", b), t.value.style.display = "none", document.body.appendChild(t.value));
282
- } catch (s) {
283
- console.error("Error initializing VeChain DApp Kit:", s), g(s.message), o("error", s.message);
284
- }
285
- }, w = (s) => {
286
- var z;
287
- const a = (z = s.detail) == null ? void 0 : z.address;
288
- a && ($(a), o("connected", a)), _();
289
- }, b = () => {
290
- k(), o("disconnected");
291
- }, I = async () => {
292
- var s;
293
- if (m.value) {
294
- V();
295
- return;
296
- }
297
- B();
298
- try {
299
- t.value ? t.value.click() : (s = c.value) == null || s.click();
300
- } catch (a) {
301
- g(a.message), o("error", a.message), _();
302
- }
303
- }, V = () => {
304
- try {
305
- if (t.value) {
306
- const s = new CustomEvent("vdk-disconnect");
307
- document.dispatchEvent(s);
308
- }
309
- k(), o("disconnected");
310
- } catch (s) {
311
- g(s.message), o("error", s.message);
312
- }
313
- }, N = p(() => [
314
- "o-vechain-login",
315
- `o-vechain-login--${n.variant}`,
316
- `o-vechain-login--${n.size}`,
317
- {
318
- "o-vechain-login--connected": m.value,
319
- "o-vechain-login--loading": h.value
320
- }
321
- ]);
322
- return E(() => {
323
- A();
324
- }), L(() => {
325
- document.removeEventListener("vdk-connected", w), document.removeEventListener("vdk-disconnected", b), t.value && t.value.parentNode && t.value.parentNode.removeChild(t.value);
326
- }), U(() => n.network, () => {
327
- t.value && t.value.setAttribute("node-url", C[n.network]);
328
- }), (s, a) => (l(), d("button", {
329
- ref_key: "walletButtonRef",
330
- ref: c,
331
- class: x(N.value),
332
- disabled: v(h),
280
+ setup(e, { emit: n }) {
281
+ const t = e, o = n, s = () => {
282
+ t.isConnected ? o("disconnect") : o("click");
283
+ }, l = d(() => ({
284
+ "o-vechain-login": !0,
285
+ [`o-vechain-login--${t.variant}`]: !0,
286
+ [`o-vechain-login--${t.size}`]: !0,
287
+ "o-vechain-login--connected": t.isConnected,
288
+ "o-vechain-login--loading": t.isConnecting
289
+ })), c = d(() => t.shortenAddressFn(t.address));
290
+ return (g, u) => (i(), a("button", {
291
+ class: h(l.value),
292
+ disabled: e.isConnecting,
333
293
  type: "button",
334
- onClick: I
294
+ onClick: s
335
295
  }, [
336
- a[1] || (a[1] = u("span", { class: "o-vechain-login__icon" }, [
337
- u("svg", {
296
+ u[1] || (u[1] = r("span", { class: "o-vechain-login__icon" }, [
297
+ r("svg", {
338
298
  viewBox: "0 0 24 24",
339
299
  fill: "currentColor",
340
300
  width: "1em",
341
301
  height: "1em"
342
302
  }, [
343
- u("path", { d: "M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" })
303
+ r("path", { d: "M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" })
344
304
  ])
345
305
  ], -1)),
346
- v(h) ? (l(), d("span", se, " Connecting... ")) : v(m) ? (l(), d("span", ie, q(v(M)(v(r))), 1)) : (l(), d("span", ae, " Connect Wallet ")),
347
- v(m) ? (l(), d("span", ce, [...a[0] || (a[0] = [
348
- u("svg", {
306
+ e.isConnecting ? (i(), a("span", A, " Connecting... ")) : e.isConnected ? (i(), a("span", F, b(c.value), 1)) : (i(), a("span", j, " Connect Wallet ")),
307
+ e.isConnected ? (i(), a("span", q, [...u[0] || (u[0] = [
308
+ r("svg", {
349
309
  viewBox: "0 0 24 24",
350
310
  fill: "none",
351
311
  stroke: "currentColor",
352
312
  width: "1em",
353
313
  height: "1em"
354
314
  }, [
355
- u("path", {
315
+ r("path", {
356
316
  "stroke-linecap": "round",
357
317
  "stroke-linejoin": "round",
358
318
  "stroke-width": "2",
359
319
  d: "M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"
360
320
  })
361
321
  ], -1)
362
- ])])) : y("", !0)
363
- ], 10, oe));
322
+ ])])) : p("", !0)
323
+ ], 10, T));
364
324
  }
365
- }, ue = {
325
+ }, W = {
366
326
  /**
367
327
  * Instala el plugin en la aplicación Vue
368
328
  *
369
329
  * @param {import('vue').App} app - Instancia de la aplicación
370
330
  */
371
331
  install(e) {
372
- e.component("OButton", J), e.component("OModal", Y), e.component("OLoading", ee), e.component("OIcon", ne), e.component("OVeChainLogin", le);
332
+ e.component("OButton", $), e.component("OModal", I), e.component("OLoading", E), e.component("OIcon", H), e.component("OVeChainLogin", D);
373
333
  }
374
334
  };
375
335
  export {
376
- J as OButton,
377
- ne as OIcon,
378
- ee as OLoading,
379
- Y as OModal,
380
- le as OVeChainLogin,
381
- ue as default
336
+ $ as OButton,
337
+ H as OIcon,
338
+ E as OLoading,
339
+ I as OModal,
340
+ D as OVeChainLogin,
341
+ W as default
382
342
  };