doz
Version:
A JavaScript framework for building UI, almost like writing in VanillaJS.
1,640 lines (1,330 loc) • 244 kB
JavaScript
// [DOZ] Build version: 3.5.3
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("Doz", [], factory);
else if(typeof exports === 'object')
exports["Doz"] = factory();
else
root["Doz"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 26);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
var _require = __webpack_require__(2),
registerDirective = _require.registerDirective;
function directive(name) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
registerDirective(name, options);
}
module.exports = Object.assign({
directive: directive
}, __webpack_require__(29), __webpack_require__(30));
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = {
COMPONENT_DYNAMIC_INSTANCE: 'componentDynamicInstance',
COMPONENT_INSTANCE: 'componentInstance',
COMPONENT_ROOT_INSTANCE: 'componentRootInstance',
PROPS_ATTRIBUTES: 'props',
ALREADY_WALKED: 'walked',
DEFAULT_SLOT_KEY: '__default__',
NS: {
SVG: 'http://www.w3.org/2000/svg'
},
TAG: {
ROOT: 'dz-root',
EACH: 'dz-each-root',
//not in use
APP: 'dz-app',
EMPTY: 'dz-empty',
MOUNT: 'dz-mount',
SLOT: 'dz-slot',
SLOT_UPPERCASE: 'DZ-SLOT',
SUFFIX_ROOT: '-root',
TEXT_NODE_PLACE: 'dz-text-node',
ITERATE_NODE_PLACE: 'dz-iterate-node'
},
REGEX: {
IS_DIRECTIVE: /^d[-:][\w-]+$/,
IS_CUSTOM_TAG: /^\w+-[\w-]+$/,
IS_CUSTOM_TAG_STRING: /<\w+-[\w-]+/,
IS_LISTENER: /^on/,
IS_ID_SELECTOR: /^#[\w-_:.]+$/,
IS_PARENT_METHOD: /^parent.(.*)/,
IS_STRING_QUOTED: /^"\w+"/,
IS_SVG: /^svg$/,
IS_CLASS: /^(class\s|function\s+_class|function.*[\s\S]+_classCallCheck\(this, .*\))|(throw new TypeError\("Cannot call a class)|(function.*\.__proto__\|\|Object\.getPrototypeOf\(.*?\))|(\)\.call\(this,)|(\).apply\(this,arg)|(for\(var.+=arguments.length)|(\.apply\(this,arguments\))|\.call\(this,?.*?\)/i,
GET_LISTENER: /^this.(.*)\((.*)\)/,
GET_LISTENER_SCOPE: /^scope.(.*)\((.*)\)/,
IS_LISTENER_SCOPE: /(^|\()scope[.)]/g,
TRIM_QUOTES: /^["'](.*)["']$/,
THIS_TARGET: /\B\$this(?!\w)/g,
HTML_MARKUP: /<!--[^]*?(?=-->)-->|<(\/?)([a-z][-.0-9_a-z]*)\s*([^>]*?)(\/?)>/ig,
HTML_ATTRIBUTE: /(^|\s)([\w-:]+)(\s*=\s*("([^"]+)"|'([^']+)'|(\S+)))?/ig,
MATCH_NLS: /\n\s+/gm,
REPLACE_QUOT: /"/g,
REPLACE_D_DIRECTIVE: /^d[-:]/,
EXTRACT_STYLE_DISPLAY_PROPERTY: /display(?:\s+)?:(?:\s+)?([\w-]+)/
},
ATTR: {
// Attributes for both
FORCE_UPDATE: 'forceupdate'
}
};
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var data = __webpack_require__(9);
/**
* Register a component to global
* @param cmp
*/
function registerComponent(cmp) {
var tag = cmp.tag.toUpperCase();
if (Object.prototype.hasOwnProperty.call(data.components, tag)) console.warn('Doz', "component ".concat(tag, " overwritten"));
data.components[tag] = cmp;
}
/**
* Remove all global components
*/
function removeAll() {
data.components = {};
data.plugins = []; //data.directives = {};
}
/**
* Get component from global
* @param tag
* @returns {*}
*/
function getComponent(tag) {
tag = tag.toUpperCase();
return data.components[tag];
}
/**
* Register a plugin to global
* @param plugin
*/
function registerPlugin(plugin) {
data.plugins.push(plugin);
}
/**
* Register a directive to global
* @param name
* @param cfg
*/
function registerDirective(name) {
var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (typeof name !== 'string') {
throw new TypeError('Doz directive name must be a string');
}
if (_typeof(cfg) !== 'object' || !cfg) {
throw new TypeError('Doz directive config must be an object');
}
if (name[0] === ':') {
cfg._onlyDozComponent = true;
name = name.substr(1);
}
name = name.toLowerCase();
var namePart = [];
if (name.indexOf('-') !== -1) {
namePart = name.split('-');
name = namePart[0];
namePart.shift();
}
cfg.name = name;
cfg._keyArguments = namePart.map(function (item) {
return item.substr(1);
}); // remove $
if (Object.prototype.hasOwnProperty.call(data.directives, name)) console.warn('Doz', "directive ".concat(name, " overwritten"));
data.directives[name] = cfg;
if (!data.directivesKeys.includes(name)) data.directivesKeys.push(name);
}
module.exports = {
registerComponent: registerComponent,
registerPlugin: registerPlugin,
getComponent: getComponent,
registerDirective: registerDirective,
removeAll: removeAll,
data: data
};
/***/ }),
/* 3 */
/***/ (function(module, exports) {
var raf = window.requestAnimationFrame || window.setTimeout;
/*const raf = function (cb) {
cb();
};*/
/*function delay(cb) {
return raf(cb);
}*/
module.exports = raf;
/***/ }),
/* 4 */
/***/ (function(module, exports) {
module.exports = function ($target) {
if ($target && !$target._dozAttach) $target._dozAttach = {};
};
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
var _require = __webpack_require__(1),
REGEX = _require.REGEX,
PROPS_ATTRIBUTES = _require.PROPS_ATTRIBUTES;
function extractDirectivesFromProps(cmp) {
//let canBeDeleteProps = true;
var props;
if (!Object.keys(cmp.props).length) {
props = cmp._rawProps; //canBeDeleteProps = false;
} else {
props = cmp.props;
}
var _defined = function _defined(key) {
if (isDirective(key)) {
var keyWithoutD = key.replace(REGEX.REPLACE_D_DIRECTIVE, '');
cmp._directiveProps[keyWithoutD] = props[key];
/*if (canBeDeleteProps)
delete props[key];*/
}
};
var _defined2 = Object.keys(props);
for (var _i2 = 0; _i2 <= _defined2.length - 1; _i2++) {
_defined(_defined2[_i2], _i2, _defined2);
}
return cmp._directiveProps;
}
function isDirective(aName) {
//return REGEX.IS_DIRECTIVE.test(name);
return aName[0] === 'd' && (aName[1] === '-' || aName[1] === ':');
}
function extractStyleDisplayFromDozProps($target) {
if (!$target._dozAttach[PROPS_ATTRIBUTES] || !$target._dozAttach[PROPS_ATTRIBUTES].style) return null;
var match = $target._dozAttach[PROPS_ATTRIBUTES].style.match(REGEX.EXTRACT_STYLE_DISPLAY_PROPERTY);
if (match) {
return match[1];
}
return null;
}
function extractDirectiveNameAndKeyValues(attributeName) {
attributeName = attributeName.replace(REGEX.REPLACE_D_DIRECTIVE, '');
var directiveName = attributeName;
var keyArgumentsValues = [];
if (directiveName.indexOf('-') !== -1) {
keyArgumentsValues = directiveName.split('-');
directiveName = keyArgumentsValues[0];
keyArgumentsValues.shift();
}
return [directiveName, keyArgumentsValues];
}
module.exports = {
isDirective: isDirective,
extractDirectivesFromProps: extractDirectivesFromProps,
extractStyleDisplayFromDozProps: extractStyleDisplayFromDozProps,
extractDirectiveNameAndKeyValues: extractDirectiveNameAndKeyValues
};
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
var delay = __webpack_require__(3);
var directive = __webpack_require__(0);
function callBeforeCreate(context) {
directive.callAppComponentBeforeCreate(context);
directive.callComponentBeforeCreate(context);
if (typeof context.onBeforeCreate === 'function') {
return context.onBeforeCreate.call(context);
}
}
function callCreate(context) {
directive.callAppComponentCreate(context);
directive.callComponentCreate(context);
if (typeof context.onCreate === 'function') {
context.onCreate.call(context);
}
context.app.emit('componentCreate', context);
}
function callConfigCreate(context) {
directive.callAppComponentConfigCreate(context);
if (typeof context.onConfigCreate === 'function') {
context.onConfigCreate.call(context);
}
if (context.parent && typeof context.parent[context.__onConfigCreate] === 'function') {
context.parent[context.__onConfigCreate].call(context.parent, context);
}
context.app.emit('componentConfigCreate', context);
}
function callBeforeMount(context) {
directive.callAppComponentBeforeMount(context);
directive.callComponentBeforeMount(context);
if (typeof context.onBeforeMount === 'function') {
return context.onBeforeMount.call(context);
}
}
function callMount(context) {
directive.callAppComponentMount(context);
directive.callComponentMount(context);
if (typeof context.onMount === 'function') {
context.onMount.call(context);
}
context.app.emit('componentMount', context);
}
function callMountAsync(context) {
delay(function () {
directive.callAppComponentMountAsync(context);
directive.callComponentMountAsync(context);
});
if (typeof context.onMountAsync === 'function') {
delay(function () {
return context.onMountAsync.call(context);
});
}
context.app.emit('componentMountAsync', context);
}
function callBeforeUpdate(context, changes) {
directive.callAppComponentBeforeUpdate(context, changes);
directive.callComponentBeforeUpdate(context, changes);
if (typeof context.onBeforeUpdate === 'function') {
return context.onBeforeUpdate.call(context, changes);
}
}
function callUpdate(context, changes) {
directive.callAppComponentUpdate(context, changes);
directive.callComponentUpdate(context, changes);
if (typeof context.onUpdate === 'function') {
context.onUpdate.call(context, changes);
}
context.app.emit('componentUpdate', context, changes);
}
function callDrawByParent(context, newNode, oldNode) {
if (!context) return;
directive.callAppComponentDrawByParent(context, newNode, oldNode);
if (typeof context.onDrawByParent === 'function') {
return context.onDrawByParent.call(context, newNode, oldNode);
}
if (context.parent && typeof context.parent[context.__onDrawByParent] === 'function') {
return context.parent[context.__onDrawByParent].call(context.parent, context, newNode, oldNode);
} //context.app.emit('componentDrawByParent', context, changes);
}
function callAfterRender(context, changes) {
directive.callAppComponentAfterRender(context, changes);
directive.callComponentAfterRender(context, changes);
if (typeof context.onAfterRender === 'function') {
return context.onAfterRender.call(context, changes);
}
}
function callBeforeUnmount(context) {
directive.callAppComponentBeforeUnmount(context);
directive.callComponentBeforeUnmount(context);
if (typeof context.onBeforeUnmount === 'function') {
return context.onBeforeUnmount.call(context);
}
}
function callUnmount(context) {
directive.callAppComponentUnmount(context);
directive.callComponentUnmount(context);
if (typeof context.onUnmount === 'function') {
context.onUnmount.call(context);
}
context.app.emit('componentUnmount', context);
}
function callBeforeDestroy(context) {
directive.callAppComponentBeforeDestroy(context);
directive.callComponentBeforeDestroy(context);
if (typeof context.onBeforeDestroy === 'function') {
return context.onBeforeDestroy.call(context);
}
}
function callDestroy(context) {
directive.callAppComponentDestroy(context);
directive.callComponentDestroy(context);
context.app.emit('componentDestroy', context);
var style = document.getElementById(context.uId + '--style');
var styleReset = document.getElementById(context.uId + '--style-reset');
if (style) {
style.parentNode.removeChild(style);
}
if (styleReset) {
styleReset.parentNode.removeChild(styleReset);
}
if (context._unmountedPlaceholder && context._unmountedPlaceholder.parentNode) context._unmountedPlaceholder.parentNode.removeChild(context._unmountedPlaceholder);
if (typeof context.onDestroy === 'function') {
context.onDestroy.call(context);
context = null;
}
}
function callLoadProps(context) {
directive.callAppComponentLoadProps(context);
directive.callComponentLoadProps(context);
if (typeof context.onLoadProps === 'function') {
context.onLoadProps.call(context);
}
context.app.emit('componentLoadProps', context);
}
module.exports = {
callBeforeCreate: callBeforeCreate,
callCreate: callCreate,
callConfigCreate: callConfigCreate,
callBeforeMount: callBeforeMount,
callMount: callMount,
callMountAsync: callMountAsync,
callBeforeUpdate: callBeforeUpdate,
callUpdate: callUpdate,
callDrawByParent: callDrawByParent,
callAfterRender: callAfterRender,
callBeforeUnmount: callBeforeUnmount,
callUnmount: callUnmount,
callBeforeDestroy: callBeforeDestroy,
callDestroy: callDestroy,
callLoadProps: callLoadProps
};
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
//const castStringTo = require('../utils/cast-string-to');
var dashToCamel = __webpack_require__(8); //const isListener = require('../utils/is-listener');
var _require = __webpack_require__(1),
REGEX = _require.REGEX,
ATTR = _require.ATTR,
TAG = _require.TAG,
PROPS_ATTRIBUTES = _require.PROPS_ATTRIBUTES;
var regExcludeSpecial = new RegExp("</?(".concat(TAG.TEXT_NODE_PLACE, "|").concat(TAG.ITERATE_NODE_PLACE, ")?>$"));
var directive = __webpack_require__(0);
var _require2 = __webpack_require__(5),
isDirective = _require2.isDirective; //const mapper = require('./mapper');
//const eventsAttributes = require('../utils/events-attributes');
var _require3 = __webpack_require__(10),
tplCache = _require3.tplCache;
var selfClosingElements = {
meta: true,
img: true,
link: true,
input: true,
area: true,
br: true,
hr: true
};
var elementsClosedByOpening = {
li: {
li: true
},
p: {
p: true,
div: true
},
td: {
td: true,
th: true
},
th: {
td: true,
th: true
}
};
var elementsClosedByClosing = {
li: {
ul: true,
ol: true
},
a: {
div: true
},
b: {
div: true
},
i: {
div: true
},
p: {
div: true
},
td: {
tr: true,
table: true
},
th: {
tr: true,
table: true
}
};
function last(arr) {
return arr[arr.length - 1];
}
function removeNLS(str) {
return str.replace(REGEX.MATCH_NLS, '');
}
/*
function removeDoubleQuotes(str) {
if (typeof str === 'string') {
if (str === '""' || str === "''")
return '';
}
return str;
}
*/
var Element = /*#__PURE__*/function () {
function Element(name, props, isSVG, style, styleScoped) {
_classCallCheck(this, Element);
this.type = name;
this.props = props; //Object.assign({}, props);
this.children = [];
if (style) this.style = style;
if (styleScoped) this.styleScoped = styleScoped;
if (isSVG || name === 'svg') this.isSVG = true;
if (props.key !== undefined) this.key = props.key; //this.hasKeys = undefined;
}
_createClass(Element, [{
key: "appendChild",
value: function appendChild(node) {
if (node.props && node.props.key !== undefined) {
this.hasKeys = true;
}
this.children.push(node);
return node;
}
}]);
return Element;
}();
function compile(tpl) {
if (!tpl) return '';
if (tplCache[tpl]) {
return tplCache[tpl];
}
var root = new Element(null, {});
var stack = [root];
var currentParent = root;
var lastTextPos = -1;
var match;
var props; //console.log(tpl)
while (match = REGEX.HTML_MARKUP.exec(tpl)) {
if (lastTextPos > -1) {
if (
/*lastTextPos > -1 && */
lastTextPos + match[0].length < REGEX.HTML_MARKUP.lastIndex) {
// remove new line space
var text = removeNLS(tpl.substring(lastTextPos, REGEX.HTML_MARKUP.lastIndex - match[0].length)); //const text = (data.substring(lastTextPos, REGEX.HTML_MARKUP.lastIndex - match[0].length));
// if has content
if (text) {
//console.log(text)
//let possibleCompiled = mapper.get(text.trim());
//text = placeholderIndex(text, values);
//if (!Array.isArray(text)) {
//console.log(currentParent)
if (currentParent.style === true) {
//console.log('currentParent.style', currentParent.style)
currentParent.style = text; //console.log(currentParent)
} else {
if (text.substr(0, 5) === ' e-0_') text = text.trim();
currentParent.appendChild(text);
}
/*} else {
currentParent.appendChild(text);
}*/
}
}
}
lastTextPos = REGEX.HTML_MARKUP.lastIndex;
if (match[0][1] === '!') {
// this is a comment or style
continue;
} // exclude special text node
if (regExcludeSpecial.test(match[0])) {
continue;
} // transform slot to dz-slot
if (match[2] === 'slot') match[2] = TAG.SLOT;
if (!match[1]) {
// not </ tags
props = {};
for (var attMatch; attMatch = REGEX.HTML_ATTRIBUTE.exec(match[3]);) {
props[attMatch[2]] = attMatch[5] || attMatch[6] || ''; //console.warn(props[attMatch[2]])
propsFixer(match[0].substring(1, match[0].length - 1), attMatch[2], props[attMatch[2]], props, null);
}
if (!match[4] && elementsClosedByOpening[currentParent.type]) {
if (elementsClosedByOpening[currentParent.type][match[2]]) {
stack.pop();
currentParent = last(stack);
}
}
/**/
if (match[2] === 'style') {
currentParent.style = true;
if (props['data-scoped'] === '') {
currentParent.styleScoped = true;
}
continue;
}
currentParent = currentParent.appendChild(new Element(match[2], props, currentParent.isSVG));
stack.push(currentParent);
}
if (match[1] || match[4] || selfClosingElements[match[2]]) {
// </ or /> or <br> etc.
while (true) {
if (currentParent.type === match[2]) {
stack.pop();
currentParent = last(stack);
break;
} else {
// Trying to close current tag, and move on
if (elementsClosedByClosing[currentParent.type]) {
if (elementsClosedByClosing[currentParent.type][match[2]]) {
stack.pop();
currentParent = last(stack);
continue;
}
} // Use aggressive strategy to handle unmatching markups.
break;
}
}
}
}
if (root.style) {
if (_typeof(root.children[0]) === 'object') {
//console.log('root.style', root.style)
root.children[0].style = root.style;
root.children[0].styleScoped = root.styleScoped;
}
}
if (root.children.length > 1) {
root.type = TAG.ROOT; //console.log(root)
} else if (root.children.length) {
tplCache[tpl] = root.children[0];
return root.children[0];
}
tplCache[tpl] = root;
return root;
}
function serializeProps($node) {
var props = {};
if ($node._dozAttach[PROPS_ATTRIBUTES]) {
var keys = Object.keys($node._dozAttach[PROPS_ATTRIBUTES]);
for (var i = 0; i < keys.length; i++) {
propsFixer($node.nodeName, keys[i], $node._dozAttach[PROPS_ATTRIBUTES][keys[i]], props, $node);
}
} else if ($node.attributes) {
var attributes = Array.from($node.attributes);
for (var j = attributes.length - 1; j >= 0; --j) {
var attr = attributes[j];
propsFixer($node.nodeName, attr.name, attr.nodeValue, props, $node);
}
}
return props;
}
function propsFixer(nName, aName, aValue, props, $node) {
if (typeof aValue === 'string' && REGEX.IS_STRING_QUOTED.test(aValue)) aValue = aValue.replace(REGEX.REPLACE_QUOT, '"'); //let isDirective = REGEX.IS_DIRECTIVE.test(aName);
var _isDirective = isDirective(aName); //console.log('isDirective', isDirective, aName, aName[0] === 'd' && (aName[1] === '-' || aName[1] === ':'));
var propsName = REGEX.IS_CUSTOM_TAG.test(nName) && !_isDirective ? dashToCamel(aName) : aName;
if ($node) {
directive.callAppComponentPropsAssignName($node, aName, aValue, _isDirective, props, function (newPropsName) {
propsName = newPropsName;
});
}
/*
if (typeof aValue === 'string' && !mapper.isValidId(aValue) && !isListener(aName)) {
aValue = mapper.getAll(aValue);
} else {
let objValue = mapper.get(aValue);
if (objValue !== undefined) {
aValue = objValue;
}
}*/
//console.log('AFTER :', aName, aValue)
props[propsName] = aName === ATTR.FORCE_UPDATE ? true : aValue;
}
module.exports = {
compile: compile,
serializeProps: serializeProps,
propsFixer: propsFixer,
Element: Element,
removeNLS: removeNLS,
last: last
};
/***/ }),
/* 8 */
/***/ (function(module, exports) {
function dashToCamel(s) {
return s.replace(/(-\w)/g, function (m) {
return m[1].toUpperCase();
});
}
module.exports = dashToCamel;
/***/ }),
/* 9 */
/***/ (function(module, exports) {
module.exports = {
components: {},
webComponents: {
tags: {},
ids: {}
},
plugins: [],
directives: {},
directivesKeys: []
};
/***/ }),
/* 10 */
/***/ (function(module, exports) {
module.exports = {
//kCache: Object.create(null),
kCache: new Map(),
tplCache: Object.create(null),
hCache: new Map()
};
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var _require = __webpack_require__(1),
TAG = _require.TAG,
COMPONENT_ROOT_INSTANCE = _require.COMPONENT_ROOT_INSTANCE,
REGEX = _require.REGEX;
var observer = __webpack_require__(32);
var hooks = __webpack_require__(6);
var update = __webpack_require__(36).updateElement;
var drawDynamic = __webpack_require__(44);
var proxy = __webpack_require__(15);
var toInlineStyle = __webpack_require__(45);
var queueReady = __webpack_require__(46);
var queueDraw = __webpack_require__(47);
var extendInstance = __webpack_require__(48);
var removeAllAttributes = __webpack_require__(49);
var h = __webpack_require__(21);
var loadLocal = __webpack_require__(51);
var localMixin = __webpack_require__(52);
var _require2 = __webpack_require__(7),
compile = _require2.compile;
var propsInit = __webpack_require__(23);
var DOMManipulation = __webpack_require__(53);
var directive = __webpack_require__(0);
var cloneObject = __webpack_require__(55);
var toLiteralString = __webpack_require__(24);
var delay = __webpack_require__(3);
var makeSureAttach = __webpack_require__(4);
var data = __webpack_require__(9); //const mapCompiled = require('../vdom/map-compiled');
var Component = /*#__PURE__*/function (_DOMManipulation) {
_inherits(Component, _DOMManipulation);
var _super = _createSuper(Component);
function Component(opt) {
var _this;
_classCallCheck(this, Component);
_this = _super.call(this, opt);
Object.defineProperty(_assertThisInitialized(_this), '_isSubclass', {
value: _this.__proto__.constructor !== Component
});
Object.defineProperty(_assertThisInitialized(_this), 'uId', {
value: _this.app.generateUId(),
enumerable: true
});
Object.defineProperty(_assertThisInitialized(_this), 'h', {
value: h.bind(_assertThisInitialized(_this)),
enumerable: false
});
_this._initRawProps(opt); // Assign cfg to instance
extendInstance(_assertThisInitialized(_this), opt.cmp.cfg); // Create mixin
localMixin(_assertThisInitialized(_this)); // Load local components
loadLocal(_assertThisInitialized(_this));
var beforeCreate = hooks.callBeforeCreate(_assertThisInitialized(_this));
if (beforeCreate === false) return _possibleConstructorReturn(_this); // Create observer to props
observer.create(_assertThisInitialized(_this), true); // Add callback to ready queue
queueReady.add(_assertThisInitialized(_this)); // Add callback app draw
queueDraw.add(_assertThisInitialized(_this)); // Call create
hooks.callCreate(_assertThisInitialized(_this));
return _this;
}
_createClass(Component, [{
key: "loadProps",
value: function loadProps(props) {
if (_typeof(props) !== 'object') throw new TypeError('Props must be an object');
this._rawProps = Object.assign({}, props);
propsInit(this);
observer.create(this);
hooks.callLoadProps(this);
}
}, {
key: "getHTMLElement",
value: function getHTMLElement() {
return this._parentElement;
}
}, {
key: "beginSafeRender",
value: function beginSafeRender() {
proxy.beginRender(this.props);
}
}, {
key: "endSafeRender",
value: function endSafeRender() {
proxy.endRender(this.props);
}
}, {
key: "each",
value: function each(obj, func) {
var safe = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
//return obj.map(func);
var res;
if (Array.isArray(obj)) {
if (safe) this.beginSafeRender();
/*res = obj.map(func).map((stringEl, i) => {
if (typeof stringEl === 'string') {
return stringEl.trim()
}
}).join('');*/
res = new Array(obj.length);
for (var _i2 = 0; _i2 <= obj.length - 1; _i2++) {
res[_i2] = func(obj[_i2], _i2, obj);
}
if (safe) this.endSafeRender();
}
return res;
} // noinspection JSMethodCanBeStatic
}, {
key: "toStyle",
value: function toStyle(obj) {
var withStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
return toInlineStyle(obj, withStyle);
}
}, {
key: "render",
value: function render(initial) {
var changes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var silentAfterRenderEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (this._renderPause) return;
this.beginSafeRender();
var propsKeys = Object.keys(this.props);
var templateArgs = [this.h];
for (var i = 0; i < propsKeys.length; i++) {
templateArgs.push(this.props[propsKeys[i]]);
}
var template = this.template.apply(this, templateArgs);
this.endSafeRender();
var next = template && _typeof(template) === 'object' ? template : compile(template, this);
this.app.emit('draw', next, this._prev, this);
queueDraw.emit(this, next, this._prev); //console.log(next)
//console.log(this._prev)
var rootElement = update(this._cfgRoot, next, this._prev, 0, this, initial); //Remove attributes from component tag
removeAllAttributes(this._cfgRoot, ['style', 'class'
/*, 'key'*/
]);
if (!this._rootElement && rootElement) {
this._rootElement = rootElement;
makeSureAttach(this._rootElement);
this._parentElement = rootElement.parentNode;
if (this.__hasStyle) this._parentElement.dataset.uid = this.uId;
}
this._prev = next; //console.log(this._prev)
if (!silentAfterRenderEvent) hooks.callAfterRender(this);
drawDynamic(this);
}
}, {
key: "renderPause",
value: function renderPause() {
this._renderPause = true;
}
}, {
key: "renderResume",
value: function renderResume() {
var callRender = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
this._renderPause = false;
if (callRender) this.render();
}
}, {
key: "prepareCommit",
value: function prepareCommit() {
//proxy.disableDOMDelayBegin(this.props);
proxy.pause(this.props);
this.renderPause();
}
}, {
key: "commit",
value: function commit() {
//delay(() => this.renderResume());
this.renderResume();
proxy.resume(this.props); //proxy.disableDOMDelayEnd(this.props);
}
}, {
key: "mount",
value: function mount(template) {
var _this2 = this;
var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (this._unmounted) {
if (hooks.callBeforeMount(this) === false) return this;
this._unmountedPlaceholder.parentNode.replaceChild(this._unmountedParentNode, this._unmountedPlaceholder);
this._unmounted = false;
this._unmountedParentNode = null;
this._unmountedPlaceholder = null;
hooks.callMount(this);
var _defined = function _defined(child) {
_this2.children[child].mount();
};
var _defined2 = Object.keys(this.children);
for (var _i4 = 0; _i4 <= _defined2.length - 1; _i4++) {
_defined(_defined2[_i4], _i4, _defined2);
}
return this;
} else if (template) {
var root = this._rootElement;
if (typeof cfg.selector === 'string') root = root.querySelector(cfg.selector);else if (cfg.selector instanceof HTMLElement) root = cfg.selector;else if (this._rootElement.nodeType !== 1) {
/*const newElement = document.createElement(this.tag + TAG.SUFFIX_ROOT);
newElement._dozAttach = {};
this._rootElement.parentNode.replaceChild(newElement, this._rootElement);
this._rootElement = newElement;
this._rootElement._dozAttach[COMPONENT_ROOT_INSTANCE] = this;
root = this._rootElement;*/
root = this.getHTMLElement();
}
this._unmounted = false;
this._unmountedParentNode = null;
this._unmountedPlaceholder = null;
return this.app.mount(template, root, this);
}
}
}, {
key: "unmount",
value: function unmount() {
var _this3 = this;
var onlyInstance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var byDestroy = arguments.length > 1 ? arguments[1] : undefined;
var silently = arguments.length > 2 ? arguments[2] : undefined;
if (this.lockRemoveInstanceByCallback && typeof this.lockRemoveInstanceByCallback === 'function') {
this.lockRemoveInstanceByCallback(this.unmount, onlyInstance, byDestroy, silently);
return;
}
if (!onlyInstance && (Boolean(this._unmountedParentNode) || !this._rootElement || !this._rootElement.parentNode || !this._rootElement.parentNode.parentNode)) {
return;
}
if (hooks.callBeforeUnmount(this) === false) return false;
this._unmountedParentNode = this._rootElement.parentNode;
this._unmountedPlaceholder = document.createComment(Date.now().toString());
if (!onlyInstance) {
this._rootElement.parentNode.parentNode.replaceChild(this._unmountedPlaceholder, this._unmountedParentNode);
} else if (this._rootElement.parentNode) {
//this._rootElement.parentNode.innerHTML = '';
this._rootElement.parentNode.parentNode.removeChild(this._rootElement.parentNode);
}
this._unmounted = !byDestroy;
if (!silently) hooks.callUnmount(this);
var _defined3 = function _defined3(child) {
_this3.children[child].unmount(onlyInstance, byDestroy, silently);
};
var _defined4 = Object.keys(this.children);
for (var _i6 = 0; _i6 <= _defined4.length - 1; _i6++) {
_defined3(_defined4[_i6], _i6, _defined4);
}
return this;
}
}, {
key: "destroy",
value: function destroy(onlyInstance) {
var _this4 = this;
if (this.lockRemoveInstanceByCallback && typeof this.lockRemoveInstanceByCallback === 'function') {
this.lockRemoveInstanceByCallback(this.destroy, onlyInstance);
return;
}
if (this.unmount(onlyInstance, true) === false) {
return;
}
if (!onlyInstance && (!this._rootElement || hooks.callBeforeDestroy(this) === false
/*|| !this._rootElement.parentNode*/
)) {
return;
}
var _defined5 = function _defined5(child) {
_this4.children[child].destroy();
};
var _defined6 = Object.keys(this.children);
for (var _i8 = 0; _i8 <= _defined6.length - 1; _i8++) {
_defined5(_defined6[_i8], _i8, _defined6);
}
hooks.callDestroy(this);
return true;
} // noinspection JSMethodCanBeStatic
}, {
key: "template",
value: function template() {
return '';
}
}, {
key: "_initTemplate",
value: function _initTemplate(opt) {
if (typeof opt.cmp.cfg.template === 'string' && opt.app.cfg.enableExternalTemplate) {
var contentTpl = opt.cmp.cfg.template;
if (REGEX.IS_ID_SELECTOR.test(contentTpl)) {
opt.cmp.cfg.template = function () {
var contentStr = toLiteralString(document.querySelector(contentTpl).innerHTML);
return eval('`' + contentStr + '`');
};
} else {
opt.cmp.cfg.template = function () {
contentTpl = toLiteralString(contentTpl);
return eval('`' + contentTpl + '`');
};
}
}
}
}, {
key: "_initRawProps",
value: function _initRawProps(opt) {
//console.log(this._isSubclass)
if (!this._isSubclass) {
this._rawProps = Object.assign({}, typeof opt.cmp.cfg.props === 'function' ? opt.cmp.cfg.props() : opt.cmp.cfg.props, opt.props);
this._initTemplate(opt);
} else {
this._rawProps = Object.assign({}, opt.props);
}
Object.defineProperty(this, '_initialProps', {
value: cloneObject(this._rawProps)
});
}
}, {
key: "getDozWebComponentById",
value: function getDozWebComponentById(id) {
return this.getWebComponentById(id);
}
}, {
key: "getDozWebComponentByTag",
value: function getDozWebComponentByTag(name) {
return this.getWebComponentByTag(name);
}
}, {
key: "getWebComponentById",
value: function getWebComponentById(id) {
return data.webComponents.ids[id] || null;
}
}, {
key: "getWebComponentByTag",
value: function getWebComponentByTag(name) {
return data.webComponents.tags[name] || null;
}
}, {
key: "_setProps",
value: function _setProps(obj) {
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
this.props[p] = obj[p];
}
}
}
}, {
key: "setProps",
value: function setProps(obj) {
this.prepareCommit();
this._setProps(obj);
this.commit();
}
}, {
key: "setPropsAsync",
value: function setPropsAsync(obj) {
var _this5 = this;
delay(function () {
return _this5._setProps(obj);
});
}
}, {
key: "props",
set: function set(props) {
if (typeof props === 'function') props = props();
this._rawProps = Object.assign({}, props, this._opt ? this._opt.props : {});
observer.create(this);
directive.callAppComponentSetProps(this);
},
get: function get() {
return this._props;
}
}, {
key: "config",
set: function set(obj) {
if (!this._isSubclass) throw new Error('Config is allowed only for classes');
if (this._configured) throw new Error('Already configured');
if (_typeof(obj) !== 'object') throw new TypeError('Config must be an object');
directive.callAppComponentSetConfig(this, obj);
if (_typeof(obj.mixin) === 'object') {
this.mixin = obj.mixin;
localMixin(this);
}
if (_typeof(obj.components) === 'object') {
this.components = obj.components;
loadLocal(this);
}
if (typeof obj.autoCreateChildren === 'boolean') {
this.autoCreateChildren = obj.autoCreateChildren;
}
if (typeof obj.updateChildrenProps === 'boolean') {
this.updateChildrenProps = obj.updateChildrenProps;
}
this._configured = true;
hooks.callConfigCreate(this);
}
}, {
key: "isRenderPause",
get: function get() {
return this._renderPause;
}
}]);
return Component;
}(DOMManipulation);
module.exports = Component;
module.exports._Component = Component;
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var bind = __webpack_require__(28);
var createInstance = __webpack_require__(13);
var _require = __webpack_require__(1),
TAG = _require.TAG,
REGEX = _require.REGEX,
ALREADY_WALKED = _require.ALREADY_WALKED;
var toLiteralString = __webpack_require__(24);
var plugin = __webpack_require__(25);
var directive = __webpack_require__(0);
var makeSureAttach = __webpack_require__(4);
var Doz = /*#__PURE__*/function () {
function Doz() {
var _this = this;
var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Doz);
this.baseTemplate = "<".concat(TAG.APP, "></").concat(TAG.APP, ">");
if (REGEX.IS_ID_SELECTOR.test(cfg.root)) {
cfg.root = document.getElementById(cfg.root.substring(1));
}
if (REGEX.IS_ID_SELECTOR.test(cfg.template)) {
cfg.template = document.getElementById(cfg.template.substring(1));
cfg.template = cfg.template.innerHTML;
}
if (!(cfg.root instanceof HTMLElement || cfg.root instanceof ShadowRoot)) {
throw new TypeError('root must be an HTMLElement or an valid ID selector like #example-root');
}
if (!(cfg.template instanceof HTMLElement || typeof cfg.template === 'string' || typeof cfg.template === 'function')) {
throw new TypeError('template must be a string or an HTMLElement or a function or an valid ID selector like #example-template');
}
var appNode = document.querySelector(TAG.APP); // This fix double app rendering in SSR
makeSureAttach(appNode);
if (appNode && !appNode._dozAttach[ALREADY_WALKED]) {
appNode.parentNode.removeChild(appNode);
}
this.cfg = Object.assign({}, {
components: [],
shared: {},
useShadowRoot: false,
propsListener: null,
propsListenerAsync: null,
actions: {},
autoDraw: true,
enableExternalTemplate: false
}, cfg);
Object.defineProperties(this, {
_lastUId: {
value: 0,
writable: true
},
_components: {
value: {},
writable: true
},
_usedComponents: {
value: {},
writable: true
},
_cache: {
value: new Map()
},
_onAppReadyCB: {
value: [],
writable: true
},
_callAppReady: {
value: function value() {
var _defined = function _defined(cb) {
if (typeof cb === 'function' && cb._instance) {
cb.call(cb._instance);
}
};
var _defined2 = this._onAppReadyCB;
for (var _i2 = 0; _i2 <= _defined2.length - 1; _i2++) {
_defined(_defined2[_i2], _i2, _defined2);
}
this._onAppReadyCB = [];
}
},
_onAppDrawCB: {
value: [],
writable: true
},
_onAppCB: {
value: {},
writable: true
},
useShadowRoot: {
value: this.cfg.useShadowRoot,
writable: true,
enumerable: true
},
_root: {
value: this.cfg.root
},
appId: {
value: window.DOZ_APP_ID || Math.random().toString(36).substring(2, 15),
enumerable: true
},
action: {
value: bind(this.cfg.actions, this),
enumerable: true
},
shared: {
value: this.cfg.shared,
writable: true,
enumerable: true
},
mount: {
value: function value(template, root) {
var parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this._tree;
if (typeof root === 'string') {
root = document.querySelector(root);
}
root = root || parent._rootElement;
if (!(root instanceof HTMLElement)) {
throw new TypeError('root must be an HTMLElement or an valid selector like #example-root');
}
var contentStr = this.cfg.enableExternalTemplate ? eval('`' + toLiteralString(template) + '`') : template;
var autoCmp = {
tag: TAG.MOUNT,
cfg: {
props: {},
template: function template(h) {
//return h`<${TAG.ROOT}>${contentStr}</${TAG.ROOT}>`;
return contentStr;
}
}
};
return createInstance({
root: root,
template: "<".concat(TAG.MOUNT, "></").concat(TAG.MOUNT, ">"),
app: this,
parentCmp: parent,
autoCmp: autoCmp,
mount: true
});
},
enumerable: true
}
});
if (Array.isArray(this.cfg.components)) {
var _defined3 = function _defined3(cmp) {
if (_typeof(cmp) === 'object' && typeof cmp.tag === 'string' && _typeof(cmp.cfg) === 'object') {
_this._components[cmp.tag] = cmp;
}
};
var _defined4 = this.cfg.components;
for (var _i4 = 0; _i4 <= _defined4.length - 1; _i4++) {
_defined3(_defined4[_i4], _i4, _defined4);
}
} else if (_typeof(this.cfg.components) === 'object') {
var _defined5 = function _defined5(objName) {
_this._components[objName] = {
tag: objName,
cfg: _this.cfg.components[objName]
};
};
var _defined6 = Object.keys(this.cfg.components);
for (var _i6 = 0; _i6 <= _defined6.length - 1; _i6++) {
_defined5(_defined6[_i6], _i6, _defined6);
}
}
this._components[TAG.APP] = {
tag: TAG.APP,
cfg: {
template: typeof cfg.template === 'function' ? cfg.template : function () {
var contentStr = toLiteralString(cfg.template);
if (/\${.*?}/g.test(contentStr)) return eval('`' + contentStr + '`');else return contentStr;
}
}
};
var _defined7 = function _defined7(p) {
if (!['template', 'root'].includes(p)) _this._components[TAG.APP].cfg[p] = cfg[p];
};
var _defined8 = Object.keys(cfg);
for (var _i8 = 0; _i8 <= _defined8.length - 1; _i8++) {
_defined7(_defined8[_i8], _i8, _defined8);
}
plugin