@gera2ld/jsx-dom
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -1,4 +0,6 @@ | ||
/*! @gera2ld/jsx-dom v1.1.2 | ISC License */ | ||
/*! @gera2ld/jsx-dom v1.2.0 | ISC License */ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var propRules = ['innerHTML', 'innerText', 'textContent', { | ||
@@ -12,12 +14,14 @@ key: 'value', | ||
function createElement(tag, props) { | ||
var el; | ||
var result; | ||
var ref; | ||
if (tag === Fragment) { | ||
el = document.createDocumentFragment(); | ||
result = document.createDocumentFragment(); | ||
} else if (typeof tag !== 'string') { | ||
throw new Error("Invalid element type: " + tag); | ||
} else { | ||
el = createElement.createElement(tag); | ||
var _el = createElement.createElement(tag); | ||
result = _el; | ||
if (props) { | ||
@@ -29,18 +33,19 @@ Object.keys(props).forEach(function (key) { | ||
if (key.startsWith('on')) { | ||
el.addEventListener(key.slice(2).toLowerCase(), value); | ||
_el.addEventListener(key.slice(2).toLowerCase(), value); | ||
} else if (key === 'children') { | ||
renderChild(el, value); | ||
renderChildren(_el, value); | ||
} else if (key === 'style' && typeof value === 'object') { | ||
renderStyle(el, value); | ||
renderStyle(_el, value); | ||
} else if (key === 'dangerouslySetInnerHTML' && value) { | ||
el.innerHTML = value.__html || ''; // eslint-disable-line no-underscore-dangle | ||
_el.innerHTML = value.__html || ''; // eslint-disable-line no-underscore-dangle | ||
} else if (key === 'ref' && typeof value === 'function') { | ||
ref = value; | ||
} else if (typeof value === 'boolean') { | ||
if (value) el.setAttribute(key, key);else el.removeAttribute(key); | ||
} else if (matchProps(tag, key, value)) { | ||
el[key] = value; | ||
if (value) _el.setAttribute(key, key);else _el.removeAttribute(key); | ||
} else if (isProp(tag, key)) { | ||
_el[key] = value; | ||
} else { | ||
if (key === 'className') key = 'class';else if (key === 'labelFor') key = 'for'; | ||
el.setAttribute(key, "" + value); | ||
_el.setAttribute(key, "" + value); | ||
} | ||
@@ -55,5 +60,5 @@ }); | ||
renderChild(el, children); | ||
if (ref) ref(el); | ||
return el; | ||
renderChildren(result, children); | ||
if (ref) ref(result); | ||
return result; | ||
} | ||
@@ -65,11 +70,9 @@ | ||
function matchProps(tag, key, value) { | ||
function isProp(tag, key) { | ||
var ctx = { | ||
tag: tag, | ||
key: key | ||
}; | ||
return propRules.some(function (rule) { | ||
if (!rule) return false; | ||
if (typeof rule === 'string') return key === rule; | ||
var ctx = { | ||
tag: tag, | ||
key: key, | ||
value: value | ||
}; | ||
return Object.keys(rule).every(function (rk) { | ||
@@ -81,17 +84,12 @@ return rule[rk] === ctx[rk]; | ||
function renderChild(el, child) { | ||
if (Array.isArray(child)) { | ||
child.forEach(function (ch) { | ||
return renderChild(el, ch); | ||
}); | ||
return; | ||
} | ||
function renderChildren(el, children) { | ||
children.forEach(function (child) { | ||
if (child == null || child === false) return; | ||
if (child == null || child === false) return; | ||
if (typeof child !== 'object') { | ||
el.appendChild(document.createTextNode("" + child)); | ||
} else { | ||
el.appendChild(child); | ||
} | ||
if (typeof child !== 'object') { | ||
el.appendChild(document.createTextNode("" + child)); | ||
} else { | ||
el.appendChild(child); | ||
} | ||
}); | ||
} | ||
@@ -98,0 +96,0 @@ |
@@ -1,3 +0,3 @@ | ||
/*! @gera2ld/jsx-dom v1.1.2 | ISC License */ | ||
var JSX = (function (exports) { | ||
/*! @gera2ld/jsx-dom v1.2.0 | ISC License */ | ||
(function (exports) { | ||
'use strict'; | ||
@@ -13,12 +13,14 @@ | ||
function createElement(tag, props) { | ||
var el; | ||
var result; | ||
var ref; | ||
if (tag === Fragment) { | ||
el = document.createDocumentFragment(); | ||
result = document.createDocumentFragment(); | ||
} else if (typeof tag !== 'string') { | ||
throw new Error("Invalid element type: " + tag); | ||
} else { | ||
el = createElement.createElement(tag); | ||
var _el = createElement.createElement(tag); | ||
result = _el; | ||
if (props) { | ||
@@ -30,18 +32,19 @@ Object.keys(props).forEach(function (key) { | ||
if (key.startsWith('on')) { | ||
el.addEventListener(key.slice(2).toLowerCase(), value); | ||
_el.addEventListener(key.slice(2).toLowerCase(), value); | ||
} else if (key === 'children') { | ||
renderChild(el, value); | ||
renderChildren(_el, value); | ||
} else if (key === 'style' && typeof value === 'object') { | ||
renderStyle(el, value); | ||
renderStyle(_el, value); | ||
} else if (key === 'dangerouslySetInnerHTML' && value) { | ||
el.innerHTML = value.__html || ''; // eslint-disable-line no-underscore-dangle | ||
_el.innerHTML = value.__html || ''; // eslint-disable-line no-underscore-dangle | ||
} else if (key === 'ref' && typeof value === 'function') { | ||
ref = value; | ||
} else if (typeof value === 'boolean') { | ||
if (value) el.setAttribute(key, key);else el.removeAttribute(key); | ||
} else if (matchProps(tag, key, value)) { | ||
el[key] = value; | ||
if (value) _el.setAttribute(key, key);else _el.removeAttribute(key); | ||
} else if (isProp(tag, key)) { | ||
_el[key] = value; | ||
} else { | ||
if (key === 'className') key = 'class';else if (key === 'labelFor') key = 'for'; | ||
el.setAttribute(key, "" + value); | ||
_el.setAttribute(key, "" + value); | ||
} | ||
@@ -56,5 +59,5 @@ }); | ||
renderChild(el, children); | ||
if (ref) ref(el); | ||
return el; | ||
renderChildren(result, children); | ||
if (ref) ref(result); | ||
return result; | ||
} | ||
@@ -66,11 +69,9 @@ | ||
function matchProps(tag, key, value) { | ||
function isProp(tag, key) { | ||
var ctx = { | ||
tag: tag, | ||
key: key | ||
}; | ||
return propRules.some(function (rule) { | ||
if (!rule) return false; | ||
if (typeof rule === 'string') return key === rule; | ||
var ctx = { | ||
tag: tag, | ||
key: key, | ||
value: value | ||
}; | ||
return Object.keys(rule).every(function (rk) { | ||
@@ -82,17 +83,12 @@ return rule[rk] === ctx[rk]; | ||
function renderChild(el, child) { | ||
if (Array.isArray(child)) { | ||
child.forEach(function (ch) { | ||
return renderChild(el, ch); | ||
}); | ||
return; | ||
} | ||
function renderChildren(el, children) { | ||
children.forEach(function (child) { | ||
if (child == null || child === false) return; | ||
if (child == null || child === false) return; | ||
if (typeof child !== 'object') { | ||
el.appendChild(document.createTextNode("" + child)); | ||
} else { | ||
el.appendChild(child); | ||
} | ||
if (typeof child !== 'object') { | ||
el.appendChild(document.createTextNode("" + child)); | ||
} else { | ||
el.appendChild(child); | ||
} | ||
}); | ||
} | ||
@@ -110,4 +106,2 @@ | ||
return exports; | ||
}({})); | ||
}(this.JSX = this.JSX || {})); |
{ | ||
"name": "@gera2ld/jsx-dom", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Use JSX for HTML elements.", | ||
@@ -16,3 +16,3 @@ "author": "Gerald <i@gerald.top>", | ||
"build": "tsc && npm run build:js", | ||
"lint": "tslint -c tslint.json 'src/**/*.ts'", | ||
"lint": "eslint --ext .ts .", | ||
"prepublishOnly": "npm run build", | ||
@@ -29,4 +29,4 @@ "ci": "npm run lint", | ||
"typings": "types/index.d.ts", | ||
"unpkg": "dist/index.min.js", | ||
"jsdelivr": "dist/index.min.js", | ||
"unpkg": "dist/index.js", | ||
"jsdelivr": "dist/index.js", | ||
"publishConfig": { | ||
@@ -36,2 +36,3 @@ "access": "public" | ||
"main": "dist/index.common.js", | ||
"module": "dist/index.esm.js", | ||
"files": [ | ||
@@ -42,20 +43,11 @@ "dist", | ||
"devDependencies": { | ||
"@babel/preset-typescript": "^7.3.3", | ||
"@gera2ld/plaid": "~1.4.0", | ||
"cross-env": "^5.2.0", | ||
"del-cli": "^1.1.0", | ||
"husky": "^2.2.0", | ||
"rollup": "^1.11.3", | ||
"rollup-plugin-alias": "^1.5.1", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-commonjs": "^9.3.4", | ||
"rollup-plugin-node-resolve": "^4.2.3", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-uglify": "^6.0.2", | ||
"tslint": "^5.16.0", | ||
"typescript": "^3.4.5" | ||
"@gera2ld/plaid": "~2.0.0", | ||
"@gera2ld/plaid-common-ts": "^2.0.5", | ||
"@gera2ld/plaid-rollup": "~2.0.0", | ||
"del-cli": "^3.0.1", | ||
"husky": "^4.2.5" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.4" | ||
"@babel/runtime": "^7.11.0" | ||
} | ||
} |
@@ -18,3 +18,3 @@ # @gera2ld/jsx-dom | ||
```js | ||
import h from '@gera2ld/jsx-dom'; | ||
import React from '@gera2ld/jsx-dom'; | ||
@@ -29,5 +29,3 @@ document.body.appendChild(<div>hello</div>); | ||
"plugins": [ | ||
["@babel/plugin-transform-react-jsx", { | ||
"pragma": "h", | ||
}], | ||
"@babel/plugin-transform-react-jsx", | ||
], | ||
@@ -48,8 +46,3 @@ } | ||
}, | ||
settings: { | ||
react: { | ||
pragma: 'h', | ||
}, | ||
}, | ||
}; | ||
``` |
@@ -1,9 +0,14 @@ | ||
interface IComponent { | ||
interface JSXComponent { | ||
name?: string; | ||
} | ||
export declare const Fragment: IComponent; | ||
export declare function createElement(tag: string | IComponent, props?: object, ...children: any[]): any; | ||
export declare const Fragment: JSXComponent; | ||
export declare type JSXProps = { | ||
[key: string]: any; | ||
}; | ||
export declare type JSXElement = HTMLElement | DocumentFragment; | ||
export declare type JSXChild = string | boolean | JSXElement; | ||
export declare function createElement(tag: string | JSXComponent, props?: JSXProps, ...children: JSXChild[]): JSXElement; | ||
export declare namespace createElement { | ||
var createElement: (tag: any) => any; | ||
var createElement: (tag: string) => HTMLElement; | ||
} | ||
export {}; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
11635
5
7
267
1
46
1
Updated@babel/runtime@^7.11.0