forked from enviPath/enviPy
Current Dev State
This commit is contained in:
49
static/js/ketcher2/node_modules/preact/src/vdom/component-recycler.js
generated
vendored
Normal file
49
static/js/ketcher2/node_modules/preact/src/vdom/component-recycler.js
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
import { Component } from '../component';
|
||||
|
||||
/** Retains a pool of Components for re-use, keyed on component name.
|
||||
* Note: since component names are not unique or even necessarily available, these are primarily a form of sharding.
|
||||
* @private
|
||||
*/
|
||||
const components = {};
|
||||
|
||||
|
||||
/** Reclaim a component for later re-use by the recycler. */
|
||||
export function collectComponent(component) {
|
||||
let name = component.constructor.name;
|
||||
(components[name] || (components[name] = [])).push(component);
|
||||
}
|
||||
|
||||
|
||||
/** Create a component. Normalizes differences between PFC's and classful Components. */
|
||||
export function createComponent(Ctor, props, context) {
|
||||
let list = components[Ctor.name],
|
||||
inst;
|
||||
|
||||
if (Ctor.prototype && Ctor.prototype.render) {
|
||||
inst = new Ctor(props, context);
|
||||
Component.call(inst, props, context);
|
||||
}
|
||||
else {
|
||||
inst = new Component(props, context);
|
||||
inst.constructor = Ctor;
|
||||
inst.render = doRender;
|
||||
}
|
||||
|
||||
|
||||
if (list) {
|
||||
for (let i=list.length; i--; ) {
|
||||
if (list[i].constructor===Ctor) {
|
||||
inst.nextBase = list[i].nextBase;
|
||||
list.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
|
||||
|
||||
/** The `.render()` method for a PFC backing instance. */
|
||||
function doRender(props, state, context) {
|
||||
return this.constructor(props, context);
|
||||
}
|
||||
274
static/js/ketcher2/node_modules/preact/src/vdom/component.js
generated
vendored
Normal file
274
static/js/ketcher2/node_modules/preact/src/vdom/component.js
generated
vendored
Normal file
@ -0,0 +1,274 @@
|
||||
import { SYNC_RENDER, NO_RENDER, FORCE_RENDER, ASYNC_RENDER, ATTR_KEY } from '../constants';
|
||||
import options from '../options';
|
||||
import { extend } from '../util';
|
||||
import { enqueueRender } from '../render-queue';
|
||||
import { getNodeProps } from './index';
|
||||
import { diff, mounts, diffLevel, flushMounts, recollectNodeTree, removeChildren } from './diff';
|
||||
import { createComponent, collectComponent } from './component-recycler';
|
||||
import { removeNode } from '../dom';
|
||||
|
||||
/** Set a component's `props` (generally derived from JSX attributes).
|
||||
* @param {Object} props
|
||||
* @param {Object} [opts]
|
||||
* @param {boolean} [opts.renderSync=false] If `true` and {@link options.syncComponentUpdates} is `true`, triggers synchronous rendering.
|
||||
* @param {boolean} [opts.render=true] If `false`, no render will be triggered.
|
||||
*/
|
||||
export function setComponentProps(component, props, opts, context, mountAll) {
|
||||
if (component._disable) return;
|
||||
component._disable = true;
|
||||
|
||||
if ((component.__ref = props.ref)) delete props.ref;
|
||||
if ((component.__key = props.key)) delete props.key;
|
||||
|
||||
if (!component.base || mountAll) {
|
||||
if (component.componentWillMount) component.componentWillMount();
|
||||
}
|
||||
else if (component.componentWillReceiveProps) {
|
||||
component.componentWillReceiveProps(props, context);
|
||||
}
|
||||
|
||||
if (context && context!==component.context) {
|
||||
if (!component.prevContext) component.prevContext = component.context;
|
||||
component.context = context;
|
||||
}
|
||||
|
||||
if (!component.prevProps) component.prevProps = component.props;
|
||||
component.props = props;
|
||||
|
||||
component._disable = false;
|
||||
|
||||
if (opts!==NO_RENDER) {
|
||||
if (opts===SYNC_RENDER || options.syncComponentUpdates!==false || !component.base) {
|
||||
renderComponent(component, SYNC_RENDER, mountAll);
|
||||
}
|
||||
else {
|
||||
enqueueRender(component);
|
||||
}
|
||||
}
|
||||
|
||||
if (component.__ref) component.__ref(component);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Render a Component, triggering necessary lifecycle events and taking High-Order Components into account.
|
||||
* @param {Component} component
|
||||
* @param {Object} [opts]
|
||||
* @param {boolean} [opts.build=false] If `true`, component will build and store a DOM node if not already associated with one.
|
||||
* @private
|
||||
*/
|
||||
export function renderComponent(component, opts, mountAll, isChild) {
|
||||
if (component._disable) return;
|
||||
|
||||
let props = component.props,
|
||||
state = component.state,
|
||||
context = component.context,
|
||||
previousProps = component.prevProps || props,
|
||||
previousState = component.prevState || state,
|
||||
previousContext = component.prevContext || context,
|
||||
isUpdate = component.base,
|
||||
nextBase = component.nextBase,
|
||||
initialBase = isUpdate || nextBase,
|
||||
initialChildComponent = component._component,
|
||||
skip = false,
|
||||
rendered, inst, cbase;
|
||||
|
||||
// if updating
|
||||
if (isUpdate) {
|
||||
component.props = previousProps;
|
||||
component.state = previousState;
|
||||
component.context = previousContext;
|
||||
if (opts!==FORCE_RENDER
|
||||
&& component.shouldComponentUpdate
|
||||
&& component.shouldComponentUpdate(props, state, context) === false) {
|
||||
skip = true;
|
||||
}
|
||||
else if (component.componentWillUpdate) {
|
||||
component.componentWillUpdate(props, state, context);
|
||||
}
|
||||
component.props = props;
|
||||
component.state = state;
|
||||
component.context = context;
|
||||
}
|
||||
|
||||
component.prevProps = component.prevState = component.prevContext = component.nextBase = null;
|
||||
component._dirty = false;
|
||||
|
||||
if (!skip) {
|
||||
rendered = component.render(props, state, context);
|
||||
|
||||
// context to pass to the child, can be updated via (grand-)parent component
|
||||
if (component.getChildContext) {
|
||||
context = extend(extend({}, context), component.getChildContext());
|
||||
}
|
||||
|
||||
let childComponent = rendered && rendered.nodeName,
|
||||
toUnmount, base;
|
||||
|
||||
if (typeof childComponent==='function') {
|
||||
// set up high order component link
|
||||
|
||||
let childProps = getNodeProps(rendered);
|
||||
inst = initialChildComponent;
|
||||
|
||||
if (inst && inst.constructor===childComponent && childProps.key==inst.__key) {
|
||||
setComponentProps(inst, childProps, SYNC_RENDER, context, false);
|
||||
}
|
||||
else {
|
||||
toUnmount = inst;
|
||||
|
||||
component._component = inst = createComponent(childComponent, childProps, context);
|
||||
inst.nextBase = inst.nextBase || nextBase;
|
||||
inst._parentComponent = component;
|
||||
setComponentProps(inst, childProps, NO_RENDER, context, false);
|
||||
renderComponent(inst, SYNC_RENDER, mountAll, true);
|
||||
}
|
||||
|
||||
base = inst.base;
|
||||
}
|
||||
else {
|
||||
cbase = initialBase;
|
||||
|
||||
// destroy high order component link
|
||||
toUnmount = initialChildComponent;
|
||||
if (toUnmount) {
|
||||
cbase = component._component = null;
|
||||
}
|
||||
|
||||
if (initialBase || opts===SYNC_RENDER) {
|
||||
if (cbase) cbase._component = null;
|
||||
base = diff(cbase, rendered, context, mountAll || !isUpdate, initialBase && initialBase.parentNode, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (initialBase && base!==initialBase && inst!==initialChildComponent) {
|
||||
let baseParent = initialBase.parentNode;
|
||||
if (baseParent && base!==baseParent) {
|
||||
baseParent.replaceChild(base, initialBase);
|
||||
|
||||
if (!toUnmount) {
|
||||
initialBase._component = null;
|
||||
recollectNodeTree(initialBase, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toUnmount) {
|
||||
unmountComponent(toUnmount);
|
||||
}
|
||||
|
||||
component.base = base;
|
||||
if (base && !isChild) {
|
||||
let componentRef = component,
|
||||
t = component;
|
||||
while ((t=t._parentComponent)) {
|
||||
(componentRef = t).base = base;
|
||||
}
|
||||
base._component = componentRef;
|
||||
base._componentConstructor = componentRef.constructor;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isUpdate || mountAll) {
|
||||
mounts.unshift(component);
|
||||
}
|
||||
else if (!skip) {
|
||||
// Ensure that pending componentDidMount() hooks of child components
|
||||
// are called before the componentDidUpdate() hook in the parent.
|
||||
flushMounts();
|
||||
|
||||
if (component.componentDidUpdate) {
|
||||
component.componentDidUpdate(previousProps, previousState, previousContext);
|
||||
}
|
||||
if (options.afterUpdate) options.afterUpdate(component);
|
||||
}
|
||||
|
||||
if (component._renderCallbacks!=null) {
|
||||
while (component._renderCallbacks.length) component._renderCallbacks.pop().call(component);
|
||||
}
|
||||
|
||||
if (!diffLevel && !isChild) flushMounts();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Apply the Component referenced by a VNode to the DOM.
|
||||
* @param {Element} dom The DOM node to mutate
|
||||
* @param {VNode} vnode A Component-referencing VNode
|
||||
* @returns {Element} dom The created/mutated element
|
||||
* @private
|
||||
*/
|
||||
export function buildComponentFromVNode(dom, vnode, context, mountAll) {
|
||||
let c = dom && dom._component,
|
||||
originalComponent = c,
|
||||
oldDom = dom,
|
||||
isDirectOwner = c && dom._componentConstructor===vnode.nodeName,
|
||||
isOwner = isDirectOwner,
|
||||
props = getNodeProps(vnode);
|
||||
while (c && !isOwner && (c=c._parentComponent)) {
|
||||
isOwner = c.constructor===vnode.nodeName;
|
||||
}
|
||||
|
||||
if (c && isOwner && (!mountAll || c._component)) {
|
||||
setComponentProps(c, props, ASYNC_RENDER, context, mountAll);
|
||||
dom = c.base;
|
||||
}
|
||||
else {
|
||||
if (originalComponent && !isDirectOwner) {
|
||||
unmountComponent(originalComponent);
|
||||
dom = oldDom = null;
|
||||
}
|
||||
|
||||
c = createComponent(vnode.nodeName, props, context);
|
||||
if (dom && !c.nextBase) {
|
||||
c.nextBase = dom;
|
||||
// passing dom/oldDom as nextBase will recycle it if unused, so bypass recycling on L229:
|
||||
oldDom = null;
|
||||
}
|
||||
setComponentProps(c, props, SYNC_RENDER, context, mountAll);
|
||||
dom = c.base;
|
||||
|
||||
if (oldDom && dom!==oldDom) {
|
||||
oldDom._component = null;
|
||||
recollectNodeTree(oldDom, false);
|
||||
}
|
||||
}
|
||||
|
||||
return dom;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Remove a component from the DOM and recycle it.
|
||||
* @param {Component} component The Component instance to unmount
|
||||
* @private
|
||||
*/
|
||||
export function unmountComponent(component) {
|
||||
if (options.beforeUnmount) options.beforeUnmount(component);
|
||||
|
||||
let base = component.base;
|
||||
|
||||
component._disable = true;
|
||||
|
||||
if (component.componentWillUnmount) component.componentWillUnmount();
|
||||
|
||||
component.base = null;
|
||||
|
||||
// recursively tear down & recollect high-order component children:
|
||||
let inner = component._component;
|
||||
if (inner) {
|
||||
unmountComponent(inner);
|
||||
}
|
||||
else if (base) {
|
||||
if (base[ATTR_KEY] && base[ATTR_KEY].ref) base[ATTR_KEY].ref(null);
|
||||
|
||||
component.nextBase = base;
|
||||
|
||||
removeNode(base);
|
||||
collectComponent(component);
|
||||
|
||||
removeChildren(base);
|
||||
}
|
||||
|
||||
if (component.__ref) component.__ref(null);
|
||||
}
|
||||
303
static/js/ketcher2/node_modules/preact/src/vdom/diff.js
generated
vendored
Normal file
303
static/js/ketcher2/node_modules/preact/src/vdom/diff.js
generated
vendored
Normal file
@ -0,0 +1,303 @@
|
||||
import { ATTR_KEY } from '../constants';
|
||||
import { isSameNodeType, isNamedNode } from './index';
|
||||
import { buildComponentFromVNode } from './component';
|
||||
import { createNode, setAccessor } from '../dom/index';
|
||||
import { unmountComponent } from './component';
|
||||
import options from '../options';
|
||||
import { removeNode } from '../dom';
|
||||
|
||||
/** Queue of components that have been mounted and are awaiting componentDidMount */
|
||||
export const mounts = [];
|
||||
|
||||
/** Diff recursion count, used to track the end of the diff cycle. */
|
||||
export let diffLevel = 0;
|
||||
|
||||
/** Global flag indicating if the diff is currently within an SVG */
|
||||
let isSvgMode = false;
|
||||
|
||||
/** Global flag indicating if the diff is performing hydration */
|
||||
let hydrating = false;
|
||||
|
||||
/** Invoke queued componentDidMount lifecycle methods */
|
||||
export function flushMounts() {
|
||||
let c;
|
||||
while ((c=mounts.pop())) {
|
||||
if (options.afterMount) options.afterMount(c);
|
||||
if (c.componentDidMount) c.componentDidMount();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Apply differences in a given vnode (and it's deep children) to a real DOM Node.
|
||||
* @param {Element} [dom=null] A DOM node to mutate into the shape of the `vnode`
|
||||
* @param {VNode} vnode A VNode (with descendants forming a tree) representing the desired DOM structure
|
||||
* @returns {Element} dom The created/mutated element
|
||||
* @private
|
||||
*/
|
||||
export function diff(dom, vnode, context, mountAll, parent, componentRoot) {
|
||||
// diffLevel having been 0 here indicates initial entry into the diff (not a subdiff)
|
||||
if (!diffLevel++) {
|
||||
// when first starting the diff, check if we're diffing an SVG or within an SVG
|
||||
isSvgMode = parent!=null && parent.ownerSVGElement!==undefined;
|
||||
|
||||
// hydration is inidicated by the existing element to be diffed not having a prop cache
|
||||
hydrating = dom!=null && !(ATTR_KEY in dom);
|
||||
}
|
||||
|
||||
let ret = idiff(dom, vnode, context, mountAll, componentRoot);
|
||||
|
||||
// append the element if its a new parent
|
||||
if (parent && ret.parentNode!==parent) parent.appendChild(ret);
|
||||
|
||||
// diffLevel being reduced to 0 means we're exiting the diff
|
||||
if (!--diffLevel) {
|
||||
hydrating = false;
|
||||
// invoke queued componentDidMount lifecycle methods
|
||||
if (!componentRoot) flushMounts();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/** Internals of `diff()`, separated to allow bypassing diffLevel / mount flushing. */
|
||||
function idiff(dom, vnode, context, mountAll, componentRoot) {
|
||||
let out = dom,
|
||||
prevSvgMode = isSvgMode;
|
||||
|
||||
// empty values (null & undefined) render as empty Text nodes
|
||||
if (vnode==null) vnode = '';
|
||||
|
||||
|
||||
// Fast case: Strings create/update Text nodes.
|
||||
if (typeof vnode==='string') {
|
||||
|
||||
// update if it's already a Text node:
|
||||
if (dom && dom.splitText!==undefined && dom.parentNode && (!dom._component || componentRoot)) {
|
||||
if (dom.nodeValue!=vnode) {
|
||||
dom.nodeValue = vnode;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// it wasn't a Text node: replace it with one and recycle the old Element
|
||||
out = document.createTextNode(vnode);
|
||||
if (dom) {
|
||||
if (dom.parentNode) dom.parentNode.replaceChild(out, dom);
|
||||
recollectNodeTree(dom, true);
|
||||
}
|
||||
}
|
||||
|
||||
out[ATTR_KEY] = true;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
// If the VNode represents a Component, perform a component diff:
|
||||
if (typeof vnode.nodeName==='function') {
|
||||
return buildComponentFromVNode(dom, vnode, context, mountAll);
|
||||
}
|
||||
|
||||
|
||||
// Tracks entering and exiting SVG namespace when descending through the tree.
|
||||
isSvgMode = vnode.nodeName==='svg' ? true : vnode.nodeName==='foreignObject' ? false : isSvgMode;
|
||||
|
||||
|
||||
// If there's no existing element or it's the wrong type, create a new one:
|
||||
if (!dom || !isNamedNode(dom, String(vnode.nodeName))) {
|
||||
out = createNode(String(vnode.nodeName), isSvgMode);
|
||||
|
||||
if (dom) {
|
||||
// move children into the replacement node
|
||||
while (dom.firstChild) out.appendChild(dom.firstChild);
|
||||
|
||||
// if the previous Element was mounted into the DOM, replace it inline
|
||||
if (dom.parentNode) dom.parentNode.replaceChild(out, dom);
|
||||
|
||||
// recycle the old element (skips non-Element node types)
|
||||
recollectNodeTree(dom, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let fc = out.firstChild,
|
||||
props = out[ATTR_KEY] || (out[ATTR_KEY] = {}),
|
||||
vchildren = vnode.children;
|
||||
|
||||
// Optimization: fast-path for elements containing a single TextNode:
|
||||
if (!hydrating && vchildren && vchildren.length===1 && typeof vchildren[0]==='string' && fc!=null && fc.splitText!==undefined && fc.nextSibling==null) {
|
||||
if (fc.nodeValue!=vchildren[0]) {
|
||||
fc.nodeValue = vchildren[0];
|
||||
}
|
||||
}
|
||||
// otherwise, if there are existing or new children, diff them:
|
||||
else if (vchildren && vchildren.length || fc!=null) {
|
||||
innerDiffNode(out, vchildren, context, mountAll, hydrating || props.dangerouslySetInnerHTML!=null);
|
||||
}
|
||||
|
||||
|
||||
// Apply attributes/props from VNode to the DOM Element:
|
||||
diffAttributes(out, vnode.attributes, props);
|
||||
|
||||
|
||||
// restore previous SVG mode: (in case we're exiting an SVG namespace)
|
||||
isSvgMode = prevSvgMode;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/** Apply child and attribute changes between a VNode and a DOM Node to the DOM.
|
||||
* @param {Element} dom Element whose children should be compared & mutated
|
||||
* @param {Array} vchildren Array of VNodes to compare to `dom.childNodes`
|
||||
* @param {Object} context Implicitly descendant context object (from most recent `getChildContext()`)
|
||||
* @param {Boolean} mountAll
|
||||
* @param {Boolean} isHydrating If `true`, consumes externally created elements similar to hydration
|
||||
*/
|
||||
function innerDiffNode(dom, vchildren, context, mountAll, isHydrating) {
|
||||
let originalChildren = dom.childNodes,
|
||||
children = [],
|
||||
keyed = {},
|
||||
keyedLen = 0,
|
||||
min = 0,
|
||||
len = originalChildren.length,
|
||||
childrenLen = 0,
|
||||
vlen = vchildren ? vchildren.length : 0,
|
||||
j, c, vchild, child;
|
||||
|
||||
// Build up a map of keyed children and an Array of unkeyed children:
|
||||
if (len!==0) {
|
||||
for (let i=0; i<len; i++) {
|
||||
let child = originalChildren[i],
|
||||
props = child[ATTR_KEY],
|
||||
key = vlen && props ? child._component ? child._component.__key : props.key : null;
|
||||
if (key!=null) {
|
||||
keyedLen++;
|
||||
keyed[key] = child;
|
||||
}
|
||||
else if (props || (child.splitText!==undefined ? (isHydrating ? child.nodeValue.trim() : true) : isHydrating)) {
|
||||
children[childrenLen++] = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vlen!==0) {
|
||||
for (let i=0; i<vlen; i++) {
|
||||
vchild = vchildren[i];
|
||||
child = null;
|
||||
|
||||
// attempt to find a node based on key matching
|
||||
let key = vchild.key;
|
||||
if (key!=null) {
|
||||
if (keyedLen && keyed[key]!==undefined) {
|
||||
child = keyed[key];
|
||||
keyed[key] = undefined;
|
||||
keyedLen--;
|
||||
}
|
||||
}
|
||||
// attempt to pluck a node of the same type from the existing children
|
||||
else if (!child && min<childrenLen) {
|
||||
for (j=min; j<childrenLen; j++) {
|
||||
if (children[j]!==undefined && isSameNodeType(c = children[j], vchild, isHydrating)) {
|
||||
child = c;
|
||||
children[j] = undefined;
|
||||
if (j===childrenLen-1) childrenLen--;
|
||||
if (j===min) min++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// morph the matched/found/created DOM child to match vchild (deep)
|
||||
child = idiff(child, vchild, context, mountAll);
|
||||
|
||||
if (child && child!==dom) {
|
||||
if (i>=len) {
|
||||
dom.appendChild(child);
|
||||
}
|
||||
else if (child!==originalChildren[i]) {
|
||||
if (child===originalChildren[i+1]) {
|
||||
removeNode(originalChildren[i]);
|
||||
}
|
||||
else {
|
||||
dom.insertBefore(child, originalChildren[i] || null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// remove unused keyed children:
|
||||
if (keyedLen) {
|
||||
for (let i in keyed) if (keyed[i]!==undefined) recollectNodeTree(keyed[i], false);
|
||||
}
|
||||
|
||||
// remove orphaned unkeyed children:
|
||||
while (min<=childrenLen) {
|
||||
if ((child = children[childrenLen--])!==undefined) recollectNodeTree(child, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Recursively recycle (or just unmount) a node an its descendants.
|
||||
* @param {Node} node DOM node to start unmount/removal from
|
||||
* @param {Boolean} [unmountOnly=false] If `true`, only triggers unmount lifecycle, skips removal
|
||||
*/
|
||||
export function recollectNodeTree(node, unmountOnly) {
|
||||
let component = node._component;
|
||||
if (component) {
|
||||
// if node is owned by a Component, unmount that component (ends up recursing back here)
|
||||
unmountComponent(component);
|
||||
}
|
||||
else {
|
||||
// If the node's VNode had a ref function, invoke it with null here.
|
||||
// (this is part of the React spec, and smart for unsetting references)
|
||||
if (node[ATTR_KEY]!=null && node[ATTR_KEY].ref) node[ATTR_KEY].ref(null);
|
||||
|
||||
if (unmountOnly===false || node[ATTR_KEY]==null) {
|
||||
removeNode(node);
|
||||
}
|
||||
|
||||
removeChildren(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Recollect/unmount all children.
|
||||
* - we use .lastChild here because it causes less reflow than .firstChild
|
||||
* - it's also cheaper than accessing the .childNodes Live NodeList
|
||||
*/
|
||||
export function removeChildren(node) {
|
||||
node = node.lastChild;
|
||||
while (node) {
|
||||
let next = node.previousSibling;
|
||||
recollectNodeTree(node, true);
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Apply differences in attributes from a VNode to the given DOM Element.
|
||||
* @param {Element} dom Element with attributes to diff `attrs` against
|
||||
* @param {Object} attrs The desired end-state key-value attribute pairs
|
||||
* @param {Object} old Current/previous attributes (from previous VNode or element's prop cache)
|
||||
*/
|
||||
function diffAttributes(dom, attrs, old) {
|
||||
let name;
|
||||
|
||||
// remove attributes no longer present on the vnode by setting them to undefined
|
||||
for (name in old) {
|
||||
if (!(attrs && attrs[name]!=null) && old[name]!=null) {
|
||||
setAccessor(dom, name, old[name], old[name] = undefined, isSvgMode);
|
||||
}
|
||||
}
|
||||
|
||||
// add new & update changed attributes
|
||||
for (name in attrs) {
|
||||
if (name!=='children' && name!=='innerHTML' && (!(name in old) || attrs[name]!==(name==='value' || name==='checked' ? dom[name] : old[name]))) {
|
||||
setAccessor(dom, name, old[name], old[name] = attrs[name], isSvgMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
50
static/js/ketcher2/node_modules/preact/src/vdom/index.js
generated
vendored
Normal file
50
static/js/ketcher2/node_modules/preact/src/vdom/index.js
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
import { extend } from '../util';
|
||||
|
||||
|
||||
/** Check if two nodes are equivalent.
|
||||
* @param {Element} node
|
||||
* @param {VNode} vnode
|
||||
* @private
|
||||
*/
|
||||
export function isSameNodeType(node, vnode, hydrating) {
|
||||
if (typeof vnode==='string' || typeof vnode==='number') {
|
||||
return node.splitText!==undefined;
|
||||
}
|
||||
if (typeof vnode.nodeName==='string') {
|
||||
return !node._componentConstructor && isNamedNode(node, vnode.nodeName);
|
||||
}
|
||||
return hydrating || node._componentConstructor===vnode.nodeName;
|
||||
}
|
||||
|
||||
|
||||
/** Check if an Element has a given normalized name.
|
||||
* @param {Element} node
|
||||
* @param {String} nodeName
|
||||
*/
|
||||
export function isNamedNode(node, nodeName) {
|
||||
return node.normalizedNodeName===nodeName || node.nodeName.toLowerCase()===nodeName.toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reconstruct Component-style `props` from a VNode.
|
||||
* Ensures default/fallback values from `defaultProps`:
|
||||
* Own-properties of `defaultProps` not present in `vnode.attributes` are added.
|
||||
* @param {VNode} vnode
|
||||
* @returns {Object} props
|
||||
*/
|
||||
export function getNodeProps(vnode) {
|
||||
let props = extend({}, vnode.attributes);
|
||||
props.children = vnode.children;
|
||||
|
||||
let defaultProps = vnode.nodeName.defaultProps;
|
||||
if (defaultProps!==undefined) {
|
||||
for (let i in defaultProps) {
|
||||
if (props[i]===undefined) {
|
||||
props[i] = defaultProps[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return props;
|
||||
}
|
||||
Reference in New Issue
Block a user