create-skybridge 0.0.0-dev.e38035c → 0.0.0-dev.e3ae7d5
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/dist/index.js +47 -63
- package/dist/index.test.js +11 -1
- package/package.json +5 -5
- package/template/README.md +4 -4
- package/template/_gitignore +5 -0
- package/template/alpic.json +1 -2
- package/template/node_modules/.bin/mcp-inspector +2 -2
- package/template/node_modules/.bin/sb +21 -0
- package/template/node_modules/.bin/skybridge +21 -0
- package/template/node_modules/.bin/vite +2 -2
- package/template/package.json +12 -16
- package/template/server/src/index.ts +13 -10
- package/template/tsconfig.server.json +1 -1
- package/template/web/src/index.css +125 -5
- package/template/web/vite.config.ts +2 -2
- package/template/node_modules/.bin/shx +0 -21
- package/template-ecom/README.md +0 -89
- package/template-ecom/alpic.json +0 -4
- package/template-ecom/nodemon.json +0 -5
- package/template-ecom/package.json +0 -40
- package/template-ecom/server/src/index.ts +0 -39
- package/template-ecom/server/src/middleware.ts +0 -54
- package/template-ecom/server/src/server.ts +0 -73
- package/template-ecom/tsconfig.json +0 -23
- package/template-ecom/tsconfig.server.json +0 -11
- package/template-ecom/web/src/helpers.ts +0 -4
- package/template-ecom/web/src/index.css +0 -194
- package/template-ecom/web/src/widgets/ecom-carousel.tsx +0 -181
- package/template-ecom/web/vite.config.ts +0 -15
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import "@/index.css";
|
|
2
|
-
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
import {
|
|
5
|
-
mountWidget,
|
|
6
|
-
useLayout,
|
|
7
|
-
useOpenExternal,
|
|
8
|
-
useRequestModal,
|
|
9
|
-
useUser,
|
|
10
|
-
useWidgetState,
|
|
11
|
-
} from "skybridge/web";
|
|
12
|
-
import { useToolInfo } from "../helpers.js";
|
|
13
|
-
|
|
14
|
-
const translations: Record<string, Record<string, string>> = {
|
|
15
|
-
en: {
|
|
16
|
-
loading: "Loading products...",
|
|
17
|
-
noProducts: "No product found",
|
|
18
|
-
addToCart: "Add to cart",
|
|
19
|
-
removeFromCart: "Remove",
|
|
20
|
-
},
|
|
21
|
-
fr: {
|
|
22
|
-
loading: "Chargement des produits...",
|
|
23
|
-
noProducts: "Aucun produit trouvé",
|
|
24
|
-
addToCart: "Ajouter",
|
|
25
|
-
removeFromCart: "Retirer",
|
|
26
|
-
},
|
|
27
|
-
es: {
|
|
28
|
-
loading: "Cargando productos...",
|
|
29
|
-
noProducts: "No se encontraron productos",
|
|
30
|
-
addToCart: "Añadir",
|
|
31
|
-
removeFromCart: "Quitar",
|
|
32
|
-
},
|
|
33
|
-
de: {
|
|
34
|
-
loading: "Produkte werden geladen...",
|
|
35
|
-
noProducts: "Keine Produkte gefunden",
|
|
36
|
-
addToCart: "Hinzufügen",
|
|
37
|
-
removeFromCart: "Entfernen",
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const CHECKOUT_URL = "https://alpic.ai";
|
|
42
|
-
|
|
43
|
-
function EcomCarousel() {
|
|
44
|
-
const { theme } = useLayout();
|
|
45
|
-
const { locale } = useUser();
|
|
46
|
-
const { open, isOpen } = useRequestModal();
|
|
47
|
-
const openExternal = useOpenExternal();
|
|
48
|
-
|
|
49
|
-
const lang = locale?.split("-")[0] ?? "en";
|
|
50
|
-
|
|
51
|
-
function translate(key: string) {
|
|
52
|
-
return translations[lang]?.[key] ?? translations.en[key];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const { output, isPending } = useToolInfo<"ecom-carousel">();
|
|
56
|
-
type Product = NonNullable<typeof output>["products"][number];
|
|
57
|
-
const [selected, setSelected] = useState<Product | null>(null);
|
|
58
|
-
|
|
59
|
-
const [cart, setCart] = useWidgetState<{ ids: number[] }>({ ids: [] });
|
|
60
|
-
|
|
61
|
-
function toggleCart(productId: number) {
|
|
62
|
-
if (cart.ids.includes(productId)) {
|
|
63
|
-
setCart({ ids: cart.ids.filter((id) => id !== productId) });
|
|
64
|
-
} else {
|
|
65
|
-
setCart({ ids: [...cart.ids, productId] });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (isPending) {
|
|
70
|
-
return (
|
|
71
|
-
<div className={`${theme} container`}>
|
|
72
|
-
<div className="message">{translate("loading")}</div>
|
|
73
|
-
</div>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!output || output.products.length === 0) {
|
|
78
|
-
return (
|
|
79
|
-
<div className={`${theme} container`}>
|
|
80
|
-
<div className="message">{translate("noProducts")}</div>
|
|
81
|
-
</div>
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (isOpen) {
|
|
86
|
-
const cartItems: Product[] = [];
|
|
87
|
-
let total = 0;
|
|
88
|
-
for (const p of output.products) {
|
|
89
|
-
if (cart.ids.includes(p.id)) {
|
|
90
|
-
cartItems.push(p);
|
|
91
|
-
total += p.price;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
const checkoutUrl = new URL(CHECKOUT_URL);
|
|
95
|
-
checkoutUrl.searchParams.set("cart", cart.ids.join(","));
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<div className={`${theme} checkout`}>
|
|
99
|
-
<div className="checkout-title">Order summary</div>
|
|
100
|
-
<div className="checkout-items">
|
|
101
|
-
{cartItems.map((item) => (
|
|
102
|
-
<div key={item.id} className="checkout-item">
|
|
103
|
-
<span>{item.title}</span>
|
|
104
|
-
<span>${item.price.toFixed(2)}</span>
|
|
105
|
-
</div>
|
|
106
|
-
))}
|
|
107
|
-
</div>
|
|
108
|
-
<div className="checkout-total">
|
|
109
|
-
<span>Total</span>
|
|
110
|
-
<span>${total.toFixed(2)}</span>
|
|
111
|
-
</div>
|
|
112
|
-
<button
|
|
113
|
-
type="button"
|
|
114
|
-
className="checkout-button"
|
|
115
|
-
onClick={() => openExternal(checkoutUrl.toString())}
|
|
116
|
-
>
|
|
117
|
-
Checkout
|
|
118
|
-
</button>
|
|
119
|
-
</div>
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const activeProduct = selected ?? output.products[0];
|
|
124
|
-
|
|
125
|
-
return (
|
|
126
|
-
<div className={`${theme} container`}>
|
|
127
|
-
<button
|
|
128
|
-
type="button"
|
|
129
|
-
className="cart-indicator"
|
|
130
|
-
onClick={() => open({ title: "Proceed to checkout ?" })}
|
|
131
|
-
disabled={cart.ids.length === 0}
|
|
132
|
-
>
|
|
133
|
-
🛒 {cart.ids.length}
|
|
134
|
-
</button>
|
|
135
|
-
<div className="carousel">
|
|
136
|
-
{output.products.map((product) => {
|
|
137
|
-
const inCart = cart.ids.includes(product.id);
|
|
138
|
-
return (
|
|
139
|
-
<div key={product.id} className="product-wrapper">
|
|
140
|
-
<button
|
|
141
|
-
type="button"
|
|
142
|
-
className={`product-card ${activeProduct?.id === product.id ? "selected" : ""}`}
|
|
143
|
-
onClick={() => setSelected(product)}
|
|
144
|
-
>
|
|
145
|
-
<img
|
|
146
|
-
src={product.image}
|
|
147
|
-
alt={product.title}
|
|
148
|
-
className="product-image"
|
|
149
|
-
/>
|
|
150
|
-
<div className="product-info">
|
|
151
|
-
<div className="product-title">{product.title}</div>
|
|
152
|
-
<div className="product-price">
|
|
153
|
-
${product.price.toFixed(2)}
|
|
154
|
-
</div>
|
|
155
|
-
</div>
|
|
156
|
-
</button>
|
|
157
|
-
<button
|
|
158
|
-
type="button"
|
|
159
|
-
className={`cart-button ${inCart ? "in-cart" : ""}`}
|
|
160
|
-
onClick={() => toggleCart(product.id)}
|
|
161
|
-
>
|
|
162
|
-
{inCart ? translate("removeFromCart") : translate("addToCart")}
|
|
163
|
-
</button>
|
|
164
|
-
</div>
|
|
165
|
-
);
|
|
166
|
-
})}
|
|
167
|
-
</div>
|
|
168
|
-
<div className="product-detail">
|
|
169
|
-
<div className="detail-title">{activeProduct.title}</div>
|
|
170
|
-
<div className="detail-rating">
|
|
171
|
-
⭐ {activeProduct.rating.rate} ({activeProduct.rating.count} reviews)
|
|
172
|
-
</div>
|
|
173
|
-
<div className="detail-description">{activeProduct.description}</div>
|
|
174
|
-
</div>
|
|
175
|
-
</div>
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export default EcomCarousel;
|
|
180
|
-
|
|
181
|
-
mountWidget(<EcomCarousel />);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import react from "@vitejs/plugin-react";
|
|
3
|
-
import { skybridge } from "skybridge/web";
|
|
4
|
-
import { defineConfig } from "vite";
|
|
5
|
-
|
|
6
|
-
// https://vite.dev/config/
|
|
7
|
-
export default defineConfig({
|
|
8
|
-
plugins: [skybridge(), react()],
|
|
9
|
-
root: __dirname,
|
|
10
|
-
resolve: {
|
|
11
|
-
alias: {
|
|
12
|
-
"@": path.resolve(__dirname, "./src"),
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
});
|