@duetds/react
Advanced tools
| import React from 'react'; | ||
| import { OverlayEventDetail } from './interfaces'; | ||
| import { StencilReactForwardedRef } from './utils'; | ||
| interface OverlayElement extends HTMLElement { | ||
| present: () => Promise<void>; | ||
| dismiss: (data?: any, role?: string | undefined) => Promise<boolean>; | ||
| } | ||
| export interface ReactOverlayProps { | ||
| children?: React.ReactNode; | ||
| isOpen: boolean; | ||
| onDidDismiss?: (event: CustomEvent<OverlayEventDetail>) => void; | ||
| onDidPresent?: (event: CustomEvent<OverlayEventDetail>) => void; | ||
| onWillDismiss?: (event: CustomEvent<OverlayEventDetail>) => void; | ||
| onWillPresent?: (event: CustomEvent<OverlayEventDetail>) => void; | ||
| } | ||
| export declare const createOverlayComponent: <OverlayComponent extends object, OverlayType extends OverlayElement>(tagName: string, controller: { | ||
| create: (options: any) => Promise<OverlayType>; | ||
| }, customElement?: any) => React.ForwardRefExoticComponent<React.PropsWithoutRef<OverlayComponent & ReactOverlayProps & { | ||
| forwardedRef?: StencilReactForwardedRef<OverlayType>; | ||
| }> & React.RefAttributes<OverlayType>>; | ||
| export {}; |
| "use strict"; | ||
| var __extends = (this && this.__extends) || (function () { | ||
| var extendStatics = function (d, b) { | ||
| extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
| return extendStatics(d, b); | ||
| }; | ||
| return function (d, b) { | ||
| if (typeof b !== "function" && b !== null) | ||
| throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| }; | ||
| })(); | ||
| var __assign = (this && this.__assign) || function () { | ||
| __assign = Object.assign || function(t) { | ||
| for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
| s = arguments[i]; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
| t[p] = s[p]; | ||
| } | ||
| return t; | ||
| }; | ||
| return __assign.apply(this, arguments); | ||
| }; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| var __generator = (this && this.__generator) || function (thisArg, body) { | ||
| var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
| return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
| function verb(n) { return function (v) { return step([n, v]); }; } | ||
| function step(op) { | ||
| if (f) throw new TypeError("Generator is already executing."); | ||
| while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
| if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
| if (y = 0, t) op = [op[0] & 2, t.value]; | ||
| switch (op[0]) { | ||
| case 0: case 1: t = op; break; | ||
| case 4: _.label++; return { value: op[1], done: false }; | ||
| case 5: _.label++; y = op[1]; op = [0]; continue; | ||
| case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
| default: | ||
| if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
| if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
| if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
| if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
| if (t[2]) _.ops.pop(); | ||
| _.trys.pop(); continue; | ||
| } | ||
| op = body.call(thisArg, _); | ||
| } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
| if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
| } | ||
| }; | ||
| var __rest = (this && this.__rest) || function (s, e) { | ||
| var t = {}; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
| t[p] = s[p]; | ||
| if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
| for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
| if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
| t[p[i]] = s[p[i]]; | ||
| } | ||
| return t; | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.createOverlayComponent = void 0; | ||
| var react_1 = __importStar(require("react")); | ||
| var react_dom_1 = __importDefault(require("react-dom")); | ||
| var utils_1 = require("./utils"); | ||
| var createOverlayComponent = function (tagName, controller, customElement) { | ||
| (0, utils_1.defineCustomElement)(tagName, customElement); | ||
| var displayName = (0, utils_1.dashToPascalCase)(tagName); | ||
| var didDismissEventName = "on".concat(displayName, "DidDismiss"); | ||
| var didPresentEventName = "on".concat(displayName, "DidPresent"); | ||
| var willDismissEventName = "on".concat(displayName, "WillDismiss"); | ||
| var willPresentEventName = "on".concat(displayName, "WillPresent"); | ||
| var isDismissing = false; | ||
| var Overlay = /** @class */ (function (_super) { | ||
| __extends(Overlay, _super); | ||
| function Overlay(props) { | ||
| var _this = _super.call(this, props) || this; | ||
| if (typeof document !== 'undefined') { | ||
| _this.el = document.createElement('div'); | ||
| } | ||
| _this.handleDismiss = _this.handleDismiss.bind(_this); | ||
| return _this; | ||
| } | ||
| Object.defineProperty(Overlay, "displayName", { | ||
| get: function () { | ||
| return displayName; | ||
| }, | ||
| enumerable: false, | ||
| configurable: true | ||
| }); | ||
| Overlay.prototype.componentDidMount = function () { | ||
| if (this.props.isOpen) { | ||
| this.present(); | ||
| } | ||
| }; | ||
| Overlay.prototype.componentWillUnmount = function () { | ||
| if (this.overlay) { | ||
| this.overlay.dismiss(); | ||
| } | ||
| }; | ||
| Overlay.prototype.handleDismiss = function (event) { | ||
| if (this.props.onDidDismiss) { | ||
| this.props.onDidDismiss(event); | ||
| } | ||
| (0, utils_1.setRef)(this.props.forwardedRef, null); | ||
| }; | ||
| Overlay.prototype.shouldComponentUpdate = function (nextProps) { | ||
| // Check if the overlay component is about to dismiss | ||
| if (this.overlay && nextProps.isOpen !== this.props.isOpen && nextProps.isOpen === false) { | ||
| isDismissing = true; | ||
| } | ||
| return true; | ||
| }; | ||
| Overlay.prototype.componentDidUpdate = function (prevProps) { | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| return __generator(this, function (_a) { | ||
| switch (_a.label) { | ||
| case 0: | ||
| if (this.overlay) { | ||
| (0, utils_1.attachProps)(this.overlay, this.props, prevProps); | ||
| } | ||
| if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) { | ||
| this.present(prevProps); | ||
| } | ||
| if (!(this.overlay && prevProps.isOpen !== this.props.isOpen && this.props.isOpen === false)) return [3 /*break*/, 2]; | ||
| return [4 /*yield*/, this.overlay.dismiss()]; | ||
| case 1: | ||
| _a.sent(); | ||
| isDismissing = false; | ||
| /** | ||
| * Now that the overlay is dismissed | ||
| * we need to render again so that any | ||
| * inner components will be unmounted | ||
| */ | ||
| this.forceUpdate(); | ||
| _a.label = 2; | ||
| case 2: return [2 /*return*/]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| Overlay.prototype.present = function (prevProps) { | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var _a, children, isOpen, onDidDismiss, onDidPresent, onWillDismiss, onWillPresent, cProps, elementProps, _b; | ||
| var _c; | ||
| var _this = this; | ||
| return __generator(this, function (_d) { | ||
| switch (_d.label) { | ||
| case 0: | ||
| _a = this.props, children = _a.children, isOpen = _a.isOpen, onDidDismiss = _a.onDidDismiss, onDidPresent = _a.onDidPresent, onWillDismiss = _a.onWillDismiss, onWillPresent = _a.onWillPresent, cProps = __rest(_a, ["children", "isOpen", "onDidDismiss", "onDidPresent", "onWillDismiss", "onWillPresent"]); | ||
| elementProps = __assign(__assign({}, cProps), (_c = { ref: this.props.forwardedRef }, _c[didDismissEventName] = this.handleDismiss, _c[didPresentEventName] = function (e) { | ||
| return _this.props.onDidPresent && _this.props.onDidPresent(e); | ||
| }, _c[willDismissEventName] = function (e) { | ||
| return _this.props.onWillDismiss && _this.props.onWillDismiss(e); | ||
| }, _c[willPresentEventName] = function (e) { | ||
| return _this.props.onWillPresent && _this.props.onWillPresent(e); | ||
| }, _c)); | ||
| _b = this; | ||
| return [4 /*yield*/, controller.create(__assign(__assign({}, elementProps), { component: this.el, componentProps: {} }))]; | ||
| case 1: | ||
| _b.overlay = _d.sent(); | ||
| (0, utils_1.setRef)(this.props.forwardedRef, this.overlay); | ||
| (0, utils_1.attachProps)(this.overlay, elementProps, prevProps); | ||
| return [4 /*yield*/, this.overlay.present()]; | ||
| case 2: | ||
| _d.sent(); | ||
| return [2 /*return*/]; | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| Overlay.prototype.render = function () { | ||
| /** | ||
| * Continue to render the component even when | ||
| * overlay is dismissing otherwise component | ||
| * will be hidden before animation is done. | ||
| */ | ||
| return react_dom_1.default.createPortal(this.props.isOpen || isDismissing ? this.props.children : null, this.el); | ||
| }; | ||
| return Overlay; | ||
| }(react_1.Component)); | ||
| return react_1.default.forwardRef(function (props, ref) { | ||
| return react_1.default.createElement(Overlay, __assign({}, props, { forwardedRef: ref })); | ||
| }); | ||
| }; | ||
| exports.createOverlayComponent = createOverlayComponent; | ||
| //# sourceMappingURL=createOverlayComponent.js.map |
| {"version":3,"file":"createOverlayComponent.js","sourceRoot":"","sources":["../../src/react-component-lib/createOverlayComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA0D;AAC1D,wDAAiC;AAGjC,iCAMiB;AAgBV,IAAM,sBAAsB,GAAG,UAIpC,OAAe,EACf,UAA8D,EAC9D,aAAmB;IAEnB,IAAA,2BAAmB,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAE5C,IAAM,WAAW,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;IAC9C,IAAM,mBAAmB,GAAG,YAAK,WAAW,eAAY,CAAC;IACzD,IAAM,mBAAmB,GAAG,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| "name": "@duetds/react", | ||
| "version": "9.11.0", | ||
| "version": "9.12.0", | ||
| "description": "This package includes React specific wrapper for Duet Design System Web Components.", | ||
@@ -25,3 +25,3 @@ "license": "SEE LICENSE IN LICENSE.md", | ||
| "dependencies": { | ||
| "@duetds/components": "9.11.0" | ||
| "@duetds/components": "9.12.0" | ||
| }, | ||
@@ -48,3 +48,3 @@ "devDependencies": { | ||
| }, | ||
| "gitHead": "a7e7d94d1e229a6d881bd187af4bad17db5095e7" | ||
| "gitHead": "efb1655b4344b0a8ae9e792e7cd4b9087676577f" | ||
| } |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
162934
11.38%62
5.08%1582
18.59%+ Added
- Removed
Updated