solid-ctrl-flow 1.0.41 → 1.0.42
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/dist/index.d.ts +31 -1
- package/dist/index.mjs +21 -3
- package/dist/index.umd.js +20 -3
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -149,7 +149,7 @@ export declare function Enfold<T>(props: Unkeyed<T>): JSX.Element;
|
|
|
149
149
|
declare type Equals = MemoOptions<unknown>["equals"];
|
|
150
150
|
|
|
151
151
|
/** Informations about a {@link Source} component */
|
|
152
|
-
declare type Info = {
|
|
152
|
+
declare type Info = Slot & {
|
|
153
153
|
/** Order of the current source if there are many */
|
|
154
154
|
order?: number;
|
|
155
155
|
children: JSX.Element;
|
|
@@ -245,6 +245,36 @@ export declare function runWithContext<T, V extends T, R>(ctx: Context<T>, value
|
|
|
245
245
|
|
|
246
246
|
export declare function runWithContext<T, R>(ctx: Context<T>, value: T | undefined, f: (x: T) => R): R;
|
|
247
247
|
|
|
248
|
+
/** Element which tracks its index in its containing array */
|
|
249
|
+
export declare interface Slot {
|
|
250
|
+
slot?: number;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** Utility of {@link Slot}s */
|
|
254
|
+
export declare namespace Slot {
|
|
255
|
+
/**
|
|
256
|
+
* Pushes an element into a slotted list
|
|
257
|
+
* @param list The list in which to add the element
|
|
258
|
+
* @param v The element to add to {@link list}
|
|
259
|
+
* @returns The index of the new element
|
|
260
|
+
*/
|
|
261
|
+
const push: <T extends Slot>(list: T[], v: T) => number;
|
|
262
|
+
/**
|
|
263
|
+
* Exactly like {@link removeSlotAt}, but it gets the index from {@link v}
|
|
264
|
+
* @param list The list from which to remove the element
|
|
265
|
+
* @param v The element to remove from {@link list}
|
|
266
|
+
* @returns The removed element
|
|
267
|
+
*/
|
|
268
|
+
const remove: <T extends Slot>(list: T[], v: T) => T | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* Removes an element from a slotted list
|
|
271
|
+
* @param list The list from which to remove the element
|
|
272
|
+
* @param i The index at which to remove the element
|
|
273
|
+
* @returns The removed element
|
|
274
|
+
*/
|
|
275
|
+
export function removeAt<T extends Slot>(list: T[], i: number): T | undefined;
|
|
276
|
+
}
|
|
277
|
+
|
|
248
278
|
/**
|
|
249
279
|
* Executes {@link splitProps} and memoizes the first of the two returned objects using {@link memoProps}
|
|
250
280
|
* @param obj Object to split and partially memoize
|
package/dist/index.mjs
CHANGED
|
@@ -123,6 +123,23 @@ function Enfold(props) {
|
|
|
123
123
|
children: (x) => createMemo(() => untrackCall(props.template, children, x))
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
|
+
var Slot;
|
|
127
|
+
((Slot2) => {
|
|
128
|
+
Slot2.push = (list, v) => v.slot = list.push(v) - 1;
|
|
129
|
+
Slot2.remove = (list, v) => v.slot != null ? removeAt(list, v.slot) : v;
|
|
130
|
+
function removeAt(list, i) {
|
|
131
|
+
if (i >= list.length)
|
|
132
|
+
return;
|
|
133
|
+
const last = list.pop();
|
|
134
|
+
if (i === list.length - 1)
|
|
135
|
+
return last;
|
|
136
|
+
const out = list[i];
|
|
137
|
+
out.slot = void 0;
|
|
138
|
+
list[last.slot = i] = last;
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
Slot2.removeAt = removeAt;
|
|
142
|
+
})(Slot || (Slot = {}));
|
|
126
143
|
function createExtractor(name = "extractor") {
|
|
127
144
|
const ctx2 = createContext(void 0, {
|
|
128
145
|
name
|
|
@@ -152,7 +169,7 @@ function Dest() {
|
|
|
152
169
|
onCleanup(() => obj.attached--);
|
|
153
170
|
return createComponent(For, {
|
|
154
171
|
get each() {
|
|
155
|
-
return obj.source.
|
|
172
|
+
return obj.source.toSorted((a, b) => a.order - b.order);
|
|
156
173
|
},
|
|
157
174
|
children: (x) => createMemo(() => x.children)
|
|
158
175
|
});
|
|
@@ -170,8 +187,8 @@ function Source(props) {
|
|
|
170
187
|
return props.children;
|
|
171
188
|
}
|
|
172
189
|
};
|
|
173
|
-
obj.source
|
|
174
|
-
onCleanup(() =>
|
|
190
|
+
Slot.push(obj.source, info);
|
|
191
|
+
onCleanup(() => Slot.remove(obj.source, info));
|
|
175
192
|
return createComponent(Show, {
|
|
176
193
|
get when() {
|
|
177
194
|
return !obj.attached;
|
|
@@ -241,6 +258,7 @@ export {
|
|
|
241
258
|
Enfold,
|
|
242
259
|
Nest,
|
|
243
260
|
ReactiveContext,
|
|
261
|
+
Slot,
|
|
244
262
|
When,
|
|
245
263
|
bind,
|
|
246
264
|
bindTwoWay,
|
package/dist/index.umd.js
CHANGED
|
@@ -125,6 +125,23 @@
|
|
|
125
125
|
children: (x) => solidJs.createMemo(() => untrackCall(props.template, children, x))
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
+
exports2.Slot = void 0;
|
|
129
|
+
((Slot2) => {
|
|
130
|
+
Slot2.push = (list, v) => v.slot = list.push(v) - 1;
|
|
131
|
+
Slot2.remove = (list, v) => v.slot != null ? removeAt(list, v.slot) : v;
|
|
132
|
+
function removeAt(list, i) {
|
|
133
|
+
if (i >= list.length)
|
|
134
|
+
return;
|
|
135
|
+
const last = list.pop();
|
|
136
|
+
if (i === list.length - 1)
|
|
137
|
+
return last;
|
|
138
|
+
const out = list[i];
|
|
139
|
+
out.slot = void 0;
|
|
140
|
+
list[last.slot = i] = last;
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
Slot2.removeAt = removeAt;
|
|
144
|
+
})(exports2.Slot || (exports2.Slot = {}));
|
|
128
145
|
function createExtractor(name = "extractor") {
|
|
129
146
|
const ctx2 = solidJs.createContext(void 0, {
|
|
130
147
|
name
|
|
@@ -154,7 +171,7 @@
|
|
|
154
171
|
solidJs.onCleanup(() => obj.attached--);
|
|
155
172
|
return solidJs.createComponent(solidJs.For, {
|
|
156
173
|
get each() {
|
|
157
|
-
return obj.source.
|
|
174
|
+
return obj.source.toSorted((a, b) => a.order - b.order);
|
|
158
175
|
},
|
|
159
176
|
children: (x) => solidJs.createMemo(() => x.children)
|
|
160
177
|
});
|
|
@@ -172,8 +189,8 @@
|
|
|
172
189
|
return props.children;
|
|
173
190
|
}
|
|
174
191
|
};
|
|
175
|
-
|
|
176
|
-
solidJs.onCleanup(() =>
|
|
192
|
+
exports2.Slot.push(obj.source, info);
|
|
193
|
+
solidJs.onCleanup(() => exports2.Slot.remove(obj.source, info));
|
|
177
194
|
return solidJs.createComponent(solidJs.Show, {
|
|
178
195
|
get when() {
|
|
179
196
|
return !obj.attached;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-ctrl-flow",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"description": "Control flow components for solid-js",
|
|
5
5
|
"author": "AFatNiBBa",
|
|
6
6
|
"license": "ISC",
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"switch",
|
|
35
35
|
"case",
|
|
36
36
|
"when",
|
|
37
|
-
"
|
|
37
|
+
"slot"
|
|
38
38
|
]
|
|
39
39
|
}
|