solid-ctrl-flow 1.0.41 → 1.0.43

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 CHANGED
@@ -75,7 +75,7 @@ export declare const Case: (props: {
75
75
 
76
76
  /**
77
77
  * Returns a {@link Signal} that applies the `??=` operator to the input one.
78
- * If the getter of {@link param0} is like "x", then the result one is like "(x ??= {@link f}())"
78
+ * If the getter of {@link param0} is like `x`, then the result one is like "(x ??= {@link f}())"
79
79
  * @param param0 The {@link Signal} to which to coalesce the getter
80
80
  * @param f An {@link Accessor} to the value to use when there's a nullish value
81
81
  */
@@ -97,8 +97,8 @@ export declare type Convert<S, D> = (x: S, prev: D) => D;
97
97
  * </div>
98
98
  * <div id="something-else">
99
99
  * <e.Source>
100
- * This text will be shown instead of "e.Dest".
101
- * If there weren't to be any "e.Joint" ancestor, then this text would have stayed here
100
+ * This text will be shown instead of `e.Dest`.
101
+ * If there weren't to be any `e.Joint` ancestor, then this text would have stayed here
102
102
  * </e.Source>
103
103
  * </div>
104
104
  * </e.Joint>
@@ -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
@@ -305,11 +335,11 @@ export declare const unwrap: <T extends object>(f: Accessor<T>) => T;
305
335
  * Calls {@link f} maintaining its reactivity at 2 levels.
306
336
  * Unlike the normal {@link unwrap}, this maintains reactivity on the elements of the array too, which means that it can be destructured
307
337
  * ```ts
308
- * const first = unwrap(f); // The value of "first" is reactive but CANNOT be destructured
309
- * const [ getFirst ] = first; // The value of "getFirst" is NOT reactive, it's the first element of the CURRENT signal returned by "f"
338
+ * const first = unwrap(f); // The value of `first` is reactive but CANNOT be destructured
339
+ * const [ getFirst ] = first; // The value of `getFirst()` is NOT reactive, it's the first element of the CURRENT signal returned by `f()`
310
340
  *
311
- * const second = unwrapSignal(f); // The value of "second" is reactive and CAN be destructured
312
- * const [ getSecond ] = second; // The value of "getSecond" IS reactive, it's a function that calls "f", gets the first element and calls that too
341
+ * const second = unwrapSignal(f); // The value of `second` is reactive and CAN be destructured
342
+ * const [ getSecond ] = second; // The value of `getSecond()` IS reactive, it's a function that calls `f()`, gets the first element and calls that too
313
343
  * ```
314
344
  * @param f An {@link Accessor} to a {@link Signal}
315
345
  */
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)
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.sort((a, b) => a.order - b.order);
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.push(info);
174
- onCleanup(() => obj.source.splice(obj.source.indexOf(createMutable(info)), 1));
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)
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.sort((a, b) => a.order - b.order);
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
- obj.source.push(info);
176
- solidJs.onCleanup(() => obj.source.splice(obj.source.indexOf(store.createMutable(info)), 1));
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.41",
3
+ "version": "1.0.43",
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
- "debug"
37
+ "slot"
38
38
  ]
39
39
  }