react-json-verbling
Version:
A JSON editor packed as a React.js component and the simplest way of creating web forms.
6 lines • 27.7 kB
JavaScript
/*
react-json v0.0.1
https://github.com/arqex/react-json
MIT: https://github.com/arqex/react-json/raw/master/LICENSE
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require(void 0)):"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Json=e(require(void 0)):t.Json=e(t.React)}(this,function(t){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){var r=n(1),i=n(13),s=n(12),a=n(2),o=n(3),u=n(4),p=n(5),c=n(6),l=n(7),f=n(8),d=n(9),h=n(10),g=n(11),v=r.createClass({getDefaultProps:function(){return{value:{},errors:!1,updating:!1}},childContextTypes:{typeDefaults:r.PropTypes.object},getChildContext:function(){return{typeDefaults:this.state.defaults}},getInitialState:function(){var t=this,e=this.props.value;return e.getListener||(e=new i(e).get()),e.getListener().on("update",function(e){return t.state.updating?t.setState({updating:!1}):(t.setState({value:e}),t.state.errors&&t.getValidationErrors(),void(t.props.onChange&&t.props.onChange(e.toJS())))}),{value:e,defaults:this.createDefaults(),id:this.getId()}},componentWillReceiveProps:function(t){t.value.getListener||this.setState({updating:!0,value:this.state.value.reset(t.value)}),this.setState({defaults:this.createDefaults()})},render:function(){var t=this.props.settings||{},e=r.createElement(a,{type:"object",value:this.state.value,settings:s({},this.state.defaults.object,{fields:t.fields,editing:this.getFormSetting(t,"editing","always"),fixedFields:this.getFormSetting(t,"fixedFields",!0),adder:this.getFormSetting(t,"adder",!1),header:!1,order:t.order}),ref:"value",defaults:this.state.defaults,id:this.state.id});return r.DOM.div({className:"jsonEditor"},e)},getValue:function(){return this.state.value.toJS()},getValidationErrors:function(){var t=this.getValue(),e=this.refs.value.getValidationErrors(t);return this.setState({errors:e.length}),e.length?e:!1},getDeepSettings:function(){var t={};for(var e in g)t[e]=g[e](this,t[e]);return t},createDefaults:function(){var t=this.props.settings||{},e=a.prototype.components,n=t.defaults||{},r={};for(var i in e)r[i]=s({},e[i].prototype.defaults||{},n[i]||{});return r},getId:function(){return btoa(parseInt(1e4*Math.random())).replace(/=/g,"")},getFormSetting:function(t,e,n){return"undefined"!=typeof t[e]?t[e]:t.form?n:void 0}});v.registerType=a.registerType.bind(a),v.registerType("object",o),v.registerType("array",u,!0),v.registerType("string",p,!0),v.registerType("text",f,!0),v.registerType("number",l,!0),v.registerType("boolean",c,!0),v.registerType("password",d),v.registerType("select",h),t.exports=v},function(e,n,r){e.exports=t},function(t,e,n){"use strict";var r=n(1),i=n(11),s=n(12),a=r.createClass({components:{},typeCheckOrder:[],contextTypes:{typeDefaults:r.PropTypes.object},render:function(){var t=this.getComponent(),e=s({},this.context.typeDefaults[this.props.type],this.props.settings);return this.addDeepSettings(e),r.createElement(t,{value:this.props.value,settings:e,onUpdated:this.props.onUpdated,id:this.props.id,ref:"field"})},getComponent:function(){var t=this.props.type;return t||(t=this.guessType(this.props.value)),this.fieldType=t,this.components[t]},guessType:function(t){for(var e,n=!1,r=0,i=this.typeCheckOrder;!n&&r<i.length;)e=this.components[i[r]].prototype,e.isType&&e.isType(t)?n=i[r++]:r++;return n||"object"},getValidationErrors:function(t){return this.refs.field.getValidationErrors(t)},addDeepSettings:function(t){var e,n=this.props.parentSettings||{};for(var r in i)e=i[r](n[r],t[r]),"undefined"!=typeof e&&(t[r]=e)}});a.registerType=function(t,e,n){var r=a.prototype;r.components[t]=e,n&&r.typeCheckOrder.unshift(t)},t.exports=a},function(t,e,n){"use strict";var r=n(1),i=n(14),s=n(12),a=n(15),o=r.createClass({mixins:[a],getInitialState:function(){return this.getStateFromProps(this.props)},getStateFromProps:function(t){return{editing:t.settings.editing||!1,fields:s({},t.settings&&t.settings.fields||{})}},defaultValue:{},render:function(){var t=this,e=this.props.settings,n=this.state.editing||e.header===!1?"open jsonObject jsonCompound":"jsonObject jsonCompound",i="",a=(this.state.fields,[]),o=(s({},this.props.value),this.getFixedFields()),u=0;this.getFieldOrder().forEach(function(e){a.push(e.constructor===Array?t.renderGroup(e,o,++u):t.renderField(e,o))});var p=[a];return e.adder!==!1&&p.push(this.renderAdder()),i=r.DOM.div({key:"o",className:"jsonChildren"},p),r.DOM.span({className:n},[this.renderHeader(),i])},renderField:function(t,e){var n=this.props.value[t],s=this.state.fields[t]||{},a=e===!0||"object"==typeof e&&e[t];return s.settings||(s.settings={}),r.createElement(i,{value:n,key:t,name:t,ref:t,fixed:a,id:this.props.id,definition:s,onUpdated:this.updateField,onDeleted:this.deleteField,parentSettings:this.props.settings})},renderGroup:function(t,e,n){var i=this,s=[];return t.forEach(function(t){s.push(i.renderField(t,e))}),r.DOM.div({className:"jsonGroup jsonGroup_"+n},s)},getDefaultHeader:function(){return"Map ["+Object.keys(this.props.value).length+"]"},getDefaultAdder:function(){return"+ Add field"},updateField:function(t,e){this.checkEditingSetting(t),this.props.value.set(t,e)},deleteField:function(t){this.props.value.remove(t)},getValidationErrors:function(t){var e=this,n=[],r=Object.keys(this.refs);return r.forEach(function(t){var r=e.refs[t].getValidationErrors();r&&(n=n.concat(r))}),n},getFieldOrder:function(){var t,e=this,n=this.props.settings.order,r=typeof n,i=this.props.settings.fields||{};if(!n||"function"!=r&&n.constructor!==Array)return Object.keys(this.props.value);var a=s({},this.props.value),o=[];if("function"==r)return n(a);n.constructor===Array&&n.forEach(function(n){n.constructor==Array?(t=[],n.forEach(function(n){e.addFieldToOrder(n,a,i)&&(t.push(n),delete a[n])}),t.length&&o.push(t)):e.addFieldToOrder(n,a,i)&&(o.push(n),delete a[n])});for(var u in a)-1==o.indexOf(u)&&o.push(u);return o},addFieldToOrder:function(t,e,n){return"undefined"!=typeof e[t]||n[t]&&"react"==n[t].type}});t.exports=o},function(t,e,n){"use strict";var r=n(1),i=n(14),s=(n(12),n(15)),a=r.createClass({mixins:[s],getInitialState:function(){return this.getStateFromProps(this.props)},getStateFromProps:function(t){return{editing:t.settings.editing||!1,fields:this.state&&this.state.fields||{}}},defaultValue:[],render:function(){for(var t,e,n=this.props.settings,s=this.state.editing?"open jsonArray jsonCompound":"jsonArray jsonCompound",a="",o=this.getFixedFields(),u=this.state.fields,p=[],c=0;c<this.props.value.length;c++)t=u[c]||{},t.settings||(t.settings={}),e=o===!0||"object"==typeof o&&o[c],p.push(r.createElement(i,{value:this.props.value[c],key:c,name:c,id:this.props.id,definition:t,fixed:e,onUpdated:this.updateField,onDeleted:this.deleteField,parentSettings:this.props.settings}));var l=[p];return n.adder!==!1&&l.push(this.renderAdder(this.props.value.length)),a=r.DOM.div({key:"o",className:"jsonChildren"},l),r.DOM.span({className:s},[this.renderHeader(),a])},getDefaultHeader:function(){return"List ["+this.props.value.length+"]"},getDefaultAdder:function(){return"+ Add element"},updateField:function(t,e){this.checkEditingSetting(t),this.props.value.set(t,e)},deleteField:function(t){var e={};for(var n in this.state.fields)n>t?e[n-1]=this.state.fields[n]:t>n&&(e[n]=this.state.fields[n]);this.props.value.splice(t,1),this.setState({fields:e})},isType:function(t){return t&&t.constructor==Array}});t.exports=a},function(t,e,n){var r=n(1),i=n(16),s=r.createClass({mixins:[i],typeClass:"jsonString",inputType:"text",defaultValue:"",getInitialState:function(){return this.getStateFromProps(this.props)},render:function(){return this.renderInput()},updateValue:function(t){this.setState({value:t.target.value})},isType:function(t){return"object"!=typeof t}});t.exports=s},function(t,e,n){var r=n(1),i=r.createClass({defaultValue:!1,render:function(){var t="jsonBoolean";return r.DOM.input({type:"checkbox",className:t,id:this.props.id,checked:this.props.value,onChange:this.updateValue})},updateValue:function(t){this.props.onUpdated(t.target.checked)},isType:function(t){return"boolean"==typeof t},componentWillReceiveProps:function(t){this.props.value!=t.value&&this.setState({value:t.value})}});t.exports=i},function(t,e,n){var r=n(1),i=n(16),s=r.createClass({mixins:[i],typeClass:"jsonNumber",inputType:"number",defaultValue:"",getInitialState:function(){return this.getStateFromProps(this.props)},render:function(){return this.renderInput()},updateValue:function(t){this.setState({value:parseFloat(t.target.value)})},isType:function(t){return"number"==typeof t}});t.exports=s},function(t,e,n){var r=n(1),i=n(16),s=r.createClass({mixins:[i],defaultValue:"",getInitialState:function(){return this.getStateFromProps(this.props)},render:function(){var t="jsonText";return this.state.editing?r.DOM.textarea({value:this.state.value,id:this.props.id,onChange:this.updateValue,placeholder:this.props.settings.placeholder||"",onBlur:this.setValue,ref:"input"}):r.DOM.span({onClick:this.setEditMode,className:t},this.props.value)},updateValue:function(t){this.setState({value:t.target.value})},isType:function(t){return"string"==typeof t&&t.length>100}});t.exports=s},function(t,e,n){var r=n(1),i=n(16),s=r.createClass({mixins:[i],typeClass:"jsonPassword",inputType:"password",defaultValue:"",getInitialState:function(){return this.getStateFromProps(this.props)},render:function(){return this.renderInput()},getDisplayModeString:function(){return this.getWildcards()},getWildcards:function(){for(var t="",e=this.state.value.length-1;e>=0;e--)t+="*";return t},isType:function(){return!1},updateValue:function(t){this.setState({value:t.target.value})}});t.exports=s},function(t,e,n){var r=n(1),i=r.createClass({defaultValue:"",getInitialState:function(){return{value:this.props.value}},render:function(){var t="jsonSelect";return r.DOM.select({className:t,id:this.props.id,value:this.props.value,onChange:this.updateValue},this.renderOptions())},renderOptions:function(){var t=this.props.settings.options,e=[];return t&&t.length?(t.forEach(function(t){var n=t;"object"!=typeof t&&(n={value:t,label:t}),e.push(r.DOM.option({value:n.value},n.label))}),e):e},updateValue:function(t){this.props.onUpdated(t.target.value)},componentWillReceiveProps:function(t){this.props.value!=t.value&&this.setState({value:t.value})}});t.exports=i},function(t,e,n){t.exports={editing:function(t,e){return"undefined"!=typeof e?e:"always"==t?"always":void 0},adder:function(t,e){return"undefined"!=typeof e?e:"undefined"!=typeof t?t:!0},fixedFields:function(t,e){return"undefined"!=typeof e?e:"boolean"==typeof t?t:void 0}}},function(t,e,n){"use strict";function r(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}t.exports=Object.assign||function(t,e){for(var n,i,s=r(t),a=1;a<arguments.length;a++){n=arguments[a],i=Object.keys(Object(n));for(var o=0;o<i.length;o++)s[i[o]]=n[i[o]]}return s}},function(t,e,n){var r=n(17);t.exports=r},function(t,e,n){"use strict";var r=n(1),i=n(12),s=n(18),a=n(2),o=r.createClass({getInitialState:function(){return{error:!1}},getDefaultProps:function(){return{definition:{}}},render:function(){var t,e=this.props.definition||{},n="jsonField",i=e.type||a.prototype.guessType(this.props.value),s=this.props.id+"_"+this.props.name,o="";if("react"==i)return this.renderReactField(e);t=this.renderTypeField(i,s),n+=" "+i+"Field",this.state.error&&(n+=" jsonError",this.state.error!==!0&&(o=r.DOM.span({key:"e",className:"jsonErrorMsg"},this.state.error)));var u=[r.DOM.label({key:"s1",htmlFor:s},(e.title||this.props.name)+":")];return u.unshift(this.props.fixed?r.DOM.span({key:"f",className:"jsonFixed"}):r.DOM.a({key:"a",href:"#",className:"jsonRemove",onClick:this.handleRemove},"x")),r.DOM.div({className:n},[r.DOM.span({className:"jsonName",key:"n"},u),r.DOM.span({className:"jsonValue",key:"v"},t),o])},renderTypeField:function(t,e){var n,s=this.props.definition,o=i({},s.settings||{});return s.fields&&(o.fields=s.fields),n=r.createElement(a,{type:t,value:this.props.value,settings:o,onUpdated:this.onUpdated,ref:"typeField",id:e,parentSettings:this.props.parentSettings})},renderReactField:function(t){return r.DOM.div({className:"jsonField reactField"},t.output)},handleRemove:function(t){this.props.onDeleted(this.props.name)},shouldComponentUpdate:function(t,e){return t.value!=this.props.value||e.error!=this.state.error},onUpdated:function(t){var e=this.props.definition;this.props.value!==t&&(this.props.onUpdated(this.props.name,t),e.onChange&&e.onChange(t,this.props.value))},getValidationErrors:function(t){var e=[],n=this.props.definition.validates,r=this.props.name,i=this.refs.typeField;if(!i)return[];if("object"==i.fieldType&&(e=i.getValidationErrors(t),e.forEach(function(t){t.path=t.path?r+"."+t.path:r}),e.length&&this.setState({error:!0})),!n)return e;var a,o=s.getValidationError(this.props.value,t,n);return o?(a=this.props.definition.errorMessage,a||(a=(this.props.definition.label||this.props.name)+" value is not valid."),o.path=r,o.message=a,this.setState({error:a}),e=e.concat([o])):this.state.error&&this.setState({error:!1}),e}});t.exports=o},function(t,e,n){"use strict";var r=n(1),i=n(19),s=n(12);t.exports={renderHeader:function(){var t=this.props.settings.header;if(t===!1)return"";var e,n=typeof t;return e="function"==n?t(this.props.value.toJS()):"undefined"==n?this.getDefaultHeader():t,r.DOM.span({key:"s",onClick:this.toggleEditing,className:"compoundToggle"},e)},toggleEditing:function(){"always"!=this.state.editing&&this.props.settings.header!==!1&&this.setState({editing:!this.state.editing})},componentWillReceiveProps:function(t){this.props.settings.editing!=t.settings.editing&&this.setState({editing:t.editing})},renderAdder:function(t){var e,n=this.props.settings.adder,s=typeof n;return e="function"==s?n(this.props.value.toJS()):n===!0||"undefined"==s?this.getDefaultAdder():n,r.createElement(i,{onCreate:this.createField,name:t,key:"add",text:e})},createField:function(t,e,n){if(this.props.value[t])return console.log("Field "+t+" already exists.");n.settings={editing:"always"==this.state.editing?"always":!0,focus:!0};var r=s({},this.state.fields);r[t]=n,this.setState({fields:r}),this.props.value.set(t,e)},checkEditingSetting:function(t){var e=this.state.fields;e[t]&&e[t].settings.focus===!0&&(e=s({},e),e[t].settings.focus=!1,this.setState({fields:e}))},getFixedFields:function(){var t=this.props.settings.fixedFields,e={};return t&&t.constructor==Array?(t.forEach(function(t){e[t]=1}),e):t}}},function(t,e,n){"use strict";var r=n(1);t.exports={getStateFromProps:function(t){return{editing:t.settings.editing||!1,value:t.value}},renderInput:function(){var t=this.typeClass;return this.state.editing?r.DOM.input({type:this.inputType,value:this.state.value,id:this.props.id,placeholder:this.props.settings.placeholder||"",onChange:this.updateValue,onBlur:this.setValue,ref:"input",onKeyDown:this.handleKeyDown}):r.DOM.span({onClick:this.setEditMode,className:t},this.getDisplayString())},getDisplayString:function(){return this.getDisplayModeString?this.getDisplayModeString():""===this.props.value?r.DOM.span({className:"jsonNovalue"},"No value"):this.props.value},componentWillReceiveProps:function(t){var e={},n=!1;this.props.value!=t.value&&(n=!0,e.value=t.value),this.props.settings.editing!=t.settings.editing&&(n=!0,e.editing=t.editing),n&&this.setState(e)},componentDidUpdate:function(t,e){(this.state.editing&&!e.editing||this.props.settings.focus)&&this.focus()},componentDidMount:function(){(this.state.editing===!0||this.props.settings.focus)&&this.focus()},setEditMode:function(){this.setState({editing:!0})},setValue:function(){"always"!=this.state.editing&&this.setState({editing:!1}),this.props.onUpdated(this.state.value)},toggleEditing:function(){this.setState({editing:!this.state.editing})},handleKeyDown:function(t){13==t.which&&this.setValue()},focus:function(){var t=this.refs.input.getDOMNode();t.focus(),t.value=t.value}}},function(t,e,n){"use strict";var r=n(20),i=n(21),s=(n(22),n(23)),a=function(t,e){var n,i=this,a=function(t,e,n){return"listener"==t?s.createListener(e):s.update(t,e,n)},o=function(){};e||(o=function(t){Object.freeze(t)}),n=s.freeze(t,a,o);var u=n.getListener(),p=!1;u.on("immediate",function(t,e){t==n&&(n=e,p||(p=!0,r.nextTick(function(){p=!1,i.trigger("update",n)})))}),r.addNE(this,{get:function(){return n},set:function(t){var e=a("reset",n,t);e.__.listener.trigger("immediate",n,e)}}),r.addNE(this,{getData:this.get,setData:this.set}),this._events=[]};a.prototype=r.createNonEnumerable({constructor:a},i),t.exports=a},function(t,e,n){"use strict";function r(t,e){return t.length?r(t.slice(1),e[t[0]]):e}var i={required:function(t){return t&&("string"!=typeof t||t.trim())?!0:!1},email:function(t){if(!t)return!0;var e=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return e.test(t)},length:function(t,e,n,r){return n||(n=0),r||(r=1/0),t.length>=n&&t.length<=r},integer:function(t,e,n,r){if(n||0===n||(n=-(1/0)),r||(r=1/0),!t&&0!=t)return!0;var i=parseInt(t);return t!=i?!1:r>=i&&i>=n},checked:function(t){return t},matches:function(t,e,n){return t==r(n.split("."),e)}};t.exports={getValidationError:function(t,e,n){var r=[],o=!1,u=0;"string"==typeof n?r=s(n):"function"==typeof n?r=[n]:n&&n.constructor===Array&&(r=n);for(var p,c,l;!o&&u<r.length;)l=r[u++],"string"==typeof l?(p=a(l),c=i[p.name],c?c.apply(null,[t,e].concat(p.args))||(o={value:t,method:l}):console.log("Unkown validation method "+p.name)):"function"==typeof l&&(l(t,e)||(o={value:t,method:"custom"}));return o}};var s=function(t){return t.match(/[^\s\[]+(\[[^\]]+?\])?/gi)},a=function(t){var e,n=t.split("["),r={name:n[0],args:[]};return n.length>1&&(e=n[1],"]"==e[e.length-1]&&(e=e.slice(0,e.length-1)),r.args=e.split(/\s*,\s*/)),r}},function(t,e,n){var r=n(1),i=n(2),s=r.createClass({getInitialState:function(){return{creating:this.props.creating||!1,name:this.props.name,type:"string"}},render:function(){if(!this.state.creating)return r.DOM.a({className:"jsonAdd",href:"#",onClick:this.handleCreate},this.props.text);var t,e=this.getTypes().map(function(t){return r.DOM.option({value:t,key:t},t[0].toUpperCase()+t.slice(1))});return t="undefined"!=typeof this.props.name?[r.DOM.span({className:"jsonName"},this.props.name),r.DOM.span(null,":")]:[r.DOM.input({ref:"keyInput",type:"text",value:this.state.value,onChange:this.changeKey}),r.DOM.span(null,":")],r.DOM.div({className:"jsonField jsonFieldAdder"},[t,r.DOM.select({key:"s",value:this.state.type,onChange:this.changeType,ref:"typeSelector"},e),r.DOM.button({key:"b",onClick:this.createField},"OK"),r.DOM.a({key:"a",href:"#",className:"cancelField",onClick:this.handleCancel},"Cancel")])},componentDidUpdate:function(t,e){!e.creating&&this.state.creating&&(this.refs.keyInput?this.refs.keyInput.getDOMNode().focus():this.refs.typeSelector.getDOMNode().focus())},componentWillReceiveProps:function(t){this.setState({name:t.name})},handleCreate:function(t){t.preventDefault(),this.setState({creating:!0})},handleCancel:function(t){t.preventDefault(),this.setState({creating:!1})},changeType:function(t){this.setState({type:t.target.value})},changeKey:function(t){this.setState({name:t.target.value})},createField:function(){this.setState({creating:!1});var t=i.prototype.components[this.state.type].prototype.defaultValue;this.props.onCreate(this.state.name,t,{type:this.state.type})},getTypes:function(){return Object.keys(i.prototype.components)}});t.exports=s},function(t,e,n){"use strict";var r=new Function("return this")(),i={extend:function(t,e){for(var n in e)t[n]=e[n];return t},createNonEnumerable:function(t,e){var n={};for(var r in t)n[r]={value:t[r]};return Object.create(e||{},n)},error:function(t){var e=new Error(t);if(console)return console.error(e);throw e},each:function(t,e){var n,r,i;if(t&&t.constructor==Array)for(n=0,r=t.length;r>n;n++)e(t[n],n);else for(i=Object.keys(t),n=0,r=i.length;r>n;n++)e(t[i[n]],i[n])},addNE:function(t,e){for(var n in e)Object.defineProperty(t,n,{enumerable:!1,configurable:!0,writable:!0,value:e[n]})},nextTick:function(){function t(){for(;n=i.shift();)n();s=!1}function e(t){i.push(t),s||(s=!0,u())}var n,i=[],s=!1,a=!!r.postMessage,o="nexttick",u=function(){return a?function(){r.postMessage(o,"*")}:function(){setTimeout(function(){p()},0)}}(),p=function(){return a?function(e){e.source===r&&e.data===o&&(e.stopPropagation(),t())}:t}();return a&&r.addEventListener("message",p,!0),e.removeListener=function(){r.removeEventListener("message",p,!0)},e}()};t.exports=i},function(t,e,n){"use strict";var r=n(20),i={on:function(t,e,n){var r=this._events[t]||[];return r.push({callback:e,once:n}),this._events[t]=r,this},once:function(t,e){this.on(t,e,!0)},off:function(t,e){if("undefined"==typeof t)this._events={};else if("undefined"==typeof e)this._events[t]=[];else{var n,r=this._events[t]||[];for(n=r.length-1;n>=0;n--)r[n]===e&&r.splice(n,1)}return this},trigger:function(t){var e,n,r=[].slice.call(arguments,1),i=this._events[t]||[],s=[];for(e=0;e<i.length;e++)n=i[e],n.callback?n.callback.apply(null,r):n.once=!0,n.once&&s.push(e);for(e=s.length-1;e>=0;e--)i.splice(s[e],1);return this}},s=r.createNonEnumerable(i);t.exports=s},function(t,e,n){"use strict";var r=n(20),i=function(t){var e={};for(var n in t)e[n]={writable:!0,configurable:!0,enumerable:!1,value:t[n]};return e},s={set:function(t,e){var n=t,r=this.__.trans;if("undefined"!=typeof e&&(n={},n[t]=e),!r){for(var i in n)r=r||this[i]!=n[i];if(!r)return this}return this.__.notify("merge",this,n)},reset:function(t){return this.__.notify("replace",this,t)},getListener:function(){return this.__.notify("listener",this)},toJS:function(){var t;return t=this.constructor==Array?new Array(this.length):{},r.each(this,function(e,n){t[n]=e&&e.__?e.toJS():e}),t},transact:function(){return this.__.notify("transact",this)},run:function(){return this.__.notify("run",this)}},a=r.extend({push:function(t){return this.append([t])},append:function(t){return t&&t.length?this.__.notify("splice",this,[this.length,0].concat(t)):this},pop:function(){return this.length?this.__.notify("splice",this,[this.length-1,1]):this},unshift:function(t){return this.prepend([t])},prepend:function(t){return t&&t.length?this.__.notify("splice",this,[0,0].concat(t)):this},shift:function(){return this.length?this.__.notify("splice",this,[0,1]):this},splice:function(t,e,n){return this.__.notify("splice",this,arguments)}},s),o=Object.create(Array.prototype,i(a)),u={Hash:Object.create(Object.prototype,i(r.extend({remove:function(t){var e=[],n=t;t.constructor!=Array&&(n=[t]);for(var r=0,i=n.length;i>r;r++)this.hasOwnProperty(n[r])&&e.push(n[r]);return e.length?this.__.notify("remove",this,e):this}},s))),List:o,arrayMethods:a};t.exports=u},function(t,e,n){"use strict";var r=n(20),i=n(22),s=n(21),a={freeze:function(t,e,n){if(t&&t.__)return t;var s,a,o=this;return s=t.constructor==Array?this.createArray(t.length):Object.create(i.Hash),r.addNE(s,{__:{listener:!1,parents:[],notify:e,dirty:!1,freezeFn:n}}),r.each(t,function(t,r){a=t&&t.constructor,(a==Array||a==Object)&&(t=o.freeze(t,e,n)),t&&t.__&&o.addParent(t,s),s[r]=t}),n(s),s},update:function(t,e,n){return this[t]?this[t](e,n):r.error("Unknown update type: "+t)},reset:function(t,e){var n,i=this;return e&&e.__?(n=e,n.__.listener=e.__.listener,n.__.parents=[],this.fixChildren(n,t),r.each(n,function(e){e&&e.__&&(i.removeParent(t),i.addParent(e,n))})):n=this.freeze(t,t.__.notify,t.__.freezeFn),n},merge:function(t,e){var n=t.__.trans,e=r.extend({},e);if(n){for(var i in e)n[i]=e[i];return t}var s,a,o,u,p=this,c=this.copyMeta(t),l=t.__.notify;r.each(t,function(n,r){return u=n&&n.__,u&&p.removeParent(n,t),(s=e[r])?(a=s&&s.constructor,(a==Array||a==Object)&&(s=p.freeze(s,l,t.__.freezeFn)),s&&s.__&&p.addParent(s,c),delete e[r],void(c[r]=s)):(u&&p.addParent(n,c),c[r]=n)});for(o in e)s=e[o],a=s&&s.constructor,(a==Array||a==Object)&&(s=p.freeze(s,l,t.__.freezeFn)),s&&s.__&&p.addParent(s,c),c[o]=s;return t.__.freezeFn(c),this.refreshParents(t,c),c},replace:function(t,e){var n=this,r=e&&e.constructor,i=t.__,s=e;(r==Array||r==Object)&&(s=n.freeze(e,i.notify,i.freezeFn),s.__.parents=i.parents,i.listener&&(s.__.listener=t.__.listener),s.__.listener&&this.trigger(s,"update",s)),!i.parents.length&&i.listener&&i.listener.trigger("immediate",t,s);for(var a=i.parents.length-1;a>=0;a--)0==a?this.refresh(i.parents[a],t,s,!1):this.markDirty(i.parents[a],[t,s]);return s},remove:function(t,e){var n=t.__.trans;if(n){for(var i=e.length-1;i>=0;i--)delete n[e[i]];return t}var s,a=this,o=this.copyMeta(t);return r.each(t,function(n,r){s=n&&n.__,s&&a.removeParent(n,t),-1==e.indexOf(r)&&(s&&a.addParent(n,o),o[r]=n)}),t.__.freezeFn(o),this.refreshParents(t,o),o},splice:function(t,e){var n=t.__.trans;if(n)return n.splice.apply(n,e),t;var i,s,a=this,o=this.copyMeta(t),u=e[0],p=u+e[1],c=t.__;if(r.each(t,function(e,n){e&&e.__&&(a.removeParent(e,t),(u>n||n>=p)&&a.addParent(e,o)),o[n]=e}),e.length>1)for(var l=e.length-1;l>=2;l--)s=e[l],i=s&&s.constructor,(i==Array||i==Object)&&(s=this.freeze(s,c.notify,c.freezeFn)),s&&s.__&&this.addParent(s,o),e[l]=s;return Array.prototype.splice.apply(o,e),t.__.freezeFn(o),this.refreshParents(t,o),o},transact:function(t){var e,n=this,i=t.__.trans;return i?i:(e=t.constructor==Array?[]:{},r.each(t,function(t,n){e[n]=t}),t.__.trans=e,r.nextTick(function(){t.__.trans&&n.run(t)}),e)},run:function(t){var e=this,n=t.__.trans;if(!n)return t;r.each(n,function(n,r){n&&n.__&&e.removeParent(n,t)}),delete t.__.trans;var i=this.replace(t,n);return i},refresh:function(t,e,n,i){var s=this,a=t.__.trans,o=0;if(a)return r.each(a,function(r,i){o||r===e&&(a[i]=n,o=1,n&&n.__&&s.addParent(n,t))}),t;var u,p,c,l=this.copyMeta(t),f=t.__.dirty;return f&&(u=f[0],p=f[1]),r.each(t,function(r,i){r===e?r=n:r===u&&(r=p),r&&(c=r.__)&&(!c.trans&&c.dirty&&(r=s.refresh(r,c.dirty[0],c.dirty[1],!0)),s.removeParent(r,t),s.addParent(r,l)),l[i]=r}),t.__.freezeFn(l),t.__.dirty=!1,i?l:void this.refreshParents(t,l)},fixChildren:function(t,e){var n=this;r.each(t,function(r){if(r&&r.__){if(-1!=r.__.parents.indexOf(t))return n.fixChildren(r);if(1==r.__.parents.length)return r.__.parents=[t];e&&n.removeParent(r,e),n.addParent(t)}})},copyMeta:function(t){var e;e=t.constructor==Array?this.createArray(t.length):Object.create(i.Hash);var n=t.__;return r.addNE(e,{__:{notify:n.notify,listener:n.listener,parents:n.parents.slice(0),trans:n.trans,dirty:!1,freezeFn:n.freezeFn}}),e},refreshParents:function(t,e){var n,r=t.__;if(r.listener&&this.trigger(e,"update",e),r.parents.length)for(n=r.parents.length-1;n>=0;n--)0==n?this.refresh(r.parents[n],t,e,!1):this.markDirty(r.parents[n],[t,e]);else r.listener&&r.listener.trigger("immediate",t,e)},markDirty:function(t,e){var n,r=t.__;for(r.dirty=e,r.trans&&this.refresh(t,e[0],e[1]),n=r.parents.length-1;n>=0;n--)this.markDirty(r.parents[n],e)},removeParent:function(t,e){var n=t.__.parents,r=n.indexOf(e);-1!=r&&n.splice(r,1)},addParent:function(t,e){var n=t.__.parents,r=n.indexOf(e);-1==r&&(n[n.length]=e)},trigger:function(t,e,n){var i=t.__.listener,s=i.ticking;i.ticking=n,s||r.nextTick(function(){var t=i.ticking;i.ticking=!1,i.trigger(e,t)})},createListener:function(t){var e=t.__.listener;return e||(e=Object.create(s,{_events:{value:{},writable:!0}}),t.__.listener=e),e},createArray:function(){return[].__proto__?function(t){var e=new Array(t);return e.__proto__=i.List,e}:function(t){var e=new Array(t),n=i.arrayMethods;for(var r in n)e[r]=n[r];return e}}()};t.exports=a}])});