From b2128609ac8159a14224deba399144b3400c8c20 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 13 Nov 2016 08:16:12 +0100 Subject: Finally give in and use React, minor tweeks. Preact (a minimalistic React alternative) had too many bugs ... --- thirdparty/preact/src/clone-element.js | 10 - thirdparty/preact/src/component.js | 102 ---- thirdparty/preact/src/constants.js | 20 - thirdparty/preact/src/dom/index.js | 99 ---- thirdparty/preact/src/dom/recycler.js | 25 - thirdparty/preact/src/h.js | 50 -- thirdparty/preact/src/linked-state.js | 24 - thirdparty/preact/src/options.js | 27 - thirdparty/preact/src/preact.d.ts | 565 --------------------- thirdparty/preact/src/preact.js | 24 - thirdparty/preact/src/preact.js.flow | 9 - thirdparty/preact/src/render-queue.js | 23 - thirdparty/preact/src/render.js | 20 - thirdparty/preact/src/util.js | 68 --- thirdparty/preact/src/vdom/component-recycler.js | 32 -- thirdparty/preact/src/vdom/component.js | 281 ---------- thirdparty/preact/src/vdom/diff.js | 254 --------- thirdparty/preact/src/vdom/functional-component.js | 25 - thirdparty/preact/src/vdom/index.js | 49 -- thirdparty/preact/src/vnode.js | 14 - 20 files changed, 1721 deletions(-) delete mode 100644 thirdparty/preact/src/clone-element.js delete mode 100644 thirdparty/preact/src/component.js delete mode 100644 thirdparty/preact/src/constants.js delete mode 100644 thirdparty/preact/src/dom/index.js delete mode 100644 thirdparty/preact/src/dom/recycler.js delete mode 100644 thirdparty/preact/src/h.js delete mode 100644 thirdparty/preact/src/linked-state.js delete mode 100644 thirdparty/preact/src/options.js delete mode 100644 thirdparty/preact/src/preact.d.ts delete mode 100644 thirdparty/preact/src/preact.js delete mode 100644 thirdparty/preact/src/preact.js.flow delete mode 100644 thirdparty/preact/src/render-queue.js delete mode 100644 thirdparty/preact/src/render.js delete mode 100644 thirdparty/preact/src/util.js delete mode 100644 thirdparty/preact/src/vdom/component-recycler.js delete mode 100644 thirdparty/preact/src/vdom/component.js delete mode 100644 thirdparty/preact/src/vdom/diff.js delete mode 100644 thirdparty/preact/src/vdom/functional-component.js delete mode 100644 thirdparty/preact/src/vdom/index.js delete mode 100644 thirdparty/preact/src/vnode.js (limited to 'thirdparty/preact/src') diff --git a/thirdparty/preact/src/clone-element.js b/thirdparty/preact/src/clone-element.js deleted file mode 100644 index fc7103056..000000000 --- a/thirdparty/preact/src/clone-element.js +++ /dev/null @@ -1,10 +0,0 @@ -import { clone, extend } from './util'; -import { h } from './h'; - -export function cloneElement(vnode, props) { - return h( - vnode.nodeName, - extend(clone(vnode.attributes), props), - arguments.length>2 ? [].slice.call(arguments, 2) : vnode.children - ); -} diff --git a/thirdparty/preact/src/component.js b/thirdparty/preact/src/component.js deleted file mode 100644 index aefaebe98..000000000 --- a/thirdparty/preact/src/component.js +++ /dev/null @@ -1,102 +0,0 @@ -import { FORCE_RENDER } from './constants'; -import { extend, clone, isFunction } from './util'; -import { createLinkedState } from './linked-state'; -import { renderComponent } from './vdom/component'; -import { enqueueRender } from './render-queue'; - -/** Base Component class, for he ES6 Class method of creating Components - * @public - * - * @example - * class MyFoo extends Component { - * render(props, state) { - * return
; - * } - * } - */ -export function Component(props, context) { - /** @private */ - this._dirty = true; - // /** @public */ - // this._disableRendering = false; - // /** @public */ - // this.prevState = this.prevProps = this.prevContext = this.base = this.nextBase = this._parentComponent = this._component = this.__ref = this.__key = this._linkedStates = this._renderCallbacks = null; - /** @public */ - this.context = context; - /** @type {object} */ - this.props = props; - /** @type {object} */ - if (!this.state) this.state = {}; -} - - -extend(Component.prototype, { - - /** Returns a `boolean` value indicating if the component should re-render when receiving the given `props` and `state`. - * @param {object} nextProps - * @param {object} nextState - * @param {object} nextContext - * @returns {Boolean} should the component re-render - * @name shouldComponentUpdate - * @function - */ - // shouldComponentUpdate() { - // return true; - // }, - - - /** Returns a function that sets a state property when called. - * Calling linkState() repeatedly with the same arguments returns a cached link function. - * - * Provides some built-in special cases: - * - Checkboxes and radio buttons link their boolean `checked` value - * - Inputs automatically link their `value` property - * - Event paths fall back to any associated Component if not found on an element - * - If linked value is a function, will invoke it and use the result - * - * @param {string} key The path to set - can be a dot-notated deep key - * @param {string} [eventPath] If set, attempts to find the new state value at a given dot-notated path within the object passed to the linkedState setter. - * @returns {function} linkStateSetter(e) - * - * @example Update a "text" state value when an input changes: - * - * - * @example Set a deep state value on click - * foo, document.body); - */ -export function h(nodeName, attributes) { - let children = [], - lastSimple, child, simple, i; - for (i=arguments.length; i-- > 2; ) { - stack.push(arguments[i]); - } - if (attributes && attributes.children) { - if (!stack.length) stack.push(attributes.children); - delete attributes.children; - } - while (stack.length) { - if ((child = stack.pop()) instanceof Array) { - for (i=child.length; i--; ) stack.push(child[i]); - } - else if (child!=null && child!==false) { - if (typeof child=='number' || child===true) child = String(child); - simple = typeof child=='string'; - if (simple && lastSimple) { - children[children.length-1] += child; - } - else { - children.push(child); - lastSimple = simple; - } - } - } - - let p = new VNode(nodeName, attributes || undefined, children); - - // if a "vnode hook" is defined, pass every created VNode to it - if (options.vnode) options.vnode(p); - - return p; -} diff --git a/thirdparty/preact/src/linked-state.js b/thirdparty/preact/src/linked-state.js deleted file mode 100644 index b6959df73..000000000 --- a/thirdparty/preact/src/linked-state.js +++ /dev/null @@ -1,24 +0,0 @@ -import { isString, delve } from './util'; - -/** Create an Event handler function that sets a given state property. - * @param {Component} component The component whose state should be updated - * @param {string} key A dot-notated key path to update in the component's state - * @param {string} eventPath A dot-notated key path to the value that should be retrieved from the Event or component - * @returns {function} linkedStateHandler - * @private - */ -export function createLinkedState(component, key, eventPath) { - let path = key.split('.'); - return function(e) { - let t = e && e.target || this, - state = {}, - obj = state, - v = isString(eventPath) ? delve(e, eventPath) : t.nodeName ? (t.type.match(/^che|rad/) ? t.checked : t.value) : e, - i = 0; - for ( ; i void; - } - - interface VNode { - nodeName:ComponentConstructor|string; - attributes:{[name:string]:any}; - children:VNode[]; - key:string; - } - - interface ComponentLifecycle { - componentWillMount?():void; - - componentDidMount?():void; - - componentWillUnmount?():void; - - componentDidUnmount?():void; - - componentWillReceiveProps?(props:PropsType):void; - - shouldComponentUpdate?(props:PropsType):boolean; - - componentWillUpdate?():void; - - componentDidUpdate?():void; - } - - interface ComponentConstructor { - new (props?:PropsType):Component; - } - - abstract class Component implements ComponentLifecycle { - constructor(props?:PropsType); - - state:StateType; - props:PropsType & ComponentProps; - base:HTMLElement; - - linkState:(name:string) => void; - - setState(state:StateType, opts?:any):void; - - abstract render(props:PropsType & ComponentProps, state:any):JSX.Element; - } - - function h(node:ComponentConstructor, params:PropsType, ...children:(JSX.Element|JSX.Element[]|string)[]):JSX.Element; - function h(node:string, params:JSX.HTMLAttributes&JSX.SVGAttributes&{[propName: string]: any}, ...children:(JSX.Element|JSX.Element[]|string)[]):JSX.Element; - - function render(node:JSX.Element, parent:Element, merge?:boolean):Element; - - function rerender():void; - - function cloneElement(element:JSX.Element, props:any):JSX.Element; - - var options:{ - syncComponentUpdates?:boolean; - debounceRendering?:(render:() => void) => void; - vnode?:(vnode:VNode) => void; - event?:(event:Event) => Event; - }; -} - -declare module "preact" { - export = preact; -} - -declare module "preact/devtools" { - // Empty. This module initializes the React Developer Tools integration - // when imported. -} - -declare namespace JSX { - interface Element extends preact.VNode { - - } - - interface ElementClass extends preact.Component { - - } - - interface ElementAttributesProperty { - props:any; - } - - interface SVGAttributes { - clipPath?:string; - cx?:number | string; - cy?:number | string; - d?:string; - dx?:number | string; - dy?:number | string; - fill?:string; - fillOpacity?:number | string; - fontFamily?:string; - fontSize?:number | string; - fx?:number | string; - fy?:number | string; - gradientTransform?:string; - gradientUnits?:string; - markerEnd?:string; - markerMid?:string; - markerStart?:string; - offset?:number | string; - opacity?:number | string; - patternContentUnits?:string; - patternUnits?:string; - points?:string; - preserveAspectRatio?:string; - r?:number | string; - rx?:number | string; - ry?:number | string; - spreadMethod?:string; - stopColor?:string; - stopOpacity?:number | string; - stroke?:string; - strokeDasharray?:string; - strokeLinecap?:string; - strokeMiterlimit?:string; - strokeOpacity?:number | string; - strokeWidth?:number | string; - textAnchor?:string; - transform?:string; - version?:string; - viewBox?:string; - x1?:number | string; - x2?:number | string; - x?:number | string; - xlinkActuate?:string; - xlinkArcrole?:string; - xlinkHref?:string; - xlinkRole?:string; - xlinkShow?:string; - xlinkTitle?:string; - xlinkType?:string; - xmlBase?:string; - xmlLang?:string; - xmlSpace?:string; - y1?:number | string; - y2?:number | string; - y?:number | string; - } - - interface PathAttributes { - d:string; - } - - interface EventHandler { - (event:E):void; - } - - type ClipboardEventHandler = EventHandler; - type CompositionEventHandler = EventHandler; - type DragEventHandler = EventHandler; - type FocusEventHandler = EventHandler; - type KeyboardEventHandler = EventHandler; - type MouseEventHandler = EventHandler; - type TouchEventHandler = EventHandler; - type UIEventHandler = EventHandler; - type WheelEventHandler = EventHandler; - type AnimationEventHandler = EventHandler; - type TransitionEventHandler = EventHandler; - - type GenericEventHandler = EventHandler; - - interface DOMAttributed { - // Clipboard Events - onCopy?:ClipboardEventHandler; - onCut?:ClipboardEventHandler; - onPaste?:ClipboardEventHandler; - - // Composition Events - onCompositionEnd?:CompositionEventHandler; - onCompositionStart?:CompositionEventHandler; - onCompositionUpdate?:CompositionEventHandler; - - // Focus Events - onFocus?:FocusEventHandler; - onBlur?:FocusEventHandler; - - // Form Events - onChange?:GenericEventHandler; - onInput?:GenericEventHandler; - onSubmit?:GenericEventHandler; - - // Keyboard Events - onKeyDown?:KeyboardEventHandler; - onKeyPress?:KeyboardEventHandler; - onKeyUp?:KeyboardEventHandler; - - // Media Events - onAbort?:GenericEventHandler; - onCanPlay?:GenericEventHandler; - onCanPlayThrough?:GenericEventHandler; - onDurationChange?:GenericEventHandler; - onEmptied?:GenericEventHandler; - onEncrypted?:GenericEventHandler; - onEnded?:GenericEventHandler; - onLoadedData?:GenericEventHandler; - onLoadedMetadata?:GenericEventHandler; - onLoadStart?:GenericEventHandler; - onPause?:GenericEventHandler; - onPlay?:GenericEventHandler; - onPlaying?:GenericEventHandler; - onProgress?:GenericEventHandler; - onRateChange?:GenericEventHandler; - onSeeked?:GenericEventHandler; - onSeeking?:GenericEventHandler; - onStalled?:GenericEventHandler; - onSuspend?:GenericEventHandler; - onTimeUpdate?:GenericEventHandler; - onVolumeChange?:GenericEventHandler; - onWaiting?:GenericEventHandler; - - // MouseEvents - onClick?:MouseEventHandler; - onContextMenu?:MouseEventHandler; - onDoubleClick?:MouseEventHandler; - onDrag?:DragEventHandler; - onDragEnd?:DragEventHandler; - onDragEnter?:DragEventHandler; - onDragExit?:DragEventHandler; - onDragLeave?:DragEventHandler; - onDragOver?:DragEventHandler; - onDragStart?:DragEventHandler; - onDrop?:DragEventHandler; - onMouseDown?:MouseEventHandler; - onMouseEnter?:MouseEventHandler; - onMouseLeave?:MouseEventHandler; - onMouseMove?:MouseEventHandler; - onMouseOut?:MouseEventHandler; - onMouseOver?:MouseEventHandler; - onMouseUp?:MouseEventHandler; - - // Selection Events - onSelect?:GenericEventHandler; - - // Touch Events - onTouchCancel?:TouchEventHandler; - onTouchEnd?:TouchEventHandler; - onTouchMove?:TouchEventHandler; - onTouchStart?:TouchEventHandler; - - // UI Events - onScroll?:UIEventHandler; - - // Wheel Events - onWheel?:WheelEventHandler; - - // Animation Events - onAnimationStart?:AnimationEventHandler; - onAnimationEnd?:AnimationEventHandler; - onAnimationIteration?:AnimationEventHandler; - - // Transition Events - onTransitionEnd?:TransitionEventHandler; - } - - interface HTMLAttributes extends preact.PreactHTMLAttributes, DOMAttributed { - // Standard HTML Attributes - accept?:string; - acceptCharset?:string; - accessKey?:string; - action?:string; - allowFullScreen?:boolean; - allowTransparency?:boolean; - alt?:string; - async?:boolean; - autocomplete?:string; - autofocus?:boolean; - autoPlay?:boolean; - capture?:boolean; - cellPadding?:number | string; - cellSpacing?:number | string; - charSet?:string; - challenge?:string; - checked?:boolean; - class?:string | { [key:string]: boolean }; - className?:string | { [key:string]: boolean }; - cols?:number; - colSpan?:number; - content?:string; - contentEditable?:boolean; - contextMenu?:string; - controls?:boolean; - coords?:string; - crossOrigin?:string; - data?:string; - dateTime?:string; - default?:boolean; - defer?:boolean; - dir?:string; - disabled?:boolean; - download?:any; - draggable?:boolean; - encType?:string; - form?:string; - formAction?:string; - formEncType?:string; - formMethod?:string; - formNoValidate?:boolean; - formTarget?:string; - frameBorder?:number | string; - headers?:string; - height?:number | string; - hidden?:boolean; - high?:number; - href?:string; - hrefLang?:string; - for?:string; - httpEquiv?:string; - icon?:string; - id?:string; - inputMode?:string; - integrity?:string; - is?:string; - keyParams?:string; - keyType?:string; - kind?:string; - label?:string; - lang?:string; - list?:string; - loop?:boolean; - low?:number; - manifest?:string; - marginHeight?:number; - marginWidth?:number; - max?:number | string; - maxLength?:number; - media?:string; - mediaGroup?:string; - method?:string; - min?:number | string; - minLength?:number; - multiple?:boolean; - muted?:boolean; - name?:string; - noValidate?:boolean; - open?:boolean; - optimum?:number; - pattern?:string; - placeholder?:string; - poster?:string; - preload?:string; - radioGroup?:string; - readOnly?:boolean; - rel?:string; - required?:boolean; - role?:string; - rows?:number; - rowSpan?:number; - sandbox?:string; - scope?:string; - scoped?:boolean; - scrolling?:string; - seamless?:boolean; - selected?:boolean; - shape?:string; - size?:number; - sizes?:string; - span?:number; - spellCheck?:boolean; - src?:string; - srcset?:string; - srcDoc?:string; - srcLang?:string; - srcSet?:string; - start?:number; - step?:number | string; - style?:any; - summary?:string; - tabIndex?:number; - target?:string; - title?:string; - type?:string; - useMap?:string; - value?:string | string[]; - width?:number | string; - wmode?:string; - wrap?:string; - - // RDFa Attributes - about?:string; - datatype?:string; - inlist?:any; - prefix?:string; - property?:string; - resource?:string; - typeof?:string; - vocab?:string; - } - - interface IntrinsicElements { - // HTML - a:HTMLAttributes; - abbr:HTMLAttributes; - address:HTMLAttributes; - area:HTMLAttributes; - article:HTMLAttributes; - aside:HTMLAttributes; - audio:HTMLAttributes; - b:HTMLAttributes; - base:HTMLAttributes; - bdi:HTMLAttributes; - bdo:HTMLAttributes; - big:HTMLAttributes; - blockquote:HTMLAttributes; - body:HTMLAttributes; - br:HTMLAttributes; - button:HTMLAttributes; - canvas:HTMLAttributes; - caption:HTMLAttributes; - cite:HTMLAttributes; - code:HTMLAttributes; - col:HTMLAttributes; - colgroup:HTMLAttributes; - data:HTMLAttributes; - datalist:HTMLAttributes; - dd:HTMLAttributes; - del:HTMLAttributes; - details:HTMLAttributes; - dfn:HTMLAttributes; - dialog:HTMLAttributes; - div:HTMLAttributes; - dl:HTMLAttributes; - dt:HTMLAttributes; - em:HTMLAttributes; - embed:HTMLAttributes; - fieldset:HTMLAttributes; - figcaption:HTMLAttributes; - figure:HTMLAttributes; - footer:HTMLAttributes; - form:HTMLAttributes; - h1:HTMLAttributes; - h2:HTMLAttributes; - h3:HTMLAttributes; - h4:HTMLAttributes; - h5:HTMLAttributes; - h6:HTMLAttributes; - head:HTMLAttributes; - header:HTMLAttributes; - hr:HTMLAttributes; - html:HTMLAttributes; - i:HTMLAttributes; - iframe:HTMLAttributes; - img:HTMLAttributes; - input:HTMLAttributes; - ins:HTMLAttributes; - kbd:HTMLAttributes; - keygen:HTMLAttributes; - label:HTMLAttributes; - legend:HTMLAttributes; - li:HTMLAttributes; - link:HTMLAttributes; - main:HTMLAttributes; - map:HTMLAttributes; - mark:HTMLAttributes; - menu:HTMLAttributes; - menuitem:HTMLAttributes; - meta:HTMLAttributes; - meter:HTMLAttributes; - nav:HTMLAttributes; - noscript:HTMLAttributes; - object:HTMLAttributes; - ol:HTMLAttributes; - optgroup:HTMLAttributes; - option:HTMLAttributes; - output:HTMLAttributes; - p:HTMLAttributes; - param:HTMLAttributes; - picture:HTMLAttributes; - pre:HTMLAttributes; - progress:HTMLAttributes; - q:HTMLAttributes; - rp:HTMLAttributes; - rt:HTMLAttributes; - ruby:HTMLAttributes; - s:HTMLAttributes; - samp:HTMLAttributes; - script:HTMLAttributes; - section:HTMLAttributes; - select:HTMLAttributes; - small:HTMLAttributes; - source:HTMLAttributes; - span:HTMLAttributes; - strong:HTMLAttributes; - style:HTMLAttributes; - sub:HTMLAttributes; - summary:HTMLAttributes; - sup:HTMLAttributes; - table:HTMLAttributes; - tbody:HTMLAttributes; - td:HTMLAttributes; - textarea:HTMLAttributes; - tfoot:HTMLAttributes; - th:HTMLAttributes; - thead:HTMLAttributes; - time:HTMLAttributes; - title:HTMLAttributes; - tr:HTMLAttributes; - track:HTMLAttributes; - u:HTMLAttributes; - ul:HTMLAttributes; - "var":HTMLAttributes; - video:HTMLAttributes; - wbr:HTMLAttributes; - - //SVG - svg:SVGAttributes; - - circle:SVGAttributes; - clipPath:SVGAttributes; - defs:SVGAttributes; - ellipse:SVGAttributes; - feBlend:SVGAttributes; - feColorMatrix:SVGAttributes; - feComponentTransfer:SVGAttributes; - feComposite:SVGAttributes; - feConvolveMatrix:SVGAttributes; - feDiffuseLighting:SVGAttributes; - feDisplacementMap:SVGAttributes; - feFlood:SVGAttributes; - feGaussianBlur:SVGAttributes; - feImage:SVGAttributes; - feMerge:SVGAttributes; - feMergeNode:SVGAttributes; - feMorphology:SVGAttributes; - feOffset:SVGAttributes; - feSpecularLighting:SVGAttributes; - feTile:SVGAttributes; - feTurbulence:SVGAttributes; - filter:SVGAttributes; - foreignObject:SVGAttributes; - g:SVGAttributes; - image:SVGAttributes; - line:SVGAttributes; - linearGradient:SVGAttributes; - marker:SVGAttributes; - mask:SVGAttributes; - path:SVGAttributes; - pattern:SVGAttributes; - polygon:SVGAttributes; - polyline:SVGAttributes; - radialGradient:SVGAttributes; - rect:SVGAttributes; - stop:SVGAttributes; - symbol:SVGAttributes; - text:SVGAttributes; - tspan:SVGAttributes; - use:SVGAttributes; - } -} \ No newline at end of file diff --git a/thirdparty/preact/src/preact.js b/thirdparty/preact/src/preact.js deleted file mode 100644 index 1fa169c04..000000000 --- a/thirdparty/preact/src/preact.js +++ /dev/null @@ -1,24 +0,0 @@ -import { h } from './h'; -import { cloneElement } from './clone-element'; -import { Component } from './component'; -import { render } from './render'; -import { rerender } from './render-queue'; -import options from './options'; - -export default { - h, - cloneElement, - Component, - render, - rerender, - options -}; - -export { - h, - cloneElement, - Component, - render, - rerender, - options -}; diff --git a/thirdparty/preact/src/preact.js.flow b/thirdparty/preact/src/preact.js.flow deleted file mode 100644 index 37745faf6..000000000 --- a/thirdparty/preact/src/preact.js.flow +++ /dev/null @@ -1,9 +0,0 @@ -/* @flow */ - -import { createElement as h, cloneElement, Component, render } from 'react'; - -export { h, cloneElement, Component, render }; -export default { h, cloneElement, Component, render }; - -declare export function rerender(): void; -declare export var options: Object; diff --git a/thirdparty/preact/src/render-queue.js b/thirdparty/preact/src/render-queue.js deleted file mode 100644 index ff603611b..000000000 --- a/thirdparty/preact/src/render-queue.js +++ /dev/null @@ -1,23 +0,0 @@ -import options from './options'; -import { defer } from './util'; -import { renderComponent } from './vdom/component'; - -/** Managed queue of dirty components to be re-rendered */ - -// items/itemsOffline swap on each rerender() call (just a simple pool technique) -let items = []; - -export function enqueueRender(component) { - if (!component._dirty && (component._dirty = true) && items.push(component)==1) { - (options.debounceRendering || defer)(rerender); - } -} - - -export function rerender() { - let p, list = items; - items = []; - while ( (p = list.pop()) ) { - if (p._dirty) renderComponent(p); - } -} diff --git a/thirdparty/preact/src/render.js b/thirdparty/preact/src/render.js deleted file mode 100644 index e0e8526ec..000000000 --- a/thirdparty/preact/src/render.js +++ /dev/null @@ -1,20 +0,0 @@ -import { diff } from './vdom/diff'; - -/** Render JSX into a `parent` Element. - * @param {VNode} vnode A (JSX) VNode to render - * @param {Element} parent DOM element to render into - * @param {Element} [merge] Attempt to re-use an existing DOM tree rooted at `merge` - * @public - * - * @example - * // render a div into : - * render(
hello!
, document.body); - * - * @example - * // render a "Thing" component into #foo: - * const Thing = ({ name }) => { name }; - * render(, document.querySelector('#foo')); - */ -export function render(vnode, parent, merge) { - return diff(merge, vnode, {}, false, parent); -} diff --git a/thirdparty/preact/src/util.js b/thirdparty/preact/src/util.js deleted file mode 100644 index d2e63b090..000000000 --- a/thirdparty/preact/src/util.js +++ /dev/null @@ -1,68 +0,0 @@ -/** Copy own-properties from `props` onto `obj`. - * @returns obj - * @private - */ -export function extend(obj, props) { - if (props) { - for (let i in props) obj[i] = props[i]; - } - return obj; -} - - -/** Fast clone. Note: does not filter out non-own properties. - * @see https://esbench.com/bench/56baa34f45df6895002e03b6 - */ -export function clone(obj) { - return extend({}, obj); -} - - -/** Get a deep property value from the given object, expressed in dot-notation. - * @private - */ -export function delve(obj, key) { - for (let p=key.split('.'), i=0; i lcCache[s] || (lcCache[s] = s.toLowerCase()); - - -/** Call a function asynchronously, as soon as possible. - * @param {Function} callback - */ -let resolved = typeof Promise!=='undefined' && Promise.resolve(); -export const defer = resolved ? (f => { resolved.then(f); }) : setTimeout; diff --git a/thirdparty/preact/src/vdom/component-recycler.js b/thirdparty/preact/src/vdom/component-recycler.js deleted file mode 100644 index a70f0ece0..000000000 --- a/thirdparty/preact/src/vdom/component-recycler.js +++ /dev/null @@ -1,32 +0,0 @@ -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 = {}; - - -export function collectComponent(component) { - let name = component.constructor.name, - list = components[name]; - if (list) list.push(component); - else components[name] = [component]; -} - - -export function createComponent(Ctor, props, context) { - let inst = new Ctor(props, context), - list = components[Ctor.name]; - Component.call(inst, props, context); - 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; -} diff --git a/thirdparty/preact/src/vdom/component.js b/thirdparty/preact/src/vdom/component.js deleted file mode 100644 index 64e7ff81f..000000000 --- a/thirdparty/preact/src/vdom/component.js +++ /dev/null @@ -1,281 +0,0 @@ -import { SYNC_RENDER, NO_RENDER, FORCE_RENDER, ASYNC_RENDER, ATTR_KEY } from '../constants'; -import options from '../options'; -import { isFunction, clone, extend } from '../util'; -import { enqueueRender } from '../render-queue'; -import { getNodeProps } from './index'; -import { diff, mounts, diffLevel, flushMounts, removeOrphanedChildren, recollectNodeTree } from './diff'; -import { isFunctionalComponent, buildFunctionalComponent } from './functional-component'; -import { createComponent, collectComponent } from './component-recycler'; -import { removeNode } from '../dom/index'; - - - -/** 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 skip, rendered, - 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, - 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) { - if (component.render) rendered = component.render(props, state, context); - - // context to pass to the child, can be updated via (grand-)parent component - if (component.getChildContext) { - context = extend(clone(context), component.getChildContext()); - } - - while (isFunctionalComponent(rendered)) { - rendered = buildFunctionalComponent(rendered, context); - } - - let childComponent = rendered && rendered.nodeName, - toUnmount, base; - - if (isFunction(childComponent)) { - // set up high order component link - - - inst = initialChildComponent; - let childProps = getNodeProps(rendered); - - if (inst && inst.constructor===childComponent) { - setComponentProps(inst, childProps, SYNC_RENDER, context); - } - else { - toUnmount = inst; - - inst = createComponent(childComponent, childProps, context); - inst.nextBase = inst.nextBase || nextBase; - inst._parentComponent = component; - component._component = inst; - setComponentProps(inst, childProps, NO_RENDER, context); - 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); - } - } - } - - if (toUnmount) { - unmountComponent(toUnmount, base!==initialBase); - } - - 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) { - if (component.componentDidUpdate) { - component.componentDidUpdate(previousProps, previousState, previousContext); - } - if (options.afterUpdate) options.afterUpdate(component); - } - - let cb = component._renderCallbacks, fn; - if (cb) while ( (fn = cb.pop()) ) fn.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, - 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 (c && !isDirectOwner) { - unmountComponent(c, true); - 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 L241: - oldDom = null; - } - setComponentProps(c, props, SYNC_RENDER, context, mountAll); - dom = c.base; - - if (oldDom && dom!==oldDom) { - oldDom._component = null; - recollectNodeTree(oldDom); - } - } - - return dom; -} - - - -/** Remove a component from the DOM and recycle it. - * @param {Element} dom A DOM node from which to unmount the given Component - * @param {Component} component The Component instance to unmount - * @private - */ -export function unmountComponent(component, remove) { - if (options.beforeUnmount) options.beforeUnmount(component); - - // console.log(`${remove?'Removing':'Unmounting'} component: ${component.constructor.name}`); - 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, remove); - } - else if (base) { - if (base[ATTR_KEY] && base[ATTR_KEY].ref) base[ATTR_KEY].ref(null); - - component.nextBase = base; - - if (remove) { - removeNode(base); - collectComponent(component); - } - removeOrphanedChildren(base.childNodes, !remove); - } - - if (component.__ref) component.__ref(null); - if (component.componentDidUnmount) component.componentDidUnmount(); -} diff --git a/thirdparty/preact/src/vdom/diff.js b/thirdparty/preact/src/vdom/diff.js deleted file mode 100644 index 794a79aaa..000000000 --- a/thirdparty/preact/src/vdom/diff.js +++ /dev/null @@ -1,254 +0,0 @@ -import { ATTR_KEY } from '../constants'; -import { isString, isFunction } from '../util'; -import { isSameNodeType, isNamedNode } from './index'; -import { isFunctionalComponent, buildFunctionalComponent } from './functional-component'; -import { buildComponentFromVNode } from './component'; -import { setAccessor } from '../dom/index'; -import { createNode, collectNode } from '../dom/recycler'; -import { unmountComponent } from './component'; -import options from '../options'; - - -/** Diff recursion count, used to track the end of the diff cycle. */ -export const mounts = []; - -/** Diff recursion count, used to track the end of the diff cycle. */ -export let diffLevel = 0; - -let isSvgMode = false; - - -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) { - if (!diffLevel++) isSvgMode = parent instanceof SVGElement; - let ret = idiff(dom, vnode, context, mountAll); - if (parent && ret.parentNode!==parent) parent.appendChild(ret); - if (!--diffLevel && !componentRoot) flushMounts(); - return ret; -} - - -function idiff(dom, vnode, context, mountAll) { - let originalAttributes = vnode && vnode.attributes; - - while (isFunctionalComponent(vnode)) { - vnode = buildFunctionalComponent(vnode, context); - } - - if (vnode==null) vnode = ''; - - if (isString(vnode)) { - if (dom) { - if (dom instanceof Text && dom.parentNode) { - if (dom.nodeValue!=vnode) { - dom.nodeValue = vnode; - } - return dom; - } - recollectNodeTree(dom); - } - return document.createTextNode(vnode); - } - - if (isFunction(vnode.nodeName)) { - return buildComponentFromVNode(dom, vnode, context, mountAll); - } - - let out = dom, - nodeName = vnode.nodeName, - prevSvgMode = isSvgMode, - vchildren = vnode.children; - - if (!isString(nodeName)) { - nodeName = String(nodeName); - } - - isSvgMode = nodeName==='svg' ? true : nodeName==='foreignObject' ? false : isSvgMode; - - if (!dom) { - out = createNode(nodeName, isSvgMode); - } - else if (!isNamedNode(dom, nodeName)) { - out = createNode(nodeName, isSvgMode); - // move children into the replacement node - while (dom.firstChild) out.appendChild(dom.firstChild); - // reclaim element nodes - recollectNodeTree(dom); - } - - // fast-path for elements containing a single TextNode: - if (vchildren && vchildren.length===1 && typeof vchildren[0]==='string' && out.childNodes.length===1 && out.firstChild instanceof Text) { - if (out.firstChild.nodeValue!=vchildren[0]) { - out.firstChild.nodeValue = vchildren[0]; - } - } - else if (vchildren && vchildren.length || out.firstChild) { - innerDiffNode(out, vchildren, context, mountAll); - } - - let props = out[ATTR_KEY]; - if (!props) { - out[ATTR_KEY] = props = {}; - for (let a=out.attributes, i=a.length; i--; ) props[a[i].name] = a[i].value; - } - - diffAttributes(out, vnode.attributes, props); - - if (originalAttributes && typeof originalAttributes.ref==='function') { - (props.ref = originalAttributes.ref)(out); - } - - isSvgMode = prevSvgMode; - - return out; -} - - -/** Apply child and attribute changes between a VNode and a DOM Node to the DOM. */ -function innerDiffNode(dom, vchildren, context, mountAll) { - let originalChildren = dom.childNodes, - children = [], - keyed = {}, - keyedLen = 0, - min = 0, - len = originalChildren.length, - childrenLen = 0, - vlen = vchildren && vchildren.length, - j, c, vchild, child; - - if (len) { - for (let i=0; i|undefined} */ - this.attributes = attributes; - - /** @type {array|undefined} */ - this.children = children; - - /** Reference to the given key. */ - this.key = attributes && attributes.key; -} -- cgit v1.2.3