- Linting (ESLint): As per latest ash-nazg

- npm: Update devDeps
This commit is contained in:
Brett Zamir
2020-02-01 20:44:13 +08:00
parent f9f359b98f
commit 33c84d89b8
37 changed files with 1254 additions and 953 deletions

View File

@@ -2,6 +2,8 @@
'use strict';
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
@@ -609,6 +611,7 @@
// to avoid setting through nullish value
var NULLABLES = ['dir', // HTMLElement
'integrity', // script, link
'lang', // HTMLElement
'max', 'min', 'title' // HTMLElement
];
@@ -959,6 +962,52 @@
* should be returned
*/
/**
* @typedef {PlainObject} JamilihOptions
* @property {"root"|"attributeValue"|"fragment"|"children"|"fragmentChildren"} $state
*/
/**
* @param {Element} elem
* @param {string} att
* @param {string} attVal
* @param {JamilihOptions} opts
* @returns {void}
*/
function checkPluginValue(elem, att, attVal, opts) {
opts.$state = 'attributeValue';
if (attVal && _typeof$1(attVal) === 'object') {
var matchingPlugin = getMatchingPlugin(opts, Object.keys(attVal)[0]);
if (matchingPlugin) {
return matchingPlugin.set({
opts: opts,
element: elem,
attribute: {
name: att,
value: attVal
}
});
}
}
return attVal;
}
/**
* @param {JamilihOptions} opts
* @param {string} item
* @returns {JamilihPlugin}
*/
function getMatchingPlugin(opts, item) {
return opts.$plugins && opts.$plugins.find(function (p) {
return p.name === item;
});
}
/**
* Creates an XHTML or HTML element (XHTML is preferred, but only in browsers
* that support); any element after element can be omitted, and any subsequent
@@ -982,7 +1031,7 @@
*/
function _checkAtts(atts) {
var _loop = function _loop() {
for (var _i2 = 0, _Object$entries2 = Object.entries(atts); _i2 < _Object$entries2.length; _i2++) {
var _Object$entries2$_i = _slicedToArray$1(_Object$entries2[_i2], 2),
att = _Object$entries2$_i[0],
attVal = _Object$entries2$_i[1];
@@ -990,14 +1039,17 @@
att = att in ATTR_MAP ? ATTR_MAP[att] : att;
if (NULLABLES.includes(att)) {
attVal = checkPluginValue(elem, att, attVal, opts);
if (!_isNullish(attVal)) {
elem[att] = attVal;
}
return "continue";
continue;
} else if (ATTR_DOM.includes(att)) {
attVal = checkPluginValue(elem, att, attVal, opts);
elem[att] = attVal;
return "continue";
continue;
}
switch (att) {
@@ -1021,10 +1073,12 @@
case '$shadow':
{
var open = attVal.open,
closed = attVal.closed;
var content = attVal.content,
template = attVal.template;
var _attVal = attVal,
open = _attVal.open,
closed = _attVal.closed;
var _attVal2 = attVal,
content = _attVal2.content,
template = _attVal2.template;
var shadowRoot = elem.attachShadow({
mode: closed || open === false ? 'closed' : 'open'
});
@@ -1085,140 +1139,159 @@
case '$define':
{
var localName = elem.localName.toLowerCase(); // Note: customized built-ins sadly not working yet
var _ret = function () {
var localName = elem.localName.toLowerCase(); // Note: customized built-ins sadly not working yet
var customizedBuiltIn = !localName.includes('-'); // We check attribute in case this is a preexisting DOM element
// const {is} = atts;
var customizedBuiltIn = !localName.includes('-'); // We check attribute in case this is a preexisting DOM element
// const {is} = atts;
var is;
var is = void 0;
if (customizedBuiltIn) {
is = elem.getAttribute('is');
if (customizedBuiltIn) {
is = elem.getAttribute('is');
if (!is) {
if (!{}.hasOwnProperty.call(atts, 'is')) {
throw new TypeError('Expected `is` with `$define` on built-in');
}
if (!is) {
if (!{}.hasOwnProperty.call(atts, 'is')) {
throw new TypeError('Expected `is` with `$define` on built-in');
}
opts.$state = 'attributeValue';
elem.setAttribute('is', atts.is);
is = atts.is;
}
}
var def = customizedBuiltIn ? is : localName;
if (customElements.get(def)) {
break;
}
var getConstructor = function getConstructor(cnstrct) {
var baseClass = options && options["extends"] ? doc.createElement(options["extends"]).constructor : customizedBuiltIn ? doc.createElement(localName).constructor : HTMLElement;
return cnstrct ?
/*#__PURE__*/
function (_baseClass) {
_inherits$1(_class, _baseClass);
function _class() {
var _this;
_classCallCheck$1(this, _class);
_this = _possibleConstructorReturn$1(this, _getPrototypeOf$1(_class).call(this));
cnstrct.call(_assertThisInitialized$1(_this));
return _this;
}
return _class;
}(baseClass) :
/*#__PURE__*/
function (_baseClass2) {
_inherits$1(_class2, _baseClass2);
function _class2() {
_classCallCheck$1(this, _class2);
return _possibleConstructorReturn$1(this, _getPrototypeOf$1(_class2).apply(this, arguments));
}
return _class2;
}(baseClass);
};
var cnstrctr, options, mixin;
if (Array.isArray(attVal)) {
if (attVal.length <= 2) {
var _attVal = _slicedToArray$1(attVal, 2);
cnstrctr = _attVal[0];
options = _attVal[1];
if (typeof options === 'string') {
// Todo: Allow creating a definition without using it;
// that may be the only reason to have a string here which
// differs from the `localName` anyways
options = {
"extends": options
};
} else if (options && !{}.hasOwnProperty.call(options, 'extends')) {
mixin = options;
}
if (_typeof$1(cnstrctr) === 'object') {
mixin = cnstrctr;
cnstrctr = getConstructor();
}
} else {
var _attVal2 = _slicedToArray$1(attVal, 3);
cnstrctr = _attVal2[0];
mixin = _attVal2[1];
options = _attVal2[2];
if (typeof options === 'string') {
options = {
"extends": options
};
atts.is = checkPluginValue(elem, 'is', atts.is, opts);
elem.setAttribute('is', atts.is);
is = atts.is;
}
}
} else if (typeof attVal === 'function') {
cnstrctr = attVal;
} else {
mixin = attVal;
cnstrctr = getConstructor();
}
if (!cnstrctr.toString().startsWith('class')) {
cnstrctr = getConstructor(cnstrctr);
}
var def = customizedBuiltIn ? is : localName;
if (!options && customizedBuiltIn) {
options = {
"extends": localName
if (customElements.get(def)) {
return "break";
}
var getConstructor = function getConstructor(cnstrct) {
var baseClass = options && options["extends"] ? doc.createElement(options["extends"]).constructor : customizedBuiltIn ? doc.createElement(localName).constructor : HTMLElement;
/**
* Class wrapping base class.
*/
return cnstrct ?
/*#__PURE__*/
function (_baseClass) {
_inherits$1(_class, _baseClass);
/**
* Calls user constructor.
*/
function _class() {
var _this;
_classCallCheck$1(this, _class);
_this = _possibleConstructorReturn$1(this, _getPrototypeOf$1(_class).call(this));
cnstrct.call(_assertThisInitialized$1(_this));
return _this;
}
return _class;
}(baseClass) :
/*#__PURE__*/
function (_baseClass2) {
_inherits$1(_class2, _baseClass2);
function _class2() {
_classCallCheck$1(this, _class2);
return _possibleConstructorReturn$1(this, _getPrototypeOf$1(_class2).apply(this, arguments));
}
return _class2;
}(baseClass);
};
}
if (mixin) {
Object.entries(mixin).forEach(function (_ref) {
var _ref2 = _slicedToArray$1(_ref, 2),
methodName = _ref2[0],
method = _ref2[1];
var cnstrctr = void 0,
options = void 0,
mixin = void 0;
cnstrctr.prototype[methodName] = method;
});
} // console.log('def', def, '::', typeof options === 'object' ? options : undefined);
if (Array.isArray(attVal)) {
if (attVal.length <= 2) {
var _attVal3 = attVal;
var _attVal4 = _slicedToArray$1(_attVal3, 2);
cnstrctr = _attVal4[0];
options = _attVal4[1];
if (typeof options === 'string') {
// Todo: Allow creating a definition without using it;
// that may be the only reason to have a string here which
// differs from the `localName` anyways
options = {
"extends": options
};
} else if (options && !{}.hasOwnProperty.call(options, 'extends')) {
mixin = options;
}
if (_typeof$1(cnstrctr) === 'object') {
mixin = cnstrctr;
cnstrctr = getConstructor();
}
} else {
var _attVal5 = attVal;
var _attVal6 = _slicedToArray$1(_attVal5, 3);
cnstrctr = _attVal6[0];
mixin = _attVal6[1];
options = _attVal6[2];
if (typeof options === 'string') {
options = {
"extends": options
};
}
}
} else if (typeof attVal === 'function') {
cnstrctr = attVal;
} else {
mixin = attVal;
cnstrctr = getConstructor();
}
if (!cnstrctr.toString().startsWith('class')) {
cnstrctr = getConstructor(cnstrctr);
}
if (!options && customizedBuiltIn) {
options = {
"extends": localName
};
}
if (mixin) {
Object.entries(mixin).forEach(function (_ref) {
var _ref2 = _slicedToArray$1(_ref, 2),
methodName = _ref2[0],
method = _ref2[1];
cnstrctr.prototype[methodName] = method;
});
} // console.log('def', def, '::', typeof options === 'object' ? options : undefined);
customElements.define(def, cnstrctr, _typeof$1(options) === 'object' ? options : undefined);
break;
customElements.define(def, cnstrctr, _typeof$1(options) === 'object' ? options : undefined);
return "break";
}();
if (_ret === "break") break;
}
case '$symbol':
{
var _attVal3 = _slicedToArray$1(attVal, 2),
symbol = _attVal3[0],
func = _attVal3[1];
var _attVal7 = attVal,
_attVal8 = _slicedToArray$1(_attVal7, 2),
symbol = _attVal8[0],
func = _attVal8[1];
if (typeof func === 'function') {
var funcBound = func.bind(elem);
@@ -1354,6 +1427,8 @@
case 'className':
case 'class':
attVal = checkPluginValue(elem, att, attVal, opts);
if (!_isNullish(attVal)) {
elem.className = attVal;
}
@@ -1362,34 +1437,38 @@
case 'dataset':
{
// Map can be keyed with hyphenated or camel-cased properties
var recurse = function recurse(atVal, startProp) {
var prop = '';
var pastInitialProp = startProp !== '';
Object.keys(atVal).forEach(function (key) {
var value = atVal[key];
var _ret2 = function () {
// Map can be keyed with hyphenated or camel-cased properties
var recurse = function recurse(atVal, startProp) {
var prop = '';
var pastInitialProp = startProp !== '';
Object.keys(atVal).forEach(function (key) {
var value = atVal[key];
if (pastInitialProp) {
prop = startProp + key.replace(hyphenForCamelCase, _upperCase).replace(/^([a-z])/, _upperCase);
} else {
prop = startProp + key.replace(hyphenForCamelCase, _upperCase);
}
if (value === null || _typeof$1(value) !== 'object') {
if (!_isNullish(value)) {
elem.dataset[prop] = value;
if (pastInitialProp) {
prop = startProp + key.replace(hyphenForCamelCase, _upperCase).replace(/^([a-z])/, _upperCase);
} else {
prop = startProp + key.replace(hyphenForCamelCase, _upperCase);
}
prop = startProp;
return;
}
if (value === null || _typeof$1(value) !== 'object') {
if (!_isNullish(value)) {
elem.dataset[prop] = value;
}
recurse(value, prop);
});
};
prop = startProp;
return;
}
recurse(attVal, '');
break; // Todo: Disable this by default unless configuration explicitly allows (for security)
recurse(value, prop);
});
};
recurse(attVal, '');
return "break"; // Todo: Disable this by default unless configuration explicitly allows (for security)
}();
if (_ret2 === "break") break;
}
// #if IS_REMOVE
// Don't remove this `if` block (for sake of no-innerHTML build)
@@ -1406,6 +1485,8 @@
case 'htmlFor':
case 'for':
if (elStr === 'label') {
attVal = checkPluginValue(elem, att, attVal, opts);
if (!_isNullish(attVal)) {
elem.htmlFor = attVal;
}
@@ -1413,7 +1494,7 @@
break;
}
opts.$state = 'attributeValue';
attVal = checkPluginValue(elem, att, attVal, opts);
elem.setAttribute(att, attVal);
break;
@@ -1424,12 +1505,15 @@
default:
{
if (att.startsWith('on')) {
attVal = checkPluginValue(elem, att, attVal, opts);
elem[att] = attVal; // _addEvent(elem, att.slice(2), attVal, false); // This worked, but perhaps the user wishes only one event
break;
}
if (att === 'style') {
attVal = checkPluginValue(elem, att, attVal, opts);
if (_isNullish(attVal)) {
break;
}
@@ -1455,7 +1539,6 @@
} // setAttribute unfortunately erases any existing styles
opts.$state = 'attributeValue';
elem.setAttribute(att, attVal);
/*
// The following reorders which is troublesome for serialization, e.g., as used in our testing
@@ -1469,9 +1552,7 @@
break;
}
var matchingPlugin = opts.$plugins && opts.$plugins.find(function (p) {
return p.name === att;
});
var matchingPlugin = getMatchingPlugin(opts, att);
if (matchingPlugin) {
matchingPlugin.set({
@@ -1485,17 +1566,11 @@
break;
}
opts.$state = 'attributeValue';
attVal = checkPluginValue(elem, att, attVal, opts);
elem.setAttribute(att, attVal);
break;
}
}
};
for (var _i2 = 0, _Object$entries2 = Object.entries(atts); _i2 < _Object$entries2.length; _i2++) {
var _ret = _loop();
if (_ret === "continue") continue;
}
}
@@ -1673,7 +1748,8 @@
break;
case '':
nodes[nodes.length] = elem = doc.createDocumentFragment();
nodes[nodes.length] = elem = doc.createDocumentFragment(); // Todo: Report to plugins
opts.$state = 'fragment';
break;
@@ -1701,7 +1777,8 @@
elem = doc.createElementNS(NS_HTML, elStr);
} else {
elem = doc.createElement(elStr);
}
} // Todo: Report to plugins
opts.$state = 'element';
nodes[nodes.length] = elem; // Add to parent
@@ -1733,7 +1810,8 @@
elem = nodes[nodes.length - 1] = new win.DOMParser().parseFromString(new win.XMLSerializer().serializeToString(elem) // Mozilla adds XHTML namespace
.replace(' xmlns="' + NS_HTML + '"', replacer), 'application/xml').documentElement;
.replace(' xmlns="' + NS_HTML + '"', replacer), 'application/xml').documentElement; // Todo: Report to plugins
opts.$state = 'element'; // }catch(e) {alert(elem.outerHTML);throw e;}
}
@@ -1751,7 +1829,8 @@
*/
if (i === 0) {
// Allow wrapping of element, fragment, or document
elem = arg;
elem = arg; // Todo: Report to plugins
opts.$state = 'element';
}
@@ -1810,7 +1889,9 @@
_appendNode(elem, jml(opts, childContent['#']));
} else {
// Single DOM element children
_appendNode(elem, childContent);
var newChildContent = checkPluginValue(elem, null, childContent, opts);
_appendNode(elem, newChildContent);
}
break;
@@ -1867,11 +1948,23 @@
function invalidStateError(msg) {
// These are probably only necessary if working with text/html
// eslint-disable-next-line no-shadow, unicorn/custom-error-definition
/* eslint-disable no-shadow, unicorn/custom-error-definition */
/**
* Polyfill for `DOMException`.
*/
var DOMException =
/*#__PURE__*/
function (_Error) {
_inherits$1(DOMException, _Error);
/* eslint-enable no-shadow, unicorn/custom-error-definition */
/**
* @param {string} message
* @param {string} name
*/
function DOMException(message, name) {
var _this2;
@@ -2267,6 +2360,10 @@
// Alias for jml.toXML for parity with jml.toJMLString
return jml.toXML.apply(jml, arguments);
};
/**
* Element-aware wrapper for `Map`.
*/
var JamilihMap =
/*#__PURE__*/
@@ -2281,16 +2378,34 @@
_createClass(JamilihMap, [{
key: "get",
/**
* @param {string|Element} elem
* @returns {any}
*/
value: function get(elem) {
elem = typeof elem === 'string' ? $(elem) : elem;
return _get(_getPrototypeOf$1(JamilihMap.prototype), "get", this).call(this, elem);
}
/**
* @param {string|Element} elem
* @param {any} value
* @returns {any}
*/
}, {
key: "set",
value: function set(elem, value) {
elem = typeof elem === 'string' ? $(elem) : elem;
return _get(_getPrototypeOf$1(JamilihMap.prototype), "set", this).call(this, elem, value);
}
/**
* @param {string|Element} elem
* @param {string} methodName
* @param {...any} args
* @returns {any}
*/
}, {
key: "invoke",
value: function invoke(elem, methodName) {
@@ -2308,6 +2423,10 @@
return JamilihMap;
}(_wrapNativeSuper$1(Map));
/**
* Element-aware wrapper for `WeakMap`.
*/
var JamilihWeakMap =
/*#__PURE__*/
@@ -2322,16 +2441,34 @@
_createClass(JamilihWeakMap, [{
key: "get",
/**
* @param {string|Element} elem
* @returns {any}
*/
value: function get(elem) {
elem = typeof elem === 'string' ? $(elem) : elem;
return _get(_getPrototypeOf$1(JamilihWeakMap.prototype), "get", this).call(this, elem);
}
/**
* @param {string|Element} elem
* @param {any} value
* @returns {any}
*/
}, {
key: "set",
value: function set(elem, value) {
elem = typeof elem === 'string' ? $(elem) : elem;
return _get(_getPrototypeOf$1(JamilihWeakMap.prototype), "set", this).call(this, elem, value);
}
/**
* @param {string|Element} elem
* @param {string} methodName
* @param {...any} args
* @returns {any}
*/
}, {
key: "invoke",
value: function invoke(elem, methodName) {
@@ -3298,17 +3435,19 @@
value: svgURL
},
$on: {
click: function () {
var _click = _asyncToGenerator(
click: function click(e) {
var _this = this;
return _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee2(e) {
regeneratorRuntime.mark(function _callee2() {
var svgurl, post, result, svg;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
e.preventDefault();
svgurl = this.dataset.value; // console.log('this', id, svgurl);
svgurl = _this.dataset.value; // console.log('this', id, svgurl);
post = function post(message) {
// Todo: Make origin customizable as set by opening window
@@ -3344,15 +3483,9 @@
return _context2.stop();
}
}
}, _callee2, this);
}));
function click(_x2) {
return _click.apply(this, arguments);
}
return click;
}()
}, _callee2);
}))();
}
}
}, [// If we wanted interactive versions despite security risk:
// ['object', {data: svgURL, type: 'image/svg+xml'}]
@@ -3429,8 +3562,8 @@
jml('div', [['style', [".control {\n padding-top: 10px;\n }"]], ['form', {
id: 'openclipart',
$custom: {
$submit: function () {
var _$submit = _asyncToGenerator(
$submit: function $submit() {
return _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
var url;
@@ -3455,14 +3588,8 @@
}
}
}, _callee);
}));
function $submit() {
return _$submit.apply(this, arguments);
}
return $submit;
}()
}))();
}
},
$on: {
submit: function submit(e) {