solid-ctrl-flow 7.0.0 → 7.0.2

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
@@ -1,4 +1,5 @@
1
1
  import { Accessor } from 'solid-js';
2
+ import { ComponentProps } from 'solid-js';
2
3
  import { Context } from 'solid-js';
3
4
  import { JSX } from 'solid-js';
4
5
  import { MemoOptions } from 'solid-js';
@@ -20,6 +21,9 @@ export declare function Case(props: ParentProps<{
20
21
  */
21
22
  export declare function disposeWithOwner<T>(outer: Owner, f: Accessor<T>): T;
22
23
 
24
+ /** Handy type alias */
25
+ declare type div = ComponentProps<"div">;
26
+
23
27
  /**
24
28
  * Eventually wraps its content into a template if a certain condition is met.
25
29
  * If you set {@link Standard.recycled} to `true`, the content will be memoized in the beginning and will be recycled even if the wrapper changes.
@@ -169,6 +173,15 @@ export declare namespace OrderedLinkedList {
169
173
  }
170
174
  }
171
175
 
176
+ /**
177
+ * Simple {@link HTMLDivElement} that accepts another set of attributes to merge with the base ones.
178
+ * Specifically, {@link div.ref}, {@link div.class}, {@link div.classList}, and {@link div.style} are combined rather than overwritten by the second set of attributes.
179
+ * Used for customizable structural parts of components
180
+ */
181
+ export declare function Part(props: {
182
+ props: div | undefined;
183
+ } & div): JSX;
184
+
172
185
  /**
173
186
  * Executes {@link f} with the provided value for the specified {@link Context}.
174
187
  * You can pass `undefined` to {@link value} in order to get back the default value for {@link ctx}.
@@ -230,6 +243,21 @@ declare class State {
230
243
  /** Type of an element wrapping call-back which accepts an additional parameter */
231
244
  declare type Template<T> = (c: Accessor<JSX.Element>, x: T) => JSX.Element;
232
245
 
246
+ /** Object that reactively tells whether a CSS transition is currently in progress */
247
+ export declare class TransitionMonitor {
248
+ #private;
249
+ /** Whether a transition is currently in progress */
250
+ get pending(): boolean;
251
+ /**
252
+ * Starts waiting for the transition to end.
253
+ * This function should be called immediately before the transition is triggered.
254
+ * If a transition is already in progress, this function does nothing, allowing the object to keep monitoring the previous transition, but the returned {@link Promise} will not wait for the latter to complete
255
+ * @param ctrl The element on which the transition will occur
256
+ * @returns A {@link Promise} that resolves to whether monitoring completed successfully or was cancelled because a transition was already in progress
257
+ */
258
+ start(ctrl: HTMLElement): Promise<boolean>;
259
+ }
260
+
233
261
  /** Parameters to pass to an unkeyed {@link Enfold} */
234
262
  declare type Unkeyed<T> = Standard<T> & {
235
263
  keyed?: false;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { untrack, getOwner, createRoot, runWithOwner, onCleanup, createMemo, Show, createContext, useContext, For, createRenderEffect, on, splitProps, createSignal, batch, createSelector, equalFn, Match } from "solid-js";
2
- import { createComponent, memo, mergeProps, spread } from "solid-js/web";
1
+ import { untrack, getOwner, createRoot, runWithOwner, onCleanup, createMemo, Show, createContext, useContext, For, createRenderEffect, on, splitProps, createSignal, batch, mergeProps as mergeProps$1, createSelector, equalFn, Match } from "solid-js";
2
+ import { createComponent, memo, mergeProps, use, spread, template } from "solid-js/web";
3
3
  function untrackCall(f, ...args) {
4
4
  return untrack(() => f.apply(this, args));
5
5
  }
@@ -226,30 +226,6 @@ function SameContextSource(props) {
226
226
  }
227
227
  }));
228
228
  }
229
- const ctx = createContext(void 0, {
230
- name: "on-case"
231
- });
232
- function On(props) {
233
- const memo2 = memoProps(props);
234
- const selector = createSelector(() => memo2.value, (a, b) => (memo2.onCompare ?? equalFn)(a, b));
235
- return createComponent(ctx.Provider, {
236
- value: selector,
237
- get children() {
238
- return props.children;
239
- }
240
- });
241
- }
242
- function Case(props) {
243
- const selector = useContext(ctx);
244
- return createComponent(Match, {
245
- get when() {
246
- return selector(props.value);
247
- },
248
- get children() {
249
- return props.children;
250
- }
251
- });
252
- }
253
229
  const memoProps = (obj, equals) => new Proxy(obj, new MemoPropsHandler(getOwner(), equals));
254
230
  const splitAndMemoProps = (obj, ...keys) => splitAndMemoSomeProps(obj, keys.length, ...keys);
255
231
  function splitAndMemoSomeProps(obj, n, ...keys) {
@@ -285,6 +261,90 @@ class MemoPropsHandler {
285
261
  return runWithOwner(this.owner, () => createMemo(() => t[k], void 0, opts));
286
262
  }
287
263
  }
264
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
265
+ function Part(props) {
266
+ const [mine, first, second, other, user] = processProps(props);
267
+ return (() => {
268
+ var _el$ = _tmpl$();
269
+ use((x) => createComponent(Spread, {
270
+ target: x,
271
+ ref(r$) {
272
+ var _ref$ = mine.ref;
273
+ typeof _ref$ === "function" ? _ref$(r$) : mine.ref = r$;
274
+ },
275
+ get style() {
276
+ return mine.style;
277
+ }
278
+ }), _el$);
279
+ spread(_el$, mergeProps(other, user, {
280
+ get classList() {
281
+ return {
282
+ [first.class ?? ""]: true,
283
+ [second.class ?? ""]: true,
284
+ // A key containing only spaces breaks, so the optional classes are kept as separate properties
285
+ ...first.classList,
286
+ ...second.classList
287
+ };
288
+ }
289
+ }), false, false);
290
+ return _el$;
291
+ })();
292
+ }
293
+ function processProps(props) {
294
+ const [mine, temp, other] = splitProps(props, ["ref", "style", "props"], ["class", "classList"]), first = memoProps(temp);
295
+ const [second, user] = splitAndMemoProps(mergeProps$1(() => mine.props), ["class", "classList"]);
296
+ return [mine, first, second, other, user];
297
+ }
298
+ const ctx = createContext(void 0, {
299
+ name: "on-case"
300
+ });
301
+ function On(props) {
302
+ const memo2 = memoProps(props);
303
+ const selector = createSelector(() => memo2.value, (a, b) => (memo2.onCompare ?? equalFn)(a, b));
304
+ return createComponent(ctx.Provider, {
305
+ value: selector,
306
+ get children() {
307
+ return props.children;
308
+ }
309
+ });
310
+ }
311
+ function Case(props) {
312
+ const selector = useContext(ctx);
313
+ return createComponent(Match, {
314
+ get when() {
315
+ return selector(props.value);
316
+ },
317
+ get children() {
318
+ return props.children;
319
+ }
320
+ });
321
+ }
322
+ class TransitionMonitor {
323
+ #signal = createSignal(false);
324
+ /** Whether a transition is currently in progress */
325
+ get pending() {
326
+ return this.#signal[0]();
327
+ }
328
+ /**
329
+ * Starts waiting for the transition to end.
330
+ * This function should be called immediately before the transition is triggered.
331
+ * If a transition is already in progress, this function does nothing, allowing the object to keep monitoring the previous transition, but the returned {@link Promise} will not wait for the latter to complete
332
+ * @param ctrl The element on which the transition will occur
333
+ * @returns A {@link Promise} that resolves to whether monitoring completed successfully or was cancelled because a transition was already in progress
334
+ */
335
+ async start(ctrl) {
336
+ const [g, s] = this.#signal;
337
+ if (g())
338
+ return false;
339
+ s(true);
340
+ try {
341
+ await new Promise((t) => ctrl.addEventListener("transitionend", t, { once: true }));
342
+ } finally {
343
+ s(false);
344
+ }
345
+ return true;
346
+ }
347
+ }
288
348
  function SameContext(props) {
289
349
  return createMemo(() => {
290
350
  getOwner().context = props.owner.context;
@@ -302,8 +362,10 @@ export {
302
362
  Extractor,
303
363
  On,
304
364
  OrderedLinkedList,
365
+ Part,
305
366
  SameContext,
306
367
  Spread,
368
+ TransitionMonitor,
307
369
  disposeWithOwner,
308
370
  memoProps,
309
371
  runWithContext,
package/dist/index.umd.js CHANGED
@@ -228,30 +228,6 @@
228
228
  }
229
229
  }));
230
230
  }
231
- const ctx = solidJs.createContext(void 0, {
232
- name: "on-case"
233
- });
234
- function On(props) {
235
- const memo = memoProps(props);
236
- const selector = solidJs.createSelector(() => memo.value, (a, b) => (memo.onCompare ?? solidJs.equalFn)(a, b));
237
- return web.createComponent(ctx.Provider, {
238
- value: selector,
239
- get children() {
240
- return props.children;
241
- }
242
- });
243
- }
244
- function Case(props) {
245
- const selector = solidJs.useContext(ctx);
246
- return web.createComponent(solidJs.Match, {
247
- get when() {
248
- return selector(props.value);
249
- },
250
- get children() {
251
- return props.children;
252
- }
253
- });
254
- }
255
231
  const memoProps = (obj, equals) => new Proxy(obj, new MemoPropsHandler(solidJs.getOwner(), equals));
256
232
  const splitAndMemoProps = (obj, ...keys) => splitAndMemoSomeProps(obj, keys.length, ...keys);
257
233
  function splitAndMemoSomeProps(obj, n, ...keys) {
@@ -287,6 +263,90 @@
287
263
  return solidJs.runWithOwner(this.owner, () => solidJs.createMemo(() => t[k], void 0, opts));
288
264
  }
289
265
  }
266
+ var _tmpl$ = /* @__PURE__ */ web.template(`<div>`);
267
+ function Part(props) {
268
+ const [mine, first, second, other, user] = processProps(props);
269
+ return (() => {
270
+ var _el$ = _tmpl$();
271
+ web.use((x) => web.createComponent(Spread, {
272
+ target: x,
273
+ ref(r$) {
274
+ var _ref$ = mine.ref;
275
+ typeof _ref$ === "function" ? _ref$(r$) : mine.ref = r$;
276
+ },
277
+ get style() {
278
+ return mine.style;
279
+ }
280
+ }), _el$);
281
+ web.spread(_el$, web.mergeProps(other, user, {
282
+ get classList() {
283
+ return {
284
+ [first.class ?? ""]: true,
285
+ [second.class ?? ""]: true,
286
+ // A key containing only spaces breaks, so the optional classes are kept as separate properties
287
+ ...first.classList,
288
+ ...second.classList
289
+ };
290
+ }
291
+ }), false, false);
292
+ return _el$;
293
+ })();
294
+ }
295
+ function processProps(props) {
296
+ const [mine, temp, other] = solidJs.splitProps(props, ["ref", "style", "props"], ["class", "classList"]), first = memoProps(temp);
297
+ const [second, user] = splitAndMemoProps(solidJs.mergeProps(() => mine.props), ["class", "classList"]);
298
+ return [mine, first, second, other, user];
299
+ }
300
+ const ctx = solidJs.createContext(void 0, {
301
+ name: "on-case"
302
+ });
303
+ function On(props) {
304
+ const memo = memoProps(props);
305
+ const selector = solidJs.createSelector(() => memo.value, (a, b) => (memo.onCompare ?? solidJs.equalFn)(a, b));
306
+ return web.createComponent(ctx.Provider, {
307
+ value: selector,
308
+ get children() {
309
+ return props.children;
310
+ }
311
+ });
312
+ }
313
+ function Case(props) {
314
+ const selector = solidJs.useContext(ctx);
315
+ return web.createComponent(solidJs.Match, {
316
+ get when() {
317
+ return selector(props.value);
318
+ },
319
+ get children() {
320
+ return props.children;
321
+ }
322
+ });
323
+ }
324
+ class TransitionMonitor {
325
+ #signal = solidJs.createSignal(false);
326
+ /** Whether a transition is currently in progress */
327
+ get pending() {
328
+ return this.#signal[0]();
329
+ }
330
+ /**
331
+ * Starts waiting for the transition to end.
332
+ * This function should be called immediately before the transition is triggered.
333
+ * If a transition is already in progress, this function does nothing, allowing the object to keep monitoring the previous transition, but the returned {@link Promise} will not wait for the latter to complete
334
+ * @param ctrl The element on which the transition will occur
335
+ * @returns A {@link Promise} that resolves to whether monitoring completed successfully or was cancelled because a transition was already in progress
336
+ */
337
+ async start(ctrl) {
338
+ const [g, s] = this.#signal;
339
+ if (g())
340
+ return false;
341
+ s(true);
342
+ try {
343
+ await new Promise((t) => ctrl.addEventListener("transitionend", t, { once: true }));
344
+ } finally {
345
+ s(false);
346
+ }
347
+ return true;
348
+ }
349
+ }
290
350
  function SameContext(props) {
291
351
  return solidJs.createMemo(() => {
292
352
  solidJs.getOwner().context = props.owner.context;
@@ -303,8 +363,10 @@
303
363
  exports2.Extractor = Extractor;
304
364
  exports2.On = On;
305
365
  exports2.OrderedLinkedList = OrderedLinkedList;
366
+ exports2.Part = Part;
306
367
  exports2.SameContext = SameContext;
307
368
  exports2.Spread = Spread;
369
+ exports2.TransitionMonitor = TransitionMonitor;
308
370
  exports2.disposeWithOwner = disposeWithOwner;
309
371
  exports2.memoProps = memoProps;
310
372
  exports2.runWithContext = runWithContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",