snabbdom-jsx-lite
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "snabbdom-jsx-lite", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Write snabbdom templates in .jsx or .tsx (JSX for TypeScript)", | ||
@@ -39,3 +39,3 @@ "files": [ | ||
"eslint-plugin-react": "7.18.3", | ||
"lint-config-nojvek": "1.0.2", | ||
"lint-config-nojvek": "1.0.3", | ||
"prettier": "2.0.5", | ||
@@ -50,3 +50,6 @@ "prettier-eslint": "9.0.1", | ||
}, | ||
"dependencies": {} | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"snabbdom": ">=0.6.1" | ||
} | ||
} |
@@ -40,2 +40,3 @@ # snabbdom-jsx-lite | ||
<div> | ||
{/* `sel` is css selector shorthand, <img sel=".profile" /> is same as <img class={profile: true} /> */} | ||
<img sel=".profile" attrs={{src: 'avatar.png'}} /> | ||
@@ -42,0 +43,0 @@ <h3>{[user.firstName, user.lastName].join(' ')}</h3> |
@@ -7,3 +7,6 @@ import {vnode, VNode, VNodeData} from 'snabbdom/vnode'; | ||
export type JsxVNodeChildren = JsxVNodeChild | JsxVNodeChild[]; | ||
export type JsxVNodeProps = VNodeData & {sel?: string}; | ||
export interface JsxVNodeProps extends VNodeData { | ||
/** css selector shorthand e.g <div sel="#id.class1.class1" /> */ | ||
sel?: string; | ||
} | ||
@@ -69,3 +72,3 @@ export type FunctionComponent = (props: {[prop: string]: any} | null, children?: VNode[]) => VNode; | ||
// append sel css selector to tag to support equivalent of h('span.foo.bar') | ||
// append sel css selector to tag to support equivalent of h('div.foo.bar') | ||
if (data && data.sel) { | ||
@@ -76,5 +79,6 @@ tag += data.sel; | ||
// NOTE: we don't hook into snabbdom's h, but directly create vnodes. | ||
// h is just a similar wrapper for creating vnodes. This lets us be performant | ||
if (flattenedChildren.length === 1 && flattenedChildren[0].sel === undefined && flattenedChildren[0].text) { | ||
const numFlattenedChildren = flattenedChildren.length; | ||
if (numFlattenedChildren === 0) { | ||
return vnode(tag, data, undefined, undefined, undefined); | ||
} else if (numFlattenedChildren === 1 && flattenedChildren[0].sel === undefined && flattenedChildren[0].text) { | ||
// only child is a simple text node, return as simple text node | ||
@@ -81,0 +85,0 @@ return vnode(tag, data, undefined, flattenedChildren[0].text, undefined); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
16306
202
105
0
1