@ticketlayer/elements-react 0.2.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.
- package/LICENSE +21 -0
- package/README.md +40 -0
- package/dist/cjs/components.js +29 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/react-component-lib/createComponent.js +104 -0
- package/dist/cjs/react-component-lib/createOverlayComponent.js +102 -0
- package/dist/cjs/react-component-lib/index.js +7 -0
- package/dist/cjs/react-component-lib/interfaces.js +2 -0
- package/dist/cjs/react-component-lib/utils/attachProps.js +115 -0
- package/dist/cjs/react-component-lib/utils/case.js +11 -0
- package/dist/cjs/react-component-lib/utils/dev.js +17 -0
- package/dist/cjs/react-component-lib/utils/index.js +56 -0
- package/dist/esm/components.d.ts +19 -0
- package/dist/esm/components.js +25 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/react-component-lib/createComponent.d.ts +10 -0
- package/dist/esm/react-component-lib/createComponent.js +67 -0
- package/dist/esm/react-component-lib/createOverlayComponent.d.ts +21 -0
- package/dist/esm/react-component-lib/createOverlayComponent.js +95 -0
- package/dist/esm/react-component-lib/index.d.ts +2 -0
- package/dist/esm/react-component-lib/index.js +2 -0
- package/dist/esm/react-component-lib/interfaces.d.ts +29 -0
- package/dist/esm/react-component-lib/interfaces.js +1 -0
- package/dist/esm/react-component-lib/utils/attachProps.d.ts +16 -0
- package/dist/esm/react-component-lib/utils/attachProps.js +107 -0
- package/dist/esm/react-component-lib/utils/case.d.ts +2 -0
- package/dist/esm/react-component-lib/utils/case.js +6 -0
- package/dist/esm/react-component-lib/utils/dev.d.ts +2 -0
- package/dist/esm/react-component-lib/utils/dev.js +12 -0
- package/dist/esm/react-component-lib/utils/index.d.ts +10 -0
- package/dist/esm/react-component-lib/utils/index.js +32 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ticketlayer Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @ticketlayer/elements-react
|
|
2
|
+
|
|
3
|
+
React wrappers for [Ticketlayer Elements](https://github.com/ticketlayer/live-elements).
|
|
4
|
+
Each `Tl*` component renders the matching `<tl-*>` custom element from
|
|
5
|
+
`@ticketlayer/elements`, which is a peer dependency: install both.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ticketlayer/elements @ticketlayer/elements-react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { useEffect } from 'react';
|
|
13
|
+
import { createLiveClient } from '@ticketlayer/live';
|
|
14
|
+
import { defineCustomElements, setSDK, TlEventList, TlCartBadge } from '@ticketlayer/elements-react';
|
|
15
|
+
|
|
16
|
+
function App() {
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
// Register the custom elements after hydration, then hand Elements the
|
|
19
|
+
// Live client so they can read the catalogue and share one cart.
|
|
20
|
+
defineCustomElements();
|
|
21
|
+
createLiveClient({ baseUrl: 'https://live-api.ticketlayer.com', publishableKey: 'tlpk_...' }).then(setSDK);
|
|
22
|
+
}, []);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<TlCartBadge />
|
|
27
|
+
<TlEventList />
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Events are exposed as `onTl*` props (`onTlAddToCart`, `onTlError`, ...) and
|
|
34
|
+
receive the `CustomEvent`; the payload is on `event.detail`. The component
|
|
35
|
+
reference, props and events for every element are in the elements package's
|
|
36
|
+
`elements.catalogue.json` and `docs/COMPONENTS.md`.
|
|
37
|
+
|
|
38
|
+
The wrapper set is generated from the elements build, so
|
|
39
|
+
`@ticketlayer/elements-react` always ships against the same major of
|
|
40
|
+
`@ticketlayer/elements`.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TlTicketSelector = exports.TlTicket = exports.TlSeatMap = exports.TlPromoCode = exports.TlOrderTickets = exports.TlOrderConfirmation = exports.TlOccurrenceSelector = exports.TlMyOrders = exports.TlLogin = exports.TlEventList = exports.TlEventCard = exports.TlCheckoutWrapper = exports.TlCartDrawer = exports.TlCartBadge = exports.TlCart = exports.TlBuyTicketsWrapper = exports.TlBuyTicketsButton = exports.TlBuyModal = exports.defineCustomElements = void 0;
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
/* GENERATED by scripts/build-react.mjs - do not edit. */
|
|
6
|
+
const react_component_lib_1 = require("./react-component-lib");
|
|
7
|
+
// Registers the custom elements. TicketlayerProvider calls this after
|
|
8
|
+
// hydration; do NOT call it at import time (SSR/hydration mismatch).
|
|
9
|
+
var loader_1 = require("@ticketlayer/elements/loader");
|
|
10
|
+
Object.defineProperty(exports, "defineCustomElements", { enumerable: true, get: function () { return loader_1.defineCustomElements; } });
|
|
11
|
+
// Props are `any`: the element types come from @ticketlayer/elements at runtime.
|
|
12
|
+
exports.TlBuyModal = (0, react_component_lib_1.createReactComponent)('tl-buy-modal');
|
|
13
|
+
exports.TlBuyTicketsButton = (0, react_component_lib_1.createReactComponent)('tl-buy-tickets-button');
|
|
14
|
+
exports.TlBuyTicketsWrapper = (0, react_component_lib_1.createReactComponent)('tl-buy-tickets-wrapper');
|
|
15
|
+
exports.TlCart = (0, react_component_lib_1.createReactComponent)('tl-cart');
|
|
16
|
+
exports.TlCartBadge = (0, react_component_lib_1.createReactComponent)('tl-cart-badge');
|
|
17
|
+
exports.TlCartDrawer = (0, react_component_lib_1.createReactComponent)('tl-cart-drawer');
|
|
18
|
+
exports.TlCheckoutWrapper = (0, react_component_lib_1.createReactComponent)('tl-checkout-wrapper');
|
|
19
|
+
exports.TlEventCard = (0, react_component_lib_1.createReactComponent)('tl-event-card');
|
|
20
|
+
exports.TlEventList = (0, react_component_lib_1.createReactComponent)('tl-event-list');
|
|
21
|
+
exports.TlLogin = (0, react_component_lib_1.createReactComponent)('tl-login');
|
|
22
|
+
exports.TlMyOrders = (0, react_component_lib_1.createReactComponent)('tl-my-orders');
|
|
23
|
+
exports.TlOccurrenceSelector = (0, react_component_lib_1.createReactComponent)('tl-occurrence-selector');
|
|
24
|
+
exports.TlOrderConfirmation = (0, react_component_lib_1.createReactComponent)('tl-order-confirmation');
|
|
25
|
+
exports.TlOrderTickets = (0, react_component_lib_1.createReactComponent)('tl-order-tickets');
|
|
26
|
+
exports.TlPromoCode = (0, react_component_lib_1.createReactComponent)('tl-promo-code');
|
|
27
|
+
exports.TlSeatMap = (0, react_component_lib_1.createReactComponent)('tl-seat-map');
|
|
28
|
+
exports.TlTicket = (0, react_component_lib_1.createReactComponent)('tl-ticket');
|
|
29
|
+
exports.TlTicketSelector = (0, react_component_lib_1.createReactComponent)('tl-ticket-selector');
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @ticketlayer/elements-react
|
|
4
|
+
*
|
|
5
|
+
* React wrappers for Ticketlayer Elements. Each Tl* component renders the
|
|
6
|
+
* matching custom element from @ticketlayer/elements (a peer dependency);
|
|
7
|
+
* call defineCustomElements() once, after hydration, to register them.
|
|
8
|
+
*
|
|
9
|
+
* components.ts is written by scripts/build-react.mjs from the Stencil
|
|
10
|
+
* build, so the exported set always matches the elements package.
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
24
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.onSDKEvent = exports.getSDK = exports.hasSDK = exports.setSDK = void 0;
|
|
28
|
+
__exportStar(require("./components"), exports);
|
|
29
|
+
// SDK connector: how a host hands its @ticketlayer/live client to Elements
|
|
30
|
+
var elements_1 = require("@ticketlayer/elements");
|
|
31
|
+
Object.defineProperty(exports, "setSDK", { enumerable: true, get: function () { return elements_1.setSDK; } });
|
|
32
|
+
Object.defineProperty(exports, "hasSDK", { enumerable: true, get: function () { return elements_1.hasSDK; } });
|
|
33
|
+
Object.defineProperty(exports, "getSDK", { enumerable: true, get: function () { return elements_1.getSDK; } });
|
|
34
|
+
Object.defineProperty(exports, "onSDKEvent", { enumerable: true, get: function () { return elements_1.onSDKEvent; } });
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createReactComponent = void 0;
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const utils_1 = require("./utils");
|
|
39
|
+
const createReactComponent = (tagName, ReactComponentContext, manipulatePropsFunction, defineCustomElement) => {
|
|
40
|
+
if (defineCustomElement !== undefined) {
|
|
41
|
+
defineCustomElement();
|
|
42
|
+
}
|
|
43
|
+
const displayName = (0, utils_1.dashToPascalCase)(tagName);
|
|
44
|
+
const ReactComponent = class extends react_1.default.Component {
|
|
45
|
+
constructor(props) {
|
|
46
|
+
super(props);
|
|
47
|
+
this.setComponentElRef = (element) => {
|
|
48
|
+
this.componentEl = element;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
componentDidMount() {
|
|
52
|
+
this.componentDidUpdate(this.props);
|
|
53
|
+
}
|
|
54
|
+
componentDidUpdate(prevProps) {
|
|
55
|
+
(0, utils_1.attachProps)(this.componentEl, this.props, prevProps);
|
|
56
|
+
}
|
|
57
|
+
render() {
|
|
58
|
+
const { children, forwardedRef, style, className, ref, ...cProps } = this.props;
|
|
59
|
+
let propsToPass = Object.keys(cProps).reduce((acc, name) => {
|
|
60
|
+
const value = cProps[name];
|
|
61
|
+
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
|
|
62
|
+
const eventName = name.substring(2).toLowerCase();
|
|
63
|
+
if (typeof document !== 'undefined' && (0, utils_1.isCoveredByReact)(eventName)) {
|
|
64
|
+
acc[name] = value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// we should only render strings, booleans, and numbers as attrs in html.
|
|
69
|
+
// objects, functions, arrays etc get synced via properties on mount.
|
|
70
|
+
const type = typeof value;
|
|
71
|
+
if (type === 'string' || type === 'boolean' || type === 'number') {
|
|
72
|
+
acc[(0, utils_1.camelToDashCase)(name)] = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return acc;
|
|
76
|
+
}, {});
|
|
77
|
+
if (manipulatePropsFunction) {
|
|
78
|
+
propsToPass = manipulatePropsFunction(this.props, propsToPass);
|
|
79
|
+
}
|
|
80
|
+
const newProps = {
|
|
81
|
+
...propsToPass,
|
|
82
|
+
ref: (0, utils_1.mergeRefs)(forwardedRef, this.setComponentElRef),
|
|
83
|
+
style,
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* We use createElement here instead of
|
|
87
|
+
* React.createElement to work around a
|
|
88
|
+
* bug in Vite (https://github.com/vitejs/vite/issues/6104).
|
|
89
|
+
* React.createElement causes all elements to be rendered
|
|
90
|
+
* as <tagname> instead of the actual Web Component.
|
|
91
|
+
*/
|
|
92
|
+
return (0, react_1.createElement)(tagName, newProps, children);
|
|
93
|
+
}
|
|
94
|
+
static get displayName() {
|
|
95
|
+
return displayName;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
// If context was passed to createReactComponent then conditionally add it to the Component Class
|
|
99
|
+
if (ReactComponentContext) {
|
|
100
|
+
ReactComponent.contextType = ReactComponentContext;
|
|
101
|
+
}
|
|
102
|
+
return (0, utils_1.createForwardRef)(ReactComponent, displayName);
|
|
103
|
+
};
|
|
104
|
+
exports.createReactComponent = createReactComponent;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createOverlayComponent = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const react_dom_1 = __importDefault(require("react-dom"));
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const createOverlayComponent = (tagName, controller, customElement) => {
|
|
11
|
+
(0, utils_1.defineCustomElement)(tagName, customElement);
|
|
12
|
+
const displayName = (0, utils_1.dashToPascalCase)(tagName);
|
|
13
|
+
const didDismissEventName = `on${displayName}DidDismiss`;
|
|
14
|
+
const didPresentEventName = `on${displayName}DidPresent`;
|
|
15
|
+
const willDismissEventName = `on${displayName}WillDismiss`;
|
|
16
|
+
const willPresentEventName = `on${displayName}WillPresent`;
|
|
17
|
+
let isDismissing = false;
|
|
18
|
+
class Overlay extends react_1.default.Component {
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props);
|
|
21
|
+
if (typeof document !== 'undefined') {
|
|
22
|
+
this.el = document.createElement('div');
|
|
23
|
+
}
|
|
24
|
+
this.handleDismiss = this.handleDismiss.bind(this);
|
|
25
|
+
}
|
|
26
|
+
static get displayName() {
|
|
27
|
+
return displayName;
|
|
28
|
+
}
|
|
29
|
+
componentDidMount() {
|
|
30
|
+
if (this.props.isOpen) {
|
|
31
|
+
this.present();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
componentWillUnmount() {
|
|
35
|
+
if (this.overlay) {
|
|
36
|
+
this.overlay.dismiss();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
handleDismiss(event) {
|
|
40
|
+
if (this.props.onDidDismiss) {
|
|
41
|
+
this.props.onDidDismiss(event);
|
|
42
|
+
}
|
|
43
|
+
(0, utils_1.setRef)(this.props.forwardedRef, null);
|
|
44
|
+
}
|
|
45
|
+
shouldComponentUpdate(nextProps) {
|
|
46
|
+
// Check if the overlay component is about to dismiss
|
|
47
|
+
if (this.overlay && nextProps.isOpen !== this.props.isOpen && nextProps.isOpen === false) {
|
|
48
|
+
isDismissing = true;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
async componentDidUpdate(prevProps) {
|
|
53
|
+
if (this.overlay) {
|
|
54
|
+
(0, utils_1.attachProps)(this.overlay, this.props, prevProps);
|
|
55
|
+
}
|
|
56
|
+
if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
|
|
57
|
+
this.present(prevProps);
|
|
58
|
+
}
|
|
59
|
+
if (this.overlay && prevProps.isOpen !== this.props.isOpen && this.props.isOpen === false) {
|
|
60
|
+
await this.overlay.dismiss();
|
|
61
|
+
isDismissing = false;
|
|
62
|
+
/**
|
|
63
|
+
* Now that the overlay is dismissed
|
|
64
|
+
* we need to render again so that any
|
|
65
|
+
* inner components will be unmounted
|
|
66
|
+
*/
|
|
67
|
+
this.forceUpdate();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async present(prevProps) {
|
|
71
|
+
const { children, isOpen, onDidDismiss, onDidPresent, onWillDismiss, onWillPresent, ...cProps } = this.props;
|
|
72
|
+
const elementProps = {
|
|
73
|
+
...cProps,
|
|
74
|
+
ref: this.props.forwardedRef,
|
|
75
|
+
[didDismissEventName]: this.handleDismiss,
|
|
76
|
+
[didPresentEventName]: (e) => this.props.onDidPresent && this.props.onDidPresent(e),
|
|
77
|
+
[willDismissEventName]: (e) => this.props.onWillDismiss && this.props.onWillDismiss(e),
|
|
78
|
+
[willPresentEventName]: (e) => this.props.onWillPresent && this.props.onWillPresent(e),
|
|
79
|
+
};
|
|
80
|
+
this.overlay = await controller.create({
|
|
81
|
+
...elementProps,
|
|
82
|
+
component: this.el,
|
|
83
|
+
componentProps: {},
|
|
84
|
+
});
|
|
85
|
+
(0, utils_1.setRef)(this.props.forwardedRef, this.overlay);
|
|
86
|
+
(0, utils_1.attachProps)(this.overlay, elementProps, prevProps);
|
|
87
|
+
await this.overlay.present();
|
|
88
|
+
}
|
|
89
|
+
render() {
|
|
90
|
+
/**
|
|
91
|
+
* Continue to render the component even when
|
|
92
|
+
* overlay is dismissing otherwise component
|
|
93
|
+
* will be hidden before animation is done.
|
|
94
|
+
*/
|
|
95
|
+
return react_dom_1.default.createPortal(this.props.isOpen || isDismissing ? this.props.children : null, this.el);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return react_1.default.forwardRef((props, ref) => {
|
|
99
|
+
return react_1.default.createElement(Overlay, { ...props, forwardedRef: ref });
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
exports.createOverlayComponent = createOverlayComponent;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOverlayComponent = exports.createReactComponent = void 0;
|
|
4
|
+
var createComponent_1 = require("./createComponent");
|
|
5
|
+
Object.defineProperty(exports, "createReactComponent", { enumerable: true, get: function () { return createComponent_1.createReactComponent; } });
|
|
6
|
+
var createOverlayComponent_1 = require("./createOverlayComponent");
|
|
7
|
+
Object.defineProperty(exports, "createOverlayComponent", { enumerable: true, get: function () { return createOverlayComponent_1.createOverlayComponent; } });
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syncEvent = exports.isCoveredByReact = exports.transformReactEventName = exports.getClassName = exports.attachProps = void 0;
|
|
4
|
+
const case_1 = require("./case");
|
|
5
|
+
const attachProps = (node, newProps, oldProps = {}) => {
|
|
6
|
+
// some test frameworks don't render DOM elements, so we test here to make sure we are dealing with DOM first
|
|
7
|
+
if (node instanceof Element) {
|
|
8
|
+
// add any classes in className to the class list
|
|
9
|
+
const className = (0, exports.getClassName)(node.classList, newProps, oldProps);
|
|
10
|
+
if (className !== '') {
|
|
11
|
+
node.className = className;
|
|
12
|
+
}
|
|
13
|
+
Object.keys(newProps).forEach((name) => {
|
|
14
|
+
if (name === 'children' ||
|
|
15
|
+
name === 'style' ||
|
|
16
|
+
name === 'ref' ||
|
|
17
|
+
name === 'class' ||
|
|
18
|
+
name === 'className' ||
|
|
19
|
+
name === 'forwardedRef') {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
|
|
23
|
+
const eventName = name.substring(2);
|
|
24
|
+
const eventNameLc = eventName[0].toLowerCase() + eventName.substring(1);
|
|
25
|
+
if (!(0, exports.isCoveredByReact)(eventNameLc)) {
|
|
26
|
+
(0, exports.syncEvent)(node, eventNameLc, newProps[name]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
node[name] = newProps[name];
|
|
31
|
+
const propType = typeof newProps[name];
|
|
32
|
+
if (propType === 'string') {
|
|
33
|
+
node.setAttribute((0, case_1.camelToDashCase)(name), newProps[name]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.attachProps = attachProps;
|
|
40
|
+
const getClassName = (classList, newProps, oldProps) => {
|
|
41
|
+
const newClassProp = newProps.className || newProps.class;
|
|
42
|
+
const oldClassProp = oldProps.className || oldProps.class;
|
|
43
|
+
// map the classes to Maps for performance
|
|
44
|
+
const currentClasses = arrayToMap(classList);
|
|
45
|
+
const incomingPropClasses = arrayToMap(newClassProp ? newClassProp.split(' ') : []);
|
|
46
|
+
const oldPropClasses = arrayToMap(oldClassProp ? oldClassProp.split(' ') : []);
|
|
47
|
+
const finalClassNames = [];
|
|
48
|
+
// loop through each of the current classes on the component
|
|
49
|
+
// to see if it should be a part of the classNames added
|
|
50
|
+
currentClasses.forEach((currentClass) => {
|
|
51
|
+
if (incomingPropClasses.has(currentClass)) {
|
|
52
|
+
// add it as its already included in classnames coming in from newProps
|
|
53
|
+
finalClassNames.push(currentClass);
|
|
54
|
+
incomingPropClasses.delete(currentClass);
|
|
55
|
+
}
|
|
56
|
+
else if (!oldPropClasses.has(currentClass)) {
|
|
57
|
+
// add it as it has NOT been removed by user
|
|
58
|
+
finalClassNames.push(currentClass);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
incomingPropClasses.forEach((s) => finalClassNames.push(s));
|
|
62
|
+
return finalClassNames.join(' ');
|
|
63
|
+
};
|
|
64
|
+
exports.getClassName = getClassName;
|
|
65
|
+
/**
|
|
66
|
+
* Transforms a React event name to a browser event name.
|
|
67
|
+
*/
|
|
68
|
+
const transformReactEventName = (eventNameSuffix) => {
|
|
69
|
+
switch (eventNameSuffix) {
|
|
70
|
+
case 'doubleclick':
|
|
71
|
+
return 'dblclick';
|
|
72
|
+
}
|
|
73
|
+
return eventNameSuffix;
|
|
74
|
+
};
|
|
75
|
+
exports.transformReactEventName = transformReactEventName;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if an event is supported in the current execution environment.
|
|
78
|
+
* @license Modernizr 3.0.0pre (Custom Build) | MIT
|
|
79
|
+
*/
|
|
80
|
+
const isCoveredByReact = (eventNameSuffix) => {
|
|
81
|
+
if (typeof document === 'undefined') {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const eventName = 'on' + (0, exports.transformReactEventName)(eventNameSuffix);
|
|
86
|
+
let isSupported = eventName in document;
|
|
87
|
+
if (!isSupported) {
|
|
88
|
+
const element = document.createElement('div');
|
|
89
|
+
element.setAttribute(eventName, 'return;');
|
|
90
|
+
isSupported = typeof element[eventName] === 'function';
|
|
91
|
+
}
|
|
92
|
+
return isSupported;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
exports.isCoveredByReact = isCoveredByReact;
|
|
96
|
+
const syncEvent = (node, eventName, newEventHandler) => {
|
|
97
|
+
const eventStore = node.__events || (node.__events = {});
|
|
98
|
+
const oldEventHandler = eventStore[eventName];
|
|
99
|
+
// Remove old listener so they don't double up.
|
|
100
|
+
if (oldEventHandler) {
|
|
101
|
+
node.removeEventListener(eventName, oldEventHandler);
|
|
102
|
+
}
|
|
103
|
+
// Bind new listener.
|
|
104
|
+
node.addEventListener(eventName, (eventStore[eventName] = function handler(e) {
|
|
105
|
+
if (newEventHandler) {
|
|
106
|
+
newEventHandler.call(this, e);
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
};
|
|
110
|
+
exports.syncEvent = syncEvent;
|
|
111
|
+
const arrayToMap = (arr) => {
|
|
112
|
+
const map = new Map();
|
|
113
|
+
arr.forEach((s) => map.set(s, s));
|
|
114
|
+
return map;
|
|
115
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.camelToDashCase = exports.dashToPascalCase = void 0;
|
|
4
|
+
const dashToPascalCase = (str) => str
|
|
5
|
+
.toLowerCase()
|
|
6
|
+
.split('-')
|
|
7
|
+
.map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
|
|
8
|
+
.join('');
|
|
9
|
+
exports.dashToPascalCase = dashToPascalCase;
|
|
10
|
+
const camelToDashCase = (str) => str.replace(/([A-Z])/g, (m) => `-${m[0].toLowerCase()}`);
|
|
11
|
+
exports.camelToDashCase = camelToDashCase;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deprecationWarning = exports.isDevMode = void 0;
|
|
4
|
+
const isDevMode = () => {
|
|
5
|
+
return process && process.env && process.env.NODE_ENV === 'development';
|
|
6
|
+
};
|
|
7
|
+
exports.isDevMode = isDevMode;
|
|
8
|
+
const warnings = {};
|
|
9
|
+
const deprecationWarning = (key, message) => {
|
|
10
|
+
if ((0, exports.isDevMode)()) {
|
|
11
|
+
if (!warnings[key]) {
|
|
12
|
+
console.warn(message);
|
|
13
|
+
warnings[key] = true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.deprecationWarning = deprecationWarning;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.defineCustomElement = exports.createForwardRef = exports.mergeRefs = exports.setRef = void 0;
|
|
21
|
+
const react_1 = __importDefault(require("react"));
|
|
22
|
+
const setRef = (ref, value) => {
|
|
23
|
+
if (typeof ref === 'function') {
|
|
24
|
+
ref(value);
|
|
25
|
+
}
|
|
26
|
+
else if (ref != null) {
|
|
27
|
+
// Cast as a MutableRef so we can assign current
|
|
28
|
+
ref.current = value;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.setRef = setRef;
|
|
32
|
+
const mergeRefs = (...refs) => {
|
|
33
|
+
return (value) => {
|
|
34
|
+
refs.forEach((ref) => {
|
|
35
|
+
(0, exports.setRef)(ref, value);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
exports.mergeRefs = mergeRefs;
|
|
40
|
+
const createForwardRef = (ReactComponent, displayName) => {
|
|
41
|
+
const forwardRef = (props, ref) => {
|
|
42
|
+
return react_1.default.createElement(ReactComponent, { ...props, forwardedRef: ref });
|
|
43
|
+
};
|
|
44
|
+
forwardRef.displayName = displayName;
|
|
45
|
+
// Cast to any to allow flexible props from Stencil components
|
|
46
|
+
return react_1.default.forwardRef(forwardRef);
|
|
47
|
+
};
|
|
48
|
+
exports.createForwardRef = createForwardRef;
|
|
49
|
+
const defineCustomElement = (tagName, customElement) => {
|
|
50
|
+
if (customElement !== undefined && typeof customElements !== 'undefined' && !customElements.get(tagName)) {
|
|
51
|
+
customElements.define(tagName, customElement);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.defineCustomElement = defineCustomElement;
|
|
55
|
+
__exportStar(require("./attachProps"), exports);
|
|
56
|
+
__exportStar(require("./case"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { defineCustomElements } from '@ticketlayer/elements/loader';
|
|
2
|
+
export declare const TlBuyModal: import("react").ForwardRefExoticComponent<any>;
|
|
3
|
+
export declare const TlBuyTicketsButton: import("react").ForwardRefExoticComponent<any>;
|
|
4
|
+
export declare const TlBuyTicketsWrapper: import("react").ForwardRefExoticComponent<any>;
|
|
5
|
+
export declare const TlCart: import("react").ForwardRefExoticComponent<any>;
|
|
6
|
+
export declare const TlCartBadge: import("react").ForwardRefExoticComponent<any>;
|
|
7
|
+
export declare const TlCartDrawer: import("react").ForwardRefExoticComponent<any>;
|
|
8
|
+
export declare const TlCheckoutWrapper: import("react").ForwardRefExoticComponent<any>;
|
|
9
|
+
export declare const TlEventCard: import("react").ForwardRefExoticComponent<any>;
|
|
10
|
+
export declare const TlEventList: import("react").ForwardRefExoticComponent<any>;
|
|
11
|
+
export declare const TlLogin: import("react").ForwardRefExoticComponent<any>;
|
|
12
|
+
export declare const TlMyOrders: import("react").ForwardRefExoticComponent<any>;
|
|
13
|
+
export declare const TlOccurrenceSelector: import("react").ForwardRefExoticComponent<any>;
|
|
14
|
+
export declare const TlOrderConfirmation: import("react").ForwardRefExoticComponent<any>;
|
|
15
|
+
export declare const TlOrderTickets: import("react").ForwardRefExoticComponent<any>;
|
|
16
|
+
export declare const TlPromoCode: import("react").ForwardRefExoticComponent<any>;
|
|
17
|
+
export declare const TlSeatMap: import("react").ForwardRefExoticComponent<any>;
|
|
18
|
+
export declare const TlTicket: import("react").ForwardRefExoticComponent<any>;
|
|
19
|
+
export declare const TlTicketSelector: import("react").ForwardRefExoticComponent<any>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* GENERATED by scripts/build-react.mjs - do not edit. */
|
|
3
|
+
import { createReactComponent } from './react-component-lib';
|
|
4
|
+
// Registers the custom elements. TicketlayerProvider calls this after
|
|
5
|
+
// hydration; do NOT call it at import time (SSR/hydration mismatch).
|
|
6
|
+
export { defineCustomElements } from '@ticketlayer/elements/loader';
|
|
7
|
+
// Props are `any`: the element types come from @ticketlayer/elements at runtime.
|
|
8
|
+
export const TlBuyModal = /*@__PURE__*/ createReactComponent('tl-buy-modal');
|
|
9
|
+
export const TlBuyTicketsButton = /*@__PURE__*/ createReactComponent('tl-buy-tickets-button');
|
|
10
|
+
export const TlBuyTicketsWrapper = /*@__PURE__*/ createReactComponent('tl-buy-tickets-wrapper');
|
|
11
|
+
export const TlCart = /*@__PURE__*/ createReactComponent('tl-cart');
|
|
12
|
+
export const TlCartBadge = /*@__PURE__*/ createReactComponent('tl-cart-badge');
|
|
13
|
+
export const TlCartDrawer = /*@__PURE__*/ createReactComponent('tl-cart-drawer');
|
|
14
|
+
export const TlCheckoutWrapper = /*@__PURE__*/ createReactComponent('tl-checkout-wrapper');
|
|
15
|
+
export const TlEventCard = /*@__PURE__*/ createReactComponent('tl-event-card');
|
|
16
|
+
export const TlEventList = /*@__PURE__*/ createReactComponent('tl-event-list');
|
|
17
|
+
export const TlLogin = /*@__PURE__*/ createReactComponent('tl-login');
|
|
18
|
+
export const TlMyOrders = /*@__PURE__*/ createReactComponent('tl-my-orders');
|
|
19
|
+
export const TlOccurrenceSelector = /*@__PURE__*/ createReactComponent('tl-occurrence-selector');
|
|
20
|
+
export const TlOrderConfirmation = /*@__PURE__*/ createReactComponent('tl-order-confirmation');
|
|
21
|
+
export const TlOrderTickets = /*@__PURE__*/ createReactComponent('tl-order-tickets');
|
|
22
|
+
export const TlPromoCode = /*@__PURE__*/ createReactComponent('tl-promo-code');
|
|
23
|
+
export const TlSeatMap = /*@__PURE__*/ createReactComponent('tl-seat-map');
|
|
24
|
+
export const TlTicket = /*@__PURE__*/ createReactComponent('tl-ticket');
|
|
25
|
+
export const TlTicketSelector = /*@__PURE__*/ createReactComponent('tl-ticket-selector');
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ticketlayer/elements-react
|
|
3
|
+
*
|
|
4
|
+
* React wrappers for Ticketlayer Elements. Each Tl* component renders the
|
|
5
|
+
* matching custom element from @ticketlayer/elements (a peer dependency);
|
|
6
|
+
* call defineCustomElements() once, after hydration, to register them.
|
|
7
|
+
*
|
|
8
|
+
* components.ts is written by scripts/build-react.mjs from the Stencil
|
|
9
|
+
* build, so the exported set always matches the elements package.
|
|
10
|
+
*/
|
|
11
|
+
export * from './components';
|
|
12
|
+
export { setSDK, hasSDK, getSDK, onSDKEvent } from '@ticketlayer/elements';
|
|
13
|
+
export type { TicketlayerSDK, ModalOptions, OrderResult } from '@ticketlayer/elements';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ticketlayer/elements-react
|
|
3
|
+
*
|
|
4
|
+
* React wrappers for Ticketlayer Elements. Each Tl* component renders the
|
|
5
|
+
* matching custom element from @ticketlayer/elements (a peer dependency);
|
|
6
|
+
* call defineCustomElements() once, after hydration, to register them.
|
|
7
|
+
*
|
|
8
|
+
* components.ts is written by scripts/build-react.mjs from the Stencil
|
|
9
|
+
* build, so the exported set always matches the elements package.
|
|
10
|
+
*/
|
|
11
|
+
export * from './components';
|
|
12
|
+
// SDK connector: how a host hands its @ticketlayer/live client to Elements
|
|
13
|
+
export { setSDK, hasSDK, getSDK, onSDKEvent } from '@ticketlayer/elements';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface HTMLStencilElement extends HTMLElement {
|
|
3
|
+
componentOnReady(): Promise<this>;
|
|
4
|
+
}
|
|
5
|
+
interface StencilReactInternalProps<ElementType> extends React.HTMLAttributes<ElementType> {
|
|
6
|
+
forwardedRef: React.RefObject<ElementType>;
|
|
7
|
+
ref?: React.Ref<any>;
|
|
8
|
+
}
|
|
9
|
+
export declare const createReactComponent: <PropType, ElementType extends HTMLStencilElement, ContextStateType = {}, ExpandedPropsTypes = {}>(tagName: string, ReactComponentContext?: React.Context<ContextStateType>, manipulatePropsFunction?: (originalProps: StencilReactInternalProps<ElementType>, propsToPass: any) => ExpandedPropsTypes, defineCustomElement?: () => void) => React.ForwardRefExoticComponent<PropType & React.RefAttributes<ElementType>>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React, { createElement } from 'react';
|
|
2
|
+
import { attachProps, camelToDashCase, createForwardRef, dashToPascalCase, isCoveredByReact, mergeRefs } from './utils';
|
|
3
|
+
export const createReactComponent = (tagName, ReactComponentContext, manipulatePropsFunction, defineCustomElement) => {
|
|
4
|
+
if (defineCustomElement !== undefined) {
|
|
5
|
+
defineCustomElement();
|
|
6
|
+
}
|
|
7
|
+
const displayName = dashToPascalCase(tagName);
|
|
8
|
+
const ReactComponent = class extends React.Component {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.setComponentElRef = (element) => {
|
|
12
|
+
this.componentEl = element;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
componentDidMount() {
|
|
16
|
+
this.componentDidUpdate(this.props);
|
|
17
|
+
}
|
|
18
|
+
componentDidUpdate(prevProps) {
|
|
19
|
+
attachProps(this.componentEl, this.props, prevProps);
|
|
20
|
+
}
|
|
21
|
+
render() {
|
|
22
|
+
const { children, forwardedRef, style, className, ref, ...cProps } = this.props;
|
|
23
|
+
let propsToPass = Object.keys(cProps).reduce((acc, name) => {
|
|
24
|
+
const value = cProps[name];
|
|
25
|
+
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
|
|
26
|
+
const eventName = name.substring(2).toLowerCase();
|
|
27
|
+
if (typeof document !== 'undefined' && isCoveredByReact(eventName)) {
|
|
28
|
+
acc[name] = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// we should only render strings, booleans, and numbers as attrs in html.
|
|
33
|
+
// objects, functions, arrays etc get synced via properties on mount.
|
|
34
|
+
const type = typeof value;
|
|
35
|
+
if (type === 'string' || type === 'boolean' || type === 'number') {
|
|
36
|
+
acc[camelToDashCase(name)] = value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return acc;
|
|
40
|
+
}, {});
|
|
41
|
+
if (manipulatePropsFunction) {
|
|
42
|
+
propsToPass = manipulatePropsFunction(this.props, propsToPass);
|
|
43
|
+
}
|
|
44
|
+
const newProps = {
|
|
45
|
+
...propsToPass,
|
|
46
|
+
ref: mergeRefs(forwardedRef, this.setComponentElRef),
|
|
47
|
+
style,
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* We use createElement here instead of
|
|
51
|
+
* React.createElement to work around a
|
|
52
|
+
* bug in Vite (https://github.com/vitejs/vite/issues/6104).
|
|
53
|
+
* React.createElement causes all elements to be rendered
|
|
54
|
+
* as <tagname> instead of the actual Web Component.
|
|
55
|
+
*/
|
|
56
|
+
return createElement(tagName, newProps, children);
|
|
57
|
+
}
|
|
58
|
+
static get displayName() {
|
|
59
|
+
return displayName;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
// If context was passed to createReactComponent then conditionally add it to the Component Class
|
|
63
|
+
if (ReactComponentContext) {
|
|
64
|
+
ReactComponent.contextType = ReactComponentContext;
|
|
65
|
+
}
|
|
66
|
+
return createForwardRef(ReactComponent, displayName);
|
|
67
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { OverlayEventDetail } from './interfaces';
|
|
3
|
+
import { StencilReactForwardedRef } from './utils';
|
|
4
|
+
interface OverlayElement extends HTMLElement {
|
|
5
|
+
present: () => Promise<void>;
|
|
6
|
+
dismiss: (data?: any, role?: string | undefined) => Promise<boolean>;
|
|
7
|
+
}
|
|
8
|
+
export interface ReactOverlayProps {
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
onDidDismiss?: (event: CustomEvent<OverlayEventDetail>) => void;
|
|
12
|
+
onDidPresent?: (event: CustomEvent<OverlayEventDetail>) => void;
|
|
13
|
+
onWillDismiss?: (event: CustomEvent<OverlayEventDetail>) => void;
|
|
14
|
+
onWillPresent?: (event: CustomEvent<OverlayEventDetail>) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare const createOverlayComponent: <OverlayComponent extends object, OverlayType extends OverlayElement>(tagName: string, controller: {
|
|
17
|
+
create: (options: any) => Promise<OverlayType>;
|
|
18
|
+
}, customElement?: any) => React.ForwardRefExoticComponent<React.PropsWithoutRef<OverlayComponent & ReactOverlayProps & {
|
|
19
|
+
forwardedRef?: StencilReactForwardedRef<OverlayType>;
|
|
20
|
+
}> & React.RefAttributes<OverlayType>>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { attachProps, dashToPascalCase, defineCustomElement, setRef } from './utils';
|
|
4
|
+
export const createOverlayComponent = (tagName, controller, customElement) => {
|
|
5
|
+
defineCustomElement(tagName, customElement);
|
|
6
|
+
const displayName = dashToPascalCase(tagName);
|
|
7
|
+
const didDismissEventName = `on${displayName}DidDismiss`;
|
|
8
|
+
const didPresentEventName = `on${displayName}DidPresent`;
|
|
9
|
+
const willDismissEventName = `on${displayName}WillDismiss`;
|
|
10
|
+
const willPresentEventName = `on${displayName}WillPresent`;
|
|
11
|
+
let isDismissing = false;
|
|
12
|
+
class Overlay extends React.Component {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(props);
|
|
15
|
+
if (typeof document !== 'undefined') {
|
|
16
|
+
this.el = document.createElement('div');
|
|
17
|
+
}
|
|
18
|
+
this.handleDismiss = this.handleDismiss.bind(this);
|
|
19
|
+
}
|
|
20
|
+
static get displayName() {
|
|
21
|
+
return displayName;
|
|
22
|
+
}
|
|
23
|
+
componentDidMount() {
|
|
24
|
+
if (this.props.isOpen) {
|
|
25
|
+
this.present();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
componentWillUnmount() {
|
|
29
|
+
if (this.overlay) {
|
|
30
|
+
this.overlay.dismiss();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
handleDismiss(event) {
|
|
34
|
+
if (this.props.onDidDismiss) {
|
|
35
|
+
this.props.onDidDismiss(event);
|
|
36
|
+
}
|
|
37
|
+
setRef(this.props.forwardedRef, null);
|
|
38
|
+
}
|
|
39
|
+
shouldComponentUpdate(nextProps) {
|
|
40
|
+
// Check if the overlay component is about to dismiss
|
|
41
|
+
if (this.overlay && nextProps.isOpen !== this.props.isOpen && nextProps.isOpen === false) {
|
|
42
|
+
isDismissing = true;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
async componentDidUpdate(prevProps) {
|
|
47
|
+
if (this.overlay) {
|
|
48
|
+
attachProps(this.overlay, this.props, prevProps);
|
|
49
|
+
}
|
|
50
|
+
if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
|
|
51
|
+
this.present(prevProps);
|
|
52
|
+
}
|
|
53
|
+
if (this.overlay && prevProps.isOpen !== this.props.isOpen && this.props.isOpen === false) {
|
|
54
|
+
await this.overlay.dismiss();
|
|
55
|
+
isDismissing = false;
|
|
56
|
+
/**
|
|
57
|
+
* Now that the overlay is dismissed
|
|
58
|
+
* we need to render again so that any
|
|
59
|
+
* inner components will be unmounted
|
|
60
|
+
*/
|
|
61
|
+
this.forceUpdate();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async present(prevProps) {
|
|
65
|
+
const { children, isOpen, onDidDismiss, onDidPresent, onWillDismiss, onWillPresent, ...cProps } = this.props;
|
|
66
|
+
const elementProps = {
|
|
67
|
+
...cProps,
|
|
68
|
+
ref: this.props.forwardedRef,
|
|
69
|
+
[didDismissEventName]: this.handleDismiss,
|
|
70
|
+
[didPresentEventName]: (e) => this.props.onDidPresent && this.props.onDidPresent(e),
|
|
71
|
+
[willDismissEventName]: (e) => this.props.onWillDismiss && this.props.onWillDismiss(e),
|
|
72
|
+
[willPresentEventName]: (e) => this.props.onWillPresent && this.props.onWillPresent(e),
|
|
73
|
+
};
|
|
74
|
+
this.overlay = await controller.create({
|
|
75
|
+
...elementProps,
|
|
76
|
+
component: this.el,
|
|
77
|
+
componentProps: {},
|
|
78
|
+
});
|
|
79
|
+
setRef(this.props.forwardedRef, this.overlay);
|
|
80
|
+
attachProps(this.overlay, elementProps, prevProps);
|
|
81
|
+
await this.overlay.present();
|
|
82
|
+
}
|
|
83
|
+
render() {
|
|
84
|
+
/**
|
|
85
|
+
* Continue to render the component even when
|
|
86
|
+
* overlay is dismissing otherwise component
|
|
87
|
+
* will be hidden before animation is done.
|
|
88
|
+
*/
|
|
89
|
+
return ReactDOM.createPortal(this.props.isOpen || isDismissing ? this.props.children : null, this.el);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return React.forwardRef((props, ref) => {
|
|
93
|
+
return React.createElement(Overlay, { ...props, forwardedRef: ref });
|
|
94
|
+
});
|
|
95
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface EventEmitter<T = any> {
|
|
2
|
+
emit: (data?: T) => CustomEvent<T>;
|
|
3
|
+
}
|
|
4
|
+
export interface StyleReactProps {
|
|
5
|
+
class?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface OverlayEventDetail<T = any> {
|
|
12
|
+
data?: T;
|
|
13
|
+
role?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface OverlayInterface {
|
|
16
|
+
el: HTMLElement;
|
|
17
|
+
animated: boolean;
|
|
18
|
+
keyboardClose: boolean;
|
|
19
|
+
overlayIndex: number;
|
|
20
|
+
presented: boolean;
|
|
21
|
+
enterAnimation?: any;
|
|
22
|
+
leaveAnimation?: any;
|
|
23
|
+
didPresent: EventEmitter<void>;
|
|
24
|
+
willPresent: EventEmitter<void>;
|
|
25
|
+
willDismiss: EventEmitter<OverlayEventDetail>;
|
|
26
|
+
didDismiss: EventEmitter<OverlayEventDetail>;
|
|
27
|
+
present(): Promise<void>;
|
|
28
|
+
dismiss(data?: any, role?: string): Promise<boolean>;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const attachProps: (node: HTMLElement, newProps: any, oldProps?: any) => void;
|
|
2
|
+
export declare const getClassName: (classList: DOMTokenList, newProps: any, oldProps: any) => string;
|
|
3
|
+
/**
|
|
4
|
+
* Transforms a React event name to a browser event name.
|
|
5
|
+
*/
|
|
6
|
+
export declare const transformReactEventName: (eventNameSuffix: string) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if an event is supported in the current execution environment.
|
|
9
|
+
* @license Modernizr 3.0.0pre (Custom Build) | MIT
|
|
10
|
+
*/
|
|
11
|
+
export declare const isCoveredByReact: (eventNameSuffix: string) => boolean;
|
|
12
|
+
export declare const syncEvent: (node: Element & {
|
|
13
|
+
__events?: {
|
|
14
|
+
[key: string]: ((e: Event) => any) | undefined;
|
|
15
|
+
};
|
|
16
|
+
}, eventName: string, newEventHandler?: (e: Event) => any) => void;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { camelToDashCase } from './case';
|
|
2
|
+
export const attachProps = (node, newProps, oldProps = {}) => {
|
|
3
|
+
// some test frameworks don't render DOM elements, so we test here to make sure we are dealing with DOM first
|
|
4
|
+
if (node instanceof Element) {
|
|
5
|
+
// add any classes in className to the class list
|
|
6
|
+
const className = getClassName(node.classList, newProps, oldProps);
|
|
7
|
+
if (className !== '') {
|
|
8
|
+
node.className = className;
|
|
9
|
+
}
|
|
10
|
+
Object.keys(newProps).forEach((name) => {
|
|
11
|
+
if (name === 'children' ||
|
|
12
|
+
name === 'style' ||
|
|
13
|
+
name === 'ref' ||
|
|
14
|
+
name === 'class' ||
|
|
15
|
+
name === 'className' ||
|
|
16
|
+
name === 'forwardedRef') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
|
|
20
|
+
const eventName = name.substring(2);
|
|
21
|
+
const eventNameLc = eventName[0].toLowerCase() + eventName.substring(1);
|
|
22
|
+
if (!isCoveredByReact(eventNameLc)) {
|
|
23
|
+
syncEvent(node, eventNameLc, newProps[name]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
node[name] = newProps[name];
|
|
28
|
+
const propType = typeof newProps[name];
|
|
29
|
+
if (propType === 'string') {
|
|
30
|
+
node.setAttribute(camelToDashCase(name), newProps[name]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export const getClassName = (classList, newProps, oldProps) => {
|
|
37
|
+
const newClassProp = newProps.className || newProps.class;
|
|
38
|
+
const oldClassProp = oldProps.className || oldProps.class;
|
|
39
|
+
// map the classes to Maps for performance
|
|
40
|
+
const currentClasses = arrayToMap(classList);
|
|
41
|
+
const incomingPropClasses = arrayToMap(newClassProp ? newClassProp.split(' ') : []);
|
|
42
|
+
const oldPropClasses = arrayToMap(oldClassProp ? oldClassProp.split(' ') : []);
|
|
43
|
+
const finalClassNames = [];
|
|
44
|
+
// loop through each of the current classes on the component
|
|
45
|
+
// to see if it should be a part of the classNames added
|
|
46
|
+
currentClasses.forEach((currentClass) => {
|
|
47
|
+
if (incomingPropClasses.has(currentClass)) {
|
|
48
|
+
// add it as its already included in classnames coming in from newProps
|
|
49
|
+
finalClassNames.push(currentClass);
|
|
50
|
+
incomingPropClasses.delete(currentClass);
|
|
51
|
+
}
|
|
52
|
+
else if (!oldPropClasses.has(currentClass)) {
|
|
53
|
+
// add it as it has NOT been removed by user
|
|
54
|
+
finalClassNames.push(currentClass);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
incomingPropClasses.forEach((s) => finalClassNames.push(s));
|
|
58
|
+
return finalClassNames.join(' ');
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Transforms a React event name to a browser event name.
|
|
62
|
+
*/
|
|
63
|
+
export const transformReactEventName = (eventNameSuffix) => {
|
|
64
|
+
switch (eventNameSuffix) {
|
|
65
|
+
case 'doubleclick':
|
|
66
|
+
return 'dblclick';
|
|
67
|
+
}
|
|
68
|
+
return eventNameSuffix;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Checks if an event is supported in the current execution environment.
|
|
72
|
+
* @license Modernizr 3.0.0pre (Custom Build) | MIT
|
|
73
|
+
*/
|
|
74
|
+
export const isCoveredByReact = (eventNameSuffix) => {
|
|
75
|
+
if (typeof document === 'undefined') {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const eventName = 'on' + transformReactEventName(eventNameSuffix);
|
|
80
|
+
let isSupported = eventName in document;
|
|
81
|
+
if (!isSupported) {
|
|
82
|
+
const element = document.createElement('div');
|
|
83
|
+
element.setAttribute(eventName, 'return;');
|
|
84
|
+
isSupported = typeof element[eventName] === 'function';
|
|
85
|
+
}
|
|
86
|
+
return isSupported;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export const syncEvent = (node, eventName, newEventHandler) => {
|
|
90
|
+
const eventStore = node.__events || (node.__events = {});
|
|
91
|
+
const oldEventHandler = eventStore[eventName];
|
|
92
|
+
// Remove old listener so they don't double up.
|
|
93
|
+
if (oldEventHandler) {
|
|
94
|
+
node.removeEventListener(eventName, oldEventHandler);
|
|
95
|
+
}
|
|
96
|
+
// Bind new listener.
|
|
97
|
+
node.addEventListener(eventName, (eventStore[eventName] = function handler(e) {
|
|
98
|
+
if (newEventHandler) {
|
|
99
|
+
newEventHandler.call(this, e);
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
};
|
|
103
|
+
const arrayToMap = (arr) => {
|
|
104
|
+
const map = new Map();
|
|
105
|
+
arr.forEach((s) => map.set(s, s));
|
|
106
|
+
return map;
|
|
107
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const isDevMode = () => {
|
|
2
|
+
return process && process.env && process.env.NODE_ENV === 'development';
|
|
3
|
+
};
|
|
4
|
+
const warnings = {};
|
|
5
|
+
export const deprecationWarning = (key, message) => {
|
|
6
|
+
if (isDevMode()) {
|
|
7
|
+
if (!warnings[key]) {
|
|
8
|
+
console.warn(message);
|
|
9
|
+
warnings[key] = true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { StyleReactProps } from '../interfaces';
|
|
3
|
+
export type StencilReactExternalProps<PropType, ElementType> = PropType & Omit<React.HTMLAttributes<ElementType>, 'style'> & StyleReactProps;
|
|
4
|
+
export type StencilReactForwardedRef<T> = ((instance: T | null) => void) | React.MutableRefObject<T | null> | null;
|
|
5
|
+
export declare const setRef: (ref: StencilReactForwardedRef<any> | React.Ref<any> | undefined, value: any) => void;
|
|
6
|
+
export declare const mergeRefs: (...refs: (StencilReactForwardedRef<any> | React.Ref<any> | undefined)[]) => React.RefCallback<any>;
|
|
7
|
+
export declare const createForwardRef: <PropType, ElementType>(ReactComponent: any, displayName: string) => React.ForwardRefExoticComponent<PropType & React.RefAttributes<ElementType>>;
|
|
8
|
+
export declare const defineCustomElement: (tagName: string, customElement: any) => void;
|
|
9
|
+
export * from './attachProps';
|
|
10
|
+
export * from './case';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export const setRef = (ref, value) => {
|
|
3
|
+
if (typeof ref === 'function') {
|
|
4
|
+
ref(value);
|
|
5
|
+
}
|
|
6
|
+
else if (ref != null) {
|
|
7
|
+
// Cast as a MutableRef so we can assign current
|
|
8
|
+
ref.current = value;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export const mergeRefs = (...refs) => {
|
|
12
|
+
return (value) => {
|
|
13
|
+
refs.forEach((ref) => {
|
|
14
|
+
setRef(ref, value);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const createForwardRef = (ReactComponent, displayName) => {
|
|
19
|
+
const forwardRef = (props, ref) => {
|
|
20
|
+
return React.createElement(ReactComponent, { ...props, forwardedRef: ref });
|
|
21
|
+
};
|
|
22
|
+
forwardRef.displayName = displayName;
|
|
23
|
+
// Cast to any to allow flexible props from Stencil components
|
|
24
|
+
return React.forwardRef(forwardRef);
|
|
25
|
+
};
|
|
26
|
+
export const defineCustomElement = (tagName, customElement) => {
|
|
27
|
+
if (customElement !== undefined && typeof customElements !== 'undefined' && !customElements.get(tagName)) {
|
|
28
|
+
customElements.define(tagName, customElement);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export * from './attachProps';
|
|
32
|
+
export * from './case';
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ticketlayer/elements-react",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "React wrappers for Ticketlayer Elements",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/esm/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/esm/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "node ../scripts/build-react.mjs"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/ticketlayer/live-elements.git",
|
|
27
|
+
"directory": "react"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://docs.ticketlayer.com/elements",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/ticketlayer/live-elements/issues"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"ticketlayer",
|
|
35
|
+
"elements",
|
|
36
|
+
"react",
|
|
37
|
+
"web-components",
|
|
38
|
+
"ticketing"
|
|
39
|
+
],
|
|
40
|
+
"author": "Ticketlayer",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18.0.0"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public",
|
|
47
|
+
"registry": "https://registry.npmjs.org/",
|
|
48
|
+
"provenance": true
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@ticketlayer/elements": ">=0.1.0 <1.0.0",
|
|
52
|
+
"@ticketlayer/live": "^0.1.0",
|
|
53
|
+
"react": ">=17.0.0",
|
|
54
|
+
"react-dom": ">=17.0.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"@ticketlayer/live": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|