From 5d9eb50527be872241cb56f77b0e5a7ae2c2026f Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 2 Jan 2017 12:27:09 +0100 Subject: [PATCH] canvio crlf --- @salix/core/src/check/check.mdl.js | 42 +- @salix/core/src/interpolate.js | 408 ++++++++++---------- @salix/core/src/mdl-override.css | 4 +- @salix/core/src/resolveDefaultComponents.js | 78 ++-- @salix/core/src/routesLoader.js | 36 +- @salix/core/src/splitingregister.js | 26 +- @salix/core/src/textfield/textfield.js | 40 +- @salix/core/src/textfield/textfield.mdl.js | 50 +-- @salix/core/src/util.js | 96 ++--- 9 files changed, 385 insertions(+), 395 deletions(-) diff --git a/@salix/core/src/check/check.mdl.js b/@salix/core/src/check/check.mdl.js index 9ebe1cbd3..1f65309b6 100644 --- a/@salix/core/src/check/check.mdl.js +++ b/@salix/core/src/check/check.mdl.js @@ -1,21 +1,21 @@ -import {module as _module} from '../module'; -import * as util from '../util'; -import * as constant from '../constants'; -import template from './check.mdl.html'; - -const _NAME = 'check'; -const DEFAULT_CLASS = 'mdl-checkbox__input'; - -export const NAME = util.getFactoryName(_NAME + constant.MATERIAL_DESIGN_FRAMEWORK); - -export function factory() { - return { - template: template, - default: { - enabled: 'true', - className: DEFAULT_CLASS - } - } -} - -_module.factory(NAME, factory); +import {module as _module} from '../module'; +import * as util from '../util'; +import * as constant from '../constants'; +import template from './check.mdl.html'; + +const _NAME = 'check'; +const DEFAULT_CLASS = 'mdl-checkbox__input'; + +export const NAME = util.getFactoryName(_NAME + constant.MATERIAL_DESIGN_FRAMEWORK); + +export function factory() { + return { + template: template, + default: { + enabled: 'true', + className: DEFAULT_CLASS + } + }; +} + +_module.factory(NAME, factory); diff --git a/@salix/core/src/interpolate.js b/@salix/core/src/interpolate.js index 115c1f98e..bfaacd6fd 100644 --- a/@salix/core/src/interpolate.js +++ b/@salix/core/src/interpolate.js @@ -1,206 +1,202 @@ -import {module} from './module'; -import {ng} from 'vendor'; -import * as util from './util'; - -export const NAME = util.getProviderName('interpolate'); - -function minErr() {} - -function stringify(value) { - if (value == null) { // null || undefined - return ''; - } - switch (typeof value) { - case 'string': - break; - case 'number': - value = '' + value; - break; - default: - value = angular.toJson(value); - } - - return value; -} - -var $interpolateMinErr = ng.angular.$interpolateMinErr = ng.$$minErr('$interpolate'); - -$interpolateMinErr.throwNoconcat = function (text) { - throw $interpolateMinErr('noconcat', - 'Error while interpolating: {0}\nStrict Contextual Escaping disallows ' + - 'interpolations that concatenate multiple expressions when a trusted value is ' + - 'required. See http://docs.angularjs.org/api/ng.$sce', text); -}; - -$interpolateMinErr.interr = function (text, err) { - return $interpolateMinErr('interr', 'Can\'t interpolate: {0}\n{1}', text, err.toString()); -}; - -function $get($parse, $exceptionHandler, $sce) { - var startSymbolLength = this._startSymbol.length, - endSymbolLength = this._endSymbol.length, - escapedStartRegexp = new RegExp(this._startSymbol.replace(/./g, escape), 'g'), - escapedEndRegexp = new RegExp(this._endSymbol.replace(/./g, escape), 'g'), - self = this; - - function escape(ch) { - return '\\\\\\' + ch; - } - - function unescapeText(text) { - return text.replace(escapedStartRegexp, self._startSymbol). - replace(escapedEndRegexp, self._endSymbol); - } - - // TODO: this is the same as the constantWatchDelegate in parse.js - function constantWatchDelegate(scope, listener, objectEquality, constantInterp) { - var unwatch = scope.$watch(function constantInterpolateWatch(scope) { - unwatch(); - return constantInterp(scope); - }, listener, objectEquality); - return unwatch; - } - - function $interpolate(text, mustHaveExpression, trustedContext, allOrNothing) - { - // Provide a quick exit and simplified result function for text with no interpolation - if (!text.length || text.indexOf(self._startSymbol) === -1) - { - var constantInterp; - if (!mustHaveExpression) { - var unescapedText = unescapeText(text); - constantInterp = valueFn(unescapedText); - constantInterp.exp = text; - constantInterp.expressions = []; - constantInterp.$$watchDelegate = constantWatchDelegate; - } - return constantInterp; - } - - allOrNothing = !!allOrNothing; - var startIndex, - endIndex, - index = 0, - expressions = [], - parseFns = [], - textLength = text.length, - exp, - concat = [], - expressionPositions = []; - - while (index < textLength) { - if (((startIndex = text.indexOf(self._startSymbol, index)) !== -1) && - ((endIndex = text.indexOf(self._endSymbol, startIndex + startSymbolLength)) !== -1)) { - if (index !== startIndex) { - concat.push(unescapeText(text.substring(index, startIndex))); - } - exp = text.substring(startIndex + startSymbolLength, endIndex); - expressions.push(exp); - parseFns.push($parse(exp, parseStringifyInterceptor)); - index = endIndex + endSymbolLength; - expressionPositions.push(concat.length); - concat.push(''); - } else { - // we did not find an interpolation, so we have to add the remainder to the separators array - if (index !== textLength) { - concat.push(unescapeText(text.substring(index))); - } - break; - } - } - - if (trustedContext && concat.length > 1) { - $interpolateMinErr.throwNoconcat(text); - } - - if (!mustHaveExpression || expressions.length) { - var compute = function (values) { - for (var i = 0, ii = expressions.length; i < ii; i++) { - if (allOrNothing && isUndefined(values[i])) return; - concat[expressionPositions[i]] = values[i]; - } - return concat.join(''); - }; - - var getValue = function (value) { - return trustedContext ? - $sce.getTrusted(trustedContext, value) : - $sce.valueOf(value); - }; - - return angular.extend(function interpolationFn(context) { - var i = 0; - var ii = expressions.length; - var values = new Array(ii); - - try { - for (; i < ii; i++) { - values[i] = parseFns[i](context); - } - - return compute(values); - } catch (err) { - $exceptionHandler($interpolateMinErr.interr(text, err)); - } - - }, { - // all of these properties are undocumented for now - exp: text, //just for compatibility with regular watchers created via $watch - expressions: expressions, - }); - } - - function parseStringifyInterceptor(value) { - try { - value = getValue(value); - return allOrNothing && !isDefined(value) ? value : stringify(value); - } catch (err) { - $exceptionHandler($interpolateMinErr.interr(text, err)); - } - } - } - - $interpolate.startSymbol = function () { - return startSymbol; - }; - - $interpolate.endSymbol = function () { - return endSymbol; - }; - - return $interpolate; - } - -$get.$inject = ['$parse', '$exceptionHandler', '$sce']; - -export class Interpolate -{ - constructor () { - this._startSymbol='*['; - this._endSymbol = ']*'; - } - - set startSymbol (value) { - if (value) { - this._startSymbol = value; - return this; - } else { - return this._startSymbol; - } - }; - - set endSymbol (value) { - if (value) { - this._endSymbol = value; - return this; - } else { - return this._endSymbol; - } - }; - - -} - -Interpolate.prototype.$get = $get; -var interpolate = new Interpolate(); -module.provider(NAME, () => interpolate); +import {module} from './module'; +import {ng} from 'vendor'; +import * as util from './util'; + +export const NAME = util.getProviderName('interpolate'); + +function minErr() {} + +function stringify(value) { + if (value === null) { // null || undefined + return ''; + } + switch (typeof value) { + case 'string': + break; + case 'number': + value = String(value); + break; + default: + value = angular.toJson(value); + } + + return value; +} + +var $interpolateMinErr = ng.angular.$interpolateMinErr = ng.$$minErr('$interpolate'); + +$interpolateMinErr.throwNoconcat = function(text) { + throw $interpolateMinErr('noconcat', + 'Error while interpolating: {0}\nStrict Contextual Escaping disallows ' + + 'interpolations that concatenate multiple expressions when a trusted value is ' + + 'required. See http://docs.angularjs.org/api/ng.$sce', text); +}; + +$interpolateMinErr.interr = function(text, err) { + return $interpolateMinErr('interr', 'Can\'t interpolate: {0}\n{1}', text, err.toString()); +}; + +function $get($parse, $exceptionHandler, $sce) { + var startSymbolLength = this._startSymbol.length, + endSymbolLength = this._endSymbol.length, + escapedStartRegexp = new RegExp(this._startSymbol.replace(/./g, escape), 'g'), + escapedEndRegexp = new RegExp(this._endSymbol.replace(/./g, escape), 'g'), + self = this; + + function escape(ch) { + return '\\\\\\' + ch; + } + + function unescapeText(text) { + return text.replace(escapedStartRegexp, self._startSymbol) + .replace(escapedEndRegexp, self._endSymbol); + } + + // TODO: this is the same as the constantWatchDelegate in parse.js + function constantWatchDelegate(scope, listener, objectEquality, constantInterp) { + var unwatch = scope.$watch(function constantInterpolateWatch(scope) { + unwatch(); + return constantInterp(scope); + }, listener, objectEquality); + return unwatch; + } + + function $interpolate(text, mustHaveExpression, trustedContext, allOrNothing) { + // Provide a quick exit and simplified result function for text with no interpolation + if (!text.length || text.indexOf(self._startSymbol) === -1) { + var constantInterp; + if (!mustHaveExpression) { + var unescapedText = unescapeText(text); + constantInterp = valueFn(unescapedText); + constantInterp.exp = text; + constantInterp.expressions = []; + constantInterp.$$watchDelegate = constantWatchDelegate; + } + return constantInterp; + } + + allOrNothing = Boolean(allOrNothing); + var startIndex, + endIndex, + index = 0, + expressions = [], + parseFns = [], + textLength = text.length, + exp, + concat = [], + expressionPositions = []; + + while (index < textLength) { + if (((startIndex = text.indexOf(self._startSymbol, index)) !== -1) && + ((endIndex = text.indexOf(self._endSymbol, startIndex + startSymbolLength)) !== -1)) { + if (index !== startIndex) { + concat.push(unescapeText(text.substring(index, startIndex))); + } + exp = text.substring(startIndex + startSymbolLength, endIndex); + expressions.push(exp); + parseFns.push($parse(exp, parseStringifyInterceptor)); + index = endIndex + endSymbolLength; + expressionPositions.push(concat.length); + concat.push(''); + } else { + // we did not find an interpolation, so we have to add the remainder to the separators array + if (index !== textLength) { + concat.push(unescapeText(text.substring(index))); + } + break; + } + } + + if (trustedContext && concat.length > 1) { + $interpolateMinErr.throwNoconcat(text); + } + + if (!mustHaveExpression || expressions.length) { + var compute = function(values) { + for (var i = 0, ii = expressions.length; i < ii; i++) { + if (allOrNothing && isUndefined(values[i])) return; + concat[expressionPositions[i]] = values[i]; + } + return concat.join(''); + }; + + var getValue = function(value) { + return trustedContext ? + $sce.getTrusted(trustedContext, value) : + $sce.valueOf(value); + }; + + return angular.extend(function interpolationFn(context) { + var i = 0; + var ii = expressions.length; + var values = new Array(ii); + + try { + for (; i < ii; i++) { + values[i] = parseFns[i](context); + } + + return compute(values); + } catch (err) { + $exceptionHandler($interpolateMinErr.interr(text, err)); + } + }, { + // all of these properties are undocumented for now + exp: text, // just for compatibility with regular watchers created via $watch + expressions: expressions + }); + } + + function parseStringifyInterceptor(value) { + try { + value = getValue(value); + return allOrNothing && !isDefined(value) ? value : stringify(value); + } catch (err) { + $exceptionHandler($interpolateMinErr.interr(text, err)); + } + } + } + + $interpolate.startSymbol = function() { + return startSymbol; + }; + + $interpolate.endSymbol = function() { + return endSymbol; + }; + + return $interpolate; +} + +$get.$inject = ['$parse', '$exceptionHandler', '$sce']; + +export class Interpolate +{ + constructor() { + this._startSymbol = '*['; + this._endSymbol = ']*'; + } + + set startSymbol(value) { + if (value) { + this._startSymbol = value; + return this; + } else { + return this._startSymbol; + } + } + + set endSymbol(value) { + if (value) { + this._endSymbol = value; + return this; + } else { + return this._endSymbol; + } + } + +} + +Interpolate.prototype.$get = $get; +var interpolate = new Interpolate(); +module.provider(NAME, () => interpolate); diff --git a/@salix/core/src/mdl-override.css b/@salix/core/src/mdl-override.css index fedc64395..3420da49e 100644 --- a/@salix/core/src/mdl-override.css +++ b/@salix/core/src/mdl-override.css @@ -1,4 +1,4 @@ - +/* .mdl-textfield { width: 100%; } @@ -19,4 +19,4 @@ .mdl-button--raised:hover { background-color: #ffa410; -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/@salix/core/src/resolveDefaultComponents.js b/@salix/core/src/resolveDefaultComponents.js index fa45672c2..5fa37cd75 100644 --- a/@salix/core/src/resolveDefaultComponents.js +++ b/@salix/core/src/resolveDefaultComponents.js @@ -1,39 +1,39 @@ -import {module as _module} from './module'; -import * as util from './util'; -import constant from './constants'; -import Interpolate from './interpolate'; - -export const NAME = util.getProviderName('ResolveDefaultComponent'); - -function $get($injector, vnInterpolate){ - return { - getTemplate:function(name, attrs) { - this._frameworkName = 'Mdl'; - let _name = util.getFactoryName( name + this._frameworkName); - let defaultfactory = $injector.has(_name) ? $injector.get(_name) : undefined; - - if(!defaultfactory) { - throw new Error("factory is not defined"); - } - - let defaultValues = defaultfactory.default; - let template = defaultfactory.template; - let scope = Object.assign({}, defaultValues || {}, attrs || {}); - return template && vnInterpolate(template)(scope); - } - }; -} -$get.$inject = ['$injector', 'vnInterpolate']; - -export class ResolveDefaultComponent { - constructor() { - this._frameworkName='Mdl'; - } - set frameworkName(value) { - this._frameworkName = value; - } -} - -ResolveDefaultComponent.prototype.$get = $get; -var resolve = new ResolveDefaultComponent(); -_module.provider(NAME,() => resolve); \ No newline at end of file +import {module as _module} from './module'; +import * as util from './util'; +import constant from './constants'; +import Interpolate from './interpolate'; + +export const NAME = util.getProviderName('ResolveDefaultComponent'); + +function $get($injector, vnInterpolate) { + return { + getTemplate: function(name, attrs) { + this._frameworkName = 'Mdl'; + let _name = util.getFactoryName(name + this._frameworkName); + let defaultfactory = $injector.has(_name) ? $injector.get(_name) : undefined; + + if (!defaultfactory) { + throw new Error("factory is not defined"); + } + + let defaultValues = defaultfactory.default; + let template = defaultfactory.template; + let scope = Object.assign({}, defaultValues || {}, attrs || {}); + return template && vnInterpolate(template)(scope); + } + }; +} +$get.$inject = ['$injector', 'vnInterpolate']; + +export class ResolveDefaultComponent { + constructor() { + this._frameworkName = 'Mdl'; + } + set frameworkName(value) { + this._frameworkName = value; + } +} + +ResolveDefaultComponent.prototype.$get = $get; +var resolve = new ResolveDefaultComponent(); +_module.provider(NAME, () => resolve); diff --git a/@salix/core/src/routesLoader.js b/@salix/core/src/routesLoader.js index eef26ff85..25a0eec6f 100644 --- a/@salix/core/src/routesLoader.js +++ b/@salix/core/src/routesLoader.js @@ -1,27 +1,27 @@ -import {module as _module} from './module' -import * as util from './util' +import {module as _module} from './module'; +import * as util from './util'; -export const NAME = util.getProviderName ('RoutesLoader') +export const NAME = util.getProviderName('RoutesLoader'); -function $get($http){ - let script = document.currentScript || (() => { - let scripts = document.getElementsByTagName ('script'); - return scripts[scripts.length - 1]; - }) (); - - let routesCdn = script.getAttribute ('routes-cdn'); - - return $http({ - method: 'GET', - url: routesCdn - }); +function $get($http) { + let script = document.currentScript || (() => { + let scripts = document.getElementsByTagName('script'); + return scripts[scripts.length - 1]; + })(); + + let routesCdn = script.getAttribute('routes-cdn'); + + return $http({ + method: 'GET', + url: routesCdn + }); } $get.$inject = ["$http"]; -export class RoutesLoader{ constructor () {} } +export class RoutesLoader { constructor() {} } RoutesLoader.prototype.$get = $get; -var routes = new RoutesLoader (); -_module.provider (NAME, () => routes) +var routes = new RoutesLoader(); +_module.provider(NAME, () => routes); diff --git a/@salix/core/src/splitingregister.js b/@salix/core/src/splitingregister.js index 725efab45..281a925de 100644 --- a/@salix/core/src/splitingregister.js +++ b/@salix/core/src/splitingregister.js @@ -1,5 +1,4 @@ const _SplitingRegister = () => { - var _graph; var dependencies = {}; @@ -16,15 +15,14 @@ const _SplitingRegister = () => { } return { - registerGraph: function (graph) { + registerGraph: function(graph) { _graph = graph; }, - register: function (dependency, loader) { + register: function(dependency, loader) { dependencies[dependency] = loader; }, - execute: function (dependency) { + execute: function(dependency) { return new Promise(resolve => { - var array = getDependencies(dependency); var arrayClone = array.concat([]); @@ -34,26 +32,22 @@ const _SplitingRegister = () => { } (function loadDependency(dependency) { - - if(!dependency){ + if (!dependency) { resolve(arrayClone); return; } - dependency().then(function (data) { - var _dependency = getDependency(); - loadDependency(_dependency); + dependency().then(function(data) { + var _dependency = getDependency(); + loadDependency(_dependency); }); - } (getDependency())) - + })(getDependency()); }); - - }, - write: function () { + write: function() { console.log(_graph); } - } + }; }; window.dependencies = _SplitingRegister(); export const SplitingRegister = window.dependencies; diff --git a/@salix/core/src/textfield/textfield.js b/@salix/core/src/textfield/textfield.js index 30130329a..11bc336df 100644 --- a/@salix/core/src/textfield/textfield.js +++ b/@salix/core/src/textfield/textfield.js @@ -1,20 +1,20 @@ -import {module as _module} from '../module'; -import * as resolveFactory from '../resolveDefaultComponents'; -import * as normalizerFactory from '../inputAttrsNormalizer'; -import * as util from '../util'; - -const _NAME = 'textfield'; -export const NAME = util.getName(_NAME); - -directive.$inject =[resolveFactory.NAME, normalizerFactory.NAME]; -export function directive (resolve, normalizer){ - return{ - require:'E', - template: function(_, attrs){ - normalizer.normalize (attrs); - return resolve.getTemplate(_NAME, attrs); - } - } -} - -_module.directive(NAME,directive); +import {module as _module} from '../module'; +import * as resolveFactory from '../resolveDefaultComponents'; +import * as normalizerFactory from '../inputAttrsNormalizer'; +import * as util from '../util'; + +const _NAME = 'textfield'; +export const NAME = util.getName(_NAME); + +directive.$inject = [resolveFactory.NAME, normalizerFactory.NAME]; +export function directive(resolve, normalizer) { + return { + require: 'E', + template: function(_, attrs) { + normalizer.normalize(attrs); + return resolve.getTemplate(_NAME, attrs); + } + }; +} + +_module.directive(NAME, directive); diff --git a/@salix/core/src/textfield/textfield.mdl.js b/@salix/core/src/textfield/textfield.mdl.js index a8b2554c1..cf8344c77 100644 --- a/@salix/core/src/textfield/textfield.mdl.js +++ b/@salix/core/src/textfield/textfield.mdl.js @@ -1,25 +1,25 @@ -import {module as _module} from '../module'; -import * as util from '../util'; -import * as constant from '../constants'; -import template from './textfield.mdl.html'; - -const _NAME = 'textfield'; -const DEFAULT_LABEL = 'text'; -const DEFAULT_CLASS = 'mdl-textfield__input'; -const DEFAULT_TYPE = 'text'; - -export const NAME = util.getFactoryName(_NAME + constant.MATERIAL_DESIGN_FRAMEWORK); - -export function factory() { - return { - template: template, - default: { - label: DEFAULT_LABEL, - name: 'textfield', - className: DEFAULT_CLASS, - type: DEFAULT_TYPE - } - } -} - -_module.factory(NAME, factory); +import {module as _module} from '../module'; +import * as util from '../util'; +import * as constant from '../constants'; +import template from './textfield.mdl.html'; + +const _NAME = 'textfield'; +const DEFAULT_LABEL = 'text'; +const DEFAULT_CLASS = 'mdl-textfield__input'; +const DEFAULT_TYPE = 'text'; + +export const NAME = util.getFactoryName(_NAME + constant.MATERIAL_DESIGN_FRAMEWORK); + +export function factory() { + return { + template: template, + default: { + label: DEFAULT_LABEL, + name: 'textfield', + className: DEFAULT_CLASS, + type: DEFAULT_TYPE + } + }; +} + +_module.factory(NAME, factory); diff --git a/@salix/core/src/util.js b/@salix/core/src/util.js index 5206d3768..75528c1c2 100644 --- a/@salix/core/src/util.js +++ b/@salix/core/src/util.js @@ -1,48 +1,48 @@ -import * as constant from './constants'; - -const FACTORY = 'Factory'; -const SERVICE = 'Service'; -const DEFAULT = 'default'; - -export function getName(name) { - return constant.PREFIX + toUpperCamelCase(name) -} - -export function toUpperCamelCase(stringToConvert){ - return stringToConvert.substr( 0, 1 ).toUpperCase() + stringToConvert.substr( 1 ) -} - -export function getFactoryName(name){ - return getName(name) + FACTORY -} - -export function getServiceName(name){ - return getName(name) + SERVICE -} - -export function getModuleName(name){ - return constant.PREFIX + name; -} - -export function getProviderNameFromConfig(name){ - return getName(name) + 'Provider'; -} - -export function getProviderName(name){ - return getName(name); -} - -export function getTemplateName(componentName,frameworkName){ - return componentName + '.' + frameworkName + '.' + '.html' -} - -export function getVendorDependencies(vendors){ - let dependencies = []; - Object.keys(vendors).forEach((vendor)=>{ - let name = vendors[vendor].name; - if(name){ - dependencies.push(name) - } - }); - return dependencies; -} +import * as constant from './constants'; + +const FACTORY = 'Factory'; +const SERVICE = 'Service'; +const DEFAULT = 'default'; + +export function getName(name) { + return constant.PREFIX + toUpperCamelCase(name); +} + +export function toUpperCamelCase(stringToConvert) { + return stringToConvert.substr(0, 1).toUpperCase() + stringToConvert.substr(1); +} + +export function getFactoryName(name) { + return getName(name) + FACTORY; +} + +export function getServiceName(name) { + return getName(name) + SERVICE; +} + +export function getModuleName(name) { + return constant.PREFIX + name; +} + +export function getProviderNameFromConfig(name) { + return getName(name) + 'Provider'; +} + +export function getProviderName(name) { + return getName(name); +} + +export function getTemplateName(componentName, frameworkName) { + return componentName + '.' + frameworkName + '.html'; +} + +export function getVendorDependencies(vendors) { + let dependencies = []; + Object.keys(vendors).forEach(vendor => { + let name = vendors[vendor].name; + if (name) { + dependencies.push(name); + } + }); + return dependencies; +}