Comparing version 5.0.0-alpha.14 to 5.0.0-alpha.15
@@ -1,8 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.define = define; | ||
function define(Ctor) { | ||
export function define(Ctor) { | ||
var registry = customElements; | ||
@@ -9,0 +5,0 @@ var is = Ctor.is; |
@@ -1,12 +0,3 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
exports.emit = emit; | ||
var defs = { | ||
@@ -18,3 +9,3 @@ bubbles: true, | ||
function emit(elem, name, opts) { | ||
export function emit(elem, name, opts) { | ||
opts = _extends({}, defs, opts); | ||
@@ -21,0 +12,0 @@ var e = void 0; |
@@ -1,89 +0,7 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _define = require('./define'); | ||
Object.keys(_define).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _define[key]; | ||
} | ||
}); | ||
}); | ||
var _emit = require('./emit'); | ||
Object.keys(_emit).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _emit[key]; | ||
} | ||
}); | ||
}); | ||
var _link = require('./link'); | ||
Object.keys(_link).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _link[key]; | ||
} | ||
}); | ||
}); | ||
var _withComponent = require('./with-component'); | ||
Object.keys(_withComponent).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _withComponent[key]; | ||
} | ||
}); | ||
}); | ||
var _withProps = require('./with-props'); | ||
Object.keys(_withProps).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _withProps[key]; | ||
} | ||
}); | ||
}); | ||
var _withRender = require('./with-render'); | ||
Object.keys(_withRender).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _withRender[key]; | ||
} | ||
}); | ||
}); | ||
var _withUnique = require('./with-unique'); | ||
Object.keys(_withUnique).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _withUnique[key]; | ||
} | ||
}); | ||
}); | ||
export * from './define'; | ||
export * from './emit'; | ||
export * from './link'; | ||
export * from './with-component'; | ||
export * from './with-props'; | ||
export * from './with-render'; | ||
export * from './with-unique'; |
@@ -1,9 +0,3 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.link = link; | ||
function getValue(elem) { | ||
@@ -20,3 +14,3 @@ var checked = elem.checked, | ||
function link(elem, target) { | ||
export function link(elem, target) { | ||
return function (e) { | ||
@@ -23,0 +17,0 @@ // TODO revisit once all browsers have native support. |
@@ -1,15 +0,3 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
exports.dashCase = dashCase; | ||
exports.debounce = debounce; | ||
exports.keys = keys; | ||
exports.sym = sym; | ||
exports.uniqueId = uniqueId; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -47,3 +35,3 @@ | ||
function dashCase(str) { | ||
export function dashCase(str) { | ||
return str.split(/([_A-Z])/).reduce(function (one, two, idx) { | ||
@@ -56,3 +44,3 @@ var dash = !one || idx % 2 === 0 ? '' : '-'; | ||
function debounce(cbFunc) { | ||
export function debounce(cbFunc) { | ||
var scheduled = false; | ||
@@ -77,7 +65,7 @@ var i = 0; | ||
var empty = exports.empty = function empty(val) { | ||
export var empty = function empty(val) { | ||
return val == null; | ||
}; | ||
function keys(obj) { | ||
export function keys(obj) { | ||
obj = obj || {}; | ||
@@ -88,7 +76,7 @@ var names = Object.getOwnPropertyNames(obj); | ||
function sym(description) { | ||
export function sym(description) { | ||
return typeof Symbol === 'function' ? Symbol(description ? String(description) : undefined) : uniqueId(description); | ||
} | ||
function uniqueId(description) { | ||
export function uniqueId(description) { | ||
return (description ? String(description) : '') + 'xxxxxxxx'.replace(/[xy]/g, function (c) { | ||
@@ -95,0 +83,0 @@ var r = Math.random() * 16 | 0; |
@@ -1,7 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
@@ -11,10 +5,5 @@ | ||
exports.normaliseAttributeDefinition = normaliseAttributeDefinition; | ||
exports.normalisePropertyDefinition = normalisePropertyDefinition; | ||
exports.syncAttributeToProperty = syncAttributeToProperty; | ||
exports.syncPropertyToAttribute = syncPropertyToAttribute; | ||
import { dashCase } from "./index"; | ||
var _index = require("./index"); | ||
function normaliseAttributeDefinition(name, prop) { | ||
export function normaliseAttributeDefinition(name, prop) { | ||
var attribute = prop.attribute; | ||
@@ -27,6 +16,6 @@ | ||
if (obj.source === true) { | ||
obj.source = (0, _index.dashCase)(name); | ||
obj.source = dashCase(name); | ||
} | ||
if (obj.target === true) { | ||
obj.target = (0, _index.dashCase)(name); | ||
obj.target = dashCase(name); | ||
} | ||
@@ -36,3 +25,3 @@ return obj; | ||
function normalisePropertyDefinition(name, prop) { | ||
export function normalisePropertyDefinition(name, prop) { | ||
var coerce = prop.coerce, | ||
@@ -58,3 +47,3 @@ def = prop.default, | ||
function syncAttributeToProperty(elem, name, value) { | ||
export function syncAttributeToProperty(elem, name, value) { | ||
if (elem._syncingPropertyToAttribute) { | ||
@@ -77,3 +66,3 @@ return; | ||
function syncPropertyToAttribute(elem, target, serialize, val) { | ||
export function syncPropertyToAttribute(elem, target, serialize, val) { | ||
if (target && elem._syncingAttributeToProperty !== target) { | ||
@@ -80,0 +69,0 @@ var serialized = serialize(val); |
@@ -1,14 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.formatName = formatName; | ||
exports.generateName = generateName; | ||
var _index = require("./index"); | ||
import { dashCase } from "./index"; | ||
var suffix = 0; | ||
function formatName(prefix, suffix) { | ||
export function formatName(prefix, suffix) { | ||
prefix = prefix || "element"; | ||
@@ -18,5 +12,5 @@ return (prefix.indexOf("-") === -1 ? "x-" + prefix : prefix) + (suffix ? "-" + suffix : ""); | ||
function generateName(Ctor) { | ||
export function generateName(Ctor) { | ||
var registry = customElements; | ||
var prefix = (0, _index.dashCase)(Ctor.name); | ||
var prefix = dashCase(Ctor.name); | ||
while (registry.get(formatName(prefix, suffix))) { | ||
@@ -23,0 +17,0 @@ suffix++; |
@@ -1,18 +0,3 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.h = exports.Component = exports.withComponent = undefined; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _preact = require('preact'); | ||
var _withProps = require('./with-props'); | ||
var _withRender2 = require('./with-render'); | ||
var _withUnique = require('./with-unique'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -24,3 +9,8 @@ | ||
var withComponent = exports.withComponent = function withComponent() { | ||
import { h, render } from 'preact'; | ||
import { withProps } from './with-props'; | ||
import { withRender } from './with-render'; | ||
import { withUnique } from './with-unique'; | ||
export var withComponent = function withComponent() { | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
@@ -39,3 +29,3 @@ return function (_withRender) { | ||
value: function rendererCallback(shadowRoot, renderCallback) { | ||
this._preactDom = (0, _preact.render)(renderCallback(), shadowRoot, this._preactDom || shadowRoot.children[0]); | ||
this._preactDom = render(renderCallback(), shadowRoot, this._preactDom || shadowRoot.children[0]); | ||
} | ||
@@ -45,6 +35,6 @@ }]); | ||
return _class2; | ||
}((0, _withRender2.withRender)((0, _withUnique.withUnique)((0, _withProps.withProps)(Base)))); | ||
}(withRender(withUnique(withProps(Base)))); | ||
}; | ||
var Component = exports.Component = withComponent(typeof window === 'undefined' ? function () { | ||
export var Component = withComponent(typeof window === 'undefined' ? function () { | ||
function _class3() { | ||
@@ -56,2 +46,2 @@ _classCallCheck(this, _class3); | ||
}() : HTMLElement); | ||
exports.h = _preact.h; | ||
export { h }; |
@@ -1,8 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.props = exports.withProps = undefined; | ||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
@@ -12,8 +5,2 @@ | ||
exports.prop = prop; | ||
var _index = require("./util/index"); | ||
var _withProps = require("./util/with-props"); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -25,3 +12,7 @@ | ||
function prop(definition) { | ||
import { debounce, empty, keys, sym } from "./util/index"; | ||
import { normalisePropertyDefinition, syncAttributeToProperty, syncPropertyToAttribute } from "./util/with-props"; | ||
export function prop(definition) { | ||
var propertyDefinition = definition || {}; | ||
@@ -33,4 +24,4 @@ | ||
var normalised = (0, _withProps.normalisePropertyDefinition)(name, propertyDefinition); | ||
var _value = (0, _index.sym)(name); | ||
var normalised = normalisePropertyDefinition(name, propertyDefinition); | ||
var _value = sym(name); | ||
@@ -52,3 +43,3 @@ // Cache the value so we can reference when syncing the attribute to the property. | ||
this[_value] = normalised.coerce(val); | ||
(0, _withProps.syncPropertyToAttribute)(this, normalised.attribute.target, normalised.serialize, val); | ||
syncPropertyToAttribute(this, normalised.attribute.target, normalised.serialize, val); | ||
this._updateDebounced(); | ||
@@ -67,3 +58,3 @@ } | ||
var withProps = exports.withProps = function withProps() { | ||
export var withProps = function withProps() { | ||
var _class, _temp; | ||
@@ -80,3 +71,3 @@ | ||
return (0, _index.keys)(this.constructor.props).reduce(function (prev, curr) { | ||
return keys(this.constructor.props).reduce(function (prev, curr) { | ||
prev[curr] = _this2[curr]; | ||
@@ -90,3 +81,3 @@ return prev; | ||
var ctorProps = this.constructor.props; | ||
(0, _index.keys)(props).forEach(function (k) { | ||
keys(props).forEach(function (k) { | ||
return k in ctorProps && (_this3[k] = props[k]); | ||
@@ -111,3 +102,3 @@ }); | ||
(0, _index.keys)(props).forEach(function (name) { | ||
keys(props).forEach(function (name) { | ||
var func = props[name]; | ||
@@ -149,3 +140,3 @@ if (typeof func !== "function") func = prop(func); | ||
_this._constructed = true; | ||
_this._updateDebounced = (0, _index.debounce)(_this._updateCallback); | ||
_this._updateDebounced = debounce(_this._updateCallback); | ||
return _this; | ||
@@ -189,3 +180,3 @@ } | ||
value: function propsUpdatedCallback(next, prev) { | ||
return !prev || (0, _index.keys)(prev).some(function (k) { | ||
return !prev || keys(prev).some(function (k) { | ||
return prev[k] !== next[k]; | ||
@@ -199,3 +190,3 @@ }); | ||
if (_get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "attributeChangedCallback", this)) _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "attributeChangedCallback", this).call(this, name, oldValue, newValue); | ||
(0, _withProps.syncAttributeToProperty)(this, name, newValue); | ||
syncAttributeToProperty(this, name, newValue); | ||
} | ||
@@ -216,3 +207,3 @@ | ||
var zeroOrNumber = function zeroOrNumber(val) { | ||
return (0, _index.empty)(val) ? 0 : Number(val); | ||
return empty(val) ? 0 : Number(val); | ||
}; | ||
@@ -227,3 +218,3 @@ | ||
coerce: function coerce(val) { | ||
return Array.isArray(val) ? val : (0, _index.empty)(val) ? null : [val]; | ||
return Array.isArray(val) ? val : empty(val) ? null : [val]; | ||
}, | ||
@@ -240,3 +231,3 @@ default: Object.freeze([]), | ||
deserialize: function deserialize(val) { | ||
return !(0, _index.empty)(val); | ||
return !empty(val); | ||
}, | ||
@@ -254,3 +245,3 @@ serialize: function serialize(val) { | ||
serialize: function serialize(val) { | ||
return (0, _index.empty)(val) ? null : String(Number(val)); | ||
return empty(val) ? null : String(Number(val)); | ||
} | ||
@@ -271,7 +262,7 @@ }); | ||
serialize: function serialize(val) { | ||
return (0, _index.empty)(val) ? null : String(val); | ||
return empty(val) ? null : String(val); | ||
} | ||
}); | ||
var props = exports.props = { | ||
export var props = { | ||
any: any, | ||
@@ -278,0 +269,0 @@ array: array, |
@@ -1,7 +0,1 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -21,3 +15,3 @@ | ||
var withRender = exports.withRender = function withRender() { | ||
export var withRender = function withRender() { | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
@@ -24,0 +18,0 @@ return function (_Base) { |
@@ -1,12 +0,3 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.withUnique = undefined; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _withUnique = require('./util/with-unique'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -18,3 +9,5 @@ | ||
var withUnique = exports.withUnique = function withUnique() { | ||
import { generateName } from './util/with-unique'; | ||
export var withUnique = function withUnique() { | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
@@ -33,3 +26,3 @@ return function (_Base) { | ||
get: function get() { | ||
return this._is || (this._is = (0, _withUnique.generateName)(this)); | ||
return this._is || (this._is = generateName(this)); | ||
}, | ||
@@ -36,0 +29,0 @@ set: function set(is) { |
@@ -1,10 +0,6 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.define = define; | ||
function define(Ctor) { | ||
var registry = customElements; | ||
var is = Ctor.is; | ||
export function define(Ctor) { | ||
const registry = customElements; | ||
const is = Ctor.is; | ||
if (!registry.get(is)) { | ||
@@ -11,0 +7,0 @@ registry.define(is, Ctor); |
@@ -1,13 +0,4 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
exports.emit = emit; | ||
var defs = { | ||
const defs = { | ||
bubbles: true, | ||
@@ -18,5 +9,5 @@ cancelable: true, | ||
function emit(elem, name, opts) { | ||
export function emit(elem, name, opts) { | ||
opts = _extends({}, defs, opts); | ||
var e = void 0; | ||
let e; | ||
if ('composed' in CustomEvent.prototype) { | ||
@@ -23,0 +14,0 @@ e = new CustomEvent(name, opts); |
@@ -1,89 +0,7 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _define = require('./define.js'); | ||
Object.keys(_define).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _define[key]; | ||
} | ||
}); | ||
}); | ||
var _emit = require('./emit.js'); | ||
Object.keys(_emit).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _emit[key]; | ||
} | ||
}); | ||
}); | ||
var _link = require('./link.js'); | ||
Object.keys(_link).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _link[key]; | ||
} | ||
}); | ||
}); | ||
var _withComponent = require('./with-component.js'); | ||
Object.keys(_withComponent).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _withComponent[key]; | ||
} | ||
}); | ||
}); | ||
var _withProps = require('./with-props.js'); | ||
Object.keys(_withProps).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _withProps[key]; | ||
} | ||
}); | ||
}); | ||
var _withRender = require('./with-render.js'); | ||
Object.keys(_withRender).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _withRender[key]; | ||
} | ||
}); | ||
}); | ||
var _withUnique = require('./with-unique.js'); | ||
Object.keys(_withUnique).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _withUnique[key]; | ||
} | ||
}); | ||
}); | ||
export * from './define.js'; | ||
export * from './emit.js'; | ||
export * from './link.js'; | ||
export * from './with-component.js'; | ||
export * from './with-props.js'; | ||
export * from './with-render.js'; | ||
export * from './with-unique.js'; |
@@ -1,14 +0,5 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.link = link; | ||
function getValue(elem) { | ||
var checked = elem.checked, | ||
type = elem.type, | ||
value = elem.value; | ||
const { checked, type, value } = elem; | ||
if (type === 'checkbox' || type === 'radio') { | ||
@@ -20,4 +11,4 @@ return checked ? value || true : false; | ||
function link(elem, target) { | ||
return function (e) { | ||
export function link(elem, target) { | ||
return e => { | ||
// TODO revisit once all browsers have native support. | ||
@@ -28,13 +19,11 @@ // | ||
// quirk in the shadydom polyfill that incorrectly returns null for the | ||
var localTarget = e.target || e.composedPath && e.composedPath()[0]; | ||
var value = getValue(localTarget); | ||
var localTargetName = target || localTarget.name || 'value'; | ||
const localTarget = e.target || e.composedPath && e.composedPath()[0]; | ||
const value = getValue(localTarget); | ||
const localTargetName = target || localTarget.name || 'value'; | ||
if (localTargetName.indexOf('.') > -1) { | ||
var parts = localTargetName.split('.'); | ||
var firstPart = parts[0]; | ||
var propName = parts.pop(); | ||
var obj = parts.reduce(function (prev, curr) { | ||
return prev[curr]; | ||
}, elem); | ||
const parts = localTargetName.split('.'); | ||
const firstPart = parts[0]; | ||
const propName = parts.pop(); | ||
const obj = parts.reduce((prev, curr) => prev[curr], elem); | ||
@@ -41,0 +30,0 @@ obj[propName || localTarget.name] = value; |
@@ -1,60 +0,33 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
exports.dashCase = dashCase; | ||
exports.debounce = debounce; | ||
exports.keys = keys; | ||
exports.sym = sym; | ||
exports.uniqueId = uniqueId; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Mo = typeof MutationObserver === 'function' ? MutationObserver : function () { | ||
function _class2(func) { | ||
_classCallCheck(this, _class2); | ||
const Mo = typeof MutationObserver === 'function' ? MutationObserver : class { | ||
constructor(func) { | ||
this.func = func; | ||
} | ||
_createClass(_class2, [{ | ||
key: 'observe', | ||
value: function observe(node) { | ||
var func = this.func; | ||
var prop = { | ||
set: function set() { | ||
if (typeof Promise === 'undefined') { | ||
setTimeout(func); | ||
} else { | ||
new Promise(function (resolve) { | ||
return resolve(); | ||
}).then(func); | ||
} | ||
observe(node) { | ||
const { func } = this; | ||
const prop = { | ||
set() { | ||
if (typeof Promise === 'undefined') { | ||
setTimeout(func); | ||
} else { | ||
new Promise(resolve => resolve()).then(func); | ||
} | ||
}; | ||
Object.defineProperty(node, 'textContent', prop); | ||
} | ||
}]); | ||
} | ||
}; | ||
Object.defineProperty(node, 'textContent', prop); | ||
} | ||
}; | ||
return _class2; | ||
}(); | ||
function dashCase(str) { | ||
return str.split(/([_A-Z])/).reduce(function (one, two, idx) { | ||
var dash = !one || idx % 2 === 0 ? '' : '-'; | ||
export function dashCase(str) { | ||
return str.split(/([_A-Z])/).reduce((one, two, idx) => { | ||
const dash = !one || idx % 2 === 0 ? '' : '-'; | ||
two = two === '_' ? '' : two; | ||
return '' + one + dash + two.toLowerCase(); | ||
return `${one}${dash}${two.toLowerCase()}`; | ||
}); | ||
} | ||
function debounce(cbFunc) { | ||
var scheduled = false; | ||
var i = 0; | ||
var elem = document.createElement('span'); | ||
var observer = new Mo(function () { | ||
export function debounce(cbFunc) { | ||
let scheduled = false; | ||
let i = 0; | ||
const elem = document.createElement('span'); | ||
const observer = new Mo(() => { | ||
cbFunc(); | ||
@@ -66,6 +39,6 @@ scheduled = false; | ||
return function () { | ||
return () => { | ||
if (!scheduled) { | ||
scheduled = true; | ||
elem.textContent = '' + i; | ||
elem.textContent = `${i}`; | ||
i += 1; | ||
@@ -76,22 +49,20 @@ } | ||
var empty = exports.empty = function empty(val) { | ||
return val == null; | ||
}; | ||
export const empty = val => val == null; | ||
function keys(obj) { | ||
export function keys(obj) { | ||
obj = obj || {}; | ||
var names = Object.getOwnPropertyNames(obj); | ||
const names = Object.getOwnPropertyNames(obj); | ||
return Object.getOwnPropertySymbols ? names.concat(Object.getOwnPropertySymbols(obj)) : names; | ||
} | ||
function sym(description) { | ||
export function sym(description) { | ||
return typeof Symbol === 'function' ? Symbol(description ? String(description) : undefined) : uniqueId(description); | ||
} | ||
function uniqueId(description) { | ||
return (description ? String(description) : '') + 'xxxxxxxx'.replace(/[xy]/g, function (c) { | ||
var r = Math.random() * 16 | 0; | ||
var v = c === 'x' ? r : r & 0x3 | 0x8; | ||
export function uniqueId(description) { | ||
return (description ? String(description) : '') + 'xxxxxxxx'.replace(/[xy]/g, c => { | ||
const r = Math.random() * 16 | 0; | ||
const v = c === 'x' ? r : r & 0x3 | 0x8; | ||
return v.toString(16); | ||
}); | ||
} |
@@ -1,22 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
import { dashCase } from "./index.js"; | ||
exports.normaliseAttributeDefinition = normaliseAttributeDefinition; | ||
exports.normalisePropertyDefinition = normalisePropertyDefinition; | ||
exports.syncAttributeToProperty = syncAttributeToProperty; | ||
exports.syncPropertyToAttribute = syncPropertyToAttribute; | ||
var _index = require("./index.js"); | ||
function normaliseAttributeDefinition(name, prop) { | ||
var attribute = prop.attribute; | ||
var obj = (typeof attribute === "undefined" ? "undefined" : _typeof(attribute)) === "object" ? _extends({}, attribute) : { | ||
export function normaliseAttributeDefinition(name, prop) { | ||
const { attribute } = prop; | ||
const obj = typeof attribute === "object" ? _extends({}, attribute) : { | ||
source: attribute, | ||
@@ -26,6 +12,6 @@ target: attribute | ||
if (obj.source === true) { | ||
obj.source = (0, _index.dashCase)(name); | ||
obj.source = dashCase(name); | ||
} | ||
if (obj.target === true) { | ||
obj.target = (0, _index.dashCase)(name); | ||
obj.target = dashCase(name); | ||
} | ||
@@ -35,33 +21,20 @@ return obj; | ||
function normalisePropertyDefinition(name, prop) { | ||
var coerce = prop.coerce, | ||
def = prop.default, | ||
deserialize = prop.deserialize, | ||
serialize = prop.serialize; | ||
export function normalisePropertyDefinition(name, prop) { | ||
const { coerce, default: def, deserialize, serialize } = prop; | ||
return { | ||
attribute: normaliseAttributeDefinition(name, prop), | ||
coerce: coerce || function (v) { | ||
return v; | ||
}, | ||
coerce: coerce || (v => v), | ||
default: def, | ||
deserialize: deserialize || function (v) { | ||
return v; | ||
}, | ||
serialize: serialize || function (v) { | ||
return v; | ||
} | ||
deserialize: deserialize || (v => v), | ||
serialize: serialize || (v => v) | ||
}; | ||
} | ||
function syncAttributeToProperty(elem, name, value) { | ||
export function syncAttributeToProperty(elem, name, value) { | ||
if (elem._syncingPropertyToAttribute) { | ||
return; | ||
} | ||
var propDefs = elem.constructor.props; | ||
for (var propName in propDefs) { | ||
var _propDefs$propName = propDefs[propName], | ||
source = _propDefs$propName.attribute.source, | ||
deserialize = _propDefs$propName.deserialize; | ||
const propDefs = elem.constructor.props; | ||
for (let propName in propDefs) { | ||
const { attribute: { source }, deserialize } = propDefs[propName]; | ||
if (source === name) { | ||
@@ -75,5 +48,5 @@ elem._syncingAttributeToProperty = propName; | ||
function syncPropertyToAttribute(elem, target, serialize, val) { | ||
export function syncPropertyToAttribute(elem, target, serialize, val) { | ||
if (target && elem._syncingAttributeToProperty !== target) { | ||
var serialized = serialize(val); | ||
const serialized = serialize(val); | ||
elem._syncingPropertyToAttribute = true; | ||
@@ -80,0 +53,0 @@ if (serialized == null) { |
@@ -1,21 +0,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.formatName = formatName; | ||
exports.generateName = generateName; | ||
var _index = require("./index.js"); | ||
import { dashCase } from "./index.js"; | ||
var suffix = 0; | ||
let suffix = 0; | ||
function formatName(prefix, suffix) { | ||
export function formatName(prefix, suffix) { | ||
prefix = prefix || "element"; | ||
return (prefix.indexOf("-") === -1 ? "x-" + prefix : prefix) + (suffix ? "-" + suffix : ""); | ||
return (prefix.indexOf("-") === -1 ? `x-${prefix}` : prefix) + (suffix ? `-${suffix}` : ""); | ||
} | ||
function generateName(Ctor) { | ||
var registry = customElements; | ||
var prefix = (0, _index.dashCase)(Ctor.name); | ||
export function generateName(Ctor) { | ||
const registry = customElements; | ||
const prefix = dashCase(Ctor.name); | ||
while (registry.get(formatName(prefix, suffix))) { | ||
@@ -22,0 +16,0 @@ suffix++; |
@@ -1,53 +0,15 @@ | ||
'use strict'; | ||
import { h, render } from '../../node_modules/preact/dist/preact.esm.js'; | ||
import { withProps } from './with-props.js'; | ||
import { withRender } from './with-render.js'; | ||
import { withUnique } from './with-unique.js'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.h = exports.Component = exports.withComponent = undefined; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _preactEsm = require('../../node_modules/preact/dist/preact.esm.js'); | ||
var _withProps = require('./with-props.js'); | ||
var _withRender2 = require('./with-render.js'); | ||
var _withUnique = require('./with-unique.js'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var withComponent = exports.withComponent = function withComponent() { | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
return function (_withRender) { | ||
_inherits(_class2, _withRender); | ||
function _class2() { | ||
_classCallCheck(this, _class2); | ||
return _possibleConstructorReturn(this, (_class2.__proto__ || Object.getPrototypeOf(_class2)).apply(this, arguments)); | ||
export const withComponent = (Base = HTMLElement) => { | ||
return class extends withRender(withUnique(withProps(Base))) { | ||
rendererCallback(shadowRoot, renderCallback) { | ||
this._preactDom = render(renderCallback(), shadowRoot, this._preactDom || shadowRoot.children[0]); | ||
} | ||
_createClass(_class2, [{ | ||
key: 'rendererCallback', | ||
value: function rendererCallback(shadowRoot, renderCallback) { | ||
this._preactDom = (0, _preactEsm.render)(renderCallback(), shadowRoot, this._preactDom || shadowRoot.children[0]); | ||
} | ||
}]); | ||
return _class2; | ||
}((0, _withRender2.withRender)((0, _withUnique.withUnique)((0, _withProps.withProps)(Base)))); | ||
}; | ||
}; | ||
var Component = exports.Component = withComponent(typeof window === 'undefined' ? function () { | ||
function _class3() { | ||
_classCallCheck(this, _class3); | ||
} | ||
return _class3; | ||
}() : HTMLElement); | ||
exports.h = _preactEsm.h; | ||
export const Component = withComponent(typeof window === 'undefined' ? class {} : HTMLElement); | ||
export { h }; |
@@ -1,34 +0,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.props = exports.withProps = undefined; | ||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
import { debounce, empty, keys, sym } from "./util/index.js"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
import { normalisePropertyDefinition, syncAttributeToProperty, syncPropertyToAttribute } from "./util/with-props.js"; | ||
exports.prop = prop; | ||
export function prop(definition) { | ||
const propertyDefinition = definition || {}; | ||
var _index = require("./util/index.js"); | ||
var _withProps = require("./util/with-props.js"); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function prop(definition) { | ||
var propertyDefinition = definition || {}; | ||
// Allows decorators, or imperative definitions. | ||
var func = function func(_ref, name) { | ||
var constructor = _ref.constructor; | ||
const func = function ({ constructor }, name) { | ||
const normalised = normalisePropertyDefinition(name, propertyDefinition); | ||
const _value = sym(name); | ||
var normalised = (0, _withProps.normalisePropertyDefinition)(name, propertyDefinition); | ||
var _value = (0, _index.sym)(name); | ||
// Cache the value so we can reference when syncing the attribute to the property. | ||
@@ -43,9 +24,9 @@ constructor._props[name] = normalised; | ||
configurable: true, | ||
get: function get() { | ||
var val = this[_value]; | ||
get() { | ||
const val = this[_value]; | ||
return val == null ? normalised.default : val; | ||
}, | ||
set: function set(val) { | ||
set(val) { | ||
this[_value] = normalised.coerce(val); | ||
(0, _withProps.syncPropertyToAttribute)(this, normalised.attribute.target, normalised.serialize, val); | ||
syncPropertyToAttribute(this, normalised.attribute.target, normalised.serialize, val); | ||
this._updateDebounced(); | ||
@@ -57,5 +38,3 @@ } | ||
// Allows easy extension of pre-defined props { ...prop(), ...{} }. | ||
Object.keys(propertyDefinition).forEach(function (key) { | ||
return func[key] = propertyDefinition[key]; | ||
}); | ||
Object.keys(propertyDefinition).forEach(key => func[key] = propertyDefinition[key]); | ||
@@ -65,58 +44,44 @@ return func; | ||
var withProps = exports.withProps = function withProps() { | ||
export const withProps = (Base = HTMLElement) => { | ||
var _class, _temp; | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
return _temp = _class = function (_Base) { | ||
_inherits(_class, _Base); | ||
return _temp = _class = class extends Base { | ||
_createClass(_class, [{ | ||
key: "props", | ||
get: function get() { | ||
var _this2 = this; | ||
static get observedAttributes() { | ||
return this._observedAttributes; | ||
} | ||
return (0, _index.keys)(this.constructor.props).reduce(function (prev, curr) { | ||
prev[curr] = _this2[curr]; | ||
return prev; | ||
}, {}); | ||
}, | ||
set: function set(props) { | ||
var _this3 = this; | ||
static set observedAttributes(attrs) { | ||
this._observedAttributes = this.observedAttributes.concat(attrs); | ||
} | ||
var ctorProps = this.constructor.props; | ||
(0, _index.keys)(props).forEach(function (k) { | ||
return k in ctorProps && (_this3[k] = props[k]); | ||
}); | ||
} | ||
}], [{ | ||
key: "observedAttributes", | ||
get: function get() { | ||
return this._observedAttributes; | ||
}, | ||
set: function set(attrs) { | ||
this._observedAttributes = this.observedAttributes.concat(attrs); | ||
} | ||
}, { | ||
key: "props", | ||
get: function get() { | ||
return this._props; | ||
}, | ||
set: function set(props) { | ||
var _this4 = this; | ||
static get props() { | ||
return this._props; | ||
} | ||
(0, _index.keys)(props).forEach(function (name) { | ||
var func = props[name]; | ||
if (typeof func !== "function") func = prop(func); | ||
func({ constructor: _this4 }, name); | ||
}); | ||
} | ||
}]); | ||
static set props(props) { | ||
keys(props).forEach(name => { | ||
let func = props[name]; | ||
if (typeof func !== "function") func = prop(func); | ||
func({ constructor: this }, name); | ||
}); | ||
} | ||
function _class() { | ||
_classCallCheck(this, _class); | ||
get props() { | ||
return keys(this.constructor.props).reduce((prev, curr) => { | ||
prev[curr] = this[curr]; | ||
return prev; | ||
}, {}); | ||
} | ||
var _this = _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this)); | ||
set props(props) { | ||
const ctorProps = this.constructor.props; | ||
keys(props).forEach(k => k in ctorProps && (this[k] = props[k])); | ||
} | ||
_this._updateCallback = function () { | ||
if (_this._updating || !_this._connected) { | ||
constructor() { | ||
super(); | ||
this._updateCallback = () => { | ||
if (this._updating || !this._connected) { | ||
return; | ||
@@ -127,95 +92,69 @@ } | ||
// queueing a render - while there is a pending render. | ||
_this._updating = true; | ||
this._updating = true; | ||
// Prev / next props for prop lifecycle callbacks. | ||
var prev = _this._prevProps; | ||
var next = _this._prevProps = _this.props; | ||
const prev = this._prevProps; | ||
const next = this._prevProps = this.props; | ||
// Always call set, but only call changed if the props updated. | ||
_this.propsSetCallback(next, prev); | ||
if (_this.propsUpdatedCallback(next, prev)) { | ||
_this.propsChangedCallback(next, prev); | ||
this.propsSetCallback(next, prev); | ||
if (this.propsUpdatedCallback(next, prev)) { | ||
this.propsChangedCallback(next, prev); | ||
} | ||
_this._updating = false; | ||
this._updating = false; | ||
}; | ||
if (_this._constructed) return _possibleConstructorReturn(_this); | ||
_this._constructed = true; | ||
_this._updateDebounced = (0, _index.debounce)(_this._updateCallback); | ||
return _this; | ||
if (this._constructed) return; | ||
this._constructed = true; | ||
this._updateDebounced = debounce(this._updateCallback); | ||
} | ||
_createClass(_class, [{ | ||
key: "connectedCallback", | ||
value: function connectedCallback() { | ||
if (this._connected) return; | ||
this._connected = true; | ||
// $FlowFixMe - HTMLElement doesn't implement connectedCallback. | ||
if (_get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "connectedCallback", this)) _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "connectedCallback", this).call(this); | ||
this._updateDebounced(); | ||
} | ||
}, { | ||
key: "disconnectedCallback", | ||
value: function disconnectedCallback() { | ||
if (!this._connected) return; | ||
this._connected = false; | ||
// $FlowFixMe - HTMLElement doesn't implement disconnectedCallback. | ||
if (_get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "disconnectedCallback", this)) _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "disconnectedCallback", this).call(this); | ||
} | ||
connectedCallback() { | ||
if (this._connected) return; | ||
this._connected = true; | ||
// $FlowFixMe - HTMLElement doesn't implement connectedCallback. | ||
if (super.connectedCallback) super.connectedCallback(); | ||
this._updateDebounced(); | ||
} | ||
// Called when props actually change. | ||
disconnectedCallback() { | ||
if (!this._connected) return; | ||
this._connected = false; | ||
// $FlowFixMe - HTMLElement doesn't implement disconnectedCallback. | ||
if (super.disconnectedCallback) super.disconnectedCallback(); | ||
} | ||
}, { | ||
key: "propsChangedCallback", | ||
value: function propsChangedCallback() {} | ||
// Called when props actually change. | ||
propsChangedCallback() {} | ||
// Called whenever props are set, even if they don't change. | ||
// Called whenever props are set, even if they don't change. | ||
propsSetCallback() {} | ||
}, { | ||
key: "propsSetCallback", | ||
value: function propsSetCallback() {} | ||
// Called to see if the props changed. | ||
propsUpdatedCallback(next, prev) { | ||
return !prev || keys(prev).some(k => prev[k] !== next[k]); | ||
} | ||
// Called to see if the props changed. | ||
attributeChangedCallback(name, oldValue, newValue) { | ||
// $FlowFixMe - HTMLElement doesn't implement attributeChangedCallback. | ||
if (super.attributeChangedCallback) super.attributeChangedCallback(name, oldValue, newValue); | ||
syncAttributeToProperty(this, name, newValue); | ||
} | ||
}, { | ||
key: "propsUpdatedCallback", | ||
value: function propsUpdatedCallback(next, prev) { | ||
return !prev || (0, _index.keys)(prev).some(function (k) { | ||
return prev[k] !== next[k]; | ||
}); | ||
} | ||
}, { | ||
key: "attributeChangedCallback", | ||
value: function attributeChangedCallback(name, oldValue, newValue) { | ||
// $FlowFixMe - HTMLElement doesn't implement attributeChangedCallback. | ||
if (_get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "attributeChangedCallback", this)) _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "attributeChangedCallback", this).call(this, name, oldValue, newValue); | ||
(0, _withProps.syncAttributeToProperty)(this, name, newValue); | ||
} | ||
// Invokes the complete render lifecycle. | ||
}]); | ||
return _class; | ||
}(Base), _class._observedAttributes = [], _class._props = {}, _temp; | ||
// Invokes the complete render lifecycle. | ||
}, _class._observedAttributes = [], _class._props = {}, _temp; | ||
}; | ||
var parse = JSON.parse, | ||
stringify = JSON.stringify; | ||
const { parse, stringify } = JSON; | ||
const attribute = Object.freeze({ source: true }); | ||
const zeroOrNumber = val => empty(val) ? 0 : Number(val); | ||
var attribute = Object.freeze({ source: true }); | ||
var zeroOrNumber = function zeroOrNumber(val) { | ||
return (0, _index.empty)(val) ? 0 : Number(val); | ||
}; | ||
var any = prop({ | ||
attribute: attribute | ||
const any = prop({ | ||
attribute | ||
}); | ||
var array = prop({ | ||
attribute: attribute, | ||
coerce: function coerce(val) { | ||
return Array.isArray(val) ? val : (0, _index.empty)(val) ? null : [val]; | ||
}, | ||
const array = prop({ | ||
attribute, | ||
coerce: val => Array.isArray(val) ? val : empty(val) ? null : [val], | ||
default: Object.freeze([]), | ||
@@ -226,26 +165,20 @@ deserialize: parse, | ||
var boolean = prop({ | ||
attribute: attribute, | ||
const boolean = prop({ | ||
attribute, | ||
coerce: Boolean, | ||
default: false, | ||
deserialize: function deserialize(val) { | ||
return !(0, _index.empty)(val); | ||
}, | ||
serialize: function serialize(val) { | ||
return val ? "" : null; | ||
} | ||
deserialize: val => !empty(val), | ||
serialize: val => val ? "" : null | ||
}); | ||
var number = prop({ | ||
attribute: attribute, | ||
const number = prop({ | ||
attribute, | ||
default: 0, | ||
coerce: zeroOrNumber, | ||
deserialize: zeroOrNumber, | ||
serialize: function serialize(val) { | ||
return (0, _index.empty)(val) ? null : String(Number(val)); | ||
} | ||
serialize: val => empty(val) ? null : String(Number(val)) | ||
}); | ||
var object = prop({ | ||
attribute: attribute, | ||
const object = prop({ | ||
attribute, | ||
default: Object.freeze({}), | ||
@@ -256,18 +189,16 @@ deserialize: parse, | ||
var string = prop({ | ||
attribute: attribute, | ||
const string = prop({ | ||
attribute, | ||
default: "", | ||
coerce: String, | ||
serialize: function serialize(val) { | ||
return (0, _index.empty)(val) ? null : String(val); | ||
} | ||
serialize: val => empty(val) ? null : String(val) | ||
}); | ||
var props = exports.props = { | ||
any: any, | ||
array: array, | ||
boolean: boolean, | ||
number: number, | ||
object: object, | ||
string: string | ||
export const props = { | ||
any, | ||
array, | ||
boolean, | ||
number, | ||
object, | ||
string | ||
}; |
@@ -1,17 +0,3 @@ | ||
'use strict'; | ||
const attachShadowOptions = { mode: 'open' }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var attachShadowOptions = { mode: 'open' }; | ||
function attachShadow(elem) { | ||
@@ -21,42 +7,19 @@ return elem.attachShadow ? elem.attachShadow(attachShadowOptions) : elem; | ||
var withRender = exports.withRender = function withRender() { | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
return function (_Base) { | ||
_inherits(_class2, _Base); | ||
export const withRender = (Base = HTMLElement) => { | ||
return class extends Base { | ||
function _class2() { | ||
_classCallCheck(this, _class2); | ||
get renderRoot() { | ||
this._shadowRoot = this._shadowRoot || (this._shadowRoot = this.shadowRoot || attachShadow(this)); | ||
return this._shadowRoot; | ||
} | ||
return _possibleConstructorReturn(this, (_class2.__proto__ || Object.getPrototypeOf(_class2)).apply(this, arguments)); | ||
propsChangedCallback() { | ||
this.rendererCallback(this.renderRoot, () => this.renderCallback(this)); | ||
this.renderedCallback(); | ||
} | ||
_createClass(_class2, [{ | ||
key: 'propsChangedCallback', | ||
value: function propsChangedCallback() { | ||
var _this2 = this; | ||
this.rendererCallback(this.renderRoot, function () { | ||
return _this2.renderCallback(_this2); | ||
}); | ||
this.renderedCallback(); | ||
} | ||
}, { | ||
key: 'renderCallback', | ||
value: function renderCallback() {} | ||
}, { | ||
key: 'renderedCallback', | ||
value: function renderedCallback() {} | ||
}, { | ||
key: 'rendererCallback', | ||
value: function rendererCallback() {} | ||
}, { | ||
key: 'renderRoot', | ||
get: function get() { | ||
this._shadowRoot = this._shadowRoot || (this._shadowRoot = this.shadowRoot || attachShadow(this)); | ||
return this._shadowRoot; | ||
} | ||
}]); | ||
return _class2; | ||
}(Base); | ||
renderCallback() {} | ||
renderedCallback() {} | ||
rendererCallback() {} | ||
}; | ||
}; |
@@ -1,41 +0,13 @@ | ||
'use strict'; | ||
import { generateName } from './util/with-unique.js'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.withUnique = undefined; | ||
export const withUnique = (Base = HTMLElement) => { | ||
return class extends Base { | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _withUnique = require('./util/with-unique.js'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var withUnique = exports.withUnique = function withUnique() { | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
return function (_Base) { | ||
_inherits(_class2, _Base); | ||
function _class2() { | ||
_classCallCheck(this, _class2); | ||
return _possibleConstructorReturn(this, (_class2.__proto__ || Object.getPrototypeOf(_class2)).apply(this, arguments)); | ||
static get is() { | ||
return this._is || (this._is = generateName(this)); | ||
} | ||
_createClass(_class2, null, [{ | ||
key: 'is', | ||
get: function get() { | ||
return this._is || (this._is = (0, _withUnique.generateName)(this)); | ||
}, | ||
set: function set(is) { | ||
this._is = is; | ||
} | ||
}]); | ||
return _class2; | ||
}(Base); | ||
static set is(is) { | ||
this._is = is; | ||
} | ||
}; | ||
}; |
@@ -8,4 +8,4 @@ 'use strict'; | ||
function define(Ctor) { | ||
var registry = customElements; | ||
var is = Ctor.is; | ||
const registry = customElements; | ||
const is = Ctor.is; | ||
if (!registry.get(is)) { | ||
@@ -12,0 +12,0 @@ registry.define(is, Ctor); |
@@ -12,3 +12,3 @@ 'use strict'; | ||
var defs = { | ||
const defs = { | ||
bubbles: true, | ||
@@ -21,3 +21,3 @@ cancelable: true, | ||
opts = _extends({}, defs, opts); | ||
var e = void 0; | ||
let e; | ||
if ('composed' in CustomEvent.prototype) { | ||
@@ -24,0 +24,0 @@ e = new CustomEvent(name, opts); |
@@ -13,3 +13,3 @@ 'use strict'; | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _define[key]; | ||
@@ -26,3 +26,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _emit[key]; | ||
@@ -39,3 +39,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _link[key]; | ||
@@ -52,3 +52,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _withComponent[key]; | ||
@@ -65,3 +65,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _withProps[key]; | ||
@@ -78,3 +78,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _withRender[key]; | ||
@@ -91,3 +91,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _withUnique[key]; | ||
@@ -94,0 +94,0 @@ } |
@@ -10,6 +10,3 @@ 'use strict'; | ||
function getValue(elem) { | ||
var checked = elem.checked, | ||
type = elem.type, | ||
value = elem.value; | ||
const { checked, type, value } = elem; | ||
if (type === 'checkbox' || type === 'radio') { | ||
@@ -22,3 +19,3 @@ return checked ? value || true : false; | ||
function link(elem, target) { | ||
return function (e) { | ||
return e => { | ||
// TODO revisit once all browsers have native support. | ||
@@ -29,13 +26,11 @@ // | ||
// quirk in the shadydom polyfill that incorrectly returns null for the | ||
var localTarget = e.target || e.composedPath && e.composedPath()[0]; | ||
var value = getValue(localTarget); | ||
var localTargetName = target || localTarget.name || 'value'; | ||
const localTarget = e.target || e.composedPath && e.composedPath()[0]; | ||
const value = getValue(localTarget); | ||
const localTargetName = target || localTarget.name || 'value'; | ||
if (localTargetName.indexOf('.') > -1) { | ||
var parts = localTargetName.split('.'); | ||
var firstPart = parts[0]; | ||
var propName = parts.pop(); | ||
var obj = parts.reduce(function (prev, curr) { | ||
return prev[curr]; | ||
}, elem); | ||
const parts = localTargetName.split('.'); | ||
const firstPart = parts[0]; | ||
const propName = parts.pop(); | ||
const obj = parts.reduce((prev, curr) => prev[curr], elem); | ||
@@ -42,0 +37,0 @@ obj[propName || localTarget.name] = value; |
@@ -6,5 +6,2 @@ 'use strict'; | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
exports.dashCase = dashCase; | ||
@@ -15,40 +12,26 @@ exports.debounce = debounce; | ||
exports.uniqueId = uniqueId; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Mo = typeof MutationObserver === 'function' ? MutationObserver : function () { | ||
function _class2(func) { | ||
_classCallCheck(this, _class2); | ||
const Mo = typeof MutationObserver === 'function' ? MutationObserver : class { | ||
constructor(func) { | ||
this.func = func; | ||
} | ||
_createClass(_class2, [{ | ||
key: 'observe', | ||
value: function observe(node) { | ||
var func = this.func; | ||
var prop = { | ||
set: function set() { | ||
if (typeof Promise === 'undefined') { | ||
setTimeout(func); | ||
} else { | ||
new Promise(function (resolve) { | ||
return resolve(); | ||
}).then(func); | ||
} | ||
observe(node) { | ||
const { func } = this; | ||
const prop = { | ||
set() { | ||
if (typeof Promise === 'undefined') { | ||
setTimeout(func); | ||
} else { | ||
new Promise(resolve => resolve()).then(func); | ||
} | ||
}; | ||
Object.defineProperty(node, 'textContent', prop); | ||
} | ||
}]); | ||
} | ||
}; | ||
Object.defineProperty(node, 'textContent', prop); | ||
} | ||
}; | ||
return _class2; | ||
}(); | ||
function dashCase(str) { | ||
return str.split(/([_A-Z])/).reduce(function (one, two, idx) { | ||
var dash = !one || idx % 2 === 0 ? '' : '-'; | ||
return str.split(/([_A-Z])/).reduce((one, two, idx) => { | ||
const dash = !one || idx % 2 === 0 ? '' : '-'; | ||
two = two === '_' ? '' : two; | ||
return '' + one + dash + two.toLowerCase(); | ||
return `${one}${dash}${two.toLowerCase()}`; | ||
}); | ||
@@ -58,6 +41,6 @@ } | ||
function debounce(cbFunc) { | ||
var scheduled = false; | ||
var i = 0; | ||
var elem = document.createElement('span'); | ||
var observer = new Mo(function () { | ||
let scheduled = false; | ||
let i = 0; | ||
const elem = document.createElement('span'); | ||
const observer = new Mo(() => { | ||
cbFunc(); | ||
@@ -69,6 +52,6 @@ scheduled = false; | ||
return function () { | ||
return () => { | ||
if (!scheduled) { | ||
scheduled = true; | ||
elem.textContent = '' + i; | ||
elem.textContent = `${i}`; | ||
i += 1; | ||
@@ -79,9 +62,7 @@ } | ||
var empty = exports.empty = function empty(val) { | ||
return val == null; | ||
}; | ||
const empty = exports.empty = val => val == null; | ||
function keys(obj) { | ||
obj = obj || {}; | ||
var names = Object.getOwnPropertyNames(obj); | ||
const names = Object.getOwnPropertyNames(obj); | ||
return Object.getOwnPropertySymbols ? names.concat(Object.getOwnPropertySymbols(obj)) : names; | ||
@@ -95,7 +76,7 @@ } | ||
function uniqueId(description) { | ||
return (description ? String(description) : '') + 'xxxxxxxx'.replace(/[xy]/g, function (c) { | ||
var r = Math.random() * 16 | 0; | ||
var v = c === 'x' ? r : r & 0x3 | 0x8; | ||
return (description ? String(description) : '') + 'xxxxxxxx'.replace(/[xy]/g, c => { | ||
const r = Math.random() * 16 | 0; | ||
const v = c === 'x' ? r : r & 0x3 | 0x8; | ||
return v.toString(16); | ||
}); | ||
} |
@@ -9,4 +9,2 @@ "use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.normaliseAttributeDefinition = normaliseAttributeDefinition; | ||
@@ -20,5 +18,4 @@ exports.normalisePropertyDefinition = normalisePropertyDefinition; | ||
function normaliseAttributeDefinition(name, prop) { | ||
var attribute = prop.attribute; | ||
var obj = (typeof attribute === "undefined" ? "undefined" : _typeof(attribute)) === "object" ? _extends({}, attribute) : { | ||
const { attribute } = prop; | ||
const obj = typeof attribute === "object" ? _extends({}, attribute) : { | ||
source: attribute, | ||
@@ -37,19 +34,9 @@ target: attribute | ||
function normalisePropertyDefinition(name, prop) { | ||
var coerce = prop.coerce, | ||
def = prop.default, | ||
deserialize = prop.deserialize, | ||
serialize = prop.serialize; | ||
const { coerce, default: def, deserialize, serialize } = prop; | ||
return { | ||
attribute: normaliseAttributeDefinition(name, prop), | ||
coerce: coerce || function (v) { | ||
return v; | ||
}, | ||
coerce: coerce || (v => v), | ||
default: def, | ||
deserialize: deserialize || function (v) { | ||
return v; | ||
}, | ||
serialize: serialize || function (v) { | ||
return v; | ||
} | ||
deserialize: deserialize || (v => v), | ||
serialize: serialize || (v => v) | ||
}; | ||
@@ -62,8 +49,5 @@ } | ||
} | ||
var propDefs = elem.constructor.props; | ||
for (var propName in propDefs) { | ||
var _propDefs$propName = propDefs[propName], | ||
source = _propDefs$propName.attribute.source, | ||
deserialize = _propDefs$propName.deserialize; | ||
const propDefs = elem.constructor.props; | ||
for (let propName in propDefs) { | ||
const { attribute: { source }, deserialize } = propDefs[propName]; | ||
if (source === name) { | ||
@@ -79,3 +63,3 @@ elem._syncingAttributeToProperty = propName; | ||
if (target && elem._syncingAttributeToProperty !== target) { | ||
var serialized = serialize(val); | ||
const serialized = serialize(val); | ||
elem._syncingPropertyToAttribute = true; | ||
@@ -82,0 +66,0 @@ if (serialized == null) { |
@@ -11,12 +11,12 @@ "use strict"; | ||
var suffix = 0; | ||
let suffix = 0; | ||
function formatName(prefix, suffix) { | ||
prefix = prefix || "element"; | ||
return (prefix.indexOf("-") === -1 ? "x-" + prefix : prefix) + (suffix ? "-" + suffix : ""); | ||
return (prefix.indexOf("-") === -1 ? `x-${prefix}` : prefix) + (suffix ? `-${suffix}` : ""); | ||
} | ||
function generateName(Ctor) { | ||
var registry = customElements; | ||
var prefix = (0, _index.dashCase)(Ctor.name); | ||
const registry = customElements; | ||
const prefix = (0, _index.dashCase)(Ctor.name); | ||
while (registry.get(formatName(prefix, suffix))) { | ||
@@ -23,0 +23,0 @@ suffix++; |
@@ -8,4 +8,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _preact = require('preact'); | ||
@@ -15,41 +13,15 @@ | ||
var _withRender2 = require('./with-render'); | ||
var _withRender = require('./with-render'); | ||
var _withUnique = require('./with-unique'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var withComponent = exports.withComponent = function withComponent() { | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
return function (_withRender) { | ||
_inherits(_class2, _withRender); | ||
function _class2() { | ||
_classCallCheck(this, _class2); | ||
return _possibleConstructorReturn(this, (_class2.__proto__ || Object.getPrototypeOf(_class2)).apply(this, arguments)); | ||
const withComponent = exports.withComponent = (Base = HTMLElement) => { | ||
return class extends (0, _withRender.withRender)((0, _withUnique.withUnique)((0, _withProps.withProps)(Base))) { | ||
rendererCallback(shadowRoot, renderCallback) { | ||
this._preactDom = (0, _preact.render)(renderCallback(), shadowRoot, this._preactDom || shadowRoot.children[0]); | ||
} | ||
_createClass(_class2, [{ | ||
key: 'rendererCallback', | ||
value: function rendererCallback(shadowRoot, renderCallback) { | ||
this._preactDom = (0, _preact.render)(renderCallback(), shadowRoot, this._preactDom || shadowRoot.children[0]); | ||
} | ||
}]); | ||
return _class2; | ||
}((0, _withRender2.withRender)((0, _withUnique.withUnique)((0, _withProps.withProps)(Base)))); | ||
}; | ||
}; | ||
var Component = exports.Component = withComponent(typeof window === 'undefined' ? function () { | ||
function _class3() { | ||
_classCallCheck(this, _class3); | ||
} | ||
return _class3; | ||
}() : HTMLElement); | ||
const Component = exports.Component = withComponent(typeof window === 'undefined' ? class {} : HTMLElement); | ||
exports.h = _preact.h; |
@@ -7,7 +7,2 @@ "use strict"; | ||
exports.props = exports.withProps = undefined; | ||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
exports.prop = prop; | ||
@@ -19,18 +14,10 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function prop(definition) { | ||
var propertyDefinition = definition || {}; | ||
const propertyDefinition = definition || {}; | ||
// Allows decorators, or imperative definitions. | ||
var func = function func(_ref, name) { | ||
var constructor = _ref.constructor; | ||
const func = function ({ constructor }, name) { | ||
const normalised = (0, _withProps.normalisePropertyDefinition)(name, propertyDefinition); | ||
const _value = (0, _index.sym)(name); | ||
var normalised = (0, _withProps.normalisePropertyDefinition)(name, propertyDefinition); | ||
var _value = (0, _index.sym)(name); | ||
// Cache the value so we can reference when syncing the attribute to the property. | ||
@@ -45,7 +32,7 @@ constructor._props[name] = normalised; | ||
configurable: true, | ||
get: function get() { | ||
var val = this[_value]; | ||
get() { | ||
const val = this[_value]; | ||
return val == null ? normalised.default : val; | ||
}, | ||
set: function set(val) { | ||
set(val) { | ||
this[_value] = normalised.coerce(val); | ||
@@ -59,5 +46,3 @@ (0, _withProps.syncPropertyToAttribute)(this, normalised.attribute.target, normalised.serialize, val); | ||
// Allows easy extension of pre-defined props { ...prop(), ...{} }. | ||
Object.keys(propertyDefinition).forEach(function (key) { | ||
return func[key] = propertyDefinition[key]; | ||
}); | ||
Object.keys(propertyDefinition).forEach(key => func[key] = propertyDefinition[key]); | ||
@@ -67,58 +52,44 @@ return func; | ||
var withProps = exports.withProps = function withProps() { | ||
const withProps = exports.withProps = (Base = HTMLElement) => { | ||
var _class, _temp; | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
return _temp = _class = function (_Base) { | ||
_inherits(_class, _Base); | ||
return _temp = _class = class extends Base { | ||
_createClass(_class, [{ | ||
key: "props", | ||
get: function get() { | ||
var _this2 = this; | ||
static get observedAttributes() { | ||
return this._observedAttributes; | ||
} | ||
return (0, _index.keys)(this.constructor.props).reduce(function (prev, curr) { | ||
prev[curr] = _this2[curr]; | ||
return prev; | ||
}, {}); | ||
}, | ||
set: function set(props) { | ||
var _this3 = this; | ||
static set observedAttributes(attrs) { | ||
this._observedAttributes = this.observedAttributes.concat(attrs); | ||
} | ||
var ctorProps = this.constructor.props; | ||
(0, _index.keys)(props).forEach(function (k) { | ||
return k in ctorProps && (_this3[k] = props[k]); | ||
}); | ||
} | ||
}], [{ | ||
key: "observedAttributes", | ||
get: function get() { | ||
return this._observedAttributes; | ||
}, | ||
set: function set(attrs) { | ||
this._observedAttributes = this.observedAttributes.concat(attrs); | ||
} | ||
}, { | ||
key: "props", | ||
get: function get() { | ||
return this._props; | ||
}, | ||
set: function set(props) { | ||
var _this4 = this; | ||
static get props() { | ||
return this._props; | ||
} | ||
(0, _index.keys)(props).forEach(function (name) { | ||
var func = props[name]; | ||
if (typeof func !== "function") func = prop(func); | ||
func({ constructor: _this4 }, name); | ||
}); | ||
} | ||
}]); | ||
static set props(props) { | ||
(0, _index.keys)(props).forEach(name => { | ||
let func = props[name]; | ||
if (typeof func !== "function") func = prop(func); | ||
func({ constructor: this }, name); | ||
}); | ||
} | ||
function _class() { | ||
_classCallCheck(this, _class); | ||
get props() { | ||
return (0, _index.keys)(this.constructor.props).reduce((prev, curr) => { | ||
prev[curr] = this[curr]; | ||
return prev; | ||
}, {}); | ||
} | ||
var _this = _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this)); | ||
set props(props) { | ||
const ctorProps = this.constructor.props; | ||
(0, _index.keys)(props).forEach(k => k in ctorProps && (this[k] = props[k])); | ||
} | ||
_this._updateCallback = function () { | ||
if (_this._updating || !_this._connected) { | ||
constructor() { | ||
super(); | ||
this._updateCallback = () => { | ||
if (this._updating || !this._connected) { | ||
return; | ||
@@ -129,95 +100,69 @@ } | ||
// queueing a render - while there is a pending render. | ||
_this._updating = true; | ||
this._updating = true; | ||
// Prev / next props for prop lifecycle callbacks. | ||
var prev = _this._prevProps; | ||
var next = _this._prevProps = _this.props; | ||
const prev = this._prevProps; | ||
const next = this._prevProps = this.props; | ||
// Always call set, but only call changed if the props updated. | ||
_this.propsSetCallback(next, prev); | ||
if (_this.propsUpdatedCallback(next, prev)) { | ||
_this.propsChangedCallback(next, prev); | ||
this.propsSetCallback(next, prev); | ||
if (this.propsUpdatedCallback(next, prev)) { | ||
this.propsChangedCallback(next, prev); | ||
} | ||
_this._updating = false; | ||
this._updating = false; | ||
}; | ||
if (_this._constructed) return _possibleConstructorReturn(_this); | ||
_this._constructed = true; | ||
_this._updateDebounced = (0, _index.debounce)(_this._updateCallback); | ||
return _this; | ||
if (this._constructed) return; | ||
this._constructed = true; | ||
this._updateDebounced = (0, _index.debounce)(this._updateCallback); | ||
} | ||
_createClass(_class, [{ | ||
key: "connectedCallback", | ||
value: function connectedCallback() { | ||
if (this._connected) return; | ||
this._connected = true; | ||
// $FlowFixMe - HTMLElement doesn't implement connectedCallback. | ||
if (_get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "connectedCallback", this)) _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "connectedCallback", this).call(this); | ||
this._updateDebounced(); | ||
} | ||
}, { | ||
key: "disconnectedCallback", | ||
value: function disconnectedCallback() { | ||
if (!this._connected) return; | ||
this._connected = false; | ||
// $FlowFixMe - HTMLElement doesn't implement disconnectedCallback. | ||
if (_get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "disconnectedCallback", this)) _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "disconnectedCallback", this).call(this); | ||
} | ||
connectedCallback() { | ||
if (this._connected) return; | ||
this._connected = true; | ||
// $FlowFixMe - HTMLElement doesn't implement connectedCallback. | ||
if (super.connectedCallback) super.connectedCallback(); | ||
this._updateDebounced(); | ||
} | ||
// Called when props actually change. | ||
disconnectedCallback() { | ||
if (!this._connected) return; | ||
this._connected = false; | ||
// $FlowFixMe - HTMLElement doesn't implement disconnectedCallback. | ||
if (super.disconnectedCallback) super.disconnectedCallback(); | ||
} | ||
}, { | ||
key: "propsChangedCallback", | ||
value: function propsChangedCallback() {} | ||
// Called when props actually change. | ||
propsChangedCallback() {} | ||
// Called whenever props are set, even if they don't change. | ||
// Called whenever props are set, even if they don't change. | ||
propsSetCallback() {} | ||
}, { | ||
key: "propsSetCallback", | ||
value: function propsSetCallback() {} | ||
// Called to see if the props changed. | ||
propsUpdatedCallback(next, prev) { | ||
return !prev || (0, _index.keys)(prev).some(k => prev[k] !== next[k]); | ||
} | ||
// Called to see if the props changed. | ||
attributeChangedCallback(name, oldValue, newValue) { | ||
// $FlowFixMe - HTMLElement doesn't implement attributeChangedCallback. | ||
if (super.attributeChangedCallback) super.attributeChangedCallback(name, oldValue, newValue); | ||
(0, _withProps.syncAttributeToProperty)(this, name, newValue); | ||
} | ||
}, { | ||
key: "propsUpdatedCallback", | ||
value: function propsUpdatedCallback(next, prev) { | ||
return !prev || (0, _index.keys)(prev).some(function (k) { | ||
return prev[k] !== next[k]; | ||
}); | ||
} | ||
}, { | ||
key: "attributeChangedCallback", | ||
value: function attributeChangedCallback(name, oldValue, newValue) { | ||
// $FlowFixMe - HTMLElement doesn't implement attributeChangedCallback. | ||
if (_get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "attributeChangedCallback", this)) _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), "attributeChangedCallback", this).call(this, name, oldValue, newValue); | ||
(0, _withProps.syncAttributeToProperty)(this, name, newValue); | ||
} | ||
// Invokes the complete render lifecycle. | ||
}]); | ||
return _class; | ||
}(Base), _class._observedAttributes = [], _class._props = {}, _temp; | ||
// Invokes the complete render lifecycle. | ||
}, _class._observedAttributes = [], _class._props = {}, _temp; | ||
}; | ||
var parse = JSON.parse, | ||
stringify = JSON.stringify; | ||
const { parse, stringify } = JSON; | ||
const attribute = Object.freeze({ source: true }); | ||
const zeroOrNumber = val => (0, _index.empty)(val) ? 0 : Number(val); | ||
var attribute = Object.freeze({ source: true }); | ||
var zeroOrNumber = function zeroOrNumber(val) { | ||
return (0, _index.empty)(val) ? 0 : Number(val); | ||
}; | ||
var any = prop({ | ||
attribute: attribute | ||
const any = prop({ | ||
attribute | ||
}); | ||
var array = prop({ | ||
attribute: attribute, | ||
coerce: function coerce(val) { | ||
return Array.isArray(val) ? val : (0, _index.empty)(val) ? null : [val]; | ||
}, | ||
const array = prop({ | ||
attribute, | ||
coerce: val => Array.isArray(val) ? val : (0, _index.empty)(val) ? null : [val], | ||
default: Object.freeze([]), | ||
@@ -228,26 +173,20 @@ deserialize: parse, | ||
var boolean = prop({ | ||
attribute: attribute, | ||
const boolean = prop({ | ||
attribute, | ||
coerce: Boolean, | ||
default: false, | ||
deserialize: function deserialize(val) { | ||
return !(0, _index.empty)(val); | ||
}, | ||
serialize: function serialize(val) { | ||
return val ? "" : null; | ||
} | ||
deserialize: val => !(0, _index.empty)(val), | ||
serialize: val => val ? "" : null | ||
}); | ||
var number = prop({ | ||
attribute: attribute, | ||
const number = prop({ | ||
attribute, | ||
default: 0, | ||
coerce: zeroOrNumber, | ||
deserialize: zeroOrNumber, | ||
serialize: function serialize(val) { | ||
return (0, _index.empty)(val) ? null : String(Number(val)); | ||
} | ||
serialize: val => (0, _index.empty)(val) ? null : String(Number(val)) | ||
}); | ||
var object = prop({ | ||
attribute: attribute, | ||
const object = prop({ | ||
attribute, | ||
default: Object.freeze({}), | ||
@@ -258,18 +197,16 @@ deserialize: parse, | ||
var string = prop({ | ||
attribute: attribute, | ||
const string = prop({ | ||
attribute, | ||
default: "", | ||
coerce: String, | ||
serialize: function serialize(val) { | ||
return (0, _index.empty)(val) ? null : String(val); | ||
} | ||
serialize: val => (0, _index.empty)(val) ? null : String(val) | ||
}); | ||
var props = exports.props = { | ||
any: any, | ||
array: array, | ||
boolean: boolean, | ||
number: number, | ||
object: object, | ||
string: string | ||
const props = exports.props = { | ||
any, | ||
array, | ||
boolean, | ||
number, | ||
object, | ||
string | ||
}; |
@@ -6,13 +6,4 @@ 'use strict'; | ||
}); | ||
const attachShadowOptions = { mode: 'open' }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var attachShadowOptions = { mode: 'open' }; | ||
function attachShadow(elem) { | ||
@@ -22,42 +13,19 @@ return elem.attachShadow ? elem.attachShadow(attachShadowOptions) : elem; | ||
var withRender = exports.withRender = function withRender() { | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
return function (_Base) { | ||
_inherits(_class2, _Base); | ||
const withRender = exports.withRender = (Base = HTMLElement) => { | ||
return class extends Base { | ||
function _class2() { | ||
_classCallCheck(this, _class2); | ||
get renderRoot() { | ||
this._shadowRoot = this._shadowRoot || (this._shadowRoot = this.shadowRoot || attachShadow(this)); | ||
return this._shadowRoot; | ||
} | ||
return _possibleConstructorReturn(this, (_class2.__proto__ || Object.getPrototypeOf(_class2)).apply(this, arguments)); | ||
propsChangedCallback() { | ||
this.rendererCallback(this.renderRoot, () => this.renderCallback(this)); | ||
this.renderedCallback(); | ||
} | ||
_createClass(_class2, [{ | ||
key: 'propsChangedCallback', | ||
value: function propsChangedCallback() { | ||
var _this2 = this; | ||
this.rendererCallback(this.renderRoot, function () { | ||
return _this2.renderCallback(_this2); | ||
}); | ||
this.renderedCallback(); | ||
} | ||
}, { | ||
key: 'renderCallback', | ||
value: function renderCallback() {} | ||
}, { | ||
key: 'renderedCallback', | ||
value: function renderedCallback() {} | ||
}, { | ||
key: 'rendererCallback', | ||
value: function rendererCallback() {} | ||
}, { | ||
key: 'renderRoot', | ||
get: function get() { | ||
this._shadowRoot = this._shadowRoot || (this._shadowRoot = this.shadowRoot || attachShadow(this)); | ||
return this._shadowRoot; | ||
} | ||
}]); | ||
return _class2; | ||
}(Base); | ||
renderCallback() {} | ||
renderedCallback() {} | ||
rendererCallback() {} | ||
}; | ||
}; |
@@ -8,35 +8,14 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _withUnique = require('./util/with-unique'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
const withUnique = exports.withUnique = (Base = HTMLElement) => { | ||
return class extends Base { | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var withUnique = exports.withUnique = function withUnique() { | ||
var Base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : HTMLElement; | ||
return function (_Base) { | ||
_inherits(_class2, _Base); | ||
function _class2() { | ||
_classCallCheck(this, _class2); | ||
return _possibleConstructorReturn(this, (_class2.__proto__ || Object.getPrototypeOf(_class2)).apply(this, arguments)); | ||
static get is() { | ||
return this._is || (this._is = (0, _withUnique.generateName)(this)); | ||
} | ||
_createClass(_class2, null, [{ | ||
key: 'is', | ||
get: function get() { | ||
return this._is || (this._is = (0, _withUnique.generateName)(this)); | ||
}, | ||
set: function set(is) { | ||
this._is = is; | ||
} | ||
}]); | ||
return _class2; | ||
}(Base); | ||
static set is(is) { | ||
this._is = is; | ||
} | ||
}; | ||
}; |
{ | ||
"name": "skatejs", | ||
"version": "5.0.0-alpha.14", | ||
"version": "5.0.0-alpha.15", | ||
"description": "Skate is a library built on top of the W3C web component specs that enables you to write functional and performant web components with a very small footprint.", | ||
@@ -71,5 +71,5 @@ "license": "MIT", | ||
"scripts": { | ||
"build:es": "babel src --out-dir es --presets=$(pwd)/config/babel.es", | ||
"build:esnext": "babel src --out-dir esnext --presets=$(pwd)/config/babel.esnext", | ||
"build:node": "babel src --out-dir node --presets=$(pwd)/config/babel.node", | ||
"build:es": "babel --no-babelrc src --out-dir es --presets=$(pwd)/config/babel.es", | ||
"build:esnext": "babel --no-babelrc src --out-dir esnext --presets=$(pwd)/config/babel.esnext", | ||
"build:node": "babel --no-babelrc src --out-dir node --presets=$(pwd)/config/babel.node", | ||
"build:umd": "rollup -c && rollup -c --min", | ||
@@ -76,0 +76,0 @@ "commitmsg": "validate-commit-msg", |
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
174315
2654