solid-ctrl-flow 1.0.4 → 1.0.6

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.
@@ -125,4 +125,10 @@ export declare function When<T>(props: {
125
125
  children: (x: NonNullable<T>) => JSX.Element;
126
126
  }): JSX.Element;
127
127
 
128
+ /** Wraps an element with a div with the specified {@link JSX.CustomAttributes.classList} if at least one of them is `true` */
129
+ export declare function Wrapper(props: {
130
+ classList: Record<string, boolean | undefined>;
131
+ children: JSX.Element;
132
+ }): JSX.Element;
133
+
128
134
  export { }
package/dist/index.mjs ADDED
@@ -0,0 +1,377 @@
1
+ import { sharedConfig, createRenderEffect, untrack, createContext, createMemo, createComponent, useContext, Match, mergeProps, onCleanup, Show, splitProps } from "solid-js";
2
+ import { createMutable } from "solid-js/store";
3
+ function reconcileArrays(parentNode, a, b) {
4
+ let bLength = b.length, aEnd = a.length, bEnd = bLength, aStart = 0, bStart = 0, after = a[aEnd - 1].nextSibling, map = null;
5
+ while (aStart < aEnd || bStart < bEnd) {
6
+ if (a[aStart] === b[bStart]) {
7
+ aStart++;
8
+ bStart++;
9
+ continue;
10
+ }
11
+ while (a[aEnd - 1] === b[bEnd - 1]) {
12
+ aEnd--;
13
+ bEnd--;
14
+ }
15
+ if (aEnd === aStart) {
16
+ const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] : after;
17
+ while (bStart < bEnd)
18
+ parentNode.insertBefore(b[bStart++], node);
19
+ } else if (bEnd === bStart) {
20
+ while (aStart < aEnd) {
21
+ if (!map || !map.has(a[aStart]))
22
+ a[aStart].remove();
23
+ aStart++;
24
+ }
25
+ } else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
26
+ const node = a[--aEnd].nextSibling;
27
+ parentNode.insertBefore(b[bStart++], a[aStart++].nextSibling);
28
+ parentNode.insertBefore(b[--bEnd], node);
29
+ a[aEnd] = b[bEnd];
30
+ } else {
31
+ if (!map) {
32
+ map = /* @__PURE__ */ new Map();
33
+ let i = bStart;
34
+ while (i < bEnd)
35
+ map.set(b[i], i++);
36
+ }
37
+ const index = map.get(a[aStart]);
38
+ if (index != null) {
39
+ if (bStart < index && index < bEnd) {
40
+ let i = aStart, sequence = 1, t;
41
+ while (++i < aEnd && i < bEnd) {
42
+ if ((t = map.get(a[i])) == null || t !== index + sequence)
43
+ break;
44
+ sequence++;
45
+ }
46
+ if (sequence > index - bStart) {
47
+ const node = a[aStart];
48
+ while (bStart < index)
49
+ parentNode.insertBefore(b[bStart++], node);
50
+ } else
51
+ parentNode.replaceChild(b[bStart++], a[aStart++]);
52
+ } else
53
+ aStart++;
54
+ } else
55
+ a[aStart++].remove();
56
+ }
57
+ }
58
+ }
59
+ function template(html, isCE, isSVG) {
60
+ let node;
61
+ const create = () => {
62
+ const t = document.createElement("template");
63
+ t.innerHTML = html;
64
+ return isSVG ? t.content.firstChild.firstChild : t.content.firstChild;
65
+ };
66
+ const fn = isCE ? () => untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true);
67
+ fn.cloneNode = fn;
68
+ return fn;
69
+ }
70
+ function className(node, value) {
71
+ if (sharedConfig.context)
72
+ return;
73
+ if (value == null)
74
+ node.removeAttribute("class");
75
+ else
76
+ node.className = value;
77
+ }
78
+ function insert(parent, accessor, marker, initial) {
79
+ if (marker !== void 0 && !initial)
80
+ initial = [];
81
+ if (typeof accessor !== "function")
82
+ return insertExpression(parent, accessor, initial, marker);
83
+ createRenderEffect((current) => insertExpression(parent, accessor(), current, marker), initial);
84
+ }
85
+ function insertExpression(parent, value, current, marker, unwrapArray) {
86
+ if (sharedConfig.context) {
87
+ !current && (current = [...parent.childNodes]);
88
+ let cleaned = [];
89
+ for (let i = 0; i < current.length; i++) {
90
+ const node = current[i];
91
+ if (node.nodeType === 8 && node.data.slice(0, 2) === "!$")
92
+ node.remove();
93
+ else
94
+ cleaned.push(node);
95
+ }
96
+ current = cleaned;
97
+ }
98
+ while (typeof current === "function")
99
+ current = current();
100
+ if (value === current)
101
+ return current;
102
+ const t = typeof value, multi = marker !== void 0;
103
+ parent = multi && current[0] && current[0].parentNode || parent;
104
+ if (t === "string" || t === "number") {
105
+ if (sharedConfig.context)
106
+ return current;
107
+ if (t === "number")
108
+ value = value.toString();
109
+ if (multi) {
110
+ let node = current[0];
111
+ if (node && node.nodeType === 3) {
112
+ node.data = value;
113
+ } else
114
+ node = document.createTextNode(value);
115
+ current = cleanChildren(parent, current, marker, node);
116
+ } else {
117
+ if (current !== "" && typeof current === "string") {
118
+ current = parent.firstChild.data = value;
119
+ } else
120
+ current = parent.textContent = value;
121
+ }
122
+ } else if (value == null || t === "boolean") {
123
+ if (sharedConfig.context)
124
+ return current;
125
+ current = cleanChildren(parent, current, marker);
126
+ } else if (t === "function") {
127
+ createRenderEffect(() => {
128
+ let v = value();
129
+ while (typeof v === "function")
130
+ v = v();
131
+ current = insertExpression(parent, v, current, marker);
132
+ });
133
+ return () => current;
134
+ } else if (Array.isArray(value)) {
135
+ const array = [];
136
+ const currentArray = current && Array.isArray(current);
137
+ if (normalizeIncomingArray(array, value, current, unwrapArray)) {
138
+ createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
139
+ return () => current;
140
+ }
141
+ if (sharedConfig.context) {
142
+ if (!array.length)
143
+ return current;
144
+ if (marker === void 0)
145
+ return [...parent.childNodes];
146
+ let node = array[0];
147
+ let nodes = [node];
148
+ while ((node = node.nextSibling) !== marker)
149
+ nodes.push(node);
150
+ return current = nodes;
151
+ }
152
+ if (array.length === 0) {
153
+ current = cleanChildren(parent, current, marker);
154
+ if (multi)
155
+ return current;
156
+ } else if (currentArray) {
157
+ if (current.length === 0) {
158
+ appendNodes(parent, array, marker);
159
+ } else
160
+ reconcileArrays(parent, current, array);
161
+ } else {
162
+ current && cleanChildren(parent);
163
+ appendNodes(parent, array);
164
+ }
165
+ current = array;
166
+ } else if (value.nodeType) {
167
+ if (sharedConfig.context && value.parentNode)
168
+ return current = multi ? [value] : value;
169
+ if (Array.isArray(current)) {
170
+ if (multi)
171
+ return current = cleanChildren(parent, current, marker, value);
172
+ cleanChildren(parent, current, null, value);
173
+ } else if (current == null || current === "" || !parent.firstChild) {
174
+ parent.appendChild(value);
175
+ } else
176
+ parent.replaceChild(value, parent.firstChild);
177
+ current = value;
178
+ } else
179
+ ;
180
+ return current;
181
+ }
182
+ function normalizeIncomingArray(normalized, array, current, unwrap) {
183
+ let dynamic = false;
184
+ for (let i = 0, len = array.length; i < len; i++) {
185
+ let item = array[i], prev = current && current[i], t;
186
+ if (item == null || item === true || item === false)
187
+ ;
188
+ else if ((t = typeof item) === "object" && item.nodeType) {
189
+ normalized.push(item);
190
+ } else if (Array.isArray(item)) {
191
+ dynamic = normalizeIncomingArray(normalized, item, prev) || dynamic;
192
+ } else if (t === "function") {
193
+ if (unwrap) {
194
+ while (typeof item === "function")
195
+ item = item();
196
+ dynamic = normalizeIncomingArray(
197
+ normalized,
198
+ Array.isArray(item) ? item : [item],
199
+ Array.isArray(prev) ? prev : [prev]
200
+ ) || dynamic;
201
+ } else {
202
+ normalized.push(item);
203
+ dynamic = true;
204
+ }
205
+ } else {
206
+ const value = String(item);
207
+ if (prev && prev.nodeType === 3 && prev.data === value)
208
+ normalized.push(prev);
209
+ else
210
+ normalized.push(document.createTextNode(value));
211
+ }
212
+ }
213
+ return dynamic;
214
+ }
215
+ function appendNodes(parent, array, marker = null) {
216
+ for (let i = 0, len = array.length; i < len; i++)
217
+ parent.insertBefore(array[i], marker);
218
+ }
219
+ function cleanChildren(parent, current, marker, replacement) {
220
+ if (marker === void 0)
221
+ return parent.textContent = "";
222
+ const node = replacement || document.createTextNode("");
223
+ if (current.length) {
224
+ let inserted = false;
225
+ for (let i = current.length - 1; i >= 0; i--) {
226
+ const el = current[i];
227
+ if (node !== el) {
228
+ const isParent = el.parentNode === parent;
229
+ if (!inserted && !i)
230
+ isParent ? parent.replaceChild(node, el) : parent.insertBefore(node, marker);
231
+ else
232
+ isParent && el.remove();
233
+ } else
234
+ inserted = true;
235
+ }
236
+ } else
237
+ parent.insertBefore(node, marker);
238
+ return [node];
239
+ }
240
+ const ctx$1 = createContext(() => void 0, {
241
+ name: "case-when"
242
+ });
243
+ function Case(props) {
244
+ const memo = createMemo(() => props.value);
245
+ return createComponent(ctx$1.Provider, {
246
+ value: memo,
247
+ get children() {
248
+ return props.children;
249
+ }
250
+ });
251
+ }
252
+ function When(props) {
253
+ const [mine, other] = splitAndMemoProps(props, ["value", "pred"]);
254
+ const value = useContext(ctx$1);
255
+ const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
256
+ return createComponent(Match, mergeProps({
257
+ get when() {
258
+ return pred(value());
259
+ }
260
+ }, other));
261
+ }
262
+ const ctx = createContext(() => false, {
263
+ name: "debug-scope"
264
+ });
265
+ function Debug(props) {
266
+ return createComponent(ctx.Provider, {
267
+ value: () => props.value ?? true,
268
+ get children() {
269
+ return props.children;
270
+ }
271
+ });
272
+ }
273
+ (function(_Debug) {
274
+ Object.defineProperty(Debug, "isDebug", {
275
+ get: () => useContext(ctx)
276
+ });
277
+ })(Debug || (Debug = {}));
278
+ function createExtractor(name = "extractor") {
279
+ const ctx2 = createContext(void 0, {
280
+ name
281
+ });
282
+ return {
283
+ /** Bound {@link Dest} */
284
+ Dest: Dest.bind(ctx2),
285
+ /** Bound {@link Source} */
286
+ Source: Source.bind(ctx2),
287
+ /** Bound {@link Joint} */
288
+ Joint: Joint.bind(ctx2),
289
+ /**
290
+ * Gets an {@link Accessor} that tells if the context in which THIS getter has been executed has been extracted (Is inside of a {@link Dest})
291
+ * @returns Returns `null` if there is no parent {@link Joint}, the number of {@link Dest}s in which this component is being displayed otherwise (Usually 1)
292
+ */
293
+ get isExtracted() {
294
+ const obj = useContext(ctx2);
295
+ return () => obj?.attached ?? null;
296
+ }
297
+ };
298
+ }
299
+ function Dest() {
300
+ const obj = useContext(this);
301
+ if (!obj)
302
+ return;
303
+ obj.attached++;
304
+ onCleanup(() => obj.attached--);
305
+ return createMemo(() => obj.source);
306
+ }
307
+ function Source(props) {
308
+ const obj = useContext(this);
309
+ if (!obj)
310
+ return props.children;
311
+ if (obj.source)
312
+ throw new Error("An extractor can't have more than one source");
313
+ obj.source = () => props.children;
314
+ onCleanup(() => obj.source = void 0);
315
+ return createComponent(Show, {
316
+ get when() {
317
+ return !obj.attached;
318
+ },
319
+ get children() {
320
+ return obj.source();
321
+ }
322
+ });
323
+ }
324
+ function Joint(props) {
325
+ const {
326
+ Provider
327
+ } = this;
328
+ const obj = createMutable({
329
+ attached: 0
330
+ });
331
+ return createComponent(Provider, {
332
+ value: obj,
333
+ get children() {
334
+ return props.children;
335
+ }
336
+ });
337
+ }
338
+ const _tmpl$ = /* @__PURE__ */ template(`<div>`);
339
+ function Wrapper(props) {
340
+ const classList = createMemo(() => Object.entries(props.classList).filter((x) => x[1]).map((x) => x[0]));
341
+ const children = createMemo(() => props.children);
342
+ return createComponent(Show, {
343
+ get when() {
344
+ return classList().length;
345
+ },
346
+ get fallback() {
347
+ return children();
348
+ },
349
+ get children() {
350
+ const _el$ = _tmpl$();
351
+ insert(_el$, children);
352
+ createRenderEffect(() => className(_el$, classList().join(" ")));
353
+ return _el$;
354
+ }
355
+ });
356
+ }
357
+ function memoProps(obj, keys = Object.keys(obj)) {
358
+ const out = {};
359
+ for (const elm of keys)
360
+ Object.defineProperty(out, elm, {
361
+ get: createMemo(() => obj[elm])
362
+ });
363
+ return out;
364
+ }
365
+ function splitAndMemoProps(obj, keys) {
366
+ const [mine, other] = splitProps(obj, keys);
367
+ return [memoProps(mine, keys), other];
368
+ }
369
+ export {
370
+ Case,
371
+ Debug,
372
+ When,
373
+ Wrapper,
374
+ createExtractor,
375
+ memoProps,
376
+ splitAndMemoProps
377
+ };
@@ -0,0 +1,379 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("solid-js"), require("solid-js/store")) : typeof define === "function" && define.amd ? define(["exports", "solid-js", "solid-js/store"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.solidCtrlFlow = {}, global.solidJs, global.solidJsStore));
3
+ })(this, function(exports2, solidJs, store) {
4
+ "use strict";
5
+ function reconcileArrays(parentNode, a, b) {
6
+ let bLength = b.length, aEnd = a.length, bEnd = bLength, aStart = 0, bStart = 0, after = a[aEnd - 1].nextSibling, map = null;
7
+ while (aStart < aEnd || bStart < bEnd) {
8
+ if (a[aStart] === b[bStart]) {
9
+ aStart++;
10
+ bStart++;
11
+ continue;
12
+ }
13
+ while (a[aEnd - 1] === b[bEnd - 1]) {
14
+ aEnd--;
15
+ bEnd--;
16
+ }
17
+ if (aEnd === aStart) {
18
+ const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] : after;
19
+ while (bStart < bEnd)
20
+ parentNode.insertBefore(b[bStart++], node);
21
+ } else if (bEnd === bStart) {
22
+ while (aStart < aEnd) {
23
+ if (!map || !map.has(a[aStart]))
24
+ a[aStart].remove();
25
+ aStart++;
26
+ }
27
+ } else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
28
+ const node = a[--aEnd].nextSibling;
29
+ parentNode.insertBefore(b[bStart++], a[aStart++].nextSibling);
30
+ parentNode.insertBefore(b[--bEnd], node);
31
+ a[aEnd] = b[bEnd];
32
+ } else {
33
+ if (!map) {
34
+ map = /* @__PURE__ */ new Map();
35
+ let i = bStart;
36
+ while (i < bEnd)
37
+ map.set(b[i], i++);
38
+ }
39
+ const index = map.get(a[aStart]);
40
+ if (index != null) {
41
+ if (bStart < index && index < bEnd) {
42
+ let i = aStart, sequence = 1, t;
43
+ while (++i < aEnd && i < bEnd) {
44
+ if ((t = map.get(a[i])) == null || t !== index + sequence)
45
+ break;
46
+ sequence++;
47
+ }
48
+ if (sequence > index - bStart) {
49
+ const node = a[aStart];
50
+ while (bStart < index)
51
+ parentNode.insertBefore(b[bStart++], node);
52
+ } else
53
+ parentNode.replaceChild(b[bStart++], a[aStart++]);
54
+ } else
55
+ aStart++;
56
+ } else
57
+ a[aStart++].remove();
58
+ }
59
+ }
60
+ }
61
+ function template(html, isCE, isSVG) {
62
+ let node;
63
+ const create = () => {
64
+ const t = document.createElement("template");
65
+ t.innerHTML = html;
66
+ return isSVG ? t.content.firstChild.firstChild : t.content.firstChild;
67
+ };
68
+ const fn = isCE ? () => solidJs.untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true);
69
+ fn.cloneNode = fn;
70
+ return fn;
71
+ }
72
+ function className(node, value) {
73
+ if (solidJs.sharedConfig.context)
74
+ return;
75
+ if (value == null)
76
+ node.removeAttribute("class");
77
+ else
78
+ node.className = value;
79
+ }
80
+ function insert(parent, accessor, marker, initial) {
81
+ if (marker !== void 0 && !initial)
82
+ initial = [];
83
+ if (typeof accessor !== "function")
84
+ return insertExpression(parent, accessor, initial, marker);
85
+ solidJs.createRenderEffect((current) => insertExpression(parent, accessor(), current, marker), initial);
86
+ }
87
+ function insertExpression(parent, value, current, marker, unwrapArray) {
88
+ if (solidJs.sharedConfig.context) {
89
+ !current && (current = [...parent.childNodes]);
90
+ let cleaned = [];
91
+ for (let i = 0; i < current.length; i++) {
92
+ const node = current[i];
93
+ if (node.nodeType === 8 && node.data.slice(0, 2) === "!$")
94
+ node.remove();
95
+ else
96
+ cleaned.push(node);
97
+ }
98
+ current = cleaned;
99
+ }
100
+ while (typeof current === "function")
101
+ current = current();
102
+ if (value === current)
103
+ return current;
104
+ const t = typeof value, multi = marker !== void 0;
105
+ parent = multi && current[0] && current[0].parentNode || parent;
106
+ if (t === "string" || t === "number") {
107
+ if (solidJs.sharedConfig.context)
108
+ return current;
109
+ if (t === "number")
110
+ value = value.toString();
111
+ if (multi) {
112
+ let node = current[0];
113
+ if (node && node.nodeType === 3) {
114
+ node.data = value;
115
+ } else
116
+ node = document.createTextNode(value);
117
+ current = cleanChildren(parent, current, marker, node);
118
+ } else {
119
+ if (current !== "" && typeof current === "string") {
120
+ current = parent.firstChild.data = value;
121
+ } else
122
+ current = parent.textContent = value;
123
+ }
124
+ } else if (value == null || t === "boolean") {
125
+ if (solidJs.sharedConfig.context)
126
+ return current;
127
+ current = cleanChildren(parent, current, marker);
128
+ } else if (t === "function") {
129
+ solidJs.createRenderEffect(() => {
130
+ let v = value();
131
+ while (typeof v === "function")
132
+ v = v();
133
+ current = insertExpression(parent, v, current, marker);
134
+ });
135
+ return () => current;
136
+ } else if (Array.isArray(value)) {
137
+ const array = [];
138
+ const currentArray = current && Array.isArray(current);
139
+ if (normalizeIncomingArray(array, value, current, unwrapArray)) {
140
+ solidJs.createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
141
+ return () => current;
142
+ }
143
+ if (solidJs.sharedConfig.context) {
144
+ if (!array.length)
145
+ return current;
146
+ if (marker === void 0)
147
+ return [...parent.childNodes];
148
+ let node = array[0];
149
+ let nodes = [node];
150
+ while ((node = node.nextSibling) !== marker)
151
+ nodes.push(node);
152
+ return current = nodes;
153
+ }
154
+ if (array.length === 0) {
155
+ current = cleanChildren(parent, current, marker);
156
+ if (multi)
157
+ return current;
158
+ } else if (currentArray) {
159
+ if (current.length === 0) {
160
+ appendNodes(parent, array, marker);
161
+ } else
162
+ reconcileArrays(parent, current, array);
163
+ } else {
164
+ current && cleanChildren(parent);
165
+ appendNodes(parent, array);
166
+ }
167
+ current = array;
168
+ } else if (value.nodeType) {
169
+ if (solidJs.sharedConfig.context && value.parentNode)
170
+ return current = multi ? [value] : value;
171
+ if (Array.isArray(current)) {
172
+ if (multi)
173
+ return current = cleanChildren(parent, current, marker, value);
174
+ cleanChildren(parent, current, null, value);
175
+ } else if (current == null || current === "" || !parent.firstChild) {
176
+ parent.appendChild(value);
177
+ } else
178
+ parent.replaceChild(value, parent.firstChild);
179
+ current = value;
180
+ } else
181
+ ;
182
+ return current;
183
+ }
184
+ function normalizeIncomingArray(normalized, array, current, unwrap) {
185
+ let dynamic = false;
186
+ for (let i = 0, len = array.length; i < len; i++) {
187
+ let item = array[i], prev = current && current[i], t;
188
+ if (item == null || item === true || item === false)
189
+ ;
190
+ else if ((t = typeof item) === "object" && item.nodeType) {
191
+ normalized.push(item);
192
+ } else if (Array.isArray(item)) {
193
+ dynamic = normalizeIncomingArray(normalized, item, prev) || dynamic;
194
+ } else if (t === "function") {
195
+ if (unwrap) {
196
+ while (typeof item === "function")
197
+ item = item();
198
+ dynamic = normalizeIncomingArray(
199
+ normalized,
200
+ Array.isArray(item) ? item : [item],
201
+ Array.isArray(prev) ? prev : [prev]
202
+ ) || dynamic;
203
+ } else {
204
+ normalized.push(item);
205
+ dynamic = true;
206
+ }
207
+ } else {
208
+ const value = String(item);
209
+ if (prev && prev.nodeType === 3 && prev.data === value)
210
+ normalized.push(prev);
211
+ else
212
+ normalized.push(document.createTextNode(value));
213
+ }
214
+ }
215
+ return dynamic;
216
+ }
217
+ function appendNodes(parent, array, marker = null) {
218
+ for (let i = 0, len = array.length; i < len; i++)
219
+ parent.insertBefore(array[i], marker);
220
+ }
221
+ function cleanChildren(parent, current, marker, replacement) {
222
+ if (marker === void 0)
223
+ return parent.textContent = "";
224
+ const node = replacement || document.createTextNode("");
225
+ if (current.length) {
226
+ let inserted = false;
227
+ for (let i = current.length - 1; i >= 0; i--) {
228
+ const el = current[i];
229
+ if (node !== el) {
230
+ const isParent = el.parentNode === parent;
231
+ if (!inserted && !i)
232
+ isParent ? parent.replaceChild(node, el) : parent.insertBefore(node, marker);
233
+ else
234
+ isParent && el.remove();
235
+ } else
236
+ inserted = true;
237
+ }
238
+ } else
239
+ parent.insertBefore(node, marker);
240
+ return [node];
241
+ }
242
+ const ctx$1 = solidJs.createContext(() => void 0, {
243
+ name: "case-when"
244
+ });
245
+ function Case(props) {
246
+ const memo = solidJs.createMemo(() => props.value);
247
+ return solidJs.createComponent(ctx$1.Provider, {
248
+ value: memo,
249
+ get children() {
250
+ return props.children;
251
+ }
252
+ });
253
+ }
254
+ function When(props) {
255
+ const [mine, other] = splitAndMemoProps(props, ["value", "pred"]);
256
+ const value = solidJs.useContext(ctx$1);
257
+ const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
258
+ return solidJs.createComponent(solidJs.Match, solidJs.mergeProps({
259
+ get when() {
260
+ return pred(value());
261
+ }
262
+ }, other));
263
+ }
264
+ const ctx = solidJs.createContext(() => false, {
265
+ name: "debug-scope"
266
+ });
267
+ function Debug(props) {
268
+ return solidJs.createComponent(ctx.Provider, {
269
+ value: () => props.value ?? true,
270
+ get children() {
271
+ return props.children;
272
+ }
273
+ });
274
+ }
275
+ (function(_Debug) {
276
+ Object.defineProperty(Debug, "isDebug", {
277
+ get: () => solidJs.useContext(ctx)
278
+ });
279
+ })(Debug || (Debug = {}));
280
+ function createExtractor(name = "extractor") {
281
+ const ctx2 = solidJs.createContext(void 0, {
282
+ name
283
+ });
284
+ return {
285
+ /** Bound {@link Dest} */
286
+ Dest: Dest.bind(ctx2),
287
+ /** Bound {@link Source} */
288
+ Source: Source.bind(ctx2),
289
+ /** Bound {@link Joint} */
290
+ Joint: Joint.bind(ctx2),
291
+ /**
292
+ * Gets an {@link Accessor} that tells if the context in which THIS getter has been executed has been extracted (Is inside of a {@link Dest})
293
+ * @returns Returns `null` if there is no parent {@link Joint}, the number of {@link Dest}s in which this component is being displayed otherwise (Usually 1)
294
+ */
295
+ get isExtracted() {
296
+ const obj = solidJs.useContext(ctx2);
297
+ return () => obj?.attached ?? null;
298
+ }
299
+ };
300
+ }
301
+ function Dest() {
302
+ const obj = solidJs.useContext(this);
303
+ if (!obj)
304
+ return;
305
+ obj.attached++;
306
+ solidJs.onCleanup(() => obj.attached--);
307
+ return solidJs.createMemo(() => obj.source);
308
+ }
309
+ function Source(props) {
310
+ const obj = solidJs.useContext(this);
311
+ if (!obj)
312
+ return props.children;
313
+ if (obj.source)
314
+ throw new Error("An extractor can't have more than one source");
315
+ obj.source = () => props.children;
316
+ solidJs.onCleanup(() => obj.source = void 0);
317
+ return solidJs.createComponent(solidJs.Show, {
318
+ get when() {
319
+ return !obj.attached;
320
+ },
321
+ get children() {
322
+ return obj.source();
323
+ }
324
+ });
325
+ }
326
+ function Joint(props) {
327
+ const {
328
+ Provider
329
+ } = this;
330
+ const obj = store.createMutable({
331
+ attached: 0
332
+ });
333
+ return solidJs.createComponent(Provider, {
334
+ value: obj,
335
+ get children() {
336
+ return props.children;
337
+ }
338
+ });
339
+ }
340
+ const _tmpl$ = /* @__PURE__ */ template(`<div>`);
341
+ function Wrapper(props) {
342
+ const classList = solidJs.createMemo(() => Object.entries(props.classList).filter((x) => x[1]).map((x) => x[0]));
343
+ const children = solidJs.createMemo(() => props.children);
344
+ return solidJs.createComponent(solidJs.Show, {
345
+ get when() {
346
+ return classList().length;
347
+ },
348
+ get fallback() {
349
+ return children();
350
+ },
351
+ get children() {
352
+ const _el$ = _tmpl$();
353
+ insert(_el$, children);
354
+ solidJs.createRenderEffect(() => className(_el$, classList().join(" ")));
355
+ return _el$;
356
+ }
357
+ });
358
+ }
359
+ function memoProps(obj, keys = Object.keys(obj)) {
360
+ const out = {};
361
+ for (const elm of keys)
362
+ Object.defineProperty(out, elm, {
363
+ get: solidJs.createMemo(() => obj[elm])
364
+ });
365
+ return out;
366
+ }
367
+ function splitAndMemoProps(obj, keys) {
368
+ const [mine, other] = solidJs.splitProps(obj, keys);
369
+ return [memoProps(mine, keys), other];
370
+ }
371
+ exports2.Case = Case;
372
+ exports2.Debug = Debug;
373
+ exports2.When = When;
374
+ exports2.Wrapper = Wrapper;
375
+ exports2.createExtractor = createExtractor;
376
+ exports2.memoProps = memoProps;
377
+ exports2.splitAndMemoProps = splitAndMemoProps;
378
+ Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
379
+ });
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
7
- "types": "./dist/flow.d.ts",
7
+ "types": "./dist/index.d.ts",
8
8
  "exports": {
9
- "require": "./dist/flow.umd.js",
10
- "import": "./dist/flow.mjs",
11
- "types": "./dist/flow.d.ts"
9
+ "require": "./dist/index.umd.js",
10
+ "import": "./dist/index.mjs",
11
+ "types": "./dist/index.d.ts"
12
12
  },
13
13
  "scripts": {
14
14
  "build": "vite build",
package/dist/flow.mjs DELETED
@@ -1,120 +0,0 @@
1
- import { createContext, createMemo, createComponent, useContext, Match, mergeProps, onCleanup, Show, splitProps } from "solid-js";
2
- import { createMutable } from "solid-js/store";
3
- const ctx$1 = createContext(() => void 0, {
4
- name: "case-when"
5
- });
6
- function Case(props) {
7
- const memo = createMemo(() => props.value);
8
- return createComponent(ctx$1.Provider, {
9
- value: memo,
10
- get children() {
11
- return props.children;
12
- }
13
- });
14
- }
15
- function When(props) {
16
- const [mine, other] = splitAndMemoProps(props, ["value", "pred"]);
17
- const value = useContext(ctx$1);
18
- const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
19
- return createComponent(Match, mergeProps({
20
- get when() {
21
- return pred(value());
22
- }
23
- }, other));
24
- }
25
- const ctx = createContext(() => false, {
26
- name: "debug-scope"
27
- });
28
- function Debug(props) {
29
- return createComponent(ctx.Provider, {
30
- value: () => props.value ?? true,
31
- get children() {
32
- return props.children;
33
- }
34
- });
35
- }
36
- (function(_Debug) {
37
- Object.defineProperty(Debug, "isDebug", {
38
- get: () => useContext(ctx)
39
- });
40
- })(Debug || (Debug = {}));
41
- function createExtractor(name = "extractor") {
42
- const ctx2 = createContext(void 0, {
43
- name
44
- });
45
- return {
46
- /** Bound {@link Dest} */
47
- Dest: Dest.bind(ctx2),
48
- /** Bound {@link Source} */
49
- Source: Source.bind(ctx2),
50
- /** Bound {@link Joint} */
51
- Joint: Joint.bind(ctx2),
52
- /**
53
- * Gets an {@link Accessor} that tells if the context in which THIS getter has been executed has been extracted (Is inside of a {@link Dest})
54
- * @returns Returns `null` if there is no parent {@link Joint}, the number of {@link Dest}s in which this component is being displayed otherwise (Usually 1)
55
- */
56
- get isExtracted() {
57
- const obj = useContext(ctx2);
58
- return () => obj?.attached ?? null;
59
- }
60
- };
61
- }
62
- function Dest() {
63
- const obj = useContext(this);
64
- if (!obj)
65
- return;
66
- obj.attached++;
67
- onCleanup(() => obj.attached--);
68
- return createMemo(() => obj.source);
69
- }
70
- function Source(props) {
71
- const obj = useContext(this);
72
- if (!obj)
73
- return props.children;
74
- if (obj.source)
75
- throw new Error("An extractor can't have more than one source");
76
- obj.source = () => props.children;
77
- onCleanup(() => obj.source = void 0);
78
- return createComponent(Show, {
79
- get when() {
80
- return !obj.attached;
81
- },
82
- get children() {
83
- return obj.source();
84
- }
85
- });
86
- }
87
- function Joint(props) {
88
- const {
89
- Provider
90
- } = this;
91
- const obj = createMutable({
92
- attached: 0
93
- });
94
- return createComponent(Provider, {
95
- value: obj,
96
- get children() {
97
- return props.children;
98
- }
99
- });
100
- }
101
- function memoProps(obj, keys = Object.keys(obj)) {
102
- const out = {};
103
- for (const elm of keys)
104
- Object.defineProperty(out, elm, {
105
- get: createMemo(() => obj[elm])
106
- });
107
- return out;
108
- }
109
- function splitAndMemoProps(obj, keys) {
110
- const [mine, other] = splitProps(obj, keys);
111
- return [memoProps(mine, keys), other];
112
- }
113
- export {
114
- Case,
115
- Debug,
116
- When,
117
- createExtractor,
118
- memoProps,
119
- splitAndMemoProps
120
- };
package/dist/flow.umd.js DELETED
@@ -1,122 +0,0 @@
1
- (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("solid-js"), require("solid-js/store")) : typeof define === "function" && define.amd ? define(["exports", "solid-js", "solid-js/store"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.solidFlow = {}, global.solidJs, global.solidJsStore));
3
- })(this, function(exports2, solidJs, store) {
4
- "use strict";
5
- const ctx$1 = solidJs.createContext(() => void 0, {
6
- name: "case-when"
7
- });
8
- function Case(props) {
9
- const memo = solidJs.createMemo(() => props.value);
10
- return solidJs.createComponent(ctx$1.Provider, {
11
- value: memo,
12
- get children() {
13
- return props.children;
14
- }
15
- });
16
- }
17
- function When(props) {
18
- const [mine, other] = splitAndMemoProps(props, ["value", "pred"]);
19
- const value = solidJs.useContext(ctx$1);
20
- const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
21
- return solidJs.createComponent(solidJs.Match, solidJs.mergeProps({
22
- get when() {
23
- return pred(value());
24
- }
25
- }, other));
26
- }
27
- const ctx = solidJs.createContext(() => false, {
28
- name: "debug-scope"
29
- });
30
- function Debug(props) {
31
- return solidJs.createComponent(ctx.Provider, {
32
- value: () => props.value ?? true,
33
- get children() {
34
- return props.children;
35
- }
36
- });
37
- }
38
- (function(_Debug) {
39
- Object.defineProperty(Debug, "isDebug", {
40
- get: () => solidJs.useContext(ctx)
41
- });
42
- })(Debug || (Debug = {}));
43
- function createExtractor(name = "extractor") {
44
- const ctx2 = solidJs.createContext(void 0, {
45
- name
46
- });
47
- return {
48
- /** Bound {@link Dest} */
49
- Dest: Dest.bind(ctx2),
50
- /** Bound {@link Source} */
51
- Source: Source.bind(ctx2),
52
- /** Bound {@link Joint} */
53
- Joint: Joint.bind(ctx2),
54
- /**
55
- * Gets an {@link Accessor} that tells if the context in which THIS getter has been executed has been extracted (Is inside of a {@link Dest})
56
- * @returns Returns `null` if there is no parent {@link Joint}, the number of {@link Dest}s in which this component is being displayed otherwise (Usually 1)
57
- */
58
- get isExtracted() {
59
- const obj = solidJs.useContext(ctx2);
60
- return () => obj?.attached ?? null;
61
- }
62
- };
63
- }
64
- function Dest() {
65
- const obj = solidJs.useContext(this);
66
- if (!obj)
67
- return;
68
- obj.attached++;
69
- solidJs.onCleanup(() => obj.attached--);
70
- return solidJs.createMemo(() => obj.source);
71
- }
72
- function Source(props) {
73
- const obj = solidJs.useContext(this);
74
- if (!obj)
75
- return props.children;
76
- if (obj.source)
77
- throw new Error("An extractor can't have more than one source");
78
- obj.source = () => props.children;
79
- solidJs.onCleanup(() => obj.source = void 0);
80
- return solidJs.createComponent(solidJs.Show, {
81
- get when() {
82
- return !obj.attached;
83
- },
84
- get children() {
85
- return obj.source();
86
- }
87
- });
88
- }
89
- function Joint(props) {
90
- const {
91
- Provider
92
- } = this;
93
- const obj = store.createMutable({
94
- attached: 0
95
- });
96
- return solidJs.createComponent(Provider, {
97
- value: obj,
98
- get children() {
99
- return props.children;
100
- }
101
- });
102
- }
103
- function memoProps(obj, keys = Object.keys(obj)) {
104
- const out = {};
105
- for (const elm of keys)
106
- Object.defineProperty(out, elm, {
107
- get: solidJs.createMemo(() => obj[elm])
108
- });
109
- return out;
110
- }
111
- function splitAndMemoProps(obj, keys) {
112
- const [mine, other] = solidJs.splitProps(obj, keys);
113
- return [memoProps(mine, keys), other];
114
- }
115
- exports2.Case = Case;
116
- exports2.Debug = Debug;
117
- exports2.When = When;
118
- exports2.createExtractor = createExtractor;
119
- exports2.memoProps = memoProps;
120
- exports2.splitAndMemoProps = splitAndMemoProps;
121
- Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
122
- });