@seatsio/seatsio-react 14.3.0 → 14.5.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
 
@@ -55,24 +55,29 @@ var didPropsChange = (prevProps, nextProps) => {
55
55
  };
56
56
 
57
57
  // src/main/Embeddable.tsx
58
- var Embeddable = class extends React.Component {
58
+ var _Embeddable = class _Embeddable extends React.Component {
59
59
  constructor(props) {
60
60
  super(props);
61
61
  this.container = React.createRef();
62
+ this.firstRender = true;
62
63
  }
63
- async componentDidMount() {
64
- if (!this.rendering) {
65
- this.rendering = this.createAndRenderChart();
64
+ componentDidMount() {
65
+ if (!_Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {
66
+ this.createAndRenderChart();
67
+ this.firstRender = false;
66
68
  }
67
69
  }
68
- async componentDidUpdate(prevProps) {
70
+ componentDidUpdate(prevProps) {
69
71
  if (didPropsChange(this.props, prevProps) && this.chart) {
70
72
  this.destroyChart();
71
73
  this.createAndRenderChart();
72
74
  }
73
75
  }
76
+ getChartUrl() {
77
+ return this.props.chartJsUrl.replace("{region}", this.props.region);
78
+ }
74
79
  async createAndRenderChart() {
75
- const seatsio2 = await this.getSeatsio();
80
+ const seatsio2 = await this.loadSeatsio();
76
81
  const config = this.extractConfigFromProps();
77
82
  config.container = this.container.current;
78
83
  this.chart = this.createChart(seatsio2, config).render();
@@ -92,33 +97,28 @@ var Embeddable = class extends React.Component {
92
97
  this.chart.destroy();
93
98
  }
94
99
  }
95
- getSeatsio() {
96
- if (typeof seatsio === "undefined") {
97
- return this.loadSeatsio();
98
- } else if (seatsio.region !== this.props.region) {
99
- seatsio = void 0;
100
- return this.loadSeatsio();
101
- } else {
102
- return Promise.resolve(seatsio);
103
- }
104
- }
105
100
  loadSeatsio() {
106
- return new Promise((resolve, reject) => {
107
- let script = document.createElement("script");
108
- script.onload = () => {
109
- seatsio.region = this.props.region;
110
- resolve(seatsio);
111
- };
112
- script.onerror = () => reject(`Could not load ${script.src}`);
113
- script.src = this.props.chartJsUrl.replace("{region}", this.props.region);
114
- document.head.appendChild(script);
115
- });
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];
116
114
  }
117
115
  render() {
118
116
  return /* @__PURE__ */ React.createElement("div", { ref: this.container, style: { "height": "100%", "width": "100%" } });
119
117
  }
120
118
  };
121
- Embeddable.defaultProps = {
119
+ _Embeddable.seatsioBundles = {};
120
+ _Embeddable.defaultProps = {
122
121
  chartJsUrl: "https://cdn-{region}.seatsio.net/chart.js"
123
122
  };
123
+ var Embeddable = _Embeddable;
124
124
  //# sourceMappingURL=Embeddable.js.map
@@ -1 +1 @@
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) => 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}","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,O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BAAwB;AACpB,SAAK,aAAa;AAAA,EACtB;AAAA,EAEA,eAAgB;AACZ,QAAI,KAAK,SAAU,KAAK,MAAc,UAAU,aAAa;AACzD,WAAK,MAAM,QAAQ;AAAA,IACvB;AAAA,EACJ;AAAA,EAEA,aAAc;AACV,QAAI,OAAO,YAAY,aAAa;AAChC,aAAO,KAAK,YAAY;AAAA,IAC5B,WAAW,QAAQ,WAAW,KAAK,MAAM,QAAQ;AAC7C,gBAAU;AACV,aAAO,KAAK,YAAY;AAAA,IAC5B,OAAO;AACH,aAAO,QAAQ,QAAQ,OAAO;AAAA,IAClC;AAAA,EACJ;AAAA,EAEA,cAAe;AACX,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACpC,UAAI,SAAS,SAAS,cAAc,QAAQ;AAC5C,aAAO,SAAS,MAAM;AAClB,gBAAQ,SAAS,KAAK,MAAM;AAC5B,gBAAQ,OAAO;AAAA,MACnB;AACA,aAAO,UAAU,MAAM,OAAO,kBAAkB,OAAO,GAAG,EAAE;AAC5D,aAAO,MAAM,KAAK,MAAM,WAAW,QAAQ,YAAY,KAAK,MAAM,MAAM;AACxE,eAAS,KAAK,YAAY,MAAM;AAAA,IACpC,CAAC;AAAA,EACL;AAAA,EAEA,SAA2B;AACvB,WACI,oCAAC,SAAI,KAAK,KAAK,WAAyD,OAAO,EAAC,UAAU,QAAQ,SAAS,OAAM,GAAG;AAAA,EAE5H;AACJ;AApF8B,WAKnB,eAAe;AAAA,EAClB,YAAY;AAChB;","names":["seatsio"]}
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,Y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AAc,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"]}
@@ -22,24 +22,29 @@ var didPropsChange = (prevProps, nextProps) => {
22
22
  };
23
23
 
24
24
  // src/main/Embeddable.tsx
25
- var Embeddable = class extends React.Component {
25
+ var _Embeddable = class _Embeddable extends React.Component {
26
26
  constructor(props) {
27
27
  super(props);
28
28
  this.container = React.createRef();
29
+ this.firstRender = true;
29
30
  }
30
- async componentDidMount() {
31
- if (!this.rendering) {
32
- this.rendering = this.createAndRenderChart();
31
+ componentDidMount() {
32
+ if (!_Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {
33
+ this.createAndRenderChart();
34
+ this.firstRender = false;
33
35
  }
34
36
  }
35
- async componentDidUpdate(prevProps) {
37
+ componentDidUpdate(prevProps) {
36
38
  if (didPropsChange(this.props, prevProps) && this.chart) {
37
39
  this.destroyChart();
38
40
  this.createAndRenderChart();
39
41
  }
40
42
  }
43
+ getChartUrl() {
44
+ return this.props.chartJsUrl.replace("{region}", this.props.region);
45
+ }
41
46
  async createAndRenderChart() {
42
- const seatsio2 = await this.getSeatsio();
47
+ const seatsio2 = await this.loadSeatsio();
43
48
  const config = this.extractConfigFromProps();
44
49
  config.container = this.container.current;
45
50
  this.chart = this.createChart(seatsio2, config).render();
@@ -59,35 +64,30 @@ var Embeddable = class extends React.Component {
59
64
  this.chart.destroy();
60
65
  }
61
66
  }
62
- getSeatsio() {
63
- if (typeof seatsio === "undefined") {
64
- return this.loadSeatsio();
65
- } else if (seatsio.region !== this.props.region) {
66
- seatsio = void 0;
67
- return this.loadSeatsio();
68
- } else {
69
- return Promise.resolve(seatsio);
70
- }
71
- }
72
67
  loadSeatsio() {
73
- return new Promise((resolve, reject) => {
74
- let script = document.createElement("script");
75
- script.onload = () => {
76
- seatsio.region = this.props.region;
77
- resolve(seatsio);
78
- };
79
- script.onerror = () => reject(`Could not load ${script.src}`);
80
- script.src = this.props.chartJsUrl.replace("{region}", this.props.region);
81
- document.head.appendChild(script);
82
- });
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];
83
81
  }
84
82
  render() {
85
83
  return /* @__PURE__ */ React.createElement("div", { ref: this.container, style: { "height": "100%", "width": "100%" } });
86
84
  }
87
85
  };
88
- Embeddable.defaultProps = {
86
+ _Embeddable.seatsioBundles = {};
87
+ _Embeddable.defaultProps = {
89
88
  chartJsUrl: "https://cdn-{region}.seatsio.net/chart.js"
90
89
  };
90
+ var Embeddable = _Embeddable;
91
91
  export {
92
92
  Embeddable as default
93
93
  };
@@ -1 +1 @@
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) => 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}","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,S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AU,KAAK,MAAc,UAAU,aAAa;AACzD,WAAK,MAAM,QAAQ;AAAA,IACvB;AAAA,EACJ;AAAA,EAEA,aAAc;AACV,QAAI,OAAO,YAAY,aAAa;AAChC,aAAO,KAAK,YAAY;AAAA,IAC5B,WAAW,QAAQ,WAAW,KAAK,MAAM,QAAQ;AAC7C,gBAAU;AACV,aAAO,KAAK,YAAY;AAAA,IAC5B,OAAO;AACH,aAAO,QAAQ,QAAQ,OAAO;AAAA,IAClC;AAAA,EACJ;AAAA,EAEA,cAAe;AACX,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACpC,UAAI,SAAS,SAAS,cAAc,QAAQ;AAC5C,aAAO,SAAS,MAAM;AAClB,gBAAQ,SAAS,KAAK,MAAM;AAC5B,gBAAQ,OAAO;AAAA,MACnB;AACA,aAAO,UAAU,MAAM,OAAO,kBAAkB,OAAO,GAAG,EAAE;AAC5D,aAAO,MAAM,KAAK,MAAM,WAAW,QAAQ,YAAY,KAAK,MAAM,MAAM;AACxE,eAAS,KAAK,YAAY,MAAM;AAAA,IACpC,CAAC;AAAA,EACL;AAAA,EAEA,SAA2B;AACvB,WACI,oCAAC,SAAI,KAAK,KAAK,WAAyD,OAAO,EAAC,UAAU,QAAQ,SAAS,OAAM,GAAG;AAAA,EAE5H;AACJ;AApF8B,WAKnB,eAAe;AAAA,EAClB,YAAY;AAChB;","names":["seatsio"]}
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,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;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AAW,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"]}
@@ -57,24 +57,29 @@ var didPropsChange = (prevProps, nextProps) => {
57
57
  };
58
58
 
59
59
  // src/main/Embeddable.tsx
60
- var Embeddable = class extends React.Component {
60
+ var _Embeddable = class _Embeddable extends React.Component {
61
61
  constructor(props) {
62
62
  super(props);
63
63
  this.container = React.createRef();
64
+ this.firstRender = true;
64
65
  }
65
- async componentDidMount() {
66
- if (!this.rendering) {
67
- this.rendering = this.createAndRenderChart();
66
+ componentDidMount() {
67
+ if (!_Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {
68
+ this.createAndRenderChart();
69
+ this.firstRender = false;
68
70
  }
69
71
  }
70
- async componentDidUpdate(prevProps) {
72
+ componentDidUpdate(prevProps) {
71
73
  if (didPropsChange(this.props, prevProps) && this.chart) {
72
74
  this.destroyChart();
73
75
  this.createAndRenderChart();
74
76
  }
75
77
  }
78
+ getChartUrl() {
79
+ return this.props.chartJsUrl.replace("{region}", this.props.region);
80
+ }
76
81
  async createAndRenderChart() {
77
- const seatsio2 = await this.getSeatsio();
82
+ const seatsio2 = await this.loadSeatsio();
78
83
  const config = this.extractConfigFromProps();
79
84
  config.container = this.container.current;
80
85
  this.chart = this.createChart(seatsio2, config).render();
@@ -94,35 +99,30 @@ var Embeddable = class extends React.Component {
94
99
  this.chart.destroy();
95
100
  }
96
101
  }
97
- getSeatsio() {
98
- if (typeof seatsio === "undefined") {
99
- return this.loadSeatsio();
100
- } else if (seatsio.region !== this.props.region) {
101
- seatsio = void 0;
102
- return this.loadSeatsio();
103
- } else {
104
- return Promise.resolve(seatsio);
105
- }
106
- }
107
102
  loadSeatsio() {
108
- return new Promise((resolve, reject) => {
109
- let script = document.createElement("script");
110
- script.onload = () => {
111
- seatsio.region = this.props.region;
112
- resolve(seatsio);
113
- };
114
- script.onerror = () => reject(`Could not load ${script.src}`);
115
- script.src = this.props.chartJsUrl.replace("{region}", this.props.region);
116
- document.head.appendChild(script);
117
- });
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];
118
116
  }
119
117
  render() {
120
118
  return /* @__PURE__ */ React.createElement("div", { ref: this.container, style: { "height": "100%", "width": "100%" } });
121
119
  }
122
120
  };
123
- Embeddable.defaultProps = {
121
+ _Embeddable.seatsioBundles = {};
122
+ _Embeddable.defaultProps = {
124
123
  chartJsUrl: "https://cdn-{region}.seatsio.net/chart.js"
125
124
  };
125
+ var Embeddable = _Embeddable;
126
126
 
127
127
  // src/main/SeatsioDesigner.tsx
128
128
  var SeatsioDesigner = class extends Embeddable {
@@ -1 +1 @@
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) => 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}","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,Y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sx","../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 GeneralAdmission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AAkB,QAAoC;AAC/D,WAAO,IAAIA,SAAQ,qBAAqB,MAAM;AAAA,EAClD;AACJ;","names":["seatsio","seatsio"]}
@@ -22,24 +22,29 @@ var didPropsChange = (prevProps, nextProps) => {
22
22
  };
23
23
 
24
24
  // src/main/Embeddable.tsx
25
- var Embeddable = class extends React.Component {
25
+ var _Embeddable = class _Embeddable extends React.Component {
26
26
  constructor(props) {
27
27
  super(props);
28
28
  this.container = React.createRef();
29
+ this.firstRender = true;
29
30
  }
30
- async componentDidMount() {
31
- if (!this.rendering) {
32
- this.rendering = this.createAndRenderChart();
31
+ componentDidMount() {
32
+ if (!_Embeddable.seatsioBundles[this.getChartUrl()] || this.firstRender) {
33
+ this.createAndRenderChart();
34
+ this.firstRender = false;
33
35
  }
34
36
  }
35
- async componentDidUpdate(prevProps) {
37
+ componentDidUpdate(prevProps) {
36
38
  if (didPropsChange(this.props, prevProps) && this.chart) {
37
39
  this.destroyChart();
38
40
  this.createAndRenderChart();
39
41
  }
40
42
  }
43
+ getChartUrl() {
44
+ return this.props.chartJsUrl.replace("{region}", this.props.region);
45
+ }
41
46
  async createAndRenderChart() {
42
- const seatsio2 = await this.getSeatsio();
47
+ const seatsio2 = await this.loadSeatsio();
43
48
  const config = this.extractConfigFromProps();
44
49
  config.container = this.container.current;
45
50
  this.chart = this.createChart(seatsio2, config).render();
@@ -59,35 +64,30 @@ var Embeddable = class extends React.Component {
59
64
  this.chart.destroy();
60
65
  }
61
66
  }
62
- getSeatsio() {
63
- if (typeof seatsio === "undefined") {
64
- return this.loadSeatsio();
65
- } else if (seatsio.region !== this.props.region) {
66
- seatsio = void 0;
67
- return this.loadSeatsio();
68
- } else {
69
- return Promise.resolve(seatsio);
70
- }
71
- }
72
67
  loadSeatsio() {
73
- return new Promise((resolve, reject) => {
74
- let script = document.createElement("script");
75
- script.onload = () => {
76
- seatsio.region = this.props.region;
77
- resolve(seatsio);
78
- };
79
- script.onerror = () => reject(`Could not load ${script.src}`);
80
- script.src = this.props.chartJsUrl.replace("{region}", this.props.region);
81
- document.head.appendChild(script);
82
- });
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];
83
81
  }
84
82
  render() {
85
83
  return /* @__PURE__ */ React.createElement("div", { ref: this.container, style: { "height": "100%", "width": "100%" } });
86
84
  }
87
85
  };
88
- Embeddable.defaultProps = {
86
+ _Embeddable.seatsioBundles = {};
87
+ _Embeddable.defaultProps = {
89
88
  chartJsUrl: "https://cdn-{region}.seatsio.net/chart.js"
90
89
  };
90
+ var Embeddable = _Embeddable;
91
91
 
92
92
  // src/main/SeatsioDesigner.tsx
93
93
  var SeatsioDesigner = class extends Embeddable {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/main/Embeddable.tsx","../src/main/util.ts","../src/main/SeatsioDesigner.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}","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'","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":";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,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,aAA9B,cAAsF,gBAA8B;AAA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AAQ;AAC5C,aAAO,SAAS,MAAM;AAClB,gBAAQ,SAAS,KAAK,MAAM;AAC5B,gBAAQ,OAAO;AAAA,MACnB;AACA,aAAO,UAAU,MAAM,OAAO,kBAAkB,OAAO,GAAG,EAAE;AAC5D,aAAO,MAAM,KAAK,MAAM,WAAW,QAAQ,YAAY,KAAK,MAAM,MAAM;AACxE,eAAS,KAAK,YAAY,MAAM;AAAA,IACpC,CAAC;AAAA,EACL;AAAA,EAEA,SAA2B;AACvB,WACI,oCAAC,SAAI,KAAK,KAAK,WAAyD,OAAO,EAAC,UAAU,QAAQ,SAAS,OAAM,GAAG;AAAA,EAE5H;AACJ;AApF8B,WAKnB,eAAe;AAAA,EAClB,YAAY;AAChB;;;AEdJ,IAAqB,kBAArB,cAA6C,WAAuC;AAAA,EAChF,YAAaC,UAAkB,QAAoC;AAC/D,WAAO,IAAIA,SAAQ,qBAAqB,MAAM;AAAA,EAClD;AACJ;","names":["seatsio","seatsio"]}
1
+ {"version":3,"sources":["../src/main/Embeddable.tsx","../src/main/util.ts","../src/main/SeatsioDesigner.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 | 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'","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":";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,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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