@globalpayments/vega-react 2.86.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +4 -0
  3. package/dist/components.d.ts +120 -0
  4. package/dist/components.js +127 -0
  5. package/dist/global.d.ts +6 -0
  6. package/dist/global.js +1 -0
  7. package/dist/hooks/use-vega-ref.d.ts +16 -0
  8. package/dist/hooks/use-vega-ref.js +28 -0
  9. package/dist/index.d.ts +4 -0
  10. package/dist/index.js +4 -0
  11. package/dist/overrides/vega-popover/index.d.ts +7 -0
  12. package/dist/overrides/vega-popover/index.js +151 -0
  13. package/dist/overrides/vega-popover/test/vega-popover.test.d.ts +6 -0
  14. package/dist/overrides/vega-popover/test/vega-popover.test.js +108 -0
  15. package/dist/package.json +17 -0
  16. package/dist/react-component-lib/createComponent.d.ts +10 -0
  17. package/dist/react-component-lib/createComponent.js +85 -0
  18. package/dist/react-component-lib/createOverlayComponent.d.ts +21 -0
  19. package/dist/react-component-lib/createOverlayComponent.js +108 -0
  20. package/dist/react-component-lib/index.d.ts +2 -0
  21. package/dist/react-component-lib/index.js +2 -0
  22. package/dist/react-component-lib/interfaces.d.ts +29 -0
  23. package/dist/react-component-lib/interfaces.js +1 -0
  24. package/dist/react-component-lib/utils/attachProps.d.ts +12 -0
  25. package/dist/react-component-lib/utils/attachProps.js +124 -0
  26. package/dist/react-component-lib/utils/case.d.ts +2 -0
  27. package/dist/react-component-lib/utils/case.js +6 -0
  28. package/dist/react-component-lib/utils/dev.d.ts +2 -0
  29. package/dist/react-component-lib/utils/dev.js +12 -0
  30. package/dist/react-component-lib/utils/index.d.ts +10 -0
  31. package/dist/react-component-lib/utils/index.js +33 -0
  32. package/dist/testing/index.d.ts +1 -0
  33. package/dist/testing/index.js +1 -0
  34. package/dist/testing/utils.d.ts +21 -0
  35. package/dist/testing/utils.js +100 -0
  36. package/dist/utils/spec-utils.d.ts +11 -0
  37. package/dist/utils/spec-utils.js +22 -0
  38. package/package.json +69 -0
@@ -0,0 +1,108 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * NOTE: This test file is for vega-popover React wrapper.
12
+ * It validates portal wrapping and slot-based child routing.
13
+ * Tests use the real VegaPopover component with mocked Shadow DOM support.
14
+ */
15
+ import "jest";
16
+ import React from "react";
17
+ import ReactDOM from "react-dom";
18
+ import { VegaPopover } from "../index";
19
+ // @ts-ignore - @testing-library/react is installed and resolved by jest, but TypeScript LSP may not find it
20
+ import { render, waitFor } from "@testing-library/react";
21
+ jest.mock("@globalpayments/vega", () => ({
22
+ FeatureFlag: {
23
+ isEnabled: () => false,
24
+ },
25
+ }), { virtual: true });
26
+ /**
27
+ * Helper to inject a mocked Shadow DOM structure into an element.
28
+ * Used for jsdom compatibility where native Shadow DOM is not supported.
29
+ */
30
+ function injectShadowRootMock(element) {
31
+ if (!element.shadowRoot) {
32
+ const contentBox = document.createElement("vega-popover-content-box");
33
+ Object.defineProperty(element, "shadowRoot", {
34
+ configurable: true,
35
+ value: {
36
+ querySelector: (selector) => {
37
+ return selector === "vega-popover-content-box" ? contentBox : null;
38
+ },
39
+ },
40
+ });
41
+ element.componentOnReady = () => Promise.resolve(element);
42
+ }
43
+ return element;
44
+ }
45
+ describe("VegaPopover (React portal wrapper)", () => {
46
+ beforeEach(() => {
47
+ // Mock createElement to inject shadowRoot on vega-popover elements
48
+ const originalCreateElement = document.createElement;
49
+ jest
50
+ .spyOn(document, "createElement")
51
+ .mockImplementation(function (tagName, ...args) {
52
+ const element = originalCreateElement.call(document, tagName, ...args);
53
+ if (tagName.toLowerCase() === "vega-popover") {
54
+ injectShadowRootMock(element);
55
+ }
56
+ return element;
57
+ });
58
+ });
59
+ afterEach(() => {
60
+ jest.restoreAllMocks();
61
+ document.body.innerHTML = "";
62
+ });
63
+ test("creates host and content-box portals for trigger and popover content", () => __awaiter(void 0, void 0, void 0, function* () {
64
+ var _a;
65
+ const createPortalSpy = jest.spyOn(ReactDOM, "createPortal");
66
+ createPortalSpy.mockImplementation((children) => children);
67
+ render(React.createElement(VegaPopover, { placement: "top", alignment: "start" },
68
+ React.createElement("button", { slot: "popover-content" }, "Click Me"),
69
+ React.createElement("div", { slot: "popover" }, "Popover Content")));
70
+ const host = document.querySelector("vega-popover");
71
+ const contentBox = (_a = host === null || host === void 0 ? void 0 : host.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector("vega-popover-content-box");
72
+ expect(host).toBeTruthy();
73
+ expect(contentBox).toBeTruthy();
74
+ yield waitFor(() => {
75
+ expect(createPortalSpy).toHaveBeenCalled();
76
+ const containers = createPortalSpy.mock.calls.map((call) => call[1]);
77
+ expect(containers).toContain(host);
78
+ expect(containers).toContain(contentBox);
79
+ });
80
+ }));
81
+ test("routes children by slot to the expected portal container", () => __awaiter(void 0, void 0, void 0, function* () {
82
+ var _b;
83
+ const createPortalSpy = jest.spyOn(ReactDOM, "createPortal");
84
+ createPortalSpy.mockImplementation((children) => children);
85
+ render(React.createElement(VegaPopover, { placement: "top", alignment: "start" },
86
+ React.createElement("button", { slot: "popover-content" }, "Trigger Button"),
87
+ React.createElement("div", { slot: "popover" }, "Popover Body")));
88
+ const host = document.querySelector("vega-popover");
89
+ const contentBox = (_b = host === null || host === void 0 ? void 0 : host.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector("vega-popover-content-box");
90
+ yield waitFor(() => {
91
+ expect(createPortalSpy.mock.calls.length).toBeGreaterThanOrEqual(2);
92
+ });
93
+ const hostPortalCall = createPortalSpy.mock.calls.find((call) => call[1] === host);
94
+ const contentPortalCall = createPortalSpy.mock.calls.find((call) => call[1] === contentBox);
95
+ expect(hostPortalCall).toBeTruthy();
96
+ expect(contentPortalCall).toBeTruthy();
97
+ const hostChildren = hostPortalCall
98
+ ? React.Children.toArray(hostPortalCall[0])
99
+ : [];
100
+ const contentChildren = contentPortalCall
101
+ ? React.Children.toArray(contentPortalCall[0])
102
+ : [];
103
+ if (hostChildren[0] && contentChildren[0]) {
104
+ expect(hostChildren[0].props.children).toBe("Trigger Button");
105
+ expect(contentChildren[0].props.children).toBe("Popover Body");
106
+ }
107
+ }));
108
+ });
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@globalpayments/vega-react",
3
+ "version": "2.86.0",
4
+ "description": "React specific wrapper for @globalpayments/vega",
5
+ "license": "UNLICENSED",
6
+ "sideEffects": false,
7
+ "main": "./index.js",
8
+ "module": "./index.js",
9
+ "types": "./index.d.ts",
10
+ "dependencies": {
11
+ "@globalpayments/vega": "2.86.0"
12
+ },
13
+ "peerDependencies": {
14
+ "react": ">=16.7.0",
15
+ "react-dom": ">=16.7.0"
16
+ }
17
+ }
@@ -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<React.PropsWithoutRef<PropType & Omit<React.HTMLAttributes<ElementType>, "style"> & import("./interfaces").StyleReactProps> & React.RefAttributes<ElementType>>;
10
+ export {};
@@ -0,0 +1,85 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React, { createElement } from 'react';
13
+ import { attachProps, camelToDashCase, createForwardRef, dashToPascalCase, isCoveredByReact, mergeRefs, } from './utils';
14
+ import { FeatureFlag } from '@globalpayments/vega';
15
+ export const createReactComponent = (tagName, ReactComponentContext, manipulatePropsFunction, defineCustomElement) => {
16
+ if (defineCustomElement !== undefined) {
17
+ defineCustomElement();
18
+ }
19
+ const displayName = dashToPascalCase(tagName);
20
+ const ReactComponent = class extends React.Component {
21
+ constructor(props) {
22
+ super(props);
23
+ this.setComponentElRef = (element) => {
24
+ this.componentEl = element;
25
+ };
26
+ /**
27
+ * While VEGA components use some keyword like `widnow` which only for browser environment, the SSR will not work as expect.
28
+ * To skip compare for SSR and CSR in Hydation we use same temporary dom. that will avoid Hydation failed and emit error messages.
29
+ * The `canRender` state is work for this, while it false we return the temporary dom for both SSR and CSR to skip Hydation check,
30
+ * while component did mount, we set it as true and then we can realy render the component.
31
+ */
32
+ this.state = { canRender: false };
33
+ }
34
+ componentDidMount() {
35
+ this.componentDidUpdate(this.props);
36
+ if (FeatureFlag.isEnabled('VEGA_REACT.PREVENT_SSR')) {
37
+ this.setState({ canRender: true });
38
+ }
39
+ }
40
+ componentDidUpdate(prevProps) {
41
+ attachProps(this.componentEl, this.props, prevProps);
42
+ }
43
+ render() {
44
+ const _a = this.props, { children, forwardedRef, style, className, ref } = _a, cProps = __rest(_a, ["children", "forwardedRef", "style", "className", "ref"]);
45
+ let propsToPass = Object.keys(cProps).reduce((acc, name) => {
46
+ const value = cProps[name];
47
+ if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
48
+ const eventName = name.substring(2).toLowerCase();
49
+ if (typeof document !== 'undefined' && isCoveredByReact(eventName)) {
50
+ acc[name] = value;
51
+ }
52
+ }
53
+ else {
54
+ // we should only render strings, booleans, and numbers as attrs in html.
55
+ // objects, functions, arrays etc get synced via properties on mount.
56
+ const type = typeof value;
57
+ if (type === 'string' || type === 'boolean' || type === 'number') {
58
+ acc[camelToDashCase(name)] = value;
59
+ }
60
+ }
61
+ return acc;
62
+ }, {});
63
+ if (manipulatePropsFunction) {
64
+ propsToPass = manipulatePropsFunction(this.props, propsToPass);
65
+ }
66
+ const newProps = Object.assign(Object.assign({}, propsToPass), { ref: mergeRefs(forwardedRef, this.setComponentElRef), style });
67
+ /**
68
+ * We use createElement here instead of
69
+ * React.createElement to work around a
70
+ * bug in Vite (https://github.com/vitejs/vite/issues/6104).
71
+ * React.createElement causes all elements to be rendered
72
+ * as <tagname> instead of the actual Web Component.
73
+ */
74
+ return (!FeatureFlag.isEnabled('VEGA_REACT.PREVENT_SSR') || this.state.canRender) ? createElement(tagName, newProps, children) : React.createElement(React.Fragment, null);
75
+ }
76
+ static get displayName() {
77
+ return displayName;
78
+ }
79
+ };
80
+ // If context was passed to createReactComponent then conditionally add it to the Component Class
81
+ if (ReactComponentContext) {
82
+ ReactComponent.contextType = ReactComponentContext;
83
+ }
84
+ return createForwardRef(ReactComponent, displayName);
85
+ };
@@ -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,108 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import React from 'react';
22
+ import ReactDOM from 'react-dom';
23
+ import { attachProps, dashToPascalCase, defineCustomElement, setRef, } from './utils';
24
+ export const createOverlayComponent = (tagName, controller, customElement) => {
25
+ defineCustomElement(tagName, customElement);
26
+ const displayName = dashToPascalCase(tagName);
27
+ const didDismissEventName = `on${displayName}DidDismiss`;
28
+ const didPresentEventName = `on${displayName}DidPresent`;
29
+ const willDismissEventName = `on${displayName}WillDismiss`;
30
+ const willPresentEventName = `on${displayName}WillPresent`;
31
+ let isDismissing = false;
32
+ class Overlay extends React.Component {
33
+ constructor(props) {
34
+ super(props);
35
+ if (typeof document !== 'undefined') {
36
+ this.el = document.createElement('div');
37
+ }
38
+ this.handleDismiss = this.handleDismiss.bind(this);
39
+ }
40
+ static get displayName() {
41
+ return displayName;
42
+ }
43
+ componentDidMount() {
44
+ if (this.props.isOpen) {
45
+ this.present();
46
+ }
47
+ }
48
+ componentWillUnmount() {
49
+ if (this.overlay) {
50
+ this.overlay.dismiss();
51
+ }
52
+ }
53
+ handleDismiss(event) {
54
+ if (this.props.onDidDismiss) {
55
+ this.props.onDidDismiss(event);
56
+ }
57
+ setRef(this.props.forwardedRef, null);
58
+ }
59
+ shouldComponentUpdate(nextProps) {
60
+ // Check if the overlay component is about to dismiss
61
+ if (this.overlay && nextProps.isOpen !== this.props.isOpen && nextProps.isOpen === false) {
62
+ isDismissing = true;
63
+ }
64
+ return true;
65
+ }
66
+ componentDidUpdate(prevProps) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ if (this.overlay) {
69
+ attachProps(this.overlay, this.props, prevProps);
70
+ }
71
+ if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
72
+ this.present(prevProps);
73
+ }
74
+ if (this.overlay && prevProps.isOpen !== this.props.isOpen && this.props.isOpen === false) {
75
+ yield this.overlay.dismiss();
76
+ isDismissing = false;
77
+ /**
78
+ * Now that the overlay is dismissed
79
+ * we need to render again so that any
80
+ * inner components will be unmounted
81
+ */
82
+ this.forceUpdate();
83
+ }
84
+ });
85
+ }
86
+ present(prevProps) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ const _a = this.props, { children, isOpen, onDidDismiss, onDidPresent, onWillDismiss, onWillPresent } = _a, cProps = __rest(_a, ["children", "isOpen", "onDidDismiss", "onDidPresent", "onWillDismiss", "onWillPresent"]);
89
+ const elementProps = Object.assign(Object.assign({}, cProps), { ref: this.props.forwardedRef, [didDismissEventName]: this.handleDismiss, [didPresentEventName]: (e) => this.props.onDidPresent && this.props.onDidPresent(e), [willDismissEventName]: (e) => this.props.onWillDismiss && this.props.onWillDismiss(e), [willPresentEventName]: (e) => this.props.onWillPresent && this.props.onWillPresent(e) });
90
+ this.overlay = yield controller.create(Object.assign(Object.assign({}, elementProps), { component: this.el, componentProps: {} }));
91
+ setRef(this.props.forwardedRef, this.overlay);
92
+ attachProps(this.overlay, elementProps, prevProps);
93
+ yield this.overlay.present();
94
+ });
95
+ }
96
+ render() {
97
+ /**
98
+ * Continue to render the component even when
99
+ * overlay is dismissing otherwise component
100
+ * will be hidden before animation is done.
101
+ */
102
+ return ReactDOM.createPortal(this.props.isOpen || isDismissing ? this.props.children : null, this.el);
103
+ }
104
+ }
105
+ return React.forwardRef((props, ref) => {
106
+ return React.createElement(Overlay, Object.assign({}, props, { forwardedRef: ref }));
107
+ });
108
+ };
@@ -0,0 +1,2 @@
1
+ export { createReactComponent } from './createComponent';
2
+ export { createOverlayComponent } from './createOverlayComponent';
@@ -0,0 +1,2 @@
1
+ export { createReactComponent } from './createComponent';
2
+ export { createOverlayComponent } from './createOverlayComponent';
@@ -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,12 @@
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
+ * Checks if an event is supported in the current execution environment.
5
+ * @license Modernizr 3.0.0pre (Custom Build) | MIT
6
+ */
7
+ export declare const isCoveredByReact: (eventNameSuffix: string) => boolean;
8
+ export declare const syncEvent: (node: Element & {
9
+ __events?: {
10
+ [key: string]: (e: Event) => any;
11
+ };
12
+ }, eventName: string, newEventHandler?: (e: Event) => any) => void;
@@ -0,0 +1,124 @@
1
+ import { camelToDashCase } from './case';
2
+ import { FeatureFlag } from '@globalpayments/vega';
3
+ export const attachProps = (node, newProps, oldProps = {}) => {
4
+ // some test frameworks don't render DOM elements, so we test here to make sure we are dealing with DOM first
5
+ if (node instanceof Element) {
6
+ // add any classes in className to the class list
7
+ const className = getClassName(node.classList, newProps, oldProps);
8
+ if (className !== '') {
9
+ node.className = className;
10
+ }
11
+ Object.keys(newProps).forEach((name) => {
12
+ if (name === 'children' ||
13
+ name === 'style' ||
14
+ name === 'ref' ||
15
+ name === 'class' ||
16
+ name === 'className' ||
17
+ name === 'forwardedRef') {
18
+ return;
19
+ }
20
+ if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
21
+ const eventName = name.substring(2);
22
+ const eventNameLc = eventName[0].toLowerCase() + eventName.substring(1);
23
+ if (!isCoveredByReact(eventNameLc) || shouldAddSyncEventFallback(eventName)) {
24
+ syncEvent(node, eventNameLc, newProps[name]);
25
+ }
26
+ }
27
+ else if (FeatureFlag.isEnabled('VEGA_REACT.PREVENT_CALL_WATCH_METHOD_BEFORE_COMPONENT_LOAD')) {
28
+ attachProp(node, newProps, name);
29
+ }
30
+ else {
31
+ // For Next, the node have componentOnReady method in prototype of node, but no exist in React.
32
+ // so we attach props while componentOnReady in Next, and directly attach in React.
33
+ const hasOnReadyMethod = Boolean(node.componentOnReady);
34
+ hasOnReadyMethod ?
35
+ node.componentOnReady().then(() => {
36
+ attachProp(node, newProps, name);
37
+ }) :
38
+ attachProp(node, newProps, name);
39
+ }
40
+ });
41
+ }
42
+ };
43
+ function attachProp(node, newProps, name) {
44
+ node[name] = newProps[name];
45
+ const propType = typeof newProps[name];
46
+ if (propType === 'string') {
47
+ node.setAttribute(camelToDashCase(name), newProps[name]);
48
+ }
49
+ }
50
+ export const getClassName = (classList, newProps, oldProps) => {
51
+ const newClassProp = newProps.className || newProps.class;
52
+ const oldClassProp = oldProps.className || oldProps.class;
53
+ // map the classes to Maps for performance
54
+ const currentClasses = arrayToMap(classList);
55
+ const incomingPropClasses = arrayToMap(newClassProp ? newClassProp.split(' ') : []);
56
+ const oldPropClasses = arrayToMap(oldClassProp ? oldClassProp.split(' ') : []);
57
+ const finalClassNames = [];
58
+ // loop through each of the current classes on the component
59
+ // to see if it should be a part of the classNames added
60
+ currentClasses.forEach((currentClass) => {
61
+ if (incomingPropClasses.has(currentClass)) {
62
+ // add it as its already included in classnames coming in from newProps
63
+ finalClassNames.push(currentClass);
64
+ incomingPropClasses.delete(currentClass);
65
+ }
66
+ else if (!oldPropClasses.has(currentClass)) {
67
+ // add it as it has NOT been removed by user
68
+ finalClassNames.push(currentClass);
69
+ }
70
+ });
71
+ incomingPropClasses.forEach((s) => finalClassNames.push(s));
72
+ return finalClassNames.join(' ');
73
+ };
74
+ /**
75
+ * Checks if an event is supported in the current execution environment.
76
+ * @license Modernizr 3.0.0pre (Custom Build) | MIT
77
+ */
78
+ export const isCoveredByReact = (eventNameSuffix) => {
79
+ if (typeof document === 'undefined') {
80
+ return true;
81
+ }
82
+ else {
83
+ const eventName = 'on' + eventNameSuffix;
84
+ let isSupported = eventName in document;
85
+ if (!isSupported) {
86
+ const element = document.createElement('div');
87
+ element.setAttribute(eventName, 'return;');
88
+ isSupported = typeof element[eventName] === 'function';
89
+ }
90
+ return isSupported;
91
+ }
92
+ };
93
+ export const syncEvent = (node, eventName, newEventHandler) => {
94
+ const eventStore = node.__events || (node.__events = {});
95
+ const oldEventHandler = eventStore[eventName];
96
+ // Remove old listener so they don't double up.
97
+ if (oldEventHandler) {
98
+ node.removeEventListener(eventName, oldEventHandler);
99
+ }
100
+ // Bind new listener.
101
+ node.addEventListener(eventName, (eventStore[eventName] = function handler(e) {
102
+ if (newEventHandler) {
103
+ newEventHandler.call(this, e);
104
+ }
105
+ }));
106
+ };
107
+ const arrayToMap = (arr) => {
108
+ const map = new Map();
109
+ arr.forEach((s) => map.set(s, s));
110
+ return map;
111
+ };
112
+ function shouldAddSyncEventFallback(eventName) {
113
+ // onChange handle not works for custom component before react 19
114
+ // https://github.com/facebook/react/issues/22888
115
+ // TODO: we should support a general method to handle those issues.
116
+ // https://gethired.atlassian.net/browse/VD-3818
117
+ if ((eventName === "Change" &&
118
+ FeatureFlag.isEnabled("VEGA_REACT.ENABLE_ON_CHANGE_HANDLE_UNDER_LOW_VERSION")) ||
119
+ (eventName === "Close" &&
120
+ FeatureFlag.isEnabled("VEGA_REACT.ENABLE_ON_CLOSE_HANDLE_UNDER_LOW_VERSION"))) {
121
+ return true;
122
+ }
123
+ return false;
124
+ }
@@ -0,0 +1,2 @@
1
+ export declare const dashToPascalCase: (str: string) => string;
2
+ export declare const camelToDashCase: (str: string) => string;
@@ -0,0 +1,6 @@
1
+ export const dashToPascalCase = (str) => str
2
+ .toLowerCase()
3
+ .split('-')
4
+ .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
5
+ .join('');
6
+ export const camelToDashCase = (str) => str.replace(/([A-Z])/g, (m) => `-${m[0].toLowerCase()}`);
@@ -0,0 +1,2 @@
1
+ export declare const isDevMode: () => boolean;
2
+ export declare const deprecationWarning: (key: string, message: string) => void;
@@ -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 declare type StencilReactExternalProps<PropType, ElementType> = PropType & Omit<React.HTMLAttributes<ElementType>, 'style'> & StyleReactProps;
4
+ export declare 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<React.PropsWithoutRef<PropType & Omit<React.HTMLAttributes<ElementType>, "style"> & StyleReactProps> & React.RefAttributes<ElementType>>;
8
+ export declare const defineCustomElement: (tagName: string, customElement: any) => void;
9
+ export * from './attachProps';
10
+ export * from './case';
@@ -0,0 +1,33 @@
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, Object.assign({}, props, { forwardedRef: ref }));
21
+ };
22
+ forwardRef.displayName = displayName;
23
+ return React.forwardRef(forwardRef);
24
+ };
25
+ export const defineCustomElement = (tagName, customElement) => {
26
+ if (customElement !== undefined &&
27
+ typeof customElements !== 'undefined' &&
28
+ !customElements.get(tagName)) {
29
+ customElements.define(tagName, customElement);
30
+ }
31
+ };
32
+ export * from './attachProps';
33
+ export * from './case';
@@ -0,0 +1 @@
1
+ export * from "./utils";
@@ -0,0 +1 @@
1
+ export * from "./utils";
@@ -0,0 +1,21 @@
1
+ import type { RenderResult } from "@testing-library/react";
2
+ export declare type Nullable<T> = T | undefined | null;
3
+ /**
4
+ * @deprecated This utility is deprecated. Use `waitForVega` from `@heartlandone/vega-testing-library` directly.
5
+ * The `vega-testing-library` package supports Jest fake timers and does not require a `RenderResult` argument.
6
+ * Install it separately: `npm install @heartlandone/vega-testing-library`
7
+ */
8
+ export declare function waitForVegaReady(renderResult: RenderResult, delay?: number): Promise<RenderResult>;
9
+ /**
10
+ * @deprecated This type is deprecated. Use `MockedResizeObserverController` from `@heartlandone/vega-testing-library` directly.
11
+ * Install it separately: `npm install @heartlandone/vega-testing-library`
12
+ */
13
+ export declare type MockedResizeObserverController = {
14
+ hide: (selector: string, container?: HTMLElement) => void;
15
+ show: (selector: string, container?: HTMLElement) => void;
16
+ };
17
+ /**
18
+ * @deprecated This function is deprecated. Use `mockResizeObserver` from `@heartlandone/vega-testing-library` directly.
19
+ * Install it separately: `npm install @heartlandone/vega-testing-library`
20
+ */
21
+ export declare function mockResizeObserver(): MockedResizeObserverController;