react-super-switch 1.0.3
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/LICENSE +21 -0
- package/README.md +334 -0
- package/dist/components/Option/Option.d.ts +10 -0
- package/dist/components/Option/Option.d.ts.map +1 -0
- package/dist/components/Option/index.d.ts +4 -0
- package/dist/components/Option/index.d.ts.map +1 -0
- package/dist/components/SuperSwitch/SuperSwitch.d.ts +10 -0
- package/dist/components/SuperSwitch/SuperSwitch.d.ts.map +1 -0
- package/dist/components/SuperSwitch/constants.d.ts +2 -0
- package/dist/components/SuperSwitch/constants.d.ts.map +1 -0
- package/dist/components/SuperSwitch/index.d.ts +4 -0
- package/dist/components/SuperSwitch/index.d.ts.map +1 -0
- package/dist/components/SuperSwitch/types.d.ts +4 -0
- package/dist/components/SuperSwitch/types.d.ts.map +1 -0
- package/dist/components/SuperSwitch/utils.d.ts +3 -0
- package/dist/components/SuperSwitch/utils.d.ts.map +1 -0
- package/dist/index.cjs.js +6 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +289 -0
- package/package.json +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Dimitris Damilos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# React Super Switch
|
|
2
|
+
|
|
3
|
+
A small React utility component for **deterministic, readable, and safe conditional rendering**.
|
|
4
|
+
|
|
5
|
+
`react-super-switch` guarantees that **exactly one** view is rendered from a set of mutually exclusive options, even when conditions are complex, unrelated, or derived from business logic.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Why React Super Switch exists
|
|
10
|
+
|
|
11
|
+
Conditional rendering in React often starts simple and slowly becomes hard to reason about.
|
|
12
|
+
|
|
13
|
+
### The common problem
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
{caseA && <ViewA />}
|
|
19
|
+
{caseB && <ViewB />}
|
|
20
|
+
{caseC && <ViewC />}
|
|
21
|
+
{caseD && <ViewD />}
|
|
22
|
+
</>
|
|
23
|
+
);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
This pattern has several issues:
|
|
27
|
+
|
|
28
|
+
- Multiple views can accidentally render at the same time
|
|
29
|
+
- Ordering and priority are implicit and fragile
|
|
30
|
+
- Negating conditions quickly becomes unreadable
|
|
31
|
+
- Refactors are risky and hard to review
|
|
32
|
+
- React Fragments are often required just to make JSX valid
|
|
33
|
+
- React does not support `switch` or `if / else` directly in JSX
|
|
34
|
+
|
|
35
|
+
As business logic grows, correctness and readability degrade fast.
|
|
36
|
+
|
|
37
|
+
## The solution
|
|
38
|
+
|
|
39
|
+
`React Super Switch` introduces a declarative, safe alternative:
|
|
40
|
+
|
|
41
|
+
- Exactly one option is rendered
|
|
42
|
+
- Conditions are clearly scoped
|
|
43
|
+
- Priority is explicit (optional)
|
|
44
|
+
- A default fallback can be defined
|
|
45
|
+
|
|
46
|
+
Invalid configurations fail loudly during development
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install react-super-switch
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Requirements
|
|
55
|
+
|
|
56
|
+
- React 17 or newer
|
|
57
|
+
- `react` and `react-dom` are peer dependencies
|
|
58
|
+
- No runtime Node.js requirement for consumers
|
|
59
|
+
|
|
60
|
+
## Basic usage
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { SuperSwitch, Option } from "react-super-switch";
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
> The package exposes named exports only.
|
|
67
|
+
|
|
68
|
+
## Example
|
|
69
|
+
|
|
70
|
+
### Before
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
return (
|
|
74
|
+
<>
|
|
75
|
+
{businessCaseA && <ViewA />}
|
|
76
|
+
{businessCaseB && <ViewB />}
|
|
77
|
+
{businessCaseC && <ViewC />}
|
|
78
|
+
{businessCaseD && <ViewD />}
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### After
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
return (
|
|
87
|
+
<SuperSwitch>
|
|
88
|
+
<Option condition={businessCaseA}>
|
|
89
|
+
<ViewA />
|
|
90
|
+
</Option>
|
|
91
|
+
|
|
92
|
+
<Option condition={businessCaseB}>
|
|
93
|
+
<ViewB />
|
|
94
|
+
</Option>
|
|
95
|
+
|
|
96
|
+
<Option condition={businessCaseC} default>
|
|
97
|
+
<ViewC />
|
|
98
|
+
</Option>
|
|
99
|
+
|
|
100
|
+
<Option condition={businessCaseD}>
|
|
101
|
+
<ViewD />
|
|
102
|
+
</Option>
|
|
103
|
+
</SuperSwitch>
|
|
104
|
+
);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Only one** `<Option />` will ever render.
|
|
108
|
+
|
|
109
|
+
## Core concepts
|
|
110
|
+
|
|
111
|
+
### `<SuperSwitch />`
|
|
112
|
+
|
|
113
|
+
The parent component that evaluates all `<Option />` children and decides which one to render.
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
<SuperSwitch mode="fcfs | priority">{options}</SuperSwitch>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
| Prop | Type | Default | Description |
|
|
120
|
+
| ------ | ------------------------ | -------- | ------------------------------------ |
|
|
121
|
+
| `mode` | `"fcfs"` or `"priority"` | `"fcfs"` | Determines how options are evaluated |
|
|
122
|
+
|
|
123
|
+
### `<Option />`
|
|
124
|
+
|
|
125
|
+
Represents a single renderable branch.
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
<Option condition={boolean} priority={number} default>
|
|
129
|
+
{children}
|
|
130
|
+
</Option>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
| Prop | Type | Required | Description |
|
|
134
|
+
| ------------- | ----------- | -------- | ---------------------------------------- |
|
|
135
|
+
| `condition` | `boolean` | ❌ | Whether this option is eligible |
|
|
136
|
+
| `priority` | `number` | ❌ | Ordering hint (lower = higher priority) |
|
|
137
|
+
| `data-testid` | `string` | ❌ | A unique identifier for testing purposes |
|
|
138
|
+
| `default` | `boolean` | ❌ | Fallback option if no conditions match |
|
|
139
|
+
| `children` | `ReactNode` | ✅ | Rendered when this option is selected |
|
|
140
|
+
|
|
141
|
+
### Evaluation modes
|
|
142
|
+
|
|
143
|
+
#### 1. `fcfs` (First-Come-First-Served) — default
|
|
144
|
+
|
|
145
|
+
Options are evaluated in JSX order.
|
|
146
|
+
|
|
147
|
+
- The first option with a truthy condition wins
|
|
148
|
+
- If no conditions match, the first default option is rendered
|
|
149
|
+
- priority is ignored
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
<SuperSwitch>
|
|
153
|
+
<Option condition={a}>
|
|
154
|
+
<A />
|
|
155
|
+
</Option>
|
|
156
|
+
<Option condition={b}>
|
|
157
|
+
<B />
|
|
158
|
+
</Option>
|
|
159
|
+
<Option default>
|
|
160
|
+
<Fallback />
|
|
161
|
+
</Option>
|
|
162
|
+
</SuperSwitch>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Use this mode when **visual order already represents priority**.
|
|
166
|
+
|
|
167
|
+
#### 2. `priority`
|
|
168
|
+
|
|
169
|
+
Options are evaluated by explicit priority.
|
|
170
|
+
|
|
171
|
+
- All `<Option />` elements must define `priority`
|
|
172
|
+
- Lower numbers mean higher priority (`1` beats `2`)
|
|
173
|
+
- Order in JSX does not matter
|
|
174
|
+
- Default options are still supported
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
<SuperSwitch mode="priority">
|
|
178
|
+
<Option condition={a} priority={2}>
|
|
179
|
+
<A />
|
|
180
|
+
</Option>
|
|
181
|
+
<Option condition={b} priority={1}>
|
|
182
|
+
<B />
|
|
183
|
+
</Option>
|
|
184
|
+
<Option default priority={99}>
|
|
185
|
+
<Fallback />
|
|
186
|
+
</Option>
|
|
187
|
+
</SuperSwitch>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Use this mode when:
|
|
191
|
+
|
|
192
|
+
- Business rules are complex
|
|
193
|
+
- Priority changes frequently
|
|
194
|
+
- You want cleaner diffs and safer refactors
|
|
195
|
+
|
|
196
|
+
### Default option behaviour
|
|
197
|
+
|
|
198
|
+
- At most one option is rendered
|
|
199
|
+
- If no conditions match:
|
|
200
|
+
- the first default option is rendered
|
|
201
|
+
- If no default exists, an error is thrown
|
|
202
|
+
|
|
203
|
+
## Runtime validation (development safety)
|
|
204
|
+
|
|
205
|
+
### Invalid children
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
<SuperSwitch>
|
|
209
|
+
<div /> {/* ❌ not allowed */}
|
|
210
|
+
</SuperSwitch>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Missing default
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
<SuperSwitch>
|
|
217
|
+
<Option condition={false}>
|
|
218
|
+
<A />
|
|
219
|
+
</Option>
|
|
220
|
+
</SuperSwitch>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Invalid priority usage
|
|
224
|
+
|
|
225
|
+
```tsx
|
|
226
|
+
<SuperSwitch mode="priority">
|
|
227
|
+
<Option condition={a} priority={1}>
|
|
228
|
+
<A />
|
|
229
|
+
</Option>
|
|
230
|
+
<Option condition={b}>
|
|
231
|
+
<B />
|
|
232
|
+
</Option>{" "}
|
|
233
|
+
{/* ❌ missing priority */}
|
|
234
|
+
</SuperSwitch>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## When should you use this library?
|
|
238
|
+
|
|
239
|
+
- When rendering logic depends on multiple independent conditions
|
|
240
|
+
- When only one view must ever render
|
|
241
|
+
- When priority must be explicit and reviewable
|
|
242
|
+
- When you want fail-fast behaviour instead of silent bugs
|
|
243
|
+
|
|
244
|
+
### When not to use it
|
|
245
|
+
|
|
246
|
+
- Simple ternaries
|
|
247
|
+
- Binary conditions (`if / else`)
|
|
248
|
+
- List rendering (map)
|
|
249
|
+
|
|
250
|
+
## Comparison with existing libraries
|
|
251
|
+
|
|
252
|
+
There are a few existing React libraries that aim to improve conditional rendering.
|
|
253
|
+
They are useful in certain scenarios, but they solve a **different class of problems**
|
|
254
|
+
than `react-super-switch`.
|
|
255
|
+
|
|
256
|
+
The goal of this library is **deterministic, exclusive rendering** with explicit
|
|
257
|
+
prioritisation and fail-fast guarantees.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
### `react-switch`
|
|
262
|
+
|
|
263
|
+
`react-switch` provides a JSX-friendly abstraction similar to a `switch / case`
|
|
264
|
+
statement.
|
|
265
|
+
|
|
266
|
+
**What it’s good at:**
|
|
267
|
+
|
|
268
|
+
- Cleaner syntax than inline `&&` expressions
|
|
269
|
+
- Familiar `switch`-like mental model
|
|
270
|
+
|
|
271
|
+
**Limitations:**
|
|
272
|
+
|
|
273
|
+
- Multiple cases can render at the same time
|
|
274
|
+
- No priority or ordering guarantees
|
|
275
|
+
- No enforced default or fallback
|
|
276
|
+
- No runtime validation
|
|
277
|
+
|
|
278
|
+
`react-switch` assumes conditions are mutually exclusive, but does not enforce that
|
|
279
|
+
assumption.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
### `react-if`
|
|
284
|
+
|
|
285
|
+
`react-if` models imperative `if / else if / else` logic in JSX.
|
|
286
|
+
|
|
287
|
+
**What it’s good at:**
|
|
288
|
+
|
|
289
|
+
- Simple, linear conditional flows
|
|
290
|
+
- Readable for small, sequential branches
|
|
291
|
+
|
|
292
|
+
**Limitations:**
|
|
293
|
+
|
|
294
|
+
- Conditions must be logically chained
|
|
295
|
+
- No concept of independent business rules
|
|
296
|
+
- No priority system
|
|
297
|
+
- Does not guarantee that only one branch renders
|
|
298
|
+
|
|
299
|
+
This approach works well for simple control flow, but becomes hard to maintain when
|
|
300
|
+
conditions are unrelated or derived from complex business logic.
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
### `react-if-vz`
|
|
305
|
+
|
|
306
|
+
`react-if-vz` is conceptually closer to `react-super-switch` and attempts to introduce
|
|
307
|
+
more structured conditional rendering.
|
|
308
|
+
|
|
309
|
+
**Limitations:**
|
|
310
|
+
|
|
311
|
+
- Largely unmaintained
|
|
312
|
+
- Weak TypeScript support
|
|
313
|
+
- No enforced exclusivity
|
|
314
|
+
- Priority is implicit rather than guaranteed
|
|
315
|
+
- No fail-fast validation
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
### Why `react-super-switch` exists
|
|
320
|
+
|
|
321
|
+
`react-super-switch` focuses on **correctness and intent**, not just syntax:
|
|
322
|
+
|
|
323
|
+
- Exactly **one** option is rendered, or an error is thrown
|
|
324
|
+
- Priority is a **first-class concept**
|
|
325
|
+
- Default behaviour is explicit and enforced
|
|
326
|
+
- Invalid configurations fail loudly during development
|
|
327
|
+
- JSX remains clean and declarative
|
|
328
|
+
|
|
329
|
+
If your rendering logic depends on **multiple independent conditions** and only one
|
|
330
|
+
view must ever render, `react-super-switch` is designed specifically for that use case.
|
|
331
|
+
|
|
332
|
+
## License
|
|
333
|
+
|
|
334
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
export type OptionProps = {
|
|
3
|
+
condition?: boolean;
|
|
4
|
+
"data-testid"?: string;
|
|
5
|
+
default?: boolean;
|
|
6
|
+
priority?: number;
|
|
7
|
+
};
|
|
8
|
+
declare const Option: ({ children }: PropsWithChildren<OptionProps>) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default Option;
|
|
10
|
+
//# sourceMappingURL=Option.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Option.d.ts","sourceRoot":"","sources":["../../../src/components/Option/Option.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,QAAA,MAAM,MAAM,GAAI,cAAc,iBAAiB,CAAC,WAAW,CAAC,4CAAoB,CAAC;AAEjF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Option/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { OptionProps } from "../Option";
|
|
3
|
+
import type { OptionChild } from "./types";
|
|
4
|
+
export type SuperSwitchProps = {
|
|
5
|
+
children: ReactElement<OptionProps> | ReactElement<OptionProps>[];
|
|
6
|
+
mode?: "priority" | "fcfs";
|
|
7
|
+
};
|
|
8
|
+
declare const SuperSwitch: ({ children, mode }: SuperSwitchProps) => OptionChild | null;
|
|
9
|
+
export default SuperSwitch;
|
|
10
|
+
//# sourceMappingURL=SuperSwitch.d.ts.map
|
|
@@ -0,0 +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;CAC5B,CAAC;AAEF,QAAA,MAAM,WAAW,GAAI,oBAA6B,gBAAgB,uBA2CjE,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/components/SuperSwitch/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAIjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SuperSwitch/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/SuperSwitch/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/SuperSwitch/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,cAAc,GAAI,SAAS,WAAW,EAAE,kBAiBjD,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("react");var b={exports:{}},_={};var L;function ne(){if(L)return _;L=1;var i=Symbol.for("react.transitional.element"),l=Symbol.for("react.fragment");function f(u,n,s){var d=null;if(s!==void 0&&(d=""+s),n.key!==void 0&&(d=""+n.key),"key"in n){s={};for(var p in n)p!=="key"&&(s[p]=n[p])}else s=n;return n=s.ref,{$$typeof:i,type:u,key:d,ref:n!==void 0?n:null,props:s}}return _.Fragment=l,_.jsx=f,_.jsxs=f,_}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 h: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 H:return e.displayName||"Context";case z:return(e._context.displayName||"Context")+".Consumer";case B: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 P:r=e._payload,e=e._init;try{return i(e(r))}catch{}}return null}function l(e){return""+e}function f(e){try{l(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,o=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.",o),l(e)}}function u(e){if(e===h)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===P)return"<...>";try{var r=i(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function n(){var e=w.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function d(e){if(I.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function p(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 c(e,r,t,o,T,A){var a=t.ref;return e={$$typeof:x,type:e,key:r,props:t,_owner:o},(a!==void 0?a: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:A}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function S(e,r,t,o,T,A){var a=r.children;if(a!==void 0)if(o)if(re(a)){for(o=0;o<a.length;o++)y(a[o]);Object.freeze&&Object.freeze(a)}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 y(a);if(I.call(r,"key")){a=i(e);var E=Object.keys(r).filter(function(te){return te!=="key"});o=0<E.length?"{key: someKey, "+E.join(": ..., ")+": ...}":"{key: someKey}",F[a+o]||(E=0<E.length?"{"+E.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,o,a,E,a),F[a+o]=!0)}if(a=null,t!==void 0&&(f(t),a=""+t),d(r)&&(f(r.key),a=""+r.key),"key"in r){t={};for(var N in r)N!=="key"&&(t[N]=r[N])}else t=r;return a&&p(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),c(e,a,t,n(),T,A)}function y(e){j(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===P&&(e._payload.status==="fulfilled"?j(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function j(e){return typeof e=="object"&&e!==null&&e.$$typeof===x}var v=O,x=Symbol.for("react.transitional.element"),q=Symbol.for("react.portal"),h=Symbol.for("react.fragment"),G=Symbol.for("react.strict_mode"),J=Symbol.for("react.profiler"),z=Symbol.for("react.consumer"),H=Symbol.for("react.context"),B=Symbol.for("react.forward_ref"),X=Symbol.for("react.suspense"),Z=Symbol.for("react.suspense_list"),Q=Symbol.for("react.memo"),P=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,I=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)(),$=k(u(s)),F={};R.Fragment=h,R.jsx=function(e,r,t){var o=1e4>w.recentlyCreatedOwnerStacks++;return S(e,r,t,!1,o?Error("react-stack-top-frame"):D,o?k(u(e)):$)},R.jsxs=function(e,r,t){var o=1e4>w.recentlyCreatedOwnerStacks++;return S(e,r,t,!0,o?Error("react-stack-top-frame"):D,o?k(u(e)):$)}})()),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}),g={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."},ie=i=>i.sort((l,f)=>{const u=l.props?.priority,n=f.props?.priority;return u===void 0&&n===void 0?0:u===void 0?1:n===void 0||u<n?-1:u>n?1:0}),se=({children:i,mode:l="fcfs"})=>{const[f,u]=O.useState(null);return O.useEffect(()=>{const n=[];let s=!1,d=!0;if(O.Children.forEach(i,c=>{if(!(c?.type===U))throw new Error(g.INVALID_CHILDREN_TYPE);n.push(c),c.props.priority!==void 0?s=!0:d=!1}),l==="priority"&&s&&!d)throw new Error(g.MISSING_PRIORITIES);const p=l==="priority"?ie(n):n,m=p.find(c=>!!c.props.condition&&!c.props.default)??p.find(c=>!!c.props.default);if(!m)throw new Error(g.NO_OPTION_TO_RENDER);u(m)},[i,l]),f};exports.Option=U;exports.SuperSwitch=se;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACzF,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import re, { useState as te, useEffect as ne, Children as oe } from "react";
|
|
2
|
+
var b = { exports: {} }, _ = {};
|
|
3
|
+
var F;
|
|
4
|
+
function ae() {
|
|
5
|
+
if (F) return _;
|
|
6
|
+
F = 1;
|
|
7
|
+
var i = /* @__PURE__ */ Symbol.for("react.transitional.element"), u = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
8
|
+
function f(l, n, s) {
|
|
9
|
+
var d = null;
|
|
10
|
+
if (s !== void 0 && (d = "" + s), n.key !== void 0 && (d = "" + n.key), "key" in n) {
|
|
11
|
+
s = {};
|
|
12
|
+
for (var p in n)
|
|
13
|
+
p !== "key" && (s[p] = n[p]);
|
|
14
|
+
} else s = n;
|
|
15
|
+
return n = s.ref, {
|
|
16
|
+
$$typeof: i,
|
|
17
|
+
type: l,
|
|
18
|
+
key: d,
|
|
19
|
+
ref: n !== void 0 ? n : null,
|
|
20
|
+
props: s
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return _.Fragment = u, _.jsx = f, _.jsxs = f, _;
|
|
24
|
+
}
|
|
25
|
+
var m = {};
|
|
26
|
+
var L;
|
|
27
|
+
function ie() {
|
|
28
|
+
return L || (L = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
29
|
+
function i(e) {
|
|
30
|
+
if (e == null) return null;
|
|
31
|
+
if (typeof e == "function")
|
|
32
|
+
return e.$$typeof === Q ? null : e.displayName || e.name || null;
|
|
33
|
+
if (typeof e == "string") return e;
|
|
34
|
+
switch (e) {
|
|
35
|
+
case S:
|
|
36
|
+
return "Fragment";
|
|
37
|
+
case G:
|
|
38
|
+
return "Profiler";
|
|
39
|
+
case U:
|
|
40
|
+
return "StrictMode";
|
|
41
|
+
case H:
|
|
42
|
+
return "Suspense";
|
|
43
|
+
case B:
|
|
44
|
+
return "SuspenseList";
|
|
45
|
+
case Z:
|
|
46
|
+
return "Activity";
|
|
47
|
+
}
|
|
48
|
+
if (typeof e == "object")
|
|
49
|
+
switch (typeof e.tag == "number" && console.error(
|
|
50
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
51
|
+
), e.$$typeof) {
|
|
52
|
+
case W:
|
|
53
|
+
return "Portal";
|
|
54
|
+
case J:
|
|
55
|
+
return e.displayName || "Context";
|
|
56
|
+
case q:
|
|
57
|
+
return (e._context.displayName || "Context") + ".Consumer";
|
|
58
|
+
case z:
|
|
59
|
+
var r = e.render;
|
|
60
|
+
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
61
|
+
case X:
|
|
62
|
+
return r = e.displayName || null, r !== null ? r : i(e.type) || "Memo";
|
|
63
|
+
case h:
|
|
64
|
+
r = e._payload, e = e._init;
|
|
65
|
+
try {
|
|
66
|
+
return i(e(r));
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function u(e) {
|
|
73
|
+
return "" + e;
|
|
74
|
+
}
|
|
75
|
+
function f(e) {
|
|
76
|
+
try {
|
|
77
|
+
u(e);
|
|
78
|
+
var r = !1;
|
|
79
|
+
} catch {
|
|
80
|
+
r = !0;
|
|
81
|
+
}
|
|
82
|
+
if (r) {
|
|
83
|
+
r = console;
|
|
84
|
+
var t = r.error, o = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
85
|
+
return t.call(
|
|
86
|
+
r,
|
|
87
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
88
|
+
o
|
|
89
|
+
), u(e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function l(e) {
|
|
93
|
+
if (e === S) return "<>";
|
|
94
|
+
if (typeof e == "object" && e !== null && e.$$typeof === h)
|
|
95
|
+
return "<...>";
|
|
96
|
+
try {
|
|
97
|
+
var r = i(e);
|
|
98
|
+
return r ? "<" + r + ">" : "<...>";
|
|
99
|
+
} catch {
|
|
100
|
+
return "<...>";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function n() {
|
|
104
|
+
var e = P.A;
|
|
105
|
+
return e === null ? null : e.getOwner();
|
|
106
|
+
}
|
|
107
|
+
function s() {
|
|
108
|
+
return Error("react-stack-top-frame");
|
|
109
|
+
}
|
|
110
|
+
function d(e) {
|
|
111
|
+
if (j.call(e, "key")) {
|
|
112
|
+
var r = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
113
|
+
if (r && r.isReactWarning) return !1;
|
|
114
|
+
}
|
|
115
|
+
return e.key !== void 0;
|
|
116
|
+
}
|
|
117
|
+
function p(e, r) {
|
|
118
|
+
function t() {
|
|
119
|
+
I || (I = !0, console.error(
|
|
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)",
|
|
121
|
+
r
|
|
122
|
+
));
|
|
123
|
+
}
|
|
124
|
+
t.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
125
|
+
get: t,
|
|
126
|
+
configurable: !0
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function R() {
|
|
130
|
+
var e = i(this.type);
|
|
131
|
+
return C[e] || (C[e] = !0, console.error(
|
|
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
|
+
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
134
|
+
}
|
|
135
|
+
function c(e, r, t, o, T, k) {
|
|
136
|
+
var a = t.ref;
|
|
137
|
+
return e = {
|
|
138
|
+
$$typeof: x,
|
|
139
|
+
type: e,
|
|
140
|
+
key: r,
|
|
141
|
+
props: t,
|
|
142
|
+
_owner: o
|
|
143
|
+
}, (a !== void 0 ? a : null) !== null ? Object.defineProperty(e, "ref", {
|
|
144
|
+
enumerable: !1,
|
|
145
|
+
get: R
|
|
146
|
+
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
147
|
+
configurable: !1,
|
|
148
|
+
enumerable: !1,
|
|
149
|
+
writable: !0,
|
|
150
|
+
value: 0
|
|
151
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
152
|
+
configurable: !1,
|
|
153
|
+
enumerable: !1,
|
|
154
|
+
writable: !0,
|
|
155
|
+
value: null
|
|
156
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
157
|
+
configurable: !1,
|
|
158
|
+
enumerable: !1,
|
|
159
|
+
writable: !0,
|
|
160
|
+
value: T
|
|
161
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
162
|
+
configurable: !1,
|
|
163
|
+
enumerable: !1,
|
|
164
|
+
writable: !0,
|
|
165
|
+
value: k
|
|
166
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
167
|
+
}
|
|
168
|
+
function O(e, r, t, o, T, k) {
|
|
169
|
+
var a = r.children;
|
|
170
|
+
if (a !== void 0)
|
|
171
|
+
if (o)
|
|
172
|
+
if (K(a)) {
|
|
173
|
+
for (o = 0; o < a.length; o++)
|
|
174
|
+
y(a[o]);
|
|
175
|
+
Object.freeze && Object.freeze(a);
|
|
176
|
+
} else
|
|
177
|
+
console.error(
|
|
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
|
+
);
|
|
180
|
+
else y(a);
|
|
181
|
+
if (j.call(r, "key")) {
|
|
182
|
+
a = i(e);
|
|
183
|
+
var E = Object.keys(r).filter(function(ee) {
|
|
184
|
+
return ee !== "key";
|
|
185
|
+
});
|
|
186
|
+
o = 0 < E.length ? "{key: someKey, " + E.join(": ..., ") + ": ...}" : "{key: someKey}", $[a + o] || (E = 0 < E.length ? "{" + E.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
187
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
188
|
+
let props = %s;
|
|
189
|
+
<%s {...props} />
|
|
190
|
+
React keys must be passed directly to JSX without using spread:
|
|
191
|
+
let props = %s;
|
|
192
|
+
<%s key={someKey} {...props} />`,
|
|
193
|
+
o,
|
|
194
|
+
a,
|
|
195
|
+
E,
|
|
196
|
+
a
|
|
197
|
+
), $[a + o] = !0);
|
|
198
|
+
}
|
|
199
|
+
if (a = null, t !== void 0 && (f(t), a = "" + t), d(r) && (f(r.key), a = "" + r.key), "key" in r) {
|
|
200
|
+
t = {};
|
|
201
|
+
for (var A in r)
|
|
202
|
+
A !== "key" && (t[A] = r[A]);
|
|
203
|
+
} else t = r;
|
|
204
|
+
return a && p(
|
|
205
|
+
t,
|
|
206
|
+
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
207
|
+
), c(
|
|
208
|
+
e,
|
|
209
|
+
a,
|
|
210
|
+
t,
|
|
211
|
+
n(),
|
|
212
|
+
T,
|
|
213
|
+
k
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function y(e) {
|
|
217
|
+
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));
|
|
218
|
+
}
|
|
219
|
+
function g(e) {
|
|
220
|
+
return typeof e == "object" && e !== null && e.$$typeof === x;
|
|
221
|
+
}
|
|
222
|
+
var v = re, x = /* @__PURE__ */ Symbol.for("react.transitional.element"), W = /* @__PURE__ */ Symbol.for("react.portal"), S = /* @__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"), H = /* @__PURE__ */ Symbol.for("react.suspense"), B = /* @__PURE__ */ Symbol.for("react.suspense_list"), X = /* @__PURE__ */ Symbol.for("react.memo"), h = /* @__PURE__ */ Symbol.for("react.lazy"), Z = /* @__PURE__ */ Symbol.for("react.activity"), Q = /* @__PURE__ */ Symbol.for("react.client.reference"), P = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, K = Array.isArray, w = console.createTask ? console.createTask : function() {
|
|
223
|
+
return null;
|
|
224
|
+
};
|
|
225
|
+
v = {
|
|
226
|
+
react_stack_bottom_frame: function(e) {
|
|
227
|
+
return e();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var I, C = {}, Y = v.react_stack_bottom_frame.bind(
|
|
231
|
+
v,
|
|
232
|
+
s
|
|
233
|
+
)(), D = w(l(s)), $ = {};
|
|
234
|
+
m.Fragment = S, m.jsx = function(e, r, t) {
|
|
235
|
+
var o = 1e4 > P.recentlyCreatedOwnerStacks++;
|
|
236
|
+
return O(
|
|
237
|
+
e,
|
|
238
|
+
r,
|
|
239
|
+
t,
|
|
240
|
+
!1,
|
|
241
|
+
o ? Error("react-stack-top-frame") : Y,
|
|
242
|
+
o ? w(l(e)) : D
|
|
243
|
+
);
|
|
244
|
+
}, m.jsxs = function(e, r, t) {
|
|
245
|
+
var o = 1e4 > P.recentlyCreatedOwnerStacks++;
|
|
246
|
+
return O(
|
|
247
|
+
e,
|
|
248
|
+
r,
|
|
249
|
+
t,
|
|
250
|
+
!0,
|
|
251
|
+
o ? Error("react-stack-top-frame") : Y,
|
|
252
|
+
o ? w(l(e)) : D
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
})()), m;
|
|
256
|
+
}
|
|
257
|
+
var M;
|
|
258
|
+
function se() {
|
|
259
|
+
return M || (M = 1, process.env.NODE_ENV === "production" ? b.exports = ae() : b.exports = ie()), b.exports;
|
|
260
|
+
}
|
|
261
|
+
var V = se();
|
|
262
|
+
const le = ({ children: i }) => /* @__PURE__ */ V.jsx(V.Fragment, { children: i }), N = {
|
|
263
|
+
INVALID_CHILDREN_TYPE: "SuperSwitch only accepts <Option /> as children. Received an invalid child instead.",
|
|
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
|
+
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
|
+
}, ue = (i) => i.sort((u, f) => {
|
|
267
|
+
const l = u.props?.priority, n = f.props?.priority;
|
|
268
|
+
return l === void 0 && n === void 0 ? 0 : l === void 0 ? 1 : n === void 0 || l < n ? -1 : l > n ? 1 : 0;
|
|
269
|
+
}), fe = ({ children: i, mode: u = "fcfs" }) => {
|
|
270
|
+
const [f, l] = te(null);
|
|
271
|
+
return ne(() => {
|
|
272
|
+
const n = [];
|
|
273
|
+
let s = !1, d = !0;
|
|
274
|
+
if (oe.forEach(i, (c) => {
|
|
275
|
+
if (!(c?.type === le))
|
|
276
|
+
throw new Error(N.INVALID_CHILDREN_TYPE);
|
|
277
|
+
n.push(c), c.props.priority !== void 0 ? s = !0 : d = !1;
|
|
278
|
+
}), u === "priority" && s && !d)
|
|
279
|
+
throw new Error(N.MISSING_PRIORITIES);
|
|
280
|
+
const p = u === "priority" ? ue(n) : n, R = p.find((c) => !!c.props.condition && !c.props.default) ?? p.find((c) => !!c.props.default);
|
|
281
|
+
if (!R)
|
|
282
|
+
throw new Error(N.NO_OPTION_TO_RENDER);
|
|
283
|
+
l(R);
|
|
284
|
+
}, [i, u]), f;
|
|
285
|
+
};
|
|
286
|
+
export {
|
|
287
|
+
le as Option,
|
|
288
|
+
fe as SuperSwitch
|
|
289
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-super-switch",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Deterministic conditional rendering for React. Render exactly one option from multiple independent conditions, with explicit priority and fail-fast guarantees.",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Dimitris Damilos",
|
|
8
|
+
"url": "https://github.com/Jonur"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"homepage": "https://github.com/Jonur/react-super-switch#readme",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/Jonur/react-super-switch.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/Jonur/react-super-switch/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"react",
|
|
21
|
+
"react-component",
|
|
22
|
+
"conditional-rendering",
|
|
23
|
+
"switch",
|
|
24
|
+
"jsx",
|
|
25
|
+
"ui",
|
|
26
|
+
"frontend",
|
|
27
|
+
"business-logic",
|
|
28
|
+
"priority",
|
|
29
|
+
"deterministic"
|
|
30
|
+
],
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.esm.js",
|
|
38
|
+
"require": "./dist/index.cjs.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"main": "dist/index.cjs.js",
|
|
42
|
+
"module": "dist/index.esm.js",
|
|
43
|
+
"types": "dist/index.d.ts",
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc -p tsconfig.build.json && vite build",
|
|
47
|
+
"format": "prettier . --write",
|
|
48
|
+
"lint": "eslint .",
|
|
49
|
+
"lint:fix": "eslint . --fix",
|
|
50
|
+
"typecheck": "tsc -p .",
|
|
51
|
+
"test": "vitest",
|
|
52
|
+
"test:watch": "vitest --watch",
|
|
53
|
+
"test:coverage": "vitest run --coverage"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"react": ">=17.0.0",
|
|
57
|
+
"react-dom": ">=17.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@testing-library/dom": "^10.4.1",
|
|
61
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
62
|
+
"@testing-library/react": "^16.3.1",
|
|
63
|
+
"@types/eslint-plugin-jsx-a11y": "^6.10.1",
|
|
64
|
+
"@types/node": "^25.0.3",
|
|
65
|
+
"@types/react": "^19.2.7",
|
|
66
|
+
"@types/react-dom": "^19.2.3",
|
|
67
|
+
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
68
|
+
"@typescript-eslint/parser": "^8.50.1",
|
|
69
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
70
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
71
|
+
"eslint": "^9.39.2",
|
|
72
|
+
"eslint-config-prettier": "^10.1.8",
|
|
73
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
74
|
+
"eslint-plugin-import": "^2.32.0",
|
|
75
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
76
|
+
"eslint-plugin-react": "^7.37.5",
|
|
77
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
78
|
+
"eslint-plugin-unused-imports": "^4.3.0",
|
|
79
|
+
"jsdom": "^27.4.0",
|
|
80
|
+
"prettier": "^3.7.4",
|
|
81
|
+
"react": "^19.2.3",
|
|
82
|
+
"react-dom": "^19.2.3",
|
|
83
|
+
"typescript": "^5.9.3",
|
|
84
|
+
"vite": "^7.3.0",
|
|
85
|
+
"vitest": "^4.0.16"
|
|
86
|
+
}
|
|
87
|
+
}
|