@uicapivara/cp-select
Version:
cp-select
1,041 lines (1,004 loc) • 775 kB
JavaScript
/******/ (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, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // 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 = "/dist/";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "../src/index.ts");
/******/ })
/************************************************************************/
/******/ ({
/***/ "../node_modules/capivarajs/package.json":
/*!***********************************************!*\
!*** ../node_modules/capivarajs/package.json ***!
\***********************************************/
/*! exports provided: _from, _id, _inBundle, _integrity, _location, _phantomChildren, _requested, _requiredBy, _resolved, _shasum, _spec, _where, author, bugs, bundleDependencies, dependencies, deprecated, description, devDependencies, homepage, keywords, license, main, name, nyc, repository, scripts, version, default */
/***/ (function(module) {
module.exports = {"_from":"capivarajs@^3.9.1","_id":"capivarajs@3.9.1","_inBundle":false,"_integrity":"sha512-u1muHI3pG0TPmS0EUZ5kcRxZVNhtE7tthz8ayhvCywp6EAHplSAVYBcqEKyw5+Pwf1IRVg3JTaBiMUQM9oI5sg==","_location":"/capivarajs","_phantomChildren":{},"_requested":{"type":"range","registry":true,"raw":"capivarajs@^3.9.1","name":"capivarajs","escapedName":"capivarajs","rawSpec":"^3.9.1","saveSpec":null,"fetchSpec":"^3.9.1"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/capivarajs/-/capivarajs-3.9.1.tgz","_shasum":"eecd82f44fdb512533ef5abd4b33378f9ef6e9e7","_spec":"capivarajs@^3.9.1","_where":"/home/jcanabarro/Desktop/cp-select","author":{"name":"Capivara Team."},"bugs":{"url":"https://github.com/CapivaraJS/capivarajs/issues"},"bundleDependencies":false,"dependencies":{"lodash":"^4.17.5","melanke-watchjs":"^1.4.3"},"deprecated":false,"description":"Um framework para criação de componentes.","devDependencies":{"@babel/core":"^7.0.0-beta.42","@babel/preset-env":"^7.0.0-beta.42","@types/jasmine":"^2.6.3","@types/node":"^10.0.3","babel-loader":"^7.1.4","babel-polyfill":"^6.26.0","babel-preset-stage-0":"^6.24.1","codecov":"^3.0.0","css-loader":"^1.0.0","eslint":"^4.19.1","extract-text-webpack-plugin":"^4.0.0-beta.0","file-loader":"^1.1.5","html-loader":"^0.5.1","jasmine":"^3.1.0","jasmine-core":"^3.1.0","karma":"^2.0.2","karma-cli":"^1.0.1","karma-es6-shim":"^1.0.0","karma-jasmine":"^1.1.1","karma-phantomjs-launcher":"^1.0.4","karma-typescript":"^3.0.12","nightwatch":"^0.9.20","node-sass":"^4.7.2","nyc":"^12.0.1","style-loader":"^0.21.0","ts-loader":"^4.1.0","tslint":"^5.9.1","typescript":"^2.7.2","uglifyjs-webpack-plugin":"^1.1.2","weakset":"^1.0.0","webpack":"^4.8.1","webpack-cli":"^2.1.3","webpack-dev-server":"^3.1.1","webpack-merge":"^4.1.2"},"homepage":"https://github.com/CapivaraJS/capivarajs#readme","keywords":["frameworkjs","web components","front end","documentation","components","gumga","capivara","capivarajs","js","javascript","framework"],"license":"MIT","main":"./src/index.ts","name":"capivarajs","nyc":{"include":["src/*.ts","src/**/*.ts"],"exclude":["typings"],"extension":[".ts",".js"],"reporter":["json","html"],"all":true},"repository":{"url":"git+https://github.com/CapivaraJS/capivarajs.git","type":"git"},"scripts":{"coverage":"npm run generate-report && nyc report --reporter=text-lcov > coverage.lcov && codecov","dev":"webpack-dev-server --config ./config/webpack.dev.js","e2e":"webpack-dev-server --config ./config/webpack.dev.js --t true","generate-report":"nyc --report-dir coverage npm run test && nyc report --reporter=text","prod":"npm run test-single && webpack --config ./config/webpack.dev.js && webpack --config ./config/webpack.prod.js","test":"karma start","test-single":"karma start --single-run"},"version":"3.9.1"};
/***/ }),
/***/ "../node_modules/capivarajs/src/common.ts":
/*!************************************************!*\
!*** ../node_modules/capivarajs/src/common.ts ***!
\************************************************/
/*! exports provided: Common */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Common", function() { return Common; });
/* harmony import */ var ___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ */ "../node_modules/capivarajs/src/index.ts");
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "../node_modules/capivarajs/src/constants.ts");
/* harmony import */ var _core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./core */ "../node_modules/capivarajs/src/core/index.ts");
var Common;
(function (Common) {
function regexIndexOf(str, regex, startPos) {
var indexOf = str.substring(startPos || 0).search(regex);
return (indexOf >= 0) ? (indexOf + (startPos || 0)) : indexOf;
}
Common.regexIndexOf = regexIndexOf;
/**
* @description Executa o eval alterando as propriedades do source para seus determinados valores dentro do contexto.
* @param source
* @param context
* @param prefix
*/
function evalInContext(source, context, test) {
if (source) {
try {
return _core__WEBPACK_IMPORTED_MODULE_2__["Eval"].exec(source, context, test);
}
catch (e) { }
}
}
Common.evalInContext = evalInContext;
function getFirstKey(str) {
var firstKey = (str.indexOf('.') !== -1 ? str.substring(0, str.indexOf('.')) : str).replace(/ /g, '');
return firstKey.split('(').join('').split(')').join('').replace(/!/g, '');
}
Common.getFirstKey = getFirstKey;
function getAttributeCpShow(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].SHOW_ATTRIBUTE_NAME);
}
Common.getAttributeCpShow = getAttributeCpShow;
function getAttributeCpIf(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].IF_ATTRIBUTE_NAME);
}
Common.getAttributeCpIf = getAttributeCpIf;
function getAttributeCpElseIf(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].ELSE_IF_ATTRIBUTE_NAME);
}
Common.getAttributeCpElseIf = getAttributeCpElseIf;
function getAttributeCpElse(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].ELSE_ATTRIBUTE_NAME);
}
Common.getAttributeCpElse = getAttributeCpElse;
function getAttributeCpInit(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].INIT_ATTRIBUTE_NAME);
}
Common.getAttributeCpInit = getAttributeCpInit;
function getAttributeCpStyle(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].STYLE_ATTRIBUTE_NAME);
}
Common.getAttributeCpStyle = getAttributeCpStyle;
function getAttributeCpClass(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].CLASS_ATTRIBUTE_NAME);
}
Common.getAttributeCpClass = getAttributeCpClass;
function getAttributeCpSrc(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].SRC_ATTRIBUTE_NAME);
}
Common.getAttributeCpSrc = getAttributeCpSrc;
function getAttributeCpDisable(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].DISABLE_ATTRIBUTE_NAME);
}
Common.getAttributeCpDisable = getAttributeCpDisable;
function getAttributeCpFocus(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].FOCUS_ATTRIBUTE_NAME);
}
Common.getAttributeCpFocus = getAttributeCpFocus;
function getAttributeCpHide(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].HIDE_ATTRIBUTE_NAME);
}
Common.getAttributeCpHide = getAttributeCpHide;
function getAttributeCpBlur(element) {
return element.getAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].BLUR_ATTRIBUTE_NAME);
}
Common.getAttributeCpBlur = getAttributeCpBlur;
function getScope(element) {
return element[_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].SCOPE_ATTRIBUTE_NAME];
}
Common.getScope = getScope;
function isComponent(element) {
var component = window['capivara'].components[element.nodeName.toUpperCase()];
return component ? true : false;
}
Common.isComponent = isComponent;
function insideComponent(element) {
if (element && element.parentNode) {
if (isComponent(element.parentNode)) {
return true;
}
else {
return insideComponent(element.parentNode);
}
}
return false;
}
Common.insideComponent = insideComponent;
function executeFunctionCallback(element, attribute, additionalParameters) {
return evalInMultiContext(element, attribute, additionalParameters);
}
Common.executeFunctionCallback = executeFunctionCallback;
function isNative(fn) {
return /{\s*\[native code]\s*}/.test('' + fn);
}
Common.isNative = isNative;
function destroyElement(element, elementComment) {
element.$$cpDestroyed = true;
if (element.replaceWith) {
element.replaceWith(elementComment);
}
___WEBPACK_IMPORTED_MODULE_0__["default"].destroyIfComponent(element);
}
Common.destroyElement = destroyElement;
function createElement(element, elementComment) {
element.$$cpDestroyed = false;
if (elementComment.replaceWith) {
elementComment.replaceWith(element);
}
___WEBPACK_IMPORTED_MODULE_0__["default"].constroyIfComponent(element, true);
}
Common.createElement = createElement;
function getAllScopes(element, scopes) {
if (element && element[_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].SCOPE_ATTRIBUTE_NAME]) {
scopes.add(element[_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].SCOPE_ATTRIBUTE_NAME].scope);
}
if (element && element.parentNode) {
return getAllScopes(element.parentNode, scopes);
}
return scopes;
}
Common.getAllScopes = getAllScopes;
function evalInMultiContext(element, condition, additionalParameters, test) {
var scopes = Array.from(getAllScopes(element, new Set())).reverse();
if (additionalParameters) {
scopes.push(additionalParameters);
}
return evalInContext(condition, scopes, test);
}
Common.evalInMultiContext = evalInMultiContext;
function isValidCondition(element, condition) {
return evalInMultiContext(element, condition);
}
Common.isValidCondition = isValidCondition;
function appendBefore(element, elementToInsert) {
element.parentNode.insertBefore(elementToInsert, element);
}
Common.appendBefore = appendBefore;
function appendAfter(element, elementToInsert) {
element.parentNode.insertBefore(elementToInsert, element.nextSibling);
}
Common.appendAfter = appendAfter;
function setScopeId(scope) {
if (!scope.id) {
___WEBPACK_IMPORTED_MODULE_0__["default"].LAST_SCOPE_ID++;
window['capivara'].scopes.push(scope);
scope.id = ___WEBPACK_IMPORTED_MODULE_0__["default"].LAST_SCOPE_ID;
}
}
Common.setScopeId = setScopeId;
function parentHasIgnore(element) {
if (element.hasAttribute && (element.hasAttribute(_constants__WEBPACK_IMPORTED_MODULE_1__["Constants"].IGNORE_BINDINGS) || element.nodeName === 'CP-TRANSCLUDE')) {
return true;
}
if (element.parentNode) {
return parentHasIgnore(element.parentNode);
}
}
Common.parentHasIgnore = parentHasIgnore;
function getFunctionArgs(func) {
return (func + '')
.replace(/[/][/].*$/mg, '') // strip single-line comments
.replace(/\s+/g, '') // strip white space
.replace(/[/][*][^/*]*[*][/]/g, '') // strip multi-line comments
.split('){', 1)[0].replace(/^[^(]*[(]/, '') // extract the parameters
.replace(/=[^,]+/g, '') // strip any ES6 defaults
.split(',').filter(Boolean); // split & filter [""]
}
Common.getFunctionArgs = getFunctionArgs;
function deepText(node) {
var A = [];
if (node) {
node = node.firstChild;
while (node != null) {
if (node.nodeType === 3) {
A[A.length] = node;
}
else {
A = A.concat(deepText(node));
}
node = node.nextSibling;
}
}
return A;
}
Common.deepText = deepText;
})(Common || (Common = {}));
/***/ }),
/***/ "../node_modules/capivarajs/src/constants.ts":
/*!***************************************************!*\
!*** ../node_modules/capivarajs/src/constants.ts ***!
\***************************************************/
/*! exports provided: Constants */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Constants", function() { return Constants; });
var Constants = {
SCOPE_ATTRIBUTE_NAME: '$scope',
EVENT_ATTRIBUTE_NAME: '$event',
REPEAT_ATTRIBUTE_NAME: 'cp-repeat',
REPEAT_INDEX_NAME: '$index',
REPEAT_ATTRIBUTE_OPERATOR: 'in',
MODEL_ATTRIBUTE_NAME: 'cp-model',
CLICK_ATTRIBUTE_NAME: 'cp-click',
DBLCLICK_ATTRIBUTE_NAME: 'cp-dblclick',
SHOW_ATTRIBUTE_NAME: 'cp-show',
IF_ATTRIBUTE_NAME: 'cp-if',
STEP_ATTRIBUTE_NAME: 'cp-step',
MAX_ATTRIBUTE_NAME: 'cp-max',
MAX_LENGTH_ATTRIBUTE_NAME: 'cp-maxlength',
MIN_ATTRIBUTE_NAME: 'cp-min',
ELSE_ATTRIBUTE_NAME: 'cp-else',
ELSE_IF_ATTRIBUTE_NAME: 'cp-else-if',
INIT_ATTRIBUTE_NAME: 'cp-init',
STYLE_ATTRIBUTE_NAME: 'cp-style',
CLASS_ATTRIBUTE_NAME: 'cp-class',
SRC_ATTRIBUTE_NAME: 'cp-src',
KEY_ATTRIBUTE_NAME: 'cp-key',
ATTR_ATTRIBUTE_NAME: 'cp-attr',
DISABLE_ATTRIBUTE_NAME: 'cp-disabled',
START_INTERPOLATION: '[[',
END_INTERPOLATION: ']]',
IGNORE_BINDINGS: 'cp-non-bindable',
FOCUS_ATTRIBUTE_NAME: 'cp-focus',
HIDE_ATTRIBUTE_NAME: 'cp-hide',
BLUR_ATTRIBUTE_NAME: 'cp-blur',
TITLE_ATTRIBUTE_NAME: 'cp-title',
PLACEHOLDER_ATTRIBUTE_NAME: 'cp-placeholder',
MOUSE_ATTRIBUTE_NAME: 'cp-mouse',
CHANGE_ATTRIBUTE_NAME: 'cp-change',
};
/***/ }),
/***/ "../node_modules/capivarajs/src/core/capivara.instance.ts":
/*!****************************************************************!*\
!*** ../node_modules/capivarajs/src/core/capivara.instance.ts ***!
\****************************************************************/
/*! exports provided: CapivaraInstance */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CapivaraInstance", function() { return CapivaraInstance; });
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "../node_modules/capivarajs/src/constants.ts");
/* harmony import */ var _scope_scope__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../scope/scope */ "../node_modules/capivarajs/src/scope/scope.ts");
/* harmony import */ var _component__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./component */ "../node_modules/capivarajs/src/core/component.ts");
/* harmony import */ var _component_instance__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./component.instance */ "../node_modules/capivarajs/src/core/component.instance.ts");
var packageJson = __webpack_require__(/*! ../../package.json */ "../node_modules/capivarajs/package.json");
var CapivaraInstance = /** @class */ (function () {
function CapivaraInstance() {
var _this = this;
this.LAST_SCOPE_ID = 0;
this.DOMMutation = window['MutationObserver'] || window['WebKitMutationObserver'] || window['MozMutationObserver'];
this.version = packageJson.version;
this.components = {};
this.scopes = [];
this.$watchers = [];
if (!Element.prototype.hasOwnProperty('getAttributeStartingWith')) {
Object.defineProperty(Element.prototype, 'getAttributeStartingWith', {
value: function hasAttributeStartingWith(attr) {
return Array.from(this.attributes).filter(function (attributeNode) {
return attributeNode.nodeName.indexOf(attr) === 0;
});
},
configurable: true,
});
}
if (!Element.prototype.hasOwnProperty('hasAttributeStartingWith')) {
Object.defineProperty(Element.prototype, 'hasAttributeStartingWith', {
value: function hasAttributeStartingWith(attr) {
return this.getAttributeStartingWith(attr).length > 0;
},
configurable: true,
});
}
if (document.readyState === 'complete' ||
(document.readyState !== 'loading' && !document.documentElement['doScroll'])) {
setTimeout(function () {
_this.createListeners();
_this.createComponents();
});
}
else {
document.addEventListener("DOMContentLoaded", function (event) {
_this.createListeners();
_this.createComponents();
});
}
}
CapivaraInstance.prototype.createComponents = function () {
var _this = this;
Object.keys(this.components).forEach(function (componentName) {
var elms = document.querySelectorAll(componentName) || [];
Array.from(elms).forEach(function (elm) {
_this.constroyIfComponent(elm);
});
});
};
CapivaraInstance.prototype.hasRepeat = function (elm) {
return elm && elm.classList && elm.classList.contains('binding-repeat');
};
CapivaraInstance.prototype.constroyIfComponent = function (addedNode, forceCreated) {
var _this = this;
var component = this.components[addedNode.nodeName];
if (component && (forceCreated || !addedNode.created)) {
addedNode.created = true;
component.createNewInstance(addedNode).create();
}
if (addedNode.children && (forceCreated || !this.hasRepeat(addedNode))) {
(Array.from(addedNode.children) || []).forEach(function (child) {
_this.constroyIfComponent(child, forceCreated);
});
}
};
CapivaraInstance.prototype.destroyIfComponent = function (removedNode) {
var _this = this;
removedNode.created = false;
if (removedNode['$instance'] && !removedNode['$instance'].destroyed) {
removedNode['$instance'].destroy();
}
if (removedNode.children) {
(Array.from(removedNode.children) || []).forEach(function (child) { return _this.destroyIfComponent(child); });
}
};
CapivaraInstance.prototype.onMutation = function (mutations) {
var _this = this;
(mutations || []).forEach(function (mutation) {
if (mutation.type === 'childList') {
((mutation && mutation.addedNodes && mutation.addedNodes.forEach) ? mutation.addedNodes : []).forEach(function (addedNode) {
_this.constroyIfComponent(addedNode);
});
((mutation && mutation.removedNodes && mutation.removedNodes.forEach) ? mutation.removedNodes : []).forEach(function (removedNode) {
_this.destroyIfComponent(removedNode);
});
}
});
};
CapivaraInstance.prototype.createListeners = function () {
var _this = this;
if (this.DOMMutation) {
var observer = new this.DOMMutation(function (mutations) { return _this.onMutation(mutations); });
observer.observe(document.body, {
attributes: false,
childList: true,
subtree: true,
characterData: false,
});
}
};
/**
* @name capivara.component
* @description Registra um novo componente capivara
*/
CapivaraInstance.prototype.component = function (componentName, config) {
if (window["capivara"].components[componentName]) {
console.error("A registered component with this name already exists.");
return;
}
window["capivara"].components[componentName.toUpperCase()] = new _component__WEBPACK_IMPORTED_MODULE_2__["Component"](componentName, config);
};
/**
* @name capivara.componentBuilder
* @description Faz a inicialização de um componente.
*/
CapivaraInstance.prototype.componentBuilder = function (hashName) {
return new Promise(function (resp) {
var elms = window["capivara"].isElement(hashName) ? [hashName] : Array.from(document.querySelectorAll("[\\#" + hashName + "]"));
if (elms.length === 0) {
console.error("CapivaraJS did not find its component with the hash " + hashName);
}
var instance;
var findElementAndCreateInstance = function () {
elms = window["capivara"].isElement(hashName) ? [hashName] : Array.from(document.querySelectorAll("[\\#" + hashName + "]"));
(elms || []).forEach(function (elm) {
var component = window["capivara"].components[elm.nodeName];
if (!component) {
console.error("We did not find a registered entry under the name: " + elm.nodeName);
return;
}
if (!instance) {
instance = elm['$instance'];
}
});
return instance;
};
setTimeout(function () {
var componentInstance = findElementAndCreateInstance();
resp(componentInstance);
});
});
};
/**
* @name capivara.controller
* @description Cria um novo controller para fazer manipulação de um determinado elemento.
*/
CapivaraInstance.prototype.controller = function (elm, callback) {
new _component_instance__WEBPACK_IMPORTED_MODULE_3__["ComponentInstance"](elm, { controller: callback }).create();
};
/**
* @name capivara,isArray
* @description Verifica se um valor é um Array.
*/
CapivaraInstance.prototype.isArray = function (value) {
return Array.isArray(value) || value instanceof Array;
};
/**
* @name capivara,isObject
* @description Verifica se um valor é um Objeto.
*/
CapivaraInstance.prototype.isObject = function (value) {
return value !== null && typeof value === "object";
};
CapivaraInstance.prototype.isObjectConstructor = function (obj) {
if (!obj) {
return false;
}
return obj.__proto__.constructor.name === 'Object';
};
/**
* @name capivara,isDate
* @description Verifica se um valor é uma Data.
*/
CapivaraInstance.prototype.isDate = function (value) {
return toString.call(value) === "[object Date]";
};
/**
* @name capivara,isElement
* @description Verifica se um valor é um NodeElement.
*/
CapivaraInstance.prototype.isElement = function (value) {
return !!(value &&
(value.nodeName // We are a direct element.
|| (value.prop && value.attr && value.find)));
};
/**
* @name capivara,isFunction
* @description Verifica se um valor é uma função.
*/
CapivaraInstance.prototype.isFunction = function (value) {
return typeof value === "function";
};
/**
* @name capivara,isNumber
* @description Verifica se um valor é um número.
*/
CapivaraInstance.prototype.isNumber = function (value) {
return typeof value === "number";
};
/**
* @name capivara,isString
* @description Verifica se um valor é uma string.
*/
CapivaraInstance.prototype.isString = function (value) {
return typeof value === "string";
};
/**
* @name capivara,merge
* @description Faz a junção de objetos em um único objeto.
*/
CapivaraInstance.prototype.merge = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return Object.assign.apply(Object, args);
};
/**
* @name capivara,copy
* @description Faz a copia de um objeto para que seja criada a referência.
*/
CapivaraInstance.prototype.copy = function (value) {
return Object.assign(value);
};
/**
* @name capivara,replaceAll
* @description Faz a devida alteração em todas as ocorrências
*/
CapivaraInstance.prototype.replaceAll = function (str, needle, replacement) {
return str.split(needle).join(replacement);
};
/**
* @name capivara.constants
* @description Modifica o nome das diretivas que são criadas pelo capivara.
*/
CapivaraInstance.prototype.constants = function (obj) {
Object.keys(obj).forEach(function (key) {
if (_constants__WEBPACK_IMPORTED_MODULE_0__["Constants"][key]) {
_constants__WEBPACK_IMPORTED_MODULE_0__["Constants"][key] = obj[key];
}
});
};
CapivaraInstance.prototype.$on = function (evtName, callback) {
window["capivara"].$watchers.push({ evtName: evtName, callback: callback });
};
CapivaraInstance.prototype.$emit = function (evtName) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
window["capivara"]
.$watchers
.filter(function (watcher) { return watcher.evtName === evtName; })
.forEach(function (watcher) {
watcher.callback.apply(watcher, args);
});
};
CapivaraInstance.prototype.simpleCompare = function (a, b) {
return a === b || (a !== a && b !== b);
};
CapivaraInstance.prototype.isRegExp = function (value) {
return toString.call(value) === '[object RegExp]';
};
CapivaraInstance.prototype.isDefined = function (value) {
return typeof value !== 'undefined';
};
CapivaraInstance.prototype.isWindow = function (value) {
return value && value.window === value;
};
CapivaraInstance.prototype.isScope = function (value) {
return value instanceof _scope_scope__WEBPACK_IMPORTED_MODULE_1__["Scope"];
};
CapivaraInstance.prototype.equals = function (o1, o2) {
if (o1 === o2) {
return true;
}
if (o1 === null || o2 === null) {
return false;
}
if (o1 !== o1 && o2 !== o2) {
return true;
}
/* tslint:disable */
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
if (t1 === t2 && t1 === 'object') {
if (this.isArray(o1)) {
if (!this.isArray(o2)) {
return false;
}
;
if ((length = o1.length) === o2.length) {
for (key = 0; key < length; key++) {
if (!this.equals(o1[key], o2[key]))
return false;
}
return true;
}
}
else if (this.isDate(o1)) {
if (!this.isDate(o2))
return false;
return this.simpleCompare(o1.getTime(), o2.getTime());
}
else if (this.isRegExp(o1)) {
if (!this.isRegExp(o2))
return false;
return o1.toString() === o2.toString();
}
else {
if (this.isScope(o1) || this.isScope(o2) || this.isWindow(o1) || this.isWindow(o2) ||
this.isArray(o2) || this.isDate(o2) || this.isRegExp(o2))
return false;
keySet = Object.create(null);
for (key in o1) {
if (key.charAt(0) === '$' || this.isFunction(o1[key]))
continue;
if (!this.equals(o1[key], o2[key]))
return false;
keySet[key] = true;
}
for (key in o2) {
if (!(key in keySet) &&
key.charAt(0) !== '$' &&
this.isDefined(o2[key]) &&
!this.isFunction(o2[key]))
return false;
}
return true;
}
}
return false;
};
return CapivaraInstance;
}());
/***/ }),
/***/ "../node_modules/capivarajs/src/core/component.config.ts":
/*!***************************************************************!*\
!*** ../node_modules/capivarajs/src/core/component.config.ts ***!
\***************************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
/***/ }),
/***/ "../node_modules/capivarajs/src/core/component.instance.ts":
/*!*****************************************************************!*\
!*** ../node_modules/capivarajs/src/core/component.instance.ts ***!
\*****************************************************************/
/*! exports provided: ComponentInstance */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ComponentInstance", function() { return ComponentInstance; });
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "../node_modules/lodash/lodash.js");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var melanke_watchjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! melanke-watchjs */ "../node_modules/melanke-watchjs/src/watch.js");
/* harmony import */ var melanke_watchjs__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(melanke_watchjs__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _common__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../common */ "../node_modules/capivarajs/src/common.ts");
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../constants */ "../node_modules/capivarajs/src/constants.ts");
/* harmony import */ var _scope_scope_proxy__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../scope/scope.proxy */ "../node_modules/capivarajs/src/scope/scope.proxy.ts");
/* harmony import */ var _controller__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./controller */ "../node_modules/capivarajs/src/core/controller.ts");
/* harmony import */ var _magic_magic__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./magic/magic */ "../node_modules/capivarajs/src/core/magic/magic.ts");
/* harmony import */ var _observer__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./observer */ "../node_modules/capivarajs/src/core/observer/index.ts");
var ComponentInstance = /** @class */ (function () {
function ComponentInstance(_element, _config) {
this.constantsValue = {};
this.functionsValue = {};
this.bindingsValue = {};
this.listenerContextBindings = {};
_config.controllerAs = _config.controllerAs || '$ctrl';
this.element = _element;
this.element.$instance = this;
this.config = _config;
this.config.controller = this.config.controller || function isolatedScope() { };
this.renderTemplate();
this.destroyed = true;
this.registerController();
}
ComponentInstance.prototype.renderTemplate = function () {
if (this.config.template) {
if (DOMParser) {
var templateToElm_1 = new DOMParser().parseFromString(this.config.template, 'text/html');
var transcludeTemplate = new DOMParser().parseFromString(this.element.innerHTML, 'text/html');
if (transcludeTemplate && templateToElm_1 && transcludeTemplate.querySelectorAll) {
Array.from((transcludeTemplate.querySelectorAll('cp-transclude') || [])).forEach(function (transclude) {
var attrName = transclude.getAttribute('name');
var query = transclude.nodeName.toLowerCase() + (attrName ? '[name="' + attrName + '"]' : '');
Array.from((templateToElm_1.querySelectorAll(query) || [])).forEach(function (transcludeReference) {
Array.from(transclude.children).forEach(function (children) {
_common__WEBPACK_IMPORTED_MODULE_2__["Common"].appendAfter(transcludeReference, children);
});
transcludeReference.parentNode.removeChild(transcludeReference);
});
});
this.element.innerHTML = templateToElm_1.body.innerHTML;
}
else {
this.element.innerHTML = this.config.template;
}
}
else {
this.element.innerHTML = this.config.template;
}
}
};
ComponentInstance.prototype.registerController = function () {
var _this = this;
new _controller__WEBPACK_IMPORTED_MODULE_5__["Controller"](this.element, function (scope) {
_this.componentScope = scope;
});
};
ComponentInstance.prototype.initController = function () {
var _a;
if (this.destroyed && document.body.contains(this.element)) {
this.destroyed = false;
if (this.config.controller) {
var args = [
this.componentScope.element[_constants__WEBPACK_IMPORTED_MODULE_3__["Constants"].SCOPE_ATTRIBUTE_NAME],
this.componentScope.mapDom.element,
this.componentScope.mapDom,
];
this.componentScope[this.config.controllerAs] = new ((_a = this.config.controller).bind.apply(_a, [void 0].concat(args)))();
}
this.contextObj = _magic_magic__WEBPACK_IMPORTED_MODULE_6__["Magic"].getContext(this.element);
this.applyConstantsComponentMagic();
this.applyFunctionsComponentMagic();
this.applyBindingsComponentMagic();
if (this.componentScope[this.config.controllerAs] && this.componentScope[this.config.controllerAs].$onInit) {
this.componentScope[this.config.controllerAs].$onInit();
}
Object.defineProperty(this.componentScope, '__$controllerAs__', {
value: this.config.controllerAs,
configurable: true,
});
var context = _common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element);
context.$emit('$onInit');
context.mapDom.reload();
}
};
/**
* @description Aplica os bindings|constants|functions
*/
ComponentInstance.prototype.build = function () {
this.applyConstantsComponentBuilder();
this.applyFunctionsComponentBuilder();
if (this.contextObj) {
this.applyBindingsComponentBuilder();
}
var context = _common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element);
if (context.scope.$ctrl.$onBuild) {
context.scope.$ctrl.$onBuild();
}
};
/**
* @description Renderiza o template no elemento.
*/
ComponentInstance.prototype.create = function () {
this.initController();
};
/**
* @description Função executada quando o elemento é destruído do documento.
*/
ComponentInstance.prototype.destroy = function () {
var _this = this;
this.destroyed = true;
this.element[_constants__WEBPACK_IMPORTED_MODULE_3__["Constants"].SCOPE_ATTRIBUTE_NAME].destroy();
_observer__WEBPACK_IMPORTED_MODULE_7__["Observe"].unobserve(this.componentScope[this.config.controllerAs]);
if (this.componentScope[this.config.controllerAs] && this.componentScope[this.config.controllerAs].$destroy) {
this.componentScope[this.config.controllerAs].$destroy();
}
if (this.componentScope[this.config.controllerAs] && this.componentScope[this.config.controllerAs].$onDestroy) {
this.componentScope[this.config.controllerAs].$onDestroy();
}
try {
window['capivara'].scopes = window['capivara'].scopes.filter(function (scope) {
return scope.id !== _this.componentScope.element[_constants__WEBPACK_IMPORTED_MODULE_3__["Constants"].SCOPE_ATTRIBUTE_NAME].id &&
scope.id !== _this.contextObj.element[_constants__WEBPACK_IMPORTED_MODULE_3__["Constants"].SCOPE_ATTRIBUTE_NAME].id;
});
}
catch (e) {
window['capivara'].scopes = window['capivara'].scopes.filter(function (scope) {
return document.body.contains(_this.componentScope.element);
});
}
};
/**
* @description
* @param obj Contexto dos bindings, o contexto é o objeto que possui os valores dos bindings
*/
ComponentInstance.prototype.context = function (obj) {
this.contextObj = obj;
return this;
};
/**
* @description Cria os bindings que o componente espera.
* @param _bindings Objeto com o nome dos bindings
*/
ComponentInstance.prototype.bindings = function (_bindings) {
if (_bindings === void 0) { _bindings = {}; }
if (!this.contextObj) {
console.error('Bindings ainda não aplicados. Primeiro, é necessário informar o contexto.');
return this;
}
this.bindingsValue = Object.assign(this.bindingsValue, _bindings);
return this;
};
ComponentInstance.prototype.applyBindingsComponentBuilder = function () {
var _this = this;
(this.config.bindings || []).forEach(function (key) {
_this.setAttributeValue(_this.bindingsValue, key);
_this.createObserverContext(_this.bindingsValue, key);
});
this.createObserverScope(this.bindingsValue);
};
ComponentInstance.prototype.applyBindingsComponentMagic = function () {
var _this = this;
if (!_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element).scope[this.config.controllerAs]['$bindings']) {
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element).scope, this.config.controllerAs + '.$bindings', {});
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element).scope, '$bindings', {});
}
(this.config.bindings || []).forEach(function (bindingKey) {
var bindAttribute = bindingKey.replace(/([A-Z])/g, "-$1").toLowerCase();
var valueAttribute = _this.element.getAttribute(bindAttribute);
if (valueAttribute) {
_this.bindingsValue[bindingKey] = valueAttribute;
_this.setAttributeValue(_this.bindingsValue, bindingKey);
_this.createObserverContext(_this.bindingsValue, bindingKey);
}
});
this.createObserverScope(this.bindingsValue);
};
/**
* @description Observa o componente quando houver alteração é modificado o contexto
*/
ComponentInstance.prototype.createObserverScope = function (_bindings) {
var _this = this;
if (_bindings === void 0) { _bindings = {}; }
var $ctrl = _common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element).scope[this.config.controllerAs];
Object.defineProperty($ctrl, '_$$checkBindings', {
value: function (changes) {
changes.forEach(function (change) {
if (change.type === 'update' && _bindings.hasOwnProperty(change.name)) {
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](_this.contextObj, _bindings[change.name], $ctrl['$bindings'][change.name]);
_this.forceUpdateContext();
_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(_this.element).mapDom.reload();
}
});
},
writable: true,
configurable: true,
});
};
ComponentInstance.prototype.forceUpdateContext = function () {
if (this.contextObj) {
if (this.contextObj['$forceUpdate']) {
this.contextObj['$forceUpdate']();
}
if (this.contextObj['$apply']) {
this.contextObj['$apply']();
}
if (this.contextObj['forceUpdate']) {
this.contextObj['forceUpdate']();
}
if (window['ng']) {
var debugContext = window['ng'].probe(this.element);
if (debugContext) {
debugContext.injector.get(window['ng'].coreTokens.ApplicationRef).tick();
}
}
}
};
/**
* @description Observa o contexto, quando houver alteração é modificado no escopo do componente
*/
ComponentInstance.getFirstAttribute = function (_bindings, key) {
if (_bindings === void 0) { _bindings = {}; }
return _bindings[key].indexOf('.') !== -1 ? _bindings[key].substring(0, _bindings[key].indexOf('.')) : _bindings[key];
};
ComponentInstance.prototype.observeAndSetValues = function (obj, _bindings, key) {
var _this = this;
_observer__WEBPACK_IMPORTED_MODULE_7__["Observe"].observe(obj, function () { return _this.setAttributeValue(_bindings, key); });
};
ComponentInstance.prototype.createObserverContext = function (_bindings, key) {
var _this = this;
if (!_bindings[key]) {
return;
}
if (this.contextObj instanceof _scope_scope_proxy__WEBPACK_IMPORTED_MODULE_4__["ScopeProxy"]) {
if (this.contextObj[this.config.controllerAs]) {
this.observeAndSetValues(this.contextObj[this.config.controllerAs], _bindings, key);
}
else {
this.observeAndSetValues(this.contextObj, _bindings, key);
}
}
else {
var attrToObserve = ComponentInstance.getFirstAttribute(_bindings, key);
melanke_watchjs__WEBPACK_IMPORTED_MODULE_1___default.a.watch(this.contextObj, attrToObserve, function () {
_this.setAttributeValue(_bindings, key);
}, 1);
}
};
ComponentInstance.prototype.setAttributeValue = function (_bindings, key) {
if (_bindings === void 0) { _bindings = {}; }
var scope = _common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element).scope;
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](scope, this.config.controllerAs + '.$bindings.' + key, lodash__WEBPACK_IMPORTED_MODULE_0__["get"](this.contextObj, _bindings[key]));
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](scope, '$bindings.' + key, lodash__WEBPACK_IMPORTED_MODULE_0__["get"](this.contextObj, _bindings[key]));
_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element).mapDom.reload();
if (scope[this.config.controllerAs] && scope[this.config.controllerAs].$onChanges) {
scope[this.config.controllerAs].$onChanges();
}
};
/**
* @description Crie valores sem referências
* @param _constants Objeto com o nome das constants
*/
ComponentInstance.prototype.constants = function (_constants) {
if (_constants === void 0) { _constants = {}; }
this.constantsValue = _constants;
return this;
};
ComponentInstance.prototype.applyConstantsComponentMagic = function () {
var _this = this;
if (!_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element).scope[this.config.controllerAs]['$constants']) {
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element).scope, this.config.controllerAs + '.$constants', {});
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(this.element).scope, '$constants', {});
}
(this.config.constants || []).forEach(function (constantKey) {
var bindAttribute = constantKey.replace(/([A-Z])/g, "-$1").toLowerCase();
var valueAttribute = _this.element.getAttribute(bindAttribute);
if (valueAttribute) {
var constantValue = _common__WEBPACK_IMPORTED_MODULE_2__["Common"].evalInContext(valueAttribute, _this.contextObj);
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(_this.element).scope, _this.config.controllerAs + '.$constants.' + constantKey, constantValue);
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(_this.element).scope, '$constants.' + constantKey, constantValue);
}
});
};
ComponentInstance.prototype.applyConstantsComponentBuilder = function () {
var _this = this;
(this.config.constants || []).forEach(function (key) {
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](_common__WEBPACK_IMPORTED_MODULE_2__["Common"].getScope(_this.element).scope, _this.config.controllerAs + '.$constants.' + key, _this.constantsValue[key]);
// Mantém compatibilidade
lodash__WEBPACK_IMPORTED_MODULE_0__["set"](_common__WEBPACK_IMPORTED_MODULE_2__["