@gait-financial/react 0.0.16
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/README.md +103 -0
- package/dist/index.cjs +199 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +123 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +168 -0
- package/dist/index.js.map +1 -0
- package/dist/register.cjs +59 -0
- package/dist/register.cjs.map +1 -0
- package/dist/register.d.cts +20 -0
- package/dist/register.d.ts +20 -0
- package/dist/register.js +33 -0
- package/dist/register.js.map +1 -0
- package/dist/wc/button.js +940 -0
- package/package.json +65 -0
- package/wc/button.js +940 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/GaitButton.tsx
|
|
4
|
+
import React, {
|
|
5
|
+
forwardRef,
|
|
6
|
+
useEffect,
|
|
7
|
+
useImperativeHandle,
|
|
8
|
+
useRef
|
|
9
|
+
} from "react";
|
|
10
|
+
var GaitButton = forwardRef(function GaitButton2({
|
|
11
|
+
label,
|
|
12
|
+
theme,
|
|
13
|
+
"data-id": dataId,
|
|
14
|
+
disabled,
|
|
15
|
+
size,
|
|
16
|
+
style,
|
|
17
|
+
items,
|
|
18
|
+
priceBreakdown,
|
|
19
|
+
totalCost,
|
|
20
|
+
brandColor,
|
|
21
|
+
customer,
|
|
22
|
+
webhook,
|
|
23
|
+
merchantStoreUrl,
|
|
24
|
+
onClick,
|
|
25
|
+
onLoaded,
|
|
26
|
+
onDataProcessed,
|
|
27
|
+
onSplitFeedback,
|
|
28
|
+
onMerchantIdError,
|
|
29
|
+
onConfirm,
|
|
30
|
+
className,
|
|
31
|
+
id,
|
|
32
|
+
...rest
|
|
33
|
+
}, ref) {
|
|
34
|
+
const elementRef = useRef(null);
|
|
35
|
+
useImperativeHandle(ref, () => elementRef.current, []);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const el = elementRef.current;
|
|
38
|
+
if (!el) return;
|
|
39
|
+
if (label !== void 0) el.setAttribute("label", label);
|
|
40
|
+
if (theme !== void 0) el.setAttribute("theme", theme);
|
|
41
|
+
if (dataId !== void 0) el.setAttribute("data-id", dataId);
|
|
42
|
+
if (size !== void 0) el.setAttribute("size", size);
|
|
43
|
+
if (disabled) {
|
|
44
|
+
el.setAttribute("disabled", "");
|
|
45
|
+
} else {
|
|
46
|
+
el.removeAttribute("disabled");
|
|
47
|
+
}
|
|
48
|
+
if (style !== void 0) {
|
|
49
|
+
const styleStr = typeof style === "string" ? style : Object.entries(style).map(
|
|
50
|
+
([k, v]) => `${k.replace(/([A-Z])/g, "-$1").toLowerCase()}: ${v}`
|
|
51
|
+
).join("; ");
|
|
52
|
+
el.setAttribute("style", styleStr);
|
|
53
|
+
}
|
|
54
|
+
if (items !== void 0) {
|
|
55
|
+
el.setAttribute(
|
|
56
|
+
"items",
|
|
57
|
+
typeof items === "string" ? items : JSON.stringify(items)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (priceBreakdown !== void 0) {
|
|
61
|
+
el.setAttribute(
|
|
62
|
+
"price-breakdown",
|
|
63
|
+
typeof priceBreakdown === "string" ? priceBreakdown : JSON.stringify(priceBreakdown)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (totalCost !== void 0) {
|
|
67
|
+
el.setAttribute("total-cost", String(totalCost));
|
|
68
|
+
}
|
|
69
|
+
if (brandColor !== void 0) el.setAttribute("brand-color", brandColor);
|
|
70
|
+
if (customer !== void 0) {
|
|
71
|
+
el.setAttribute(
|
|
72
|
+
"customer",
|
|
73
|
+
typeof customer === "string" ? customer : JSON.stringify(customer)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
if (webhook !== void 0) {
|
|
77
|
+
el.setAttribute(
|
|
78
|
+
"webhook",
|
|
79
|
+
typeof webhook === "string" ? webhook : JSON.stringify(webhook)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (merchantStoreUrl !== void 0) {
|
|
83
|
+
el.setAttribute("merchant-store-url", merchantStoreUrl);
|
|
84
|
+
}
|
|
85
|
+
}, [
|
|
86
|
+
label,
|
|
87
|
+
theme,
|
|
88
|
+
dataId,
|
|
89
|
+
disabled,
|
|
90
|
+
size,
|
|
91
|
+
style,
|
|
92
|
+
items,
|
|
93
|
+
priceBreakdown,
|
|
94
|
+
totalCost,
|
|
95
|
+
brandColor,
|
|
96
|
+
customer,
|
|
97
|
+
webhook,
|
|
98
|
+
merchantStoreUrl
|
|
99
|
+
]);
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const el = elementRef.current;
|
|
102
|
+
if (!el) return;
|
|
103
|
+
const handleClick = (e) => {
|
|
104
|
+
if (onClick && e instanceof CustomEvent && e.detail) {
|
|
105
|
+
onClick(e.detail);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const handleLoaded = (e) => {
|
|
109
|
+
if (onLoaded && e instanceof CustomEvent && e.detail) {
|
|
110
|
+
onLoaded(e.detail);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const handleDataProcessed = (e) => {
|
|
114
|
+
if (onDataProcessed && e instanceof CustomEvent && e.detail) {
|
|
115
|
+
onDataProcessed(e.detail);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const handleSplitFeedback = (e) => {
|
|
119
|
+
if (onSplitFeedback && e instanceof CustomEvent && e.detail) {
|
|
120
|
+
onSplitFeedback(e.detail);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const handleMerchantIdError = (e) => {
|
|
124
|
+
if (onMerchantIdError && e instanceof CustomEvent && e.detail) {
|
|
125
|
+
onMerchantIdError(e.detail);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const handleConfirm = (e) => {
|
|
129
|
+
if (onConfirm && e instanceof CustomEvent && e.detail) {
|
|
130
|
+
onConfirm(e.detail);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
el.addEventListener("gait-click", handleClick);
|
|
134
|
+
el.addEventListener("gait-loaded", handleLoaded);
|
|
135
|
+
el.addEventListener("gait-data-processed", handleDataProcessed);
|
|
136
|
+
el.addEventListener("gait-split-feedback", handleSplitFeedback);
|
|
137
|
+
el.addEventListener("gait-merchant-id-error", handleMerchantIdError);
|
|
138
|
+
el.addEventListener("gait-confirm", handleConfirm);
|
|
139
|
+
return () => {
|
|
140
|
+
el.removeEventListener("gait-click", handleClick);
|
|
141
|
+
el.removeEventListener("gait-loaded", handleLoaded);
|
|
142
|
+
el.removeEventListener("gait-data-processed", handleDataProcessed);
|
|
143
|
+
el.removeEventListener("gait-split-feedback", handleSplitFeedback);
|
|
144
|
+
el.removeEventListener("gait-merchant-id-error", handleMerchantIdError);
|
|
145
|
+
el.removeEventListener("gait-confirm", handleConfirm);
|
|
146
|
+
};
|
|
147
|
+
}, [
|
|
148
|
+
onClick,
|
|
149
|
+
onLoaded,
|
|
150
|
+
onDataProcessed,
|
|
151
|
+
onSplitFeedback,
|
|
152
|
+
onMerchantIdError,
|
|
153
|
+
onConfirm
|
|
154
|
+
]);
|
|
155
|
+
const passthrough = {};
|
|
156
|
+
if (className) passthrough.className = className;
|
|
157
|
+
if (id) passthrough.id = id;
|
|
158
|
+
Object.assign(passthrough, rest);
|
|
159
|
+
return React.createElement("gait-button", {
|
|
160
|
+
ref: elementRef,
|
|
161
|
+
...passthrough
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
GaitButton.displayName = "GaitButton";
|
|
165
|
+
export {
|
|
166
|
+
GaitButton
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/GaitButton.tsx"],"sourcesContent":["'use client';\n\n/**\n * React wrapper for GaitButton Web Component\n * Maps React props to element attributes (WC uses attributes as source of truth).\n * Uses ref + useEffect for binding - no direct JSX attribute spread to avoid React's\n * string coercion of booleans/objects.\n */\n\nimport React, {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n} from 'react';\nimport type {\n GaitButtonItem,\n GaitPriceBreakdownItem,\n GaitCustomer,\n GaitWebhook,\n GaitClickDetail,\n GaitLoadedDetail,\n GaitDataProcessedDetail,\n GaitSplitFeedbackDetail,\n GaitMerchantIdErrorDetail,\n GaitConfirmDetail,\n} from '../types';\n\nexport interface GaitButtonProps\n extends Omit<React.HTMLAttributes<HTMLElement>, 'onClick' | 'style'> {\n /** Button label (default: \"Button\") */\n label?: string;\n /** Theme variant */\n theme?: 'dark' | 'light';\n /** Checkout/data identity (required for payment flow) */\n 'data-id'?: string;\n /** Disable the button */\n disabled?: boolean;\n /** Button size */\n size?: 'small' | 'medium' | 'large';\n /** Inline styles - string (for WC) or React.CSSProperties */\n style?: React.CSSProperties | string;\n /** Cart/order items for split payment modal */\n items?: GaitButtonItem[] | string;\n /** Price breakdown items */\n priceBreakdown?: GaitPriceBreakdownItem[] | string;\n /** Total cost */\n totalCost?: number | string;\n /** Brand/accent color */\n brandColor?: string;\n /** Customer info for split payment */\n customer?: GaitCustomer | string;\n /** Webhook config for split payment callbacks */\n webhook?: GaitWebhook | string;\n /** Merchant store URL (defaults to window.location.origin) */\n merchantStoreUrl?: string;\n\n /** Button clicked */\n onClick?: (detail: GaitClickDetail) => void;\n /** Component loaded/rendered */\n onLoaded?: (detail: GaitLoadedDetail) => void;\n /** Data processed (e.g. checkoutId resolved) */\n onDataProcessed?: (detail: GaitDataProcessedDetail) => void;\n /** Split payment API feedback (success/failure) */\n onSplitFeedback?: (detail: GaitSplitFeedbackDetail) => void;\n /** Merchant ID lookup failed */\n onMerchantIdError?: (detail: GaitMerchantIdErrorDetail) => void;\n /** Pay remaining confirmed */\n onConfirm?: (detail: GaitConfirmDetail) => void;\n}\n\nconst GaitButton = forwardRef<HTMLElement, GaitButtonProps>(function GaitButton(\n {\n label,\n theme,\n 'data-id': dataId,\n disabled,\n size,\n style,\n items,\n priceBreakdown,\n totalCost,\n brandColor,\n customer,\n webhook,\n merchantStoreUrl,\n onClick,\n onLoaded,\n onDataProcessed,\n onSplitFeedback,\n onMerchantIdError,\n onConfirm,\n className,\n id,\n ...rest\n },\n ref\n) {\n const elementRef = useRef<HTMLElement>(null);\n\n useImperativeHandle(ref, () => elementRef.current as HTMLElement, []);\n\n // Sync props to element attributes via ref (WC reads attributes)\n useEffect(() => {\n const el = elementRef.current;\n if (!el) return;\n\n if (label !== undefined) el.setAttribute('label', label);\n if (theme !== undefined) el.setAttribute('theme', theme);\n if (dataId !== undefined) el.setAttribute('data-id', dataId);\n if (size !== undefined) el.setAttribute('size', size);\n\n if (disabled) {\n el.setAttribute('disabled', '');\n } else {\n el.removeAttribute('disabled');\n }\n\n if (style !== undefined) {\n const styleStr =\n typeof style === 'string'\n ? style\n : Object.entries(style)\n .map(\n ([k, v]) =>\n `${k.replace(/([A-Z])/g, '-$1').toLowerCase()}: ${v}`\n )\n .join('; ');\n el.setAttribute('style', styleStr);\n }\n\n if (items !== undefined) {\n el.setAttribute(\n 'items',\n typeof items === 'string' ? items : JSON.stringify(items)\n );\n }\n\n if (priceBreakdown !== undefined) {\n el.setAttribute(\n 'price-breakdown',\n typeof priceBreakdown === 'string'\n ? priceBreakdown\n : JSON.stringify(priceBreakdown)\n );\n }\n\n if (totalCost !== undefined) {\n el.setAttribute('total-cost', String(totalCost));\n }\n\n if (brandColor !== undefined) el.setAttribute('brand-color', brandColor);\n\n if (customer !== undefined) {\n el.setAttribute(\n 'customer',\n typeof customer === 'string' ? customer : JSON.stringify(customer)\n );\n }\n\n if (webhook !== undefined) {\n el.setAttribute(\n 'webhook',\n typeof webhook === 'string' ? webhook : JSON.stringify(webhook)\n );\n }\n\n if (merchantStoreUrl !== undefined) {\n el.setAttribute('merchant-store-url', merchantStoreUrl);\n }\n }, [\n label,\n theme,\n dataId,\n disabled,\n size,\n style,\n items,\n priceBreakdown,\n totalCost,\n brandColor,\n customer,\n webhook,\n merchantStoreUrl,\n ]);\n\n // Event listeners\n useEffect(() => {\n const el = elementRef.current;\n if (!el) return;\n\n const handleClick = (e: Event) => {\n if (onClick && e instanceof CustomEvent && e.detail) {\n onClick(e.detail as GaitClickDetail);\n }\n };\n const handleLoaded = (e: Event) => {\n if (onLoaded && e instanceof CustomEvent && e.detail) {\n onLoaded(e.detail as GaitLoadedDetail);\n }\n };\n const handleDataProcessed = (e: Event) => {\n if (onDataProcessed && e instanceof CustomEvent && e.detail) {\n onDataProcessed(e.detail as GaitDataProcessedDetail);\n }\n };\n const handleSplitFeedback = (e: Event) => {\n if (onSplitFeedback && e instanceof CustomEvent && e.detail) {\n onSplitFeedback(e.detail as GaitSplitFeedbackDetail);\n }\n };\n const handleMerchantIdError = (e: Event) => {\n if (onMerchantIdError && e instanceof CustomEvent && e.detail) {\n onMerchantIdError(e.detail as GaitMerchantIdErrorDetail);\n }\n };\n const handleConfirm = (e: Event) => {\n if (onConfirm && e instanceof CustomEvent && e.detail) {\n onConfirm(e.detail as GaitConfirmDetail);\n }\n };\n\n el.addEventListener('gait-click', handleClick as EventListener);\n el.addEventListener('gait-loaded', handleLoaded as EventListener);\n el.addEventListener('gait-data-processed', handleDataProcessed as EventListener);\n el.addEventListener('gait-split-feedback', handleSplitFeedback as EventListener);\n el.addEventListener('gait-merchant-id-error', handleMerchantIdError as EventListener);\n el.addEventListener('gait-confirm', handleConfirm as EventListener);\n\n return () => {\n el.removeEventListener('gait-click', handleClick as EventListener);\n el.removeEventListener('gait-loaded', handleLoaded as EventListener);\n el.removeEventListener('gait-data-processed', handleDataProcessed as EventListener);\n el.removeEventListener('gait-split-feedback', handleSplitFeedback as EventListener);\n el.removeEventListener('gait-merchant-id-error', handleMerchantIdError as EventListener);\n el.removeEventListener('gait-confirm', handleConfirm as EventListener);\n };\n }, [\n onClick,\n onLoaded,\n onDataProcessed,\n onSplitFeedback,\n onMerchantIdError,\n onConfirm,\n ]);\n\n const passthrough: Record<string, unknown> = {};\n if (className) passthrough.className = className;\n if (id) passthrough.id = id;\n Object.assign(passthrough, rest);\n\n return React.createElement('gait-button', {\n ref: elementRef,\n ...passthrough,\n });\n});\n\nGaitButton.displayName = 'GaitButton';\n\nexport { GaitButton };\n"],"mappings":";;;AASA,OAAO;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAyDP,IAAM,aAAa,WAAyC,SAASA,YACnE;AAAA,EACE;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,aAAa,OAAoB,IAAI;AAE3C,sBAAoB,KAAK,MAAM,WAAW,SAAwB,CAAC,CAAC;AAGpE,YAAU,MAAM;AACd,UAAM,KAAK,WAAW;AACtB,QAAI,CAAC,GAAI;AAET,QAAI,UAAU,OAAW,IAAG,aAAa,SAAS,KAAK;AACvD,QAAI,UAAU,OAAW,IAAG,aAAa,SAAS,KAAK;AACvD,QAAI,WAAW,OAAW,IAAG,aAAa,WAAW,MAAM;AAC3D,QAAI,SAAS,OAAW,IAAG,aAAa,QAAQ,IAAI;AAEpD,QAAI,UAAU;AACZ,SAAG,aAAa,YAAY,EAAE;AAAA,IAChC,OAAO;AACL,SAAG,gBAAgB,UAAU;AAAA,IAC/B;AAEA,QAAI,UAAU,QAAW;AACvB,YAAM,WACJ,OAAO,UAAU,WACb,QACA,OAAO,QAAQ,KAAK,EACjB;AAAA,QACC,CAAC,CAAC,GAAG,CAAC,MACJ,GAAG,EAAE,QAAQ,YAAY,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC;AAAA,MACvD,EACC,KAAK,IAAI;AAClB,SAAG,aAAa,SAAS,QAAQ;AAAA,IACnC;AAEA,QAAI,UAAU,QAAW;A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["GaitButton"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/register.ts
|
|
21
|
+
var register_exports = {};
|
|
22
|
+
__export(register_exports, {
|
|
23
|
+
defineCustomElements: () => defineCustomElements
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(register_exports);
|
|
26
|
+
var import_meta = {};
|
|
27
|
+
async function defineCustomElements(scriptUrl) {
|
|
28
|
+
if (typeof window === "undefined" || typeof customElements === "undefined") {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (customElements.get("gait-button")) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const script = document.createElement("script");
|
|
36
|
+
script.async = true;
|
|
37
|
+
if (scriptUrl) {
|
|
38
|
+
script.src = scriptUrl;
|
|
39
|
+
} else {
|
|
40
|
+
try {
|
|
41
|
+
script.src = new URL("./wc/button.js", import_meta.url).href;
|
|
42
|
+
} catch {
|
|
43
|
+
reject(new Error("[@gait/react] Could not resolve bundled script. Load the web component via script tag or pass scriptUrl."));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
script.onload = () => resolve();
|
|
48
|
+
script.onerror = () => reject(new Error("[@gait/react] Failed to load Gait web component script."));
|
|
49
|
+
document.head.appendChild(script);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (typeof window !== "undefined" && typeof customElements !== "undefined") {
|
|
53
|
+
void defineCustomElements();
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
defineCustomElements
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=register.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/register.ts"],"sourcesContent":["/**\n * Registers Gait Web Components in the browser.\n * Safe to call in SSR environments - no-op when window/customElements unavailable.\n *\n * Usage:\n * import '@gait/react/register'; // Side-effect: registers when in browser\n * // or\n * import { defineCustomElements } from '@gait/react/register';\n * await defineCustomElements(); // Optional: load from custom URL\n */\n\n/**\n * Loads and registers Gait Web Components.\n * In browser: loads the WC script if not already registered.\n * In SSR: no-op.\n *\n * @param scriptUrl - Optional URL to the button.js script. If omitted, uses the bundled script.\n */\nexport async function defineCustomElements(\n scriptUrl?: string\n): Promise<void> {\n if (typeof window === 'undefined' || typeof customElements === 'undefined') {\n return;\n }\n if (customElements.get('gait-button')) {\n return;\n }\n\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.async = true;\n\n if (scriptUrl) {\n script.src = scriptUrl;\n } else {\n // Use bundled script - path relative to this module\n try {\n script.src = new URL('./wc/button.js', import.meta.url).href;\n } catch {\n reject(new Error('[@gait/react] Could not resolve bundled script. Load the web component via script tag or pass scriptUrl.'));\n return;\n }\n }\n\n script.onload = () => resolve();\n script.onerror = () =>\n reject(new Error('[@gait/react] Failed to load Gait web component script.'));\n document.head.appendChild(script);\n });\n}\n\n// Side-effect: auto-register when imported in browser (SSR-safe)\nif (typeof window !== 'undefined' && typeof customElements !== 'undefined') {\n void defineCustomElements();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,eAAsB,qBACpB,WACe;AACf,MAAI,OAAO,WAAW,eAAe,OAAO,mBAAmB,aAAa;AAC1E;AAAA,EACF;AACA,MAAI,eAAe,IAAI,aAAa,GAAG;AACrC;AAAA,EACF;AAEA,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,QAAQ;AAEf,QAAI,WAAW;AACb,aAAO,MAAM;AAAA,IACf,OAAO;AAEL,UAAI;AACF,eAAO,MAAM,IAAI,IAAI,kBAAkB,YAAY,GAAG,EAAE;AAAA,MAC1D,QAAQ;AACN,eAAO,IAAI,MAAM,0GAA0G,CAAC;AAC5H;AAAA,MACF;AAAA,IACF;AAEA,WAAO,SAAS,MAAM,QAAQ;AAC9B,WAAO,UAAU,MACf,OAAO,IAAI,MAAM,yDAAyD,CAAC;AAC7E,aAAS,KAAK,YAAY,MAAM;AAAA,EAClC,CAAC;AACH;AAGA,IAAI,OAAO,WAAW,eAAe,OAAO,mBAAmB,aAAa;AAC1E,OAAK,qBAAqB;AAC5B;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers Gait Web Components in the browser.
|
|
3
|
+
* Safe to call in SSR environments - no-op when window/customElements unavailable.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* import '@gait/react/register'; // Side-effect: registers when in browser
|
|
7
|
+
* // or
|
|
8
|
+
* import { defineCustomElements } from '@gait/react/register';
|
|
9
|
+
* await defineCustomElements(); // Optional: load from custom URL
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Loads and registers Gait Web Components.
|
|
13
|
+
* In browser: loads the WC script if not already registered.
|
|
14
|
+
* In SSR: no-op.
|
|
15
|
+
*
|
|
16
|
+
* @param scriptUrl - Optional URL to the button.js script. If omitted, uses the bundled script.
|
|
17
|
+
*/
|
|
18
|
+
declare function defineCustomElements(scriptUrl?: string): Promise<void>;
|
|
19
|
+
|
|
20
|
+
export { defineCustomElements };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers Gait Web Components in the browser.
|
|
3
|
+
* Safe to call in SSR environments - no-op when window/customElements unavailable.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* import '@gait/react/register'; // Side-effect: registers when in browser
|
|
7
|
+
* // or
|
|
8
|
+
* import { defineCustomElements } from '@gait/react/register';
|
|
9
|
+
* await defineCustomElements(); // Optional: load from custom URL
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Loads and registers Gait Web Components.
|
|
13
|
+
* In browser: loads the WC script if not already registered.
|
|
14
|
+
* In SSR: no-op.
|
|
15
|
+
*
|
|
16
|
+
* @param scriptUrl - Optional URL to the button.js script. If omitted, uses the bundled script.
|
|
17
|
+
*/
|
|
18
|
+
declare function defineCustomElements(scriptUrl?: string): Promise<void>;
|
|
19
|
+
|
|
20
|
+
export { defineCustomElements };
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/register.ts
|
|
2
|
+
async function defineCustomElements(scriptUrl) {
|
|
3
|
+
if (typeof window === "undefined" || typeof customElements === "undefined") {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
if (customElements.get("gait-button")) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const script = document.createElement("script");
|
|
11
|
+
script.async = true;
|
|
12
|
+
if (scriptUrl) {
|
|
13
|
+
script.src = scriptUrl;
|
|
14
|
+
} else {
|
|
15
|
+
try {
|
|
16
|
+
script.src = new URL("./wc/button.js", import.meta.url).href;
|
|
17
|
+
} catch {
|
|
18
|
+
reject(new Error("[@gait/react] Could not resolve bundled script. Load the web component via script tag or pass scriptUrl."));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
script.onload = () => resolve();
|
|
23
|
+
script.onerror = () => reject(new Error("[@gait/react] Failed to load Gait web component script."));
|
|
24
|
+
document.head.appendChild(script);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (typeof window !== "undefined" && typeof customElements !== "undefined") {
|
|
28
|
+
void defineCustomElements();
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
defineCustomElements
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/register.ts"],"sourcesContent":["/**\n * Registers Gait Web Components in the browser.\n * Safe to call in SSR environments - no-op when window/customElements unavailable.\n *\n * Usage:\n * import '@gait/react/register'; // Side-effect: registers when in browser\n * // or\n * import { defineCustomElements } from '@gait/react/register';\n * await defineCustomElements(); // Optional: load from custom URL\n */\n\n/**\n * Loads and registers Gait Web Components.\n * In browser: loads the WC script if not already registered.\n * In SSR: no-op.\n *\n * @param scriptUrl - Optional URL to the button.js script. If omitted, uses the bundled script.\n */\nexport async function defineCustomElements(\n scriptUrl?: string\n): Promise<void> {\n if (typeof window === 'undefined' || typeof customElements === 'undefined') {\n return;\n }\n if (customElements.get('gait-button')) {\n return;\n }\n\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.async = true;\n\n if (scriptUrl) {\n script.src = scriptUrl;\n } else {\n // Use bundled script - path relative to this module\n try {\n script.src = new URL('./wc/button.js', import.meta.url).href;\n } catch {\n reject(new Error('[@gait/react] Could not resolve bundled script. Load the web component via script tag or pass scriptUrl.'));\n return;\n }\n }\n\n script.onload = () => resolve();\n script.onerror = () =>\n reject(new Error('[@gait/react] Failed to load Gait web component script.'));\n document.head.appendChild(script);\n });\n}\n\n// Side-effect: auto-register when imported in browser (SSR-safe)\nif (typeof window !== 'undefined' && typeof customElements !== 'undefined') {\n void defineCustomElements();\n}\n"],"mappings":";AAkBA,eAAsB,qBACpB,WACe;AACf,MAAI,OAAO,WAAW,eAAe,OAAO,mBAAmB,aAAa;AAC1E;AAAA,EACF;AACA,MAAI,eAAe,IAAI,aAAa,GAAG;AACrC;AAAA,EACF;AAEA,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,QAAQ;AAEf,QAAI,WAAW;AACb,aAAO,MAAM;AAAA,IACf,OAAO;AAEL,UAAI;AACF,eAAO,MAAM,IAAI,IAAI,kBAAkB,YAAY,GAAG,EAAE;AAAA,MAC1D,QAAQ;AACN,eAAO,IAAI,MAAM,0GAA0G,CAAC;AAC5H;AAAA,MACF;AAAA,IACF;AAEA,WAAO,SAAS,MAAM,QAAQ;AAC9B,WAAO,UAAU,MACf,OAAO,IAAI,MAAM,yDAAyD,CAAC;AAC7E,aAAS,KAAK,YAAY,MAAM;AAAA,EAClC,CAAC;AACH;AAGA,IAAI,OAAO,WAAW,eAAe,OAAO,mBAAmB,aAAa;AAC1E,OAAK,qBAAqB;AAC5B;","names":[]}
|