capejs-rails 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7323d4e08d6718e87bb6905c472d8916e1e0e88a
4
+ data.tar.gz: e1c05a7c8b2a365b4d8de071100bcffcae76a1d0
5
+ SHA512:
6
+ metadata.gz: 353f711d43b01f17cfdd19c0743268f8ab17f0c238645315add3a284fd59425f1c3a0bae8f40df2b15adc0f966b199e978f36f68a92e51b15f21a3cec3be2e6e
7
+ data.tar.gz: a633cdc91edf430c1543fc8818477f2f2d913184c3c9d2cd7506e5d3bd41db8b388b643ccfcae5df5e8c69b9cba317232425c9a5638d5e65fa030d605d409fbf
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Oiax Inc. and contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # capejs-rails
2
+
3
+ This gem wraps the [Cape.JS](https://github.com/oiax/capejs) for use in Rails 4.2 and above.
4
+
5
+ ## Usage
6
+
7
+ Add the following to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'capejs-rails'
11
+ gem 'sass-rails', github: 'rails/sass-rails', branch: 'master'
12
+ gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master'
13
+ gem 'sprockets', github: 'rails/sprockets', branch: 'master'
14
+ gem 'babel-transpiler'
15
+ ```
16
+
17
+ Add the following directive to your `application.js`:
18
+
19
+ ```javascript
20
+ //= require capejs
21
+ ```
@@ -0,0 +1,4564 @@
1
+ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Cape = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+ 'use strict';
3
+
4
+ var Cape = require('./cape/utilities');
5
+ Cape.MarkupBuilder = require('./cape/markup_builder');
6
+ Cape.VirtualForms = require('./cape/virtual_forms');
7
+ Cape.Component = require('./cape/component.js');
8
+ Cape.Partial = require('./cape/partial.js');
9
+ Cape.DataStore = require('./cape/data_store.js');
10
+ Cape.AgentAdapters = {};
11
+ Cape.AgentAdapters.RailsAdapter = require('./cape/agent_adapters/rails_adapter.js');
12
+ Cape.ResourceAgent = require('./cape/resource_agent.js');
13
+ Cape.CollectionAgent = require('./cape/collection_agent.js');
14
+ Cape.RoutingMapper = require('./cape/routing_mapper.js');
15
+ Cape.Router = require('./cape/router.js');
16
+
17
+ // Default name of adapter fo CollectionAgent and ResourceAgent (e.g. 'rails')
18
+ Cape.defaultAgentAdapter = undefined;
19
+
20
+ module.exports = Cape;
21
+
22
+ },{"./cape/agent_adapters/rails_adapter.js":2,"./cape/collection_agent.js":3,"./cape/component.js":4,"./cape/data_store.js":5,"./cape/markup_builder":6,"./cape/partial.js":11,"./cape/resource_agent.js":12,"./cape/router.js":13,"./cape/routing_mapper.js":14,"./cape/utilities":15,"./cape/virtual_forms":16}],2:[function(require,module,exports){
23
+ 'use strict';
24
+
25
+ // Cape.AgentAdapters.RailsAdapter
26
+ //
27
+ // This function is called just before an instance of Cape.ResourceAgent or
28
+ // Cape.ResourceCollectionAgent makes an Ajax request.
29
+ //
30
+ // The purpose of this adapter is to set the X-CSRF-Token header of Ajax requests.
31
+
32
+ function RailsAdapter(resourceName, client, options) {
33
+ var metaElements = document.getElementsByTagName('meta');
34
+ for (var i = metaElements.length - 1; i >= 0; i--) {
35
+ if (metaElements[i].getAttribute('name') === 'csrf-token') {
36
+ this.headers['X-CSRF-Token'] = metaElements[i].getAttribute('content');
37
+ break;
38
+ }
39
+ }
40
+ }
41
+
42
+ module.exports = RailsAdapter;
43
+
44
+ },{}],3:[function(require,module,exports){
45
+ 'use strict';
46
+
47
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
48
+
49
+ var Inflector = require('inflected');
50
+ var Cape = require('./utilities');
51
+
52
+ // Cape.CollectionAgent
53
+ //
54
+ // public properties:
55
+ // resourceName: the name of resource
56
+ // basePath: the string that is added to the request path. Default value is '/'.
57
+ // nestedIn: the string that is inserted between path prefix and the resource
58
+ // name. Default value is ''.
59
+ // shallow: a boolean value that controls whether the agent should omit
60
+ // the `nestedIn` string from the member path. Default is `false`.
61
+ // adapter: the name of adapter (e.g., 'rails'). Default is undefined.
62
+ // Default value can be changed by setting Cape.defaultAgentAdapter property.
63
+ // autoRefresh: a boolean value that controls unsafe Ajax requests trigger
64
+ // this.refresh(). Default is `true`.
65
+ // dataType: the type of data that you're expecting from the server.
66
+ // The value must be 'json', 'text' or undefined. Default is undefiend.
67
+ // When the `dataType` option is not defined, the type is detected automatically.
68
+ // paramName: the name of parameter to be used when the `objects`
69
+ // property is initialized and refreshed. Default is undefiend.
70
+ // When the `paramName` option is not defined, the name is derived from the
71
+ // `resourceName` property, e.g. `user` if the resource name is `users`.
72
+ // objects: the array of objects that represent the collection of resources
73
+ // data: the response data from the server. This property holds an object
74
+ // if the response data is a valid JSON string. Otherwise, it holds the
75
+ // original string value.
76
+ // headers: the HTTP headers for Ajax requests
77
+ // private properties:
78
+ // _: the object that holds internal methods and properties of this class.
79
+ //
80
+ // parameters for the constructor
81
+ // options: an object that is used to initialize properties. The properties
82
+ // which can be initialized by it are `resourceName`, `basePath`,
83
+ // `nestedIn`, `adapter`, `autoRefresh`, `dataType`, and `paramName`.
84
+ //
85
+ var CollectionAgent = function CollectionAgent(client, options) {
86
+ this._ = new _Internal(this);
87
+ this.init(options);
88
+
89
+ this.client = client;
90
+ this.objects = [];
91
+ this.data = undefined;
92
+ this.headers = { 'Content-Type': 'application/json' };
93
+ };
94
+
95
+ _extends(CollectionAgent.prototype, {
96
+ init: function (options) {
97
+ options = options || {};
98
+ this.resourceName = options.resourceName;
99
+ this.basePath = options.basePath;
100
+ this.nestedIn = options.nestedIn;
101
+ this.shallow = options.shallow || false;
102
+ this.adapter = options.adapter;
103
+ this.autoRefresh = options.autoRefresh;
104
+ if (this.autoRefresh === undefined) this.autoRefresh = true;
105
+ this.dataType = options.dataType;
106
+ this.paramName = options.paramName;
107
+ },
108
+
109
+ // Fetch current data through the API and refresh this.objects.
110
+ //
111
+ // The default implementation assumes that the request URI has no query string and
112
+ // the API returns a hash like this:
113
+ // { users: [ { id: 1, name: 'John' }, { id: 2, name: 'Kate' } ]}
114
+ //
115
+ // Developers may change this assumption by overriding the `paramsForRefresh()`
116
+ // method or setting the `paramName` property.
117
+ refresh: function () {
118
+ var self = this;
119
+ this.index(this.paramsForRefresh(), function (data) {
120
+ self.data = data;
121
+ self.refreshObjects(data);
122
+ self.afterRefresh();
123
+ });
124
+ },
125
+
126
+ // Returns an empty object always. This object is used to construct
127
+ // the query string of the request URL during the `refresh()` process.
128
+ //
129
+ // Developers may override this method to change this behavior.
130
+ paramsForRefresh: function () {
131
+ return {};
132
+ },
133
+
134
+ // Refresh the `objects` property using the response data from the server.
135
+ //
136
+ // Developers may override this method to change its default behavior.
137
+ refreshObjects: function (data) {
138
+ var paramName = this.paramName || Inflector.tableize(this.resourceName);
139
+
140
+ this.objects.length = 0;
141
+ if (typeof data === 'object' && Array.isArray(data[paramName])) {
142
+ for (var i = 0; i < data[paramName].length; i++) {
143
+ this.objects.push(data[paramName][i]);
144
+ }
145
+ }
146
+ },
147
+
148
+ // Called by the `refresh()` method after it updates the `data` and
149
+ // `objects` properties.
150
+ //
151
+ // Developers may override this method to let the agent do some
152
+ // post-processing jobs.
153
+ afterRefresh: function () {
154
+ this.client.refresh();
155
+ },
156
+
157
+ index: function (params, callback, errorHandler) {
158
+ this.get('', null, params, callback, errorHandler);
159
+ },
160
+
161
+ create: function (params, callback, errorHandler) {
162
+ this.post('', null, params, callback, errorHandler);
163
+ },
164
+
165
+ update: function (id, params, callback, errorHandler) {
166
+ this.patch('', id, params, callback, errorHandler);
167
+ },
168
+
169
+ destroy: function (id, callback, errorHandler) {
170
+ this.delete('', id, {}, callback, errorHandler);
171
+ },
172
+
173
+ get: function (actionName, id, params, callback, errorHandler) {
174
+ var path = id ? this.memberPath(id) : this.collectionPath();
175
+ if (actionName !== '') path = path + '/' + actionName;
176
+ this.ajax('GET', path, params, callback, errorHandler);
177
+ },
178
+
179
+ head: function (actionName, id, params, callback, errorHandler) {
180
+ var path = id ? this.memberPath(id) : this.collectionPath();
181
+ if (actionName !== '') path = path + '/' + actionName;
182
+ this.ajax('HEAD', path, params, callback, errorHandler);
183
+ },
184
+
185
+ post: function (actionName, id, params, callback, errorHandler) {
186
+ var path = id ? this.memberPath(id) : this.collectionPath();
187
+ if (actionName !== '') path = path + '/' + actionName;
188
+ this.ajax('POST', path, params, callback, errorHandler);
189
+ },
190
+
191
+ patch: function (actionName, id, params, callback, errorHandler) {
192
+ var path = id ? this.memberPath(id) : this.collectionPath();
193
+ if (actionName !== '') path = path + '/' + actionName;
194
+ this.ajax('PATCH', path, params, callback, errorHandler);
195
+ },
196
+
197
+ put: function (actionName, id, params, callback, errorHandler) {
198
+ var path = id ? this.memberPath(id) : this.collectionPath();
199
+ if (actionName !== '') path = path + '/' + actionName;
200
+ this.ajax('PUT', path, params, callback, errorHandler);
201
+ },
202
+
203
+ delete: function (actionName, id, params, callback, errorHandler) {
204
+ var path = id ? this.memberPath(id) : this.collectionPath();
205
+ if (actionName !== '') path = path + '/' + actionName;
206
+ this.ajax('DELETE', path, params, callback, errorHandler);
207
+ },
208
+
209
+ collectionPath: function () {
210
+ var resources = Inflector.pluralize(Inflector.underscore(this.resourceName));
211
+ return this._.pathPrefix() + resources;
212
+ },
213
+
214
+ memberPath: function (id) {
215
+ var resources = Inflector.pluralize(Inflector.underscore(this.resourceName));
216
+ return this._.pathPrefix(this.shallow) + resources + '/' + id;
217
+ },
218
+
219
+ defaultErrorHandler: function (ex) {
220
+ console.log(ex);
221
+ }
222
+ });
223
+
224
+ var AgentCommonMethods = require('./mixins/agent_common_methods');
225
+ _extends(CollectionAgent.prototype, AgentCommonMethods);
226
+
227
+ // Internal properties of Cape.CollectionAgent
228
+ var _Internal = function _Internal(main) {
229
+ this.main = main;
230
+ this.components = [];
231
+ };
232
+
233
+ var AgentCommonInnerMethods = require('./mixins/agent_common_inner_methods');
234
+
235
+ // Internal methods of Cape.CollectionAgent
236
+ _extends(_Internal.prototype, AgentCommonInnerMethods);
237
+
238
+ module.exports = CollectionAgent;
239
+
240
+ },{"./mixins/agent_common_inner_methods":7,"./mixins/agent_common_methods":8,"./utilities":15,"inflected":22}],4:[function(require,module,exports){
241
+ (function (global){
242
+ 'use strict';
243
+
244
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
245
+
246
+ var virtualDom = require('virtual-dom');
247
+ var Inflector = require('inflected');
248
+ var Cape = require('./utilities');
249
+
250
+ // Cape.Component
251
+ //
252
+ // public properties:
253
+ // root: the root node which this component is mounted on.
254
+ // virtualForms: an object that keeps the values of all form controls within this component.
255
+ // private properties:
256
+ // _: the object that holds internal methods and properties of this class.
257
+ var Component = function Component() {
258
+ this.root = undefined;
259
+ this.virtualForms = new Cape.VirtualForms(this);
260
+ this._ = new _Internal(this);
261
+ };
262
+
263
+ _extends(Component.prototype, {
264
+ mount: function (id) {
265
+ if (id === undefined) throw new Error("The first argument is missing.");
266
+ if (typeof id !== 'string') throw new Error("The first argument must be a string.");
267
+ if (this._.mounted) throw new Error("This component has been mounted already.");
268
+
269
+ this._.mounted = true;
270
+ this.root = document.getElementById(id);
271
+ this.root.data = this._.getElementData(this.root);
272
+
273
+ if (this.init) this.init();else this.refresh();
274
+ },
275
+ unmount: function () {
276
+ if (!this._.mounted) throw new Error("This component has not been mounted yet.");
277
+
278
+ this._.mounted = false;
279
+
280
+ if (this.beforeUnmount) this.beforeUnmount();
281
+ while (this.root.firstChild) this.root.removeChild(this.root.firstChild);
282
+ if (this.afterUnmount) this.afterUnmount();
283
+ },
284
+ refresh: function () {
285
+ var builder, newTree, patches, tempNode, textareaNodes, i, j, len, form, elements, elem, formName, vform, elemName;
286
+
287
+ builder = new global.Cape.MarkupBuilder(this);
288
+
289
+ this.virtualForms.prepare();
290
+ if (this._.tree) {
291
+ newTree = builder.markup(this.render);
292
+ patches = virtualDom.diff(this._.tree, newTree);
293
+ this.root = virtualDom.patch(this.root, patches);
294
+ this._.tree = newTree;
295
+ } else {
296
+ this._.tree = builder.markup(this.render);
297
+ tempNode = virtualDom.create(this._.tree);
298
+ this.root.parentNode.replaceChild(tempNode, this.root);
299
+ this.root = tempNode;
300
+ }
301
+ this.virtualForms.apply();
302
+ },
303
+ val: function (arg1, arg2) {
304
+ if (arguments.length === 1) return this.virtualForms.val(arg1);else return this.virtualForms.val(arg1, arg2);
305
+ },
306
+ setValues: function (formName, obj) {
307
+ this.virtualForms.setValues(formName, obj);
308
+ },
309
+ formData: function (formName) {
310
+ return this.virtualForms.formData(formName);
311
+ },
312
+ paramsFor: function (formName, options) {
313
+ return this.virtualForms.paramsFor(formName, options);
314
+ },
315
+ jsonFor: function (formName, options) {
316
+ return this.virtualForms.jsonFor(formName, options);
317
+ },
318
+ checkedOn: function (name) {
319
+ return this.virtualForms.checkedOn(name);
320
+ }
321
+ });
322
+
323
+ // Internal properties of Cape.Component
324
+ var _Internal = function _Internal(main) {
325
+ this.main = main;
326
+ this.mounted = false;
327
+ };
328
+
329
+ // Internal methods of Cape.Component
330
+ _extends(_Internal.prototype, {
331
+ getElementData: function (element) {
332
+ var data = {},
333
+ camelCaseName;
334
+ [].forEach.call(element.attributes, function (attr) {
335
+ if (/^data-/.test(attr.name)) {
336
+ camelCaseName = attr.name.substr(5).replace(/-(.)/g, function ($0, $1) {
337
+ return $1.toUpperCase();
338
+ });
339
+ data[camelCaseName] = attr.value;
340
+ }
341
+ });
342
+ return data;
343
+ }
344
+ });
345
+
346
+ module.exports = Component;
347
+
348
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
349
+ },{"./utilities":15,"inflected":22,"virtual-dom":36}],5:[function(require,module,exports){
350
+ 'use strict';
351
+
352
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
353
+
354
+ var Cape = require('./utilities');
355
+
356
+ // Cape.DataStore
357
+ //
358
+ // public properties:
359
+ // options: the object that holds option values given to the constructor
360
+ // private properties:
361
+ // _: the object that holds internal methods and properties of this class.
362
+ var DataStore = function DataStore(options) {
363
+ this.options = options || {};
364
+ this._ = new _Internal(this);
365
+ if (typeof this.init === 'function') this.init();
366
+ };
367
+
368
+ DataStore.create = function (options) {
369
+ if (!this.instance) this.instance = new this(options);
370
+ return this.instance;
371
+ };
372
+
373
+ var PropagatorMethods = require('./mixins/propagator_methods');
374
+ _extends(DataStore.prototype, PropagatorMethods);
375
+
376
+ // Internal properties of Cape.DataStore
377
+ var _Internal = function _Internal(main) {
378
+ this.main = main;
379
+ this.components = [];
380
+ };
381
+
382
+ module.exports = DataStore;
383
+
384
+ },{"./mixins/propagator_methods":10,"./utilities":15}],6:[function(require,module,exports){
385
+ 'use strict';
386
+
387
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
388
+
389
+ var virtualDom = require('virtual-dom');
390
+ var Inflector = require('inflected');
391
+ var Cape = require('./utilities');
392
+
393
+ // Cape.MarkupBuilder
394
+ //
395
+ // public properties:
396
+ // component: the component that this builder works for.
397
+ // formName: current form name.
398
+ // selectBoxName: current select box name.
399
+ // fieldNamePrefix: current field name prefix.
400
+ // private properties:
401
+ // _: the object that holds internal methods and properties of this class.
402
+ var MarkupBuilder = function MarkupBuilder(component, options) {
403
+ this._ = new _Internal(this);
404
+ this.component = component;
405
+ if (options) {
406
+ this.formName = options.formName;
407
+ this.selectBoxName = options.selectBoxName;
408
+ this.fieldNamePrefix = options.fieldNamePrefix;
409
+ }
410
+ };
411
+
412
+ _extends(MarkupBuilder.prototype, {
413
+ markup: function (callback) {
414
+ var root = this.component.root,
415
+ formName,
416
+ builder,
417
+ attributes;
418
+
419
+ if (typeof callback !== 'function') throw new Error("The first agument must be a function.");
420
+ if (callback.length === 0) throw new Error("Callback requires an argument.");
421
+ if (root.tagName == 'form') formName = root.attributes.name;
422
+ builder = new MarkupBuilder(this.component, { formName: formName });
423
+ callback.call(this.component, builder);
424
+
425
+ attributes = {};
426
+ for (var i = root.attributes.length; i--;) attributes[root.attributes[i].nodeName] = root.attributes[i].value;
427
+ return this._.h(root.tagName, attributes, builder._.elements);
428
+ },
429
+ elem: function (tagName) {
430
+ var args, options, content, callback, builder, attributes;
431
+
432
+ args = Array.prototype.slice.call(arguments, 1);
433
+ content = this._.extractContent(args);
434
+ options = this._.extractOptions(args);
435
+ callback = this._.extractCallback(args);
436
+
437
+ if (callback) {
438
+ builder = new MarkupBuilder(this.component, { formName: this.formName,
439
+ selectBoxName: this.selectBoxName,
440
+ fieldNamePrefix: this.fieldNamePrefix });
441
+ if (callback.length === 0) {
442
+ throw new Error("Callback requires an argument.");
443
+ }
444
+ callback.call(this.component, builder);
445
+ attributes = this._.generateAttributes(options);
446
+ this._.elements.push(this._.h(tagName, attributes, builder._.elements));
447
+ } else {
448
+ content = content || '';
449
+ attributes = this._.generateAttributes(options);
450
+ this._.elements.push(this._.h(tagName, attributes, content));
451
+ }
452
+ return this;
453
+ },
454
+ text: function (content) {
455
+ this._.elements.push(content);
456
+ return this;
457
+ },
458
+ space: function () {
459
+ this._.elements.push(' ');
460
+ return this;
461
+ },
462
+ sp: function () {
463
+ this.space();
464
+ return this;
465
+ },
466
+ formFor: function (name) {
467
+ var args, options, callback, name, builder, attributes;
468
+
469
+ args = Array.prototype.slice.call(arguments);
470
+ options = this._.extractOptions(args) || {};
471
+ callback = this._.extractCallback(args);
472
+
473
+ if (typeof callback !== 'function') throw new Error("One of arguments must be a function.");
474
+ if (callback.length === 0) throw new Error("Callback requires an argument.");
475
+
476
+ builder = new MarkupBuilder(this.component, { formName: name });
477
+ callback.call(this.component, builder);
478
+ options = options || {};
479
+ options.name = name;
480
+ if (options.onsubmit === undefined && this._.eventCallbacks.onsubmit === undefined) {
481
+ options.onsubmit = function (e) {
482
+ return false;
483
+ };
484
+ }
485
+ attributes = this._.generateAttributes(options);
486
+ this._.elements.push(this._.h('form', attributes, builder._.elements));
487
+ return this;
488
+ },
489
+ fieldsFor: function (name) {
490
+ var args, options, callback, prefix, builder;
491
+
492
+ args = Array.prototype.slice.call(arguments, 1);
493
+ options = this._.extractOptions(args) || {};
494
+ callback = this._.extractCallback(args);
495
+
496
+ if (typeof callback !== 'function') throw new Error("One of arguments must be a function.");
497
+ if (callback.length === 0) throw new Error("Callback requires an argument.");
498
+
499
+ if (this.fieldNamePrefix !== undefined) prefix = this.fieldNamePrefix + '/' + name;else prefix = name;
500
+ if (options.index !== undefined) prefix = prefix + '/' + String(options.index);
501
+
502
+ builder = new MarkupBuilder(this.component, { formName: this.formName, fieldNamePrefix: prefix });
503
+ callback.call(this.component, builder);
504
+ builder._.elements.forEach(function (elem) {
505
+ this._.elements.push(elem);
506
+ }.bind(this));
507
+
508
+ return this;
509
+ },
510
+ labelFor: function (name, content, options) {
511
+ var fieldName;
512
+
513
+ options = options || {};
514
+ options.htmlFor = this._.elementIdFor(name);
515
+ this.elem('label', content, options);
516
+ return this;
517
+ },
518
+ hiddenField: function (name, options) {
519
+ options = options || {};
520
+ options.type = 'hidden';
521
+ options.name = name;
522
+ this._.inputField(options);
523
+ return this;
524
+ },
525
+ textField: function (name, options) {
526
+ options = options || {};
527
+ options.type = options.type || 'text';
528
+ options.name = name;
529
+ this._.inputField(options);
530
+ return this;
531
+ },
532
+ passwordField: function (name, options) {
533
+ options = options || {};
534
+ options.type = 'password';
535
+ options.name = name;
536
+ this._.inputField(options);
537
+ return this;
538
+ },
539
+ textareaField: function (attrName, options) {
540
+ var formName, vform, dasherized;
541
+
542
+ if (attrName && this.fieldNamePrefix) attrName = this.fieldNamePrefix + '/' + attrName;
543
+ options = options || {};
544
+ options.name = attrName;
545
+
546
+ formName = this.formName || '';
547
+ this.component.virtualForms.update(formName, options);
548
+
549
+ dasherized = Inflector.dasherize(attrName.replace(/\//g, '_'));
550
+ if (!options.id) {
551
+ if (this.formName) options.id = this.formName + '-field-' + dasherized;else options.id = 'field-' + dasherized;
552
+ }
553
+ this.elem('textarea', '', options);
554
+ return this;
555
+ },
556
+ checkBox: function (attrName, options) {
557
+ var fieldName;
558
+
559
+ options = options || {};
560
+ options.type = 'checkbox';
561
+ if (attrName) options.name = attrName;
562
+ if (!options.value) options.value = '1';
563
+
564
+ if (options.name && this.fieldNamePrefix) fieldName = this.fieldNamePrefix + '/' + options.name;else fieldName = options.name;
565
+
566
+ if (attrName.slice(-2) !== '[]') {
567
+ this._.elements.push(this._.h('input', _extends({}, { name: fieldName, type: 'hidden', value: '0' })));
568
+ }
569
+ this._.inputField(options);
570
+ return this;
571
+ },
572
+ radioButton: function (attrName, value, options) {
573
+ options = options || {};
574
+ options.type = 'radio';
575
+ options.value = value;
576
+ if (attrName) options.name = attrName;
577
+ this._.inputField(options);
578
+ return this;
579
+ },
580
+ selectBox: function (name) {
581
+ var args, options, callback, builder, attributes, dasherized, formName;
582
+
583
+ args = Array.prototype.slice.call(arguments, 1);
584
+ options = this._.extractOptions(args) || {};
585
+ callback = this._.extractCallback(args);
586
+
587
+ if (typeof callback !== 'function') throw new Error("One of arguments must be a function.");
588
+ if (callback.length === 0) throw new Error("Callback requires an argument.");
589
+
590
+ if (name && this.fieldNamePrefix) options.name = this.fieldNamePrefix + '/' + name;else options.name = name;
591
+
592
+ options.id = options.id || this._.elementIdFor(name);
593
+
594
+ builder = new MarkupBuilder(this.component, { formName: this.formName, selectBoxName: name });
595
+ callback.call(this.component, builder);
596
+ options = options || {};
597
+ attributes = this._.generateAttributes(options);
598
+
599
+ formName = this.formName || '';
600
+ this.component.virtualForms.update(formName, { name: name, value: options.value });
601
+
602
+ this._.elements.push(this._.h('select', attributes, builder._.elements));
603
+ return this;
604
+ },
605
+ btn: function () {
606
+ var args, options, content, callback;
607
+
608
+ args = Array.prototype.slice.call(arguments);
609
+ content = this._.extractContent(args);
610
+ options = this._.extractOptions(args) || {};
611
+ callback = this._.extractCallback(args);
612
+
613
+ options.type = options.type || 'button';
614
+ this.elem('button', content, options, callback);
615
+ return this;
616
+ },
617
+ attr: function (name, value) {
618
+ if (typeof name === 'object') _extends(this._.attr, name);else if (typeof name === 'string') this._.attr[name] = value;
619
+
620
+ return this;
621
+ },
622
+ class: function (name) {
623
+ if (typeof name === 'object') _extends(this._.classNames, name);else if (typeof name === 'string') this._.classNames[name] = true;
624
+ return this;
625
+ },
626
+ data: function (name, value) {
627
+ if (typeof name === 'object') _extends(this._.data, name);else if (typeof name === 'string') this._.data[name] = value;
628
+ return this;
629
+ },
630
+ css: function (name, value) {
631
+ if (typeof name === 'object') _extends(this._.style, name);else if (typeof name === 'string') this._.style[name] = value;
632
+
633
+ return this;
634
+ },
635
+ on: function (eventName, callback) {
636
+ if (typeof eventName === 'string') this._.eventCallbacks['on' + eventName] = callback;else throw new Error("The first agument must be a string.");
637
+ },
638
+ fa: function (iconName, options) {
639
+ options = options || {};
640
+ var htmlClass = options.class || options.className;
641
+ if (htmlClass) {
642
+ htmlClass = htmlClass + ' fa fa-' + iconName;
643
+ } else {
644
+ htmlClass = 'fa fa-' + iconName;
645
+ }
646
+ options.class = htmlClass;
647
+ this.i('', options);
648
+ return this;
649
+ }
650
+ });
651
+
652
+ // Internal properties of Cape.MarkupBuilder
653
+ var _Internal = function _Internal(main) {
654
+ this.main = main;
655
+ this.h = virtualDom.h;
656
+ this.elements = [];
657
+ this.classNames = {};
658
+ this.attr = {};
659
+ this.data = {};
660
+ this.style = {};
661
+ this.eventCallbacks = {};
662
+ };
663
+
664
+ // Internal methods of Cape.MarkupBuilder
665
+ _extends(_Internal.prototype, {
666
+ inputField: function (options) {
667
+ var attributes, dasherized, formName, vform;
668
+
669
+ options = options || {};
670
+
671
+ if (options.id === undefined) {
672
+ options.id = this.elementIdFor(options.name);
673
+ if (options.type === 'radio') options.id = options.id + '-' + String(options.value);
674
+ }
675
+ if (options.id === null) delete options.id;
676
+ if (options.name && this.main.fieldNamePrefix) options.name = this.main.fieldNamePrefix + '/' + options.name;
677
+
678
+ formName = this.main.formName || '';
679
+ this.main.component.virtualForms.update(formName, options);
680
+
681
+ attributes = this.generateAttributes(options);
682
+ this.elements.push(this.h('input', attributes));
683
+ return this;
684
+ },
685
+
686
+ elementIdFor: function (name) {
687
+ var dasherized;
688
+
689
+ if (this.main.fieldNamePrefix) dasherized = Inflector.dasherize(this.main.fieldNamePrefix.replace(/\//g, '-') + '-' + name);else dasherized = Inflector.dasherize(name);
690
+
691
+ if (this.main.formName) return this.main.formName + '-field-' + dasherized;else return 'field-' + dasherized;
692
+ },
693
+
694
+ extractContent: function (args) {
695
+ if (typeof args[0] === 'string') return args[0];
696
+ },
697
+
698
+ extractOptions: function (args) {
699
+ for (var i = 0; i < args.length; i++) if (typeof args[i] === 'object') return args[i];
700
+ },
701
+
702
+ extractCallback: function (args) {
703
+ for (var i = 0; i < args.length; i++) if (typeof args[i] === 'function') return args[i];
704
+ },
705
+
706
+ generateAttributes: function (options) {
707
+ var classNames, data;
708
+
709
+ options = options || {};
710
+ options = _extends({}, this.attr, options);
711
+ this.attr = {};
712
+
713
+ if ('visible' in options && !options['visible']) {
714
+ options['style'] = options['style'] || {};
715
+ options['style']['display'] = 'none';
716
+ }
717
+ if ('class' in options) {
718
+ options['className'] = options['class'];
719
+ delete options['class'];
720
+ }
721
+ if ('for' in options) {
722
+ options['htmlFor'] = options['for'];
723
+ delete options['for'];
724
+ }
725
+
726
+ classNames = [];
727
+ for (key in this.classNames) if (this.classNames.hasOwnProperty(key) && this.classNames[key]) classNames.push(key);
728
+ this.classNames = [];
729
+
730
+ if (typeof options['className'] === 'object') {
731
+ for (var name in options['className']) {
732
+ if (options['className'][name]) {
733
+ classNames.push(name);
734
+ }
735
+ }
736
+ } else if (typeof options['className'] === 'string') {
737
+ options['className'].split(' ').forEach(function (e) {
738
+ classNames.push(e);
739
+ });
740
+ }
741
+
742
+ if (classNames.length) {
743
+ classNames = classNames.filter(function (e, i, self) {
744
+ return self.indexOf(e) === i;
745
+ });
746
+ options['className'] = classNames.join(' ');
747
+ } else {
748
+ delete options['className'];
749
+ }
750
+
751
+ if ('data' in options) {
752
+ options['dataset'] = options['data'];
753
+ delete options['data'];
754
+ }
755
+ data = options.dataset || {};
756
+ data = _extends({}, this.data, data);
757
+ this.data = {};
758
+ options.dataset = data;
759
+
760
+ if (typeof options.style === 'object') options.style = _extends({}, this.style, options.style);else options.style = this.style;
761
+ this.style = {};
762
+
763
+ Cape.merge(options, this.eventCallbacks);
764
+ this.eventCallbacks = {};
765
+
766
+ for (var key in options) {
767
+ if (typeof options[key] === 'function') {
768
+ options[key] = options[key].bind(this.main.component);
769
+ }
770
+ }
771
+ return options;
772
+ }
773
+ });
774
+
775
+ var normalElementNames = ['a', 'abbr', 'address', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'blockquote', 'body', 'button', 'canvas', 'caption', 'cite', 'code', 'colgroup', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'html', 'i', 'iframe', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'menu', 'menuitem', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'u', 'ul', 'var', 'video'];
776
+
777
+ for (var i = normalElementNames.length; i--;) {
778
+ var tagName = normalElementNames[i];
779
+ MarkupBuilder.prototype[tagName] = new Function("arg1", "arg2", "this.elem('" + tagName + "', arg1, arg2); return this");
780
+ }
781
+
782
+ var voidElementNames = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'];
783
+
784
+ for (var i = voidElementNames.length; i--;) {
785
+ var tagName = voidElementNames[i];
786
+ MarkupBuilder.prototype[tagName] = new Function("options", "this.elem('" + tagName + "', options); return this");
787
+ }
788
+
789
+ var attrNames = ['checked', 'disabled'];
790
+
791
+ for (var i = attrNames.length; i--;) {
792
+ var attrName = attrNames[i];
793
+ MarkupBuilder.prototype[attrName] = new Function("value", "this.attr('" + attrName + "', value); return this");
794
+ }
795
+
796
+ var eventNames = ['blur', 'focus', 'change', 'select', 'submit', 'reset', 'abort', 'error', 'load', 'unload', 'click', 'dblclick', 'keyup', 'keydown', 'keypress', 'mouseout', 'mouseover', 'mouseup', 'mousedown', 'mousemove'];
797
+
798
+ for (var i = eventNames.length; i--;) {
799
+ var eventName = eventNames[i];
800
+ MarkupBuilder.prototype['on' + eventName] = new Function("callback", "this.on('" + eventName + "', callback); return this");
801
+ }
802
+
803
+ module.exports = MarkupBuilder;
804
+
805
+ },{"./utilities":15,"inflected":22,"virtual-dom":36}],7:[function(require,module,exports){
806
+ 'use strict';
807
+
808
+ var Inflector = require('inflected');
809
+
810
+ var AgentCommonInnerMethods = {
811
+ applyAdapter: function () {
812
+ var adapterName, adapter;
813
+
814
+ adapterName = this.main.adapter || Cape.defaultAgentAdapter;
815
+ if (typeof adapterName === 'string') {
816
+ adapter = Cape.AgentAdapters[Inflector.camelize(adapterName) + 'Adapter'];
817
+ if (typeof adapter === 'function') adapter.apply(this.main, arguments);
818
+ }
819
+ },
820
+
821
+ headers: function () {
822
+ var headers = this.main.headers;
823
+ if (this.main.dataType === undefined) {
824
+ headers['Accept'] = 'application/json, text/plain';
825
+ } else if (this.main.dataType === 'json') {
826
+ headers['Accept'] = 'application/json';
827
+ } else if (this.main.dataType === 'text') {
828
+ headers['Accept'] = 'text/plain';
829
+ } else {
830
+ throw new Error('Unsupported data type: ' + this.main.dataType);
831
+ }
832
+ return headers;
833
+ },
834
+
835
+ pathPrefix: function (shallow) {
836
+ var prefix = this.main.basePath || '/';
837
+ if (this.main.nestedIn && !shallow) prefix = prefix + this.main.nestedIn;
838
+ return prefix;
839
+ },
840
+
841
+ responseHandler: function () {
842
+ if (this.main.dataType === undefined) {
843
+ return function (response) {
844
+ return response.text();
845
+ };
846
+ } else if (this.main.dataType === 'json') {
847
+ return function (response) {
848
+ return response.json();
849
+ };
850
+ } else if (this.main.dataType === 'text') {
851
+ return function (response) {
852
+ return response.text();
853
+ };
854
+ } else {
855
+ throw new Error('Unsupported data type: ' + this.main.dataType);
856
+ }
857
+ },
858
+
859
+ dataHandler: function (data, callback) {
860
+ if (this.main.dataType === undefined) {
861
+ try {
862
+ this.main.data = JSON.parse(data);
863
+ } catch (e) {
864
+ this.main.data = data;
865
+ }
866
+ } else {
867
+ this.main.data = data;
868
+ }
869
+
870
+ if (typeof callback === 'function') {
871
+ callback.call(this.main.client, this.main.data);
872
+ }
873
+ }
874
+ };
875
+
876
+ module.exports = AgentCommonInnerMethods;
877
+
878
+ },{"inflected":22}],8:[function(require,module,exports){
879
+ 'use strict';
880
+
881
+ var Inflector = require('inflected');
882
+ var checkStatus = require('./check_status');
883
+
884
+ var AgentCommonMethods = {
885
+ ajax: function (httpMethod, path, params, callback, errorHandler) {
886
+ var self = this,
887
+ isSafeMethod,
888
+ fetchOptions;
889
+
890
+ params = params || {};
891
+ errorHandler = errorHandler || this.defaultErrorHandler;
892
+
893
+ this._.applyAdapter();
894
+
895
+ isSafeMethod = httpMethod === 'GET' || httpMethod === 'HEAD';
896
+ fetchOptions = {
897
+ method: httpMethod,
898
+ headers: this._.headers(),
899
+ credentials: 'same-origin'
900
+ };
901
+
902
+ if (isSafeMethod) {
903
+ var pairs = [];
904
+ for (var key in params) {
905
+ pairs.push(encodeURIComponent(key) + "=" + encodeURIComponent(params[key]));
906
+ }
907
+ if (pairs.length) path = path + '?' + pairs.join('&');
908
+ } else {
909
+ fetchOptions.body = JSON.stringify(params);
910
+ }
911
+
912
+ fetch(path, fetchOptions).then(checkStatus).then(this._.responseHandler()).then(function (data) {
913
+ self._.dataHandler(data, callback);
914
+ if (self.autoRefresh && !isSafeMethod) self.refresh();
915
+ }).catch(errorHandler);
916
+
917
+ return false;
918
+ }
919
+ };
920
+
921
+ module.exports = AgentCommonMethods;
922
+
923
+ },{"./check_status":9,"inflected":22}],9:[function(require,module,exports){
924
+ 'use strict';
925
+
926
+ function checkStatus(response) {
927
+ if (response.status >= 200 && response.status < 300) {
928
+ return response;
929
+ } else {
930
+ var error = new Error(response.statusText);
931
+ error.response = response;
932
+ throw error;
933
+ }
934
+ }
935
+
936
+ module.exports = checkStatus;
937
+
938
+ },{}],10:[function(require,module,exports){
939
+ 'use strict';
940
+
941
+ var PropagatorMethods = {
942
+ attach: function (component) {
943
+ var target = component;
944
+ for (var i = 0, len = this._.components.length; i < len; i++) {
945
+ if (this._.components[i] === component) return;
946
+ }
947
+ this._.components.push(component);
948
+ },
949
+
950
+ detach: function (component) {
951
+ for (var i = 0, len = this._.components.length; i < len; i++) {
952
+ if (this._.components[i] === component) {
953
+ this._.components.splice(i, 1);
954
+ break;
955
+ }
956
+ }
957
+ },
958
+
959
+ propagate: function () {
960
+ for (var i = this._.components.length; i--;) this._.components[i].refresh();
961
+ }
962
+ };
963
+
964
+ module.exports = PropagatorMethods;
965
+
966
+ },{}],11:[function(require,module,exports){
967
+ 'use strict';
968
+
969
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
970
+
971
+ var Cape = require('./utilities');
972
+
973
+ // Cape.Partial
974
+ //
975
+ // public properties:
976
+ // parent: the parent component that contains this partial component.
977
+ var Partial = function Partial(parent) {
978
+ this.parent = parent;
979
+ this.virtualForms = parent.virtualForms;
980
+ };
981
+
982
+ _extends(Partial.prototype, {
983
+ refresh: function () {
984
+ this.parent.refresh();
985
+ },
986
+
987
+ val: function (arg1, arg2) {
988
+ if (arguments.length === 1) return this.parent.val(arg1);else return this.parent.val(arg1, arg2);
989
+ },
990
+
991
+ setValues: function (formName, obj) {
992
+ this.virtualForms.setValues(formName, obj);
993
+ },
994
+
995
+ formData: function (formName) {
996
+ return this.virtualForms.formData(formName);
997
+ },
998
+
999
+ paramsFor: function (formName, options) {
1000
+ return this.virtualForms.paramsFor(formName, options);
1001
+ },
1002
+
1003
+ jsonFor: function (formName, options) {
1004
+ return this.virtualForms.jsonFor(formName, options);
1005
+ },
1006
+
1007
+ checkedOn: function (name) {
1008
+ return this.virtualForms.checkedOn(name);
1009
+ }
1010
+ });
1011
+
1012
+ module.exports = Partial;
1013
+
1014
+ },{"./utilities":15}],12:[function(require,module,exports){
1015
+ 'use strict';
1016
+
1017
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
1018
+
1019
+ var Inflector = require('inflected');
1020
+ var Cape = require('./utilities');
1021
+ var checkStatus = require('./mixins/check_status');
1022
+
1023
+ // Cape.ResourceAgent
1024
+ //
1025
+ // public properties:
1026
+ // resourceName: the name of resource
1027
+ // id: the id of the resource
1028
+ // client: the object that utilizes this agent
1029
+ // basePath: the string that is added to the request path. Default value is '/'.
1030
+ // nestedIn: the string that is inserted between path prefix and the resource
1031
+ // name. Default value is ''.
1032
+ // shallow: a boolean value that controls whether the agent should omit
1033
+ // the `nestedIn` string from the member path. Default is `false`.
1034
+ // adapter: the name of adapter (e.g., 'rails'). Default is undefined.
1035
+ // Default value can be changed by setting Cape.defaultAgentAdapter property.
1036
+ // autoRefresh: a boolean value that controls unsafe Ajax requests trigger
1037
+ // this.refresh(). Default is `false`.
1038
+ // dataType: the type of data that you're expecting from the server.
1039
+ // The value must be 'json', text' or undefined.
1040
+ // When the `dataType` option is not defined, the type is detected automatically.
1041
+ // singular: a boolean value that specifies if the resource is singular or not.
1042
+ // Resources are called 'singular' when they have a URL without ID.
1043
+ // Default is `false`.
1044
+ // formName: the name of form with which the users edit the properties
1045
+ // of the resource. Default is `undefiend`.
1046
+ // When the `formName` option is not defined, the name is derived from the
1047
+ // `resourceName` property, e.g. `user` if the resource name is `user`.
1048
+ // paramName: the name of parameter to be used when request parameter is
1049
+ // constructed. Default is `undefiend`.
1050
+ // When the `paramName` option is not defined, the name is derived from the
1051
+ // `resourceName` property, e.g. `user` if the resource name is `user`.
1052
+ // object: the object that represents the resource.
1053
+ // data: the response data from the server. This property holds an object
1054
+ // if the response data is a valid JSON string. Otherwise, it holds the
1055
+ // original string value.
1056
+ // errors: the object that holds error messages.
1057
+ // headers: the HTTP headers for Ajax requests.
1058
+ // private properties:
1059
+ // _: the object that holds internal methods and properties of this class.
1060
+ //
1061
+ // parameters for the constructor
1062
+ // client: the component object that use this agent.
1063
+ // options: an object that is used to initialize properties. The properties
1064
+ // which can be initialized by it are `resourceName`, `basePath`,
1065
+ // `nestedIn`, `adapter`, `dataType`, and `singular`.
1066
+ function ResourceAgent(client, options) {
1067
+ var adapterName, adapter;
1068
+
1069
+ options = options || {};
1070
+
1071
+ this._ = new _Internal(this);
1072
+ this.resourceName = options.resourceName;
1073
+ this.client = client;
1074
+ this.id = options.id;
1075
+ this.basePath = options.basePath;
1076
+ this.nestedIn = options.nestedIn;
1077
+ this.shallow = options.shallow || false;
1078
+ this.adapter = options.adapter;
1079
+ this.autoRefresh = options.autoRefresh || false;
1080
+ this.dataType = options.dataType;
1081
+ this.singular = options.singular || false;
1082
+ this.formName = options.formName;
1083
+ this.paramName = options.paramName;
1084
+
1085
+ this.object = undefined;
1086
+ this.data = undefined;
1087
+ this.errors = {};
1088
+ this.headers = { 'Content-Type': 'application/json' };
1089
+ };
1090
+
1091
+ _extends(ResourceAgent.prototype, {
1092
+ init: function (afterInitialize, errorHandler) {
1093
+ var self = this,
1094
+ path;
1095
+
1096
+ if (this.singular) {
1097
+ path = this.singularPath();
1098
+ } else if (this.id) {
1099
+ path = this.memberPath();
1100
+ } else {
1101
+ path = this.newPath();
1102
+ }
1103
+ errorHandler = errorHandler || this.defaultErrorHandler;
1104
+
1105
+ this._.applyAdapter();
1106
+
1107
+ fetch(path, {
1108
+ headers: this._.headers(),
1109
+ credentials: 'same-origin'
1110
+ }).then(checkStatus).then(this._.responseHandler()).then(function (data) {
1111
+ self._.initialDataHandler(data, afterInitialize);
1112
+ }).catch(errorHandler);
1113
+ },
1114
+
1115
+ refresh: function () {
1116
+ var self = this;
1117
+ this.show(function (data) {
1118
+ self.data = data;
1119
+ self.afterRefresh();
1120
+ });
1121
+ },
1122
+
1123
+ // Called by the `refresh()` method after it updates the `data` property.
1124
+ //
1125
+ // Developers may override this method to let the agent do some
1126
+ // post-processing jobs.
1127
+ afterRefresh: function () {
1128
+ this.client.refresh();
1129
+ },
1130
+
1131
+ show: function (callback, errorHandler) {
1132
+ this.ajax('GET', this.requestPath(), {}, callback, errorHandler);
1133
+ },
1134
+
1135
+ create: function (afterCreate, errorHandler) {
1136
+ var path = this.singular ? this.singularPath() : this.collectionPath();
1137
+ var params = this.client.paramsFor(this.formName || this.resourceName, { as: this.paramName || this.resourceName });
1138
+ this.ajax('POST', path, params, afterCreate, errorHandler);
1139
+ return false;
1140
+ },
1141
+
1142
+ update: function (afterUpdate, errorHandler) {
1143
+ var path = this.singular ? this.singularPath() : this.memberPath();
1144
+ var params = this.client.paramsFor(this.formName || this.resourceName, { as: this.paramName || this.resourceName });
1145
+ this.ajax('PATCH', path, params, afterUpdate, errorHandler);
1146
+ return false;
1147
+ },
1148
+
1149
+ destroy: function (afterDestroy, errorHandler) {
1150
+ var path = this.singular ? this.singularPath() : this.memberPath();
1151
+ this.ajax('DELETE', path, {}, afterDestroy, errorHandler);
1152
+ return false;
1153
+ },
1154
+
1155
+ get: function (actionName, params, callback, errorHandler) {
1156
+ var path = this.requestPath();
1157
+ if (actionName !== '') path = path + '/' + actionName;
1158
+ this.ajax('GET', path, params, callback, errorHandler);
1159
+ },
1160
+
1161
+ head: function (actionName, params, callback, errorHandler) {
1162
+ var path = this.requestPath();
1163
+ if (actionName !== '') path = path + '/' + actionName;
1164
+ this.ajax('HEAD', path, params, callback, errorHandler);
1165
+ },
1166
+
1167
+ post: function (actionName, params, callback, errorHandler) {
1168
+ var path = this.requestPath();
1169
+ if (actionName !== '') path = path + '/' + actionName;
1170
+ this.ajax('POST', path, params, callback, errorHandler);
1171
+ },
1172
+
1173
+ patch: function (actionName, params, callback, errorHandler) {
1174
+ var path = this.requestPath();
1175
+ if (actionName !== '') path = path + '/' + actionName;
1176
+ this.ajax('PATCH', path, params, callback, errorHandler);
1177
+ },
1178
+
1179
+ put: function (actionName, params, callback, errorHandler) {
1180
+ var path = this.requestPath();
1181
+ if (actionName !== '') path = path + '/' + actionName;
1182
+ this.ajax('PUT', path, params, callback, errorHandler);
1183
+ },
1184
+
1185
+ delete: function (actionName, params, callback, errorHandler) {
1186
+ var path = this.requestPath();
1187
+ if (actionName !== '') path = path + '/' + actionName;
1188
+ this.ajax('DELETE', path, params, callback, errorHandler);
1189
+ },
1190
+
1191
+ requestPath: function () {
1192
+ if (this.singular) {
1193
+ return this.singularPath();
1194
+ } else if (this.id === undefined) {
1195
+ return this.collectionPath();
1196
+ } else {
1197
+ return this.memberPath();
1198
+ }
1199
+ },
1200
+
1201
+ collectionPath: function () {
1202
+ var resources = Inflector.pluralize(Inflector.underscore(this.resourceName));
1203
+ return this._.pathPrefix() + resources;
1204
+ },
1205
+
1206
+ newPath: function () {
1207
+ var resources = Inflector.pluralize(Inflector.underscore(this.resourceName));
1208
+ return this._.pathPrefix() + resources + '/new';
1209
+ },
1210
+
1211
+ memberPath: function () {
1212
+ var resources = Inflector.pluralize(Inflector.underscore(this.resourceName));
1213
+ return this._.pathPrefix(this.shallow) + resources + '/' + this.id;
1214
+ },
1215
+
1216
+ singularPath: function () {
1217
+ var resource = Inflector.underscore(this.resourceName);
1218
+ return this._.pathPrefix() + resource;
1219
+ },
1220
+
1221
+ defaultErrorHandler: function (ex) {
1222
+ console.log(ex);
1223
+ }
1224
+ });
1225
+
1226
+ var AgentCommonMethods = require('./mixins/agent_common_methods');
1227
+ _extends(ResourceAgent.prototype, AgentCommonMethods);
1228
+
1229
+ // Internal properties of Cape.ResourceAgent
1230
+ var _Internal = function _Internal(main) {
1231
+ this.main = main;
1232
+ };
1233
+
1234
+ var AgentCommonInnerMethods = require('./mixins/agent_common_inner_methods');
1235
+
1236
+ // Internal methods of Cape.ResourceAgent
1237
+ _extends(_Internal.prototype, AgentCommonInnerMethods);
1238
+
1239
+ _extends(_Internal.prototype, {
1240
+ initialDataHandler: function (data, afterInitialize) {
1241
+ var formName = this.main.formName || this.main.resourceName,
1242
+ paramName = this.main.paramName || this.main.resourceName;
1243
+
1244
+ try {
1245
+ this.main.data = JSON.parse(data);
1246
+ this.main.object = this.main.data[paramName] || {};
1247
+ } catch (e) {
1248
+ console.log("Could not parse the response data as JSON.");
1249
+ this.main.data = data;
1250
+ }
1251
+ if (typeof afterInitialize === 'function') {
1252
+ afterInitialize.call(this.main.client, this.main);
1253
+ } else if (this.main.object) {
1254
+ this.main.client.setValues(formName, this.main.object);
1255
+ this.main.client.refresh();
1256
+ }
1257
+ }
1258
+ });
1259
+
1260
+ module.exports = ResourceAgent;
1261
+
1262
+ },{"./mixins/agent_common_inner_methods":7,"./mixins/agent_common_methods":8,"./mixins/check_status":9,"./utilities":15,"inflected":22}],13:[function(require,module,exports){
1263
+ (function (global){
1264
+ 'use strict';
1265
+
1266
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
1267
+
1268
+ var Inflector = require('inflected');
1269
+ var Cape = require('./utilities');
1270
+
1271
+ // Cape.Router
1272
+ //
1273
+ // public properties:
1274
+ // routes: array of hashes that contains routing information.
1275
+ // params: the parameters that are extracted from URL hash fragment.
1276
+ // query: the parameters that are extracted from the query part of URL hash fragment.
1277
+ // vars: an object which users can store arbitrary data to.
1278
+ // flash: an object which users can store arbitrary data to, but is erased after each
1279
+ // navigation.
1280
+ // namespace: the namespace part of URL hash fragment.
1281
+ // resource: the resource part of URL hash fragment.
1282
+ // action: the action name of current route.
1283
+ // container: the name of container of component.
1284
+ // component: the name of component.
1285
+ // private properties:
1286
+ // _: the object that holds internal methods and properties of this class.
1287
+ var Router = function Router(rootContainer) {
1288
+ this._ = new _Internal(this);
1289
+ this.rootContainer = rootContainer || window;
1290
+ this.routes = [];
1291
+ this.params = {};
1292
+ this.query = {};
1293
+ this.vars = {};
1294
+ this.flash = {};
1295
+ this.namespace = null;
1296
+ this.resource = null;
1297
+ this.action = null;
1298
+ this.container = null;
1299
+ this.component = null;
1300
+ };
1301
+
1302
+ _extends(Router.prototype, {
1303
+ draw: function (callback) {
1304
+ var mapper;
1305
+
1306
+ if (typeof callback !== 'function') throw new Error("The last argument must be a function.");
1307
+ if (callback.length === 0) throw new Error("Callback requires an argument.");
1308
+
1309
+ mapper = new global.Cape.RoutingMapper(this);
1310
+ callback(mapper);
1311
+ },
1312
+ mount: function (elementId) {
1313
+ this._.targetElementId = elementId;
1314
+ },
1315
+ start: function () {
1316
+ var self = this,
1317
+ callback;
1318
+
1319
+ if (window.addEventListener) window.addEventListener('hashchange', self._.eventListener, false);else if (window.attachEvent) window.attachEvent('onhashchange', self._.eventListener);
1320
+
1321
+ this.currentHash = window.location.href.split('#')[1] || '';
1322
+ this.navigate(this.currentHash);
1323
+ },
1324
+ stop: function () {
1325
+ var self = this;
1326
+
1327
+ if (window.removeEventListener) window.removeEventListener('hashchange', self._.eventListener, false);else if (window.detachEvent) window.detachEvent('onhashchange', self._.eventListener);
1328
+ },
1329
+ routeFor: function (hash) {
1330
+ var i, len, route;
1331
+
1332
+ for (i = 0, len = this.routes.length; i < len; i++) {
1333
+ route = this.routes[i];
1334
+ if (hash.match(route.regexp)) return route;
1335
+ }
1336
+ throw new Error("No route match. [" + hash + "]");
1337
+ },
1338
+ navigateTo: function (hash, params, options) {
1339
+ var self = this,
1340
+ promises,
1341
+ promise,
1342
+ i,
1343
+ len;
1344
+
1345
+ if (params !== undefined) {
1346
+ hash = this._.constructHash(params, hash);
1347
+ }
1348
+
1349
+ this._.currentHash = hash;
1350
+ this._.setHash(hash);
1351
+
1352
+ options = options || {};
1353
+ this.flash.notice = options.notice;
1354
+ this.flash.alert = options.alert;
1355
+
1356
+ if (this._.beforeNavigationCallbacks.length) {
1357
+ promises = [];
1358
+ promise = new Promise(function (resolve, reject) {
1359
+ resolve(hash);
1360
+ });
1361
+ promises.push(promise);
1362
+ for (i = 0, len = this._.beforeNavigationCallbacks.length; i < len; i++) {
1363
+ promise = promise.then(this._.beforeNavigationCallbacks[i]);
1364
+ promises.push(promise);
1365
+ }
1366
+ Promise.all(promises).then(function (results) {
1367
+ self._.mountComponent(results.pop());
1368
+ }, self._.errorHandler);
1369
+ } else {
1370
+ self._.mountComponent(hash);
1371
+ }
1372
+ },
1373
+ // Deprecated. Use navigateTo() instead.
1374
+ navigate: function (hash, options) {
1375
+ this.navigateTo(hash, {}, options);
1376
+ },
1377
+ redirectTo: function (hash, params, options) {
1378
+ var self = this;
1379
+
1380
+ // For backward compatibility, if the second argument has a key 'notice'
1381
+ // or 'alert' and the third argument is undefined, the second argument
1382
+ // should be treated as options.
1383
+ if (typeof params === 'object' && options === undefined) {
1384
+ if (params.hasOwnProperty('notice') || params.hasOwnProperty('alert')) {
1385
+ options = params;
1386
+ params = undefined;
1387
+ }
1388
+ }
1389
+
1390
+ if (params !== undefined) {
1391
+ hash = this._.constructHash(params, hash);
1392
+ }
1393
+
1394
+ this._.currentHash = hash;
1395
+ this._.setHash(hash);
1396
+
1397
+ options = options || {};
1398
+ this.flash.notice = options.notice;
1399
+ this.flash.alert = options.alert;
1400
+ self._.mountComponent(hash);
1401
+ },
1402
+ show: function (klass, params) {
1403
+ var prop, component;
1404
+
1405
+ this.query = {};
1406
+ if (params !== undefined) {
1407
+ for (prop in params) {
1408
+ this.query[prop] = params[prop];
1409
+ }
1410
+ }
1411
+
1412
+ component = new klass();
1413
+ component.mount(this._.targetElementId);
1414
+ this._.mountedComponentClass = klass;
1415
+ this._.mountedComponent = component;
1416
+ },
1417
+ attach: function (listener) {
1418
+ if (listener === undefined) throw new Error("Missing listener.");
1419
+ if (typeof listener.refresh !== 'function') throw new Error('The listener must have the "refresh" function.');
1420
+
1421
+ for (var i = 0, len = this._.notificationListeners.length; i < len; i++) {
1422
+ if (this._.notificationListeners[i] === listener) return;
1423
+ }
1424
+ this._.notificationListeners.push(listener);
1425
+ },
1426
+ detach: function (listener) {
1427
+ for (var i = 0, len = this._.notificationListeners.length; i < len; i++) {
1428
+ if (this._.notificationListeners[i] === listener) {
1429
+ this._.notificationListeners.splice(i, 1);
1430
+ break;
1431
+ }
1432
+ }
1433
+ },
1434
+ beforeNavigation: function (callback) {
1435
+ this._.beforeNavigationCallbacks.push(callback);
1436
+ },
1437
+ errorHandler: function (callback) {
1438
+ this._.errorHandler = callback;
1439
+ },
1440
+ notify: function () {
1441
+ var i;
1442
+
1443
+ for (i = this._.notificationListeners.length; i--;) {
1444
+ this._.notificationListeners[i].refresh();
1445
+ }
1446
+ }
1447
+ });
1448
+
1449
+ // Internal properties of Cape.Router
1450
+ var _Internal = function _Internal(main) {
1451
+ var self = this;
1452
+ this.main = main;
1453
+ this.eventListener = function () {
1454
+ var hash = window.location.href.split('#')[1] || '';
1455
+ if (hash != self.currentHash) self.main.navigate(hash);
1456
+ };
1457
+ this.beforeNavigationCallbacks = [];
1458
+ this.notificationListeners = [];
1459
+ this.currentHash = null;
1460
+ this.mountedComponent = null;
1461
+ this.targetElementId = null;
1462
+ };
1463
+
1464
+ // Internal methods of Cape.Router
1465
+ _extends(_Internal.prototype, {
1466
+ mountComponent: function (hash) {
1467
+ var route, componentClass, component;
1468
+
1469
+ if (typeof hash !== 'string') throw new Error("The first argument must be a string.");
1470
+
1471
+ route = this.main.routeFor(hash);
1472
+ this.main.namespace = route.namespace;
1473
+ this.main.resource = route.resource;
1474
+ this.main.action = route.action;
1475
+ this.main.container = route.container;
1476
+ this.main.component = route.component;
1477
+ this.setParams(route);
1478
+ this.setQuery(route);
1479
+ componentClass = this.getComponentClassFor(route);
1480
+
1481
+ if (componentClass === this.mountedComponentClass) {
1482
+ this.main.notify();
1483
+ } else {
1484
+ if (this.mountedComponent) this.mountedComponent.unmount();
1485
+ this.main.notify();
1486
+ component = new componentClass();
1487
+ component.mount(this.targetElementId);
1488
+ this.mountedComponentClass = componentClass;
1489
+ this.mountedComponent = component;
1490
+ }
1491
+
1492
+ this.main.flash = {};
1493
+ },
1494
+ constructHash: function (params, hash) {
1495
+ var pairs, prop;
1496
+
1497
+ pairs = [];
1498
+ for (prop in params) {
1499
+ pairs.push(prop + '=' + params[prop]);
1500
+ }
1501
+ if (pairs.length > 0) return hash + '?' + pairs.join('&');else return hash;
1502
+ },
1503
+ setHash: function (hash) {
1504
+ window.location.hash = hash;
1505
+ },
1506
+ setParams: function (route) {
1507
+ var md = this.currentHash.match(route.regexp);
1508
+ this.main.params = {};
1509
+ route.keys.forEach(function (key, i) {
1510
+ this.main.params[key] = md[i + 1];
1511
+ }.bind(this));
1512
+ },
1513
+ setQuery: function (route) {
1514
+ var queryString, pairs;
1515
+
1516
+ this.main.query = {};
1517
+ queryString = this.currentHash.split('?')[1];
1518
+ if (queryString === undefined) return;
1519
+ pairs = queryString.split('&');
1520
+ pairs.forEach(function (pair) {
1521
+ var parts = pair.split('=');
1522
+ this.main.query[parts[0]] = parts[1] || '';
1523
+ }.bind(this));
1524
+ },
1525
+ getComponentClassFor: function (route) {
1526
+ var fragments, obj, i, componentName;
1527
+
1528
+ fragments = [];
1529
+ if (route.container) {
1530
+ route.container.split('.').forEach(function (part) {
1531
+ fragments.push(Inflector.camelize(part));
1532
+ });
1533
+ }
1534
+
1535
+ obj = this.main.rootContainer;
1536
+ for (i = 0; obj && i < fragments.length; i++) {
1537
+ if (obj[fragments[i]]) obj = obj[fragments[i]];else obj = null;
1538
+ }
1539
+
1540
+ componentName = Inflector.camelize(route.component);
1541
+ if (obj && obj[componentName]) return obj[componentName];
1542
+
1543
+ throw new Error("Component class " + fragments.concat([componentName]).join('.') + " is not defined.");
1544
+ }
1545
+ });
1546
+
1547
+ module.exports = Router;
1548
+
1549
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
1550
+ },{"./utilities":15,"inflected":22}],14:[function(require,module,exports){
1551
+ 'use strict';
1552
+
1553
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
1554
+
1555
+ var Inflector = require('inflected');
1556
+ var Cape = require('./utilities');
1557
+
1558
+ // Cape.RoutingMapper
1559
+ function RoutingMapper(router, options) {
1560
+ this._ = new _Internal(this);
1561
+ this.router = router;
1562
+ if (options) {
1563
+ // The namespace part of URL hash
1564
+ this.namespacePath = options.namespacePath;
1565
+ this.singular = options.singular;
1566
+ this.pathPrefix = options.pathPrefix;
1567
+ this.resourcePath = options.resourcePath;
1568
+ this.classNamePrefix = options.classNamePrefix;
1569
+ this.resourceClassName = options.resourceClassName;
1570
+ }
1571
+ };
1572
+
1573
+ _extends(RoutingMapper.prototype, {
1574
+ page: function (path, className, constraints, options) {
1575
+ var route = {},
1576
+ fullClassName,
1577
+ fragments,
1578
+ resourceNames;
1579
+
1580
+ if (path === undefined) throw new Error("Missing hash pattern.");
1581
+
1582
+ if (className === undefined) {
1583
+ if (path.match(/^\w+(\/\w+)*$/)) className = path.replace('/', '.');else throw new Error("Missing class name path.");
1584
+ }
1585
+
1586
+ options = options || {};
1587
+
1588
+ if (this.pathPrefix) path = this.pathPrefix + '/' + path;
1589
+
1590
+ route.path = path;
1591
+ route.keys = this._.extractKeys(path);
1592
+ route.regexp = this._.constructRegexp(path, constraints);
1593
+
1594
+ if (this.classNamePrefix) fullClassName = this.classNamePrefix + '.' + className;else fullClassName = className;
1595
+
1596
+ fragments = fullClassName.split('.');
1597
+ route.component = fragments.pop();
1598
+ route.container = fragments.length ? fragments.join('.') : null;
1599
+
1600
+ route.namespace = this.namespacePath || null;
1601
+
1602
+ resourceNames = [];
1603
+ if (this.resourcePath) resourceNames.push(this.resourcePath);
1604
+ if (options.resource) resourceNames.push(options.resource);
1605
+ if (resourceNames.length) route.resource = resourceNames.join('/');else route.resource = null;
1606
+
1607
+ route.action = options.action || null;
1608
+
1609
+ this.router.routes.push(route);
1610
+ },
1611
+ root: function (className) {
1612
+ this.page('', className);
1613
+ },
1614
+ many: function (resourceName) {
1615
+ var options, callback, resourcePath;
1616
+
1617
+ options = this._.extractOptions(arguments);
1618
+ callback = this._.extractCallback(arguments);
1619
+ resourcePath = this._.getResourcePath(options.path || resourceName);
1620
+
1621
+ this._.addPagesForPluralResource(resourceName, resourcePath, options);
1622
+ this._.executeCallback(callback, resourceName, resourcePath, false);
1623
+ },
1624
+ one: function (resourceName) {
1625
+ var options, callback, resourcePath;
1626
+
1627
+ options = this._.extractOptions(arguments);
1628
+ callback = this._.extractCallback(arguments);
1629
+ resourcePath = this._.getResourcePath(options.path || resourceName);
1630
+
1631
+ this._.addPagesForSingularResource(resourceName, resourcePath, options);
1632
+ this._.executeCallback(callback, resourceName, resourcePath, true);
1633
+ },
1634
+ collection: function () {
1635
+ var args;
1636
+
1637
+ if (this.resourcePath === undefined || this.singular) throw new Error("The collection method must be called within a plural resource definition.");
1638
+
1639
+ args = Array.prototype.slice.call(arguments, 0);
1640
+ args.forEach(function (path) {
1641
+ this.page(this.resourcePath + '/' + path, this.resourcePath + '.' + path, {}, { action: path });
1642
+ }.bind(this));
1643
+ },
1644
+ member: function () {
1645
+ var args;
1646
+
1647
+ if (this.resourcePath === undefined || this.singular) throw new Error("The member method must be called within a plural resource definition.");
1648
+
1649
+ args = Array.prototype.slice.call(arguments, 0);
1650
+ args.forEach(function (path) {
1651
+ this.page(this.resourcePath + '/:id/' + path, this.resourcePath + '.' + path, { id: '\\d+' }, {}, { action: path });
1652
+ }.bind(this));
1653
+ },
1654
+ new: function () {
1655
+ var args;
1656
+
1657
+ if (this.resourcePath === undefined) throw new Error("The member method must be called within a resource definition.");
1658
+
1659
+ args = Array.prototype.slice.call(arguments, 0);
1660
+ args.forEach(function (path) {
1661
+ this.page(this.resourcePath + '/new/' + path, this.resourcePath + '.' + path, {}, { action: path });
1662
+ }.bind(this));
1663
+ },
1664
+ view: function () {
1665
+ var args;
1666
+
1667
+ if (this.resourcePath === undefined || !this.singular) throw new Error("The view method must be called within a singular resource definition.");
1668
+
1669
+ args = Array.prototype.slice.call(arguments, 0);
1670
+ args.forEach(function (path) {
1671
+ this.page(this.resourcePath + '/' + path, this.resourcePath + '.' + path, {}, { action: path });
1672
+ }.bind(this));
1673
+ },
1674
+ namespace: function (className) {
1675
+ var args, callback, options, namespacePath, path;
1676
+
1677
+ args = Array.prototype.slice.call(arguments, 1);
1678
+ callback = args.pop();
1679
+ options = args.pop() || {};
1680
+
1681
+ if (typeof callback !== 'function') throw new Error("The last argument must be a function.");
1682
+ if (callback.length === 0) throw new Error("Callback requires an argument.");
1683
+
1684
+ path = options.path || className;
1685
+ if (this.namespacePath) namespacePath = this.namespacePath + '/' + path;else namespacePath = path;
1686
+ if (this.pathPrefix) path = this.pathPrefix + '/' + path;
1687
+ if (this.classNamePrefix) className = this.classNamePrefix + '.' + className;
1688
+
1689
+ callback(new RoutingMapper(this.router, {
1690
+ namespacePath: namespacePath,
1691
+ pathPrefix: path,
1692
+ classNamePrefix: className
1693
+ }));
1694
+ }
1695
+ });
1696
+
1697
+ // Internal properties of Cape.Component
1698
+ var _Internal = function _Internal(main) {
1699
+ this.main = main;
1700
+ };
1701
+
1702
+ // Internal methods of Cape.Component
1703
+ _extends(_Internal.prototype, {
1704
+ extractKeys: function (path) {
1705
+ var keys = [],
1706
+ md;
1707
+
1708
+ path.split('/').forEach(function (fragment) {
1709
+ if (md = fragment.match(/^:(\w+)$/)) keys.push(md[1]);
1710
+ });
1711
+ return keys;
1712
+ },
1713
+ constructRegexp: function (path, constraints) {
1714
+ var fragments = [],
1715
+ md;
1716
+
1717
+ constraints = constraints || {};
1718
+ path.split('/').forEach(function (fragment) {
1719
+ if (md = fragment.match(/^:(\w+)$/)) {
1720
+ if (constraints[md[1]]) fragments.push('(' + constraints[md[1]] + ')');else fragments.push('([^/]+)');
1721
+ } else if (fragment.match(/^\w+$/)) {
1722
+ fragments.push(fragment);
1723
+ }
1724
+ });
1725
+ return new RegExp('^' + fragments.join('/') + '(?:\\?[\\w-]+(?:=[\\w-]*)?(?:&[\\w-]+(?:=[\\w-]*)?)*)?$');
1726
+ },
1727
+ extractOptions: function (args) {
1728
+ if (typeof args[1] === 'function') return {};else return args[1] || {};
1729
+ },
1730
+ extractCallback: function (args) {
1731
+ if (typeof args[1] === 'function') return args[1];else return args[2];
1732
+ },
1733
+ filterActions: function (actions, options) {
1734
+ var idx;
1735
+
1736
+ options = options || {};
1737
+ if (typeof options['only'] === 'string') {
1738
+ actions.length = 0;
1739
+ actions.push(options['only']);
1740
+ }
1741
+ if (Array.isArray(options['only'])) {
1742
+ actions.length = 0;
1743
+ options['only'].forEach(function (name) {
1744
+ actions.push(name);
1745
+ });
1746
+ }
1747
+ if (typeof options['except'] === 'string') {
1748
+ idx = actions.indexOf(options['except']);
1749
+ if (idx !== -1) actions.splice(idx, 1);
1750
+ }
1751
+ if (Array.isArray(options['except'])) {
1752
+ options['except'].forEach(function (name) {
1753
+ idx = actions.indexOf(name);
1754
+ if (idx !== -1) actions.splice(idx, 1);
1755
+ });
1756
+ }
1757
+ },
1758
+ getResourcePath: function (path) {
1759
+ if (this.main.resourcePath) {
1760
+ if (this.main.singular) {
1761
+ path = this.main.resourcePath + '/' + path;
1762
+ } else {
1763
+ path = this.main.resourcePath + '/:' + Inflector.singularize(this.main.resourcePath) + '_id/' + path;
1764
+ }
1765
+ }
1766
+ return path;
1767
+ },
1768
+ addPagesForPluralResource: function (resourceName, resourcePath, options) {
1769
+ var actions = ['index', 'new', 'show', 'edit'],
1770
+ pathName;
1771
+ this.filterActions(actions, options);
1772
+
1773
+ options.pathNames = options.pathNames || {};
1774
+
1775
+ if (actions.indexOf('index') != -1) this.main.page(resourcePath, resourceName + '.list', {}, { resource: resourceName, action: 'index' });
1776
+ if (actions.indexOf('new') != -1) {
1777
+ pathName = options.pathNames.new ? options.pathNames.new : 'new';
1778
+ this.main.page(resourcePath + '/' + pathName, resourceName + '.form', {}, { resource: resourceName, action: 'new' });
1779
+ }
1780
+ if (actions.indexOf('show') != -1) this.main.page(resourcePath + '/:id', resourceName + '.item', { id: '\\d+' }, { resource: resourceName, action: 'show' });
1781
+ if (actions.indexOf('edit') != -1) {
1782
+ pathName = options.pathNames.edit ? options.pathNames.edit : 'edit';
1783
+ this.main.page(resourcePath + '/:id/' + pathName, resourceName + '.form', { id: '\\d+' }, { resource: resourceName, action: 'edit' });
1784
+ }
1785
+ },
1786
+ addPagesForSingularResource: function (resourceName, resourcePath, options) {
1787
+ var actions = ['new', 'show', 'edit'],
1788
+ pathName;
1789
+ this.filterActions(actions, options);
1790
+
1791
+ options.pathNames = options.pathNames || {};
1792
+
1793
+ if (actions.indexOf('show') != -1) this.main.page(resourcePath, resourceName + '.content', {}, { resource: resourceName, action: 'show' });
1794
+ if (actions.indexOf('new') != -1) {
1795
+ pathName = options.pathNames.new ? options.pathNames.new : 'new';
1796
+ this.main.page(resourcePath + '/' + pathName, resourceName + '.form', {}, { resource: resourceName, action: 'new' });
1797
+ }
1798
+ if (actions.indexOf('edit') != -1) {
1799
+ pathName = options.pathNames.edit ? options.pathNames.edit : 'edit';
1800
+ this.main.page(resourcePath + '/' + pathName, resourceName + '.form', {}, { resource: resourceName, action: 'edit' });
1801
+ }
1802
+ },
1803
+ executeCallback: function (callback, resourceName, resourcePath, singular) {
1804
+ if (typeof callback == 'function') {
1805
+ if (callback.length === 0) throw new Error("Callback requires an argument.");
1806
+ callback(new RoutingMapper(this.main.router, {
1807
+ singular: singular,
1808
+ pathPrefix: this.main.pathPrefix,
1809
+ resourcePath: resourcePath,
1810
+ classNamePrefix: this.main.classNamePrefix,
1811
+ resourceClassName: resourceName
1812
+ }));
1813
+ }
1814
+ }
1815
+ });
1816
+
1817
+ module.exports = RoutingMapper;
1818
+
1819
+ },{"./utilities":15,"inflected":22}],15:[function(require,module,exports){
1820
+ (function (global){
1821
+ 'use strict';
1822
+
1823
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
1824
+
1825
+ var Cape = {};
1826
+
1827
+ // Merge the properties of two or more objects together into the first object.
1828
+ Cape.extend = function () {
1829
+ var i, key;
1830
+
1831
+ for (i = 1; i < arguments.length; i++) for (key in arguments[i]) if (arguments[i].hasOwnProperty(key)) arguments[0][key] = arguments[i][key];
1832
+ return arguments[0];
1833
+ };
1834
+
1835
+ // Merge the properties of two or more objects together into the first object recursively.
1836
+ Cape.deepExtend = function () {
1837
+ var i, key;
1838
+
1839
+ for (i = 1; i < arguments.length; i++) for (key in arguments[i]) if (arguments[i].hasOwnProperty(key)) {
1840
+ if (typeof arguments[0][key] === 'object' && typeof arguments[i][key] === 'object') global.Cape.deepExtend(arguments[0][key], arguments[i][key]);else arguments[0][key] = arguments[i][key];
1841
+ }
1842
+ return arguments[0];
1843
+ };
1844
+
1845
+ // Merge (but not override) the properties of two or more objects together
1846
+ // into the first object
1847
+ Cape.merge = function () {
1848
+ var i, key;
1849
+
1850
+ for (i = 1; i < arguments.length; i++) for (key in arguments[i]) if (!arguments[0].hasOwnProperty(key) && arguments[i].hasOwnProperty(key)) arguments[0][key] = arguments[i][key];
1851
+ return arguments[0];
1852
+ };
1853
+
1854
+ Cape.createComponentClass = function (methods) {
1855
+ var klass = function () {
1856
+ Cape.Component.apply(this, arguments);
1857
+ if (typeof methods.constructor === 'function') methods.constructor.apply(this, arguments);
1858
+ };
1859
+ _extends(klass.prototype, Cape.Component.prototype, methods);
1860
+ return klass;
1861
+ };
1862
+
1863
+ Cape.createPartialClass = function (methods) {
1864
+ var klass = function () {
1865
+ Cape.Partial.apply(this, arguments);
1866
+ if (typeof methods.constructor === 'function') methods.constructor.apply(this, arguments);
1867
+ };
1868
+ _extends(klass.prototype, Cape.Partial.prototype, methods);
1869
+ return klass;
1870
+ };
1871
+
1872
+ Cape.createDataStoreClass = function (methods) {
1873
+ var klass = function () {
1874
+ Cape.DataStore.apply(this, arguments);
1875
+ if (typeof methods.constructor === 'function') methods.constructor.apply(this, arguments);
1876
+ };
1877
+ _extends(klass.prototype, Cape.DataStore.prototype, methods);
1878
+ klass.create = Cape.DataStore.create;
1879
+ return klass;
1880
+ };
1881
+
1882
+ Cape.createCollectionAgentClass = function (methods) {
1883
+ var klass = function () {
1884
+ Cape.CollectionAgent.apply(this, arguments);
1885
+ if (typeof methods.constructor === 'function') methods.constructor.apply(this, arguments);
1886
+ this._.applyAdapter();
1887
+ };
1888
+ _extends(klass.prototype, Cape.CollectionAgent.prototype, methods);
1889
+ return klass;
1890
+ };
1891
+
1892
+ Cape.createResourceAgentClass = function (methods) {
1893
+ var klass = function () {
1894
+ Cape.ResourceAgent.apply(this, arguments);
1895
+ if (typeof methods.constructor === 'function') methods.constructor.apply(this, arguments);
1896
+ this._.applyAdapter();
1897
+ };
1898
+ _extends(klass.prototype, Cape.ResourceAgent.prototype, methods);
1899
+ return klass;
1900
+ };
1901
+
1902
+ module.exports = Cape;
1903
+
1904
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
1905
+ },{}],16:[function(require,module,exports){
1906
+ (function (global){
1907
+ 'use strict';
1908
+
1909
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
1910
+
1911
+ var Cape = require('./utilities');
1912
+
1913
+ // Cape.VirtualForms
1914
+ //
1915
+ // This class is to be used by an instance of Cape.Component internally.
1916
+ //
1917
+ // public properties:
1918
+ // component: the component whose forms are represented by the instance of this class.
1919
+ // items: an object that keeps virtual forms, which keep attribute names and their values
1920
+ // to be applied to the component after it gets rendered.
1921
+ // private properties:
1922
+ // _: the object that holds internal methods and properties of this class.
1923
+ var VirtualForms = function VirtualForms(component) {
1924
+ this.component = component;
1925
+ this.items = {};
1926
+ this._ = new _Internal(this);
1927
+ };
1928
+
1929
+ _extends(VirtualForms.prototype, {
1930
+ prepare: function () {
1931
+ this._.compile();
1932
+ global.Cape.deepExtend(this._.realForms, this.items);
1933
+ this._.tempForms = global.Cape.deepExtend({}, this._.realForms);
1934
+ },
1935
+
1936
+ apply: function () {
1937
+ var forms, i, len, form, formName, tForm, j, elements, elem, elemName, k;
1938
+
1939
+ forms = this.component.root.getElementsByTagName('form');
1940
+
1941
+ for (i = 0, len = forms.length; i < len; i++) {
1942
+ form = forms[i];
1943
+ formName = form.getAttribute('name') || '';
1944
+ tForm = this._.tempForms[formName] || {};
1945
+
1946
+ elements = form.getElementsByTagName('*');
1947
+ for (j = 0; j < elements.length; j++) {
1948
+ elem = elements[j];
1949
+ if (elem.value === undefined || elem.name === undefined) continue;
1950
+ if (elem.type === 'hidden') {
1951
+ if (elements[j + 1] && elements[j + 1].type === 'checkbox') continue;
1952
+ }
1953
+ elemName = elem.getAttribute('name');
1954
+
1955
+ if (elem.type === 'checkbox') {
1956
+ if (elemName.slice(-2) === '[]' && Array.isArray(tForm[elemName])) {
1957
+ elem.checked = false;
1958
+ for (k = 0; k < tForm[elemName].length; k++) {
1959
+ if (elem.value === tForm[elemName][k]) {
1960
+ elem.checked = true;
1961
+ break;
1962
+ }
1963
+ }
1964
+ } else {
1965
+ elem.checked = tForm[elemName] === true || tForm[elemName] === '1';
1966
+ }
1967
+ } else if (elem.type === 'radio') {
1968
+ elem.checked = elem.value === tForm[elemName];
1969
+ } else {
1970
+ if (elem.value !== tForm[elemName]) elem.value = tForm[elemName] ? tForm[elemName] : '';
1971
+ }
1972
+ }
1973
+ }
1974
+
1975
+ this.items = {};
1976
+ this._.compiled = false;
1977
+ },
1978
+
1979
+ update: function (formName, options) {
1980
+ var tForm;
1981
+
1982
+ tForm = this._.tempForms[formName];
1983
+ if (tForm === undefined) {
1984
+ tForm = this._.tempForms[formName] = {};
1985
+ }
1986
+ if (options.type === 'checkbox') {
1987
+ if (tForm[options.name] === undefined) tForm[options.name] = !!options.checked;
1988
+ } else if (options.type === 'radio' && options.checked) {
1989
+ if (tForm[options.name] === undefined) tForm[options.name] = options.value;
1990
+ } else {
1991
+ if (options.value) {
1992
+ if (tForm[options.name] === undefined) tForm[options.name] = options.value;
1993
+ }
1994
+ }
1995
+ },
1996
+
1997
+ val: function (arg1, arg2) {
1998
+ var key1, key2, value;
1999
+
2000
+ if (typeof arg1 === 'object') {
2001
+ for (key1 in arg1) {
2002
+ if (arg1.hasOwnProperty(key1)) {
2003
+ value = arg1[key1];
2004
+ if (typeof value === 'object') {
2005
+ for (key2 in value) {
2006
+ if (value.hasOwnProperty(key2)) {
2007
+ this._.setValue(key1 + '.' + key2, value[key2]);
2008
+ }
2009
+ }
2010
+ } else {
2011
+ this._.setValue(key1, value);
2012
+ }
2013
+ }
2014
+ }
2015
+ } else {
2016
+ if (arguments.length === 1) return this._.getValue(arg1);else return this._.setValue(arg1, arg2);
2017
+ }
2018
+ },
2019
+
2020
+ setValues: function (formName, obj) {
2021
+ var key;
2022
+
2023
+ if (typeof formName !== 'string') throw new Error("The first argument must be a string.");
2024
+
2025
+ if (typeof obj !== 'object') throw new Error("The second argument must be an object.");
2026
+
2027
+ if (!this.items[formName]) this.items[formName] = {};
2028
+ this._.setValuesOfNestedFields(formName, null, obj);
2029
+ },
2030
+
2031
+ formData: function (formName) {
2032
+ var form, data, name, segments, lastSegment, obj;
2033
+
2034
+ this._.compile();
2035
+ if (formName === undefined) formName = '';
2036
+ form = this._.realForms[formName] || {};
2037
+
2038
+ data = {};
2039
+
2040
+ for (name in form) {
2041
+ segments = name.split('/');
2042
+ lastSegment = segments.pop();
2043
+ obj = data;
2044
+ segments.forEach(function (segment) {
2045
+ if (!obj[segment]) obj[segment] = {};
2046
+ obj = obj[segment];
2047
+ });
2048
+ if (lastSegment.slice(-2) === '[]') {
2049
+ lastSegment = lastSegment.slice(0, -2);
2050
+ }
2051
+ obj[lastSegment] = form[name];
2052
+ }
2053
+
2054
+ return data;
2055
+ },
2056
+
2057
+ paramsFor: function (formName, options) {
2058
+ var paramName, params;
2059
+
2060
+ options = options || {};
2061
+ paramName = options.as || formName;
2062
+ params = {};
2063
+ params[paramName] = this.formData(formName);
2064
+ return params;
2065
+ },
2066
+
2067
+ jsonFor: function (formName, options) {
2068
+ var paramName, obj, params;
2069
+
2070
+ options = options || {};
2071
+ paramName = options.as || formName;
2072
+
2073
+ obj = this.formData(formName);
2074
+ obj = this._.object2array(obj);
2075
+
2076
+ params = {};
2077
+ params[paramName] = obj;
2078
+ return JSON.stringify(params);
2079
+ },
2080
+
2081
+ checkedOn: function (name) {
2082
+ var names, formName, attrName, forms, elements, cb, value;
2083
+
2084
+ names = this._.getNames(name);
2085
+ formName = names[0];
2086
+ attrName = names[1];
2087
+
2088
+ forms = this.component.root.getElementsByTagName('form');
2089
+
2090
+ for (var i = 0; i < forms.length; i++) {
2091
+ elements = forms[i].getElementsByTagName('input');
2092
+ for (var j = 0; j < elements.length; j++) {
2093
+ if (elements[j].name === attrName && elements[j].type === 'checkbox') {
2094
+ cb = elements[j];
2095
+ }
2096
+ }
2097
+ }
2098
+
2099
+ if (cb === undefined) return undefined;
2100
+
2101
+ value = this._.getValue(name);
2102
+
2103
+ return value === '1' || value === true;
2104
+ }
2105
+ });
2106
+
2107
+ // Internal properties of Cape.VirtualForms
2108
+ var _Internal = function _Internal(main) {
2109
+ this.main = main;
2110
+ this.realForms = {};
2111
+ this.tempForms = {};
2112
+ this.compiled = false;
2113
+ };
2114
+
2115
+ // Internal methods of Cape.VirtualForms
2116
+ _extends(_Internal.prototype, {
2117
+ getValue: function (name) {
2118
+ var names, formName, attrName, form, _form;
2119
+
2120
+ names = this.getNames(name);
2121
+ formName = names[0];
2122
+ attrName = names[1];
2123
+
2124
+ if (formName in this.main.items) {
2125
+ if (attrName in this.main.items[formName]) {
2126
+ return this.main.items[formName][attrName];
2127
+ }
2128
+ }
2129
+ if (!this.compiled) this.compile();
2130
+
2131
+ if (formName in this.realForms) {
2132
+ if (attrName in this.realForms[formName]) {
2133
+ return this.realForms[formName][attrName];
2134
+ }
2135
+ }
2136
+ return '';
2137
+ },
2138
+
2139
+ setValue: function (name, value) {
2140
+ var names, formName, attrName, origValue;
2141
+
2142
+ names = this.getNames(name);
2143
+ formName = names[0];
2144
+ attrName = names[1];
2145
+ origValue = this.getValue(name);
2146
+
2147
+ if (!this.main.items[formName]) this.main.items[formName] = {};
2148
+ this.main.items[formName][attrName] = value;
2149
+
2150
+ return origValue;
2151
+ },
2152
+
2153
+ setValuesOfNestedFields: function (formName, prefix, obj) {
2154
+ var attrName, key, self;
2155
+
2156
+ for (key in obj) {
2157
+ attrName = prefix ? prefix + '/' + key : key;
2158
+ if (key.slice(-2) === '[]') {
2159
+ if (Array.isArray(obj[key])) {
2160
+ this.main.items[formName][attrName] = obj[key];
2161
+ }
2162
+ } else {
2163
+ if (Array.isArray(obj[key])) {
2164
+ self = this;
2165
+ obj[key].forEach(function (element, index) {
2166
+ self.setValuesOfNestedFields(formName, attrName + '/' + index, element);
2167
+ });
2168
+ } else if (typeof obj[key] === 'object') {
2169
+ this.setValuesOfNestedFields(formName, attrName, obj[key]);
2170
+ } else {
2171
+ this.main.items[formName][attrName] = obj[key];
2172
+ }
2173
+ }
2174
+ }
2175
+ },
2176
+
2177
+ compile: function () {
2178
+ var forms, elements, i, j, elem, segments, lastSegment, obj, o, name;
2179
+
2180
+ this.realForms = {};
2181
+ forms = this.main.component.root.getElementsByTagName('form');
2182
+ for (i = 0; i < forms.length; i++) {
2183
+ elements = forms[i].getElementsByTagName('*');
2184
+ obj = {};
2185
+ for (j = 0; j < elements.length; j++) {
2186
+ elem = elements[j];
2187
+ if (elem.name && elem.value !== undefined && !elem.disabled) {
2188
+ if (elem.type === 'checkbox') {
2189
+ if (elem.name.slice(-2) === '[]') {
2190
+ if (!Array.isArray(obj[elem.name])) obj[elem.name] = [];
2191
+ if (elem.checked) obj[elem.name].push(elem.value);
2192
+ } else {
2193
+ if (elem.checked) obj[elem.name] = elem.value;
2194
+ }
2195
+ } else if (elem.type === 'radio') {
2196
+ if (elem.checked) obj[elem.name] = elem.value;
2197
+ } else {
2198
+ obj[elem.name] = elem.value;
2199
+ }
2200
+ }
2201
+ }
2202
+ if (forms[i].getAttribute('name')) {
2203
+ this.realForms[forms[i].getAttribute('name')] = obj;
2204
+ } else {
2205
+ this.realForms[''] = obj;
2206
+ }
2207
+ }
2208
+ this.compiled = true;
2209
+ },
2210
+
2211
+ getNames: function (name) {
2212
+ if (typeof name === 'string' && name.indexOf('.') >= 0) {
2213
+ return name.split('.', 2);
2214
+ } else {
2215
+ return ['', name];
2216
+ }
2217
+ },
2218
+
2219
+ object2array: function (obj) {
2220
+ var isArray = true,
2221
+ _obj,
2222
+ key,
2223
+ ary = [];
2224
+
2225
+ _obj = Cape.deepExtend({}, obj);
2226
+ for (key in _obj) {
2227
+ if (key.length === 0 || key.match(/\D/)) {
2228
+ isArray = false;
2229
+ if (typeof obj[key] === 'object') obj[key] = this.object2array(_obj[key]);
2230
+ } else {
2231
+ if (typeof obj[key] === 'object') ary.push(this.object2array(_obj[key]));else ary.push(obj[key]);
2232
+ }
2233
+ }
2234
+
2235
+ if (isArray) return ary;else return obj;
2236
+ }
2237
+ });
2238
+
2239
+ module.exports = VirtualForms;
2240
+
2241
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
2242
+ },{"./utilities":15}],17:[function(require,module,exports){
2243
+ /*!
2244
+ * Cross-Browser Split 1.1.1
2245
+ * Copyright 2007-2012 Steven Levithan <stevenlevithan.com>
2246
+ * Available under the MIT License
2247
+ * ECMAScript compliant, uniform cross-browser split method
2248
+ */
2249
+
2250
+ /**
2251
+ * Splits a string into an array of strings using a regex or string separator. Matches of the
2252
+ * separator are not included in the result array. However, if `separator` is a regex that contains
2253
+ * capturing groups, backreferences are spliced into the result each time `separator` is matched.
2254
+ * Fixes browser bugs compared to the native `String.prototype.split` and can be used reliably
2255
+ * cross-browser.
2256
+ * @param {String} str String to split.
2257
+ * @param {RegExp|String} separator Regex or string to use for separating the string.
2258
+ * @param {Number} [limit] Maximum number of items to include in the result array.
2259
+ * @returns {Array} Array of substrings.
2260
+ * @example
2261
+ *
2262
+ * // Basic use
2263
+ * split('a b c d', ' ');
2264
+ * // -> ['a', 'b', 'c', 'd']
2265
+ *
2266
+ * // With limit
2267
+ * split('a b c d', ' ', 2);
2268
+ * // -> ['a', 'b']
2269
+ *
2270
+ * // Backreferences in result array
2271
+ * split('..word1 word2..', /([a-z]+)(\d+)/i);
2272
+ * // -> ['..', 'word', '1', ' ', 'word', '2', '..']
2273
+ */
2274
+ module.exports = (function split(undef) {
2275
+
2276
+ var nativeSplit = String.prototype.split,
2277
+ compliantExecNpcg = /()??/.exec("")[1] === undef,
2278
+ // NPCG: nonparticipating capturing group
2279
+ self;
2280
+
2281
+ self = function(str, separator, limit) {
2282
+ // If `separator` is not a regex, use `nativeSplit`
2283
+ if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
2284
+ return nativeSplit.call(str, separator, limit);
2285
+ }
2286
+ var output = [],
2287
+ flags = (separator.ignoreCase ? "i" : "") + (separator.multiline ? "m" : "") + (separator.extended ? "x" : "") + // Proposed for ES6
2288
+ (separator.sticky ? "y" : ""),
2289
+ // Firefox 3+
2290
+ lastLastIndex = 0,
2291
+ // Make `global` and avoid `lastIndex` issues by working with a copy
2292
+ separator = new RegExp(separator.source, flags + "g"),
2293
+ separator2, match, lastIndex, lastLength;
2294
+ str += ""; // Type-convert
2295
+ if (!compliantExecNpcg) {
2296
+ // Doesn't need flags gy, but they don't hurt
2297
+ separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
2298
+ }
2299
+ /* Values for `limit`, per the spec:
2300
+ * If undefined: 4294967295 // Math.pow(2, 32) - 1
2301
+ * If 0, Infinity, or NaN: 0
2302
+ * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
2303
+ * If negative number: 4294967296 - Math.floor(Math.abs(limit))
2304
+ * If other: Type-convert, then use the above rules
2305
+ */
2306
+ limit = limit === undef ? -1 >>> 0 : // Math.pow(2, 32) - 1
2307
+ limit >>> 0; // ToUint32(limit)
2308
+ while (match = separator.exec(str)) {
2309
+ // `separator.lastIndex` is not reliable cross-browser
2310
+ lastIndex = match.index + match[0].length;
2311
+ if (lastIndex > lastLastIndex) {
2312
+ output.push(str.slice(lastLastIndex, match.index));
2313
+ // Fix browsers whose `exec` methods don't consistently return `undefined` for
2314
+ // nonparticipating capturing groups
2315
+ if (!compliantExecNpcg && match.length > 1) {
2316
+ match[0].replace(separator2, function() {
2317
+ for (var i = 1; i < arguments.length - 2; i++) {
2318
+ if (arguments[i] === undef) {
2319
+ match[i] = undef;
2320
+ }
2321
+ }
2322
+ });
2323
+ }
2324
+ if (match.length > 1 && match.index < str.length) {
2325
+ Array.prototype.push.apply(output, match.slice(1));
2326
+ }
2327
+ lastLength = match[0].length;
2328
+ lastLastIndex = lastIndex;
2329
+ if (output.length >= limit) {
2330
+ break;
2331
+ }
2332
+ }
2333
+ if (separator.lastIndex === match.index) {
2334
+ separator.lastIndex++; // Avoid an infinite loop
2335
+ }
2336
+ }
2337
+ if (lastLastIndex === str.length) {
2338
+ if (lastLength || !separator.test("")) {
2339
+ output.push("");
2340
+ }
2341
+ } else {
2342
+ output.push(str.slice(lastLastIndex));
2343
+ }
2344
+ return output.length > limit ? output.slice(0, limit) : output;
2345
+ };
2346
+
2347
+ return self;
2348
+ })();
2349
+
2350
+ },{}],18:[function(require,module,exports){
2351
+ 'use strict';
2352
+
2353
+ var OneVersionConstraint = require('individual/one-version');
2354
+
2355
+ var MY_VERSION = '7';
2356
+ OneVersionConstraint('ev-store', MY_VERSION);
2357
+
2358
+ var hashKey = '__EV_STORE_KEY@' + MY_VERSION;
2359
+
2360
+ module.exports = EvStore;
2361
+
2362
+ function EvStore(elem) {
2363
+ var hash = elem[hashKey];
2364
+
2365
+ if (!hash) {
2366
+ hash = elem[hashKey] = {};
2367
+ }
2368
+
2369
+ return hash;
2370
+ }
2371
+
2372
+ },{"individual/one-version":21}],19:[function(require,module,exports){
2373
+ (function (global){
2374
+ var topLevel = typeof global !== 'undefined' ? global :
2375
+ typeof window !== 'undefined' ? window : {}
2376
+ var minDoc = require('min-document');
2377
+
2378
+ if (typeof document !== 'undefined') {
2379
+ module.exports = document;
2380
+ } else {
2381
+ var doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'];
2382
+
2383
+ if (!doccy) {
2384
+ doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'] = minDoc;
2385
+ }
2386
+
2387
+ module.exports = doccy;
2388
+ }
2389
+
2390
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
2391
+ },{"min-document":61}],20:[function(require,module,exports){
2392
+ (function (global){
2393
+ 'use strict';
2394
+
2395
+ /*global window, global*/
2396
+
2397
+ var root = typeof window !== 'undefined' ?
2398
+ window : typeof global !== 'undefined' ?
2399
+ global : {};
2400
+
2401
+ module.exports = Individual;
2402
+
2403
+ function Individual(key, value) {
2404
+ if (key in root) {
2405
+ return root[key];
2406
+ }
2407
+
2408
+ root[key] = value;
2409
+
2410
+ return value;
2411
+ }
2412
+
2413
+ }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
2414
+ },{}],21:[function(require,module,exports){
2415
+ 'use strict';
2416
+
2417
+ var Individual = require('./index.js');
2418
+
2419
+ module.exports = OneVersion;
2420
+
2421
+ function OneVersion(moduleName, version, defaultValue) {
2422
+ var key = '__INDIVIDUAL_ONE_VERSION_' + moduleName;
2423
+ var enforceKey = key + '_ENFORCE_SINGLETON';
2424
+
2425
+ var versionValue = Individual(enforceKey, version);
2426
+
2427
+ if (versionValue !== version) {
2428
+ throw new Error('Can only have one copy of ' +
2429
+ moduleName + '.\n' +
2430
+ 'You already have version ' + versionValue +
2431
+ ' installed.\n' +
2432
+ 'This means you cannot install version ' + version);
2433
+ }
2434
+
2435
+ return Individual(key, defaultValue);
2436
+ }
2437
+
2438
+ },{"./index.js":20}],22:[function(require,module,exports){
2439
+ "use strict";
2440
+
2441
+ module.exports = require('./lib/Inflector');
2442
+
2443
+ },{"./lib/Inflector":24}],23:[function(require,module,exports){
2444
+ (function (process,global){
2445
+ 'use strict';
2446
+
2447
+ var hasProp = require('./hasProp');
2448
+ var remove = require('./remove');
2449
+ var icPart = require('./icPart');
2450
+
2451
+ function Inflections() {
2452
+ this.plurals = [];
2453
+ this.singulars = [];
2454
+ this.uncountables = [];
2455
+ this.humans = [];
2456
+ this.acronyms = {};
2457
+ this.acronymRegex = /(?=a)b/;
2458
+ }
2459
+
2460
+ Inflections.getInstance = function(locale) {
2461
+ var storage = typeof process !== 'undefined' ? process : global;
2462
+ storage.__Inflector_Inflections = storage.__Inflector_Inflections || {};
2463
+ storage.__Inflector_Inflections[locale] = storage.__Inflector_Inflections[locale] || new Inflections();
2464
+
2465
+ return storage.__Inflector_Inflections[locale];
2466
+ };
2467
+
2468
+ Inflections.prototype.acronym = function(word) {
2469
+ this.acronyms[word.toLowerCase()] = word;
2470
+
2471
+ var values = [];
2472
+
2473
+ for (var key in this.acronyms) {
2474
+ if (hasProp(this.acronyms, key)) {
2475
+ values.push(this.acronyms[key]);
2476
+ }
2477
+ }
2478
+
2479
+ this.acronymRegex = new RegExp(values.join('|'));
2480
+ };
2481
+
2482
+ Inflections.prototype.plural = function(rule, replacement) {
2483
+ if (typeof rule === 'string') {
2484
+ remove(this.uncountables, rule);
2485
+ }
2486
+
2487
+ remove(this.uncountables, replacement);
2488
+ this.plurals.unshift([rule, replacement]);
2489
+ };
2490
+
2491
+ Inflections.prototype.singular = function(rule, replacement) {
2492
+ if (typeof rule === 'string') {
2493
+ remove(this.uncountables, rule);
2494
+ }
2495
+
2496
+ remove(this.uncountables, replacement);
2497
+ this.singulars.unshift([rule, replacement]);
2498
+ };
2499
+
2500
+ Inflections.prototype.irregular = function(singular, plural) {
2501
+ remove(this.uncountables, singular);
2502
+ remove(this.uncountables, plural);
2503
+
2504
+ var s0 = singular[0];
2505
+ var sRest = singular.substr(1);
2506
+
2507
+ var p0 = plural[0];
2508
+ var pRest = plural.substr(1);
2509
+
2510
+ if (s0.toUpperCase() === p0.toUpperCase()) {
2511
+ this.plural(new RegExp('(' + s0 + ')' + sRest + '$', 'i'), '$1' + pRest);
2512
+ this.plural(new RegExp('(' + p0 + ')' + pRest + '$', 'i'), '$1' + pRest);
2513
+
2514
+ this.singular(new RegExp('(' + s0 + ')' + sRest + '$', 'i'), '$1' + sRest);
2515
+ this.singular(new RegExp('(' + p0 + ')' + pRest + '$', 'i'), '$1' + sRest);
2516
+ } else {
2517
+ var sRestIC = icPart(sRest);
2518
+ var pRestIC = icPart(pRest);
2519
+
2520
+ this.plural(new RegExp(s0.toUpperCase() + sRestIC + '$'), p0.toUpperCase() + pRest);
2521
+ this.plural(new RegExp(s0.toLowerCase() + sRestIC + '$'), p0.toLowerCase() + pRest);
2522
+ this.plural(new RegExp(p0.toUpperCase() + pRestIC + '$'), p0.toUpperCase() + pRest);
2523
+ this.plural(new RegExp(p0.toLowerCase() + pRestIC + '$'), p0.toLowerCase() + pRest);
2524
+
2525
+ this.singular(new RegExp(s0.toUpperCase() + sRestIC + '$'), s0.toUpperCase() + sRest);
2526
+ this.singular(new RegExp(s0.toLowerCase() + sRestIC + '$'), s0.toLowerCase() + sRest);
2527
+ this.singular(new RegExp(p0.toUpperCase() + pRestIC + '$'), s0.toUpperCase() + sRest);
2528
+ this.singular(new RegExp(p0.toLowerCase() + pRestIC + '$'), s0.toLowerCase() + sRest);
2529
+ }
2530
+ };
2531
+
2532
+ Inflections.prototype.uncountable = function() {
2533
+ var words = Array.prototype.slice.call(arguments, 0);
2534
+ this.uncountables = this.uncountables.concat(words);
2535
+ };
2536
+
2537
+ Inflections.prototype.human = function(rule, replacement) {
2538
+ this.humans.unshift([rule, replacement]);
2539
+ };
2540
+
2541
+ Inflections.prototype.clear = function(scope) {
2542
+ scope = scope || 'all';
2543
+
2544
+ if (scope === 'all') {
2545
+ this.plurals = [];
2546
+ this.singulars = [];
2547
+ this.uncountables = [];
2548
+ this.humans = [];
2549
+ } else {
2550
+ this[scope] = [];
2551
+ }
2552
+ };
2553
+
2554
+ module.exports = Inflections;
2555
+
2556
+ }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
2557
+ },{"./hasProp":28,"./icPart":29,"./remove":31,"_process":62}],24:[function(require,module,exports){
2558
+ 'use strict';
2559
+
2560
+ var Inflections = require('./Inflections');
2561
+ var Transliterator = require('./Transliterator');
2562
+ var Methods = require('./Methods');
2563
+ var defaults = require('./defaults');
2564
+ var isFunc = require('./isFunc');
2565
+
2566
+ var Inflector = Methods;
2567
+
2568
+ Inflector.inflections = function(locale, fn) {
2569
+ if (isFunc(locale)) {
2570
+ fn = locale;
2571
+ locale = null;
2572
+ }
2573
+
2574
+ locale = locale || 'en';
2575
+
2576
+ if (fn) {
2577
+ fn(Inflections.getInstance(locale));
2578
+ } else {
2579
+ return Inflections.getInstance(locale);
2580
+ }
2581
+ };
2582
+
2583
+ Inflector.transliterations = function(locale, fn) {
2584
+ if (isFunc(locale)) {
2585
+ fn = locale;
2586
+ locale = null;
2587
+ }
2588
+
2589
+ locale = locale || 'en';
2590
+
2591
+ if (fn) {
2592
+ fn(Transliterator.getInstance(locale));
2593
+ } else {
2594
+ return Transliterator.getInstance(locale);
2595
+ }
2596
+ }
2597
+
2598
+ for (var locale in defaults) {
2599
+ Inflector.inflections(locale, defaults[locale]);
2600
+ }
2601
+
2602
+ module.exports = Inflector;
2603
+
2604
+ },{"./Inflections":23,"./Methods":25,"./Transliterator":26,"./defaults":27,"./isFunc":30}],25:[function(require,module,exports){
2605
+ 'use strict';
2606
+
2607
+ var Methods = {
2608
+ pluralize: function(word, locale) {
2609
+ locale = locale || 'en';
2610
+
2611
+ return this._applyInflections(word, this.inflections(locale).plurals);
2612
+ },
2613
+
2614
+ singularize: function(word, locale) {
2615
+ locale = locale || 'en';
2616
+
2617
+ return this._applyInflections(word, this.inflections(locale).singulars);
2618
+ },
2619
+
2620
+ camelize: function(term, uppercaseFirstLetter) {
2621
+ if (uppercaseFirstLetter === null || uppercaseFirstLetter === undefined) {
2622
+ uppercaseFirstLetter = true;
2623
+ }
2624
+
2625
+ var result = '' + term, self = this;
2626
+
2627
+ if (uppercaseFirstLetter) {
2628
+ result = result.replace(/^[a-z\d]*/, function(a) {
2629
+ return self.inflections().acronyms[a] || self.capitalize(a);
2630
+ });
2631
+ } else {
2632
+ result = result.replace(new RegExp('^(?:' + this.inflections().acronymRegex.source + '(?=\\b|[A-Z_])|\\w)'), function(a) {
2633
+ return a.toLowerCase();
2634
+ });
2635
+ }
2636
+
2637
+ result = result.replace(/(?:_|(\/))([a-z\d]*)/gi, function(match, a, b, idx, string) {
2638
+ a || (a = '');
2639
+ return '' + a + (self.inflections().acronyms[b] || self.capitalize(b));
2640
+ });
2641
+
2642
+ return result;
2643
+ },
2644
+
2645
+ underscore: function(camelCasedWord) {
2646
+ var result = '' + camelCasedWord;
2647
+
2648
+ result = result.replace(new RegExp('(?:([A-Za-z\\d])|^)(' + this.inflections().acronymRegex.source + ')(?=\\b|[^a-z])', 'g'), function(match, $1, $2) {
2649
+ return '' + ($1 || '') + ($1 ? '_' : '') + $2.toLowerCase();
2650
+ });
2651
+
2652
+ result = result.replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1_$2');
2653
+ result = result.replace(/([a-z\d])([A-Z])/g, '$1_$2');
2654
+ result = result.replace(/-/g, '_');
2655
+
2656
+ return result.toLowerCase();
2657
+ },
2658
+
2659
+ humanize: function(lowerCaseAndUnderscoredWord, options) {
2660
+ var result = '' + lowerCaseAndUnderscoredWord;
2661
+ var humans = this.inflections().humans;
2662
+ var human, rule, replacement;
2663
+ var self = this;
2664
+
2665
+ options = options || {};
2666
+
2667
+ if (options.capitalize === null || options.capitalize === undefined) {
2668
+ options.capitalize = true;
2669
+ }
2670
+
2671
+ for (var i = 0, ii = humans.length; i < ii; i++) {
2672
+ human = humans[i];
2673
+ rule = human[0];
2674
+ replacement = human[1];
2675
+
2676
+ if (rule.test && rule.test(result) || result.indexOf(rule) > -1) {
2677
+ result = result.replace(rule, replacement);
2678
+ break;
2679
+ }
2680
+ }
2681
+
2682
+ result = result.replace(/_id$/, '');
2683
+ result = result.replace(/_/g, ' ');
2684
+
2685
+ result = result.replace(/([a-z\d]*)/gi, function(match) {
2686
+ return self.inflections().acronyms[match] || match.toLowerCase();
2687
+ });
2688
+
2689
+ if (options.capitalize) {
2690
+ result = result.replace(/^\w/, function(match) {
2691
+ return match.toUpperCase();
2692
+ });
2693
+ }
2694
+
2695
+ return result;
2696
+ },
2697
+
2698
+ capitalize: function(str) {
2699
+ var result = str === null || str === undefined ? '' : String(str);
2700
+ return result.charAt(0).toUpperCase() + result.slice(1);
2701
+ },
2702
+
2703
+ titleize: function(word) {
2704
+ return this.humanize(this.underscore(word)).replace(/(^|[\s¿\/]+)([a-z])/g, function(match, boundary, letter, idx, string) {
2705
+ return match.replace(letter, letter.toUpperCase());
2706
+ });
2707
+ },
2708
+
2709
+ tableize: function(className) {
2710
+ return this.pluralize(this.underscore(className));
2711
+ },
2712
+
2713
+ classify: function(tableName) {
2714
+ return this.camelize(this.singularize(tableName.replace(/.*\./g, '')));
2715
+ },
2716
+
2717
+ dasherize: function(underscoredWord) {
2718
+ return underscoredWord.replace(/_/g, '-');
2719
+ },
2720
+
2721
+ foreignKey: function(className, separateWithUnderscore) {
2722
+ if (separateWithUnderscore === null || separateWithUnderscore === undefined) {
2723
+ separateWithUnderscore = true;
2724
+ }
2725
+
2726
+ return this.underscore(className) + (separateWithUnderscore ? '_id' : 'id');
2727
+ },
2728
+
2729
+ ordinal: function(number) {
2730
+ var absNumber = Math.abs(Number(number));
2731
+ var mod100 = absNumber % 100;
2732
+
2733
+ if (mod100 === 11 || mod100 === 12 || mod100 === 13) {
2734
+ return 'th';
2735
+ } else {
2736
+ switch (absNumber % 10) {
2737
+ case 1: return 'st';
2738
+ case 2: return 'nd';
2739
+ case 3: return 'rd';
2740
+ default: return 'th';
2741
+ }
2742
+ }
2743
+ },
2744
+
2745
+ ordinalize: function(number) {
2746
+ return '' + number + this.ordinal(number);
2747
+ },
2748
+
2749
+ transliterate: function(string, options) {
2750
+ options = options || {};
2751
+
2752
+ var locale = options.locale || 'en';
2753
+ var replacement = options.replacement || '?';
2754
+
2755
+ return this.transliterations(locale).transliterate(string, replacement);
2756
+ },
2757
+
2758
+ parameterize: function(string, options) {
2759
+ options = options || {};
2760
+
2761
+ if (options.separator === undefined) {
2762
+ options.separator = '-';
2763
+ }
2764
+
2765
+ if (options.separator === null) {
2766
+ options.separator = '';
2767
+ }
2768
+
2769
+ // replace accented chars with their ascii equivalents
2770
+ var result = this.transliterate(string, options);
2771
+
2772
+ result = result.replace(/[^a-z0-9\-_]+/ig, options.separator);
2773
+
2774
+ if (options.separator.length) {
2775
+ var separatorRegex = new RegExp(options.separator);
2776
+
2777
+ // no more than one of the separator in a row
2778
+ result = result.replace(new RegExp(separatorRegex.source + '{2,}'), options.separator);
2779
+
2780
+ // remove leading/trailing separator
2781
+ result = result.replace(new RegExp('^' + separatorRegex.source + '|' + separatorRegex.source + '$', 'i'), '');
2782
+ }
2783
+
2784
+ return result.toLowerCase();
2785
+ },
2786
+
2787
+ _applyInflections: function(word, rules) {
2788
+ var result = '' + word, rule, regex, replacement;
2789
+
2790
+ if (result.length === 0) {
2791
+ return result;
2792
+ } else {
2793
+ var match = result.toLowerCase().match(/\b\w+$/);
2794
+
2795
+ if (match && this.inflections().uncountables.indexOf(match[0]) > -1) {
2796
+ return result;
2797
+ } else {
2798
+ for (var i = 0, ii = rules.length; i < ii; i++) {
2799
+ rule = rules[i];
2800
+
2801
+ regex = rule[0];
2802
+ replacement = rule[1];
2803
+
2804
+ if (result.match(regex)) {
2805
+ result = result.replace(regex, replacement);
2806
+ break;
2807
+ }
2808
+ }
2809
+
2810
+ return result;
2811
+ }
2812
+ }
2813
+ }
2814
+ };
2815
+
2816
+ module.exports = Methods;
2817
+
2818
+ },{}],26:[function(require,module,exports){
2819
+ (function (process,global){
2820
+ 'use strict';
2821
+
2822
+ var DEFAULT_APPROXIMATIONS = {
2823
+ 'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE',
2824
+ 'Ç': 'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I',
2825
+ 'Î': 'I', 'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O',
2826
+ 'Õ': 'O', 'Ö': 'O', '×': 'x', 'Ø': 'O', 'Ù': 'U', 'Ú': 'U', 'Û': 'U',
2827
+ 'Ü': 'U', 'Ý': 'Y', 'Þ': 'Th', 'ß': 'ss', 'à': 'a', 'á': 'a', 'â': 'a',
2828
+ 'ã': 'a', 'ä': 'a', 'å': 'a', 'æ': 'ae', 'ç': 'c', 'è': 'e', 'é': 'e',
2829
+ 'ê': 'e', 'ë': 'e', 'ì': 'i', 'í': 'i', 'î': 'i', 'ï': 'i', 'ð': 'd',
2830
+ 'ñ': 'n', 'ò': 'o', 'ó': 'o', 'ô': 'o', 'õ': 'o', 'ö': 'o', 'ø': 'o',
2831
+ 'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y',
2832
+ 'Ā': 'A', 'ā': 'a', 'Ă': 'A', 'ă': 'a', 'Ą': 'A', 'ą': 'a', 'Ć': 'C',
2833
+ 'ć': 'c', 'Ĉ': 'C', 'ĉ': 'c', 'Ċ': 'C', 'ċ': 'c', 'Č': 'C', 'č': 'c',
2834
+ 'Ď': 'D', 'ď': 'd', 'Đ': 'D', 'đ': 'd', 'Ē': 'E', 'ē': 'e', 'Ĕ': 'E',
2835
+ 'ĕ': 'e', 'Ė': 'E', 'ė': 'e', 'Ę': 'E', 'ę': 'e', 'Ě': 'E', 'ě': 'e',
2836
+ 'Ĝ': 'G', 'ĝ': 'g', 'Ğ': 'G', 'ğ': 'g', 'Ġ': 'G', 'ġ': 'g', 'Ģ': 'G',
2837
+ 'ģ': 'g', 'Ĥ': 'H', 'ĥ': 'h', 'Ħ': 'H', 'ħ': 'h', 'Ĩ': 'I', 'ĩ': 'i',
2838
+ 'Ī': 'I', 'ī': 'i', 'Ĭ': 'I', 'ĭ': 'i', 'Į': 'I', 'į': 'i', 'İ': 'I',
2839
+ 'ı': 'i', 'IJ': 'IJ', 'ij': 'ij', 'Ĵ': 'J', 'ĵ': 'j', 'Ķ': 'K', 'ķ': 'k',
2840
+ 'ĸ': 'k', 'Ĺ': 'L', 'ĺ': 'l', 'Ļ': 'L', 'ļ': 'l', 'Ľ': 'L', 'ľ': 'l',
2841
+ 'Ŀ': 'L', 'ŀ': 'l', 'Ł': 'L', 'ł': 'l', 'Ń': 'N', 'ń': 'n', 'Ņ': 'N',
2842
+ 'ņ': 'n', 'Ň': 'N', 'ň': 'n', 'ʼn': '\'n', 'Ŋ': 'NG', 'ŋ': 'ng',
2843
+ 'Ō': 'O', 'ō': 'o', 'Ŏ': 'O', 'ŏ': 'o', 'Ő': 'O', 'ő': 'o', 'Œ': 'OE',
2844
+ 'œ': 'oe', 'Ŕ': 'R', 'ŕ': 'r', 'Ŗ': 'R', 'ŗ': 'r', 'Ř': 'R', 'ř': 'r',
2845
+ 'Ś': 'S', 'ś': 's', 'Ŝ': 'S', 'ŝ': 's', 'Ş': 'S', 'ş': 's', 'Š': 'S',
2846
+ 'š': 's', 'Ţ': 'T', 'ţ': 't', 'Ť': 'T', 'ť': 't', 'Ŧ': 'T', 'ŧ': 't',
2847
+ 'Ũ': 'U', 'ũ': 'u', 'Ū': 'U', 'ū': 'u', 'Ŭ': 'U', 'ŭ': 'u', 'Ů': 'U',
2848
+ 'ů': 'u', 'Ű': 'U', 'ű': 'u', 'Ų': 'U', 'ų': 'u', 'Ŵ': 'W', 'ŵ': 'w',
2849
+ 'Ŷ': 'Y', 'ŷ': 'y', 'Ÿ': 'Y', 'Ź': 'Z', 'ź': 'z', 'Ż': 'Z', 'ż': 'z',
2850
+ 'Ž': 'Z', 'ž': 'z'
2851
+ };
2852
+
2853
+ var DEFAULT_REPLACEMENT_CHAR = '?';
2854
+
2855
+ function Transliterator() {
2856
+ this.approximations = {};
2857
+
2858
+ for (var c in DEFAULT_APPROXIMATIONS) {
2859
+ this.approximate(c, DEFAULT_APPROXIMATIONS[c]);
2860
+ }
2861
+ }
2862
+
2863
+ Transliterator.getInstance = function(locale) {
2864
+ var storage = typeof process !== 'undefined' ? process : global;
2865
+ storage.__Inflector_Transliterator = storage.__Inflector_Transliterator || {};
2866
+ storage.__Inflector_Transliterator[locale] = storage.__Inflector_Transliterator[locale] || new Transliterator();
2867
+
2868
+ return storage.__Inflector_Transliterator[locale];
2869
+ };
2870
+
2871
+ Transliterator.prototype.approximate = function(string, replacement) {
2872
+ this.approximations[string] = replacement;
2873
+ };
2874
+
2875
+ Transliterator.prototype.transliterate = function(string, replacement) {
2876
+ var self = this;
2877
+
2878
+ return string.replace(/[^\u0000-\u007f]/g, function(c) {
2879
+ return self.approximations[c] || replacement || DEFAULT_REPLACEMENT_CHAR;
2880
+ });
2881
+ };
2882
+
2883
+ module.exports = Transliterator;
2884
+
2885
+ }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
2886
+ },{"_process":62}],27:[function(require,module,exports){
2887
+ 'use strict';
2888
+
2889
+ function enDefaults(inflect) {
2890
+ inflect.plural(/$/, 's');
2891
+ inflect.plural(/s$/i, 's');
2892
+ inflect.plural(/^(ax|test)is$/i, '$1es');
2893
+ inflect.plural(/(octop|vir)us$/i, '$1i');
2894
+ inflect.plural(/(octop|vir)i$/i, '$1i');
2895
+ inflect.plural(/(alias|status)$/i, '$1es');
2896
+ inflect.plural(/(bu)s$/i, '$1ses');
2897
+ inflect.plural(/(buffal|tomat)o$/i, '$1oes');
2898
+ inflect.plural(/([ti])um$/i, '$1a');
2899
+ inflect.plural(/([ti])a$/i, '$1a');
2900
+ inflect.plural(/sis$/i, 'ses');
2901
+ inflect.plural(/(?:([^f])fe|([lr])f)$/i, '$1$2ves');
2902
+ inflect.plural(/(hive)$/i, '$1s');
2903
+ inflect.plural(/([^aeiouy]|qu)y$/i, '$1ies');
2904
+ inflect.plural(/(x|ch|ss|sh)$/i, '$1es');
2905
+ inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '$1ices');
2906
+ inflect.plural(/^(m|l)ouse$/i, '$1ice');
2907
+ inflect.plural(/^(m|l)ice$/i, '$1ice');
2908
+ inflect.plural(/^(ox)$/i, '$1en');
2909
+ inflect.plural(/^(oxen)$/i, '$1');
2910
+ inflect.plural(/(quiz)$/i, '$1zes');
2911
+
2912
+ inflect.singular(/s$/i, '');
2913
+ inflect.singular(/(ss)$/i, '$1');
2914
+ inflect.singular(/(n)ews$/i, '$1ews');
2915
+ inflect.singular(/([ti])a$/i, '$1um');
2916
+ inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1sis');
2917
+ inflect.singular(/(^analy)(sis|ses)$/i, '$1sis');
2918
+ inflect.singular(/([^f])ves$/i, '$1fe');
2919
+ inflect.singular(/(hive)s$/i, '$1');
2920
+ inflect.singular(/(tive)s$/i, '$1');
2921
+ inflect.singular(/([lr])ves$/i, '$1f');
2922
+ inflect.singular(/([^aeiouy]|qu)ies$/i, '$1y');
2923
+ inflect.singular(/(s)eries$/i, '$1eries');
2924
+ inflect.singular(/(m)ovies$/i, '$1ovie');
2925
+ inflect.singular(/(x|ch|ss|sh)es$/i, '$1');
2926
+ inflect.singular(/^(m|l)ice$/i, '$1ouse');
2927
+ inflect.singular(/(bus)(es)?$/i, '$1');
2928
+ inflect.singular(/(o)es$/i, '$1');
2929
+ inflect.singular(/(shoe)s$/i, '$1');
2930
+ inflect.singular(/(cris|test)(is|es)$/i, '$1is');
2931
+ inflect.singular(/^(a)x[ie]s$/i, '$1xis');
2932
+ inflect.singular(/(octop|vir)(us|i)$/i, '$1us');
2933
+ inflect.singular(/(alias|status)(es)?$/i, '$1');
2934
+ inflect.singular(/^(ox)en/i, '$1');
2935
+ inflect.singular(/(vert|ind)ices$/i, '$1ex');
2936
+ inflect.singular(/(matr)ices$/i, '$1ix');
2937
+ inflect.singular(/(quiz)zes$/i, '$1');
2938
+ inflect.singular(/(database)s$/i, '$1');
2939
+
2940
+ inflect.irregular('person', 'people');
2941
+ inflect.irregular('man', 'men');
2942
+ inflect.irregular('child', 'children');
2943
+ inflect.irregular('sex', 'sexes');
2944
+ inflect.irregular('move', 'moves');
2945
+ inflect.irregular('zombie', 'zombies');
2946
+
2947
+ inflect.uncountable('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'police');
2948
+ }
2949
+
2950
+ module.exports = {
2951
+ en: enDefaults
2952
+ };
2953
+
2954
+ },{}],28:[function(require,module,exports){
2955
+ 'use strict';
2956
+
2957
+ var hasOwnProp = Object.prototype.hasOwnProperty;
2958
+
2959
+ function hasProp(obj, key) {
2960
+ return hasOwnProp.call(obj, key);
2961
+ }
2962
+
2963
+ module.exports = hasProp;
2964
+
2965
+ },{}],29:[function(require,module,exports){
2966
+ 'use strict';
2967
+
2968
+ function icPart(str) {
2969
+ return str.split('').map(function(c) { return '(?:' + [c.toUpperCase(), c.toLowerCase()].join('|') + ')'; }).join('')
2970
+ }
2971
+
2972
+ module.exports = icPart;
2973
+
2974
+ },{}],30:[function(require,module,exports){
2975
+ 'use strict';
2976
+
2977
+ var toString = Object.prototype.toString;
2978
+
2979
+ function isFunc(obj) {
2980
+ return toString.call(obj) === '[object Function]';
2981
+ }
2982
+
2983
+ module.exports = isFunc;
2984
+
2985
+ },{}],31:[function(require,module,exports){
2986
+ 'use strict';
2987
+
2988
+ var splice = Array.prototype.splice;
2989
+
2990
+ function remove(arr, elem) {
2991
+ for (var i = arr.length - 1; i >= 0; i--) {
2992
+ if (arr[i] === elem) {
2993
+ splice.call(arr, i, 1);
2994
+ }
2995
+ }
2996
+ }
2997
+
2998
+ module.exports = remove;
2999
+
3000
+ },{}],32:[function(require,module,exports){
3001
+ "use strict";
3002
+
3003
+ module.exports = function isObject(x) {
3004
+ return typeof x === "object" && x !== null;
3005
+ };
3006
+
3007
+ },{}],33:[function(require,module,exports){
3008
+ var createElement = require("./vdom/create-element.js")
3009
+
3010
+ module.exports = createElement
3011
+
3012
+ },{"./vdom/create-element.js":39}],34:[function(require,module,exports){
3013
+ var diff = require("./vtree/diff.js")
3014
+
3015
+ module.exports = diff
3016
+
3017
+ },{"./vtree/diff.js":59}],35:[function(require,module,exports){
3018
+ var h = require("./virtual-hyperscript/index.js")
3019
+
3020
+ module.exports = h
3021
+
3022
+ },{"./virtual-hyperscript/index.js":46}],36:[function(require,module,exports){
3023
+ var diff = require("./diff.js")
3024
+ var patch = require("./patch.js")
3025
+ var h = require("./h.js")
3026
+ var create = require("./create-element.js")
3027
+ var VNode = require('./vnode/vnode.js')
3028
+ var VText = require('./vnode/vtext.js')
3029
+
3030
+ module.exports = {
3031
+ diff: diff,
3032
+ patch: patch,
3033
+ h: h,
3034
+ create: create,
3035
+ VNode: VNode,
3036
+ VText: VText
3037
+ }
3038
+
3039
+ },{"./create-element.js":33,"./diff.js":34,"./h.js":35,"./patch.js":37,"./vnode/vnode.js":55,"./vnode/vtext.js":57}],37:[function(require,module,exports){
3040
+ var patch = require("./vdom/patch.js")
3041
+
3042
+ module.exports = patch
3043
+
3044
+ },{"./vdom/patch.js":42}],38:[function(require,module,exports){
3045
+ var isObject = require("is-object")
3046
+ var isHook = require("../vnode/is-vhook.js")
3047
+
3048
+ module.exports = applyProperties
3049
+
3050
+ function applyProperties(node, props, previous) {
3051
+ for (var propName in props) {
3052
+ var propValue = props[propName]
3053
+
3054
+ if (propValue === undefined) {
3055
+ removeProperty(node, propName, propValue, previous);
3056
+ } else if (isHook(propValue)) {
3057
+ removeProperty(node, propName, propValue, previous)
3058
+ if (propValue.hook) {
3059
+ propValue.hook(node,
3060
+ propName,
3061
+ previous ? previous[propName] : undefined)
3062
+ }
3063
+ } else {
3064
+ if (isObject(propValue)) {
3065
+ patchObject(node, props, previous, propName, propValue);
3066
+ } else {
3067
+ node[propName] = propValue
3068
+ }
3069
+ }
3070
+ }
3071
+ }
3072
+
3073
+ function removeProperty(node, propName, propValue, previous) {
3074
+ if (previous) {
3075
+ var previousValue = previous[propName]
3076
+
3077
+ if (!isHook(previousValue)) {
3078
+ if (propName === "attributes") {
3079
+ for (var attrName in previousValue) {
3080
+ node.removeAttribute(attrName)
3081
+ }
3082
+ } else if (propName === "style") {
3083
+ for (var i in previousValue) {
3084
+ node.style[i] = ""
3085
+ }
3086
+ } else if (typeof previousValue === "string") {
3087
+ node[propName] = ""
3088
+ } else {
3089
+ node[propName] = null
3090
+ }
3091
+ } else if (previousValue.unhook) {
3092
+ previousValue.unhook(node, propName, propValue)
3093
+ }
3094
+ }
3095
+ }
3096
+
3097
+ function patchObject(node, props, previous, propName, propValue) {
3098
+ var previousValue = previous ? previous[propName] : undefined
3099
+
3100
+ // Set attributes
3101
+ if (propName === "attributes") {
3102
+ for (var attrName in propValue) {
3103
+ var attrValue = propValue[attrName]
3104
+
3105
+ if (attrValue === undefined) {
3106
+ node.removeAttribute(attrName)
3107
+ } else {
3108
+ node.setAttribute(attrName, attrValue)
3109
+ }
3110
+ }
3111
+
3112
+ return
3113
+ }
3114
+
3115
+ if(previousValue && isObject(previousValue) &&
3116
+ getPrototype(previousValue) !== getPrototype(propValue)) {
3117
+ node[propName] = propValue
3118
+ return
3119
+ }
3120
+
3121
+ if (!isObject(node[propName])) {
3122
+ node[propName] = {}
3123
+ }
3124
+
3125
+ var replacer = propName === "style" ? "" : undefined
3126
+
3127
+ for (var k in propValue) {
3128
+ var value = propValue[k]
3129
+ node[propName][k] = (value === undefined) ? replacer : value
3130
+ }
3131
+ }
3132
+
3133
+ function getPrototype(value) {
3134
+ if (Object.getPrototypeOf) {
3135
+ return Object.getPrototypeOf(value)
3136
+ } else if (value.__proto__) {
3137
+ return value.__proto__
3138
+ } else if (value.constructor) {
3139
+ return value.constructor.prototype
3140
+ }
3141
+ }
3142
+
3143
+ },{"../vnode/is-vhook.js":50,"is-object":32}],39:[function(require,module,exports){
3144
+ var document = require("global/document")
3145
+
3146
+ var applyProperties = require("./apply-properties")
3147
+
3148
+ var isVNode = require("../vnode/is-vnode.js")
3149
+ var isVText = require("../vnode/is-vtext.js")
3150
+ var isWidget = require("../vnode/is-widget.js")
3151
+ var handleThunk = require("../vnode/handle-thunk.js")
3152
+
3153
+ module.exports = createElement
3154
+
3155
+ function createElement(vnode, opts) {
3156
+ var doc = opts ? opts.document || document : document
3157
+ var warn = opts ? opts.warn : null
3158
+
3159
+ vnode = handleThunk(vnode).a
3160
+
3161
+ if (isWidget(vnode)) {
3162
+ return vnode.init()
3163
+ } else if (isVText(vnode)) {
3164
+ return doc.createTextNode(vnode.text)
3165
+ } else if (!isVNode(vnode)) {
3166
+ if (warn) {
3167
+ warn("Item is not a valid virtual dom node", vnode)
3168
+ }
3169
+ return null
3170
+ }
3171
+
3172
+ var node = (vnode.namespace === null) ?
3173
+ doc.createElement(vnode.tagName) :
3174
+ doc.createElementNS(vnode.namespace, vnode.tagName)
3175
+
3176
+ var props = vnode.properties
3177
+ applyProperties(node, props)
3178
+
3179
+ var children = vnode.children
3180
+
3181
+ for (var i = 0; i < children.length; i++) {
3182
+ var childNode = createElement(children[i], opts)
3183
+ if (childNode) {
3184
+ node.appendChild(childNode)
3185
+ }
3186
+ }
3187
+
3188
+ return node
3189
+ }
3190
+
3191
+ },{"../vnode/handle-thunk.js":48,"../vnode/is-vnode.js":51,"../vnode/is-vtext.js":52,"../vnode/is-widget.js":53,"./apply-properties":38,"global/document":19}],40:[function(require,module,exports){
3192
+ // Maps a virtual DOM tree onto a real DOM tree in an efficient manner.
3193
+ // We don't want to read all of the DOM nodes in the tree so we use
3194
+ // the in-order tree indexing to eliminate recursion down certain branches.
3195
+ // We only recurse into a DOM node if we know that it contains a child of
3196
+ // interest.
3197
+
3198
+ var noChild = {}
3199
+
3200
+ module.exports = domIndex
3201
+
3202
+ function domIndex(rootNode, tree, indices, nodes) {
3203
+ if (!indices || indices.length === 0) {
3204
+ return {}
3205
+ } else {
3206
+ indices.sort(ascending)
3207
+ return recurse(rootNode, tree, indices, nodes, 0)
3208
+ }
3209
+ }
3210
+
3211
+ function recurse(rootNode, tree, indices, nodes, rootIndex) {
3212
+ nodes = nodes || {}
3213
+
3214
+
3215
+ if (rootNode) {
3216
+ if (indexInRange(indices, rootIndex, rootIndex)) {
3217
+ nodes[rootIndex] = rootNode
3218
+ }
3219
+
3220
+ var vChildren = tree.children
3221
+
3222
+ if (vChildren) {
3223
+
3224
+ var childNodes = rootNode.childNodes
3225
+
3226
+ for (var i = 0; i < tree.children.length; i++) {
3227
+ rootIndex += 1
3228
+
3229
+ var vChild = vChildren[i] || noChild
3230
+ var nextIndex = rootIndex + (vChild.count || 0)
3231
+
3232
+ // skip recursion down the tree if there are no nodes down here
3233
+ if (indexInRange(indices, rootIndex, nextIndex)) {
3234
+ recurse(childNodes[i], vChild, indices, nodes, rootIndex)
3235
+ }
3236
+
3237
+ rootIndex = nextIndex
3238
+ }
3239
+ }
3240
+ }
3241
+
3242
+ return nodes
3243
+ }
3244
+
3245
+ // Binary search for an index in the interval [left, right]
3246
+ function indexInRange(indices, left, right) {
3247
+ if (indices.length === 0) {
3248
+ return false
3249
+ }
3250
+
3251
+ var minIndex = 0
3252
+ var maxIndex = indices.length - 1
3253
+ var currentIndex
3254
+ var currentItem
3255
+
3256
+ while (minIndex <= maxIndex) {
3257
+ currentIndex = ((maxIndex + minIndex) / 2) >> 0
3258
+ currentItem = indices[currentIndex]
3259
+
3260
+ if (minIndex === maxIndex) {
3261
+ return currentItem >= left && currentItem <= right
3262
+ } else if (currentItem < left) {
3263
+ minIndex = currentIndex + 1
3264
+ } else if (currentItem > right) {
3265
+ maxIndex = currentIndex - 1
3266
+ } else {
3267
+ return true
3268
+ }
3269
+ }
3270
+
3271
+ return false;
3272
+ }
3273
+
3274
+ function ascending(a, b) {
3275
+ return a > b ? 1 : -1
3276
+ }
3277
+
3278
+ },{}],41:[function(require,module,exports){
3279
+ var applyProperties = require("./apply-properties")
3280
+
3281
+ var isWidget = require("../vnode/is-widget.js")
3282
+ var VPatch = require("../vnode/vpatch.js")
3283
+
3284
+ var updateWidget = require("./update-widget")
3285
+
3286
+ module.exports = applyPatch
3287
+
3288
+ function applyPatch(vpatch, domNode, renderOptions) {
3289
+ var type = vpatch.type
3290
+ var vNode = vpatch.vNode
3291
+ var patch = vpatch.patch
3292
+
3293
+ switch (type) {
3294
+ case VPatch.REMOVE:
3295
+ return removeNode(domNode, vNode)
3296
+ case VPatch.INSERT:
3297
+ return insertNode(domNode, patch, renderOptions)
3298
+ case VPatch.VTEXT:
3299
+ return stringPatch(domNode, vNode, patch, renderOptions)
3300
+ case VPatch.WIDGET:
3301
+ return widgetPatch(domNode, vNode, patch, renderOptions)
3302
+ case VPatch.VNODE:
3303
+ return vNodePatch(domNode, vNode, patch, renderOptions)
3304
+ case VPatch.ORDER:
3305
+ reorderChildren(domNode, patch)
3306
+ return domNode
3307
+ case VPatch.PROPS:
3308
+ applyProperties(domNode, patch, vNode.properties)
3309
+ return domNode
3310
+ case VPatch.THUNK:
3311
+ return replaceRoot(domNode,
3312
+ renderOptions.patch(domNode, patch, renderOptions))
3313
+ default:
3314
+ return domNode
3315
+ }
3316
+ }
3317
+
3318
+ function removeNode(domNode, vNode) {
3319
+ var parentNode = domNode.parentNode
3320
+
3321
+ if (parentNode) {
3322
+ parentNode.removeChild(domNode)
3323
+ }
3324
+
3325
+ destroyWidget(domNode, vNode);
3326
+
3327
+ return null
3328
+ }
3329
+
3330
+ function insertNode(parentNode, vNode, renderOptions) {
3331
+ var newNode = renderOptions.render(vNode, renderOptions)
3332
+
3333
+ if (parentNode) {
3334
+ parentNode.appendChild(newNode)
3335
+ }
3336
+
3337
+ return parentNode
3338
+ }
3339
+
3340
+ function stringPatch(domNode, leftVNode, vText, renderOptions) {
3341
+ var newNode
3342
+
3343
+ if (domNode.nodeType === 3) {
3344
+ domNode.replaceData(0, domNode.length, vText.text)
3345
+ newNode = domNode
3346
+ } else {
3347
+ var parentNode = domNode.parentNode
3348
+ newNode = renderOptions.render(vText, renderOptions)
3349
+
3350
+ if (parentNode && newNode !== domNode) {
3351
+ parentNode.replaceChild(newNode, domNode)
3352
+ }
3353
+ }
3354
+
3355
+ return newNode
3356
+ }
3357
+
3358
+ function widgetPatch(domNode, leftVNode, widget, renderOptions) {
3359
+ var updating = updateWidget(leftVNode, widget)
3360
+ var newNode
3361
+
3362
+ if (updating) {
3363
+ newNode = widget.update(leftVNode, domNode) || domNode
3364
+ } else {
3365
+ newNode = renderOptions.render(widget, renderOptions)
3366
+ }
3367
+
3368
+ var parentNode = domNode.parentNode
3369
+
3370
+ if (parentNode && newNode !== domNode) {
3371
+ parentNode.replaceChild(newNode, domNode)
3372
+ }
3373
+
3374
+ if (!updating) {
3375
+ destroyWidget(domNode, leftVNode)
3376
+ }
3377
+
3378
+ return newNode
3379
+ }
3380
+
3381
+ function vNodePatch(domNode, leftVNode, vNode, renderOptions) {
3382
+ var parentNode = domNode.parentNode
3383
+ var newNode = renderOptions.render(vNode, renderOptions)
3384
+
3385
+ if (parentNode && newNode !== domNode) {
3386
+ parentNode.replaceChild(newNode, domNode)
3387
+ }
3388
+
3389
+ return newNode
3390
+ }
3391
+
3392
+ function destroyWidget(domNode, w) {
3393
+ if (typeof w.destroy === "function" && isWidget(w)) {
3394
+ w.destroy(domNode)
3395
+ }
3396
+ }
3397
+
3398
+ function reorderChildren(domNode, moves) {
3399
+ var childNodes = domNode.childNodes
3400
+ var keyMap = {}
3401
+ var node
3402
+ var remove
3403
+ var insert
3404
+
3405
+ for (var i = 0; i < moves.removes.length; i++) {
3406
+ remove = moves.removes[i]
3407
+ node = childNodes[remove.from]
3408
+ if (remove.key) {
3409
+ keyMap[remove.key] = node
3410
+ }
3411
+ domNode.removeChild(node)
3412
+ }
3413
+
3414
+ var length = childNodes.length
3415
+ for (var j = 0; j < moves.inserts.length; j++) {
3416
+ insert = moves.inserts[j]
3417
+ node = keyMap[insert.key]
3418
+ // this is the weirdest bug i've ever seen in webkit
3419
+ domNode.insertBefore(node, insert.to >= length++ ? null : childNodes[insert.to])
3420
+ }
3421
+ }
3422
+
3423
+ function replaceRoot(oldRoot, newRoot) {
3424
+ if (oldRoot && newRoot && oldRoot !== newRoot && oldRoot.parentNode) {
3425
+ oldRoot.parentNode.replaceChild(newRoot, oldRoot)
3426
+ }
3427
+
3428
+ return newRoot;
3429
+ }
3430
+
3431
+ },{"../vnode/is-widget.js":53,"../vnode/vpatch.js":56,"./apply-properties":38,"./update-widget":43}],42:[function(require,module,exports){
3432
+ var document = require("global/document")
3433
+ var isArray = require("x-is-array")
3434
+
3435
+ var render = require("./create-element")
3436
+ var domIndex = require("./dom-index")
3437
+ var patchOp = require("./patch-op")
3438
+ module.exports = patch
3439
+
3440
+ function patch(rootNode, patches, renderOptions) {
3441
+ renderOptions = renderOptions || {}
3442
+ renderOptions.patch = renderOptions.patch && renderOptions.patch !== patch
3443
+ ? renderOptions.patch
3444
+ : patchRecursive
3445
+ renderOptions.render = renderOptions.render || render
3446
+
3447
+ return renderOptions.patch(rootNode, patches, renderOptions)
3448
+ }
3449
+
3450
+ function patchRecursive(rootNode, patches, renderOptions) {
3451
+ var indices = patchIndices(patches)
3452
+
3453
+ if (indices.length === 0) {
3454
+ return rootNode
3455
+ }
3456
+
3457
+ var index = domIndex(rootNode, patches.a, indices)
3458
+ var ownerDocument = rootNode.ownerDocument
3459
+
3460
+ if (!renderOptions.document && ownerDocument !== document) {
3461
+ renderOptions.document = ownerDocument
3462
+ }
3463
+
3464
+ for (var i = 0; i < indices.length; i++) {
3465
+ var nodeIndex = indices[i]
3466
+ rootNode = applyPatch(rootNode,
3467
+ index[nodeIndex],
3468
+ patches[nodeIndex],
3469
+ renderOptions)
3470
+ }
3471
+
3472
+ return rootNode
3473
+ }
3474
+
3475
+ function applyPatch(rootNode, domNode, patchList, renderOptions) {
3476
+ if (!domNode) {
3477
+ return rootNode
3478
+ }
3479
+
3480
+ var newNode
3481
+
3482
+ if (isArray(patchList)) {
3483
+ for (var i = 0; i < patchList.length; i++) {
3484
+ newNode = patchOp(patchList[i], domNode, renderOptions)
3485
+
3486
+ if (domNode === rootNode) {
3487
+ rootNode = newNode
3488
+ }
3489
+ }
3490
+ } else {
3491
+ newNode = patchOp(patchList, domNode, renderOptions)
3492
+
3493
+ if (domNode === rootNode) {
3494
+ rootNode = newNode
3495
+ }
3496
+ }
3497
+
3498
+ return rootNode
3499
+ }
3500
+
3501
+ function patchIndices(patches) {
3502
+ var indices = []
3503
+
3504
+ for (var key in patches) {
3505
+ if (key !== "a") {
3506
+ indices.push(Number(key))
3507
+ }
3508
+ }
3509
+
3510
+ return indices
3511
+ }
3512
+
3513
+ },{"./create-element":39,"./dom-index":40,"./patch-op":41,"global/document":19,"x-is-array":60}],43:[function(require,module,exports){
3514
+ var isWidget = require("../vnode/is-widget.js")
3515
+
3516
+ module.exports = updateWidget
3517
+
3518
+ function updateWidget(a, b) {
3519
+ if (isWidget(a) && isWidget(b)) {
3520
+ if ("name" in a && "name" in b) {
3521
+ return a.id === b.id
3522
+ } else {
3523
+ return a.init === b.init
3524
+ }
3525
+ }
3526
+
3527
+ return false
3528
+ }
3529
+
3530
+ },{"../vnode/is-widget.js":53}],44:[function(require,module,exports){
3531
+ 'use strict';
3532
+
3533
+ var EvStore = require('ev-store');
3534
+
3535
+ module.exports = EvHook;
3536
+
3537
+ function EvHook(value) {
3538
+ if (!(this instanceof EvHook)) {
3539
+ return new EvHook(value);
3540
+ }
3541
+
3542
+ this.value = value;
3543
+ }
3544
+
3545
+ EvHook.prototype.hook = function (node, propertyName) {
3546
+ var es = EvStore(node);
3547
+ var propName = propertyName.substr(3);
3548
+
3549
+ es[propName] = this.value;
3550
+ };
3551
+
3552
+ EvHook.prototype.unhook = function(node, propertyName) {
3553
+ var es = EvStore(node);
3554
+ var propName = propertyName.substr(3);
3555
+
3556
+ es[propName] = undefined;
3557
+ };
3558
+
3559
+ },{"ev-store":18}],45:[function(require,module,exports){
3560
+ 'use strict';
3561
+
3562
+ module.exports = SoftSetHook;
3563
+
3564
+ function SoftSetHook(value) {
3565
+ if (!(this instanceof SoftSetHook)) {
3566
+ return new SoftSetHook(value);
3567
+ }
3568
+
3569
+ this.value = value;
3570
+ }
3571
+
3572
+ SoftSetHook.prototype.hook = function (node, propertyName) {
3573
+ if (node[propertyName] !== this.value) {
3574
+ node[propertyName] = this.value;
3575
+ }
3576
+ };
3577
+
3578
+ },{}],46:[function(require,module,exports){
3579
+ 'use strict';
3580
+
3581
+ var isArray = require('x-is-array');
3582
+
3583
+ var VNode = require('../vnode/vnode.js');
3584
+ var VText = require('../vnode/vtext.js');
3585
+ var isVNode = require('../vnode/is-vnode');
3586
+ var isVText = require('../vnode/is-vtext');
3587
+ var isWidget = require('../vnode/is-widget');
3588
+ var isHook = require('../vnode/is-vhook');
3589
+ var isVThunk = require('../vnode/is-thunk');
3590
+
3591
+ var parseTag = require('./parse-tag.js');
3592
+ var softSetHook = require('./hooks/soft-set-hook.js');
3593
+ var evHook = require('./hooks/ev-hook.js');
3594
+
3595
+ module.exports = h;
3596
+
3597
+ function h(tagName, properties, children) {
3598
+ var childNodes = [];
3599
+ var tag, props, key, namespace;
3600
+
3601
+ if (!children && isChildren(properties)) {
3602
+ children = properties;
3603
+ props = {};
3604
+ }
3605
+
3606
+ props = props || properties || {};
3607
+ tag = parseTag(tagName, props);
3608
+
3609
+ // support keys
3610
+ if (props.hasOwnProperty('key')) {
3611
+ key = props.key;
3612
+ props.key = undefined;
3613
+ }
3614
+
3615
+ // support namespace
3616
+ if (props.hasOwnProperty('namespace')) {
3617
+ namespace = props.namespace;
3618
+ props.namespace = undefined;
3619
+ }
3620
+
3621
+ // fix cursor bug
3622
+ if (tag === 'INPUT' &&
3623
+ !namespace &&
3624
+ props.hasOwnProperty('value') &&
3625
+ props.value !== undefined &&
3626
+ !isHook(props.value)
3627
+ ) {
3628
+ props.value = softSetHook(props.value);
3629
+ }
3630
+
3631
+ transformProperties(props);
3632
+
3633
+ if (children !== undefined && children !== null) {
3634
+ addChild(children, childNodes, tag, props);
3635
+ }
3636
+
3637
+
3638
+ return new VNode(tag, props, childNodes, key, namespace);
3639
+ }
3640
+
3641
+ function addChild(c, childNodes, tag, props) {
3642
+ if (typeof c === 'string') {
3643
+ childNodes.push(new VText(c));
3644
+ } else if (typeof c === 'number') {
3645
+ childNodes.push(new VText(String(c)));
3646
+ } else if (isChild(c)) {
3647
+ childNodes.push(c);
3648
+ } else if (isArray(c)) {
3649
+ for (var i = 0; i < c.length; i++) {
3650
+ addChild(c[i], childNodes, tag, props);
3651
+ }
3652
+ } else if (c === null || c === undefined) {
3653
+ return;
3654
+ } else {
3655
+ throw UnexpectedVirtualElement({
3656
+ foreignObject: c,
3657
+ parentVnode: {
3658
+ tagName: tag,
3659
+ properties: props
3660
+ }
3661
+ });
3662
+ }
3663
+ }
3664
+
3665
+ function transformProperties(props) {
3666
+ for (var propName in props) {
3667
+ if (props.hasOwnProperty(propName)) {
3668
+ var value = props[propName];
3669
+
3670
+ if (isHook(value)) {
3671
+ continue;
3672
+ }
3673
+
3674
+ if (propName.substr(0, 3) === 'ev-') {
3675
+ // add ev-foo support
3676
+ props[propName] = evHook(value);
3677
+ }
3678
+ }
3679
+ }
3680
+ }
3681
+
3682
+ function isChild(x) {
3683
+ return isVNode(x) || isVText(x) || isWidget(x) || isVThunk(x);
3684
+ }
3685
+
3686
+ function isChildren(x) {
3687
+ return typeof x === 'string' || isArray(x) || isChild(x);
3688
+ }
3689
+
3690
+ function UnexpectedVirtualElement(data) {
3691
+ var err = new Error();
3692
+
3693
+ err.type = 'virtual-hyperscript.unexpected.virtual-element';
3694
+ err.message = 'Unexpected virtual child passed to h().\n' +
3695
+ 'Expected a VNode / Vthunk / VWidget / string but:\n' +
3696
+ 'got:\n' +
3697
+ errorString(data.foreignObject) +
3698
+ '.\n' +
3699
+ 'The parent vnode is:\n' +
3700
+ errorString(data.parentVnode)
3701
+ '\n' +
3702
+ 'Suggested fix: change your `h(..., [ ... ])` callsite.';
3703
+ err.foreignObject = data.foreignObject;
3704
+ err.parentVnode = data.parentVnode;
3705
+
3706
+ return err;
3707
+ }
3708
+
3709
+ function errorString(obj) {
3710
+ try {
3711
+ return JSON.stringify(obj, null, ' ');
3712
+ } catch (e) {
3713
+ return String(obj);
3714
+ }
3715
+ }
3716
+
3717
+ },{"../vnode/is-thunk":49,"../vnode/is-vhook":50,"../vnode/is-vnode":51,"../vnode/is-vtext":52,"../vnode/is-widget":53,"../vnode/vnode.js":55,"../vnode/vtext.js":57,"./hooks/ev-hook.js":44,"./hooks/soft-set-hook.js":45,"./parse-tag.js":47,"x-is-array":60}],47:[function(require,module,exports){
3718
+ 'use strict';
3719
+
3720
+ var split = require('browser-split');
3721
+
3722
+ var classIdSplit = /([\.#]?[a-zA-Z0-9\u007F-\uFFFF_:-]+)/;
3723
+ var notClassId = /^\.|#/;
3724
+
3725
+ module.exports = parseTag;
3726
+
3727
+ function parseTag(tag, props) {
3728
+ if (!tag) {
3729
+ return 'DIV';
3730
+ }
3731
+
3732
+ var noId = !(props.hasOwnProperty('id'));
3733
+
3734
+ var tagParts = split(tag, classIdSplit);
3735
+ var tagName = null;
3736
+
3737
+ if (notClassId.test(tagParts[1])) {
3738
+ tagName = 'DIV';
3739
+ }
3740
+
3741
+ var classes, part, type, i;
3742
+
3743
+ for (i = 0; i < tagParts.length; i++) {
3744
+ part = tagParts[i];
3745
+
3746
+ if (!part) {
3747
+ continue;
3748
+ }
3749
+
3750
+ type = part.charAt(0);
3751
+
3752
+ if (!tagName) {
3753
+ tagName = part;
3754
+ } else if (type === '.') {
3755
+ classes = classes || [];
3756
+ classes.push(part.substring(1, part.length));
3757
+ } else if (type === '#' && noId) {
3758
+ props.id = part.substring(1, part.length);
3759
+ }
3760
+ }
3761
+
3762
+ if (classes) {
3763
+ if (props.className) {
3764
+ classes.push(props.className);
3765
+ }
3766
+
3767
+ props.className = classes.join(' ');
3768
+ }
3769
+
3770
+ return props.namespace ? tagName : tagName.toUpperCase();
3771
+ }
3772
+
3773
+ },{"browser-split":17}],48:[function(require,module,exports){
3774
+ var isVNode = require("./is-vnode")
3775
+ var isVText = require("./is-vtext")
3776
+ var isWidget = require("./is-widget")
3777
+ var isThunk = require("./is-thunk")
3778
+
3779
+ module.exports = handleThunk
3780
+
3781
+ function handleThunk(a, b) {
3782
+ var renderedA = a
3783
+ var renderedB = b
3784
+
3785
+ if (isThunk(b)) {
3786
+ renderedB = renderThunk(b, a)
3787
+ }
3788
+
3789
+ if (isThunk(a)) {
3790
+ renderedA = renderThunk(a, null)
3791
+ }
3792
+
3793
+ return {
3794
+ a: renderedA,
3795
+ b: renderedB
3796
+ }
3797
+ }
3798
+
3799
+ function renderThunk(thunk, previous) {
3800
+ var renderedThunk = thunk.vnode
3801
+
3802
+ if (!renderedThunk) {
3803
+ renderedThunk = thunk.vnode = thunk.render(previous)
3804
+ }
3805
+
3806
+ if (!(isVNode(renderedThunk) ||
3807
+ isVText(renderedThunk) ||
3808
+ isWidget(renderedThunk))) {
3809
+ throw new Error("thunk did not return a valid node");
3810
+ }
3811
+
3812
+ return renderedThunk
3813
+ }
3814
+
3815
+ },{"./is-thunk":49,"./is-vnode":51,"./is-vtext":52,"./is-widget":53}],49:[function(require,module,exports){
3816
+ module.exports = isThunk
3817
+
3818
+ function isThunk(t) {
3819
+ return t && t.type === "Thunk"
3820
+ }
3821
+
3822
+ },{}],50:[function(require,module,exports){
3823
+ module.exports = isHook
3824
+
3825
+ function isHook(hook) {
3826
+ return hook &&
3827
+ (typeof hook.hook === "function" && !hook.hasOwnProperty("hook") ||
3828
+ typeof hook.unhook === "function" && !hook.hasOwnProperty("unhook"))
3829
+ }
3830
+
3831
+ },{}],51:[function(require,module,exports){
3832
+ var version = require("./version")
3833
+
3834
+ module.exports = isVirtualNode
3835
+
3836
+ function isVirtualNode(x) {
3837
+ return x && x.type === "VirtualNode" && x.version === version
3838
+ }
3839
+
3840
+ },{"./version":54}],52:[function(require,module,exports){
3841
+ var version = require("./version")
3842
+
3843
+ module.exports = isVirtualText
3844
+
3845
+ function isVirtualText(x) {
3846
+ return x && x.type === "VirtualText" && x.version === version
3847
+ }
3848
+
3849
+ },{"./version":54}],53:[function(require,module,exports){
3850
+ module.exports = isWidget
3851
+
3852
+ function isWidget(w) {
3853
+ return w && w.type === "Widget"
3854
+ }
3855
+
3856
+ },{}],54:[function(require,module,exports){
3857
+ module.exports = "2"
3858
+
3859
+ },{}],55:[function(require,module,exports){
3860
+ var version = require("./version")
3861
+ var isVNode = require("./is-vnode")
3862
+ var isWidget = require("./is-widget")
3863
+ var isThunk = require("./is-thunk")
3864
+ var isVHook = require("./is-vhook")
3865
+
3866
+ module.exports = VirtualNode
3867
+
3868
+ var noProperties = {}
3869
+ var noChildren = []
3870
+
3871
+ function VirtualNode(tagName, properties, children, key, namespace) {
3872
+ this.tagName = tagName
3873
+ this.properties = properties || noProperties
3874
+ this.children = children || noChildren
3875
+ this.key = key != null ? String(key) : undefined
3876
+ this.namespace = (typeof namespace === "string") ? namespace : null
3877
+
3878
+ var count = (children && children.length) || 0
3879
+ var descendants = 0
3880
+ var hasWidgets = false
3881
+ var hasThunks = false
3882
+ var descendantHooks = false
3883
+ var hooks
3884
+
3885
+ for (var propName in properties) {
3886
+ if (properties.hasOwnProperty(propName)) {
3887
+ var property = properties[propName]
3888
+ if (isVHook(property) && property.unhook) {
3889
+ if (!hooks) {
3890
+ hooks = {}
3891
+ }
3892
+
3893
+ hooks[propName] = property
3894
+ }
3895
+ }
3896
+ }
3897
+
3898
+ for (var i = 0; i < count; i++) {
3899
+ var child = children[i]
3900
+ if (isVNode(child)) {
3901
+ descendants += child.count || 0
3902
+
3903
+ if (!hasWidgets && child.hasWidgets) {
3904
+ hasWidgets = true
3905
+ }
3906
+
3907
+ if (!hasThunks && child.hasThunks) {
3908
+ hasThunks = true
3909
+ }
3910
+
3911
+ if (!descendantHooks && (child.hooks || child.descendantHooks)) {
3912
+ descendantHooks = true
3913
+ }
3914
+ } else if (!hasWidgets && isWidget(child)) {
3915
+ if (typeof child.destroy === "function") {
3916
+ hasWidgets = true
3917
+ }
3918
+ } else if (!hasThunks && isThunk(child)) {
3919
+ hasThunks = true;
3920
+ }
3921
+ }
3922
+
3923
+ this.count = count + descendants
3924
+ this.hasWidgets = hasWidgets
3925
+ this.hasThunks = hasThunks
3926
+ this.hooks = hooks
3927
+ this.descendantHooks = descendantHooks
3928
+ }
3929
+
3930
+ VirtualNode.prototype.version = version
3931
+ VirtualNode.prototype.type = "VirtualNode"
3932
+
3933
+ },{"./is-thunk":49,"./is-vhook":50,"./is-vnode":51,"./is-widget":53,"./version":54}],56:[function(require,module,exports){
3934
+ var version = require("./version")
3935
+
3936
+ VirtualPatch.NONE = 0
3937
+ VirtualPatch.VTEXT = 1
3938
+ VirtualPatch.VNODE = 2
3939
+ VirtualPatch.WIDGET = 3
3940
+ VirtualPatch.PROPS = 4
3941
+ VirtualPatch.ORDER = 5
3942
+ VirtualPatch.INSERT = 6
3943
+ VirtualPatch.REMOVE = 7
3944
+ VirtualPatch.THUNK = 8
3945
+
3946
+ module.exports = VirtualPatch
3947
+
3948
+ function VirtualPatch(type, vNode, patch) {
3949
+ this.type = Number(type)
3950
+ this.vNode = vNode
3951
+ this.patch = patch
3952
+ }
3953
+
3954
+ VirtualPatch.prototype.version = version
3955
+ VirtualPatch.prototype.type = "VirtualPatch"
3956
+
3957
+ },{"./version":54}],57:[function(require,module,exports){
3958
+ var version = require("./version")
3959
+
3960
+ module.exports = VirtualText
3961
+
3962
+ function VirtualText(text) {
3963
+ this.text = String(text)
3964
+ }
3965
+
3966
+ VirtualText.prototype.version = version
3967
+ VirtualText.prototype.type = "VirtualText"
3968
+
3969
+ },{"./version":54}],58:[function(require,module,exports){
3970
+ var isObject = require("is-object")
3971
+ var isHook = require("../vnode/is-vhook")
3972
+
3973
+ module.exports = diffProps
3974
+
3975
+ function diffProps(a, b) {
3976
+ var diff
3977
+
3978
+ for (var aKey in a) {
3979
+ if (!(aKey in b)) {
3980
+ diff = diff || {}
3981
+ diff[aKey] = undefined
3982
+ }
3983
+
3984
+ var aValue = a[aKey]
3985
+ var bValue = b[aKey]
3986
+
3987
+ if (aValue === bValue) {
3988
+ continue
3989
+ } else if (isObject(aValue) && isObject(bValue)) {
3990
+ if (getPrototype(bValue) !== getPrototype(aValue)) {
3991
+ diff = diff || {}
3992
+ diff[aKey] = bValue
3993
+ } else if (isHook(bValue)) {
3994
+ diff = diff || {}
3995
+ diff[aKey] = bValue
3996
+ } else {
3997
+ var objectDiff = diffProps(aValue, bValue)
3998
+ if (objectDiff) {
3999
+ diff = diff || {}
4000
+ diff[aKey] = objectDiff
4001
+ }
4002
+ }
4003
+ } else {
4004
+ diff = diff || {}
4005
+ diff[aKey] = bValue
4006
+ }
4007
+ }
4008
+
4009
+ for (var bKey in b) {
4010
+ if (!(bKey in a)) {
4011
+ diff = diff || {}
4012
+ diff[bKey] = b[bKey]
4013
+ }
4014
+ }
4015
+
4016
+ return diff
4017
+ }
4018
+
4019
+ function getPrototype(value) {
4020
+ if (Object.getPrototypeOf) {
4021
+ return Object.getPrototypeOf(value)
4022
+ } else if (value.__proto__) {
4023
+ return value.__proto__
4024
+ } else if (value.constructor) {
4025
+ return value.constructor.prototype
4026
+ }
4027
+ }
4028
+
4029
+ },{"../vnode/is-vhook":50,"is-object":32}],59:[function(require,module,exports){
4030
+ var isArray = require("x-is-array")
4031
+
4032
+ var VPatch = require("../vnode/vpatch")
4033
+ var isVNode = require("../vnode/is-vnode")
4034
+ var isVText = require("../vnode/is-vtext")
4035
+ var isWidget = require("../vnode/is-widget")
4036
+ var isThunk = require("../vnode/is-thunk")
4037
+ var handleThunk = require("../vnode/handle-thunk")
4038
+
4039
+ var diffProps = require("./diff-props")
4040
+
4041
+ module.exports = diff
4042
+
4043
+ function diff(a, b) {
4044
+ var patch = { a: a }
4045
+ walk(a, b, patch, 0)
4046
+ return patch
4047
+ }
4048
+
4049
+ function walk(a, b, patch, index) {
4050
+ if (a === b) {
4051
+ return
4052
+ }
4053
+
4054
+ var apply = patch[index]
4055
+ var applyClear = false
4056
+
4057
+ if (isThunk(a) || isThunk(b)) {
4058
+ thunks(a, b, patch, index)
4059
+ } else if (b == null) {
4060
+
4061
+ // If a is a widget we will add a remove patch for it
4062
+ // Otherwise any child widgets/hooks must be destroyed.
4063
+ // This prevents adding two remove patches for a widget.
4064
+ if (!isWidget(a)) {
4065
+ clearState(a, patch, index)
4066
+ apply = patch[index]
4067
+ }
4068
+
4069
+ apply = appendPatch(apply, new VPatch(VPatch.REMOVE, a, b))
4070
+ } else if (isVNode(b)) {
4071
+ if (isVNode(a)) {
4072
+ if (a.tagName === b.tagName &&
4073
+ a.namespace === b.namespace &&
4074
+ a.key === b.key) {
4075
+ var propsPatch = diffProps(a.properties, b.properties)
4076
+ if (propsPatch) {
4077
+ apply = appendPatch(apply,
4078
+ new VPatch(VPatch.PROPS, a, propsPatch))
4079
+ }
4080
+ apply = diffChildren(a, b, patch, apply, index)
4081
+ } else {
4082
+ apply = appendPatch(apply, new VPatch(VPatch.VNODE, a, b))
4083
+ applyClear = true
4084
+ }
4085
+ } else {
4086
+ apply = appendPatch(apply, new VPatch(VPatch.VNODE, a, b))
4087
+ applyClear = true
4088
+ }
4089
+ } else if (isVText(b)) {
4090
+ if (!isVText(a)) {
4091
+ apply = appendPatch(apply, new VPatch(VPatch.VTEXT, a, b))
4092
+ applyClear = true
4093
+ } else if (a.text !== b.text) {
4094
+ apply = appendPatch(apply, new VPatch(VPatch.VTEXT, a, b))
4095
+ }
4096
+ } else if (isWidget(b)) {
4097
+ if (!isWidget(a)) {
4098
+ applyClear = true
4099
+ }
4100
+
4101
+ apply = appendPatch(apply, new VPatch(VPatch.WIDGET, a, b))
4102
+ }
4103
+
4104
+ if (apply) {
4105
+ patch[index] = apply
4106
+ }
4107
+
4108
+ if (applyClear) {
4109
+ clearState(a, patch, index)
4110
+ }
4111
+ }
4112
+
4113
+ function diffChildren(a, b, patch, apply, index) {
4114
+ var aChildren = a.children
4115
+ var orderedSet = reorder(aChildren, b.children)
4116
+ var bChildren = orderedSet.children
4117
+
4118
+ var aLen = aChildren.length
4119
+ var bLen = bChildren.length
4120
+ var len = aLen > bLen ? aLen : bLen
4121
+
4122
+ for (var i = 0; i < len; i++) {
4123
+ var leftNode = aChildren[i]
4124
+ var rightNode = bChildren[i]
4125
+ index += 1
4126
+
4127
+ if (!leftNode) {
4128
+ if (rightNode) {
4129
+ // Excess nodes in b need to be added
4130
+ apply = appendPatch(apply,
4131
+ new VPatch(VPatch.INSERT, null, rightNode))
4132
+ }
4133
+ } else {
4134
+ walk(leftNode, rightNode, patch, index)
4135
+ }
4136
+
4137
+ if (isVNode(leftNode) && leftNode.count) {
4138
+ index += leftNode.count
4139
+ }
4140
+ }
4141
+
4142
+ if (orderedSet.moves) {
4143
+ // Reorder nodes last
4144
+ apply = appendPatch(apply, new VPatch(
4145
+ VPatch.ORDER,
4146
+ a,
4147
+ orderedSet.moves
4148
+ ))
4149
+ }
4150
+
4151
+ return apply
4152
+ }
4153
+
4154
+ function clearState(vNode, patch, index) {
4155
+ // TODO: Make this a single walk, not two
4156
+ unhook(vNode, patch, index)
4157
+ destroyWidgets(vNode, patch, index)
4158
+ }
4159
+
4160
+ // Patch records for all destroyed widgets must be added because we need
4161
+ // a DOM node reference for the destroy function
4162
+ function destroyWidgets(vNode, patch, index) {
4163
+ if (isWidget(vNode)) {
4164
+ if (typeof vNode.destroy === "function") {
4165
+ patch[index] = appendPatch(
4166
+ patch[index],
4167
+ new VPatch(VPatch.REMOVE, vNode, null)
4168
+ )
4169
+ }
4170
+ } else if (isVNode(vNode) && (vNode.hasWidgets || vNode.hasThunks)) {
4171
+ var children = vNode.children
4172
+ var len = children.length
4173
+ for (var i = 0; i < len; i++) {
4174
+ var child = children[i]
4175
+ index += 1
4176
+
4177
+ destroyWidgets(child, patch, index)
4178
+
4179
+ if (isVNode(child) && child.count) {
4180
+ index += child.count
4181
+ }
4182
+ }
4183
+ } else if (isThunk(vNode)) {
4184
+ thunks(vNode, null, patch, index)
4185
+ }
4186
+ }
4187
+
4188
+ // Create a sub-patch for thunks
4189
+ function thunks(a, b, patch, index) {
4190
+ var nodes = handleThunk(a, b)
4191
+ var thunkPatch = diff(nodes.a, nodes.b)
4192
+ if (hasPatches(thunkPatch)) {
4193
+ patch[index] = new VPatch(VPatch.THUNK, null, thunkPatch)
4194
+ }
4195
+ }
4196
+
4197
+ function hasPatches(patch) {
4198
+ for (var index in patch) {
4199
+ if (index !== "a") {
4200
+ return true
4201
+ }
4202
+ }
4203
+
4204
+ return false
4205
+ }
4206
+
4207
+ // Execute hooks when two nodes are identical
4208
+ function unhook(vNode, patch, index) {
4209
+ if (isVNode(vNode)) {
4210
+ if (vNode.hooks) {
4211
+ patch[index] = appendPatch(
4212
+ patch[index],
4213
+ new VPatch(
4214
+ VPatch.PROPS,
4215
+ vNode,
4216
+ undefinedKeys(vNode.hooks)
4217
+ )
4218
+ )
4219
+ }
4220
+
4221
+ if (vNode.descendantHooks || vNode.hasThunks) {
4222
+ var children = vNode.children
4223
+ var len = children.length
4224
+ for (var i = 0; i < len; i++) {
4225
+ var child = children[i]
4226
+ index += 1
4227
+
4228
+ unhook(child, patch, index)
4229
+
4230
+ if (isVNode(child) && child.count) {
4231
+ index += child.count
4232
+ }
4233
+ }
4234
+ }
4235
+ } else if (isThunk(vNode)) {
4236
+ thunks(vNode, null, patch, index)
4237
+ }
4238
+ }
4239
+
4240
+ function undefinedKeys(obj) {
4241
+ var result = {}
4242
+
4243
+ for (var key in obj) {
4244
+ result[key] = undefined
4245
+ }
4246
+
4247
+ return result
4248
+ }
4249
+
4250
+ // List diff, naive left to right reordering
4251
+ function reorder(aChildren, bChildren) {
4252
+ // O(M) time, O(M) memory
4253
+ var bChildIndex = keyIndex(bChildren)
4254
+ var bKeys = bChildIndex.keys
4255
+ var bFree = bChildIndex.free
4256
+
4257
+ if (bFree.length === bChildren.length) {
4258
+ return {
4259
+ children: bChildren,
4260
+ moves: null
4261
+ }
4262
+ }
4263
+
4264
+ // O(N) time, O(N) memory
4265
+ var aChildIndex = keyIndex(aChildren)
4266
+ var aKeys = aChildIndex.keys
4267
+ var aFree = aChildIndex.free
4268
+
4269
+ if (aFree.length === aChildren.length) {
4270
+ return {
4271
+ children: bChildren,
4272
+ moves: null
4273
+ }
4274
+ }
4275
+
4276
+ // O(MAX(N, M)) memory
4277
+ var newChildren = []
4278
+
4279
+ var freeIndex = 0
4280
+ var freeCount = bFree.length
4281
+ var deletedItems = 0
4282
+
4283
+ // Iterate through a and match a node in b
4284
+ // O(N) time,
4285
+ for (var i = 0 ; i < aChildren.length; i++) {
4286
+ var aItem = aChildren[i]
4287
+ var itemIndex
4288
+
4289
+ if (aItem.key) {
4290
+ if (bKeys.hasOwnProperty(aItem.key)) {
4291
+ // Match up the old keys
4292
+ itemIndex = bKeys[aItem.key]
4293
+ newChildren.push(bChildren[itemIndex])
4294
+
4295
+ } else {
4296
+ // Remove old keyed items
4297
+ itemIndex = i - deletedItems++
4298
+ newChildren.push(null)
4299
+ }
4300
+ } else {
4301
+ // Match the item in a with the next free item in b
4302
+ if (freeIndex < freeCount) {
4303
+ itemIndex = bFree[freeIndex++]
4304
+ newChildren.push(bChildren[itemIndex])
4305
+ } else {
4306
+ // There are no free items in b to match with
4307
+ // the free items in a, so the extra free nodes
4308
+ // are deleted.
4309
+ itemIndex = i - deletedItems++
4310
+ newChildren.push(null)
4311
+ }
4312
+ }
4313
+ }
4314
+
4315
+ var lastFreeIndex = freeIndex >= bFree.length ?
4316
+ bChildren.length :
4317
+ bFree[freeIndex]
4318
+
4319
+ // Iterate through b and append any new keys
4320
+ // O(M) time
4321
+ for (var j = 0; j < bChildren.length; j++) {
4322
+ var newItem = bChildren[j]
4323
+
4324
+ if (newItem.key) {
4325
+ if (!aKeys.hasOwnProperty(newItem.key)) {
4326
+ // Add any new keyed items
4327
+ // We are adding new items to the end and then sorting them
4328
+ // in place. In future we should insert new items in place.
4329
+ newChildren.push(newItem)
4330
+ }
4331
+ } else if (j >= lastFreeIndex) {
4332
+ // Add any leftover non-keyed items
4333
+ newChildren.push(newItem)
4334
+ }
4335
+ }
4336
+
4337
+ var simulate = newChildren.slice()
4338
+ var simulateIndex = 0
4339
+ var removes = []
4340
+ var inserts = []
4341
+ var simulateItem
4342
+
4343
+ for (var k = 0; k < bChildren.length;) {
4344
+ var wantedItem = bChildren[k]
4345
+ simulateItem = simulate[simulateIndex]
4346
+
4347
+ // remove items
4348
+ while (simulateItem === null && simulate.length) {
4349
+ removes.push(remove(simulate, simulateIndex, null))
4350
+ simulateItem = simulate[simulateIndex]
4351
+ }
4352
+
4353
+ if (!simulateItem || simulateItem.key !== wantedItem.key) {
4354
+ // if we need a key in this position...
4355
+ if (wantedItem.key) {
4356
+ if (simulateItem && simulateItem.key) {
4357
+ // if an insert doesn't put this key in place, it needs to move
4358
+ if (bKeys[simulateItem.key] !== k + 1) {
4359
+ removes.push(remove(simulate, simulateIndex, simulateItem.key))
4360
+ simulateItem = simulate[simulateIndex]
4361
+ // if the remove didn't put the wanted item in place, we need to insert it
4362
+ if (!simulateItem || simulateItem.key !== wantedItem.key) {
4363
+ inserts.push({key: wantedItem.key, to: k})
4364
+ }
4365
+ // items are matching, so skip ahead
4366
+ else {
4367
+ simulateIndex++
4368
+ }
4369
+ }
4370
+ else {
4371
+ inserts.push({key: wantedItem.key, to: k})
4372
+ }
4373
+ }
4374
+ else {
4375
+ inserts.push({key: wantedItem.key, to: k})
4376
+ }
4377
+ k++
4378
+ }
4379
+ // a key in simulate has no matching wanted key, remove it
4380
+ else if (simulateItem && simulateItem.key) {
4381
+ removes.push(remove(simulate, simulateIndex, simulateItem.key))
4382
+ }
4383
+ }
4384
+ else {
4385
+ simulateIndex++
4386
+ k++
4387
+ }
4388
+ }
4389
+
4390
+ // remove all the remaining nodes from simulate
4391
+ while(simulateIndex < simulate.length) {
4392
+ simulateItem = simulate[simulateIndex]
4393
+ removes.push(remove(simulate, simulateIndex, simulateItem && simulateItem.key))
4394
+ }
4395
+
4396
+ // If the only moves we have are deletes then we can just
4397
+ // let the delete patch remove these items.
4398
+ if (removes.length === deletedItems && !inserts.length) {
4399
+ return {
4400
+ children: newChildren,
4401
+ moves: null
4402
+ }
4403
+ }
4404
+
4405
+ return {
4406
+ children: newChildren,
4407
+ moves: {
4408
+ removes: removes,
4409
+ inserts: inserts
4410
+ }
4411
+ }
4412
+ }
4413
+
4414
+ function remove(arr, index, key) {
4415
+ arr.splice(index, 1)
4416
+
4417
+ return {
4418
+ from: index,
4419
+ key: key
4420
+ }
4421
+ }
4422
+
4423
+ function keyIndex(children) {
4424
+ var keys = {}
4425
+ var free = []
4426
+ var length = children.length
4427
+
4428
+ for (var i = 0; i < length; i++) {
4429
+ var child = children[i]
4430
+
4431
+ if (child.key) {
4432
+ keys[child.key] = i
4433
+ } else {
4434
+ free.push(i)
4435
+ }
4436
+ }
4437
+
4438
+ return {
4439
+ keys: keys, // A hash of key name to index
4440
+ free: free // An array of unkeyed item indices
4441
+ }
4442
+ }
4443
+
4444
+ function appendPatch(apply, patch) {
4445
+ if (apply) {
4446
+ if (isArray(apply)) {
4447
+ apply.push(patch)
4448
+ } else {
4449
+ apply = [apply, patch]
4450
+ }
4451
+
4452
+ return apply
4453
+ } else {
4454
+ return patch
4455
+ }
4456
+ }
4457
+
4458
+ },{"../vnode/handle-thunk":48,"../vnode/is-thunk":49,"../vnode/is-vnode":51,"../vnode/is-vtext":52,"../vnode/is-widget":53,"../vnode/vpatch":56,"./diff-props":58,"x-is-array":60}],60:[function(require,module,exports){
4459
+ var nativeIsArray = Array.isArray
4460
+ var toString = Object.prototype.toString
4461
+
4462
+ module.exports = nativeIsArray || isArray
4463
+
4464
+ function isArray(obj) {
4465
+ return toString.call(obj) === "[object Array]"
4466
+ }
4467
+
4468
+ },{}],61:[function(require,module,exports){
4469
+
4470
+ },{}],62:[function(require,module,exports){
4471
+ // shim for using process in browser
4472
+
4473
+ var process = module.exports = {};
4474
+ var queue = [];
4475
+ var draining = false;
4476
+ var currentQueue;
4477
+ var queueIndex = -1;
4478
+
4479
+ function cleanUpNextTick() {
4480
+ draining = false;
4481
+ if (currentQueue.length) {
4482
+ queue = currentQueue.concat(queue);
4483
+ } else {
4484
+ queueIndex = -1;
4485
+ }
4486
+ if (queue.length) {
4487
+ drainQueue();
4488
+ }
4489
+ }
4490
+
4491
+ function drainQueue() {
4492
+ if (draining) {
4493
+ return;
4494
+ }
4495
+ var timeout = setTimeout(cleanUpNextTick);
4496
+ draining = true;
4497
+
4498
+ var len = queue.length;
4499
+ while(len) {
4500
+ currentQueue = queue;
4501
+ queue = [];
4502
+ while (++queueIndex < len) {
4503
+ if (currentQueue) {
4504
+ currentQueue[queueIndex].run();
4505
+ }
4506
+ }
4507
+ queueIndex = -1;
4508
+ len = queue.length;
4509
+ }
4510
+ currentQueue = null;
4511
+ draining = false;
4512
+ clearTimeout(timeout);
4513
+ }
4514
+
4515
+ process.nextTick = function (fun) {
4516
+ var args = new Array(arguments.length - 1);
4517
+ if (arguments.length > 1) {
4518
+ for (var i = 1; i < arguments.length; i++) {
4519
+ args[i - 1] = arguments[i];
4520
+ }
4521
+ }
4522
+ queue.push(new Item(fun, args));
4523
+ if (queue.length === 1 && !draining) {
4524
+ setTimeout(drainQueue, 0);
4525
+ }
4526
+ };
4527
+
4528
+ // v8 likes predictible objects
4529
+ function Item(fun, array) {
4530
+ this.fun = fun;
4531
+ this.array = array;
4532
+ }
4533
+ Item.prototype.run = function () {
4534
+ this.fun.apply(null, this.array);
4535
+ };
4536
+ process.title = 'browser';
4537
+ process.browser = true;
4538
+ process.env = {};
4539
+ process.argv = [];
4540
+ process.version = ''; // empty string to avoid regexp issues
4541
+ process.versions = {};
4542
+
4543
+ function noop() {}
4544
+
4545
+ process.on = noop;
4546
+ process.addListener = noop;
4547
+ process.once = noop;
4548
+ process.off = noop;
4549
+ process.removeListener = noop;
4550
+ process.removeAllListeners = noop;
4551
+ process.emit = noop;
4552
+
4553
+ process.binding = function (name) {
4554
+ throw new Error('process.binding is not supported');
4555
+ };
4556
+
4557
+ process.cwd = function () { return '/' };
4558
+ process.chdir = function (dir) {
4559
+ throw new Error('process.chdir is not supported');
4560
+ };
4561
+ process.umask = function() { return 0; };
4562
+
4563
+ },{}]},{},[1])(1)
4564
+ });