Adding hotfixes for packages
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
6
jsx-html/nodejs/constants.d.ts
vendored
Normal file
6
jsx-html/nodejs/constants.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export declare enum NODE_TYPE {
|
||||
ELEMENT = "element",
|
||||
TEXT = "text",
|
||||
COMPONENT = "component",
|
||||
FRAGMENT = "fragment"
|
||||
}
|
12
jsx-html/nodejs/constants.js
Normal file
12
jsx-html/nodejs/constants.js
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NODE_TYPE = void 0;
|
||||
var NODE_TYPE;
|
||||
(function (NODE_TYPE) {
|
||||
NODE_TYPE["ELEMENT"] = "element";
|
||||
NODE_TYPE["TEXT"] = "text";
|
||||
NODE_TYPE["COMPONENT"] = "component";
|
||||
NODE_TYPE["FRAGMENT"] = "fragment";
|
||||
})(NODE_TYPE = exports.NODE_TYPE || (exports.NODE_TYPE = {}));
|
||||
;
|
||||
//# sourceMappingURL=constants.js.map
|
1
jsx-html/nodejs/constants.js.map
Normal file
1
jsx-html/nodejs/constants.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../tmp/constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,gCAAmB,CAAA;IACnB,0BAAa,CAAA;IACb,oCAAuB,CAAA;IACvB,kCAAqB,CAAA;AACvB,CAAC,EALW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAKpB;AACD,CAAC"}
|
5
jsx-html/nodejs/jsx.d.ts
vendored
Normal file
5
jsx-html/nodejs/jsx.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
import { NodePropsType, ComponentFunctionType, NullableChildType, ChildType } from "./types";
|
||||
import { ElementNode } from "./node/ElementNode";
|
||||
import { ComponentNode } from "./node/ComponentNode";
|
||||
export declare const jsx: <P extends NodePropsType = NodePropsType>(element: string | ComponentFunctionType, props: P, ...children: NullableChildType[]) => ElementNode | ComponentNode;
|
||||
export declare const Fragment: (props: NodePropsType, children: ChildType) => NullableChildType;
|
19
jsx-html/nodejs/jsx.js
Normal file
19
jsx-html/nodejs/jsx.js
Normal file
@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Fragment = exports.jsx = void 0;
|
||||
const ElementNode_1 = require("./node/ElementNode");
|
||||
const ComponentNode_1 = require("./node/ComponentNode");
|
||||
exports.jsx = (element, props, ...children) => {
|
||||
const nodeProps = props || {};
|
||||
if (typeof element === 'string') {
|
||||
return new ElementNode_1.ElementNode(element, nodeProps, children);
|
||||
}
|
||||
if (typeof element === 'function') {
|
||||
return new ComponentNode_1.ComponentNode(element, nodeProps, children);
|
||||
}
|
||||
throw new TypeError(`Expected jsx element to be a string or a function`);
|
||||
};
|
||||
exports.Fragment = (props, children) => {
|
||||
return children;
|
||||
};
|
||||
//# sourceMappingURL=jsx.js.map
|
1
jsx-html/nodejs/jsx.js.map
Normal file
1
jsx-html/nodejs/jsx.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"jsx.js","sourceRoot":"","sources":["../tmp/jsx.ts"],"names":[],"mappings":";;;AACA,oDAAiD;AACjD,wDAAqD;AACxC,QAAA,GAAG,GAAG,CAA0C,OAAuC,EAAE,KAAe,EAAE,GAAG,QAA6B,EAAE,EAAE;IACzJ,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE,CAAC;IAE9B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,IAAI,yBAAW,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;KACtD;IAED,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;QACjC,OAAO,IAAI,6BAAa,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;KACxD;IAED,MAAM,IAAI,SAAS,CAAC,mDAAmD,CAAC,CAAC;AAC3E,CAAC,CAAC;AACW,QAAA,QAAQ,GAAG,CAAC,KAAoB,EAAE,QAAmB,EAAqB,EAAE;IACvF,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
|
9
jsx-html/nodejs/mod.d.ts
vendored
Normal file
9
jsx-html/nodejs/mod.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { jsx, Fragment } from "./jsx";
|
||||
import { ComponentFunctionType, NodePropsType, NullableChildType } from "./types";
|
||||
export { ElementNode } from "./node/ElementNode";
|
||||
export { ComponentNode } from "./node/ComponentNode";
|
||||
export { jsx, Fragment, ComponentFunctionType, NullableChildType, NodePropsType };
|
||||
export declare const React: {
|
||||
Fragment: (props: NodePropsType, children: import("./types").ChildType) => NullableChildType;
|
||||
createElement<P extends NodePropsType = NodePropsType>(element: string | ComponentFunctionType, props: P, ...children: NullableChildType[]): import("./node/ElementNode").ElementNode | import("./node/ComponentNode").ComponentNode;
|
||||
};
|
17
jsx-html/nodejs/mod.js
Normal file
17
jsx-html/nodejs/mod.js
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.React = exports.Fragment = exports.jsx = void 0;
|
||||
const jsx_1 = require("./jsx");
|
||||
Object.defineProperty(exports, "jsx", { enumerable: true, get: function () { return jsx_1.jsx; } });
|
||||
Object.defineProperty(exports, "Fragment", { enumerable: true, get: function () { return jsx_1.Fragment; } });
|
||||
var ElementNode_1 = require("./node/ElementNode");
|
||||
Object.defineProperty(exports, "ElementNode", { enumerable: true, get: function () { return ElementNode_1.ElementNode; } });
|
||||
var ComponentNode_1 = require("./node/ComponentNode");
|
||||
Object.defineProperty(exports, "ComponentNode", { enumerable: true, get: function () { return ComponentNode_1.ComponentNode; } });
|
||||
exports.React = {
|
||||
Fragment: jsx_1.Fragment,
|
||||
createElement(element, props, ...children) {
|
||||
return jsx_1.jsx(element, props, ...children);
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=mod.js.map
|
1
jsx-html/nodejs/mod.js.map
Normal file
1
jsx-html/nodejs/mod.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../tmp/mod.ts"],"names":[],"mappings":";;;AAAA,+BAAsC;AAI7B,oFAJA,SAAG,OAIA;AAAE,yFAJA,cAAQ,OAIA;AAFtB,kDAAiD;AAAxC,0GAAA,WAAW,OAAA;AACpB,sDAAqD;AAA5C,8GAAA,aAAa,OAAA;AAET,QAAA,KAAK,GAAG;IACnB,QAAQ,EAAR,cAAQ;IAER,aAAa,CAA0C,OAAuC,EAAE,KAAe,EAAE,GAAG,QAA6B;QAC/I,OAAO,SAAG,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC;IAC1C,CAAC;CAEF,CAAC"}
|
11
jsx-html/nodejs/node/ComponentNode.d.ts
vendored
Normal file
11
jsx-html/nodejs/node/ComponentNode.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
import { NodePropsType, ComponentFunctionType, NullableChildType } from "../types";
|
||||
import { NODE_TYPE } from "../constants";
|
||||
import { Node } from "./Node";
|
||||
export declare class ComponentNode extends Node {
|
||||
component: ComponentFunctionType;
|
||||
props: NodePropsType;
|
||||
type: NODE_TYPE;
|
||||
constructor(component: ComponentFunctionType, props: NodePropsType, children: NullableChildType[]);
|
||||
render(): Promise<string | any[]>;
|
||||
renderComponent(): Promise<string | any[]>;
|
||||
}
|
43
jsx-html/nodejs/node/ComponentNode.js
Normal file
43
jsx-html/nodejs/node/ComponentNode.js
Normal file
@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ComponentNode = void 0;
|
||||
const constants_1 = require("../constants");
|
||||
const FragmentNode_1 = require("./FragmentNode");
|
||||
const Node_1 = require("./Node");
|
||||
const normalizeChildren_1 = require("./utils/normalizeChildren");
|
||||
class ComponentNode extends Node_1.Node {
|
||||
constructor(component, props, children) {
|
||||
super(children);
|
||||
this.component = component;
|
||||
this.props = props;
|
||||
this.type = constants_1.NODE_TYPE.COMPONENT;
|
||||
}
|
||||
render() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return [].concat(yield this.renderComponent()).join('');
|
||||
});
|
||||
}
|
||||
renderComponent() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const child = yield this.component(this.props, this.children);
|
||||
const children = normalizeChildren_1.normalizeChildren(Array.isArray(child) ? child : [child]);
|
||||
if (children.length === 1) {
|
||||
return children[0].render();
|
||||
}
|
||||
else if (children.length > 1) {
|
||||
return new FragmentNode_1.FragmentNode(children).render();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ComponentNode = ComponentNode;
|
||||
//# sourceMappingURL=ComponentNode.js.map
|
1
jsx-html/nodejs/node/ComponentNode.js.map
Normal file
1
jsx-html/nodejs/node/ComponentNode.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"ComponentNode.js","sourceRoot":"","sources":["../../tmp/node/ComponentNode.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,4CAAyC;AACzC,iDAA8C;AAC9C,iCAA8B;AAC9B,iEAA8D;AAC9D,MAAa,aAAc,SAAQ,WAAI;IAGrC,YAAmB,SAAgC,EAAS,KAAoB,EAAE,QAA6B;QAC7G,KAAK,CAAC,QAAQ,CAAC,CAAC;QADC,cAAS,GAAT,SAAS,CAAuB;QAAS,UAAK,GAAL,KAAK,CAAe;QAFhF,SAAI,GAAG,qBAAS,CAAC,SAAS,CAAC;IAI3B,CAAC;IAEK,MAAM;;YACV,OAAO,EAAE,CAAC,MAAM,CAAE,MAAM,IAAI,CAAC,eAAe,EAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnE,CAAC;KAAA;IAEK,eAAe;;YACnB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC9D,MAAM,QAAQ,GAAG,qCAAiB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YAE3E,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;gBACzB,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;aAC7B;iBAAM,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC9B,OAAO,IAAI,2BAAY,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;aAC5C;QACH,CAAC;KAAA;CAEF;AAtBD,sCAsBC"}
|
12
jsx-html/nodejs/node/ElementNode.d.ts
vendored
Normal file
12
jsx-html/nodejs/node/ElementNode.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { NODE_TYPE } from "../constants";
|
||||
import { NodePropsType, NullableChildType } from "../types";
|
||||
import { Node } from "./Node";
|
||||
export declare class ElementNode extends Node {
|
||||
name: string;
|
||||
props: NodePropsType;
|
||||
type: NODE_TYPE;
|
||||
constructor(name: string, props: NodePropsType, children: NullableChildType[]);
|
||||
render(): Promise<string | any[]>;
|
||||
private getValidProps;
|
||||
private propsToHTML;
|
||||
}
|
60
jsx-html/nodejs/node/ElementNode.js
Normal file
60
jsx-html/nodejs/node/ElementNode.js
Normal file
@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ElementNode = void 0;
|
||||
const constants_1 = require("../constants");
|
||||
const Node_1 = require("./Node");
|
||||
const htmlEncode_1 = require("./utils/htmlEncode");
|
||||
const ELEMENT_PROP = {
|
||||
INNER_HTML: 'innerHTML'
|
||||
};
|
||||
class ElementNode extends Node_1.Node {
|
||||
constructor(name, props, children) {
|
||||
super(children);
|
||||
this.name = name;
|
||||
this.props = props;
|
||||
this.type = constants_1.NODE_TYPE.ELEMENT;
|
||||
}
|
||||
render() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const renderedProps = this.propsToHTML();
|
||||
const renderedChildren = typeof this.props[ELEMENT_PROP.INNER_HTML] === 'string' ? this.props[ELEMENT_PROP.INNER_HTML] : (yield this.renderChildren()).join('');
|
||||
return renderedChildren ? `<${this.name}${renderedProps}>${renderedChildren}</${this.name}>` : `<${this.name}${renderedProps} />`;
|
||||
});
|
||||
}
|
||||
getValidProps() {
|
||||
const props = this.props;
|
||||
return Object.keys(this.props).filter(key => {
|
||||
if (key === ELEMENT_PROP.INNER_HTML) {
|
||||
return false;
|
||||
}
|
||||
const val = props[key];
|
||||
return typeof val === 'string' || typeof val === 'number' || val === true;
|
||||
});
|
||||
}
|
||||
propsToHTML() {
|
||||
const keys = this.getValidProps();
|
||||
if (!keys.length) {
|
||||
return '';
|
||||
}
|
||||
const props = this.props;
|
||||
const pairs = keys.map(key => {
|
||||
if (!/^[a-zA-Z0-9-:\._]+$/.test(key)) {
|
||||
throw new Error(`Invalid attribute name format ${key}`);
|
||||
}
|
||||
const val = props[key];
|
||||
return val === true || val === '' ? key : `${key}="${htmlEncode_1.doubleQuoteEncode(val.toString())}"`;
|
||||
});
|
||||
return ` ${pairs.join(' ')}`;
|
||||
}
|
||||
}
|
||||
exports.ElementNode = ElementNode;
|
||||
//# sourceMappingURL=ElementNode.js.map
|
1
jsx-html/nodejs/node/ElementNode.js.map
Normal file
1
jsx-html/nodejs/node/ElementNode.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"ElementNode.js","sourceRoot":"","sources":["../../tmp/node/ElementNode.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAyC;AAEzC,iCAA8B;AAC9B,mDAAuD;AACvD,MAAM,YAAY,GAAG;IACnB,UAAU,EAAE,WAAW;CACxB,CAAC;AACF,MAAa,WAAY,SAAQ,WAAI;IAGnC,YAAmB,IAAY,EAAS,KAAoB,EAAE,QAA6B;QACzF,KAAK,CAAC,QAAQ,CAAC,CAAC;QADC,SAAI,GAAJ,IAAI,CAAQ;QAAS,UAAK,GAAL,KAAK,CAAe;QAF5D,SAAI,GAAG,qBAAS,CAAC,OAAO,CAAC;IAIzB,CAAC;IAEK,MAAM;;YACV,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YACzC,MAAM,gBAAgB,GAAG,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAChK,OAAO,gBAAgB,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,aAAa,IAAI,gBAAgB,KAAK,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,aAAa,KAAK,CAAC;QACpI,CAAC;KAAA;IAEO,aAAa;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YAC1C,IAAI,GAAG,KAAK,YAAY,CAAC,UAAU,EAAE;gBACnC,OAAO,KAAK,CAAC;aACd;YAED,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YACvB,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,CAAC;QAC5E,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,WAAW;QACjB,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAElC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,OAAO,EAAE,CAAC;SACX;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAC3B,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBACpC,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,EAAE,CAAC,CAAC;aACzD;YAED,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YAEvB,OAAO,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,8BAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC;QAC5F,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC/B,CAAC;CAEF;AA7CD,kCA6CC"}
|
8
jsx-html/nodejs/node/FragmentNode.d.ts
vendored
Normal file
8
jsx-html/nodejs/node/FragmentNode.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import { NODE_TYPE } from "../constants";
|
||||
import { ChildNodeType } from "../types";
|
||||
import { Node } from "./Node";
|
||||
export declare class FragmentNode extends Node {
|
||||
type: NODE_TYPE;
|
||||
constructor(children: ChildNodeType[]);
|
||||
render(): Promise<string[]>;
|
||||
}
|
16
jsx-html/nodejs/node/FragmentNode.js
Normal file
16
jsx-html/nodejs/node/FragmentNode.js
Normal file
@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FragmentNode = void 0;
|
||||
const constants_1 = require("../constants");
|
||||
const Node_1 = require("./Node");
|
||||
class FragmentNode extends Node_1.Node {
|
||||
constructor(children) {
|
||||
super(children);
|
||||
this.type = constants_1.NODE_TYPE.FRAGMENT;
|
||||
}
|
||||
render() {
|
||||
return this.renderChildren();
|
||||
}
|
||||
}
|
||||
exports.FragmentNode = FragmentNode;
|
||||
//# sourceMappingURL=FragmentNode.js.map
|
1
jsx-html/nodejs/node/FragmentNode.js.map
Normal file
1
jsx-html/nodejs/node/FragmentNode.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"FragmentNode.js","sourceRoot":"","sources":["../../tmp/node/FragmentNode.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AAEzC,iCAA8B;AAC9B,MAAa,YAAa,SAAQ,WAAI;IAGpC,YAAY,QAAyB;QACnC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAHlB,SAAI,GAAG,qBAAS,CAAC,QAAQ,CAAC;IAI1B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC;IAC/B,CAAC;CAEF;AAXD,oCAWC"}
|
9
jsx-html/nodejs/node/Node.d.ts
vendored
Normal file
9
jsx-html/nodejs/node/Node.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { NODE_TYPE } from "../constants";
|
||||
import { NullableChildType } from "../types";
|
||||
export declare abstract class Node {
|
||||
children: NullableChildType[];
|
||||
abstract type: NODE_TYPE;
|
||||
constructor(children: NullableChildType[]);
|
||||
abstract render(): Promise<string | any[]>;
|
||||
renderChildren(): Promise<string[]>;
|
||||
}
|
38
jsx-html/nodejs/node/Node.js
Normal file
38
jsx-html/nodejs/node/Node.js
Normal file
@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Node = void 0;
|
||||
const normalizeChildren_1 = require("./utils/normalizeChildren");
|
||||
class Node {
|
||||
constructor(children) {
|
||||
this.children = children;
|
||||
}
|
||||
renderChildren() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const result = [];
|
||||
const children = normalizeChildren_1.normalizeChildren(this.children);
|
||||
for (const child of children) {
|
||||
const renderedChild = yield child.render();
|
||||
if (renderedChild) {
|
||||
if (Array.isArray(renderedChild)) {
|
||||
renderedChild.forEach(subchild => subchild && result.push(subchild));
|
||||
}
|
||||
else {
|
||||
result.push(renderedChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Node = Node;
|
||||
//# sourceMappingURL=Node.js.map
|
1
jsx-html/nodejs/node/Node.js.map
Normal file
1
jsx-html/nodejs/node/Node.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"Node.js","sourceRoot":"","sources":["../../tmp/node/Node.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,iEAA8D;AAC9D,MAAsB,IAAI;IAGxB,YAAmB,QAA6B;QAA7B,aAAQ,GAAR,QAAQ,CAAqB;IAAG,CAAC;IAI9C,cAAc;;YAClB,MAAM,MAAM,GAAa,EAAE,CAAC;YAC5B,MAAM,QAAQ,GAAG,qCAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAElD,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;gBAC5B,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC;gBAE3C,IAAI,aAAa,EAAE;oBACjB,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;wBAChC,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;qBACtE;yBAAM;wBACL,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;qBAC5B;iBACF;aACF;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CAEF;AA1BD,oBA0BC"}
|
7
jsx-html/nodejs/node/TextNode.d.ts
vendored
Normal file
7
jsx-html/nodejs/node/TextNode.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import { NODE_TYPE } from "../constants";
|
||||
export declare class TextNode {
|
||||
text: string;
|
||||
type: NODE_TYPE;
|
||||
constructor(text: string);
|
||||
render(): Promise<string | any[]>;
|
||||
}
|
27
jsx-html/nodejs/node/TextNode.js
Normal file
27
jsx-html/nodejs/node/TextNode.js
Normal file
@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TextNode = void 0;
|
||||
const constants_1 = require("../constants");
|
||||
const htmlEncode_1 = require("./utils/htmlEncode");
|
||||
class TextNode {
|
||||
constructor(text) {
|
||||
this.text = text;
|
||||
this.type = constants_1.NODE_TYPE.TEXT;
|
||||
}
|
||||
render() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return htmlEncode_1.htmlEncode(this.text);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.TextNode = TextNode;
|
||||
//# sourceMappingURL=TextNode.js.map
|
1
jsx-html/nodejs/node/TextNode.js.map
Normal file
1
jsx-html/nodejs/node/TextNode.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"TextNode.js","sourceRoot":"","sources":["../../tmp/node/TextNode.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAyC;AACzC,mDAAgD;AAChD,MAAa,QAAQ;IAGnB,YAAmB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAF/B,SAAI,GAAG,qBAAS,CAAC,IAAI,CAAC;IAEY,CAAC;IAE7B,MAAM;;YACV,OAAO,uBAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;KAAA;CAEF;AATD,4BASC"}
|
2
jsx-html/nodejs/node/utils/htmlEncode.d.ts
vendored
Normal file
2
jsx-html/nodejs/node/utils/htmlEncode.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export declare function doubleQuoteEncode(text: string): string;
|
||||
export declare function htmlEncode(text: string): string;
|
12
jsx-html/nodejs/node/utils/htmlEncode.js
Normal file
12
jsx-html/nodejs/node/utils/htmlEncode.js
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.htmlEncode = exports.doubleQuoteEncode = void 0;
|
||||
function doubleQuoteEncode(text) {
|
||||
return text.replace(/"/g, '"');
|
||||
}
|
||||
exports.doubleQuoteEncode = doubleQuoteEncode;
|
||||
function htmlEncode(text) {
|
||||
return doubleQuoteEncode(text.replace(/&/g, '&').replace(/\//g, '/').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, '''));
|
||||
}
|
||||
exports.htmlEncode = htmlEncode;
|
||||
//# sourceMappingURL=htmlEncode.js.map
|
1
jsx-html/nodejs/node/utils/htmlEncode.js.map
Normal file
1
jsx-html/nodejs/node/utils/htmlEncode.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"htmlEncode.js","sourceRoot":"","sources":["../../../tmp/node/utils/htmlEncode.ts"],"names":[],"mappings":";;;AAAA,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AAFD,8CAEC;AACD,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AACpJ,CAAC;AAFD,gCAEC"}
|
2
jsx-html/nodejs/node/utils/normalizeChildren.d.ts
vendored
Normal file
2
jsx-html/nodejs/node/utils/normalizeChildren.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import { NullableChildType, ChildNodeType } from "../../types";
|
||||
export declare function normalizeChildren(children: NullableChildType[]): ChildNodeType[];
|
27
jsx-html/nodejs/node/utils/normalizeChildren.js
Normal file
27
jsx-html/nodejs/node/utils/normalizeChildren.js
Normal file
@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.normalizeChildren = void 0;
|
||||
const TextNode_1 = require("../TextNode");
|
||||
const constants_1 = require("../../constants");
|
||||
function normalizeChildren(children) {
|
||||
const result = [];
|
||||
for (const child of children) {
|
||||
if (child && typeof child !== 'boolean') {
|
||||
if (typeof child === 'string' || typeof child === 'number') {
|
||||
result.push(new TextNode_1.TextNode(`${child}`));
|
||||
}
|
||||
else if (Array.isArray(child)) {
|
||||
normalizeChildren(child).forEach(result.push);
|
||||
}
|
||||
else if (child.type === constants_1.NODE_TYPE.ELEMENT || child.type === constants_1.NODE_TYPE.TEXT || child.type === constants_1.NODE_TYPE.COMPONENT) {
|
||||
result.push(child);
|
||||
}
|
||||
else {
|
||||
throw new TypeError(`Unrecognized node type: ${typeof child}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.normalizeChildren = normalizeChildren;
|
||||
//# sourceMappingURL=normalizeChildren.js.map
|
1
jsx-html/nodejs/node/utils/normalizeChildren.js.map
Normal file
1
jsx-html/nodejs/node/utils/normalizeChildren.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"normalizeChildren.js","sourceRoot":"","sources":["../../../tmp/node/utils/normalizeChildren.ts"],"names":[],"mappings":";;;AACA,0CAAuC;AACvC,+CAA4C;AAC5C,SAAgB,iBAAiB,CAAC,QAA6B;IAC7D,MAAM,MAAM,GAAU,EAAE,CAAC;IAEzB,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;QAC5B,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;YACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBAC1D,MAAM,CAAC,IAAI,CAAC,IAAI,mBAAQ,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC;aACvC;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAC/B,iBAAiB,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aAC/C;iBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAS,CAAC,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAS,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAS,CAAC,SAAS,EAAE;gBAClH,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;iBAAM;gBACL,MAAM,IAAI,SAAS,CAAC,2BAA2B,OAAO,KAAK,EAAE,CAAC,CAAC;aAChE;SACF;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAlBD,8CAkBC"}
|
15
jsx-html/nodejs/types.d.ts
vendored
Normal file
15
jsx-html/nodejs/types.d.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
import { ElementNode } from "./node/ElementNode";
|
||||
import { TextNode } from "./node/TextNode";
|
||||
import { ComponentNode } from "./node/ComponentNode";
|
||||
import { FragmentNode } from "./node/FragmentNode";
|
||||
export declare type NodePropsType = {
|
||||
[key: string]: any;
|
||||
};
|
||||
declare type Primitive = string | boolean | number;
|
||||
declare type NullablePrimitive = Primitive | null | void;
|
||||
export declare type ChildNodeType = ElementNode | TextNode | ComponentNode;
|
||||
export declare type NodeType = ChildNodeType | FragmentNode;
|
||||
export declare type ChildType = ChildNodeType | Primitive;
|
||||
export declare type NullableChildType = ChildType | ChildNodeType | NullablePrimitive;
|
||||
export declare type ComponentFunctionType = (props: NodePropsType, child?: NullableChildType[]) => NullableChildType | Promise<NullableChildType>;
|
||||
export {};
|
3
jsx-html/nodejs/types.js
Normal file
3
jsx-html/nodejs/types.js
Normal file
@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
1
jsx-html/nodejs/types.js.map
Normal file
1
jsx-html/nodejs/types.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../tmp/types.ts"],"names":[],"mappings":""}
|
Reference in New Issue
Block a user