@zonetrix/viewer 2.1.0 → 2.1.1
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),t=require("react"),h=require("react-konva");function $(i){const[f,n]=t.useState(null),[v,x]=t.useState(!1),[p,d]=t.useState(null),u=async()=>{if(i){x(!0),d(null);try{const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),t=require("react"),h=require("react-konva");function $(i){const[f,n]=t.useState(null),[v,x]=t.useState(!1),[p,d]=t.useState(null),u=async()=>{if(i){x(!0),d(null);try{const o=await fetch(i);if(!o.ok)throw new Error(`Failed to fetch config: ${o.statusText}`);const c=await o.json();n(c)}catch(o){const c=o instanceof Error?o:new Error("Unknown error occurred");d(c),console.error("Failed to fetch seat map config:",c)}finally{x(!1)}}};return t.useEffect(()=>{u()},[i]),{config:f,loading:v,error:p,refetch:u}}const z={canvasBackground:"#1a1a1a",stageColor:"#808080",seatAvailable:"#2C2B30",seatReserved:"#FCEA00",seatSelected:"#3A7DE5",seatUnavailable:"#6b7280",seatHidden:"#4a4a4a",gridLines:"#404040",currency:"KD"},V=t.memo(({seat:i,state:f,colors:n,onClick:v})=>{const d={available:n.seatAvailable,reserved:n.seatReserved,selected:n.seatSelected,unavailable:n.seatUnavailable,hidden:n.seatHidden}[f],u=f==="available"||f==="selected",o=t.useCallback(()=>{u&&v(i)},[i,v,u]),c={x:i.position.x,y:i.position.y,fill:d,stroke:"#ffffff",strokeWidth:1,onClick:o,onTap:o};return i.shape==="circle"?s.jsx(h.Circle,{...c,radius:12}):s.jsx(h.Rect,{...c,width:24,height:24,offsetX:12,offsetY:12,cornerRadius:i.shape==="square"?0:4})});V.displayName="ViewerSeat";const _=t.memo(({stage:i,stageColor:f})=>s.jsxs(h.Group,{x:i.position.x,y:i.position.y,children:[s.jsx(h.Rect,{width:i.config.width,height:i.config.height,fill:f+"80",stroke:"#ffffff",strokeWidth:2,cornerRadius:10}),s.jsx(h.Text,{text:i.config.label,x:0,y:0,width:i.config.width,height:i.config.height,fontSize:24,fontStyle:"bold",fill:"#ffffff",align:"center",verticalAlign:"middle"})]}));_.displayName="ViewerStage";const X=({config:i,configUrl:f,floorId:n,onFloorChange:v,reservedSeats:x=[],unavailableSeats:p=[],onSeatSelect:d,onSeatDeselect:u,onSelectionChange:o,colorOverrides:c,showTooltip:G=!0,zoomEnabled:A=!0,className:k="",onConfigLoad:N,onError:R})=>{const L=t.useRef(null),[S,q]=t.useState(new Set),[M,D]=t.useState(1),[y,O]=t.useState({x:0,y:0}),{config:W,loading:U,error:b}=$(f),r=i||W,E=t.useMemo(()=>r?{...r.colors,...c}:{...z,...c},[r,c]),F=t.useMemo(()=>{if(!r)return[];let e=r.seats.filter(a=>a.state!=="hidden");return n&&(e=e.filter(a=>a.floorId===n||!a.floorId&&n==="floor_default")),e},[r,n]),Y=t.useMemo(()=>r?.stages?n?r.stages.filter(e=>e.floorId===n||!e.floorId&&n==="floor_default"):r.stages:[],[r,n]),w=t.useMemo(()=>{const e=new Set(x),a=new Set(p);return{reserved:e,unavailable:a}},[x,p]),T=t.useCallback(e=>{const a=e.id,l=e.seatNumber||"";return w.unavailable.has(a)||w.unavailable.has(l)?"unavailable":w.reserved.has(a)||w.reserved.has(l)?"reserved":S.has(a)?"selected":e.state},[w,S]);t.useEffect(()=>{r&&N&&N(r)},[r,N]),t.useEffect(()=>{b&&R&&R(b)},[b,R]);const B=t.useCallback(e=>{const a=T(e);if(a!=="available"&&a!=="selected")return;const l=S.has(e.id);q(g=>{const m=new Set(g);return l?m.delete(e.id):m.add(e.id),m}),l?u?.(e):(d?.(e),d||console.log("Seat selected:",e))},[T,S,d,u]),j=t.useMemo(()=>r?F.filter(e=>S.has(e.id)):[],[F,S]);t.useEffect(()=>{o?.(j)},[j,o]);const H=t.useCallback(e=>{if(!A)return;e.evt.preventDefault();const a=L.current;if(!a)return;const l=M,g=a.getPointerPosition();if(!g)return;const m={x:(g.x-y.x)/l,y:(g.y-y.y)/l},K=e.evt.deltaY>0?-1:1,P=1.05;let C=K>0?l*P:l/P;C=Math.max(.5,Math.min(5,C)),D(C),O({x:g.x-m.x*C,y:g.y-m.y*C})},[A,M,y]);return U?s.jsx("div",{className:`flex items-center justify-center h-full ${k}`,children:s.jsx("p",{children:"Loading seat map..."})}):b?s.jsx("div",{className:`flex items-center justify-center h-full ${k}`,children:s.jsxs("p",{className:"text-red-500",children:["Error loading seat map: ",b.message]})}):r?s.jsxs("div",{className:`relative ${k}`,children:[s.jsxs(h.Stage,{ref:L,width:r.canvas.width,height:r.canvas.height,scaleX:M,scaleY:M,x:y.x,y:y.y,onWheel:H,style:{backgroundColor:r.canvas.backgroundColor},children:[s.jsx(h.Layer,{listening:!1,children:Y.map(e=>s.jsx(_,{stage:e,stageColor:E.stageColor},e.id))}),s.jsx(h.Layer,{children:F.map(e=>s.jsx(V,{seat:e,state:T(e),colors:E,onClick:B},e.id))})]}),j.length>0&&s.jsxs("div",{className:"absolute top-4 right-4 bg-white dark:bg-gray-800 p-4 rounded shadow-lg",children:[s.jsxs("h3",{className:"font-semibold mb-2",children:["Selected Seats (",j.length,")"]}),s.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:j.map(e=>s.jsxs("div",{className:"text-sm",children:[e.seatNumber,e.price&&` - ${E.currency} ${e.price.toFixed(2)}`]},e.id))})]})]}):s.jsx("div",{className:`flex items-center justify-center h-full ${k}`,children:s.jsx("p",{children:"No configuration provided"})})};exports.DEFAULT_COLORS=z;exports.SeatMapViewer=X;exports.useConfigFetcher=$;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as s, jsxs as u } from "react/jsx-runtime";
|
|
2
|
-
import { useState as v, useEffect as
|
|
3
|
-
import { Stage as Z, Layer as
|
|
2
|
+
import { useState as v, useEffect as T, useRef as Q, useMemo as N, useCallback as $, memo as W } from "react";
|
|
3
|
+
import { Stage as Z, Layer as L, Group as ee, Rect as D, Text as te, Circle as ie } from "react-konva";
|
|
4
4
|
function re(t) {
|
|
5
5
|
const [c, r] = v(null), [S, g] = v(!1), [y, d] = v(null), f = async () => {
|
|
6
6
|
if (t) {
|
|
@@ -19,7 +19,7 @@ function re(t) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
return
|
|
22
|
+
return T(() => {
|
|
23
23
|
f();
|
|
24
24
|
}, [t]), {
|
|
25
25
|
config: c,
|
|
@@ -38,7 +38,7 @@ const ne = {
|
|
|
38
38
|
seatHidden: "#4a4a4a",
|
|
39
39
|
gridLines: "#404040",
|
|
40
40
|
currency: "KD"
|
|
41
|
-
},
|
|
41
|
+
}, Y = W(({ seat: t, state: c, colors: r, onClick: S }) => {
|
|
42
42
|
const d = {
|
|
43
43
|
available: r.seatAvailable,
|
|
44
44
|
reserved: r.seatReserved,
|
|
@@ -46,7 +46,7 @@ const ne = {
|
|
|
46
46
|
unavailable: r.seatUnavailable,
|
|
47
47
|
hidden: r.seatHidden
|
|
48
48
|
// Hidden seats are filtered out, but included for type safety
|
|
49
|
-
}[c], f = c === "available" || c === "selected", a =
|
|
49
|
+
}[c], f = c === "available" || c === "selected", a = $(() => {
|
|
50
50
|
f && S(t);
|
|
51
51
|
}, [t, S, f]), o = {
|
|
52
52
|
x: t.position.x,
|
|
@@ -64,7 +64,7 @@ const ne = {
|
|
|
64
64
|
radius: 12
|
|
65
65
|
}
|
|
66
66
|
) : /* @__PURE__ */ s(
|
|
67
|
-
|
|
67
|
+
D,
|
|
68
68
|
{
|
|
69
69
|
...o,
|
|
70
70
|
width: 24,
|
|
@@ -75,10 +75,10 @@ const ne = {
|
|
|
75
75
|
}
|
|
76
76
|
);
|
|
77
77
|
});
|
|
78
|
-
|
|
79
|
-
const B =
|
|
78
|
+
Y.displayName = "ViewerSeat";
|
|
79
|
+
const B = W(({ stage: t, stageColor: c }) => /* @__PURE__ */ u(ee, { x: t.position.x, y: t.position.y, children: [
|
|
80
80
|
/* @__PURE__ */ s(
|
|
81
|
-
|
|
81
|
+
D,
|
|
82
82
|
{
|
|
83
83
|
width: t.config.width,
|
|
84
84
|
height: t.config.height,
|
|
@@ -117,15 +117,15 @@ const ce = ({
|
|
|
117
117
|
onSelectionChange: a,
|
|
118
118
|
colorOverrides: o,
|
|
119
119
|
showTooltip: se = !0,
|
|
120
|
-
zoomEnabled:
|
|
121
|
-
className:
|
|
122
|
-
onConfigLoad:
|
|
123
|
-
onError:
|
|
120
|
+
zoomEnabled: P = !0,
|
|
121
|
+
className: F = "",
|
|
122
|
+
onConfigLoad: j,
|
|
123
|
+
onError: z
|
|
124
124
|
}) => {
|
|
125
|
-
const V = Q(null), [m, H] = v(/* @__PURE__ */ new Set()), [
|
|
125
|
+
const V = Q(null), [m, H] = v(/* @__PURE__ */ new Set()), [R, U] = v(1), [w, X] = v({ x: 0, y: 0 }), { config: q, loading: G, error: x } = re(c), i = t || q, A = N(
|
|
126
126
|
() => i ? { ...i.colors, ...o } : { ...ne, ...o },
|
|
127
127
|
[i, o]
|
|
128
|
-
),
|
|
128
|
+
), E = N(() => {
|
|
129
129
|
if (!i) return [];
|
|
130
130
|
let e = i.seats.filter((n) => n.state !== "hidden");
|
|
131
131
|
return r && (e = e.filter(
|
|
@@ -136,17 +136,17 @@ const ce = ({
|
|
|
136
136
|
) : i.stages : [], [i, r]), b = N(() => {
|
|
137
137
|
const e = new Set(g), n = new Set(y);
|
|
138
138
|
return { reserved: e, unavailable: n };
|
|
139
|
-
}, [g, y]),
|
|
139
|
+
}, [g, y]), M = $((e) => {
|
|
140
140
|
const n = e.id, l = e.seatNumber || "";
|
|
141
141
|
return b.unavailable.has(n) || b.unavailable.has(l) ? "unavailable" : b.reserved.has(n) || b.reserved.has(l) ? "reserved" : m.has(n) ? "selected" : e.state;
|
|
142
142
|
}, [b, m]);
|
|
143
|
-
|
|
144
|
-
i &&
|
|
145
|
-
}, [i,
|
|
146
|
-
x &&
|
|
147
|
-
}, [x,
|
|
148
|
-
const O =
|
|
149
|
-
const n =
|
|
143
|
+
T(() => {
|
|
144
|
+
i && j && j(i);
|
|
145
|
+
}, [i, j]), T(() => {
|
|
146
|
+
x && z && z(x);
|
|
147
|
+
}, [x, z]);
|
|
148
|
+
const O = $((e) => {
|
|
149
|
+
const n = M(e);
|
|
150
150
|
if (n !== "available" && n !== "selected")
|
|
151
151
|
return;
|
|
152
152
|
const l = m.has(e.id);
|
|
@@ -154,58 +154,58 @@ const ce = ({
|
|
|
154
154
|
const p = new Set(h);
|
|
155
155
|
return l ? p.delete(e.id) : p.add(e.id), p;
|
|
156
156
|
}), l ? f?.(e) : (d?.(e), d || console.log("Seat selected:", e));
|
|
157
|
-
}, [
|
|
158
|
-
|
|
157
|
+
}, [M, m, d, f]), C = N(() => i ? E.filter((e) => m.has(e.id)) : [], [E, m]);
|
|
158
|
+
T(() => {
|
|
159
159
|
a?.(C);
|
|
160
160
|
}, [C, a]);
|
|
161
|
-
const I =
|
|
162
|
-
if (!
|
|
161
|
+
const I = $((e) => {
|
|
162
|
+
if (!P) return;
|
|
163
163
|
e.evt.preventDefault();
|
|
164
164
|
const n = V.current;
|
|
165
165
|
if (!n) return;
|
|
166
|
-
const l =
|
|
166
|
+
const l = R, h = n.getPointerPosition();
|
|
167
167
|
if (!h) return;
|
|
168
168
|
const p = {
|
|
169
169
|
x: (h.x - w.x) / l,
|
|
170
170
|
y: (h.y - w.y) / l
|
|
171
|
-
}, J = e.evt.deltaY > 0 ? -1 : 1,
|
|
172
|
-
let k = J > 0 ? l *
|
|
171
|
+
}, J = e.evt.deltaY > 0 ? -1 : 1, _ = 1.05;
|
|
172
|
+
let k = J > 0 ? l * _ : l / _;
|
|
173
173
|
k = Math.max(0.5, Math.min(5, k)), U(k), X({
|
|
174
174
|
x: h.x - p.x * k,
|
|
175
175
|
y: h.y - p.y * k
|
|
176
176
|
});
|
|
177
|
-
}, [
|
|
178
|
-
return G ? /* @__PURE__ */ s("div", { className: `flex items-center justify-center h-full ${
|
|
177
|
+
}, [P, R, w]);
|
|
178
|
+
return G ? /* @__PURE__ */ s("div", { className: `flex items-center justify-center h-full ${F}`, children: /* @__PURE__ */ s("p", { children: "Loading seat map..." }) }) : x ? /* @__PURE__ */ s("div", { className: `flex items-center justify-center h-full ${F}`, children: /* @__PURE__ */ u("p", { className: "text-red-500", children: [
|
|
179
179
|
"Error loading seat map: ",
|
|
180
180
|
x.message
|
|
181
|
-
] }) }) : i ? /* @__PURE__ */ u("div", { className: `relative ${
|
|
181
|
+
] }) }) : i ? /* @__PURE__ */ u("div", { className: `relative ${F}`, children: [
|
|
182
182
|
/* @__PURE__ */ u(
|
|
183
183
|
Z,
|
|
184
184
|
{
|
|
185
185
|
ref: V,
|
|
186
186
|
width: i.canvas.width,
|
|
187
187
|
height: i.canvas.height,
|
|
188
|
-
scaleX:
|
|
189
|
-
scaleY:
|
|
188
|
+
scaleX: R,
|
|
189
|
+
scaleY: R,
|
|
190
190
|
x: w.x,
|
|
191
191
|
y: w.y,
|
|
192
192
|
onWheel: I,
|
|
193
193
|
style: { backgroundColor: i.canvas.backgroundColor },
|
|
194
194
|
children: [
|
|
195
|
-
/* @__PURE__ */ s(
|
|
195
|
+
/* @__PURE__ */ s(L, { listening: !1, children: K.map((e) => /* @__PURE__ */ s(
|
|
196
196
|
B,
|
|
197
197
|
{
|
|
198
198
|
stage: e,
|
|
199
|
-
stageColor:
|
|
199
|
+
stageColor: A.stageColor
|
|
200
200
|
},
|
|
201
201
|
e.id
|
|
202
202
|
)) }),
|
|
203
|
-
/* @__PURE__ */ s(
|
|
204
|
-
|
|
203
|
+
/* @__PURE__ */ s(L, { children: E.map((e) => /* @__PURE__ */ s(
|
|
204
|
+
Y,
|
|
205
205
|
{
|
|
206
206
|
seat: e,
|
|
207
|
-
state:
|
|
208
|
-
colors:
|
|
207
|
+
state: M(e),
|
|
208
|
+
colors: A,
|
|
209
209
|
onClick: O
|
|
210
210
|
},
|
|
211
211
|
e.id
|
|
@@ -221,10 +221,10 @@ const ce = ({
|
|
|
221
221
|
] }),
|
|
222
222
|
/* @__PURE__ */ s("div", { className: "max-h-48 overflow-y-auto space-y-1", children: C.map((e) => /* @__PURE__ */ u("div", { className: "text-sm", children: [
|
|
223
223
|
e.seatNumber,
|
|
224
|
-
e.price && ` - ${
|
|
224
|
+
e.price && ` - ${A.currency} ${e.price.toFixed(2)}`
|
|
225
225
|
] }, e.id)) })
|
|
226
226
|
] })
|
|
227
|
-
] }) : /* @__PURE__ */ s("div", { className: `flex items-center justify-center h-full ${
|
|
227
|
+
] }) : /* @__PURE__ */ s("div", { className: `flex items-center justify-center h-full ${F}`, children: /* @__PURE__ */ s("p", { children: "No configuration provided" }) });
|
|
228
228
|
};
|
|
229
229
|
export {
|
|
230
230
|
ne as DEFAULT_COLORS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zonetrix/viewer",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Lightweight React component for rendering interactive seat maps",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
12
13
|
"import": "./dist/index.mjs",
|
|
13
|
-
"require": "./dist/index.js"
|
|
14
|
-
"types": "./dist/index.d.ts"
|
|
14
|
+
"require": "./dist/index.js"
|
|
15
15
|
},
|
|
16
16
|
"./styles.css": "./dist/style.css"
|
|
17
17
|
},
|
|
@@ -35,19 +35,19 @@
|
|
|
35
35
|
"author": "",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"konva": "^
|
|
38
|
+
"konva": "^10.0.12",
|
|
39
39
|
"react": "^18.0.0 || ^19.0.0",
|
|
40
40
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
41
|
-
"react-konva": "^
|
|
41
|
+
"react-konva": "^19.2.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/react": "^19.2.0",
|
|
45
45
|
"@types/react-dom": "^19.2.0",
|
|
46
46
|
"@vitejs/plugin-react-swc": "^4.2.2",
|
|
47
|
-
"konva": "^
|
|
48
|
-
"react-konva": "^
|
|
47
|
+
"konva": "^10.0.12",
|
|
48
|
+
"react-konva": "^19.2.1",
|
|
49
49
|
"typescript": "^5.8.3",
|
|
50
50
|
"vite": "^7.3.0",
|
|
51
|
-
"vite-plugin-dts": "^
|
|
51
|
+
"vite-plugin-dts": "^4.5.4"
|
|
52
52
|
}
|
|
53
53
|
}
|