solid-ctrl-flow 1.0.27 → 1.0.28

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
@@ -2,6 +2,7 @@ import { Accessor } from 'solid-js';
2
2
  import { Context } from 'solid-js';
3
3
  import { EffectFunction } from 'solid-js';
4
4
  import { JSX } from 'solid-js';
5
+ import { Ref } from 'solid-js';
5
6
  import { Resource } from 'solid-js';
6
7
  import { Setter } from 'solid-js';
7
8
  import { Signal } from 'solid-js';
@@ -156,6 +157,11 @@ export declare const Debug: {
156
157
  read: Accessor<boolean>;
157
158
  };
158
159
 
160
+ /** Component that gives you the owner {@link Document} */
161
+ export declare function Doc(props: {
162
+ ref: Ref<Document>;
163
+ }): Text;
164
+
159
165
  /** Informations about a {@link Source} component */
160
166
  declare type Info = {
161
167
  /** Order of the current source if there are many */
@@ -171,6 +177,15 @@ declare type Info = {
171
177
  */
172
178
  export declare function memoProps<T, K extends readonly (keyof T)[] = (keyof T)[]>(obj: T, keys?: K): Pick<T, K[number]>;
173
179
 
180
+ /**
181
+ * Executes a {@link Ref}.
182
+ * Throws a {@link ReferenceError} if {@link ref} its not a function at runtime (Which should never be the case thanks to the solid compiler)
183
+ * @param ref The function to execute
184
+ * @param value The value to pass to the function
185
+ * @returns The same value of {@link value}
186
+ */
187
+ export declare function refCall<T, U extends T = T>(ref: Ref<T> | undefined, value: U): U;
188
+
174
189
  /**
175
190
  * Executes {@link f} with the provided {@link Context}
176
191
  * @param ctx The context to which to set the value
package/dist/index.mjs CHANGED
@@ -1,8 +1,16 @@
1
- import { untrack, createMemo, splitProps, createEffect, on, createResource, createContext, createRoot, getOwner, createComponent, useContext, createRenderEffect, onCleanup, Match, mergeProps, For, Show } from "solid-js";
1
+ import { untrack, createMemo, splitProps, createContext, createRoot, getOwner, createEffect, on, createResource, createComponent, useContext, createRenderEffect, onCleanup, Match, mergeProps, For, Show, onMount } from "solid-js";
2
2
  import { createMutable } from "solid-js/store";
3
3
  function untrackCall(f, ...args) {
4
4
  return untrack(() => f.apply(this, args));
5
5
  }
6
+ function refCall(ref, value) {
7
+ if (!ref)
8
+ return value;
9
+ if (typeof ref !== "function")
10
+ throw new ReferenceError('Il parametro "ref" deve essere stato compilato in una funzione a runtime');
11
+ ref(value);
12
+ return value;
13
+ }
6
14
  function memoProps(obj, keys = Object.keys(obj)) {
7
15
  const out = {};
8
16
  for (const elm of keys)
@@ -17,15 +25,6 @@ function splitAndMemoProps(obj, keys) {
17
25
  out[0] = memoProps(out[0], keys);
18
26
  return out;
19
27
  }
20
- function createReactiveResource(f) {
21
- var refetch;
22
- const memo = createMemo(f);
23
- createEffect(on(memo, () => refetch?.()));
24
- const [get] = [, {
25
- refetch
26
- }] = createResource(memo);
27
- return get;
28
- }
29
28
  function createOption(init, def = init, name) {
30
29
  const prop = "read";
31
30
  const ctx2 = createContext(() => init, {
@@ -58,6 +57,15 @@ function runWithContext(ctx2, value, f) {
58
57
  }
59
58
  });
60
59
  }
60
+ function createReactiveResource(f) {
61
+ var refetch;
62
+ const memo = createMemo(f);
63
+ createEffect(on(memo, () => refetch?.()));
64
+ const [get] = [, {
65
+ refetch
66
+ }] = createResource(memo);
67
+ return get;
68
+ }
61
69
  const IDENTITY = (x) => x;
62
70
  function bind([get], [, set], to = IDENTITY) {
63
71
  const d = createRoot((d2) => (createRenderEffect(on(get, (x) => set((prev) => to(x, prev)))), d2));
@@ -180,9 +188,15 @@ function Joint(props) {
180
188
  });
181
189
  }
182
190
  const Debug = createOption(false, true, "debug-scope");
191
+ function Doc(props) {
192
+ const node = document.createTextNode("");
193
+ onMount(() => (refCall(props.ref, node.ownerDocument), node.remove()));
194
+ return node;
195
+ }
183
196
  export {
184
197
  Case,
185
198
  Debug,
199
+ Doc,
186
200
  When,
187
201
  bind,
188
202
  bindTwoWay,
@@ -191,6 +205,7 @@ export {
191
205
  createOption,
192
206
  createReactiveResource,
193
207
  memoProps,
208
+ refCall,
194
209
  runWithContext,
195
210
  splitAndMemoProps,
196
211
  toSetter,
package/dist/index.umd.js CHANGED
@@ -5,6 +5,14 @@
5
5
  function untrackCall(f, ...args) {
6
6
  return solidJs.untrack(() => f.apply(this, args));
7
7
  }
8
+ function refCall(ref, value) {
9
+ if (!ref)
10
+ return value;
11
+ if (typeof ref !== "function")
12
+ throw new ReferenceError('Il parametro "ref" deve essere stato compilato in una funzione a runtime');
13
+ ref(value);
14
+ return value;
15
+ }
8
16
  function memoProps(obj, keys = Object.keys(obj)) {
9
17
  const out = {};
10
18
  for (const elm of keys)
@@ -19,15 +27,6 @@
19
27
  out[0] = memoProps(out[0], keys);
20
28
  return out;
21
29
  }
22
- function createReactiveResource(f) {
23
- var refetch;
24
- const memo = solidJs.createMemo(f);
25
- solidJs.createEffect(solidJs.on(memo, () => refetch?.()));
26
- const [get] = [, {
27
- refetch
28
- }] = solidJs.createResource(memo);
29
- return get;
30
- }
31
30
  function createOption(init, def = init, name) {
32
31
  const prop = "read";
33
32
  const ctx2 = solidJs.createContext(() => init, {
@@ -60,6 +59,15 @@
60
59
  }
61
60
  });
62
61
  }
62
+ function createReactiveResource(f) {
63
+ var refetch;
64
+ const memo = solidJs.createMemo(f);
65
+ solidJs.createEffect(solidJs.on(memo, () => refetch?.()));
66
+ const [get] = [, {
67
+ refetch
68
+ }] = solidJs.createResource(memo);
69
+ return get;
70
+ }
63
71
  const IDENTITY = (x) => x;
64
72
  function bind([get], [, set], to = IDENTITY) {
65
73
  const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(get, (x) => set((prev) => to(x, prev)))), d2));
@@ -182,8 +190,14 @@
182
190
  });
183
191
  }
184
192
  const Debug = createOption(false, true, "debug-scope");
193
+ function Doc(props) {
194
+ const node = document.createTextNode("");
195
+ solidJs.onMount(() => (refCall(props.ref, node.ownerDocument), node.remove()));
196
+ return node;
197
+ }
185
198
  exports2.Case = Case;
186
199
  exports2.Debug = Debug;
200
+ exports2.Doc = Doc;
187
201
  exports2.When = When;
188
202
  exports2.bind = bind;
189
203
  exports2.bindTwoWay = bindTwoWay;
@@ -192,6 +206,7 @@
192
206
  exports2.createOption = createOption;
193
207
  exports2.createReactiveResource = createReactiveResource;
194
208
  exports2.memoProps = memoProps;
209
+ exports2.refCall = refCall;
195
210
  exports2.runWithContext = runWithContext;
196
211
  exports2.splitAndMemoProps = splitAndMemoProps;
197
212
  exports2.toSetter = toSetter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
package/readMe.md CHANGED
@@ -47,6 +47,15 @@ return <>
47
47
  </>
48
48
  ```
49
49
 
50
+ ### `Doc`
51
+ Gives back the current document
52
+ ```tsx
53
+ var doc: Document;
54
+ return <>
55
+ <Doc ref={doc} />
56
+ </>
57
+ ```
58
+
50
59
  ### `createExtractor()`
51
60
  Creates a context for components that may need to be out of their parent in certain conditions.
52
61
  If you have this component
@@ -148,17 +157,20 @@ Utility functions needed for the components above
148
157
  ### `untrackCall()`
149
158
  Calls a function untracking what happens inside of it but not what gets passed as its argument
150
159
 
160
+ ### `refCall()`
161
+ Executes a `Ref`
162
+
151
163
  ### `memoProps()`
152
164
  Creates a partial version of an object with memoized remaining properties
153
165
 
154
166
  ### `splitAndMemoProps()`
155
167
  Like `splitProps()` but memoizes the whole local part
156
168
 
157
- ### `createReactiveResource()`
158
- Like `createResource()` but the provided function will be reactive
159
-
160
169
  ### `createOption()`
161
170
  Allows you to create simple reactive contexts; For example `Debug` is made with it
162
171
 
163
172
  ### `runWithContext()`
164
- Creates a context scope that persists for the duration of a function
173
+ Creates a context scope that persists for the duration of a function
174
+
175
+ ### `createReactiveResource()`
176
+ Like `createResource()` but the provided function will be reactive