react-super-switch 1.0.6 → 1.0.7
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
CHANGED
|
@@ -131,9 +131,10 @@ The parent component that evaluates all `<Option />` children and decides which
|
|
|
131
131
|
<SuperSwitch mode="fcfs | priority">{options}</SuperSwitch>
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
| Prop
|
|
135
|
-
|
|
|
136
|
-
| `mode`
|
|
134
|
+
| Prop | Type | Default | Description |
|
|
135
|
+
| ---------- | ------------------------ | -------- | --------------------------------------------------------------------------- |
|
|
136
|
+
| `mode` | `"fcfs"` or `"priority"` | `"fcfs"` | Determines how options are evaluated |
|
|
137
|
+
| `optional` | `boolean` | `false` | Allows the switch to render nothing when all `Option` conditions are falsy. |
|
|
137
138
|
|
|
138
139
|
### `<Option />`
|
|
139
140
|
|
|
@@ -4,7 +4,8 @@ import type { OptionChild } from "./types";
|
|
|
4
4
|
export type SuperSwitchProps = {
|
|
5
5
|
children: ReactElement<OptionProps> | ReactElement<OptionProps>[];
|
|
6
6
|
mode?: "priority" | "fcfs";
|
|
7
|
+
optional?: boolean;
|
|
7
8
|
};
|
|
8
|
-
declare const SuperSwitch: ({ children, mode }: SuperSwitchProps) => OptionChild | null;
|
|
9
|
+
declare const SuperSwitch: ({ children, mode, optional }: SuperSwitchProps) => OptionChild | null;
|
|
9
10
|
export default SuperSwitch;
|
|
10
11
|
//# sourceMappingURL=SuperSwitch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuperSwitch.d.ts","sourceRoot":"","sources":["../../../src/components/SuperSwitch/SuperSwitch.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAI1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,GAAG,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;IAClE,IAAI,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"SuperSwitch.d.ts","sourceRoot":"","sources":["../../../src/components/SuperSwitch/SuperSwitch.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAI1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,GAAG,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;IAClE,IAAI,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,QAAA,MAAM,WAAW,GAAI,8BAA+C,gBAAgB,uBA8CnF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react");var b={exports:{}},_={};var F;function ne(){if(F)return _;F=1;var i=Symbol.for("react.transitional.element"),f=Symbol.for("react.fragment");function c(u,a,s){var p=null;if(s!==void 0&&(p=""+s),a.key!==void 0&&(p=""+a.key),"key"in a){s={};for(var d in a)d!=="key"&&(s[d]=a[d])}else s=a;return a=s.ref,{$$typeof:i,type:u,key:p,ref:a!==void 0?a:null,props:s}}return _.Fragment=f,_.jsx=c,_.jsxs=c,_}var R={};var M;function oe(){return M||(M=1,process.env.NODE_ENV!=="production"&&(function(){function i(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ee?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case P:return"Fragment";case J:return"Profiler";case G:return"StrictMode";case X:return"Suspense";case Z:return"SuspenseList";case K: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 q:return"Portal";case B:return e.displayName||"Context";case z:return(e._context.displayName||"Context")+".Consumer";case H:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Q:return r=e.displayName||null,r!==null?r:i(e.type)||"Memo";case h:r=e._payload,e=e._init;try{return i(e(r))}catch{}}return null}function f(e){return""+e}function c(e){try{f(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,n=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),f(e)}}function u(e){if(e===P)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===h)return"<...>";try{var r=i(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function a(){var e=w.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function p(e){if(x.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function d(e,r){function t(){C||(C=!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)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function m(){var e=i(this.type);return Y[e]||(Y[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 l(e,r,t,n,T,N){var o=t.ref;return e={$$typeof:j,type:e,key:r,props:t,_owner:n},(o!==void 0?o:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:m}):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:T}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:N}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function y(e,r,t,n,T,N){var o=r.children;if(o!==void 0)if(n)if(re(o)){for(n=0;n<o.length;n++)I(o[n]);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 I(o);if(x.call(r,"key")){o=i(e);var E=Object.keys(r).filter(function(te){return te!=="key"});n=0<E.length?"{key: someKey, "+E.join(": ..., ")+": ...}":"{key: someKey}",$[o+n]||(E=0<E.length?"{"+E.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,o,
|
|
6
|
+
<%s key={someKey} {...props} />`,n,o,E,o),$[o+n]=!0)}if(o=null,t!==void 0&&(c(t),o=""+t),p(r)&&(c(r.key),o=""+r.key),"key"in r){t={};for(var A in r)A!=="key"&&(t[A]=r[A])}else t=r;return o&&d(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),l(e,o,t,a(),T,N)}function I(e){g(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===h&&(e._payload.status==="fulfilled"?g(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function g(e){return typeof e=="object"&&e!==null&&e.$$typeof===j}var v=S,j=Symbol.for("react.transitional.element"),q=Symbol.for("react.portal"),P=Symbol.for("react.fragment"),G=Symbol.for("react.strict_mode"),J=Symbol.for("react.profiler"),z=Symbol.for("react.consumer"),B=Symbol.for("react.context"),H=Symbol.for("react.forward_ref"),X=Symbol.for("react.suspense"),Z=Symbol.for("react.suspense_list"),Q=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),K=Symbol.for("react.activity"),ee=Symbol.for("react.client.reference"),w=v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,x=Object.prototype.hasOwnProperty,re=Array.isArray,k=console.createTask?console.createTask:function(){return null};v={react_stack_bottom_frame:function(e){return e()}};var C,Y={},D=v.react_stack_bottom_frame.bind(v,s)(),L=k(u(s)),$={};R.Fragment=P,R.jsx=function(e,r,t){var n=1e4>w.recentlyCreatedOwnerStacks++;return y(e,r,t,!1,n?Error("react-stack-top-frame"):D,n?k(u(e)):L)},R.jsxs=function(e,r,t){var n=1e4>w.recentlyCreatedOwnerStacks++;return y(e,r,t,!0,n?Error("react-stack-top-frame"):D,n?k(u(e)):L)}})()),R}var V;function ae(){return V||(V=1,process.env.NODE_ENV==="production"?b.exports=ne():b.exports=oe()),b.exports}var W=ae();const U=({children:i})=>W.jsx(W.Fragment,{children:i}),O={INVALID_CHILDREN_TYPE:"SuperSwitch only accepts <Option /> as children. Received an invalid child instead.",MISSING_PRIORITIES:'SuperSwitch is running in "priority" mode, but not all <Option /> elements define a priority. When using priority mode, every <Option /> must specify a numeric "priority" prop.',NO_OPTION_TO_RENDER:"SuperSwitch could not determine which option to render. No <Option /> had a truthy condition, and no default option was provided.",INVALID_OPTION_PROPS:'Invalid <Option />: "default" and "condition" cannot be used together. Use "default" for the fallback option, or "condition" for conditional options.'},ie=i=>i.sort((f,c)=>{const u=f.props?.priority,a=c.props?.priority;return u===void 0&&a===void 0?0:u===void 0?1:a===void 0||u<a?-1:u>a?1:0}),se=({children:i,mode:f="fcfs",optional:c=!1})=>{const[u,a]=S.useState(null);return S.useEffect(()=>{const s=[];let p=!0;S.Children.forEach(i,l=>{if(!(l?.type===U))throw new Error(O.INVALID_CHILDREN_TYPE);if(l.props.default&&"condition"in l.props)throw new Error(O.INVALID_OPTION_PROPS);s.push(l),l.props.priority===void 0&&(p=!1)});let d=s;if(f==="priority"){if(!p)throw new Error(O.MISSING_PRIORITIES);d=ie(s)}const m=d.find(l=>!!l.props.condition&&!l.props.default)??d.find(l=>!!l.props.default);if(m)a(m);else if(!c)throw new Error(O.NO_OPTION_TO_RENDER)},[i,f,c]),u};exports.Option=U;exports.SuperSwitch=se;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import re, { useState as te, useEffect as ne, Children as oe } from "react";
|
|
2
|
-
var
|
|
2
|
+
var b = { exports: {} }, _ = {};
|
|
3
3
|
var $;
|
|
4
4
|
function ae() {
|
|
5
5
|
if ($) return _;
|
|
6
6
|
$ = 1;
|
|
7
|
-
var i = /* @__PURE__ */ Symbol.for("react.transitional.element"),
|
|
8
|
-
function
|
|
9
|
-
var
|
|
10
|
-
if (s !== void 0 && (
|
|
7
|
+
var i = /* @__PURE__ */ Symbol.for("react.transitional.element"), f = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
8
|
+
function c(l, a, s) {
|
|
9
|
+
var p = null;
|
|
10
|
+
if (s !== void 0 && (p = "" + s), a.key !== void 0 && (p = "" + a.key), "key" in a) {
|
|
11
11
|
s = {};
|
|
12
|
-
for (var
|
|
13
|
-
|
|
14
|
-
} else s =
|
|
15
|
-
return
|
|
12
|
+
for (var d in a)
|
|
13
|
+
d !== "key" && (s[d] = a[d]);
|
|
14
|
+
} else s = a;
|
|
15
|
+
return a = s.ref, {
|
|
16
16
|
$$typeof: i,
|
|
17
17
|
type: l,
|
|
18
|
-
key:
|
|
19
|
-
ref:
|
|
18
|
+
key: p,
|
|
19
|
+
ref: a !== void 0 ? a : null,
|
|
20
20
|
props: s
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
return _.Fragment =
|
|
23
|
+
return _.Fragment = f, _.jsx = c, _.jsxs = c, _;
|
|
24
24
|
}
|
|
25
25
|
var R = {};
|
|
26
26
|
var F;
|
|
@@ -32,7 +32,7 @@ function ie() {
|
|
|
32
32
|
return e.$$typeof === Q ? null : e.displayName || e.name || null;
|
|
33
33
|
if (typeof e == "string") return e;
|
|
34
34
|
switch (e) {
|
|
35
|
-
case
|
|
35
|
+
case y:
|
|
36
36
|
return "Fragment";
|
|
37
37
|
case G:
|
|
38
38
|
return "Profiler";
|
|
@@ -60,7 +60,7 @@ function ie() {
|
|
|
60
60
|
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
61
61
|
case X:
|
|
62
62
|
return r = e.displayName || null, r !== null ? r : i(e.type) || "Memo";
|
|
63
|
-
case
|
|
63
|
+
case P:
|
|
64
64
|
r = e._payload, e = e._init;
|
|
65
65
|
try {
|
|
66
66
|
return i(e(r));
|
|
@@ -69,29 +69,29 @@ function ie() {
|
|
|
69
69
|
}
|
|
70
70
|
return null;
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function f(e) {
|
|
73
73
|
return "" + e;
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function c(e) {
|
|
76
76
|
try {
|
|
77
|
-
|
|
77
|
+
f(e);
|
|
78
78
|
var r = !1;
|
|
79
79
|
} catch {
|
|
80
80
|
r = !0;
|
|
81
81
|
}
|
|
82
82
|
if (r) {
|
|
83
83
|
r = console;
|
|
84
|
-
var t = r.error,
|
|
84
|
+
var t = r.error, n = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
85
85
|
return t.call(
|
|
86
86
|
r,
|
|
87
87
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
88
|
-
|
|
89
|
-
),
|
|
88
|
+
n
|
|
89
|
+
), f(e);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
function l(e) {
|
|
93
|
-
if (e ===
|
|
94
|
-
if (typeof e == "object" && e !== null && e.$$typeof ===
|
|
93
|
+
if (e === y) return "<>";
|
|
94
|
+
if (typeof e == "object" && e !== null && e.$$typeof === P)
|
|
95
95
|
return "<...>";
|
|
96
96
|
try {
|
|
97
97
|
var r = i(e);
|
|
@@ -100,21 +100,21 @@ function ie() {
|
|
|
100
100
|
return "<...>";
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
var e =
|
|
103
|
+
function a() {
|
|
104
|
+
var e = h.A;
|
|
105
105
|
return e === null ? null : e.getOwner();
|
|
106
106
|
}
|
|
107
107
|
function s() {
|
|
108
108
|
return Error("react-stack-top-frame");
|
|
109
109
|
}
|
|
110
|
-
function
|
|
110
|
+
function p(e) {
|
|
111
111
|
if (x.call(e, "key")) {
|
|
112
112
|
var r = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
113
113
|
if (r && r.isReactWarning) return !1;
|
|
114
114
|
}
|
|
115
115
|
return e.key !== void 0;
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function d(e, r) {
|
|
118
118
|
function t() {
|
|
119
119
|
j || (j = !0, console.error(
|
|
120
120
|
"%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)",
|
|
@@ -126,23 +126,23 @@ function ie() {
|
|
|
126
126
|
configurable: !0
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function m() {
|
|
130
130
|
var e = i(this.type);
|
|
131
131
|
return C[e] || (C[e] = !0, console.error(
|
|
132
132
|
"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."
|
|
133
133
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
134
134
|
}
|
|
135
|
-
function
|
|
136
|
-
var
|
|
135
|
+
function u(e, r, t, n, T, k) {
|
|
136
|
+
var o = t.ref;
|
|
137
137
|
return e = {
|
|
138
138
|
$$typeof: g,
|
|
139
139
|
type: e,
|
|
140
140
|
key: r,
|
|
141
141
|
props: t,
|
|
142
|
-
_owner:
|
|
143
|
-
}, (
|
|
142
|
+
_owner: n
|
|
143
|
+
}, (o !== void 0 ? o : null) !== null ? Object.defineProperty(e, "ref", {
|
|
144
144
|
enumerable: !1,
|
|
145
|
-
get:
|
|
145
|
+
get: m
|
|
146
146
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
147
147
|
configurable: !1,
|
|
148
148
|
enumerable: !1,
|
|
@@ -157,139 +157,140 @@ function ie() {
|
|
|
157
157
|
configurable: !1,
|
|
158
158
|
enumerable: !1,
|
|
159
159
|
writable: !0,
|
|
160
|
-
value:
|
|
160
|
+
value: T
|
|
161
161
|
}), Object.defineProperty(e, "_debugTask", {
|
|
162
162
|
configurable: !1,
|
|
163
163
|
enumerable: !1,
|
|
164
164
|
writable: !0,
|
|
165
|
-
value:
|
|
165
|
+
value: k
|
|
166
166
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
167
167
|
}
|
|
168
|
-
function
|
|
169
|
-
var
|
|
170
|
-
if (
|
|
171
|
-
if (
|
|
172
|
-
if (K(
|
|
173
|
-
for (
|
|
174
|
-
A(
|
|
175
|
-
Object.freeze && Object.freeze(
|
|
168
|
+
function S(e, r, t, n, T, k) {
|
|
169
|
+
var o = r.children;
|
|
170
|
+
if (o !== void 0)
|
|
171
|
+
if (n)
|
|
172
|
+
if (K(o)) {
|
|
173
|
+
for (n = 0; n < o.length; n++)
|
|
174
|
+
A(o[n]);
|
|
175
|
+
Object.freeze && Object.freeze(o);
|
|
176
176
|
} else
|
|
177
177
|
console.error(
|
|
178
178
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
179
179
|
);
|
|
180
|
-
else A(
|
|
180
|
+
else A(o);
|
|
181
181
|
if (x.call(r, "key")) {
|
|
182
|
-
|
|
182
|
+
o = i(e);
|
|
183
183
|
var E = Object.keys(r).filter(function(ee) {
|
|
184
184
|
return ee !== "key";
|
|
185
185
|
});
|
|
186
|
-
|
|
186
|
+
n = 0 < E.length ? "{key: someKey, " + E.join(": ..., ") + ": ...}" : "{key: someKey}", L[o + n] || (E = 0 < E.length ? "{" + E.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
187
187
|
`A props object containing a "key" prop is being spread into JSX:
|
|
188
188
|
let props = %s;
|
|
189
189
|
<%s {...props} />
|
|
190
190
|
React keys must be passed directly to JSX without using spread:
|
|
191
191
|
let props = %s;
|
|
192
192
|
<%s key={someKey} {...props} />`,
|
|
193
|
+
n,
|
|
193
194
|
o,
|
|
194
|
-
a,
|
|
195
195
|
E,
|
|
196
|
-
|
|
197
|
-
), L[
|
|
196
|
+
o
|
|
197
|
+
), L[o + n] = !0);
|
|
198
198
|
}
|
|
199
|
-
if (
|
|
199
|
+
if (o = null, t !== void 0 && (c(t), o = "" + t), p(r) && (c(r.key), o = "" + r.key), "key" in r) {
|
|
200
200
|
t = {};
|
|
201
|
-
for (var
|
|
202
|
-
|
|
201
|
+
for (var N in r)
|
|
202
|
+
N !== "key" && (t[N] = r[N]);
|
|
203
203
|
} else t = r;
|
|
204
|
-
return
|
|
204
|
+
return o && d(
|
|
205
205
|
t,
|
|
206
206
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
207
|
-
),
|
|
207
|
+
), u(
|
|
208
208
|
e,
|
|
209
|
-
|
|
209
|
+
o,
|
|
210
210
|
t,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
a(),
|
|
212
|
+
T,
|
|
213
|
+
k
|
|
214
214
|
);
|
|
215
215
|
}
|
|
216
216
|
function A(e) {
|
|
217
|
-
I(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof ===
|
|
217
|
+
I(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === P && (e._payload.status === "fulfilled" ? I(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
218
218
|
}
|
|
219
219
|
function I(e) {
|
|
220
220
|
return typeof e == "object" && e !== null && e.$$typeof === g;
|
|
221
221
|
}
|
|
222
|
-
var
|
|
222
|
+
var v = re, g = /* @__PURE__ */ Symbol.for("react.transitional.element"), W = /* @__PURE__ */ Symbol.for("react.portal"), y = /* @__PURE__ */ Symbol.for("react.fragment"), U = /* @__PURE__ */ Symbol.for("react.strict_mode"), G = /* @__PURE__ */ Symbol.for("react.profiler"), q = /* @__PURE__ */ Symbol.for("react.consumer"), J = /* @__PURE__ */ Symbol.for("react.context"), z = /* @__PURE__ */ Symbol.for("react.forward_ref"), B = /* @__PURE__ */ Symbol.for("react.suspense"), H = /* @__PURE__ */ Symbol.for("react.suspense_list"), X = /* @__PURE__ */ Symbol.for("react.memo"), P = /* @__PURE__ */ Symbol.for("react.lazy"), Z = /* @__PURE__ */ Symbol.for("react.activity"), Q = /* @__PURE__ */ Symbol.for("react.client.reference"), h = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, x = Object.prototype.hasOwnProperty, K = Array.isArray, w = console.createTask ? console.createTask : function() {
|
|
223
223
|
return null;
|
|
224
224
|
};
|
|
225
|
-
|
|
225
|
+
v = {
|
|
226
226
|
react_stack_bottom_frame: function(e) {
|
|
227
227
|
return e();
|
|
228
228
|
}
|
|
229
229
|
};
|
|
230
|
-
var j, C = {}, Y =
|
|
231
|
-
|
|
230
|
+
var j, C = {}, Y = v.react_stack_bottom_frame.bind(
|
|
231
|
+
v,
|
|
232
232
|
s
|
|
233
|
-
)(), D =
|
|
234
|
-
R.Fragment =
|
|
235
|
-
var
|
|
236
|
-
return
|
|
233
|
+
)(), D = w(l(s)), L = {};
|
|
234
|
+
R.Fragment = y, R.jsx = function(e, r, t) {
|
|
235
|
+
var n = 1e4 > h.recentlyCreatedOwnerStacks++;
|
|
236
|
+
return S(
|
|
237
237
|
e,
|
|
238
238
|
r,
|
|
239
239
|
t,
|
|
240
240
|
!1,
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
n ? Error("react-stack-top-frame") : Y,
|
|
242
|
+
n ? w(l(e)) : D
|
|
243
243
|
);
|
|
244
244
|
}, R.jsxs = function(e, r, t) {
|
|
245
|
-
var
|
|
246
|
-
return
|
|
245
|
+
var n = 1e4 > h.recentlyCreatedOwnerStacks++;
|
|
246
|
+
return S(
|
|
247
247
|
e,
|
|
248
248
|
r,
|
|
249
249
|
t,
|
|
250
250
|
!0,
|
|
251
|
-
|
|
252
|
-
|
|
251
|
+
n ? Error("react-stack-top-frame") : Y,
|
|
252
|
+
n ? w(l(e)) : D
|
|
253
253
|
);
|
|
254
254
|
};
|
|
255
255
|
})()), R;
|
|
256
256
|
}
|
|
257
257
|
var M;
|
|
258
258
|
function se() {
|
|
259
|
-
return M || (M = 1, process.env.NODE_ENV === "production" ?
|
|
259
|
+
return M || (M = 1, process.env.NODE_ENV === "production" ? b.exports = ae() : b.exports = ie()), b.exports;
|
|
260
260
|
}
|
|
261
261
|
var V = se();
|
|
262
|
-
const le = ({ children: i }) => /* @__PURE__ */ V.jsx(V.Fragment, { children: i }),
|
|
262
|
+
const le = ({ children: i }) => /* @__PURE__ */ V.jsx(V.Fragment, { children: i }), O = {
|
|
263
263
|
INVALID_CHILDREN_TYPE: "SuperSwitch only accepts <Option /> as children. Received an invalid child instead.",
|
|
264
264
|
MISSING_PRIORITIES: 'SuperSwitch is running in "priority" mode, but not all <Option /> elements define a priority. When using priority mode, every <Option /> must specify a numeric "priority" prop.',
|
|
265
265
|
NO_OPTION_TO_RENDER: "SuperSwitch could not determine which option to render. No <Option /> had a truthy condition, and no default option was provided.",
|
|
266
266
|
INVALID_OPTION_PROPS: 'Invalid <Option />: "default" and "condition" cannot be used together. Use "default" for the fallback option, or "condition" for conditional options.'
|
|
267
|
-
}, ue = (i) => i.sort((
|
|
268
|
-
const l =
|
|
269
|
-
return l === void 0 &&
|
|
270
|
-
}), fe = ({ children: i, mode:
|
|
271
|
-
const [
|
|
267
|
+
}, ue = (i) => i.sort((f, c) => {
|
|
268
|
+
const l = f.props?.priority, a = c.props?.priority;
|
|
269
|
+
return l === void 0 && a === void 0 ? 0 : l === void 0 ? 1 : a === void 0 || l < a ? -1 : l > a ? 1 : 0;
|
|
270
|
+
}), fe = ({ children: i, mode: f = "fcfs", optional: c = !1 }) => {
|
|
271
|
+
const [l, a] = te(null);
|
|
272
272
|
return ne(() => {
|
|
273
|
-
const
|
|
274
|
-
let
|
|
273
|
+
const s = [];
|
|
274
|
+
let p = !0;
|
|
275
275
|
oe.forEach(i, (u) => {
|
|
276
276
|
if (!(u?.type === le))
|
|
277
|
-
throw new Error(
|
|
277
|
+
throw new Error(O.INVALID_CHILDREN_TYPE);
|
|
278
278
|
if (u.props.default && "condition" in u.props)
|
|
279
|
-
throw new Error(
|
|
280
|
-
|
|
279
|
+
throw new Error(O.INVALID_OPTION_PROPS);
|
|
280
|
+
s.push(u), u.props.priority === void 0 && (p = !1);
|
|
281
281
|
});
|
|
282
|
-
let d =
|
|
283
|
-
if (
|
|
284
|
-
if (!
|
|
285
|
-
throw new Error(
|
|
286
|
-
d = ue(
|
|
282
|
+
let d = s;
|
|
283
|
+
if (f === "priority") {
|
|
284
|
+
if (!p)
|
|
285
|
+
throw new Error(O.MISSING_PRIORITIES);
|
|
286
|
+
d = ue(s);
|
|
287
287
|
}
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
288
|
+
const m = d.find((u) => !!u.props.condition && !u.props.default) ?? d.find((u) => !!u.props.default);
|
|
289
|
+
if (m)
|
|
290
|
+
a(m);
|
|
291
|
+
else if (!c)
|
|
292
|
+
throw new Error(O.NO_OPTION_TO_RENDER);
|
|
293
|
+
}, [i, f, c]), l;
|
|
293
294
|
};
|
|
294
295
|
export {
|
|
295
296
|
le as Option,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-super-switch",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deterministic conditional rendering for React. Render exactly one option from multiple independent conditions, with explicit priority and fail-fast guarantees.",
|
|
6
6
|
"author": {
|