omi/dist/omi.js

3105 lines
114 KiB
JavaScript
Raw Normal View History

2017-01-21 14:01:46 +08:00
/*!
2017-07-01 09:56:39 +08:00
* Omi v1.7.4 By dntzhang
2017-04-19 10:20:03 +08:00
* Github: https://github.com/AlloyTeam/omi
2017-01-21 14:01:46 +08:00
* MIT Licensed.
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["Omi"] = factory();
else
root["Omi"] = factory();
})(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] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = 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;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
2017-04-20 17:46:08 +08:00
/***/ (function(module, exports, __webpack_require__) {
2017-01-21 14:01:46 +08:00
'use strict';
var _omi = __webpack_require__(1);
var _omi2 = _interopRequireDefault(_omi);
2017-04-19 10:20:03 +08:00
var _soda = __webpack_require__(2);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var _soda2 = _interopRequireDefault(_soda);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var _component = __webpack_require__(4);
2017-01-21 14:01:46 +08:00
var _component2 = _interopRequireDefault(_component);
2017-04-19 10:20:03 +08:00
var _store = __webpack_require__(9);
2017-03-18 08:08:11 +08:00
var _store2 = _interopRequireDefault(_store);
2017-02-08 21:48:08 +08:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
_soda2['default'].prefix('o');
_omi2['default'].template = _soda2['default'];
2017-01-21 14:01:46 +08:00
2017-03-18 08:08:11 +08:00
_omi2['default'].Store = _store2['default'];
2017-02-08 21:48:08 +08:00
_omi2['default'].Component = _component2['default'];
if (window.Omi) {
module.exports = window.Omi;
} else {
window.Omi = _omi2['default'];
module.exports = _omi2['default'];
}
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
/***/ }),
2017-01-21 14:01:46 +08:00
/* 1 */
2017-04-20 17:46:08 +08:00
/***/ (function(module, exports) {
2017-01-21 14:01:46 +08:00
"use strict";
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var Omi = {};
Omi.instances = {};
Omi._instanceId = 0;
Omi.getInstanceId = function () {
return Omi._instanceId++;
};
Omi.customTags = [];
Omi.mapping = {};
Omi.STYLEPREFIX = "omi_style_";
Omi.STYLESCOPEDPREFIX = "omi_scoped_";
Omi.style = {};
2017-03-27 21:25:24 +08:00
Omi.componentConstructor = {};
2017-03-18 08:08:11 +08:00
2017-01-21 14:01:46 +08:00
//fix ie bug
if (typeof Object.assign != 'function') {
Object.assign = function (target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
}
2017-04-19 10:20:03 +08:00
/**
* Shim for "fixing" IE's lack of support (IE < 9) for applying slice
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
* (technically, since host objects have been implementation-dependent,
* at least before ES6, IE hasn't needed to work this way).
* Also works on strings, fixes IE < 9 to allow an explicit undefined
* for the 2nd argument (as in Firefox), and prevents errors when
* called on other DOM objects.
2017-02-08 21:48:08 +08:00
*/
(function () {
'use strict';
var _slice = Array.prototype.slice;
try {
// Can't be used with DOM elements in IE < 9
_slice.call(document.documentElement);
} catch (e) {
// Fails in IE < 9
// This will work for genuine arrays, array-like objects,
// NamedNodeMap (attributes, entities, notations),
// NodeList (e.g., getElementsByTagName), HTMLCollection (e.g., childNodes),
// and will not fail on other DOM objects (as do DOM elements in IE < 9)
Array.prototype.slice = function (begin, end) {
// IE < 9 gets unhappy with an undefined end argument
end = typeof end !== 'undefined' ? end : this.length;
// For native Array objects, we use the native slice function
if (Object.prototype.toString.call(this) === '[object Array]') {
return _slice.call(this, begin, end);
}
// For array like object we handle it ourselves.
var i,
cloned = [],
size,
len = this.length;
// Handle negative value for "begin"
var start = begin || 0;
start = start >= 0 ? start : len + start;
// Handle negative value for "end"
var upTo = end ? end : len;
if (end < 0) {
upTo = len + end;
}
// Actual expected size of the slice
size = upTo - start;
if (size > 0) {
cloned = new Array(size);
if (this.charAt) {
for (i = 0; i < size; i++) {
cloned[i] = this.charAt(start + i);
}
} else {
for (i = 0; i < size; i++) {
cloned[i] = this[start + i];
}
}
}
return cloned;
};
}
})();
2017-01-21 14:01:46 +08:00
var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
}
}return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
};
}();
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _possibleConstructorReturn(self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}return call && ((typeof call === "undefined" ? "undefined" : _typeof(call)) === "object" || typeof call === "function") ? call : self;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + (typeof superClass === "undefined" ? "undefined" : _typeof(superClass)));
}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}
function toArr(obj) {
var arr = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
arr.push({ key: key, value: obj[key] });
}
}
return arr;
}
Omi.create = function (tagName, parent, setting) {
var u_setting = parent,
u_parent = Omi.Component;
if (arguments.length > 2) {
u_setting = setting;
u_parent = parent;
}
2017-03-27 21:25:24 +08:00
Omi.componentConstructor[tagName] = function (parent) {
2017-01-21 14:01:46 +08:00
_inherits(Obj, parent);
function Obj(data, server) {
_classCallCheck(this, Obj);
this.___omi_constructor_name = tagName;
return _possibleConstructorReturn(this, (Obj.__proto__ || Object.getPrototypeOf(Obj)).call(this, data, server));
}
_createClass(Obj, toArr(u_setting));
return Obj;
}(u_parent);
Omi.customTags.push(tagName);
2017-03-27 21:25:24 +08:00
return Omi.componentConstructor[tagName];
2017-01-21 14:01:46 +08:00
};
2017-03-23 18:31:46 +08:00
Omi.createStore = function (option) {
var Store = function (parent) {
_inherits(Obj, parent);
function Obj(data, isReady) {
_classCallCheck(this, Obj);
this.data = data;
option.methods.install && option.methods.install.call(this);
2017-03-23 18:31:46 +08:00
return _possibleConstructorReturn(this, (Obj.__proto__ || Object.getPrototypeOf(Obj)).call(this, data, isReady));
}
_createClass(Obj, toArr(option.methods));
return Obj;
}(Omi.Store);
return new Store(option.data, true);
};
2017-01-21 14:01:46 +08:00
Omi.mixIndex = function (array, key) {
var len = array.length,
indexName = key || "index";
for (var i = 0; i < len; i++) {
var item = array[i];
if ((typeof item === "undefined" ? "undefined" : _typeof(item)) === "object") {
item[indexName] = i;
} else {
array[i] = { value: item };
array[i][indexName] = i;
}
}
return array;
};
Omi.$ = function (selector, context) {
if (context) {
return context.querySelector(selector);
} else {
return document.querySelector(selector);
}
};
2017-01-23 10:45:19 +08:00
Omi.$$ = function (selector, context) {
if (context) {
return Array.prototype.slice.call(context.querySelectorAll(selector));
} else {
return Array.prototype.slice.call(document.querySelectorAll(selector));
}
};
2017-01-21 14:01:46 +08:00
Omi.getClassFromString = function (str) {
2017-03-18 08:08:11 +08:00
if (str.indexOf('.') !== -1) {
//root is window
2017-01-21 14:01:46 +08:00
var arr = str.split('.');
var len = arr.length;
2017-03-18 08:08:11 +08:00
var current = window[arr[0]];
2017-01-21 14:01:46 +08:00
for (var i = 1; i < len; i++) {
current = current[arr[i]];
}
return current;
} else {
2017-03-27 21:25:24 +08:00
return Omi.componentConstructor[str];
2017-01-21 14:01:46 +08:00
}
};
2017-03-09 09:00:00 +08:00
//以前是Component的静态方法移到omi下来不然makehtml 在ie下child访问不到父亲的静态方法
2017-02-05 13:29:14 +08:00
Omi.makeHTML = function (name, ctor) {
2017-03-27 21:25:24 +08:00
Omi.componentConstructor[name] = ctor;
2017-04-06 21:15:09 +08:00
Omi.componentConstructor[name.toLowerCase()] = ctor;
Omi.customTags.push(name, name.toLowerCase());
2017-04-20 17:46:08 +08:00
if (document.documentMode < 9) {
document.createElement(name.toLowerCase());
}
2017-01-21 14:01:46 +08:00
};
Omi.tag = Omi.makeHTML;
Omi.render = function (component, renderTo, incrementOrOption) {
2017-01-21 14:01:46 +08:00
component.renderTo = typeof renderTo === "string" ? document.querySelector(renderTo) : renderTo;
if (typeof incrementOrOption === 'boolean') {
component._omi_increment = incrementOrOption;
} else if (incrementOrOption) {
component._omi_increment = incrementOrOption.increment;
if (incrementOrOption.store) {
if (incrementOrOption.store instanceof Omi.Store) {
component.$store = incrementOrOption.store;
} else {
component.$store = Omi.createStore(incrementOrOption.store);
}
}
component._omi_autoStoreToData = incrementOrOption.autoStoreToData;
}
2017-01-21 14:01:46 +08:00
component.install();
component._render(true);
2017-07-01 09:56:39 +08:00
component._childrenInstalled(component);
component.installed();
component._execInstalledHandlers();
2017-01-21 14:01:46 +08:00
return component;
};
2017-01-22 11:45:52 +08:00
Omi.get = function (name) {
return Omi.mapping[name];
};
2017-02-12 21:11:25 +08:00
Omi.plugins = {};
Omi.extendPlugin = function (name, handler) {
Omi.plugins[name] = handler;
};
Omi.getParameters = function (dom, instance, types) {
var data = {};
var noop = function noop() {};
var methodMapping = {
stringType: function stringType(value) {
return value;
},
numberType: function numberType(value) {
return Number(value);
},
booleanType: function booleanType(value) {
if (value === 'true') {
return true;
} else if (value === 'false') {
return false;
} else {
return Boolean(value);
}
},
functionType: function functionType(value) {
if (value) {
var handler = instance[value.replace(/Omi.instances\[\d\]./, '')];
if (handler) {
return handler.bind(instance);
} else {
console.warn('You do not define [ ' + value + ' ] method in following component');
console.warn(instance);
}
} else {
return noop;
}
}
};
Object.keys(types).forEach(function (type) {
types[type].forEach(function (name) {
var attr = dom.getAttribute(name);
if (attr !== null) {
data[name] = methodMapping[type](attr);
}
});
});
return data;
};
Omi.mixIndexToArray = function (arr, indexName) {
arr.forEach(function (item, index) {
item[indexName || 'index'] = index;
});
};
Omi.deletePlugin = function (name) {
delete Omi.plugins[name];
};
2017-01-21 14:01:46 +08:00
module.exports = Omi;
2017-04-20 17:46:08 +08:00
/***/ }),
2017-01-21 14:01:46 +08:00
/* 2 */
2017-04-20 17:46:08 +08:00
/***/ (function(module, exports, __webpack_require__) {
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(module) {'use strict';
2017-01-21 14:01:46 +08:00
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
2017-04-19 10:20:03 +08:00
/**
2017-05-10 12:57:03 +08:00
* sodajs v0.4.4 by dorsywang
2017-04-19 10:20:03 +08:00
* Light weight but powerful template engine for JavaScript
* Github: https://github.com/AlloyTeam/sodajs
* MIT License
2017-01-21 14:01:46 +08:00
*/
2017-04-19 10:20:03 +08:00
;(function () {
2017-04-20 17:46:08 +08:00
if (!Array.prototype.map) {
Array.prototype.map = function (func) {
var arr = [];
for (var i = 0; i < this.length; i++) {
var item = this[i];
[].push(func && func.call(item, item, i));
}
return arr;
};
}
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s*|\s*$/g, '');
};
}
var nodes2Arr = function nodes2Arr(nodes) {
var arr = [];
for (var i = 0; i < nodes.length; i++) {
arr.push(nodes[i]);
}
return arr;
};
2017-04-19 10:20:03 +08:00
var valueoutReg = /\{\{([^\}]*)\}\}/g;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var prefix = 'soda';
var prefixReg = new RegExp('^' + prefix + '-');
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var classNameRegExp = function classNameRegExp(className) {
return new RegExp('(^|\\s+)' + className + '(\\s+|$)', 'g');
2017-01-21 14:01:46 +08:00
};
2017-04-19 10:20:03 +08:00
var addClass = function addClass(el, className) {
if (!el.className) {
el.className = className;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
return;
}
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (el.className.match(classNameRegExp(className))) {} else {
el.className += " " + className;
}
};
2017-01-21 14:01:46 +08:00
2017-07-01 09:02:05 +08:00
var exist = function exist(value) {
return value !== null && value !== undefined && value !== "" && typeof value !== 'undefined';
};
2017-04-19 10:20:03 +08:00
var removeClass = function removeClass(el, className) {
el.className = el.className.replace(classNameRegExp(className), "");
};
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var getValue = function getValue(_data, _attrStr) {
CONST_REGG.lastIndex = 0;
var realAttrStr = _attrStr.replace(CONST_REGG, function (r) {
if (typeof _data[r] === "undefined") {
return r;
} else {
return _data[r];
}
});
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (_attrStr === 'true') {
return true;
}
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (_attrStr === 'false') {
return false;
}
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var _getValue = function _getValue(data, attrStr) {
var dotIndex = attrStr.indexOf(".");
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (dotIndex > -1) {
var attr = attrStr.substr(0, dotIndex);
attrStr = attrStr.substr(dotIndex + 1);
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
// <20>?查attrStr是否属<E590A6>?<3F>变量并转换
2017-04-19 10:20:03 +08:00
if (typeof _data[attr] !== "undefined" && CONST_REG.test(attr)) {
attr = _data[attr];
}
if (typeof data[attr] !== "undefined") {
return _getValue(data[attr], attrStr);
} else {
var eventData = {
name: realAttrStr,
data: _data
};
triggerEvent("nullvalue", {
type: "nullattr",
data: eventData
}, eventData);
2017-04-20 17:46:08 +08:00
// 如果还有
2017-04-19 10:20:03 +08:00
return "";
2017-01-21 14:01:46 +08:00
}
} else {
2017-04-19 10:20:03 +08:00
2017-04-20 17:46:08 +08:00
// <20>?查attrStr是否属<E590A6>?<3F>变量并转换
2017-04-19 10:20:03 +08:00
if (typeof _data[attrStr] !== "undefined" && CONST_REG.test(attrStr)) {
attrStr = _data[attrStr];
}
var rValue;
if (typeof data[attrStr] !== "undefined") {
rValue = data[attrStr];
} else {
var eventData = {
name: realAttrStr,
data: _data
};
triggerEvent("nullvalue", {
type: "nullvalue",
data: eventData
}, eventData);
rValue = '';
}
return rValue;
2017-01-21 14:01:46 +08:00
}
2017-04-19 10:20:03 +08:00
};
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
return _getValue(_data, _attrStr);
};
2017-04-20 17:46:08 +08:00
// 注释node
2017-04-19 10:20:03 +08:00
var commentNode = function commentNode(node) {};
2017-04-20 17:46:08 +08:00
// 标识<E6A087>?
2017-04-19 10:20:03 +08:00
var IDENTOR_REG = /[a-zA-Z_\$]+[\w\$]*/g;
var STRING_REG = /"([^"]*)"|'([^']*)'/g;
var NUMBER_REG = /\d+|\d*\.\d+/g;
var OBJECT_REG = /[a-zA-Z_\$]+[\w\$]*(?:\s*\.\s*(?:[a-zA-Z_\$]+[\w\$]*|\d+))*/g;
2017-04-20 17:46:08 +08:00
// 非global 做test用
var OBJECT_REG_NG = /[a-zA-Z_\$]+[\w\$]*(?:\s*\.\s*(?:[a-zA-Z_\$]+[\w\$]*|\d+))*/;
2017-04-19 10:20:03 +08:00
var ATTR_REG = /\[([^\[\]]*)\]/g;
2017-04-20 17:46:08 +08:00
var ATTR_REG_NG = /\[([^\[\]]*)\]/;
2017-04-19 10:20:03 +08:00
var ATTR_REG_DOT = /\.([a-zA-Z_\$]+[\w\$]*)/g;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var NOT_ATTR_REG = /[^\.|]([a-zA-Z_\$]+[\w\$]*)/g;
var OR_REG = /\|\|/g;
var OR_REPLACE = "OR_OPERATOR\x1E";
var getRandom = function getRandom() {
return "$$" + ~~(Math.random() * 1E6);
};
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var CONST_PRIFIX = "_$C$_";
var CONST_REG = /^_\$C\$_/;
var CONST_REGG = /_\$C\$_[^\.]+/g;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var getAttrVarKey = function getAttrVarKey() {
return CONST_PRIFIX + ~~(Math.random() * 1E6);
};
var parseSodaExpression = function parseSodaExpression(str, scope) {
2017-04-20 17:46:08 +08:00
// 对filter进行处理
2017-04-19 10:20:03 +08:00
str = str.replace(OR_REG, OR_REPLACE).split("|");
for (var i = 0; i < str.length; i++) {
str[i] = (str[i].replace(new RegExp(OR_REPLACE, 'g'), "||") || '').trim();
2017-01-21 14:01:46 +08:00
}
2017-04-19 10:20:03 +08:00
var expr = str[0] || "";
var filters = str.slice(1);
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
// 将字符常量保存下<E5AD98>?
2017-04-19 10:20:03 +08:00
expr = expr.replace(STRING_REG, function (r, $1, $2) {
var key = getRandom();
scope[key] = $1 || $2;
return key;
});
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
while (ATTR_REG_NG.test(expr)) {
2017-04-19 10:20:03 +08:00
ATTR_REG.lastIndex = 0;
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
//对expr预处<E9A284>?
2017-04-19 10:20:03 +08:00
expr = expr.replace(ATTR_REG, function (r, $1) {
var key = getAttrVarKey();
2017-04-20 17:46:08 +08:00
// 属<>?<3F><EFBFBD>? 为字符常<E7ACA6>?
2017-04-19 10:20:03 +08:00
var attrName = parseSodaExpression($1, scope);
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
// 给一个特殊的前缀 表示是属性变<E680A7>?
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
scope[key] = attrName;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
return "." + key;
});
}
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
expr = expr.replace(OBJECT_REG, function (value) {
return "getValue(scope,'" + value.trim() + "')";
});
var parseFilter = function parseFilter() {
var filterExpr = filters.shift();
if (!filterExpr) {
return;
2017-01-21 14:01:46 +08:00
}
2017-04-19 10:20:03 +08:00
var filterExpr = filterExpr.split(":");
var args = filterExpr.slice(1) || [];
var name = filterExpr[0] || "";
var stringReg = /^'.*'$|^".*"$/;
for (var i = 0; i < args.length; i++) {
2017-04-20 17:46:08 +08:00
//这里根据类型进行判断
if (OBJECT_REG_NG.test(args[i])) {
2017-04-19 10:20:03 +08:00
args[i] = "getValue(scope,'" + args[i] + "')";
} else {}
}
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (sodaFilterMap[name]) {
args.unshift(expr);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
args = args.join(",");
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
expr = "sodaFilterMap['" + name + "'](" + args + ")";
2017-01-21 14:01:46 +08:00
}
2017-04-19 10:20:03 +08:00
parseFilter();
};
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
parseFilter();
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var evalFunc = new Function("getValue", "sodaFilterMap", "return function sodaExp(scope){ return " + expr + "}")(getValue, sodaFilterMap);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
return evalFunc(scope);
};
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var hashTable = {
id2Expression: {},
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
expression2id: {},
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
getRandId: function getRandId() {
return 'soda' + ~~(Math.random() * 1E5);
}
};
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
// 解析指令
// 解析attr
2017-04-19 10:20:03 +08:00
var compileNode = function compileNode(node, scope) {
2017-04-20 17:46:08 +08:00
// 如果只是文本
2017-04-19 10:20:03 +08:00
if (node.nodeType === 3) {
node.nodeValue = node.nodeValue.replace(valueoutReg, function (item, $1) {
/*
var id = hashTable.getRandId();
hashTable.id2Expression[id] = {
expression: $1,
el: child
};
hashTable.expression2id[$1] = {
id: id,
el: child
};
*/
return parseSodaExpression($1, scope);
});
}
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (node.attributes) {
2017-04-20 17:46:08 +08:00
// 指令处理
2017-04-19 10:20:03 +08:00
sodaDirectiveArr.map(function (item) {
var name = item.name;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var opt = item.opt;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (node.getAttribute(name) && node.parentNode) {
opt.link(scope, node, node.attributes);
2017-01-21 14:01:46 +08:00
}
2017-04-19 10:20:03 +08:00
});
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
// 处理输出 包含 prefix-*
2017-04-19 10:20:03 +08:00
[].map.call(node.attributes, function (attr) {
2017-04-20 17:46:08 +08:00
// 如果dirctiveMap有的就跳过不再处<E5868D>?
2017-04-19 10:20:03 +08:00
if (!sodaDirectiveMap[attr.name]) {
if (prefixReg.test(attr.name)) {
var attrName = attr.name.replace(prefixReg, '');
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (attrName) {
2017-04-20 17:46:08 +08:00
if (attr.value) {
var attrValue = attr.value.replace(valueoutReg, function (item, $1) {
return parseSodaExpression($1, scope);
});
2017-01-21 14:01:46 +08:00
2017-07-01 09:02:05 +08:00
if (exist(attrValue)) {
node.setAttribute(attrName, attrValue);
}
2017-04-20 17:46:08 +08:00
}
2017-04-19 10:20:03 +08:00
}
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
// 对其他属性里含expr 处理
2017-04-19 10:20:03 +08:00
} else {
2017-04-20 17:46:08 +08:00
if (attr.value) {
attr.value = attr.value.replace(valueoutReg, function (item, $1) {
return parseSodaExpression($1, scope);
});
}
2017-04-19 10:20:03 +08:00
}
}
});
}
2017-04-20 17:46:08 +08:00
nodes2Arr(node.childNodes).map(function (child) {
2017-04-19 10:20:03 +08:00
compileNode(child, scope);
});
2017-01-21 14:01:46 +08:00
};
2017-04-19 10:20:03 +08:00
var sodaDirectiveMap = {};
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var sodaFilterMap = {};
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var sodaDirectiveArr = [];
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var sodaDirective = function sodaDirective(name, func) {
var name = prefix + '-' + name;
sodaDirectiveMap[name] = func();
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
sodaDirectiveArr.push({
name: name,
opt: sodaDirectiveMap[name]
});
2017-01-21 14:01:46 +08:00
};
2017-04-19 10:20:03 +08:00
var sodaFilter = function sodaFilter(name, func) {
sodaFilterMap[name] = func;
2017-01-21 14:01:46 +08:00
};
2017-04-19 10:20:03 +08:00
sodaFilter.get = function (name) {
return sodaFilterMap[name];
2017-01-21 14:01:46 +08:00
};
2017-04-19 10:20:03 +08:00
sodaFilter("date", function (input, lenth) {
return lenth;
});
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
sodaDirective('repeat', function () {
return {
priority: 10,
compile: function compile(scope, el, attrs) {},
link: function link(scope, el, attrs) {
var opt = el.getAttribute(prefix + '-repeat');
var itemName;
var valueName;
var trackReg = /\s+by\s+([^\s]+)$/;
var trackName;
opt = opt.replace(trackReg, function (item, $1) {
if ($1) {
trackName = ($1 || '').trim();
}
return '';
});
var inReg = /([^\s]+)\s+in\s+([^\s]+)|\(([^,]+)\s*,\s*([^)]+)\)\s+in\s+([^\s]+)/;
var r = inReg.exec(opt);
if (r) {
if (r[1] && r[2]) {
itemName = (r[1] || '').trim();
valueName = (r[2] || '').trim();
if (!(itemName && valueName)) {
return;
}
} else if (r[3] && r[4] && r[5]) {
trackName = (r[3] || '').trim();
itemName = (r[4] || '').trim();
valueName = (r[5] || '').trim();
2017-01-21 14:01:46 +08:00
}
} else {
2017-04-19 10:20:03 +08:00
return;
2017-01-21 14:01:46 +08:00
}
2017-04-19 10:20:03 +08:00
trackName = trackName || '$index';
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
// 这里要处理一<E79086>?
2017-04-19 10:20:03 +08:00
var repeatObj = getValue(scope, valueName) || [];
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var repeatFunc = function repeatFunc(i) {
var itemNode = el.cloneNode(true);
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
// 这里创建<E5889B>?个新的scope
2017-04-19 10:20:03 +08:00
var itemScope = {};
itemScope[trackName] = i;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
itemScope[itemName] = repeatObj[i];
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
itemScope.__proto__ = scope;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
itemNode.removeAttribute(prefix + '-repeat');
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
el.parentNode.insertBefore(itemNode, el);
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
// 这里是新加的dom, 要单独编<E78BAC>?
2017-04-19 10:20:03 +08:00
compileNode(itemNode, itemScope);
};
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if ('length' in repeatObj) {
for (var i = 0; i < repeatObj.length; i++) {
repeatFunc(i);
}
} else {
for (var i in repeatObj) {
if (repeatObj.hasOwnProperty(i)) {
repeatFunc(i);
}
}
}
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
el.parentNode.removeChild(el);
}
};
});
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
sodaDirective('if', function () {
return {
priority: 9,
link: function link(scope, el, attrs) {
var opt = el.getAttribute(prefix + '-if');
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var expressFunc = parseSodaExpression(opt, scope);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (expressFunc) {} else {
// el.setAttribute("removed", "removed");
el.parentNode && el.parentNode.removeChild(el);
}
}
};
});
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
sodaDirective('class', function () {
return {
link: function link(scope, el, attrs) {
var opt = el.getAttribute(prefix + "-class");
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var expressFunc = parseSodaExpression(opt, scope);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (expressFunc) {
addClass(el, expressFunc);
} else {}
}
};
});
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
sodaDirective('src', function () {
return {
link: function link(scope, el, attrs) {
var opt = el.getAttribute(prefix + "-src");
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var expressFunc = opt.replace(valueoutReg, function (item, $1) {
return parseSodaExpression($1, scope);
});
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (expressFunc) {
el.setAttribute("src", expressFunc);
} else {}
2017-01-21 14:01:46 +08:00
}
2017-04-19 10:20:03 +08:00
};
});
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
sodaDirective('bind-html', function () {
return {
link: function link(scope, el, attrs) {
var opt = el.getAttribute(prefix + "-bind-html");
var expressFunc = parseSodaExpression(opt, scope);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (expressFunc) {
el.innerHTML = expressFunc;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
return {
command: "childDone"
};
}
}
};
});
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
sodaDirective('html', function () {
return {
link: function link(scope, el, attrs) {
var opt = el.getAttribute(prefix + "-html");
var expressFunc = parseSodaExpression(opt, scope);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (expressFunc) {
el.innerHTML = expressFunc;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
return {
command: "childDone"
};
}
}
};
});
2017-01-21 14:01:46 +08:00
2017-05-10 12:57:03 +08:00
sodaDirective('replace', function () {
return {
link: function link(scope, el, attrs) {
var opt = el.getAttribute(prefix + "-replace");
var expressFunc = parseSodaExpression(opt, scope);
if (expressFunc) {
var div = document.createElement('div');
div.innerHTML = expressFunc;
if (el.parentNode) {
while (div.childNodes[0]) {
el.parentNode.insertBefore(div.childNodes[0], el);
}
}
}
el.parentNode.removeChild(el);
}
};
});
2017-04-19 10:20:03 +08:00
sodaDirective("style", function () {
return {
link: function link(scope, el, attrs) {
var opt = el.getAttribute(prefix + "-style");
var expressFunc = parseSodaExpression(opt, scope);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var getCssValue = function getCssValue(name, value) {
var numberWithoutpx = /opacity|z-index/;
if (numberWithoutpx.test(name)) {
return parseFloat(value);
}
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (isNaN(value)) {
return value;
} else {
return value + "px";
}
};
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
if (expressFunc) {
var stylelist = [];
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
for (var i in expressFunc) {
if (expressFunc.hasOwnProperty(i)) {
var provalue = getCssValue(i, expressFunc[i]);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
stylelist.push([i, provalue].join(":"));
}
}
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var style = el.style;
for (var i = 0; i < style.length; i++) {
var name = style[i];
if (expressFunc[name]) {} else {
stylelist.push([name, style[name]].join(":"));
}
}
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var styleStr = stylelist.join(";");
el.setAttribute("style", styleStr);
}
}
};
});
var sodaRender = function sodaRender(str, data) {
2017-04-20 17:46:08 +08:00
// 对directive进行排序
2017-04-19 10:20:03 +08:00
sodaDirectiveArr.sort(function (b, a) {
return Number(a.opt.priority || 0) - Number(b.opt.priority || 0);
});
//console.log(sodaDirectiveArr);
2017-04-20 17:46:08 +08:00
// 解析模板DOM
2017-04-19 10:20:03 +08:00
var div = document.createElement("div");
2017-04-20 17:46:08 +08:00
// 必须加入到body中去不然自定义标签不生效
if (document.documentMode < 9) {
div.style.display = 'none';
document.body.appendChild(div);
}
2017-04-19 10:20:03 +08:00
div.innerHTML = str;
2017-04-20 17:46:08 +08:00
nodes2Arr(div.childNodes).map(function (child) {
2017-04-19 10:20:03 +08:00
compileNode(child, data);
});
2017-04-20 17:46:08 +08:00
var innerHTML = div.innerHTML;
if (document.documentMode < 9) {
document.body.removeChild(div);
}
return innerHTML;
2017-04-19 10:20:03 +08:00
// var frament = document.createDocumentFragment();
// frament.innerHTML = div.innerHTML;
/*
frament.update = function(newData){
//checkingDirtyData(data, d);
var diff = DeepDiff.noConflict();
var diffResult = diff(data, newData);
console.log(diffResult);
var dirtyData = ['a'];
for(var i = 0; i < dirtyData.length; i ++){
var item = dirtyData[i];
var id = hashTable.expression2id[item];
var nowValue = parseSodaExpression(item, newData);
//console.log(nowValue);
if(id.el){
id.el.nodeValue = nowValue;
}
}
console.log(hashTable);
};
*/
var child;
while (child = div.childNodes[0]) {
frament.appendChild(child);
2017-01-21 14:01:46 +08:00
}
2017-04-19 10:20:03 +08:00
return frament;
2017-01-21 14:01:46 +08:00
};
2017-04-19 10:20:03 +08:00
var eventPool = {};
sodaRender.addEventListener = function (type, func) {
if (eventPool[type]) {} else {
eventPool[type] = [];
}
eventPool[type].push(func);
};
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var triggerEvent = function triggerEvent(type, e, data) {
var events = eventPool[type] || [];
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
for (var i = 0; i < events.length; i++) {
var eventFunc = events[i];
eventFunc && eventFunc(e, data);
2017-01-21 14:01:46 +08:00
}
};
2017-04-19 10:20:03 +08:00
sodaRender.filter = sodaFilter;
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
sodaRender.prefix = function (newPrefix) {
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
for (var key in sodaDirectiveMap) {
if (sodaDirectiveMap.hasOwnProperty(key)) {
sodaDirectiveMap[key.replace(prefix, newPrefix)] = sodaDirectiveMap[key];
delete sodaDirectiveMap[key];
}
}
var i = 0,
len = sodaDirectiveArr.length;
for (; i < len; i++) {
sodaDirectiveArr[i].name = sodaDirectiveArr[i].name.replace(prefix, newPrefix);
}
prefix = newPrefix;
prefixReg = new RegExp('^' + prefix + '-');
};
if (( false ? 'undefined' : _typeof(exports)) === 'object' && ( false ? 'undefined' : _typeof(module)) === 'object') module.exports = sodaRender;else if (true) !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function () {
return sodaRender;
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));else if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') exports["soda"] = sodaRender;else window.soda = sodaRender;
2017-04-20 17:46:08 +08:00
// 监听数据异常情况
2017-04-19 10:20:03 +08:00
})();
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)(module)))
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
/***/ }),
2017-01-21 14:01:46 +08:00
/* 3 */
2017-04-20 17:46:08 +08:00
/***/ (function(module, exports) {
2017-04-19 10:20:03 +08:00
module.exports = function(module) {
if(!module.webpackPolyfill) {
module.deprecate = function() {};
module.paths = [];
// module.parent = undefined by default
module.children = [];
module.webpackPolyfill = 1;
}
return module;
}
2017-04-20 17:46:08 +08:00
/***/ }),
2017-04-19 10:20:03 +08:00
/* 4 */
2017-04-20 17:46:08 +08:00
/***/ (function(module, exports, __webpack_require__) {
2017-01-21 14:01:46 +08:00
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _omi = __webpack_require__(1);
var _omi2 = _interopRequireDefault(_omi);
2017-04-19 10:20:03 +08:00
var _style = __webpack_require__(5);
2017-01-21 14:01:46 +08:00
var _style2 = _interopRequireDefault(_style);
2017-04-19 10:20:03 +08:00
var _event = __webpack_require__(6);
2017-01-21 14:01:46 +08:00
var _event2 = _interopRequireDefault(_event);
2017-04-19 10:20:03 +08:00
var _morphdom = __webpack_require__(7);
2017-01-21 14:01:46 +08:00
var _morphdom2 = _interopRequireDefault(_morphdom);
2017-01-21 14:01:46 +08:00
2017-04-19 10:20:03 +08:00
var _html2json = __webpack_require__(8);
var _html2json2 = _interopRequireDefault(_html2json);
2017-02-08 21:48:08 +08:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
2017-01-21 14:01:46 +08:00
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Component = function () {
2017-03-18 19:46:53 +08:00
function Component(data, option) {
2017-01-21 14:01:46 +08:00
_classCallCheck(this, Component);
2017-03-18 19:46:53 +08:00
var componentOption = Object.assign({
2017-03-20 01:14:35 +08:00
server: false,
2017-03-22 09:09:35 +08:00
ignoreStoreData: false,
preventSelfUpdate: false,
selfDataFirst: false,
domDiffDisabled: false,
scopedSelfCSS: false
2017-03-18 19:46:53 +08:00
}, option);
this._omi_scopedSelfCSS = componentOption.scopedSelfCSS;
2017-03-22 09:09:35 +08:00
this._omi_preventSelfUpdate = componentOption.preventSelfUpdate;
this._omi_domDiffDisabled = componentOption.domDiffDisabled;
2017-03-20 01:14:35 +08:00
this._omi_ignoreStoreData = componentOption.ignoreStoreData;
2017-07-01 09:56:39 +08:00
this.data = data || {};
this._omi_server_rendering = componentOption.server;
this.id = this._omi_server_rendering ? 1000000 + _omi2['default'].getInstanceId() : _omi2['default'].getInstanceId();
2017-02-05 13:29:14 +08:00
this.refs = {};
2017-01-21 14:01:46 +08:00
this.children = [];
2017-01-21 14:01:46 +08:00
this.HTML = null;
2017-02-08 21:48:08 +08:00
_omi2['default'].instances[this.id] = this;
this.selfDataFirst = componentOption.selfDataFirst;
2017-03-18 08:08:11 +08:00
2017-02-12 21:11:25 +08:00
this._omi_scoped_attr = _omi2['default'].STYLESCOPEDPREFIX + this.id;
2017-03-18 08:08:11 +08:00
//this.BODY_ELEMENT = document.createElement('body')
2017-02-04 18:10:54 +08:00
this._preCSS = null;
2017-02-15 10:00:20 +08:00
this._omiGroupDataCounter = {};
this._omi_installedHandlers = null;
2017-01-21 14:01:46 +08:00
}
_createClass(Component, [{
key: 'install',
value: function install() {}
}, {
key: 'installed',
value: function installed() {}
}, {
key: 'onInstalled',
value: function onInstalled(handler) {
if (!this._omi_installedHandlers) {
this._omi_installedHandlers = [];
}
this._omi_installedHandlers.push(handler);
}
}, {
key: '_execInstalledHandlers',
value: function _execInstalledHandlers() {
this._omi_installedHandlers && this._omi_installedHandlers.forEach(function (handler) {
handler();
});
}
2017-01-21 14:01:46 +08:00
}, {
key: 'uninstall',
value: function uninstall() {}
}, {
key: 'afterUpdate',
value: function afterUpdate() {}
}, {
key: 'beforeUpdate',
value: function beforeUpdate() {}
}, {
key: 'render',
value: function render() {}
}, {
key: 'style',
value: function style() {}
}, {
2017-03-22 08:45:47 +08:00
key: 'beforeRender',
value: function beforeRender() {}
2017-03-18 08:08:11 +08:00
}, {
key: 'useStore',
value: function useStore(store) {
var _this = this;
this.$$store = store;
2017-03-18 08:08:11 +08:00
var isInclude = false;
store.instances.forEach(function (instance) {
if (instance.id === _this.id) {
isInclude = true;
}
});
if (!isInclude) {
store.instances.push(this);
}
}
}, {
key: 'updateSelf',
value: function updateSelf() {
this.beforeUpdate();
if (this.renderTo) {
this._render(false, true);
} else {
if (this._omi_preventSelfUpdate) return;
// update child node
if (this._omi_removed) {
var hdNode = this._createHiddenNode();
this.node.parentNode.replaceChild(hdNode, this.node);
this.node = hdNode;
} else {
(0, _morphdom2['default'])(this.node, (0, _event2['default'])(this._childRender(this._omiChildStr, true), this.id), {
ignoreAttr: this._getIgnoreAttr()
});
this.node = document.querySelector("[" + this._omi_scoped_attr + "]");
this._queryElements(this);
this._fixForm();
}
}
this.afterUpdate();
}
2017-01-21 14:01:46 +08:00
}, {
key: 'update',
value: function update() {
this.beforeUpdate();
this._childrenBeforeUpdate(this);
2017-05-01 19:55:35 +08:00
this._omiGroupDataCounter = {};
2017-01-21 14:01:46 +08:00
if (this.renderTo) {
2017-07-01 09:56:39 +08:00
this._render(false, false, true);
2017-01-21 14:01:46 +08:00
} else {
2017-03-22 09:09:35 +08:00
if (this._omi_preventSelfUpdate) return;
2017-01-21 14:01:46 +08:00
// update child node
if (this._omi_removed) {
var hdNode = this._createHiddenNode();
this.node.parentNode.replaceChild(hdNode, this.node);
this.node = hdNode;
} else {
if (this._omi_domDiffDisabled) {
2017-07-01 09:56:39 +08:00
this.node.parentNode.replaceChild(_morphdom2['default'].toElement((0, _event2['default'])(this._childRender(this._omiChildStr, false, true), this.id)), this.node);
} else {
2017-07-01 09:56:39 +08:00
(0, _morphdom2['default'])(this.node, (0, _event2['default'])(this._childRender(this._omiChildStr, false, true), this.id));
}
2017-02-14 23:11:51 +08:00
this.node = document.querySelector("[" + this._omi_scoped_attr + "]");
this._queryElements(this);
this._fixForm();
2017-01-21 14:01:46 +08:00
}
}
2017-07-01 09:56:39 +08:00
//exec new element installed
this._childrenInstalledAfterUpdate(this);
this._childrenAfterUpdate(this);
2017-01-21 14:01:46 +08:00
this.afterUpdate();
}
}, {
key: '_childrenBeforeUpdate',
value: function _childrenBeforeUpdate(root) {
2017-03-18 08:08:11 +08:00
var _this2 = this;
root.children.forEach(function (child) {
child.beforeUpdate();
2017-05-01 19:55:35 +08:00
child._omiGroupDataCounter = {};
2017-03-18 08:08:11 +08:00
_this2._childrenBeforeUpdate(child);
});
}
}, {
key: '_childrenAfterUpdate',
value: function _childrenAfterUpdate(root) {
2017-03-18 08:08:11 +08:00
var _this3 = this;
root.children.forEach(function (child) {
2017-03-18 08:08:11 +08:00
_this3._childrenAfterUpdate(child);
child.afterUpdate();
});
}
2017-01-21 14:01:46 +08:00
}, {
key: 'setData',
value: function setData(data, update) {
this.data = data;
if (update) {
this.update();
}
}
}, {
key: 'removeChild',
value: function removeChild(indexOrChild) {
var child = indexOrChild;
if (typeof indexOrChild === 'number') {
child = this.children[indexOrChild];
}
child.remove();
}
}, {
key: 'restoreChild',
value: function restoreChild(indexOrChild) {
var child = indexOrChild;
if (typeof indexOrChild === 'number') {
child = this.children[indexOrChild];
}
child.restore();
}
}, {
key: 'remove',
value: function remove() {
this._omi_removed = true;
this.update();
this.uninstall();
}
}, {
key: 'restore',
value: function restore() {
this._omi_removed = false;
this.update();
this.installed();
this._execInstalledHandlers();
2017-01-21 14:01:46 +08:00
}
}, {
key: '_render',
2017-07-01 09:56:39 +08:00
value: function _render(isFirst, isSelf, fromUpdate) {
var _this4 = this;
2017-01-21 14:01:46 +08:00
if (this._omi_removed) {
var node = this._createHiddenNode();
if (!isFirst) {
this.node.parentNode.replaceChild(node, this.node);
this.node = node;
} else if (this.renderTo) {
this.renderTo.appendChild(node);
}
return;
}
if (this._omi_autoStoreToData) {
2017-03-20 01:14:35 +08:00
if (!this._omi_ignoreStoreData) {
this.data = this.$store.data;
}
}
2017-03-22 08:45:47 +08:00
this.beforeRender();
2017-01-21 14:01:46 +08:00
this._generateHTMLCSS();
if (!isSelf) {
2017-07-01 09:56:39 +08:00
this._extractChildren(this, fromUpdate);
} else {
2017-07-01 09:56:39 +08:00
this._extractChildrenString(this, fromUpdate);
}
2017-03-08 18:27:43 +08:00
this.children.forEach(function (item) {
_this4.HTML = _this4.HTML.replace(item._omiChildStr, isSelf ? item.node.outerHTML : item.HTML);
2017-01-21 14:01:46 +08:00
});
2017-02-08 21:48:08 +08:00
this.HTML = (0, _event2['default'])(this.HTML, this.id);
2017-01-21 14:01:46 +08:00
if (isFirst) {
if (this.renderTo) {
if (this._omi_increment) {
this.renderTo.insertAdjacentHTML('beforeend', this.HTML);
} else {
this.renderTo.innerHTML = this.HTML;
}
}
} else {
if (this.HTML !== "") {
if (this._omi_domDiffDisabled) {
this.renderTo.innerHTML = this.HTML;
} else {
(0, _morphdom2['default'])(this.node, this.HTML, isSelf ? {
ignoreAttr: this._getIgnoreAttr()
} : null);
}
2017-01-21 14:01:46 +08:00
} else {
(0, _morphdom2['default'])(this.node, this._createHiddenNode());
2017-01-21 14:01:46 +08:00
}
}
//get node prop from parent node
if (this.renderTo) {
2017-02-12 21:11:25 +08:00
this.node = document.querySelector("[" + this._omi_scoped_attr + "]");
2017-01-21 14:01:46 +08:00
this._queryElements(this);
this._fixForm();
}
}
}, {
key: '_getIgnoreAttr',
value: function _getIgnoreAttr() {
var arr = [];
this.children.forEach(function (child) {
arr.push(child._omi_scoped_attr);
});
return arr;
}
2017-01-21 14:01:46 +08:00
}, {
key: '_childRender',
2017-07-01 09:56:39 +08:00
value: function _childRender(childStr, isSelf, fromUpdate) {
var _this5 = this;
2017-01-21 14:01:46 +08:00
if (this._omi_removed) {
this.HTML = '<input type="hidden" omi_scoped_' + this.id + ' >';
return this.HTML;
}
2017-03-18 08:08:11 +08:00
//childStr = childStr.replace("<child", "<div").replace("/>", "></div>")
2017-02-20 10:10:42 +08:00
this._mergeData(childStr);
if (this.parent._omi_autoStoreToData) {
this._omi_autoStoreToData = true;
2017-03-20 01:14:35 +08:00
if (!this._omi_ignoreStoreData) {
this.data = this.$store.data;
}
}
2017-03-22 08:45:47 +08:00
this.beforeRender();
2017-04-06 21:15:09 +08:00
this._fixSlot(this._generateHTMLCSS());
if (!isSelf) {
2017-07-01 09:56:39 +08:00
this._extractChildren(this, fromUpdate);
} else {
2017-07-01 09:56:39 +08:00
this._extractChildrenString(this, fromUpdate);
}
2017-03-08 18:27:43 +08:00
this.children.forEach(function (item) {
_this5.HTML = _this5.HTML.replace(item._omiChildStr, isSelf ? item.node.outerHTML : item.HTML);
2017-01-21 14:01:46 +08:00
});
2017-02-08 21:48:08 +08:00
this.HTML = (0, _event2['default'])(this.HTML, this.id);
2017-01-21 14:01:46 +08:00
return this.HTML;
}
2017-04-06 21:15:09 +08:00
}, {
key: '_fixSlot',
value: function _fixSlot(shareAttr) {
var _this6 = this;
if (!this._omi_slotContent) return;
2017-04-06 21:15:09 +08:00
this._omi_slotContent = this._scopedAttr(this._omi_slotContent, this._omi_scoped_attr, shareAttr);
var nodes = _morphdom2['default'].toElements(this._omi_slotContent);
var slotMatch = this.HTML.match(/<slot[\s\S]*?<\/slot>/g);
if (nodes.length === 1 && slotMatch && slotMatch.length === 1) {
this.HTML = this.HTML.replace(/<slot[\s\S]*?<\/slot>/, this._omi_slotContent);
} else {
nodes.sort(function (a, b) {
return parseInt(a.getAttribute('slot-index')) - parseInt(b.getAttribute('slot-index'));
});
nodes.forEach(function (node) {
_this6.HTML = _this6.HTML.replace(/<slot[\s\S]*?<\/slot>/, node.outerHTML);
});
}
}
2017-01-21 14:01:46 +08:00
}, {
key: '_queryElements',
value: function _queryElements(current) {
current._mixRefs();
2017-02-12 21:11:25 +08:00
current._execPlugins();
2017-01-21 14:01:46 +08:00
current.children.forEach(function (item) {
2017-02-08 21:48:08 +08:00
item.node = current.node.querySelector("[" + _omi2['default'].STYLESCOPEDPREFIX + item.id + "]");
2017-01-21 14:01:46 +08:00
//recursion get node prop from parent node
2017-03-08 18:27:43 +08:00
item.node && current._queryElements(item);
2017-01-21 14:01:46 +08:00
});
}
}, {
key: '_mixRefs',
value: function _mixRefs() {
2017-04-06 21:15:09 +08:00
var _this7 = this;
2017-02-12 21:11:25 +08:00
var nodes = _omi2['default'].$$('*[ref]', this.node);
nodes.forEach(function (node) {
2017-04-06 21:15:09 +08:00
if (node.hasAttribute(_this7._omi_scoped_attr)) {
_this7.refs[node.getAttribute('ref')] = node;
2017-01-21 14:01:46 +08:00
}
2017-02-12 21:11:25 +08:00
});
var attr = this.node.getAttribute('ref');
if (attr) {
this.refs[attr] = this.node;
}
2017-02-12 21:11:25 +08:00
}
}, {
key: '_execPlugins',
value: function _execPlugins() {
2017-04-06 21:15:09 +08:00
var _this8 = this;
2017-02-12 21:11:25 +08:00
Object.keys(_omi2['default'].plugins).forEach(function (item) {
2017-04-06 21:15:09 +08:00
var nodes = _omi2['default'].$$('*[' + item + ']', _this8.node);
2017-02-12 21:11:25 +08:00
nodes.forEach(function (node) {
2017-04-06 21:15:09 +08:00
if (node.hasAttribute(_this8._omi_scoped_attr)) {
_omi2['default'].plugins[item](node, _this8);
2017-02-12 21:11:25 +08:00
}
});
2017-04-06 21:15:09 +08:00
if (_this8.node.hasAttribute(item)) {
_omi2['default'].plugins[item](_this8.node, _this8);
}
2017-02-12 21:11:25 +08:00
});
2017-01-21 14:01:46 +08:00
}
2017-07-01 09:56:39 +08:00
}, {
key: '_childrenInstalled',
value: function _childrenInstalled(root) {
var _this9 = this;
root.children.forEach(function (child) {
_this9._childrenInstalled(child);
child.installed();
child._execInstalledHandlers();
});
}
}, {
key: '_childrenInstalledAfterUpdate',
value: function _childrenInstalledAfterUpdate(root) {
var _this10 = this;
root.children.forEach(function (child) {
if (child._omi_needInstalled) {
child._omi_needInstalled = false;
_this10._childrenInstalled(child);
child.installed();
child._execInstalledHandlers();
}
});
}
2017-01-21 14:01:46 +08:00
}, {
key: '_fixForm',
value: function _fixForm() {
2017-01-23 10:45:19 +08:00
2017-02-08 21:48:08 +08:00
_omi2['default'].$$('input', this.node).forEach(function (element) {
2017-01-21 14:01:46 +08:00
var type = element.type.toLowerCase();
if (element.getAttribute('value') === '') {
element.value = '';
}
if (type === 'checked' || type === 'radio') {
if (element.hasAttribute('checked')) {
element.checked = 'checked';
} else {
element.checked = false;
}
}
2017-01-23 10:45:19 +08:00
});
2017-02-17 11:32:16 +08:00
_omi2['default'].$$('textarea', this.node).forEach(function (textarea) {
textarea.value = textarea.getAttribute('value');
});
2017-02-08 21:48:08 +08:00
_omi2['default'].$$('select', this.node).forEach(function (select) {
2017-01-23 10:45:19 +08:00
var value = select.getAttribute('value');
if (value) {
2017-02-08 21:48:08 +08:00
_omi2['default'].$$('option', select).forEach(function (option) {
2017-01-23 10:45:19 +08:00
if (value === option.getAttribute('value')) {
option.setAttribute('selected', 'selected');
}
});
} else {
2017-02-08 21:48:08 +08:00
var firstOption = _omi2['default'].$$('option', select)[0];
2017-01-23 10:45:19 +08:00
firstOption && firstOption.setAttribute('selected', 'selected');
}
});
2017-01-21 14:01:46 +08:00
}
}, {
key: '_replaceTags',
2017-07-01 09:56:39 +08:00
value: function _replaceTags(array, html, updateSelf, fromUpdate) {
var _this11 = this;
2017-04-06 21:15:09 +08:00
if (_omi2['default'].customTags.length === 0) return;
2017-01-21 14:01:46 +08:00
var str = array.join("|");
2017-04-06 21:15:09 +08:00
var reg = new RegExp('<(' + str + '+)((?:\\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\\s*=\\s*(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>\\s]+))?)*)\\s*((\\/>)|>(([\\s\\S]*?)<\\/\\1>))', 'g');
var index = 0;
return html.replace(reg, function (m, a, b, c, d, e, f) {
if (updateSelf) {
2017-07-01 09:56:39 +08:00
var cmi = _this11.children[index];
2017-04-06 21:15:09 +08:00
if (cmi && cmi.___omi_constructor_name === a) {
cmi._omiChildStr = m;
}
} else {
2017-07-01 09:56:39 +08:00
_this11._initComponentByString(a, m, f, index++, _this11, fromUpdate);
}
2017-01-21 14:01:46 +08:00
});
}
}, {
key: '_createHiddenNode',
value: function _createHiddenNode() {
var hdNode = document.createElement("input");
hdNode.setAttribute("type", "hidden");
2017-02-12 21:11:25 +08:00
hdNode.setAttribute(this._omi_scoped_attr, '');
2017-01-21 14:01:46 +08:00
return hdNode;
}
}, {
key: '_mergeData',
2017-02-20 10:10:42 +08:00
value: function _mergeData(childStr) {
if (this.selfDataFirst) {
2017-02-20 10:10:42 +08:00
this.data = Object.assign({}, this._getDataset(childStr), this.data);
2017-02-08 23:12:43 +08:00
} else {
2017-02-20 10:10:42 +08:00
this.data = Object.assign({}, this.data, this._getDataset(childStr));
2017-02-08 23:12:43 +08:00
}
2017-01-21 14:01:46 +08:00
}
}, {
key: '_generateHTMLCSS',
2017-02-08 09:44:31 +08:00
value: function _generateHTMLCSS() {
this.CSS = (this.style() || '').replace(/<\/?style>/g, '');
var shareAttr = this.___omi_constructor_name ? _omi2['default'].STYLESCOPEDPREFIX + this.___omi_constructor_name.toLowerCase() : this._omi_scoped_attr;
2017-01-21 14:01:46 +08:00
if (this.CSS) {
if (this._omi_scopedSelfCSS || !_omi2['default'].style[shareAttr]) {
this.CSS = _style2['default'].scoper(this.CSS, this._omi_scopedSelfCSS ? "[" + this._omi_scoped_attr + "]" : "[" + shareAttr + "]");
_omi2['default'].style[shareAttr] = this.CSS;
if (this.CSS !== this._preCSS && !this._omi_server_rendering) {
_style2['default'].addStyle(this.CSS, this.id);
this._preCSS = this.CSS;
}
2017-01-21 14:01:46 +08:00
}
}
var tpl = this.render();
this.HTML = this._scopedAttr(_omi2['default'].template(tpl ? tpl : "", this.data), this._omi_scoped_attr, shareAttr).trim();
2017-01-21 14:01:46 +08:00
if (this._omi_server_rendering) {
2017-02-08 21:48:08 +08:00
this.HTML = '\r\n<style id="' + _omi2['default'].STYLEPREFIX + this.id + '">\r\n' + this.CSS + '\r\n</style>\r\n' + this.HTML;
this.HTML += '\r\n<input type="hidden" data-omi-id="' + this.id + '" class="' + _omi2['default'].STYLESCOPEDPREFIX + '_hidden_data" value=\'' + JSON.stringify(this.data) + '\' />\r\n';
2017-01-21 14:01:46 +08:00
}
2017-04-06 21:15:09 +08:00
return shareAttr;
2017-01-21 14:01:46 +08:00
}
}, {
key: '_scopedAttr',
value: function _scopedAttr(html, id, shareAtrr) {
2017-07-01 09:56:39 +08:00
var _this12 = this;
2017-01-21 14:01:46 +08:00
return html.replace(/<[^/]([A-Za-z]*)[^>]*>/g, function (m) {
var str = m.split(" ")[0].replace(">", "");
2017-07-01 09:56:39 +08:00
if (_this12._omi_scopedSelfCSS || !_this12.___omi_constructor_name) {
return m.replace(str, str + " " + id);
} else {
return m.replace(str, str + " " + id + " " + shareAtrr);
}
2017-01-21 14:01:46 +08:00
});
}
}, {
key: '_getDataset',
value: function _getDataset(childStr) {
2017-07-01 09:56:39 +08:00
var _this13 = this;
2017-02-08 21:48:08 +08:00
var json = (0, _html2json2['default'])(childStr);
var attr = json.child[0].attr;
var baseData = {};
Object.keys(attr).forEach(function (key) {
var value = attr[key];
if (key.indexOf('on') === 0) {
2017-07-01 09:56:39 +08:00
var handler = _this13.parent[value];
if (handler) {
2017-07-01 09:56:39 +08:00
baseData[_this13._capitalize(key)] = handler.bind(_this13.parent);
}
} else if (key.indexOf('data-') === 0) {
2017-07-01 09:56:39 +08:00
_this13._dataset[_this13._capitalize(key.replace('data-', ''))] = value;
} else if (key.indexOf(':data-') === 0) {
2017-07-01 09:56:39 +08:00
_this13._dataset[_this13._capitalize(key.replace(':data-', ''))] = eval('(' + value + ')');
} else if (key.indexOf('::data-') === 0) {
2017-07-01 09:56:39 +08:00
_this13._dataset[_this13._capitalize(key.replace('::data-', ''))] = _this13._extractPropertyFromString(value, _this13.parent);
} else if (key === 'data') {
2017-07-01 09:56:39 +08:00
_this13._dataset = _this13._extractPropertyFromString(value, _this13.parent);
} else if (key === ':data') {
2017-07-01 09:56:39 +08:00
_this13._dataset = eval('(' + value + ')');
} else if (key === 'group-data') {
2017-07-01 09:56:39 +08:00
_this13._dataset = _this13._extractPropertyFromString(value, _this13.parent)[_this13._omi_groupDataIndex];
}
});
return Object.assign(baseData, this._dataset);
2017-02-08 21:48:08 +08:00
}
}, {
key: '_capitalize',
value: function _capitalize(str) {
str = str.toLowerCase();
str = str.replace(/\b\w+\b/g, function (word) {
return word.substring(0, 1).toUpperCase() + word.substring(1);
}).replace(/-/g, '');
return str.substring(0, 1).toLowerCase() + str.substring(1);
2017-01-21 14:01:46 +08:00
}
}, {
key: '_extractPropertyFromString',
value: function _extractPropertyFromString(str, instance) {
var arr = str.replace(/['|"|\]]/g, '').replace(/\[/g, '.').split('.');
var current = instance;
arr.forEach(function (prop) {
current = current[prop];
});
arr = null;
return current;
}
2017-01-21 14:01:46 +08:00
}, {
key: '_extractChildrenString',
2017-07-01 09:56:39 +08:00
value: function _extractChildrenString(child, fromUpdate) {
this._replaceTags(_omi2['default'].customTags, child.HTML, true, fromUpdate);
}
}, {
key: '_extractChildren',
2017-07-01 09:56:39 +08:00
value: function _extractChildren(child, fromUpdate) {
this._replaceTags(_omi2['default'].customTags, child.HTML, false, fromUpdate);
2017-04-06 21:15:09 +08:00
}
}, {
key: '_initComponentByString',
2017-07-01 09:56:39 +08:00
value: function _initComponentByString(name, childStr, slotContent, i, child, fromUpdate) {
var _this14 = this;
2017-04-06 21:15:09 +08:00
var json = (0, _html2json2['default'])(childStr);
var attr = json.child[0].attr;
var cmi = this.children[i];
//if not first time to invoke _extractChildren method
if (cmi && cmi.___omi_constructor_name === name) {
cmi._omiChildStr = childStr;
cmi._omi_slotContent = slotContent;
Object.keys(attr).forEach(function (key) {
var value = attr[key];
if (key === 'group-data') {
if (child._omiGroupDataCounter.hasOwnProperty(value)) {
child._omiGroupDataCounter[value]++;
} else {
child._omiGroupDataCounter[value] = 0;
}
cmi._omi_groupDataIndex = child._omiGroupDataCounter[value];
}
});
2017-04-06 21:15:09 +08:00
cmi._childRender(childStr);
} else {
2017-04-20 17:46:08 +08:00
var baseData = {};
var dataset = {};
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
var groupDataIndex = null;
var omiID = null;
var instanceName = null;
var _omi_option = {};
Object.keys(attr).forEach(function (key) {
var value = attr[key];
if (key.indexOf('on') === 0) {
var handler = child[value];
if (handler) {
2017-07-01 09:56:39 +08:00
baseData[_this14._capitalize(key)] = handler.bind(child);
2017-04-20 17:46:08 +08:00
}
} else if (key === 'omi-id') {
omiID = value;
} else if (key === 'name') {
instanceName = value;
} else if (key === 'group-data') {
if (child._omiGroupDataCounter.hasOwnProperty(value)) {
child._omiGroupDataCounter[value]++;
} else {
child._omiGroupDataCounter[value] = 0;
}
groupDataIndex = child._omiGroupDataCounter[value];
2017-07-01 09:56:39 +08:00
dataset = _this14._extractPropertyFromString(value, child)[groupDataIndex];
2017-04-20 17:46:08 +08:00
} else if (key.indexOf('data-') === 0) {
2017-07-01 09:56:39 +08:00
dataset[_this14._capitalize(key.replace('data-', ''))] = value;
2017-04-20 17:46:08 +08:00
} else if (key.indexOf(':data-') === 0) {
2017-07-01 09:56:39 +08:00
dataset[_this14._capitalize(key.replace(':data-', ''))] = eval('(' + value + ')');
} else if (key.indexOf('::data-') === 0) {
2017-07-01 09:56:39 +08:00
dataset[_this14._capitalize(key.replace('::data-', ''))] = _this14._extractPropertyFromString(value, child);
2017-04-20 17:46:08 +08:00
} else if (key === 'data') {
2017-07-01 09:56:39 +08:00
dataset = _this14._extractPropertyFromString(value, child);
} else if (key === ':data') {
dataset = eval('(' + value + ')');
} else if (key === 'preventSelfUpdate' || key === 'psu' || key === 'preventselfupdate') {
2017-04-20 17:46:08 +08:00
_omi_option.preventSelfUpdate = true;
} else if (key === 'selfDataFirst' || key === 'sdf' || key === 'selfdatafirst') {
2017-04-20 17:46:08 +08:00
_omi_option.selfDataFirst = true;
} else if (key === 'domDiffDisabled' || key === 'ddd' || key === 'domdiffdisabled') {
2017-04-20 17:46:08 +08:00
_omi_option.domDiffDisabled = true;
} else if (key === 'ignoreStoreData' || key === 'isd' || key === 'ignorestoredata') {
2017-04-20 17:46:08 +08:00
_omi_option.ignoreStoreData = true;
} else if (key === 'scopedSelfCSS' || key === 'ssc' || key === 'scopedselfcss') {
2017-04-20 17:46:08 +08:00
_omi_option.scopedSelfCSS = true;
2017-01-21 14:01:46 +08:00
}
2017-04-20 17:46:08 +08:00
});
var ChildClass = _omi2['default'].getClassFromString(name);
if (!ChildClass) throw "Can't find Class called [" + name + "]";
var sub_child = new ChildClass(Object.assign(baseData, dataset), _omi_option);
2017-04-20 17:46:08 +08:00
sub_child._omi_groupDataIndex = groupDataIndex;
sub_child._omiChildStr = childStr;
sub_child._omi_slotContent = slotContent;
sub_child.parent = child;
sub_child.$store = child.$store;
sub_child.___omi_constructor_name = name;
sub_child._dataset = {};
sub_child.install();
omiID && (_omi2['default'].mapping[omiID] = sub_child);
instanceName && (child[instanceName] = sub_child);
if (!cmi) {
child.children.push(sub_child);
} else {
child.children[i] = sub_child;
}
2017-04-06 21:15:09 +08:00
2017-04-20 17:46:08 +08:00
sub_child._childRender(childStr);
2017-07-01 09:02:05 +08:00
2017-07-01 09:56:39 +08:00
if (fromUpdate) {
sub_child._omi_needInstalled = true;
}
2017-01-21 14:01:46 +08:00
}
}
}]);
return Component;
}();
2017-02-08 21:48:08 +08:00
exports['default'] = Component;
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
/***/ }),
2017-04-19 10:20:03 +08:00
/* 5 */
2017-04-20 17:46:08 +08:00
/***/ (function(module, exports, __webpack_require__) {
2017-01-21 14:01:46 +08:00
'use strict';
2017-01-21 14:01:46 +08:00
Object.defineProperty(exports, "__esModule", {
value: true
});
var _omi = __webpack_require__(1);
var _omi2 = _interopRequireDefault(_omi);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
2017-01-21 14:01:46 +08:00
//many thanks to https://github.com/thomaspark/scoper/
function scoper(css, prefix) {
//https://www.w3.org/TR/css-syntax-3/#lexical
css = css.replace(/\/\*[^*]*\*+([^/][^*]*\*+)*\//g, '');
var re = new RegExp("([^\r\n,{}:]+)(:[^\r\n,{}]+)?(,(?=[^{}]*{)|\s*{)", "g");
2017-03-22 15:12:26 +08:00
/**
* Example:
*
* .classname::pesudo { color:red }
*
* g1 is normal selector `.classname`
* g2 is pesudo class or pesudo element
* g3 is the suffix
*/
css = css.replace(re, function (g0, g1, g2, g3) {
if (typeof g2 === "undefined") {
g2 = "";
2017-01-21 14:01:46 +08:00
}
2017-07-01 09:02:05 +08:00
if (g1.match(/^\s*(@media|\d+%?|@-webkit-keyframes|@keyframes|to|from|@font-face)/)) {
2017-03-22 15:12:26 +08:00
return g1 + g2 + g3;
2017-01-21 14:01:46 +08:00
}
2017-03-22 15:12:26 +08:00
var appendClass = g1.replace(/(\s*)$/, "") + prefix + g2;
var prependClass = prefix + " " + g1.trim() + g2;
return appendClass + "," + prependClass + g3;
2017-01-21 14:01:46 +08:00
});
return css;
}
function addStyle(cssText, id) {
var ele = document.getElementById(_omi2['default'].STYLEPREFIX + id),
2017-01-21 14:01:46 +08:00
head = document.getElementsByTagName('head')[0];
if (ele && ele.parentNode === head) {
head.removeChild(ele);
}
var someThingStyles = document.createElement('style');
head.appendChild(someThingStyles);
someThingStyles.setAttribute('type', 'text/css');
someThingStyles.setAttribute('id', _omi2['default'].STYLEPREFIX + id);
2017-01-21 14:01:46 +08:00
if (!!window.ActiveXObject) {
someThingStyles.styleSheet.cssText = cssText;
} else {
someThingStyles.textContent = cssText;
}
}
exports['default'] = {
2017-01-21 14:01:46 +08:00
scoper: scoper,
addStyle: addStyle
};
2017-04-20 17:46:08 +08:00
/***/ }),
2017-04-19 10:20:03 +08:00
/* 6 */
2017-04-20 17:46:08 +08:00
/***/ (function(module, exports) {
2017-01-21 14:01:46 +08:00
2017-02-19 10:28:59 +08:00
'use strict';
2017-01-21 14:01:46 +08:00
Object.defineProperty(exports, "__esModule", {
value: true
});
function scopedEvent(tpl, id) {
2017-03-10 11:40:23 +08:00
return tpl.replace(/<[\s\S]*?>/g, function (item) {
return item.replace(/on(abort|blur|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|dblclick|drag|dragend|dragenter|dragleave|dragover|dragstart|drop|durationchange|emptied|ended|error|focus|input|invalid|keydown|keypress|keyup|load|loadeddata|loadedmetadata|loadstart|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|pause|play|playing|progress|ratechange|reset|resize|scroll|seeked|seeking|select|show|stalled|submit|suspend|timeupdate|toggle|volumechange|waiting|autocomplete|autocompleteerror|beforecopy|beforecut|beforepaste|copy|cut|paste|search|selectstart|wheel|webkitfullscreenchange|webkitfullscreenerror|touchstart|touchmove|touchend|touchcancel|pointerdown|pointerup|pointercancel|pointermove|pointerover|pointerout|pointerenter|pointerleave|Abort|Blur|Cancel|CanPlay|CanPlayThrough|Change|Click|Close|ContextMenu|CueChange|DblClick|Drag|DragEnd|DragEnter|DragLeave|DragOver|DragStart|Drop|DurationChange|Emptied|Ended|Error|Focus|Input|Invalid|KeyDown|KeyPress|KeyUp|Load|LoadedData|LoadedMetadata|LoadStart|MouseDown|MouseEnter|MouseLeave|MouseMove|MouseOut|MouseOver|MouseUp|MouseWheel|Pause|Play|Playing|Progress|RateChange|Reset|Resize|Scroll|Seeked|Seeking|Select|Show|Stalled|Submit|Suspend|TimeUpdate|Toggle|VolumeChange|Waiting|AutoComplete|AutoCompleteError|BeforeCopy|BeforeCut|BeforePaste|Copy|Cut|Paste|Search|SelectStart|Wheel|WebkitFullScreenChange|WebkitFullScreenError|TouchStart|TouchMove|TouchEnd|TouchCancel|PointerDown|PointerUp|PointerCancel|PointerMove|PointerOver|PointerOut|PointerEnter|PointerLeave)=(('([\s\S]*?)')|("([\s\S]*?)"))/g, function (eventStr, b, c) {
if (c.indexOf('Omi.instances[') === 1) {
2017-02-19 10:28:59 +08:00
return eventStr;
} else if (c.lastIndexOf(')') === c.length - 2) {
2017-03-10 11:40:23 +08:00
return eventStr.replace(/=(['|"])/, '=$1Omi.instances[' + id + '].');
} else {
var str = eventStr.replace(/=(['|"])/, '=$1Omi.instances[' + id + '].');
return str.substr(0, str.length - 1) + "(event)" + str.substr(str.length - 1, 1);
2017-02-19 10:28:59 +08:00
}
2017-01-21 14:01:46 +08:00
});
});
2017-03-18 08:08:11 +08:00
}
2017-01-21 14:01:46 +08:00
2017-02-19 10:28:59 +08:00
exports['default'] = scopedEvent;
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
/***/ }),
2017-04-19 10:20:03 +08:00
/* 7 */
2017-04-20 17:46:08 +08:00
/***/ (function(module, exports, __webpack_require__) {
2017-01-21 14:01:46 +08:00
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;'use strict';
2017-01-21 14:01:46 +08:00
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
2017-02-08 21:48:08 +08:00
(function (global, factory) {
( false ? 'undefined' : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : true ? !(__WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)) : global.morphdom = factory();
})(undefined, function () {
'use strict';
var range; // Create a range object for efficently rendering strings to elements.
var NS_XHTML = 'http://www.w3.org/1999/xhtml';
var doc = typeof document === 'undefined' ? undefined : document;
var testEl = doc ? doc.body || doc.createElement('div') : {};
// Fixes <https://github.com/patrick-steele-idem/morphdom/issues/32>
// (IE7+ support) <=IE7 does not support el.hasAttribute(name)
var actualHasAttributeNS;
if (testEl.hasAttributeNS) {
actualHasAttributeNS = function actualHasAttributeNS(el, namespaceURI, name) {
return el.hasAttributeNS(namespaceURI, name);
};
} else if (testEl.hasAttribute) {
actualHasAttributeNS = function actualHasAttributeNS(el, namespaceURI, name) {
return el.hasAttribute(name);
};
} else {
actualHasAttributeNS = function actualHasAttributeNS(el, namespaceURI, name) {
return el.getAttributeNode(namespaceURI, name) != null;
};
}
var hasAttributeNS = actualHasAttributeNS;
function toElement(str) {
if (!range && doc.createRange) {
range = doc.createRange();
range.selectNode(doc.body);
}
var fragment;
if (range && range.createContextualFragment) {
fragment = range.createContextualFragment(str);
2017-01-21 14:01:46 +08:00
} else {
fragment = doc.createElement('body');
fragment.innerHTML = str;
2017-01-21 14:01:46 +08:00
}
return fragment.childNodes[0];
2017-01-21 14:01:46 +08:00
}
2017-04-06 21:15:09 +08:00
function toElements(str) {
if (!range && doc.createRange) {
range = doc.createRange();
range.selectNode(doc.body);
}
var fragment;
if (range && range.createContextualFragment) {
fragment = range.createContextualFragment(str);
} else {
fragment = doc.createElement('body');
fragment.innerHTML = str;
}
var arr = [],
i = 0,
len = fragment.childNodes.length;
for (; i < len; i++) {
var item = fragment.childNodes[i];
if (item.nodeType === 1) {
arr.push(item);
}
}
return arr;
}
2017-04-19 10:20:03 +08:00
/**
* Returns true if two node's names are the same.
*
* NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same
* nodeName and different namespace URIs.
*
* @param {Element} a
* @param {Element} b The target element
* @return {boolean}
*/
function compareNodeNames(fromEl, toEl) {
var fromNodeName = fromEl.nodeName;
var toNodeName = toEl.nodeName;
2017-01-21 14:01:46 +08:00
if (fromNodeName === toNodeName) {
return true;
}
if (toEl.actualize && fromNodeName.charCodeAt(0) < 91 && /* from tag name is upper case */
toNodeName.charCodeAt(0) > 90 /* target tag name is lower case */) {
// If the target element is a virtual DOM node then we may need to normalize the tag name
// before comparing. Normal HTML elements that are in the "http://www.w3.org/1999/xhtml"
// are converted to upper case
return fromNodeName === toNodeName.toUpperCase();
} else {
return false;
2017-01-21 14:01:46 +08:00
}
}
2017-04-19 10:20:03 +08:00
/**
* Create an element, optionally with a known namespace URI.
*
* @param {string} name the element name, e.g. 'div' or 'svg'
* @param {string} [namespaceURI] the element's namespace URI, i.e. the value of
* its `xmlns` attribute or its inferred namespace.
*
* @return {Element}
*/
function createElementNS(name, namespaceURI) {
return !namespaceURI || namespaceURI === NS_XHTML ? doc.createElement(name) : doc.createElementNS(namespaceURI, name);
2017-01-21 14:01:46 +08:00
}
2017-04-19 10:20:03 +08:00
/**
* Copies the children of one DOM element to another DOM element
*/
function moveChildren(fromEl, toEl) {
var curChild = fromEl.firstChild;
while (curChild) {
var nextChild = curChild.nextSibling;
toEl.appendChild(curChild);
curChild = nextChild;
2017-01-21 14:01:46 +08:00
}
return toEl;
2017-01-21 14:01:46 +08:00
}
function morphAttrs(fromNode, toNode) {
var attrs = toNode.attributes;
var i;
var attr;
var attrName;
var attrNamespaceURI;
var attrValue;
var fromValue;
for (i = attrs.length - 1; i >= 0; --i) {
attr = attrs[i];
attrName = attr.name;
attrNamespaceURI = attr.namespaceURI;
attrValue = attr.value;
if (attrNamespaceURI) {
attrName = attr.localName || attrName;
fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrName);
if (fromValue !== attrValue) {
fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue);
}
} else {
fromValue = fromNode.getAttribute(attrName);
2017-01-21 14:01:46 +08:00
if (fromValue !== attrValue) {
fromNode.setAttribute(attrName, attrValue);
}
}
}
// Remove any extra attributes found on the original DOM element that
// weren't found on the target element.
attrs = fromNode.attributes;
2017-01-21 14:01:46 +08:00
for (i = attrs.length - 1; i >= 0; --i) {
attr = attrs[i];
if (attr.specified !== false) {
attrName = attr.name;
attrNamespaceURI = attr.namespaceURI;
if (attrNamespaceURI) {
attrName = attr.localName || attrName;
if (!hasAttributeNS(toNode, attrNamespaceURI, attrName)) {
fromNode.removeAttributeNS(attrNamespaceURI, attrName);
}
} else {
if (!hasAttributeNS(toNode, null, attrName)) {
fromNode.removeAttribute(attrName);
}
}
}
}
2017-01-21 14:01:46 +08:00
}
function syncBooleanAttrProp(fromEl, toEl, name) {
if (fromEl[name] !== toEl[name]) {
fromEl[name] = toEl[name];
if (fromEl[name]) {
fromEl.setAttribute(name, '');
} else {
fromEl.removeAttribute(name, '');
}
2017-01-21 14:01:46 +08:00
}
}
var specialElHandlers = {
2017-04-19 10:20:03 +08:00
/**
* Needed for IE. Apparently IE doesn't think that "selected" is an
* attribute when reading over the attributes using selectEl.attributes
*/
OPTION: function OPTION(fromEl, toEl) {
syncBooleanAttrProp(fromEl, toEl, 'selected');
},
2017-04-19 10:20:03 +08:00
/**
* The "value" attribute is special for the <input> element since it sets
* the initial value. Changing the "value" attribute without changing the
* "value" property will have no effect since it is only used to the set the
* initial value. Similar for the "checked" attribute, and "disabled".
*/
INPUT: function INPUT(fromEl, toEl) {
syncBooleanAttrProp(fromEl, toEl, 'checked');
syncBooleanAttrProp(fromEl, toEl, 'disabled');
if (fromEl.value !== toEl.value) {
fromEl.value = toEl.value;
}
if (!hasAttributeNS(toEl, null, 'value')) {
fromEl.removeAttribute('value');
}
},
TEXTAREA: function TEXTAREA(fromEl, toEl) {
var newValue = toEl.value;
if (fromEl.value !== newValue) {
fromEl.value = newValue;
}
if (fromEl.firstChild) {
// Needed for IE. Apparently IE sets the placeholder as the
// node value and vise versa. This ignores an empty update.
if (newValue === '' && fromEl.firstChild.nodeValue === fromEl.placeholder) {
return;
}
fromEl.firstChild.nodeValue = newValue;
}
},
SELECT: function SELECT(fromEl, toEl) {
if (!hasAttributeNS(toEl, null, 'multiple')) {
var selectedIndex = -1;
var i = 0;
var curChild = toEl.firstChild;
while (curChild) {
var nodeName = curChild.nodeName;
if (nodeName && nodeName.toUpperCase() === 'OPTION') {
if (hasAttributeNS(curChild, null, 'selected')) {
selectedIndex = i;
break;
}
i++;
}
curChild = curChild.nextSibling;
}
fromEl.selectedIndex = i;
}
}
};
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var COMMENT_NODE = 8;
function noop() {}
2017-01-21 14:01:46 +08:00
function defaultGetNodeKey(node) {
return node.id;
2017-01-21 14:01:46 +08:00
}
function morphdomFactory(morphAttrs) {
2017-01-21 14:01:46 +08:00
return function morphdom(fromNode, toNode, options) {
if (!options) {
options = {};
}
2017-01-21 14:01:46 +08:00
if (typeof toNode === 'string') {
if (fromNode.nodeName === '#document' || fromNode.nodeName === 'HTML') {
var toNodeHtml = toNode;
toNode = doc.createElement('html');
toNode.innerHTML = toNodeHtml;
} else {
toNode = toElement(toNode);
}
}
var getNodeKey = options.getNodeKey || defaultGetNodeKey;
var onBeforeNodeAdded = options.onBeforeNodeAdded || noop;
var onNodeAdded = options.onNodeAdded || noop;
var onBeforeElUpdated = options.onBeforeElUpdated || noop;
var onElUpdated = options.onElUpdated || noop;
var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop;
var onNodeDiscarded = options.onNodeDiscarded || noop;
var onBeforeElChildrenUpdated = options.onBeforeElChildrenUpdated || noop;
var childrenOnly = options.childrenOnly === true;
var ignoreAttr = options.ignoreAttr;
// This object is used as a lookup to quickly find all keyed elements in the original DOM tree.
var fromNodesLookup = {};
var keyedRemovalList;
function addKeyedRemoval(key) {
if (keyedRemovalList) {
keyedRemovalList.push(key);
} else {
keyedRemovalList = [key];
}
}
function walkDiscardedChildNodes(node, skipKeyedNodes) {
if (node.nodeType === ELEMENT_NODE) {
var curChild = node.firstChild;
while (curChild) {
var key = undefined;
if (skipKeyedNodes && (key = getNodeKey(curChild))) {
// If we are skipping keyed nodes then we add the key
// to a list so that it can be handled at the very end.
addKeyedRemoval(key);
} else {
// Only report the node as discarded if it is not keyed. We do this because
// at the end we loop through all keyed elements that were unmatched
// and then discard them in one final pass.
onNodeDiscarded(curChild);
if (curChild.firstChild) {
walkDiscardedChildNodes(curChild, skipKeyedNodes);
}
}
curChild = curChild.nextSibling;
}
}
}
2017-04-19 10:20:03 +08:00
/**
* Removes a DOM node out of the original DOM
*
* @param {Node} node The node to remove
* @param {Node} parentNode The nodes parent
* @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded.
* @return {undefined}
*/
function removeNode(node, parentNode, skipKeyedNodes) {
if (onBeforeNodeDiscarded(node) === false) {
return;
}
if (parentNode) {
parentNode.removeChild(node);
}
onNodeDiscarded(node);
walkDiscardedChildNodes(node, skipKeyedNodes);
}
// // TreeWalker implementation is no faster, but keeping this around in case this changes in the future
// function indexTree(root) {
// var treeWalker = document.createTreeWalker(
// root,
// NodeFilter.SHOW_ELEMENT);
//
// var el;
// while((el = treeWalker.nextNode())) {
// var key = getNodeKey(el);
// if (key) {
// fromNodesLookup[key] = el;
// }
// }
// }
// // NodeIterator implementation is no faster, but keeping this around in case this changes in the future
//
// function indexTree(node) {
// var nodeIterator = document.createNodeIterator(node, NodeFilter.SHOW_ELEMENT);
// var el;
// while((el = nodeIterator.nextNode())) {
// var key = getNodeKey(el);
// if (key) {
// fromNodesLookup[key] = el;
// }
// }
// }
function indexTree(node) {
if (node.nodeType === ELEMENT_NODE) {
var curChild = node.firstChild;
while (curChild) {
var key = getNodeKey(curChild);
if (key) {
fromNodesLookup[key] = curChild;
}
// Walk recursively
indexTree(curChild);
curChild = curChild.nextSibling;
}
}
}
indexTree(fromNode);
function handleNodeAdded(el) {
onNodeAdded(el);
var curChild = el.firstChild;
while (curChild) {
var nextSibling = curChild.nextSibling;
var key = getNodeKey(curChild);
if (key) {
var unmatchedFromEl = fromNodesLookup[key];
if (unmatchedFromEl && compareNodeNames(curChild, unmatchedFromEl)) {
curChild.parentNode.replaceChild(unmatchedFromEl, curChild);
morphEl(unmatchedFromEl, curChild);
}
}
handleNodeAdded(curChild);
curChild = nextSibling;
}
}
function morphEl(fromEl, toEl, childrenOnly) {
if (ignoreAttr) {
var ignoreF = false,
ignoreT = false,
attrF = null,
attrT = null;
for (var _i = 0, _len = ignoreAttr.length; _i < _len; _i++) {
var selector = ignoreAttr[_i];
if (!ignoreF && fromEl.getAttribute(selector) !== null) {
ignoreF = true;
attrF = selector;
}
if (!ignoreT && toEl.getAttribute(selector) !== null) {
ignoreT = true;
attrT = selector;
}
if (ignoreF && ignoreT) break;
}
if (ignoreF && ignoreT && attrF === attrT) {
return;
}
}
var toElKey = getNodeKey(toEl);
var curFromNodeKey;
if (toElKey) {
// If an element with an ID is being morphed then it is will be in the final
// DOM so clear it out of the saved elements collection
delete fromNodesLookup[toElKey];
}
if (toNode.isSameNode && toNode.isSameNode(fromNode)) {
return;
}
if (!childrenOnly) {
if (onBeforeElUpdated(fromEl, toEl) === false) {
return;
}
morphAttrs(fromEl, toEl);
onElUpdated(fromEl);
if (onBeforeElChildrenUpdated(fromEl, toEl) === false) {
return;
}
}
if (fromEl.nodeName !== 'TEXTAREA') {
var curToNodeChild = toEl.firstChild;
var curFromNodeChild = fromEl.firstChild;
var curToNodeKey;
var fromNextSibling;
var toNextSibling;
var matchingFromEl;
2017-01-21 14:01:46 +08:00
outer: while (curToNodeChild) {
toNextSibling = curToNodeChild.nextSibling;
curToNodeKey = getNodeKey(curToNodeChild);
while (curFromNodeChild) {
fromNextSibling = curFromNodeChild.nextSibling;
if (curToNodeChild.isSameNode && curToNodeChild.isSameNode(curFromNodeChild)) {
curToNodeChild = toNextSibling;
curFromNodeChild = fromNextSibling;
continue outer;
}
curFromNodeKey = getNodeKey(curFromNodeChild);
var curFromNodeType = curFromNodeChild.nodeType;
var isCompatible = undefined;
if (curFromNodeType === curToNodeChild.nodeType) {
if (curFromNodeType === ELEMENT_NODE) {
// Both nodes being compared are Element nodes
if (curToNodeKey) {
// The target node has a key so we want to match it up with the correct element
// in the original DOM tree
if (curToNodeKey !== curFromNodeKey) {
// The current element in the original DOM tree does not have a matching key so
// let's check our lookup to see if there is a matching element in the original
// DOM tree
if (matchingFromEl = fromNodesLookup[curToNodeKey]) {
if (curFromNodeChild.nextSibling === matchingFromEl) {
// Special case for single element removals. To avoid removing the original
// DOM node out of the tree (since that can break CSS transitions, etc.),
// we will instead discard the current node and wait until the next
// iteration to properly match up the keyed target element with its matching
// element in the original tree
isCompatible = false;
} else {
// We found a matching keyed element somewhere in the original DOM tree.
// Let's moving the original DOM node into the current position and morph
// it.
// NOTE: We use insertBefore instead of replaceChild because we want to go through
// the `removeNode()` function for the node that is being discarded so that
// all lifecycle hooks are correctly invoked
fromEl.insertBefore(matchingFromEl, curFromNodeChild);
fromNextSibling = curFromNodeChild.nextSibling;
if (curFromNodeKey) {
// Since the node is keyed it might be matched up later so we defer
// the actual removal to later
addKeyedRemoval(curFromNodeKey);
} else {
// NOTE: we skip nested keyed nodes from being removed since there is
// still a chance they will be matched up later
removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
}
curFromNodeChild = matchingFromEl;
}
} else {
// The nodes are not compatible since the "to" node has a key and there
// is no matching keyed node in the source tree
isCompatible = false;
}
}
} else if (curFromNodeKey) {
// The original has a key
isCompatible = false;
}
isCompatible = isCompatible !== false && compareNodeNames(curFromNodeChild, curToNodeChild);
if (isCompatible) {
// We found compatible DOM elements so transform
// the current "from" node to match the current
// target DOM node.
morphEl(curFromNodeChild, curToNodeChild);
}
} else if (curFromNodeType === TEXT_NODE || curFromNodeType == COMMENT_NODE) {
// Both nodes being compared are Text or Comment nodes
isCompatible = true;
// Simply update nodeValue on the original node to
// change the text value
curFromNodeChild.nodeValue = curToNodeChild.nodeValue;
}
}
if (isCompatible) {
// Advance both the "to" child and the "from" child since we found a match
curToNodeChild = toNextSibling;
curFromNodeChild = fromNextSibling;
continue outer;
}
// No compatible match so remove the old node from the DOM and continue trying to find a
// match in the original DOM. However, we only do this if the from node is not keyed
// since it is possible that a keyed node might match up with a node somewhere else in the
// target tree and we don't want to discard it just yet since it still might find a
// home in the final DOM tree. After everything is done we will remove any keyed nodes
// that didn't find a home
if (curFromNodeKey) {
// Since the node is keyed it might be matched up later so we defer
// the actual removal to later
addKeyedRemoval(curFromNodeKey);
} else {
// NOTE: we skip nested keyed nodes from being removed since there is
// still a chance they will be matched up later
removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
}
curFromNodeChild = fromNextSibling;
}
// If we got this far then we did not find a candidate match for
// our "to node" and we exhausted all of the children "from"
// nodes. Therefore, we will just append the current "to" node
// to the end
if (curToNodeKey && (matchingFromEl = fromNodesLookup[curToNodeKey]) && compareNodeNames(matchingFromEl, curToNodeChild)) {
fromEl.appendChild(matchingFromEl);
morphEl(matchingFromEl, curToNodeChild);
} else {
var onBeforeNodeAddedResult = onBeforeNodeAdded(curToNodeChild);
if (onBeforeNodeAddedResult !== false) {
if (onBeforeNodeAddedResult) {
curToNodeChild = onBeforeNodeAddedResult;
}
if (curToNodeChild.actualize) {
curToNodeChild = curToNodeChild.actualize(fromEl.ownerDocument || doc);
}
fromEl.appendChild(curToNodeChild);
handleNodeAdded(curToNodeChild);
}
}
curToNodeChild = toNextSibling;
curFromNodeChild = fromNextSibling;
}
// We have processed all of the "to nodes". If curFromNodeChild is
// non-null then we still have some from nodes left over that need
// to be removed
while (curFromNodeChild) {
fromNextSibling = curFromNodeChild.nextSibling;
if (curFromNodeKey = getNodeKey(curFromNodeChild)) {
// Since the node is keyed it might be matched up later so we defer
// the actual removal to later
addKeyedRemoval(curFromNodeKey);
} else {
// NOTE: we skip nested keyed nodes from being removed since there is
// still a chance they will be matched up later
removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
}
curFromNodeChild = fromNextSibling;
}
}
var specialElHandler = specialElHandlers[fromEl.nodeName];
if (specialElHandler) {
specialElHandler(fromEl, toEl);
}
} // END: morphEl(...)
var morphedNode = fromNode;
var morphedNodeType = morphedNode.nodeType;
var toNodeType = toNode.nodeType;
if (!childrenOnly) {
// Handle the case where we are given two DOM nodes that are not
// compatible (e.g. <div> --> <span> or <div> --> TEXT)
if (morphedNodeType === ELEMENT_NODE) {
if (toNodeType === ELEMENT_NODE) {
if (!compareNodeNames(fromNode, toNode)) {
onNodeDiscarded(fromNode);
morphedNode = moveChildren(fromNode, createElementNS(toNode.nodeName, toNode.namespaceURI));
}
} else {
// Going from an element node to a text node
morphedNode = toNode;
}
} else if (morphedNodeType === TEXT_NODE || morphedNodeType === COMMENT_NODE) {
// Text or comment node
if (toNodeType === morphedNodeType) {
morphedNode.nodeValue = toNode.nodeValue;
return morphedNode;
} else {
// Text node to something else
morphedNode = toNode;
}
}
}
if (morphedNode === toNode) {
// The "to node" was not compatible with the "from node" so we had to
// toss out the "from node" and use the "to node"
onNodeDiscarded(fromNode);
} else {
morphEl(morphedNode, toNode, childrenOnly);
// We now need to loop over any keyed nodes that might need to be
// removed. We only do the removal if we know that the keyed node
// never found a match. When a keyed node is matched up we remove
// it out of fromNodesLookup and we use fromNodesLookup to determine
// if a keyed node has been matched up or not
if (keyedRemovalList) {
for (var i = 0, len = keyedRemovalList.length; i < len; i++) {
var elToRemove = fromNodesLookup[keyedRemovalList[i]];
if (elToRemove) {
removeNode(elToRemove, elToRemove.parentNode, false);
}
}
}
}
if (!childrenOnly && morphedNode !== fromNode && fromNode.parentNode) {
if (morphedNode.actualize) {
morphedNode = morphedNode.actualize(fromNode.ownerDocument || doc);
}
// If we had to swap out the from node with a new node because the old
// node was not compatible with the target node then we need to
// replace the old DOM node in the original DOM tree. This is only
// possible if the original DOM node was part of a DOM tree which
// we know is the case if it has a parent node.
fromNode.parentNode.replaceChild(morphedNode, fromNode);
}
return morphedNode;
};
}
var morphdom = morphdomFactory(morphAttrs);
morphdom.toElement = toElement;
2017-04-06 21:15:09 +08:00
morphdom.toElements = toElements;
return morphdom;
});
2017-01-21 14:01:46 +08:00
2017-04-20 17:46:08 +08:00
/***/ }),
2017-04-19 10:20:03 +08:00
/* 8 */
2017-04-20 17:46:08 +08:00
/***/ (function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
2017-04-19 10:20:03 +08:00
/*
* html2json for omi
* https://github.com/AlloyTeam/omi
*
* Original code by John Resig (ejohn.org)
* http://ejohn.org/blog/pure-javascript-html-parser/
* Original code by Erik Arvidsson, Mozilla Public License
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
* Original code by Jxck
* https://github.com/Jxck/html2json
*/
// Regular Expressions for parsing tags and attributes
var startTag = /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,
endTag = /^<\/([-A-Za-z0-9_]+)[^>]*>/,
attr = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
var HTMLParser = function HTMLParser(html, handler) {
var index,
chars,
match,
stack = [],
last = html;
stack.last = function () {
return this[this.length - 1];
};
while (html) {
chars = true;
// Make sure we're not in a script or style element
if (!stack.last()) {
if (html.indexOf("</") == 0) {
match = html.match(endTag);
if (match) {
html = html.substring(match[0].length);
match[0].replace(endTag, parseEndTag);
chars = false;
}
// start tag
} else if (html.indexOf("<") == 0) {
match = html.match(startTag);
if (match) {
html = html.substring(match[0].length);
match[0].replace(startTag, parseStartTag);
chars = false;
}
}
if (chars) {
index = html.indexOf("<");
var text = index < 0 ? html : html.substring(0, index);
html = index < 0 ? "" : html.substring(index);
if (handler.chars) handler.chars(text);
}
} else {
html = html.replace(new RegExp("([\\s\\S]*?)<\/" + stack.last() + "[^>]*>"), function (all, text) {
if (handler.chars) handler.chars(text);
return "";
});
parseEndTag("", stack.last());
}
if (html == last) throw "Parse Error: " + html;
last = html;
}
// Clean up any remaining tags
parseEndTag();
function parseStartTag(tag, tagName, rest, unary) {
2017-04-06 21:15:09 +08:00
//tagName = tagName.toLowerCase();
unary = !!unary;
if (!unary) stack.push(tagName);
if (handler.start) {
var attrs = [];
rest.replace(attr, function (match, name) {
var value = arguments[2] ? arguments[2] : arguments[3] ? arguments[3] : arguments[4] ? arguments[4] : "";
attrs.push({
name: name,
value: value,
escaped: value.replace(/(^|[^\\])"/g, '$1\\\"') //"
});
});
if (handler.start) handler.start(tagName, attrs, unary);
}
}
function parseEndTag(tag, tagName) {
// If no tag name is provided, clean shop
if (!tagName) var pos = 0;
// Find the closest opened tag of the same type
else for (var pos = stack.length - 1; pos >= 0; pos--) {
if (stack[pos] == tagName) break;
}if (pos >= 0) {
// Close all the open elements, up the stack
for (var i = stack.length - 1; i >= pos; i--) {
if (handler.end) handler.end(stack[i]);
} // Remove the open elements from the stack
stack.length = pos;
}
}
};
var DEBUG = false;
var debug = DEBUG ? console.log.bind(console) : function () {};
// Production steps of ECMA-262, Edition 5, 15.4.4.21
// Reference: http://es5.github.io/#x15.4.4.21
if (!Array.prototype.reduce) {
Array.prototype.reduce = function (callback /*, initialValue*/) {
'use strict';
if (this == null) {
throw new TypeError('Array.prototype.reduce called on null or undefined');
}
if (typeof callback !== 'function') {
throw new TypeError(callback + ' is not a function');
}
var t = Object(this),
len = t.length >>> 0,
k = 0,
value;
if (arguments.length == 2) {
value = arguments[1];
} else {
while (k < len && !(k in t)) {
k++;
}
if (k >= len) {
throw new TypeError('Reduce of empty array with no initial value');
}
value = t[k++];
}
for (; k < len; k++) {
if (k in t) {
value = callback(value, t[k], k, t);
}
}
return value;
};
}
var html2json = function html2json(html) {
var bufArray = [];
var results = {
node: 'root',
child: []
};
HTMLParser(html, {
start: function start(tag, attrs, unary) {
debug(tag, attrs, unary);
// node for this element
var node = {
node: 'element',
tag: tag
};
if (attrs.length !== 0) {
node.attr = attrs.reduce(function (pre, attr) {
var name = attr.name;
var value = attr.value;
pre[name] = value;
return pre;
}, {});
}
if (unary) {
// if this tag dosen't have end tag
// like <img src="hoge.png"/>
// add to parents
var parent = bufArray[0] || results;
if (parent.child === undefined) {
parent.child = [];
}
parent.child.push(node);
} else {
bufArray.unshift(node);
}
},
end: function end(tag) {
debug(tag);
// merge into parent tag
var node = bufArray.shift();
if (node.tag !== tag) console.error('invalid state: mismatch end tag');
if (bufArray.length === 0) {
results.child.push(node);
} else {
var parent = bufArray[0];
if (parent.child === undefined) {
parent.child = [];
}
parent.child.push(node);
}
},
chars: function chars(text) {
debug(text);
var node = {
node: 'text',
text: text
};
if (bufArray.length === 0) {
results.child.push(node);
} else {
var parent = bufArray[0];
if (parent.child === undefined) {
parent.child = [];
}
parent.child.push(node);
}
}
});
return results;
};
exports["default"] = html2json;
2017-04-20 17:46:08 +08:00
/***/ }),
2017-04-19 10:20:03 +08:00
/* 9 */
2017-04-20 17:46:08 +08:00
/***/ (function(module, exports) {
2017-03-18 08:08:11 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Store = function () {
function Store(isReady) {
_classCallCheck(this, Store);
this.readyHandlers = [];
this.isReady = isReady;
this.instances = [];
this.updateSelfInstances = [];
2017-03-18 08:08:11 +08:00
}
_createClass(Store, [{
key: "ready",
value: function ready(readyHandler) {
if (this.isReady) {
readyHandler();
return;
}
this.readyHandlers.push(readyHandler);
}
}, {
key: "addSelfView",
value: function addSelfView(view) {
var added = false;
for (var i = 0, len = this.updateSelfInstances.length; i < len; i++) {
if (this.updateSelfInstances[i].id === view.id) {
added = true;
break;
}
}
if (!added) {
this.updateSelfInstances.push(view);
}
}
}, {
key: "addView",
value: function addView(view) {
var added = false;
for (var i = 0, len = this.instances.length; i < len; i++) {
if (this.instances[i].id === view.id) {
added = true;
break;
}
}
if (!added) {
this.instances.push(view);
}
}
2017-03-18 08:08:11 +08:00
}, {
key: "beReady",
value: function beReady() {
this.isReady = true;
this.readyHandlers.forEach(function (handler) {
return handler();
});
}
}, {
key: "update",
value: function update() {
this._mergeInstances();
this._mergeSelfInstances();
2017-03-18 08:08:11 +08:00
this.instances.forEach(function (instance) {
return instance.update();
});
this.updateSelfInstances.forEach(function (instance) {
return instance.updateSelf();
});
2017-03-18 08:08:11 +08:00
}
}, {
key: "_mergeSelfInstances",
value: function _mergeSelfInstances() {
2017-03-18 08:08:11 +08:00
var _this = this;
var arr = [];
this.updateSelfInstances.forEach(function (instance) {
if (!_this._checkSelfUpdateInstance(instance)) {
arr.push(instance);
}
2017-03-18 08:08:11 +08:00
});
this.updateSelfInstances = arr;
}
}, {
key: "_mergeInstances",
value: function _mergeInstances() {
var _this2 = this;
2017-03-18 08:08:11 +08:00
var arr = [];
this.idArr = [];
this.instances.forEach(function (instance) {
_this2.idArr.push(instance.id);
});
this.instances.forEach(function (instance) {
2017-03-18 08:08:11 +08:00
if (!instance.parent) {
arr.push(instance);
} else {
if (!_this2._isSubInstance(instance)) {
2017-03-18 08:08:11 +08:00
arr.push(instance);
}
}
});
this.instances = arr;
}
}, {
key: "_checkSelfUpdateInstance",
value: function _checkSelfUpdateInstance(instance) {
if (this.idArr.indexOf(instance.id) !== -1) {
return true;
} else if (instance.parent) {
return this._checkSelfUpdateInstance(instance.parent);
}
}
2017-03-18 08:08:11 +08:00
}, {
key: "_isSubInstance",
value: function _isSubInstance(instance) {
if (this.idArr.indexOf(instance.parent.id) !== -1) {
2017-03-18 08:08:11 +08:00
return true;
} else if (instance.parent.parent) {
return this._isSubInstance(instance.parent);
2017-03-18 08:08:11 +08:00
}
}
}]);
return Store;
}();
exports["default"] = Store;
2017-04-20 17:46:08 +08:00
/***/ })
2017-01-21 14:01:46 +08:00
/******/ ])
});
;