@seatsio/seatsio-react 14.2.0 → 14.4.0

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.
@@ -1,28 +1,29 @@
1
1
  import * as React from 'react';
2
- import { SeatingChart, Region, CommonConfigOptions, Seatsio, EventManager, ChartDesigner } from '@seatsio/seatsio-types';
2
+ import { SeatingChart, EventManager, Region, CommonConfigOptions, Seatsio, ChartDesigner } from '@seatsio/seatsio-types';
3
3
 
4
4
  type EmbeddableProps<T> = {
5
- onRenderStarted?: (chart: SeatingChart) => void;
5
+ onRenderStarted?: (chart: SeatingChart | EventManager) => void;
6
6
  chartJsUrl?: string;
7
7
  region: Region;
8
8
  } & T;
9
9
  declare abstract class Embeddable<T extends CommonConfigOptions> extends React.Component<EmbeddableProps<T>> {
10
10
  private container;
11
- private rendering?;
12
11
  private chart;
12
+ private firstRender;
13
+ private static seatsioBundles;
13
14
  static defaultProps: {
14
15
  chartJsUrl: string;
15
16
  };
16
17
  constructor(props: EmbeddableProps<T>);
17
18
  abstract createChart(seatsio: Seatsio, config: T): SeatingChart | EventManager | ChartDesigner;
18
- componentDidMount(): Promise<void>;
19
- componentDidUpdate(prevProps: EmbeddableProps<T>): Promise<void>;
19
+ componentDidMount(): void;
20
+ componentDidUpdate(prevProps: EmbeddableProps<T>): void;
21
+ getChartUrl(): string;
20
22
  createAndRenderChart(): Promise<void>;
21
23
  extractConfigFromProps(): any;
22
24
  componentWillUnmount(): void;
23
25
  destroyChart(): void;
24
- getSeatsio(): Promise<any>;
25
- loadSeatsio(): Promise<unknown>;
26
+ loadSeatsio(): Promise<Seatsio>;
26
27
  render(): React.ReactNode;
27
28
  }
28
29
 
@@ -1,28 +1,29 @@
1
1
  import * as React from 'react';
2
- import { SeatingChart, Region, CommonConfigOptions, Seatsio, EventManager, ChartDesigner } from '@seatsio/seatsio-types';
2
+ import { SeatingChart, EventManager, Region, CommonConfigOptions, Seatsio, ChartDesigner } from '@seatsio/seatsio-types';
3
3
 
4
4
  type EmbeddableProps<T> = {
5
- onRenderStarted?: (chart: SeatingChart) => void;
5
+ onRenderStarted?: (chart: SeatingChart | EventManager) => void;
6
6
  chartJsUrl?: string;
7
7
  region: Region;
8
8
  } & T;
9
9
  declare abstract class Embeddable<T extends CommonConfigOptions> extends React.Component<EmbeddableProps<T>> {
10
10
  private container;
11
- private rendering?;
12
11
  private chart;
12
+ private firstRender;
13
+ private static seatsioBundles;
13
14
  static defaultProps: {
14
15
  chartJsUrl: string;
15
16
  };
16
17
  constructor(props: EmbeddableProps<T>);
17
18
  abstract createChart(seatsio: Seatsio, config: T): SeatingChart | EventManager | ChartDesigner;
18
- componentDidMount(): Promise<void>;
19
- componentDidUpdate(prevProps: EmbeddableProps<T>): Promise<void>;
19
+ componentDidMount(): void;
20
+ componentDidUpdate(prevProps: EmbeddableProps<T>): void;
21
+ getChartUrl(): string;
20
22
  createAndRenderChart(): Promise<void>;
21
23
  extractConfigFromProps(): any;
22
24
  componentWillUnmount(): void;
23
25
  destroyChart(): void;
24
- getSeatsio(): Promise<any>;
25
- loadSeatsio(): Promise<unknown>;
26
+ loadSeatsio(): Promise<Seatsio>;
26
27
  render(): React.ReactNode;
27
28
  }
28
29
 
@@ -1,2 +1,124 @@
1
- var p=Object.create;var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var C=(t,r)=>{for(var e in r)i(t,e,{get:r[e],enumerable:!0})},d=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of l(r))!f.call(t,o)&&o!==e&&i(t,o,{get:()=>r[o],enumerable:!(s=g(r,o))||s.enumerable});return t};var u=(t,r,e)=>(e=t!=null?p(m(t)):{},d(r||!t||!t.__esModule?i(e,"default",{value:t,enumerable:!0}):e,t)),R=t=>d(i({},"__esModule",{value:!0}),t);var S={};C(S,{default:()=>a});module.exports=R(S);var n=u(require("react")),h=require("./util");class a extends n.Component{constructor(e){super(e);this.container=n.createRef()}async componentDidMount(){this.rendering||(this.rendering=this.createAndRenderChart())}async componentDidUpdate(e){(0,h.didPropsChange)(this.props,e)&&this.chart&&(this.destroyChart(),this.createAndRenderChart())}async createAndRenderChart(){const e=await this.getSeatsio(),s=this.extractConfigFromProps();s.container=this.container.current,this.chart=this.createChart(e,s).render(),this.props.onRenderStarted&&this.props.onRenderStarted(this.chart)}extractConfigFromProps(){let{chartJsUrl:e,divId:s,onRenderStarted:o,region:b,...c}=this.props;return c}componentWillUnmount(){this.destroyChart()}destroyChart(){this.chart&&this.chart.state!=="DESTROYED"&&this.chart.destroy()}getSeatsio(){return typeof seatsio=="undefined"?this.loadSeatsio():seatsio.region!==this.props.region?(seatsio=void 0,this.loadSeatsio()):Promise.resolve(seatsio)}loadSeatsio(){return new Promise((e,s)=>{let o=document.createElement("script");o.onload=()=>{seatsio.region=this.props.region,e(seatsio)},o.onerror=()=>s(`Could not load ${o.src}`),o.src=this.props.chartJsUrl.replace("{region}",this.props.region),document.head.appendChild(o)})}render(){return n.createElement("div",{ref:this.container,style:{height:"100%",width:"100%"}})}}a.defaultProps={chartJsUrl:"https://cdn-{region}.seatsio.net/chart.js"};
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/main/Embeddable.tsx
30
+ var Embeddable_exports = {};
31
+ __export(Embeddable_exports, {
32
+ default: () => Embeddable
33
+ });
34
+ module.exports = __toCommonJS(Embeddable_exports);
35
+ var React = __toESM(require("react"));
36
+
37
+ // src/main/util.ts
38
+ var didPropsChange = (prevProps, nextProps) => {
39
+ if (Object.keys(prevProps).length !== Object.keys(nextProps).length) {
40
+ return true;
41
+ }
42
+ return Object.keys(nextProps).some((propName) => {
43
+ let prevValue = prevProps[propName];
44
+ let nextValue = nextProps[propName];
45
+ if (prevValue && nextValue) {
46
+ if (typeof prevValue === "function" && typeof nextValue === "function") {
47
+ return prevValue.toString() !== nextValue.toString();
48
+ }
49
+ if (typeof prevValue === "object" && typeof nextValue === "object") {
50
+ return didPropsChange(prevValue, nextValue);
51
+ }
52
+ }
53
+ return prevValue !== nextValue;
54
+ });
55
+ };
56
+
57
+ // src/main/Embeddable.tsx
58
+ var _Embeddable = class _Embeddable extends React.Component {
59
+ constructor(props) {
60
+ super(props);
61
+ this.container = React.createRef();
62
+ this.firstRender = true;
63
+ }
64
+ componentDidMount() {
65
+ if (!_Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {
66
+ this.createAndRenderChart();
67
+ this.firstRender = false;
68
+ }
69
+ }
70
+ componentDidUpdate(prevProps) {
71
+ if (didPropsChange(this.props, prevProps) && this.chart) {
72
+ this.destroyChart();
73
+ this.createAndRenderChart();
74
+ }
75
+ }
76
+ getChartUrl() {
77
+ return this.props.chartJsUrl.replace("{region}", this.props.region);
78
+ }
79
+ async createAndRenderChart() {
80
+ const seatsio2 = await this.loadSeatsio();
81
+ const config = this.extractConfigFromProps();
82
+ config.container = this.container.current;
83
+ this.chart = this.createChart(seatsio2, config).render();
84
+ if (this.props.onRenderStarted) {
85
+ this.props.onRenderStarted(this.chart);
86
+ }
87
+ }
88
+ extractConfigFromProps() {
89
+ let { chartJsUrl, divId, onRenderStarted, region, ...config } = this.props;
90
+ return config;
91
+ }
92
+ componentWillUnmount() {
93
+ this.destroyChart();
94
+ }
95
+ destroyChart() {
96
+ if (this.chart && this.chart.state !== "DESTROYED") {
97
+ this.chart.destroy();
98
+ }
99
+ }
100
+ loadSeatsio() {
101
+ const chartUrl = this.getChartUrl();
102
+ if (!_Embeddable.seatsioBundles[chartUrl]) {
103
+ _Embeddable.seatsioBundles[chartUrl] = new Promise((resolve, reject) => {
104
+ const script = document.head.appendChild(document.createElement("script"));
105
+ window.seatsio = void 0;
106
+ script.onload = () => {
107
+ resolve(seatsio);
108
+ };
109
+ script.onerror = () => reject(`Could not load ${script.src}`);
110
+ script.src = chartUrl;
111
+ });
112
+ }
113
+ return _Embeddable.seatsioBundles[chartUrl];
114
+ }
115
+ render() {
116
+ return /* @__PURE__ */ React.createElement("div", { ref: this.container, style: { "height": "100%", "width": "100%" } });
117
+ }
118
+ };
119
+ _Embeddable.seatsioBundles = {};
120
+ _Embeddable.defaultProps = {
121
+ chartJsUrl: "https://cdn-{region}.seatsio.net/chart.js"
122
+ };
123
+ var Embeddable = _Embeddable;
2
124
  //# sourceMappingURL=Embeddable.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/main/Embeddable.tsx"],"sourcesContent":["import * as React from 'react'\nimport {didPropsChange} from './util'\nimport { ChartDesigner, CommonConfigOptions, EventManager, Region, SeatingChart, Seatsio } from '@seatsio/seatsio-types'\n\nexport type EmbeddableProps<T> = {\n onRenderStarted?: (chart: SeatingChart) => void\n chartJsUrl?: string\n region: Region\n} & T\n\nexport default abstract class Embeddable<T extends CommonConfigOptions> extends React.Component<EmbeddableProps<T>> {\n private container: React.RefObject<HTMLDivElement>\n private rendering?: Promise<void>\n private chart: SeatingChart\n\n static defaultProps = {\n chartJsUrl: 'https://cdn-{region}.seatsio.net/chart.js'\n }\n\n constructor(props: EmbeddableProps<T>) {\n super(props);\n this.container = React.createRef();\n }\n\n abstract createChart (seatsio: Seatsio, config: T): SeatingChart | EventManager | ChartDesigner\n\n async componentDidMount () {\n if(!this.rendering) {\n this.rendering = this.createAndRenderChart()\n }\n }\n\n async componentDidUpdate (prevProps: EmbeddableProps<T>) {\n if (didPropsChange(this.props, prevProps) && this.chart) {\n this.destroyChart()\n this.createAndRenderChart()\n }\n }\n\n async createAndRenderChart () {\n const seatsio = await this.getSeatsio()\n const config = this.extractConfigFromProps()\n config.container = this.container.current\n this.chart = this.createChart(seatsio, config).render()\n if (this.props.onRenderStarted) {\n this.props.onRenderStarted(this.chart)\n }\n }\n\n extractConfigFromProps (): any {\n // noinspection JSUnusedLocalSymbols\n let { chartJsUrl, divId, onRenderStarted, region, ...config } = this.props\n return config\n }\n\n componentWillUnmount () {\n this.destroyChart()\n }\n\n destroyChart () {\n if (this.chart && (this.chart as any).state !== 'DESTROYED') {\n this.chart.destroy()\n }\n }\n\n getSeatsio () {\n if (typeof seatsio === 'undefined') {\n return this.loadSeatsio()\n } else if (seatsio.region !== this.props.region) {\n seatsio = undefined\n return this.loadSeatsio()\n } else {\n return Promise.resolve(seatsio)\n }\n }\n\n loadSeatsio () {\n return new Promise((resolve, reject) => {\n let script = document.createElement('script')\n script.onload = () => {\n seatsio.region = this.props.region\n resolve(seatsio)\n }\n script.onerror = () => reject(`Could not load ${script.src}`)\n script.src = this.props.chartJsUrl.replace('{region}', this.props.region)\n document.head.appendChild(script)\n })\n }\n\n render (): React.ReactNode {\n return (\n <div ref={this.container as unknown as React.RefObject<HTMLDivElement>} style={{'height': '100%', 'width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OAC5BF,EAAQ,OAAO,CACnB,EACAE,EAAO,QAAU,IAAMD,EAAO,kBAAkBC,EAAO,GAAG,EAAE,EAC5DA,EAAO,IAAM,KAAK,MAAM,WAAW,QAAQ,WAAY,KAAK,MAAM,MAAM,EACxE,SAAS,KAAK,YAAYA,CAAM,CACpC,CAAC,CACL,CAEA,QAA2B,CACvB,OACIZ,EAAA,cAAC,OAAI,IAAK,KAAK,UAAyD,MAAO,CAAC,OAAU,OAAQ,MAAS,MAAM,EAAG,CAE5H,CACJ,CApF8BF,EAKnB,aAAe,CAClB,WAAY,2CAChB","names":["Embeddable_exports","__export","Embeddable","__toCommonJS","React","import_util","props","prevProps","seatsio","config","chartJsUrl","divId","onRenderStarted","region","resolve","reject","script"]}
1
+ {"version":3,"sources":["../src/main/Embeddable.tsx","../src/main/util.ts"],"sourcesContent":["import * as React from 'react'\nimport {didPropsChange} from './util'\nimport { ChartDesigner, CommonConfigOptions, EventManager, Region, SeatingChart, Seatsio } from '@seatsio/seatsio-types'\n\nexport type EmbeddableProps<T > = {\n onRenderStarted?: (chart: SeatingChart | EventManager) => void\n chartJsUrl?: string\n region: Region\n} & T\n\nexport default abstract class Embeddable<T extends CommonConfigOptions> extends React.Component<EmbeddableProps<T>> {\n private container: React.RefObject<HTMLDivElement>\n private chart: SeatingChart\n private firstRender: boolean\n\n private static seatsioBundles: { [key: string]: Promise<Seatsio> } = {}\n\n static defaultProps = {\n chartJsUrl: 'https://cdn-{region}.seatsio.net/chart.js'\n }\n\n constructor(props: EmbeddableProps<T>) {\n super(props);\n this.container = React.createRef()\n this.firstRender = true\n }\n\n abstract createChart (seatsio: Seatsio, config: T): SeatingChart | EventManager | ChartDesigner\n\n componentDidMount () {\n if (!Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {\n this.createAndRenderChart()\n this.firstRender = false\n }\n }\n\n componentDidUpdate (prevProps: EmbeddableProps<T>) {\n if (didPropsChange(this.props, prevProps) && this.chart) {\n this.destroyChart()\n this.createAndRenderChart()\n }\n }\n\n getChartUrl () {\n return this.props.chartJsUrl.replace('{region}', this.props.region)\n }\n\n async createAndRenderChart () {\n const seatsio = await this.loadSeatsio()\n const config = this.extractConfigFromProps()\n config.container = this.container.current\n this.chart = this.createChart(seatsio, config).render()\n if (this.props.onRenderStarted) {\n this.props.onRenderStarted(this.chart)\n }\n }\n\n extractConfigFromProps (): any {\n let { chartJsUrl, divId, onRenderStarted, region, ...config } = this.props\n return config\n }\n\n componentWillUnmount () {\n this.destroyChart()\n }\n\n destroyChart () {\n if (this.chart && (this.chart as any).state !== 'DESTROYED') {\n this.chart.destroy()\n }\n }\n\n loadSeatsio (): Promise<Seatsio> {\n const chartUrl = this.getChartUrl()\n if (!Embeddable.seatsioBundles[chartUrl]) {\n Embeddable.seatsioBundles[chartUrl] = new Promise<Seatsio>((resolve, reject) => {\n const script = document.head.appendChild(document.createElement('script'))\n // Seatsio global is not replaced if already present, which would cause the wrong region bundle to resolve when changing region\n window.seatsio = undefined\n script.onload = () => {\n resolve(seatsio)\n }\n script.onerror = () => reject(`Could not load ${script.src}`)\n script.src = chartUrl\n })\n }\n\n return Embeddable.seatsioBundles[chartUrl]\n }\n\n render (): React.ReactNode {\n return (\n <div ref={this.container as unknown as React.RefObject<HTMLDivElement>} style={{'height': '100%', 'width': '100%'}} />\n )\n }\n}","import { BoothProps, GeneralAdmissionAreaProps, InteractiveObjectProps, InteractiveSectionProps, SeatProps, SelectableObjectProps, TableProps } from \"@seatsio/seatsio-types\"\n\nexport const didPropsChange = <P extends { [key: string]: any}>(prevProps: P, nextProps: P): boolean => {\n if (Object.keys(prevProps).length !== Object.keys(nextProps).length) {\n return true\n }\n return Object.keys(nextProps).some((propName: string) => {\n let prevValue = prevProps[propName]\n let nextValue = nextProps[propName]\n if (prevValue && nextValue) {\n if (typeof prevValue === 'function' && typeof nextValue === 'function') {\n return prevValue.toString() !== nextValue.toString()\n }\n if (typeof prevValue === 'object' && typeof nextValue === 'object') {\n return didPropsChange(prevValue, nextValue)\n }\n }\n return prevValue !== nextValue\n })\n}\n\nexport const isSeat = (obj: SelectableObjectProps): obj is SeatProps => obj.objectType === 'Seat'\nexport const isTable = (obj: SelectableObjectProps): obj is TableProps => obj.objectType === 'Table'\nexport const isSection = (obj: SelectableObjectProps): obj is InteractiveSectionProps => obj.objectType === 'section'\nexport const isBooth = (obj: SelectableObjectProps): obj is BoothProps => obj.objectType === 'Booth'\nexport const isGeneralAdmission = (obj: SelectableObjectProps): obj is GeneralAdmissionAreaProps => obj.objectType === 'GeneralAdmissionArea'"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;;;ACEhB,IAAM,iBAAiB,CAAkC,WAAc,cAA0B;AACpG,MAAI,OAAO,KAAK,SAAS,EAAE,WAAW,OAAO,KAAK,SAAS,EAAE,QAAQ;AACjE,WAAO;AAAA,EACX;AACA,SAAO,OAAO,KAAK,SAAS,EAAE,KAAK,CAAC,aAAqB;AACrD,QAAI,YAAY,UAAU,QAAQ;AAClC,QAAI,YAAY,UAAU,QAAQ;AAClC,QAAI,aAAa,WAAW;AACxB,UAAI,OAAO,cAAc,cAAc,OAAO,cAAc,YAAY;AACpE,eAAO,UAAU,SAAS,MAAM,UAAU,SAAS;AAAA,MACvD;AACA,UAAI,OAAO,cAAc,YAAY,OAAO,cAAc,UAAU;AAChE,eAAO,eAAe,WAAW,SAAS;AAAA,MAC9C;AAAA,IACJ;AACA,WAAO,cAAc;AAAA,EACzB,CAAC;AACL;;;ADTA,IAA8B,cAA9B,MAA8B,oBAAwD,gBAA8B;AAAA,EAWhH,YAAY,OAA2B;AACnC,UAAM,KAAK;AACX,SAAK,YAAkB,gBAAU;AACjC,SAAK,cAAc;AAAA,EACvB;AAAA,EAIA,oBAAqB;AACjB,QAAI,CAAC,YAAW,eAAe,KAAK,YAAY,CAAC,KAAK,KAAK,aAAa;AACpE,WAAK,qBAAqB;AAC1B,WAAK,cAAc;AAAA,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AW,eAAe,QAAQ;AAAA,EAC7C;AAAA,EAEA,SAA2B;AACvB,WACI,oCAAC,SAAI,KAAK,KAAK,WAAyD,OAAO,EAAC,UAAU,QAAQ,SAAS,OAAM,GAAG;AAAA,EAE5H;AACJ;AArF8B,YAKX,iBAAsD,CAAC;AAL5C,YAOnB,eAAe;AAAA,EAClB,YAAY;AAChB;AATJ,IAA8B,aAA9B;","names":["seatsio"]}
@@ -1,2 +1,94 @@
1
- import*as o from"react";import{didPropsChange as n}from"./util";class s extends o.Component{constructor(e){super(e);this.container=o.createRef()}async componentDidMount(){this.rendering||(this.rendering=this.createAndRenderChart())}async componentDidUpdate(e){n(this.props,e)&&this.chart&&(this.destroyChart(),this.createAndRenderChart())}async createAndRenderChart(){const e=await this.getSeatsio(),r=this.extractConfigFromProps();r.container=this.container.current,this.chart=this.createChart(e,r).render(),this.props.onRenderStarted&&this.props.onRenderStarted(this.chart)}extractConfigFromProps(){let{chartJsUrl:e,divId:r,onRenderStarted:t,region:h,...i}=this.props;return i}componentWillUnmount(){this.destroyChart()}destroyChart(){this.chart&&this.chart.state!=="DESTROYED"&&this.chart.destroy()}getSeatsio(){return typeof seatsio=="undefined"?this.loadSeatsio():seatsio.region!==this.props.region?(seatsio=void 0,this.loadSeatsio()):Promise.resolve(seatsio)}loadSeatsio(){return new Promise((e,r)=>{let t=document.createElement("script");t.onload=()=>{seatsio.region=this.props.region,e(seatsio)},t.onerror=()=>r(`Could not load ${t.src}`),t.src=this.props.chartJsUrl.replace("{region}",this.props.region),document.head.appendChild(t)})}render(){return o.createElement("div",{ref:this.container,style:{height:"100%",width:"100%"}})}}s.defaultProps={chartJsUrl:"https://cdn-{region}.seatsio.net/chart.js"};export{s as default};
1
+ // src/main/Embeddable.tsx
2
+ import * as React from "react";
3
+
4
+ // src/main/util.ts
5
+ var didPropsChange = (prevProps, nextProps) => {
6
+ if (Object.keys(prevProps).length !== Object.keys(nextProps).length) {
7
+ return true;
8
+ }
9
+ return Object.keys(nextProps).some((propName) => {
10
+ let prevValue = prevProps[propName];
11
+ let nextValue = nextProps[propName];
12
+ if (prevValue && nextValue) {
13
+ if (typeof prevValue === "function" && typeof nextValue === "function") {
14
+ return prevValue.toString() !== nextValue.toString();
15
+ }
16
+ if (typeof prevValue === "object" && typeof nextValue === "object") {
17
+ return didPropsChange(prevValue, nextValue);
18
+ }
19
+ }
20
+ return prevValue !== nextValue;
21
+ });
22
+ };
23
+
24
+ // src/main/Embeddable.tsx
25
+ var _Embeddable = class _Embeddable extends React.Component {
26
+ constructor(props) {
27
+ super(props);
28
+ this.container = React.createRef();
29
+ this.firstRender = true;
30
+ }
31
+ componentDidMount() {
32
+ if (!_Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {
33
+ this.createAndRenderChart();
34
+ this.firstRender = false;
35
+ }
36
+ }
37
+ componentDidUpdate(prevProps) {
38
+ if (didPropsChange(this.props, prevProps) && this.chart) {
39
+ this.destroyChart();
40
+ this.createAndRenderChart();
41
+ }
42
+ }
43
+ getChartUrl() {
44
+ return this.props.chartJsUrl.replace("{region}", this.props.region);
45
+ }
46
+ async createAndRenderChart() {
47
+ const seatsio2 = await this.loadSeatsio();
48
+ const config = this.extractConfigFromProps();
49
+ config.container = this.container.current;
50
+ this.chart = this.createChart(seatsio2, config).render();
51
+ if (this.props.onRenderStarted) {
52
+ this.props.onRenderStarted(this.chart);
53
+ }
54
+ }
55
+ extractConfigFromProps() {
56
+ let { chartJsUrl, divId, onRenderStarted, region, ...config } = this.props;
57
+ return config;
58
+ }
59
+ componentWillUnmount() {
60
+ this.destroyChart();
61
+ }
62
+ destroyChart() {
63
+ if (this.chart && this.chart.state !== "DESTROYED") {
64
+ this.chart.destroy();
65
+ }
66
+ }
67
+ loadSeatsio() {
68
+ const chartUrl = this.getChartUrl();
69
+ if (!_Embeddable.seatsioBundles[chartUrl]) {
70
+ _Embeddable.seatsioBundles[chartUrl] = new Promise((resolve, reject) => {
71
+ const script = document.head.appendChild(document.createElement("script"));
72
+ window.seatsio = void 0;
73
+ script.onload = () => {
74
+ resolve(seatsio);
75
+ };
76
+ script.onerror = () => reject(`Could not load ${script.src}`);
77
+ script.src = chartUrl;
78
+ });
79
+ }
80
+ return _Embeddable.seatsioBundles[chartUrl];
81
+ }
82
+ render() {
83
+ return /* @__PURE__ */ React.createElement("div", { ref: this.container, style: { "height": "100%", "width": "100%" } });
84
+ }
85
+ };
86
+ _Embeddable.seatsioBundles = {};
87
+ _Embeddable.defaultProps = {
88
+ chartJsUrl: "https://cdn-{region}.seatsio.net/chart.js"
89
+ };
90
+ var Embeddable = _Embeddable;
91
+ export {
92
+ Embeddable as default
93
+ };
2
94
  //# sourceMappingURL=Embeddable.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/main/Embeddable.tsx"],"sourcesContent":["import * as React from 'react'\nimport {didPropsChange} from './util'\nimport { ChartDesigner, CommonConfigOptions, EventManager, Region, SeatingChart, Seatsio } from '@seatsio/seatsio-types'\n\nexport type EmbeddableProps<T> = {\n onRenderStarted?: (chart: SeatingChart) => void\n chartJsUrl?: string\n region: Region\n} & T\n\nexport default abstract class Embeddable<T extends CommonConfigOptions> extends React.Component<EmbeddableProps<T>> {\n private container: React.RefObject<HTMLDivElement>\n private rendering?: Promise<void>\n private chart: SeatingChart\n\n static defaultProps = {\n chartJsUrl: 'https://cdn-{region}.seatsio.net/chart.js'\n }\n\n constructor(props: EmbeddableProps<T>) {\n super(props);\n this.container = React.createRef();\n }\n\n abstract createChart (seatsio: Seatsio, config: T): SeatingChart | EventManager | ChartDesigner\n\n async componentDidMount () {\n if(!this.rendering) {\n this.rendering = this.createAndRenderChart()\n }\n }\n\n async componentDidUpdate (prevProps: EmbeddableProps<T>) {\n if (didPropsChange(this.props, prevProps) && this.chart) {\n this.destroyChart()\n this.createAndRenderChart()\n }\n }\n\n async createAndRenderChart () {\n const seatsio = await this.getSeatsio()\n const config = this.extractConfigFromProps()\n config.container = this.container.current\n this.chart = this.createChart(seatsio, config).render()\n if (this.props.onRenderStarted) {\n this.props.onRenderStarted(this.chart)\n }\n }\n\n extractConfigFromProps (): any {\n // noinspection JSUnusedLocalSymbols\n let { chartJsUrl, divId, onRenderStarted, region, ...config } = this.props\n return config\n }\n\n componentWillUnmount () {\n this.destroyChart()\n }\n\n destroyChart () {\n if (this.chart && (this.chart as any).state !== 'DESTROYED') {\n this.chart.destroy()\n }\n }\n\n getSeatsio () {\n if (typeof seatsio === 'undefined') {\n return this.loadSeatsio()\n } else if (seatsio.region !== this.props.region) {\n seatsio = undefined\n return this.loadSeatsio()\n } else {\n return Promise.resolve(seatsio)\n }\n }\n\n loadSeatsio () {\n return new Promise((resolve, reject) => {\n let script = document.createElement('script')\n script.onload = () => {\n seatsio.region = this.props.region\n resolve(seatsio)\n }\n script.onerror = () => reject(`Could not load ${script.src}`)\n script.src = this.props.chartJsUrl.replace('{region}', this.props.region)\n document.head.appendChild(script)\n })\n }\n\n render (): React.ReactNode {\n return (\n <div ref={this.container as unknown as React.RefObject<HTMLDivElement>} style={{'height': '100%', 'width': '100%'}} />\n )\n }\n}"],"mappings":"AAAA,UAAYA,MAAW,QACvB,OAAQ,kBAAAC,MAAqB,SAS7B,MAAOC,UAAyEF,EAAM,SAA8B,CAShH,YAAYG,EAA2B,CACnC,MAAMA,CAAK,EACX,KAAK,UAAYH,EAAM,UAAU,CACrC,CAIA,MAAM,mBAAqB,CACnB,KAAK,YACL,KAAK,UAAY,KAAK,qBAAqB,EAEnD,CAEA,MAAM,mBAAoBI,EAA+B,CACjDH,EAAe,KAAK,MAAOG,CAAS,GAAK,KAAK,QAC9C,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAElC,CAEA,MAAM,sBAAwB,CAC1B,MAAMC,EAAU,MAAM,KAAK,WAAW,EAChCC,EAAS,KAAK,uBAAuB,EAC3CA,EAAO,UAAY,KAAK,UAAU,QAClC,KAAK,MAAQ,KAAK,YAAYD,EAASC,CAAM,EAAE,OAAO,EAClD,KAAK,MAAM,iBACX,KAAK,MAAM,gBAAgB,KAAK,KAAK,CAE7C,CAEA,wBAA+B,CAE3B,GAAI,CAAE,WAAAC,EAAY,MAAAC,EAAO,gBAAAC,EAAiB,OAAAC,EAAQ,GAAGJ,CAAO,EAAI,KAAK,MACrE,OAAOA,CACX,CAEA,sBAAwB,CACpB,KAAK,aAAa,CACtB,CAEA,cAAgB,CACR,KAAK,OAAU,KAAK,MAAc,QAAU,aAC5C,KAAK,MAAM,QAAQ,CAE3B,CAEA,YAAc,CACV,OAAI,OAAO,SAAY,YACZ,KAAK,YAAY,EACjB,QAAQ,SAAW,KAAK,MAAM,QACrC,QAAU,OACH,KAAK,YAAY,GAEjB,QAAQ,QAAQ,OAAO,CAEtC,CAEA,aAAe,CACX,OAAO,IAAI,QAAQ,CAACK,EAASC,IAAW,CACpC,IAAIC,EAAS,SAAS,cAAc,QAAQ,EAC5CA,EAAO,OAAS,IAAM,CAClB,QAAQ,OAAS,KAAK,MAAM,OAC5BF,EAAQ,OAAO,CACnB,EACAE,EAAO,QAAU,IAAMD,EAAO,kBAAkBC,EAAO,GAAG,EAAE,EAC5DA,EAAO,IAAM,KAAK,MAAM,WAAW,QAAQ,WAAY,KAAK,MAAM,MAAM,EACxE,SAAS,KAAK,YAAYA,CAAM,CACpC,CAAC,CACL,CAEA,QAA2B,CACvB,OACIb,EAAA,cAAC,OAAI,IAAK,KAAK,UAAyD,MAAO,CAAC,OAAU,OAAQ,MAAS,MAAM,EAAG,CAE5H,CACJ,CApF8BE,EAKnB,aAAe,CAClB,WAAY,2CAChB","names":["React","didPropsChange","Embeddable","props","prevProps","seatsio","config","chartJsUrl","divId","onRenderStarted","region","resolve","reject","script"]}
1
+ {"version":3,"sources":["../src/main/Embeddable.tsx","../src/main/util.ts"],"sourcesContent":["import * as React from 'react'\nimport {didPropsChange} from './util'\nimport { ChartDesigner, CommonConfigOptions, EventManager, Region, SeatingChart, Seatsio } from '@seatsio/seatsio-types'\n\nexport type EmbeddableProps<T > = {\n onRenderStarted?: (chart: SeatingChart | EventManager) => void\n chartJsUrl?: string\n region: Region\n} & T\n\nexport default abstract class Embeddable<T extends CommonConfigOptions> extends React.Component<EmbeddableProps<T>> {\n private container: React.RefObject<HTMLDivElement>\n private chart: SeatingChart\n private firstRender: boolean\n\n private static seatsioBundles: { [key: string]: Promise<Seatsio> } = {}\n\n static defaultProps = {\n chartJsUrl: 'https://cdn-{region}.seatsio.net/chart.js'\n }\n\n constructor(props: EmbeddableProps<T>) {\n super(props);\n this.container = React.createRef()\n this.firstRender = true\n }\n\n abstract createChart (seatsio: Seatsio, config: T): SeatingChart | EventManager | ChartDesigner\n\n componentDidMount () {\n if (!Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {\n this.createAndRenderChart()\n this.firstRender = false\n }\n }\n\n componentDidUpdate (prevProps: EmbeddableProps<T>) {\n if (didPropsChange(this.props, prevProps) && this.chart) {\n this.destroyChart()\n this.createAndRenderChart()\n }\n }\n\n getChartUrl () {\n return this.props.chartJsUrl.replace('{region}', this.props.region)\n }\n\n async createAndRenderChart () {\n const seatsio = await this.loadSeatsio()\n const config = this.extractConfigFromProps()\n config.container = this.container.current\n this.chart = this.createChart(seatsio, config).render()\n if (this.props.onRenderStarted) {\n this.props.onRenderStarted(this.chart)\n }\n }\n\n extractConfigFromProps (): any {\n let { chartJsUrl, divId, onRenderStarted, region, ...config } = this.props\n return config\n }\n\n componentWillUnmount () {\n this.destroyChart()\n }\n\n destroyChart () {\n if (this.chart && (this.chart as any).state !== 'DESTROYED') {\n this.chart.destroy()\n }\n }\n\n loadSeatsio (): Promise<Seatsio> {\n const chartUrl = this.getChartUrl()\n if (!Embeddable.seatsioBundles[chartUrl]) {\n Embeddable.seatsioBundles[chartUrl] = new Promise<Seatsio>((resolve, reject) => {\n const script = document.head.appendChild(document.createElement('script'))\n // Seatsio global is not replaced if already present, which would cause the wrong region bundle to resolve when changing region\n window.seatsio = undefined\n script.onload = () => {\n resolve(seatsio)\n }\n script.onerror = () => reject(`Could not load ${script.src}`)\n script.src = chartUrl\n })\n }\n\n return Embeddable.seatsioBundles[chartUrl]\n }\n\n render (): React.ReactNode {\n return (\n <div ref={this.container as unknown as React.RefObject<HTMLDivElement>} style={{'height': '100%', 'width': '100%'}} />\n )\n }\n}","import { BoothProps, GeneralAdmissionAreaProps, InteractiveObjectProps, InteractiveSectionProps, SeatProps, SelectableObjectProps, TableProps } from \"@seatsio/seatsio-types\"\n\nexport const didPropsChange = <P extends { [key: string]: any}>(prevProps: P, nextProps: P): boolean => {\n if (Object.keys(prevProps).length !== Object.keys(nextProps).length) {\n return true\n }\n return Object.keys(nextProps).some((propName: string) => {\n let prevValue = prevProps[propName]\n let nextValue = nextProps[propName]\n if (prevValue && nextValue) {\n if (typeof prevValue === 'function' && typeof nextValue === 'function') {\n return prevValue.toString() !== nextValue.toString()\n }\n if (typeof prevValue === 'object' && typeof nextValue === 'object') {\n return didPropsChange(prevValue, nextValue)\n }\n }\n return prevValue !== nextValue\n })\n}\n\nexport const isSeat = (obj: SelectableObjectProps): obj is SeatProps => obj.objectType === 'Seat'\nexport const isTable = (obj: SelectableObjectProps): obj is TableProps => obj.objectType === 'Table'\nexport const isSection = (obj: SelectableObjectProps): obj is InteractiveSectionProps => obj.objectType === 'section'\nexport const isBooth = (obj: SelectableObjectProps): obj is BoothProps => obj.objectType === 'Booth'\nexport const isGeneralAdmission = (obj: SelectableObjectProps): obj is GeneralAdmissionAreaProps => obj.objectType === 'GeneralAdmissionArea'"],"mappings":";AAAA,YAAY,WAAW;;;ACEhB,IAAM,iBAAiB,CAAkC,WAAc,cAA0B;AACpG,MAAI,OAAO,KAAK,SAAS,EAAE,WAAW,OAAO,KAAK,SAAS,EAAE,QAAQ;AACjE,WAAO;AAAA,EACX;AACA,SAAO,OAAO,KAAK,SAAS,EAAE,KAAK,CAAC,aAAqB;AACrD,QAAI,YAAY,UAAU,QAAQ;AAClC,QAAI,YAAY,UAAU,QAAQ;AAClC,QAAI,aAAa,WAAW;AACxB,UAAI,OAAO,c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AAI,KAAK,SAAU,KAAK,MAAc,UAAU,aAAa;AACzD,WAAK,MAAM,QAAQ;AAAA,IACvB;AAAA,EACJ;AAAA,EAEA,cAAiC;AAC7B,UAAM,WAAW,KAAK,YAAY;AAClC,QAAI,CAAC,YAAW,eAAe,QAAQ,GAAG;AACtC,kBAAW,eAAe,QAAQ,IAAI,IAAI,QAAiB,CAAC,SAAS,WAAW;AAC5E,cAAM,SAAS,SAAS,KAAK,YAAY,SAAS,cAAc,QAAQ,CAAC;AAEzE,eAAO,UAAU;AACjB,eAAO,SAAS,MAAM;AAClB,kBAAQ,OAAO;AAAA,QACnB;AACA,eAAO,UAAU,MAAM,OAAO,kBAAkB,OAAO,GAAG,EAAE;AAC5D,eAAO,MAAM;AAAA,MACjB,CAAC;AAAA,IACL;AAEA,WAAO,YAAW,eAAe,QAAQ;AAAA,EAC7C;AAAA,EAEA,SAA2B;AACvB,WACI,oCAAC,SAAI,KAAK,KAAK,WAAyD,OAAO,EAAC,UAAU,QAAQ,SAAS,OAAM,GAAG;AAAA,EAE5H;AACJ;AArF8B,YAKX,iBAAsD,CAAC;AAL5C,YAOnB,eAAe;AAAA,EAClB,YAAY;AAChB;AATJ,IAA8B,aAA9B;","names":["seatsio"]}
@@ -1,2 +1,133 @@
1
- var C=Object.create;var n=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of p(t))!m.call(e,i)&&i!==r&&n(e,i,{get:()=>t[i],enumerable:!(o=f(t,i))||o.enumerable});return e};var d=(e,t,r)=>(r=e!=null?C(h(e)):{},s(t||!e||!e.__esModule?n(r,"default",{value:e,enumerable:!0}):r,e)),S=e=>s(n({},"__esModule",{value:!0}),e);var l={};D(l,{default:()=>g});module.exports=S(l);var a=d(require("./Embeddable"));class g extends a.default{createChart(t,r){return new t.SeatingChartDesigner(r)}}
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/main/SeatsioDesigner.tsx
30
+ var SeatsioDesigner_exports = {};
31
+ __export(SeatsioDesigner_exports, {
32
+ default: () => SeatsioDesigner
33
+ });
34
+ module.exports = __toCommonJS(SeatsioDesigner_exports);
35
+
36
+ // src/main/Embeddable.tsx
37
+ var React = __toESM(require("react"));
38
+
39
+ // src/main/util.ts
40
+ var didPropsChange = (prevProps, nextProps) => {
41
+ if (Object.keys(prevProps).length !== Object.keys(nextProps).length) {
42
+ return true;
43
+ }
44
+ return Object.keys(nextProps).some((propName) => {
45
+ let prevValue = prevProps[propName];
46
+ let nextValue = nextProps[propName];
47
+ if (prevValue && nextValue) {
48
+ if (typeof prevValue === "function" && typeof nextValue === "function") {
49
+ return prevValue.toString() !== nextValue.toString();
50
+ }
51
+ if (typeof prevValue === "object" && typeof nextValue === "object") {
52
+ return didPropsChange(prevValue, nextValue);
53
+ }
54
+ }
55
+ return prevValue !== nextValue;
56
+ });
57
+ };
58
+
59
+ // src/main/Embeddable.tsx
60
+ var _Embeddable = class _Embeddable extends React.Component {
61
+ constructor(props) {
62
+ super(props);
63
+ this.container = React.createRef();
64
+ this.firstRender = true;
65
+ }
66
+ componentDidMount() {
67
+ if (!_Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {
68
+ this.createAndRenderChart();
69
+ this.firstRender = false;
70
+ }
71
+ }
72
+ componentDidUpdate(prevProps) {
73
+ if (didPropsChange(this.props, prevProps) && this.chart) {
74
+ this.destroyChart();
75
+ this.createAndRenderChart();
76
+ }
77
+ }
78
+ getChartUrl() {
79
+ return this.props.chartJsUrl.replace("{region}", this.props.region);
80
+ }
81
+ async createAndRenderChart() {
82
+ const seatsio2 = await this.loadSeatsio();
83
+ const config = this.extractConfigFromProps();
84
+ config.container = this.container.current;
85
+ this.chart = this.createChart(seatsio2, config).render();
86
+ if (this.props.onRenderStarted) {
87
+ this.props.onRenderStarted(this.chart);
88
+ }
89
+ }
90
+ extractConfigFromProps() {
91
+ let { chartJsUrl, divId, onRenderStarted, region, ...config } = this.props;
92
+ return config;
93
+ }
94
+ componentWillUnmount() {
95
+ this.destroyChart();
96
+ }
97
+ destroyChart() {
98
+ if (this.chart && this.chart.state !== "DESTROYED") {
99
+ this.chart.destroy();
100
+ }
101
+ }
102
+ loadSeatsio() {
103
+ const chartUrl = this.getChartUrl();
104
+ if (!_Embeddable.seatsioBundles[chartUrl]) {
105
+ _Embeddable.seatsioBundles[chartUrl] = new Promise((resolve, reject) => {
106
+ const script = document.head.appendChild(document.createElement("script"));
107
+ window.seatsio = void 0;
108
+ script.onload = () => {
109
+ resolve(seatsio);
110
+ };
111
+ script.onerror = () => reject(`Could not load ${script.src}`);
112
+ script.src = chartUrl;
113
+ });
114
+ }
115
+ return _Embeddable.seatsioBundles[chartUrl];
116
+ }
117
+ render() {
118
+ return /* @__PURE__ */ React.createElement("div", { ref: this.container, style: { "height": "100%", "width": "100%" } });
119
+ }
120
+ };
121
+ _Embeddable.seatsioBundles = {};
122
+ _Embeddable.defaultProps = {
123
+ chartJsUrl: "https://cdn-{region}.seatsio.net/chart.js"
124
+ };
125
+ var Embeddable = _Embeddable;
126
+
127
+ // src/main/SeatsioDesigner.tsx
128
+ var SeatsioDesigner = class extends Embeddable {
129
+ createChart(seatsio2, config) {
130
+ return new seatsio2.SeatingChartDesigner(config);
131
+ }
132
+ };
2
133
  //# sourceMappingURL=SeatsioDesigner.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/main/SeatsioDesigner.tsx"],"sourcesContent":["import Embeddable from './Embeddable'\nimport { ChartDesignerConfigOptions, Seatsio } from '@seatsio/seatsio-types'\n\nexport default class SeatsioDesigner extends Embeddable<ChartDesignerConfigOptions> {\n createChart (seatsio: Seatsio, config: ChartDesignerConfigOptions) {\n return new seatsio.SeatingChartDesigner(config)\n }\n}"],"mappings":"6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAuB,2BAGvB,MAAOF,UAAsC,EAAAG,OAAuC,CAChF,YAAaC,EAAkBC,EAAoC,CAC/D,OAAO,IAAID,EAAQ,qBAAqBC,CAAM,CAClD,CACJ","names":["SeatsioDesigner_exports","__export","SeatsioDesigner","__toCommonJS","import_Embeddable","Embeddable","seatsio","config"]}
1
+ {"version":3,"sources":["../src/main/SeatsioDesigner.tsx","../src/main/Embeddable.tsx","../src/main/util.ts"],"sourcesContent":["import Embeddable from './Embeddable'\nimport { ChartDesignerConfigOptions, Seatsio } from '@seatsio/seatsio-types'\n\nexport default class SeatsioDesigner extends Embeddable<ChartDesignerConfigOptions> {\n createChart (seatsio: Seatsio, config: ChartDesignerConfigOptions) {\n return new seatsio.SeatingChartDesigner(config)\n }\n}","import * as React from 'react'\nimport {didPropsChange} from './util'\nimport { ChartDesigner, CommonConfigOptions, EventManager, Region, SeatingChart, Seatsio } from '@seatsio/seatsio-types'\n\nexport type EmbeddableProps<T > = {\n onRenderStarted?: (chart: SeatingChart | EventManager) => void\n chartJsUrl?: string\n region: Region\n} & T\n\nexport default abstract class Embeddable<T extends CommonConfigOptions> extends React.Component<EmbeddableProps<T>> {\n private container: React.RefObject<HTMLDivElement>\n private chart: SeatingChart\n private firstRender: boolean\n\n private static seatsioBundles: { [key: string]: Promise<Seatsio> } = {}\n\n static defaultProps = {\n chartJsUrl: 'https://cdn-{region}.seatsio.net/chart.js'\n }\n\n constructor(props: EmbeddableProps<T>) {\n super(props);\n this.container = React.createRef()\n this.firstRender = true\n }\n\n abstract createChart (seatsio: Seatsio, config: T): SeatingChart | EventManager | ChartDesigner\n\n componentDidMount () {\n if (!Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {\n this.createAndRenderChart()\n this.firstRender = false\n }\n }\n\n componentDidUpdate (prevProps: EmbeddableProps<T>) {\n if (didPropsChange(this.props, prevProps) && this.chart) {\n this.destroyChart()\n this.createAndRenderChart()\n }\n }\n\n getChartUrl () {\n return this.props.chartJsUrl.replace('{region}', this.props.region)\n }\n\n async createAndRenderChart () {\n const seatsio = await this.loadSeatsio()\n const config = this.extractConfigFromProps()\n config.container = this.container.current\n this.chart = this.createChart(seatsio, config).render()\n if (this.props.onRenderStarted) {\n this.props.onRenderStarted(this.chart)\n }\n }\n\n extractConfigFromProps (): any {\n let { chartJsUrl, divId, onRenderStarted, region, ...config } = this.props\n return config\n }\n\n componentWillUnmount () {\n this.destroyChart()\n }\n\n destroyChart () {\n if (this.chart && (this.chart as any).state !== 'DESTROYED') {\n this.chart.destroy()\n }\n }\n\n loadSeatsio (): Promise<Seatsio> {\n const chartUrl = this.getChartUrl()\n if (!Embeddable.seatsioBundles[chartUrl]) {\n Embeddable.seatsioBundles[chartUrl] = new Promise<Seatsio>((resolve, reject) => {\n const script = document.head.appendChild(document.createElement('script'))\n // Seatsio global is not replaced if already present, which would cause the wrong region bundle to resolve when changing region\n window.seatsio = undefined\n script.onload = () => {\n resolve(seatsio)\n }\n script.onerror = () => reject(`Could not load ${script.src}`)\n script.src = chartUrl\n })\n }\n\n return Embeddable.seatsioBundles[chartUrl]\n }\n\n render (): React.ReactNode {\n return (\n <div ref={this.container as unknown as React.RefObject<HTMLDivElement>} style={{'height': '100%', 'width': '100%'}} />\n )\n }\n}","import { BoothProps, GeneralAdmissionAreaProps, InteractiveObjectProps, InteractiveSectionProps, SeatProps, SelectableObjectProps, TableProps } from \"@seatsio/seatsio-types\"\n\nexport const didPropsChange = <P extends { [key: string]: any}>(prevProps: P, nextProps: P): boolean => {\n if (Object.keys(prevProps).length !== Object.keys(nextProps).length) {\n return true\n }\n return Object.keys(nextProps).some((propName: string) => {\n let prevValue = prevProps[propName]\n let nextValue = nextProps[propName]\n if (prevValue && nextValue) {\n if (typeof prevValue === 'function' && typeof nextValue === 'function') {\n return prevValue.toString() !== nextValue.toString()\n }\n if (typeof prevValue === 'object' && typeof nextValue === 'object') {\n return didPropsChange(prevValue, nextValue)\n }\n }\n return prevValue !== nextValue\n })\n}\n\nexport const isSeat = (obj: SelectableObjectProps): obj is SeatProps => obj.objectType === 'Seat'\nexport const isTable = (obj: SelectableObjectProps): obj is TableProps => obj.objectType === 'Table'\nexport const isSection = (obj: SelectableObjectProps): obj is InteractiveSectionProps => obj.objectType === 'section'\nexport const isBooth = (obj: SelectableObjectProps): obj is BoothProps => obj.objectType === 'Booth'\nexport const isGeneralAdmission = (obj: SelectableObjectProps): obj is GeneralAdmissionAreaProps => obj.objectType === 'GeneralAdmissionArea'"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;;;ACEhB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class i extends r{createChart(e,t){return new e.SeatingChartDesigner(t)}}export{i as default};
1
+ // src/main/Embeddable.tsx
2
+ import * as React from "react";
3
+
4
+ // src/main/util.ts
5
+ var didPropsChange = (prevProps, nextProps) => {
6
+ if (Object.keys(prevProps).length !== Object.keys(nextProps).length) {
7
+ return true;
8
+ }
9
+ return Object.keys(nextProps).some((propName) => {
10
+ let prevValue = prevProps[propName];
11
+ let nextValue = nextProps[propName];
12
+ if (prevValue && nextValue) {
13
+ if (typeof prevValue === "function" && typeof nextValue === "function") {
14
+ return prevValue.toString() !== nextValue.toString();
15
+ }
16
+ if (typeof prevValue === "object" && typeof nextValue === "object") {
17
+ return didPropsChange(prevValue, nextValue);
18
+ }
19
+ }
20
+ return prevValue !== nextValue;
21
+ });
22
+ };
23
+
24
+ // src/main/Embeddable.tsx
25
+ var _Embeddable = class _Embeddable extends React.Component {
26
+ constructor(props) {
27
+ super(props);
28
+ this.container = React.createRef();
29
+ this.firstRender = true;
30
+ }
31
+ componentDidMount() {
32
+ if (!_Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {
33
+ this.createAndRenderChart();
34
+ this.firstRender = false;
35
+ }
36
+ }
37
+ componentDidUpdate(prevProps) {
38
+ if (didPropsChange(this.props, prevProps) && this.chart) {
39
+ this.destroyChart();
40
+ this.createAndRenderChart();
41
+ }
42
+ }
43
+ getChartUrl() {
44
+ return this.props.chartJsUrl.replace("{region}", this.props.region);
45
+ }
46
+ async createAndRenderChart() {
47
+ const seatsio2 = await this.loadSeatsio();
48
+ const config = this.extractConfigFromProps();
49
+ config.container = this.container.current;
50
+ this.chart = this.createChart(seatsio2, config).render();
51
+ if (this.props.onRenderStarted) {
52
+ this.props.onRenderStarted(this.chart);
53
+ }
54
+ }
55
+ extractConfigFromProps() {
56
+ let { chartJsUrl, divId, onRenderStarted, region, ...config } = this.props;
57
+ return config;
58
+ }
59
+ componentWillUnmount() {
60
+ this.destroyChart();
61
+ }
62
+ destroyChart() {
63
+ if (this.chart && this.chart.state !== "DESTROYED") {
64
+ this.chart.destroy();
65
+ }
66
+ }
67
+ loadSeatsio() {
68
+ const chartUrl = this.getChartUrl();
69
+ if (!_Embeddable.seatsioBundles[chartUrl]) {
70
+ _Embeddable.seatsioBundles[chartUrl] = new Promise((resolve, reject) => {
71
+ const script = document.head.appendChild(document.createElement("script"));
72
+ window.seatsio = void 0;
73
+ script.onload = () => {
74
+ resolve(seatsio);
75
+ };
76
+ script.onerror = () => reject(`Could not load ${script.src}`);
77
+ script.src = chartUrl;
78
+ });
79
+ }
80
+ return _Embeddable.seatsioBundles[chartUrl];
81
+ }
82
+ render() {
83
+ return /* @__PURE__ */ React.createElement("div", { ref: this.container, style: { "height": "100%", "width": "100%" } });
84
+ }
85
+ };
86
+ _Embeddable.seatsioBundles = {};
87
+ _Embeddable.defaultProps = {
88
+ chartJsUrl: "https://cdn-{region}.seatsio.net/chart.js"
89
+ };
90
+ var Embeddable = _Embeddable;
91
+
92
+ // src/main/SeatsioDesigner.tsx
93
+ var SeatsioDesigner = class extends Embeddable {
94
+ createChart(seatsio2, config) {
95
+ return new seatsio2.SeatingChartDesigner(config);
96
+ }
97
+ };
98
+ export {
99
+ SeatsioDesigner as default
100
+ };
2
101
  //# sourceMappingURL=SeatsioDesigner.mjs.map