tungsten 0.2.2 → 0.2.3
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/ContentNode.d.ts +1 -1
- package/dist/ContentNode.d.ts.map +1 -1
- package/dist/RenderingNode.js +2 -2
- package/dist/components/bindable/BindVariable.d.ts +2 -0
- package/dist/components/bindable/BindVariable.d.ts.map +1 -1
- package/dist/hydrate/hydrate.d.ts.map +1 -1
- package/dist/hydrate/hydrate.js +46 -1
- package/dist/react-zone.js +1 -1
- package/dist/render/processProps.js +1 -1
- package/dist/render/processRenderingNodeHtml.d.ts +2 -2
- package/dist/render/processRenderingNodeHtml.d.ts.map +1 -1
- package/dist/render/processRenderingNodeHtml.js +33 -12
- package/dist/render/renderingTreeToHtml.d.ts +2 -2
- package/dist/render/renderingTreeToHtml.d.ts.map +1 -1
- package/dist/render/renderingTreeToHtml.js +37 -34
- package/dist/render/rootToHtml.d.ts.map +1 -1
- package/dist/render/rootToHtml.js +0 -38
- package/dist/update/integrateUpdateVdom.d.ts.map +1 -1
- package/dist/update/integrateUpdateVdom.js +91 -42
- package/package.json +1 -1
- package/types/jsx/html.d.ts +1 -1
package/dist/ContentNode.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type NodeProps = {
|
|
|
13
13
|
value?: NodeValue;
|
|
14
14
|
ref?: TungstenRef<HTMLElement>;
|
|
15
15
|
/** Raw server HTML whose descendants are owned by another renderer. */
|
|
16
|
-
|
|
16
|
+
__zoneHtml?: string;
|
|
17
17
|
/** Prevent Tungsten from reconciling descendants of this host element. */
|
|
18
18
|
__opaque?: boolean;
|
|
19
19
|
[key: string]: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentNode.d.ts","sourceRoot":"","sources":["../src/ContentNode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,WAAW,EAA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AyB,CAEtD;AAED,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,yBAAyB,CAE9G;AAED,wBAAgB,uCAAuC,CAEnD,KAAK,SAAS,0BAA0B,EACxC,KAAK,SAAS,gCAAgC,EAC9C,SAAS,EACT,KAAK,SAAS,gCAAgC,EAEjD,oBAAoB,EAAE,oBAAoB,GACrC,oBAAoB,IAAI,yBAAyB,CAEtD;AAED,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,yBAAyB,CAEjH;AAGD,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,MAAM,CAEnF;AACD,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,MAAM,CAEnF;AACD,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,kBAAkB,CAEhG;AAGD,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,kBAAkB,GACnE,OAAO,IAAI,kBAAkB,GAAG;IAAE,CAAC,IAAI,CAAC,EAAE,YAAY,CAAA;CAAE,CAE7D"}
|
package/dist/RenderingNode.js
CHANGED
|
@@ -12,7 +12,7 @@ export function makeRenderingNodeClassComponentFromContentNodeClassComponent(con
|
|
|
12
12
|
children: renderingChildren
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
if (placeholder) n[$placeholder] = placeholder;
|
|
15
|
+
if (placeholder === true) n[$placeholder] = placeholder;
|
|
16
16
|
return n;
|
|
17
17
|
}
|
|
18
18
|
export function makeRenderingNodeFunctionComponentFromContentNodeFunctionComponent(contentNode, element, renderingChildren, placeholder) {
|
|
@@ -23,7 +23,7 @@ export function makeRenderingNodeFunctionComponentFromContentNodeFunctionCompone
|
|
|
23
23
|
children: renderingChildren
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
if (placeholder) n[$placeholder] = placeholder;
|
|
26
|
+
if (placeholder === true) n[$placeholder] = placeholder;
|
|
27
27
|
return n;
|
|
28
28
|
}
|
|
29
29
|
export function makeRenderingNodePlaceholderFromContentNodeComponent(contentNode, element, renderingChildren) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { NodeValue } from '../../ContentNode.js';
|
|
1
2
|
export type BindVariable<O extends object> = [O, keyof O];
|
|
3
|
+
export type WidestBindVariable = BindVariable<Record<PropertyKey, NodeValue>>;
|
|
2
4
|
export type TypedBindVariable<O extends object, K extends keyof O> = [O, K];
|
|
3
5
|
//# sourceMappingURL=BindVariable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BindVariable.d.ts","sourceRoot":"","sources":["../../../src/components/bindable/BindVariable.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;AAEzD,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"BindVariable.d.ts","sourceRoot":"","sources":["../../../src/components/bindable/BindVariable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEhD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;AAEzD,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,CAAA;AAG7E,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../../src/hydrate/hydrate.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAQnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AA0BxD,OAAO,EAAE,yBAAyB,EAAoD,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../../src/hydrate/hydrate.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAQnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AA0BxD,OAAO,EAAE,yBAAyB,EAAoD,MAAM,mBAAmB,CAAA;AAmC/G,wBAAsB,OAAO,CACzB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,yBAAyB,GAAG,IAAI,EAC/C,cAAc,EAAE,cAAc,iBAyDjC"}
|
package/dist/hydrate/hydrate.js
CHANGED
|
@@ -26,6 +26,8 @@ import { checkedValueToBoolean } from "../checkedValueToBoolean.js";
|
|
|
26
26
|
import { Default404 } from "../routing/Default404.js";
|
|
27
27
|
import { initStores } from 'tungsten/Servers/initStores.js';
|
|
28
28
|
import { MatchedRoute } from "../routing/MatchedRoute.js";
|
|
29
|
+
import { isDev } from "../isDev.js";
|
|
30
|
+
import { warn } from "../appOutput.js";
|
|
29
31
|
import { jsx as _jsx } from "tungsten/jsxRuntime.js";
|
|
30
32
|
function debug(...texts) {
|
|
31
33
|
//console.log(...texts)
|
|
@@ -190,7 +192,7 @@ async function hydrateClassComponent(node, parentElement, domPointer, instance,
|
|
|
190
192
|
const render = Component.render;
|
|
191
193
|
//console.log('render', render)
|
|
192
194
|
//console.log('Component', Component)
|
|
193
|
-
if (render) {
|
|
195
|
+
if (render !== undefined) {
|
|
194
196
|
const placeholderContent = typeof render === 'object' ? render.placeholder : null;
|
|
195
197
|
//console.log('hydrating content', placeholderContent)
|
|
196
198
|
const renderedPlaceholderContent = await hydrateNode(placeholderContent, element, domPointer, instance, meta);
|
|
@@ -465,6 +467,31 @@ async function hydrateNodeSingle(node, parentElement, domPointer, instance, meta
|
|
|
465
467
|
debug('hydarating atts');
|
|
466
468
|
hydrateAttributes(node, domNode);
|
|
467
469
|
//!!! node.domElement = domNode
|
|
470
|
+
const props = node[$props];
|
|
471
|
+
if (node[$type] === 'textarea') {
|
|
472
|
+
if ('value' in props) {
|
|
473
|
+
if (props.children !== undefined && !(Array.isArray(node[$props].children) && node[$props].children.length === 0)) {
|
|
474
|
+
if (isDev) {
|
|
475
|
+
warn('textarea element has both value attribute and children, children will be ignored.');
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
//if (props.value !== undefined)
|
|
479
|
+
props.children = props.value;
|
|
480
|
+
delete props.value;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/// !!! TODO
|
|
484
|
+
// This code relies on the select node being the immediate parent.
|
|
485
|
+
// This may not be the case (there could be a wrapping component), and could be improved
|
|
486
|
+
// if (node[$type] === 'option') {
|
|
487
|
+
// if (ContentNodeIsHtml(parentNode) && parentNode[$type] === 'select') {
|
|
488
|
+
// if (parentNode[$props].value !== undefined) {
|
|
489
|
+
// if (props.value === parentNode[$props].value) {
|
|
490
|
+
// props.selected = 'selected'
|
|
491
|
+
// }
|
|
492
|
+
// }
|
|
493
|
+
// }
|
|
494
|
+
// }
|
|
468
495
|
// look up any refs
|
|
469
496
|
//const props = node[$props]
|
|
470
497
|
//const ref = node[$props].ref
|
|
@@ -479,6 +506,17 @@ async function hydrateNodeSingle(node, parentElement, domPointer, instance, meta
|
|
|
479
506
|
const childDomPointer = new DomPointer(domNode);
|
|
480
507
|
renderedChildren = await hydrateNode(children, parentElement, childDomPointer, instance, meta);
|
|
481
508
|
}
|
|
509
|
+
if (node[$type] === 'select' && node[$props].value !== undefined && node[$props].value !== null) {
|
|
510
|
+
const options = domNode.options;
|
|
511
|
+
const value = String(node[$props].value);
|
|
512
|
+
for (let i = options.length - 1; i >= 0; i--) {
|
|
513
|
+
const option = options[i];
|
|
514
|
+
if (option.value === value) {
|
|
515
|
+
option.selected = true;
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
482
520
|
// note that we have left the form
|
|
483
521
|
if (node[$type] === 'form') meta.insideForm = false;
|
|
484
522
|
domPointer.increment();
|
|
@@ -624,6 +662,13 @@ function hydrateAttributes(node, domNode) {
|
|
|
624
662
|
domNode[htmlEventHandlerKey(eventName)] = handler;
|
|
625
663
|
}
|
|
626
664
|
}
|
|
665
|
+
if (node[$type] === 'option') {
|
|
666
|
+
const option = domNode;
|
|
667
|
+
const select = option.closest('select');
|
|
668
|
+
if (select !== null && select.hasAttribute('value') && select.getAttribute('value') === option.value) {
|
|
669
|
+
option.selected = true;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
627
672
|
debug('--');
|
|
628
673
|
}
|
|
629
674
|
// onChange -> add
|
package/dist/react-zone.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { objects } from 'sxy-lib';
|
|
2
2
|
import { jssToCss } from "../style/jssToCss.js";
|
|
3
|
-
const omitProps = ['ref', 'onClick', 'onChange', 'onSubmit', 'onKeyDown', 'onKeyUp', 'onKeyPress', 'onMouseDown', 'onMouseUp', 'onMouseMove', 'onMouseEnter', 'onMouseLeave', 'onMouseOver', 'onMouseOut', '
|
|
3
|
+
const omitProps = ['ref', 'onClick', 'onChange', 'onSubmit', 'onKeyDown', 'onKeyUp', 'onKeyPress', 'onMouseDown', 'onMouseUp', 'onMouseMove', 'onMouseEnter', 'onMouseLeave', 'onMouseOver', 'onMouseOut', '__zoneHtml', '__opaque'];
|
|
4
4
|
//// !!!! We need to handle bind here
|
|
5
5
|
export function processProps(props) {
|
|
6
6
|
props = objects.filter(props, key => {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function processRenderingNodeHtml(node: RenderingNodeHtml,
|
|
1
|
+
import { type RenderingNodeHtml } from '../RenderingNode.js';
|
|
2
|
+
export declare function processRenderingNodeHtml(node: RenderingNodeHtml, lastSelect: RenderingNodeHtml | null): void;
|
|
3
3
|
//# sourceMappingURL=processRenderingNodeHtml.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processRenderingNodeHtml.d.ts","sourceRoot":"","sources":["../../src/render/processRenderingNodeHtml.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"processRenderingNodeHtml.d.ts","sourceRoot":"","sources":["../../src/render/processRenderingNodeHtml.ts"],"names":[],"mappings":"AAEA,OAAO,EACiB,KAAK,iBAAiB,EAE7C,MAAM,qBAAqB,CAAA;AAqC5B,wBAAgB,wBAAwB,CACpC,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,iBAAiB,GAAG,IAAI,QAwDhE"}
|
|
@@ -1,15 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RenderingNodeElementIsComponent, RenderingNodeElementIsHtml } from "../RenderingNode.js";
|
|
2
2
|
import { bindableHtmlElements } from "../components/bindable/bindableHtmlElements.js";
|
|
3
3
|
import { cliWarn } from "../cliOutput.js";
|
|
4
4
|
import { debug } from "./debug.js";
|
|
5
5
|
import { $props, $type } from "../contentNodeSymbols.js";
|
|
6
6
|
import { checkedValueToBoolean } from "../checkedValueToBoolean.js";
|
|
7
|
-
|
|
7
|
+
function collectOptionText(node) {
|
|
8
|
+
if (node === undefined || node === null || node === false || node === true) return '';
|
|
9
|
+
if (Array.isArray(node)) {
|
|
10
|
+
let text = '';
|
|
11
|
+
for (const child of node) text += collectOptionText(child);
|
|
12
|
+
return text;
|
|
13
|
+
}
|
|
14
|
+
if (typeof node === 'string' || typeof node === 'number') return String(node);
|
|
15
|
+
if (RenderingNodeElementIsHtml(node)) {
|
|
16
|
+
if (node[$type] === 'script' || typeof node[$props].__html === 'string') return '';
|
|
17
|
+
return collectOptionText(node[$props].children);
|
|
18
|
+
}
|
|
19
|
+
if (RenderingNodeElementIsComponent(node)) {
|
|
20
|
+
return collectOptionText(node[$props].children);
|
|
21
|
+
}
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
function normalizeOptionText(text) {
|
|
25
|
+
return text.replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g, '').replace(/[\t\n\f\r ]+/g, ' ');
|
|
26
|
+
}
|
|
27
|
+
export function processRenderingNodeHtml(node, lastSelect) {
|
|
8
28
|
const props = node[$props];
|
|
9
29
|
debug('processRenderingNodeHtml', node);
|
|
10
30
|
if ('bind' in props && node[$type] in bindableHtmlElements) {
|
|
11
31
|
debug('setting bound value');
|
|
32
|
+
// do we actually enforce NodeValue as the type of a bind value?
|
|
12
33
|
const [bindObject, bindKey] = props.bind;
|
|
34
|
+
//const [bindObject, bindKey] = (props.bind as [Record<PropertyKey, NodeValue>, PropertyKey])
|
|
13
35
|
props.value = bindObject[bindKey] ?? ''; // nullish coalesce to avoid putting undef/null into elements
|
|
14
36
|
delete props.bind;
|
|
15
37
|
delete props.filter;
|
|
@@ -27,20 +49,19 @@ export function processRenderingNodeHtml(node, parent) {
|
|
|
27
49
|
}
|
|
28
50
|
if (node[$type] === 'textarea') {
|
|
29
51
|
if ('value' in props) {
|
|
30
|
-
if (props.children && !(Array.isArray(props.children) && props.children.length === 0)) {
|
|
31
|
-
cliWarn('textarea element has both value attribute and children,
|
|
32
|
-
} else {
|
|
33
|
-
if (props.value !== undefined) props.children = [props.value];
|
|
34
|
-
delete props.value;
|
|
52
|
+
if (props.children !== undefined && !(Array.isArray(props.children) && props.children.length === 0)) {
|
|
53
|
+
cliWarn('textarea element has both value attribute and children, children will be ignored.');
|
|
35
54
|
}
|
|
55
|
+
//if (props.value !== undefined)
|
|
56
|
+
props.children = props.value;
|
|
57
|
+
delete props.value;
|
|
36
58
|
}
|
|
37
59
|
}
|
|
38
|
-
// This code relies on the select node being the immediate parent.
|
|
39
|
-
// This may not be the case (there could be a wrapping component), and could be improved
|
|
40
60
|
if (node[$type] === 'option') {
|
|
41
|
-
if (
|
|
42
|
-
if (
|
|
43
|
-
|
|
61
|
+
if (lastSelect !== null) {
|
|
62
|
+
if (lastSelect[$props].value !== undefined && lastSelect[$props].value !== null) {
|
|
63
|
+
const optionValue = props.value !== undefined && props.value !== null ? String(props.value) : normalizeOptionText(collectOptionText(props.children));
|
|
64
|
+
if (optionValue === String(lastSelect[$props].value)) {
|
|
44
65
|
props.selected = 'selected';
|
|
45
66
|
}
|
|
46
67
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { HeadData } from './HeadData.js';
|
|
2
|
-
import { type RenderingNode } from '../RenderingNode.js';
|
|
3
|
-
export declare function renderingNodeToHtml(node: RenderingNode, noEscape: boolean, headData: HeadData,
|
|
2
|
+
import { type RenderingNode, type RenderingNodeHtml } from '../RenderingNode.js';
|
|
3
|
+
export declare function renderingNodeToHtml(node: RenderingNode, noEscape: boolean, headData: HeadData, lastSelect: RenderingNodeHtml | null): Promise<string>;
|
|
4
4
|
//# sourceMappingURL=renderingTreeToHtml.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderingTreeToHtml.d.ts","sourceRoot":"","sources":["../../src/render/renderingTreeToHtml.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAY7C,OAAO,EACH,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"renderingTreeToHtml.d.ts","sourceRoot":"","sources":["../../src/render/renderingTreeToHtml.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAY7C,OAAO,EACH,KAAK,aAAa,EAAE,KAAK,iBAAiB,EAG7C,MAAM,qBAAqB,CAAA;AAS5B,wBAAsB,mBAAmB,CACrC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAC1D,UAAU,EAAE,iBAAiB,GAAG,IAAI,GACrC,OAAO,CAAC,MAAM,CAAC,CA4IjB"}
|
|
@@ -10,12 +10,12 @@ import { TungstenError } from "../TungstenError.js";
|
|
|
10
10
|
import { throwError } from "../throwError.js";
|
|
11
11
|
import { $props, $type } from "../contentNodeSymbols.js";
|
|
12
12
|
import { printComponentNamesInSource } from "./printComponentNameInSource.js";
|
|
13
|
-
import { RenderingNodeElementIsComponent, RenderingNodeElementIsHtml
|
|
13
|
+
import { RenderingNodeElementIsComponent, RenderingNodeElementIsHtml } from "../RenderingNode.js";
|
|
14
14
|
import { processHead } from "./processHead.js";
|
|
15
15
|
import { processRenderingNodeHtml } from "./processRenderingNodeHtml.js";
|
|
16
16
|
//// Maybe we should build the full tree before rendering
|
|
17
17
|
//// may need some merging with componentTreeToHtml
|
|
18
|
-
export async function renderingNodeToHtml(node, noEscape, headData,
|
|
18
|
+
export async function renderingNodeToHtml(node, noEscape, headData, lastSelect) {
|
|
19
19
|
//console.log('nodeToHtml node', node)
|
|
20
20
|
debug('nodeToHtml node', node);
|
|
21
21
|
if (node === undefined || node === null || node === false || node === true) {
|
|
@@ -26,7 +26,7 @@ export async function renderingNodeToHtml(node, noEscape, headData, parent) {
|
|
|
26
26
|
const htmls = [];
|
|
27
27
|
for (const i in node) {
|
|
28
28
|
const subNode = node[i];
|
|
29
|
-
htmls[i] = await renderingNodeToHtml(subNode, noEscape, headData,
|
|
29
|
+
htmls[i] = await renderingNodeToHtml(subNode, noEscape, headData, lastSelect);
|
|
30
30
|
}
|
|
31
31
|
return htmls.join('');
|
|
32
32
|
}
|
|
@@ -57,21 +57,23 @@ export async function renderingNodeToHtml(node, noEscape, headData, parent) {
|
|
|
57
57
|
children: []
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
-
const headHtml = await renderingNodeToHtml(headNode, noEscape, headData,
|
|
60
|
+
const headHtml = await renderingNodeToHtml(headNode, noEscape, headData, lastSelect);
|
|
61
61
|
html += headHtml;
|
|
62
62
|
// how do we render it?
|
|
63
63
|
//tree[$props].children.unshift(head)
|
|
64
64
|
}
|
|
65
|
-
processRenderingNodeHtml(node,
|
|
65
|
+
processRenderingNodeHtml(node, lastSelect);
|
|
66
66
|
// update the children and attribs after processing
|
|
67
67
|
let children, attribProps;
|
|
68
|
-
if (node[$props]) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
const attribs = node[$props]
|
|
68
|
+
//if (node[$props]) {
|
|
69
|
+
({
|
|
70
|
+
children,
|
|
71
|
+
...attribProps
|
|
72
|
+
} = node[$props]);
|
|
73
|
+
//}
|
|
74
|
+
//const attribs = (node[$props])
|
|
75
|
+
// ?
|
|
76
|
+
const attribs = objectReduce(processProps(attribProps), (string, key, value) => {
|
|
75
77
|
//debug('reducing attr', key, value)
|
|
76
78
|
if (typeof value === 'boolean') {
|
|
77
79
|
if (value) return string + ` ${key}`;else return string;
|
|
@@ -80,12 +82,12 @@ export async function renderingNodeToHtml(node, noEscape, headData, parent) {
|
|
|
80
82
|
} else {
|
|
81
83
|
return string + ` ${key}="${value}"`;
|
|
82
84
|
}
|
|
83
|
-
}, '')
|
|
85
|
+
}, '');
|
|
86
|
+
// : ''
|
|
84
87
|
debug('attribs', attribs);
|
|
85
|
-
if (typeof node[$props].
|
|
86
|
-
return html + `<${type}${attribs}>${node[$props].
|
|
88
|
+
if (typeof node[$props].__zoneHtml === 'string') {
|
|
89
|
+
return html + `<${type}${attribs}>${node[$props].__zoneHtml}</${type}>`;
|
|
87
90
|
}
|
|
88
|
-
;
|
|
89
91
|
({
|
|
90
92
|
children,
|
|
91
93
|
...attribProps
|
|
@@ -98,7 +100,8 @@ export async function renderingNodeToHtml(node, noEscape, headData, parent) {
|
|
|
98
100
|
debug('children', children);
|
|
99
101
|
const noEscape = type === 'script' || type === 'style' || '__noEscape' in node[$props] && node[$props].__noEscape !== false;
|
|
100
102
|
//console.log(node[$type], node[$props], 'noEscape', noEscape)
|
|
101
|
-
const
|
|
103
|
+
const childLastSelect = type === 'select' ? node : lastSelect;
|
|
104
|
+
const childrenHtml = await renderingNodeToHtml(children, noEscape, headData, childLastSelect);
|
|
102
105
|
return html + `<${type}${attribs}>${childrenHtml}</${type}>`;
|
|
103
106
|
} else {
|
|
104
107
|
if (type in htmlMonoTags) {
|
|
@@ -118,7 +121,7 @@ export async function renderingNodeToHtml(node, noEscape, headData, parent) {
|
|
|
118
121
|
const {
|
|
119
122
|
children
|
|
120
123
|
} = node[$props];
|
|
121
|
-
const inner = await renderingNodeToHtml(children, noEscape, headData,
|
|
124
|
+
const inner = await renderingNodeToHtml(children, noEscape, headData, lastSelect);
|
|
122
125
|
// const meta = (node[$placeholder]) ? ' -content-length=' + treeWidth(children).toString() : ''
|
|
123
126
|
// return printComponentNamesInSource
|
|
124
127
|
// ? '<!--' + node[$type].name + meta + '-->' + inner + '<!--/' + node[$type].name + '-->'
|
|
@@ -140,19 +143,19 @@ export async function renderingNodeToHtml(node, noEscape, headData, parent) {
|
|
|
140
143
|
const n = node; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
141
144
|
throwError('render -> treeToHtml()', `node returned from a component did not match expected format.` + ` Node: ${JSON.stringify(node)}`);
|
|
142
145
|
}
|
|
143
|
-
function treeWidth(tree) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
146
|
+
// function treeWidth(tree: RenderingNode): number {
|
|
147
|
+
// if (RenderingNodeIsNonRendered(tree)) return 0
|
|
148
|
+
// if (RenderingNodeIsLiteral(tree)) return 1
|
|
149
|
+
// tree
|
|
150
|
+
// if (RenderingNodeIsHtml(tree)) return 1
|
|
151
|
+
// tree
|
|
152
|
+
// if (Array.isArray(tree)) {
|
|
153
|
+
// let len = 0
|
|
154
|
+
// for (const node of tree) {
|
|
155
|
+
// len += treeWidth(node)
|
|
156
|
+
// }
|
|
157
|
+
// return len
|
|
158
|
+
// }
|
|
159
|
+
// tree
|
|
160
|
+
// return treeWidth(tree[$props].children)
|
|
161
|
+
// }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rootToHtml.d.ts","sourceRoot":"","sources":["../../src/render/rootToHtml.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAY,YAAY,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAMvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAI9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AAGrE,wBAAsB,UAAU,CAC5B,eAAe,EAAE,eAAe,EAAE,mBAAmB,EAAE,aAAa,EACpE,kBAAkB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,uBAAuB,EACzF,oBAAoB,EAAE,YAAY,EAAE,iBAAiB,GAAE,sBAAkC,EACzF,GAAG,UAAQ,GACZ,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"rootToHtml.d.ts","sourceRoot":"","sources":["../../src/render/rootToHtml.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAY,YAAY,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAMvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAI9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AAGrE,wBAAsB,UAAU,CAC5B,eAAe,EAAE,eAAe,EAAE,mBAAmB,EAAE,aAAa,EACpE,kBAAkB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,uBAAuB,EACzF,oBAAoB,EAAE,YAAY,EAAE,iBAAiB,GAAE,sBAAkC,EACzF,GAAG,UAAQ,GACZ,OAAO,CAAC,MAAM,CAAC,CAWjB"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { renderingNodeToHtml } from "./renderingTreeToHtml.js";
|
|
2
|
-
import { TungstenError } from "../TungstenError.js";
|
|
3
|
-
import { componentNodeToRenderingTree } from "./componentNodeToRenderingTree.js";
|
|
4
1
|
import { $props, $type } from "../contentNodeSymbols.js";
|
|
5
|
-
import { RenderingNodeIsElement } from "../RenderingNode.js";
|
|
6
|
-
import { writeFileSync } from 'fs';
|
|
7
2
|
import { contentToHtml } from "./contentToHtml.js";
|
|
8
3
|
export async function rootToHtml(compilationInfo, clientImportAliases, RootComponentClass, instance, config, siteBasePathOverride, tungstenPublicEnv = undefined, dev = false) {
|
|
9
4
|
const rootNode = {
|
|
@@ -12,37 +7,4 @@ export async function rootToHtml(compilationInfo, clientImportAliases, RootCompo
|
|
|
12
7
|
[$props]: {} // is equivalent to { type: ClassComponentTypeAny } | { type: FunctionComponentTypeAny } (type names simplified here)
|
|
13
8
|
};
|
|
14
9
|
return contentToHtml(compilationInfo, clientImportAliases, rootNode, instance, config, siteBasePathOverride, tungstenPublicEnv, dev);
|
|
15
|
-
// return contentTreeToRenderingTree(
|
|
16
|
-
// rootNode, null, instance, false
|
|
17
|
-
// )
|
|
18
|
-
const tree = await componentNodeToRenderingTree(rootNode, null, instance, false);
|
|
19
|
-
//console.log('tree', tree)
|
|
20
|
-
if (!RenderingNodeIsElement(tree)) {
|
|
21
|
-
throw new TungstenError(`Root content was not a ContentNodeElement type. Ensure that your root node returns valid content.`);
|
|
22
|
-
}
|
|
23
|
-
// // render tree to html string
|
|
24
|
-
const headData = {
|
|
25
|
-
found: false,
|
|
26
|
-
instance,
|
|
27
|
-
importAliases: compilationInfo.importAliases,
|
|
28
|
-
clientImportAliases,
|
|
29
|
-
compilationLocation: compilationInfo.buildCodeLocation,
|
|
30
|
-
dev,
|
|
31
|
-
tungstenPublicEnv,
|
|
32
|
-
siteBasePath: siteBasePathOverride
|
|
33
|
-
};
|
|
34
|
-
//console.log('rendering tree', inspect(tree, { depth: 99 } ))
|
|
35
|
-
let html = await renderingNodeToHtml(tree, false, headData, null);
|
|
36
|
-
writeFileSync('page.html', html);
|
|
37
|
-
//console.log('rootToHtml html', html)
|
|
38
|
-
// insert the title if one was set during processing
|
|
39
|
-
if (instance.title) {
|
|
40
|
-
if (html.includes('<title>')) {
|
|
41
|
-
html = html.replace(/(?:<title>)(.*?)(?:<\/title>)/, `<title>${instance.title}</title>`);
|
|
42
|
-
} else {
|
|
43
|
-
html = html.replace('</head>', `</head><title>${instance.title}</title>`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
html = '<!DOCTYPE html>' + html;
|
|
47
|
-
return html;
|
|
48
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integrateUpdateVdom.d.ts","sourceRoot":"","sources":["../../src/update/integrateUpdateVdom.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EACH,WAAW,EAAwC,eAAe,EAElE,uBAAuB,EAG1B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAKlD,OAAO,EAAE,eAAe,EAAE,MA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B,uBAAuB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,2BAA2B,GAC3G,OAAO,CAAC,4BAA4B,CAAC,CAU1C"}
|
|
@@ -19,6 +19,7 @@ import { bindableHtmlElementsNumber, bindableHtmlElementsString } from "../compo
|
|
|
19
19
|
import { checkedValueToBoolean } from "../checkedValueToBoolean.js";
|
|
20
20
|
import { setCurrentComponent } from 'tungsten/hooks/setCurrentComponent.js';
|
|
21
21
|
import { clearCurrentComponent } from 'tungsten/hooks/clearCurrentComponent.js';
|
|
22
|
+
import { isDev } from "../isDev.js";
|
|
22
23
|
function debug(...texts) {
|
|
23
24
|
//console.log(...texts)
|
|
24
25
|
//console.log(getStackTrace().split('\n')[2])
|
|
@@ -343,30 +344,7 @@ async function applyUpdate({
|
|
|
343
344
|
debug('node types', newNode[$type].toLocaleLowerCase(), oldNode[$type].toLocaleLowerCase(), newNode[$type].toLocaleLowerCase() === oldNode[$type].toLocaleLowerCase());
|
|
344
345
|
}
|
|
345
346
|
if (WideRenderedContentNodeIsHtml(oldNode) && newNode[$type].toLocaleLowerCase() === oldNode[$type].toLocaleLowerCase()) {
|
|
346
|
-
|
|
347
|
-
//console.log('updating html node', newNode[$type])
|
|
348
|
-
//console.log('old node', oldNode[$type])
|
|
349
|
-
debug('updating html node', newNode[$type]);
|
|
350
|
-
// !!!! update
|
|
351
|
-
const domNode = oldNode.domNode;
|
|
352
|
-
updateAttributes(newNode, oldNode, domNode);
|
|
353
|
-
domPointer.increment();
|
|
354
|
-
debug(`!!!!dom pointer index is`, domPointer.index, 'after updating html node');
|
|
355
|
-
// !!! handle children
|
|
356
|
-
const newChildren = newNode[$props].children;
|
|
357
|
-
//console.log(newNode[$type], 'children', newChildren)
|
|
358
|
-
const oldChildren = oldNode.renderedChildren;
|
|
359
|
-
//console.log('oldChildren', oldChildren)
|
|
360
|
-
const renderedChildren = newNode[$props].__opaque === true ? oldChildren : await applyUpdate({
|
|
361
|
-
tungstenElement: tungstenElement,
|
|
362
|
-
instance,
|
|
363
|
-
newNode: newChildren,
|
|
364
|
-
oldNode: oldChildren,
|
|
365
|
-
domRegion: new DomRegion(domNode),
|
|
366
|
-
domPointer: new DomPointer(domNode, 0),
|
|
367
|
-
parentNode: newNode
|
|
368
|
-
});
|
|
369
|
-
return makeRenderedContentNodeHtml(newNode, domNode, renderedChildren);
|
|
347
|
+
return updateHtmlElement(tungstenElement, instance, newNode, oldNode, domPointer);
|
|
370
348
|
} else {
|
|
371
349
|
//console.log('deleting node and creating html', newNode[$type], oldNode)
|
|
372
350
|
debug('deleting node and creating html node', newNode[$type], oldNode);
|
|
@@ -408,6 +386,50 @@ async function applyUpdate({
|
|
|
408
386
|
const n = newNode; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
409
387
|
return makeRenderedContentNodeNonRendered();
|
|
410
388
|
}
|
|
389
|
+
async function updateHtmlElement(tungstenElement, instance, newNode, oldNode, domPointer) {
|
|
390
|
+
//newNode[$props].it = it
|
|
391
|
+
//console.log('updating html node', newNode[$type])
|
|
392
|
+
//console.log('old node', oldNode[$type])
|
|
393
|
+
debug('updating html node', newNode[$type]);
|
|
394
|
+
// !!!! update
|
|
395
|
+
const domNode = oldNode.domNode;
|
|
396
|
+
updateAttributes(newNode, oldNode, domNode);
|
|
397
|
+
domPointer.increment();
|
|
398
|
+
debug(`!!!!dom pointer index is`, domPointer.index, 'after updating html node');
|
|
399
|
+
// !!! handle children
|
|
400
|
+
const newChildren = newNode[$props].children;
|
|
401
|
+
//console.log(newNode[$type], 'children', newChildren)
|
|
402
|
+
const oldChildren = oldNode.renderedChildren;
|
|
403
|
+
//console.log('oldChildren', oldChildren)
|
|
404
|
+
const renderedChildren = newNode[$props].__opaque === true ? oldChildren : await applyUpdate({
|
|
405
|
+
tungstenElement: tungstenElement,
|
|
406
|
+
instance,
|
|
407
|
+
newNode: newChildren,
|
|
408
|
+
oldNode: oldChildren,
|
|
409
|
+
domRegion: new DomRegion(domNode),
|
|
410
|
+
domPointer: new DomPointer(domNode, 0),
|
|
411
|
+
parentNode: newNode
|
|
412
|
+
});
|
|
413
|
+
if (newNode[$type] === 'select') {
|
|
414
|
+
// if we updated a select element
|
|
415
|
+
// if the value changed, we need to update the options
|
|
416
|
+
// alternatively the options might have changed, also requiring
|
|
417
|
+
// updates to `selected`
|
|
418
|
+
// if the options update without the select updating, then they will need to look-back to find the value of the select
|
|
419
|
+
if (newNode[$props].value !== undefined && newNode[$props].value !== null && String(newNode[$props].value) !== String(oldNode[$props].value)) {
|
|
420
|
+
const options = domNode.options;
|
|
421
|
+
const value = String(newNode[$props].value);
|
|
422
|
+
for (let i = options.length - 1; i >= 0; i--) {
|
|
423
|
+
const option = options[i];
|
|
424
|
+
if (option.value === value) {
|
|
425
|
+
option.selected = true;
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return makeRenderedContentNodeHtml(newNode, domNode, renderedChildren);
|
|
432
|
+
}
|
|
411
433
|
async function updateComponent({
|
|
412
434
|
newNode,
|
|
413
435
|
parent,
|
|
@@ -583,7 +605,7 @@ export function processHtmlNode(node, parentNode) {
|
|
|
583
605
|
//console.log('processHtmlNode', node)
|
|
584
606
|
const props = node[$props];
|
|
585
607
|
// set a button without specified type to button, so buttons don't submit forms unless instructed to
|
|
586
|
-
if (node[$type] === 'button' && !props
|
|
608
|
+
if (node[$type] === 'button' && !('type' in props)) props.type = 'button';
|
|
587
609
|
if (props.bind !== undefined) {
|
|
588
610
|
const eventName = 'onInput';
|
|
589
611
|
//// we have event handler code here as well as in addAttributes -- should this be moved to updateAttributes??
|
|
@@ -689,25 +711,25 @@ export function processHtmlNode(node, parentNode) {
|
|
|
689
711
|
delete props.bindRadio;
|
|
690
712
|
}
|
|
691
713
|
if (node[$type] === 'textarea') {
|
|
692
|
-
if ('
|
|
693
|
-
if ('
|
|
694
|
-
warn('textarea element has both value attribute and children, value attribute will be used.');
|
|
695
|
-
//delete props.children
|
|
696
|
-
props.children = props.value;
|
|
714
|
+
if ('value' in props) {
|
|
715
|
+
if ('children' in props && !(Array.isArray(props.children) && props.children.length === 0)) {
|
|
716
|
+
if (isDev) warn('textarea element has both value attribute and children, value attribute will be used.');
|
|
697
717
|
}
|
|
718
|
+
props.children = props.value;
|
|
719
|
+
delete props.value;
|
|
698
720
|
}
|
|
699
721
|
}
|
|
700
722
|
// This code relies on the select node being the immediate parent.
|
|
701
723
|
// This may not be the case (there could be a wrapping component), and could be improved
|
|
702
|
-
if (node[$type] === 'option') {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
}
|
|
724
|
+
// if (node[$type] === 'option') {
|
|
725
|
+
// if (ContentNodeIsHtml(parentNode) && parentNode[$type] === 'select') {
|
|
726
|
+
// if (parentNode[$props].value !== undefined) {
|
|
727
|
+
// if (props.value === parentNode[$props].value) {
|
|
728
|
+
// props.selected = 'selected'
|
|
729
|
+
// }
|
|
730
|
+
// }
|
|
731
|
+
// }
|
|
732
|
+
// }
|
|
711
733
|
//console.log('processed:', node)
|
|
712
734
|
debug('post processHtmlNode', node);
|
|
713
735
|
}
|
|
@@ -776,6 +798,26 @@ async function createHtmlElement(tungstenElement, instance, node, domPointer, pa
|
|
|
776
798
|
domPointer: new DomPointer(htmlEl, htmlEl.childNodes.length),
|
|
777
799
|
parentNode: node
|
|
778
800
|
});
|
|
801
|
+
if (node[$type] === 'select') {
|
|
802
|
+
if (node[$props].value !== undefined && node[$props].value !== null) {
|
|
803
|
+
const options = htmlEl.options;
|
|
804
|
+
const value = String(node[$props].value);
|
|
805
|
+
for (let i = options.length - 1; i >= 0; i--) {
|
|
806
|
+
const option = options[i];
|
|
807
|
+
if (option.value === value) {
|
|
808
|
+
option.selected = true;
|
|
809
|
+
break;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
if (node[$type] === 'option') {
|
|
815
|
+
const option = htmlEl;
|
|
816
|
+
const select = option.closest('select');
|
|
817
|
+
if (select !== null && select.hasAttribute('value') && select.getAttribute('value') === option.value) {
|
|
818
|
+
option.selected = true;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
779
821
|
return {
|
|
780
822
|
...node,
|
|
781
823
|
domNode: htmlEl,
|
|
@@ -863,7 +905,7 @@ function updateAttributes(node, oldNode, domNodeHTMLElement) {
|
|
|
863
905
|
debug('add onclick');
|
|
864
906
|
const clickHandlerKey = htmlEventHandlerKey('click');
|
|
865
907
|
debug('domNode.' + clickHandlerKey, domNode[clickHandlerKey]);
|
|
866
|
-
if (domNode
|
|
908
|
+
if ('clickHandlerKey' in domNode) {
|
|
867
909
|
domNode.removeEventListener('click', domNode[clickHandlerKey]);
|
|
868
910
|
}
|
|
869
911
|
// if its a button without type="submit", prevent default to stop it from submitting forms
|
|
@@ -896,6 +938,13 @@ function updateAttributes(node, oldNode, domNodeHTMLElement) {
|
|
|
896
938
|
}
|
|
897
939
|
}
|
|
898
940
|
}
|
|
941
|
+
if (node[$type] === 'option') {
|
|
942
|
+
const option = domNode;
|
|
943
|
+
const select = option.closest('select');
|
|
944
|
+
if (select !== null && select.hasAttribute('value') && select.getAttribute('value') === option.value) {
|
|
945
|
+
option.selected = true;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
899
948
|
domNode.__tungsten_oldAttributes = newAttributes;
|
|
900
949
|
return newAttributes;
|
|
901
950
|
}
|
|
@@ -913,13 +962,13 @@ function processAttributes(node) {
|
|
|
913
962
|
...props
|
|
914
963
|
};
|
|
915
964
|
delete attributes.ref;
|
|
916
|
-
delete attributes.
|
|
965
|
+
delete attributes.__zoneHtml;
|
|
917
966
|
delete attributes.__opaque;
|
|
918
967
|
delete attributes.class;
|
|
919
968
|
if (attributes.className !== undefined) attributes.class = attributes.className;
|
|
920
969
|
delete attributes.className;
|
|
921
970
|
// process the bind attr to a value attr
|
|
922
|
-
if (attributes.bind) {
|
|
971
|
+
if ('bind' in attributes && attributes.bind !== undefined) {
|
|
923
972
|
const bind = attributes.bind;
|
|
924
973
|
// this will overwrite any existing value attr
|
|
925
974
|
attributes.value = bind[0][bind[1]] ?? ''; // !!! unsafe, assuming bind variable is a suitable value
|
package/package.json
CHANGED
package/types/jsx/html.d.ts
CHANGED
|
@@ -527,7 +527,7 @@ type AriaRole =
|
|
|
527
527
|
type ClassNameType = string | undefined | (string | undefined)[];
|
|
528
528
|
|
|
529
529
|
export interface HTMLAttributes<T> extends AriaAttributes, DOMAttributes<T> {
|
|
530
|
-
|
|
530
|
+
__zoneHtml?: string | undefined;
|
|
531
531
|
__opaque?: boolean | undefined;
|
|
532
532
|
// React-specific Attributes
|
|
533
533
|
defaultChecked?: boolean | undefined;
|