@nozzlegear/react-win-dialog
Version:
An attempt to recreate the Dialog element from WinJS.
354 lines (353 loc) • 12.1 kB
JavaScript
import * as b from "react";
import te from "react";
import * as ne from "react-dom";
import R from "classnames";
var T = { exports: {} }, _ = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var L;
function ae() {
if (L) return _;
L = 1;
var r = Symbol.for("react.transitional.element"), s = Symbol.for("react.fragment");
function u(d, l, c) {
var f = null;
if (c !== void 0 && (f = "" + c), l.key !== void 0 && (f = "" + l.key), "key" in l) {
c = {};
for (var m in l)
m !== "key" && (c[m] = l[m]);
} else c = l;
return l = c.ref, {
$$typeof: r,
type: d,
key: f,
ref: l !== void 0 ? l : null,
props: c
};
}
return _.Fragment = s, _.jsx = u, _.jsxs = u, _;
}
var E = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var W;
function oe() {
return W || (W = 1, process.env.NODE_ENV !== "production" && (function() {
function r(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === K ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case k:
return "Fragment";
case q:
return "Profiler";
case V:
return "StrictMode";
case B:
return "Suspense";
case H:
return "SuspenseList";
case Q:
return "Activity";
}
if (typeof e == "object")
switch (typeof e.tag == "number" && console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
), e.$$typeof) {
case J:
return "Portal";
case G:
return e.displayName || "Context";
case z:
return (e._context.displayName || "Context") + ".Consumer";
case X:
var t = e.render;
return e = e.displayName, e || (e = t.displayName || t.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case Z:
return t = e.displayName || null, t !== null ? t : r(e.type) || "Memo";
case j:
t = e._payload, e = e._init;
try {
return r(e(t));
} catch {
}
}
return null;
}
function s(e) {
return "" + e;
}
function u(e) {
try {
s(e);
var t = !1;
} catch {
t = !0;
}
if (t) {
t = console;
var n = t.error, a = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
return n.call(
t,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
a
), s(e);
}
}
function d(e) {
if (e === k) return "<>";
if (typeof e == "object" && e !== null && e.$$typeof === j)
return "<...>";
try {
var t = r(e);
return t ? "<" + t + ">" : "<...>";
} catch {
return "<...>";
}
}
function l() {
var e = h.A;
return e === null ? null : e.getOwner();
}
function c() {
return Error("react-stack-top-frame");
}
function f(e) {
if (Y.call(e, "key")) {
var t = Object.getOwnPropertyDescriptor(e, "key").get;
if (t && t.isReactWarning) return !1;
}
return e.key !== void 0;
}
function m(e, t) {
function n() {
F || (F = !0, console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
t
));
}
n.isReactWarning = !0, Object.defineProperty(e, "key", {
get: n,
configurable: !0
});
}
function x() {
var e = r(this.type);
return I[e] || (I[e] = !0, console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
)), e = this.props.ref, e !== void 0 ? e : null;
}
function w(e, t, n, a, y, O) {
var o = n.ref;
return e = {
$$typeof: p,
type: e,
key: t,
props: n,
_owner: a
}, (o !== void 0 ? o : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: x
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: 0
}), Object.defineProperty(e, "_debugInfo", {
configurable: !1,
enumerable: !1,
writable: !0,
value: null
}), Object.defineProperty(e, "_debugStack", {
configurable: !1,
enumerable: !1,
writable: !0,
value: y
}), Object.defineProperty(e, "_debugTask", {
configurable: !1,
enumerable: !1,
writable: !0,
value: O
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
}
function A(e, t, n, a, y, O) {
var o = t.children;
if (o !== void 0)
if (a)
if (ee(o)) {
for (a = 0; a < o.length; a++)
N(o[a]);
Object.freeze && Object.freeze(o);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else N(o);
if (Y.call(t, "key")) {
o = r(e);
var v = Object.keys(t).filter(function(re) {
return re !== "key";
});
a = 0 < v.length ? "{key: someKey, " + v.join(": ..., ") + ": ...}" : "{key: someKey}", M[o + a] || (v = 0 < v.length ? "{" + v.join(": ..., ") + ": ...}" : "{}", console.error(
`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,
a,
o,
v,
o
), M[o + a] = !0);
}
if (o = null, n !== void 0 && (u(n), o = "" + n), f(t) && (u(t.key), o = "" + t.key), "key" in t) {
n = {};
for (var P in t)
P !== "key" && (n[P] = t[P]);
} else n = t;
return o && m(
n,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), w(
e,
o,
n,
l(),
y,
O
);
}
function N(e) {
C(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === j && (e._payload.status === "fulfilled" ? C(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
}
function C(e) {
return typeof e == "object" && e !== null && e.$$typeof === p;
}
var g = te, p = Symbol.for("react.transitional.element"), J = Symbol.for("react.portal"), k = Symbol.for("react.fragment"), V = Symbol.for("react.strict_mode"), q = Symbol.for("react.profiler"), z = Symbol.for("react.consumer"), G = Symbol.for("react.context"), X = Symbol.for("react.forward_ref"), B = Symbol.for("react.suspense"), H = Symbol.for("react.suspense_list"), Z = Symbol.for("react.memo"), j = Symbol.for("react.lazy"), Q = Symbol.for("react.activity"), K = Symbol.for("react.client.reference"), h = g.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Y = Object.prototype.hasOwnProperty, ee = Array.isArray, S = console.createTask ? console.createTask : function() {
return null;
};
g = {
react_stack_bottom_frame: function(e) {
return e();
}
};
var F, I = {}, D = g.react_stack_bottom_frame.bind(
g,
c
)(), $ = S(d(c)), M = {};
E.Fragment = k, E.jsx = function(e, t, n) {
var a = 1e4 > h.recentlyCreatedOwnerStacks++;
return A(
e,
t,
n,
!1,
a ? Error("react-stack-top-frame") : D,
a ? S(d(e)) : $
);
}, E.jsxs = function(e, t, n) {
var a = 1e4 > h.recentlyCreatedOwnerStacks++;
return A(
e,
t,
n,
!0,
a ? Error("react-stack-top-frame") : D,
a ? S(d(e)) : $
);
};
})()), E;
}
var U;
function le() {
return U || (U = 1, process.env.NODE_ENV === "production" ? T.exports = ae() : T.exports = oe()), T.exports;
}
var i = le();
function ue(r) {
const s = () => {
}, u = r.overlayPreventsScrolling !== !1;
let d = /* @__PURE__ */ i.jsx(b.Fragment, {});
const l = b.useMemo(() => document.body.style.overflow, []);
if (b.useEffect(() => (u && (r.open ? document.body.style.overflow = "hidden" : document.body.style.overflow = l || ""), () => {
u && (document.body.style.overflow = l || "");
}), [r.open, u, l]), r.open) {
const f = [], m = r.loading ?? !1, x = r.loadingHidesButtons ?? !0;
(m === !1 || x === !1) && (typeof r.secondaryText == "string" && f.push(
/* @__PURE__ */ i.jsx(
"button",
{
type: "button",
className: "btn react-win-dialog-secondary-command",
onClick: r.onSecondaryClick || s,
children: r.secondaryText
},
"secondary-button"
)
), typeof r.primaryText == "string" && f.push(
/* @__PURE__ */ i.jsx(
"button",
{
type: "button",
className: R("btn react-win-dialog-primary-command primary", { danger: r.danger }),
onClick: r.onPrimaryClick || s,
children: r.primaryText
},
"primary-button"
)
));
const w = /* @__PURE__ */ i.jsx(
"div",
{
id: r.id,
className: R("react-win-dialog-container", r.className),
style: r.containerStyle,
children: /* @__PURE__ */ i.jsxs(
"div",
{
className: R("react-win-dialog", { danger: r.danger || !1 }),
style: r.dialogStyle,
children: [
/* @__PURE__ */ i.jsx("p", { className: "react-win-dialog-title", children: r.title }),
/* @__PURE__ */ i.jsxs("div", { className: "react-win-dialog-content", children: [
r.children,
/* @__PURE__ */ i.jsx(ie, { loading: m, loadingComponent: r.loadingComponent })
] }),
/* @__PURE__ */ i.jsx("div", { className: "react-win-dialog-footer", children: f })
]
}
)
},
"react-win-dialog-container"
);
d = /* @__PURE__ */ i.jsx("div", { children: w });
}
const c = /* @__PURE__ */ i.jsx("div", { className: R("react-win-dialog-overlay", { open: r.open }), style: r.overlayStyle, children: d });
return ne.createPortal(c, document.body);
}
const ie = b.memo((r) => {
if (r.loading !== !0)
return /* @__PURE__ */ i.jsx(b.Fragment, {});
let s;
return r.loadingComponent === null || r.loadingComponent === void 0 ? s = /* @__PURE__ */ i.jsx("progress", { className: "react-win-dialog-loading-bar" }) : typeof r.loadingComponent == "function" ? s = b.createElement(r.loadingComponent) : s = r.loadingComponent, /* @__PURE__ */ i.jsx("div", { className: "react-win-dialog-loading-container", children: s });
});
export {
ue as Dialog
};
//# sourceMappingURL=index.js.map