solid-js 1.3.16 → 1.4.0-beta.1

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.
@@ -68,11 +68,14 @@ function proxyDescriptor(target, property) {
68
68
  desc.get = () => target[solidJs.$PROXY][property];
69
69
  return desc;
70
70
  }
71
- function ownKeys(target) {
71
+ function trackSelf(target) {
72
72
  if (solidJs.getListener()) {
73
73
  const nodes = getDataNodes(target);
74
74
  (nodes._ || (nodes._ = createDataNode()))();
75
75
  }
76
+ }
77
+ function ownKeys(target) {
78
+ trackSelf(target);
76
79
  return Reflect.ownKeys(target);
77
80
  }
78
81
  function createDataNode() {
@@ -89,18 +92,12 @@ const proxyTraps$1 = {
89
92
  if (property === solidJs.$PROXY) return receiver;
90
93
  const value = target[property];
91
94
  if (property === $NODE || property === "__proto__") return value;
92
- const wrappable = isWrappable(value);
95
+ if (property === solidJs.$TRACK) return trackSelf(target);
93
96
  if (solidJs.getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
94
- let nodes, node;
95
- if (wrappable && (nodes = getDataNodes(value))) {
96
- node = nodes._ || (nodes._ = createDataNode());
97
- node();
98
- }
99
- nodes = getDataNodes(target);
100
- node = nodes[property] || (nodes[property] = createDataNode());
101
- node();
97
+ const nodes = getDataNodes(target);
98
+ (nodes[property] || (nodes[property] = createDataNode()))();
102
99
  }
103
- return wrappable ? wrap$1(value) : value;
100
+ return isWrappable(value) ? wrap$1(value) : value;
104
101
  },
105
102
  set() {
106
103
  return true;
@@ -115,16 +112,14 @@ function setProperty(state, property, value) {
115
112
  if (state[property] === value) return;
116
113
  const array = Array.isArray(state);
117
114
  const len = state.length;
118
- const isUndefined = value === undefined;
119
- const notify = array || isUndefined === property in state;
120
- if (isUndefined) {
115
+ if (value === undefined) {
121
116
  delete state[property];
122
117
  } else state[property] = value;
123
118
  let nodes = getDataNodes(state),
124
119
  node;
125
120
  (node = nodes[property]) && node.$();
126
121
  if (array && state.length !== len) (node = nodes.length) && node.$();
127
- notify && (node = nodes._) && node.$();
122
+ (node = nodes._) && node.$();
128
123
  }
129
124
  function mergeStoreNode(state, value) {
130
125
  const keys = Object.keys(value);
@@ -133,6 +128,18 @@ function mergeStoreNode(state, value) {
133
128
  setProperty(state, key, value[key]);
134
129
  }
135
130
  }
131
+ function updateArray(current, next) {
132
+ if (typeof next === "function") next = next(current);
133
+ next = unwrap(next);
134
+ if (current === next) return;
135
+ let i = 0,
136
+ len = next.length;
137
+ for (; i < len; i++) {
138
+ const value = next[i];
139
+ if (current[i] !== value) setProperty(current, i, value);
140
+ }
141
+ setProperty(current, "length", len);
142
+ }
136
143
  function updatePath(current, path, traversed = []) {
137
144
  let part,
138
145
  prev = current;
@@ -180,9 +187,12 @@ function updatePath(current, path, traversed = []) {
180
187
  }
181
188
  function createStore(store, options) {
182
189
  const unwrappedStore = unwrap(store || {});
190
+ const isArray = Array.isArray(unwrappedStore);
183
191
  const wrappedStore = wrap$1(unwrappedStore);
184
192
  function setStore(...args) {
185
- solidJs.batch(() => updatePath(unwrappedStore, args));
193
+ solidJs.batch(() => {
194
+ isArray && args.length === 1 ? updateArray(unwrappedStore, args[0]) : updatePath(unwrappedStore, args);
195
+ });
186
196
  }
187
197
  return [wrappedStore, setStore];
188
198
  }
@@ -193,18 +203,14 @@ const proxyTraps = {
193
203
  if (property === solidJs.$PROXY) return receiver;
194
204
  const value = target[property];
195
205
  if (property === $NODE || property === "__proto__") return value;
196
- const wrappable = isWrappable(value);
206
+ if (property === solidJs.$TRACK) return trackSelf(target);
197
207
  if (solidJs.getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
198
- let nodes, node;
199
- if (wrappable && (nodes = getDataNodes(value))) {
200
- node = nodes._ || (nodes._ = createDataNode());
201
- node();
202
- }
203
- nodes = getDataNodes(target);
204
- node = nodes[property] || (nodes[property] = createDataNode());
205
- node();
208
+ const nodes = getDataNodes(target);
209
+ (nodes[property] || (nodes[property] = createDataNode()))();
210
+ } else if (value != null && typeof value === "function" && value === Array.prototype[property]) {
211
+ return (...args) => solidJs.batch(() => Array.prototype[property].apply(receiver, args));
206
212
  }
207
- return wrappable ? wrap(value) : value;
213
+ return isWrappable(value) ? wrap(value) : value;
208
214
  },
209
215
  set(target, property, value) {
210
216
  setProperty(target, property, unwrap(value));
@@ -249,6 +255,9 @@ function createMutable(state, options) {
249
255
  const wrappedStore = wrap(unwrappedStore);
250
256
  return wrappedStore;
251
257
  }
258
+ function modifyMutable(state, modifier) {
259
+ solidJs.batch(() => modifier(unwrap(state)));
260
+ }
252
261
 
253
262
  function applyState(target, parent, property, merge, key) {
254
263
  const previous = parent[property];
@@ -326,9 +335,9 @@ function reconcile(value, options = {}) {
326
335
  v = unwrap(value);
327
336
  return state => {
328
337
  if (!isWrappable(state) || !isWrappable(v)) return v;
329
- applyState(v, {
338
+ solidJs.batch(() => applyState(v, {
330
339
  state
331
- }, "state", merge, key);
340
+ }, "state", merge, key));
332
341
  return state;
333
342
  };
334
343
  }
@@ -353,10 +362,36 @@ function produce(fn) {
353
362
  return state;
354
363
  };
355
364
  }
365
+ function splice(start, deleteCount = 0, ...items) {
366
+ return state => {
367
+ if (Array.isArray(state)) {
368
+ if (start < 0) start = start + state.length;
369
+ if (deleteCount < 0) deleteCount = 0;
370
+ const stop = start + deleteCount;
371
+ if (deleteCount >= items.length) {
372
+ for (let i = stop; i < state.length; i++) {
373
+ setProperty(state, start + i - stop, state[i]);
374
+ }
375
+ } else {
376
+ const offset = items.length - deleteCount;
377
+ for (let i = state.length - 1; i >= stop; i--) {
378
+ setProperty(state, i + offset, state[i]);
379
+ }
380
+ }
381
+ for (let i = 0; i < items.length; i++) {
382
+ setProperty(state, start + i, items[i]);
383
+ }
384
+ setProperty(state, "length", state.length + items.length - deleteCount);
385
+ }
386
+ return state;
387
+ };
388
+ }
356
389
 
357
390
  exports.$RAW = $RAW;
358
391
  exports.createMutable = createMutable;
359
392
  exports.createStore = createStore;
393
+ exports.modifyMutable = modifyMutable;
360
394
  exports.produce = produce;
361
395
  exports.reconcile = reconcile;
396
+ exports.splice = splice;
362
397
  exports.unwrap = unwrap;
@@ -1,4 +1,4 @@
1
- import { $PROXY, getListener, batch, createSignal } from 'solid-js';
1
+ import { $PROXY, $TRACK, getListener, batch, createSignal } from 'solid-js';
2
2
 
3
3
  const $RAW = Symbol("store-raw"),
4
4
  $NODE = Symbol("store-node"),
@@ -64,11 +64,14 @@ function proxyDescriptor(target, property) {
64
64
  desc.get = () => target[$PROXY][property];
65
65
  return desc;
66
66
  }
67
- function ownKeys(target) {
67
+ function trackSelf(target) {
68
68
  if (getListener()) {
69
69
  const nodes = getDataNodes(target);
70
70
  (nodes._ || (nodes._ = createDataNode()))();
71
71
  }
72
+ }
73
+ function ownKeys(target) {
74
+ trackSelf(target);
72
75
  return Reflect.ownKeys(target);
73
76
  }
74
77
  function createDataNode() {
@@ -85,18 +88,12 @@ const proxyTraps$1 = {
85
88
  if (property === $PROXY) return receiver;
86
89
  const value = target[property];
87
90
  if (property === $NODE || property === "__proto__") return value;
88
- const wrappable = isWrappable(value);
91
+ if (property === $TRACK) return trackSelf(target);
89
92
  if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
90
- let nodes, node;
91
- if (wrappable && (nodes = getDataNodes(value))) {
92
- node = nodes._ || (nodes._ = createDataNode());
93
- node();
94
- }
95
- nodes = getDataNodes(target);
96
- node = nodes[property] || (nodes[property] = createDataNode());
97
- node();
93
+ const nodes = getDataNodes(target);
94
+ (nodes[property] || (nodes[property] = createDataNode()))();
98
95
  }
99
- return wrappable ? wrap$1(value) : value;
96
+ return isWrappable(value) ? wrap$1(value) : value;
100
97
  },
101
98
  set() {
102
99
  return true;
@@ -111,16 +108,14 @@ function setProperty(state, property, value) {
111
108
  if (state[property] === value) return;
112
109
  const array = Array.isArray(state);
113
110
  const len = state.length;
114
- const isUndefined = value === undefined;
115
- const notify = array || isUndefined === property in state;
116
- if (isUndefined) {
111
+ if (value === undefined) {
117
112
  delete state[property];
118
113
  } else state[property] = value;
119
114
  let nodes = getDataNodes(state),
120
115
  node;
121
116
  (node = nodes[property]) && node.$();
122
117
  if (array && state.length !== len) (node = nodes.length) && node.$();
123
- notify && (node = nodes._) && node.$();
118
+ (node = nodes._) && node.$();
124
119
  }
125
120
  function mergeStoreNode(state, value) {
126
121
  const keys = Object.keys(value);
@@ -129,6 +124,18 @@ function mergeStoreNode(state, value) {
129
124
  setProperty(state, key, value[key]);
130
125
  }
131
126
  }
127
+ function updateArray(current, next) {
128
+ if (typeof next === "function") next = next(current);
129
+ next = unwrap(next);
130
+ if (current === next) return;
131
+ let i = 0,
132
+ len = next.length;
133
+ for (; i < len; i++) {
134
+ const value = next[i];
135
+ if (current[i] !== value) setProperty(current, i, value);
136
+ }
137
+ setProperty(current, "length", len);
138
+ }
132
139
  function updatePath(current, path, traversed = []) {
133
140
  let part,
134
141
  prev = current;
@@ -176,9 +183,12 @@ function updatePath(current, path, traversed = []) {
176
183
  }
177
184
  function createStore(store, options) {
178
185
  const unwrappedStore = unwrap(store || {});
186
+ const isArray = Array.isArray(unwrappedStore);
179
187
  const wrappedStore = wrap$1(unwrappedStore);
180
188
  function setStore(...args) {
181
- batch(() => updatePath(unwrappedStore, args));
189
+ batch(() => {
190
+ isArray && args.length === 1 ? updateArray(unwrappedStore, args[0]) : updatePath(unwrappedStore, args);
191
+ });
182
192
  }
183
193
  return [wrappedStore, setStore];
184
194
  }
@@ -189,18 +199,14 @@ const proxyTraps = {
189
199
  if (property === $PROXY) return receiver;
190
200
  const value = target[property];
191
201
  if (property === $NODE || property === "__proto__") return value;
192
- const wrappable = isWrappable(value);
202
+ if (property === $TRACK) return trackSelf(target);
193
203
  if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
194
- let nodes, node;
195
- if (wrappable && (nodes = getDataNodes(value))) {
196
- node = nodes._ || (nodes._ = createDataNode());
197
- node();
198
- }
199
- nodes = getDataNodes(target);
200
- node = nodes[property] || (nodes[property] = createDataNode());
201
- node();
204
+ const nodes = getDataNodes(target);
205
+ (nodes[property] || (nodes[property] = createDataNode()))();
206
+ } else if (value != null && typeof value === "function" && value === Array.prototype[property]) {
207
+ return (...args) => batch(() => Array.prototype[property].apply(receiver, args));
202
208
  }
203
- return wrappable ? wrap(value) : value;
209
+ return isWrappable(value) ? wrap(value) : value;
204
210
  },
205
211
  set(target, property, value) {
206
212
  setProperty(target, property, unwrap(value));
@@ -245,6 +251,9 @@ function createMutable(state, options) {
245
251
  const wrappedStore = wrap(unwrappedStore);
246
252
  return wrappedStore;
247
253
  }
254
+ function modifyMutable(state, modifier) {
255
+ batch(() => modifier(unwrap(state)));
256
+ }
248
257
 
249
258
  function applyState(target, parent, property, merge, key) {
250
259
  const previous = parent[property];
@@ -322,9 +331,9 @@ function reconcile(value, options = {}) {
322
331
  v = unwrap(value);
323
332
  return state => {
324
333
  if (!isWrappable(state) || !isWrappable(v)) return v;
325
- applyState(v, {
334
+ batch(() => applyState(v, {
326
335
  state
327
- }, "state", merge, key);
336
+ }, "state", merge, key));
328
337
  return state;
329
338
  };
330
339
  }
@@ -349,5 +358,29 @@ function produce(fn) {
349
358
  return state;
350
359
  };
351
360
  }
361
+ function splice(start, deleteCount = 0, ...items) {
362
+ return state => {
363
+ if (Array.isArray(state)) {
364
+ if (start < 0) start = start + state.length;
365
+ if (deleteCount < 0) deleteCount = 0;
366
+ const stop = start + deleteCount;
367
+ if (deleteCount >= items.length) {
368
+ for (let i = stop; i < state.length; i++) {
369
+ setProperty(state, start + i - stop, state[i]);
370
+ }
371
+ } else {
372
+ const offset = items.length - deleteCount;
373
+ for (let i = state.length - 1; i >= stop; i--) {
374
+ setProperty(state, i + offset, state[i]);
375
+ }
376
+ }
377
+ for (let i = 0; i < items.length; i++) {
378
+ setProperty(state, start + i, items[i]);
379
+ }
380
+ setProperty(state, "length", state.length + items.length - deleteCount);
381
+ }
382
+ return state;
383
+ };
384
+ }
352
385
 
353
- export { $RAW, createMutable, createStore, produce, reconcile, unwrap };
386
+ export { $RAW, createMutable, createStore, modifyMutable, produce, reconcile, splice, unwrap };
@@ -5,3 +5,4 @@ export declare type ReconcileOptions = {
5
5
  };
6
6
  export declare function reconcile<T extends U, U>(value: T, options?: ReconcileOptions): (state: U) => T;
7
7
  export declare function produce<T>(fn: (state: DeepMutable<T>) => void): (state: T) => T;
8
+ export declare function splice<T extends U, U>(start: number, deleteCount?: number, ...items: T[]): (state: readonly U[]) => T[];
@@ -2,3 +2,4 @@ import { StoreNode } from "./store";
2
2
  export declare function createMutable<T extends StoreNode>(state: T, options?: {
3
3
  name?: string;
4
4
  }): T;
5
+ export declare function modifyMutable<T extends U, U>(state: T, modifier: (state: U) => T): void;
@@ -11,6 +11,7 @@ export declare function isWrappable(obj: any): any;
11
11
  export declare function unwrap<T extends StoreNode>(item: any, set?: Set<unknown>): T;
12
12
  export declare function getDataNodes(target: StoreNode): any;
13
13
  export declare function proxyDescriptor(target: StoreNode, property: PropertyKey): PropertyDescriptor | undefined;
14
+ export declare function trackSelf(target: StoreNode): void;
14
15
  export declare function ownKeys(target: StoreNode): (string | symbol)[];
15
16
  export declare function createDataNode(): Accessor<void> & {
16
17
  $: () => void;
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { createRoot, createSignal, createEffect, createRenderEffect, createComputed, createReaction, createDeferred, createSelector, createMemo, createResource, onMount, onCleanup, onError, untrack, batch, on, enableScheduling, enableExternalSource, startTransition, useTransition, refetchResources, createContext, useContext, children, getListener, getOwner, runWithOwner, equalFn, $DEVCOMP, $PROXY } from "./reactive/signal";
1
+ export { createRoot, createSignal, createEffect, createRenderEffect, createComputed, createReaction, createDeferred, createSelector, createMemo, createResource, onMount, onCleanup, onError, untrack, batch, on, enableScheduling, enableExternalSource, startTransition, useTransition, createContext, useContext, children, getListener, getOwner, runWithOwner, equalFn, $DEVCOMP, $PROXY, $TRACK } from "./reactive/signal";
2
2
  export type { Accessor, Setter, Signal, Resource, ResourceReturn, ResourceFetcher, ResourceFetcherInfo, Context, ReturnTypes } from "./reactive/signal";
3
3
  export * from "./reactive/observable";
4
4
  export * from "./reactive/scheduler";
package/types/jsx.d.ts CHANGED
@@ -23,7 +23,6 @@ export namespace JSX {
23
23
  interface ElementClass {
24
24
  // empty, libs can define requirements downstream
25
25
  }
26
- type LibraryManagedAttributes<Component, Props> = Props;
27
26
  interface ElementAttributesProperty {
28
27
  // empty, libs can define requirements downstream
29
28
  }
@@ -59,7 +58,11 @@ export namespace JSX {
59
58
  };
60
59
  $ServerOnly?: boolean;
61
60
  }
61
+ type Accessor<T> = () => T
62
62
  interface Directives {}
63
+ interface DirectiveFunctions {
64
+ [x: string]: (el: Element, accessor: Accessor<any>) => void;
65
+ }
63
66
  interface ExplicitProperties {}
64
67
  interface ExplicitAttributes {}
65
68
  interface CustomEvents {}
@@ -67,6 +70,20 @@ export namespace JSX {
67
70
  type DirectiveAttributes = {
68
71
  [Key in keyof Directives as `use:${Key}`]?: Directives[Key];
69
72
  };
73
+ type DirectiveFunctionAttributes<T> = {
74
+ [K in keyof DirectiveFunctions as string extends K ? never : `use:${K}`]?: DirectiveFunctions[K] extends (
75
+ el: infer E, // will be unknown if not provided
76
+ ...rest: infer R // use rest so that we can check whether it's provided or not
77
+ ) => void
78
+ ? T extends E // everything extends unknown if E is unknown
79
+ ? R extends [infer A] // check if has accessor provided
80
+ ? A extends Accessor<infer V>
81
+ ? V // it's an accessor
82
+ : never // it isn't, type error
83
+ : true // no accessor provided
84
+ : never // T is the wrong element
85
+ : never; // it isn't a function
86
+ };
70
87
  type PropAttributes = {
71
88
  [Key in keyof ExplicitProperties as `prop:${Key}`]?: ExplicitProperties[Key];
72
89
  };
@@ -79,7 +96,7 @@ export namespace JSX {
79
96
  type OnCaptureAttributes<T> = {
80
97
  [Key in keyof CustomCaptureEvents as `oncapture:${Key}`]?: EventHandler<T, CustomCaptureEvents[Key]>;
81
98
  }
82
- interface DOMAttributes<T> extends CustomAttributes<T>, DirectiveAttributes, PropAttributes, AttrAttributes, OnAttributes<T>, OnCaptureAttributes<T> {
99
+ interface DOMAttributes<T> extends CustomAttributes<T>, DirectiveAttributes, DirectiveFunctionAttributes<T>, PropAttributes, AttrAttributes, OnAttributes<T>, OnCaptureAttributes<T> {
83
100
  children?: Element;
84
101
  innerHTML?: string;
85
102
  innerText?: string | number;
@@ -1906,7 +1923,6 @@ export namespace JSX {
1906
1923
 
1907
1924
  interface HTMLAttributes<T> extends AriaAttributes, DOMAttributes<T> {
1908
1925
  accessKey?: string;
1909
- className?: string;
1910
1926
  class?: string;
1911
1927
  contenteditable?: boolean | "inherit";
1912
1928
  contextmenu?: string;
@@ -2207,7 +2223,6 @@ export namespace JSX {
2207
2223
  name?: string;
2208
2224
  }
2209
2225
  interface LabelHTMLAttributes<T> extends HTMLAttributes<T> {
2210
- htmlFor?: string;
2211
2226
  for?: string;
2212
2227
  form?: string;
2213
2228
  }
@@ -2294,7 +2309,6 @@ export namespace JSX {
2294
2309
  }
2295
2310
  interface OutputHTMLAttributes<T> extends HTMLAttributes<T> {
2296
2311
  form?: string;
2297
- htmlFor?: string;
2298
2312
  for?: string;
2299
2313
  name?: string;
2300
2314
  }
@@ -2468,7 +2482,6 @@ export namespace JSX {
2468
2482
  }
2469
2483
  interface StylableSVGAttributes {
2470
2484
  class?: string;
2471
- className?: string;
2472
2485
  style?: CSSProperties | string;
2473
2486
  }
2474
2487
  interface TransformableSVGAttributes {
@@ -1,7 +1,9 @@
1
1
  import { requestCallback } from "./scheduler";
2
2
  import type { JSX } from "../jsx";
3
+ import type { FlowComponent } from "../render";
3
4
  export declare const equalFn: <T>(a: T, b: T) => boolean;
4
5
  export declare const $PROXY: unique symbol;
6
+ export declare const $TRACK: unique symbol;
5
7
  export declare const $DEVCOMP: unique symbol;
6
8
  export declare const NOTPENDING: {};
7
9
  export declare var Owner: Owner | null;
@@ -70,7 +72,7 @@ export declare type RootFunction<T> = (dispose: () => void) => T;
70
72
  */
71
73
  export declare function createRoot<T>(fn: RootFunction<T>, detachedOwner?: Owner): T;
72
74
  export declare type Accessor<T> = () => T;
73
- export declare type Setter<T> = (undefined extends T ? (value?: undefined) => undefined : {}) & (<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)) => U);
75
+ export declare type Setter<T> = (undefined extends T ? () => undefined : {}) & (<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)) => U);
74
76
  export declare type Signal<T> = [get: Accessor<T>, set: Setter<T>];
75
77
  export interface SignalOptions<T> extends MemoOptions<T> {
76
78
  internal?: boolean;
@@ -122,8 +124,8 @@ export declare type EffectFunction<Prev, Next extends Prev = Prev> = (v: Prev) =
122
124
  *
123
125
  * @description https://www.solidjs.com/docs/latest/api#createcomputed
124
126
  */
127
+ export declare function createComputed<Next>(fn: EffectFunction<undefined | NoInfer<Next>, Next>): void;
125
128
  export declare function createComputed<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
126
- export declare function createComputed<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
127
129
  /**
128
130
  * Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
129
131
  * ```typescript
@@ -139,8 +141,8 @@ export declare function createComputed<Next, Init = undefined>(..._: undefined e
139
141
  *
140
142
  * @description https://www.solidjs.com/docs/latest/api#createrendereffect
141
143
  */
144
+ export declare function createRenderEffect<Next>(fn: EffectFunction<undefined | NoInfer<Next>, Next>): void;
142
145
  export declare function createRenderEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
143
- export declare function createRenderEffect<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
144
146
  /**
145
147
  * Creates a reactive computation that runs after the render phase
146
148
  * ```typescript
@@ -156,8 +158,8 @@ export declare function createRenderEffect<Next, Init = undefined>(..._: undefin
156
158
  *
157
159
  * @description https://www.solidjs.com/docs/latest/api#createeffect
158
160
  */
161
+ export declare function createEffect<Next>(fn: EffectFunction<undefined | NoInfer<Next>, Next>): void;
159
162
  export declare function createEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
160
- export declare function createEffect<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
161
163
  /**
162
164
  * Creates a reactive computation that runs after the render phase with flexible tracking
163
165
  * ```typescript
@@ -193,11 +195,12 @@ export interface MemoOptions<T> extends EffectOptions {
193
195
  *
194
196
  * @description https://www.solidjs.com/docs/latest/api#creatememo
195
197
  */
196
- export declare function createMemo<Next extends _Next, Init = Next, _Next = Next>(fn: EffectFunction<Init | _Next, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
197
- export declare function createMemo<Next extends _Next, Init = undefined, _Next = Next>(..._: undefined extends Init ? [fn: EffectFunction<Init | _Next, Next>, value?: Init, options?: MemoOptions<Next>] : [fn: EffectFunction<Init | _Next, Next>, value: Init, options?: MemoOptions<Next>]): Accessor<Next>;
198
+ export declare function createMemo<Next extends Prev, Prev = Next>(fn: EffectFunction<undefined | NoInfer<Prev>, Next>): Accessor<Next>;
199
+ export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>(fn: EffectFunction<Init | Prev, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
198
200
  export interface Resource<T> extends Accessor<T> {
199
201
  loading: boolean;
200
202
  error: any;
203
+ latest: T | undefined;
201
204
  }
202
205
  export declare type ResourceActions<T> = {
203
206
  mutate: Setter<T>;
@@ -213,12 +216,10 @@ export declare type ResourceFetcherInfo<T> = {
213
216
  export declare type ResourceOptions<T> = undefined extends T ? {
214
217
  initialValue?: T;
215
218
  name?: string;
216
- globalRefetch?: boolean;
217
219
  onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void;
218
220
  } : {
219
221
  initialValue: T;
220
222
  name?: string;
221
- globalRefetch?: boolean;
222
223
  onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void;
223
224
  };
224
225
  /**
@@ -250,7 +251,6 @@ export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S,
250
251
  export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
251
252
  export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
252
253
  export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
253
- export declare function refetchResources(info?: unknown): Promise<any[]>;
254
254
  export interface DeferredOptions<T> {
255
255
  equals?: false | ((prev: T, next: T) => boolean);
256
256
  name?: string;
@@ -402,10 +402,9 @@ interface GraphRecord {
402
402
  [k: string]: GraphRecord | unknown;
403
403
  }
404
404
  export declare function serializeGraph(owner?: Owner | null): GraphRecord;
405
- export declare type ContextProviderComponent<T> = (props: {
405
+ export declare type ContextProviderComponent<T> = FlowComponent<{
406
406
  value: T;
407
- children: any;
408
- }) => any;
407
+ }>;
409
408
  export interface Context<T> {
410
409
  id: symbol;
411
410
  Provider: ContextProviderComponent<T>;
@@ -416,7 +415,7 @@ export interface Context<T> {
416
415
  * ```typescript
417
416
  * interface Context<T> {
418
417
  * id: symbol;
419
- * Provider: (props: { value: T; children: any }) => any;
418
+ * Provider: FlowComponent<{ value: T }>;
420
419
  * defaultValue: T;
421
420
  * }
422
421
  * export function createContext<T>(defaultValue?: T): Context<T | undefined>;
@@ -1,9 +1,56 @@
1
1
  import type { JSX } from "../jsx";
2
2
  export declare function enableHydration(): void;
3
- export declare type PropsWithChildren<P = {}> = P & {
3
+ /**
4
+ * A general `Component` has no implicit `children` prop. If desired, you can
5
+ * specify one as in `Component<{name: String, children: JSX.Element>}`.
6
+ */
7
+ export declare type Component<P = {}> = (props: P) => JSX.Element;
8
+ /**
9
+ * Extend props to forbid the `children` prop.
10
+ * Use this to prevent accidentally passing `children` to components that
11
+ * would silently throw them away.
12
+ */
13
+ export declare type VoidProps<P = {}> = P & {
14
+ children?: never;
15
+ };
16
+ /**
17
+ * `VoidComponent` forbids the `children` prop.
18
+ * Use this to prevent accidentally passing `children` to components that
19
+ * would silently throw them away.
20
+ */
21
+ export declare type VoidComponent<P = {}> = Component<VoidProps<P>>;
22
+ /**
23
+ * Extend props to allow an optional `children` prop with the usual
24
+ * type in JSX, `JSX.Element` (which allows elements, arrays, functions, etc.).
25
+ * Use this for components that you want to accept children.
26
+ */
27
+ export declare type ParentProps<P = {}> = P & {
4
28
  children?: JSX.Element;
5
29
  };
6
- export declare type Component<P = {}> = (props: PropsWithChildren<P>) => JSX.Element;
30
+ /**
31
+ * `ParentComponent` allows an optional `children` prop with the usual
32
+ * type in JSX, `JSX.Element` (which allows elements, arrays, functions, etc.).
33
+ * Use this for components that you want to accept children.
34
+ */
35
+ export declare type ParentComponent<P = {}> = Component<ParentProps<P>>;
36
+ /**
37
+ * Extend props to require a `children` prop with the specified type.
38
+ * Use this for components where you need a specific child type,
39
+ * typically a function that receives specific argument types.
40
+ * Note that all JSX <Elements> are of the type `JSX.Element`.
41
+ */
42
+ export declare type FlowProps<P = {}, C = JSX.Element> = P & {
43
+ children: C;
44
+ };
45
+ /**
46
+ * `FlowComponent` requires a `children` prop with the specified type.
47
+ * Use this for components where you need a specific child type,
48
+ * typically a function that receives specific argument types.
49
+ * Note that all JSX <Elements> are of the type `JSX.Element`.
50
+ */
51
+ export declare type FlowComponent<P = {}, C = JSX.Element> = Component<FlowProps<P, C>>;
52
+ /** @deprecated: use `ParentProps` instead */
53
+ export declare type PropsWithChildren<P = {}> = ParentProps<P>;
7
54
  /**
8
55
  * Takes the props of the passed component and returns its type
9
56
  *
@@ -12,7 +59,13 @@ export declare type Component<P = {}> = (props: PropsWithChildren<P>) => JSX.Ele
12
59
  * ComponentProps<'div'> // JSX.HTMLAttributes<HTMLDivElement>
13
60
  */
14
61
  export declare type ComponentProps<T extends keyof JSX.IntrinsicElements | Component<any>> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : {};
15
- export declare function createComponent<T>(Comp: (props: T) => JSX.Element, props: T): JSX.Element;
62
+ /**
63
+ * Type of `props.ref`, for use in `Component` or `props` typing.
64
+ *
65
+ * @example Component<{ref: Ref<Element>}>
66
+ */
67
+ export declare type Ref<T> = T | ((val: T) => void);
68
+ export declare function createComponent<T>(Comp: Component<T>, props: T): JSX.Element;
16
69
  declare type UnboxLazy<T> = T extends () => infer U ? U : T;
17
70
  declare type BoxedTupleTypes<T extends any[]> = {
18
71
  [P in keyof T]: [UnboxLazy<T[P]>];
@@ -23,18 +76,13 @@ declare type UnboxIntersection<T> = T extends {
23
76
  } ? U : never;
24
77
  declare type MergeProps<T extends any[]> = UnboxIntersection<UnionToIntersection<BoxedTupleTypes<T>>>;
25
78
  export declare function mergeProps<T extends any[]>(...sources: T): MergeProps<T>;
26
- export declare function splitProps<T extends object, K1 extends keyof T>(props: T, ...keys: [K1[]]): [Pick<T, K1>, Omit<T, K1>];
27
- export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T>(props: T, ...keys: [K1[], K2[]]): [Pick<T, K1>, Pick<T, K2>, Omit<T, K1 | K2>];
28
- export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Omit<T, K1 | K2 | K3>];
29
- export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[], K4[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Pick<T, K4>, Omit<T, K1 | K2 | K3 | K4>];
30
- export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T, K5 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[], K4[], K5[]]): [
31
- Pick<T, K1>,
32
- Pick<T, K2>,
33
- Pick<T, K3>,
34
- Pick<T, K4>,
35
- Pick<T, K5>,
36
- Omit<T, K1 | K2 | K3 | K4 | K5>
79
+ declare type SplitProps<T, K extends (readonly (keyof T)[])[]> = [
80
+ ...{
81
+ [P in keyof K]: P extends `${number}` ? Pick<T, Extract<K[P], readonly (keyof T)[]>[number]> : K[P];
82
+ },
83
+ Omit<T, K[number][number]>
37
84
  ];
85
+ export declare function splitProps<T, K extends [readonly (keyof T)[], ...(readonly (keyof T)[])[]]>(props: T, ...keys: K): SplitProps<T, K>;
38
86
  export declare function lazy<T extends Component<any>>(fn: () => Promise<{
39
87
  default: T;
40
88
  }>): T & {
@@ -1,3 +1,3 @@
1
1
  export { createRoot, createSignal, createComputed, createRenderEffect, createEffect, createReaction, createDeferred, createSelector, createMemo, getListener, onMount, onCleanup, onError, untrack, batch, on, children, createContext, useContext, getOwner, runWithOwner, equalFn, requestCallback, mapArray, observable, from, $PROXY, $DEVCOMP, DEV, enableExternalSource } from "./reactive";
2
- export { mergeProps, splitProps, createComponent, For, Index, Show, Switch, Match, ErrorBoundary, Suspense, SuspenseList, createResource, refetchResources, resetErrorBoundaries, enableScheduling, enableHydration, startTransition, useTransition, createUniqueId, lazy, sharedConfig } from "./rendering";
2
+ export { mergeProps, splitProps, createComponent, For, Index, Show, Switch, Match, ErrorBoundary, Suspense, SuspenseList, createResource, resetErrorBoundaries, enableScheduling, enableHydration, startTransition, useTransition, createUniqueId, lazy, sharedConfig } from "./rendering";
3
3
  export type { Component, Resource } from "./rendering";