@viur/shop-components 0.0.1-dev.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.
@@ -0,0 +1,93 @@
1
+ // @ts-nocheck
2
+ import { createRouter, createWebHashHistory } from "vue-router";
3
+ import ViewMissing from "../views/ViewMissing.vue";
4
+
5
+ const default_routes = [
6
+ {
7
+ path: "/:pathMatch(.*)*",
8
+ name: "view_missing",
9
+ component: ViewMissing,
10
+ },
11
+ {
12
+ path: "/shop/category/:identifier",
13
+ name: "CategoryView",
14
+ component: () => import("../components/order/category/CategoryView.vue"),
15
+ },
16
+ {
17
+ path: "/shop/item/:item",
18
+ name: "itemView",
19
+ component: () => import("../components/order/item/ItemView.vue"),
20
+ },
21
+ {
22
+ path: "/shop/basket/",
23
+ name: "BasketView",
24
+ component: () => import("../components/cart/BasketView.vue"),
25
+ },
26
+ ];
27
+
28
+ function createRouterInstance(routes, replace = false) {
29
+ let newRoutes = [];
30
+ if (replace) {
31
+ newRoutes = routes;
32
+ } else {
33
+ newRoutes = routes.concat(default_routes);
34
+ }
35
+
36
+ const router = createRouter({
37
+ // @ts-ignore
38
+ history: createWebHashHistory(import.meta.env.BASE_URL),
39
+ routes: newRoutes,
40
+ });
41
+
42
+ // router.afterEach((to, from) => {
43
+ // //useUserStore().addAction();
44
+ // });
45
+
46
+ // router.beforeEach((to, from, next) => {
47
+ // const contextStore = useContextStore();
48
+ // let localContext = {};
49
+ // let handlerId = to.query["_"]?.toString();
50
+ // if (!handlerId) next();
51
+ // if (Object.keys(contextStore.state.localContext).includes(handlerId)) {
52
+ // localContext = contextStore.state.localContext[handlerId];
53
+ // }
54
+ // let newQuery = {
55
+ // ...contextStore.state.globalContext,
56
+ // ...localContext,
57
+ // ...to.query,
58
+ // };
59
+ // if (
60
+ // Object.keys(to.query).every(
61
+ // (key) =>
62
+ // to.query[key] === newQuery[key] &&
63
+ // to.query.hasOwnProperty(key) &&
64
+ // newQuery.hasOwnProperty(key),
65
+ // ) &&
66
+ // Object.keys(newQuery).every(
67
+ // (key) =>
68
+ // to.query[key] === newQuery[key] &&
69
+ // to.query.hasOwnProperty(key) &&
70
+ // newQuery.hasOwnProperty(key),
71
+ // )
72
+ // ) {
73
+ // //disabled because of to much context copy and updates
74
+ // // Writes query to context
75
+ // /*
76
+ // for (const [k, v] of Object.entries(to.query)) {
77
+ // if (k.startsWith("_")) continue
78
+ // if (Object.keys(contextStore.state.localContext).includes(handlerId)) {
79
+ // contextStore.state.localContext[handlerId][k] = v
80
+ // } else {
81
+ // contextStore.state.localContext[handlerId] = { [k]: v }
82
+ // }
83
+ // }*/
84
+ // next(); // no change
85
+ // } else {
86
+ // to.query = newQuery;
87
+ // next(to);
88
+ // }
89
+ // });
90
+ return router;
91
+ }
92
+
93
+ export default createRouterInstance;
@@ -0,0 +1,54 @@
1
+ // import "@viur/shoelace/dist/themes/viur.css"
2
+ import "@viur/shoelace/dist/components/button/button.js";
3
+ import "@viur/shoelace/dist/components/button-group/button-group.js";
4
+ import "@viur/shoelace/dist/components/icon/icon.js";
5
+ import "@viur/shoelace/dist/components/input/input.js";
6
+ import "@viur/shoelace/dist/components/dropdown/dropdown.js";
7
+ import "@viur/shoelace/dist/components/menu/menu.js";
8
+ import "@viur/shoelace/dist/components/menu-item/menu-item.js";
9
+ import "@viur/shoelace/dist/components/badge/badge.js";
10
+ import "@viur/shoelace/dist/components/divider/divider.js";
11
+ import "@viur/shoelace/dist/components/avatar/avatar.js";
12
+ import "@viur/shoelace/dist/components/dialog/dialog.js";
13
+ import "@viur/shoelace/dist/components/tooltip/tooltip.js";
14
+ import "@viur/shoelace/dist/components/split-panel/split-panel.js";
15
+ import "@viur/shoelace/dist/components/radio-group/radio-group.js";
16
+ import "@viur/shoelace/dist/components/radio-button/radio-button.js";
17
+ import "@viur/shoelace/dist/components/select/select.js";
18
+ import "@viur/shoelace/dist/components/option/option.js";
19
+ import "@viur/shoelace/dist/components/spinner/spinner.js";
20
+ import "@viur/shoelace/dist/components/switch/switch.js";
21
+ import "@viur/shoelace/dist/components/card/card.js";
22
+ import "@viur/shoelace/dist/components/tag/tag.js";
23
+ import "@viur/shoelace/dist/components/tooltip/tooltip.js";
24
+ import "@viur/shoelace/dist/components/checkbox/checkbox.js";
25
+ import "@viur/shoelace/dist/components/table-wrapper/table-wrapper.js";
26
+ import "@viur/shoelace/dist/components/drawer/drawer.js";
27
+ import "@viur/shoelace/dist/components/alert/alert.js";
28
+ import "@viur/shoelace/dist/components/icon-button/icon-button.js";
29
+ import "@viur/shoelace/dist/components/tree/tree.js";
30
+ import "@viur/shoelace/dist/components/tree-item/tree-item.js";
31
+ import "@viur/shoelace/dist/components/breadcrumb/breadcrumb.js";
32
+ import "@viur/shoelace/dist/components/breadcrumb-item/breadcrumb-item.js";
33
+ import "@viur/shoelace/dist/components/format-date/format-date.js";
34
+ import "@viur/shoelace/dist/components/format-bytes/format-bytes.js";
35
+ import "@viur/shoelace/dist/components/tab-group/tab-group.js";
36
+ import "@viur/shoelace/dist/components/tab/tab.js";
37
+ import "@viur/shoelace/dist/components/tab-panel/tab-panel.js";
38
+ import "@viur/shoelace/dist/components/combobox/combobox.js";
39
+
40
+ import { setBasePath } from "@viur/shoelace/dist/utilities/base-path.js";
41
+ import { registerIconLibrary } from "@viur/shoelace/dist/utilities/icon-library.js";
42
+
43
+ if (import.meta.env.DEV) {
44
+ setBasePath(`/static/dashboard/shoelace`);
45
+ } else {
46
+ setBasePath(`shoelace`);
47
+ }
48
+
49
+
50
+ // Register a custom icons repository for this app
51
+
52
+ // registerIconLibrary("logo", {
53
+ // resolver: (name) => `/static/app-logos/${name}.svg`,
54
+ // });
@@ -0,0 +1,98 @@
1
+ import { reactive } from "vue";
2
+ import { Request } from "@viur/vue-utils";
3
+ import { defineStore } from "pinia";
4
+ import { ViURShopClient } from "@viur/viur-shop-client";
5
+
6
+ export const useCartStore = defineStore("cartstore", () => {
7
+ const state = reactive({
8
+ currentCart: "",
9
+ allCarts: {},
10
+ cartItems: {},
11
+ basketArticle: [],
12
+ });
13
+
14
+ function init() {
15
+ listCarts().then(async (resp) => {
16
+ let data = await resp.json();
17
+ getBasket(data);
18
+ data.forEach((cart) => {
19
+ state.allCarts[cart.key] = cart;
20
+ getCartItems(cart.key).then(async (resp) => {
21
+ let data = await resp.json();
22
+ state.cartItems[cart.key] = data;
23
+ });
24
+ });
25
+ });
26
+
27
+ console.log("hier", state.currentCart);
28
+
29
+ getBasketItems(state.currentCart).then(async (resp) => {
30
+ let data = await resp.json();
31
+ console.log("cartStore basket article", data);
32
+ state.basketArticle = data;
33
+ });
34
+
35
+ // state.allCarts.forEach((cart) => {
36
+ // getCartItems(cart.key).then(async (resp) => {
37
+ // let data = await resp.json();
38
+ // state.cartItems[cartKey] = data;
39
+ // });
40
+ // });
41
+ }
42
+
43
+ function listCarts() {
44
+ return Request.get("/shop/api/cart_list");
45
+ // const sc = new ViURShopClient();
46
+
47
+ // sc.cart_list().then(async (resp) => console.log("test", await resp.json));
48
+ }
49
+
50
+ function getBasket(skellist) {
51
+ skellist.forEach((cart) => {
52
+ if ((cart.cart_type = "basket")) {
53
+ state.currentCart = cart.key;
54
+ }
55
+ });
56
+ }
57
+
58
+ function getBasketItems(cartKey) {
59
+ return Request.get(`/shop/api/cart_list`, {
60
+ dataObj: { cart_key: cartKey },
61
+ });
62
+ }
63
+
64
+ function getCartItems(cartKey) {
65
+ return Request.get(`/shop/api/cart_list`, {
66
+ dataObj: { cart_key: cartKey },
67
+ });
68
+ }
69
+
70
+ function addToCart(articleKey, cartKey) {
71
+ // let skey = "";
72
+ // Request.get("/vi/skey?amount=1").then(async (resp) => {
73
+ // let data = await resp.json();
74
+ // console.log("skey", data);
75
+ // skey = data;
76
+ // });
77
+ Request.securePost("/shop/api/article_add", {
78
+ dataObj: {
79
+ article_key: articleKey,
80
+ parent_cart_key: cartKey,
81
+ quantity: 1,
82
+ quantity_mode: "increase",
83
+ // skey: skey,
84
+ },
85
+ }).then(async (resp) => {
86
+ let data = await resp.json();
87
+ console.log("article add", data);
88
+ });
89
+ }
90
+
91
+ return {
92
+ state,
93
+ listCarts,
94
+ addToCart,
95
+ getBasketItems,
96
+ init,
97
+ };
98
+ });
package/src/style.css ADDED
@@ -0,0 +1,79 @@
1
+ :root {
2
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3
+ line-height: 1.5;
4
+ font-weight: 400;
5
+
6
+ color-scheme: light dark;
7
+ color: rgba(255, 255, 255, 0.87);
8
+ background-color: #242424;
9
+
10
+ font-synthesis: none;
11
+ text-rendering: optimizeLegibility;
12
+ -webkit-font-smoothing: antialiased;
13
+ -moz-osx-font-smoothing: grayscale;
14
+ }
15
+
16
+ a {
17
+ font-weight: 500;
18
+ color: #646cff;
19
+ text-decoration: inherit;
20
+ }
21
+ a:hover {
22
+ color: #535bf2;
23
+ }
24
+
25
+ body {
26
+ margin: 0;
27
+ display: flex;
28
+ place-items: center;
29
+ min-width: 320px;
30
+ min-height: 100vh;
31
+ }
32
+
33
+ h1 {
34
+ font-size: 3.2em;
35
+ line-height: 1.1;
36
+ }
37
+
38
+ button {
39
+ border-radius: 8px;
40
+ border: 1px solid transparent;
41
+ padding: 0.6em 1.2em;
42
+ font-size: 1em;
43
+ font-weight: 500;
44
+ font-family: inherit;
45
+ background-color: #1a1a1a;
46
+ cursor: pointer;
47
+ transition: border-color 0.25s;
48
+ }
49
+ button:hover {
50
+ border-color: #646cff;
51
+ }
52
+ button:focus,
53
+ button:focus-visible {
54
+ outline: 4px auto -webkit-focus-ring-color;
55
+ }
56
+
57
+ .card {
58
+ padding: 2em;
59
+ }
60
+
61
+ #app {
62
+ max-width: 1280px;
63
+ margin: 0 auto;
64
+ padding: 2rem;
65
+ text-align: center;
66
+ }
67
+
68
+ @media (prefers-color-scheme: light) {
69
+ :root {
70
+ color: #213547;
71
+ background-color: #ffffff;
72
+ }
73
+ a:hover {
74
+ color: #747bff;
75
+ }
76
+ button {
77
+ background-color: #f9f9f9;
78
+ }
79
+ }
@@ -0,0 +1,20 @@
1
+ <template>
2
+ <div class="home">View {{ route.path }} is missing.</div>
3
+ </template>
4
+
5
+ <script>
6
+ import { defineComponent, reactive } from "vue"
7
+ import { useRoute } from "vue-router"
8
+
9
+ export default defineComponent({
10
+ props: {},
11
+ components: {},
12
+ setup(props, context) {
13
+ const route = useRoute()
14
+ const state = reactive({})
15
+ return { state, route }
16
+ }
17
+ })
18
+ </script>
19
+
20
+ <style scoped></style>
package/vite.config.js ADDED
@@ -0,0 +1,23 @@
1
+ import { defineConfig } from 'vite'
2
+ import vue from '@vitejs/plugin-vue'
3
+ import { resolve } from "node:path";
4
+
5
+ // https://vitejs.dev/config/
6
+ export default defineConfig({
7
+ plugins: [vue()],
8
+ build: {
9
+ lib: {
10
+ entry: resolve(__dirname, "src/index.js"),
11
+ name: "ShopComponents",
12
+ fileName: "shop-components",
13
+ },
14
+ rollupOptions: {
15
+ external: ["vue"],
16
+ output: {
17
+ globals: {
18
+ vue: "Vue",
19
+ },
20
+ },
21
+ },
22
+ },
23
+ });