solid-js 1.1.7 → 1.2.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/dev.cjs +22 -12
- package/dist/dev.js +22 -12
- package/dist/server.cjs +1 -0
- package/dist/server.js +1 -1
- package/dist/solid.cjs +22 -12
- package/dist/solid.js +22 -12
- package/h/README.md +99 -0
- package/html/README.md +84 -0
- package/html/dist/html.cjs +24 -6
- package/html/dist/html.js +25 -7
- package/package.json +14 -2
- package/store/README.md +23 -0
- package/types/jsx.d.ts +5 -2
- package/types/render/component.d.ts +1 -1
- package/types/server/index.d.ts +1 -1
- package/universal/README.md +102 -0
- package/universal/dist/dev.cjs +258 -0
- package/universal/dist/dev.js +254 -0
- package/universal/dist/universal.cjs +258 -0
- package/universal/dist/universal.js +254 -0
- package/universal/package.json +8 -0
- package/universal/types/index.d.ts +2 -0
- package/universal/types/universal.d.ts +29 -0
- package/web/README.md +7 -0
- package/web/types/client.d.ts +1 -1
package/html/dist/html.cjs
CHANGED
|
@@ -213,7 +213,7 @@ function createHTML(r, {
|
|
|
213
213
|
markup = markup + statics[i] + "<!--#-->";
|
|
214
214
|
}
|
|
215
215
|
markup = markup + statics[i];
|
|
216
|
-
markup = markup.replace(selfClosing, fullClosing).replace(/<(<!--#-->)/g, "<###").replace(attrSeeker, attrReplacer).replace(/>\n+\s*/g, ">").replace(/\n+\s*</g, "<").replace(/\s+</g, " <").replace(/>\s+/g, "> ");
|
|
216
|
+
markup = markup.replace(selfClosing, fullClosing).replace(/<(<!--#-->)/g, "<###").replace(/\.\.\.(<!--#-->)/g, "###").replace(attrSeeker, attrReplacer).replace(/>\n+\s*/g, ">").replace(/\n+\s*</g, "<").replace(/\s+</g, " <").replace(/>\s+/g, "> ");
|
|
217
217
|
const [html, code] = parseTemplate(parse(markup)),
|
|
218
218
|
templates = [];
|
|
219
219
|
for (let i = 0; i < html.length; i++) {
|
|
@@ -323,16 +323,29 @@ function createHTML(r, {
|
|
|
323
323
|
options.counter = childOptions.counter;
|
|
324
324
|
options.templateId = childOptions.templateId;
|
|
325
325
|
}
|
|
326
|
+
function processComponentProps(propGroups) {
|
|
327
|
+
let result = [];
|
|
328
|
+
for (const props of propGroups) {
|
|
329
|
+
if (Array.isArray(props)) {
|
|
330
|
+
if (!props.length) continue;
|
|
331
|
+
result.push(`r.wrapProps({${props.join(",") || ""}})`);
|
|
332
|
+
} else result.push(props);
|
|
333
|
+
}
|
|
334
|
+
return result.length > 1 ? `r.mergeProps(${result.join(",")})` : result[0];
|
|
335
|
+
}
|
|
326
336
|
function processComponent(node, options) {
|
|
337
|
+
let props = [];
|
|
327
338
|
const keys = Object.keys(node.attrs),
|
|
328
|
-
|
|
339
|
+
propGroups = [props],
|
|
329
340
|
componentIdentifier = options.counter++;
|
|
330
341
|
for (let i = 0; i < keys.length; i++) {
|
|
331
342
|
const name = keys[i],
|
|
332
343
|
value = node.attrs[name];
|
|
333
|
-
if (
|
|
334
|
-
|
|
335
|
-
|
|
344
|
+
if (name === "###") {
|
|
345
|
+
propGroups.push(`exprs[${options.counter++}]`);
|
|
346
|
+
propGroups.push(props = []);
|
|
347
|
+
} else if (value === "###") {
|
|
348
|
+
props.push(`${name}: exprs[${options.counter++}]`);
|
|
336
349
|
} else props.push(`${name}: "${value}"`);
|
|
337
350
|
}
|
|
338
351
|
if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") {
|
|
@@ -357,7 +370,7 @@ function createHTML(r, {
|
|
|
357
370
|
tag = `_$el${uuid++}`;
|
|
358
371
|
options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
|
|
359
372
|
}
|
|
360
|
-
if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}]
|
|
373
|
+
if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${tag ? `, ${tag}` : ""})`);else options.exprs.push(`${options.fragment ? "" : "return "}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`);
|
|
361
374
|
options.path = tag;
|
|
362
375
|
options.first = false;
|
|
363
376
|
}
|
|
@@ -410,6 +423,9 @@ function createHTML(r, {
|
|
|
410
423
|
if (value === "###") {
|
|
411
424
|
delete node.attrs[name];
|
|
412
425
|
parseAttribute(tag, name, isSVG, isCE, options);
|
|
426
|
+
} else if (name === "###") {
|
|
427
|
+
delete node.attrs[name];
|
|
428
|
+
options.exprs.push(`r.spread(${tag},exprs[${options.counter++}],${isSVG},${!!node.children.length})`);
|
|
413
429
|
}
|
|
414
430
|
}
|
|
415
431
|
options.path = tag;
|
|
@@ -470,9 +486,11 @@ var index = createHTML({
|
|
|
470
486
|
effect: web.effect,
|
|
471
487
|
style: web.style,
|
|
472
488
|
insert: web.insert,
|
|
489
|
+
spread: web.spread,
|
|
473
490
|
createComponent: web.createComponent,
|
|
474
491
|
delegateEvents: web.delegateEvents,
|
|
475
492
|
classList: web.classList,
|
|
493
|
+
mergeProps: web.mergeProps,
|
|
476
494
|
dynamicProperty: web.dynamicProperty,
|
|
477
495
|
setAttribute: web.setAttribute,
|
|
478
496
|
setAttributeNS: web.setAttributeNS,
|
package/html/dist/html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { effect, style, insert, createComponent, delegateEvents, classList, dynamicProperty, setAttribute, setAttributeNS, addEventListener, Aliases, PropAliases, Properties, ChildProperties, DelegatedEvents, SVGElements, SVGNamespace } from 'solid-js/web';
|
|
1
|
+
import { effect, style, insert, spread, createComponent, delegateEvents, classList, mergeProps, dynamicProperty, setAttribute, setAttributeNS, addEventListener, Aliases, PropAliases, Properties, ChildProperties, DelegatedEvents, SVGElements, SVGNamespace } from 'solid-js/web';
|
|
2
2
|
|
|
3
3
|
var attrRE, lookup, parseTag, pushCommentNode, pushTextNode, tagRE;
|
|
4
4
|
tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
|
|
@@ -211,7 +211,7 @@ function createHTML(r, {
|
|
|
211
211
|
markup = markup + statics[i] + "<!--#-->";
|
|
212
212
|
}
|
|
213
213
|
markup = markup + statics[i];
|
|
214
|
-
markup = markup.replace(selfClosing, fullClosing).replace(/<(<!--#-->)/g, "<###").replace(attrSeeker, attrReplacer).replace(/>\n+\s*/g, ">").replace(/\n+\s*</g, "<").replace(/\s+</g, " <").replace(/>\s+/g, "> ");
|
|
214
|
+
markup = markup.replace(selfClosing, fullClosing).replace(/<(<!--#-->)/g, "<###").replace(/\.\.\.(<!--#-->)/g, "###").replace(attrSeeker, attrReplacer).replace(/>\n+\s*/g, ">").replace(/\n+\s*</g, "<").replace(/\s+</g, " <").replace(/>\s+/g, "> ");
|
|
215
215
|
const [html, code] = parseTemplate(parse(markup)),
|
|
216
216
|
templates = [];
|
|
217
217
|
for (let i = 0; i < html.length; i++) {
|
|
@@ -321,16 +321,29 @@ function createHTML(r, {
|
|
|
321
321
|
options.counter = childOptions.counter;
|
|
322
322
|
options.templateId = childOptions.templateId;
|
|
323
323
|
}
|
|
324
|
+
function processComponentProps(propGroups) {
|
|
325
|
+
let result = [];
|
|
326
|
+
for (const props of propGroups) {
|
|
327
|
+
if (Array.isArray(props)) {
|
|
328
|
+
if (!props.length) continue;
|
|
329
|
+
result.push(`r.wrapProps({${props.join(",") || ""}})`);
|
|
330
|
+
} else result.push(props);
|
|
331
|
+
}
|
|
332
|
+
return result.length > 1 ? `r.mergeProps(${result.join(",")})` : result[0];
|
|
333
|
+
}
|
|
324
334
|
function processComponent(node, options) {
|
|
335
|
+
let props = [];
|
|
325
336
|
const keys = Object.keys(node.attrs),
|
|
326
|
-
|
|
337
|
+
propGroups = [props],
|
|
327
338
|
componentIdentifier = options.counter++;
|
|
328
339
|
for (let i = 0; i < keys.length; i++) {
|
|
329
340
|
const name = keys[i],
|
|
330
341
|
value = node.attrs[name];
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
|
|
342
|
+
if (name === "###") {
|
|
343
|
+
propGroups.push(`exprs[${options.counter++}]`);
|
|
344
|
+
propGroups.push(props = []);
|
|
345
|
+
} else if (value === "###") {
|
|
346
|
+
props.push(`${name}: exprs[${options.counter++}]`);
|
|
334
347
|
} else props.push(`${name}: "${value}"`);
|
|
335
348
|
}
|
|
336
349
|
if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") {
|
|
@@ -355,7 +368,7 @@ function createHTML(r, {
|
|
|
355
368
|
tag = `_$el${uuid++}`;
|
|
356
369
|
options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
|
|
357
370
|
}
|
|
358
|
-
if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}]
|
|
371
|
+
if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${tag ? `, ${tag}` : ""})`);else options.exprs.push(`${options.fragment ? "" : "return "}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`);
|
|
359
372
|
options.path = tag;
|
|
360
373
|
options.first = false;
|
|
361
374
|
}
|
|
@@ -408,6 +421,9 @@ function createHTML(r, {
|
|
|
408
421
|
if (value === "###") {
|
|
409
422
|
delete node.attrs[name];
|
|
410
423
|
parseAttribute(tag, name, isSVG, isCE, options);
|
|
424
|
+
} else if (name === "###") {
|
|
425
|
+
delete node.attrs[name];
|
|
426
|
+
options.exprs.push(`r.spread(${tag},exprs[${options.counter++}],${isSVG},${!!node.children.length})`);
|
|
411
427
|
}
|
|
412
428
|
}
|
|
413
429
|
options.path = tag;
|
|
@@ -468,9 +484,11 @@ var index = createHTML({
|
|
|
468
484
|
effect,
|
|
469
485
|
style,
|
|
470
486
|
insert,
|
|
487
|
+
spread,
|
|
471
488
|
createComponent,
|
|
472
489
|
delegateEvents,
|
|
473
490
|
classList,
|
|
491
|
+
mergeProps,
|
|
474
492
|
dynamicProperty,
|
|
475
493
|
setAttribute,
|
|
476
494
|
setAttributeNS,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-js",
|
|
3
3
|
"description": "A declarative JavaScript library for building user interfaces.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.2",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/solidjs/solid#readme",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"h/types",
|
|
30
30
|
"html/dist",
|
|
31
31
|
"html/types",
|
|
32
|
+
"universal/dist",
|
|
33
|
+
"universal/types",
|
|
32
34
|
"types",
|
|
33
35
|
"jsx-runtime.d.ts"
|
|
34
36
|
],
|
|
@@ -84,6 +86,15 @@
|
|
|
84
86
|
"require": "./web/dist/web.cjs"
|
|
85
87
|
},
|
|
86
88
|
"./web/dist/*": "./web/dist/*",
|
|
89
|
+
"./universal": {
|
|
90
|
+
"development": {
|
|
91
|
+
"import": "./universal/dist/dev.js",
|
|
92
|
+
"require": "./universal/dist/dev.cjs"
|
|
93
|
+
},
|
|
94
|
+
"import": "./universal/dist/universal.js",
|
|
95
|
+
"require": "./universal/dist/universal.cjs"
|
|
96
|
+
},
|
|
97
|
+
"./universal/dist/*": "./universal/dist/*",
|
|
87
98
|
"./h": {
|
|
88
99
|
"import": "./h/dist/h.js",
|
|
89
100
|
"require": "./h/dist/h.cjs"
|
|
@@ -106,6 +117,7 @@
|
|
|
106
117
|
"build:types-web": "tsc --project ./web/tsconfig.json && tsconfig-replace-paths --project ./web/tsconfig.types.json",
|
|
107
118
|
"build:types-html": "tsc --project ./html/tsconfig.json",
|
|
108
119
|
"build:types-h": "tsc --project ./h/tsconfig.json",
|
|
120
|
+
"build:types-universal": "tsc --project ./universal/tsconfig.json",
|
|
109
121
|
"bench": "node --allow-natives-syntax bench/bench.cjs",
|
|
110
122
|
"test": "jest && npm run test:types",
|
|
111
123
|
"test:coverage": "jest --coverage && npm run test:types",
|
|
@@ -120,5 +132,5 @@
|
|
|
120
132
|
"compiler",
|
|
121
133
|
"performance"
|
|
122
134
|
],
|
|
123
|
-
"gitHead": "
|
|
135
|
+
"gitHead": "116e636553b34a7bf9fc5d87402d0077d7f16e59"
|
|
124
136
|
}
|
package/store/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Solid Store
|
|
2
|
+
|
|
3
|
+
This submodules contains the means for handling deeps nested reactivity. It provides 2 main primitives `createStore` and `createMutable` which leverage proxies to create dynamic nested reactive structures.
|
|
4
|
+
|
|
5
|
+
This also contains helper methods `produce` and `reconcile` which augment the behavior of the store setter method to allow for localized mutationa and data diffing.
|
|
6
|
+
|
|
7
|
+
For full documentation, check out the [website](https://www.solidjs.com/docs/latest/api).
|
|
8
|
+
|
|
9
|
+
## Example
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { createStore } from "solid-js/store";
|
|
13
|
+
|
|
14
|
+
const [store, setStore] = createStore({
|
|
15
|
+
user: {
|
|
16
|
+
firstName: "John",
|
|
17
|
+
lastName: "Smith"
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// update store.user.firstName
|
|
22
|
+
setStore("user", "firstName", "Will");
|
|
23
|
+
```
|
package/types/jsx.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export namespace JSX {
|
|
|
11
11
|
| Node
|
|
12
12
|
| ArrayElement
|
|
13
13
|
| FunctionElement
|
|
14
|
-
| string
|
|
14
|
+
| (string & {})
|
|
15
15
|
| number
|
|
16
16
|
| boolean
|
|
17
17
|
| null
|
|
@@ -1674,6 +1674,7 @@ export namespace JSX {
|
|
|
1674
1674
|
| "unsafe-url";
|
|
1675
1675
|
type HTMLIframeSandbox =
|
|
1676
1676
|
| "allow-downloads-without-user-activation"
|
|
1677
|
+
| "allow-downloads"
|
|
1677
1678
|
| "allow-forms"
|
|
1678
1679
|
| "allow-modals"
|
|
1679
1680
|
| "allow-orientation-lock"
|
|
@@ -2873,7 +2874,8 @@ export namespace JSX {
|
|
|
2873
2874
|
extends FilterPrimitiveElementSVGAttributes<T>,
|
|
2874
2875
|
ExternalResourceSVGAttributes,
|
|
2875
2876
|
StylableSVGAttributes {
|
|
2876
|
-
preserveAspectRatio
|
|
2877
|
+
preserveAspectRatio?: SVGPreserveAspectRatio;
|
|
2878
|
+
href?: string;
|
|
2877
2879
|
}
|
|
2878
2880
|
interface FeMergeSVGAttributes<T>
|
|
2879
2881
|
extends FilterPrimitiveElementSVGAttributes<T>,
|
|
@@ -2976,6 +2978,7 @@ export namespace JSX {
|
|
|
2976
2978
|
width?: number | string;
|
|
2977
2979
|
height?: number | string;
|
|
2978
2980
|
preserveAspectRatio?: ImagePreserveAspectRatio;
|
|
2981
|
+
href?: string;
|
|
2979
2982
|
}
|
|
2980
2983
|
interface LineSVGAttributes<T>
|
|
2981
2984
|
extends GraphicsElementSVGAttributes<T>,
|
|
@@ -15,7 +15,7 @@ export declare function createComponent<T>(Comp: (props: T) => JSX.Element, prop
|
|
|
15
15
|
declare type BoxedTupleTypes<T extends any[]> = {
|
|
16
16
|
[P in keyof T]: [T[P]];
|
|
17
17
|
}[Exclude<keyof T, keyof any[]>];
|
|
18
|
-
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
18
|
+
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
19
19
|
declare type UnboxIntersection<T> = T extends {
|
|
20
20
|
0: infer U;
|
|
21
21
|
} ? U : never;
|
package/types/server/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createRoot, createSignal, createComputed, createRenderEffect, createEffect, createDeferred, createSelector, createMemo, getListener, onMount, onCleanup, onError, untrack, batch, on, createContext, useContext, getOwner, runWithOwner, equalFn, requestCallback, mapArray, observable, from, $PROXY, DEV } from "./reactive";
|
|
1
|
+
export { createRoot, createSignal, createComputed, createRenderEffect, createEffect, createDeferred, createSelector, createMemo, getListener, onMount, onCleanup, onError, untrack, batch, on, children, createContext, useContext, getOwner, runWithOwner, equalFn, requestCallback, mapArray, observable, from, $PROXY, DEV } from "./reactive";
|
|
2
2
|
export { awaitSuspense, mergeProps, splitProps, createComponent, For, Index, Show, Switch, Match, ErrorBoundary, Suspense, SuspenseList, createResource, enableScheduling, startTransition, useTransition, createUniqueId, lazy, sharedConfig } from "./rendering";
|
|
3
3
|
export type { Component, Resource } from "./rendering";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Solid Universal
|
|
2
|
+
|
|
3
|
+
This contains the means to create the runtime for a custom renderer for Solid. This can enable using Solid to render to different platforms like native mobile and desktop, canvas or WebGL, or even the terminal. It relies on custom compilation from `babel-preset-solid` and exporting the result of `createRenderer` at a referenceable location.
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
To use a custom renderer available in the (fictional) `solid-custom-dom` package you'd configure your babelrc as:
|
|
8
|
+
```json
|
|
9
|
+
{
|
|
10
|
+
"presets": [
|
|
11
|
+
[
|
|
12
|
+
"babel-preset-solid",
|
|
13
|
+
{
|
|
14
|
+
"moduleName": "solid-custom-dom",
|
|
15
|
+
"generate": "universal"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
To create a custom renderer you must implement certain methods and export (as named exports) the results. You may also want to forward `solid-js` control flow to allow them to be auto imported as well.
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
// example custom dom renderer
|
|
26
|
+
import { createRenderer } from "solid-js/universal";
|
|
27
|
+
|
|
28
|
+
const PROPERTIES = new Set(["className", "textContent"]);
|
|
29
|
+
|
|
30
|
+
export const {
|
|
31
|
+
render,
|
|
32
|
+
effect,
|
|
33
|
+
memo,
|
|
34
|
+
createComponent,
|
|
35
|
+
createElement,
|
|
36
|
+
createTextNode,
|
|
37
|
+
insertNode,
|
|
38
|
+
insert,
|
|
39
|
+
spread,
|
|
40
|
+
setProp,
|
|
41
|
+
mergeProps
|
|
42
|
+
} = createRenderer({
|
|
43
|
+
createElement(string) {
|
|
44
|
+
return document.createElement(string);
|
|
45
|
+
},
|
|
46
|
+
createTextNode(value) {
|
|
47
|
+
return document.createTextNode(value);
|
|
48
|
+
},
|
|
49
|
+
replaceText(textNode, value) {
|
|
50
|
+
textNode.data = value;
|
|
51
|
+
},
|
|
52
|
+
setProperty(node, name, value) {
|
|
53
|
+
if (name === "style") Object.assign(node.style, value);
|
|
54
|
+
else if (name.startsWith("on")) node[name.toLowerCase()] = value;
|
|
55
|
+
else if (PROPERTIES.has(name)) node[name] = value;
|
|
56
|
+
else node.setAttribute(name, value);
|
|
57
|
+
},
|
|
58
|
+
insertNode(parent, node, anchor) {
|
|
59
|
+
parent.insertBefore(node, anchor);
|
|
60
|
+
},
|
|
61
|
+
isTextNode(node) {
|
|
62
|
+
return node.type === 3;
|
|
63
|
+
},
|
|
64
|
+
removeNode(parent, node) {
|
|
65
|
+
parent.removeChild(node);
|
|
66
|
+
},
|
|
67
|
+
getParentNode(node) {
|
|
68
|
+
return node.parentNode;
|
|
69
|
+
},
|
|
70
|
+
getFirstChild(node) {
|
|
71
|
+
return node.firstChild;
|
|
72
|
+
},
|
|
73
|
+
getNextSibling(node) {
|
|
74
|
+
return node.nextSibling;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Forward Solid control flow
|
|
79
|
+
export {
|
|
80
|
+
For,
|
|
81
|
+
Show,
|
|
82
|
+
Suspense,
|
|
83
|
+
SuspenseList,
|
|
84
|
+
Switch,
|
|
85
|
+
Match,
|
|
86
|
+
Index,
|
|
87
|
+
ErrorBoundary
|
|
88
|
+
} from "solid-js";
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Then to consume:
|
|
92
|
+
```js
|
|
93
|
+
import { render } from "solid-custom-dom";
|
|
94
|
+
|
|
95
|
+
function App() {
|
|
96
|
+
// the skies the limits
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
render(() => <App />, mountNode)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
> Note: For TypeScript support of non-standard JSX you will need to provide your own types at a jsx-runtime entry on your package so that it can be set as the `jsxImportSource`. If mixing and matching different JSX implementations you will need use the per file pragmas.
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var solidJs = require('solid-js');
|
|
6
|
+
|
|
7
|
+
function memo(fn, equals) {
|
|
8
|
+
return solidJs.createMemo(fn, undefined, !equals ? {
|
|
9
|
+
equals
|
|
10
|
+
} : undefined);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function createRenderer$1({
|
|
14
|
+
createElement,
|
|
15
|
+
createTextNode,
|
|
16
|
+
isTextNode,
|
|
17
|
+
replaceText,
|
|
18
|
+
insertNode,
|
|
19
|
+
removeNode,
|
|
20
|
+
setProperty,
|
|
21
|
+
getParentNode,
|
|
22
|
+
getFirstChild,
|
|
23
|
+
getNextSibling
|
|
24
|
+
}) {
|
|
25
|
+
function insert(parent, accessor, marker, initial) {
|
|
26
|
+
if (marker !== undefined && !initial) initial = [];
|
|
27
|
+
if (typeof accessor !== "function") return insertExpression(parent, accessor, initial, marker);
|
|
28
|
+
solidJs.createRenderEffect(current => insertExpression(parent, accessor(), current, marker), initial);
|
|
29
|
+
}
|
|
30
|
+
function insertExpression(parent, value, current, marker, unwrapArray) {
|
|
31
|
+
while (typeof current === "function") current = current();
|
|
32
|
+
if (value === current) return current;
|
|
33
|
+
const t = typeof value,
|
|
34
|
+
multi = marker !== undefined;
|
|
35
|
+
if (t === "string" || t === "number") {
|
|
36
|
+
if (t === "number") value = value.toString();
|
|
37
|
+
if (multi) {
|
|
38
|
+
let node = current[0];
|
|
39
|
+
if (node && isTextNode(node)) {
|
|
40
|
+
replaceText(node, value);
|
|
41
|
+
} else node = createTextNode(value);
|
|
42
|
+
current = cleanChildren(parent, current, marker, node);
|
|
43
|
+
} else {
|
|
44
|
+
if (current !== "" && typeof current === "string") {
|
|
45
|
+
replaceText(getFirstChild(parent), current = value);
|
|
46
|
+
} else {
|
|
47
|
+
cleanChildren(parent, current, marker, createTextNode(value));
|
|
48
|
+
current = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} else if (value == null || t === "boolean") {
|
|
52
|
+
current = cleanChildren(parent, current, marker);
|
|
53
|
+
} else if (t === "function") {
|
|
54
|
+
solidJs.createRenderEffect(() => {
|
|
55
|
+
let v = value();
|
|
56
|
+
while (typeof v === "function") v = v();
|
|
57
|
+
current = insertExpression(parent, v, current, marker);
|
|
58
|
+
});
|
|
59
|
+
return () => current;
|
|
60
|
+
} else if (Array.isArray(value)) {
|
|
61
|
+
const array = [];
|
|
62
|
+
if (normalizeIncomingArray(array, value, unwrapArray)) {
|
|
63
|
+
solidJs.createRenderEffect(() => current = insertExpression(parent, array, current, marker, true));
|
|
64
|
+
return () => current;
|
|
65
|
+
}
|
|
66
|
+
if (array.length === 0) {
|
|
67
|
+
const replacement = cleanChildren(parent, current, marker);
|
|
68
|
+
if (multi) return current = replacement;
|
|
69
|
+
} else {
|
|
70
|
+
if (Array.isArray(current)) {
|
|
71
|
+
if (current.length === 0) {
|
|
72
|
+
appendNodes(parent, array, marker);
|
|
73
|
+
} else reconcileArrays(parent, current, array);
|
|
74
|
+
} else if (current == null || current === "") {
|
|
75
|
+
appendNodes(parent, array);
|
|
76
|
+
} else {
|
|
77
|
+
reconcileArrays(parent, multi && current || [getFirstChild(parent)], array);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
current = array;
|
|
81
|
+
} else {
|
|
82
|
+
if (Array.isArray(current)) {
|
|
83
|
+
if (multi) return current = cleanChildren(parent, current, marker, value);
|
|
84
|
+
cleanChildren(parent, current, null, value);
|
|
85
|
+
} else if (current == null || current === "" || !getFirstChild(parent)) {
|
|
86
|
+
insertNode(parent, value);
|
|
87
|
+
} else replaceNode(parent, value, getFirstChild(parent));
|
|
88
|
+
current = value;
|
|
89
|
+
}
|
|
90
|
+
return current;
|
|
91
|
+
}
|
|
92
|
+
function normalizeIncomingArray(normalized, array, unwrap) {
|
|
93
|
+
let dynamic = false;
|
|
94
|
+
for (let i = 0, len = array.length; i < len; i++) {
|
|
95
|
+
let item = array[i],
|
|
96
|
+
t;
|
|
97
|
+
if (item == null || item === true || item === false) ; else if (Array.isArray(item)) {
|
|
98
|
+
dynamic = normalizeIncomingArray(normalized, item) || dynamic;
|
|
99
|
+
} else if ((t = typeof item) === "string" || t === "number") {
|
|
100
|
+
normalized.push(createTextNode(item));
|
|
101
|
+
} else if (t === "function") {
|
|
102
|
+
if (unwrap) {
|
|
103
|
+
while (typeof item === "function") item = item();
|
|
104
|
+
dynamic = normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic;
|
|
105
|
+
} else {
|
|
106
|
+
normalized.push(item);
|
|
107
|
+
dynamic = true;
|
|
108
|
+
}
|
|
109
|
+
} else normalized.push(item);
|
|
110
|
+
}
|
|
111
|
+
return dynamic;
|
|
112
|
+
}
|
|
113
|
+
function reconcileArrays(parentNode, a, b) {
|
|
114
|
+
let bLength = b.length,
|
|
115
|
+
aEnd = a.length,
|
|
116
|
+
bEnd = bLength,
|
|
117
|
+
aStart = 0,
|
|
118
|
+
bStart = 0,
|
|
119
|
+
after = getNextSibling(a[aEnd - 1]),
|
|
120
|
+
map = null;
|
|
121
|
+
while (aStart < aEnd || bStart < bEnd) {
|
|
122
|
+
if (a[aStart] === b[bStart]) {
|
|
123
|
+
aStart++;
|
|
124
|
+
bStart++;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
while (a[aEnd - 1] === b[bEnd - 1]) {
|
|
128
|
+
aEnd--;
|
|
129
|
+
bEnd--;
|
|
130
|
+
}
|
|
131
|
+
if (aEnd === aStart) {
|
|
132
|
+
const node = bEnd < bLength ? bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart] : after;
|
|
133
|
+
while (bStart < bEnd) insertNode(parentNode, b[bStart++], node);
|
|
134
|
+
} else if (bEnd === bStart) {
|
|
135
|
+
while (aStart < aEnd) {
|
|
136
|
+
if (!map || !map.has(a[aStart])) removeNode(parentNode, a[aStart]);
|
|
137
|
+
aStart++;
|
|
138
|
+
}
|
|
139
|
+
} else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
|
|
140
|
+
const node = getNextSibling(a[--aEnd]);
|
|
141
|
+
insertNode(parentNode, b[bStart++], getNextSibling(a[aStart++]));
|
|
142
|
+
insertNode(parentNode, b[--bEnd], node);
|
|
143
|
+
a[aEnd] = b[bEnd];
|
|
144
|
+
} else {
|
|
145
|
+
if (!map) {
|
|
146
|
+
map = new Map();
|
|
147
|
+
let i = bStart;
|
|
148
|
+
while (i < bEnd) map.set(b[i], i++);
|
|
149
|
+
}
|
|
150
|
+
const index = map.get(a[aStart]);
|
|
151
|
+
if (index != null) {
|
|
152
|
+
if (bStart < index && index < bEnd) {
|
|
153
|
+
let i = aStart,
|
|
154
|
+
sequence = 1,
|
|
155
|
+
t;
|
|
156
|
+
while (++i < aEnd && i < bEnd) {
|
|
157
|
+
if ((t = map.get(a[i])) == null || t !== index + sequence) break;
|
|
158
|
+
sequence++;
|
|
159
|
+
}
|
|
160
|
+
if (sequence > index - bStart) {
|
|
161
|
+
const node = a[aStart];
|
|
162
|
+
while (bStart < index) insertNode(parentNode, b[bStart++], node);
|
|
163
|
+
} else replaceNode(parentNode, b[bStart++], a[aStart++]);
|
|
164
|
+
} else aStart++;
|
|
165
|
+
} else removeNode(parentNode, a[aStart++]);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function cleanChildren(parent, current, marker, replacement) {
|
|
170
|
+
if (marker === undefined) {
|
|
171
|
+
let removed;
|
|
172
|
+
while (removed = getFirstChild(parent)) removeNode(parent, removed);
|
|
173
|
+
replacement && insertNode(parent, replacement);
|
|
174
|
+
return "";
|
|
175
|
+
}
|
|
176
|
+
const node = replacement || createTextNode("");
|
|
177
|
+
if (current.length) {
|
|
178
|
+
let inserted = false;
|
|
179
|
+
for (let i = current.length - 1; i >= 0; i--) {
|
|
180
|
+
const el = current[i];
|
|
181
|
+
if (node !== el) {
|
|
182
|
+
const isParent = getParentNode(el) === parent;
|
|
183
|
+
if (!inserted && !i) isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker);else isParent && removeNode(parent, el);
|
|
184
|
+
} else inserted = true;
|
|
185
|
+
}
|
|
186
|
+
} else insertNode(parent, node, marker);
|
|
187
|
+
return [node];
|
|
188
|
+
}
|
|
189
|
+
function appendNodes(parent, array, marker) {
|
|
190
|
+
for (let i = 0, len = array.length; i < len; i++) insertNode(parent, array[i], marker);
|
|
191
|
+
}
|
|
192
|
+
function replaceNode(parent, newNode, oldNode) {
|
|
193
|
+
insertNode(parent, newNode, oldNode);
|
|
194
|
+
removeNode(parent, oldNode);
|
|
195
|
+
}
|
|
196
|
+
function spreadExpression(node, props, prevProps = {}, skipChildren) {
|
|
197
|
+
if (!skipChildren && "children" in props) {
|
|
198
|
+
solidJs.createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children));
|
|
199
|
+
}
|
|
200
|
+
solidJs.createRenderEffect(() => {
|
|
201
|
+
for (const prop in props) {
|
|
202
|
+
if (prop === "children") continue;
|
|
203
|
+
const value = props[prop];
|
|
204
|
+
if (value === prevProps[prop]) continue;
|
|
205
|
+
if (prop === "ref") value(node);else {
|
|
206
|
+
setProperty(node, prop, value, prevProps[prop]);
|
|
207
|
+
prevProps[prop] = value;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
return prevProps;
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
render(code, element) {
|
|
215
|
+
let disposer;
|
|
216
|
+
solidJs.createRoot(dispose => {
|
|
217
|
+
disposer = dispose;
|
|
218
|
+
insert(element, code());
|
|
219
|
+
});
|
|
220
|
+
return disposer;
|
|
221
|
+
},
|
|
222
|
+
insert,
|
|
223
|
+
spread(node, accessor, skipChildren) {
|
|
224
|
+
if (typeof accessor === "function") {
|
|
225
|
+
solidJs.createRenderEffect(current => spreadExpression(node, accessor(), current, skipChildren));
|
|
226
|
+
} else spreadExpression(node, accessor, undefined, skipChildren);
|
|
227
|
+
},
|
|
228
|
+
createElement,
|
|
229
|
+
createTextNode,
|
|
230
|
+
insertNode,
|
|
231
|
+
setProp(node, name, value, prev) {
|
|
232
|
+
setProperty(node, name, value, prev);
|
|
233
|
+
return value;
|
|
234
|
+
},
|
|
235
|
+
mergeProps,
|
|
236
|
+
effect: solidJs.createRenderEffect,
|
|
237
|
+
memo,
|
|
238
|
+
createComponent: solidJs.createComponent
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
function mergeProps(...sources) {
|
|
242
|
+
const target = {};
|
|
243
|
+
for (let i = 0; i < sources.length; i++) {
|
|
244
|
+
let source = sources[i];
|
|
245
|
+
if (typeof source === "function") source = source();
|
|
246
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
247
|
+
Object.defineProperties(target, descriptors);
|
|
248
|
+
}
|
|
249
|
+
return target;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function createRenderer(options) {
|
|
253
|
+
const renderer = createRenderer$1(options);
|
|
254
|
+
renderer.mergeProps = solidJs.mergeProps;
|
|
255
|
+
return renderer;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
exports.createRenderer = createRenderer;
|