1 | (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 _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; };
|
5 |
|
6 | var React = require('react');
|
7 | var ReactDOM = require('react-dom');
|
8 | var Slate = require('slate');
|
9 | var PluginEditCode = require('../lib/');
|
10 |
|
11 | var stateJson = require('./state');
|
12 |
|
13 | var plugin = PluginEditCode();
|
14 | var plugins = [plugin];
|
15 |
|
16 | var SCHEMA = {
|
17 | nodes: {
|
18 | code_block: function code_block(props) {
|
19 | return React.createElement(
|
20 | 'div',
|
21 | _extends({ className: 'code' }, props.attributes),
|
22 | props.children
|
23 | );
|
24 | },
|
25 | code_line: function code_line(props) {
|
26 | return React.createElement(
|
27 | 'pre',
|
28 | props.attributes,
|
29 | props.children
|
30 | );
|
31 | },
|
32 | paragraph: function paragraph(props) {
|
33 | return React.createElement(
|
34 | 'p',
|
35 | props.attributes,
|
36 | props.children
|
37 | );
|
38 | },
|
39 | heading: function heading(props) {
|
40 | return React.createElement(
|
41 | 'h1',
|
42 | props.attributes,
|
43 | props.children
|
44 | );
|
45 | }
|
46 | }
|
47 | };
|
48 |
|
49 | var Example = React.createClass({
|
50 | displayName: 'Example',
|
51 | getInitialState: function getInitialState() {
|
52 | return {
|
53 | state: Slate.State.fromJSON(stateJson)
|
54 | };
|
55 | },
|
56 | onChange: function onChange(_ref) {
|
57 | var state = _ref.state;
|
58 |
|
59 | this.setState({
|
60 | state: state
|
61 | });
|
62 | },
|
63 | onToggleCode: function onToggleCode() {
|
64 | var state = this.state.state;
|
65 |
|
66 |
|
67 | this.onChange(plugin.changes.toggleCodeBlock(state.change(), 'paragraph').focus());
|
68 | },
|
69 | render: function render() {
|
70 | var state = this.state.state;
|
71 |
|
72 |
|
73 | return React.createElement(
|
74 | 'div',
|
75 | null,
|
76 | React.createElement(
|
77 | 'button',
|
78 | { onClick: this.onToggleCode },
|
79 | plugin.utils.isInCodeBlock(state) ? 'Paragraph' : 'Code Block'
|
80 | ),
|
81 | React.createElement(Slate.Editor, {
|
82 | placeholder: 'Enter some text...',
|
83 | plugins: plugins,
|
84 | state: state,
|
85 | onChange: this.onChange,
|
86 | schema: SCHEMA
|
87 | })
|
88 | );
|
89 | }
|
90 | });
|
91 |
|
92 | ReactDOM.render(React.createElement(Example, null), document.getElementById('example'));
|
93 |
|
94 | },{"../lib/":14,"./state":2,"react":309,"react-dom":153,"slate":330}],2:[function(require,module,exports){
|
95 | module.exports={
|
96 | "document": {
|
97 | "nodes": [
|
98 | {
|
99 | "kind": "block",
|
100 | "type": "heading",
|
101 | "nodes": [
|
102 | {
|
103 | "kind": "text",
|
104 | "ranges": [
|
105 | {
|
106 | "text": "Slate + Code Edition"
|
107 | }
|
108 | ]
|
109 | }
|
110 | ]
|
111 | },
|
112 | {
|
113 | "kind": "block",
|
114 | "type": "paragraph",
|
115 | "nodes": [
|
116 | {
|
117 | "kind": "text",
|
118 | "ranges": [
|
119 | {
|
120 | "text": "This page is a basic example of Slate + slate-edit-code plugin. Press Tab to indent code. Shift+Tab to unindent. Press Enter to carry indentation onto the newline. Press Mod (Cmd on Mac, Ctrl on Windows) + Enter to exit the code block."
|
121 | }
|
122 | ]
|
123 | }
|
124 | ]
|
125 | },
|
126 | {
|
127 | "kind": "block",
|
128 | "type": "code_block",
|
129 | "nodes": [
|
130 | {
|
131 | "kind": "block",
|
132 | "type": "code_line",
|
133 | "nodes": [
|
134 | {
|
135 | "kind": "text",
|
136 | "ranges": [
|
137 | {
|
138 | "text": "// Some JavaScript"
|
139 | }
|
140 | ]
|
141 | }
|
142 | ]
|
143 | },
|
144 | {
|
145 | "kind": "block",
|
146 | "type": "code_line",
|
147 | "nodes": [
|
148 | {
|
149 | "kind": "text",
|
150 | "ranges": [
|
151 | {
|
152 | "text": "function hello() {"
|
153 | }
|
154 | ]
|
155 | }
|
156 | ]
|
157 | },
|
158 | {
|
159 | "kind": "block",
|
160 | "type": "code_line",
|
161 | "nodes": [
|
162 | {
|
163 | "kind": "text",
|
164 | "ranges": [
|
165 | {
|
166 | "text": " console.log('Hello World')"
|
167 | }
|
168 | ]
|
169 | }
|
170 | ]
|
171 | },
|
172 | {
|
173 | "kind": "block",
|
174 | "type": "code_line",
|
175 | "nodes": [
|
176 | {
|
177 | "kind": "text",
|
178 | "ranges": [
|
179 | {
|
180 | "text": "}"
|
181 | }
|
182 | ]
|
183 | }
|
184 | ]
|
185 | }
|
186 | ]
|
187 | },
|
188 | {
|
189 | "kind": "block",
|
190 | "type": "paragraph",
|
191 | "nodes": [
|
192 | {
|
193 | "kind": "text",
|
194 | "ranges": [
|
195 | {
|
196 | "text": "End paragraph"
|
197 | }
|
198 | ]
|
199 | }
|
200 | ]
|
201 | }
|
202 | ]
|
203 | }
|
204 | }
|
205 | },{}],3:[function(require,module,exports){
|
206 | "use strict";
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 | function dedentLines(opts, change, indent) {
|
215 | var state = change.state;
|
216 | var document = state.document,
|
217 | selection = state.selection;
|
218 |
|
219 | var lines = document.getBlocksAtRange(selection).filter(function (node) {
|
220 | return node.type === opts.lineType;
|
221 | });
|
222 |
|
223 | return lines.reduce(function (c, line) {
|
224 |
|
225 | var text = line.nodes.first();
|
226 | var lengthToRemove = text.characters.takeWhile(function (char, index) {
|
227 | return indent.charAt(index) === char.text;
|
228 | }).count();
|
229 | return c.removeTextByKey(text.key, 0, lengthToRemove);
|
230 | }, change);
|
231 | }
|
232 |
|
233 | module.exports = dedentLines;
|
234 |
|
235 | },{}],4:[function(require,module,exports){
|
236 | "use strict";
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | function indentLines(opts, change, indent) {
|
245 | var state = change.state;
|
246 | var document = state.document,
|
247 | selection = state.selection;
|
248 |
|
249 | var lines = document.getBlocksAtRange(selection).filter(function (node) {
|
250 | return node.type === opts.lineType;
|
251 | });
|
252 |
|
253 | return lines.reduce(function (c, line) {
|
254 |
|
255 | var text = line.nodes.first();
|
256 | return c.insertTextByKey(text.key, 0, indent);
|
257 | }, change);
|
258 | }
|
259 |
|
260 | module.exports = indentLines;
|
261 |
|
262 | },{}],5:[function(require,module,exports){
|
263 | 'use strict';
|
264 |
|
265 | var wrapCodeBlock = require('./wrapCodeBlock');
|
266 | var unwrapCodeBlock = require('./unwrapCodeBlock');
|
267 | var isInCodeBlock = require('../isInCodeBlock');
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 | function toggleCodeBlock(opts, change, type) {
|
276 | if (isInCodeBlock(opts, change.state)) {
|
277 | return unwrapCodeBlock(opts, change, type);
|
278 | } else {
|
279 | return wrapCodeBlock(opts, change);
|
280 | }
|
281 | }
|
282 |
|
283 | module.exports = toggleCodeBlock;
|
284 |
|
285 | },{"../isInCodeBlock":15,"./unwrapCodeBlock":6,"./wrapCodeBlock":8}],6:[function(require,module,exports){
|
286 | 'use strict';
|
287 |
|
288 | var getCurrentCode = require('../getCurrentCode');
|
289 | var unwrapCodeBlockByKey = require('./unwrapCodeBlockByKey');
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 | function unwrapCodeBlock(opts, change, type) {
|
298 | var _change = change,
|
299 | state = _change.state;
|
300 |
|
301 |
|
302 | var codeBlock = getCurrentCode(opts, state);
|
303 |
|
304 | if (!codeBlock) {
|
305 | return change;
|
306 | }
|
307 |
|
308 |
|
309 | change = unwrapCodeBlockByKey(opts, change, codeBlock.key, type);
|
310 |
|
311 | return change;
|
312 | }
|
313 |
|
314 | module.exports = unwrapCodeBlock;
|
315 |
|
316 | },{"../getCurrentCode":11,"./unwrapCodeBlockByKey":7}],7:[function(require,module,exports){
|
317 | 'use strict';
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 | function unwrapCodeBlockByKey(opts, change, key, type) {
|
328 | var state = change.state;
|
329 | var document = state.document;
|
330 |
|
331 |
|
332 |
|
333 | var codeBlock = document.getDescendant(key);
|
334 |
|
335 | if (!codeBlock || codeBlock.type != opts.containerType) {
|
336 | throw new Error('Block passed to unwrapCodeBlockByKey should be a code block container');
|
337 | }
|
338 |
|
339 |
|
340 | codeBlock.nodes.forEach(function (line) {
|
341 | return change.setNodeByKey(line.key, { type: type }).unwrapNodeByKey(line.key);
|
342 | });
|
343 |
|
344 | return change;
|
345 | }
|
346 |
|
347 | module.exports = unwrapCodeBlockByKey;
|
348 |
|
349 | },{}],8:[function(require,module,exports){
|
350 | 'use strict';
|
351 |
|
352 | var wrapCodeBlockByKey = require('./wrapCodeBlockByKey');
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 | function wrapCodeBlock(opts, change) {
|
360 | var _change = change,
|
361 | state = _change.state;
|
362 | var startBlock = state.startBlock,
|
363 | selection = state.selection;
|
364 |
|
365 |
|
366 |
|
367 | change = wrapCodeBlockByKey(opts, change, startBlock.key);
|
368 |
|
369 |
|
370 | change.collapseToStartOf(change.state.document.getDescendant(startBlock.key)).moveOffsetsTo(selection.startOffset);
|
371 |
|
372 | return change;
|
373 | }
|
374 |
|
375 | module.exports = wrapCodeBlock;
|
376 |
|
377 | },{"./wrapCodeBlockByKey":9}],9:[function(require,module,exports){
|
378 | 'use strict';
|
379 |
|
380 | var deserializeCode = require('../deserializeCode');
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 | function wrapCodeBlockByKey(opts, change, key) {
|
390 | var state = change.state;
|
391 | var document = state.document;
|
392 |
|
393 |
|
394 | var startBlock = document.getDescendant(key);
|
395 | var text = startBlock.text;
|
396 |
|
397 |
|
398 | startBlock.nodes.forEach(function (node) {
|
399 | change.removeNodeByKey(node.key, { normalize: false });
|
400 | });
|
401 |
|
402 |
|
403 | var toInsert = deserializeCode(opts, text);
|
404 |
|
405 | toInsert.nodes.forEach(function (node, i) {
|
406 | change.insertNodeByKey(startBlock.key, i, node);
|
407 | });
|
408 |
|
409 |
|
410 | change.setNodeByKey(startBlock.key, {
|
411 | type: opts.containerType
|
412 | });
|
413 |
|
414 | return change;
|
415 | }
|
416 |
|
417 | module.exports = wrapCodeBlockByKey;
|
418 |
|
419 | },{"../deserializeCode":10}],10:[function(require,module,exports){
|
420 | 'use strict';
|
421 |
|
422 | var _require = require('slate'),
|
423 | Block = _require.Block,
|
424 | Text = _require.Text;
|
425 |
|
426 | var _require2 = require('immutable'),
|
427 | List = _require2.List;
|
428 |
|
429 | var detectNewline = require('detect-newline');
|
430 |
|
431 | var DEFAULT_NEWLINE = '\n';
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 | function deserializeCode(opts, text) {
|
440 | var sep = detectNewline(text) || DEFAULT_NEWLINE;
|
441 |
|
442 | var lines = List(text.split(sep)).map(function (line) {
|
443 | return Block.create({
|
444 | type: opts.lineType,
|
445 | nodes: [Text.create(line)]
|
446 | });
|
447 | });
|
448 |
|
449 | var code = Block.create({
|
450 | type: opts.containerType,
|
451 | nodes: lines
|
452 | });
|
453 |
|
454 | return code;
|
455 | }
|
456 |
|
457 | module.exports = deserializeCode;
|
458 |
|
459 | },{"detect-newline":25,"immutable":135,"slate":330}],11:[function(require,module,exports){
|
460 | "use strict";
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 | function getCurrentCode(opts, state, key) {
|
471 | var document = state.document;
|
472 |
|
473 |
|
474 | var currentBlock = void 0;
|
475 | if (key) {
|
476 | currentBlock = state.document.getDescendant(key);
|
477 | } else {
|
478 | if (!state.selection.startKey) return null;
|
479 | currentBlock = state.startBlock;
|
480 | }
|
481 |
|
482 |
|
483 |
|
484 | var parent = document.getParent(currentBlock.key);
|
485 | if (parent && parent.type === opts.containerType) {
|
486 | return parent;
|
487 | } else {
|
488 | return null;
|
489 | }
|
490 | }
|
491 |
|
492 | module.exports = getCurrentCode;
|
493 |
|
494 | },{}],12:[function(require,module,exports){
|
495 | 'use strict';
|
496 |
|
497 | var getIndent = require('./getIndent');
|
498 | var getCurrentCode = require('./getCurrentCode');
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 | function getCurrentIndent(opts, state) {
|
507 | var currentCode = getCurrentCode(opts, state);
|
508 | var text = currentCode.getTexts().map(function (t) {
|
509 | return t.text;
|
510 | }).join('\n');
|
511 | return getIndent(text);
|
512 | }
|
513 |
|
514 | module.exports = getCurrentIndent;
|
515 |
|
516 | },{"./getCurrentCode":11,"./getIndent":13}],13:[function(require,module,exports){
|
517 | 'use strict';
|
518 |
|
519 | var detectIndent = require('detect-indent');
|
520 | var DEFAULT_INDENTATION = ' ';
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 | function getIndent(text) {
|
529 | var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INDENTATION;
|
530 |
|
531 | return detectIndent(text).indent || defaultValue;
|
532 | }
|
533 |
|
534 | module.exports = getIndent;
|
535 |
|
536 | },{"detect-indent":24}],14:[function(require,module,exports){
|
537 | 'use strict';
|
538 |
|
539 | var _require = require('slate'),
|
540 | Document = _require.Document;
|
541 |
|
542 | var onEnter = require('./onEnter');
|
543 | var onModEnter = require('./onModEnter');
|
544 | var onTab = require('./onTab');
|
545 | var onShiftTab = require('./onShiftTab');
|
546 | var onBackspace = require('./onBackspace');
|
547 | var onSelectAll = require('./onSelectAll');
|
548 | var makeSchema = require('./makeSchema');
|
549 | var getCurrentCode = require('./getCurrentCode');
|
550 | var Options = require('./options');
|
551 | var deserializeCode = require('./deserializeCode');
|
552 | var isInCodeBlock = require('./isInCodeBlock');
|
553 |
|
554 | var wrapCodeBlockByKey = require('./changes/wrapCodeBlockByKey');
|
555 | var unwrapCodeBlockByKey = require('./changes/unwrapCodeBlockByKey');
|
556 | var wrapCodeBlock = require('./changes/wrapCodeBlock');
|
557 | var unwrapCodeBlock = require('./changes/unwrapCodeBlock');
|
558 | var toggleCodeBlock = require('./changes/toggleCodeBlock');
|
559 |
|
560 | var KEY_ENTER = 'enter';
|
561 | var KEY_TAB = 'tab';
|
562 | var KEY_BACKSPACE = 'backspace';
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 | function EditCode(opts) {
|
571 | opts = new Options(opts);
|
572 |
|
573 | |
574 |
|
575 |
|
576 | function _onKeyDown(e, data, change) {
|
577 | var state = change.state;
|
578 |
|
579 | var currentCode = getCurrentCode(opts, state);
|
580 |
|
581 |
|
582 | if (!currentCode) {
|
583 | return;
|
584 | }
|
585 |
|
586 |
|
587 | var args = [e, data, change, opts];
|
588 |
|
589 |
|
590 | if (data.key === 'a' && data.isMod && opts.selectAll) {
|
591 | return onSelectAll.apply(undefined, args);
|
592 | }
|
593 |
|
594 |
|
595 | else if (data.key === KEY_TAB && data.isShift) {
|
596 | return onShiftTab.apply(undefined, args);
|
597 | }
|
598 |
|
599 |
|
600 | else if (data.key == KEY_TAB) {
|
601 | return onTab.apply(undefined, args);
|
602 | }
|
603 |
|
604 |
|
605 | else if (data.key == KEY_ENTER && data.isMod && opts.exitBlockType) {
|
606 | return onModEnter.apply(undefined, args);
|
607 | }
|
608 |
|
609 |
|
610 | else if (data.key == KEY_ENTER) {
|
611 | return onEnter.apply(undefined, args);
|
612 | }
|
613 |
|
614 |
|
615 | else if (data.key == KEY_BACKSPACE) {
|
616 | return onBackspace.apply(undefined, args);
|
617 | }
|
618 | }
|
619 |
|
620 | |
621 |
|
622 |
|
623 | function onPaste(event, data, change) {
|
624 | var state = change.state;
|
625 |
|
626 | var currentCode = getCurrentCode(opts, state);
|
627 |
|
628 |
|
629 | var endBlock = state.endBlock;
|
630 |
|
631 | if (!currentCode || !currentCode.hasDescendant(endBlock.key)) {
|
632 | return;
|
633 | }
|
634 |
|
635 |
|
636 | var text = void 0;
|
637 | if (data.type === 'fragment') {
|
638 | text = data.fragment.getTexts().map(function (t) {
|
639 | return t.text;
|
640 | }).join('\n');
|
641 | } else {
|
642 | text = data.text;
|
643 | }
|
644 |
|
645 |
|
646 | var lines = deserializeCode(opts, text).nodes;
|
647 |
|
648 | var fragment = Document.create({ nodes: lines });
|
649 |
|
650 | return change.insertFragment(fragment);
|
651 | }
|
652 |
|
653 | var schema = makeSchema(opts);
|
654 |
|
655 | return {
|
656 | onKeyDown: _onKeyDown,
|
657 | onPaste: onPaste,
|
658 |
|
659 | schema: schema,
|
660 |
|
661 | changes: {
|
662 | unwrapCodeBlockByKey: unwrapCodeBlockByKey.bind(null, opts),
|
663 | wrapCodeBlockByKey: wrapCodeBlockByKey.bind(null, opts),
|
664 | wrapCodeBlock: wrapCodeBlock.bind(null, opts),
|
665 | unwrapCodeBlock: unwrapCodeBlock.bind(null, opts),
|
666 | toggleCodeBlock: toggleCodeBlock.bind(null, opts)
|
667 | },
|
668 |
|
669 | utils: {
|
670 | isInCodeBlock: isInCodeBlock.bind(null, opts),
|
671 | deserializeCode: deserializeCode.bind(null, opts)
|
672 | }
|
673 | };
|
674 | }
|
675 |
|
676 | module.exports = EditCode;
|
677 |
|
678 | },{"./changes/toggleCodeBlock":5,"./changes/unwrapCodeBlock":6,"./changes/unwrapCodeBlockByKey":7,"./changes/wrapCodeBlock":8,"./changes/wrapCodeBlockByKey":9,"./deserializeCode":10,"./getCurrentCode":11,"./isInCodeBlock":15,"./makeSchema":16,"./onBackspace":17,"./onEnter":18,"./onModEnter":19,"./onSelectAll":20,"./onShiftTab":21,"./onTab":22,"./options":23,"slate":330}],15:[function(require,module,exports){
|
679 | "use strict";
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 | function isInCodeBlock(opts, state) {
|
687 | var document = state.document,
|
688 | startKey = state.startKey;
|
689 |
|
690 | var codeBlock = document.getClosest(startKey, function (block) {
|
691 | return block.type === opts.containerType;
|
692 | });
|
693 |
|
694 | return Boolean(codeBlock);
|
695 | }
|
696 |
|
697 | module.exports = isInCodeBlock;
|
698 |
|
699 | },{}],16:[function(require,module,exports){
|
700 | 'use strict';
|
701 |
|
702 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
703 |
|
704 | var _require = require('immutable'),
|
705 | Set = _require.Set,
|
706 | List = _require.List;
|
707 |
|
708 | var Slate = require('slate');
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 | function makeSchema(opts) {
|
716 | return {
|
717 | rules: [noOrphanLine(opts), onlyLine(opts), onlyText(opts), noMarks(opts)]
|
718 | };
|
719 | }
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 | function noOrphanLine(opts) {
|
726 |
|
727 | return {
|
728 |
|
729 | match: function match(node) {
|
730 | return (node.kind === 'block' || node.kind === 'document') && node.type !== opts.containerType;
|
731 | },
|
732 | validate: function validate(node) {
|
733 | var codeLines = node.nodes.filter(function (n) {
|
734 | return n.type === opts.lineType;
|
735 | });
|
736 |
|
737 | if (codeLines.isEmpty()) {
|
738 |
|
739 | return null;
|
740 | } else {
|
741 |
|
742 | return {
|
743 | toWrap: codeLines
|
744 | };
|
745 | }
|
746 | },
|
747 |
|
748 |
|
749 | |
750 |
|
751 |
|
752 |
|
753 | normalize: function normalize(change, node, value) {
|
754 | return value.toWrap.reduce(function (c, n) {
|
755 | return c.wrapBlockByKey(n.key, opts.containerType);
|
756 | }, change);
|
757 | }
|
758 | };
|
759 | }
|
760 |
|
761 |
|
762 |
|
763 |
|
764 | function onlyLine(opts) {
|
765 | return {
|
766 | match: function match(node) {
|
767 | return node.type === opts.containerType;
|
768 | },
|
769 |
|
770 | validate: function validate(node) {
|
771 | var nodes = node.nodes;
|
772 |
|
773 |
|
774 | var toWrap = [];
|
775 | var toRemove = [];
|
776 |
|
777 | nodes.forEach(function (child) {
|
778 | if (child.kind === 'text') toWrap.push(child);else if (child.type !== opts.lineType) toRemove.push(child);
|
779 | });
|
780 |
|
781 | if (toWrap.length || toRemove.length) {
|
782 | return { toWrap: toWrap, toRemove: toRemove };
|
783 | } else {
|
784 | return null;
|
785 | }
|
786 | },
|
787 | normalize: function normalize(change, node, _ref) {
|
788 | var toWrap = _ref.toWrap,
|
789 | toRemove = _ref.toRemove;
|
790 |
|
791 | toRemove.forEach(function (child) {
|
792 | change.removeNodeByKey(child.key);
|
793 | });
|
794 |
|
795 | toWrap.forEach(function (child) {
|
796 | change.wrapBlockByKey(child.key, opts.lineType);
|
797 | });
|
798 |
|
799 |
|
800 |
|
801 | return applyRule(noMarks(opts), change, node.key);
|
802 | }
|
803 | };
|
804 | }
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 | function onlyText(opts) {
|
811 | return {
|
812 | match: function match(node) {
|
813 | return node.type === opts.lineType;
|
814 | },
|
815 |
|
816 | validate: function validate(node) {
|
817 | var nodes = node.nodes;
|
818 |
|
819 |
|
820 | var toRemove = nodes.filterNot(function (n) {
|
821 | return n.kind === 'text';
|
822 | });
|
823 | if (!toRemove.isEmpty()) {
|
824 |
|
825 |
|
826 | return { toRemove: toRemove };
|
827 | }
|
828 |
|
829 |
|
830 | else if (nodes.size > 1) {
|
831 | return { toJoin: nodes };
|
832 | } else if (nodes.size === 0) {
|
833 | return { toAdd: [Slate.Text.create()] };
|
834 | } else {
|
835 |
|
836 | return null;
|
837 | }
|
838 | },
|
839 |
|
840 |
|
841 | |
842 |
|
843 |
|
844 | normalize: function normalize(change, node, _ref2) {
|
845 | var _ref2$toRemove = _ref2.toRemove,
|
846 | toRemove = _ref2$toRemove === undefined ? List() : _ref2$toRemove,
|
847 | _ref2$toAdd = _ref2.toAdd,
|
848 | toAdd = _ref2$toAdd === undefined ? List() : _ref2$toAdd,
|
849 | _ref2$toJoin = _ref2.toJoin,
|
850 | toJoin = _ref2$toJoin === undefined ? List() : _ref2$toJoin;
|
851 |
|
852 |
|
853 | toRemove.reduce(function (c, child) {
|
854 | return c.removeNodeByKey(child.key, { normalize: false });
|
855 | }, change);
|
856 |
|
857 |
|
858 | var pairs = toJoin.butLast().map(function (child, index) {
|
859 | return [child.key, toJoin.get(index + 1).key];
|
860 | });
|
861 |
|
862 |
|
863 | pairs.reverse().reduce(function (c, _ref3) {
|
864 | var _ref4 = _slicedToArray(_ref3, 2),
|
865 | childKey = _ref4[0],
|
866 | nextChildKey = _ref4[1];
|
867 |
|
868 | return c.joinNodeByKey(nextChildKey, childKey, { normalize: false });
|
869 | }, change);
|
870 |
|
871 |
|
872 | toAdd.reduce(function (c, child) {
|
873 | return c.insertNodeByKey(node.key, 0, child);
|
874 | }, change);
|
875 |
|
876 | return change;
|
877 | }
|
878 | };
|
879 | }
|
880 |
|
881 |
|
882 |
|
883 |
|
884 | function noMarks(opts) {
|
885 | return {
|
886 |
|
887 | match: function match(node) {
|
888 | return node.type === opts.lineType;
|
889 | },
|
890 |
|
891 | validate: function validate(node) {
|
892 | if (opts.allowMarks) return null;
|
893 |
|
894 | var marks = getMarks(node);
|
895 |
|
896 | if (marks.isEmpty()) {
|
897 | return null;
|
898 | } else {
|
899 | return {
|
900 | removeMarks: marks
|
901 | };
|
902 | }
|
903 | },
|
904 |
|
905 |
|
906 | |
907 |
|
908 |
|
909 |
|
910 | normalize: function normalize(change, node, _ref5) {
|
911 | var removeMarks = _ref5.removeMarks;
|
912 |
|
913 | var selection = change.state.selection;
|
914 | var range = selection.moveToRangeOf(node);
|
915 |
|
916 | return removeMarks.reduce(function (c, mark) {
|
917 | return c.removeMarkAtRange(range, mark);
|
918 | }, change);
|
919 | }
|
920 | };
|
921 | }
|
922 |
|
923 |
|
924 |
|
925 |
|
926 |
|
927 | function getMarks(node) {
|
928 | var texts = node.getTexts();
|
929 |
|
930 | var marks = texts.reduce(function (all, text) {
|
931 | return text.characters.reduce(function (accu, chars) {
|
932 | return accu.union(chars.marks);
|
933 | }, all);
|
934 | }, new Set());
|
935 |
|
936 | return marks;
|
937 | }
|
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 |
|
945 |
|
946 | function applyRule(rule, change, key) {
|
947 | var node = change.state.document.getDescendant(key);
|
948 | var notValid = rule.validate(node);
|
949 | if (notValid) {
|
950 | rule.normalize(change, node, notValid);
|
951 | }
|
952 |
|
953 | return change;
|
954 | }
|
955 |
|
956 | module.exports = makeSchema;
|
957 |
|
958 | },{"immutable":135,"slate":330}],17:[function(require,module,exports){
|
959 | 'use strict';
|
960 |
|
961 | var endsWith = require('ends-with');
|
962 |
|
963 | var getCurrentIndent = require('./getCurrentIndent');
|
964 | var getCurrentCode = require('./getCurrentCode');
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 | function onBackspace(event, data, change, opts) {
|
971 | var state = change.state;
|
972 |
|
973 | if (state.isExpanded) {
|
974 | return;
|
975 | }
|
976 |
|
977 | var startOffset = state.startOffset,
|
978 | startText = state.startText;
|
979 |
|
980 |
|
981 | var currentLine = state.startBlock;
|
982 |
|
983 |
|
984 | var indent = getCurrentIndent(opts, state);
|
985 | var beforeSelection = currentLine.text.slice(0, startOffset);
|
986 |
|
987 |
|
988 | if (endsWith(beforeSelection, indent)) {
|
989 |
|
990 | event.preventDefault();
|
991 |
|
992 | return change.deleteBackward(indent.length).focus();
|
993 | }
|
994 |
|
995 |
|
996 | else if (opts.exitBlockType) {
|
997 | var currentCode = getCurrentCode(opts, state);
|
998 | var isStartOfCode = startOffset === 0 && currentCode.getFirstText() === startText;
|
999 |
|
1000 | var isEmpty = currentCode.nodes.size === 1 && currentLine.text.length === 0;
|
1001 |
|
1002 | if (isStartOfCode && isEmpty) {
|
1003 |
|
1004 | event.preventDefault();
|
1005 |
|
1006 | return change.setBlock(opts.exitBlockType).unwrapNodeByKey(currentLine.key);
|
1007 | }
|
1008 | }
|
1009 | }
|
1010 |
|
1011 | module.exports = onBackspace;
|
1012 |
|
1013 | },{"./getCurrentCode":11,"./getCurrentIndent":12,"ends-with":27}],18:[function(require,module,exports){
|
1014 | 'use strict';
|
1015 |
|
1016 | var getIndent = require('./getIndent');
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 | function onEnter(event, data, change, opts) {
|
1023 | var state = change.state;
|
1024 |
|
1025 | if (!state.isCollapsed) {
|
1026 | return;
|
1027 | }
|
1028 |
|
1029 | event.preventDefault();
|
1030 |
|
1031 | var startBlock = state.startBlock;
|
1032 |
|
1033 | var currentLineText = startBlock.text;
|
1034 | var indent = getIndent(currentLineText, '');
|
1035 |
|
1036 | return change.splitBlock().insertText(indent).focus();
|
1037 | }
|
1038 |
|
1039 | module.exports = onEnter;
|
1040 |
|
1041 | },{"./getIndent":13}],19:[function(require,module,exports){
|
1042 | "use strict";
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 | function onModEnter(event, data, change, opts) {
|
1049 | var state = change.state;
|
1050 |
|
1051 | if (!state.isCollapsed) {
|
1052 | return;
|
1053 | }
|
1054 |
|
1055 | event.preventDefault();
|
1056 |
|
1057 |
|
1058 | return opts.onExit(change, opts);
|
1059 | }
|
1060 |
|
1061 | module.exports = onModEnter;
|
1062 |
|
1063 | },{}],20:[function(require,module,exports){
|
1064 | 'use strict';
|
1065 |
|
1066 | var getCurrentCode = require('./getCurrentCode');
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 | function onSelectAll(event, data, change, opts) {
|
1072 | var state = change.state;
|
1073 |
|
1074 | event.preventDefault();
|
1075 |
|
1076 | var currentCode = getCurrentCode(opts, state);
|
1077 | return change.collapseToStartOf(currentCode.getFirstText()).extendToEndOf(currentCode.getLastText());
|
1078 | }
|
1079 |
|
1080 | module.exports = onSelectAll;
|
1081 |
|
1082 | },{"./getCurrentCode":11}],21:[function(require,module,exports){
|
1083 | 'use strict';
|
1084 |
|
1085 | var getCurrentIndent = require('./getCurrentIndent');
|
1086 | var dedentLines = require('./changes/dedentLines');
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 | function onShiftTab(event, data, change, opts) {
|
1093 | var state = change.state;
|
1094 |
|
1095 | event.preventDefault();
|
1096 | event.stopPropagation();
|
1097 |
|
1098 | var indent = getCurrentIndent(opts, state);
|
1099 |
|
1100 |
|
1101 | return dedentLines(opts, change, indent);
|
1102 | }
|
1103 |
|
1104 | module.exports = onShiftTab;
|
1105 |
|
1106 | },{"./changes/dedentLines":3,"./getCurrentIndent":12}],22:[function(require,module,exports){
|
1107 | 'use strict';
|
1108 |
|
1109 | var getCurrentIndent = require('./getCurrentIndent');
|
1110 | var indentLines = require('./changes/indentLines');
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 | function onTab(event, data, change, opts) {
|
1117 | var state = change.state;
|
1118 |
|
1119 | event.preventDefault();
|
1120 | event.stopPropagation();
|
1121 |
|
1122 | var isCollapsed = state.isCollapsed;
|
1123 |
|
1124 | var indent = getCurrentIndent(opts, state);
|
1125 |
|
1126 |
|
1127 | if (isCollapsed) {
|
1128 | return change.insertText(indent).focus();
|
1129 | }
|
1130 |
|
1131 |
|
1132 | return indentLines(opts, change, indent);
|
1133 | }
|
1134 |
|
1135 | module.exports = onTab;
|
1136 |
|
1137 | },{"./changes/indentLines":4,"./getCurrentIndent":12}],23:[function(require,module,exports){
|
1138 | 'use strict';
|
1139 |
|
1140 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
1141 |
|
1142 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
1143 |
|
1144 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
1145 |
|
1146 | var _require = require('immutable'),
|
1147 | Record = _require.Record;
|
1148 |
|
1149 | var DEFAULTS = {
|
1150 |
|
1151 | containerType: 'code_block',
|
1152 |
|
1153 | lineType: 'code_line',
|
1154 |
|
1155 |
|
1156 |
|
1157 | exitBlockType: 'paragraph',
|
1158 |
|
1159 | selectAll: true,
|
1160 |
|
1161 | allowMarks: false,
|
1162 |
|
1163 |
|
1164 | onExit: function onExit(change, options) {
|
1165 |
|
1166 | change.insertBlock({ type: options.exitBlockType });
|
1167 |
|
1168 | var inserted = change.state.startBlock;
|
1169 | return change.unwrapNodeByKey(inserted.key);
|
1170 | }
|
1171 | };
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 | var Options = function (_ref) {
|
1178 | _inherits(Options, _ref);
|
1179 |
|
1180 | function Options() {
|
1181 | _classCallCheck(this, Options);
|
1182 |
|
1183 | return _possibleConstructorReturn(this, (Options.__proto__ || Object.getPrototypeOf(Options)).apply(this, arguments));
|
1184 | }
|
1185 |
|
1186 | return Options;
|
1187 | }(new Record(DEFAULTS));
|
1188 |
|
1189 | module.exports = Options;
|
1190 |
|
1191 | },{"immutable":135}],24:[function(require,module,exports){
|
1192 |
|
1193 | 'use strict';
|
1194 | var repeating = require('repeating');
|
1195 |
|
1196 |
|
1197 |
|
1198 | var INDENT_RE = /^(?:( )+|\t+)/;
|
1199 |
|
1200 | function getMostUsed(indents) {
|
1201 | var result = 0;
|
1202 | var maxUsed = 0;
|
1203 | var maxWeight = 0;
|
1204 |
|
1205 | for (var n in indents) {
|
1206 | var indent = indents[n];
|
1207 | var u = indent[0];
|
1208 | var w = indent[1];
|
1209 |
|
1210 | if (u > maxUsed || u === maxUsed && w > maxWeight) {
|
1211 | maxUsed = u;
|
1212 | maxWeight = w;
|
1213 | result = Number(n);
|
1214 | }
|
1215 | }
|
1216 |
|
1217 | return result;
|
1218 | }
|
1219 |
|
1220 | module.exports = function (str) {
|
1221 | if (typeof str !== 'string') {
|
1222 | throw new TypeError('Expected a string');
|
1223 | }
|
1224 |
|
1225 |
|
1226 | var tabs = 0;
|
1227 | var spaces = 0;
|
1228 |
|
1229 |
|
1230 | var prev = 0;
|
1231 |
|
1232 |
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 | var indents = {};
|
1242 |
|
1243 |
|
1244 | var current;
|
1245 |
|
1246 |
|
1247 | var isIndent;
|
1248 |
|
1249 | str.split(/\n/g).forEach(function (line) {
|
1250 | if (!line) {
|
1251 |
|
1252 | return;
|
1253 | }
|
1254 |
|
1255 | var indent;
|
1256 | var matches = line.match(INDENT_RE);
|
1257 |
|
1258 | if (!matches) {
|
1259 | indent = 0;
|
1260 | } else {
|
1261 | indent = matches[0].length;
|
1262 |
|
1263 | if (matches[1]) {
|
1264 | spaces++;
|
1265 | } else {
|
1266 | tabs++;
|
1267 | }
|
1268 | }
|
1269 |
|
1270 | var diff = indent - prev;
|
1271 | prev = indent;
|
1272 |
|
1273 | if (diff) {
|
1274 |
|
1275 |
|
1276 | isIndent = diff > 0;
|
1277 |
|
1278 | current = indents[isIndent ? diff : -diff];
|
1279 |
|
1280 | if (current) {
|
1281 | current[0]++;
|
1282 | } else {
|
1283 | current = indents[diff] = [1, 0];
|
1284 | }
|
1285 | } else if (current) {
|
1286 |
|
1287 | current[1] += Number(isIndent);
|
1288 | }
|
1289 | });
|
1290 |
|
1291 | var amount = getMostUsed(indents);
|
1292 |
|
1293 | var type;
|
1294 | var actual;
|
1295 | if (!amount) {
|
1296 | type = null;
|
1297 | actual = '';
|
1298 | } else if (spaces >= tabs) {
|
1299 | type = 'space';
|
1300 | actual = repeating(' ', amount);
|
1301 | } else {
|
1302 | type = 'tab';
|
1303 | actual = repeating('\t', amount);
|
1304 | }
|
1305 |
|
1306 | return {
|
1307 | amount: amount,
|
1308 | type: type,
|
1309 | indent: actual
|
1310 | };
|
1311 | };
|
1312 |
|
1313 | },{"repeating":310}],25:[function(require,module,exports){
|
1314 | 'use strict';
|
1315 | module.exports = function (str) {
|
1316 | if (typeof str !== 'string') {
|
1317 | throw new TypeError('Expected a string');
|
1318 | }
|
1319 |
|
1320 | var newlines = (str.match(/(?:\r?\n)/g) || []);
|
1321 |
|
1322 | if (newlines.length === 0) {
|
1323 | return null;
|
1324 | }
|
1325 |
|
1326 | var crlf = newlines.filter(function (el) {
|
1327 | return el === '\r\n';
|
1328 | }).length;
|
1329 |
|
1330 | var lf = newlines.length - crlf;
|
1331 |
|
1332 | return crlf > lf ? '\r\n' : '\n';
|
1333 | };
|
1334 |
|
1335 | module.exports.graceful = function (str) {
|
1336 | return module.exports(str) || '\n';
|
1337 | };
|
1338 |
|
1339 | },{}],26:[function(require,module,exports){
|
1340 | 'use strict';
|
1341 |
|
1342 | var GROUP_LEFT_TO_RIGHT,
|
1343 | GROUP_RIGHT_TO_LEFT,
|
1344 | EXPRESSION_LEFT_TO_RIGHT,
|
1345 | EXPRESSION_RIGHT_TO_LEFT;
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 | GROUP_LEFT_TO_RIGHT = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6' +
|
1352 | '\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u200E\u2C00-\uFB1C' +
|
1353 | '\uFE00-\uFE6F\uFEFD-\uFFFF';
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 | GROUP_RIGHT_TO_LEFT = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC';
|
1360 |
|
1361 |
|
1362 |
|
1363 |
|
1364 |
|
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 | EXPRESSION_LEFT_TO_RIGHT = new RegExp(
|
1370 | '^[^' + GROUP_RIGHT_TO_LEFT + ']*[' + GROUP_LEFT_TO_RIGHT + ']'
|
1371 | );
|
1372 |
|
1373 |
|
1374 |
|
1375 |
|
1376 |
|
1377 |
|
1378 |
|
1379 |
|
1380 |
|
1381 | EXPRESSION_RIGHT_TO_LEFT = new RegExp(
|
1382 | '^[^' + GROUP_LEFT_TO_RIGHT + ']*[' + GROUP_RIGHT_TO_LEFT + ']'
|
1383 | );
|
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 |
|
1389 |
|
1390 |
|
1391 |
|
1392 | function direction(value) {
|
1393 | value = value.toString();
|
1394 |
|
1395 | if (EXPRESSION_RIGHT_TO_LEFT.test(value)) {
|
1396 | return 'rtl';
|
1397 | }
|
1398 |
|
1399 | if (EXPRESSION_LEFT_TO_RIGHT.test(value)) {
|
1400 | return 'ltr';
|
1401 | }
|
1402 |
|
1403 | return 'neutral';
|
1404 | }
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 | module.exports = direction;
|
1411 |
|
1412 | },{}],27:[function(require,module,exports){
|
1413 |
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 | 'use strict';
|
1421 |
|
1422 | module.exports = function (a, b) {
|
1423 | if (Array.isArray(a)) {
|
1424 | return a[a.length - 1] === b;
|
1425 | }
|
1426 |
|
1427 | a = String(a);
|
1428 | b = String(b);
|
1429 |
|
1430 | var i = b.length;
|
1431 | var len = a.length - i;
|
1432 |
|
1433 | while (i--) {
|
1434 | if (b.charAt(i) !== a.charAt(len + i)) {
|
1435 | return false;
|
1436 | }
|
1437 | }
|
1438 | return true;
|
1439 | };
|
1440 | },{}],28:[function(require,module,exports){
|
1441 | 'use strict';
|
1442 |
|
1443 | module.exports = require('./is-implemented')() ? Map : require('./polyfill');
|
1444 |
|
1445 | },{"./is-implemented":29,"./polyfill":107}],29:[function(require,module,exports){
|
1446 | 'use strict';
|
1447 |
|
1448 | module.exports = function () {
|
1449 | var map, iterator, result;
|
1450 | if (typeof Map !== 'function') return false;
|
1451 | try {
|
1452 |
|
1453 | map = new Map([['raz', 'one'], ['dwa', 'two'], ['trzy', 'three']]);
|
1454 | } catch (e) {
|
1455 | return false;
|
1456 | }
|
1457 | if (String(map) !== '[object Map]') return false;
|
1458 | if (map.size !== 3) return false;
|
1459 | if (typeof map.clear !== 'function') return false;
|
1460 | if (typeof map.delete !== 'function') return false;
|
1461 | if (typeof map.entries !== 'function') return false;
|
1462 | if (typeof map.forEach !== 'function') return false;
|
1463 | if (typeof map.get !== 'function') return false;
|
1464 | if (typeof map.has !== 'function') return false;
|
1465 | if (typeof map.keys !== 'function') return false;
|
1466 | if (typeof map.set !== 'function') return false;
|
1467 | if (typeof map.values !== 'function') return false;
|
1468 |
|
1469 | iterator = map.entries();
|
1470 | result = iterator.next();
|
1471 | if (result.done !== false) return false;
|
1472 | if (!result.value) return false;
|
1473 | if (result.value[0] !== 'raz') return false;
|
1474 | if (result.value[1] !== 'one') return false;
|
1475 |
|
1476 | return true;
|
1477 | };
|
1478 |
|
1479 | },{}],30:[function(require,module,exports){
|
1480 |
|
1481 |
|
1482 |
|
1483 | 'use strict';
|
1484 |
|
1485 | module.exports = (function () {
|
1486 | if (typeof Map === 'undefined') return false;
|
1487 | return (Object.prototype.toString.call(new Map()) === '[object Map]');
|
1488 | }());
|
1489 |
|
1490 | },{}],31:[function(require,module,exports){
|
1491 | 'use strict';
|
1492 |
|
1493 | module.exports = require('es5-ext/object/primitive-set')('key',
|
1494 | 'value', 'key+value');
|
1495 |
|
1496 | },{"es5-ext/object/primitive-set":84}],32:[function(require,module,exports){
|
1497 | 'use strict';
|
1498 |
|
1499 | var setPrototypeOf = require('es5-ext/object/set-prototype-of')
|
1500 | , d = require('d')
|
1501 | , Iterator = require('es6-iterator')
|
1502 | , toStringTagSymbol = require('es6-symbol').toStringTag
|
1503 | , kinds = require('./iterator-kinds')
|
1504 |
|
1505 | , defineProperties = Object.defineProperties
|
1506 | , unBind = Iterator.prototype._unBind
|
1507 | , MapIterator;
|
1508 |
|
1509 | MapIterator = module.exports = function (map, kind) {
|
1510 | if (!(this instanceof MapIterator)) return new MapIterator(map, kind);
|
1511 | Iterator.call(this, map.__mapKeysData__, map);
|
1512 | if (!kind || !kinds[kind]) kind = 'key+value';
|
1513 | defineProperties(this, {
|
1514 | __kind__: d('', kind),
|
1515 | __values__: d('w', map.__mapValuesData__)
|
1516 | });
|
1517 | };
|
1518 | if (setPrototypeOf) setPrototypeOf(MapIterator, Iterator);
|
1519 |
|
1520 | MapIterator.prototype = Object.create(Iterator.prototype, {
|
1521 | constructor: d(MapIterator),
|
1522 | _resolve: d(function (i) {
|
1523 | if (this.__kind__ === 'value') return this.__values__[i];
|
1524 | if (this.__kind__ === 'key') return this.__list__[i];
|
1525 | return [this.__list__[i], this.__values__[i]];
|
1526 | }),
|
1527 | _unBind: d(function () {
|
1528 | this.__values__ = null;
|
1529 | unBind.call(this);
|
1530 | }),
|
1531 | toString: d(function () { return '[object Map Iterator]'; })
|
1532 | });
|
1533 | Object.defineProperty(MapIterator.prototype, toStringTagSymbol,
|
1534 | d('c', 'Map Iterator'));
|
1535 |
|
1536 | },{"./iterator-kinds":31,"d":34,"es5-ext/object/set-prototype-of":85,"es6-iterator":97,"es6-symbol":101}],33:[function(require,module,exports){
|
1537 | 'use strict';
|
1538 |
|
1539 | var copy = require('es5-ext/object/copy')
|
1540 | , normalizeOptions = require('es5-ext/object/normalize-options')
|
1541 | , ensureCallable = require('es5-ext/object/valid-callable')
|
1542 | , map = require('es5-ext/object/map')
|
1543 | , callable = require('es5-ext/object/valid-callable')
|
1544 | , validValue = require('es5-ext/object/valid-value')
|
1545 |
|
1546 | , bind = Function.prototype.bind, defineProperty = Object.defineProperty
|
1547 | , hasOwnProperty = Object.prototype.hasOwnProperty
|
1548 | , define;
|
1549 |
|
1550 | define = function (name, desc, options) {
|
1551 | var value = validValue(desc) && callable(desc.value), dgs;
|
1552 | dgs = copy(desc);
|
1553 | delete dgs.writable;
|
1554 | delete dgs.value;
|
1555 | dgs.get = function () {
|
1556 | if (!options.overwriteDefinition && hasOwnProperty.call(this, name)) return value;
|
1557 | desc.value = bind.call(value, options.resolveContext ? options.resolveContext(this) : this);
|
1558 | defineProperty(this, name, desc);
|
1559 | return this[name];
|
1560 | };
|
1561 | return dgs;
|
1562 | };
|
1563 |
|
1564 | module.exports = function (props/*, options*/) {
|
1565 | var options = normalizeOptions(arguments[1]);
|
1566 | if (options.resolveContext != null) ensureCallable(options.resolveContext);
|
1567 | return map(props, function (desc, name) { return define(name, desc, options); });
|
1568 | };
|
1569 |
|
1570 | },{"es5-ext/object/copy":73,"es5-ext/object/map":82,"es5-ext/object/normalize-options":83,"es5-ext/object/valid-callable":88,"es5-ext/object/valid-value":89}],34:[function(require,module,exports){
|
1571 | 'use strict';
|
1572 |
|
1573 | var assign = require('es5-ext/object/assign')
|
1574 | , normalizeOpts = require('es5-ext/object/normalize-options')
|
1575 | , isCallable = require('es5-ext/object/is-callable')
|
1576 | , contains = require('es5-ext/string/#/contains')
|
1577 |
|
1578 | , d;
|
1579 |
|
1580 | d = module.exports = function (dscr, value/*, options*/) {
|
1581 | var c, e, w, options, desc;
|
1582 | if ((arguments.length < 2) || (typeof dscr !== 'string')) {
|
1583 | options = value;
|
1584 | value = dscr;
|
1585 | dscr = null;
|
1586 | } else {
|
1587 | options = arguments[2];
|
1588 | }
|
1589 | if (dscr == null) {
|
1590 | c = w = true;
|
1591 | e = false;
|
1592 | } else {
|
1593 | c = contains.call(dscr, 'c');
|
1594 | e = contains.call(dscr, 'e');
|
1595 | w = contains.call(dscr, 'w');
|
1596 | }
|
1597 |
|
1598 | desc = { value: value, configurable: c, enumerable: e, writable: w };
|
1599 | return !options ? desc : assign(normalizeOpts(options), desc);
|
1600 | };
|
1601 |
|
1602 | d.gs = function (dscr, get, set/*, options*/) {
|
1603 | var c, e, options, desc;
|
1604 | if (typeof dscr !== 'string') {
|
1605 | options = set;
|
1606 | set = get;
|
1607 | get = dscr;
|
1608 | dscr = null;
|
1609 | } else {
|
1610 | options = arguments[3];
|
1611 | }
|
1612 | if (get == null) {
|
1613 | get = undefined;
|
1614 | } else if (!isCallable(get)) {
|
1615 | options = get;
|
1616 | get = set = undefined;
|
1617 | } else if (set == null) {
|
1618 | set = undefined;
|
1619 | } else if (!isCallable(set)) {
|
1620 | options = set;
|
1621 | set = undefined;
|
1622 | }
|
1623 | if (dscr == null) {
|
1624 | c = true;
|
1625 | e = false;
|
1626 | } else {
|
1627 | c = contains.call(dscr, 'c');
|
1628 | e = contains.call(dscr, 'e');
|
1629 | }
|
1630 |
|
1631 | desc = { get: get, set: set, configurable: c, enumerable: e };
|
1632 | return !options ? desc : assign(normalizeOpts(options), desc);
|
1633 | };
|
1634 |
|
1635 | },{"es5-ext/object/assign":70,"es5-ext/object/is-callable":76,"es5-ext/object/normalize-options":83,"es5-ext/string/#/contains":90}],35:[function(require,module,exports){
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 | "use strict";
|
1641 |
|
1642 | var value = require("../../object/valid-value");
|
1643 |
|
1644 | module.exports = function () {
|
1645 | value(this).length = 0;
|
1646 | return this;
|
1647 | };
|
1648 |
|
1649 | },{"../../object/valid-value":89}],36:[function(require,module,exports){
|
1650 | "use strict";
|
1651 |
|
1652 | var numberIsNaN = require("../../number/is-nan")
|
1653 | , toPosInt = require("../../number/to-pos-integer")
|
1654 | , value = require("../../object/valid-value")
|
1655 | , indexOf = Array.prototype.indexOf
|
1656 | , objHasOwnProperty = Object.prototype.hasOwnProperty
|
1657 | , abs = Math.abs
|
1658 | , floor = Math.floor;
|
1659 |
|
1660 | module.exports = function (searchElement /*, fromIndex*/) {
|
1661 | var i, length, fromIndex, val;
|
1662 | if (!numberIsNaN(searchElement)) return indexOf.apply(this, arguments);
|
1663 |
|
1664 | length = toPosInt(value(this).length);
|
1665 | fromIndex = arguments[1];
|
1666 | if (isNaN(fromIndex)) fromIndex = 0;
|
1667 | else if (fromIndex >= 0) fromIndex = floor(fromIndex);
|
1668 | else fromIndex = toPosInt(this.length) - floor(abs(fromIndex));
|
1669 |
|
1670 | for (i = fromIndex; i < length; ++i) {
|
1671 | if (objHasOwnProperty.call(this, i)) {
|
1672 | val = this[i];
|
1673 | if (numberIsNaN(val)) return i;
|
1674 | }
|
1675 | }
|
1676 | return -1;
|
1677 | };
|
1678 |
|
1679 | },{"../../number/is-nan":64,"../../number/to-pos-integer":68,"../../object/valid-value":89}],37:[function(require,module,exports){
|
1680 | "use strict";
|
1681 |
|
1682 | module.exports = require("./is-implemented")()
|
1683 | ? Array.from
|
1684 | : require("./shim");
|
1685 |
|
1686 | },{"./is-implemented":38,"./shim":39}],38:[function(require,module,exports){
|
1687 | "use strict";
|
1688 |
|
1689 | module.exports = function () {
|
1690 | var from = Array.from, arr, result;
|
1691 | if (typeof from !== "function") return false;
|
1692 | arr = ["raz", "dwa"];
|
1693 | result = from(arr);
|
1694 | return Boolean(result && (result !== arr) && (result[1] === "dwa"));
|
1695 | };
|
1696 |
|
1697 | },{}],39:[function(require,module,exports){
|
1698 | "use strict";
|
1699 |
|
1700 | var iteratorSymbol = require("es6-symbol").iterator
|
1701 | , isArguments = require("../../function/is-arguments")
|
1702 | , isFunction = require("../../function/is-function")
|
1703 | , toPosInt = require("../../number/to-pos-integer")
|
1704 | , callable = require("../../object/valid-callable")
|
1705 | , validValue = require("../../object/valid-value")
|
1706 | , isValue = require("../../object/is-value")
|
1707 | , isString = require("../../string/is-string")
|
1708 | , isArray = Array.isArray
|
1709 | , call = Function.prototype.call
|
1710 | , desc = { configurable: true, enumerable: true, writable: true, value: null }
|
1711 | , defineProperty = Object.defineProperty;
|
1712 |
|
1713 |
|
1714 | module.exports = function (arrayLike /*, mapFn, thisArg*/) {
|
1715 | var mapFn = arguments[1]
|
1716 | , thisArg = arguments[2]
|
1717 | , Context
|
1718 | , i
|
1719 | , j
|
1720 | , arr
|
1721 | , length
|
1722 | , code
|
1723 | , iterator
|
1724 | , result
|
1725 | , getIterator
|
1726 | , value;
|
1727 |
|
1728 | arrayLike = Object(validValue(arrayLike));
|
1729 |
|
1730 | if (isValue(mapFn)) callable(mapFn);
|
1731 | if (!this || this === Array || !isFunction(this)) {
|
1732 |
|
1733 | if (!mapFn) {
|
1734 | if (isArguments(arrayLike)) {
|
1735 |
|
1736 | length = arrayLike.length;
|
1737 | if (length !== 1) return Array.apply(null, arrayLike);
|
1738 | arr = new Array(1);
|
1739 | arr[0] = arrayLike[0];
|
1740 | return arr;
|
1741 | }
|
1742 | if (isArray(arrayLike)) {
|
1743 |
|
1744 | arr = new Array(length = arrayLike.length);
|
1745 | for (i = 0; i < length; ++i) arr[i] = arrayLike[i];
|
1746 | return arr;
|
1747 | }
|
1748 | }
|
1749 | arr = [];
|
1750 | } else {
|
1751 |
|
1752 | Context = this;
|
1753 | }
|
1754 |
|
1755 | if (!isArray(arrayLike)) {
|
1756 | if ((getIterator = arrayLike[iteratorSymbol]) !== undefined) {
|
1757 |
|
1758 | iterator = callable(getIterator).call(arrayLike);
|
1759 | if (Context) arr = new Context();
|
1760 | result = iterator.next();
|
1761 | i = 0;
|
1762 | while (!result.done) {
|
1763 | value = mapFn ? call.call(mapFn, thisArg, result.value, i) : result.value;
|
1764 | if (Context) {
|
1765 | desc.value = value;
|
1766 | defineProperty(arr, i, desc);
|
1767 | } else {
|
1768 | arr[i] = value;
|
1769 | }
|
1770 | result = iterator.next();
|
1771 | ++i;
|
1772 | }
|
1773 | length = i;
|
1774 | } else if (isString(arrayLike)) {
|
1775 |
|
1776 | length = arrayLike.length;
|
1777 | if (Context) arr = new Context();
|
1778 | for (i = 0, j = 0; i < length; ++i) {
|
1779 | value = arrayLike[i];
|
1780 | if (i + 1 < length) {
|
1781 | code = value.charCodeAt(0);
|
1782 |
|
1783 | if (code >= 0xd800 && code <= 0xdbff) value += arrayLike[++i];
|
1784 | }
|
1785 | value = mapFn ? call.call(mapFn, thisArg, value, j) : value;
|
1786 | if (Context) {
|
1787 | desc.value = value;
|
1788 | defineProperty(arr, j, desc);
|
1789 | } else {
|
1790 | arr[j] = value;
|
1791 | }
|
1792 | ++j;
|
1793 | }
|
1794 | length = j;
|
1795 | }
|
1796 | }
|
1797 | if (length === undefined) {
|
1798 |
|
1799 | length = toPosInt(arrayLike.length);
|
1800 | if (Context) arr = new Context(length);
|
1801 | for (i = 0; i < length; ++i) {
|
1802 | value = mapFn ? call.call(mapFn, thisArg, arrayLike[i], i) : arrayLike[i];
|
1803 | if (Context) {
|
1804 | desc.value = value;
|
1805 | defineProperty(arr, i, desc);
|
1806 | } else {
|
1807 | arr[i] = value;
|
1808 | }
|
1809 | }
|
1810 | }
|
1811 | if (Context) {
|
1812 | desc.value = null;
|
1813 | arr.length = length;
|
1814 | }
|
1815 | return arr;
|
1816 | };
|
1817 |
|
1818 | },{"../../function/is-arguments":40,"../../function/is-function":41,"../../number/to-pos-integer":68,"../../object/is-value":78,"../../object/valid-callable":88,"../../object/valid-value":89,"../../string/is-string":93,"es6-symbol":59}],40:[function(require,module,exports){
|
1819 | "use strict";
|
1820 |
|
1821 | var objToString = Object.prototype.toString
|
1822 | , id = objToString.call(
|
1823 | (function () {
|
1824 | return arguments;
|
1825 | })()
|
1826 | );
|
1827 |
|
1828 | module.exports = function (value) {
|
1829 | return objToString.call(value) === id;
|
1830 | };
|
1831 |
|
1832 | },{}],41:[function(require,module,exports){
|
1833 | "use strict";
|
1834 |
|
1835 | var objToString = Object.prototype.toString, id = objToString.call(require("./noop"));
|
1836 |
|
1837 | module.exports = function (value) {
|
1838 | return typeof value === "function" && objToString.call(value) === id;
|
1839 | };
|
1840 |
|
1841 | },{"./noop":42}],42:[function(require,module,exports){
|
1842 | "use strict";
|
1843 |
|
1844 |
|
1845 | module.exports = function () {};
|
1846 |
|
1847 | },{}],43:[function(require,module,exports){
|
1848 | "use strict";
|
1849 |
|
1850 | module.exports = require("./is-implemented")()
|
1851 | ? Math.sign
|
1852 | : require("./shim");
|
1853 |
|
1854 | },{"./is-implemented":44,"./shim":45}],44:[function(require,module,exports){
|
1855 | "use strict";
|
1856 |
|
1857 | module.exports = function () {
|
1858 | var sign = Math.sign;
|
1859 | if (typeof sign !== "function") return false;
|
1860 | return (sign(10) === 1) && (sign(-20) === -1);
|
1861 | };
|
1862 |
|
1863 | },{}],45:[function(require,module,exports){
|
1864 | "use strict";
|
1865 |
|
1866 | module.exports = function (value) {
|
1867 | value = Number(value);
|
1868 | if (isNaN(value) || (value === 0)) return value;
|
1869 | return value > 0 ? 1 : -1;
|
1870 | };
|
1871 |
|
1872 | },{}],46:[function(require,module,exports){
|
1873 | arguments[4][34][0].apply(exports,arguments)
|
1874 | },{"dup":34,"es5-ext/object/assign":47,"es5-ext/object/is-callable":50,"es5-ext/object/normalize-options":54,"es5-ext/string/#/contains":56}],47:[function(require,module,exports){
|
1875 | 'use strict';
|
1876 |
|
1877 | module.exports = require('./is-implemented')()
|
1878 | ? Object.assign
|
1879 | : require('./shim');
|
1880 |
|
1881 | },{"./is-implemented":48,"./shim":49}],48:[function(require,module,exports){
|
1882 | 'use strict';
|
1883 |
|
1884 | module.exports = function () {
|
1885 | var assign = Object.assign, obj;
|
1886 | if (typeof assign !== 'function') return false;
|
1887 | obj = { foo: 'raz' };
|
1888 | assign(obj, { bar: 'dwa' }, { trzy: 'trzy' });
|
1889 | return (obj.foo + obj.bar + obj.trzy) === 'razdwatrzy';
|
1890 | };
|
1891 |
|
1892 | },{}],49:[function(require,module,exports){
|
1893 | 'use strict';
|
1894 |
|
1895 | var keys = require('../keys')
|
1896 | , value = require('../valid-value')
|
1897 |
|
1898 | , max = Math.max;
|
1899 |
|
1900 | module.exports = function (dest, src/*, …srcn*/) {
|
1901 | var error, i, l = max(arguments.length, 2), assign;
|
1902 | dest = Object(value(dest));
|
1903 | assign = function (key) {
|
1904 | try { dest[key] = src[key]; } catch (e) {
|
1905 | if (!error) error = e;
|
1906 | }
|
1907 | };
|
1908 | for (i = 1; i < l; ++i) {
|
1909 | src = arguments[i];
|
1910 | keys(src).forEach(assign);
|
1911 | }
|
1912 | if (error !== undefined) throw error;
|
1913 | return dest;
|
1914 | };
|
1915 |
|
1916 | },{"../keys":51,"../valid-value":55}],50:[function(require,module,exports){
|
1917 |
|
1918 |
|
1919 | 'use strict';
|
1920 |
|
1921 | module.exports = function (obj) { return typeof obj === 'function'; };
|
1922 |
|
1923 | },{}],51:[function(require,module,exports){
|
1924 | 'use strict';
|
1925 |
|
1926 | module.exports = require('./is-implemented')()
|
1927 | ? Object.keys
|
1928 | : require('./shim');
|
1929 |
|
1930 | },{"./is-implemented":52,"./shim":53}],52:[function(require,module,exports){
|
1931 | 'use strict';
|
1932 |
|
1933 | module.exports = function () {
|
1934 | try {
|
1935 | Object.keys('primitive');
|
1936 | return true;
|
1937 | } catch (e) { return false; }
|
1938 | };
|
1939 |
|
1940 | },{}],53:[function(require,module,exports){
|
1941 | 'use strict';
|
1942 |
|
1943 | var keys = Object.keys;
|
1944 |
|
1945 | module.exports = function (object) {
|
1946 | return keys(object == null ? object : Object(object));
|
1947 | };
|
1948 |
|
1949 | },{}],54:[function(require,module,exports){
|
1950 | 'use strict';
|
1951 |
|
1952 | var forEach = Array.prototype.forEach, create = Object.create;
|
1953 |
|
1954 | var process = function (src, obj) {
|
1955 | var key;
|
1956 | for (key in src) obj[key] = src[key];
|
1957 | };
|
1958 |
|
1959 | module.exports = function (options/*, …options*/) {
|
1960 | var result = create(null);
|
1961 | forEach.call(arguments, function (options) {
|
1962 | if (options == null) return;
|
1963 | process(Object(options), result);
|
1964 | });
|
1965 | return result;
|
1966 | };
|
1967 |
|
1968 | },{}],55:[function(require,module,exports){
|
1969 | 'use strict';
|
1970 |
|
1971 | module.exports = function (value) {
|
1972 | if (value == null) throw new TypeError("Cannot use null or undefined");
|
1973 | return value;
|
1974 | };
|
1975 |
|
1976 | },{}],56:[function(require,module,exports){
|
1977 | 'use strict';
|
1978 |
|
1979 | module.exports = require('./is-implemented')()
|
1980 | ? String.prototype.contains
|
1981 | : require('./shim');
|
1982 |
|
1983 | },{"./is-implemented":57,"./shim":58}],57:[function(require,module,exports){
|
1984 | 'use strict';
|
1985 |
|
1986 | var str = 'razdwatrzy';
|
1987 |
|
1988 | module.exports = function () {
|
1989 | if (typeof str.contains !== 'function') return false;
|
1990 | return ((str.contains('dwa') === true) && (str.contains('foo') === false));
|
1991 | };
|
1992 |
|
1993 | },{}],58:[function(require,module,exports){
|
1994 | 'use strict';
|
1995 |
|
1996 | var indexOf = String.prototype.indexOf;
|
1997 |
|
1998 | module.exports = function (searchString/*, position*/) {
|
1999 | return indexOf.call(this, searchString, arguments[1]) > -1;
|
2000 | };
|
2001 |
|
2002 | },{}],59:[function(require,module,exports){
|
2003 | 'use strict';
|
2004 |
|
2005 | module.exports = require('./is-implemented')() ? Symbol : require('./polyfill');
|
2006 |
|
2007 | },{"./is-implemented":60,"./polyfill":62}],60:[function(require,module,exports){
|
2008 | 'use strict';
|
2009 |
|
2010 | var validTypes = { object: true, symbol: true };
|
2011 |
|
2012 | module.exports = function () {
|
2013 | var symbol;
|
2014 | if (typeof Symbol !== 'function') return false;
|
2015 | symbol = Symbol('test symbol');
|
2016 | try { String(symbol); } catch (e) { return false; }
|
2017 |
|
2018 |
|
2019 | if (!validTypes[typeof Symbol.iterator]) return false;
|
2020 | if (!validTypes[typeof Symbol.toPrimitive]) return false;
|
2021 | if (!validTypes[typeof Symbol.toStringTag]) return false;
|
2022 |
|
2023 | return true;
|
2024 | };
|
2025 |
|
2026 | },{}],61:[function(require,module,exports){
|
2027 | 'use strict';
|
2028 |
|
2029 | module.exports = function (x) {
|
2030 | if (!x) return false;
|
2031 | if (typeof x === 'symbol') return true;
|
2032 | if (!x.constructor) return false;
|
2033 | if (x.constructor.name !== 'Symbol') return false;
|
2034 | return (x[x.constructor.toStringTag] === 'Symbol');
|
2035 | };
|
2036 |
|
2037 | },{}],62:[function(require,module,exports){
|
2038 |
|
2039 |
|
2040 | 'use strict';
|
2041 |
|
2042 | var d = require('d')
|
2043 | , validateSymbol = require('./validate-symbol')
|
2044 |
|
2045 | , create = Object.create, defineProperties = Object.defineProperties
|
2046 | , defineProperty = Object.defineProperty, objPrototype = Object.prototype
|
2047 | , NativeSymbol, SymbolPolyfill, HiddenSymbol, globalSymbols = create(null)
|
2048 | , isNativeSafe;
|
2049 |
|
2050 | if (typeof Symbol === 'function') {
|
2051 | NativeSymbol = Symbol;
|
2052 | try {
|
2053 | String(NativeSymbol());
|
2054 | isNativeSafe = true;
|
2055 | } catch (ignore) {}
|
2056 | }
|
2057 |
|
2058 | var generateName = (function () {
|
2059 | var created = create(null);
|
2060 | return function (desc) {
|
2061 | var postfix = 0, name, ie11BugWorkaround;
|
2062 | while (created[desc + (postfix || '')]) ++postfix;
|
2063 | desc += (postfix || '');
|
2064 | created[desc] = true;
|
2065 | name = '@@' + desc;
|
2066 | defineProperty(objPrototype, name, d.gs(null, function (value) {
|
2067 |
|
2068 |
|
2069 |
|
2070 |
|
2071 | if (ie11BugWorkaround) return;
|
2072 | ie11BugWorkaround = true;
|
2073 | defineProperty(this, name, d(value));
|
2074 | ie11BugWorkaround = false;
|
2075 | }));
|
2076 | return name;
|
2077 | };
|
2078 | }());
|
2079 |
|
2080 |
|
2081 |
|
2082 | HiddenSymbol = function Symbol(description) {
|
2083 | if (this instanceof HiddenSymbol) throw new TypeError('TypeError: Symbol is not a constructor');
|
2084 | return SymbolPolyfill(description);
|
2085 | };
|
2086 |
|
2087 |
|
2088 |
|
2089 | module.exports = SymbolPolyfill = function Symbol(description) {
|
2090 | var symbol;
|
2091 | if (this instanceof Symbol) throw new TypeError('TypeError: Symbol is not a constructor');
|
2092 | if (isNativeSafe) return NativeSymbol(description);
|
2093 | symbol = create(HiddenSymbol.prototype);
|
2094 | description = (description === undefined ? '' : String(description));
|
2095 | return defineProperties(symbol, {
|
2096 | __description__: d('', description),
|
2097 | __name__: d('', generateName(description))
|
2098 | });
|
2099 | };
|
2100 | defineProperties(SymbolPolyfill, {
|
2101 | for: d(function (key) {
|
2102 | if (globalSymbols[key]) return globalSymbols[key];
|
2103 | return (globalSymbols[key] = SymbolPolyfill(String(key)));
|
2104 | }),
|
2105 | keyFor: d(function (s) {
|
2106 | var key;
|
2107 | validateSymbol(s);
|
2108 | for (key in globalSymbols) if (globalSymbols[key] === s) return key;
|
2109 | }),
|
2110 |
|
2111 |
|
2112 |
|
2113 | hasInstance: d('', (NativeSymbol && NativeSymbol.hasInstance) || SymbolPolyfill('hasInstance')),
|
2114 | isConcatSpreadable: d('', (NativeSymbol && NativeSymbol.isConcatSpreadable) ||
|
2115 | SymbolPolyfill('isConcatSpreadable')),
|
2116 | iterator: d('', (NativeSymbol && NativeSymbol.iterator) || SymbolPolyfill('iterator')),
|
2117 | match: d('', (NativeSymbol && NativeSymbol.match) || SymbolPolyfill('match')),
|
2118 | replace: d('', (NativeSymbol && NativeSymbol.replace) || SymbolPolyfill('replace')),
|
2119 | search: d('', (NativeSymbol && NativeSymbol.search) || SymbolPolyfill('search')),
|
2120 | species: d('', (NativeSymbol && NativeSymbol.species) || SymbolPolyfill('species')),
|
2121 | split: d('', (NativeSymbol && NativeSymbol.split) || SymbolPolyfill('split')),
|
2122 | toPrimitive: d('', (NativeSymbol && NativeSymbol.toPrimitive) || SymbolPolyfill('toPrimitive')),
|
2123 | toStringTag: d('', (NativeSymbol && NativeSymbol.toStringTag) || SymbolPolyfill('toStringTag')),
|
2124 | unscopables: d('', (NativeSymbol && NativeSymbol.unscopables) || SymbolPolyfill('unscopables'))
|
2125 | });
|
2126 |
|
2127 |
|
2128 | defineProperties(HiddenSymbol.prototype, {
|
2129 | constructor: d(SymbolPolyfill),
|
2130 | toString: d('', function () { return this.__name__; })
|
2131 | });
|
2132 |
|
2133 |
|
2134 |
|
2135 | defineProperties(SymbolPolyfill.prototype, {
|
2136 | toString: d(function () { return 'Symbol (' + validateSymbol(this).__description__ + ')'; }),
|
2137 | valueOf: d(function () { return validateSymbol(this); })
|
2138 | });
|
2139 | defineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toPrimitive, d('', function () {
|
2140 | var symbol = validateSymbol(this);
|
2141 | if (typeof symbol === 'symbol') return symbol;
|
2142 | return symbol.toString();
|
2143 | }));
|
2144 | defineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toStringTag, d('c', 'Symbol'));
|
2145 |
|
2146 |
|
2147 | defineProperty(HiddenSymbol.prototype, SymbolPolyfill.toStringTag,
|
2148 | d('c', SymbolPolyfill.prototype[SymbolPolyfill.toStringTag]));
|
2149 |
|
2150 |
|
2151 |
|
2152 |
|
2153 |
|
2154 | defineProperty(HiddenSymbol.prototype, SymbolPolyfill.toPrimitive,
|
2155 | d('c', SymbolPolyfill.prototype[SymbolPolyfill.toPrimitive]));
|
2156 |
|
2157 | },{"./validate-symbol":63,"d":46}],63:[function(require,module,exports){
|
2158 | 'use strict';
|
2159 |
|
2160 | var isSymbol = require('./is-symbol');
|
2161 |
|
2162 | module.exports = function (value) {
|
2163 | if (!isSymbol(value)) throw new TypeError(value + " is not a symbol");
|
2164 | return value;
|
2165 | };
|
2166 |
|
2167 | },{"./is-symbol":61}],64:[function(require,module,exports){
|
2168 | "use strict";
|
2169 |
|
2170 | module.exports = require("./is-implemented")()
|
2171 | ? Number.isNaN
|
2172 | : require("./shim");
|
2173 |
|
2174 | },{"./is-implemented":65,"./shim":66}],65:[function(require,module,exports){
|
2175 | "use strict";
|
2176 |
|
2177 | module.exports = function () {
|
2178 | var numberIsNaN = Number.isNaN;
|
2179 | if (typeof numberIsNaN !== "function") return false;
|
2180 | return !numberIsNaN({}) && numberIsNaN(NaN) && !numberIsNaN(34);
|
2181 | };
|
2182 |
|
2183 | },{}],66:[function(require,module,exports){
|
2184 | "use strict";
|
2185 |
|
2186 | module.exports = function (value) {
|
2187 |
|
2188 | return value !== value;
|
2189 | };
|
2190 |
|
2191 | },{}],67:[function(require,module,exports){
|
2192 | "use strict";
|
2193 |
|
2194 | var sign = require("../math/sign")
|
2195 |
|
2196 | , abs = Math.abs, floor = Math.floor;
|
2197 |
|
2198 | module.exports = function (value) {
|
2199 | if (isNaN(value)) return 0;
|
2200 | value = Number(value);
|
2201 | if ((value === 0) || !isFinite(value)) return value;
|
2202 | return sign(value) * floor(abs(value));
|
2203 | };
|
2204 |
|
2205 | },{"../math/sign":43}],68:[function(require,module,exports){
|
2206 | "use strict";
|
2207 |
|
2208 | var toInteger = require("./to-integer")
|
2209 |
|
2210 | , max = Math.max;
|
2211 |
|
2212 | module.exports = function (value) {
|
2213 | return max(0, toInteger(value));
|
2214 | };
|
2215 |
|
2216 | },{"./to-integer":67}],69:[function(require,module,exports){
|
2217 |
|
2218 |
|
2219 |
|
2220 |
|
2221 | "use strict";
|
2222 |
|
2223 | var callable = require("./valid-callable")
|
2224 | , value = require("./valid-value")
|
2225 | , bind = Function.prototype.bind
|
2226 | , call = Function.prototype.call
|
2227 | , keys = Object.keys
|
2228 | , objPropertyIsEnumerable = Object.prototype.propertyIsEnumerable;
|
2229 |
|
2230 | module.exports = function (method, defVal) {
|
2231 | return function (obj, cb /*, thisArg, compareFn*/) {
|
2232 | var list, thisArg = arguments[2], compareFn = arguments[3];
|
2233 | obj = Object(value(obj));
|
2234 | callable(cb);
|
2235 |
|
2236 | list = keys(obj);
|
2237 | if (compareFn) {
|
2238 | list.sort(typeof compareFn === "function" ? bind.call(compareFn, obj) : undefined);
|
2239 | }
|
2240 | if (typeof method !== "function") method = list[method];
|
2241 | return call.call(method, list, function (key, index) {
|
2242 | if (!objPropertyIsEnumerable.call(obj, key)) return defVal;
|
2243 | return call.call(cb, thisArg, obj[key], key, obj, index);
|
2244 | });
|
2245 | };
|
2246 | };
|
2247 |
|
2248 | },{"./valid-callable":88,"./valid-value":89}],70:[function(require,module,exports){
|
2249 | "use strict";
|
2250 |
|
2251 | module.exports = require("./is-implemented")()
|
2252 | ? Object.assign
|
2253 | : require("./shim");
|
2254 |
|
2255 | },{"./is-implemented":71,"./shim":72}],71:[function(require,module,exports){
|
2256 | "use strict";
|
2257 |
|
2258 | module.exports = function () {
|
2259 | var assign = Object.assign, obj;
|
2260 | if (typeof assign !== "function") return false;
|
2261 | obj = { foo: "raz" };
|
2262 | assign(obj, { bar: "dwa" }, { trzy: "trzy" });
|
2263 | return (obj.foo + obj.bar + obj.trzy) === "razdwatrzy";
|
2264 | };
|
2265 |
|
2266 | },{}],72:[function(require,module,exports){
|
2267 | "use strict";
|
2268 |
|
2269 | var keys = require("../keys")
|
2270 | , value = require("../valid-value")
|
2271 | , max = Math.max;
|
2272 |
|
2273 | module.exports = function (dest, src /*, …srcn*/) {
|
2274 | var error, i, length = max(arguments.length, 2), assign;
|
2275 | dest = Object(value(dest));
|
2276 | assign = function (key) {
|
2277 | try {
|
2278 | dest[key] = src[key];
|
2279 | } catch (e) {
|
2280 | if (!error) error = e;
|
2281 | }
|
2282 | };
|
2283 | for (i = 1; i < length; ++i) {
|
2284 | src = arguments[i];
|
2285 | keys(src).forEach(assign);
|
2286 | }
|
2287 | if (error !== undefined) throw error;
|
2288 | return dest;
|
2289 | };
|
2290 |
|
2291 | },{"../keys":79,"../valid-value":89}],73:[function(require,module,exports){
|
2292 | "use strict";
|
2293 |
|
2294 | var aFrom = require("../array/from")
|
2295 | , assign = require("./assign")
|
2296 | , value = require("./valid-value");
|
2297 |
|
2298 | module.exports = function (obj/*, propertyNames, options*/) {
|
2299 | var copy = Object(value(obj)), propertyNames = arguments[1], options = Object(arguments[2]);
|
2300 | if (copy !== obj && !propertyNames) return copy;
|
2301 | var result = {};
|
2302 | if (propertyNames) {
|
2303 | aFrom(propertyNames, function (propertyName) {
|
2304 | if (options.ensure || propertyName in obj) result[propertyName] = obj[propertyName];
|
2305 | });
|
2306 | } else {
|
2307 | assign(result, obj);
|
2308 | }
|
2309 | return result;
|
2310 | };
|
2311 |
|
2312 | },{"../array/from":37,"./assign":70,"./valid-value":89}],74:[function(require,module,exports){
|
2313 |
|
2314 |
|
2315 | "use strict";
|
2316 |
|
2317 | var create = Object.create, shim;
|
2318 |
|
2319 | if (!require("./set-prototype-of/is-implemented")()) {
|
2320 | shim = require("./set-prototype-of/shim");
|
2321 | }
|
2322 |
|
2323 | module.exports = (function () {
|
2324 | var nullObject, polyProps, desc;
|
2325 | if (!shim) return create;
|
2326 | if (shim.level !== 1) return create;
|
2327 |
|
2328 | nullObject = {};
|
2329 | polyProps = {};
|
2330 | desc = {
|
2331 | configurable: false,
|
2332 | enumerable: false,
|
2333 | writable: true,
|
2334 | value: undefined
|
2335 | };
|
2336 | Object.getOwnPropertyNames(Object.prototype).forEach(function (name) {
|
2337 | if (name === "__proto__") {
|
2338 | polyProps[name] = {
|
2339 | configurable: true,
|
2340 | enumerable: false,
|
2341 | writable: true,
|
2342 | value: undefined
|
2343 | };
|
2344 | return;
|
2345 | }
|
2346 | polyProps[name] = desc;
|
2347 | });
|
2348 | Object.defineProperties(nullObject, polyProps);
|
2349 |
|
2350 | Object.defineProperty(shim, "nullPolyfill", {
|
2351 | configurable: false,
|
2352 | enumerable: false,
|
2353 | writable: false,
|
2354 | value: nullObject
|
2355 | });
|
2356 |
|
2357 | return function (prototype, props) {
|
2358 | return create(prototype === null ? nullObject : prototype, props);
|
2359 | };
|
2360 | }());
|
2361 |
|
2362 | },{"./set-prototype-of/is-implemented":86,"./set-prototype-of/shim":87}],75:[function(require,module,exports){
|
2363 | "use strict";
|
2364 |
|
2365 | module.exports = require("./_iterate")("forEach");
|
2366 |
|
2367 | },{"./_iterate":69}],76:[function(require,module,exports){
|
2368 |
|
2369 |
|
2370 | "use strict";
|
2371 |
|
2372 | module.exports = function (obj) {
|
2373 | return typeof obj === "function";
|
2374 | };
|
2375 |
|
2376 | },{}],77:[function(require,module,exports){
|
2377 | "use strict";
|
2378 |
|
2379 | var isValue = require("./is-value");
|
2380 |
|
2381 | var map = { function: true, object: true };
|
2382 |
|
2383 | module.exports = function (value) {
|
2384 | return (isValue(value) && map[typeof value]) || false;
|
2385 | };
|
2386 |
|
2387 | },{"./is-value":78}],78:[function(require,module,exports){
|
2388 | "use strict";
|
2389 |
|
2390 | var _undefined = require("../function/noop")();
|
2391 |
|
2392 | module.exports = function (val) {
|
2393 | return (val !== _undefined) && (val !== null);
|
2394 | };
|
2395 |
|
2396 | },{"../function/noop":42}],79:[function(require,module,exports){
|
2397 | "use strict";
|
2398 |
|
2399 | module.exports = require("./is-implemented")()
|
2400 | ? Object.keys
|
2401 | : require("./shim");
|
2402 |
|
2403 | },{"./is-implemented":80,"./shim":81}],80:[function(require,module,exports){
|
2404 | "use strict";
|
2405 |
|
2406 | module.exports = function () {
|
2407 | try {
|
2408 | Object.keys("primitive");
|
2409 | return true;
|
2410 | } catch (e) {
|
2411 | return false;
|
2412 | }
|
2413 | };
|
2414 |
|
2415 | },{}],81:[function(require,module,exports){
|
2416 | "use strict";
|
2417 |
|
2418 | var isValue = require("../is-value");
|
2419 |
|
2420 | var keys = Object.keys;
|
2421 |
|
2422 | module.exports = function (object) {
|
2423 | return keys(isValue(object) ? Object(object) : object);
|
2424 | };
|
2425 |
|
2426 | },{"../is-value":78}],82:[function(require,module,exports){
|
2427 | "use strict";
|
2428 |
|
2429 | var callable = require("./valid-callable")
|
2430 | , forEach = require("./for-each")
|
2431 | , call = Function.prototype.call;
|
2432 |
|
2433 | module.exports = function (obj, cb /*, thisArg*/) {
|
2434 | var result = {}, thisArg = arguments[2];
|
2435 | callable(cb);
|
2436 | forEach(obj, function (value, key, targetObj, index) {
|
2437 | result[key] = call.call(cb, thisArg, value, key, targetObj, index);
|
2438 | });
|
2439 | return result;
|
2440 | };
|
2441 |
|
2442 | },{"./for-each":75,"./valid-callable":88}],83:[function(require,module,exports){
|
2443 | "use strict";
|
2444 |
|
2445 | var isValue = require("./is-value");
|
2446 |
|
2447 | var forEach = Array.prototype.forEach, create = Object.create;
|
2448 |
|
2449 | var process = function (src, obj) {
|
2450 | var key;
|
2451 | for (key in src) obj[key] = src[key];
|
2452 | };
|
2453 |
|
2454 |
|
2455 | module.exports = function (opts1 /*, …options*/) {
|
2456 | var result = create(null);
|
2457 | forEach.call(arguments, function (options) {
|
2458 | if (!isValue(options)) return;
|
2459 | process(Object(options), result);
|
2460 | });
|
2461 | return result;
|
2462 | };
|
2463 |
|
2464 | },{"./is-value":78}],84:[function(require,module,exports){
|
2465 | "use strict";
|
2466 |
|
2467 | var forEach = Array.prototype.forEach, create = Object.create;
|
2468 |
|
2469 |
|
2470 | module.exports = function (arg /*, …args*/) {
|
2471 | var set = create(null);
|
2472 | forEach.call(arguments, function (name) {
|
2473 | set[name] = true;
|
2474 | });
|
2475 | return set;
|
2476 | };
|
2477 |
|
2478 | },{}],85:[function(require,module,exports){
|
2479 | "use strict";
|
2480 |
|
2481 | module.exports = require("./is-implemented")()
|
2482 | ? Object.setPrototypeOf
|
2483 | : require("./shim");
|
2484 |
|
2485 | },{"./is-implemented":86,"./shim":87}],86:[function(require,module,exports){
|
2486 | "use strict";
|
2487 |
|
2488 | var create = Object.create, getPrototypeOf = Object.getPrototypeOf, plainObject = {};
|
2489 |
|
2490 | module.exports = function (/* CustomCreate*/) {
|
2491 | var setPrototypeOf = Object.setPrototypeOf, customCreate = arguments[0] || create;
|
2492 | if (typeof setPrototypeOf !== "function") return false;
|
2493 | return getPrototypeOf(setPrototypeOf(customCreate(null), plainObject)) === plainObject;
|
2494 | };
|
2495 |
|
2496 | },{}],87:[function(require,module,exports){
|
2497 |
|
2498 |
|
2499 |
|
2500 |
|
2501 |
|
2502 | "use strict";
|
2503 |
|
2504 | var isObject = require("../is-object")
|
2505 | , value = require("../valid-value")
|
2506 | , objIsPrototypOf = Object.prototype.isPrototypeOf
|
2507 | , defineProperty = Object.defineProperty
|
2508 | , nullDesc = {
|
2509 | configurable: true,
|
2510 | enumerable: false,
|
2511 | writable: true,
|
2512 | value: undefined
|
2513 | }
|
2514 | , validate;
|
2515 |
|
2516 | validate = function (obj, prototype) {
|
2517 | value(obj);
|
2518 | if (prototype === null || isObject(prototype)) return obj;
|
2519 | throw new TypeError("Prototype must be null or an object");
|
2520 | };
|
2521 |
|
2522 | module.exports = (function (status) {
|
2523 | var fn, set;
|
2524 | if (!status) return null;
|
2525 | if (status.level === 2) {
|
2526 | if (status.set) {
|
2527 | set = status.set;
|
2528 | fn = function (obj, prototype) {
|
2529 | set.call(validate(obj, prototype), prototype);
|
2530 | return obj;
|
2531 | };
|
2532 | } else {
|
2533 | fn = function (obj, prototype) {
|
2534 | validate(obj, prototype).__proto__ = prototype;
|
2535 | return obj;
|
2536 | };
|
2537 | }
|
2538 | } else {
|
2539 | fn = function self (obj, prototype) {
|
2540 | var isNullBase;
|
2541 | validate(obj, prototype);
|
2542 | isNullBase = objIsPrototypOf.call(self.nullPolyfill, obj);
|
2543 | if (isNullBase) delete self.nullPolyfill.__proto__;
|
2544 | if (prototype === null) prototype = self.nullPolyfill;
|
2545 | obj.__proto__ = prototype;
|
2546 | if (isNullBase) defineProperty(self.nullPolyfill, "__proto__", nullDesc);
|
2547 | return obj;
|
2548 | };
|
2549 | }
|
2550 | return Object.defineProperty(fn, "level", {
|
2551 | configurable: false,
|
2552 | enumerable: false,
|
2553 | writable: false,
|
2554 | value: status.level
|
2555 | });
|
2556 | }(
|
2557 | (function () {
|
2558 | var tmpObj1 = Object.create(null)
|
2559 | , tmpObj2 = {}
|
2560 | , set
|
2561 | , desc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__");
|
2562 |
|
2563 | if (desc) {
|
2564 | try {
|
2565 | set = desc.set; // Opera crashes at this point
|
2566 | set.call(tmpObj1, tmpObj2);
|
2567 | } catch (ignore) {}
|
2568 | if (Object.getPrototypeOf(tmpObj1) === tmpObj2) return { set: set, level: 2 };
|
2569 | }
|
2570 |
|
2571 | tmpObj1.__proto__ = tmpObj2;
|
2572 | if (Object.getPrototypeOf(tmpObj1) === tmpObj2) return { level: 2 };
|
2573 |
|
2574 | tmpObj1 = {};
|
2575 | tmpObj1.__proto__ = tmpObj2;
|
2576 | if (Object.getPrototypeOf(tmpObj1) === tmpObj2) return { level: 1 };
|
2577 |
|
2578 | return false;
|
2579 | })()
|
2580 | ));
|
2581 |
|
2582 | require("../create");
|
2583 |
|
2584 | },{"../create":74,"../is-object":77,"../valid-value":89}],88:[function(require,module,exports){
|
2585 | "use strict";
|
2586 |
|
2587 | module.exports = function (fn) {
|
2588 | if (typeof fn !== "function") throw new TypeError(fn + " is not a function");
|
2589 | return fn;
|
2590 | };
|
2591 |
|
2592 | },{}],89:[function(require,module,exports){
|
2593 | "use strict";
|
2594 |
|
2595 | var isValue = require("./is-value");
|
2596 |
|
2597 | module.exports = function (value) {
|
2598 | if (!isValue(value)) throw new TypeError("Cannot use null or undefined");
|
2599 | return value;
|
2600 | };
|
2601 |
|
2602 | },{"./is-value":78}],90:[function(require,module,exports){
|
2603 | "use strict";
|
2604 |
|
2605 | module.exports = require("./is-implemented")()
|
2606 | ? String.prototype.contains
|
2607 | : require("./shim");
|
2608 |
|
2609 | },{"./is-implemented":91,"./shim":92}],91:[function(require,module,exports){
|
2610 | "use strict";
|
2611 |
|
2612 | var str = "razdwatrzy";
|
2613 |
|
2614 | module.exports = function () {
|
2615 | if (typeof str.contains !== "function") return false;
|
2616 | return (str.contains("dwa") === true) && (str.contains("foo") === false);
|
2617 | };
|
2618 |
|
2619 | },{}],92:[function(require,module,exports){
|
2620 | "use strict";
|
2621 |
|
2622 | var indexOf = String.prototype.indexOf;
|
2623 |
|
2624 | module.exports = function (searchString/*, position*/) {
|
2625 | return indexOf.call(this, searchString, arguments[1]) > -1;
|
2626 | };
|
2627 |
|
2628 | },{}],93:[function(require,module,exports){
|
2629 | "use strict";
|
2630 |
|
2631 | var objToString = Object.prototype.toString, id = objToString.call("");
|
2632 |
|
2633 | module.exports = function (value) {
|
2634 | return (
|
2635 | typeof value === "string" ||
|
2636 | (value &&
|
2637 | typeof value === "object" &&
|
2638 | (value instanceof String || objToString.call(value) === id)) ||
|
2639 | false
|
2640 | );
|
2641 | };
|
2642 |
|
2643 | },{}],94:[function(require,module,exports){
|
2644 | 'use strict';
|
2645 |
|
2646 | var setPrototypeOf = require('es5-ext/object/set-prototype-of')
|
2647 | , contains = require('es5-ext/string/#/contains')
|
2648 | , d = require('d')
|
2649 | , Iterator = require('./')
|
2650 |
|
2651 | , defineProperty = Object.defineProperty
|
2652 | , ArrayIterator;
|
2653 |
|
2654 | ArrayIterator = module.exports = function (arr, kind) {
|
2655 | if (!(this instanceof ArrayIterator)) return new ArrayIterator(arr, kind);
|
2656 | Iterator.call(this, arr);
|
2657 | if (!kind) kind = 'value';
|
2658 | else if (contains.call(kind, 'key+value')) kind = 'key+value';
|
2659 | else if (contains.call(kind, 'key')) kind = 'key';
|
2660 | else kind = 'value';
|
2661 | defineProperty(this, '__kind__', d('', kind));
|
2662 | };
|
2663 | if (setPrototypeOf) setPrototypeOf(ArrayIterator, Iterator);
|
2664 |
|
2665 | ArrayIterator.prototype = Object.create(Iterator.prototype, {
|
2666 | constructor: d(ArrayIterator),
|
2667 | _resolve: d(function (i) {
|
2668 | if (this.__kind__ === 'value') return this.__list__[i];
|
2669 | if (this.__kind__ === 'key+value') return [i, this.__list__[i]];
|
2670 | return i;
|
2671 | }),
|
2672 | toString: d(function () { return '[object Array Iterator]'; })
|
2673 | });
|
2674 |
|
2675 | },{"./":97,"d":34,"es5-ext/object/set-prototype-of":85,"es5-ext/string/#/contains":90}],95:[function(require,module,exports){
|
2676 | 'use strict';
|
2677 |
|
2678 | var isArguments = require('es5-ext/function/is-arguments')
|
2679 | , callable = require('es5-ext/object/valid-callable')
|
2680 | , isString = require('es5-ext/string/is-string')
|
2681 | , get = require('./get')
|
2682 |
|
2683 | , isArray = Array.isArray, call = Function.prototype.call
|
2684 | , some = Array.prototype.some;
|
2685 |
|
2686 | module.exports = function (iterable, cb/*, thisArg*/) {
|
2687 | var mode, thisArg = arguments[2], result, doBreak, broken, i, l, char, code;
|
2688 | if (isArray(iterable) || isArguments(iterable)) mode = 'array';
|
2689 | else if (isString(iterable)) mode = 'string';
|
2690 | else iterable = get(iterable);
|
2691 |
|
2692 | callable(cb);
|
2693 | doBreak = function () { broken = true; };
|
2694 | if (mode === 'array') {
|
2695 | some.call(iterable, function (value) {
|
2696 | call.call(cb, thisArg, value, doBreak);
|
2697 | if (broken) return true;
|
2698 | });
|
2699 | return;
|
2700 | }
|
2701 | if (mode === 'string') {
|
2702 | l = iterable.length;
|
2703 | for (i = 0; i < l; ++i) {
|
2704 | char = iterable[i];
|
2705 | if ((i + 1) < l) {
|
2706 | code = char.charCodeAt(0);
|
2707 | if ((code >= 0xD800) && (code <= 0xDBFF)) char += iterable[++i];
|
2708 | }
|
2709 | call.call(cb, thisArg, char, doBreak);
|
2710 | if (broken) break;
|
2711 | }
|
2712 | return;
|
2713 | }
|
2714 | result = iterable.next();
|
2715 |
|
2716 | while (!result.done) {
|
2717 | call.call(cb, thisArg, result.value, doBreak);
|
2718 | if (broken) return;
|
2719 | result = iterable.next();
|
2720 | }
|
2721 | };
|
2722 |
|
2723 | },{"./get":96,"es5-ext/function/is-arguments":40,"es5-ext/object/valid-callable":88,"es5-ext/string/is-string":93}],96:[function(require,module,exports){
|
2724 | 'use strict';
|
2725 |
|
2726 | var isArguments = require('es5-ext/function/is-arguments')
|
2727 | , isString = require('es5-ext/string/is-string')
|
2728 | , ArrayIterator = require('./array')
|
2729 | , StringIterator = require('./string')
|
2730 | , iterable = require('./valid-iterable')
|
2731 | , iteratorSymbol = require('es6-symbol').iterator;
|
2732 |
|
2733 | module.exports = function (obj) {
|
2734 | if (typeof iterable(obj)[iteratorSymbol] === 'function') return obj[iteratorSymbol]();
|
2735 | if (isArguments(obj)) return new ArrayIterator(obj);
|
2736 | if (isString(obj)) return new StringIterator(obj);
|
2737 | return new ArrayIterator(obj);
|
2738 | };
|
2739 |
|
2740 | },{"./array":94,"./string":99,"./valid-iterable":100,"es5-ext/function/is-arguments":40,"es5-ext/string/is-string":93,"es6-symbol":101}],97:[function(require,module,exports){
|
2741 | 'use strict';
|
2742 |
|
2743 | var clear = require('es5-ext/array/#/clear')
|
2744 | , assign = require('es5-ext/object/assign')
|
2745 | , callable = require('es5-ext/object/valid-callable')
|
2746 | , value = require('es5-ext/object/valid-value')
|
2747 | , d = require('d')
|
2748 | , autoBind = require('d/auto-bind')
|
2749 | , Symbol = require('es6-symbol')
|
2750 |
|
2751 | , defineProperty = Object.defineProperty
|
2752 | , defineProperties = Object.defineProperties
|
2753 | , Iterator;
|
2754 |
|
2755 | module.exports = Iterator = function (list, context) {
|
2756 | if (!(this instanceof Iterator)) return new Iterator(list, context);
|
2757 | defineProperties(this, {
|
2758 | __list__: d('w', value(list)),
|
2759 | __context__: d('w', context),
|
2760 | __nextIndex__: d('w', 0)
|
2761 | });
|
2762 | if (!context) return;
|
2763 | callable(context.on);
|
2764 | context.on('_add', this._onAdd);
|
2765 | context.on('_delete', this._onDelete);
|
2766 | context.on('_clear', this._onClear);
|
2767 | };
|
2768 |
|
2769 | defineProperties(Iterator.prototype, assign({
|
2770 | constructor: d(Iterator),
|
2771 | _next: d(function () {
|
2772 | var i;
|
2773 | if (!this.__list__) return;
|
2774 | if (this.__redo__) {
|
2775 | i = this.__redo__.shift();
|
2776 | if (i !== undefined) return i;
|
2777 | }
|
2778 | if (this.__nextIndex__ < this.__list__.length) return this.__nextIndex__++;
|
2779 | this._unBind();
|
2780 | }),
|
2781 | next: d(function () { return this._createResult(this._next()); }),
|
2782 | _createResult: d(function (i) {
|
2783 | if (i === undefined) return { done: true, value: undefined };
|
2784 | return { done: false, value: this._resolve(i) };
|
2785 | }),
|
2786 | _resolve: d(function (i) { return this.__list__[i]; }),
|
2787 | _unBind: d(function () {
|
2788 | this.__list__ = null;
|
2789 | delete this.__redo__;
|
2790 | if (!this.__context__) return;
|
2791 | this.__context__.off('_add', this._onAdd);
|
2792 | this.__context__.off('_delete', this._onDelete);
|
2793 | this.__context__.off('_clear', this._onClear);
|
2794 | this.__context__ = null;
|
2795 | }),
|
2796 | toString: d(function () { return '[object Iterator]'; })
|
2797 | }, autoBind({
|
2798 | _onAdd: d(function (index) {
|
2799 | if (index >= this.__nextIndex__) return;
|
2800 | ++this.__nextIndex__;
|
2801 | if (!this.__redo__) {
|
2802 | defineProperty(this, '__redo__', d('c', [index]));
|
2803 | return;
|
2804 | }
|
2805 | this.__redo__.forEach(function (redo, i) {
|
2806 | if (redo >= index) this.__redo__[i] = ++redo;
|
2807 | }, this);
|
2808 | this.__redo__.push(index);
|
2809 | }),
|
2810 | _onDelete: d(function (index) {
|
2811 | var i;
|
2812 | if (index >= this.__nextIndex__) return;
|
2813 | --this.__nextIndex__;
|
2814 | if (!this.__redo__) return;
|
2815 | i = this.__redo__.indexOf(index);
|
2816 | if (i !== -1) this.__redo__.splice(i, 1);
|
2817 | this.__redo__.forEach(function (redo, i) {
|
2818 | if (redo > index) this.__redo__[i] = --redo;
|
2819 | }, this);
|
2820 | }),
|
2821 | _onClear: d(function () {
|
2822 | if (this.__redo__) clear.call(this.__redo__);
|
2823 | this.__nextIndex__ = 0;
|
2824 | })
|
2825 | })));
|
2826 |
|
2827 | defineProperty(Iterator.prototype, Symbol.iterator, d(function () {
|
2828 | return this;
|
2829 | }));
|
2830 | defineProperty(Iterator.prototype, Symbol.toStringTag, d('', 'Iterator'));
|
2831 |
|
2832 | },{"d":34,"d/auto-bind":33,"es5-ext/array/#/clear":35,"es5-ext/object/assign":70,"es5-ext/object/valid-callable":88,"es5-ext/object/valid-value":89,"es6-symbol":101}],98:[function(require,module,exports){
|
2833 | 'use strict';
|
2834 |
|
2835 | var isArguments = require('es5-ext/function/is-arguments')
|
2836 | , isString = require('es5-ext/string/is-string')
|
2837 | , iteratorSymbol = require('es6-symbol').iterator
|
2838 |
|
2839 | , isArray = Array.isArray;
|
2840 |
|
2841 | module.exports = function (value) {
|
2842 | if (value == null) return false;
|
2843 | if (isArray(value)) return true;
|
2844 | if (isString(value)) return true;
|
2845 | if (isArguments(value)) return true;
|
2846 | return (typeof value[iteratorSymbol] === 'function');
|
2847 | };
|
2848 |
|
2849 | },{"es5-ext/function/is-arguments":40,"es5-ext/string/is-string":93,"es6-symbol":101}],99:[function(require,module,exports){
|
2850 |
|
2851 |
|
2852 |
|
2853 | 'use strict';
|
2854 |
|
2855 | var setPrototypeOf = require('es5-ext/object/set-prototype-of')
|
2856 | , d = require('d')
|
2857 | , Iterator = require('./')
|
2858 |
|
2859 | , defineProperty = Object.defineProperty
|
2860 | , StringIterator;
|
2861 |
|
2862 | StringIterator = module.exports = function (str) {
|
2863 | if (!(this instanceof StringIterator)) return new StringIterator(str);
|
2864 | str = String(str);
|
2865 | Iterator.call(this, str);
|
2866 | defineProperty(this, '__length__', d('', str.length));
|
2867 |
|
2868 | };
|
2869 | if (setPrototypeOf) setPrototypeOf(StringIterator, Iterator);
|
2870 |
|
2871 | StringIterator.prototype = Object.create(Iterator.prototype, {
|
2872 | constructor: d(StringIterator),
|
2873 | _next: d(function () {
|
2874 | if (!this.__list__) return;
|
2875 | if (this.__nextIndex__ < this.__length__) return this.__nextIndex__++;
|
2876 | this._unBind();
|
2877 | }),
|
2878 | _resolve: d(function (i) {
|
2879 | var char = this.__list__[i], code;
|
2880 | if (this.__nextIndex__ === this.__length__) return char;
|
2881 | code = char.charCodeAt(0);
|
2882 | if ((code >= 0xD800) && (code <= 0xDBFF)) return char + this.__list__[this.__nextIndex__++];
|
2883 | return char;
|
2884 | }),
|
2885 | toString: d(function () { return '[object String Iterator]'; })
|
2886 | });
|
2887 |
|
2888 | },{"./":97,"d":34,"es5-ext/object/set-prototype-of":85}],100:[function(require,module,exports){
|
2889 | 'use strict';
|
2890 |
|
2891 | var isIterable = require('./is-iterable');
|
2892 |
|
2893 | module.exports = function (value) {
|
2894 | if (!isIterable(value)) throw new TypeError(value + " is not iterable");
|
2895 | return value;
|
2896 | };
|
2897 |
|
2898 | },{"./is-iterable":98}],101:[function(require,module,exports){
|
2899 | arguments[4][59][0].apply(exports,arguments)
|
2900 | },{"./is-implemented":102,"./polyfill":104,"dup":59}],102:[function(require,module,exports){
|
2901 | arguments[4][60][0].apply(exports,arguments)
|
2902 | },{"dup":60}],103:[function(require,module,exports){
|
2903 | arguments[4][61][0].apply(exports,arguments)
|
2904 | },{"dup":61}],104:[function(require,module,exports){
|
2905 |
|
2906 |
|
2907 | 'use strict';
|
2908 |
|
2909 | var d = require('d')
|
2910 | , validateSymbol = require('./validate-symbol')
|
2911 |
|
2912 | , create = Object.create, defineProperties = Object.defineProperties
|
2913 | , defineProperty = Object.defineProperty, objPrototype = Object.prototype
|
2914 | , NativeSymbol, SymbolPolyfill, HiddenSymbol, globalSymbols = create(null)
|
2915 | , isNativeSafe;
|
2916 |
|
2917 | if (typeof Symbol === 'function') {
|
2918 | NativeSymbol = Symbol;
|
2919 | try {
|
2920 | String(NativeSymbol());
|
2921 | isNativeSafe = true;
|
2922 | } catch (ignore) {}
|
2923 | }
|
2924 |
|
2925 | var generateName = (function () {
|
2926 | var created = create(null);
|
2927 | return function (desc) {
|
2928 | var postfix = 0, name, ie11BugWorkaround;
|
2929 | while (created[desc + (postfix || '')]) ++postfix;
|
2930 | desc += (postfix || '');
|
2931 | created[desc] = true;
|
2932 | name = '@@' + desc;
|
2933 | defineProperty(objPrototype, name, d.gs(null, function (value) {
|
2934 |
|
2935 |
|
2936 |
|
2937 |
|
2938 | if (ie11BugWorkaround) return;
|
2939 | ie11BugWorkaround = true;
|
2940 | defineProperty(this, name, d(value));
|
2941 | ie11BugWorkaround = false;
|
2942 | }));
|
2943 | return name;
|
2944 | };
|
2945 | }());
|
2946 |
|
2947 |
|
2948 |
|
2949 | HiddenSymbol = function Symbol(description) {
|
2950 | if (this instanceof HiddenSymbol) throw new TypeError('Symbol is not a constructor');
|
2951 | return SymbolPolyfill(description);
|
2952 | };
|
2953 |
|
2954 |
|
2955 |
|
2956 | module.exports = SymbolPolyfill = function Symbol(description) {
|
2957 | var symbol;
|
2958 | if (this instanceof Symbol) throw new TypeError('Symbol is not a constructor');
|
2959 | if (isNativeSafe) return NativeSymbol(description);
|
2960 | symbol = create(HiddenSymbol.prototype);
|
2961 | description = (description === undefined ? '' : String(description));
|
2962 | return defineProperties(symbol, {
|
2963 | __description__: d('', description),
|
2964 | __name__: d('', generateName(description))
|
2965 | });
|
2966 | };
|
2967 | defineProperties(SymbolPolyfill, {
|
2968 | for: d(function (key) {
|
2969 | if (globalSymbols[key]) return globalSymbols[key];
|
2970 | return (globalSymbols[key] = SymbolPolyfill(String(key)));
|
2971 | }),
|
2972 | keyFor: d(function (s) {
|
2973 | var key;
|
2974 | validateSymbol(s);
|
2975 | for (key in globalSymbols) if (globalSymbols[key] === s) return key;
|
2976 | }),
|
2977 |
|
2978 |
|
2979 |
|
2980 | hasInstance: d('', (NativeSymbol && NativeSymbol.hasInstance) || SymbolPolyfill('hasInstance')),
|
2981 | isConcatSpreadable: d('', (NativeSymbol && NativeSymbol.isConcatSpreadable) ||
|
2982 | SymbolPolyfill('isConcatSpreadable')),
|
2983 | iterator: d('', (NativeSymbol && NativeSymbol.iterator) || SymbolPolyfill('iterator')),
|
2984 | match: d('', (NativeSymbol && NativeSymbol.match) || SymbolPolyfill('match')),
|
2985 | replace: d('', (NativeSymbol && NativeSymbol.replace) || SymbolPolyfill('replace')),
|
2986 | search: d('', (NativeSymbol && NativeSymbol.search) || SymbolPolyfill('search')),
|
2987 | species: d('', (NativeSymbol && NativeSymbol.species) || SymbolPolyfill('species')),
|
2988 | split: d('', (NativeSymbol && NativeSymbol.split) || SymbolPolyfill('split')),
|
2989 | toPrimitive: d('', (NativeSymbol && NativeSymbol.toPrimitive) || SymbolPolyfill('toPrimitive')),
|
2990 | toStringTag: d('', (NativeSymbol && NativeSymbol.toStringTag) || SymbolPolyfill('toStringTag')),
|
2991 | unscopables: d('', (NativeSymbol && NativeSymbol.unscopables) || SymbolPolyfill('unscopables'))
|
2992 | });
|
2993 |
|
2994 |
|
2995 | defineProperties(HiddenSymbol.prototype, {
|
2996 | constructor: d(SymbolPolyfill),
|
2997 | toString: d('', function () { return this.__name__; })
|
2998 | });
|
2999 |
|
3000 |
|
3001 |
|
3002 | defineProperties(SymbolPolyfill.prototype, {
|
3003 | toString: d(function () { return 'Symbol (' + validateSymbol(this).__description__ + ')'; }),
|
3004 | valueOf: d(function () { return validateSymbol(this); })
|
3005 | });
|
3006 | defineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toPrimitive, d('', function () {
|
3007 | var symbol = validateSymbol(this);
|
3008 | if (typeof symbol === 'symbol') return symbol;
|
3009 | return symbol.toString();
|
3010 | }));
|
3011 | defineProperty(SymbolPolyfill.prototype, SymbolPolyfill.toStringTag, d('c', 'Symbol'));
|
3012 |
|
3013 |
|
3014 | defineProperty(HiddenSymbol.prototype, SymbolPolyfill.toStringTag,
|
3015 | d('c', SymbolPolyfill.prototype[SymbolPolyfill.toStringTag]));
|
3016 |
|
3017 |
|
3018 |
|
3019 |
|
3020 |
|
3021 | defineProperty(HiddenSymbol.prototype, SymbolPolyfill.toPrimitive,
|
3022 | d('c', SymbolPolyfill.prototype[SymbolPolyfill.toPrimitive]));
|
3023 |
|
3024 | },{"./validate-symbol":105,"d":34}],105:[function(require,module,exports){
|
3025 | arguments[4][63][0].apply(exports,arguments)
|
3026 | },{"./is-symbol":103,"dup":63}],106:[function(require,module,exports){
|
3027 | 'use strict';
|
3028 |
|
3029 | var d = require('d')
|
3030 | , callable = require('es5-ext/object/valid-callable')
|
3031 |
|
3032 | , apply = Function.prototype.apply, call = Function.prototype.call
|
3033 | , create = Object.create, defineProperty = Object.defineProperty
|
3034 | , defineProperties = Object.defineProperties
|
3035 | , hasOwnProperty = Object.prototype.hasOwnProperty
|
3036 | , descriptor = { configurable: true, enumerable: false, writable: true }
|
3037 |
|
3038 | , on, once, off, emit, methods, descriptors, base;
|
3039 |
|
3040 | on = function (type, listener) {
|
3041 | var data;
|
3042 |
|
3043 | callable(listener);
|
3044 |
|
3045 | if (!hasOwnProperty.call(this, '__ee__')) {
|
3046 | data = descriptor.value = create(null);
|
3047 | defineProperty(this, '__ee__', descriptor);
|
3048 | descriptor.value = null;
|
3049 | } else {
|
3050 | data = this.__ee__;
|
3051 | }
|
3052 | if (!data[type]) data[type] = listener;
|
3053 | else if (typeof data[type] === 'object') data[type].push(listener);
|
3054 | else data[type] = [data[type], listener];
|
3055 |
|
3056 | return this;
|
3057 | };
|
3058 |
|
3059 | once = function (type, listener) {
|
3060 | var once, self;
|
3061 |
|
3062 | callable(listener);
|
3063 | self = this;
|
3064 | on.call(this, type, once = function () {
|
3065 | off.call(self, type, once);
|
3066 | apply.call(listener, this, arguments);
|
3067 | });
|
3068 |
|
3069 | once.__eeOnceListener__ = listener;
|
3070 | return this;
|
3071 | };
|
3072 |
|
3073 | off = function (type, listener) {
|
3074 | var data, listeners, candidate, i;
|
3075 |
|
3076 | callable(listener);
|
3077 |
|
3078 | if (!hasOwnProperty.call(this, '__ee__')) return this;
|
3079 | data = this.__ee__;
|
3080 | if (!data[type]) return this;
|
3081 | listeners = data[type];
|
3082 |
|
3083 | if (typeof listeners === 'object') {
|
3084 | for (i = 0; (candidate = listeners[i]); ++i) {
|
3085 | if ((candidate === listener) ||
|
3086 | (candidate.__eeOnceListener__ === listener)) {
|
3087 | if (listeners.length === 2) data[type] = listeners[i ? 0 : 1];
|
3088 | else listeners.splice(i, 1);
|
3089 | }
|
3090 | }
|
3091 | } else {
|
3092 | if ((listeners === listener) ||
|
3093 | (listeners.__eeOnceListener__ === listener)) {
|
3094 | delete data[type];
|
3095 | }
|
3096 | }
|
3097 |
|
3098 | return this;
|
3099 | };
|
3100 |
|
3101 | emit = function (type) {
|
3102 | var i, l, listener, listeners, args;
|
3103 |
|
3104 | if (!hasOwnProperty.call(this, '__ee__')) return;
|
3105 | listeners = this.__ee__[type];
|
3106 | if (!listeners) return;
|
3107 |
|
3108 | if (typeof listeners === 'object') {
|
3109 | l = arguments.length;
|
3110 | args = new Array(l - 1);
|
3111 | for (i = 1; i < l; ++i) args[i - 1] = arguments[i];
|
3112 |
|
3113 | listeners = listeners.slice();
|
3114 | for (i = 0; (listener = listeners[i]); ++i) {
|
3115 | apply.call(listener, this, args);
|
3116 | }
|
3117 | } else {
|
3118 | switch (arguments.length) {
|
3119 | case 1:
|
3120 | call.call(listeners, this);
|
3121 | break;
|
3122 | case 2:
|
3123 | call.call(listeners, this, arguments[1]);
|
3124 | break;
|
3125 | case 3:
|
3126 | call.call(listeners, this, arguments[1], arguments[2]);
|
3127 | break;
|
3128 | default:
|
3129 | l = arguments.length;
|
3130 | args = new Array(l - 1);
|
3131 | for (i = 1; i < l; ++i) {
|
3132 | args[i - 1] = arguments[i];
|
3133 | }
|
3134 | apply.call(listeners, this, args);
|
3135 | }
|
3136 | }
|
3137 | };
|
3138 |
|
3139 | methods = {
|
3140 | on: on,
|
3141 | once: once,
|
3142 | off: off,
|
3143 | emit: emit
|
3144 | };
|
3145 |
|
3146 | descriptors = {
|
3147 | on: d(on),
|
3148 | once: d(once),
|
3149 | off: d(off),
|
3150 | emit: d(emit)
|
3151 | };
|
3152 |
|
3153 | base = defineProperties({}, descriptors);
|
3154 |
|
3155 | module.exports = exports = function (o) {
|
3156 | return (o == null) ? create(base) : defineProperties(Object(o), descriptors);
|
3157 | };
|
3158 | exports.methods = methods;
|
3159 |
|
3160 | },{"d":34,"es5-ext/object/valid-callable":88}],107:[function(require,module,exports){
|
3161 | 'use strict';
|
3162 |
|
3163 | var clear = require('es5-ext/array/#/clear')
|
3164 | , eIndexOf = require('es5-ext/array/#/e-index-of')
|
3165 | , setPrototypeOf = require('es5-ext/object/set-prototype-of')
|
3166 | , callable = require('es5-ext/object/valid-callable')
|
3167 | , validValue = require('es5-ext/object/valid-value')
|
3168 | , d = require('d')
|
3169 | , ee = require('event-emitter')
|
3170 | , Symbol = require('es6-symbol')
|
3171 | , iterator = require('es6-iterator/valid-iterable')
|
3172 | , forOf = require('es6-iterator/for-of')
|
3173 | , Iterator = require('./lib/iterator')
|
3174 | , isNative = require('./is-native-implemented')
|
3175 |
|
3176 | , call = Function.prototype.call
|
3177 | , defineProperties = Object.defineProperties, getPrototypeOf = Object.getPrototypeOf
|
3178 | , MapPoly;
|
3179 |
|
3180 | module.exports = MapPoly = function (/*iterable*/) {
|
3181 | var iterable = arguments[0], keys, values, self;
|
3182 | if (!(this instanceof MapPoly)) throw new TypeError('Constructor requires \'new\'');
|
3183 | if (isNative && setPrototypeOf && (Map !== MapPoly)) {
|
3184 | self = setPrototypeOf(new Map(), getPrototypeOf(this));
|
3185 | } else {
|
3186 | self = this;
|
3187 | }
|
3188 | if (iterable != null) iterator(iterable);
|
3189 | defineProperties(self, {
|
3190 | __mapKeysData__: d('c', keys = []),
|
3191 | __mapValuesData__: d('c', values = [])
|
3192 | });
|
3193 | if (!iterable) return self;
|
3194 | forOf(iterable, function (value) {
|
3195 | var key = validValue(value)[0];
|
3196 | value = value[1];
|
3197 | if (eIndexOf.call(keys, key) !== -1) return;
|
3198 | keys.push(key);
|
3199 | values.push(value);
|
3200 | }, self);
|
3201 | return self;
|
3202 | };
|
3203 |
|
3204 | if (isNative) {
|
3205 | if (setPrototypeOf) setPrototypeOf(MapPoly, Map);
|
3206 | MapPoly.prototype = Object.create(Map.prototype, {
|
3207 | constructor: d(MapPoly)
|
3208 | });
|
3209 | }
|
3210 |
|
3211 | ee(defineProperties(MapPoly.prototype, {
|
3212 | clear: d(function () {
|
3213 | if (!this.__mapKeysData__.length) return;
|
3214 | clear.call(this.__mapKeysData__);
|
3215 | clear.call(this.__mapValuesData__);
|
3216 | this.emit('_clear');
|
3217 | }),
|
3218 | delete: d(function (key) {
|
3219 | var index = eIndexOf.call(this.__mapKeysData__, key);
|
3220 | if (index === -1) return false;
|
3221 | this.__mapKeysData__.splice(index, 1);
|
3222 | this.__mapValuesData__.splice(index, 1);
|
3223 | this.emit('_delete', index, key);
|
3224 | return true;
|
3225 | }),
|
3226 | entries: d(function () { return new Iterator(this, 'key+value'); }),
|
3227 | forEach: d(function (cb/*, thisArg*/) {
|
3228 | var thisArg = arguments[1], iterator, result;
|
3229 | callable(cb);
|
3230 | iterator = this.entries();
|
3231 | result = iterator._next();
|
3232 | while (result !== undefined) {
|
3233 | call.call(cb, thisArg, this.__mapValuesData__[result],
|
3234 | this.__mapKeysData__[result], this);
|
3235 | result = iterator._next();
|
3236 | }
|
3237 | }),
|
3238 | get: d(function (key) {
|
3239 | var index = eIndexOf.call(this.__mapKeysData__, key);
|
3240 | if (index === -1) return;
|
3241 | return this.__mapValuesData__[index];
|
3242 | }),
|
3243 | has: d(function (key) {
|
3244 | return (eIndexOf.call(this.__mapKeysData__, key) !== -1);
|
3245 | }),
|
3246 | keys: d(function () { return new Iterator(this, 'key'); }),
|
3247 | set: d(function (key, value) {
|
3248 | var index = eIndexOf.call(this.__mapKeysData__, key), emit;
|
3249 | if (index === -1) {
|
3250 | index = this.__mapKeysData__.push(key) - 1;
|
3251 | emit = true;
|
3252 | }
|
3253 | this.__mapValuesData__[index] = value;
|
3254 | if (emit) this.emit('_add', index, key);
|
3255 | return this;
|
3256 | }),
|
3257 | size: d.gs(function () { return this.__mapKeysData__.length; }),
|
3258 | values: d(function () { return new Iterator(this, 'value'); }),
|
3259 | toString: d(function () { return '[object Map]'; })
|
3260 | }));
|
3261 | Object.defineProperty(MapPoly.prototype, Symbol.iterator, d(function () {
|
3262 | return this.entries();
|
3263 | }));
|
3264 | Object.defineProperty(MapPoly.prototype, Symbol.toStringTag, d('c', 'Map'));
|
3265 |
|
3266 | },{"./is-native-implemented":30,"./lib/iterator":32,"d":34,"es5-ext/array/#/clear":35,"es5-ext/array/#/e-index-of":36,"es5-ext/object/set-prototype-of":85,"es5-ext/object/valid-callable":88,"es5-ext/object/valid-value":89,"es6-iterator/for-of":95,"es6-iterator/valid-iterable":100,"es6-symbol":101,"event-emitter":106}],108:[function(require,module,exports){
|
3267 | (function (global){
|
3268 |
|
3269 | ;(function(root) {
|
3270 |
|
3271 |
|
3272 | var freeExports = typeof exports == 'object' && exports;
|
3273 |
|
3274 |
|
3275 | var freeModule = typeof module == 'object' && module &&
|
3276 | module.exports == freeExports && module;
|
3277 |
|
3278 |
|
3279 |
|
3280 | var freeGlobal = typeof global == 'object' && global;
|
3281 | if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
|
3282 | root = freeGlobal;
|
3283 | }
|
3284 |
|
3285 |
|
3286 |
|
3287 | var regexSymbolWithCombiningMarks = /([\0-\u02FF\u0370-\u1AAF\u1B00-\u1DBF\u1E00-\u20CF\u2100-\uD7FF\uE000-\uFE1F\uFE30-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])([\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]+)/g;
|
3288 | var regexSurrogatePair = /([\uD800-\uDBFF])([\uDC00-\uDFFF])/g;
|
3289 |
|
3290 | var reverse = function(string) {
|
3291 |
|
3292 | string = string
|
3293 |
|
3294 | .replace(regexSymbolWithCombiningMarks, function($0, $1, $2) {
|
3295 |
|
3296 |
|
3297 | return reverse($2) + $1;
|
3298 | })
|
3299 |
|
3300 | .replace(regexSurrogatePair, '$2$1');
|
3301 |
|
3302 | var result = '';
|
3303 | var index = string.length;
|
3304 | while (index--) {
|
3305 | result += string.charAt(index);
|
3306 | }
|
3307 | return result;
|
3308 | };
|
3309 |
|
3310 |
|
3311 |
|
3312 | var esrever = {
|
3313 | 'version': '0.2.0',
|
3314 | 'reverse': reverse
|
3315 | };
|
3316 |
|
3317 |
|
3318 |
|
3319 | if (
|
3320 | typeof define == 'function' &&
|
3321 | typeof define.amd == 'object' &&
|
3322 | define.amd
|
3323 | ) {
|
3324 | define(function() {
|
3325 | return esrever;
|
3326 | });
|
3327 | } else if (freeExports && !freeExports.nodeType) {
|
3328 | if (freeModule) {
|
3329 | freeModule.exports = esrever;
|
3330 | } else {
|
3331 | for (var key in esrever) {
|
3332 | esrever.hasOwnProperty(key) && (freeExports[key] = esrever[key]);
|
3333 | }
|
3334 | }
|
3335 | } else {
|
3336 | root.esrever = esrever;
|
3337 | }
|
3338 |
|
3339 | }(this));
|
3340 |
|
3341 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3342 | },{}],109:[function(require,module,exports){
|
3343 | (function (process){
|
3344 | 'use strict';
|
3345 |
|
3346 |
|
3347 |
|
3348 |
|
3349 |
|
3350 |
|
3351 |
|
3352 |
|
3353 |
|
3354 |
|
3355 |
|
3356 |
|
3357 |
|
3358 |
|
3359 |
|
3360 |
|
3361 |
|
3362 |
|
3363 |
|
3364 | var emptyFunction = require('./emptyFunction');
|
3365 |
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 | var EventListener = {
|
3371 | |
3372 |
|
3373 |
|
3374 |
|
3375 |
|
3376 |
|
3377 |
|
3378 |
|
3379 | listen: function listen(target, eventType, callback) {
|
3380 | if (target.addEventListener) {
|
3381 | target.addEventListener(eventType, callback, false);
|
3382 | return {
|
3383 | remove: function remove() {
|
3384 | target.removeEventListener(eventType, callback, false);
|
3385 | }
|
3386 | };
|
3387 | } else if (target.attachEvent) {
|
3388 | target.attachEvent('on' + eventType, callback);
|
3389 | return {
|
3390 | remove: function remove() {
|
3391 | target.detachEvent('on' + eventType, callback);
|
3392 | }
|
3393 | };
|
3394 | }
|
3395 | },
|
3396 |
|
3397 | |
3398 |
|
3399 |
|
3400 |
|
3401 |
|
3402 |
|
3403 |
|
3404 |
|
3405 | capture: function capture(target, eventType, callback) {
|
3406 | if (target.addEventListener) {
|
3407 | target.addEventListener(eventType, callback, true);
|
3408 | return {
|
3409 | remove: function remove() {
|
3410 | target.removeEventListener(eventType, callback, true);
|
3411 | }
|
3412 | };
|
3413 | } else {
|
3414 | if (process.env.NODE_ENV !== 'production') {
|
3415 | console.error('Attempted to listen to events during the capture phase on a ' + 'browser that does not support the capture phase. Your application ' + 'will not receive some events.');
|
3416 | }
|
3417 | return {
|
3418 | remove: emptyFunction
|
3419 | };
|
3420 | }
|
3421 | },
|
3422 |
|
3423 | registerDefault: function registerDefault() {}
|
3424 | };
|
3425 |
|
3426 | module.exports = EventListener;
|
3427 | }).call(this,require('_process'))
|
3428 | },{"./emptyFunction":116,"_process":144}],110:[function(require,module,exports){
|
3429 |
|
3430 |
|
3431 |
|
3432 |
|
3433 |
|
3434 |
|
3435 |
|
3436 |
|
3437 |
|
3438 |
|
3439 | 'use strict';
|
3440 |
|
3441 | var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
3442 |
|
3443 |
|
3444 |
|
3445 |
|
3446 |
|
3447 |
|
3448 |
|
3449 | var ExecutionEnvironment = {
|
3450 |
|
3451 | canUseDOM: canUseDOM,
|
3452 |
|
3453 | canUseWorkers: typeof Worker !== 'undefined',
|
3454 |
|
3455 | canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent),
|
3456 |
|
3457 | canUseViewport: canUseDOM && !!window.screen,
|
3458 |
|
3459 | isInWorker: !canUseDOM
|
3460 |
|
3461 | };
|
3462 |
|
3463 | module.exports = ExecutionEnvironment;
|
3464 | },{}],111:[function(require,module,exports){
|
3465 | "use strict";
|
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 |
|
3474 |
|
3475 |
|
3476 |
|
3477 |
|
3478 | var _hyphenPattern = /-(.)/g;
|
3479 |
|
3480 |
|
3481 |
|
3482 |
|
3483 |
|
3484 |
|
3485 |
|
3486 |
|
3487 |
|
3488 |
|
3489 | function camelize(string) {
|
3490 | return string.replace(_hyphenPattern, function (_, character) {
|
3491 | return character.toUpperCase();
|
3492 | });
|
3493 | }
|
3494 |
|
3495 | module.exports = camelize;
|
3496 | },{}],112:[function(require,module,exports){
|
3497 |
|
3498 |
|
3499 |
|
3500 |
|
3501 |
|
3502 |
|
3503 |
|
3504 |
|
3505 |
|
3506 |
|
3507 |
|
3508 | 'use strict';
|
3509 |
|
3510 | var camelize = require('./camelize');
|
3511 |
|
3512 | var msPattern = /^-ms-/;
|
3513 |
|
3514 |
|
3515 |
|
3516 |
|
3517 |
|
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 | function camelizeStyleName(string) {
|
3532 | return camelize(string.replace(msPattern, 'ms-'));
|
3533 | }
|
3534 |
|
3535 | module.exports = camelizeStyleName;
|
3536 | },{"./camelize":111}],113:[function(require,module,exports){
|
3537 | 'use strict';
|
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 |
|
3547 |
|
3548 |
|
3549 |
|
3550 | var isTextNode = require('./isTextNode');
|
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 | function containsNode(outerNode, innerNode) {
|
3558 | if (!outerNode || !innerNode) {
|
3559 | return false;
|
3560 | } else if (outerNode === innerNode) {
|
3561 | return true;
|
3562 | } else if (isTextNode(outerNode)) {
|
3563 | return false;
|
3564 | } else if (isTextNode(innerNode)) {
|
3565 | return containsNode(outerNode, innerNode.parentNode);
|
3566 | } else if ('contains' in outerNode) {
|
3567 | return outerNode.contains(innerNode);
|
3568 | } else if (outerNode.compareDocumentPosition) {
|
3569 | return !!(outerNode.compareDocumentPosition(innerNode) & 16);
|
3570 | } else {
|
3571 | return false;
|
3572 | }
|
3573 | }
|
3574 |
|
3575 | module.exports = containsNode;
|
3576 | },{"./isTextNode":126}],114:[function(require,module,exports){
|
3577 | (function (process){
|
3578 | 'use strict';
|
3579 |
|
3580 |
|
3581 |
|
3582 |
|
3583 |
|
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 |
|
3589 |
|
3590 |
|
3591 | var invariant = require('./invariant');
|
3592 |
|
3593 |
|
3594 |
|
3595 |
|
3596 |
|
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 |
|
3602 | function toArray(obj) {
|
3603 | var length = obj.length;
|
3604 |
|
3605 |
|
3606 |
|
3607 | !(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Array-like object expected') : invariant(false) : void 0;
|
3608 |
|
3609 | !(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object needs a length property') : invariant(false) : void 0;
|
3610 |
|
3611 | !(length === 0 || length - 1 in obj) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object should have keys for indices') : invariant(false) : void 0;
|
3612 |
|
3613 | !(typeof obj.callee !== 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object can\'t be `arguments`. Use rest params ' + '(function(...args) {}) or Array.from() instead.') : invariant(false) : void 0;
|
3614 |
|
3615 |
|
3616 |
|
3617 |
|
3618 | if (obj.hasOwnProperty) {
|
3619 | try {
|
3620 | return Array.prototype.slice.call(obj);
|
3621 | } catch (e) {
|
3622 |
|
3623 | }
|
3624 | }
|
3625 |
|
3626 |
|
3627 |
|
3628 | var ret = Array(length);
|
3629 | for (var ii = 0; ii < length; ii++) {
|
3630 | ret[ii] = obj[ii];
|
3631 | }
|
3632 | return ret;
|
3633 | }
|
3634 |
|
3635 |
|
3636 |
|
3637 |
|
3638 |
|
3639 |
|
3640 |
|
3641 |
|
3642 |
|
3643 |
|
3644 |
|
3645 |
|
3646 |
|
3647 |
|
3648 |
|
3649 |
|
3650 | function hasArrayNature(obj) {
|
3651 | return (
|
3652 |
|
3653 | !!obj && (
|
3654 |
|
3655 | typeof obj == 'object' || typeof obj == 'function') &&
|
3656 |
|
3657 | 'length' in obj &&
|
3658 |
|
3659 | !('setInterval' in obj) &&
|
3660 |
|
3661 |
|
3662 | typeof obj.nodeType != 'number' && (
|
3663 |
|
3664 | Array.isArray(obj) ||
|
3665 |
|
3666 | 'callee' in obj ||
|
3667 |
|
3668 | 'item' in obj)
|
3669 | );
|
3670 | }
|
3671 |
|
3672 |
|
3673 |
|
3674 |
|
3675 |
|
3676 |
|
3677 |
|
3678 |
|
3679 |
|
3680 |
|
3681 |
|
3682 |
|
3683 |
|
3684 |
|
3685 |
|
3686 |
|
3687 |
|
3688 |
|
3689 |
|
3690 |
|
3691 |
|
3692 |
|
3693 | function createArrayFromMixed(obj) {
|
3694 | if (!hasArrayNature(obj)) {
|
3695 | return [obj];
|
3696 | } else if (Array.isArray(obj)) {
|
3697 | return obj.slice();
|
3698 | } else {
|
3699 | return toArray(obj);
|
3700 | }
|
3701 | }
|
3702 |
|
3703 | module.exports = createArrayFromMixed;
|
3704 | }).call(this,require('_process'))
|
3705 | },{"./invariant":124,"_process":144}],115:[function(require,module,exports){
|
3706 | (function (process){
|
3707 | 'use strict';
|
3708 |
|
3709 |
|
3710 |
|
3711 |
|
3712 |
|
3713 |
|
3714 |
|
3715 |
|
3716 |
|
3717 |
|
3718 |
|
3719 |
|
3720 |
|
3721 |
|
3722 | var ExecutionEnvironment = require('./ExecutionEnvironment');
|
3723 |
|
3724 | var createArrayFromMixed = require('./createArrayFromMixed');
|
3725 | var getMarkupWrap = require('./getMarkupWrap');
|
3726 | var invariant = require('./invariant');
|
3727 |
|
3728 |
|
3729 |
|
3730 |
|
3731 | var dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null;
|
3732 |
|
3733 |
|
3734 |
|
3735 |
|
3736 | var nodeNamePattern = /^\s*<(\w+)/;
|
3737 |
|
3738 |
|
3739 |
|
3740 |
|
3741 |
|
3742 |
|
3743 |
|
3744 | function getNodeName(markup) {
|
3745 | var nodeNameMatch = markup.match(nodeNamePattern);
|
3746 | return nodeNameMatch && nodeNameMatch[1].toLowerCase();
|
3747 | }
|
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 |
|
3755 |
|
3756 |
|
3757 |
|
3758 |
|
3759 | function createNodesFromMarkup(markup, handleScript) {
|
3760 | var node = dummyNode;
|
3761 | !!!dummyNode ? process.env.NODE_ENV !== 'production' ? invariant(false, 'createNodesFromMarkup dummy not initialized') : invariant(false) : void 0;
|
3762 | var nodeName = getNodeName(markup);
|
3763 |
|
3764 | var wrap = nodeName && getMarkupWrap(nodeName);
|
3765 | if (wrap) {
|
3766 | node.innerHTML = wrap[1] + markup + wrap[2];
|
3767 |
|
3768 | var wrapDepth = wrap[0];
|
3769 | while (wrapDepth--) {
|
3770 | node = node.lastChild;
|
3771 | }
|
3772 | } else {
|
3773 | node.innerHTML = markup;
|
3774 | }
|
3775 |
|
3776 | var scripts = node.getElementsByTagName('script');
|
3777 | if (scripts.length) {
|
3778 | !handleScript ? process.env.NODE_ENV !== 'production' ? invariant(false, 'createNodesFromMarkup(...): Unexpected <script> element rendered.') : invariant(false) : void 0;
|
3779 | createArrayFromMixed(scripts).forEach(handleScript);
|
3780 | }
|
3781 |
|
3782 | var nodes = Array.from(node.childNodes);
|
3783 | while (node.lastChild) {
|
3784 | node.removeChild(node.lastChild);
|
3785 | }
|
3786 | return nodes;
|
3787 | }
|
3788 |
|
3789 | module.exports = createNodesFromMarkup;
|
3790 | }).call(this,require('_process'))
|
3791 | },{"./ExecutionEnvironment":110,"./createArrayFromMixed":114,"./getMarkupWrap":120,"./invariant":124,"_process":144}],116:[function(require,module,exports){
|
3792 | "use strict";
|
3793 |
|
3794 |
|
3795 |
|
3796 |
|
3797 |
|
3798 |
|
3799 |
|
3800 |
|
3801 |
|
3802 |
|
3803 |
|
3804 |
|
3805 | function makeEmptyFunction(arg) {
|
3806 | return function () {
|
3807 | return arg;
|
3808 | };
|
3809 | }
|
3810 |
|
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 | var emptyFunction = function emptyFunction() {};
|
3817 |
|
3818 | emptyFunction.thatReturns = makeEmptyFunction;
|
3819 | emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
|
3820 | emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
|
3821 | emptyFunction.thatReturnsNull = makeEmptyFunction(null);
|
3822 | emptyFunction.thatReturnsThis = function () {
|
3823 | return this;
|
3824 | };
|
3825 | emptyFunction.thatReturnsArgument = function (arg) {
|
3826 | return arg;
|
3827 | };
|
3828 |
|
3829 | module.exports = emptyFunction;
|
3830 | },{}],117:[function(require,module,exports){
|
3831 | (function (process){
|
3832 |
|
3833 |
|
3834 |
|
3835 |
|
3836 |
|
3837 |
|
3838 |
|
3839 |
|
3840 |
|
3841 |
|
3842 | 'use strict';
|
3843 |
|
3844 | var emptyObject = {};
|
3845 |
|
3846 | if (process.env.NODE_ENV !== 'production') {
|
3847 | Object.freeze(emptyObject);
|
3848 | }
|
3849 |
|
3850 | module.exports = emptyObject;
|
3851 | }).call(this,require('_process'))
|
3852 | },{"_process":144}],118:[function(require,module,exports){
|
3853 |
|
3854 |
|
3855 |
|
3856 |
|
3857 |
|
3858 |
|
3859 |
|
3860 |
|
3861 |
|
3862 |
|
3863 | 'use strict';
|
3864 |
|
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 | function focusNode(node) {
|
3870 |
|
3871 |
|
3872 |
|
3873 | try {
|
3874 | node.focus();
|
3875 | } catch (e) {}
|
3876 | }
|
3877 |
|
3878 | module.exports = focusNode;
|
3879 | },{}],119:[function(require,module,exports){
|
3880 | 'use strict';
|
3881 |
|
3882 |
|
3883 |
|
3884 |
|
3885 |
|
3886 |
|
3887 |
|
3888 |
|
3889 |
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 |
|
3900 |
|
3901 |
|
3902 | function getActiveElement() /*?DOMElement*/{
|
3903 | if (typeof document === 'undefined') {
|
3904 | return null;
|
3905 | }
|
3906 | try {
|
3907 | return document.activeElement || document.body;
|
3908 | } catch (e) {
|
3909 | return document.body;
|
3910 | }
|
3911 | }
|
3912 |
|
3913 | module.exports = getActiveElement;
|
3914 | },{}],120:[function(require,module,exports){
|
3915 | (function (process){
|
3916 | 'use strict';
|
3917 |
|
3918 |
|
3919 |
|
3920 |
|
3921 |
|
3922 |
|
3923 |
|
3924 |
|
3925 |
|
3926 |
|
3927 |
|
3928 |
|
3929 |
|
3930 | var ExecutionEnvironment = require('./ExecutionEnvironment');
|
3931 |
|
3932 | var invariant = require('./invariant');
|
3933 |
|
3934 |
|
3935 |
|
3936 |
|
3937 | var dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null;
|
3938 |
|
3939 |
|
3940 |
|
3941 |
|
3942 |
|
3943 |
|
3944 |
|
3945 |
|
3946 | var shouldWrap = {};
|
3947 |
|
3948 | var selectWrap = [1, '<select multiple="true">', '</select>'];
|
3949 | var tableWrap = [1, '<table>', '</table>'];
|
3950 | var trWrap = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
|
3951 |
|
3952 | var svgWrap = [1, '<svg xmlns="http://www.w3.org/2000/svg">', '</svg>'];
|
3953 |
|
3954 | var markupWrap = {
|
3955 | '*': [1, '?<div>', '</div>'],
|
3956 |
|
3957 | 'area': [1, '<map>', '</map>'],
|
3958 | 'col': [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
|
3959 | 'legend': [1, '<fieldset>', '</fieldset>'],
|
3960 | 'param': [1, '<object>', '</object>'],
|
3961 | 'tr': [2, '<table><tbody>', '</tbody></table>'],
|
3962 |
|
3963 | 'optgroup': selectWrap,
|
3964 | 'option': selectWrap,
|
3965 |
|
3966 | 'caption': tableWrap,
|
3967 | 'colgroup': tableWrap,
|
3968 | 'tbody': tableWrap,
|
3969 | 'tfoot': tableWrap,
|
3970 | 'thead': tableWrap,
|
3971 |
|
3972 | 'td': trWrap,
|
3973 | 'th': trWrap
|
3974 | };
|
3975 |
|
3976 |
|
3977 |
|
3978 |
|
3979 | var svgElements = ['circle', 'clipPath', 'defs', 'ellipse', 'g', 'image', 'line', 'linearGradient', 'mask', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'stop', 'text', 'tspan'];
|
3980 | svgElements.forEach(function (nodeName) {
|
3981 | markupWrap[nodeName] = svgWrap;
|
3982 | shouldWrap[nodeName] = true;
|
3983 | });
|
3984 |
|
3985 |
|
3986 |
|
3987 |
|
3988 |
|
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 | function getMarkupWrap(nodeName) {
|
3994 | !!!dummyNode ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Markup wrapping node not initialized') : invariant(false) : void 0;
|
3995 | if (!markupWrap.hasOwnProperty(nodeName)) {
|
3996 | nodeName = '*';
|
3997 | }
|
3998 | if (!shouldWrap.hasOwnProperty(nodeName)) {
|
3999 | if (nodeName === '*') {
|
4000 | dummyNode.innerHTML = '<link />';
|
4001 | } else {
|
4002 | dummyNode.innerHTML = '<' + nodeName + '></' + nodeName + '>';
|
4003 | }
|
4004 | shouldWrap[nodeName] = !dummyNode.firstChild;
|
4005 | }
|
4006 | return shouldWrap[nodeName] ? markupWrap[nodeName] : null;
|
4007 | }
|
4008 |
|
4009 | module.exports = getMarkupWrap;
|
4010 | }).call(this,require('_process'))
|
4011 | },{"./ExecutionEnvironment":110,"./invariant":124,"_process":144}],121:[function(require,module,exports){
|
4012 |
|
4013 |
|
4014 |
|
4015 |
|
4016 |
|
4017 |
|
4018 |
|
4019 |
|
4020 |
|
4021 |
|
4022 |
|
4023 | 'use strict';
|
4024 |
|
4025 |
|
4026 |
|
4027 |
|
4028 |
|
4029 |
|
4030 |
|
4031 |
|
4032 |
|
4033 |
|
4034 |
|
4035 |
|
4036 | function getUnboundedScrollPosition(scrollable) {
|
4037 | if (scrollable === window) {
|
4038 | return {
|
4039 | x: window.pageXOffset || document.documentElement.scrollLeft,
|
4040 | y: window.pageYOffset || document.documentElement.scrollTop
|
4041 | };
|
4042 | }
|
4043 | return {
|
4044 | x: scrollable.scrollLeft,
|
4045 | y: scrollable.scrollTop
|
4046 | };
|
4047 | }
|
4048 |
|
4049 | module.exports = getUnboundedScrollPosition;
|
4050 | },{}],122:[function(require,module,exports){
|
4051 | 'use strict';
|
4052 |
|
4053 |
|
4054 |
|
4055 |
|
4056 |
|
4057 |
|
4058 |
|
4059 |
|
4060 |
|
4061 |
|
4062 |
|
4063 |
|
4064 | var _uppercasePattern = /([A-Z])/g;
|
4065 |
|
4066 |
|
4067 |
|
4068 |
|
4069 |
|
4070 |
|
4071 |
|
4072 |
|
4073 |
|
4074 |
|
4075 |
|
4076 |
|
4077 |
|
4078 | function hyphenate(string) {
|
4079 | return string.replace(_uppercasePattern, '-$1').toLowerCase();
|
4080 | }
|
4081 |
|
4082 | module.exports = hyphenate;
|
4083 | },{}],123:[function(require,module,exports){
|
4084 |
|
4085 |
|
4086 |
|
4087 |
|
4088 |
|
4089 |
|
4090 |
|
4091 |
|
4092 |
|
4093 |
|
4094 |
|
4095 | 'use strict';
|
4096 |
|
4097 | var hyphenate = require('./hyphenate');
|
4098 |
|
4099 | var msPattern = /^ms-/;
|
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 |
|
4105 |
|
4106 |
|
4107 |
|
4108 |
|
4109 |
|
4110 |
|
4111 |
|
4112 |
|
4113 |
|
4114 |
|
4115 |
|
4116 |
|
4117 | function hyphenateStyleName(string) {
|
4118 | return hyphenate(string).replace(msPattern, '-ms-');
|
4119 | }
|
4120 |
|
4121 | module.exports = hyphenateStyleName;
|
4122 | },{"./hyphenate":122}],124:[function(require,module,exports){
|
4123 | (function (process){
|
4124 |
|
4125 |
|
4126 |
|
4127 |
|
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 |
|
4133 |
|
4134 | 'use strict';
|
4135 |
|
4136 |
|
4137 |
|
4138 |
|
4139 |
|
4140 |
|
4141 |
|
4142 |
|
4143 |
|
4144 |
|
4145 |
|
4146 |
|
4147 | function invariant(condition, format, a, b, c, d, e, f) {
|
4148 | if (process.env.NODE_ENV !== 'production') {
|
4149 | if (format === undefined) {
|
4150 | throw new Error('invariant requires an error message argument');
|
4151 | }
|
4152 | }
|
4153 |
|
4154 | if (!condition) {
|
4155 | var error;
|
4156 | if (format === undefined) {
|
4157 | error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
|
4158 | } else {
|
4159 | var args = [a, b, c, d, e, f];
|
4160 | var argIndex = 0;
|
4161 | error = new Error(format.replace(/%s/g, function () {
|
4162 | return args[argIndex++];
|
4163 | }));
|
4164 | error.name = 'Invariant Violation';
|
4165 | }
|
4166 |
|
4167 | error.framesToPop = 1;
|
4168 | throw error;
|
4169 | }
|
4170 | }
|
4171 |
|
4172 | module.exports = invariant;
|
4173 | }).call(this,require('_process'))
|
4174 | },{"_process":144}],125:[function(require,module,exports){
|
4175 | 'use strict';
|
4176 |
|
4177 |
|
4178 |
|
4179 |
|
4180 |
|
4181 |
|
4182 |
|
4183 |
|
4184 |
|
4185 |
|
4186 |
|
4187 |
|
4188 |
|
4189 |
|
4190 |
|
4191 |
|
4192 | function isNode(object) {
|
4193 | return !!(object && (typeof Node === 'function' ? object instanceof Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
|
4194 | }
|
4195 |
|
4196 | module.exports = isNode;
|
4197 | },{}],126:[function(require,module,exports){
|
4198 | 'use strict';
|
4199 |
|
4200 |
|
4201 |
|
4202 |
|
4203 |
|
4204 |
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 |
|
4210 |
|
4211 | var isNode = require('./isNode');
|
4212 |
|
4213 |
|
4214 |
|
4215 |
|
4216 |
|
4217 | function isTextNode(object) {
|
4218 | return isNode(object) && object.nodeType == 3;
|
4219 | }
|
4220 |
|
4221 | module.exports = isTextNode;
|
4222 | },{"./isNode":125}],127:[function(require,module,exports){
|
4223 |
|
4224 |
|
4225 |
|
4226 |
|
4227 |
|
4228 |
|
4229 |
|
4230 |
|
4231 |
|
4232 |
|
4233 |
|
4234 |
|
4235 | 'use strict';
|
4236 |
|
4237 |
|
4238 |
|
4239 |
|
4240 |
|
4241 | function memoizeStringOnly(callback) {
|
4242 | var cache = {};
|
4243 | return function (string) {
|
4244 | if (!cache.hasOwnProperty(string)) {
|
4245 | cache[string] = callback.call(this, string);
|
4246 | }
|
4247 | return cache[string];
|
4248 | };
|
4249 | }
|
4250 |
|
4251 | module.exports = memoizeStringOnly;
|
4252 | },{}],128:[function(require,module,exports){
|
4253 |
|
4254 |
|
4255 |
|
4256 |
|
4257 |
|
4258 |
|
4259 |
|
4260 |
|
4261 |
|
4262 |
|
4263 |
|
4264 | 'use strict';
|
4265 |
|
4266 | var ExecutionEnvironment = require('./ExecutionEnvironment');
|
4267 |
|
4268 | var performance;
|
4269 |
|
4270 | if (ExecutionEnvironment.canUseDOM) {
|
4271 | performance = window.performance || window.msPerformance || window.webkitPerformance;
|
4272 | }
|
4273 |
|
4274 | module.exports = performance || {};
|
4275 | },{"./ExecutionEnvironment":110}],129:[function(require,module,exports){
|
4276 | 'use strict';
|
4277 |
|
4278 |
|
4279 |
|
4280 |
|
4281 |
|
4282 |
|
4283 |
|
4284 |
|
4285 |
|
4286 |
|
4287 |
|
4288 |
|
4289 | var performance = require('./performance');
|
4290 |
|
4291 | var performanceNow;
|
4292 |
|
4293 |
|
4294 |
|
4295 |
|
4296 |
|
4297 |
|
4298 | if (performance.now) {
|
4299 | performanceNow = function performanceNow() {
|
4300 | return performance.now();
|
4301 | };
|
4302 | } else {
|
4303 | performanceNow = function performanceNow() {
|
4304 | return Date.now();
|
4305 | };
|
4306 | }
|
4307 |
|
4308 | module.exports = performanceNow;
|
4309 | },{"./performance":128}],130:[function(require,module,exports){
|
4310 |
|
4311 |
|
4312 |
|
4313 |
|
4314 |
|
4315 |
|
4316 |
|
4317 |
|
4318 |
|
4319 |
|
4320 |
|
4321 |
|
4322 |
|
4323 |
|
4324 | 'use strict';
|
4325 |
|
4326 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
4327 |
|
4328 |
|
4329 |
|
4330 |
|
4331 |
|
4332 | function is(x, y) {
|
4333 |
|
4334 | if (x === y) {
|
4335 |
|
4336 |
|
4337 |
|
4338 | return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
4339 | } else {
|
4340 |
|
4341 | return x !== x && y !== y;
|
4342 | }
|
4343 | }
|
4344 |
|
4345 |
|
4346 |
|
4347 |
|
4348 |
|
4349 |
|
4350 | function shallowEqual(objA, objB) {
|
4351 | if (is(objA, objB)) {
|
4352 | return true;
|
4353 | }
|
4354 |
|
4355 | if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
4356 | return false;
|
4357 | }
|
4358 |
|
4359 | var keysA = Object.keys(objA);
|
4360 | var keysB = Object.keys(objB);
|
4361 |
|
4362 | if (keysA.length !== keysB.length) {
|
4363 | return false;
|
4364 | }
|
4365 |
|
4366 |
|
4367 | for (var i = 0; i < keysA.length; i++) {
|
4368 | if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
|
4369 | return false;
|
4370 | }
|
4371 | }
|
4372 |
|
4373 | return true;
|
4374 | }
|
4375 |
|
4376 | module.exports = shallowEqual;
|
4377 | },{}],131:[function(require,module,exports){
|
4378 | (function (process){
|
4379 |
|
4380 |
|
4381 |
|
4382 |
|
4383 |
|
4384 |
|
4385 |
|
4386 |
|
4387 |
|
4388 |
|
4389 | 'use strict';
|
4390 |
|
4391 | var emptyFunction = require('./emptyFunction');
|
4392 |
|
4393 |
|
4394 |
|
4395 |
|
4396 |
|
4397 |
|
4398 |
|
4399 |
|
4400 | var warning = emptyFunction;
|
4401 |
|
4402 | if (process.env.NODE_ENV !== 'production') {
|
4403 | (function () {
|
4404 | var printWarning = function printWarning(format) {
|
4405 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
4406 | args[_key - 1] = arguments[_key];
|
4407 | }
|
4408 |
|
4409 | var argIndex = 0;
|
4410 | var message = 'Warning: ' + format.replace(/%s/g, function () {
|
4411 | return args[argIndex++];
|
4412 | });
|
4413 | if (typeof console !== 'undefined') {
|
4414 | console.error(message);
|
4415 | }
|
4416 | try {
|
4417 |
|
4418 |
|
4419 |
|
4420 | throw new Error(message);
|
4421 | } catch (x) {}
|
4422 | };
|
4423 |
|
4424 | warning = function warning(condition, format) {
|
4425 | if (format === undefined) {
|
4426 | throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
|
4427 | }
|
4428 |
|
4429 | if (format.indexOf('Failed Composite propType: ') === 0) {
|
4430 | return;
|
4431 | }
|
4432 |
|
4433 | if (!condition) {
|
4434 | for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
4435 | args[_key2 - 2] = arguments[_key2];
|
4436 | }
|
4437 |
|
4438 | printWarning.apply(undefined, [format].concat(args));
|
4439 | }
|
4440 | };
|
4441 | })();
|
4442 | }
|
4443 |
|
4444 | module.exports = warning;
|
4445 | }).call(this,require('_process'))
|
4446 | },{"./emptyFunction":116,"_process":144}],132:[function(require,module,exports){
|
4447 |
|
4448 |
|
4449 |
|
4450 |
|
4451 |
|
4452 | module.exports = getDocument;
|
4453 |
|
4454 |
|
4455 | var DOCUMENT_NODE = 9;
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 | function isDocument (d) {
|
4466 | return d && d.nodeType === DOCUMENT_NODE;
|
4467 | }
|
4468 |
|
4469 |
|
4470 |
|
4471 |
|
4472 |
|
4473 |
|
4474 |
|
4475 |
|
4476 |
|
4477 |
|
4478 |
|
4479 | function getDocument(node) {
|
4480 | if (isDocument(node)) {
|
4481 | return node;
|
4482 |
|
4483 | } else if (isDocument(node.ownerDocument)) {
|
4484 | return node.ownerDocument;
|
4485 |
|
4486 | } else if (isDocument(node.document)) {
|
4487 | return node.document;
|
4488 |
|
4489 | } else if (node.parentNode) {
|
4490 | return getDocument(node.parentNode);
|
4491 |
|
4492 |
|
4493 | } else if (node.commonAncestorContainer) {
|
4494 | return getDocument(node.commonAncestorContainer);
|
4495 |
|
4496 | } else if (node.startContainer) {
|
4497 | return getDocument(node.startContainer);
|
4498 |
|
4499 |
|
4500 | } else if (node.anchorNode) {
|
4501 | return getDocument(node.anchorNode);
|
4502 | }
|
4503 | }
|
4504 |
|
4505 | },{}],133:[function(require,module,exports){
|
4506 |
|
4507 |
|
4508 |
|
4509 |
|
4510 |
|
4511 | var getDocument = require('get-document');
|
4512 |
|
4513 |
|
4514 |
|
4515 |
|
4516 |
|
4517 | module.exports = getWindow;
|
4518 |
|
4519 | var needsIEFallback = require('./needs-ie-fallback');
|
4520 |
|
4521 |
|
4522 |
|
4523 |
|
4524 |
|
4525 |
|
4526 |
|
4527 |
|
4528 |
|
4529 | function isWindow (w) {
|
4530 | return w && w.window === w;
|
4531 | }
|
4532 |
|
4533 |
|
4534 |
|
4535 |
|
4536 |
|
4537 |
|
4538 |
|
4539 |
|
4540 |
|
4541 |
|
4542 |
|
4543 | function getWindow(node) {
|
4544 | if (isWindow(node)) {
|
4545 | return node;
|
4546 | }
|
4547 |
|
4548 | var doc = getDocument(node);
|
4549 |
|
4550 | if (needsIEFallback) {
|
4551 |
|
4552 |
|
4553 | doc.parentWindow.execScript('document._parentWindow = window;', 'Javascript');
|
4554 | var win = doc._parentWindow;
|
4555 |
|
4556 |
|
4557 |
|
4558 | doc._parentWindow = null;
|
4559 | return win;
|
4560 | } else {
|
4561 |
|
4562 | return doc.defaultView || doc.parentWindow;
|
4563 | }
|
4564 | }
|
4565 |
|
4566 | },{"./needs-ie-fallback":134,"get-document":132}],134:[function(require,module,exports){
|
4567 |
|
4568 |
|
4569 |
|
4570 | module.exports = !!document.attachEvent && window !== document.parentWindow;
|
4571 |
|
4572 | },{}],135:[function(require,module,exports){
|
4573 |
|
4574 |
|
4575 |
|
4576 |
|
4577 |
|
4578 |
|
4579 |
|
4580 |
|
4581 |
|
4582 | (function (global, factory) {
|
4583 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
4584 | typeof define === 'function' && define.amd ? define(factory) :
|
4585 | (global.Immutable = factory());
|
4586 | }(this, function () { 'use strict';var SLICE$0 = Array.prototype.slice;
|
4587 |
|
4588 | function createClass(ctor, superClass) {
|
4589 | if (superClass) {
|
4590 | ctor.prototype = Object.create(superClass.prototype);
|
4591 | }
|
4592 | ctor.prototype.constructor = ctor;
|
4593 | }
|
4594 |
|
4595 | function Iterable(value) {
|
4596 | return isIterable(value) ? value : Seq(value);
|
4597 | }
|
4598 |
|
4599 |
|
4600 | createClass(KeyedIterable, Iterable);
|
4601 | function KeyedIterable(value) {
|
4602 | return isKeyed(value) ? value : KeyedSeq(value);
|
4603 | }
|
4604 |
|
4605 |
|
4606 | createClass(IndexedIterable, Iterable);
|
4607 | function IndexedIterable(value) {
|
4608 | return isIndexed(value) ? value : IndexedSeq(value);
|
4609 | }
|
4610 |
|
4611 |
|
4612 | createClass(SetIterable, Iterable);
|
4613 | function SetIterable(value) {
|
4614 | return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
|
4615 | }
|
4616 |
|
4617 |
|
4618 |
|
4619 | function isIterable(maybeIterable) {
|
4620 | return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
|
4621 | }
|
4622 |
|
4623 | function isKeyed(maybeKeyed) {
|
4624 | return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
|
4625 | }
|
4626 |
|
4627 | function isIndexed(maybeIndexed) {
|
4628 | return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
|
4629 | }
|
4630 |
|
4631 | function isAssociative(maybeAssociative) {
|
4632 | return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
|
4633 | }
|
4634 |
|
4635 | function isOrdered(maybeOrdered) {
|
4636 | return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
|
4637 | }
|
4638 |
|
4639 | Iterable.isIterable = isIterable;
|
4640 | Iterable.isKeyed = isKeyed;
|
4641 | Iterable.isIndexed = isIndexed;
|
4642 | Iterable.isAssociative = isAssociative;
|
4643 | Iterable.isOrdered = isOrdered;
|
4644 |
|
4645 | Iterable.Keyed = KeyedIterable;
|
4646 | Iterable.Indexed = IndexedIterable;
|
4647 | Iterable.Set = SetIterable;
|
4648 |
|
4649 |
|
4650 | var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
|
4651 | var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
|
4652 | var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
|
4653 | var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
|
4654 |
|
4655 |
|
4656 | var DELETE = 'delete';
|
4657 |
|
4658 |
|
4659 | var SHIFT = 5;
|
4660 | var SIZE = 1 << SHIFT;
|
4661 | var MASK = SIZE - 1;
|
4662 |
|
4663 |
|
4664 |
|
4665 | var NOT_SET = {};
|
4666 |
|
4667 |
|
4668 | var CHANGE_LENGTH = { value: false };
|
4669 | var DID_ALTER = { value: false };
|
4670 |
|
4671 | function MakeRef(ref) {
|
4672 | ref.value = false;
|
4673 | return ref;
|
4674 | }
|
4675 |
|
4676 | function SetRef(ref) {
|
4677 | ref && (ref.value = true);
|
4678 | }
|
4679 |
|
4680 |
|
4681 |
|
4682 |
|
4683 | function OwnerID() {}
|
4684 |
|
4685 |
|
4686 | function arrCopy(arr, offset) {
|
4687 | offset = offset || 0;
|
4688 | var len = Math.max(0, arr.length - offset);
|
4689 | var newArr = new Array(len);
|
4690 | for (var ii = 0; ii < len; ii++) {
|
4691 | newArr[ii] = arr[ii + offset];
|
4692 | }
|
4693 | return newArr;
|
4694 | }
|
4695 |
|
4696 | function ensureSize(iter) {
|
4697 | if (iter.size === undefined) {
|
4698 | iter.size = iter.__iterate(returnTrue);
|
4699 | }
|
4700 | return iter.size;
|
4701 | }
|
4702 |
|
4703 | function wrapIndex(iter, index) {
|
4704 |
|
4705 |
|
4706 |
|
4707 |
|
4708 |
|
4709 |
|
4710 |
|
4711 | if (typeof index !== 'number') {
|
4712 | var uint32Index = index >>> 0;
|
4713 | if ('' + uint32Index !== index || uint32Index === 4294967295) {
|
4714 | return NaN;
|
4715 | }
|
4716 | index = uint32Index;
|
4717 | }
|
4718 | return index < 0 ? ensureSize(iter) + index : index;
|
4719 | }
|
4720 |
|
4721 | function returnTrue() {
|
4722 | return true;
|
4723 | }
|
4724 |
|
4725 | function wholeSlice(begin, end, size) {
|
4726 | return (begin === 0 || (size !== undefined && begin <= -size)) &&
|
4727 | (end === undefined || (size !== undefined && end >= size));
|
4728 | }
|
4729 |
|
4730 | function resolveBegin(begin, size) {
|
4731 | return resolveIndex(begin, size, 0);
|
4732 | }
|
4733 |
|
4734 | function resolveEnd(end, size) {
|
4735 | return resolveIndex(end, size, size);
|
4736 | }
|
4737 |
|
4738 | function resolveIndex(index, size, defaultIndex) {
|
4739 | return index === undefined ?
|
4740 | defaultIndex :
|
4741 | index < 0 ?
|
4742 | Math.max(0, size + index) :
|
4743 | size === undefined ?
|
4744 | index :
|
4745 | Math.min(size, index);
|
4746 | }
|
4747 |
|
4748 |
|
4749 |
|
4750 | var ITERATE_KEYS = 0;
|
4751 | var ITERATE_VALUES = 1;
|
4752 | var ITERATE_ENTRIES = 2;
|
4753 |
|
4754 | var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
4755 | var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
4756 |
|
4757 | var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
|
4758 |
|
4759 |
|
4760 | function Iterator(next) {
|
4761 | this.next = next;
|
4762 | }
|
4763 |
|
4764 | Iterator.prototype.toString = function() {
|
4765 | return '[Iterator]';
|
4766 | };
|
4767 |
|
4768 |
|
4769 | Iterator.KEYS = ITERATE_KEYS;
|
4770 | Iterator.VALUES = ITERATE_VALUES;
|
4771 | Iterator.ENTRIES = ITERATE_ENTRIES;
|
4772 |
|
4773 | Iterator.prototype.inspect =
|
4774 | Iterator.prototype.toSource = function () { return this.toString(); }
|
4775 | Iterator.prototype[ITERATOR_SYMBOL] = function () {
|
4776 | return this;
|
4777 | };
|
4778 |
|
4779 |
|
4780 | function iteratorValue(type, k, v, iteratorResult) {
|
4781 | var value = type === 0 ? k : type === 1 ? v : [k, v];
|
4782 | iteratorResult ? (iteratorResult.value = value) : (iteratorResult = {
|
4783 | value: value, done: false
|
4784 | });
|
4785 | return iteratorResult;
|
4786 | }
|
4787 |
|
4788 | function iteratorDone() {
|
4789 | return { value: undefined, done: true };
|
4790 | }
|
4791 |
|
4792 | function hasIterator(maybeIterable) {
|
4793 | return !!getIteratorFn(maybeIterable);
|
4794 | }
|
4795 |
|
4796 | function isIterator(maybeIterator) {
|
4797 | return maybeIterator && typeof maybeIterator.next === 'function';
|
4798 | }
|
4799 |
|
4800 | function getIterator(iterable) {
|
4801 | var iteratorFn = getIteratorFn(iterable);
|
4802 | return iteratorFn && iteratorFn.call(iterable);
|
4803 | }
|
4804 |
|
4805 | function getIteratorFn(iterable) {
|
4806 | var iteratorFn = iterable && (
|
4807 | (REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
|
4808 | iterable[FAUX_ITERATOR_SYMBOL]
|
4809 | );
|
4810 | if (typeof iteratorFn === 'function') {
|
4811 | return iteratorFn;
|
4812 | }
|
4813 | }
|
4814 |
|
4815 | function isArrayLike(value) {
|
4816 | return value && typeof value.length === 'number';
|
4817 | }
|
4818 |
|
4819 | createClass(Seq, Iterable);
|
4820 | function Seq(value) {
|
4821 | return value === null || value === undefined ? emptySequence() :
|
4822 | isIterable(value) ? value.toSeq() : seqFromValue(value);
|
4823 | }
|
4824 |
|
4825 | Seq.of = function(/*...values*/) {
|
4826 | return Seq(arguments);
|
4827 | };
|
4828 |
|
4829 | Seq.prototype.toSeq = function() {
|
4830 | return this;
|
4831 | };
|
4832 |
|
4833 | Seq.prototype.toString = function() {
|
4834 | return this.__toString('Seq {', '}');
|
4835 | };
|
4836 |
|
4837 | Seq.prototype.cacheResult = function() {
|
4838 | if (!this._cache && this.__iterateUncached) {
|
4839 | this._cache = this.entrySeq().toArray();
|
4840 | this.size = this._cache.length;
|
4841 | }
|
4842 | return this;
|
4843 | };
|
4844 |
|
4845 |
|
4846 |
|
4847 | Seq.prototype.__iterate = function(fn, reverse) {
|
4848 | return seqIterate(this, fn, reverse, true);
|
4849 | };
|
4850 |
|
4851 |
|
4852 |
|
4853 | Seq.prototype.__iterator = function(type, reverse) {
|
4854 | return seqIterator(this, type, reverse, true);
|
4855 | };
|
4856 |
|
4857 |
|
4858 |
|
4859 | createClass(KeyedSeq, Seq);
|
4860 | function KeyedSeq(value) {
|
4861 | return value === null || value === undefined ?
|
4862 | emptySequence().toKeyedSeq() :
|
4863 | isIterable(value) ?
|
4864 | (isKeyed(value) ? value.toSeq() : value.fromEntrySeq()) :
|
4865 | keyedSeqFromValue(value);
|
4866 | }
|
4867 |
|
4868 | KeyedSeq.prototype.toKeyedSeq = function() {
|
4869 | return this;
|
4870 | };
|
4871 |
|
4872 |
|
4873 |
|
4874 | createClass(IndexedSeq, Seq);
|
4875 | function IndexedSeq(value) {
|
4876 | return value === null || value === undefined ? emptySequence() :
|
4877 | !isIterable(value) ? indexedSeqFromValue(value) :
|
4878 | isKeyed(value) ? value.entrySeq() : value.toIndexedSeq();
|
4879 | }
|
4880 |
|
4881 | IndexedSeq.of = function(/*...values*/) {
|
4882 | return IndexedSeq(arguments);
|
4883 | };
|
4884 |
|
4885 | IndexedSeq.prototype.toIndexedSeq = function() {
|
4886 | return this;
|
4887 | };
|
4888 |
|
4889 | IndexedSeq.prototype.toString = function() {
|
4890 | return this.__toString('Seq [', ']');
|
4891 | };
|
4892 |
|
4893 | IndexedSeq.prototype.__iterate = function(fn, reverse) {
|
4894 | return seqIterate(this, fn, reverse, false);
|
4895 | };
|
4896 |
|
4897 | IndexedSeq.prototype.__iterator = function(type, reverse) {
|
4898 | return seqIterator(this, type, reverse, false);
|
4899 | };
|
4900 |
|
4901 |
|
4902 |
|
4903 | createClass(SetSeq, Seq);
|
4904 | function SetSeq(value) {
|
4905 | return (
|
4906 | value === null || value === undefined ? emptySequence() :
|
4907 | !isIterable(value) ? indexedSeqFromValue(value) :
|
4908 | isKeyed(value) ? value.entrySeq() : value
|
4909 | ).toSetSeq();
|
4910 | }
|
4911 |
|
4912 | SetSeq.of = function(/*...values*/) {
|
4913 | return SetSeq(arguments);
|
4914 | };
|
4915 |
|
4916 | SetSeq.prototype.toSetSeq = function() {
|
4917 | return this;
|
4918 | };
|
4919 |
|
4920 |
|
4921 |
|
4922 | Seq.isSeq = isSeq;
|
4923 | Seq.Keyed = KeyedSeq;
|
4924 | Seq.Set = SetSeq;
|
4925 | Seq.Indexed = IndexedSeq;
|
4926 |
|
4927 | var IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@';
|
4928 |
|
4929 | Seq.prototype[IS_SEQ_SENTINEL] = true;
|
4930 |
|
4931 |
|
4932 |
|
4933 | createClass(ArraySeq, IndexedSeq);
|
4934 | function ArraySeq(array) {
|
4935 | this._array = array;
|
4936 | this.size = array.length;
|
4937 | }
|
4938 |
|
4939 | ArraySeq.prototype.get = function(index, notSetValue) {
|
4940 | return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
|
4941 | };
|
4942 |
|
4943 | ArraySeq.prototype.__iterate = function(fn, reverse) {
|
4944 | var array = this._array;
|
4945 | var maxIndex = array.length - 1;
|
4946 | for (var ii = 0; ii <= maxIndex; ii++) {
|
4947 | if (fn(array[reverse ? maxIndex - ii : ii], ii, this) === false) {
|
4948 | return ii + 1;
|
4949 | }
|
4950 | }
|
4951 | return ii;
|
4952 | };
|
4953 |
|
4954 | ArraySeq.prototype.__iterator = function(type, reverse) {
|
4955 | var array = this._array;
|
4956 | var maxIndex = array.length - 1;
|
4957 | var ii = 0;
|
4958 | return new Iterator(function()
|
4959 | {return ii > maxIndex ?
|
4960 | iteratorDone() :
|
4961 | iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
|
4962 | );
|
4963 | };
|
4964 |
|
4965 |
|
4966 |
|
4967 | createClass(ObjectSeq, KeyedSeq);
|
4968 | function ObjectSeq(object) {
|
4969 | var keys = Object.keys(object);
|
4970 | this._object = object;
|
4971 | this._keys = keys;
|
4972 | this.size = keys.length;
|
4973 | }
|
4974 |
|
4975 | ObjectSeq.prototype.get = function(key, notSetValue) {
|
4976 | if (notSetValue !== undefined && !this.has(key)) {
|
4977 | return notSetValue;
|
4978 | }
|
4979 | return this._object[key];
|
4980 | };
|
4981 |
|
4982 | ObjectSeq.prototype.has = function(key) {
|
4983 | return this._object.hasOwnProperty(key);
|
4984 | };
|
4985 |
|
4986 | ObjectSeq.prototype.__iterate = function(fn, reverse) {
|
4987 | var object = this._object;
|
4988 | var keys = this._keys;
|
4989 | var maxIndex = keys.length - 1;
|
4990 | for (var ii = 0; ii <= maxIndex; ii++) {
|
4991 | var key = keys[reverse ? maxIndex - ii : ii];
|
4992 | if (fn(object[key], key, this) === false) {
|
4993 | return ii + 1;
|
4994 | }
|
4995 | }
|
4996 | return ii;
|
4997 | };
|
4998 |
|
4999 | ObjectSeq.prototype.__iterator = function(type, reverse) {
|
5000 | var object = this._object;
|
5001 | var keys = this._keys;
|
5002 | var maxIndex = keys.length - 1;
|
5003 | var ii = 0;
|
5004 | return new Iterator(function() {
|
5005 | var key = keys[reverse ? maxIndex - ii : ii];
|
5006 | return ii++ > maxIndex ?
|
5007 | iteratorDone() :
|
5008 | iteratorValue(type, key, object[key]);
|
5009 | });
|
5010 | };
|
5011 |
|
5012 | ObjectSeq.prototype[IS_ORDERED_SENTINEL] = true;
|
5013 |
|
5014 |
|
5015 | createClass(IterableSeq, IndexedSeq);
|
5016 | function IterableSeq(iterable) {
|
5017 | this._iterable = iterable;
|
5018 | this.size = iterable.length || iterable.size;
|
5019 | }
|
5020 |
|
5021 | IterableSeq.prototype.__iterateUncached = function(fn, reverse) {
|
5022 | if (reverse) {
|
5023 | return this.cacheResult().__iterate(fn, reverse);
|
5024 | }
|
5025 | var iterable = this._iterable;
|
5026 | var iterator = getIterator(iterable);
|
5027 | var iterations = 0;
|
5028 | if (isIterator(iterator)) {
|
5029 | var step;
|
5030 | while (!(step = iterator.next()).done) {
|
5031 | if (fn(step.value, iterations++, this) === false) {
|
5032 | break;
|
5033 | }
|
5034 | }
|
5035 | }
|
5036 | return iterations;
|
5037 | };
|
5038 |
|
5039 | IterableSeq.prototype.__iteratorUncached = function(type, reverse) {
|
5040 | if (reverse) {
|
5041 | return this.cacheResult().__iterator(type, reverse);
|
5042 | }
|
5043 | var iterable = this._iterable;
|
5044 | var iterator = getIterator(iterable);
|
5045 | if (!isIterator(iterator)) {
|
5046 | return new Iterator(iteratorDone);
|
5047 | }
|
5048 | var iterations = 0;
|
5049 | return new Iterator(function() {
|
5050 | var step = iterator.next();
|
5051 | return step.done ? step : iteratorValue(type, iterations++, step.value);
|
5052 | });
|
5053 | };
|
5054 |
|
5055 |
|
5056 |
|
5057 | createClass(IteratorSeq, IndexedSeq);
|
5058 | function IteratorSeq(iterator) {
|
5059 | this._iterator = iterator;
|
5060 | this._iteratorCache = [];
|
5061 | }
|
5062 |
|
5063 | IteratorSeq.prototype.__iterateUncached = function(fn, reverse) {
|
5064 | if (reverse) {
|
5065 | return this.cacheResult().__iterate(fn, reverse);
|
5066 | }
|
5067 | var iterator = this._iterator;
|
5068 | var cache = this._iteratorCache;
|
5069 | var iterations = 0;
|
5070 | while (iterations < cache.length) {
|
5071 | if (fn(cache[iterations], iterations++, this) === false) {
|
5072 | return iterations;
|
5073 | }
|
5074 | }
|
5075 | var step;
|
5076 | while (!(step = iterator.next()).done) {
|
5077 | var val = step.value;
|
5078 | cache[iterations] = val;
|
5079 | if (fn(val, iterations++, this) === false) {
|
5080 | break;
|
5081 | }
|
5082 | }
|
5083 | return iterations;
|
5084 | };
|
5085 |
|
5086 | IteratorSeq.prototype.__iteratorUncached = function(type, reverse) {
|
5087 | if (reverse) {
|
5088 | return this.cacheResult().__iterator(type, reverse);
|
5089 | }
|
5090 | var iterator = this._iterator;
|
5091 | var cache = this._iteratorCache;
|
5092 | var iterations = 0;
|
5093 | return new Iterator(function() {
|
5094 | if (iterations >= cache.length) {
|
5095 | var step = iterator.next();
|
5096 | if (step.done) {
|
5097 | return step;
|
5098 | }
|
5099 | cache[iterations] = step.value;
|
5100 | }
|
5101 | return iteratorValue(type, iterations, cache[iterations++]);
|
5102 | });
|
5103 | };
|
5104 |
|
5105 |
|
5106 |
|
5107 |
|
5108 |
|
5109 |
|
5110 | function isSeq(maybeSeq) {
|
5111 | return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
|
5112 | }
|
5113 |
|
5114 | var EMPTY_SEQ;
|
5115 |
|
5116 | function emptySequence() {
|
5117 | return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
|
5118 | }
|
5119 |
|
5120 | function keyedSeqFromValue(value) {
|
5121 | var seq =
|
5122 | Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
|
5123 | isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
|
5124 | hasIterator(value) ? new IterableSeq(value).fromEntrySeq() :
|
5125 | typeof value === 'object' ? new ObjectSeq(value) :
|
5126 | undefined;
|
5127 | if (!seq) {
|
5128 | throw new TypeError(
|
5129 | 'Expected Array or iterable object of [k, v] entries, '+
|
5130 | 'or keyed object: ' + value
|
5131 | );
|
5132 | }
|
5133 | return seq;
|
5134 | }
|
5135 |
|
5136 | function indexedSeqFromValue(value) {
|
5137 | var seq = maybeIndexedSeqFromValue(value);
|
5138 | if (!seq) {
|
5139 | throw new TypeError(
|
5140 | 'Expected Array or iterable object of values: ' + value
|
5141 | );
|
5142 | }
|
5143 | return seq;
|
5144 | }
|
5145 |
|
5146 | function seqFromValue(value) {
|
5147 | var seq = maybeIndexedSeqFromValue(value) ||
|
5148 | (typeof value === 'object' && new ObjectSeq(value));
|
5149 | if (!seq) {
|
5150 | throw new TypeError(
|
5151 | 'Expected Array or iterable object of values, or keyed object: ' + value
|
5152 | );
|
5153 | }
|
5154 | return seq;
|
5155 | }
|
5156 |
|
5157 | function maybeIndexedSeqFromValue(value) {
|
5158 | return (
|
5159 | isArrayLike(value) ? new ArraySeq(value) :
|
5160 | isIterator(value) ? new IteratorSeq(value) :
|
5161 | hasIterator(value) ? new IterableSeq(value) :
|
5162 | undefined
|
5163 | );
|
5164 | }
|
5165 |
|
5166 | function seqIterate(seq, fn, reverse, useKeys) {
|
5167 | var cache = seq._cache;
|
5168 | if (cache) {
|
5169 | var maxIndex = cache.length - 1;
|
5170 | for (var ii = 0; ii <= maxIndex; ii++) {
|
5171 | var entry = cache[reverse ? maxIndex - ii : ii];
|
5172 | if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) {
|
5173 | return ii + 1;
|
5174 | }
|
5175 | }
|
5176 | return ii;
|
5177 | }
|
5178 | return seq.__iterateUncached(fn, reverse);
|
5179 | }
|
5180 |
|
5181 | function seqIterator(seq, type, reverse, useKeys) {
|
5182 | var cache = seq._cache;
|
5183 | if (cache) {
|
5184 | var maxIndex = cache.length - 1;
|
5185 | var ii = 0;
|
5186 | return new Iterator(function() {
|
5187 | var entry = cache[reverse ? maxIndex - ii : ii];
|
5188 | return ii++ > maxIndex ?
|
5189 | iteratorDone() :
|
5190 | iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
|
5191 | });
|
5192 | }
|
5193 | return seq.__iteratorUncached(type, reverse);
|
5194 | }
|
5195 |
|
5196 | function fromJS(json, converter) {
|
5197 | return converter ?
|
5198 | fromJSWith(converter, json, '', {'': json}) :
|
5199 | fromJSDefault(json);
|
5200 | }
|
5201 |
|
5202 | function fromJSWith(converter, json, key, parentJSON) {
|
5203 | if (Array.isArray(json)) {
|
5204 | return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
|
5205 | }
|
5206 | if (isPlainObj(json)) {
|
5207 | return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
|
5208 | }
|
5209 | return json;
|
5210 | }
|
5211 |
|
5212 | function fromJSDefault(json) {
|
5213 | if (Array.isArray(json)) {
|
5214 | return IndexedSeq(json).map(fromJSDefault).toList();
|
5215 | }
|
5216 | if (isPlainObj(json)) {
|
5217 | return KeyedSeq(json).map(fromJSDefault).toMap();
|
5218 | }
|
5219 | return json;
|
5220 | }
|
5221 |
|
5222 | function isPlainObj(value) {
|
5223 | return value && (value.constructor === Object || value.constructor === undefined);
|
5224 | }
|
5225 |
|
5226 | |
5227 |
|
5228 |
|
5229 |
|
5230 |
|
5231 |
|
5232 |
|
5233 |
|
5234 |
|
5235 |
|
5236 |
|
5237 |
|
5238 |
|
5239 |
|
5240 |
|
5241 |
|
5242 |
|
5243 |
|
5244 |
|
5245 |
|
5246 |
|
5247 |
|
5248 |
|
5249 |
|
5250 |
|
5251 |
|
5252 |
|
5253 |
|
5254 |
|
5255 |
|
5256 |
|
5257 |
|
5258 |
|
5259 |
|
5260 |
|
5261 |
|
5262 |
|
5263 |
|
5264 |
|
5265 |
|
5266 |
|
5267 |
|
5268 |
|
5269 |
|
5270 |
|
5271 |
|
5272 |
|
5273 |
|
5274 |
|
5275 |
|
5276 |
|
5277 |
|
5278 |
|
5279 |
|
5280 | function is(valueA, valueB) {
|
5281 | if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
|
5282 | return true;
|
5283 | }
|
5284 | if (!valueA || !valueB) {
|
5285 | return false;
|
5286 | }
|
5287 | if (typeof valueA.valueOf === 'function' &&
|
5288 | typeof valueB.valueOf === 'function') {
|
5289 | valueA = valueA.valueOf();
|
5290 | valueB = valueB.valueOf();
|
5291 | if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
|
5292 | return true;
|
5293 | }
|
5294 | if (!valueA || !valueB) {
|
5295 | return false;
|
5296 | }
|
5297 | }
|
5298 | if (typeof valueA.equals === 'function' &&
|
5299 | typeof valueB.equals === 'function' &&
|
5300 | valueA.equals(valueB)) {
|
5301 | return true;
|
5302 | }
|
5303 | return false;
|
5304 | }
|
5305 |
|
5306 | function deepEqual(a, b) {
|
5307 | if (a === b) {
|
5308 | return true;
|
5309 | }
|
5310 |
|
5311 | if (
|
5312 | !isIterable(b) ||
|
5313 | a.size !== undefined && b.size !== undefined && a.size !== b.size ||
|
5314 | a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
|
5315 | isKeyed(a) !== isKeyed(b) ||
|
5316 | isIndexed(a) !== isIndexed(b) ||
|
5317 | isOrdered(a) !== isOrdered(b)
|
5318 | ) {
|
5319 | return false;
|
5320 | }
|
5321 |
|
5322 | if (a.size === 0 && b.size === 0) {
|
5323 | return true;
|
5324 | }
|
5325 |
|
5326 | var notAssociative = !isAssociative(a);
|
5327 |
|
5328 | if (isOrdered(a)) {
|
5329 | var entries = a.entries();
|
5330 | return b.every(function(v, k) {
|
5331 | var entry = entries.next().value;
|
5332 | return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
|
5333 | }) && entries.next().done;
|
5334 | }
|
5335 |
|
5336 | var flipped = false;
|
5337 |
|
5338 | if (a.size === undefined) {
|
5339 | if (b.size === undefined) {
|
5340 | if (typeof a.cacheResult === 'function') {
|
5341 | a.cacheResult();
|
5342 | }
|
5343 | } else {
|
5344 | flipped = true;
|
5345 | var _ = a;
|
5346 | a = b;
|
5347 | b = _;
|
5348 | }
|
5349 | }
|
5350 |
|
5351 | var allEqual = true;
|
5352 | var bSize = b.__iterate(function(v, k) {
|
5353 | if (notAssociative ? !a.has(v) :
|
5354 | flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
|
5355 | allEqual = false;
|
5356 | return false;
|
5357 | }
|
5358 | });
|
5359 |
|
5360 | return allEqual && a.size === bSize;
|
5361 | }
|
5362 |
|
5363 | createClass(Repeat, IndexedSeq);
|
5364 |
|
5365 | function Repeat(value, times) {
|
5366 | if (!(this instanceof Repeat)) {
|
5367 | return new Repeat(value, times);
|
5368 | }
|
5369 | this._value = value;
|
5370 | this.size = times === undefined ? Infinity : Math.max(0, times);
|
5371 | if (this.size === 0) {
|
5372 | if (EMPTY_REPEAT) {
|
5373 | return EMPTY_REPEAT;
|
5374 | }
|
5375 | EMPTY_REPEAT = this;
|
5376 | }
|
5377 | }
|
5378 |
|
5379 | Repeat.prototype.toString = function() {
|
5380 | if (this.size === 0) {
|
5381 | return 'Repeat []';
|
5382 | }
|
5383 | return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
|
5384 | };
|
5385 |
|
5386 | Repeat.prototype.get = function(index, notSetValue) {
|
5387 | return this.has(index) ? this._value : notSetValue;
|
5388 | };
|
5389 |
|
5390 | Repeat.prototype.includes = function(searchValue) {
|
5391 | return is(this._value, searchValue);
|
5392 | };
|
5393 |
|
5394 | Repeat.prototype.slice = function(begin, end) {
|
5395 | var size = this.size;
|
5396 | return wholeSlice(begin, end, size) ? this :
|
5397 | new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
|
5398 | };
|
5399 |
|
5400 | Repeat.prototype.reverse = function() {
|
5401 | return this;
|
5402 | };
|
5403 |
|
5404 | Repeat.prototype.indexOf = function(searchValue) {
|
5405 | if (is(this._value, searchValue)) {
|
5406 | return 0;
|
5407 | }
|
5408 | return -1;
|
5409 | };
|
5410 |
|
5411 | Repeat.prototype.lastIndexOf = function(searchValue) {
|
5412 | if (is(this._value, searchValue)) {
|
5413 | return this.size;
|
5414 | }
|
5415 | return -1;
|
5416 | };
|
5417 |
|
5418 | Repeat.prototype.__iterate = function(fn, reverse) {
|
5419 | for (var ii = 0; ii < this.size; ii++) {
|
5420 | if (fn(this._value, ii, this) === false) {
|
5421 | return ii + 1;
|
5422 | }
|
5423 | }
|
5424 | return ii;
|
5425 | };
|
5426 |
|
5427 | Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
|
5428 | var ii = 0;
|
5429 | return new Iterator(function()
|
5430 | {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
|
5431 | );
|
5432 | };
|
5433 |
|
5434 | Repeat.prototype.equals = function(other) {
|
5435 | return other instanceof Repeat ?
|
5436 | is(this._value, other._value) :
|
5437 | deepEqual(other);
|
5438 | };
|
5439 |
|
5440 |
|
5441 | var EMPTY_REPEAT;
|
5442 |
|
5443 | function invariant(condition, error) {
|
5444 | if (!condition) throw new Error(error);
|
5445 | }
|
5446 |
|
5447 | createClass(Range, IndexedSeq);
|
5448 |
|
5449 | function Range(start, end, step) {
|
5450 | if (!(this instanceof Range)) {
|
5451 | return new Range(start, end, step);
|
5452 | }
|
5453 | invariant(step !== 0, 'Cannot step a Range by 0');
|
5454 | start = start || 0;
|
5455 | if (end === undefined) {
|
5456 | end = Infinity;
|
5457 | }
|
5458 | step = step === undefined ? 1 : Math.abs(step);
|
5459 | if (end < start) {
|
5460 | step = -step;
|
5461 | }
|
5462 | this._start = start;
|
5463 | this._end = end;
|
5464 | this._step = step;
|
5465 | this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
|
5466 | if (this.size === 0) {
|
5467 | if (EMPTY_RANGE) {
|
5468 | return EMPTY_RANGE;
|
5469 | }
|
5470 | EMPTY_RANGE = this;
|
5471 | }
|
5472 | }
|
5473 |
|
5474 | Range.prototype.toString = function() {
|
5475 | if (this.size === 0) {
|
5476 | return 'Range []';
|
5477 | }
|
5478 | return 'Range [ ' +
|
5479 | this._start + '...' + this._end +
|
5480 | (this._step !== 1 ? ' by ' + this._step : '') +
|
5481 | ' ]';
|
5482 | };
|
5483 |
|
5484 | Range.prototype.get = function(index, notSetValue) {
|
5485 | return this.has(index) ?
|
5486 | this._start + wrapIndex(this, index) * this._step :
|
5487 | notSetValue;
|
5488 | };
|
5489 |
|
5490 | Range.prototype.includes = function(searchValue) {
|
5491 | var possibleIndex = (searchValue - this._start) / this._step;
|
5492 | return possibleIndex >= 0 &&
|
5493 | possibleIndex < this.size &&
|
5494 | possibleIndex === Math.floor(possibleIndex);
|
5495 | };
|
5496 |
|
5497 | Range.prototype.slice = function(begin, end) {
|
5498 | if (wholeSlice(begin, end, this.size)) {
|
5499 | return this;
|
5500 | }
|
5501 | begin = resolveBegin(begin, this.size);
|
5502 | end = resolveEnd(end, this.size);
|
5503 | if (end <= begin) {
|
5504 | return new Range(0, 0);
|
5505 | }
|
5506 | return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
|
5507 | };
|
5508 |
|
5509 | Range.prototype.indexOf = function(searchValue) {
|
5510 | var offsetValue = searchValue - this._start;
|
5511 | if (offsetValue % this._step === 0) {
|
5512 | var index = offsetValue / this._step;
|
5513 | if (index >= 0 && index < this.size) {
|
5514 | return index
|
5515 | }
|
5516 | }
|
5517 | return -1;
|
5518 | };
|
5519 |
|
5520 | Range.prototype.lastIndexOf = function(searchValue) {
|
5521 | return this.indexOf(searchValue);
|
5522 | };
|
5523 |
|
5524 | Range.prototype.__iterate = function(fn, reverse) {
|
5525 | var maxIndex = this.size - 1;
|
5526 | var step = this._step;
|
5527 | var value = reverse ? this._start + maxIndex * step : this._start;
|
5528 | for (var ii = 0; ii <= maxIndex; ii++) {
|
5529 | if (fn(value, ii, this) === false) {
|
5530 | return ii + 1;
|
5531 | }
|
5532 | value += reverse ? -step : step;
|
5533 | }
|
5534 | return ii;
|
5535 | };
|
5536 |
|
5537 | Range.prototype.__iterator = function(type, reverse) {
|
5538 | var maxIndex = this.size - 1;
|
5539 | var step = this._step;
|
5540 | var value = reverse ? this._start + maxIndex * step : this._start;
|
5541 | var ii = 0;
|
5542 | return new Iterator(function() {
|
5543 | var v = value;
|
5544 | value += reverse ? -step : step;
|
5545 | return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
|
5546 | });
|
5547 | };
|
5548 |
|
5549 | Range.prototype.equals = function(other) {
|
5550 | return other instanceof Range ?
|
5551 | this._start === other._start &&
|
5552 | this._end === other._end &&
|
5553 | this._step === other._step :
|
5554 | deepEqual(this, other);
|
5555 | };
|
5556 |
|
5557 |
|
5558 | var EMPTY_RANGE;
|
5559 |
|
5560 | createClass(Collection, Iterable);
|
5561 | function Collection() {
|
5562 | throw TypeError('Abstract');
|
5563 | }
|
5564 |
|
5565 |
|
5566 | createClass(KeyedCollection, Collection);function KeyedCollection() {}
|
5567 |
|
5568 | createClass(IndexedCollection, Collection);function IndexedCollection() {}
|
5569 |
|
5570 | createClass(SetCollection, Collection);function SetCollection() {}
|
5571 |
|
5572 |
|
5573 | Collection.Keyed = KeyedCollection;
|
5574 | Collection.Indexed = IndexedCollection;
|
5575 | Collection.Set = SetCollection;
|
5576 |
|
5577 | var imul =
|
5578 | typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
|
5579 | Math.imul :
|
5580 | function imul(a, b) {
|
5581 | a = a | 0;
|
5582 | b = b | 0;
|
5583 | var c = a & 0xffff;
|
5584 | var d = b & 0xffff;
|
5585 |
|
5586 | return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0;
|
5587 | };
|
5588 |
|
5589 |
|
5590 |
|
5591 |
|
5592 |
|
5593 | function smi(i32) {
|
5594 | return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
|
5595 | }
|
5596 |
|
5597 | function hash(o) {
|
5598 | if (o === false || o === null || o === undefined) {
|
5599 | return 0;
|
5600 | }
|
5601 | if (typeof o.valueOf === 'function') {
|
5602 | o = o.valueOf();
|
5603 | if (o === false || o === null || o === undefined) {
|
5604 | return 0;
|
5605 | }
|
5606 | }
|
5607 | if (o === true) {
|
5608 | return 1;
|
5609 | }
|
5610 | var type = typeof o;
|
5611 | if (type === 'number') {
|
5612 | if (o !== o || o === Infinity) {
|
5613 | return 0;
|
5614 | }
|
5615 | var h = o | 0;
|
5616 | if (h !== o) {
|
5617 | h ^= o * 0xFFFFFFFF;
|
5618 | }
|
5619 | while (o > 0xFFFFFFFF) {
|
5620 | o /= 0xFFFFFFFF;
|
5621 | h ^= o;
|
5622 | }
|
5623 | return smi(h);
|
5624 | }
|
5625 | if (type === 'string') {
|
5626 | return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
|
5627 | }
|
5628 | if (typeof o.hashCode === 'function') {
|
5629 | return o.hashCode();
|
5630 | }
|
5631 | if (type === 'object') {
|
5632 | return hashJSObj(o);
|
5633 | }
|
5634 | if (typeof o.toString === 'function') {
|
5635 | return hashString(o.toString());
|
5636 | }
|
5637 | throw new Error('Value type ' + type + ' cannot be hashed.');
|
5638 | }
|
5639 |
|
5640 | function cachedHashString(string) {
|
5641 | var hash = stringHashCache[string];
|
5642 | if (hash === undefined) {
|
5643 | hash = hashString(string);
|
5644 | if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
|
5645 | STRING_HASH_CACHE_SIZE = 0;
|
5646 | stringHashCache = {};
|
5647 | }
|
5648 | STRING_HASH_CACHE_SIZE++;
|
5649 | stringHashCache[string] = hash;
|
5650 | }
|
5651 | return hash;
|
5652 | }
|
5653 |
|
5654 |
|
5655 | function hashString(string) {
|
5656 |
|
5657 |
|
5658 |
|
5659 |
|
5660 |
|
5661 |
|
5662 | var hash = 0;
|
5663 | for (var ii = 0; ii < string.length; ii++) {
|
5664 | hash = 31 * hash + string.charCodeAt(ii) | 0;
|
5665 | }
|
5666 | return smi(hash);
|
5667 | }
|
5668 |
|
5669 | function hashJSObj(obj) {
|
5670 | var hash;
|
5671 | if (usingWeakMap) {
|
5672 | hash = weakMap.get(obj);
|
5673 | if (hash !== undefined) {
|
5674 | return hash;
|
5675 | }
|
5676 | }
|
5677 |
|
5678 | hash = obj[UID_HASH_KEY];
|
5679 | if (hash !== undefined) {
|
5680 | return hash;
|
5681 | }
|
5682 |
|
5683 | if (!canDefineProperty) {
|
5684 | hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
|
5685 | if (hash !== undefined) {
|
5686 | return hash;
|
5687 | }
|
5688 |
|
5689 | hash = getIENodeHash(obj);
|
5690 | if (hash !== undefined) {
|
5691 | return hash;
|
5692 | }
|
5693 | }
|
5694 |
|
5695 | hash = ++objHashUID;
|
5696 | if (objHashUID & 0x40000000) {
|
5697 | objHashUID = 0;
|
5698 | }
|
5699 |
|
5700 | if (usingWeakMap) {
|
5701 | weakMap.set(obj, hash);
|
5702 | } else if (isExtensible !== undefined && isExtensible(obj) === false) {
|
5703 | throw new Error('Non-extensible objects are not allowed as keys.');
|
5704 | } else if (canDefineProperty) {
|
5705 | Object.defineProperty(obj, UID_HASH_KEY, {
|
5706 | 'enumerable': false,
|
5707 | 'configurable': false,
|
5708 | 'writable': false,
|
5709 | 'value': hash
|
5710 | });
|
5711 | } else if (obj.propertyIsEnumerable !== undefined &&
|
5712 | obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
|
5713 |
|
5714 |
|
5715 |
|
5716 |
|
5717 | obj.propertyIsEnumerable = function() {
|
5718 | return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
|
5719 | };
|
5720 | obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
|
5721 | } else if (obj.nodeType !== undefined) {
|
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 | obj[UID_HASH_KEY] = hash;
|
5727 | } else {
|
5728 | throw new Error('Unable to set a non-enumerable property on object.');
|
5729 | }
|
5730 |
|
5731 | return hash;
|
5732 | }
|
5733 |
|
5734 |
|
5735 | var isExtensible = Object.isExtensible;
|
5736 |
|
5737 |
|
5738 | var canDefineProperty = (function() {
|
5739 | try {
|
5740 | Object.defineProperty({}, '@', {});
|
5741 | return true;
|
5742 | } catch (e) {
|
5743 | return false;
|
5744 | }
|
5745 | }());
|
5746 |
|
5747 |
|
5748 |
|
5749 | function getIENodeHash(node) {
|
5750 | if (node && node.nodeType > 0) {
|
5751 | switch (node.nodeType) {
|
5752 | case 1:
|
5753 | return node.uniqueID;
|
5754 | case 9:
|
5755 | return node.documentElement && node.documentElement.uniqueID;
|
5756 | }
|
5757 | }
|
5758 | }
|
5759 |
|
5760 |
|
5761 | var usingWeakMap = typeof WeakMap === 'function';
|
5762 | var weakMap;
|
5763 | if (usingWeakMap) {
|
5764 | weakMap = new WeakMap();
|
5765 | }
|
5766 |
|
5767 | var objHashUID = 0;
|
5768 |
|
5769 | var UID_HASH_KEY = '__immutablehash__';
|
5770 | if (typeof Symbol === 'function') {
|
5771 | UID_HASH_KEY = Symbol(UID_HASH_KEY);
|
5772 | }
|
5773 |
|
5774 | var STRING_HASH_CACHE_MIN_STRLEN = 16;
|
5775 | var STRING_HASH_CACHE_MAX_SIZE = 255;
|
5776 | var STRING_HASH_CACHE_SIZE = 0;
|
5777 | var stringHashCache = {};
|
5778 |
|
5779 | function assertNotInfinite(size) {
|
5780 | invariant(
|
5781 | size !== Infinity,
|
5782 | 'Cannot perform this action with an infinite size.'
|
5783 | );
|
5784 | }
|
5785 |
|
5786 | createClass(Map, KeyedCollection);
|
5787 |
|
5788 |
|
5789 |
|
5790 | function Map(value) {
|
5791 | return value === null || value === undefined ? emptyMap() :
|
5792 | isMap(value) && !isOrdered(value) ? value :
|
5793 | emptyMap().withMutations(function(map ) {
|
5794 | var iter = KeyedIterable(value);
|
5795 | assertNotInfinite(iter.size);
|
5796 | iter.forEach(function(v, k) {return map.set(k, v)});
|
5797 | });
|
5798 | }
|
5799 |
|
5800 | Map.of = function() {var keyValues = SLICE$0.call(arguments, 0);
|
5801 | return emptyMap().withMutations(function(map ) {
|
5802 | for (var i = 0; i < keyValues.length; i += 2) {
|
5803 | if (i + 1 >= keyValues.length) {
|
5804 | throw new Error('Missing value for key: ' + keyValues[i]);
|
5805 | }
|
5806 | map.set(keyValues[i], keyValues[i + 1]);
|
5807 | }
|
5808 | });
|
5809 | };
|
5810 |
|
5811 | Map.prototype.toString = function() {
|
5812 | return this.__toString('Map {', '}');
|
5813 | };
|
5814 |
|
5815 |
|
5816 |
|
5817 | Map.prototype.get = function(k, notSetValue) {
|
5818 | return this._root ?
|
5819 | this._root.get(0, undefined, k, notSetValue) :
|
5820 | notSetValue;
|
5821 | };
|
5822 |
|
5823 |
|
5824 |
|
5825 | Map.prototype.set = function(k, v) {
|
5826 | return updateMap(this, k, v);
|
5827 | };
|
5828 |
|
5829 | Map.prototype.setIn = function(keyPath, v) {
|
5830 | return this.updateIn(keyPath, NOT_SET, function() {return v});
|
5831 | };
|
5832 |
|
5833 | Map.prototype.remove = function(k) {
|
5834 | return updateMap(this, k, NOT_SET);
|
5835 | };
|
5836 |
|
5837 | Map.prototype.deleteIn = function(keyPath) {
|
5838 | return this.updateIn(keyPath, function() {return NOT_SET});
|
5839 | };
|
5840 |
|
5841 | Map.prototype.update = function(k, notSetValue, updater) {
|
5842 | return arguments.length === 1 ?
|
5843 | k(this) :
|
5844 | this.updateIn([k], notSetValue, updater);
|
5845 | };
|
5846 |
|
5847 | Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
|
5848 | if (!updater) {
|
5849 | updater = notSetValue;
|
5850 | notSetValue = undefined;
|
5851 | }
|
5852 | var updatedValue = updateInDeepMap(
|
5853 | this,
|
5854 | forceIterator(keyPath),
|
5855 | notSetValue,
|
5856 | updater
|
5857 | );
|
5858 | return updatedValue === NOT_SET ? undefined : updatedValue;
|
5859 | };
|
5860 |
|
5861 | Map.prototype.clear = function() {
|
5862 | if (this.size === 0) {
|
5863 | return this;
|
5864 | }
|
5865 | if (this.__ownerID) {
|
5866 | this.size = 0;
|
5867 | this._root = null;
|
5868 | this.__hash = undefined;
|
5869 | this.__altered = true;
|
5870 | return this;
|
5871 | }
|
5872 | return emptyMap();
|
5873 | };
|
5874 |
|
5875 |
|
5876 |
|
5877 | Map.prototype.merge = function(/*...iters*/) {
|
5878 | return mergeIntoMapWith(this, undefined, arguments);
|
5879 | };
|
5880 |
|
5881 | Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
|
5882 | return mergeIntoMapWith(this, merger, iters);
|
5883 | };
|
5884 |
|
5885 | Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
|
5886 | return this.updateIn(
|
5887 | keyPath,
|
5888 | emptyMap(),
|
5889 | function(m ) {return typeof m.merge === 'function' ?
|
5890 | m.merge.apply(m, iters) :
|
5891 | iters[iters.length - 1]}
|
5892 | );
|
5893 | };
|
5894 |
|
5895 | Map.prototype.mergeDeep = function(/*...iters*/) {
|
5896 | return mergeIntoMapWith(this, deepMerger, arguments);
|
5897 | };
|
5898 |
|
5899 | Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
|
5900 | return mergeIntoMapWith(this, deepMergerWith(merger), iters);
|
5901 | };
|
5902 |
|
5903 | Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
|
5904 | return this.updateIn(
|
5905 | keyPath,
|
5906 | emptyMap(),
|
5907 | function(m ) {return typeof m.mergeDeep === 'function' ?
|
5908 | m.mergeDeep.apply(m, iters) :
|
5909 | iters[iters.length - 1]}
|
5910 | );
|
5911 | };
|
5912 |
|
5913 | Map.prototype.sort = function(comparator) {
|
5914 |
|
5915 | return OrderedMap(sortFactory(this, comparator));
|
5916 | };
|
5917 |
|
5918 | Map.prototype.sortBy = function(mapper, comparator) {
|
5919 |
|
5920 | return OrderedMap(sortFactory(this, comparator, mapper));
|
5921 | };
|
5922 |
|
5923 |
|
5924 |
|
5925 | Map.prototype.withMutations = function(fn) {
|
5926 | var mutable = this.asMutable();
|
5927 | fn(mutable);
|
5928 | return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
|
5929 | };
|
5930 |
|
5931 | Map.prototype.asMutable = function() {
|
5932 | return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
|
5933 | };
|
5934 |
|
5935 | Map.prototype.asImmutable = function() {
|
5936 | return this.__ensureOwner();
|
5937 | };
|
5938 |
|
5939 | Map.prototype.wasAltered = function() {
|
5940 | return this.__altered;
|
5941 | };
|
5942 |
|
5943 | Map.prototype.__iterator = function(type, reverse) {
|
5944 | return new MapIterator(this, type, reverse);
|
5945 | };
|
5946 |
|
5947 | Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
|
5948 | var iterations = 0;
|
5949 | this._root && this._root.iterate(function(entry ) {
|
5950 | iterations++;
|
5951 | return fn(entry[1], entry[0], this$0);
|
5952 | }, reverse);
|
5953 | return iterations;
|
5954 | };
|
5955 |
|
5956 | Map.prototype.__ensureOwner = function(ownerID) {
|
5957 | if (ownerID === this.__ownerID) {
|
5958 | return this;
|
5959 | }
|
5960 | if (!ownerID) {
|
5961 | this.__ownerID = ownerID;
|
5962 | this.__altered = false;
|
5963 | return this;
|
5964 | }
|
5965 | return makeMap(this.size, this._root, ownerID, this.__hash);
|
5966 | };
|
5967 |
|
5968 |
|
5969 | function isMap(maybeMap) {
|
5970 | return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
|
5971 | }
|
5972 |
|
5973 | Map.isMap = isMap;
|
5974 |
|
5975 | var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
|
5976 |
|
5977 | var MapPrototype = Map.prototype;
|
5978 | MapPrototype[IS_MAP_SENTINEL] = true;
|
5979 | MapPrototype[DELETE] = MapPrototype.remove;
|
5980 | MapPrototype.removeIn = MapPrototype.deleteIn;
|
5981 |
|
5982 |
|
5983 |
|
5984 |
|
5985 |
|
5986 |
|
5987 | function ArrayMapNode(ownerID, entries) {
|
5988 | this.ownerID = ownerID;
|
5989 | this.entries = entries;
|
5990 | }
|
5991 |
|
5992 | ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
|
5993 | var entries = this.entries;
|
5994 | for (var ii = 0, len = entries.length; ii < len; ii++) {
|
5995 | if (is(key, entries[ii][0])) {
|
5996 | return entries[ii][1];
|
5997 | }
|
5998 | }
|
5999 | return notSetValue;
|
6000 | };
|
6001 |
|
6002 | ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
|
6003 | var removed = value === NOT_SET;
|
6004 |
|
6005 | var entries = this.entries;
|
6006 | var idx = 0;
|
6007 | for (var len = entries.length; idx < len; idx++) {
|
6008 | if (is(key, entries[idx][0])) {
|
6009 | break;
|
6010 | }
|
6011 | }
|
6012 | var exists = idx < len;
|
6013 |
|
6014 | if (exists ? entries[idx][1] === value : removed) {
|
6015 | return this;
|
6016 | }
|
6017 |
|
6018 | SetRef(didAlter);
|
6019 | (removed || !exists) && SetRef(didChangeSize);
|
6020 |
|
6021 | if (removed && entries.length === 1) {
|
6022 | return;
|
6023 | }
|
6024 |
|
6025 | if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
|
6026 | return createNodes(ownerID, entries, key, value);
|
6027 | }
|
6028 |
|
6029 | var isEditable = ownerID && ownerID === this.ownerID;
|
6030 | var newEntries = isEditable ? entries : arrCopy(entries);
|
6031 |
|
6032 | if (exists) {
|
6033 | if (removed) {
|
6034 | idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
|
6035 | } else {
|
6036 | newEntries[idx] = [key, value];
|
6037 | }
|
6038 | } else {
|
6039 | newEntries.push([key, value]);
|
6040 | }
|
6041 |
|
6042 | if (isEditable) {
|
6043 | this.entries = newEntries;
|
6044 | return this;
|
6045 | }
|
6046 |
|
6047 | return new ArrayMapNode(ownerID, newEntries);
|
6048 | };
|
6049 |
|
6050 |
|
6051 |
|
6052 |
|
6053 | function BitmapIndexedNode(ownerID, bitmap, nodes) {
|
6054 | this.ownerID = ownerID;
|
6055 | this.bitmap = bitmap;
|
6056 | this.nodes = nodes;
|
6057 | }
|
6058 |
|
6059 | BitmapIndexedNode.prototype.get = function(shift, keyHash, key, notSetValue) {
|
6060 | if (keyHash === undefined) {
|
6061 | keyHash = hash(key);
|
6062 | }
|
6063 | var bit = (1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK));
|
6064 | var bitmap = this.bitmap;
|
6065 | return (bitmap & bit) === 0 ? notSetValue :
|
6066 | this.nodes[popCount(bitmap & (bit - 1))].get(shift + SHIFT, keyHash, key, notSetValue);
|
6067 | };
|
6068 |
|
6069 | BitmapIndexedNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
|
6070 | if (keyHash === undefined) {
|
6071 | keyHash = hash(key);
|
6072 | }
|
6073 | var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
|
6074 | var bit = 1 << keyHashFrag;
|
6075 | var bitmap = this.bitmap;
|
6076 | var exists = (bitmap & bit) !== 0;
|
6077 |
|
6078 | if (!exists && value === NOT_SET) {
|
6079 | return this;
|
6080 | }
|
6081 |
|
6082 | var idx = popCount(bitmap & (bit - 1));
|
6083 | var nodes = this.nodes;
|
6084 | var node = exists ? nodes[idx] : undefined;
|
6085 | var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
|
6086 |
|
6087 | if (newNode === node) {
|
6088 | return this;
|
6089 | }
|
6090 |
|
6091 | if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
|
6092 | return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
|
6093 | }
|
6094 |
|
6095 | if (exists && !newNode && nodes.length === 2 && isLeafNode(nodes[idx ^ 1])) {
|
6096 | return nodes[idx ^ 1];
|
6097 | }
|
6098 |
|
6099 | if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
|
6100 | return newNode;
|
6101 | }
|
6102 |
|
6103 | var isEditable = ownerID && ownerID === this.ownerID;
|
6104 | var newBitmap = exists ? newNode ? bitmap : bitmap ^ bit : bitmap | bit;
|
6105 | var newNodes = exists ? newNode ?
|
6106 | setIn(nodes, idx, newNode, isEditable) :
|
6107 | spliceOut(nodes, idx, isEditable) :
|
6108 | spliceIn(nodes, idx, newNode, isEditable);
|
6109 |
|
6110 | if (isEditable) {
|
6111 | this.bitmap = newBitmap;
|
6112 | this.nodes = newNodes;
|
6113 | return this;
|
6114 | }
|
6115 |
|
6116 | return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
|
6117 | };
|
6118 |
|
6119 |
|
6120 |
|
6121 |
|
6122 | function HashArrayMapNode(ownerID, count, nodes) {
|
6123 | this.ownerID = ownerID;
|
6124 | this.count = count;
|
6125 | this.nodes = nodes;
|
6126 | }
|
6127 |
|
6128 | HashArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
|
6129 | if (keyHash === undefined) {
|
6130 | keyHash = hash(key);
|
6131 | }
|
6132 | var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
|
6133 | var node = this.nodes[idx];
|
6134 | return node ? node.get(shift + SHIFT, keyHash, key, notSetValue) : notSetValue;
|
6135 | };
|
6136 |
|
6137 | HashArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
|
6138 | if (keyHash === undefined) {
|
6139 | keyHash = hash(key);
|
6140 | }
|
6141 | var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
|
6142 | var removed = value === NOT_SET;
|
6143 | var nodes = this.nodes;
|
6144 | var node = nodes[idx];
|
6145 |
|
6146 | if (removed && !node) {
|
6147 | return this;
|
6148 | }
|
6149 |
|
6150 | var newNode = updateNode(node, ownerID, shift + SHIFT, keyHash, key, value, didChangeSize, didAlter);
|
6151 | if (newNode === node) {
|
6152 | return this;
|
6153 | }
|
6154 |
|
6155 | var newCount = this.count;
|
6156 | if (!node) {
|
6157 | newCount++;
|
6158 | } else if (!newNode) {
|
6159 | newCount--;
|
6160 | if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
|
6161 | return packNodes(ownerID, nodes, newCount, idx);
|
6162 | }
|
6163 | }
|
6164 |
|
6165 | var isEditable = ownerID && ownerID === this.ownerID;
|
6166 | var newNodes = setIn(nodes, idx, newNode, isEditable);
|
6167 |
|
6168 | if (isEditable) {
|
6169 | this.count = newCount;
|
6170 | this.nodes = newNodes;
|
6171 | return this;
|
6172 | }
|
6173 |
|
6174 | return new HashArrayMapNode(ownerID, newCount, newNodes);
|
6175 | };
|
6176 |
|
6177 |
|
6178 |
|
6179 |
|
6180 | function HashCollisionNode(ownerID, keyHash, entries) {
|
6181 | this.ownerID = ownerID;
|
6182 | this.keyHash = keyHash;
|
6183 | this.entries = entries;
|
6184 | }
|
6185 |
|
6186 | HashCollisionNode.prototype.get = function(shift, keyHash, key, notSetValue) {
|
6187 | var entries = this.entries;
|
6188 | for (var ii = 0, len = entries.length; ii < len; ii++) {
|
6189 | if (is(key, entries[ii][0])) {
|
6190 | return entries[ii][1];
|
6191 | }
|
6192 | }
|
6193 | return notSetValue;
|
6194 | };
|
6195 |
|
6196 | HashCollisionNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
|
6197 | if (keyHash === undefined) {
|
6198 | keyHash = hash(key);
|
6199 | }
|
6200 |
|
6201 | var removed = value === NOT_SET;
|
6202 |
|
6203 | if (keyHash !== this.keyHash) {
|
6204 | if (removed) {
|
6205 | return this;
|
6206 | }
|
6207 | SetRef(didAlter);
|
6208 | SetRef(didChangeSize);
|
6209 | return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
|
6210 | }
|
6211 |
|
6212 | var entries = this.entries;
|
6213 | var idx = 0;
|
6214 | for (var len = entries.length; idx < len; idx++) {
|
6215 | if (is(key, entries[idx][0])) {
|
6216 | break;
|
6217 | }
|
6218 | }
|
6219 | var exists = idx < len;
|
6220 |
|
6221 | if (exists ? entries[idx][1] === value : removed) {
|
6222 | return this;
|
6223 | }
|
6224 |
|
6225 | SetRef(didAlter);
|
6226 | (removed || !exists) && SetRef(didChangeSize);
|
6227 |
|
6228 | if (removed && len === 2) {
|
6229 | return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
|
6230 | }
|
6231 |
|
6232 | var isEditable = ownerID && ownerID === this.ownerID;
|
6233 | var newEntries = isEditable ? entries : arrCopy(entries);
|
6234 |
|
6235 | if (exists) {
|
6236 | if (removed) {
|
6237 | idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
|
6238 | } else {
|
6239 | newEntries[idx] = [key, value];
|
6240 | }
|
6241 | } else {
|
6242 | newEntries.push([key, value]);
|
6243 | }
|
6244 |
|
6245 | if (isEditable) {
|
6246 | this.entries = newEntries;
|
6247 | return this;
|
6248 | }
|
6249 |
|
6250 | return new HashCollisionNode(ownerID, this.keyHash, newEntries);
|
6251 | };
|
6252 |
|
6253 |
|
6254 |
|
6255 |
|
6256 | function ValueNode(ownerID, keyHash, entry) {
|
6257 | this.ownerID = ownerID;
|
6258 | this.keyHash = keyHash;
|
6259 | this.entry = entry;
|
6260 | }
|
6261 |
|
6262 | ValueNode.prototype.get = function(shift, keyHash, key, notSetValue) {
|
6263 | return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
|
6264 | };
|
6265 |
|
6266 | ValueNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
|
6267 | var removed = value === NOT_SET;
|
6268 | var keyMatch = is(key, this.entry[0]);
|
6269 | if (keyMatch ? value === this.entry[1] : removed) {
|
6270 | return this;
|
6271 | }
|
6272 |
|
6273 | SetRef(didAlter);
|
6274 |
|
6275 | if (removed) {
|
6276 | SetRef(didChangeSize);
|
6277 | return;
|
6278 | }
|
6279 |
|
6280 | if (keyMatch) {
|
6281 | if (ownerID && ownerID === this.ownerID) {
|
6282 | this.entry[1] = value;
|
6283 | return this;
|
6284 | }
|
6285 | return new ValueNode(ownerID, this.keyHash, [key, value]);
|
6286 | }
|
6287 |
|
6288 | SetRef(didChangeSize);
|
6289 | return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
|
6290 | };
|
6291 |
|
6292 |
|
6293 |
|
6294 |
|
6295 |
|
6296 | ArrayMapNode.prototype.iterate =
|
6297 | HashCollisionNode.prototype.iterate = function (fn, reverse) {
|
6298 | var entries = this.entries;
|
6299 | for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
|
6300 | if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
|
6301 | return false;
|
6302 | }
|
6303 | }
|
6304 | }
|
6305 |
|
6306 | BitmapIndexedNode.prototype.iterate =
|
6307 | HashArrayMapNode.prototype.iterate = function (fn, reverse) {
|
6308 | var nodes = this.nodes;
|
6309 | for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
|
6310 | var node = nodes[reverse ? maxIndex - ii : ii];
|
6311 | if (node && node.iterate(fn, reverse) === false) {
|
6312 | return false;
|
6313 | }
|
6314 | }
|
6315 | }
|
6316 |
|
6317 | ValueNode.prototype.iterate = function (fn, reverse) {
|
6318 | return fn(this.entry);
|
6319 | }
|
6320 |
|
6321 | createClass(MapIterator, Iterator);
|
6322 |
|
6323 | function MapIterator(map, type, reverse) {
|
6324 | this._type = type;
|
6325 | this._reverse = reverse;
|
6326 | this._stack = map._root && mapIteratorFrame(map._root);
|
6327 | }
|
6328 |
|
6329 | MapIterator.prototype.next = function() {
|
6330 | var type = this._type;
|
6331 | var stack = this._stack;
|
6332 | while (stack) {
|
6333 | var node = stack.node;
|
6334 | var index = stack.index++;
|
6335 | var maxIndex;
|
6336 | if (node.entry) {
|
6337 | if (index === 0) {
|
6338 | return mapIteratorValue(type, node.entry);
|
6339 | }
|
6340 | } else if (node.entries) {
|
6341 | maxIndex = node.entries.length - 1;
|
6342 | if (index <= maxIndex) {
|
6343 | return mapIteratorValue(type, node.entries[this._reverse ? maxIndex - index : index]);
|
6344 | }
|
6345 | } else {
|
6346 | maxIndex = node.nodes.length - 1;
|
6347 | if (index <= maxIndex) {
|
6348 | var subNode = node.nodes[this._reverse ? maxIndex - index : index];
|
6349 | if (subNode) {
|
6350 | if (subNode.entry) {
|
6351 | return mapIteratorValue(type, subNode.entry);
|
6352 | }
|
6353 | stack = this._stack = mapIteratorFrame(subNode, stack);
|
6354 | }
|
6355 | continue;
|
6356 | }
|
6357 | }
|
6358 | stack = this._stack = this._stack.__prev;
|
6359 | }
|
6360 | return iteratorDone();
|
6361 | };
|
6362 |
|
6363 |
|
6364 | function mapIteratorValue(type, entry) {
|
6365 | return iteratorValue(type, entry[0], entry[1]);
|
6366 | }
|
6367 |
|
6368 | function mapIteratorFrame(node, prev) {
|
6369 | return {
|
6370 | node: node,
|
6371 | index: 0,
|
6372 | __prev: prev
|
6373 | };
|
6374 | }
|
6375 |
|
6376 | function makeMap(size, root, ownerID, hash) {
|
6377 | var map = Object.create(MapPrototype);
|
6378 | map.size = size;
|
6379 | map._root = root;
|
6380 | map.__ownerID = ownerID;
|
6381 | map.__hash = hash;
|
6382 | map.__altered = false;
|
6383 | return map;
|
6384 | }
|
6385 |
|
6386 | var EMPTY_MAP;
|
6387 | function emptyMap() {
|
6388 | return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
|
6389 | }
|
6390 |
|
6391 | function updateMap(map, k, v) {
|
6392 | var newRoot;
|
6393 | var newSize;
|
6394 | if (!map._root) {
|
6395 | if (v === NOT_SET) {
|
6396 | return map;
|
6397 | }
|
6398 | newSize = 1;
|
6399 | newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
|
6400 | } else {
|
6401 | var didChangeSize = MakeRef(CHANGE_LENGTH);
|
6402 | var didAlter = MakeRef(DID_ALTER);
|
6403 | newRoot = updateNode(map._root, map.__ownerID, 0, undefined, k, v, didChangeSize, didAlter);
|
6404 | if (!didAlter.value) {
|
6405 | return map;
|
6406 | }
|
6407 | newSize = map.size + (didChangeSize.value ? v === NOT_SET ? -1 : 1 : 0);
|
6408 | }
|
6409 | if (map.__ownerID) {
|
6410 | map.size = newSize;
|
6411 | map._root = newRoot;
|
6412 | map.__hash = undefined;
|
6413 | map.__altered = true;
|
6414 | return map;
|
6415 | }
|
6416 | return newRoot ? makeMap(newSize, newRoot) : emptyMap();
|
6417 | }
|
6418 |
|
6419 | function updateNode(node, ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
|
6420 | if (!node) {
|
6421 | if (value === NOT_SET) {
|
6422 | return node;
|
6423 | }
|
6424 | SetRef(didAlter);
|
6425 | SetRef(didChangeSize);
|
6426 | return new ValueNode(ownerID, keyHash, [key, value]);
|
6427 | }
|
6428 | return node.update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter);
|
6429 | }
|
6430 |
|
6431 | function isLeafNode(node) {
|
6432 | return node.constructor === ValueNode || node.constructor === HashCollisionNode;
|
6433 | }
|
6434 |
|
6435 | function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
|
6436 | if (node.keyHash === keyHash) {
|
6437 | return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
|
6438 | }
|
6439 |
|
6440 | var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
|
6441 | var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
|
6442 |
|
6443 | var newNode;
|
6444 | var nodes = idx1 === idx2 ?
|
6445 | [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)] :
|
6446 | ((newNode = new ValueNode(ownerID, keyHash, entry)), idx1 < idx2 ? [node, newNode] : [newNode, node]);
|
6447 |
|
6448 | return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
|
6449 | }
|
6450 |
|
6451 | function createNodes(ownerID, entries, key, value) {
|
6452 | if (!ownerID) {
|
6453 | ownerID = new OwnerID();
|
6454 | }
|
6455 | var node = new ValueNode(ownerID, hash(key), [key, value]);
|
6456 | for (var ii = 0; ii < entries.length; ii++) {
|
6457 | var entry = entries[ii];
|
6458 | node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
|
6459 | }
|
6460 | return node;
|
6461 | }
|
6462 |
|
6463 | function packNodes(ownerID, nodes, count, excluding) {
|
6464 | var bitmap = 0;
|
6465 | var packedII = 0;
|
6466 | var packedNodes = new Array(count);
|
6467 | for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
|
6468 | var node = nodes[ii];
|
6469 | if (node !== undefined && ii !== excluding) {
|
6470 | bitmap |= bit;
|
6471 | packedNodes[packedII++] = node;
|
6472 | }
|
6473 | }
|
6474 | return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
|
6475 | }
|
6476 |
|
6477 | function expandNodes(ownerID, nodes, bitmap, including, node) {
|
6478 | var count = 0;
|
6479 | var expandedNodes = new Array(SIZE);
|
6480 | for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
|
6481 | expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
|
6482 | }
|
6483 | expandedNodes[including] = node;
|
6484 | return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
|
6485 | }
|
6486 |
|
6487 | function mergeIntoMapWith(map, merger, iterables) {
|
6488 | var iters = [];
|
6489 | for (var ii = 0; ii < iterables.length; ii++) {
|
6490 | var value = iterables[ii];
|
6491 | var iter = KeyedIterable(value);
|
6492 | if (!isIterable(value)) {
|
6493 | iter = iter.map(function(v ) {return fromJS(v)});
|
6494 | }
|
6495 | iters.push(iter);
|
6496 | }
|
6497 | return mergeIntoCollectionWith(map, merger, iters);
|
6498 | }
|
6499 |
|
6500 | function deepMerger(existing, value, key) {
|
6501 | return existing && existing.mergeDeep && isIterable(value) ?
|
6502 | existing.mergeDeep(value) :
|
6503 | is(existing, value) ? existing : value;
|
6504 | }
|
6505 |
|
6506 | function deepMergerWith(merger) {
|
6507 | return function(existing, value, key) {
|
6508 | if (existing && existing.mergeDeepWith && isIterable(value)) {
|
6509 | return existing.mergeDeepWith(merger, value);
|
6510 | }
|
6511 | var nextValue = merger(existing, value, key);
|
6512 | return is(existing, nextValue) ? existing : nextValue;
|
6513 | };
|
6514 | }
|
6515 |
|
6516 | function mergeIntoCollectionWith(collection, merger, iters) {
|
6517 | iters = iters.filter(function(x ) {return x.size !== 0});
|
6518 | if (iters.length === 0) {
|
6519 | return collection;
|
6520 | }
|
6521 | if (collection.size === 0 && !collection.__ownerID && iters.length === 1) {
|
6522 | return collection.constructor(iters[0]);
|
6523 | }
|
6524 | return collection.withMutations(function(collection ) {
|
6525 | var mergeIntoMap = merger ?
|
6526 | function(value, key) {
|
6527 | collection.update(key, NOT_SET, function(existing )
|
6528 | {return existing === NOT_SET ? value : merger(existing, value, key)}
|
6529 | );
|
6530 | } :
|
6531 | function(value, key) {
|
6532 | collection.set(key, value);
|
6533 | }
|
6534 | for (var ii = 0; ii < iters.length; ii++) {
|
6535 | iters[ii].forEach(mergeIntoMap);
|
6536 | }
|
6537 | });
|
6538 | }
|
6539 |
|
6540 | function updateInDeepMap(existing, keyPathIter, notSetValue, updater) {
|
6541 | var isNotSet = existing === NOT_SET;
|
6542 | var step = keyPathIter.next();
|
6543 | if (step.done) {
|
6544 | var existingValue = isNotSet ? notSetValue : existing;
|
6545 | var newValue = updater(existingValue);
|
6546 | return newValue === existingValue ? existing : newValue;
|
6547 | }
|
6548 | invariant(
|
6549 | isNotSet || (existing && existing.set),
|
6550 | 'invalid keyPath'
|
6551 | );
|
6552 | var key = step.value;
|
6553 | var nextExisting = isNotSet ? NOT_SET : existing.get(key, NOT_SET);
|
6554 | var nextUpdated = updateInDeepMap(
|
6555 | nextExisting,
|
6556 | keyPathIter,
|
6557 | notSetValue,
|
6558 | updater
|
6559 | );
|
6560 | return nextUpdated === nextExisting ? existing :
|
6561 | nextUpdated === NOT_SET ? existing.remove(key) :
|
6562 | (isNotSet ? emptyMap() : existing).set(key, nextUpdated);
|
6563 | }
|
6564 |
|
6565 | function popCount(x) {
|
6566 | x = x - ((x >> 1) & 0x55555555);
|
6567 | x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
|
6568 | x = (x + (x >> 4)) & 0x0f0f0f0f;
|
6569 | x = x + (x >> 8);
|
6570 | x = x + (x >> 16);
|
6571 | return x & 0x7f;
|
6572 | }
|
6573 |
|
6574 | function setIn(array, idx, val, canEdit) {
|
6575 | var newArray = canEdit ? array : arrCopy(array);
|
6576 | newArray[idx] = val;
|
6577 | return newArray;
|
6578 | }
|
6579 |
|
6580 | function spliceIn(array, idx, val, canEdit) {
|
6581 | var newLen = array.length + 1;
|
6582 | if (canEdit && idx + 1 === newLen) {
|
6583 | array[idx] = val;
|
6584 | return array;
|
6585 | }
|
6586 | var newArray = new Array(newLen);
|
6587 | var after = 0;
|
6588 | for (var ii = 0; ii < newLen; ii++) {
|
6589 | if (ii === idx) {
|
6590 | newArray[ii] = val;
|
6591 | after = -1;
|
6592 | } else {
|
6593 | newArray[ii] = array[ii + after];
|
6594 | }
|
6595 | }
|
6596 | return newArray;
|
6597 | }
|
6598 |
|
6599 | function spliceOut(array, idx, canEdit) {
|
6600 | var newLen = array.length - 1;
|
6601 | if (canEdit && idx === newLen) {
|
6602 | array.pop();
|
6603 | return array;
|
6604 | }
|
6605 | var newArray = new Array(newLen);
|
6606 | var after = 0;
|
6607 | for (var ii = 0; ii < newLen; ii++) {
|
6608 | if (ii === idx) {
|
6609 | after = 1;
|
6610 | }
|
6611 | newArray[ii] = array[ii + after];
|
6612 | }
|
6613 | return newArray;
|
6614 | }
|
6615 |
|
6616 | var MAX_ARRAY_MAP_SIZE = SIZE / 4;
|
6617 | var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
|
6618 | var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
|
6619 |
|
6620 | createClass(List, IndexedCollection);
|
6621 |
|
6622 |
|
6623 |
|
6624 | function List(value) {
|
6625 | var empty = emptyList();
|
6626 | if (value === null || value === undefined) {
|
6627 | return empty;
|
6628 | }
|
6629 | if (isList(value)) {
|
6630 | return value;
|
6631 | }
|
6632 | var iter = IndexedIterable(value);
|
6633 | var size = iter.size;
|
6634 | if (size === 0) {
|
6635 | return empty;
|
6636 | }
|
6637 | assertNotInfinite(size);
|
6638 | if (size > 0 && size < SIZE) {
|
6639 | return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
|
6640 | }
|
6641 | return empty.withMutations(function(list ) {
|
6642 | list.setSize(size);
|
6643 | iter.forEach(function(v, i) {return list.set(i, v)});
|
6644 | });
|
6645 | }
|
6646 |
|
6647 | List.of = function(/*...values*/) {
|
6648 | return this(arguments);
|
6649 | };
|
6650 |
|
6651 | List.prototype.toString = function() {
|
6652 | return this.__toString('List [', ']');
|
6653 | };
|
6654 |
|
6655 |
|
6656 |
|
6657 | List.prototype.get = function(index, notSetValue) {
|
6658 | index = wrapIndex(this, index);
|
6659 | if (index >= 0 && index < this.size) {
|
6660 | index += this._origin;
|
6661 | var node = listNodeFor(this, index);
|
6662 | return node && node.array[index & MASK];
|
6663 | }
|
6664 | return notSetValue;
|
6665 | };
|
6666 |
|
6667 |
|
6668 |
|
6669 | List.prototype.set = function(index, value) {
|
6670 | return updateList(this, index, value);
|
6671 | };
|
6672 |
|
6673 | List.prototype.remove = function(index) {
|
6674 | return !this.has(index) ? this :
|
6675 | index === 0 ? this.shift() :
|
6676 | index === this.size - 1 ? this.pop() :
|
6677 | this.splice(index, 1);
|
6678 | };
|
6679 |
|
6680 | List.prototype.insert = function(index, value) {
|
6681 | return this.splice(index, 0, value);
|
6682 | };
|
6683 |
|
6684 | List.prototype.clear = function() {
|
6685 | if (this.size === 0) {
|
6686 | return this;
|
6687 | }
|
6688 | if (this.__ownerID) {
|
6689 | this.size = this._origin = this._capacity = 0;
|
6690 | this._level = SHIFT;
|
6691 | this._root = this._tail = null;
|
6692 | this.__hash = undefined;
|
6693 | this.__altered = true;
|
6694 | return this;
|
6695 | }
|
6696 | return emptyList();
|
6697 | };
|
6698 |
|
6699 | List.prototype.push = function(/*...values*/) {
|
6700 | var values = arguments;
|
6701 | var oldSize = this.size;
|
6702 | return this.withMutations(function(list ) {
|
6703 | setListBounds(list, 0, oldSize + values.length);
|
6704 | for (var ii = 0; ii < values.length; ii++) {
|
6705 | list.set(oldSize + ii, values[ii]);
|
6706 | }
|
6707 | });
|
6708 | };
|
6709 |
|
6710 | List.prototype.pop = function() {
|
6711 | return setListBounds(this, 0, -1);
|
6712 | };
|
6713 |
|
6714 | List.prototype.unshift = function(/*...values*/) {
|
6715 | var values = arguments;
|
6716 | return this.withMutations(function(list ) {
|
6717 | setListBounds(list, -values.length);
|
6718 | for (var ii = 0; ii < values.length; ii++) {
|
6719 | list.set(ii, values[ii]);
|
6720 | }
|
6721 | });
|
6722 | };
|
6723 |
|
6724 | List.prototype.shift = function() {
|
6725 | return setListBounds(this, 1);
|
6726 | };
|
6727 |
|
6728 |
|
6729 |
|
6730 | List.prototype.merge = function(/*...iters*/) {
|
6731 | return mergeIntoListWith(this, undefined, arguments);
|
6732 | };
|
6733 |
|
6734 | List.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
|
6735 | return mergeIntoListWith(this, merger, iters);
|
6736 | };
|
6737 |
|
6738 | List.prototype.mergeDeep = function(/*...iters*/) {
|
6739 | return mergeIntoListWith(this, deepMerger, arguments);
|
6740 | };
|
6741 |
|
6742 | List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
|
6743 | return mergeIntoListWith(this, deepMergerWith(merger), iters);
|
6744 | };
|
6745 |
|
6746 | List.prototype.setSize = function(size) {
|
6747 | return setListBounds(this, 0, size);
|
6748 | };
|
6749 |
|
6750 |
|
6751 |
|
6752 | List.prototype.slice = function(begin, end) {
|
6753 | var size = this.size;
|
6754 | if (wholeSlice(begin, end, size)) {
|
6755 | return this;
|
6756 | }
|
6757 | return setListBounds(
|
6758 | this,
|
6759 | resolveBegin(begin, size),
|
6760 | resolveEnd(end, size)
|
6761 | );
|
6762 | };
|
6763 |
|
6764 | List.prototype.__iterator = function(type, reverse) {
|
6765 | var index = 0;
|
6766 | var values = iterateList(this, reverse);
|
6767 | return new Iterator(function() {
|
6768 | var value = values();
|
6769 | return value === DONE ?
|
6770 | iteratorDone() :
|
6771 | iteratorValue(type, index++, value);
|
6772 | });
|
6773 | };
|
6774 |
|
6775 | List.prototype.__iterate = function(fn, reverse) {
|
6776 | var index = 0;
|
6777 | var values = iterateList(this, reverse);
|
6778 | var value;
|
6779 | while ((value = values()) !== DONE) {
|
6780 | if (fn(value, index++, this) === false) {
|
6781 | break;
|
6782 | }
|
6783 | }
|
6784 | return index;
|
6785 | };
|
6786 |
|
6787 | List.prototype.__ensureOwner = function(ownerID) {
|
6788 | if (ownerID === this.__ownerID) {
|
6789 | return this;
|
6790 | }
|
6791 | if (!ownerID) {
|
6792 | this.__ownerID = ownerID;
|
6793 | return this;
|
6794 | }
|
6795 | return makeList(this._origin, this._capacity, this._level, this._root, this._tail, ownerID, this.__hash);
|
6796 | };
|
6797 |
|
6798 |
|
6799 | function isList(maybeList) {
|
6800 | return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
|
6801 | }
|
6802 |
|
6803 | List.isList = isList;
|
6804 |
|
6805 | var IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
|
6806 |
|
6807 | var ListPrototype = List.prototype;
|
6808 | ListPrototype[IS_LIST_SENTINEL] = true;
|
6809 | ListPrototype[DELETE] = ListPrototype.remove;
|
6810 | ListPrototype.setIn = MapPrototype.setIn;
|
6811 | ListPrototype.deleteIn =
|
6812 | ListPrototype.removeIn = MapPrototype.removeIn;
|
6813 | ListPrototype.update = MapPrototype.update;
|
6814 | ListPrototype.updateIn = MapPrototype.updateIn;
|
6815 | ListPrototype.mergeIn = MapPrototype.mergeIn;
|
6816 | ListPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
|
6817 | ListPrototype.withMutations = MapPrototype.withMutations;
|
6818 | ListPrototype.asMutable = MapPrototype.asMutable;
|
6819 | ListPrototype.asImmutable = MapPrototype.asImmutable;
|
6820 | ListPrototype.wasAltered = MapPrototype.wasAltered;
|
6821 |
|
6822 |
|
6823 |
|
6824 | function VNode(array, ownerID) {
|
6825 | this.array = array;
|
6826 | this.ownerID = ownerID;
|
6827 | }
|
6828 |
|
6829 |
|
6830 |
|
6831 | VNode.prototype.removeBefore = function(ownerID, level, index) {
|
6832 | if (index === level ? 1 << level : 0 || this.array.length === 0) {
|
6833 | return this;
|
6834 | }
|
6835 | var originIndex = (index >>> level) & MASK;
|
6836 | if (originIndex >= this.array.length) {
|
6837 | return new VNode([], ownerID);
|
6838 | }
|
6839 | var removingFirst = originIndex === 0;
|
6840 | var newChild;
|
6841 | if (level > 0) {
|
6842 | var oldChild = this.array[originIndex];
|
6843 | newChild = oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
|
6844 | if (newChild === oldChild && removingFirst) {
|
6845 | return this;
|
6846 | }
|
6847 | }
|
6848 | if (removingFirst && !newChild) {
|
6849 | return this;
|
6850 | }
|
6851 | var editable = editableVNode(this, ownerID);
|
6852 | if (!removingFirst) {
|
6853 | for (var ii = 0; ii < originIndex; ii++) {
|
6854 | editable.array[ii] = undefined;
|
6855 | }
|
6856 | }
|
6857 | if (newChild) {
|
6858 | editable.array[originIndex] = newChild;
|
6859 | }
|
6860 | return editable;
|
6861 | };
|
6862 |
|
6863 | VNode.prototype.removeAfter = function(ownerID, level, index) {
|
6864 | if (index === (level ? 1 << level : 0) || this.array.length === 0) {
|
6865 | return this;
|
6866 | }
|
6867 | var sizeIndex = ((index - 1) >>> level) & MASK;
|
6868 | if (sizeIndex >= this.array.length) {
|
6869 | return this;
|
6870 | }
|
6871 |
|
6872 | var newChild;
|
6873 | if (level > 0) {
|
6874 | var oldChild = this.array[sizeIndex];
|
6875 | newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
|
6876 | if (newChild === oldChild && sizeIndex === this.array.length - 1) {
|
6877 | return this;
|
6878 | }
|
6879 | }
|
6880 |
|
6881 | var editable = editableVNode(this, ownerID);
|
6882 | editable.array.splice(sizeIndex + 1);
|
6883 | if (newChild) {
|
6884 | editable.array[sizeIndex] = newChild;
|
6885 | }
|
6886 | return editable;
|
6887 | };
|
6888 |
|
6889 |
|
6890 |
|
6891 | var DONE = {};
|
6892 |
|
6893 | function iterateList(list, reverse) {
|
6894 | var left = list._origin;
|
6895 | var right = list._capacity;
|
6896 | var tailPos = getTailOffset(right);
|
6897 | var tail = list._tail;
|
6898 |
|
6899 | return iterateNodeOrLeaf(list._root, list._level, 0);
|
6900 |
|
6901 | function iterateNodeOrLeaf(node, level, offset) {
|
6902 | return level === 0 ?
|
6903 | iterateLeaf(node, offset) :
|
6904 | iterateNode(node, level, offset);
|
6905 | }
|
6906 |
|
6907 | function iterateLeaf(node, offset) {
|
6908 | var array = offset === tailPos ? tail && tail.array : node && node.array;
|
6909 | var from = offset > left ? 0 : left - offset;
|
6910 | var to = right - offset;
|
6911 | if (to > SIZE) {
|
6912 | to = SIZE;
|
6913 | }
|
6914 | return function() {
|
6915 | if (from === to) {
|
6916 | return DONE;
|
6917 | }
|
6918 | var idx = reverse ? --to : from++;
|
6919 | return array && array[idx];
|
6920 | };
|
6921 | }
|
6922 |
|
6923 | function iterateNode(node, level, offset) {
|
6924 | var values;
|
6925 | var array = node && node.array;
|
6926 | var from = offset > left ? 0 : (left - offset) >> level;
|
6927 | var to = ((right - offset) >> level) + 1;
|
6928 | if (to > SIZE) {
|
6929 | to = SIZE;
|
6930 | }
|
6931 | return function() {
|
6932 | do {
|
6933 | if (values) {
|
6934 | var value = values();
|
6935 | if (value !== DONE) {
|
6936 | return value;
|
6937 | }
|
6938 | values = null;
|
6939 | }
|
6940 | if (from === to) {
|
6941 | return DONE;
|
6942 | }
|
6943 | var idx = reverse ? --to : from++;
|
6944 | values = iterateNodeOrLeaf(
|
6945 | array && array[idx], level - SHIFT, offset + (idx << level)
|
6946 | );
|
6947 | } while (true);
|
6948 | };
|
6949 | }
|
6950 | }
|
6951 |
|
6952 | function makeList(origin, capacity, level, root, tail, ownerID, hash) {
|
6953 | var list = Object.create(ListPrototype);
|
6954 | list.size = capacity - origin;
|
6955 | list._origin = origin;
|
6956 | list._capacity = capacity;
|
6957 | list._level = level;
|
6958 | list._root = root;
|
6959 | list._tail = tail;
|
6960 | list.__ownerID = ownerID;
|
6961 | list.__hash = hash;
|
6962 | list.__altered = false;
|
6963 | return list;
|
6964 | }
|
6965 |
|
6966 | var EMPTY_LIST;
|
6967 | function emptyList() {
|
6968 | return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));
|
6969 | }
|
6970 |
|
6971 | function updateList(list, index, value) {
|
6972 | index = wrapIndex(list, index);
|
6973 |
|
6974 | if (index !== index) {
|
6975 | return list;
|
6976 | }
|
6977 |
|
6978 | if (index >= list.size || index < 0) {
|
6979 | return list.withMutations(function(list ) {
|
6980 | index < 0 ?
|
6981 | setListBounds(list, index).set(0, value) :
|
6982 | setListBounds(list, 0, index + 1).set(index, value)
|
6983 | });
|
6984 | }
|
6985 |
|
6986 | index += list._origin;
|
6987 |
|
6988 | var newTail = list._tail;
|
6989 | var newRoot = list._root;
|
6990 | var didAlter = MakeRef(DID_ALTER);
|
6991 | if (index >= getTailOffset(list._capacity)) {
|
6992 | newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
|
6993 | } else {
|
6994 | newRoot = updateVNode(newRoot, list.__ownerID, list._level, index, value, didAlter);
|
6995 | }
|
6996 |
|
6997 | if (!didAlter.value) {
|
6998 | return list;
|
6999 | }
|
7000 |
|
7001 | if (list.__ownerID) {
|
7002 | list._root = newRoot;
|
7003 | list._tail = newTail;
|
7004 | list.__hash = undefined;
|
7005 | list.__altered = true;
|
7006 | return list;
|
7007 | }
|
7008 | return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
|
7009 | }
|
7010 |
|
7011 | function updateVNode(node, ownerID, level, index, value, didAlter) {
|
7012 | var idx = (index >>> level) & MASK;
|
7013 | var nodeHas = node && idx < node.array.length;
|
7014 | if (!nodeHas && value === undefined) {
|
7015 | return node;
|
7016 | }
|
7017 |
|
7018 | var newNode;
|
7019 |
|
7020 | if (level > 0) {
|
7021 | var lowerNode = node && node.array[idx];
|
7022 | var newLowerNode = updateVNode(lowerNode, ownerID, level - SHIFT, index, value, didAlter);
|
7023 | if (newLowerNode === lowerNode) {
|
7024 | return node;
|
7025 | }
|
7026 | newNode = editableVNode(node, ownerID);
|
7027 | newNode.array[idx] = newLowerNode;
|
7028 | return newNode;
|
7029 | }
|
7030 |
|
7031 | if (nodeHas && node.array[idx] === value) {
|
7032 | return node;
|
7033 | }
|
7034 |
|
7035 | SetRef(didAlter);
|
7036 |
|
7037 | newNode = editableVNode(node, ownerID);
|
7038 | if (value === undefined && idx === newNode.array.length - 1) {
|
7039 | newNode.array.pop();
|
7040 | } else {
|
7041 | newNode.array[idx] = value;
|
7042 | }
|
7043 | return newNode;
|
7044 | }
|
7045 |
|
7046 | function editableVNode(node, ownerID) {
|
7047 | if (ownerID && node && ownerID === node.ownerID) {
|
7048 | return node;
|
7049 | }
|
7050 | return new VNode(node ? node.array.slice() : [], ownerID);
|
7051 | }
|
7052 |
|
7053 | function listNodeFor(list, rawIndex) {
|
7054 | if (rawIndex >= getTailOffset(list._capacity)) {
|
7055 | return list._tail;
|
7056 | }
|
7057 | if (rawIndex < 1 << (list._level + SHIFT)) {
|
7058 | var node = list._root;
|
7059 | var level = list._level;
|
7060 | while (node && level > 0) {
|
7061 | node = node.array[(rawIndex >>> level) & MASK];
|
7062 | level -= SHIFT;
|
7063 | }
|
7064 | return node;
|
7065 | }
|
7066 | }
|
7067 |
|
7068 | function setListBounds(list, begin, end) {
|
7069 |
|
7070 |
|
7071 | if (begin !== undefined) {
|
7072 | begin = begin | 0;
|
7073 | }
|
7074 | if (end !== undefined) {
|
7075 | end = end | 0;
|
7076 | }
|
7077 | var owner = list.__ownerID || new OwnerID();
|
7078 | var oldOrigin = list._origin;
|
7079 | var oldCapacity = list._capacity;
|
7080 | var newOrigin = oldOrigin + begin;
|
7081 | var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end;
|
7082 | if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
|
7083 | return list;
|
7084 | }
|
7085 |
|
7086 |
|
7087 | if (newOrigin >= newCapacity) {
|
7088 | return list.clear();
|
7089 | }
|
7090 |
|
7091 | var newLevel = list._level;
|
7092 | var newRoot = list._root;
|
7093 |
|
7094 |
|
7095 | var offsetShift = 0;
|
7096 | while (newOrigin + offsetShift < 0) {
|
7097 | newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
|
7098 | newLevel += SHIFT;
|
7099 | offsetShift += 1 << newLevel;
|
7100 | }
|
7101 | if (offsetShift) {
|
7102 | newOrigin += offsetShift;
|
7103 | oldOrigin += offsetShift;
|
7104 | newCapacity += offsetShift;
|
7105 | oldCapacity += offsetShift;
|
7106 | }
|
7107 |
|
7108 | var oldTailOffset = getTailOffset(oldCapacity);
|
7109 | var newTailOffset = getTailOffset(newCapacity);
|
7110 |
|
7111 |
|
7112 | while (newTailOffset >= 1 << (newLevel + SHIFT)) {
|
7113 | newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
|
7114 | newLevel += SHIFT;
|
7115 | }
|
7116 |
|
7117 |
|
7118 | var oldTail = list._tail;
|
7119 | var newTail = newTailOffset < oldTailOffset ?
|
7120 | listNodeFor(list, newCapacity - 1) :
|
7121 | newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
|
7122 |
|
7123 |
|
7124 | if (oldTail && newTailOffset > oldTailOffset && newOrigin < oldCapacity && oldTail.array.length) {
|
7125 | newRoot = editableVNode(newRoot, owner);
|
7126 | var node = newRoot;
|
7127 | for (var level = newLevel; level > SHIFT; level -= SHIFT) {
|
7128 | var idx = (oldTailOffset >>> level) & MASK;
|
7129 | node = node.array[idx] = editableVNode(node.array[idx], owner);
|
7130 | }
|
7131 | node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
|
7132 | }
|
7133 |
|
7134 |
|
7135 | if (newCapacity < oldCapacity) {
|
7136 | newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
|
7137 | }
|
7138 |
|
7139 |
|
7140 | if (newOrigin >= newTailOffset) {
|
7141 | newOrigin -= newTailOffset;
|
7142 | newCapacity -= newTailOffset;
|
7143 | newLevel = SHIFT;
|
7144 | newRoot = null;
|
7145 | newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
|
7146 |
|
7147 |
|
7148 | } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
|
7149 | offsetShift = 0;
|
7150 |
|
7151 |
|
7152 | while (newRoot) {
|
7153 | var beginIndex = (newOrigin >>> newLevel) & MASK;
|
7154 | if (beginIndex !== (newTailOffset >>> newLevel) & MASK) {
|
7155 | break;
|
7156 | }
|
7157 | if (beginIndex) {
|
7158 | offsetShift += (1 << newLevel) * beginIndex;
|
7159 | }
|
7160 | newLevel -= SHIFT;
|
7161 | newRoot = newRoot.array[beginIndex];
|
7162 | }
|
7163 |
|
7164 |
|
7165 | if (newRoot && newOrigin > oldOrigin) {
|
7166 | newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
|
7167 | }
|
7168 | if (newRoot && newTailOffset < oldTailOffset) {
|
7169 | newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
|
7170 | }
|
7171 | if (offsetShift) {
|
7172 | newOrigin -= offsetShift;
|
7173 | newCapacity -= offsetShift;
|
7174 | }
|
7175 | }
|
7176 |
|
7177 | if (list.__ownerID) {
|
7178 | list.size = newCapacity - newOrigin;
|
7179 | list._origin = newOrigin;
|
7180 | list._capacity = newCapacity;
|
7181 | list._level = newLevel;
|
7182 | list._root = newRoot;
|
7183 | list._tail = newTail;
|
7184 | list.__hash = undefined;
|
7185 | list.__altered = true;
|
7186 | return list;
|
7187 | }
|
7188 | return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
|
7189 | }
|
7190 |
|
7191 | function mergeIntoListWith(list, merger, iterables) {
|
7192 | var iters = [];
|
7193 | var maxSize = 0;
|
7194 | for (var ii = 0; ii < iterables.length; ii++) {
|
7195 | var value = iterables[ii];
|
7196 | var iter = IndexedIterable(value);
|
7197 | if (iter.size > maxSize) {
|
7198 | maxSize = iter.size;
|
7199 | }
|
7200 | if (!isIterable(value)) {
|
7201 | iter = iter.map(function(v ) {return fromJS(v)});
|
7202 | }
|
7203 | iters.push(iter);
|
7204 | }
|
7205 | if (maxSize > list.size) {
|
7206 | list = list.setSize(maxSize);
|
7207 | }
|
7208 | return mergeIntoCollectionWith(list, merger, iters);
|
7209 | }
|
7210 |
|
7211 | function getTailOffset(size) {
|
7212 | return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
|
7213 | }
|
7214 |
|
7215 | createClass(OrderedMap, Map);
|
7216 |
|
7217 |
|
7218 |
|
7219 | function OrderedMap(value) {
|
7220 | return value === null || value === undefined ? emptyOrderedMap() :
|
7221 | isOrderedMap(value) ? value :
|
7222 | emptyOrderedMap().withMutations(function(map ) {
|
7223 | var iter = KeyedIterable(value);
|
7224 | assertNotInfinite(iter.size);
|
7225 | iter.forEach(function(v, k) {return map.set(k, v)});
|
7226 | });
|
7227 | }
|
7228 |
|
7229 | OrderedMap.of = function(/*...values*/) {
|
7230 | return this(arguments);
|
7231 | };
|
7232 |
|
7233 | OrderedMap.prototype.toString = function() {
|
7234 | return this.__toString('OrderedMap {', '}');
|
7235 | };
|
7236 |
|
7237 |
|
7238 |
|
7239 | OrderedMap.prototype.get = function(k, notSetValue) {
|
7240 | var index = this._map.get(k);
|
7241 | return index !== undefined ? this._list.get(index)[1] : notSetValue;
|
7242 | };
|
7243 |
|
7244 |
|
7245 |
|
7246 | OrderedMap.prototype.clear = function() {
|
7247 | if (this.size === 0) {
|
7248 | return this;
|
7249 | }
|
7250 | if (this.__ownerID) {
|
7251 | this.size = 0;
|
7252 | this._map.clear();
|
7253 | this._list.clear();
|
7254 | return this;
|
7255 | }
|
7256 | return emptyOrderedMap();
|
7257 | };
|
7258 |
|
7259 | OrderedMap.prototype.set = function(k, v) {
|
7260 | return updateOrderedMap(this, k, v);
|
7261 | };
|
7262 |
|
7263 | OrderedMap.prototype.remove = function(k) {
|
7264 | return updateOrderedMap(this, k, NOT_SET);
|
7265 | };
|
7266 |
|
7267 | OrderedMap.prototype.wasAltered = function() {
|
7268 | return this._map.wasAltered() || this._list.wasAltered();
|
7269 | };
|
7270 |
|
7271 | OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
|
7272 | return this._list.__iterate(
|
7273 | function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
|
7274 | reverse
|
7275 | );
|
7276 | };
|
7277 |
|
7278 | OrderedMap.prototype.__iterator = function(type, reverse) {
|
7279 | return this._list.fromEntrySeq().__iterator(type, reverse);
|
7280 | };
|
7281 |
|
7282 | OrderedMap.prototype.__ensureOwner = function(ownerID) {
|
7283 | if (ownerID === this.__ownerID) {
|
7284 | return this;
|
7285 | }
|
7286 | var newMap = this._map.__ensureOwner(ownerID);
|
7287 | var newList = this._list.__ensureOwner(ownerID);
|
7288 | if (!ownerID) {
|
7289 | this.__ownerID = ownerID;
|
7290 | this._map = newMap;
|
7291 | this._list = newList;
|
7292 | return this;
|
7293 | }
|
7294 | return makeOrderedMap(newMap, newList, ownerID, this.__hash);
|
7295 | };
|
7296 |
|
7297 |
|
7298 | function isOrderedMap(maybeOrderedMap) {
|
7299 | return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
|
7300 | }
|
7301 |
|
7302 | OrderedMap.isOrderedMap = isOrderedMap;
|
7303 |
|
7304 | OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
|
7305 | OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
|
7306 |
|
7307 |
|
7308 |
|
7309 | function makeOrderedMap(map, list, ownerID, hash) {
|
7310 | var omap = Object.create(OrderedMap.prototype);
|
7311 | omap.size = map ? map.size : 0;
|
7312 | omap._map = map;
|
7313 | omap._list = list;
|
7314 | omap.__ownerID = ownerID;
|
7315 | omap.__hash = hash;
|
7316 | return omap;
|
7317 | }
|
7318 |
|
7319 | var EMPTY_ORDERED_MAP;
|
7320 | function emptyOrderedMap() {
|
7321 | return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
|
7322 | }
|
7323 |
|
7324 | function updateOrderedMap(omap, k, v) {
|
7325 | var map = omap._map;
|
7326 | var list = omap._list;
|
7327 | var i = map.get(k);
|
7328 | var has = i !== undefined;
|
7329 | var newMap;
|
7330 | var newList;
|
7331 | if (v === NOT_SET) {
|
7332 | if (!has) {
|
7333 | return omap;
|
7334 | }
|
7335 | if (list.size >= SIZE && list.size >= map.size * 2) {
|
7336 | newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
|
7337 | newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
|
7338 | if (omap.__ownerID) {
|
7339 | newMap.__ownerID = newList.__ownerID = omap.__ownerID;
|
7340 | }
|
7341 | } else {
|
7342 | newMap = map.remove(k);
|
7343 | newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
|
7344 | }
|
7345 | } else {
|
7346 | if (has) {
|
7347 | if (v === list.get(i)[1]) {
|
7348 | return omap;
|
7349 | }
|
7350 | newMap = map;
|
7351 | newList = list.set(i, [k, v]);
|
7352 | } else {
|
7353 | newMap = map.set(k, list.size);
|
7354 | newList = list.set(list.size, [k, v]);
|
7355 | }
|
7356 | }
|
7357 | if (omap.__ownerID) {
|
7358 | omap.size = newMap.size;
|
7359 | omap._map = newMap;
|
7360 | omap._list = newList;
|
7361 | omap.__hash = undefined;
|
7362 | return omap;
|
7363 | }
|
7364 | return makeOrderedMap(newMap, newList);
|
7365 | }
|
7366 |
|
7367 | createClass(ToKeyedSequence, KeyedSeq);
|
7368 | function ToKeyedSequence(indexed, useKeys) {
|
7369 | this._iter = indexed;
|
7370 | this._useKeys = useKeys;
|
7371 | this.size = indexed.size;
|
7372 | }
|
7373 |
|
7374 | ToKeyedSequence.prototype.get = function(key, notSetValue) {
|
7375 | return this._iter.get(key, notSetValue);
|
7376 | };
|
7377 |
|
7378 | ToKeyedSequence.prototype.has = function(key) {
|
7379 | return this._iter.has(key);
|
7380 | };
|
7381 |
|
7382 | ToKeyedSequence.prototype.valueSeq = function() {
|
7383 | return this._iter.valueSeq();
|
7384 | };
|
7385 |
|
7386 | ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
|
7387 | var reversedSequence = reverseFactory(this, true);
|
7388 | if (!this._useKeys) {
|
7389 | reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
|
7390 | }
|
7391 | return reversedSequence;
|
7392 | };
|
7393 |
|
7394 | ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
|
7395 | var mappedSequence = mapFactory(this, mapper, context);
|
7396 | if (!this._useKeys) {
|
7397 | mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
|
7398 | }
|
7399 | return mappedSequence;
|
7400 | };
|
7401 |
|
7402 | ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
|
7403 | var ii;
|
7404 | return this._iter.__iterate(
|
7405 | this._useKeys ?
|
7406 | function(v, k) {return fn(v, k, this$0)} :
|
7407 | ((ii = reverse ? resolveSize(this) : 0),
|
7408 | function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
|
7409 | reverse
|
7410 | );
|
7411 | };
|
7412 |
|
7413 | ToKeyedSequence.prototype.__iterator = function(type, reverse) {
|
7414 | if (this._useKeys) {
|
7415 | return this._iter.__iterator(type, reverse);
|
7416 | }
|
7417 | var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
|
7418 | var ii = reverse ? resolveSize(this) : 0;
|
7419 | return new Iterator(function() {
|
7420 | var step = iterator.next();
|
7421 | return step.done ? step :
|
7422 | iteratorValue(type, reverse ? --ii : ii++, step.value, step);
|
7423 | });
|
7424 | };
|
7425 |
|
7426 | ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
|
7427 |
|
7428 |
|
7429 | createClass(ToIndexedSequence, IndexedSeq);
|
7430 | function ToIndexedSequence(iter) {
|
7431 | this._iter = iter;
|
7432 | this.size = iter.size;
|
7433 | }
|
7434 |
|
7435 | ToIndexedSequence.prototype.includes = function(value) {
|
7436 | return this._iter.includes(value);
|
7437 | };
|
7438 |
|
7439 | ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
|
7440 | var iterations = 0;
|
7441 | return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
|
7442 | };
|
7443 |
|
7444 | ToIndexedSequence.prototype.__iterator = function(type, reverse) {
|
7445 | var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
|
7446 | var iterations = 0;
|
7447 | return new Iterator(function() {
|
7448 | var step = iterator.next();
|
7449 | return step.done ? step :
|
7450 | iteratorValue(type, iterations++, step.value, step)
|
7451 | });
|
7452 | };
|
7453 |
|
7454 |
|
7455 |
|
7456 | createClass(ToSetSequence, SetSeq);
|
7457 | function ToSetSequence(iter) {
|
7458 | this._iter = iter;
|
7459 | this.size = iter.size;
|
7460 | }
|
7461 |
|
7462 | ToSetSequence.prototype.has = function(key) {
|
7463 | return this._iter.includes(key);
|
7464 | };
|
7465 |
|
7466 | ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
|
7467 | return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
|
7468 | };
|
7469 |
|
7470 | ToSetSequence.prototype.__iterator = function(type, reverse) {
|
7471 | var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
|
7472 | return new Iterator(function() {
|
7473 | var step = iterator.next();
|
7474 | return step.done ? step :
|
7475 | iteratorValue(type, step.value, step.value, step);
|
7476 | });
|
7477 | };
|
7478 |
|
7479 |
|
7480 |
|
7481 | createClass(FromEntriesSequence, KeyedSeq);
|
7482 | function FromEntriesSequence(entries) {
|
7483 | this._iter = entries;
|
7484 | this.size = entries.size;
|
7485 | }
|
7486 |
|
7487 | FromEntriesSequence.prototype.entrySeq = function() {
|
7488 | return this._iter.toSeq();
|
7489 | };
|
7490 |
|
7491 | FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
|
7492 | return this._iter.__iterate(function(entry ) {
|
7493 |
|
7494 |
|
7495 | if (entry) {
|
7496 | validateEntry(entry);
|
7497 | var indexedIterable = isIterable(entry);
|
7498 | return fn(
|
7499 | indexedIterable ? entry.get(1) : entry[1],
|
7500 | indexedIterable ? entry.get(0) : entry[0],
|
7501 | this$0
|
7502 | );
|
7503 | }
|
7504 | }, reverse);
|
7505 | };
|
7506 |
|
7507 | FromEntriesSequence.prototype.__iterator = function(type, reverse) {
|
7508 | var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
|
7509 | return new Iterator(function() {
|
7510 | while (true) {
|
7511 | var step = iterator.next();
|
7512 | if (step.done) {
|
7513 | return step;
|
7514 | }
|
7515 | var entry = step.value;
|
7516 |
|
7517 |
|
7518 | if (entry) {
|
7519 | validateEntry(entry);
|
7520 | var indexedIterable = isIterable(entry);
|
7521 | return iteratorValue(
|
7522 | type,
|
7523 | indexedIterable ? entry.get(0) : entry[0],
|
7524 | indexedIterable ? entry.get(1) : entry[1],
|
7525 | step
|
7526 | );
|
7527 | }
|
7528 | }
|
7529 | });
|
7530 | };
|
7531 |
|
7532 |
|
7533 | ToIndexedSequence.prototype.cacheResult =
|
7534 | ToKeyedSequence.prototype.cacheResult =
|
7535 | ToSetSequence.prototype.cacheResult =
|
7536 | FromEntriesSequence.prototype.cacheResult =
|
7537 | cacheResultThrough;
|
7538 |
|
7539 |
|
7540 | function flipFactory(iterable) {
|
7541 | var flipSequence = makeSequence(iterable);
|
7542 | flipSequence._iter = iterable;
|
7543 | flipSequence.size = iterable.size;
|
7544 | flipSequence.flip = function() {return iterable};
|
7545 | flipSequence.reverse = function () {
|
7546 | var reversedSequence = iterable.reverse.apply(this);
|
7547 | reversedSequence.flip = function() {return iterable.reverse()};
|
7548 | return reversedSequence;
|
7549 | };
|
7550 | flipSequence.has = function(key ) {return iterable.includes(key)};
|
7551 | flipSequence.includes = function(key ) {return iterable.has(key)};
|
7552 | flipSequence.cacheResult = cacheResultThrough;
|
7553 | flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
|
7554 | return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
|
7555 | }
|
7556 | flipSequence.__iteratorUncached = function(type, reverse) {
|
7557 | if (type === ITERATE_ENTRIES) {
|
7558 | var iterator = iterable.__iterator(type, reverse);
|
7559 | return new Iterator(function() {
|
7560 | var step = iterator.next();
|
7561 | if (!step.done) {
|
7562 | var k = step.value[0];
|
7563 | step.value[0] = step.value[1];
|
7564 | step.value[1] = k;
|
7565 | }
|
7566 | return step;
|
7567 | });
|
7568 | }
|
7569 | return iterable.__iterator(
|
7570 | type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
|
7571 | reverse
|
7572 | );
|
7573 | }
|
7574 | return flipSequence;
|
7575 | }
|
7576 |
|
7577 |
|
7578 | function mapFactory(iterable, mapper, context) {
|
7579 | var mappedSequence = makeSequence(iterable);
|
7580 | mappedSequence.size = iterable.size;
|
7581 | mappedSequence.has = function(key ) {return iterable.has(key)};
|
7582 | mappedSequence.get = function(key, notSetValue) {
|
7583 | var v = iterable.get(key, NOT_SET);
|
7584 | return v === NOT_SET ?
|
7585 | notSetValue :
|
7586 | mapper.call(context, v, key, iterable);
|
7587 | };
|
7588 | mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
|
7589 | return iterable.__iterate(
|
7590 | function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
|
7591 | reverse
|
7592 | );
|
7593 | }
|
7594 | mappedSequence.__iteratorUncached = function (type, reverse) {
|
7595 | var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
|
7596 | return new Iterator(function() {
|
7597 | var step = iterator.next();
|
7598 | if (step.done) {
|
7599 | return step;
|
7600 | }
|
7601 | var entry = step.value;
|
7602 | var key = entry[0];
|
7603 | return iteratorValue(
|
7604 | type,
|
7605 | key,
|
7606 | mapper.call(context, entry[1], key, iterable),
|
7607 | step
|
7608 | );
|
7609 | });
|
7610 | }
|
7611 | return mappedSequence;
|
7612 | }
|
7613 |
|
7614 |
|
7615 | function reverseFactory(iterable, useKeys) {
|
7616 | var reversedSequence = makeSequence(iterable);
|
7617 | reversedSequence._iter = iterable;
|
7618 | reversedSequence.size = iterable.size;
|
7619 | reversedSequence.reverse = function() {return iterable};
|
7620 | if (iterable.flip) {
|
7621 | reversedSequence.flip = function () {
|
7622 | var flipSequence = flipFactory(iterable);
|
7623 | flipSequence.reverse = function() {return iterable.flip()};
|
7624 | return flipSequence;
|
7625 | };
|
7626 | }
|
7627 | reversedSequence.get = function(key, notSetValue)
|
7628 | {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
|
7629 | reversedSequence.has = function(key )
|
7630 | {return iterable.has(useKeys ? key : -1 - key)};
|
7631 | reversedSequence.includes = function(value ) {return iterable.includes(value)};
|
7632 | reversedSequence.cacheResult = cacheResultThrough;
|
7633 | reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
|
7634 | return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
|
7635 | };
|
7636 | reversedSequence.__iterator =
|
7637 | function(type, reverse) {return iterable.__iterator(type, !reverse)};
|
7638 | return reversedSequence;
|
7639 | }
|
7640 |
|
7641 |
|
7642 | function filterFactory(iterable, predicate, context, useKeys) {
|
7643 | var filterSequence = makeSequence(iterable);
|
7644 | if (useKeys) {
|
7645 | filterSequence.has = function(key ) {
|
7646 | var v = iterable.get(key, NOT_SET);
|
7647 | return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
|
7648 | };
|
7649 | filterSequence.get = function(key, notSetValue) {
|
7650 | var v = iterable.get(key, NOT_SET);
|
7651 | return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
|
7652 | v : notSetValue;
|
7653 | };
|
7654 | }
|
7655 | filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
|
7656 | var iterations = 0;
|
7657 | iterable.__iterate(function(v, k, c) {
|
7658 | if (predicate.call(context, v, k, c)) {
|
7659 | iterations++;
|
7660 | return fn(v, useKeys ? k : iterations - 1, this$0);
|
7661 | }
|
7662 | }, reverse);
|
7663 | return iterations;
|
7664 | };
|
7665 | filterSequence.__iteratorUncached = function (type, reverse) {
|
7666 | var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
|
7667 | var iterations = 0;
|
7668 | return new Iterator(function() {
|
7669 | while (true) {
|
7670 | var step = iterator.next();
|
7671 | if (step.done) {
|
7672 | return step;
|
7673 | }
|
7674 | var entry = step.value;
|
7675 | var key = entry[0];
|
7676 | var value = entry[1];
|
7677 | if (predicate.call(context, value, key, iterable)) {
|
7678 | return iteratorValue(type, useKeys ? key : iterations++, value, step);
|
7679 | }
|
7680 | }
|
7681 | });
|
7682 | }
|
7683 | return filterSequence;
|
7684 | }
|
7685 |
|
7686 |
|
7687 | function countByFactory(iterable, grouper, context) {
|
7688 | var groups = Map().asMutable();
|
7689 | iterable.__iterate(function(v, k) {
|
7690 | groups.update(
|
7691 | grouper.call(context, v, k, iterable),
|
7692 | 0,
|
7693 | function(a ) {return a + 1}
|
7694 | );
|
7695 | });
|
7696 | return groups.asImmutable();
|
7697 | }
|
7698 |
|
7699 |
|
7700 | function groupByFactory(iterable, grouper, context) {
|
7701 | var isKeyedIter = isKeyed(iterable);
|
7702 | var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
|
7703 | iterable.__iterate(function(v, k) {
|
7704 | groups.update(
|
7705 | grouper.call(context, v, k, iterable),
|
7706 | function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
|
7707 | );
|
7708 | });
|
7709 | var coerce = iterableClass(iterable);
|
7710 | return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
|
7711 | }
|
7712 |
|
7713 |
|
7714 | function sliceFactory(iterable, begin, end, useKeys) {
|
7715 | var originalSize = iterable.size;
|
7716 |
|
7717 |
|
7718 |
|
7719 | if (begin !== undefined) {
|
7720 | begin = begin | 0;
|
7721 | }
|
7722 | if (end !== undefined) {
|
7723 | if (end === Infinity) {
|
7724 | end = originalSize;
|
7725 | } else {
|
7726 | end = end | 0;
|
7727 | }
|
7728 | }
|
7729 |
|
7730 | if (wholeSlice(begin, end, originalSize)) {
|
7731 | return iterable;
|
7732 | }
|
7733 |
|
7734 | var resolvedBegin = resolveBegin(begin, originalSize);
|
7735 | var resolvedEnd = resolveEnd(end, originalSize);
|
7736 |
|
7737 |
|
7738 |
|
7739 |
|
7740 | if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
|
7741 | return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
|
7742 | }
|
7743 |
|
7744 |
|
7745 |
|
7746 |
|
7747 |
|
7748 | var resolvedSize = resolvedEnd - resolvedBegin;
|
7749 | var sliceSize;
|
7750 | if (resolvedSize === resolvedSize) {
|
7751 | sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
|
7752 | }
|
7753 |
|
7754 | var sliceSeq = makeSequence(iterable);
|
7755 |
|
7756 |
|
7757 |
|
7758 | sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
|
7759 |
|
7760 | if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
|
7761 | sliceSeq.get = function (index, notSetValue) {
|
7762 | index = wrapIndex(this, index);
|
7763 | return index >= 0 && index < sliceSize ?
|
7764 | iterable.get(index + resolvedBegin, notSetValue) :
|
7765 | notSetValue;
|
7766 | }
|
7767 | }
|
7768 |
|
7769 | sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
|
7770 | if (sliceSize === 0) {
|
7771 | return 0;
|
7772 | }
|
7773 | if (reverse) {
|
7774 | return this.cacheResult().__iterate(fn, reverse);
|
7775 | }
|
7776 | var skipped = 0;
|
7777 | var isSkipping = true;
|
7778 | var iterations = 0;
|
7779 | iterable.__iterate(function(v, k) {
|
7780 | if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
|
7781 | iterations++;
|
7782 | return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
|
7783 | iterations !== sliceSize;
|
7784 | }
|
7785 | });
|
7786 | return iterations;
|
7787 | };
|
7788 |
|
7789 | sliceSeq.__iteratorUncached = function(type, reverse) {
|
7790 | if (sliceSize !== 0 && reverse) {
|
7791 | return this.cacheResult().__iterator(type, reverse);
|
7792 | }
|
7793 | // Don't bother instantiating parent iterator if taking 0.
|
7794 | var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
|
7795 | var skipped = 0;
|
7796 | var iterations = 0;
|
7797 | return new Iterator(function() {
|
7798 | while (skipped++ < resolvedBegin) {
|
7799 | iterator.next();
|
7800 | }
|
7801 | if (++iterations > sliceSize) {
|
7802 | return iteratorDone();
|
7803 | }
|
7804 | var step = iterator.next();
|
7805 | if (useKeys || type === ITERATE_VALUES) {
|
7806 | return step;
|
7807 | } else if (type === ITERATE_KEYS) {
|
7808 | return iteratorValue(type, iterations - 1, undefined, step);
|
7809 | } else {
|
7810 | return iteratorValue(type, iterations - 1, step.value[1], step);
|
7811 | }
|
7812 | });
|
7813 | }
|
7814 |
|
7815 | return sliceSeq;
|
7816 | }
|
7817 |
|
7818 |
|
7819 | function takeWhileFactory(iterable, predicate, context) {
|
7820 | var takeSequence = makeSequence(iterable);
|
7821 | takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
|
7822 | if (reverse) {
|
7823 | return this.cacheResult().__iterate(fn, reverse);
|
7824 | }
|
7825 | var iterations = 0;
|
7826 | iterable.__iterate(function(v, k, c)
|
7827 | {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
|
7828 | );
|
7829 | return iterations;
|
7830 | };
|
7831 | takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
|
7832 | if (reverse) {
|
7833 | return this.cacheResult().__iterator(type, reverse);
|
7834 | }
|
7835 | var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
|
7836 | var iterating = true;
|
7837 | return new Iterator(function() {
|
7838 | if (!iterating) {
|
7839 | return iteratorDone();
|
7840 | }
|
7841 | var step = iterator.next();
|
7842 | if (step.done) {
|
7843 | return step;
|
7844 | }
|
7845 | var entry = step.value;
|
7846 | var k = entry[0];
|
7847 | var v = entry[1];
|
7848 | if (!predicate.call(context, v, k, this$0)) {
|
7849 | iterating = false;
|
7850 | return iteratorDone();
|
7851 | }
|
7852 | return type === ITERATE_ENTRIES ? step :
|
7853 | iteratorValue(type, k, v, step);
|
7854 | });
|
7855 | };
|
7856 | return takeSequence;
|
7857 | }
|
7858 |
|
7859 |
|
7860 | function skipWhileFactory(iterable, predicate, context, useKeys) {
|
7861 | var skipSequence = makeSequence(iterable);
|
7862 | skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
|
7863 | if (reverse) {
|
7864 | return this.cacheResult().__iterate(fn, reverse);
|
7865 | }
|
7866 | var isSkipping = true;
|
7867 | var iterations = 0;
|
7868 | iterable.__iterate(function(v, k, c) {
|
7869 | if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
|
7870 | iterations++;
|
7871 | return fn(v, useKeys ? k : iterations - 1, this$0);
|
7872 | }
|
7873 | });
|
7874 | return iterations;
|
7875 | };
|
7876 | skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
|
7877 | if (reverse) {
|
7878 | return this.cacheResult().__iterator(type, reverse);
|
7879 | }
|
7880 | var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
|
7881 | var skipping = true;
|
7882 | var iterations = 0;
|
7883 | return new Iterator(function() {
|
7884 | var step, k, v;
|
7885 | do {
|
7886 | step = iterator.next();
|
7887 | if (step.done) {
|
7888 | if (useKeys || type === ITERATE_VALUES) {
|
7889 | return step;
|
7890 | } else if (type === ITERATE_KEYS) {
|
7891 | return iteratorValue(type, iterations++, undefined, step);
|
7892 | } else {
|
7893 | return iteratorValue(type, iterations++, step.value[1], step);
|
7894 | }
|
7895 | }
|
7896 | var entry = step.value;
|
7897 | k = entry[0];
|
7898 | v = entry[1];
|
7899 | skipping && (skipping = predicate.call(context, v, k, this$0));
|
7900 | } while (skipping);
|
7901 | return type === ITERATE_ENTRIES ? step :
|
7902 | iteratorValue(type, k, v, step);
|
7903 | });
|
7904 | };
|
7905 | return skipSequence;
|
7906 | }
|
7907 |
|
7908 |
|
7909 | function concatFactory(iterable, values) {
|
7910 | var isKeyedIterable = isKeyed(iterable);
|
7911 | var iters = [iterable].concat(values).map(function(v ) {
|
7912 | if (!isIterable(v)) {
|
7913 | v = isKeyedIterable ?
|
7914 | keyedSeqFromValue(v) :
|
7915 | indexedSeqFromValue(Array.isArray(v) ? v : [v]);
|
7916 | } else if (isKeyedIterable) {
|
7917 | v = KeyedIterable(v);
|
7918 | }
|
7919 | return v;
|
7920 | }).filter(function(v ) {return v.size !== 0});
|
7921 |
|
7922 | if (iters.length === 0) {
|
7923 | return iterable;
|
7924 | }
|
7925 |
|
7926 | if (iters.length === 1) {
|
7927 | var singleton = iters[0];
|
7928 | if (singleton === iterable ||
|
7929 | isKeyedIterable && isKeyed(singleton) ||
|
7930 | isIndexed(iterable) && isIndexed(singleton)) {
|
7931 | return singleton;
|
7932 | }
|
7933 | }
|
7934 |
|
7935 | var concatSeq = new ArraySeq(iters);
|
7936 | if (isKeyedIterable) {
|
7937 | concatSeq = concatSeq.toKeyedSeq();
|
7938 | } else if (!isIndexed(iterable)) {
|
7939 | concatSeq = concatSeq.toSetSeq();
|
7940 | }
|
7941 | concatSeq = concatSeq.flatten(true);
|
7942 | concatSeq.size = iters.reduce(
|
7943 | function(sum, seq) {
|
7944 | if (sum !== undefined) {
|
7945 | var size = seq.size;
|
7946 | if (size !== undefined) {
|
7947 | return sum + size;
|
7948 | }
|
7949 | }
|
7950 | },
|
7951 | 0
|
7952 | );
|
7953 | return concatSeq;
|
7954 | }
|
7955 |
|
7956 |
|
7957 | function flattenFactory(iterable, depth, useKeys) {
|
7958 | var flatSequence = makeSequence(iterable);
|
7959 | flatSequence.__iterateUncached = function(fn, reverse) {
|
7960 | var iterations = 0;
|
7961 | var stopped = false;
|
7962 | function flatDeep(iter, currentDepth) {var this$0 = this;
|
7963 | iter.__iterate(function(v, k) {
|
7964 | if ((!depth || currentDepth < depth) && isIterable(v)) {
|
7965 | flatDeep(v, currentDepth + 1);
|
7966 | } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
|
7967 | stopped = true;
|
7968 | }
|
7969 | return !stopped;
|
7970 | }, reverse);
|
7971 | }
|
7972 | flatDeep(iterable, 0);
|
7973 | return iterations;
|
7974 | }
|
7975 | flatSequence.__iteratorUncached = function(type, reverse) {
|
7976 | var iterator = iterable.__iterator(type, reverse);
|
7977 | var stack = [];
|
7978 | var iterations = 0;
|
7979 | return new Iterator(function() {
|
7980 | while (iterator) {
|
7981 | var step = iterator.next();
|
7982 | if (step.done !== false) {
|
7983 | iterator = stack.pop();
|
7984 | continue;
|
7985 | }
|
7986 | var v = step.value;
|
7987 | if (type === ITERATE_ENTRIES) {
|
7988 | v = v[1];
|
7989 | }
|
7990 | if ((!depth || stack.length < depth) && isIterable(v)) {
|
7991 | stack.push(iterator);
|
7992 | iterator = v.__iterator(type, reverse);
|
7993 | } else {
|
7994 | return useKeys ? step : iteratorValue(type, iterations++, v, step);
|
7995 | }
|
7996 | }
|
7997 | return iteratorDone();
|
7998 | });
|
7999 | }
|
8000 | return flatSequence;
|
8001 | }
|
8002 |
|
8003 |
|
8004 | function flatMapFactory(iterable, mapper, context) {
|
8005 | var coerce = iterableClass(iterable);
|
8006 | return iterable.toSeq().map(
|
8007 | function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
|
8008 | ).flatten(true);
|
8009 | }
|
8010 |
|
8011 |
|
8012 | function interposeFactory(iterable, separator) {
|
8013 | var interposedSequence = makeSequence(iterable);
|
8014 | interposedSequence.size = iterable.size && iterable.size * 2 -1;
|
8015 | interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
|
8016 | var iterations = 0;
|
8017 | iterable.__iterate(function(v, k)
|
8018 | {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
|
8019 | fn(v, iterations++, this$0) !== false},
|
8020 | reverse
|
8021 | );
|
8022 | return iterations;
|
8023 | };
|
8024 | interposedSequence.__iteratorUncached = function(type, reverse) {
|
8025 | var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
|
8026 | var iterations = 0;
|
8027 | var step;
|
8028 | return new Iterator(function() {
|
8029 | if (!step || iterations % 2) {
|
8030 | step = iterator.next();
|
8031 | if (step.done) {
|
8032 | return step;
|
8033 | }
|
8034 | }
|
8035 | return iterations % 2 ?
|
8036 | iteratorValue(type, iterations++, separator) :
|
8037 | iteratorValue(type, iterations++, step.value, step);
|
8038 | });
|
8039 | };
|
8040 | return interposedSequence;
|
8041 | }
|
8042 |
|
8043 |
|
8044 | function sortFactory(iterable, comparator, mapper) {
|
8045 | if (!comparator) {
|
8046 | comparator = defaultComparator;
|
8047 | }
|
8048 | var isKeyedIterable = isKeyed(iterable);
|
8049 | var index = 0;
|
8050 | var entries = iterable.toSeq().map(
|
8051 | function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
|
8052 | ).toArray();
|
8053 | entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
|
8054 | isKeyedIterable ?
|
8055 | function(v, i) { entries[i].length = 2; } :
|
8056 | function(v, i) { entries[i] = v[1]; }
|
8057 | );
|
8058 | return isKeyedIterable ? KeyedSeq(entries) :
|
8059 | isIndexed(iterable) ? IndexedSeq(entries) :
|
8060 | SetSeq(entries);
|
8061 | }
|
8062 |
|
8063 |
|
8064 | function maxFactory(iterable, comparator, mapper) {
|
8065 | if (!comparator) {
|
8066 | comparator = defaultComparator;
|
8067 | }
|
8068 | if (mapper) {
|
8069 | var entry = iterable.toSeq()
|
8070 | .map(function(v, k) {return [v, mapper(v, k, iterable)]})
|
8071 | .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
|
8072 | return entry && entry[0];
|
8073 | } else {
|
8074 | return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
|
8075 | }
|
8076 | }
|
8077 |
|
8078 | function maxCompare(comparator, a, b) {
|
8079 | var comp = comparator(b, a);
|
8080 | // b is considered the new max if the comparator declares them equal, but
|
8081 | // they are not equal and b is in fact a nullish value.
|
8082 | return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
|
8083 | }
|
8084 |
|
8085 |
|
8086 | function zipWithFactory(keyIter, zipper, iters) {
|
8087 | var zipSequence = makeSequence(keyIter);
|
8088 | zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
|
8089 | // Note: this a generic base implementation of __iterate in terms of
|
8090 | // __iterator which may be more generically useful in the future.
|
8091 | zipSequence.__iterate = function(fn, reverse) {
|
8092 | /* generic:
|
8093 | var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
|
8094 | var step;
|
8095 | var iterations = 0;
|
8096 | while (!(step = iterator.next()).done) {
|
8097 | iterations++;
|
8098 | if (fn(step.value[1], step.value[0], this) === false) {
|
8099 | break;
|
8100 | }
|
8101 | }
|
8102 | return iterations;
|
8103 | */
|
8104 | // indexed:
|
8105 | var iterator = this.__iterator(ITERATE_VALUES, reverse);
|
8106 | var step;
|
8107 | var iterations = 0;
|
8108 | while (!(step = iterator.next()).done) {
|
8109 | if (fn(step.value, iterations++, this) === false) {
|
8110 | break;
|
8111 | }
|
8112 | }
|
8113 | return iterations;
|
8114 | };
|
8115 | zipSequence.__iteratorUncached = function(type, reverse) {
|
8116 | var iterators = iters.map(function(i )
|
8117 | {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
|
8118 | );
|
8119 | var iterations = 0;
|
8120 | var isDone = false;
|
8121 | return new Iterator(function() {
|
8122 | var steps;
|
8123 | if (!isDone) {
|
8124 | steps = iterators.map(function(i ) {return i.next()});
|
8125 | isDone = steps.some(function(s ) {return s.done});
|
8126 | }
|
8127 | if (isDone) {
|
8128 | return iteratorDone();
|
8129 | }
|
8130 | return iteratorValue(
|
8131 | type,
|
8132 | iterations++,
|
8133 | zipper.apply(null, steps.map(function(s ) {return s.value}))
|
8134 | );
|
8135 | });
|
8136 | };
|
8137 | return zipSequence
|
8138 | }
|
8139 |
|
8140 |
|
8141 | // #pragma Helper Functions
|
8142 |
|
8143 | function reify(iter, seq) {
|
8144 | return isSeq(iter) ? seq : iter.constructor(seq);
|
8145 | }
|
8146 |
|
8147 | function validateEntry(entry) {
|
8148 | if (entry !== Object(entry)) {
|
8149 | throw new TypeError('Expected [K, V] tuple: ' + entry);
|
8150 | }
|
8151 | }
|
8152 |
|
8153 | function resolveSize(iter) {
|
8154 | assertNotInfinite(iter.size);
|
8155 | return ensureSize(iter);
|
8156 | }
|
8157 |
|
8158 | function iterableClass(iterable) {
|
8159 | return isKeyed(iterable) ? KeyedIterable :
|
8160 | isIndexed(iterable) ? IndexedIterable :
|
8161 | SetIterable;
|
8162 | }
|
8163 |
|
8164 | function makeSequence(iterable) {
|
8165 | return Object.create(
|
8166 | (
|
8167 | isKeyed(iterable) ? KeyedSeq :
|
8168 | isIndexed(iterable) ? IndexedSeq :
|
8169 | SetSeq
|
8170 | ).prototype
|
8171 | );
|
8172 | }
|
8173 |
|
8174 | function cacheResultThrough() {
|
8175 | if (this._iter.cacheResult) {
|
8176 | this._iter.cacheResult();
|
8177 | this.size = this._iter.size;
|
8178 | return this;
|
8179 | } else {
|
8180 | return Seq.prototype.cacheResult.call(this);
|
8181 | }
|
8182 | }
|
8183 |
|
8184 | function defaultComparator(a, b) {
|
8185 | return a > b ? 1 : a < b ? -1 : 0;
|
8186 | }
|
8187 |
|
8188 | function forceIterator(keyPath) {
|
8189 | var iter = getIterator(keyPath);
|
8190 | if (!iter) {
|
8191 | // Array might not be iterable in this environment, so we need a fallback
|
8192 | // to our wrapped type.
|
8193 | if (!isArrayLike(keyPath)) {
|
8194 | throw new TypeError('Expected iterable or array-like: ' + keyPath);
|
8195 | }
|
8196 | iter = getIterator(Iterable(keyPath));
|
8197 | }
|
8198 | return iter;
|
8199 | }
|
8200 |
|
8201 | createClass(Record, KeyedCollection);
|
8202 |
|
8203 | function Record(defaultValues, name) {
|
8204 | var hasInitialized;
|
8205 |
|
8206 | var RecordType = function Record(values) {
|
8207 | if (values instanceof RecordType) {
|
8208 | return values;
|
8209 | }
|
8210 | if (!(this instanceof RecordType)) {
|
8211 | return new RecordType(values);
|
8212 | }
|
8213 | if (!hasInitialized) {
|
8214 | hasInitialized = true;
|
8215 | var keys = Object.keys(defaultValues);
|
8216 | setProps(RecordTypePrototype, keys);
|
8217 | RecordTypePrototype.size = keys.length;
|
8218 | RecordTypePrototype._name = name;
|
8219 | RecordTypePrototype._keys = keys;
|
8220 | RecordTypePrototype._defaultValues = defaultValues;
|
8221 | }
|
8222 | this._map = Map(values);
|
8223 | };
|
8224 |
|
8225 | var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
|
8226 | RecordTypePrototype.constructor = RecordType;
|
8227 |
|
8228 | return RecordType;
|
8229 | }
|
8230 |
|
8231 | Record.prototype.toString = function() {
|
8232 | return this.__toString(recordName(this) + ' {', '}');
|
8233 | };
|
8234 |
|
8235 | // @pragma Access
|
8236 |
|
8237 | Record.prototype.has = function(k) {
|
8238 | return this._defaultValues.hasOwnProperty(k);
|
8239 | };
|
8240 |
|
8241 | Record.prototype.get = function(k, notSetValue) {
|
8242 | if (!this.has(k)) {
|
8243 | return notSetValue;
|
8244 | }
|
8245 | var defaultVal = this._defaultValues[k];
|
8246 | return this._map ? this._map.get(k, defaultVal) : defaultVal;
|
8247 | };
|
8248 |
|
8249 | // @pragma Modification
|
8250 |
|
8251 | Record.prototype.clear = function() {
|
8252 | if (this.__ownerID) {
|
8253 | this._map && this._map.clear();
|
8254 | return this;
|
8255 | }
|
8256 | var RecordType = this.constructor;
|
8257 | return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
|
8258 | };
|
8259 |
|
8260 | Record.prototype.set = function(k, v) {
|
8261 | if (!this.has(k)) {
|
8262 | throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
|
8263 | }
|
8264 | if (this._map && !this._map.has(k)) {
|
8265 | var defaultVal = this._defaultValues[k];
|
8266 | if (v === defaultVal) {
|
8267 | return this;
|
8268 | }
|
8269 | }
|
8270 | var newMap = this._map && this._map.set(k, v);
|
8271 | if (this.__ownerID || newMap === this._map) {
|
8272 | return this;
|
8273 | }
|
8274 | return makeRecord(this, newMap);
|
8275 | };
|
8276 |
|
8277 | Record.prototype.remove = function(k) {
|
8278 | if (!this.has(k)) {
|
8279 | return this;
|
8280 | }
|
8281 | var newMap = this._map && this._map.remove(k);
|
8282 | if (this.__ownerID || newMap === this._map) {
|
8283 | return this;
|
8284 | }
|
8285 | return makeRecord(this, newMap);
|
8286 | };
|
8287 |
|
8288 | Record.prototype.wasAltered = function() {
|
8289 | return this._map.wasAltered();
|
8290 | };
|
8291 |
|
8292 | Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
|
8293 | return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
|
8294 | };
|
8295 |
|
8296 | Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
|
8297 | return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
|
8298 | };
|
8299 |
|
8300 | Record.prototype.__ensureOwner = function(ownerID) {
|
8301 | if (ownerID === this.__ownerID) {
|
8302 | return this;
|
8303 | }
|
8304 | var newMap = this._map && this._map.__ensureOwner(ownerID);
|
8305 | if (!ownerID) {
|
8306 | this.__ownerID = ownerID;
|
8307 | this._map = newMap;
|
8308 | return this;
|
8309 | }
|
8310 | return makeRecord(this, newMap, ownerID);
|
8311 | };
|
8312 |
|
8313 |
|
8314 | var RecordPrototype = Record.prototype;
|
8315 | RecordPrototype[DELETE] = RecordPrototype.remove;
|
8316 | RecordPrototype.deleteIn =
|
8317 | RecordPrototype.removeIn = MapPrototype.removeIn;
|
8318 | RecordPrototype.merge = MapPrototype.merge;
|
8319 | RecordPrototype.mergeWith = MapPrototype.mergeWith;
|
8320 | RecordPrototype.mergeIn = MapPrototype.mergeIn;
|
8321 | RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
|
8322 | RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
|
8323 | RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
|
8324 | RecordPrototype.setIn = MapPrototype.setIn;
|
8325 | RecordPrototype.update = MapPrototype.update;
|
8326 | RecordPrototype.updateIn = MapPrototype.updateIn;
|
8327 | RecordPrototype.withMutations = MapPrototype.withMutations;
|
8328 | RecordPrototype.asMutable = MapPrototype.asMutable;
|
8329 | RecordPrototype.asImmutable = MapPrototype.asImmutable;
|
8330 |
|
8331 |
|
8332 | function makeRecord(likeRecord, map, ownerID) {
|
8333 | var record = Object.create(Object.getPrototypeOf(likeRecord));
|
8334 | record._map = map;
|
8335 | record.__ownerID = ownerID;
|
8336 | return record;
|
8337 | }
|
8338 |
|
8339 | function recordName(record) {
|
8340 | return record._name || record.constructor.name || 'Record';
|
8341 | }
|
8342 |
|
8343 | function setProps(prototype, names) {
|
8344 | try {
|
8345 | names.forEach(setProp.bind(undefined, prototype));
|
8346 | } catch (error) {
|
8347 | // Object.defineProperty failed. Probably IE8.
|
8348 | }
|
8349 | }
|
8350 |
|
8351 | function setProp(prototype, name) {
|
8352 | Object.defineProperty(prototype, name, {
|
8353 | get: function() {
|
8354 | return this.get(name);
|
8355 | },
|
8356 | set: function(value) {
|
8357 | invariant(this.__ownerID, 'Cannot set on an immutable record.');
|
8358 | this.set(name, value);
|
8359 | }
|
8360 | });
|
8361 | }
|
8362 |
|
8363 | createClass(Set, SetCollection);
|
8364 |
|
8365 | // @pragma Construction
|
8366 |
|
8367 | function Set(value) {
|
8368 | return value === null || value === undefined ? emptySet() :
|
8369 | isSet(value) && !isOrdered(value) ? value :
|
8370 | emptySet().withMutations(function(set ) {
|
8371 | var iter = SetIterable(value);
|
8372 | assertNotInfinite(iter.size);
|
8373 | iter.forEach(function(v ) {return set.add(v)});
|
8374 | });
|
8375 | }
|
8376 |
|
8377 | Set.of = function(/*...values*/) {
|
8378 | return this(arguments);
|
8379 | };
|
8380 |
|
8381 | Set.fromKeys = function(value) {
|
8382 | return this(KeyedIterable(value).keySeq());
|
8383 | };
|
8384 |
|
8385 | Set.prototype.toString = function() {
|
8386 | return this.__toString('Set {', '}');
|
8387 | };
|
8388 |
|
8389 | // @pragma Access
|
8390 |
|
8391 | Set.prototype.has = function(value) {
|
8392 | return this._map.has(value);
|
8393 | };
|
8394 |
|
8395 | // @pragma Modification
|
8396 |
|
8397 | Set.prototype.add = function(value) {
|
8398 | return updateSet(this, this._map.set(value, true));
|
8399 | };
|
8400 |
|
8401 | Set.prototype.remove = function(value) {
|
8402 | return updateSet(this, this._map.remove(value));
|
8403 | };
|
8404 |
|
8405 | Set.prototype.clear = function() {
|
8406 | return updateSet(this, this._map.clear());
|
8407 | };
|
8408 |
|
8409 | // @pragma Composition
|
8410 |
|
8411 | Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
|
8412 | iters = iters.filter(function(x ) {return x.size !== 0});
|
8413 | if (iters.length === 0) {
|
8414 | return this;
|
8415 | }
|
8416 | if (this.size === 0 && !this.__ownerID && iters.length === 1) {
|
8417 | return this.constructor(iters[0]);
|
8418 | }
|
8419 | return this.withMutations(function(set ) {
|
8420 | for (var ii = 0; ii < iters.length; ii++) {
|
8421 | SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
|
8422 | }
|
8423 | });
|
8424 | };
|
8425 |
|
8426 | Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
|
8427 | if (iters.length === 0) {
|
8428 | return this;
|
8429 | }
|
8430 | iters = iters.map(function(iter ) {return SetIterable(iter)});
|
8431 | var originalSet = this;
|
8432 | return this.withMutations(function(set ) {
|
8433 | originalSet.forEach(function(value ) {
|
8434 | if (!iters.every(function(iter ) {return iter.includes(value)})) {
|
8435 | set.remove(value);
|
8436 | }
|
8437 | });
|
8438 | });
|
8439 | };
|
8440 |
|
8441 | Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
|
8442 | if (iters.length === 0) {
|
8443 | return this;
|
8444 | }
|
8445 | iters = iters.map(function(iter ) {return SetIterable(iter)});
|
8446 | var originalSet = this;
|
8447 | return this.withMutations(function(set ) {
|
8448 | originalSet.forEach(function(value ) {
|
8449 | if (iters.some(function(iter ) {return iter.includes(value)})) {
|
8450 | set.remove(value);
|
8451 | }
|
8452 | });
|
8453 | });
|
8454 | };
|
8455 |
|
8456 | Set.prototype.merge = function() {
|
8457 | return this.union.apply(this, arguments);
|
8458 | };
|
8459 |
|
8460 | Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
|
8461 | return this.union.apply(this, iters);
|
8462 | };
|
8463 |
|
8464 | Set.prototype.sort = function(comparator) {
|
8465 | // Late binding
|
8466 | return OrderedSet(sortFactory(this, comparator));
|
8467 | };
|
8468 |
|
8469 | Set.prototype.sortBy = function(mapper, comparator) {
|
8470 | // Late binding
|
8471 | return OrderedSet(sortFactory(this, comparator, mapper));
|
8472 | };
|
8473 |
|
8474 | Set.prototype.wasAltered = function() {
|
8475 | return this._map.wasAltered();
|
8476 | };
|
8477 |
|
8478 | Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
|
8479 | return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
|
8480 | };
|
8481 |
|
8482 | Set.prototype.__iterator = function(type, reverse) {
|
8483 | return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
|
8484 | };
|
8485 |
|
8486 | Set.prototype.__ensureOwner = function(ownerID) {
|
8487 | if (ownerID === this.__ownerID) {
|
8488 | return this;
|
8489 | }
|
8490 | var newMap = this._map.__ensureOwner(ownerID);
|
8491 | if (!ownerID) {
|
8492 | this.__ownerID = ownerID;
|
8493 | this._map = newMap;
|
8494 | return this;
|
8495 | }
|
8496 | return this.__make(newMap, ownerID);
|
8497 | };
|
8498 |
|
8499 |
|
8500 | function isSet(maybeSet) {
|
8501 | return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
|
8502 | }
|
8503 |
|
8504 | Set.isSet = isSet;
|
8505 |
|
8506 | var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
|
8507 |
|
8508 | var SetPrototype = Set.prototype;
|
8509 | SetPrototype[IS_SET_SENTINEL] = true;
|
8510 | SetPrototype[DELETE] = SetPrototype.remove;
|
8511 | SetPrototype.mergeDeep = SetPrototype.merge;
|
8512 | SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
|
8513 | SetPrototype.withMutations = MapPrototype.withMutations;
|
8514 | SetPrototype.asMutable = MapPrototype.asMutable;
|
8515 | SetPrototype.asImmutable = MapPrototype.asImmutable;
|
8516 |
|
8517 | SetPrototype.__empty = emptySet;
|
8518 | SetPrototype.__make = makeSet;
|
8519 |
|
8520 | function updateSet(set, newMap) {
|
8521 | if (set.__ownerID) {
|
8522 | set.size = newMap.size;
|
8523 | set._map = newMap;
|
8524 | return set;
|
8525 | }
|
8526 | return newMap === set._map ? set :
|
8527 | newMap.size === 0 ? set.__empty() :
|
8528 | set.__make(newMap);
|
8529 | }
|
8530 |
|
8531 | function makeSet(map, ownerID) {
|
8532 | var set = Object.create(SetPrototype);
|
8533 | set.size = map ? map.size : 0;
|
8534 | set._map = map;
|
8535 | set.__ownerID = ownerID;
|
8536 | return set;
|
8537 | }
|
8538 |
|
8539 | var EMPTY_SET;
|
8540 | function emptySet() {
|
8541 | return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
|
8542 | }
|
8543 |
|
8544 | createClass(OrderedSet, Set);
|
8545 |
|
8546 | // @pragma Construction
|
8547 |
|
8548 | function OrderedSet(value) {
|
8549 | return value === null || value === undefined ? emptyOrderedSet() :
|
8550 | isOrderedSet(value) ? value :
|
8551 | emptyOrderedSet().withMutations(function(set ) {
|
8552 | var iter = SetIterable(value);
|
8553 | assertNotInfinite(iter.size);
|
8554 | iter.forEach(function(v ) {return set.add(v)});
|
8555 | });
|
8556 | }
|
8557 |
|
8558 | OrderedSet.of = function(/*...values*/) {
|
8559 | return this(arguments);
|
8560 | };
|
8561 |
|
8562 | OrderedSet.fromKeys = function(value) {
|
8563 | return this(KeyedIterable(value).keySeq());
|
8564 | };
|
8565 |
|
8566 | OrderedSet.prototype.toString = function() {
|
8567 | return this.__toString('OrderedSet {', '}');
|
8568 | };
|
8569 |
|
8570 |
|
8571 | function isOrderedSet(maybeOrderedSet) {
|
8572 | return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
|
8573 | }
|
8574 |
|
8575 | OrderedSet.isOrderedSet = isOrderedSet;
|
8576 |
|
8577 | var OrderedSetPrototype = OrderedSet.prototype;
|
8578 | OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
|
8579 |
|
8580 | OrderedSetPrototype.__empty = emptyOrderedSet;
|
8581 | OrderedSetPrototype.__make = makeOrderedSet;
|
8582 |
|
8583 | function makeOrderedSet(map, ownerID) {
|
8584 | var set = Object.create(OrderedSetPrototype);
|
8585 | set.size = map ? map.size : 0;
|
8586 | set._map = map;
|
8587 | set.__ownerID = ownerID;
|
8588 | return set;
|
8589 | }
|
8590 |
|
8591 | var EMPTY_ORDERED_SET;
|
8592 | function emptyOrderedSet() {
|
8593 | return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
|
8594 | }
|
8595 |
|
8596 | createClass(Stack, IndexedCollection);
|
8597 |
|
8598 | // @pragma Construction
|
8599 |
|
8600 | function Stack(value) {
|
8601 | return value === null || value === undefined ? emptyStack() :
|
8602 | isStack(value) ? value :
|
8603 | emptyStack().unshiftAll(value);
|
8604 | }
|
8605 |
|
8606 | Stack.of = function(/*...values*/) {
|
8607 | return this(arguments);
|
8608 | };
|
8609 |
|
8610 | Stack.prototype.toString = function() {
|
8611 | return this.__toString('Stack [', ']');
|
8612 | };
|
8613 |
|
8614 | // @pragma Access
|
8615 |
|
8616 | Stack.prototype.get = function(index, notSetValue) {
|
8617 | var head = this._head;
|
8618 | index = wrapIndex(this, index);
|
8619 | while (head && index--) {
|
8620 | head = head.next;
|
8621 | }
|
8622 | return head ? head.value : notSetValue;
|
8623 | };
|
8624 |
|
8625 | Stack.prototype.peek = function() {
|
8626 | return this._head && this._head.value;
|
8627 | };
|
8628 |
|
8629 | // @pragma Modification
|
8630 |
|
8631 | Stack.prototype.push = function(/*...values*/) {
|
8632 | if (arguments.length === 0) {
|
8633 | return this;
|
8634 | }
|
8635 | var newSize = this.size + arguments.length;
|
8636 | var head = this._head;
|
8637 | for (var ii = arguments.length - 1; ii >= 0; ii--) {
|
8638 | head = {
|
8639 | value: arguments[ii],
|
8640 | next: head
|
8641 | };
|
8642 | }
|
8643 | if (this.__ownerID) {
|
8644 | this.size = newSize;
|
8645 | this._head = head;
|
8646 | this.__hash = undefined;
|
8647 | this.__altered = true;
|
8648 | return this;
|
8649 | }
|
8650 | return makeStack(newSize, head);
|
8651 | };
|
8652 |
|
8653 | Stack.prototype.pushAll = function(iter) {
|
8654 | iter = IndexedIterable(iter);
|
8655 | if (iter.size === 0) {
|
8656 | return this;
|
8657 | }
|
8658 | assertNotInfinite(iter.size);
|
8659 | var newSize = this.size;
|
8660 | var head = this._head;
|
8661 | iter.reverse().forEach(function(value ) {
|
8662 | newSize++;
|
8663 | head = {
|
8664 | value: value,
|
8665 | next: head
|
8666 | };
|
8667 | });
|
8668 | if (this.__ownerID) {
|
8669 | this.size = newSize;
|
8670 | this._head = head;
|
8671 | this.__hash = undefined;
|
8672 | this.__altered = true;
|
8673 | return this;
|
8674 | }
|
8675 | return makeStack(newSize, head);
|
8676 | };
|
8677 |
|
8678 | Stack.prototype.pop = function() {
|
8679 | return this.slice(1);
|
8680 | };
|
8681 |
|
8682 | Stack.prototype.unshift = function(/*...values*/) {
|
8683 | return this.push.apply(this, arguments);
|
8684 | };
|
8685 |
|
8686 | Stack.prototype.unshiftAll = function(iter) {
|
8687 | return this.pushAll(iter);
|
8688 | };
|
8689 |
|
8690 | Stack.prototype.shift = function() {
|
8691 | return this.pop.apply(this, arguments);
|
8692 | };
|
8693 |
|
8694 | Stack.prototype.clear = function() {
|
8695 | if (this.size === 0) {
|
8696 | return this;
|
8697 | }
|
8698 | if (this.__ownerID) {
|
8699 | this.size = 0;
|
8700 | this._head = undefined;
|
8701 | this.__hash = undefined;
|
8702 | this.__altered = true;
|
8703 | return this;
|
8704 | }
|
8705 | return emptyStack();
|
8706 | };
|
8707 |
|
8708 | Stack.prototype.slice = function(begin, end) {
|
8709 | if (wholeSlice(begin, end, this.size)) {
|
8710 | return this;
|
8711 | }
|
8712 | var resolvedBegin = resolveBegin(begin, this.size);
|
8713 | var resolvedEnd = resolveEnd(end, this.size);
|
8714 | if (resolvedEnd !== this.size) {
|
8715 | // super.slice(begin, end);
|
8716 | return IndexedCollection.prototype.slice.call(this, begin, end);
|
8717 | }
|
8718 | var newSize = this.size - resolvedBegin;
|
8719 | var head = this._head;
|
8720 | while (resolvedBegin--) {
|
8721 | head = head.next;
|
8722 | }
|
8723 | if (this.__ownerID) {
|
8724 | this.size = newSize;
|
8725 | this._head = head;
|
8726 | this.__hash = undefined;
|
8727 | this.__altered = true;
|
8728 | return this;
|
8729 | }
|
8730 | return makeStack(newSize, head);
|
8731 | };
|
8732 |
|
8733 | // @pragma Mutability
|
8734 |
|
8735 | Stack.prototype.__ensureOwner = function(ownerID) {
|
8736 | if (ownerID === this.__ownerID) {
|
8737 | return this;
|
8738 | }
|
8739 | if (!ownerID) {
|
8740 | this.__ownerID = ownerID;
|
8741 | this.__altered = false;
|
8742 | return this;
|
8743 | }
|
8744 | return makeStack(this.size, this._head, ownerID, this.__hash);
|
8745 | };
|
8746 |
|
8747 | // @pragma Iteration
|
8748 |
|
8749 | Stack.prototype.__iterate = function(fn, reverse) {
|
8750 | if (reverse) {
|
8751 | return this.reverse().__iterate(fn);
|
8752 | }
|
8753 | var iterations = 0;
|
8754 | var node = this._head;
|
8755 | while (node) {
|
8756 | if (fn(node.value, iterations++, this) === false) {
|
8757 | break;
|
8758 | }
|
8759 | node = node.next;
|
8760 | }
|
8761 | return iterations;
|
8762 | };
|
8763 |
|
8764 | Stack.prototype.__iterator = function(type, reverse) {
|
8765 | if (reverse) {
|
8766 | return this.reverse().__iterator(type);
|
8767 | }
|
8768 | var iterations = 0;
|
8769 | var node = this._head;
|
8770 | return new Iterator(function() {
|
8771 | if (node) {
|
8772 | var value = node.value;
|
8773 | node = node.next;
|
8774 | return iteratorValue(type, iterations++, value);
|
8775 | }
|
8776 | return iteratorDone();
|
8777 | });
|
8778 | };
|
8779 |
|
8780 |
|
8781 | function isStack(maybeStack) {
|
8782 | return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
|
8783 | }
|
8784 |
|
8785 | Stack.isStack = isStack;
|
8786 |
|
8787 | var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
|
8788 |
|
8789 | var StackPrototype = Stack.prototype;
|
8790 | StackPrototype[IS_STACK_SENTINEL] = true;
|
8791 | StackPrototype.withMutations = MapPrototype.withMutations;
|
8792 | StackPrototype.asMutable = MapPrototype.asMutable;
|
8793 | StackPrototype.asImmutable = MapPrototype.asImmutable;
|
8794 | StackPrototype.wasAltered = MapPrototype.wasAltered;
|
8795 |
|
8796 |
|
8797 | function makeStack(size, head, ownerID, hash) {
|
8798 | var map = Object.create(StackPrototype);
|
8799 | map.size = size;
|
8800 | map._head = head;
|
8801 | map.__ownerID = ownerID;
|
8802 | map.__hash = hash;
|
8803 | map.__altered = false;
|
8804 | return map;
|
8805 | }
|
8806 |
|
8807 | var EMPTY_STACK;
|
8808 | function emptyStack() {
|
8809 | return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
|
8810 | }
|
8811 |
|
8812 | /**
|
8813 | * Contributes additional methods to a constructor
|
8814 | */
|
8815 | function mixin(ctor, methods) {
|
8816 | var keyCopier = function(key ) { ctor.prototype[key] = methods[key]; };
|
8817 | Object.keys(methods).forEach(keyCopier);
|
8818 | Object.getOwnPropertySymbols &&
|
8819 | Object.getOwnPropertySymbols(methods).forEach(keyCopier);
|
8820 | return ctor;
|
8821 | }
|
8822 |
|
8823 | Iterable.Iterator = Iterator;
|
8824 |
|
8825 | mixin(Iterable, {
|
8826 |
|
8827 | // ### Conversion to other types
|
8828 |
|
8829 | toArray: function() {
|
8830 | assertNotInfinite(this.size);
|
8831 | var array = new Array(this.size || 0);
|
8832 | this.valueSeq().__iterate(function(v, i) { array[i] = v; });
|
8833 | return array;
|
8834 | },
|
8835 |
|
8836 | toIndexedSeq: function() {
|
8837 | return new ToIndexedSequence(this);
|
8838 | },
|
8839 |
|
8840 | toJS: function() {
|
8841 | return this.toSeq().map(
|
8842 | function(value ) {return value && typeof value.toJS === 'function' ? value.toJS() : value}
|
8843 | ).__toJS();
|
8844 | },
|
8845 |
|
8846 | toJSON: function() {
|
8847 | return this.toSeq().map(
|
8848 | function(value ) {return value && typeof value.toJSON === 'function' ? value.toJSON() : value}
|
8849 | ).__toJS();
|
8850 | },
|
8851 |
|
8852 | toKeyedSeq: function() {
|
8853 | return new ToKeyedSequence(this, true);
|
8854 | },
|
8855 |
|
8856 | toMap: function() {
|
8857 | // Use Late Binding here to solve the circular dependency.
|
8858 | return Map(this.toKeyedSeq());
|
8859 | },
|
8860 |
|
8861 | toObject: function() {
|
8862 | assertNotInfinite(this.size);
|
8863 | var object = {};
|
8864 | this.__iterate(function(v, k) { object[k] = v; });
|
8865 | return object;
|
8866 | },
|
8867 |
|
8868 | toOrderedMap: function() {
|
8869 | // Use Late Binding here to solve the circular dependency.
|
8870 | return OrderedMap(this.toKeyedSeq());
|
8871 | },
|
8872 |
|
8873 | toOrderedSet: function() {
|
8874 | // Use Late Binding here to solve the circular dependency.
|
8875 | return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
|
8876 | },
|
8877 |
|
8878 | toSet: function() {
|
8879 | // Use Late Binding here to solve the circular dependency.
|
8880 | return Set(isKeyed(this) ? this.valueSeq() : this);
|
8881 | },
|
8882 |
|
8883 | toSetSeq: function() {
|
8884 | return new ToSetSequence(this);
|
8885 | },
|
8886 |
|
8887 | toSeq: function() {
|
8888 | return isIndexed(this) ? this.toIndexedSeq() :
|
8889 | isKeyed(this) ? this.toKeyedSeq() :
|
8890 | this.toSetSeq();
|
8891 | },
|
8892 |
|
8893 | toStack: function() {
|
8894 | // Use Late Binding here to solve the circular dependency.
|
8895 | return Stack(isKeyed(this) ? this.valueSeq() : this);
|
8896 | },
|
8897 |
|
8898 | toList: function() {
|
8899 | // Use Late Binding here to solve the circular dependency.
|
8900 | return List(isKeyed(this) ? this.valueSeq() : this);
|
8901 | },
|
8902 |
|
8903 |
|
8904 | // ### Common JavaScript methods and properties
|
8905 |
|
8906 | toString: function() {
|
8907 | return '[Iterable]';
|
8908 | },
|
8909 |
|
8910 | __toString: function(head, tail) {
|
8911 | if (this.size === 0) {
|
8912 | return head + tail;
|
8913 | }
|
8914 | return head + ' ' + this.toSeq().map(this.__toStringMapper).join(', ') + ' ' + tail;
|
8915 | },
|
8916 |
|
8917 |
|
8918 | // ### ES6 Collection methods (ES6 Array and Map)
|
8919 |
|
8920 | concat: function() {var values = SLICE$0.call(arguments, 0);
|
8921 | return reify(this, concatFactory(this, values));
|
8922 | },
|
8923 |
|
8924 | includes: function(searchValue) {
|
8925 | return this.some(function(value ) {return is(value, searchValue)});
|
8926 | },
|
8927 |
|
8928 | entries: function() {
|
8929 | return this.__iterator(ITERATE_ENTRIES);
|
8930 | },
|
8931 |
|
8932 | every: function(predicate, context) {
|
8933 | assertNotInfinite(this.size);
|
8934 | var returnValue = true;
|
8935 | this.__iterate(function(v, k, c) {
|
8936 | if (!predicate.call(context, v, k, c)) {
|
8937 | returnValue = false;
|
8938 | return false;
|
8939 | }
|
8940 | });
|
8941 | return returnValue;
|
8942 | },
|
8943 |
|
8944 | filter: function(predicate, context) {
|
8945 | return reify(this, filterFactory(this, predicate, context, true));
|
8946 | },
|
8947 |
|
8948 | find: function(predicate, context, notSetValue) {
|
8949 | var entry = this.findEntry(predicate, context);
|
8950 | return entry ? entry[1] : notSetValue;
|
8951 | },
|
8952 |
|
8953 | forEach: function(sideEffect, context) {
|
8954 | assertNotInfinite(this.size);
|
8955 | return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
|
8956 | },
|
8957 |
|
8958 | join: function(separator) {
|
8959 | assertNotInfinite(this.size);
|
8960 | separator = separator !== undefined ? '' + separator : ',';
|
8961 | var joined = '';
|
8962 | var isFirst = true;
|
8963 | this.__iterate(function(v ) {
|
8964 | isFirst ? (isFirst = false) : (joined += separator);
|
8965 | joined += v !== null && v !== undefined ? v.toString() : '';
|
8966 | });
|
8967 | return joined;
|
8968 | },
|
8969 |
|
8970 | keys: function() {
|
8971 | return this.__iterator(ITERATE_KEYS);
|
8972 | },
|
8973 |
|
8974 | map: function(mapper, context) {
|
8975 | return reify(this, mapFactory(this, mapper, context));
|
8976 | },
|
8977 |
|
8978 | reduce: function(reducer, initialReduction, context) {
|
8979 | assertNotInfinite(this.size);
|
8980 | var reduction;
|
8981 | var useFirst;
|
8982 | if (arguments.length < 2) {
|
8983 | useFirst = true;
|
8984 | } else {
|
8985 | reduction = initialReduction;
|
8986 | }
|
8987 | this.__iterate(function(v, k, c) {
|
8988 | if (useFirst) {
|
8989 | useFirst = false;
|
8990 | reduction = v;
|
8991 | } else {
|
8992 | reduction = reducer.call(context, reduction, v, k, c);
|
8993 | }
|
8994 | });
|
8995 | return reduction;
|
8996 | },
|
8997 |
|
8998 | reduceRight: function(reducer, initialReduction, context) {
|
8999 | var reversed = this.toKeyedSeq().reverse();
|
9000 | return reversed.reduce.apply(reversed, arguments);
|
9001 | },
|
9002 |
|
9003 | reverse: function() {
|
9004 | return reify(this, reverseFactory(this, true));
|
9005 | },
|
9006 |
|
9007 | slice: function(begin, end) {
|
9008 | return reify(this, sliceFactory(this, begin, end, true));
|
9009 | },
|
9010 |
|
9011 | some: function(predicate, context) {
|
9012 | return !this.every(not(predicate), context);
|
9013 | },
|
9014 |
|
9015 | sort: function(comparator) {
|
9016 | return reify(this, sortFactory(this, comparator));
|
9017 | },
|
9018 |
|
9019 | values: function() {
|
9020 | return this.__iterator(ITERATE_VALUES);
|
9021 | },
|
9022 |
|
9023 |
|
9024 | // ### More sequential methods
|
9025 |
|
9026 | butLast: function() {
|
9027 | return this.slice(0, -1);
|
9028 | },
|
9029 |
|
9030 | isEmpty: function() {
|
9031 | return this.size !== undefined ? this.size === 0 : !this.some(function() {return true});
|
9032 | },
|
9033 |
|
9034 | count: function(predicate, context) {
|
9035 | return ensureSize(
|
9036 | predicate ? this.toSeq().filter(predicate, context) : this
|
9037 | );
|
9038 | },
|
9039 |
|
9040 | countBy: function(grouper, context) {
|
9041 | return countByFactory(this, grouper, context);
|
9042 | },
|
9043 |
|
9044 | equals: function(other) {
|
9045 | return deepEqual(this, other);
|
9046 | },
|
9047 |
|
9048 | entrySeq: function() {
|
9049 | var iterable = this;
|
9050 | if (iterable._cache) {
|
9051 | // We cache as an entries array, so we can just return the cache!
|
9052 | return new ArraySeq(iterable._cache);
|
9053 | }
|
9054 | var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
|
9055 | entriesSequence.fromEntrySeq = function() {return iterable.toSeq()};
|
9056 | return entriesSequence;
|
9057 | },
|
9058 |
|
9059 | filterNot: function(predicate, context) {
|
9060 | return this.filter(not(predicate), context);
|
9061 | },
|
9062 |
|
9063 | findEntry: function(predicate, context, notSetValue) {
|
9064 | var found = notSetValue;
|
9065 | this.__iterate(function(v, k, c) {
|
9066 | if (predicate.call(context, v, k, c)) {
|
9067 | found = [k, v];
|
9068 | return false;
|
9069 | }
|
9070 | });
|
9071 | return found;
|
9072 | },
|
9073 |
|
9074 | findKey: function(predicate, context) {
|
9075 | var entry = this.findEntry(predicate, context);
|
9076 | return entry && entry[0];
|
9077 | },
|
9078 |
|
9079 | findLast: function(predicate, context, notSetValue) {
|
9080 | return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
|
9081 | },
|
9082 |
|
9083 | findLastEntry: function(predicate, context, notSetValue) {
|
9084 | return this.toKeyedSeq().reverse().findEntry(predicate, context, notSetValue);
|
9085 | },
|
9086 |
|
9087 | findLastKey: function(predicate, context) {
|
9088 | return this.toKeyedSeq().reverse().findKey(predicate, context);
|
9089 | },
|
9090 |
|
9091 | first: function() {
|
9092 | return this.find(returnTrue);
|
9093 | },
|
9094 |
|
9095 | flatMap: function(mapper, context) {
|
9096 | return reify(this, flatMapFactory(this, mapper, context));
|
9097 | },
|
9098 |
|
9099 | flatten: function(depth) {
|
9100 | return reify(this, flattenFactory(this, depth, true));
|
9101 | },
|
9102 |
|
9103 | fromEntrySeq: function() {
|
9104 | return new FromEntriesSequence(this);
|
9105 | },
|
9106 |
|
9107 | get: function(searchKey, notSetValue) {
|
9108 | return this.find(function(_, key) {return is(key, searchKey)}, undefined, notSetValue);
|
9109 | },
|
9110 |
|
9111 | getIn: function(searchKeyPath, notSetValue) {
|
9112 | var nested = this;
|
9113 | // Note: in an ES6 environment, we would prefer:
|
9114 | // for (var key of searchKeyPath) {
|
9115 | var iter = forceIterator(searchKeyPath);
|
9116 | var step;
|
9117 | while (!(step = iter.next()).done) {
|
9118 | var key = step.value;
|
9119 | nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET;
|
9120 | if (nested === NOT_SET) {
|
9121 | return notSetValue;
|
9122 | }
|
9123 | }
|
9124 | return nested;
|
9125 | },
|
9126 |
|
9127 | groupBy: function(grouper, context) {
|
9128 | return groupByFactory(this, grouper, context);
|
9129 | },
|
9130 |
|
9131 | has: function(searchKey) {
|
9132 | return this.get(searchKey, NOT_SET) !== NOT_SET;
|
9133 | },
|
9134 |
|
9135 | hasIn: function(searchKeyPath) {
|
9136 | return this.getIn(searchKeyPath, NOT_SET) !== NOT_SET;
|
9137 | },
|
9138 |
|
9139 | isSubset: function(iter) {
|
9140 | iter = typeof iter.includes === 'function' ? iter : Iterable(iter);
|
9141 | return this.every(function(value ) {return iter.includes(value)});
|
9142 | },
|
9143 |
|
9144 | isSuperset: function(iter) {
|
9145 | iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
|
9146 | return iter.isSubset(this);
|
9147 | },
|
9148 |
|
9149 | keyOf: function(searchValue) {
|
9150 | return this.findKey(function(value ) {return is(value, searchValue)});
|
9151 | },
|
9152 |
|
9153 | keySeq: function() {
|
9154 | return this.toSeq().map(keyMapper).toIndexedSeq();
|
9155 | },
|
9156 |
|
9157 | last: function() {
|
9158 | return this.toSeq().reverse().first();
|
9159 | },
|
9160 |
|
9161 | lastKeyOf: function(searchValue) {
|
9162 | return this.toKeyedSeq().reverse().keyOf(searchValue);
|
9163 | },
|
9164 |
|
9165 | max: function(comparator) {
|
9166 | return maxFactory(this, comparator);
|
9167 | },
|
9168 |
|
9169 | maxBy: function(mapper, comparator) {
|
9170 | return maxFactory(this, comparator, mapper);
|
9171 | },
|
9172 |
|
9173 | min: function(comparator) {
|
9174 | return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator);
|
9175 | },
|
9176 |
|
9177 | minBy: function(mapper, comparator) {
|
9178 | return maxFactory(this, comparator ? neg(comparator) : defaultNegComparator, mapper);
|
9179 | },
|
9180 |
|
9181 | rest: function() {
|
9182 | return this.slice(1);
|
9183 | },
|
9184 |
|
9185 | skip: function(amount) {
|
9186 | return this.slice(Math.max(0, amount));
|
9187 | },
|
9188 |
|
9189 | skipLast: function(amount) {
|
9190 | return reify(this, this.toSeq().reverse().skip(amount).reverse());
|
9191 | },
|
9192 |
|
9193 | skipWhile: function(predicate, context) {
|
9194 | return reify(this, skipWhileFactory(this, predicate, context, true));
|
9195 | },
|
9196 |
|
9197 | skipUntil: function(predicate, context) {
|
9198 | return this.skipWhile(not(predicate), context);
|
9199 | },
|
9200 |
|
9201 | sortBy: function(mapper, comparator) {
|
9202 | return reify(this, sortFactory(this, comparator, mapper));
|
9203 | },
|
9204 |
|
9205 | take: function(amount) {
|
9206 | return this.slice(0, Math.max(0, amount));
|
9207 | },
|
9208 |
|
9209 | takeLast: function(amount) {
|
9210 | return reify(this, this.toSeq().reverse().take(amount).reverse());
|
9211 | },
|
9212 |
|
9213 | takeWhile: function(predicate, context) {
|
9214 | return reify(this, takeWhileFactory(this, predicate, context));
|
9215 | },
|
9216 |
|
9217 | takeUntil: function(predicate, context) {
|
9218 | return this.takeWhile(not(predicate), context);
|
9219 | },
|
9220 |
|
9221 | valueSeq: function() {
|
9222 | return this.toIndexedSeq();
|
9223 | },
|
9224 |
|
9225 |
|
9226 | // ### Hashable Object
|
9227 |
|
9228 | hashCode: function() {
|
9229 | return this.__hash || (this.__hash = hashIterable(this));
|
9230 | }
|
9231 |
|
9232 |
|
9233 | // ### Internal
|
9234 |
|
9235 | // abstract __iterate(fn, reverse)
|
9236 |
|
9237 | // abstract __iterator(type, reverse)
|
9238 | });
|
9239 |
|
9240 | // var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
|
9241 | // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
|
9242 | // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
|
9243 | // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
|
9244 |
|
9245 | var IterablePrototype = Iterable.prototype;
|
9246 | IterablePrototype[IS_ITERABLE_SENTINEL] = true;
|
9247 | IterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.values;
|
9248 | IterablePrototype.__toJS = IterablePrototype.toArray;
|
9249 | IterablePrototype.__toStringMapper = quoteString;
|
9250 | IterablePrototype.inspect =
|
9251 | IterablePrototype.toSource = function() { return this.toString(); };
|
9252 | IterablePrototype.chain = IterablePrototype.flatMap;
|
9253 | IterablePrototype.contains = IterablePrototype.includes;
|
9254 |
|
9255 | mixin(KeyedIterable, {
|
9256 |
|
9257 | // ### More sequential methods
|
9258 |
|
9259 | flip: function() {
|
9260 | return reify(this, flipFactory(this));
|
9261 | },
|
9262 |
|
9263 | mapEntries: function(mapper, context) {var this$0 = this;
|
9264 | var iterations = 0;
|
9265 | return reify(this,
|
9266 | this.toSeq().map(
|
9267 | function(v, k) {return mapper.call(context, [k, v], iterations++, this$0)}
|
9268 | ).fromEntrySeq()
|
9269 | );
|
9270 | },
|
9271 |
|
9272 | mapKeys: function(mapper, context) {var this$0 = this;
|
9273 | return reify(this,
|
9274 | this.toSeq().flip().map(
|
9275 | function(k, v) {return mapper.call(context, k, v, this$0)}
|
9276 | ).flip()
|
9277 | );
|
9278 | }
|
9279 |
|
9280 | });
|
9281 |
|
9282 | var KeyedIterablePrototype = KeyedIterable.prototype;
|
9283 | KeyedIterablePrototype[IS_KEYED_SENTINEL] = true;
|
9284 | KeyedIterablePrototype[ITERATOR_SYMBOL] = IterablePrototype.entries;
|
9285 | KeyedIterablePrototype.__toJS = IterablePrototype.toObject;
|
9286 | KeyedIterablePrototype.__toStringMapper = function(v, k) {return JSON.stringify(k) + ': ' + quoteString(v)};
|
9287 |
|
9288 |
|
9289 |
|
9290 | mixin(IndexedIterable, {
|
9291 |
|
9292 | // ### Conversion to other types
|
9293 |
|
9294 | toKeyedSeq: function() {
|
9295 | return new ToKeyedSequence(this, false);
|
9296 | },
|
9297 |
|
9298 |
|
9299 | // ### ES6 Collection methods (ES6 Array and Map)
|
9300 |
|
9301 | filter: function(predicate, context) {
|
9302 | return reify(this, filterFactory(this, predicate, context, false));
|
9303 | },
|
9304 |
|
9305 | findIndex: function(predicate, context) {
|
9306 | var entry = this.findEntry(predicate, context);
|
9307 | return entry ? entry[0] : -1;
|
9308 | },
|
9309 |
|
9310 | indexOf: function(searchValue) {
|
9311 | var key = this.keyOf(searchValue);
|
9312 | return key === undefined ? -1 : key;
|
9313 | },
|
9314 |
|
9315 | lastIndexOf: function(searchValue) {
|
9316 | var key = this.lastKeyOf(searchValue);
|
9317 | return key === undefined ? -1 : key;
|
9318 | },
|
9319 |
|
9320 | reverse: function() {
|
9321 | return reify(this, reverseFactory(this, false));
|
9322 | },
|
9323 |
|
9324 | slice: function(begin, end) {
|
9325 | return reify(this, sliceFactory(this, begin, end, false));
|
9326 | },
|
9327 |
|
9328 | splice: function(index, removeNum /*, ...values*/) {
|
9329 | var numArgs = arguments.length;
|
9330 | removeNum = Math.max(removeNum | 0, 0);
|
9331 | if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
|
9332 | return this;
|
9333 | }
|
9334 | // If index is negative, it should resolve relative to the size of the
|
9335 | // collection. However size may be expensive to compute if not cached, so
|
9336 | // only call count() if the number is in fact negative.
|
9337 | index = resolveBegin(index, index < 0 ? this.count() : this.size);
|
9338 | var spliced = this.slice(0, index);
|
9339 | return reify(
|
9340 | this,
|
9341 | numArgs === 1 ?
|
9342 | spliced :
|
9343 | spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
|
9344 | );
|
9345 | },
|
9346 |
|
9347 |
|
9348 | // ### More collection methods
|
9349 |
|
9350 | findLastIndex: function(predicate, context) {
|
9351 | var entry = this.findLastEntry(predicate, context);
|
9352 | return entry ? entry[0] : -1;
|
9353 | },
|
9354 |
|
9355 | first: function() {
|
9356 | return this.get(0);
|
9357 | },
|
9358 |
|
9359 | flatten: function(depth) {
|
9360 | return reify(this, flattenFactory(this, depth, false));
|
9361 | },
|
9362 |
|
9363 | get: function(index, notSetValue) {
|
9364 | index = wrapIndex(this, index);
|
9365 | return (index < 0 || (this.size === Infinity ||
|
9366 | (this.size !== undefined && index > this.size))) ?
|
9367 | notSetValue :
|
9368 | this.find(function(_, key) {return key === index}, undefined, notSetValue);
|
9369 | },
|
9370 |
|
9371 | has: function(index) {
|
9372 | index = wrapIndex(this, index);
|
9373 | return index >= 0 && (this.size !== undefined ?
|
9374 | this.size === Infinity || index < this.size :
|
9375 | this.indexOf(index) !== -1
|
9376 | );
|
9377 | },
|
9378 |
|
9379 | interpose: function(separator) {
|
9380 | return reify(this, interposeFactory(this, separator));
|
9381 | },
|
9382 |
|
9383 | interleave: function(/*...iterables*/) {
|
9384 | var iterables = [this].concat(arrCopy(arguments));
|
9385 | var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, iterables);
|
9386 | var interleaved = zipped.flatten(true);
|
9387 | if (zipped.size) {
|
9388 | interleaved.size = zipped.size * iterables.length;
|
9389 | }
|
9390 | return reify(this, interleaved);
|
9391 | },
|
9392 |
|
9393 | keySeq: function() {
|
9394 | return Range(0, this.size);
|
9395 | },
|
9396 |
|
9397 | last: function() {
|
9398 | return this.get(-1);
|
9399 | },
|
9400 |
|
9401 | skipWhile: function(predicate, context) {
|
9402 | return reify(this, skipWhileFactory(this, predicate, context, false));
|
9403 | },
|
9404 |
|
9405 | zip: function(/*, ...iterables */) {
|
9406 | var iterables = [this].concat(arrCopy(arguments));
|
9407 | return reify(this, zipWithFactory(this, defaultZipper, iterables));
|
9408 | },
|
9409 |
|
9410 | zipWith: function(zipper/*, ...iterables */) {
|
9411 | var iterables = arrCopy(arguments);
|
9412 | iterables[0] = this;
|
9413 | return reify(this, zipWithFactory(this, zipper, iterables));
|
9414 | }
|
9415 |
|
9416 | });
|
9417 |
|
9418 | IndexedIterable.prototype[IS_INDEXED_SENTINEL] = true;
|
9419 | IndexedIterable.prototype[IS_ORDERED_SENTINEL] = true;
|
9420 |
|
9421 |
|
9422 |
|
9423 | mixin(SetIterable, {
|
9424 |
|
9425 | // ### ES6 Collection methods (ES6 Array and Map)
|
9426 |
|
9427 | get: function(value, notSetValue) {
|
9428 | return this.has(value) ? value : notSetValue;
|
9429 | },
|
9430 |
|
9431 | includes: function(value) {
|
9432 | return this.has(value);
|
9433 | },
|
9434 |
|
9435 |
|
9436 | // ### More sequential methods
|
9437 |
|
9438 | keySeq: function() {
|
9439 | return this.valueSeq();
|
9440 | }
|
9441 |
|
9442 | });
|
9443 |
|
9444 | SetIterable.prototype.has = IterablePrototype.includes;
|
9445 | SetIterable.prototype.contains = SetIterable.prototype.includes;
|
9446 |
|
9447 |
|
9448 | // Mixin subclasses
|
9449 |
|
9450 | mixin(KeyedSeq, KeyedIterable.prototype);
|
9451 | mixin(IndexedSeq, IndexedIterable.prototype);
|
9452 | mixin(SetSeq, SetIterable.prototype);
|
9453 |
|
9454 | mixin(KeyedCollection, KeyedIterable.prototype);
|
9455 | mixin(IndexedCollection, IndexedIterable.prototype);
|
9456 | mixin(SetCollection, SetIterable.prototype);
|
9457 |
|
9458 |
|
9459 | // #pragma Helper functions
|
9460 |
|
9461 | function keyMapper(v, k) {
|
9462 | return k;
|
9463 | }
|
9464 |
|
9465 | function entryMapper(v, k) {
|
9466 | return [k, v];
|
9467 | }
|
9468 |
|
9469 | function not(predicate) {
|
9470 | return function() {
|
9471 | return !predicate.apply(this, arguments);
|
9472 | }
|
9473 | }
|
9474 |
|
9475 | function neg(predicate) {
|
9476 | return function() {
|
9477 | return -predicate.apply(this, arguments);
|
9478 | }
|
9479 | }
|
9480 |
|
9481 | function quoteString(value) {
|
9482 | return typeof value === 'string' ? JSON.stringify(value) : String(value);
|
9483 | }
|
9484 |
|
9485 | function defaultZipper() {
|
9486 | return arrCopy(arguments);
|
9487 | }
|
9488 |
|
9489 | function defaultNegComparator(a, b) {
|
9490 | return a < b ? 1 : a > b ? -1 : 0;
|
9491 | }
|
9492 |
|
9493 | function hashIterable(iterable) {
|
9494 | if (iterable.size === Infinity) {
|
9495 | return 0;
|
9496 | }
|
9497 | var ordered = isOrdered(iterable);
|
9498 | var keyed = isKeyed(iterable);
|
9499 | var h = ordered ? 1 : 0;
|
9500 | var size = iterable.__iterate(
|
9501 | keyed ?
|
9502 | ordered ?
|
9503 | function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } :
|
9504 | function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
|
9505 | ordered ?
|
9506 | function(v ) { h = 31 * h + hash(v) | 0; } :
|
9507 | function(v ) { h = h + hash(v) | 0; }
|
9508 | );
|
9509 | return murmurHashOfSize(size, h);
|
9510 | }
|
9511 |
|
9512 | function murmurHashOfSize(size, h) {
|
9513 | h = imul(h, 0xCC9E2D51);
|
9514 | h = imul(h << 15 | h >>> -15, 0x1B873593);
|
9515 | h = imul(h << 13 | h >>> -13, 5);
|
9516 | h = (h + 0xE6546B64 | 0) ^ size;
|
9517 | h = imul(h ^ h >>> 16, 0x85EBCA6B);
|
9518 | h = imul(h ^ h >>> 13, 0xC2B2AE35);
|
9519 | h = smi(h ^ h >>> 16);
|
9520 | return h;
|
9521 | }
|
9522 |
|
9523 | function hashMerge(a, b) {
|
9524 | return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
|
9525 | }
|
9526 |
|
9527 | var Immutable = {
|
9528 |
|
9529 | Iterable: Iterable,
|
9530 |
|
9531 | Seq: Seq,
|
9532 | Collection: Collection,
|
9533 | Map: Map,
|
9534 | OrderedMap: OrderedMap,
|
9535 | List: List,
|
9536 | Stack: Stack,
|
9537 | Set: Set,
|
9538 | OrderedSet: OrderedSet,
|
9539 |
|
9540 | Record: Record,
|
9541 | Range: Range,
|
9542 | Repeat: Repeat,
|
9543 |
|
9544 | is: is,
|
9545 | fromJS: fromJS
|
9546 |
|
9547 | };
|
9548 |
|
9549 | return Immutable;
|
9550 |
|
9551 | }));
|
9552 | },{}],136:[function(require,module,exports){
|
9553 |
|
9554 | /**
|
9555 | * Has own property.
|
9556 | *
|
9557 | * @type {Function}
|
9558 | */
|
9559 |
|
9560 | var has = Object.prototype.hasOwnProperty
|
9561 |
|
9562 | /**
|
9563 | * To string.
|
9564 | *
|
9565 | * @type {Function}
|
9566 | */
|
9567 |
|
9568 | var toString = Object.prototype.toString
|
9569 |
|
9570 | /**
|
9571 | * Test whether a value is "empty".
|
9572 | *
|
9573 | * @param {Mixed} val
|
9574 | * @return {Boolean}
|
9575 | */
|
9576 |
|
9577 | function isEmpty(val) {
|
9578 | // Null and Undefined...
|
9579 | if (val == null) return true
|
9580 |
|
9581 | // Booleans...
|
9582 | if ('boolean' == typeof val) return false
|
9583 |
|
9584 | // Numbers...
|
9585 | if ('number' == typeof val) return val === 0
|
9586 |
|
9587 | // Strings...
|
9588 | if ('string' == typeof val) return val.length === 0
|
9589 |
|
9590 | // Functions...
|
9591 | if ('function' == typeof val) return val.length === 0
|
9592 |
|
9593 | // Arrays...
|
9594 | if (Array.isArray(val)) return val.length === 0
|
9595 |
|
9596 | // Errors...
|
9597 | if (val instanceof Error) return val.message === ''
|
9598 |
|
9599 | // Objects...
|
9600 | if (val.toString == toString) {
|
9601 | switch (val.toString()) {
|
9602 |
|
9603 | // Maps, Sets, Files and Errors...
|
9604 | case '[object File]':
|
9605 | case '[object Map]':
|
9606 | case '[object Set]': {
|
9607 | return val.size === 0
|
9608 | }
|
9609 |
|
9610 | // Plain objects...
|
9611 | case '[object Object]': {
|
9612 | for (var key in val) {
|
9613 | if (has.call(val, key)) return false
|
9614 | }
|
9615 |
|
9616 | return true
|
9617 | }
|
9618 | }
|
9619 | }
|
9620 |
|
9621 | // Anything else...
|
9622 | return false
|
9623 | }
|
9624 |
|
9625 | /**
|
9626 | * Export `isEmpty`.
|
9627 | *
|
9628 | * @type {Function}
|
9629 | */
|
9630 |
|
9631 | module.exports = isEmpty
|
9632 |
|
9633 | },{}],137:[function(require,module,exports){
|
9634 | 'use strict';
|
9635 | var numberIsNan = require('number-is-nan');
|
9636 |
|
9637 | module.exports = Number.isFinite || function (val) {
|
9638 | return !(typeof val !== 'number' || numberIsNan(val) || val === Infinity || val === -Infinity);
|
9639 | };
|
9640 |
|
9641 | },{"number-is-nan":142}],138:[function(require,module,exports){
|
9642 | "use strict";
|
9643 |
|
9644 | Object.defineProperty(exports, "__esModule", {
|
9645 | value: true
|
9646 | });
|
9647 |
|
9648 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
9649 |
|
9650 | var isBrowser = exports.isBrowser = (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object" && (typeof document === "undefined" ? "undefined" : _typeof(document)) === 'object' && document.nodeType === 9;
|
9651 |
|
9652 | exports.default = isBrowser;
|
9653 | },{}],139:[function(require,module,exports){
|
9654 | /*!
|
9655 | * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
9656 | *
|
9657 | * Copyright (c) 2014-2017, Jon Schlinkert.
|
9658 | * Released under the MIT License.
|
9659 | */
|
9660 |
|
9661 | 'use strict';
|
9662 |
|
9663 | var isObject = require('isobject');
|
9664 |
|
9665 | function isObjectObject(o) {
|
9666 | return isObject(o) === true
|
9667 | && Object.prototype.toString.call(o) === '[object Object]';
|
9668 | }
|
9669 |
|
9670 | module.exports = function isPlainObject(o) {
|
9671 | var ctor,prot;
|
9672 |
|
9673 | if (isObjectObject(o) === false) return false;
|
9674 |
|
9675 | // If has modified constructor
|
9676 | ctor = o.constructor;
|
9677 | if (typeof ctor !== 'function') return false;
|
9678 |
|
9679 | // If has modified prototype
|
9680 | prot = ctor.prototype;
|
9681 | if (isObjectObject(prot) === false) return false;
|
9682 |
|
9683 | // If constructor does not have an Object-specific method
|
9684 | if (prot.hasOwnProperty('isPrototypeOf') === false) {
|
9685 | return false;
|
9686 | }
|
9687 |
|
9688 | // Most likely a plain Object
|
9689 | return true;
|
9690 | };
|
9691 |
|
9692 | },{"isobject":140}],140:[function(require,module,exports){
|
9693 | /*!
|
9694 | * isobject <https://github.com/jonschlinkert/isobject>
|
9695 | *
|
9696 | * Copyright (c) 2014-2017, Jon Schlinkert.
|
9697 | * Released under the MIT License.
|
9698 | */
|
9699 |
|
9700 | 'use strict';
|
9701 |
|
9702 | module.exports = function isObject(val) {
|
9703 | return val != null && typeof val === 'object' && Array.isArray(val) === false;
|
9704 | };
|
9705 |
|
9706 | },{}],141:[function(require,module,exports){
|
9707 | // Source: http://jsfiddle.net/vWx8V/
|
9708 | // http://stackoverflow.com/questions/5603195/full-list-of-javascript-keycodes
|
9709 |
|
9710 | /**
|
9711 | * Conenience method returns corresponding value for given keyName or keyCode.
|
9712 | *
|
9713 | * @param {Mixed} keyCode {Number} or keyName {String}
|
9714 | * @return {Mixed}
|
9715 | * @api public
|
9716 | */
|
9717 |
|
9718 | exports = module.exports = function(searchInput) {
|
9719 | // Keyboard Events
|
9720 | if (searchInput && 'object' === typeof searchInput) {
|
9721 | var hasKeyCode = searchInput.which || searchInput.keyCode || searchInput.charCode
|
9722 | if (hasKeyCode) searchInput = hasKeyCode
|
9723 | }
|
9724 |
|
9725 | // Numbers
|
9726 | if ('number' === typeof searchInput) return names[searchInput]
|
9727 |
|
9728 | // Everything else (cast to string)
|
9729 | var search = String(searchInput)
|
9730 |
|
9731 | // check codes
|
9732 | var foundNamedKey = codes[search.toLowerCase()]
|
9733 | if (foundNamedKey) return foundNamedKey
|
9734 |
|
9735 | // check aliases
|
9736 | var foundNamedKey = aliases[search.toLowerCase()]
|
9737 | if (foundNamedKey) return foundNamedKey
|
9738 |
|
9739 | // weird character?
|
9740 | if (search.length === 1) return search.charCodeAt(0)
|
9741 |
|
9742 | return undefined
|
9743 | }
|
9744 |
|
9745 | /**
|
9746 | * Get by name
|
9747 | *
|
9748 | * exports.code['enter'] // => 13
|
9749 | */
|
9750 |
|
9751 | var codes = exports.code = exports.codes = {
|
9752 | 'backspace': 8,
|
9753 | 'tab': 9,
|
9754 | 'enter': 13,
|
9755 | 'shift': 16,
|
9756 | 'ctrl': 17,
|
9757 | 'alt': 18,
|
9758 | 'pause/break': 19,
|
9759 | 'caps lock': 20,
|
9760 | 'esc': 27,
|
9761 | 'space': 32,
|
9762 | 'page up': 33,
|
9763 | 'page down': 34,
|
9764 | 'end': 35,
|
9765 | 'home': 36,
|
9766 | 'left': 37,
|
9767 | 'up': 38,
|
9768 | 'right': 39,
|
9769 | 'down': 40,
|
9770 | 'insert': 45,
|
9771 | 'delete': 46,
|
9772 | 'command': 91,
|
9773 | 'left command': 91,
|
9774 | 'right command': 93,
|
9775 | 'numpad *': 106,
|
9776 | 'numpad +': 107,
|
9777 | 'numpad -': 109,
|
9778 | 'numpad .': 110,
|
9779 | 'numpad /': 111,
|
9780 | 'num lock': 144,
|
9781 | 'scroll lock': 145,
|
9782 | 'my computer': 182,
|
9783 | 'my calculator': 183,
|
9784 | ';': 186,
|
9785 | '=': 187,
|
9786 | ',': 188,
|
9787 | '-': 189,
|
9788 | '.': 190,
|
9789 | '/': 191,
|
9790 | '`': 192,
|
9791 | '[': 219,
|
9792 | '\\': 220,
|
9793 | ']': 221,
|
9794 | "'": 222
|
9795 | }
|
9796 |
|
9797 | // Helper aliases
|
9798 |
|
9799 | var aliases = exports.aliases = {
|
9800 | 'windows': 91,
|
9801 | '⇧': 16,
|
9802 | '⌥': 18,
|
9803 | '⌃': 17,
|
9804 | '⌘': 91,
|
9805 | 'ctl': 17,
|
9806 | 'control': 17,
|
9807 | 'option': 18,
|
9808 | 'pause': 19,
|
9809 | 'break': 19,
|
9810 | 'caps': 20,
|
9811 | 'return': 13,
|
9812 | 'escape': 27,
|
9813 | 'spc': 32,
|
9814 | 'pgup': 33,
|
9815 | 'pgdn': 34,
|
9816 | 'ins': 45,
|
9817 | 'del': 46,
|
9818 | 'cmd': 91
|
9819 | }
|
9820 |
|
9821 |
|
9822 | /*!
|
9823 | * Programatically add the following
|
9824 | */
|
9825 |
|
9826 | // lower case chars
|
9827 | for (i = 97; i < 123; i++) codes[String.fromCharCode(i)] = i - 32
|
9828 |
|
9829 | // numbers
|
9830 | for (var i = 48; i < 58; i++) codes[i - 48] = i
|
9831 |
|
9832 | // function keys
|
9833 | for (i = 1; i < 13; i++) codes['f'+i] = i + 111
|
9834 |
|
9835 | // numpad keys
|
9836 | for (i = 0; i < 10; i++) codes['numpad '+i] = i + 96
|
9837 |
|
9838 | /**
|
9839 | * Get by code
|
9840 | *
|
9841 | * exports.name[13] // => 'Enter'
|
9842 | */
|
9843 |
|
9844 | var names = exports.names = exports.title = {} // title for backward compat
|
9845 |
|
9846 | // Create reverse mapping
|
9847 | for (i in codes) names[codes[i]] = i
|
9848 |
|
9849 | // Add aliases
|
9850 | for (var alias in aliases) {
|
9851 | codes[alias] = aliases[alias]
|
9852 | }
|
9853 |
|
9854 | },{}],142:[function(require,module,exports){
|
9855 | 'use strict';
|
9856 | module.exports = Number.isNaN || function (x) {
|
9857 | return x !== x;
|
9858 | };
|
9859 |
|
9860 | },{}],143:[function(require,module,exports){
|
9861 | 'use strict';
|
9862 | /* eslint-disable no-unused-vars */
|
9863 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
9864 | var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
9865 |
|
9866 | function toObject(val) {
|
9867 | if (val === null || val === undefined) {
|
9868 | throw new TypeError('Object.assign cannot be called with null or undefined');
|
9869 | }
|
9870 |
|
9871 | return Object(val);
|
9872 | }
|
9873 |
|
9874 | function shouldUseNative() {
|
9875 | try {
|
9876 | if (!Object.assign) {
|
9877 | return false;
|
9878 | }
|
9879 |
|
9880 | // Detect buggy property enumeration order in older V8 versions.
|
9881 |
|
9882 | // https://bugs.chromium.org/p/v8/issues/detail?id=4118
|
9883 | var test1 = new String('abc'); // eslint-disable-line
|
9884 | test1[5] = 'de';
|
9885 | if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
9886 | return false;
|
9887 | }
|
9888 |
|
9889 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
9890 | var test2 = {};
|
9891 | for (var i = 0; i < 10; i++) {
|
9892 | test2['_' + String.fromCharCode(i)] = i;
|
9893 | }
|
9894 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
9895 | return test2[n];
|
9896 | });
|
9897 | if (order2.join('') !== '0123456789') {
|
9898 | return false;
|
9899 | }
|
9900 |
|
9901 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
9902 | var test3 = {};
|
9903 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
9904 | test3[letter] = letter;
|
9905 | });
|
9906 | if (Object.keys(Object.assign({}, test3)).join('') !==
|
9907 | 'abcdefghijklmnopqrst') {
|
9908 | return false;
|
9909 | }
|
9910 |
|
9911 | return true;
|
9912 | } catch (e) {
|
9913 | // We don't expect any of the above to throw, but better to be safe.
|
9914 | return false;
|
9915 | }
|
9916 | }
|
9917 |
|
9918 | module.exports = shouldUseNative() ? Object.assign : function (target, source) {
|
9919 | var from;
|
9920 | var to = toObject(target);
|
9921 | var symbols;
|
9922 |
|
9923 | for (var s = 1; s < arguments.length; s++) {
|
9924 | from = Object(arguments[s]);
|
9925 |
|
9926 | for (var key in from) {
|
9927 | if (hasOwnProperty.call(from, key)) {
|
9928 | to[key] = from[key];
|
9929 | }
|
9930 | }
|
9931 |
|
9932 | if (Object.getOwnPropertySymbols) {
|
9933 | symbols = Object.getOwnPropertySymbols(from);
|
9934 | for (var i = 0; i < symbols.length; i++) {
|
9935 | if (propIsEnumerable.call(from, symbols[i])) {
|
9936 | to[symbols[i]] = from[symbols[i]];
|
9937 | }
|
9938 | }
|
9939 | }
|
9940 | }
|
9941 |
|
9942 | return to;
|
9943 | };
|
9944 |
|
9945 | },{}],144:[function(require,module,exports){
|
9946 | // shim for using process in browser
|
9947 | var process = module.exports = {};
|
9948 |
|
9949 | // cached from whatever global is present so that test runners that stub it
|
9950 | // don't break things. But we need to wrap it in a try catch in case it is
|
9951 | // wrapped in strict mode code which doesn't define any globals. It's inside a
|
9952 | // function because try/catches deoptimize in certain engines.
|
9953 |
|
9954 | var cachedSetTimeout;
|
9955 | var cachedClearTimeout;
|
9956 |
|
9957 | function defaultSetTimout() {
|
9958 | throw new Error('setTimeout has not been defined');
|
9959 | }
|
9960 | function defaultClearTimeout () {
|
9961 | throw new Error('clearTimeout has not been defined');
|
9962 | }
|
9963 | (function () {
|
9964 | try {
|
9965 | if (typeof setTimeout === 'function') {
|
9966 | cachedSetTimeout = setTimeout;
|
9967 | } else {
|
9968 | cachedSetTimeout = defaultSetTimout;
|
9969 | }
|
9970 | } catch (e) {
|
9971 | cachedSetTimeout = defaultSetTimout;
|
9972 | }
|
9973 | try {
|
9974 | if (typeof clearTimeout === 'function') {
|
9975 | cachedClearTimeout = clearTimeout;
|
9976 | } else {
|
9977 | cachedClearTimeout = defaultClearTimeout;
|
9978 | }
|
9979 | } catch (e) {
|
9980 | cachedClearTimeout = defaultClearTimeout;
|
9981 | }
|
9982 | } ())
|
9983 | function runTimeout(fun) {
|
9984 | if (cachedSetTimeout === setTimeout) {
|
9985 | //normal enviroments in sane situations
|
9986 | return setTimeout(fun, 0);
|
9987 | }
|
9988 | // if setTimeout wasn't available but was latter defined
|
9989 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
9990 | cachedSetTimeout = setTimeout;
|
9991 | return setTimeout(fun, 0);
|
9992 | }
|
9993 | try {
|
9994 | // when when somebody has screwed with setTimeout but no I.E. maddness
|
9995 | return cachedSetTimeout(fun, 0);
|
9996 | } catch(e){
|
9997 | try {
|
9998 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
9999 | return cachedSetTimeout.call(null, fun, 0);
|
10000 | } catch(e){
|
10001 | // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
10002 | return cachedSetTimeout.call(this, fun, 0);
|
10003 | }
|
10004 | }
|
10005 |
|
10006 |
|
10007 | }
|
10008 | function runClearTimeout(marker) {
|
10009 | if (cachedClearTimeout === clearTimeout) {
|
10010 | //normal enviroments in sane situations
|
10011 | return clearTimeout(marker);
|
10012 | }
|
10013 | // if clearTimeout wasn't available but was latter defined
|
10014 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
10015 | cachedClearTimeout = clearTimeout;
|
10016 | return clearTimeout(marker);
|
10017 | }
|
10018 | try {
|
10019 | // when when somebody has screwed with setTimeout but no I.E. maddness
|
10020 | return cachedClearTimeout(marker);
|
10021 | } catch (e){
|
10022 | try {
|
10023 | // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
10024 | return cachedClearTimeout.call(null, marker);
|
10025 | } catch (e){
|
10026 | // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
10027 | // Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
10028 | return cachedClearTimeout.call(this, marker);
|
10029 | }
|
10030 | }
|
10031 |
|
10032 |
|
10033 |
|
10034 | }
|
10035 | var queue = [];
|
10036 | var draining = false;
|
10037 | var currentQueue;
|
10038 | var queueIndex = -1;
|
10039 |
|
10040 | function cleanUpNextTick() {
|
10041 | if (!draining || !currentQueue) {
|
10042 | return;
|
10043 | }
|
10044 | draining = false;
|
10045 | if (currentQueue.length) {
|
10046 | queue = currentQueue.concat(queue);
|
10047 | } else {
|
10048 | queueIndex = -1;
|
10049 | }
|
10050 | if (queue.length) {
|
10051 | drainQueue();
|
10052 | }
|
10053 | }
|
10054 |
|
10055 | function drainQueue() {
|
10056 | if (draining) {
|
10057 | return;
|
10058 | }
|
10059 | var timeout = runTimeout(cleanUpNextTick);
|
10060 | draining = true;
|
10061 |
|
10062 | var len = queue.length;
|
10063 | while(len) {
|
10064 | currentQueue = queue;
|
10065 | queue = [];
|
10066 | while (++queueIndex < len) {
|
10067 | if (currentQueue) {
|
10068 | currentQueue[queueIndex].run();
|
10069 | }
|
10070 | }
|
10071 | queueIndex = -1;
|
10072 | len = queue.length;
|
10073 | }
|
10074 | currentQueue = null;
|
10075 | draining = false;
|
10076 | runClearTimeout(timeout);
|
10077 | }
|
10078 |
|
10079 | process.nextTick = function (fun) {
|
10080 | var args = new Array(arguments.length - 1);
|
10081 | if (arguments.length > 1) {
|
10082 | for (var i = 1; i < arguments.length; i++) {
|
10083 | args[i - 1] = arguments[i];
|
10084 | }
|
10085 | }
|
10086 | queue.push(new Item(fun, args));
|
10087 | if (queue.length === 1 && !draining) {
|
10088 | runTimeout(drainQueue);
|
10089 | }
|
10090 | };
|
10091 |
|
10092 | // v8 likes predictible objects
|
10093 | function Item(fun, array) {
|
10094 | this.fun = fun;
|
10095 | this.array = array;
|
10096 | }
|
10097 | Item.prototype.run = function () {
|
10098 | this.fun.apply(null, this.array);
|
10099 | };
|
10100 | process.title = 'browser';
|
10101 | process.browser = true;
|
10102 | process.env = {};
|
10103 | process.argv = [];
|
10104 | process.version = ''; // empty string to avoid regexp issues
|
10105 | process.versions = {};
|
10106 |
|
10107 | function noop() {}
|
10108 |
|
10109 | process.on = noop;
|
10110 | process.addListener = noop;
|
10111 | process.once = noop;
|
10112 | process.off = noop;
|
10113 | process.removeListener = noop;
|
10114 | process.removeAllListeners = noop;
|
10115 | process.emit = noop;
|
10116 |
|
10117 | process.binding = function (name) {
|
10118 | throw new Error('process.binding is not supported');
|
10119 | };
|
10120 |
|
10121 | process.cwd = function () { return '/' };
|
10122 | process.chdir = function (dir) {
|
10123 | throw new Error('process.chdir is not supported');
|
10124 | };
|
10125 | process.umask = function() { return 0; };
|
10126 |
|
10127 | },{}],145:[function(require,module,exports){
|
10128 | (function (process){
|
10129 | /**
|
10130 | * Copyright 2013-present, Facebook, Inc.
|
10131 | * All rights reserved.
|
10132 | *
|
10133 | * This source code is licensed under the BSD-style license found in the
|
10134 | * LICENSE file in the root directory of this source tree. An additional grant
|
10135 | * of patent rights can be found in the PATENTS file in the same directory.
|
10136 | */
|
10137 |
|
10138 | 'use strict';
|
10139 |
|
10140 | if (process.env.NODE_ENV !== 'production') {
|
10141 | var invariant = require('fbjs/lib/invariant');
|
10142 | var warning = require('fbjs/lib/warning');
|
10143 | var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret');
|
10144 | var loggedTypeFailures = {};
|
10145 | }
|
10146 |
|
10147 | /**
|
10148 | * Assert that the values match with the type specs.
|
10149 | * Error messages are memorized and will only be shown once.
|
10150 | *
|
10151 | * @param {object} typeSpecs Map of name to a ReactPropType
|
10152 | * @param {object} values Runtime values that need to be type-checked
|
10153 | * @param {string} location e.g. "prop", "context", "child context"
|
10154 | * @param {string} componentName Name of the component for error messages.
|
10155 | * @param {?Function} getStack Returns the component stack.
|
10156 | * @private
|
10157 | */
|
10158 | function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
10159 | if (process.env.NODE_ENV !== 'production') {
|
10160 | for (var typeSpecName in typeSpecs) {
|
10161 | if (typeSpecs.hasOwnProperty(typeSpecName)) {
|
10162 | var error;
|
10163 | // Prop type validation may throw. In case they do, we don't want to
|
10164 | // fail the render phase where it didn't fail before. So we log it.
|
10165 | // After these have been cleaned up, we'll let them throw.
|
10166 | try {
|
10167 | // This is intentionally an invariant that gets caught. It's the same
|
10168 | // behavior as without this statement except with a better message.
|
10169 | invariant(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', location, typeSpecName);
|
10170 | error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
|
10171 | } catch (ex) {
|
10172 | error = ex;
|
10173 | }
|
10174 | warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error);
|
10175 | if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
10176 | // Only monitor this failure once because there tends to be a lot of the
|
10177 | // same error.
|
10178 | loggedTypeFailures[error.message] = true;
|
10179 |
|
10180 | var stack = getStack ? getStack() : '';
|
10181 |
|
10182 | warning(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : '');
|
10183 | }
|
10184 | }
|
10185 | }
|
10186 | }
|
10187 | }
|
10188 |
|
10189 | module.exports = checkPropTypes;
|
10190 |
|
10191 | }).call(this,require('_process'))
|
10192 | },{"./lib/ReactPropTypesSecret":149,"_process":144,"fbjs/lib/invariant":151,"fbjs/lib/warning":152}],146:[function(require,module,exports){
|
10193 | /**
|
10194 | * Copyright 2013-present, Facebook, Inc.
|
10195 | * All rights reserved.
|
10196 | *
|
10197 | * This source code is licensed under the BSD-style license found in the
|
10198 | * LICENSE file in the root directory of this source tree. An additional grant
|
10199 | * of patent rights can be found in the PATENTS file in the same directory.
|
10200 | */
|
10201 |
|
10202 | 'use strict';
|
10203 |
|
10204 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
10205 | var invariant = require('fbjs/lib/invariant');
|
10206 | var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret');
|
10207 |
|
10208 | module.exports = function() {
|
10209 | function shim(props, propName, componentName, location, propFullName, secret) {
|
10210 | if (secret === ReactPropTypesSecret) {
|
10211 | // It is still safe when called from React.
|
10212 | return;
|
10213 | }
|
10214 | invariant(
|
10215 | false,
|
10216 | 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
10217 | 'Use PropTypes.checkPropTypes() to call them. ' +
|
10218 | 'Read more at http://fb.me/use-check-prop-types'
|
10219 | );
|
10220 | };
|
10221 | shim.isRequired = shim;
|
10222 | function getShim() {
|
10223 | return shim;
|
10224 | };
|
10225 | // Important!
|
10226 | // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
|
10227 | var ReactPropTypes = {
|
10228 | array: shim,
|
10229 | bool: shim,
|
10230 | func: shim,
|
10231 | number: shim,
|
10232 | object: shim,
|
10233 | string: shim,
|
10234 | symbol: shim,
|
10235 |
|
10236 | any: shim,
|
10237 | arrayOf: getShim,
|
10238 | element: shim,
|
10239 | instanceOf: getShim,
|
10240 | node: shim,
|
10241 | objectOf: getShim,
|
10242 | oneOf: getShim,
|
10243 | oneOfType: getShim,
|
10244 | shape: getShim
|
10245 | };
|
10246 |
|
10247 | ReactPropTypes.checkPropTypes = emptyFunction;
|
10248 | ReactPropTypes.PropTypes = ReactPropTypes;
|
10249 |
|
10250 | return ReactPropTypes;
|
10251 | };
|
10252 |
|
10253 | },{"./lib/ReactPropTypesSecret":149,"fbjs/lib/emptyFunction":150,"fbjs/lib/invariant":151}],147:[function(require,module,exports){
|
10254 | (function (process){
|
10255 | /**
|
10256 | * Copyright 2013-present, Facebook, Inc.
|
10257 | * All rights reserved.
|
10258 | *
|
10259 | * This source code is licensed under the BSD-style license found in the
|
10260 | * LICENSE file in the root directory of this source tree. An additional grant
|
10261 | * of patent rights can be found in the PATENTS file in the same directory.
|
10262 | */
|
10263 |
|
10264 | 'use strict';
|
10265 |
|
10266 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
10267 | var invariant = require('fbjs/lib/invariant');
|
10268 | var warning = require('fbjs/lib/warning');
|
10269 |
|
10270 | var ReactPropTypesSecret = require('./lib/ReactPropTypesSecret');
|
10271 | var checkPropTypes = require('./checkPropTypes');
|
10272 |
|
10273 | module.exports = function(isValidElement, throwOnDirectAccess) {
|
10274 | /* global Symbol */
|
10275 | var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
10276 | var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
10277 |
|
10278 | /**
|
10279 | * Returns the iterator method function contained on the iterable object.
|
10280 | *
|
10281 | * Be sure to invoke the function with the iterable as context:
|
10282 | *
|
10283 | * var iteratorFn = getIteratorFn(myIterable);
|
10284 | * if (iteratorFn) {
|
10285 | * var iterator = iteratorFn.call(myIterable);
|
10286 | * ...
|
10287 | * }
|
10288 | *
|
10289 | * @param {?object} maybeIterable
|
10290 | * @return {?function}
|
10291 | */
|
10292 | function getIteratorFn(maybeIterable) {
|
10293 | var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
10294 | if (typeof iteratorFn === 'function') {
|
10295 | return iteratorFn;
|
10296 | }
|
10297 | }
|
10298 |
|
10299 | /**
|
10300 | * Collection of methods that allow declaration and validation of props that are
|
10301 | * supplied to React components. Example usage:
|
10302 | *
|
10303 | * var Props = require('ReactPropTypes');
|
10304 | * var MyArticle = React.createClass({
|
10305 | * propTypes: {
|
10306 | * // An optional string prop named "description".
|
10307 | * description: Props.string,
|
10308 | *
|
10309 | * // A required enum prop named "category".
|
10310 | * category: Props.oneOf(['News','Photos']).isRequired,
|
10311 | *
|
10312 | * // A prop named "dialog" that requires an instance of Dialog.
|
10313 | * dialog: Props.instanceOf(Dialog).isRequired
|
10314 | * },
|
10315 | * render: function() { ... }
|
10316 | * });
|
10317 | *
|
10318 | * A more formal specification of how these methods are used:
|
10319 | *
|
10320 | * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
|
10321 | * decl := ReactPropTypes.{type}(.isRequired)?
|
10322 | *
|
10323 | * Each and every declaration produces a function with the same signature. This
|
10324 | * allows the creation of custom validation functions. For example:
|
10325 | *
|
10326 | * var MyLink = React.createClass({
|
10327 | * propTypes: {
|
10328 | * // An optional string or URI prop named "href".
|
10329 | * href: function(props, propName, componentName) {
|
10330 | * var propValue = props[propName];
|
10331 | * if (propValue != null && typeof propValue !== 'string' &&
|
10332 | * !(propValue instanceof URI)) {
|
10333 | * return new Error(
|
10334 | * 'Expected a string or an URI for ' + propName + ' in ' +
|
10335 | * componentName
|
10336 | * );
|
10337 | * }
|
10338 | * }
|
10339 | * },
|
10340 | * render: function() {...}
|
10341 | * });
|
10342 | *
|
10343 | * @internal
|
10344 | */
|
10345 |
|
10346 | var ANONYMOUS = '<<anonymous>>';
|
10347 |
|
10348 | // Important!
|
10349 | // Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
|
10350 | var ReactPropTypes = {
|
10351 | array: createPrimitiveTypeChecker('array'),
|
10352 | bool: createPrimitiveTypeChecker('boolean'),
|
10353 | func: createPrimitiveTypeChecker('function'),
|
10354 | number: createPrimitiveTypeChecker('number'),
|
10355 | object: createPrimitiveTypeChecker('object'),
|
10356 | string: createPrimitiveTypeChecker('string'),
|
10357 | symbol: createPrimitiveTypeChecker('symbol'),
|
10358 |
|
10359 | any: createAnyTypeChecker(),
|
10360 | arrayOf: createArrayOfTypeChecker,
|
10361 | element: createElementTypeChecker(),
|
10362 | instanceOf: createInstanceTypeChecker,
|
10363 | node: createNodeChecker(),
|
10364 | objectOf: createObjectOfTypeChecker,
|
10365 | oneOf: createEnumTypeChecker,
|
10366 | oneOfType: createUnionTypeChecker,
|
10367 | shape: createShapeTypeChecker
|
10368 | };
|
10369 |
|
10370 | /**
|
10371 | * inlined Object.is polyfill to avoid requiring consumers ship their own
|
10372 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
10373 | */
|
10374 | /*eslint-disable no-self-compare*/
|
10375 | function is(x, y) {
|
10376 | // SameValue algorithm
|
10377 | if (x === y) {
|
10378 | // Steps 1-5, 7-10
|
10379 | // Steps 6.b-6.e: +0 != -0
|
10380 | return x !== 0 || 1 / x === 1 / y;
|
10381 | } else {
|
10382 | // Step 6.a: NaN == NaN
|
10383 | return x !== x && y !== y;
|
10384 | }
|
10385 | }
|
10386 | /*eslint-enable no-self-compare*/
|
10387 |
|
10388 | /**
|
10389 | * We use an Error-like object for backward compatibility as people may call
|
10390 | * PropTypes directly and inspect their output. However, we don't use real
|
10391 | * Errors anymore. We don't inspect their stack anyway, and creating them
|
10392 | * is prohibitively expensive if they are created too often, such as what
|
10393 | * happens in oneOfType() for any type before the one that matched.
|
10394 | */
|
10395 | function PropTypeError(message) {
|
10396 | this.message = message;
|
10397 | this.stack = '';
|
10398 | }
|
10399 | // Make `instanceof Error` still work for returned errors.
|
10400 | PropTypeError.prototype = Error.prototype;
|
10401 |
|
10402 | function createChainableTypeChecker(validate) {
|
10403 | if (process.env.NODE_ENV !== 'production') {
|
10404 | var manualPropTypeCallCache = {};
|
10405 | var manualPropTypeWarningCount = 0;
|
10406 | }
|
10407 | function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
10408 | componentName = componentName || ANONYMOUS;
|
10409 | propFullName = propFullName || propName;
|
10410 |
|
10411 | if (secret !== ReactPropTypesSecret) {
|
10412 | if (throwOnDirectAccess) {
|
10413 | // New behavior only for users of `prop-types` package
|
10414 | invariant(
|
10415 | false,
|
10416 | 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
10417 | 'Use `PropTypes.checkPropTypes()` to call them. ' +
|
10418 | 'Read more at http://fb.me/use-check-prop-types'
|
10419 | );
|
10420 | } else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
|
10421 | // Old behavior for people using React.PropTypes
|
10422 | var cacheKey = componentName + ':' + propName;
|
10423 | if (
|
10424 | !manualPropTypeCallCache[cacheKey] &&
|
10425 | // Avoid spamming the console because they are often not actionable except for lib authors
|
10426 | manualPropTypeWarningCount < 3
|
10427 | ) {
|
10428 | warning(
|
10429 | false,
|
10430 | 'You are manually calling a React.PropTypes validation ' +
|
10431 | 'function for the `%s` prop on `%s`. This is deprecated ' +
|
10432 | 'and will throw in the standalone `prop-types` package. ' +
|
10433 | 'You may be seeing this warning due to a third-party PropTypes ' +
|
10434 | 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.',
|
10435 | propFullName,
|
10436 | componentName
|
10437 | );
|
10438 | manualPropTypeCallCache[cacheKey] = true;
|
10439 | manualPropTypeWarningCount++;
|
10440 | }
|
10441 | }
|
10442 | }
|
10443 | if (props[propName] == null) {
|
10444 | if (isRequired) {
|
10445 | if (props[propName] === null) {
|
10446 | return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
10447 | }
|
10448 | return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
10449 | }
|
10450 | return null;
|
10451 | } else {
|
10452 | return validate(props, propName, componentName, location, propFullName);
|
10453 | }
|
10454 | }
|
10455 |
|
10456 | var chainedCheckType = checkType.bind(null, false);
|
10457 | chainedCheckType.isRequired = checkType.bind(null, true);
|
10458 |
|
10459 | return chainedCheckType;
|
10460 | }
|
10461 |
|
10462 | function createPrimitiveTypeChecker(expectedType) {
|
10463 | function validate(props, propName, componentName, location, propFullName, secret) {
|
10464 | var propValue = props[propName];
|
10465 | var propType = getPropType(propValue);
|
10466 | if (propType !== expectedType) {
|
10467 | // `propValue` being instance of, say, date/regexp, pass the 'object'
|
10468 | // check, but we can offer a more precise error message here rather than
|
10469 | // 'of type `object`'.
|
10470 | var preciseType = getPreciseType(propValue);
|
10471 |
|
10472 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
|
10473 | }
|
10474 | return null;
|
10475 | }
|
10476 | return createChainableTypeChecker(validate);
|
10477 | }
|
10478 |
|
10479 | function createAnyTypeChecker() {
|
10480 | return createChainableTypeChecker(emptyFunction.thatReturnsNull);
|
10481 | }
|
10482 |
|
10483 | function createArrayOfTypeChecker(typeChecker) {
|
10484 | function validate(props, propName, componentName, location, propFullName) {
|
10485 | if (typeof typeChecker !== 'function') {
|
10486 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
10487 | }
|
10488 | var propValue = props[propName];
|
10489 | if (!Array.isArray(propValue)) {
|
10490 | var propType = getPropType(propValue);
|
10491 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
10492 | }
|
10493 | for (var i = 0; i < propValue.length; i++) {
|
10494 | var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
|
10495 | if (error instanceof Error) {
|
10496 | return error;
|
10497 | }
|
10498 | }
|
10499 | return null;
|
10500 | }
|
10501 | return createChainableTypeChecker(validate);
|
10502 | }
|
10503 |
|
10504 | function createElementTypeChecker() {
|
10505 | function validate(props, propName, componentName, location, propFullName) {
|
10506 | var propValue = props[propName];
|
10507 | if (!isValidElement(propValue)) {
|
10508 | var propType = getPropType(propValue);
|
10509 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
10510 | }
|
10511 | return null;
|
10512 | }
|
10513 | return createChainableTypeChecker(validate);
|
10514 | }
|
10515 |
|
10516 | function createInstanceTypeChecker(expectedClass) {
|
10517 | function validate(props, propName, componentName, location, propFullName) {
|
10518 | if (!(props[propName] instanceof expectedClass)) {
|
10519 | var expectedClassName = expectedClass.name || ANONYMOUS;
|
10520 | var actualClassName = getClassName(props[propName]);
|
10521 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
10522 | }
|
10523 | return null;
|
10524 | }
|
10525 | return createChainableTypeChecker(validate);
|
10526 | }
|
10527 |
|
10528 | function createEnumTypeChecker(expectedValues) {
|
10529 | if (!Array.isArray(expectedValues)) {
|
10530 | process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
|
10531 | return emptyFunction.thatReturnsNull;
|
10532 | }
|
10533 |
|
10534 | function validate(props, propName, componentName, location, propFullName) {
|
10535 | var propValue = props[propName];
|
10536 | for (var i = 0; i < expectedValues.length; i++) {
|
10537 | if (is(propValue, expectedValues[i])) {
|
10538 | return null;
|
10539 | }
|
10540 | }
|
10541 |
|
10542 | var valuesString = JSON.stringify(expectedValues);
|
10543 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
10544 | }
|
10545 | return createChainableTypeChecker(validate);
|
10546 | }
|
10547 |
|
10548 | function createObjectOfTypeChecker(typeChecker) {
|
10549 | function validate(props, propName, componentName, location, propFullName) {
|
10550 | if (typeof typeChecker !== 'function') {
|
10551 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
10552 | }
|
10553 | var propValue = props[propName];
|
10554 | var propType = getPropType(propValue);
|
10555 | if (propType !== 'object') {
|
10556 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
10557 | }
|
10558 | for (var key in propValue) {
|
10559 | if (propValue.hasOwnProperty(key)) {
|
10560 | var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
10561 | if (error instanceof Error) {
|
10562 | return error;
|
10563 | }
|
10564 | }
|
10565 | }
|
10566 | return null;
|
10567 | }
|
10568 | return createChainableTypeChecker(validate);
|
10569 | }
|
10570 |
|
10571 | function createUnionTypeChecker(arrayOfTypeCheckers) {
|
10572 | if (!Array.isArray(arrayOfTypeCheckers)) {
|
10573 | process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
|
10574 | return emptyFunction.thatReturnsNull;
|
10575 | }
|
10576 |
|
10577 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
10578 | var checker = arrayOfTypeCheckers[i];
|
10579 | if (typeof checker !== 'function') {
|
10580 | warning(
|
10581 | false,
|
10582 | 'Invalid argument supplid to oneOfType. Expected an array of check functions, but ' +
|
10583 | 'received %s at index %s.',
|
10584 | getPostfixForTypeWarning(checker),
|
10585 | i
|
10586 | );
|
10587 | return emptyFunction.thatReturnsNull;
|
10588 | }
|
10589 | }
|
10590 |
|
10591 | function validate(props, propName, componentName, location, propFullName) {
|
10592 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
10593 | var checker = arrayOfTypeCheckers[i];
|
10594 | if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) {
|
10595 | return null;
|
10596 | }
|
10597 | }
|
10598 |
|
10599 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
10600 | }
|
10601 | return createChainableTypeChecker(validate);
|
10602 | }
|
10603 |
|
10604 | function createNodeChecker() {
|
10605 | function validate(props, propName, componentName, location, propFullName) {
|
10606 | if (!isNode(props[propName])) {
|
10607 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
10608 | }
|
10609 | return null;
|
10610 | }
|
10611 | return createChainableTypeChecker(validate);
|
10612 | }
|
10613 |
|
10614 | function createShapeTypeChecker(shapeTypes) {
|
10615 | function validate(props, propName, componentName, location, propFullName) {
|
10616 | var propValue = props[propName];
|
10617 | var propType = getPropType(propValue);
|
10618 | if (propType !== 'object') {
|
10619 | return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
10620 | }
|
10621 | for (var key in shapeTypes) {
|
10622 | var checker = shapeTypes[key];
|
10623 | if (!checker) {
|
10624 | continue;
|
10625 | }
|
10626 | var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
10627 | if (error) {
|
10628 | return error;
|
10629 | }
|
10630 | }
|
10631 | return null;
|
10632 | }
|
10633 | return createChainableTypeChecker(validate);
|
10634 | }
|
10635 |
|
10636 | function isNode(propValue) {
|
10637 | switch (typeof propValue) {
|
10638 | case 'number':
|
10639 | case 'string':
|
10640 | case 'undefined':
|
10641 | return true;
|
10642 | case 'boolean':
|
10643 | return !propValue;
|
10644 | case 'object':
|
10645 | if (Array.isArray(propValue)) {
|
10646 | return propValue.every(isNode);
|
10647 | }
|
10648 | if (propValue === null || isValidElement(propValue)) {
|
10649 | return true;
|
10650 | }
|
10651 |
|
10652 | var iteratorFn = getIteratorFn(propValue);
|
10653 | if (iteratorFn) {
|
10654 | var iterator = iteratorFn.call(propValue);
|
10655 | var step;
|
10656 | if (iteratorFn !== propValue.entries) {
|
10657 | while (!(step = iterator.next()).done) {
|
10658 | if (!isNode(step.value)) {
|
10659 | return false;
|
10660 | }
|
10661 | }
|
10662 | } else {
|
10663 | // Iterator will provide entry [k,v] tuples rather than values.
|
10664 | while (!(step = iterator.next()).done) {
|
10665 | var entry = step.value;
|
10666 | if (entry) {
|
10667 | if (!isNode(entry[1])) {
|
10668 | return false;
|
10669 | }
|
10670 | }
|
10671 | }
|
10672 | }
|
10673 | } else {
|
10674 | return false;
|
10675 | }
|
10676 |
|
10677 | return true;
|
10678 | default:
|
10679 | return false;
|
10680 | }
|
10681 | }
|
10682 |
|
10683 | function isSymbol(propType, propValue) {
|
10684 | // Native Symbol.
|
10685 | if (propType === 'symbol') {
|
10686 | return true;
|
10687 | }
|
10688 |
|
10689 | // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
10690 | if (propValue['@@toStringTag'] === 'Symbol') {
|
10691 | return true;
|
10692 | }
|
10693 |
|
10694 | // Fallback for non-spec compliant Symbols which are polyfilled.
|
10695 | if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
10696 | return true;
|
10697 | }
|
10698 |
|
10699 | return false;
|
10700 | }
|
10701 |
|
10702 | // Equivalent of `typeof` but with special handling for array and regexp.
|
10703 | function getPropType(propValue) {
|
10704 | var propType = typeof propValue;
|
10705 | if (Array.isArray(propValue)) {
|
10706 | return 'array';
|
10707 | }
|
10708 | if (propValue instanceof RegExp) {
|
10709 | // Old webkits (at least until Android 4.0) return 'function' rather than
|
10710 | // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
10711 | // passes PropTypes.object.
|
10712 | return 'object';
|
10713 | }
|
10714 | if (isSymbol(propType, propValue)) {
|
10715 | return 'symbol';
|
10716 | }
|
10717 | return propType;
|
10718 | }
|
10719 |
|
10720 | // This handles more types than `getPropType`. Only used for error messages.
|
10721 | // See `createPrimitiveTypeChecker`.
|
10722 | function getPreciseType(propValue) {
|
10723 | if (typeof propValue === 'undefined' || propValue === null) {
|
10724 | return '' + propValue;
|
10725 | }
|
10726 | var propType = getPropType(propValue);
|
10727 | if (propType === 'object') {
|
10728 | if (propValue instanceof Date) {
|
10729 | return 'date';
|
10730 | } else if (propValue instanceof RegExp) {
|
10731 | return 'regexp';
|
10732 | }
|
10733 | }
|
10734 | return propType;
|
10735 | }
|
10736 |
|
10737 | // Returns a string that is postfixed to a warning about an invalid type.
|
10738 | // For example, "undefined" or "of type array"
|
10739 | function getPostfixForTypeWarning(value) {
|
10740 | var type = getPreciseType(value);
|
10741 | switch (type) {
|
10742 | case 'array':
|
10743 | case 'object':
|
10744 | return 'an ' + type;
|
10745 | case 'boolean':
|
10746 | case 'date':
|
10747 | case 'regexp':
|
10748 | return 'a ' + type;
|
10749 | default:
|
10750 | return type;
|
10751 | }
|
10752 | }
|
10753 |
|
10754 | // Returns class name of the object, if any.
|
10755 | function getClassName(propValue) {
|
10756 | if (!propValue.constructor || !propValue.constructor.name) {
|
10757 | return ANONYMOUS;
|
10758 | }
|
10759 | return propValue.constructor.name;
|
10760 | }
|
10761 |
|
10762 | ReactPropTypes.checkPropTypes = checkPropTypes;
|
10763 | ReactPropTypes.PropTypes = ReactPropTypes;
|
10764 |
|
10765 | return ReactPropTypes;
|
10766 | };
|
10767 |
|
10768 | }).call(this,require('_process'))
|
10769 | },{"./checkPropTypes":145,"./lib/ReactPropTypesSecret":149,"_process":144,"fbjs/lib/emptyFunction":150,"fbjs/lib/invariant":151,"fbjs/lib/warning":152}],148:[function(require,module,exports){
|
10770 | (function (process){
|
10771 | /**
|
10772 | * Copyright 2013-present, Facebook, Inc.
|
10773 | * All rights reserved.
|
10774 | *
|
10775 | * This source code is licensed under the BSD-style license found in the
|
10776 | * LICENSE file in the root directory of this source tree. An additional grant
|
10777 | * of patent rights can be found in the PATENTS file in the same directory.
|
10778 | */
|
10779 |
|
10780 | if (process.env.NODE_ENV !== 'production') {
|
10781 | var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
|
10782 | Symbol.for &&
|
10783 | Symbol.for('react.element')) ||
|
10784 | 0xeac7;
|
10785 |
|
10786 | var isValidElement = function(object) {
|
10787 | return typeof object === 'object' &&
|
10788 | object !== null &&
|
10789 | object.$$typeof === REACT_ELEMENT_TYPE;
|
10790 | };
|
10791 |
|
10792 | // By explicitly using `prop-types` you are opting into new development behavior.
|
10793 | // http://fb.me/prop-types-in-prod
|
10794 | var throwOnDirectAccess = true;
|
10795 | module.exports = require('./factoryWithTypeCheckers')(isValidElement, throwOnDirectAccess);
|
10796 | } else {
|
10797 | // By explicitly using `prop-types` you are opting into new production behavior.
|
10798 | // http://fb.me/prop-types-in-prod
|
10799 | module.exports = require('./factoryWithThrowingShims')();
|
10800 | }
|
10801 |
|
10802 | }).call(this,require('_process'))
|
10803 | },{"./factoryWithThrowingShims":146,"./factoryWithTypeCheckers":147,"_process":144}],149:[function(require,module,exports){
|
10804 | /**
|
10805 | * Copyright 2013-present, Facebook, Inc.
|
10806 | * All rights reserved.
|
10807 | *
|
10808 | * This source code is licensed under the BSD-style license found in the
|
10809 | * LICENSE file in the root directory of this source tree. An additional grant
|
10810 | * of patent rights can be found in the PATENTS file in the same directory.
|
10811 | */
|
10812 |
|
10813 | 'use strict';
|
10814 |
|
10815 | var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
10816 |
|
10817 | module.exports = ReactPropTypesSecret;
|
10818 |
|
10819 | },{}],150:[function(require,module,exports){
|
10820 | arguments[4][116][0].apply(exports,arguments)
|
10821 | },{"dup":116}],151:[function(require,module,exports){
|
10822 | (function (process){
|
10823 | /**
|
10824 | * Copyright (c) 2013-present, Facebook, Inc.
|
10825 | * All rights reserved.
|
10826 | *
|
10827 | * This source code is licensed under the BSD-style license found in the
|
10828 | * LICENSE file in the root directory of this source tree. An additional grant
|
10829 | * of patent rights can be found in the PATENTS file in the same directory.
|
10830 | *
|
10831 | */
|
10832 |
|
10833 | 'use strict';
|
10834 |
|
10835 | /**
|
10836 | * Use invariant() to assert state which your program assumes to be true.
|
10837 | *
|
10838 | * Provide sprintf-style format (only %s is supported) and arguments
|
10839 | * to provide information about what broke and what you were
|
10840 | * expecting.
|
10841 | *
|
10842 | * The invariant message will be stripped in production, but the invariant
|
10843 | * will remain to ensure logic does not differ in production.
|
10844 | */
|
10845 |
|
10846 | var validateFormat = function validateFormat(format) {};
|
10847 |
|
10848 | if (process.env.NODE_ENV !== 'production') {
|
10849 | validateFormat = function validateFormat(format) {
|
10850 | if (format === undefined) {
|
10851 | throw new Error('invariant requires an error message argument');
|
10852 | }
|
10853 | };
|
10854 | }
|
10855 |
|
10856 | function invariant(condition, format, a, b, c, d, e, f) {
|
10857 | validateFormat(format);
|
10858 |
|
10859 | if (!condition) {
|
10860 | var error;
|
10861 | if (format === undefined) {
|
10862 | error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
|
10863 | } else {
|
10864 | var args = [a, b, c, d, e, f];
|
10865 | var argIndex = 0;
|
10866 | error = new Error(format.replace(/%s/g, function () {
|
10867 | return args[argIndex++];
|
10868 | }));
|
10869 | error.name = 'Invariant Violation';
|
10870 | }
|
10871 |
|
10872 | error.framesToPop = 1; // we don't care about invariant's own frame
|
10873 | throw error;
|
10874 | }
|
10875 | }
|
10876 |
|
10877 | module.exports = invariant;
|
10878 | }).call(this,require('_process'))
|
10879 | },{"_process":144}],152:[function(require,module,exports){
|
10880 | (function (process){
|
10881 | /**
|
10882 | * Copyright 2014-2015, Facebook, Inc.
|
10883 | * All rights reserved.
|
10884 | *
|
10885 | * This source code is licensed under the BSD-style license found in the
|
10886 | * LICENSE file in the root directory of this source tree. An additional grant
|
10887 | * of patent rights can be found in the PATENTS file in the same directory.
|
10888 | *
|
10889 | */
|
10890 |
|
10891 | 'use strict';
|
10892 |
|
10893 | var emptyFunction = require('./emptyFunction');
|
10894 |
|
10895 | /**
|
10896 | * Similar to invariant but only logs a warning if the condition is not met.
|
10897 | * This can be used to log issues in development environments in critical
|
10898 | * paths. Removing the logging code for production environments will keep the
|
10899 | * same logic and follow the same code paths.
|
10900 | */
|
10901 |
|
10902 | var warning = emptyFunction;
|
10903 |
|
10904 | if (process.env.NODE_ENV !== 'production') {
|
10905 | var printWarning = function printWarning(format) {
|
10906 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
10907 | args[_key - 1] = arguments[_key];
|
10908 | }
|
10909 |
|
10910 | var argIndex = 0;
|
10911 | var message = 'Warning: ' + format.replace(/%s/g, function () {
|
10912 | return args[argIndex++];
|
10913 | });
|
10914 | if (typeof console !== 'undefined') {
|
10915 | console.error(message);
|
10916 | }
|
10917 | try {
|
10918 | // --- Welcome to debugging React ---
|
10919 | // This error was thrown as a convenience so that you can use this stack
|
10920 | // to find the callsite that caused this warning to fire.
|
10921 | throw new Error(message);
|
10922 | } catch (x) {}
|
10923 | };
|
10924 |
|
10925 | warning = function warning(condition, format) {
|
10926 | if (format === undefined) {
|
10927 | throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
|
10928 | }
|
10929 |
|
10930 | if (format.indexOf('Failed Composite propType: ') === 0) {
|
10931 | return; // Ignore CompositeComponent proptype check.
|
10932 | }
|
10933 |
|
10934 | if (!condition) {
|
10935 | for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
10936 | args[_key2 - 2] = arguments[_key2];
|
10937 | }
|
10938 |
|
10939 | printWarning.apply(undefined, [format].concat(args));
|
10940 | }
|
10941 | };
|
10942 | }
|
10943 |
|
10944 | module.exports = warning;
|
10945 | }).call(this,require('_process'))
|
10946 | },{"./emptyFunction":150,"_process":144}],153:[function(require,module,exports){
|
10947 | 'use strict';
|
10948 |
|
10949 | module.exports = require('./lib/ReactDOM');
|
10950 |
|
10951 | },{"./lib/ReactDOM":183}],154:[function(require,module,exports){
|
10952 | /**
|
10953 | * Copyright 2013-present, Facebook, Inc.
|
10954 | * All rights reserved.
|
10955 | *
|
10956 | * This source code is licensed under the BSD-style license found in the
|
10957 | * LICENSE file in the root directory of this source tree. An additional grant
|
10958 | * of patent rights can be found in the PATENTS file in the same directory.
|
10959 | *
|
10960 | */
|
10961 |
|
10962 | 'use strict';
|
10963 |
|
10964 | var ARIADOMPropertyConfig = {
|
10965 | Properties: {
|
10966 | // Global States and Properties
|
10967 | 'aria-current': 0, // state
|
10968 | 'aria-details': 0,
|
10969 | 'aria-disabled': 0, // state
|
10970 | 'aria-hidden': 0, // state
|
10971 | 'aria-invalid': 0, // state
|
10972 | 'aria-keyshortcuts': 0,
|
10973 | 'aria-label': 0,
|
10974 | 'aria-roledescription': 0,
|
10975 | // Widget Attributes
|
10976 | 'aria-autocomplete': 0,
|
10977 | 'aria-checked': 0,
|
10978 | 'aria-expanded': 0,
|
10979 | 'aria-haspopup': 0,
|
10980 | 'aria-level': 0,
|
10981 | 'aria-modal': 0,
|
10982 | 'aria-multiline': 0,
|
10983 | 'aria-multiselectable': 0,
|
10984 | 'aria-orientation': 0,
|
10985 | 'aria-placeholder': 0,
|
10986 | 'aria-pressed': 0,
|
10987 | 'aria-readonly': 0,
|
10988 | 'aria-required': 0,
|
10989 | 'aria-selected': 0,
|
10990 | 'aria-sort': 0,
|
10991 | 'aria-valuemax': 0,
|
10992 | 'aria-valuemin': 0,
|
10993 | 'aria-valuenow': 0,
|
10994 | 'aria-valuetext': 0,
|
10995 | // Live Region Attributes
|
10996 | 'aria-atomic': 0,
|
10997 | 'aria-busy': 0,
|
10998 | 'aria-live': 0,
|
10999 | 'aria-relevant': 0,
|
11000 | // Drag-and-Drop Attributes
|
11001 | 'aria-dropeffect': 0,
|
11002 | 'aria-grabbed': 0,
|
11003 | // Relationship Attributes
|
11004 | 'aria-activedescendant': 0,
|
11005 | 'aria-colcount': 0,
|
11006 | 'aria-colindex': 0,
|
11007 | 'aria-colspan': 0,
|
11008 | 'aria-controls': 0,
|
11009 | 'aria-describedby': 0,
|
11010 | 'aria-errormessage': 0,
|
11011 | 'aria-flowto': 0,
|
11012 | 'aria-labelledby': 0,
|
11013 | 'aria-owns': 0,
|
11014 | 'aria-posinset': 0,
|
11015 | 'aria-rowcount': 0,
|
11016 | 'aria-rowindex': 0,
|
11017 | 'aria-rowspan': 0,
|
11018 | 'aria-setsize': 0
|
11019 | },
|
11020 | DOMAttributeNames: {},
|
11021 | DOMPropertyNames: {}
|
11022 | };
|
11023 |
|
11024 | module.exports = ARIADOMPropertyConfig;
|
11025 | },{}],155:[function(require,module,exports){
|
11026 | /**
|
11027 | * Copyright 2013-present, Facebook, Inc.
|
11028 | * All rights reserved.
|
11029 | *
|
11030 | * This source code is licensed under the BSD-style license found in the
|
11031 | * LICENSE file in the root directory of this source tree. An additional grant
|
11032 | * of patent rights can be found in the PATENTS file in the same directory.
|
11033 | *
|
11034 | */
|
11035 |
|
11036 | 'use strict';
|
11037 |
|
11038 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
11039 |
|
11040 | var focusNode = require('fbjs/lib/focusNode');
|
11041 |
|
11042 | var AutoFocusUtils = {
|
11043 | focusDOMComponent: function () {
|
11044 | focusNode(ReactDOMComponentTree.getNodeFromInstance(this));
|
11045 | }
|
11046 | };
|
11047 |
|
11048 | module.exports = AutoFocusUtils;
|
11049 | },{"./ReactDOMComponentTree":186,"fbjs/lib/focusNode":118}],156:[function(require,module,exports){
|
11050 | /**
|
11051 | * Copyright 2013-present Facebook, Inc.
|
11052 | * All rights reserved.
|
11053 | *
|
11054 | * This source code is licensed under the BSD-style license found in the
|
11055 | * LICENSE file in the root directory of this source tree. An additional grant
|
11056 | * of patent rights can be found in the PATENTS file in the same directory.
|
11057 | *
|
11058 | */
|
11059 |
|
11060 | 'use strict';
|
11061 |
|
11062 | var EventPropagators = require('./EventPropagators');
|
11063 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
11064 | var FallbackCompositionState = require('./FallbackCompositionState');
|
11065 | var SyntheticCompositionEvent = require('./SyntheticCompositionEvent');
|
11066 | var SyntheticInputEvent = require('./SyntheticInputEvent');
|
11067 |
|
11068 | var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
|
11069 | var START_KEYCODE = 229;
|
11070 |
|
11071 | var canUseCompositionEvent = ExecutionEnvironment.canUseDOM && 'CompositionEvent' in window;
|
11072 |
|
11073 | var documentMode = null;
|
11074 | if (ExecutionEnvironment.canUseDOM && 'documentMode' in document) {
|
11075 | documentMode = document.documentMode;
|
11076 | }
|
11077 |
|
11078 | // Webkit offers a very useful `textInput` event that can be used to
|
11079 | // directly represent `beforeInput`. The IE `textinput` event is not as
|
11080 | // useful, so we don't use it.
|
11081 | var canUseTextInputEvent = ExecutionEnvironment.canUseDOM && 'TextEvent' in window && !documentMode && !isPresto();
|
11082 |
|
11083 | // In IE9+, we have access to composition events, but the data supplied
|
11084 | // by the native compositionend event may be incorrect. Japanese ideographic
|
11085 | // spaces, for instance (\u3000) are not recorded correctly.
|
11086 | var useFallbackCompositionData = ExecutionEnvironment.canUseDOM && (!canUseCompositionEvent || documentMode && documentMode > 8 && documentMode <= 11);
|
11087 |
|
11088 | /**
|
11089 | * Opera <= 12 includes TextEvent in window, but does not fire
|
11090 | * text input events. Rely on keypress instead.
|
11091 | */
|
11092 | function isPresto() {
|
11093 | var opera = window.opera;
|
11094 | return typeof opera === 'object' && typeof opera.version === 'function' && parseInt(opera.version(), 10) <= 12;
|
11095 | }
|
11096 |
|
11097 | var SPACEBAR_CODE = 32;
|
11098 | var SPACEBAR_CHAR = String.fromCharCode(SPACEBAR_CODE);
|
11099 |
|
11100 | // Events and their corresponding property names.
|
11101 | var eventTypes = {
|
11102 | beforeInput: {
|
11103 | phasedRegistrationNames: {
|
11104 | bubbled: 'onBeforeInput',
|
11105 | captured: 'onBeforeInputCapture'
|
11106 | },
|
11107 | dependencies: ['topCompositionEnd', 'topKeyPress', 'topTextInput', 'topPaste']
|
11108 | },
|
11109 | compositionEnd: {
|
11110 | phasedRegistrationNames: {
|
11111 | bubbled: 'onCompositionEnd',
|
11112 | captured: 'onCompositionEndCapture'
|
11113 | },
|
11114 | dependencies: ['topBlur', 'topCompositionEnd', 'topKeyDown', 'topKeyPress', 'topKeyUp', 'topMouseDown']
|
11115 | },
|
11116 | compositionStart: {
|
11117 | phasedRegistrationNames: {
|
11118 | bubbled: 'onCompositionStart',
|
11119 | captured: 'onCompositionStartCapture'
|
11120 | },
|
11121 | dependencies: ['topBlur', 'topCompositionStart', 'topKeyDown', 'topKeyPress', 'topKeyUp', 'topMouseDown']
|
11122 | },
|
11123 | compositionUpdate: {
|
11124 | phasedRegistrationNames: {
|
11125 | bubbled: 'onCompositionUpdate',
|
11126 | captured: 'onCompositionUpdateCapture'
|
11127 | },
|
11128 | dependencies: ['topBlur', 'topCompositionUpdate', 'topKeyDown', 'topKeyPress', 'topKeyUp', 'topMouseDown']
|
11129 | }
|
11130 | };
|
11131 |
|
11132 | // Track whether we've ever handled a keypress on the space key.
|
11133 | var hasSpaceKeypress = false;
|
11134 |
|
11135 | /**
|
11136 | * Return whether a native keypress event is assumed to be a command.
|
11137 | * This is required because Firefox fires `keypress` events for key commands
|
11138 | * (cut, copy, select-all, etc.) even though no character is inserted.
|
11139 | */
|
11140 | function isKeypressCommand(nativeEvent) {
|
11141 | return (nativeEvent.ctrlKey || nativeEvent.altKey || nativeEvent.metaKey) &&
|
11142 | // ctrlKey && altKey is equivalent to AltGr, and is not a command.
|
11143 | !(nativeEvent.ctrlKey && nativeEvent.altKey);
|
11144 | }
|
11145 |
|
11146 | /**
|
11147 | * Translate native top level events into event types.
|
11148 | *
|
11149 | * @param {string} topLevelType
|
11150 | * @return {object}
|
11151 | */
|
11152 | function getCompositionEventType(topLevelType) {
|
11153 | switch (topLevelType) {
|
11154 | case 'topCompositionStart':
|
11155 | return eventTypes.compositionStart;
|
11156 | case 'topCompositionEnd':
|
11157 | return eventTypes.compositionEnd;
|
11158 | case 'topCompositionUpdate':
|
11159 | return eventTypes.compositionUpdate;
|
11160 | }
|
11161 | }
|
11162 |
|
11163 | /**
|
11164 | * Does our fallback best-guess model think this event signifies that
|
11165 | * composition has begun?
|
11166 | *
|
11167 | * @param {string} topLevelType
|
11168 | * @param {object} nativeEvent
|
11169 | * @return {boolean}
|
11170 | */
|
11171 | function isFallbackCompositionStart(topLevelType, nativeEvent) {
|
11172 | return topLevelType === 'topKeyDown' && nativeEvent.keyCode === START_KEYCODE;
|
11173 | }
|
11174 |
|
11175 | /**
|
11176 | * Does our fallback mode think that this event is the end of composition?
|
11177 | *
|
11178 | * @param {string} topLevelType
|
11179 | * @param {object} nativeEvent
|
11180 | * @return {boolean}
|
11181 | */
|
11182 | function isFallbackCompositionEnd(topLevelType, nativeEvent) {
|
11183 | switch (topLevelType) {
|
11184 | case 'topKeyUp':
|
11185 | // Command keys insert or clear IME input.
|
11186 | return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1;
|
11187 | case 'topKeyDown':
|
11188 | // Expect IME keyCode on each keydown. If we get any other
|
11189 | // code we must have exited earlier.
|
11190 | return nativeEvent.keyCode !== START_KEYCODE;
|
11191 | case 'topKeyPress':
|
11192 | case 'topMouseDown':
|
11193 | case 'topBlur':
|
11194 | // Events are not possible without cancelling IME.
|
11195 | return true;
|
11196 | default:
|
11197 | return false;
|
11198 | }
|
11199 | }
|
11200 |
|
11201 | /**
|
11202 | * Google Input Tools provides composition data via a CustomEvent,
|
11203 | * with the `data` property populated in the `detail` object. If this
|
11204 | * is available on the event object, use it. If not, this is a plain
|
11205 | * composition event and we have nothing special to extract.
|
11206 | *
|
11207 | * @param {object} nativeEvent
|
11208 | * @return {?string}
|
11209 | */
|
11210 | function getDataFromCustomEvent(nativeEvent) {
|
11211 | var detail = nativeEvent.detail;
|
11212 | if (typeof detail === 'object' && 'data' in detail) {
|
11213 | return detail.data;
|
11214 | }
|
11215 | return null;
|
11216 | }
|
11217 |
|
11218 | // Track the current IME composition fallback object, if any.
|
11219 | var currentComposition = null;
|
11220 |
|
11221 | /**
|
11222 | * @return {?object} A SyntheticCompositionEvent.
|
11223 | */
|
11224 | function extractCompositionEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) {
|
11225 | var eventType;
|
11226 | var fallbackData;
|
11227 |
|
11228 | if (canUseCompositionEvent) {
|
11229 | eventType = getCompositionEventType(topLevelType);
|
11230 | } else if (!currentComposition) {
|
11231 | if (isFallbackCompositionStart(topLevelType, nativeEvent)) {
|
11232 | eventType = eventTypes.compositionStart;
|
11233 | }
|
11234 | } else if (isFallbackCompositionEnd(topLevelType, nativeEvent)) {
|
11235 | eventType = eventTypes.compositionEnd;
|
11236 | }
|
11237 |
|
11238 | if (!eventType) {
|
11239 | return null;
|
11240 | }
|
11241 |
|
11242 | if (useFallbackCompositionData) {
|
11243 | // The current composition is stored statically and must not be
|
11244 | // overwritten while composition continues.
|
11245 | if (!currentComposition && eventType === eventTypes.compositionStart) {
|
11246 | currentComposition = FallbackCompositionState.getPooled(nativeEventTarget);
|
11247 | } else if (eventType === eventTypes.compositionEnd) {
|
11248 | if (currentComposition) {
|
11249 | fallbackData = currentComposition.getData();
|
11250 | }
|
11251 | }
|
11252 | }
|
11253 |
|
11254 | var event = SyntheticCompositionEvent.getPooled(eventType, targetInst, nativeEvent, nativeEventTarget);
|
11255 |
|
11256 | if (fallbackData) {
|
11257 | // Inject data generated from fallback path into the synthetic event.
|
11258 | // This matches the property of native CompositionEventInterface.
|
11259 | event.data = fallbackData;
|
11260 | } else {
|
11261 | var customData = getDataFromCustomEvent(nativeEvent);
|
11262 | if (customData !== null) {
|
11263 | event.data = customData;
|
11264 | }
|
11265 | }
|
11266 |
|
11267 | EventPropagators.accumulateTwoPhaseDispatches(event);
|
11268 | return event;
|
11269 | }
|
11270 |
|
11271 | /**
|
11272 | * @param {string} topLevelType Record from `EventConstants`.
|
11273 | * @param {object} nativeEvent Native browser event.
|
11274 | * @return {?string} The string corresponding to this `beforeInput` event.
|
11275 | */
|
11276 | function getNativeBeforeInputChars(topLevelType, nativeEvent) {
|
11277 | switch (topLevelType) {
|
11278 | case 'topCompositionEnd':
|
11279 | return getDataFromCustomEvent(nativeEvent);
|
11280 | case 'topKeyPress':
|
11281 | /**
|
11282 | * If native `textInput` events are available, our goal is to make
|
11283 | * use of them. However, there is a special case: the spacebar key.
|
11284 | * In Webkit, preventing default on a spacebar `textInput` event
|
11285 | * cancels character insertion, but it *also* causes the browser
|
11286 | * to fall back to its default spacebar behavior of scrolling the
|
11287 | * page.
|
11288 | *
|
11289 | * Tracking at:
|
11290 | * https://code.google.com/p/chromium/issues/detail?id=355103
|
11291 | *
|
11292 | * To avoid this issue, use the keypress event as if no `textInput`
|
11293 | * event is available.
|
11294 | */
|
11295 | var which = nativeEvent.which;
|
11296 | if (which !== SPACEBAR_CODE) {
|
11297 | return null;
|
11298 | }
|
11299 |
|
11300 | hasSpaceKeypress = true;
|
11301 | return SPACEBAR_CHAR;
|
11302 |
|
11303 | case 'topTextInput':
|
11304 | // Record the characters to be added to the DOM.
|
11305 | var chars = nativeEvent.data;
|
11306 |
|
11307 | // If it's a spacebar character, assume that we have already handled
|
11308 | // it at the keypress level and bail immediately. Android Chrome
|
11309 | // doesn't give us keycodes, so we need to blacklist it.
|
11310 | if (chars === SPACEBAR_CHAR && hasSpaceKeypress) {
|
11311 | return null;
|
11312 | }
|
11313 |
|
11314 | return chars;
|
11315 |
|
11316 | default:
|
11317 | // For other native event types, do nothing.
|
11318 | return null;
|
11319 | }
|
11320 | }
|
11321 |
|
11322 | /**
|
11323 | * For browsers that do not provide the `textInput` event, extract the
|
11324 | * appropriate string to use for SyntheticInputEvent.
|
11325 | *
|
11326 | * @param {string} topLevelType Record from `EventConstants`.
|
11327 | * @param {object} nativeEvent Native browser event.
|
11328 | * @return {?string} The fallback string for this `beforeInput` event.
|
11329 | */
|
11330 | function getFallbackBeforeInputChars(topLevelType, nativeEvent) {
|
11331 | // If we are currently composing (IME) and using a fallback to do so,
|
11332 | // try to extract the composed characters from the fallback object.
|
11333 | // If composition event is available, we extract a string only at
|
11334 | // compositionevent, otherwise extract it at fallback events.
|
11335 | if (currentComposition) {
|
11336 | if (topLevelType === 'topCompositionEnd' || !canUseCompositionEvent && isFallbackCompositionEnd(topLevelType, nativeEvent)) {
|
11337 | var chars = currentComposition.getData();
|
11338 | FallbackCompositionState.release(currentComposition);
|
11339 | currentComposition = null;
|
11340 | return chars;
|
11341 | }
|
11342 | return null;
|
11343 | }
|
11344 |
|
11345 | switch (topLevelType) {
|
11346 | case 'topPaste':
|
11347 | // If a paste event occurs after a keypress, throw out the input
|
11348 | // chars. Paste events should not lead to BeforeInput events.
|
11349 | return null;
|
11350 | case 'topKeyPress':
|
11351 | /**
|
11352 | * As of v27, Firefox may fire keypress events even when no character
|
11353 | * will be inserted. A few possibilities:
|
11354 | *
|
11355 | * - `which` is `0`. Arrow keys, Esc key, etc.
|
11356 | *
|
11357 | * - `which` is the pressed key code, but no char is available.
|
11358 | * Ex: 'AltGr + d` in Polish. There is no modified character for
|
11359 | * this key combination and no character is inserted into the
|
11360 | * document, but FF fires the keypress for char code `100` anyway.
|
11361 | * No `input` event will occur.
|
11362 | *
|
11363 | * - `which` is the pressed key code, but a command combination is
|
11364 | * being used. Ex: `Cmd+C`. No character is inserted, and no
|
11365 | * `input` event will occur.
|
11366 | */
|
11367 | if (nativeEvent.which && !isKeypressCommand(nativeEvent)) {
|
11368 | return String.fromCharCode(nativeEvent.which);
|
11369 | }
|
11370 | return null;
|
11371 | case 'topCompositionEnd':
|
11372 | return useFallbackCompositionData ? null : nativeEvent.data;
|
11373 | default:
|
11374 | return null;
|
11375 | }
|
11376 | }
|
11377 |
|
11378 | /**
|
11379 | * Extract a SyntheticInputEvent for `beforeInput`, based on either native
|
11380 | * `textInput` or fallback behavior.
|
11381 | *
|
11382 | * @return {?object} A SyntheticInputEvent.
|
11383 | */
|
11384 | function extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) {
|
11385 | var chars;
|
11386 |
|
11387 | if (canUseTextInputEvent) {
|
11388 | chars = getNativeBeforeInputChars(topLevelType, nativeEvent);
|
11389 | } else {
|
11390 | chars = getFallbackBeforeInputChars(topLevelType, nativeEvent);
|
11391 | }
|
11392 |
|
11393 | // If no characters are being inserted, no BeforeInput event should
|
11394 | // be fired.
|
11395 | if (!chars) {
|
11396 | return null;
|
11397 | }
|
11398 |
|
11399 | var event = SyntheticInputEvent.getPooled(eventTypes.beforeInput, targetInst, nativeEvent, nativeEventTarget);
|
11400 |
|
11401 | event.data = chars;
|
11402 | EventPropagators.accumulateTwoPhaseDispatches(event);
|
11403 | return event;
|
11404 | }
|
11405 |
|
11406 | /**
|
11407 | * Create an `onBeforeInput` event to match
|
11408 | * http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105/#events-inputevents.
|
11409 | *
|
11410 | * This event plugin is based on the native `textInput` event
|
11411 | * available in Chrome, Safari, Opera, and IE. This event fires after
|
11412 | * `onKeyPress` and `onCompositionEnd`, but before `onInput`.
|
11413 | *
|
11414 | * `beforeInput` is spec'd but not implemented in any browsers, and
|
11415 | * the `input` event does not provide any useful information about what has
|
11416 | * actually been added, contrary to the spec. Thus, `textInput` is the best
|
11417 | * available event to identify the characters that have actually been inserted
|
11418 | * into the target node.
|
11419 | *
|
11420 | * This plugin is also responsible for emitting `composition` events, thus
|
11421 | * allowing us to share composition fallback code for both `beforeInput` and
|
11422 | * `composition` event types.
|
11423 | */
|
11424 | var BeforeInputEventPlugin = {
|
11425 |
|
11426 | eventTypes: eventTypes,
|
11427 |
|
11428 | extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
|
11429 | return [extractCompositionEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget), extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget)];
|
11430 | }
|
11431 | };
|
11432 |
|
11433 | module.exports = BeforeInputEventPlugin;
|
11434 | },{"./EventPropagators":172,"./FallbackCompositionState":173,"./SyntheticCompositionEvent":240,"./SyntheticInputEvent":244,"fbjs/lib/ExecutionEnvironment":110}],157:[function(require,module,exports){
|
11435 | /**
|
11436 | * Copyright 2013-present, Facebook, Inc.
|
11437 | * All rights reserved.
|
11438 | *
|
11439 | * This source code is licensed under the BSD-style license found in the
|
11440 | * LICENSE file in the root directory of this source tree. An additional grant
|
11441 | * of patent rights can be found in the PATENTS file in the same directory.
|
11442 | *
|
11443 | */
|
11444 |
|
11445 | 'use strict';
|
11446 |
|
11447 | /**
|
11448 | * CSS properties which accept numbers but are not in units of "px".
|
11449 | */
|
11450 |
|
11451 | var isUnitlessNumber = {
|
11452 | animationIterationCount: true,
|
11453 | borderImageOutset: true,
|
11454 | borderImageSlice: true,
|
11455 | borderImageWidth: true,
|
11456 | boxFlex: true,
|
11457 | boxFlexGroup: true,
|
11458 | boxOrdinalGroup: true,
|
11459 | columnCount: true,
|
11460 | flex: true,
|
11461 | flexGrow: true,
|
11462 | flexPositive: true,
|
11463 | flexShrink: true,
|
11464 | flexNegative: true,
|
11465 | flexOrder: true,
|
11466 | gridRow: true,
|
11467 | gridColumn: true,
|
11468 | fontWeight: true,
|
11469 | lineClamp: true,
|
11470 | lineHeight: true,
|
11471 | opacity: true,
|
11472 | order: true,
|
11473 | orphans: true,
|
11474 | tabSize: true,
|
11475 | widows: true,
|
11476 | zIndex: true,
|
11477 | zoom: true,
|
11478 |
|
11479 | // SVG-related properties
|
11480 | fillOpacity: true,
|
11481 | floodOpacity: true,
|
11482 | stopOpacity: true,
|
11483 | strokeDasharray: true,
|
11484 | strokeDashoffset: true,
|
11485 | strokeMiterlimit: true,
|
11486 | strokeOpacity: true,
|
11487 | strokeWidth: true
|
11488 | };
|
11489 |
|
11490 | /**
|
11491 | * @param {string} prefix vendor-specific prefix, eg: Webkit
|
11492 | * @param {string} key style name, eg: transitionDuration
|
11493 | * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
|
11494 | * WebkitTransitionDuration
|
11495 | */
|
11496 | function prefixKey(prefix, key) {
|
11497 | return prefix + key.charAt(0).toUpperCase() + key.substring(1);
|
11498 | }
|
11499 |
|
11500 | /**
|
11501 | * Support style names that may come passed in prefixed by adding permutations
|
11502 | * of vendor prefixes.
|
11503 | */
|
11504 | var prefixes = ['Webkit', 'ms', 'Moz', 'O'];
|
11505 |
|
11506 | // Using Object.keys here, or else the vanilla for-in loop makes IE8 go into an
|
11507 | // infinite loop, because it iterates over the newly added props too.
|
11508 | Object.keys(isUnitlessNumber).forEach(function (prop) {
|
11509 | prefixes.forEach(function (prefix) {
|
11510 | isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop];
|
11511 | });
|
11512 | });
|
11513 |
|
11514 | /**
|
11515 | * Most style properties can be unset by doing .style[prop] = '' but IE8
|
11516 | * doesn't like doing that with shorthand properties so for the properties that
|
11517 | * IE8 breaks on, which are listed here, we instead unset each of the
|
11518 | * individual properties. See http://bugs.jquery.com/ticket/12385.
|
11519 | * The 4-value 'clock' properties like margin, padding, border-width seem to
|
11520 | * behave without any problems. Curiously, list-style works too without any
|
11521 | * special prodding.
|
11522 | */
|
11523 | var shorthandPropertyExpansions = {
|
11524 | background: {
|
11525 | backgroundAttachment: true,
|
11526 | backgroundColor: true,
|
11527 | backgroundImage: true,
|
11528 | backgroundPositionX: true,
|
11529 | backgroundPositionY: true,
|
11530 | backgroundRepeat: true
|
11531 | },
|
11532 | backgroundPosition: {
|
11533 | backgroundPositionX: true,
|
11534 | backgroundPositionY: true
|
11535 | },
|
11536 | border: {
|
11537 | borderWidth: true,
|
11538 | borderStyle: true,
|
11539 | borderColor: true
|
11540 | },
|
11541 | borderBottom: {
|
11542 | borderBottomWidth: true,
|
11543 | borderBottomStyle: true,
|
11544 | borderBottomColor: true
|
11545 | },
|
11546 | borderLeft: {
|
11547 | borderLeftWidth: true,
|
11548 | borderLeftStyle: true,
|
11549 | borderLeftColor: true
|
11550 | },
|
11551 | borderRight: {
|
11552 | borderRightWidth: true,
|
11553 | borderRightStyle: true,
|
11554 | borderRightColor: true
|
11555 | },
|
11556 | borderTop: {
|
11557 | borderTopWidth: true,
|
11558 | borderTopStyle: true,
|
11559 | borderTopColor: true
|
11560 | },
|
11561 | font: {
|
11562 | fontStyle: true,
|
11563 | fontVariant: true,
|
11564 | fontWeight: true,
|
11565 | fontSize: true,
|
11566 | lineHeight: true,
|
11567 | fontFamily: true
|
11568 | },
|
11569 | outline: {
|
11570 | outlineWidth: true,
|
11571 | outlineStyle: true,
|
11572 | outlineColor: true
|
11573 | }
|
11574 | };
|
11575 |
|
11576 | var CSSProperty = {
|
11577 | isUnitlessNumber: isUnitlessNumber,
|
11578 | shorthandPropertyExpansions: shorthandPropertyExpansions
|
11579 | };
|
11580 |
|
11581 | module.exports = CSSProperty;
|
11582 | },{}],158:[function(require,module,exports){
|
11583 | (function (process){
|
11584 | /**
|
11585 | * Copyright 2013-present, Facebook, Inc.
|
11586 | * All rights reserved.
|
11587 | *
|
11588 | * This source code is licensed under the BSD-style license found in the
|
11589 | * LICENSE file in the root directory of this source tree. An additional grant
|
11590 | * of patent rights can be found in the PATENTS file in the same directory.
|
11591 | *
|
11592 | */
|
11593 |
|
11594 | 'use strict';
|
11595 |
|
11596 | var CSSProperty = require('./CSSProperty');
|
11597 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
11598 | var ReactInstrumentation = require('./ReactInstrumentation');
|
11599 |
|
11600 | var camelizeStyleName = require('fbjs/lib/camelizeStyleName');
|
11601 | var dangerousStyleValue = require('./dangerousStyleValue');
|
11602 | var hyphenateStyleName = require('fbjs/lib/hyphenateStyleName');
|
11603 | var memoizeStringOnly = require('fbjs/lib/memoizeStringOnly');
|
11604 | var warning = require('fbjs/lib/warning');
|
11605 |
|
11606 | var processStyleName = memoizeStringOnly(function (styleName) {
|
11607 | return hyphenateStyleName(styleName);
|
11608 | });
|
11609 |
|
11610 | var hasShorthandPropertyBug = false;
|
11611 | var styleFloatAccessor = 'cssFloat';
|
11612 | if (ExecutionEnvironment.canUseDOM) {
|
11613 | var tempStyle = document.createElement('div').style;
|
11614 | try {
|
11615 | // IE8 throws "Invalid argument." if resetting shorthand style properties.
|
11616 | tempStyle.font = '';
|
11617 | } catch (e) {
|
11618 | hasShorthandPropertyBug = true;
|
11619 | }
|
11620 | // IE8 only supports accessing cssFloat (standard) as styleFloat
|
11621 | if (document.documentElement.style.cssFloat === undefined) {
|
11622 | styleFloatAccessor = 'styleFloat';
|
11623 | }
|
11624 | }
|
11625 |
|
11626 | if (process.env.NODE_ENV !== 'production') {
|
11627 | // 'msTransform' is correct, but the other prefixes should be capitalized
|
11628 | var badVendoredStyleNamePattern = /^(?:webkit|moz|o)[A-Z]/;
|
11629 |
|
11630 | // style values shouldn't contain a semicolon
|
11631 | var badStyleValueWithSemicolonPattern = /;\s*$/;
|
11632 |
|
11633 | var warnedStyleNames = {};
|
11634 | var warnedStyleValues = {};
|
11635 | var warnedForNaNValue = false;
|
11636 |
|
11637 | var warnHyphenatedStyleName = function (name, owner) {
|
11638 | if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
|
11639 | return;
|
11640 | }
|
11641 |
|
11642 | warnedStyleNames[name] = true;
|
11643 | process.env.NODE_ENV !== 'production' ? warning(false, 'Unsupported style property %s. Did you mean %s?%s', name, camelizeStyleName(name), checkRenderMessage(owner)) : void 0;
|
11644 | };
|
11645 |
|
11646 | var warnBadVendoredStyleName = function (name, owner) {
|
11647 | if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
|
11648 | return;
|
11649 | }
|
11650 |
|
11651 | warnedStyleNames[name] = true;
|
11652 | process.env.NODE_ENV !== 'production' ? warning(false, 'Unsupported vendor-prefixed style property %s. Did you mean %s?%s', name, name.charAt(0).toUpperCase() + name.slice(1), checkRenderMessage(owner)) : void 0;
|
11653 | };
|
11654 |
|
11655 | var warnStyleValueWithSemicolon = function (name, value, owner) {
|
11656 | if (warnedStyleValues.hasOwnProperty(value) && warnedStyleValues[value]) {
|
11657 | return;
|
11658 | }
|
11659 |
|
11660 | warnedStyleValues[value] = true;
|
11661 | process.env.NODE_ENV !== 'production' ? warning(false, 'Style property values shouldn\'t contain a semicolon.%s ' + 'Try "%s: %s" instead.', checkRenderMessage(owner), name, value.replace(badStyleValueWithSemicolonPattern, '')) : void 0;
|
11662 | };
|
11663 |
|
11664 | var warnStyleValueIsNaN = function (name, value, owner) {
|
11665 | if (warnedForNaNValue) {
|
11666 | return;
|
11667 | }
|
11668 |
|
11669 | warnedForNaNValue = true;
|
11670 | process.env.NODE_ENV !== 'production' ? warning(false, '`NaN` is an invalid value for the `%s` css style property.%s', name, checkRenderMessage(owner)) : void 0;
|
11671 | };
|
11672 |
|
11673 | var checkRenderMessage = function (owner) {
|
11674 | if (owner) {
|
11675 | var name = owner.getName();
|
11676 | if (name) {
|
11677 | return ' Check the render method of `' + name + '`.';
|
11678 | }
|
11679 | }
|
11680 | return '';
|
11681 | };
|
11682 |
|
11683 | /**
|
11684 | * @param {string} name
|
11685 | * @param {*} value
|
11686 | * @param {ReactDOMComponent} component
|
11687 | */
|
11688 | var warnValidStyle = function (name, value, component) {
|
11689 | var owner;
|
11690 | if (component) {
|
11691 | owner = component._currentElement._owner;
|
11692 | }
|
11693 | if (name.indexOf('-') > -1) {
|
11694 | warnHyphenatedStyleName(name, owner);
|
11695 | } else if (badVendoredStyleNamePattern.test(name)) {
|
11696 | warnBadVendoredStyleName(name, owner);
|
11697 | } else if (badStyleValueWithSemicolonPattern.test(value)) {
|
11698 | warnStyleValueWithSemicolon(name, value, owner);
|
11699 | }
|
11700 |
|
11701 | if (typeof value === 'number' && isNaN(value)) {
|
11702 | warnStyleValueIsNaN(name, value, owner);
|
11703 | }
|
11704 | };
|
11705 | }
|
11706 |
|
11707 | /**
|
11708 | * Operations for dealing with CSS properties.
|
11709 | */
|
11710 | var CSSPropertyOperations = {
|
11711 |
|
11712 | /**
|
11713 | * Serializes a mapping of style properties for use as inline styles:
|
11714 | *
|
11715 | * > createMarkupForStyles({width: '200px', height: 0})
|
11716 | * "width:200px;height:0;"
|
11717 | *
|
11718 | * Undefined values are ignored so that declarative programming is easier.
|
11719 | * The result should be HTML-escaped before insertion into the DOM.
|
11720 | *
|
11721 | * @param {object} styles
|
11722 | * @param {ReactDOMComponent} component
|
11723 | * @return {?string}
|
11724 | */
|
11725 | createMarkupForStyles: function (styles, component) {
|
11726 | var serialized = '';
|
11727 | for (var styleName in styles) {
|
11728 | if (!styles.hasOwnProperty(styleName)) {
|
11729 | continue;
|
11730 | }
|
11731 | var styleValue = styles[styleName];
|
11732 | if (process.env.NODE_ENV !== 'production') {
|
11733 | warnValidStyle(styleName, styleValue, component);
|
11734 | }
|
11735 | if (styleValue != null) {
|
11736 | serialized += processStyleName(styleName) + ':';
|
11737 | serialized += dangerousStyleValue(styleName, styleValue, component) + ';';
|
11738 | }
|
11739 | }
|
11740 | return serialized || null;
|
11741 | },
|
11742 |
|
11743 | /**
|
11744 | * Sets the value for multiple styles on a node. If a value is specified as
|
11745 | * '' (empty string), the corresponding style property will be unset.
|
11746 | *
|
11747 | * @param {DOMElement} node
|
11748 | * @param {object} styles
|
11749 | * @param {ReactDOMComponent} component
|
11750 | */
|
11751 | setValueForStyles: function (node, styles, component) {
|
11752 | if (process.env.NODE_ENV !== 'production') {
|
11753 | ReactInstrumentation.debugTool.onHostOperation({
|
11754 | instanceID: component._debugID,
|
11755 | type: 'update styles',
|
11756 | payload: styles
|
11757 | });
|
11758 | }
|
11759 |
|
11760 | var style = node.style;
|
11761 | for (var styleName in styles) {
|
11762 | if (!styles.hasOwnProperty(styleName)) {
|
11763 | continue;
|
11764 | }
|
11765 | if (process.env.NODE_ENV !== 'production') {
|
11766 | warnValidStyle(styleName, styles[styleName], component);
|
11767 | }
|
11768 | var styleValue = dangerousStyleValue(styleName, styles[styleName], component);
|
11769 | if (styleName === 'float' || styleName === 'cssFloat') {
|
11770 | styleName = styleFloatAccessor;
|
11771 | }
|
11772 | if (styleValue) {
|
11773 | style[styleName] = styleValue;
|
11774 | } else {
|
11775 | var expansion = hasShorthandPropertyBug && CSSProperty.shorthandPropertyExpansions[styleName];
|
11776 | if (expansion) {
|
11777 | // Shorthand property that IE8 won't like unsetting, so unset each
|
11778 | // component to placate it
|
11779 | for (var individualStyleName in expansion) {
|
11780 | style[individualStyleName] = '';
|
11781 | }
|
11782 | } else {
|
11783 | style[styleName] = '';
|
11784 | }
|
11785 | }
|
11786 | }
|
11787 | }
|
11788 |
|
11789 | };
|
11790 |
|
11791 | module.exports = CSSPropertyOperations;
|
11792 | }).call(this,require('_process'))
|
11793 | },{"./CSSProperty":157,"./ReactInstrumentation":216,"./dangerousStyleValue":257,"_process":144,"fbjs/lib/ExecutionEnvironment":110,"fbjs/lib/camelizeStyleName":112,"fbjs/lib/hyphenateStyleName":123,"fbjs/lib/memoizeStringOnly":127,"fbjs/lib/warning":131}],159:[function(require,module,exports){
|
11794 | (function (process){
|
11795 | /**
|
11796 | * Copyright 2013-present, Facebook, Inc.
|
11797 | * All rights reserved.
|
11798 | *
|
11799 | * This source code is licensed under the BSD-style license found in the
|
11800 | * LICENSE file in the root directory of this source tree. An additional grant
|
11801 | * of patent rights can be found in the PATENTS file in the same directory.
|
11802 | *
|
11803 | *
|
11804 | */
|
11805 |
|
11806 | 'use strict';
|
11807 |
|
11808 | var _prodInvariant = require('./reactProdInvariant');
|
11809 |
|
11810 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
11811 |
|
11812 | var PooledClass = require('./PooledClass');
|
11813 |
|
11814 | var invariant = require('fbjs/lib/invariant');
|
11815 |
|
11816 | /**
|
11817 | * A specialized pseudo-event module to help keep track of components waiting to
|
11818 | * be notified when their DOM representations are available for use.
|
11819 | *
|
11820 | * This implements `PooledClass`, so you should never need to instantiate this.
|
11821 | * Instead, use `CallbackQueue.getPooled()`.
|
11822 | *
|
11823 | * @class ReactMountReady
|
11824 | * @implements PooledClass
|
11825 | * @internal
|
11826 | */
|
11827 |
|
11828 | var CallbackQueue = function () {
|
11829 | function CallbackQueue(arg) {
|
11830 | _classCallCheck(this, CallbackQueue);
|
11831 |
|
11832 | this._callbacks = null;
|
11833 | this._contexts = null;
|
11834 | this._arg = arg;
|
11835 | }
|
11836 |
|
11837 | /**
|
11838 | * Enqueues a callback to be invoked when `notifyAll` is invoked.
|
11839 | *
|
11840 | * @param {function} callback Invoked when `notifyAll` is invoked.
|
11841 | * @param {?object} context Context to call `callback` with.
|
11842 | * @internal
|
11843 | */
|
11844 |
|
11845 |
|
11846 | CallbackQueue.prototype.enqueue = function enqueue(callback, context) {
|
11847 | this._callbacks = this._callbacks || [];
|
11848 | this._callbacks.push(callback);
|
11849 | this._contexts = this._contexts || [];
|
11850 | this._contexts.push(context);
|
11851 | };
|
11852 |
|
11853 | /**
|
11854 | * Invokes all enqueued callbacks and clears the queue. This is invoked after
|
11855 | * the DOM representation of a component has been created or updated.
|
11856 | *
|
11857 | * @internal
|
11858 | */
|
11859 |
|
11860 |
|
11861 | CallbackQueue.prototype.notifyAll = function notifyAll() {
|
11862 | var callbacks = this._callbacks;
|
11863 | var contexts = this._contexts;
|
11864 | var arg = this._arg;
|
11865 | if (callbacks && contexts) {
|
11866 | !(callbacks.length === contexts.length) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Mismatched list of contexts in callback queue') : _prodInvariant('24') : void 0;
|
11867 | this._callbacks = null;
|
11868 | this._contexts = null;
|
11869 | for (var i = 0; i < callbacks.length; i++) {
|
11870 | callbacks[i].call(contexts[i], arg);
|
11871 | }
|
11872 | callbacks.length = 0;
|
11873 | contexts.length = 0;
|
11874 | }
|
11875 | };
|
11876 |
|
11877 | CallbackQueue.prototype.checkpoint = function checkpoint() {
|
11878 | return this._callbacks ? this._callbacks.length : 0;
|
11879 | };
|
11880 |
|
11881 | CallbackQueue.prototype.rollback = function rollback(len) {
|
11882 | if (this._callbacks && this._contexts) {
|
11883 | this._callbacks.length = len;
|
11884 | this._contexts.length = len;
|
11885 | }
|
11886 | };
|
11887 |
|
11888 | /**
|
11889 | * Resets the internal queue.
|
11890 | *
|
11891 | * @internal
|
11892 | */
|
11893 |
|
11894 |
|
11895 | CallbackQueue.prototype.reset = function reset() {
|
11896 | this._callbacks = null;
|
11897 | this._contexts = null;
|
11898 | };
|
11899 |
|
11900 | /**
|
11901 | * `PooledClass` looks for this.
|
11902 | */
|
11903 |
|
11904 |
|
11905 | CallbackQueue.prototype.destructor = function destructor() {
|
11906 | this.reset();
|
11907 | };
|
11908 |
|
11909 | return CallbackQueue;
|
11910 | }();
|
11911 |
|
11912 | module.exports = PooledClass.addPoolingTo(CallbackQueue);
|
11913 | }).call(this,require('_process'))
|
11914 | },{"./PooledClass":177,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],160:[function(require,module,exports){
|
11915 | /**
|
11916 | * Copyright 2013-present, Facebook, Inc.
|
11917 | * All rights reserved.
|
11918 | *
|
11919 | * This source code is licensed under the BSD-style license found in the
|
11920 | * LICENSE file in the root directory of this source tree. An additional grant
|
11921 | * of patent rights can be found in the PATENTS file in the same directory.
|
11922 | *
|
11923 | */
|
11924 |
|
11925 | 'use strict';
|
11926 |
|
11927 | var EventPluginHub = require('./EventPluginHub');
|
11928 | var EventPropagators = require('./EventPropagators');
|
11929 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
11930 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
11931 | var ReactUpdates = require('./ReactUpdates');
|
11932 | var SyntheticEvent = require('./SyntheticEvent');
|
11933 |
|
11934 | var getEventTarget = require('./getEventTarget');
|
11935 | var isEventSupported = require('./isEventSupported');
|
11936 | var isTextInputElement = require('./isTextInputElement');
|
11937 |
|
11938 | var eventTypes = {
|
11939 | change: {
|
11940 | phasedRegistrationNames: {
|
11941 | bubbled: 'onChange',
|
11942 | captured: 'onChangeCapture'
|
11943 | },
|
11944 | dependencies: ['topBlur', 'topChange', 'topClick', 'topFocus', 'topInput', 'topKeyDown', 'topKeyUp', 'topSelectionChange']
|
11945 | }
|
11946 | };
|
11947 |
|
11948 | /**
|
11949 | * For IE shims
|
11950 | */
|
11951 | var activeElement = null;
|
11952 | var activeElementInst = null;
|
11953 | var activeElementValue = null;
|
11954 | var activeElementValueProp = null;
|
11955 |
|
11956 | /**
|
11957 | * SECTION: handle `change` event
|
11958 | */
|
11959 | function shouldUseChangeEvent(elem) {
|
11960 | var nodeName = elem.nodeName && elem.nodeName.toLowerCase();
|
11961 | return nodeName === 'select' || nodeName === 'input' && elem.type === 'file';
|
11962 | }
|
11963 |
|
11964 | var doesChangeEventBubble = false;
|
11965 | if (ExecutionEnvironment.canUseDOM) {
|
11966 | // See `handleChange` comment below
|
11967 | doesChangeEventBubble = isEventSupported('change') && (!document.documentMode || document.documentMode > 8);
|
11968 | }
|
11969 |
|
11970 | function manualDispatchChangeEvent(nativeEvent) {
|
11971 | var event = SyntheticEvent.getPooled(eventTypes.change, activeElementInst, nativeEvent, getEventTarget(nativeEvent));
|
11972 | EventPropagators.accumulateTwoPhaseDispatches(event);
|
11973 |
|
11974 | // If change and propertychange bubbled, we'd just bind to it like all the
|
11975 | // other events and have it go through ReactBrowserEventEmitter. Since it
|
11976 | // doesn't, we manually listen for the events and so we have to enqueue and
|
11977 | // process the abstract event manually.
|
11978 | //
|
11979 | // Batching is necessary here in order to ensure that all event handlers run
|
11980 | // before the next rerender (including event handlers attached to ancestor
|
11981 | // elements instead of directly on the input). Without this, controlled
|
11982 | // components don't work properly in conjunction with event bubbling because
|
11983 | // the component is rerendered and the value reverted before all the event
|
11984 | // handlers can run. See https://github.com/facebook/react/issues/708.
|
11985 | ReactUpdates.batchedUpdates(runEventInBatch, event);
|
11986 | }
|
11987 |
|
11988 | function runEventInBatch(event) {
|
11989 | EventPluginHub.enqueueEvents(event);
|
11990 | EventPluginHub.processEventQueue(false);
|
11991 | }
|
11992 |
|
11993 | function startWatchingForChangeEventIE8(target, targetInst) {
|
11994 | activeElement = target;
|
11995 | activeElementInst = targetInst;
|
11996 | activeElement.attachEvent('onchange', manualDispatchChangeEvent);
|
11997 | }
|
11998 |
|
11999 | function stopWatchingForChangeEventIE8() {
|
12000 | if (!activeElement) {
|
12001 | return;
|
12002 | }
|
12003 | activeElement.detachEvent('onchange', manualDispatchChangeEvent);
|
12004 | activeElement = null;
|
12005 | activeElementInst = null;
|
12006 | }
|
12007 |
|
12008 | function getTargetInstForChangeEvent(topLevelType, targetInst) {
|
12009 | if (topLevelType === 'topChange') {
|
12010 | return targetInst;
|
12011 | }
|
12012 | }
|
12013 | function handleEventsForChangeEventIE8(topLevelType, target, targetInst) {
|
12014 | if (topLevelType === 'topFocus') {
|
12015 | // stopWatching() should be a noop here but we call it just in case we
|
12016 | // missed a blur event somehow.
|
12017 | stopWatchingForChangeEventIE8();
|
12018 | startWatchingForChangeEventIE8(target, targetInst);
|
12019 | } else if (topLevelType === 'topBlur') {
|
12020 | stopWatchingForChangeEventIE8();
|
12021 | }
|
12022 | }
|
12023 |
|
12024 | /**
|
12025 | * SECTION: handle `input` event
|
12026 | */
|
12027 | var isInputEventSupported = false;
|
12028 | if (ExecutionEnvironment.canUseDOM) {
|
12029 | // IE9 claims to support the input event but fails to trigger it when
|
12030 | // deleting text, so we ignore its input events.
|
12031 | // IE10+ fire input events to often, such when a placeholder
|
12032 | // changes or when an input with a placeholder is focused.
|
12033 | isInputEventSupported = isEventSupported('input') && (!document.documentMode || document.documentMode > 11);
|
12034 | }
|
12035 |
|
12036 | /**
|
12037 | * (For IE <=11) Replacement getter/setter for the `value` property that gets
|
12038 | * set on the active element.
|
12039 | */
|
12040 | var newValueProp = {
|
12041 | get: function () {
|
12042 | return activeElementValueProp.get.call(this);
|
12043 | },
|
12044 | set: function (val) {
|
12045 | // Cast to a string so we can do equality checks.
|
12046 | activeElementValue = '' + val;
|
12047 | activeElementValueProp.set.call(this, val);
|
12048 | }
|
12049 | };
|
12050 |
|
12051 | /**
|
12052 | * (For IE <=11) Starts tracking propertychange events on the passed-in element
|
12053 | * and override the value property so that we can distinguish user events from
|
12054 | * value changes in JS.
|
12055 | */
|
12056 | function startWatchingForValueChange(target, targetInst) {
|
12057 | activeElement = target;
|
12058 | activeElementInst = targetInst;
|
12059 | activeElementValue = target.value;
|
12060 | activeElementValueProp = Object.getOwnPropertyDescriptor(target.constructor.prototype, 'value');
|
12061 |
|
12062 | // Not guarded in a canDefineProperty check: IE8 supports defineProperty only
|
12063 | // on DOM elements
|
12064 | Object.defineProperty(activeElement, 'value', newValueProp);
|
12065 | if (activeElement.attachEvent) {
|
12066 | activeElement.attachEvent('onpropertychange', handlePropertyChange);
|
12067 | } else {
|
12068 | activeElement.addEventListener('propertychange', handlePropertyChange, false);
|
12069 | }
|
12070 | }
|
12071 |
|
12072 | /**
|
12073 | * (For IE <=11) Removes the event listeners from the currently-tracked element,
|
12074 | * if any exists.
|
12075 | */
|
12076 | function stopWatchingForValueChange() {
|
12077 | if (!activeElement) {
|
12078 | return;
|
12079 | }
|
12080 |
|
12081 | // delete restores the original property definition
|
12082 | delete activeElement.value;
|
12083 |
|
12084 | if (activeElement.detachEvent) {
|
12085 | activeElement.detachEvent('onpropertychange', handlePropertyChange);
|
12086 | } else {
|
12087 | activeElement.removeEventListener('propertychange', handlePropertyChange, false);
|
12088 | }
|
12089 |
|
12090 | activeElement = null;
|
12091 | activeElementInst = null;
|
12092 | activeElementValue = null;
|
12093 | activeElementValueProp = null;
|
12094 | }
|
12095 |
|
12096 | /**
|
12097 | * (For IE <=11) Handles a propertychange event, sending a `change` event if
|
12098 | * the value of the active element has changed.
|
12099 | */
|
12100 | function handlePropertyChange(nativeEvent) {
|
12101 | if (nativeEvent.propertyName !== 'value') {
|
12102 | return;
|
12103 | }
|
12104 | var value = nativeEvent.srcElement.value;
|
12105 | if (value === activeElementValue) {
|
12106 | return;
|
12107 | }
|
12108 | activeElementValue = value;
|
12109 |
|
12110 | manualDispatchChangeEvent(nativeEvent);
|
12111 | }
|
12112 |
|
12113 | /**
|
12114 | * If a `change` event should be fired, returns the target's ID.
|
12115 | */
|
12116 | function getTargetInstForInputEvent(topLevelType, targetInst) {
|
12117 | if (topLevelType === 'topInput') {
|
12118 | // In modern browsers (i.e., not IE8 or IE9), the input event is exactly
|
12119 | // what we want so fall through here and trigger an abstract event
|
12120 | return targetInst;
|
12121 | }
|
12122 | }
|
12123 |
|
12124 | function handleEventsForInputEventIE(topLevelType, target, targetInst) {
|
12125 | if (topLevelType === 'topFocus') {
|
12126 | // In IE8, we can capture almost all .value changes by adding a
|
12127 | // propertychange handler and looking for events with propertyName
|
12128 | // equal to 'value'
|
12129 | // In IE9-11, propertychange fires for most input events but is buggy and
|
12130 | // doesn't fire when text is deleted, but conveniently, selectionchange
|
12131 | // appears to fire in all of the remaining cases so we catch those and
|
12132 | // forward the event if the value has changed
|
12133 | // In either case, we don't want to call the event handler if the value
|
12134 | // is changed from JS so we redefine a setter for `.value` that updates
|
12135 | // our activeElementValue variable, allowing us to ignore those changes
|
12136 | //
|
12137 | // stopWatching() should be a noop here but we call it just in case we
|
12138 | // missed a blur event somehow.
|
12139 | stopWatchingForValueChange();
|
12140 | startWatchingForValueChange(target, targetInst);
|
12141 | } else if (topLevelType === 'topBlur') {
|
12142 | stopWatchingForValueChange();
|
12143 | }
|
12144 | }
|
12145 |
|
12146 | // For IE8 and IE9.
|
12147 | function getTargetInstForInputEventIE(topLevelType, targetInst) {
|
12148 | if (topLevelType === 'topSelectionChange' || topLevelType === 'topKeyUp' || topLevelType === 'topKeyDown') {
|
12149 | // On the selectionchange event, the target is just document which isn't
|
12150 | // helpful for us so just check activeElement instead.
|
12151 | //
|
12152 | // 99% of the time, keydown and keyup aren't necessary. IE8 fails to fire
|
12153 | // propertychange on the first input event after setting `value` from a
|
12154 | // script and fires only keydown, keypress, keyup. Catching keyup usually
|
12155 | // gets it and catching keydown lets us fire an event for the first
|
12156 | // keystroke if user does a key repeat (it'll be a little delayed: right
|
12157 | // before the second keystroke). Other input methods (e.g., paste) seem to
|
12158 | // fire selectionchange normally.
|
12159 | if (activeElement && activeElement.value !== activeElementValue) {
|
12160 | activeElementValue = activeElement.value;
|
12161 | return activeElementInst;
|
12162 | }
|
12163 | }
|
12164 | }
|
12165 |
|
12166 | /**
|
12167 | * SECTION: handle `click` event
|
12168 | */
|
12169 | function shouldUseClickEvent(elem) {
|
12170 | // Use the `click` event to detect changes to checkbox and radio inputs.
|
12171 | // This approach works across all browsers, whereas `change` does not fire
|
12172 | // until `blur` in IE8.
|
12173 | return elem.nodeName && elem.nodeName.toLowerCase() === 'input' && (elem.type === 'checkbox' || elem.type === 'radio');
|
12174 | }
|
12175 |
|
12176 | function getTargetInstForClickEvent(topLevelType, targetInst) {
|
12177 | if (topLevelType === 'topClick') {
|
12178 | return targetInst;
|
12179 | }
|
12180 | }
|
12181 |
|
12182 | /**
|
12183 | * This plugin creates an `onChange` event that normalizes change events
|
12184 | * across form elements. This event fires at a time when it's possible to
|
12185 | * change the element's value without seeing a flicker.
|
12186 | *
|
12187 | * Supported elements are:
|
12188 | * - input (see `isTextInputElement`)
|
12189 | * - textarea
|
12190 | * - select
|
12191 | */
|
12192 | var ChangeEventPlugin = {
|
12193 |
|
12194 | eventTypes: eventTypes,
|
12195 |
|
12196 | extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
|
12197 | var targetNode = targetInst ? ReactDOMComponentTree.getNodeFromInstance(targetInst) : window;
|
12198 |
|
12199 | var getTargetInstFunc, handleEventFunc;
|
12200 | if (shouldUseChangeEvent(targetNode)) {
|
12201 | if (doesChangeEventBubble) {
|
12202 | getTargetInstFunc = getTargetInstForChangeEvent;
|
12203 | } else {
|
12204 | handleEventFunc = handleEventsForChangeEventIE8;
|
12205 | }
|
12206 | } else if (isTextInputElement(targetNode)) {
|
12207 | if (isInputEventSupported) {
|
12208 | getTargetInstFunc = getTargetInstForInputEvent;
|
12209 | } else {
|
12210 | getTargetInstFunc = getTargetInstForInputEventIE;
|
12211 | handleEventFunc = handleEventsForInputEventIE;
|
12212 | }
|
12213 | } else if (shouldUseClickEvent(targetNode)) {
|
12214 | getTargetInstFunc = getTargetInstForClickEvent;
|
12215 | }
|
12216 |
|
12217 | if (getTargetInstFunc) {
|
12218 | var inst = getTargetInstFunc(topLevelType, targetInst);
|
12219 | if (inst) {
|
12220 | var event = SyntheticEvent.getPooled(eventTypes.change, inst, nativeEvent, nativeEventTarget);
|
12221 | event.type = 'change';
|
12222 | EventPropagators.accumulateTwoPhaseDispatches(event);
|
12223 | return event;
|
12224 | }
|
12225 | }
|
12226 |
|
12227 | if (handleEventFunc) {
|
12228 | handleEventFunc(topLevelType, targetNode, targetInst);
|
12229 | }
|
12230 | }
|
12231 |
|
12232 | };
|
12233 |
|
12234 | module.exports = ChangeEventPlugin;
|
12235 | },{"./EventPluginHub":169,"./EventPropagators":172,"./ReactDOMComponentTree":186,"./ReactUpdates":233,"./SyntheticEvent":242,"./getEventTarget":265,"./isEventSupported":273,"./isTextInputElement":274,"fbjs/lib/ExecutionEnvironment":110}],161:[function(require,module,exports){
|
12236 | (function (process){
|
12237 | /**
|
12238 | * Copyright 2013-present, Facebook, Inc.
|
12239 | * All rights reserved.
|
12240 | *
|
12241 | * This source code is licensed under the BSD-style license found in the
|
12242 | * LICENSE file in the root directory of this source tree. An additional grant
|
12243 | * of patent rights can be found in the PATENTS file in the same directory.
|
12244 | *
|
12245 | */
|
12246 |
|
12247 | 'use strict';
|
12248 |
|
12249 | var DOMLazyTree = require('./DOMLazyTree');
|
12250 | var Danger = require('./Danger');
|
12251 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
12252 | var ReactInstrumentation = require('./ReactInstrumentation');
|
12253 |
|
12254 | var createMicrosoftUnsafeLocalFunction = require('./createMicrosoftUnsafeLocalFunction');
|
12255 | var setInnerHTML = require('./setInnerHTML');
|
12256 | var setTextContent = require('./setTextContent');
|
12257 |
|
12258 | function getNodeAfter(parentNode, node) {
|
12259 | // Special case for text components, which return [open, close] comments
|
12260 | // from getHostNode.
|
12261 | if (Array.isArray(node)) {
|
12262 | node = node[1];
|
12263 | }
|
12264 | return node ? node.nextSibling : parentNode.firstChild;
|
12265 | }
|
12266 |
|
12267 | /**
|
12268 | * Inserts `childNode` as a child of `parentNode` at the `index`.
|
12269 | *
|
12270 | * @param {DOMElement} parentNode Parent node in which to insert.
|
12271 | * @param {DOMElement} childNode Child node to insert.
|
12272 | * @param {number} index Index at which to insert the child.
|
12273 | * @internal
|
12274 | */
|
12275 | var insertChildAt = createMicrosoftUnsafeLocalFunction(function (parentNode, childNode, referenceNode) {
|
12276 | // We rely exclusively on `insertBefore(node, null)` instead of also using
|
12277 | // `appendChild(node)`. (Using `undefined` is not allowed by all browsers so
|
12278 | // we are careful to use `null`.)
|
12279 | parentNode.insertBefore(childNode, referenceNode);
|
12280 | });
|
12281 |
|
12282 | function insertLazyTreeChildAt(parentNode, childTree, referenceNode) {
|
12283 | DOMLazyTree.insertTreeBefore(parentNode, childTree, referenceNode);
|
12284 | }
|
12285 |
|
12286 | function moveChild(parentNode, childNode, referenceNode) {
|
12287 | if (Array.isArray(childNode)) {
|
12288 | moveDelimitedText(parentNode, childNode[0], childNode[1], referenceNode);
|
12289 | } else {
|
12290 | insertChildAt(parentNode, childNode, referenceNode);
|
12291 | }
|
12292 | }
|
12293 |
|
12294 | function removeChild(parentNode, childNode) {
|
12295 | if (Array.isArray(childNode)) {
|
12296 | var closingComment = childNode[1];
|
12297 | childNode = childNode[0];
|
12298 | removeDelimitedText(parentNode, childNode, closingComment);
|
12299 | parentNode.removeChild(closingComment);
|
12300 | }
|
12301 | parentNode.removeChild(childNode);
|
12302 | }
|
12303 |
|
12304 | function moveDelimitedText(parentNode, openingComment, closingComment, referenceNode) {
|
12305 | var node = openingComment;
|
12306 | while (true) {
|
12307 | var nextNode = node.nextSibling;
|
12308 | insertChildAt(parentNode, node, referenceNode);
|
12309 | if (node === closingComment) {
|
12310 | break;
|
12311 | }
|
12312 | node = nextNode;
|
12313 | }
|
12314 | }
|
12315 |
|
12316 | function removeDelimitedText(parentNode, startNode, closingComment) {
|
12317 | while (true) {
|
12318 | var node = startNode.nextSibling;
|
12319 | if (node === closingComment) {
|
12320 | // The closing comment is removed by ReactMultiChild.
|
12321 | break;
|
12322 | } else {
|
12323 | parentNode.removeChild(node);
|
12324 | }
|
12325 | }
|
12326 | }
|
12327 |
|
12328 | function replaceDelimitedText(openingComment, closingComment, stringText) {
|
12329 | var parentNode = openingComment.parentNode;
|
12330 | var nodeAfterComment = openingComment.nextSibling;
|
12331 | if (nodeAfterComment === closingComment) {
|
12332 | // There are no text nodes between the opening and closing comments; insert
|
12333 | // a new one if stringText isn't empty.
|
12334 | if (stringText) {
|
12335 | insertChildAt(parentNode, document.createTextNode(stringText), nodeAfterComment);
|
12336 | }
|
12337 | } else {
|
12338 | if (stringText) {
|
12339 | // Set the text content of the first node after the opening comment, and
|
12340 | // remove all following nodes up until the closing comment.
|
12341 | setTextContent(nodeAfterComment, stringText);
|
12342 | removeDelimitedText(parentNode, nodeAfterComment, closingComment);
|
12343 | } else {
|
12344 | removeDelimitedText(parentNode, openingComment, closingComment);
|
12345 | }
|
12346 | }
|
12347 |
|
12348 | if (process.env.NODE_ENV !== 'production') {
|
12349 | ReactInstrumentation.debugTool.onHostOperation({
|
12350 | instanceID: ReactDOMComponentTree.getInstanceFromNode(openingComment)._debugID,
|
12351 | type: 'replace text',
|
12352 | payload: stringText
|
12353 | });
|
12354 | }
|
12355 | }
|
12356 |
|
12357 | var dangerouslyReplaceNodeWithMarkup = Danger.dangerouslyReplaceNodeWithMarkup;
|
12358 | if (process.env.NODE_ENV !== 'production') {
|
12359 | dangerouslyReplaceNodeWithMarkup = function (oldChild, markup, prevInstance) {
|
12360 | Danger.dangerouslyReplaceNodeWithMarkup(oldChild, markup);
|
12361 | if (prevInstance._debugID !== 0) {
|
12362 | ReactInstrumentation.debugTool.onHostOperation({
|
12363 | instanceID: prevInstance._debugID,
|
12364 | type: 'replace with',
|
12365 | payload: markup.toString()
|
12366 | });
|
12367 | } else {
|
12368 | var nextInstance = ReactDOMComponentTree.getInstanceFromNode(markup.node);
|
12369 | if (nextInstance._debugID !== 0) {
|
12370 | ReactInstrumentation.debugTool.onHostOperation({
|
12371 | instanceID: nextInstance._debugID,
|
12372 | type: 'mount',
|
12373 | payload: markup.toString()
|
12374 | });
|
12375 | }
|
12376 | }
|
12377 | };
|
12378 | }
|
12379 |
|
12380 | /**
|
12381 | * Operations for updating with DOM children.
|
12382 | */
|
12383 | var DOMChildrenOperations = {
|
12384 |
|
12385 | dangerouslyReplaceNodeWithMarkup: dangerouslyReplaceNodeWithMarkup,
|
12386 |
|
12387 | replaceDelimitedText: replaceDelimitedText,
|
12388 |
|
12389 | /**
|
12390 | * Updates a component's children by processing a series of updates. The
|
12391 | * update configurations are each expected to have a `parentNode` property.
|
12392 | *
|
12393 | * @param {array<object>} updates List of update configurations.
|
12394 | * @internal
|
12395 | */
|
12396 | processUpdates: function (parentNode, updates) {
|
12397 | if (process.env.NODE_ENV !== 'production') {
|
12398 | var parentNodeDebugID = ReactDOMComponentTree.getInstanceFromNode(parentNode)._debugID;
|
12399 | }
|
12400 |
|
12401 | for (var k = 0; k < updates.length; k++) {
|
12402 | var update = updates[k];
|
12403 | switch (update.type) {
|
12404 | case 'INSERT_MARKUP':
|
12405 | insertLazyTreeChildAt(parentNode, update.content, getNodeAfter(parentNode, update.afterNode));
|
12406 | if (process.env.NODE_ENV !== 'production') {
|
12407 | ReactInstrumentation.debugTool.onHostOperation({
|
12408 | instanceID: parentNodeDebugID,
|
12409 | type: 'insert child',
|
12410 | payload: { toIndex: update.toIndex, content: update.content.toString() }
|
12411 | });
|
12412 | }
|
12413 | break;
|
12414 | case 'MOVE_EXISTING':
|
12415 | moveChild(parentNode, update.fromNode, getNodeAfter(parentNode, update.afterNode));
|
12416 | if (process.env.NODE_ENV !== 'production') {
|
12417 | ReactInstrumentation.debugTool.onHostOperation({
|
12418 | instanceID: parentNodeDebugID,
|
12419 | type: 'move child',
|
12420 | payload: { fromIndex: update.fromIndex, toIndex: update.toIndex }
|
12421 | });
|
12422 | }
|
12423 | break;
|
12424 | case 'SET_MARKUP':
|
12425 | setInnerHTML(parentNode, update.content);
|
12426 | if (process.env.NODE_ENV !== 'production') {
|
12427 | ReactInstrumentation.debugTool.onHostOperation({
|
12428 | instanceID: parentNodeDebugID,
|
12429 | type: 'replace children',
|
12430 | payload: update.content.toString()
|
12431 | });
|
12432 | }
|
12433 | break;
|
12434 | case 'TEXT_CONTENT':
|
12435 | setTextContent(parentNode, update.content);
|
12436 | if (process.env.NODE_ENV !== 'production') {
|
12437 | ReactInstrumentation.debugTool.onHostOperation({
|
12438 | instanceID: parentNodeDebugID,
|
12439 | type: 'replace text',
|
12440 | payload: update.content.toString()
|
12441 | });
|
12442 | }
|
12443 | break;
|
12444 | case 'REMOVE_NODE':
|
12445 | removeChild(parentNode, update.fromNode);
|
12446 | if (process.env.NODE_ENV !== 'production') {
|
12447 | ReactInstrumentation.debugTool.onHostOperation({
|
12448 | instanceID: parentNodeDebugID,
|
12449 | type: 'remove child',
|
12450 | payload: { fromIndex: update.fromIndex }
|
12451 | });
|
12452 | }
|
12453 | break;
|
12454 | }
|
12455 | }
|
12456 | }
|
12457 |
|
12458 | };
|
12459 |
|
12460 | module.exports = DOMChildrenOperations;
|
12461 | }).call(this,require('_process'))
|
12462 | },{"./DOMLazyTree":162,"./Danger":166,"./ReactDOMComponentTree":186,"./ReactInstrumentation":216,"./createMicrosoftUnsafeLocalFunction":256,"./setInnerHTML":278,"./setTextContent":279,"_process":144}],162:[function(require,module,exports){
|
12463 | /**
|
12464 | * Copyright 2015-present, Facebook, Inc.
|
12465 | * All rights reserved.
|
12466 | *
|
12467 | * This source code is licensed under the BSD-style license found in the
|
12468 | * LICENSE file in the root directory of this source tree. An additional grant
|
12469 | * of patent rights can be found in the PATENTS file in the same directory.
|
12470 | *
|
12471 | */
|
12472 |
|
12473 | 'use strict';
|
12474 |
|
12475 | var DOMNamespaces = require('./DOMNamespaces');
|
12476 | var setInnerHTML = require('./setInnerHTML');
|
12477 |
|
12478 | var createMicrosoftUnsafeLocalFunction = require('./createMicrosoftUnsafeLocalFunction');
|
12479 | var setTextContent = require('./setTextContent');
|
12480 |
|
12481 | var ELEMENT_NODE_TYPE = 1;
|
12482 | var DOCUMENT_FRAGMENT_NODE_TYPE = 11;
|
12483 |
|
12484 | /**
|
12485 | * In IE (8-11) and Edge, appending nodes with no children is dramatically
|
12486 | * faster than appending a full subtree, so we essentially queue up the
|
12487 | * .appendChild calls here and apply them so each node is added to its parent
|
12488 | * before any children are added.
|
12489 | *
|
12490 | * In other browsers, doing so is slower or neutral compared to the other order
|
12491 | * (in Firefox, twice as slow) so we only do this inversion in IE.
|
12492 | *
|
12493 | * See https://github.com/spicyj/innerhtml-vs-createelement-vs-clonenode.
|
12494 | */
|
12495 | var enableLazy = typeof document !== 'undefined' && typeof document.documentMode === 'number' || typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string' && /\bEdge\/\d/.test(navigator.userAgent);
|
12496 |
|
12497 | function insertTreeChildren(tree) {
|
12498 | if (!enableLazy) {
|
12499 | return;
|
12500 | }
|
12501 | var node = tree.node;
|
12502 | var children = tree.children;
|
12503 | if (children.length) {
|
12504 | for (var i = 0; i < children.length; i++) {
|
12505 | insertTreeBefore(node, children[i], null);
|
12506 | }
|
12507 | } else if (tree.html != null) {
|
12508 | setInnerHTML(node, tree.html);
|
12509 | } else if (tree.text != null) {
|
12510 | setTextContent(node, tree.text);
|
12511 | }
|
12512 | }
|
12513 |
|
12514 | var insertTreeBefore = createMicrosoftUnsafeLocalFunction(function (parentNode, tree, referenceNode) {
|
12515 | // DocumentFragments aren't actually part of the DOM after insertion so
|
12516 | // appending children won't update the DOM. We need to ensure the fragment
|
12517 | // is properly populated first, breaking out of our lazy approach for just
|
12518 | // this level. Also, some <object> plugins (like Flash Player) will read
|
12519 | // <param> nodes immediately upon insertion into the DOM, so <object>
|
12520 | // must also be populated prior to insertion into the DOM.
|
12521 | if (tree.node.nodeType === DOCUMENT_FRAGMENT_NODE_TYPE || tree.node.nodeType === ELEMENT_NODE_TYPE && tree.node.nodeName.toLowerCase() === 'object' && (tree.node.namespaceURI == null || tree.node.namespaceURI === DOMNamespaces.html)) {
|
12522 | insertTreeChildren(tree);
|
12523 | parentNode.insertBefore(tree.node, referenceNode);
|
12524 | } else {
|
12525 | parentNode.insertBefore(tree.node, referenceNode);
|
12526 | insertTreeChildren(tree);
|
12527 | }
|
12528 | });
|
12529 |
|
12530 | function replaceChildWithTree(oldNode, newTree) {
|
12531 | oldNode.parentNode.replaceChild(newTree.node, oldNode);
|
12532 | insertTreeChildren(newTree);
|
12533 | }
|
12534 |
|
12535 | function queueChild(parentTree, childTree) {
|
12536 | if (enableLazy) {
|
12537 | parentTree.children.push(childTree);
|
12538 | } else {
|
12539 | parentTree.node.appendChild(childTree.node);
|
12540 | }
|
12541 | }
|
12542 |
|
12543 | function queueHTML(tree, html) {
|
12544 | if (enableLazy) {
|
12545 | tree.html = html;
|
12546 | } else {
|
12547 | setInnerHTML(tree.node, html);
|
12548 | }
|
12549 | }
|
12550 |
|
12551 | function queueText(tree, text) {
|
12552 | if (enableLazy) {
|
12553 | tree.text = text;
|
12554 | } else {
|
12555 | setTextContent(tree.node, text);
|
12556 | }
|
12557 | }
|
12558 |
|
12559 | function toString() {
|
12560 | return this.node.nodeName;
|
12561 | }
|
12562 |
|
12563 | function DOMLazyTree(node) {
|
12564 | return {
|
12565 | node: node,
|
12566 | children: [],
|
12567 | html: null,
|
12568 | text: null,
|
12569 | toString: toString
|
12570 | };
|
12571 | }
|
12572 |
|
12573 | DOMLazyTree.insertTreeBefore = insertTreeBefore;
|
12574 | DOMLazyTree.replaceChildWithTree = replaceChildWithTree;
|
12575 | DOMLazyTree.queueChild = queueChild;
|
12576 | DOMLazyTree.queueHTML = queueHTML;
|
12577 | DOMLazyTree.queueText = queueText;
|
12578 |
|
12579 | module.exports = DOMLazyTree;
|
12580 | },{"./DOMNamespaces":163,"./createMicrosoftUnsafeLocalFunction":256,"./setInnerHTML":278,"./setTextContent":279}],163:[function(require,module,exports){
|
12581 | /**
|
12582 | * Copyright 2013-present, Facebook, Inc.
|
12583 | * All rights reserved.
|
12584 | *
|
12585 | * This source code is licensed under the BSD-style license found in the
|
12586 | * LICENSE file in the root directory of this source tree. An additional grant
|
12587 | * of patent rights can be found in the PATENTS file in the same directory.
|
12588 | *
|
12589 | */
|
12590 |
|
12591 | 'use strict';
|
12592 |
|
12593 | var DOMNamespaces = {
|
12594 | html: 'http://www.w3.org/1999/xhtml',
|
12595 | mathml: 'http://www.w3.org/1998/Math/MathML',
|
12596 | svg: 'http://www.w3.org/2000/svg'
|
12597 | };
|
12598 |
|
12599 | module.exports = DOMNamespaces;
|
12600 | },{}],164:[function(require,module,exports){
|
12601 | (function (process){
|
12602 | /**
|
12603 | * Copyright 2013-present, Facebook, Inc.
|
12604 | * All rights reserved.
|
12605 | *
|
12606 | * This source code is licensed under the BSD-style license found in the
|
12607 | * LICENSE file in the root directory of this source tree. An additional grant
|
12608 | * of patent rights can be found in the PATENTS file in the same directory.
|
12609 | *
|
12610 | */
|
12611 |
|
12612 | 'use strict';
|
12613 |
|
12614 | var _prodInvariant = require('./reactProdInvariant');
|
12615 |
|
12616 | var invariant = require('fbjs/lib/invariant');
|
12617 |
|
12618 | function checkMask(value, bitmask) {
|
12619 | return (value & bitmask) === bitmask;
|
12620 | }
|
12621 |
|
12622 | var DOMPropertyInjection = {
|
12623 | /**
|
12624 | * Mapping from normalized, camelcased property names to a configuration that
|
12625 | * specifies how the associated DOM property should be accessed or rendered.
|
12626 | */
|
12627 | MUST_USE_PROPERTY: 0x1,
|
12628 | HAS_BOOLEAN_VALUE: 0x4,
|
12629 | HAS_NUMERIC_VALUE: 0x8,
|
12630 | HAS_POSITIVE_NUMERIC_VALUE: 0x10 | 0x8,
|
12631 | HAS_OVERLOADED_BOOLEAN_VALUE: 0x20,
|
12632 |
|
12633 | /**
|
12634 | * Inject some specialized knowledge about the DOM. This takes a config object
|
12635 | * with the following properties:
|
12636 | *
|
12637 | * isCustomAttribute: function that given an attribute name will return true
|
12638 | * if it can be inserted into the DOM verbatim. Useful for data-* or aria-*
|
12639 | * attributes where it's impossible to enumerate all of the possible
|
12640 | * attribute names,
|
12641 | *
|
12642 | * Properties: object mapping DOM property name to one of the
|
12643 | * DOMPropertyInjection constants or null. If your attribute isn't in here,
|
12644 | * it won't get written to the DOM.
|
12645 | *
|
12646 | * DOMAttributeNames: object mapping React attribute name to the DOM
|
12647 | * attribute name. Attribute names not specified use the **lowercase**
|
12648 | * normalized name.
|
12649 | *
|
12650 | * DOMAttributeNamespaces: object mapping React attribute name to the DOM
|
12651 | * attribute namespace URL. (Attribute names not specified use no namespace.)
|
12652 | *
|
12653 | * DOMPropertyNames: similar to DOMAttributeNames but for DOM properties.
|
12654 | * Property names not specified use the normalized name.
|
12655 | *
|
12656 | * DOMMutationMethods: Properties that require special mutation methods. If
|
12657 | * `value` is undefined, the mutation method should unset the property.
|
12658 | *
|
12659 | * @param {object} domPropertyConfig the config as described above.
|
12660 | */
|
12661 | injectDOMPropertyConfig: function (domPropertyConfig) {
|
12662 | var Injection = DOMPropertyInjection;
|
12663 | var Properties = domPropertyConfig.Properties || {};
|
12664 | var DOMAttributeNamespaces = domPropertyConfig.DOMAttributeNamespaces || {};
|
12665 | var DOMAttributeNames = domPropertyConfig.DOMAttributeNames || {};
|
12666 | var DOMPropertyNames = domPropertyConfig.DOMPropertyNames || {};
|
12667 | var DOMMutationMethods = domPropertyConfig.DOMMutationMethods || {};
|
12668 |
|
12669 | if (domPropertyConfig.isCustomAttribute) {
|
12670 | DOMProperty._isCustomAttributeFunctions.push(domPropertyConfig.isCustomAttribute);
|
12671 | }
|
12672 |
|
12673 | for (var propName in Properties) {
|
12674 | !!DOMProperty.properties.hasOwnProperty(propName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'injectDOMPropertyConfig(...): You\'re trying to inject DOM property \'%s\' which has already been injected. You may be accidentally injecting the same DOM property config twice, or you may be injecting two configs that have conflicting property names.', propName) : _prodInvariant('48', propName) : void 0;
|
12675 |
|
12676 | var lowerCased = propName.toLowerCase();
|
12677 | var propConfig = Properties[propName];
|
12678 |
|
12679 | var propertyInfo = {
|
12680 | attributeName: lowerCased,
|
12681 | attributeNamespace: null,
|
12682 | propertyName: propName,
|
12683 | mutationMethod: null,
|
12684 |
|
12685 | mustUseProperty: checkMask(propConfig, Injection.MUST_USE_PROPERTY),
|
12686 | hasBooleanValue: checkMask(propConfig, Injection.HAS_BOOLEAN_VALUE),
|
12687 | hasNumericValue: checkMask(propConfig, Injection.HAS_NUMERIC_VALUE),
|
12688 | hasPositiveNumericValue: checkMask(propConfig, Injection.HAS_POSITIVE_NUMERIC_VALUE),
|
12689 | hasOverloadedBooleanValue: checkMask(propConfig, Injection.HAS_OVERLOADED_BOOLEAN_VALUE)
|
12690 | };
|
12691 | !(propertyInfo.hasBooleanValue + propertyInfo.hasNumericValue + propertyInfo.hasOverloadedBooleanValue <= 1) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'DOMProperty: Value can be one of boolean, overloaded boolean, or numeric value, but not a combination: %s', propName) : _prodInvariant('50', propName) : void 0;
|
12692 |
|
12693 | if (process.env.NODE_ENV !== 'production') {
|
12694 | DOMProperty.getPossibleStandardName[lowerCased] = propName;
|
12695 | }
|
12696 |
|
12697 | if (DOMAttributeNames.hasOwnProperty(propName)) {
|
12698 | var attributeName = DOMAttributeNames[propName];
|
12699 | propertyInfo.attributeName = attributeName;
|
12700 | if (process.env.NODE_ENV !== 'production') {
|
12701 | DOMProperty.getPossibleStandardName[attributeName] = propName;
|
12702 | }
|
12703 | }
|
12704 |
|
12705 | if (DOMAttributeNamespaces.hasOwnProperty(propName)) {
|
12706 | propertyInfo.attributeNamespace = DOMAttributeNamespaces[propName];
|
12707 | }
|
12708 |
|
12709 | if (DOMPropertyNames.hasOwnProperty(propName)) {
|
12710 | propertyInfo.propertyName = DOMPropertyNames[propName];
|
12711 | }
|
12712 |
|
12713 | if (DOMMutationMethods.hasOwnProperty(propName)) {
|
12714 | propertyInfo.mutationMethod = DOMMutationMethods[propName];
|
12715 | }
|
12716 |
|
12717 | DOMProperty.properties[propName] = propertyInfo;
|
12718 | }
|
12719 | }
|
12720 | };
|
12721 |
|
12722 | /* eslint-disable max-len */
|
12723 | var ATTRIBUTE_NAME_START_CHAR = ':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
|
12724 | /* eslint-enable max-len */
|
12725 |
|
12726 | /**
|
12727 | * DOMProperty exports lookup objects that can be used like functions:
|
12728 | *
|
12729 | * > DOMProperty.isValid['id']
|
12730 | * true
|
12731 | * > DOMProperty.isValid['foobar']
|
12732 | * undefined
|
12733 | *
|
12734 | * Although this may be confusing, it performs better in general.
|
12735 | *
|
12736 | * @see http://jsperf.com/key-exists
|
12737 | * @see http://jsperf.com/key-missing
|
12738 | */
|
12739 | var DOMProperty = {
|
12740 |
|
12741 | ID_ATTRIBUTE_NAME: 'data-reactid',
|
12742 | ROOT_ATTRIBUTE_NAME: 'data-reactroot',
|
12743 |
|
12744 | ATTRIBUTE_NAME_START_CHAR: ATTRIBUTE_NAME_START_CHAR,
|
12745 | ATTRIBUTE_NAME_CHAR: ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040',
|
12746 |
|
12747 | /**
|
12748 | * Map from property "standard name" to an object with info about how to set
|
12749 | * the property in the DOM. Each object contains:
|
12750 | *
|
12751 | * attributeName:
|
12752 | * Used when rendering markup or with `*Attribute()`.
|
12753 | * attributeNamespace
|
12754 | * propertyName:
|
12755 | * Used on DOM node instances. (This includes properties that mutate due to
|
12756 | * external factors.)
|
12757 | * mutationMethod:
|
12758 | * If non-null, used instead of the property or `setAttribute()` after
|
12759 | * initial render.
|
12760 | * mustUseProperty:
|
12761 | * Whether the property must be accessed and mutated as an object property.
|
12762 | * hasBooleanValue:
|
12763 | * Whether the property should be removed when set to a falsey value.
|
12764 | * hasNumericValue:
|
12765 | * Whether the property must be numeric or parse as a numeric and should be
|
12766 | * removed when set to a falsey value.
|
12767 | * hasPositiveNumericValue:
|
12768 | * Whether the property must be positive numeric or parse as a positive
|
12769 | * numeric and should be removed when set to a falsey value.
|
12770 | * hasOverloadedBooleanValue:
|
12771 | * Whether the property can be used as a flag as well as with a value.
|
12772 | * Removed when strictly equal to false; present without a value when
|
12773 | * strictly equal to true; present with a value otherwise.
|
12774 | */
|
12775 | properties: {},
|
12776 |
|
12777 | /**
|
12778 | * Mapping from lowercase property names to the properly cased version, used
|
12779 | * to warn in the case of missing properties. Available only in __DEV__.
|
12780 | *
|
12781 | * autofocus is predefined, because adding it to the property whitelist
|
12782 | * causes unintended side effects.
|
12783 | *
|
12784 | * @type {Object}
|
12785 | */
|
12786 | getPossibleStandardName: process.env.NODE_ENV !== 'production' ? { autofocus: 'autoFocus' } : null,
|
12787 |
|
12788 | /**
|
12789 | * All of the isCustomAttribute() functions that have been injected.
|
12790 | */
|
12791 | _isCustomAttributeFunctions: [],
|
12792 |
|
12793 | /**
|
12794 | * Checks whether a property name is a custom attribute.
|
12795 | * @method
|
12796 | */
|
12797 | isCustomAttribute: function (attributeName) {
|
12798 | for (var i = 0; i < DOMProperty._isCustomAttributeFunctions.length; i++) {
|
12799 | var isCustomAttributeFn = DOMProperty._isCustomAttributeFunctions[i];
|
12800 | if (isCustomAttributeFn(attributeName)) {
|
12801 | return true;
|
12802 | }
|
12803 | }
|
12804 | return false;
|
12805 | },
|
12806 |
|
12807 | injection: DOMPropertyInjection
|
12808 | };
|
12809 |
|
12810 | module.exports = DOMProperty;
|
12811 | }).call(this,require('_process'))
|
12812 | },{"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],165:[function(require,module,exports){
|
12813 | (function (process){
|
12814 | /**
|
12815 | * Copyright 2013-present, Facebook, Inc.
|
12816 | * All rights reserved.
|
12817 | *
|
12818 | * This source code is licensed under the BSD-style license found in the
|
12819 | * LICENSE file in the root directory of this source tree. An additional grant
|
12820 | * of patent rights can be found in the PATENTS file in the same directory.
|
12821 | *
|
12822 | */
|
12823 |
|
12824 | 'use strict';
|
12825 |
|
12826 | var DOMProperty = require('./DOMProperty');
|
12827 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
12828 | var ReactInstrumentation = require('./ReactInstrumentation');
|
12829 |
|
12830 | var quoteAttributeValueForBrowser = require('./quoteAttributeValueForBrowser');
|
12831 | var warning = require('fbjs/lib/warning');
|
12832 |
|
12833 | var VALID_ATTRIBUTE_NAME_REGEX = new RegExp('^[' + DOMProperty.ATTRIBUTE_NAME_START_CHAR + '][' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$');
|
12834 | var illegalAttributeNameCache = {};
|
12835 | var validatedAttributeNameCache = {};
|
12836 |
|
12837 | function isAttributeNameSafe(attributeName) {
|
12838 | if (validatedAttributeNameCache.hasOwnProperty(attributeName)) {
|
12839 | return true;
|
12840 | }
|
12841 | if (illegalAttributeNameCache.hasOwnProperty(attributeName)) {
|
12842 | return false;
|
12843 | }
|
12844 | if (VALID_ATTRIBUTE_NAME_REGEX.test(attributeName)) {
|
12845 | validatedAttributeNameCache[attributeName] = true;
|
12846 | return true;
|
12847 | }
|
12848 | illegalAttributeNameCache[attributeName] = true;
|
12849 | process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid attribute name: `%s`', attributeName) : void 0;
|
12850 | return false;
|
12851 | }
|
12852 |
|
12853 | function shouldIgnoreValue(propertyInfo, value) {
|
12854 | return value == null || propertyInfo.hasBooleanValue && !value || propertyInfo.hasNumericValue && isNaN(value) || propertyInfo.hasPositiveNumericValue && value < 1 || propertyInfo.hasOverloadedBooleanValue && value === false;
|
12855 | }
|
12856 |
|
12857 | /**
|
12858 | * Operations for dealing with DOM properties.
|
12859 | */
|
12860 | var DOMPropertyOperations = {
|
12861 |
|
12862 | /**
|
12863 | * Creates markup for the ID property.
|
12864 | *
|
12865 | * @param {string} id Unescaped ID.
|
12866 | * @return {string} Markup string.
|
12867 | */
|
12868 | createMarkupForID: function (id) {
|
12869 | return DOMProperty.ID_ATTRIBUTE_NAME + '=' + quoteAttributeValueForBrowser(id);
|
12870 | },
|
12871 |
|
12872 | setAttributeForID: function (node, id) {
|
12873 | node.setAttribute(DOMProperty.ID_ATTRIBUTE_NAME, id);
|
12874 | },
|
12875 |
|
12876 | createMarkupForRoot: function () {
|
12877 | return DOMProperty.ROOT_ATTRIBUTE_NAME + '=""';
|
12878 | },
|
12879 |
|
12880 | setAttributeForRoot: function (node) {
|
12881 | node.setAttribute(DOMProperty.ROOT_ATTRIBUTE_NAME, '');
|
12882 | },
|
12883 |
|
12884 | /**
|
12885 | * Creates markup for a property.
|
12886 | *
|
12887 | * @param {string} name
|
12888 | * @param {*} value
|
12889 | * @return {?string} Markup string, or null if the property was invalid.
|
12890 | */
|
12891 | createMarkupForProperty: function (name, value) {
|
12892 | var propertyInfo = DOMProperty.properties.hasOwnProperty(name) ? DOMProperty.properties[name] : null;
|
12893 | if (propertyInfo) {
|
12894 | if (shouldIgnoreValue(propertyInfo, value)) {
|
12895 | return '';
|
12896 | }
|
12897 | var attributeName = propertyInfo.attributeName;
|
12898 | if (propertyInfo.hasBooleanValue || propertyInfo.hasOverloadedBooleanValue && value === true) {
|
12899 | return attributeName + '=""';
|
12900 | }
|
12901 | return attributeName + '=' + quoteAttributeValueForBrowser(value);
|
12902 | } else if (DOMProperty.isCustomAttribute(name)) {
|
12903 | if (value == null) {
|
12904 | return '';
|
12905 | }
|
12906 | return name + '=' + quoteAttributeValueForBrowser(value);
|
12907 | }
|
12908 | return null;
|
12909 | },
|
12910 |
|
12911 | /**
|
12912 | * Creates markup for a custom property.
|
12913 | *
|
12914 | * @param {string} name
|
12915 | * @param {*} value
|
12916 | * @return {string} Markup string, or empty string if the property was invalid.
|
12917 | */
|
12918 | createMarkupForCustomAttribute: function (name, value) {
|
12919 | if (!isAttributeNameSafe(name) || value == null) {
|
12920 | return '';
|
12921 | }
|
12922 | return name + '=' + quoteAttributeValueForBrowser(value);
|
12923 | },
|
12924 |
|
12925 | /**
|
12926 | * Sets the value for a property on a node.
|
12927 | *
|
12928 | * @param {DOMElement} node
|
12929 | * @param {string} name
|
12930 | * @param {*} value
|
12931 | */
|
12932 | setValueForProperty: function (node, name, value) {
|
12933 | var propertyInfo = DOMProperty.properties.hasOwnProperty(name) ? DOMProperty.properties[name] : null;
|
12934 | if (propertyInfo) {
|
12935 | var mutationMethod = propertyInfo.mutationMethod;
|
12936 | if (mutationMethod) {
|
12937 | mutationMethod(node, value);
|
12938 | } else if (shouldIgnoreValue(propertyInfo, value)) {
|
12939 | this.deleteValueForProperty(node, name);
|
12940 | return;
|
12941 | } else if (propertyInfo.mustUseProperty) {
|
12942 | // Contrary to `setAttribute`, object properties are properly
|
12943 | // `toString`ed by IE8/9.
|
12944 | node[propertyInfo.propertyName] = value;
|
12945 | } else {
|
12946 | var attributeName = propertyInfo.attributeName;
|
12947 | var namespace = propertyInfo.attributeNamespace;
|
12948 | // `setAttribute` with objects becomes only `[object]` in IE8/9,
|
12949 | // ('' + value) makes it output the correct toString()-value.
|
12950 | if (namespace) {
|
12951 | node.setAttributeNS(namespace, attributeName, '' + value);
|
12952 | } else if (propertyInfo.hasBooleanValue || propertyInfo.hasOverloadedBooleanValue && value === true) {
|
12953 | node.setAttribute(attributeName, '');
|
12954 | } else {
|
12955 | node.setAttribute(attributeName, '' + value);
|
12956 | }
|
12957 | }
|
12958 | } else if (DOMProperty.isCustomAttribute(name)) {
|
12959 | DOMPropertyOperations.setValueForAttribute(node, name, value);
|
12960 | return;
|
12961 | }
|
12962 |
|
12963 | if (process.env.NODE_ENV !== 'production') {
|
12964 | var payload = {};
|
12965 | payload[name] = value;
|
12966 | ReactInstrumentation.debugTool.onHostOperation({
|
12967 | instanceID: ReactDOMComponentTree.getInstanceFromNode(node)._debugID,
|
12968 | type: 'update attribute',
|
12969 | payload: payload
|
12970 | });
|
12971 | }
|
12972 | },
|
12973 |
|
12974 | setValueForAttribute: function (node, name, value) {
|
12975 | if (!isAttributeNameSafe(name)) {
|
12976 | return;
|
12977 | }
|
12978 | if (value == null) {
|
12979 | node.removeAttribute(name);
|
12980 | } else {
|
12981 | node.setAttribute(name, '' + value);
|
12982 | }
|
12983 |
|
12984 | if (process.env.NODE_ENV !== 'production') {
|
12985 | var payload = {};
|
12986 | payload[name] = value;
|
12987 | ReactInstrumentation.debugTool.onHostOperation({
|
12988 | instanceID: ReactDOMComponentTree.getInstanceFromNode(node)._debugID,
|
12989 | type: 'update attribute',
|
12990 | payload: payload
|
12991 | });
|
12992 | }
|
12993 | },
|
12994 |
|
12995 | /**
|
12996 | * Deletes an attributes from a node.
|
12997 | *
|
12998 | * @param {DOMElement} node
|
12999 | * @param {string} name
|
13000 | */
|
13001 | deleteValueForAttribute: function (node, name) {
|
13002 | node.removeAttribute(name);
|
13003 | if (process.env.NODE_ENV !== 'production') {
|
13004 | ReactInstrumentation.debugTool.onHostOperation({
|
13005 | instanceID: ReactDOMComponentTree.getInstanceFromNode(node)._debugID,
|
13006 | type: 'remove attribute',
|
13007 | payload: name
|
13008 | });
|
13009 | }
|
13010 | },
|
13011 |
|
13012 | /**
|
13013 | * Deletes the value for a property on a node.
|
13014 | *
|
13015 | * @param {DOMElement} node
|
13016 | * @param {string} name
|
13017 | */
|
13018 | deleteValueForProperty: function (node, name) {
|
13019 | var propertyInfo = DOMProperty.properties.hasOwnProperty(name) ? DOMProperty.properties[name] : null;
|
13020 | if (propertyInfo) {
|
13021 | var mutationMethod = propertyInfo.mutationMethod;
|
13022 | if (mutationMethod) {
|
13023 | mutationMethod(node, undefined);
|
13024 | } else if (propertyInfo.mustUseProperty) {
|
13025 | var propName = propertyInfo.propertyName;
|
13026 | if (propertyInfo.hasBooleanValue) {
|
13027 | node[propName] = false;
|
13028 | } else {
|
13029 | node[propName] = '';
|
13030 | }
|
13031 | } else {
|
13032 | node.removeAttribute(propertyInfo.attributeName);
|
13033 | }
|
13034 | } else if (DOMProperty.isCustomAttribute(name)) {
|
13035 | node.removeAttribute(name);
|
13036 | }
|
13037 |
|
13038 | if (process.env.NODE_ENV !== 'production') {
|
13039 | ReactInstrumentation.debugTool.onHostOperation({
|
13040 | instanceID: ReactDOMComponentTree.getInstanceFromNode(node)._debugID,
|
13041 | type: 'remove attribute',
|
13042 | payload: name
|
13043 | });
|
13044 | }
|
13045 | }
|
13046 |
|
13047 | };
|
13048 |
|
13049 | module.exports = DOMPropertyOperations;
|
13050 | }).call(this,require('_process'))
|
13051 | },{"./DOMProperty":164,"./ReactDOMComponentTree":186,"./ReactInstrumentation":216,"./quoteAttributeValueForBrowser":275,"_process":144,"fbjs/lib/warning":131}],166:[function(require,module,exports){
|
13052 | (function (process){
|
13053 | /**
|
13054 | * Copyright 2013-present, Facebook, Inc.
|
13055 | * All rights reserved.
|
13056 | *
|
13057 | * This source code is licensed under the BSD-style license found in the
|
13058 | * LICENSE file in the root directory of this source tree. An additional grant
|
13059 | * of patent rights can be found in the PATENTS file in the same directory.
|
13060 | *
|
13061 | */
|
13062 |
|
13063 | 'use strict';
|
13064 |
|
13065 | var _prodInvariant = require('./reactProdInvariant');
|
13066 |
|
13067 | var DOMLazyTree = require('./DOMLazyTree');
|
13068 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
13069 |
|
13070 | var createNodesFromMarkup = require('fbjs/lib/createNodesFromMarkup');
|
13071 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
13072 | var invariant = require('fbjs/lib/invariant');
|
13073 |
|
13074 | var Danger = {
|
13075 |
|
13076 | /**
|
13077 | * Replaces a node with a string of markup at its current position within its
|
13078 | * parent. The markup must render into a single root node.
|
13079 | *
|
13080 | * @param {DOMElement} oldChild Child node to replace.
|
13081 | * @param {string} markup Markup to render in place of the child node.
|
13082 | * @internal
|
13083 | */
|
13084 | dangerouslyReplaceNodeWithMarkup: function (oldChild, markup) {
|
13085 | !ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? invariant(false, 'dangerouslyReplaceNodeWithMarkup(...): Cannot render markup in a worker thread. Make sure `window` and `document` are available globally before requiring React when unit testing or use ReactDOMServer.renderToString() for server rendering.') : _prodInvariant('56') : void 0;
|
13086 | !markup ? process.env.NODE_ENV !== 'production' ? invariant(false, 'dangerouslyReplaceNodeWithMarkup(...): Missing markup.') : _prodInvariant('57') : void 0;
|
13087 | !(oldChild.nodeName !== 'HTML') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'dangerouslyReplaceNodeWithMarkup(...): Cannot replace markup of the <html> node. This is because browser quirks make this unreliable and/or slow. If you want to render to the root you must use server rendering. See ReactDOMServer.renderToString().') : _prodInvariant('58') : void 0;
|
13088 |
|
13089 | if (typeof markup === 'string') {
|
13090 | var newChild = createNodesFromMarkup(markup, emptyFunction)[0];
|
13091 | oldChild.parentNode.replaceChild(newChild, oldChild);
|
13092 | } else {
|
13093 | DOMLazyTree.replaceChildWithTree(oldChild, markup);
|
13094 | }
|
13095 | }
|
13096 |
|
13097 | };
|
13098 |
|
13099 | module.exports = Danger;
|
13100 | }).call(this,require('_process'))
|
13101 | },{"./DOMLazyTree":162,"./reactProdInvariant":276,"_process":144,"fbjs/lib/ExecutionEnvironment":110,"fbjs/lib/createNodesFromMarkup":115,"fbjs/lib/emptyFunction":116,"fbjs/lib/invariant":124}],167:[function(require,module,exports){
|
13102 | /**
|
13103 | * Copyright 2013-present, Facebook, Inc.
|
13104 | * All rights reserved.
|
13105 | *
|
13106 | * This source code is licensed under the BSD-style license found in the
|
13107 | * LICENSE file in the root directory of this source tree. An additional grant
|
13108 | * of patent rights can be found in the PATENTS file in the same directory.
|
13109 | *
|
13110 | */
|
13111 |
|
13112 | 'use strict';
|
13113 |
|
13114 | /**
|
13115 | * Module that is injectable into `EventPluginHub`, that specifies a
|
13116 | * deterministic ordering of `EventPlugin`s. A convenient way to reason about
|
13117 | * plugins, without having to package every one of them. This is better than
|
13118 | * having plugins be ordered in the same order that they are injected because
|
13119 | * that ordering would be influenced by the packaging order.
|
13120 | * `ResponderEventPlugin` must occur before `SimpleEventPlugin` so that
|
13121 | * preventing default on events is convenient in `SimpleEventPlugin` handlers.
|
13122 | */
|
13123 |
|
13124 | var DefaultEventPluginOrder = ['ResponderEventPlugin', 'SimpleEventPlugin', 'TapEventPlugin', 'EnterLeaveEventPlugin', 'ChangeEventPlugin', 'SelectEventPlugin', 'BeforeInputEventPlugin'];
|
13125 |
|
13126 | module.exports = DefaultEventPluginOrder;
|
13127 | },{}],168:[function(require,module,exports){
|
13128 | /**
|
13129 | * Copyright 2013-present, Facebook, Inc.
|
13130 | * All rights reserved.
|
13131 | *
|
13132 | * This source code is licensed under the BSD-style license found in the
|
13133 | * LICENSE file in the root directory of this source tree. An additional grant
|
13134 | * of patent rights can be found in the PATENTS file in the same directory.
|
13135 | *
|
13136 | */
|
13137 |
|
13138 | 'use strict';
|
13139 |
|
13140 | var EventPropagators = require('./EventPropagators');
|
13141 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
13142 | var SyntheticMouseEvent = require('./SyntheticMouseEvent');
|
13143 |
|
13144 | var eventTypes = {
|
13145 | mouseEnter: {
|
13146 | registrationName: 'onMouseEnter',
|
13147 | dependencies: ['topMouseOut', 'topMouseOver']
|
13148 | },
|
13149 | mouseLeave: {
|
13150 | registrationName: 'onMouseLeave',
|
13151 | dependencies: ['topMouseOut', 'topMouseOver']
|
13152 | }
|
13153 | };
|
13154 |
|
13155 | var EnterLeaveEventPlugin = {
|
13156 |
|
13157 | eventTypes: eventTypes,
|
13158 |
|
13159 | /**
|
13160 | * For almost every interaction we care about, there will be both a top-level
|
13161 | * `mouseover` and `mouseout` event that occurs. Only use `mouseout` so that
|
13162 | * we do not extract duplicate events. However, moving the mouse into the
|
13163 | * browser from outside will not fire a `mouseout` event. In this case, we use
|
13164 | * the `mouseover` top-level event.
|
13165 | */
|
13166 | extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
|
13167 | if (topLevelType === 'topMouseOver' && (nativeEvent.relatedTarget || nativeEvent.fromElement)) {
|
13168 | return null;
|
13169 | }
|
13170 | if (topLevelType !== 'topMouseOut' && topLevelType !== 'topMouseOver') {
|
13171 | // Must not be a mouse in or mouse out - ignoring.
|
13172 | return null;
|
13173 | }
|
13174 |
|
13175 | var win;
|
13176 | if (nativeEventTarget.window === nativeEventTarget) {
|
13177 | // `nativeEventTarget` is probably a window object.
|
13178 | win = nativeEventTarget;
|
13179 | } else {
|
13180 | // TODO: Figure out why `ownerDocument` is sometimes undefined in IE8.
|
13181 | var doc = nativeEventTarget.ownerDocument;
|
13182 | if (doc) {
|
13183 | win = doc.defaultView || doc.parentWindow;
|
13184 | } else {
|
13185 | win = window;
|
13186 | }
|
13187 | }
|
13188 |
|
13189 | var from;
|
13190 | var to;
|
13191 | if (topLevelType === 'topMouseOut') {
|
13192 | from = targetInst;
|
13193 | var related = nativeEvent.relatedTarget || nativeEvent.toElement;
|
13194 | to = related ? ReactDOMComponentTree.getClosestInstanceFromNode(related) : null;
|
13195 | } else {
|
13196 | // Moving to a node from outside the window.
|
13197 | from = null;
|
13198 | to = targetInst;
|
13199 | }
|
13200 |
|
13201 | if (from === to) {
|
13202 | // Nothing pertains to our managed components.
|
13203 | return null;
|
13204 | }
|
13205 |
|
13206 | var fromNode = from == null ? win : ReactDOMComponentTree.getNodeFromInstance(from);
|
13207 | var toNode = to == null ? win : ReactDOMComponentTree.getNodeFromInstance(to);
|
13208 |
|
13209 | var leave = SyntheticMouseEvent.getPooled(eventTypes.mouseLeave, from, nativeEvent, nativeEventTarget);
|
13210 | leave.type = 'mouseleave';
|
13211 | leave.target = fromNode;
|
13212 | leave.relatedTarget = toNode;
|
13213 |
|
13214 | var enter = SyntheticMouseEvent.getPooled(eventTypes.mouseEnter, to, nativeEvent, nativeEventTarget);
|
13215 | enter.type = 'mouseenter';
|
13216 | enter.target = toNode;
|
13217 | enter.relatedTarget = fromNode;
|
13218 |
|
13219 | EventPropagators.accumulateEnterLeaveDispatches(leave, enter, from, to);
|
13220 |
|
13221 | return [leave, enter];
|
13222 | }
|
13223 |
|
13224 | };
|
13225 |
|
13226 | module.exports = EnterLeaveEventPlugin;
|
13227 | },{"./EventPropagators":172,"./ReactDOMComponentTree":186,"./SyntheticMouseEvent":246}],169:[function(require,module,exports){
|
13228 | (function (process){
|
13229 | /**
|
13230 | * Copyright 2013-present, Facebook, Inc.
|
13231 | * All rights reserved.
|
13232 | *
|
13233 | * This source code is licensed under the BSD-style license found in the
|
13234 | * LICENSE file in the root directory of this source tree. An additional grant
|
13235 | * of patent rights can be found in the PATENTS file in the same directory.
|
13236 | *
|
13237 | */
|
13238 |
|
13239 | 'use strict';
|
13240 |
|
13241 | var _prodInvariant = require('./reactProdInvariant');
|
13242 |
|
13243 | var EventPluginRegistry = require('./EventPluginRegistry');
|
13244 | var EventPluginUtils = require('./EventPluginUtils');
|
13245 | var ReactErrorUtils = require('./ReactErrorUtils');
|
13246 |
|
13247 | var accumulateInto = require('./accumulateInto');
|
13248 | var forEachAccumulated = require('./forEachAccumulated');
|
13249 | var invariant = require('fbjs/lib/invariant');
|
13250 |
|
13251 | /**
|
13252 | * Internal store for event listeners
|
13253 | */
|
13254 | var listenerBank = {};
|
13255 |
|
13256 | /**
|
13257 | * Internal queue of events that have accumulated their dispatches and are
|
13258 | * waiting to have their dispatches executed.
|
13259 | */
|
13260 | var eventQueue = null;
|
13261 |
|
13262 | /**
|
13263 | * Dispatches an event and releases it back into the pool, unless persistent.
|
13264 | *
|
13265 | * @param {?object} event Synthetic event to be dispatched.
|
13266 | * @param {boolean} simulated If the event is simulated (changes exn behavior)
|
13267 | * @private
|
13268 | */
|
13269 | var executeDispatchesAndRelease = function (event, simulated) {
|
13270 | if (event) {
|
13271 | EventPluginUtils.executeDispatchesInOrder(event, simulated);
|
13272 |
|
13273 | if (!event.isPersistent()) {
|
13274 | event.constructor.release(event);
|
13275 | }
|
13276 | }
|
13277 | };
|
13278 | var executeDispatchesAndReleaseSimulated = function (e) {
|
13279 | return executeDispatchesAndRelease(e, true);
|
13280 | };
|
13281 | var executeDispatchesAndReleaseTopLevel = function (e) {
|
13282 | return executeDispatchesAndRelease(e, false);
|
13283 | };
|
13284 |
|
13285 | var getDictionaryKey = function (inst) {
|
13286 | // Prevents V8 performance issue:
|
13287 | // https://github.com/facebook/react/pull/7232
|
13288 | return '.' + inst._rootNodeID;
|
13289 | };
|
13290 |
|
13291 | function isInteractive(tag) {
|
13292 | return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
|
13293 | }
|
13294 |
|
13295 | function shouldPreventMouseEvent(name, type, props) {
|
13296 | switch (name) {
|
13297 | case 'onClick':
|
13298 | case 'onClickCapture':
|
13299 | case 'onDoubleClick':
|
13300 | case 'onDoubleClickCapture':
|
13301 | case 'onMouseDown':
|
13302 | case 'onMouseDownCapture':
|
13303 | case 'onMouseMove':
|
13304 | case 'onMouseMoveCapture':
|
13305 | case 'onMouseUp':
|
13306 | case 'onMouseUpCapture':
|
13307 | return !!(props.disabled && isInteractive(type));
|
13308 | default:
|
13309 | return false;
|
13310 | }
|
13311 | }
|
13312 |
|
13313 | /**
|
13314 | * This is a unified interface for event plugins to be installed and configured.
|
13315 | *
|
13316 | * Event plugins can implement the following properties:
|
13317 | *
|
13318 | * `extractEvents` {function(string, DOMEventTarget, string, object): *}
|
13319 | * Required. When a top-level event is fired, this method is expected to
|
13320 | * extract synthetic events that will in turn be queued and dispatched.
|
13321 | *
|
13322 | * `eventTypes` {object}
|
13323 | * Optional, plugins that fire events must publish a mapping of registration
|
13324 | * names that are used to register listeners. Values of this mapping must
|
13325 | * be objects that contain `registrationName` or `phasedRegistrationNames`.
|
13326 | *
|
13327 | * `executeDispatch` {function(object, function, string)}
|
13328 | * Optional, allows plugins to override how an event gets dispatched. By
|
13329 | * default, the listener is simply invoked.
|
13330 | *
|
13331 | * Each plugin that is injected into `EventsPluginHub` is immediately operable.
|
13332 | *
|
13333 | * @public
|
13334 | */
|
13335 | var EventPluginHub = {
|
13336 |
|
13337 | /**
|
13338 | * Methods for injecting dependencies.
|
13339 | */
|
13340 | injection: {
|
13341 |
|
13342 | /**
|
13343 | * @param {array} InjectedEventPluginOrder
|
13344 | * @public
|
13345 | */
|
13346 | injectEventPluginOrder: EventPluginRegistry.injectEventPluginOrder,
|
13347 |
|
13348 | /**
|
13349 | * @param {object} injectedNamesToPlugins Map from names to plugin modules.
|
13350 | */
|
13351 | injectEventPluginsByName: EventPluginRegistry.injectEventPluginsByName
|
13352 |
|
13353 | },
|
13354 |
|
13355 | /**
|
13356 | * Stores `listener` at `listenerBank[registrationName][key]`. Is idempotent.
|
13357 | *
|
13358 | * @param {object} inst The instance, which is the source of events.
|
13359 | * @param {string} registrationName Name of listener (e.g. `onClick`).
|
13360 | * @param {function} listener The callback to store.
|
13361 | */
|
13362 | putListener: function (inst, registrationName, listener) {
|
13363 | !(typeof listener === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Expected %s listener to be a function, instead got type %s', registrationName, typeof listener) : _prodInvariant('94', registrationName, typeof listener) : void 0;
|
13364 |
|
13365 | var key = getDictionaryKey(inst);
|
13366 | var bankForRegistrationName = listenerBank[registrationName] || (listenerBank[registrationName] = {});
|
13367 | bankForRegistrationName[key] = listener;
|
13368 |
|
13369 | var PluginModule = EventPluginRegistry.registrationNameModules[registrationName];
|
13370 | if (PluginModule && PluginModule.didPutListener) {
|
13371 | PluginModule.didPutListener(inst, registrationName, listener);
|
13372 | }
|
13373 | },
|
13374 |
|
13375 | /**
|
13376 | * @param {object} inst The instance, which is the source of events.
|
13377 | * @param {string} registrationName Name of listener (e.g. `onClick`).
|
13378 | * @return {?function} The stored callback.
|
13379 | */
|
13380 | getListener: function (inst, registrationName) {
|
13381 | // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
|
13382 | // live here; needs to be moved to a better place soon
|
13383 | var bankForRegistrationName = listenerBank[registrationName];
|
13384 | if (shouldPreventMouseEvent(registrationName, inst._currentElement.type, inst._currentElement.props)) {
|
13385 | return null;
|
13386 | }
|
13387 | var key = getDictionaryKey(inst);
|
13388 | return bankForRegistrationName && bankForRegistrationName[key];
|
13389 | },
|
13390 |
|
13391 | /**
|
13392 | * Deletes a listener from the registration bank.
|
13393 | *
|
13394 | * @param {object} inst The instance, which is the source of events.
|
13395 | * @param {string} registrationName Name of listener (e.g. `onClick`).
|
13396 | */
|
13397 | deleteListener: function (inst, registrationName) {
|
13398 | var PluginModule = EventPluginRegistry.registrationNameModules[registrationName];
|
13399 | if (PluginModule && PluginModule.willDeleteListener) {
|
13400 | PluginModule.willDeleteListener(inst, registrationName);
|
13401 | }
|
13402 |
|
13403 | var bankForRegistrationName = listenerBank[registrationName];
|
13404 | // TODO: This should never be null -- when is it?
|
13405 | if (bankForRegistrationName) {
|
13406 | var key = getDictionaryKey(inst);
|
13407 | delete bankForRegistrationName[key];
|
13408 | }
|
13409 | },
|
13410 |
|
13411 | /**
|
13412 | * Deletes all listeners for the DOM element with the supplied ID.
|
13413 | *
|
13414 | * @param {object} inst The instance, which is the source of events.
|
13415 | */
|
13416 | deleteAllListeners: function (inst) {
|
13417 | var key = getDictionaryKey(inst);
|
13418 | for (var registrationName in listenerBank) {
|
13419 | if (!listenerBank.hasOwnProperty(registrationName)) {
|
13420 | continue;
|
13421 | }
|
13422 |
|
13423 | if (!listenerBank[registrationName][key]) {
|
13424 | continue;
|
13425 | }
|
13426 |
|
13427 | var PluginModule = EventPluginRegistry.registrationNameModules[registrationName];
|
13428 | if (PluginModule && PluginModule.willDeleteListener) {
|
13429 | PluginModule.willDeleteListener(inst, registrationName);
|
13430 | }
|
13431 |
|
13432 | delete listenerBank[registrationName][key];
|
13433 | }
|
13434 | },
|
13435 |
|
13436 | /**
|
13437 | * Allows registered plugins an opportunity to extract events from top-level
|
13438 | * native browser events.
|
13439 | *
|
13440 | * @return {*} An accumulation of synthetic events.
|
13441 | * @internal
|
13442 | */
|
13443 | extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
|
13444 | var events;
|
13445 | var plugins = EventPluginRegistry.plugins;
|
13446 | for (var i = 0; i < plugins.length; i++) {
|
13447 | // Not every plugin in the ordering may be loaded at runtime.
|
13448 | var possiblePlugin = plugins[i];
|
13449 | if (possiblePlugin) {
|
13450 | var extractedEvents = possiblePlugin.extractEvents(topLevelType, targetInst, nativeEvent, nativeEventTarget);
|
13451 | if (extractedEvents) {
|
13452 | events = accumulateInto(events, extractedEvents);
|
13453 | }
|
13454 | }
|
13455 | }
|
13456 | return events;
|
13457 | },
|
13458 |
|
13459 | /**
|
13460 | * Enqueues a synthetic event that should be dispatched when
|
13461 | * `processEventQueue` is invoked.
|
13462 | *
|
13463 | * @param {*} events An accumulation of synthetic events.
|
13464 | * @internal
|
13465 | */
|
13466 | enqueueEvents: function (events) {
|
13467 | if (events) {
|
13468 | eventQueue = accumulateInto(eventQueue, events);
|
13469 | }
|
13470 | },
|
13471 |
|
13472 | /**
|
13473 | * Dispatches all synthetic events on the event queue.
|
13474 | *
|
13475 | * @internal
|
13476 | */
|
13477 | processEventQueue: function (simulated) {
|
13478 | // Set `eventQueue` to null before processing it so that we can tell if more
|
13479 | // events get enqueued while processing.
|
13480 | var processingEventQueue = eventQueue;
|
13481 | eventQueue = null;
|
13482 | if (simulated) {
|
13483 | forEachAccumulated(processingEventQueue, executeDispatchesAndReleaseSimulated);
|
13484 | } else {
|
13485 | forEachAccumulated(processingEventQueue, executeDispatchesAndReleaseTopLevel);
|
13486 | }
|
13487 | !!eventQueue ? process.env.NODE_ENV !== 'production' ? invariant(false, 'processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented.') : _prodInvariant('95') : void 0;
|
13488 | // This would be a good time to rethrow if any of the event handlers threw.
|
13489 | ReactErrorUtils.rethrowCaughtError();
|
13490 | },
|
13491 |
|
13492 | /**
|
13493 | * These are needed for tests only. Do not use!
|
13494 | */
|
13495 | __purge: function () {
|
13496 | listenerBank = {};
|
13497 | },
|
13498 |
|
13499 | __getListenerBank: function () {
|
13500 | return listenerBank;
|
13501 | }
|
13502 |
|
13503 | };
|
13504 |
|
13505 | module.exports = EventPluginHub;
|
13506 | }).call(this,require('_process'))
|
13507 | },{"./EventPluginRegistry":170,"./EventPluginUtils":171,"./ReactErrorUtils":207,"./accumulateInto":253,"./forEachAccumulated":261,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],170:[function(require,module,exports){
|
13508 | (function (process){
|
13509 | /**
|
13510 | * Copyright 2013-present, Facebook, Inc.
|
13511 | * All rights reserved.
|
13512 | *
|
13513 | * This source code is licensed under the BSD-style license found in the
|
13514 | * LICENSE file in the root directory of this source tree. An additional grant
|
13515 | * of patent rights can be found in the PATENTS file in the same directory.
|
13516 | *
|
13517 | *
|
13518 | */
|
13519 |
|
13520 | 'use strict';
|
13521 |
|
13522 | var _prodInvariant = require('./reactProdInvariant');
|
13523 |
|
13524 | var invariant = require('fbjs/lib/invariant');
|
13525 |
|
13526 | /**
|
13527 | * Injectable ordering of event plugins.
|
13528 | */
|
13529 | var eventPluginOrder = null;
|
13530 |
|
13531 | /**
|
13532 | * Injectable mapping from names to event plugin modules.
|
13533 | */
|
13534 | var namesToPlugins = {};
|
13535 |
|
13536 | /**
|
13537 | * Recomputes the plugin list using the injected plugins and plugin ordering.
|
13538 | *
|
13539 | * @private
|
13540 | */
|
13541 | function recomputePluginOrdering() {
|
13542 | if (!eventPluginOrder) {
|
13543 | // Wait until an `eventPluginOrder` is injected.
|
13544 | return;
|
13545 | }
|
13546 | for (var pluginName in namesToPlugins) {
|
13547 | var pluginModule = namesToPlugins[pluginName];
|
13548 | var pluginIndex = eventPluginOrder.indexOf(pluginName);
|
13549 | !(pluginIndex > -1) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `%s`.', pluginName) : _prodInvariant('96', pluginName) : void 0;
|
13550 | if (EventPluginRegistry.plugins[pluginIndex]) {
|
13551 | continue;
|
13552 | }
|
13553 | !pluginModule.extractEvents ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `%s` does not.', pluginName) : _prodInvariant('97', pluginName) : void 0;
|
13554 | EventPluginRegistry.plugins[pluginIndex] = pluginModule;
|
13555 | var publishedEvents = pluginModule.eventTypes;
|
13556 | for (var eventName in publishedEvents) {
|
13557 | !publishEventForPlugin(publishedEvents[eventName], pluginModule, eventName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.', eventName, pluginName) : _prodInvariant('98', eventName, pluginName) : void 0;
|
13558 | }
|
13559 | }
|
13560 | }
|
13561 |
|
13562 | /**
|
13563 | * Publishes an event so that it can be dispatched by the supplied plugin.
|
13564 | *
|
13565 | * @param {object} dispatchConfig Dispatch configuration for the event.
|
13566 | * @param {object} PluginModule Plugin publishing the event.
|
13567 | * @return {boolean} True if the event was successfully published.
|
13568 | * @private
|
13569 | */
|
13570 | function publishEventForPlugin(dispatchConfig, pluginModule, eventName) {
|
13571 | !!EventPluginRegistry.eventNameDispatchConfigs.hasOwnProperty(eventName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginHub: More than one plugin attempted to publish the same event name, `%s`.', eventName) : _prodInvariant('99', eventName) : void 0;
|
13572 | EventPluginRegistry.eventNameDispatchConfigs[eventName] = dispatchConfig;
|
13573 |
|
13574 | var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
|
13575 | if (phasedRegistrationNames) {
|
13576 | for (var phaseName in phasedRegistrationNames) {
|
13577 | if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
|
13578 | var phasedRegistrationName = phasedRegistrationNames[phaseName];
|
13579 | publishRegistrationName(phasedRegistrationName, pluginModule, eventName);
|
13580 | }
|
13581 | }
|
13582 | return true;
|
13583 | } else if (dispatchConfig.registrationName) {
|
13584 | publishRegistrationName(dispatchConfig.registrationName, pluginModule, eventName);
|
13585 | return true;
|
13586 | }
|
13587 | return false;
|
13588 | }
|
13589 |
|
13590 | /**
|
13591 | * Publishes a registration name that is used to identify dispatched events and
|
13592 | * can be used with `EventPluginHub.putListener` to register listeners.
|
13593 | *
|
13594 | * @param {string} registrationName Registration name to add.
|
13595 | * @param {object} PluginModule Plugin publishing the event.
|
13596 | * @private
|
13597 | */
|
13598 | function publishRegistrationName(registrationName, pluginModule, eventName) {
|
13599 | !!EventPluginRegistry.registrationNameModules[registrationName] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginHub: More than one plugin attempted to publish the same registration name, `%s`.', registrationName) : _prodInvariant('100', registrationName) : void 0;
|
13600 | EventPluginRegistry.registrationNameModules[registrationName] = pluginModule;
|
13601 | EventPluginRegistry.registrationNameDependencies[registrationName] = pluginModule.eventTypes[eventName].dependencies;
|
13602 |
|
13603 | if (process.env.NODE_ENV !== 'production') {
|
13604 | var lowerCasedName = registrationName.toLowerCase();
|
13605 | EventPluginRegistry.possibleRegistrationNames[lowerCasedName] = registrationName;
|
13606 |
|
13607 | if (registrationName === 'onDoubleClick') {
|
13608 | EventPluginRegistry.possibleRegistrationNames.ondblclick = registrationName;
|
13609 | }
|
13610 | }
|
13611 | }
|
13612 |
|
13613 | /**
|
13614 | * Registers plugins so that they can extract and dispatch events.
|
13615 | *
|
13616 | * @see {EventPluginHub}
|
13617 | */
|
13618 | var EventPluginRegistry = {
|
13619 |
|
13620 | /**
|
13621 | * Ordered list of injected plugins.
|
13622 | */
|
13623 | plugins: [],
|
13624 |
|
13625 | /**
|
13626 | * Mapping from event name to dispatch config
|
13627 | */
|
13628 | eventNameDispatchConfigs: {},
|
13629 |
|
13630 | /**
|
13631 | * Mapping from registration name to plugin module
|
13632 | */
|
13633 | registrationNameModules: {},
|
13634 |
|
13635 | /**
|
13636 | * Mapping from registration name to event name
|
13637 | */
|
13638 | registrationNameDependencies: {},
|
13639 |
|
13640 | /**
|
13641 | * Mapping from lowercase registration names to the properly cased version,
|
13642 | * used to warn in the case of missing event handlers. Available
|
13643 | * only in __DEV__.
|
13644 | * @type {Object}
|
13645 | */
|
13646 | possibleRegistrationNames: process.env.NODE_ENV !== 'production' ? {} : null,
|
13647 | // Trust the developer to only use possibleRegistrationNames in __DEV__
|
13648 |
|
13649 | /**
|
13650 | * Injects an ordering of plugins (by plugin name). This allows the ordering
|
13651 | * to be decoupled from injection of the actual plugins so that ordering is
|
13652 | * always deterministic regardless of packaging, on-the-fly injection, etc.
|
13653 | *
|
13654 | * @param {array} InjectedEventPluginOrder
|
13655 | * @internal
|
13656 | * @see {EventPluginHub.injection.injectEventPluginOrder}
|
13657 | */
|
13658 | injectEventPluginOrder: function (injectedEventPluginOrder) {
|
13659 | !!eventPluginOrder ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React.') : _prodInvariant('101') : void 0;
|
13660 | // Clone the ordering so it cannot be dynamically mutated.
|
13661 | eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
|
13662 | recomputePluginOrdering();
|
13663 | },
|
13664 |
|
13665 | /**
|
13666 | * Injects plugins to be used by `EventPluginHub`. The plugin names must be
|
13667 | * in the ordering injected by `injectEventPluginOrder`.
|
13668 | *
|
13669 | * Plugins can be injected as part of page initialization or on-the-fly.
|
13670 | *
|
13671 | * @param {object} injectedNamesToPlugins Map from names to plugin modules.
|
13672 | * @internal
|
13673 | * @see {EventPluginHub.injection.injectEventPluginsByName}
|
13674 | */
|
13675 | injectEventPluginsByName: function (injectedNamesToPlugins) {
|
13676 | var isOrderingDirty = false;
|
13677 | for (var pluginName in injectedNamesToPlugins) {
|
13678 | if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
|
13679 | continue;
|
13680 | }
|
13681 | var pluginModule = injectedNamesToPlugins[pluginName];
|
13682 | if (!namesToPlugins.hasOwnProperty(pluginName) || namesToPlugins[pluginName] !== pluginModule) {
|
13683 | !!namesToPlugins[pluginName] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Cannot inject two different event plugins using the same name, `%s`.', pluginName) : _prodInvariant('102', pluginName) : void 0;
|
13684 | namesToPlugins[pluginName] = pluginModule;
|
13685 | isOrderingDirty = true;
|
13686 | }
|
13687 | }
|
13688 | if (isOrderingDirty) {
|
13689 | recomputePluginOrdering();
|
13690 | }
|
13691 | },
|
13692 |
|
13693 | /**
|
13694 | * Looks up the plugin for the supplied event.
|
13695 | *
|
13696 | * @param {object} event A synthetic event.
|
13697 | * @return {?object} The plugin that created the supplied event.
|
13698 | * @internal
|
13699 | */
|
13700 | getPluginModuleForEvent: function (event) {
|
13701 | var dispatchConfig = event.dispatchConfig;
|
13702 | if (dispatchConfig.registrationName) {
|
13703 | return EventPluginRegistry.registrationNameModules[dispatchConfig.registrationName] || null;
|
13704 | }
|
13705 | if (dispatchConfig.phasedRegistrationNames !== undefined) {
|
13706 | // pulling phasedRegistrationNames out of dispatchConfig helps Flow see
|
13707 | // that it is not undefined.
|
13708 | var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
|
13709 |
|
13710 | for (var phase in phasedRegistrationNames) {
|
13711 | if (!phasedRegistrationNames.hasOwnProperty(phase)) {
|
13712 | continue;
|
13713 | }
|
13714 | var pluginModule = EventPluginRegistry.registrationNameModules[phasedRegistrationNames[phase]];
|
13715 | if (pluginModule) {
|
13716 | return pluginModule;
|
13717 | }
|
13718 | }
|
13719 | }
|
13720 | return null;
|
13721 | },
|
13722 |
|
13723 | /**
|
13724 | * Exposed for unit testing.
|
13725 | * @private
|
13726 | */
|
13727 | _resetEventPlugins: function () {
|
13728 | eventPluginOrder = null;
|
13729 | for (var pluginName in namesToPlugins) {
|
13730 | if (namesToPlugins.hasOwnProperty(pluginName)) {
|
13731 | delete namesToPlugins[pluginName];
|
13732 | }
|
13733 | }
|
13734 | EventPluginRegistry.plugins.length = 0;
|
13735 |
|
13736 | var eventNameDispatchConfigs = EventPluginRegistry.eventNameDispatchConfigs;
|
13737 | for (var eventName in eventNameDispatchConfigs) {
|
13738 | if (eventNameDispatchConfigs.hasOwnProperty(eventName)) {
|
13739 | delete eventNameDispatchConfigs[eventName];
|
13740 | }
|
13741 | }
|
13742 |
|
13743 | var registrationNameModules = EventPluginRegistry.registrationNameModules;
|
13744 | for (var registrationName in registrationNameModules) {
|
13745 | if (registrationNameModules.hasOwnProperty(registrationName)) {
|
13746 | delete registrationNameModules[registrationName];
|
13747 | }
|
13748 | }
|
13749 |
|
13750 | if (process.env.NODE_ENV !== 'production') {
|
13751 | var possibleRegistrationNames = EventPluginRegistry.possibleRegistrationNames;
|
13752 | for (var lowerCasedName in possibleRegistrationNames) {
|
13753 | if (possibleRegistrationNames.hasOwnProperty(lowerCasedName)) {
|
13754 | delete possibleRegistrationNames[lowerCasedName];
|
13755 | }
|
13756 | }
|
13757 | }
|
13758 | }
|
13759 |
|
13760 | };
|
13761 |
|
13762 | module.exports = EventPluginRegistry;
|
13763 | }).call(this,require('_process'))
|
13764 | },{"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],171:[function(require,module,exports){
|
13765 | (function (process){
|
13766 | /**
|
13767 | * Copyright 2013-present, Facebook, Inc.
|
13768 | * All rights reserved.
|
13769 | *
|
13770 | * This source code is licensed under the BSD-style license found in the
|
13771 | * LICENSE file in the root directory of this source tree. An additional grant
|
13772 | * of patent rights can be found in the PATENTS file in the same directory.
|
13773 | *
|
13774 | */
|
13775 |
|
13776 | 'use strict';
|
13777 |
|
13778 | var _prodInvariant = require('./reactProdInvariant');
|
13779 |
|
13780 | var ReactErrorUtils = require('./ReactErrorUtils');
|
13781 |
|
13782 | var invariant = require('fbjs/lib/invariant');
|
13783 | var warning = require('fbjs/lib/warning');
|
13784 |
|
13785 | /**
|
13786 | * Injected dependencies:
|
13787 | */
|
13788 |
|
13789 | /**
|
13790 | * - `ComponentTree`: [required] Module that can convert between React instances
|
13791 | * and actual node references.
|
13792 | */
|
13793 | var ComponentTree;
|
13794 | var TreeTraversal;
|
13795 | var injection = {
|
13796 | injectComponentTree: function (Injected) {
|
13797 | ComponentTree = Injected;
|
13798 | if (process.env.NODE_ENV !== 'production') {
|
13799 | process.env.NODE_ENV !== 'production' ? warning(Injected && Injected.getNodeFromInstance && Injected.getInstanceFromNode, 'EventPluginUtils.injection.injectComponentTree(...): Injected ' + 'module is missing getNodeFromInstance or getInstanceFromNode.') : void 0;
|
13800 | }
|
13801 | },
|
13802 | injectTreeTraversal: function (Injected) {
|
13803 | TreeTraversal = Injected;
|
13804 | if (process.env.NODE_ENV !== 'production') {
|
13805 | process.env.NODE_ENV !== 'production' ? warning(Injected && Injected.isAncestor && Injected.getLowestCommonAncestor, 'EventPluginUtils.injection.injectTreeTraversal(...): Injected ' + 'module is missing isAncestor or getLowestCommonAncestor.') : void 0;
|
13806 | }
|
13807 | }
|
13808 | };
|
13809 |
|
13810 | function isEndish(topLevelType) {
|
13811 | return topLevelType === 'topMouseUp' || topLevelType === 'topTouchEnd' || topLevelType === 'topTouchCancel';
|
13812 | }
|
13813 |
|
13814 | function isMoveish(topLevelType) {
|
13815 | return topLevelType === 'topMouseMove' || topLevelType === 'topTouchMove';
|
13816 | }
|
13817 | function isStartish(topLevelType) {
|
13818 | return topLevelType === 'topMouseDown' || topLevelType === 'topTouchStart';
|
13819 | }
|
13820 |
|
13821 | var validateEventDispatches;
|
13822 | if (process.env.NODE_ENV !== 'production') {
|
13823 | validateEventDispatches = function (event) {
|
13824 | var dispatchListeners = event._dispatchListeners;
|
13825 | var dispatchInstances = event._dispatchInstances;
|
13826 |
|
13827 | var listenersIsArr = Array.isArray(dispatchListeners);
|
13828 | var listenersLen = listenersIsArr ? dispatchListeners.length : dispatchListeners ? 1 : 0;
|
13829 |
|
13830 | var instancesIsArr = Array.isArray(dispatchInstances);
|
13831 | var instancesLen = instancesIsArr ? dispatchInstances.length : dispatchInstances ? 1 : 0;
|
13832 |
|
13833 | process.env.NODE_ENV !== 'production' ? warning(instancesIsArr === listenersIsArr && instancesLen === listenersLen, 'EventPluginUtils: Invalid `event`.') : void 0;
|
13834 | };
|
13835 | }
|
13836 |
|
13837 | /**
|
13838 | * Dispatch the event to the listener.
|
13839 | * @param {SyntheticEvent} event SyntheticEvent to handle
|
13840 | * @param {boolean} simulated If the event is simulated (changes exn behavior)
|
13841 | * @param {function} listener Application-level callback
|
13842 | * @param {*} inst Internal component instance
|
13843 | */
|
13844 | function executeDispatch(event, simulated, listener, inst) {
|
13845 | var type = event.type || 'unknown-event';
|
13846 | event.currentTarget = EventPluginUtils.getNodeFromInstance(inst);
|
13847 | if (simulated) {
|
13848 | ReactErrorUtils.invokeGuardedCallbackWithCatch(type, listener, event);
|
13849 | } else {
|
13850 | ReactErrorUtils.invokeGuardedCallback(type, listener, event);
|
13851 | }
|
13852 | event.currentTarget = null;
|
13853 | }
|
13854 |
|
13855 | /**
|
13856 | * Standard/simple iteration through an event's collected dispatches.
|
13857 | */
|
13858 | function executeDispatchesInOrder(event, simulated) {
|
13859 | var dispatchListeners = event._dispatchListeners;
|
13860 | var dispatchInstances = event._dispatchInstances;
|
13861 | if (process.env.NODE_ENV !== 'production') {
|
13862 | validateEventDispatches(event);
|
13863 | }
|
13864 | if (Array.isArray(dispatchListeners)) {
|
13865 | for (var i = 0; i < dispatchListeners.length; i++) {
|
13866 | if (event.isPropagationStopped()) {
|
13867 | break;
|
13868 | }
|
13869 | // Listeners and Instances are two parallel arrays that are always in sync.
|
13870 | executeDispatch(event, simulated, dispatchListeners[i], dispatchInstances[i]);
|
13871 | }
|
13872 | } else if (dispatchListeners) {
|
13873 | executeDispatch(event, simulated, dispatchListeners, dispatchInstances);
|
13874 | }
|
13875 | event._dispatchListeners = null;
|
13876 | event._dispatchInstances = null;
|
13877 | }
|
13878 |
|
13879 | /**
|
13880 | * Standard/simple iteration through an event's collected dispatches, but stops
|
13881 | * at the first dispatch execution returning true, and returns that id.
|
13882 | *
|
13883 | * @return {?string} id of the first dispatch execution who's listener returns
|
13884 | * true, or null if no listener returned true.
|
13885 | */
|
13886 | function executeDispatchesInOrderStopAtTrueImpl(event) {
|
13887 | var dispatchListeners = event._dispatchListeners;
|
13888 | var dispatchInstances = event._dispatchInstances;
|
13889 | if (process.env.NODE_ENV !== 'production') {
|
13890 | validateEventDispatches(event);
|
13891 | }
|
13892 | if (Array.isArray(dispatchListeners)) {
|
13893 | for (var i = 0; i < dispatchListeners.length; i++) {
|
13894 | if (event.isPropagationStopped()) {
|
13895 | break;
|
13896 | }
|
13897 | // Listeners and Instances are two parallel arrays that are always in sync.
|
13898 | if (dispatchListeners[i](event, dispatchInstances[i])) {
|
13899 | return dispatchInstances[i];
|
13900 | }
|
13901 | }
|
13902 | } else if (dispatchListeners) {
|
13903 | if (dispatchListeners(event, dispatchInstances)) {
|
13904 | return dispatchInstances;
|
13905 | }
|
13906 | }
|
13907 | return null;
|
13908 | }
|
13909 |
|
13910 | /**
|
13911 | * @see executeDispatchesInOrderStopAtTrueImpl
|
13912 | */
|
13913 | function executeDispatchesInOrderStopAtTrue(event) {
|
13914 | var ret = executeDispatchesInOrderStopAtTrueImpl(event);
|
13915 | event._dispatchInstances = null;
|
13916 | event._dispatchListeners = null;
|
13917 | return ret;
|
13918 | }
|
13919 |
|
13920 | /**
|
13921 | * Execution of a "direct" dispatch - there must be at most one dispatch
|
13922 | * accumulated on the event or it is considered an error. It doesn't really make
|
13923 | * sense for an event with multiple dispatches (bubbled) to keep track of the
|
13924 | * return values at each dispatch execution, but it does tend to make sense when
|
13925 | * dealing with "direct" dispatches.
|
13926 | *
|
13927 | * @return {*} The return value of executing the single dispatch.
|
13928 | */
|
13929 | function executeDirectDispatch(event) {
|
13930 | if (process.env.NODE_ENV !== 'production') {
|
13931 | validateEventDispatches(event);
|
13932 | }
|
13933 | var dispatchListener = event._dispatchListeners;
|
13934 | var dispatchInstance = event._dispatchInstances;
|
13935 | !!Array.isArray(dispatchListener) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'executeDirectDispatch(...): Invalid `event`.') : _prodInvariant('103') : void 0;
|
13936 | event.currentTarget = dispatchListener ? EventPluginUtils.getNodeFromInstance(dispatchInstance) : null;
|
13937 | var res = dispatchListener ? dispatchListener(event) : null;
|
13938 | event.currentTarget = null;
|
13939 | event._dispatchListeners = null;
|
13940 | event._dispatchInstances = null;
|
13941 | return res;
|
13942 | }
|
13943 |
|
13944 | /**
|
13945 | * @param {SyntheticEvent} event
|
13946 | * @return {boolean} True iff number of dispatches accumulated is greater than 0.
|
13947 | */
|
13948 | function hasDispatches(event) {
|
13949 | return !!event._dispatchListeners;
|
13950 | }
|
13951 |
|
13952 | /**
|
13953 | * General utilities that are useful in creating custom Event Plugins.
|
13954 | */
|
13955 | var EventPluginUtils = {
|
13956 | isEndish: isEndish,
|
13957 | isMoveish: isMoveish,
|
13958 | isStartish: isStartish,
|
13959 |
|
13960 | executeDirectDispatch: executeDirectDispatch,
|
13961 | executeDispatchesInOrder: executeDispatchesInOrder,
|
13962 | executeDispatchesInOrderStopAtTrue: executeDispatchesInOrderStopAtTrue,
|
13963 | hasDispatches: hasDispatches,
|
13964 |
|
13965 | getInstanceFromNode: function (node) {
|
13966 | return ComponentTree.getInstanceFromNode(node);
|
13967 | },
|
13968 | getNodeFromInstance: function (node) {
|
13969 | return ComponentTree.getNodeFromInstance(node);
|
13970 | },
|
13971 | isAncestor: function (a, b) {
|
13972 | return TreeTraversal.isAncestor(a, b);
|
13973 | },
|
13974 | getLowestCommonAncestor: function (a, b) {
|
13975 | return TreeTraversal.getLowestCommonAncestor(a, b);
|
13976 | },
|
13977 | getParentInstance: function (inst) {
|
13978 | return TreeTraversal.getParentInstance(inst);
|
13979 | },
|
13980 | traverseTwoPhase: function (target, fn, arg) {
|
13981 | return TreeTraversal.traverseTwoPhase(target, fn, arg);
|
13982 | },
|
13983 | traverseEnterLeave: function (from, to, fn, argFrom, argTo) {
|
13984 | return TreeTraversal.traverseEnterLeave(from, to, fn, argFrom, argTo);
|
13985 | },
|
13986 |
|
13987 | injection: injection
|
13988 | };
|
13989 |
|
13990 | module.exports = EventPluginUtils;
|
13991 | }).call(this,require('_process'))
|
13992 | },{"./ReactErrorUtils":207,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131}],172:[function(require,module,exports){
|
13993 | (function (process){
|
13994 | /**
|
13995 | * Copyright 2013-present, Facebook, Inc.
|
13996 | * All rights reserved.
|
13997 | *
|
13998 | * This source code is licensed under the BSD-style license found in the
|
13999 | * LICENSE file in the root directory of this source tree. An additional grant
|
14000 | * of patent rights can be found in the PATENTS file in the same directory.
|
14001 | *
|
14002 | */
|
14003 |
|
14004 | 'use strict';
|
14005 |
|
14006 | var EventPluginHub = require('./EventPluginHub');
|
14007 | var EventPluginUtils = require('./EventPluginUtils');
|
14008 |
|
14009 | var accumulateInto = require('./accumulateInto');
|
14010 | var forEachAccumulated = require('./forEachAccumulated');
|
14011 | var warning = require('fbjs/lib/warning');
|
14012 |
|
14013 | var getListener = EventPluginHub.getListener;
|
14014 |
|
14015 | /**
|
14016 | * Some event types have a notion of different registration names for different
|
14017 | * "phases" of propagation. This finds listeners by a given phase.
|
14018 | */
|
14019 | function listenerAtPhase(inst, event, propagationPhase) {
|
14020 | var registrationName = event.dispatchConfig.phasedRegistrationNames[propagationPhase];
|
14021 | return getListener(inst, registrationName);
|
14022 | }
|
14023 |
|
14024 | /**
|
14025 | * Tags a `SyntheticEvent` with dispatched listeners. Creating this function
|
14026 | * here, allows us to not have to bind or create functions for each event.
|
14027 | * Mutating the event's members allows us to not have to create a wrapping
|
14028 | * "dispatch" object that pairs the event with the listener.
|
14029 | */
|
14030 | function accumulateDirectionalDispatches(inst, phase, event) {
|
14031 | if (process.env.NODE_ENV !== 'production') {
|
14032 | process.env.NODE_ENV !== 'production' ? warning(inst, 'Dispatching inst must not be null') : void 0;
|
14033 | }
|
14034 | var listener = listenerAtPhase(inst, event, phase);
|
14035 | if (listener) {
|
14036 | event._dispatchListeners = accumulateInto(event._dispatchListeners, listener);
|
14037 | event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
|
14038 | }
|
14039 | }
|
14040 |
|
14041 | /**
|
14042 | * Collect dispatches (must be entirely collected before dispatching - see unit
|
14043 | * tests). Lazily allocate the array to conserve memory. We must loop through
|
14044 | * each event and perform the traversal for each one. We cannot perform a
|
14045 | * single traversal for the entire collection of events because each event may
|
14046 | * have a different target.
|
14047 | */
|
14048 | function accumulateTwoPhaseDispatchesSingle(event) {
|
14049 | if (event && event.dispatchConfig.phasedRegistrationNames) {
|
14050 | EventPluginUtils.traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
|
14051 | }
|
14052 | }
|
14053 |
|
14054 | /**
|
14055 | * Same as `accumulateTwoPhaseDispatchesSingle`, but skips over the targetID.
|
14056 | */
|
14057 | function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
|
14058 | if (event && event.dispatchConfig.phasedRegistrationNames) {
|
14059 | var targetInst = event._targetInst;
|
14060 | var parentInst = targetInst ? EventPluginUtils.getParentInstance(targetInst) : null;
|
14061 | EventPluginUtils.traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event);
|
14062 | }
|
14063 | }
|
14064 |
|
14065 | /**
|
14066 | * Accumulates without regard to direction, does not look for phased
|
14067 | * registration names. Same as `accumulateDirectDispatchesSingle` but without
|
14068 | * requiring that the `dispatchMarker` be the same as the dispatched ID.
|
14069 | */
|
14070 | function accumulateDispatches(inst, ignoredDirection, event) {
|
14071 | if (event && event.dispatchConfig.registrationName) {
|
14072 | var registrationName = event.dispatchConfig.registrationName;
|
14073 | var listener = getListener(inst, registrationName);
|
14074 | if (listener) {
|
14075 | event._dispatchListeners = accumulateInto(event._dispatchListeners, listener);
|
14076 | event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
|
14077 | }
|
14078 | }
|
14079 | }
|
14080 |
|
14081 | /**
|
14082 | * Accumulates dispatches on an `SyntheticEvent`, but only for the
|
14083 | * `dispatchMarker`.
|
14084 | * @param {SyntheticEvent} event
|
14085 | */
|
14086 | function accumulateDirectDispatchesSingle(event) {
|
14087 | if (event && event.dispatchConfig.registrationName) {
|
14088 | accumulateDispatches(event._targetInst, null, event);
|
14089 | }
|
14090 | }
|
14091 |
|
14092 | function accumulateTwoPhaseDispatches(events) {
|
14093 | forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
|
14094 | }
|
14095 |
|
14096 | function accumulateTwoPhaseDispatchesSkipTarget(events) {
|
14097 | forEachAccumulated(events, accumulateTwoPhaseDispatchesSingleSkipTarget);
|
14098 | }
|
14099 |
|
14100 | function accumulateEnterLeaveDispatches(leave, enter, from, to) {
|
14101 | EventPluginUtils.traverseEnterLeave(from, to, accumulateDispatches, leave, enter);
|
14102 | }
|
14103 |
|
14104 | function accumulateDirectDispatches(events) {
|
14105 | forEachAccumulated(events, accumulateDirectDispatchesSingle);
|
14106 | }
|
14107 |
|
14108 | /**
|
14109 | * A small set of propagation patterns, each of which will accept a small amount
|
14110 | * of information, and generate a set of "dispatch ready event objects" - which
|
14111 | * are sets of events that have already been annotated with a set of dispatched
|
14112 | * listener functions/ids. The API is designed this way to discourage these
|
14113 | * propagation strategies from actually executing the dispatches, since we
|
14114 | * always want to collect the entire set of dispatches before executing event a
|
14115 | * single one.
|
14116 | *
|
14117 | * @constructor EventPropagators
|
14118 | */
|
14119 | var EventPropagators = {
|
14120 | accumulateTwoPhaseDispatches: accumulateTwoPhaseDispatches,
|
14121 | accumulateTwoPhaseDispatchesSkipTarget: accumulateTwoPhaseDispatchesSkipTarget,
|
14122 | accumulateDirectDispatches: accumulateDirectDispatches,
|
14123 | accumulateEnterLeaveDispatches: accumulateEnterLeaveDispatches
|
14124 | };
|
14125 |
|
14126 | module.exports = EventPropagators;
|
14127 | }).call(this,require('_process'))
|
14128 | },{"./EventPluginHub":169,"./EventPluginUtils":171,"./accumulateInto":253,"./forEachAccumulated":261,"_process":144,"fbjs/lib/warning":131}],173:[function(require,module,exports){
|
14129 | /**
|
14130 | * Copyright 2013-present, Facebook, Inc.
|
14131 | * All rights reserved.
|
14132 | *
|
14133 | * This source code is licensed under the BSD-style license found in the
|
14134 | * LICENSE file in the root directory of this source tree. An additional grant
|
14135 | * of patent rights can be found in the PATENTS file in the same directory.
|
14136 | *
|
14137 | */
|
14138 |
|
14139 | 'use strict';
|
14140 |
|
14141 | var _assign = require('object-assign');
|
14142 |
|
14143 | var PooledClass = require('./PooledClass');
|
14144 |
|
14145 | var getTextContentAccessor = require('./getTextContentAccessor');
|
14146 |
|
14147 | /**
|
14148 | * This helper class stores information about text content of a target node,
|
14149 | * allowing comparison of content before and after a given event.
|
14150 | *
|
14151 | * Identify the node where selection currently begins, then observe
|
14152 | * both its text content and its current position in the DOM. Since the
|
14153 | * browser may natively replace the target node during composition, we can
|
14154 | * use its position to find its replacement.
|
14155 | *
|
14156 | * @param {DOMEventTarget} root
|
14157 | */
|
14158 | function FallbackCompositionState(root) {
|
14159 | this._root = root;
|
14160 | this._startText = this.getText();
|
14161 | this._fallbackText = null;
|
14162 | }
|
14163 |
|
14164 | _assign(FallbackCompositionState.prototype, {
|
14165 | destructor: function () {
|
14166 | this._root = null;
|
14167 | this._startText = null;
|
14168 | this._fallbackText = null;
|
14169 | },
|
14170 |
|
14171 | /**
|
14172 | * Get current text of input.
|
14173 | *
|
14174 | * @return {string}
|
14175 | */
|
14176 | getText: function () {
|
14177 | if ('value' in this._root) {
|
14178 | return this._root.value;
|
14179 | }
|
14180 | return this._root[getTextContentAccessor()];
|
14181 | },
|
14182 |
|
14183 | /**
|
14184 | * Determine the differing substring between the initially stored
|
14185 | * text content and the current content.
|
14186 | *
|
14187 | * @return {string}
|
14188 | */
|
14189 | getData: function () {
|
14190 | if (this._fallbackText) {
|
14191 | return this._fallbackText;
|
14192 | }
|
14193 |
|
14194 | var start;
|
14195 | var startValue = this._startText;
|
14196 | var startLength = startValue.length;
|
14197 | var end;
|
14198 | var endValue = this.getText();
|
14199 | var endLength = endValue.length;
|
14200 |
|
14201 | for (start = 0; start < startLength; start++) {
|
14202 | if (startValue[start] !== endValue[start]) {
|
14203 | break;
|
14204 | }
|
14205 | }
|
14206 |
|
14207 | var minEnd = startLength - start;
|
14208 | for (end = 1; end <= minEnd; end++) {
|
14209 | if (startValue[startLength - end] !== endValue[endLength - end]) {
|
14210 | break;
|
14211 | }
|
14212 | }
|
14213 |
|
14214 | var sliceTail = end > 1 ? 1 - end : undefined;
|
14215 | this._fallbackText = endValue.slice(start, sliceTail);
|
14216 | return this._fallbackText;
|
14217 | }
|
14218 | });
|
14219 |
|
14220 | PooledClass.addPoolingTo(FallbackCompositionState);
|
14221 |
|
14222 | module.exports = FallbackCompositionState;
|
14223 | },{"./PooledClass":177,"./getTextContentAccessor":270,"object-assign":143}],174:[function(require,module,exports){
|
14224 | /**
|
14225 | * Copyright 2013-present, Facebook, Inc.
|
14226 | * All rights reserved.
|
14227 | *
|
14228 | * This source code is licensed under the BSD-style license found in the
|
14229 | * LICENSE file in the root directory of this source tree. An additional grant
|
14230 | * of patent rights can be found in the PATENTS file in the same directory.
|
14231 | *
|
14232 | */
|
14233 |
|
14234 | 'use strict';
|
14235 |
|
14236 | var DOMProperty = require('./DOMProperty');
|
14237 |
|
14238 | var MUST_USE_PROPERTY = DOMProperty.injection.MUST_USE_PROPERTY;
|
14239 | var HAS_BOOLEAN_VALUE = DOMProperty.injection.HAS_BOOLEAN_VALUE;
|
14240 | var HAS_NUMERIC_VALUE = DOMProperty.injection.HAS_NUMERIC_VALUE;
|
14241 | var HAS_POSITIVE_NUMERIC_VALUE = DOMProperty.injection.HAS_POSITIVE_NUMERIC_VALUE;
|
14242 | var HAS_OVERLOADED_BOOLEAN_VALUE = DOMProperty.injection.HAS_OVERLOADED_BOOLEAN_VALUE;
|
14243 |
|
14244 | var HTMLDOMPropertyConfig = {
|
14245 | isCustomAttribute: RegExp.prototype.test.bind(new RegExp('^(data|aria)-[' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$')),
|
14246 | Properties: {
|
14247 | /**
|
14248 | * Standard Properties
|
14249 | */
|
14250 | accept: 0,
|
14251 | acceptCharset: 0,
|
14252 | accessKey: 0,
|
14253 | action: 0,
|
14254 | allowFullScreen: HAS_BOOLEAN_VALUE,
|
14255 | allowTransparency: 0,
|
14256 | alt: 0,
|
14257 | // specifies target context for links with `preload` type
|
14258 | as: 0,
|
14259 | async: HAS_BOOLEAN_VALUE,
|
14260 | autoComplete: 0,
|
14261 | // autoFocus is polyfilled/normalized by AutoFocusUtils
|
14262 | // autoFocus: HAS_BOOLEAN_VALUE,
|
14263 | autoPlay: HAS_BOOLEAN_VALUE,
|
14264 | capture: HAS_BOOLEAN_VALUE,
|
14265 | cellPadding: 0,
|
14266 | cellSpacing: 0,
|
14267 | charSet: 0,
|
14268 | challenge: 0,
|
14269 | checked: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
|
14270 | cite: 0,
|
14271 | classID: 0,
|
14272 | className: 0,
|
14273 | cols: HAS_POSITIVE_NUMERIC_VALUE,
|
14274 | colSpan: 0,
|
14275 | content: 0,
|
14276 | contentEditable: 0,
|
14277 | contextMenu: 0,
|
14278 | controls: HAS_BOOLEAN_VALUE,
|
14279 | coords: 0,
|
14280 | crossOrigin: 0,
|
14281 | data: 0, // For `<object />` acts as `src`.
|
14282 | dateTime: 0,
|
14283 | 'default': HAS_BOOLEAN_VALUE,
|
14284 | defer: HAS_BOOLEAN_VALUE,
|
14285 | dir: 0,
|
14286 | disabled: HAS_BOOLEAN_VALUE,
|
14287 | download: HAS_OVERLOADED_BOOLEAN_VALUE,
|
14288 | draggable: 0,
|
14289 | encType: 0,
|
14290 | form: 0,
|
14291 | formAction: 0,
|
14292 | formEncType: 0,
|
14293 | formMethod: 0,
|
14294 | formNoValidate: HAS_BOOLEAN_VALUE,
|
14295 | formTarget: 0,
|
14296 | frameBorder: 0,
|
14297 | headers: 0,
|
14298 | height: 0,
|
14299 | hidden: HAS_BOOLEAN_VALUE,
|
14300 | high: 0,
|
14301 | href: 0,
|
14302 | hrefLang: 0,
|
14303 | htmlFor: 0,
|
14304 | httpEquiv: 0,
|
14305 | icon: 0,
|
14306 | id: 0,
|
14307 | inputMode: 0,
|
14308 | integrity: 0,
|
14309 | is: 0,
|
14310 | keyParams: 0,
|
14311 | keyType: 0,
|
14312 | kind: 0,
|
14313 | label: 0,
|
14314 | lang: 0,
|
14315 | list: 0,
|
14316 | loop: HAS_BOOLEAN_VALUE,
|
14317 | low: 0,
|
14318 | manifest: 0,
|
14319 | marginHeight: 0,
|
14320 | marginWidth: 0,
|
14321 | max: 0,
|
14322 | maxLength: 0,
|
14323 | media: 0,
|
14324 | mediaGroup: 0,
|
14325 | method: 0,
|
14326 | min: 0,
|
14327 | minLength: 0,
|
14328 | // Caution; `option.selected` is not updated if `select.multiple` is
|
14329 | // disabled with `removeAttribute`.
|
14330 | multiple: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
|
14331 | muted: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
|
14332 | name: 0,
|
14333 | nonce: 0,
|
14334 | noValidate: HAS_BOOLEAN_VALUE,
|
14335 | open: HAS_BOOLEAN_VALUE,
|
14336 | optimum: 0,
|
14337 | pattern: 0,
|
14338 | placeholder: 0,
|
14339 | playsInline: HAS_BOOLEAN_VALUE,
|
14340 | poster: 0,
|
14341 | preload: 0,
|
14342 | profile: 0,
|
14343 | radioGroup: 0,
|
14344 | readOnly: HAS_BOOLEAN_VALUE,
|
14345 | referrerPolicy: 0,
|
14346 | rel: 0,
|
14347 | required: HAS_BOOLEAN_VALUE,
|
14348 | reversed: HAS_BOOLEAN_VALUE,
|
14349 | role: 0,
|
14350 | rows: HAS_POSITIVE_NUMERIC_VALUE,
|
14351 | rowSpan: HAS_NUMERIC_VALUE,
|
14352 | sandbox: 0,
|
14353 | scope: 0,
|
14354 | scoped: HAS_BOOLEAN_VALUE,
|
14355 | scrolling: 0,
|
14356 | seamless: HAS_BOOLEAN_VALUE,
|
14357 | selected: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
|
14358 | shape: 0,
|
14359 | size: HAS_POSITIVE_NUMERIC_VALUE,
|
14360 | sizes: 0,
|
14361 | span: HAS_POSITIVE_NUMERIC_VALUE,
|
14362 | spellCheck: 0,
|
14363 | src: 0,
|
14364 | srcDoc: 0,
|
14365 | srcLang: 0,
|
14366 | srcSet: 0,
|
14367 | start: HAS_NUMERIC_VALUE,
|
14368 | step: 0,
|
14369 | style: 0,
|
14370 | summary: 0,
|
14371 | tabIndex: 0,
|
14372 | target: 0,
|
14373 | title: 0,
|
14374 | // Setting .type throws on non-<input> tags
|
14375 | type: 0,
|
14376 | useMap: 0,
|
14377 | value: 0,
|
14378 | width: 0,
|
14379 | wmode: 0,
|
14380 | wrap: 0,
|
14381 |
|
14382 | /**
|
14383 | * RDFa Properties
|
14384 | */
|
14385 | about: 0,
|
14386 | datatype: 0,
|
14387 | inlist: 0,
|
14388 | prefix: 0,
|
14389 | // property is also supported for OpenGraph in meta tags.
|
14390 | property: 0,
|
14391 | resource: 0,
|
14392 | 'typeof': 0,
|
14393 | vocab: 0,
|
14394 |
|
14395 | /**
|
14396 | * Non-standard Properties
|
14397 | */
|
14398 | // autoCapitalize and autoCorrect are supported in Mobile Safari for
|
14399 | // keyboard hints.
|
14400 | autoCapitalize: 0,
|
14401 | autoCorrect: 0,
|
14402 | // autoSave allows WebKit/Blink to persist values of input fields on page reloads
|
14403 | autoSave: 0,
|
14404 | // color is for Safari mask-icon link
|
14405 | color: 0,
|
14406 | // itemProp, itemScope, itemType are for
|
14407 | // Microdata support. See http://schema.org/docs/gs.html
|
14408 | itemProp: 0,
|
14409 | itemScope: HAS_BOOLEAN_VALUE,
|
14410 | itemType: 0,
|
14411 | // itemID and itemRef are for Microdata support as well but
|
14412 | // only specified in the WHATWG spec document. See
|
14413 | // https://html.spec.whatwg.org/multipage/microdata.html#microdata-dom-api
|
14414 | itemID: 0,
|
14415 | itemRef: 0,
|
14416 | // results show looking glass icon and recent searches on input
|
14417 | // search fields in WebKit/Blink
|
14418 | results: 0,
|
14419 | // IE-only attribute that specifies security restrictions on an iframe
|
14420 | // as an alternative to the sandbox attribute on IE<10
|
14421 | security: 0,
|
14422 | // IE-only attribute that controls focus behavior
|
14423 | unselectable: 0
|
14424 | },
|
14425 | DOMAttributeNames: {
|
14426 | acceptCharset: 'accept-charset',
|
14427 | className: 'class',
|
14428 | htmlFor: 'for',
|
14429 | httpEquiv: 'http-equiv'
|
14430 | },
|
14431 | DOMPropertyNames: {}
|
14432 | };
|
14433 |
|
14434 | module.exports = HTMLDOMPropertyConfig;
|
14435 | },{"./DOMProperty":164}],175:[function(require,module,exports){
|
14436 | /**
|
14437 | * Copyright 2013-present, Facebook, Inc.
|
14438 | * All rights reserved.
|
14439 | *
|
14440 | * This source code is licensed under the BSD-style license found in the
|
14441 | * LICENSE file in the root directory of this source tree. An additional grant
|
14442 | * of patent rights can be found in the PATENTS file in the same directory.
|
14443 | *
|
14444 | *
|
14445 | */
|
14446 |
|
14447 | 'use strict';
|
14448 |
|
14449 | /**
|
14450 | * Escape and wrap key so it is safe to use as a reactid
|
14451 | *
|
14452 | * @param {string} key to be escaped.
|
14453 | * @return {string} the escaped key.
|
14454 | */
|
14455 |
|
14456 | function escape(key) {
|
14457 | var escapeRegex = /[=:]/g;
|
14458 | var escaperLookup = {
|
14459 | '=': '=0',
|
14460 | ':': '=2'
|
14461 | };
|
14462 | var escapedString = ('' + key).replace(escapeRegex, function (match) {
|
14463 | return escaperLookup[match];
|
14464 | });
|
14465 |
|
14466 | return '$' + escapedString;
|
14467 | }
|
14468 |
|
14469 | /**
|
14470 | * Unescape and unwrap key for human-readable display
|
14471 | *
|
14472 | * @param {string} key to unescape.
|
14473 | * @return {string} the unescaped key.
|
14474 | */
|
14475 | function unescape(key) {
|
14476 | var unescapeRegex = /(=0|=2)/g;
|
14477 | var unescaperLookup = {
|
14478 | '=0': '=',
|
14479 | '=2': ':'
|
14480 | };
|
14481 | var keySubstring = key[0] === '.' && key[1] === '$' ? key.substring(2) : key.substring(1);
|
14482 |
|
14483 | return ('' + keySubstring).replace(unescapeRegex, function (match) {
|
14484 | return unescaperLookup[match];
|
14485 | });
|
14486 | }
|
14487 |
|
14488 | var KeyEscapeUtils = {
|
14489 | escape: escape,
|
14490 | unescape: unescape
|
14491 | };
|
14492 |
|
14493 | module.exports = KeyEscapeUtils;
|
14494 | },{}],176:[function(require,module,exports){
|
14495 | (function (process){
|
14496 | /**
|
14497 | * Copyright 2013-present, Facebook, Inc.
|
14498 | * All rights reserved.
|
14499 | *
|
14500 | * This source code is licensed under the BSD-style license found in the
|
14501 | * LICENSE file in the root directory of this source tree. An additional grant
|
14502 | * of patent rights can be found in the PATENTS file in the same directory.
|
14503 | *
|
14504 | */
|
14505 |
|
14506 | 'use strict';
|
14507 |
|
14508 | var _prodInvariant = require('./reactProdInvariant');
|
14509 |
|
14510 | var React = require('react/lib/React');
|
14511 | var ReactPropTypesSecret = require('./ReactPropTypesSecret');
|
14512 |
|
14513 | var invariant = require('fbjs/lib/invariant');
|
14514 | var warning = require('fbjs/lib/warning');
|
14515 |
|
14516 | var hasReadOnlyValue = {
|
14517 | 'button': true,
|
14518 | 'checkbox': true,
|
14519 | 'image': true,
|
14520 | 'hidden': true,
|
14521 | 'radio': true,
|
14522 | 'reset': true,
|
14523 | 'submit': true
|
14524 | };
|
14525 |
|
14526 | function _assertSingleLink(inputProps) {
|
14527 | !(inputProps.checkedLink == null || inputProps.valueLink == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Cannot provide a checkedLink and a valueLink. If you want to use checkedLink, you probably don\'t want to use valueLink and vice versa.') : _prodInvariant('87') : void 0;
|
14528 | }
|
14529 | function _assertValueLink(inputProps) {
|
14530 | _assertSingleLink(inputProps);
|
14531 | !(inputProps.value == null && inputProps.onChange == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Cannot provide a valueLink and a value or onChange event. If you want to use value or onChange, you probably don\'t want to use valueLink.') : _prodInvariant('88') : void 0;
|
14532 | }
|
14533 |
|
14534 | function _assertCheckedLink(inputProps) {
|
14535 | _assertSingleLink(inputProps);
|
14536 | !(inputProps.checked == null && inputProps.onChange == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Cannot provide a checkedLink and a checked property or onChange event. If you want to use checked or onChange, you probably don\'t want to use checkedLink') : _prodInvariant('89') : void 0;
|
14537 | }
|
14538 |
|
14539 | var propTypes = {
|
14540 | value: function (props, propName, componentName) {
|
14541 | if (!props[propName] || hasReadOnlyValue[props.type] || props.onChange || props.readOnly || props.disabled) {
|
14542 | return null;
|
14543 | }
|
14544 | return new Error('You provided a `value` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultValue`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
|
14545 | },
|
14546 | checked: function (props, propName, componentName) {
|
14547 | if (!props[propName] || props.onChange || props.readOnly || props.disabled) {
|
14548 | return null;
|
14549 | }
|
14550 | return new Error('You provided a `checked` prop to a form field without an ' + '`onChange` handler. This will render a read-only field. If ' + 'the field should be mutable use `defaultChecked`. Otherwise, ' + 'set either `onChange` or `readOnly`.');
|
14551 | },
|
14552 | onChange: React.PropTypes.func
|
14553 | };
|
14554 |
|
14555 | var loggedTypeFailures = {};
|
14556 | function getDeclarationErrorAddendum(owner) {
|
14557 | if (owner) {
|
14558 | var name = owner.getName();
|
14559 | if (name) {
|
14560 | return ' Check the render method of `' + name + '`.';
|
14561 | }
|
14562 | }
|
14563 | return '';
|
14564 | }
|
14565 |
|
14566 | /**
|
14567 | * Provide a linked `value` attribute for controlled forms. You should not use
|
14568 | * this outside of the ReactDOM controlled form components.
|
14569 | */
|
14570 | var LinkedValueUtils = {
|
14571 | checkPropTypes: function (tagName, props, owner) {
|
14572 | for (var propName in propTypes) {
|
14573 | if (propTypes.hasOwnProperty(propName)) {
|
14574 | var error = propTypes[propName](props, propName, tagName, 'prop', null, ReactPropTypesSecret);
|
14575 | }
|
14576 | if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
14577 | // Only monitor this failure once because there tends to be a lot of the
|
14578 | // same error.
|
14579 | loggedTypeFailures[error.message] = true;
|
14580 |
|
14581 | var addendum = getDeclarationErrorAddendum(owner);
|
14582 | process.env.NODE_ENV !== 'production' ? warning(false, 'Failed form propType: %s%s', error.message, addendum) : void 0;
|
14583 | }
|
14584 | }
|
14585 | },
|
14586 |
|
14587 | /**
|
14588 | * @param {object} inputProps Props for form component
|
14589 | * @return {*} current value of the input either from value prop or link.
|
14590 | */
|
14591 | getValue: function (inputProps) {
|
14592 | if (inputProps.valueLink) {
|
14593 | _assertValueLink(inputProps);
|
14594 | return inputProps.valueLink.value;
|
14595 | }
|
14596 | return inputProps.value;
|
14597 | },
|
14598 |
|
14599 | /**
|
14600 | * @param {object} inputProps Props for form component
|
14601 | * @return {*} current checked status of the input either from checked prop
|
14602 | * or link.
|
14603 | */
|
14604 | getChecked: function (inputProps) {
|
14605 | if (inputProps.checkedLink) {
|
14606 | _assertCheckedLink(inputProps);
|
14607 | return inputProps.checkedLink.value;
|
14608 | }
|
14609 | return inputProps.checked;
|
14610 | },
|
14611 |
|
14612 | /**
|
14613 | * @param {object} inputProps Props for form component
|
14614 | * @param {SyntheticEvent} event change event to handle
|
14615 | */
|
14616 | executeOnChange: function (inputProps, event) {
|
14617 | if (inputProps.valueLink) {
|
14618 | _assertValueLink(inputProps);
|
14619 | return inputProps.valueLink.requestChange(event.target.value);
|
14620 | } else if (inputProps.checkedLink) {
|
14621 | _assertCheckedLink(inputProps);
|
14622 | return inputProps.checkedLink.requestChange(event.target.checked);
|
14623 | } else if (inputProps.onChange) {
|
14624 | return inputProps.onChange.call(undefined, event);
|
14625 | }
|
14626 | }
|
14627 | };
|
14628 |
|
14629 | module.exports = LinkedValueUtils;
|
14630 | }).call(this,require('_process'))
|
14631 | },{"./ReactPropTypesSecret":224,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131,"react/lib/React":287}],177:[function(require,module,exports){
|
14632 | (function (process){
|
14633 | /**
|
14634 | * Copyright 2013-present, Facebook, Inc.
|
14635 | * All rights reserved.
|
14636 | *
|
14637 | * This source code is licensed under the BSD-style license found in the
|
14638 | * LICENSE file in the root directory of this source tree. An additional grant
|
14639 | * of patent rights can be found in the PATENTS file in the same directory.
|
14640 | *
|
14641 | *
|
14642 | */
|
14643 |
|
14644 | 'use strict';
|
14645 |
|
14646 | var _prodInvariant = require('./reactProdInvariant');
|
14647 |
|
14648 | var invariant = require('fbjs/lib/invariant');
|
14649 |
|
14650 | /**
|
14651 | * Static poolers. Several custom versions for each potential number of
|
14652 | * arguments. A completely generic pooler is easy to implement, but would
|
14653 | * require accessing the `arguments` object. In each of these, `this` refers to
|
14654 | * the Class itself, not an instance. If any others are needed, simply add them
|
14655 | * here, or in their own files.
|
14656 | */
|
14657 | var oneArgumentPooler = function (copyFieldsFrom) {
|
14658 | var Klass = this;
|
14659 | if (Klass.instancePool.length) {
|
14660 | var instance = Klass.instancePool.pop();
|
14661 | Klass.call(instance, copyFieldsFrom);
|
14662 | return instance;
|
14663 | } else {
|
14664 | return new Klass(copyFieldsFrom);
|
14665 | }
|
14666 | };
|
14667 |
|
14668 | var twoArgumentPooler = function (a1, a2) {
|
14669 | var Klass = this;
|
14670 | if (Klass.instancePool.length) {
|
14671 | var instance = Klass.instancePool.pop();
|
14672 | Klass.call(instance, a1, a2);
|
14673 | return instance;
|
14674 | } else {
|
14675 | return new Klass(a1, a2);
|
14676 | }
|
14677 | };
|
14678 |
|
14679 | var threeArgumentPooler = function (a1, a2, a3) {
|
14680 | var Klass = this;
|
14681 | if (Klass.instancePool.length) {
|
14682 | var instance = Klass.instancePool.pop();
|
14683 | Klass.call(instance, a1, a2, a3);
|
14684 | return instance;
|
14685 | } else {
|
14686 | return new Klass(a1, a2, a3);
|
14687 | }
|
14688 | };
|
14689 |
|
14690 | var fourArgumentPooler = function (a1, a2, a3, a4) {
|
14691 | var Klass = this;
|
14692 | if (Klass.instancePool.length) {
|
14693 | var instance = Klass.instancePool.pop();
|
14694 | Klass.call(instance, a1, a2, a3, a4);
|
14695 | return instance;
|
14696 | } else {
|
14697 | return new Klass(a1, a2, a3, a4);
|
14698 | }
|
14699 | };
|
14700 |
|
14701 | var fiveArgumentPooler = function (a1, a2, a3, a4, a5) {
|
14702 | var Klass = this;
|
14703 | if (Klass.instancePool.length) {
|
14704 | var instance = Klass.instancePool.pop();
|
14705 | Klass.call(instance, a1, a2, a3, a4, a5);
|
14706 | return instance;
|
14707 | } else {
|
14708 | return new Klass(a1, a2, a3, a4, a5);
|
14709 | }
|
14710 | };
|
14711 |
|
14712 | var standardReleaser = function (instance) {
|
14713 | var Klass = this;
|
14714 | !(instance instanceof Klass) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Trying to release an instance into a pool of a different type.') : _prodInvariant('25') : void 0;
|
14715 | instance.destructor();
|
14716 | if (Klass.instancePool.length < Klass.poolSize) {
|
14717 | Klass.instancePool.push(instance);
|
14718 | }
|
14719 | };
|
14720 |
|
14721 | var DEFAULT_POOL_SIZE = 10;
|
14722 | var DEFAULT_POOLER = oneArgumentPooler;
|
14723 |
|
14724 | /**
|
14725 | * Augments `CopyConstructor` to be a poolable class, augmenting only the class
|
14726 | * itself (statically) not adding any prototypical fields. Any CopyConstructor
|
14727 | * you give this may have a `poolSize` property, and will look for a
|
14728 | * prototypical `destructor` on instances.
|
14729 | *
|
14730 | * @param {Function} CopyConstructor Constructor that can be used to reset.
|
14731 | * @param {Function} pooler Customizable pooler.
|
14732 | */
|
14733 | var addPoolingTo = function (CopyConstructor, pooler) {
|
14734 | // Casting as any so that flow ignores the actual implementation and trusts
|
14735 | // it to match the type we declared
|
14736 | var NewKlass = CopyConstructor;
|
14737 | NewKlass.instancePool = [];
|
14738 | NewKlass.getPooled = pooler || DEFAULT_POOLER;
|
14739 | if (!NewKlass.poolSize) {
|
14740 | NewKlass.poolSize = DEFAULT_POOL_SIZE;
|
14741 | }
|
14742 | NewKlass.release = standardReleaser;
|
14743 | return NewKlass;
|
14744 | };
|
14745 |
|
14746 | var PooledClass = {
|
14747 | addPoolingTo: addPoolingTo,
|
14748 | oneArgumentPooler: oneArgumentPooler,
|
14749 | twoArgumentPooler: twoArgumentPooler,
|
14750 | threeArgumentPooler: threeArgumentPooler,
|
14751 | fourArgumentPooler: fourArgumentPooler,
|
14752 | fiveArgumentPooler: fiveArgumentPooler
|
14753 | };
|
14754 |
|
14755 | module.exports = PooledClass;
|
14756 | }).call(this,require('_process'))
|
14757 | },{"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],178:[function(require,module,exports){
|
14758 | /**
|
14759 | * Copyright 2013-present, Facebook, Inc.
|
14760 | * All rights reserved.
|
14761 | *
|
14762 | * This source code is licensed under the BSD-style license found in the
|
14763 | * LICENSE file in the root directory of this source tree. An additional grant
|
14764 | * of patent rights can be found in the PATENTS file in the same directory.
|
14765 | *
|
14766 | */
|
14767 |
|
14768 | 'use strict';
|
14769 |
|
14770 | var _assign = require('object-assign');
|
14771 |
|
14772 | var EventPluginRegistry = require('./EventPluginRegistry');
|
14773 | var ReactEventEmitterMixin = require('./ReactEventEmitterMixin');
|
14774 | var ViewportMetrics = require('./ViewportMetrics');
|
14775 |
|
14776 | var getVendorPrefixedEventName = require('./getVendorPrefixedEventName');
|
14777 | var isEventSupported = require('./isEventSupported');
|
14778 |
|
14779 | /**
|
14780 | * Summary of `ReactBrowserEventEmitter` event handling:
|
14781 | *
|
14782 | * - Top-level delegation is used to trap most native browser events. This
|
14783 | * may only occur in the main thread and is the responsibility of
|
14784 | * ReactEventListener, which is injected and can therefore support pluggable
|
14785 | * event sources. This is the only work that occurs in the main thread.
|
14786 | *
|
14787 | * - We normalize and de-duplicate events to account for browser quirks. This
|
14788 | * may be done in the worker thread.
|
14789 | *
|
14790 | * - Forward these native events (with the associated top-level type used to
|
14791 | * trap it) to `EventPluginHub`, which in turn will ask plugins if they want
|
14792 | * to extract any synthetic events.
|
14793 | *
|
14794 | * - The `EventPluginHub` will then process each event by annotating them with
|
14795 | * "dispatches", a sequence of listeners and IDs that care about that event.
|
14796 | *
|
14797 | * - The `EventPluginHub` then dispatches the events.
|
14798 | *
|
14799 | * Overview of React and the event system:
|
14800 | *
|
14801 | * +------------+ .
|
14802 | * | DOM | .
|
14803 | * +------------+ .
|
14804 | * | .
|
14805 | * v .
|
14806 | * +------------+ .
|
14807 | * | ReactEvent | .
|
14808 | * | Listener | .
|
14809 | * +------------+ . +-----------+
|
14810 | * | . +--------+|SimpleEvent|
|
14811 | * | . | |Plugin |
|
14812 | * +-----|------+ . v +-----------+
|
14813 | * | | | . +--------------+ +------------+
|
14814 | * | +-----------.--->|EventPluginHub| | Event |
|
14815 | * | | . | | +-----------+ | Propagators|
|
14816 | * | ReactEvent | . | | |TapEvent | |------------|
|
14817 | * | Emitter | . | |<---+|Plugin | |other plugin|
|
14818 | * | | . | | +-----------+ | utilities |
|
14819 | * | +-----------.--->| | +------------+
|
14820 | * | | | . +--------------+
|
14821 | * +-----|------+ . ^ +-----------+
|
14822 | * | . | |Enter/Leave|
|
14823 | * + . +-------+|Plugin |
|
14824 | * +-------------+ . +-----------+
|
14825 | * | application | .
|
14826 | * |-------------| .
|
14827 | * | | .
|
14828 | * | | .
|
14829 | * +-------------+ .
|
14830 | * .
|
14831 | * React Core . General Purpose Event Plugin System
|
14832 | */
|
14833 |
|
14834 | var hasEventPageXY;
|
14835 | var alreadyListeningTo = {};
|
14836 | var isMonitoringScrollValue = false;
|
14837 | var reactTopListenersCounter = 0;
|
14838 |
|
14839 | // For events like 'submit' which don't consistently bubble (which we trap at a
|
14840 | // lower node than `document`), binding at `document` would cause duplicate
|
14841 | // events so we don't include them here
|
14842 | var topEventMapping = {
|
14843 | topAbort: 'abort',
|
14844 | topAnimationEnd: getVendorPrefixedEventName('animationend') || 'animationend',
|
14845 | topAnimationIteration: getVendorPrefixedEventName('animationiteration') || 'animationiteration',
|
14846 | topAnimationStart: getVendorPrefixedEventName('animationstart') || 'animationstart',
|
14847 | topBlur: 'blur',
|
14848 | topCanPlay: 'canplay',
|
14849 | topCanPlayThrough: 'canplaythrough',
|
14850 | topChange: 'change',
|
14851 | topClick: 'click',
|
14852 | topCompositionEnd: 'compositionend',
|
14853 | topCompositionStart: 'compositionstart',
|
14854 | topCompositionUpdate: 'compositionupdate',
|
14855 | topContextMenu: 'contextmenu',
|
14856 | topCopy: 'copy',
|
14857 | topCut: 'cut',
|
14858 | topDoubleClick: 'dblclick',
|
14859 | topDrag: 'drag',
|
14860 | topDragEnd: 'dragend',
|
14861 | topDragEnter: 'dragenter',
|
14862 | topDragExit: 'dragexit',
|
14863 | topDragLeave: 'dragleave',
|
14864 | topDragOver: 'dragover',
|
14865 | topDragStart: 'dragstart',
|
14866 | topDrop: 'drop',
|
14867 | topDurationChange: 'durationchange',
|
14868 | topEmptied: 'emptied',
|
14869 | topEncrypted: 'encrypted',
|
14870 | topEnded: 'ended',
|
14871 | topError: 'error',
|
14872 | topFocus: 'focus',
|
14873 | topInput: 'input',
|
14874 | topKeyDown: 'keydown',
|
14875 | topKeyPress: 'keypress',
|
14876 | topKeyUp: 'keyup',
|
14877 | topLoadedData: 'loadeddata',
|
14878 | topLoadedMetadata: 'loadedmetadata',
|
14879 | topLoadStart: 'loadstart',
|
14880 | topMouseDown: 'mousedown',
|
14881 | topMouseMove: 'mousemove',
|
14882 | topMouseOut: 'mouseout',
|
14883 | topMouseOver: 'mouseover',
|
14884 | topMouseUp: 'mouseup',
|
14885 | topPaste: 'paste',
|
14886 | topPause: 'pause',
|
14887 | topPlay: 'play',
|
14888 | topPlaying: 'playing',
|
14889 | topProgress: 'progress',
|
14890 | topRateChange: 'ratechange',
|
14891 | topScroll: 'scroll',
|
14892 | topSeeked: 'seeked',
|
14893 | topSeeking: 'seeking',
|
14894 | topSelectionChange: 'selectionchange',
|
14895 | topStalled: 'stalled',
|
14896 | topSuspend: 'suspend',
|
14897 | topTextInput: 'textInput',
|
14898 | topTimeUpdate: 'timeupdate',
|
14899 | topTouchCancel: 'touchcancel',
|
14900 | topTouchEnd: 'touchend',
|
14901 | topTouchMove: 'touchmove',
|
14902 | topTouchStart: 'touchstart',
|
14903 | topTransitionEnd: getVendorPrefixedEventName('transitionend') || 'transitionend',
|
14904 | topVolumeChange: 'volumechange',
|
14905 | topWaiting: 'waiting',
|
14906 | topWheel: 'wheel'
|
14907 | };
|
14908 |
|
14909 | /**
|
14910 | * To ensure no conflicts with other potential React instances on the page
|
14911 | */
|
14912 | var topListenersIDKey = '_reactListenersID' + String(Math.random()).slice(2);
|
14913 |
|
14914 | function getListeningForDocument(mountAt) {
|
14915 | // In IE8, `mountAt` is a host object and doesn't have `hasOwnProperty`
|
14916 | // directly.
|
14917 | if (!Object.prototype.hasOwnProperty.call(mountAt, topListenersIDKey)) {
|
14918 | mountAt[topListenersIDKey] = reactTopListenersCounter++;
|
14919 | alreadyListeningTo[mountAt[topListenersIDKey]] = {};
|
14920 | }
|
14921 | return alreadyListeningTo[mountAt[topListenersIDKey]];
|
14922 | }
|
14923 |
|
14924 | /**
|
14925 | * `ReactBrowserEventEmitter` is used to attach top-level event listeners. For
|
14926 | * example:
|
14927 | *
|
14928 | * EventPluginHub.putListener('myID', 'onClick', myFunction);
|
14929 | *
|
14930 | * This would allocate a "registration" of `('onClick', myFunction)` on 'myID'.
|
14931 | *
|
14932 | * @internal
|
14933 | */
|
14934 | var ReactBrowserEventEmitter = _assign({}, ReactEventEmitterMixin, {
|
14935 |
|
14936 | /**
|
14937 | * Injectable event backend
|
14938 | */
|
14939 | ReactEventListener: null,
|
14940 |
|
14941 | injection: {
|
14942 | /**
|
14943 | * @param {object} ReactEventListener
|
14944 | */
|
14945 | injectReactEventListener: function (ReactEventListener) {
|
14946 | ReactEventListener.setHandleTopLevel(ReactBrowserEventEmitter.handleTopLevel);
|
14947 | ReactBrowserEventEmitter.ReactEventListener = ReactEventListener;
|
14948 | }
|
14949 | },
|
14950 |
|
14951 | /**
|
14952 | * Sets whether or not any created callbacks should be enabled.
|
14953 | *
|
14954 | * @param {boolean} enabled True if callbacks should be enabled.
|
14955 | */
|
14956 | setEnabled: function (enabled) {
|
14957 | if (ReactBrowserEventEmitter.ReactEventListener) {
|
14958 | ReactBrowserEventEmitter.ReactEventListener.setEnabled(enabled);
|
14959 | }
|
14960 | },
|
14961 |
|
14962 | /**
|
14963 | * @return {boolean} True if callbacks are enabled.
|
14964 | */
|
14965 | isEnabled: function () {
|
14966 | return !!(ReactBrowserEventEmitter.ReactEventListener && ReactBrowserEventEmitter.ReactEventListener.isEnabled());
|
14967 | },
|
14968 |
|
14969 | /**
|
14970 | * We listen for bubbled touch events on the document object.
|
14971 | *
|
14972 | * Firefox v8.01 (and possibly others) exhibited strange behavior when
|
14973 | * mounting `onmousemove` events at some node that was not the document
|
14974 | * element. The symptoms were that if your mouse is not moving over something
|
14975 | * contained within that mount point (for example on the background) the
|
14976 | * top-level listeners for `onmousemove` won't be called. However, if you
|
14977 | * register the `mousemove` on the document object, then it will of course
|
14978 | * catch all `mousemove`s. This along with iOS quirks, justifies restricting
|
14979 | * top-level listeners to the document object only, at least for these
|
14980 | * movement types of events and possibly all events.
|
14981 | *
|
14982 | * @see http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
|
14983 | *
|
14984 | * Also, `keyup`/`keypress`/`keydown` do not bubble to the window on IE, but
|
14985 | * they bubble to document.
|
14986 | *
|
14987 | * @param {string} registrationName Name of listener (e.g. `onClick`).
|
14988 | * @param {object} contentDocumentHandle Document which owns the container
|
14989 | */
|
14990 | listenTo: function (registrationName, contentDocumentHandle) {
|
14991 | var mountAt = contentDocumentHandle;
|
14992 | var isListening = getListeningForDocument(mountAt);
|
14993 | var dependencies = EventPluginRegistry.registrationNameDependencies[registrationName];
|
14994 |
|
14995 | for (var i = 0; i < dependencies.length; i++) {
|
14996 | var dependency = dependencies[i];
|
14997 | if (!(isListening.hasOwnProperty(dependency) && isListening[dependency])) {
|
14998 | if (dependency === 'topWheel') {
|
14999 | if (isEventSupported('wheel')) {
|
15000 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topWheel', 'wheel', mountAt);
|
15001 | } else if (isEventSupported('mousewheel')) {
|
15002 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topWheel', 'mousewheel', mountAt);
|
15003 | } else {
|
15004 | // Firefox needs to capture a different mouse scroll event.
|
15005 | // @see http://www.quirksmode.org/dom/events/tests/scroll.html
|
15006 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topWheel', 'DOMMouseScroll', mountAt);
|
15007 | }
|
15008 | } else if (dependency === 'topScroll') {
|
15009 |
|
15010 | if (isEventSupported('scroll', true)) {
|
15011 | ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent('topScroll', 'scroll', mountAt);
|
15012 | } else {
|
15013 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topScroll', 'scroll', ReactBrowserEventEmitter.ReactEventListener.WINDOW_HANDLE);
|
15014 | }
|
15015 | } else if (dependency === 'topFocus' || dependency === 'topBlur') {
|
15016 |
|
15017 | if (isEventSupported('focus', true)) {
|
15018 | ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent('topFocus', 'focus', mountAt);
|
15019 | ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent('topBlur', 'blur', mountAt);
|
15020 | } else if (isEventSupported('focusin')) {
|
15021 | // IE has `focusin` and `focusout` events which bubble.
|
15022 | // @see http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html
|
15023 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topFocus', 'focusin', mountAt);
|
15024 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topBlur', 'focusout', mountAt);
|
15025 | }
|
15026 |
|
15027 | // to make sure blur and focus event listeners are only attached once
|
15028 | isListening.topBlur = true;
|
15029 | isListening.topFocus = true;
|
15030 | } else if (topEventMapping.hasOwnProperty(dependency)) {
|
15031 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(dependency, topEventMapping[dependency], mountAt);
|
15032 | }
|
15033 |
|
15034 | isListening[dependency] = true;
|
15035 | }
|
15036 | }
|
15037 | },
|
15038 |
|
15039 | trapBubbledEvent: function (topLevelType, handlerBaseName, handle) {
|
15040 | return ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(topLevelType, handlerBaseName, handle);
|
15041 | },
|
15042 |
|
15043 | trapCapturedEvent: function (topLevelType, handlerBaseName, handle) {
|
15044 | return ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent(topLevelType, handlerBaseName, handle);
|
15045 | },
|
15046 |
|
15047 | /**
|
15048 | * Protect against document.createEvent() returning null
|
15049 | * Some popup blocker extensions appear to do this:
|
15050 | * https://github.com/facebook/react/issues/6887
|
15051 | */
|
15052 | supportsEventPageXY: function () {
|
15053 | if (!document.createEvent) {
|
15054 | return false;
|
15055 | }
|
15056 | var ev = document.createEvent('MouseEvent');
|
15057 | return ev != null && 'pageX' in ev;
|
15058 | },
|
15059 |
|
15060 | /**
|
15061 | * Listens to window scroll and resize events. We cache scroll values so that
|
15062 | * application code can access them without triggering reflows.
|
15063 | *
|
15064 | * ViewportMetrics is only used by SyntheticMouse/TouchEvent and only when
|
15065 | * pageX/pageY isn't supported (legacy browsers).
|
15066 | *
|
15067 | * NOTE: Scroll events do not bubble.
|
15068 | *
|
15069 | * @see http://www.quirksmode.org/dom/events/scroll.html
|
15070 | */
|
15071 | ensureScrollValueMonitoring: function () {
|
15072 | if (hasEventPageXY === undefined) {
|
15073 | hasEventPageXY = ReactBrowserEventEmitter.supportsEventPageXY();
|
15074 | }
|
15075 | if (!hasEventPageXY && !isMonitoringScrollValue) {
|
15076 | var refresh = ViewportMetrics.refreshScrollValues;
|
15077 | ReactBrowserEventEmitter.ReactEventListener.monitorScrollValue(refresh);
|
15078 | isMonitoringScrollValue = true;
|
15079 | }
|
15080 | }
|
15081 |
|
15082 | });
|
15083 |
|
15084 | module.exports = ReactBrowserEventEmitter;
|
15085 | },{"./EventPluginRegistry":170,"./ReactEventEmitterMixin":208,"./ViewportMetrics":252,"./getVendorPrefixedEventName":271,"./isEventSupported":273,"object-assign":143}],179:[function(require,module,exports){
|
15086 | (function (process){
|
15087 | /**
|
15088 | * Copyright 2014-present, Facebook, Inc.
|
15089 | * All rights reserved.
|
15090 | *
|
15091 | * This source code is licensed under the BSD-style license found in the
|
15092 | * LICENSE file in the root directory of this source tree. An additional grant
|
15093 | * of patent rights can be found in the PATENTS file in the same directory.
|
15094 | *
|
15095 | */
|
15096 |
|
15097 | 'use strict';
|
15098 |
|
15099 | var ReactReconciler = require('./ReactReconciler');
|
15100 |
|
15101 | var instantiateReactComponent = require('./instantiateReactComponent');
|
15102 | var KeyEscapeUtils = require('./KeyEscapeUtils');
|
15103 | var shouldUpdateReactComponent = require('./shouldUpdateReactComponent');
|
15104 | var traverseAllChildren = require('./traverseAllChildren');
|
15105 | var warning = require('fbjs/lib/warning');
|
15106 |
|
15107 | var ReactComponentTreeHook;
|
15108 |
|
15109 | if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'test') {
|
15110 | // Temporary hack.
|
15111 | // Inline requires don't work well with Jest:
|
15112 | // https://github.com/facebook/react/issues/7240
|
15113 | // Remove the inline requires when we don't need them anymore:
|
15114 | // https://github.com/facebook/react/pull/7178
|
15115 | ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
15116 | }
|
15117 |
|
15118 | function instantiateChild(childInstances, child, name, selfDebugID) {
|
15119 | // We found a component instance.
|
15120 | var keyUnique = childInstances[name] === undefined;
|
15121 | if (process.env.NODE_ENV !== 'production') {
|
15122 | if (!ReactComponentTreeHook) {
|
15123 | ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
15124 | }
|
15125 | if (!keyUnique) {
|
15126 | process.env.NODE_ENV !== 'production' ? warning(false, 'flattenChildren(...): Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, only ' + 'the first child will be used.%s', KeyEscapeUtils.unescape(name), ReactComponentTreeHook.getStackAddendumByID(selfDebugID)) : void 0;
|
15127 | }
|
15128 | }
|
15129 | if (child != null && keyUnique) {
|
15130 | childInstances[name] = instantiateReactComponent(child, true);
|
15131 | }
|
15132 | }
|
15133 |
|
15134 | /**
|
15135 | * ReactChildReconciler provides helpers for initializing or updating a set of
|
15136 | * children. Its output is suitable for passing it onto ReactMultiChild which
|
15137 | * does diffed reordering and insertion.
|
15138 | */
|
15139 | var ReactChildReconciler = {
|
15140 | /**
|
15141 | * Generates a "mount image" for each of the supplied children. In the case
|
15142 | * of `ReactDOMComponent`, a mount image is a string of markup.
|
15143 | *
|
15144 | * @param {?object} nestedChildNodes Nested child maps.
|
15145 | * @return {?object} A set of child instances.
|
15146 | * @internal
|
15147 | */
|
15148 | instantiateChildren: function (nestedChildNodes, transaction, context, selfDebugID // 0 in production and for roots
|
15149 | ) {
|
15150 | if (nestedChildNodes == null) {
|
15151 | return null;
|
15152 | }
|
15153 | var childInstances = {};
|
15154 |
|
15155 | if (process.env.NODE_ENV !== 'production') {
|
15156 | traverseAllChildren(nestedChildNodes, function (childInsts, child, name) {
|
15157 | return instantiateChild(childInsts, child, name, selfDebugID);
|
15158 | }, childInstances);
|
15159 | } else {
|
15160 | traverseAllChildren(nestedChildNodes, instantiateChild, childInstances);
|
15161 | }
|
15162 | return childInstances;
|
15163 | },
|
15164 |
|
15165 | /**
|
15166 | * Updates the rendered children and returns a new set of children.
|
15167 | *
|
15168 | * @param {?object} prevChildren Previously initialized set of children.
|
15169 | * @param {?object} nextChildren Flat child element maps.
|
15170 | * @param {ReactReconcileTransaction} transaction
|
15171 | * @param {object} context
|
15172 | * @return {?object} A new set of child instances.
|
15173 | * @internal
|
15174 | */
|
15175 | updateChildren: function (prevChildren, nextChildren, mountImages, removedNodes, transaction, hostParent, hostContainerInfo, context, selfDebugID // 0 in production and for roots
|
15176 | ) {
|
15177 | // We currently don't have a way to track moves here but if we use iterators
|
15178 | // instead of for..in we can zip the iterators and check if an item has
|
15179 | // moved.
|
15180 | // TODO: If nothing has changed, return the prevChildren object so that we
|
15181 | // can quickly bailout if nothing has changed.
|
15182 | if (!nextChildren && !prevChildren) {
|
15183 | return;
|
15184 | }
|
15185 | var name;
|
15186 | var prevChild;
|
15187 | for (name in nextChildren) {
|
15188 | if (!nextChildren.hasOwnProperty(name)) {
|
15189 | continue;
|
15190 | }
|
15191 | prevChild = prevChildren && prevChildren[name];
|
15192 | var prevElement = prevChild && prevChild._currentElement;
|
15193 | var nextElement = nextChildren[name];
|
15194 | if (prevChild != null && shouldUpdateReactComponent(prevElement, nextElement)) {
|
15195 | ReactReconciler.receiveComponent(prevChild, nextElement, transaction, context);
|
15196 | nextChildren[name] = prevChild;
|
15197 | } else {
|
15198 | if (prevChild) {
|
15199 | removedNodes[name] = ReactReconciler.getHostNode(prevChild);
|
15200 | ReactReconciler.unmountComponent(prevChild, false);
|
15201 | }
|
15202 | // The child must be instantiated before it's mounted.
|
15203 | var nextChildInstance = instantiateReactComponent(nextElement, true);
|
15204 | nextChildren[name] = nextChildInstance;
|
15205 | // Creating mount image now ensures refs are resolved in right order
|
15206 | // (see https://github.com/facebook/react/pull/7101 for explanation).
|
15207 | var nextChildMountImage = ReactReconciler.mountComponent(nextChildInstance, transaction, hostParent, hostContainerInfo, context, selfDebugID);
|
15208 | mountImages.push(nextChildMountImage);
|
15209 | }
|
15210 | }
|
15211 | // Unmount children that are no longer present.
|
15212 | for (name in prevChildren) {
|
15213 | if (prevChildren.hasOwnProperty(name) && !(nextChildren && nextChildren.hasOwnProperty(name))) {
|
15214 | prevChild = prevChildren[name];
|
15215 | removedNodes[name] = ReactReconciler.getHostNode(prevChild);
|
15216 | ReactReconciler.unmountComponent(prevChild, false);
|
15217 | }
|
15218 | }
|
15219 | },
|
15220 |
|
15221 | /**
|
15222 | * Unmounts all rendered children. This should be used to clean up children
|
15223 | * when this component is unmounted.
|
15224 | *
|
15225 | * @param {?object} renderedChildren Previously initialized set of children.
|
15226 | * @internal
|
15227 | */
|
15228 | unmountChildren: function (renderedChildren, safely) {
|
15229 | for (var name in renderedChildren) {
|
15230 | if (renderedChildren.hasOwnProperty(name)) {
|
15231 | var renderedChild = renderedChildren[name];
|
15232 | ReactReconciler.unmountComponent(renderedChild, safely);
|
15233 | }
|
15234 | }
|
15235 | }
|
15236 |
|
15237 | };
|
15238 |
|
15239 | module.exports = ReactChildReconciler;
|
15240 | }).call(this,require('_process'))
|
15241 | },{"./KeyEscapeUtils":175,"./ReactReconciler":226,"./instantiateReactComponent":272,"./shouldUpdateReactComponent":280,"./traverseAllChildren":281,"_process":144,"fbjs/lib/warning":131,"react/lib/ReactComponentTreeHook":291}],180:[function(require,module,exports){
|
15242 | /**
|
15243 | * Copyright 2013-present, Facebook, Inc.
|
15244 | * All rights reserved.
|
15245 | *
|
15246 | * This source code is licensed under the BSD-style license found in the
|
15247 | * LICENSE file in the root directory of this source tree. An additional grant
|
15248 | * of patent rights can be found in the PATENTS file in the same directory.
|
15249 | *
|
15250 | */
|
15251 |
|
15252 | 'use strict';
|
15253 |
|
15254 | var DOMChildrenOperations = require('./DOMChildrenOperations');
|
15255 | var ReactDOMIDOperations = require('./ReactDOMIDOperations');
|
15256 |
|
15257 | /**
|
15258 | * Abstracts away all functionality of the reconciler that requires knowledge of
|
15259 | * the browser context. TODO: These callers should be refactored to avoid the
|
15260 | * need for this injection.
|
15261 | */
|
15262 | var ReactComponentBrowserEnvironment = {
|
15263 |
|
15264 | processChildrenUpdates: ReactDOMIDOperations.dangerouslyProcessChildrenUpdates,
|
15265 |
|
15266 | replaceNodeWithMarkup: DOMChildrenOperations.dangerouslyReplaceNodeWithMarkup
|
15267 |
|
15268 | };
|
15269 |
|
15270 | module.exports = ReactComponentBrowserEnvironment;
|
15271 | },{"./DOMChildrenOperations":161,"./ReactDOMIDOperations":190}],181:[function(require,module,exports){
|
15272 | (function (process){
|
15273 | /**
|
15274 | * Copyright 2014-present, Facebook, Inc.
|
15275 | * All rights reserved.
|
15276 | *
|
15277 | * This source code is licensed under the BSD-style license found in the
|
15278 | * LICENSE file in the root directory of this source tree. An additional grant
|
15279 | * of patent rights can be found in the PATENTS file in the same directory.
|
15280 | *
|
15281 | *
|
15282 | */
|
15283 |
|
15284 | 'use strict';
|
15285 |
|
15286 | var _prodInvariant = require('./reactProdInvariant');
|
15287 |
|
15288 | var invariant = require('fbjs/lib/invariant');
|
15289 |
|
15290 | var injected = false;
|
15291 |
|
15292 | var ReactComponentEnvironment = {
|
15293 |
|
15294 | /**
|
15295 | * Optionally injectable hook for swapping out mount images in the middle of
|
15296 | * the tree.
|
15297 | */
|
15298 | replaceNodeWithMarkup: null,
|
15299 |
|
15300 | /**
|
15301 | * Optionally injectable hook for processing a queue of child updates. Will
|
15302 | * later move into MultiChildComponents.
|
15303 | */
|
15304 | processChildrenUpdates: null,
|
15305 |
|
15306 | injection: {
|
15307 | injectEnvironment: function (environment) {
|
15308 | !!injected ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactCompositeComponent: injectEnvironment() can only be called once.') : _prodInvariant('104') : void 0;
|
15309 | ReactComponentEnvironment.replaceNodeWithMarkup = environment.replaceNodeWithMarkup;
|
15310 | ReactComponentEnvironment.processChildrenUpdates = environment.processChildrenUpdates;
|
15311 | injected = true;
|
15312 | }
|
15313 | }
|
15314 |
|
15315 | };
|
15316 |
|
15317 | module.exports = ReactComponentEnvironment;
|
15318 | }).call(this,require('_process'))
|
15319 | },{"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],182:[function(require,module,exports){
|
15320 | (function (process){
|
15321 | /**
|
15322 | * Copyright 2013-present, Facebook, Inc.
|
15323 | * All rights reserved.
|
15324 | *
|
15325 | * This source code is licensed under the BSD-style license found in the
|
15326 | * LICENSE file in the root directory of this source tree. An additional grant
|
15327 | * of patent rights can be found in the PATENTS file in the same directory.
|
15328 | *
|
15329 | */
|
15330 |
|
15331 | 'use strict';
|
15332 |
|
15333 | var _prodInvariant = require('./reactProdInvariant'),
|
15334 | _assign = require('object-assign');
|
15335 |
|
15336 | var React = require('react/lib/React');
|
15337 | var ReactComponentEnvironment = require('./ReactComponentEnvironment');
|
15338 | var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
15339 | var ReactErrorUtils = require('./ReactErrorUtils');
|
15340 | var ReactInstanceMap = require('./ReactInstanceMap');
|
15341 | var ReactInstrumentation = require('./ReactInstrumentation');
|
15342 | var ReactNodeTypes = require('./ReactNodeTypes');
|
15343 | var ReactReconciler = require('./ReactReconciler');
|
15344 |
|
15345 | if (process.env.NODE_ENV !== 'production') {
|
15346 | var checkReactTypeSpec = require('./checkReactTypeSpec');
|
15347 | }
|
15348 |
|
15349 | var emptyObject = require('fbjs/lib/emptyObject');
|
15350 | var invariant = require('fbjs/lib/invariant');
|
15351 | var shallowEqual = require('fbjs/lib/shallowEqual');
|
15352 | var shouldUpdateReactComponent = require('./shouldUpdateReactComponent');
|
15353 | var warning = require('fbjs/lib/warning');
|
15354 |
|
15355 | var CompositeTypes = {
|
15356 | ImpureClass: 0,
|
15357 | PureClass: 1,
|
15358 | StatelessFunctional: 2
|
15359 | };
|
15360 |
|
15361 | function StatelessComponent(Component) {}
|
15362 | StatelessComponent.prototype.render = function () {
|
15363 | var Component = ReactInstanceMap.get(this)._currentElement.type;
|
15364 | var element = Component(this.props, this.context, this.updater);
|
15365 | warnIfInvalidElement(Component, element);
|
15366 | return element;
|
15367 | };
|
15368 |
|
15369 | function warnIfInvalidElement(Component, element) {
|
15370 | if (process.env.NODE_ENV !== 'production') {
|
15371 | process.env.NODE_ENV !== 'production' ? warning(element === null || element === false || React.isValidElement(element), '%s(...): A valid React element (or null) must be returned. You may have ' + 'returned undefined, an array or some other invalid object.', Component.displayName || Component.name || 'Component') : void 0;
|
15372 | process.env.NODE_ENV !== 'production' ? warning(!Component.childContextTypes, '%s(...): childContextTypes cannot be defined on a functional component.', Component.displayName || Component.name || 'Component') : void 0;
|
15373 | }
|
15374 | }
|
15375 |
|
15376 | function shouldConstruct(Component) {
|
15377 | return !!(Component.prototype && Component.prototype.isReactComponent);
|
15378 | }
|
15379 |
|
15380 | function isPureComponent(Component) {
|
15381 | return !!(Component.prototype && Component.prototype.isPureReactComponent);
|
15382 | }
|
15383 |
|
15384 | // Separated into a function to contain deoptimizations caused by try/finally.
|
15385 | function measureLifeCyclePerf(fn, debugID, timerType) {
|
15386 | if (debugID === 0) {
|
15387 | // Top-level wrappers (see ReactMount) and empty components (see
|
15388 | // ReactDOMEmptyComponent) are invisible to hooks and devtools.
|
15389 | // Both are implementation details that should go away in the future.
|
15390 | return fn();
|
15391 | }
|
15392 |
|
15393 | ReactInstrumentation.debugTool.onBeginLifeCycleTimer(debugID, timerType);
|
15394 | try {
|
15395 | return fn();
|
15396 | } finally {
|
15397 | ReactInstrumentation.debugTool.onEndLifeCycleTimer(debugID, timerType);
|
15398 | }
|
15399 | }
|
15400 |
|
15401 | /**
|
15402 | * ------------------ The Life-Cycle of a Composite Component ------------------
|
15403 | *
|
15404 | * - constructor: Initialization of state. The instance is now retained.
|
15405 | * - componentWillMount
|
15406 | * - render
|
15407 | * - [children's constructors]
|
15408 | * - [children's componentWillMount and render]
|
15409 | * - [children's componentDidMount]
|
15410 | * - componentDidMount
|
15411 | *
|
15412 | * Update Phases:
|
15413 | * - componentWillReceiveProps (only called if parent updated)
|
15414 | * - shouldComponentUpdate
|
15415 | * - componentWillUpdate
|
15416 | * - render
|
15417 | * - [children's constructors or receive props phases]
|
15418 | * - componentDidUpdate
|
15419 | *
|
15420 | * - componentWillUnmount
|
15421 | * - [children's componentWillUnmount]
|
15422 | * - [children destroyed]
|
15423 | * - (destroyed): The instance is now blank, released by React and ready for GC.
|
15424 | *
|
15425 | * -----------------------------------------------------------------------------
|
15426 | */
|
15427 |
|
15428 | /**
|
15429 | * An incrementing ID assigned to each component when it is mounted. This is
|
15430 | * used to enforce the order in which `ReactUpdates` updates dirty components.
|
15431 | *
|
15432 | * @private
|
15433 | */
|
15434 | var nextMountID = 1;
|
15435 |
|
15436 | /**
|
15437 | * @lends {ReactCompositeComponent.prototype}
|
15438 | */
|
15439 | var ReactCompositeComponent = {
|
15440 |
|
15441 | /**
|
15442 | * Base constructor for all composite component.
|
15443 | *
|
15444 | * @param {ReactElement} element
|
15445 | * @final
|
15446 | * @internal
|
15447 | */
|
15448 | construct: function (element) {
|
15449 | this._currentElement = element;
|
15450 | this._rootNodeID = 0;
|
15451 | this._compositeType = null;
|
15452 | this._instance = null;
|
15453 | this._hostParent = null;
|
15454 | this._hostContainerInfo = null;
|
15455 |
|
15456 | // See ReactUpdateQueue
|
15457 | this._updateBatchNumber = null;
|
15458 | this._pendingElement = null;
|
15459 | this._pendingStateQueue = null;
|
15460 | this._pendingReplaceState = false;
|
15461 | this._pendingForceUpdate = false;
|
15462 |
|
15463 | this._renderedNodeType = null;
|
15464 | this._renderedComponent = null;
|
15465 | this._context = null;
|
15466 | this._mountOrder = 0;
|
15467 | this._topLevelWrapper = null;
|
15468 |
|
15469 | // See ReactUpdates and ReactUpdateQueue.
|
15470 | this._pendingCallbacks = null;
|
15471 |
|
15472 | // ComponentWillUnmount shall only be called once
|
15473 | this._calledComponentWillUnmount = false;
|
15474 |
|
15475 | if (process.env.NODE_ENV !== 'production') {
|
15476 | this._warnedAboutRefsInRender = false;
|
15477 | }
|
15478 | },
|
15479 |
|
15480 | /**
|
15481 | * Initializes the component, renders markup, and registers event listeners.
|
15482 | *
|
15483 | * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
15484 | * @param {?object} hostParent
|
15485 | * @param {?object} hostContainerInfo
|
15486 | * @param {?object} context
|
15487 | * @return {?string} Rendered markup to be inserted into the DOM.
|
15488 | * @final
|
15489 | * @internal
|
15490 | */
|
15491 | mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
|
15492 | var _this = this;
|
15493 |
|
15494 | this._context = context;
|
15495 | this._mountOrder = nextMountID++;
|
15496 | this._hostParent = hostParent;
|
15497 | this._hostContainerInfo = hostContainerInfo;
|
15498 |
|
15499 | var publicProps = this._currentElement.props;
|
15500 | var publicContext = this._processContext(context);
|
15501 |
|
15502 | var Component = this._currentElement.type;
|
15503 |
|
15504 | var updateQueue = transaction.getUpdateQueue();
|
15505 |
|
15506 | // Initialize the public class
|
15507 | var doConstruct = shouldConstruct(Component);
|
15508 | var inst = this._constructComponent(doConstruct, publicProps, publicContext, updateQueue);
|
15509 | var renderedElement;
|
15510 |
|
15511 | // Support functional components
|
15512 | if (!doConstruct && (inst == null || inst.render == null)) {
|
15513 | renderedElement = inst;
|
15514 | warnIfInvalidElement(Component, renderedElement);
|
15515 | !(inst === null || inst === false || React.isValidElement(inst)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s(...): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.', Component.displayName || Component.name || 'Component') : _prodInvariant('105', Component.displayName || Component.name || 'Component') : void 0;
|
15516 | inst = new StatelessComponent(Component);
|
15517 | this._compositeType = CompositeTypes.StatelessFunctional;
|
15518 | } else {
|
15519 | if (isPureComponent(Component)) {
|
15520 | this._compositeType = CompositeTypes.PureClass;
|
15521 | } else {
|
15522 | this._compositeType = CompositeTypes.ImpureClass;
|
15523 | }
|
15524 | }
|
15525 |
|
15526 | if (process.env.NODE_ENV !== 'production') {
|
15527 | // This will throw later in _renderValidatedComponent, but add an early
|
15528 | // warning now to help debugging
|
15529 | if (inst.render == null) {
|
15530 | process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', Component.displayName || Component.name || 'Component') : void 0;
|
15531 | }
|
15532 |
|
15533 | var propsMutated = inst.props !== publicProps;
|
15534 | var componentName = Component.displayName || Component.name || 'Component';
|
15535 |
|
15536 | process.env.NODE_ENV !== 'production' ? warning(inst.props === undefined || !propsMutated, '%s(...): When calling super() in `%s`, make sure to pass ' + 'up the same props that your component\'s constructor was passed.', componentName, componentName) : void 0;
|
15537 | }
|
15538 |
|
15539 | // These should be set up in the constructor, but as a convenience for
|
15540 | // simpler class abstractions, we set them up after the fact.
|
15541 | inst.props = publicProps;
|
15542 | inst.context = publicContext;
|
15543 | inst.refs = emptyObject;
|
15544 | inst.updater = updateQueue;
|
15545 |
|
15546 | this._instance = inst;
|
15547 |
|
15548 | // Store a reference from the instance back to the internal representation
|
15549 | ReactInstanceMap.set(inst, this);
|
15550 |
|
15551 | if (process.env.NODE_ENV !== 'production') {
|
15552 | // Since plain JS classes are defined without any special initialization
|
15553 | // logic, we can not catch common errors early. Therefore, we have to
|
15554 | // catch them here, at initialization time, instead.
|
15555 | process.env.NODE_ENV !== 'production' ? warning(!inst.getInitialState || inst.getInitialState.isReactClassApproved, 'getInitialState was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Did you mean to define a state property instead?', this.getName() || 'a component') : void 0;
|
15556 | process.env.NODE_ENV !== 'production' ? warning(!inst.getDefaultProps || inst.getDefaultProps.isReactClassApproved, 'getDefaultProps was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Use a static property to define defaultProps instead.', this.getName() || 'a component') : void 0;
|
15557 | process.env.NODE_ENV !== 'production' ? warning(!inst.propTypes, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', this.getName() || 'a component') : void 0;
|
15558 | process.env.NODE_ENV !== 'production' ? warning(!inst.contextTypes, 'contextTypes was defined as an instance property on %s. Use a ' + 'static property to define contextTypes instead.', this.getName() || 'a component') : void 0;
|
15559 | process.env.NODE_ENV !== 'production' ? warning(typeof inst.componentShouldUpdate !== 'function', '%s has a method called ' + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' + 'The name is phrased as a question because the function is ' + 'expected to return a value.', this.getName() || 'A component') : void 0;
|
15560 | process.env.NODE_ENV !== 'production' ? warning(typeof inst.componentDidUnmount !== 'function', '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', this.getName() || 'A component') : void 0;
|
15561 | process.env.NODE_ENV !== 'production' ? warning(typeof inst.componentWillRecieveProps !== 'function', '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', this.getName() || 'A component') : void 0;
|
15562 | }
|
15563 |
|
15564 | var initialState = inst.state;
|
15565 | if (initialState === undefined) {
|
15566 | inst.state = initialState = null;
|
15567 | }
|
15568 | !(typeof initialState === 'object' && !Array.isArray(initialState)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.state: must be set to an object or null', this.getName() || 'ReactCompositeComponent') : _prodInvariant('106', this.getName() || 'ReactCompositeComponent') : void 0;
|
15569 |
|
15570 | this._pendingStateQueue = null;
|
15571 | this._pendingReplaceState = false;
|
15572 | this._pendingForceUpdate = false;
|
15573 |
|
15574 | var markup;
|
15575 | if (inst.unstable_handleError) {
|
15576 | markup = this.performInitialMountWithErrorHandling(renderedElement, hostParent, hostContainerInfo, transaction, context);
|
15577 | } else {
|
15578 | markup = this.performInitialMount(renderedElement, hostParent, hostContainerInfo, transaction, context);
|
15579 | }
|
15580 |
|
15581 | if (inst.componentDidMount) {
|
15582 | if (process.env.NODE_ENV !== 'production') {
|
15583 | transaction.getReactMountReady().enqueue(function () {
|
15584 | measureLifeCyclePerf(function () {
|
15585 | return inst.componentDidMount();
|
15586 | }, _this._debugID, 'componentDidMount');
|
15587 | });
|
15588 | } else {
|
15589 | transaction.getReactMountReady().enqueue(inst.componentDidMount, inst);
|
15590 | }
|
15591 | }
|
15592 |
|
15593 | return markup;
|
15594 | },
|
15595 |
|
15596 | _constructComponent: function (doConstruct, publicProps, publicContext, updateQueue) {
|
15597 | if (process.env.NODE_ENV !== 'production') {
|
15598 | ReactCurrentOwner.current = this;
|
15599 | try {
|
15600 | return this._constructComponentWithoutOwner(doConstruct, publicProps, publicContext, updateQueue);
|
15601 | } finally {
|
15602 | ReactCurrentOwner.current = null;
|
15603 | }
|
15604 | } else {
|
15605 | return this._constructComponentWithoutOwner(doConstruct, publicProps, publicContext, updateQueue);
|
15606 | }
|
15607 | },
|
15608 |
|
15609 | _constructComponentWithoutOwner: function (doConstruct, publicProps, publicContext, updateQueue) {
|
15610 | var Component = this._currentElement.type;
|
15611 |
|
15612 | if (doConstruct) {
|
15613 | if (process.env.NODE_ENV !== 'production') {
|
15614 | return measureLifeCyclePerf(function () {
|
15615 | return new Component(publicProps, publicContext, updateQueue);
|
15616 | }, this._debugID, 'ctor');
|
15617 | } else {
|
15618 | return new Component(publicProps, publicContext, updateQueue);
|
15619 | }
|
15620 | }
|
15621 |
|
15622 | // This can still be an instance in case of factory components
|
15623 | // but we'll count this as time spent rendering as the more common case.
|
15624 | if (process.env.NODE_ENV !== 'production') {
|
15625 | return measureLifeCyclePerf(function () {
|
15626 | return Component(publicProps, publicContext, updateQueue);
|
15627 | }, this._debugID, 'render');
|
15628 | } else {
|
15629 | return Component(publicProps, publicContext, updateQueue);
|
15630 | }
|
15631 | },
|
15632 |
|
15633 | performInitialMountWithErrorHandling: function (renderedElement, hostParent, hostContainerInfo, transaction, context) {
|
15634 | var markup;
|
15635 | var checkpoint = transaction.checkpoint();
|
15636 | try {
|
15637 | markup = this.performInitialMount(renderedElement, hostParent, hostContainerInfo, transaction, context);
|
15638 | } catch (e) {
|
15639 | // Roll back to checkpoint, handle error (which may add items to the transaction), and take a new checkpoint
|
15640 | transaction.rollback(checkpoint);
|
15641 | this._instance.unstable_handleError(e);
|
15642 | if (this._pendingStateQueue) {
|
15643 | this._instance.state = this._processPendingState(this._instance.props, this._instance.context);
|
15644 | }
|
15645 | checkpoint = transaction.checkpoint();
|
15646 |
|
15647 | this._renderedComponent.unmountComponent(true);
|
15648 | transaction.rollback(checkpoint);
|
15649 |
|
15650 | // Try again - we've informed the component about the error, so they can render an error message this time.
|
15651 | // If this throws again, the error will bubble up (and can be caught by a higher error boundary).
|
15652 | markup = this.performInitialMount(renderedElement, hostParent, hostContainerInfo, transaction, context);
|
15653 | }
|
15654 | return markup;
|
15655 | },
|
15656 |
|
15657 | performInitialMount: function (renderedElement, hostParent, hostContainerInfo, transaction, context) {
|
15658 | var inst = this._instance;
|
15659 |
|
15660 | var debugID = 0;
|
15661 | if (process.env.NODE_ENV !== 'production') {
|
15662 | debugID = this._debugID;
|
15663 | }
|
15664 |
|
15665 | if (inst.componentWillMount) {
|
15666 | if (process.env.NODE_ENV !== 'production') {
|
15667 | measureLifeCyclePerf(function () {
|
15668 | return inst.componentWillMount();
|
15669 | }, debugID, 'componentWillMount');
|
15670 | } else {
|
15671 | inst.componentWillMount();
|
15672 | }
|
15673 | // When mounting, calls to `setState` by `componentWillMount` will set
|
15674 | // `this._pendingStateQueue` without triggering a re-render.
|
15675 | if (this._pendingStateQueue) {
|
15676 | inst.state = this._processPendingState(inst.props, inst.context);
|
15677 | }
|
15678 | }
|
15679 |
|
15680 | // If not a stateless component, we now render
|
15681 | if (renderedElement === undefined) {
|
15682 | renderedElement = this._renderValidatedComponent();
|
15683 | }
|
15684 |
|
15685 | var nodeType = ReactNodeTypes.getType(renderedElement);
|
15686 | this._renderedNodeType = nodeType;
|
15687 | var child = this._instantiateReactComponent(renderedElement, nodeType !== ReactNodeTypes.EMPTY /* shouldHaveDebugID */
|
15688 | );
|
15689 | this._renderedComponent = child;
|
15690 |
|
15691 | var markup = ReactReconciler.mountComponent(child, transaction, hostParent, hostContainerInfo, this._processChildContext(context), debugID);
|
15692 |
|
15693 | if (process.env.NODE_ENV !== 'production') {
|
15694 | if (debugID !== 0) {
|
15695 | var childDebugIDs = child._debugID !== 0 ? [child._debugID] : [];
|
15696 | ReactInstrumentation.debugTool.onSetChildren(debugID, childDebugIDs);
|
15697 | }
|
15698 | }
|
15699 |
|
15700 | return markup;
|
15701 | },
|
15702 |
|
15703 | getHostNode: function () {
|
15704 | return ReactReconciler.getHostNode(this._renderedComponent);
|
15705 | },
|
15706 |
|
15707 | /**
|
15708 | * Releases any resources allocated by `mountComponent`.
|
15709 | *
|
15710 | * @final
|
15711 | * @internal
|
15712 | */
|
15713 | unmountComponent: function (safely) {
|
15714 | if (!this._renderedComponent) {
|
15715 | return;
|
15716 | }
|
15717 |
|
15718 | var inst = this._instance;
|
15719 |
|
15720 | if (inst.componentWillUnmount && !inst._calledComponentWillUnmount) {
|
15721 | inst._calledComponentWillUnmount = true;
|
15722 |
|
15723 | if (safely) {
|
15724 | var name = this.getName() + '.componentWillUnmount()';
|
15725 | ReactErrorUtils.invokeGuardedCallback(name, inst.componentWillUnmount.bind(inst));
|
15726 | } else {
|
15727 | if (process.env.NODE_ENV !== 'production') {
|
15728 | measureLifeCyclePerf(function () {
|
15729 | return inst.componentWillUnmount();
|
15730 | }, this._debugID, 'componentWillUnmount');
|
15731 | } else {
|
15732 | inst.componentWillUnmount();
|
15733 | }
|
15734 | }
|
15735 | }
|
15736 |
|
15737 | if (this._renderedComponent) {
|
15738 | ReactReconciler.unmountComponent(this._renderedComponent, safely);
|
15739 | this._renderedNodeType = null;
|
15740 | this._renderedComponent = null;
|
15741 | this._instance = null;
|
15742 | }
|
15743 |
|
15744 | // Reset pending fields
|
15745 | // Even if this component is scheduled for another update in ReactUpdates,
|
15746 | // it would still be ignored because these fields are reset.
|
15747 | this._pendingStateQueue = null;
|
15748 | this._pendingReplaceState = false;
|
15749 | this._pendingForceUpdate = false;
|
15750 | this._pendingCallbacks = null;
|
15751 | this._pendingElement = null;
|
15752 |
|
15753 | // These fields do not really need to be reset since this object is no
|
15754 | // longer accessible.
|
15755 | this._context = null;
|
15756 | this._rootNodeID = 0;
|
15757 | this._topLevelWrapper = null;
|
15758 |
|
15759 | // Delete the reference from the instance to this internal representation
|
15760 | // which allow the internals to be properly cleaned up even if the user
|
15761 | // leaks a reference to the public instance.
|
15762 | ReactInstanceMap.remove(inst);
|
15763 |
|
15764 | // Some existing components rely on inst.props even after they've been
|
15765 | // destroyed (in event handlers).
|
15766 | // TODO: inst.props = null;
|
15767 | // TODO: inst.state = null;
|
15768 | // TODO: inst.context = null;
|
15769 | },
|
15770 |
|
15771 | /**
|
15772 | * Filters the context object to only contain keys specified in
|
15773 | * `contextTypes`
|
15774 | *
|
15775 | * @param {object} context
|
15776 | * @return {?object}
|
15777 | * @private
|
15778 | */
|
15779 | _maskContext: function (context) {
|
15780 | var Component = this._currentElement.type;
|
15781 | var contextTypes = Component.contextTypes;
|
15782 | if (!contextTypes) {
|
15783 | return emptyObject;
|
15784 | }
|
15785 | var maskedContext = {};
|
15786 | for (var contextName in contextTypes) {
|
15787 | maskedContext[contextName] = context[contextName];
|
15788 | }
|
15789 | return maskedContext;
|
15790 | },
|
15791 |
|
15792 | /**
|
15793 | * Filters the context object to only contain keys specified in
|
15794 | * `contextTypes`, and asserts that they are valid.
|
15795 | *
|
15796 | * @param {object} context
|
15797 | * @return {?object}
|
15798 | * @private
|
15799 | */
|
15800 | _processContext: function (context) {
|
15801 | var maskedContext = this._maskContext(context);
|
15802 | if (process.env.NODE_ENV !== 'production') {
|
15803 | var Component = this._currentElement.type;
|
15804 | if (Component.contextTypes) {
|
15805 | this._checkContextTypes(Component.contextTypes, maskedContext, 'context');
|
15806 | }
|
15807 | }
|
15808 | return maskedContext;
|
15809 | },
|
15810 |
|
15811 | /**
|
15812 | * @param {object} currentContext
|
15813 | * @return {object}
|
15814 | * @private
|
15815 | */
|
15816 | _processChildContext: function (currentContext) {
|
15817 | var Component = this._currentElement.type;
|
15818 | var inst = this._instance;
|
15819 | var childContext;
|
15820 |
|
15821 | if (inst.getChildContext) {
|
15822 | if (process.env.NODE_ENV !== 'production') {
|
15823 | ReactInstrumentation.debugTool.onBeginProcessingChildContext();
|
15824 | try {
|
15825 | childContext = inst.getChildContext();
|
15826 | } finally {
|
15827 | ReactInstrumentation.debugTool.onEndProcessingChildContext();
|
15828 | }
|
15829 | } else {
|
15830 | childContext = inst.getChildContext();
|
15831 | }
|
15832 | }
|
15833 |
|
15834 | if (childContext) {
|
15835 | !(typeof Component.childContextTypes === 'object') ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getChildContext(): childContextTypes must be defined in order to use getChildContext().', this.getName() || 'ReactCompositeComponent') : _prodInvariant('107', this.getName() || 'ReactCompositeComponent') : void 0;
|
15836 | if (process.env.NODE_ENV !== 'production') {
|
15837 | this._checkContextTypes(Component.childContextTypes, childContext, 'childContext');
|
15838 | }
|
15839 | for (var name in childContext) {
|
15840 | !(name in Component.childContextTypes) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', this.getName() || 'ReactCompositeComponent', name) : _prodInvariant('108', this.getName() || 'ReactCompositeComponent', name) : void 0;
|
15841 | }
|
15842 | return _assign({}, currentContext, childContext);
|
15843 | }
|
15844 | return currentContext;
|
15845 | },
|
15846 |
|
15847 | /**
|
15848 | * Assert that the context types are valid
|
15849 | *
|
15850 | * @param {object} typeSpecs Map of context field to a ReactPropType
|
15851 | * @param {object} values Runtime values that need to be type-checked
|
15852 | * @param {string} location e.g. "prop", "context", "child context"
|
15853 | * @private
|
15854 | */
|
15855 | _checkContextTypes: function (typeSpecs, values, location) {
|
15856 | if (process.env.NODE_ENV !== 'production') {
|
15857 | checkReactTypeSpec(typeSpecs, values, location, this.getName(), null, this._debugID);
|
15858 | }
|
15859 | },
|
15860 |
|
15861 | receiveComponent: function (nextElement, transaction, nextContext) {
|
15862 | var prevElement = this._currentElement;
|
15863 | var prevContext = this._context;
|
15864 |
|
15865 | this._pendingElement = null;
|
15866 |
|
15867 | this.updateComponent(transaction, prevElement, nextElement, prevContext, nextContext);
|
15868 | },
|
15869 |
|
15870 | /**
|
15871 | * If any of `_pendingElement`, `_pendingStateQueue`, or `_pendingForceUpdate`
|
15872 | * is set, update the component.
|
15873 | *
|
15874 | * @param {ReactReconcileTransaction} transaction
|
15875 | * @internal
|
15876 | */
|
15877 | performUpdateIfNecessary: function (transaction) {
|
15878 | if (this._pendingElement != null) {
|
15879 | ReactReconciler.receiveComponent(this, this._pendingElement, transaction, this._context);
|
15880 | } else if (this._pendingStateQueue !== null || this._pendingForceUpdate) {
|
15881 | this.updateComponent(transaction, this._currentElement, this._currentElement, this._context, this._context);
|
15882 | } else {
|
15883 | this._updateBatchNumber = null;
|
15884 | }
|
15885 | },
|
15886 |
|
15887 | /**
|
15888 | * Perform an update to a mounted component. The componentWillReceiveProps and
|
15889 | * shouldComponentUpdate methods are called, then (assuming the update isn't
|
15890 | * skipped) the remaining update lifecycle methods are called and the DOM
|
15891 | * representation is updated.
|
15892 | *
|
15893 | * By default, this implements React's rendering and reconciliation algorithm.
|
15894 | * Sophisticated clients may wish to override this.
|
15895 | *
|
15896 | * @param {ReactReconcileTransaction} transaction
|
15897 | * @param {ReactElement} prevParentElement
|
15898 | * @param {ReactElement} nextParentElement
|
15899 | * @internal
|
15900 | * @overridable
|
15901 | */
|
15902 | updateComponent: function (transaction, prevParentElement, nextParentElement, prevUnmaskedContext, nextUnmaskedContext) {
|
15903 | var inst = this._instance;
|
15904 | !(inst != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Attempted to update component `%s` that has already been unmounted (or failed to mount).', this.getName() || 'ReactCompositeComponent') : _prodInvariant('136', this.getName() || 'ReactCompositeComponent') : void 0;
|
15905 |
|
15906 | var willReceive = false;
|
15907 | var nextContext;
|
15908 |
|
15909 | // Determine if the context has changed or not
|
15910 | if (this._context === nextUnmaskedContext) {
|
15911 | nextContext = inst.context;
|
15912 | } else {
|
15913 | nextContext = this._processContext(nextUnmaskedContext);
|
15914 | willReceive = true;
|
15915 | }
|
15916 |
|
15917 | var prevProps = prevParentElement.props;
|
15918 | var nextProps = nextParentElement.props;
|
15919 |
|
15920 | // Not a simple state update but a props update
|
15921 | if (prevParentElement !== nextParentElement) {
|
15922 | willReceive = true;
|
15923 | }
|
15924 |
|
15925 | // An update here will schedule an update but immediately set
|
15926 | // _pendingStateQueue which will ensure that any state updates gets
|
15927 | // immediately reconciled instead of waiting for the next batch.
|
15928 | if (willReceive && inst.componentWillReceiveProps) {
|
15929 | if (process.env.NODE_ENV !== 'production') {
|
15930 | measureLifeCyclePerf(function () {
|
15931 | return inst.componentWillReceiveProps(nextProps, nextContext);
|
15932 | }, this._debugID, 'componentWillReceiveProps');
|
15933 | } else {
|
15934 | inst.componentWillReceiveProps(nextProps, nextContext);
|
15935 | }
|
15936 | }
|
15937 |
|
15938 | var nextState = this._processPendingState(nextProps, nextContext);
|
15939 | var shouldUpdate = true;
|
15940 |
|
15941 | if (!this._pendingForceUpdate) {
|
15942 | if (inst.shouldComponentUpdate) {
|
15943 | if (process.env.NODE_ENV !== 'production') {
|
15944 | shouldUpdate = measureLifeCyclePerf(function () {
|
15945 | return inst.shouldComponentUpdate(nextProps, nextState, nextContext);
|
15946 | }, this._debugID, 'shouldComponentUpdate');
|
15947 | } else {
|
15948 | shouldUpdate = inst.shouldComponentUpdate(nextProps, nextState, nextContext);
|
15949 | }
|
15950 | } else {
|
15951 | if (this._compositeType === CompositeTypes.PureClass) {
|
15952 | shouldUpdate = !shallowEqual(prevProps, nextProps) || !shallowEqual(inst.state, nextState);
|
15953 | }
|
15954 | }
|
15955 | }
|
15956 |
|
15957 | if (process.env.NODE_ENV !== 'production') {
|
15958 | process.env.NODE_ENV !== 'production' ? warning(shouldUpdate !== undefined, '%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', this.getName() || 'ReactCompositeComponent') : void 0;
|
15959 | }
|
15960 |
|
15961 | this._updateBatchNumber = null;
|
15962 | if (shouldUpdate) {
|
15963 | this._pendingForceUpdate = false;
|
15964 | // Will set `this.props`, `this.state` and `this.context`.
|
15965 | this._performComponentUpdate(nextParentElement, nextProps, nextState, nextContext, transaction, nextUnmaskedContext);
|
15966 | } else {
|
15967 | // If it's determined that a component should not update, we still want
|
15968 | // to set props and state but we shortcut the rest of the update.
|
15969 | this._currentElement = nextParentElement;
|
15970 | this._context = nextUnmaskedContext;
|
15971 | inst.props = nextProps;
|
15972 | inst.state = nextState;
|
15973 | inst.context = nextContext;
|
15974 | }
|
15975 | },
|
15976 |
|
15977 | _processPendingState: function (props, context) {
|
15978 | var inst = this._instance;
|
15979 | var queue = this._pendingStateQueue;
|
15980 | var replace = this._pendingReplaceState;
|
15981 | this._pendingReplaceState = false;
|
15982 | this._pendingStateQueue = null;
|
15983 |
|
15984 | if (!queue) {
|
15985 | return inst.state;
|
15986 | }
|
15987 |
|
15988 | if (replace && queue.length === 1) {
|
15989 | return queue[0];
|
15990 | }
|
15991 |
|
15992 | var nextState = _assign({}, replace ? queue[0] : inst.state);
|
15993 | for (var i = replace ? 1 : 0; i < queue.length; i++) {
|
15994 | var partial = queue[i];
|
15995 | _assign(nextState, typeof partial === 'function' ? partial.call(inst, nextState, props, context) : partial);
|
15996 | }
|
15997 |
|
15998 | return nextState;
|
15999 | },
|
16000 |
|
16001 | /**
|
16002 | * Merges new props and state, notifies delegate methods of update and
|
16003 | * performs update.
|
16004 | *
|
16005 | * @param {ReactElement} nextElement Next element
|
16006 | * @param {object} nextProps Next public object to set as properties.
|
16007 | * @param {?object} nextState Next object to set as state.
|
16008 | * @param {?object} nextContext Next public object to set as context.
|
16009 | * @param {ReactReconcileTransaction} transaction
|
16010 | * @param {?object} unmaskedContext
|
16011 | * @private
|
16012 | */
|
16013 | _performComponentUpdate: function (nextElement, nextProps, nextState, nextContext, transaction, unmaskedContext) {
|
16014 | var _this2 = this;
|
16015 |
|
16016 | var inst = this._instance;
|
16017 |
|
16018 | var hasComponentDidUpdate = Boolean(inst.componentDidUpdate);
|
16019 | var prevProps;
|
16020 | var prevState;
|
16021 | var prevContext;
|
16022 | if (hasComponentDidUpdate) {
|
16023 | prevProps = inst.props;
|
16024 | prevState = inst.state;
|
16025 | prevContext = inst.context;
|
16026 | }
|
16027 |
|
16028 | if (inst.componentWillUpdate) {
|
16029 | if (process.env.NODE_ENV !== 'production') {
|
16030 | measureLifeCyclePerf(function () {
|
16031 | return inst.componentWillUpdate(nextProps, nextState, nextContext);
|
16032 | }, this._debugID, 'componentWillUpdate');
|
16033 | } else {
|
16034 | inst.componentWillUpdate(nextProps, nextState, nextContext);
|
16035 | }
|
16036 | }
|
16037 |
|
16038 | this._currentElement = nextElement;
|
16039 | this._context = unmaskedContext;
|
16040 | inst.props = nextProps;
|
16041 | inst.state = nextState;
|
16042 | inst.context = nextContext;
|
16043 |
|
16044 | this._updateRenderedComponent(transaction, unmaskedContext);
|
16045 |
|
16046 | if (hasComponentDidUpdate) {
|
16047 | if (process.env.NODE_ENV !== 'production') {
|
16048 | transaction.getReactMountReady().enqueue(function () {
|
16049 | measureLifeCyclePerf(inst.componentDidUpdate.bind(inst, prevProps, prevState, prevContext), _this2._debugID, 'componentDidUpdate');
|
16050 | });
|
16051 | } else {
|
16052 | transaction.getReactMountReady().enqueue(inst.componentDidUpdate.bind(inst, prevProps, prevState, prevContext), inst);
|
16053 | }
|
16054 | }
|
16055 | },
|
16056 |
|
16057 | /**
|
16058 | * Call the component's `render` method and update the DOM accordingly.
|
16059 | *
|
16060 | * @param {ReactReconcileTransaction} transaction
|
16061 | * @internal
|
16062 | */
|
16063 | _updateRenderedComponent: function (transaction, context) {
|
16064 | var prevComponentInstance = this._renderedComponent;
|
16065 | var prevRenderedElement = prevComponentInstance._currentElement;
|
16066 | var nextRenderedElement = this._renderValidatedComponent();
|
16067 |
|
16068 | var debugID = 0;
|
16069 | if (process.env.NODE_ENV !== 'production') {
|
16070 | debugID = this._debugID;
|
16071 | }
|
16072 |
|
16073 | if (shouldUpdateReactComponent(prevRenderedElement, nextRenderedElement)) {
|
16074 | ReactReconciler.receiveComponent(prevComponentInstance, nextRenderedElement, transaction, this._processChildContext(context));
|
16075 | } else {
|
16076 | var oldHostNode = ReactReconciler.getHostNode(prevComponentInstance);
|
16077 | ReactReconciler.unmountComponent(prevComponentInstance, false);
|
16078 |
|
16079 | var nodeType = ReactNodeTypes.getType(nextRenderedElement);
|
16080 | this._renderedNodeType = nodeType;
|
16081 | var child = this._instantiateReactComponent(nextRenderedElement, nodeType !== ReactNodeTypes.EMPTY /* shouldHaveDebugID */
|
16082 | );
|
16083 | this._renderedComponent = child;
|
16084 |
|
16085 | var nextMarkup = ReactReconciler.mountComponent(child, transaction, this._hostParent, this._hostContainerInfo, this._processChildContext(context), debugID);
|
16086 |
|
16087 | if (process.env.NODE_ENV !== 'production') {
|
16088 | if (debugID !== 0) {
|
16089 | var childDebugIDs = child._debugID !== 0 ? [child._debugID] : [];
|
16090 | ReactInstrumentation.debugTool.onSetChildren(debugID, childDebugIDs);
|
16091 | }
|
16092 | }
|
16093 |
|
16094 | this._replaceNodeWithMarkup(oldHostNode, nextMarkup, prevComponentInstance);
|
16095 | }
|
16096 | },
|
16097 |
|
16098 | /**
|
16099 | * Overridden in shallow rendering.
|
16100 | *
|
16101 | * @protected
|
16102 | */
|
16103 | _replaceNodeWithMarkup: function (oldHostNode, nextMarkup, prevInstance) {
|
16104 | ReactComponentEnvironment.replaceNodeWithMarkup(oldHostNode, nextMarkup, prevInstance);
|
16105 | },
|
16106 |
|
16107 | /**
|
16108 | * @protected
|
16109 | */
|
16110 | _renderValidatedComponentWithoutOwnerOrContext: function () {
|
16111 | var inst = this._instance;
|
16112 | var renderedElement;
|
16113 |
|
16114 | if (process.env.NODE_ENV !== 'production') {
|
16115 | renderedElement = measureLifeCyclePerf(function () {
|
16116 | return inst.render();
|
16117 | }, this._debugID, 'render');
|
16118 | } else {
|
16119 | renderedElement = inst.render();
|
16120 | }
|
16121 |
|
16122 | if (process.env.NODE_ENV !== 'production') {
|
16123 | // We allow auto-mocks to proceed as if they're returning null.
|
16124 | if (renderedElement === undefined && inst.render._isMockFunction) {
|
16125 | // This is probably bad practice. Consider warning here and
|
16126 | // deprecating this convenience.
|
16127 | renderedElement = null;
|
16128 | }
|
16129 | }
|
16130 |
|
16131 | return renderedElement;
|
16132 | },
|
16133 |
|
16134 | /**
|
16135 | * @private
|
16136 | */
|
16137 | _renderValidatedComponent: function () {
|
16138 | var renderedElement;
|
16139 | if (process.env.NODE_ENV !== 'production' || this._compositeType !== CompositeTypes.StatelessFunctional) {
|
16140 | ReactCurrentOwner.current = this;
|
16141 | try {
|
16142 | renderedElement = this._renderValidatedComponentWithoutOwnerOrContext();
|
16143 | } finally {
|
16144 | ReactCurrentOwner.current = null;
|
16145 | }
|
16146 | } else {
|
16147 | renderedElement = this._renderValidatedComponentWithoutOwnerOrContext();
|
16148 | }
|
16149 | !(
|
16150 | // TODO: An `isValidNode` function would probably be more appropriate
|
16151 | renderedElement === null || renderedElement === false || React.isValidElement(renderedElement)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.', this.getName() || 'ReactCompositeComponent') : _prodInvariant('109', this.getName() || 'ReactCompositeComponent') : void 0;
|
16152 |
|
16153 | return renderedElement;
|
16154 | },
|
16155 |
|
16156 | /**
|
16157 | * Lazily allocates the refs object and stores `component` as `ref`.
|
16158 | *
|
16159 | * @param {string} ref Reference name.
|
16160 | * @param {component} component Component to store as `ref`.
|
16161 | * @final
|
16162 | * @private
|
16163 | */
|
16164 | attachRef: function (ref, component) {
|
16165 | var inst = this.getPublicInstance();
|
16166 | !(inst != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Stateless function components cannot have refs.') : _prodInvariant('110') : void 0;
|
16167 | var publicComponentInstance = component.getPublicInstance();
|
16168 | if (process.env.NODE_ENV !== 'production') {
|
16169 | var componentName = component && component.getName ? component.getName() : 'a component';
|
16170 | process.env.NODE_ENV !== 'production' ? warning(publicComponentInstance != null || component._compositeType !== CompositeTypes.StatelessFunctional, 'Stateless function components cannot be given refs ' + '(See ref "%s" in %s created by %s). ' + 'Attempts to access this ref will fail.', ref, componentName, this.getName()) : void 0;
|
16171 | }
|
16172 | var refs = inst.refs === emptyObject ? inst.refs = {} : inst.refs;
|
16173 | refs[ref] = publicComponentInstance;
|
16174 | },
|
16175 |
|
16176 | /**
|
16177 | * Detaches a reference name.
|
16178 | *
|
16179 | * @param {string} ref Name to dereference.
|
16180 | * @final
|
16181 | * @private
|
16182 | */
|
16183 | detachRef: function (ref) {
|
16184 | var refs = this.getPublicInstance().refs;
|
16185 | delete refs[ref];
|
16186 | },
|
16187 |
|
16188 | /**
|
16189 | * Get a text description of the component that can be used to identify it
|
16190 | * in error messages.
|
16191 | * @return {string} The name or null.
|
16192 | * @internal
|
16193 | */
|
16194 | getName: function () {
|
16195 | var type = this._currentElement.type;
|
16196 | var constructor = this._instance && this._instance.constructor;
|
16197 | return type.displayName || constructor && constructor.displayName || type.name || constructor && constructor.name || null;
|
16198 | },
|
16199 |
|
16200 | /**
|
16201 | * Get the publicly accessible representation of this component - i.e. what
|
16202 | * is exposed by refs and returned by render. Can be null for stateless
|
16203 | * components.
|
16204 | *
|
16205 | * @return {ReactComponent} the public component instance.
|
16206 | * @internal
|
16207 | */
|
16208 | getPublicInstance: function () {
|
16209 | var inst = this._instance;
|
16210 | if (this._compositeType === CompositeTypes.StatelessFunctional) {
|
16211 | return null;
|
16212 | }
|
16213 | return inst;
|
16214 | },
|
16215 |
|
16216 | // Stub
|
16217 | _instantiateReactComponent: null
|
16218 |
|
16219 | };
|
16220 |
|
16221 | module.exports = ReactCompositeComponent;
|
16222 | }).call(this,require('_process'))
|
16223 | },{"./ReactComponentEnvironment":181,"./ReactErrorUtils":207,"./ReactInstanceMap":215,"./ReactInstrumentation":216,"./ReactNodeTypes":221,"./ReactReconciler":226,"./checkReactTypeSpec":255,"./reactProdInvariant":276,"./shouldUpdateReactComponent":280,"_process":144,"fbjs/lib/emptyObject":117,"fbjs/lib/invariant":124,"fbjs/lib/shallowEqual":130,"fbjs/lib/warning":131,"object-assign":143,"react/lib/React":287,"react/lib/ReactCurrentOwner":292}],183:[function(require,module,exports){
|
16224 | (function (process){
|
16225 | /**
|
16226 | * Copyright 2013-present, Facebook, Inc.
|
16227 | * All rights reserved.
|
16228 | *
|
16229 | * This source code is licensed under the BSD-style license found in the
|
16230 | * LICENSE file in the root directory of this source tree. An additional grant
|
16231 | * of patent rights can be found in the PATENTS file in the same directory.
|
16232 | *
|
16233 | */
|
16234 |
|
16235 | /* globals __REACT_DEVTOOLS_GLOBAL_HOOK__*/
|
16236 |
|
16237 | 'use strict';
|
16238 |
|
16239 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
16240 | var ReactDefaultInjection = require('./ReactDefaultInjection');
|
16241 | var ReactMount = require('./ReactMount');
|
16242 | var ReactReconciler = require('./ReactReconciler');
|
16243 | var ReactUpdates = require('./ReactUpdates');
|
16244 | var ReactVersion = require('./ReactVersion');
|
16245 |
|
16246 | var findDOMNode = require('./findDOMNode');
|
16247 | var getHostComponentFromComposite = require('./getHostComponentFromComposite');
|
16248 | var renderSubtreeIntoContainer = require('./renderSubtreeIntoContainer');
|
16249 | var warning = require('fbjs/lib/warning');
|
16250 |
|
16251 | ReactDefaultInjection.inject();
|
16252 |
|
16253 | var ReactDOM = {
|
16254 | findDOMNode: findDOMNode,
|
16255 | render: ReactMount.render,
|
16256 | unmountComponentAtNode: ReactMount.unmountComponentAtNode,
|
16257 | version: ReactVersion,
|
16258 |
|
16259 | /* eslint-disable camelcase */
|
16260 | unstable_batchedUpdates: ReactUpdates.batchedUpdates,
|
16261 | unstable_renderSubtreeIntoContainer: renderSubtreeIntoContainer
|
16262 | };
|
16263 |
|
16264 | // Inject the runtime into a devtools global hook regardless of browser.
|
16265 | // Allows for debugging when the hook is injected on the page.
|
16266 | if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') {
|
16267 | __REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
|
16268 | ComponentTree: {
|
16269 | getClosestInstanceFromNode: ReactDOMComponentTree.getClosestInstanceFromNode,
|
16270 | getNodeFromInstance: function (inst) {
|
16271 | // inst is an internal instance (but could be a composite)
|
16272 | if (inst._renderedComponent) {
|
16273 | inst = getHostComponentFromComposite(inst);
|
16274 | }
|
16275 | if (inst) {
|
16276 | return ReactDOMComponentTree.getNodeFromInstance(inst);
|
16277 | } else {
|
16278 | return null;
|
16279 | }
|
16280 | }
|
16281 | },
|
16282 | Mount: ReactMount,
|
16283 | Reconciler: ReactReconciler
|
16284 | });
|
16285 | }
|
16286 |
|
16287 | if (process.env.NODE_ENV !== 'production') {
|
16288 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
16289 | if (ExecutionEnvironment.canUseDOM && window.top === window.self) {
|
16290 |
|
16291 | // First check if devtools is not installed
|
16292 | if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
|
16293 | // If we're in Chrome or Firefox, provide a download link if not installed.
|
16294 | if (navigator.userAgent.indexOf('Chrome') > -1 && navigator.userAgent.indexOf('Edge') === -1 || navigator.userAgent.indexOf('Firefox') > -1) {
|
16295 | // Firefox does not have the issue with devtools loaded over file://
|
16296 | var showFileUrlMessage = window.location.protocol.indexOf('http') === -1 && navigator.userAgent.indexOf('Firefox') === -1;
|
16297 | console.debug('Download the React DevTools ' + (showFileUrlMessage ? 'and use an HTTP server (instead of a file: URL) ' : '') + 'for a better development experience: ' + 'https://fb.me/react-devtools');
|
16298 | }
|
16299 | }
|
16300 |
|
16301 | var testFunc = function testFn() {};
|
16302 | process.env.NODE_ENV !== 'production' ? warning((testFunc.name || testFunc.toString()).indexOf('testFn') !== -1, 'It looks like you\'re using a minified copy of the development build ' + 'of React. When deploying React apps to production, make sure to use ' + 'the production build which skips development warnings and is faster. ' + 'See https://fb.me/react-minification for more details.') : void 0;
|
16303 |
|
16304 | // If we're in IE8, check to see if we are in compatibility mode and provide
|
16305 | // information on preventing compatibility mode
|
16306 | var ieCompatibilityMode = document.documentMode && document.documentMode < 8;
|
16307 |
|
16308 | process.env.NODE_ENV !== 'production' ? warning(!ieCompatibilityMode, 'Internet Explorer is running in compatibility mode; please add the ' + 'following tag to your HTML to prevent this from happening: ' + '<meta http-equiv="X-UA-Compatible" content="IE=edge" />') : void 0;
|
16309 |
|
16310 | var expectedFeatures = [
|
16311 | // shims
|
16312 | Array.isArray, Array.prototype.every, Array.prototype.forEach, Array.prototype.indexOf, Array.prototype.map, Date.now, Function.prototype.bind, Object.keys, String.prototype.trim];
|
16313 |
|
16314 | for (var i = 0; i < expectedFeatures.length; i++) {
|
16315 | if (!expectedFeatures[i]) {
|
16316 | process.env.NODE_ENV !== 'production' ? warning(false, 'One or more ES5 shims expected by React are not available: ' + 'https://fb.me/react-warning-polyfills') : void 0;
|
16317 | break;
|
16318 | }
|
16319 | }
|
16320 | }
|
16321 | }
|
16322 |
|
16323 | if (process.env.NODE_ENV !== 'production') {
|
16324 | var ReactInstrumentation = require('./ReactInstrumentation');
|
16325 | var ReactDOMUnknownPropertyHook = require('./ReactDOMUnknownPropertyHook');
|
16326 | var ReactDOMNullInputValuePropHook = require('./ReactDOMNullInputValuePropHook');
|
16327 | var ReactDOMInvalidARIAHook = require('./ReactDOMInvalidARIAHook');
|
16328 |
|
16329 | ReactInstrumentation.debugTool.addHook(ReactDOMUnknownPropertyHook);
|
16330 | ReactInstrumentation.debugTool.addHook(ReactDOMNullInputValuePropHook);
|
16331 | ReactInstrumentation.debugTool.addHook(ReactDOMInvalidARIAHook);
|
16332 | }
|
16333 |
|
16334 | module.exports = ReactDOM;
|
16335 | }).call(this,require('_process'))
|
16336 | },{"./ReactDOMComponentTree":186,"./ReactDOMInvalidARIAHook":192,"./ReactDOMNullInputValuePropHook":193,"./ReactDOMUnknownPropertyHook":201,"./ReactDefaultInjection":204,"./ReactInstrumentation":216,"./ReactMount":219,"./ReactReconciler":226,"./ReactUpdates":233,"./ReactVersion":234,"./findDOMNode":259,"./getHostComponentFromComposite":266,"./renderSubtreeIntoContainer":277,"_process":144,"fbjs/lib/ExecutionEnvironment":110,"fbjs/lib/warning":131}],184:[function(require,module,exports){
|
16337 | (function (process){
|
16338 | /**
|
16339 | * Copyright 2013-present, Facebook, Inc.
|
16340 | * All rights reserved.
|
16341 | *
|
16342 | * This source code is licensed under the BSD-style license found in the
|
16343 | * LICENSE file in the root directory of this source tree. An additional grant
|
16344 | * of patent rights can be found in the PATENTS file in the same directory.
|
16345 | *
|
16346 | */
|
16347 |
|
16348 | /* global hasOwnProperty:true */
|
16349 |
|
16350 | 'use strict';
|
16351 |
|
16352 | var _prodInvariant = require('./reactProdInvariant'),
|
16353 | _assign = require('object-assign');
|
16354 |
|
16355 | var AutoFocusUtils = require('./AutoFocusUtils');
|
16356 | var CSSPropertyOperations = require('./CSSPropertyOperations');
|
16357 | var DOMLazyTree = require('./DOMLazyTree');
|
16358 | var DOMNamespaces = require('./DOMNamespaces');
|
16359 | var DOMProperty = require('./DOMProperty');
|
16360 | var DOMPropertyOperations = require('./DOMPropertyOperations');
|
16361 | var EventPluginHub = require('./EventPluginHub');
|
16362 | var EventPluginRegistry = require('./EventPluginRegistry');
|
16363 | var ReactBrowserEventEmitter = require('./ReactBrowserEventEmitter');
|
16364 | var ReactDOMComponentFlags = require('./ReactDOMComponentFlags');
|
16365 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
16366 | var ReactDOMInput = require('./ReactDOMInput');
|
16367 | var ReactDOMOption = require('./ReactDOMOption');
|
16368 | var ReactDOMSelect = require('./ReactDOMSelect');
|
16369 | var ReactDOMTextarea = require('./ReactDOMTextarea');
|
16370 | var ReactInstrumentation = require('./ReactInstrumentation');
|
16371 | var ReactMultiChild = require('./ReactMultiChild');
|
16372 | var ReactServerRenderingTransaction = require('./ReactServerRenderingTransaction');
|
16373 |
|
16374 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
16375 | var escapeTextContentForBrowser = require('./escapeTextContentForBrowser');
|
16376 | var invariant = require('fbjs/lib/invariant');
|
16377 | var isEventSupported = require('./isEventSupported');
|
16378 | var shallowEqual = require('fbjs/lib/shallowEqual');
|
16379 | var validateDOMNesting = require('./validateDOMNesting');
|
16380 | var warning = require('fbjs/lib/warning');
|
16381 |
|
16382 | var Flags = ReactDOMComponentFlags;
|
16383 | var deleteListener = EventPluginHub.deleteListener;
|
16384 | var getNode = ReactDOMComponentTree.getNodeFromInstance;
|
16385 | var listenTo = ReactBrowserEventEmitter.listenTo;
|
16386 | var registrationNameModules = EventPluginRegistry.registrationNameModules;
|
16387 |
|
16388 | // For quickly matching children type, to test if can be treated as content.
|
16389 | var CONTENT_TYPES = { 'string': true, 'number': true };
|
16390 |
|
16391 | var STYLE = 'style';
|
16392 | var HTML = '__html';
|
16393 | var RESERVED_PROPS = {
|
16394 | children: null,
|
16395 | dangerouslySetInnerHTML: null,
|
16396 | suppressContentEditableWarning: null
|
16397 | };
|
16398 |
|
16399 | // Node type for document fragments (Node.DOCUMENT_FRAGMENT_NODE).
|
16400 | var DOC_FRAGMENT_TYPE = 11;
|
16401 |
|
16402 | function getDeclarationErrorAddendum(internalInstance) {
|
16403 | if (internalInstance) {
|
16404 | var owner = internalInstance._currentElement._owner || null;
|
16405 | if (owner) {
|
16406 | var name = owner.getName();
|
16407 | if (name) {
|
16408 | return ' This DOM node was rendered by `' + name + '`.';
|
16409 | }
|
16410 | }
|
16411 | }
|
16412 | return '';
|
16413 | }
|
16414 |
|
16415 | function friendlyStringify(obj) {
|
16416 | if (typeof obj === 'object') {
|
16417 | if (Array.isArray(obj)) {
|
16418 | return '[' + obj.map(friendlyStringify).join(', ') + ']';
|
16419 | } else {
|
16420 | var pairs = [];
|
16421 | for (var key in obj) {
|
16422 | if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
16423 | var keyEscaped = /^[a-z$_][\w$_]*$/i.test(key) ? key : JSON.stringify(key);
|
16424 | pairs.push(keyEscaped + ': ' + friendlyStringify(obj[key]));
|
16425 | }
|
16426 | }
|
16427 | return '{' + pairs.join(', ') + '}';
|
16428 | }
|
16429 | } else if (typeof obj === 'string') {
|
16430 | return JSON.stringify(obj);
|
16431 | } else if (typeof obj === 'function') {
|
16432 | return '[function object]';
|
16433 | }
|
16434 | // Differs from JSON.stringify in that undefined because undefined and that
|
16435 | // inf and nan don't become null
|
16436 | return String(obj);
|
16437 | }
|
16438 |
|
16439 | var styleMutationWarning = {};
|
16440 |
|
16441 | function checkAndWarnForMutatedStyle(style1, style2, component) {
|
16442 | if (style1 == null || style2 == null) {
|
16443 | return;
|
16444 | }
|
16445 | if (shallowEqual(style1, style2)) {
|
16446 | return;
|
16447 | }
|
16448 |
|
16449 | var componentName = component._tag;
|
16450 | var owner = component._currentElement._owner;
|
16451 | var ownerName;
|
16452 | if (owner) {
|
16453 | ownerName = owner.getName();
|
16454 | }
|
16455 |
|
16456 | var hash = ownerName + '|' + componentName;
|
16457 |
|
16458 | if (styleMutationWarning.hasOwnProperty(hash)) {
|
16459 | return;
|
16460 | }
|
16461 |
|
16462 | styleMutationWarning[hash] = true;
|
16463 |
|
16464 | process.env.NODE_ENV !== 'production' ? warning(false, '`%s` was passed a style object that has previously been mutated. ' + 'Mutating `style` is deprecated. Consider cloning it beforehand. Check ' + 'the `render` %s. Previous style: %s. Mutated style: %s.', componentName, owner ? 'of `' + ownerName + '`' : 'using <' + componentName + '>', friendlyStringify(style1), friendlyStringify(style2)) : void 0;
|
16465 | }
|
16466 |
|
16467 | /**
|
16468 | * @param {object} component
|
16469 | * @param {?object} props
|
16470 | */
|
16471 | function assertValidProps(component, props) {
|
16472 | if (!props) {
|
16473 | return;
|
16474 | }
|
16475 | // Note the use of `==` which checks for null or undefined.
|
16476 | if (voidElementTags[component._tag]) {
|
16477 | !(props.children == null && props.dangerouslySetInnerHTML == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`.%s', component._tag, component._currentElement._owner ? ' Check the render method of ' + component._currentElement._owner.getName() + '.' : '') : _prodInvariant('137', component._tag, component._currentElement._owner ? ' Check the render method of ' + component._currentElement._owner.getName() + '.' : '') : void 0;
|
16478 | }
|
16479 | if (props.dangerouslySetInnerHTML != null) {
|
16480 | !(props.children == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Can only set one of `children` or `props.dangerouslySetInnerHTML`.') : _prodInvariant('60') : void 0;
|
16481 | !(typeof props.dangerouslySetInnerHTML === 'object' && HTML in props.dangerouslySetInnerHTML) ? process.env.NODE_ENV !== 'production' ? invariant(false, '`props.dangerouslySetInnerHTML` must be in the form `{__html: ...}`. Please visit https://fb.me/react-invariant-dangerously-set-inner-html for more information.') : _prodInvariant('61') : void 0;
|
16482 | }
|
16483 | if (process.env.NODE_ENV !== 'production') {
|
16484 | process.env.NODE_ENV !== 'production' ? warning(props.innerHTML == null, 'Directly setting property `innerHTML` is not permitted. ' + 'For more information, lookup documentation on `dangerouslySetInnerHTML`.') : void 0;
|
16485 | process.env.NODE_ENV !== 'production' ? warning(props.suppressContentEditableWarning || !props.contentEditable || props.children == null, 'A component is `contentEditable` and contains `children` managed by ' + 'React. It is now your responsibility to guarantee that none of ' + 'those nodes are unexpectedly modified or duplicated. This is ' + 'probably not intentional.') : void 0;
|
16486 | process.env.NODE_ENV !== 'production' ? warning(props.onFocusIn == null && props.onFocusOut == null, 'React uses onFocus and onBlur instead of onFocusIn and onFocusOut. ' + 'All React events are normalized to bubble, so onFocusIn and onFocusOut ' + 'are not needed/supported by React.') : void 0;
|
16487 | }
|
16488 | !(props.style == null || typeof props.style === 'object') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + \'em\'}} when using JSX.%s', getDeclarationErrorAddendum(component)) : _prodInvariant('62', getDeclarationErrorAddendum(component)) : void 0;
|
16489 | }
|
16490 |
|
16491 | function enqueuePutListener(inst, registrationName, listener, transaction) {
|
16492 | if (transaction instanceof ReactServerRenderingTransaction) {
|
16493 | return;
|
16494 | }
|
16495 | if (process.env.NODE_ENV !== 'production') {
|
16496 | // IE8 has no API for event capturing and the `onScroll` event doesn't
|
16497 | // bubble.
|
16498 | process.env.NODE_ENV !== 'production' ? warning(registrationName !== 'onScroll' || isEventSupported('scroll', true), 'This browser doesn\'t support the `onScroll` event') : void 0;
|
16499 | }
|
16500 | var containerInfo = inst._hostContainerInfo;
|
16501 | var isDocumentFragment = containerInfo._node && containerInfo._node.nodeType === DOC_FRAGMENT_TYPE;
|
16502 | var doc = isDocumentFragment ? containerInfo._node : containerInfo._ownerDocument;
|
16503 | listenTo(registrationName, doc);
|
16504 | transaction.getReactMountReady().enqueue(putListener, {
|
16505 | inst: inst,
|
16506 | registrationName: registrationName,
|
16507 | listener: listener
|
16508 | });
|
16509 | }
|
16510 |
|
16511 | function putListener() {
|
16512 | var listenerToPut = this;
|
16513 | EventPluginHub.putListener(listenerToPut.inst, listenerToPut.registrationName, listenerToPut.listener);
|
16514 | }
|
16515 |
|
16516 | function inputPostMount() {
|
16517 | var inst = this;
|
16518 | ReactDOMInput.postMountWrapper(inst);
|
16519 | }
|
16520 |
|
16521 | function textareaPostMount() {
|
16522 | var inst = this;
|
16523 | ReactDOMTextarea.postMountWrapper(inst);
|
16524 | }
|
16525 |
|
16526 | function optionPostMount() {
|
16527 | var inst = this;
|
16528 | ReactDOMOption.postMountWrapper(inst);
|
16529 | }
|
16530 |
|
16531 | var setAndValidateContentChildDev = emptyFunction;
|
16532 | if (process.env.NODE_ENV !== 'production') {
|
16533 | setAndValidateContentChildDev = function (content) {
|
16534 | var hasExistingContent = this._contentDebugID != null;
|
16535 | var debugID = this._debugID;
|
16536 | // This ID represents the inlined child that has no backing instance:
|
16537 | var contentDebugID = -debugID;
|
16538 |
|
16539 | if (content == null) {
|
16540 | if (hasExistingContent) {
|
16541 | ReactInstrumentation.debugTool.onUnmountComponent(this._contentDebugID);
|
16542 | }
|
16543 | this._contentDebugID = null;
|
16544 | return;
|
16545 | }
|
16546 |
|
16547 | validateDOMNesting(null, String(content), this, this._ancestorInfo);
|
16548 | this._contentDebugID = contentDebugID;
|
16549 | if (hasExistingContent) {
|
16550 | ReactInstrumentation.debugTool.onBeforeUpdateComponent(contentDebugID, content);
|
16551 | ReactInstrumentation.debugTool.onUpdateComponent(contentDebugID);
|
16552 | } else {
|
16553 | ReactInstrumentation.debugTool.onBeforeMountComponent(contentDebugID, content, debugID);
|
16554 | ReactInstrumentation.debugTool.onMountComponent(contentDebugID);
|
16555 | ReactInstrumentation.debugTool.onSetChildren(debugID, [contentDebugID]);
|
16556 | }
|
16557 | };
|
16558 | }
|
16559 |
|
16560 | // There are so many media events, it makes sense to just
|
16561 | // maintain a list rather than create a `trapBubbledEvent` for each
|
16562 | var mediaEvents = {
|
16563 | topAbort: 'abort',
|
16564 | topCanPlay: 'canplay',
|
16565 | topCanPlayThrough: 'canplaythrough',
|
16566 | topDurationChange: 'durationchange',
|
16567 | topEmptied: 'emptied',
|
16568 | topEncrypted: 'encrypted',
|
16569 | topEnded: 'ended',
|
16570 | topError: 'error',
|
16571 | topLoadedData: 'loadeddata',
|
16572 | topLoadedMetadata: 'loadedmetadata',
|
16573 | topLoadStart: 'loadstart',
|
16574 | topPause: 'pause',
|
16575 | topPlay: 'play',
|
16576 | topPlaying: 'playing',
|
16577 | topProgress: 'progress',
|
16578 | topRateChange: 'ratechange',
|
16579 | topSeeked: 'seeked',
|
16580 | topSeeking: 'seeking',
|
16581 | topStalled: 'stalled',
|
16582 | topSuspend: 'suspend',
|
16583 | topTimeUpdate: 'timeupdate',
|
16584 | topVolumeChange: 'volumechange',
|
16585 | topWaiting: 'waiting'
|
16586 | };
|
16587 |
|
16588 | function trapBubbledEventsLocal() {
|
16589 | var inst = this;
|
16590 | // If a component renders to null or if another component fatals and causes
|
16591 | // the state of the tree to be corrupted, `node` here can be null.
|
16592 | !inst._rootNodeID ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Must be mounted to trap events') : _prodInvariant('63') : void 0;
|
16593 | var node = getNode(inst);
|
16594 | !node ? process.env.NODE_ENV !== 'production' ? invariant(false, 'trapBubbledEvent(...): Requires node to be rendered.') : _prodInvariant('64') : void 0;
|
16595 |
|
16596 | switch (inst._tag) {
|
16597 | case 'iframe':
|
16598 | case 'object':
|
16599 | inst._wrapperState.listeners = [ReactBrowserEventEmitter.trapBubbledEvent('topLoad', 'load', node)];
|
16600 | break;
|
16601 | case 'video':
|
16602 | case 'audio':
|
16603 |
|
16604 | inst._wrapperState.listeners = [];
|
16605 | // Create listener for each media event
|
16606 | for (var event in mediaEvents) {
|
16607 | if (mediaEvents.hasOwnProperty(event)) {
|
16608 | inst._wrapperState.listeners.push(ReactBrowserEventEmitter.trapBubbledEvent(event, mediaEvents[event], node));
|
16609 | }
|
16610 | }
|
16611 | break;
|
16612 | case 'source':
|
16613 | inst._wrapperState.listeners = [ReactBrowserEventEmitter.trapBubbledEvent('topError', 'error', node)];
|
16614 | break;
|
16615 | case 'img':
|
16616 | inst._wrapperState.listeners = [ReactBrowserEventEmitter.trapBubbledEvent('topError', 'error', node), ReactBrowserEventEmitter.trapBubbledEvent('topLoad', 'load', node)];
|
16617 | break;
|
16618 | case 'form':
|
16619 | inst._wrapperState.listeners = [ReactBrowserEventEmitter.trapBubbledEvent('topReset', 'reset', node), ReactBrowserEventEmitter.trapBubbledEvent('topSubmit', 'submit', node)];
|
16620 | break;
|
16621 | case 'input':
|
16622 | case 'select':
|
16623 | case 'textarea':
|
16624 | inst._wrapperState.listeners = [ReactBrowserEventEmitter.trapBubbledEvent('topInvalid', 'invalid', node)];
|
16625 | break;
|
16626 | }
|
16627 | }
|
16628 |
|
16629 | function postUpdateSelectWrapper() {
|
16630 | ReactDOMSelect.postUpdateWrapper(this);
|
16631 | }
|
16632 |
|
16633 | // For HTML, certain tags should omit their close tag. We keep a whitelist for
|
16634 | // those special-case tags.
|
16635 |
|
16636 | var omittedCloseTags = {
|
16637 | 'area': true,
|
16638 | 'base': true,
|
16639 | 'br': true,
|
16640 | 'col': true,
|
16641 | 'embed': true,
|
16642 | 'hr': true,
|
16643 | 'img': true,
|
16644 | 'input': true,
|
16645 | 'keygen': true,
|
16646 | 'link': true,
|
16647 | 'meta': true,
|
16648 | 'param': true,
|
16649 | 'source': true,
|
16650 | 'track': true,
|
16651 | 'wbr': true
|
16652 | };
|
16653 |
|
16654 | var newlineEatingTags = {
|
16655 | 'listing': true,
|
16656 | 'pre': true,
|
16657 | 'textarea': true
|
16658 | };
|
16659 |
|
16660 | // For HTML, certain tags cannot have children. This has the same purpose as
|
16661 | // `omittedCloseTags` except that `menuitem` should still have its closing tag.
|
16662 |
|
16663 | var voidElementTags = _assign({
|
16664 | 'menuitem': true
|
16665 | }, omittedCloseTags);
|
16666 |
|
16667 | // We accept any tag to be rendered but since this gets injected into arbitrary
|
16668 | // HTML, we want to make sure that it's a safe tag.
|
16669 | // http://www.w3.org/TR/REC-xml/#NT-Name
|
16670 |
|
16671 | var VALID_TAG_REGEX = /^[a-zA-Z][a-zA-Z:_\.\-\d]*$/; // Simplified subset
|
16672 | var validatedTagCache = {};
|
16673 | var hasOwnProperty = {}.hasOwnProperty;
|
16674 |
|
16675 | function validateDangerousTag(tag) {
|
16676 | if (!hasOwnProperty.call(validatedTagCache, tag)) {
|
16677 | !VALID_TAG_REGEX.test(tag) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Invalid tag: %s', tag) : _prodInvariant('65', tag) : void 0;
|
16678 | validatedTagCache[tag] = true;
|
16679 | }
|
16680 | }
|
16681 |
|
16682 | function isCustomComponent(tagName, props) {
|
16683 | return tagName.indexOf('-') >= 0 || props.is != null;
|
16684 | }
|
16685 |
|
16686 | var globalIdCounter = 1;
|
16687 |
|
16688 | /**
|
16689 | * Creates a new React class that is idempotent and capable of containing other
|
16690 | * React components. It accepts event listeners and DOM properties that are
|
16691 | * valid according to `DOMProperty`.
|
16692 | *
|
16693 | * - Event listeners: `onClick`, `onMouseDown`, etc.
|
16694 | * - DOM properties: `className`, `name`, `title`, etc.
|
16695 | *
|
16696 | * The `style` property functions differently from the DOM API. It accepts an
|
16697 | * object mapping of style properties to values.
|
16698 | *
|
16699 | * @constructor ReactDOMComponent
|
16700 | * @extends ReactMultiChild
|
16701 | */
|
16702 | function ReactDOMComponent(element) {
|
16703 | var tag = element.type;
|
16704 | validateDangerousTag(tag);
|
16705 | this._currentElement = element;
|
16706 | this._tag = tag.toLowerCase();
|
16707 | this._namespaceURI = null;
|
16708 | this._renderedChildren = null;
|
16709 | this._previousStyle = null;
|
16710 | this._previousStyleCopy = null;
|
16711 | this._hostNode = null;
|
16712 | this._hostParent = null;
|
16713 | this._rootNodeID = 0;
|
16714 | this._domID = 0;
|
16715 | this._hostContainerInfo = null;
|
16716 | this._wrapperState = null;
|
16717 | this._topLevelWrapper = null;
|
16718 | this._flags = 0;
|
16719 | if (process.env.NODE_ENV !== 'production') {
|
16720 | this._ancestorInfo = null;
|
16721 | setAndValidateContentChildDev.call(this, null);
|
16722 | }
|
16723 | }
|
16724 |
|
16725 | ReactDOMComponent.displayName = 'ReactDOMComponent';
|
16726 |
|
16727 | ReactDOMComponent.Mixin = {
|
16728 |
|
16729 | /**
|
16730 | * Generates root tag markup then recurses. This method has side effects and
|
16731 | * is not idempotent.
|
16732 | *
|
16733 | * @internal
|
16734 | * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
16735 | * @param {?ReactDOMComponent} the parent component instance
|
16736 | * @param {?object} info about the host container
|
16737 | * @param {object} context
|
16738 | * @return {string} The computed markup.
|
16739 | */
|
16740 | mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
|
16741 | this._rootNodeID = globalIdCounter++;
|
16742 | this._domID = hostContainerInfo._idCounter++;
|
16743 | this._hostParent = hostParent;
|
16744 | this._hostContainerInfo = hostContainerInfo;
|
16745 |
|
16746 | var props = this._currentElement.props;
|
16747 |
|
16748 | switch (this._tag) {
|
16749 | case 'audio':
|
16750 | case 'form':
|
16751 | case 'iframe':
|
16752 | case 'img':
|
16753 | case 'link':
|
16754 | case 'object':
|
16755 | case 'source':
|
16756 | case 'video':
|
16757 | this._wrapperState = {
|
16758 | listeners: null
|
16759 | };
|
16760 | transaction.getReactMountReady().enqueue(trapBubbledEventsLocal, this);
|
16761 | break;
|
16762 | case 'input':
|
16763 | ReactDOMInput.mountWrapper(this, props, hostParent);
|
16764 | props = ReactDOMInput.getHostProps(this, props);
|
16765 | transaction.getReactMountReady().enqueue(trapBubbledEventsLocal, this);
|
16766 | break;
|
16767 | case 'option':
|
16768 | ReactDOMOption.mountWrapper(this, props, hostParent);
|
16769 | props = ReactDOMOption.getHostProps(this, props);
|
16770 | break;
|
16771 | case 'select':
|
16772 | ReactDOMSelect.mountWrapper(this, props, hostParent);
|
16773 | props = ReactDOMSelect.getHostProps(this, props);
|
16774 | transaction.getReactMountReady().enqueue(trapBubbledEventsLocal, this);
|
16775 | break;
|
16776 | case 'textarea':
|
16777 | ReactDOMTextarea.mountWrapper(this, props, hostParent);
|
16778 | props = ReactDOMTextarea.getHostProps(this, props);
|
16779 | transaction.getReactMountReady().enqueue(trapBubbledEventsLocal, this);
|
16780 | break;
|
16781 | }
|
16782 |
|
16783 | assertValidProps(this, props);
|
16784 |
|
16785 | // We create tags in the namespace of their parent container, except HTML
|
16786 | // tags get no namespace.
|
16787 | var namespaceURI;
|
16788 | var parentTag;
|
16789 | if (hostParent != null) {
|
16790 | namespaceURI = hostParent._namespaceURI;
|
16791 | parentTag = hostParent._tag;
|
16792 | } else if (hostContainerInfo._tag) {
|
16793 | namespaceURI = hostContainerInfo._namespaceURI;
|
16794 | parentTag = hostContainerInfo._tag;
|
16795 | }
|
16796 | if (namespaceURI == null || namespaceURI === DOMNamespaces.svg && parentTag === 'foreignobject') {
|
16797 | namespaceURI = DOMNamespaces.html;
|
16798 | }
|
16799 | if (namespaceURI === DOMNamespaces.html) {
|
16800 | if (this._tag === 'svg') {
|
16801 | namespaceURI = DOMNamespaces.svg;
|
16802 | } else if (this._tag === 'math') {
|
16803 | namespaceURI = DOMNamespaces.mathml;
|
16804 | }
|
16805 | }
|
16806 | this._namespaceURI = namespaceURI;
|
16807 |
|
16808 | if (process.env.NODE_ENV !== 'production') {
|
16809 | var parentInfo;
|
16810 | if (hostParent != null) {
|
16811 | parentInfo = hostParent._ancestorInfo;
|
16812 | } else if (hostContainerInfo._tag) {
|
16813 | parentInfo = hostContainerInfo._ancestorInfo;
|
16814 | }
|
16815 | if (parentInfo) {
|
16816 | // parentInfo should always be present except for the top-level
|
16817 | // component when server rendering
|
16818 | validateDOMNesting(this._tag, null, this, parentInfo);
|
16819 | }
|
16820 | this._ancestorInfo = validateDOMNesting.updatedAncestorInfo(parentInfo, this._tag, this);
|
16821 | }
|
16822 |
|
16823 | var mountImage;
|
16824 | if (transaction.useCreateElement) {
|
16825 | var ownerDocument = hostContainerInfo._ownerDocument;
|
16826 | var el;
|
16827 | if (namespaceURI === DOMNamespaces.html) {
|
16828 | if (this._tag === 'script') {
|
16829 | // Create the script via .innerHTML so its "parser-inserted" flag is
|
16830 | // set to true and it does not execute
|
16831 | var div = ownerDocument.createElement('div');
|
16832 | var type = this._currentElement.type;
|
16833 | div.innerHTML = '<' + type + '></' + type + '>';
|
16834 | el = div.removeChild(div.firstChild);
|
16835 | } else if (props.is) {
|
16836 | el = ownerDocument.createElement(this._currentElement.type, props.is);
|
16837 | } else {
|
16838 | // Separate else branch instead of using `props.is || undefined` above becuase of a Firefox bug.
|
16839 | // See discussion in https://github.com/facebook/react/pull/6896
|
16840 | // and discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1276240
|
16841 | el = ownerDocument.createElement(this._currentElement.type);
|
16842 | }
|
16843 | } else {
|
16844 | el = ownerDocument.createElementNS(namespaceURI, this._currentElement.type);
|
16845 | }
|
16846 | ReactDOMComponentTree.precacheNode(this, el);
|
16847 | this._flags |= Flags.hasCachedChildNodes;
|
16848 | if (!this._hostParent) {
|
16849 | DOMPropertyOperations.setAttributeForRoot(el);
|
16850 | }
|
16851 | this._updateDOMProperties(null, props, transaction);
|
16852 | var lazyTree = DOMLazyTree(el);
|
16853 | this._createInitialChildren(transaction, props, context, lazyTree);
|
16854 | mountImage = lazyTree;
|
16855 | } else {
|
16856 | var tagOpen = this._createOpenTagMarkupAndPutListeners(transaction, props);
|
16857 | var tagContent = this._createContentMarkup(transaction, props, context);
|
16858 | if (!tagContent && omittedCloseTags[this._tag]) {
|
16859 | mountImage = tagOpen + '/>';
|
16860 | } else {
|
16861 | mountImage = tagOpen + '>' + tagContent + '</' + this._currentElement.type + '>';
|
16862 | }
|
16863 | }
|
16864 |
|
16865 | switch (this._tag) {
|
16866 | case 'input':
|
16867 | transaction.getReactMountReady().enqueue(inputPostMount, this);
|
16868 | if (props.autoFocus) {
|
16869 | transaction.getReactMountReady().enqueue(AutoFocusUtils.focusDOMComponent, this);
|
16870 | }
|
16871 | break;
|
16872 | case 'textarea':
|
16873 | transaction.getReactMountReady().enqueue(textareaPostMount, this);
|
16874 | if (props.autoFocus) {
|
16875 | transaction.getReactMountReady().enqueue(AutoFocusUtils.focusDOMComponent, this);
|
16876 | }
|
16877 | break;
|
16878 | case 'select':
|
16879 | if (props.autoFocus) {
|
16880 | transaction.getReactMountReady().enqueue(AutoFocusUtils.focusDOMComponent, this);
|
16881 | }
|
16882 | break;
|
16883 | case 'button':
|
16884 | if (props.autoFocus) {
|
16885 | transaction.getReactMountReady().enqueue(AutoFocusUtils.focusDOMComponent, this);
|
16886 | }
|
16887 | break;
|
16888 | case 'option':
|
16889 | transaction.getReactMountReady().enqueue(optionPostMount, this);
|
16890 | break;
|
16891 | }
|
16892 |
|
16893 | return mountImage;
|
16894 | },
|
16895 |
|
16896 | /**
|
16897 | * Creates markup for the open tag and all attributes.
|
16898 | *
|
16899 | * This method has side effects because events get registered.
|
16900 | *
|
16901 | * Iterating over object properties is faster than iterating over arrays.
|
16902 | * @see http://jsperf.com/obj-vs-arr-iteration
|
16903 | *
|
16904 | * @private
|
16905 | * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
16906 | * @param {object} props
|
16907 | * @return {string} Markup of opening tag.
|
16908 | */
|
16909 | _createOpenTagMarkupAndPutListeners: function (transaction, props) {
|
16910 | var ret = '<' + this._currentElement.type;
|
16911 |
|
16912 | for (var propKey in props) {
|
16913 | if (!props.hasOwnProperty(propKey)) {
|
16914 | continue;
|
16915 | }
|
16916 | var propValue = props[propKey];
|
16917 | if (propValue == null) {
|
16918 | continue;
|
16919 | }
|
16920 | if (registrationNameModules.hasOwnProperty(propKey)) {
|
16921 | if (propValue) {
|
16922 | enqueuePutListener(this, propKey, propValue, transaction);
|
16923 | }
|
16924 | } else {
|
16925 | if (propKey === STYLE) {
|
16926 | if (propValue) {
|
16927 | if (process.env.NODE_ENV !== 'production') {
|
16928 | // See `_updateDOMProperties`. style block
|
16929 | this._previousStyle = propValue;
|
16930 | }
|
16931 | propValue = this._previousStyleCopy = _assign({}, props.style);
|
16932 | }
|
16933 | propValue = CSSPropertyOperations.createMarkupForStyles(propValue, this);
|
16934 | }
|
16935 | var markup = null;
|
16936 | if (this._tag != null && isCustomComponent(this._tag, props)) {
|
16937 | if (!RESERVED_PROPS.hasOwnProperty(propKey)) {
|
16938 | markup = DOMPropertyOperations.createMarkupForCustomAttribute(propKey, propValue);
|
16939 | }
|
16940 | } else {
|
16941 | markup = DOMPropertyOperations.createMarkupForProperty(propKey, propValue);
|
16942 | }
|
16943 | if (markup) {
|
16944 | ret += ' ' + markup;
|
16945 | }
|
16946 | }
|
16947 | }
|
16948 |
|
16949 | // For static pages, no need to put React ID and checksum. Saves lots of
|
16950 | // bytes.
|
16951 | if (transaction.renderToStaticMarkup) {
|
16952 | return ret;
|
16953 | }
|
16954 |
|
16955 | if (!this._hostParent) {
|
16956 | ret += ' ' + DOMPropertyOperations.createMarkupForRoot();
|
16957 | }
|
16958 | ret += ' ' + DOMPropertyOperations.createMarkupForID(this._domID);
|
16959 | return ret;
|
16960 | },
|
16961 |
|
16962 | /**
|
16963 | * Creates markup for the content between the tags.
|
16964 | *
|
16965 | * @private
|
16966 | * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
16967 | * @param {object} props
|
16968 | * @param {object} context
|
16969 | * @return {string} Content markup.
|
16970 | */
|
16971 | _createContentMarkup: function (transaction, props, context) {
|
16972 | var ret = '';
|
16973 |
|
16974 | // Intentional use of != to avoid catching zero/false.
|
16975 | var innerHTML = props.dangerouslySetInnerHTML;
|
16976 | if (innerHTML != null) {
|
16977 | if (innerHTML.__html != null) {
|
16978 | ret = innerHTML.__html;
|
16979 | }
|
16980 | } else {
|
16981 | var contentToUse = CONTENT_TYPES[typeof props.children] ? props.children : null;
|
16982 | var childrenToUse = contentToUse != null ? null : props.children;
|
16983 | if (contentToUse != null) {
|
16984 | // TODO: Validate that text is allowed as a child of this node
|
16985 | ret = escapeTextContentForBrowser(contentToUse);
|
16986 | if (process.env.NODE_ENV !== 'production') {
|
16987 | setAndValidateContentChildDev.call(this, contentToUse);
|
16988 | }
|
16989 | } else if (childrenToUse != null) {
|
16990 | var mountImages = this.mountChildren(childrenToUse, transaction, context);
|
16991 | ret = mountImages.join('');
|
16992 | }
|
16993 | }
|
16994 | if (newlineEatingTags[this._tag] && ret.charAt(0) === '\n') {
|
16995 | // text/html ignores the first character in these tags if it's a newline
|
16996 | // Prefer to break application/xml over text/html (for now) by adding
|
16997 | // a newline specifically to get eaten by the parser. (Alternately for
|
16998 | // textareas, replacing "^\n" with "\r\n" doesn't get eaten, and the first
|
16999 | // \r is normalized out by HTMLTextAreaElement#value.)
|
17000 | // See: <http://www.w3.org/TR/html-polyglot/#newlines-in-textarea-and-pre>
|
17001 | // See: <http://www.w3.org/TR/html5/syntax.html#element-restrictions>
|
17002 | // See: <http://www.w3.org/TR/html5/syntax.html#newlines>
|
17003 | // See: Parsing of "textarea" "listing" and "pre" elements
|
17004 | // from <http://www.w3.org/TR/html5/syntax.html#parsing-main-inbody>
|
17005 | return '\n' + ret;
|
17006 | } else {
|
17007 | return ret;
|
17008 | }
|
17009 | },
|
17010 |
|
17011 | _createInitialChildren: function (transaction, props, context, lazyTree) {
|
17012 | // Intentional use of != to avoid catching zero/false.
|
17013 | var innerHTML = props.dangerouslySetInnerHTML;
|
17014 | if (innerHTML != null) {
|
17015 | if (innerHTML.__html != null) {
|
17016 | DOMLazyTree.queueHTML(lazyTree, innerHTML.__html);
|
17017 | }
|
17018 | } else {
|
17019 | var contentToUse = CONTENT_TYPES[typeof props.children] ? props.children : null;
|
17020 | var childrenToUse = contentToUse != null ? null : props.children;
|
17021 | if (contentToUse != null) {
|
17022 | // TODO: Validate that text is allowed as a child of this node
|
17023 | if (process.env.NODE_ENV !== 'production') {
|
17024 | setAndValidateContentChildDev.call(this, contentToUse);
|
17025 | }
|
17026 | DOMLazyTree.queueText(lazyTree, contentToUse);
|
17027 | } else if (childrenToUse != null) {
|
17028 | var mountImages = this.mountChildren(childrenToUse, transaction, context);
|
17029 | for (var i = 0; i < mountImages.length; i++) {
|
17030 | DOMLazyTree.queueChild(lazyTree, mountImages[i]);
|
17031 | }
|
17032 | }
|
17033 | }
|
17034 | },
|
17035 |
|
17036 | /**
|
17037 | * Receives a next element and updates the component.
|
17038 | *
|
17039 | * @internal
|
17040 | * @param {ReactElement} nextElement
|
17041 | * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
17042 | * @param {object} context
|
17043 | */
|
17044 | receiveComponent: function (nextElement, transaction, context) {
|
17045 | var prevElement = this._currentElement;
|
17046 | this._currentElement = nextElement;
|
17047 | this.updateComponent(transaction, prevElement, nextElement, context);
|
17048 | },
|
17049 |
|
17050 | /**
|
17051 | * Updates a DOM component after it has already been allocated and
|
17052 | * attached to the DOM. Reconciles the root DOM node, then recurses.
|
17053 | *
|
17054 | * @param {ReactReconcileTransaction} transaction
|
17055 | * @param {ReactElement} prevElement
|
17056 | * @param {ReactElement} nextElement
|
17057 | * @internal
|
17058 | * @overridable
|
17059 | */
|
17060 | updateComponent: function (transaction, prevElement, nextElement, context) {
|
17061 | var lastProps = prevElement.props;
|
17062 | var nextProps = this._currentElement.props;
|
17063 |
|
17064 | switch (this._tag) {
|
17065 | case 'input':
|
17066 | lastProps = ReactDOMInput.getHostProps(this, lastProps);
|
17067 | nextProps = ReactDOMInput.getHostProps(this, nextProps);
|
17068 | break;
|
17069 | case 'option':
|
17070 | lastProps = ReactDOMOption.getHostProps(this, lastProps);
|
17071 | nextProps = ReactDOMOption.getHostProps(this, nextProps);
|
17072 | break;
|
17073 | case 'select':
|
17074 | lastProps = ReactDOMSelect.getHostProps(this, lastProps);
|
17075 | nextProps = ReactDOMSelect.getHostProps(this, nextProps);
|
17076 | break;
|
17077 | case 'textarea':
|
17078 | lastProps = ReactDOMTextarea.getHostProps(this, lastProps);
|
17079 | nextProps = ReactDOMTextarea.getHostProps(this, nextProps);
|
17080 | break;
|
17081 | }
|
17082 |
|
17083 | assertValidProps(this, nextProps);
|
17084 | this._updateDOMProperties(lastProps, nextProps, transaction);
|
17085 | this._updateDOMChildren(lastProps, nextProps, transaction, context);
|
17086 |
|
17087 | switch (this._tag) {
|
17088 | case 'input':
|
17089 | // Update the wrapper around inputs *after* updating props. This has to
|
17090 | // happen after `_updateDOMProperties`. Otherwise HTML5 input validations
|
17091 | // raise warnings and prevent the new value from being assigned.
|
17092 | ReactDOMInput.updateWrapper(this);
|
17093 | break;
|
17094 | case 'textarea':
|
17095 | ReactDOMTextarea.updateWrapper(this);
|
17096 | break;
|
17097 | case 'select':
|
17098 | // <select> value update needs to occur after <option> children
|
17099 | // reconciliation
|
17100 | transaction.getReactMountReady().enqueue(postUpdateSelectWrapper, this);
|
17101 | break;
|
17102 | }
|
17103 | },
|
17104 |
|
17105 | /**
|
17106 | * Reconciles the properties by detecting differences in property values and
|
17107 | * updating the DOM as necessary. This function is probably the single most
|
17108 | * critical path for performance optimization.
|
17109 | *
|
17110 | * TODO: Benchmark whether checking for changed values in memory actually
|
17111 | * improves performance (especially statically positioned elements).
|
17112 | * TODO: Benchmark the effects of putting this at the top since 99% of props
|
17113 | * do not change for a given reconciliation.
|
17114 | * TODO: Benchmark areas that can be improved with caching.
|
17115 | *
|
17116 | * @private
|
17117 | * @param {object} lastProps
|
17118 | * @param {object} nextProps
|
17119 | * @param {?DOMElement} node
|
17120 | */
|
17121 | _updateDOMProperties: function (lastProps, nextProps, transaction) {
|
17122 | var propKey;
|
17123 | var styleName;
|
17124 | var styleUpdates;
|
17125 | for (propKey in lastProps) {
|
17126 | if (nextProps.hasOwnProperty(propKey) || !lastProps.hasOwnProperty(propKey) || lastProps[propKey] == null) {
|
17127 | continue;
|
17128 | }
|
17129 | if (propKey === STYLE) {
|
17130 | var lastStyle = this._previousStyleCopy;
|
17131 | for (styleName in lastStyle) {
|
17132 | if (lastStyle.hasOwnProperty(styleName)) {
|
17133 | styleUpdates = styleUpdates || {};
|
17134 | styleUpdates[styleName] = '';
|
17135 | }
|
17136 | }
|
17137 | this._previousStyleCopy = null;
|
17138 | } else if (registrationNameModules.hasOwnProperty(propKey)) {
|
17139 | if (lastProps[propKey]) {
|
17140 | // Only call deleteListener if there was a listener previously or
|
17141 | // else willDeleteListener gets called when there wasn't actually a
|
17142 | // listener (e.g., onClick={null})
|
17143 | deleteListener(this, propKey);
|
17144 | }
|
17145 | } else if (isCustomComponent(this._tag, lastProps)) {
|
17146 | if (!RESERVED_PROPS.hasOwnProperty(propKey)) {
|
17147 | DOMPropertyOperations.deleteValueForAttribute(getNode(this), propKey);
|
17148 | }
|
17149 | } else if (DOMProperty.properties[propKey] || DOMProperty.isCustomAttribute(propKey)) {
|
17150 | DOMPropertyOperations.deleteValueForProperty(getNode(this), propKey);
|
17151 | }
|
17152 | }
|
17153 | for (propKey in nextProps) {
|
17154 | var nextProp = nextProps[propKey];
|
17155 | var lastProp = propKey === STYLE ? this._previousStyleCopy : lastProps != null ? lastProps[propKey] : undefined;
|
17156 | if (!nextProps.hasOwnProperty(propKey) || nextProp === lastProp || nextProp == null && lastProp == null) {
|
17157 | continue;
|
17158 | }
|
17159 | if (propKey === STYLE) {
|
17160 | if (nextProp) {
|
17161 | if (process.env.NODE_ENV !== 'production') {
|
17162 | checkAndWarnForMutatedStyle(this._previousStyleCopy, this._previousStyle, this);
|
17163 | this._previousStyle = nextProp;
|
17164 | }
|
17165 | nextProp = this._previousStyleCopy = _assign({}, nextProp);
|
17166 | } else {
|
17167 | this._previousStyleCopy = null;
|
17168 | }
|
17169 | if (lastProp) {
|
17170 | // Unset styles on `lastProp` but not on `nextProp`.
|
17171 | for (styleName in lastProp) {
|
17172 | if (lastProp.hasOwnProperty(styleName) && (!nextProp || !nextProp.hasOwnProperty(styleName))) {
|
17173 | styleUpdates = styleUpdates || {};
|
17174 | styleUpdates[styleName] = '';
|
17175 | }
|
17176 | }
|
17177 | // Update styles that changed since `lastProp`.
|
17178 | for (styleName in nextProp) {
|
17179 | if (nextProp.hasOwnProperty(styleName) && lastProp[styleName] !== nextProp[styleName]) {
|
17180 | styleUpdates = styleUpdates || {};
|
17181 | styleUpdates[styleName] = nextProp[styleName];
|
17182 | }
|
17183 | }
|
17184 | } else {
|
17185 | // Relies on `updateStylesByID` not mutating `styleUpdates`.
|
17186 | styleUpdates = nextProp;
|
17187 | }
|
17188 | } else if (registrationNameModules.hasOwnProperty(propKey)) {
|
17189 | if (nextProp) {
|
17190 | enqueuePutListener(this, propKey, nextProp, transaction);
|
17191 | } else if (lastProp) {
|
17192 | deleteListener(this, propKey);
|
17193 | }
|
17194 | } else if (isCustomComponent(this._tag, nextProps)) {
|
17195 | if (!RESERVED_PROPS.hasOwnProperty(propKey)) {
|
17196 | DOMPropertyOperations.setValueForAttribute(getNode(this), propKey, nextProp);
|
17197 | }
|
17198 | } else if (DOMProperty.properties[propKey] || DOMProperty.isCustomAttribute(propKey)) {
|
17199 | var node = getNode(this);
|
17200 | // If we're updating to null or undefined, we should remove the property
|
17201 | // from the DOM node instead of inadvertently setting to a string. This
|
17202 | // brings us in line with the same behavior we have on initial render.
|
17203 | if (nextProp != null) {
|
17204 | DOMPropertyOperations.setValueForProperty(node, propKey, nextProp);
|
17205 | } else {
|
17206 | DOMPropertyOperations.deleteValueForProperty(node, propKey);
|
17207 | }
|
17208 | }
|
17209 | }
|
17210 | if (styleUpdates) {
|
17211 | CSSPropertyOperations.setValueForStyles(getNode(this), styleUpdates, this);
|
17212 | }
|
17213 | },
|
17214 |
|
17215 | /**
|
17216 | * Reconciles the children with the various properties that affect the
|
17217 | * children content.
|
17218 | *
|
17219 | * @param {object} lastProps
|
17220 | * @param {object} nextProps
|
17221 | * @param {ReactReconcileTransaction} transaction
|
17222 | * @param {object} context
|
17223 | */
|
17224 | _updateDOMChildren: function (lastProps, nextProps, transaction, context) {
|
17225 | var lastContent = CONTENT_TYPES[typeof lastProps.children] ? lastProps.children : null;
|
17226 | var nextContent = CONTENT_TYPES[typeof nextProps.children] ? nextProps.children : null;
|
17227 |
|
17228 | var lastHtml = lastProps.dangerouslySetInnerHTML && lastProps.dangerouslySetInnerHTML.__html;
|
17229 | var nextHtml = nextProps.dangerouslySetInnerHTML && nextProps.dangerouslySetInnerHTML.__html;
|
17230 |
|
17231 | // Note the use of `!=` which checks for null or undefined.
|
17232 | var lastChildren = lastContent != null ? null : lastProps.children;
|
17233 | var nextChildren = nextContent != null ? null : nextProps.children;
|
17234 |
|
17235 | // If we're switching from children to content/html or vice versa, remove
|
17236 | // the old content
|
17237 | var lastHasContentOrHtml = lastContent != null || lastHtml != null;
|
17238 | var nextHasContentOrHtml = nextContent != null || nextHtml != null;
|
17239 | if (lastChildren != null && nextChildren == null) {
|
17240 | this.updateChildren(null, transaction, context);
|
17241 | } else if (lastHasContentOrHtml && !nextHasContentOrHtml) {
|
17242 | this.updateTextContent('');
|
17243 | if (process.env.NODE_ENV !== 'production') {
|
17244 | ReactInstrumentation.debugTool.onSetChildren(this._debugID, []);
|
17245 | }
|
17246 | }
|
17247 |
|
17248 | if (nextContent != null) {
|
17249 | if (lastContent !== nextContent) {
|
17250 | this.updateTextContent('' + nextContent);
|
17251 | if (process.env.NODE_ENV !== 'production') {
|
17252 | setAndValidateContentChildDev.call(this, nextContent);
|
17253 | }
|
17254 | }
|
17255 | } else if (nextHtml != null) {
|
17256 | if (lastHtml !== nextHtml) {
|
17257 | this.updateMarkup('' + nextHtml);
|
17258 | }
|
17259 | if (process.env.NODE_ENV !== 'production') {
|
17260 | ReactInstrumentation.debugTool.onSetChildren(this._debugID, []);
|
17261 | }
|
17262 | } else if (nextChildren != null) {
|
17263 | if (process.env.NODE_ENV !== 'production') {
|
17264 | setAndValidateContentChildDev.call(this, null);
|
17265 | }
|
17266 |
|
17267 | this.updateChildren(nextChildren, transaction, context);
|
17268 | }
|
17269 | },
|
17270 |
|
17271 | getHostNode: function () {
|
17272 | return getNode(this);
|
17273 | },
|
17274 |
|
17275 | /**
|
17276 | * Destroys all event registrations for this instance. Does not remove from
|
17277 | * the DOM. That must be done by the parent.
|
17278 | *
|
17279 | * @internal
|
17280 | */
|
17281 | unmountComponent: function (safely) {
|
17282 | switch (this._tag) {
|
17283 | case 'audio':
|
17284 | case 'form':
|
17285 | case 'iframe':
|
17286 | case 'img':
|
17287 | case 'link':
|
17288 | case 'object':
|
17289 | case 'source':
|
17290 | case 'video':
|
17291 | var listeners = this._wrapperState.listeners;
|
17292 | if (listeners) {
|
17293 | for (var i = 0; i < listeners.length; i++) {
|
17294 | listeners[i].remove();
|
17295 | }
|
17296 | }
|
17297 | break;
|
17298 | case 'html':
|
17299 | case 'head':
|
17300 | case 'body':
|
17301 | /**
|
17302 | * Components like <html> <head> and <body> can't be removed or added
|
17303 | * easily in a cross-browser way, however it's valuable to be able to
|
17304 | * take advantage of React's reconciliation for styling and <title>
|
17305 | * management. So we just document it and throw in dangerous cases.
|
17306 | */
|
17307 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, '<%s> tried to unmount. Because of cross-browser quirks it is impossible to unmount some top-level components (eg <html>, <head>, and <body>) reliably and efficiently. To fix this, have a single top-level component that never unmounts render these elements.', this._tag) : _prodInvariant('66', this._tag) : void 0;
|
17308 | break;
|
17309 | }
|
17310 |
|
17311 | this.unmountChildren(safely);
|
17312 | ReactDOMComponentTree.uncacheNode(this);
|
17313 | EventPluginHub.deleteAllListeners(this);
|
17314 | this._rootNodeID = 0;
|
17315 | this._domID = 0;
|
17316 | this._wrapperState = null;
|
17317 |
|
17318 | if (process.env.NODE_ENV !== 'production') {
|
17319 | setAndValidateContentChildDev.call(this, null);
|
17320 | }
|
17321 | },
|
17322 |
|
17323 | getPublicInstance: function () {
|
17324 | return getNode(this);
|
17325 | }
|
17326 |
|
17327 | };
|
17328 |
|
17329 | _assign(ReactDOMComponent.prototype, ReactDOMComponent.Mixin, ReactMultiChild.Mixin);
|
17330 |
|
17331 | module.exports = ReactDOMComponent;
|
17332 | }).call(this,require('_process'))
|
17333 | },{"./AutoFocusUtils":155,"./CSSPropertyOperations":158,"./DOMLazyTree":162,"./DOMNamespaces":163,"./DOMProperty":164,"./DOMPropertyOperations":165,"./EventPluginHub":169,"./EventPluginRegistry":170,"./ReactBrowserEventEmitter":178,"./ReactDOMComponentFlags":185,"./ReactDOMComponentTree":186,"./ReactDOMInput":191,"./ReactDOMOption":194,"./ReactDOMSelect":195,"./ReactDOMTextarea":199,"./ReactInstrumentation":216,"./ReactMultiChild":220,"./ReactServerRenderingTransaction":230,"./escapeTextContentForBrowser":258,"./isEventSupported":273,"./reactProdInvariant":276,"./validateDOMNesting":282,"_process":144,"fbjs/lib/emptyFunction":116,"fbjs/lib/invariant":124,"fbjs/lib/shallowEqual":130,"fbjs/lib/warning":131,"object-assign":143}],185:[function(require,module,exports){
|
17334 | /**
|
17335 | * Copyright 2015-present, Facebook, Inc.
|
17336 | * All rights reserved.
|
17337 | *
|
17338 | * This source code is licensed under the BSD-style license found in the
|
17339 | * LICENSE file in the root directory of this source tree. An additional grant
|
17340 | * of patent rights can be found in the PATENTS file in the same directory.
|
17341 | *
|
17342 | */
|
17343 |
|
17344 | 'use strict';
|
17345 |
|
17346 | var ReactDOMComponentFlags = {
|
17347 | hasCachedChildNodes: 1 << 0
|
17348 | };
|
17349 |
|
17350 | module.exports = ReactDOMComponentFlags;
|
17351 | },{}],186:[function(require,module,exports){
|
17352 | (function (process){
|
17353 | /**
|
17354 | * Copyright 2013-present, Facebook, Inc.
|
17355 | * All rights reserved.
|
17356 | *
|
17357 | * This source code is licensed under the BSD-style license found in the
|
17358 | * LICENSE file in the root directory of this source tree. An additional grant
|
17359 | * of patent rights can be found in the PATENTS file in the same directory.
|
17360 | *
|
17361 | */
|
17362 |
|
17363 | 'use strict';
|
17364 |
|
17365 | var _prodInvariant = require('./reactProdInvariant');
|
17366 |
|
17367 | var DOMProperty = require('./DOMProperty');
|
17368 | var ReactDOMComponentFlags = require('./ReactDOMComponentFlags');
|
17369 |
|
17370 | var invariant = require('fbjs/lib/invariant');
|
17371 |
|
17372 | var ATTR_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
|
17373 | var Flags = ReactDOMComponentFlags;
|
17374 |
|
17375 | var internalInstanceKey = '__reactInternalInstance$' + Math.random().toString(36).slice(2);
|
17376 |
|
17377 | /**
|
17378 | * Drill down (through composites and empty components) until we get a host or
|
17379 | * host text component.
|
17380 | *
|
17381 | * This is pretty polymorphic but unavoidable with the current structure we have
|
17382 | * for `_renderedChildren`.
|
17383 | */
|
17384 | function getRenderedHostOrTextFromComponent(component) {
|
17385 | var rendered;
|
17386 | while (rendered = component._renderedComponent) {
|
17387 | component = rendered;
|
17388 | }
|
17389 | return component;
|
17390 | }
|
17391 |
|
17392 | /**
|
17393 | * Populate `_hostNode` on the rendered host/text component with the given
|
17394 | * DOM node. The passed `inst` can be a composite.
|
17395 | */
|
17396 | function precacheNode(inst, node) {
|
17397 | var hostInst = getRenderedHostOrTextFromComponent(inst);
|
17398 | hostInst._hostNode = node;
|
17399 | node[internalInstanceKey] = hostInst;
|
17400 | }
|
17401 |
|
17402 | function uncacheNode(inst) {
|
17403 | var node = inst._hostNode;
|
17404 | if (node) {
|
17405 | delete node[internalInstanceKey];
|
17406 | inst._hostNode = null;
|
17407 | }
|
17408 | }
|
17409 |
|
17410 | /**
|
17411 | * Populate `_hostNode` on each child of `inst`, assuming that the children
|
17412 | * match up with the DOM (element) children of `node`.
|
17413 | *
|
17414 | * We cache entire levels at once to avoid an n^2 problem where we access the
|
17415 | * children of a node sequentially and have to walk from the start to our target
|
17416 | * node every time.
|
17417 | *
|
17418 | * Since we update `_renderedChildren` and the actual DOM at (slightly)
|
17419 | * different times, we could race here and see a newer `_renderedChildren` than
|
17420 | * the DOM nodes we see. To avoid this, ReactMultiChild calls
|
17421 | * `prepareToManageChildren` before we change `_renderedChildren`, at which
|
17422 | * time the container's child nodes are always cached (until it unmounts).
|
17423 | */
|
17424 | function precacheChildNodes(inst, node) {
|
17425 | if (inst._flags & Flags.hasCachedChildNodes) {
|
17426 | return;
|
17427 | }
|
17428 | var children = inst._renderedChildren;
|
17429 | var childNode = node.firstChild;
|
17430 | outer: for (var name in children) {
|
17431 | if (!children.hasOwnProperty(name)) {
|
17432 | continue;
|
17433 | }
|
17434 | var childInst = children[name];
|
17435 | var childID = getRenderedHostOrTextFromComponent(childInst)._domID;
|
17436 | if (childID === 0) {
|
17437 | // We're currently unmounting this child in ReactMultiChild; skip it.
|
17438 | continue;
|
17439 | }
|
17440 | // We assume the child nodes are in the same order as the child instances.
|
17441 | for (; childNode !== null; childNode = childNode.nextSibling) {
|
17442 | if (childNode.nodeType === 1 && childNode.getAttribute(ATTR_NAME) === String(childID) || childNode.nodeType === 8 && childNode.nodeValue === ' react-text: ' + childID + ' ' || childNode.nodeType === 8 && childNode.nodeValue === ' react-empty: ' + childID + ' ') {
|
17443 | precacheNode(childInst, childNode);
|
17444 | continue outer;
|
17445 | }
|
17446 | }
|
17447 | // We reached the end of the DOM children without finding an ID match.
|
17448 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Unable to find element with ID %s.', childID) : _prodInvariant('32', childID) : void 0;
|
17449 | }
|
17450 | inst._flags |= Flags.hasCachedChildNodes;
|
17451 | }
|
17452 |
|
17453 | /**
|
17454 | * Given a DOM node, return the closest ReactDOMComponent or
|
17455 | * ReactDOMTextComponent instance ancestor.
|
17456 | */
|
17457 | function getClosestInstanceFromNode(node) {
|
17458 | if (node[internalInstanceKey]) {
|
17459 | return node[internalInstanceKey];
|
17460 | }
|
17461 |
|
17462 | // Walk up the tree until we find an ancestor whose instance we have cached.
|
17463 | var parents = [];
|
17464 | while (!node[internalInstanceKey]) {
|
17465 | parents.push(node);
|
17466 | if (node.parentNode) {
|
17467 | node = node.parentNode;
|
17468 | } else {
|
17469 | // Top of the tree. This node must not be part of a React tree (or is
|
17470 | // unmounted, potentially).
|
17471 | return null;
|
17472 | }
|
17473 | }
|
17474 |
|
17475 | var closest;
|
17476 | var inst;
|
17477 | for (; node && (inst = node[internalInstanceKey]); node = parents.pop()) {
|
17478 | closest = inst;
|
17479 | if (parents.length) {
|
17480 | precacheChildNodes(inst, node);
|
17481 | }
|
17482 | }
|
17483 |
|
17484 | return closest;
|
17485 | }
|
17486 |
|
17487 | /**
|
17488 | * Given a DOM node, return the ReactDOMComponent or ReactDOMTextComponent
|
17489 | * instance, or null if the node was not rendered by this React.
|
17490 | */
|
17491 | function getInstanceFromNode(node) {
|
17492 | var inst = getClosestInstanceFromNode(node);
|
17493 | if (inst != null && inst._hostNode === node) {
|
17494 | return inst;
|
17495 | } else {
|
17496 | return null;
|
17497 | }
|
17498 | }
|
17499 |
|
17500 | /**
|
17501 | * Given a ReactDOMComponent or ReactDOMTextComponent, return the corresponding
|
17502 | * DOM node.
|
17503 | */
|
17504 | function getNodeFromInstance(inst) {
|
17505 | // Without this first invariant, passing a non-DOM-component triggers the next
|
17506 | // invariant for a missing parent, which is super confusing.
|
17507 | !(inst._hostNode !== undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'getNodeFromInstance: Invalid argument.') : _prodInvariant('33') : void 0;
|
17508 |
|
17509 | if (inst._hostNode) {
|
17510 | return inst._hostNode;
|
17511 | }
|
17512 |
|
17513 | // Walk up the tree until we find an ancestor whose DOM node we have cached.
|
17514 | var parents = [];
|
17515 | while (!inst._hostNode) {
|
17516 | parents.push(inst);
|
17517 | !inst._hostParent ? process.env.NODE_ENV !== 'production' ? invariant(false, 'React DOM tree root should always have a node reference.') : _prodInvariant('34') : void 0;
|
17518 | inst = inst._hostParent;
|
17519 | }
|
17520 |
|
17521 | // Now parents contains each ancestor that does *not* have a cached native
|
17522 | // node, and `inst` is the deepest ancestor that does.
|
17523 | for (; parents.length; inst = parents.pop()) {
|
17524 | precacheChildNodes(inst, inst._hostNode);
|
17525 | }
|
17526 |
|
17527 | return inst._hostNode;
|
17528 | }
|
17529 |
|
17530 | var ReactDOMComponentTree = {
|
17531 | getClosestInstanceFromNode: getClosestInstanceFromNode,
|
17532 | getInstanceFromNode: getInstanceFromNode,
|
17533 | getNodeFromInstance: getNodeFromInstance,
|
17534 | precacheChildNodes: precacheChildNodes,
|
17535 | precacheNode: precacheNode,
|
17536 | uncacheNode: uncacheNode
|
17537 | };
|
17538 |
|
17539 | module.exports = ReactDOMComponentTree;
|
17540 | }).call(this,require('_process'))
|
17541 | },{"./DOMProperty":164,"./ReactDOMComponentFlags":185,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],187:[function(require,module,exports){
|
17542 | (function (process){
|
17543 | /**
|
17544 | * Copyright 2013-present, Facebook, Inc.
|
17545 | * All rights reserved.
|
17546 | *
|
17547 | * This source code is licensed under the BSD-style license found in the
|
17548 | * LICENSE file in the root directory of this source tree. An additional grant
|
17549 | * of patent rights can be found in the PATENTS file in the same directory.
|
17550 | *
|
17551 | */
|
17552 |
|
17553 | 'use strict';
|
17554 |
|
17555 | var validateDOMNesting = require('./validateDOMNesting');
|
17556 |
|
17557 | var DOC_NODE_TYPE = 9;
|
17558 |
|
17559 | function ReactDOMContainerInfo(topLevelWrapper, node) {
|
17560 | var info = {
|
17561 | _topLevelWrapper: topLevelWrapper,
|
17562 | _idCounter: 1,
|
17563 | _ownerDocument: node ? node.nodeType === DOC_NODE_TYPE ? node : node.ownerDocument : null,
|
17564 | _node: node,
|
17565 | _tag: node ? node.nodeName.toLowerCase() : null,
|
17566 | _namespaceURI: node ? node.namespaceURI : null
|
17567 | };
|
17568 | if (process.env.NODE_ENV !== 'production') {
|
17569 | info._ancestorInfo = node ? validateDOMNesting.updatedAncestorInfo(null, info._tag, null) : null;
|
17570 | }
|
17571 | return info;
|
17572 | }
|
17573 |
|
17574 | module.exports = ReactDOMContainerInfo;
|
17575 | }).call(this,require('_process'))
|
17576 | },{"./validateDOMNesting":282,"_process":144}],188:[function(require,module,exports){
|
17577 | /**
|
17578 | * Copyright 2014-present, Facebook, Inc.
|
17579 | * All rights reserved.
|
17580 | *
|
17581 | * This source code is licensed under the BSD-style license found in the
|
17582 | * LICENSE file in the root directory of this source tree. An additional grant
|
17583 | * of patent rights can be found in the PATENTS file in the same directory.
|
17584 | *
|
17585 | */
|
17586 |
|
17587 | 'use strict';
|
17588 |
|
17589 | var _assign = require('object-assign');
|
17590 |
|
17591 | var DOMLazyTree = require('./DOMLazyTree');
|
17592 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
17593 |
|
17594 | var ReactDOMEmptyComponent = function (instantiate) {
|
17595 | // ReactCompositeComponent uses this:
|
17596 | this._currentElement = null;
|
17597 | // ReactDOMComponentTree uses these:
|
17598 | this._hostNode = null;
|
17599 | this._hostParent = null;
|
17600 | this._hostContainerInfo = null;
|
17601 | this._domID = 0;
|
17602 | };
|
17603 | _assign(ReactDOMEmptyComponent.prototype, {
|
17604 | mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
|
17605 | var domID = hostContainerInfo._idCounter++;
|
17606 | this._domID = domID;
|
17607 | this._hostParent = hostParent;
|
17608 | this._hostContainerInfo = hostContainerInfo;
|
17609 |
|
17610 | var nodeValue = ' react-empty: ' + this._domID + ' ';
|
17611 | if (transaction.useCreateElement) {
|
17612 | var ownerDocument = hostContainerInfo._ownerDocument;
|
17613 | var node = ownerDocument.createComment(nodeValue);
|
17614 | ReactDOMComponentTree.precacheNode(this, node);
|
17615 | return DOMLazyTree(node);
|
17616 | } else {
|
17617 | if (transaction.renderToStaticMarkup) {
|
17618 | // Normally we'd insert a comment node, but since this is a situation
|
17619 | // where React won't take over (static pages), we can simply return
|
17620 | // nothing.
|
17621 | return '';
|
17622 | }
|
17623 | return '<!--' + nodeValue + '-->';
|
17624 | }
|
17625 | },
|
17626 | receiveComponent: function () {},
|
17627 | getHostNode: function () {
|
17628 | return ReactDOMComponentTree.getNodeFromInstance(this);
|
17629 | },
|
17630 | unmountComponent: function () {
|
17631 | ReactDOMComponentTree.uncacheNode(this);
|
17632 | }
|
17633 | });
|
17634 |
|
17635 | module.exports = ReactDOMEmptyComponent;
|
17636 | },{"./DOMLazyTree":162,"./ReactDOMComponentTree":186,"object-assign":143}],189:[function(require,module,exports){
|
17637 | /**
|
17638 | * Copyright 2013-present, Facebook, Inc.
|
17639 | * All rights reserved.
|
17640 | *
|
17641 | * This source code is licensed under the BSD-style license found in the
|
17642 | * LICENSE file in the root directory of this source tree. An additional grant
|
17643 | * of patent rights can be found in the PATENTS file in the same directory.
|
17644 | *
|
17645 | */
|
17646 |
|
17647 | 'use strict';
|
17648 |
|
17649 | var ReactDOMFeatureFlags = {
|
17650 | useCreateElement: true,
|
17651 | useFiber: false
|
17652 | };
|
17653 |
|
17654 | module.exports = ReactDOMFeatureFlags;
|
17655 | },{}],190:[function(require,module,exports){
|
17656 | /**
|
17657 | * Copyright 2013-present, Facebook, Inc.
|
17658 | * All rights reserved.
|
17659 | *
|
17660 | * This source code is licensed under the BSD-style license found in the
|
17661 | * LICENSE file in the root directory of this source tree. An additional grant
|
17662 | * of patent rights can be found in the PATENTS file in the same directory.
|
17663 | *
|
17664 | */
|
17665 |
|
17666 | 'use strict';
|
17667 |
|
17668 | var DOMChildrenOperations = require('./DOMChildrenOperations');
|
17669 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
17670 |
|
17671 | /**
|
17672 | * Operations used to process updates to DOM nodes.
|
17673 | */
|
17674 | var ReactDOMIDOperations = {
|
17675 |
|
17676 | /**
|
17677 | * Updates a component's children by processing a series of updates.
|
17678 | *
|
17679 | * @param {array<object>} updates List of update configurations.
|
17680 | * @internal
|
17681 | */
|
17682 | dangerouslyProcessChildrenUpdates: function (parentInst, updates) {
|
17683 | var node = ReactDOMComponentTree.getNodeFromInstance(parentInst);
|
17684 | DOMChildrenOperations.processUpdates(node, updates);
|
17685 | }
|
17686 | };
|
17687 |
|
17688 | module.exports = ReactDOMIDOperations;
|
17689 | },{"./DOMChildrenOperations":161,"./ReactDOMComponentTree":186}],191:[function(require,module,exports){
|
17690 | (function (process){
|
17691 | /**
|
17692 | * Copyright 2013-present, Facebook, Inc.
|
17693 | * All rights reserved.
|
17694 | *
|
17695 | * This source code is licensed under the BSD-style license found in the
|
17696 | * LICENSE file in the root directory of this source tree. An additional grant
|
17697 | * of patent rights can be found in the PATENTS file in the same directory.
|
17698 | *
|
17699 | */
|
17700 |
|
17701 | 'use strict';
|
17702 |
|
17703 | var _prodInvariant = require('./reactProdInvariant'),
|
17704 | _assign = require('object-assign');
|
17705 |
|
17706 | var DOMPropertyOperations = require('./DOMPropertyOperations');
|
17707 | var LinkedValueUtils = require('./LinkedValueUtils');
|
17708 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
17709 | var ReactUpdates = require('./ReactUpdates');
|
17710 |
|
17711 | var invariant = require('fbjs/lib/invariant');
|
17712 | var warning = require('fbjs/lib/warning');
|
17713 |
|
17714 | var didWarnValueLink = false;
|
17715 | var didWarnCheckedLink = false;
|
17716 | var didWarnValueDefaultValue = false;
|
17717 | var didWarnCheckedDefaultChecked = false;
|
17718 | var didWarnControlledToUncontrolled = false;
|
17719 | var didWarnUncontrolledToControlled = false;
|
17720 |
|
17721 | function forceUpdateIfMounted() {
|
17722 | if (this._rootNodeID) {
|
17723 | // DOM component is still mounted; update
|
17724 | ReactDOMInput.updateWrapper(this);
|
17725 | }
|
17726 | }
|
17727 |
|
17728 | function isControlled(props) {
|
17729 | var usesChecked = props.type === 'checkbox' || props.type === 'radio';
|
17730 | return usesChecked ? props.checked != null : props.value != null;
|
17731 | }
|
17732 |
|
17733 | /**
|
17734 | * Implements an <input> host component that allows setting these optional
|
17735 | * props: `checked`, `value`, `defaultChecked`, and `defaultValue`.
|
17736 | *
|
17737 | * If `checked` or `value` are not supplied (or null/undefined), user actions
|
17738 | * that affect the checked state or value will trigger updates to the element.
|
17739 | *
|
17740 | * If they are supplied (and not null/undefined), the rendered element will not
|
17741 | * trigger updates to the element. Instead, the props must change in order for
|
17742 | * the rendered element to be updated.
|
17743 | *
|
17744 | * The rendered element will be initialized as unchecked (or `defaultChecked`)
|
17745 | * with an empty value (or `defaultValue`).
|
17746 | *
|
17747 | * @see http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
|
17748 | */
|
17749 | var ReactDOMInput = {
|
17750 | getHostProps: function (inst, props) {
|
17751 | var value = LinkedValueUtils.getValue(props);
|
17752 | var checked = LinkedValueUtils.getChecked(props);
|
17753 |
|
17754 | var hostProps = _assign({
|
17755 | // Make sure we set .type before any other properties (setting .value
|
17756 | // before .type means .value is lost in IE11 and below)
|
17757 | type: undefined,
|
17758 | // Make sure we set .step before .value (setting .value before .step
|
17759 | // means .value is rounded on mount, based upon step precision)
|
17760 | step: undefined,
|
17761 | // Make sure we set .min & .max before .value (to ensure proper order
|
17762 | // in corner cases such as min or max deriving from value, e.g. Issue #7170)
|
17763 | min: undefined,
|
17764 | max: undefined
|
17765 | }, props, {
|
17766 | defaultChecked: undefined,
|
17767 | defaultValue: undefined,
|
17768 | value: value != null ? value : inst._wrapperState.initialValue,
|
17769 | checked: checked != null ? checked : inst._wrapperState.initialChecked,
|
17770 | onChange: inst._wrapperState.onChange
|
17771 | });
|
17772 |
|
17773 | return hostProps;
|
17774 | },
|
17775 |
|
17776 | mountWrapper: function (inst, props) {
|
17777 | if (process.env.NODE_ENV !== 'production') {
|
17778 | LinkedValueUtils.checkPropTypes('input', props, inst._currentElement._owner);
|
17779 |
|
17780 | var owner = inst._currentElement._owner;
|
17781 |
|
17782 | if (props.valueLink !== undefined && !didWarnValueLink) {
|
17783 | process.env.NODE_ENV !== 'production' ? warning(false, '`valueLink` prop on `input` is deprecated; set `value` and `onChange` instead.') : void 0;
|
17784 | didWarnValueLink = true;
|
17785 | }
|
17786 | if (props.checkedLink !== undefined && !didWarnCheckedLink) {
|
17787 | process.env.NODE_ENV !== 'production' ? warning(false, '`checkedLink` prop on `input` is deprecated; set `value` and `onChange` instead.') : void 0;
|
17788 | didWarnCheckedLink = true;
|
17789 | }
|
17790 | if (props.checked !== undefined && props.defaultChecked !== undefined && !didWarnCheckedDefaultChecked) {
|
17791 | process.env.NODE_ENV !== 'production' ? warning(false, '%s contains an input of type %s with both checked and defaultChecked props. ' + 'Input elements must be either controlled or uncontrolled ' + '(specify either the checked prop, or the defaultChecked prop, but not ' + 'both). Decide between using a controlled or uncontrolled input ' + 'element and remove one of these props. More info: ' + 'https://fb.me/react-controlled-components', owner && owner.getName() || 'A component', props.type) : void 0;
|
17792 | didWarnCheckedDefaultChecked = true;
|
17793 | }
|
17794 | if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValueDefaultValue) {
|
17795 | process.env.NODE_ENV !== 'production' ? warning(false, '%s contains an input of type %s with both value and defaultValue props. ' + 'Input elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled input ' + 'element and remove one of these props. More info: ' + 'https://fb.me/react-controlled-components', owner && owner.getName() || 'A component', props.type) : void 0;
|
17796 | didWarnValueDefaultValue = true;
|
17797 | }
|
17798 | }
|
17799 |
|
17800 | var defaultValue = props.defaultValue;
|
17801 | inst._wrapperState = {
|
17802 | initialChecked: props.checked != null ? props.checked : props.defaultChecked,
|
17803 | initialValue: props.value != null ? props.value : defaultValue,
|
17804 | listeners: null,
|
17805 | onChange: _handleChange.bind(inst)
|
17806 | };
|
17807 |
|
17808 | if (process.env.NODE_ENV !== 'production') {
|
17809 | inst._wrapperState.controlled = isControlled(props);
|
17810 | }
|
17811 | },
|
17812 |
|
17813 | updateWrapper: function (inst) {
|
17814 | var props = inst._currentElement.props;
|
17815 |
|
17816 | if (process.env.NODE_ENV !== 'production') {
|
17817 | var controlled = isControlled(props);
|
17818 | var owner = inst._currentElement._owner;
|
17819 |
|
17820 | if (!inst._wrapperState.controlled && controlled && !didWarnUncontrolledToControlled) {
|
17821 | process.env.NODE_ENV !== 'production' ? warning(false, '%s is changing an uncontrolled input of type %s to be controlled. ' + 'Input elements should not switch from uncontrolled to controlled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://fb.me/react-controlled-components', owner && owner.getName() || 'A component', props.type) : void 0;
|
17822 | didWarnUncontrolledToControlled = true;
|
17823 | }
|
17824 | if (inst._wrapperState.controlled && !controlled && !didWarnControlledToUncontrolled) {
|
17825 | process.env.NODE_ENV !== 'production' ? warning(false, '%s is changing a controlled input of type %s to be uncontrolled. ' + 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://fb.me/react-controlled-components', owner && owner.getName() || 'A component', props.type) : void 0;
|
17826 | didWarnControlledToUncontrolled = true;
|
17827 | }
|
17828 | }
|
17829 |
|
17830 | // TODO: Shouldn't this be getChecked(props)?
|
17831 | var checked = props.checked;
|
17832 | if (checked != null) {
|
17833 | DOMPropertyOperations.setValueForProperty(ReactDOMComponentTree.getNodeFromInstance(inst), 'checked', checked || false);
|
17834 | }
|
17835 |
|
17836 | var node = ReactDOMComponentTree.getNodeFromInstance(inst);
|
17837 | var value = LinkedValueUtils.getValue(props);
|
17838 | if (value != null) {
|
17839 |
|
17840 | // Cast `value` to a string to ensure the value is set correctly. While
|
17841 | // browsers typically do this as necessary, jsdom doesn't.
|
17842 | var newValue = '' + value;
|
17843 |
|
17844 | // To avoid side effects (such as losing text selection), only set value if changed
|
17845 | if (newValue !== node.value) {
|
17846 | node.value = newValue;
|
17847 | }
|
17848 | } else {
|
17849 | if (props.value == null && props.defaultValue != null) {
|
17850 | node.defaultValue = '' + props.defaultValue;
|
17851 | }
|
17852 | if (props.checked == null && props.defaultChecked != null) {
|
17853 | node.defaultChecked = !!props.defaultChecked;
|
17854 | }
|
17855 | }
|
17856 | },
|
17857 |
|
17858 | postMountWrapper: function (inst) {
|
17859 | var props = inst._currentElement.props;
|
17860 |
|
17861 | // This is in postMount because we need access to the DOM node, which is not
|
17862 | // available until after the component has mounted.
|
17863 | var node = ReactDOMComponentTree.getNodeFromInstance(inst);
|
17864 |
|
17865 | // Detach value from defaultValue. We won't do anything if we're working on
|
17866 | // submit or reset inputs as those values & defaultValues are linked. They
|
17867 | // are not resetable nodes so this operation doesn't matter and actually
|
17868 | // removes browser-default values (eg "Submit Query") when no value is
|
17869 | // provided.
|
17870 |
|
17871 | switch (props.type) {
|
17872 | case 'submit':
|
17873 | case 'reset':
|
17874 | break;
|
17875 | case 'color':
|
17876 | case 'date':
|
17877 | case 'datetime':
|
17878 | case 'datetime-local':
|
17879 | case 'month':
|
17880 | case 'time':
|
17881 | case 'week':
|
17882 | // This fixes the no-show issue on iOS Safari and Android Chrome:
|
17883 | // https://github.com/facebook/react/issues/7233
|
17884 | node.value = '';
|
17885 | node.value = node.defaultValue;
|
17886 | break;
|
17887 | default:
|
17888 | node.value = node.value;
|
17889 | break;
|
17890 | }
|
17891 |
|
17892 | // Normally, we'd just do `node.checked = node.checked` upon initial mount, less this bug
|
17893 | // this is needed to work around a chrome bug where setting defaultChecked
|
17894 | // will sometimes influence the value of checked (even after detachment).
|
17895 | // Reference: https://bugs.chromium.org/p/chromium/issues/detail?id=608416
|
17896 | // We need to temporarily unset name to avoid disrupting radio button groups.
|
17897 | var name = node.name;
|
17898 | if (name !== '') {
|
17899 | node.name = '';
|
17900 | }
|
17901 | node.defaultChecked = !node.defaultChecked;
|
17902 | node.defaultChecked = !node.defaultChecked;
|
17903 | if (name !== '') {
|
17904 | node.name = name;
|
17905 | }
|
17906 | }
|
17907 | };
|
17908 |
|
17909 | function _handleChange(event) {
|
17910 | var props = this._currentElement.props;
|
17911 |
|
17912 | var returnValue = LinkedValueUtils.executeOnChange(props, event);
|
17913 |
|
17914 | // Here we use asap to wait until all updates have propagated, which
|
17915 | // is important when using controlled components within layers:
|
17916 | // https://github.com/facebook/react/issues/1698
|
17917 | ReactUpdates.asap(forceUpdateIfMounted, this);
|
17918 |
|
17919 | var name = props.name;
|
17920 | if (props.type === 'radio' && name != null) {
|
17921 | var rootNode = ReactDOMComponentTree.getNodeFromInstance(this);
|
17922 | var queryRoot = rootNode;
|
17923 |
|
17924 | while (queryRoot.parentNode) {
|
17925 | queryRoot = queryRoot.parentNode;
|
17926 | }
|
17927 |
|
17928 | // If `rootNode.form` was non-null, then we could try `form.elements`,
|
17929 | // but that sometimes behaves strangely in IE8. We could also try using
|
17930 | // `form.getElementsByName`, but that will only return direct children
|
17931 | // and won't include inputs that use the HTML5 `form=` attribute. Since
|
17932 | // the input might not even be in a form, let's just use the global
|
17933 | // `querySelectorAll` to ensure we don't miss anything.
|
17934 | var group = queryRoot.querySelectorAll('input[name=' + JSON.stringify('' + name) + '][type="radio"]');
|
17935 |
|
17936 | for (var i = 0; i < group.length; i++) {
|
17937 | var otherNode = group[i];
|
17938 | if (otherNode === rootNode || otherNode.form !== rootNode.form) {
|
17939 | continue;
|
17940 | }
|
17941 | // This will throw if radio buttons rendered by different copies of React
|
17942 | // and the same name are rendered into the same form (same as #1939).
|
17943 | // That's probably okay; we don't support it just as we don't support
|
17944 | // mixing React radio buttons with non-React ones.
|
17945 | var otherInstance = ReactDOMComponentTree.getInstanceFromNode(otherNode);
|
17946 | !otherInstance ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactDOMInput: Mixing React and non-React radio inputs with the same `name` is not supported.') : _prodInvariant('90') : void 0;
|
17947 | // If this is a controlled radio button group, forcing the input that
|
17948 | // was previously checked to update will cause it to be come re-checked
|
17949 | // as appropriate.
|
17950 | ReactUpdates.asap(forceUpdateIfMounted, otherInstance);
|
17951 | }
|
17952 | }
|
17953 |
|
17954 | return returnValue;
|
17955 | }
|
17956 |
|
17957 | module.exports = ReactDOMInput;
|
17958 | }).call(this,require('_process'))
|
17959 | },{"./DOMPropertyOperations":165,"./LinkedValueUtils":176,"./ReactDOMComponentTree":186,"./ReactUpdates":233,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131,"object-assign":143}],192:[function(require,module,exports){
|
17960 | (function (process){
|
17961 | /**
|
17962 | * Copyright 2013-present, Facebook, Inc.
|
17963 | * All rights reserved.
|
17964 | *
|
17965 | * This source code is licensed under the BSD-style license found in the
|
17966 | * LICENSE file in the root directory of this source tree. An additional grant
|
17967 | * of patent rights can be found in the PATENTS file in the same directory.
|
17968 | *
|
17969 | */
|
17970 |
|
17971 | 'use strict';
|
17972 |
|
17973 | var DOMProperty = require('./DOMProperty');
|
17974 | var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
17975 |
|
17976 | var warning = require('fbjs/lib/warning');
|
17977 |
|
17978 | var warnedProperties = {};
|
17979 | var rARIA = new RegExp('^(aria)-[' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$');
|
17980 |
|
17981 | function validateProperty(tagName, name, debugID) {
|
17982 | if (warnedProperties.hasOwnProperty(name) && warnedProperties[name]) {
|
17983 | return true;
|
17984 | }
|
17985 |
|
17986 | if (rARIA.test(name)) {
|
17987 | var lowerCasedName = name.toLowerCase();
|
17988 | var standardName = DOMProperty.getPossibleStandardName.hasOwnProperty(lowerCasedName) ? DOMProperty.getPossibleStandardName[lowerCasedName] : null;
|
17989 |
|
17990 | // If this is an aria-* attribute, but is not listed in the known DOM
|
17991 | // DOM properties, then it is an invalid aria-* attribute.
|
17992 | if (standardName == null) {
|
17993 | warnedProperties[name] = true;
|
17994 | return false;
|
17995 | }
|
17996 | // aria-* attributes should be lowercase; suggest the lowercase version.
|
17997 | if (name !== standardName) {
|
17998 | process.env.NODE_ENV !== 'production' ? warning(false, 'Unknown ARIA attribute %s. Did you mean %s?%s', name, standardName, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
17999 | warnedProperties[name] = true;
|
18000 | return true;
|
18001 | }
|
18002 | }
|
18003 |
|
18004 | return true;
|
18005 | }
|
18006 |
|
18007 | function warnInvalidARIAProps(debugID, element) {
|
18008 | var invalidProps = [];
|
18009 |
|
18010 | for (var key in element.props) {
|
18011 | var isValid = validateProperty(element.type, key, debugID);
|
18012 | if (!isValid) {
|
18013 | invalidProps.push(key);
|
18014 | }
|
18015 | }
|
18016 |
|
18017 | var unknownPropString = invalidProps.map(function (prop) {
|
18018 | return '`' + prop + '`';
|
18019 | }).join(', ');
|
18020 |
|
18021 | if (invalidProps.length === 1) {
|
18022 | process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid aria prop %s on <%s> tag. ' + 'For details, see https://fb.me/invalid-aria-prop%s', unknownPropString, element.type, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
18023 | } else if (invalidProps.length > 1) {
|
18024 | process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid aria props %s on <%s> tag. ' + 'For details, see https://fb.me/invalid-aria-prop%s', unknownPropString, element.type, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
18025 | }
|
18026 | }
|
18027 |
|
18028 | function handleElement(debugID, element) {
|
18029 | if (element == null || typeof element.type !== 'string') {
|
18030 | return;
|
18031 | }
|
18032 | if (element.type.indexOf('-') >= 0 || element.props.is) {
|
18033 | return;
|
18034 | }
|
18035 |
|
18036 | warnInvalidARIAProps(debugID, element);
|
18037 | }
|
18038 |
|
18039 | var ReactDOMInvalidARIAHook = {
|
18040 | onBeforeMountComponent: function (debugID, element) {
|
18041 | if (process.env.NODE_ENV !== 'production') {
|
18042 | handleElement(debugID, element);
|
18043 | }
|
18044 | },
|
18045 | onBeforeUpdateComponent: function (debugID, element) {
|
18046 | if (process.env.NODE_ENV !== 'production') {
|
18047 | handleElement(debugID, element);
|
18048 | }
|
18049 | }
|
18050 | };
|
18051 |
|
18052 | module.exports = ReactDOMInvalidARIAHook;
|
18053 | }).call(this,require('_process'))
|
18054 | },{"./DOMProperty":164,"_process":144,"fbjs/lib/warning":131,"react/lib/ReactComponentTreeHook":291}],193:[function(require,module,exports){
|
18055 | (function (process){
|
18056 | /**
|
18057 | * Copyright 2013-present, Facebook, Inc.
|
18058 | * All rights reserved.
|
18059 | *
|
18060 | * This source code is licensed under the BSD-style license found in the
|
18061 | * LICENSE file in the root directory of this source tree. An additional grant
|
18062 | * of patent rights can be found in the PATENTS file in the same directory.
|
18063 | *
|
18064 | */
|
18065 |
|
18066 | 'use strict';
|
18067 |
|
18068 | var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
18069 |
|
18070 | var warning = require('fbjs/lib/warning');
|
18071 |
|
18072 | var didWarnValueNull = false;
|
18073 |
|
18074 | function handleElement(debugID, element) {
|
18075 | if (element == null) {
|
18076 | return;
|
18077 | }
|
18078 | if (element.type !== 'input' && element.type !== 'textarea' && element.type !== 'select') {
|
18079 | return;
|
18080 | }
|
18081 | if (element.props != null && element.props.value === null && !didWarnValueNull) {
|
18082 | process.env.NODE_ENV !== 'production' ? warning(false, '`value` prop on `%s` should not be null. ' + 'Consider using the empty string to clear the component or `undefined` ' + 'for uncontrolled components.%s', element.type, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
18083 |
|
18084 | didWarnValueNull = true;
|
18085 | }
|
18086 | }
|
18087 |
|
18088 | var ReactDOMNullInputValuePropHook = {
|
18089 | onBeforeMountComponent: function (debugID, element) {
|
18090 | handleElement(debugID, element);
|
18091 | },
|
18092 | onBeforeUpdateComponent: function (debugID, element) {
|
18093 | handleElement(debugID, element);
|
18094 | }
|
18095 | };
|
18096 |
|
18097 | module.exports = ReactDOMNullInputValuePropHook;
|
18098 | }).call(this,require('_process'))
|
18099 | },{"_process":144,"fbjs/lib/warning":131,"react/lib/ReactComponentTreeHook":291}],194:[function(require,module,exports){
|
18100 | (function (process){
|
18101 | /**
|
18102 | * Copyright 2013-present, Facebook, Inc.
|
18103 | * All rights reserved.
|
18104 | *
|
18105 | * This source code is licensed under the BSD-style license found in the
|
18106 | * LICENSE file in the root directory of this source tree. An additional grant
|
18107 | * of patent rights can be found in the PATENTS file in the same directory.
|
18108 | *
|
18109 | */
|
18110 |
|
18111 | 'use strict';
|
18112 |
|
18113 | var _assign = require('object-assign');
|
18114 |
|
18115 | var React = require('react/lib/React');
|
18116 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
18117 | var ReactDOMSelect = require('./ReactDOMSelect');
|
18118 |
|
18119 | var warning = require('fbjs/lib/warning');
|
18120 | var didWarnInvalidOptionChildren = false;
|
18121 |
|
18122 | function flattenChildren(children) {
|
18123 | var content = '';
|
18124 |
|
18125 | // Flatten children and warn if they aren't strings or numbers;
|
18126 | // invalid types are ignored.
|
18127 | React.Children.forEach(children, function (child) {
|
18128 | if (child == null) {
|
18129 | return;
|
18130 | }
|
18131 | if (typeof child === 'string' || typeof child === 'number') {
|
18132 | content += child;
|
18133 | } else if (!didWarnInvalidOptionChildren) {
|
18134 | didWarnInvalidOptionChildren = true;
|
18135 | process.env.NODE_ENV !== 'production' ? warning(false, 'Only strings and numbers are supported as <option> children.') : void 0;
|
18136 | }
|
18137 | });
|
18138 |
|
18139 | return content;
|
18140 | }
|
18141 |
|
18142 | /**
|
18143 | * Implements an <option> host component that warns when `selected` is set.
|
18144 | */
|
18145 | var ReactDOMOption = {
|
18146 | mountWrapper: function (inst, props, hostParent) {
|
18147 | // TODO (yungsters): Remove support for `selected` in <option>.
|
18148 | if (process.env.NODE_ENV !== 'production') {
|
18149 | process.env.NODE_ENV !== 'production' ? warning(props.selected == null, 'Use the `defaultValue` or `value` props on <select> instead of ' + 'setting `selected` on <option>.') : void 0;
|
18150 | }
|
18151 |
|
18152 | // Look up whether this option is 'selected'
|
18153 | var selectValue = null;
|
18154 | if (hostParent != null) {
|
18155 | var selectParent = hostParent;
|
18156 |
|
18157 | if (selectParent._tag === 'optgroup') {
|
18158 | selectParent = selectParent._hostParent;
|
18159 | }
|
18160 |
|
18161 | if (selectParent != null && selectParent._tag === 'select') {
|
18162 | selectValue = ReactDOMSelect.getSelectValueContext(selectParent);
|
18163 | }
|
18164 | }
|
18165 |
|
18166 | // If the value is null (e.g., no specified value or after initial mount)
|
18167 | // or missing (e.g., for <datalist>), we don't change props.selected
|
18168 | var selected = null;
|
18169 | if (selectValue != null) {
|
18170 | var value;
|
18171 | if (props.value != null) {
|
18172 | value = props.value + '';
|
18173 | } else {
|
18174 | value = flattenChildren(props.children);
|
18175 | }
|
18176 | selected = false;
|
18177 | if (Array.isArray(selectValue)) {
|
18178 | // multiple
|
18179 | for (var i = 0; i < selectValue.length; i++) {
|
18180 | if ('' + selectValue[i] === value) {
|
18181 | selected = true;
|
18182 | break;
|
18183 | }
|
18184 | }
|
18185 | } else {
|
18186 | selected = '' + selectValue === value;
|
18187 | }
|
18188 | }
|
18189 |
|
18190 | inst._wrapperState = { selected: selected };
|
18191 | },
|
18192 |
|
18193 | postMountWrapper: function (inst) {
|
18194 | // value="" should make a value attribute (#6219)
|
18195 | var props = inst._currentElement.props;
|
18196 | if (props.value != null) {
|
18197 | var node = ReactDOMComponentTree.getNodeFromInstance(inst);
|
18198 | node.setAttribute('value', props.value);
|
18199 | }
|
18200 | },
|
18201 |
|
18202 | getHostProps: function (inst, props) {
|
18203 | var hostProps = _assign({ selected: undefined, children: undefined }, props);
|
18204 |
|
18205 | // Read state only from initial mount because <select> updates value
|
18206 | // manually; we need the initial state only for server rendering
|
18207 | if (inst._wrapperState.selected != null) {
|
18208 | hostProps.selected = inst._wrapperState.selected;
|
18209 | }
|
18210 |
|
18211 | var content = flattenChildren(props.children);
|
18212 |
|
18213 | if (content) {
|
18214 | hostProps.children = content;
|
18215 | }
|
18216 |
|
18217 | return hostProps;
|
18218 | }
|
18219 |
|
18220 | };
|
18221 |
|
18222 | module.exports = ReactDOMOption;
|
18223 | }).call(this,require('_process'))
|
18224 | },{"./ReactDOMComponentTree":186,"./ReactDOMSelect":195,"_process":144,"fbjs/lib/warning":131,"object-assign":143,"react/lib/React":287}],195:[function(require,module,exports){
|
18225 | (function (process){
|
18226 | /**
|
18227 | * Copyright 2013-present, Facebook, Inc.
|
18228 | * All rights reserved.
|
18229 | *
|
18230 | * This source code is licensed under the BSD-style license found in the
|
18231 | * LICENSE file in the root directory of this source tree. An additional grant
|
18232 | * of patent rights can be found in the PATENTS file in the same directory.
|
18233 | *
|
18234 | */
|
18235 |
|
18236 | 'use strict';
|
18237 |
|
18238 | var _assign = require('object-assign');
|
18239 |
|
18240 | var LinkedValueUtils = require('./LinkedValueUtils');
|
18241 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
18242 | var ReactUpdates = require('./ReactUpdates');
|
18243 |
|
18244 | var warning = require('fbjs/lib/warning');
|
18245 |
|
18246 | var didWarnValueLink = false;
|
18247 | var didWarnValueDefaultValue = false;
|
18248 |
|
18249 | function updateOptionsIfPendingUpdateAndMounted() {
|
18250 | if (this._rootNodeID && this._wrapperState.pendingUpdate) {
|
18251 | this._wrapperState.pendingUpdate = false;
|
18252 |
|
18253 | var props = this._currentElement.props;
|
18254 | var value = LinkedValueUtils.getValue(props);
|
18255 |
|
18256 | if (value != null) {
|
18257 | updateOptions(this, Boolean(props.multiple), value);
|
18258 | }
|
18259 | }
|
18260 | }
|
18261 |
|
18262 | function getDeclarationErrorAddendum(owner) {
|
18263 | if (owner) {
|
18264 | var name = owner.getName();
|
18265 | if (name) {
|
18266 | return ' Check the render method of `' + name + '`.';
|
18267 | }
|
18268 | }
|
18269 | return '';
|
18270 | }
|
18271 |
|
18272 | var valuePropNames = ['value', 'defaultValue'];
|
18273 |
|
18274 | /**
|
18275 | * Validation function for `value` and `defaultValue`.
|
18276 | * @private
|
18277 | */
|
18278 | function checkSelectPropTypes(inst, props) {
|
18279 | var owner = inst._currentElement._owner;
|
18280 | LinkedValueUtils.checkPropTypes('select', props, owner);
|
18281 |
|
18282 | if (props.valueLink !== undefined && !didWarnValueLink) {
|
18283 | process.env.NODE_ENV !== 'production' ? warning(false, '`valueLink` prop on `select` is deprecated; set `value` and `onChange` instead.') : void 0;
|
18284 | didWarnValueLink = true;
|
18285 | }
|
18286 |
|
18287 | for (var i = 0; i < valuePropNames.length; i++) {
|
18288 | var propName = valuePropNames[i];
|
18289 | if (props[propName] == null) {
|
18290 | continue;
|
18291 | }
|
18292 | var isArray = Array.isArray(props[propName]);
|
18293 | if (props.multiple && !isArray) {
|
18294 | process.env.NODE_ENV !== 'production' ? warning(false, 'The `%s` prop supplied to <select> must be an array if ' + '`multiple` is true.%s', propName, getDeclarationErrorAddendum(owner)) : void 0;
|
18295 | } else if (!props.multiple && isArray) {
|
18296 | process.env.NODE_ENV !== 'production' ? warning(false, 'The `%s` prop supplied to <select> must be a scalar ' + 'value if `multiple` is false.%s', propName, getDeclarationErrorAddendum(owner)) : void 0;
|
18297 | }
|
18298 | }
|
18299 | }
|
18300 |
|
18301 | /**
|
18302 | * @param {ReactDOMComponent} inst
|
18303 | * @param {boolean} multiple
|
18304 | * @param {*} propValue A stringable (with `multiple`, a list of stringables).
|
18305 | * @private
|
18306 | */
|
18307 | function updateOptions(inst, multiple, propValue) {
|
18308 | var selectedValue, i;
|
18309 | var options = ReactDOMComponentTree.getNodeFromInstance(inst).options;
|
18310 |
|
18311 | if (multiple) {
|
18312 | selectedValue = {};
|
18313 | for (i = 0; i < propValue.length; i++) {
|
18314 | selectedValue['' + propValue[i]] = true;
|
18315 | }
|
18316 | for (i = 0; i < options.length; i++) {
|
18317 | var selected = selectedValue.hasOwnProperty(options[i].value);
|
18318 | if (options[i].selected !== selected) {
|
18319 | options[i].selected = selected;
|
18320 | }
|
18321 | }
|
18322 | } else {
|
18323 | // Do not set `select.value` as exact behavior isn't consistent across all
|
18324 | // browsers for all cases.
|
18325 | selectedValue = '' + propValue;
|
18326 | for (i = 0; i < options.length; i++) {
|
18327 | if (options[i].value === selectedValue) {
|
18328 | options[i].selected = true;
|
18329 | return;
|
18330 | }
|
18331 | }
|
18332 | if (options.length) {
|
18333 | options[0].selected = true;
|
18334 | }
|
18335 | }
|
18336 | }
|
18337 |
|
18338 | /**
|
18339 | * Implements a <select> host component that allows optionally setting the
|
18340 | * props `value` and `defaultValue`. If `multiple` is false, the prop must be a
|
18341 | * stringable. If `multiple` is true, the prop must be an array of stringables.
|
18342 | *
|
18343 | * If `value` is not supplied (or null/undefined), user actions that change the
|
18344 | * selected option will trigger updates to the rendered options.
|
18345 | *
|
18346 | * If it is supplied (and not null/undefined), the rendered options will not
|
18347 | * update in response to user actions. Instead, the `value` prop must change in
|
18348 | * order for the rendered options to update.
|
18349 | *
|
18350 | * If `defaultValue` is provided, any options with the supplied values will be
|
18351 | * selected.
|
18352 | */
|
18353 | var ReactDOMSelect = {
|
18354 | getHostProps: function (inst, props) {
|
18355 | return _assign({}, props, {
|
18356 | onChange: inst._wrapperState.onChange,
|
18357 | value: undefined
|
18358 | });
|
18359 | },
|
18360 |
|
18361 | mountWrapper: function (inst, props) {
|
18362 | if (process.env.NODE_ENV !== 'production') {
|
18363 | checkSelectPropTypes(inst, props);
|
18364 | }
|
18365 |
|
18366 | var value = LinkedValueUtils.getValue(props);
|
18367 | inst._wrapperState = {
|
18368 | pendingUpdate: false,
|
18369 | initialValue: value != null ? value : props.defaultValue,
|
18370 | listeners: null,
|
18371 | onChange: _handleChange.bind(inst),
|
18372 | wasMultiple: Boolean(props.multiple)
|
18373 | };
|
18374 |
|
18375 | if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValueDefaultValue) {
|
18376 | process.env.NODE_ENV !== 'production' ? warning(false, 'Select elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled select ' + 'element and remove one of these props. More info: ' + 'https://fb.me/react-controlled-components') : void 0;
|
18377 | didWarnValueDefaultValue = true;
|
18378 | }
|
18379 | },
|
18380 |
|
18381 | getSelectValueContext: function (inst) {
|
18382 | // ReactDOMOption looks at this initial value so the initial generated
|
18383 | // markup has correct `selected` attributes
|
18384 | return inst._wrapperState.initialValue;
|
18385 | },
|
18386 |
|
18387 | postUpdateWrapper: function (inst) {
|
18388 | var props = inst._currentElement.props;
|
18389 |
|
18390 | // After the initial mount, we control selected-ness manually so don't pass
|
18391 | // this value down
|
18392 | inst._wrapperState.initialValue = undefined;
|
18393 |
|
18394 | var wasMultiple = inst._wrapperState.wasMultiple;
|
18395 | inst._wrapperState.wasMultiple = Boolean(props.multiple);
|
18396 |
|
18397 | var value = LinkedValueUtils.getValue(props);
|
18398 | if (value != null) {
|
18399 | inst._wrapperState.pendingUpdate = false;
|
18400 | updateOptions(inst, Boolean(props.multiple), value);
|
18401 | } else if (wasMultiple !== Boolean(props.multiple)) {
|
18402 | // For simplicity, reapply `defaultValue` if `multiple` is toggled.
|
18403 | if (props.defaultValue != null) {
|
18404 | updateOptions(inst, Boolean(props.multiple), props.defaultValue);
|
18405 | } else {
|
18406 | // Revert the select back to its default unselected state.
|
18407 | updateOptions(inst, Boolean(props.multiple), props.multiple ? [] : '');
|
18408 | }
|
18409 | }
|
18410 | }
|
18411 | };
|
18412 |
|
18413 | function _handleChange(event) {
|
18414 | var props = this._currentElement.props;
|
18415 | var returnValue = LinkedValueUtils.executeOnChange(props, event);
|
18416 |
|
18417 | if (this._rootNodeID) {
|
18418 | this._wrapperState.pendingUpdate = true;
|
18419 | }
|
18420 | ReactUpdates.asap(updateOptionsIfPendingUpdateAndMounted, this);
|
18421 | return returnValue;
|
18422 | }
|
18423 |
|
18424 | module.exports = ReactDOMSelect;
|
18425 | }).call(this,require('_process'))
|
18426 | },{"./LinkedValueUtils":176,"./ReactDOMComponentTree":186,"./ReactUpdates":233,"_process":144,"fbjs/lib/warning":131,"object-assign":143}],196:[function(require,module,exports){
|
18427 | /**
|
18428 | * Copyright 2013-present, Facebook, Inc.
|
18429 | * All rights reserved.
|
18430 | *
|
18431 | * This source code is licensed under the BSD-style license found in the
|
18432 | * LICENSE file in the root directory of this source tree. An additional grant
|
18433 | * of patent rights can be found in the PATENTS file in the same directory.
|
18434 | *
|
18435 | */
|
18436 |
|
18437 | 'use strict';
|
18438 |
|
18439 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
18440 |
|
18441 | var getNodeForCharacterOffset = require('./getNodeForCharacterOffset');
|
18442 | var getTextContentAccessor = require('./getTextContentAccessor');
|
18443 |
|
18444 | /**
|
18445 | * While `isCollapsed` is available on the Selection object and `collapsed`
|
18446 | * is available on the Range object, IE11 sometimes gets them wrong.
|
18447 | * If the anchor/focus nodes and offsets are the same, the range is collapsed.
|
18448 | */
|
18449 | function isCollapsed(anchorNode, anchorOffset, focusNode, focusOffset) {
|
18450 | return anchorNode === focusNode && anchorOffset === focusOffset;
|
18451 | }
|
18452 |
|
18453 | /**
|
18454 | * Get the appropriate anchor and focus node/offset pairs for IE.
|
18455 | *
|
18456 | * The catch here is that IE's selection API doesn't provide information
|
18457 | * about whether the selection is forward or backward, so we have to
|
18458 | * behave as though it's always forward.
|
18459 | *
|
18460 | * IE text differs from modern selection in that it behaves as though
|
18461 | * block elements end with a new line. This means character offsets will
|
18462 | * differ between the two APIs.
|
18463 | *
|
18464 | * @param {DOMElement} node
|
18465 | * @return {object}
|
18466 | */
|
18467 | function getIEOffsets(node) {
|
18468 | var selection = document.selection;
|
18469 | var selectedRange = selection.createRange();
|
18470 | var selectedLength = selectedRange.text.length;
|
18471 |
|
18472 | // Duplicate selection so we can move range without breaking user selection.
|
18473 | var fromStart = selectedRange.duplicate();
|
18474 | fromStart.moveToElementText(node);
|
18475 | fromStart.setEndPoint('EndToStart', selectedRange);
|
18476 |
|
18477 | var startOffset = fromStart.text.length;
|
18478 | var endOffset = startOffset + selectedLength;
|
18479 |
|
18480 | return {
|
18481 | start: startOffset,
|
18482 | end: endOffset
|
18483 | };
|
18484 | }
|
18485 |
|
18486 | /**
|
18487 | * @param {DOMElement} node
|
18488 | * @return {?object}
|
18489 | */
|
18490 | function getModernOffsets(node) {
|
18491 | var selection = window.getSelection && window.getSelection();
|
18492 |
|
18493 | if (!selection || selection.rangeCount === 0) {
|
18494 | return null;
|
18495 | }
|
18496 |
|
18497 | var anchorNode = selection.anchorNode;
|
18498 | var anchorOffset = selection.anchorOffset;
|
18499 | var focusNode = selection.focusNode;
|
18500 | var focusOffset = selection.focusOffset;
|
18501 |
|
18502 | var currentRange = selection.getRangeAt(0);
|
18503 |
|
18504 | // In Firefox, range.startContainer and range.endContainer can be "anonymous
|
18505 | // divs", e.g. the up/down buttons on an <input type="number">. Anonymous
|
18506 | // divs do not seem to expose properties, triggering a "Permission denied
|
18507 | // error" if any of its properties are accessed. The only seemingly possible
|
18508 | // way to avoid erroring is to access a property that typically works for
|
18509 | // non-anonymous divs and catch any error that may otherwise arise. See
|
18510 | // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
|
18511 | try {
|
18512 | /* eslint-disable no-unused-expressions */
|
18513 | currentRange.startContainer.nodeType;
|
18514 | currentRange.endContainer.nodeType;
|
18515 | /* eslint-enable no-unused-expressions */
|
18516 | } catch (e) {
|
18517 | return null;
|
18518 | }
|
18519 |
|
18520 | // If the node and offset values are the same, the selection is collapsed.
|
18521 | // `Selection.isCollapsed` is available natively, but IE sometimes gets
|
18522 | // this value wrong.
|
18523 | var isSelectionCollapsed = isCollapsed(selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
|
18524 |
|
18525 | var rangeLength = isSelectionCollapsed ? 0 : currentRange.toString().length;
|
18526 |
|
18527 | var tempRange = currentRange.cloneRange();
|
18528 | tempRange.selectNodeContents(node);
|
18529 | tempRange.setEnd(currentRange.startContainer, currentRange.startOffset);
|
18530 |
|
18531 | var isTempRangeCollapsed = isCollapsed(tempRange.startContainer, tempRange.startOffset, tempRange.endContainer, tempRange.endOffset);
|
18532 |
|
18533 | var start = isTempRangeCollapsed ? 0 : tempRange.toString().length;
|
18534 | var end = start + rangeLength;
|
18535 |
|
18536 | // Detect whether the selection is backward.
|
18537 | var detectionRange = document.createRange();
|
18538 | detectionRange.setStart(anchorNode, anchorOffset);
|
18539 | detectionRange.setEnd(focusNode, focusOffset);
|
18540 | var isBackward = detectionRange.collapsed;
|
18541 |
|
18542 | return {
|
18543 | start: isBackward ? end : start,
|
18544 | end: isBackward ? start : end
|
18545 | };
|
18546 | }
|
18547 |
|
18548 | /**
|
18549 | * @param {DOMElement|DOMTextNode} node
|
18550 | * @param {object} offsets
|
18551 | */
|
18552 | function setIEOffsets(node, offsets) {
|
18553 | var range = document.selection.createRange().duplicate();
|
18554 | var start, end;
|
18555 |
|
18556 | if (offsets.end === undefined) {
|
18557 | start = offsets.start;
|
18558 | end = start;
|
18559 | } else if (offsets.start > offsets.end) {
|
18560 | start = offsets.end;
|
18561 | end = offsets.start;
|
18562 | } else {
|
18563 | start = offsets.start;
|
18564 | end = offsets.end;
|
18565 | }
|
18566 |
|
18567 | range.moveToElementText(node);
|
18568 | range.moveStart('character', start);
|
18569 | range.setEndPoint('EndToStart', range);
|
18570 | range.moveEnd('character', end - start);
|
18571 | range.select();
|
18572 | }
|
18573 |
|
18574 | /**
|
18575 | * In modern non-IE browsers, we can support both forward and backward
|
18576 | * selections.
|
18577 | *
|
18578 | * Note: IE10+ supports the Selection object, but it does not support
|
18579 | * the `extend` method, which means that even in modern IE, it's not possible
|
18580 | * to programmatically create a backward selection. Thus, for all IE
|
18581 | * versions, we use the old IE API to create our selections.
|
18582 | *
|
18583 | * @param {DOMElement|DOMTextNode} node
|
18584 | * @param {object} offsets
|
18585 | */
|
18586 | function setModernOffsets(node, offsets) {
|
18587 | if (!window.getSelection) {
|
18588 | return;
|
18589 | }
|
18590 |
|
18591 | var selection = window.getSelection();
|
18592 | var length = node[getTextContentAccessor()].length;
|
18593 | var start = Math.min(offsets.start, length);
|
18594 | var end = offsets.end === undefined ? start : Math.min(offsets.end, length);
|
18595 |
|
18596 | // IE 11 uses modern selection, but doesn't support the extend method.
|
18597 | // Flip backward selections, so we can set with a single range.
|
18598 | if (!selection.extend && start > end) {
|
18599 | var temp = end;
|
18600 | end = start;
|
18601 | start = temp;
|
18602 | }
|
18603 |
|
18604 | var startMarker = getNodeForCharacterOffset(node, start);
|
18605 | var endMarker = getNodeForCharacterOffset(node, end);
|
18606 |
|
18607 | if (startMarker && endMarker) {
|
18608 | var range = document.createRange();
|
18609 | range.setStart(startMarker.node, startMarker.offset);
|
18610 | selection.removeAllRanges();
|
18611 |
|
18612 | if (start > end) {
|
18613 | selection.addRange(range);
|
18614 | selection.extend(endMarker.node, endMarker.offset);
|
18615 | } else {
|
18616 | range.setEnd(endMarker.node, endMarker.offset);
|
18617 | selection.addRange(range);
|
18618 | }
|
18619 | }
|
18620 | }
|
18621 |
|
18622 | var useIEOffsets = ExecutionEnvironment.canUseDOM && 'selection' in document && !('getSelection' in window);
|
18623 |
|
18624 | var ReactDOMSelection = {
|
18625 | /**
|
18626 | * @param {DOMElement} node
|
18627 | */
|
18628 | getOffsets: useIEOffsets ? getIEOffsets : getModernOffsets,
|
18629 |
|
18630 | /**
|
18631 | * @param {DOMElement|DOMTextNode} node
|
18632 | * @param {object} offsets
|
18633 | */
|
18634 | setOffsets: useIEOffsets ? setIEOffsets : setModernOffsets
|
18635 | };
|
18636 |
|
18637 | module.exports = ReactDOMSelection;
|
18638 | },{"./getNodeForCharacterOffset":269,"./getTextContentAccessor":270,"fbjs/lib/ExecutionEnvironment":110}],197:[function(require,module,exports){
|
18639 | /**
|
18640 | * Copyright 2013-present, Facebook, Inc.
|
18641 | * All rights reserved.
|
18642 | *
|
18643 | * This source code is licensed under the BSD-style license found in the
|
18644 | * LICENSE file in the root directory of this source tree. An additional grant
|
18645 | * of patent rights can be found in the PATENTS file in the same directory.
|
18646 | *
|
18647 | */
|
18648 |
|
18649 | 'use strict';
|
18650 |
|
18651 | var ReactDefaultInjection = require('./ReactDefaultInjection');
|
18652 | var ReactServerRendering = require('./ReactServerRendering');
|
18653 | var ReactVersion = require('./ReactVersion');
|
18654 |
|
18655 | ReactDefaultInjection.inject();
|
18656 |
|
18657 | var ReactDOMServer = {
|
18658 | renderToString: ReactServerRendering.renderToString,
|
18659 | renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup,
|
18660 | version: ReactVersion
|
18661 | };
|
18662 |
|
18663 | module.exports = ReactDOMServer;
|
18664 | },{"./ReactDefaultInjection":204,"./ReactServerRendering":229,"./ReactVersion":234}],198:[function(require,module,exports){
|
18665 | (function (process){
|
18666 | /**
|
18667 | * Copyright 2013-present, Facebook, Inc.
|
18668 | * All rights reserved.
|
18669 | *
|
18670 | * This source code is licensed under the BSD-style license found in the
|
18671 | * LICENSE file in the root directory of this source tree. An additional grant
|
18672 | * of patent rights can be found in the PATENTS file in the same directory.
|
18673 | *
|
18674 | */
|
18675 |
|
18676 | 'use strict';
|
18677 |
|
18678 | var _prodInvariant = require('./reactProdInvariant'),
|
18679 | _assign = require('object-assign');
|
18680 |
|
18681 | var DOMChildrenOperations = require('./DOMChildrenOperations');
|
18682 | var DOMLazyTree = require('./DOMLazyTree');
|
18683 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
18684 |
|
18685 | var escapeTextContentForBrowser = require('./escapeTextContentForBrowser');
|
18686 | var invariant = require('fbjs/lib/invariant');
|
18687 | var validateDOMNesting = require('./validateDOMNesting');
|
18688 |
|
18689 | /**
|
18690 | * Text nodes violate a couple assumptions that React makes about components:
|
18691 | *
|
18692 | * - When mounting text into the DOM, adjacent text nodes are merged.
|
18693 | * - Text nodes cannot be assigned a React root ID.
|
18694 | *
|
18695 | * This component is used to wrap strings between comment nodes so that they
|
18696 | * can undergo the same reconciliation that is applied to elements.
|
18697 | *
|
18698 | * TODO: Investigate representing React components in the DOM with text nodes.
|
18699 | *
|
18700 | * @class ReactDOMTextComponent
|
18701 | * @extends ReactComponent
|
18702 | * @internal
|
18703 | */
|
18704 | var ReactDOMTextComponent = function (text) {
|
18705 | // TODO: This is really a ReactText (ReactNode), not a ReactElement
|
18706 | this._currentElement = text;
|
18707 | this._stringText = '' + text;
|
18708 | // ReactDOMComponentTree uses these:
|
18709 | this._hostNode = null;
|
18710 | this._hostParent = null;
|
18711 |
|
18712 | // Properties
|
18713 | this._domID = 0;
|
18714 | this._mountIndex = 0;
|
18715 | this._closingComment = null;
|
18716 | this._commentNodes = null;
|
18717 | };
|
18718 |
|
18719 | _assign(ReactDOMTextComponent.prototype, {
|
18720 |
|
18721 | /**
|
18722 | * Creates the markup for this text node. This node is not intended to have
|
18723 | * any features besides containing text content.
|
18724 | *
|
18725 | * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
18726 | * @return {string} Markup for this text node.
|
18727 | * @internal
|
18728 | */
|
18729 | mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
|
18730 | if (process.env.NODE_ENV !== 'production') {
|
18731 | var parentInfo;
|
18732 | if (hostParent != null) {
|
18733 | parentInfo = hostParent._ancestorInfo;
|
18734 | } else if (hostContainerInfo != null) {
|
18735 | parentInfo = hostContainerInfo._ancestorInfo;
|
18736 | }
|
18737 | if (parentInfo) {
|
18738 | // parentInfo should always be present except for the top-level
|
18739 | // component when server rendering
|
18740 | validateDOMNesting(null, this._stringText, this, parentInfo);
|
18741 | }
|
18742 | }
|
18743 |
|
18744 | var domID = hostContainerInfo._idCounter++;
|
18745 | var openingValue = ' react-text: ' + domID + ' ';
|
18746 | var closingValue = ' /react-text ';
|
18747 | this._domID = domID;
|
18748 | this._hostParent = hostParent;
|
18749 | if (transaction.useCreateElement) {
|
18750 | var ownerDocument = hostContainerInfo._ownerDocument;
|
18751 | var openingComment = ownerDocument.createComment(openingValue);
|
18752 | var closingComment = ownerDocument.createComment(closingValue);
|
18753 | var lazyTree = DOMLazyTree(ownerDocument.createDocumentFragment());
|
18754 | DOMLazyTree.queueChild(lazyTree, DOMLazyTree(openingComment));
|
18755 | if (this._stringText) {
|
18756 | DOMLazyTree.queueChild(lazyTree, DOMLazyTree(ownerDocument.createTextNode(this._stringText)));
|
18757 | }
|
18758 | DOMLazyTree.queueChild(lazyTree, DOMLazyTree(closingComment));
|
18759 | ReactDOMComponentTree.precacheNode(this, openingComment);
|
18760 | this._closingComment = closingComment;
|
18761 | return lazyTree;
|
18762 | } else {
|
18763 | var escapedText = escapeTextContentForBrowser(this._stringText);
|
18764 |
|
18765 | if (transaction.renderToStaticMarkup) {
|
18766 | // Normally we'd wrap this between comment nodes for the reasons stated
|
18767 | // above, but since this is a situation where React won't take over
|
18768 | // (static pages), we can simply return the text as it is.
|
18769 | return escapedText;
|
18770 | }
|
18771 |
|
18772 | return '<!--' + openingValue + '-->' + escapedText + '<!--' + closingValue + '-->';
|
18773 | }
|
18774 | },
|
18775 |
|
18776 | /**
|
18777 | * Updates this component by updating the text content.
|
18778 | *
|
18779 | * @param {ReactText} nextText The next text content
|
18780 | * @param {ReactReconcileTransaction} transaction
|
18781 | * @internal
|
18782 | */
|
18783 | receiveComponent: function (nextText, transaction) {
|
18784 | if (nextText !== this._currentElement) {
|
18785 | this._currentElement = nextText;
|
18786 | var nextStringText = '' + nextText;
|
18787 | if (nextStringText !== this._stringText) {
|
18788 | // TODO: Save this as pending props and use performUpdateIfNecessary
|
18789 | // and/or updateComponent to do the actual update for consistency with
|
18790 | // other component types?
|
18791 | this._stringText = nextStringText;
|
18792 | var commentNodes = this.getHostNode();
|
18793 | DOMChildrenOperations.replaceDelimitedText(commentNodes[0], commentNodes[1], nextStringText);
|
18794 | }
|
18795 | }
|
18796 | },
|
18797 |
|
18798 | getHostNode: function () {
|
18799 | var hostNode = this._commentNodes;
|
18800 | if (hostNode) {
|
18801 | return hostNode;
|
18802 | }
|
18803 | if (!this._closingComment) {
|
18804 | var openingComment = ReactDOMComponentTree.getNodeFromInstance(this);
|
18805 | var node = openingComment.nextSibling;
|
18806 | while (true) {
|
18807 | !(node != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Missing closing comment for text component %s', this._domID) : _prodInvariant('67', this._domID) : void 0;
|
18808 | if (node.nodeType === 8 && node.nodeValue === ' /react-text ') {
|
18809 | this._closingComment = node;
|
18810 | break;
|
18811 | }
|
18812 | node = node.nextSibling;
|
18813 | }
|
18814 | }
|
18815 | hostNode = [this._hostNode, this._closingComment];
|
18816 | this._commentNodes = hostNode;
|
18817 | return hostNode;
|
18818 | },
|
18819 |
|
18820 | unmountComponent: function () {
|
18821 | this._closingComment = null;
|
18822 | this._commentNodes = null;
|
18823 | ReactDOMComponentTree.uncacheNode(this);
|
18824 | }
|
18825 |
|
18826 | });
|
18827 |
|
18828 | module.exports = ReactDOMTextComponent;
|
18829 | }).call(this,require('_process'))
|
18830 | },{"./DOMChildrenOperations":161,"./DOMLazyTree":162,"./ReactDOMComponentTree":186,"./escapeTextContentForBrowser":258,"./reactProdInvariant":276,"./validateDOMNesting":282,"_process":144,"fbjs/lib/invariant":124,"object-assign":143}],199:[function(require,module,exports){
|
18831 | (function (process){
|
18832 | /**
|
18833 | * Copyright 2013-present, Facebook, Inc.
|
18834 | * All rights reserved.
|
18835 | *
|
18836 | * This source code is licensed under the BSD-style license found in the
|
18837 | * LICENSE file in the root directory of this source tree. An additional grant
|
18838 | * of patent rights can be found in the PATENTS file in the same directory.
|
18839 | *
|
18840 | */
|
18841 |
|
18842 | 'use strict';
|
18843 |
|
18844 | var _prodInvariant = require('./reactProdInvariant'),
|
18845 | _assign = require('object-assign');
|
18846 |
|
18847 | var LinkedValueUtils = require('./LinkedValueUtils');
|
18848 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
18849 | var ReactUpdates = require('./ReactUpdates');
|
18850 |
|
18851 | var invariant = require('fbjs/lib/invariant');
|
18852 | var warning = require('fbjs/lib/warning');
|
18853 |
|
18854 | var didWarnValueLink = false;
|
18855 | var didWarnValDefaultVal = false;
|
18856 |
|
18857 | function forceUpdateIfMounted() {
|
18858 | if (this._rootNodeID) {
|
18859 | // DOM component is still mounted; update
|
18860 | ReactDOMTextarea.updateWrapper(this);
|
18861 | }
|
18862 | }
|
18863 |
|
18864 | /**
|
18865 | * Implements a <textarea> host component that allows setting `value`, and
|
18866 | * `defaultValue`. This differs from the traditional DOM API because value is
|
18867 | * usually set as PCDATA children.
|
18868 | *
|
18869 | * If `value` is not supplied (or null/undefined), user actions that affect the
|
18870 | * value will trigger updates to the element.
|
18871 | *
|
18872 | * If `value` is supplied (and not null/undefined), the rendered element will
|
18873 | * not trigger updates to the element. Instead, the `value` prop must change in
|
18874 | * order for the rendered element to be updated.
|
18875 | *
|
18876 | * The rendered element will be initialized with an empty value, the prop
|
18877 | * `defaultValue` if specified, or the children content (deprecated).
|
18878 | */
|
18879 | var ReactDOMTextarea = {
|
18880 | getHostProps: function (inst, props) {
|
18881 | !(props.dangerouslySetInnerHTML == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, '`dangerouslySetInnerHTML` does not make sense on <textarea>.') : _prodInvariant('91') : void 0;
|
18882 |
|
18883 | // Always set children to the same thing. In IE9, the selection range will
|
18884 | // get reset if `textContent` is mutated. We could add a check in setTextContent
|
18885 | // to only set the value if/when the value differs from the node value (which would
|
18886 | // completely solve this IE9 bug), but Sebastian+Ben seemed to like this solution.
|
18887 | // The value can be a boolean or object so that's why it's forced to be a string.
|
18888 | var hostProps = _assign({}, props, {
|
18889 | value: undefined,
|
18890 | defaultValue: undefined,
|
18891 | children: '' + inst._wrapperState.initialValue,
|
18892 | onChange: inst._wrapperState.onChange
|
18893 | });
|
18894 |
|
18895 | return hostProps;
|
18896 | },
|
18897 |
|
18898 | mountWrapper: function (inst, props) {
|
18899 | if (process.env.NODE_ENV !== 'production') {
|
18900 | LinkedValueUtils.checkPropTypes('textarea', props, inst._currentElement._owner);
|
18901 | if (props.valueLink !== undefined && !didWarnValueLink) {
|
18902 | process.env.NODE_ENV !== 'production' ? warning(false, '`valueLink` prop on `textarea` is deprecated; set `value` and `onChange` instead.') : void 0;
|
18903 | didWarnValueLink = true;
|
18904 | }
|
18905 | if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValDefaultVal) {
|
18906 | process.env.NODE_ENV !== 'production' ? warning(false, 'Textarea elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled textarea ' + 'and remove one of these props. More info: ' + 'https://fb.me/react-controlled-components') : void 0;
|
18907 | didWarnValDefaultVal = true;
|
18908 | }
|
18909 | }
|
18910 |
|
18911 | var value = LinkedValueUtils.getValue(props);
|
18912 | var initialValue = value;
|
18913 |
|
18914 | // Only bother fetching default value if we're going to use it
|
18915 | if (value == null) {
|
18916 | var defaultValue = props.defaultValue;
|
18917 | // TODO (yungsters): Remove support for children content in <textarea>.
|
18918 | var children = props.children;
|
18919 | if (children != null) {
|
18920 | if (process.env.NODE_ENV !== 'production') {
|
18921 | process.env.NODE_ENV !== 'production' ? warning(false, 'Use the `defaultValue` or `value` props instead of setting ' + 'children on <textarea>.') : void 0;
|
18922 | }
|
18923 | !(defaultValue == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'If you supply `defaultValue` on a <textarea>, do not pass children.') : _prodInvariant('92') : void 0;
|
18924 | if (Array.isArray(children)) {
|
18925 | !(children.length <= 1) ? process.env.NODE_ENV !== 'production' ? invariant(false, '<textarea> can only have at most one child.') : _prodInvariant('93') : void 0;
|
18926 | children = children[0];
|
18927 | }
|
18928 |
|
18929 | defaultValue = '' + children;
|
18930 | }
|
18931 | if (defaultValue == null) {
|
18932 | defaultValue = '';
|
18933 | }
|
18934 | initialValue = defaultValue;
|
18935 | }
|
18936 |
|
18937 | inst._wrapperState = {
|
18938 | initialValue: '' + initialValue,
|
18939 | listeners: null,
|
18940 | onChange: _handleChange.bind(inst)
|
18941 | };
|
18942 | },
|
18943 |
|
18944 | updateWrapper: function (inst) {
|
18945 | var props = inst._currentElement.props;
|
18946 |
|
18947 | var node = ReactDOMComponentTree.getNodeFromInstance(inst);
|
18948 | var value = LinkedValueUtils.getValue(props);
|
18949 | if (value != null) {
|
18950 | // Cast `value` to a string to ensure the value is set correctly. While
|
18951 | // browsers typically do this as necessary, jsdom doesn't.
|
18952 | var newValue = '' + value;
|
18953 |
|
18954 | // To avoid side effects (such as losing text selection), only set value if changed
|
18955 | if (newValue !== node.value) {
|
18956 | node.value = newValue;
|
18957 | }
|
18958 | if (props.defaultValue == null) {
|
18959 | node.defaultValue = newValue;
|
18960 | }
|
18961 | }
|
18962 | if (props.defaultValue != null) {
|
18963 | node.defaultValue = props.defaultValue;
|
18964 | }
|
18965 | },
|
18966 |
|
18967 | postMountWrapper: function (inst) {
|
18968 | // This is in postMount because we need access to the DOM node, which is not
|
18969 | // available until after the component has mounted.
|
18970 | var node = ReactDOMComponentTree.getNodeFromInstance(inst);
|
18971 |
|
18972 | // Warning: node.value may be the empty string at this point (IE11) if placeholder is set.
|
18973 | node.value = node.textContent; // Detach value from defaultValue
|
18974 | }
|
18975 | };
|
18976 |
|
18977 | function _handleChange(event) {
|
18978 | var props = this._currentElement.props;
|
18979 | var returnValue = LinkedValueUtils.executeOnChange(props, event);
|
18980 | ReactUpdates.asap(forceUpdateIfMounted, this);
|
18981 | return returnValue;
|
18982 | }
|
18983 |
|
18984 | module.exports = ReactDOMTextarea;
|
18985 | }).call(this,require('_process'))
|
18986 | },{"./LinkedValueUtils":176,"./ReactDOMComponentTree":186,"./ReactUpdates":233,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131,"object-assign":143}],200:[function(require,module,exports){
|
18987 | (function (process){
|
18988 | /**
|
18989 | * Copyright 2015-present, Facebook, Inc.
|
18990 | * All rights reserved.
|
18991 | *
|
18992 | * This source code is licensed under the BSD-style license found in the
|
18993 | * LICENSE file in the root directory of this source tree. An additional grant
|
18994 | * of patent rights can be found in the PATENTS file in the same directory.
|
18995 | *
|
18996 | */
|
18997 |
|
18998 | 'use strict';
|
18999 |
|
19000 | var _prodInvariant = require('./reactProdInvariant');
|
19001 |
|
19002 | var invariant = require('fbjs/lib/invariant');
|
19003 |
|
19004 | /**
|
19005 | * Return the lowest common ancestor of A and B, or null if they are in
|
19006 | * different trees.
|
19007 | */
|
19008 | function getLowestCommonAncestor(instA, instB) {
|
19009 | !('_hostNode' in instA) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'getNodeFromInstance: Invalid argument.') : _prodInvariant('33') : void 0;
|
19010 | !('_hostNode' in instB) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'getNodeFromInstance: Invalid argument.') : _prodInvariant('33') : void 0;
|
19011 |
|
19012 | var depthA = 0;
|
19013 | for (var tempA = instA; tempA; tempA = tempA._hostParent) {
|
19014 | depthA++;
|
19015 | }
|
19016 | var depthB = 0;
|
19017 | for (var tempB = instB; tempB; tempB = tempB._hostParent) {
|
19018 | depthB++;
|
19019 | }
|
19020 |
|
19021 | // If A is deeper, crawl up.
|
19022 | while (depthA - depthB > 0) {
|
19023 | instA = instA._hostParent;
|
19024 | depthA--;
|
19025 | }
|
19026 |
|
19027 | // If B is deeper, crawl up.
|
19028 | while (depthB - depthA > 0) {
|
19029 | instB = instB._hostParent;
|
19030 | depthB--;
|
19031 | }
|
19032 |
|
19033 | // Walk in lockstep until we find a match.
|
19034 | var depth = depthA;
|
19035 | while (depth--) {
|
19036 | if (instA === instB) {
|
19037 | return instA;
|
19038 | }
|
19039 | instA = instA._hostParent;
|
19040 | instB = instB._hostParent;
|
19041 | }
|
19042 | return null;
|
19043 | }
|
19044 |
|
19045 | /**
|
19046 | * Return if A is an ancestor of B.
|
19047 | */
|
19048 | function isAncestor(instA, instB) {
|
19049 | !('_hostNode' in instA) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'isAncestor: Invalid argument.') : _prodInvariant('35') : void 0;
|
19050 | !('_hostNode' in instB) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'isAncestor: Invalid argument.') : _prodInvariant('35') : void 0;
|
19051 |
|
19052 | while (instB) {
|
19053 | if (instB === instA) {
|
19054 | return true;
|
19055 | }
|
19056 | instB = instB._hostParent;
|
19057 | }
|
19058 | return false;
|
19059 | }
|
19060 |
|
19061 | /**
|
19062 | * Return the parent instance of the passed-in instance.
|
19063 | */
|
19064 | function getParentInstance(inst) {
|
19065 | !('_hostNode' in inst) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'getParentInstance: Invalid argument.') : _prodInvariant('36') : void 0;
|
19066 |
|
19067 | return inst._hostParent;
|
19068 | }
|
19069 |
|
19070 | /**
|
19071 | * Simulates the traversal of a two-phase, capture/bubble event dispatch.
|
19072 | */
|
19073 | function traverseTwoPhase(inst, fn, arg) {
|
19074 | var path = [];
|
19075 | while (inst) {
|
19076 | path.push(inst);
|
19077 | inst = inst._hostParent;
|
19078 | }
|
19079 | var i;
|
19080 | for (i = path.length; i-- > 0;) {
|
19081 | fn(path[i], 'captured', arg);
|
19082 | }
|
19083 | for (i = 0; i < path.length; i++) {
|
19084 | fn(path[i], 'bubbled', arg);
|
19085 | }
|
19086 | }
|
19087 |
|
19088 | /**
|
19089 | * Traverses the ID hierarchy and invokes the supplied `cb` on any IDs that
|
19090 | * should would receive a `mouseEnter` or `mouseLeave` event.
|
19091 | *
|
19092 | * Does not invoke the callback on the nearest common ancestor because nothing
|
19093 | * "entered" or "left" that element.
|
19094 | */
|
19095 | function traverseEnterLeave(from, to, fn, argFrom, argTo) {
|
19096 | var common = from && to ? getLowestCommonAncestor(from, to) : null;
|
19097 | var pathFrom = [];
|
19098 | while (from && from !== common) {
|
19099 | pathFrom.push(from);
|
19100 | from = from._hostParent;
|
19101 | }
|
19102 | var pathTo = [];
|
19103 | while (to && to !== common) {
|
19104 | pathTo.push(to);
|
19105 | to = to._hostParent;
|
19106 | }
|
19107 | var i;
|
19108 | for (i = 0; i < pathFrom.length; i++) {
|
19109 | fn(pathFrom[i], 'bubbled', argFrom);
|
19110 | }
|
19111 | for (i = pathTo.length; i-- > 0;) {
|
19112 | fn(pathTo[i], 'captured', argTo);
|
19113 | }
|
19114 | }
|
19115 |
|
19116 | module.exports = {
|
19117 | isAncestor: isAncestor,
|
19118 | getLowestCommonAncestor: getLowestCommonAncestor,
|
19119 | getParentInstance: getParentInstance,
|
19120 | traverseTwoPhase: traverseTwoPhase,
|
19121 | traverseEnterLeave: traverseEnterLeave
|
19122 | };
|
19123 | }).call(this,require('_process'))
|
19124 | },{"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],201:[function(require,module,exports){
|
19125 | (function (process){
|
19126 | /**
|
19127 | * Copyright 2013-present, Facebook, Inc.
|
19128 | * All rights reserved.
|
19129 | *
|
19130 | * This source code is licensed under the BSD-style license found in the
|
19131 | * LICENSE file in the root directory of this source tree. An additional grant
|
19132 | * of patent rights can be found in the PATENTS file in the same directory.
|
19133 | *
|
19134 | */
|
19135 |
|
19136 | 'use strict';
|
19137 |
|
19138 | var DOMProperty = require('./DOMProperty');
|
19139 | var EventPluginRegistry = require('./EventPluginRegistry');
|
19140 | var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
19141 |
|
19142 | var warning = require('fbjs/lib/warning');
|
19143 |
|
19144 | if (process.env.NODE_ENV !== 'production') {
|
19145 | var reactProps = {
|
19146 | children: true,
|
19147 | dangerouslySetInnerHTML: true,
|
19148 | key: true,
|
19149 | ref: true,
|
19150 |
|
19151 | autoFocus: true,
|
19152 | defaultValue: true,
|
19153 | valueLink: true,
|
19154 | defaultChecked: true,
|
19155 | checkedLink: true,
|
19156 | innerHTML: true,
|
19157 | suppressContentEditableWarning: true,
|
19158 | onFocusIn: true,
|
19159 | onFocusOut: true
|
19160 | };
|
19161 | var warnedProperties = {};
|
19162 |
|
19163 | var validateProperty = function (tagName, name, debugID) {
|
19164 | if (DOMProperty.properties.hasOwnProperty(name) || DOMProperty.isCustomAttribute(name)) {
|
19165 | return true;
|
19166 | }
|
19167 | if (reactProps.hasOwnProperty(name) && reactProps[name] || warnedProperties.hasOwnProperty(name) && warnedProperties[name]) {
|
19168 | return true;
|
19169 | }
|
19170 | if (EventPluginRegistry.registrationNameModules.hasOwnProperty(name)) {
|
19171 | return true;
|
19172 | }
|
19173 | warnedProperties[name] = true;
|
19174 | var lowerCasedName = name.toLowerCase();
|
19175 |
|
19176 | // data-* attributes should be lowercase; suggest the lowercase version
|
19177 | var standardName = DOMProperty.isCustomAttribute(lowerCasedName) ? lowerCasedName : DOMProperty.getPossibleStandardName.hasOwnProperty(lowerCasedName) ? DOMProperty.getPossibleStandardName[lowerCasedName] : null;
|
19178 |
|
19179 | var registrationName = EventPluginRegistry.possibleRegistrationNames.hasOwnProperty(lowerCasedName) ? EventPluginRegistry.possibleRegistrationNames[lowerCasedName] : null;
|
19180 |
|
19181 | if (standardName != null) {
|
19182 | process.env.NODE_ENV !== 'production' ? warning(false, 'Unknown DOM property %s. Did you mean %s?%s', name, standardName, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
19183 | return true;
|
19184 | } else if (registrationName != null) {
|
19185 | process.env.NODE_ENV !== 'production' ? warning(false, 'Unknown event handler property %s. Did you mean `%s`?%s', name, registrationName, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
19186 | return true;
|
19187 | } else {
|
19188 | // We were unable to guess which prop the user intended.
|
19189 | // It is likely that the user was just blindly spreading/forwarding props
|
19190 | // Components should be careful to only render valid props/attributes.
|
19191 | // Warning will be invoked in warnUnknownProperties to allow grouping.
|
19192 | return false;
|
19193 | }
|
19194 | };
|
19195 | }
|
19196 |
|
19197 | var warnUnknownProperties = function (debugID, element) {
|
19198 | var unknownProps = [];
|
19199 | for (var key in element.props) {
|
19200 | var isValid = validateProperty(element.type, key, debugID);
|
19201 | if (!isValid) {
|
19202 | unknownProps.push(key);
|
19203 | }
|
19204 | }
|
19205 |
|
19206 | var unknownPropString = unknownProps.map(function (prop) {
|
19207 | return '`' + prop + '`';
|
19208 | }).join(', ');
|
19209 |
|
19210 | if (unknownProps.length === 1) {
|
19211 | process.env.NODE_ENV !== 'production' ? warning(false, 'Unknown prop %s on <%s> tag. Remove this prop from the element. ' + 'For details, see https://fb.me/react-unknown-prop%s', unknownPropString, element.type, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
19212 | } else if (unknownProps.length > 1) {
|
19213 | process.env.NODE_ENV !== 'production' ? warning(false, 'Unknown props %s on <%s> tag. Remove these props from the element. ' + 'For details, see https://fb.me/react-unknown-prop%s', unknownPropString, element.type, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
|
19214 | }
|
19215 | };
|
19216 |
|
19217 | function handleElement(debugID, element) {
|
19218 | if (element == null || typeof element.type !== 'string') {
|
19219 | return;
|
19220 | }
|
19221 | if (element.type.indexOf('-') >= 0 || element.props.is) {
|
19222 | return;
|
19223 | }
|
19224 | warnUnknownProperties(debugID, element);
|
19225 | }
|
19226 |
|
19227 | var ReactDOMUnknownPropertyHook = {
|
19228 | onBeforeMountComponent: function (debugID, element) {
|
19229 | handleElement(debugID, element);
|
19230 | },
|
19231 | onBeforeUpdateComponent: function (debugID, element) {
|
19232 | handleElement(debugID, element);
|
19233 | }
|
19234 | };
|
19235 |
|
19236 | module.exports = ReactDOMUnknownPropertyHook;
|
19237 | }).call(this,require('_process'))
|
19238 | },{"./DOMProperty":164,"./EventPluginRegistry":170,"_process":144,"fbjs/lib/warning":131,"react/lib/ReactComponentTreeHook":291}],202:[function(require,module,exports){
|
19239 | (function (process){
|
19240 | /**
|
19241 | * Copyright 2016-present, Facebook, Inc.
|
19242 | * All rights reserved.
|
19243 | *
|
19244 | * This source code is licensed under the BSD-style license found in the
|
19245 | * LICENSE file in the root directory of this source tree. An additional grant
|
19246 | * of patent rights can be found in the PATENTS file in the same directory.
|
19247 | *
|
19248 | *
|
19249 | */
|
19250 |
|
19251 | 'use strict';
|
19252 |
|
19253 | var ReactInvalidSetStateWarningHook = require('./ReactInvalidSetStateWarningHook');
|
19254 | var ReactHostOperationHistoryHook = require('./ReactHostOperationHistoryHook');
|
19255 | var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
19256 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
19257 |
|
19258 | var performanceNow = require('fbjs/lib/performanceNow');
|
19259 | var warning = require('fbjs/lib/warning');
|
19260 |
|
19261 | var hooks = [];
|
19262 | var didHookThrowForEvent = {};
|
19263 |
|
19264 | function callHook(event, fn, context, arg1, arg2, arg3, arg4, arg5) {
|
19265 | try {
|
19266 | fn.call(context, arg1, arg2, arg3, arg4, arg5);
|
19267 | } catch (e) {
|
19268 | process.env.NODE_ENV !== 'production' ? warning(didHookThrowForEvent[event], 'Exception thrown by hook while handling %s: %s', event, e + '\n' + e.stack) : void 0;
|
19269 | didHookThrowForEvent[event] = true;
|
19270 | }
|
19271 | }
|
19272 |
|
19273 | function emitEvent(event, arg1, arg2, arg3, arg4, arg5) {
|
19274 | for (var i = 0; i < hooks.length; i++) {
|
19275 | var hook = hooks[i];
|
19276 | var fn = hook[event];
|
19277 | if (fn) {
|
19278 | callHook(event, fn, hook, arg1, arg2, arg3, arg4, arg5);
|
19279 | }
|
19280 | }
|
19281 | }
|
19282 |
|
19283 | var isProfiling = false;
|
19284 | var flushHistory = [];
|
19285 | var lifeCycleTimerStack = [];
|
19286 | var currentFlushNesting = 0;
|
19287 | var currentFlushMeasurements = [];
|
19288 | var currentFlushStartTime = 0;
|
19289 | var currentTimerDebugID = null;
|
19290 | var currentTimerStartTime = 0;
|
19291 | var currentTimerNestedFlushDuration = 0;
|
19292 | var currentTimerType = null;
|
19293 |
|
19294 | var lifeCycleTimerHasWarned = false;
|
19295 |
|
19296 | function clearHistory() {
|
19297 | ReactComponentTreeHook.purgeUnmountedComponents();
|
19298 | ReactHostOperationHistoryHook.clearHistory();
|
19299 | }
|
19300 |
|
19301 | function getTreeSnapshot(registeredIDs) {
|
19302 | return registeredIDs.reduce(function (tree, id) {
|
19303 | var ownerID = ReactComponentTreeHook.getOwnerID(id);
|
19304 | var parentID = ReactComponentTreeHook.getParentID(id);
|
19305 | tree[id] = {
|
19306 | displayName: ReactComponentTreeHook.getDisplayName(id),
|
19307 | text: ReactComponentTreeHook.getText(id),
|
19308 | updateCount: ReactComponentTreeHook.getUpdateCount(id),
|
19309 | childIDs: ReactComponentTreeHook.getChildIDs(id),
|
19310 | // Text nodes don't have owners but this is close enough.
|
19311 | ownerID: ownerID || parentID && ReactComponentTreeHook.getOwnerID(parentID) || 0,
|
19312 | parentID: parentID
|
19313 | };
|
19314 | return tree;
|
19315 | }, {});
|
19316 | }
|
19317 |
|
19318 | function resetMeasurements() {
|
19319 | var previousStartTime = currentFlushStartTime;
|
19320 | var previousMeasurements = currentFlushMeasurements;
|
19321 | var previousOperations = ReactHostOperationHistoryHook.getHistory();
|
19322 |
|
19323 | if (currentFlushNesting === 0) {
|
19324 | currentFlushStartTime = 0;
|
19325 | currentFlushMeasurements = [];
|
19326 | clearHistory();
|
19327 | return;
|
19328 | }
|
19329 |
|
19330 | if (previousMeasurements.length || previousOperations.length) {
|
19331 | var registeredIDs = ReactComponentTreeHook.getRegisteredIDs();
|
19332 | flushHistory.push({
|
19333 | duration: performanceNow() - previousStartTime,
|
19334 | measurements: previousMeasurements || [],
|
19335 | operations: previousOperations || [],
|
19336 | treeSnapshot: getTreeSnapshot(registeredIDs)
|
19337 | });
|
19338 | }
|
19339 |
|
19340 | clearHistory();
|
19341 | currentFlushStartTime = performanceNow();
|
19342 | currentFlushMeasurements = [];
|
19343 | }
|
19344 |
|
19345 | function checkDebugID(debugID) {
|
19346 | var allowRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
19347 |
|
19348 | if (allowRoot && debugID === 0) {
|
19349 | return;
|
19350 | }
|
19351 | if (!debugID) {
|
19352 | process.env.NODE_ENV !== 'production' ? warning(false, 'ReactDebugTool: debugID may not be empty.') : void 0;
|
19353 | }
|
19354 | }
|
19355 |
|
19356 | function beginLifeCycleTimer(debugID, timerType) {
|
19357 | if (currentFlushNesting === 0) {
|
19358 | return;
|
19359 | }
|
19360 | if (currentTimerType && !lifeCycleTimerHasWarned) {
|
19361 | process.env.NODE_ENV !== 'production' ? warning(false, 'There is an internal error in the React performance measurement code. ' + 'Did not expect %s timer to start while %s timer is still in ' + 'progress for %s instance.', timerType, currentTimerType || 'no', debugID === currentTimerDebugID ? 'the same' : 'another') : void 0;
|
19362 | lifeCycleTimerHasWarned = true;
|
19363 | }
|
19364 | currentTimerStartTime = performanceNow();
|
19365 | currentTimerNestedFlushDuration = 0;
|
19366 | currentTimerDebugID = debugID;
|
19367 | currentTimerType = timerType;
|
19368 | }
|
19369 |
|
19370 | function endLifeCycleTimer(debugID, timerType) {
|
19371 | if (currentFlushNesting === 0) {
|
19372 | return;
|
19373 | }
|
19374 | if (currentTimerType !== timerType && !lifeCycleTimerHasWarned) {
|
19375 | process.env.NODE_ENV !== 'production' ? warning(false, 'There is an internal error in the React performance measurement code. ' + 'We did not expect %s timer to stop while %s timer is still in ' + 'progress for %s instance. Please report this as a bug in React.', timerType, currentTimerType || 'no', debugID === currentTimerDebugID ? 'the same' : 'another') : void 0;
|
19376 | lifeCycleTimerHasWarned = true;
|
19377 | }
|
19378 | if (isProfiling) {
|
19379 | currentFlushMeasurements.push({
|
19380 | timerType: timerType,
|
19381 | instanceID: debugID,
|
19382 | duration: performanceNow() - currentTimerStartTime - currentTimerNestedFlushDuration
|
19383 | });
|
19384 | }
|
19385 | currentTimerStartTime = 0;
|
19386 | currentTimerNestedFlushDuration = 0;
|
19387 | currentTimerDebugID = null;
|
19388 | currentTimerType = null;
|
19389 | }
|
19390 |
|
19391 | function pauseCurrentLifeCycleTimer() {
|
19392 | var currentTimer = {
|
19393 | startTime: currentTimerStartTime,
|
19394 | nestedFlushStartTime: performanceNow(),
|
19395 | debugID: currentTimerDebugID,
|
19396 | timerType: currentTimerType
|
19397 | };
|
19398 | lifeCycleTimerStack.push(currentTimer);
|
19399 | currentTimerStartTime = 0;
|
19400 | currentTimerNestedFlushDuration = 0;
|
19401 | currentTimerDebugID = null;
|
19402 | currentTimerType = null;
|
19403 | }
|
19404 |
|
19405 | function resumeCurrentLifeCycleTimer() {
|
19406 | var _lifeCycleTimerStack$ = lifeCycleTimerStack.pop(),
|
19407 | startTime = _lifeCycleTimerStack$.startTime,
|
19408 | nestedFlushStartTime = _lifeCycleTimerStack$.nestedFlushStartTime,
|
19409 | debugID = _lifeCycleTimerStack$.debugID,
|
19410 | timerType = _lifeCycleTimerStack$.timerType;
|
19411 |
|
19412 | var nestedFlushDuration = performanceNow() - nestedFlushStartTime;
|
19413 | currentTimerStartTime = startTime;
|
19414 | currentTimerNestedFlushDuration += nestedFlushDuration;
|
19415 | currentTimerDebugID = debugID;
|
19416 | currentTimerType = timerType;
|
19417 | }
|
19418 |
|
19419 | var lastMarkTimeStamp = 0;
|
19420 | var canUsePerformanceMeasure =
|
19421 | // $FlowFixMe https://github.com/facebook/flow/issues/2345
|
19422 | typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function';
|
19423 |
|
19424 | function shouldMark(debugID) {
|
19425 | if (!isProfiling || !canUsePerformanceMeasure) {
|
19426 | return false;
|
19427 | }
|
19428 | var element = ReactComponentTreeHook.getElement(debugID);
|
19429 | if (element == null || typeof element !== 'object') {
|
19430 | return false;
|
19431 | }
|
19432 | var isHostElement = typeof element.type === 'string';
|
19433 | if (isHostElement) {
|
19434 | return false;
|
19435 | }
|
19436 | return true;
|
19437 | }
|
19438 |
|
19439 | function markBegin(debugID, markType) {
|
19440 | if (!shouldMark(debugID)) {
|
19441 | return;
|
19442 | }
|
19443 |
|
19444 | var markName = debugID + '::' + markType;
|
19445 | lastMarkTimeStamp = performanceNow();
|
19446 | performance.mark(markName);
|
19447 | }
|
19448 |
|
19449 | function markEnd(debugID, markType) {
|
19450 | if (!shouldMark(debugID)) {
|
19451 | return;
|
19452 | }
|
19453 |
|
19454 | var markName = debugID + '::' + markType;
|
19455 | var displayName = ReactComponentTreeHook.getDisplayName(debugID) || 'Unknown';
|
19456 |
|
19457 | // Chrome has an issue of dropping markers recorded too fast:
|
19458 | // https://bugs.chromium.org/p/chromium/issues/detail?id=640652
|
19459 | // To work around this, we will not report very small measurements.
|
19460 | // I determined the magic number by tweaking it back and forth.
|
19461 | // 0.05ms was enough to prevent the issue, but I set it to 0.1ms to be safe.
|
19462 | // When the bug is fixed, we can `measure()` unconditionally if we want to.
|
19463 | var timeStamp = performanceNow();
|
19464 | if (timeStamp - lastMarkTimeStamp > 0.1) {
|
19465 | var measurementName = displayName + ' [' + markType + ']';
|
19466 | performance.measure(measurementName, markName);
|
19467 | }
|
19468 |
|
19469 | performance.clearMarks(markName);
|
19470 | performance.clearMeasures(measurementName);
|
19471 | }
|
19472 |
|
19473 | var ReactDebugTool = {
|
19474 | addHook: function (hook) {
|
19475 | hooks.push(hook);
|
19476 | },
|
19477 | removeHook: function (hook) {
|
19478 | for (var i = 0; i < hooks.length; i++) {
|
19479 | if (hooks[i] === hook) {
|
19480 | hooks.splice(i, 1);
|
19481 | i--;
|
19482 | }
|
19483 | }
|
19484 | },
|
19485 | isProfiling: function () {
|
19486 | return isProfiling;
|
19487 | },
|
19488 | beginProfiling: function () {
|
19489 | if (isProfiling) {
|
19490 | return;
|
19491 | }
|
19492 |
|
19493 | isProfiling = true;
|
19494 | flushHistory.length = 0;
|
19495 | resetMeasurements();
|
19496 | ReactDebugTool.addHook(ReactHostOperationHistoryHook);
|
19497 | },
|
19498 | endProfiling: function () {
|
19499 | if (!isProfiling) {
|
19500 | return;
|
19501 | }
|
19502 |
|
19503 | isProfiling = false;
|
19504 | resetMeasurements();
|
19505 | ReactDebugTool.removeHook(ReactHostOperationHistoryHook);
|
19506 | },
|
19507 | getFlushHistory: function () {
|
19508 | return flushHistory;
|
19509 | },
|
19510 | onBeginFlush: function () {
|
19511 | currentFlushNesting++;
|
19512 | resetMeasurements();
|
19513 | pauseCurrentLifeCycleTimer();
|
19514 | emitEvent('onBeginFlush');
|
19515 | },
|
19516 | onEndFlush: function () {
|
19517 | resetMeasurements();
|
19518 | currentFlushNesting--;
|
19519 | resumeCurrentLifeCycleTimer();
|
19520 | emitEvent('onEndFlush');
|
19521 | },
|
19522 | onBeginLifeCycleTimer: function (debugID, timerType) {
|
19523 | checkDebugID(debugID);
|
19524 | emitEvent('onBeginLifeCycleTimer', debugID, timerType);
|
19525 | markBegin(debugID, timerType);
|
19526 | beginLifeCycleTimer(debugID, timerType);
|
19527 | },
|
19528 | onEndLifeCycleTimer: function (debugID, timerType) {
|
19529 | checkDebugID(debugID);
|
19530 | endLifeCycleTimer(debugID, timerType);
|
19531 | markEnd(debugID, timerType);
|
19532 | emitEvent('onEndLifeCycleTimer', debugID, timerType);
|
19533 | },
|
19534 | onBeginProcessingChildContext: function () {
|
19535 | emitEvent('onBeginProcessingChildContext');
|
19536 | },
|
19537 | onEndProcessingChildContext: function () {
|
19538 | emitEvent('onEndProcessingChildContext');
|
19539 | },
|
19540 | onHostOperation: function (operation) {
|
19541 | checkDebugID(operation.instanceID);
|
19542 | emitEvent('onHostOperation', operation);
|
19543 | },
|
19544 | onSetState: function () {
|
19545 | emitEvent('onSetState');
|
19546 | },
|
19547 | onSetChildren: function (debugID, childDebugIDs) {
|
19548 | checkDebugID(debugID);
|
19549 | childDebugIDs.forEach(checkDebugID);
|
19550 | emitEvent('onSetChildren', debugID, childDebugIDs);
|
19551 | },
|
19552 | onBeforeMountComponent: function (debugID, element, parentDebugID) {
|
19553 | checkDebugID(debugID);
|
19554 | checkDebugID(parentDebugID, true);
|
19555 | emitEvent('onBeforeMountComponent', debugID, element, parentDebugID);
|
19556 | markBegin(debugID, 'mount');
|
19557 | },
|
19558 | onMountComponent: function (debugID) {
|
19559 | checkDebugID(debugID);
|
19560 | markEnd(debugID, 'mount');
|
19561 | emitEvent('onMountComponent', debugID);
|
19562 | },
|
19563 | onBeforeUpdateComponent: function (debugID, element) {
|
19564 | checkDebugID(debugID);
|
19565 | emitEvent('onBeforeUpdateComponent', debugID, element);
|
19566 | markBegin(debugID, 'update');
|
19567 | },
|
19568 | onUpdateComponent: function (debugID) {
|
19569 | checkDebugID(debugID);
|
19570 | markEnd(debugID, 'update');
|
19571 | emitEvent('onUpdateComponent', debugID);
|
19572 | },
|
19573 | onBeforeUnmountComponent: function (debugID) {
|
19574 | checkDebugID(debugID);
|
19575 | emitEvent('onBeforeUnmountComponent', debugID);
|
19576 | markBegin(debugID, 'unmount');
|
19577 | },
|
19578 | onUnmountComponent: function (debugID) {
|
19579 | checkDebugID(debugID);
|
19580 | markEnd(debugID, 'unmount');
|
19581 | emitEvent('onUnmountComponent', debugID);
|
19582 | },
|
19583 | onTestEvent: function () {
|
19584 | emitEvent('onTestEvent');
|
19585 | }
|
19586 | };
|
19587 |
|
19588 | // TODO remove these when RN/www gets updated
|
19589 | ReactDebugTool.addDevtool = ReactDebugTool.addHook;
|
19590 | ReactDebugTool.removeDevtool = ReactDebugTool.removeHook;
|
19591 |
|
19592 | ReactDebugTool.addHook(ReactInvalidSetStateWarningHook);
|
19593 | ReactDebugTool.addHook(ReactComponentTreeHook);
|
19594 | var url = ExecutionEnvironment.canUseDOM && window.location.href || '';
|
19595 | if (/[?&]react_perf\b/.test(url)) {
|
19596 | ReactDebugTool.beginProfiling();
|
19597 | }
|
19598 |
|
19599 | module.exports = ReactDebugTool;
|
19600 | }).call(this,require('_process'))
|
19601 | },{"./ReactHostOperationHistoryHook":212,"./ReactInvalidSetStateWarningHook":217,"_process":144,"fbjs/lib/ExecutionEnvironment":110,"fbjs/lib/performanceNow":129,"fbjs/lib/warning":131,"react/lib/ReactComponentTreeHook":291}],203:[function(require,module,exports){
|
19602 | /**
|
19603 | * Copyright 2013-present, Facebook, Inc.
|
19604 | * All rights reserved.
|
19605 | *
|
19606 | * This source code is licensed under the BSD-style license found in the
|
19607 | * LICENSE file in the root directory of this source tree. An additional grant
|
19608 | * of patent rights can be found in the PATENTS file in the same directory.
|
19609 | *
|
19610 | */
|
19611 |
|
19612 | 'use strict';
|
19613 |
|
19614 | var _assign = require('object-assign');
|
19615 |
|
19616 | var ReactUpdates = require('./ReactUpdates');
|
19617 | var Transaction = require('./Transaction');
|
19618 |
|
19619 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
19620 |
|
19621 | var RESET_BATCHED_UPDATES = {
|
19622 | initialize: emptyFunction,
|
19623 | close: function () {
|
19624 | ReactDefaultBatchingStrategy.isBatchingUpdates = false;
|
19625 | }
|
19626 | };
|
19627 |
|
19628 | var FLUSH_BATCHED_UPDATES = {
|
19629 | initialize: emptyFunction,
|
19630 | close: ReactUpdates.flushBatchedUpdates.bind(ReactUpdates)
|
19631 | };
|
19632 |
|
19633 | var TRANSACTION_WRAPPERS = [FLUSH_BATCHED_UPDATES, RESET_BATCHED_UPDATES];
|
19634 |
|
19635 | function ReactDefaultBatchingStrategyTransaction() {
|
19636 | this.reinitializeTransaction();
|
19637 | }
|
19638 |
|
19639 | _assign(ReactDefaultBatchingStrategyTransaction.prototype, Transaction, {
|
19640 | getTransactionWrappers: function () {
|
19641 | return TRANSACTION_WRAPPERS;
|
19642 | }
|
19643 | });
|
19644 |
|
19645 | var transaction = new ReactDefaultBatchingStrategyTransaction();
|
19646 |
|
19647 | var ReactDefaultBatchingStrategy = {
|
19648 | isBatchingUpdates: false,
|
19649 |
|
19650 | /**
|
19651 | * Call the provided function in a context within which calls to `setState`
|
19652 | * and friends are batched such that components aren't updated unnecessarily.
|
19653 | */
|
19654 | batchedUpdates: function (callback, a, b, c, d, e) {
|
19655 | var alreadyBatchingUpdates = ReactDefaultBatchingStrategy.isBatchingUpdates;
|
19656 |
|
19657 | ReactDefaultBatchingStrategy.isBatchingUpdates = true;
|
19658 |
|
19659 | // The code is written this way to avoid extra allocations
|
19660 | if (alreadyBatchingUpdates) {
|
19661 | return callback(a, b, c, d, e);
|
19662 | } else {
|
19663 | return transaction.perform(callback, null, a, b, c, d, e);
|
19664 | }
|
19665 | }
|
19666 | };
|
19667 |
|
19668 | module.exports = ReactDefaultBatchingStrategy;
|
19669 | },{"./ReactUpdates":233,"./Transaction":251,"fbjs/lib/emptyFunction":116,"object-assign":143}],204:[function(require,module,exports){
|
19670 | /**
|
19671 | * Copyright 2013-present, Facebook, Inc.
|
19672 | * All rights reserved.
|
19673 | *
|
19674 | * This source code is licensed under the BSD-style license found in the
|
19675 | * LICENSE file in the root directory of this source tree. An additional grant
|
19676 | * of patent rights can be found in the PATENTS file in the same directory.
|
19677 | *
|
19678 | */
|
19679 |
|
19680 | 'use strict';
|
19681 |
|
19682 | var ARIADOMPropertyConfig = require('./ARIADOMPropertyConfig');
|
19683 | var BeforeInputEventPlugin = require('./BeforeInputEventPlugin');
|
19684 | var ChangeEventPlugin = require('./ChangeEventPlugin');
|
19685 | var DefaultEventPluginOrder = require('./DefaultEventPluginOrder');
|
19686 | var EnterLeaveEventPlugin = require('./EnterLeaveEventPlugin');
|
19687 | var HTMLDOMPropertyConfig = require('./HTMLDOMPropertyConfig');
|
19688 | var ReactComponentBrowserEnvironment = require('./ReactComponentBrowserEnvironment');
|
19689 | var ReactDOMComponent = require('./ReactDOMComponent');
|
19690 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
19691 | var ReactDOMEmptyComponent = require('./ReactDOMEmptyComponent');
|
19692 | var ReactDOMTreeTraversal = require('./ReactDOMTreeTraversal');
|
19693 | var ReactDOMTextComponent = require('./ReactDOMTextComponent');
|
19694 | var ReactDefaultBatchingStrategy = require('./ReactDefaultBatchingStrategy');
|
19695 | var ReactEventListener = require('./ReactEventListener');
|
19696 | var ReactInjection = require('./ReactInjection');
|
19697 | var ReactReconcileTransaction = require('./ReactReconcileTransaction');
|
19698 | var SVGDOMPropertyConfig = require('./SVGDOMPropertyConfig');
|
19699 | var SelectEventPlugin = require('./SelectEventPlugin');
|
19700 | var SimpleEventPlugin = require('./SimpleEventPlugin');
|
19701 |
|
19702 | var alreadyInjected = false;
|
19703 |
|
19704 | function inject() {
|
19705 | if (alreadyInjected) {
|
19706 | // TODO: This is currently true because these injections are shared between
|
19707 | // the client and the server package. They should be built independently
|
19708 | // and not share any injection state. Then this problem will be solved.
|
19709 | return;
|
19710 | }
|
19711 | alreadyInjected = true;
|
19712 |
|
19713 | ReactInjection.EventEmitter.injectReactEventListener(ReactEventListener);
|
19714 |
|
19715 | /**
|
19716 | * Inject modules for resolving DOM hierarchy and plugin ordering.
|
19717 | */
|
19718 | ReactInjection.EventPluginHub.injectEventPluginOrder(DefaultEventPluginOrder);
|
19719 | ReactInjection.EventPluginUtils.injectComponentTree(ReactDOMComponentTree);
|
19720 | ReactInjection.EventPluginUtils.injectTreeTraversal(ReactDOMTreeTraversal);
|
19721 |
|
19722 | /**
|
19723 | * Some important event plugins included by default (without having to require
|
19724 | * them).
|
19725 | */
|
19726 | ReactInjection.EventPluginHub.injectEventPluginsByName({
|
19727 | SimpleEventPlugin: SimpleEventPlugin,
|
19728 | EnterLeaveEventPlugin: EnterLeaveEventPlugin,
|
19729 | ChangeEventPlugin: ChangeEventPlugin,
|
19730 | SelectEventPlugin: SelectEventPlugin,
|
19731 | BeforeInputEventPlugin: BeforeInputEventPlugin
|
19732 | });
|
19733 |
|
19734 | ReactInjection.HostComponent.injectGenericComponentClass(ReactDOMComponent);
|
19735 |
|
19736 | ReactInjection.HostComponent.injectTextComponentClass(ReactDOMTextComponent);
|
19737 |
|
19738 | ReactInjection.DOMProperty.injectDOMPropertyConfig(ARIADOMPropertyConfig);
|
19739 | ReactInjection.DOMProperty.injectDOMPropertyConfig(HTMLDOMPropertyConfig);
|
19740 | ReactInjection.DOMProperty.injectDOMPropertyConfig(SVGDOMPropertyConfig);
|
19741 |
|
19742 | ReactInjection.EmptyComponent.injectEmptyComponentFactory(function (instantiate) {
|
19743 | return new ReactDOMEmptyComponent(instantiate);
|
19744 | });
|
19745 |
|
19746 | ReactInjection.Updates.injectReconcileTransaction(ReactReconcileTransaction);
|
19747 | ReactInjection.Updates.injectBatchingStrategy(ReactDefaultBatchingStrategy);
|
19748 |
|
19749 | ReactInjection.Component.injectEnvironment(ReactComponentBrowserEnvironment);
|
19750 | }
|
19751 |
|
19752 | module.exports = {
|
19753 | inject: inject
|
19754 | };
|
19755 | },{"./ARIADOMPropertyConfig":154,"./BeforeInputEventPlugin":156,"./ChangeEventPlugin":160,"./DefaultEventPluginOrder":167,"./EnterLeaveEventPlugin":168,"./HTMLDOMPropertyConfig":174,"./ReactComponentBrowserEnvironment":180,"./ReactDOMComponent":184,"./ReactDOMComponentTree":186,"./ReactDOMEmptyComponent":188,"./ReactDOMTextComponent":198,"./ReactDOMTreeTraversal":200,"./ReactDefaultBatchingStrategy":203,"./ReactEventListener":209,"./ReactInjection":213,"./ReactReconcileTransaction":225,"./SVGDOMPropertyConfig":235,"./SelectEventPlugin":236,"./SimpleEventPlugin":237}],205:[function(require,module,exports){
|
19756 | /**
|
19757 | * Copyright 2014-present, Facebook, Inc.
|
19758 | * All rights reserved.
|
19759 | *
|
19760 | * This source code is licensed under the BSD-style license found in the
|
19761 | * LICENSE file in the root directory of this source tree. An additional grant
|
19762 | * of patent rights can be found in the PATENTS file in the same directory.
|
19763 | *
|
19764 | *
|
19765 | */
|
19766 |
|
19767 | 'use strict';
|
19768 |
|
19769 | // The Symbol used to tag the ReactElement type. If there is no native Symbol
|
19770 | // nor polyfill, then a plain number is used for performance.
|
19771 |
|
19772 | var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol['for'] && Symbol['for']('react.element') || 0xeac7;
|
19773 |
|
19774 | module.exports = REACT_ELEMENT_TYPE;
|
19775 | },{}],206:[function(require,module,exports){
|
19776 | /**
|
19777 | * Copyright 2014-present, Facebook, Inc.
|
19778 | * All rights reserved.
|
19779 | *
|
19780 | * This source code is licensed under the BSD-style license found in the
|
19781 | * LICENSE file in the root directory of this source tree. An additional grant
|
19782 | * of patent rights can be found in the PATENTS file in the same directory.
|
19783 | *
|
19784 | */
|
19785 |
|
19786 | 'use strict';
|
19787 |
|
19788 | var emptyComponentFactory;
|
19789 |
|
19790 | var ReactEmptyComponentInjection = {
|
19791 | injectEmptyComponentFactory: function (factory) {
|
19792 | emptyComponentFactory = factory;
|
19793 | }
|
19794 | };
|
19795 |
|
19796 | var ReactEmptyComponent = {
|
19797 | create: function (instantiate) {
|
19798 | return emptyComponentFactory(instantiate);
|
19799 | }
|
19800 | };
|
19801 |
|
19802 | ReactEmptyComponent.injection = ReactEmptyComponentInjection;
|
19803 |
|
19804 | module.exports = ReactEmptyComponent;
|
19805 | },{}],207:[function(require,module,exports){
|
19806 | (function (process){
|
19807 | /**
|
19808 | * Copyright 2013-present, Facebook, Inc.
|
19809 | * All rights reserved.
|
19810 | *
|
19811 | * This source code is licensed under the BSD-style license found in the
|
19812 | * LICENSE file in the root directory of this source tree. An additional grant
|
19813 | * of patent rights can be found in the PATENTS file in the same directory.
|
19814 | *
|
19815 | *
|
19816 | */
|
19817 |
|
19818 | 'use strict';
|
19819 |
|
19820 | var caughtError = null;
|
19821 |
|
19822 | /**
|
19823 | * Call a function while guarding against errors that happens within it.
|
19824 | *
|
19825 | * @param {String} name of the guard to use for logging or debugging
|
19826 | * @param {Function} func The function to invoke
|
19827 | * @param {*} a First argument
|
19828 | * @param {*} b Second argument
|
19829 | */
|
19830 | function invokeGuardedCallback(name, func, a) {
|
19831 | try {
|
19832 | func(a);
|
19833 | } catch (x) {
|
19834 | if (caughtError === null) {
|
19835 | caughtError = x;
|
19836 | }
|
19837 | }
|
19838 | }
|
19839 |
|
19840 | var ReactErrorUtils = {
|
19841 | invokeGuardedCallback: invokeGuardedCallback,
|
19842 |
|
19843 | /**
|
19844 | * Invoked by ReactTestUtils.Simulate so that any errors thrown by the event
|
19845 | * handler are sure to be rethrown by rethrowCaughtError.
|
19846 | */
|
19847 | invokeGuardedCallbackWithCatch: invokeGuardedCallback,
|
19848 |
|
19849 | /**
|
19850 | * During execution of guarded functions we will capture the first error which
|
19851 | * we will rethrow to be handled by the top level error handler.
|
19852 | */
|
19853 | rethrowCaughtError: function () {
|
19854 | if (caughtError) {
|
19855 | var error = caughtError;
|
19856 | caughtError = null;
|
19857 | throw error;
|
19858 | }
|
19859 | }
|
19860 | };
|
19861 |
|
19862 | if (process.env.NODE_ENV !== 'production') {
|
19863 | /**
|
19864 | * To help development we can get better devtools integration by simulating a
|
19865 | * real browser event.
|
19866 | */
|
19867 | if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
|
19868 | var fakeNode = document.createElement('react');
|
19869 | ReactErrorUtils.invokeGuardedCallback = function (name, func, a) {
|
19870 | var boundFunc = func.bind(null, a);
|
19871 | var evtType = 'react-' + name;
|
19872 | fakeNode.addEventListener(evtType, boundFunc, false);
|
19873 | var evt = document.createEvent('Event');
|
19874 | // $FlowFixMe https://github.com/facebook/flow/issues/2336
|
19875 | evt.initEvent(evtType, false, false);
|
19876 | fakeNode.dispatchEvent(evt);
|
19877 | fakeNode.removeEventListener(evtType, boundFunc, false);
|
19878 | };
|
19879 | }
|
19880 | }
|
19881 |
|
19882 | module.exports = ReactErrorUtils;
|
19883 | }).call(this,require('_process'))
|
19884 | },{"_process":144}],208:[function(require,module,exports){
|
19885 | /**
|
19886 | * Copyright 2013-present, Facebook, Inc.
|
19887 | * All rights reserved.
|
19888 | *
|
19889 | * This source code is licensed under the BSD-style license found in the
|
19890 | * LICENSE file in the root directory of this source tree. An additional grant
|
19891 | * of patent rights can be found in the PATENTS file in the same directory.
|
19892 | *
|
19893 | */
|
19894 |
|
19895 | 'use strict';
|
19896 |
|
19897 | var EventPluginHub = require('./EventPluginHub');
|
19898 |
|
19899 | function runEventQueueInBatch(events) {
|
19900 | EventPluginHub.enqueueEvents(events);
|
19901 | EventPluginHub.processEventQueue(false);
|
19902 | }
|
19903 |
|
19904 | var ReactEventEmitterMixin = {
|
19905 |
|
19906 | /**
|
19907 | * Streams a fired top-level event to `EventPluginHub` where plugins have the
|
19908 | * opportunity to create `ReactEvent`s to be dispatched.
|
19909 | */
|
19910 | handleTopLevel: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
|
19911 | var events = EventPluginHub.extractEvents(topLevelType, targetInst, nativeEvent, nativeEventTarget);
|
19912 | runEventQueueInBatch(events);
|
19913 | }
|
19914 | };
|
19915 |
|
19916 | module.exports = ReactEventEmitterMixin;
|
19917 | },{"./EventPluginHub":169}],209:[function(require,module,exports){
|
19918 | /**
|
19919 | * Copyright 2013-present, Facebook, Inc.
|
19920 | * All rights reserved.
|
19921 | *
|
19922 | * This source code is licensed under the BSD-style license found in the
|
19923 | * LICENSE file in the root directory of this source tree. An additional grant
|
19924 | * of patent rights can be found in the PATENTS file in the same directory.
|
19925 | *
|
19926 | */
|
19927 |
|
19928 | 'use strict';
|
19929 |
|
19930 | var _assign = require('object-assign');
|
19931 |
|
19932 | var EventListener = require('fbjs/lib/EventListener');
|
19933 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
19934 | var PooledClass = require('./PooledClass');
|
19935 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
19936 | var ReactUpdates = require('./ReactUpdates');
|
19937 |
|
19938 | var getEventTarget = require('./getEventTarget');
|
19939 | var getUnboundedScrollPosition = require('fbjs/lib/getUnboundedScrollPosition');
|
19940 |
|
19941 | /**
|
19942 | * Find the deepest React component completely containing the root of the
|
19943 | * passed-in instance (for use when entire React trees are nested within each
|
19944 | * other). If React trees are not nested, returns null.
|
19945 | */
|
19946 | function findParent(inst) {
|
19947 | // TODO: It may be a good idea to cache this to prevent unnecessary DOM
|
19948 | // traversal, but caching is difficult to do correctly without using a
|
19949 | // mutation observer to listen for all DOM changes.
|
19950 | while (inst._hostParent) {
|
19951 | inst = inst._hostParent;
|
19952 | }
|
19953 | var rootNode = ReactDOMComponentTree.getNodeFromInstance(inst);
|
19954 | var container = rootNode.parentNode;
|
19955 | return ReactDOMComponentTree.getClosestInstanceFromNode(container);
|
19956 | }
|
19957 |
|
19958 | // Used to store ancestor hierarchy in top level callback
|
19959 | function TopLevelCallbackBookKeeping(topLevelType, nativeEvent) {
|
19960 | this.topLevelType = topLevelType;
|
19961 | this.nativeEvent = nativeEvent;
|
19962 | this.ancestors = [];
|
19963 | }
|
19964 | _assign(TopLevelCallbackBookKeeping.prototype, {
|
19965 | destructor: function () {
|
19966 | this.topLevelType = null;
|
19967 | this.nativeEvent = null;
|
19968 | this.ancestors.length = 0;
|
19969 | }
|
19970 | });
|
19971 | PooledClass.addPoolingTo(TopLevelCallbackBookKeeping, PooledClass.twoArgumentPooler);
|
19972 |
|
19973 | function handleTopLevelImpl(bookKeeping) {
|
19974 | var nativeEventTarget = getEventTarget(bookKeeping.nativeEvent);
|
19975 | var targetInst = ReactDOMComponentTree.getClosestInstanceFromNode(nativeEventTarget);
|
19976 |
|
19977 | // Loop through the hierarchy, in case there's any nested components.
|
19978 | // It's important that we build the array of ancestors before calling any
|
19979 | // event handlers, because event handlers can modify the DOM, leading to
|
19980 | // inconsistencies with ReactMount's node cache. See #1105.
|
19981 | var ancestor = targetInst;
|
19982 | do {
|
19983 | bookKeeping.ancestors.push(ancestor);
|
19984 | ancestor = ancestor && findParent(ancestor);
|
19985 | } while (ancestor);
|
19986 |
|
19987 | for (var i = 0; i < bookKeeping.ancestors.length; i++) {
|
19988 | targetInst = bookKeeping.ancestors[i];
|
19989 | ReactEventListener._handleTopLevel(bookKeeping.topLevelType, targetInst, bookKeeping.nativeEvent, getEventTarget(bookKeeping.nativeEvent));
|
19990 | }
|
19991 | }
|
19992 |
|
19993 | function scrollValueMonitor(cb) {
|
19994 | var scrollPosition = getUnboundedScrollPosition(window);
|
19995 | cb(scrollPosition);
|
19996 | }
|
19997 |
|
19998 | var ReactEventListener = {
|
19999 | _enabled: true,
|
20000 | _handleTopLevel: null,
|
20001 |
|
20002 | WINDOW_HANDLE: ExecutionEnvironment.canUseDOM ? window : null,
|
20003 |
|
20004 | setHandleTopLevel: function (handleTopLevel) {
|
20005 | ReactEventListener._handleTopLevel = handleTopLevel;
|
20006 | },
|
20007 |
|
20008 | setEnabled: function (enabled) {
|
20009 | ReactEventListener._enabled = !!enabled;
|
20010 | },
|
20011 |
|
20012 | isEnabled: function () {
|
20013 | return ReactEventListener._enabled;
|
20014 | },
|
20015 |
|
20016 | /**
|
20017 | * Traps top-level events by using event bubbling.
|
20018 | *
|
20019 | * @param {string} topLevelType Record from `EventConstants`.
|
20020 | * @param {string} handlerBaseName Event name (e.g. "click").
|
20021 | * @param {object} element Element on which to attach listener.
|
20022 | * @return {?object} An object with a remove function which will forcefully
|
20023 | * remove the listener.
|
20024 | * @internal
|
20025 | */
|
20026 | trapBubbledEvent: function (topLevelType, handlerBaseName, element) {
|
20027 | if (!element) {
|
20028 | return null;
|
20029 | }
|
20030 | return EventListener.listen(element, handlerBaseName, ReactEventListener.dispatchEvent.bind(null, topLevelType));
|
20031 | },
|
20032 |
|
20033 | /**
|
20034 | * Traps a top-level event by using event capturing.
|
20035 | *
|
20036 | * @param {string} topLevelType Record from `EventConstants`.
|
20037 | * @param {string} handlerBaseName Event name (e.g. "click").
|
20038 | * @param {object} element Element on which to attach listener.
|
20039 | * @return {?object} An object with a remove function which will forcefully
|
20040 | * remove the listener.
|
20041 | * @internal
|
20042 | */
|
20043 | trapCapturedEvent: function (topLevelType, handlerBaseName, element) {
|
20044 | if (!element) {
|
20045 | return null;
|
20046 | }
|
20047 | return EventListener.capture(element, handlerBaseName, ReactEventListener.dispatchEvent.bind(null, topLevelType));
|
20048 | },
|
20049 |
|
20050 | monitorScrollValue: function (refresh) {
|
20051 | var callback = scrollValueMonitor.bind(null, refresh);
|
20052 | EventListener.listen(window, 'scroll', callback);
|
20053 | },
|
20054 |
|
20055 | dispatchEvent: function (topLevelType, nativeEvent) {
|
20056 | if (!ReactEventListener._enabled) {
|
20057 | return;
|
20058 | }
|
20059 |
|
20060 | var bookKeeping = TopLevelCallbackBookKeeping.getPooled(topLevelType, nativeEvent);
|
20061 | try {
|
20062 | // Event queue being processed in the same cycle allows
|
20063 | // `preventDefault`.
|
20064 | ReactUpdates.batchedUpdates(handleTopLevelImpl, bookKeeping);
|
20065 | } finally {
|
20066 | TopLevelCallbackBookKeeping.release(bookKeeping);
|
20067 | }
|
20068 | }
|
20069 | };
|
20070 |
|
20071 | module.exports = ReactEventListener;
|
20072 | },{"./PooledClass":177,"./ReactDOMComponentTree":186,"./ReactUpdates":233,"./getEventTarget":265,"fbjs/lib/EventListener":109,"fbjs/lib/ExecutionEnvironment":110,"fbjs/lib/getUnboundedScrollPosition":121,"object-assign":143}],210:[function(require,module,exports){
|
20073 | /**
|
20074 | * Copyright 2013-present, Facebook, Inc.
|
20075 | * All rights reserved.
|
20076 | *
|
20077 | * This source code is licensed under the BSD-style license found in the
|
20078 | * LICENSE file in the root directory of this source tree. An additional grant
|
20079 | * of patent rights can be found in the PATENTS file in the same directory.
|
20080 | *
|
20081 | *
|
20082 | */
|
20083 |
|
20084 | 'use strict';
|
20085 |
|
20086 | var ReactFeatureFlags = {
|
20087 | // When true, call console.time() before and .timeEnd() after each top-level
|
20088 | // render (both initial renders and updates). Useful when looking at prod-mode
|
20089 | // timeline profiles in Chrome, for example.
|
20090 | logTopLevelRenders: false
|
20091 | };
|
20092 |
|
20093 | module.exports = ReactFeatureFlags;
|
20094 | },{}],211:[function(require,module,exports){
|
20095 | (function (process){
|
20096 | /**
|
20097 | * Copyright 2014-present, Facebook, Inc.
|
20098 | * All rights reserved.
|
20099 | *
|
20100 | * This source code is licensed under the BSD-style license found in the
|
20101 | * LICENSE file in the root directory of this source tree. An additional grant
|
20102 | * of patent rights can be found in the PATENTS file in the same directory.
|
20103 | *
|
20104 | */
|
20105 |
|
20106 | 'use strict';
|
20107 |
|
20108 | var _prodInvariant = require('./reactProdInvariant'),
|
20109 | _assign = require('object-assign');
|
20110 |
|
20111 | var invariant = require('fbjs/lib/invariant');
|
20112 |
|
20113 | var genericComponentClass = null;
|
20114 | // This registry keeps track of wrapper classes around host tags.
|
20115 | var tagToComponentClass = {};
|
20116 | var textComponentClass = null;
|
20117 |
|
20118 | var ReactHostComponentInjection = {
|
20119 | // This accepts a class that receives the tag string. This is a catch all
|
20120 | // that can render any kind of tag.
|
20121 | injectGenericComponentClass: function (componentClass) {
|
20122 | genericComponentClass = componentClass;
|
20123 | },
|
20124 | // This accepts a text component class that takes the text string to be
|
20125 | // rendered as props.
|
20126 | injectTextComponentClass: function (componentClass) {
|
20127 | textComponentClass = componentClass;
|
20128 | },
|
20129 | // This accepts a keyed object with classes as values. Each key represents a
|
20130 | // tag. That particular tag will use this class instead of the generic one.
|
20131 | injectComponentClasses: function (componentClasses) {
|
20132 | _assign(tagToComponentClass, componentClasses);
|
20133 | }
|
20134 | };
|
20135 |
|
20136 | /**
|
20137 | * Get a host internal component class for a specific tag.
|
20138 | *
|
20139 | * @param {ReactElement} element The element to create.
|
20140 | * @return {function} The internal class constructor function.
|
20141 | */
|
20142 | function createInternalComponent(element) {
|
20143 | !genericComponentClass ? process.env.NODE_ENV !== 'production' ? invariant(false, 'There is no registered component for the tag %s', element.type) : _prodInvariant('111', element.type) : void 0;
|
20144 | return new genericComponentClass(element);
|
20145 | }
|
20146 |
|
20147 | /**
|
20148 | * @param {ReactText} text
|
20149 | * @return {ReactComponent}
|
20150 | */
|
20151 | function createInstanceForText(text) {
|
20152 | return new textComponentClass(text);
|
20153 | }
|
20154 |
|
20155 | /**
|
20156 | * @param {ReactComponent} component
|
20157 | * @return {boolean}
|
20158 | */
|
20159 | function isTextComponent(component) {
|
20160 | return component instanceof textComponentClass;
|
20161 | }
|
20162 |
|
20163 | var ReactHostComponent = {
|
20164 | createInternalComponent: createInternalComponent,
|
20165 | createInstanceForText: createInstanceForText,
|
20166 | isTextComponent: isTextComponent,
|
20167 | injection: ReactHostComponentInjection
|
20168 | };
|
20169 |
|
20170 | module.exports = ReactHostComponent;
|
20171 | }).call(this,require('_process'))
|
20172 | },{"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"object-assign":143}],212:[function(require,module,exports){
|
20173 | /**
|
20174 | * Copyright 2016-present, Facebook, Inc.
|
20175 | * All rights reserved.
|
20176 | *
|
20177 | * This source code is licensed under the BSD-style license found in the
|
20178 | * LICENSE file in the root directory of this source tree. An additional grant
|
20179 | * of patent rights can be found in the PATENTS file in the same directory.
|
20180 | *
|
20181 | *
|
20182 | */
|
20183 |
|
20184 | 'use strict';
|
20185 |
|
20186 | var history = [];
|
20187 |
|
20188 | var ReactHostOperationHistoryHook = {
|
20189 | onHostOperation: function (operation) {
|
20190 | history.push(operation);
|
20191 | },
|
20192 | clearHistory: function () {
|
20193 | if (ReactHostOperationHistoryHook._preventClearing) {
|
20194 | // Should only be used for tests.
|
20195 | return;
|
20196 | }
|
20197 |
|
20198 | history = [];
|
20199 | },
|
20200 | getHistory: function () {
|
20201 | return history;
|
20202 | }
|
20203 | };
|
20204 |
|
20205 | module.exports = ReactHostOperationHistoryHook;
|
20206 | },{}],213:[function(require,module,exports){
|
20207 | /**
|
20208 | * Copyright 2013-present, Facebook, Inc.
|
20209 | * All rights reserved.
|
20210 | *
|
20211 | * This source code is licensed under the BSD-style license found in the
|
20212 | * LICENSE file in the root directory of this source tree. An additional grant
|
20213 | * of patent rights can be found in the PATENTS file in the same directory.
|
20214 | *
|
20215 | */
|
20216 |
|
20217 | 'use strict';
|
20218 |
|
20219 | var DOMProperty = require('./DOMProperty');
|
20220 | var EventPluginHub = require('./EventPluginHub');
|
20221 | var EventPluginUtils = require('./EventPluginUtils');
|
20222 | var ReactComponentEnvironment = require('./ReactComponentEnvironment');
|
20223 | var ReactEmptyComponent = require('./ReactEmptyComponent');
|
20224 | var ReactBrowserEventEmitter = require('./ReactBrowserEventEmitter');
|
20225 | var ReactHostComponent = require('./ReactHostComponent');
|
20226 | var ReactUpdates = require('./ReactUpdates');
|
20227 |
|
20228 | var ReactInjection = {
|
20229 | Component: ReactComponentEnvironment.injection,
|
20230 | DOMProperty: DOMProperty.injection,
|
20231 | EmptyComponent: ReactEmptyComponent.injection,
|
20232 | EventPluginHub: EventPluginHub.injection,
|
20233 | EventPluginUtils: EventPluginUtils.injection,
|
20234 | EventEmitter: ReactBrowserEventEmitter.injection,
|
20235 | HostComponent: ReactHostComponent.injection,
|
20236 | Updates: ReactUpdates.injection
|
20237 | };
|
20238 |
|
20239 | module.exports = ReactInjection;
|
20240 | },{"./DOMProperty":164,"./EventPluginHub":169,"./EventPluginUtils":171,"./ReactBrowserEventEmitter":178,"./ReactComponentEnvironment":181,"./ReactEmptyComponent":206,"./ReactHostComponent":211,"./ReactUpdates":233}],214:[function(require,module,exports){
|
20241 | /**
|
20242 | * Copyright 2013-present, Facebook, Inc.
|
20243 | * All rights reserved.
|
20244 | *
|
20245 | * This source code is licensed under the BSD-style license found in the
|
20246 | * LICENSE file in the root directory of this source tree. An additional grant
|
20247 | * of patent rights can be found in the PATENTS file in the same directory.
|
20248 | *
|
20249 | */
|
20250 |
|
20251 | 'use strict';
|
20252 |
|
20253 | var ReactDOMSelection = require('./ReactDOMSelection');
|
20254 |
|
20255 | var containsNode = require('fbjs/lib/containsNode');
|
20256 | var focusNode = require('fbjs/lib/focusNode');
|
20257 | var getActiveElement = require('fbjs/lib/getActiveElement');
|
20258 |
|
20259 | function isInDocument(node) {
|
20260 | return containsNode(document.documentElement, node);
|
20261 | }
|
20262 |
|
20263 | /**
|
20264 | * @ReactInputSelection: React input selection module. Based on Selection.js,
|
20265 | * but modified to be suitable for react and has a couple of bug fixes (doesn't
|
20266 | * assume buttons have range selections allowed).
|
20267 | * Input selection module for React.
|
20268 | */
|
20269 | var ReactInputSelection = {
|
20270 |
|
20271 | hasSelectionCapabilities: function (elem) {
|
20272 | var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
|
20273 | return nodeName && (nodeName === 'input' && elem.type === 'text' || nodeName === 'textarea' || elem.contentEditable === 'true');
|
20274 | },
|
20275 |
|
20276 | getSelectionInformation: function () {
|
20277 | var focusedElem = getActiveElement();
|
20278 | return {
|
20279 | focusedElem: focusedElem,
|
20280 | selectionRange: ReactInputSelection.hasSelectionCapabilities(focusedElem) ? ReactInputSelection.getSelection(focusedElem) : null
|
20281 | };
|
20282 | },
|
20283 |
|
20284 | /**
|
20285 | * @restoreSelection: If any selection information was potentially lost,
|
20286 | * restore it. This is useful when performing operations that could remove dom
|
20287 | * nodes and place them back in, resulting in focus being lost.
|
20288 | */
|
20289 | restoreSelection: function (priorSelectionInformation) {
|
20290 | var curFocusedElem = getActiveElement();
|
20291 | var priorFocusedElem = priorSelectionInformation.focusedElem;
|
20292 | var priorSelectionRange = priorSelectionInformation.selectionRange;
|
20293 | if (curFocusedElem !== priorFocusedElem && isInDocument(priorFocusedElem)) {
|
20294 | if (ReactInputSelection.hasSelectionCapabilities(priorFocusedElem)) {
|
20295 | ReactInputSelection.setSelection(priorFocusedElem, priorSelectionRange);
|
20296 | }
|
20297 | focusNode(priorFocusedElem);
|
20298 | }
|
20299 | },
|
20300 |
|
20301 | /**
|
20302 | * @getSelection: Gets the selection bounds of a focused textarea, input or
|
20303 | * contentEditable node.
|
20304 | * -@input: Look up selection bounds of this input
|
20305 | * -@return {start: selectionStart, end: selectionEnd}
|
20306 | */
|
20307 | getSelection: function (input) {
|
20308 | var selection;
|
20309 |
|
20310 | if ('selectionStart' in input) {
|
20311 | // Modern browser with input or textarea.
|
20312 | selection = {
|
20313 | start: input.selectionStart,
|
20314 | end: input.selectionEnd
|
20315 | };
|
20316 | } else if (document.selection && input.nodeName && input.nodeName.toLowerCase() === 'input') {
|
20317 | // IE8 input.
|
20318 | var range = document.selection.createRange();
|
20319 | // There can only be one selection per document in IE, so it must
|
20320 | // be in our element.
|
20321 | if (range.parentElement() === input) {
|
20322 | selection = {
|
20323 | start: -range.moveStart('character', -input.value.length),
|
20324 | end: -range.moveEnd('character', -input.value.length)
|
20325 | };
|
20326 | }
|
20327 | } else {
|
20328 | // Content editable or old IE textarea.
|
20329 | selection = ReactDOMSelection.getOffsets(input);
|
20330 | }
|
20331 |
|
20332 | return selection || { start: 0, end: 0 };
|
20333 | },
|
20334 |
|
20335 | /**
|
20336 | * @setSelection: Sets the selection bounds of a textarea or input and focuses
|
20337 | * the input.
|
20338 | * -@input Set selection bounds of this input or textarea
|
20339 | * -@offsets Object of same form that is returned from get*
|
20340 | */
|
20341 | setSelection: function (input, offsets) {
|
20342 | var start = offsets.start;
|
20343 | var end = offsets.end;
|
20344 | if (end === undefined) {
|
20345 | end = start;
|
20346 | }
|
20347 |
|
20348 | if ('selectionStart' in input) {
|
20349 | input.selectionStart = start;
|
20350 | input.selectionEnd = Math.min(end, input.value.length);
|
20351 | } else if (document.selection && input.nodeName && input.nodeName.toLowerCase() === 'input') {
|
20352 | var range = input.createTextRange();
|
20353 | range.collapse(true);
|
20354 | range.moveStart('character', start);
|
20355 | range.moveEnd('character', end - start);
|
20356 | range.select();
|
20357 | } else {
|
20358 | ReactDOMSelection.setOffsets(input, offsets);
|
20359 | }
|
20360 | }
|
20361 | };
|
20362 |
|
20363 | module.exports = ReactInputSelection;
|
20364 | },{"./ReactDOMSelection":196,"fbjs/lib/containsNode":113,"fbjs/lib/focusNode":118,"fbjs/lib/getActiveElement":119}],215:[function(require,module,exports){
|
20365 | /**
|
20366 | * Copyright 2013-present, Facebook, Inc.
|
20367 | * All rights reserved.
|
20368 | *
|
20369 | * This source code is licensed under the BSD-style license found in the
|
20370 | * LICENSE file in the root directory of this source tree. An additional grant
|
20371 | * of patent rights can be found in the PATENTS file in the same directory.
|
20372 | *
|
20373 | */
|
20374 |
|
20375 | 'use strict';
|
20376 |
|
20377 | /**
|
20378 | * `ReactInstanceMap` maintains a mapping from a public facing stateful
|
20379 | * instance (key) and the internal representation (value). This allows public
|
20380 | * methods to accept the user facing instance as an argument and map them back
|
20381 | * to internal methods.
|
20382 | */
|
20383 |
|
20384 | // TODO: Replace this with ES6: var ReactInstanceMap = new Map();
|
20385 |
|
20386 | var ReactInstanceMap = {
|
20387 |
|
20388 | /**
|
20389 | * This API should be called `delete` but we'd have to make sure to always
|
20390 | * transform these to strings for IE support. When this transform is fully
|
20391 | * supported we can rename it.
|
20392 | */
|
20393 | remove: function (key) {
|
20394 | key._reactInternalInstance = undefined;
|
20395 | },
|
20396 |
|
20397 | get: function (key) {
|
20398 | return key._reactInternalInstance;
|
20399 | },
|
20400 |
|
20401 | has: function (key) {
|
20402 | return key._reactInternalInstance !== undefined;
|
20403 | },
|
20404 |
|
20405 | set: function (key, value) {
|
20406 | key._reactInternalInstance = value;
|
20407 | }
|
20408 |
|
20409 | };
|
20410 |
|
20411 | module.exports = ReactInstanceMap;
|
20412 | },{}],216:[function(require,module,exports){
|
20413 | (function (process){
|
20414 | /**
|
20415 | * Copyright 2016-present, Facebook, Inc.
|
20416 | * All rights reserved.
|
20417 | *
|
20418 | * This source code is licensed under the BSD-style license found in the
|
20419 | * LICENSE file in the root directory of this source tree. An additional grant
|
20420 | * of patent rights can be found in the PATENTS file in the same directory.
|
20421 | *
|
20422 | *
|
20423 | */
|
20424 |
|
20425 | 'use strict';
|
20426 |
|
20427 | // Trust the developer to only use ReactInstrumentation with a __DEV__ check
|
20428 |
|
20429 | var debugTool = null;
|
20430 |
|
20431 | if (process.env.NODE_ENV !== 'production') {
|
20432 | var ReactDebugTool = require('./ReactDebugTool');
|
20433 | debugTool = ReactDebugTool;
|
20434 | }
|
20435 |
|
20436 | module.exports = { debugTool: debugTool };
|
20437 | }).call(this,require('_process'))
|
20438 | },{"./ReactDebugTool":202,"_process":144}],217:[function(require,module,exports){
|
20439 | (function (process){
|
20440 | /**
|
20441 | * Copyright 2016-present, Facebook, Inc.
|
20442 | * All rights reserved.
|
20443 | *
|
20444 | * This source code is licensed under the BSD-style license found in the
|
20445 | * LICENSE file in the root directory of this source tree. An additional grant
|
20446 | * of patent rights can be found in the PATENTS file in the same directory.
|
20447 | *
|
20448 | *
|
20449 | */
|
20450 |
|
20451 | 'use strict';
|
20452 |
|
20453 | var warning = require('fbjs/lib/warning');
|
20454 |
|
20455 | if (process.env.NODE_ENV !== 'production') {
|
20456 | var processingChildContext = false;
|
20457 |
|
20458 | var warnInvalidSetState = function () {
|
20459 | process.env.NODE_ENV !== 'production' ? warning(!processingChildContext, 'setState(...): Cannot call setState() inside getChildContext()') : void 0;
|
20460 | };
|
20461 | }
|
20462 |
|
20463 | var ReactInvalidSetStateWarningHook = {
|
20464 | onBeginProcessingChildContext: function () {
|
20465 | processingChildContext = true;
|
20466 | },
|
20467 | onEndProcessingChildContext: function () {
|
20468 | processingChildContext = false;
|
20469 | },
|
20470 | onSetState: function () {
|
20471 | warnInvalidSetState();
|
20472 | }
|
20473 | };
|
20474 |
|
20475 | module.exports = ReactInvalidSetStateWarningHook;
|
20476 | }).call(this,require('_process'))
|
20477 | },{"_process":144,"fbjs/lib/warning":131}],218:[function(require,module,exports){
|
20478 | /**
|
20479 | * Copyright 2013-present, Facebook, Inc.
|
20480 | * All rights reserved.
|
20481 | *
|
20482 | * This source code is licensed under the BSD-style license found in the
|
20483 | * LICENSE file in the root directory of this source tree. An additional grant
|
20484 | * of patent rights can be found in the PATENTS file in the same directory.
|
20485 | *
|
20486 | */
|
20487 |
|
20488 | 'use strict';
|
20489 |
|
20490 | var adler32 = require('./adler32');
|
20491 |
|
20492 | var TAG_END = /\/?>/;
|
20493 | var COMMENT_START = /^<\!\-\-/;
|
20494 |
|
20495 | var ReactMarkupChecksum = {
|
20496 | CHECKSUM_ATTR_NAME: 'data-react-checksum',
|
20497 |
|
20498 | /**
|
20499 | * @param {string} markup Markup string
|
20500 | * @return {string} Markup string with checksum attribute attached
|
20501 | */
|
20502 | addChecksumToMarkup: function (markup) {
|
20503 | var checksum = adler32(markup);
|
20504 |
|
20505 | // Add checksum (handle both parent tags, comments and self-closing tags)
|
20506 | if (COMMENT_START.test(markup)) {
|
20507 | return markup;
|
20508 | } else {
|
20509 | return markup.replace(TAG_END, ' ' + ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="' + checksum + '"$&');
|
20510 | }
|
20511 | },
|
20512 |
|
20513 | /**
|
20514 | * @param {string} markup to use
|
20515 | * @param {DOMElement} element root React element
|
20516 | * @returns {boolean} whether or not the markup is the same
|
20517 | */
|
20518 | canReuseMarkup: function (markup, element) {
|
20519 | var existingChecksum = element.getAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
20520 | existingChecksum = existingChecksum && parseInt(existingChecksum, 10);
|
20521 | var markupChecksum = adler32(markup);
|
20522 | return markupChecksum === existingChecksum;
|
20523 | }
|
20524 | };
|
20525 |
|
20526 | module.exports = ReactMarkupChecksum;
|
20527 | },{"./adler32":254}],219:[function(require,module,exports){
|
20528 | (function (process){
|
20529 | /**
|
20530 | * Copyright 2013-present, Facebook, Inc.
|
20531 | * All rights reserved.
|
20532 | *
|
20533 | * This source code is licensed under the BSD-style license found in the
|
20534 | * LICENSE file in the root directory of this source tree. An additional grant
|
20535 | * of patent rights can be found in the PATENTS file in the same directory.
|
20536 | *
|
20537 | */
|
20538 |
|
20539 | 'use strict';
|
20540 |
|
20541 | var _prodInvariant = require('./reactProdInvariant');
|
20542 |
|
20543 | var DOMLazyTree = require('./DOMLazyTree');
|
20544 | var DOMProperty = require('./DOMProperty');
|
20545 | var React = require('react/lib/React');
|
20546 | var ReactBrowserEventEmitter = require('./ReactBrowserEventEmitter');
|
20547 | var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
20548 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
20549 | var ReactDOMContainerInfo = require('./ReactDOMContainerInfo');
|
20550 | var ReactDOMFeatureFlags = require('./ReactDOMFeatureFlags');
|
20551 | var ReactFeatureFlags = require('./ReactFeatureFlags');
|
20552 | var ReactInstanceMap = require('./ReactInstanceMap');
|
20553 | var ReactInstrumentation = require('./ReactInstrumentation');
|
20554 | var ReactMarkupChecksum = require('./ReactMarkupChecksum');
|
20555 | var ReactReconciler = require('./ReactReconciler');
|
20556 | var ReactUpdateQueue = require('./ReactUpdateQueue');
|
20557 | var ReactUpdates = require('./ReactUpdates');
|
20558 |
|
20559 | var emptyObject = require('fbjs/lib/emptyObject');
|
20560 | var instantiateReactComponent = require('./instantiateReactComponent');
|
20561 | var invariant = require('fbjs/lib/invariant');
|
20562 | var setInnerHTML = require('./setInnerHTML');
|
20563 | var shouldUpdateReactComponent = require('./shouldUpdateReactComponent');
|
20564 | var warning = require('fbjs/lib/warning');
|
20565 |
|
20566 | var ATTR_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
|
20567 | var ROOT_ATTR_NAME = DOMProperty.ROOT_ATTRIBUTE_NAME;
|
20568 |
|
20569 | var ELEMENT_NODE_TYPE = 1;
|
20570 | var DOC_NODE_TYPE = 9;
|
20571 | var DOCUMENT_FRAGMENT_NODE_TYPE = 11;
|
20572 |
|
20573 | var instancesByReactRootID = {};
|
20574 |
|
20575 | /**
|
20576 | * Finds the index of the first character
|
20577 | * that's not common between the two given strings.
|
20578 | *
|
20579 | * @return {number} the index of the character where the strings diverge
|
20580 | */
|
20581 | function firstDifferenceIndex(string1, string2) {
|
20582 | var minLen = Math.min(string1.length, string2.length);
|
20583 | for (var i = 0; i < minLen; i++) {
|
20584 | if (string1.charAt(i) !== string2.charAt(i)) {
|
20585 | return i;
|
20586 | }
|
20587 | }
|
20588 | return string1.length === string2.length ? -1 : minLen;
|
20589 | }
|
20590 |
|
20591 | /**
|
20592 | * @param {DOMElement|DOMDocument} container DOM element that may contain
|
20593 | * a React component
|
20594 | * @return {?*} DOM element that may have the reactRoot ID, or null.
|
20595 | */
|
20596 | function getReactRootElementInContainer(container) {
|
20597 | if (!container) {
|
20598 | return null;
|
20599 | }
|
20600 |
|
20601 | if (container.nodeType === DOC_NODE_TYPE) {
|
20602 | return container.documentElement;
|
20603 | } else {
|
20604 | return container.firstChild;
|
20605 | }
|
20606 | }
|
20607 |
|
20608 | function internalGetID(node) {
|
20609 | // If node is something like a window, document, or text node, none of
|
20610 | // which support attributes or a .getAttribute method, gracefully return
|
20611 | // the empty string, as if the attribute were missing.
|
20612 | return node.getAttribute && node.getAttribute(ATTR_NAME) || '';
|
20613 | }
|
20614 |
|
20615 | /**
|
20616 | * Mounts this component and inserts it into the DOM.
|
20617 | *
|
20618 | * @param {ReactComponent} componentInstance The instance to mount.
|
20619 | * @param {DOMElement} container DOM element to mount into.
|
20620 | * @param {ReactReconcileTransaction} transaction
|
20621 | * @param {boolean} shouldReuseMarkup If true, do not insert markup
|
20622 | */
|
20623 | function mountComponentIntoNode(wrapperInstance, container, transaction, shouldReuseMarkup, context) {
|
20624 | var markerName;
|
20625 | if (ReactFeatureFlags.logTopLevelRenders) {
|
20626 | var wrappedElement = wrapperInstance._currentElement.props.child;
|
20627 | var type = wrappedElement.type;
|
20628 | markerName = 'React mount: ' + (typeof type === 'string' ? type : type.displayName || type.name);
|
20629 | console.time(markerName);
|
20630 | }
|
20631 |
|
20632 | var markup = ReactReconciler.mountComponent(wrapperInstance, transaction, null, ReactDOMContainerInfo(wrapperInstance, container), context, 0 /* parentDebugID */
|
20633 | );
|
20634 |
|
20635 | if (markerName) {
|
20636 | console.timeEnd(markerName);
|
20637 | }
|
20638 |
|
20639 | wrapperInstance._renderedComponent._topLevelWrapper = wrapperInstance;
|
20640 | ReactMount._mountImageIntoNode(markup, container, wrapperInstance, shouldReuseMarkup, transaction);
|
20641 | }
|
20642 |
|
20643 | /**
|
20644 | * Batched mount.
|
20645 | *
|
20646 | * @param {ReactComponent} componentInstance The instance to mount.
|
20647 | * @param {DOMElement} container DOM element to mount into.
|
20648 | * @param {boolean} shouldReuseMarkup If true, do not insert markup
|
20649 | */
|
20650 | function batchedMountComponentIntoNode(componentInstance, container, shouldReuseMarkup, context) {
|
20651 | var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(
|
20652 | /* useCreateElement */
|
20653 | !shouldReuseMarkup && ReactDOMFeatureFlags.useCreateElement);
|
20654 | transaction.perform(mountComponentIntoNode, null, componentInstance, container, transaction, shouldReuseMarkup, context);
|
20655 | ReactUpdates.ReactReconcileTransaction.release(transaction);
|
20656 | }
|
20657 |
|
20658 | /**
|
20659 | * Unmounts a component and removes it from the DOM.
|
20660 | *
|
20661 | * @param {ReactComponent} instance React component instance.
|
20662 | * @param {DOMElement} container DOM element to unmount from.
|
20663 | * @final
|
20664 | * @internal
|
20665 | * @see {ReactMount.unmountComponentAtNode}
|
20666 | */
|
20667 | function unmountComponentFromNode(instance, container, safely) {
|
20668 | if (process.env.NODE_ENV !== 'production') {
|
20669 | ReactInstrumentation.debugTool.onBeginFlush();
|
20670 | }
|
20671 | ReactReconciler.unmountComponent(instance, safely);
|
20672 | if (process.env.NODE_ENV !== 'production') {
|
20673 | ReactInstrumentation.debugTool.onEndFlush();
|
20674 | }
|
20675 |
|
20676 | if (container.nodeType === DOC_NODE_TYPE) {
|
20677 | container = container.documentElement;
|
20678 | }
|
20679 |
|
20680 | // http://jsperf.com/emptying-a-node
|
20681 | while (container.lastChild) {
|
20682 | container.removeChild(container.lastChild);
|
20683 | }
|
20684 | }
|
20685 |
|
20686 | /**
|
20687 | * True if the supplied DOM node has a direct React-rendered child that is
|
20688 | * not a React root element. Useful for warning in `render`,
|
20689 | * `unmountComponentAtNode`, etc.
|
20690 | *
|
20691 | * @param {?DOMElement} node The candidate DOM node.
|
20692 | * @return {boolean} True if the DOM element contains a direct child that was
|
20693 | * rendered by React but is not a root element.
|
20694 | * @internal
|
20695 | */
|
20696 | function hasNonRootReactChild(container) {
|
20697 | var rootEl = getReactRootElementInContainer(container);
|
20698 | if (rootEl) {
|
20699 | var inst = ReactDOMComponentTree.getInstanceFromNode(rootEl);
|
20700 | return !!(inst && inst._hostParent);
|
20701 | }
|
20702 | }
|
20703 |
|
20704 | /**
|
20705 | * True if the supplied DOM node is a React DOM element and
|
20706 | * it has been rendered by another copy of React.
|
20707 | *
|
20708 | * @param {?DOMElement} node The candidate DOM node.
|
20709 | * @return {boolean} True if the DOM has been rendered by another copy of React
|
20710 | * @internal
|
20711 | */
|
20712 | function nodeIsRenderedByOtherInstance(container) {
|
20713 | var rootEl = getReactRootElementInContainer(container);
|
20714 | return !!(rootEl && isReactNode(rootEl) && !ReactDOMComponentTree.getInstanceFromNode(rootEl));
|
20715 | }
|
20716 |
|
20717 | /**
|
20718 | * True if the supplied DOM node is a valid node element.
|
20719 | *
|
20720 | * @param {?DOMElement} node The candidate DOM node.
|
20721 | * @return {boolean} True if the DOM is a valid DOM node.
|
20722 | * @internal
|
20723 | */
|
20724 | function isValidContainer(node) {
|
20725 | return !!(node && (node.nodeType === ELEMENT_NODE_TYPE || node.nodeType === DOC_NODE_TYPE || node.nodeType === DOCUMENT_FRAGMENT_NODE_TYPE));
|
20726 | }
|
20727 |
|
20728 | /**
|
20729 | * True if the supplied DOM node is a valid React node element.
|
20730 | *
|
20731 | * @param {?DOMElement} node The candidate DOM node.
|
20732 | * @return {boolean} True if the DOM is a valid React DOM node.
|
20733 | * @internal
|
20734 | */
|
20735 | function isReactNode(node) {
|
20736 | return isValidContainer(node) && (node.hasAttribute(ROOT_ATTR_NAME) || node.hasAttribute(ATTR_NAME));
|
20737 | }
|
20738 |
|
20739 | function getHostRootInstanceInContainer(container) {
|
20740 | var rootEl = getReactRootElementInContainer(container);
|
20741 | var prevHostInstance = rootEl && ReactDOMComponentTree.getInstanceFromNode(rootEl);
|
20742 | return prevHostInstance && !prevHostInstance._hostParent ? prevHostInstance : null;
|
20743 | }
|
20744 |
|
20745 | function getTopLevelWrapperInContainer(container) {
|
20746 | var root = getHostRootInstanceInContainer(container);
|
20747 | return root ? root._hostContainerInfo._topLevelWrapper : null;
|
20748 | }
|
20749 |
|
20750 | /**
|
20751 | * Temporary (?) hack so that we can store all top-level pending updates on
|
20752 | * composites instead of having to worry about different types of components
|
20753 | * here.
|
20754 | */
|
20755 | var topLevelRootCounter = 1;
|
20756 | var TopLevelWrapper = function () {
|
20757 | this.rootID = topLevelRootCounter++;
|
20758 | };
|
20759 | TopLevelWrapper.prototype.isReactComponent = {};
|
20760 | if (process.env.NODE_ENV !== 'production') {
|
20761 | TopLevelWrapper.displayName = 'TopLevelWrapper';
|
20762 | }
|
20763 | TopLevelWrapper.prototype.render = function () {
|
20764 | return this.props.child;
|
20765 | };
|
20766 | TopLevelWrapper.isReactTopLevelWrapper = true;
|
20767 |
|
20768 | /**
|
20769 | * Mounting is the process of initializing a React component by creating its
|
20770 | * representative DOM elements and inserting them into a supplied `container`.
|
20771 | * Any prior content inside `container` is destroyed in the process.
|
20772 | *
|
20773 | * ReactMount.render(
|
20774 | * component,
|
20775 | * document.getElementById('container')
|
20776 | * );
|
20777 | *
|
20778 | * <div id="container"> <-- Supplied `container`.
|
20779 | * <div data-reactid=".3"> <-- Rendered reactRoot of React
|
20780 | * // ... component.
|
20781 | * </div>
|
20782 | * </div>
|
20783 | *
|
20784 | * Inside of `container`, the first element rendered is the "reactRoot".
|
20785 | */
|
20786 | var ReactMount = {
|
20787 |
|
20788 | TopLevelWrapper: TopLevelWrapper,
|
20789 |
|
20790 | /**
|
20791 | * Used by devtools. The keys are not important.
|
20792 | */
|
20793 | _instancesByReactRootID: instancesByReactRootID,
|
20794 |
|
20795 | /**
|
20796 | * This is a hook provided to support rendering React components while
|
20797 | * ensuring that the apparent scroll position of its `container` does not
|
20798 | * change.
|
20799 | *
|
20800 | * @param {DOMElement} container The `container` being rendered into.
|
20801 | * @param {function} renderCallback This must be called once to do the render.
|
20802 | */
|
20803 | scrollMonitor: function (container, renderCallback) {
|
20804 | renderCallback();
|
20805 | },
|
20806 |
|
20807 | /**
|
20808 | * Take a component that's already mounted into the DOM and replace its props
|
20809 | * @param {ReactComponent} prevComponent component instance already in the DOM
|
20810 | * @param {ReactElement} nextElement component instance to render
|
20811 | * @param {DOMElement} container container to render into
|
20812 | * @param {?function} callback function triggered on completion
|
20813 | */
|
20814 | _updateRootComponent: function (prevComponent, nextElement, nextContext, container, callback) {
|
20815 | ReactMount.scrollMonitor(container, function () {
|
20816 | ReactUpdateQueue.enqueueElementInternal(prevComponent, nextElement, nextContext);
|
20817 | if (callback) {
|
20818 | ReactUpdateQueue.enqueueCallbackInternal(prevComponent, callback);
|
20819 | }
|
20820 | });
|
20821 |
|
20822 | return prevComponent;
|
20823 | },
|
20824 |
|
20825 | /**
|
20826 | * Render a new component into the DOM. Hooked by hooks!
|
20827 | *
|
20828 | * @param {ReactElement} nextElement element to render
|
20829 | * @param {DOMElement} container container to render into
|
20830 | * @param {boolean} shouldReuseMarkup if we should skip the markup insertion
|
20831 | * @return {ReactComponent} nextComponent
|
20832 | */
|
20833 | _renderNewRootComponent: function (nextElement, container, shouldReuseMarkup, context) {
|
20834 | // Various parts of our code (such as ReactCompositeComponent's
|
20835 | // _renderValidatedComponent) assume that calls to render aren't nested;
|
20836 | // verify that that's the case.
|
20837 | process.env.NODE_ENV !== 'production' ? warning(ReactCurrentOwner.current == null, '_renderNewRootComponent(): Render methods should be a pure function ' + 'of props and state; triggering nested component updates from ' + 'render is not allowed. If necessary, trigger nested updates in ' + 'componentDidUpdate. Check the render method of %s.', ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || 'ReactCompositeComponent') : void 0;
|
20838 |
|
20839 | !isValidContainer(container) ? process.env.NODE_ENV !== 'production' ? invariant(false, '_registerComponent(...): Target container is not a DOM element.') : _prodInvariant('37') : void 0;
|
20840 |
|
20841 | ReactBrowserEventEmitter.ensureScrollValueMonitoring();
|
20842 | var componentInstance = instantiateReactComponent(nextElement, false);
|
20843 |
|
20844 | // The initial render is synchronous but any updates that happen during
|
20845 | // rendering, in componentWillMount or componentDidMount, will be batched
|
20846 | // according to the current batching strategy.
|
20847 |
|
20848 | ReactUpdates.batchedUpdates(batchedMountComponentIntoNode, componentInstance, container, shouldReuseMarkup, context);
|
20849 |
|
20850 | var wrapperID = componentInstance._instance.rootID;
|
20851 | instancesByReactRootID[wrapperID] = componentInstance;
|
20852 |
|
20853 | return componentInstance;
|
20854 | },
|
20855 |
|
20856 | /**
|
20857 | * Renders a React component into the DOM in the supplied `container`.
|
20858 | *
|
20859 | * If the React component was previously rendered into `container`, this will
|
20860 | * perform an update on it and only mutate the DOM as necessary to reflect the
|
20861 | * latest React component.
|
20862 | *
|
20863 | * @param {ReactComponent} parentComponent The conceptual parent of this render tree.
|
20864 | * @param {ReactElement} nextElement Component element to render.
|
20865 | * @param {DOMElement} container DOM element to render into.
|
20866 | * @param {?function} callback function triggered on completion
|
20867 | * @return {ReactComponent} Component instance rendered in `container`.
|
20868 | */
|
20869 | renderSubtreeIntoContainer: function (parentComponent, nextElement, container, callback) {
|
20870 | !(parentComponent != null && ReactInstanceMap.has(parentComponent)) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'parentComponent must be a valid React Component') : _prodInvariant('38') : void 0;
|
20871 | return ReactMount._renderSubtreeIntoContainer(parentComponent, nextElement, container, callback);
|
20872 | },
|
20873 |
|
20874 | _renderSubtreeIntoContainer: function (parentComponent, nextElement, container, callback) {
|
20875 | ReactUpdateQueue.validateCallback(callback, 'ReactDOM.render');
|
20876 | !React.isValidElement(nextElement) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactDOM.render(): Invalid component element.%s', typeof nextElement === 'string' ? ' Instead of passing a string like \'div\', pass ' + 'React.createElement(\'div\') or <div />.' : typeof nextElement === 'function' ? ' Instead of passing a class like Foo, pass ' + 'React.createElement(Foo) or <Foo />.' :
|
20877 | // Check if it quacks like an element
|
20878 | nextElement != null && nextElement.props !== undefined ? ' This may be caused by unintentionally loading two independent ' + 'copies of React.' : '') : _prodInvariant('39', typeof nextElement === 'string' ? ' Instead of passing a string like \'div\', pass ' + 'React.createElement(\'div\') or <div />.' : typeof nextElement === 'function' ? ' Instead of passing a class like Foo, pass ' + 'React.createElement(Foo) or <Foo />.' : nextElement != null && nextElement.props !== undefined ? ' This may be caused by unintentionally loading two independent ' + 'copies of React.' : '') : void 0;
|
20879 |
|
20880 | process.env.NODE_ENV !== 'production' ? warning(!container || !container.tagName || container.tagName.toUpperCase() !== 'BODY', 'render(): Rendering components directly into document.body is ' + 'discouraged, since its children are often manipulated by third-party ' + 'scripts and browser extensions. This may lead to subtle ' + 'reconciliation issues. Try rendering into a container element created ' + 'for your app.') : void 0;
|
20881 |
|
20882 | var nextWrappedElement = React.createElement(TopLevelWrapper, { child: nextElement });
|
20883 |
|
20884 | var nextContext;
|
20885 | if (parentComponent) {
|
20886 | var parentInst = ReactInstanceMap.get(parentComponent);
|
20887 | nextContext = parentInst._processChildContext(parentInst._context);
|
20888 | } else {
|
20889 | nextContext = emptyObject;
|
20890 | }
|
20891 |
|
20892 | var prevComponent = getTopLevelWrapperInContainer(container);
|
20893 |
|
20894 | if (prevComponent) {
|
20895 | var prevWrappedElement = prevComponent._currentElement;
|
20896 | var prevElement = prevWrappedElement.props.child;
|
20897 | if (shouldUpdateReactComponent(prevElement, nextElement)) {
|
20898 | var publicInst = prevComponent._renderedComponent.getPublicInstance();
|
20899 | var updatedCallback = callback && function () {
|
20900 | callback.call(publicInst);
|
20901 | };
|
20902 | ReactMount._updateRootComponent(prevComponent, nextWrappedElement, nextContext, container, updatedCallback);
|
20903 | return publicInst;
|
20904 | } else {
|
20905 | ReactMount.unmountComponentAtNode(container);
|
20906 | }
|
20907 | }
|
20908 |
|
20909 | var reactRootElement = getReactRootElementInContainer(container);
|
20910 | var containerHasReactMarkup = reactRootElement && !!internalGetID(reactRootElement);
|
20911 | var containerHasNonRootReactChild = hasNonRootReactChild(container);
|
20912 |
|
20913 | if (process.env.NODE_ENV !== 'production') {
|
20914 | process.env.NODE_ENV !== 'production' ? warning(!containerHasNonRootReactChild, 'render(...): Replacing React-rendered children with a new root ' + 'component. If you intended to update the children of this node, ' + 'you should instead have the existing children update their state ' + 'and render the new components instead of calling ReactDOM.render.') : void 0;
|
20915 |
|
20916 | if (!containerHasReactMarkup || reactRootElement.nextSibling) {
|
20917 | var rootElementSibling = reactRootElement;
|
20918 | while (rootElementSibling) {
|
20919 | if (internalGetID(rootElementSibling)) {
|
20920 | process.env.NODE_ENV !== 'production' ? warning(false, 'render(): Target node has markup rendered by React, but there ' + 'are unrelated nodes as well. This is most commonly caused by ' + 'white-space inserted around server-rendered markup.') : void 0;
|
20921 | break;
|
20922 | }
|
20923 | rootElementSibling = rootElementSibling.nextSibling;
|
20924 | }
|
20925 | }
|
20926 | }
|
20927 |
|
20928 | var shouldReuseMarkup = containerHasReactMarkup && !prevComponent && !containerHasNonRootReactChild;
|
20929 | var component = ReactMount._renderNewRootComponent(nextWrappedElement, container, shouldReuseMarkup, nextContext)._renderedComponent.getPublicInstance();
|
20930 | if (callback) {
|
20931 | callback.call(component);
|
20932 | }
|
20933 | return component;
|
20934 | },
|
20935 |
|
20936 | /**
|
20937 | * Renders a React component into the DOM in the supplied `container`.
|
20938 | * See https://facebook.github.io/react/docs/top-level-api.html#reactdom.render
|
20939 | *
|
20940 | * If the React component was previously rendered into `container`, this will
|
20941 | * perform an update on it and only mutate the DOM as necessary to reflect the
|
20942 | * latest React component.
|
20943 | *
|
20944 | * @param {ReactElement} nextElement Component element to render.
|
20945 | * @param {DOMElement} container DOM element to render into.
|
20946 | * @param {?function} callback function triggered on completion
|
20947 | * @return {ReactComponent} Component instance rendered in `container`.
|
20948 | */
|
20949 | render: function (nextElement, container, callback) {
|
20950 | return ReactMount._renderSubtreeIntoContainer(null, nextElement, container, callback);
|
20951 | },
|
20952 |
|
20953 | /**
|
20954 | * Unmounts and destroys the React component rendered in the `container`.
|
20955 | * See https://facebook.github.io/react/docs/top-level-api.html#reactdom.unmountcomponentatnode
|
20956 | *
|
20957 | * @param {DOMElement} container DOM element containing a React component.
|
20958 | * @return {boolean} True if a component was found in and unmounted from
|
20959 | * `container`
|
20960 | */
|
20961 | unmountComponentAtNode: function (container) {
|
20962 | // Various parts of our code (such as ReactCompositeComponent's
|
20963 | // _renderValidatedComponent) assume that calls to render aren't nested;
|
20964 | // verify that that's the case. (Strictly speaking, unmounting won't cause a
|
20965 | // render but we still don't expect to be in a render call here.)
|
20966 | process.env.NODE_ENV !== 'production' ? warning(ReactCurrentOwner.current == null, 'unmountComponentAtNode(): Render methods should be a pure function ' + 'of props and state; triggering nested component updates from render ' + 'is not allowed. If necessary, trigger nested updates in ' + 'componentDidUpdate. Check the render method of %s.', ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || 'ReactCompositeComponent') : void 0;
|
20967 |
|
20968 | !isValidContainer(container) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'unmountComponentAtNode(...): Target container is not a DOM element.') : _prodInvariant('40') : void 0;
|
20969 |
|
20970 | if (process.env.NODE_ENV !== 'production') {
|
20971 | process.env.NODE_ENV !== 'production' ? warning(!nodeIsRenderedByOtherInstance(container), 'unmountComponentAtNode(): The node you\'re attempting to unmount ' + 'was rendered by another copy of React.') : void 0;
|
20972 | }
|
20973 |
|
20974 | var prevComponent = getTopLevelWrapperInContainer(container);
|
20975 | if (!prevComponent) {
|
20976 | // Check if the node being unmounted was rendered by React, but isn't a
|
20977 | // root node.
|
20978 | var containerHasNonRootReactChild = hasNonRootReactChild(container);
|
20979 |
|
20980 | // Check if the container itself is a React root node.
|
20981 | var isContainerReactRoot = container.nodeType === 1 && container.hasAttribute(ROOT_ATTR_NAME);
|
20982 |
|
20983 | if (process.env.NODE_ENV !== 'production') {
|
20984 | process.env.NODE_ENV !== 'production' ? warning(!containerHasNonRootReactChild, 'unmountComponentAtNode(): The node you\'re attempting to unmount ' + 'was rendered by React and is not a top-level container. %s', isContainerReactRoot ? 'You may have accidentally passed in a React root node instead ' + 'of its container.' : 'Instead, have the parent component update its state and ' + 'rerender in order to remove this component.') : void 0;
|
20985 | }
|
20986 |
|
20987 | return false;
|
20988 | }
|
20989 | delete instancesByReactRootID[prevComponent._instance.rootID];
|
20990 | ReactUpdates.batchedUpdates(unmountComponentFromNode, prevComponent, container, false);
|
20991 | return true;
|
20992 | },
|
20993 |
|
20994 | _mountImageIntoNode: function (markup, container, instance, shouldReuseMarkup, transaction) {
|
20995 | !isValidContainer(container) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'mountComponentIntoNode(...): Target container is not valid.') : _prodInvariant('41') : void 0;
|
20996 |
|
20997 | if (shouldReuseMarkup) {
|
20998 | var rootElement = getReactRootElementInContainer(container);
|
20999 | if (ReactMarkupChecksum.canReuseMarkup(markup, rootElement)) {
|
21000 | ReactDOMComponentTree.precacheNode(instance, rootElement);
|
21001 | return;
|
21002 | } else {
|
21003 | var checksum = rootElement.getAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
21004 | rootElement.removeAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
21005 |
|
21006 | var rootMarkup = rootElement.outerHTML;
|
21007 | rootElement.setAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME, checksum);
|
21008 |
|
21009 | var normalizedMarkup = markup;
|
21010 | if (process.env.NODE_ENV !== 'production') {
|
21011 | // because rootMarkup is retrieved from the DOM, various normalizations
|
21012 | // will have occurred which will not be present in `markup`. Here,
|
21013 | // insert markup into a <div> or <iframe> depending on the container
|
21014 | // type to perform the same normalizations before comparing.
|
21015 | var normalizer;
|
21016 | if (container.nodeType === ELEMENT_NODE_TYPE) {
|
21017 | normalizer = document.createElement('div');
|
21018 | normalizer.innerHTML = markup;
|
21019 | normalizedMarkup = normalizer.innerHTML;
|
21020 | } else {
|
21021 | normalizer = document.createElement('iframe');
|
21022 | document.body.appendChild(normalizer);
|
21023 | normalizer.contentDocument.write(markup);
|
21024 | normalizedMarkup = normalizer.contentDocument.documentElement.outerHTML;
|
21025 | document.body.removeChild(normalizer);
|
21026 | }
|
21027 | }
|
21028 |
|
21029 | var diffIndex = firstDifferenceIndex(normalizedMarkup, rootMarkup);
|
21030 | var difference = ' (client) ' + normalizedMarkup.substring(diffIndex - 20, diffIndex + 20) + '\n (server) ' + rootMarkup.substring(diffIndex - 20, diffIndex + 20);
|
21031 |
|
21032 | !(container.nodeType !== DOC_NODE_TYPE) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'You\'re trying to render a component to the document using server rendering but the checksum was invalid. This usually means you rendered a different component type or props on the client from the one on the server, or your render() methods are impure. React cannot handle this case due to cross-browser quirks by rendering at the document root. You should look for environment dependent code in your components and ensure the props are the same client and server side:\n%s', difference) : _prodInvariant('42', difference) : void 0;
|
21033 |
|
21034 | if (process.env.NODE_ENV !== 'production') {
|
21035 | process.env.NODE_ENV !== 'production' ? warning(false, 'React attempted to reuse markup in a container but the ' + 'checksum was invalid. This generally means that you are ' + 'using server rendering and the markup generated on the ' + 'server was not what the client was expecting. React injected ' + 'new markup to compensate which works but you have lost many ' + 'of the benefits of server rendering. Instead, figure out ' + 'why the markup being generated is different on the client ' + 'or server:\n%s', difference) : void 0;
|
21036 | }
|
21037 | }
|
21038 | }
|
21039 |
|
21040 | !(container.nodeType !== DOC_NODE_TYPE) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'You\'re trying to render a component to the document but you didn\'t use server rendering. We can\'t do this without using server rendering due to cross-browser quirks. See ReactDOMServer.renderToString() for server rendering.') : _prodInvariant('43') : void 0;
|
21041 |
|
21042 | if (transaction.useCreateElement) {
|
21043 | while (container.lastChild) {
|
21044 | container.removeChild(container.lastChild);
|
21045 | }
|
21046 | DOMLazyTree.insertTreeBefore(container, markup, null);
|
21047 | } else {
|
21048 | setInnerHTML(container, markup);
|
21049 | ReactDOMComponentTree.precacheNode(instance, container.firstChild);
|
21050 | }
|
21051 |
|
21052 | if (process.env.NODE_ENV !== 'production') {
|
21053 | var hostNode = ReactDOMComponentTree.getInstanceFromNode(container.firstChild);
|
21054 | if (hostNode._debugID !== 0) {
|
21055 | ReactInstrumentation.debugTool.onHostOperation({
|
21056 | instanceID: hostNode._debugID,
|
21057 | type: 'mount',
|
21058 | payload: markup.toString()
|
21059 | });
|
21060 | }
|
21061 | }
|
21062 | }
|
21063 | };
|
21064 |
|
21065 | module.exports = ReactMount;
|
21066 | }).call(this,require('_process'))
|
21067 | },{"./DOMLazyTree":162,"./DOMProperty":164,"./ReactBrowserEventEmitter":178,"./ReactDOMComponentTree":186,"./ReactDOMContainerInfo":187,"./ReactDOMFeatureFlags":189,"./ReactFeatureFlags":210,"./ReactInstanceMap":215,"./ReactInstrumentation":216,"./ReactMarkupChecksum":218,"./ReactReconciler":226,"./ReactUpdateQueue":232,"./ReactUpdates":233,"./instantiateReactComponent":272,"./reactProdInvariant":276,"./setInnerHTML":278,"./shouldUpdateReactComponent":280,"_process":144,"fbjs/lib/emptyObject":117,"fbjs/lib/invariant":124,"fbjs/lib/warning":131,"react/lib/React":287,"react/lib/ReactCurrentOwner":292}],220:[function(require,module,exports){
|
21068 | (function (process){
|
21069 | /**
|
21070 | * Copyright 2013-present, Facebook, Inc.
|
21071 | * All rights reserved.
|
21072 | *
|
21073 | * This source code is licensed under the BSD-style license found in the
|
21074 | * LICENSE file in the root directory of this source tree. An additional grant
|
21075 | * of patent rights can be found in the PATENTS file in the same directory.
|
21076 | *
|
21077 | */
|
21078 |
|
21079 | 'use strict';
|
21080 |
|
21081 | var _prodInvariant = require('./reactProdInvariant');
|
21082 |
|
21083 | var ReactComponentEnvironment = require('./ReactComponentEnvironment');
|
21084 | var ReactInstanceMap = require('./ReactInstanceMap');
|
21085 | var ReactInstrumentation = require('./ReactInstrumentation');
|
21086 |
|
21087 | var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
21088 | var ReactReconciler = require('./ReactReconciler');
|
21089 | var ReactChildReconciler = require('./ReactChildReconciler');
|
21090 |
|
21091 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
21092 | var flattenChildren = require('./flattenChildren');
|
21093 | var invariant = require('fbjs/lib/invariant');
|
21094 |
|
21095 | /**
|
21096 | * Make an update for markup to be rendered and inserted at a supplied index.
|
21097 | *
|
21098 | * @param {string} markup Markup that renders into an element.
|
21099 | * @param {number} toIndex Destination index.
|
21100 | * @private
|
21101 | */
|
21102 | function makeInsertMarkup(markup, afterNode, toIndex) {
|
21103 | // NOTE: Null values reduce hidden classes.
|
21104 | return {
|
21105 | type: 'INSERT_MARKUP',
|
21106 | content: markup,
|
21107 | fromIndex: null,
|
21108 | fromNode: null,
|
21109 | toIndex: toIndex,
|
21110 | afterNode: afterNode
|
21111 | };
|
21112 | }
|
21113 |
|
21114 | /**
|
21115 | * Make an update for moving an existing element to another index.
|
21116 | *
|
21117 | * @param {number} fromIndex Source index of the existing element.
|
21118 | * @param {number} toIndex Destination index of the element.
|
21119 | * @private
|
21120 | */
|
21121 | function makeMove(child, afterNode, toIndex) {
|
21122 | // NOTE: Null values reduce hidden classes.
|
21123 | return {
|
21124 | type: 'MOVE_EXISTING',
|
21125 | content: null,
|
21126 | fromIndex: child._mountIndex,
|
21127 | fromNode: ReactReconciler.getHostNode(child),
|
21128 | toIndex: toIndex,
|
21129 | afterNode: afterNode
|
21130 | };
|
21131 | }
|
21132 |
|
21133 | /**
|
21134 | * Make an update for removing an element at an index.
|
21135 | *
|
21136 | * @param {number} fromIndex Index of the element to remove.
|
21137 | * @private
|
21138 | */
|
21139 | function makeRemove(child, node) {
|
21140 | // NOTE: Null values reduce hidden classes.
|
21141 | return {
|
21142 | type: 'REMOVE_NODE',
|
21143 | content: null,
|
21144 | fromIndex: child._mountIndex,
|
21145 | fromNode: node,
|
21146 | toIndex: null,
|
21147 | afterNode: null
|
21148 | };
|
21149 | }
|
21150 |
|
21151 | /**
|
21152 | * Make an update for setting the markup of a node.
|
21153 | *
|
21154 | * @param {string} markup Markup that renders into an element.
|
21155 | * @private
|
21156 | */
|
21157 | function makeSetMarkup(markup) {
|
21158 | // NOTE: Null values reduce hidden classes.
|
21159 | return {
|
21160 | type: 'SET_MARKUP',
|
21161 | content: markup,
|
21162 | fromIndex: null,
|
21163 | fromNode: null,
|
21164 | toIndex: null,
|
21165 | afterNode: null
|
21166 | };
|
21167 | }
|
21168 |
|
21169 | /**
|
21170 | * Make an update for setting the text content.
|
21171 | *
|
21172 | * @param {string} textContent Text content to set.
|
21173 | * @private
|
21174 | */
|
21175 | function makeTextContent(textContent) {
|
21176 | // NOTE: Null values reduce hidden classes.
|
21177 | return {
|
21178 | type: 'TEXT_CONTENT',
|
21179 | content: textContent,
|
21180 | fromIndex: null,
|
21181 | fromNode: null,
|
21182 | toIndex: null,
|
21183 | afterNode: null
|
21184 | };
|
21185 | }
|
21186 |
|
21187 | /**
|
21188 | * Push an update, if any, onto the queue. Creates a new queue if none is
|
21189 | * passed and always returns the queue. Mutative.
|
21190 | */
|
21191 | function enqueue(queue, update) {
|
21192 | if (update) {
|
21193 | queue = queue || [];
|
21194 | queue.push(update);
|
21195 | }
|
21196 | return queue;
|
21197 | }
|
21198 |
|
21199 | /**
|
21200 | * Processes any enqueued updates.
|
21201 | *
|
21202 | * @private
|
21203 | */
|
21204 | function processQueue(inst, updateQueue) {
|
21205 | ReactComponentEnvironment.processChildrenUpdates(inst, updateQueue);
|
21206 | }
|
21207 |
|
21208 | var setChildrenForInstrumentation = emptyFunction;
|
21209 | if (process.env.NODE_ENV !== 'production') {
|
21210 | var getDebugID = function (inst) {
|
21211 | if (!inst._debugID) {
|
21212 | // Check for ART-like instances. TODO: This is silly/gross.
|
21213 | var internal;
|
21214 | if (internal = ReactInstanceMap.get(inst)) {
|
21215 | inst = internal;
|
21216 | }
|
21217 | }
|
21218 | return inst._debugID;
|
21219 | };
|
21220 | setChildrenForInstrumentation = function (children) {
|
21221 | var debugID = getDebugID(this);
|
21222 | // TODO: React Native empty components are also multichild.
|
21223 | // This means they still get into this method but don't have _debugID.
|
21224 | if (debugID !== 0) {
|
21225 | ReactInstrumentation.debugTool.onSetChildren(debugID, children ? Object.keys(children).map(function (key) {
|
21226 | return children[key]._debugID;
|
21227 | }) : []);
|
21228 | }
|
21229 | };
|
21230 | }
|
21231 |
|
21232 | /**
|
21233 | * ReactMultiChild are capable of reconciling multiple children.
|
21234 | *
|
21235 | * @class ReactMultiChild
|
21236 | * @internal
|
21237 | */
|
21238 | var ReactMultiChild = {
|
21239 |
|
21240 | /**
|
21241 | * Provides common functionality for components that must reconcile multiple
|
21242 | * children. This is used by `ReactDOMComponent` to mount, update, and
|
21243 | * unmount child components.
|
21244 | *
|
21245 | * @lends {ReactMultiChild.prototype}
|
21246 | */
|
21247 | Mixin: {
|
21248 |
|
21249 | _reconcilerInstantiateChildren: function (nestedChildren, transaction, context) {
|
21250 | if (process.env.NODE_ENV !== 'production') {
|
21251 | var selfDebugID = getDebugID(this);
|
21252 | if (this._currentElement) {
|
21253 | try {
|
21254 | ReactCurrentOwner.current = this._currentElement._owner;
|
21255 | return ReactChildReconciler.instantiateChildren(nestedChildren, transaction, context, selfDebugID);
|
21256 | } finally {
|
21257 | ReactCurrentOwner.current = null;
|
21258 | }
|
21259 | }
|
21260 | }
|
21261 | return ReactChildReconciler.instantiateChildren(nestedChildren, transaction, context);
|
21262 | },
|
21263 |
|
21264 | _reconcilerUpdateChildren: function (prevChildren, nextNestedChildrenElements, mountImages, removedNodes, transaction, context) {
|
21265 | var nextChildren;
|
21266 | var selfDebugID = 0;
|
21267 | if (process.env.NODE_ENV !== 'production') {
|
21268 | selfDebugID = getDebugID(this);
|
21269 | if (this._currentElement) {
|
21270 | try {
|
21271 | ReactCurrentOwner.current = this._currentElement._owner;
|
21272 | nextChildren = flattenChildren(nextNestedChildrenElements, selfDebugID);
|
21273 | } finally {
|
21274 | ReactCurrentOwner.current = null;
|
21275 | }
|
21276 | ReactChildReconciler.updateChildren(prevChildren, nextChildren, mountImages, removedNodes, transaction, this, this._hostContainerInfo, context, selfDebugID);
|
21277 | return nextChildren;
|
21278 | }
|
21279 | }
|
21280 | nextChildren = flattenChildren(nextNestedChildrenElements, selfDebugID);
|
21281 | ReactChildReconciler.updateChildren(prevChildren, nextChildren, mountImages, removedNodes, transaction, this, this._hostContainerInfo, context, selfDebugID);
|
21282 | return nextChildren;
|
21283 | },
|
21284 |
|
21285 | /**
|
21286 | * Generates a "mount image" for each of the supplied children. In the case
|
21287 | * of `ReactDOMComponent`, a mount image is a string of markup.
|
21288 | *
|
21289 | * @param {?object} nestedChildren Nested child maps.
|
21290 | * @return {array} An array of mounted representations.
|
21291 | * @internal
|
21292 | */
|
21293 | mountChildren: function (nestedChildren, transaction, context) {
|
21294 | var children = this._reconcilerInstantiateChildren(nestedChildren, transaction, context);
|
21295 | this._renderedChildren = children;
|
21296 |
|
21297 | var mountImages = [];
|
21298 | var index = 0;
|
21299 | for (var name in children) {
|
21300 | if (children.hasOwnProperty(name)) {
|
21301 | var child = children[name];
|
21302 | var selfDebugID = 0;
|
21303 | if (process.env.NODE_ENV !== 'production') {
|
21304 | selfDebugID = getDebugID(this);
|
21305 | }
|
21306 | var mountImage = ReactReconciler.mountComponent(child, transaction, this, this._hostContainerInfo, context, selfDebugID);
|
21307 | child._mountIndex = index++;
|
21308 | mountImages.push(mountImage);
|
21309 | }
|
21310 | }
|
21311 |
|
21312 | if (process.env.NODE_ENV !== 'production') {
|
21313 | setChildrenForInstrumentation.call(this, children);
|
21314 | }
|
21315 |
|
21316 | return mountImages;
|
21317 | },
|
21318 |
|
21319 | /**
|
21320 | * Replaces any rendered children with a text content string.
|
21321 | *
|
21322 | * @param {string} nextContent String of content.
|
21323 | * @internal
|
21324 | */
|
21325 | updateTextContent: function (nextContent) {
|
21326 | var prevChildren = this._renderedChildren;
|
21327 | // Remove any rendered children.
|
21328 | ReactChildReconciler.unmountChildren(prevChildren, false);
|
21329 | for (var name in prevChildren) {
|
21330 | if (prevChildren.hasOwnProperty(name)) {
|
21331 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'updateTextContent called on non-empty component.') : _prodInvariant('118') : void 0;
|
21332 | }
|
21333 | }
|
21334 | // Set new text content.
|
21335 | var updates = [makeTextContent(nextContent)];
|
21336 | processQueue(this, updates);
|
21337 | },
|
21338 |
|
21339 | /**
|
21340 | * Replaces any rendered children with a markup string.
|
21341 | *
|
21342 | * @param {string} nextMarkup String of markup.
|
21343 | * @internal
|
21344 | */
|
21345 | updateMarkup: function (nextMarkup) {
|
21346 | var prevChildren = this._renderedChildren;
|
21347 | // Remove any rendered children.
|
21348 | ReactChildReconciler.unmountChildren(prevChildren, false);
|
21349 | for (var name in prevChildren) {
|
21350 | if (prevChildren.hasOwnProperty(name)) {
|
21351 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'updateTextContent called on non-empty component.') : _prodInvariant('118') : void 0;
|
21352 | }
|
21353 | }
|
21354 | var updates = [makeSetMarkup(nextMarkup)];
|
21355 | processQueue(this, updates);
|
21356 | },
|
21357 |
|
21358 | /**
|
21359 | * Updates the rendered children with new children.
|
21360 | *
|
21361 | * @param {?object} nextNestedChildrenElements Nested child element maps.
|
21362 | * @param {ReactReconcileTransaction} transaction
|
21363 | * @internal
|
21364 | */
|
21365 | updateChildren: function (nextNestedChildrenElements, transaction, context) {
|
21366 | // Hook used by React ART
|
21367 | this._updateChildren(nextNestedChildrenElements, transaction, context);
|
21368 | },
|
21369 |
|
21370 | /**
|
21371 | * @param {?object} nextNestedChildrenElements Nested child element maps.
|
21372 | * @param {ReactReconcileTransaction} transaction
|
21373 | * @final
|
21374 | * @protected
|
21375 | */
|
21376 | _updateChildren: function (nextNestedChildrenElements, transaction, context) {
|
21377 | var prevChildren = this._renderedChildren;
|
21378 | var removedNodes = {};
|
21379 | var mountImages = [];
|
21380 | var nextChildren = this._reconcilerUpdateChildren(prevChildren, nextNestedChildrenElements, mountImages, removedNodes, transaction, context);
|
21381 | if (!nextChildren && !prevChildren) {
|
21382 | return;
|
21383 | }
|
21384 | var updates = null;
|
21385 | var name;
|
21386 | // `nextIndex` will increment for each child in `nextChildren`, but
|
21387 | // `lastIndex` will be the last index visited in `prevChildren`.
|
21388 | var nextIndex = 0;
|
21389 | var lastIndex = 0;
|
21390 | // `nextMountIndex` will increment for each newly mounted child.
|
21391 | var nextMountIndex = 0;
|
21392 | var lastPlacedNode = null;
|
21393 | for (name in nextChildren) {
|
21394 | if (!nextChildren.hasOwnProperty(name)) {
|
21395 | continue;
|
21396 | }
|
21397 | var prevChild = prevChildren && prevChildren[name];
|
21398 | var nextChild = nextChildren[name];
|
21399 | if (prevChild === nextChild) {
|
21400 | updates = enqueue(updates, this.moveChild(prevChild, lastPlacedNode, nextIndex, lastIndex));
|
21401 | lastIndex = Math.max(prevChild._mountIndex, lastIndex);
|
21402 | prevChild._mountIndex = nextIndex;
|
21403 | } else {
|
21404 | if (prevChild) {
|
21405 | // Update `lastIndex` before `_mountIndex` gets unset by unmounting.
|
21406 | lastIndex = Math.max(prevChild._mountIndex, lastIndex);
|
21407 | // The `removedNodes` loop below will actually remove the child.
|
21408 | }
|
21409 | // The child must be instantiated before it's mounted.
|
21410 | updates = enqueue(updates, this._mountChildAtIndex(nextChild, mountImages[nextMountIndex], lastPlacedNode, nextIndex, transaction, context));
|
21411 | nextMountIndex++;
|
21412 | }
|
21413 | nextIndex++;
|
21414 | lastPlacedNode = ReactReconciler.getHostNode(nextChild);
|
21415 | }
|
21416 | // Remove children that are no longer present.
|
21417 | for (name in removedNodes) {
|
21418 | if (removedNodes.hasOwnProperty(name)) {
|
21419 | updates = enqueue(updates, this._unmountChild(prevChildren[name], removedNodes[name]));
|
21420 | }
|
21421 | }
|
21422 | if (updates) {
|
21423 | processQueue(this, updates);
|
21424 | }
|
21425 | this._renderedChildren = nextChildren;
|
21426 |
|
21427 | if (process.env.NODE_ENV !== 'production') {
|
21428 | setChildrenForInstrumentation.call(this, nextChildren);
|
21429 | }
|
21430 | },
|
21431 |
|
21432 | /**
|
21433 | * Unmounts all rendered children. This should be used to clean up children
|
21434 | * when this component is unmounted. It does not actually perform any
|
21435 | * backend operations.
|
21436 | *
|
21437 | * @internal
|
21438 | */
|
21439 | unmountChildren: function (safely) {
|
21440 | var renderedChildren = this._renderedChildren;
|
21441 | ReactChildReconciler.unmountChildren(renderedChildren, safely);
|
21442 | this._renderedChildren = null;
|
21443 | },
|
21444 |
|
21445 | /**
|
21446 | * Moves a child component to the supplied index.
|
21447 | *
|
21448 | * @param {ReactComponent} child Component to move.
|
21449 | * @param {number} toIndex Destination index of the element.
|
21450 | * @param {number} lastIndex Last index visited of the siblings of `child`.
|
21451 | * @protected
|
21452 | */
|
21453 | moveChild: function (child, afterNode, toIndex, lastIndex) {
|
21454 | // If the index of `child` is less than `lastIndex`, then it needs to
|
21455 | // be moved. Otherwise, we do not need to move it because a child will be
|
21456 | // inserted or moved before `child`.
|
21457 | if (child._mountIndex < lastIndex) {
|
21458 | return makeMove(child, afterNode, toIndex);
|
21459 | }
|
21460 | },
|
21461 |
|
21462 | /**
|
21463 | * Creates a child component.
|
21464 | *
|
21465 | * @param {ReactComponent} child Component to create.
|
21466 | * @param {string} mountImage Markup to insert.
|
21467 | * @protected
|
21468 | */
|
21469 | createChild: function (child, afterNode, mountImage) {
|
21470 | return makeInsertMarkup(mountImage, afterNode, child._mountIndex);
|
21471 | },
|
21472 |
|
21473 | /**
|
21474 | * Removes a child component.
|
21475 | *
|
21476 | * @param {ReactComponent} child Child to remove.
|
21477 | * @protected
|
21478 | */
|
21479 | removeChild: function (child, node) {
|
21480 | return makeRemove(child, node);
|
21481 | },
|
21482 |
|
21483 | /**
|
21484 | * Mounts a child with the supplied name.
|
21485 | *
|
21486 | * NOTE: This is part of `updateChildren` and is here for readability.
|
21487 | *
|
21488 | * @param {ReactComponent} child Component to mount.
|
21489 | * @param {string} name Name of the child.
|
21490 | * @param {number} index Index at which to insert the child.
|
21491 | * @param {ReactReconcileTransaction} transaction
|
21492 | * @private
|
21493 | */
|
21494 | _mountChildAtIndex: function (child, mountImage, afterNode, index, transaction, context) {
|
21495 | child._mountIndex = index;
|
21496 | return this.createChild(child, afterNode, mountImage);
|
21497 | },
|
21498 |
|
21499 | /**
|
21500 | * Unmounts a rendered child.
|
21501 | *
|
21502 | * NOTE: This is part of `updateChildren` and is here for readability.
|
21503 | *
|
21504 | * @param {ReactComponent} child Component to unmount.
|
21505 | * @private
|
21506 | */
|
21507 | _unmountChild: function (child, node) {
|
21508 | var update = this.removeChild(child, node);
|
21509 | child._mountIndex = null;
|
21510 | return update;
|
21511 | }
|
21512 |
|
21513 | }
|
21514 |
|
21515 | };
|
21516 |
|
21517 | module.exports = ReactMultiChild;
|
21518 | }).call(this,require('_process'))
|
21519 | },{"./ReactChildReconciler":179,"./ReactComponentEnvironment":181,"./ReactInstanceMap":215,"./ReactInstrumentation":216,"./ReactReconciler":226,"./flattenChildren":260,"./reactProdInvariant":276,"_process":144,"fbjs/lib/emptyFunction":116,"fbjs/lib/invariant":124,"react/lib/ReactCurrentOwner":292}],221:[function(require,module,exports){
|
21520 | (function (process){
|
21521 | /**
|
21522 | * Copyright 2013-present, Facebook, Inc.
|
21523 | * All rights reserved.
|
21524 | *
|
21525 | * This source code is licensed under the BSD-style license found in the
|
21526 | * LICENSE file in the root directory of this source tree. An additional grant
|
21527 | * of patent rights can be found in the PATENTS file in the same directory.
|
21528 | *
|
21529 | *
|
21530 | */
|
21531 |
|
21532 | 'use strict';
|
21533 |
|
21534 | var _prodInvariant = require('./reactProdInvariant');
|
21535 |
|
21536 | var React = require('react/lib/React');
|
21537 |
|
21538 | var invariant = require('fbjs/lib/invariant');
|
21539 |
|
21540 | var ReactNodeTypes = {
|
21541 | HOST: 0,
|
21542 | COMPOSITE: 1,
|
21543 | EMPTY: 2,
|
21544 |
|
21545 | getType: function (node) {
|
21546 | if (node === null || node === false) {
|
21547 | return ReactNodeTypes.EMPTY;
|
21548 | } else if (React.isValidElement(node)) {
|
21549 | if (typeof node.type === 'function') {
|
21550 | return ReactNodeTypes.COMPOSITE;
|
21551 | } else {
|
21552 | return ReactNodeTypes.HOST;
|
21553 | }
|
21554 | }
|
21555 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Unexpected node: %s', node) : _prodInvariant('26', node) : void 0;
|
21556 | }
|
21557 | };
|
21558 |
|
21559 | module.exports = ReactNodeTypes;
|
21560 | }).call(this,require('_process'))
|
21561 | },{"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"react/lib/React":287}],222:[function(require,module,exports){
|
21562 | (function (process){
|
21563 | /**
|
21564 | * Copyright 2013-present, Facebook, Inc.
|
21565 | * All rights reserved.
|
21566 | *
|
21567 | * This source code is licensed under the BSD-style license found in the
|
21568 | * LICENSE file in the root directory of this source tree. An additional grant
|
21569 | * of patent rights can be found in the PATENTS file in the same directory.
|
21570 | *
|
21571 | *
|
21572 | */
|
21573 |
|
21574 | 'use strict';
|
21575 |
|
21576 | var _prodInvariant = require('./reactProdInvariant');
|
21577 |
|
21578 | var invariant = require('fbjs/lib/invariant');
|
21579 |
|
21580 | /**
|
21581 | * @param {?object} object
|
21582 | * @return {boolean} True if `object` is a valid owner.
|
21583 | * @final
|
21584 | */
|
21585 | function isValidOwner(object) {
|
21586 | return !!(object && typeof object.attachRef === 'function' && typeof object.detachRef === 'function');
|
21587 | }
|
21588 |
|
21589 | /**
|
21590 | * ReactOwners are capable of storing references to owned components.
|
21591 | *
|
21592 | * All components are capable of //being// referenced by owner components, but
|
21593 | * only ReactOwner components are capable of //referencing// owned components.
|
21594 | * The named reference is known as a "ref".
|
21595 | *
|
21596 | * Refs are available when mounted and updated during reconciliation.
|
21597 | *
|
21598 | * var MyComponent = React.createClass({
|
21599 | * render: function() {
|
21600 | * return (
|
21601 | * <div onClick={this.handleClick}>
|
21602 | * <CustomComponent ref="custom" />
|
21603 | * </div>
|
21604 | * );
|
21605 | * },
|
21606 | * handleClick: function() {
|
21607 | * this.refs.custom.handleClick();
|
21608 | * },
|
21609 | * componentDidMount: function() {
|
21610 | * this.refs.custom.initialize();
|
21611 | * }
|
21612 | * });
|
21613 | *
|
21614 | * Refs should rarely be used. When refs are used, they should only be done to
|
21615 | * control data that is not handled by React's data flow.
|
21616 | *
|
21617 | * @class ReactOwner
|
21618 | */
|
21619 | var ReactOwner = {
|
21620 | /**
|
21621 | * Adds a component by ref to an owner component.
|
21622 | *
|
21623 | * @param {ReactComponent} component Component to reference.
|
21624 | * @param {string} ref Name by which to refer to the component.
|
21625 | * @param {ReactOwner} owner Component on which to record the ref.
|
21626 | * @final
|
21627 | * @internal
|
21628 | */
|
21629 | addComponentAsRefTo: function (component, ref, owner) {
|
21630 | !isValidOwner(owner) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component\'s `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).') : _prodInvariant('119') : void 0;
|
21631 | owner.attachRef(ref, component);
|
21632 | },
|
21633 |
|
21634 | /**
|
21635 | * Removes a component by ref from an owner component.
|
21636 | *
|
21637 | * @param {ReactComponent} component Component to dereference.
|
21638 | * @param {string} ref Name of the ref to remove.
|
21639 | * @param {ReactOwner} owner Component on which the ref is recorded.
|
21640 | * @final
|
21641 | * @internal
|
21642 | */
|
21643 | removeComponentAsRefFrom: function (component, ref, owner) {
|
21644 | !isValidOwner(owner) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'removeComponentAsRefFrom(...): Only a ReactOwner can have refs. You might be removing a ref to a component that was not created inside a component\'s `render` method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).') : _prodInvariant('120') : void 0;
|
21645 | var ownerPublicInstance = owner.getPublicInstance();
|
21646 | // Check that `component`'s owner is still alive and that `component` is still the current ref
|
21647 | // because we do not want to detach the ref if another component stole it.
|
21648 | if (ownerPublicInstance && ownerPublicInstance.refs[ref] === component.getPublicInstance()) {
|
21649 | owner.detachRef(ref);
|
21650 | }
|
21651 | }
|
21652 |
|
21653 | };
|
21654 |
|
21655 | module.exports = ReactOwner;
|
21656 | }).call(this,require('_process'))
|
21657 | },{"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],223:[function(require,module,exports){
|
21658 | (function (process){
|
21659 | /**
|
21660 | * Copyright 2013-present, Facebook, Inc.
|
21661 | * All rights reserved.
|
21662 | *
|
21663 | * This source code is licensed under the BSD-style license found in the
|
21664 | * LICENSE file in the root directory of this source tree. An additional grant
|
21665 | * of patent rights can be found in the PATENTS file in the same directory.
|
21666 | *
|
21667 | *
|
21668 | */
|
21669 |
|
21670 | 'use strict';
|
21671 |
|
21672 | var ReactPropTypeLocationNames = {};
|
21673 |
|
21674 | if (process.env.NODE_ENV !== 'production') {
|
21675 | ReactPropTypeLocationNames = {
|
21676 | prop: 'prop',
|
21677 | context: 'context',
|
21678 | childContext: 'child context'
|
21679 | };
|
21680 | }
|
21681 |
|
21682 | module.exports = ReactPropTypeLocationNames;
|
21683 | }).call(this,require('_process'))
|
21684 | },{"_process":144}],224:[function(require,module,exports){
|
21685 | /**
|
21686 | * Copyright 2013-present, Facebook, Inc.
|
21687 | * All rights reserved.
|
21688 | *
|
21689 | * This source code is licensed under the BSD-style license found in the
|
21690 | * LICENSE file in the root directory of this source tree. An additional grant
|
21691 | * of patent rights can be found in the PATENTS file in the same directory.
|
21692 | *
|
21693 | *
|
21694 | */
|
21695 |
|
21696 | 'use strict';
|
21697 |
|
21698 | var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
21699 |
|
21700 | module.exports = ReactPropTypesSecret;
|
21701 | },{}],225:[function(require,module,exports){
|
21702 | (function (process){
|
21703 | /**
|
21704 | * Copyright 2013-present, Facebook, Inc.
|
21705 | * All rights reserved.
|
21706 | *
|
21707 | * This source code is licensed under the BSD-style license found in the
|
21708 | * LICENSE file in the root directory of this source tree. An additional grant
|
21709 | * of patent rights can be found in the PATENTS file in the same directory.
|
21710 | *
|
21711 | */
|
21712 |
|
21713 | 'use strict';
|
21714 |
|
21715 | var _assign = require('object-assign');
|
21716 |
|
21717 | var CallbackQueue = require('./CallbackQueue');
|
21718 | var PooledClass = require('./PooledClass');
|
21719 | var ReactBrowserEventEmitter = require('./ReactBrowserEventEmitter');
|
21720 | var ReactInputSelection = require('./ReactInputSelection');
|
21721 | var ReactInstrumentation = require('./ReactInstrumentation');
|
21722 | var Transaction = require('./Transaction');
|
21723 | var ReactUpdateQueue = require('./ReactUpdateQueue');
|
21724 |
|
21725 | /**
|
21726 | * Ensures that, when possible, the selection range (currently selected text
|
21727 | * input) is not disturbed by performing the transaction.
|
21728 | */
|
21729 | var SELECTION_RESTORATION = {
|
21730 | /**
|
21731 | * @return {Selection} Selection information.
|
21732 | */
|
21733 | initialize: ReactInputSelection.getSelectionInformation,
|
21734 | /**
|
21735 | * @param {Selection} sel Selection information returned from `initialize`.
|
21736 | */
|
21737 | close: ReactInputSelection.restoreSelection
|
21738 | };
|
21739 |
|
21740 | /**
|
21741 | * Suppresses events (blur/focus) that could be inadvertently dispatched due to
|
21742 | * high level DOM manipulations (like temporarily removing a text input from the
|
21743 | * DOM).
|
21744 | */
|
21745 | var EVENT_SUPPRESSION = {
|
21746 | /**
|
21747 | * @return {boolean} The enabled status of `ReactBrowserEventEmitter` before
|
21748 | * the reconciliation.
|
21749 | */
|
21750 | initialize: function () {
|
21751 | var currentlyEnabled = ReactBrowserEventEmitter.isEnabled();
|
21752 | ReactBrowserEventEmitter.setEnabled(false);
|
21753 | return currentlyEnabled;
|
21754 | },
|
21755 |
|
21756 | /**
|
21757 | * @param {boolean} previouslyEnabled Enabled status of
|
21758 | * `ReactBrowserEventEmitter` before the reconciliation occurred. `close`
|
21759 | * restores the previous value.
|
21760 | */
|
21761 | close: function (previouslyEnabled) {
|
21762 | ReactBrowserEventEmitter.setEnabled(previouslyEnabled);
|
21763 | }
|
21764 | };
|
21765 |
|
21766 | /**
|
21767 | * Provides a queue for collecting `componentDidMount` and
|
21768 | * `componentDidUpdate` callbacks during the transaction.
|
21769 | */
|
21770 | var ON_DOM_READY_QUEUEING = {
|
21771 | /**
|
21772 | * Initializes the internal `onDOMReady` queue.
|
21773 | */
|
21774 | initialize: function () {
|
21775 | this.reactMountReady.reset();
|
21776 | },
|
21777 |
|
21778 | /**
|
21779 | * After DOM is flushed, invoke all registered `onDOMReady` callbacks.
|
21780 | */
|
21781 | close: function () {
|
21782 | this.reactMountReady.notifyAll();
|
21783 | }
|
21784 | };
|
21785 |
|
21786 | /**
|
21787 | * Executed within the scope of the `Transaction` instance. Consider these as
|
21788 | * being member methods, but with an implied ordering while being isolated from
|
21789 | * each other.
|
21790 | */
|
21791 | var TRANSACTION_WRAPPERS = [SELECTION_RESTORATION, EVENT_SUPPRESSION, ON_DOM_READY_QUEUEING];
|
21792 |
|
21793 | if (process.env.NODE_ENV !== 'production') {
|
21794 | TRANSACTION_WRAPPERS.push({
|
21795 | initialize: ReactInstrumentation.debugTool.onBeginFlush,
|
21796 | close: ReactInstrumentation.debugTool.onEndFlush
|
21797 | });
|
21798 | }
|
21799 |
|
21800 | /**
|
21801 | * Currently:
|
21802 | * - The order that these are listed in the transaction is critical:
|
21803 | * - Suppresses events.
|
21804 | * - Restores selection range.
|
21805 | *
|
21806 | * Future:
|
21807 | * - Restore document/overflow scroll positions that were unintentionally
|
21808 | * modified via DOM insertions above the top viewport boundary.
|
21809 | * - Implement/integrate with customized constraint based layout system and keep
|
21810 | * track of which dimensions must be remeasured.
|
21811 | *
|
21812 | * @class ReactReconcileTransaction
|
21813 | */
|
21814 | function ReactReconcileTransaction(useCreateElement) {
|
21815 | this.reinitializeTransaction();
|
21816 | // Only server-side rendering really needs this option (see
|
21817 | // `ReactServerRendering`), but server-side uses
|
21818 | // `ReactServerRenderingTransaction` instead. This option is here so that it's
|
21819 | // accessible and defaults to false when `ReactDOMComponent` and
|
21820 | // `ReactDOMTextComponent` checks it in `mountComponent`.`
|
21821 | this.renderToStaticMarkup = false;
|
21822 | this.reactMountReady = CallbackQueue.getPooled(null);
|
21823 | this.useCreateElement = useCreateElement;
|
21824 | }
|
21825 |
|
21826 | var Mixin = {
|
21827 | /**
|
21828 | * @see Transaction
|
21829 | * @abstract
|
21830 | * @final
|
21831 | * @return {array<object>} List of operation wrap procedures.
|
21832 | * TODO: convert to array<TransactionWrapper>
|
21833 | */
|
21834 | getTransactionWrappers: function () {
|
21835 | return TRANSACTION_WRAPPERS;
|
21836 | },
|
21837 |
|
21838 | /**
|
21839 | * @return {object} The queue to collect `onDOMReady` callbacks with.
|
21840 | */
|
21841 | getReactMountReady: function () {
|
21842 | return this.reactMountReady;
|
21843 | },
|
21844 |
|
21845 | /**
|
21846 | * @return {object} The queue to collect React async events.
|
21847 | */
|
21848 | getUpdateQueue: function () {
|
21849 | return ReactUpdateQueue;
|
21850 | },
|
21851 |
|
21852 | /**
|
21853 | * Save current transaction state -- if the return value from this method is
|
21854 | * passed to `rollback`, the transaction will be reset to that state.
|
21855 | */
|
21856 | checkpoint: function () {
|
21857 | // reactMountReady is the our only stateful wrapper
|
21858 | return this.reactMountReady.checkpoint();
|
21859 | },
|
21860 |
|
21861 | rollback: function (checkpoint) {
|
21862 | this.reactMountReady.rollback(checkpoint);
|
21863 | },
|
21864 |
|
21865 | /**
|
21866 | * `PooledClass` looks for this, and will invoke this before allowing this
|
21867 | * instance to be reused.
|
21868 | */
|
21869 | destructor: function () {
|
21870 | CallbackQueue.release(this.reactMountReady);
|
21871 | this.reactMountReady = null;
|
21872 | }
|
21873 | };
|
21874 |
|
21875 | _assign(ReactReconcileTransaction.prototype, Transaction, Mixin);
|
21876 |
|
21877 | PooledClass.addPoolingTo(ReactReconcileTransaction);
|
21878 |
|
21879 | module.exports = ReactReconcileTransaction;
|
21880 | }).call(this,require('_process'))
|
21881 | },{"./CallbackQueue":159,"./PooledClass":177,"./ReactBrowserEventEmitter":178,"./ReactInputSelection":214,"./ReactInstrumentation":216,"./ReactUpdateQueue":232,"./Transaction":251,"_process":144,"object-assign":143}],226:[function(require,module,exports){
|
21882 | (function (process){
|
21883 | /**
|
21884 | * Copyright 2013-present, Facebook, Inc.
|
21885 | * All rights reserved.
|
21886 | *
|
21887 | * This source code is licensed under the BSD-style license found in the
|
21888 | * LICENSE file in the root directory of this source tree. An additional grant
|
21889 | * of patent rights can be found in the PATENTS file in the same directory.
|
21890 | *
|
21891 | */
|
21892 |
|
21893 | 'use strict';
|
21894 |
|
21895 | var ReactRef = require('./ReactRef');
|
21896 | var ReactInstrumentation = require('./ReactInstrumentation');
|
21897 |
|
21898 | var warning = require('fbjs/lib/warning');
|
21899 |
|
21900 | /**
|
21901 | * Helper to call ReactRef.attachRefs with this composite component, split out
|
21902 | * to avoid allocations in the transaction mount-ready queue.
|
21903 | */
|
21904 | function attachRefs() {
|
21905 | ReactRef.attachRefs(this, this._currentElement);
|
21906 | }
|
21907 |
|
21908 | var ReactReconciler = {
|
21909 |
|
21910 | /**
|
21911 | * Initializes the component, renders markup, and registers event listeners.
|
21912 | *
|
21913 | * @param {ReactComponent} internalInstance
|
21914 | * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
21915 | * @param {?object} the containing host component instance
|
21916 | * @param {?object} info about the host container
|
21917 | * @return {?string} Rendered markup to be inserted into the DOM.
|
21918 | * @final
|
21919 | * @internal
|
21920 | */
|
21921 | mountComponent: function (internalInstance, transaction, hostParent, hostContainerInfo, context, parentDebugID // 0 in production and for roots
|
21922 | ) {
|
21923 | if (process.env.NODE_ENV !== 'production') {
|
21924 | if (internalInstance._debugID !== 0) {
|
21925 | ReactInstrumentation.debugTool.onBeforeMountComponent(internalInstance._debugID, internalInstance._currentElement, parentDebugID);
|
21926 | }
|
21927 | }
|
21928 | var markup = internalInstance.mountComponent(transaction, hostParent, hostContainerInfo, context, parentDebugID);
|
21929 | if (internalInstance._currentElement && internalInstance._currentElement.ref != null) {
|
21930 | transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
|
21931 | }
|
21932 | if (process.env.NODE_ENV !== 'production') {
|
21933 | if (internalInstance._debugID !== 0) {
|
21934 | ReactInstrumentation.debugTool.onMountComponent(internalInstance._debugID);
|
21935 | }
|
21936 | }
|
21937 | return markup;
|
21938 | },
|
21939 |
|
21940 | /**
|
21941 | * Returns a value that can be passed to
|
21942 | * ReactComponentEnvironment.replaceNodeWithMarkup.
|
21943 | */
|
21944 | getHostNode: function (internalInstance) {
|
21945 | return internalInstance.getHostNode();
|
21946 | },
|
21947 |
|
21948 | /**
|
21949 | * Releases any resources allocated by `mountComponent`.
|
21950 | *
|
21951 | * @final
|
21952 | * @internal
|
21953 | */
|
21954 | unmountComponent: function (internalInstance, safely) {
|
21955 | if (process.env.NODE_ENV !== 'production') {
|
21956 | if (internalInstance._debugID !== 0) {
|
21957 | ReactInstrumentation.debugTool.onBeforeUnmountComponent(internalInstance._debugID);
|
21958 | }
|
21959 | }
|
21960 | ReactRef.detachRefs(internalInstance, internalInstance._currentElement);
|
21961 | internalInstance.unmountComponent(safely);
|
21962 | if (process.env.NODE_ENV !== 'production') {
|
21963 | if (internalInstance._debugID !== 0) {
|
21964 | ReactInstrumentation.debugTool.onUnmountComponent(internalInstance._debugID);
|
21965 | }
|
21966 | }
|
21967 | },
|
21968 |
|
21969 | /**
|
21970 | * Update a component using a new element.
|
21971 | *
|
21972 | * @param {ReactComponent} internalInstance
|
21973 | * @param {ReactElement} nextElement
|
21974 | * @param {ReactReconcileTransaction} transaction
|
21975 | * @param {object} context
|
21976 | * @internal
|
21977 | */
|
21978 | receiveComponent: function (internalInstance, nextElement, transaction, context) {
|
21979 | var prevElement = internalInstance._currentElement;
|
21980 |
|
21981 | if (nextElement === prevElement && context === internalInstance._context) {
|
21982 | // Since elements are immutable after the owner is rendered,
|
21983 | // we can do a cheap identity compare here to determine if this is a
|
21984 | // superfluous reconcile. It's possible for state to be mutable but such
|
21985 | // change should trigger an update of the owner which would recreate
|
21986 | // the element. We explicitly check for the existence of an owner since
|
21987 | // it's possible for an element created outside a composite to be
|
21988 | // deeply mutated and reused.
|
21989 |
|
21990 | // TODO: Bailing out early is just a perf optimization right?
|
21991 | // TODO: Removing the return statement should affect correctness?
|
21992 | return;
|
21993 | }
|
21994 |
|
21995 | if (process.env.NODE_ENV !== 'production') {
|
21996 | if (internalInstance._debugID !== 0) {
|
21997 | ReactInstrumentation.debugTool.onBeforeUpdateComponent(internalInstance._debugID, nextElement);
|
21998 | }
|
21999 | }
|
22000 |
|
22001 | var refsChanged = ReactRef.shouldUpdateRefs(prevElement, nextElement);
|
22002 |
|
22003 | if (refsChanged) {
|
22004 | ReactRef.detachRefs(internalInstance, prevElement);
|
22005 | }
|
22006 |
|
22007 | internalInstance.receiveComponent(nextElement, transaction, context);
|
22008 |
|
22009 | if (refsChanged && internalInstance._currentElement && internalInstance._currentElement.ref != null) {
|
22010 | transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
|
22011 | }
|
22012 |
|
22013 | if (process.env.NODE_ENV !== 'production') {
|
22014 | if (internalInstance._debugID !== 0) {
|
22015 | ReactInstrumentation.debugTool.onUpdateComponent(internalInstance._debugID);
|
22016 | }
|
22017 | }
|
22018 | },
|
22019 |
|
22020 | /**
|
22021 | * Flush any dirty changes in a component.
|
22022 | *
|
22023 | * @param {ReactComponent} internalInstance
|
22024 | * @param {ReactReconcileTransaction} transaction
|
22025 | * @internal
|
22026 | */
|
22027 | performUpdateIfNecessary: function (internalInstance, transaction, updateBatchNumber) {
|
22028 | if (internalInstance._updateBatchNumber !== updateBatchNumber) {
|
22029 | // The component's enqueued batch number should always be the current
|
22030 | // batch or the following one.
|
22031 | process.env.NODE_ENV !== 'production' ? warning(internalInstance._updateBatchNumber == null || internalInstance._updateBatchNumber === updateBatchNumber + 1, 'performUpdateIfNecessary: Unexpected batch number (current %s, ' + 'pending %s)', updateBatchNumber, internalInstance._updateBatchNumber) : void 0;
|
22032 | return;
|
22033 | }
|
22034 | if (process.env.NODE_ENV !== 'production') {
|
22035 | if (internalInstance._debugID !== 0) {
|
22036 | ReactInstrumentation.debugTool.onBeforeUpdateComponent(internalInstance._debugID, internalInstance._currentElement);
|
22037 | }
|
22038 | }
|
22039 | internalInstance.performUpdateIfNecessary(transaction);
|
22040 | if (process.env.NODE_ENV !== 'production') {
|
22041 | if (internalInstance._debugID !== 0) {
|
22042 | ReactInstrumentation.debugTool.onUpdateComponent(internalInstance._debugID);
|
22043 | }
|
22044 | }
|
22045 | }
|
22046 |
|
22047 | };
|
22048 |
|
22049 | module.exports = ReactReconciler;
|
22050 | }).call(this,require('_process'))
|
22051 | },{"./ReactInstrumentation":216,"./ReactRef":227,"_process":144,"fbjs/lib/warning":131}],227:[function(require,module,exports){
|
22052 | /**
|
22053 | * Copyright 2013-present, Facebook, Inc.
|
22054 | * All rights reserved.
|
22055 | *
|
22056 | * This source code is licensed under the BSD-style license found in the
|
22057 | * LICENSE file in the root directory of this source tree. An additional grant
|
22058 | * of patent rights can be found in the PATENTS file in the same directory.
|
22059 | *
|
22060 | *
|
22061 | */
|
22062 |
|
22063 | 'use strict';
|
22064 |
|
22065 | var ReactOwner = require('./ReactOwner');
|
22066 |
|
22067 | var ReactRef = {};
|
22068 |
|
22069 | function attachRef(ref, component, owner) {
|
22070 | if (typeof ref === 'function') {
|
22071 | ref(component.getPublicInstance());
|
22072 | } else {
|
22073 | // Legacy ref
|
22074 | ReactOwner.addComponentAsRefTo(component, ref, owner);
|
22075 | }
|
22076 | }
|
22077 |
|
22078 | function detachRef(ref, component, owner) {
|
22079 | if (typeof ref === 'function') {
|
22080 | ref(null);
|
22081 | } else {
|
22082 | // Legacy ref
|
22083 | ReactOwner.removeComponentAsRefFrom(component, ref, owner);
|
22084 | }
|
22085 | }
|
22086 |
|
22087 | ReactRef.attachRefs = function (instance, element) {
|
22088 | if (element === null || typeof element !== 'object') {
|
22089 | return;
|
22090 | }
|
22091 | var ref = element.ref;
|
22092 | if (ref != null) {
|
22093 | attachRef(ref, instance, element._owner);
|
22094 | }
|
22095 | };
|
22096 |
|
22097 | ReactRef.shouldUpdateRefs = function (prevElement, nextElement) {
|
22098 | // If either the owner or a `ref` has changed, make sure the newest owner
|
22099 | // has stored a reference to `this`, and the previous owner (if different)
|
22100 | // has forgotten the reference to `this`. We use the element instead
|
22101 | // of the public this.props because the post processing cannot determine
|
22102 | // a ref. The ref conceptually lives on the element.
|
22103 |
|
22104 | // TODO: Should this even be possible? The owner cannot change because
|
22105 | // it's forbidden by shouldUpdateReactComponent. The ref can change
|
22106 | // if you swap the keys of but not the refs. Reconsider where this check
|
22107 | // is made. It probably belongs where the key checking and
|
22108 | // instantiateReactComponent is done.
|
22109 |
|
22110 | var prevRef = null;
|
22111 | var prevOwner = null;
|
22112 | if (prevElement !== null && typeof prevElement === 'object') {
|
22113 | prevRef = prevElement.ref;
|
22114 | prevOwner = prevElement._owner;
|
22115 | }
|
22116 |
|
22117 | var nextRef = null;
|
22118 | var nextOwner = null;
|
22119 | if (nextElement !== null && typeof nextElement === 'object') {
|
22120 | nextRef = nextElement.ref;
|
22121 | nextOwner = nextElement._owner;
|
22122 | }
|
22123 |
|
22124 | return prevRef !== nextRef ||
|
22125 | // If owner changes but we have an unchanged function ref, don't update refs
|
22126 | typeof nextRef === 'string' && nextOwner !== prevOwner;
|
22127 | };
|
22128 |
|
22129 | ReactRef.detachRefs = function (instance, element) {
|
22130 | if (element === null || typeof element !== 'object') {
|
22131 | return;
|
22132 | }
|
22133 | var ref = element.ref;
|
22134 | if (ref != null) {
|
22135 | detachRef(ref, instance, element._owner);
|
22136 | }
|
22137 | };
|
22138 |
|
22139 | module.exports = ReactRef;
|
22140 | },{"./ReactOwner":222}],228:[function(require,module,exports){
|
22141 | /**
|
22142 | * Copyright 2014-present, Facebook, Inc.
|
22143 | * All rights reserved.
|
22144 | *
|
22145 | * This source code is licensed under the BSD-style license found in the
|
22146 | * LICENSE file in the root directory of this source tree. An additional grant
|
22147 | * of patent rights can be found in the PATENTS file in the same directory.
|
22148 | *
|
22149 | */
|
22150 |
|
22151 | 'use strict';
|
22152 |
|
22153 | var ReactServerBatchingStrategy = {
|
22154 | isBatchingUpdates: false,
|
22155 | batchedUpdates: function (callback) {
|
22156 | // Don't do anything here. During the server rendering we don't want to
|
22157 | // schedule any updates. We will simply ignore them.
|
22158 | }
|
22159 | };
|
22160 |
|
22161 | module.exports = ReactServerBatchingStrategy;
|
22162 | },{}],229:[function(require,module,exports){
|
22163 | (function (process){
|
22164 | /**
|
22165 | * Copyright 2013-present, Facebook, Inc.
|
22166 | * All rights reserved.
|
22167 | *
|
22168 | * This source code is licensed under the BSD-style license found in the
|
22169 | * LICENSE file in the root directory of this source tree. An additional grant
|
22170 | * of patent rights can be found in the PATENTS file in the same directory.
|
22171 | *
|
22172 | */
|
22173 | 'use strict';
|
22174 |
|
22175 | var _prodInvariant = require('./reactProdInvariant');
|
22176 |
|
22177 | var React = require('react/lib/React');
|
22178 | var ReactDOMContainerInfo = require('./ReactDOMContainerInfo');
|
22179 | var ReactDefaultBatchingStrategy = require('./ReactDefaultBatchingStrategy');
|
22180 | var ReactInstrumentation = require('./ReactInstrumentation');
|
22181 | var ReactMarkupChecksum = require('./ReactMarkupChecksum');
|
22182 | var ReactReconciler = require('./ReactReconciler');
|
22183 | var ReactServerBatchingStrategy = require('./ReactServerBatchingStrategy');
|
22184 | var ReactServerRenderingTransaction = require('./ReactServerRenderingTransaction');
|
22185 | var ReactUpdates = require('./ReactUpdates');
|
22186 |
|
22187 | var emptyObject = require('fbjs/lib/emptyObject');
|
22188 | var instantiateReactComponent = require('./instantiateReactComponent');
|
22189 | var invariant = require('fbjs/lib/invariant');
|
22190 |
|
22191 | var pendingTransactions = 0;
|
22192 |
|
22193 | /**
|
22194 | * @param {ReactElement} element
|
22195 | * @return {string} the HTML markup
|
22196 | */
|
22197 | function renderToStringImpl(element, makeStaticMarkup) {
|
22198 | var transaction;
|
22199 | try {
|
22200 | ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy);
|
22201 |
|
22202 | transaction = ReactServerRenderingTransaction.getPooled(makeStaticMarkup);
|
22203 |
|
22204 | pendingTransactions++;
|
22205 |
|
22206 | return transaction.perform(function () {
|
22207 | var componentInstance = instantiateReactComponent(element, true);
|
22208 | var markup = ReactReconciler.mountComponent(componentInstance, transaction, null, ReactDOMContainerInfo(), emptyObject, 0 /* parentDebugID */
|
22209 | );
|
22210 | if (process.env.NODE_ENV !== 'production') {
|
22211 | ReactInstrumentation.debugTool.onUnmountComponent(componentInstance._debugID);
|
22212 | }
|
22213 | if (!makeStaticMarkup) {
|
22214 | markup = ReactMarkupChecksum.addChecksumToMarkup(markup);
|
22215 | }
|
22216 | return markup;
|
22217 | }, null);
|
22218 | } finally {
|
22219 | pendingTransactions--;
|
22220 | ReactServerRenderingTransaction.release(transaction);
|
22221 | // Revert to the DOM batching strategy since these two renderers
|
22222 | // currently share these stateful modules.
|
22223 | if (!pendingTransactions) {
|
22224 | ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
|
22225 | }
|
22226 | }
|
22227 | }
|
22228 |
|
22229 | /**
|
22230 | * Render a ReactElement to its initial HTML. This should only be used on the
|
22231 | * server.
|
22232 | * See https://facebook.github.io/react/docs/top-level-api.html#reactdomserver.rendertostring
|
22233 | */
|
22234 | function renderToString(element) {
|
22235 | !React.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'renderToString(): You must pass a valid ReactElement.') : _prodInvariant('46') : void 0;
|
22236 | return renderToStringImpl(element, false);
|
22237 | }
|
22238 |
|
22239 | /**
|
22240 | * Similar to renderToString, except this doesn't create extra DOM attributes
|
22241 | * such as data-react-id that React uses internally.
|
22242 | * See https://facebook.github.io/react/docs/top-level-api.html#reactdomserver.rendertostaticmarkup
|
22243 | */
|
22244 | function renderToStaticMarkup(element) {
|
22245 | !React.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'renderToStaticMarkup(): You must pass a valid ReactElement.') : _prodInvariant('47') : void 0;
|
22246 | return renderToStringImpl(element, true);
|
22247 | }
|
22248 |
|
22249 | module.exports = {
|
22250 | renderToString: renderToString,
|
22251 | renderToStaticMarkup: renderToStaticMarkup
|
22252 | };
|
22253 | }).call(this,require('_process'))
|
22254 | },{"./ReactDOMContainerInfo":187,"./ReactDefaultBatchingStrategy":203,"./ReactInstrumentation":216,"./ReactMarkupChecksum":218,"./ReactReconciler":226,"./ReactServerBatchingStrategy":228,"./ReactServerRenderingTransaction":230,"./ReactUpdates":233,"./instantiateReactComponent":272,"./reactProdInvariant":276,"_process":144,"fbjs/lib/emptyObject":117,"fbjs/lib/invariant":124,"react/lib/React":287}],230:[function(require,module,exports){
|
22255 | (function (process){
|
22256 | /**
|
22257 | * Copyright 2014-present, Facebook, Inc.
|
22258 | * All rights reserved.
|
22259 | *
|
22260 | * This source code is licensed under the BSD-style license found in the
|
22261 | * LICENSE file in the root directory of this source tree. An additional grant
|
22262 | * of patent rights can be found in the PATENTS file in the same directory.
|
22263 | *
|
22264 | */
|
22265 |
|
22266 | 'use strict';
|
22267 |
|
22268 | var _assign = require('object-assign');
|
22269 |
|
22270 | var PooledClass = require('./PooledClass');
|
22271 | var Transaction = require('./Transaction');
|
22272 | var ReactInstrumentation = require('./ReactInstrumentation');
|
22273 | var ReactServerUpdateQueue = require('./ReactServerUpdateQueue');
|
22274 |
|
22275 | /**
|
22276 | * Executed within the scope of the `Transaction` instance. Consider these as
|
22277 | * being member methods, but with an implied ordering while being isolated from
|
22278 | * each other.
|
22279 | */
|
22280 | var TRANSACTION_WRAPPERS = [];
|
22281 |
|
22282 | if (process.env.NODE_ENV !== 'production') {
|
22283 | TRANSACTION_WRAPPERS.push({
|
22284 | initialize: ReactInstrumentation.debugTool.onBeginFlush,
|
22285 | close: ReactInstrumentation.debugTool.onEndFlush
|
22286 | });
|
22287 | }
|
22288 |
|
22289 | var noopCallbackQueue = {
|
22290 | enqueue: function () {}
|
22291 | };
|
22292 |
|
22293 | /**
|
22294 | * @class ReactServerRenderingTransaction
|
22295 | * @param {boolean} renderToStaticMarkup
|
22296 | */
|
22297 | function ReactServerRenderingTransaction(renderToStaticMarkup) {
|
22298 | this.reinitializeTransaction();
|
22299 | this.renderToStaticMarkup = renderToStaticMarkup;
|
22300 | this.useCreateElement = false;
|
22301 | this.updateQueue = new ReactServerUpdateQueue(this);
|
22302 | }
|
22303 |
|
22304 | var Mixin = {
|
22305 | /**
|
22306 | * @see Transaction
|
22307 | * @abstract
|
22308 | * @final
|
22309 | * @return {array} Empty list of operation wrap procedures.
|
22310 | */
|
22311 | getTransactionWrappers: function () {
|
22312 | return TRANSACTION_WRAPPERS;
|
22313 | },
|
22314 |
|
22315 | /**
|
22316 | * @return {object} The queue to collect `onDOMReady` callbacks with.
|
22317 | */
|
22318 | getReactMountReady: function () {
|
22319 | return noopCallbackQueue;
|
22320 | },
|
22321 |
|
22322 | /**
|
22323 | * @return {object} The queue to collect React async events.
|
22324 | */
|
22325 | getUpdateQueue: function () {
|
22326 | return this.updateQueue;
|
22327 | },
|
22328 |
|
22329 | /**
|
22330 | * `PooledClass` looks for this, and will invoke this before allowing this
|
22331 | * instance to be reused.
|
22332 | */
|
22333 | destructor: function () {},
|
22334 |
|
22335 | checkpoint: function () {},
|
22336 |
|
22337 | rollback: function () {}
|
22338 | };
|
22339 |
|
22340 | _assign(ReactServerRenderingTransaction.prototype, Transaction, Mixin);
|
22341 |
|
22342 | PooledClass.addPoolingTo(ReactServerRenderingTransaction);
|
22343 |
|
22344 | module.exports = ReactServerRenderingTransaction;
|
22345 | }).call(this,require('_process'))
|
22346 | },{"./PooledClass":177,"./ReactInstrumentation":216,"./ReactServerUpdateQueue":231,"./Transaction":251,"_process":144,"object-assign":143}],231:[function(require,module,exports){
|
22347 | (function (process){
|
22348 | /**
|
22349 | * Copyright 2015-present, Facebook, Inc.
|
22350 | * All rights reserved.
|
22351 | *
|
22352 | * This source code is licensed under the BSD-style license found in the
|
22353 | * LICENSE file in the root directory of this source tree. An additional grant
|
22354 | * of patent rights can be found in the PATENTS file in the same directory.
|
22355 | *
|
22356 | *
|
22357 | */
|
22358 |
|
22359 | 'use strict';
|
22360 |
|
22361 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
22362 |
|
22363 | var ReactUpdateQueue = require('./ReactUpdateQueue');
|
22364 |
|
22365 | var warning = require('fbjs/lib/warning');
|
22366 |
|
22367 | function warnNoop(publicInstance, callerName) {
|
22368 | if (process.env.NODE_ENV !== 'production') {
|
22369 | var constructor = publicInstance.constructor;
|
22370 | process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): Can only update a mounting component. ' + 'This usually means you called %s() outside componentWillMount() on the server. ' + 'This is a no-op. Please check the code for the %s component.', callerName, callerName, constructor && (constructor.displayName || constructor.name) || 'ReactClass') : void 0;
|
22371 | }
|
22372 | }
|
22373 |
|
22374 | /**
|
22375 | * This is the update queue used for server rendering.
|
22376 | * It delegates to ReactUpdateQueue while server rendering is in progress and
|
22377 | * switches to ReactNoopUpdateQueue after the transaction has completed.
|
22378 | * @class ReactServerUpdateQueue
|
22379 | * @param {Transaction} transaction
|
22380 | */
|
22381 |
|
22382 | var ReactServerUpdateQueue = function () {
|
22383 | function ReactServerUpdateQueue(transaction) {
|
22384 | _classCallCheck(this, ReactServerUpdateQueue);
|
22385 |
|
22386 | this.transaction = transaction;
|
22387 | }
|
22388 |
|
22389 | /**
|
22390 | * Checks whether or not this composite component is mounted.
|
22391 | * @param {ReactClass} publicInstance The instance we want to test.
|
22392 | * @return {boolean} True if mounted, false otherwise.
|
22393 | * @protected
|
22394 | * @final
|
22395 | */
|
22396 |
|
22397 |
|
22398 | ReactServerUpdateQueue.prototype.isMounted = function isMounted(publicInstance) {
|
22399 | return false;
|
22400 | };
|
22401 |
|
22402 | /**
|
22403 | * Enqueue a callback that will be executed after all the pending updates
|
22404 | * have processed.
|
22405 | *
|
22406 | * @param {ReactClass} publicInstance The instance to use as `this` context.
|
22407 | * @param {?function} callback Called after state is updated.
|
22408 | * @internal
|
22409 | */
|
22410 |
|
22411 |
|
22412 | ReactServerUpdateQueue.prototype.enqueueCallback = function enqueueCallback(publicInstance, callback, callerName) {
|
22413 | if (this.transaction.isInTransaction()) {
|
22414 | ReactUpdateQueue.enqueueCallback(publicInstance, callback, callerName);
|
22415 | }
|
22416 | };
|
22417 |
|
22418 | /**
|
22419 | * Forces an update. This should only be invoked when it is known with
|
22420 | * certainty that we are **not** in a DOM transaction.
|
22421 | *
|
22422 | * You may want to call this when you know that some deeper aspect of the
|
22423 | * component's state has changed but `setState` was not called.
|
22424 | *
|
22425 | * This will not invoke `shouldComponentUpdate`, but it will invoke
|
22426 | * `componentWillUpdate` and `componentDidUpdate`.
|
22427 | *
|
22428 | * @param {ReactClass} publicInstance The instance that should rerender.
|
22429 | * @internal
|
22430 | */
|
22431 |
|
22432 |
|
22433 | ReactServerUpdateQueue.prototype.enqueueForceUpdate = function enqueueForceUpdate(publicInstance) {
|
22434 | if (this.transaction.isInTransaction()) {
|
22435 | ReactUpdateQueue.enqueueForceUpdate(publicInstance);
|
22436 | } else {
|
22437 | warnNoop(publicInstance, 'forceUpdate');
|
22438 | }
|
22439 | };
|
22440 |
|
22441 | /**
|
22442 | * Replaces all of the state. Always use this or `setState` to mutate state.
|
22443 | * You should treat `this.state` as immutable.
|
22444 | *
|
22445 | * There is no guarantee that `this.state` will be immediately updated, so
|
22446 | * accessing `this.state` after calling this method may return the old value.
|
22447 | *
|
22448 | * @param {ReactClass} publicInstance The instance that should rerender.
|
22449 | * @param {object|function} completeState Next state.
|
22450 | * @internal
|
22451 | */
|
22452 |
|
22453 |
|
22454 | ReactServerUpdateQueue.prototype.enqueueReplaceState = function enqueueReplaceState(publicInstance, completeState) {
|
22455 | if (this.transaction.isInTransaction()) {
|
22456 | ReactUpdateQueue.enqueueReplaceState(publicInstance, completeState);
|
22457 | } else {
|
22458 | warnNoop(publicInstance, 'replaceState');
|
22459 | }
|
22460 | };
|
22461 |
|
22462 | /**
|
22463 | * Sets a subset of the state. This only exists because _pendingState is
|
22464 | * internal. This provides a merging strategy that is not available to deep
|
22465 | * properties which is confusing. TODO: Expose pendingState or don't use it
|
22466 | * during the merge.
|
22467 | *
|
22468 | * @param {ReactClass} publicInstance The instance that should rerender.
|
22469 | * @param {object|function} partialState Next partial state to be merged with state.
|
22470 | * @internal
|
22471 | */
|
22472 |
|
22473 |
|
22474 | ReactServerUpdateQueue.prototype.enqueueSetState = function enqueueSetState(publicInstance, partialState) {
|
22475 | if (this.transaction.isInTransaction()) {
|
22476 | ReactUpdateQueue.enqueueSetState(publicInstance, partialState);
|
22477 | } else {
|
22478 | warnNoop(publicInstance, 'setState');
|
22479 | }
|
22480 | };
|
22481 |
|
22482 | return ReactServerUpdateQueue;
|
22483 | }();
|
22484 |
|
22485 | module.exports = ReactServerUpdateQueue;
|
22486 | }).call(this,require('_process'))
|
22487 | },{"./ReactUpdateQueue":232,"_process":144,"fbjs/lib/warning":131}],232:[function(require,module,exports){
|
22488 | (function (process){
|
22489 | /**
|
22490 | * Copyright 2015-present, Facebook, Inc.
|
22491 | * All rights reserved.
|
22492 | *
|
22493 | * This source code is licensed under the BSD-style license found in the
|
22494 | * LICENSE file in the root directory of this source tree. An additional grant
|
22495 | * of patent rights can be found in the PATENTS file in the same directory.
|
22496 | *
|
22497 | */
|
22498 |
|
22499 | 'use strict';
|
22500 |
|
22501 | var _prodInvariant = require('./reactProdInvariant');
|
22502 |
|
22503 | var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
22504 | var ReactInstanceMap = require('./ReactInstanceMap');
|
22505 | var ReactInstrumentation = require('./ReactInstrumentation');
|
22506 | var ReactUpdates = require('./ReactUpdates');
|
22507 |
|
22508 | var invariant = require('fbjs/lib/invariant');
|
22509 | var warning = require('fbjs/lib/warning');
|
22510 |
|
22511 | function enqueueUpdate(internalInstance) {
|
22512 | ReactUpdates.enqueueUpdate(internalInstance);
|
22513 | }
|
22514 |
|
22515 | function formatUnexpectedArgument(arg) {
|
22516 | var type = typeof arg;
|
22517 | if (type !== 'object') {
|
22518 | return type;
|
22519 | }
|
22520 | var displayName = arg.constructor && arg.constructor.name || type;
|
22521 | var keys = Object.keys(arg);
|
22522 | if (keys.length > 0 && keys.length < 20) {
|
22523 | return displayName + ' (keys: ' + keys.join(', ') + ')';
|
22524 | }
|
22525 | return displayName;
|
22526 | }
|
22527 |
|
22528 | function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
|
22529 | var internalInstance = ReactInstanceMap.get(publicInstance);
|
22530 | if (!internalInstance) {
|
22531 | if (process.env.NODE_ENV !== 'production') {
|
22532 | var ctor = publicInstance.constructor;
|
22533 | // Only warn when we have a callerName. Otherwise we should be silent.
|
22534 | // We're probably calling from enqueueCallback. We don't want to warn
|
22535 | // there because we already warned for the corresponding lifecycle method.
|
22536 | process.env.NODE_ENV !== 'production' ? warning(!callerName, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op. Please check the code for the %s component.', callerName, callerName, ctor && (ctor.displayName || ctor.name) || 'ReactClass') : void 0;
|
22537 | }
|
22538 | return null;
|
22539 | }
|
22540 |
|
22541 | if (process.env.NODE_ENV !== 'production') {
|
22542 | process.env.NODE_ENV !== 'production' ? warning(ReactCurrentOwner.current == null, '%s(...): Cannot update during an existing state transition (such as ' + 'within `render` or another component\'s constructor). Render methods ' + 'should be a pure function of props and state; constructor ' + 'side-effects are an anti-pattern, but can be moved to ' + '`componentWillMount`.', callerName) : void 0;
|
22543 | }
|
22544 |
|
22545 | return internalInstance;
|
22546 | }
|
22547 |
|
22548 | /**
|
22549 | * ReactUpdateQueue allows for state updates to be scheduled into a later
|
22550 | * reconciliation step.
|
22551 | */
|
22552 | var ReactUpdateQueue = {
|
22553 |
|
22554 | /**
|
22555 | * Checks whether or not this composite component is mounted.
|
22556 | * @param {ReactClass} publicInstance The instance we want to test.
|
22557 | * @return {boolean} True if mounted, false otherwise.
|
22558 | * @protected
|
22559 | * @final
|
22560 | */
|
22561 | isMounted: function (publicInstance) {
|
22562 | if (process.env.NODE_ENV !== 'production') {
|
22563 | var owner = ReactCurrentOwner.current;
|
22564 | if (owner !== null) {
|
22565 | process.env.NODE_ENV !== 'production' ? warning(owner._warnedAboutRefsInRender, '%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', owner.getName() || 'A component') : void 0;
|
22566 | owner._warnedAboutRefsInRender = true;
|
22567 | }
|
22568 | }
|
22569 | var internalInstance = ReactInstanceMap.get(publicInstance);
|
22570 | if (internalInstance) {
|
22571 | // During componentWillMount and render this will still be null but after
|
22572 | // that will always render to something. At least for now. So we can use
|
22573 | // this hack.
|
22574 | return !!internalInstance._renderedComponent;
|
22575 | } else {
|
22576 | return false;
|
22577 | }
|
22578 | },
|
22579 |
|
22580 | /**
|
22581 | * Enqueue a callback that will be executed after all the pending updates
|
22582 | * have processed.
|
22583 | *
|
22584 | * @param {ReactClass} publicInstance The instance to use as `this` context.
|
22585 | * @param {?function} callback Called after state is updated.
|
22586 | * @param {string} callerName Name of the calling function in the public API.
|
22587 | * @internal
|
22588 | */
|
22589 | enqueueCallback: function (publicInstance, callback, callerName) {
|
22590 | ReactUpdateQueue.validateCallback(callback, callerName);
|
22591 | var internalInstance = getInternalInstanceReadyForUpdate(publicInstance);
|
22592 |
|
22593 | // Previously we would throw an error if we didn't have an internal
|
22594 | // instance. Since we want to make it a no-op instead, we mirror the same
|
22595 | // behavior we have in other enqueue* methods.
|
22596 | // We also need to ignore callbacks in componentWillMount. See
|
22597 | // enqueueUpdates.
|
22598 | if (!internalInstance) {
|
22599 | return null;
|
22600 | }
|
22601 |
|
22602 | if (internalInstance._pendingCallbacks) {
|
22603 | internalInstance._pendingCallbacks.push(callback);
|
22604 | } else {
|
22605 | internalInstance._pendingCallbacks = [callback];
|
22606 | }
|
22607 | // TODO: The callback here is ignored when setState is called from
|
22608 | // componentWillMount. Either fix it or disallow doing so completely in
|
22609 | // favor of getInitialState. Alternatively, we can disallow
|
22610 | // componentWillMount during server-side rendering.
|
22611 | enqueueUpdate(internalInstance);
|
22612 | },
|
22613 |
|
22614 | enqueueCallbackInternal: function (internalInstance, callback) {
|
22615 | if (internalInstance._pendingCallbacks) {
|
22616 | internalInstance._pendingCallbacks.push(callback);
|
22617 | } else {
|
22618 | internalInstance._pendingCallbacks = [callback];
|
22619 | }
|
22620 | enqueueUpdate(internalInstance);
|
22621 | },
|
22622 |
|
22623 | /**
|
22624 | * Forces an update. This should only be invoked when it is known with
|
22625 | * certainty that we are **not** in a DOM transaction.
|
22626 | *
|
22627 | * You may want to call this when you know that some deeper aspect of the
|
22628 | * component's state has changed but `setState` was not called.
|
22629 | *
|
22630 | * This will not invoke `shouldComponentUpdate`, but it will invoke
|
22631 | * `componentWillUpdate` and `componentDidUpdate`.
|
22632 | *
|
22633 | * @param {ReactClass} publicInstance The instance that should rerender.
|
22634 | * @internal
|
22635 | */
|
22636 | enqueueForceUpdate: function (publicInstance) {
|
22637 | var internalInstance = getInternalInstanceReadyForUpdate(publicInstance, 'forceUpdate');
|
22638 |
|
22639 | if (!internalInstance) {
|
22640 | return;
|
22641 | }
|
22642 |
|
22643 | internalInstance._pendingForceUpdate = true;
|
22644 |
|
22645 | enqueueUpdate(internalInstance);
|
22646 | },
|
22647 |
|
22648 | /**
|
22649 | * Replaces all of the state. Always use this or `setState` to mutate state.
|
22650 | * You should treat `this.state` as immutable.
|
22651 | *
|
22652 | * There is no guarantee that `this.state` will be immediately updated, so
|
22653 | * accessing `this.state` after calling this method may return the old value.
|
22654 | *
|
22655 | * @param {ReactClass} publicInstance The instance that should rerender.
|
22656 | * @param {object} completeState Next state.
|
22657 | * @internal
|
22658 | */
|
22659 | enqueueReplaceState: function (publicInstance, completeState) {
|
22660 | var internalInstance = getInternalInstanceReadyForUpdate(publicInstance, 'replaceState');
|
22661 |
|
22662 | if (!internalInstance) {
|
22663 | return;
|
22664 | }
|
22665 |
|
22666 | internalInstance._pendingStateQueue = [completeState];
|
22667 | internalInstance._pendingReplaceState = true;
|
22668 |
|
22669 | enqueueUpdate(internalInstance);
|
22670 | },
|
22671 |
|
22672 | /**
|
22673 | * Sets a subset of the state. This only exists because _pendingState is
|
22674 | * internal. This provides a merging strategy that is not available to deep
|
22675 | * properties which is confusing. TODO: Expose pendingState or don't use it
|
22676 | * during the merge.
|
22677 | *
|
22678 | * @param {ReactClass} publicInstance The instance that should rerender.
|
22679 | * @param {object} partialState Next partial state to be merged with state.
|
22680 | * @internal
|
22681 | */
|
22682 | enqueueSetState: function (publicInstance, partialState) {
|
22683 | if (process.env.NODE_ENV !== 'production') {
|
22684 | ReactInstrumentation.debugTool.onSetState();
|
22685 | process.env.NODE_ENV !== 'production' ? warning(partialState != null, 'setState(...): You passed an undefined or null state object; ' + 'instead, use forceUpdate().') : void 0;
|
22686 | }
|
22687 |
|
22688 | var internalInstance = getInternalInstanceReadyForUpdate(publicInstance, 'setState');
|
22689 |
|
22690 | if (!internalInstance) {
|
22691 | return;
|
22692 | }
|
22693 |
|
22694 | var queue = internalInstance._pendingStateQueue || (internalInstance._pendingStateQueue = []);
|
22695 | queue.push(partialState);
|
22696 |
|
22697 | enqueueUpdate(internalInstance);
|
22698 | },
|
22699 |
|
22700 | enqueueElementInternal: function (internalInstance, nextElement, nextContext) {
|
22701 | internalInstance._pendingElement = nextElement;
|
22702 | // TODO: introduce _pendingContext instead of setting it directly.
|
22703 | internalInstance._context = nextContext;
|
22704 | enqueueUpdate(internalInstance);
|
22705 | },
|
22706 |
|
22707 | validateCallback: function (callback, callerName) {
|
22708 | !(!callback || typeof callback === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s(...): Expected the last optional `callback` argument to be a function. Instead received: %s.', callerName, formatUnexpectedArgument(callback)) : _prodInvariant('122', callerName, formatUnexpectedArgument(callback)) : void 0;
|
22709 | }
|
22710 |
|
22711 | };
|
22712 |
|
22713 | module.exports = ReactUpdateQueue;
|
22714 | }).call(this,require('_process'))
|
22715 | },{"./ReactInstanceMap":215,"./ReactInstrumentation":216,"./ReactUpdates":233,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131,"react/lib/ReactCurrentOwner":292}],233:[function(require,module,exports){
|
22716 | (function (process){
|
22717 | /**
|
22718 | * Copyright 2013-present, Facebook, Inc.
|
22719 | * All rights reserved.
|
22720 | *
|
22721 | * This source code is licensed under the BSD-style license found in the
|
22722 | * LICENSE file in the root directory of this source tree. An additional grant
|
22723 | * of patent rights can be found in the PATENTS file in the same directory.
|
22724 | *
|
22725 | */
|
22726 |
|
22727 | 'use strict';
|
22728 |
|
22729 | var _prodInvariant = require('./reactProdInvariant'),
|
22730 | _assign = require('object-assign');
|
22731 |
|
22732 | var CallbackQueue = require('./CallbackQueue');
|
22733 | var PooledClass = require('./PooledClass');
|
22734 | var ReactFeatureFlags = require('./ReactFeatureFlags');
|
22735 | var ReactReconciler = require('./ReactReconciler');
|
22736 | var Transaction = require('./Transaction');
|
22737 |
|
22738 | var invariant = require('fbjs/lib/invariant');
|
22739 |
|
22740 | var dirtyComponents = [];
|
22741 | var updateBatchNumber = 0;
|
22742 | var asapCallbackQueue = CallbackQueue.getPooled();
|
22743 | var asapEnqueued = false;
|
22744 |
|
22745 | var batchingStrategy = null;
|
22746 |
|
22747 | function ensureInjected() {
|
22748 | !(ReactUpdates.ReactReconcileTransaction && batchingStrategy) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactUpdates: must inject a reconcile transaction class and batching strategy') : _prodInvariant('123') : void 0;
|
22749 | }
|
22750 |
|
22751 | var NESTED_UPDATES = {
|
22752 | initialize: function () {
|
22753 | this.dirtyComponentsLength = dirtyComponents.length;
|
22754 | },
|
22755 | close: function () {
|
22756 | if (this.dirtyComponentsLength !== dirtyComponents.length) {
|
22757 | // Additional updates were enqueued by componentDidUpdate handlers or
|
22758 | // similar; before our own UPDATE_QUEUEING wrapper closes, we want to run
|
22759 | // these new updates so that if A's componentDidUpdate calls setState on
|
22760 | // B, B will update before the callback A's updater provided when calling
|
22761 | // setState.
|
22762 | dirtyComponents.splice(0, this.dirtyComponentsLength);
|
22763 | flushBatchedUpdates();
|
22764 | } else {
|
22765 | dirtyComponents.length = 0;
|
22766 | }
|
22767 | }
|
22768 | };
|
22769 |
|
22770 | var UPDATE_QUEUEING = {
|
22771 | initialize: function () {
|
22772 | this.callbackQueue.reset();
|
22773 | },
|
22774 | close: function () {
|
22775 | this.callbackQueue.notifyAll();
|
22776 | }
|
22777 | };
|
22778 |
|
22779 | var TRANSACTION_WRAPPERS = [NESTED_UPDATES, UPDATE_QUEUEING];
|
22780 |
|
22781 | function ReactUpdatesFlushTransaction() {
|
22782 | this.reinitializeTransaction();
|
22783 | this.dirtyComponentsLength = null;
|
22784 | this.callbackQueue = CallbackQueue.getPooled();
|
22785 | this.reconcileTransaction = ReactUpdates.ReactReconcileTransaction.getPooled(
|
22786 | /* useCreateElement */true);
|
22787 | }
|
22788 |
|
22789 | _assign(ReactUpdatesFlushTransaction.prototype, Transaction, {
|
22790 | getTransactionWrappers: function () {
|
22791 | return TRANSACTION_WRAPPERS;
|
22792 | },
|
22793 |
|
22794 | destructor: function () {
|
22795 | this.dirtyComponentsLength = null;
|
22796 | CallbackQueue.release(this.callbackQueue);
|
22797 | this.callbackQueue = null;
|
22798 | ReactUpdates.ReactReconcileTransaction.release(this.reconcileTransaction);
|
22799 | this.reconcileTransaction = null;
|
22800 | },
|
22801 |
|
22802 | perform: function (method, scope, a) {
|
22803 | // Essentially calls `this.reconcileTransaction.perform(method, scope, a)`
|
22804 | // with this transaction's wrappers around it.
|
22805 | return Transaction.perform.call(this, this.reconcileTransaction.perform, this.reconcileTransaction, method, scope, a);
|
22806 | }
|
22807 | });
|
22808 |
|
22809 | PooledClass.addPoolingTo(ReactUpdatesFlushTransaction);
|
22810 |
|
22811 | function batchedUpdates(callback, a, b, c, d, e) {
|
22812 | ensureInjected();
|
22813 | return batchingStrategy.batchedUpdates(callback, a, b, c, d, e);
|
22814 | }
|
22815 |
|
22816 | /**
|
22817 | * Array comparator for ReactComponents by mount ordering.
|
22818 | *
|
22819 | * @param {ReactComponent} c1 first component you're comparing
|
22820 | * @param {ReactComponent} c2 second component you're comparing
|
22821 | * @return {number} Return value usable by Array.prototype.sort().
|
22822 | */
|
22823 | function mountOrderComparator(c1, c2) {
|
22824 | return c1._mountOrder - c2._mountOrder;
|
22825 | }
|
22826 |
|
22827 | function runBatchedUpdates(transaction) {
|
22828 | var len = transaction.dirtyComponentsLength;
|
22829 | !(len === dirtyComponents.length) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Expected flush transaction\'s stored dirty-components length (%s) to match dirty-components array length (%s).', len, dirtyComponents.length) : _prodInvariant('124', len, dirtyComponents.length) : void 0;
|
22830 |
|
22831 | // Since reconciling a component higher in the owner hierarchy usually (not
|
22832 | // always -- see shouldComponentUpdate()) will reconcile children, reconcile
|
22833 | // them before their children by sorting the array.
|
22834 | dirtyComponents.sort(mountOrderComparator);
|
22835 |
|
22836 | // Any updates enqueued while reconciling must be performed after this entire
|
22837 | // batch. Otherwise, if dirtyComponents is [A, B] where A has children B and
|
22838 | // C, B could update twice in a single batch if C's render enqueues an update
|
22839 | // to B (since B would have already updated, we should skip it, and the only
|
22840 | // way we can know to do so is by checking the batch counter).
|
22841 | updateBatchNumber++;
|
22842 |
|
22843 | for (var i = 0; i < len; i++) {
|
22844 | // If a component is unmounted before pending changes apply, it will still
|
22845 | // be here, but we assume that it has cleared its _pendingCallbacks and
|
22846 | // that performUpdateIfNecessary is a noop.
|
22847 | var component = dirtyComponents[i];
|
22848 |
|
22849 | // If performUpdateIfNecessary happens to enqueue any new updates, we
|
22850 | // shouldn't execute the callbacks until the next render happens, so
|
22851 | // stash the callbacks first
|
22852 | var callbacks = component._pendingCallbacks;
|
22853 | component._pendingCallbacks = null;
|
22854 |
|
22855 | var markerName;
|
22856 | if (ReactFeatureFlags.logTopLevelRenders) {
|
22857 | var namedComponent = component;
|
22858 | // Duck type TopLevelWrapper. This is probably always true.
|
22859 | if (component._currentElement.type.isReactTopLevelWrapper) {
|
22860 | namedComponent = component._renderedComponent;
|
22861 | }
|
22862 | markerName = 'React update: ' + namedComponent.getName();
|
22863 | console.time(markerName);
|
22864 | }
|
22865 |
|
22866 | ReactReconciler.performUpdateIfNecessary(component, transaction.reconcileTransaction, updateBatchNumber);
|
22867 |
|
22868 | if (markerName) {
|
22869 | console.timeEnd(markerName);
|
22870 | }
|
22871 |
|
22872 | if (callbacks) {
|
22873 | for (var j = 0; j < callbacks.length; j++) {
|
22874 | transaction.callbackQueue.enqueue(callbacks[j], component.getPublicInstance());
|
22875 | }
|
22876 | }
|
22877 | }
|
22878 | }
|
22879 |
|
22880 | var flushBatchedUpdates = function () {
|
22881 | // ReactUpdatesFlushTransaction's wrappers will clear the dirtyComponents
|
22882 | // array and perform any updates enqueued by mount-ready handlers (i.e.,
|
22883 | // componentDidUpdate) but we need to check here too in order to catch
|
22884 | // updates enqueued by setState callbacks and asap calls.
|
22885 | while (dirtyComponents.length || asapEnqueued) {
|
22886 | if (dirtyComponents.length) {
|
22887 | var transaction = ReactUpdatesFlushTransaction.getPooled();
|
22888 | transaction.perform(runBatchedUpdates, null, transaction);
|
22889 | ReactUpdatesFlushTransaction.release(transaction);
|
22890 | }
|
22891 |
|
22892 | if (asapEnqueued) {
|
22893 | asapEnqueued = false;
|
22894 | var queue = asapCallbackQueue;
|
22895 | asapCallbackQueue = CallbackQueue.getPooled();
|
22896 | queue.notifyAll();
|
22897 | CallbackQueue.release(queue);
|
22898 | }
|
22899 | }
|
22900 | };
|
22901 |
|
22902 | /**
|
22903 | * Mark a component as needing a rerender, adding an optional callback to a
|
22904 | * list of functions which will be executed once the rerender occurs.
|
22905 | */
|
22906 | function enqueueUpdate(component) {
|
22907 | ensureInjected();
|
22908 |
|
22909 | // Various parts of our code (such as ReactCompositeComponent's
|
22910 | // _renderValidatedComponent) assume that calls to render aren't nested;
|
22911 | // verify that that's the case. (This is called by each top-level update
|
22912 | // function, like setState, forceUpdate, etc.; creation and
|
22913 | // destruction of top-level components is guarded in ReactMount.)
|
22914 |
|
22915 | if (!batchingStrategy.isBatchingUpdates) {
|
22916 | batchingStrategy.batchedUpdates(enqueueUpdate, component);
|
22917 | return;
|
22918 | }
|
22919 |
|
22920 | dirtyComponents.push(component);
|
22921 | if (component._updateBatchNumber == null) {
|
22922 | component._updateBatchNumber = updateBatchNumber + 1;
|
22923 | }
|
22924 | }
|
22925 |
|
22926 | /**
|
22927 | * Enqueue a callback to be run at the end of the current batching cycle. Throws
|
22928 | * if no updates are currently being performed.
|
22929 | */
|
22930 | function asap(callback, context) {
|
22931 | !batchingStrategy.isBatchingUpdates ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactUpdates.asap: Can\'t enqueue an asap callback in a context whereupdates are not being batched.') : _prodInvariant('125') : void 0;
|
22932 | asapCallbackQueue.enqueue(callback, context);
|
22933 | asapEnqueued = true;
|
22934 | }
|
22935 |
|
22936 | var ReactUpdatesInjection = {
|
22937 | injectReconcileTransaction: function (ReconcileTransaction) {
|
22938 | !ReconcileTransaction ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactUpdates: must provide a reconcile transaction class') : _prodInvariant('126') : void 0;
|
22939 | ReactUpdates.ReactReconcileTransaction = ReconcileTransaction;
|
22940 | },
|
22941 |
|
22942 | injectBatchingStrategy: function (_batchingStrategy) {
|
22943 | !_batchingStrategy ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactUpdates: must provide a batching strategy') : _prodInvariant('127') : void 0;
|
22944 | !(typeof _batchingStrategy.batchedUpdates === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactUpdates: must provide a batchedUpdates() function') : _prodInvariant('128') : void 0;
|
22945 | !(typeof _batchingStrategy.isBatchingUpdates === 'boolean') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactUpdates: must provide an isBatchingUpdates boolean attribute') : _prodInvariant('129') : void 0;
|
22946 | batchingStrategy = _batchingStrategy;
|
22947 | }
|
22948 | };
|
22949 |
|
22950 | var ReactUpdates = {
|
22951 | /**
|
22952 | * React references `ReactReconcileTransaction` using this property in order
|
22953 | * to allow dependency injection.
|
22954 | *
|
22955 | * @internal
|
22956 | */
|
22957 | ReactReconcileTransaction: null,
|
22958 |
|
22959 | batchedUpdates: batchedUpdates,
|
22960 | enqueueUpdate: enqueueUpdate,
|
22961 | flushBatchedUpdates: flushBatchedUpdates,
|
22962 | injection: ReactUpdatesInjection,
|
22963 | asap: asap
|
22964 | };
|
22965 |
|
22966 | module.exports = ReactUpdates;
|
22967 | }).call(this,require('_process'))
|
22968 | },{"./CallbackQueue":159,"./PooledClass":177,"./ReactFeatureFlags":210,"./ReactReconciler":226,"./Transaction":251,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"object-assign":143}],234:[function(require,module,exports){
|
22969 | /**
|
22970 | * Copyright 2013-present, Facebook, Inc.
|
22971 | * All rights reserved.
|
22972 | *
|
22973 | * This source code is licensed under the BSD-style license found in the
|
22974 | * LICENSE file in the root directory of this source tree. An additional grant
|
22975 | * of patent rights can be found in the PATENTS file in the same directory.
|
22976 | *
|
22977 | */
|
22978 |
|
22979 | 'use strict';
|
22980 |
|
22981 | module.exports = '15.4.1';
|
22982 | },{}],235:[function(require,module,exports){
|
22983 | /**
|
22984 | * Copyright 2013-present, Facebook, Inc.
|
22985 | * All rights reserved.
|
22986 | *
|
22987 | * This source code is licensed under the BSD-style license found in the
|
22988 | * LICENSE file in the root directory of this source tree. An additional grant
|
22989 | * of patent rights can be found in the PATENTS file in the same directory.
|
22990 | *
|
22991 | */
|
22992 |
|
22993 | 'use strict';
|
22994 |
|
22995 | var NS = {
|
22996 | xlink: 'http://www.w3.org/1999/xlink',
|
22997 | xml: 'http://www.w3.org/XML/1998/namespace'
|
22998 | };
|
22999 |
|
23000 | // We use attributes for everything SVG so let's avoid some duplication and run
|
23001 | // code instead.
|
23002 | // The following are all specified in the HTML config already so we exclude here.
|
23003 | // - class (as className)
|
23004 | // - color
|
23005 | // - height
|
23006 | // - id
|
23007 | // - lang
|
23008 | // - max
|
23009 | // - media
|
23010 | // - method
|
23011 | // - min
|
23012 | // - name
|
23013 | // - style
|
23014 | // - target
|
23015 | // - type
|
23016 | // - width
|
23017 | var ATTRS = {
|
23018 | accentHeight: 'accent-height',
|
23019 | accumulate: 0,
|
23020 | additive: 0,
|
23021 | alignmentBaseline: 'alignment-baseline',
|
23022 | allowReorder: 'allowReorder',
|
23023 | alphabetic: 0,
|
23024 | amplitude: 0,
|
23025 | arabicForm: 'arabic-form',
|
23026 | ascent: 0,
|
23027 | attributeName: 'attributeName',
|
23028 | attributeType: 'attributeType',
|
23029 | autoReverse: 'autoReverse',
|
23030 | azimuth: 0,
|
23031 | baseFrequency: 'baseFrequency',
|
23032 | baseProfile: 'baseProfile',
|
23033 | baselineShift: 'baseline-shift',
|
23034 | bbox: 0,
|
23035 | begin: 0,
|
23036 | bias: 0,
|
23037 | by: 0,
|
23038 | calcMode: 'calcMode',
|
23039 | capHeight: 'cap-height',
|
23040 | clip: 0,
|
23041 | clipPath: 'clip-path',
|
23042 | clipRule: 'clip-rule',
|
23043 | clipPathUnits: 'clipPathUnits',
|
23044 | colorInterpolation: 'color-interpolation',
|
23045 | colorInterpolationFilters: 'color-interpolation-filters',
|
23046 | colorProfile: 'color-profile',
|
23047 | colorRendering: 'color-rendering',
|
23048 | contentScriptType: 'contentScriptType',
|
23049 | contentStyleType: 'contentStyleType',
|
23050 | cursor: 0,
|
23051 | cx: 0,
|
23052 | cy: 0,
|
23053 | d: 0,
|
23054 | decelerate: 0,
|
23055 | descent: 0,
|
23056 | diffuseConstant: 'diffuseConstant',
|
23057 | direction: 0,
|
23058 | display: 0,
|
23059 | divisor: 0,
|
23060 | dominantBaseline: 'dominant-baseline',
|
23061 | dur: 0,
|
23062 | dx: 0,
|
23063 | dy: 0,
|
23064 | edgeMode: 'edgeMode',
|
23065 | elevation: 0,
|
23066 | enableBackground: 'enable-background',
|
23067 | end: 0,
|
23068 | exponent: 0,
|
23069 | externalResourcesRequired: 'externalResourcesRequired',
|
23070 | fill: 0,
|
23071 | fillOpacity: 'fill-opacity',
|
23072 | fillRule: 'fill-rule',
|
23073 | filter: 0,
|
23074 | filterRes: 'filterRes',
|
23075 | filterUnits: 'filterUnits',
|
23076 | floodColor: 'flood-color',
|
23077 | floodOpacity: 'flood-opacity',
|
23078 | focusable: 0,
|
23079 | fontFamily: 'font-family',
|
23080 | fontSize: 'font-size',
|
23081 | fontSizeAdjust: 'font-size-adjust',
|
23082 | fontStretch: 'font-stretch',
|
23083 | fontStyle: 'font-style',
|
23084 | fontVariant: 'font-variant',
|
23085 | fontWeight: 'font-weight',
|
23086 | format: 0,
|
23087 | from: 0,
|
23088 | fx: 0,
|
23089 | fy: 0,
|
23090 | g1: 0,
|
23091 | g2: 0,
|
23092 | glyphName: 'glyph-name',
|
23093 | glyphOrientationHorizontal: 'glyph-orientation-horizontal',
|
23094 | glyphOrientationVertical: 'glyph-orientation-vertical',
|
23095 | glyphRef: 'glyphRef',
|
23096 | gradientTransform: 'gradientTransform',
|
23097 | gradientUnits: 'gradientUnits',
|
23098 | hanging: 0,
|
23099 | horizAdvX: 'horiz-adv-x',
|
23100 | horizOriginX: 'horiz-origin-x',
|
23101 | ideographic: 0,
|
23102 | imageRendering: 'image-rendering',
|
23103 | 'in': 0,
|
23104 | in2: 0,
|
23105 | intercept: 0,
|
23106 | k: 0,
|
23107 | k1: 0,
|
23108 | k2: 0,
|
23109 | k3: 0,
|
23110 | k4: 0,
|
23111 | kernelMatrix: 'kernelMatrix',
|
23112 | kernelUnitLength: 'kernelUnitLength',
|
23113 | kerning: 0,
|
23114 | keyPoints: 'keyPoints',
|
23115 | keySplines: 'keySplines',
|
23116 | keyTimes: 'keyTimes',
|
23117 | lengthAdjust: 'lengthAdjust',
|
23118 | letterSpacing: 'letter-spacing',
|
23119 | lightingColor: 'lighting-color',
|
23120 | limitingConeAngle: 'limitingConeAngle',
|
23121 | local: 0,
|
23122 | markerEnd: 'marker-end',
|
23123 | markerMid: 'marker-mid',
|
23124 | markerStart: 'marker-start',
|
23125 | markerHeight: 'markerHeight',
|
23126 | markerUnits: 'markerUnits',
|
23127 | markerWidth: 'markerWidth',
|
23128 | mask: 0,
|
23129 | maskContentUnits: 'maskContentUnits',
|
23130 | maskUnits: 'maskUnits',
|
23131 | mathematical: 0,
|
23132 | mode: 0,
|
23133 | numOctaves: 'numOctaves',
|
23134 | offset: 0,
|
23135 | opacity: 0,
|
23136 | operator: 0,
|
23137 | order: 0,
|
23138 | orient: 0,
|
23139 | orientation: 0,
|
23140 | origin: 0,
|
23141 | overflow: 0,
|
23142 | overlinePosition: 'overline-position',
|
23143 | overlineThickness: 'overline-thickness',
|
23144 | paintOrder: 'paint-order',
|
23145 | panose1: 'panose-1',
|
23146 | pathLength: 'pathLength',
|
23147 | patternContentUnits: 'patternContentUnits',
|
23148 | patternTransform: 'patternTransform',
|
23149 | patternUnits: 'patternUnits',
|
23150 | pointerEvents: 'pointer-events',
|
23151 | points: 0,
|
23152 | pointsAtX: 'pointsAtX',
|
23153 | pointsAtY: 'pointsAtY',
|
23154 | pointsAtZ: 'pointsAtZ',
|
23155 | preserveAlpha: 'preserveAlpha',
|
23156 | preserveAspectRatio: 'preserveAspectRatio',
|
23157 | primitiveUnits: 'primitiveUnits',
|
23158 | r: 0,
|
23159 | radius: 0,
|
23160 | refX: 'refX',
|
23161 | refY: 'refY',
|
23162 | renderingIntent: 'rendering-intent',
|
23163 | repeatCount: 'repeatCount',
|
23164 | repeatDur: 'repeatDur',
|
23165 | requiredExtensions: 'requiredExtensions',
|
23166 | requiredFeatures: 'requiredFeatures',
|
23167 | restart: 0,
|
23168 | result: 0,
|
23169 | rotate: 0,
|
23170 | rx: 0,
|
23171 | ry: 0,
|
23172 | scale: 0,
|
23173 | seed: 0,
|
23174 | shapeRendering: 'shape-rendering',
|
23175 | slope: 0,
|
23176 | spacing: 0,
|
23177 | specularConstant: 'specularConstant',
|
23178 | specularExponent: 'specularExponent',
|
23179 | speed: 0,
|
23180 | spreadMethod: 'spreadMethod',
|
23181 | startOffset: 'startOffset',
|
23182 | stdDeviation: 'stdDeviation',
|
23183 | stemh: 0,
|
23184 | stemv: 0,
|
23185 | stitchTiles: 'stitchTiles',
|
23186 | stopColor: 'stop-color',
|
23187 | stopOpacity: 'stop-opacity',
|
23188 | strikethroughPosition: 'strikethrough-position',
|
23189 | strikethroughThickness: 'strikethrough-thickness',
|
23190 | string: 0,
|
23191 | stroke: 0,
|
23192 | strokeDasharray: 'stroke-dasharray',
|
23193 | strokeDashoffset: 'stroke-dashoffset',
|
23194 | strokeLinecap: 'stroke-linecap',
|
23195 | strokeLinejoin: 'stroke-linejoin',
|
23196 | strokeMiterlimit: 'stroke-miterlimit',
|
23197 | strokeOpacity: 'stroke-opacity',
|
23198 | strokeWidth: 'stroke-width',
|
23199 | surfaceScale: 'surfaceScale',
|
23200 | systemLanguage: 'systemLanguage',
|
23201 | tableValues: 'tableValues',
|
23202 | targetX: 'targetX',
|
23203 | targetY: 'targetY',
|
23204 | textAnchor: 'text-anchor',
|
23205 | textDecoration: 'text-decoration',
|
23206 | textRendering: 'text-rendering',
|
23207 | textLength: 'textLength',
|
23208 | to: 0,
|
23209 | transform: 0,
|
23210 | u1: 0,
|
23211 | u2: 0,
|
23212 | underlinePosition: 'underline-position',
|
23213 | underlineThickness: 'underline-thickness',
|
23214 | unicode: 0,
|
23215 | unicodeBidi: 'unicode-bidi',
|
23216 | unicodeRange: 'unicode-range',
|
23217 | unitsPerEm: 'units-per-em',
|
23218 | vAlphabetic: 'v-alphabetic',
|
23219 | vHanging: 'v-hanging',
|
23220 | vIdeographic: 'v-ideographic',
|
23221 | vMathematical: 'v-mathematical',
|
23222 | values: 0,
|
23223 | vectorEffect: 'vector-effect',
|
23224 | version: 0,
|
23225 | vertAdvY: 'vert-adv-y',
|
23226 | vertOriginX: 'vert-origin-x',
|
23227 | vertOriginY: 'vert-origin-y',
|
23228 | viewBox: 'viewBox',
|
23229 | viewTarget: 'viewTarget',
|
23230 | visibility: 0,
|
23231 | widths: 0,
|
23232 | wordSpacing: 'word-spacing',
|
23233 | writingMode: 'writing-mode',
|
23234 | x: 0,
|
23235 | xHeight: 'x-height',
|
23236 | x1: 0,
|
23237 | x2: 0,
|
23238 | xChannelSelector: 'xChannelSelector',
|
23239 | xlinkActuate: 'xlink:actuate',
|
23240 | xlinkArcrole: 'xlink:arcrole',
|
23241 | xlinkHref: 'xlink:href',
|
23242 | xlinkRole: 'xlink:role',
|
23243 | xlinkShow: 'xlink:show',
|
23244 | xlinkTitle: 'xlink:title',
|
23245 | xlinkType: 'xlink:type',
|
23246 | xmlBase: 'xml:base',
|
23247 | xmlns: 0,
|
23248 | xmlnsXlink: 'xmlns:xlink',
|
23249 | xmlLang: 'xml:lang',
|
23250 | xmlSpace: 'xml:space',
|
23251 | y: 0,
|
23252 | y1: 0,
|
23253 | y2: 0,
|
23254 | yChannelSelector: 'yChannelSelector',
|
23255 | z: 0,
|
23256 | zoomAndPan: 'zoomAndPan'
|
23257 | };
|
23258 |
|
23259 | var SVGDOMPropertyConfig = {
|
23260 | Properties: {},
|
23261 | DOMAttributeNamespaces: {
|
23262 | xlinkActuate: NS.xlink,
|
23263 | xlinkArcrole: NS.xlink,
|
23264 | xlinkHref: NS.xlink,
|
23265 | xlinkRole: NS.xlink,
|
23266 | xlinkShow: NS.xlink,
|
23267 | xlinkTitle: NS.xlink,
|
23268 | xlinkType: NS.xlink,
|
23269 | xmlBase: NS.xml,
|
23270 | xmlLang: NS.xml,
|
23271 | xmlSpace: NS.xml
|
23272 | },
|
23273 | DOMAttributeNames: {}
|
23274 | };
|
23275 |
|
23276 | Object.keys(ATTRS).forEach(function (key) {
|
23277 | SVGDOMPropertyConfig.Properties[key] = 0;
|
23278 | if (ATTRS[key]) {
|
23279 | SVGDOMPropertyConfig.DOMAttributeNames[key] = ATTRS[key];
|
23280 | }
|
23281 | });
|
23282 |
|
23283 | module.exports = SVGDOMPropertyConfig;
|
23284 | },{}],236:[function(require,module,exports){
|
23285 | /**
|
23286 | * Copyright 2013-present, Facebook, Inc.
|
23287 | * All rights reserved.
|
23288 | *
|
23289 | * This source code is licensed under the BSD-style license found in the
|
23290 | * LICENSE file in the root directory of this source tree. An additional grant
|
23291 | * of patent rights can be found in the PATENTS file in the same directory.
|
23292 | *
|
23293 | */
|
23294 |
|
23295 | 'use strict';
|
23296 |
|
23297 | var EventPropagators = require('./EventPropagators');
|
23298 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
23299 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
23300 | var ReactInputSelection = require('./ReactInputSelection');
|
23301 | var SyntheticEvent = require('./SyntheticEvent');
|
23302 |
|
23303 | var getActiveElement = require('fbjs/lib/getActiveElement');
|
23304 | var isTextInputElement = require('./isTextInputElement');
|
23305 | var shallowEqual = require('fbjs/lib/shallowEqual');
|
23306 |
|
23307 | var skipSelectionChangeEvent = ExecutionEnvironment.canUseDOM && 'documentMode' in document && document.documentMode <= 11;
|
23308 |
|
23309 | var eventTypes = {
|
23310 | select: {
|
23311 | phasedRegistrationNames: {
|
23312 | bubbled: 'onSelect',
|
23313 | captured: 'onSelectCapture'
|
23314 | },
|
23315 | dependencies: ['topBlur', 'topContextMenu', 'topFocus', 'topKeyDown', 'topKeyUp', 'topMouseDown', 'topMouseUp', 'topSelectionChange']
|
23316 | }
|
23317 | };
|
23318 |
|
23319 | var activeElement = null;
|
23320 | var activeElementInst = null;
|
23321 | var lastSelection = null;
|
23322 | var mouseDown = false;
|
23323 |
|
23324 | // Track whether a listener exists for this plugin. If none exist, we do
|
23325 | // not extract events. See #3639.
|
23326 | var hasListener = false;
|
23327 |
|
23328 | /**
|
23329 | * Get an object which is a unique representation of the current selection.
|
23330 | *
|
23331 | * The return value will not be consistent across nodes or browsers, but
|
23332 | * two identical selections on the same node will return identical objects.
|
23333 | *
|
23334 | * @param {DOMElement} node
|
23335 | * @return {object}
|
23336 | */
|
23337 | function getSelection(node) {
|
23338 | if ('selectionStart' in node && ReactInputSelection.hasSelectionCapabilities(node)) {
|
23339 | return {
|
23340 | start: node.selectionStart,
|
23341 | end: node.selectionEnd
|
23342 | };
|
23343 | } else if (window.getSelection) {
|
23344 | var selection = window.getSelection();
|
23345 | return {
|
23346 | anchorNode: selection.anchorNode,
|
23347 | anchorOffset: selection.anchorOffset,
|
23348 | focusNode: selection.focusNode,
|
23349 | focusOffset: selection.focusOffset
|
23350 | };
|
23351 | } else if (document.selection) {
|
23352 | var range = document.selection.createRange();
|
23353 | return {
|
23354 | parentElement: range.parentElement(),
|
23355 | text: range.text,
|
23356 | top: range.boundingTop,
|
23357 | left: range.boundingLeft
|
23358 | };
|
23359 | }
|
23360 | }
|
23361 |
|
23362 | /**
|
23363 | * Poll selection to see whether it's changed.
|
23364 | *
|
23365 | * @param {object} nativeEvent
|
23366 | * @return {?SyntheticEvent}
|
23367 | */
|
23368 | function constructSelectEvent(nativeEvent, nativeEventTarget) {
|
23369 | // Ensure we have the right element, and that the user is not dragging a
|
23370 | // selection (this matches native `select` event behavior). In HTML5, select
|
23371 | // fires only on input and textarea thus if there's no focused element we
|
23372 | // won't dispatch.
|
23373 | if (mouseDown || activeElement == null || activeElement !== getActiveElement()) {
|
23374 | return null;
|
23375 | }
|
23376 |
|
23377 | // Only fire when selection has actually changed.
|
23378 | var currentSelection = getSelection(activeElement);
|
23379 | if (!lastSelection || !shallowEqual(lastSelection, currentSelection)) {
|
23380 | lastSelection = currentSelection;
|
23381 |
|
23382 | var syntheticEvent = SyntheticEvent.getPooled(eventTypes.select, activeElementInst, nativeEvent, nativeEventTarget);
|
23383 |
|
23384 | syntheticEvent.type = 'select';
|
23385 | syntheticEvent.target = activeElement;
|
23386 |
|
23387 | EventPropagators.accumulateTwoPhaseDispatches(syntheticEvent);
|
23388 |
|
23389 | return syntheticEvent;
|
23390 | }
|
23391 |
|
23392 | return null;
|
23393 | }
|
23394 |
|
23395 | /**
|
23396 | * This plugin creates an `onSelect` event that normalizes select events
|
23397 | * across form elements.
|
23398 | *
|
23399 | * Supported elements are:
|
23400 | * - input (see `isTextInputElement`)
|
23401 | * - textarea
|
23402 | * - contentEditable
|
23403 | *
|
23404 | * This differs from native browser implementations in the following ways:
|
23405 | * - Fires on contentEditable fields as well as inputs.
|
23406 | * - Fires for collapsed selection.
|
23407 | * - Fires after user input.
|
23408 | */
|
23409 | var SelectEventPlugin = {
|
23410 |
|
23411 | eventTypes: eventTypes,
|
23412 |
|
23413 | extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
|
23414 | if (!hasListener) {
|
23415 | return null;
|
23416 | }
|
23417 |
|
23418 | var targetNode = targetInst ? ReactDOMComponentTree.getNodeFromInstance(targetInst) : window;
|
23419 |
|
23420 | switch (topLevelType) {
|
23421 | // Track the input node that has focus.
|
23422 | case 'topFocus':
|
23423 | if (isTextInputElement(targetNode) || targetNode.contentEditable === 'true') {
|
23424 | activeElement = targetNode;
|
23425 | activeElementInst = targetInst;
|
23426 | lastSelection = null;
|
23427 | }
|
23428 | break;
|
23429 | case 'topBlur':
|
23430 | activeElement = null;
|
23431 | activeElementInst = null;
|
23432 | lastSelection = null;
|
23433 | break;
|
23434 |
|
23435 | // Don't fire the event while the user is dragging. This matches the
|
23436 | // semantics of the native select event.
|
23437 | case 'topMouseDown':
|
23438 | mouseDown = true;
|
23439 | break;
|
23440 | case 'topContextMenu':
|
23441 | case 'topMouseUp':
|
23442 | mouseDown = false;
|
23443 | return constructSelectEvent(nativeEvent, nativeEventTarget);
|
23444 |
|
23445 | // Chrome and IE fire non-standard event when selection is changed (and
|
23446 | // sometimes when it hasn't). IE's event fires out of order with respect
|
23447 | // to key and input events on deletion, so we discard it.
|
23448 | //
|
23449 | // Firefox doesn't support selectionchange, so check selection status
|
23450 | // after each key entry. The selection changes after keydown and before
|
23451 | // keyup, but we check on keydown as well in the case of holding down a
|
23452 | // key, when multiple keydown events are fired but only one keyup is.
|
23453 | // This is also our approach for IE handling, for the reason above.
|
23454 | case 'topSelectionChange':
|
23455 | if (skipSelectionChangeEvent) {
|
23456 | break;
|
23457 | }
|
23458 | // falls through
|
23459 | case 'topKeyDown':
|
23460 | case 'topKeyUp':
|
23461 | return constructSelectEvent(nativeEvent, nativeEventTarget);
|
23462 | }
|
23463 |
|
23464 | return null;
|
23465 | },
|
23466 |
|
23467 | didPutListener: function (inst, registrationName, listener) {
|
23468 | if (registrationName === 'onSelect') {
|
23469 | hasListener = true;
|
23470 | }
|
23471 | }
|
23472 | };
|
23473 |
|
23474 | module.exports = SelectEventPlugin;
|
23475 | },{"./EventPropagators":172,"./ReactDOMComponentTree":186,"./ReactInputSelection":214,"./SyntheticEvent":242,"./isTextInputElement":274,"fbjs/lib/ExecutionEnvironment":110,"fbjs/lib/getActiveElement":119,"fbjs/lib/shallowEqual":130}],237:[function(require,module,exports){
|
23476 | (function (process){
|
23477 | /**
|
23478 | * Copyright 2013-present, Facebook, Inc.
|
23479 | * All rights reserved.
|
23480 | *
|
23481 | * This source code is licensed under the BSD-style license found in the
|
23482 | * LICENSE file in the root directory of this source tree. An additional grant
|
23483 | * of patent rights can be found in the PATENTS file in the same directory.
|
23484 | *
|
23485 | *
|
23486 | */
|
23487 |
|
23488 | 'use strict';
|
23489 |
|
23490 | var _prodInvariant = require('./reactProdInvariant');
|
23491 |
|
23492 | var EventListener = require('fbjs/lib/EventListener');
|
23493 | var EventPropagators = require('./EventPropagators');
|
23494 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
23495 | var SyntheticAnimationEvent = require('./SyntheticAnimationEvent');
|
23496 | var SyntheticClipboardEvent = require('./SyntheticClipboardEvent');
|
23497 | var SyntheticEvent = require('./SyntheticEvent');
|
23498 | var SyntheticFocusEvent = require('./SyntheticFocusEvent');
|
23499 | var SyntheticKeyboardEvent = require('./SyntheticKeyboardEvent');
|
23500 | var SyntheticMouseEvent = require('./SyntheticMouseEvent');
|
23501 | var SyntheticDragEvent = require('./SyntheticDragEvent');
|
23502 | var SyntheticTouchEvent = require('./SyntheticTouchEvent');
|
23503 | var SyntheticTransitionEvent = require('./SyntheticTransitionEvent');
|
23504 | var SyntheticUIEvent = require('./SyntheticUIEvent');
|
23505 | var SyntheticWheelEvent = require('./SyntheticWheelEvent');
|
23506 |
|
23507 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
23508 | var getEventCharCode = require('./getEventCharCode');
|
23509 | var invariant = require('fbjs/lib/invariant');
|
23510 |
|
23511 | /**
|
23512 | * Turns
|
23513 | * ['abort', ...]
|
23514 | * into
|
23515 | * eventTypes = {
|
23516 | * 'abort': {
|
23517 | * phasedRegistrationNames: {
|
23518 | * bubbled: 'onAbort',
|
23519 | * captured: 'onAbortCapture',
|
23520 | * },
|
23521 | * dependencies: ['topAbort'],
|
23522 | * },
|
23523 | * ...
|
23524 | * };
|
23525 | * topLevelEventsToDispatchConfig = {
|
23526 | * 'topAbort': { sameConfig }
|
23527 | * };
|
23528 | */
|
23529 | var eventTypes = {};
|
23530 | var topLevelEventsToDispatchConfig = {};
|
23531 | ['abort', 'animationEnd', 'animationIteration', 'animationStart', 'blur', 'canPlay', 'canPlayThrough', 'click', 'contextMenu', 'copy', 'cut', 'doubleClick', 'drag', 'dragEnd', 'dragEnter', 'dragExit', 'dragLeave', 'dragOver', 'dragStart', 'drop', 'durationChange', 'emptied', 'encrypted', 'ended', 'error', 'focus', 'input', 'invalid', 'keyDown', 'keyPress', 'keyUp', 'load', 'loadedData', 'loadedMetadata', 'loadStart', 'mouseDown', 'mouseMove', 'mouseOut', 'mouseOver', 'mouseUp', 'paste', 'pause', 'play', 'playing', 'progress', 'rateChange', 'reset', 'scroll', 'seeked', 'seeking', 'stalled', 'submit', 'suspend', 'timeUpdate', 'touchCancel', 'touchEnd', 'touchMove', 'touchStart', 'transitionEnd', 'volumeChange', 'waiting', 'wheel'].forEach(function (event) {
|
23532 | var capitalizedEvent = event[0].toUpperCase() + event.slice(1);
|
23533 | var onEvent = 'on' + capitalizedEvent;
|
23534 | var topEvent = 'top' + capitalizedEvent;
|
23535 |
|
23536 | var type = {
|
23537 | phasedRegistrationNames: {
|
23538 | bubbled: onEvent,
|
23539 | captured: onEvent + 'Capture'
|
23540 | },
|
23541 | dependencies: [topEvent]
|
23542 | };
|
23543 | eventTypes[event] = type;
|
23544 | topLevelEventsToDispatchConfig[topEvent] = type;
|
23545 | });
|
23546 |
|
23547 | var onClickListeners = {};
|
23548 |
|
23549 | function getDictionaryKey(inst) {
|
23550 | // Prevents V8 performance issue:
|
23551 | // https://github.com/facebook/react/pull/7232
|
23552 | return '.' + inst._rootNodeID;
|
23553 | }
|
23554 |
|
23555 | function isInteractive(tag) {
|
23556 | return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
|
23557 | }
|
23558 |
|
23559 | var SimpleEventPlugin = {
|
23560 |
|
23561 | eventTypes: eventTypes,
|
23562 |
|
23563 | extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
|
23564 | var dispatchConfig = topLevelEventsToDispatchConfig[topLevelType];
|
23565 | if (!dispatchConfig) {
|
23566 | return null;
|
23567 | }
|
23568 | var EventConstructor;
|
23569 | switch (topLevelType) {
|
23570 | case 'topAbort':
|
23571 | case 'topCanPlay':
|
23572 | case 'topCanPlayThrough':
|
23573 | case 'topDurationChange':
|
23574 | case 'topEmptied':
|
23575 | case 'topEncrypted':
|
23576 | case 'topEnded':
|
23577 | case 'topError':
|
23578 | case 'topInput':
|
23579 | case 'topInvalid':
|
23580 | case 'topLoad':
|
23581 | case 'topLoadedData':
|
23582 | case 'topLoadedMetadata':
|
23583 | case 'topLoadStart':
|
23584 | case 'topPause':
|
23585 | case 'topPlay':
|
23586 | case 'topPlaying':
|
23587 | case 'topProgress':
|
23588 | case 'topRateChange':
|
23589 | case 'topReset':
|
23590 | case 'topSeeked':
|
23591 | case 'topSeeking':
|
23592 | case 'topStalled':
|
23593 | case 'topSubmit':
|
23594 | case 'topSuspend':
|
23595 | case 'topTimeUpdate':
|
23596 | case 'topVolumeChange':
|
23597 | case 'topWaiting':
|
23598 | // HTML Events
|
23599 | // @see http://www.w3.org/TR/html5/index.html#events-0
|
23600 | EventConstructor = SyntheticEvent;
|
23601 | break;
|
23602 | case 'topKeyPress':
|
23603 | // Firefox creates a keypress event for function keys too. This removes
|
23604 | // the unwanted keypress events. Enter is however both printable and
|
23605 | // non-printable. One would expect Tab to be as well (but it isn't).
|
23606 | if (getEventCharCode(nativeEvent) === 0) {
|
23607 | return null;
|
23608 | }
|
23609 | /* falls through */
|
23610 | case 'topKeyDown':
|
23611 | case 'topKeyUp':
|
23612 | EventConstructor = SyntheticKeyboardEvent;
|
23613 | break;
|
23614 | case 'topBlur':
|
23615 | case 'topFocus':
|
23616 | EventConstructor = SyntheticFocusEvent;
|
23617 | break;
|
23618 | case 'topClick':
|
23619 | // Firefox creates a click event on right mouse clicks. This removes the
|
23620 | // unwanted click events.
|
23621 | if (nativeEvent.button === 2) {
|
23622 | return null;
|
23623 | }
|
23624 | /* falls through */
|
23625 | case 'topDoubleClick':
|
23626 | case 'topMouseDown':
|
23627 | case 'topMouseMove':
|
23628 | case 'topMouseUp':
|
23629 | // TODO: Disabled elements should not respond to mouse events
|
23630 | /* falls through */
|
23631 | case 'topMouseOut':
|
23632 | case 'topMouseOver':
|
23633 | case 'topContextMenu':
|
23634 | EventConstructor = SyntheticMouseEvent;
|
23635 | break;
|
23636 | case 'topDrag':
|
23637 | case 'topDragEnd':
|
23638 | case 'topDragEnter':
|
23639 | case 'topDragExit':
|
23640 | case 'topDragLeave':
|
23641 | case 'topDragOver':
|
23642 | case 'topDragStart':
|
23643 | case 'topDrop':
|
23644 | EventConstructor = SyntheticDragEvent;
|
23645 | break;
|
23646 | case 'topTouchCancel':
|
23647 | case 'topTouchEnd':
|
23648 | case 'topTouchMove':
|
23649 | case 'topTouchStart':
|
23650 | EventConstructor = SyntheticTouchEvent;
|
23651 | break;
|
23652 | case 'topAnimationEnd':
|
23653 | case 'topAnimationIteration':
|
23654 | case 'topAnimationStart':
|
23655 | EventConstructor = SyntheticAnimationEvent;
|
23656 | break;
|
23657 | case 'topTransitionEnd':
|
23658 | EventConstructor = SyntheticTransitionEvent;
|
23659 | break;
|
23660 | case 'topScroll':
|
23661 | EventConstructor = SyntheticUIEvent;
|
23662 | break;
|
23663 | case 'topWheel':
|
23664 | EventConstructor = SyntheticWheelEvent;
|
23665 | break;
|
23666 | case 'topCopy':
|
23667 | case 'topCut':
|
23668 | case 'topPaste':
|
23669 | EventConstructor = SyntheticClipboardEvent;
|
23670 | break;
|
23671 | }
|
23672 | !EventConstructor ? process.env.NODE_ENV !== 'production' ? invariant(false, 'SimpleEventPlugin: Unhandled event type, `%s`.', topLevelType) : _prodInvariant('86', topLevelType) : void 0;
|
23673 | var event = EventConstructor.getPooled(dispatchConfig, targetInst, nativeEvent, nativeEventTarget);
|
23674 | EventPropagators.accumulateTwoPhaseDispatches(event);
|
23675 | return event;
|
23676 | },
|
23677 |
|
23678 | didPutListener: function (inst, registrationName, listener) {
|
23679 | // Mobile Safari does not fire properly bubble click events on
|
23680 | // non-interactive elements, which means delegated click listeners do not
|
23681 | // fire. The workaround for this bug involves attaching an empty click
|
23682 | // listener on the target node.
|
23683 | // http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
|
23684 | if (registrationName === 'onClick' && !isInteractive(inst._tag)) {
|
23685 | var key = getDictionaryKey(inst);
|
23686 | var node = ReactDOMComponentTree.getNodeFromInstance(inst);
|
23687 | if (!onClickListeners[key]) {
|
23688 | onClickListeners[key] = EventListener.listen(node, 'click', emptyFunction);
|
23689 | }
|
23690 | }
|
23691 | },
|
23692 |
|
23693 | willDeleteListener: function (inst, registrationName) {
|
23694 | if (registrationName === 'onClick' && !isInteractive(inst._tag)) {
|
23695 | var key = getDictionaryKey(inst);
|
23696 | onClickListeners[key].remove();
|
23697 | delete onClickListeners[key];
|
23698 | }
|
23699 | }
|
23700 |
|
23701 | };
|
23702 |
|
23703 | module.exports = SimpleEventPlugin;
|
23704 | }).call(this,require('_process'))
|
23705 | },{"./EventPropagators":172,"./ReactDOMComponentTree":186,"./SyntheticAnimationEvent":238,"./SyntheticClipboardEvent":239,"./SyntheticDragEvent":241,"./SyntheticEvent":242,"./SyntheticFocusEvent":243,"./SyntheticKeyboardEvent":245,"./SyntheticMouseEvent":246,"./SyntheticTouchEvent":247,"./SyntheticTransitionEvent":248,"./SyntheticUIEvent":249,"./SyntheticWheelEvent":250,"./getEventCharCode":262,"./reactProdInvariant":276,"_process":144,"fbjs/lib/EventListener":109,"fbjs/lib/emptyFunction":116,"fbjs/lib/invariant":124}],238:[function(require,module,exports){
|
23706 | /**
|
23707 | * Copyright 2013-present, Facebook, Inc.
|
23708 | * All rights reserved.
|
23709 | *
|
23710 | * This source code is licensed under the BSD-style license found in the
|
23711 | * LICENSE file in the root directory of this source tree. An additional grant
|
23712 | * of patent rights can be found in the PATENTS file in the same directory.
|
23713 | *
|
23714 | */
|
23715 |
|
23716 | 'use strict';
|
23717 |
|
23718 | var SyntheticEvent = require('./SyntheticEvent');
|
23719 |
|
23720 | /**
|
23721 | * @interface Event
|
23722 | * @see http://www.w3.org/TR/css3-animations/#AnimationEvent-interface
|
23723 | * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent
|
23724 | */
|
23725 | var AnimationEventInterface = {
|
23726 | animationName: null,
|
23727 | elapsedTime: null,
|
23728 | pseudoElement: null
|
23729 | };
|
23730 |
|
23731 | /**
|
23732 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
23733 | * @param {string} dispatchMarker Marker identifying the event target.
|
23734 | * @param {object} nativeEvent Native browser event.
|
23735 | * @extends {SyntheticEvent}
|
23736 | */
|
23737 | function SyntheticAnimationEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
23738 | return SyntheticEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
23739 | }
|
23740 |
|
23741 | SyntheticEvent.augmentClass(SyntheticAnimationEvent, AnimationEventInterface);
|
23742 |
|
23743 | module.exports = SyntheticAnimationEvent;
|
23744 | },{"./SyntheticEvent":242}],239:[function(require,module,exports){
|
23745 | /**
|
23746 | * Copyright 2013-present, Facebook, Inc.
|
23747 | * All rights reserved.
|
23748 | *
|
23749 | * This source code is licensed under the BSD-style license found in the
|
23750 | * LICENSE file in the root directory of this source tree. An additional grant
|
23751 | * of patent rights can be found in the PATENTS file in the same directory.
|
23752 | *
|
23753 | */
|
23754 |
|
23755 | 'use strict';
|
23756 |
|
23757 | var SyntheticEvent = require('./SyntheticEvent');
|
23758 |
|
23759 | /**
|
23760 | * @interface Event
|
23761 | * @see http://www.w3.org/TR/clipboard-apis/
|
23762 | */
|
23763 | var ClipboardEventInterface = {
|
23764 | clipboardData: function (event) {
|
23765 | return 'clipboardData' in event ? event.clipboardData : window.clipboardData;
|
23766 | }
|
23767 | };
|
23768 |
|
23769 | /**
|
23770 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
23771 | * @param {string} dispatchMarker Marker identifying the event target.
|
23772 | * @param {object} nativeEvent Native browser event.
|
23773 | * @extends {SyntheticUIEvent}
|
23774 | */
|
23775 | function SyntheticClipboardEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
23776 | return SyntheticEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
23777 | }
|
23778 |
|
23779 | SyntheticEvent.augmentClass(SyntheticClipboardEvent, ClipboardEventInterface);
|
23780 |
|
23781 | module.exports = SyntheticClipboardEvent;
|
23782 | },{"./SyntheticEvent":242}],240:[function(require,module,exports){
|
23783 | /**
|
23784 | * Copyright 2013-present, Facebook, Inc.
|
23785 | * All rights reserved.
|
23786 | *
|
23787 | * This source code is licensed under the BSD-style license found in the
|
23788 | * LICENSE file in the root directory of this source tree. An additional grant
|
23789 | * of patent rights can be found in the PATENTS file in the same directory.
|
23790 | *
|
23791 | */
|
23792 |
|
23793 | 'use strict';
|
23794 |
|
23795 | var SyntheticEvent = require('./SyntheticEvent');
|
23796 |
|
23797 | /**
|
23798 | * @interface Event
|
23799 | * @see http://www.w3.org/TR/DOM-Level-3-Events/#events-compositionevents
|
23800 | */
|
23801 | var CompositionEventInterface = {
|
23802 | data: null
|
23803 | };
|
23804 |
|
23805 | /**
|
23806 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
23807 | * @param {string} dispatchMarker Marker identifying the event target.
|
23808 | * @param {object} nativeEvent Native browser event.
|
23809 | * @extends {SyntheticUIEvent}
|
23810 | */
|
23811 | function SyntheticCompositionEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
23812 | return SyntheticEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
23813 | }
|
23814 |
|
23815 | SyntheticEvent.augmentClass(SyntheticCompositionEvent, CompositionEventInterface);
|
23816 |
|
23817 | module.exports = SyntheticCompositionEvent;
|
23818 | },{"./SyntheticEvent":242}],241:[function(require,module,exports){
|
23819 | /**
|
23820 | * Copyright 2013-present, Facebook, Inc.
|
23821 | * All rights reserved.
|
23822 | *
|
23823 | * This source code is licensed under the BSD-style license found in the
|
23824 | * LICENSE file in the root directory of this source tree. An additional grant
|
23825 | * of patent rights can be found in the PATENTS file in the same directory.
|
23826 | *
|
23827 | */
|
23828 |
|
23829 | 'use strict';
|
23830 |
|
23831 | var SyntheticMouseEvent = require('./SyntheticMouseEvent');
|
23832 |
|
23833 | /**
|
23834 | * @interface DragEvent
|
23835 | * @see http://www.w3.org/TR/DOM-Level-3-Events/
|
23836 | */
|
23837 | var DragEventInterface = {
|
23838 | dataTransfer: null
|
23839 | };
|
23840 |
|
23841 | /**
|
23842 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
23843 | * @param {string} dispatchMarker Marker identifying the event target.
|
23844 | * @param {object} nativeEvent Native browser event.
|
23845 | * @extends {SyntheticUIEvent}
|
23846 | */
|
23847 | function SyntheticDragEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
23848 | return SyntheticMouseEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
23849 | }
|
23850 |
|
23851 | SyntheticMouseEvent.augmentClass(SyntheticDragEvent, DragEventInterface);
|
23852 |
|
23853 | module.exports = SyntheticDragEvent;
|
23854 | },{"./SyntheticMouseEvent":246}],242:[function(require,module,exports){
|
23855 | (function (process){
|
23856 | /**
|
23857 | * Copyright 2013-present, Facebook, Inc.
|
23858 | * All rights reserved.
|
23859 | *
|
23860 | * This source code is licensed under the BSD-style license found in the
|
23861 | * LICENSE file in the root directory of this source tree. An additional grant
|
23862 | * of patent rights can be found in the PATENTS file in the same directory.
|
23863 | *
|
23864 | */
|
23865 |
|
23866 | 'use strict';
|
23867 |
|
23868 | var _assign = require('object-assign');
|
23869 |
|
23870 | var PooledClass = require('./PooledClass');
|
23871 |
|
23872 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
23873 | var warning = require('fbjs/lib/warning');
|
23874 |
|
23875 | var didWarnForAddedNewProperty = false;
|
23876 | var isProxySupported = typeof Proxy === 'function';
|
23877 |
|
23878 | var shouldBeReleasedProperties = ['dispatchConfig', '_targetInst', 'nativeEvent', 'isDefaultPrevented', 'isPropagationStopped', '_dispatchListeners', '_dispatchInstances'];
|
23879 |
|
23880 | /**
|
23881 | * @interface Event
|
23882 | * @see http://www.w3.org/TR/DOM-Level-3-Events/
|
23883 | */
|
23884 | var EventInterface = {
|
23885 | type: null,
|
23886 | target: null,
|
23887 | // currentTarget is set when dispatching; no use in copying it here
|
23888 | currentTarget: emptyFunction.thatReturnsNull,
|
23889 | eventPhase: null,
|
23890 | bubbles: null,
|
23891 | cancelable: null,
|
23892 | timeStamp: function (event) {
|
23893 | return event.timeStamp || Date.now();
|
23894 | },
|
23895 | defaultPrevented: null,
|
23896 | isTrusted: null
|
23897 | };
|
23898 |
|
23899 | /**
|
23900 | * Synthetic events are dispatched by event plugins, typically in response to a
|
23901 | * top-level event delegation handler.
|
23902 | *
|
23903 | * These systems should generally use pooling to reduce the frequency of garbage
|
23904 | * collection. The system should check `isPersistent` to determine whether the
|
23905 | * event should be released into the pool after being dispatched. Users that
|
23906 | * need a persisted event should invoke `persist`.
|
23907 | *
|
23908 | * Synthetic events (and subclasses) implement the DOM Level 3 Events API by
|
23909 | * normalizing browser quirks. Subclasses do not necessarily have to implement a
|
23910 | * DOM interface; custom application-specific events can also subclass this.
|
23911 | *
|
23912 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
23913 | * @param {*} targetInst Marker identifying the event target.
|
23914 | * @param {object} nativeEvent Native browser event.
|
23915 | * @param {DOMEventTarget} nativeEventTarget Target node.
|
23916 | */
|
23917 | function SyntheticEvent(dispatchConfig, targetInst, nativeEvent, nativeEventTarget) {
|
23918 | if (process.env.NODE_ENV !== 'production') {
|
23919 | // these have a getter/setter for warnings
|
23920 | delete this.nativeEvent;
|
23921 | delete this.preventDefault;
|
23922 | delete this.stopPropagation;
|
23923 | }
|
23924 |
|
23925 | this.dispatchConfig = dispatchConfig;
|
23926 | this._targetInst = targetInst;
|
23927 | this.nativeEvent = nativeEvent;
|
23928 |
|
23929 | var Interface = this.constructor.Interface;
|
23930 | for (var propName in Interface) {
|
23931 | if (!Interface.hasOwnProperty(propName)) {
|
23932 | continue;
|
23933 | }
|
23934 | if (process.env.NODE_ENV !== 'production') {
|
23935 | delete this[propName]; // this has a getter/setter for warnings
|
23936 | }
|
23937 | var normalize = Interface[propName];
|
23938 | if (normalize) {
|
23939 | this[propName] = normalize(nativeEvent);
|
23940 | } else {
|
23941 | if (propName === 'target') {
|
23942 | this.target = nativeEventTarget;
|
23943 | } else {
|
23944 | this[propName] = nativeEvent[propName];
|
23945 | }
|
23946 | }
|
23947 | }
|
23948 |
|
23949 | var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
|
23950 | if (defaultPrevented) {
|
23951 | this.isDefaultPrevented = emptyFunction.thatReturnsTrue;
|
23952 | } else {
|
23953 | this.isDefaultPrevented = emptyFunction.thatReturnsFalse;
|
23954 | }
|
23955 | this.isPropagationStopped = emptyFunction.thatReturnsFalse;
|
23956 | return this;
|
23957 | }
|
23958 |
|
23959 | _assign(SyntheticEvent.prototype, {
|
23960 |
|
23961 | preventDefault: function () {
|
23962 | this.defaultPrevented = true;
|
23963 | var event = this.nativeEvent;
|
23964 | if (!event) {
|
23965 | return;
|
23966 | }
|
23967 |
|
23968 | if (event.preventDefault) {
|
23969 | event.preventDefault();
|
23970 | } else if (typeof event.returnValue !== 'unknown') {
|
23971 | // eslint-disable-line valid-typeof
|
23972 | event.returnValue = false;
|
23973 | }
|
23974 | this.isDefaultPrevented = emptyFunction.thatReturnsTrue;
|
23975 | },
|
23976 |
|
23977 | stopPropagation: function () {
|
23978 | var event = this.nativeEvent;
|
23979 | if (!event) {
|
23980 | return;
|
23981 | }
|
23982 |
|
23983 | if (event.stopPropagation) {
|
23984 | event.stopPropagation();
|
23985 | } else if (typeof event.cancelBubble !== 'unknown') {
|
23986 | // eslint-disable-line valid-typeof
|
23987 | // The ChangeEventPlugin registers a "propertychange" event for
|
23988 | // IE. This event does not support bubbling or cancelling, and
|
23989 | // any references to cancelBubble throw "Member not found". A
|
23990 | // typeof check of "unknown" circumvents this issue (and is also
|
23991 | // IE specific).
|
23992 | event.cancelBubble = true;
|
23993 | }
|
23994 |
|
23995 | this.isPropagationStopped = emptyFunction.thatReturnsTrue;
|
23996 | },
|
23997 |
|
23998 | /**
|
23999 | * We release all dispatched `SyntheticEvent`s after each event loop, adding
|
24000 | * them back into the pool. This allows a way to hold onto a reference that
|
24001 | * won't be added back into the pool.
|
24002 | */
|
24003 | persist: function () {
|
24004 | this.isPersistent = emptyFunction.thatReturnsTrue;
|
24005 | },
|
24006 |
|
24007 | /**
|
24008 | * Checks if this event should be released back into the pool.
|
24009 | *
|
24010 | * @return {boolean} True if this should not be released, false otherwise.
|
24011 | */
|
24012 | isPersistent: emptyFunction.thatReturnsFalse,
|
24013 |
|
24014 | /**
|
24015 | * `PooledClass` looks for `destructor` on each instance it releases.
|
24016 | */
|
24017 | destructor: function () {
|
24018 | var Interface = this.constructor.Interface;
|
24019 | for (var propName in Interface) {
|
24020 | if (process.env.NODE_ENV !== 'production') {
|
24021 | Object.defineProperty(this, propName, getPooledWarningPropertyDefinition(propName, Interface[propName]));
|
24022 | } else {
|
24023 | this[propName] = null;
|
24024 | }
|
24025 | }
|
24026 | for (var i = 0; i < shouldBeReleasedProperties.length; i++) {
|
24027 | this[shouldBeReleasedProperties[i]] = null;
|
24028 | }
|
24029 | if (process.env.NODE_ENV !== 'production') {
|
24030 | Object.defineProperty(this, 'nativeEvent', getPooledWarningPropertyDefinition('nativeEvent', null));
|
24031 | Object.defineProperty(this, 'preventDefault', getPooledWarningPropertyDefinition('preventDefault', emptyFunction));
|
24032 | Object.defineProperty(this, 'stopPropagation', getPooledWarningPropertyDefinition('stopPropagation', emptyFunction));
|
24033 | }
|
24034 | }
|
24035 |
|
24036 | });
|
24037 |
|
24038 | SyntheticEvent.Interface = EventInterface;
|
24039 |
|
24040 | if (process.env.NODE_ENV !== 'production') {
|
24041 | if (isProxySupported) {
|
24042 | /*eslint-disable no-func-assign */
|
24043 | SyntheticEvent = new Proxy(SyntheticEvent, {
|
24044 | construct: function (target, args) {
|
24045 | return this.apply(target, Object.create(target.prototype), args);
|
24046 | },
|
24047 | apply: function (constructor, that, args) {
|
24048 | return new Proxy(constructor.apply(that, args), {
|
24049 | set: function (target, prop, value) {
|
24050 | if (prop !== 'isPersistent' && !target.constructor.Interface.hasOwnProperty(prop) && shouldBeReleasedProperties.indexOf(prop) === -1) {
|
24051 | process.env.NODE_ENV !== 'production' ? warning(didWarnForAddedNewProperty || target.isPersistent(), 'This synthetic event is reused for performance reasons. If you\'re ' + 'seeing this, you\'re adding a new property in the synthetic event object. ' + 'The property is never released. See ' + 'https://fb.me/react-event-pooling for more information.') : void 0;
|
24052 | didWarnForAddedNewProperty = true;
|
24053 | }
|
24054 | target[prop] = value;
|
24055 | return true;
|
24056 | }
|
24057 | });
|
24058 | }
|
24059 | });
|
24060 | /*eslint-enable no-func-assign */
|
24061 | }
|
24062 | }
|
24063 | /**
|
24064 | * Helper to reduce boilerplate when creating subclasses.
|
24065 | *
|
24066 | * @param {function} Class
|
24067 | * @param {?object} Interface
|
24068 | */
|
24069 | SyntheticEvent.augmentClass = function (Class, Interface) {
|
24070 | var Super = this;
|
24071 |
|
24072 | var E = function () {};
|
24073 | E.prototype = Super.prototype;
|
24074 | var prototype = new E();
|
24075 |
|
24076 | _assign(prototype, Class.prototype);
|
24077 | Class.prototype = prototype;
|
24078 | Class.prototype.constructor = Class;
|
24079 |
|
24080 | Class.Interface = _assign({}, Super.Interface, Interface);
|
24081 | Class.augmentClass = Super.augmentClass;
|
24082 |
|
24083 | PooledClass.addPoolingTo(Class, PooledClass.fourArgumentPooler);
|
24084 | };
|
24085 |
|
24086 | PooledClass.addPoolingTo(SyntheticEvent, PooledClass.fourArgumentPooler);
|
24087 |
|
24088 | module.exports = SyntheticEvent;
|
24089 |
|
24090 | /**
|
24091 | * Helper to nullify syntheticEvent instance properties when destructing
|
24092 | *
|
24093 | * @param {object} SyntheticEvent
|
24094 | * @param {String} propName
|
24095 | * @return {object} defineProperty object
|
24096 | */
|
24097 | function getPooledWarningPropertyDefinition(propName, getVal) {
|
24098 | var isFunction = typeof getVal === 'function';
|
24099 | return {
|
24100 | configurable: true,
|
24101 | set: set,
|
24102 | get: get
|
24103 | };
|
24104 |
|
24105 | function set(val) {
|
24106 | var action = isFunction ? 'setting the method' : 'setting the property';
|
24107 | warn(action, 'This is effectively a no-op');
|
24108 | return val;
|
24109 | }
|
24110 |
|
24111 | function get() {
|
24112 | var action = isFunction ? 'accessing the method' : 'accessing the property';
|
24113 | var result = isFunction ? 'This is a no-op function' : 'This is set to null';
|
24114 | warn(action, result);
|
24115 | return getVal;
|
24116 | }
|
24117 |
|
24118 | function warn(action, result) {
|
24119 | var warningCondition = false;
|
24120 | process.env.NODE_ENV !== 'production' ? warning(warningCondition, 'This synthetic event is reused for performance reasons. If you\'re seeing this, ' + 'you\'re %s `%s` on a released/nullified synthetic event. %s. ' + 'If you must keep the original synthetic event around, use event.persist(). ' + 'See https://fb.me/react-event-pooling for more information.', action, propName, result) : void 0;
|
24121 | }
|
24122 | }
|
24123 | }).call(this,require('_process'))
|
24124 | },{"./PooledClass":177,"_process":144,"fbjs/lib/emptyFunction":116,"fbjs/lib/warning":131,"object-assign":143}],243:[function(require,module,exports){
|
24125 | /**
|
24126 | * Copyright 2013-present, Facebook, Inc.
|
24127 | * All rights reserved.
|
24128 | *
|
24129 | * This source code is licensed under the BSD-style license found in the
|
24130 | * LICENSE file in the root directory of this source tree. An additional grant
|
24131 | * of patent rights can be found in the PATENTS file in the same directory.
|
24132 | *
|
24133 | */
|
24134 |
|
24135 | 'use strict';
|
24136 |
|
24137 | var SyntheticUIEvent = require('./SyntheticUIEvent');
|
24138 |
|
24139 | /**
|
24140 | * @interface FocusEvent
|
24141 | * @see http://www.w3.org/TR/DOM-Level-3-Events/
|
24142 | */
|
24143 | var FocusEventInterface = {
|
24144 | relatedTarget: null
|
24145 | };
|
24146 |
|
24147 | /**
|
24148 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
24149 | * @param {string} dispatchMarker Marker identifying the event target.
|
24150 | * @param {object} nativeEvent Native browser event.
|
24151 | * @extends {SyntheticUIEvent}
|
24152 | */
|
24153 | function SyntheticFocusEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
24154 | return SyntheticUIEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
24155 | }
|
24156 |
|
24157 | SyntheticUIEvent.augmentClass(SyntheticFocusEvent, FocusEventInterface);
|
24158 |
|
24159 | module.exports = SyntheticFocusEvent;
|
24160 | },{"./SyntheticUIEvent":249}],244:[function(require,module,exports){
|
24161 | /**
|
24162 | * Copyright 2013-present, Facebook, Inc.
|
24163 | * All rights reserved.
|
24164 | *
|
24165 | * This source code is licensed under the BSD-style license found in the
|
24166 | * LICENSE file in the root directory of this source tree. An additional grant
|
24167 | * of patent rights can be found in the PATENTS file in the same directory.
|
24168 | *
|
24169 | */
|
24170 |
|
24171 | 'use strict';
|
24172 |
|
24173 | var SyntheticEvent = require('./SyntheticEvent');
|
24174 |
|
24175 | /**
|
24176 | * @interface Event
|
24177 | * @see http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105
|
24178 | * /#events-inputevents
|
24179 | */
|
24180 | var InputEventInterface = {
|
24181 | data: null
|
24182 | };
|
24183 |
|
24184 | /**
|
24185 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
24186 | * @param {string} dispatchMarker Marker identifying the event target.
|
24187 | * @param {object} nativeEvent Native browser event.
|
24188 | * @extends {SyntheticUIEvent}
|
24189 | */
|
24190 | function SyntheticInputEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
24191 | return SyntheticEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
24192 | }
|
24193 |
|
24194 | SyntheticEvent.augmentClass(SyntheticInputEvent, InputEventInterface);
|
24195 |
|
24196 | module.exports = SyntheticInputEvent;
|
24197 | },{"./SyntheticEvent":242}],245:[function(require,module,exports){
|
24198 | /**
|
24199 | * Copyright 2013-present, Facebook, Inc.
|
24200 | * All rights reserved.
|
24201 | *
|
24202 | * This source code is licensed under the BSD-style license found in the
|
24203 | * LICENSE file in the root directory of this source tree. An additional grant
|
24204 | * of patent rights can be found in the PATENTS file in the same directory.
|
24205 | *
|
24206 | */
|
24207 |
|
24208 | 'use strict';
|
24209 |
|
24210 | var SyntheticUIEvent = require('./SyntheticUIEvent');
|
24211 |
|
24212 | var getEventCharCode = require('./getEventCharCode');
|
24213 | var getEventKey = require('./getEventKey');
|
24214 | var getEventModifierState = require('./getEventModifierState');
|
24215 |
|
24216 | /**
|
24217 | * @interface KeyboardEvent
|
24218 | * @see http://www.w3.org/TR/DOM-Level-3-Events/
|
24219 | */
|
24220 | var KeyboardEventInterface = {
|
24221 | key: getEventKey,
|
24222 | location: null,
|
24223 | ctrlKey: null,
|
24224 | shiftKey: null,
|
24225 | altKey: null,
|
24226 | metaKey: null,
|
24227 | repeat: null,
|
24228 | locale: null,
|
24229 | getModifierState: getEventModifierState,
|
24230 | // Legacy Interface
|
24231 | charCode: function (event) {
|
24232 | // `charCode` is the result of a KeyPress event and represents the value of
|
24233 | // the actual printable character.
|
24234 |
|
24235 | // KeyPress is deprecated, but its replacement is not yet final and not
|
24236 | // implemented in any major browser. Only KeyPress has charCode.
|
24237 | if (event.type === 'keypress') {
|
24238 | return getEventCharCode(event);
|
24239 | }
|
24240 | return 0;
|
24241 | },
|
24242 | keyCode: function (event) {
|
24243 | // `keyCode` is the result of a KeyDown/Up event and represents the value of
|
24244 | // physical keyboard key.
|
24245 |
|
24246 | // The actual meaning of the value depends on the users' keyboard layout
|
24247 | // which cannot be detected. Assuming that it is a US keyboard layout
|
24248 | // provides a surprisingly accurate mapping for US and European users.
|
24249 | // Due to this, it is left to the user to implement at this time.
|
24250 | if (event.type === 'keydown' || event.type === 'keyup') {
|
24251 | return event.keyCode;
|
24252 | }
|
24253 | return 0;
|
24254 | },
|
24255 | which: function (event) {
|
24256 | // `which` is an alias for either `keyCode` or `charCode` depending on the
|
24257 | // type of the event.
|
24258 | if (event.type === 'keypress') {
|
24259 | return getEventCharCode(event);
|
24260 | }
|
24261 | if (event.type === 'keydown' || event.type === 'keyup') {
|
24262 | return event.keyCode;
|
24263 | }
|
24264 | return 0;
|
24265 | }
|
24266 | };
|
24267 |
|
24268 | /**
|
24269 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
24270 | * @param {string} dispatchMarker Marker identifying the event target.
|
24271 | * @param {object} nativeEvent Native browser event.
|
24272 | * @extends {SyntheticUIEvent}
|
24273 | */
|
24274 | function SyntheticKeyboardEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
24275 | return SyntheticUIEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
24276 | }
|
24277 |
|
24278 | SyntheticUIEvent.augmentClass(SyntheticKeyboardEvent, KeyboardEventInterface);
|
24279 |
|
24280 | module.exports = SyntheticKeyboardEvent;
|
24281 | },{"./SyntheticUIEvent":249,"./getEventCharCode":262,"./getEventKey":263,"./getEventModifierState":264}],246:[function(require,module,exports){
|
24282 | /**
|
24283 | * Copyright 2013-present, Facebook, Inc.
|
24284 | * All rights reserved.
|
24285 | *
|
24286 | * This source code is licensed under the BSD-style license found in the
|
24287 | * LICENSE file in the root directory of this source tree. An additional grant
|
24288 | * of patent rights can be found in the PATENTS file in the same directory.
|
24289 | *
|
24290 | */
|
24291 |
|
24292 | 'use strict';
|
24293 |
|
24294 | var SyntheticUIEvent = require('./SyntheticUIEvent');
|
24295 | var ViewportMetrics = require('./ViewportMetrics');
|
24296 |
|
24297 | var getEventModifierState = require('./getEventModifierState');
|
24298 |
|
24299 | /**
|
24300 | * @interface MouseEvent
|
24301 | * @see http://www.w3.org/TR/DOM-Level-3-Events/
|
24302 | */
|
24303 | var MouseEventInterface = {
|
24304 | screenX: null,
|
24305 | screenY: null,
|
24306 | clientX: null,
|
24307 | clientY: null,
|
24308 | ctrlKey: null,
|
24309 | shiftKey: null,
|
24310 | altKey: null,
|
24311 | metaKey: null,
|
24312 | getModifierState: getEventModifierState,
|
24313 | button: function (event) {
|
24314 | // Webkit, Firefox, IE9+
|
24315 | // which: 1 2 3
|
24316 | // button: 0 1 2 (standard)
|
24317 | var button = event.button;
|
24318 | if ('which' in event) {
|
24319 | return button;
|
24320 | }
|
24321 | // IE<9
|
24322 | // which: undefined
|
24323 | // button: 0 0 0
|
24324 | // button: 1 4 2 (onmouseup)
|
24325 | return button === 2 ? 2 : button === 4 ? 1 : 0;
|
24326 | },
|
24327 | buttons: null,
|
24328 | relatedTarget: function (event) {
|
24329 | return event.relatedTarget || (event.fromElement === event.srcElement ? event.toElement : event.fromElement);
|
24330 | },
|
24331 | // "Proprietary" Interface.
|
24332 | pageX: function (event) {
|
24333 | return 'pageX' in event ? event.pageX : event.clientX + ViewportMetrics.currentScrollLeft;
|
24334 | },
|
24335 | pageY: function (event) {
|
24336 | return 'pageY' in event ? event.pageY : event.clientY + ViewportMetrics.currentScrollTop;
|
24337 | }
|
24338 | };
|
24339 |
|
24340 | /**
|
24341 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
24342 | * @param {string} dispatchMarker Marker identifying the event target.
|
24343 | * @param {object} nativeEvent Native browser event.
|
24344 | * @extends {SyntheticUIEvent}
|
24345 | */
|
24346 | function SyntheticMouseEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
24347 | return SyntheticUIEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
24348 | }
|
24349 |
|
24350 | SyntheticUIEvent.augmentClass(SyntheticMouseEvent, MouseEventInterface);
|
24351 |
|
24352 | module.exports = SyntheticMouseEvent;
|
24353 | },{"./SyntheticUIEvent":249,"./ViewportMetrics":252,"./getEventModifierState":264}],247:[function(require,module,exports){
|
24354 | /**
|
24355 | * Copyright 2013-present, Facebook, Inc.
|
24356 | * All rights reserved.
|
24357 | *
|
24358 | * This source code is licensed under the BSD-style license found in the
|
24359 | * LICENSE file in the root directory of this source tree. An additional grant
|
24360 | * of patent rights can be found in the PATENTS file in the same directory.
|
24361 | *
|
24362 | */
|
24363 |
|
24364 | 'use strict';
|
24365 |
|
24366 | var SyntheticUIEvent = require('./SyntheticUIEvent');
|
24367 |
|
24368 | var getEventModifierState = require('./getEventModifierState');
|
24369 |
|
24370 | /**
|
24371 | * @interface TouchEvent
|
24372 | * @see http://www.w3.org/TR/touch-events/
|
24373 | */
|
24374 | var TouchEventInterface = {
|
24375 | touches: null,
|
24376 | targetTouches: null,
|
24377 | changedTouches: null,
|
24378 | altKey: null,
|
24379 | metaKey: null,
|
24380 | ctrlKey: null,
|
24381 | shiftKey: null,
|
24382 | getModifierState: getEventModifierState
|
24383 | };
|
24384 |
|
24385 | /**
|
24386 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
24387 | * @param {string} dispatchMarker Marker identifying the event target.
|
24388 | * @param {object} nativeEvent Native browser event.
|
24389 | * @extends {SyntheticUIEvent}
|
24390 | */
|
24391 | function SyntheticTouchEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
24392 | return SyntheticUIEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
24393 | }
|
24394 |
|
24395 | SyntheticUIEvent.augmentClass(SyntheticTouchEvent, TouchEventInterface);
|
24396 |
|
24397 | module.exports = SyntheticTouchEvent;
|
24398 | },{"./SyntheticUIEvent":249,"./getEventModifierState":264}],248:[function(require,module,exports){
|
24399 | /**
|
24400 | * Copyright 2013-present, Facebook, Inc.
|
24401 | * All rights reserved.
|
24402 | *
|
24403 | * This source code is licensed under the BSD-style license found in the
|
24404 | * LICENSE file in the root directory of this source tree. An additional grant
|
24405 | * of patent rights can be found in the PATENTS file in the same directory.
|
24406 | *
|
24407 | */
|
24408 |
|
24409 | 'use strict';
|
24410 |
|
24411 | var SyntheticEvent = require('./SyntheticEvent');
|
24412 |
|
24413 | /**
|
24414 | * @interface Event
|
24415 | * @see http://www.w3.org/TR/2009/WD-css3-transitions-20090320/#transition-events-
|
24416 | * @see https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent
|
24417 | */
|
24418 | var TransitionEventInterface = {
|
24419 | propertyName: null,
|
24420 | elapsedTime: null,
|
24421 | pseudoElement: null
|
24422 | };
|
24423 |
|
24424 | /**
|
24425 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
24426 | * @param {string} dispatchMarker Marker identifying the event target.
|
24427 | * @param {object} nativeEvent Native browser event.
|
24428 | * @extends {SyntheticEvent}
|
24429 | */
|
24430 | function SyntheticTransitionEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
24431 | return SyntheticEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
24432 | }
|
24433 |
|
24434 | SyntheticEvent.augmentClass(SyntheticTransitionEvent, TransitionEventInterface);
|
24435 |
|
24436 | module.exports = SyntheticTransitionEvent;
|
24437 | },{"./SyntheticEvent":242}],249:[function(require,module,exports){
|
24438 | /**
|
24439 | * Copyright 2013-present, Facebook, Inc.
|
24440 | * All rights reserved.
|
24441 | *
|
24442 | * This source code is licensed under the BSD-style license found in the
|
24443 | * LICENSE file in the root directory of this source tree. An additional grant
|
24444 | * of patent rights can be found in the PATENTS file in the same directory.
|
24445 | *
|
24446 | */
|
24447 |
|
24448 | 'use strict';
|
24449 |
|
24450 | var SyntheticEvent = require('./SyntheticEvent');
|
24451 |
|
24452 | var getEventTarget = require('./getEventTarget');
|
24453 |
|
24454 | /**
|
24455 | * @interface UIEvent
|
24456 | * @see http://www.w3.org/TR/DOM-Level-3-Events/
|
24457 | */
|
24458 | var UIEventInterface = {
|
24459 | view: function (event) {
|
24460 | if (event.view) {
|
24461 | return event.view;
|
24462 | }
|
24463 |
|
24464 | var target = getEventTarget(event);
|
24465 | if (target.window === target) {
|
24466 | // target is a window object
|
24467 | return target;
|
24468 | }
|
24469 |
|
24470 | var doc = target.ownerDocument;
|
24471 | // TODO: Figure out why `ownerDocument` is sometimes undefined in IE8.
|
24472 | if (doc) {
|
24473 | return doc.defaultView || doc.parentWindow;
|
24474 | } else {
|
24475 | return window;
|
24476 | }
|
24477 | },
|
24478 | detail: function (event) {
|
24479 | return event.detail || 0;
|
24480 | }
|
24481 | };
|
24482 |
|
24483 | /**
|
24484 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
24485 | * @param {string} dispatchMarker Marker identifying the event target.
|
24486 | * @param {object} nativeEvent Native browser event.
|
24487 | * @extends {SyntheticEvent}
|
24488 | */
|
24489 | function SyntheticUIEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
24490 | return SyntheticEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
24491 | }
|
24492 |
|
24493 | SyntheticEvent.augmentClass(SyntheticUIEvent, UIEventInterface);
|
24494 |
|
24495 | module.exports = SyntheticUIEvent;
|
24496 | },{"./SyntheticEvent":242,"./getEventTarget":265}],250:[function(require,module,exports){
|
24497 | /**
|
24498 | * Copyright 2013-present, Facebook, Inc.
|
24499 | * All rights reserved.
|
24500 | *
|
24501 | * This source code is licensed under the BSD-style license found in the
|
24502 | * LICENSE file in the root directory of this source tree. An additional grant
|
24503 | * of patent rights can be found in the PATENTS file in the same directory.
|
24504 | *
|
24505 | */
|
24506 |
|
24507 | 'use strict';
|
24508 |
|
24509 | var SyntheticMouseEvent = require('./SyntheticMouseEvent');
|
24510 |
|
24511 | /**
|
24512 | * @interface WheelEvent
|
24513 | * @see http://www.w3.org/TR/DOM-Level-3-Events/
|
24514 | */
|
24515 | var WheelEventInterface = {
|
24516 | deltaX: function (event) {
|
24517 | return 'deltaX' in event ? event.deltaX :
|
24518 | // Fallback to `wheelDeltaX` for Webkit and normalize (right is positive).
|
24519 | 'wheelDeltaX' in event ? -event.wheelDeltaX : 0;
|
24520 | },
|
24521 | deltaY: function (event) {
|
24522 | return 'deltaY' in event ? event.deltaY :
|
24523 | // Fallback to `wheelDeltaY` for Webkit and normalize (down is positive).
|
24524 | 'wheelDeltaY' in event ? -event.wheelDeltaY :
|
24525 | // Fallback to `wheelDelta` for IE<9 and normalize (down is positive).
|
24526 | 'wheelDelta' in event ? -event.wheelDelta : 0;
|
24527 | },
|
24528 | deltaZ: null,
|
24529 |
|
24530 | // Browsers without "deltaMode" is reporting in raw wheel delta where one
|
24531 | // notch on the scroll is always +/- 120, roughly equivalent to pixels.
|
24532 | // A good approximation of DOM_DELTA_LINE (1) is 5% of viewport size or
|
24533 | // ~40 pixels, for DOM_DELTA_SCREEN (2) it is 87.5% of viewport size.
|
24534 | deltaMode: null
|
24535 | };
|
24536 |
|
24537 | /**
|
24538 | * @param {object} dispatchConfig Configuration used to dispatch this event.
|
24539 | * @param {string} dispatchMarker Marker identifying the event target.
|
24540 | * @param {object} nativeEvent Native browser event.
|
24541 | * @extends {SyntheticMouseEvent}
|
24542 | */
|
24543 | function SyntheticWheelEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
|
24544 | return SyntheticMouseEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
|
24545 | }
|
24546 |
|
24547 | SyntheticMouseEvent.augmentClass(SyntheticWheelEvent, WheelEventInterface);
|
24548 |
|
24549 | module.exports = SyntheticWheelEvent;
|
24550 | },{"./SyntheticMouseEvent":246}],251:[function(require,module,exports){
|
24551 | (function (process){
|
24552 | /**
|
24553 | * Copyright 2013-present, Facebook, Inc.
|
24554 | * All rights reserved.
|
24555 | *
|
24556 | * This source code is licensed under the BSD-style license found in the
|
24557 | * LICENSE file in the root directory of this source tree. An additional grant
|
24558 | * of patent rights can be found in the PATENTS file in the same directory.
|
24559 | *
|
24560 | *
|
24561 | */
|
24562 |
|
24563 | 'use strict';
|
24564 |
|
24565 | var _prodInvariant = require('./reactProdInvariant');
|
24566 |
|
24567 | var invariant = require('fbjs/lib/invariant');
|
24568 |
|
24569 | var OBSERVED_ERROR = {};
|
24570 |
|
24571 | /**
|
24572 | * `Transaction` creates a black box that is able to wrap any method such that
|
24573 | * certain invariants are maintained before and after the method is invoked
|
24574 | * (Even if an exception is thrown while invoking the wrapped method). Whoever
|
24575 | * instantiates a transaction can provide enforcers of the invariants at
|
24576 | * creation time. The `Transaction` class itself will supply one additional
|
24577 | * automatic invariant for you - the invariant that any transaction instance
|
24578 | * should not be run while it is already being run. You would typically create a
|
24579 | * single instance of a `Transaction` for reuse multiple times, that potentially
|
24580 | * is used to wrap several different methods. Wrappers are extremely simple -
|
24581 | * they only require implementing two methods.
|
24582 | *
|
24583 | * <pre>
|
24584 | * wrappers (injected at creation time)
|
24585 | * + +
|
24586 | * | |
|
24587 | * +-----------------|--------|--------------+
|
24588 | * | v | |
|
24589 | * | +---------------+ | |
|
24590 | * | +--| wrapper1 |---|----+ |
|
24591 | * | | +---------------+ v | |
|
24592 | * | | +-------------+ | |
|
24593 | * | | +----| wrapper2 |--------+ |
|
24594 | * | | | +-------------+ | | |
|
24595 | * | | | | | |
|
24596 | * | v v v v | wrapper
|
24597 | * | +---+ +---+ +---------+ +---+ +---+ | invariants
|
24598 | * perform(anyMethod) | | | | | | | | | | | | maintained
|
24599 | * +----------------->|-|---|-|---|-->|anyMethod|---|---|-|---|-|-------->
|
24600 | * | | | | | | | | | | | |
|
24601 | * | | | | | | | | | | | |
|
24602 | * | | | | | | | | | | | |
|
24603 | * | +---+ +---+ +---------+ +---+ +---+ |
|
24604 | * | initialize close |
|
24605 | * +-----------------------------------------+
|
24606 | * </pre>
|
24607 | *
|
24608 | * Use cases:
|
24609 | * - Preserving the input selection ranges before/after reconciliation.
|
24610 | * Restoring selection even in the event of an unexpected error.
|
24611 | * - Deactivating events while rearranging the DOM, preventing blurs/focuses,
|
24612 | * while guaranteeing that afterwards, the event system is reactivated.
|
24613 | * - Flushing a queue of collected DOM mutations to the main UI thread after a
|
24614 | * reconciliation takes place in a worker thread.
|
24615 | * - Invoking any collected `componentDidUpdate` callbacks after rendering new
|
24616 | * content.
|
24617 | * - (Future use case): Wrapping particular flushes of the `ReactWorker` queue
|
24618 | * to preserve the `scrollTop` (an automatic scroll aware DOM).
|
24619 | * - (Future use case): Layout calculations before and after DOM updates.
|
24620 | *
|
24621 | * Transactional plugin API:
|
24622 | * - A module that has an `initialize` method that returns any precomputation.
|
24623 | * - and a `close` method that accepts the precomputation. `close` is invoked
|
24624 | * when the wrapped process is completed, or has failed.
|
24625 | *
|
24626 | * @param {Array<TransactionalWrapper>} transactionWrapper Wrapper modules
|
24627 | * that implement `initialize` and `close`.
|
24628 | * @return {Transaction} Single transaction for reuse in thread.
|
24629 | *
|
24630 | * @class Transaction
|
24631 | */
|
24632 | var TransactionImpl = {
|
24633 | /**
|
24634 | * Sets up this instance so that it is prepared for collecting metrics. Does
|
24635 | * so such that this setup method may be used on an instance that is already
|
24636 | * initialized, in a way that does not consume additional memory upon reuse.
|
24637 | * That can be useful if you decide to make your subclass of this mixin a
|
24638 | * "PooledClass".
|
24639 | */
|
24640 | reinitializeTransaction: function () {
|
24641 | this.transactionWrappers = this.getTransactionWrappers();
|
24642 | if (this.wrapperInitData) {
|
24643 | this.wrapperInitData.length = 0;
|
24644 | } else {
|
24645 | this.wrapperInitData = [];
|
24646 | }
|
24647 | this._isInTransaction = false;
|
24648 | },
|
24649 |
|
24650 | _isInTransaction: false,
|
24651 |
|
24652 | /**
|
24653 | * @abstract
|
24654 | * @return {Array<TransactionWrapper>} Array of transaction wrappers.
|
24655 | */
|
24656 | getTransactionWrappers: null,
|
24657 |
|
24658 | isInTransaction: function () {
|
24659 | return !!this._isInTransaction;
|
24660 | },
|
24661 |
|
24662 | /**
|
24663 | * Executes the function within a safety window. Use this for the top level
|
24664 | * methods that result in large amounts of computation/mutations that would
|
24665 | * need to be safety checked. The optional arguments helps prevent the need
|
24666 | * to bind in many cases.
|
24667 | *
|
24668 | * @param {function} method Member of scope to call.
|
24669 | * @param {Object} scope Scope to invoke from.
|
24670 | * @param {Object?=} a Argument to pass to the method.
|
24671 | * @param {Object?=} b Argument to pass to the method.
|
24672 | * @param {Object?=} c Argument to pass to the method.
|
24673 | * @param {Object?=} d Argument to pass to the method.
|
24674 | * @param {Object?=} e Argument to pass to the method.
|
24675 | * @param {Object?=} f Argument to pass to the method.
|
24676 | *
|
24677 | * @return {*} Return value from `method`.
|
24678 | */
|
24679 | perform: function (method, scope, a, b, c, d, e, f) {
|
24680 | !!this.isInTransaction() ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Transaction.perform(...): Cannot initialize a transaction when there is already an outstanding transaction.') : _prodInvariant('27') : void 0;
|
24681 | var errorThrown;
|
24682 | var ret;
|
24683 | try {
|
24684 | this._isInTransaction = true;
|
24685 | // Catching errors makes debugging more difficult, so we start with
|
24686 | // errorThrown set to true before setting it to false after calling
|
24687 | // close -- if it's still set to true in the finally block, it means
|
24688 | // one of these calls threw.
|
24689 | errorThrown = true;
|
24690 | this.initializeAll(0);
|
24691 | ret = method.call(scope, a, b, c, d, e, f);
|
24692 | errorThrown = false;
|
24693 | } finally {
|
24694 | try {
|
24695 | if (errorThrown) {
|
24696 | // If `method` throws, prefer to show that stack trace over any thrown
|
24697 | // by invoking `closeAll`.
|
24698 | try {
|
24699 | this.closeAll(0);
|
24700 | } catch (err) {}
|
24701 | } else {
|
24702 | // Since `method` didn't throw, we don't want to silence the exception
|
24703 | // here.
|
24704 | this.closeAll(0);
|
24705 | }
|
24706 | } finally {
|
24707 | this._isInTransaction = false;
|
24708 | }
|
24709 | }
|
24710 | return ret;
|
24711 | },
|
24712 |
|
24713 | initializeAll: function (startIndex) {
|
24714 | var transactionWrappers = this.transactionWrappers;
|
24715 | for (var i = startIndex; i < transactionWrappers.length; i++) {
|
24716 | var wrapper = transactionWrappers[i];
|
24717 | try {
|
24718 | // Catching errors makes debugging more difficult, so we start with the
|
24719 | // OBSERVED_ERROR state before overwriting it with the real return value
|
24720 | // of initialize -- if it's still set to OBSERVED_ERROR in the finally
|
24721 | // block, it means wrapper.initialize threw.
|
24722 | this.wrapperInitData[i] = OBSERVED_ERROR;
|
24723 | this.wrapperInitData[i] = wrapper.initialize ? wrapper.initialize.call(this) : null;
|
24724 | } finally {
|
24725 | if (this.wrapperInitData[i] === OBSERVED_ERROR) {
|
24726 | // The initializer for wrapper i threw an error; initialize the
|
24727 | // remaining wrappers but silence any exceptions from them to ensure
|
24728 | // that the first error is the one to bubble up.
|
24729 | try {
|
24730 | this.initializeAll(i + 1);
|
24731 | } catch (err) {}
|
24732 | }
|
24733 | }
|
24734 | }
|
24735 | },
|
24736 |
|
24737 | /**
|
24738 | * Invokes each of `this.transactionWrappers.close[i]` functions, passing into
|
24739 | * them the respective return values of `this.transactionWrappers.init[i]`
|
24740 | * (`close`rs that correspond to initializers that failed will not be
|
24741 | * invoked).
|
24742 | */
|
24743 | closeAll: function (startIndex) {
|
24744 | !this.isInTransaction() ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Transaction.closeAll(): Cannot close transaction when none are open.') : _prodInvariant('28') : void 0;
|
24745 | var transactionWrappers = this.transactionWrappers;
|
24746 | for (var i = startIndex; i < transactionWrappers.length; i++) {
|
24747 | var wrapper = transactionWrappers[i];
|
24748 | var initData = this.wrapperInitData[i];
|
24749 | var errorThrown;
|
24750 | try {
|
24751 | // Catching errors makes debugging more difficult, so we start with
|
24752 | // errorThrown set to true before setting it to false after calling
|
24753 | // close -- if it's still set to true in the finally block, it means
|
24754 | // wrapper.close threw.
|
24755 | errorThrown = true;
|
24756 | if (initData !== OBSERVED_ERROR && wrapper.close) {
|
24757 | wrapper.close.call(this, initData);
|
24758 | }
|
24759 | errorThrown = false;
|
24760 | } finally {
|
24761 | if (errorThrown) {
|
24762 | // The closer for wrapper i threw an error; close the remaining
|
24763 | // wrappers but silence any exceptions from them to ensure that the
|
24764 | // first error is the one to bubble up.
|
24765 | try {
|
24766 | this.closeAll(i + 1);
|
24767 | } catch (e) {}
|
24768 | }
|
24769 | }
|
24770 | }
|
24771 | this.wrapperInitData.length = 0;
|
24772 | }
|
24773 | };
|
24774 |
|
24775 | module.exports = TransactionImpl;
|
24776 | }).call(this,require('_process'))
|
24777 | },{"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],252:[function(require,module,exports){
|
24778 | /**
|
24779 | * Copyright 2013-present, Facebook, Inc.
|
24780 | * All rights reserved.
|
24781 | *
|
24782 | * This source code is licensed under the BSD-style license found in the
|
24783 | * LICENSE file in the root directory of this source tree. An additional grant
|
24784 | * of patent rights can be found in the PATENTS file in the same directory.
|
24785 | *
|
24786 | */
|
24787 |
|
24788 | 'use strict';
|
24789 |
|
24790 | var ViewportMetrics = {
|
24791 |
|
24792 | currentScrollLeft: 0,
|
24793 |
|
24794 | currentScrollTop: 0,
|
24795 |
|
24796 | refreshScrollValues: function (scrollPosition) {
|
24797 | ViewportMetrics.currentScrollLeft = scrollPosition.x;
|
24798 | ViewportMetrics.currentScrollTop = scrollPosition.y;
|
24799 | }
|
24800 |
|
24801 | };
|
24802 |
|
24803 | module.exports = ViewportMetrics;
|
24804 | },{}],253:[function(require,module,exports){
|
24805 | (function (process){
|
24806 | /**
|
24807 | * Copyright 2014-present, Facebook, Inc.
|
24808 | * All rights reserved.
|
24809 | *
|
24810 | * This source code is licensed under the BSD-style license found in the
|
24811 | * LICENSE file in the root directory of this source tree. An additional grant
|
24812 | * of patent rights can be found in the PATENTS file in the same directory.
|
24813 | *
|
24814 | *
|
24815 | */
|
24816 |
|
24817 | 'use strict';
|
24818 |
|
24819 | var _prodInvariant = require('./reactProdInvariant');
|
24820 |
|
24821 | var invariant = require('fbjs/lib/invariant');
|
24822 |
|
24823 | /**
|
24824 | * Accumulates items that must not be null or undefined into the first one. This
|
24825 | * is used to conserve memory by avoiding array allocations, and thus sacrifices
|
24826 | * API cleanness. Since `current` can be null before being passed in and not
|
24827 | * null after this function, make sure to assign it back to `current`:
|
24828 | *
|
24829 | * `a = accumulateInto(a, b);`
|
24830 | *
|
24831 | * This API should be sparingly used. Try `accumulate` for something cleaner.
|
24832 | *
|
24833 | * @return {*|array<*>} An accumulation of items.
|
24834 | */
|
24835 |
|
24836 | function accumulateInto(current, next) {
|
24837 | !(next != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : _prodInvariant('30') : void 0;
|
24838 |
|
24839 | if (current == null) {
|
24840 | return next;
|
24841 | }
|
24842 |
|
24843 | // Both are not empty. Warning: Never call x.concat(y) when you are not
|
24844 | // certain that x is an Array (x could be a string with concat method).
|
24845 | if (Array.isArray(current)) {
|
24846 | if (Array.isArray(next)) {
|
24847 | current.push.apply(current, next);
|
24848 | return current;
|
24849 | }
|
24850 | current.push(next);
|
24851 | return current;
|
24852 | }
|
24853 |
|
24854 | if (Array.isArray(next)) {
|
24855 | // A bit too dangerous to mutate `next`.
|
24856 | return [current].concat(next);
|
24857 | }
|
24858 |
|
24859 | return [current, next];
|
24860 | }
|
24861 |
|
24862 | module.exports = accumulateInto;
|
24863 | }).call(this,require('_process'))
|
24864 | },{"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124}],254:[function(require,module,exports){
|
24865 | /**
|
24866 | * Copyright 2013-present, Facebook, Inc.
|
24867 | * All rights reserved.
|
24868 | *
|
24869 | * This source code is licensed under the BSD-style license found in the
|
24870 | * LICENSE file in the root directory of this source tree. An additional grant
|
24871 | * of patent rights can be found in the PATENTS file in the same directory.
|
24872 | *
|
24873 | *
|
24874 | */
|
24875 |
|
24876 | 'use strict';
|
24877 |
|
24878 | var MOD = 65521;
|
24879 |
|
24880 | // adler32 is not cryptographically strong, and is only used to sanity check that
|
24881 | // markup generated on the server matches the markup generated on the client.
|
24882 | // This implementation (a modified version of the SheetJS version) has been optimized
|
24883 | // for our use case, at the expense of conforming to the adler32 specification
|
24884 | // for non-ascii inputs.
|
24885 | function adler32(data) {
|
24886 | var a = 1;
|
24887 | var b = 0;
|
24888 | var i = 0;
|
24889 | var l = data.length;
|
24890 | var m = l & ~0x3;
|
24891 | while (i < m) {
|
24892 | var n = Math.min(i + 4096, m);
|
24893 | for (; i < n; i += 4) {
|
24894 | b += (a += data.charCodeAt(i)) + (a += data.charCodeAt(i + 1)) + (a += data.charCodeAt(i + 2)) + (a += data.charCodeAt(i + 3));
|
24895 | }
|
24896 | a %= MOD;
|
24897 | b %= MOD;
|
24898 | }
|
24899 | for (; i < l; i++) {
|
24900 | b += a += data.charCodeAt(i);
|
24901 | }
|
24902 | a %= MOD;
|
24903 | b %= MOD;
|
24904 | return a | b << 16;
|
24905 | }
|
24906 |
|
24907 | module.exports = adler32;
|
24908 | },{}],255:[function(require,module,exports){
|
24909 | (function (process){
|
24910 | /**
|
24911 | * Copyright 2013-present, Facebook, Inc.
|
24912 | * All rights reserved.
|
24913 | *
|
24914 | * This source code is licensed under the BSD-style license found in the
|
24915 | * LICENSE file in the root directory of this source tree. An additional grant
|
24916 | * of patent rights can be found in the PATENTS file in the same directory.
|
24917 | *
|
24918 | */
|
24919 |
|
24920 | 'use strict';
|
24921 |
|
24922 | var _prodInvariant = require('./reactProdInvariant');
|
24923 |
|
24924 | var ReactPropTypeLocationNames = require('./ReactPropTypeLocationNames');
|
24925 | var ReactPropTypesSecret = require('./ReactPropTypesSecret');
|
24926 |
|
24927 | var invariant = require('fbjs/lib/invariant');
|
24928 | var warning = require('fbjs/lib/warning');
|
24929 |
|
24930 | var ReactComponentTreeHook;
|
24931 |
|
24932 | if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'test') {
|
24933 | // Temporary hack.
|
24934 | // Inline requires don't work well with Jest:
|
24935 | // https://github.com/facebook/react/issues/7240
|
24936 | // Remove the inline requires when we don't need them anymore:
|
24937 | // https://github.com/facebook/react/pull/7178
|
24938 | ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
24939 | }
|
24940 |
|
24941 | var loggedTypeFailures = {};
|
24942 |
|
24943 | /**
|
24944 | * Assert that the values match with the type specs.
|
24945 | * Error messages are memorized and will only be shown once.
|
24946 | *
|
24947 | * @param {object} typeSpecs Map of name to a ReactPropType
|
24948 | * @param {object} values Runtime values that need to be type-checked
|
24949 | * @param {string} location e.g. "prop", "context", "child context"
|
24950 | * @param {string} componentName Name of the component for error messages.
|
24951 | * @param {?object} element The React element that is being type-checked
|
24952 | * @param {?number} debugID The React component instance that is being type-checked
|
24953 | * @private
|
24954 | */
|
24955 | function checkReactTypeSpec(typeSpecs, values, location, componentName, element, debugID) {
|
24956 | for (var typeSpecName in typeSpecs) {
|
24957 | if (typeSpecs.hasOwnProperty(typeSpecName)) {
|
24958 | var error;
|
24959 | // Prop type validation may throw. In case they do, we don't want to
|
24960 | // fail the render phase where it didn't fail before. So we log it.
|
24961 | // After these have been cleaned up, we'll let them throw.
|
24962 | try {
|
24963 | // This is intentionally an invariant that gets caught. It's the same
|
24964 | // behavior as without this statement except with a better message.
|
24965 | !(typeof typeSpecs[typeSpecName] === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName) : _prodInvariant('84', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName) : void 0;
|
24966 | error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
|
24967 | } catch (ex) {
|
24968 | error = ex;
|
24969 | }
|
24970 | process.env.NODE_ENV !== 'production' ? warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName, typeof error) : void 0;
|
24971 | if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
24972 | // Only monitor this failure once because there tends to be a lot of the
|
24973 | // same error.
|
24974 | loggedTypeFailures[error.message] = true;
|
24975 |
|
24976 | var componentStackInfo = '';
|
24977 |
|
24978 | if (process.env.NODE_ENV !== 'production') {
|
24979 | if (!ReactComponentTreeHook) {
|
24980 | ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
24981 | }
|
24982 | if (debugID !== null) {
|
24983 | componentStackInfo = ReactComponentTreeHook.getStackAddendumByID(debugID);
|
24984 | } else if (element !== null) {
|
24985 | componentStackInfo = ReactComponentTreeHook.getCurrentStackAddendum(element);
|
24986 | }
|
24987 | }
|
24988 |
|
24989 | process.env.NODE_ENV !== 'production' ? warning(false, 'Failed %s type: %s%s', location, error.message, componentStackInfo) : void 0;
|
24990 | }
|
24991 | }
|
24992 | }
|
24993 | }
|
24994 |
|
24995 | module.exports = checkReactTypeSpec;
|
24996 | }).call(this,require('_process'))
|
24997 | },{"./ReactPropTypeLocationNames":223,"./ReactPropTypesSecret":224,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131,"react/lib/ReactComponentTreeHook":291}],256:[function(require,module,exports){
|
24998 | /**
|
24999 | * Copyright 2013-present, Facebook, Inc.
|
25000 | * All rights reserved.
|
25001 | *
|
25002 | * This source code is licensed under the BSD-style license found in the
|
25003 | * LICENSE file in the root directory of this source tree. An additional grant
|
25004 | * of patent rights can be found in the PATENTS file in the same directory.
|
25005 | *
|
25006 | */
|
25007 |
|
25008 | /* globals MSApp */
|
25009 |
|
25010 | 'use strict';
|
25011 |
|
25012 | /**
|
25013 | * Create a function which has 'unsafe' privileges (required by windows8 apps)
|
25014 | */
|
25015 |
|
25016 | var createMicrosoftUnsafeLocalFunction = function (func) {
|
25017 | if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) {
|
25018 | return function (arg0, arg1, arg2, arg3) {
|
25019 | MSApp.execUnsafeLocalFunction(function () {
|
25020 | return func(arg0, arg1, arg2, arg3);
|
25021 | });
|
25022 | };
|
25023 | } else {
|
25024 | return func;
|
25025 | }
|
25026 | };
|
25027 |
|
25028 | module.exports = createMicrosoftUnsafeLocalFunction;
|
25029 | },{}],257:[function(require,module,exports){
|
25030 | (function (process){
|
25031 | /**
|
25032 | * Copyright 2013-present, Facebook, Inc.
|
25033 | * All rights reserved.
|
25034 | *
|
25035 | * This source code is licensed under the BSD-style license found in the
|
25036 | * LICENSE file in the root directory of this source tree. An additional grant
|
25037 | * of patent rights can be found in the PATENTS file in the same directory.
|
25038 | *
|
25039 | */
|
25040 |
|
25041 | 'use strict';
|
25042 |
|
25043 | var CSSProperty = require('./CSSProperty');
|
25044 | var warning = require('fbjs/lib/warning');
|
25045 |
|
25046 | var isUnitlessNumber = CSSProperty.isUnitlessNumber;
|
25047 | var styleWarnings = {};
|
25048 |
|
25049 | /**
|
25050 | * Convert a value into the proper css writable value. The style name `name`
|
25051 | * should be logical (no hyphens), as specified
|
25052 | * in `CSSProperty.isUnitlessNumber`.
|
25053 | *
|
25054 | * @param {string} name CSS property name such as `topMargin`.
|
25055 | * @param {*} value CSS property value such as `10px`.
|
25056 | * @param {ReactDOMComponent} component
|
25057 | * @return {string} Normalized style value with dimensions applied.
|
25058 | */
|
25059 | function dangerousStyleValue(name, value, component) {
|
25060 | // Note that we've removed escapeTextForBrowser() calls here since the
|
25061 | // whole string will be escaped when the attribute is injected into
|
25062 | // the markup. If you provide unsafe user data here they can inject
|
25063 | // arbitrary CSS which may be problematic (I couldn't repro this):
|
25064 | // https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
|
25065 | // http://www.thespanner.co.uk/2007/11/26/ultimate-xss-css-injection/
|
25066 | // This is not an XSS hole but instead a potential CSS injection issue
|
25067 | // which has lead to a greater discussion about how we're going to
|
25068 | // trust URLs moving forward. See #2115901
|
25069 |
|
25070 | var isEmpty = value == null || typeof value === 'boolean' || value === '';
|
25071 | if (isEmpty) {
|
25072 | return '';
|
25073 | }
|
25074 |
|
25075 | var isNonNumeric = isNaN(value);
|
25076 | if (isNonNumeric || value === 0 || isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name]) {
|
25077 | return '' + value; // cast to string
|
25078 | }
|
25079 |
|
25080 | if (typeof value === 'string') {
|
25081 | if (process.env.NODE_ENV !== 'production') {
|
25082 | // Allow '0' to pass through without warning. 0 is already special and
|
25083 | // doesn't require units, so we don't need to warn about it.
|
25084 | if (component && value !== '0') {
|
25085 | var owner = component._currentElement._owner;
|
25086 | var ownerName = owner ? owner.getName() : null;
|
25087 | if (ownerName && !styleWarnings[ownerName]) {
|
25088 | styleWarnings[ownerName] = {};
|
25089 | }
|
25090 | var warned = false;
|
25091 | if (ownerName) {
|
25092 | var warnings = styleWarnings[ownerName];
|
25093 | warned = warnings[name];
|
25094 | if (!warned) {
|
25095 | warnings[name] = true;
|
25096 | }
|
25097 | }
|
25098 | if (!warned) {
|
25099 | process.env.NODE_ENV !== 'production' ? warning(false, 'a `%s` tag (owner: `%s`) was passed a numeric string value ' + 'for CSS property `%s` (value: `%s`) which will be treated ' + 'as a unitless number in a future version of React.', component._currentElement.type, ownerName || 'unknown', name, value) : void 0;
|
25100 | }
|
25101 | }
|
25102 | }
|
25103 | value = value.trim();
|
25104 | }
|
25105 | return value + 'px';
|
25106 | }
|
25107 |
|
25108 | module.exports = dangerousStyleValue;
|
25109 | }).call(this,require('_process'))
|
25110 | },{"./CSSProperty":157,"_process":144,"fbjs/lib/warning":131}],258:[function(require,module,exports){
|
25111 | /**
|
25112 | * Copyright 2016-present, Facebook, Inc.
|
25113 | * All rights reserved.
|
25114 | *
|
25115 | * This source code is licensed under the BSD-style license found in the
|
25116 | * LICENSE file in the root directory of this source tree. An additional grant
|
25117 | * of patent rights can be found in the PATENTS file in the same directory.
|
25118 | *
|
25119 | * Based on the escape-html library, which is used under the MIT License below:
|
25120 | *
|
25121 | * Copyright (c) 2012-2013 TJ Holowaychuk
|
25122 | * Copyright (c) 2015 Andreas Lubbe
|
25123 | * Copyright (c) 2015 Tiancheng "Timothy" Gu
|
25124 | *
|
25125 | * Permission is hereby granted, free of charge, to any person obtaining
|
25126 | * a copy of this software and associated documentation files (the
|
25127 | * 'Software'), to deal in the Software without restriction, including
|
25128 | * without limitation the rights to use, copy, modify, merge, publish,
|
25129 | * distribute, sublicense, and/or sell copies of the Software, and to
|
25130 | * permit persons to whom the Software is furnished to do so, subject to
|
25131 | * the following conditions:
|
25132 | *
|
25133 | * The above copyright notice and this permission notice shall be
|
25134 | * included in all copies or substantial portions of the Software.
|
25135 | *
|
25136 | * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
25137 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25138 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
25139 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
25140 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
25141 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
25142 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25143 | *
|
25144 | */
|
25145 |
|
25146 | 'use strict';
|
25147 |
|
25148 | // code copied and modified from escape-html
|
25149 | /**
|
25150 | * Module variables.
|
25151 | * @private
|
25152 | */
|
25153 |
|
25154 | var matchHtmlRegExp = /["'&<>]/;
|
25155 |
|
25156 | /**
|
25157 | * Escape special characters in the given string of html.
|
25158 | *
|
25159 | * @param {string} string The string to escape for inserting into HTML
|
25160 | * @return {string}
|
25161 | * @public
|
25162 | */
|
25163 |
|
25164 | function escapeHtml(string) {
|
25165 | var str = '' + string;
|
25166 | var match = matchHtmlRegExp.exec(str);
|
25167 |
|
25168 | if (!match) {
|
25169 | return str;
|
25170 | }
|
25171 |
|
25172 | var escape;
|
25173 | var html = '';
|
25174 | var index = 0;
|
25175 | var lastIndex = 0;
|
25176 |
|
25177 | for (index = match.index; index < str.length; index++) {
|
25178 | switch (str.charCodeAt(index)) {
|
25179 | case 34:
|
25180 | // "
|
25181 | escape = '"';
|
25182 | break;
|
25183 | case 38:
|
25184 | // &
|
25185 | escape = '&';
|
25186 | break;
|
25187 | case 39:
|
25188 | // '
|
25189 | escape = '''; // modified from escape-html; used to be '''
|
25190 | break;
|
25191 | case 60:
|
25192 | // <
|
25193 | escape = '<';
|
25194 | break;
|
25195 | case 62:
|
25196 | // >
|
25197 | escape = '>';
|
25198 | break;
|
25199 | default:
|
25200 | continue;
|
25201 | }
|
25202 |
|
25203 | if (lastIndex !== index) {
|
25204 | html += str.substring(lastIndex, index);
|
25205 | }
|
25206 |
|
25207 | lastIndex = index + 1;
|
25208 | html += escape;
|
25209 | }
|
25210 |
|
25211 | return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
|
25212 | }
|
25213 | // end code copied and modified from escape-html
|
25214 |
|
25215 |
|
25216 | /**
|
25217 | * Escapes text to prevent scripting attacks.
|
25218 | *
|
25219 | * @param {*} text Text value to escape.
|
25220 | * @return {string} An escaped string.
|
25221 | */
|
25222 | function escapeTextContentForBrowser(text) {
|
25223 | if (typeof text === 'boolean' || typeof text === 'number') {
|
25224 | // this shortcircuit helps perf for types that we know will never have
|
25225 | // special characters, especially given that this function is used often
|
25226 | // for numeric dom ids.
|
25227 | return '' + text;
|
25228 | }
|
25229 | return escapeHtml(text);
|
25230 | }
|
25231 |
|
25232 | module.exports = escapeTextContentForBrowser;
|
25233 | },{}],259:[function(require,module,exports){
|
25234 | (function (process){
|
25235 | /**
|
25236 | * Copyright 2013-present, Facebook, Inc.
|
25237 | * All rights reserved.
|
25238 | *
|
25239 | * This source code is licensed under the BSD-style license found in the
|
25240 | * LICENSE file in the root directory of this source tree. An additional grant
|
25241 | * of patent rights can be found in the PATENTS file in the same directory.
|
25242 | *
|
25243 | */
|
25244 |
|
25245 | 'use strict';
|
25246 |
|
25247 | var _prodInvariant = require('./reactProdInvariant');
|
25248 |
|
25249 | var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
25250 | var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
25251 | var ReactInstanceMap = require('./ReactInstanceMap');
|
25252 |
|
25253 | var getHostComponentFromComposite = require('./getHostComponentFromComposite');
|
25254 | var invariant = require('fbjs/lib/invariant');
|
25255 | var warning = require('fbjs/lib/warning');
|
25256 |
|
25257 | /**
|
25258 | * Returns the DOM node rendered by this element.
|
25259 | *
|
25260 | * See https://facebook.github.io/react/docs/top-level-api.html#reactdom.finddomnode
|
25261 | *
|
25262 | * @param {ReactComponent|DOMElement} componentOrElement
|
25263 | * @return {?DOMElement} The root node of this element.
|
25264 | */
|
25265 | function findDOMNode(componentOrElement) {
|
25266 | if (process.env.NODE_ENV !== 'production') {
|
25267 | var owner = ReactCurrentOwner.current;
|
25268 | if (owner !== null) {
|
25269 | process.env.NODE_ENV !== 'production' ? warning(owner._warnedAboutRefsInRender, '%s is accessing findDOMNode inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', owner.getName() || 'A component') : void 0;
|
25270 | owner._warnedAboutRefsInRender = true;
|
25271 | }
|
25272 | }
|
25273 | if (componentOrElement == null) {
|
25274 | return null;
|
25275 | }
|
25276 | if (componentOrElement.nodeType === 1) {
|
25277 | return componentOrElement;
|
25278 | }
|
25279 |
|
25280 | var inst = ReactInstanceMap.get(componentOrElement);
|
25281 | if (inst) {
|
25282 | inst = getHostComponentFromComposite(inst);
|
25283 | return inst ? ReactDOMComponentTree.getNodeFromInstance(inst) : null;
|
25284 | }
|
25285 |
|
25286 | if (typeof componentOrElement.render === 'function') {
|
25287 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'findDOMNode was called on an unmounted component.') : _prodInvariant('44') : void 0;
|
25288 | } else {
|
25289 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Element appears to be neither ReactComponent nor DOMNode (keys: %s)', Object.keys(componentOrElement)) : _prodInvariant('45', Object.keys(componentOrElement)) : void 0;
|
25290 | }
|
25291 | }
|
25292 |
|
25293 | module.exports = findDOMNode;
|
25294 | }).call(this,require('_process'))
|
25295 | },{"./ReactDOMComponentTree":186,"./ReactInstanceMap":215,"./getHostComponentFromComposite":266,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131,"react/lib/ReactCurrentOwner":292}],260:[function(require,module,exports){
|
25296 | (function (process){
|
25297 | /**
|
25298 | * Copyright 2013-present, Facebook, Inc.
|
25299 | * All rights reserved.
|
25300 | *
|
25301 | * This source code is licensed under the BSD-style license found in the
|
25302 | * LICENSE file in the root directory of this source tree. An additional grant
|
25303 | * of patent rights can be found in the PATENTS file in the same directory.
|
25304 | *
|
25305 | *
|
25306 | */
|
25307 |
|
25308 | 'use strict';
|
25309 |
|
25310 | var KeyEscapeUtils = require('./KeyEscapeUtils');
|
25311 | var traverseAllChildren = require('./traverseAllChildren');
|
25312 | var warning = require('fbjs/lib/warning');
|
25313 |
|
25314 | var ReactComponentTreeHook;
|
25315 |
|
25316 | if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'test') {
|
25317 | // Temporary hack.
|
25318 | // Inline requires don't work well with Jest:
|
25319 | // https://github.com/facebook/react/issues/7240
|
25320 | // Remove the inline requires when we don't need them anymore:
|
25321 | // https://github.com/facebook/react/pull/7178
|
25322 | ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
25323 | }
|
25324 |
|
25325 | /**
|
25326 | * @param {function} traverseContext Context passed through traversal.
|
25327 | * @param {?ReactComponent} child React child component.
|
25328 | * @param {!string} name String name of key path to child.
|
25329 | * @param {number=} selfDebugID Optional debugID of the current internal instance.
|
25330 | */
|
25331 | function flattenSingleChildIntoContext(traverseContext, child, name, selfDebugID) {
|
25332 | // We found a component instance.
|
25333 | if (traverseContext && typeof traverseContext === 'object') {
|
25334 | var result = traverseContext;
|
25335 | var keyUnique = result[name] === undefined;
|
25336 | if (process.env.NODE_ENV !== 'production') {
|
25337 | if (!ReactComponentTreeHook) {
|
25338 | ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
25339 | }
|
25340 | if (!keyUnique) {
|
25341 | process.env.NODE_ENV !== 'production' ? warning(false, 'flattenChildren(...): Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, only ' + 'the first child will be used.%s', KeyEscapeUtils.unescape(name), ReactComponentTreeHook.getStackAddendumByID(selfDebugID)) : void 0;
|
25342 | }
|
25343 | }
|
25344 | if (keyUnique && child != null) {
|
25345 | result[name] = child;
|
25346 | }
|
25347 | }
|
25348 | }
|
25349 |
|
25350 | /**
|
25351 | * Flattens children that are typically specified as `props.children`. Any null
|
25352 | * children will not be included in the resulting object.
|
25353 | * @return {!object} flattened children keyed by name.
|
25354 | */
|
25355 | function flattenChildren(children, selfDebugID) {
|
25356 | if (children == null) {
|
25357 | return children;
|
25358 | }
|
25359 | var result = {};
|
25360 |
|
25361 | if (process.env.NODE_ENV !== 'production') {
|
25362 | traverseAllChildren(children, function (traverseContext, child, name) {
|
25363 | return flattenSingleChildIntoContext(traverseContext, child, name, selfDebugID);
|
25364 | }, result);
|
25365 | } else {
|
25366 | traverseAllChildren(children, flattenSingleChildIntoContext, result);
|
25367 | }
|
25368 | return result;
|
25369 | }
|
25370 |
|
25371 | module.exports = flattenChildren;
|
25372 | }).call(this,require('_process'))
|
25373 | },{"./KeyEscapeUtils":175,"./traverseAllChildren":281,"_process":144,"fbjs/lib/warning":131,"react/lib/ReactComponentTreeHook":291}],261:[function(require,module,exports){
|
25374 | /**
|
25375 | * Copyright 2013-present, Facebook, Inc.
|
25376 | * All rights reserved.
|
25377 | *
|
25378 | * This source code is licensed under the BSD-style license found in the
|
25379 | * LICENSE file in the root directory of this source tree. An additional grant
|
25380 | * of patent rights can be found in the PATENTS file in the same directory.
|
25381 | *
|
25382 | *
|
25383 | */
|
25384 |
|
25385 | 'use strict';
|
25386 |
|
25387 | /**
|
25388 | * @param {array} arr an "accumulation" of items which is either an Array or
|
25389 | * a single item. Useful when paired with the `accumulate` module. This is a
|
25390 | * simple utility that allows us to reason about a collection of items, but
|
25391 | * handling the case when there is exactly one item (and we do not need to
|
25392 | * allocate an array).
|
25393 | */
|
25394 |
|
25395 | function forEachAccumulated(arr, cb, scope) {
|
25396 | if (Array.isArray(arr)) {
|
25397 | arr.forEach(cb, scope);
|
25398 | } else if (arr) {
|
25399 | cb.call(scope, arr);
|
25400 | }
|
25401 | }
|
25402 |
|
25403 | module.exports = forEachAccumulated;
|
25404 | },{}],262:[function(require,module,exports){
|
25405 | /**
|
25406 | * Copyright 2013-present, Facebook, Inc.
|
25407 | * All rights reserved.
|
25408 | *
|
25409 | * This source code is licensed under the BSD-style license found in the
|
25410 | * LICENSE file in the root directory of this source tree. An additional grant
|
25411 | * of patent rights can be found in the PATENTS file in the same directory.
|
25412 | *
|
25413 | */
|
25414 |
|
25415 | 'use strict';
|
25416 |
|
25417 | /**
|
25418 | * `charCode` represents the actual "character code" and is safe to use with
|
25419 | * `String.fromCharCode`. As such, only keys that correspond to printable
|
25420 | * characters produce a valid `charCode`, the only exception to this is Enter.
|
25421 | * The Tab-key is considered non-printable and does not have a `charCode`,
|
25422 | * presumably because it does not produce a tab-character in browsers.
|
25423 | *
|
25424 | * @param {object} nativeEvent Native browser event.
|
25425 | * @return {number} Normalized `charCode` property.
|
25426 | */
|
25427 |
|
25428 | function getEventCharCode(nativeEvent) {
|
25429 | var charCode;
|
25430 | var keyCode = nativeEvent.keyCode;
|
25431 |
|
25432 | if ('charCode' in nativeEvent) {
|
25433 | charCode = nativeEvent.charCode;
|
25434 |
|
25435 | // FF does not set `charCode` for the Enter-key, check against `keyCode`.
|
25436 | if (charCode === 0 && keyCode === 13) {
|
25437 | charCode = 13;
|
25438 | }
|
25439 | } else {
|
25440 | // IE8 does not implement `charCode`, but `keyCode` has the correct value.
|
25441 | charCode = keyCode;
|
25442 | }
|
25443 |
|
25444 | // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
|
25445 | // Must not discard the (non-)printable Enter-key.
|
25446 | if (charCode >= 32 || charCode === 13) {
|
25447 | return charCode;
|
25448 | }
|
25449 |
|
25450 | return 0;
|
25451 | }
|
25452 |
|
25453 | module.exports = getEventCharCode;
|
25454 | },{}],263:[function(require,module,exports){
|
25455 | /**
|
25456 | * Copyright 2013-present, Facebook, Inc.
|
25457 | * All rights reserved.
|
25458 | *
|
25459 | * This source code is licensed under the BSD-style license found in the
|
25460 | * LICENSE file in the root directory of this source tree. An additional grant
|
25461 | * of patent rights can be found in the PATENTS file in the same directory.
|
25462 | *
|
25463 | */
|
25464 |
|
25465 | 'use strict';
|
25466 |
|
25467 | var getEventCharCode = require('./getEventCharCode');
|
25468 |
|
25469 | /**
|
25470 | * Normalization of deprecated HTML5 `key` values
|
25471 | * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
|
25472 | */
|
25473 | var normalizeKey = {
|
25474 | 'Esc': 'Escape',
|
25475 | 'Spacebar': ' ',
|
25476 | 'Left': 'ArrowLeft',
|
25477 | 'Up': 'ArrowUp',
|
25478 | 'Right': 'ArrowRight',
|
25479 | 'Down': 'ArrowDown',
|
25480 | 'Del': 'Delete',
|
25481 | 'Win': 'OS',
|
25482 | 'Menu': 'ContextMenu',
|
25483 | 'Apps': 'ContextMenu',
|
25484 | 'Scroll': 'ScrollLock',
|
25485 | 'MozPrintableKey': 'Unidentified'
|
25486 | };
|
25487 |
|
25488 | /**
|
25489 | * Translation from legacy `keyCode` to HTML5 `key`
|
25490 | * Only special keys supported, all others depend on keyboard layout or browser
|
25491 | * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
|
25492 | */
|
25493 | var translateToKey = {
|
25494 | 8: 'Backspace',
|
25495 | 9: 'Tab',
|
25496 | 12: 'Clear',
|
25497 | 13: 'Enter',
|
25498 | 16: 'Shift',
|
25499 | 17: 'Control',
|
25500 | 18: 'Alt',
|
25501 | 19: 'Pause',
|
25502 | 20: 'CapsLock',
|
25503 | 27: 'Escape',
|
25504 | 32: ' ',
|
25505 | 33: 'PageUp',
|
25506 | 34: 'PageDown',
|
25507 | 35: 'End',
|
25508 | 36: 'Home',
|
25509 | 37: 'ArrowLeft',
|
25510 | 38: 'ArrowUp',
|
25511 | 39: 'ArrowRight',
|
25512 | 40: 'ArrowDown',
|
25513 | 45: 'Insert',
|
25514 | 46: 'Delete',
|
25515 | 112: 'F1', 113: 'F2', 114: 'F3', 115: 'F4', 116: 'F5', 117: 'F6',
|
25516 | 118: 'F7', 119: 'F8', 120: 'F9', 121: 'F10', 122: 'F11', 123: 'F12',
|
25517 | 144: 'NumLock',
|
25518 | 145: 'ScrollLock',
|
25519 | 224: 'Meta'
|
25520 | };
|
25521 |
|
25522 | /**
|
25523 | * @param {object} nativeEvent Native browser event.
|
25524 | * @return {string} Normalized `key` property.
|
25525 | */
|
25526 | function getEventKey(nativeEvent) {
|
25527 | if (nativeEvent.key) {
|
25528 | // Normalize inconsistent values reported by browsers due to
|
25529 | // implementations of a working draft specification.
|
25530 |
|
25531 | // FireFox implements `key` but returns `MozPrintableKey` for all
|
25532 | // printable characters (normalized to `Unidentified`), ignore it.
|
25533 | var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
|
25534 | if (key !== 'Unidentified') {
|
25535 | return key;
|
25536 | }
|
25537 | }
|
25538 |
|
25539 | // Browser does not implement `key`, polyfill as much of it as we can.
|
25540 | if (nativeEvent.type === 'keypress') {
|
25541 | var charCode = getEventCharCode(nativeEvent);
|
25542 |
|
25543 | // The enter-key is technically both printable and non-printable and can
|
25544 | // thus be captured by `keypress`, no other non-printable key should.
|
25545 | return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
|
25546 | }
|
25547 | if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
|
25548 | // While user keyboard layout determines the actual meaning of each
|
25549 | // `keyCode` value, almost all function keys have a universal value.
|
25550 | return translateToKey[nativeEvent.keyCode] || 'Unidentified';
|
25551 | }
|
25552 | return '';
|
25553 | }
|
25554 |
|
25555 | module.exports = getEventKey;
|
25556 | },{"./getEventCharCode":262}],264:[function(require,module,exports){
|
25557 | /**
|
25558 | * Copyright 2013-present, Facebook, Inc.
|
25559 | * All rights reserved.
|
25560 | *
|
25561 | * This source code is licensed under the BSD-style license found in the
|
25562 | * LICENSE file in the root directory of this source tree. An additional grant
|
25563 | * of patent rights can be found in the PATENTS file in the same directory.
|
25564 | *
|
25565 | */
|
25566 |
|
25567 | 'use strict';
|
25568 |
|
25569 | /**
|
25570 | * Translation from modifier key to the associated property in the event.
|
25571 | * @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
|
25572 | */
|
25573 |
|
25574 | var modifierKeyToProp = {
|
25575 | 'Alt': 'altKey',
|
25576 | 'Control': 'ctrlKey',
|
25577 | 'Meta': 'metaKey',
|
25578 | 'Shift': 'shiftKey'
|
25579 | };
|
25580 |
|
25581 | // IE8 does not implement getModifierState so we simply map it to the only
|
25582 | // modifier keys exposed by the event itself, does not support Lock-keys.
|
25583 | // Currently, all major browsers except Chrome seems to support Lock-keys.
|
25584 | function modifierStateGetter(keyArg) {
|
25585 | var syntheticEvent = this;
|
25586 | var nativeEvent = syntheticEvent.nativeEvent;
|
25587 | if (nativeEvent.getModifierState) {
|
25588 | return nativeEvent.getModifierState(keyArg);
|
25589 | }
|
25590 | var keyProp = modifierKeyToProp[keyArg];
|
25591 | return keyProp ? !!nativeEvent[keyProp] : false;
|
25592 | }
|
25593 |
|
25594 | function getEventModifierState(nativeEvent) {
|
25595 | return modifierStateGetter;
|
25596 | }
|
25597 |
|
25598 | module.exports = getEventModifierState;
|
25599 | },{}],265:[function(require,module,exports){
|
25600 | /**
|
25601 | * Copyright 2013-present, Facebook, Inc.
|
25602 | * All rights reserved.
|
25603 | *
|
25604 | * This source code is licensed under the BSD-style license found in the
|
25605 | * LICENSE file in the root directory of this source tree. An additional grant
|
25606 | * of patent rights can be found in the PATENTS file in the same directory.
|
25607 | *
|
25608 | */
|
25609 |
|
25610 | 'use strict';
|
25611 |
|
25612 | /**
|
25613 | * Gets the target node from a native browser event by accounting for
|
25614 | * inconsistencies in browser DOM APIs.
|
25615 | *
|
25616 | * @param {object} nativeEvent Native browser event.
|
25617 | * @return {DOMEventTarget} Target node.
|
25618 | */
|
25619 |
|
25620 | function getEventTarget(nativeEvent) {
|
25621 | var target = nativeEvent.target || nativeEvent.srcElement || window;
|
25622 |
|
25623 | // Normalize SVG <use> element events #4963
|
25624 | if (target.correspondingUseElement) {
|
25625 | target = target.correspondingUseElement;
|
25626 | }
|
25627 |
|
25628 | // Safari may fire events on text nodes (Node.TEXT_NODE is 3).
|
25629 | // @see http://www.quirksmode.org/js/events_properties.html
|
25630 | return target.nodeType === 3 ? target.parentNode : target;
|
25631 | }
|
25632 |
|
25633 | module.exports = getEventTarget;
|
25634 | },{}],266:[function(require,module,exports){
|
25635 | /**
|
25636 | * Copyright 2013-present, Facebook, Inc.
|
25637 | * All rights reserved.
|
25638 | *
|
25639 | * This source code is licensed under the BSD-style license found in the
|
25640 | * LICENSE file in the root directory of this source tree. An additional grant
|
25641 | * of patent rights can be found in the PATENTS file in the same directory.
|
25642 | *
|
25643 | */
|
25644 |
|
25645 | 'use strict';
|
25646 |
|
25647 | var ReactNodeTypes = require('./ReactNodeTypes');
|
25648 |
|
25649 | function getHostComponentFromComposite(inst) {
|
25650 | var type;
|
25651 |
|
25652 | while ((type = inst._renderedNodeType) === ReactNodeTypes.COMPOSITE) {
|
25653 | inst = inst._renderedComponent;
|
25654 | }
|
25655 |
|
25656 | if (type === ReactNodeTypes.HOST) {
|
25657 | return inst._renderedComponent;
|
25658 | } else if (type === ReactNodeTypes.EMPTY) {
|
25659 | return null;
|
25660 | }
|
25661 | }
|
25662 |
|
25663 | module.exports = getHostComponentFromComposite;
|
25664 | },{"./ReactNodeTypes":221}],267:[function(require,module,exports){
|
25665 | /**
|
25666 | * Copyright 2013-present, Facebook, Inc.
|
25667 | * All rights reserved.
|
25668 | *
|
25669 | * This source code is licensed under the BSD-style license found in the
|
25670 | * LICENSE file in the root directory of this source tree. An additional grant
|
25671 | * of patent rights can be found in the PATENTS file in the same directory.
|
25672 | *
|
25673 | *
|
25674 | */
|
25675 |
|
25676 | 'use strict';
|
25677 |
|
25678 | /* global Symbol */
|
25679 |
|
25680 | var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
25681 | var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
25682 |
|
25683 | /**
|
25684 | * Returns the iterator method function contained on the iterable object.
|
25685 | *
|
25686 | * Be sure to invoke the function with the iterable as context:
|
25687 | *
|
25688 | * var iteratorFn = getIteratorFn(myIterable);
|
25689 | * if (iteratorFn) {
|
25690 | * var iterator = iteratorFn.call(myIterable);
|
25691 | * ...
|
25692 | * }
|
25693 | *
|
25694 | * @param {?object} maybeIterable
|
25695 | * @return {?function}
|
25696 | */
|
25697 | function getIteratorFn(maybeIterable) {
|
25698 | var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
25699 | if (typeof iteratorFn === 'function') {
|
25700 | return iteratorFn;
|
25701 | }
|
25702 | }
|
25703 |
|
25704 | module.exports = getIteratorFn;
|
25705 | },{}],268:[function(require,module,exports){
|
25706 | /**
|
25707 | * Copyright 2013-present, Facebook, Inc.
|
25708 | * All rights reserved.
|
25709 | *
|
25710 | * This source code is licensed under the BSD-style license found in the
|
25711 | * LICENSE file in the root directory of this source tree. An additional grant
|
25712 | * of patent rights can be found in the PATENTS file in the same directory.
|
25713 | *
|
25714 | *
|
25715 | */
|
25716 |
|
25717 | 'use strict';
|
25718 |
|
25719 | var nextDebugID = 1;
|
25720 |
|
25721 | function getNextDebugID() {
|
25722 | return nextDebugID++;
|
25723 | }
|
25724 |
|
25725 | module.exports = getNextDebugID;
|
25726 | },{}],269:[function(require,module,exports){
|
25727 | /**
|
25728 | * Copyright 2013-present, Facebook, Inc.
|
25729 | * All rights reserved.
|
25730 | *
|
25731 | * This source code is licensed under the BSD-style license found in the
|
25732 | * LICENSE file in the root directory of this source tree. An additional grant
|
25733 | * of patent rights can be found in the PATENTS file in the same directory.
|
25734 | *
|
25735 | */
|
25736 |
|
25737 | 'use strict';
|
25738 |
|
25739 | /**
|
25740 | * Given any node return the first leaf node without children.
|
25741 | *
|
25742 | * @param {DOMElement|DOMTextNode} node
|
25743 | * @return {DOMElement|DOMTextNode}
|
25744 | */
|
25745 |
|
25746 | function getLeafNode(node) {
|
25747 | while (node && node.firstChild) {
|
25748 | node = node.firstChild;
|
25749 | }
|
25750 | return node;
|
25751 | }
|
25752 |
|
25753 | /**
|
25754 | * Get the next sibling within a container. This will walk up the
|
25755 | * DOM if a node's siblings have been exhausted.
|
25756 | *
|
25757 | * @param {DOMElement|DOMTextNode} node
|
25758 | * @return {?DOMElement|DOMTextNode}
|
25759 | */
|
25760 | function getSiblingNode(node) {
|
25761 | while (node) {
|
25762 | if (node.nextSibling) {
|
25763 | return node.nextSibling;
|
25764 | }
|
25765 | node = node.parentNode;
|
25766 | }
|
25767 | }
|
25768 |
|
25769 | /**
|
25770 | * Get object describing the nodes which contain characters at offset.
|
25771 | *
|
25772 | * @param {DOMElement|DOMTextNode} root
|
25773 | * @param {number} offset
|
25774 | * @return {?object}
|
25775 | */
|
25776 | function getNodeForCharacterOffset(root, offset) {
|
25777 | var node = getLeafNode(root);
|
25778 | var nodeStart = 0;
|
25779 | var nodeEnd = 0;
|
25780 |
|
25781 | while (node) {
|
25782 | if (node.nodeType === 3) {
|
25783 | nodeEnd = nodeStart + node.textContent.length;
|
25784 |
|
25785 | if (nodeStart <= offset && nodeEnd >= offset) {
|
25786 | return {
|
25787 | node: node,
|
25788 | offset: offset - nodeStart
|
25789 | };
|
25790 | }
|
25791 |
|
25792 | nodeStart = nodeEnd;
|
25793 | }
|
25794 |
|
25795 | node = getLeafNode(getSiblingNode(node));
|
25796 | }
|
25797 | }
|
25798 |
|
25799 | module.exports = getNodeForCharacterOffset;
|
25800 | },{}],270:[function(require,module,exports){
|
25801 | /**
|
25802 | * Copyright 2013-present, Facebook, Inc.
|
25803 | * All rights reserved.
|
25804 | *
|
25805 | * This source code is licensed under the BSD-style license found in the
|
25806 | * LICENSE file in the root directory of this source tree. An additional grant
|
25807 | * of patent rights can be found in the PATENTS file in the same directory.
|
25808 | *
|
25809 | */
|
25810 |
|
25811 | 'use strict';
|
25812 |
|
25813 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
25814 |
|
25815 | var contentKey = null;
|
25816 |
|
25817 | /**
|
25818 | * Gets the key used to access text content on a DOM node.
|
25819 | *
|
25820 | * @return {?string} Key used to access text content.
|
25821 | * @internal
|
25822 | */
|
25823 | function getTextContentAccessor() {
|
25824 | if (!contentKey && ExecutionEnvironment.canUseDOM) {
|
25825 | // Prefer textContent to innerText because many browsers support both but
|
25826 | // SVG <text> elements don't support innerText even when <div> does.
|
25827 | contentKey = 'textContent' in document.documentElement ? 'textContent' : 'innerText';
|
25828 | }
|
25829 | return contentKey;
|
25830 | }
|
25831 |
|
25832 | module.exports = getTextContentAccessor;
|
25833 | },{"fbjs/lib/ExecutionEnvironment":110}],271:[function(require,module,exports){
|
25834 | /**
|
25835 | * Copyright 2013-present, Facebook, Inc.
|
25836 | * All rights reserved.
|
25837 | *
|
25838 | * This source code is licensed under the BSD-style license found in the
|
25839 | * LICENSE file in the root directory of this source tree. An additional grant
|
25840 | * of patent rights can be found in the PATENTS file in the same directory.
|
25841 | *
|
25842 | */
|
25843 |
|
25844 | 'use strict';
|
25845 |
|
25846 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
25847 |
|
25848 | /**
|
25849 | * Generate a mapping of standard vendor prefixes using the defined style property and event name.
|
25850 | *
|
25851 | * @param {string} styleProp
|
25852 | * @param {string} eventName
|
25853 | * @returns {object}
|
25854 | */
|
25855 | function makePrefixMap(styleProp, eventName) {
|
25856 | var prefixes = {};
|
25857 |
|
25858 | prefixes[styleProp.toLowerCase()] = eventName.toLowerCase();
|
25859 | prefixes['Webkit' + styleProp] = 'webkit' + eventName;
|
25860 | prefixes['Moz' + styleProp] = 'moz' + eventName;
|
25861 | prefixes['ms' + styleProp] = 'MS' + eventName;
|
25862 | prefixes['O' + styleProp] = 'o' + eventName.toLowerCase();
|
25863 |
|
25864 | return prefixes;
|
25865 | }
|
25866 |
|
25867 | /**
|
25868 | * A list of event names to a configurable list of vendor prefixes.
|
25869 | */
|
25870 | var vendorPrefixes = {
|
25871 | animationend: makePrefixMap('Animation', 'AnimationEnd'),
|
25872 | animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
|
25873 | animationstart: makePrefixMap('Animation', 'AnimationStart'),
|
25874 | transitionend: makePrefixMap('Transition', 'TransitionEnd')
|
25875 | };
|
25876 |
|
25877 | /**
|
25878 | * Event names that have already been detected and prefixed (if applicable).
|
25879 | */
|
25880 | var prefixedEventNames = {};
|
25881 |
|
25882 | /**
|
25883 | * Element to check for prefixes on.
|
25884 | */
|
25885 | var style = {};
|
25886 |
|
25887 | /**
|
25888 | * Bootstrap if a DOM exists.
|
25889 | */
|
25890 | if (ExecutionEnvironment.canUseDOM) {
|
25891 | style = document.createElement('div').style;
|
25892 |
|
25893 | // On some platforms, in particular some releases of Android 4.x,
|
25894 | // the un-prefixed "animation" and "transition" properties are defined on the
|
25895 | // style object but the events that fire will still be prefixed, so we need
|
25896 | // to check if the un-prefixed events are usable, and if not remove them from the map.
|
25897 | if (!('AnimationEvent' in window)) {
|
25898 | delete vendorPrefixes.animationend.animation;
|
25899 | delete vendorPrefixes.animationiteration.animation;
|
25900 | delete vendorPrefixes.animationstart.animation;
|
25901 | }
|
25902 |
|
25903 | // Same as above
|
25904 | if (!('TransitionEvent' in window)) {
|
25905 | delete vendorPrefixes.transitionend.transition;
|
25906 | }
|
25907 | }
|
25908 |
|
25909 | /**
|
25910 | * Attempts to determine the correct vendor prefixed event name.
|
25911 | *
|
25912 | * @param {string} eventName
|
25913 | * @returns {string}
|
25914 | */
|
25915 | function getVendorPrefixedEventName(eventName) {
|
25916 | if (prefixedEventNames[eventName]) {
|
25917 | return prefixedEventNames[eventName];
|
25918 | } else if (!vendorPrefixes[eventName]) {
|
25919 | return eventName;
|
25920 | }
|
25921 |
|
25922 | var prefixMap = vendorPrefixes[eventName];
|
25923 |
|
25924 | for (var styleProp in prefixMap) {
|
25925 | if (prefixMap.hasOwnProperty(styleProp) && styleProp in style) {
|
25926 | return prefixedEventNames[eventName] = prefixMap[styleProp];
|
25927 | }
|
25928 | }
|
25929 |
|
25930 | return '';
|
25931 | }
|
25932 |
|
25933 | module.exports = getVendorPrefixedEventName;
|
25934 | },{"fbjs/lib/ExecutionEnvironment":110}],272:[function(require,module,exports){
|
25935 | (function (process){
|
25936 | /**
|
25937 | * Copyright 2013-present, Facebook, Inc.
|
25938 | * All rights reserved.
|
25939 | *
|
25940 | * This source code is licensed under the BSD-style license found in the
|
25941 | * LICENSE file in the root directory of this source tree. An additional grant
|
25942 | * of patent rights can be found in the PATENTS file in the same directory.
|
25943 | *
|
25944 | */
|
25945 |
|
25946 | 'use strict';
|
25947 |
|
25948 | var _prodInvariant = require('./reactProdInvariant'),
|
25949 | _assign = require('object-assign');
|
25950 |
|
25951 | var ReactCompositeComponent = require('./ReactCompositeComponent');
|
25952 | var ReactEmptyComponent = require('./ReactEmptyComponent');
|
25953 | var ReactHostComponent = require('./ReactHostComponent');
|
25954 |
|
25955 | var getNextDebugID = require('./getNextDebugID');
|
25956 | var invariant = require('fbjs/lib/invariant');
|
25957 | var warning = require('fbjs/lib/warning');
|
25958 |
|
25959 | // To avoid a cyclic dependency, we create the final class in this module
|
25960 | var ReactCompositeComponentWrapper = function (element) {
|
25961 | this.construct(element);
|
25962 | };
|
25963 | _assign(ReactCompositeComponentWrapper.prototype, ReactCompositeComponent, {
|
25964 | _instantiateReactComponent: instantiateReactComponent
|
25965 | });
|
25966 |
|
25967 | function getDeclarationErrorAddendum(owner) {
|
25968 | if (owner) {
|
25969 | var name = owner.getName();
|
25970 | if (name) {
|
25971 | return ' Check the render method of `' + name + '`.';
|
25972 | }
|
25973 | }
|
25974 | return '';
|
25975 | }
|
25976 |
|
25977 | /**
|
25978 | * Check if the type reference is a known internal type. I.e. not a user
|
25979 | * provided composite type.
|
25980 | *
|
25981 | * @param {function} type
|
25982 | * @return {boolean} Returns true if this is a valid internal type.
|
25983 | */
|
25984 | function isInternalComponentType(type) {
|
25985 | return typeof type === 'function' && typeof type.prototype !== 'undefined' && typeof type.prototype.mountComponent === 'function' && typeof type.prototype.receiveComponent === 'function';
|
25986 | }
|
25987 |
|
25988 | /**
|
25989 | * Given a ReactNode, create an instance that will actually be mounted.
|
25990 | *
|
25991 | * @param {ReactNode} node
|
25992 | * @param {boolean} shouldHaveDebugID
|
25993 | * @return {object} A new instance of the element's constructor.
|
25994 | * @protected
|
25995 | */
|
25996 | function instantiateReactComponent(node, shouldHaveDebugID) {
|
25997 | var instance;
|
25998 |
|
25999 | if (node === null || node === false) {
|
26000 | instance = ReactEmptyComponent.create(instantiateReactComponent);
|
26001 | } else if (typeof node === 'object') {
|
26002 | var element = node;
|
26003 | !(element && (typeof element.type === 'function' || typeof element.type === 'string')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s', element.type == null ? element.type : typeof element.type, getDeclarationErrorAddendum(element._owner)) : _prodInvariant('130', element.type == null ? element.type : typeof element.type, getDeclarationErrorAddendum(element._owner)) : void 0;
|
26004 |
|
26005 | // Special case string values
|
26006 | if (typeof element.type === 'string') {
|
26007 | instance = ReactHostComponent.createInternalComponent(element);
|
26008 | } else if (isInternalComponentType(element.type)) {
|
26009 | // This is temporarily available for custom components that are not string
|
26010 | // representations. I.e. ART. Once those are updated to use the string
|
26011 | // representation, we can drop this code path.
|
26012 | instance = new element.type(element);
|
26013 |
|
26014 | // We renamed this. Allow the old name for compat. :(
|
26015 | if (!instance.getHostNode) {
|
26016 | instance.getHostNode = instance.getNativeNode;
|
26017 | }
|
26018 | } else {
|
26019 | instance = new ReactCompositeComponentWrapper(element);
|
26020 | }
|
26021 | } else if (typeof node === 'string' || typeof node === 'number') {
|
26022 | instance = ReactHostComponent.createInstanceForText(node);
|
26023 | } else {
|
26024 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Encountered invalid React node of type %s', typeof node) : _prodInvariant('131', typeof node) : void 0;
|
26025 | }
|
26026 |
|
26027 | if (process.env.NODE_ENV !== 'production') {
|
26028 | process.env.NODE_ENV !== 'production' ? warning(typeof instance.mountComponent === 'function' && typeof instance.receiveComponent === 'function' && typeof instance.getHostNode === 'function' && typeof instance.unmountComponent === 'function', 'Only React Components can be mounted.') : void 0;
|
26029 | }
|
26030 |
|
26031 | // These two fields are used by the DOM and ART diffing algorithms
|
26032 | // respectively. Instead of using expandos on components, we should be
|
26033 | // storing the state needed by the diffing algorithms elsewhere.
|
26034 | instance._mountIndex = 0;
|
26035 | instance._mountImage = null;
|
26036 |
|
26037 | if (process.env.NODE_ENV !== 'production') {
|
26038 | instance._debugID = shouldHaveDebugID ? getNextDebugID() : 0;
|
26039 | }
|
26040 |
|
26041 | // Internal instances should fully constructed at this point, so they should
|
26042 | // not get any new fields added to them at this point.
|
26043 | if (process.env.NODE_ENV !== 'production') {
|
26044 | if (Object.preventExtensions) {
|
26045 | Object.preventExtensions(instance);
|
26046 | }
|
26047 | }
|
26048 |
|
26049 | return instance;
|
26050 | }
|
26051 |
|
26052 | module.exports = instantiateReactComponent;
|
26053 | }).call(this,require('_process'))
|
26054 | },{"./ReactCompositeComponent":182,"./ReactEmptyComponent":206,"./ReactHostComponent":211,"./getNextDebugID":268,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131,"object-assign":143}],273:[function(require,module,exports){
|
26055 | /**
|
26056 | * Copyright 2013-present, Facebook, Inc.
|
26057 | * All rights reserved.
|
26058 | *
|
26059 | * This source code is licensed under the BSD-style license found in the
|
26060 | * LICENSE file in the root directory of this source tree. An additional grant
|
26061 | * of patent rights can be found in the PATENTS file in the same directory.
|
26062 | *
|
26063 | */
|
26064 |
|
26065 | 'use strict';
|
26066 |
|
26067 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
26068 |
|
26069 | var useHasFeature;
|
26070 | if (ExecutionEnvironment.canUseDOM) {
|
26071 | useHasFeature = document.implementation && document.implementation.hasFeature &&
|
26072 | // always returns true in newer browsers as per the standard.
|
26073 | // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
|
26074 | document.implementation.hasFeature('', '') !== true;
|
26075 | }
|
26076 |
|
26077 | /**
|
26078 | * Checks if an event is supported in the current execution environment.
|
26079 | *
|
26080 | * NOTE: This will not work correctly for non-generic events such as `change`,
|
26081 | * `reset`, `load`, `error`, and `select`.
|
26082 | *
|
26083 | * Borrows from Modernizr.
|
26084 | *
|
26085 | * @param {string} eventNameSuffix Event name, e.g. "click".
|
26086 | * @param {?boolean} capture Check if the capture phase is supported.
|
26087 | * @return {boolean} True if the event is supported.
|
26088 | * @internal
|
26089 | * @license Modernizr 3.0.0pre (Custom Build) | MIT
|
26090 | */
|
26091 | function isEventSupported(eventNameSuffix, capture) {
|
26092 | if (!ExecutionEnvironment.canUseDOM || capture && !('addEventListener' in document)) {
|
26093 | return false;
|
26094 | }
|
26095 |
|
26096 | var eventName = 'on' + eventNameSuffix;
|
26097 | var isSupported = eventName in document;
|
26098 |
|
26099 | if (!isSupported) {
|
26100 | var element = document.createElement('div');
|
26101 | element.setAttribute(eventName, 'return;');
|
26102 | isSupported = typeof element[eventName] === 'function';
|
26103 | }
|
26104 |
|
26105 | if (!isSupported && useHasFeature && eventNameSuffix === 'wheel') {
|
26106 | // This is the only way to test support for the `wheel` event in IE9+.
|
26107 | isSupported = document.implementation.hasFeature('Events.wheel', '3.0');
|
26108 | }
|
26109 |
|
26110 | return isSupported;
|
26111 | }
|
26112 |
|
26113 | module.exports = isEventSupported;
|
26114 | },{"fbjs/lib/ExecutionEnvironment":110}],274:[function(require,module,exports){
|
26115 | /**
|
26116 | * Copyright 2013-present, Facebook, Inc.
|
26117 | * All rights reserved.
|
26118 | *
|
26119 | * This source code is licensed under the BSD-style license found in the
|
26120 | * LICENSE file in the root directory of this source tree. An additional grant
|
26121 | * of patent rights can be found in the PATENTS file in the same directory.
|
26122 | *
|
26123 | *
|
26124 | */
|
26125 |
|
26126 | 'use strict';
|
26127 |
|
26128 | /**
|
26129 | * @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
|
26130 | */
|
26131 |
|
26132 | var supportedInputTypes = {
|
26133 | 'color': true,
|
26134 | 'date': true,
|
26135 | 'datetime': true,
|
26136 | 'datetime-local': true,
|
26137 | 'email': true,
|
26138 | 'month': true,
|
26139 | 'number': true,
|
26140 | 'password': true,
|
26141 | 'range': true,
|
26142 | 'search': true,
|
26143 | 'tel': true,
|
26144 | 'text': true,
|
26145 | 'time': true,
|
26146 | 'url': true,
|
26147 | 'week': true
|
26148 | };
|
26149 |
|
26150 | function isTextInputElement(elem) {
|
26151 | var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
|
26152 |
|
26153 | if (nodeName === 'input') {
|
26154 | return !!supportedInputTypes[elem.type];
|
26155 | }
|
26156 |
|
26157 | if (nodeName === 'textarea') {
|
26158 | return true;
|
26159 | }
|
26160 |
|
26161 | return false;
|
26162 | }
|
26163 |
|
26164 | module.exports = isTextInputElement;
|
26165 | },{}],275:[function(require,module,exports){
|
26166 | /**
|
26167 | * Copyright 2013-present, Facebook, Inc.
|
26168 | * All rights reserved.
|
26169 | *
|
26170 | * This source code is licensed under the BSD-style license found in the
|
26171 | * LICENSE file in the root directory of this source tree. An additional grant
|
26172 | * of patent rights can be found in the PATENTS file in the same directory.
|
26173 | *
|
26174 | */
|
26175 |
|
26176 | 'use strict';
|
26177 |
|
26178 | var escapeTextContentForBrowser = require('./escapeTextContentForBrowser');
|
26179 |
|
26180 | /**
|
26181 | * Escapes attribute value to prevent scripting attacks.
|
26182 | *
|
26183 | * @param {*} value Value to escape.
|
26184 | * @return {string} An escaped string.
|
26185 | */
|
26186 | function quoteAttributeValueForBrowser(value) {
|
26187 | return '"' + escapeTextContentForBrowser(value) + '"';
|
26188 | }
|
26189 |
|
26190 | module.exports = quoteAttributeValueForBrowser;
|
26191 | },{"./escapeTextContentForBrowser":258}],276:[function(require,module,exports){
|
26192 | /**
|
26193 | * Copyright (c) 2013-present, Facebook, Inc.
|
26194 | * All rights reserved.
|
26195 | *
|
26196 | * This source code is licensed under the BSD-style license found in the
|
26197 | * LICENSE file in the root directory of this source tree. An additional grant
|
26198 | * of patent rights can be found in the PATENTS file in the same directory.
|
26199 | *
|
26200 | *
|
26201 | */
|
26202 | 'use strict';
|
26203 |
|
26204 | /**
|
26205 | * WARNING: DO NOT manually require this module.
|
26206 | * This is a replacement for `invariant(...)` used by the error code system
|
26207 | * and will _only_ be required by the corresponding babel pass.
|
26208 | * It always throws.
|
26209 | */
|
26210 |
|
26211 | function reactProdInvariant(code) {
|
26212 | var argCount = arguments.length - 1;
|
26213 |
|
26214 | var message = 'Minified React error #' + code + '; visit ' + 'http://facebook.github.io/react/docs/error-decoder.html?invariant=' + code;
|
26215 |
|
26216 | for (var argIdx = 0; argIdx < argCount; argIdx++) {
|
26217 | message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]);
|
26218 | }
|
26219 |
|
26220 | message += ' for the full message or use the non-minified dev environment' + ' for full errors and additional helpful warnings.';
|
26221 |
|
26222 | var error = new Error(message);
|
26223 | error.name = 'Invariant Violation';
|
26224 | error.framesToPop = 1; // we don't care about reactProdInvariant's own frame
|
26225 |
|
26226 | throw error;
|
26227 | }
|
26228 |
|
26229 | module.exports = reactProdInvariant;
|
26230 | },{}],277:[function(require,module,exports){
|
26231 | /**
|
26232 | * Copyright 2013-present, Facebook, Inc.
|
26233 | * All rights reserved.
|
26234 | *
|
26235 | * This source code is licensed under the BSD-style license found in the
|
26236 | * LICENSE file in the root directory of this source tree. An additional grant
|
26237 | * of patent rights can be found in the PATENTS file in the same directory.
|
26238 | *
|
26239 | */
|
26240 |
|
26241 | 'use strict';
|
26242 |
|
26243 | var ReactMount = require('./ReactMount');
|
26244 |
|
26245 | module.exports = ReactMount.renderSubtreeIntoContainer;
|
26246 | },{"./ReactMount":219}],278:[function(require,module,exports){
|
26247 | /**
|
26248 | * Copyright 2013-present, Facebook, Inc.
|
26249 | * All rights reserved.
|
26250 | *
|
26251 | * This source code is licensed under the BSD-style license found in the
|
26252 | * LICENSE file in the root directory of this source tree. An additional grant
|
26253 | * of patent rights can be found in the PATENTS file in the same directory.
|
26254 | *
|
26255 | */
|
26256 |
|
26257 | 'use strict';
|
26258 |
|
26259 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
26260 | var DOMNamespaces = require('./DOMNamespaces');
|
26261 |
|
26262 | var WHITESPACE_TEST = /^[ \r\n\t\f]/;
|
26263 | var NONVISIBLE_TEST = /<(!--|link|noscript|meta|script|style)[ \r\n\t\f\/>]/;
|
26264 |
|
26265 | var createMicrosoftUnsafeLocalFunction = require('./createMicrosoftUnsafeLocalFunction');
|
26266 |
|
26267 | // SVG temp container for IE lacking innerHTML
|
26268 | var reusableSVGContainer;
|
26269 |
|
26270 | /**
|
26271 | * Set the innerHTML property of a node, ensuring that whitespace is preserved
|
26272 | * even in IE8.
|
26273 | *
|
26274 | * @param {DOMElement} node
|
26275 | * @param {string} html
|
26276 | * @internal
|
26277 | */
|
26278 | var setInnerHTML = createMicrosoftUnsafeLocalFunction(function (node, html) {
|
26279 | // IE does not have innerHTML for SVG nodes, so instead we inject the
|
26280 | // new markup in a temp node and then move the child nodes across into
|
26281 | // the target node
|
26282 | if (node.namespaceURI === DOMNamespaces.svg && !('innerHTML' in node)) {
|
26283 | reusableSVGContainer = reusableSVGContainer || document.createElement('div');
|
26284 | reusableSVGContainer.innerHTML = '<svg>' + html + '</svg>';
|
26285 | var svgNode = reusableSVGContainer.firstChild;
|
26286 | while (svgNode.firstChild) {
|
26287 | node.appendChild(svgNode.firstChild);
|
26288 | }
|
26289 | } else {
|
26290 | node.innerHTML = html;
|
26291 | }
|
26292 | });
|
26293 |
|
26294 | if (ExecutionEnvironment.canUseDOM) {
|
26295 | // IE8: When updating a just created node with innerHTML only leading
|
26296 | // whitespace is removed. When updating an existing node with innerHTML
|
26297 | // whitespace in root TextNodes is also collapsed.
|
26298 | // @see quirksmode.org/bugreports/archives/2004/11/innerhtml_and_t.html
|
26299 |
|
26300 | // Feature detection; only IE8 is known to behave improperly like this.
|
26301 | var testElement = document.createElement('div');
|
26302 | testElement.innerHTML = ' ';
|
26303 | if (testElement.innerHTML === '') {
|
26304 | setInnerHTML = function (node, html) {
|
26305 | // Magic theory: IE8 supposedly differentiates between added and updated
|
26306 | // nodes when processing innerHTML, innerHTML on updated nodes suffers
|
26307 | // from worse whitespace behavior. Re-adding a node like this triggers
|
26308 | // the initial and more favorable whitespace behavior.
|
26309 | // TODO: What to do on a detached node?
|
26310 | if (node.parentNode) {
|
26311 | node.parentNode.replaceChild(node, node);
|
26312 | }
|
26313 |
|
26314 | // We also implement a workaround for non-visible tags disappearing into
|
26315 | // thin air on IE8, this only happens if there is no visible text
|
26316 | // in-front of the non-visible tags. Piggyback on the whitespace fix
|
26317 | // and simply check if any non-visible tags appear in the source.
|
26318 | if (WHITESPACE_TEST.test(html) || html[0] === '<' && NONVISIBLE_TEST.test(html)) {
|
26319 | // Recover leading whitespace by temporarily prepending any character.
|
26320 | // \uFEFF has the potential advantage of being zero-width/invisible.
|
26321 | // UglifyJS drops U+FEFF chars when parsing, so use String.fromCharCode
|
26322 | // in hopes that this is preserved even if "\uFEFF" is transformed to
|
26323 | // the actual Unicode character (by Babel, for example).
|
26324 | // https://github.com/mishoo/UglifyJS2/blob/v2.4.20/lib/parse.js#L216
|
26325 | node.innerHTML = String.fromCharCode(0xFEFF) + html;
|
26326 |
|
26327 | // deleteData leaves an empty `TextNode` which offsets the index of all
|
26328 | // children. Definitely want to avoid this.
|
26329 | var textNode = node.firstChild;
|
26330 | if (textNode.data.length === 1) {
|
26331 | node.removeChild(textNode);
|
26332 | } else {
|
26333 | textNode.deleteData(0, 1);
|
26334 | }
|
26335 | } else {
|
26336 | node.innerHTML = html;
|
26337 | }
|
26338 | };
|
26339 | }
|
26340 | testElement = null;
|
26341 | }
|
26342 |
|
26343 | module.exports = setInnerHTML;
|
26344 | },{"./DOMNamespaces":163,"./createMicrosoftUnsafeLocalFunction":256,"fbjs/lib/ExecutionEnvironment":110}],279:[function(require,module,exports){
|
26345 | /**
|
26346 | * Copyright 2013-present, Facebook, Inc.
|
26347 | * All rights reserved.
|
26348 | *
|
26349 | * This source code is licensed under the BSD-style license found in the
|
26350 | * LICENSE file in the root directory of this source tree. An additional grant
|
26351 | * of patent rights can be found in the PATENTS file in the same directory.
|
26352 | *
|
26353 | */
|
26354 |
|
26355 | 'use strict';
|
26356 |
|
26357 | var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
26358 | var escapeTextContentForBrowser = require('./escapeTextContentForBrowser');
|
26359 | var setInnerHTML = require('./setInnerHTML');
|
26360 |
|
26361 | /**
|
26362 | * Set the textContent property of a node, ensuring that whitespace is preserved
|
26363 | * even in IE8. innerText is a poor substitute for textContent and, among many
|
26364 | * issues, inserts <br> instead of the literal newline chars. innerHTML behaves
|
26365 | * as it should.
|
26366 | *
|
26367 | * @param {DOMElement} node
|
26368 | * @param {string} text
|
26369 | * @internal
|
26370 | */
|
26371 | var setTextContent = function (node, text) {
|
26372 | if (text) {
|
26373 | var firstChild = node.firstChild;
|
26374 |
|
26375 | if (firstChild && firstChild === node.lastChild && firstChild.nodeType === 3) {
|
26376 | firstChild.nodeValue = text;
|
26377 | return;
|
26378 | }
|
26379 | }
|
26380 | node.textContent = text;
|
26381 | };
|
26382 |
|
26383 | if (ExecutionEnvironment.canUseDOM) {
|
26384 | if (!('textContent' in document.documentElement)) {
|
26385 | setTextContent = function (node, text) {
|
26386 | if (node.nodeType === 3) {
|
26387 | node.nodeValue = text;
|
26388 | return;
|
26389 | }
|
26390 | setInnerHTML(node, escapeTextContentForBrowser(text));
|
26391 | };
|
26392 | }
|
26393 | }
|
26394 |
|
26395 | module.exports = setTextContent;
|
26396 | },{"./escapeTextContentForBrowser":258,"./setInnerHTML":278,"fbjs/lib/ExecutionEnvironment":110}],280:[function(require,module,exports){
|
26397 | /**
|
26398 | * Copyright 2013-present, Facebook, Inc.
|
26399 | * All rights reserved.
|
26400 | *
|
26401 | * This source code is licensed under the BSD-style license found in the
|
26402 | * LICENSE file in the root directory of this source tree. An additional grant
|
26403 | * of patent rights can be found in the PATENTS file in the same directory.
|
26404 | *
|
26405 | */
|
26406 |
|
26407 | 'use strict';
|
26408 |
|
26409 | /**
|
26410 | * Given a `prevElement` and `nextElement`, determines if the existing
|
26411 | * instance should be updated as opposed to being destroyed or replaced by a new
|
26412 | * instance. Both arguments are elements. This ensures that this logic can
|
26413 | * operate on stateless trees without any backing instance.
|
26414 | *
|
26415 | * @param {?object} prevElement
|
26416 | * @param {?object} nextElement
|
26417 | * @return {boolean} True if the existing instance should be updated.
|
26418 | * @protected
|
26419 | */
|
26420 |
|
26421 | function shouldUpdateReactComponent(prevElement, nextElement) {
|
26422 | var prevEmpty = prevElement === null || prevElement === false;
|
26423 | var nextEmpty = nextElement === null || nextElement === false;
|
26424 | if (prevEmpty || nextEmpty) {
|
26425 | return prevEmpty === nextEmpty;
|
26426 | }
|
26427 |
|
26428 | var prevType = typeof prevElement;
|
26429 | var nextType = typeof nextElement;
|
26430 | if (prevType === 'string' || prevType === 'number') {
|
26431 | return nextType === 'string' || nextType === 'number';
|
26432 | } else {
|
26433 | return nextType === 'object' && prevElement.type === nextElement.type && prevElement.key === nextElement.key;
|
26434 | }
|
26435 | }
|
26436 |
|
26437 | module.exports = shouldUpdateReactComponent;
|
26438 | },{}],281:[function(require,module,exports){
|
26439 | (function (process){
|
26440 | /**
|
26441 | * Copyright 2013-present, Facebook, Inc.
|
26442 | * All rights reserved.
|
26443 | *
|
26444 | * This source code is licensed under the BSD-style license found in the
|
26445 | * LICENSE file in the root directory of this source tree. An additional grant
|
26446 | * of patent rights can be found in the PATENTS file in the same directory.
|
26447 | *
|
26448 | */
|
26449 |
|
26450 | 'use strict';
|
26451 |
|
26452 | var _prodInvariant = require('./reactProdInvariant');
|
26453 |
|
26454 | var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
26455 | var REACT_ELEMENT_TYPE = require('./ReactElementSymbol');
|
26456 |
|
26457 | var getIteratorFn = require('./getIteratorFn');
|
26458 | var invariant = require('fbjs/lib/invariant');
|
26459 | var KeyEscapeUtils = require('./KeyEscapeUtils');
|
26460 | var warning = require('fbjs/lib/warning');
|
26461 |
|
26462 | var SEPARATOR = '.';
|
26463 | var SUBSEPARATOR = ':';
|
26464 |
|
26465 | /**
|
26466 | * This is inlined from ReactElement since this file is shared between
|
26467 | * isomorphic and renderers. We could extract this to a
|
26468 | *
|
26469 | */
|
26470 |
|
26471 | /**
|
26472 | * TODO: Test that a single child and an array with one item have the same key
|
26473 | * pattern.
|
26474 | */
|
26475 |
|
26476 | var didWarnAboutMaps = false;
|
26477 |
|
26478 | /**
|
26479 | * Generate a key string that identifies a component within a set.
|
26480 | *
|
26481 | * @param {*} component A component that could contain a manual key.
|
26482 | * @param {number} index Index that is used if a manual key is not provided.
|
26483 | * @return {string}
|
26484 | */
|
26485 | function getComponentKey(component, index) {
|
26486 | // Do some typechecking here since we call this blindly. We want to ensure
|
26487 | // that we don't block potential future ES APIs.
|
26488 | if (component && typeof component === 'object' && component.key != null) {
|
26489 | // Explicit key
|
26490 | return KeyEscapeUtils.escape(component.key);
|
26491 | }
|
26492 | // Implicit key determined by the index in the set
|
26493 | return index.toString(36);
|
26494 | }
|
26495 |
|
26496 | /**
|
26497 | * @param {?*} children Children tree container.
|
26498 | * @param {!string} nameSoFar Name of the key path so far.
|
26499 | * @param {!function} callback Callback to invoke with each child found.
|
26500 | * @param {?*} traverseContext Used to pass information throughout the traversal
|
26501 | * process.
|
26502 | * @return {!number} The number of children in this subtree.
|
26503 | */
|
26504 | function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) {
|
26505 | var type = typeof children;
|
26506 |
|
26507 | if (type === 'undefined' || type === 'boolean') {
|
26508 | // All of the above are perceived as null.
|
26509 | children = null;
|
26510 | }
|
26511 |
|
26512 | if (children === null || type === 'string' || type === 'number' ||
|
26513 | // The following is inlined from ReactElement. This means we can optimize
|
26514 | // some checks. React Fiber also inlines this logic for similar purposes.
|
26515 | type === 'object' && children.$$typeof === REACT_ELEMENT_TYPE) {
|
26516 | callback(traverseContext, children,
|
26517 | // If it's the only child, treat the name as if it was wrapped in an array
|
26518 | // so that it's consistent if the number of children grows.
|
26519 | nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar);
|
26520 | return 1;
|
26521 | }
|
26522 |
|
26523 | var child;
|
26524 | var nextName;
|
26525 | var subtreeCount = 0; // Count of children found in the current subtree.
|
26526 | var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
|
26527 |
|
26528 | if (Array.isArray(children)) {
|
26529 | for (var i = 0; i < children.length; i++) {
|
26530 | child = children[i];
|
26531 | nextName = nextNamePrefix + getComponentKey(child, i);
|
26532 | subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
26533 | }
|
26534 | } else {
|
26535 | var iteratorFn = getIteratorFn(children);
|
26536 | if (iteratorFn) {
|
26537 | var iterator = iteratorFn.call(children);
|
26538 | var step;
|
26539 | if (iteratorFn !== children.entries) {
|
26540 | var ii = 0;
|
26541 | while (!(step = iterator.next()).done) {
|
26542 | child = step.value;
|
26543 | nextName = nextNamePrefix + getComponentKey(child, ii++);
|
26544 | subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
26545 | }
|
26546 | } else {
|
26547 | if (process.env.NODE_ENV !== 'production') {
|
26548 | var mapsAsChildrenAddendum = '';
|
26549 | if (ReactCurrentOwner.current) {
|
26550 | var mapsAsChildrenOwnerName = ReactCurrentOwner.current.getName();
|
26551 | if (mapsAsChildrenOwnerName) {
|
26552 | mapsAsChildrenAddendum = ' Check the render method of `' + mapsAsChildrenOwnerName + '`.';
|
26553 | }
|
26554 | }
|
26555 | process.env.NODE_ENV !== 'production' ? warning(didWarnAboutMaps, 'Using Maps as children is not yet fully supported. It is an ' + 'experimental feature that might be removed. Convert it to a ' + 'sequence / iterable of keyed ReactElements instead.%s', mapsAsChildrenAddendum) : void 0;
|
26556 | didWarnAboutMaps = true;
|
26557 | }
|
26558 | // Iterator will provide entry [k,v] tuples rather than values.
|
26559 | while (!(step = iterator.next()).done) {
|
26560 | var entry = step.value;
|
26561 | if (entry) {
|
26562 | child = entry[1];
|
26563 | nextName = nextNamePrefix + KeyEscapeUtils.escape(entry[0]) + SUBSEPARATOR + getComponentKey(child, 0);
|
26564 | subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
26565 | }
|
26566 | }
|
26567 | }
|
26568 | } else if (type === 'object') {
|
26569 | var addendum = '';
|
26570 | if (process.env.NODE_ENV !== 'production') {
|
26571 | addendum = ' If you meant to render a collection of children, use an array ' + 'instead or wrap the object using createFragment(object) from the ' + 'React add-ons.';
|
26572 | if (children._isReactElement) {
|
26573 | addendum = ' It looks like you\'re using an element created by a different ' + 'version of React. Make sure to use only one copy of React.';
|
26574 | }
|
26575 | if (ReactCurrentOwner.current) {
|
26576 | var name = ReactCurrentOwner.current.getName();
|
26577 | if (name) {
|
26578 | addendum += ' Check the render method of `' + name + '`.';
|
26579 | }
|
26580 | }
|
26581 | }
|
26582 | var childrenString = String(children);
|
26583 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Objects are not valid as a React child (found: %s).%s', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum) : _prodInvariant('31', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum) : void 0;
|
26584 | }
|
26585 | }
|
26586 |
|
26587 | return subtreeCount;
|
26588 | }
|
26589 |
|
26590 | /**
|
26591 | * Traverses children that are typically specified as `props.children`, but
|
26592 | * might also be specified through attributes:
|
26593 | *
|
26594 | * - `traverseAllChildren(this.props.children, ...)`
|
26595 | * - `traverseAllChildren(this.props.leftPanelChildren, ...)`
|
26596 | *
|
26597 | * The `traverseContext` is an optional argument that is passed through the
|
26598 | * entire traversal. It can be used to store accumulations or anything else that
|
26599 | * the callback might find relevant.
|
26600 | *
|
26601 | * @param {?*} children Children tree object.
|
26602 | * @param {!function} callback To invoke upon traversing each child.
|
26603 | * @param {?*} traverseContext Context for traversal.
|
26604 | * @return {!number} The number of children in this subtree.
|
26605 | */
|
26606 | function traverseAllChildren(children, callback, traverseContext) {
|
26607 | if (children == null) {
|
26608 | return 0;
|
26609 | }
|
26610 |
|
26611 | return traverseAllChildrenImpl(children, '', callback, traverseContext);
|
26612 | }
|
26613 |
|
26614 | module.exports = traverseAllChildren;
|
26615 | }).call(this,require('_process'))
|
26616 | },{"./KeyEscapeUtils":175,"./ReactElementSymbol":205,"./getIteratorFn":267,"./reactProdInvariant":276,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131,"react/lib/ReactCurrentOwner":292}],282:[function(require,module,exports){
|
26617 | (function (process){
|
26618 | /**
|
26619 | * Copyright 2015-present, Facebook, Inc.
|
26620 | * All rights reserved.
|
26621 | *
|
26622 | * This source code is licensed under the BSD-style license found in the
|
26623 | * LICENSE file in the root directory of this source tree. An additional grant
|
26624 | * of patent rights can be found in the PATENTS file in the same directory.
|
26625 | *
|
26626 | */
|
26627 |
|
26628 | 'use strict';
|
26629 |
|
26630 | var _assign = require('object-assign');
|
26631 |
|
26632 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
26633 | var warning = require('fbjs/lib/warning');
|
26634 |
|
26635 | var validateDOMNesting = emptyFunction;
|
26636 |
|
26637 | if (process.env.NODE_ENV !== 'production') {
|
26638 | // This validation code was written based on the HTML5 parsing spec:
|
26639 | // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-scope
|
26640 | //
|
26641 | // Note: this does not catch all invalid nesting, nor does it try to (as it's
|
26642 | // not clear what practical benefit doing so provides); instead, we warn only
|
26643 | // for cases where the parser will give a parse tree differing from what React
|
26644 | // intended. For example, <b><div></div></b> is invalid but we don't warn
|
26645 | // because it still parses correctly; we do warn for other cases like nested
|
26646 | // <p> tags where the beginning of the second element implicitly closes the
|
26647 | // first, causing a confusing mess.
|
26648 |
|
26649 | // https://html.spec.whatwg.org/multipage/syntax.html#special
|
26650 | var specialTags = ['address', 'applet', 'area', 'article', 'aside', 'base', 'basefont', 'bgsound', 'blockquote', 'body', 'br', 'button', 'caption', 'center', 'col', 'colgroup', 'dd', 'details', 'dir', 'div', 'dl', 'dt', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'iframe', 'img', 'input', 'isindex', 'li', 'link', 'listing', 'main', 'marquee', 'menu', 'menuitem', 'meta', 'nav', 'noembed', 'noframes', 'noscript', 'object', 'ol', 'p', 'param', 'plaintext', 'pre', 'script', 'section', 'select', 'source', 'style', 'summary', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'track', 'ul', 'wbr', 'xmp'];
|
26651 |
|
26652 | // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-scope
|
26653 | var inScopeTags = ['applet', 'caption', 'html', 'table', 'td', 'th', 'marquee', 'object', 'template',
|
26654 |
|
26655 | // https://html.spec.whatwg.org/multipage/syntax.html#html-integration-point
|
26656 | // TODO: Distinguish by namespace here -- for <title>, including it here
|
26657 | // errs on the side of fewer warnings
|
26658 | 'foreignObject', 'desc', 'title'];
|
26659 |
|
26660 | // https://html.spec.whatwg.org/multipage/syntax.html#has-an-element-in-button-scope
|
26661 | var buttonScopeTags = inScopeTags.concat(['button']);
|
26662 |
|
26663 | // https://html.spec.whatwg.org/multipage/syntax.html#generate-implied-end-tags
|
26664 | var impliedEndTags = ['dd', 'dt', 'li', 'option', 'optgroup', 'p', 'rp', 'rt'];
|
26665 |
|
26666 | var emptyAncestorInfo = {
|
26667 | current: null,
|
26668 |
|
26669 | formTag: null,
|
26670 | aTagInScope: null,
|
26671 | buttonTagInScope: null,
|
26672 | nobrTagInScope: null,
|
26673 | pTagInButtonScope: null,
|
26674 |
|
26675 | listItemTagAutoclosing: null,
|
26676 | dlItemTagAutoclosing: null
|
26677 | };
|
26678 |
|
26679 | var updatedAncestorInfo = function (oldInfo, tag, instance) {
|
26680 | var ancestorInfo = _assign({}, oldInfo || emptyAncestorInfo);
|
26681 | var info = { tag: tag, instance: instance };
|
26682 |
|
26683 | if (inScopeTags.indexOf(tag) !== -1) {
|
26684 | ancestorInfo.aTagInScope = null;
|
26685 | ancestorInfo.buttonTagInScope = null;
|
26686 | ancestorInfo.nobrTagInScope = null;
|
26687 | }
|
26688 | if (buttonScopeTags.indexOf(tag) !== -1) {
|
26689 | ancestorInfo.pTagInButtonScope = null;
|
26690 | }
|
26691 |
|
26692 | // See rules for 'li', 'dd', 'dt' start tags in
|
26693 | // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
|
26694 | if (specialTags.indexOf(tag) !== -1 && tag !== 'address' && tag !== 'div' && tag !== 'p') {
|
26695 | ancestorInfo.listItemTagAutoclosing = null;
|
26696 | ancestorInfo.dlItemTagAutoclosing = null;
|
26697 | }
|
26698 |
|
26699 | ancestorInfo.current = info;
|
26700 |
|
26701 | if (tag === 'form') {
|
26702 | ancestorInfo.formTag = info;
|
26703 | }
|
26704 | if (tag === 'a') {
|
26705 | ancestorInfo.aTagInScope = info;
|
26706 | }
|
26707 | if (tag === 'button') {
|
26708 | ancestorInfo.buttonTagInScope = info;
|
26709 | }
|
26710 | if (tag === 'nobr') {
|
26711 | ancestorInfo.nobrTagInScope = info;
|
26712 | }
|
26713 | if (tag === 'p') {
|
26714 | ancestorInfo.pTagInButtonScope = info;
|
26715 | }
|
26716 | if (tag === 'li') {
|
26717 | ancestorInfo.listItemTagAutoclosing = info;
|
26718 | }
|
26719 | if (tag === 'dd' || tag === 'dt') {
|
26720 | ancestorInfo.dlItemTagAutoclosing = info;
|
26721 | }
|
26722 |
|
26723 | return ancestorInfo;
|
26724 | };
|
26725 |
|
26726 | /**
|
26727 | * Returns whether
|
26728 | */
|
26729 | var isTagValidWithParent = function (tag, parentTag) {
|
26730 | // First, let's check if we're in an unusual parsing mode...
|
26731 | switch (parentTag) {
|
26732 | // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inselect
|
26733 | case 'select':
|
26734 | return tag === 'option' || tag === 'optgroup' || tag === '#text';
|
26735 | case 'optgroup':
|
26736 | return tag === 'option' || tag === '#text';
|
26737 | // Strictly speaking, seeing an <option> doesn't mean we're in a <select>
|
26738 | // but
|
26739 | case 'option':
|
26740 | return tag === '#text';
|
26741 |
|
26742 | // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intd
|
26743 | // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incaption
|
26744 | // No special behavior since these rules fall back to "in body" mode for
|
26745 | // all except special table nodes which cause bad parsing behavior anyway.
|
26746 |
|
26747 | // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intr
|
26748 | case 'tr':
|
26749 | return tag === 'th' || tag === 'td' || tag === 'style' || tag === 'script' || tag === 'template';
|
26750 |
|
26751 | // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intbody
|
26752 | case 'tbody':
|
26753 | case 'thead':
|
26754 | case 'tfoot':
|
26755 | return tag === 'tr' || tag === 'style' || tag === 'script' || tag === 'template';
|
26756 |
|
26757 | // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incolgroup
|
26758 | case 'colgroup':
|
26759 | return tag === 'col' || tag === 'template';
|
26760 |
|
26761 | // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intable
|
26762 | case 'table':
|
26763 | return tag === 'caption' || tag === 'colgroup' || tag === 'tbody' || tag === 'tfoot' || tag === 'thead' || tag === 'style' || tag === 'script' || tag === 'template';
|
26764 |
|
26765 | // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inhead
|
26766 | case 'head':
|
26767 | return tag === 'base' || tag === 'basefont' || tag === 'bgsound' || tag === 'link' || tag === 'meta' || tag === 'title' || tag === 'noscript' || tag === 'noframes' || tag === 'style' || tag === 'script' || tag === 'template';
|
26768 |
|
26769 | // https://html.spec.whatwg.org/multipage/semantics.html#the-html-element
|
26770 | case 'html':
|
26771 | return tag === 'head' || tag === 'body';
|
26772 | case '#document':
|
26773 | return tag === 'html';
|
26774 | }
|
26775 |
|
26776 | // Probably in the "in body" parsing mode, so we outlaw only tag combos
|
26777 | // where the parsing rules cause implicit opens or closes to be added.
|
26778 | // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
|
26779 | switch (tag) {
|
26780 | case 'h1':
|
26781 | case 'h2':
|
26782 | case 'h3':
|
26783 | case 'h4':
|
26784 | case 'h5':
|
26785 | case 'h6':
|
26786 | return parentTag !== 'h1' && parentTag !== 'h2' && parentTag !== 'h3' && parentTag !== 'h4' && parentTag !== 'h5' && parentTag !== 'h6';
|
26787 |
|
26788 | case 'rp':
|
26789 | case 'rt':
|
26790 | return impliedEndTags.indexOf(parentTag) === -1;
|
26791 |
|
26792 | case 'body':
|
26793 | case 'caption':
|
26794 | case 'col':
|
26795 | case 'colgroup':
|
26796 | case 'frame':
|
26797 | case 'head':
|
26798 | case 'html':
|
26799 | case 'tbody':
|
26800 | case 'td':
|
26801 | case 'tfoot':
|
26802 | case 'th':
|
26803 | case 'thead':
|
26804 | case 'tr':
|
26805 | // These tags are only valid with a few parents that have special child
|
26806 | // parsing rules -- if we're down here, then none of those matched and
|
26807 | // so we allow it only if we don't know what the parent is, as all other
|
26808 | // cases are invalid.
|
26809 | return parentTag == null;
|
26810 | }
|
26811 |
|
26812 | return true;
|
26813 | };
|
26814 |
|
26815 | /**
|
26816 | * Returns whether
|
26817 | */
|
26818 | var findInvalidAncestorForTag = function (tag, ancestorInfo) {
|
26819 | switch (tag) {
|
26820 | case 'address':
|
26821 | case 'article':
|
26822 | case 'aside':
|
26823 | case 'blockquote':
|
26824 | case 'center':
|
26825 | case 'details':
|
26826 | case 'dialog':
|
26827 | case 'dir':
|
26828 | case 'div':
|
26829 | case 'dl':
|
26830 | case 'fieldset':
|
26831 | case 'figcaption':
|
26832 | case 'figure':
|
26833 | case 'footer':
|
26834 | case 'header':
|
26835 | case 'hgroup':
|
26836 | case 'main':
|
26837 | case 'menu':
|
26838 | case 'nav':
|
26839 | case 'ol':
|
26840 | case 'p':
|
26841 | case 'section':
|
26842 | case 'summary':
|
26843 | case 'ul':
|
26844 |
|
26845 | case 'pre':
|
26846 | case 'listing':
|
26847 |
|
26848 | case 'table':
|
26849 |
|
26850 | case 'hr':
|
26851 |
|
26852 | case 'xmp':
|
26853 |
|
26854 | case 'h1':
|
26855 | case 'h2':
|
26856 | case 'h3':
|
26857 | case 'h4':
|
26858 | case 'h5':
|
26859 | case 'h6':
|
26860 | return ancestorInfo.pTagInButtonScope;
|
26861 |
|
26862 | case 'form':
|
26863 | return ancestorInfo.formTag || ancestorInfo.pTagInButtonScope;
|
26864 |
|
26865 | case 'li':
|
26866 | return ancestorInfo.listItemTagAutoclosing;
|
26867 |
|
26868 | case 'dd':
|
26869 | case 'dt':
|
26870 | return ancestorInfo.dlItemTagAutoclosing;
|
26871 |
|
26872 | case 'button':
|
26873 | return ancestorInfo.buttonTagInScope;
|
26874 |
|
26875 | case 'a':
|
26876 | // Spec says something about storing a list of markers, but it sounds
|
26877 | // equivalent to this check.
|
26878 | return ancestorInfo.aTagInScope;
|
26879 |
|
26880 | case 'nobr':
|
26881 | return ancestorInfo.nobrTagInScope;
|
26882 | }
|
26883 |
|
26884 | return null;
|
26885 | };
|
26886 |
|
26887 | /**
|
26888 | * Given a ReactCompositeComponent instance, return a list of its recursive
|
26889 | * owners, starting at the root and ending with the instance itself.
|
26890 | */
|
26891 | var findOwnerStack = function (instance) {
|
26892 | if (!instance) {
|
26893 | return [];
|
26894 | }
|
26895 |
|
26896 | var stack = [];
|
26897 | do {
|
26898 | stack.push(instance);
|
26899 | } while (instance = instance._currentElement._owner);
|
26900 | stack.reverse();
|
26901 | return stack;
|
26902 | };
|
26903 |
|
26904 | var didWarn = {};
|
26905 |
|
26906 | validateDOMNesting = function (childTag, childText, childInstance, ancestorInfo) {
|
26907 | ancestorInfo = ancestorInfo || emptyAncestorInfo;
|
26908 | var parentInfo = ancestorInfo.current;
|
26909 | var parentTag = parentInfo && parentInfo.tag;
|
26910 |
|
26911 | if (childText != null) {
|
26912 | process.env.NODE_ENV !== 'production' ? warning(childTag == null, 'validateDOMNesting: when childText is passed, childTag should be null') : void 0;
|
26913 | childTag = '#text';
|
26914 | }
|
26915 |
|
26916 | var invalidParent = isTagValidWithParent(childTag, parentTag) ? null : parentInfo;
|
26917 | var invalidAncestor = invalidParent ? null : findInvalidAncestorForTag(childTag, ancestorInfo);
|
26918 | var problematic = invalidParent || invalidAncestor;
|
26919 |
|
26920 | if (problematic) {
|
26921 | var ancestorTag = problematic.tag;
|
26922 | var ancestorInstance = problematic.instance;
|
26923 |
|
26924 | var childOwner = childInstance && childInstance._currentElement._owner;
|
26925 | var ancestorOwner = ancestorInstance && ancestorInstance._currentElement._owner;
|
26926 |
|
26927 | var childOwners = findOwnerStack(childOwner);
|
26928 | var ancestorOwners = findOwnerStack(ancestorOwner);
|
26929 |
|
26930 | var minStackLen = Math.min(childOwners.length, ancestorOwners.length);
|
26931 | var i;
|
26932 |
|
26933 | var deepestCommon = -1;
|
26934 | for (i = 0; i < minStackLen; i++) {
|
26935 | if (childOwners[i] === ancestorOwners[i]) {
|
26936 | deepestCommon = i;
|
26937 | } else {
|
26938 | break;
|
26939 | }
|
26940 | }
|
26941 |
|
26942 | var UNKNOWN = '(unknown)';
|
26943 | var childOwnerNames = childOwners.slice(deepestCommon + 1).map(function (inst) {
|
26944 | return inst.getName() || UNKNOWN;
|
26945 | });
|
26946 | var ancestorOwnerNames = ancestorOwners.slice(deepestCommon + 1).map(function (inst) {
|
26947 | return inst.getName() || UNKNOWN;
|
26948 | });
|
26949 | var ownerInfo = [].concat(
|
26950 | // If the parent and child instances have a common owner ancestor, start
|
26951 | // with that -- otherwise we just start with the parent's owners.
|
26952 | deepestCommon !== -1 ? childOwners[deepestCommon].getName() || UNKNOWN : [], ancestorOwnerNames, ancestorTag,
|
26953 | // If we're warning about an invalid (non-parent) ancestry, add '...'
|
26954 | invalidAncestor ? ['...'] : [], childOwnerNames, childTag).join(' > ');
|
26955 |
|
26956 | var warnKey = !!invalidParent + '|' + childTag + '|' + ancestorTag + '|' + ownerInfo;
|
26957 | if (didWarn[warnKey]) {
|
26958 | return;
|
26959 | }
|
26960 | didWarn[warnKey] = true;
|
26961 |
|
26962 | var tagDisplayName = childTag;
|
26963 | var whitespaceInfo = '';
|
26964 | if (childTag === '#text') {
|
26965 | if (/\S/.test(childText)) {
|
26966 | tagDisplayName = 'Text nodes';
|
26967 | } else {
|
26968 | tagDisplayName = 'Whitespace text nodes';
|
26969 | whitespaceInfo = ' Make sure you don\'t have any extra whitespace between tags on ' + 'each line of your source code.';
|
26970 | }
|
26971 | } else {
|
26972 | tagDisplayName = '<' + childTag + '>';
|
26973 | }
|
26974 |
|
26975 | if (invalidParent) {
|
26976 | var info = '';
|
26977 | if (ancestorTag === 'table' && childTag === 'tr') {
|
26978 | info += ' Add a <tbody> to your code to match the DOM tree generated by ' + 'the browser.';
|
26979 | }
|
26980 | process.env.NODE_ENV !== 'production' ? warning(false, 'validateDOMNesting(...): %s cannot appear as a child of <%s>.%s ' + 'See %s.%s', tagDisplayName, ancestorTag, whitespaceInfo, ownerInfo, info) : void 0;
|
26981 | } else {
|
26982 | process.env.NODE_ENV !== 'production' ? warning(false, 'validateDOMNesting(...): %s cannot appear as a descendant of ' + '<%s>. See %s.', tagDisplayName, ancestorTag, ownerInfo) : void 0;
|
26983 | }
|
26984 | }
|
26985 | };
|
26986 |
|
26987 | validateDOMNesting.updatedAncestorInfo = updatedAncestorInfo;
|
26988 |
|
26989 | // For testing
|
26990 | validateDOMNesting.isTagValidInContext = function (tag, ancestorInfo) {
|
26991 | ancestorInfo = ancestorInfo || emptyAncestorInfo;
|
26992 | var parentInfo = ancestorInfo.current;
|
26993 | var parentTag = parentInfo && parentInfo.tag;
|
26994 | return isTagValidWithParent(tag, parentTag) && !findInvalidAncestorForTag(tag, ancestorInfo);
|
26995 | };
|
26996 | }
|
26997 |
|
26998 | module.exports = validateDOMNesting;
|
26999 | }).call(this,require('_process'))
|
27000 | },{"_process":144,"fbjs/lib/emptyFunction":116,"fbjs/lib/warning":131,"object-assign":143}],283:[function(require,module,exports){
|
27001 | 'use strict';
|
27002 |
|
27003 | module.exports = require('./lib/ReactDOMServer');
|
27004 |
|
27005 | },{"./lib/ReactDOMServer":197}],284:[function(require,module,exports){
|
27006 | 'use strict';
|
27007 |
|
27008 | Object.defineProperty(exports, "__esModule", {
|
27009 | value: true
|
27010 | });
|
27011 |
|
27012 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
27013 |
|
27014 | var _react = require('react');
|
27015 |
|
27016 | var _react2 = _interopRequireDefault(_react);
|
27017 |
|
27018 | var _reactDom = require('react-dom');
|
27019 |
|
27020 | var _reactDom2 = _interopRequireDefault(_reactDom);
|
27021 |
|
27022 | var _propTypes = require('prop-types');
|
27023 |
|
27024 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
27025 |
|
27026 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
27027 |
|
27028 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
27029 |
|
27030 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
27031 |
|
27032 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
27033 |
|
27034 | var KEYCODES = {
|
27035 | ESCAPE: 27
|
27036 | };
|
27037 |
|
27038 | var Portal = function (_React$Component) {
|
27039 | _inherits(Portal, _React$Component);
|
27040 |
|
27041 | function Portal() {
|
27042 | _classCallCheck(this, Portal);
|
27043 |
|
27044 | var _this = _possibleConstructorReturn(this, (Portal.__proto__ || Object.getPrototypeOf(Portal)).call(this));
|
27045 |
|
27046 | _this.state = { active: false };
|
27047 | _this.handleWrapperClick = _this.handleWrapperClick.bind(_this);
|
27048 | _this.closePortal = _this.closePortal.bind(_this);
|
27049 | _this.handleOutsideMouseClick = _this.handleOutsideMouseClick.bind(_this);
|
27050 | _this.handleKeydown = _this.handleKeydown.bind(_this);
|
27051 | _this.portal = null;
|
27052 | _this.node = null;
|
27053 | return _this;
|
27054 | }
|
27055 |
|
27056 | _createClass(Portal, [{
|
27057 | key: 'componentDidMount',
|
27058 | value: function componentDidMount() {
|
27059 | if (this.props.closeOnEsc) {
|
27060 | document.addEventListener('keydown', this.handleKeydown);
|
27061 | }
|
27062 |
|
27063 | if (this.props.closeOnOutsideClick) {
|
27064 | document.addEventListener('mouseup', this.handleOutsideMouseClick);
|
27065 | document.addEventListener('touchstart', this.handleOutsideMouseClick);
|
27066 | }
|
27067 |
|
27068 | if (this.props.isOpened) {
|
27069 | this.openPortal();
|
27070 | }
|
27071 | }
|
27072 | }, {
|
27073 | key: 'componentWillReceiveProps',
|
27074 | value: function componentWillReceiveProps(newProps) {
|
27075 | // portal's 'is open' state is handled through the prop isOpened
|
27076 | if (typeof newProps.isOpened !== 'undefined') {
|
27077 | if (newProps.isOpened) {
|
27078 | if (this.state.active) {
|
27079 | this.renderPortal(newProps);
|
27080 | } else {
|
27081 | this.openPortal(newProps);
|
27082 | }
|
27083 | }
|
27084 | if (!newProps.isOpened && this.state.active) {
|
27085 | this.closePortal();
|
27086 | }
|
27087 | }
|
27088 |
|
27089 | // portal handles its own 'is open' state
|
27090 | if (typeof newProps.isOpened === 'undefined' && this.state.active) {
|
27091 | this.renderPortal(newProps);
|
27092 | }
|
27093 | }
|
27094 | }, {
|
27095 | key: 'componentWillUnmount',
|
27096 | value: function componentWillUnmount() {
|
27097 | if (this.props.closeOnEsc) {
|
27098 | document.removeEventListener('keydown', this.handleKeydown);
|
27099 | }
|
27100 |
|
27101 | if (this.props.closeOnOutsideClick) {
|
27102 | document.removeEventListener('mouseup', this.handleOutsideMouseClick);
|
27103 | document.removeEventListener('touchstart', this.handleOutsideMouseClick);
|
27104 | }
|
27105 |
|
27106 | this.closePortal(true);
|
27107 | }
|
27108 | }, {
|
27109 | key: 'handleWrapperClick',
|
27110 | value: function handleWrapperClick(e) {
|
27111 | e.preventDefault();
|
27112 | e.stopPropagation();
|
27113 | if (this.state.active) {
|
27114 | return;
|
27115 | }
|
27116 | this.openPortal();
|
27117 | }
|
27118 | }, {
|
27119 | key: 'openPortal',
|
27120 | value: function openPortal() {
|
27121 | var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props;
|
27122 |
|
27123 | this.setState({ active: true });
|
27124 | this.renderPortal(props);
|
27125 | this.props.onOpen(this.node);
|
27126 | }
|
27127 | }, {
|
27128 | key: 'closePortal',
|
27129 | value: function closePortal() {
|
27130 | var _this2 = this;
|
27131 |
|
27132 | var isUnmounted = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
27133 |
|
27134 | var resetPortalState = function resetPortalState() {
|
27135 | if (_this2.node) {
|
27136 | _reactDom2.default.unmountComponentAtNode(_this2.node);
|
27137 | document.body.removeChild(_this2.node);
|
27138 | }
|
27139 | _this2.portal = null;
|
27140 | _this2.node = null;
|
27141 | if (isUnmounted !== true) {
|
27142 | _this2.setState({ active: false });
|
27143 | }
|
27144 | };
|
27145 |
|
27146 | if (this.state.active) {
|
27147 | if (this.props.beforeClose) {
|
27148 | this.props.beforeClose(this.node, resetPortalState);
|
27149 | } else {
|
27150 | resetPortalState();
|
27151 | }
|
27152 |
|
27153 | this.props.onClose();
|
27154 | }
|
27155 | }
|
27156 | }, {
|
27157 | key: 'handleOutsideMouseClick',
|
27158 | value: function handleOutsideMouseClick(e) {
|
27159 | if (!this.state.active) {
|
27160 | return;
|
27161 | }
|
27162 |
|
27163 | var root = (0, _reactDom.findDOMNode)(this.portal);
|
27164 | if (root.contains(e.target) || e.button && e.button !== 0) {
|
27165 | return;
|
27166 | }
|
27167 |
|
27168 | e.stopPropagation();
|
27169 | this.closePortal();
|
27170 | }
|
27171 | }, {
|
27172 | key: 'handleKeydown',
|
27173 | value: function handleKeydown(e) {
|
27174 | if (e.keyCode === KEYCODES.ESCAPE && this.state.active) {
|
27175 | this.closePortal();
|
27176 | }
|
27177 | }
|
27178 | }, {
|
27179 | key: 'renderPortal',
|
27180 | value: function renderPortal(props) {
|
27181 | if (!this.node) {
|
27182 | this.node = document.createElement('div');
|
27183 | document.body.appendChild(this.node);
|
27184 | }
|
27185 |
|
27186 | var children = props.children;
|
27187 | // https://gist.github.com/jimfb/d99e0678e9da715ccf6454961ef04d1b
|
27188 | if (typeof props.children.type === 'function') {
|
27189 | children = _react2.default.cloneElement(props.children, { closePortal: this.closePortal });
|
27190 | }
|
27191 |
|
27192 | this.portal = _reactDom2.default.unstable_renderSubtreeIntoContainer(this, children, this.node, this.props.onUpdate);
|
27193 | }
|
27194 | }, {
|
27195 | key: 'render',
|
27196 | value: function render() {
|
27197 | if (this.props.openByClickOn) {
|
27198 | return _react2.default.cloneElement(this.props.openByClickOn, { onClick: this.handleWrapperClick });
|
27199 | }
|
27200 | return null;
|
27201 | }
|
27202 | }]);
|
27203 |
|
27204 | return Portal;
|
27205 | }(_react2.default.Component);
|
27206 |
|
27207 | exports.default = Portal;
|
27208 |
|
27209 |
|
27210 | Portal.propTypes = {
|
27211 | children: _propTypes2.default.element.isRequired,
|
27212 | openByClickOn: _propTypes2.default.element,
|
27213 | closeOnEsc: _propTypes2.default.bool,
|
27214 | closeOnOutsideClick: _propTypes2.default.bool,
|
27215 | isOpened: _propTypes2.default.bool,
|
27216 | onOpen: _propTypes2.default.func,
|
27217 | onClose: _propTypes2.default.func,
|
27218 | beforeClose: _propTypes2.default.func,
|
27219 | onUpdate: _propTypes2.default.func
|
27220 | };
|
27221 |
|
27222 | Portal.defaultProps = {
|
27223 | onOpen: function onOpen() {},
|
27224 | onClose: function onClose() {},
|
27225 | onUpdate: function onUpdate() {}
|
27226 | };
|
27227 | module.exports = exports['default'];
|
27228 |
|
27229 | },{"prop-types":148,"react":309,"react-dom":153}],285:[function(require,module,exports){
|
27230 | arguments[4][175][0].apply(exports,arguments)
|
27231 | },{"dup":175}],286:[function(require,module,exports){
|
27232 | arguments[4][177][0].apply(exports,arguments)
|
27233 | },{"./reactProdInvariant":307,"_process":144,"dup":177,"fbjs/lib/invariant":124}],287:[function(require,module,exports){
|
27234 | (function (process){
|
27235 | /**
|
27236 | * Copyright 2013-present, Facebook, Inc.
|
27237 | * All rights reserved.
|
27238 | *
|
27239 | * This source code is licensed under the BSD-style license found in the
|
27240 | * LICENSE file in the root directory of this source tree. An additional grant
|
27241 | * of patent rights can be found in the PATENTS file in the same directory.
|
27242 | *
|
27243 | */
|
27244 |
|
27245 | 'use strict';
|
27246 |
|
27247 | var _assign = require('object-assign');
|
27248 |
|
27249 | var ReactChildren = require('./ReactChildren');
|
27250 | var ReactComponent = require('./ReactComponent');
|
27251 | var ReactPureComponent = require('./ReactPureComponent');
|
27252 | var ReactClass = require('./ReactClass');
|
27253 | var ReactDOMFactories = require('./ReactDOMFactories');
|
27254 | var ReactElement = require('./ReactElement');
|
27255 | var ReactPropTypes = require('./ReactPropTypes');
|
27256 | var ReactVersion = require('./ReactVersion');
|
27257 |
|
27258 | var onlyChild = require('./onlyChild');
|
27259 | var warning = require('fbjs/lib/warning');
|
27260 |
|
27261 | var createElement = ReactElement.createElement;
|
27262 | var createFactory = ReactElement.createFactory;
|
27263 | var cloneElement = ReactElement.cloneElement;
|
27264 |
|
27265 | if (process.env.NODE_ENV !== 'production') {
|
27266 | var ReactElementValidator = require('./ReactElementValidator');
|
27267 | createElement = ReactElementValidator.createElement;
|
27268 | createFactory = ReactElementValidator.createFactory;
|
27269 | cloneElement = ReactElementValidator.cloneElement;
|
27270 | }
|
27271 |
|
27272 | var __spread = _assign;
|
27273 |
|
27274 | if (process.env.NODE_ENV !== 'production') {
|
27275 | var warned = false;
|
27276 | __spread = function () {
|
27277 | process.env.NODE_ENV !== 'production' ? warning(warned, 'React.__spread is deprecated and should not be used. Use ' + 'Object.assign directly or another helper function with similar ' + 'semantics. You may be seeing this warning due to your compiler. ' + 'See https://fb.me/react-spread-deprecation for more details.') : void 0;
|
27278 | warned = true;
|
27279 | return _assign.apply(null, arguments);
|
27280 | };
|
27281 | }
|
27282 |
|
27283 | var React = {
|
27284 |
|
27285 | // Modern
|
27286 |
|
27287 | Children: {
|
27288 | map: ReactChildren.map,
|
27289 | forEach: ReactChildren.forEach,
|
27290 | count: ReactChildren.count,
|
27291 | toArray: ReactChildren.toArray,
|
27292 | only: onlyChild
|
27293 | },
|
27294 |
|
27295 | Component: ReactComponent,
|
27296 | PureComponent: ReactPureComponent,
|
27297 |
|
27298 | createElement: createElement,
|
27299 | cloneElement: cloneElement,
|
27300 | isValidElement: ReactElement.isValidElement,
|
27301 |
|
27302 | // Classic
|
27303 |
|
27304 | PropTypes: ReactPropTypes,
|
27305 | createClass: ReactClass.createClass,
|
27306 | createFactory: createFactory,
|
27307 | createMixin: function (mixin) {
|
27308 | // Currently a noop. Will be used to validate and trace mixins.
|
27309 | return mixin;
|
27310 | },
|
27311 |
|
27312 | // This looks DOM specific but these are actually isomorphic helpers
|
27313 | // since they are just generating DOM strings.
|
27314 | DOM: ReactDOMFactories,
|
27315 |
|
27316 | version: ReactVersion,
|
27317 |
|
27318 | // Deprecated hook for JSX spread, don't use this for anything.
|
27319 | __spread: __spread
|
27320 | };
|
27321 |
|
27322 | module.exports = React;
|
27323 | }).call(this,require('_process'))
|
27324 | },{"./ReactChildren":288,"./ReactClass":289,"./ReactComponent":290,"./ReactDOMFactories":293,"./ReactElement":294,"./ReactElementValidator":296,"./ReactPropTypes":299,"./ReactPureComponent":301,"./ReactVersion":302,"./onlyChild":306,"_process":144,"fbjs/lib/warning":131,"object-assign":143}],288:[function(require,module,exports){
|
27325 | /**
|
27326 | * Copyright 2013-present, Facebook, Inc.
|
27327 | * All rights reserved.
|
27328 | *
|
27329 | * This source code is licensed under the BSD-style license found in the
|
27330 | * LICENSE file in the root directory of this source tree. An additional grant
|
27331 | * of patent rights can be found in the PATENTS file in the same directory.
|
27332 | *
|
27333 | */
|
27334 |
|
27335 | 'use strict';
|
27336 |
|
27337 | var PooledClass = require('./PooledClass');
|
27338 | var ReactElement = require('./ReactElement');
|
27339 |
|
27340 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
27341 | var traverseAllChildren = require('./traverseAllChildren');
|
27342 |
|
27343 | var twoArgumentPooler = PooledClass.twoArgumentPooler;
|
27344 | var fourArgumentPooler = PooledClass.fourArgumentPooler;
|
27345 |
|
27346 | var userProvidedKeyEscapeRegex = /\/+/g;
|
27347 | function escapeUserProvidedKey(text) {
|
27348 | return ('' + text).replace(userProvidedKeyEscapeRegex, '$&/');
|
27349 | }
|
27350 |
|
27351 | /**
|
27352 | * PooledClass representing the bookkeeping associated with performing a child
|
27353 | * traversal. Allows avoiding binding callbacks.
|
27354 | *
|
27355 | * @constructor ForEachBookKeeping
|
27356 | * @param {!function} forEachFunction Function to perform traversal with.
|
27357 | * @param {?*} forEachContext Context to perform context with.
|
27358 | */
|
27359 | function ForEachBookKeeping(forEachFunction, forEachContext) {
|
27360 | this.func = forEachFunction;
|
27361 | this.context = forEachContext;
|
27362 | this.count = 0;
|
27363 | }
|
27364 | ForEachBookKeeping.prototype.destructor = function () {
|
27365 | this.func = null;
|
27366 | this.context = null;
|
27367 | this.count = 0;
|
27368 | };
|
27369 | PooledClass.addPoolingTo(ForEachBookKeeping, twoArgumentPooler);
|
27370 |
|
27371 | function forEachSingleChild(bookKeeping, child, name) {
|
27372 | var func = bookKeeping.func,
|
27373 | context = bookKeeping.context;
|
27374 |
|
27375 | func.call(context, child, bookKeeping.count++);
|
27376 | }
|
27377 |
|
27378 | /**
|
27379 | * Iterates through children that are typically specified as `props.children`.
|
27380 | *
|
27381 | * See https://facebook.github.io/react/docs/top-level-api.html#react.children.foreach
|
27382 | *
|
27383 | * The provided forEachFunc(child, index) will be called for each
|
27384 | * leaf child.
|
27385 | *
|
27386 | * @param {?*} children Children tree container.
|
27387 | * @param {function(*, int)} forEachFunc
|
27388 | * @param {*} forEachContext Context for forEachContext.
|
27389 | */
|
27390 | function forEachChildren(children, forEachFunc, forEachContext) {
|
27391 | if (children == null) {
|
27392 | return children;
|
27393 | }
|
27394 | var traverseContext = ForEachBookKeeping.getPooled(forEachFunc, forEachContext);
|
27395 | traverseAllChildren(children, forEachSingleChild, traverseContext);
|
27396 | ForEachBookKeeping.release(traverseContext);
|
27397 | }
|
27398 |
|
27399 | /**
|
27400 | * PooledClass representing the bookkeeping associated with performing a child
|
27401 | * mapping. Allows avoiding binding callbacks.
|
27402 | *
|
27403 | * @constructor MapBookKeeping
|
27404 | * @param {!*} mapResult Object containing the ordered map of results.
|
27405 | * @param {!function} mapFunction Function to perform mapping with.
|
27406 | * @param {?*} mapContext Context to perform mapping with.
|
27407 | */
|
27408 | function MapBookKeeping(mapResult, keyPrefix, mapFunction, mapContext) {
|
27409 | this.result = mapResult;
|
27410 | this.keyPrefix = keyPrefix;
|
27411 | this.func = mapFunction;
|
27412 | this.context = mapContext;
|
27413 | this.count = 0;
|
27414 | }
|
27415 | MapBookKeeping.prototype.destructor = function () {
|
27416 | this.result = null;
|
27417 | this.keyPrefix = null;
|
27418 | this.func = null;
|
27419 | this.context = null;
|
27420 | this.count = 0;
|
27421 | };
|
27422 | PooledClass.addPoolingTo(MapBookKeeping, fourArgumentPooler);
|
27423 |
|
27424 | function mapSingleChildIntoContext(bookKeeping, child, childKey) {
|
27425 | var result = bookKeeping.result,
|
27426 | keyPrefix = bookKeeping.keyPrefix,
|
27427 | func = bookKeeping.func,
|
27428 | context = bookKeeping.context;
|
27429 |
|
27430 |
|
27431 | var mappedChild = func.call(context, child, bookKeeping.count++);
|
27432 | if (Array.isArray(mappedChild)) {
|
27433 | mapIntoWithKeyPrefixInternal(mappedChild, result, childKey, emptyFunction.thatReturnsArgument);
|
27434 | } else if (mappedChild != null) {
|
27435 | if (ReactElement.isValidElement(mappedChild)) {
|
27436 | mappedChild = ReactElement.cloneAndReplaceKey(mappedChild,
|
27437 | // Keep both the (mapped) and old keys if they differ, just as
|
27438 | // traverseAllChildren used to do for objects as children
|
27439 | keyPrefix + (mappedChild.key && (!child || child.key !== mappedChild.key) ? escapeUserProvidedKey(mappedChild.key) + '/' : '') + childKey);
|
27440 | }
|
27441 | result.push(mappedChild);
|
27442 | }
|
27443 | }
|
27444 |
|
27445 | function mapIntoWithKeyPrefixInternal(children, array, prefix, func, context) {
|
27446 | var escapedPrefix = '';
|
27447 | if (prefix != null) {
|
27448 | escapedPrefix = escapeUserProvidedKey(prefix) + '/';
|
27449 | }
|
27450 | var traverseContext = MapBookKeeping.getPooled(array, escapedPrefix, func, context);
|
27451 | traverseAllChildren(children, mapSingleChildIntoContext, traverseContext);
|
27452 | MapBookKeeping.release(traverseContext);
|
27453 | }
|
27454 |
|
27455 | /**
|
27456 | * Maps children that are typically specified as `props.children`.
|
27457 | *
|
27458 | * See https://facebook.github.io/react/docs/top-level-api.html#react.children.map
|
27459 | *
|
27460 | * The provided mapFunction(child, key, index) will be called for each
|
27461 | * leaf child.
|
27462 | *
|
27463 | * @param {?*} children Children tree container.
|
27464 | * @param {function(*, int)} func The map function.
|
27465 | * @param {*} context Context for mapFunction.
|
27466 | * @return {object} Object containing the ordered map of results.
|
27467 | */
|
27468 | function mapChildren(children, func, context) {
|
27469 | if (children == null) {
|
27470 | return children;
|
27471 | }
|
27472 | var result = [];
|
27473 | mapIntoWithKeyPrefixInternal(children, result, null, func, context);
|
27474 | return result;
|
27475 | }
|
27476 |
|
27477 | function forEachSingleChildDummy(traverseContext, child, name) {
|
27478 | return null;
|
27479 | }
|
27480 |
|
27481 | /**
|
27482 | * Count the number of children that are typically specified as
|
27483 | * `props.children`.
|
27484 | *
|
27485 | * See https://facebook.github.io/react/docs/top-level-api.html#react.children.count
|
27486 | *
|
27487 | * @param {?*} children Children tree container.
|
27488 | * @return {number} The number of children.
|
27489 | */
|
27490 | function countChildren(children, context) {
|
27491 | return traverseAllChildren(children, forEachSingleChildDummy, null);
|
27492 | }
|
27493 |
|
27494 | /**
|
27495 | * Flatten a children object (typically specified as `props.children`) and
|
27496 | * return an array with appropriately re-keyed children.
|
27497 | *
|
27498 | * See https://facebook.github.io/react/docs/top-level-api.html#react.children.toarray
|
27499 | */
|
27500 | function toArray(children) {
|
27501 | var result = [];
|
27502 | mapIntoWithKeyPrefixInternal(children, result, null, emptyFunction.thatReturnsArgument);
|
27503 | return result;
|
27504 | }
|
27505 |
|
27506 | var ReactChildren = {
|
27507 | forEach: forEachChildren,
|
27508 | map: mapChildren,
|
27509 | mapIntoWithKeyPrefixInternal: mapIntoWithKeyPrefixInternal,
|
27510 | count: countChildren,
|
27511 | toArray: toArray
|
27512 | };
|
27513 |
|
27514 | module.exports = ReactChildren;
|
27515 | },{"./PooledClass":286,"./ReactElement":294,"./traverseAllChildren":308,"fbjs/lib/emptyFunction":116}],289:[function(require,module,exports){
|
27516 | (function (process){
|
27517 | /**
|
27518 | * Copyright 2013-present, Facebook, Inc.
|
27519 | * All rights reserved.
|
27520 | *
|
27521 | * This source code is licensed under the BSD-style license found in the
|
27522 | * LICENSE file in the root directory of this source tree. An additional grant
|
27523 | * of patent rights can be found in the PATENTS file in the same directory.
|
27524 | *
|
27525 | */
|
27526 |
|
27527 | 'use strict';
|
27528 |
|
27529 | var _prodInvariant = require('./reactProdInvariant'),
|
27530 | _assign = require('object-assign');
|
27531 |
|
27532 | var ReactComponent = require('./ReactComponent');
|
27533 | var ReactElement = require('./ReactElement');
|
27534 | var ReactPropTypeLocationNames = require('./ReactPropTypeLocationNames');
|
27535 | var ReactNoopUpdateQueue = require('./ReactNoopUpdateQueue');
|
27536 |
|
27537 | var emptyObject = require('fbjs/lib/emptyObject');
|
27538 | var invariant = require('fbjs/lib/invariant');
|
27539 | var warning = require('fbjs/lib/warning');
|
27540 |
|
27541 | var MIXINS_KEY = 'mixins';
|
27542 |
|
27543 | // Helper function to allow the creation of anonymous functions which do not
|
27544 | // have .name set to the name of the variable being assigned to.
|
27545 | function identity(fn) {
|
27546 | return fn;
|
27547 | }
|
27548 |
|
27549 | /**
|
27550 | * Policies that describe methods in `ReactClassInterface`.
|
27551 | */
|
27552 |
|
27553 |
|
27554 | var injectedMixins = [];
|
27555 |
|
27556 | /**
|
27557 | * Composite components are higher-level components that compose other composite
|
27558 | * or host components.
|
27559 | *
|
27560 | * To create a new type of `ReactClass`, pass a specification of
|
27561 | * your new class to `React.createClass`. The only requirement of your class
|
27562 | * specification is that you implement a `render` method.
|
27563 | *
|
27564 | * var MyComponent = React.createClass({
|
27565 | * render: function() {
|
27566 | * return <div>Hello World</div>;
|
27567 | * }
|
27568 | * });
|
27569 | *
|
27570 | * The class specification supports a specific protocol of methods that have
|
27571 | * special meaning (e.g. `render`). See `ReactClassInterface` for
|
27572 | * more the comprehensive protocol. Any other properties and methods in the
|
27573 | * class specification will be available on the prototype.
|
27574 | *
|
27575 | * @interface ReactClassInterface
|
27576 | * @internal
|
27577 | */
|
27578 | var ReactClassInterface = {
|
27579 |
|
27580 | /**
|
27581 | * An array of Mixin objects to include when defining your component.
|
27582 | *
|
27583 | * @type {array}
|
27584 | * @optional
|
27585 | */
|
27586 | mixins: 'DEFINE_MANY',
|
27587 |
|
27588 | /**
|
27589 | * An object containing properties and methods that should be defined on
|
27590 | * the component's constructor instead of its prototype (static methods).
|
27591 | *
|
27592 | * @type {object}
|
27593 | * @optional
|
27594 | */
|
27595 | statics: 'DEFINE_MANY',
|
27596 |
|
27597 | /**
|
27598 | * Definition of prop types for this component.
|
27599 | *
|
27600 | * @type {object}
|
27601 | * @optional
|
27602 | */
|
27603 | propTypes: 'DEFINE_MANY',
|
27604 |
|
27605 | /**
|
27606 | * Definition of context types for this component.
|
27607 | *
|
27608 | * @type {object}
|
27609 | * @optional
|
27610 | */
|
27611 | contextTypes: 'DEFINE_MANY',
|
27612 |
|
27613 | /**
|
27614 | * Definition of context types this component sets for its children.
|
27615 | *
|
27616 | * @type {object}
|
27617 | * @optional
|
27618 | */
|
27619 | childContextTypes: 'DEFINE_MANY',
|
27620 |
|
27621 | // ==== Definition methods ====
|
27622 |
|
27623 | /**
|
27624 | * Invoked when the component is mounted. Values in the mapping will be set on
|
27625 | * `this.props` if that prop is not specified (i.e. using an `in` check).
|
27626 | *
|
27627 | * This method is invoked before `getInitialState` and therefore cannot rely
|
27628 | * on `this.state` or use `this.setState`.
|
27629 | *
|
27630 | * @return {object}
|
27631 | * @optional
|
27632 | */
|
27633 | getDefaultProps: 'DEFINE_MANY_MERGED',
|
27634 |
|
27635 | /**
|
27636 | * Invoked once before the component is mounted. The return value will be used
|
27637 | * as the initial value of `this.state`.
|
27638 | *
|
27639 | * getInitialState: function() {
|
27640 | * return {
|
27641 | * isOn: false,
|
27642 | * fooBaz: new BazFoo()
|
27643 | * }
|
27644 | * }
|
27645 | *
|
27646 | * @return {object}
|
27647 | * @optional
|
27648 | */
|
27649 | getInitialState: 'DEFINE_MANY_MERGED',
|
27650 |
|
27651 | /**
|
27652 | * @return {object}
|
27653 | * @optional
|
27654 | */
|
27655 | getChildContext: 'DEFINE_MANY_MERGED',
|
27656 |
|
27657 | /**
|
27658 | * Uses props from `this.props` and state from `this.state` to render the
|
27659 | * structure of the component.
|
27660 | *
|
27661 | * No guarantees are made about when or how often this method is invoked, so
|
27662 | * it must not have side effects.
|
27663 | *
|
27664 | * render: function() {
|
27665 | * var name = this.props.name;
|
27666 | * return <div>Hello, {name}!</div>;
|
27667 | * }
|
27668 | *
|
27669 | * @return {ReactComponent}
|
27670 | * @nosideeffects
|
27671 | * @required
|
27672 | */
|
27673 | render: 'DEFINE_ONCE',
|
27674 |
|
27675 | // ==== Delegate methods ====
|
27676 |
|
27677 | /**
|
27678 | * Invoked when the component is initially created and about to be mounted.
|
27679 | * This may have side effects, but any external subscriptions or data created
|
27680 | * by this method must be cleaned up in `componentWillUnmount`.
|
27681 | *
|
27682 | * @optional
|
27683 | */
|
27684 | componentWillMount: 'DEFINE_MANY',
|
27685 |
|
27686 | /**
|
27687 | * Invoked when the component has been mounted and has a DOM representation.
|
27688 | * However, there is no guarantee that the DOM node is in the document.
|
27689 | *
|
27690 | * Use this as an opportunity to operate on the DOM when the component has
|
27691 | * been mounted (initialized and rendered) for the first time.
|
27692 | *
|
27693 | * @param {DOMElement} rootNode DOM element representing the component.
|
27694 | * @optional
|
27695 | */
|
27696 | componentDidMount: 'DEFINE_MANY',
|
27697 |
|
27698 | /**
|
27699 | * Invoked before the component receives new props.
|
27700 | *
|
27701 | * Use this as an opportunity to react to a prop transition by updating the
|
27702 | * state using `this.setState`. Current props are accessed via `this.props`.
|
27703 | *
|
27704 | * componentWillReceiveProps: function(nextProps, nextContext) {
|
27705 | * this.setState({
|
27706 | * likesIncreasing: nextProps.likeCount > this.props.likeCount
|
27707 | * });
|
27708 | * }
|
27709 | *
|
27710 | * NOTE: There is no equivalent `componentWillReceiveState`. An incoming prop
|
27711 | * transition may cause a state change, but the opposite is not true. If you
|
27712 | * need it, you are probably looking for `componentWillUpdate`.
|
27713 | *
|
27714 | * @param {object} nextProps
|
27715 | * @optional
|
27716 | */
|
27717 | componentWillReceiveProps: 'DEFINE_MANY',
|
27718 |
|
27719 | /**
|
27720 | * Invoked while deciding if the component should be updated as a result of
|
27721 | * receiving new props, state and/or context.
|
27722 | *
|
27723 | * Use this as an opportunity to `return false` when you're certain that the
|
27724 | * transition to the new props/state/context will not require a component
|
27725 | * update.
|
27726 | *
|
27727 | * shouldComponentUpdate: function(nextProps, nextState, nextContext) {
|
27728 | * return !equal(nextProps, this.props) ||
|
27729 | * !equal(nextState, this.state) ||
|
27730 | * !equal(nextContext, this.context);
|
27731 | * }
|
27732 | *
|
27733 | * @param {object} nextProps
|
27734 | * @param {?object} nextState
|
27735 | * @param {?object} nextContext
|
27736 | * @return {boolean} True if the component should update.
|
27737 | * @optional
|
27738 | */
|
27739 | shouldComponentUpdate: 'DEFINE_ONCE',
|
27740 |
|
27741 | /**
|
27742 | * Invoked when the component is about to update due to a transition from
|
27743 | * `this.props`, `this.state` and `this.context` to `nextProps`, `nextState`
|
27744 | * and `nextContext`.
|
27745 | *
|
27746 | * Use this as an opportunity to perform preparation before an update occurs.
|
27747 | *
|
27748 | * NOTE: You **cannot** use `this.setState()` in this method.
|
27749 | *
|
27750 | * @param {object} nextProps
|
27751 | * @param {?object} nextState
|
27752 | * @param {?object} nextContext
|
27753 | * @param {ReactReconcileTransaction} transaction
|
27754 | * @optional
|
27755 | */
|
27756 | componentWillUpdate: 'DEFINE_MANY',
|
27757 |
|
27758 | /**
|
27759 | * Invoked when the component's DOM representation has been updated.
|
27760 | *
|
27761 | * Use this as an opportunity to operate on the DOM when the component has
|
27762 | * been updated.
|
27763 | *
|
27764 | * @param {object} prevProps
|
27765 | * @param {?object} prevState
|
27766 | * @param {?object} prevContext
|
27767 | * @param {DOMElement} rootNode DOM element representing the component.
|
27768 | * @optional
|
27769 | */
|
27770 | componentDidUpdate: 'DEFINE_MANY',
|
27771 |
|
27772 | /**
|
27773 | * Invoked when the component is about to be removed from its parent and have
|
27774 | * its DOM representation destroyed.
|
27775 | *
|
27776 | * Use this as an opportunity to deallocate any external resources.
|
27777 | *
|
27778 | * NOTE: There is no `componentDidUnmount` since your component will have been
|
27779 | * destroyed by that point.
|
27780 | *
|
27781 | * @optional
|
27782 | */
|
27783 | componentWillUnmount: 'DEFINE_MANY',
|
27784 |
|
27785 | // ==== Advanced methods ====
|
27786 |
|
27787 | /**
|
27788 | * Updates the component's currently mounted DOM representation.
|
27789 | *
|
27790 | * By default, this implements React's rendering and reconciliation algorithm.
|
27791 | * Sophisticated clients may wish to override this.
|
27792 | *
|
27793 | * @param {ReactReconcileTransaction} transaction
|
27794 | * @internal
|
27795 | * @overridable
|
27796 | */
|
27797 | updateComponent: 'OVERRIDE_BASE'
|
27798 |
|
27799 | };
|
27800 |
|
27801 | /**
|
27802 | * Mapping from class specification keys to special processing functions.
|
27803 | *
|
27804 | * Although these are declared like instance properties in the specification
|
27805 | * when defining classes using `React.createClass`, they are actually static
|
27806 | * and are accessible on the constructor instead of the prototype. Despite
|
27807 | * being static, they must be defined outside of the "statics" key under
|
27808 | * which all other static methods are defined.
|
27809 | */
|
27810 | var RESERVED_SPEC_KEYS = {
|
27811 | displayName: function (Constructor, displayName) {
|
27812 | Constructor.displayName = displayName;
|
27813 | },
|
27814 | mixins: function (Constructor, mixins) {
|
27815 | if (mixins) {
|
27816 | for (var i = 0; i < mixins.length; i++) {
|
27817 | mixSpecIntoComponent(Constructor, mixins[i]);
|
27818 | }
|
27819 | }
|
27820 | },
|
27821 | childContextTypes: function (Constructor, childContextTypes) {
|
27822 | if (process.env.NODE_ENV !== 'production') {
|
27823 | validateTypeDef(Constructor, childContextTypes, 'childContext');
|
27824 | }
|
27825 | Constructor.childContextTypes = _assign({}, Constructor.childContextTypes, childContextTypes);
|
27826 | },
|
27827 | contextTypes: function (Constructor, contextTypes) {
|
27828 | if (process.env.NODE_ENV !== 'production') {
|
27829 | validateTypeDef(Constructor, contextTypes, 'context');
|
27830 | }
|
27831 | Constructor.contextTypes = _assign({}, Constructor.contextTypes, contextTypes);
|
27832 | },
|
27833 | /**
|
27834 | * Special case getDefaultProps which should move into statics but requires
|
27835 | * automatic merging.
|
27836 | */
|
27837 | getDefaultProps: function (Constructor, getDefaultProps) {
|
27838 | if (Constructor.getDefaultProps) {
|
27839 | Constructor.getDefaultProps = createMergedResultFunction(Constructor.getDefaultProps, getDefaultProps);
|
27840 | } else {
|
27841 | Constructor.getDefaultProps = getDefaultProps;
|
27842 | }
|
27843 | },
|
27844 | propTypes: function (Constructor, propTypes) {
|
27845 | if (process.env.NODE_ENV !== 'production') {
|
27846 | validateTypeDef(Constructor, propTypes, 'prop');
|
27847 | }
|
27848 | Constructor.propTypes = _assign({}, Constructor.propTypes, propTypes);
|
27849 | },
|
27850 | statics: function (Constructor, statics) {
|
27851 | mixStaticSpecIntoComponent(Constructor, statics);
|
27852 | },
|
27853 | autobind: function () {} };
|
27854 |
|
27855 | function validateTypeDef(Constructor, typeDef, location) {
|
27856 | for (var propName in typeDef) {
|
27857 | if (typeDef.hasOwnProperty(propName)) {
|
27858 | // use a warning instead of an invariant so components
|
27859 | // don't show up in prod but only in __DEV__
|
27860 | process.env.NODE_ENV !== 'production' ? warning(typeof typeDef[propName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', Constructor.displayName || 'ReactClass', ReactPropTypeLocationNames[location], propName) : void 0;
|
27861 | }
|
27862 | }
|
27863 | }
|
27864 |
|
27865 | function validateMethodOverride(isAlreadyDefined, name) {
|
27866 | var specPolicy = ReactClassInterface.hasOwnProperty(name) ? ReactClassInterface[name] : null;
|
27867 |
|
27868 | // Disallow overriding of base class methods unless explicitly allowed.
|
27869 | if (ReactClassMixin.hasOwnProperty(name)) {
|
27870 | !(specPolicy === 'OVERRIDE_BASE') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.', name) : _prodInvariant('73', name) : void 0;
|
27871 | }
|
27872 |
|
27873 | // Disallow defining methods more than once unless explicitly allowed.
|
27874 | if (isAlreadyDefined) {
|
27875 | !(specPolicy === 'DEFINE_MANY' || specPolicy === 'DEFINE_MANY_MERGED') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.', name) : _prodInvariant('74', name) : void 0;
|
27876 | }
|
27877 | }
|
27878 |
|
27879 | /**
|
27880 | * Mixin helper which handles policy validation and reserved
|
27881 | * specification keys when building React classes.
|
27882 | */
|
27883 | function mixSpecIntoComponent(Constructor, spec) {
|
27884 | if (!spec) {
|
27885 | if (process.env.NODE_ENV !== 'production') {
|
27886 | var typeofSpec = typeof spec;
|
27887 | var isMixinValid = typeofSpec === 'object' && spec !== null;
|
27888 |
|
27889 | process.env.NODE_ENV !== 'production' ? warning(isMixinValid, '%s: You\'re attempting to include a mixin that is either null ' + 'or not an object. Check the mixins included by the component, ' + 'as well as any mixins they include themselves. ' + 'Expected object but got %s.', Constructor.displayName || 'ReactClass', spec === null ? null : typeofSpec) : void 0;
|
27890 | }
|
27891 |
|
27892 | return;
|
27893 | }
|
27894 |
|
27895 | !(typeof spec !== 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: You\'re attempting to use a component class or function as a mixin. Instead, just use a regular object.') : _prodInvariant('75') : void 0;
|
27896 | !!ReactElement.isValidElement(spec) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: You\'re attempting to use a component as a mixin. Instead, just use a regular object.') : _prodInvariant('76') : void 0;
|
27897 |
|
27898 | var proto = Constructor.prototype;
|
27899 | var autoBindPairs = proto.__reactAutoBindPairs;
|
27900 |
|
27901 | // By handling mixins before any other properties, we ensure the same
|
27902 | // chaining order is applied to methods with DEFINE_MANY policy, whether
|
27903 | // mixins are listed before or after these methods in the spec.
|
27904 | if (spec.hasOwnProperty(MIXINS_KEY)) {
|
27905 | RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins);
|
27906 | }
|
27907 |
|
27908 | for (var name in spec) {
|
27909 | if (!spec.hasOwnProperty(name)) {
|
27910 | continue;
|
27911 | }
|
27912 |
|
27913 | if (name === MIXINS_KEY) {
|
27914 | // We have already handled mixins in a special case above.
|
27915 | continue;
|
27916 | }
|
27917 |
|
27918 | var property = spec[name];
|
27919 | var isAlreadyDefined = proto.hasOwnProperty(name);
|
27920 | validateMethodOverride(isAlreadyDefined, name);
|
27921 |
|
27922 | if (RESERVED_SPEC_KEYS.hasOwnProperty(name)) {
|
27923 | RESERVED_SPEC_KEYS[name](Constructor, property);
|
27924 | } else {
|
27925 | // Setup methods on prototype:
|
27926 | // The following member methods should not be automatically bound:
|
27927 | // 1. Expected ReactClass methods (in the "interface").
|
27928 | // 2. Overridden methods (that were mixed in).
|
27929 | var isReactClassMethod = ReactClassInterface.hasOwnProperty(name);
|
27930 | var isFunction = typeof property === 'function';
|
27931 | var shouldAutoBind = isFunction && !isReactClassMethod && !isAlreadyDefined && spec.autobind !== false;
|
27932 |
|
27933 | if (shouldAutoBind) {
|
27934 | autoBindPairs.push(name, property);
|
27935 | proto[name] = property;
|
27936 | } else {
|
27937 | if (isAlreadyDefined) {
|
27938 | var specPolicy = ReactClassInterface[name];
|
27939 |
|
27940 | // These cases should already be caught by validateMethodOverride.
|
27941 | !(isReactClassMethod && (specPolicy === 'DEFINE_MANY_MERGED' || specPolicy === 'DEFINE_MANY')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.', specPolicy, name) : _prodInvariant('77', specPolicy, name) : void 0;
|
27942 |
|
27943 | // For methods which are defined more than once, call the existing
|
27944 | // methods before calling the new property, merging if appropriate.
|
27945 | if (specPolicy === 'DEFINE_MANY_MERGED') {
|
27946 | proto[name] = createMergedResultFunction(proto[name], property);
|
27947 | } else if (specPolicy === 'DEFINE_MANY') {
|
27948 | proto[name] = createChainedFunction(proto[name], property);
|
27949 | }
|
27950 | } else {
|
27951 | proto[name] = property;
|
27952 | if (process.env.NODE_ENV !== 'production') {
|
27953 | // Add verbose displayName to the function, which helps when looking
|
27954 | // at profiling tools.
|
27955 | if (typeof property === 'function' && spec.displayName) {
|
27956 | proto[name].displayName = spec.displayName + '_' + name;
|
27957 | }
|
27958 | }
|
27959 | }
|
27960 | }
|
27961 | }
|
27962 | }
|
27963 | }
|
27964 |
|
27965 | function mixStaticSpecIntoComponent(Constructor, statics) {
|
27966 | if (!statics) {
|
27967 | return;
|
27968 | }
|
27969 | for (var name in statics) {
|
27970 | var property = statics[name];
|
27971 | if (!statics.hasOwnProperty(name)) {
|
27972 | continue;
|
27973 | }
|
27974 |
|
27975 | var isReserved = name in RESERVED_SPEC_KEYS;
|
27976 | !!isReserved ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.', name) : _prodInvariant('78', name) : void 0;
|
27977 |
|
27978 | var isInherited = name in Constructor;
|
27979 | !!isInherited ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.', name) : _prodInvariant('79', name) : void 0;
|
27980 | Constructor[name] = property;
|
27981 | }
|
27982 | }
|
27983 |
|
27984 | /**
|
27985 | * Merge two objects, but throw if both contain the same key.
|
27986 | *
|
27987 | * @param {object} one The first object, which is mutated.
|
27988 | * @param {object} two The second object
|
27989 | * @return {object} one after it has been mutated to contain everything in two.
|
27990 | */
|
27991 | function mergeIntoWithNoDuplicateKeys(one, two) {
|
27992 | !(one && two && typeof one === 'object' && typeof two === 'object') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.') : _prodInvariant('80') : void 0;
|
27993 |
|
27994 | for (var key in two) {
|
27995 | if (two.hasOwnProperty(key)) {
|
27996 | !(one[key] === undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.', key) : _prodInvariant('81', key) : void 0;
|
27997 | one[key] = two[key];
|
27998 | }
|
27999 | }
|
28000 | return one;
|
28001 | }
|
28002 |
|
28003 | /**
|
28004 | * Creates a function that invokes two functions and merges their return values.
|
28005 | *
|
28006 | * @param {function} one Function to invoke first.
|
28007 | * @param {function} two Function to invoke second.
|
28008 | * @return {function} Function that invokes the two argument functions.
|
28009 | * @private
|
28010 | */
|
28011 | function createMergedResultFunction(one, two) {
|
28012 | return function mergedResult() {
|
28013 | var a = one.apply(this, arguments);
|
28014 | var b = two.apply(this, arguments);
|
28015 | if (a == null) {
|
28016 | return b;
|
28017 | } else if (b == null) {
|
28018 | return a;
|
28019 | }
|
28020 | var c = {};
|
28021 | mergeIntoWithNoDuplicateKeys(c, a);
|
28022 | mergeIntoWithNoDuplicateKeys(c, b);
|
28023 | return c;
|
28024 | };
|
28025 | }
|
28026 |
|
28027 | /**
|
28028 | * Creates a function that invokes two functions and ignores their return vales.
|
28029 | *
|
28030 | * @param {function} one Function to invoke first.
|
28031 | * @param {function} two Function to invoke second.
|
28032 | * @return {function} Function that invokes the two argument functions.
|
28033 | * @private
|
28034 | */
|
28035 | function createChainedFunction(one, two) {
|
28036 | return function chainedFunction() {
|
28037 | one.apply(this, arguments);
|
28038 | two.apply(this, arguments);
|
28039 | };
|
28040 | }
|
28041 |
|
28042 | /**
|
28043 | * Binds a method to the component.
|
28044 | *
|
28045 | * @param {object} component Component whose method is going to be bound.
|
28046 | * @param {function} method Method to be bound.
|
28047 | * @return {function} The bound method.
|
28048 | */
|
28049 | function bindAutoBindMethod(component, method) {
|
28050 | var boundMethod = method.bind(component);
|
28051 | if (process.env.NODE_ENV !== 'production') {
|
28052 | boundMethod.__reactBoundContext = component;
|
28053 | boundMethod.__reactBoundMethod = method;
|
28054 | boundMethod.__reactBoundArguments = null;
|
28055 | var componentName = component.constructor.displayName;
|
28056 | var _bind = boundMethod.bind;
|
28057 | boundMethod.bind = function (newThis) {
|
28058 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
28059 | args[_key - 1] = arguments[_key];
|
28060 | }
|
28061 |
|
28062 | // User is trying to bind() an autobound method; we effectively will
|
28063 | // ignore the value of "this" that the user is trying to use, so
|
28064 | // let's warn.
|
28065 | if (newThis !== component && newThis !== null) {
|
28066 | process.env.NODE_ENV !== 'production' ? warning(false, 'bind(): React component methods may only be bound to the ' + 'component instance. See %s', componentName) : void 0;
|
28067 | } else if (!args.length) {
|
28068 | process.env.NODE_ENV !== 'production' ? warning(false, 'bind(): You are binding a component method to the component. ' + 'React does this for you automatically in a high-performance ' + 'way, so you can safely remove this call. See %s', componentName) : void 0;
|
28069 | return boundMethod;
|
28070 | }
|
28071 | var reboundMethod = _bind.apply(boundMethod, arguments);
|
28072 | reboundMethod.__reactBoundContext = component;
|
28073 | reboundMethod.__reactBoundMethod = method;
|
28074 | reboundMethod.__reactBoundArguments = args;
|
28075 | return reboundMethod;
|
28076 | };
|
28077 | }
|
28078 | return boundMethod;
|
28079 | }
|
28080 |
|
28081 | /**
|
28082 | * Binds all auto-bound methods in a component.
|
28083 | *
|
28084 | * @param {object} component Component whose method is going to be bound.
|
28085 | */
|
28086 | function bindAutoBindMethods(component) {
|
28087 | var pairs = component.__reactAutoBindPairs;
|
28088 | for (var i = 0; i < pairs.length; i += 2) {
|
28089 | var autoBindKey = pairs[i];
|
28090 | var method = pairs[i + 1];
|
28091 | component[autoBindKey] = bindAutoBindMethod(component, method);
|
28092 | }
|
28093 | }
|
28094 |
|
28095 | /**
|
28096 | * Add more to the ReactClass base class. These are all legacy features and
|
28097 | * therefore not already part of the modern ReactComponent.
|
28098 | */
|
28099 | var ReactClassMixin = {
|
28100 |
|
28101 | /**
|
28102 | * TODO: This will be deprecated because state should always keep a consistent
|
28103 | * type signature and the only use case for this, is to avoid that.
|
28104 | */
|
28105 | replaceState: function (newState, callback) {
|
28106 | this.updater.enqueueReplaceState(this, newState);
|
28107 | if (callback) {
|
28108 | this.updater.enqueueCallback(this, callback, 'replaceState');
|
28109 | }
|
28110 | },
|
28111 |
|
28112 | /**
|
28113 | * Checks whether or not this composite component is mounted.
|
28114 | * @return {boolean} True if mounted, false otherwise.
|
28115 | * @protected
|
28116 | * @final
|
28117 | */
|
28118 | isMounted: function () {
|
28119 | return this.updater.isMounted(this);
|
28120 | }
|
28121 | };
|
28122 |
|
28123 | var ReactClassComponent = function () {};
|
28124 | _assign(ReactClassComponent.prototype, ReactComponent.prototype, ReactClassMixin);
|
28125 |
|
28126 | /**
|
28127 | * Module for creating composite components.
|
28128 | *
|
28129 | * @class ReactClass
|
28130 | */
|
28131 | var ReactClass = {
|
28132 |
|
28133 | /**
|
28134 | * Creates a composite component class given a class specification.
|
28135 | * See https://facebook.github.io/react/docs/top-level-api.html#react.createclass
|
28136 | *
|
28137 | * @param {object} spec Class specification (which must define `render`).
|
28138 | * @return {function} Component constructor function.
|
28139 | * @public
|
28140 | */
|
28141 | createClass: function (spec) {
|
28142 | // To keep our warnings more understandable, we'll use a little hack here to
|
28143 | // ensure that Constructor.name !== 'Constructor'. This makes sure we don't
|
28144 | // unnecessarily identify a class without displayName as 'Constructor'.
|
28145 | var Constructor = identity(function (props, context, updater) {
|
28146 | // This constructor gets overridden by mocks. The argument is used
|
28147 | // by mocks to assert on what gets mounted.
|
28148 |
|
28149 | if (process.env.NODE_ENV !== 'production') {
|
28150 | process.env.NODE_ENV !== 'production' ? warning(this instanceof Constructor, 'Something is calling a React component directly. Use a factory or ' + 'JSX instead. See: https://fb.me/react-legacyfactory') : void 0;
|
28151 | }
|
28152 |
|
28153 | // Wire up auto-binding
|
28154 | if (this.__reactAutoBindPairs.length) {
|
28155 | bindAutoBindMethods(this);
|
28156 | }
|
28157 |
|
28158 | this.props = props;
|
28159 | this.context = context;
|
28160 | this.refs = emptyObject;
|
28161 | this.updater = updater || ReactNoopUpdateQueue;
|
28162 |
|
28163 | this.state = null;
|
28164 |
|
28165 | // ReactClasses doesn't have constructors. Instead, they use the
|
28166 | // getInitialState and componentWillMount methods for initialization.
|
28167 |
|
28168 | var initialState = this.getInitialState ? this.getInitialState() : null;
|
28169 | if (process.env.NODE_ENV !== 'production') {
|
28170 | // We allow auto-mocks to proceed as if they're returning null.
|
28171 | if (initialState === undefined && this.getInitialState._isMockFunction) {
|
28172 | // This is probably bad practice. Consider warning here and
|
28173 | // deprecating this convenience.
|
28174 | initialState = null;
|
28175 | }
|
28176 | }
|
28177 | !(typeof initialState === 'object' && !Array.isArray(initialState)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getInitialState(): must return an object or null', Constructor.displayName || 'ReactCompositeComponent') : _prodInvariant('82', Constructor.displayName || 'ReactCompositeComponent') : void 0;
|
28178 |
|
28179 | this.state = initialState;
|
28180 | });
|
28181 | Constructor.prototype = new ReactClassComponent();
|
28182 | Constructor.prototype.constructor = Constructor;
|
28183 | Constructor.prototype.__reactAutoBindPairs = [];
|
28184 |
|
28185 | injectedMixins.forEach(mixSpecIntoComponent.bind(null, Constructor));
|
28186 |
|
28187 | mixSpecIntoComponent(Constructor, spec);
|
28188 |
|
28189 | // Initialize the defaultProps property after all mixins have been merged.
|
28190 | if (Constructor.getDefaultProps) {
|
28191 | Constructor.defaultProps = Constructor.getDefaultProps();
|
28192 | }
|
28193 |
|
28194 | if (process.env.NODE_ENV !== 'production') {
|
28195 | // This is a tag to indicate that the use of these method names is ok,
|
28196 | // since it's used with createClass. If it's not, then it's likely a
|
28197 | // mistake so we'll warn you to use the static property, property
|
28198 | // initializer or constructor respectively.
|
28199 | if (Constructor.getDefaultProps) {
|
28200 | Constructor.getDefaultProps.isReactClassApproved = {};
|
28201 | }
|
28202 | if (Constructor.prototype.getInitialState) {
|
28203 | Constructor.prototype.getInitialState.isReactClassApproved = {};
|
28204 | }
|
28205 | }
|
28206 |
|
28207 | !Constructor.prototype.render ? process.env.NODE_ENV !== 'production' ? invariant(false, 'createClass(...): Class specification must implement a `render` method.') : _prodInvariant('83') : void 0;
|
28208 |
|
28209 | if (process.env.NODE_ENV !== 'production') {
|
28210 | process.env.NODE_ENV !== 'production' ? warning(!Constructor.prototype.componentShouldUpdate, '%s has a method called ' + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' + 'The name is phrased as a question because the function is ' + 'expected to return a value.', spec.displayName || 'A component') : void 0;
|
28211 | process.env.NODE_ENV !== 'production' ? warning(!Constructor.prototype.componentWillRecieveProps, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', spec.displayName || 'A component') : void 0;
|
28212 | }
|
28213 |
|
28214 | // Reduce time spent doing lookups by setting these on the prototype.
|
28215 | for (var methodName in ReactClassInterface) {
|
28216 | if (!Constructor.prototype[methodName]) {
|
28217 | Constructor.prototype[methodName] = null;
|
28218 | }
|
28219 | }
|
28220 |
|
28221 | return Constructor;
|
28222 | },
|
28223 |
|
28224 | injection: {
|
28225 | injectMixin: function (mixin) {
|
28226 | injectedMixins.push(mixin);
|
28227 | }
|
28228 | }
|
28229 |
|
28230 | };
|
28231 |
|
28232 | module.exports = ReactClass;
|
28233 | }).call(this,require('_process'))
|
28234 | },{"./ReactComponent":290,"./ReactElement":294,"./ReactNoopUpdateQueue":297,"./ReactPropTypeLocationNames":298,"./reactProdInvariant":307,"_process":144,"fbjs/lib/emptyObject":117,"fbjs/lib/invariant":124,"fbjs/lib/warning":131,"object-assign":143}],290:[function(require,module,exports){
|
28235 | (function (process){
|
28236 | /**
|
28237 | * Copyright 2013-present, Facebook, Inc.
|
28238 | * All rights reserved.
|
28239 | *
|
28240 | * This source code is licensed under the BSD-style license found in the
|
28241 | * LICENSE file in the root directory of this source tree. An additional grant
|
28242 | * of patent rights can be found in the PATENTS file in the same directory.
|
28243 | *
|
28244 | */
|
28245 |
|
28246 | 'use strict';
|
28247 |
|
28248 | var _prodInvariant = require('./reactProdInvariant');
|
28249 |
|
28250 | var ReactNoopUpdateQueue = require('./ReactNoopUpdateQueue');
|
28251 |
|
28252 | var canDefineProperty = require('./canDefineProperty');
|
28253 | var emptyObject = require('fbjs/lib/emptyObject');
|
28254 | var invariant = require('fbjs/lib/invariant');
|
28255 | var warning = require('fbjs/lib/warning');
|
28256 |
|
28257 | /**
|
28258 | * Base class helpers for the updating state of a component.
|
28259 | */
|
28260 | function ReactComponent(props, context, updater) {
|
28261 | this.props = props;
|
28262 | this.context = context;
|
28263 | this.refs = emptyObject;
|
28264 | // We initialize the default updater but the real one gets injected by the
|
28265 | // renderer.
|
28266 | this.updater = updater || ReactNoopUpdateQueue;
|
28267 | }
|
28268 |
|
28269 | ReactComponent.prototype.isReactComponent = {};
|
28270 |
|
28271 | /**
|
28272 | * Sets a subset of the state. Always use this to mutate
|
28273 | * state. You should treat `this.state` as immutable.
|
28274 | *
|
28275 | * There is no guarantee that `this.state` will be immediately updated, so
|
28276 | * accessing `this.state` after calling this method may return the old value.
|
28277 | *
|
28278 | * There is no guarantee that calls to `setState` will run synchronously,
|
28279 | * as they may eventually be batched together. You can provide an optional
|
28280 | * callback that will be executed when the call to setState is actually
|
28281 | * completed.
|
28282 | *
|
28283 | * When a function is provided to setState, it will be called at some point in
|
28284 | * the future (not synchronously). It will be called with the up to date
|
28285 | * component arguments (state, props, context). These values can be different
|
28286 | * from this.* because your function may be called after receiveProps but before
|
28287 | * shouldComponentUpdate, and this new state, props, and context will not yet be
|
28288 | * assigned to this.
|
28289 | *
|
28290 | * @param {object|function} partialState Next partial state or function to
|
28291 | * produce next partial state to be merged with current state.
|
28292 | * @param {?function} callback Called after state is updated.
|
28293 | * @final
|
28294 | * @protected
|
28295 | */
|
28296 | ReactComponent.prototype.setState = function (partialState, callback) {
|
28297 | !(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'setState(...): takes an object of state variables to update or a function which returns an object of state variables.') : _prodInvariant('85') : void 0;
|
28298 | this.updater.enqueueSetState(this, partialState);
|
28299 | if (callback) {
|
28300 | this.updater.enqueueCallback(this, callback, 'setState');
|
28301 | }
|
28302 | };
|
28303 |
|
28304 | /**
|
28305 | * Forces an update. This should only be invoked when it is known with
|
28306 | * certainty that we are **not** in a DOM transaction.
|
28307 | *
|
28308 | * You may want to call this when you know that some deeper aspect of the
|
28309 | * component's state has changed but `setState` was not called.
|
28310 | *
|
28311 | * This will not invoke `shouldComponentUpdate`, but it will invoke
|
28312 | * `componentWillUpdate` and `componentDidUpdate`.
|
28313 | *
|
28314 | * @param {?function} callback Called after update is complete.
|
28315 | * @final
|
28316 | * @protected
|
28317 | */
|
28318 | ReactComponent.prototype.forceUpdate = function (callback) {
|
28319 | this.updater.enqueueForceUpdate(this);
|
28320 | if (callback) {
|
28321 | this.updater.enqueueCallback(this, callback, 'forceUpdate');
|
28322 | }
|
28323 | };
|
28324 |
|
28325 | /**
|
28326 | * Deprecated APIs. These APIs used to exist on classic React classes but since
|
28327 | * we would like to deprecate them, we're not going to move them over to this
|
28328 | * modern base class. Instead, we define a getter that warns if it's accessed.
|
28329 | */
|
28330 | if (process.env.NODE_ENV !== 'production') {
|
28331 | var deprecatedAPIs = {
|
28332 | isMounted: ['isMounted', 'Instead, make sure to clean up subscriptions and pending requests in ' + 'componentWillUnmount to prevent memory leaks.'],
|
28333 | replaceState: ['replaceState', 'Refactor your code to use setState instead (see ' + 'https://github.com/facebook/react/issues/3236).']
|
28334 | };
|
28335 | var defineDeprecationWarning = function (methodName, info) {
|
28336 | if (canDefineProperty) {
|
28337 | Object.defineProperty(ReactComponent.prototype, methodName, {
|
28338 | get: function () {
|
28339 | process.env.NODE_ENV !== 'production' ? warning(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]) : void 0;
|
28340 | return undefined;
|
28341 | }
|
28342 | });
|
28343 | }
|
28344 | };
|
28345 | for (var fnName in deprecatedAPIs) {
|
28346 | if (deprecatedAPIs.hasOwnProperty(fnName)) {
|
28347 | defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
|
28348 | }
|
28349 | }
|
28350 | }
|
28351 |
|
28352 | module.exports = ReactComponent;
|
28353 | }).call(this,require('_process'))
|
28354 | },{"./ReactNoopUpdateQueue":297,"./canDefineProperty":303,"./reactProdInvariant":307,"_process":144,"fbjs/lib/emptyObject":117,"fbjs/lib/invariant":124,"fbjs/lib/warning":131}],291:[function(require,module,exports){
|
28355 | (function (process){
|
28356 | /**
|
28357 | * Copyright 2016-present, Facebook, Inc.
|
28358 | * All rights reserved.
|
28359 | *
|
28360 | * This source code is licensed under the BSD-style license found in the
|
28361 | * LICENSE file in the root directory of this source tree. An additional grant
|
28362 | * of patent rights can be found in the PATENTS file in the same directory.
|
28363 | *
|
28364 | *
|
28365 | */
|
28366 |
|
28367 | 'use strict';
|
28368 |
|
28369 | var _prodInvariant = require('./reactProdInvariant');
|
28370 |
|
28371 | var ReactCurrentOwner = require('./ReactCurrentOwner');
|
28372 |
|
28373 | var invariant = require('fbjs/lib/invariant');
|
28374 | var warning = require('fbjs/lib/warning');
|
28375 |
|
28376 | function isNative(fn) {
|
28377 | // Based on isNative() from Lodash
|
28378 | var funcToString = Function.prototype.toString;
|
28379 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
28380 | var reIsNative = RegExp('^' + funcToString
|
28381 | // Take an example native function source for comparison
|
28382 | .call(hasOwnProperty)
|
28383 | // Strip regex characters so we can use it for regex
|
28384 | .replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
|
28385 | // Remove hasOwnProperty from the template to make it generic
|
28386 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
|
28387 | try {
|
28388 | var source = funcToString.call(fn);
|
28389 | return reIsNative.test(source);
|
28390 | } catch (err) {
|
28391 | return false;
|
28392 | }
|
28393 | }
|
28394 |
|
28395 | var canUseCollections =
|
28396 | // Array.from
|
28397 | typeof Array.from === 'function' &&
|
28398 | // Map
|
28399 | typeof Map === 'function' && isNative(Map) &&
|
28400 | // Map.prototype.keys
|
28401 | Map.prototype != null && typeof Map.prototype.keys === 'function' && isNative(Map.prototype.keys) &&
|
28402 | // Set
|
28403 | typeof Set === 'function' && isNative(Set) &&
|
28404 | // Set.prototype.keys
|
28405 | Set.prototype != null && typeof Set.prototype.keys === 'function' && isNative(Set.prototype.keys);
|
28406 |
|
28407 | var setItem;
|
28408 | var getItem;
|
28409 | var removeItem;
|
28410 | var getItemIDs;
|
28411 | var addRoot;
|
28412 | var removeRoot;
|
28413 | var getRootIDs;
|
28414 |
|
28415 | if (canUseCollections) {
|
28416 | var itemMap = new Map();
|
28417 | var rootIDSet = new Set();
|
28418 |
|
28419 | setItem = function (id, item) {
|
28420 | itemMap.set(id, item);
|
28421 | };
|
28422 | getItem = function (id) {
|
28423 | return itemMap.get(id);
|
28424 | };
|
28425 | removeItem = function (id) {
|
28426 | itemMap['delete'](id);
|
28427 | };
|
28428 | getItemIDs = function () {
|
28429 | return Array.from(itemMap.keys());
|
28430 | };
|
28431 |
|
28432 | addRoot = function (id) {
|
28433 | rootIDSet.add(id);
|
28434 | };
|
28435 | removeRoot = function (id) {
|
28436 | rootIDSet['delete'](id);
|
28437 | };
|
28438 | getRootIDs = function () {
|
28439 | return Array.from(rootIDSet.keys());
|
28440 | };
|
28441 | } else {
|
28442 | var itemByKey = {};
|
28443 | var rootByKey = {};
|
28444 |
|
28445 | // Use non-numeric keys to prevent V8 performance issues:
|
28446 | // https://github.com/facebook/react/pull/7232
|
28447 | var getKeyFromID = function (id) {
|
28448 | return '.' + id;
|
28449 | };
|
28450 | var getIDFromKey = function (key) {
|
28451 | return parseInt(key.substr(1), 10);
|
28452 | };
|
28453 |
|
28454 | setItem = function (id, item) {
|
28455 | var key = getKeyFromID(id);
|
28456 | itemByKey[key] = item;
|
28457 | };
|
28458 | getItem = function (id) {
|
28459 | var key = getKeyFromID(id);
|
28460 | return itemByKey[key];
|
28461 | };
|
28462 | removeItem = function (id) {
|
28463 | var key = getKeyFromID(id);
|
28464 | delete itemByKey[key];
|
28465 | };
|
28466 | getItemIDs = function () {
|
28467 | return Object.keys(itemByKey).map(getIDFromKey);
|
28468 | };
|
28469 |
|
28470 | addRoot = function (id) {
|
28471 | var key = getKeyFromID(id);
|
28472 | rootByKey[key] = true;
|
28473 | };
|
28474 | removeRoot = function (id) {
|
28475 | var key = getKeyFromID(id);
|
28476 | delete rootByKey[key];
|
28477 | };
|
28478 | getRootIDs = function () {
|
28479 | return Object.keys(rootByKey).map(getIDFromKey);
|
28480 | };
|
28481 | }
|
28482 |
|
28483 | var unmountedIDs = [];
|
28484 |
|
28485 | function purgeDeep(id) {
|
28486 | var item = getItem(id);
|
28487 | if (item) {
|
28488 | var childIDs = item.childIDs;
|
28489 |
|
28490 | removeItem(id);
|
28491 | childIDs.forEach(purgeDeep);
|
28492 | }
|
28493 | }
|
28494 |
|
28495 | function describeComponentFrame(name, source, ownerName) {
|
28496 | return '\n in ' + (name || 'Unknown') + (source ? ' (at ' + source.fileName.replace(/^.*[\\\/]/, '') + ':' + source.lineNumber + ')' : ownerName ? ' (created by ' + ownerName + ')' : '');
|
28497 | }
|
28498 |
|
28499 | function getDisplayName(element) {
|
28500 | if (element == null) {
|
28501 | return '#empty';
|
28502 | } else if (typeof element === 'string' || typeof element === 'number') {
|
28503 | return '#text';
|
28504 | } else if (typeof element.type === 'string') {
|
28505 | return element.type;
|
28506 | } else {
|
28507 | return element.type.displayName || element.type.name || 'Unknown';
|
28508 | }
|
28509 | }
|
28510 |
|
28511 | function describeID(id) {
|
28512 | var name = ReactComponentTreeHook.getDisplayName(id);
|
28513 | var element = ReactComponentTreeHook.getElement(id);
|
28514 | var ownerID = ReactComponentTreeHook.getOwnerID(id);
|
28515 | var ownerName;
|
28516 | if (ownerID) {
|
28517 | ownerName = ReactComponentTreeHook.getDisplayName(ownerID);
|
28518 | }
|
28519 | process.env.NODE_ENV !== 'production' ? warning(element, 'ReactComponentTreeHook: Missing React element for debugID %s when ' + 'building stack', id) : void 0;
|
28520 | return describeComponentFrame(name, element && element._source, ownerName);
|
28521 | }
|
28522 |
|
28523 | var ReactComponentTreeHook = {
|
28524 | onSetChildren: function (id, nextChildIDs) {
|
28525 | var item = getItem(id);
|
28526 | !item ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Item must have been set') : _prodInvariant('144') : void 0;
|
28527 | item.childIDs = nextChildIDs;
|
28528 |
|
28529 | for (var i = 0; i < nextChildIDs.length; i++) {
|
28530 | var nextChildID = nextChildIDs[i];
|
28531 | var nextChild = getItem(nextChildID);
|
28532 | !nextChild ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Expected hook events to fire for the child before its parent includes it in onSetChildren().') : _prodInvariant('140') : void 0;
|
28533 | !(nextChild.childIDs != null || typeof nextChild.element !== 'object' || nextChild.element == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Expected onSetChildren() to fire for a container child before its parent includes it in onSetChildren().') : _prodInvariant('141') : void 0;
|
28534 | !nextChild.isMounted ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Expected onMountComponent() to fire for the child before its parent includes it in onSetChildren().') : _prodInvariant('71') : void 0;
|
28535 | if (nextChild.parentID == null) {
|
28536 | nextChild.parentID = id;
|
28537 | // TODO: This shouldn't be necessary but mounting a new root during in
|
28538 | // componentWillMount currently causes not-yet-mounted components to
|
28539 | // be purged from our tree data so their parent id is missing.
|
28540 | }
|
28541 | !(nextChild.parentID === id) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (%s has parents %s and %s).', nextChildID, nextChild.parentID, id) : _prodInvariant('142', nextChildID, nextChild.parentID, id) : void 0;
|
28542 | }
|
28543 | },
|
28544 | onBeforeMountComponent: function (id, element, parentID) {
|
28545 | var item = {
|
28546 | element: element,
|
28547 | parentID: parentID,
|
28548 | text: null,
|
28549 | childIDs: [],
|
28550 | isMounted: false,
|
28551 | updateCount: 0
|
28552 | };
|
28553 | setItem(id, item);
|
28554 | },
|
28555 | onBeforeUpdateComponent: function (id, element) {
|
28556 | var item = getItem(id);
|
28557 | if (!item || !item.isMounted) {
|
28558 | // We may end up here as a result of setState() in componentWillUnmount().
|
28559 | // In this case, ignore the element.
|
28560 | return;
|
28561 | }
|
28562 | item.element = element;
|
28563 | },
|
28564 | onMountComponent: function (id) {
|
28565 | var item = getItem(id);
|
28566 | !item ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Item must have been set') : _prodInvariant('144') : void 0;
|
28567 | item.isMounted = true;
|
28568 | var isRoot = item.parentID === 0;
|
28569 | if (isRoot) {
|
28570 | addRoot(id);
|
28571 | }
|
28572 | },
|
28573 | onUpdateComponent: function (id) {
|
28574 | var item = getItem(id);
|
28575 | if (!item || !item.isMounted) {
|
28576 | // We may end up here as a result of setState() in componentWillUnmount().
|
28577 | // In this case, ignore the element.
|
28578 | return;
|
28579 | }
|
28580 | item.updateCount++;
|
28581 | },
|
28582 | onUnmountComponent: function (id) {
|
28583 | var item = getItem(id);
|
28584 | if (item) {
|
28585 | // We need to check if it exists.
|
28586 | // `item` might not exist if it is inside an error boundary, and a sibling
|
28587 | // error boundary child threw while mounting. Then this instance never
|
28588 | // got a chance to mount, but it still gets an unmounting event during
|
28589 | // the error boundary cleanup.
|
28590 | item.isMounted = false;
|
28591 | var isRoot = item.parentID === 0;
|
28592 | if (isRoot) {
|
28593 | removeRoot(id);
|
28594 | }
|
28595 | }
|
28596 | unmountedIDs.push(id);
|
28597 | },
|
28598 | purgeUnmountedComponents: function () {
|
28599 | if (ReactComponentTreeHook._preventPurging) {
|
28600 | // Should only be used for testing.
|
28601 | return;
|
28602 | }
|
28603 |
|
28604 | for (var i = 0; i < unmountedIDs.length; i++) {
|
28605 | var id = unmountedIDs[i];
|
28606 | purgeDeep(id);
|
28607 | }
|
28608 | unmountedIDs.length = 0;
|
28609 | },
|
28610 | isMounted: function (id) {
|
28611 | var item = getItem(id);
|
28612 | return item ? item.isMounted : false;
|
28613 | },
|
28614 | getCurrentStackAddendum: function (topElement) {
|
28615 | var info = '';
|
28616 | if (topElement) {
|
28617 | var name = getDisplayName(topElement);
|
28618 | var owner = topElement._owner;
|
28619 | info += describeComponentFrame(name, topElement._source, owner && owner.getName());
|
28620 | }
|
28621 |
|
28622 | var currentOwner = ReactCurrentOwner.current;
|
28623 | var id = currentOwner && currentOwner._debugID;
|
28624 |
|
28625 | info += ReactComponentTreeHook.getStackAddendumByID(id);
|
28626 | return info;
|
28627 | },
|
28628 | getStackAddendumByID: function (id) {
|
28629 | var info = '';
|
28630 | while (id) {
|
28631 | info += describeID(id);
|
28632 | id = ReactComponentTreeHook.getParentID(id);
|
28633 | }
|
28634 | return info;
|
28635 | },
|
28636 | getChildIDs: function (id) {
|
28637 | var item = getItem(id);
|
28638 | return item ? item.childIDs : [];
|
28639 | },
|
28640 | getDisplayName: function (id) {
|
28641 | var element = ReactComponentTreeHook.getElement(id);
|
28642 | if (!element) {
|
28643 | return null;
|
28644 | }
|
28645 | return getDisplayName(element);
|
28646 | },
|
28647 | getElement: function (id) {
|
28648 | var item = getItem(id);
|
28649 | return item ? item.element : null;
|
28650 | },
|
28651 | getOwnerID: function (id) {
|
28652 | var element = ReactComponentTreeHook.getElement(id);
|
28653 | if (!element || !element._owner) {
|
28654 | return null;
|
28655 | }
|
28656 | return element._owner._debugID;
|
28657 | },
|
28658 | getParentID: function (id) {
|
28659 | var item = getItem(id);
|
28660 | return item ? item.parentID : null;
|
28661 | },
|
28662 | getSource: function (id) {
|
28663 | var item = getItem(id);
|
28664 | var element = item ? item.element : null;
|
28665 | var source = element != null ? element._source : null;
|
28666 | return source;
|
28667 | },
|
28668 | getText: function (id) {
|
28669 | var element = ReactComponentTreeHook.getElement(id);
|
28670 | if (typeof element === 'string') {
|
28671 | return element;
|
28672 | } else if (typeof element === 'number') {
|
28673 | return '' + element;
|
28674 | } else {
|
28675 | return null;
|
28676 | }
|
28677 | },
|
28678 | getUpdateCount: function (id) {
|
28679 | var item = getItem(id);
|
28680 | return item ? item.updateCount : 0;
|
28681 | },
|
28682 |
|
28683 |
|
28684 | getRootIDs: getRootIDs,
|
28685 | getRegisteredIDs: getItemIDs
|
28686 | };
|
28687 |
|
28688 | module.exports = ReactComponentTreeHook;
|
28689 | }).call(this,require('_process'))
|
28690 | },{"./ReactCurrentOwner":292,"./reactProdInvariant":307,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131}],292:[function(require,module,exports){
|
28691 | /**
|
28692 | * Copyright 2013-present, Facebook, Inc.
|
28693 | * All rights reserved.
|
28694 | *
|
28695 | * This source code is licensed under the BSD-style license found in the
|
28696 | * LICENSE file in the root directory of this source tree. An additional grant
|
28697 | * of patent rights can be found in the PATENTS file in the same directory.
|
28698 | *
|
28699 | *
|
28700 | */
|
28701 |
|
28702 | 'use strict';
|
28703 |
|
28704 | /**
|
28705 | * Keeps track of the current owner.
|
28706 | *
|
28707 | * The current owner is the component who should own any components that are
|
28708 | * currently being constructed.
|
28709 | */
|
28710 | var ReactCurrentOwner = {
|
28711 |
|
28712 | /**
|
28713 | * @internal
|
28714 | * @type {ReactComponent}
|
28715 | */
|
28716 | current: null
|
28717 |
|
28718 | };
|
28719 |
|
28720 | module.exports = ReactCurrentOwner;
|
28721 | },{}],293:[function(require,module,exports){
|
28722 | (function (process){
|
28723 | /**
|
28724 | * Copyright 2013-present, Facebook, Inc.
|
28725 | * All rights reserved.
|
28726 | *
|
28727 | * This source code is licensed under the BSD-style license found in the
|
28728 | * LICENSE file in the root directory of this source tree. An additional grant
|
28729 | * of patent rights can be found in the PATENTS file in the same directory.
|
28730 | *
|
28731 | */
|
28732 |
|
28733 | 'use strict';
|
28734 |
|
28735 | var ReactElement = require('./ReactElement');
|
28736 |
|
28737 | /**
|
28738 | * Create a factory that creates HTML tag elements.
|
28739 | *
|
28740 | * @private
|
28741 | */
|
28742 | var createDOMFactory = ReactElement.createFactory;
|
28743 | if (process.env.NODE_ENV !== 'production') {
|
28744 | var ReactElementValidator = require('./ReactElementValidator');
|
28745 | createDOMFactory = ReactElementValidator.createFactory;
|
28746 | }
|
28747 |
|
28748 | /**
|
28749 | * Creates a mapping from supported HTML tags to `ReactDOMComponent` classes.
|
28750 | * This is also accessible via `React.DOM`.
|
28751 | *
|
28752 | * @public
|
28753 | */
|
28754 | var ReactDOMFactories = {
|
28755 | a: createDOMFactory('a'),
|
28756 | abbr: createDOMFactory('abbr'),
|
28757 | address: createDOMFactory('address'),
|
28758 | area: createDOMFactory('area'),
|
28759 | article: createDOMFactory('article'),
|
28760 | aside: createDOMFactory('aside'),
|
28761 | audio: createDOMFactory('audio'),
|
28762 | b: createDOMFactory('b'),
|
28763 | base: createDOMFactory('base'),
|
28764 | bdi: createDOMFactory('bdi'),
|
28765 | bdo: createDOMFactory('bdo'),
|
28766 | big: createDOMFactory('big'),
|
28767 | blockquote: createDOMFactory('blockquote'),
|
28768 | body: createDOMFactory('body'),
|
28769 | br: createDOMFactory('br'),
|
28770 | button: createDOMFactory('button'),
|
28771 | canvas: createDOMFactory('canvas'),
|
28772 | caption: createDOMFactory('caption'),
|
28773 | cite: createDOMFactory('cite'),
|
28774 | code: createDOMFactory('code'),
|
28775 | col: createDOMFactory('col'),
|
28776 | colgroup: createDOMFactory('colgroup'),
|
28777 | data: createDOMFactory('data'),
|
28778 | datalist: createDOMFactory('datalist'),
|
28779 | dd: createDOMFactory('dd'),
|
28780 | del: createDOMFactory('del'),
|
28781 | details: createDOMFactory('details'),
|
28782 | dfn: createDOMFactory('dfn'),
|
28783 | dialog: createDOMFactory('dialog'),
|
28784 | div: createDOMFactory('div'),
|
28785 | dl: createDOMFactory('dl'),
|
28786 | dt: createDOMFactory('dt'),
|
28787 | em: createDOMFactory('em'),
|
28788 | embed: createDOMFactory('embed'),
|
28789 | fieldset: createDOMFactory('fieldset'),
|
28790 | figcaption: createDOMFactory('figcaption'),
|
28791 | figure: createDOMFactory('figure'),
|
28792 | footer: createDOMFactory('footer'),
|
28793 | form: createDOMFactory('form'),
|
28794 | h1: createDOMFactory('h1'),
|
28795 | h2: createDOMFactory('h2'),
|
28796 | h3: createDOMFactory('h3'),
|
28797 | h4: createDOMFactory('h4'),
|
28798 | h5: createDOMFactory('h5'),
|
28799 | h6: createDOMFactory('h6'),
|
28800 | head: createDOMFactory('head'),
|
28801 | header: createDOMFactory('header'),
|
28802 | hgroup: createDOMFactory('hgroup'),
|
28803 | hr: createDOMFactory('hr'),
|
28804 | html: createDOMFactory('html'),
|
28805 | i: createDOMFactory('i'),
|
28806 | iframe: createDOMFactory('iframe'),
|
28807 | img: createDOMFactory('img'),
|
28808 | input: createDOMFactory('input'),
|
28809 | ins: createDOMFactory('ins'),
|
28810 | kbd: createDOMFactory('kbd'),
|
28811 | keygen: createDOMFactory('keygen'),
|
28812 | label: createDOMFactory('label'),
|
28813 | legend: createDOMFactory('legend'),
|
28814 | li: createDOMFactory('li'),
|
28815 | link: createDOMFactory('link'),
|
28816 | main: createDOMFactory('main'),
|
28817 | map: createDOMFactory('map'),
|
28818 | mark: createDOMFactory('mark'),
|
28819 | menu: createDOMFactory('menu'),
|
28820 | menuitem: createDOMFactory('menuitem'),
|
28821 | meta: createDOMFactory('meta'),
|
28822 | meter: createDOMFactory('meter'),
|
28823 | nav: createDOMFactory('nav'),
|
28824 | noscript: createDOMFactory('noscript'),
|
28825 | object: createDOMFactory('object'),
|
28826 | ol: createDOMFactory('ol'),
|
28827 | optgroup: createDOMFactory('optgroup'),
|
28828 | option: createDOMFactory('option'),
|
28829 | output: createDOMFactory('output'),
|
28830 | p: createDOMFactory('p'),
|
28831 | param: createDOMFactory('param'),
|
28832 | picture: createDOMFactory('picture'),
|
28833 | pre: createDOMFactory('pre'),
|
28834 | progress: createDOMFactory('progress'),
|
28835 | q: createDOMFactory('q'),
|
28836 | rp: createDOMFactory('rp'),
|
28837 | rt: createDOMFactory('rt'),
|
28838 | ruby: createDOMFactory('ruby'),
|
28839 | s: createDOMFactory('s'),
|
28840 | samp: createDOMFactory('samp'),
|
28841 | script: createDOMFactory('script'),
|
28842 | section: createDOMFactory('section'),
|
28843 | select: createDOMFactory('select'),
|
28844 | small: createDOMFactory('small'),
|
28845 | source: createDOMFactory('source'),
|
28846 | span: createDOMFactory('span'),
|
28847 | strong: createDOMFactory('strong'),
|
28848 | style: createDOMFactory('style'),
|
28849 | sub: createDOMFactory('sub'),
|
28850 | summary: createDOMFactory('summary'),
|
28851 | sup: createDOMFactory('sup'),
|
28852 | table: createDOMFactory('table'),
|
28853 | tbody: createDOMFactory('tbody'),
|
28854 | td: createDOMFactory('td'),
|
28855 | textarea: createDOMFactory('textarea'),
|
28856 | tfoot: createDOMFactory('tfoot'),
|
28857 | th: createDOMFactory('th'),
|
28858 | thead: createDOMFactory('thead'),
|
28859 | time: createDOMFactory('time'),
|
28860 | title: createDOMFactory('title'),
|
28861 | tr: createDOMFactory('tr'),
|
28862 | track: createDOMFactory('track'),
|
28863 | u: createDOMFactory('u'),
|
28864 | ul: createDOMFactory('ul'),
|
28865 | 'var': createDOMFactory('var'),
|
28866 | video: createDOMFactory('video'),
|
28867 | wbr: createDOMFactory('wbr'),
|
28868 |
|
28869 | // SVG
|
28870 | circle: createDOMFactory('circle'),
|
28871 | clipPath: createDOMFactory('clipPath'),
|
28872 | defs: createDOMFactory('defs'),
|
28873 | ellipse: createDOMFactory('ellipse'),
|
28874 | g: createDOMFactory('g'),
|
28875 | image: createDOMFactory('image'),
|
28876 | line: createDOMFactory('line'),
|
28877 | linearGradient: createDOMFactory('linearGradient'),
|
28878 | mask: createDOMFactory('mask'),
|
28879 | path: createDOMFactory('path'),
|
28880 | pattern: createDOMFactory('pattern'),
|
28881 | polygon: createDOMFactory('polygon'),
|
28882 | polyline: createDOMFactory('polyline'),
|
28883 | radialGradient: createDOMFactory('radialGradient'),
|
28884 | rect: createDOMFactory('rect'),
|
28885 | stop: createDOMFactory('stop'),
|
28886 | svg: createDOMFactory('svg'),
|
28887 | text: createDOMFactory('text'),
|
28888 | tspan: createDOMFactory('tspan')
|
28889 | };
|
28890 |
|
28891 | module.exports = ReactDOMFactories;
|
28892 | }).call(this,require('_process'))
|
28893 | },{"./ReactElement":294,"./ReactElementValidator":296,"_process":144}],294:[function(require,module,exports){
|
28894 | (function (process){
|
28895 | /**
|
28896 | * Copyright 2014-present, Facebook, Inc.
|
28897 | * All rights reserved.
|
28898 | *
|
28899 | * This source code is licensed under the BSD-style license found in the
|
28900 | * LICENSE file in the root directory of this source tree. An additional grant
|
28901 | * of patent rights can be found in the PATENTS file in the same directory.
|
28902 | *
|
28903 | */
|
28904 |
|
28905 | 'use strict';
|
28906 |
|
28907 | var _assign = require('object-assign');
|
28908 |
|
28909 | var ReactCurrentOwner = require('./ReactCurrentOwner');
|
28910 |
|
28911 | var warning = require('fbjs/lib/warning');
|
28912 | var canDefineProperty = require('./canDefineProperty');
|
28913 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
28914 |
|
28915 | var REACT_ELEMENT_TYPE = require('./ReactElementSymbol');
|
28916 |
|
28917 | var RESERVED_PROPS = {
|
28918 | key: true,
|
28919 | ref: true,
|
28920 | __self: true,
|
28921 | __source: true
|
28922 | };
|
28923 |
|
28924 | var specialPropKeyWarningShown, specialPropRefWarningShown;
|
28925 |
|
28926 | function hasValidRef(config) {
|
28927 | if (process.env.NODE_ENV !== 'production') {
|
28928 | if (hasOwnProperty.call(config, 'ref')) {
|
28929 | var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
|
28930 | if (getter && getter.isReactWarning) {
|
28931 | return false;
|
28932 | }
|
28933 | }
|
28934 | }
|
28935 | return config.ref !== undefined;
|
28936 | }
|
28937 |
|
28938 | function hasValidKey(config) {
|
28939 | if (process.env.NODE_ENV !== 'production') {
|
28940 | if (hasOwnProperty.call(config, 'key')) {
|
28941 | var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
|
28942 | if (getter && getter.isReactWarning) {
|
28943 | return false;
|
28944 | }
|
28945 | }
|
28946 | }
|
28947 | return config.key !== undefined;
|
28948 | }
|
28949 |
|
28950 | function defineKeyPropWarningGetter(props, displayName) {
|
28951 | var warnAboutAccessingKey = function () {
|
28952 | if (!specialPropKeyWarningShown) {
|
28953 | specialPropKeyWarningShown = true;
|
28954 | process.env.NODE_ENV !== 'production' ? warning(false, '%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', displayName) : void 0;
|
28955 | }
|
28956 | };
|
28957 | warnAboutAccessingKey.isReactWarning = true;
|
28958 | Object.defineProperty(props, 'key', {
|
28959 | get: warnAboutAccessingKey,
|
28960 | configurable: true
|
28961 | });
|
28962 | }
|
28963 |
|
28964 | function defineRefPropWarningGetter(props, displayName) {
|
28965 | var warnAboutAccessingRef = function () {
|
28966 | if (!specialPropRefWarningShown) {
|
28967 | specialPropRefWarningShown = true;
|
28968 | process.env.NODE_ENV !== 'production' ? warning(false, '%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', displayName) : void 0;
|
28969 | }
|
28970 | };
|
28971 | warnAboutAccessingRef.isReactWarning = true;
|
28972 | Object.defineProperty(props, 'ref', {
|
28973 | get: warnAboutAccessingRef,
|
28974 | configurable: true
|
28975 | });
|
28976 | }
|
28977 |
|
28978 | /**
|
28979 | * Factory method to create a new React element. This no longer adheres to
|
28980 | * the class pattern, so do not use new to call it. Also, no instanceof check
|
28981 | * will work. Instead test $$typeof field against Symbol.for('react.element') to check
|
28982 | * if something is a React Element.
|
28983 | *
|
28984 | * @param {*} type
|
28985 | * @param {*} key
|
28986 | * @param {string|object} ref
|
28987 | * @param {*} self A *temporary* helper to detect places where `this` is
|
28988 | * different from the `owner` when React.createElement is called, so that we
|
28989 | * can warn. We want to get rid of owner and replace string `ref`s with arrow
|
28990 | * functions, and as long as `this` and owner are the same, there will be no
|
28991 | * change in behavior.
|
28992 | * @param {*} source An annotation object (added by a transpiler or otherwise)
|
28993 | * indicating filename, line number, and/or other information.
|
28994 | * @param {*} owner
|
28995 | * @param {*} props
|
28996 | * @internal
|
28997 | */
|
28998 | var ReactElement = function (type, key, ref, self, source, owner, props) {
|
28999 | var element = {
|
29000 | // This tag allow us to uniquely identify this as a React Element
|
29001 | $$typeof: REACT_ELEMENT_TYPE,
|
29002 |
|
29003 | // Built-in properties that belong on the element
|
29004 | type: type,
|
29005 | key: key,
|
29006 | ref: ref,
|
29007 | props: props,
|
29008 |
|
29009 | // Record the component responsible for creating this element.
|
29010 | _owner: owner
|
29011 | };
|
29012 |
|
29013 | if (process.env.NODE_ENV !== 'production') {
|
29014 | // The validation flag is currently mutative. We put it on
|
29015 | // an external backing store so that we can freeze the whole object.
|
29016 | // This can be replaced with a WeakMap once they are implemented in
|
29017 | // commonly used development environments.
|
29018 | element._store = {};
|
29019 |
|
29020 | // To make comparing ReactElements easier for testing purposes, we make
|
29021 | // the validation flag non-enumerable (where possible, which should
|
29022 | // include every environment we run tests in), so the test framework
|
29023 | // ignores it.
|
29024 | if (canDefineProperty) {
|
29025 | Object.defineProperty(element._store, 'validated', {
|
29026 | configurable: false,
|
29027 | enumerable: false,
|
29028 | writable: true,
|
29029 | value: false
|
29030 | });
|
29031 | // self and source are DEV only properties.
|
29032 | Object.defineProperty(element, '_self', {
|
29033 | configurable: false,
|
29034 | enumerable: false,
|
29035 | writable: false,
|
29036 | value: self
|
29037 | });
|
29038 | // Two elements created in two different places should be considered
|
29039 | // equal for testing purposes and therefore we hide it from enumeration.
|
29040 | Object.defineProperty(element, '_source', {
|
29041 | configurable: false,
|
29042 | enumerable: false,
|
29043 | writable: false,
|
29044 | value: source
|
29045 | });
|
29046 | } else {
|
29047 | element._store.validated = false;
|
29048 | element._self = self;
|
29049 | element._source = source;
|
29050 | }
|
29051 | if (Object.freeze) {
|
29052 | Object.freeze(element.props);
|
29053 | Object.freeze(element);
|
29054 | }
|
29055 | }
|
29056 |
|
29057 | return element;
|
29058 | };
|
29059 |
|
29060 | /**
|
29061 | * Create and return a new ReactElement of the given type.
|
29062 | * See https://facebook.github.io/react/docs/top-level-api.html#react.createelement
|
29063 | */
|
29064 | ReactElement.createElement = function (type, config, children) {
|
29065 | var propName;
|
29066 |
|
29067 | // Reserved names are extracted
|
29068 | var props = {};
|
29069 |
|
29070 | var key = null;
|
29071 | var ref = null;
|
29072 | var self = null;
|
29073 | var source = null;
|
29074 |
|
29075 | if (config != null) {
|
29076 | if (hasValidRef(config)) {
|
29077 | ref = config.ref;
|
29078 | }
|
29079 | if (hasValidKey(config)) {
|
29080 | key = '' + config.key;
|
29081 | }
|
29082 |
|
29083 | self = config.__self === undefined ? null : config.__self;
|
29084 | source = config.__source === undefined ? null : config.__source;
|
29085 | // Remaining properties are added to a new props object
|
29086 | for (propName in config) {
|
29087 | if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
29088 | props[propName] = config[propName];
|
29089 | }
|
29090 | }
|
29091 | }
|
29092 |
|
29093 | // Children can be more than one argument, and those are transferred onto
|
29094 | // the newly allocated props object.
|
29095 | var childrenLength = arguments.length - 2;
|
29096 | if (childrenLength === 1) {
|
29097 | props.children = children;
|
29098 | } else if (childrenLength > 1) {
|
29099 | var childArray = Array(childrenLength);
|
29100 | for (var i = 0; i < childrenLength; i++) {
|
29101 | childArray[i] = arguments[i + 2];
|
29102 | }
|
29103 | if (process.env.NODE_ENV !== 'production') {
|
29104 | if (Object.freeze) {
|
29105 | Object.freeze(childArray);
|
29106 | }
|
29107 | }
|
29108 | props.children = childArray;
|
29109 | }
|
29110 |
|
29111 | // Resolve default props
|
29112 | if (type && type.defaultProps) {
|
29113 | var defaultProps = type.defaultProps;
|
29114 | for (propName in defaultProps) {
|
29115 | if (props[propName] === undefined) {
|
29116 | props[propName] = defaultProps[propName];
|
29117 | }
|
29118 | }
|
29119 | }
|
29120 | if (process.env.NODE_ENV !== 'production') {
|
29121 | if (key || ref) {
|
29122 | if (typeof props.$$typeof === 'undefined' || props.$$typeof !== REACT_ELEMENT_TYPE) {
|
29123 | var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
|
29124 | if (key) {
|
29125 | defineKeyPropWarningGetter(props, displayName);
|
29126 | }
|
29127 | if (ref) {
|
29128 | defineRefPropWarningGetter(props, displayName);
|
29129 | }
|
29130 | }
|
29131 | }
|
29132 | }
|
29133 | return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
|
29134 | };
|
29135 |
|
29136 | /**
|
29137 | * Return a function that produces ReactElements of a given type.
|
29138 | * See https://facebook.github.io/react/docs/top-level-api.html#react.createfactory
|
29139 | */
|
29140 | ReactElement.createFactory = function (type) {
|
29141 | var factory = ReactElement.createElement.bind(null, type);
|
29142 | // Expose the type on the factory and the prototype so that it can be
|
29143 | // easily accessed on elements. E.g. `<Foo />.type === Foo`.
|
29144 | // This should not be named `constructor` since this may not be the function
|
29145 | // that created the element, and it may not even be a constructor.
|
29146 | // Legacy hook TODO: Warn if this is accessed
|
29147 | factory.type = type;
|
29148 | return factory;
|
29149 | };
|
29150 |
|
29151 | ReactElement.cloneAndReplaceKey = function (oldElement, newKey) {
|
29152 | var newElement = ReactElement(oldElement.type, newKey, oldElement.ref, oldElement._self, oldElement._source, oldElement._owner, oldElement.props);
|
29153 |
|
29154 | return newElement;
|
29155 | };
|
29156 |
|
29157 | /**
|
29158 | * Clone and return a new ReactElement using element as the starting point.
|
29159 | * See https://facebook.github.io/react/docs/top-level-api.html#react.cloneelement
|
29160 | */
|
29161 | ReactElement.cloneElement = function (element, config, children) {
|
29162 | var propName;
|
29163 |
|
29164 | // Original props are copied
|
29165 | var props = _assign({}, element.props);
|
29166 |
|
29167 | // Reserved names are extracted
|
29168 | var key = element.key;
|
29169 | var ref = element.ref;
|
29170 | // Self is preserved since the owner is preserved.
|
29171 | var self = element._self;
|
29172 | // Source is preserved since cloneElement is unlikely to be targeted by a
|
29173 | // transpiler, and the original source is probably a better indicator of the
|
29174 | // true owner.
|
29175 | var source = element._source;
|
29176 |
|
29177 | // Owner will be preserved, unless ref is overridden
|
29178 | var owner = element._owner;
|
29179 |
|
29180 | if (config != null) {
|
29181 | if (hasValidRef(config)) {
|
29182 | // Silently steal the ref from the parent.
|
29183 | ref = config.ref;
|
29184 | owner = ReactCurrentOwner.current;
|
29185 | }
|
29186 | if (hasValidKey(config)) {
|
29187 | key = '' + config.key;
|
29188 | }
|
29189 |
|
29190 | // Remaining properties override existing props
|
29191 | var defaultProps;
|
29192 | if (element.type && element.type.defaultProps) {
|
29193 | defaultProps = element.type.defaultProps;
|
29194 | }
|
29195 | for (propName in config) {
|
29196 | if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
29197 | if (config[propName] === undefined && defaultProps !== undefined) {
|
29198 | // Resolve default props
|
29199 | props[propName] = defaultProps[propName];
|
29200 | } else {
|
29201 | props[propName] = config[propName];
|
29202 | }
|
29203 | }
|
29204 | }
|
29205 | }
|
29206 |
|
29207 | // Children can be more than one argument, and those are transferred onto
|
29208 | // the newly allocated props object.
|
29209 | var childrenLength = arguments.length - 2;
|
29210 | if (childrenLength === 1) {
|
29211 | props.children = children;
|
29212 | } else if (childrenLength > 1) {
|
29213 | var childArray = Array(childrenLength);
|
29214 | for (var i = 0; i < childrenLength; i++) {
|
29215 | childArray[i] = arguments[i + 2];
|
29216 | }
|
29217 | props.children = childArray;
|
29218 | }
|
29219 |
|
29220 | return ReactElement(element.type, key, ref, self, source, owner, props);
|
29221 | };
|
29222 |
|
29223 | /**
|
29224 | * Verifies the object is a ReactElement.
|
29225 | * See https://facebook.github.io/react/docs/top-level-api.html#react.isvalidelement
|
29226 | * @param {?object} object
|
29227 | * @return {boolean} True if `object` is a valid component.
|
29228 | * @final
|
29229 | */
|
29230 | ReactElement.isValidElement = function (object) {
|
29231 | return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
29232 | };
|
29233 |
|
29234 | module.exports = ReactElement;
|
29235 | }).call(this,require('_process'))
|
29236 | },{"./ReactCurrentOwner":292,"./ReactElementSymbol":295,"./canDefineProperty":303,"_process":144,"fbjs/lib/warning":131,"object-assign":143}],295:[function(require,module,exports){
|
29237 | arguments[4][205][0].apply(exports,arguments)
|
29238 | },{"dup":205}],296:[function(require,module,exports){
|
29239 | (function (process){
|
29240 | /**
|
29241 | * Copyright 2014-present, Facebook, Inc.
|
29242 | * All rights reserved.
|
29243 | *
|
29244 | * This source code is licensed under the BSD-style license found in the
|
29245 | * LICENSE file in the root directory of this source tree. An additional grant
|
29246 | * of patent rights can be found in the PATENTS file in the same directory.
|
29247 | *
|
29248 | */
|
29249 |
|
29250 | /**
|
29251 | * ReactElementValidator provides a wrapper around a element factory
|
29252 | * which validates the props passed to the element. This is intended to be
|
29253 | * used only in DEV and could be replaced by a static type checker for languages
|
29254 | * that support it.
|
29255 | */
|
29256 |
|
29257 | 'use strict';
|
29258 |
|
29259 | var ReactCurrentOwner = require('./ReactCurrentOwner');
|
29260 | var ReactComponentTreeHook = require('./ReactComponentTreeHook');
|
29261 | var ReactElement = require('./ReactElement');
|
29262 |
|
29263 | var checkReactTypeSpec = require('./checkReactTypeSpec');
|
29264 |
|
29265 | var canDefineProperty = require('./canDefineProperty');
|
29266 | var getIteratorFn = require('./getIteratorFn');
|
29267 | var warning = require('fbjs/lib/warning');
|
29268 |
|
29269 | function getDeclarationErrorAddendum() {
|
29270 | if (ReactCurrentOwner.current) {
|
29271 | var name = ReactCurrentOwner.current.getName();
|
29272 | if (name) {
|
29273 | return ' Check the render method of `' + name + '`.';
|
29274 | }
|
29275 | }
|
29276 | return '';
|
29277 | }
|
29278 |
|
29279 | /**
|
29280 | * Warn if there's no key explicitly set on dynamic arrays of children or
|
29281 | * object keys are not valid. This allows us to keep track of children between
|
29282 | * updates.
|
29283 | */
|
29284 | var ownerHasKeyUseWarning = {};
|
29285 |
|
29286 | function getCurrentComponentErrorInfo(parentType) {
|
29287 | var info = getDeclarationErrorAddendum();
|
29288 |
|
29289 | if (!info) {
|
29290 | var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
|
29291 | if (parentName) {
|
29292 | info = ' Check the top-level render call using <' + parentName + '>.';
|
29293 | }
|
29294 | }
|
29295 | return info;
|
29296 | }
|
29297 |
|
29298 | /**
|
29299 | * Warn if the element doesn't have an explicit key assigned to it.
|
29300 | * This element is in an array. The array could grow and shrink or be
|
29301 | * reordered. All children that haven't already been validated are required to
|
29302 | * have a "key" property assigned to it. Error statuses are cached so a warning
|
29303 | * will only be shown once.
|
29304 | *
|
29305 | * @internal
|
29306 | * @param {ReactElement} element Element that requires a key.
|
29307 | * @param {*} parentType element's parent's type.
|
29308 | */
|
29309 | function validateExplicitKey(element, parentType) {
|
29310 | if (!element._store || element._store.validated || element.key != null) {
|
29311 | return;
|
29312 | }
|
29313 | element._store.validated = true;
|
29314 |
|
29315 | var memoizer = ownerHasKeyUseWarning.uniqueKey || (ownerHasKeyUseWarning.uniqueKey = {});
|
29316 |
|
29317 | var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
|
29318 | if (memoizer[currentComponentErrorInfo]) {
|
29319 | return;
|
29320 | }
|
29321 | memoizer[currentComponentErrorInfo] = true;
|
29322 |
|
29323 | // Usually the current owner is the offender, but if it accepts children as a
|
29324 | // property, it may be the creator of the child that's responsible for
|
29325 | // assigning it a key.
|
29326 | var childOwner = '';
|
29327 | if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
|
29328 | // Give the component that originally created this child.
|
29329 | childOwner = ' It was passed a child from ' + element._owner.getName() + '.';
|
29330 | }
|
29331 |
|
29332 | process.env.NODE_ENV !== 'production' ? warning(false, 'Each child in an array or iterator should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.%s', currentComponentErrorInfo, childOwner, ReactComponentTreeHook.getCurrentStackAddendum(element)) : void 0;
|
29333 | }
|
29334 |
|
29335 | /**
|
29336 | * Ensure that every element either is passed in a static location, in an
|
29337 | * array with an explicit keys property defined, or in an object literal
|
29338 | * with valid key property.
|
29339 | *
|
29340 | * @internal
|
29341 | * @param {ReactNode} node Statically passed child of any type.
|
29342 | * @param {*} parentType node's parent's type.
|
29343 | */
|
29344 | function validateChildKeys(node, parentType) {
|
29345 | if (typeof node !== 'object') {
|
29346 | return;
|
29347 | }
|
29348 | if (Array.isArray(node)) {
|
29349 | for (var i = 0; i < node.length; i++) {
|
29350 | var child = node[i];
|
29351 | if (ReactElement.isValidElement(child)) {
|
29352 | validateExplicitKey(child, parentType);
|
29353 | }
|
29354 | }
|
29355 | } else if (ReactElement.isValidElement(node)) {
|
29356 | // This element was passed in a valid location.
|
29357 | if (node._store) {
|
29358 | node._store.validated = true;
|
29359 | }
|
29360 | } else if (node) {
|
29361 | var iteratorFn = getIteratorFn(node);
|
29362 | // Entry iterators provide implicit keys.
|
29363 | if (iteratorFn) {
|
29364 | if (iteratorFn !== node.entries) {
|
29365 | var iterator = iteratorFn.call(node);
|
29366 | var step;
|
29367 | while (!(step = iterator.next()).done) {
|
29368 | if (ReactElement.isValidElement(step.value)) {
|
29369 | validateExplicitKey(step.value, parentType);
|
29370 | }
|
29371 | }
|
29372 | }
|
29373 | }
|
29374 | }
|
29375 | }
|
29376 |
|
29377 | /**
|
29378 | * Given an element, validate that its props follow the propTypes definition,
|
29379 | * provided by the type.
|
29380 | *
|
29381 | * @param {ReactElement} element
|
29382 | */
|
29383 | function validatePropTypes(element) {
|
29384 | var componentClass = element.type;
|
29385 | if (typeof componentClass !== 'function') {
|
29386 | return;
|
29387 | }
|
29388 | var name = componentClass.displayName || componentClass.name;
|
29389 | if (componentClass.propTypes) {
|
29390 | checkReactTypeSpec(componentClass.propTypes, element.props, 'prop', name, element, null);
|
29391 | }
|
29392 | if (typeof componentClass.getDefaultProps === 'function') {
|
29393 | process.env.NODE_ENV !== 'production' ? warning(componentClass.getDefaultProps.isReactClassApproved, 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.') : void 0;
|
29394 | }
|
29395 | }
|
29396 |
|
29397 | var ReactElementValidator = {
|
29398 |
|
29399 | createElement: function (type, props, children) {
|
29400 | var validType = typeof type === 'string' || typeof type === 'function';
|
29401 | // We warn in this case but don't throw. We expect the element creation to
|
29402 | // succeed and there will likely be errors in render.
|
29403 | if (!validType) {
|
29404 | process.env.NODE_ENV !== 'production' ? warning(false, 'React.createElement: type should not be null, undefined, boolean, or ' + 'number. It should be a string (for DOM elements) or a ReactClass ' + '(for composite components).%s', getDeclarationErrorAddendum()) : void 0;
|
29405 | }
|
29406 |
|
29407 | var element = ReactElement.createElement.apply(this, arguments);
|
29408 |
|
29409 | // The result can be nullish if a mock or a custom function is used.
|
29410 | // TODO: Drop this when these are no longer allowed as the type argument.
|
29411 | if (element == null) {
|
29412 | return element;
|
29413 | }
|
29414 |
|
29415 | // Skip key warning if the type isn't valid since our key validation logic
|
29416 | // doesn't expect a non-string/function type and can throw confusing errors.
|
29417 | // We don't want exception behavior to differ between dev and prod.
|
29418 | // (Rendering will throw with a helpful message and as soon as the type is
|
29419 | // fixed, the key warnings will appear.)
|
29420 | if (validType) {
|
29421 | for (var i = 2; i < arguments.length; i++) {
|
29422 | validateChildKeys(arguments[i], type);
|
29423 | }
|
29424 | }
|
29425 |
|
29426 | validatePropTypes(element);
|
29427 |
|
29428 | return element;
|
29429 | },
|
29430 |
|
29431 | createFactory: function (type) {
|
29432 | var validatedFactory = ReactElementValidator.createElement.bind(null, type);
|
29433 | // Legacy hook TODO: Warn if this is accessed
|
29434 | validatedFactory.type = type;
|
29435 |
|
29436 | if (process.env.NODE_ENV !== 'production') {
|
29437 | if (canDefineProperty) {
|
29438 | Object.defineProperty(validatedFactory, 'type', {
|
29439 | enumerable: false,
|
29440 | get: function () {
|
29441 | process.env.NODE_ENV !== 'production' ? warning(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.') : void 0;
|
29442 | Object.defineProperty(this, 'type', {
|
29443 | value: type
|
29444 | });
|
29445 | return type;
|
29446 | }
|
29447 | });
|
29448 | }
|
29449 | }
|
29450 |
|
29451 | return validatedFactory;
|
29452 | },
|
29453 |
|
29454 | cloneElement: function (element, props, children) {
|
29455 | var newElement = ReactElement.cloneElement.apply(this, arguments);
|
29456 | for (var i = 2; i < arguments.length; i++) {
|
29457 | validateChildKeys(arguments[i], newElement.type);
|
29458 | }
|
29459 | validatePropTypes(newElement);
|
29460 | return newElement;
|
29461 | }
|
29462 |
|
29463 | };
|
29464 |
|
29465 | module.exports = ReactElementValidator;
|
29466 | }).call(this,require('_process'))
|
29467 | },{"./ReactComponentTreeHook":291,"./ReactCurrentOwner":292,"./ReactElement":294,"./canDefineProperty":303,"./checkReactTypeSpec":304,"./getIteratorFn":305,"_process":144,"fbjs/lib/warning":131}],297:[function(require,module,exports){
|
29468 | (function (process){
|
29469 | /**
|
29470 | * Copyright 2015-present, Facebook, Inc.
|
29471 | * All rights reserved.
|
29472 | *
|
29473 | * This source code is licensed under the BSD-style license found in the
|
29474 | * LICENSE file in the root directory of this source tree. An additional grant
|
29475 | * of patent rights can be found in the PATENTS file in the same directory.
|
29476 | *
|
29477 | */
|
29478 |
|
29479 | 'use strict';
|
29480 |
|
29481 | var warning = require('fbjs/lib/warning');
|
29482 |
|
29483 | function warnNoop(publicInstance, callerName) {
|
29484 | if (process.env.NODE_ENV !== 'production') {
|
29485 | var constructor = publicInstance.constructor;
|
29486 | process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op. Please check the code for the %s component.', callerName, callerName, constructor && (constructor.displayName || constructor.name) || 'ReactClass') : void 0;
|
29487 | }
|
29488 | }
|
29489 |
|
29490 | /**
|
29491 | * This is the abstract API for an update queue.
|
29492 | */
|
29493 | var ReactNoopUpdateQueue = {
|
29494 |
|
29495 | /**
|
29496 | * Checks whether or not this composite component is mounted.
|
29497 | * @param {ReactClass} publicInstance The instance we want to test.
|
29498 | * @return {boolean} True if mounted, false otherwise.
|
29499 | * @protected
|
29500 | * @final
|
29501 | */
|
29502 | isMounted: function (publicInstance) {
|
29503 | return false;
|
29504 | },
|
29505 |
|
29506 | /**
|
29507 | * Enqueue a callback that will be executed after all the pending updates
|
29508 | * have processed.
|
29509 | *
|
29510 | * @param {ReactClass} publicInstance The instance to use as `this` context.
|
29511 | * @param {?function} callback Called after state is updated.
|
29512 | * @internal
|
29513 | */
|
29514 | enqueueCallback: function (publicInstance, callback) {},
|
29515 |
|
29516 | /**
|
29517 | * Forces an update. This should only be invoked when it is known with
|
29518 | * certainty that we are **not** in a DOM transaction.
|
29519 | *
|
29520 | * You may want to call this when you know that some deeper aspect of the
|
29521 | * component's state has changed but `setState` was not called.
|
29522 | *
|
29523 | * This will not invoke `shouldComponentUpdate`, but it will invoke
|
29524 | * `componentWillUpdate` and `componentDidUpdate`.
|
29525 | *
|
29526 | * @param {ReactClass} publicInstance The instance that should rerender.
|
29527 | * @internal
|
29528 | */
|
29529 | enqueueForceUpdate: function (publicInstance) {
|
29530 | warnNoop(publicInstance, 'forceUpdate');
|
29531 | },
|
29532 |
|
29533 | /**
|
29534 | * Replaces all of the state. Always use this or `setState` to mutate state.
|
29535 | * You should treat `this.state` as immutable.
|
29536 | *
|
29537 | * There is no guarantee that `this.state` will be immediately updated, so
|
29538 | * accessing `this.state` after calling this method may return the old value.
|
29539 | *
|
29540 | * @param {ReactClass} publicInstance The instance that should rerender.
|
29541 | * @param {object} completeState Next state.
|
29542 | * @internal
|
29543 | */
|
29544 | enqueueReplaceState: function (publicInstance, completeState) {
|
29545 | warnNoop(publicInstance, 'replaceState');
|
29546 | },
|
29547 |
|
29548 | /**
|
29549 | * Sets a subset of the state. This only exists because _pendingState is
|
29550 | * internal. This provides a merging strategy that is not available to deep
|
29551 | * properties which is confusing. TODO: Expose pendingState or don't use it
|
29552 | * during the merge.
|
29553 | *
|
29554 | * @param {ReactClass} publicInstance The instance that should rerender.
|
29555 | * @param {object} partialState Next partial state to be merged with state.
|
29556 | * @internal
|
29557 | */
|
29558 | enqueueSetState: function (publicInstance, partialState) {
|
29559 | warnNoop(publicInstance, 'setState');
|
29560 | }
|
29561 | };
|
29562 |
|
29563 | module.exports = ReactNoopUpdateQueue;
|
29564 | }).call(this,require('_process'))
|
29565 | },{"_process":144,"fbjs/lib/warning":131}],298:[function(require,module,exports){
|
29566 | arguments[4][223][0].apply(exports,arguments)
|
29567 | },{"_process":144,"dup":223}],299:[function(require,module,exports){
|
29568 | (function (process){
|
29569 | /**
|
29570 | * Copyright 2013-present, Facebook, Inc.
|
29571 | * All rights reserved.
|
29572 | *
|
29573 | * This source code is licensed under the BSD-style license found in the
|
29574 | * LICENSE file in the root directory of this source tree. An additional grant
|
29575 | * of patent rights can be found in the PATENTS file in the same directory.
|
29576 | *
|
29577 | */
|
29578 |
|
29579 | 'use strict';
|
29580 |
|
29581 | var ReactElement = require('./ReactElement');
|
29582 | var ReactPropTypeLocationNames = require('./ReactPropTypeLocationNames');
|
29583 | var ReactPropTypesSecret = require('./ReactPropTypesSecret');
|
29584 |
|
29585 | var emptyFunction = require('fbjs/lib/emptyFunction');
|
29586 | var getIteratorFn = require('./getIteratorFn');
|
29587 | var warning = require('fbjs/lib/warning');
|
29588 |
|
29589 | /**
|
29590 | * Collection of methods that allow declaration and validation of props that are
|
29591 | * supplied to React components. Example usage:
|
29592 | *
|
29593 | * var Props = require('ReactPropTypes');
|
29594 | * var MyArticle = React.createClass({
|
29595 | * propTypes: {
|
29596 | * // An optional string prop named "description".
|
29597 | * description: Props.string,
|
29598 | *
|
29599 | * // A required enum prop named "category".
|
29600 | * category: Props.oneOf(['News','Photos']).isRequired,
|
29601 | *
|
29602 | * // A prop named "dialog" that requires an instance of Dialog.
|
29603 | * dialog: Props.instanceOf(Dialog).isRequired
|
29604 | * },
|
29605 | * render: function() { ... }
|
29606 | * });
|
29607 | *
|
29608 | * A more formal specification of how these methods are used:
|
29609 | *
|
29610 | * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
|
29611 | * decl := ReactPropTypes.{type}(.isRequired)?
|
29612 | *
|
29613 | * Each and every declaration produces a function with the same signature. This
|
29614 | * allows the creation of custom validation functions. For example:
|
29615 | *
|
29616 | * var MyLink = React.createClass({
|
29617 | * propTypes: {
|
29618 | * // An optional string or URI prop named "href".
|
29619 | * href: function(props, propName, componentName) {
|
29620 | * var propValue = props[propName];
|
29621 | * if (propValue != null && typeof propValue !== 'string' &&
|
29622 | * !(propValue instanceof URI)) {
|
29623 | * return new Error(
|
29624 | * 'Expected a string or an URI for ' + propName + ' in ' +
|
29625 | * componentName
|
29626 | * );
|
29627 | * }
|
29628 | * }
|
29629 | * },
|
29630 | * render: function() {...}
|
29631 | * });
|
29632 | *
|
29633 | * @internal
|
29634 | */
|
29635 |
|
29636 | var ANONYMOUS = '<<anonymous>>';
|
29637 |
|
29638 | var ReactPropTypes = {
|
29639 | array: createPrimitiveTypeChecker('array'),
|
29640 | bool: createPrimitiveTypeChecker('boolean'),
|
29641 | func: createPrimitiveTypeChecker('function'),
|
29642 | number: createPrimitiveTypeChecker('number'),
|
29643 | object: createPrimitiveTypeChecker('object'),
|
29644 | string: createPrimitiveTypeChecker('string'),
|
29645 | symbol: createPrimitiveTypeChecker('symbol'),
|
29646 |
|
29647 | any: createAnyTypeChecker(),
|
29648 | arrayOf: createArrayOfTypeChecker,
|
29649 | element: createElementTypeChecker(),
|
29650 | instanceOf: createInstanceTypeChecker,
|
29651 | node: createNodeChecker(),
|
29652 | objectOf: createObjectOfTypeChecker,
|
29653 | oneOf: createEnumTypeChecker,
|
29654 | oneOfType: createUnionTypeChecker,
|
29655 | shape: createShapeTypeChecker
|
29656 | };
|
29657 |
|
29658 | /**
|
29659 | * inlined Object.is polyfill to avoid requiring consumers ship their own
|
29660 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
29661 | */
|
29662 | /*eslint-disable no-self-compare*/
|
29663 | function is(x, y) {
|
29664 | // SameValue algorithm
|
29665 | if (x === y) {
|
29666 | // Steps 1-5, 7-10
|
29667 | // Steps 6.b-6.e: +0 != -0
|
29668 | return x !== 0 || 1 / x === 1 / y;
|
29669 | } else {
|
29670 | // Step 6.a: NaN == NaN
|
29671 | return x !== x && y !== y;
|
29672 | }
|
29673 | }
|
29674 | /*eslint-enable no-self-compare*/
|
29675 |
|
29676 | /**
|
29677 | * We use an Error-like object for backward compatibility as people may call
|
29678 | * PropTypes directly and inspect their output. However we don't use real
|
29679 | * Errors anymore. We don't inspect their stack anyway, and creating them
|
29680 | * is prohibitively expensive if they are created too often, such as what
|
29681 | * happens in oneOfType() for any type before the one that matched.
|
29682 | */
|
29683 | function PropTypeError(message) {
|
29684 | this.message = message;
|
29685 | this.stack = '';
|
29686 | }
|
29687 | // Make `instanceof Error` still work for returned errors.
|
29688 | PropTypeError.prototype = Error.prototype;
|
29689 |
|
29690 | function createChainableTypeChecker(validate) {
|
29691 | if (process.env.NODE_ENV !== 'production') {
|
29692 | var manualPropTypeCallCache = {};
|
29693 | }
|
29694 | function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
29695 | componentName = componentName || ANONYMOUS;
|
29696 | propFullName = propFullName || propName;
|
29697 | if (process.env.NODE_ENV !== 'production') {
|
29698 | if (secret !== ReactPropTypesSecret && typeof console !== 'undefined') {
|
29699 | var cacheKey = componentName + ':' + propName;
|
29700 | if (!manualPropTypeCallCache[cacheKey]) {
|
29701 | process.env.NODE_ENV !== 'production' ? warning(false, 'You are manually calling a React.PropTypes validation ' + 'function for the `%s` prop on `%s`. This is deprecated ' + 'and will not work in production with the next major version. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', propFullName, componentName) : void 0;
|
29702 | manualPropTypeCallCache[cacheKey] = true;
|
29703 | }
|
29704 | }
|
29705 | }
|
29706 | if (props[propName] == null) {
|
29707 | var locationName = ReactPropTypeLocationNames[location];
|
29708 | if (isRequired) {
|
29709 | if (props[propName] === null) {
|
29710 | return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
29711 | }
|
29712 | return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
29713 | }
|
29714 | return null;
|
29715 | } else {
|
29716 | return validate(props, propName, componentName, location, propFullName);
|
29717 | }
|
29718 | }
|
29719 |
|
29720 | var chainedCheckType = checkType.bind(null, false);
|
29721 | chainedCheckType.isRequired = checkType.bind(null, true);
|
29722 |
|
29723 | return chainedCheckType;
|
29724 | }
|
29725 |
|
29726 | function createPrimitiveTypeChecker(expectedType) {
|
29727 | function validate(props, propName, componentName, location, propFullName, secret) {
|
29728 | var propValue = props[propName];
|
29729 | var propType = getPropType(propValue);
|
29730 | if (propType !== expectedType) {
|
29731 | var locationName = ReactPropTypeLocationNames[location];
|
29732 | // `propValue` being instance of, say, date/regexp, pass the 'object'
|
29733 | // check, but we can offer a more precise error message here rather than
|
29734 | // 'of type `object`'.
|
29735 | var preciseType = getPreciseType(propValue);
|
29736 |
|
29737 | return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
|
29738 | }
|
29739 | return null;
|
29740 | }
|
29741 | return createChainableTypeChecker(validate);
|
29742 | }
|
29743 |
|
29744 | function createAnyTypeChecker() {
|
29745 | return createChainableTypeChecker(emptyFunction.thatReturns(null));
|
29746 | }
|
29747 |
|
29748 | function createArrayOfTypeChecker(typeChecker) {
|
29749 | function validate(props, propName, componentName, location, propFullName) {
|
29750 | if (typeof typeChecker !== 'function') {
|
29751 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
29752 | }
|
29753 | var propValue = props[propName];
|
29754 | if (!Array.isArray(propValue)) {
|
29755 | var locationName = ReactPropTypeLocationNames[location];
|
29756 | var propType = getPropType(propValue);
|
29757 | return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
29758 | }
|
29759 | for (var i = 0; i < propValue.length; i++) {
|
29760 | var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
|
29761 | if (error instanceof Error) {
|
29762 | return error;
|
29763 | }
|
29764 | }
|
29765 | return null;
|
29766 | }
|
29767 | return createChainableTypeChecker(validate);
|
29768 | }
|
29769 |
|
29770 | function createElementTypeChecker() {
|
29771 | function validate(props, propName, componentName, location, propFullName) {
|
29772 | var propValue = props[propName];
|
29773 | if (!ReactElement.isValidElement(propValue)) {
|
29774 | var locationName = ReactPropTypeLocationNames[location];
|
29775 | var propType = getPropType(propValue);
|
29776 | return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
29777 | }
|
29778 | return null;
|
29779 | }
|
29780 | return createChainableTypeChecker(validate);
|
29781 | }
|
29782 |
|
29783 | function createInstanceTypeChecker(expectedClass) {
|
29784 | function validate(props, propName, componentName, location, propFullName) {
|
29785 | if (!(props[propName] instanceof expectedClass)) {
|
29786 | var locationName = ReactPropTypeLocationNames[location];
|
29787 | var expectedClassName = expectedClass.name || ANONYMOUS;
|
29788 | var actualClassName = getClassName(props[propName]);
|
29789 | return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
29790 | }
|
29791 | return null;
|
29792 | }
|
29793 | return createChainableTypeChecker(validate);
|
29794 | }
|
29795 |
|
29796 | function createEnumTypeChecker(expectedValues) {
|
29797 | if (!Array.isArray(expectedValues)) {
|
29798 | process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
|
29799 | return emptyFunction.thatReturnsNull;
|
29800 | }
|
29801 |
|
29802 | function validate(props, propName, componentName, location, propFullName) {
|
29803 | var propValue = props[propName];
|
29804 | for (var i = 0; i < expectedValues.length; i++) {
|
29805 | if (is(propValue, expectedValues[i])) {
|
29806 | return null;
|
29807 | }
|
29808 | }
|
29809 |
|
29810 | var locationName = ReactPropTypeLocationNames[location];
|
29811 | var valuesString = JSON.stringify(expectedValues);
|
29812 | return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
29813 | }
|
29814 | return createChainableTypeChecker(validate);
|
29815 | }
|
29816 |
|
29817 | function createObjectOfTypeChecker(typeChecker) {
|
29818 | function validate(props, propName, componentName, location, propFullName) {
|
29819 | if (typeof typeChecker !== 'function') {
|
29820 | return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
29821 | }
|
29822 | var propValue = props[propName];
|
29823 | var propType = getPropType(propValue);
|
29824 | if (propType !== 'object') {
|
29825 | var locationName = ReactPropTypeLocationNames[location];
|
29826 | return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
29827 | }
|
29828 | for (var key in propValue) {
|
29829 | if (propValue.hasOwnProperty(key)) {
|
29830 | var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
29831 | if (error instanceof Error) {
|
29832 | return error;
|
29833 | }
|
29834 | }
|
29835 | }
|
29836 | return null;
|
29837 | }
|
29838 | return createChainableTypeChecker(validate);
|
29839 | }
|
29840 |
|
29841 | function createUnionTypeChecker(arrayOfTypeCheckers) {
|
29842 | if (!Array.isArray(arrayOfTypeCheckers)) {
|
29843 | process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
|
29844 | return emptyFunction.thatReturnsNull;
|
29845 | }
|
29846 |
|
29847 | function validate(props, propName, componentName, location, propFullName) {
|
29848 | for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
29849 | var checker = arrayOfTypeCheckers[i];
|
29850 | if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) {
|
29851 | return null;
|
29852 | }
|
29853 | }
|
29854 |
|
29855 | var locationName = ReactPropTypeLocationNames[location];
|
29856 | return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
29857 | }
|
29858 | return createChainableTypeChecker(validate);
|
29859 | }
|
29860 |
|
29861 | function createNodeChecker() {
|
29862 | function validate(props, propName, componentName, location, propFullName) {
|
29863 | if (!isNode(props[propName])) {
|
29864 | var locationName = ReactPropTypeLocationNames[location];
|
29865 | return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
29866 | }
|
29867 | return null;
|
29868 | }
|
29869 | return createChainableTypeChecker(validate);
|
29870 | }
|
29871 |
|
29872 | function createShapeTypeChecker(shapeTypes) {
|
29873 | function validate(props, propName, componentName, location, propFullName) {
|
29874 | var propValue = props[propName];
|
29875 | var propType = getPropType(propValue);
|
29876 | if (propType !== 'object') {
|
29877 | var locationName = ReactPropTypeLocationNames[location];
|
29878 | return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
29879 | }
|
29880 | for (var key in shapeTypes) {
|
29881 | var checker = shapeTypes[key];
|
29882 | if (!checker) {
|
29883 | continue;
|
29884 | }
|
29885 | var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
29886 | if (error) {
|
29887 | return error;
|
29888 | }
|
29889 | }
|
29890 | return null;
|
29891 | }
|
29892 | return createChainableTypeChecker(validate);
|
29893 | }
|
29894 |
|
29895 | function isNode(propValue) {
|
29896 | switch (typeof propValue) {
|
29897 | case 'number':
|
29898 | case 'string':
|
29899 | case 'undefined':
|
29900 | return true;
|
29901 | case 'boolean':
|
29902 | return !propValue;
|
29903 | case 'object':
|
29904 | if (Array.isArray(propValue)) {
|
29905 | return propValue.every(isNode);
|
29906 | }
|
29907 | if (propValue === null || ReactElement.isValidElement(propValue)) {
|
29908 | return true;
|
29909 | }
|
29910 |
|
29911 | var iteratorFn = getIteratorFn(propValue);
|
29912 | if (iteratorFn) {
|
29913 | var iterator = iteratorFn.call(propValue);
|
29914 | var step;
|
29915 | if (iteratorFn !== propValue.entries) {
|
29916 | while (!(step = iterator.next()).done) {
|
29917 | if (!isNode(step.value)) {
|
29918 | return false;
|
29919 | }
|
29920 | }
|
29921 | } else {
|
29922 | // Iterator will provide entry [k,v] tuples rather than values.
|
29923 | while (!(step = iterator.next()).done) {
|
29924 | var entry = step.value;
|
29925 | if (entry) {
|
29926 | if (!isNode(entry[1])) {
|
29927 | return false;
|
29928 | }
|
29929 | }
|
29930 | }
|
29931 | }
|
29932 | } else {
|
29933 | return false;
|
29934 | }
|
29935 |
|
29936 | return true;
|
29937 | default:
|
29938 | return false;
|
29939 | }
|
29940 | }
|
29941 |
|
29942 | function isSymbol(propType, propValue) {
|
29943 | // Native Symbol.
|
29944 | if (propType === 'symbol') {
|
29945 | return true;
|
29946 | }
|
29947 |
|
29948 | // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
29949 | if (propValue['@@toStringTag'] === 'Symbol') {
|
29950 | return true;
|
29951 | }
|
29952 |
|
29953 | // Fallback for non-spec compliant Symbols which are polyfilled.
|
29954 | if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
29955 | return true;
|
29956 | }
|
29957 |
|
29958 | return false;
|
29959 | }
|
29960 |
|
29961 | // Equivalent of `typeof` but with special handling for array and regexp.
|
29962 | function getPropType(propValue) {
|
29963 | var propType = typeof propValue;
|
29964 | if (Array.isArray(propValue)) {
|
29965 | return 'array';
|
29966 | }
|
29967 | if (propValue instanceof RegExp) {
|
29968 | // Old webkits (at least until Android 4.0) return 'function' rather than
|
29969 | // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
29970 | // passes PropTypes.object.
|
29971 | return 'object';
|
29972 | }
|
29973 | if (isSymbol(propType, propValue)) {
|
29974 | return 'symbol';
|
29975 | }
|
29976 | return propType;
|
29977 | }
|
29978 |
|
29979 | // This handles more types than `getPropType`. Only used for error messages.
|
29980 | // See `createPrimitiveTypeChecker`.
|
29981 | function getPreciseType(propValue) {
|
29982 | var propType = getPropType(propValue);
|
29983 | if (propType === 'object') {
|
29984 | if (propValue instanceof Date) {
|
29985 | return 'date';
|
29986 | } else if (propValue instanceof RegExp) {
|
29987 | return 'regexp';
|
29988 | }
|
29989 | }
|
29990 | return propType;
|
29991 | }
|
29992 |
|
29993 | // Returns class name of the object, if any.
|
29994 | function getClassName(propValue) {
|
29995 | if (!propValue.constructor || !propValue.constructor.name) {
|
29996 | return ANONYMOUS;
|
29997 | }
|
29998 | return propValue.constructor.name;
|
29999 | }
|
30000 |
|
30001 | module.exports = ReactPropTypes;
|
30002 | }).call(this,require('_process'))
|
30003 | },{"./ReactElement":294,"./ReactPropTypeLocationNames":298,"./ReactPropTypesSecret":300,"./getIteratorFn":305,"_process":144,"fbjs/lib/emptyFunction":116,"fbjs/lib/warning":131}],300:[function(require,module,exports){
|
30004 | arguments[4][224][0].apply(exports,arguments)
|
30005 | },{"dup":224}],301:[function(require,module,exports){
|
30006 | /**
|
30007 | * Copyright 2013-present, Facebook, Inc.
|
30008 | * All rights reserved.
|
30009 | *
|
30010 | * This source code is licensed under the BSD-style license found in the
|
30011 | * LICENSE file in the root directory of this source tree. An additional grant
|
30012 | * of patent rights can be found in the PATENTS file in the same directory.
|
30013 | *
|
30014 | */
|
30015 |
|
30016 | 'use strict';
|
30017 |
|
30018 | var _assign = require('object-assign');
|
30019 |
|
30020 | var ReactComponent = require('./ReactComponent');
|
30021 | var ReactNoopUpdateQueue = require('./ReactNoopUpdateQueue');
|
30022 |
|
30023 | var emptyObject = require('fbjs/lib/emptyObject');
|
30024 |
|
30025 | /**
|
30026 | * Base class helpers for the updating state of a component.
|
30027 | */
|
30028 | function ReactPureComponent(props, context, updater) {
|
30029 | // Duplicated from ReactComponent.
|
30030 | this.props = props;
|
30031 | this.context = context;
|
30032 | this.refs = emptyObject;
|
30033 | // We initialize the default updater but the real one gets injected by the
|
30034 | // renderer.
|
30035 | this.updater = updater || ReactNoopUpdateQueue;
|
30036 | }
|
30037 |
|
30038 | function ComponentDummy() {}
|
30039 | ComponentDummy.prototype = ReactComponent.prototype;
|
30040 | ReactPureComponent.prototype = new ComponentDummy();
|
30041 | ReactPureComponent.prototype.constructor = ReactPureComponent;
|
30042 | // Avoid an extra prototype jump for these methods.
|
30043 | _assign(ReactPureComponent.prototype, ReactComponent.prototype);
|
30044 | ReactPureComponent.prototype.isPureReactComponent = true;
|
30045 |
|
30046 | module.exports = ReactPureComponent;
|
30047 | },{"./ReactComponent":290,"./ReactNoopUpdateQueue":297,"fbjs/lib/emptyObject":117,"object-assign":143}],302:[function(require,module,exports){
|
30048 | arguments[4][234][0].apply(exports,arguments)
|
30049 | },{"dup":234}],303:[function(require,module,exports){
|
30050 | (function (process){
|
30051 | /**
|
30052 | * Copyright 2013-present, Facebook, Inc.
|
30053 | * All rights reserved.
|
30054 | *
|
30055 | * This source code is licensed under the BSD-style license found in the
|
30056 | * LICENSE file in the root directory of this source tree. An additional grant
|
30057 | * of patent rights can be found in the PATENTS file in the same directory.
|
30058 | *
|
30059 | *
|
30060 | */
|
30061 |
|
30062 | 'use strict';
|
30063 |
|
30064 | var canDefineProperty = false;
|
30065 | if (process.env.NODE_ENV !== 'production') {
|
30066 | try {
|
30067 | // $FlowFixMe https://github.com/facebook/flow/issues/285
|
30068 | Object.defineProperty({}, 'x', { get: function () {} });
|
30069 | canDefineProperty = true;
|
30070 | } catch (x) {
|
30071 | // IE will fail on defineProperty
|
30072 | }
|
30073 | }
|
30074 |
|
30075 | module.exports = canDefineProperty;
|
30076 | }).call(this,require('_process'))
|
30077 | },{"_process":144}],304:[function(require,module,exports){
|
30078 | (function (process){
|
30079 | /**
|
30080 | * Copyright 2013-present, Facebook, Inc.
|
30081 | * All rights reserved.
|
30082 | *
|
30083 | * This source code is licensed under the BSD-style license found in the
|
30084 | * LICENSE file in the root directory of this source tree. An additional grant
|
30085 | * of patent rights can be found in the PATENTS file in the same directory.
|
30086 | *
|
30087 | */
|
30088 |
|
30089 | 'use strict';
|
30090 |
|
30091 | var _prodInvariant = require('./reactProdInvariant');
|
30092 |
|
30093 | var ReactPropTypeLocationNames = require('./ReactPropTypeLocationNames');
|
30094 | var ReactPropTypesSecret = require('./ReactPropTypesSecret');
|
30095 |
|
30096 | var invariant = require('fbjs/lib/invariant');
|
30097 | var warning = require('fbjs/lib/warning');
|
30098 |
|
30099 | var ReactComponentTreeHook;
|
30100 |
|
30101 | if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'test') {
|
30102 | // Temporary hack.
|
30103 | // Inline requires don't work well with Jest:
|
30104 | // https://github.com/facebook/react/issues/7240
|
30105 | // Remove the inline requires when we don't need them anymore:
|
30106 | // https://github.com/facebook/react/pull/7178
|
30107 | ReactComponentTreeHook = require('./ReactComponentTreeHook');
|
30108 | }
|
30109 |
|
30110 | var loggedTypeFailures = {};
|
30111 |
|
30112 | /**
|
30113 | * Assert that the values match with the type specs.
|
30114 | * Error messages are memorized and will only be shown once.
|
30115 | *
|
30116 | * @param {object} typeSpecs Map of name to a ReactPropType
|
30117 | * @param {object} values Runtime values that need to be type-checked
|
30118 | * @param {string} location e.g. "prop", "context", "child context"
|
30119 | * @param {string} componentName Name of the component for error messages.
|
30120 | * @param {?object} element The React element that is being type-checked
|
30121 | * @param {?number} debugID The React component instance that is being type-checked
|
30122 | * @private
|
30123 | */
|
30124 | function checkReactTypeSpec(typeSpecs, values, location, componentName, element, debugID) {
|
30125 | for (var typeSpecName in typeSpecs) {
|
30126 | if (typeSpecs.hasOwnProperty(typeSpecName)) {
|
30127 | var error;
|
30128 | // Prop type validation may throw. In case they do, we don't want to
|
30129 | // fail the render phase where it didn't fail before. So we log it.
|
30130 | // After these have been cleaned up, we'll let them throw.
|
30131 | try {
|
30132 | // This is intentionally an invariant that gets caught. It's the same
|
30133 | // behavior as without this statement except with a better message.
|
30134 | !(typeof typeSpecs[typeSpecName] === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName) : _prodInvariant('84', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName) : void 0;
|
30135 | error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
|
30136 | } catch (ex) {
|
30137 | error = ex;
|
30138 | }
|
30139 | process.env.NODE_ENV !== 'production' ? warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', ReactPropTypeLocationNames[location], typeSpecName, typeof error) : void 0;
|
30140 | if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
30141 | // Only monitor this failure once because there tends to be a lot of the
|
30142 | // same error.
|
30143 | loggedTypeFailures[error.message] = true;
|
30144 |
|
30145 | var componentStackInfo = '';
|
30146 |
|
30147 | if (process.env.NODE_ENV !== 'production') {
|
30148 | if (!ReactComponentTreeHook) {
|
30149 | ReactComponentTreeHook = require('./ReactComponentTreeHook');
|
30150 | }
|
30151 | if (debugID !== null) {
|
30152 | componentStackInfo = ReactComponentTreeHook.getStackAddendumByID(debugID);
|
30153 | } else if (element !== null) {
|
30154 | componentStackInfo = ReactComponentTreeHook.getCurrentStackAddendum(element);
|
30155 | }
|
30156 | }
|
30157 |
|
30158 | process.env.NODE_ENV !== 'production' ? warning(false, 'Failed %s type: %s%s', location, error.message, componentStackInfo) : void 0;
|
30159 | }
|
30160 | }
|
30161 | }
|
30162 | }
|
30163 |
|
30164 | module.exports = checkReactTypeSpec;
|
30165 | }).call(this,require('_process'))
|
30166 | },{"./ReactComponentTreeHook":291,"./ReactPropTypeLocationNames":298,"./ReactPropTypesSecret":300,"./reactProdInvariant":307,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131}],305:[function(require,module,exports){
|
30167 | arguments[4][267][0].apply(exports,arguments)
|
30168 | },{"dup":267}],306:[function(require,module,exports){
|
30169 | (function (process){
|
30170 | /**
|
30171 | * Copyright 2013-present, Facebook, Inc.
|
30172 | * All rights reserved.
|
30173 | *
|
30174 | * This source code is licensed under the BSD-style license found in the
|
30175 | * LICENSE file in the root directory of this source tree. An additional grant
|
30176 | * of patent rights can be found in the PATENTS file in the same directory.
|
30177 | *
|
30178 | */
|
30179 | 'use strict';
|
30180 |
|
30181 | var _prodInvariant = require('./reactProdInvariant');
|
30182 |
|
30183 | var ReactElement = require('./ReactElement');
|
30184 |
|
30185 | var invariant = require('fbjs/lib/invariant');
|
30186 |
|
30187 | /**
|
30188 | * Returns the first child in a collection of children and verifies that there
|
30189 | * is only one child in the collection.
|
30190 | *
|
30191 | * See https://facebook.github.io/react/docs/top-level-api.html#react.children.only
|
30192 | *
|
30193 | * The current implementation of this function assumes that a single child gets
|
30194 | * passed without a wrapper, but the purpose of this helper function is to
|
30195 | * abstract away the particular structure of children.
|
30196 | *
|
30197 | * @param {?object} children Child collection structure.
|
30198 | * @return {ReactElement} The first and only `ReactElement` contained in the
|
30199 | * structure.
|
30200 | */
|
30201 | function onlyChild(children) {
|
30202 | !ReactElement.isValidElement(children) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'React.Children.only expected to receive a single React element child.') : _prodInvariant('143') : void 0;
|
30203 | return children;
|
30204 | }
|
30205 |
|
30206 | module.exports = onlyChild;
|
30207 | }).call(this,require('_process'))
|
30208 | },{"./ReactElement":294,"./reactProdInvariant":307,"_process":144,"fbjs/lib/invariant":124}],307:[function(require,module,exports){
|
30209 | arguments[4][276][0].apply(exports,arguments)
|
30210 | },{"dup":276}],308:[function(require,module,exports){
|
30211 | (function (process){
|
30212 | /**
|
30213 | * Copyright 2013-present, Facebook, Inc.
|
30214 | * All rights reserved.
|
30215 | *
|
30216 | * This source code is licensed under the BSD-style license found in the
|
30217 | * LICENSE file in the root directory of this source tree. An additional grant
|
30218 | * of patent rights can be found in the PATENTS file in the same directory.
|
30219 | *
|
30220 | */
|
30221 |
|
30222 | 'use strict';
|
30223 |
|
30224 | var _prodInvariant = require('./reactProdInvariant');
|
30225 |
|
30226 | var ReactCurrentOwner = require('./ReactCurrentOwner');
|
30227 | var REACT_ELEMENT_TYPE = require('./ReactElementSymbol');
|
30228 |
|
30229 | var getIteratorFn = require('./getIteratorFn');
|
30230 | var invariant = require('fbjs/lib/invariant');
|
30231 | var KeyEscapeUtils = require('./KeyEscapeUtils');
|
30232 | var warning = require('fbjs/lib/warning');
|
30233 |
|
30234 | var SEPARATOR = '.';
|
30235 | var SUBSEPARATOR = ':';
|
30236 |
|
30237 | /**
|
30238 | * This is inlined from ReactElement since this file is shared between
|
30239 | * isomorphic and renderers. We could extract this to a
|
30240 | *
|
30241 | */
|
30242 |
|
30243 | /**
|
30244 | * TODO: Test that a single child and an array with one item have the same key
|
30245 | * pattern.
|
30246 | */
|
30247 |
|
30248 | var didWarnAboutMaps = false;
|
30249 |
|
30250 | /**
|
30251 | * Generate a key string that identifies a component within a set.
|
30252 | *
|
30253 | * @param {*} component A component that could contain a manual key.
|
30254 | * @param {number} index Index that is used if a manual key is not provided.
|
30255 | * @return {string}
|
30256 | */
|
30257 | function getComponentKey(component, index) {
|
30258 | // Do some typechecking here since we call this blindly. We want to ensure
|
30259 | // that we don't block potential future ES APIs.
|
30260 | if (component && typeof component === 'object' && component.key != null) {
|
30261 | // Explicit key
|
30262 | return KeyEscapeUtils.escape(component.key);
|
30263 | }
|
30264 | // Implicit key determined by the index in the set
|
30265 | return index.toString(36);
|
30266 | }
|
30267 |
|
30268 | /**
|
30269 | * @param {?*} children Children tree container.
|
30270 | * @param {!string} nameSoFar Name of the key path so far.
|
30271 | * @param {!function} callback Callback to invoke with each child found.
|
30272 | * @param {?*} traverseContext Used to pass information throughout the traversal
|
30273 | * process.
|
30274 | * @return {!number} The number of children in this subtree.
|
30275 | */
|
30276 | function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) {
|
30277 | var type = typeof children;
|
30278 |
|
30279 | if (type === 'undefined' || type === 'boolean') {
|
30280 | // All of the above are perceived as null.
|
30281 | children = null;
|
30282 | }
|
30283 |
|
30284 | if (children === null || type === 'string' || type === 'number' ||
|
30285 | // The following is inlined from ReactElement. This means we can optimize
|
30286 | // some checks. React Fiber also inlines this logic for similar purposes.
|
30287 | type === 'object' && children.$$typeof === REACT_ELEMENT_TYPE) {
|
30288 | callback(traverseContext, children,
|
30289 | // If it's the only child, treat the name as if it was wrapped in an array
|
30290 | // so that it's consistent if the number of children grows.
|
30291 | nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar);
|
30292 | return 1;
|
30293 | }
|
30294 |
|
30295 | var child;
|
30296 | var nextName;
|
30297 | var subtreeCount = 0; // Count of children found in the current subtree.
|
30298 | var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
|
30299 |
|
30300 | if (Array.isArray(children)) {
|
30301 | for (var i = 0; i < children.length; i++) {
|
30302 | child = children[i];
|
30303 | nextName = nextNamePrefix + getComponentKey(child, i);
|
30304 | subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
30305 | }
|
30306 | } else {
|
30307 | var iteratorFn = getIteratorFn(children);
|
30308 | if (iteratorFn) {
|
30309 | var iterator = iteratorFn.call(children);
|
30310 | var step;
|
30311 | if (iteratorFn !== children.entries) {
|
30312 | var ii = 0;
|
30313 | while (!(step = iterator.next()).done) {
|
30314 | child = step.value;
|
30315 | nextName = nextNamePrefix + getComponentKey(child, ii++);
|
30316 | subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
30317 | }
|
30318 | } else {
|
30319 | if (process.env.NODE_ENV !== 'production') {
|
30320 | var mapsAsChildrenAddendum = '';
|
30321 | if (ReactCurrentOwner.current) {
|
30322 | var mapsAsChildrenOwnerName = ReactCurrentOwner.current.getName();
|
30323 | if (mapsAsChildrenOwnerName) {
|
30324 | mapsAsChildrenAddendum = ' Check the render method of `' + mapsAsChildrenOwnerName + '`.';
|
30325 | }
|
30326 | }
|
30327 | process.env.NODE_ENV !== 'production' ? warning(didWarnAboutMaps, 'Using Maps as children is not yet fully supported. It is an ' + 'experimental feature that might be removed. Convert it to a ' + 'sequence / iterable of keyed ReactElements instead.%s', mapsAsChildrenAddendum) : void 0;
|
30328 | didWarnAboutMaps = true;
|
30329 | }
|
30330 | // Iterator will provide entry [k,v] tuples rather than values.
|
30331 | while (!(step = iterator.next()).done) {
|
30332 | var entry = step.value;
|
30333 | if (entry) {
|
30334 | child = entry[1];
|
30335 | nextName = nextNamePrefix + KeyEscapeUtils.escape(entry[0]) + SUBSEPARATOR + getComponentKey(child, 0);
|
30336 | subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
30337 | }
|
30338 | }
|
30339 | }
|
30340 | } else if (type === 'object') {
|
30341 | var addendum = '';
|
30342 | if (process.env.NODE_ENV !== 'production') {
|
30343 | addendum = ' If you meant to render a collection of children, use an array ' + 'instead or wrap the object using createFragment(object) from the ' + 'React add-ons.';
|
30344 | if (children._isReactElement) {
|
30345 | addendum = ' It looks like you\'re using an element created by a different ' + 'version of React. Make sure to use only one copy of React.';
|
30346 | }
|
30347 | if (ReactCurrentOwner.current) {
|
30348 | var name = ReactCurrentOwner.current.getName();
|
30349 | if (name) {
|
30350 | addendum += ' Check the render method of `' + name + '`.';
|
30351 | }
|
30352 | }
|
30353 | }
|
30354 | var childrenString = String(children);
|
30355 | !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Objects are not valid as a React child (found: %s).%s', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum) : _prodInvariant('31', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum) : void 0;
|
30356 | }
|
30357 | }
|
30358 |
|
30359 | return subtreeCount;
|
30360 | }
|
30361 |
|
30362 | /**
|
30363 | * Traverses children that are typically specified as `props.children`, but
|
30364 | * might also be specified through attributes:
|
30365 | *
|
30366 | * - `traverseAllChildren(this.props.children, ...)`
|
30367 | * - `traverseAllChildren(this.props.leftPanelChildren, ...)`
|
30368 | *
|
30369 | * The `traverseContext` is an optional argument that is passed through the
|
30370 | * entire traversal. It can be used to store accumulations or anything else that
|
30371 | * the callback might find relevant.
|
30372 | *
|
30373 | * @param {?*} children Children tree object.
|
30374 | * @param {!function} callback To invoke upon traversing each child.
|
30375 | * @param {?*} traverseContext Context for traversal.
|
30376 | * @return {!number} The number of children in this subtree.
|
30377 | */
|
30378 | function traverseAllChildren(children, callback, traverseContext) {
|
30379 | if (children == null) {
|
30380 | return 0;
|
30381 | }
|
30382 |
|
30383 | return traverseAllChildrenImpl(children, '', callback, traverseContext);
|
30384 | }
|
30385 |
|
30386 | module.exports = traverseAllChildren;
|
30387 | }).call(this,require('_process'))
|
30388 | },{"./KeyEscapeUtils":285,"./ReactCurrentOwner":292,"./ReactElementSymbol":295,"./getIteratorFn":305,"./reactProdInvariant":307,"_process":144,"fbjs/lib/invariant":124,"fbjs/lib/warning":131}],309:[function(require,module,exports){
|
30389 | 'use strict';
|
30390 |
|
30391 | module.exports = require('./lib/React');
|
30392 |
|
30393 | },{"./lib/React":287}],310:[function(require,module,exports){
|
30394 | 'use strict';
|
30395 | var isFinite = require('is-finite');
|
30396 |
|
30397 | module.exports = function (str, n) {
|
30398 | if (typeof str !== 'string') {
|
30399 | throw new TypeError('Expected `input` to be a string');
|
30400 | }
|
30401 |
|
30402 | if (n < 0 || !isFinite(n)) {
|
30403 | throw new TypeError('Expected `count` to be a positive finite number');
|
30404 | }
|
30405 |
|
30406 | var ret = '';
|
30407 |
|
30408 | do {
|
30409 | if (n & 1) {
|
30410 | ret += str;
|
30411 | }
|
30412 |
|
30413 | str += str;
|
30414 | } while ((n >>= 1));
|
30415 |
|
30416 | return ret;
|
30417 | };
|
30418 |
|
30419 | },{"is-finite":137}],311:[function(require,module,exports){
|
30420 | function isBackward(selection) {
|
30421 | var startNode = selection.anchorNode;
|
30422 | var startOffset = selection.anchorOffset;
|
30423 | var endNode = selection.focusNode;
|
30424 | var endOffset = selection.focusOffset;
|
30425 |
|
30426 | var position = startNode.compareDocumentPosition(endNode);
|
30427 |
|
30428 | return !(position === 4 || (position === 0 && startOffset < endOffset));
|
30429 | }
|
30430 |
|
30431 | module.exports = isBackward;
|
30432 |
|
30433 | },{}],312:[function(require,module,exports){
|
30434 | 'use strict';
|
30435 |
|
30436 | Object.defineProperty(exports, "__esModule", {
|
30437 | value: true
|
30438 | });
|
30439 |
|
30440 | var _block = require('../models/block');
|
30441 |
|
30442 | var _block2 = _interopRequireDefault(_block);
|
30443 |
|
30444 | var _inline = require('../models/inline');
|
30445 |
|
30446 | var _inline2 = _interopRequireDefault(_inline);
|
30447 |
|
30448 | var _mark = require('../models/mark');
|
30449 |
|
30450 | var _mark2 = _interopRequireDefault(_mark);
|
30451 |
|
30452 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
30453 |
|
30454 | /**
|
30455 | * Changes.
|
30456 | *
|
30457 | * @type {Object}
|
30458 | */
|
30459 |
|
30460 | var Changes = {};
|
30461 |
|
30462 | /**
|
30463 | * Mix in the changes that just pass through to their at-range equivalents
|
30464 | * because they don't have any effect on the selection.
|
30465 | */
|
30466 |
|
30467 | var PROXY_TRANSFORMS = ['deleteBackward', 'deleteCharBackward', 'deleteLineBackward', 'deleteWordBackward', 'deleteForward', 'deleteCharForward', 'deleteWordForward', 'deleteLineForward', 'setBlock', 'setInline', 'splitInline', 'unwrapBlock', 'unwrapInline', 'wrapBlock', 'wrapInline'];
|
30468 |
|
30469 | PROXY_TRANSFORMS.forEach(function (method) {
|
30470 | Changes[method] = function (change) {
|
30471 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
30472 | args[_key - 1] = arguments[_key];
|
30473 | }
|
30474 |
|
30475 | var state = change.state;
|
30476 | var selection = state.selection;
|
30477 |
|
30478 | var methodAtRange = method + 'AtRange';
|
30479 | change[methodAtRange].apply(change, [selection].concat(args));
|
30480 | };
|
30481 | });
|
30482 |
|
30483 | /**
|
30484 | * Add a `mark` to the characters in the current selection.
|
30485 | *
|
30486 | * @param {Change} change
|
30487 | * @param {Mark} mark
|
30488 | */
|
30489 |
|
30490 | Changes.addMark = function (change, mark) {
|
30491 | mark = _mark2.default.create(mark);
|
30492 | var state = change.state;
|
30493 | var document = state.document,
|
30494 | selection = state.selection;
|
30495 |
|
30496 |
|
30497 | if (selection.isExpanded) {
|
30498 | change.addMarkAtRange(selection, mark);
|
30499 | } else if (selection.marks) {
|
30500 | var marks = selection.marks.add(mark);
|
30501 | var sel = selection.set('marks', marks);
|
30502 | change.select(sel);
|
30503 | } else {
|
30504 | var _marks = document.getActiveMarksAtRange(selection).add(mark);
|
30505 | var _sel = selection.set('marks', _marks);
|
30506 | change.select(_sel);
|
30507 | }
|
30508 | };
|
30509 |
|
30510 | /**
|
30511 | * Delete at the current selection.
|
30512 | *
|
30513 | * @param {Change} change
|
30514 | */
|
30515 |
|
30516 | Changes.delete = function (change) {
|
30517 | var state = change.state;
|
30518 | var selection = state.selection;
|
30519 |
|
30520 | change.deleteAtRange(selection);
|
30521 |
|
30522 | // Ensure that the selection is collapsed to the start, because in certain
|
30523 | // cases when deleting across inline nodes, when splitting the inline node the
|
30524 | // end point of the selection will end up after the split point.
|
30525 | change.collapseToStart();
|
30526 | };
|
30527 |
|
30528 | /**
|
30529 | * Insert a `block` at the current selection.
|
30530 | *
|
30531 | * @param {Change} change
|
30532 | * @param {String|Object|Block} block
|
30533 | */
|
30534 |
|
30535 | Changes.insertBlock = function (change, block) {
|
30536 | block = _block2.default.create(block);
|
30537 | var state = change.state;
|
30538 | var selection = state.selection;
|
30539 |
|
30540 | change.insertBlockAtRange(selection, block);
|
30541 |
|
30542 | // If the node was successfully inserted, update the selection.
|
30543 | var node = change.state.document.getNode(block.key);
|
30544 | if (node) change.collapseToEndOf(node);
|
30545 | };
|
30546 |
|
30547 | /**
|
30548 | * Insert a `fragment` at the current selection.
|
30549 | *
|
30550 | * @param {Change} change
|
30551 | * @param {Document} fragment
|
30552 | */
|
30553 |
|
30554 | Changes.insertFragment = function (change, fragment) {
|
30555 | if (!fragment.nodes.size) return;
|
30556 |
|
30557 | var state = change.state;
|
30558 | var _state = state,
|
30559 | document = _state.document,
|
30560 | selection = _state.selection;
|
30561 | var _state2 = state,
|
30562 | startText = _state2.startText,
|
30563 | endText = _state2.endText,
|
30564 | startInline = _state2.startInline;
|
30565 |
|
30566 | var lastText = fragment.getLastText();
|
30567 | var lastInline = fragment.getClosestInline(lastText.key);
|
30568 | var keys = document.getTexts().map(function (text) {
|
30569 | return text.key;
|
30570 | });
|
30571 | var isAppending = !startInline || selection.hasEdgeAtStartOf(startText) || selection.hasEdgeAtEndOf(endText);
|
30572 |
|
30573 | change.insertFragmentAtRange(selection, fragment);
|
30574 | state = change.state;
|
30575 | document = state.document;
|
30576 |
|
30577 | var newTexts = document.getTexts().filter(function (n) {
|
30578 | return !keys.includes(n.key);
|
30579 | });
|
30580 | var newText = isAppending ? newTexts.last() : newTexts.takeLast(2).first();
|
30581 |
|
30582 | if (newText && lastInline) {
|
30583 | change.select(selection.collapseToEndOf(newText));
|
30584 | } else if (newText) {
|
30585 | change.select(selection.collapseToStartOf(newText).move(lastText.text.length));
|
30586 | } else {
|
30587 | change.select(selection.collapseToStart().move(lastText.text.length));
|
30588 | }
|
30589 | };
|
30590 |
|
30591 | /**
|
30592 | * Insert an `inline` at the current selection.
|
30593 | *
|
30594 | * @param {Change} change
|
30595 | * @param {String|Object|Inline} inline
|
30596 | */
|
30597 |
|
30598 | Changes.insertInline = function (change, inline) {
|
30599 | inline = _inline2.default.create(inline);
|
30600 | var state = change.state;
|
30601 | var selection = state.selection;
|
30602 |
|
30603 | change.insertInlineAtRange(selection, inline);
|
30604 |
|
30605 | // If the node was successfully inserted, update the selection.
|
30606 | var node = change.state.document.getNode(inline.key);
|
30607 | if (node) change.collapseToEndOf(node);
|
30608 | };
|
30609 |
|
30610 | /**
|
30611 | * Insert a string of `text` with optional `marks` at the current selection.
|
30612 | *
|
30613 | * @param {Change} change
|
30614 | * @param {String} text
|
30615 | * @param {Set<Mark>} marks (optional)
|
30616 | */
|
30617 |
|
30618 | Changes.insertText = function (change, text, marks) {
|
30619 | var state = change.state;
|
30620 | var document = state.document,
|
30621 | selection = state.selection;
|
30622 |
|
30623 | marks = marks || selection.marks;
|
30624 | change.insertTextAtRange(selection, text, marks);
|
30625 |
|
30626 | // If the text was successfully inserted, and the selection had marks on it,
|
30627 | // unset the selection's marks.
|
30628 | if (selection.marks && document != change.state.document) {
|
30629 | change.select({ marks: null });
|
30630 | }
|
30631 | };
|
30632 |
|
30633 | /**
|
30634 | * Split the block node at the current selection, to optional `depth`.
|
30635 | *
|
30636 | * @param {Change} change
|
30637 | * @param {Number} depth (optional)
|
30638 | */
|
30639 |
|
30640 | Changes.splitBlock = function (change) {
|
30641 | var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
30642 | var state = change.state;
|
30643 | var selection = state.selection;
|
30644 |
|
30645 | change.splitBlockAtRange(selection, depth).collapseToEnd();
|
30646 | };
|
30647 |
|
30648 | /**
|
30649 | * Remove a `mark` from the characters in the current selection.
|
30650 | *
|
30651 | * @param {Change} change
|
30652 | * @param {Mark} mark
|
30653 | */
|
30654 |
|
30655 | Changes.removeMark = function (change, mark) {
|
30656 | mark = _mark2.default.create(mark);
|
30657 | var state = change.state;
|
30658 | var document = state.document,
|
30659 | selection = state.selection;
|
30660 |
|
30661 |
|
30662 | if (selection.isExpanded) {
|
30663 | change.removeMarkAtRange(selection, mark);
|
30664 | } else if (selection.marks) {
|
30665 | var marks = selection.marks.remove(mark);
|
30666 | var sel = selection.set('marks', marks);
|
30667 | change.select(sel);
|
30668 | } else {
|
30669 | var _marks2 = document.getActiveMarksAtRange(selection).remove(mark);
|
30670 | var _sel2 = selection.set('marks', _marks2);
|
30671 | change.select(_sel2);
|
30672 | }
|
30673 | };
|
30674 |
|
30675 | /**
|
30676 | * Add or remove a `mark` from the characters in the current selection,
|
30677 | * depending on whether it's already there.
|
30678 | *
|
30679 | * @param {Change} change
|
30680 | * @param {Mark} mark
|
30681 | */
|
30682 |
|
30683 | Changes.toggleMark = function (change, mark) {
|
30684 | mark = _mark2.default.create(mark);
|
30685 | var state = change.state;
|
30686 |
|
30687 | var exists = state.activeMarks.has(mark);
|
30688 |
|
30689 | if (exists) {
|
30690 | change.removeMark(mark);
|
30691 | } else {
|
30692 | change.addMark(mark);
|
30693 | }
|
30694 | };
|
30695 |
|
30696 | /**
|
30697 | * Wrap the current selection with prefix/suffix.
|
30698 | *
|
30699 | * @param {Change} change
|
30700 | * @param {String} prefix
|
30701 | * @param {String} suffix
|
30702 | */
|
30703 |
|
30704 | Changes.wrapText = function (change, prefix) {
|
30705 | var suffix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : prefix;
|
30706 | var state = change.state;
|
30707 | var selection = state.selection;
|
30708 |
|
30709 | change.wrapTextAtRange(selection, prefix, suffix);
|
30710 |
|
30711 | // If the selection was collapsed, it will have moved the start offset too.
|
30712 | if (selection.isCollapsed) {
|
30713 | change.moveStart(0 - prefix.length);
|
30714 | }
|
30715 |
|
30716 | // Adding the suffix will have pushed the end of the selection further on, so
|
30717 | // we need to move it back to account for this.
|
30718 | change.moveEnd(0 - suffix.length);
|
30719 |
|
30720 | // There's a chance that the selection points moved "through" each other,
|
30721 | // resulting in a now-incorrect selection direction.
|
30722 | if (selection.isForward != change.state.selection.isForward) {
|
30723 | change.flip();
|
30724 | }
|
30725 | };
|
30726 |
|
30727 | /**
|
30728 | * Export.
|
30729 | *
|
30730 | * @type {Object}
|
30731 | */
|
30732 |
|
30733 | exports.default = Changes;
|
30734 | },{"../models/block":331,"../models/inline":337,"../models/mark":338}],313:[function(require,module,exports){
|
30735 | 'use strict';
|
30736 |
|
30737 | Object.defineProperty(exports, "__esModule", {
|
30738 | value: true
|
30739 | });
|
30740 |
|
30741 | var _block = require('../models/block');
|
30742 |
|
30743 | var _block2 = _interopRequireDefault(_block);
|
30744 |
|
30745 | var _inline = require('../models/inline');
|
30746 |
|
30747 | var _inline2 = _interopRequireDefault(_inline);
|
30748 |
|
30749 | var _mark = require('../models/mark');
|
30750 |
|
30751 | var _mark2 = _interopRequireDefault(_mark);
|
30752 |
|
30753 | var _node = require('../models/node');
|
30754 |
|
30755 | var _node2 = _interopRequireDefault(_node);
|
30756 |
|
30757 | var _string = require('../utils/string');
|
30758 |
|
30759 | var _string2 = _interopRequireDefault(_string);
|
30760 |
|
30761 | var _core = require('../schemas/core');
|
30762 |
|
30763 | var _core2 = _interopRequireDefault(_core);
|
30764 |
|
30765 | var _immutable = require('immutable');
|
30766 |
|
30767 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
30768 |
|
30769 | /**
|
30770 | * Changes.
|
30771 | *
|
30772 | * @type {Object}
|
30773 | */
|
30774 |
|
30775 | var Changes = {};
|
30776 |
|
30777 | /**
|
30778 | * Add a new `mark` to the characters at `range`.
|
30779 | *
|
30780 | * @param {Change} change
|
30781 | * @param {Selection} range
|
30782 | * @param {Mixed} mark
|
30783 | * @param {Object} options
|
30784 | * @property {Boolean} normalize
|
30785 | */
|
30786 |
|
30787 | Changes.addMarkAtRange = function (change, range, mark) {
|
30788 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
30789 |
|
30790 | if (range.isCollapsed) return;
|
30791 |
|
30792 | var _options$normalize = options.normalize,
|
30793 | normalize = _options$normalize === undefined ? true : _options$normalize;
|
30794 | var state = change.state;
|
30795 | var document = state.document;
|
30796 | var startKey = range.startKey,
|
30797 | startOffset = range.startOffset,
|
30798 | endKey = range.endKey,
|
30799 | endOffset = range.endOffset;
|
30800 |
|
30801 | var texts = document.getTextsAtRange(range);
|
30802 |
|
30803 | texts.forEach(function (node) {
|
30804 | var key = node.key;
|
30805 |
|
30806 | var index = 0;
|
30807 | var length = node.text.length;
|
30808 |
|
30809 | if (key == startKey) index = startOffset;
|
30810 | if (key == endKey) length = endOffset;
|
30811 | if (key == startKey && key == endKey) length = endOffset - startOffset;
|
30812 |
|
30813 | change.addMarkByKey(key, index, length, mark, { normalize: normalize });
|
30814 | });
|
30815 | };
|
30816 |
|
30817 | /**
|
30818 | * Delete everything in a `range`.
|
30819 | *
|
30820 | * @param {Change} change
|
30821 | * @param {Selection} range
|
30822 | * @param {Object} options
|
30823 | * @property {Boolean} normalize
|
30824 | */
|
30825 |
|
30826 | Changes.deleteAtRange = function (change, range) {
|
30827 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
30828 |
|
30829 | if (range.isCollapsed) return;
|
30830 |
|
30831 | // Snapshot the selection, which creates an extra undo save point, so that
|
30832 | // when you undo a delete, the expanded selection will be retained.
|
30833 | change.snapshotSelection();
|
30834 |
|
30835 | var _options$normalize2 = options.normalize,
|
30836 | normalize = _options$normalize2 === undefined ? true : _options$normalize2;
|
30837 | var state = change.state;
|
30838 | var startKey = range.startKey,
|
30839 | startOffset = range.startOffset,
|
30840 | endKey = range.endKey,
|
30841 | endOffset = range.endOffset;
|
30842 | var document = state.document;
|
30843 |
|
30844 | var isStartVoid = document.hasVoidParent(startKey);
|
30845 | var isEndVoid = document.hasVoidParent(endKey);
|
30846 | var startBlock = document.getClosestBlock(startKey);
|
30847 | var endBlock = document.getClosestBlock(endKey);
|
30848 |
|
30849 | // Check if we have a "hanging" selection case where the even though the
|
30850 | // selection extends into the start of the end node, we actually want to
|
30851 | // ignore that for UX reasons.
|
30852 | var isHanging = startOffset == 0 && endOffset == 0 && isStartVoid == false && startKey == startBlock.getFirstText().key && endKey == endBlock.getFirstText().key;
|
30853 |
|
30854 | // If it's a hanging selection, nudge it back to end in the previous text.
|
30855 | if (isHanging) {
|
30856 | var prevText = document.getPreviousText(endKey);
|
30857 | endKey = prevText.key;
|
30858 | endOffset = prevText.text.length;
|
30859 | isEndVoid = document.hasVoidParent(endKey);
|
30860 | }
|
30861 |
|
30862 | // If the start node is inside a void node, remove the void node and update
|
30863 | // the starting point to be right after it, continuously until the start point
|
30864 | // is not a void, or until the entire range is handled.
|
30865 | while (isStartVoid) {
|
30866 | var startVoid = document.getClosestVoid(startKey);
|
30867 | var _nextText = document.getNextText(startKey);
|
30868 | change.removeNodeByKey(startVoid.key, { normalize: false });
|
30869 |
|
30870 | // If the start and end keys are the same, we're done.
|
30871 | if (startKey == endKey) return;
|
30872 |
|
30873 | // If there is no next text node, we're done.
|
30874 | if (!_nextText) return;
|
30875 |
|
30876 | // Continue...
|
30877 | document = change.state.document;
|
30878 | startKey = _nextText.key;
|
30879 | startOffset = 0;
|
30880 | isStartVoid = document.hasVoidParent(startKey);
|
30881 | }
|
30882 |
|
30883 | // If the end node is inside a void node, do the same thing but backwards. But
|
30884 | // we don't need any aborting checks because if we've gotten this far there
|
30885 | // must be a non-void node that will exit the loop.
|
30886 | while (isEndVoid) {
|
30887 | var endVoid = document.getClosestVoid(endKey);
|
30888 | var _prevText = document.getPreviousText(endKey);
|
30889 | change.removeNodeByKey(endVoid.key, { normalize: false });
|
30890 |
|
30891 | // Continue...
|
30892 | document = change.state.document;
|
30893 | endKey = _prevText.key;
|
30894 | endOffset = _prevText.text.length;
|
30895 | isEndVoid = document.hasVoidParent(endKey);
|
30896 | }
|
30897 |
|
30898 | // If the start and end key are the same, and it was a hanging selection, we
|
30899 | // can just remove the entire block.
|
30900 | if (startKey == endKey && isHanging) {
|
30901 | change.removeNodeByKey(startBlock.key);
|
30902 | return;
|
30903 | }
|
30904 |
|
30905 | // Otherwise, if it wasn't hanging, we're inside a single text node, so we can
|
30906 | // simply remove the text in the range.
|
30907 | else if (startKey == endKey) {
|
30908 | var index = startOffset;
|
30909 | var length = endOffset - startOffset;
|
30910 | change.removeTextByKey(startKey, index, length, { normalize: normalize });
|
30911 | return;
|
30912 | }
|
30913 |
|
30914 | // Otherwise, we need to remove more than one node, so first split at the
|
30915 | // range edges within a common ancestor, without normalizing. This makes it
|
30916 | // easy, because we can then just remove every node inside the split.
|
30917 | document = change.state.document;
|
30918 | var ancestor = document.getCommonAncestor(startKey, endKey);
|
30919 | var startChild = ancestor.getFurthestAncestor(startKey);
|
30920 | var endChild = ancestor.getFurthestAncestor(endKey);
|
30921 | change.splitDescendantsByKey(startChild.key, startKey, startOffset, { normalize: false });
|
30922 | change.splitDescendantsByKey(endChild.key, endKey, endOffset, { normalize: false });
|
30923 |
|
30924 | // Refresh the variables after the split.
|
30925 | document = change.state.document;
|
30926 | ancestor = document.getCommonAncestor(startKey, endKey);
|
30927 | startChild = ancestor.getFurthestAncestor(startKey);
|
30928 | endChild = ancestor.getFurthestAncestor(endKey);
|
30929 |
|
30930 | // Determine which are the middle nodes.
|
30931 | var nextText = document.getNextText(endKey);
|
30932 | var startIndex = ancestor.nodes.indexOf(startChild);
|
30933 | var endIndex = ancestor.nodes.indexOf(endChild);
|
30934 | var middles = ancestor.nodes.slice(startIndex + 1, endIndex + 1);
|
30935 | startBlock = document.getClosestBlock(startKey);
|
30936 | endBlock = document.getClosestBlock(nextText.key);
|
30937 |
|
30938 | // Remove all of the middle nodes, between the splits.
|
30939 | middles.forEach(function (child) {
|
30940 | change.removeNodeByKey(child.key, { normalize: false });
|
30941 | });
|
30942 |
|
30943 | // If the start and end blocks are different, and the selection was hanging,
|
30944 | // remove the start block and the orphaned end block.
|
30945 | if (startBlock.key != endBlock.key && isHanging) {
|
30946 | change.removeNodeByKey(startBlock.key, { normalize: false });
|
30947 | change.removeNodeByKey(endBlock.key, { normalize: false });
|
30948 | }
|
30949 |
|
30950 | // Otherwise, move all of the nodes from the end block into the start block.
|
30951 | else if (startBlock.key != endBlock.key) {
|
30952 | endBlock.nodes.forEach(function (child, i) {
|
30953 | var newKey = startBlock.key;
|
30954 | var newIndex = startBlock.nodes.size + i;
|
30955 | change.moveNodeByKey(child.key, newKey, newIndex, { normalize: false });
|
30956 | });
|
30957 |
|
30958 | // Remove parents of endBlock as long as they have a single child.
|
30959 | var lonely = document.getFurthestOnlyChildAncestor(endBlock.key) || endBlock;
|
30960 | change.removeNodeByKey(lonely.key, { normalize: false });
|
30961 | }
|
30962 |
|
30963 | if (normalize) {
|
30964 | change.normalizeNodeByKey(ancestor.key, _core2.default);
|
30965 | }
|
30966 | };
|
30967 |
|
30968 | /**
|
30969 | * Delete backward until the character boundary at a `range`.
|
30970 | *
|
30971 | * @param {Change} change
|
30972 | * @param {Selection} range
|
30973 | * @param {Object} options
|
30974 | * @property {Boolean} normalize
|
30975 | */
|
30976 |
|
30977 | Changes.deleteCharBackwardAtRange = function (change, range, options) {
|
30978 | var state = change.state;
|
30979 | var document = state.document;
|
30980 | var startKey = range.startKey,
|
30981 | startOffset = range.startOffset;
|
30982 |
|
30983 | var startBlock = document.getClosestBlock(startKey);
|
30984 | var offset = startBlock.getOffset(startKey);
|
30985 | var o = offset + startOffset;
|
30986 | var text = startBlock.text;
|
30987 |
|
30988 | var n = _string2.default.getCharOffsetBackward(text, o);
|
30989 | change.deleteBackwardAtRange(range, n, options);
|
30990 | };
|
30991 |
|
30992 | /**
|
30993 | * Delete backward until the line boundary at a `range`.
|
30994 | *
|
30995 | * @param {Change} change
|
30996 | * @param {Selection} range
|
30997 | * @param {Object} options
|
30998 | * @property {Boolean} normalize
|
30999 | */
|
31000 |
|
31001 | Changes.deleteLineBackwardAtRange = function (change, range, options) {
|
31002 | var state = change.state;
|
31003 | var document = state.document;
|
31004 | var startKey = range.startKey,
|
31005 | startOffset = range.startOffset;
|
31006 |
|
31007 | var startBlock = document.getClosestBlock(startKey);
|
31008 | var offset = startBlock.getOffset(startKey);
|
31009 | var o = offset + startOffset;
|
31010 | change.deleteBackwardAtRange(range, o, options);
|
31011 | };
|
31012 |
|
31013 | /**
|
31014 | * Delete backward until the word boundary at a `range`.
|
31015 | *
|
31016 | * @param {Change} change
|
31017 | * @param {Selection} range
|
31018 | * @param {Object} options
|
31019 | * @property {Boolean} normalize
|
31020 | */
|
31021 |
|
31022 | Changes.deleteWordBackwardAtRange = function (change, range, options) {
|
31023 | var state = change.state;
|
31024 | var document = state.document;
|
31025 | var startKey = range.startKey,
|
31026 | startOffset = range.startOffset;
|
31027 |
|
31028 | var startBlock = document.getClosestBlock(startKey);
|
31029 | var offset = startBlock.getOffset(startKey);
|
31030 | var o = offset + startOffset;
|
31031 | var text = startBlock.text;
|
31032 |
|
31033 | var n = _string2.default.getWordOffsetBackward(text, o);
|
31034 | change.deleteBackwardAtRange(range, n, options);
|
31035 | };
|
31036 |
|
31037 | /**
|
31038 | * Delete backward `n` characters at a `range`.
|
31039 | *
|
31040 | * @param {Change} change
|
31041 | * @param {Selection} range
|
31042 | * @param {Number} n (optional)
|
31043 | * @param {Object} options
|
31044 | * @property {Boolean} normalize
|
31045 | */
|
31046 |
|
31047 | Changes.deleteBackwardAtRange = function (change, range) {
|
31048 | var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
31049 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31050 | var _options$normalize3 = options.normalize,
|
31051 | normalize = _options$normalize3 === undefined ? true : _options$normalize3;
|
31052 | var state = change.state;
|
31053 | var document = state.document;
|
31054 | var _range = range,
|
31055 | startKey = _range.startKey,
|
31056 | focusOffset = _range.focusOffset;
|
31057 |
|
31058 | // If the range is expanded, perform a regular delete instead.
|
31059 |
|
31060 | if (range.isExpanded) {
|
31061 | change.deleteAtRange(range, { normalize: normalize });
|
31062 | return;
|
31063 | }
|
31064 |
|
31065 | var block = document.getClosestBlock(startKey);
|
31066 |
|
31067 | // If the closest block is void, delete it.
|
31068 | if (block && block.isVoid) {
|
31069 | change.removeNodeByKey(block.key, { normalize: normalize });
|
31070 | return;
|
31071 | }
|
31072 |
|
31073 | // If the closest is not void, but empty, remove it
|
31074 | if (block && !block.isVoid && block.isEmpty && document.nodes.size !== 1) {
|
31075 | change.removeNodeByKey(block.key, { normalize: normalize });
|
31076 | return;
|
31077 | }
|
31078 |
|
31079 | // If the closest inline is void, delete it.
|
31080 | var inline = document.getClosestInline(startKey);
|
31081 | if (inline && inline.isVoid) {
|
31082 | change.removeNodeByKey(inline.key, { normalize: normalize });
|
31083 | return;
|
31084 | }
|
31085 |
|
31086 | // If the range is at the start of the document, abort.
|
31087 | if (range.isAtStartOf(document)) {
|
31088 | return;
|
31089 | }
|
31090 |
|
31091 | // If the range is at the start of the text node, we need to figure out what
|
31092 | // is behind it to know how to delete...
|
31093 | var text = document.getDescendant(startKey);
|
31094 | if (range.isAtStartOf(text)) {
|
31095 | var prev = document.getPreviousText(text.key);
|
31096 | var prevBlock = document.getClosestBlock(prev.key);
|
31097 | var prevInline = document.getClosestInline(prev.key);
|
31098 |
|
31099 | // If the previous block is void, remove it.
|
31100 | if (prevBlock && prevBlock.isVoid) {
|
31101 | change.removeNodeByKey(prevBlock.key, { normalize: normalize });
|
31102 | return;
|
31103 | }
|
31104 |
|
31105 | // If the previous inline is void, remove it.
|
31106 | if (prevInline && prevInline.isVoid) {
|
31107 | change.removeNodeByKey(prevInline.key, { normalize: normalize });
|
31108 | return;
|
31109 | }
|
31110 |
|
31111 | // If we're deleting by one character and the previous text node is not
|
31112 | // inside the current block, we need to merge the two blocks together.
|
31113 | if (n == 1 && prevBlock != block) {
|
31114 | range = range.merge({
|
31115 | anchorKey: prev.key,
|
31116 | anchorOffset: prev.text.length
|
31117 | });
|
31118 |
|
31119 | change.deleteAtRange(range, { normalize: normalize });
|
31120 | return;
|
31121 | }
|
31122 | }
|
31123 |
|
31124 | // If the focus offset is farther than the number of characters to delete,
|
31125 | // just remove the characters backwards inside the current node.
|
31126 | if (n < focusOffset) {
|
31127 | range = range.merge({
|
31128 | focusOffset: focusOffset - n,
|
31129 | isBackward: true
|
31130 | });
|
31131 |
|
31132 | change.deleteAtRange(range, { normalize: normalize });
|
31133 | return;
|
31134 | }
|
31135 |
|
31136 | // Otherwise, we need to see how many nodes backwards to go.
|
31137 | var node = text;
|
31138 | var offset = 0;
|
31139 | var traversed = focusOffset;
|
31140 |
|
31141 | while (n > traversed) {
|
31142 | node = document.getPreviousText(node.key);
|
31143 | var next = traversed + node.text.length;
|
31144 | if (n <= next) {
|
31145 | offset = next - n;
|
31146 | break;
|
31147 | } else {
|
31148 | traversed = next;
|
31149 | }
|
31150 | }
|
31151 |
|
31152 | // If the focus node is inside a void, go up until right after it.
|
31153 | if (document.hasVoidParent(node.key)) {
|
31154 | var parent = document.getClosestVoid(node.key);
|
31155 | node = document.getNextText(parent.key);
|
31156 | offset = 0;
|
31157 | }
|
31158 |
|
31159 | range = range.merge({
|
31160 | focusKey: node.key,
|
31161 | focusOffset: offset,
|
31162 | isBackward: true
|
31163 | });
|
31164 |
|
31165 | change.deleteAtRange(range, { normalize: normalize });
|
31166 | };
|
31167 |
|
31168 | /**
|
31169 | * Delete forward until the character boundary at a `range`.
|
31170 | *
|
31171 | * @param {Change} change
|
31172 | * @param {Selection} range
|
31173 | * @param {Object} options
|
31174 | * @property {Boolean} normalize
|
31175 | */
|
31176 |
|
31177 | Changes.deleteCharForwardAtRange = function (change, range, options) {
|
31178 | var state = change.state;
|
31179 | var document = state.document;
|
31180 | var startKey = range.startKey,
|
31181 | startOffset = range.startOffset;
|
31182 |
|
31183 | var startBlock = document.getClosestBlock(startKey);
|
31184 | var offset = startBlock.getOffset(startKey);
|
31185 | var o = offset + startOffset;
|
31186 | var text = startBlock.text;
|
31187 |
|
31188 | var n = _string2.default.getCharOffsetForward(text, o);
|
31189 | change.deleteForwardAtRange(range, n, options);
|
31190 | };
|
31191 |
|
31192 | /**
|
31193 | * Delete forward until the line boundary at a `range`.
|
31194 | *
|
31195 | * @param {Change} change
|
31196 | * @param {Selection} range
|
31197 | * @param {Object} options
|
31198 | * @property {Boolean} normalize
|
31199 | */
|
31200 |
|
31201 | Changes.deleteLineForwardAtRange = function (change, range, options) {
|
31202 | var state = change.state;
|
31203 | var document = state.document;
|
31204 | var startKey = range.startKey,
|
31205 | startOffset = range.startOffset;
|
31206 |
|
31207 | var startBlock = document.getClosestBlock(startKey);
|
31208 | var offset = startBlock.getOffset(startKey);
|
31209 | var o = offset + startOffset;
|
31210 | change.deleteForwardAtRange(range, o, options);
|
31211 | };
|
31212 |
|
31213 | /**
|
31214 | * Delete forward until the word boundary at a `range`.
|
31215 | *
|
31216 | * @param {Change} change
|
31217 | * @param {Selection} range
|
31218 | * @param {Object} options
|
31219 | * @property {Boolean} normalize
|
31220 | */
|
31221 |
|
31222 | Changes.deleteWordForwardAtRange = function (change, range, options) {
|
31223 | var state = change.state;
|
31224 | var document = state.document;
|
31225 | var startKey = range.startKey,
|
31226 | startOffset = range.startOffset;
|
31227 |
|
31228 | var startBlock = document.getClosestBlock(startKey);
|
31229 | var offset = startBlock.getOffset(startKey);
|
31230 | var o = offset + startOffset;
|
31231 | var text = startBlock.text;
|
31232 |
|
31233 | var n = _string2.default.getWordOffsetForward(text, o);
|
31234 | change.deleteForwardAtRange(range, n, options);
|
31235 | };
|
31236 |
|
31237 | /**
|
31238 | * Delete forward `n` characters at a `range`.
|
31239 | *
|
31240 | * @param {Change} change
|
31241 | * @param {Selection} range
|
31242 | * @param {Number} n (optional)
|
31243 | * @param {Object} options
|
31244 | * @property {Boolean} normalize
|
31245 | */
|
31246 |
|
31247 | Changes.deleteForwardAtRange = function (change, range) {
|
31248 | var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
31249 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31250 | var _options$normalize4 = options.normalize,
|
31251 | normalize = _options$normalize4 === undefined ? true : _options$normalize4;
|
31252 | var state = change.state;
|
31253 | var document = state.document;
|
31254 | var _range2 = range,
|
31255 | startKey = _range2.startKey,
|
31256 | focusOffset = _range2.focusOffset;
|
31257 |
|
31258 | // If the range is expanded, perform a regular delete instead.
|
31259 |
|
31260 | if (range.isExpanded) {
|
31261 | change.deleteAtRange(range, { normalize: normalize });
|
31262 | return;
|
31263 | }
|
31264 |
|
31265 | var block = document.getClosestBlock(startKey);
|
31266 |
|
31267 | // If the closest block is void, delete it.
|
31268 | if (block && block.isVoid) {
|
31269 | change.removeNodeByKey(block.key, { normalize: normalize });
|
31270 | return;
|
31271 | }
|
31272 |
|
31273 | // If the closest is not void, but empty, remove it
|
31274 | if (block && !block.isVoid && block.isEmpty && document.nodes.size !== 1) {
|
31275 | change.removeNodeByKey(block.key, { normalize: normalize });
|
31276 | return;
|
31277 | }
|
31278 |
|
31279 | // If the closest inline is void, delete it.
|
31280 | var inline = document.getClosestInline(startKey);
|
31281 | if (inline && inline.isVoid) {
|
31282 | change.removeNodeByKey(inline.key, { normalize: normalize });
|
31283 | return;
|
31284 | }
|
31285 |
|
31286 | // If the range is at the start of the document, abort.
|
31287 | if (range.isAtEndOf(document)) {
|
31288 | return;
|
31289 | }
|
31290 |
|
31291 | // If the range is at the start of the text node, we need to figure out what
|
31292 | // is behind it to know how to delete...
|
31293 | var text = document.getDescendant(startKey);
|
31294 | if (range.isAtEndOf(text)) {
|
31295 | var next = document.getNextText(text.key);
|
31296 | var nextBlock = document.getClosestBlock(next.key);
|
31297 | var nextInline = document.getClosestInline(next.key);
|
31298 |
|
31299 | // If the previous block is void, remove it.
|
31300 | if (nextBlock && nextBlock.isVoid) {
|
31301 | change.removeNodeByKey(nextBlock.key, { normalize: normalize });
|
31302 | return;
|
31303 | }
|
31304 |
|
31305 | // If the previous inline is void, remove it.
|
31306 | if (nextInline && nextInline.isVoid) {
|
31307 | change.removeNodeByKey(nextInline.key, { normalize: normalize });
|
31308 | return;
|
31309 | }
|
31310 |
|
31311 | // If we're deleting by one character and the previous text node is not
|
31312 | // inside the current block, we need to merge the two blocks together.
|
31313 | if (n == 1 && nextBlock != block) {
|
31314 | range = range.merge({
|
31315 | focusKey: next.key,
|
31316 | focusOffset: 0
|
31317 | });
|
31318 |
|
31319 | change.deleteAtRange(range, { normalize: normalize });
|
31320 | return;
|
31321 | }
|
31322 | }
|
31323 |
|
31324 | // If the remaining characters to the end of the node is greater than or equal
|
31325 | // to the number of characters to delete, just remove the characters forwards
|
31326 | // inside the current node.
|
31327 | if (n <= text.text.length - focusOffset) {
|
31328 | range = range.merge({
|
31329 | focusOffset: focusOffset + n
|
31330 | });
|
31331 |
|
31332 | change.deleteAtRange(range, { normalize: normalize });
|
31333 | return;
|
31334 | }
|
31335 |
|
31336 | // Otherwise, we need to see how many nodes forwards to go.
|
31337 | var node = text;
|
31338 | var offset = focusOffset;
|
31339 | var traversed = text.text.length - focusOffset;
|
31340 |
|
31341 | while (n > traversed) {
|
31342 | node = document.getNextText(node.key);
|
31343 | var _next = traversed + node.text.length;
|
31344 | if (n <= _next) {
|
31345 | offset = n - traversed;
|
31346 | break;
|
31347 | } else {
|
31348 | traversed = _next;
|
31349 | }
|
31350 | }
|
31351 |
|
31352 | // If the focus node is inside a void, go up until right before it.
|
31353 | if (document.hasVoidParent(node.key)) {
|
31354 | var parent = document.getClosestVoid(node.key);
|
31355 | node = document.getPreviousText(parent.key);
|
31356 | offset = node.text.length;
|
31357 | }
|
31358 |
|
31359 | range = range.merge({
|
31360 | focusKey: node.key,
|
31361 | focusOffset: offset
|
31362 | });
|
31363 |
|
31364 | change.deleteAtRange(range, { normalize: normalize });
|
31365 | };
|
31366 |
|
31367 | /**
|
31368 | * Insert a `block` node at `range`.
|
31369 | *
|
31370 | * @param {Change} change
|
31371 | * @param {Selection} range
|
31372 | * @param {Block|String|Object} block
|
31373 | * @param {Object} options
|
31374 | * @property {Boolean} normalize
|
31375 | */
|
31376 |
|
31377 | Changes.insertBlockAtRange = function (change, range, block) {
|
31378 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31379 |
|
31380 | block = _block2.default.create(block);
|
31381 | var _options$normalize5 = options.normalize,
|
31382 | normalize = _options$normalize5 === undefined ? true : _options$normalize5;
|
31383 |
|
31384 |
|
31385 | if (range.isExpanded) {
|
31386 | change.deleteAtRange(range);
|
31387 | range = range.collapseToStart();
|
31388 | }
|
31389 |
|
31390 | var state = change.state;
|
31391 | var document = state.document;
|
31392 | var _range3 = range,
|
31393 | startKey = _range3.startKey,
|
31394 | startOffset = _range3.startOffset;
|
31395 |
|
31396 | var startBlock = document.getClosestBlock(startKey);
|
31397 | var parent = document.getParent(startBlock.key);
|
31398 | var index = parent.nodes.indexOf(startBlock);
|
31399 |
|
31400 | if (startBlock.isVoid) {
|
31401 | var extra = range.isAtEndOf(startBlock) ? 1 : 0;
|
31402 | change.insertNodeByKey(parent.key, index + extra, block, { normalize: normalize });
|
31403 | } else if (startBlock.isEmpty) {
|
31404 | change.removeNodeByKey(startBlock.key);
|
31405 | change.insertNodeByKey(parent.key, index, block, { normalize: normalize });
|
31406 | } else if (range.isAtStartOf(startBlock)) {
|
31407 | change.insertNodeByKey(parent.key, index, block, { normalize: normalize });
|
31408 | } else if (range.isAtEndOf(startBlock)) {
|
31409 | change.insertNodeByKey(parent.key, index + 1, block, { normalize: normalize });
|
31410 | } else {
|
31411 | change.splitDescendantsByKey(startBlock.key, startKey, startOffset, { normalize: false });
|
31412 | change.insertNodeByKey(parent.key, index + 1, block, { normalize: normalize });
|
31413 | }
|
31414 |
|
31415 | if (normalize) {
|
31416 | change.normalizeNodeByKey(parent.key, _core2.default);
|
31417 | }
|
31418 | };
|
31419 |
|
31420 | /**
|
31421 | * Insert a `fragment` at a `range`.
|
31422 | *
|
31423 | * @param {Change} change
|
31424 | * @param {Selection} range
|
31425 | * @param {Document} fragment
|
31426 | * @param {Object} options
|
31427 | * @property {Boolean} normalize
|
31428 | */
|
31429 |
|
31430 | Changes.insertFragmentAtRange = function (change, range, fragment) {
|
31431 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31432 | var _options$normalize6 = options.normalize,
|
31433 | normalize = _options$normalize6 === undefined ? true : _options$normalize6;
|
31434 |
|
31435 | // If the range is expanded, delete it first.
|
31436 |
|
31437 | if (range.isExpanded) {
|
31438 | change.deleteAtRange(range, { normalize: false });
|
31439 | range = range.collapseToStart();
|
31440 | }
|
31441 |
|
31442 | // If the fragment is empty, there's nothing to do after deleting.
|
31443 | if (!fragment.nodes.size) return;
|
31444 |
|
31445 | // Regenerate the keys for all of the fragments nodes, so that they're
|
31446 | // guaranteed not to collide with the existing keys in the document. Otherwise
|
31447 | // they will be rengerated automatically and we won't have an easy way to
|
31448 | // reference them.
|
31449 | fragment = fragment.mapDescendants(function (child) {
|
31450 | return child.regenerateKey();
|
31451 | });
|
31452 |
|
31453 | // Calculate a few things...
|
31454 | var _range4 = range,
|
31455 | startKey = _range4.startKey,
|
31456 | startOffset = _range4.startOffset;
|
31457 | var state = change.state;
|
31458 | var document = state.document;
|
31459 |
|
31460 | var startText = document.getDescendant(startKey);
|
31461 | var startBlock = document.getClosestBlock(startText.key);
|
31462 | var startChild = startBlock.getFurthestAncestor(startText.key);
|
31463 | var isAtStart = range.isAtStartOf(startBlock);
|
31464 | var parent = document.getParent(startBlock.key);
|
31465 | var index = parent.nodes.indexOf(startBlock);
|
31466 | var blocks = fragment.getBlocks();
|
31467 | var firstBlock = blocks.first();
|
31468 | var lastBlock = blocks.last();
|
31469 |
|
31470 | // If the fragment only contains a void block, use `insertBlock` instead.
|
31471 | if (firstBlock == lastBlock && firstBlock.isVoid) {
|
31472 | change.insertBlockAtRange(range, firstBlock, options);
|
31473 | return;
|
31474 | }
|
31475 |
|
31476 | // If the first and last block aren't the same, we need to insert all of the
|
31477 | // nodes after the fragment's first block at the index.
|
31478 | if (firstBlock != lastBlock) {
|
31479 | var lonelyParent = fragment.getFurthest(firstBlock.key, function (p) {
|
31480 | return p.nodes.size == 1;
|
31481 | });
|
31482 | var lonelyChild = lonelyParent || firstBlock;
|
31483 | var startIndex = parent.nodes.indexOf(startBlock);
|
31484 | fragment = fragment.removeDescendant(lonelyChild.key);
|
31485 |
|
31486 | fragment.nodes.forEach(function (node, i) {
|
31487 | var newIndex = startIndex + i + 1;
|
31488 | change.insertNodeByKey(parent.key, newIndex, node, { normalize: false });
|
31489 | });
|
31490 | }
|
31491 |
|
31492 | // Check if we need to split the node.
|
31493 | if (startOffset != 0) {
|
31494 | change.splitDescendantsByKey(startChild.key, startKey, startOffset, { normalize: false });
|
31495 | }
|
31496 |
|
31497 | // Update our variables with the new state.
|
31498 | document = change.state.document;
|
31499 | startText = document.getDescendant(startKey);
|
31500 | startBlock = document.getClosestBlock(startKey);
|
31501 | startChild = startBlock.getFurthestAncestor(startText.key);
|
31502 |
|
31503 | // If the first and last block aren't the same, we need to move any of the
|
31504 | // starting block's children after the split into the last block of the
|
31505 | // fragment, which has already been inserted.
|
31506 | if (firstBlock != lastBlock) {
|
31507 | var nextChild = isAtStart ? startChild : startBlock.getNextSibling(startChild.key);
|
31508 | var nextNodes = nextChild ? startBlock.nodes.skipUntil(function (n) {
|
31509 | return n.key == nextChild.key;
|
31510 | }) : (0, _immutable.List)();
|
31511 | var lastIndex = lastBlock.nodes.size;
|
31512 |
|
31513 | nextNodes.forEach(function (node, i) {
|
31514 | var newIndex = lastIndex + i;
|
31515 | change.moveNodeByKey(node.key, lastBlock.key, newIndex, { normalize: false });
|
31516 | });
|
31517 | }
|
31518 |
|
31519 | // If the starting block is empty, we replace it entirely with the first block
|
31520 | // of the fragment, since this leads to a more expected behavior for the user.
|
31521 | if (startBlock.isEmpty) {
|
31522 | change.removeNodeByKey(startBlock.key, { normalize: false });
|
31523 | change.insertNodeByKey(parent.key, index, firstBlock, { normalize: false });
|
31524 | }
|
31525 |
|
31526 | // Otherwise, we maintain the starting block, and insert all of the first
|
31527 | // block's inline nodes into it at the split point.
|
31528 | else {
|
31529 | var inlineChild = startBlock.getFurthestAncestor(startText.key);
|
31530 | var inlineIndex = startBlock.nodes.indexOf(inlineChild);
|
31531 |
|
31532 | firstBlock.nodes.forEach(function (inline, i) {
|
31533 | var o = startOffset == 0 ? 0 : 1;
|
31534 | var newIndex = inlineIndex + i + o;
|
31535 | change.insertNodeByKey(startBlock.key, newIndex, inline, { normalize: false });
|
31536 | });
|
31537 | }
|
31538 |
|
31539 | // Normalize if requested.
|
31540 | if (normalize) {
|
31541 | change.normalizeNodeByKey(parent.key, _core2.default);
|
31542 | }
|
31543 | };
|
31544 |
|
31545 | /**
|
31546 | * Insert an `inline` node at `range`.
|
31547 | *
|
31548 | * @param {Change} change
|
31549 | * @param {Selection} range
|
31550 | * @param {Inline|String|Object} inline
|
31551 | * @param {Object} options
|
31552 | * @property {Boolean} normalize
|
31553 | */
|
31554 |
|
31555 | Changes.insertInlineAtRange = function (change, range, inline) {
|
31556 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31557 | var _options$normalize7 = options.normalize,
|
31558 | normalize = _options$normalize7 === undefined ? true : _options$normalize7;
|
31559 |
|
31560 | inline = _inline2.default.create(inline);
|
31561 |
|
31562 | if (range.isExpanded) {
|
31563 | change.deleteAtRange(range, { normalize: false });
|
31564 | range = range.collapseToStart();
|
31565 | }
|
31566 |
|
31567 | var state = change.state;
|
31568 | var document = state.document;
|
31569 | var _range5 = range,
|
31570 | startKey = _range5.startKey,
|
31571 | startOffset = _range5.startOffset;
|
31572 |
|
31573 | var parent = document.getParent(startKey);
|
31574 | var startText = document.assertDescendant(startKey);
|
31575 | var index = parent.nodes.indexOf(startText);
|
31576 |
|
31577 | if (parent.isVoid) return;
|
31578 |
|
31579 | change.splitNodeByKey(startKey, startOffset, { normalize: false });
|
31580 | change.insertNodeByKey(parent.key, index + 1, inline, { normalize: false });
|
31581 |
|
31582 | if (normalize) {
|
31583 | change.normalizeNodeByKey(parent.key, _core2.default);
|
31584 | }
|
31585 | };
|
31586 |
|
31587 | /**
|
31588 | * Insert `text` at a `range`, with optional `marks`.
|
31589 | *
|
31590 | * @param {Change} change
|
31591 | * @param {Selection} range
|
31592 | * @param {String} text
|
31593 | * @param {Set<Mark>} marks (optional)
|
31594 | * @param {Object} options
|
31595 | * @property {Boolean} normalize
|
31596 | */
|
31597 |
|
31598 | Changes.insertTextAtRange = function (change, range, text, marks) {
|
31599 | var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
31600 | var normalize = options.normalize;
|
31601 | var state = change.state;
|
31602 | var document = state.document;
|
31603 | var startKey = range.startKey,
|
31604 | startOffset = range.startOffset;
|
31605 |
|
31606 | var parent = document.getParent(startKey);
|
31607 |
|
31608 | if (parent.isVoid) return;
|
31609 |
|
31610 | if (range.isExpanded) {
|
31611 | change.deleteAtRange(range, { normalize: false });
|
31612 | }
|
31613 |
|
31614 | // PERF: Unless specified, don't normalize if only inserting text.
|
31615 | if (normalize !== undefined) {
|
31616 | normalize = range.isExpanded;
|
31617 | }
|
31618 |
|
31619 | change.insertTextByKey(startKey, startOffset, text, marks, { normalize: normalize });
|
31620 | };
|
31621 |
|
31622 | /**
|
31623 | * Remove an existing `mark` to the characters at `range`.
|
31624 | *
|
31625 | * @param {Change} change
|
31626 | * @param {Selection} range
|
31627 | * @param {Mark|String} mark (optional)
|
31628 | * @param {Object} options
|
31629 | * @property {Boolean} normalize
|
31630 | */
|
31631 |
|
31632 | Changes.removeMarkAtRange = function (change, range, mark) {
|
31633 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31634 |
|
31635 | if (range.isCollapsed) return;
|
31636 |
|
31637 | var _options$normalize8 = options.normalize,
|
31638 | normalize = _options$normalize8 === undefined ? true : _options$normalize8;
|
31639 | var state = change.state;
|
31640 | var document = state.document;
|
31641 |
|
31642 | var texts = document.getTextsAtRange(range);
|
31643 | var startKey = range.startKey,
|
31644 | startOffset = range.startOffset,
|
31645 | endKey = range.endKey,
|
31646 | endOffset = range.endOffset;
|
31647 |
|
31648 |
|
31649 | texts.forEach(function (node) {
|
31650 | var key = node.key;
|
31651 |
|
31652 | var index = 0;
|
31653 | var length = node.text.length;
|
31654 |
|
31655 | if (key == startKey) index = startOffset;
|
31656 | if (key == endKey) length = endOffset;
|
31657 | if (key == startKey && key == endKey) length = endOffset - startOffset;
|
31658 |
|
31659 | change.removeMarkByKey(key, index, length, mark, { normalize: normalize });
|
31660 | });
|
31661 | };
|
31662 |
|
31663 | /**
|
31664 | * Set the `properties` of block nodes in a `range`.
|
31665 | *
|
31666 | * @param {Change} change
|
31667 | * @param {Selection} range
|
31668 | * @param {Object|String} properties
|
31669 | * @param {Object} options
|
31670 | * @property {Boolean} normalize
|
31671 | */
|
31672 |
|
31673 | Changes.setBlockAtRange = function (change, range, properties) {
|
31674 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31675 | var _options$normalize9 = options.normalize,
|
31676 | normalize = _options$normalize9 === undefined ? true : _options$normalize9;
|
31677 | var state = change.state;
|
31678 | var document = state.document;
|
31679 |
|
31680 | var blocks = document.getBlocksAtRange(range);
|
31681 |
|
31682 | blocks.forEach(function (block) {
|
31683 | change.setNodeByKey(block.key, properties, { normalize: normalize });
|
31684 | });
|
31685 | };
|
31686 |
|
31687 | /**
|
31688 | * Set the `properties` of inline nodes in a `range`.
|
31689 | *
|
31690 | * @param {Change} change
|
31691 | * @param {Selection} range
|
31692 | * @param {Object|String} properties
|
31693 | * @param {Object} options
|
31694 | * @property {Boolean} normalize
|
31695 | */
|
31696 |
|
31697 | Changes.setInlineAtRange = function (change, range, properties) {
|
31698 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31699 | var _options$normalize10 = options.normalize,
|
31700 | normalize = _options$normalize10 === undefined ? true : _options$normalize10;
|
31701 | var state = change.state;
|
31702 | var document = state.document;
|
31703 |
|
31704 | var inlines = document.getInlinesAtRange(range);
|
31705 |
|
31706 | inlines.forEach(function (inline) {
|
31707 | change.setNodeByKey(inline.key, properties, { normalize: normalize });
|
31708 | });
|
31709 | };
|
31710 |
|
31711 | /**
|
31712 | * Split the block nodes at a `range`, to optional `height`.
|
31713 | *
|
31714 | * @param {Change} change
|
31715 | * @param {Selection} range
|
31716 | * @param {Number} height (optional)
|
31717 | * @param {Object} options
|
31718 | * @property {Boolean} normalize
|
31719 | */
|
31720 |
|
31721 | Changes.splitBlockAtRange = function (change, range) {
|
31722 | var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
31723 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31724 | var _options$normalize11 = options.normalize,
|
31725 | normalize = _options$normalize11 === undefined ? true : _options$normalize11;
|
31726 |
|
31727 |
|
31728 | if (range.isExpanded) {
|
31729 | change.deleteAtRange(range, { normalize: normalize });
|
31730 | range = range.collapseToStart();
|
31731 | }
|
31732 |
|
31733 | var _range6 = range,
|
31734 | startKey = _range6.startKey,
|
31735 | startOffset = _range6.startOffset;
|
31736 | var state = change.state;
|
31737 | var document = state.document;
|
31738 |
|
31739 | var node = document.assertDescendant(startKey);
|
31740 | var parent = document.getClosestBlock(node.key);
|
31741 | var h = 0;
|
31742 |
|
31743 | while (parent && parent.kind == 'block' && h < height) {
|
31744 | node = parent;
|
31745 | parent = document.getClosestBlock(parent.key);
|
31746 | h++;
|
31747 | }
|
31748 |
|
31749 | change.splitDescendantsByKey(node.key, startKey, startOffset, { normalize: normalize });
|
31750 | };
|
31751 |
|
31752 | /**
|
31753 | * Split the inline nodes at a `range`, to optional `height`.
|
31754 | *
|
31755 | * @param {Change} change
|
31756 | * @param {Selection} range
|
31757 | * @param {Number} height (optional)
|
31758 | * @param {Object} options
|
31759 | * @property {Boolean} normalize
|
31760 | */
|
31761 |
|
31762 | Changes.splitInlineAtRange = function (change, range) {
|
31763 | var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
|
31764 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31765 | var _options$normalize12 = options.normalize,
|
31766 | normalize = _options$normalize12 === undefined ? true : _options$normalize12;
|
31767 |
|
31768 |
|
31769 | if (range.isExpanded) {
|
31770 | change.deleteAtRange(range, { normalize: normalize });
|
31771 | range = range.collapseToStart();
|
31772 | }
|
31773 |
|
31774 | var _range7 = range,
|
31775 | startKey = _range7.startKey,
|
31776 | startOffset = _range7.startOffset;
|
31777 | var state = change.state;
|
31778 | var document = state.document;
|
31779 |
|
31780 | var node = document.assertDescendant(startKey);
|
31781 | var parent = document.getClosestInline(node.key);
|
31782 | var h = 0;
|
31783 |
|
31784 | while (parent && parent.kind == 'inline' && h < height) {
|
31785 | node = parent;
|
31786 | parent = document.getClosestInline(parent.key);
|
31787 | h++;
|
31788 | }
|
31789 |
|
31790 | change.splitDescendantsByKey(node.key, startKey, startOffset, { normalize: normalize });
|
31791 | };
|
31792 |
|
31793 | /**
|
31794 | * Add or remove a `mark` from the characters at `range`, depending on whether
|
31795 | * it's already there.
|
31796 | *
|
31797 | * @param {Change} change
|
31798 | * @param {Selection} range
|
31799 | * @param {Mixed} mark
|
31800 | * @param {Object} options
|
31801 | * @property {Boolean} normalize
|
31802 | */
|
31803 |
|
31804 | Changes.toggleMarkAtRange = function (change, range, mark) {
|
31805 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31806 |
|
31807 | if (range.isCollapsed) return;
|
31808 |
|
31809 | mark = _mark2.default.create(mark);
|
31810 |
|
31811 | var _options$normalize13 = options.normalize,
|
31812 | normalize = _options$normalize13 === undefined ? true : _options$normalize13;
|
31813 | var state = change.state;
|
31814 | var document = state.document;
|
31815 |
|
31816 | var marks = document.getActiveMarksAtRange(range);
|
31817 | var exists = marks.some(function (m) {
|
31818 | return m.equals(mark);
|
31819 | });
|
31820 |
|
31821 | if (exists) {
|
31822 | change.removeMarkAtRange(range, mark, { normalize: normalize });
|
31823 | } else {
|
31824 | change.addMarkAtRange(range, mark, { normalize: normalize });
|
31825 | }
|
31826 | };
|
31827 |
|
31828 | /**
|
31829 | * Unwrap all of the block nodes in a `range` from a block with `properties`.
|
31830 | *
|
31831 | * @param {Change} change
|
31832 | * @param {Selection} range
|
31833 | * @param {String|Object} properties
|
31834 | * @param {Object} options
|
31835 | * @property {Boolean} normalize
|
31836 | */
|
31837 |
|
31838 | Changes.unwrapBlockAtRange = function (change, range, properties) {
|
31839 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31840 |
|
31841 | properties = _node2.default.createProperties(properties);
|
31842 |
|
31843 | var _options$normalize14 = options.normalize,
|
31844 | normalize = _options$normalize14 === undefined ? true : _options$normalize14;
|
31845 | var state = change.state;
|
31846 | var document = state.document;
|
31847 |
|
31848 | var blocks = document.getBlocksAtRange(range);
|
31849 | var wrappers = blocks.map(function (block) {
|
31850 | return document.getClosest(block.key, function (parent) {
|
31851 | if (parent.kind != 'block') return false;
|
31852 | if (properties.type != null && parent.type != properties.type) return false;
|
31853 | if (properties.isVoid != null && parent.isVoid != properties.isVoid) return false;
|
31854 | if (properties.data != null && !parent.data.isSuperset(properties.data)) return false;
|
31855 | return true;
|
31856 | });
|
31857 | }).filter(function (exists) {
|
31858 | return exists;
|
31859 | }).toOrderedSet().toList();
|
31860 |
|
31861 | wrappers.forEach(function (block) {
|
31862 | var first = block.nodes.first();
|
31863 | var last = block.nodes.last();
|
31864 | var parent = document.getParent(block.key);
|
31865 | var index = parent.nodes.indexOf(block);
|
31866 |
|
31867 | var children = block.nodes.filter(function (child) {
|
31868 | return blocks.some(function (b) {
|
31869 | return child == b || child.hasDescendant(b.key);
|
31870 | });
|
31871 | });
|
31872 |
|
31873 | var firstMatch = children.first();
|
31874 | var lastMatch = children.last();
|
31875 |
|
31876 | if (first == firstMatch && last == lastMatch) {
|
31877 | block.nodes.forEach(function (child, i) {
|
31878 | change.moveNodeByKey(child.key, parent.key, index + i, { normalize: false });
|
31879 | });
|
31880 |
|
31881 | change.removeNodeByKey(block.key, { normalize: false });
|
31882 | } else if (last == lastMatch) {
|
31883 | block.nodes.skipUntil(function (n) {
|
31884 | return n == firstMatch;
|
31885 | }).forEach(function (child, i) {
|
31886 | change.moveNodeByKey(child.key, parent.key, index + 1 + i, { normalize: false });
|
31887 | });
|
31888 | } else if (first == firstMatch) {
|
31889 | block.nodes.takeUntil(function (n) {
|
31890 | return n == lastMatch;
|
31891 | }).push(lastMatch).forEach(function (child, i) {
|
31892 | change.moveNodeByKey(child.key, parent.key, index + i, { normalize: false });
|
31893 | });
|
31894 | } else {
|
31895 | var firstText = firstMatch.getFirstText();
|
31896 | change.splitDescendantsByKey(block.key, firstText.key, 0, { normalize: false });
|
31897 | document = change.state.document;
|
31898 |
|
31899 | children.forEach(function (child, i) {
|
31900 | if (i == 0) {
|
31901 | var extra = child;
|
31902 | child = document.getNextBlock(child.key);
|
31903 | change.removeNodeByKey(extra.key, { normalize: false });
|
31904 | }
|
31905 |
|
31906 | change.moveNodeByKey(child.key, parent.key, index + 1 + i, { normalize: false });
|
31907 | });
|
31908 | }
|
31909 | });
|
31910 |
|
31911 | // TODO: optmize to only normalize the right block
|
31912 | if (normalize) {
|
31913 | change.normalizeDocument(_core2.default);
|
31914 | }
|
31915 | };
|
31916 |
|
31917 | /**
|
31918 | * Unwrap the inline nodes in a `range` from an inline with `properties`.
|
31919 | *
|
31920 | * @param {Change} change
|
31921 | * @param {Selection} range
|
31922 | * @param {String|Object} properties
|
31923 | * @param {Object} options
|
31924 | * @property {Boolean} normalize
|
31925 | */
|
31926 |
|
31927 | Changes.unwrapInlineAtRange = function (change, range, properties) {
|
31928 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31929 |
|
31930 | properties = _node2.default.createProperties(properties);
|
31931 |
|
31932 | var _options$normalize15 = options.normalize,
|
31933 | normalize = _options$normalize15 === undefined ? true : _options$normalize15;
|
31934 | var state = change.state;
|
31935 | var document = state.document;
|
31936 |
|
31937 | var texts = document.getTextsAtRange(range);
|
31938 | var inlines = texts.map(function (text) {
|
31939 | return document.getClosest(text.key, function (parent) {
|
31940 | if (parent.kind != 'inline') return false;
|
31941 | if (properties.type != null && parent.type != properties.type) return false;
|
31942 | if (properties.isVoid != null && parent.isVoid != properties.isVoid) return false;
|
31943 | if (properties.data != null && !parent.data.isSuperset(properties.data)) return false;
|
31944 | return true;
|
31945 | });
|
31946 | }).filter(function (exists) {
|
31947 | return exists;
|
31948 | }).toOrderedSet().toList();
|
31949 |
|
31950 | inlines.forEach(function (inline) {
|
31951 | var parent = change.state.document.getParent(inline.key);
|
31952 | var index = parent.nodes.indexOf(inline);
|
31953 |
|
31954 | inline.nodes.forEach(function (child, i) {
|
31955 | change.moveNodeByKey(child.key, parent.key, index + i, { normalize: false });
|
31956 | });
|
31957 | });
|
31958 |
|
31959 | // TODO: optmize to only normalize the right block
|
31960 | if (normalize) {
|
31961 | change.normalizeDocument(_core2.default);
|
31962 | }
|
31963 | };
|
31964 |
|
31965 | /**
|
31966 | * Wrap all of the blocks in a `range` in a new `block`.
|
31967 | *
|
31968 | * @param {Change} change
|
31969 | * @param {Selection} range
|
31970 | * @param {Block|Object|String} block
|
31971 | * @param {Object} options
|
31972 | * @property {Boolean} normalize
|
31973 | */
|
31974 |
|
31975 | Changes.wrapBlockAtRange = function (change, range, block) {
|
31976 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
31977 |
|
31978 | block = _block2.default.create(block);
|
31979 | block = block.set('nodes', block.nodes.clear());
|
31980 |
|
31981 | var _options$normalize16 = options.normalize,
|
31982 | normalize = _options$normalize16 === undefined ? true : _options$normalize16;
|
31983 | var state = change.state;
|
31984 | var document = state.document;
|
31985 |
|
31986 |
|
31987 | var blocks = document.getBlocksAtRange(range);
|
31988 | var firstblock = blocks.first();
|
31989 | var lastblock = blocks.last();
|
31990 | var parent = void 0,
|
31991 | siblings = void 0,
|
31992 | index = void 0;
|
31993 |
|
31994 | // If there is only one block in the selection then we know the parent and
|
31995 | // siblings.
|
31996 | if (blocks.length === 1) {
|
31997 | parent = document.getParent(firstblock.key);
|
31998 | siblings = blocks;
|
31999 | }
|
32000 |
|
32001 | // Determine closest shared parent to all blocks in selection.
|
32002 | else {
|
32003 | parent = document.getClosest(firstblock.key, function (p1) {
|
32004 | return !!document.getClosest(lastblock.key, function (p2) {
|
32005 | return p1 == p2;
|
32006 | });
|
32007 | });
|
32008 | }
|
32009 |
|
32010 | // If no shared parent could be found then the parent is the document.
|
32011 | if (parent == null) parent = document;
|
32012 |
|
32013 | // Create a list of direct children siblings of parent that fall in the
|
32014 | // selection.
|
32015 | if (siblings == null) {
|
32016 | var indexes = parent.nodes.reduce(function (ind, node, i) {
|
32017 | if (node == firstblock || node.hasDescendant(firstblock.key)) ind[0] = i;
|
32018 | if (node == lastblock || node.hasDescendant(lastblock.key)) ind[1] = i;
|
32019 | return ind;
|
32020 | }, []);
|
32021 |
|
32022 | index = indexes[0];
|
32023 | siblings = parent.nodes.slice(indexes[0], indexes[1] + 1);
|
32024 | }
|
32025 |
|
32026 | // Get the index to place the new wrapped node at.
|
32027 | if (index == null) {
|
32028 | index = parent.nodes.indexOf(siblings.first());
|
32029 | }
|
32030 |
|
32031 | // Inject the new block node into the parent.
|
32032 | change.insertNodeByKey(parent.key, index, block, { normalize: false });
|
32033 |
|
32034 | // Move the sibling nodes into the new block node.
|
32035 | siblings.forEach(function (node, i) {
|
32036 | change.moveNodeByKey(node.key, block.key, i, { normalize: false });
|
32037 | });
|
32038 |
|
32039 | if (normalize) {
|
32040 | change.normalizeNodeByKey(parent.key, _core2.default);
|
32041 | }
|
32042 | };
|
32043 |
|
32044 | /**
|
32045 | * Wrap the text and inlines in a `range` in a new `inline`.
|
32046 | *
|
32047 | * @param {Change} change
|
32048 | * @param {Selection} range
|
32049 | * @param {Inline|Object|String} inline
|
32050 | * @param {Object} options
|
32051 | * @property {Boolean} normalize
|
32052 | */
|
32053 |
|
32054 | Changes.wrapInlineAtRange = function (change, range, inline) {
|
32055 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
32056 | var state = change.state;
|
32057 | var document = state.document;
|
32058 | var _options$normalize17 = options.normalize,
|
32059 | normalize = _options$normalize17 === undefined ? true : _options$normalize17;
|
32060 | var startKey = range.startKey,
|
32061 | startOffset = range.startOffset,
|
32062 | endKey = range.endKey,
|
32063 | endOffset = range.endOffset;
|
32064 |
|
32065 |
|
32066 | if (range.isCollapsed) {
|
32067 | // Wrapping an inline void
|
32068 | var inlineParent = document.getClosestInline(startKey);
|
32069 | if (!inlineParent.isVoid) {
|
32070 | return;
|
32071 | }
|
32072 |
|
32073 | return change.wrapInlineByKey(inlineParent.key, inline, options);
|
32074 | }
|
32075 |
|
32076 | inline = _inline2.default.create(inline);
|
32077 | inline = inline.set('nodes', inline.nodes.clear());
|
32078 |
|
32079 | var blocks = document.getBlocksAtRange(range);
|
32080 | var startBlock = document.getClosestBlock(startKey);
|
32081 | var endBlock = document.getClosestBlock(endKey);
|
32082 | var startChild = startBlock.getFurthestAncestor(startKey);
|
32083 | var endChild = endBlock.getFurthestAncestor(endKey);
|
32084 |
|
32085 | change.splitDescendantsByKey(endChild.key, endKey, endOffset, { normalize: false });
|
32086 | change.splitDescendantsByKey(startChild.key, startKey, startOffset, { normalize: false });
|
32087 |
|
32088 | document = change.state.document;
|
32089 | startBlock = document.getDescendant(startBlock.key);
|
32090 | endBlock = document.getDescendant(endBlock.key);
|
32091 | startChild = startBlock.getFurthestAncestor(startKey);
|
32092 | endChild = endBlock.getFurthestAncestor(endKey);
|
32093 | var startIndex = startBlock.nodes.indexOf(startChild);
|
32094 | var endIndex = endBlock.nodes.indexOf(endChild);
|
32095 |
|
32096 | if (startBlock == endBlock) {
|
32097 | document = change.state.document;
|
32098 | startBlock = document.getClosestBlock(startKey);
|
32099 | startChild = startBlock.getFurthestAncestor(startKey);
|
32100 |
|
32101 | var startInner = document.getNextSibling(startChild.key);
|
32102 | var startInnerIndex = startBlock.nodes.indexOf(startInner);
|
32103 | var endInner = startKey == endKey ? startInner : startBlock.getFurthestAncestor(endKey);
|
32104 | var inlines = startBlock.nodes.skipUntil(function (n) {
|
32105 | return n == startInner;
|
32106 | }).takeUntil(function (n) {
|
32107 | return n == endInner;
|
32108 | }).push(endInner);
|
32109 |
|
32110 | var node = inline.regenerateKey();
|
32111 |
|
32112 | change.insertNodeByKey(startBlock.key, startInnerIndex, node, { normalize: false });
|
32113 |
|
32114 | inlines.forEach(function (child, i) {
|
32115 | change.moveNodeByKey(child.key, node.key, i, { normalize: false });
|
32116 | });
|
32117 |
|
32118 | if (normalize) {
|
32119 | change.normalizeNodeByKey(startBlock.key, _core2.default);
|
32120 | }
|
32121 | } else {
|
32122 | var startInlines = startBlock.nodes.slice(startIndex + 1);
|
32123 | var endInlines = endBlock.nodes.slice(0, endIndex + 1);
|
32124 | var startNode = inline.regenerateKey();
|
32125 | var endNode = inline.regenerateKey();
|
32126 |
|
32127 | change.insertNodeByKey(startBlock.key, startIndex - 1, startNode, { normalize: false });
|
32128 | change.insertNodeByKey(endBlock.key, endIndex, endNode, { normalize: false });
|
32129 |
|
32130 | startInlines.forEach(function (child, i) {
|
32131 | change.moveNodeByKey(child.key, startNode.key, i, { normalize: false });
|
32132 | });
|
32133 |
|
32134 | endInlines.forEach(function (child, i) {
|
32135 | change.moveNodeByKey(child.key, endNode.key, i, { normalize: false });
|
32136 | });
|
32137 |
|
32138 | if (normalize) {
|
32139 | change.normalizeNodeByKey(startBlock.key, _core2.default).normalizeNodeByKey(endBlock.key, _core2.default);
|
32140 | }
|
32141 |
|
32142 | blocks.slice(1, -1).forEach(function (block) {
|
32143 | var node = inline.regenerateKey();
|
32144 | change.insertNodeByKey(block.key, 0, node, { normalize: false });
|
32145 |
|
32146 | block.nodes.forEach(function (child, i) {
|
32147 | change.moveNodeByKey(child.key, node.key, i, { normalize: false });
|
32148 | });
|
32149 |
|
32150 | if (normalize) {
|
32151 | change.normalizeNodeByKey(block.key, _core2.default);
|
32152 | }
|
32153 | });
|
32154 | }
|
32155 | };
|
32156 |
|
32157 | /**
|
32158 | * Wrap the text in a `range` in a prefix/suffix.
|
32159 | *
|
32160 | * @param {Change} change
|
32161 | * @param {Selection} range
|
32162 | * @param {String} prefix
|
32163 | * @param {String} suffix (optional)
|
32164 | * @param {Object} options
|
32165 | * @property {Boolean} normalize
|
32166 | */
|
32167 |
|
32168 | Changes.wrapTextAtRange = function (change, range, prefix) {
|
32169 | var suffix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : prefix;
|
32170 | var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
32171 | var _options$normalize18 = options.normalize,
|
32172 | normalize = _options$normalize18 === undefined ? true : _options$normalize18;
|
32173 | var startKey = range.startKey,
|
32174 | endKey = range.endKey;
|
32175 |
|
32176 | var start = range.collapseToStart();
|
32177 | var end = range.collapseToEnd();
|
32178 |
|
32179 | if (startKey == endKey) {
|
32180 | end = end.move(prefix.length);
|
32181 | }
|
32182 |
|
32183 | change.insertTextAtRange(start, prefix, [], { normalize: normalize });
|
32184 | change.insertTextAtRange(end, suffix, [], { normalize: normalize });
|
32185 | };
|
32186 |
|
32187 | /**
|
32188 | * Export.
|
32189 | *
|
32190 | * @type {Object}
|
32191 | */
|
32192 |
|
32193 | exports.default = Changes;
|
32194 | },{"../models/block":331,"../models/inline":337,"../models/mark":338,"../models/node":339,"../schemas/core":350,"../utils/string":374,"immutable":135}],314:[function(require,module,exports){
|
32195 | 'use strict';
|
32196 |
|
32197 | Object.defineProperty(exports, "__esModule", {
|
32198 | value: true
|
32199 | });
|
32200 |
|
32201 | var _block = require('../models/block');
|
32202 |
|
32203 | var _block2 = _interopRequireDefault(_block);
|
32204 |
|
32205 | var _inline = require('../models/inline');
|
32206 |
|
32207 | var _inline2 = _interopRequireDefault(_inline);
|
32208 |
|
32209 | var _mark = require('../models/mark');
|
32210 |
|
32211 | var _mark2 = _interopRequireDefault(_mark);
|
32212 |
|
32213 | var _node = require('../models/node');
|
32214 |
|
32215 | var _node2 = _interopRequireDefault(_node);
|
32216 |
|
32217 | var _core = require('../schemas/core');
|
32218 |
|
32219 | var _core2 = _interopRequireDefault(_core);
|
32220 |
|
32221 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
32222 |
|
32223 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
32224 |
|
32225 | /**
|
32226 | * Changes.
|
32227 | *
|
32228 | * @type {Object}
|
32229 | */
|
32230 |
|
32231 | var Changes = {};
|
32232 |
|
32233 | /**
|
32234 | * Add mark to text at `offset` and `length` in node by `key`.
|
32235 | *
|
32236 | * @param {Change} change
|
32237 | * @param {String} key
|
32238 | * @param {Number} offset
|
32239 | * @param {Number} length
|
32240 | * @param {Mixed} mark
|
32241 | * @param {Object} options
|
32242 | * @property {Boolean} normalize
|
32243 | */
|
32244 |
|
32245 | Changes.addMarkByKey = function (change, key, offset, length, mark) {
|
32246 | var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
32247 |
|
32248 | mark = _mark2.default.create(mark);
|
32249 | var _options$normalize = options.normalize,
|
32250 | normalize = _options$normalize === undefined ? true : _options$normalize;
|
32251 | var state = change.state;
|
32252 | var document = state.document;
|
32253 |
|
32254 | var path = document.getPath(key);
|
32255 | var node = document.getNode(key);
|
32256 | var ranges = node.getRanges();
|
32257 |
|
32258 | var operations = [];
|
32259 | var bx = offset;
|
32260 | var by = offset + length;
|
32261 | var o = 0;
|
32262 |
|
32263 | ranges.forEach(function (range) {
|
32264 | var ax = o;
|
32265 | var ay = ax + range.text.length;
|
32266 |
|
32267 | o += range.text.length;
|
32268 |
|
32269 | // If the range doesn't overlap with the operation, continue on.
|
32270 | if (ay < bx || by < ax) return;
|
32271 |
|
32272 | // If the range already has the mark, continue on.
|
32273 | if (range.marks.has(mark)) return;
|
32274 |
|
32275 | // Otherwise, determine which offset and characters overlap.
|
32276 | var start = Math.max(ax, bx);
|
32277 | var end = Math.min(ay, by);
|
32278 |
|
32279 | operations.push({
|
32280 | type: 'add_mark',
|
32281 | path: path,
|
32282 | offset: start,
|
32283 | length: end - start,
|
32284 | mark: mark
|
32285 | });
|
32286 | });
|
32287 |
|
32288 | change.applyOperations(operations);
|
32289 |
|
32290 | if (normalize) {
|
32291 | var parent = document.getParent(key);
|
32292 | change.normalizeNodeByKey(parent.key, _core2.default);
|
32293 | }
|
32294 | };
|
32295 |
|
32296 | /**
|
32297 | * Insert a `fragment` at `index` in a node by `key`.
|
32298 | *
|
32299 | * @param {Change} change
|
32300 | * @param {String} key
|
32301 | * @param {Number} index
|
32302 | * @param {Fragment} fragment
|
32303 | * @param {Object} options
|
32304 | * @property {Boolean} normalize
|
32305 | */
|
32306 |
|
32307 | Changes.insertFragmentByKey = function (change, key, index, fragment) {
|
32308 | var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
32309 | var _options$normalize2 = options.normalize,
|
32310 | normalize = _options$normalize2 === undefined ? true : _options$normalize2;
|
32311 |
|
32312 |
|
32313 | fragment.nodes.forEach(function (node, i) {
|
32314 | change.insertNodeByKey(key, index + i, node);
|
32315 | });
|
32316 |
|
32317 | if (normalize) {
|
32318 | change.normalizeNodeByKey(key, _core2.default);
|
32319 | }
|
32320 | };
|
32321 |
|
32322 | /**
|
32323 | * Insert a `node` at `index` in a node by `key`.
|
32324 | *
|
32325 | * @param {Change} change
|
32326 | * @param {String} key
|
32327 | * @param {Number} index
|
32328 | * @param {Node} node
|
32329 | * @param {Object} options
|
32330 | * @property {Boolean} normalize
|
32331 | */
|
32332 |
|
32333 | Changes.insertNodeByKey = function (change, key, index, node) {
|
32334 | var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
32335 | var _options$normalize3 = options.normalize,
|
32336 | normalize = _options$normalize3 === undefined ? true : _options$normalize3;
|
32337 | var state = change.state;
|
32338 | var document = state.document;
|
32339 |
|
32340 | var path = document.getPath(key);
|
32341 |
|
32342 | change.applyOperation({
|
32343 | type: 'insert_node',
|
32344 | path: [].concat(_toConsumableArray(path), [index]),
|
32345 | node: node
|
32346 | });
|
32347 |
|
32348 | if (normalize) {
|
32349 | change.normalizeNodeByKey(key, _core2.default);
|
32350 | }
|
32351 | };
|
32352 |
|
32353 | /**
|
32354 | * Insert `text` at `offset` in node by `key`.
|
32355 | *
|
32356 | * @param {Change} change
|
32357 | * @param {String} key
|
32358 | * @param {Number} offset
|
32359 | * @param {String} text
|
32360 | * @param {Set<Mark>} marks (optional)
|
32361 | * @param {Object} options
|
32362 | * @property {Boolean} normalize
|
32363 | */
|
32364 |
|
32365 | Changes.insertTextByKey = function (change, key, offset, text, marks) {
|
32366 | var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
32367 | var _options$normalize4 = options.normalize,
|
32368 | normalize = _options$normalize4 === undefined ? true : _options$normalize4;
|
32369 | var state = change.state;
|
32370 | var document = state.document;
|
32371 |
|
32372 | var path = document.getPath(key);
|
32373 | var node = document.getNode(key);
|
32374 | marks = marks || node.getMarksAtIndex(offset);
|
32375 |
|
32376 | change.applyOperation({
|
32377 | type: 'insert_text',
|
32378 | path: path,
|
32379 | offset: offset,
|
32380 | text: text,
|
32381 | marks: marks
|
32382 | });
|
32383 |
|
32384 | if (normalize) {
|
32385 | var parent = document.getParent(key);
|
32386 | change.normalizeNodeByKey(parent.key, _core2.default);
|
32387 | }
|
32388 | };
|
32389 |
|
32390 | /**
|
32391 | * Merge a node by `key` with the previous node.
|
32392 | *
|
32393 | * @param {Change} change
|
32394 | * @param {String} key
|
32395 | * @param {Object} options
|
32396 | * @property {Boolean} normalize
|
32397 | */
|
32398 |
|
32399 | Changes.mergeNodeByKey = function (change, key) {
|
32400 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
32401 | var _options$normalize5 = options.normalize,
|
32402 | normalize = _options$normalize5 === undefined ? true : _options$normalize5;
|
32403 | var state = change.state;
|
32404 | var document = state.document;
|
32405 |
|
32406 | var path = document.getPath(key);
|
32407 | var previous = document.getPreviousSibling(key);
|
32408 |
|
32409 | if (!previous) {
|
32410 | throw new Error('Unable to merge node with key "' + key + '", no previous key.');
|
32411 | }
|
32412 |
|
32413 | var position = previous.kind == 'text' ? previous.text.length : previous.nodes.size;
|
32414 |
|
32415 | change.applyOperation({
|
32416 | type: 'merge_node',
|
32417 | path: path,
|
32418 | position: position
|
32419 | });
|
32420 |
|
32421 | if (normalize) {
|
32422 | var parent = document.getParent(key);
|
32423 | change.normalizeNodeByKey(parent.key, _core2.default);
|
32424 | }
|
32425 | };
|
32426 |
|
32427 | /**
|
32428 | * Move a node by `key` to a new parent by `newKey` and `index`.
|
32429 | * `newKey` is the key of the container (it can be the document itself)
|
32430 | *
|
32431 | * @param {Change} change
|
32432 | * @param {String} key
|
32433 | * @param {String} newKey
|
32434 | * @param {Number} index
|
32435 | * @param {Object} options
|
32436 | * @property {Boolean} normalize
|
32437 | */
|
32438 |
|
32439 | Changes.moveNodeByKey = function (change, key, newKey, newIndex) {
|
32440 | var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
32441 | var _options$normalize6 = options.normalize,
|
32442 | normalize = _options$normalize6 === undefined ? true : _options$normalize6;
|
32443 | var state = change.state;
|
32444 | var document = state.document;
|
32445 |
|
32446 | var path = document.getPath(key);
|
32447 | var newPath = document.getPath(newKey);
|
32448 |
|
32449 | change.applyOperation({
|
32450 | type: 'move_node',
|
32451 | path: path,
|
32452 | newPath: [].concat(_toConsumableArray(newPath), [newIndex])
|
32453 | });
|
32454 |
|
32455 | if (normalize) {
|
32456 | var parent = document.getCommonAncestor(key, newKey);
|
32457 | change.normalizeNodeByKey(parent.key, _core2.default);
|
32458 | }
|
32459 | };
|
32460 |
|
32461 | /**
|
32462 | * Remove mark from text at `offset` and `length` in node by `key`.
|
32463 | *
|
32464 | * @param {Change} change
|
32465 | * @param {String} key
|
32466 | * @param {Number} offset
|
32467 | * @param {Number} length
|
32468 | * @param {Mark} mark
|
32469 | * @param {Object} options
|
32470 | * @property {Boolean} normalize
|
32471 | */
|
32472 |
|
32473 | Changes.removeMarkByKey = function (change, key, offset, length, mark) {
|
32474 | var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
32475 |
|
32476 | mark = _mark2.default.create(mark);
|
32477 | var _options$normalize7 = options.normalize,
|
32478 | normalize = _options$normalize7 === undefined ? true : _options$normalize7;
|
32479 | var state = change.state;
|
32480 | var document = state.document;
|
32481 |
|
32482 | var path = document.getPath(key);
|
32483 | var node = document.getNode(key);
|
32484 | var ranges = node.getRanges();
|
32485 |
|
32486 | var operations = [];
|
32487 | var bx = offset;
|
32488 | var by = offset + length;
|
32489 | var o = 0;
|
32490 |
|
32491 | ranges.forEach(function (range) {
|
32492 | var ax = o;
|
32493 | var ay = ax + range.text.length;
|
32494 |
|
32495 | o += range.text.length;
|
32496 |
|
32497 | // If the range doesn't overlap with the operation, continue on.
|
32498 | if (ay < bx || by < ax) return;
|
32499 |
|
32500 | // If the range already has the mark, continue on.
|
32501 | if (!range.marks.has(mark)) return;
|
32502 |
|
32503 | // Otherwise, determine which offset and characters overlap.
|
32504 | var start = Math.max(ax, bx);
|
32505 | var end = Math.min(ay, by);
|
32506 |
|
32507 | operations.push({
|
32508 | type: 'remove_mark',
|
32509 | path: path,
|
32510 | offset: start,
|
32511 | length: end - start,
|
32512 | mark: mark
|
32513 | });
|
32514 | });
|
32515 |
|
32516 | change.applyOperations(operations);
|
32517 |
|
32518 | if (normalize) {
|
32519 | var parent = document.getParent(key);
|
32520 | change.normalizeNodeByKey(parent.key, _core2.default);
|
32521 | }
|
32522 | };
|
32523 |
|
32524 | /**
|
32525 | * Remove a node by `key`.
|
32526 | *
|
32527 | * @param {Change} change
|
32528 | * @param {String} key
|
32529 | * @param {Object} options
|
32530 | * @property {Boolean} normalize
|
32531 | */
|
32532 |
|
32533 | Changes.removeNodeByKey = function (change, key) {
|
32534 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
32535 | var _options$normalize8 = options.normalize,
|
32536 | normalize = _options$normalize8 === undefined ? true : _options$normalize8;
|
32537 | var state = change.state;
|
32538 | var document = state.document;
|
32539 |
|
32540 | var path = document.getPath(key);
|
32541 | var node = document.getNode(key);
|
32542 |
|
32543 | change.applyOperation({
|
32544 | type: 'remove_node',
|
32545 | path: path,
|
32546 | node: node
|
32547 | });
|
32548 |
|
32549 | if (normalize) {
|
32550 | var parent = document.getParent(key);
|
32551 | change.normalizeNodeByKey(parent.key, _core2.default);
|
32552 | }
|
32553 | };
|
32554 |
|
32555 | /**
|
32556 | * Remove text at `offset` and `length` in node by `key`.
|
32557 | *
|
32558 | * @param {Change} change
|
32559 | * @param {String} key
|
32560 | * @param {Number} offset
|
32561 | * @param {Number} length
|
32562 | * @param {Object} options
|
32563 | * @property {Boolean} normalize
|
32564 | */
|
32565 |
|
32566 | Changes.removeTextByKey = function (change, key, offset, length) {
|
32567 | var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
32568 | var _options$normalize9 = options.normalize,
|
32569 | normalize = _options$normalize9 === undefined ? true : _options$normalize9;
|
32570 | var state = change.state;
|
32571 | var document = state.document;
|
32572 |
|
32573 | var path = document.getPath(key);
|
32574 | var node = document.getNode(key);
|
32575 | var ranges = node.getRanges();
|
32576 | var text = node.text;
|
32577 |
|
32578 |
|
32579 | var removals = [];
|
32580 | var bx = offset;
|
32581 | var by = offset + length;
|
32582 | var o = 0;
|
32583 |
|
32584 | ranges.forEach(function (range) {
|
32585 | var ax = o;
|
32586 | var ay = ax + range.text.length;
|
32587 |
|
32588 | o += range.text.length;
|
32589 |
|
32590 | // If the range doesn't overlap with the removal, continue on.
|
32591 | if (ay < bx || by < ax) return;
|
32592 |
|
32593 | // Otherwise, determine which offset and characters overlap.
|
32594 | var start = Math.max(ax, bx);
|
32595 | var end = Math.min(ay, by);
|
32596 | var string = text.slice(start, end);
|
32597 |
|
32598 | removals.push({
|
32599 | type: 'remove_text',
|
32600 | path: path,
|
32601 | offset: start,
|
32602 | text: string,
|
32603 | marks: range.marks
|
32604 | });
|
32605 | });
|
32606 |
|
32607 | // Apply in reverse order, so subsequent removals don't impact previous ones.
|
32608 | change.applyOperations(removals.reverse());
|
32609 |
|
32610 | if (normalize) {
|
32611 | var block = document.getClosestBlock(key);
|
32612 | change.normalizeNodeByKey(block.key, _core2.default);
|
32613 | }
|
32614 | };
|
32615 |
|
32616 | /**
|
32617 | * Set `properties` on mark on text at `offset` and `length` in node by `key`.
|
32618 | *
|
32619 | * @param {Change} change
|
32620 | * @param {String} key
|
32621 | * @param {Number} offset
|
32622 | * @param {Number} length
|
32623 | * @param {Mark} mark
|
32624 | * @param {Object} options
|
32625 | * @property {Boolean} normalize
|
32626 | */
|
32627 |
|
32628 | Changes.setMarkByKey = function (change, key, offset, length, mark, properties) {
|
32629 | var options = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
|
32630 |
|
32631 | mark = _mark2.default.create(mark);
|
32632 | properties = _mark2.default.createProperties(properties);
|
32633 | var _options$normalize10 = options.normalize,
|
32634 | normalize = _options$normalize10 === undefined ? true : _options$normalize10;
|
32635 | var state = change.state;
|
32636 | var document = state.document;
|
32637 |
|
32638 | var path = document.getPath(key);
|
32639 |
|
32640 | change.applyOperation({
|
32641 | type: 'set_mark',
|
32642 | path: path,
|
32643 | offset: offset,
|
32644 | length: length,
|
32645 | mark: mark,
|
32646 | properties: properties
|
32647 | });
|
32648 |
|
32649 | if (normalize) {
|
32650 | var parent = document.getParent(key);
|
32651 | change.normalizeNodeByKey(parent.key, _core2.default);
|
32652 | }
|
32653 | };
|
32654 |
|
32655 | /**
|
32656 | * Set `properties` on a node by `key`.
|
32657 | *
|
32658 | * @param {Change} change
|
32659 | * @param {String} key
|
32660 | * @param {Object|String} properties
|
32661 | * @param {Object} options
|
32662 | * @property {Boolean} normalize
|
32663 | */
|
32664 |
|
32665 | Changes.setNodeByKey = function (change, key, properties) {
|
32666 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
32667 |
|
32668 | properties = _node2.default.createProperties(properties);
|
32669 | var _options$normalize11 = options.normalize,
|
32670 | normalize = _options$normalize11 === undefined ? true : _options$normalize11;
|
32671 | var state = change.state;
|
32672 | var document = state.document;
|
32673 |
|
32674 | var path = document.getPath(key);
|
32675 | var node = document.getNode(key);
|
32676 |
|
32677 | change.applyOperation({
|
32678 | type: 'set_node',
|
32679 | path: path,
|
32680 | node: node,
|
32681 | properties: properties
|
32682 | });
|
32683 |
|
32684 | if (normalize) {
|
32685 | change.normalizeNodeByKey(node.key, _core2.default);
|
32686 | }
|
32687 | };
|
32688 |
|
32689 | /**
|
32690 | * Split a node by `key` at `position`.
|
32691 | *
|
32692 | * @param {Change} change
|
32693 | * @param {String} key
|
32694 | * @param {Number} position
|
32695 | * @param {Object} options
|
32696 | * @property {Boolean} normalize
|
32697 | */
|
32698 |
|
32699 | Changes.splitNodeByKey = function (change, key, position) {
|
32700 | var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
32701 | var _options$normalize12 = options.normalize,
|
32702 | normalize = _options$normalize12 === undefined ? true : _options$normalize12;
|
32703 | var state = change.state;
|
32704 | var document = state.document;
|
32705 |
|
32706 | var path = document.getPath(key);
|
32707 |
|
32708 | change.applyOperation({
|
32709 | type: 'split_node',
|
32710 | path: path,
|
32711 | position: position
|
32712 | });
|
32713 |
|
32714 | if (normalize) {
|
32715 | var parent = document.getParent(key);
|
32716 | change.normalizeNodeByKey(parent.key, _core2.default);
|
32717 | }
|
32718 | };
|
32719 |
|
32720 | /**
|
32721 | * Split a node deeply down the tree by `key`, `textKey` and `textOffset`.
|
32722 | *
|
32723 | * @param {Change} change
|
32724 | * @param {String} key
|
32725 | * @param {Number} position
|
32726 | * @param {Object} options
|
32727 | * @property {Boolean} normalize
|
32728 | */
|
32729 |
|
32730 | Changes.splitDescendantsByKey = function (change, key, textKey, textOffset) {
|
32731 | var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
32732 |
|
32733 | if (key == textKey) {
|
32734 | change.splitNodeByKey(textKey, textOffset, options);
|
32735 | return;
|
32736 | }
|
32737 |
|
32738 | var _options$normalize13 = options.normalize,
|
32739 | normalize = _options$normalize13 === undefined ? true : _options$normalize13;
|
32740 | var state = change.state;
|
32741 | var document = state.document;
|
32742 |
|
32743 |
|
32744 | var text = document.getNode(textKey);
|
32745 | var ancestors = document.getAncestors(textKey);
|
32746 | var nodes = ancestors.skipUntil(function (a) {
|
32747 | return a.key == key;
|
32748 | }).reverse().unshift(text);
|
32749 | var previous = void 0;
|
32750 |
|
32751 | nodes.forEach(function (node) {
|
32752 | var index = previous ? node.nodes.indexOf(previous) + 1 : textOffset;
|
32753 | previous = node;
|
32754 | change.splitNodeByKey(node.key, index, { normalize: false });
|
32755 | });
|
32756 |
|
32757 | if (normalize) {
|
32758 | var parent = document.getParent(key);
|
32759 | change.normalizeNodeByKey(parent.key, _core2.default);
|
32760 | }
|
32761 | };
|
32762 |
|
32763 | /**
|
32764 | * Unwrap content from an inline parent with `properties`.
|
32765 | *
|
32766 | * @param {Change} change
|
32767 | * @param {String} key
|
32768 | * @param {Object|String} properties
|
32769 | * @param {Object} options
|
32770 | * @property {Boolean} normalize
|
32771 | */
|
32772 |
|
32773 | Changes.unwrapInlineByKey = function (change, key, properties, options) {
|
32774 | var state = change.state;
|
32775 | var document = state.document,
|
32776 | selection = state.selection;
|
32777 |
|
32778 | var node = document.assertDescendant(key);
|
32779 | var first = node.getFirstText();
|
32780 | var last = node.getLastText();
|
32781 | var range = selection.moveToRangeOf(first, last);
|
32782 | change.unwrapInlineAtRange(range, properties, options);
|
32783 | };
|
32784 |
|
32785 | /**
|
32786 | * Unwrap content from a block parent with `properties`.
|
32787 | *
|
32788 | * @param {Change} change
|
32789 | * @param {String} key
|
32790 | * @param {Object|String} properties
|
32791 | * @param {Object} options
|
32792 | * @property {Boolean} normalize
|
32793 | */
|
32794 |
|
32795 | Changes.unwrapBlockByKey = function (change, key, properties, options) {
|
32796 | var state = change.state;
|
32797 | var document = state.document,
|
32798 | selection = state.selection;
|
32799 |
|
32800 | var node = document.assertDescendant(key);
|
32801 | var first = node.getFirstText();
|
32802 | var last = node.getLastText();
|
32803 | var range = selection.moveToRangeOf(first, last);
|
32804 | change.unwrapBlockAtRange(range, properties, options);
|
32805 | };
|
32806 |
|
32807 | /**
|
32808 | * Unwrap a single node from its parent.
|
32809 | *
|
32810 | * If the node is surrounded with siblings, its parent will be
|
32811 | * split. If the node is the only child, the parent is removed, and
|
32812 | * simply replaced by the node itself. Cannot unwrap a root node.
|
32813 | *
|
32814 | * @param {Change} change
|
32815 | * @param {String} key
|
32816 | * @param {Object} options
|
32817 | * @property {Boolean} normalize
|
32818 | */
|
32819 |
|
32820 | Changes.unwrapNodeByKey = function (change, key) {
|
32821 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
32822 | var _options$normalize14 = options.normalize,
|
32823 | normalize = _options$normalize14 === undefined ? true : _options$normalize14;
|
32824 | var state = change.state;
|
32825 | var document = state.document;
|
32826 |
|
32827 | var parent = document.getParent(key);
|
32828 | var node = parent.getChild(key);
|
32829 |
|
32830 | var index = parent.nodes.indexOf(node);
|
32831 | var isFirst = index === 0;
|
32832 | var isLast = index === parent.nodes.size - 1;
|
32833 |
|
32834 | var parentParent = document.getParent(parent.key);
|
32835 | var parentIndex = parentParent.nodes.indexOf(parent);
|
32836 |
|
32837 | if (parent.nodes.size === 1) {
|
32838 | change.moveNodeByKey(key, parentParent.key, parentIndex, { normalize: false });
|
32839 | change.removeNodeByKey(parent.key, options);
|
32840 | } else if (isFirst) {
|
32841 | // Just move the node before its parent.
|
32842 | change.moveNodeByKey(key, parentParent.key, parentIndex, options);
|
32843 | } else if (isLast) {
|
32844 | // Just move the node after its parent.
|
32845 | change.moveNodeByKey(key, parentParent.key, parentIndex + 1, options);
|
32846 | } else {
|
32847 | // Split the parent.
|
32848 | change.splitNodeByKey(parent.key, index, { normalize: false });
|
32849 |
|
32850 | // Extract the node in between the splitted parent.
|
32851 | change.moveNodeByKey(key, parentParent.key, parentIndex + 1, { normalize: false });
|
32852 |
|
32853 | if (normalize) {
|
32854 | change.normalizeNodeByKey(parentParent.key, _core2.default);
|
32855 | }
|
32856 | }
|
32857 | };
|
32858 |
|
32859 | /**
|
32860 | * Wrap a node in an inline with `properties`.
|
32861 | *
|
32862 | * @param {Change} change
|
32863 | * @param {String} key The node to wrap
|
32864 | * @param {Block|Object|String} inline The wrapping inline (its children are discarded)
|
32865 | * @param {Object} options
|
32866 | * @property {Boolean} normalize
|
32867 | */
|
32868 |
|
32869 | Changes.wrapInlineByKey = function (change, key, inline, options) {
|
32870 | inline = _inline2.default.create(inline);
|
32871 | inline = inline.set('nodes', inline.nodes.clear());
|
32872 |
|
32873 | var document = change.state.document;
|
32874 |
|
32875 | var node = document.assertDescendant(key);
|
32876 | var parent = document.getParent(node.key);
|
32877 | var index = parent.nodes.indexOf(node);
|
32878 |
|
32879 | change.insertNodeByKey(parent.key, index, inline, { normalize: false });
|
32880 | change.moveNodeByKey(node.key, inline.key, 0, options);
|
32881 | };
|
32882 |
|
32883 | /**
|
32884 | * Wrap a node in a block with `properties`.
|
32885 | *
|
32886 | * @param {Change} change
|
32887 | * @param {String} key The node to wrap
|
32888 | * @param {Block|Object|String} block The wrapping block (its children are discarded)
|
32889 | * @param {Object} options
|
32890 | * @property {Boolean} normalize
|
32891 | */
|
32892 |
|
32893 | Changes.wrapBlockByKey = function (change, key, block, options) {
|
32894 | block = _block2.default.create(block);
|
32895 | block = block.set('nodes', block.nodes.clear());
|
32896 |
|
32897 | var document = change.state.document;
|
32898 |
|
32899 | var node = document.assertDescendant(key);
|
32900 | var parent = document.getParent(node.key);
|
32901 | var index = parent.nodes.indexOf(node);
|
32902 |
|
32903 | change.insertNodeByKey(parent.key, index, block, { normalize: false });
|
32904 | change.moveNodeByKey(node.key, block.key, 0, options);
|
32905 | };
|
32906 |
|
32907 | /**
|
32908 | * Export.
|
32909 | *
|
32910 | * @type {Object}
|
32911 | */
|
32912 |
|
32913 | exports.default = Changes;
|
32914 | },{"../models/block":331,"../models/inline":337,"../models/mark":338,"../models/node":339,"../schemas/core":350}],315:[function(require,module,exports){
|
32915 | 'use strict';
|
32916 |
|
32917 | Object.defineProperty(exports, "__esModule", {
|
32918 | value: true
|
32919 | });
|
32920 |
|
32921 | 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; };
|
32922 |
|
32923 | var _atCurrentRange = require('./at-current-range');
|
32924 |
|
32925 | var _atCurrentRange2 = _interopRequireDefault(_atCurrentRange);
|
32926 |
|
32927 | var _atRange = require('./at-range');
|
32928 |
|
32929 | var _atRange2 = _interopRequireDefault(_atRange);
|
32930 |
|
32931 | var _byKey = require('./by-key');
|
32932 |
|
32933 | var _byKey2 = _interopRequireDefault(_byKey);
|
32934 |
|
32935 | var _normalize = require('./normalize');
|
32936 |
|
32937 | var _normalize2 = _interopRequireDefault(_normalize);
|
32938 |
|
32939 | var _onHistory = require('./on-history');
|
32940 |
|
32941 | var _onHistory2 = _interopRequireDefault(_onHistory);
|
32942 |
|
32943 | var _onSelection = require('./on-selection');
|
32944 |
|
32945 | var _onSelection2 = _interopRequireDefault(_onSelection);
|
32946 |
|
32947 | var _onState = require('./on-state');
|
32948 |
|
32949 | var _onState2 = _interopRequireDefault(_onState);
|
32950 |
|
32951 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
32952 |
|
32953 | /**
|
32954 | * Export.
|
32955 | *
|
32956 | * @type {Object}
|
32957 | */
|
32958 |
|
32959 | exports.default = _extends({}, _atCurrentRange2.default, _atRange2.default, _byKey2.default, _normalize2.default, _onHistory2.default, _onSelection2.default, _onState2.default);
|
32960 | },{"./at-current-range":312,"./at-range":313,"./by-key":314,"./normalize":316,"./on-history":317,"./on-selection":318,"./on-state":319}],316:[function(require,module,exports){
|
32961 | 'use strict';
|
32962 |
|
32963 | Object.defineProperty(exports, "__esModule", {
|
32964 | value: true
|
32965 | });
|
32966 |
|
32967 | var _schema = require('../models/schema');
|
32968 |
|
32969 | var _schema2 = _interopRequireDefault(_schema);
|
32970 |
|
32971 | var _immutable = require('immutable');
|
32972 |
|
32973 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
32974 |
|
32975 | /**
|
32976 | * Changes.
|
32977 | *
|
32978 | * @type {Object}
|
32979 | */
|
32980 |
|
32981 | var Changes = {};
|
32982 |
|
32983 | /**
|
32984 | * Normalize the document and selection with a `schema`.
|
32985 | *
|
32986 | * @param {Change} change
|
32987 | * @param {Schema} schema
|
32988 | */
|
32989 |
|
32990 | Changes.normalize = function (change, schema) {
|
32991 | change.normalizeDocument(schema);
|
32992 | };
|
32993 |
|
32994 | /**
|
32995 | * Normalize the document with a `schema`.
|
32996 | *
|
32997 | * @param {Change} change
|
32998 | * @param {Schema} schema
|
32999 | */
|
33000 |
|
33001 | Changes.normalizeDocument = function (change, schema) {
|
33002 | var state = change.state;
|
33003 | var document = state.document;
|
33004 |
|
33005 | change.normalizeNodeByKey(document.key, schema);
|
33006 | };
|
33007 |
|
33008 | /**
|
33009 | * Normalize a `node` and its children with a `schema`.
|
33010 | *
|
33011 | * @param {Change} change
|
33012 | * @param {Node|String} key
|
33013 | * @param {Schema} schema
|
33014 | */
|
33015 |
|
33016 | Changes.normalizeNodeByKey = function (change, key, schema) {
|
33017 | assertSchema(schema);
|
33018 |
|
33019 | // If the schema has no validation rules, there's nothing to normalize.
|
33020 | if (!schema.hasValidators) return;
|
33021 |
|
33022 | var state = change.state;
|
33023 | var document = state.document;
|
33024 |
|
33025 | var node = document.assertNode(key);
|
33026 | normalizeNodeAndChildren(change, node, schema);
|
33027 | };
|
33028 |
|
33029 | /**
|
33030 | * Normalize a `node` and its children with a `schema`.
|
33031 | *
|
33032 | * @param {Change} change
|
33033 | * @param {Node} node
|
33034 | * @param {Schema} schema
|
33035 | */
|
33036 |
|
33037 | function normalizeNodeAndChildren(change, node, schema) {
|
33038 | if (node.kind == 'text') {
|
33039 | normalizeNode(change, node, schema);
|
33040 | return;
|
33041 | }
|
33042 |
|
33043 | // We can't just loop the children and normalize them, because in the process
|
33044 | // of normalizing one child, we might end up creating another. Instead, we
|
33045 | // have to normalize one at a time, and check for new children along the way.
|
33046 | // PERF: use a mutable array here instead of an immutable stack.
|
33047 | var keys = node.nodes.toArray().map(function (n) {
|
33048 | return n.key;
|
33049 | });
|
33050 |
|
33051 | // While there is still a child key that hasn't been normalized yet...
|
33052 |
|
33053 | var _loop = function _loop() {
|
33054 | var ops = change.operations.length;
|
33055 | var key = void 0;
|
33056 |
|
33057 | // PERF: use a mutable set here since we'll be add to it a lot.
|
33058 | var set = new _immutable.Set().asMutable();
|
33059 |
|
33060 | // Unwind the stack, normalizing every child and adding it to the set.
|
33061 | while (key = keys[0]) {
|
33062 | var child = node.getChild(key);
|
33063 | normalizeNodeAndChildren(change, child, schema);
|
33064 | set.add(key);
|
33065 | keys.shift();
|
33066 | }
|
33067 |
|
33068 | // Turn the set immutable to be able to compare against it.
|
33069 | set = set.asImmutable();
|
33070 |
|
33071 | // PERF: Only re-find the node and re-normalize any new children if
|
33072 | // operations occured that might have changed it.
|
33073 | if (change.operations.length != ops) {
|
33074 | node = refindNode(change, node);
|
33075 |
|
33076 | // Add any new children back onto the stack.
|
33077 | node.nodes.forEach(function (n) {
|
33078 | if (set.has(n.key)) return;
|
33079 | keys.unshift(n.key);
|
33080 | });
|
33081 | }
|
33082 | };
|
33083 |
|
33084 | while (keys.length) {
|
33085 | _loop();
|
33086 | }
|
33087 |
|
33088 | // Normalize the node itself if it still exists.
|
33089 | if (node) {
|
33090 | normalizeNode(change, node, schema);
|
33091 | }
|
33092 | }
|
33093 |
|
33094 | /**
|
33095 | * Re-find a reference to a node that may have been modified or removed
|
33096 | * entirely by a change.
|
33097 | *
|
33098 | * @param {Change} change
|
33099 | * @param {Node} node
|
33100 | * @return {Node}
|
33101 | */
|
33102 |
|
33103 | function refindNode(change, node) {
|
33104 | var state = change.state;
|
33105 | var document = state.document;
|
33106 |
|
33107 | return node.kind == 'document' ? document : document.getDescendant(node.key);
|
33108 | }
|
33109 |
|
33110 | /**
|
33111 | * Normalize a `node` with a `schema`, but not its children.
|
33112 | *
|
33113 | * @param {Change} change
|
33114 | * @param {Node} node
|
33115 | * @param {Schema} schema
|
33116 | */
|
33117 |
|
33118 | function normalizeNode(change, node, schema) {
|
33119 | var max = schema.rules.length;
|
33120 | var iterations = 0;
|
33121 |
|
33122 | function iterate(t, n) {
|
33123 | var failure = n.validate(schema);
|
33124 | if (!failure) return;
|
33125 |
|
33126 | // Run the `normalize` function for the rule with the invalid value.
|
33127 | var value = failure.value,
|
33128 | rule = failure.rule;
|
33129 |
|
33130 | rule.normalize(t, n, value);
|
33131 |
|
33132 | // Re-find the node reference, in case it was updated. If the node no longer
|
33133 | // exists, we're done for this branch.
|
33134 | n = refindNode(t, n);
|
33135 | if (!n) return;
|
33136 |
|
33137 | // Increment the iterations counter, and check to make sure that we haven't
|
33138 | // exceeded the max. Without this check, it's easy for the `validate` or
|
33139 | // `normalize` function of a schema rule to be written incorrectly and for
|
33140 | // an infinite invalid loop to occur.
|
33141 | iterations++;
|
33142 |
|
33143 | if (iterations > max) {
|
33144 | throw new Error('A schema rule could not be validated after sufficient iterations. This is usually due to a `rule.validate` or `rule.normalize` function of a schema being incorrectly written, causing an infinite loop.');
|
33145 | }
|
33146 |
|
33147 | // Otherwise, iterate again.
|
33148 | iterate(t, n);
|
33149 | }
|
33150 |
|
33151 | iterate(change, node);
|
33152 | }
|
33153 |
|
33154 | /**
|
33155 | * Assert that a `schema` exists.
|
33156 | *
|
33157 | * @param {Schema} schema
|
33158 | */
|
33159 |
|
33160 | function assertSchema(schema) {
|
33161 | if (_schema2.default.isSchema(schema)) {
|
33162 | return;
|
33163 | } else if (schema == null) {
|
33164 | throw new Error('You must pass a `schema` object.');
|
33165 | } else {
|
33166 | throw new Error('You passed an invalid `schema` object: ' + schema + '.');
|
33167 | }
|
33168 | }
|
33169 |
|
33170 | /**
|
33171 | * Export.
|
33172 | *
|
33173 | * @type {Object}
|
33174 | */
|
33175 |
|
33176 | exports.default = Changes;
|
33177 | },{"../models/schema":341,"immutable":135}],317:[function(require,module,exports){
|
33178 | 'use strict';
|
33179 |
|
33180 | Object.defineProperty(exports, "__esModule", {
|
33181 | value: true
|
33182 | });
|
33183 |
|
33184 | var _invert = require('../operations/invert');
|
33185 |
|
33186 | var _invert2 = _interopRequireDefault(_invert);
|
33187 |
|
33188 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33189 |
|
33190 | /**
|
33191 | * Changes.
|
33192 | *
|
33193 | * @type {Object}
|
33194 | */
|
33195 |
|
33196 | var Changes = {};
|
33197 |
|
33198 | /**
|
33199 | * Redo to the next state in the history.
|
33200 | *
|
33201 | * @param {Change} change
|
33202 | */
|
33203 |
|
33204 | Changes.redo = function (change) {
|
33205 | var state = change.state;
|
33206 | var _state = state,
|
33207 | history = _state.history;
|
33208 |
|
33209 | if (!history) return;
|
33210 |
|
33211 | var _history = history,
|
33212 | undos = _history.undos,
|
33213 | redos = _history.redos;
|
33214 |
|
33215 | var next = redos.peek();
|
33216 | if (!next) return;
|
33217 |
|
33218 | // Shift the next state into the undo stack.
|
33219 | redos = redos.pop();
|
33220 | undos = undos.push(next);
|
33221 |
|
33222 | // Replay the next operations.
|
33223 | next.forEach(function (op) {
|
33224 | change.applyOperation(op, { save: false });
|
33225 | });
|
33226 |
|
33227 | // Update the history.
|
33228 | state = change.state;
|
33229 | history = history.set('undos', undos).set('redos', redos);
|
33230 | state = state.set('history', history);
|
33231 | change.state = state;
|
33232 | };
|
33233 |
|
33234 | /**
|
33235 | * Undo the previous operations in the history.
|
33236 | *
|
33237 | * @param {Change} change
|
33238 | */
|
33239 |
|
33240 | Changes.undo = function (change) {
|
33241 | var state = change.state;
|
33242 | var _state2 = state,
|
33243 | history = _state2.history;
|
33244 |
|
33245 | if (!history) return;
|
33246 |
|
33247 | var _history2 = history,
|
33248 | undos = _history2.undos,
|
33249 | redos = _history2.redos;
|
33250 |
|
33251 | var previous = undos.peek();
|
33252 | if (!previous) return;
|
33253 |
|
33254 | // Shift the previous operations into the redo stack.
|
33255 | undos = undos.pop();
|
33256 | redos = redos.push(previous);
|
33257 |
|
33258 | // Replay the inverse of the previous operations.
|
33259 | previous.slice().reverse().map(_invert2.default).forEach(function (inverse) {
|
33260 | change.applyOperation(inverse, { save: false });
|
33261 | });
|
33262 |
|
33263 | // Update the history.
|
33264 | state = change.state;
|
33265 | history = history.set('undos', undos).set('redos', redos);
|
33266 | state = state.set('history', history);
|
33267 | change.state = state;
|
33268 | };
|
33269 |
|
33270 | /**
|
33271 | * Export.
|
33272 | *
|
33273 | * @type {Object}
|
33274 | */
|
33275 |
|
33276 | exports.default = Changes;
|
33277 | },{"../operations/invert":348}],318:[function(require,module,exports){
|
33278 | 'use strict';
|
33279 |
|
33280 | Object.defineProperty(exports, "__esModule", {
|
33281 | value: true
|
33282 | });
|
33283 |
|
33284 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
33285 |
|
33286 | var _selection = require('../models/selection');
|
33287 |
|
33288 | var _selection2 = _interopRequireDefault(_selection);
|
33289 |
|
33290 | var _isEmpty = require('is-empty');
|
33291 |
|
33292 | var _isEmpty2 = _interopRequireDefault(_isEmpty);
|
33293 |
|
33294 | var _logger = require('../utils/logger');
|
33295 |
|
33296 | var _logger2 = _interopRequireDefault(_logger);
|
33297 |
|
33298 | var _pick = require('lodash/pick');
|
33299 |
|
33300 | var _pick2 = _interopRequireDefault(_pick);
|
33301 |
|
33302 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33303 |
|
33304 | /**
|
33305 | * Changes.
|
33306 | *
|
33307 | * @type {Object}
|
33308 | */
|
33309 |
|
33310 | var Changes = {};
|
33311 |
|
33312 | /**
|
33313 | * Set `properties` on the selection.
|
33314 | *
|
33315 | * @param {Change} change
|
33316 | * @param {Object} properties
|
33317 | */
|
33318 |
|
33319 | Changes.select = function (change, properties) {
|
33320 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
33321 |
|
33322 | properties = _selection2.default.createProperties(properties);
|
33323 |
|
33324 | var _options$snapshot = options.snapshot,
|
33325 | snapshot = _options$snapshot === undefined ? false : _options$snapshot;
|
33326 | var state = change.state;
|
33327 | var document = state.document,
|
33328 | selection = state.selection;
|
33329 |
|
33330 | var props = {};
|
33331 | var sel = selection.toJSON();
|
33332 | var next = selection.merge(properties).normalize(document);
|
33333 | properties = (0, _pick2.default)(next, Object.keys(properties));
|
33334 |
|
33335 | // Remove any properties that are already equal to the current selection. And
|
33336 | // create a dictionary of the previous values for all of the properties that
|
33337 | // are being changed, for the inverse operation.
|
33338 | for (var k in properties) {
|
33339 | if (snapshot == false && properties[k] == sel[k]) continue;
|
33340 | props[k] = properties[k];
|
33341 | }
|
33342 |
|
33343 | // Resolve the selection keys into paths.
|
33344 | sel.anchorPath = sel.anchorKey == null ? null : document.getPath(sel.anchorKey);
|
33345 | delete sel.anchorKey;
|
33346 |
|
33347 | if (props.anchorKey) {
|
33348 | props.anchorPath = props.anchorKey == null ? null : document.getPath(props.anchorKey);
|
33349 | delete props.anchorKey;
|
33350 | }
|
33351 |
|
33352 | sel.focusPath = sel.focusKey == null ? null : document.getPath(sel.focusKey);
|
33353 | delete sel.focusKey;
|
33354 |
|
33355 | if (props.focusKey) {
|
33356 | props.focusPath = props.focusKey == null ? null : document.getPath(props.focusKey);
|
33357 | delete props.focusKey;
|
33358 | }
|
33359 |
|
33360 | // If the selection moves, clear any marks, unless the new selection
|
33361 | // properties change the marks in some way.
|
33362 | var moved = ['anchorPath', 'anchorOffset', 'focusPath', 'focusOffset'].some(function (p) {
|
33363 | return props.hasOwnProperty(p);
|
33364 | });
|
33365 |
|
33366 | if (sel.marks && properties.marks == sel.marks && moved) {
|
33367 | props.marks = null;
|
33368 | }
|
33369 |
|
33370 | // If there are no new properties to set, abort.
|
33371 | if ((0, _isEmpty2.default)(props)) {
|
33372 | return;
|
33373 | }
|
33374 |
|
33375 | // Apply the operation.
|
33376 | change.applyOperation({
|
33377 | type: 'set_selection',
|
33378 | properties: props,
|
33379 | selection: sel
|
33380 | }, snapshot ? { skip: false, merge: false } : {});
|
33381 | };
|
33382 |
|
33383 | /**
|
33384 | * Select the whole document.
|
33385 | *
|
33386 | * @param {Change} change
|
33387 | */
|
33388 |
|
33389 | Changes.selectAll = function (change) {
|
33390 | var state = change.state;
|
33391 | var document = state.document,
|
33392 | selection = state.selection;
|
33393 |
|
33394 | var next = selection.moveToRangeOf(document);
|
33395 | change.select(next);
|
33396 | };
|
33397 |
|
33398 | /**
|
33399 | * Snapshot the current selection.
|
33400 | *
|
33401 | * @param {Change} change
|
33402 | */
|
33403 |
|
33404 | Changes.snapshotSelection = function (change) {
|
33405 | var state = change.state;
|
33406 | var selection = state.selection;
|
33407 |
|
33408 | change.select(selection, { snapshot: true });
|
33409 | };
|
33410 |
|
33411 | /**
|
33412 | * Set `properties` on the selection.
|
33413 | *
|
33414 | * @param {Mixed} ...args
|
33415 | * @param {Change} change
|
33416 | */
|
33417 |
|
33418 | Changes.moveTo = function (change, properties) {
|
33419 | _logger2.default.deprecate('0.17.0', 'The `moveTo()` change is deprecated, please use `select()` instead.');
|
33420 | change.select(properties);
|
33421 | };
|
33422 |
|
33423 | /**
|
33424 | * Unset the selection's marks.
|
33425 | *
|
33426 | * @param {Change} change
|
33427 | */
|
33428 |
|
33429 | Changes.unsetMarks = function (change) {
|
33430 | _logger2.default.deprecate('0.17.0', 'The `unsetMarks()` change is deprecated.');
|
33431 | change.select({ marks: null });
|
33432 | };
|
33433 |
|
33434 | /**
|
33435 | * Unset the selection, removing an association to a node.
|
33436 | *
|
33437 | * @param {Change} change
|
33438 | */
|
33439 |
|
33440 | Changes.unsetSelection = function (change) {
|
33441 | _logger2.default.deprecate('0.17.0', 'The `unsetSelection()` change is deprecated, please use `deselect()` instead.');
|
33442 | change.select({
|
33443 | anchorKey: null,
|
33444 | anchorOffset: 0,
|
33445 | focusKey: null,
|
33446 | focusOffset: 0,
|
33447 | isFocused: false,
|
33448 | isBackward: false
|
33449 | });
|
33450 | };
|
33451 |
|
33452 | /**
|
33453 | * Mix in selection changes that are just a proxy for the selection method.
|
33454 | */
|
33455 |
|
33456 | var PROXY_TRANSFORMS = ['blur', 'collapseTo', 'collapseToAnchor', 'collapseToEnd', 'collapseToEndOf', 'collapseToFocus', 'collapseToStart', 'collapseToStartOf', 'extend', 'extendTo', 'extendToEndOf', 'extendToStartOf', 'flip', 'focus', 'move', 'moveAnchor', 'moveAnchorOffsetTo', 'moveAnchorTo', 'moveAnchorToEndOf', 'moveAnchorToStartOf', 'moveEnd', 'moveEndOffsetTo', 'moveEndTo', 'moveFocus', 'moveFocusOffsetTo', 'moveFocusTo', 'moveFocusToEndOf', 'moveFocusToStartOf', 'moveOffsetsTo', 'moveStart', 'moveStartOffsetTo', 'moveStartTo',
|
33457 | // 'moveTo', Commented out for now, since it conflicts with a deprecated one.
|
33458 | 'moveToEnd', 'moveToEndOf', 'moveToRangeOf', 'moveToStart', 'moveToStartOf', 'deselect'];
|
33459 |
|
33460 | PROXY_TRANSFORMS.forEach(function (method) {
|
33461 | Changes[method] = function (change) {
|
33462 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
33463 | args[_key - 1] = arguments[_key];
|
33464 | }
|
33465 |
|
33466 | var normalize = method != 'deselect';
|
33467 | var state = change.state;
|
33468 | var document = state.document,
|
33469 | selection = state.selection;
|
33470 |
|
33471 | var next = selection[method].apply(selection, args);
|
33472 | if (normalize) next = next.normalize(document);
|
33473 | change.select(next);
|
33474 | };
|
33475 | });
|
33476 |
|
33477 | /**
|
33478 | * Mix in node-related changes.
|
33479 | */
|
33480 |
|
33481 | var PREFIXES = ['moveTo', 'collapseTo', 'extendTo'];
|
33482 |
|
33483 | var DIRECTIONS = ['Next', 'Previous'];
|
33484 |
|
33485 | var KINDS = ['Block', 'Inline', 'Text'];
|
33486 |
|
33487 | PREFIXES.forEach(function (prefix) {
|
33488 | var edges = ['Start', 'End'];
|
33489 |
|
33490 | if (prefix == 'moveTo') {
|
33491 | edges.push('Range');
|
33492 | }
|
33493 |
|
33494 | edges.forEach(function (edge) {
|
33495 | DIRECTIONS.forEach(function (direction) {
|
33496 | KINDS.forEach(function (kind) {
|
33497 | var get = 'get' + direction + kind;
|
33498 | var getAtRange = 'get' + kind + 'sAtRange';
|
33499 | var index = direction == 'Next' ? 'last' : 'first';
|
33500 | var method = '' + prefix + edge + 'Of';
|
33501 | var name = '' + method + direction + kind;
|
33502 |
|
33503 | Changes[name] = function (change) {
|
33504 | var state = change.state;
|
33505 | var document = state.document,
|
33506 | selection = state.selection;
|
33507 |
|
33508 | var nodes = document[getAtRange](selection);
|
33509 | var node = nodes[index]();
|
33510 | var target = document[get](node.key);
|
33511 | if (!target) return;
|
33512 | var next = selection[method](target);
|
33513 | change.select(next);
|
33514 | };
|
33515 | });
|
33516 | });
|
33517 | });
|
33518 | });
|
33519 |
|
33520 | /**
|
33521 | * Mix in deprecated changes with a warning.
|
33522 | */
|
33523 |
|
33524 | var DEPRECATED_TRANSFORMS = [['extendBackward', 'extend', 'The `extendBackward(n)` change is deprecated, please use `extend(n)` instead with a negative offset.'], ['extendForward', 'extend', 'The `extendForward(n)` change is deprecated, please use `extend(n)` instead.'], ['moveBackward', 'move', 'The `moveBackward(n)` change is deprecated, please use `move(n)` instead with a negative offset.'], ['moveForward', 'move', 'The `moveForward(n)` change is deprecated, please use `move(n)` instead.'], ['moveStartOffset', 'moveStart', 'The `moveStartOffset(n)` change is deprecated, please use `moveStart(n)` instead.'], ['moveEndOffset', 'moveEnd', 'The `moveEndOffset(n)` change is deprecated, please use `moveEnd()` instead.'], ['moveToOffsets', 'moveOffsetsTo', 'The `moveToOffsets()` change is deprecated, please use `moveOffsetsTo()` instead.'], ['flipSelection', 'flip', 'The `flipSelection()` change is deprecated, please use `flip()` instead.']];
|
33525 |
|
33526 | DEPRECATED_TRANSFORMS.forEach(function (_ref) {
|
33527 | var _ref2 = _slicedToArray(_ref, 3),
|
33528 | old = _ref2[0],
|
33529 | current = _ref2[1],
|
33530 | warning = _ref2[2];
|
33531 |
|
33532 | Changes[old] = function (change) {
|
33533 | for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
33534 | args[_key2 - 1] = arguments[_key2];
|
33535 | }
|
33536 |
|
33537 | _logger2.default.deprecate('0.17.0', warning);
|
33538 | var state = change.state;
|
33539 | var document = state.document,
|
33540 | selection = state.selection;
|
33541 |
|
33542 | var sel = selection[current].apply(selection, args).normalize(document);
|
33543 | change.select(sel);
|
33544 | };
|
33545 | });
|
33546 |
|
33547 | /**
|
33548 | * Export.
|
33549 | *
|
33550 | * @type {Object}
|
33551 | */
|
33552 |
|
33553 | exports.default = Changes;
|
33554 | },{"../models/selection":342,"../utils/logger":366,"is-empty":136,"lodash/pick":508}],319:[function(require,module,exports){
|
33555 | 'use strict';
|
33556 |
|
33557 | Object.defineProperty(exports, "__esModule", {
|
33558 | value: true
|
33559 | });
|
33560 |
|
33561 | /**
|
33562 | * Changes.
|
33563 | *
|
33564 | * @type {Object}
|
33565 | */
|
33566 |
|
33567 | var Changes = {};
|
33568 |
|
33569 | /**
|
33570 | * Set `properties` on the top-level state's data.
|
33571 | *
|
33572 | * @param {Change} change
|
33573 | * @param {Object} properties
|
33574 | */
|
33575 |
|
33576 | Changes.setData = function (change, properties) {
|
33577 | var state = change.state;
|
33578 | var data = state.data;
|
33579 |
|
33580 |
|
33581 | change.applyOperation({
|
33582 | type: 'set_data',
|
33583 | properties: properties,
|
33584 | data: data
|
33585 | });
|
33586 | };
|
33587 |
|
33588 | /**
|
33589 | * Export.
|
33590 | *
|
33591 | * @type {Object}
|
33592 | */
|
33593 |
|
33594 | exports.default = Changes;
|
33595 | },{}],320:[function(require,module,exports){
|
33596 | 'use strict';
|
33597 |
|
33598 | Object.defineProperty(exports, "__esModule", {
|
33599 | value: true
|
33600 | });
|
33601 |
|
33602 | 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; };
|
33603 |
|
33604 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
33605 |
|
33606 | var _debug = require('debug');
|
33607 |
|
33608 | var _debug2 = _interopRequireDefault(_debug);
|
33609 |
|
33610 | var _react = require('react');
|
33611 |
|
33612 | var _react2 = _interopRequireDefault(_react);
|
33613 |
|
33614 | var _propTypes = require('prop-types');
|
33615 |
|
33616 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
33617 |
|
33618 | var _getWindow = require('get-window');
|
33619 |
|
33620 | var _getWindow2 = _interopRequireDefault(_getWindow);
|
33621 |
|
33622 | var _keycode = require('keycode');
|
33623 |
|
33624 | var _keycode2 = _interopRequireDefault(_keycode);
|
33625 |
|
33626 | var _transferTypes = require('../constants/transfer-types');
|
33627 |
|
33628 | var _transferTypes2 = _interopRequireDefault(_transferTypes);
|
33629 |
|
33630 | var _base = require('../serializers/base-64');
|
33631 |
|
33632 | var _base2 = _interopRequireDefault(_base);
|
33633 |
|
33634 | var _node = require('./node');
|
33635 |
|
33636 | var _node2 = _interopRequireDefault(_node);
|
33637 |
|
33638 | var _selection = require('../models/selection');
|
33639 |
|
33640 | var _selection2 = _interopRequireDefault(_selection);
|
33641 |
|
33642 | var _propTypes3 = require('../utils/prop-types');
|
33643 |
|
33644 | var _propTypes4 = _interopRequireDefault(_propTypes3);
|
33645 |
|
33646 | var _extendSelection = require('../utils/extend-selection');
|
33647 |
|
33648 | var _extendSelection2 = _interopRequireDefault(_extendSelection);
|
33649 |
|
33650 | var _findClosestNode = require('../utils/find-closest-node');
|
33651 |
|
33652 | var _findClosestNode2 = _interopRequireDefault(_findClosestNode);
|
33653 |
|
33654 | var _getCaretPosition = require('../utils/get-caret-position');
|
33655 |
|
33656 | var _getCaretPosition2 = _interopRequireDefault(_getCaretPosition);
|
33657 |
|
33658 | var _getHtmlFromNativePaste = require('../utils/get-html-from-native-paste');
|
33659 |
|
33660 | var _getHtmlFromNativePaste2 = _interopRequireDefault(_getHtmlFromNativePaste);
|
33661 |
|
33662 | var _getPoint = require('../utils/get-point');
|
33663 |
|
33664 | var _getPoint2 = _interopRequireDefault(_getPoint);
|
33665 |
|
33666 | var _getTransferData = require('../utils/get-transfer-data');
|
33667 |
|
33668 | var _getTransferData2 = _interopRequireDefault(_getTransferData);
|
33669 |
|
33670 | var _setTransferData = require('../utils/set-transfer-data');
|
33671 |
|
33672 | var _setTransferData2 = _interopRequireDefault(_setTransferData);
|
33673 |
|
33674 | var _environment = require('../constants/environment');
|
33675 |
|
33676 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33677 |
|
33678 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
33679 |
|
33680 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
33681 |
|
33682 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
33683 |
|
33684 | /**
|
33685 | * Debug.
|
33686 | *
|
33687 | * @type {Function}
|
33688 | */
|
33689 |
|
33690 | var debug = (0, _debug2.default)('slate:content');
|
33691 |
|
33692 | /**
|
33693 | * Content.
|
33694 | *
|
33695 | * @type {Component}
|
33696 | */
|
33697 |
|
33698 | var Content = function (_React$Component) {
|
33699 | _inherits(Content, _React$Component);
|
33700 |
|
33701 | /**
|
33702 | * Constructor.
|
33703 | *
|
33704 | * @param {Object} props
|
33705 | */
|
33706 |
|
33707 | /**
|
33708 | * Property types.
|
33709 | *
|
33710 | * @type {Object}
|
33711 | */
|
33712 |
|
33713 | function Content(props) {
|
33714 | _classCallCheck(this, Content);
|
33715 |
|
33716 | var _this = _possibleConstructorReturn(this, (Content.__proto__ || Object.getPrototypeOf(Content)).call(this, props));
|
33717 |
|
33718 | _this.componentDidMount = function () {
|
33719 | _this.updateSelection();
|
33720 |
|
33721 | if (_this.props.autoFocus) {
|
33722 | _this.element.focus();
|
33723 | }
|
33724 | };
|
33725 |
|
33726 | _this.componentDidUpdate = function () {
|
33727 | _this.updateSelection();
|
33728 | };
|
33729 |
|
33730 | _this.updateSelection = function () {
|
33731 | var _this$props = _this.props,
|
33732 | editor = _this$props.editor,
|
33733 | state = _this$props.state;
|
33734 | var selection = state.selection;
|
33735 |
|
33736 | var window = (0, _getWindow2.default)(_this.element);
|
33737 | var native = window.getSelection();
|
33738 |
|
33739 | // If both selections are blurred, do nothing.
|
33740 | if (!native.rangeCount && selection.isBlurred) return;
|
33741 |
|
33742 | // If the selection has been blurred, but is still inside the editor in the
|
33743 | // DOM, blur it manually.
|
33744 | if (selection.isBlurred) {
|
33745 | if (!_this.isInEditor(native.anchorNode)) return;
|
33746 | native.removeAllRanges();
|
33747 | _this.element.blur();
|
33748 | debug('updateSelection', { selection: selection, native: native });
|
33749 | return;
|
33750 | }
|
33751 |
|
33752 | // If the selection isn't set, do nothing.
|
33753 | if (selection.isUnset) return;
|
33754 |
|
33755 | // Otherwise, figure out which DOM nodes should be selected...
|
33756 | var anchorKey = selection.anchorKey,
|
33757 | anchorOffset = selection.anchorOffset,
|
33758 | focusKey = selection.focusKey,
|
33759 | focusOffset = selection.focusOffset,
|
33760 | isCollapsed = selection.isCollapsed;
|
33761 |
|
33762 | var anchor = (0, _getCaretPosition2.default)(anchorKey, anchorOffset, state, editor, _this.element);
|
33763 | var focus = isCollapsed ? anchor : (0, _getCaretPosition2.default)(focusKey, focusOffset, state, editor, _this.element);
|
33764 |
|
33765 | // If they are already selected, do nothing.
|
33766 | if (anchor.node == native.anchorNode && anchor.offset == native.anchorOffset && focus.node == native.focusNode && focus.offset == native.focusOffset) {
|
33767 | return;
|
33768 | }
|
33769 |
|
33770 | // Otherwise, set the `isSelecting` flag and update the selection.
|
33771 | _this.tmp.isSelecting = true;
|
33772 | native.removeAllRanges();
|
33773 | var range = window.document.createRange();
|
33774 | range.setStart(anchor.node, anchor.offset);
|
33775 | native.addRange(range);
|
33776 | if (!isCollapsed) (0, _extendSelection2.default)(native, focus.node, focus.offset);
|
33777 |
|
33778 | // Then unset the `isSelecting` flag after a delay.
|
33779 | setTimeout(function () {
|
33780 | // COMPAT: In Firefox, it's not enough to create a range, you also need to
|
33781 | // focus the contenteditable element too. (2016/11/16)
|
33782 | if (_environment.IS_FIREFOX) _this.element.focus();
|
33783 | _this.tmp.isSelecting = false;
|
33784 | });
|
33785 |
|
33786 | debug('updateSelection', { selection: selection, native: native });
|
33787 | };
|
33788 |
|
33789 | _this.ref = function (element) {
|
33790 | _this.element = element;
|
33791 | };
|
33792 |
|
33793 | _this.isInEditor = function (target) {
|
33794 | var element = _this.element;
|
33795 | // COMPAT: Text nodes don't have `isContentEditable` property. So, when
|
33796 | // `target` is a text node use its parent node for check.
|
33797 |
|
33798 | var el = target.nodeType === 3 ? target.parentNode : target;
|
33799 | return el.isContentEditable && (el === element || (0, _findClosestNode2.default)(el, '[data-slate-editor]') === element);
|
33800 | };
|
33801 |
|
33802 | _this.onBeforeInput = function (event) {
|
33803 | if (_this.props.readOnly) return;
|
33804 | if (!_this.isInEditor(event.target)) return;
|
33805 |
|
33806 | var data = {};
|
33807 |
|
33808 | debug('onBeforeInput', { event: event, data: data });
|
33809 | _this.props.onBeforeInput(event, data);
|
33810 | };
|
33811 |
|
33812 | _this.onBlur = function (event) {
|
33813 | if (_this.props.readOnly) return;
|
33814 | if (_this.tmp.isCopying) return;
|
33815 | if (!_this.isInEditor(event.target)) return;
|
33816 |
|
33817 | // If the active element is still the editor, the blur event is due to the
|
33818 | // window itself being blurred (eg. when changing tabs) so we should ignore
|
33819 | // the event, since we want to maintain focus when returning.
|
33820 | var window = (0, _getWindow2.default)(_this.element);
|
33821 | if (window.document.activeElement == _this.element) return;
|
33822 |
|
33823 | var data = {};
|
33824 |
|
33825 | debug('onBlur', { event: event, data: data });
|
33826 | _this.props.onBlur(event, data);
|
33827 | };
|
33828 |
|
33829 | _this.onFocus = function (event) {
|
33830 | if (_this.props.readOnly) return;
|
33831 | if (_this.tmp.isCopying) return;
|
33832 | if (!_this.isInEditor(event.target)) return;
|
33833 |
|
33834 | // COMPAT: If the editor has nested editable elements, the focus can go to
|
33835 | // those elements. In Firefox, this must be prevented because it results in
|
33836 | // issues with keyboard navigation. (2017/03/30)
|
33837 | if (_environment.IS_FIREFOX && event.target != _this.element) {
|
33838 | _this.element.focus();
|
33839 | return;
|
33840 | }
|
33841 |
|
33842 | var data = {};
|
33843 |
|
33844 | debug('onFocus', { event: event, data: data });
|
33845 | _this.props.onFocus(event, data);
|
33846 | };
|
33847 |
|
33848 | _this.onCompositionStart = function (event) {
|
33849 | if (!_this.isInEditor(event.target)) return;
|
33850 |
|
33851 | _this.tmp.isComposing = true;
|
33852 | _this.tmp.compositions++;
|
33853 |
|
33854 | debug('onCompositionStart', { event: event });
|
33855 | };
|
33856 |
|
33857 | _this.onCompositionEnd = function (event) {
|
33858 | if (!_this.isInEditor(event.target)) return;
|
33859 |
|
33860 | _this.tmp.forces++;
|
33861 | var count = _this.tmp.compositions;
|
33862 |
|
33863 | // The `count` check here ensures that if another composition starts
|
33864 | // before the timeout has closed out this one, we will abort unsetting the
|
33865 | // `isComposing` flag, since a composition in still in affect.
|
33866 | setTimeout(function () {
|
33867 | if (_this.tmp.compositions > count) return;
|
33868 | _this.tmp.isComposing = false;
|
33869 | });
|
33870 |
|
33871 | debug('onCompositionEnd', { event: event });
|
33872 | };
|
33873 |
|
33874 | _this.onCopy = function (event) {
|
33875 | if (!_this.isInEditor(event.target)) return;
|
33876 | var window = (0, _getWindow2.default)(event.target);
|
33877 |
|
33878 | _this.tmp.isCopying = true;
|
33879 | window.requestAnimationFrame(function () {
|
33880 | _this.tmp.isCopying = false;
|
33881 | });
|
33882 |
|
33883 | var state = _this.props.state;
|
33884 |
|
33885 | var data = {};
|
33886 | data.type = 'fragment';
|
33887 | data.fragment = state.fragment;
|
33888 |
|
33889 | debug('onCopy', { event: event, data: data });
|
33890 | _this.props.onCopy(event, data);
|
33891 | };
|
33892 |
|
33893 | _this.onCut = function (event) {
|
33894 | if (_this.props.readOnly) return;
|
33895 | if (!_this.isInEditor(event.target)) return;
|
33896 | var window = (0, _getWindow2.default)(event.target);
|
33897 |
|
33898 | _this.tmp.isCopying = true;
|
33899 | window.requestAnimationFrame(function () {
|
33900 | _this.tmp.isCopying = false;
|
33901 | });
|
33902 |
|
33903 | var state = _this.props.state;
|
33904 |
|
33905 | var data = {};
|
33906 | data.type = 'fragment';
|
33907 | data.fragment = state.fragment;
|
33908 |
|
33909 | debug('onCut', { event: event, data: data });
|
33910 | _this.props.onCut(event, data);
|
33911 | };
|
33912 |
|
33913 | _this.onDragEnd = function (event) {
|
33914 | if (!_this.isInEditor(event.target)) return;
|
33915 |
|
33916 | _this.tmp.isDragging = false;
|
33917 | _this.tmp.isInternalDrag = null;
|
33918 |
|
33919 | debug('onDragEnd', { event: event });
|
33920 | };
|
33921 |
|
33922 | _this.onDragOver = function (event) {
|
33923 | if (!_this.isInEditor(event.target)) return;
|
33924 | if (_this.tmp.isDragging) return;
|
33925 | _this.tmp.isDragging = true;
|
33926 | _this.tmp.isInternalDrag = false;
|
33927 |
|
33928 | debug('onDragOver', { event: event });
|
33929 | };
|
33930 |
|
33931 | _this.onDragStart = function (event) {
|
33932 | if (!_this.isInEditor(event.target)) return;
|
33933 |
|
33934 | _this.tmp.isDragging = true;
|
33935 | _this.tmp.isInternalDrag = true;
|
33936 | var dataTransfer = event.nativeEvent.dataTransfer;
|
33937 |
|
33938 | var data = (0, _getTransferData2.default)(dataTransfer);
|
33939 |
|
33940 | // If it's a node being dragged, the data type is already set.
|
33941 | if (data.type == 'node') return;
|
33942 |
|
33943 | var state = _this.props.state;
|
33944 | var fragment = state.fragment;
|
33945 |
|
33946 | var encoded = _base2.default.serializeNode(fragment);
|
33947 |
|
33948 | (0, _setTransferData2.default)(dataTransfer, _transferTypes2.default.FRAGMENT, encoded);
|
33949 |
|
33950 | debug('onDragStart', { event: event });
|
33951 | };
|
33952 |
|
33953 | _this.onDrop = function (event) {
|
33954 | event.preventDefault();
|
33955 |
|
33956 | if (_this.props.readOnly) return;
|
33957 | if (!_this.isInEditor(event.target)) return;
|
33958 |
|
33959 | var window = (0, _getWindow2.default)(event.target);
|
33960 | var _this$props2 = _this.props,
|
33961 | state = _this$props2.state,
|
33962 | editor = _this$props2.editor;
|
33963 | var nativeEvent = event.nativeEvent;
|
33964 | var dataTransfer = nativeEvent.dataTransfer,
|
33965 | x = nativeEvent.x,
|
33966 | y = nativeEvent.y;
|
33967 |
|
33968 | var data = (0, _getTransferData2.default)(dataTransfer);
|
33969 |
|
33970 | // Resolve the point where the drop occured.
|
33971 | var range = void 0;
|
33972 |
|
33973 | // COMPAT: In Firefox, `caretRangeFromPoint` doesn't exist. (2016/07/25)
|
33974 | if (window.document.caretRangeFromPoint) {
|
33975 | range = window.document.caretRangeFromPoint(x, y);
|
33976 | } else {
|
33977 | range = window.document.createRange();
|
33978 | range.setStart(nativeEvent.rangeParent, nativeEvent.rangeOffset);
|
33979 | }
|
33980 |
|
33981 | var _range = range,
|
33982 | startContainer = _range.startContainer,
|
33983 | startOffset = _range.startOffset;
|
33984 |
|
33985 | var point = (0, _getPoint2.default)(startContainer, startOffset, state, editor);
|
33986 | if (!point) return;
|
33987 |
|
33988 | var target = _selection2.default.create({
|
33989 | anchorKey: point.key,
|
33990 | anchorOffset: point.offset,
|
33991 | focusKey: point.key,
|
33992 | focusOffset: point.offset,
|
33993 | isFocused: true
|
33994 | });
|
33995 |
|
33996 | // Add drop-specific information to the data.
|
33997 | data.target = target;
|
33998 |
|
33999 | // COMPAT: Edge throws "Permission denied" errors when
|
34000 | // accessing `dropEffect` or `effectAllowed` (2017/7/12)
|
34001 | try {
|
34002 | data.effect = dataTransfer.dropEffect;
|
34003 | } catch (err) {
|
34004 | data.effect = null;
|
34005 | }
|
34006 |
|
34007 | if (data.type == 'fragment' || data.type == 'node') {
|
34008 | data.isInternal = _this.tmp.isInternalDrag;
|
34009 | }
|
34010 |
|
34011 | debug('onDrop', { event: event, data: data });
|
34012 | _this.props.onDrop(event, data);
|
34013 | };
|
34014 |
|
34015 | _this.onInput = function (event) {
|
34016 | if (_this.tmp.isComposing) return;
|
34017 | if (_this.props.state.isBlurred) return;
|
34018 | if (!_this.isInEditor(event.target)) return;
|
34019 | debug('onInput', { event: event });
|
34020 |
|
34021 | var window = (0, _getWindow2.default)(event.target);
|
34022 | var _this$props3 = _this.props,
|
34023 | state = _this$props3.state,
|
34024 | editor = _this$props3.editor;
|
34025 |
|
34026 | // Get the selection point.
|
34027 |
|
34028 | var native = window.getSelection();
|
34029 | var anchorNode = native.anchorNode,
|
34030 | anchorOffset = native.anchorOffset;
|
34031 |
|
34032 | var point = (0, _getPoint2.default)(anchorNode, anchorOffset, state, editor);
|
34033 | if (!point) return;
|
34034 |
|
34035 | // Get the range in question.
|
34036 | var key = point.key,
|
34037 | index = point.index,
|
34038 | start = point.start,
|
34039 | end = point.end;
|
34040 | var document = state.document,
|
34041 | selection = state.selection;
|
34042 |
|
34043 | var schema = editor.getSchema();
|
34044 | var decorators = document.getDescendantDecorators(key, schema);
|
34045 | var node = document.getDescendant(key);
|
34046 | var block = document.getClosestBlock(node.key);
|
34047 | var ranges = node.getRanges(decorators);
|
34048 | var lastText = block.getLastText();
|
34049 |
|
34050 | // Get the text information.
|
34051 | var textContent = anchorNode.textContent;
|
34052 |
|
34053 | var lastChar = textContent.charAt(textContent.length - 1);
|
34054 | var isLastText = node == lastText;
|
34055 | var isLastRange = index == ranges.size - 1;
|
34056 |
|
34057 | // If we're dealing with the last leaf, and the DOM text ends in a new line,
|
34058 | // we will have added another new line in <Leaf>'s render method to account
|
34059 | // for browsers collapsing a single trailing new lines, so remove it.
|
34060 | if (isLastText && isLastRange && lastChar == '\n') {
|
34061 | textContent = textContent.slice(0, -1);
|
34062 | }
|
34063 |
|
34064 | // If the text is no different, abort.
|
34065 | var range = ranges.get(index);
|
34066 | var text = range.text,
|
34067 | marks = range.marks;
|
34068 |
|
34069 | if (textContent == text) return;
|
34070 |
|
34071 | // Determine what the selection should be after changing the text.
|
34072 | var delta = textContent.length - text.length;
|
34073 | var after = selection.collapseToEnd().move(delta);
|
34074 |
|
34075 | // Change the current state to have the text replaced.
|
34076 | editor.change(function (change) {
|
34077 | change.select({
|
34078 | anchorKey: key,
|
34079 | anchorOffset: start,
|
34080 | focusKey: key,
|
34081 | focusOffset: end
|
34082 | }).delete().insertText(textContent, marks).select(after);
|
34083 | });
|
34084 | };
|
34085 |
|
34086 | _this.onKeyDown = function (event) {
|
34087 | if (_this.props.readOnly) return;
|
34088 | if (!_this.isInEditor(event.target)) return;
|
34089 |
|
34090 | var altKey = event.altKey,
|
34091 | ctrlKey = event.ctrlKey,
|
34092 | metaKey = event.metaKey,
|
34093 | shiftKey = event.shiftKey,
|
34094 | which = event.which;
|
34095 |
|
34096 | var key = (0, _keycode2.default)(which);
|
34097 | var data = {};
|
34098 |
|
34099 | // Keep track of an `isShifting` flag, because it's often used to trigger
|
34100 | // "Paste and Match Style" commands, but isn't available on the event in a
|
34101 | // normal paste event.
|
34102 | if (key == 'shift') {
|
34103 | _this.tmp.isShifting = true;
|
34104 | }
|
34105 |
|
34106 | // When composing, these characters commit the composition but also move the
|
34107 | // selection before we're able to handle it, so prevent their default,
|
34108 | // selection-moving behavior.
|
34109 | if (_this.tmp.isComposing && (key == 'left' || key == 'right' || key == 'up' || key == 'down')) {
|
34110 | event.preventDefault();
|
34111 | return;
|
34112 | }
|
34113 |
|
34114 | // Add helpful properties for handling hotkeys to the data object.
|
34115 | data.code = which;
|
34116 | data.key = key;
|
34117 | data.isAlt = altKey;
|
34118 | data.isCmd = _environment.IS_MAC ? metaKey && !altKey : false;
|
34119 | data.isCtrl = ctrlKey && !altKey;
|
34120 | data.isLine = _environment.IS_MAC ? metaKey : false;
|
34121 | data.isMeta = metaKey;
|
34122 | data.isMod = _environment.IS_MAC ? metaKey && !altKey : ctrlKey && !altKey;
|
34123 | data.isModAlt = _environment.IS_MAC ? metaKey && altKey : ctrlKey && altKey;
|
34124 | data.isShift = shiftKey;
|
34125 | data.isWord = _environment.IS_MAC ? altKey : ctrlKey;
|
34126 |
|
34127 | // These key commands have native behavior in contenteditable elements which
|
34128 | // will cause our state to be out of sync, so prevent them.
|
34129 | if (key == 'enter' || key == 'backspace' || key == 'delete' || key == 'b' && data.isMod || key == 'i' && data.isMod || key == 'y' && data.isMod || key == 'z' && data.isMod) {
|
34130 | event.preventDefault();
|
34131 | }
|
34132 |
|
34133 | debug('onKeyDown', { event: event, data: data });
|
34134 | _this.props.onKeyDown(event, data);
|
34135 | };
|
34136 |
|
34137 | _this.onKeyUp = function (event) {
|
34138 | var altKey = event.altKey,
|
34139 | ctrlKey = event.ctrlKey,
|
34140 | metaKey = event.metaKey,
|
34141 | shiftKey = event.shiftKey,
|
34142 | which = event.which;
|
34143 |
|
34144 | var key = (0, _keycode2.default)(which);
|
34145 | var data = {};
|
34146 |
|
34147 | if (key == 'shift') {
|
34148 | _this.tmp.isShifting = false;
|
34149 | }
|
34150 |
|
34151 | // Add helpful properties for handling hotkeys to the data object.
|
34152 | data.code = which;
|
34153 | data.key = key;
|
34154 | data.isAlt = altKey;
|
34155 | data.isCmd = _environment.IS_MAC ? metaKey && !altKey : false;
|
34156 | data.isCtrl = ctrlKey && !altKey;
|
34157 | data.isLine = _environment.IS_MAC ? metaKey : false;
|
34158 | data.isMeta = metaKey;
|
34159 | data.isMod = _environment.IS_MAC ? metaKey && !altKey : ctrlKey && !altKey;
|
34160 | data.isModAlt = _environment.IS_MAC ? metaKey && altKey : ctrlKey && altKey;
|
34161 | data.isShift = shiftKey;
|
34162 | data.isWord = _environment.IS_MAC ? altKey : ctrlKey;
|
34163 |
|
34164 | debug('onKeyUp', { event: event, data: data });
|
34165 | _this.props.onKeyUp(event, data);
|
34166 | };
|
34167 |
|
34168 | _this.onPaste = function (event) {
|
34169 | if (_this.props.readOnly) return;
|
34170 | if (!_this.isInEditor(event.target)) return;
|
34171 |
|
34172 | var data = (0, _getTransferData2.default)(event.clipboardData);
|
34173 |
|
34174 | // Attach the `isShift` flag, so that people can use it to trigger "Paste
|
34175 | // and Match Style" logic.
|
34176 | data.isShift = !!_this.tmp.isShifting;
|
34177 | debug('onPaste', { event: event, data: data });
|
34178 |
|
34179 | // COMPAT: In IE 11, only plain text can be retrieved from the event's
|
34180 | // `clipboardData`. To get HTML, use the browser's native paste action which
|
34181 | // can only be handled synchronously. (2017/06/23)
|
34182 | if (_environment.IS_IE) {
|
34183 | // Do not use `event.preventDefault()` as we need the native paste action.
|
34184 | (0, _getHtmlFromNativePaste2.default)(event.target, function (html) {
|
34185 | // If pasted HTML can be retreived, it is added to the `data` object,
|
34186 | // setting the `type` to `html`.
|
34187 | _this.props.onPaste(event, html === undefined ? data : _extends({}, data, { html: html, type: 'html' }));
|
34188 | });
|
34189 | } else {
|
34190 | event.preventDefault();
|
34191 | _this.props.onPaste(event, data);
|
34192 | }
|
34193 | };
|
34194 |
|
34195 | _this.onSelect = function (event) {
|
34196 | if (_this.props.readOnly) return;
|
34197 | if (_this.tmp.isCopying) return;
|
34198 | if (_this.tmp.isComposing) return;
|
34199 | if (_this.tmp.isSelecting) return;
|
34200 | if (!_this.isInEditor(event.target)) return;
|
34201 |
|
34202 | var window = (0, _getWindow2.default)(event.target);
|
34203 | var _this$props4 = _this.props,
|
34204 | state = _this$props4.state,
|
34205 | editor = _this$props4.editor;
|
34206 | var document = state.document,
|
34207 | selection = state.selection;
|
34208 |
|
34209 | var native = window.getSelection();
|
34210 | var data = {};
|
34211 |
|
34212 | // If there are no ranges, the editor was blurred natively.
|
34213 | if (!native.rangeCount) {
|
34214 | data.selection = selection.set('isFocused', false);
|
34215 | }
|
34216 |
|
34217 | // Otherwise, determine the Slate selection from the native one.
|
34218 | else {
|
34219 | var anchorNode = native.anchorNode,
|
34220 | anchorOffset = native.anchorOffset,
|
34221 | focusNode = native.focusNode,
|
34222 | focusOffset = native.focusOffset;
|
34223 |
|
34224 | var anchor = (0, _getPoint2.default)(anchorNode, anchorOffset, state, editor);
|
34225 | var focus = (0, _getPoint2.default)(focusNode, focusOffset, state, editor);
|
34226 | if (!anchor || !focus) return;
|
34227 |
|
34228 | // There are situations where a select event will fire with a new native
|
34229 | // selection that resolves to the same internal position. In those cases
|
34230 | // we don't need to trigger any changes, since our internal model is
|
34231 | // already up to date, but we do want to update the native selection again
|
34232 | // to make sure it is in sync.
|
34233 | if (anchor.key == selection.anchorKey && anchor.offset == selection.anchorOffset && focus.key == selection.focusKey && focus.offset == selection.focusOffset && selection.isFocused) {
|
34234 | _this.updateSelection();
|
34235 | return;
|
34236 | }
|
34237 |
|
34238 | var properties = {
|
34239 | anchorKey: anchor.key,
|
34240 | anchorOffset: anchor.offset,
|
34241 | focusKey: focus.key,
|
34242 | focusOffset: focus.offset,
|
34243 | isFocused: true,
|
34244 | isBackward: null
|
34245 | };
|
34246 |
|
34247 | var anchorText = document.getNode(anchor.key);
|
34248 | var focusText = document.getNode(focus.key);
|
34249 | var anchorInline = document.getClosestInline(anchor.key);
|
34250 | var focusInline = document.getClosestInline(focus.key);
|
34251 | var focusBlock = document.getClosestBlock(focus.key);
|
34252 | var anchorBlock = document.getClosestBlock(anchor.key);
|
34253 |
|
34254 | // COMPAT: If the anchor point is at the start of a non-void, and the
|
34255 | // focus point is inside a void node with an offset that isn't `0`, set
|
34256 | // the focus offset to `0`. This is due to void nodes <span>'s being
|
34257 | // positioned off screen, resulting in the offset always being greater
|
34258 | // than `0`. Since we can't know what it really should be, and since an
|
34259 | // offset of `0` is less destructive because it creates a hanging
|
34260 | // selection, go with `0`. (2017/09/07)
|
34261 | if (anchorBlock && !anchorBlock.isVoid && anchor.offset == 0 && focusBlock && focusBlock.isVoid && focus.offset != 0) {
|
34262 | properties.focusOffset = 0;
|
34263 | }
|
34264 |
|
34265 | // COMPAT: If the selection is at the end of a non-void inline node, and
|
34266 | // there is a node after it, put it in the node after instead. This
|
34267 | // standardizes the behavior, since it's indistinguishable to the user.
|
34268 | if (anchorInline && !anchorInline.isVoid && anchor.offset == anchorText.text.length) {
|
34269 | var block = document.getClosestBlock(anchor.key);
|
34270 | var next = block.getNextText(anchor.key);
|
34271 | if (next) {
|
34272 | properties.anchorKey = next.key;
|
34273 | properties.anchorOffset = 0;
|
34274 | }
|
34275 | }
|
34276 |
|
34277 | if (focusInline && !focusInline.isVoid && focus.offset == focusText.text.length) {
|
34278 | var _block = document.getClosestBlock(focus.key);
|
34279 | var _next = _block.getNextText(focus.key);
|
34280 | if (_next) {
|
34281 | properties.focusKey = _next.key;
|
34282 | properties.focusOffset = 0;
|
34283 | }
|
34284 | }
|
34285 |
|
34286 | data.selection = selection.merge(properties).normalize(document);
|
34287 | }
|
34288 |
|
34289 | debug('onSelect', { event: event, data: data });
|
34290 | _this.props.onSelect(event, data);
|
34291 | };
|
34292 |
|
34293 | _this.renderNode = function (child, isSelected) {
|
34294 | var _this$props5 = _this.props,
|
34295 | editor = _this$props5.editor,
|
34296 | readOnly = _this$props5.readOnly,
|
34297 | schema = _this$props5.schema,
|
34298 | state = _this$props5.state;
|
34299 | var document = state.document;
|
34300 |
|
34301 | return _react2.default.createElement(_node2.default, {
|
34302 | block: null,
|
34303 | editor: editor,
|
34304 | isSelected: isSelected,
|
34305 | key: child.key,
|
34306 | node: child,
|
34307 | parent: document,
|
34308 | readOnly: readOnly,
|
34309 | schema: schema,
|
34310 | state: state
|
34311 | });
|
34312 | };
|
34313 |
|
34314 | _this.tmp = {};
|
34315 | _this.tmp.compositions = 0;
|
34316 | _this.tmp.forces = 0;
|
34317 | return _this;
|
34318 | }
|
34319 |
|
34320 | /**
|
34321 | * When the editor first mounts in the DOM we need to:
|
34322 | *
|
34323 | * - Update the selection, in case it starts focused.
|
34324 | * - Focus the editor if `autoFocus` is set.
|
34325 | */
|
34326 |
|
34327 | /**
|
34328 | * Default properties.
|
34329 | *
|
34330 | * @type {Object}
|
34331 | */
|
34332 |
|
34333 | /**
|
34334 | * On update, update the selection.
|
34335 | */
|
34336 |
|
34337 | /**
|
34338 | * Update the native DOM selection to reflect the internal model.
|
34339 | */
|
34340 |
|
34341 | /**
|
34342 | * The React ref method to set the root content element locally.
|
34343 | *
|
34344 | * @param {Element} element
|
34345 | */
|
34346 |
|
34347 | /**
|
34348 | * Check if an event `target` is fired from within the contenteditable
|
34349 | * element. This should be false for edits happening in non-contenteditable
|
34350 | * children, such as void nodes and other nested Slate editors.
|
34351 | *
|
34352 | * @param {Element} target
|
34353 | * @return {Boolean}
|
34354 | */
|
34355 |
|
34356 | /**
|
34357 | * On before input, bubble up.
|
34358 | *
|
34359 | * @param {Event} event
|
34360 | */
|
34361 |
|
34362 | /**
|
34363 | * On blur, update the selection to be not focused.
|
34364 | *
|
34365 | * @param {Event} event
|
34366 | */
|
34367 |
|
34368 | /**
|
34369 | * On focus, update the selection to be focused.
|
34370 | *
|
34371 | * @param {Event} event
|
34372 | */
|
34373 |
|
34374 | /**
|
34375 | * On composition start, set the `isComposing` flag.
|
34376 | *
|
34377 | * @param {Event} event
|
34378 | */
|
34379 |
|
34380 | /**
|
34381 | * On composition end, remove the `isComposing` flag on the next tick. Also
|
34382 | * increment the `forces` key, which will force the contenteditable element
|
34383 | * to completely re-render, since IME puts React in an unreconcilable state.
|
34384 | *
|
34385 | * @param {Event} event
|
34386 | */
|
34387 |
|
34388 | /**
|
34389 | * On copy, defer to `onCutCopy`, then bubble up.
|
34390 | *
|
34391 | * @param {Event} event
|
34392 | */
|
34393 |
|
34394 | /**
|
34395 | * On cut, defer to `onCutCopy`, then bubble up.
|
34396 | *
|
34397 | * @param {Event} event
|
34398 | */
|
34399 |
|
34400 | /**
|
34401 | * On drag end, unset the `isDragging` flag.
|
34402 | *
|
34403 | * @param {Event} event
|
34404 | */
|
34405 |
|
34406 | /**
|
34407 | * On drag over, set the `isDragging` flag and the `isInternalDrag` flag.
|
34408 | *
|
34409 | * @param {Event} event
|
34410 | */
|
34411 |
|
34412 | /**
|
34413 | * On drag start, set the `isDragging` flag and the `isInternalDrag` flag.
|
34414 | *
|
34415 | * @param {Event} event
|
34416 | */
|
34417 |
|
34418 | /**
|
34419 | * On drop.
|
34420 | *
|
34421 | * @param {Event} event
|
34422 | */
|
34423 |
|
34424 | /**
|
34425 | * On input, handle spellcheck and other similar edits that don't go trigger
|
34426 | * the `onBeforeInput` and instead update the DOM directly.
|
34427 | *
|
34428 | * @param {Event} event
|
34429 | */
|
34430 |
|
34431 | /**
|
34432 | * On key down, prevent the default behavior of certain commands that will
|
34433 | * leave the editor in an out-of-sync state, then bubble up.
|
34434 | *
|
34435 | * @param {Event} event
|
34436 | */
|
34437 |
|
34438 | /**
|
34439 | * On key up, unset the `isShifting` flag.
|
34440 | *
|
34441 | * @param {Event} event
|
34442 | */
|
34443 |
|
34444 | /**
|
34445 | * On paste, determine the type and bubble up.
|
34446 | *
|
34447 | * @param {Event} event
|
34448 | */
|
34449 |
|
34450 | /**
|
34451 | * On select, update the current state's selection.
|
34452 | *
|
34453 | * @param {Event} event
|
34454 | */
|
34455 |
|
34456 | _createClass(Content, [{
|
34457 | key: 'render',
|
34458 |
|
34459 |
|
34460 | /**
|
34461 | * Render the editor content.
|
34462 | *
|
34463 | * @return {Element}
|
34464 | */
|
34465 |
|
34466 | value: function render() {
|
34467 | var _this2 = this;
|
34468 |
|
34469 | var props = this.props;
|
34470 | var className = props.className,
|
34471 | readOnly = props.readOnly,
|
34472 | state = props.state,
|
34473 | tabIndex = props.tabIndex,
|
34474 | role = props.role,
|
34475 | tagName = props.tagName;
|
34476 |
|
34477 | var Container = tagName;
|
34478 | var document = state.document,
|
34479 | selection = state.selection;
|
34480 |
|
34481 | var indexes = document.getSelectionIndexes(selection, selection.isFocused);
|
34482 | var children = document.nodes.toArray().map(function (child, i) {
|
34483 | var isSelected = !!indexes && indexes.start <= i && i < indexes.end;
|
34484 | return _this2.renderNode(child, isSelected);
|
34485 | });
|
34486 |
|
34487 | var style = _extends({
|
34488 | // Prevent the default outline styles.
|
34489 | outline: 'none',
|
34490 | // Preserve adjacent whitespace and new lines.
|
34491 | whiteSpace: 'pre-wrap',
|
34492 | // Allow words to break if they are too long.
|
34493 | wordWrap: 'break-word'
|
34494 | }, readOnly ? {} : { WebkitUserModify: 'read-write-plaintext-only' }, props.style);
|
34495 |
|
34496 | // COMPAT: In Firefox, spellchecking can remove entire wrapping elements
|
34497 | // including inline ones like `<a>`, which is jarring for the user but also
|
34498 | // causes the DOM to get into an irreconcilable state. (2016/09/01)
|
34499 | var spellCheck = _environment.IS_FIREFOX ? false : props.spellCheck;
|
34500 |
|
34501 | debug('render', { props: props });
|
34502 |
|
34503 | return _react2.default.createElement(
|
34504 | Container,
|
34505 | {
|
34506 | 'data-slate-editor': true,
|
34507 | key: this.tmp.forces,
|
34508 | ref: this.ref,
|
34509 | 'data-key': document.key,
|
34510 | contentEditable: !readOnly,
|
34511 | suppressContentEditableWarning: true,
|
34512 | className: className,
|
34513 | onBeforeInput: this.onBeforeInput,
|
34514 | onBlur: this.onBlur,
|
34515 | onFocus: this.onFocus,
|
34516 | onCompositionEnd: this.onCompositionEnd,
|
34517 | onCompositionStart: this.onCompositionStart,
|
34518 | onCopy: this.onCopy,
|
34519 | onCut: this.onCut,
|
34520 | onDragEnd: this.onDragEnd,
|
34521 | onDragOver: this.onDragOver,
|
34522 | onDragStart: this.onDragStart,
|
34523 | onDrop: this.onDrop,
|
34524 | onInput: this.onInput,
|
34525 | onKeyDown: this.onKeyDown,
|
34526 | onKeyUp: this.onKeyUp,
|
34527 | onPaste: this.onPaste,
|
34528 | onSelect: this.onSelect,
|
34529 | autoCorrect: props.autoCorrect,
|
34530 | spellCheck: spellCheck,
|
34531 | style: style,
|
34532 | role: readOnly ? null : role || 'textbox',
|
34533 | tabIndex: tabIndex
|
34534 | // COMPAT: The Grammarly Chrome extension works by changing the DOM out
|
34535 | // from under `contenteditable` elements, which leads to weird behaviors
|
34536 | // so we have to disable it like this. (2017/04/24)
|
34537 | , 'data-gramm': false
|
34538 | },
|
34539 | children,
|
34540 | this.props.children
|
34541 | );
|
34542 | }
|
34543 |
|
34544 | /**
|
34545 | * Render a `child` node of the document.
|
34546 | *
|
34547 | * @param {Node} child
|
34548 | * @param {Boolean} isSelected
|
34549 | * @return {Element}
|
34550 | */
|
34551 |
|
34552 | }]);
|
34553 |
|
34554 | return Content;
|
34555 | }(_react2.default.Component);
|
34556 |
|
34557 | /**
|
34558 | * Export.
|
34559 | *
|
34560 | * @type {Component}
|
34561 | */
|
34562 |
|
34563 | Content.propTypes = {
|
34564 | autoCorrect: _propTypes2.default.bool.isRequired,
|
34565 | autoFocus: _propTypes2.default.bool.isRequired,
|
34566 | children: _propTypes2.default.array.isRequired,
|
34567 | className: _propTypes2.default.string,
|
34568 | editor: _propTypes2.default.object.isRequired,
|
34569 | onBeforeInput: _propTypes2.default.func.isRequired,
|
34570 | onBlur: _propTypes2.default.func.isRequired,
|
34571 | onCopy: _propTypes2.default.func.isRequired,
|
34572 | onCut: _propTypes2.default.func.isRequired,
|
34573 | onDrop: _propTypes2.default.func.isRequired,
|
34574 | onFocus: _propTypes2.default.func.isRequired,
|
34575 | onKeyDown: _propTypes2.default.func.isRequired,
|
34576 | onKeyUp: _propTypes2.default.func.isRequired,
|
34577 | onPaste: _propTypes2.default.func.isRequired,
|
34578 | onSelect: _propTypes2.default.func.isRequired,
|
34579 | readOnly: _propTypes2.default.bool.isRequired,
|
34580 | role: _propTypes2.default.string,
|
34581 | schema: _propTypes4.default.schema.isRequired,
|
34582 | spellCheck: _propTypes2.default.bool.isRequired,
|
34583 | state: _propTypes4.default.state.isRequired,
|
34584 | style: _propTypes2.default.object,
|
34585 | tabIndex: _propTypes2.default.number,
|
34586 | tagName: _propTypes2.default.string
|
34587 | };
|
34588 | Content.defaultProps = {
|
34589 | style: {},
|
34590 | tagName: 'div'
|
34591 | };
|
34592 | exports.default = Content;
|
34593 | },{"../constants/environment":326,"../constants/transfer-types":329,"../models/selection":342,"../serializers/base-64":351,"../utils/extend-selection":355,"../utils/find-closest-node":356,"../utils/get-caret-position":360,"../utils/get-html-from-native-paste":361,"../utils/get-point":362,"../utils/get-transfer-data":363,"../utils/prop-types":371,"../utils/set-transfer-data":373,"./node":323,"debug":375,"get-window":133,"keycode":141,"prop-types":148,"react":309}],321:[function(require,module,exports){
|
34594 | 'use strict';
|
34595 |
|
34596 | Object.defineProperty(exports, "__esModule", {
|
34597 | value: true
|
34598 | });
|
34599 |
|
34600 | 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; };
|
34601 |
|
34602 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
34603 |
|
34604 | var _debug = require('debug');
|
34605 |
|
34606 | var _debug2 = _interopRequireDefault(_debug);
|
34607 |
|
34608 | var _reactPortal = require('react-portal');
|
34609 |
|
34610 | var _reactPortal2 = _interopRequireDefault(_reactPortal);
|
34611 |
|
34612 | var _react = require('react');
|
34613 |
|
34614 | var _react2 = _interopRequireDefault(_react);
|
34615 |
|
34616 | var _propTypes = require('prop-types');
|
34617 |
|
34618 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
34619 |
|
34620 | var _stack = require('../models/stack');
|
34621 |
|
34622 | var _stack2 = _interopRequireDefault(_stack);
|
34623 |
|
34624 | var _state = require('../models/state');
|
34625 |
|
34626 | var _state2 = _interopRequireDefault(_state);
|
34627 |
|
34628 | var _propTypes3 = require('../utils/prop-types');
|
34629 |
|
34630 | var _propTypes4 = _interopRequireDefault(_propTypes3);
|
34631 |
|
34632 | var _logger = require('../utils/logger');
|
34633 |
|
34634 | var _logger2 = _interopRequireDefault(_logger);
|
34635 |
|
34636 | var _noop = require('../utils/noop');
|
34637 |
|
34638 | var _noop2 = _interopRequireDefault(_noop);
|
34639 |
|
34640 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
34641 |
|
34642 | function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
34643 |
|
34644 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
34645 |
|
34646 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
34647 |
|
34648 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
34649 |
|
34650 | /**
|
34651 | * Debug.
|
34652 | *
|
34653 | * @type {Function}
|
34654 | */
|
34655 |
|
34656 | var debug = (0, _debug2.default)('slate:editor');
|
34657 |
|
34658 | /**
|
34659 | * Event handlers to mix in to the editor.
|
34660 | *
|
34661 | * @type {Array}
|
34662 | */
|
34663 |
|
34664 | var EVENT_HANDLERS = ['onBeforeInput', 'onBlur', 'onFocus', 'onCopy', 'onCut', 'onDrop', 'onKeyDown', 'onKeyUp', 'onPaste', 'onSelect'];
|
34665 |
|
34666 | /**
|
34667 | * Plugin-related properties of the editor.
|
34668 | *
|
34669 | * @type {Array}
|
34670 | */
|
34671 |
|
34672 | var PLUGINS_PROPS = [].concat(EVENT_HANDLERS, ['placeholder', 'placeholderClassName', 'placeholderStyle', 'plugins', 'schema']);
|
34673 |
|
34674 | /**
|
34675 | * Editor.
|
34676 | *
|
34677 | * @type {Component}
|
34678 | */
|
34679 |
|
34680 | var Editor = function (_React$Component) {
|
34681 | _inherits(Editor, _React$Component);
|
34682 |
|
34683 | /**
|
34684 | * When constructed, create a new `Stack` and run `onBeforeChange`.
|
34685 | *
|
34686 | * @param {Object} props
|
34687 | */
|
34688 |
|
34689 | /**
|
34690 | * Property types.
|
34691 | *
|
34692 | * @type {Object}
|
34693 | */
|
34694 |
|
34695 | function Editor(props) {
|
34696 | _classCallCheck(this, Editor);
|
34697 |
|
34698 | var _this = _possibleConstructorReturn(this, (Editor.__proto__ || Object.getPrototypeOf(Editor)).call(this, props));
|
34699 |
|
34700 | _initialiseProps.call(_this);
|
34701 |
|
34702 | _this.tmp = {};
|
34703 | _this.state = {};
|
34704 |
|
34705 | // Create a new `Stack`, omitting the `onChange` property since that has
|
34706 | // special significance on the editor itself.
|
34707 |
|
34708 | var state = props.state,
|
34709 | onChange = props.onChange,
|
34710 | rest = _objectWithoutProperties(props, ['state', 'onChange']); // eslint-disable-line no-unused-vars
|
34711 |
|
34712 |
|
34713 | var stack = _stack2.default.create(rest);
|
34714 | _this.state.stack = stack;
|
34715 |
|
34716 | // Cache and set the state.
|
34717 | _this.cacheState(state);
|
34718 | _this.state.state = state;
|
34719 |
|
34720 | // Create a bound event handler for each event.
|
34721 |
|
34722 | var _loop = function _loop(i) {
|
34723 | var method = EVENT_HANDLERS[i];
|
34724 | _this[method] = function () {
|
34725 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
34726 | args[_key] = arguments[_key];
|
34727 | }
|
34728 |
|
34729 | var stk = _this.state.stack;
|
34730 | var change = _this.state.state.change();
|
34731 | stk[method].apply(stk, [change, _this].concat(args));
|
34732 | stk.onBeforeChange(change, _this);
|
34733 | stk.onChange(change, _this);
|
34734 | _this.onChange(change);
|
34735 | };
|
34736 | };
|
34737 |
|
34738 | for (var i = 0; i < EVENT_HANDLERS.length; i++) {
|
34739 | _loop(i);
|
34740 | }
|
34741 |
|
34742 | if (props.onDocumentChange) {
|
34743 | _logger2.default.deprecate('0.22.10', 'The `onDocumentChange` prop is deprecated because it led to confusing UX issues, see https://github.com/ianstormtaylor/slate/issues/614#issuecomment-327868679');
|
34744 | }
|
34745 |
|
34746 | if (props.onSelectionChange) {
|
34747 | _logger2.default.deprecate('0.22.10', 'The `onSelectionChange` prop is deprecated because it led to confusing UX issues, see https://github.com/ianstormtaylor/slate/issues/614#issuecomment-327868679');
|
34748 | }
|
34749 | return _this;
|
34750 | }
|
34751 |
|
34752 | /**
|
34753 | * When the `props` are updated, create a new `Stack` if necessary.
|
34754 | *
|
34755 | * @param {Object} props
|
34756 | */
|
34757 |
|
34758 | /**
|
34759 | * Default properties.
|
34760 | *
|
34761 | * @type {Object}
|
34762 | */
|
34763 |
|
34764 | /**
|
34765 | * Cache a `state` in memory to be able to compare against it later, for
|
34766 | * things like `onDocumentChange`.
|
34767 | *
|
34768 | * @param {State} state
|
34769 | */
|
34770 |
|
34771 | /**
|
34772 | * Programmatically blur the editor.
|
34773 | */
|
34774 |
|
34775 | /**
|
34776 | * Programmatically focus the editor.
|
34777 | */
|
34778 |
|
34779 | /**
|
34780 | * Get the editor's current schema.
|
34781 | *
|
34782 | * @return {Schema}
|
34783 | */
|
34784 |
|
34785 | /**
|
34786 | * Get the editor's current state.
|
34787 | *
|
34788 | * @return {State}
|
34789 | */
|
34790 |
|
34791 | /**
|
34792 | * Perform a change `fn` on the editor's current state.
|
34793 | *
|
34794 | * @param {Function} fn
|
34795 | */
|
34796 |
|
34797 | /**
|
34798 | * On change.
|
34799 | *
|
34800 | * @param {Change} change
|
34801 | */
|
34802 |
|
34803 | _createClass(Editor, [{
|
34804 | key: 'render',
|
34805 |
|
34806 |
|
34807 | /**
|
34808 | * Render the editor.
|
34809 | *
|
34810 | * @return {Element}
|
34811 | */
|
34812 |
|
34813 | value: function render() {
|
34814 | var props = this.props,
|
34815 | state = this.state;
|
34816 | var stack = state.stack;
|
34817 |
|
34818 | var children = stack.renderPortal(state.state, this).map(function (child, i) {
|
34819 | return _react2.default.createElement(
|
34820 | _reactPortal2.default,
|
34821 | { key: i, isOpened: true },
|
34822 | child
|
34823 | );
|
34824 | });
|
34825 |
|
34826 | debug('render', { props: props, state: state });
|
34827 |
|
34828 | var tree = stack.render(state.state, this, _extends({}, props, { children: children }));
|
34829 | return tree;
|
34830 | }
|
34831 | }]);
|
34832 |
|
34833 | return Editor;
|
34834 | }(_react2.default.Component);
|
34835 |
|
34836 | /**
|
34837 | * Mix in the property types for the event handlers.
|
34838 | */
|
34839 |
|
34840 | Editor.propTypes = {
|
34841 | autoCorrect: _propTypes2.default.bool,
|
34842 | autoFocus: _propTypes2.default.bool,
|
34843 | className: _propTypes2.default.string,
|
34844 | onBeforeChange: _propTypes2.default.func,
|
34845 | onChange: _propTypes2.default.func,
|
34846 | placeholder: _propTypes2.default.any,
|
34847 | placeholderClassName: _propTypes2.default.string,
|
34848 | placeholderStyle: _propTypes2.default.object,
|
34849 | plugins: _propTypes2.default.array,
|
34850 | readOnly: _propTypes2.default.bool,
|
34851 | role: _propTypes2.default.string,
|
34852 | schema: _propTypes2.default.object,
|
34853 | spellCheck: _propTypes2.default.bool,
|
34854 | state: _propTypes4.default.state.isRequired,
|
34855 | style: _propTypes2.default.object,
|
34856 | tabIndex: _propTypes2.default.number
|
34857 | };
|
34858 | Editor.defaultProps = {
|
34859 | autoFocus: false,
|
34860 | autoCorrect: true,
|
34861 | onChange: _noop2.default,
|
34862 | plugins: [],
|
34863 | readOnly: false,
|
34864 | schema: {},
|
34865 | spellCheck: true
|
34866 | };
|
34867 |
|
34868 | var _initialiseProps = function _initialiseProps() {
|
34869 | var _this2 = this;
|
34870 |
|
34871 | this.componentWillReceiveProps = function (props) {
|
34872 | var state = props.state;
|
34873 |
|
34874 | // If any plugin-related properties will change, create a new `Stack`.
|
34875 |
|
34876 | for (var _i = 0; _i < PLUGINS_PROPS.length; _i++) {
|
34877 | var prop = PLUGINS_PROPS[_i];
|
34878 | if (props[prop] == _this2.props[prop]) continue;
|
34879 |
|
34880 | var onChange = props.onChange,
|
34881 | rest = _objectWithoutProperties(props, ['onChange']); // eslint-disable-line no-unused-vars
|
34882 |
|
34883 |
|
34884 | var stack = _stack2.default.create(rest);
|
34885 | _this2.setState({ stack: stack });
|
34886 | }
|
34887 |
|
34888 | // Cache and save the state.
|
34889 | _this2.cacheState(state);
|
34890 | _this2.setState({ state: state });
|
34891 | };
|
34892 |
|
34893 | this.cacheState = function (state) {
|
34894 | _this2.tmp.document = state.document;
|
34895 | _this2.tmp.selection = state.selection;
|
34896 | };
|
34897 |
|
34898 | this.blur = function () {
|
34899 | _this2.change(function (t) {
|
34900 | return t.blur();
|
34901 | });
|
34902 | };
|
34903 |
|
34904 | this.focus = function () {
|
34905 | _this2.change(function (t) {
|
34906 | return t.focus();
|
34907 | });
|
34908 | };
|
34909 |
|
34910 | this.getSchema = function () {
|
34911 | return _this2.state.stack.schema;
|
34912 | };
|
34913 |
|
34914 | this.getState = function () {
|
34915 | return _this2.state.state;
|
34916 | };
|
34917 |
|
34918 | this.change = function (fn) {
|
34919 | var change = _this2.state.state.change();
|
34920 | fn(change);
|
34921 | _this2.onChange(change);
|
34922 | };
|
34923 |
|
34924 | this.onChange = function (change) {
|
34925 | if (_state2.default.isState(change)) {
|
34926 | throw new Error('As of slate@0.22.0 the `editor.onChange` method must be passed a `Change` object not a `State` object.');
|
34927 | }
|
34928 |
|
34929 | var _props = _this2.props,
|
34930 | onChange = _props.onChange,
|
34931 | onDocumentChange = _props.onDocumentChange,
|
34932 | onSelectionChange = _props.onSelectionChange;
|
34933 | var _tmp = _this2.tmp,
|
34934 | document = _tmp.document,
|
34935 | selection = _tmp.selection;
|
34936 | var state = change.state;
|
34937 |
|
34938 | if (state == _this2.state.state) return;
|
34939 |
|
34940 | onChange(change);
|
34941 | if (onDocumentChange && state.document != document) onDocumentChange(state.document, change);
|
34942 | if (onSelectionChange && state.selection != selection) onSelectionChange(state.selection, change);
|
34943 | };
|
34944 | };
|
34945 |
|
34946 | for (var i = 0; i < EVENT_HANDLERS.length; i++) {
|
34947 | var property = EVENT_HANDLERS[i];
|
34948 | Editor.propTypes[property] = _propTypes2.default.func;
|
34949 | }
|
34950 |
|
34951 | /**
|
34952 | * Export.
|
34953 | *
|
34954 | * @type {Component}
|
34955 | */
|
34956 |
|
34957 | exports.default = Editor;
|
34958 | },{"../models/stack":343,"../models/state":344,"../utils/logger":366,"../utils/noop":368,"../utils/prop-types":371,"debug":375,"prop-types":148,"react":309,"react-portal":284}],322:[function(require,module,exports){
|
34959 | 'use strict';
|
34960 |
|
34961 | Object.defineProperty(exports, "__esModule", {
|
34962 | value: true
|
34963 | });
|
34964 |
|
34965 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
34966 |
|
34967 | var _debug = require('debug');
|
34968 |
|
34969 | var _debug2 = _interopRequireDefault(_debug);
|
34970 |
|
34971 | var _react = require('react');
|
34972 |
|
34973 | var _react2 = _interopRequireDefault(_react);
|
34974 |
|
34975 | var _propTypes = require('prop-types');
|
34976 |
|
34977 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
34978 |
|
34979 | var _offsetKey = require('../utils/offset-key');
|
34980 |
|
34981 | var _offsetKey2 = _interopRequireDefault(_offsetKey);
|
34982 |
|
34983 | var _propTypes3 = require('../utils/prop-types');
|
34984 |
|
34985 | var _propTypes4 = _interopRequireDefault(_propTypes3);
|
34986 |
|
34987 | var _environment = require('../constants/environment');
|
34988 |
|
34989 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
34990 |
|
34991 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
34992 |
|
34993 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
34994 |
|
34995 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
34996 |
|
34997 | /**
|
34998 | * Debugger.
|
34999 | *
|
35000 | * @type {Function}
|
35001 | */
|
35002 |
|
35003 | var debug = (0, _debug2.default)('slate:leaf');
|
35004 |
|
35005 | /**
|
35006 | * Leaf.
|
35007 | *
|
35008 | * @type {Component}
|
35009 | */
|
35010 |
|
35011 | var Leaf = function (_React$Component) {
|
35012 | _inherits(Leaf, _React$Component);
|
35013 |
|
35014 | function Leaf() {
|
35015 | var _ref;
|
35016 |
|
35017 | var _temp, _this, _ret;
|
35018 |
|
35019 | _classCallCheck(this, Leaf);
|
35020 |
|
35021 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
35022 | args[_key] = arguments[_key];
|
35023 | }
|
35024 |
|
35025 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Leaf.__proto__ || Object.getPrototypeOf(Leaf)).call.apply(_ref, [this].concat(args))), _this), _initialiseProps.call(_this), _temp), _possibleConstructorReturn(_this, _ret);
|
35026 | }
|
35027 |
|
35028 | /**
|
35029 | * Property types.
|
35030 | *
|
35031 | * @type {Object}
|
35032 | */
|
35033 |
|
35034 | /**
|
35035 | * Debug.
|
35036 | *
|
35037 | * @param {String} message
|
35038 | * @param {Mixed} ...args
|
35039 | */
|
35040 |
|
35041 | _createClass(Leaf, [{
|
35042 | key: 'shouldComponentUpdate',
|
35043 |
|
35044 |
|
35045 | /**
|
35046 | * Should component update?
|
35047 | *
|
35048 | * @param {Object} props
|
35049 | * @return {Boolean}
|
35050 | */
|
35051 |
|
35052 | value: function shouldComponentUpdate(props) {
|
35053 | // If any of the regular properties have changed, re-render.
|
35054 | if (props.index != this.props.index || props.marks != this.props.marks || props.schema != this.props.schema || props.text != this.props.text) {
|
35055 | return true;
|
35056 | }
|
35057 |
|
35058 | // Otherwise, don't update.
|
35059 | return false;
|
35060 | }
|
35061 |
|
35062 | /**
|
35063 | * Render the leaf.
|
35064 | *
|
35065 | * @return {Element}
|
35066 | */
|
35067 |
|
35068 | }, {
|
35069 | key: 'render',
|
35070 | value: function render() {
|
35071 | var props = this.props;
|
35072 | var node = props.node,
|
35073 | index = props.index;
|
35074 |
|
35075 | var offsetKey = _offsetKey2.default.stringify({
|
35076 | key: node.key,
|
35077 | index: index
|
35078 | });
|
35079 |
|
35080 | this.debug('render', { props: props });
|
35081 |
|
35082 | return _react2.default.createElement(
|
35083 | 'span',
|
35084 | { 'data-offset-key': offsetKey },
|
35085 | this.renderMarks(props)
|
35086 | );
|
35087 | }
|
35088 |
|
35089 | /**
|
35090 | * Render the text content of the leaf, accounting for browsers.
|
35091 | *
|
35092 | * @param {Object} props
|
35093 | * @return {Element}
|
35094 | */
|
35095 |
|
35096 | }, {
|
35097 | key: 'renderText',
|
35098 | value: function renderText(props) {
|
35099 | var block = props.block,
|
35100 | node = props.node,
|
35101 | parent = props.parent,
|
35102 | text = props.text,
|
35103 | index = props.index,
|
35104 | ranges = props.ranges;
|
35105 |
|
35106 | // COMPAT: If the text is empty and it's the only child, we need to render a
|
35107 | // <br/> to get the block to have the proper height.
|
35108 |
|
35109 | if (text == '' && parent.kind == 'block' && parent.text == '') return _react2.default.createElement('br', null);
|
35110 |
|
35111 | // COMPAT: If the text is empty otherwise, it's because it's on the edge of
|
35112 | // an inline void node, so we render a zero-width space so that the
|
35113 | // selection can be inserted next to it still.
|
35114 | if (text == '') {
|
35115 | // COMPAT: In Chrome, zero-width space produces graphics glitches, so use
|
35116 | // hair space in place of it. (2017/02/12)
|
35117 | var space = _environment.IS_FIREFOX ? '\u200B' : '\u200A';
|
35118 | return _react2.default.createElement(
|
35119 | 'span',
|
35120 | { 'data-slate-zero-width': true },
|
35121 | space
|
35122 | );
|
35123 | }
|
35124 |
|
35125 | // COMPAT: Browsers will collapse trailing new lines at the end of blocks,
|
35126 | // so we need to add an extra trailing new lines to prevent that.
|
35127 | var lastText = block.getLastText();
|
35128 | var lastChar = text.charAt(text.length - 1);
|
35129 | var isLastText = node == lastText;
|
35130 | var isLastRange = index == ranges.size - 1;
|
35131 | if (isLastText && isLastRange && lastChar == '\n') return text + '\n';
|
35132 |
|
35133 | // Otherwise, just return the text.
|
35134 | return text;
|
35135 | }
|
35136 |
|
35137 | /**
|
35138 | * Render all of the leaf's mark components.
|
35139 | *
|
35140 | * @param {Object} props
|
35141 | * @return {Element}
|
35142 | */
|
35143 |
|
35144 | }, {
|
35145 | key: 'renderMarks',
|
35146 | value: function renderMarks(props) {
|
35147 | var marks = props.marks,
|
35148 | schema = props.schema,
|
35149 | node = props.node,
|
35150 | offset = props.offset,
|
35151 | text = props.text,
|
35152 | state = props.state,
|
35153 | editor = props.editor;
|
35154 |
|
35155 | var children = this.renderText(props);
|
35156 |
|
35157 | return marks.reduce(function (memo, mark) {
|
35158 | var Component = mark.getComponent(schema);
|
35159 | if (!Component) return memo;
|
35160 | return _react2.default.createElement(
|
35161 | Component,
|
35162 | {
|
35163 | editor: editor,
|
35164 | mark: mark,
|
35165 | marks: marks,
|
35166 | node: node,
|
35167 | offset: offset,
|
35168 | schema: schema,
|
35169 | state: state,
|
35170 | text: text
|
35171 | },
|
35172 | memo
|
35173 | );
|
35174 | }, children);
|
35175 | }
|
35176 | }]);
|
35177 |
|
35178 | return Leaf;
|
35179 | }(_react2.default.Component);
|
35180 |
|
35181 | /**
|
35182 | * Export.
|
35183 | *
|
35184 | * @type {Component}
|
35185 | */
|
35186 |
|
35187 | Leaf.propTypes = {
|
35188 | block: _propTypes4.default.block.isRequired,
|
35189 | editor: _propTypes2.default.object.isRequired,
|
35190 | index: _propTypes2.default.number.isRequired,
|
35191 | marks: _propTypes4.default.marks.isRequired,
|
35192 | node: _propTypes4.default.node.isRequired,
|
35193 | offset: _propTypes2.default.number.isRequired,
|
35194 | parent: _propTypes4.default.node.isRequired,
|
35195 | ranges: _propTypes4.default.ranges.isRequired,
|
35196 | schema: _propTypes4.default.schema.isRequired,
|
35197 | state: _propTypes4.default.state.isRequired,
|
35198 | text: _propTypes2.default.string.isRequired
|
35199 | };
|
35200 |
|
35201 | var _initialiseProps = function _initialiseProps() {
|
35202 | var _this2 = this;
|
35203 |
|
35204 | this.debug = function (message) {
|
35205 | for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
35206 | args[_key2 - 1] = arguments[_key2];
|
35207 | }
|
35208 |
|
35209 | debug.apply(undefined, [message, _this2.props.node.key + '-' + _this2.props.index].concat(args));
|
35210 | };
|
35211 | };
|
35212 |
|
35213 | exports.default = Leaf;
|
35214 | },{"../constants/environment":326,"../utils/offset-key":370,"../utils/prop-types":371,"debug":375,"prop-types":148,"react":309}],323:[function(require,module,exports){
|
35215 | 'use strict';
|
35216 |
|
35217 | Object.defineProperty(exports, "__esModule", {
|
35218 | value: true
|
35219 | });
|
35220 |
|
35221 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
35222 |
|
35223 | var _debug = require('debug');
|
35224 |
|
35225 | var _debug2 = _interopRequireDefault(_debug);
|
35226 |
|
35227 | var _react = require('react');
|
35228 |
|
35229 | var _react2 = _interopRequireDefault(_react);
|
35230 |
|
35231 | var _reactDom = require('react-dom');
|
35232 |
|
35233 | var _reactDom2 = _interopRequireDefault(_reactDom);
|
35234 |
|
35235 | var _propTypes = require('prop-types');
|
35236 |
|
35237 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
35238 |
|
35239 | var _transferTypes = require('../constants/transfer-types');
|
35240 |
|
35241 | var _transferTypes2 = _interopRequireDefault(_transferTypes);
|
35242 |
|
35243 | var _base = require('../serializers/base-64');
|
35244 |
|
35245 | var _base2 = _interopRequireDefault(_base);
|
35246 |
|
35247 | var _leaf = require('./leaf');
|
35248 |
|
35249 | var _leaf2 = _interopRequireDefault(_leaf);
|
35250 |
|
35251 | var _propTypes3 = require('../utils/prop-types');
|
35252 |
|
35253 | var _propTypes4 = _interopRequireDefault(_propTypes3);
|
35254 |
|
35255 | var _void = require('./void');
|
35256 |
|
35257 | var _void2 = _interopRequireDefault(_void);
|
35258 |
|
35259 | var _getWindow = require('get-window');
|
35260 |
|
35261 | var _getWindow2 = _interopRequireDefault(_getWindow);
|
35262 |
|
35263 | var _scrollToSelection = require('../utils/scroll-to-selection');
|
35264 |
|
35265 | var _scrollToSelection2 = _interopRequireDefault(_scrollToSelection);
|
35266 |
|
35267 | var _setTransferData = require('../utils/set-transfer-data');
|
35268 |
|
35269 | var _setTransferData2 = _interopRequireDefault(_setTransferData);
|
35270 |
|
35271 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
35272 |
|
35273 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
35274 |
|
35275 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
35276 |
|
35277 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
35278 |
|
35279 | /**
|
35280 | * Debug.
|
35281 | *
|
35282 | * @type {Function}
|
35283 | */
|
35284 |
|
35285 | var debug = (0, _debug2.default)('slate:node');
|
35286 |
|
35287 | /**
|
35288 | * Node.
|
35289 | *
|
35290 | * @type {Component}
|
35291 | */
|
35292 |
|
35293 | var Node = function (_React$Component) {
|
35294 | _inherits(Node, _React$Component);
|
35295 |
|
35296 | /**
|
35297 | * Constructor.
|
35298 | *
|
35299 | * @param {Object} props
|
35300 | */
|
35301 |
|
35302 | function Node(props) {
|
35303 | _classCallCheck(this, Node);
|
35304 |
|
35305 | var _this = _possibleConstructorReturn(this, (Node.__proto__ || Object.getPrototypeOf(Node)).call(this, props));
|
35306 |
|
35307 | _initialiseProps.call(_this);
|
35308 |
|
35309 | var node = props.node,
|
35310 | schema = props.schema;
|
35311 |
|
35312 | _this.state = {};
|
35313 | _this.state.Component = node.kind == 'text' ? null : node.getComponent(schema);
|
35314 | return _this;
|
35315 | }
|
35316 |
|
35317 | /**
|
35318 | * Debug.
|
35319 | *
|
35320 | * @param {String} message
|
35321 | * @param {Mixed} ...args
|
35322 | */
|
35323 |
|
35324 | /**
|
35325 | * Property types.
|
35326 | *
|
35327 | * @type {Object}
|
35328 | */
|
35329 |
|
35330 | /**
|
35331 | * On receiving new props, update the `Component` renderer.
|
35332 | *
|
35333 | * @param {Object} props
|
35334 | */
|
35335 |
|
35336 | /**
|
35337 | * Should the node update?
|
35338 | *
|
35339 | * @param {Object} nextProps
|
35340 | * @param {Object} state
|
35341 | * @return {Boolean}
|
35342 | */
|
35343 |
|
35344 | /**
|
35345 | * On mount, update the scroll position.
|
35346 | */
|
35347 |
|
35348 | /**
|
35349 | * After update, update the scroll position if the node's content changed.
|
35350 | *
|
35351 | * @param {Object} prevProps
|
35352 | * @param {Object} prevState
|
35353 | */
|
35354 |
|
35355 | /**
|
35356 | * There is a corner case, that some nodes are unmounted right after they update
|
35357 | * Then, when the timer execute, it will throw the error
|
35358 | * `findDOMNode was called on an unmounted component`
|
35359 | * We should clear the timer from updateScroll here
|
35360 | */
|
35361 |
|
35362 | /**
|
35363 | * Update the scroll position after a change as occured if this is a leaf
|
35364 | * block and it has the selection's ending edge. This ensures that scrolling
|
35365 | * matches native `contenteditable` behavior even for cases where the edit is
|
35366 | * not applied natively, like when enter is pressed.
|
35367 | */
|
35368 |
|
35369 | /**
|
35370 | * On drag start, add a serialized representation of the node to the data.
|
35371 | *
|
35372 | * @param {Event} e
|
35373 | */
|
35374 |
|
35375 | _createClass(Node, [{
|
35376 | key: 'render',
|
35377 |
|
35378 |
|
35379 | /**
|
35380 | * Render.
|
35381 | *
|
35382 | * @return {Element}
|
35383 | */
|
35384 |
|
35385 | value: function render() {
|
35386 | var props = this.props;
|
35387 | var node = this.props.node;
|
35388 |
|
35389 |
|
35390 | this.debug('render', { props: props });
|
35391 |
|
35392 | return node.kind == 'text' ? this.renderText() : this.renderElement();
|
35393 | }
|
35394 |
|
35395 | /**
|
35396 | * Render a `child` node.
|
35397 | *
|
35398 | * @param {Node} child
|
35399 | * @param {Boolean} isSelected
|
35400 | * @return {Element}
|
35401 | */
|
35402 |
|
35403 | /**
|
35404 | * Render an element `node`.
|
35405 | *
|
35406 | * @return {Element}
|
35407 | */
|
35408 |
|
35409 | /**
|
35410 | * Render a text node.
|
35411 | *
|
35412 | * @return {Element}
|
35413 | */
|
35414 |
|
35415 | /**
|
35416 | * Render a single leaf node given a `range` and `offset`.
|
35417 | *
|
35418 | * @param {List<Range>} ranges
|
35419 | * @param {Range} range
|
35420 | * @param {Number} index
|
35421 | * @param {Number} offset
|
35422 | * @return {Element} leaf
|
35423 | */
|
35424 |
|
35425 | }]);
|
35426 |
|
35427 | return Node;
|
35428 | }(_react2.default.Component);
|
35429 |
|
35430 | /**
|
35431 | * Export.
|
35432 | *
|
35433 | * @type {Component}
|
35434 | */
|
35435 |
|
35436 | Node.propTypes = {
|
35437 | block: _propTypes4.default.block,
|
35438 | editor: _propTypes2.default.object.isRequired,
|
35439 | isSelected: _propTypes2.default.bool.isRequired,
|
35440 | node: _propTypes4.default.node.isRequired,
|
35441 | parent: _propTypes4.default.node.isRequired,
|
35442 | readOnly: _propTypes2.default.bool.isRequired,
|
35443 | schema: _propTypes4.default.schema.isRequired,
|
35444 | state: _propTypes4.default.state.isRequired
|
35445 | };
|
35446 |
|
35447 | var _initialiseProps = function _initialiseProps() {
|
35448 | var _this2 = this;
|
35449 |
|
35450 | this.debug = function (message) {
|
35451 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
35452 | args[_key - 1] = arguments[_key];
|
35453 | }
|
35454 |
|
35455 | var node = _this2.props.node;
|
35456 | var key = node.key,
|
35457 | kind = node.kind,
|
35458 | type = node.type;
|
35459 |
|
35460 | var id = kind == 'text' ? key + ' (' + kind + ')' : key + ' (' + type + ')';
|
35461 | debug.apply(undefined, [message, '' + id].concat(args));
|
35462 | };
|
35463 |
|
35464 | this.componentWillReceiveProps = function (props) {
|
35465 | if (props.node.kind == 'text') return;
|
35466 | if (props.node == _this2.props.node) return;
|
35467 | var Component = props.node.getComponent(props.schema);
|
35468 | _this2.setState({ Component: Component });
|
35469 | };
|
35470 |
|
35471 | this.shouldComponentUpdate = function (nextProps) {
|
35472 | var props = _this2.props;
|
35473 | var Component = _this2.state.Component;
|
35474 |
|
35475 | var n = nextProps;
|
35476 | var p = props;
|
35477 |
|
35478 | // If the `Component` has enabled suppression of update checking, always
|
35479 | // return true so that it can deal with update checking itself.
|
35480 | if (Component && Component.suppressShouldComponentUpdate) return true;
|
35481 |
|
35482 | // If the `readOnly` status has changed, re-render in case there is any
|
35483 | // user-land logic that depends on it, like nested editable contents.
|
35484 | if (n.readOnly != p.readOnly) return true;
|
35485 |
|
35486 | // If the node has changed, update. PERF: There are cases where it will have
|
35487 | // changed, but it's properties will be exactly the same (eg. copy-paste)
|
35488 | // which this won't catch. But that's rare and not a drag on performance, so
|
35489 | // for simplicity we just let them through.
|
35490 | if (n.node != p.node) return true;
|
35491 |
|
35492 | // If the node's selection state has changed, re-render in case there is any
|
35493 | // user-land logic depends on it to render.
|
35494 | if (n.isSelected != p.isSelected) return true;
|
35495 |
|
35496 | // If the node is a text node, re-render if the current decorations have
|
35497 | // changed, even if the content of the text node itself hasn't.
|
35498 | if (n.node.kind == 'text' && n.schema.hasDecorators) {
|
35499 | var nDecorators = n.state.document.getDescendantDecorators(n.node.key, n.schema);
|
35500 | var pDecorators = p.state.document.getDescendantDecorators(p.node.key, p.schema);
|
35501 | var nRanges = n.node.getRanges(nDecorators);
|
35502 | var pRanges = p.node.getRanges(pDecorators);
|
35503 | if (!nRanges.equals(pRanges)) return true;
|
35504 | }
|
35505 |
|
35506 | // If the node is a text node, and its parent is a block node, and it was
|
35507 | // the last child of the block, re-render to cleanup extra `<br/>` or `\n`.
|
35508 | if (n.node.kind == 'text' && n.parent.kind == 'block') {
|
35509 | var pLast = p.parent.nodes.last();
|
35510 | var nLast = n.parent.nodes.last();
|
35511 | if (p.node == pLast && n.node != nLast) return true;
|
35512 | }
|
35513 |
|
35514 | // Otherwise, don't update.
|
35515 | return false;
|
35516 | };
|
35517 |
|
35518 | this.componentDidMount = function () {
|
35519 | _this2.updateScroll();
|
35520 | };
|
35521 |
|
35522 | this.componentDidUpdate = function (prevProps, prevState) {
|
35523 | if (_this2.props.node != prevProps.node) _this2.updateScroll();
|
35524 | };
|
35525 |
|
35526 | this.componentWillUnmount = function () {
|
35527 | clearTimeout(_this2.scrollTimer);
|
35528 | };
|
35529 |
|
35530 | this.updateScroll = function () {
|
35531 | var _props = _this2.props,
|
35532 | node = _props.node,
|
35533 | state = _props.state;
|
35534 | var selection = state.selection;
|
35535 |
|
35536 | // If this isn't a block, or it's a wrapping block, abort.
|
35537 |
|
35538 | if (node.kind != 'block') return;
|
35539 | if (node.nodes.first().kind == 'block') return;
|
35540 |
|
35541 | // If the selection is blurred, or this block doesn't contain it, abort.
|
35542 | if (selection.isBlurred) return;
|
35543 | if (!selection.hasEndIn(node)) return;
|
35544 |
|
35545 | // The native selection will be updated after componentDidMount or componentDidUpdate.
|
35546 | // Use setTimeout to queue scrolling to the last when the native selection has been updated to the correct value.
|
35547 | _this2.scrollTimer = setTimeout(function () {
|
35548 | var el = _reactDom2.default.findDOMNode(_this2);
|
35549 | var window = (0, _getWindow2.default)(el);
|
35550 | var native = window.getSelection();
|
35551 | (0, _scrollToSelection2.default)(native);
|
35552 |
|
35553 | _this2.debug('updateScroll', el);
|
35554 | });
|
35555 | };
|
35556 |
|
35557 | this.onDragStart = function (e) {
|
35558 | var node = _this2.props.node;
|
35559 |
|
35560 | // Only void node are draggable
|
35561 |
|
35562 | if (!node.isVoid) {
|
35563 | return;
|
35564 | }
|
35565 |
|
35566 | var encoded = _base2.default.serializeNode(node, { preserveKeys: true });
|
35567 | var dataTransfer = e.nativeEvent.dataTransfer;
|
35568 |
|
35569 |
|
35570 | (0, _setTransferData2.default)(dataTransfer, _transferTypes2.default.NODE, encoded);
|
35571 |
|
35572 | _this2.debug('onDragStart', e);
|
35573 | };
|
35574 |
|
35575 | this.renderNode = function (child, isSelected) {
|
35576 | var _props2 = _this2.props,
|
35577 | block = _props2.block,
|
35578 | editor = _props2.editor,
|
35579 | node = _props2.node,
|
35580 | readOnly = _props2.readOnly,
|
35581 | schema = _props2.schema,
|
35582 | state = _props2.state;
|
35583 |
|
35584 | return _react2.default.createElement(Node, {
|
35585 | block: node.kind == 'block' ? node : block,
|
35586 | editor: editor,
|
35587 | isSelected: isSelected,
|
35588 | key: child.key,
|
35589 | node: child,
|
35590 | parent: node,
|
35591 | readOnly: readOnly,
|
35592 | schema: schema,
|
35593 | state: state
|
35594 | });
|
35595 | };
|
35596 |
|
35597 | this.renderElement = function () {
|
35598 | var _props3 = _this2.props,
|
35599 | editor = _props3.editor,
|
35600 | isSelected = _props3.isSelected,
|
35601 | node = _props3.node,
|
35602 | parent = _props3.parent,
|
35603 | readOnly = _props3.readOnly,
|
35604 | state = _props3.state;
|
35605 | var Component = _this2.state.Component;
|
35606 | var selection = state.selection;
|
35607 |
|
35608 | var indexes = node.getSelectionIndexes(selection, isSelected);
|
35609 | var children = node.nodes.toArray().map(function (child, i) {
|
35610 | var isChildSelected = !!indexes && indexes.start <= i && i < indexes.end;
|
35611 | return _this2.renderNode(child, isChildSelected);
|
35612 | });
|
35613 |
|
35614 | // Attributes that the developer must to mix into the element in their
|
35615 | // custom node renderer component.
|
35616 | var attributes = {
|
35617 | 'data-key': node.key,
|
35618 | 'onDragStart': _this2.onDragStart
|
35619 | };
|
35620 |
|
35621 | // If it's a block node with inline children, add the proper `dir` attribute
|
35622 | // for text direction.
|
35623 | if (node.kind == 'block' && node.nodes.first().kind != 'block') {
|
35624 | var direction = node.getTextDirection();
|
35625 | if (direction == 'rtl') attributes.dir = 'rtl';
|
35626 | }
|
35627 |
|
35628 | var element = _react2.default.createElement(
|
35629 | Component,
|
35630 | {
|
35631 | attributes: attributes,
|
35632 | editor: editor,
|
35633 | isSelected: isSelected,
|
35634 | key: node.key,
|
35635 | node: node,
|
35636 | parent: parent,
|
35637 | readOnly: readOnly,
|
35638 | state: state
|
35639 | },
|
35640 | children
|
35641 | );
|
35642 |
|
35643 | return node.isVoid ? _react2.default.createElement(
|
35644 | _void2.default,
|
35645 | _this2.props,
|
35646 | element
|
35647 | ) : element;
|
35648 | };
|
35649 |
|
35650 | this.renderText = function () {
|
35651 | var _props4 = _this2.props,
|
35652 | node = _props4.node,
|
35653 | schema = _props4.schema,
|
35654 | state = _props4.state;
|
35655 | var document = state.document;
|
35656 |
|
35657 | var decorators = schema.hasDecorators ? document.getDescendantDecorators(node.key, schema) : [];
|
35658 | var ranges = node.getRanges(decorators);
|
35659 | var offset = 0;
|
35660 |
|
35661 | var leaves = ranges.map(function (range, i) {
|
35662 | var leaf = _this2.renderLeaf(ranges, range, i, offset);
|
35663 | offset += range.text.length;
|
35664 | return leaf;
|
35665 | });
|
35666 |
|
35667 | return _react2.default.createElement(
|
35668 | 'span',
|
35669 | { 'data-key': node.key },
|
35670 | leaves
|
35671 | );
|
35672 | };
|
35673 |
|
35674 | this.renderLeaf = function (ranges, range, index, offset) {
|
35675 | var _props5 = _this2.props,
|
35676 | block = _props5.block,
|
35677 | node = _props5.node,
|
35678 | parent = _props5.parent,
|
35679 | schema = _props5.schema,
|
35680 | state = _props5.state,
|
35681 | editor = _props5.editor;
|
35682 | var text = range.text,
|
35683 | marks = range.marks;
|
35684 |
|
35685 |
|
35686 | return _react2.default.createElement(_leaf2.default, {
|
35687 | key: node.key + '-' + index,
|
35688 | block: block,
|
35689 | editor: editor,
|
35690 | index: index,
|
35691 | marks: marks,
|
35692 | node: node,
|
35693 | offset: offset,
|
35694 | parent: parent,
|
35695 | ranges: ranges,
|
35696 | schema: schema,
|
35697 | state: state,
|
35698 | text: text
|
35699 | });
|
35700 | };
|
35701 | };
|
35702 |
|
35703 | exports.default = Node;
|
35704 | },{"../constants/transfer-types":329,"../serializers/base-64":351,"../utils/prop-types":371,"../utils/scroll-to-selection":372,"../utils/set-transfer-data":373,"./leaf":322,"./void":325,"debug":375,"get-window":133,"prop-types":148,"react":309,"react-dom":153}],324:[function(require,module,exports){
|
35705 | 'use strict';
|
35706 |
|
35707 | Object.defineProperty(exports, "__esModule", {
|
35708 | value: true
|
35709 | });
|
35710 |
|
35711 | 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; };
|
35712 |
|
35713 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
35714 |
|
35715 | var _react = require('react');
|
35716 |
|
35717 | var _react2 = _interopRequireDefault(_react);
|
35718 |
|
35719 | var _propTypes = require('prop-types');
|
35720 |
|
35721 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
35722 |
|
35723 | var _propTypes3 = require('../utils/prop-types');
|
35724 |
|
35725 | var _propTypes4 = _interopRequireDefault(_propTypes3);
|
35726 |
|
35727 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
35728 |
|
35729 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
35730 |
|
35731 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
35732 |
|
35733 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
35734 |
|
35735 | /**
|
35736 | * Placeholder.
|
35737 | *
|
35738 | * @type {Component}
|
35739 | */
|
35740 |
|
35741 | var Placeholder = function (_React$Component) {
|
35742 | _inherits(Placeholder, _React$Component);
|
35743 |
|
35744 | function Placeholder() {
|
35745 | var _ref;
|
35746 |
|
35747 | var _temp, _this, _ret;
|
35748 |
|
35749 | _classCallCheck(this, Placeholder);
|
35750 |
|
35751 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
35752 | args[_key] = arguments[_key];
|
35753 | }
|
35754 |
|
35755 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Placeholder.__proto__ || Object.getPrototypeOf(Placeholder)).call.apply(_ref, [this].concat(args))), _this), _this.shouldComponentUpdate = function (props, state) {
|
35756 | return props.children != _this.props.children || props.className != _this.props.className || props.firstOnly != _this.props.firstOnly || props.parent != _this.props.parent || props.node != _this.props.node || props.style != _this.props.style;
|
35757 | }, _this.isVisible = function () {
|
35758 | var _this$props = _this.props,
|
35759 | firstOnly = _this$props.firstOnly,
|
35760 | node = _this$props.node,
|
35761 | parent = _this$props.parent;
|
35762 |
|
35763 | if (node.text) return false;
|
35764 |
|
35765 | if (firstOnly) {
|
35766 | if (parent.nodes.size > 1) return false;
|
35767 | if (parent.nodes.first() === node) return true;
|
35768 | return false;
|
35769 | } else {
|
35770 | return true;
|
35771 | }
|
35772 | }, _temp), _possibleConstructorReturn(_this, _ret);
|
35773 | }
|
35774 |
|
35775 | /**
|
35776 | * Property types.
|
35777 | *
|
35778 | * @type {Object}
|
35779 | */
|
35780 |
|
35781 | /**
|
35782 | * Default properties.
|
35783 | *
|
35784 | * @type {Object}
|
35785 | */
|
35786 |
|
35787 | /**
|
35788 | * Should the placeholder update?
|
35789 | *
|
35790 | * @param {Object} props
|
35791 | * @param {Object} state
|
35792 | * @return {Boolean}
|
35793 | */
|
35794 |
|
35795 | /**
|
35796 | * Is the placeholder visible?
|
35797 | *
|
35798 | * @return {Boolean}
|
35799 | */
|
35800 |
|
35801 | _createClass(Placeholder, [{
|
35802 | key: 'render',
|
35803 |
|
35804 |
|
35805 | /**
|
35806 | * Render.
|
35807 | *
|
35808 | * If the placeholder is a string, and no `className` or `style` has been
|
35809 | * passed, give it a default style of lowered opacity.
|
35810 | *
|
35811 | * @return {Element}
|
35812 | */
|
35813 |
|
35814 | value: function render() {
|
35815 | var isVisible = this.isVisible();
|
35816 | if (!isVisible) return null;
|
35817 |
|
35818 | var _props = this.props,
|
35819 | children = _props.children,
|
35820 | className = _props.className;
|
35821 | var style = this.props.style;
|
35822 |
|
35823 |
|
35824 | if (typeof children === 'string' && style == null && className == null) {
|
35825 | style = { opacity: '0.333' };
|
35826 | } else if (style == null) {
|
35827 | style = {};
|
35828 | }
|
35829 |
|
35830 | var styles = _extends({
|
35831 | position: 'absolute',
|
35832 | top: '0px',
|
35833 | right: '0px',
|
35834 | bottom: '0px',
|
35835 | left: '0px',
|
35836 | pointerEvents: 'none'
|
35837 | }, style);
|
35838 |
|
35839 | return _react2.default.createElement(
|
35840 | 'span',
|
35841 | { contentEditable: false, className: className, style: styles },
|
35842 | children
|
35843 | );
|
35844 | }
|
35845 | }]);
|
35846 |
|
35847 | return Placeholder;
|
35848 | }(_react2.default.Component);
|
35849 |
|
35850 | /**
|
35851 | * Export.
|
35852 | *
|
35853 | * @type {Component}
|
35854 | */
|
35855 |
|
35856 | Placeholder.propTypes = {
|
35857 | children: _propTypes2.default.any.isRequired,
|
35858 | className: _propTypes2.default.string,
|
35859 | firstOnly: _propTypes2.default.bool,
|
35860 | node: _propTypes4.default.node.isRequired,
|
35861 | parent: _propTypes4.default.node,
|
35862 | state: _propTypes4.default.state.isRequired,
|
35863 | style: _propTypes2.default.object
|
35864 | };
|
35865 | Placeholder.defaultProps = {
|
35866 | firstOnly: true
|
35867 | };
|
35868 | exports.default = Placeholder;
|
35869 | },{"../utils/prop-types":371,"prop-types":148,"react":309}],325:[function(require,module,exports){
|
35870 | 'use strict';
|
35871 |
|
35872 | Object.defineProperty(exports, "__esModule", {
|
35873 | value: true
|
35874 | });
|
35875 |
|
35876 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
35877 |
|
35878 | var _debug = require('debug');
|
35879 |
|
35880 | var _debug2 = _interopRequireDefault(_debug);
|
35881 |
|
35882 | var _react = require('react');
|
35883 |
|
35884 | var _react2 = _interopRequireDefault(_react);
|
35885 |
|
35886 | var _propTypes = require('prop-types');
|
35887 |
|
35888 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
35889 |
|
35890 | var _leaf = require('./leaf');
|
35891 |
|
35892 | var _leaf2 = _interopRequireDefault(_leaf);
|
35893 |
|
35894 | var _mark = require('../models/mark');
|
35895 |
|
35896 | var _mark2 = _interopRequireDefault(_mark);
|
35897 |
|
35898 | var _offsetKey = require('../utils/offset-key');
|
35899 |
|
35900 | var _offsetKey2 = _interopRequireDefault(_offsetKey);
|
35901 |
|
35902 | var _propTypes3 = require('../utils/prop-types');
|
35903 |
|
35904 | var _propTypes4 = _interopRequireDefault(_propTypes3);
|
35905 |
|
35906 | var _environment = require('../constants/environment');
|
35907 |
|
35908 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
35909 |
|
35910 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
35911 |
|
35912 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
35913 |
|
35914 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
35915 |
|
35916 | /**
|
35917 | * Debug.
|
35918 | *
|
35919 | * @type {Function}
|
35920 | */
|
35921 |
|
35922 | var debug = (0, _debug2.default)('slate:void');
|
35923 |
|
35924 | /**
|
35925 | * Void.
|
35926 | *
|
35927 | * @type {Component}
|
35928 | */
|
35929 |
|
35930 | var Void = function (_React$Component) {
|
35931 | _inherits(Void, _React$Component);
|
35932 |
|
35933 | function Void() {
|
35934 | var _ref;
|
35935 |
|
35936 | var _temp, _this, _ret;
|
35937 |
|
35938 | _classCallCheck(this, Void);
|
35939 |
|
35940 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
35941 | args[_key] = arguments[_key];
|
35942 | }
|
35943 |
|
35944 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Void.__proto__ || Object.getPrototypeOf(Void)).call.apply(_ref, [this].concat(args))), _this), _initialiseProps.call(_this), _temp), _possibleConstructorReturn(_this, _ret);
|
35945 | }
|
35946 |
|
35947 | /**
|
35948 | * Property types.
|
35949 | *
|
35950 | * @type {Object}
|
35951 | */
|
35952 |
|
35953 | /**
|
35954 | * State
|
35955 | *
|
35956 | * @type {Object}
|
35957 | */
|
35958 |
|
35959 | /**
|
35960 | * Debug.
|
35961 | *
|
35962 | * @param {String} message
|
35963 | * @param {Mixed} ...args
|
35964 | */
|
35965 |
|
35966 | /**
|
35967 | * When one of the wrapper elements it clicked, select the void node.
|
35968 | *
|
35969 | * @param {Event} event
|
35970 | */
|
35971 |
|
35972 | /**
|
35973 | * Increment counter, and temporarily switch node to editable to allow drop events
|
35974 | * Counter required as onDragLeave fires when hovering over child elements
|
35975 | *
|
35976 | * @param {Event} event
|
35977 | */
|
35978 |
|
35979 | /**
|
35980 | * Decrement counter, and if counter 0, then no longer dragging over node
|
35981 | * and thus switch back to non-editable
|
35982 | *
|
35983 | * @param {Event} event
|
35984 | */
|
35985 |
|
35986 | /**
|
35987 | * If dropped item onto node, then reset state
|
35988 | *
|
35989 | * @param {Event} event
|
35990 | */
|
35991 |
|
35992 | _createClass(Void, [{
|
35993 | key: 'render',
|
35994 |
|
35995 |
|
35996 | /**
|
35997 | * Render.
|
35998 | *
|
35999 | * @return {Element}
|
36000 | */
|
36001 |
|
36002 | value: function render() {
|
36003 | var props = this.props;
|
36004 | var children = props.children,
|
36005 | node = props.node;
|
36006 |
|
36007 | var Tag = void 0,
|
36008 | style = void 0;
|
36009 |
|
36010 | // Make the outer wrapper relative, so the spacer can overlay it.
|
36011 | if (node.kind === 'block') {
|
36012 | Tag = 'div';
|
36013 | style = { position: 'relative' };
|
36014 | } else {
|
36015 | Tag = 'span';
|
36016 | }
|
36017 |
|
36018 | this.debug('render', { props: props });
|
36019 |
|
36020 | return _react2.default.createElement(
|
36021 | Tag,
|
36022 | {
|
36023 | 'data-slate-void': true,
|
36024 | style: style,
|
36025 | onClick: this.onClick,
|
36026 | onDragEnter: this.onDragEnter,
|
36027 | onDragLeave: this.onDragLeave,
|
36028 | onDrop: this.onDrop
|
36029 | },
|
36030 | this.renderSpacer(),
|
36031 | _react2.default.createElement(
|
36032 | Tag,
|
36033 | { contentEditable: this.state.editable },
|
36034 | children
|
36035 | )
|
36036 | );
|
36037 | }
|
36038 |
|
36039 | /**
|
36040 | * Render a fake spacer leaf, which will catch the cursor when it the void
|
36041 | * node is navigated to with the arrow keys. Having this spacer there means
|
36042 | * the browser continues to manage the selection natively, so it keeps track
|
36043 | * of the right offset when moving across the block.
|
36044 | *
|
36045 | * @return {Element}
|
36046 | */
|
36047 |
|
36048 | /**
|
36049 | * Render a fake leaf.
|
36050 | *
|
36051 | * @return {Element}
|
36052 | */
|
36053 |
|
36054 | }]);
|
36055 |
|
36056 | return Void;
|
36057 | }(_react2.default.Component);
|
36058 |
|
36059 | /**
|
36060 | * Export.
|
36061 | *
|
36062 | * @type {Component}
|
36063 | */
|
36064 |
|
36065 | Void.propTypes = {
|
36066 | block: _propTypes4.default.block,
|
36067 | children: _propTypes2.default.any.isRequired,
|
36068 | editor: _propTypes2.default.object.isRequired,
|
36069 | node: _propTypes4.default.node.isRequired,
|
36070 | parent: _propTypes4.default.node.isRequired,
|
36071 | readOnly: _propTypes2.default.bool.isRequired,
|
36072 | schema: _propTypes4.default.schema.isRequired,
|
36073 | state: _propTypes4.default.state.isRequired
|
36074 | };
|
36075 |
|
36076 | var _initialiseProps = function _initialiseProps() {
|
36077 | var _this2 = this;
|
36078 |
|
36079 | this.state = {
|
36080 | dragCounter: 0,
|
36081 | editable: false
|
36082 | };
|
36083 |
|
36084 | this.debug = function (message) {
|
36085 | for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
36086 | args[_key2 - 1] = arguments[_key2];
|
36087 | }
|
36088 |
|
36089 | var node = _this2.props.node;
|
36090 | var key = node.key,
|
36091 | type = node.type;
|
36092 |
|
36093 | var id = key + ' (' + type + ')';
|
36094 | debug.apply(undefined, [message, '' + id].concat(args));
|
36095 | };
|
36096 |
|
36097 | this.onClick = function (event) {
|
36098 | if (_this2.props.readOnly) return;
|
36099 |
|
36100 | _this2.debug('onClick', { event: event });
|
36101 |
|
36102 | var _props = _this2.props,
|
36103 | node = _props.node,
|
36104 | editor = _props.editor;
|
36105 |
|
36106 |
|
36107 | editor.change(function (change) {
|
36108 | change
|
36109 | // COMPAT: In Chrome & Safari, selections that are at the zero offset of
|
36110 | // an inline node will be automatically replaced to be at the last
|
36111 | // offset of a previous inline node, which screws us up, so we always
|
36112 | // want to set it to the end of the node. (2016/11/29)
|
36113 | .collapseToEndOf(node).focus();
|
36114 | });
|
36115 | };
|
36116 |
|
36117 | this.onDragEnter = function () {
|
36118 | _this2.setState(function (prevState) {
|
36119 | var dragCounter = prevState.dragCounter + 1;
|
36120 | return { dragCounter: dragCounter, editable: undefined };
|
36121 | });
|
36122 | };
|
36123 |
|
36124 | this.onDragLeave = function () {
|
36125 | _this2.setState(function (prevState) {
|
36126 | var dragCounter = prevState.dragCounter - 1;
|
36127 | var editable = dragCounter === 0 ? false : undefined;
|
36128 | return { dragCounter: dragCounter, editable: editable };
|
36129 | });
|
36130 | };
|
36131 |
|
36132 | this.onDrop = function () {
|
36133 | _this2.setState({ dragCounter: 0, editable: false });
|
36134 | };
|
36135 |
|
36136 | this.renderSpacer = function () {
|
36137 | var node = _this2.props.node;
|
36138 |
|
36139 | var style = void 0;
|
36140 |
|
36141 | if (node.kind == 'block') {
|
36142 | style = _environment.IS_FIREFOX ? {
|
36143 | pointerEvents: 'none',
|
36144 | width: '0px',
|
36145 | height: '0px',
|
36146 | lineHeight: '0px',
|
36147 | visibility: 'hidden'
|
36148 | } : {
|
36149 | position: 'absolute',
|
36150 | top: '0px',
|
36151 | left: '-9999px',
|
36152 | textIndent: '-9999px'
|
36153 | };
|
36154 | } else {
|
36155 | style = {
|
36156 | color: 'transparent'
|
36157 | };
|
36158 | }
|
36159 |
|
36160 | return _react2.default.createElement(
|
36161 | 'span',
|
36162 | { style: style },
|
36163 | _this2.renderLeaf()
|
36164 | );
|
36165 | };
|
36166 |
|
36167 | this.renderLeaf = function () {
|
36168 | var _props2 = _this2.props,
|
36169 | block = _props2.block,
|
36170 | node = _props2.node,
|
36171 | schema = _props2.schema,
|
36172 | state = _props2.state,
|
36173 | editor = _props2.editor;
|
36174 |
|
36175 | var child = node.getFirstText();
|
36176 | var ranges = child.getRanges();
|
36177 | var text = '';
|
36178 | var offset = 0;
|
36179 | var marks = _mark2.default.createSet();
|
36180 | var index = 0;
|
36181 | var offsetKey = _offsetKey2.default.stringify({
|
36182 | key: child.key,
|
36183 | index: index
|
36184 | });
|
36185 |
|
36186 | return _react2.default.createElement(_leaf2.default, {
|
36187 | key: offsetKey,
|
36188 | block: node.kind == 'block' ? node : block,
|
36189 | editor: editor,
|
36190 | index: index,
|
36191 | marks: marks,
|
36192 | node: child,
|
36193 | offset: offset,
|
36194 | parent: node,
|
36195 | ranges: ranges,
|
36196 | schema: schema,
|
36197 | state: state,
|
36198 | text: text
|
36199 | });
|
36200 | };
|
36201 | };
|
36202 |
|
36203 | exports.default = Void;
|
36204 | },{"../constants/environment":326,"../models/mark":338,"../utils/offset-key":370,"../utils/prop-types":371,"./leaf":322,"debug":375,"prop-types":148,"react":309}],326:[function(require,module,exports){
|
36205 | 'use strict';
|
36206 |
|
36207 | Object.defineProperty(exports, "__esModule", {
|
36208 | value: true
|
36209 | });
|
36210 | exports.IS_WINDOWS = exports.IS_MAC = exports.IS_IE = exports.IS_SAFARI = exports.IS_FIREFOX = exports.IS_CHROME = undefined;
|
36211 |
|
36212 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
36213 |
|
36214 | var _isInBrowser = require('is-in-browser');
|
36215 |
|
36216 | var _isInBrowser2 = _interopRequireDefault(_isInBrowser);
|
36217 |
|
36218 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
36219 |
|
36220 | /**
|
36221 | * Browser matching rules.
|
36222 | *
|
36223 | * @type {Array}
|
36224 | */
|
36225 |
|
36226 | var BROWSER_RULES = [['edge', /Edge\/([0-9\._]+)/], ['chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/], ['firefox', /Firefox\/([0-9\.]+)(?:\s|$)/], ['opera', /Opera\/([0-9\.]+)(?:\s|$)/], ['opera', /OPR\/([0-9\.]+)(:?\s|$)$/], ['ie', /Trident\/7\.0.*rv\:([0-9\.]+)\).*Gecko$/], ['ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/], ['ie', /MSIE\s(7\.0)/], ['android', /Android\s([0-9\.]+)/], ['safari', /Version\/([0-9\._]+).*Safari/]];
|
36227 |
|
36228 | /**
|
36229 | * Operating system matching rules.
|
36230 | *
|
36231 | * @type {Array}
|
36232 | */
|
36233 |
|
36234 | var OS_RULES = [['macos', /mac os x/i], ['ios', /os ([\.\_\d]+) like mac os/i], ['android', /android/i], ['firefoxos', /mozilla\/[a-z\.\_\d]+ \((?:mobile)|(?:tablet)/i], ['windows', /windows\s*(?:nt)?\s*([\.\_\d]+)/i]];
|
36235 |
|
36236 | /**
|
36237 | * Define variables to store the result.
|
36238 | */
|
36239 |
|
36240 | var BROWSER = void 0;
|
36241 | var OS = void 0;
|
36242 |
|
36243 | /**
|
36244 | * Run the matchers when in browser.
|
36245 | */
|
36246 |
|
36247 | if (_isInBrowser2.default) {
|
36248 | var userAgent = window.navigator.userAgent;
|
36249 |
|
36250 |
|
36251 | for (var i = 0; i < BROWSER_RULES.length; i++) {
|
36252 | var _BROWSER_RULES$i = _slicedToArray(BROWSER_RULES[i], 2),
|
36253 | name = _BROWSER_RULES$i[0],
|
36254 | regexp = _BROWSER_RULES$i[1];
|
36255 |
|
36256 | if (regexp.test(userAgent)) {
|
36257 | BROWSER = name;
|
36258 | break;
|
36259 | }
|
36260 | }
|
36261 |
|
36262 | for (var _i = 0; _i < OS_RULES.length; _i++) {
|
36263 | var _OS_RULES$_i = _slicedToArray(OS_RULES[_i], 2),
|
36264 | name = _OS_RULES$_i[0],
|
36265 | regexp = _OS_RULES$_i[1];
|
36266 |
|
36267 | if (regexp.test(userAgent)) {
|
36268 | OS = name;
|
36269 | break;
|
36270 | }
|
36271 | }
|
36272 | }
|
36273 |
|
36274 | /**
|
36275 | * Export.
|
36276 | *
|
36277 | * @type {Object}
|
36278 | */
|
36279 |
|
36280 | var IS_CHROME = exports.IS_CHROME = BROWSER === 'chrome';
|
36281 | var IS_FIREFOX = exports.IS_FIREFOX = BROWSER === 'firefox';
|
36282 | var IS_SAFARI = exports.IS_SAFARI = BROWSER === 'safari';
|
36283 | var IS_IE = exports.IS_IE = BROWSER === 'ie';
|
36284 |
|
36285 | var IS_MAC = exports.IS_MAC = OS === 'macos';
|
36286 | var IS_WINDOWS = exports.IS_WINDOWS = OS === 'windows';
|
36287 | },{"is-in-browser":138}],327:[function(require,module,exports){
|
36288 | (function (process){
|
36289 | 'use strict';
|
36290 |
|
36291 | Object.defineProperty(exports, "__esModule", {
|
36292 | value: true
|
36293 | });
|
36294 |
|
36295 | /**
|
36296 | * Is in development?
|
36297 | *
|
36298 | * @type {Boolean}
|
36299 | */
|
36300 |
|
36301 | var IS_DEV = typeof process !== 'undefined' && process.env && process.env.NODE_ENV !== 'production';
|
36302 |
|
36303 | /**
|
36304 | * Export.
|
36305 | *
|
36306 | * @type {Boolean}
|
36307 | */
|
36308 |
|
36309 | exports.default = IS_DEV;
|
36310 | }).call(this,require('_process'))
|
36311 | },{"_process":144}],328:[function(require,module,exports){
|
36312 | 'use strict';
|
36313 |
|
36314 | Object.defineProperty(exports, "__esModule", {
|
36315 | value: true
|
36316 | });
|
36317 |
|
36318 | /**
|
36319 | * Slate-specific model types.
|
36320 | *
|
36321 | * @type {Object}
|
36322 | */
|
36323 |
|
36324 | var MODEL_TYPES = {
|
36325 | BLOCK: '@@__SLATE_BLOCK__@@',
|
36326 | CHANGE: '@@__SLATE_CHANGE__@@',
|
36327 | CHARACTER: '@@__SLATE_CHARACTER__@@',
|
36328 | DOCUMENT: '@@__SLATE_DOCUMENT__@@',
|
36329 | HISTORY: '@@__SLATE_HISTORY__@@',
|
36330 | INLINE: '@@__SLATE_INLINE__@@',
|
36331 | MARK: '@@__SLATE_MARK__@@',
|
36332 | RANGE: '@@__SLATE_RANGE__@@',
|
36333 | SCHEMA: '@@__SLATE_SCHEMA__@@',
|
36334 | SELECTION: '@@__SLATE_SELECTION__@@',
|
36335 | STACK: '@@__SLATE_STACK__@@',
|
36336 | STATE: '@@__SLATE_STATE__@@',
|
36337 | TEXT: '@@__SLATE_TEXT__@@'
|
36338 | };
|
36339 |
|
36340 | /**
|
36341 | * Export.
|
36342 | *
|
36343 | * @type {Object}
|
36344 | */
|
36345 |
|
36346 | exports.default = MODEL_TYPES;
|
36347 | },{}],329:[function(require,module,exports){
|
36348 | 'use strict';
|
36349 |
|
36350 | Object.defineProperty(exports, "__esModule", {
|
36351 | value: true
|
36352 | });
|
36353 | /**
|
36354 | * Slate-specific data transfer types.
|
36355 | *
|
36356 | * @type {Object}
|
36357 | */
|
36358 |
|
36359 | var TYPES = {
|
36360 | FRAGMENT: 'application/x-slate-fragment',
|
36361 | NODE: 'application/x-slate-node'
|
36362 | };
|
36363 |
|
36364 | /**
|
36365 | * Export.
|
36366 | *
|
36367 | * @type {Object}
|
36368 | */
|
36369 |
|
36370 | exports.default = TYPES;
|
36371 | },{}],330:[function(require,module,exports){
|
36372 | 'use strict';
|
36373 |
|
36374 | Object.defineProperty(exports, "__esModule", {
|
36375 | value: true
|
36376 | });
|
36377 | exports.setKeyGenerator = exports.resetKeyGenerator = exports.findDOMNode = exports.Changes = exports.Text = exports.State = exports.Stack = exports.Selection = exports.Schema = exports.Raw = exports.Range = exports.Plain = exports.Placeholder = exports.Operations = exports.Node = exports.Mark = exports.Inline = exports.Html = exports.History = exports.Editor = exports.Document = exports.Data = exports.Character = exports.Block = undefined;
|
36378 |
|
36379 | var _editor = require('./components/editor');
|
36380 |
|
36381 | var _editor2 = _interopRequireDefault(_editor);
|
36382 |
|
36383 | var _placeholder = require('./components/placeholder');
|
36384 |
|
36385 | var _placeholder2 = _interopRequireDefault(_placeholder);
|
36386 |
|
36387 | var _block = require('./models/block');
|
36388 |
|
36389 | var _block2 = _interopRequireDefault(_block);
|
36390 |
|
36391 | var _character = require('./models/character');
|
36392 |
|
36393 | var _character2 = _interopRequireDefault(_character);
|
36394 |
|
36395 | var _data = require('./models/data');
|
36396 |
|
36397 | var _data2 = _interopRequireDefault(_data);
|
36398 |
|
36399 | var _document = require('./models/document');
|
36400 |
|
36401 | var _document2 = _interopRequireDefault(_document);
|
36402 |
|
36403 | var _history = require('./models/history');
|
36404 |
|
36405 | var _history2 = _interopRequireDefault(_history);
|
36406 |
|
36407 | var _inline = require('./models/inline');
|
36408 |
|
36409 | var _inline2 = _interopRequireDefault(_inline);
|
36410 |
|
36411 | var _mark = require('./models/mark');
|
36412 |
|
36413 | var _mark2 = _interopRequireDefault(_mark);
|
36414 |
|
36415 | var _node = require('./models/node');
|
36416 |
|
36417 | var _node2 = _interopRequireDefault(_node);
|
36418 |
|
36419 | var _schema = require('./models/schema');
|
36420 |
|
36421 | var _schema2 = _interopRequireDefault(_schema);
|
36422 |
|
36423 | var _selection = require('./models/selection');
|
36424 |
|
36425 | var _selection2 = _interopRequireDefault(_selection);
|
36426 |
|
36427 | var _stack = require('./models/stack');
|
36428 |
|
36429 | var _stack2 = _interopRequireDefault(_stack);
|
36430 |
|
36431 | var _state = require('./models/state');
|
36432 |
|
36433 | var _state2 = _interopRequireDefault(_state);
|
36434 |
|
36435 | var _text = require('./models/text');
|
36436 |
|
36437 | var _text2 = _interopRequireDefault(_text);
|
36438 |
|
36439 | var _range = require('./models/range');
|
36440 |
|
36441 | var _range2 = _interopRequireDefault(_range);
|
36442 |
|
36443 | var _operations = require('./operations');
|
36444 |
|
36445 | var _operations2 = _interopRequireDefault(_operations);
|
36446 |
|
36447 | var _html = require('./serializers/html');
|
36448 |
|
36449 | var _html2 = _interopRequireDefault(_html);
|
36450 |
|
36451 | var _plain = require('./serializers/plain');
|
36452 |
|
36453 | var _plain2 = _interopRequireDefault(_plain);
|
36454 |
|
36455 | var _raw = require('./serializers/raw');
|
36456 |
|
36457 | var _raw2 = _interopRequireDefault(_raw);
|
36458 |
|
36459 | var _changes = require('./changes');
|
36460 |
|
36461 | var _changes2 = _interopRequireDefault(_changes);
|
36462 |
|
36463 | var _findDomNode = require('./utils/find-dom-node');
|
36464 |
|
36465 | var _findDomNode2 = _interopRequireDefault(_findDomNode);
|
36466 |
|
36467 | var _generateKey = require('./utils/generate-key');
|
36468 |
|
36469 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
36470 |
|
36471 | /**
|
36472 | * Export.
|
36473 | *
|
36474 | * @type {Object}
|
36475 | */
|
36476 |
|
36477 | /**
|
36478 | * Utils.
|
36479 | */
|
36480 |
|
36481 | /**
|
36482 | * Serializers.
|
36483 | */
|
36484 |
|
36485 | exports.Block = _block2.default;
|
36486 | exports.Character = _character2.default;
|
36487 | exports.Data = _data2.default;
|
36488 | exports.Document = _document2.default;
|
36489 | exports.Editor = _editor2.default;
|
36490 | exports.History = _history2.default;
|
36491 | exports.Html = _html2.default;
|
36492 | exports.Inline = _inline2.default;
|
36493 | exports.Mark = _mark2.default;
|
36494 | exports.Node = _node2.default;
|
36495 | exports.Operations = _operations2.default;
|
36496 | exports.Placeholder = _placeholder2.default;
|
36497 | exports.Plain = _plain2.default;
|
36498 | exports.Range = _range2.default;
|
36499 | exports.Raw = _raw2.default;
|
36500 | exports.Schema = _schema2.default;
|
36501 | exports.Selection = _selection2.default;
|
36502 | exports.Stack = _stack2.default;
|
36503 | exports.State = _state2.default;
|
36504 | exports.Text = _text2.default;
|
36505 | exports.Changes = _changes2.default;
|
36506 | exports.findDOMNode = _findDomNode2.default;
|
36507 | exports.resetKeyGenerator = _generateKey.resetKeyGenerator;
|
36508 | exports.setKeyGenerator = _generateKey.setKeyGenerator;
|
36509 |
|
36510 | /**
|
36511 | * Changes.
|
36512 | */
|
36513 |
|
36514 | /**
|
36515 | * Operations.
|
36516 | */
|
36517 |
|
36518 | /**
|
36519 | * Models.
|
36520 | */
|
36521 |
|
36522 | /**
|
36523 | * Components.
|
36524 | */
|
36525 |
|
36526 | exports.default = {
|
36527 | Block: _block2.default,
|
36528 | Character: _character2.default,
|
36529 | Data: _data2.default,
|
36530 | Document: _document2.default,
|
36531 | Editor: _editor2.default,
|
36532 | History: _history2.default,
|
36533 | Html: _html2.default,
|
36534 | Inline: _inline2.default,
|
36535 | Mark: _mark2.default,
|
36536 | Node: _node2.default,
|
36537 | Operations: _operations2.default,
|
36538 | Placeholder: _placeholder2.default,
|
36539 | Plain: _plain2.default,
|
36540 | Range: _range2.default,
|
36541 | Raw: _raw2.default,
|
36542 | Schema: _schema2.default,
|
36543 | Selection: _selection2.default,
|
36544 | Stack: _stack2.default,
|
36545 | State: _state2.default,
|
36546 | Text: _text2.default,
|
36547 | Changes: _changes2.default,
|
36548 | findDOMNode: _findDomNode2.default,
|
36549 | resetKeyGenerator: _generateKey.resetKeyGenerator,
|
36550 | setKeyGenerator: _generateKey.setKeyGenerator
|
36551 | };
|
36552 | },{"./changes":315,"./components/editor":321,"./components/placeholder":324,"./models/block":331,"./models/character":333,"./models/data":334,"./models/document":335,"./models/history":336,"./models/inline":337,"./models/mark":338,"./models/node":339,"./models/range":340,"./models/schema":341,"./models/selection":342,"./models/stack":343,"./models/state":344,"./models/text":345,"./operations":347,"./serializers/html":352,"./serializers/plain":353,"./serializers/raw":354,"./utils/find-dom-node":358,"./utils/generate-key":359}],331:[function(require,module,exports){
|
36553 | 'use strict';
|
36554 |
|
36555 | Object.defineProperty(exports, "__esModule", {
|
36556 | value: true
|
36557 | });
|
36558 |
|
36559 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
36560 |
|
36561 | require('./document');
|
36562 |
|
36563 | var _node = require('./node');
|
36564 |
|
36565 | var _node2 = _interopRequireDefault(_node);
|
36566 |
|
36567 | var _modelTypes = require('../constants/model-types');
|
36568 |
|
36569 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
36570 |
|
36571 | var _generateKey = require('../utils/generate-key');
|
36572 |
|
36573 | var _generateKey2 = _interopRequireDefault(_generateKey);
|
36574 |
|
36575 | var _isPlainObject = require('is-plain-object');
|
36576 |
|
36577 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
36578 |
|
36579 | var _immutable = require('immutable');
|
36580 |
|
36581 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
36582 |
|
36583 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
36584 |
|
36585 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
36586 |
|
36587 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
36588 | /**
|
36589 | * Prevent circular dependencies.
|
36590 | */
|
36591 |
|
36592 | /**
|
36593 | * Dependencies.
|
36594 | */
|
36595 |
|
36596 | /**
|
36597 | * Default properties.
|
36598 | *
|
36599 | * @type {Object}
|
36600 | */
|
36601 |
|
36602 | var DEFAULTS = {
|
36603 | data: new _immutable.Map(),
|
36604 | isVoid: false,
|
36605 | key: undefined,
|
36606 | nodes: new _immutable.List(),
|
36607 | type: undefined
|
36608 | };
|
36609 |
|
36610 | /**
|
36611 | * Block.
|
36612 | *
|
36613 | * @type {Block}
|
36614 | */
|
36615 |
|
36616 | var Block = function (_Record) {
|
36617 | _inherits(Block, _Record);
|
36618 |
|
36619 | function Block() {
|
36620 | _classCallCheck(this, Block);
|
36621 |
|
36622 | return _possibleConstructorReturn(this, (Block.__proto__ || Object.getPrototypeOf(Block)).apply(this, arguments));
|
36623 | }
|
36624 |
|
36625 | _createClass(Block, [{
|
36626 | key: 'toJSON',
|
36627 |
|
36628 |
|
36629 | /**
|
36630 | * Return a JSON representation of the block.
|
36631 | *
|
36632 | * @param {Object} options
|
36633 | * @return {Object}
|
36634 | */
|
36635 |
|
36636 | value: function toJSON() {
|
36637 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
36638 |
|
36639 | var object = {
|
36640 | data: this.data.toJSON(),
|
36641 | key: this.key,
|
36642 | kind: this.kind,
|
36643 | isVoid: this.isVoid,
|
36644 | type: this.type,
|
36645 | nodes: this.nodes.toArray().map(function (n) {
|
36646 | return n.toJSON(options);
|
36647 | })
|
36648 | };
|
36649 |
|
36650 | if (!options.preserveKeys) {
|
36651 | delete object.key;
|
36652 | }
|
36653 |
|
36654 | return object;
|
36655 | }
|
36656 |
|
36657 | /**
|
36658 | * Alias `toJS`.
|
36659 | */
|
36660 |
|
36661 | }, {
|
36662 | key: 'toJS',
|
36663 | value: function toJS(options) {
|
36664 | return this.toJSON(options);
|
36665 | }
|
36666 | }, {
|
36667 | key: 'kind',
|
36668 |
|
36669 |
|
36670 | /**
|
36671 | * Get the node's kind.
|
36672 | *
|
36673 | * @return {String}
|
36674 | */
|
36675 |
|
36676 | get: function get() {
|
36677 | return 'block';
|
36678 | }
|
36679 |
|
36680 | /**
|
36681 | * Check if the block is empty.
|
36682 | *
|
36683 | * @return {Boolean}
|
36684 | */
|
36685 |
|
36686 | }, {
|
36687 | key: 'isEmpty',
|
36688 | get: function get() {
|
36689 | return this.text == '';
|
36690 | }
|
36691 |
|
36692 | /**
|
36693 | * Get the concatenated text of all the block's children.
|
36694 | *
|
36695 | * @return {String}
|
36696 | */
|
36697 |
|
36698 | }, {
|
36699 | key: 'text',
|
36700 | get: function get() {
|
36701 | return this.getText();
|
36702 | }
|
36703 | }], [{
|
36704 | key: 'create',
|
36705 |
|
36706 |
|
36707 | /**
|
36708 | * Create a new `Block` from `value`.
|
36709 | *
|
36710 | * @param {Object|String|Block} value
|
36711 | * @return {Block}
|
36712 | */
|
36713 |
|
36714 | value: function create() {
|
36715 | var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
36716 |
|
36717 | if (Block.isBlock(value)) {
|
36718 | return value;
|
36719 | }
|
36720 |
|
36721 | if (typeof value == 'string') {
|
36722 | value = { type: value };
|
36723 | }
|
36724 |
|
36725 | if ((0, _isPlainObject2.default)(value)) {
|
36726 | return Block.fromJSON(value);
|
36727 | }
|
36728 |
|
36729 | throw new Error('`Block.create` only accepts objects, strings or blocks, but you passed it: ' + value);
|
36730 | }
|
36731 |
|
36732 | /**
|
36733 | * Create a list of `Blocks` from `value`.
|
36734 | *
|
36735 | * @param {Array<Block|Object>|List<Block|Object>} value
|
36736 | * @return {List<Block>}
|
36737 | */
|
36738 |
|
36739 | }, {
|
36740 | key: 'createList',
|
36741 | value: function createList() {
|
36742 | var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
36743 |
|
36744 | if (_immutable.List.isList(value) || Array.isArray(value)) {
|
36745 | var list = new _immutable.List(value.map(Block.create));
|
36746 | return list;
|
36747 | }
|
36748 |
|
36749 | throw new Error('`Block.createList` only accepts arrays or lists, but you passed it: ' + value);
|
36750 | }
|
36751 |
|
36752 | /**
|
36753 | * Create a `Block` from a JSON `object`.
|
36754 | *
|
36755 | * @param {Object|Block} object
|
36756 | * @return {Block}
|
36757 | */
|
36758 |
|
36759 | }, {
|
36760 | key: 'fromJSON',
|
36761 | value: function fromJSON(object) {
|
36762 | if (Block.isBlock(object)) {
|
36763 | return object;
|
36764 | }
|
36765 |
|
36766 | var _object$data = object.data,
|
36767 | data = _object$data === undefined ? {} : _object$data,
|
36768 | _object$isVoid = object.isVoid,
|
36769 | isVoid = _object$isVoid === undefined ? false : _object$isVoid,
|
36770 | _object$key = object.key,
|
36771 | key = _object$key === undefined ? (0, _generateKey2.default)() : _object$key,
|
36772 | type = object.type;
|
36773 | var _object$nodes = object.nodes,
|
36774 | nodes = _object$nodes === undefined ? [] : _object$nodes;
|
36775 |
|
36776 |
|
36777 | if (typeof type != 'string') {
|
36778 | throw new Error('`Block.fromJSON` requires a `type` string.');
|
36779 | }
|
36780 |
|
36781 | if (nodes.length == 0) {
|
36782 | nodes = [{ kind: 'text', text: '' }];
|
36783 | }
|
36784 |
|
36785 | var block = new Block({
|
36786 | key: key,
|
36787 | type: type,
|
36788 | isVoid: !!isVoid,
|
36789 | data: new _immutable.Map(data),
|
36790 | nodes: new _immutable.List(nodes.map(_node2.default.fromJSON))
|
36791 | });
|
36792 |
|
36793 | return block;
|
36794 | }
|
36795 |
|
36796 | /**
|
36797 | * Alias `fromJS`.
|
36798 | */
|
36799 |
|
36800 | }, {
|
36801 | key: 'isBlock',
|
36802 |
|
36803 |
|
36804 | /**
|
36805 | * Check if a `value` is a `Block`.
|
36806 | *
|
36807 | * @param {Any} value
|
36808 | * @return {Boolean}
|
36809 | */
|
36810 |
|
36811 | value: function isBlock(value) {
|
36812 | return !!(value && value[_modelTypes2.default.BLOCK]);
|
36813 | }
|
36814 |
|
36815 | /**
|
36816 | * Check if a `value` is a block list.
|
36817 | *
|
36818 | * @param {Any} value
|
36819 | * @return {Boolean}
|
36820 | */
|
36821 |
|
36822 | }, {
|
36823 | key: 'isBlockList',
|
36824 | value: function isBlockList(value) {
|
36825 | return _immutable.List.isList(value) && value.every(function (item) {
|
36826 | return Block.isBlock(item);
|
36827 | });
|
36828 | }
|
36829 | }]);
|
36830 |
|
36831 | return Block;
|
36832 | }((0, _immutable.Record)(DEFAULTS));
|
36833 |
|
36834 | /**
|
36835 | * Attach a pseudo-symbol for type checking.
|
36836 | */
|
36837 |
|
36838 | Block.fromJS = Block.fromJSON;
|
36839 | Block.prototype[_modelTypes2.default.BLOCK] = true;
|
36840 |
|
36841 | /**
|
36842 | * Mix in `Node` methods.
|
36843 | */
|
36844 |
|
36845 | Object.getOwnPropertyNames(_node2.default.prototype).forEach(function (method) {
|
36846 | if (method == 'constructor') return;
|
36847 | Block.prototype[method] = _node2.default.prototype[method];
|
36848 | });
|
36849 |
|
36850 | /**
|
36851 | * Export.
|
36852 | *
|
36853 | * @type {Block}
|
36854 | */
|
36855 |
|
36856 | exports.default = Block;
|
36857 | },{"../constants/model-types":328,"../utils/generate-key":359,"./document":335,"./node":339,"immutable":135,"is-plain-object":139}],332:[function(require,module,exports){
|
36858 | 'use strict';
|
36859 |
|
36860 | Object.defineProperty(exports, "__esModule", {
|
36861 | value: true
|
36862 | });
|
36863 |
|
36864 | 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; };
|
36865 |
|
36866 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
36867 |
|
36868 | var _modelTypes = require('../constants/model-types');
|
36869 |
|
36870 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
36871 |
|
36872 | var _debug = require('debug');
|
36873 |
|
36874 | var _debug2 = _interopRequireDefault(_debug);
|
36875 |
|
36876 | var _changes = require('../changes');
|
36877 |
|
36878 | var _changes2 = _interopRequireDefault(_changes);
|
36879 |
|
36880 | var _apply = require('../operations/apply');
|
36881 |
|
36882 | var _apply2 = _interopRequireDefault(_apply);
|
36883 |
|
36884 | var _logger = require('../utils/logger');
|
36885 |
|
36886 | var _logger2 = _interopRequireDefault(_logger);
|
36887 |
|
36888 | var _pick = require('lodash/pick');
|
36889 |
|
36890 | var _pick2 = _interopRequireDefault(_pick);
|
36891 |
|
36892 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
36893 |
|
36894 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
36895 |
|
36896 | /**
|
36897 | * Debug.
|
36898 | *
|
36899 | * @type {Function}
|
36900 | */
|
36901 |
|
36902 | var debug = (0, _debug2.default)('slate:change');
|
36903 |
|
36904 | /**
|
36905 | * Change.
|
36906 | *
|
36907 | * @type {Change}
|
36908 | */
|
36909 |
|
36910 | var Change = function () {
|
36911 | _createClass(Change, null, [{
|
36912 | key: 'isChange',
|
36913 |
|
36914 |
|
36915 | /**
|
36916 | * Check if a `value` is a `Change`.
|
36917 | *
|
36918 | * @param {Any} value
|
36919 | * @return {Boolean}
|
36920 | */
|
36921 |
|
36922 | value: function isChange(value) {
|
36923 | return !!(value && value[_modelTypes2.default.CHANGE]);
|
36924 | }
|
36925 |
|
36926 | /**
|
36927 | * Create a new `Change` with `attrs`.
|
36928 | *
|
36929 | * @param {Object} attrs
|
36930 | * @property {State} state
|
36931 | */
|
36932 |
|
36933 | }]);
|
36934 |
|
36935 | function Change(attrs) {
|
36936 | _classCallCheck(this, Change);
|
36937 |
|
36938 | var state = attrs.state;
|
36939 |
|
36940 | this.state = state;
|
36941 | this.operations = [];
|
36942 | this.flags = (0, _pick2.default)(attrs, ['merge', 'save']);
|
36943 | }
|
36944 |
|
36945 | /**
|
36946 | * Get the kind.
|
36947 | *
|
36948 | * @return {String}
|
36949 | */
|
36950 |
|
36951 | _createClass(Change, [{
|
36952 | key: 'applyOperation',
|
36953 |
|
36954 |
|
36955 | /**
|
36956 | * Apply an `operation` to the current state, saving the operation to the
|
36957 | * history if needed.
|
36958 | *
|
36959 | * @param {Object} operation
|
36960 | * @param {Object} options
|
36961 | * @return {Change}
|
36962 | */
|
36963 |
|
36964 | value: function applyOperation(operation) {
|
36965 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
36966 | var operations = this.operations,
|
36967 | flags = this.flags;
|
36968 | var state = this.state;
|
36969 | var _state = state,
|
36970 | history = _state.history;
|
36971 |
|
36972 | // Default options to the change-level flags, this allows for setting
|
36973 | // specific options for all of the operations of a given change.
|
36974 |
|
36975 | options = _extends({}, flags, options);
|
36976 |
|
36977 | // Derive the default option values.
|
36978 | var _options = options,
|
36979 | _options$merge = _options.merge,
|
36980 | merge = _options$merge === undefined ? operations.length == 0 ? null : true : _options$merge,
|
36981 | _options$save = _options.save,
|
36982 | save = _options$save === undefined ? true : _options$save,
|
36983 | _options$skip = _options.skip,
|
36984 | skip = _options$skip === undefined ? null : _options$skip;
|
36985 |
|
36986 | // Apply the operation to the state.
|
36987 |
|
36988 | debug('apply', { operation: operation, save: save, merge: merge });
|
36989 | state = (0, _apply2.default)(state, operation);
|
36990 |
|
36991 | // If needed, save the operation to the history.
|
36992 | if (history && save) {
|
36993 | history = history.save(operation, { merge: merge, skip: skip });
|
36994 | state = state.set('history', history);
|
36995 | }
|
36996 |
|
36997 | // Update the mutable change object.
|
36998 | this.state = state;
|
36999 | this.operations.push(operation);
|
37000 | return this;
|
37001 | }
|
37002 |
|
37003 | /**
|
37004 | * Apply a series of `operations` to the current state.
|
37005 | *
|
37006 | * @param {Array} operations
|
37007 | * @param {Object} options
|
37008 | * @return {Change}
|
37009 | */
|
37010 |
|
37011 | }, {
|
37012 | key: 'applyOperations',
|
37013 | value: function applyOperations(operations, options) {
|
37014 | var _this = this;
|
37015 |
|
37016 | operations.forEach(function (op) {
|
37017 | return _this.applyOperation(op, options);
|
37018 | });
|
37019 | return this;
|
37020 | }
|
37021 |
|
37022 | /**
|
37023 | * Call a change `fn` with arguments.
|
37024 | *
|
37025 | * @param {Function} fn
|
37026 | * @param {Mixed} ...args
|
37027 | * @return {Change}
|
37028 | */
|
37029 |
|
37030 | }, {
|
37031 | key: 'call',
|
37032 | value: function call(fn) {
|
37033 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
37034 | args[_key - 1] = arguments[_key];
|
37035 | }
|
37036 |
|
37037 | fn.apply(undefined, [this].concat(args));
|
37038 | return this;
|
37039 | }
|
37040 |
|
37041 | /**
|
37042 | * Set an operation flag by `key` to `value`.
|
37043 | *
|
37044 | * @param {String} key
|
37045 | * @param {Any} value
|
37046 | * @return {Change}
|
37047 | */
|
37048 |
|
37049 | }, {
|
37050 | key: 'setOperationFlag',
|
37051 | value: function setOperationFlag(key, value) {
|
37052 | this.flags[key] = value;
|
37053 | return this;
|
37054 | }
|
37055 |
|
37056 | /**
|
37057 | * Unset an operation flag by `key`.
|
37058 | *
|
37059 | * @param {String} key
|
37060 | * @return {Change}
|
37061 | */
|
37062 |
|
37063 | }, {
|
37064 | key: 'unsetOperationFlag',
|
37065 | value: function unsetOperationFlag(key) {
|
37066 | delete this.flags[key];
|
37067 | return this;
|
37068 | }
|
37069 |
|
37070 | /**
|
37071 | * Deprecated.
|
37072 | *
|
37073 | * @return {State}
|
37074 | */
|
37075 |
|
37076 | }, {
|
37077 | key: 'apply',
|
37078 | value: function apply() {
|
37079 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
37080 |
|
37081 | _logger2.default.deprecate('0.22.0', 'The `change.apply()` method is deprecrated and no longer necessary, as all operations are applied immediately when invoked. You can access the change\'s state, which is already pre-computed, directly via `change.state` instead.');
|
37082 | return this.state;
|
37083 | }
|
37084 | }, {
|
37085 | key: 'kind',
|
37086 | get: function get() {
|
37087 | return 'change';
|
37088 | }
|
37089 | }]);
|
37090 |
|
37091 | return Change;
|
37092 | }();
|
37093 |
|
37094 | /**
|
37095 | * Attach a pseudo-symbol for type checking.
|
37096 | */
|
37097 |
|
37098 | Change.prototype[_modelTypes2.default.CHANGE] = true;
|
37099 |
|
37100 | /**
|
37101 | * Add a change method for each of the changes.
|
37102 | */
|
37103 |
|
37104 | Object.keys(_changes2.default).forEach(function (type) {
|
37105 | Change.prototype[type] = function () {
|
37106 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
37107 | args[_key2] = arguments[_key2];
|
37108 | }
|
37109 |
|
37110 | debug(type, { args: args });
|
37111 | this.call.apply(this, [_changes2.default[type]].concat(args));
|
37112 | return this;
|
37113 | };
|
37114 | })
|
37115 |
|
37116 | /**
|
37117 | * Add deprecation warnings in case people try to access a change as a state.
|
37118 | */
|
37119 |
|
37120 | ;['hasUndos', 'hasRedos', 'isBlurred', 'isFocused', 'isCollapsed', 'isExpanded', 'isBackward', 'isForward', 'startKey', 'endKey', 'startOffset', 'endOffset', 'anchorKey', 'focusKey', 'anchorOffset', 'focusOffset', 'startBlock', 'endBlock', 'anchorBlock', 'focusBlock', 'startInline', 'endInline', 'anchorInline', 'focusInline', 'startText', 'endText', 'anchorText', 'focusText', 'characters', 'marks', 'blocks', 'fragment', 'inlines', 'texts', 'isEmpty'].forEach(function (getter) {
|
37121 | Object.defineProperty(Change.prototype, getter, {
|
37122 | get: function get() {
|
37123 | _logger2.default.deprecate('0.22.0', 'You attempted to access the `' + getter + '` property of what was previously a `state` object but is now a `change` object. This syntax has been deprecated as plugins are now passed `change` objects instead of `state` objects.');
|
37124 | return this.state[getter];
|
37125 | }
|
37126 | });
|
37127 | });
|
37128 |
|
37129 | Change.prototype.transform = function () {
|
37130 | _logger2.default.deprecate('0.22.0', 'You attempted to call `.transform()` on what was previously a `state` object but is now already a `change` object. This syntax has been deprecated as plugins are now passed `change` objects instead of `state` objects.');
|
37131 | return this;
|
37132 | };
|
37133 |
|
37134 | /**
|
37135 | * Export.
|
37136 | *
|
37137 | * @type {Change}
|
37138 | */
|
37139 |
|
37140 | exports.default = Change;
|
37141 | },{"../changes":315,"../constants/model-types":328,"../operations/apply":346,"../utils/logger":366,"debug":375,"lodash/pick":508}],333:[function(require,module,exports){
|
37142 | 'use strict';
|
37143 |
|
37144 | Object.defineProperty(exports, "__esModule", {
|
37145 | value: true
|
37146 | });
|
37147 |
|
37148 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
37149 |
|
37150 | var _modelTypes = require('../constants/model-types');
|
37151 |
|
37152 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
37153 |
|
37154 | var _isPlainObject = require('is-plain-object');
|
37155 |
|
37156 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
37157 |
|
37158 | var _logger = require('../utils/logger');
|
37159 |
|
37160 | var _logger2 = _interopRequireDefault(_logger);
|
37161 |
|
37162 | var _immutable = require('immutable');
|
37163 |
|
37164 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
37165 |
|
37166 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
37167 |
|
37168 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
37169 |
|
37170 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
37171 |
|
37172 | /**
|
37173 | * Default properties.
|
37174 | *
|
37175 | * @type {Object}
|
37176 | */
|
37177 |
|
37178 | var DEFAULTS = {
|
37179 | marks: new _immutable.Set(),
|
37180 | text: ''
|
37181 | };
|
37182 |
|
37183 | /**
|
37184 | * Character.
|
37185 | *
|
37186 | * @type {Character}
|
37187 | */
|
37188 |
|
37189 | var Character = function (_Record) {
|
37190 | _inherits(Character, _Record);
|
37191 |
|
37192 | function Character() {
|
37193 | _classCallCheck(this, Character);
|
37194 |
|
37195 | return _possibleConstructorReturn(this, (Character.__proto__ || Object.getPrototypeOf(Character)).apply(this, arguments));
|
37196 | }
|
37197 |
|
37198 | _createClass(Character, [{
|
37199 | key: 'toJSON',
|
37200 |
|
37201 |
|
37202 | /**
|
37203 | * Return a JSON representation of the character.
|
37204 | *
|
37205 | * @return {Object}
|
37206 | */
|
37207 |
|
37208 | value: function toJSON() {
|
37209 | var object = {
|
37210 | kind: this.kind,
|
37211 | marks: this.marks.toArray().map(function (m) {
|
37212 | return m.toJSON();
|
37213 | }),
|
37214 | text: this.text
|
37215 | };
|
37216 |
|
37217 | return object;
|
37218 | }
|
37219 |
|
37220 | /**
|
37221 | * Alias `toJS`.
|
37222 | */
|
37223 |
|
37224 | }, {
|
37225 | key: 'toJS',
|
37226 | value: function toJS() {
|
37227 | return this.toJSON();
|
37228 | }
|
37229 | }, {
|
37230 | key: 'kind',
|
37231 |
|
37232 |
|
37233 | /**
|
37234 | * Get the kind.
|
37235 | *
|
37236 | * @return {String}
|
37237 | */
|
37238 |
|
37239 | get: function get() {
|
37240 | return 'character';
|
37241 | }
|
37242 | }], [{
|
37243 | key: 'create',
|
37244 |
|
37245 |
|
37246 | /**
|
37247 | * Create a `Character` with `attrs`.
|
37248 | *
|
37249 | * @param {Object|String|Character} attrs
|
37250 | * @return {Character}
|
37251 | */
|
37252 |
|
37253 | value: function create() {
|
37254 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
37255 |
|
37256 | if (Character.isCharacter(attrs)) {
|
37257 | return attrs;
|
37258 | }
|
37259 |
|
37260 | if (typeof attrs == 'string') {
|
37261 | attrs = { text: attrs };
|
37262 | }
|
37263 |
|
37264 | if ((0, _isPlainObject2.default)(attrs)) {
|
37265 | return Character.fromJSON(attrs);
|
37266 | }
|
37267 |
|
37268 | throw new Error('`Character.create` only accepts objects, strings or characters, but you passed it: ' + attrs);
|
37269 | }
|
37270 |
|
37271 | /**
|
37272 | * Create a list of `Characters` from `elements`.
|
37273 | *
|
37274 | * @param {String|Array<Object|Character|String>|List<Object|Character|String>} elements
|
37275 | * @return {List<Character>}
|
37276 | */
|
37277 |
|
37278 | }, {
|
37279 | key: 'createList',
|
37280 | value: function createList() {
|
37281 | var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
37282 |
|
37283 | if (typeof elements == 'string') {
|
37284 | elements = elements.split('');
|
37285 | }
|
37286 |
|
37287 | if (_immutable.List.isList(elements) || Array.isArray(elements)) {
|
37288 | var list = new _immutable.List(elements.map(Character.create));
|
37289 | return list;
|
37290 | }
|
37291 |
|
37292 | throw new Error('`Block.createList` only accepts strings, arrays or lists, but you passed it: ' + elements);
|
37293 | }
|
37294 |
|
37295 | /**
|
37296 | * Create a `Character` from a JSON `object`.
|
37297 | *
|
37298 | * @param {Object} object
|
37299 | * @return {Character}
|
37300 | */
|
37301 |
|
37302 | }, {
|
37303 | key: 'fromJSON',
|
37304 | value: function fromJSON(object) {
|
37305 | var text = object.text,
|
37306 | _object$marks = object.marks,
|
37307 | marks = _object$marks === undefined ? [] : _object$marks;
|
37308 |
|
37309 |
|
37310 | if (typeof text != 'string') {
|
37311 | throw new Error('`Character.fromJSON` requires a block `text` string.');
|
37312 | }
|
37313 |
|
37314 | var character = new Character({
|
37315 | text: text,
|
37316 | marks: new _immutable.Set(marks)
|
37317 | });
|
37318 |
|
37319 | return character;
|
37320 | }
|
37321 |
|
37322 | /**
|
37323 | * Alias `fromJS`.
|
37324 | */
|
37325 |
|
37326 | }, {
|
37327 | key: 'isCharacter',
|
37328 |
|
37329 |
|
37330 | /**
|
37331 | * Check if a `value` is a `Character`.
|
37332 | *
|
37333 | * @param {Any} value
|
37334 | * @return {Boolean}
|
37335 | */
|
37336 |
|
37337 | value: function isCharacter(value) {
|
37338 | return !!(value && value[_modelTypes2.default.CHARACTER]);
|
37339 | }
|
37340 |
|
37341 | /**
|
37342 | * Check if a `value` is a character list.
|
37343 | *
|
37344 | * @param {Any} value
|
37345 | * @return {Boolean}
|
37346 | */
|
37347 |
|
37348 | }, {
|
37349 | key: 'isCharacterList',
|
37350 | value: function isCharacterList(value) {
|
37351 | return _immutable.List.isList(value) && value.every(function (item) {
|
37352 | return Character.isCharacter(item);
|
37353 | });
|
37354 | }
|
37355 |
|
37356 | /**
|
37357 | * Deprecated.
|
37358 | */
|
37359 |
|
37360 | }, {
|
37361 | key: 'createListFromText',
|
37362 | value: function createListFromText(string) {
|
37363 | _logger2.default.deprecate('0.22.0', 'The `Character.createListFromText(string)` method is deprecated, use `Character.createList(string)` instead.');
|
37364 | return this.createList(string);
|
37365 | }
|
37366 | }]);
|
37367 |
|
37368 | return Character;
|
37369 | }((0, _immutable.Record)(DEFAULTS));
|
37370 |
|
37371 | /**
|
37372 | * Attach a pseudo-symbol for type checking.
|
37373 | */
|
37374 |
|
37375 | Character.fromJS = Character.fromJSON;
|
37376 | Character.prototype[_modelTypes2.default.CHARACTER] = true;
|
37377 |
|
37378 | /**
|
37379 | * Export.
|
37380 | *
|
37381 | * @type {Character}
|
37382 | */
|
37383 |
|
37384 | exports.default = Character;
|
37385 | },{"../constants/model-types":328,"../utils/logger":366,"immutable":135,"is-plain-object":139}],334:[function(require,module,exports){
|
37386 | 'use strict';
|
37387 |
|
37388 | Object.defineProperty(exports, "__esModule", {
|
37389 | value: true
|
37390 | });
|
37391 |
|
37392 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
37393 |
|
37394 | var _isPlainObject = require('is-plain-object');
|
37395 |
|
37396 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
37397 |
|
37398 | var _immutable = require('immutable');
|
37399 |
|
37400 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
37401 |
|
37402 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
37403 |
|
37404 | /**
|
37405 | * Data.
|
37406 | *
|
37407 | * This isn't an immutable record, it's just a thin wrapper around `Map` so that
|
37408 | * we can allow for more convenient creation.
|
37409 | *
|
37410 | * @type {Object}
|
37411 | */
|
37412 |
|
37413 | var Data = function () {
|
37414 | function Data() {
|
37415 | _classCallCheck(this, Data);
|
37416 | }
|
37417 |
|
37418 | _createClass(Data, null, [{
|
37419 | key: 'create',
|
37420 |
|
37421 |
|
37422 | /**
|
37423 | * Create a new `Data` with `attrs`.
|
37424 | *
|
37425 | * @param {Object|Data|Map} attrs
|
37426 | * @return {Data} data
|
37427 | */
|
37428 |
|
37429 | value: function create() {
|
37430 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
37431 |
|
37432 | if (_immutable.Map.isMap(attrs)) {
|
37433 | return attrs;
|
37434 | }
|
37435 |
|
37436 | if ((0, _isPlainObject2.default)(attrs)) {
|
37437 | return Data.fromJSON(attrs);
|
37438 | }
|
37439 |
|
37440 | throw new Error('`Data.create` only accepts objects or maps, but you passed it: ' + attrs);
|
37441 | }
|
37442 |
|
37443 | /**
|
37444 | * Create a `Data` from a JSON `object`.
|
37445 | *
|
37446 | * @param {Object} object
|
37447 | * @return {Data}
|
37448 | */
|
37449 |
|
37450 | }, {
|
37451 | key: 'fromJSON',
|
37452 | value: function fromJSON(object) {
|
37453 | return new _immutable.Map(object);
|
37454 | }
|
37455 |
|
37456 | /**
|
37457 | * Alias `fromJS`.
|
37458 | */
|
37459 |
|
37460 | }]);
|
37461 |
|
37462 | return Data;
|
37463 | }();
|
37464 |
|
37465 | /**
|
37466 | * Export.
|
37467 | *
|
37468 | * @type {Object}
|
37469 | */
|
37470 |
|
37471 | Data.fromJS = Data.fromJSON;
|
37472 | exports.default = Data;
|
37473 | },{"immutable":135,"is-plain-object":139}],335:[function(require,module,exports){
|
37474 | 'use strict';
|
37475 |
|
37476 | Object.defineProperty(exports, "__esModule", {
|
37477 | value: true
|
37478 | });
|
37479 |
|
37480 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
37481 |
|
37482 | require('./block');
|
37483 |
|
37484 | require('./inline');
|
37485 |
|
37486 | var _node = require('./node');
|
37487 |
|
37488 | var _node2 = _interopRequireDefault(_node);
|
37489 |
|
37490 | var _modelTypes = require('../constants/model-types');
|
37491 |
|
37492 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
37493 |
|
37494 | var _generateKey = require('../utils/generate-key');
|
37495 |
|
37496 | var _generateKey2 = _interopRequireDefault(_generateKey);
|
37497 |
|
37498 | var _isPlainObject = require('is-plain-object');
|
37499 |
|
37500 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
37501 |
|
37502 | var _immutable = require('immutable');
|
37503 |
|
37504 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
37505 |
|
37506 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
37507 |
|
37508 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
37509 |
|
37510 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
37511 | /**
|
37512 | * Prevent circular dependencies.
|
37513 | */
|
37514 |
|
37515 | /**
|
37516 | * Dependencies.
|
37517 | */
|
37518 |
|
37519 | /**
|
37520 | * Default properties.
|
37521 | *
|
37522 | * @type {Object}
|
37523 | */
|
37524 |
|
37525 | var DEFAULTS = {
|
37526 | data: new _immutable.Map(),
|
37527 | key: undefined,
|
37528 | nodes: new _immutable.List()
|
37529 | };
|
37530 |
|
37531 | /**
|
37532 | * Document.
|
37533 | *
|
37534 | * @type {Document}
|
37535 | */
|
37536 |
|
37537 | var Document = function (_Record) {
|
37538 | _inherits(Document, _Record);
|
37539 |
|
37540 | function Document() {
|
37541 | _classCallCheck(this, Document);
|
37542 |
|
37543 | return _possibleConstructorReturn(this, (Document.__proto__ || Object.getPrototypeOf(Document)).apply(this, arguments));
|
37544 | }
|
37545 |
|
37546 | _createClass(Document, [{
|
37547 | key: 'toJSON',
|
37548 |
|
37549 |
|
37550 | /**
|
37551 | * Return a JSON representation of the document.
|
37552 | *
|
37553 | * @param {Object} options
|
37554 | * @return {Object}
|
37555 | */
|
37556 |
|
37557 | value: function toJSON() {
|
37558 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
37559 |
|
37560 | var object = {
|
37561 | data: this.data.toJSON(),
|
37562 | key: this.key,
|
37563 | kind: this.kind,
|
37564 | nodes: this.nodes.toArray().map(function (n) {
|
37565 | return n.toJSON(options);
|
37566 | })
|
37567 | };
|
37568 |
|
37569 | if (!options.preserveKeys) {
|
37570 | delete object.key;
|
37571 | }
|
37572 |
|
37573 | return object;
|
37574 | }
|
37575 |
|
37576 | /**
|
37577 | * Alias `toJS`.
|
37578 | */
|
37579 |
|
37580 | }, {
|
37581 | key: 'toJS',
|
37582 | value: function toJS(options) {
|
37583 | return this.toJSON(options);
|
37584 | }
|
37585 | }, {
|
37586 | key: 'kind',
|
37587 |
|
37588 |
|
37589 | /**
|
37590 | * Get the node's kind.
|
37591 | *
|
37592 | * @return {String}
|
37593 | */
|
37594 |
|
37595 | get: function get() {
|
37596 | return 'document';
|
37597 | }
|
37598 |
|
37599 | /**
|
37600 | * Check if the document is empty.
|
37601 | *
|
37602 | * @return {Boolean}
|
37603 | */
|
37604 |
|
37605 | }, {
|
37606 | key: 'isEmpty',
|
37607 | get: function get() {
|
37608 | return this.text == '';
|
37609 | }
|
37610 |
|
37611 | /**
|
37612 | * Get the concatenated text of all the document's children.
|
37613 | *
|
37614 | * @return {String}
|
37615 | */
|
37616 |
|
37617 | }, {
|
37618 | key: 'text',
|
37619 | get: function get() {
|
37620 | return this.getText();
|
37621 | }
|
37622 | }], [{
|
37623 | key: 'create',
|
37624 |
|
37625 |
|
37626 | /**
|
37627 | * Create a new `Document` with `attrs`.
|
37628 | *
|
37629 | * @param {Object|Array|List|Text} attrs
|
37630 | * @return {Document}
|
37631 | */
|
37632 |
|
37633 | value: function create() {
|
37634 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
37635 |
|
37636 | if (Document.isDocument(attrs)) {
|
37637 | return attrs;
|
37638 | }
|
37639 |
|
37640 | if (_immutable.List.isList(attrs) || Array.isArray(attrs)) {
|
37641 | attrs = { nodes: attrs };
|
37642 | }
|
37643 |
|
37644 | if ((0, _isPlainObject2.default)(attrs)) {
|
37645 | return Document.fromJSON(attrs);
|
37646 | }
|
37647 |
|
37648 | throw new Error('`Document.create` only accepts objects, arrays, lists or documents, but you passed it: ' + attrs);
|
37649 | }
|
37650 |
|
37651 | /**
|
37652 | * Create a `Document` from a JSON `object`.
|
37653 | *
|
37654 | * @param {Object|Document} object
|
37655 | * @return {Document}
|
37656 | */
|
37657 |
|
37658 | }, {
|
37659 | key: 'fromJSON',
|
37660 | value: function fromJSON(object) {
|
37661 | if (Document.isDocument(object)) {
|
37662 | return object;
|
37663 | }
|
37664 |
|
37665 | var _object$data = object.data,
|
37666 | data = _object$data === undefined ? {} : _object$data,
|
37667 | _object$key = object.key,
|
37668 | key = _object$key === undefined ? (0, _generateKey2.default)() : _object$key,
|
37669 | _object$nodes = object.nodes,
|
37670 | nodes = _object$nodes === undefined ? [] : _object$nodes;
|
37671 |
|
37672 |
|
37673 | var document = new Document({
|
37674 | key: key,
|
37675 | data: new _immutable.Map(data),
|
37676 | nodes: new _immutable.List(nodes.map(_node2.default.fromJSON))
|
37677 | });
|
37678 |
|
37679 | return document;
|
37680 | }
|
37681 |
|
37682 | /**
|
37683 | * Alias `fromJS`.
|
37684 | */
|
37685 |
|
37686 | }, {
|
37687 | key: 'isDocument',
|
37688 |
|
37689 |
|
37690 | /**
|
37691 | * Check if a `value` is a `Document`.
|
37692 | *
|
37693 | * @param {Any} value
|
37694 | * @return {Boolean}
|
37695 | */
|
37696 |
|
37697 | value: function isDocument(value) {
|
37698 | return !!(value && value[_modelTypes2.default.DOCUMENT]);
|
37699 | }
|
37700 | }]);
|
37701 |
|
37702 | return Document;
|
37703 | }((0, _immutable.Record)(DEFAULTS));
|
37704 |
|
37705 | /**
|
37706 | * Attach a pseudo-symbol for type checking.
|
37707 | */
|
37708 |
|
37709 | Document.fromJS = Document.fromJSON;
|
37710 | Document.prototype[_modelTypes2.default.DOCUMENT] = true;
|
37711 |
|
37712 | /**
|
37713 | * Mix in `Node` methods.
|
37714 | */
|
37715 |
|
37716 | Object.getOwnPropertyNames(_node2.default.prototype).forEach(function (method) {
|
37717 | if (method == 'constructor') return;
|
37718 | Document.prototype[method] = _node2.default.prototype[method];
|
37719 | });
|
37720 |
|
37721 | /**
|
37722 | * Export.
|
37723 | *
|
37724 | * @type {Document}
|
37725 | */
|
37726 |
|
37727 | exports.default = Document;
|
37728 | },{"../constants/model-types":328,"../utils/generate-key":359,"./block":331,"./inline":337,"./node":339,"immutable":135,"is-plain-object":139}],336:[function(require,module,exports){
|
37729 | 'use strict';
|
37730 |
|
37731 | Object.defineProperty(exports, "__esModule", {
|
37732 | value: true
|
37733 | });
|
37734 |
|
37735 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
37736 |
|
37737 | var _modelTypes = require('../constants/model-types');
|
37738 |
|
37739 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
37740 |
|
37741 | var _debug = require('debug');
|
37742 |
|
37743 | var _debug2 = _interopRequireDefault(_debug);
|
37744 |
|
37745 | var _isEqual = require('lodash/isEqual');
|
37746 |
|
37747 | var _isEqual2 = _interopRequireDefault(_isEqual);
|
37748 |
|
37749 | var _isPlainObject = require('is-plain-object');
|
37750 |
|
37751 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
37752 |
|
37753 | var _immutable = require('immutable');
|
37754 |
|
37755 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
37756 |
|
37757 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
37758 |
|
37759 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
37760 |
|
37761 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
37762 |
|
37763 | /**
|
37764 | * Debug.
|
37765 | *
|
37766 | * @type {Function}
|
37767 | */
|
37768 |
|
37769 | var debug = (0, _debug2.default)('slate:history');
|
37770 |
|
37771 | /**
|
37772 | * Default properties.
|
37773 | *
|
37774 | * @type {Object}
|
37775 | */
|
37776 |
|
37777 | var DEFAULTS = {
|
37778 | redos: new _immutable.Stack(),
|
37779 | undos: new _immutable.Stack()
|
37780 | };
|
37781 |
|
37782 | /**
|
37783 | * History.
|
37784 | *
|
37785 | * @type {History}
|
37786 | */
|
37787 |
|
37788 | var History = function (_Record) {
|
37789 | _inherits(History, _Record);
|
37790 |
|
37791 | function History() {
|
37792 | _classCallCheck(this, History);
|
37793 |
|
37794 | return _possibleConstructorReturn(this, (History.__proto__ || Object.getPrototypeOf(History)).apply(this, arguments));
|
37795 | }
|
37796 |
|
37797 | _createClass(History, [{
|
37798 | key: 'save',
|
37799 |
|
37800 |
|
37801 | /**
|
37802 | * Save an `operation` into the history.
|
37803 | *
|
37804 | * @param {Object} operation
|
37805 | * @param {Object} options
|
37806 | * @return {History}
|
37807 | */
|
37808 |
|
37809 | value: function save(operation) {
|
37810 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
37811 |
|
37812 | var history = this;
|
37813 | var _history = history,
|
37814 | undos = _history.undos,
|
37815 | redos = _history.redos;
|
37816 | var merge = options.merge,
|
37817 | skip = options.skip;
|
37818 |
|
37819 | var prevBatch = undos.peek();
|
37820 | var prevOperation = prevBatch && prevBatch[prevBatch.length - 1];
|
37821 |
|
37822 | if (skip == null) {
|
37823 | skip = shouldSkip(operation, prevOperation);
|
37824 | }
|
37825 |
|
37826 | if (skip) {
|
37827 | return history;
|
37828 | }
|
37829 |
|
37830 | if (merge == null) {
|
37831 | merge = shouldMerge(operation, prevOperation);
|
37832 | }
|
37833 |
|
37834 | debug('save', { operation: operation, merge: merge });
|
37835 |
|
37836 | // If the `merge` flag is true, add the operation to the previous batch.
|
37837 | if (merge) {
|
37838 | var batch = prevBatch.slice();
|
37839 | batch.push(operation);
|
37840 | undos = undos.pop();
|
37841 | undos = undos.push(batch);
|
37842 | }
|
37843 |
|
37844 | // Otherwise, create a new batch with the operation.
|
37845 | else {
|
37846 | var _batch = [operation];
|
37847 | undos = undos.push(_batch);
|
37848 | }
|
37849 |
|
37850 | // Constrain the history to 100 entries for memory's sake.
|
37851 | if (undos.length > 100) {
|
37852 | undos = undos.take(100);
|
37853 | }
|
37854 |
|
37855 | // Clear the redos and update the history.
|
37856 | redos = redos.clear();
|
37857 | history = history.set('undos', undos).set('redos', redos);
|
37858 | return history;
|
37859 | }
|
37860 |
|
37861 | /**
|
37862 | * Return a JSON representation of the history.
|
37863 | *
|
37864 | * @return {Object}
|
37865 | */
|
37866 |
|
37867 | }, {
|
37868 | key: 'toJSON',
|
37869 | value: function toJSON() {
|
37870 | var object = {
|
37871 | kind: this.kind,
|
37872 | redos: this.redos.toJSON(),
|
37873 | undos: this.undos.toJSON()
|
37874 | };
|
37875 |
|
37876 | return object;
|
37877 | }
|
37878 |
|
37879 | /**
|
37880 | * Alias `toJS`.
|
37881 | */
|
37882 |
|
37883 | }, {
|
37884 | key: 'toJS',
|
37885 | value: function toJS() {
|
37886 | return this.toJSON();
|
37887 | }
|
37888 | }, {
|
37889 | key: 'kind',
|
37890 |
|
37891 |
|
37892 | /**
|
37893 | * Get the kind.
|
37894 | *
|
37895 | * @return {String}
|
37896 | */
|
37897 |
|
37898 | get: function get() {
|
37899 | return 'history';
|
37900 | }
|
37901 | }], [{
|
37902 | key: 'create',
|
37903 |
|
37904 |
|
37905 | /**
|
37906 | * Create a new `History` with `attrs`.
|
37907 | *
|
37908 | * @param {Object|History} attrs
|
37909 | * @return {History}
|
37910 | */
|
37911 |
|
37912 | value: function create() {
|
37913 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
37914 |
|
37915 | if (History.isHistory(attrs)) {
|
37916 | return attrs;
|
37917 | }
|
37918 |
|
37919 | if ((0, _isPlainObject2.default)(attrs)) {
|
37920 | return History.fromJSON(attrs);
|
37921 | }
|
37922 |
|
37923 | throw new Error('`History.create` only accepts objects or histories, but you passed it: ' + attrs);
|
37924 | }
|
37925 |
|
37926 | /**
|
37927 | * Create a `History` from a JSON `object`.
|
37928 | *
|
37929 | * @param {Object} object
|
37930 | * @return {History}
|
37931 | */
|
37932 |
|
37933 | }, {
|
37934 | key: 'fromJSON',
|
37935 | value: function fromJSON(object) {
|
37936 | var _object$redos = object.redos,
|
37937 | redos = _object$redos === undefined ? [] : _object$redos,
|
37938 | _object$undos = object.undos,
|
37939 | undos = _object$undos === undefined ? [] : _object$undos;
|
37940 |
|
37941 |
|
37942 | var history = new History({
|
37943 | redos: new _immutable.Stack(redos),
|
37944 | undos: new _immutable.Stack(undos)
|
37945 | });
|
37946 |
|
37947 | return history;
|
37948 | }
|
37949 |
|
37950 | /**
|
37951 | * Alias `fromJS`.
|
37952 | */
|
37953 |
|
37954 | }, {
|
37955 | key: 'isHistory',
|
37956 |
|
37957 |
|
37958 | /**
|
37959 | * Check if a `value` is a `History`.
|
37960 | *
|
37961 | * @param {Any} value
|
37962 | * @return {Boolean}
|
37963 | */
|
37964 |
|
37965 | value: function isHistory(value) {
|
37966 | return !!(value && value[_modelTypes2.default.HISTORY]);
|
37967 | }
|
37968 | }]);
|
37969 |
|
37970 | return History;
|
37971 | }((0, _immutable.Record)(DEFAULTS));
|
37972 |
|
37973 | /**
|
37974 | * Attach a pseudo-symbol for type checking.
|
37975 | */
|
37976 |
|
37977 | History.fromJS = History.fromJSON;
|
37978 | History.prototype[_modelTypes2.default.HISTORY] = true;
|
37979 |
|
37980 | /**
|
37981 | * Check whether to merge a new operation `o` into the previous operation `p`.
|
37982 | *
|
37983 | * @param {Object} o
|
37984 | * @param {Object} p
|
37985 | * @return {Boolean}
|
37986 | */
|
37987 |
|
37988 | function shouldMerge(o, p) {
|
37989 | if (!p) return false;
|
37990 |
|
37991 | var merge = o.type == 'set_selection' && p.type == 'set_selection' || o.type == 'insert_text' && p.type == 'insert_text' && o.offset == p.offset + p.text.length && (0, _isEqual2.default)(o.path, p.path) || o.type == 'remove_text' && p.type == 'remove_text' && o.offset + o.text.length == p.offset && (0, _isEqual2.default)(o.path, p.path);
|
37992 |
|
37993 | return merge;
|
37994 | }
|
37995 |
|
37996 | /**
|
37997 | * Check whether to skip a new operation `o`, given previous operation `p`.
|
37998 | *
|
37999 | * @param {Object} o
|
38000 | * @param {Object} p
|
38001 | * @return {Boolean}
|
38002 | */
|
38003 |
|
38004 | function shouldSkip(o, p) {
|
38005 | if (!p) return false;
|
38006 |
|
38007 | var skip = o.type == 'set_selection' && p.type == 'set_selection';
|
38008 |
|
38009 | return skip;
|
38010 | }
|
38011 |
|
38012 | /**
|
38013 | * Export.
|
38014 | *
|
38015 | * @type {History}
|
38016 | */
|
38017 |
|
38018 | exports.default = History;
|
38019 | },{"../constants/model-types":328,"debug":375,"immutable":135,"is-plain-object":139,"lodash/isEqual":499}],337:[function(require,module,exports){
|
38020 | 'use strict';
|
38021 |
|
38022 | Object.defineProperty(exports, "__esModule", {
|
38023 | value: true
|
38024 | });
|
38025 |
|
38026 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
38027 |
|
38028 | require('./document');
|
38029 |
|
38030 | var _node = require('./node');
|
38031 |
|
38032 | var _node2 = _interopRequireDefault(_node);
|
38033 |
|
38034 | var _modelTypes = require('../constants/model-types');
|
38035 |
|
38036 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
38037 |
|
38038 | var _generateKey = require('../utils/generate-key');
|
38039 |
|
38040 | var _generateKey2 = _interopRequireDefault(_generateKey);
|
38041 |
|
38042 | var _isPlainObject = require('is-plain-object');
|
38043 |
|
38044 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
38045 |
|
38046 | var _immutable = require('immutable');
|
38047 |
|
38048 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
38049 |
|
38050 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
38051 |
|
38052 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
38053 |
|
38054 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
38055 | /**
|
38056 | * Prevent circular dependencies.
|
38057 | */
|
38058 |
|
38059 | /**
|
38060 | * Dependencies.
|
38061 | */
|
38062 |
|
38063 | /**
|
38064 | * Default properties.
|
38065 | *
|
38066 | * @type {Object}
|
38067 | */
|
38068 |
|
38069 | var DEFAULTS = {
|
38070 | data: new _immutable.Map(),
|
38071 | isVoid: false,
|
38072 | key: undefined,
|
38073 | nodes: new _immutable.List(),
|
38074 | type: undefined
|
38075 | };
|
38076 |
|
38077 | /**
|
38078 | * Inline.
|
38079 | *
|
38080 | * @type {Inline}
|
38081 | */
|
38082 |
|
38083 | var Inline = function (_Record) {
|
38084 | _inherits(Inline, _Record);
|
38085 |
|
38086 | function Inline() {
|
38087 | _classCallCheck(this, Inline);
|
38088 |
|
38089 | return _possibleConstructorReturn(this, (Inline.__proto__ || Object.getPrototypeOf(Inline)).apply(this, arguments));
|
38090 | }
|
38091 |
|
38092 | _createClass(Inline, [{
|
38093 | key: 'toJSON',
|
38094 |
|
38095 |
|
38096 | /**
|
38097 | * Return a JSON representation of the inline.
|
38098 | *
|
38099 | * @param {Object} options
|
38100 | * @return {Object}
|
38101 | */
|
38102 |
|
38103 | value: function toJSON() {
|
38104 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
38105 |
|
38106 | var object = {
|
38107 | data: this.data.toJSON(),
|
38108 | key: this.key,
|
38109 | kind: this.kind,
|
38110 | isVoid: this.isVoid,
|
38111 | type: this.type,
|
38112 | nodes: this.nodes.toArray().map(function (n) {
|
38113 | return n.toJSON(options);
|
38114 | })
|
38115 | };
|
38116 |
|
38117 | if (!options.preserveKeys) {
|
38118 | delete object.key;
|
38119 | }
|
38120 |
|
38121 | return object;
|
38122 | }
|
38123 |
|
38124 | /**
|
38125 | * Alias `toJS`.
|
38126 | */
|
38127 |
|
38128 | }, {
|
38129 | key: 'toJS',
|
38130 | value: function toJS(options) {
|
38131 | return this.toJSON(options);
|
38132 | }
|
38133 | }, {
|
38134 | key: 'kind',
|
38135 |
|
38136 |
|
38137 | /**
|
38138 | * Get the node's kind.
|
38139 | *
|
38140 | * @return {String}
|
38141 | */
|
38142 |
|
38143 | get: function get() {
|
38144 | return 'inline';
|
38145 | }
|
38146 |
|
38147 | /**
|
38148 | * Check if the inline is empty.
|
38149 | *
|
38150 | * @return {Boolean}
|
38151 | */
|
38152 |
|
38153 | }, {
|
38154 | key: 'isEmpty',
|
38155 | get: function get() {
|
38156 | return this.text == '';
|
38157 | }
|
38158 |
|
38159 | /**
|
38160 | * Get the concatenated text of all the inline's children.
|
38161 | *
|
38162 | * @return {String}
|
38163 | */
|
38164 |
|
38165 | }, {
|
38166 | key: 'text',
|
38167 | get: function get() {
|
38168 | return this.getText();
|
38169 | }
|
38170 | }], [{
|
38171 | key: 'create',
|
38172 |
|
38173 |
|
38174 | /**
|
38175 | * Create a new `Inline` with `attrs`.
|
38176 | *
|
38177 | * @param {Object|String|Inline} attrs
|
38178 | * @return {Inline}
|
38179 | */
|
38180 |
|
38181 | value: function create() {
|
38182 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
38183 |
|
38184 | if (Inline.isInline(attrs)) {
|
38185 | return attrs;
|
38186 | }
|
38187 |
|
38188 | if (typeof attrs == 'string') {
|
38189 | attrs = { type: attrs };
|
38190 | }
|
38191 |
|
38192 | if ((0, _isPlainObject2.default)(attrs)) {
|
38193 | return Inline.fromJSON(attrs);
|
38194 | }
|
38195 |
|
38196 | throw new Error('`Inline.create` only accepts objects, strings or inlines, but you passed it: ' + attrs);
|
38197 | }
|
38198 |
|
38199 | /**
|
38200 | * Create a list of `Inlines` from an array.
|
38201 | *
|
38202 | * @param {Array<Inline|Object>|List<Inline|Object>} elements
|
38203 | * @return {List<Inline>}
|
38204 | */
|
38205 |
|
38206 | }, {
|
38207 | key: 'createList',
|
38208 | value: function createList() {
|
38209 | var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
38210 |
|
38211 | if (_immutable.List.isList(elements) || Array.isArray(elements)) {
|
38212 | var list = new _immutable.List(elements.map(Inline.create));
|
38213 | return list;
|
38214 | }
|
38215 |
|
38216 | throw new Error('`Inline.createList` only accepts arrays or lists, but you passed it: ' + elements);
|
38217 | }
|
38218 |
|
38219 | /**
|
38220 | * Create a `Inline` from a JSON `object`.
|
38221 | *
|
38222 | * @param {Object|Inline} object
|
38223 | * @return {Inline}
|
38224 | */
|
38225 |
|
38226 | }, {
|
38227 | key: 'fromJSON',
|
38228 | value: function fromJSON(object) {
|
38229 | if (Inline.isInline(object)) {
|
38230 | return object;
|
38231 | }
|
38232 |
|
38233 | var _object$data = object.data,
|
38234 | data = _object$data === undefined ? {} : _object$data,
|
38235 | _object$isVoid = object.isVoid,
|
38236 | isVoid = _object$isVoid === undefined ? false : _object$isVoid,
|
38237 | _object$key = object.key,
|
38238 | key = _object$key === undefined ? (0, _generateKey2.default)() : _object$key,
|
38239 | type = object.type;
|
38240 | var _object$nodes = object.nodes,
|
38241 | nodes = _object$nodes === undefined ? [] : _object$nodes;
|
38242 |
|
38243 |
|
38244 | if (typeof type != 'string') {
|
38245 | throw new Error('`Inline.fromJS` requires a `type` string.');
|
38246 | }
|
38247 |
|
38248 | if (nodes.length == 0) {
|
38249 | nodes = [{ kind: 'text', text: '' }];
|
38250 | }
|
38251 |
|
38252 | var inline = new Inline({
|
38253 | key: key,
|
38254 | type: type,
|
38255 | isVoid: !!isVoid,
|
38256 | data: new _immutable.Map(data),
|
38257 | nodes: new _immutable.List(nodes.map(_node2.default.fromJSON))
|
38258 | });
|
38259 |
|
38260 | return inline;
|
38261 | }
|
38262 |
|
38263 | /**
|
38264 | * Alias `fromJS`.
|
38265 | */
|
38266 |
|
38267 | }, {
|
38268 | key: 'isInline',
|
38269 |
|
38270 |
|
38271 | /**
|
38272 | * Check if a `value` is a `Inline`.
|
38273 | *
|
38274 | * @param {Any} value
|
38275 | * @return {Boolean}
|
38276 | */
|
38277 |
|
38278 | value: function isInline(value) {
|
38279 | return !!(value && value[_modelTypes2.default.INLINE]);
|
38280 | }
|
38281 |
|
38282 | /**
|
38283 | * Check if a `value` is a list of inlines.
|
38284 | *
|
38285 | * @param {Any} value
|
38286 | * @return {Boolean}
|
38287 | */
|
38288 |
|
38289 | }, {
|
38290 | key: 'isInlineList',
|
38291 | value: function isInlineList(value) {
|
38292 | return _immutable.List.isList(value) && value.every(function (item) {
|
38293 | return Inline.isInline(item);
|
38294 | });
|
38295 | }
|
38296 | }]);
|
38297 |
|
38298 | return Inline;
|
38299 | }((0, _immutable.Record)(DEFAULTS));
|
38300 |
|
38301 | /**
|
38302 | * Attach a pseudo-symbol for type checking.
|
38303 | */
|
38304 |
|
38305 | Inline.fromJS = Inline.fromJSON;
|
38306 | Inline.prototype[_modelTypes2.default.INLINE] = true;
|
38307 |
|
38308 | /**
|
38309 | * Mix in `Node` methods.
|
38310 | */
|
38311 |
|
38312 | Object.getOwnPropertyNames(_node2.default.prototype).forEach(function (method) {
|
38313 | if (method == 'constructor') return;
|
38314 | Inline.prototype[method] = _node2.default.prototype[method];
|
38315 | });
|
38316 |
|
38317 | /**
|
38318 | * Export.
|
38319 | *
|
38320 | * @type {Inline}
|
38321 | */
|
38322 |
|
38323 | exports.default = Inline;
|
38324 | },{"../constants/model-types":328,"../utils/generate-key":359,"./document":335,"./node":339,"immutable":135,"is-plain-object":139}],338:[function(require,module,exports){
|
38325 | 'use strict';
|
38326 |
|
38327 | Object.defineProperty(exports, "__esModule", {
|
38328 | value: true
|
38329 | });
|
38330 |
|
38331 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
38332 |
|
38333 | var _modelTypes = require('../constants/model-types');
|
38334 |
|
38335 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
38336 |
|
38337 | var _data = require('./data');
|
38338 |
|
38339 | var _data2 = _interopRequireDefault(_data);
|
38340 |
|
38341 | var _isPlainObject = require('is-plain-object');
|
38342 |
|
38343 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
38344 |
|
38345 | var _memoize = require('../utils/memoize');
|
38346 |
|
38347 | var _memoize2 = _interopRequireDefault(_memoize);
|
38348 |
|
38349 | var _immutable = require('immutable');
|
38350 |
|
38351 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
38352 |
|
38353 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
38354 |
|
38355 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
38356 |
|
38357 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
38358 |
|
38359 | /**
|
38360 | * Default properties.
|
38361 | *
|
38362 | * @type {Object}
|
38363 | */
|
38364 |
|
38365 | var DEFAULTS = {
|
38366 | data: new _immutable.Map(),
|
38367 | type: undefined
|
38368 | };
|
38369 |
|
38370 | /**
|
38371 | * Mark.
|
38372 | *
|
38373 | * @type {Mark}
|
38374 | */
|
38375 |
|
38376 | var Mark = function (_Record) {
|
38377 | _inherits(Mark, _Record);
|
38378 |
|
38379 | function Mark() {
|
38380 | _classCallCheck(this, Mark);
|
38381 |
|
38382 | return _possibleConstructorReturn(this, (Mark.__proto__ || Object.getPrototypeOf(Mark)).apply(this, arguments));
|
38383 | }
|
38384 |
|
38385 | _createClass(Mark, [{
|
38386 | key: 'getComponent',
|
38387 |
|
38388 |
|
38389 | /**
|
38390 | * Get the component for the node from a `schema`.
|
38391 | *
|
38392 | * @param {Schema} schema
|
38393 | * @return {Component|Void}
|
38394 | */
|
38395 |
|
38396 | value: function getComponent(schema) {
|
38397 | return schema.__getComponent(this);
|
38398 | }
|
38399 |
|
38400 | /**
|
38401 | * Return a JSON representation of the mark.
|
38402 | *
|
38403 | * @return {Object}
|
38404 | */
|
38405 |
|
38406 | }, {
|
38407 | key: 'toJSON',
|
38408 | value: function toJSON() {
|
38409 | var object = {
|
38410 | data: this.data.toJSON(),
|
38411 | kind: this.kind,
|
38412 | type: this.type
|
38413 | };
|
38414 |
|
38415 | return object;
|
38416 | }
|
38417 |
|
38418 | /**
|
38419 | * Alias `toJS`.
|
38420 | */
|
38421 |
|
38422 | }, {
|
38423 | key: 'toJS',
|
38424 | value: function toJS() {
|
38425 | return this.toJSON();
|
38426 | }
|
38427 | }, {
|
38428 | key: 'kind',
|
38429 |
|
38430 |
|
38431 | /**
|
38432 | * Get the kind.
|
38433 | */
|
38434 |
|
38435 | get: function get() {
|
38436 | return 'mark';
|
38437 | }
|
38438 | }], [{
|
38439 | key: 'create',
|
38440 |
|
38441 |
|
38442 | /**
|
38443 | * Create a new `Mark` with `attrs`.
|
38444 | *
|
38445 | * @param {Object|Mark} attrs
|
38446 | * @return {Mark}
|
38447 | */
|
38448 |
|
38449 | value: function create() {
|
38450 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
38451 |
|
38452 | if (Mark.isMark(attrs)) {
|
38453 | return attrs;
|
38454 | }
|
38455 |
|
38456 | if (typeof attrs == 'string') {
|
38457 | attrs = { type: attrs };
|
38458 | }
|
38459 |
|
38460 | if ((0, _isPlainObject2.default)(attrs)) {
|
38461 | return Mark.fromJSON(attrs);
|
38462 | }
|
38463 |
|
38464 | throw new Error('`Mark.create` only accepts objects, strings or marks, but you passed it: ' + attrs);
|
38465 | }
|
38466 |
|
38467 | /**
|
38468 | * Create a set of marks.
|
38469 | *
|
38470 | * @param {Array<Object|Mark>} elements
|
38471 | * @return {Set<Mark>}
|
38472 | */
|
38473 |
|
38474 | }, {
|
38475 | key: 'createSet',
|
38476 | value: function createSet(elements) {
|
38477 | if (_immutable.Set.isSet(elements) || Array.isArray(elements)) {
|
38478 | var marks = new _immutable.Set(elements.map(Mark.create));
|
38479 | return marks;
|
38480 | }
|
38481 |
|
38482 | if (elements == null) {
|
38483 | return new _immutable.Set();
|
38484 | }
|
38485 |
|
38486 | throw new Error('`Mark.createSet` only accepts sets, arrays or null, but you passed it: ' + elements);
|
38487 | }
|
38488 |
|
38489 | /**
|
38490 | * Create a dictionary of settable mark properties from `attrs`.
|
38491 | *
|
38492 | * @param {Object|String|Mark} attrs
|
38493 | * @return {Object}
|
38494 | */
|
38495 |
|
38496 | }, {
|
38497 | key: 'createProperties',
|
38498 | value: function createProperties() {
|
38499 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
38500 |
|
38501 | if (Mark.isMark(attrs)) {
|
38502 | return {
|
38503 | data: attrs.data,
|
38504 | type: attrs.type
|
38505 | };
|
38506 | }
|
38507 |
|
38508 | if (typeof attrs == 'string') {
|
38509 | return { type: attrs };
|
38510 | }
|
38511 |
|
38512 | if ((0, _isPlainObject2.default)(attrs)) {
|
38513 | var props = {};
|
38514 | if ('type' in attrs) props.type = attrs.type;
|
38515 | if ('data' in attrs) props.data = _data2.default.create(attrs.data);
|
38516 | return props;
|
38517 | }
|
38518 |
|
38519 | throw new Error('`Mark.createProperties` only accepts objects, strings or marks, but you passed it: ' + attrs);
|
38520 | }
|
38521 |
|
38522 | /**
|
38523 | * Create a `Mark` from a JSON `object`.
|
38524 | *
|
38525 | * @param {Object} object
|
38526 | * @return {Mark}
|
38527 | */
|
38528 |
|
38529 | }, {
|
38530 | key: 'fromJSON',
|
38531 | value: function fromJSON(object) {
|
38532 | var _object$data = object.data,
|
38533 | data = _object$data === undefined ? {} : _object$data,
|
38534 | type = object.type;
|
38535 |
|
38536 |
|
38537 | if (typeof type != 'string') {
|
38538 | throw new Error('`Mark.fromJS` requires a `type` string.');
|
38539 | }
|
38540 |
|
38541 | var mark = new Mark({
|
38542 | type: type,
|
38543 | data: new _immutable.Map(data)
|
38544 | });
|
38545 |
|
38546 | return mark;
|
38547 | }
|
38548 |
|
38549 | /**
|
38550 | * Alias `fromJS`.
|
38551 | */
|
38552 |
|
38553 | }, {
|
38554 | key: 'isMark',
|
38555 |
|
38556 |
|
38557 | /**
|
38558 | * Check if a `value` is a `Mark`.
|
38559 | *
|
38560 | * @param {Any} value
|
38561 | * @return {Boolean}
|
38562 | */
|
38563 |
|
38564 | value: function isMark(value) {
|
38565 | return !!(value && value[_modelTypes2.default.MARK]);
|
38566 | }
|
38567 |
|
38568 | /**
|
38569 | * Check if a `value` is a set of marks.
|
38570 | *
|
38571 | * @param {Any} value
|
38572 | * @return {Boolean}
|
38573 | */
|
38574 |
|
38575 | }, {
|
38576 | key: 'isMarkSet',
|
38577 | value: function isMarkSet(value) {
|
38578 | return _immutable.Set.isSet(value) && value.every(function (item) {
|
38579 | return Mark.isMark(item);
|
38580 | });
|
38581 | }
|
38582 | }]);
|
38583 |
|
38584 | return Mark;
|
38585 | }((0, _immutable.Record)(DEFAULTS));
|
38586 |
|
38587 | /**
|
38588 | * Attach a pseudo-symbol for type checking.
|
38589 | */
|
38590 |
|
38591 | Mark.fromJS = Mark.fromJSON;
|
38592 | Mark.prototype[_modelTypes2.default.MARK] = true;
|
38593 |
|
38594 | /**
|
38595 | * Memoize read methods.
|
38596 | */
|
38597 |
|
38598 | (0, _memoize2.default)(Mark.prototype, ['getComponent'], {
|
38599 | takesArguments: true
|
38600 | });
|
38601 |
|
38602 | /**
|
38603 | * Export.
|
38604 | *
|
38605 | * @type {Mark}
|
38606 | */
|
38607 |
|
38608 | exports.default = Mark;
|
38609 | },{"../constants/model-types":328,"../utils/memoize":367,"./data":334,"immutable":135,"is-plain-object":139}],339:[function(require,module,exports){
|
38610 | 'use strict';
|
38611 |
|
38612 | Object.defineProperty(exports, "__esModule", {
|
38613 | value: true
|
38614 | });
|
38615 |
|
38616 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
38617 |
|
38618 | var _block = require('./block');
|
38619 |
|
38620 | var _block2 = _interopRequireDefault(_block);
|
38621 |
|
38622 | var _data = require('./data');
|
38623 |
|
38624 | var _data2 = _interopRequireDefault(_data);
|
38625 |
|
38626 | var _document = require('./document');
|
38627 |
|
38628 | var _document2 = _interopRequireDefault(_document);
|
38629 |
|
38630 | var _inline = require('./inline');
|
38631 |
|
38632 | var _inline2 = _interopRequireDefault(_inline);
|
38633 |
|
38634 | var _text = require('./text');
|
38635 |
|
38636 | var _text2 = _interopRequireDefault(_text);
|
38637 |
|
38638 | var _direction = require('direction');
|
38639 |
|
38640 | var _direction2 = _interopRequireDefault(_direction);
|
38641 |
|
38642 | var _generateKey = require('../utils/generate-key');
|
38643 |
|
38644 | var _generateKey2 = _interopRequireDefault(_generateKey);
|
38645 |
|
38646 | var _isIndexInRange = require('../utils/is-index-in-range');
|
38647 |
|
38648 | var _isIndexInRange2 = _interopRequireDefault(_isIndexInRange);
|
38649 |
|
38650 | var _isPlainObject = require('is-plain-object');
|
38651 |
|
38652 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
38653 |
|
38654 | var _logger = require('../utils/logger');
|
38655 |
|
38656 | var _logger2 = _interopRequireDefault(_logger);
|
38657 |
|
38658 | var _memoize = require('../utils/memoize');
|
38659 |
|
38660 | var _memoize2 = _interopRequireDefault(_memoize);
|
38661 |
|
38662 | var _immutable = require('immutable');
|
38663 |
|
38664 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
38665 |
|
38666 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
38667 |
|
38668 | /**
|
38669 | * Node.
|
38670 | *
|
38671 | * And interface that `Document`, `Block` and `Inline` all implement, to make
|
38672 | * working with the recursive node tree easier.
|
38673 | *
|
38674 | * @type {Node}
|
38675 | */
|
38676 |
|
38677 | var Node = function () {
|
38678 | function Node() {
|
38679 | _classCallCheck(this, Node);
|
38680 | }
|
38681 |
|
38682 | _createClass(Node, [{
|
38683 | key: 'areDescendantsSorted',
|
38684 |
|
38685 |
|
38686 | /**
|
38687 | * True if the node has both descendants in that order, false otherwise. The
|
38688 | * order is depth-first, post-order.
|
38689 | *
|
38690 | * @param {String} first
|
38691 | * @param {String} second
|
38692 | * @return {Boolean}
|
38693 | */
|
38694 |
|
38695 | value: function areDescendantsSorted(first, second) {
|
38696 | first = normalizeKey(first);
|
38697 | second = normalizeKey(second);
|
38698 |
|
38699 | var sorted = void 0;
|
38700 |
|
38701 | this.forEachDescendant(function (n) {
|
38702 | if (n.key === first) {
|
38703 | sorted = true;
|
38704 | return false;
|
38705 | } else if (n.key === second) {
|
38706 | sorted = false;
|
38707 | return false;
|
38708 | }
|
38709 | });
|
38710 |
|
38711 | return sorted;
|
38712 | }
|
38713 |
|
38714 | /**
|
38715 | * Assert that a node has a child by `key` and return it.
|
38716 | *
|
38717 | * @param {String} key
|
38718 | * @return {Node}
|
38719 | */
|
38720 |
|
38721 | }, {
|
38722 | key: 'assertChild',
|
38723 | value: function assertChild(key) {
|
38724 | var child = this.getChild(key);
|
38725 |
|
38726 | if (!child) {
|
38727 | key = normalizeKey(key);
|
38728 | throw new Error('Could not find a child node with key "' + key + '".');
|
38729 | }
|
38730 |
|
38731 | return child;
|
38732 | }
|
38733 |
|
38734 | /**
|
38735 | * Assert that a node has a descendant by `key` and return it.
|
38736 | *
|
38737 | * @param {String} key
|
38738 | * @return {Node}
|
38739 | */
|
38740 |
|
38741 | }, {
|
38742 | key: 'assertDescendant',
|
38743 | value: function assertDescendant(key) {
|
38744 | var descendant = this.getDescendant(key);
|
38745 |
|
38746 | if (!descendant) {
|
38747 | key = normalizeKey(key);
|
38748 | throw new Error('Could not find a descendant node with key "' + key + '".');
|
38749 | }
|
38750 |
|
38751 | return descendant;
|
38752 | }
|
38753 |
|
38754 | /**
|
38755 | * Assert that a node's tree has a node by `key` and return it.
|
38756 | *
|
38757 | * @param {String} key
|
38758 | * @return {Node}
|
38759 | */
|
38760 |
|
38761 | }, {
|
38762 | key: 'assertNode',
|
38763 | value: function assertNode(key) {
|
38764 | var node = this.getNode(key);
|
38765 |
|
38766 | if (!node) {
|
38767 | key = normalizeKey(key);
|
38768 | throw new Error('Could not find a node with key "' + key + '".');
|
38769 | }
|
38770 |
|
38771 | return node;
|
38772 | }
|
38773 |
|
38774 | /**
|
38775 | * Assert that a node exists at `path` and return it.
|
38776 | *
|
38777 | * @param {Array} path
|
38778 | * @return {Node}
|
38779 | */
|
38780 |
|
38781 | }, {
|
38782 | key: 'assertPath',
|
38783 | value: function assertPath(path) {
|
38784 | var descendant = this.getDescendantAtPath(path);
|
38785 |
|
38786 | if (!descendant) {
|
38787 | throw new Error('Could not find a descendant at path "' + path + '".');
|
38788 | }
|
38789 |
|
38790 | return descendant;
|
38791 | }
|
38792 |
|
38793 | /**
|
38794 | * Recursively filter all descendant nodes with `iterator`.
|
38795 | *
|
38796 | * @param {Function} iterator
|
38797 | * @return {List<Node>}
|
38798 | */
|
38799 |
|
38800 | }, {
|
38801 | key: 'filterDescendants',
|
38802 | value: function filterDescendants(iterator) {
|
38803 | var matches = [];
|
38804 |
|
38805 | this.forEachDescendant(function (node, i, nodes) {
|
38806 | if (iterator(node, i, nodes)) matches.push(node);
|
38807 | });
|
38808 |
|
38809 | return (0, _immutable.List)(matches);
|
38810 | }
|
38811 |
|
38812 | /**
|
38813 | * Recursively find all descendant nodes by `iterator`.
|
38814 | *
|
38815 | * @param {Function} iterator
|
38816 | * @return {Node|Null}
|
38817 | */
|
38818 |
|
38819 | }, {
|
38820 | key: 'findDescendant',
|
38821 | value: function findDescendant(iterator) {
|
38822 | var found = null;
|
38823 |
|
38824 | this.forEachDescendant(function (node, i, nodes) {
|
38825 | if (iterator(node, i, nodes)) {
|
38826 | found = node;
|
38827 | return false;
|
38828 | }
|
38829 | });
|
38830 |
|
38831 | return found;
|
38832 | }
|
38833 |
|
38834 | /**
|
38835 | * Recursively iterate over all descendant nodes with `iterator`. If the
|
38836 | * iterator returns false it will break the loop.
|
38837 | *
|
38838 | * @param {Function} iterator
|
38839 | */
|
38840 |
|
38841 | }, {
|
38842 | key: 'forEachDescendant',
|
38843 | value: function forEachDescendant(iterator) {
|
38844 | var ret = void 0;
|
38845 |
|
38846 | this.nodes.forEach(function (child, i, nodes) {
|
38847 | if (iterator(child, i, nodes) === false) {
|
38848 | ret = false;
|
38849 | return false;
|
38850 | }
|
38851 |
|
38852 | if (child.kind != 'text') {
|
38853 | ret = child.forEachDescendant(iterator);
|
38854 | return ret;
|
38855 | }
|
38856 | });
|
38857 |
|
38858 | return ret;
|
38859 | }
|
38860 |
|
38861 | /**
|
38862 | * Get the path of ancestors of a descendant node by `key`.
|
38863 | *
|
38864 | * @param {String|Node} key
|
38865 | * @return {List<Node>|Null}
|
38866 | */
|
38867 |
|
38868 | }, {
|
38869 | key: 'getAncestors',
|
38870 | value: function getAncestors(key) {
|
38871 | key = normalizeKey(key);
|
38872 |
|
38873 | if (key == this.key) return (0, _immutable.List)();
|
38874 | if (this.hasChild(key)) return (0, _immutable.List)([this]);
|
38875 |
|
38876 | var ancestors = void 0;
|
38877 | this.nodes.find(function (node) {
|
38878 | if (node.kind == 'text') return false;
|
38879 | ancestors = node.getAncestors(key);
|
38880 | return ancestors;
|
38881 | });
|
38882 |
|
38883 | if (ancestors) {
|
38884 | return ancestors.unshift(this);
|
38885 | } else {
|
38886 | return null;
|
38887 | }
|
38888 | }
|
38889 |
|
38890 | /**
|
38891 | * Get the leaf block descendants of the node.
|
38892 | *
|
38893 | * @return {List<Node>}
|
38894 | */
|
38895 |
|
38896 | }, {
|
38897 | key: 'getBlocks',
|
38898 | value: function getBlocks() {
|
38899 | var array = this.getBlocksAsArray();
|
38900 | return new _immutable.List(array);
|
38901 | }
|
38902 |
|
38903 | /**
|
38904 | * Get the leaf block descendants of the node.
|
38905 | *
|
38906 | * @return {List<Node>}
|
38907 | */
|
38908 |
|
38909 | }, {
|
38910 | key: 'getBlocksAsArray',
|
38911 | value: function getBlocksAsArray() {
|
38912 | return this.nodes.reduce(function (array, child) {
|
38913 | if (child.kind != 'block') return array;
|
38914 | if (!child.isLeafBlock()) return array.concat(child.getBlocksAsArray());
|
38915 | array.push(child);
|
38916 | return array;
|
38917 | }, []);
|
38918 | }
|
38919 |
|
38920 | /**
|
38921 | * Get the leaf block descendants in a `range`.
|
38922 | *
|
38923 | * @param {Selection} range
|
38924 | * @return {List<Node>}
|
38925 | */
|
38926 |
|
38927 | }, {
|
38928 | key: 'getBlocksAtRange',
|
38929 | value: function getBlocksAtRange(range) {
|
38930 | var array = this.getBlocksAtRangeAsArray(range);
|
38931 | // Eliminate duplicates by converting to an `OrderedSet` first.
|
38932 | return new _immutable.List(new _immutable.OrderedSet(array));
|
38933 | }
|
38934 |
|
38935 | /**
|
38936 | * Get the leaf block descendants in a `range` as an array
|
38937 | *
|
38938 | * @param {Selection} range
|
38939 | * @return {Array}
|
38940 | */
|
38941 |
|
38942 | }, {
|
38943 | key: 'getBlocksAtRangeAsArray',
|
38944 | value: function getBlocksAtRangeAsArray(range) {
|
38945 | range = range.normalize(this);
|
38946 | if (range.isUnset) return [];
|
38947 |
|
38948 | var _range = range,
|
38949 | startKey = _range.startKey,
|
38950 | endKey = _range.endKey;
|
38951 |
|
38952 | var startBlock = this.getClosestBlock(startKey);
|
38953 |
|
38954 | // PERF: the most common case is when the range is in a single block node,
|
38955 | // where we can avoid a lot of iterating of the tree.
|
38956 | if (startKey == endKey) return [startBlock];
|
38957 |
|
38958 | var endBlock = this.getClosestBlock(endKey);
|
38959 | var blocks = this.getBlocksAsArray();
|
38960 | var start = blocks.indexOf(startBlock);
|
38961 | var end = blocks.indexOf(endBlock);
|
38962 | return blocks.slice(start, end + 1);
|
38963 | }
|
38964 |
|
38965 | /**
|
38966 | * Get all of the leaf blocks that match a `type`.
|
38967 | *
|
38968 | * @param {String} type
|
38969 | * @return {List<Node>}
|
38970 | */
|
38971 |
|
38972 | }, {
|
38973 | key: 'getBlocksByType',
|
38974 | value: function getBlocksByType(type) {
|
38975 | var array = this.getBlocksByTypeAsArray(type);
|
38976 | return new _immutable.List(array);
|
38977 | }
|
38978 |
|
38979 | /**
|
38980 | * Get all of the leaf blocks that match a `type` as an array
|
38981 | *
|
38982 | * @param {String} type
|
38983 | * @return {Array}
|
38984 | */
|
38985 |
|
38986 | }, {
|
38987 | key: 'getBlocksByTypeAsArray',
|
38988 | value: function getBlocksByTypeAsArray(type) {
|
38989 | return this.nodes.reduce(function (array, node) {
|
38990 | if (node.kind != 'block') {
|
38991 | return array;
|
38992 | } else if (node.isLeafBlock() && node.type == type) {
|
38993 | array.push(node);
|
38994 | return array;
|
38995 | } else {
|
38996 | return array.concat(node.getBlocksByTypeAsArray(type));
|
38997 | }
|
38998 | }, []);
|
38999 | }
|
39000 |
|
39001 | /**
|
39002 | * Get all of the characters for every text node.
|
39003 | *
|
39004 | * @return {List<Character>}
|
39005 | */
|
39006 |
|
39007 | }, {
|
39008 | key: 'getCharacters',
|
39009 | value: function getCharacters() {
|
39010 | var array = this.getCharactersAsArray();
|
39011 | return new _immutable.List(array);
|
39012 | }
|
39013 |
|
39014 | /**
|
39015 | * Get all of the characters for every text node as an array
|
39016 | *
|
39017 | * @return {Array}
|
39018 | */
|
39019 |
|
39020 | }, {
|
39021 | key: 'getCharactersAsArray',
|
39022 | value: function getCharactersAsArray() {
|
39023 | return this.nodes.reduce(function (arr, node) {
|
39024 | return node.kind == 'text' ? arr.concat(node.characters.toArray()) : arr.concat(node.getCharactersAsArray());
|
39025 | }, []);
|
39026 | }
|
39027 |
|
39028 | /**
|
39029 | * Get a list of the characters in a `range`.
|
39030 | *
|
39031 | * @param {Selection} range
|
39032 | * @return {List<Character>}
|
39033 | */
|
39034 |
|
39035 | }, {
|
39036 | key: 'getCharactersAtRange',
|
39037 | value: function getCharactersAtRange(range) {
|
39038 | var array = this.getCharactersAtRangeAsArray(range);
|
39039 | return new _immutable.List(array);
|
39040 | }
|
39041 |
|
39042 | /**
|
39043 | * Get a list of the characters in a `range` as an array.
|
39044 | *
|
39045 | * @param {Selection} range
|
39046 | * @return {Array}
|
39047 | */
|
39048 |
|
39049 | }, {
|
39050 | key: 'getCharactersAtRangeAsArray',
|
39051 | value: function getCharactersAtRangeAsArray(range) {
|
39052 | range = range.normalize(this);
|
39053 | if (range.isUnset) return [];
|
39054 |
|
39055 | return this.getTextsAtRange(range).reduce(function (arr, text) {
|
39056 | var chars = text.characters.filter(function (char, i) {
|
39057 | return (0, _isIndexInRange2.default)(i, text, range);
|
39058 | }).toArray();
|
39059 |
|
39060 | return arr.concat(chars);
|
39061 | }, []);
|
39062 | }
|
39063 |
|
39064 | /**
|
39065 | * Get a child node by `key`.
|
39066 | *
|
39067 | * @param {String} key
|
39068 | * @return {Node|Null}
|
39069 | */
|
39070 |
|
39071 | }, {
|
39072 | key: 'getChild',
|
39073 | value: function getChild(key) {
|
39074 | key = normalizeKey(key);
|
39075 | return this.nodes.find(function (node) {
|
39076 | return node.key == key;
|
39077 | });
|
39078 | }
|
39079 |
|
39080 | /**
|
39081 | * Get closest parent of node by `key` that matches `iterator`.
|
39082 | *
|
39083 | * @param {String} key
|
39084 | * @param {Function} iterator
|
39085 | * @return {Node|Null}
|
39086 | */
|
39087 |
|
39088 | }, {
|
39089 | key: 'getClosest',
|
39090 | value: function getClosest(key, iterator) {
|
39091 | key = normalizeKey(key);
|
39092 | var ancestors = this.getAncestors(key);
|
39093 | if (!ancestors) {
|
39094 | throw new Error('Could not find a descendant node with key "' + key + '".');
|
39095 | }
|
39096 |
|
39097 | // Exclude this node itself.
|
39098 | return ancestors.rest().findLast(iterator);
|
39099 | }
|
39100 |
|
39101 | /**
|
39102 | * Get the closest block parent of a `node`.
|
39103 | *
|
39104 | * @param {String} key
|
39105 | * @return {Node|Null}
|
39106 | */
|
39107 |
|
39108 | }, {
|
39109 | key: 'getClosestBlock',
|
39110 | value: function getClosestBlock(key) {
|
39111 | return this.getClosest(key, function (parent) {
|
39112 | return parent.kind == 'block';
|
39113 | });
|
39114 | }
|
39115 |
|
39116 | /**
|
39117 | * Get the closest inline parent of a `node`.
|
39118 | *
|
39119 | * @param {String} key
|
39120 | * @return {Node|Null}
|
39121 | */
|
39122 |
|
39123 | }, {
|
39124 | key: 'getClosestInline',
|
39125 | value: function getClosestInline(key) {
|
39126 | return this.getClosest(key, function (parent) {
|
39127 | return parent.kind == 'inline';
|
39128 | });
|
39129 | }
|
39130 |
|
39131 | /**
|
39132 | * Get the closest void parent of a `node`.
|
39133 | *
|
39134 | * @param {String} key
|
39135 | * @return {Node|Null}
|
39136 | */
|
39137 |
|
39138 | }, {
|
39139 | key: 'getClosestVoid',
|
39140 | value: function getClosestVoid(key) {
|
39141 | return this.getClosest(key, function (parent) {
|
39142 | return parent.isVoid;
|
39143 | });
|
39144 | }
|
39145 |
|
39146 | /**
|
39147 | * Get the common ancestor of nodes `one` and `two` by keys.
|
39148 | *
|
39149 | * @param {String} one
|
39150 | * @param {String} two
|
39151 | * @return {Node}
|
39152 | */
|
39153 |
|
39154 | }, {
|
39155 | key: 'getCommonAncestor',
|
39156 | value: function getCommonAncestor(one, two) {
|
39157 | one = normalizeKey(one);
|
39158 | two = normalizeKey(two);
|
39159 |
|
39160 | if (one == this.key) return this;
|
39161 | if (two == this.key) return this;
|
39162 |
|
39163 | this.assertDescendant(one);
|
39164 | this.assertDescendant(two);
|
39165 | var ancestors = new _immutable.List();
|
39166 | var oneParent = this.getParent(one);
|
39167 | var twoParent = this.getParent(two);
|
39168 |
|
39169 | while (oneParent) {
|
39170 | ancestors = ancestors.push(oneParent);
|
39171 | oneParent = this.getParent(oneParent.key);
|
39172 | }
|
39173 |
|
39174 | while (twoParent) {
|
39175 | if (ancestors.includes(twoParent)) return twoParent;
|
39176 | twoParent = this.getParent(twoParent.key);
|
39177 | }
|
39178 | }
|
39179 |
|
39180 | /**
|
39181 | * Get the component for the node from a `schema`.
|
39182 | *
|
39183 | * @param {Schema} schema
|
39184 | * @return {Component|Void}
|
39185 | */
|
39186 |
|
39187 | }, {
|
39188 | key: 'getComponent',
|
39189 | value: function getComponent(schema) {
|
39190 | return schema.__getComponent(this);
|
39191 | }
|
39192 |
|
39193 | /**
|
39194 | * Get the decorations for the node from a `schema`.
|
39195 | *
|
39196 | * @param {Schema} schema
|
39197 | * @return {Array}
|
39198 | */
|
39199 |
|
39200 | }, {
|
39201 | key: 'getDecorators',
|
39202 | value: function getDecorators(schema) {
|
39203 | return schema.__getDecorators(this);
|
39204 | }
|
39205 |
|
39206 | /**
|
39207 | * Get the depth of a child node by `key`, with optional `startAt`.
|
39208 | *
|
39209 | * @param {String} key
|
39210 | * @param {Number} startAt (optional)
|
39211 | * @return {Number} depth
|
39212 | */
|
39213 |
|
39214 | }, {
|
39215 | key: 'getDepth',
|
39216 | value: function getDepth(key) {
|
39217 | var startAt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
39218 |
|
39219 | this.assertDescendant(key);
|
39220 | if (this.hasChild(key)) return startAt;
|
39221 | return this.getFurthestAncestor(key).getDepth(key, startAt + 1);
|
39222 | }
|
39223 |
|
39224 | /**
|
39225 | * Get a descendant node by `key`.
|
39226 | *
|
39227 | * @param {String} key
|
39228 | * @return {Node|Null}
|
39229 | */
|
39230 |
|
39231 | }, {
|
39232 | key: 'getDescendant',
|
39233 | value: function getDescendant(key) {
|
39234 | key = normalizeKey(key);
|
39235 | var descendantFound = null;
|
39236 |
|
39237 | var found = this.nodes.find(function (node) {
|
39238 | if (node.key === key) {
|
39239 | return node;
|
39240 | } else if (node.kind !== 'text') {
|
39241 | descendantFound = node.getDescendant(key);
|
39242 | return descendantFound;
|
39243 | } else {
|
39244 | return false;
|
39245 | }
|
39246 | });
|
39247 |
|
39248 | return descendantFound || found;
|
39249 | }
|
39250 |
|
39251 | /**
|
39252 | * Get a descendant by `path`.
|
39253 | *
|
39254 | * @param {Array} path
|
39255 | * @return {Node|Null}
|
39256 | */
|
39257 |
|
39258 | }, {
|
39259 | key: 'getDescendantAtPath',
|
39260 | value: function getDescendantAtPath(path) {
|
39261 | var descendant = this;
|
39262 |
|
39263 | for (var i = 0; i < path.length; i++) {
|
39264 | var index = path[i];
|
39265 | if (!descendant) return;
|
39266 | if (!descendant.nodes) return;
|
39267 | descendant = descendant.nodes.get(index);
|
39268 | }
|
39269 |
|
39270 | return descendant;
|
39271 | }
|
39272 |
|
39273 | /**
|
39274 | * Get the decorators for a descendant by `key` given a `schema`.
|
39275 | *
|
39276 | * @param {String} key
|
39277 | * @param {Schema} schema
|
39278 | * @return {Array}
|
39279 | */
|
39280 |
|
39281 | }, {
|
39282 | key: 'getDescendantDecorators',
|
39283 | value: function getDescendantDecorators(key, schema) {
|
39284 | if (!schema.hasDecorators) {
|
39285 | return [];
|
39286 | }
|
39287 |
|
39288 | var descendant = this.assertDescendant(key);
|
39289 | var child = this.getFurthestAncestor(key);
|
39290 | var decorators = [];
|
39291 |
|
39292 | while (child != descendant) {
|
39293 | decorators = decorators.concat(child.getDecorators(schema));
|
39294 | child = child.getFurthestAncestor(key);
|
39295 | }
|
39296 |
|
39297 | decorators = decorators.concat(descendant.getDecorators(schema));
|
39298 | return decorators;
|
39299 | }
|
39300 |
|
39301 | /**
|
39302 | * Get the first child text node.
|
39303 | *
|
39304 | * @return {Node|Null}
|
39305 | */
|
39306 |
|
39307 | }, {
|
39308 | key: 'getFirstText',
|
39309 | value: function getFirstText() {
|
39310 | var descendantFound = null;
|
39311 |
|
39312 | var found = this.nodes.find(function (node) {
|
39313 | if (node.kind == 'text') return true;
|
39314 | descendantFound = node.getFirstText();
|
39315 | return descendantFound;
|
39316 | });
|
39317 |
|
39318 | return descendantFound || found;
|
39319 | }
|
39320 |
|
39321 | /**
|
39322 | * Get a fragment of the node at a `range`.
|
39323 | *
|
39324 | * @param {Selection} range
|
39325 | * @return {Document}
|
39326 | */
|
39327 |
|
39328 | }, {
|
39329 | key: 'getFragmentAtRange',
|
39330 | value: function getFragmentAtRange(range) {
|
39331 | range = range.normalize(this);
|
39332 | if (range.isUnset) return _document2.default.create();
|
39333 |
|
39334 | var node = this;
|
39335 |
|
39336 | // Make sure the children exist.
|
39337 | var _range2 = range,
|
39338 | startKey = _range2.startKey,
|
39339 | startOffset = _range2.startOffset,
|
39340 | endKey = _range2.endKey,
|
39341 | endOffset = _range2.endOffset;
|
39342 |
|
39343 | var startText = node.assertDescendant(startKey);
|
39344 | var endText = node.assertDescendant(endKey);
|
39345 |
|
39346 | // Split at the start and end.
|
39347 | var child = startText;
|
39348 | var previous = void 0;
|
39349 | var parent = void 0;
|
39350 |
|
39351 | while (parent = node.getParent(child.key)) {
|
39352 | var index = parent.nodes.indexOf(child);
|
39353 | var position = child.kind == 'text' ? startOffset : child.nodes.indexOf(previous);
|
39354 | parent = parent.splitNode(index, position);
|
39355 | node = node.updateNode(parent);
|
39356 | previous = parent.nodes.get(index + 1);
|
39357 | child = parent;
|
39358 | }
|
39359 |
|
39360 | child = endText;
|
39361 |
|
39362 | while (parent = node.getParent(child.key)) {
|
39363 | var _index = parent.nodes.indexOf(child);
|
39364 | var _position = child.kind == 'text' ? endOffset : child.nodes.indexOf(previous);
|
39365 | parent = parent.splitNode(_index, _position);
|
39366 | node = node.updateNode(parent);
|
39367 | previous = parent.nodes.get(_index + 1);
|
39368 | child = parent;
|
39369 | }
|
39370 |
|
39371 | // Get the start and end nodes.
|
39372 | var next = node.getNextText(startKey);
|
39373 | var startNode = node.getNextSibling(node.getFurthestAncestor(startKey).key);
|
39374 | var endNode = startKey == endKey ? node.getFurthestAncestor(next.key) : node.getFurthestAncestor(endKey);
|
39375 |
|
39376 | // Get children range of nodes from start to end nodes
|
39377 | var startIndex = node.nodes.indexOf(startNode);
|
39378 | var endIndex = node.nodes.indexOf(endNode);
|
39379 | var nodes = node.nodes.slice(startIndex, endIndex + 1);
|
39380 |
|
39381 | // Return a new document fragment.
|
39382 | return _document2.default.create({ nodes: nodes });
|
39383 | }
|
39384 |
|
39385 | /**
|
39386 | * Get the furthest parent of a node by `key` that matches an `iterator`.
|
39387 | *
|
39388 | * @param {String} key
|
39389 | * @param {Function} iterator
|
39390 | * @return {Node|Null}
|
39391 | */
|
39392 |
|
39393 | }, {
|
39394 | key: 'getFurthest',
|
39395 | value: function getFurthest(key, iterator) {
|
39396 | var ancestors = this.getAncestors(key);
|
39397 | if (!ancestors) {
|
39398 | key = normalizeKey(key);
|
39399 | throw new Error('Could not find a descendant node with key "' + key + '".');
|
39400 | }
|
39401 |
|
39402 | // Exclude this node itself
|
39403 | return ancestors.rest().find(iterator);
|
39404 | }
|
39405 |
|
39406 | /**
|
39407 | * Get the furthest block parent of a node by `key`.
|
39408 | *
|
39409 | * @param {String} key
|
39410 | * @return {Node|Null}
|
39411 | */
|
39412 |
|
39413 | }, {
|
39414 | key: 'getFurthestBlock',
|
39415 | value: function getFurthestBlock(key) {
|
39416 | return this.getFurthest(key, function (node) {
|
39417 | return node.kind == 'block';
|
39418 | });
|
39419 | }
|
39420 |
|
39421 | /**
|
39422 | * Get the furthest inline parent of a node by `key`.
|
39423 | *
|
39424 | * @param {String} key
|
39425 | * @return {Node|Null}
|
39426 | */
|
39427 |
|
39428 | }, {
|
39429 | key: 'getFurthestInline',
|
39430 | value: function getFurthestInline(key) {
|
39431 | return this.getFurthest(key, function (node) {
|
39432 | return node.kind == 'inline';
|
39433 | });
|
39434 | }
|
39435 |
|
39436 | /**
|
39437 | * Get the furthest ancestor of a node by `key`.
|
39438 | *
|
39439 | * @param {String} key
|
39440 | * @return {Node|Null}
|
39441 | */
|
39442 |
|
39443 | }, {
|
39444 | key: 'getFurthestAncestor',
|
39445 | value: function getFurthestAncestor(key) {
|
39446 | key = normalizeKey(key);
|
39447 | return this.nodes.find(function (node) {
|
39448 | if (node.key == key) return true;
|
39449 | if (node.kind == 'text') return false;
|
39450 | return node.hasDescendant(key);
|
39451 | });
|
39452 | }
|
39453 |
|
39454 | /**
|
39455 | * Get the furthest ancestor of a node by `key` that has only one child.
|
39456 | *
|
39457 | * @param {String} key
|
39458 | * @return {Node|Null}
|
39459 | */
|
39460 |
|
39461 | }, {
|
39462 | key: 'getFurthestOnlyChildAncestor',
|
39463 | value: function getFurthestOnlyChildAncestor(key) {
|
39464 | var ancestors = this.getAncestors(key);
|
39465 |
|
39466 | if (!ancestors) {
|
39467 | key = normalizeKey(key);
|
39468 | throw new Error('Could not find a descendant node with key "' + key + '".');
|
39469 | }
|
39470 |
|
39471 | return ancestors
|
39472 | // Skip this node...
|
39473 | .skipLast()
|
39474 | // Take parents until there are more than one child...
|
39475 | .reverse().takeUntil(function (p) {
|
39476 | return p.nodes.size > 1;
|
39477 | })
|
39478 | // And pick the highest.
|
39479 | .last();
|
39480 | }
|
39481 |
|
39482 | /**
|
39483 | * Get the closest inline nodes for each text node in the node.
|
39484 | *
|
39485 | * @return {List<Node>}
|
39486 | */
|
39487 |
|
39488 | }, {
|
39489 | key: 'getInlines',
|
39490 | value: function getInlines() {
|
39491 | var array = this.getInlinesAsArray();
|
39492 | return new _immutable.List(array);
|
39493 | }
|
39494 |
|
39495 | /**
|
39496 | * Get the closest inline nodes for each text node in the node, as an array.
|
39497 | *
|
39498 | * @return {List<Node>}
|
39499 | */
|
39500 |
|
39501 | }, {
|
39502 | key: 'getInlinesAsArray',
|
39503 | value: function getInlinesAsArray() {
|
39504 | var array = [];
|
39505 |
|
39506 | this.nodes.forEach(function (child) {
|
39507 | if (child.kind == 'text') return;
|
39508 | if (child.isLeafInline()) {
|
39509 | array.push(child);
|
39510 | } else {
|
39511 | array = array.concat(child.getInlinesAsArray());
|
39512 | }
|
39513 | });
|
39514 |
|
39515 | return array;
|
39516 | }
|
39517 |
|
39518 | /**
|
39519 | * Get the closest inline nodes for each text node in a `range`.
|
39520 | *
|
39521 | * @param {Selection} range
|
39522 | * @return {List<Node>}
|
39523 | */
|
39524 |
|
39525 | }, {
|
39526 | key: 'getInlinesAtRange',
|
39527 | value: function getInlinesAtRange(range) {
|
39528 | var array = this.getInlinesAtRangeAsArray(range);
|
39529 | // Remove duplicates by converting it to an `OrderedSet` first.
|
39530 | return new _immutable.List(new _immutable.OrderedSet(array));
|
39531 | }
|
39532 |
|
39533 | /**
|
39534 | * Get the closest inline nodes for each text node in a `range` as an array.
|
39535 | *
|
39536 | * @param {Selection} range
|
39537 | * @return {Array}
|
39538 | */
|
39539 |
|
39540 | }, {
|
39541 | key: 'getInlinesAtRangeAsArray',
|
39542 | value: function getInlinesAtRangeAsArray(range) {
|
39543 | var _this = this;
|
39544 |
|
39545 | range = range.normalize(this);
|
39546 | if (range.isUnset) return [];
|
39547 |
|
39548 | return this.getTextsAtRangeAsArray(range).map(function (text) {
|
39549 | return _this.getClosestInline(text.key);
|
39550 | }).filter(function (exists) {
|
39551 | return exists;
|
39552 | });
|
39553 | }
|
39554 |
|
39555 | /**
|
39556 | * Get all of the leaf inline nodes that match a `type`.
|
39557 | *
|
39558 | * @param {String} type
|
39559 | * @return {List<Node>}
|
39560 | */
|
39561 |
|
39562 | }, {
|
39563 | key: 'getInlinesByType',
|
39564 | value: function getInlinesByType(type) {
|
39565 | var array = this.getInlinesByTypeAsArray(type);
|
39566 | return new _immutable.List(array);
|
39567 | }
|
39568 |
|
39569 | /**
|
39570 | * Get all of the leaf inline nodes that match a `type` as an array.
|
39571 | *
|
39572 | * @param {String} type
|
39573 | * @return {Array}
|
39574 | */
|
39575 |
|
39576 | }, {
|
39577 | key: 'getInlinesByTypeAsArray',
|
39578 | value: function getInlinesByTypeAsArray(type) {
|
39579 | return this.nodes.reduce(function (inlines, node) {
|
39580 | if (node.kind == 'text') {
|
39581 | return inlines;
|
39582 | } else if (node.isLeafInline() && node.type == type) {
|
39583 | inlines.push(node);
|
39584 | return inlines;
|
39585 | } else {
|
39586 | return inlines.concat(node.getInlinesByTypeAsArray(type));
|
39587 | }
|
39588 | }, []);
|
39589 | }
|
39590 |
|
39591 | /**
|
39592 | * Return a set of all keys in the node.
|
39593 | *
|
39594 | * @return {Set<String>}
|
39595 | */
|
39596 |
|
39597 | }, {
|
39598 | key: 'getKeys',
|
39599 | value: function getKeys() {
|
39600 | var keys = [];
|
39601 |
|
39602 | this.forEachDescendant(function (desc) {
|
39603 | keys.push(desc.key);
|
39604 | });
|
39605 |
|
39606 | return new _immutable.Set(keys);
|
39607 | }
|
39608 |
|
39609 | /**
|
39610 | * Get the last child text node.
|
39611 | *
|
39612 | * @return {Node|Null}
|
39613 | */
|
39614 |
|
39615 | }, {
|
39616 | key: 'getLastText',
|
39617 | value: function getLastText() {
|
39618 | var descendantFound = null;
|
39619 |
|
39620 | var found = this.nodes.findLast(function (node) {
|
39621 | if (node.kind == 'text') return true;
|
39622 | descendantFound = node.getLastText();
|
39623 | return descendantFound;
|
39624 | });
|
39625 |
|
39626 | return descendantFound || found;
|
39627 | }
|
39628 |
|
39629 | /**
|
39630 | * Get all of the marks for all of the characters of every text node.
|
39631 | *
|
39632 | * @return {Set<Mark>}
|
39633 | */
|
39634 |
|
39635 | }, {
|
39636 | key: 'getMarks',
|
39637 | value: function getMarks() {
|
39638 | var array = this.getMarksAsArray();
|
39639 | return new _immutable.Set(array);
|
39640 | }
|
39641 |
|
39642 | /**
|
39643 | * Get all of the marks for all of the characters of every text node.
|
39644 | *
|
39645 | * @return {OrderedSet<Mark>}
|
39646 | */
|
39647 |
|
39648 | }, {
|
39649 | key: 'getOrderedMarks',
|
39650 | value: function getOrderedMarks() {
|
39651 | var array = this.getMarksAsArray();
|
39652 | return new _immutable.OrderedSet(array);
|
39653 | }
|
39654 |
|
39655 | /**
|
39656 | * Get all of the marks as an array.
|
39657 | *
|
39658 | * @return {Array}
|
39659 | */
|
39660 |
|
39661 | }, {
|
39662 | key: 'getMarksAsArray',
|
39663 | value: function getMarksAsArray() {
|
39664 | return this.nodes.reduce(function (marks, node) {
|
39665 | return marks.concat(node.getMarksAsArray());
|
39666 | }, []);
|
39667 | }
|
39668 |
|
39669 | /**
|
39670 | * Get a set of the marks in a `range`.
|
39671 | *
|
39672 | * @param {Selection} range
|
39673 | * @return {Set<Mark>}
|
39674 | */
|
39675 |
|
39676 | }, {
|
39677 | key: 'getMarksAtRange',
|
39678 | value: function getMarksAtRange(range) {
|
39679 | var array = this.getMarksAtRangeAsArray(range);
|
39680 | return new _immutable.Set(array);
|
39681 | }
|
39682 |
|
39683 | /**
|
39684 | * Get a set of the marks in a `range`.
|
39685 | *
|
39686 | * @param {Selection} range
|
39687 | * @return {OrderedSet<Mark>}
|
39688 | */
|
39689 |
|
39690 | }, {
|
39691 | key: 'getOrderedMarksAtRange',
|
39692 | value: function getOrderedMarksAtRange(range) {
|
39693 | var array = this.getMarksAtRangeAsArray(range);
|
39694 | return new _immutable.OrderedSet(array);
|
39695 | }
|
39696 |
|
39697 | /**
|
39698 | * Get a set of the active marks in a `range`.
|
39699 | *
|
39700 | * @param {Selection} range
|
39701 | * @return {Set<Mark>}
|
39702 | */
|
39703 |
|
39704 | }, {
|
39705 | key: 'getActiveMarksAtRange',
|
39706 | value: function getActiveMarksAtRange(range) {
|
39707 | var array = this.getActiveMarksAtRangeAsArray(range);
|
39708 | return new _immutable.Set(array);
|
39709 | }
|
39710 |
|
39711 | /**
|
39712 | * Get a set of the marks in a `range`, by unioning.
|
39713 | *
|
39714 | * @param {Selection} range
|
39715 | * @return {Array}
|
39716 | */
|
39717 |
|
39718 | }, {
|
39719 | key: 'getMarksAtRangeAsArray',
|
39720 | value: function getMarksAtRangeAsArray(range) {
|
39721 | range = range.normalize(this);
|
39722 | if (range.isUnset) return [];
|
39723 |
|
39724 | var _range3 = range,
|
39725 | startKey = _range3.startKey,
|
39726 | startOffset = _range3.startOffset;
|
39727 |
|
39728 | // If the range is collapsed at the start of the node, check the previous.
|
39729 |
|
39730 | if (range.isCollapsed && startOffset == 0) {
|
39731 | var previous = this.getPreviousText(startKey);
|
39732 | if (!previous || previous.text.length == 0) return [];
|
39733 | var char = previous.characters.get(previous.text.length - 1);
|
39734 | return char.marks.toArray();
|
39735 | }
|
39736 |
|
39737 | // If the range is collapsed, check the character before the start.
|
39738 | if (range.isCollapsed) {
|
39739 | var text = this.getDescendant(startKey);
|
39740 | var _char = text.characters.get(range.startOffset - 1);
|
39741 | return _char.marks.toArray();
|
39742 | }
|
39743 |
|
39744 | // Otherwise, get a set of the marks for each character in the range.
|
39745 | return this.getCharactersAtRange(range).reduce(function (memo, char) {
|
39746 | char.marks.toArray().forEach(function (c) {
|
39747 | return memo.push(c);
|
39748 | });
|
39749 | return memo;
|
39750 | }, []);
|
39751 | }
|
39752 |
|
39753 | /**
|
39754 | * Get a set of marks in a `range`, by intersecting.
|
39755 | *
|
39756 | * @param {Selection} range
|
39757 | * @return {Array}
|
39758 | */
|
39759 |
|
39760 | }, {
|
39761 | key: 'getActiveMarksAtRangeAsArray',
|
39762 | value: function getActiveMarksAtRangeAsArray(range) {
|
39763 | range = range.normalize(this);
|
39764 | if (range.isUnset) return [];
|
39765 |
|
39766 | var _range4 = range,
|
39767 | startKey = _range4.startKey,
|
39768 | startOffset = _range4.startOffset;
|
39769 |
|
39770 | // If the range is collapsed at the start of the node, check the previous.
|
39771 |
|
39772 | if (range.isCollapsed && startOffset == 0) {
|
39773 | var previous = this.getPreviousText(startKey);
|
39774 | if (!previous || !previous.length) return [];
|
39775 | var char = previous.characters.get(previous.length - 1);
|
39776 | return char.marks.toArray();
|
39777 | }
|
39778 |
|
39779 | // If the range is collapsed, check the character before the start.
|
39780 | if (range.isCollapsed) {
|
39781 | var text = this.getDescendant(startKey);
|
39782 | var _char2 = text.characters.get(range.startOffset - 1);
|
39783 | return _char2.marks.toArray();
|
39784 | }
|
39785 |
|
39786 | // Otherwise, get a set of the marks for each character in the range.
|
39787 | var chars = this.getCharactersAtRange(range);
|
39788 | var first = chars.first();
|
39789 | if (!first) return [];
|
39790 |
|
39791 | var memo = first.marks;
|
39792 |
|
39793 | chars.slice(1).forEach(function (char) {
|
39794 | memo = memo.intersect(char.marks);
|
39795 | return memo.size != 0;
|
39796 | });
|
39797 |
|
39798 | return memo.toArray();
|
39799 | }
|
39800 |
|
39801 | /**
|
39802 | * Get all of the marks that match a `type`.
|
39803 | *
|
39804 | * @param {String} type
|
39805 | * @return {Set<Mark>}
|
39806 | */
|
39807 |
|
39808 | }, {
|
39809 | key: 'getMarksByType',
|
39810 | value: function getMarksByType(type) {
|
39811 | var array = this.getMarksByTypeAsArray(type);
|
39812 | return new _immutable.Set(array);
|
39813 | }
|
39814 |
|
39815 | /**
|
39816 | * Get all of the marks that match a `type`.
|
39817 | *
|
39818 | * @param {String} type
|
39819 | * @return {OrderedSet<Mark>}
|
39820 | */
|
39821 |
|
39822 | }, {
|
39823 | key: 'getOrderedMarksByType',
|
39824 | value: function getOrderedMarksByType(type) {
|
39825 | var array = this.getMarksByTypeAsArray(type);
|
39826 | return new _immutable.OrderedSet(array);
|
39827 | }
|
39828 |
|
39829 | /**
|
39830 | * Get all of the marks that match a `type` as an array.
|
39831 | *
|
39832 | * @param {String} type
|
39833 | * @return {Array}
|
39834 | */
|
39835 |
|
39836 | }, {
|
39837 | key: 'getMarksByTypeAsArray',
|
39838 | value: function getMarksByTypeAsArray(type) {
|
39839 | return this.nodes.reduce(function (array, node) {
|
39840 | return node.kind == 'text' ? array.concat(node.getMarksAsArray().filter(function (m) {
|
39841 | return m.type == type;
|
39842 | })) : array.concat(node.getMarksByTypeAsArray(type));
|
39843 | }, []);
|
39844 | }
|
39845 |
|
39846 | /**
|
39847 | * Get the block node before a descendant text node by `key`.
|
39848 | *
|
39849 | * @param {String} key
|
39850 | * @return {Node|Null}
|
39851 | */
|
39852 |
|
39853 | }, {
|
39854 | key: 'getNextBlock',
|
39855 | value: function getNextBlock(key) {
|
39856 | var child = this.assertDescendant(key);
|
39857 | var last = void 0;
|
39858 |
|
39859 | if (child.kind == 'block') {
|
39860 | last = child.getLastText();
|
39861 | } else {
|
39862 | var block = this.getClosestBlock(key);
|
39863 | last = block.getLastText();
|
39864 | }
|
39865 |
|
39866 | var next = this.getNextText(last.key);
|
39867 | if (!next) return null;
|
39868 |
|
39869 | return this.getClosestBlock(next.key);
|
39870 | }
|
39871 |
|
39872 | /**
|
39873 | * Get the node after a descendant by `key`.
|
39874 | *
|
39875 | * @param {String} key
|
39876 | * @return {Node|Null}
|
39877 | */
|
39878 |
|
39879 | }, {
|
39880 | key: 'getNextSibling',
|
39881 | value: function getNextSibling(key) {
|
39882 | key = normalizeKey(key);
|
39883 |
|
39884 | var parent = this.getParent(key);
|
39885 | var after = parent.nodes.skipUntil(function (child) {
|
39886 | return child.key == key;
|
39887 | });
|
39888 |
|
39889 | if (after.size == 0) {
|
39890 | throw new Error('Could not find a child node with key "' + key + '".');
|
39891 | }
|
39892 | return after.get(1);
|
39893 | }
|
39894 |
|
39895 | /**
|
39896 | * Get the text node after a descendant text node by `key`.
|
39897 | *
|
39898 | * @param {String} key
|
39899 | * @return {Node|Null}
|
39900 | */
|
39901 |
|
39902 | }, {
|
39903 | key: 'getNextText',
|
39904 | value: function getNextText(key) {
|
39905 | key = normalizeKey(key);
|
39906 | return this.getTexts().skipUntil(function (text) {
|
39907 | return text.key == key;
|
39908 | }).get(1);
|
39909 | }
|
39910 |
|
39911 | /**
|
39912 | * Get a node in the tree by `key`.
|
39913 | *
|
39914 | * @param {String} key
|
39915 | * @return {Node|Null}
|
39916 | */
|
39917 |
|
39918 | }, {
|
39919 | key: 'getNode',
|
39920 | value: function getNode(key) {
|
39921 | key = normalizeKey(key);
|
39922 | return this.key == key ? this : this.getDescendant(key);
|
39923 | }
|
39924 |
|
39925 | /**
|
39926 | * Get a node in the tree by `path`.
|
39927 | *
|
39928 | * @param {Array} path
|
39929 | * @return {Node|Null}
|
39930 | */
|
39931 |
|
39932 | }, {
|
39933 | key: 'getNodeAtPath',
|
39934 | value: function getNodeAtPath(path) {
|
39935 | return path.length ? this.getDescendantAtPath(path) : this;
|
39936 | }
|
39937 |
|
39938 | /**
|
39939 | * Get the offset for a descendant text node by `key`.
|
39940 | *
|
39941 | * @param {String} key
|
39942 | * @return {Number}
|
39943 | */
|
39944 |
|
39945 | }, {
|
39946 | key: 'getOffset',
|
39947 | value: function getOffset(key) {
|
39948 | this.assertDescendant(key);
|
39949 |
|
39950 | // Calculate the offset of the nodes before the highest child.
|
39951 | var child = this.getFurthestAncestor(key);
|
39952 | var offset = this.nodes.takeUntil(function (n) {
|
39953 | return n == child;
|
39954 | }).reduce(function (memo, n) {
|
39955 | return memo + n.text.length;
|
39956 | }, 0);
|
39957 |
|
39958 | // Recurse if need be.
|
39959 | return this.hasChild(key) ? offset : offset + child.getOffset(key);
|
39960 | }
|
39961 |
|
39962 | /**
|
39963 | * Get the offset from a `range`.
|
39964 | *
|
39965 | * @param {Selection} range
|
39966 | * @return {Number}
|
39967 | */
|
39968 |
|
39969 | }, {
|
39970 | key: 'getOffsetAtRange',
|
39971 | value: function getOffsetAtRange(range) {
|
39972 | range = range.normalize(this);
|
39973 |
|
39974 | if (range.isUnset) {
|
39975 | throw new Error('The range cannot be unset to calculcate its offset.');
|
39976 | }
|
39977 |
|
39978 | if (range.isExpanded) {
|
39979 | throw new Error('The range must be collapsed to calculcate its offset.');
|
39980 | }
|
39981 |
|
39982 | var _range5 = range,
|
39983 | startKey = _range5.startKey,
|
39984 | startOffset = _range5.startOffset;
|
39985 |
|
39986 | return this.getOffset(startKey) + startOffset;
|
39987 | }
|
39988 |
|
39989 | /**
|
39990 | * Get the parent of a child node by `key`.
|
39991 | *
|
39992 | * @param {String} key
|
39993 | * @return {Node|Null}
|
39994 | */
|
39995 |
|
39996 | }, {
|
39997 | key: 'getParent',
|
39998 | value: function getParent(key) {
|
39999 | if (this.hasChild(key)) return this;
|
40000 |
|
40001 | var node = null;
|
40002 |
|
40003 | this.nodes.find(function (child) {
|
40004 | if (child.kind == 'text') {
|
40005 | return false;
|
40006 | } else {
|
40007 | node = child.getParent(key);
|
40008 | return node;
|
40009 | }
|
40010 | });
|
40011 |
|
40012 | return node;
|
40013 | }
|
40014 |
|
40015 | /**
|
40016 | * Get the path of a descendant node by `key`.
|
40017 | *
|
40018 | * @param {String|Node} key
|
40019 | * @return {Array}
|
40020 | */
|
40021 |
|
40022 | }, {
|
40023 | key: 'getPath',
|
40024 | value: function getPath(key) {
|
40025 | var child = this.assertNode(key);
|
40026 | var ancestors = this.getAncestors(key);
|
40027 | var path = [];
|
40028 |
|
40029 | ancestors.reverse().forEach(function (ancestor) {
|
40030 | var index = ancestor.nodes.indexOf(child);
|
40031 | path.unshift(index);
|
40032 | child = ancestor;
|
40033 | });
|
40034 |
|
40035 | return path;
|
40036 | }
|
40037 |
|
40038 | /**
|
40039 | * Get the block node before a descendant text node by `key`.
|
40040 | *
|
40041 | * @param {String} key
|
40042 | * @return {Node|Null}
|
40043 | */
|
40044 |
|
40045 | }, {
|
40046 | key: 'getPreviousBlock',
|
40047 | value: function getPreviousBlock(key) {
|
40048 | var child = this.assertDescendant(key);
|
40049 | var first = void 0;
|
40050 |
|
40051 | if (child.kind == 'block') {
|
40052 | first = child.getFirstText();
|
40053 | } else {
|
40054 | var block = this.getClosestBlock(key);
|
40055 | first = block.getFirstText();
|
40056 | }
|
40057 |
|
40058 | var previous = this.getPreviousText(first.key);
|
40059 | if (!previous) return null;
|
40060 |
|
40061 | return this.getClosestBlock(previous.key);
|
40062 | }
|
40063 |
|
40064 | /**
|
40065 | * Get the node before a descendant node by `key`.
|
40066 | *
|
40067 | * @param {String} key
|
40068 | * @return {Node|Null}
|
40069 | */
|
40070 |
|
40071 | }, {
|
40072 | key: 'getPreviousSibling',
|
40073 | value: function getPreviousSibling(key) {
|
40074 | key = normalizeKey(key);
|
40075 | var parent = this.getParent(key);
|
40076 | var before = parent.nodes.takeUntil(function (child) {
|
40077 | return child.key == key;
|
40078 | });
|
40079 |
|
40080 | if (before.size == parent.nodes.size) {
|
40081 | throw new Error('Could not find a child node with key "' + key + '".');
|
40082 | }
|
40083 |
|
40084 | return before.last();
|
40085 | }
|
40086 |
|
40087 | /**
|
40088 | * Get the text node before a descendant text node by `key`.
|
40089 | *
|
40090 | * @param {String} key
|
40091 | * @return {Node|Null}
|
40092 | */
|
40093 |
|
40094 | }, {
|
40095 | key: 'getPreviousText',
|
40096 | value: function getPreviousText(key) {
|
40097 | key = normalizeKey(key);
|
40098 | return this.getTexts().takeUntil(function (text) {
|
40099 | return text.key == key;
|
40100 | }).last();
|
40101 | }
|
40102 |
|
40103 | /**
|
40104 | * Get the indexes of the selection for a `range`, given an extra flag for
|
40105 | * whether the node `isSelected`, to determine whether not finding matches
|
40106 | * means everything is selected or nothing is.
|
40107 | *
|
40108 | * @param {Selection} range
|
40109 | * @param {Boolean} isSelected
|
40110 | * @return {Object|Null}
|
40111 | */
|
40112 |
|
40113 | }, {
|
40114 | key: 'getSelectionIndexes',
|
40115 | value: function getSelectionIndexes(range) {
|
40116 | var isSelected = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
40117 | var startKey = range.startKey,
|
40118 | endKey = range.endKey;
|
40119 |
|
40120 | // PERF: if we're not selected, or the range is blurred, we can exit early.
|
40121 |
|
40122 | if (!isSelected || range.isBlurred) {
|
40123 | return null;
|
40124 | }
|
40125 |
|
40126 | // PERF: if the start and end keys are the same, just check for the child
|
40127 | // that contains that single key.
|
40128 | if (startKey == endKey) {
|
40129 | var child = this.getFurthestAncestor(startKey);
|
40130 | var index = child ? this.nodes.indexOf(child) : null;
|
40131 | return { start: index, end: index + 1 };
|
40132 | }
|
40133 |
|
40134 | // Otherwise, check all of the children...
|
40135 | var start = null;
|
40136 | var end = null;
|
40137 |
|
40138 | this.nodes.forEach(function (child, i) {
|
40139 | if (child.kind == 'text') {
|
40140 | if (start == null && child.key == startKey) start = i;
|
40141 | if (end == null && child.key == endKey) end = i + 1;
|
40142 | } else {
|
40143 | if (start == null && child.hasDescendant(startKey)) start = i;
|
40144 | if (end == null && child.hasDescendant(endKey)) end = i + 1;
|
40145 | }
|
40146 |
|
40147 | // PERF: exit early if both start and end have been found.
|
40148 | return start != null && end != null;
|
40149 | });
|
40150 |
|
40151 | if (isSelected && start == null) start = 0;
|
40152 | if (isSelected && end == null) end = this.nodes.size;
|
40153 | return start == null ? null : { start: start, end: end };
|
40154 | }
|
40155 |
|
40156 | /**
|
40157 | * Get the concatenated text string of all child nodes.
|
40158 | *
|
40159 | * @return {String}
|
40160 | */
|
40161 |
|
40162 | }, {
|
40163 | key: 'getText',
|
40164 | value: function getText() {
|
40165 | return this.nodes.reduce(function (string, node) {
|
40166 | return string + node.text;
|
40167 | }, '');
|
40168 | }
|
40169 |
|
40170 | /**
|
40171 | * Get the descendent text node at an `offset`.
|
40172 | *
|
40173 | * @param {String} offset
|
40174 | * @return {Node|Null}
|
40175 | */
|
40176 |
|
40177 | }, {
|
40178 | key: 'getTextAtOffset',
|
40179 | value: function getTextAtOffset(offset) {
|
40180 | // PERF: Add a few shortcuts for the obvious cases.
|
40181 | if (offset == 0) return this.getFirstText();
|
40182 | if (offset == this.text.length) return this.getLastText();
|
40183 | if (offset < 0 || offset > this.text.length) return null;
|
40184 |
|
40185 | var length = 0;
|
40186 |
|
40187 | return this.getTexts().find(function (node, i, nodes) {
|
40188 | length += node.text.length;
|
40189 | return length > offset;
|
40190 | });
|
40191 | }
|
40192 |
|
40193 | /**
|
40194 | * Get the direction of the node's text.
|
40195 | *
|
40196 | * @return {String}
|
40197 | */
|
40198 |
|
40199 | }, {
|
40200 | key: 'getTextDirection',
|
40201 | value: function getTextDirection() {
|
40202 | var dir = (0, _direction2.default)(this.text);
|
40203 | return dir == 'neutral' ? undefined : dir;
|
40204 | }
|
40205 |
|
40206 | /**
|
40207 | * Recursively get all of the child text nodes in order of appearance.
|
40208 | *
|
40209 | * @return {List<Node>}
|
40210 | */
|
40211 |
|
40212 | }, {
|
40213 | key: 'getTexts',
|
40214 | value: function getTexts() {
|
40215 | var array = this.getTextsAsArray();
|
40216 | return new _immutable.List(array);
|
40217 | }
|
40218 |
|
40219 | /**
|
40220 | * Recursively get all the leaf text nodes in order of appearance, as array.
|
40221 | *
|
40222 | * @return {List<Node>}
|
40223 | */
|
40224 |
|
40225 | }, {
|
40226 | key: 'getTextsAsArray',
|
40227 | value: function getTextsAsArray() {
|
40228 | var array = [];
|
40229 |
|
40230 | this.nodes.forEach(function (node) {
|
40231 | if (node.kind == 'text') {
|
40232 | array.push(node);
|
40233 | } else {
|
40234 | array = array.concat(node.getTextsAsArray());
|
40235 | }
|
40236 | });
|
40237 |
|
40238 | return array;
|
40239 | }
|
40240 |
|
40241 | /**
|
40242 | * Get all of the text nodes in a `range`.
|
40243 | *
|
40244 | * @param {Selection} range
|
40245 | * @return {List<Node>}
|
40246 | */
|
40247 |
|
40248 | }, {
|
40249 | key: 'getTextsAtRange',
|
40250 | value: function getTextsAtRange(range) {
|
40251 | var array = this.getTextsAtRangeAsArray(range);
|
40252 | return new _immutable.List(array);
|
40253 | }
|
40254 |
|
40255 | /**
|
40256 | * Get all of the text nodes in a `range` as an array.
|
40257 | *
|
40258 | * @param {Selection} range
|
40259 | * @return {Array}
|
40260 | */
|
40261 |
|
40262 | }, {
|
40263 | key: 'getTextsAtRangeAsArray',
|
40264 | value: function getTextsAtRangeAsArray(range) {
|
40265 | range = range.normalize(this);
|
40266 | if (range.isUnset) return [];
|
40267 |
|
40268 | var _range6 = range,
|
40269 | startKey = _range6.startKey,
|
40270 | endKey = _range6.endKey;
|
40271 |
|
40272 | var startText = this.getDescendant(startKey);
|
40273 |
|
40274 | // PERF: the most common case is when the range is in a single text node,
|
40275 | // where we can avoid a lot of iterating of the tree.
|
40276 | if (startKey == endKey) return [startText];
|
40277 |
|
40278 | var endText = this.getDescendant(endKey);
|
40279 | var texts = this.getTextsAsArray();
|
40280 | var start = texts.indexOf(startText);
|
40281 | var end = texts.indexOf(endText);
|
40282 | return texts.slice(start, end + 1);
|
40283 | }
|
40284 |
|
40285 | /**
|
40286 | * Check if a child node exists by `key`.
|
40287 | *
|
40288 | * @param {String} key
|
40289 | * @return {Boolean}
|
40290 | */
|
40291 |
|
40292 | }, {
|
40293 | key: 'hasChild',
|
40294 | value: function hasChild(key) {
|
40295 | return !!this.getChild(key);
|
40296 | }
|
40297 |
|
40298 | /**
|
40299 | * Recursively check if a child node exists by `key`.
|
40300 | *
|
40301 | * @param {String} key
|
40302 | * @return {Boolean}
|
40303 | */
|
40304 |
|
40305 | }, {
|
40306 | key: 'hasDescendant',
|
40307 | value: function hasDescendant(key) {
|
40308 | return !!this.getDescendant(key);
|
40309 | }
|
40310 |
|
40311 | /**
|
40312 | * Recursively check if a node exists by `key`.
|
40313 | *
|
40314 | * @param {String} key
|
40315 | * @return {Boolean}
|
40316 | */
|
40317 |
|
40318 | }, {
|
40319 | key: 'hasNode',
|
40320 | value: function hasNode(key) {
|
40321 | return !!this.getNode(key);
|
40322 | }
|
40323 |
|
40324 | /**
|
40325 | * Check if a node has a void parent by `key`.
|
40326 | *
|
40327 | * @param {String} key
|
40328 | * @return {Boolean}
|
40329 | */
|
40330 |
|
40331 | }, {
|
40332 | key: 'hasVoidParent',
|
40333 | value: function hasVoidParent(key) {
|
40334 | return !!this.getClosest(key, function (parent) {
|
40335 | return parent.isVoid;
|
40336 | });
|
40337 | }
|
40338 |
|
40339 | /**
|
40340 | * Insert a `node` at `index`.
|
40341 | *
|
40342 | * @param {Number} index
|
40343 | * @param {Node} node
|
40344 | * @return {Node}
|
40345 | */
|
40346 |
|
40347 | }, {
|
40348 | key: 'insertNode',
|
40349 | value: function insertNode(index, node) {
|
40350 | var keys = this.getKeys();
|
40351 |
|
40352 | if (keys.contains(node.key)) {
|
40353 | node = node.regenerateKey();
|
40354 | }
|
40355 |
|
40356 | if (node.kind != 'text') {
|
40357 | node = node.mapDescendants(function (desc) {
|
40358 | return keys.contains(desc.key) ? desc.regenerateKey() : desc;
|
40359 | });
|
40360 | }
|
40361 |
|
40362 | var nodes = this.nodes.insert(index, node);
|
40363 | return this.set('nodes', nodes);
|
40364 | }
|
40365 |
|
40366 | /**
|
40367 | * Check whether the node is in a `range`.
|
40368 | *
|
40369 | * @param {Selection} range
|
40370 | * @return {Boolean}
|
40371 | */
|
40372 |
|
40373 | }, {
|
40374 | key: 'isInRange',
|
40375 | value: function isInRange(range) {
|
40376 | range = range.normalize(this);
|
40377 |
|
40378 | var node = this;
|
40379 | var _range7 = range,
|
40380 | startKey = _range7.startKey,
|
40381 | endKey = _range7.endKey,
|
40382 | isCollapsed = _range7.isCollapsed;
|
40383 |
|
40384 | // PERF: solve the most common cast where the start or end key are inside
|
40385 | // the node, for collapsed selections.
|
40386 |
|
40387 | if (node.key == startKey || node.key == endKey || node.hasDescendant(startKey) || node.hasDescendant(endKey)) {
|
40388 | return true;
|
40389 | }
|
40390 |
|
40391 | // PERF: if the selection is collapsed and the previous check didn't return
|
40392 | // true, then it must be false.
|
40393 | if (isCollapsed) {
|
40394 | return false;
|
40395 | }
|
40396 |
|
40397 | // Otherwise, look through all of the leaf text nodes in the range, to see
|
40398 | // if any of them are inside the node.
|
40399 | var texts = node.getTextsAtRange(range);
|
40400 | var memo = false;
|
40401 |
|
40402 | texts.forEach(function (text) {
|
40403 | if (node.hasDescendant(text.key)) memo = true;
|
40404 | return memo;
|
40405 | });
|
40406 |
|
40407 | return memo;
|
40408 | }
|
40409 |
|
40410 | /**
|
40411 | * Check whether the node is a leaf block.
|
40412 | *
|
40413 | * @return {Boolean}
|
40414 | */
|
40415 |
|
40416 | }, {
|
40417 | key: 'isLeafBlock',
|
40418 | value: function isLeafBlock() {
|
40419 | return this.kind == 'block' && this.nodes.every(function (n) {
|
40420 | return n.kind != 'block';
|
40421 | });
|
40422 | }
|
40423 |
|
40424 | /**
|
40425 | * Check whether the node is a leaf inline.
|
40426 | *
|
40427 | * @return {Boolean}
|
40428 | */
|
40429 |
|
40430 | }, {
|
40431 | key: 'isLeafInline',
|
40432 | value: function isLeafInline() {
|
40433 | return this.kind == 'inline' && this.nodes.every(function (n) {
|
40434 | return n.kind != 'inline';
|
40435 | });
|
40436 | }
|
40437 |
|
40438 | /**
|
40439 | * Merge a children node `first` with another children node `second`.
|
40440 | * `first` and `second` will be concatenated in that order.
|
40441 | * `first` and `second` must be two Nodes or two Text.
|
40442 | *
|
40443 | * @param {Node} first
|
40444 | * @param {Node} second
|
40445 | * @return {Node}
|
40446 | */
|
40447 |
|
40448 | }, {
|
40449 | key: 'mergeNode',
|
40450 | value: function mergeNode(withIndex, index) {
|
40451 | var node = this;
|
40452 | var one = node.nodes.get(withIndex);
|
40453 | var two = node.nodes.get(index);
|
40454 |
|
40455 | if (one.kind != two.kind) {
|
40456 | throw new Error('Tried to merge two nodes of different kinds: "' + one.kind + '" and "' + two.kind + '".');
|
40457 | }
|
40458 |
|
40459 | // If the nodes are text nodes, concatenate their characters together.
|
40460 | if (one.kind == 'text') {
|
40461 | var characters = one.characters.concat(two.characters);
|
40462 | one = one.set('characters', characters);
|
40463 | }
|
40464 |
|
40465 | // Otherwise, concatenate their child nodes together.
|
40466 | else {
|
40467 | var nodes = one.nodes.concat(two.nodes);
|
40468 | one = one.set('nodes', nodes);
|
40469 | }
|
40470 |
|
40471 | node = node.removeNode(index);
|
40472 | node = node.removeNode(withIndex);
|
40473 | node = node.insertNode(withIndex, one);
|
40474 | return node;
|
40475 | }
|
40476 |
|
40477 | /**
|
40478 | * Map all child nodes, updating them in their parents. This method is
|
40479 | * optimized to not return a new node if no changes are made.
|
40480 | *
|
40481 | * @param {Function} iterator
|
40482 | * @return {Node}
|
40483 | */
|
40484 |
|
40485 | }, {
|
40486 | key: 'mapChildren',
|
40487 | value: function mapChildren(iterator) {
|
40488 | var _this2 = this;
|
40489 |
|
40490 | var nodes = this.nodes;
|
40491 |
|
40492 |
|
40493 | nodes.forEach(function (node, i) {
|
40494 | var ret = iterator(node, i, _this2.nodes);
|
40495 | if (ret != node) nodes = nodes.set(ret.key, ret);
|
40496 | });
|
40497 |
|
40498 | return this.set('nodes', nodes);
|
40499 | }
|
40500 |
|
40501 | /**
|
40502 | * Map all descendant nodes, updating them in their parents. This method is
|
40503 | * optimized to not return a new node if no changes are made.
|
40504 | *
|
40505 | * @param {Function} iterator
|
40506 | * @return {Node}
|
40507 | */
|
40508 |
|
40509 | }, {
|
40510 | key: 'mapDescendants',
|
40511 | value: function mapDescendants(iterator) {
|
40512 | var _this3 = this;
|
40513 |
|
40514 | var nodes = this.nodes;
|
40515 |
|
40516 |
|
40517 | nodes.forEach(function (node, i) {
|
40518 | var ret = node;
|
40519 | if (ret.kind != 'text') ret = ret.mapDescendants(iterator);
|
40520 | ret = iterator(ret, i, _this3.nodes);
|
40521 | if (ret == node) return;
|
40522 |
|
40523 | var index = nodes.indexOf(node);
|
40524 | nodes = nodes.set(index, ret);
|
40525 | });
|
40526 |
|
40527 | return this.set('nodes', nodes);
|
40528 | }
|
40529 |
|
40530 | /**
|
40531 | * Regenerate the node's key.
|
40532 | *
|
40533 | * @return {Node}
|
40534 | */
|
40535 |
|
40536 | }, {
|
40537 | key: 'regenerateKey',
|
40538 | value: function regenerateKey() {
|
40539 | var key = (0, _generateKey2.default)();
|
40540 | return this.set('key', key);
|
40541 | }
|
40542 |
|
40543 | /**
|
40544 | * Remove a `node` from the children node map.
|
40545 | *
|
40546 | * @param {String} key
|
40547 | * @return {Node}
|
40548 | */
|
40549 |
|
40550 | }, {
|
40551 | key: 'removeDescendant',
|
40552 | value: function removeDescendant(key) {
|
40553 | key = normalizeKey(key);
|
40554 |
|
40555 | var node = this;
|
40556 | var parent = node.getParent(key);
|
40557 | if (!parent) throw new Error('Could not find a descendant node with key "' + key + '".');
|
40558 |
|
40559 | var index = parent.nodes.findIndex(function (n) {
|
40560 | return n.key === key;
|
40561 | });
|
40562 | var nodes = parent.nodes.splice(index, 1);
|
40563 |
|
40564 | parent = parent.set('nodes', nodes);
|
40565 | node = node.updateNode(parent);
|
40566 | return node;
|
40567 | }
|
40568 |
|
40569 | /**
|
40570 | * Remove a node at `index`.
|
40571 | *
|
40572 | * @param {Number} index
|
40573 | * @return {Node}
|
40574 | */
|
40575 |
|
40576 | }, {
|
40577 | key: 'removeNode',
|
40578 | value: function removeNode(index) {
|
40579 | var nodes = this.nodes.splice(index, 1);
|
40580 | return this.set('nodes', nodes);
|
40581 | }
|
40582 |
|
40583 | /**
|
40584 | * Split a child node by `index` at `position`.
|
40585 | *
|
40586 | * @param {Number} index
|
40587 | * @param {Number} position
|
40588 | * @return {Node}
|
40589 | */
|
40590 |
|
40591 | }, {
|
40592 | key: 'splitNode',
|
40593 | value: function splitNode(index, position) {
|
40594 | var node = this;
|
40595 | var child = node.nodes.get(index);
|
40596 | var one = void 0;
|
40597 | var two = void 0;
|
40598 |
|
40599 | // If the child is a text node, the `position` refers to the text offset at
|
40600 | // which to split it.
|
40601 | if (child.kind == 'text') {
|
40602 | var befores = child.characters.take(position);
|
40603 | var afters = child.characters.skip(position);
|
40604 | one = child.set('characters', befores);
|
40605 | two = child.set('characters', afters).regenerateKey();
|
40606 | }
|
40607 |
|
40608 | // Otherwise, if the child is not a text node, the `position` refers to the
|
40609 | // index at which to split its children.
|
40610 | else {
|
40611 | var _befores = child.nodes.take(position);
|
40612 | var _afters = child.nodes.skip(position);
|
40613 | one = child.set('nodes', _befores);
|
40614 | two = child.set('nodes', _afters).regenerateKey();
|
40615 | }
|
40616 |
|
40617 | // Remove the old node and insert the newly split children.
|
40618 | node = node.removeNode(index);
|
40619 | node = node.insertNode(index, two);
|
40620 | node = node.insertNode(index, one);
|
40621 | return node;
|
40622 | }
|
40623 |
|
40624 | /**
|
40625 | * Set a new value for a child node by `key`.
|
40626 | *
|
40627 | * @param {Node} node
|
40628 | * @return {Node}
|
40629 | */
|
40630 |
|
40631 | }, {
|
40632 | key: 'updateNode',
|
40633 | value: function updateNode(node) {
|
40634 | if (node.key == this.key) {
|
40635 | return node;
|
40636 | }
|
40637 |
|
40638 | var child = this.assertDescendant(node.key);
|
40639 | var ancestors = this.getAncestors(node.key);
|
40640 |
|
40641 | ancestors.reverse().forEach(function (parent) {
|
40642 | var _parent = parent,
|
40643 | nodes = _parent.nodes;
|
40644 |
|
40645 | var index = nodes.indexOf(child);
|
40646 | child = parent;
|
40647 | nodes = nodes.set(index, node);
|
40648 | parent = parent.set('nodes', nodes);
|
40649 | node = parent;
|
40650 | });
|
40651 |
|
40652 | return node;
|
40653 | }
|
40654 |
|
40655 | /**
|
40656 | * Validate the node against a `schema`.
|
40657 | *
|
40658 | * @param {Schema} schema
|
40659 | * @return {Object|Null}
|
40660 | */
|
40661 |
|
40662 | }, {
|
40663 | key: 'validate',
|
40664 | value: function validate(schema) {
|
40665 | return schema.__validate(this);
|
40666 | }
|
40667 |
|
40668 | /**
|
40669 | * True if the node has both descendants in that order, false otherwise. The
|
40670 | * order is depth-first, post-order.
|
40671 | *
|
40672 | * @param {String} first
|
40673 | * @param {String} second
|
40674 | * @return {Boolean}
|
40675 | */
|
40676 |
|
40677 | }, {
|
40678 | key: 'areDescendantSorted',
|
40679 | value: function areDescendantSorted(first, second) {
|
40680 | _logger2.default.deprecate('0.19.0', 'The Node.areDescendantSorted(first, second) method is deprecated, please use `Node.areDescendantsSorted(first, second) instead.');
|
40681 | return this.areDescendantsSorted(first, second);
|
40682 | }
|
40683 |
|
40684 | /**
|
40685 | * Concat children `nodes` on to the end of the node.
|
40686 | *
|
40687 | * @param {List<Node>} nodes
|
40688 | * @return {Node}
|
40689 | */
|
40690 |
|
40691 | }, {
|
40692 | key: 'concatChildren',
|
40693 | value: function concatChildren(nodes) {
|
40694 | _logger2.default.deprecate('0.19.0', 'The `Node.concatChildren(nodes)` method is deprecated.');
|
40695 | nodes = this.nodes.concat(nodes);
|
40696 | return this.set('nodes', nodes);
|
40697 | }
|
40698 |
|
40699 | /**
|
40700 | * Decorate all of the text nodes with a `decorator` function.
|
40701 | *
|
40702 | * @param {Function} decorator
|
40703 | * @return {Node}
|
40704 | */
|
40705 |
|
40706 | }, {
|
40707 | key: 'decorateTexts',
|
40708 | value: function decorateTexts(decorator) {
|
40709 | _logger2.default.deprecate('0.19.0', 'The `Node.decorateTexts(decorator) method is deprecated.');
|
40710 | return this.mapDescendants(function (child) {
|
40711 | return child.kind == 'text' ? child.decorateCharacters(decorator) : child;
|
40712 | });
|
40713 | }
|
40714 |
|
40715 | /**
|
40716 | * Recursively filter all descendant nodes with `iterator`, depth-first.
|
40717 | * It is different from `filterDescendants` in regard of the order of results.
|
40718 | *
|
40719 | * @param {Function} iterator
|
40720 | * @return {List<Node>}
|
40721 | */
|
40722 |
|
40723 | }, {
|
40724 | key: 'filterDescendantsDeep',
|
40725 | value: function filterDescendantsDeep(iterator) {
|
40726 | _logger2.default.deprecate('0.19.0', 'The Node.filterDescendantsDeep(iterator) method is deprecated.');
|
40727 | return this.nodes.reduce(function (matches, child, i, nodes) {
|
40728 | if (child.kind != 'text') matches = matches.concat(child.filterDescendantsDeep(iterator));
|
40729 | if (iterator(child, i, nodes)) matches = matches.push(child);
|
40730 | return matches;
|
40731 | }, new _immutable.List());
|
40732 | }
|
40733 |
|
40734 | /**
|
40735 | * Recursively find all descendant nodes by `iterator`. Depth first.
|
40736 | *
|
40737 | * @param {Function} iterator
|
40738 | * @return {Node|Null}
|
40739 | */
|
40740 |
|
40741 | }, {
|
40742 | key: 'findDescendantDeep',
|
40743 | value: function findDescendantDeep(iterator) {
|
40744 | _logger2.default.deprecate('0.19.0', 'The Node.findDescendantDeep(iterator) method is deprecated.');
|
40745 | var found = void 0;
|
40746 |
|
40747 | this.forEachDescendant(function (node) {
|
40748 | if (iterator(node)) {
|
40749 | found = node;
|
40750 | return false;
|
40751 | }
|
40752 | });
|
40753 |
|
40754 | return found;
|
40755 | }
|
40756 |
|
40757 | /**
|
40758 | * Get children between two child keys.
|
40759 | *
|
40760 | * @param {String} start
|
40761 | * @param {String} end
|
40762 | * @return {Node}
|
40763 | */
|
40764 |
|
40765 | }, {
|
40766 | key: 'getChildrenBetween',
|
40767 | value: function getChildrenBetween(start, end) {
|
40768 | _logger2.default.deprecate('0.19.0', 'The `Node.getChildrenBetween(start, end)` method is deprecated.');
|
40769 | start = this.assertChild(start);
|
40770 | start = this.nodes.indexOf(start);
|
40771 | end = this.assertChild(end);
|
40772 | end = this.nodes.indexOf(end);
|
40773 | return this.nodes.slice(start + 1, end);
|
40774 | }
|
40775 |
|
40776 | /**
|
40777 | * Get children between two child keys, including the two children.
|
40778 | *
|
40779 | * @param {String} start
|
40780 | * @param {String} end
|
40781 | * @return {Node}
|
40782 | */
|
40783 |
|
40784 | }, {
|
40785 | key: 'getChildrenBetweenIncluding',
|
40786 | value: function getChildrenBetweenIncluding(start, end) {
|
40787 | _logger2.default.deprecate('0.19.0', 'The `Node.getChildrenBetweenIncluding(start, end)` method is deprecated.');
|
40788 | start = this.assertChild(start);
|
40789 | start = this.nodes.indexOf(start);
|
40790 | end = this.assertChild(end);
|
40791 | end = this.nodes.indexOf(end);
|
40792 | return this.nodes.slice(start, end + 1);
|
40793 | }
|
40794 |
|
40795 | /**
|
40796 | * Get the highest child ancestor of a node by `key`.
|
40797 | *
|
40798 | * @param {String} key
|
40799 | * @return {Node|Null}
|
40800 | */
|
40801 |
|
40802 | }, {
|
40803 | key: 'getHighestChild',
|
40804 | value: function getHighestChild(key) {
|
40805 | _logger2.default.deprecate('0.19.0', 'The `Node.getHighestChild(key) method is deprecated, please use `Node.getFurthestAncestor(key) instead.');
|
40806 | return this.getFurthestAncestor(key);
|
40807 | }
|
40808 |
|
40809 | /**
|
40810 | * Get the highest parent of a node by `key` which has an only child.
|
40811 | *
|
40812 | * @param {String} key
|
40813 | * @return {Node|Null}
|
40814 | */
|
40815 |
|
40816 | }, {
|
40817 | key: 'getHighestOnlyChildParent',
|
40818 | value: function getHighestOnlyChildParent(key) {
|
40819 | _logger2.default.deprecate('0.19.0', 'The `Node.getHighestOnlyChildParent(key)` method is deprecated, please use `Node.getFurthestOnlyChildAncestor` instead.');
|
40820 | return this.getFurthestOnlyChildAncestor(key);
|
40821 | }
|
40822 |
|
40823 | /**
|
40824 | * Check if the inline nodes are split at a `range`.
|
40825 | *
|
40826 | * @param {Selection} range
|
40827 | * @return {Boolean}
|
40828 | */
|
40829 |
|
40830 | }, {
|
40831 | key: 'isInlineSplitAtRange',
|
40832 | value: function isInlineSplitAtRange(range) {
|
40833 | _logger2.default.deprecate('0.19.0', 'The `Node.isInlineSplitAtRange(range)` method is deprecated.');
|
40834 | range = range.normalize(this);
|
40835 | if (range.isExpanded) throw new Error();
|
40836 |
|
40837 | var _range8 = range,
|
40838 | startKey = _range8.startKey;
|
40839 |
|
40840 | var start = this.getFurthestInline(startKey) || this.getDescendant(startKey);
|
40841 | return range.isAtStartOf(start) || range.isAtEndOf(start);
|
40842 | }
|
40843 | }], [{
|
40844 | key: 'create',
|
40845 |
|
40846 |
|
40847 | /**
|
40848 | * Create a new `Node` with `attrs`.
|
40849 | *
|
40850 | * @param {Object|Node} attrs
|
40851 | * @return {Node}
|
40852 | */
|
40853 |
|
40854 | value: function create() {
|
40855 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
40856 |
|
40857 | if (Node.isNode(attrs)) {
|
40858 | return attrs;
|
40859 | }
|
40860 |
|
40861 | if ((0, _isPlainObject2.default)(attrs)) {
|
40862 | switch (attrs.kind) {
|
40863 | case 'block':
|
40864 | return _block2.default.create(attrs);
|
40865 | case 'document':
|
40866 | return _document2.default.create(attrs);
|
40867 | case 'inline':
|
40868 | return _inline2.default.create(attrs);
|
40869 | case 'text':
|
40870 | return _text2.default.create(attrs);
|
40871 | default:
|
40872 | {
|
40873 | throw new Error('`Node.create` requires a `kind` string.');
|
40874 | }
|
40875 | }
|
40876 | }
|
40877 |
|
40878 | throw new Error('`Node.create` only accepts objects or nodes but you passed it: ' + attrs);
|
40879 | }
|
40880 |
|
40881 | /**
|
40882 | * Create a list of `Nodes` from an array.
|
40883 | *
|
40884 | * @param {Array<Object|Node>} elements
|
40885 | * @return {List<Node>}
|
40886 | */
|
40887 |
|
40888 | }, {
|
40889 | key: 'createList',
|
40890 | value: function createList() {
|
40891 | var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
40892 |
|
40893 | if (_immutable.List.isList(elements) || Array.isArray(elements)) {
|
40894 | var list = new _immutable.List(elements.map(Node.create));
|
40895 | return list;
|
40896 | }
|
40897 |
|
40898 | throw new Error('`Node.createList` only accepts lists or arrays, but you passed it: ' + elements);
|
40899 | }
|
40900 |
|
40901 | /**
|
40902 | * Create a dictionary of settable node properties from `attrs`.
|
40903 | *
|
40904 | * @param {Object|String|Node} attrs
|
40905 | * @return {Object}
|
40906 | */
|
40907 |
|
40908 | }, {
|
40909 | key: 'createProperties',
|
40910 | value: function createProperties() {
|
40911 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
40912 |
|
40913 | if (_block2.default.isBlock(attrs) || _inline2.default.isInline(attrs)) {
|
40914 | return {
|
40915 | data: attrs.data,
|
40916 | isVoid: attrs.isVoid,
|
40917 | type: attrs.type
|
40918 | };
|
40919 | }
|
40920 |
|
40921 | if (typeof attrs == 'string') {
|
40922 | return { type: attrs };
|
40923 | }
|
40924 |
|
40925 | if ((0, _isPlainObject2.default)(attrs)) {
|
40926 | var props = {};
|
40927 | if ('type' in attrs) props.type = attrs.type;
|
40928 | if ('data' in attrs) props.data = _data2.default.create(attrs.data);
|
40929 | if ('isVoid' in attrs) props.isVoid = attrs.isVoid;
|
40930 | return props;
|
40931 | }
|
40932 |
|
40933 | throw new Error('`Node.createProperties` only accepts objects, strings, blocks or inlines, but you passed it: ' + attrs);
|
40934 | }
|
40935 |
|
40936 | /**
|
40937 | * Create a `Node` from a JSON `object`.
|
40938 | *
|
40939 | * @param {Object} object
|
40940 | * @return {Node}
|
40941 | */
|
40942 |
|
40943 | }, {
|
40944 | key: 'fromJSON',
|
40945 | value: function fromJSON(object) {
|
40946 | var kind = object.kind;
|
40947 |
|
40948 |
|
40949 | switch (kind) {
|
40950 | case 'block':
|
40951 | return _block2.default.fromJSON(object);
|
40952 | case 'document':
|
40953 | return _document2.default.fromJSON(object);
|
40954 | case 'inline':
|
40955 | return _inline2.default.fromJSON(object);
|
40956 | case 'text':
|
40957 | return _text2.default.fromJSON(object);
|
40958 | default:
|
40959 | {
|
40960 | throw new Error('`Node.fromJSON` requires a `kind` of either \'block\', \'document\', \'inline\' or \'text\', but you passed: ' + kind);
|
40961 | }
|
40962 | }
|
40963 | }
|
40964 |
|
40965 | /**
|
40966 | * Alias `fromJS`.
|
40967 | */
|
40968 |
|
40969 | }, {
|
40970 | key: 'isNode',
|
40971 |
|
40972 |
|
40973 | /**
|
40974 | * Check if a `value` is a `Node`.
|
40975 | *
|
40976 | * @param {Any} value
|
40977 | * @return {Boolean}
|
40978 | */
|
40979 |
|
40980 | value: function isNode(value) {
|
40981 | return _block2.default.isBlock(value) || _document2.default.isDocument(value) || _inline2.default.isInline(value) || _text2.default.isText(value);
|
40982 | }
|
40983 |
|
40984 | /**
|
40985 | * Check if a `value` is a list of nodes.
|
40986 | *
|
40987 | * @param {Any} value
|
40988 | * @return {Boolean}
|
40989 | */
|
40990 |
|
40991 | }, {
|
40992 | key: 'isNodeList',
|
40993 | value: function isNodeList(value) {
|
40994 | return _immutable.List.isList(value) && value.every(function (item) {
|
40995 | return Node.isNode(item);
|
40996 | });
|
40997 | }
|
40998 | }]);
|
40999 |
|
41000 | return Node;
|
41001 | }();
|
41002 |
|
41003 | /**
|
41004 | * Normalize a key argument `value`.
|
41005 | *
|
41006 | * @param {String|Node} value
|
41007 | * @return {String}
|
41008 | */
|
41009 |
|
41010 | Node.fromJS = Node.fromJSON;
|
41011 | function normalizeKey(value) {
|
41012 | if (typeof value == 'string') return value;
|
41013 |
|
41014 | _logger2.default.deprecate('0.14.0', 'An object was passed to a Node method instead of a `key` string. This was previously supported, but is being deprecated because it can have a negative impact on performance. The object in question was:', value);
|
41015 |
|
41016 | if (Node.isNode(value)) {
|
41017 | return value.key;
|
41018 | }
|
41019 |
|
41020 | throw new Error('Invalid `key` argument! It must be either a block, an inline, a text, or a string. You passed: ' + value);
|
41021 | }
|
41022 |
|
41023 | /**
|
41024 | * Memoize read methods.
|
41025 | */
|
41026 |
|
41027 | (0, _memoize2.default)(Node.prototype, ['getBlocks', 'getBlocksAsArray', 'getCharacters', 'getCharactersAsArray', 'getFirstText', 'getInlines', 'getInlinesAsArray', 'getKeys', 'getLastText', 'getMarks', 'getOrderedMarks', 'getMarksAsArray', 'getText', 'getTextDirection', 'getTexts', 'getTextsAsArray', 'isLeafBlock', 'isLeafInline'], {
|
41028 | takesArguments: false
|
41029 | });
|
41030 |
|
41031 | (0, _memoize2.default)(Node.prototype, ['areDescendantsSorted', 'getActiveMarksAtRange', 'getActiveMarksAtRangeAsArray', 'getAncestors', 'getBlocksAtRange', 'getBlocksAtRangeAsArray', 'getBlocksByType', 'getBlocksByTypeAsArray', 'getCharactersAtRange', 'getCharactersAtRangeAsArray', 'getChild', 'getChildrenBetween', 'getChildrenBetweenIncluding', 'getClosestBlock', 'getClosestInline', 'getClosestVoid', 'getCommonAncestor', 'getComponent', 'getDecorators', 'getDepth', 'getDescendant', 'getDescendantAtPath', 'getDescendantDecorators', 'getFragmentAtRange', 'getFurthestBlock', 'getFurthestInline', 'getFurthestAncestor', 'getFurthestOnlyChildAncestor', 'getInlinesAtRange', 'getInlinesAtRangeAsArray', 'getInlinesByType', 'getInlinesByTypeAsArray', 'getMarksAtRange', 'getOrderedMarksAtRange', 'getMarksAtRangeAsArray', 'getMarksByType', 'getOrderedMarksByType', 'getMarksByTypeAsArray', 'getNextBlock', 'getNextSibling', 'getNextText', 'getNode', 'getNodeAtPath', 'getOffset', 'getOffsetAtRange', 'getParent', 'getPath', 'getPreviousBlock', 'getPreviousSibling', 'getPreviousText', 'getTextAtOffset', 'getTextsAtRange', 'getTextsAtRangeAsArray', 'hasChild', 'hasDescendant', 'hasNode', 'hasVoidParent', 'isInlineSplitAtRange', 'validate'], {
|
41032 | takesArguments: true
|
41033 | });
|
41034 |
|
41035 | /**
|
41036 | * Export.
|
41037 | *
|
41038 | * @type {Object}
|
41039 | */
|
41040 |
|
41041 | exports.default = Node;
|
41042 | },{"../utils/generate-key":359,"../utils/is-index-in-range":364,"../utils/logger":366,"../utils/memoize":367,"./block":331,"./data":334,"./document":335,"./inline":337,"./text":345,"direction":26,"immutable":135,"is-plain-object":139}],340:[function(require,module,exports){
|
41043 | 'use strict';
|
41044 |
|
41045 | Object.defineProperty(exports, "__esModule", {
|
41046 | value: true
|
41047 | });
|
41048 |
|
41049 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
41050 |
|
41051 | var _modelTypes = require('../constants/model-types');
|
41052 |
|
41053 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
41054 |
|
41055 | var _character = require('./character');
|
41056 |
|
41057 | var _character2 = _interopRequireDefault(_character);
|
41058 |
|
41059 | var _mark = require('./mark');
|
41060 |
|
41061 | var _mark2 = _interopRequireDefault(_mark);
|
41062 |
|
41063 | var _isPlainObject = require('is-plain-object');
|
41064 |
|
41065 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
41066 |
|
41067 | var _immutable = require('immutable');
|
41068 |
|
41069 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
41070 |
|
41071 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
41072 |
|
41073 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
41074 |
|
41075 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
41076 |
|
41077 | /**
|
41078 | * Default properties.
|
41079 | *
|
41080 | * @type {Object}
|
41081 | */
|
41082 |
|
41083 | var DEFAULTS = {
|
41084 | marks: new _immutable.Set(),
|
41085 | text: ''
|
41086 | };
|
41087 |
|
41088 | /**
|
41089 | * Range.
|
41090 | *
|
41091 | * @type {Range}
|
41092 | */
|
41093 |
|
41094 | var Range = function (_Record) {
|
41095 | _inherits(Range, _Record);
|
41096 |
|
41097 | function Range() {
|
41098 | _classCallCheck(this, Range);
|
41099 |
|
41100 | return _possibleConstructorReturn(this, (Range.__proto__ || Object.getPrototypeOf(Range)).apply(this, arguments));
|
41101 | }
|
41102 |
|
41103 | _createClass(Range, [{
|
41104 | key: 'getCharacters',
|
41105 |
|
41106 |
|
41107 | /**
|
41108 | * Return range as a list of characters
|
41109 | *
|
41110 | * @return {List<Character>}
|
41111 | */
|
41112 |
|
41113 | value: function getCharacters() {
|
41114 | var marks = this.marks;
|
41115 |
|
41116 | var characters = _character2.default.createList(this.text.split('').map(function (char) {
|
41117 | return _character2.default.create({
|
41118 | text: char,
|
41119 | marks: marks
|
41120 | });
|
41121 | }));
|
41122 |
|
41123 | return characters;
|
41124 | }
|
41125 |
|
41126 | /**
|
41127 | * Return a JSON representation of the range.
|
41128 | *
|
41129 | * @return {Object}
|
41130 | */
|
41131 |
|
41132 | }, {
|
41133 | key: 'toJSON',
|
41134 | value: function toJSON() {
|
41135 | var object = {
|
41136 | kind: this.kind,
|
41137 | marks: this.marks.toArray().map(function (m) {
|
41138 | return m.toJSON();
|
41139 | }),
|
41140 | text: this.text
|
41141 | };
|
41142 |
|
41143 | return object;
|
41144 | }
|
41145 |
|
41146 | /**
|
41147 | * Alias `toJS`.
|
41148 | */
|
41149 |
|
41150 | }, {
|
41151 | key: 'toJS',
|
41152 | value: function toJS() {
|
41153 | return this.toJSON();
|
41154 | }
|
41155 | }, {
|
41156 | key: 'kind',
|
41157 |
|
41158 |
|
41159 | /**
|
41160 | * Get the node's kind.
|
41161 | *
|
41162 | * @return {String}
|
41163 | */
|
41164 |
|
41165 | get: function get() {
|
41166 | return 'range';
|
41167 | }
|
41168 | }], [{
|
41169 | key: 'create',
|
41170 |
|
41171 |
|
41172 | /**
|
41173 | * Create a new `Range` with `attrs`.
|
41174 | *
|
41175 | * @param {Object|Range} attrs
|
41176 | * @return {Range}
|
41177 | */
|
41178 |
|
41179 | value: function create() {
|
41180 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
41181 |
|
41182 | if (Range.isRange(attrs)) {
|
41183 | return attrs;
|
41184 | }
|
41185 |
|
41186 | if (typeof attrs == 'string') {
|
41187 | attrs = { text: attrs };
|
41188 | }
|
41189 |
|
41190 | if ((0, _isPlainObject2.default)(attrs)) {
|
41191 | return Range.fromJSON(attrs);
|
41192 | }
|
41193 |
|
41194 | throw new Error('`Range.create` only accepts objects, strings or ranges, but you passed it: ' + attrs);
|
41195 | }
|
41196 |
|
41197 | /**
|
41198 | * Create a list of `Ranges` from `value`.
|
41199 | *
|
41200 | * @param {Array<Range|Object>|List<Range|Object>} value
|
41201 | * @return {List<Range>}
|
41202 | */
|
41203 |
|
41204 | }, {
|
41205 | key: 'createList',
|
41206 | value: function createList() {
|
41207 | var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
41208 |
|
41209 | if (_immutable.List.isList(value) || Array.isArray(value)) {
|
41210 | var list = new _immutable.List(value.map(Range.create));
|
41211 | return list;
|
41212 | }
|
41213 |
|
41214 | throw new Error('`Range.createList` only accepts arrays or lists, but you passed it: ' + value);
|
41215 | }
|
41216 |
|
41217 | /**
|
41218 | * Create a `Range` from a JSON `object`.
|
41219 | *
|
41220 | * @param {Object} object
|
41221 | * @return {Range}
|
41222 | */
|
41223 |
|
41224 | }, {
|
41225 | key: 'fromJSON',
|
41226 | value: function fromJSON(object) {
|
41227 | var _object$text = object.text,
|
41228 | text = _object$text === undefined ? '' : _object$text,
|
41229 | _object$marks = object.marks,
|
41230 | marks = _object$marks === undefined ? [] : _object$marks;
|
41231 |
|
41232 |
|
41233 | var range = new Range({
|
41234 | text: text,
|
41235 | marks: new _immutable.Set(marks.map(_mark2.default.fromJSON))
|
41236 | });
|
41237 |
|
41238 | return range;
|
41239 | }
|
41240 |
|
41241 | /**
|
41242 | * Alias `fromJS`.
|
41243 | */
|
41244 |
|
41245 | }, {
|
41246 | key: 'isRange',
|
41247 |
|
41248 |
|
41249 | /**
|
41250 | * Check if a `value` is a `Range`.
|
41251 | *
|
41252 | * @param {Any} value
|
41253 | * @return {Boolean}
|
41254 | */
|
41255 |
|
41256 | value: function isRange(value) {
|
41257 | return !!(value && value[_modelTypes2.default.RANGE]);
|
41258 | }
|
41259 |
|
41260 | /**
|
41261 | * Check if a `value` is a list of ranges.
|
41262 | *
|
41263 | * @param {Any} value
|
41264 | * @return {Boolean}
|
41265 | */
|
41266 |
|
41267 | }, {
|
41268 | key: 'isRangeList',
|
41269 | value: function isRangeList(value) {
|
41270 | return _immutable.List.isList(value) && value.every(function (item) {
|
41271 | return Range.isRange(item);
|
41272 | });
|
41273 | }
|
41274 | }]);
|
41275 |
|
41276 | return Range;
|
41277 | }((0, _immutable.Record)(DEFAULTS));
|
41278 |
|
41279 | /**
|
41280 | * Attach a pseudo-symbol for type checking.
|
41281 | */
|
41282 |
|
41283 | Range.fromJS = Range.fromJSON;
|
41284 | Range.prototype[_modelTypes2.default.RANGE] = true;
|
41285 |
|
41286 | /**
|
41287 | * Export.
|
41288 | *
|
41289 | * @type {Range}
|
41290 | */
|
41291 |
|
41292 | exports.default = Range;
|
41293 | },{"../constants/model-types":328,"./character":333,"./mark":338,"immutable":135,"is-plain-object":139}],341:[function(require,module,exports){
|
41294 | 'use strict';
|
41295 |
|
41296 | Object.defineProperty(exports, "__esModule", {
|
41297 | value: true
|
41298 | });
|
41299 |
|
41300 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
41301 |
|
41302 | var _modelTypes = require('../constants/model-types');
|
41303 |
|
41304 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
41305 |
|
41306 | var _react = require('react');
|
41307 |
|
41308 | var _react2 = _interopRequireDefault(_react);
|
41309 |
|
41310 | var _find = require('lodash/find');
|
41311 |
|
41312 | var _find2 = _interopRequireDefault(_find);
|
41313 |
|
41314 | var _isPlainObject = require('is-plain-object');
|
41315 |
|
41316 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
41317 |
|
41318 | var _isReactComponent = require('../utils/is-react-component');
|
41319 |
|
41320 | var _isReactComponent2 = _interopRequireDefault(_isReactComponent);
|
41321 |
|
41322 | var _logger = require('../utils/logger');
|
41323 |
|
41324 | var _logger2 = _interopRequireDefault(_logger);
|
41325 |
|
41326 | var _typeOf = require('type-of');
|
41327 |
|
41328 | var _typeOf2 = _interopRequireDefault(_typeOf);
|
41329 |
|
41330 | var _immutable = require('immutable');
|
41331 |
|
41332 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
41333 |
|
41334 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
41335 |
|
41336 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
41337 |
|
41338 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
41339 |
|
41340 | /**
|
41341 | * Default properties.
|
41342 | *
|
41343 | * @type {Object}
|
41344 | */
|
41345 |
|
41346 | var DEFAULTS = {
|
41347 | rules: []
|
41348 | };
|
41349 |
|
41350 | /**
|
41351 | * Schema.
|
41352 | *
|
41353 | * @type {Schema}
|
41354 | */
|
41355 |
|
41356 | var Schema = function (_Record) {
|
41357 | _inherits(Schema, _Record);
|
41358 |
|
41359 | function Schema() {
|
41360 | _classCallCheck(this, Schema);
|
41361 |
|
41362 | return _possibleConstructorReturn(this, (Schema.__proto__ || Object.getPrototypeOf(Schema)).apply(this, arguments));
|
41363 | }
|
41364 |
|
41365 | _createClass(Schema, [{
|
41366 | key: '__getComponent',
|
41367 |
|
41368 |
|
41369 | /**
|
41370 | * Return the renderer for an `object`.
|
41371 | *
|
41372 | * This method is private, because it should always be called on one of the
|
41373 | * often-changing immutable objects instead, since it will be memoized for
|
41374 | * much better performance.
|
41375 | *
|
41376 | * @param {Mixed} object
|
41377 | * @return {Component|Void}
|
41378 | */
|
41379 |
|
41380 | value: function __getComponent(object) {
|
41381 | var match = (0, _find2.default)(this.rules, function (rule) {
|
41382 | return rule.render && rule.match(object);
|
41383 | });
|
41384 | if (!match) return;
|
41385 | return match.render;
|
41386 | }
|
41387 |
|
41388 | /**
|
41389 | * Return the decorators for an `object`.
|
41390 | *
|
41391 | * This method is private, because it should always be called on one of the
|
41392 | * often-changing immutable objects instead, since it will be memoized for
|
41393 | * much better performance.
|
41394 | *
|
41395 | * @param {Mixed} object
|
41396 | * @return {Array}
|
41397 | */
|
41398 |
|
41399 | }, {
|
41400 | key: '__getDecorators',
|
41401 | value: function __getDecorators(object) {
|
41402 | return this.rules.filter(function (rule) {
|
41403 | return rule.decorate && rule.match(object);
|
41404 | }).map(function (rule) {
|
41405 | return function (text) {
|
41406 | return rule.decorate(text, object);
|
41407 | };
|
41408 | });
|
41409 | }
|
41410 |
|
41411 | /**
|
41412 | * Validate an `object` against the schema, returning the failing rule and
|
41413 | * value if the object is invalid, or void if it's valid.
|
41414 | *
|
41415 | * This method is private, because it should always be called on one of the
|
41416 | * often-changing immutable objects instead, since it will be memoized for
|
41417 | * much better performance.
|
41418 | *
|
41419 | * @param {Mixed} object
|
41420 | * @return {Object|Void}
|
41421 | */
|
41422 |
|
41423 | }, {
|
41424 | key: '__validate',
|
41425 | value: function __validate(object) {
|
41426 | var value = void 0;
|
41427 |
|
41428 | var match = (0, _find2.default)(this.rules, function (rule) {
|
41429 | if (!rule.validate) return;
|
41430 | if (!rule.match(object)) return;
|
41431 |
|
41432 | value = rule.validate(object);
|
41433 | return value;
|
41434 | });
|
41435 |
|
41436 | if (!value) return;
|
41437 |
|
41438 | return {
|
41439 | rule: match,
|
41440 | value: value
|
41441 | };
|
41442 | }
|
41443 | }, {
|
41444 | key: 'kind',
|
41445 |
|
41446 |
|
41447 | /**
|
41448 | * Get the kind.
|
41449 | *
|
41450 | * @return {String}
|
41451 | */
|
41452 |
|
41453 | get: function get() {
|
41454 | return 'schema';
|
41455 | }
|
41456 |
|
41457 | /**
|
41458 | * Return true if one rule can normalize the document
|
41459 | *
|
41460 | * @return {Boolean}
|
41461 | */
|
41462 |
|
41463 | }, {
|
41464 | key: 'hasValidators',
|
41465 | get: function get() {
|
41466 | var rules = this.rules;
|
41467 |
|
41468 | return rules.some(function (rule) {
|
41469 | return rule.validate;
|
41470 | });
|
41471 | }
|
41472 |
|
41473 | /**
|
41474 | * Return true if one rule can decorate text nodes
|
41475 | *
|
41476 | * @return {Boolean}
|
41477 | */
|
41478 |
|
41479 | }, {
|
41480 | key: 'hasDecorators',
|
41481 | get: function get() {
|
41482 | var rules = this.rules;
|
41483 |
|
41484 | return rules.some(function (rule) {
|
41485 | return rule.decorate;
|
41486 | });
|
41487 | }
|
41488 | }], [{
|
41489 | key: 'create',
|
41490 |
|
41491 |
|
41492 | /**
|
41493 | * Create a new `Schema` with `attrs`.
|
41494 | *
|
41495 | * @param {Object|Schema} attrs
|
41496 | * @return {Schema}
|
41497 | */
|
41498 |
|
41499 | value: function create() {
|
41500 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
41501 |
|
41502 | if (Schema.isSchema(attrs)) {
|
41503 | return attrs;
|
41504 | }
|
41505 |
|
41506 | if ((0, _isPlainObject2.default)(attrs)) {
|
41507 | return Schema.fromJSON(attrs);
|
41508 | }
|
41509 |
|
41510 | throw new Error('`Schema.create` only accepts objects or schemas, but you passed it: ' + attrs);
|
41511 | }
|
41512 |
|
41513 | /**
|
41514 | * Check if a `value` is a `Schema`.
|
41515 | *
|
41516 | * @param {Any} value
|
41517 | * @return {Boolean}
|
41518 | */
|
41519 |
|
41520 | }, {
|
41521 | key: 'isSchema',
|
41522 | value: function isSchema(value) {
|
41523 | return !!(value && value[_modelTypes2.default.SCHEMA]);
|
41524 | }
|
41525 |
|
41526 | /**
|
41527 | * Create a `Schema` from a JSON `object`.
|
41528 | *
|
41529 | * @param {Object} object
|
41530 | * @return {Schema}
|
41531 | */
|
41532 |
|
41533 | }, {
|
41534 | key: 'fromJSON',
|
41535 | value: function fromJSON(object) {
|
41536 | object = normalizeProperties(object);
|
41537 | var schema = new Schema(object);
|
41538 | return schema;
|
41539 | }
|
41540 |
|
41541 | /**
|
41542 | * Alias `fromJS`.
|
41543 | */
|
41544 |
|
41545 | }]);
|
41546 |
|
41547 | return Schema;
|
41548 | }((0, _immutable.Record)(DEFAULTS));
|
41549 |
|
41550 | /**
|
41551 | * Normalize the `properties` of a schema.
|
41552 | *
|
41553 | * @param {Object} properties
|
41554 | * @return {Object}
|
41555 | */
|
41556 |
|
41557 | Schema.fromJS = Schema.fromJSON;
|
41558 | function normalizeProperties(properties) {
|
41559 | var _properties$rules = properties.rules,
|
41560 | rules = _properties$rules === undefined ? [] : _properties$rules,
|
41561 | nodes = properties.nodes,
|
41562 | marks = properties.marks;
|
41563 |
|
41564 |
|
41565 | if (nodes) {
|
41566 | var array = normalizeNodes(nodes);
|
41567 | rules = rules.concat(array);
|
41568 | }
|
41569 |
|
41570 | if (marks) {
|
41571 | var _array = normalizeMarks(marks);
|
41572 | rules = rules.concat(_array);
|
41573 | }
|
41574 |
|
41575 | if (properties.transform) {
|
41576 | _logger2.default.deprecate('0.22.0', 'The `schema.transform` property has been deprecated in favor of `schema.change`.');
|
41577 | properties.change = properties.transform;
|
41578 | delete properties.transform;
|
41579 | }
|
41580 |
|
41581 | return { rules: rules };
|
41582 | }
|
41583 |
|
41584 | /**
|
41585 | * Normalize a `nodes` shorthand argument.
|
41586 | *
|
41587 | * @param {Object} nodes
|
41588 | * @return {Array}
|
41589 | */
|
41590 |
|
41591 | function normalizeNodes(nodes) {
|
41592 | var rules = [];
|
41593 |
|
41594 | var _loop = function _loop(key) {
|
41595 | var rule = nodes[key];
|
41596 |
|
41597 | if ((0, _typeOf2.default)(rule) == 'function' || (0, _isReactComponent2.default)(rule)) {
|
41598 | rule = { render: rule };
|
41599 | }
|
41600 |
|
41601 | rule.match = function (object) {
|
41602 | return (object.kind == 'block' || object.kind == 'inline') && object.type == key;
|
41603 | };
|
41604 |
|
41605 | rules.push(rule);
|
41606 | };
|
41607 |
|
41608 | for (var key in nodes) {
|
41609 | _loop(key);
|
41610 | }
|
41611 |
|
41612 | return rules;
|
41613 | }
|
41614 |
|
41615 | /**
|
41616 | * Normalize a `marks` shorthand argument.
|
41617 | *
|
41618 | * @param {Object} marks
|
41619 | * @return {Array}
|
41620 | */
|
41621 |
|
41622 | function normalizeMarks(marks) {
|
41623 | var rules = [];
|
41624 |
|
41625 | var _loop2 = function _loop2(key) {
|
41626 | var rule = marks[key];
|
41627 |
|
41628 | if (!rule.render && !rule.decorator && !rule.validate) {
|
41629 | rule = { render: rule };
|
41630 | }
|
41631 |
|
41632 | rule.render = normalizeMarkComponent(rule.render);
|
41633 | rule.match = function (object) {
|
41634 | return object.kind == 'mark' && object.type == key;
|
41635 | };
|
41636 | rules.push(rule);
|
41637 | };
|
41638 |
|
41639 | for (var key in marks) {
|
41640 | _loop2(key);
|
41641 | }
|
41642 |
|
41643 | return rules;
|
41644 | }
|
41645 |
|
41646 | /**
|
41647 | * Normalize a mark `render` property.
|
41648 | *
|
41649 | * @param {Component|Function|Object|String} render
|
41650 | * @return {Component}
|
41651 | */
|
41652 |
|
41653 | function normalizeMarkComponent(render) {
|
41654 | if ((0, _isReactComponent2.default)(render)) return render;
|
41655 |
|
41656 | switch ((0, _typeOf2.default)(render)) {
|
41657 | case 'function':
|
41658 | return render;
|
41659 | case 'object':
|
41660 | return function (props) {
|
41661 | return _react2.default.createElement(
|
41662 | 'span',
|
41663 | { style: render },
|
41664 | props.children
|
41665 | );
|
41666 | };
|
41667 | case 'string':
|
41668 | return function (props) {
|
41669 | return _react2.default.createElement(
|
41670 | 'span',
|
41671 | { className: render },
|
41672 | props.children
|
41673 | );
|
41674 | };
|
41675 | }
|
41676 | }
|
41677 |
|
41678 | /**
|
41679 | * Attach a pseudo-symbol for type checking.
|
41680 | */
|
41681 |
|
41682 | Schema.prototype[_modelTypes2.default.SCHEMA] = true;
|
41683 |
|
41684 | /**
|
41685 | * Export.
|
41686 | *
|
41687 | * @type {Schema}
|
41688 | */
|
41689 |
|
41690 | exports.default = Schema;
|
41691 | },{"../constants/model-types":328,"../utils/is-react-component":365,"../utils/logger":366,"immutable":135,"is-plain-object":139,"lodash/find":489,"react":309,"type-of":517}],342:[function(require,module,exports){
|
41692 | 'use strict';
|
41693 |
|
41694 | Object.defineProperty(exports, "__esModule", {
|
41695 | value: true
|
41696 | });
|
41697 |
|
41698 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
41699 |
|
41700 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
41701 |
|
41702 | var _modelTypes = require('../constants/model-types');
|
41703 |
|
41704 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
41705 |
|
41706 | var _isPlainObject = require('is-plain-object');
|
41707 |
|
41708 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
41709 |
|
41710 | var _logger = require('../utils/logger');
|
41711 |
|
41712 | var _logger2 = _interopRequireDefault(_logger);
|
41713 |
|
41714 | var _immutable = require('immutable');
|
41715 |
|
41716 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
41717 |
|
41718 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
41719 |
|
41720 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
41721 |
|
41722 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
41723 |
|
41724 | /**
|
41725 | * Default properties.
|
41726 | *
|
41727 | * @type {Object}
|
41728 | */
|
41729 |
|
41730 | var DEFAULTS = {
|
41731 | anchorKey: null,
|
41732 | anchorOffset: 0,
|
41733 | focusKey: null,
|
41734 | focusOffset: 0,
|
41735 | isBackward: null,
|
41736 | isFocused: false,
|
41737 | marks: null
|
41738 | };
|
41739 |
|
41740 | /**
|
41741 | * Selection.
|
41742 | *
|
41743 | * @type {Selection}
|
41744 | */
|
41745 |
|
41746 | var Selection = function (_Record) {
|
41747 | _inherits(Selection, _Record);
|
41748 |
|
41749 | function Selection() {
|
41750 | _classCallCheck(this, Selection);
|
41751 |
|
41752 | return _possibleConstructorReturn(this, (Selection.__proto__ || Object.getPrototypeOf(Selection)).apply(this, arguments));
|
41753 | }
|
41754 |
|
41755 | _createClass(Selection, [{
|
41756 | key: 'hasAnchorAtStartOf',
|
41757 |
|
41758 |
|
41759 | /**
|
41760 | * Check whether anchor point of the selection is at the start of a `node`.
|
41761 | *
|
41762 | * @param {Node} node
|
41763 | * @return {Boolean}
|
41764 | */
|
41765 |
|
41766 | value: function hasAnchorAtStartOf(node) {
|
41767 | // PERF: Do a check for a `0` offset first since it's quickest.
|
41768 | if (this.anchorOffset != 0) return false;
|
41769 | var first = getFirst(node);
|
41770 | return this.anchorKey == first.key;
|
41771 | }
|
41772 |
|
41773 | /**
|
41774 | * Check whether anchor point of the selection is at the end of a `node`.
|
41775 | *
|
41776 | * @param {Node} node
|
41777 | * @return {Boolean}
|
41778 | */
|
41779 |
|
41780 | }, {
|
41781 | key: 'hasAnchorAtEndOf',
|
41782 | value: function hasAnchorAtEndOf(node) {
|
41783 | var last = getLast(node);
|
41784 | return this.anchorKey == last.key && this.anchorOffset == last.text.length;
|
41785 | }
|
41786 |
|
41787 | /**
|
41788 | * Check whether the anchor edge of a selection is in a `node` and at an
|
41789 | * offset between `start` and `end`.
|
41790 | *
|
41791 | * @param {Node} node
|
41792 | * @param {Number} start
|
41793 | * @param {Number} end
|
41794 | * @return {Boolean}
|
41795 | */
|
41796 |
|
41797 | }, {
|
41798 | key: 'hasAnchorBetween',
|
41799 | value: function hasAnchorBetween(node, start, end) {
|
41800 | return this.anchorOffset <= end && start <= this.anchorOffset && this.hasAnchorIn(node);
|
41801 | }
|
41802 |
|
41803 | /**
|
41804 | * Check whether the anchor edge of a selection is in a `node`.
|
41805 | *
|
41806 | * @param {Node} node
|
41807 | * @return {Boolean}
|
41808 | */
|
41809 |
|
41810 | }, {
|
41811 | key: 'hasAnchorIn',
|
41812 | value: function hasAnchorIn(node) {
|
41813 | return node.kind == 'text' ? node.key == this.anchorKey : this.anchorKey != null && node.hasDescendant(this.anchorKey);
|
41814 | }
|
41815 |
|
41816 | /**
|
41817 | * Check whether focus point of the selection is at the end of a `node`.
|
41818 | *
|
41819 | * @param {Node} node
|
41820 | * @return {Boolean}
|
41821 | */
|
41822 |
|
41823 | }, {
|
41824 | key: 'hasFocusAtEndOf',
|
41825 | value: function hasFocusAtEndOf(node) {
|
41826 | var last = getLast(node);
|
41827 | return this.focusKey == last.key && this.focusOffset == last.text.length;
|
41828 | }
|
41829 |
|
41830 | /**
|
41831 | * Check whether focus point of the selection is at the start of a `node`.
|
41832 | *
|
41833 | * @param {Node} node
|
41834 | * @return {Boolean}
|
41835 | */
|
41836 |
|
41837 | }, {
|
41838 | key: 'hasFocusAtStartOf',
|
41839 | value: function hasFocusAtStartOf(node) {
|
41840 | if (this.focusOffset != 0) return false;
|
41841 | var first = getFirst(node);
|
41842 | return this.focusKey == first.key;
|
41843 | }
|
41844 |
|
41845 | /**
|
41846 | * Check whether the focus edge of a selection is in a `node` and at an
|
41847 | * offset between `start` and `end`.
|
41848 | *
|
41849 | * @param {Node} node
|
41850 | * @param {Number} start
|
41851 | * @param {Number} end
|
41852 | * @return {Boolean}
|
41853 | */
|
41854 |
|
41855 | }, {
|
41856 | key: 'hasFocusBetween',
|
41857 | value: function hasFocusBetween(node, start, end) {
|
41858 | return start <= this.focusOffset && this.focusOffset <= end && this.hasFocusIn(node);
|
41859 | }
|
41860 |
|
41861 | /**
|
41862 | * Check whether the focus edge of a selection is in a `node`.
|
41863 | *
|
41864 | * @param {Node} node
|
41865 | * @return {Boolean}
|
41866 | */
|
41867 |
|
41868 | }, {
|
41869 | key: 'hasFocusIn',
|
41870 | value: function hasFocusIn(node) {
|
41871 | return node.kind == 'text' ? node.key == this.focusKey : this.focusKey != null && node.hasDescendant(this.focusKey);
|
41872 | }
|
41873 |
|
41874 | /**
|
41875 | * Check whether the selection is at the start of a `node`.
|
41876 | *
|
41877 | * @param {Node} node
|
41878 | * @return {Boolean}
|
41879 | */
|
41880 |
|
41881 | }, {
|
41882 | key: 'isAtStartOf',
|
41883 | value: function isAtStartOf(node) {
|
41884 | return this.isCollapsed && this.hasAnchorAtStartOf(node);
|
41885 | }
|
41886 |
|
41887 | /**
|
41888 | * Check whether the selection is at the end of a `node`.
|
41889 | *
|
41890 | * @param {Node} node
|
41891 | * @return {Boolean}
|
41892 | */
|
41893 |
|
41894 | }, {
|
41895 | key: 'isAtEndOf',
|
41896 | value: function isAtEndOf(node) {
|
41897 | return this.isCollapsed && this.hasAnchorAtEndOf(node);
|
41898 | }
|
41899 |
|
41900 | /**
|
41901 | * Focus the selection.
|
41902 | *
|
41903 | * @return {Selection}
|
41904 | */
|
41905 |
|
41906 | }, {
|
41907 | key: 'focus',
|
41908 | value: function focus() {
|
41909 | return this.merge({
|
41910 | isFocused: true
|
41911 | });
|
41912 | }
|
41913 |
|
41914 | /**
|
41915 | * Blur the selection.
|
41916 | *
|
41917 | * @return {Selection}
|
41918 | */
|
41919 |
|
41920 | }, {
|
41921 | key: 'blur',
|
41922 | value: function blur() {
|
41923 | return this.merge({
|
41924 | isFocused: false
|
41925 | });
|
41926 | }
|
41927 |
|
41928 | /**
|
41929 | * Unset the selection.
|
41930 | *
|
41931 | * @return {Selection}
|
41932 | */
|
41933 |
|
41934 | }, {
|
41935 | key: 'deselect',
|
41936 | value: function deselect() {
|
41937 | return this.merge({
|
41938 | anchorKey: null,
|
41939 | anchorOffset: 0,
|
41940 | focusKey: null,
|
41941 | focusOffset: 0,
|
41942 | isFocused: false,
|
41943 | isBackward: false
|
41944 | });
|
41945 | }
|
41946 |
|
41947 | /**
|
41948 | * Flip the selection.
|
41949 | *
|
41950 | * @return {Selection}
|
41951 | */
|
41952 |
|
41953 | }, {
|
41954 | key: 'flip',
|
41955 | value: function flip() {
|
41956 | return this.merge({
|
41957 | anchorKey: this.focusKey,
|
41958 | anchorOffset: this.focusOffset,
|
41959 | focusKey: this.anchorKey,
|
41960 | focusOffset: this.anchorOffset,
|
41961 | isBackward: this.isBackward == null ? null : !this.isBackward
|
41962 | });
|
41963 | }
|
41964 |
|
41965 | /**
|
41966 | * Move the anchor offset `n` characters.
|
41967 | *
|
41968 | * @param {Number} n (optional)
|
41969 | * @return {Selection}
|
41970 | */
|
41971 |
|
41972 | }, {
|
41973 | key: 'moveAnchor',
|
41974 | value: function moveAnchor() {
|
41975 | var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
41976 | var anchorKey = this.anchorKey,
|
41977 | focusKey = this.focusKey,
|
41978 | focusOffset = this.focusOffset,
|
41979 | isBackward = this.isBackward;
|
41980 |
|
41981 | var anchorOffset = this.anchorOffset + n;
|
41982 | return this.merge({
|
41983 | anchorOffset: anchorOffset,
|
41984 | isBackward: anchorKey == focusKey ? anchorOffset > focusOffset : isBackward
|
41985 | });
|
41986 | }
|
41987 |
|
41988 | /**
|
41989 | * Move the anchor offset `n` characters.
|
41990 | *
|
41991 | * @param {Number} n (optional)
|
41992 | * @return {Selection}
|
41993 | */
|
41994 |
|
41995 | }, {
|
41996 | key: 'moveFocus',
|
41997 | value: function moveFocus() {
|
41998 | var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
41999 | var anchorKey = this.anchorKey,
|
42000 | anchorOffset = this.anchorOffset,
|
42001 | focusKey = this.focusKey,
|
42002 | isBackward = this.isBackward;
|
42003 |
|
42004 | var focusOffset = this.focusOffset + n;
|
42005 | return this.merge({
|
42006 | focusOffset: focusOffset,
|
42007 | isBackward: focusKey == anchorKey ? anchorOffset > focusOffset : isBackward
|
42008 | });
|
42009 | }
|
42010 |
|
42011 | /**
|
42012 | * Move the selection's anchor point to a `key` and `offset`.
|
42013 | *
|
42014 | * @param {String} key
|
42015 | * @param {Number} offset
|
42016 | * @return {Selection}
|
42017 | */
|
42018 |
|
42019 | }, {
|
42020 | key: 'moveAnchorTo',
|
42021 | value: function moveAnchorTo(key, offset) {
|
42022 | var anchorKey = this.anchorKey,
|
42023 | focusKey = this.focusKey,
|
42024 | focusOffset = this.focusOffset,
|
42025 | isBackward = this.isBackward;
|
42026 |
|
42027 | return this.merge({
|
42028 | anchorKey: key,
|
42029 | anchorOffset: offset,
|
42030 | isBackward: key == focusKey ? offset > focusOffset : key == anchorKey ? isBackward : null
|
42031 | });
|
42032 | }
|
42033 |
|
42034 | /**
|
42035 | * Move the selection's focus point to a `key` and `offset`.
|
42036 | *
|
42037 | * @param {String} key
|
42038 | * @param {Number} offset
|
42039 | * @return {Selection}
|
42040 | */
|
42041 |
|
42042 | }, {
|
42043 | key: 'moveFocusTo',
|
42044 | value: function moveFocusTo(key, offset) {
|
42045 | var focusKey = this.focusKey,
|
42046 | anchorKey = this.anchorKey,
|
42047 | anchorOffset = this.anchorOffset,
|
42048 | isBackward = this.isBackward;
|
42049 |
|
42050 | return this.merge({
|
42051 | focusKey: key,
|
42052 | focusOffset: offset,
|
42053 | isBackward: key == anchorKey ? anchorOffset > offset : key == focusKey ? isBackward : null
|
42054 | });
|
42055 | }
|
42056 |
|
42057 | /**
|
42058 | * Move the selection to `anchorOffset`.
|
42059 | *
|
42060 | * @param {Number} anchorOffset
|
42061 | * @return {Selection}
|
42062 | */
|
42063 |
|
42064 | }, {
|
42065 | key: 'moveAnchorOffsetTo',
|
42066 | value: function moveAnchorOffsetTo(anchorOffset) {
|
42067 | return this.merge({
|
42068 | anchorOffset: anchorOffset,
|
42069 | isBackward: this.anchorKey == this.focusKey ? anchorOffset > this.focusOffset : this.isBackward
|
42070 | });
|
42071 | }
|
42072 |
|
42073 | /**
|
42074 | * Move the selection to `focusOffset`.
|
42075 | *
|
42076 | * @param {Number} focusOffset
|
42077 | * @return {Selection}
|
42078 | */
|
42079 |
|
42080 | }, {
|
42081 | key: 'moveFocusOffsetTo',
|
42082 | value: function moveFocusOffsetTo(focusOffset) {
|
42083 | return this.merge({
|
42084 | focusOffset: focusOffset,
|
42085 | isBackward: this.anchorKey == this.focusKey ? this.anchorOffset > focusOffset : this.isBackward
|
42086 | });
|
42087 | }
|
42088 |
|
42089 | /**
|
42090 | * Move the selection to `anchorOffset` and `focusOffset`.
|
42091 | *
|
42092 | * @param {Number} anchorOffset
|
42093 | * @param {Number} focusOffset (optional)
|
42094 | * @return {Selection}
|
42095 | */
|
42096 |
|
42097 | }, {
|
42098 | key: 'moveOffsetsTo',
|
42099 | value: function moveOffsetsTo(anchorOffset) {
|
42100 | var focusOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : anchorOffset;
|
42101 |
|
42102 | return this.moveAnchorOffsetTo(anchorOffset).moveFocusOffsetTo(focusOffset);
|
42103 | }
|
42104 |
|
42105 | /**
|
42106 | * Move the focus point to the anchor point.
|
42107 | *
|
42108 | * @return {Selection}
|
42109 | */
|
42110 |
|
42111 | }, {
|
42112 | key: 'moveToAnchor',
|
42113 | value: function moveToAnchor() {
|
42114 | return this.moveFocusTo(this.anchorKey, this.anchorOffset);
|
42115 | }
|
42116 |
|
42117 | /**
|
42118 | * Move the anchor point to the focus point.
|
42119 | *
|
42120 | * @return {Selection}
|
42121 | */
|
42122 |
|
42123 | }, {
|
42124 | key: 'moveToFocus',
|
42125 | value: function moveToFocus() {
|
42126 | return this.moveAnchorTo(this.focusKey, this.focusOffset);
|
42127 | }
|
42128 |
|
42129 | /**
|
42130 | * Move the selection's anchor point to the start of a `node`.
|
42131 | *
|
42132 | * @param {Node} node
|
42133 | * @return {Selection}
|
42134 | */
|
42135 |
|
42136 | }, {
|
42137 | key: 'moveAnchorToStartOf',
|
42138 | value: function moveAnchorToStartOf(node) {
|
42139 | node = getFirst(node);
|
42140 | return this.moveAnchorTo(node.key, 0);
|
42141 | }
|
42142 |
|
42143 | /**
|
42144 | * Move the selection's anchor point to the end of a `node`.
|
42145 | *
|
42146 | * @param {Node} node
|
42147 | * @return {Selection}
|
42148 | */
|
42149 |
|
42150 | }, {
|
42151 | key: 'moveAnchorToEndOf',
|
42152 | value: function moveAnchorToEndOf(node) {
|
42153 | node = getLast(node);
|
42154 | return this.moveAnchorTo(node.key, node.text.length);
|
42155 | }
|
42156 |
|
42157 | /**
|
42158 | * Move the selection's focus point to the start of a `node`.
|
42159 | *
|
42160 | * @param {Node} node
|
42161 | * @return {Selection}
|
42162 | */
|
42163 |
|
42164 | }, {
|
42165 | key: 'moveFocusToStartOf',
|
42166 | value: function moveFocusToStartOf(node) {
|
42167 | node = getFirst(node);
|
42168 | return this.moveFocusTo(node.key, 0);
|
42169 | }
|
42170 |
|
42171 | /**
|
42172 | * Move the selection's focus point to the end of a `node`.
|
42173 | *
|
42174 | * @param {Node} node
|
42175 | * @return {Selection}
|
42176 | */
|
42177 |
|
42178 | }, {
|
42179 | key: 'moveFocusToEndOf',
|
42180 | value: function moveFocusToEndOf(node) {
|
42181 | node = getLast(node);
|
42182 | return this.moveFocusTo(node.key, node.text.length);
|
42183 | }
|
42184 |
|
42185 | /**
|
42186 | * Move to the entire range of `start` and `end` nodes.
|
42187 | *
|
42188 | * @param {Node} start
|
42189 | * @param {Node} end (optional)
|
42190 | * @return {Selection}
|
42191 | */
|
42192 |
|
42193 | }, {
|
42194 | key: 'moveToRangeOf',
|
42195 | value: function moveToRangeOf(start) {
|
42196 | var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : start;
|
42197 |
|
42198 | return this.moveAnchorToStartOf(start).moveFocusToEndOf(end);
|
42199 | }
|
42200 |
|
42201 | /**
|
42202 | * Normalize the selection, relative to a `node`, ensuring that the anchor
|
42203 | * and focus nodes of the selection always refer to leaf text nodes.
|
42204 | *
|
42205 | * @param {Node} node
|
42206 | * @return {Selection}
|
42207 | */
|
42208 |
|
42209 | }, {
|
42210 | key: 'normalize',
|
42211 | value: function normalize(node) {
|
42212 | var selection = this;
|
42213 | var anchorKey = selection.anchorKey,
|
42214 | anchorOffset = selection.anchorOffset,
|
42215 | focusKey = selection.focusKey,
|
42216 | focusOffset = selection.focusOffset,
|
42217 | isBackward = selection.isBackward;
|
42218 |
|
42219 | // If the selection is unset, make sure it is properly zeroed out.
|
42220 |
|
42221 | if (anchorKey == null || focusKey == null) {
|
42222 | return selection.merge({
|
42223 | anchorKey: null,
|
42224 | anchorOffset: 0,
|
42225 | focusKey: null,
|
42226 | focusOffset: 0,
|
42227 | isBackward: false
|
42228 | });
|
42229 | }
|
42230 |
|
42231 | // Get the anchor and focus nodes.
|
42232 | var anchorNode = node.getDescendant(anchorKey);
|
42233 | var focusNode = node.getDescendant(focusKey);
|
42234 |
|
42235 | // If the selection is malformed, warn and zero it out.
|
42236 | if (!anchorNode || !focusNode) {
|
42237 | _logger2.default.warn('The selection was invalid and was reset. The selection in question was:', selection);
|
42238 | var first = node.getFirstText();
|
42239 | return selection.merge({
|
42240 | anchorKey: first ? first.key : null,
|
42241 | anchorOffset: 0,
|
42242 | focusKey: first ? first.key : null,
|
42243 | focusOffset: 0,
|
42244 | isBackward: false
|
42245 | });
|
42246 | }
|
42247 |
|
42248 | // If the anchor node isn't a text node, match it to one.
|
42249 | if (anchorNode.kind != 'text') {
|
42250 | _logger2.default.warn('The selection anchor was set to a Node that is not a Text node. This should not happen and can degrade performance. The node in question was:', anchorNode);
|
42251 | var anchorText = anchorNode.getTextAtOffset(anchorOffset);
|
42252 | var offset = anchorNode.getOffset(anchorText.key);
|
42253 | anchorOffset = anchorOffset - offset;
|
42254 | anchorNode = anchorText;
|
42255 | }
|
42256 |
|
42257 | // If the focus node isn't a text node, match it to one.
|
42258 | if (focusNode.kind != 'text') {
|
42259 | _logger2.default.warn('The selection focus was set to a Node that is not a Text node. This should not happen and can degrade performance. The node in question was:', focusNode);
|
42260 | var focusText = focusNode.getTextAtOffset(focusOffset);
|
42261 | var _offset = focusNode.getOffset(focusText.key);
|
42262 | focusOffset = focusOffset - _offset;
|
42263 | focusNode = focusText;
|
42264 | }
|
42265 |
|
42266 | // If `isBackward` is not set, derive it.
|
42267 | if (isBackward == null) {
|
42268 | if (anchorNode.key === focusNode.key) {
|
42269 | isBackward = anchorOffset > focusOffset;
|
42270 | } else {
|
42271 | isBackward = !node.areDescendantsSorted(anchorNode.key, focusNode.key);
|
42272 | }
|
42273 | }
|
42274 |
|
42275 | // Merge in any updated properties.
|
42276 | return selection.merge({
|
42277 | anchorKey: anchorNode.key,
|
42278 | anchorOffset: anchorOffset,
|
42279 | focusKey: focusNode.key,
|
42280 | focusOffset: focusOffset,
|
42281 | isBackward: isBackward
|
42282 | });
|
42283 | }
|
42284 |
|
42285 | /**
|
42286 | * Return a JSON representation of the selection.
|
42287 | *
|
42288 | * @return {Object}
|
42289 | */
|
42290 |
|
42291 | }, {
|
42292 | key: 'toJSON',
|
42293 | value: function toJSON() {
|
42294 | var object = {
|
42295 | anchorKey: this.anchorKey,
|
42296 | anchorOffset: this.anchorOffset,
|
42297 | focusKey: this.focusKey,
|
42298 | focusOffset: this.focusOffset,
|
42299 | isBackward: this.isBackward,
|
42300 | isFocused: this.isFocused,
|
42301 | kind: this.kind,
|
42302 | marks: this.marks == null ? null : this.marks.toArray().map(function (m) {
|
42303 | return m.toJSON();
|
42304 | })
|
42305 | };
|
42306 |
|
42307 | return object;
|
42308 | }
|
42309 |
|
42310 | /**
|
42311 | * Alias `toJS`.
|
42312 | */
|
42313 |
|
42314 | }, {
|
42315 | key: 'toJS',
|
42316 | value: function toJS() {
|
42317 | return this.toJSON();
|
42318 | }
|
42319 |
|
42320 | /**
|
42321 | * Unset the selection.
|
42322 | *
|
42323 | * @return {Selection}
|
42324 | */
|
42325 |
|
42326 | }, {
|
42327 | key: 'unset',
|
42328 | value: function unset() {
|
42329 | _logger2.default.deprecate('0.17.0', 'The `Selection.unset` method is deprecated, please switch to using `Selection.deselect` instead.');
|
42330 | return this.deselect();
|
42331 | }
|
42332 |
|
42333 | /**
|
42334 | * Move the selection forward `n` characters.
|
42335 | *
|
42336 | * @param {Number} n (optional)
|
42337 | * @return {Selection}
|
42338 | */
|
42339 |
|
42340 | }, {
|
42341 | key: 'moveForward',
|
42342 | value: function moveForward() {
|
42343 | var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
42344 |
|
42345 | _logger2.default.deprecate('0.17.0', 'The `Selection.moveForward(n)` method is deprecated, please switch to using `Selection.move(n)` instead.');
|
42346 | return this.move(n);
|
42347 | }
|
42348 |
|
42349 | /**
|
42350 | * Move the selection backward `n` characters.
|
42351 | *
|
42352 | * @param {Number} n (optional)
|
42353 | * @return {Selection}
|
42354 | */
|
42355 |
|
42356 | }, {
|
42357 | key: 'moveBackward',
|
42358 | value: function moveBackward() {
|
42359 | var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
42360 |
|
42361 | _logger2.default.deprecate('0.17.0', 'The `Selection.moveBackward(n)` method is deprecated, please switch to using `Selection.move(-n)` (with a negative number) instead.');
|
42362 | return this.move(0 - n);
|
42363 | }
|
42364 |
|
42365 | /**
|
42366 | * Move the anchor offset `n` characters.
|
42367 | *
|
42368 | * @param {Number} n (optional)
|
42369 | * @return {Selection}
|
42370 | */
|
42371 |
|
42372 | }, {
|
42373 | key: 'moveAnchorOffset',
|
42374 | value: function moveAnchorOffset() {
|
42375 | var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
42376 |
|
42377 | _logger2.default.deprecate('0.17.0', 'The `Selection.moveAnchorOffset(n)` method is deprecated, please switch to using `Selection.moveAnchor(n)` instead.');
|
42378 | return this.moveAnchor(n);
|
42379 | }
|
42380 |
|
42381 | /**
|
42382 | * Move the focus offset `n` characters.
|
42383 | *
|
42384 | * @param {Number} n (optional)
|
42385 | * @return {Selection}
|
42386 | */
|
42387 |
|
42388 | }, {
|
42389 | key: 'moveFocusOffset',
|
42390 | value: function moveFocusOffset() {
|
42391 | var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
42392 |
|
42393 | _logger2.default.deprecate('0.17.0', 'The `Selection.moveFocusOffset(n)` method is deprecated, please switch to using `Selection.moveFocus(n)` instead.');
|
42394 | return this.moveFocus(n);
|
42395 | }
|
42396 |
|
42397 | /**
|
42398 | * Move the start offset `n` characters.
|
42399 | *
|
42400 | * @param {Number} n (optional)
|
42401 | * @return {Selection}
|
42402 | */
|
42403 |
|
42404 | }, {
|
42405 | key: 'moveStartOffset',
|
42406 | value: function moveStartOffset() {
|
42407 | var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
42408 |
|
42409 | _logger2.default.deprecate('0.17.0', 'The `Selection.moveStartOffset(n)` method is deprecated, please switch to using `Selection.moveStart(n)` instead.');
|
42410 | return this.moveStart(n);
|
42411 | }
|
42412 |
|
42413 | /**
|
42414 | * Move the focus offset `n` characters.
|
42415 | *
|
42416 | * @param {Number} n (optional)
|
42417 | * @return {Selection}
|
42418 | */
|
42419 |
|
42420 | }, {
|
42421 | key: 'moveEndOffset',
|
42422 | value: function moveEndOffset() {
|
42423 | var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
42424 |
|
42425 | _logger2.default.deprecate('0.17.0', 'The `Selection.moveEndOffset(n)` method is deprecated, please switch to using `Selection.moveEnd(n)` instead.');
|
42426 | return this.moveEnd(n);
|
42427 | }
|
42428 |
|
42429 | /**
|
42430 | * Extend the focus point forward `n` characters.
|
42431 | *
|
42432 | * @param {Number} n (optional)
|
42433 | * @return {Selection}
|
42434 | */
|
42435 |
|
42436 | }, {
|
42437 | key: 'extendForward',
|
42438 | value: function extendForward() {
|
42439 | var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
42440 |
|
42441 | _logger2.default.deprecate('0.17.0', 'The `Selection.extendForward(n)` method is deprecated, please switch to using `Selection.extend(n)` instead.');
|
42442 | return this.extend(n);
|
42443 | }
|
42444 |
|
42445 | /**
|
42446 | * Extend the focus point backward `n` characters.
|
42447 | *
|
42448 | * @param {Number} n (optional)
|
42449 | * @return {Selection}
|
42450 | */
|
42451 |
|
42452 | }, {
|
42453 | key: 'extendBackward',
|
42454 | value: function extendBackward() {
|
42455 | var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
42456 |
|
42457 | _logger2.default.deprecate('0.17.0', 'The `Selection.extendBackward(n)` method is deprecated, please switch to using `Selection.extend(-n)` (with a negative number) instead.');
|
42458 | return this.extend(0 - n);
|
42459 | }
|
42460 |
|
42461 | /**
|
42462 | * Move the selection to `anchorOffset` and `focusOffset`.
|
42463 | *
|
42464 | * @param {Number} anchorOffset
|
42465 | * @param {Number} focusOffset (optional)
|
42466 | * @return {Selection}
|
42467 | */
|
42468 |
|
42469 | }, {
|
42470 | key: 'moveToOffsets',
|
42471 | value: function moveToOffsets(anchorOffset) {
|
42472 | var focusOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : anchorOffset;
|
42473 |
|
42474 | _logger2.default.deprecate('0.17.0', 'The `Selection.moveToOffsets` method is deprecated, please switch to using `Selection.moveOffsetsTo` instead.');
|
42475 | return this.moveOffsetsTo(anchorOffset, focusOffset);
|
42476 | }
|
42477 | }, {
|
42478 | key: 'kind',
|
42479 |
|
42480 |
|
42481 | /**
|
42482 | * Get the kind.
|
42483 | *
|
42484 | * @return {String}
|
42485 | */
|
42486 |
|
42487 | get: function get() {
|
42488 | return 'selection';
|
42489 | }
|
42490 |
|
42491 | /**
|
42492 | * Check whether the selection is blurred.
|
42493 | *
|
42494 | * @return {Boolean}
|
42495 | */
|
42496 |
|
42497 | }, {
|
42498 | key: 'isBlurred',
|
42499 | get: function get() {
|
42500 | return !this.isFocused;
|
42501 | }
|
42502 |
|
42503 | /**
|
42504 | * Check whether the selection is collapsed.
|
42505 | *
|
42506 | * @return {Boolean}
|
42507 | */
|
42508 |
|
42509 | }, {
|
42510 | key: 'isCollapsed',
|
42511 | get: function get() {
|
42512 | return this.anchorKey == this.focusKey && this.anchorOffset == this.focusOffset;
|
42513 | }
|
42514 |
|
42515 | /**
|
42516 | * Check whether the selection is expanded.
|
42517 | *
|
42518 | * @return {Boolean}
|
42519 | */
|
42520 |
|
42521 | }, {
|
42522 | key: 'isExpanded',
|
42523 | get: function get() {
|
42524 | return !this.isCollapsed;
|
42525 | }
|
42526 |
|
42527 | /**
|
42528 | * Check whether the selection is forward.
|
42529 | *
|
42530 | * @return {Boolean}
|
42531 | */
|
42532 |
|
42533 | }, {
|
42534 | key: 'isForward',
|
42535 | get: function get() {
|
42536 | return this.isBackward == null ? null : !this.isBackward;
|
42537 | }
|
42538 |
|
42539 | /**
|
42540 | * Check whether the selection's keys are set.
|
42541 | *
|
42542 | * @return {Boolean}
|
42543 | */
|
42544 |
|
42545 | }, {
|
42546 | key: 'isSet',
|
42547 | get: function get() {
|
42548 | return this.anchorKey != null && this.focusKey != null;
|
42549 | }
|
42550 |
|
42551 | /**
|
42552 | * Check whether the selection's keys are not set.
|
42553 | *
|
42554 | * @return {Boolean}
|
42555 | */
|
42556 |
|
42557 | }, {
|
42558 | key: 'isUnset',
|
42559 | get: function get() {
|
42560 | return !this.isSet;
|
42561 | }
|
42562 |
|
42563 | /**
|
42564 | * Get the start key.
|
42565 | *
|
42566 | * @return {String}
|
42567 | */
|
42568 |
|
42569 | }, {
|
42570 | key: 'startKey',
|
42571 | get: function get() {
|
42572 | return this.isBackward ? this.focusKey : this.anchorKey;
|
42573 | }
|
42574 |
|
42575 | /**
|
42576 | * Get the start offset.
|
42577 | *
|
42578 | * @return {String}
|
42579 | */
|
42580 |
|
42581 | }, {
|
42582 | key: 'startOffset',
|
42583 | get: function get() {
|
42584 | return this.isBackward ? this.focusOffset : this.anchorOffset;
|
42585 | }
|
42586 |
|
42587 | /**
|
42588 | * Get the end key.
|
42589 | *
|
42590 | * @return {String}
|
42591 | */
|
42592 |
|
42593 | }, {
|
42594 | key: 'endKey',
|
42595 | get: function get() {
|
42596 | return this.isBackward ? this.anchorKey : this.focusKey;
|
42597 | }
|
42598 |
|
42599 | /**
|
42600 | * Get the end offset.
|
42601 | *
|
42602 | * @return {String}
|
42603 | */
|
42604 |
|
42605 | }, {
|
42606 | key: 'endOffset',
|
42607 | get: function get() {
|
42608 | return this.isBackward ? this.anchorOffset : this.focusOffset;
|
42609 | }
|
42610 | }], [{
|
42611 | key: 'create',
|
42612 |
|
42613 |
|
42614 | /**
|
42615 | * Create a new `Selection` with `attrs`.
|
42616 | *
|
42617 | * @param {Object|Selection} attrs
|
42618 | * @return {Selection}
|
42619 | */
|
42620 |
|
42621 | value: function create() {
|
42622 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
42623 |
|
42624 | if (Selection.isSelection(attrs)) {
|
42625 | return attrs;
|
42626 | }
|
42627 |
|
42628 | if ((0, _isPlainObject2.default)(attrs)) {
|
42629 | return Selection.fromJSON(attrs);
|
42630 | }
|
42631 |
|
42632 | throw new Error('`Selection.create` only accepts objects or selections, but you passed it: ' + attrs);
|
42633 | }
|
42634 |
|
42635 | /**
|
42636 | * Create a dictionary of settable selection properties from `attrs`.
|
42637 | *
|
42638 | * @param {Object|String|Selection} attrs
|
42639 | * @return {Object}
|
42640 | */
|
42641 |
|
42642 | }, {
|
42643 | key: 'createProperties',
|
42644 | value: function createProperties() {
|
42645 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
42646 |
|
42647 | if (Selection.isSelection(attrs)) {
|
42648 | return {
|
42649 | anchorKey: attrs.anchorKey,
|
42650 | anchorOffset: attrs.anchorOffset,
|
42651 | focusKey: attrs.focusKey,
|
42652 | focusOffset: attrs.focusOffset,
|
42653 | isBackward: attrs.isBackward,
|
42654 | isFocused: attrs.isFocused,
|
42655 | marks: attrs.marks
|
42656 | };
|
42657 | }
|
42658 |
|
42659 | if ((0, _isPlainObject2.default)(attrs)) {
|
42660 | var props = {};
|
42661 | if ('anchorKey' in attrs) props.anchorKey = attrs.anchorKey;
|
42662 | if ('anchorOffset' in attrs) props.anchorOffset = attrs.anchorOffset;
|
42663 | if ('focusKey' in attrs) props.focusKey = attrs.focusKey;
|
42664 | if ('focusOffset' in attrs) props.focusOffset = attrs.focusOffset;
|
42665 | if ('isBackward' in attrs) props.isBackward = attrs.isBackward;
|
42666 | if ('isFocused' in attrs) props.isFocused = attrs.isFocused;
|
42667 | if ('marks' in attrs) props.marks = attrs.marks;
|
42668 | return props;
|
42669 | }
|
42670 |
|
42671 | throw new Error('`Selection.createProperties` only accepts objects or selections, but you passed it: ' + attrs);
|
42672 | }
|
42673 |
|
42674 | /**
|
42675 | * Create a `Selection` from a JSON `object`.
|
42676 | *
|
42677 | * @param {Object} object
|
42678 | * @return {Selection}
|
42679 | */
|
42680 |
|
42681 | }, {
|
42682 | key: 'fromJSON',
|
42683 | value: function fromJSON(object) {
|
42684 | var _object$anchorKey = object.anchorKey,
|
42685 | anchorKey = _object$anchorKey === undefined ? null : _object$anchorKey,
|
42686 | _object$anchorOffset = object.anchorOffset,
|
42687 | anchorOffset = _object$anchorOffset === undefined ? 0 : _object$anchorOffset,
|
42688 | _object$focusKey = object.focusKey,
|
42689 | focusKey = _object$focusKey === undefined ? null : _object$focusKey,
|
42690 | _object$focusOffset = object.focusOffset,
|
42691 | focusOffset = _object$focusOffset === undefined ? 0 : _object$focusOffset,
|
42692 | _object$isBackward = object.isBackward,
|
42693 | isBackward = _object$isBackward === undefined ? null : _object$isBackward,
|
42694 | _object$isFocused = object.isFocused,
|
42695 | isFocused = _object$isFocused === undefined ? false : _object$isFocused,
|
42696 | _object$marks = object.marks,
|
42697 | marks = _object$marks === undefined ? null : _object$marks;
|
42698 |
|
42699 |
|
42700 | var selection = new Selection({
|
42701 | anchorKey: anchorKey,
|
42702 | anchorOffset: anchorOffset,
|
42703 | focusKey: focusKey,
|
42704 | focusOffset: focusOffset,
|
42705 | isBackward: isBackward,
|
42706 | isFocused: isFocused,
|
42707 | marks: marks
|
42708 | });
|
42709 |
|
42710 | return selection;
|
42711 | }
|
42712 |
|
42713 | /**
|
42714 | * Alias `fromJS`.
|
42715 | */
|
42716 |
|
42717 | }, {
|
42718 | key: 'isSelection',
|
42719 |
|
42720 |
|
42721 | /**
|
42722 | * Check if a `value` is a `Selection`.
|
42723 | *
|
42724 | * @param {Any} value
|
42725 | * @return {Boolean}
|
42726 | */
|
42727 |
|
42728 | value: function isSelection(value) {
|
42729 | return !!(value && value[_modelTypes2.default.SELECTION]);
|
42730 | }
|
42731 | }]);
|
42732 |
|
42733 | return Selection;
|
42734 | }((0, _immutable.Record)(DEFAULTS));
|
42735 |
|
42736 | /**
|
42737 | * Attach a pseudo-symbol for type checking.
|
42738 | */
|
42739 |
|
42740 | Selection.fromJS = Selection.fromJSON;
|
42741 | Selection.prototype[_modelTypes2.default.SELECTION] = true;
|
42742 |
|
42743 | /**
|
42744 | * Mix in some "move" convenience methods.
|
42745 | */
|
42746 |
|
42747 | var MOVE_METHODS = [['move', ''], ['move', 'To'], ['move', 'ToStartOf'], ['move', 'ToEndOf']];
|
42748 |
|
42749 | MOVE_METHODS.forEach(function (_ref) {
|
42750 | var _ref2 = _slicedToArray(_ref, 2),
|
42751 | p = _ref2[0],
|
42752 | s = _ref2[1];
|
42753 |
|
42754 | Selection.prototype['' + p + s] = function () {
|
42755 | var _ref3;
|
42756 |
|
42757 | return (_ref3 = this[p + 'Anchor' + s].apply(this, arguments))[p + 'Focus' + s].apply(_ref3, arguments);
|
42758 | };
|
42759 | });
|
42760 |
|
42761 | /**
|
42762 | * Mix in the "start", "end" and "edge" convenience methods.
|
42763 | */
|
42764 |
|
42765 | var EDGE_METHODS = [['has', 'AtStartOf', true], ['has', 'AtEndOf', true], ['has', 'Between', true], ['has', 'In', true], ['collapseTo', ''], ['move', ''], ['moveTo', ''], ['move', 'To'], ['move', 'OffsetTo']];
|
42766 |
|
42767 | EDGE_METHODS.forEach(function (_ref4) {
|
42768 | var _ref5 = _slicedToArray(_ref4, 3),
|
42769 | p = _ref5[0],
|
42770 | s = _ref5[1],
|
42771 | hasEdge = _ref5[2];
|
42772 |
|
42773 | var anchor = p + 'Anchor' + s;
|
42774 | var focus = p + 'Focus' + s;
|
42775 |
|
42776 | Selection.prototype[p + 'Start' + s] = function () {
|
42777 | return this.isBackward ? this[focus].apply(this, arguments) : this[anchor].apply(this, arguments);
|
42778 | };
|
42779 |
|
42780 | Selection.prototype[p + 'End' + s] = function () {
|
42781 | return this.isBackward ? this[anchor].apply(this, arguments) : this[focus].apply(this, arguments);
|
42782 | };
|
42783 |
|
42784 | if (hasEdge) {
|
42785 | Selection.prototype[p + 'Edge' + s] = function () {
|
42786 | return this[anchor].apply(this, arguments) || this[focus].apply(this, arguments);
|
42787 | };
|
42788 | }
|
42789 | });
|
42790 |
|
42791 | /**
|
42792 | * Mix in some aliases for convenience / parallelism with the browser APIs.
|
42793 | */
|
42794 |
|
42795 | var ALIAS_METHODS = [['collapseTo', 'moveTo'], ['collapseToAnchor', 'moveToAnchor'], ['collapseToFocus', 'moveToFocus'], ['collapseToStart', 'moveToStart'], ['collapseToEnd', 'moveToEnd'], ['collapseToStartOf', 'moveToStartOf'], ['collapseToEndOf', 'moveToEndOf'], ['extend', 'moveFocus'], ['extendTo', 'moveFocusTo'], ['extendToStartOf', 'moveFocusToStartOf'], ['extendToEndOf', 'moveFocusToEndOf']];
|
42796 |
|
42797 | ALIAS_METHODS.forEach(function (_ref6) {
|
42798 | var _ref7 = _slicedToArray(_ref6, 2),
|
42799 | alias = _ref7[0],
|
42800 | method = _ref7[1];
|
42801 |
|
42802 | Selection.prototype[alias] = function () {
|
42803 | return this[method].apply(this, arguments);
|
42804 | };
|
42805 | });
|
42806 |
|
42807 | /**
|
42808 | * Get the first text of a `node`.
|
42809 | *
|
42810 | * @param {Node} node
|
42811 | * @return {Text}
|
42812 | */
|
42813 |
|
42814 | function getFirst(node) {
|
42815 | return node.kind == 'text' ? node : node.getFirstText();
|
42816 | }
|
42817 |
|
42818 | /**
|
42819 | * Get the last text of a `node`.
|
42820 | *
|
42821 | * @param {Node} node
|
42822 | * @return {Text}
|
42823 | */
|
42824 |
|
42825 | function getLast(node) {
|
42826 | return node.kind == 'text' ? node : node.getLastText();
|
42827 | }
|
42828 |
|
42829 | /**
|
42830 | * Export.
|
42831 | *
|
42832 | * @type {Selection}
|
42833 | */
|
42834 |
|
42835 | exports.default = Selection;
|
42836 | },{"../constants/model-types":328,"../utils/logger":366,"immutable":135,"is-plain-object":139}],343:[function(require,module,exports){
|
42837 | 'use strict';
|
42838 |
|
42839 | Object.defineProperty(exports, "__esModule", {
|
42840 | value: true
|
42841 | });
|
42842 |
|
42843 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
42844 |
|
42845 | var _modelTypes = require('../constants/model-types');
|
42846 |
|
42847 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
42848 |
|
42849 | var _core = require('../plugins/core');
|
42850 |
|
42851 | var _core2 = _interopRequireDefault(_core);
|
42852 |
|
42853 | var _debug = require('debug');
|
42854 |
|
42855 | var _debug2 = _interopRequireDefault(_debug);
|
42856 |
|
42857 | var _schema2 = require('./schema');
|
42858 |
|
42859 | var _schema3 = _interopRequireDefault(_schema2);
|
42860 |
|
42861 | var _immutable = require('immutable');
|
42862 |
|
42863 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
42864 |
|
42865 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
42866 |
|
42867 | function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
42868 |
|
42869 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
42870 |
|
42871 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
42872 |
|
42873 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
42874 |
|
42875 | /**
|
42876 | * Debug.
|
42877 | *
|
42878 | * @type {Function}
|
42879 | */
|
42880 |
|
42881 | var debug = (0, _debug2.default)('slate:stack');
|
42882 |
|
42883 | /**
|
42884 | * Methods that are triggered on events and can change the state.
|
42885 | *
|
42886 | * @type {Array}
|
42887 | */
|
42888 |
|
42889 | var METHODS = ['onBeforeInput', 'onBeforeChange', 'onBlur', 'onCopy', 'onCut', 'onDrop', 'onFocus', 'onKeyDown', 'onKeyUp', 'onPaste', 'onSelect', 'onChange'];
|
42890 |
|
42891 | /**
|
42892 | * Default properties.
|
42893 | *
|
42894 | * @type {Object}
|
42895 | */
|
42896 |
|
42897 | var DEFAULTS = {
|
42898 | plugins: [],
|
42899 | schema: new _schema3.default()
|
42900 | };
|
42901 |
|
42902 | /**
|
42903 | * Stack.
|
42904 | *
|
42905 | * @type {Stack}
|
42906 | */
|
42907 |
|
42908 | var Stack = function (_Record) {
|
42909 | _inherits(Stack, _Record);
|
42910 |
|
42911 | function Stack() {
|
42912 | _classCallCheck(this, Stack);
|
42913 |
|
42914 | return _possibleConstructorReturn(this, (Stack.__proto__ || Object.getPrototypeOf(Stack)).apply(this, arguments));
|
42915 | }
|
42916 |
|
42917 | _createClass(Stack, [{
|
42918 | key: 'render',
|
42919 |
|
42920 |
|
42921 | /**
|
42922 | * Invoke `render` on all of the plugins in reverse, building up a tree of
|
42923 | * higher-order components.
|
42924 | *
|
42925 | * @param {State} state
|
42926 | * @param {Editor} editor
|
42927 | * @param {Object} children
|
42928 | * @param {Object} props
|
42929 | * @return {Component}
|
42930 | */
|
42931 |
|
42932 | value: function render(state, editor, props) {
|
42933 | debug('render');
|
42934 | var plugins = this.plugins.slice().reverse();
|
42935 | var children = void 0;
|
42936 |
|
42937 | for (var i = 0; i < plugins.length; i++) {
|
42938 | var plugin = plugins[i];
|
42939 | if (!plugin.render) continue;
|
42940 | children = plugin.render(props, state, editor);
|
42941 | props.children = children;
|
42942 | }
|
42943 |
|
42944 | return children;
|
42945 | }
|
42946 |
|
42947 | /**
|
42948 | * Invoke `renderPortal` on all of the plugins, building a list of portals.
|
42949 | *
|
42950 | * @param {State} state
|
42951 | * @param {Editor} editor
|
42952 | * @return {Array}
|
42953 | */
|
42954 |
|
42955 | }, {
|
42956 | key: 'renderPortal',
|
42957 | value: function renderPortal(state, editor) {
|
42958 | debug('renderPortal');
|
42959 | var portals = [];
|
42960 |
|
42961 | for (var i = 0; i < this.plugins.length; i++) {
|
42962 | var plugin = this.plugins[i];
|
42963 | if (!plugin.renderPortal) continue;
|
42964 | var portal = plugin.renderPortal(state, editor);
|
42965 | if (portal) portals.push(portal);
|
42966 | }
|
42967 |
|
42968 | return portals;
|
42969 | }
|
42970 | }, {
|
42971 | key: 'kind',
|
42972 |
|
42973 |
|
42974 | /**
|
42975 | * Get the kind.
|
42976 | *
|
42977 | * @return {String}
|
42978 | */
|
42979 |
|
42980 | get: function get() {
|
42981 | return 'stack';
|
42982 | }
|
42983 | }], [{
|
42984 | key: 'create',
|
42985 |
|
42986 |
|
42987 | /**
|
42988 | * Constructor.
|
42989 | *
|
42990 | * @param {Object} attrs
|
42991 | * @property {Array} plugins
|
42992 | * @property {Schema|Object} schema
|
42993 | * @property {Function} ...handlers
|
42994 | */
|
42995 |
|
42996 | value: function create() {
|
42997 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
42998 |
|
42999 | var plugins = resolvePlugins(attrs);
|
43000 | var schema = resolveSchema(plugins);
|
43001 | var stack = new Stack({ plugins: plugins, schema: schema });
|
43002 | return stack;
|
43003 | }
|
43004 |
|
43005 | /**
|
43006 | * Check if a `value` is a `Stack`.
|
43007 | *
|
43008 | * @param {Any} value
|
43009 | * @return {Boolean}
|
43010 | */
|
43011 |
|
43012 | }, {
|
43013 | key: 'isStack',
|
43014 | value: function isStack(value) {
|
43015 | return !!(value && value[_modelTypes2.default.STACK]);
|
43016 | }
|
43017 | }]);
|
43018 |
|
43019 | return Stack;
|
43020 | }((0, _immutable.Record)(DEFAULTS));
|
43021 |
|
43022 | /**
|
43023 | * Attach a pseudo-symbol for type checking.
|
43024 | */
|
43025 |
|
43026 | Stack.prototype[_modelTypes2.default.STACK] = true;
|
43027 |
|
43028 | /**
|
43029 | * Mix in the stack methods.
|
43030 | *
|
43031 | * @param {Change} change
|
43032 | * @param {Editor} editor
|
43033 | * @param {Mixed} ...args
|
43034 | */
|
43035 |
|
43036 | var _loop = function _loop(i) {
|
43037 | var method = METHODS[i];
|
43038 | Stack.prototype[method] = function (change, editor) {
|
43039 | debug(method);
|
43040 |
|
43041 | for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
43042 | args[_key - 2] = arguments[_key];
|
43043 | }
|
43044 |
|
43045 | for (var k = 0; k < this.plugins.length; k++) {
|
43046 | var plugin = this.plugins[k];
|
43047 | if (!plugin[method]) continue;
|
43048 | var next = plugin[method].apply(plugin, args.concat([change, editor]));
|
43049 | if (next != null) break;
|
43050 | }
|
43051 | };
|
43052 | };
|
43053 |
|
43054 | for (var i = 0; i < METHODS.length; i++) {
|
43055 | _loop(i);
|
43056 | }
|
43057 |
|
43058 | /**
|
43059 | * Resolve a schema from a set of `plugins`.
|
43060 | *
|
43061 | * @param {Array} plugins
|
43062 | * @return {Schema}
|
43063 | */
|
43064 |
|
43065 | function resolveSchema(plugins) {
|
43066 | var rules = [];
|
43067 |
|
43068 | for (var i = 0; i < plugins.length; i++) {
|
43069 | var plugin = plugins[i];
|
43070 | if (plugin.schema == null) continue;
|
43071 | var _schema = _schema3.default.create(plugin.schema);
|
43072 | rules = rules.concat(_schema.rules);
|
43073 | }
|
43074 |
|
43075 | var schema = _schema3.default.create({ rules: rules });
|
43076 | return schema;
|
43077 | }
|
43078 |
|
43079 | /**
|
43080 | * Resolve an array of plugins from `properties`.
|
43081 | *
|
43082 | * In addition to the plugins provided in `properties.plugins`, this will
|
43083 | * create two other plugins:
|
43084 | *
|
43085 | * - A plugin made from the top-level `properties` themselves, which are
|
43086 | * placed at the beginning of the stack. That way, you can add a `onKeyDown`
|
43087 | * handler, and it will override all of the existing plugins.
|
43088 | *
|
43089 | * - A "core" functionality plugin that handles the most basic events in Slate,
|
43090 | * like deleting characters, splitting blocks, etc.
|
43091 | *
|
43092 | * @param {Object} props
|
43093 | * @return {Array}
|
43094 | */
|
43095 |
|
43096 | function resolvePlugins(props) {
|
43097 | var _props$plugins = props.plugins,
|
43098 | plugins = _props$plugins === undefined ? [] : _props$plugins,
|
43099 | overridePlugin = _objectWithoutProperties(props, ['plugins']);
|
43100 |
|
43101 | var corePlugin = (0, _core2.default)(props);
|
43102 | return [overridePlugin].concat(_toConsumableArray(plugins), [corePlugin]);
|
43103 | }
|
43104 |
|
43105 | /**
|
43106 | * Export.
|
43107 | *
|
43108 | * @type {Stack}
|
43109 | */
|
43110 |
|
43111 | exports.default = Stack;
|
43112 | },{"../constants/model-types":328,"../plugins/core":349,"./schema":341,"debug":375,"immutable":135}],344:[function(require,module,exports){
|
43113 | 'use strict';
|
43114 |
|
43115 | Object.defineProperty(exports, "__esModule", {
|
43116 | value: true
|
43117 | });
|
43118 |
|
43119 | 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; };
|
43120 |
|
43121 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
43122 |
|
43123 | var _modelTypes = require('../constants/model-types');
|
43124 |
|
43125 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
43126 |
|
43127 | var _core = require('../schemas/core');
|
43128 |
|
43129 | var _core2 = _interopRequireDefault(_core);
|
43130 |
|
43131 | var _change = require('./change');
|
43132 |
|
43133 | var _change2 = _interopRequireDefault(_change);
|
43134 |
|
43135 | var _document = require('./document');
|
43136 |
|
43137 | var _document2 = _interopRequireDefault(_document);
|
43138 |
|
43139 | var _history = require('./history');
|
43140 |
|
43141 | var _history2 = _interopRequireDefault(_history);
|
43142 |
|
43143 | var _selection = require('./selection');
|
43144 |
|
43145 | var _selection2 = _interopRequireDefault(_selection);
|
43146 |
|
43147 | var _isPlainObject = require('is-plain-object');
|
43148 |
|
43149 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
43150 |
|
43151 | var _logger = require('../utils/logger');
|
43152 |
|
43153 | var _logger2 = _interopRequireDefault(_logger);
|
43154 |
|
43155 | var _immutable = require('immutable');
|
43156 |
|
43157 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
43158 |
|
43159 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
43160 |
|
43161 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
43162 |
|
43163 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
43164 |
|
43165 | /**
|
43166 | * Default properties.
|
43167 | *
|
43168 | * @type {Object}
|
43169 | */
|
43170 |
|
43171 | var DEFAULTS = {
|
43172 | document: _document2.default.create(),
|
43173 | selection: _selection2.default.create(),
|
43174 | history: _history2.default.create(),
|
43175 | data: new _immutable.Map()
|
43176 | };
|
43177 |
|
43178 | /**
|
43179 | * State.
|
43180 | *
|
43181 | * @type {State}
|
43182 | */
|
43183 |
|
43184 | var State = function (_Record) {
|
43185 | _inherits(State, _Record);
|
43186 |
|
43187 | function State() {
|
43188 | _classCallCheck(this, State);
|
43189 |
|
43190 | return _possibleConstructorReturn(this, (State.__proto__ || Object.getPrototypeOf(State)).apply(this, arguments));
|
43191 | }
|
43192 |
|
43193 | _createClass(State, [{
|
43194 | key: 'change',
|
43195 |
|
43196 |
|
43197 | /**
|
43198 | * Create a new `Change` with the current state as a starting point.
|
43199 | *
|
43200 | * @param {Object} attrs
|
43201 | * @return {Change}
|
43202 | */
|
43203 |
|
43204 | value: function change() {
|
43205 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
43206 |
|
43207 | return new _change2.default(_extends({}, attrs, { state: this }));
|
43208 | }
|
43209 |
|
43210 | /**
|
43211 | * Deprecated.
|
43212 | *
|
43213 | * @return {Change}
|
43214 | */
|
43215 |
|
43216 | }, {
|
43217 | key: 'transform',
|
43218 | value: function transform() {
|
43219 | _logger2.default.deprecate('0.22.0', 'The `state.transform()` method has been deprecated in favor of `state.change()`.');
|
43220 | return this.change.apply(this, arguments);
|
43221 | }
|
43222 |
|
43223 | /**
|
43224 | * Return a JSON representation of the state.
|
43225 | *
|
43226 | * @param {Object} options
|
43227 | * @return {Object}
|
43228 | */
|
43229 |
|
43230 | }, {
|
43231 | key: 'toJSON',
|
43232 | value: function toJSON() {
|
43233 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
43234 |
|
43235 | var object = {
|
43236 | data: this.data.toJSON(),
|
43237 | document: this.document.toJSON(options),
|
43238 | kind: this.kind,
|
43239 | history: this.history.toJSON(),
|
43240 | selection: this.selection.toJSON()
|
43241 | };
|
43242 |
|
43243 | if (!options.preserveHistory) {
|
43244 | delete object.history;
|
43245 | }
|
43246 |
|
43247 | if (!options.preserveSelection) {
|
43248 | delete object.selection;
|
43249 | }
|
43250 |
|
43251 | if (!options.preserveStateData) {
|
43252 | delete object.data;
|
43253 | }
|
43254 |
|
43255 | if (options.preserveSelection && !options.preserveKeys) {
|
43256 | var document = this.document,
|
43257 | selection = this.selection;
|
43258 |
|
43259 | object.selection.anchorPath = document.getPath(selection.anchorKey);
|
43260 | object.selection.focusPath = document.getPath(selection.focusKey);
|
43261 | delete object.selection.anchorKey;
|
43262 | delete object.selection.focusKey;
|
43263 | }
|
43264 |
|
43265 | return object;
|
43266 | }
|
43267 |
|
43268 | /**
|
43269 | * Alias `toJS`.
|
43270 | */
|
43271 |
|
43272 | }, {
|
43273 | key: 'toJS',
|
43274 | value: function toJS(options) {
|
43275 | return this.toJSON(options);
|
43276 | }
|
43277 | }, {
|
43278 | key: 'kind',
|
43279 |
|
43280 |
|
43281 | /**
|
43282 | * Get the kind.
|
43283 | *
|
43284 | * @return {String}
|
43285 | */
|
43286 |
|
43287 | get: function get() {
|
43288 | return 'state';
|
43289 | }
|
43290 |
|
43291 | /**
|
43292 | * Are there undoable events?
|
43293 | *
|
43294 | * @return {Boolean}
|
43295 | */
|
43296 |
|
43297 | }, {
|
43298 | key: 'hasUndos',
|
43299 | get: function get() {
|
43300 | return this.history.undos.size > 0;
|
43301 | }
|
43302 |
|
43303 | /**
|
43304 | * Are there redoable events?
|
43305 | *
|
43306 | * @return {Boolean}
|
43307 | */
|
43308 |
|
43309 | }, {
|
43310 | key: 'hasRedos',
|
43311 | get: function get() {
|
43312 | return this.history.redos.size > 0;
|
43313 | }
|
43314 |
|
43315 | /**
|
43316 | * Is the current selection blurred?
|
43317 | *
|
43318 | * @return {Boolean}
|
43319 | */
|
43320 |
|
43321 | }, {
|
43322 | key: 'isBlurred',
|
43323 | get: function get() {
|
43324 | return this.selection.isBlurred;
|
43325 | }
|
43326 |
|
43327 | /**
|
43328 | * Is the current selection focused?
|
43329 | *
|
43330 | * @return {Boolean}
|
43331 | */
|
43332 |
|
43333 | }, {
|
43334 | key: 'isFocused',
|
43335 | get: function get() {
|
43336 | return this.selection.isFocused;
|
43337 | }
|
43338 |
|
43339 | /**
|
43340 | * Is the current selection collapsed?
|
43341 | *
|
43342 | * @return {Boolean}
|
43343 | */
|
43344 |
|
43345 | }, {
|
43346 | key: 'isCollapsed',
|
43347 | get: function get() {
|
43348 | return this.selection.isCollapsed;
|
43349 | }
|
43350 |
|
43351 | /**
|
43352 | * Is the current selection expanded?
|
43353 | *
|
43354 | * @return {Boolean}
|
43355 | */
|
43356 |
|
43357 | }, {
|
43358 | key: 'isExpanded',
|
43359 | get: function get() {
|
43360 | return this.selection.isExpanded;
|
43361 | }
|
43362 |
|
43363 | /**
|
43364 | * Is the current selection backward?
|
43365 | *
|
43366 | * @return {Boolean} isBackward
|
43367 | */
|
43368 |
|
43369 | }, {
|
43370 | key: 'isBackward',
|
43371 | get: function get() {
|
43372 | return this.selection.isBackward;
|
43373 | }
|
43374 |
|
43375 | /**
|
43376 | * Is the current selection forward?
|
43377 | *
|
43378 | * @return {Boolean}
|
43379 | */
|
43380 |
|
43381 | }, {
|
43382 | key: 'isForward',
|
43383 | get: function get() {
|
43384 | return this.selection.isForward;
|
43385 | }
|
43386 |
|
43387 | /**
|
43388 | * Get the current start key.
|
43389 | *
|
43390 | * @return {String}
|
43391 | */
|
43392 |
|
43393 | }, {
|
43394 | key: 'startKey',
|
43395 | get: function get() {
|
43396 | return this.selection.startKey;
|
43397 | }
|
43398 |
|
43399 | /**
|
43400 | * Get the current end key.
|
43401 | *
|
43402 | * @return {String}
|
43403 | */
|
43404 |
|
43405 | }, {
|
43406 | key: 'endKey',
|
43407 | get: function get() {
|
43408 | return this.selection.endKey;
|
43409 | }
|
43410 |
|
43411 | /**
|
43412 | * Get the current start offset.
|
43413 | *
|
43414 | * @return {String}
|
43415 | */
|
43416 |
|
43417 | }, {
|
43418 | key: 'startOffset',
|
43419 | get: function get() {
|
43420 | return this.selection.startOffset;
|
43421 | }
|
43422 |
|
43423 | /**
|
43424 | * Get the current end offset.
|
43425 | *
|
43426 | * @return {String}
|
43427 | */
|
43428 |
|
43429 | }, {
|
43430 | key: 'endOffset',
|
43431 | get: function get() {
|
43432 | return this.selection.endOffset;
|
43433 | }
|
43434 |
|
43435 | /**
|
43436 | * Get the current anchor key.
|
43437 | *
|
43438 | * @return {String}
|
43439 | */
|
43440 |
|
43441 | }, {
|
43442 | key: 'anchorKey',
|
43443 | get: function get() {
|
43444 | return this.selection.anchorKey;
|
43445 | }
|
43446 |
|
43447 | /**
|
43448 | * Get the current focus key.
|
43449 | *
|
43450 | * @return {String}
|
43451 | */
|
43452 |
|
43453 | }, {
|
43454 | key: 'focusKey',
|
43455 | get: function get() {
|
43456 | return this.selection.focusKey;
|
43457 | }
|
43458 |
|
43459 | /**
|
43460 | * Get the current anchor offset.
|
43461 | *
|
43462 | * @return {String}
|
43463 | */
|
43464 |
|
43465 | }, {
|
43466 | key: 'anchorOffset',
|
43467 | get: function get() {
|
43468 | return this.selection.anchorOffset;
|
43469 | }
|
43470 |
|
43471 | /**
|
43472 | * Get the current focus offset.
|
43473 | *
|
43474 | * @return {String}
|
43475 | */
|
43476 |
|
43477 | }, {
|
43478 | key: 'focusOffset',
|
43479 | get: function get() {
|
43480 | return this.selection.focusOffset;
|
43481 | }
|
43482 |
|
43483 | /**
|
43484 | * Get the current start text node's closest block parent.
|
43485 | *
|
43486 | * @return {Block}
|
43487 | */
|
43488 |
|
43489 | }, {
|
43490 | key: 'startBlock',
|
43491 | get: function get() {
|
43492 | return this.selection.isUnset ? null : this.document.getClosestBlock(this.selection.startKey);
|
43493 | }
|
43494 |
|
43495 | /**
|
43496 | * Get the current end text node's closest block parent.
|
43497 | *
|
43498 | * @return {Block}
|
43499 | */
|
43500 |
|
43501 | }, {
|
43502 | key: 'endBlock',
|
43503 | get: function get() {
|
43504 | return this.selection.isUnset ? null : this.document.getClosestBlock(this.selection.endKey);
|
43505 | }
|
43506 |
|
43507 | /**
|
43508 | * Get the current anchor text node's closest block parent.
|
43509 | *
|
43510 | * @return {Block}
|
43511 | */
|
43512 |
|
43513 | }, {
|
43514 | key: 'anchorBlock',
|
43515 | get: function get() {
|
43516 | return this.selection.isUnset ? null : this.document.getClosestBlock(this.selection.anchorKey);
|
43517 | }
|
43518 |
|
43519 | /**
|
43520 | * Get the current focus text node's closest block parent.
|
43521 | *
|
43522 | * @return {Block}
|
43523 | */
|
43524 |
|
43525 | }, {
|
43526 | key: 'focusBlock',
|
43527 | get: function get() {
|
43528 | return this.selection.isUnset ? null : this.document.getClosestBlock(this.selection.focusKey);
|
43529 | }
|
43530 |
|
43531 | /**
|
43532 | * Get the current start text node's closest inline parent.
|
43533 | *
|
43534 | * @return {Inline}
|
43535 | */
|
43536 |
|
43537 | }, {
|
43538 | key: 'startInline',
|
43539 | get: function get() {
|
43540 | return this.selection.isUnset ? null : this.document.getClosestInline(this.selection.startKey);
|
43541 | }
|
43542 |
|
43543 | /**
|
43544 | * Get the current end text node's closest inline parent.
|
43545 | *
|
43546 | * @return {Inline}
|
43547 | */
|
43548 |
|
43549 | }, {
|
43550 | key: 'endInline',
|
43551 | get: function get() {
|
43552 | return this.selection.isUnset ? null : this.document.getClosestInline(this.selection.endKey);
|
43553 | }
|
43554 |
|
43555 | /**
|
43556 | * Get the current anchor text node's closest inline parent.
|
43557 | *
|
43558 | * @return {Inline}
|
43559 | */
|
43560 |
|
43561 | }, {
|
43562 | key: 'anchorInline',
|
43563 | get: function get() {
|
43564 | return this.selection.isUnset ? null : this.document.getClosestInline(this.selection.anchorKey);
|
43565 | }
|
43566 |
|
43567 | /**
|
43568 | * Get the current focus text node's closest inline parent.
|
43569 | *
|
43570 | * @return {Inline}
|
43571 | */
|
43572 |
|
43573 | }, {
|
43574 | key: 'focusInline',
|
43575 | get: function get() {
|
43576 | return this.selection.isUnset ? null : this.document.getClosestInline(this.selection.focusKey);
|
43577 | }
|
43578 |
|
43579 | /**
|
43580 | * Get the current start text node.
|
43581 | *
|
43582 | * @return {Text}
|
43583 | */
|
43584 |
|
43585 | }, {
|
43586 | key: 'startText',
|
43587 | get: function get() {
|
43588 | return this.selection.isUnset ? null : this.document.getDescendant(this.selection.startKey);
|
43589 | }
|
43590 |
|
43591 | /**
|
43592 | * Get the current end node.
|
43593 | *
|
43594 | * @return {Text}
|
43595 | */
|
43596 |
|
43597 | }, {
|
43598 | key: 'endText',
|
43599 | get: function get() {
|
43600 | return this.selection.isUnset ? null : this.document.getDescendant(this.selection.endKey);
|
43601 | }
|
43602 |
|
43603 | /**
|
43604 | * Get the current anchor node.
|
43605 | *
|
43606 | * @return {Text}
|
43607 | */
|
43608 |
|
43609 | }, {
|
43610 | key: 'anchorText',
|
43611 | get: function get() {
|
43612 | return this.selection.isUnset ? null : this.document.getDescendant(this.selection.anchorKey);
|
43613 | }
|
43614 |
|
43615 | /**
|
43616 | * Get the current focus node.
|
43617 | *
|
43618 | * @return {Text}
|
43619 | */
|
43620 |
|
43621 | }, {
|
43622 | key: 'focusText',
|
43623 | get: function get() {
|
43624 | return this.selection.isUnset ? null : this.document.getDescendant(this.selection.focusKey);
|
43625 | }
|
43626 |
|
43627 | /**
|
43628 | * Get the characters in the current selection.
|
43629 | *
|
43630 | * @return {List<Character>}
|
43631 | */
|
43632 |
|
43633 | }, {
|
43634 | key: 'characters',
|
43635 | get: function get() {
|
43636 | return this.selection.isUnset ? new _immutable.List() : this.document.getCharactersAtRange(this.selection);
|
43637 | }
|
43638 |
|
43639 | /**
|
43640 | * Get the marks of the current selection.
|
43641 | *
|
43642 | * @return {Set<Mark>}
|
43643 | */
|
43644 |
|
43645 | }, {
|
43646 | key: 'marks',
|
43647 | get: function get() {
|
43648 | return this.selection.isUnset ? new _immutable.Set() : this.selection.marks || this.document.getMarksAtRange(this.selection);
|
43649 | }
|
43650 |
|
43651 | /**
|
43652 | * Get the active marks of the current selection.
|
43653 | *
|
43654 | * @return {Set<Mark>}
|
43655 | */
|
43656 |
|
43657 | }, {
|
43658 | key: 'activeMarks',
|
43659 | get: function get() {
|
43660 | return this.selection.isUnset ? new _immutable.Set() : this.selection.marks || this.document.getActiveMarksAtRange(this.selection);
|
43661 | }
|
43662 |
|
43663 | /**
|
43664 | * Get the block nodes in the current selection.
|
43665 | *
|
43666 | * @return {List<Block>}
|
43667 | */
|
43668 |
|
43669 | }, {
|
43670 | key: 'blocks',
|
43671 | get: function get() {
|
43672 | return this.selection.isUnset ? new _immutable.List() : this.document.getBlocksAtRange(this.selection);
|
43673 | }
|
43674 |
|
43675 | /**
|
43676 | * Get the fragment of the current selection.
|
43677 | *
|
43678 | * @return {Document}
|
43679 | */
|
43680 |
|
43681 | }, {
|
43682 | key: 'fragment',
|
43683 | get: function get() {
|
43684 | return this.selection.isUnset ? _document2.default.create() : this.document.getFragmentAtRange(this.selection);
|
43685 | }
|
43686 |
|
43687 | /**
|
43688 | * Get the inline nodes in the current selection.
|
43689 | *
|
43690 | * @return {List<Inline>}
|
43691 | */
|
43692 |
|
43693 | }, {
|
43694 | key: 'inlines',
|
43695 | get: function get() {
|
43696 | return this.selection.isUnset ? new _immutable.List() : this.document.getInlinesAtRange(this.selection);
|
43697 | }
|
43698 |
|
43699 | /**
|
43700 | * Get the text nodes in the current selection.
|
43701 | *
|
43702 | * @return {List<Text>}
|
43703 | */
|
43704 |
|
43705 | }, {
|
43706 | key: 'texts',
|
43707 | get: function get() {
|
43708 | return this.selection.isUnset ? new _immutable.List() : this.document.getTextsAtRange(this.selection);
|
43709 | }
|
43710 |
|
43711 | /**
|
43712 | * Check whether the selection is empty.
|
43713 | *
|
43714 | * @return {Boolean}
|
43715 | */
|
43716 |
|
43717 | }, {
|
43718 | key: 'isEmpty',
|
43719 | get: function get() {
|
43720 | var startOffset = this.startOffset,
|
43721 | endOffset = this.endOffset;
|
43722 |
|
43723 |
|
43724 | if (this.isCollapsed) {
|
43725 | return true;
|
43726 | }
|
43727 |
|
43728 | if (endOffset != 0 && startOffset != 0) {
|
43729 | return false;
|
43730 | }
|
43731 |
|
43732 | return this.fragment.text.length == 0;
|
43733 | }
|
43734 | }], [{
|
43735 | key: 'create',
|
43736 |
|
43737 |
|
43738 | /**
|
43739 | * Create a new `State` with `attrs`.
|
43740 | *
|
43741 | * @param {Object|State} attrs
|
43742 | * @param {Object} options
|
43743 | * @return {State}
|
43744 | */
|
43745 |
|
43746 | value: function create() {
|
43747 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
43748 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
43749 |
|
43750 | if (State.isState(attrs)) {
|
43751 | return attrs;
|
43752 | }
|
43753 |
|
43754 | if ((0, _isPlainObject2.default)(attrs)) {
|
43755 | return State.fromJSON(attrs);
|
43756 | }
|
43757 |
|
43758 | throw new Error('`State.create` only accepts objects or states, but you passed it: ' + attrs);
|
43759 | }
|
43760 |
|
43761 | /**
|
43762 | * Create a `State` from a JSON `object`.
|
43763 | *
|
43764 | * @param {Object} object
|
43765 | * @param {Object} options
|
43766 | * @property {Boolean} normalize
|
43767 | * @property {Array} plugins
|
43768 | * @return {State}
|
43769 | */
|
43770 |
|
43771 | }, {
|
43772 | key: 'fromJSON',
|
43773 | value: function fromJSON(object) {
|
43774 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
43775 | var _object$document = object.document,
|
43776 | document = _object$document === undefined ? {} : _object$document,
|
43777 | _object$selection = object.selection,
|
43778 | selection = _object$selection === undefined ? {} : _object$selection;
|
43779 |
|
43780 |
|
43781 | var data = new _immutable.Map();
|
43782 |
|
43783 | document = _document2.default.fromJSON(document);
|
43784 | selection = _selection2.default.fromJSON(selection);
|
43785 |
|
43786 | // Allow plugins to set a default value for `data`.
|
43787 | if (options.plugins) {
|
43788 | var _iteratorNormalCompletion = true;
|
43789 | var _didIteratorError = false;
|
43790 | var _iteratorError = undefined;
|
43791 |
|
43792 | try {
|
43793 | for (var _iterator = options.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
43794 | var plugin = _step.value;
|
43795 |
|
43796 | if (plugin.data) data = data.merge(plugin.data);
|
43797 | }
|
43798 | } catch (err) {
|
43799 | _didIteratorError = true;
|
43800 | _iteratorError = err;
|
43801 | } finally {
|
43802 | try {
|
43803 | if (!_iteratorNormalCompletion && _iterator.return) {
|
43804 | _iterator.return();
|
43805 | }
|
43806 | } finally {
|
43807 | if (_didIteratorError) {
|
43808 | throw _iteratorError;
|
43809 | }
|
43810 | }
|
43811 | }
|
43812 | }
|
43813 |
|
43814 | // Then merge in the `data` provided.
|
43815 | if ('data' in object) {
|
43816 | data = data.merge(object.data);
|
43817 | }
|
43818 |
|
43819 | if (selection.isUnset) {
|
43820 | var text = document.getFirstText();
|
43821 | if (text) selection = selection.collapseToStartOf(text);
|
43822 | }
|
43823 |
|
43824 | var state = new State({
|
43825 | data: data,
|
43826 | document: document,
|
43827 | selection: selection
|
43828 | });
|
43829 |
|
43830 | if (options.normalize !== false) {
|
43831 | state = state.change({ save: false }).normalize(_core2.default).state;
|
43832 | }
|
43833 |
|
43834 | return state;
|
43835 | }
|
43836 |
|
43837 | /**
|
43838 | * Alias `fromJS`.
|
43839 | */
|
43840 |
|
43841 | }, {
|
43842 | key: 'isState',
|
43843 |
|
43844 |
|
43845 | /**
|
43846 | * Check if a `value` is a `State`.
|
43847 | *
|
43848 | * @param {Any} value
|
43849 | * @return {Boolean}
|
43850 | */
|
43851 |
|
43852 | value: function isState(value) {
|
43853 | return !!(value && value[_modelTypes2.default.STATE]);
|
43854 | }
|
43855 | }]);
|
43856 |
|
43857 | return State;
|
43858 | }((0, _immutable.Record)(DEFAULTS));
|
43859 |
|
43860 | /**
|
43861 | * Attach a pseudo-symbol for type checking.
|
43862 | */
|
43863 |
|
43864 | State.fromJS = State.fromJSON;
|
43865 | State.prototype[_modelTypes2.default.STATE] = true;
|
43866 |
|
43867 | /**
|
43868 | * Export.
|
43869 | */
|
43870 |
|
43871 | exports.default = State;
|
43872 | },{"../constants/model-types":328,"../schemas/core":350,"../utils/logger":366,"./change":332,"./document":335,"./history":336,"./selection":342,"immutable":135,"is-plain-object":139}],345:[function(require,module,exports){
|
43873 | 'use strict';
|
43874 |
|
43875 | Object.defineProperty(exports, "__esModule", {
|
43876 | value: true
|
43877 | });
|
43878 |
|
43879 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
43880 |
|
43881 | var _character = require('./character');
|
43882 |
|
43883 | var _character2 = _interopRequireDefault(_character);
|
43884 |
|
43885 | var _mark = require('./mark');
|
43886 |
|
43887 | var _mark2 = _interopRequireDefault(_mark);
|
43888 |
|
43889 | var _range = require('./range');
|
43890 |
|
43891 | var _range2 = _interopRequireDefault(_range);
|
43892 |
|
43893 | var _modelTypes = require('../constants/model-types');
|
43894 |
|
43895 | var _modelTypes2 = _interopRequireDefault(_modelTypes);
|
43896 |
|
43897 | var _generateKey = require('../utils/generate-key');
|
43898 |
|
43899 | var _generateKey2 = _interopRequireDefault(_generateKey);
|
43900 |
|
43901 | var _isPlainObject = require('is-plain-object');
|
43902 |
|
43903 | var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
|
43904 |
|
43905 | var _logger = require('../utils/logger');
|
43906 |
|
43907 | var _logger2 = _interopRequireDefault(_logger);
|
43908 |
|
43909 | var _memoize = require('../utils/memoize');
|
43910 |
|
43911 | var _memoize2 = _interopRequireDefault(_memoize);
|
43912 |
|
43913 | var _immutable = require('immutable');
|
43914 |
|
43915 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
43916 |
|
43917 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
43918 |
|
43919 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
43920 |
|
43921 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
43922 |
|
43923 | /**
|
43924 | * Default properties.
|
43925 | *
|
43926 | * @type {Object}
|
43927 | */
|
43928 |
|
43929 | var DEFAULTS = {
|
43930 | characters: new _immutable.List(),
|
43931 | key: undefined
|
43932 | };
|
43933 |
|
43934 | /**
|
43935 | * Text.
|
43936 | *
|
43937 | * @type {Text}
|
43938 | */
|
43939 |
|
43940 | var Text = function (_Record) {
|
43941 | _inherits(Text, _Record);
|
43942 |
|
43943 | function Text() {
|
43944 | _classCallCheck(this, Text);
|
43945 |
|
43946 | return _possibleConstructorReturn(this, (Text.__proto__ || Object.getPrototypeOf(Text)).apply(this, arguments));
|
43947 | }
|
43948 |
|
43949 | _createClass(Text, [{
|
43950 | key: 'addMark',
|
43951 |
|
43952 |
|
43953 | /**
|
43954 | * Add a `mark` at `index` and `length`.
|
43955 | *
|
43956 | * @param {Number} index
|
43957 | * @param {Number} length
|
43958 | * @param {Mark} mark
|
43959 | * @return {Text}
|
43960 | */
|
43961 |
|
43962 | value: function addMark(index, length, mark) {
|
43963 | var characters = this.characters.map(function (char, i) {
|
43964 | if (i < index) return char;
|
43965 | if (i >= index + length) return char;
|
43966 | var _char = char,
|
43967 | marks = _char.marks;
|
43968 |
|
43969 | marks = marks.add(mark);
|
43970 | char = char.set('marks', marks);
|
43971 | return char;
|
43972 | });
|
43973 |
|
43974 | return this.set('characters', characters);
|
43975 | }
|
43976 |
|
43977 | /**
|
43978 | * Derive a set of decorated characters with `decorators`.
|
43979 | *
|
43980 | * @param {Array} decorators
|
43981 | * @return {List<Character>}
|
43982 | */
|
43983 |
|
43984 | }, {
|
43985 | key: 'getDecorations',
|
43986 | value: function getDecorations(decorators) {
|
43987 | var node = this;
|
43988 | var characters = node.characters;
|
43989 |
|
43990 | if (characters.size == 0) return characters;
|
43991 |
|
43992 | for (var i = 0; i < decorators.length; i++) {
|
43993 | var decorator = decorators[i];
|
43994 | var decorateds = decorator(node);
|
43995 | characters = characters.merge(decorateds);
|
43996 | }
|
43997 |
|
43998 | return characters;
|
43999 | }
|
44000 |
|
44001 | /**
|
44002 | * Get the decorations for the node from a `schema`.
|
44003 | *
|
44004 | * @param {Schema} schema
|
44005 | * @return {Array}
|
44006 | */
|
44007 |
|
44008 | }, {
|
44009 | key: 'getDecorators',
|
44010 | value: function getDecorators(schema) {
|
44011 | return schema.__getDecorators(this);
|
44012 | }
|
44013 |
|
44014 | /**
|
44015 | * Get all of the marks on the text.
|
44016 | *
|
44017 | * @return {OrderedSet<Mark>}
|
44018 | */
|
44019 |
|
44020 | }, {
|
44021 | key: 'getMarks',
|
44022 | value: function getMarks() {
|
44023 | var array = this.getMarksAsArray();
|
44024 | return new _immutable.OrderedSet(array);
|
44025 | }
|
44026 |
|
44027 | /**
|
44028 | * Get all of the marks on the text as an array
|
44029 | *
|
44030 | * @return {Array}
|
44031 | */
|
44032 |
|
44033 | }, {
|
44034 | key: 'getMarksAsArray',
|
44035 | value: function getMarksAsArray() {
|
44036 | return this.characters.reduce(function (array, char) {
|
44037 | return array.concat(char.marks.toArray());
|
44038 | }, []);
|
44039 | }
|
44040 |
|
44041 | /**
|
44042 | * Get the marks on the text at `index`.
|
44043 | *
|
44044 | * @param {Number} index
|
44045 | * @return {Set<Mark>}
|
44046 | */
|
44047 |
|
44048 | }, {
|
44049 | key: 'getMarksAtIndex',
|
44050 | value: function getMarksAtIndex(index) {
|
44051 | if (index == 0) return _mark2.default.createSet();
|
44052 | var characters = this.characters;
|
44053 |
|
44054 | var char = characters.get(index - 1);
|
44055 | if (!char) return _mark2.default.createSet();
|
44056 | return char.marks;
|
44057 | }
|
44058 |
|
44059 | /**
|
44060 | * Get a node by `key`, to parallel other nodes.
|
44061 | *
|
44062 | * @param {String} key
|
44063 | * @return {Node|Null}
|
44064 | */
|
44065 |
|
44066 | }, {
|
44067 | key: 'getNode',
|
44068 | value: function getNode(key) {
|
44069 | return this.key == key ? this : null;
|
44070 | }
|
44071 |
|
44072 | /**
|
44073 | * Derive the ranges for a list of `characters`.
|
44074 | *
|
44075 | * @param {Array|Void} decorators (optional)
|
44076 | * @return {List<Range>}
|
44077 | */
|
44078 |
|
44079 | }, {
|
44080 | key: 'getRanges',
|
44081 | value: function getRanges() {
|
44082 | var decorators = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
44083 |
|
44084 | var characters = this.getDecorations(decorators);
|
44085 | var ranges = [];
|
44086 |
|
44087 | // PERF: cache previous values for faster lookup.
|
44088 | var prevChar = void 0;
|
44089 | var prevRange = void 0;
|
44090 |
|
44091 | // If there are no characters, return one empty range.
|
44092 | if (characters.size == 0) {
|
44093 | ranges.push({});
|
44094 | }
|
44095 |
|
44096 | // Otherwise, loop the characters and build the ranges...
|
44097 | else {
|
44098 | characters.forEach(function (char, i) {
|
44099 | var marks = char.marks,
|
44100 | text = char.text;
|
44101 |
|
44102 | // The first one can always just be created.
|
44103 |
|
44104 | if (i == 0) {
|
44105 | prevChar = char;
|
44106 | prevRange = { text: text, marks: marks };
|
44107 | ranges.push(prevRange);
|
44108 | return;
|
44109 | }
|
44110 |
|
44111 | // Otherwise, compare the current and previous marks.
|
44112 | var prevMarks = prevChar.marks;
|
44113 | var isSame = (0, _immutable.is)(marks, prevMarks);
|
44114 |
|
44115 | // If the marks are the same, add the text to the previous range.
|
44116 | if (isSame) {
|
44117 | prevChar = char;
|
44118 | prevRange.text += text;
|
44119 | return;
|
44120 | }
|
44121 |
|
44122 | // Otherwise, create a new range.
|
44123 | prevChar = char;
|
44124 | prevRange = { text: text, marks: marks };
|
44125 | ranges.push(prevRange);
|
44126 | }, []);
|
44127 | }
|
44128 |
|
44129 | // PERF: convert the ranges to immutable objects after iterating.
|
44130 | ranges = new _immutable.List(ranges.map(function (object) {
|
44131 | return new _range2.default(object);
|
44132 | }));
|
44133 |
|
44134 | // Return the ranges.
|
44135 | return ranges;
|
44136 | }
|
44137 |
|
44138 | /**
|
44139 | * Check if the node has a node by `key`, to parallel other nodes.
|
44140 | *
|
44141 | * @param {String} key
|
44142 | * @return {Boolean}
|
44143 | */
|
44144 |
|
44145 | }, {
|
44146 | key: 'hasNode',
|
44147 | value: function hasNode(key) {
|
44148 | return !!this.getNode(key);
|
44149 | }
|
44150 |
|
44151 | /**
|
44152 | * Insert `text` at `index`.
|
44153 | *
|
44154 | * @param {Numbder} index
|
44155 | * @param {String} text
|
44156 | * @param {String} marks (optional)
|
44157 | * @return {Text}
|
44158 | */
|
44159 |
|
44160 | }, {
|
44161 | key: 'insertText',
|
44162 | value: function insertText(index, text, marks) {
|
44163 | var characters = this.characters;
|
44164 |
|
44165 | var chars = _character2.default.createList(text.split('').map(function (char) {
|
44166 | return { text: char, marks: marks };
|
44167 | }));
|
44168 |
|
44169 | characters = characters.slice(0, index).concat(chars).concat(characters.slice(index));
|
44170 |
|
44171 | return this.set('characters', characters);
|
44172 | }
|
44173 |
|
44174 | /**
|
44175 | * Regenerate the node's key.
|
44176 | *
|
44177 | * @return {Text}
|
44178 | */
|
44179 |
|
44180 | }, {
|
44181 | key: 'regenerateKey',
|
44182 | value: function regenerateKey() {
|
44183 | var key = (0, _generateKey2.default)();
|
44184 | return this.set('key', key);
|
44185 | }
|
44186 |
|
44187 | /**
|
44188 | * Remove a `mark` at `index` and `length`.
|
44189 | *
|
44190 | * @param {Number} index
|
44191 | * @param {Number} length
|
44192 | * @param {Mark} mark
|
44193 | * @return {Text}
|
44194 | */
|
44195 |
|
44196 | }, {
|
44197 | key: 'removeMark',
|
44198 | value: function removeMark(index, length, mark) {
|
44199 | var characters = this.characters.map(function (char, i) {
|
44200 | if (i < index) return char;
|
44201 | if (i >= index + length) return char;
|
44202 | var _char2 = char,
|
44203 | marks = _char2.marks;
|
44204 |
|
44205 | marks = marks.remove(mark);
|
44206 | char = char.set('marks', marks);
|
44207 | return char;
|
44208 | });
|
44209 |
|
44210 | return this.set('characters', characters);
|
44211 | }
|
44212 |
|
44213 | /**
|
44214 | * Remove text from the text node at `index` for `length`.
|
44215 | *
|
44216 | * @param {Number} index
|
44217 | * @param {Number} length
|
44218 | * @return {Text}
|
44219 | */
|
44220 |
|
44221 | }, {
|
44222 | key: 'removeText',
|
44223 | value: function removeText(index, length) {
|
44224 | var characters = this.characters;
|
44225 |
|
44226 | var start = index;
|
44227 | var end = index + length;
|
44228 | characters = characters.filterNot(function (char, i) {
|
44229 | return start <= i && i < end;
|
44230 | });
|
44231 | return this.set('characters', characters);
|
44232 | }
|
44233 |
|
44234 | /**
|
44235 | * Return a JSON representation of the text.
|
44236 | *
|
44237 | * @param {Object} options
|
44238 | * @return {Object}
|
44239 | */
|
44240 |
|
44241 | }, {
|
44242 | key: 'toJSON',
|
44243 | value: function toJSON() {
|
44244 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
44245 |
|
44246 | var object = {
|
44247 | key: this.key,
|
44248 | kind: this.kind,
|
44249 | ranges: this.getRanges().toArray().map(function (r) {
|
44250 | return r.toJSON();
|
44251 | })
|
44252 | };
|
44253 |
|
44254 | if (!options.preserveKeys) {
|
44255 | delete object.key;
|
44256 | }
|
44257 |
|
44258 | return object;
|
44259 | }
|
44260 |
|
44261 | /**
|
44262 | * Alias `toJS`.
|
44263 | */
|
44264 |
|
44265 | }, {
|
44266 | key: 'toJS',
|
44267 | value: function toJS(options) {
|
44268 | return this.toJSON(options);
|
44269 | }
|
44270 |
|
44271 | /**
|
44272 | * Update a `mark` at `index` and `length` with `properties`.
|
44273 | *
|
44274 | * @param {Number} index
|
44275 | * @param {Number} length
|
44276 | * @param {Mark} mark
|
44277 | * @param {Object} properties
|
44278 | * @return {Text}
|
44279 | */
|
44280 |
|
44281 | }, {
|
44282 | key: 'updateMark',
|
44283 | value: function updateMark(index, length, mark, properties) {
|
44284 | var newMark = mark.merge(properties);
|
44285 |
|
44286 | var characters = this.characters.map(function (char, i) {
|
44287 | if (i < index) return char;
|
44288 | if (i >= index + length) return char;
|
44289 | var _char3 = char,
|
44290 | marks = _char3.marks;
|
44291 |
|
44292 | if (!marks.has(mark)) return char;
|
44293 | marks = marks.remove(mark);
|
44294 | marks = marks.add(newMark);
|
44295 | char = char.set('marks', marks);
|
44296 | return char;
|
44297 | });
|
44298 |
|
44299 | return this.set('characters', characters);
|
44300 | }
|
44301 |
|
44302 | /**
|
44303 | * Validate the text node against a `schema`.
|
44304 | *
|
44305 | * @param {Schema} schema
|
44306 | * @return {Object|Void}
|
44307 | */
|
44308 |
|
44309 | }, {
|
44310 | key: 'validate',
|
44311 | value: function validate(schema) {
|
44312 | return schema.__validate(this);
|
44313 | }
|
44314 | }, {
|
44315 | key: 'kind',
|
44316 |
|
44317 |
|
44318 | /**
|
44319 | * Get the node's kind.
|
44320 | *
|
44321 | * @return {String}
|
44322 | */
|
44323 |
|
44324 | get: function get() {
|
44325 | return 'text';
|
44326 | }
|
44327 |
|
44328 | /**
|
44329 | * Is the node empty?
|
44330 | *
|
44331 | * @return {Boolean}
|
44332 | */
|
44333 |
|
44334 | }, {
|
44335 | key: 'isEmpty',
|
44336 | get: function get() {
|
44337 | return this.text == '';
|
44338 | }
|
44339 |
|
44340 | /**
|
44341 | * Get the concatenated text of the node.
|
44342 | *
|
44343 | * @return {String}
|
44344 | */
|
44345 |
|
44346 | }, {
|
44347 | key: 'text',
|
44348 | get: function get() {
|
44349 | return this.characters.reduce(function (string, char) {
|
44350 | return string + char.text;
|
44351 | }, '');
|
44352 | }
|
44353 | }], [{
|
44354 | key: 'create',
|
44355 |
|
44356 |
|
44357 | /**
|
44358 | * Create a new `Text` with `attrs`.
|
44359 | *
|
44360 | * @param {Object|Array|List|String|Text} attrs
|
44361 | * @return {Text}
|
44362 | */
|
44363 |
|
44364 | value: function create() {
|
44365 | var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
44366 |
|
44367 | if (Text.isText(attrs)) {
|
44368 | return attrs;
|
44369 | }
|
44370 |
|
44371 | if (typeof attrs == 'string') {
|
44372 | attrs = { ranges: [{ text: attrs }] };
|
44373 | }
|
44374 |
|
44375 | if ((0, _isPlainObject2.default)(attrs)) {
|
44376 | if (attrs.text) {
|
44377 | var _attrs = attrs,
|
44378 | text = _attrs.text,
|
44379 | marks = _attrs.marks,
|
44380 | key = _attrs.key;
|
44381 |
|
44382 | attrs = { key: key, ranges: [{ text: text, marks: marks }] };
|
44383 | }
|
44384 |
|
44385 | return Text.fromJSON(attrs);
|
44386 | }
|
44387 |
|
44388 | throw new Error('`Text.create` only accepts objects, arrays, strings or texts, but you passed it: ' + attrs);
|
44389 | }
|
44390 |
|
44391 | /**
|
44392 | * Create a list of `Texts` from a `value`.
|
44393 | *
|
44394 | * @param {Array<Text|Object>|List<Text|Object>} value
|
44395 | * @return {List<Text>}
|
44396 | */
|
44397 |
|
44398 | }, {
|
44399 | key: 'createList',
|
44400 | value: function createList() {
|
44401 | var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
44402 |
|
44403 | if (_immutable.List.isList(value) || Array.isArray(value)) {
|
44404 | var list = new _immutable.List(value.map(Text.create));
|
44405 | return list;
|
44406 | }
|
44407 |
|
44408 | throw new Error('`Text.createList` only accepts arrays or lists, but you passed it: ' + value);
|
44409 | }
|
44410 |
|
44411 | /**
|
44412 | * Create a `Text` from a JSON `object`.
|
44413 | *
|
44414 | * @param {Object|Text} object
|
44415 | * @return {Text}
|
44416 | */
|
44417 |
|
44418 | }, {
|
44419 | key: 'fromJSON',
|
44420 | value: function fromJSON(object) {
|
44421 | if (Text.isText(object)) {
|
44422 | return object;
|
44423 | }
|
44424 |
|
44425 | var _object$ranges = object.ranges,
|
44426 | ranges = _object$ranges === undefined ? [] : _object$ranges,
|
44427 | _object$key = object.key,
|
44428 | key = _object$key === undefined ? (0, _generateKey2.default)() : _object$key;
|
44429 |
|
44430 |
|
44431 | if (object.text) {
|
44432 | _logger2.default.deprecate('0.23.0', 'Passing `object.text` to `Text.fromJSON` has been deprecated, please use `object.ranges` instead.');
|
44433 | ranges = [{ text: object.text }];
|
44434 | }
|
44435 |
|
44436 | var characters = ranges.map(_range2.default.fromJSON).reduce(function (l, r) {
|
44437 | return l.concat(r.getCharacters());
|
44438 | }, new _immutable.List());
|
44439 |
|
44440 | var node = new Text({
|
44441 | characters: characters,
|
44442 | key: key
|
44443 | });
|
44444 |
|
44445 | return node;
|
44446 | }
|
44447 |
|
44448 | /**
|
44449 | * Alias `fromJS`.
|
44450 | */
|
44451 |
|
44452 | }, {
|
44453 | key: 'isText',
|
44454 |
|
44455 |
|
44456 | /**
|
44457 | * Check if a `value` is a `Text`.
|
44458 | *
|
44459 | * @param {Any} value
|
44460 | * @return {Boolean}
|
44461 | */
|
44462 |
|
44463 | value: function isText(value) {
|
44464 | return !!(value && value[_modelTypes2.default.TEXT]);
|
44465 | }
|
44466 |
|
44467 | /**
|
44468 | * Check if a `value` is a list of texts.
|
44469 | *
|
44470 | * @param {Any} value
|
44471 | * @return {Boolean}
|
44472 | */
|
44473 |
|
44474 | }, {
|
44475 | key: 'isTextList',
|
44476 | value: function isTextList(value) {
|
44477 | return _immutable.List.isList(value) && value.every(function (item) {
|
44478 | return Text.isText(item);
|
44479 | });
|
44480 | }
|
44481 |
|
44482 | /**
|
44483 | * Deprecated.
|
44484 | */
|
44485 |
|
44486 | }, {
|
44487 | key: 'createFromString',
|
44488 | value: function createFromString(string) {
|
44489 | _logger2.default.deprecate('0.22.0', 'The `Text.createFromString(string)` method is deprecated, use `Text.create(string)` instead.');
|
44490 | return Text.create(string);
|
44491 | }
|
44492 |
|
44493 | /**
|
44494 | * Deprecated.
|
44495 | */
|
44496 |
|
44497 | }, {
|
44498 | key: 'createFromRanges',
|
44499 | value: function createFromRanges(ranges) {
|
44500 | _logger2.default.deprecate('0.22.0', 'The `Text.createFromRanges(ranges)` method is deprecated, use `Text.create(ranges)` instead.');
|
44501 | return Text.create(ranges);
|
44502 | }
|
44503 | }]);
|
44504 |
|
44505 | return Text;
|
44506 | }((0, _immutable.Record)(DEFAULTS));
|
44507 |
|
44508 | /**
|
44509 | * Attach a pseudo-symbol for type checking.
|
44510 | */
|
44511 |
|
44512 | Text.fromJS = Text.fromJSON;
|
44513 | Text.prototype[_modelTypes2.default.TEXT] = true;
|
44514 |
|
44515 | /**
|
44516 | * Memoize read methods.
|
44517 | */
|
44518 |
|
44519 | (0, _memoize2.default)(Text.prototype, ['getMarks', 'getMarksAsArray'], {
|
44520 | takesArguments: false
|
44521 | });
|
44522 |
|
44523 | (0, _memoize2.default)(Text.prototype, ['getDecorations', 'getDecorators', 'getMarksAtIndex', 'getRanges', 'validate'], {
|
44524 | takesArguments: true
|
44525 | });
|
44526 |
|
44527 | /**
|
44528 | * Export.
|
44529 | *
|
44530 | * @type {Text}
|
44531 | */
|
44532 |
|
44533 | exports.default = Text;
|
44534 | },{"../constants/model-types":328,"../utils/generate-key":359,"../utils/logger":366,"../utils/memoize":367,"./character":333,"./mark":338,"./range":340,"immutable":135,"is-plain-object":139}],346:[function(require,module,exports){
|
44535 | 'use strict';
|
44536 |
|
44537 | Object.defineProperty(exports, "__esModule", {
|
44538 | value: true
|
44539 | });
|
44540 |
|
44541 | 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; };
|
44542 |
|
44543 | var _debug = require('debug');
|
44544 |
|
44545 | var _debug2 = _interopRequireDefault(_debug);
|
44546 |
|
44547 | var _node = require('../models/node');
|
44548 |
|
44549 | var _node2 = _interopRequireDefault(_node);
|
44550 |
|
44551 | var _mark = require('../models/mark');
|
44552 |
|
44553 | var _mark2 = _interopRequireDefault(_mark);
|
44554 |
|
44555 | var _logger = require('../utils/logger');
|
44556 |
|
44557 | var _logger2 = _interopRequireDefault(_logger);
|
44558 |
|
44559 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
44560 |
|
44561 | /**
|
44562 | * Debug.
|
44563 | *
|
44564 | * @type {Function}
|
44565 | */
|
44566 |
|
44567 | var debug = (0, _debug2.default)('slate:operation:apply');
|
44568 |
|
44569 | /**
|
44570 | * Applying functions.
|
44571 | *
|
44572 | * @type {Object}
|
44573 | */
|
44574 |
|
44575 | var APPLIERS = {
|
44576 |
|
44577 | /**
|
44578 | * Add mark to text at `offset` and `length` in node by `path`.
|
44579 | *
|
44580 | * @param {State} state
|
44581 | * @param {Object} operation
|
44582 | * @return {State}
|
44583 | */
|
44584 |
|
44585 | add_mark: function add_mark(state, operation) {
|
44586 | var path = operation.path,
|
44587 | offset = operation.offset,
|
44588 | length = operation.length;
|
44589 |
|
44590 | var mark = _mark2.default.create(operation.mark);
|
44591 | var _state = state,
|
44592 | document = _state.document;
|
44593 |
|
44594 | var node = document.assertPath(path);
|
44595 | node = node.addMark(offset, length, mark);
|
44596 | document = document.updateNode(node);
|
44597 | state = state.set('document', document);
|
44598 | return state;
|
44599 | },
|
44600 |
|
44601 |
|
44602 | /**
|
44603 | * Insert a `node` at `index` in a node by `path`.
|
44604 | *
|
44605 | * @param {State} state
|
44606 | * @param {Object} operation
|
44607 | * @return {State}
|
44608 | */
|
44609 |
|
44610 | insert_node: function insert_node(state, operation) {
|
44611 | var path = operation.path;
|
44612 |
|
44613 | var node = _node2.default.create(operation.node);
|
44614 | var index = path[path.length - 1];
|
44615 | var rest = path.slice(0, -1);
|
44616 | var _state2 = state,
|
44617 | document = _state2.document;
|
44618 |
|
44619 | var parent = document.assertPath(rest);
|
44620 | parent = parent.insertNode(index, node);
|
44621 | document = document.updateNode(parent);
|
44622 | state = state.set('document', document);
|
44623 | return state;
|
44624 | },
|
44625 |
|
44626 |
|
44627 | /**
|
44628 | * Insert `text` at `offset` in node by `path`.
|
44629 | *
|
44630 | * @param {State} state
|
44631 | * @param {Object} operation
|
44632 | * @return {State}
|
44633 | */
|
44634 |
|
44635 | insert_text: function insert_text(state, operation) {
|
44636 | var path = operation.path,
|
44637 | offset = operation.offset,
|
44638 | text = operation.text;
|
44639 | var marks = operation.marks;
|
44640 |
|
44641 | if (Array.isArray(marks)) marks = _mark2.default.createSet(marks);
|
44642 |
|
44643 | var _state3 = state,
|
44644 | document = _state3.document,
|
44645 | selection = _state3.selection;
|
44646 | var _selection = selection,
|
44647 | anchorKey = _selection.anchorKey,
|
44648 | focusKey = _selection.focusKey,
|
44649 | anchorOffset = _selection.anchorOffset,
|
44650 | focusOffset = _selection.focusOffset;
|
44651 |
|
44652 | var node = document.assertPath(path);
|
44653 |
|
44654 | // Update the document
|
44655 | node = node.insertText(offset, text, marks);
|
44656 | document = document.updateNode(node);
|
44657 |
|
44658 | // Update the selection
|
44659 | if (anchorKey == node.key && anchorOffset >= offset) {
|
44660 | selection = selection.moveAnchor(text.length);
|
44661 | }
|
44662 | if (focusKey == node.key && focusOffset >= offset) {
|
44663 | selection = selection.moveFocus(text.length);
|
44664 | }
|
44665 |
|
44666 | state = state.set('document', document).set('selection', selection);
|
44667 | return state;
|
44668 | },
|
44669 |
|
44670 |
|
44671 | /**
|
44672 | * Merge a node at `path` with the previous node.
|
44673 | *
|
44674 | * @param {State} state
|
44675 | * @param {Object} operation
|
44676 | * @return {State}
|
44677 | */
|
44678 |
|
44679 | merge_node: function merge_node(state, operation) {
|
44680 | var path = operation.path;
|
44681 |
|
44682 | var withPath = path.slice(0, path.length - 1).concat([path[path.length - 1] - 1]);
|
44683 | var _state4 = state,
|
44684 | document = _state4.document,
|
44685 | selection = _state4.selection;
|
44686 |
|
44687 | var one = document.assertPath(withPath);
|
44688 | var two = document.assertPath(path);
|
44689 | var parent = document.getParent(one.key);
|
44690 | var oneIndex = parent.nodes.indexOf(one);
|
44691 | var twoIndex = parent.nodes.indexOf(two);
|
44692 |
|
44693 | // Perform the merge in the document.
|
44694 | parent = parent.mergeNode(oneIndex, twoIndex);
|
44695 | document = document.updateNode(parent);
|
44696 |
|
44697 | // If the nodes are text nodes and the selection is inside the second node
|
44698 | // update it to refer to the first node instead.
|
44699 | if (one.kind == 'text') {
|
44700 | var _selection2 = selection,
|
44701 | anchorKey = _selection2.anchorKey,
|
44702 | anchorOffset = _selection2.anchorOffset,
|
44703 | focusKey = _selection2.focusKey,
|
44704 | focusOffset = _selection2.focusOffset;
|
44705 |
|
44706 | var normalize = false;
|
44707 |
|
44708 | if (anchorKey == two.key) {
|
44709 | selection = selection.moveAnchorTo(one.key, one.text.length + anchorOffset);
|
44710 | normalize = true;
|
44711 | }
|
44712 |
|
44713 | if (focusKey == two.key) {
|
44714 | selection = selection.moveFocusTo(one.key, one.text.length + focusOffset);
|
44715 | normalize = true;
|
44716 | }
|
44717 |
|
44718 | if (normalize) {
|
44719 | selection = selection.normalize(document);
|
44720 | }
|
44721 | }
|
44722 |
|
44723 | // Update the document and selection.
|
44724 | state = state.set('document', document).set('selection', selection);
|
44725 | return state;
|
44726 | },
|
44727 |
|
44728 |
|
44729 | /**
|
44730 | * Move a node by `path` to `newPath`.
|
44731 | *
|
44732 | * @param {State} state
|
44733 | * @param {Object} operation
|
44734 | * @return {State}
|
44735 | */
|
44736 |
|
44737 | move_node: function move_node(state, operation) {
|
44738 | var path = operation.path,
|
44739 | newPath = operation.newPath;
|
44740 |
|
44741 | var newIndex = newPath[newPath.length - 1];
|
44742 | var newParentPath = newPath.slice(0, -1);
|
44743 | var oldParentPath = path.slice(0, -1);
|
44744 | var oldIndex = path[path.length - 1];
|
44745 | var _state5 = state,
|
44746 | document = _state5.document;
|
44747 |
|
44748 | var node = document.assertPath(path);
|
44749 |
|
44750 | // Remove the node from its current parent.
|
44751 | var parent = document.getParent(node.key);
|
44752 | parent = parent.removeNode(oldIndex);
|
44753 | document = document.updateNode(parent);
|
44754 |
|
44755 | // Find the new target...
|
44756 | var target = void 0;
|
44757 |
|
44758 | // If the old path and the rest of the new path are the same, then the new
|
44759 | // target is the old parent.
|
44760 | if (oldParentPath.every(function (x, i) {
|
44761 | return x === newParentPath[i];
|
44762 | }) && oldParentPath.length === newParentPath.length) {
|
44763 | target = parent;
|
44764 | }
|
44765 |
|
44766 | // Otherwise, if the old path removal resulted in the new path being no longer
|
44767 | // correct, we need to decrement the new path at the old path's last index.
|
44768 | else if (oldParentPath.every(function (x, i) {
|
44769 | return x === newParentPath[i];
|
44770 | }) && oldIndex < newParentPath[oldParentPath.length]) {
|
44771 | newParentPath[oldParentPath.length]--;
|
44772 | target = document.assertPath(newParentPath);
|
44773 | }
|
44774 |
|
44775 | // Otherwise, we can just grab the target normally...
|
44776 | else {
|
44777 | target = document.assertPath(newParentPath);
|
44778 | }
|
44779 |
|
44780 | // Insert the new node to its new parent.
|
44781 | target = target.insertNode(newIndex, node);
|
44782 | document = document.updateNode(target);
|
44783 | state = state.set('document', document);
|
44784 | return state;
|
44785 | },
|
44786 |
|
44787 |
|
44788 | /**
|
44789 | * Remove mark from text at `offset` and `length` in node by `path`.
|
44790 | *
|
44791 | * @param {State} state
|
44792 | * @param {Object} operation
|
44793 | * @return {State}
|
44794 | */
|
44795 |
|
44796 | remove_mark: function remove_mark(state, operation) {
|
44797 | var path = operation.path,
|
44798 | offset = operation.offset,
|
44799 | length = operation.length;
|
44800 |
|
44801 | var mark = _mark2.default.create(operation.mark);
|
44802 | var _state6 = state,
|
44803 | document = _state6.document;
|
44804 |
|
44805 | var node = document.assertPath(path);
|
44806 | node = node.removeMark(offset, length, mark);
|
44807 | document = document.updateNode(node);
|
44808 | state = state.set('document', document);
|
44809 | return state;
|
44810 | },
|
44811 |
|
44812 |
|
44813 | /**
|
44814 | * Remove a node by `path`.
|
44815 | *
|
44816 | * @param {State} state
|
44817 | * @param {Object} operation
|
44818 | * @return {State}
|
44819 | */
|
44820 |
|
44821 | remove_node: function remove_node(state, operation) {
|
44822 | var path = operation.path;
|
44823 | var _state7 = state,
|
44824 | document = _state7.document,
|
44825 | selection = _state7.selection;
|
44826 | var _selection3 = selection,
|
44827 | startKey = _selection3.startKey,
|
44828 | endKey = _selection3.endKey;
|
44829 |
|
44830 | var node = document.assertPath(path);
|
44831 |
|
44832 | // If the selection is set, check to see if it needs to be updated.
|
44833 | if (selection.isSet) {
|
44834 | var hasStartNode = node.hasNode(startKey);
|
44835 | var hasEndNode = node.hasNode(endKey);
|
44836 | var normalize = false;
|
44837 |
|
44838 | // If one of the selection's nodes is being removed, we need to update it.
|
44839 | if (hasStartNode) {
|
44840 | var prev = document.getPreviousText(startKey);
|
44841 | var next = document.getNextText(startKey);
|
44842 |
|
44843 | if (prev) {
|
44844 | selection = selection.moveStartTo(prev.key, prev.text.length);
|
44845 | normalize = true;
|
44846 | } else if (next) {
|
44847 | selection = selection.moveStartTo(next.key, 0);
|
44848 | normalize = true;
|
44849 | } else {
|
44850 | selection = selection.deselect();
|
44851 | }
|
44852 | }
|
44853 |
|
44854 | if (hasEndNode) {
|
44855 | var _prev = document.getPreviousText(endKey);
|
44856 | var _next = document.getNextText(endKey);
|
44857 |
|
44858 | if (_prev) {
|
44859 | selection = selection.moveEndTo(_prev.key, _prev.text.length);
|
44860 | normalize = true;
|
44861 | } else if (_next) {
|
44862 | selection = selection.moveEndTo(_next.key, 0);
|
44863 | normalize = true;
|
44864 | } else {
|
44865 | selection = selection.deselect();
|
44866 | }
|
44867 | }
|
44868 |
|
44869 | if (normalize) {
|
44870 | selection = selection.normalize(document);
|
44871 | }
|
44872 | }
|
44873 |
|
44874 | // Remove the node from the document.
|
44875 | var parent = document.getParent(node.key);
|
44876 | var index = parent.nodes.indexOf(node);
|
44877 | parent = parent.removeNode(index);
|
44878 | document = document.updateNode(parent);
|
44879 |
|
44880 | // Update the document and selection.
|
44881 | state = state.set('document', document).set('selection', selection);
|
44882 | return state;
|
44883 | },
|
44884 |
|
44885 |
|
44886 | /**
|
44887 | * Remove `text` at `offset` in node by `path`.
|
44888 | *
|
44889 | * @param {State} state
|
44890 | * @param {Object} operation
|
44891 | * @return {State}
|
44892 | */
|
44893 |
|
44894 | remove_text: function remove_text(state, operation) {
|
44895 | var path = operation.path,
|
44896 | offset = operation.offset,
|
44897 | text = operation.text;
|
44898 | var length = text.length;
|
44899 |
|
44900 | var rangeOffset = offset + length;
|
44901 | var _state8 = state,
|
44902 | document = _state8.document,
|
44903 | selection = _state8.selection;
|
44904 | var _selection4 = selection,
|
44905 | anchorKey = _selection4.anchorKey,
|
44906 | focusKey = _selection4.focusKey,
|
44907 | anchorOffset = _selection4.anchorOffset,
|
44908 | focusOffset = _selection4.focusOffset;
|
44909 |
|
44910 | var node = document.assertPath(path);
|
44911 |
|
44912 | // Update the selection.
|
44913 | if (anchorKey == node.key && anchorOffset >= rangeOffset) {
|
44914 | selection = selection.moveAnchor(-length);
|
44915 | }
|
44916 |
|
44917 | if (focusKey == node.key && focusOffset >= rangeOffset) {
|
44918 | selection = selection.moveFocus(-length);
|
44919 | }
|
44920 |
|
44921 | node = node.removeText(offset, length);
|
44922 | document = document.updateNode(node);
|
44923 | state = state.set('document', document).set('selection', selection);
|
44924 | return state;
|
44925 | },
|
44926 |
|
44927 |
|
44928 | /**
|
44929 | * Set `data` on `state`.
|
44930 | *
|
44931 | * @param {State} state
|
44932 | * @param {Object} operation
|
44933 | * @return {State}
|
44934 | */
|
44935 |
|
44936 | set_data: function set_data(state, operation) {
|
44937 | var properties = operation.properties;
|
44938 | var _state9 = state,
|
44939 | data = _state9.data;
|
44940 |
|
44941 |
|
44942 | data = data.merge(properties);
|
44943 | state = state.set('data', data);
|
44944 | return state;
|
44945 | },
|
44946 |
|
44947 |
|
44948 | /**
|
44949 | * Set `properties` on mark on text at `offset` and `length` in node by `path`.
|
44950 | *
|
44951 | * @param {State} state
|
44952 | * @param {Object} operation
|
44953 | * @return {State}
|
44954 | */
|
44955 |
|
44956 | set_mark: function set_mark(state, operation) {
|
44957 | var path = operation.path,
|
44958 | offset = operation.offset,
|
44959 | length = operation.length,
|
44960 | properties = operation.properties;
|
44961 |
|
44962 | var mark = _mark2.default.create(operation.mark);
|
44963 | var _state10 = state,
|
44964 | document = _state10.document;
|
44965 |
|
44966 | var node = document.assertPath(path);
|
44967 | node = node.updateMark(offset, length, mark, properties);
|
44968 | document = document.updateNode(node);
|
44969 | state = state.set('document', document);
|
44970 | return state;
|
44971 | },
|
44972 |
|
44973 |
|
44974 | /**
|
44975 | * Set `properties` on a node by `path`.
|
44976 | *
|
44977 | * @param {State} state
|
44978 | * @param {Object} operation
|
44979 | * @return {State}
|
44980 | */
|
44981 |
|
44982 | set_node: function set_node(state, operation) {
|
44983 | var path = operation.path,
|
44984 | properties = operation.properties;
|
44985 | var _state11 = state,
|
44986 | document = _state11.document;
|
44987 |
|
44988 | var node = document.assertPath(path);
|
44989 |
|
44990 | // Warn when trying to overwite a node's children.
|
44991 | if (properties.nodes && properties.nodes != node.nodes) {
|
44992 | _logger2.default.warn('Updating a Node\'s `nodes` property via `setNode()` is not allowed. Use the appropriate insertion and removal operations instead. The opeartion in question was:', operation);
|
44993 | delete properties.nodes;
|
44994 | }
|
44995 |
|
44996 | // Warn when trying to change a node's key.
|
44997 | if (properties.key && properties.key != node.key) {
|
44998 | _logger2.default.warn('Updating a Node\'s `key` property via `setNode()` is not allowed. There should be no reason to do this. The opeartion in question was:', operation);
|
44999 | delete properties.key;
|
45000 | }
|
45001 |
|
45002 | node = node.merge(properties);
|
45003 | document = document.updateNode(node);
|
45004 | state = state.set('document', document);
|
45005 | return state;
|
45006 | },
|
45007 |
|
45008 |
|
45009 | /**
|
45010 | * Set `properties` on the selection.
|
45011 | *
|
45012 | * @param {State} state
|
45013 | * @param {Object} operation
|
45014 | * @return {State}
|
45015 | */
|
45016 |
|
45017 | set_selection: function set_selection(state, operation) {
|
45018 | var properties = _extends({}, operation.properties);
|
45019 | var _state12 = state,
|
45020 | document = _state12.document,
|
45021 | selection = _state12.selection;
|
45022 |
|
45023 |
|
45024 | if (properties.marks != null) {
|
45025 | properties.marks = _mark2.default.createSet(properties.marks);
|
45026 | }
|
45027 |
|
45028 | if (properties.anchorPath !== undefined) {
|
45029 | properties.anchorKey = properties.anchorPath === null ? null : document.assertPath(properties.anchorPath).key;
|
45030 | delete properties.anchorPath;
|
45031 | }
|
45032 |
|
45033 | if (properties.focusPath !== undefined) {
|
45034 | properties.focusKey = properties.focusPath === null ? null : document.assertPath(properties.focusPath).key;
|
45035 | delete properties.focusPath;
|
45036 | }
|
45037 |
|
45038 | selection = selection.merge(properties);
|
45039 | selection = selection.normalize(document);
|
45040 | state = state.set('selection', selection);
|
45041 | return state;
|
45042 | },
|
45043 |
|
45044 |
|
45045 | /**
|
45046 | * Split a node by `path` at `offset`.
|
45047 | *
|
45048 | * @param {State} state
|
45049 | * @param {Object} operation
|
45050 | * @return {State}
|
45051 | */
|
45052 |
|
45053 | split_node: function split_node(state, operation) {
|
45054 | var path = operation.path,
|
45055 | position = operation.position;
|
45056 | var _state13 = state,
|
45057 | document = _state13.document,
|
45058 | selection = _state13.selection;
|
45059 |
|
45060 | // Calculate a few things...
|
45061 |
|
45062 | var node = document.assertPath(path);
|
45063 | var parent = document.getParent(node.key);
|
45064 | var index = parent.nodes.indexOf(node);
|
45065 |
|
45066 | // Split the node by its parent.
|
45067 | parent = parent.splitNode(index, position);
|
45068 | document = document.updateNode(parent);
|
45069 |
|
45070 | // Determine whether we need to update the selection...
|
45071 | var _selection5 = selection,
|
45072 | startKey = _selection5.startKey,
|
45073 | endKey = _selection5.endKey,
|
45074 | startOffset = _selection5.startOffset,
|
45075 | endOffset = _selection5.endOffset;
|
45076 |
|
45077 | var next = document.getNextText(node.key);
|
45078 | var normalize = false;
|
45079 |
|
45080 | // If the start point is after or equal to the split, update it.
|
45081 | if (node.key == startKey && position <= startOffset) {
|
45082 | selection = selection.moveStartTo(next.key, startOffset - position);
|
45083 | normalize = true;
|
45084 | }
|
45085 |
|
45086 | // If the end point is after or equal to the split, update it.
|
45087 | if (node.key == endKey && position <= endOffset) {
|
45088 | selection = selection.moveEndTo(next.key, endOffset - position);
|
45089 | normalize = true;
|
45090 | }
|
45091 |
|
45092 | // Normalize the selection if we changed it, since the methods we use might
|
45093 | // leave it in a non-normalized state.
|
45094 | if (normalize) {
|
45095 | selection = selection.normalize(document);
|
45096 | }
|
45097 |
|
45098 | // Return the updated state.
|
45099 | state = state.set('document', document).set('selection', selection);
|
45100 | return state;
|
45101 | }
|
45102 | };
|
45103 |
|
45104 | /**
|
45105 | * Apply an `operation` to a `state`.
|
45106 | *
|
45107 | * @param {State} state
|
45108 | * @param {Object} operation
|
45109 | * @return {State} state
|
45110 | */
|
45111 |
|
45112 | function applyOperation(state, operation) {
|
45113 | var type = operation.type;
|
45114 |
|
45115 | var apply = APPLIERS[type];
|
45116 |
|
45117 | if (!apply) {
|
45118 | throw new Error('Unknown operation type: "' + type + '".');
|
45119 | }
|
45120 |
|
45121 | debug(type, operation);
|
45122 | state = apply(state, operation);
|
45123 | return state;
|
45124 | }
|
45125 |
|
45126 | /**
|
45127 | * Export.
|
45128 | *
|
45129 | * @type {Function}
|
45130 | */
|
45131 |
|
45132 | exports.default = applyOperation;
|
45133 | },{"../models/mark":338,"../models/node":339,"../utils/logger":366,"debug":375}],347:[function(require,module,exports){
|
45134 | 'use strict';
|
45135 |
|
45136 | Object.defineProperty(exports, "__esModule", {
|
45137 | value: true
|
45138 | });
|
45139 |
|
45140 | var _apply = require('./apply');
|
45141 |
|
45142 | var _apply2 = _interopRequireDefault(_apply);
|
45143 |
|
45144 | var _invert = require('./invert');
|
45145 |
|
45146 | var _invert2 = _interopRequireDefault(_invert);
|
45147 |
|
45148 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
45149 |
|
45150 | /**
|
45151 | * Export.
|
45152 | *
|
45153 | * @type {Object}
|
45154 | */
|
45155 |
|
45156 | exports.default = {
|
45157 | apply: _apply2.default,
|
45158 | invert: _invert2.default
|
45159 | };
|
45160 | },{"./apply":346,"./invert":348}],348:[function(require,module,exports){
|
45161 | 'use strict';
|
45162 |
|
45163 | Object.defineProperty(exports, "__esModule", {
|
45164 | value: true
|
45165 | });
|
45166 |
|
45167 | 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; };
|
45168 |
|
45169 | var _debug = require('debug');
|
45170 |
|
45171 | var _debug2 = _interopRequireDefault(_debug);
|
45172 |
|
45173 | var _pick = require('lodash/pick');
|
45174 |
|
45175 | var _pick2 = _interopRequireDefault(_pick);
|
45176 |
|
45177 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
45178 |
|
45179 | /**
|
45180 | * Debug.
|
45181 | *
|
45182 | * @type {Function}
|
45183 | */
|
45184 |
|
45185 | var debug = (0, _debug2.default)('slate:operation:invert');
|
45186 |
|
45187 | /**
|
45188 | * Invert an `op`.
|
45189 | *
|
45190 | * @param {Object} op
|
45191 | * @return {Object}
|
45192 | */
|
45193 |
|
45194 | function invertOperation(op) {
|
45195 | var type = op.type;
|
45196 |
|
45197 | debug(type, op);
|
45198 |
|
45199 | /**
|
45200 | * Insert node.
|
45201 | */
|
45202 |
|
45203 | if (type == 'insert_node') {
|
45204 | return _extends({}, op, {
|
45205 | type: 'remove_node'
|
45206 | });
|
45207 | }
|
45208 |
|
45209 | /**
|
45210 | * Remove node.
|
45211 | */
|
45212 |
|
45213 | if (type == 'remove_node') {
|
45214 | return _extends({}, op, {
|
45215 | type: 'insert_node'
|
45216 | });
|
45217 | }
|
45218 |
|
45219 | /**
|
45220 | * Move node.
|
45221 | */
|
45222 |
|
45223 | if (type == 'move_node') {
|
45224 | return _extends({}, op, {
|
45225 | path: op.newPath,
|
45226 | newPath: op.path
|
45227 | });
|
45228 | }
|
45229 |
|
45230 | /**
|
45231 | * Merge node.
|
45232 | */
|
45233 |
|
45234 | if (type == 'merge_node') {
|
45235 | var path = op.path;
|
45236 | var length = path.length;
|
45237 |
|
45238 | var last = length - 1;
|
45239 | return _extends({}, op, {
|
45240 | type: 'split_node',
|
45241 | path: path.slice(0, last).concat([path[last] - 1])
|
45242 | });
|
45243 | }
|
45244 |
|
45245 | /**
|
45246 | * Split node.
|
45247 | */
|
45248 |
|
45249 | if (type == 'split_node') {
|
45250 | var _path = op.path;
|
45251 | var _length = _path.length;
|
45252 |
|
45253 | var _last = _length - 1;
|
45254 | return _extends({}, op, {
|
45255 | type: 'merge_node',
|
45256 | path: _path.slice(0, _last).concat([_path[_last] + 1])
|
45257 | });
|
45258 | }
|
45259 |
|
45260 | /**
|
45261 | * Set node.
|
45262 | */
|
45263 |
|
45264 | if (type == 'set_node') {
|
45265 | var properties = op.properties,
|
45266 | node = op.node;
|
45267 |
|
45268 | return _extends({}, op, {
|
45269 | node: node.merge(properties),
|
45270 | properties: (0, _pick2.default)(node, Object.keys(properties))
|
45271 | });
|
45272 | }
|
45273 |
|
45274 | /**
|
45275 | * Insert text.
|
45276 | */
|
45277 |
|
45278 | if (type == 'insert_text') {
|
45279 | return _extends({}, op, {
|
45280 | type: 'remove_text'
|
45281 | });
|
45282 | }
|
45283 |
|
45284 | /**
|
45285 | * Remove text.
|
45286 | */
|
45287 |
|
45288 | if (type == 'remove_text') {
|
45289 | return _extends({}, op, {
|
45290 | type: 'insert_text'
|
45291 | });
|
45292 | }
|
45293 |
|
45294 | /**
|
45295 | * Add mark.
|
45296 | */
|
45297 |
|
45298 | if (type == 'add_mark') {
|
45299 | return _extends({}, op, {
|
45300 | type: 'remove_mark'
|
45301 | });
|
45302 | }
|
45303 |
|
45304 | /**
|
45305 | * Remove mark.
|
45306 | */
|
45307 |
|
45308 | if (type == 'remove_mark') {
|
45309 | return _extends({}, op, {
|
45310 | type: 'add_mark'
|
45311 | });
|
45312 | }
|
45313 |
|
45314 | /**
|
45315 | * Set mark.
|
45316 | */
|
45317 |
|
45318 | if (type == 'set_mark') {
|
45319 | var _properties = op.properties,
|
45320 | mark = op.mark;
|
45321 |
|
45322 | return _extends({}, op, {
|
45323 | mark: mark.merge(_properties),
|
45324 | properties: (0, _pick2.default)(mark, Object.keys(_properties))
|
45325 | });
|
45326 | }
|
45327 |
|
45328 | /**
|
45329 | * Set selection.
|
45330 | */
|
45331 |
|
45332 | if (type == 'set_selection') {
|
45333 | var _properties2 = op.properties,
|
45334 | selection = op.selection;
|
45335 |
|
45336 | var inverse = _extends({}, op, {
|
45337 | selection: _extends({}, selection, _properties2),
|
45338 | properties: (0, _pick2.default)(selection, Object.keys(_properties2))
|
45339 | });
|
45340 |
|
45341 | return inverse;
|
45342 | }
|
45343 |
|
45344 | /**
|
45345 | * Set data.
|
45346 | */
|
45347 |
|
45348 | if (type == 'set_data') {
|
45349 | var _properties3 = op.properties,
|
45350 | data = op.data;
|
45351 |
|
45352 | return _extends({}, op, {
|
45353 | data: data.merge(_properties3),
|
45354 | properties: (0, _pick2.default)(data, Object.keys(_properties3))
|
45355 | });
|
45356 | }
|
45357 |
|
45358 | /**
|
45359 | * Unknown.
|
45360 | */
|
45361 |
|
45362 | throw new Error('Unknown op type: "' + type + '".');
|
45363 | }
|
45364 |
|
45365 | /**
|
45366 | * Export.
|
45367 | *
|
45368 | * @type {Function}
|
45369 | */
|
45370 |
|
45371 | exports.default = invertOperation;
|
45372 | },{"debug":375,"lodash/pick":508}],349:[function(require,module,exports){
|
45373 | 'use strict';
|
45374 |
|
45375 | Object.defineProperty(exports, "__esModule", {
|
45376 | value: true
|
45377 | });
|
45378 |
|
45379 | 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; };
|
45380 |
|
45381 | var _base = require('../serializers/base-64');
|
45382 |
|
45383 | var _base2 = _interopRequireDefault(_base);
|
45384 |
|
45385 | var _block = require('../models/block');
|
45386 |
|
45387 | var _block2 = _interopRequireDefault(_block);
|
45388 |
|
45389 | var _content = require('../components/content');
|
45390 |
|
45391 | var _content2 = _interopRequireDefault(_content);
|
45392 |
|
45393 | var _debug = require('debug');
|
45394 |
|
45395 | var _debug2 = _interopRequireDefault(_debug);
|
45396 |
|
45397 | var _inline = require('../models/inline');
|
45398 |
|
45399 | var _inline2 = _interopRequireDefault(_inline);
|
45400 |
|
45401 | var _plain = require('../serializers/plain');
|
45402 |
|
45403 | var _plain2 = _interopRequireDefault(_plain);
|
45404 |
|
45405 | var _placeholder = require('../components/placeholder');
|
45406 |
|
45407 | var _placeholder2 = _interopRequireDefault(_placeholder);
|
45408 |
|
45409 | var _react = require('react');
|
45410 |
|
45411 | var _react2 = _interopRequireDefault(_react);
|
45412 |
|
45413 | var _getPoint = require('../utils/get-point');
|
45414 |
|
45415 | var _getPoint2 = _interopRequireDefault(_getPoint);
|
45416 |
|
45417 | var _getWindow = require('get-window');
|
45418 |
|
45419 | var _getWindow2 = _interopRequireDefault(_getWindow);
|
45420 |
|
45421 | var _findDomNode = require('../utils/find-dom-node');
|
45422 |
|
45423 | var _findDomNode2 = _interopRequireDefault(_findDomNode);
|
45424 |
|
45425 | var _environment = require('../constants/environment');
|
45426 |
|
45427 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
45428 |
|
45429 | /**
|
45430 | * Debug.
|
45431 | *
|
45432 | * @type {Function}
|
45433 | */
|
45434 |
|
45435 | var debug = (0, _debug2.default)('slate:core');
|
45436 |
|
45437 | /**
|
45438 | * The default plugin.
|
45439 | *
|
45440 | * @param {Object} options
|
45441 | * @property {Element} placeholder
|
45442 | * @property {String} placeholderClassName
|
45443 | * @property {Object} placeholderStyle
|
45444 | * @return {Object}
|
45445 | */
|
45446 |
|
45447 | function Plugin() {
|
45448 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
45449 | var placeholder = options.placeholder,
|
45450 | placeholderClassName = options.placeholderClassName,
|
45451 | placeholderStyle = options.placeholderStyle;
|
45452 |
|
45453 | /**
|
45454 | * On before change, enforce the editor's schema.
|
45455 | *
|
45456 | * @param {Change} change
|
45457 | * @param {Editor} schema
|
45458 | */
|
45459 |
|
45460 | function onBeforeChange(change, editor) {
|
45461 | var state = change.state;
|
45462 |
|
45463 | var schema = editor.getSchema();
|
45464 | var prevState = editor.getState();
|
45465 |
|
45466 | // PERF: Skip normalizing if the document hasn't changed, since the core
|
45467 | // schema only normalizes changes to the document, not selection.
|
45468 | if (prevState && state.document == prevState.document) return;
|
45469 |
|
45470 | change.normalize(schema);
|
45471 | debug('onBeforeChange');
|
45472 | }
|
45473 |
|
45474 | /**
|
45475 | * On before input, correct any browser inconsistencies.
|
45476 | *
|
45477 | * @param {Event} e
|
45478 | * @param {Object} data
|
45479 | * @param {Change} change
|
45480 | * @param {Editor} editor
|
45481 | */
|
45482 |
|
45483 | function onBeforeInput(e, data, change, editor) {
|
45484 | debug('onBeforeInput', { data: data });
|
45485 | e.preventDefault();
|
45486 |
|
45487 | var state = change.state;
|
45488 | var selection = state.selection;
|
45489 | var anchorKey = selection.anchorKey,
|
45490 | anchorOffset = selection.anchorOffset,
|
45491 | focusKey = selection.focusKey,
|
45492 | focusOffset = selection.focusOffset;
|
45493 |
|
45494 | // COMPAT: In iOS, when using predictive text suggestions, the native
|
45495 | // selection will be changed to span the existing word, so that the word is
|
45496 | // replaced. But the `select` fires after the `beforeInput` event, even
|
45497 | // though the native selection is updated. So we need to manually check if
|
45498 | // the selection has gotten out of sync, and adjust it if so. (03/18/2017)
|
45499 |
|
45500 | var window = (0, _getWindow2.default)(e.target);
|
45501 | var native = window.getSelection();
|
45502 | var a = (0, _getPoint2.default)(native.anchorNode, native.anchorOffset, state, editor);
|
45503 | var f = (0, _getPoint2.default)(native.focusNode, native.focusOffset, state, editor);
|
45504 | var hasMismatch = a && f && (anchorKey != a.key || anchorOffset != a.offset || focusKey != f.key || focusOffset != f.offset);
|
45505 |
|
45506 | if (hasMismatch) {
|
45507 | change.select({
|
45508 | anchorKey: a.key,
|
45509 | anchorOffset: a.offset,
|
45510 | focusKey: f.key,
|
45511 | focusOffset: f.offset
|
45512 | });
|
45513 | }
|
45514 |
|
45515 | change.insertText(e.data);
|
45516 | }
|
45517 |
|
45518 | /**
|
45519 | * On blur.
|
45520 | *
|
45521 | * @param {Event} e
|
45522 | * @param {Object} data
|
45523 | * @param {Change} change
|
45524 | */
|
45525 |
|
45526 | function onBlur(e, data, change) {
|
45527 | debug('onBlur', { data: data });
|
45528 | change.blur();
|
45529 | }
|
45530 |
|
45531 | /**
|
45532 | * On copy.
|
45533 | *
|
45534 | * @param {Event} e
|
45535 | * @param {Object} data
|
45536 | * @param {Change} change
|
45537 | */
|
45538 |
|
45539 | function onCopy(e, data, change) {
|
45540 | debug('onCopy', data);
|
45541 | onCutOrCopy(e, data, change);
|
45542 | }
|
45543 |
|
45544 | /**
|
45545 | * On cut.
|
45546 | *
|
45547 | * @param {Event} e
|
45548 | * @param {Object} data
|
45549 | * @param {Change} change
|
45550 | * @param {Editor} editor
|
45551 | */
|
45552 |
|
45553 | function onCut(e, data, change, editor) {
|
45554 | debug('onCut', data);
|
45555 | onCutOrCopy(e, data, change);
|
45556 | var window = (0, _getWindow2.default)(e.target);
|
45557 |
|
45558 | // Once the fake cut content has successfully been added to the clipboard,
|
45559 | // delete the content in the current selection.
|
45560 | window.requestAnimationFrame(function () {
|
45561 | editor.change(function (t) {
|
45562 | return t.delete();
|
45563 | });
|
45564 | });
|
45565 | }
|
45566 |
|
45567 | /**
|
45568 | * On cut or copy, create a fake selection so that we can add a Base 64
|
45569 | * encoded copy of the fragment to the HTML, to decode on future pastes.
|
45570 | *
|
45571 | * @param {Event} e
|
45572 | * @param {Object} data
|
45573 | * @param {Change} change
|
45574 | */
|
45575 |
|
45576 | function onCutOrCopy(e, data, change) {
|
45577 | var window = (0, _getWindow2.default)(e.target);
|
45578 | var native = window.getSelection();
|
45579 | var state = change.state;
|
45580 | var endBlock = state.endBlock,
|
45581 | endInline = state.endInline;
|
45582 |
|
45583 | var isVoidBlock = endBlock && endBlock.isVoid;
|
45584 | var isVoidInline = endInline && endInline.isVoid;
|
45585 | var isVoid = isVoidBlock || isVoidInline;
|
45586 |
|
45587 | // If the selection is collapsed, and it isn't inside a void node, abort.
|
45588 | if (native.isCollapsed && !isVoid) return;
|
45589 |
|
45590 | var fragment = data.fragment;
|
45591 |
|
45592 | var encoded = _base2.default.serializeNode(fragment);
|
45593 | var range = native.getRangeAt(0);
|
45594 | var contents = range.cloneContents();
|
45595 | var attach = contents.childNodes[0];
|
45596 |
|
45597 | // If the end node is a void node, we need to move the end of the range from
|
45598 | // the void node's spacer span, to the end of the void node's content.
|
45599 | if (isVoid) {
|
45600 | var _r = range.cloneRange();
|
45601 | var node = (0, _findDomNode2.default)(isVoidBlock ? endBlock : endInline);
|
45602 | _r.setEndAfter(node);
|
45603 | contents = _r.cloneContents();
|
45604 | attach = contents.childNodes[contents.childNodes.length - 1].firstChild;
|
45605 | }
|
45606 |
|
45607 | // Remove any zero-width space spans from the cloned DOM so that they don't
|
45608 | // show up elsewhere when pasted.
|
45609 | var zws = [].slice.call(contents.querySelectorAll('[data-slate-zero-width]'));
|
45610 | zws.forEach(function (zw) {
|
45611 | return zw.parentNode.removeChild(zw);
|
45612 | });
|
45613 |
|
45614 | // COMPAT: In Chrome and Safari, if the last element in the selection to
|
45615 | // copy has `contenteditable="false"` the copy will fail, and nothing will
|
45616 | // be put in the clipboard. So we remove them all. (2017/05/04)
|
45617 | if (_environment.IS_CHROME || _environment.IS_SAFARI) {
|
45618 | var els = [].slice.call(contents.querySelectorAll('[contenteditable="false"]'));
|
45619 | els.forEach(function (el) {
|
45620 | return el.removeAttribute('contenteditable');
|
45621 | });
|
45622 | }
|
45623 |
|
45624 | // Set a `data-slate-fragment` attribute on a non-empty node, so it shows up
|
45625 | // in the HTML, and can be used for intra-Slate pasting. If it's a text
|
45626 | // node, wrap it in a `<span>` so we have something to set an attribute on.
|
45627 | if (attach.nodeType == 3) {
|
45628 | var span = window.document.createElement('span');
|
45629 | span.appendChild(attach);
|
45630 | contents.appendChild(span);
|
45631 | attach = span;
|
45632 | }
|
45633 |
|
45634 | attach.setAttribute('data-slate-fragment', encoded);
|
45635 |
|
45636 | // Add the phony content to the DOM, and select it, so it will be copied.
|
45637 | var body = window.document.querySelector('body');
|
45638 | var div = window.document.createElement('div');
|
45639 | div.setAttribute('contenteditable', true);
|
45640 | div.style.position = 'absolute';
|
45641 | div.style.left = '-9999px';
|
45642 | div.appendChild(contents);
|
45643 | body.appendChild(div);
|
45644 |
|
45645 | // COMPAT: In Firefox, trying to use the terser `native.selectAllChildren`
|
45646 | // throws an error, so we use the older `range` equivalent. (2016/06/21)
|
45647 | var r = window.document.createRange();
|
45648 | r.selectNodeContents(div);
|
45649 | native.removeAllRanges();
|
45650 | native.addRange(r);
|
45651 |
|
45652 | // Revert to the previous selection right after copying.
|
45653 | window.requestAnimationFrame(function () {
|
45654 | body.removeChild(div);
|
45655 | native.removeAllRanges();
|
45656 | native.addRange(range);
|
45657 | });
|
45658 | }
|
45659 |
|
45660 | /**
|
45661 | * On drop.
|
45662 | *
|
45663 | * @param {Event} e
|
45664 | * @param {Object} data
|
45665 | * @param {Change} change
|
45666 | */
|
45667 |
|
45668 | function onDrop(e, data, change) {
|
45669 | debug('onDrop', { data: data });
|
45670 |
|
45671 | switch (data.type) {
|
45672 | case 'text':
|
45673 | case 'html':
|
45674 | return onDropText(e, data, change);
|
45675 | case 'fragment':
|
45676 | return onDropFragment(e, data, change);
|
45677 | case 'node':
|
45678 | return onDropNode(e, data, change);
|
45679 | }
|
45680 | }
|
45681 |
|
45682 | /**
|
45683 | * On drop node, insert the node wherever it is dropped.
|
45684 | *
|
45685 | * @param {Event} e
|
45686 | * @param {Object} data
|
45687 | * @param {Change} change
|
45688 | */
|
45689 |
|
45690 | function onDropNode(e, data, change) {
|
45691 | debug('onDropNode', { data: data });
|
45692 |
|
45693 | var state = change.state;
|
45694 | var selection = state.selection;
|
45695 | var node = data.node,
|
45696 | target = data.target,
|
45697 | isInternal = data.isInternal;
|
45698 |
|
45699 | // If the drag is internal and the target is after the selection, it
|
45700 | // needs to account for the selection's content being deleted.
|
45701 |
|
45702 | if (isInternal && selection.endKey == target.endKey && selection.endOffset < target.endOffset) {
|
45703 | target = target.move(selection.startKey == selection.endKey ? 0 - selection.endOffset + selection.startOffset : 0 - selection.endOffset);
|
45704 | }
|
45705 |
|
45706 | if (isInternal) {
|
45707 | change.delete();
|
45708 | }
|
45709 |
|
45710 | if (_block2.default.isBlock(node)) {
|
45711 | change.select(target).insertBlock(node).removeNodeByKey(node.key);
|
45712 | }
|
45713 |
|
45714 | if (_inline2.default.isInline(node)) {
|
45715 | change.select(target).insertInline(node).removeNodeByKey(node.key);
|
45716 | }
|
45717 | }
|
45718 |
|
45719 | /**
|
45720 | * On drop fragment.
|
45721 | *
|
45722 | * @param {Event} e
|
45723 | * @param {Object} data
|
45724 | * @param {Change} change
|
45725 | */
|
45726 |
|
45727 | function onDropFragment(e, data, change) {
|
45728 | debug('onDropFragment', { data: data });
|
45729 |
|
45730 | var state = change.state;
|
45731 | var selection = state.selection;
|
45732 | var fragment = data.fragment,
|
45733 | target = data.target,
|
45734 | isInternal = data.isInternal;
|
45735 |
|
45736 | // If the drag is internal and the target is after the selection, it
|
45737 | // needs to account for the selection's content being deleted.
|
45738 |
|
45739 | if (isInternal && selection.endKey == target.endKey && selection.endOffset < target.endOffset) {
|
45740 | target = target.move(selection.startKey == selection.endKey ? 0 - selection.endOffset + selection.startOffset : 0 - selection.endOffset);
|
45741 | }
|
45742 |
|
45743 | if (isInternal) {
|
45744 | change.delete();
|
45745 | }
|
45746 |
|
45747 | change.select(target).insertFragment(fragment);
|
45748 | }
|
45749 |
|
45750 | /**
|
45751 | * On drop text, split the blocks at new lines.
|
45752 | *
|
45753 | * @param {Event} e
|
45754 | * @param {Object} data
|
45755 | * @param {Change} change
|
45756 | */
|
45757 |
|
45758 | function onDropText(e, data, change) {
|
45759 | debug('onDropText', { data: data });
|
45760 |
|
45761 | var state = change.state;
|
45762 | var document = state.document;
|
45763 | var text = data.text,
|
45764 | target = data.target;
|
45765 | var anchorKey = target.anchorKey;
|
45766 |
|
45767 |
|
45768 | change.select(target);
|
45769 |
|
45770 | var hasVoidParent = document.hasVoidParent(anchorKey);
|
45771 |
|
45772 | // Insert text into nearest text node
|
45773 | if (hasVoidParent) {
|
45774 | var node = document.getNode(anchorKey);
|
45775 |
|
45776 | while (hasVoidParent) {
|
45777 | node = document.getNextText(node.key);
|
45778 | if (!node) break;
|
45779 | hasVoidParent = document.hasVoidParent(node.key);
|
45780 | }
|
45781 |
|
45782 | if (node) change.collapseToStartOf(node);
|
45783 | }
|
45784 |
|
45785 | text.split('\n').forEach(function (line, i) {
|
45786 | if (i > 0) change.splitBlock();
|
45787 | change.insertText(line);
|
45788 | });
|
45789 | }
|
45790 |
|
45791 | /**
|
45792 | * On key down.
|
45793 | *
|
45794 | * @param {Event} e
|
45795 | * @param {Object} data
|
45796 | * @param {Change} change
|
45797 | */
|
45798 |
|
45799 | function onKeyDown(e, data, change) {
|
45800 | debug('onKeyDown', { data: data });
|
45801 |
|
45802 | switch (data.key) {
|
45803 | case 'enter':
|
45804 | return onKeyDownEnter(e, data, change);
|
45805 | case 'backspace':
|
45806 | return onKeyDownBackspace(e, data, change);
|
45807 | case 'delete':
|
45808 | return onKeyDownDelete(e, data, change);
|
45809 | case 'left':
|
45810 | return onKeyDownLeft(e, data, change);
|
45811 | case 'right':
|
45812 | return onKeyDownRight(e, data, change);
|
45813 | case 'up':
|
45814 | return onKeyDownUp(e, data, change);
|
45815 | case 'down':
|
45816 | return onKeyDownDown(e, data, change);
|
45817 | case 'd':
|
45818 | return onKeyDownD(e, data, change);
|
45819 | case 'h':
|
45820 | return onKeyDownH(e, data, change);
|
45821 | case 'k':
|
45822 | return onKeyDownK(e, data, change);
|
45823 | case 'y':
|
45824 | return onKeyDownY(e, data, change);
|
45825 | case 'z':
|
45826 | return onKeyDownZ(e, data, change);
|
45827 | }
|
45828 | }
|
45829 |
|
45830 | /**
|
45831 | * On `enter` key down, split the current block in half.
|
45832 | *
|
45833 | * @param {Event} e
|
45834 | * @param {Object} data
|
45835 | * @param {Change} change
|
45836 | */
|
45837 |
|
45838 | function onKeyDownEnter(e, data, change) {
|
45839 | var state = change.state;
|
45840 | var document = state.document,
|
45841 | startKey = state.startKey;
|
45842 |
|
45843 | var hasVoidParent = document.hasVoidParent(startKey);
|
45844 |
|
45845 | // For void nodes, we don't want to split. Instead we just move to the start
|
45846 | // of the next text node if one exists.
|
45847 | if (hasVoidParent) {
|
45848 | var text = document.getNextText(startKey);
|
45849 | if (!text) return;
|
45850 | change.collapseToStartOf(text);
|
45851 | return;
|
45852 | }
|
45853 |
|
45854 | change.splitBlock();
|
45855 | }
|
45856 |
|
45857 | /**
|
45858 | * On `backspace` key down, delete backwards.
|
45859 | *
|
45860 | * @param {Event} e
|
45861 | * @param {Object} data
|
45862 | * @param {Change} change
|
45863 | */
|
45864 |
|
45865 | function onKeyDownBackspace(e, data, change) {
|
45866 | var boundary = 'Char';
|
45867 | if (data.isWord) boundary = 'Word';
|
45868 | if (data.isLine) boundary = 'Line';
|
45869 | change['delete' + boundary + 'Backward']();
|
45870 | }
|
45871 |
|
45872 | /**
|
45873 | * On `delete` key down, delete forwards.
|
45874 | *
|
45875 | * @param {Event} e
|
45876 | * @param {Object} data
|
45877 | * @param {Change} change
|
45878 | */
|
45879 |
|
45880 | function onKeyDownDelete(e, data, change) {
|
45881 | var boundary = 'Char';
|
45882 | if (data.isWord) boundary = 'Word';
|
45883 | if (data.isLine) boundary = 'Line';
|
45884 | change['delete' + boundary + 'Forward']();
|
45885 | }
|
45886 |
|
45887 | /**
|
45888 | * On `left` key down, move backward.
|
45889 | *
|
45890 | * COMPAT: This is required to make navigating with the left arrow work when
|
45891 | * a void node is selected.
|
45892 | *
|
45893 | * COMPAT: This is also required to solve for the case where an inline node is
|
45894 | * surrounded by empty text nodes with zero-width spaces in them. Without this
|
45895 | * the zero-width spaces will cause two arrow keys to jump to the next text.
|
45896 | *
|
45897 | * @param {Event} e
|
45898 | * @param {Object} data
|
45899 | * @param {Change} change
|
45900 | */
|
45901 |
|
45902 | function onKeyDownLeft(e, data, change) {
|
45903 | var state = change.state;
|
45904 |
|
45905 |
|
45906 | if (data.isCtrl) return;
|
45907 | if (data.isAlt) return;
|
45908 | if (state.isExpanded) return;
|
45909 |
|
45910 | var document = state.document,
|
45911 | startKey = state.startKey,
|
45912 | startText = state.startText;
|
45913 |
|
45914 | var hasVoidParent = document.hasVoidParent(startKey);
|
45915 |
|
45916 | // If the current text node is empty, or we're inside a void parent, we're
|
45917 | // going to need to handle the selection behavior.
|
45918 | if (startText.text == '' || hasVoidParent) {
|
45919 | e.preventDefault();
|
45920 | var previous = document.getPreviousText(startKey);
|
45921 |
|
45922 | // If there's no previous text node in the document, abort.
|
45923 | if (!previous) return;
|
45924 |
|
45925 | // If the previous text is in the current block, and inside a non-void
|
45926 | // inline node, move one character into the inline node.
|
45927 | var startBlock = state.startBlock;
|
45928 |
|
45929 | var previousBlock = document.getClosestBlock(previous.key);
|
45930 | var previousInline = document.getClosestInline(previous.key);
|
45931 |
|
45932 | if (previousBlock === startBlock && previousInline && !previousInline.isVoid) {
|
45933 | var extendOrMove = data.isShift ? 'extend' : 'move';
|
45934 | change.collapseToEndOf(previous)[extendOrMove](-1);
|
45935 | return;
|
45936 | }
|
45937 |
|
45938 | // Otherwise, move to the end of the previous node.
|
45939 | change.collapseToEndOf(previous);
|
45940 | }
|
45941 | }
|
45942 |
|
45943 | /**
|
45944 | * On `right` key down, move forward.
|
45945 | *
|
45946 | * COMPAT: This is required to make navigating with the right arrow work when
|
45947 | * a void node is selected.
|
45948 | *
|
45949 | * COMPAT: This is also required to solve for the case where an inline node is
|
45950 | * surrounded by empty text nodes with zero-width spaces in them. Without this
|
45951 | * the zero-width spaces will cause two arrow keys to jump to the next text.
|
45952 | *
|
45953 | * COMPAT: In Chrome & Safari, selections that are at the zero offset of
|
45954 | * an inline node will be automatically replaced to be at the last offset
|
45955 | * of a previous inline node, which screws us up, so we never want to set the
|
45956 | * selection to the very start of an inline node here. (2016/11/29)
|
45957 | *
|
45958 | * @param {Event} e
|
45959 | * @param {Object} data
|
45960 | * @param {Change} change
|
45961 | */
|
45962 |
|
45963 | function onKeyDownRight(e, data, change) {
|
45964 | var state = change.state;
|
45965 |
|
45966 |
|
45967 | if (data.isCtrl) return;
|
45968 | if (data.isAlt) return;
|
45969 | if (state.isExpanded) return;
|
45970 |
|
45971 | var document = state.document,
|
45972 | startKey = state.startKey,
|
45973 | startText = state.startText;
|
45974 |
|
45975 | var hasVoidParent = document.hasVoidParent(startKey);
|
45976 |
|
45977 | // If the current text node is empty, or we're inside a void parent, we're
|
45978 | // going to need to handle the selection behavior.
|
45979 | if (startText.text == '' || hasVoidParent) {
|
45980 | e.preventDefault();
|
45981 | var next = document.getNextText(startKey);
|
45982 |
|
45983 | // If there's no next text node in the document, abort.
|
45984 | if (!next) return;
|
45985 |
|
45986 | // If the next text is inside a void node, move to the end of it.
|
45987 | if (document.hasVoidParent(next.key)) {
|
45988 | change.collapseToEndOf(next);
|
45989 | return;
|
45990 | }
|
45991 |
|
45992 | // If the next text is in the current block, and inside an inline node,
|
45993 | // move one character into the inline node.
|
45994 | var startBlock = state.startBlock;
|
45995 |
|
45996 | var nextBlock = document.getClosestBlock(next.key);
|
45997 | var nextInline = document.getClosestInline(next.key);
|
45998 |
|
45999 | if (nextBlock == startBlock && nextInline) {
|
46000 | var extendOrMove = data.isShift ? 'extend' : 'move';
|
46001 | change.collapseToStartOf(next)[extendOrMove](1);
|
46002 | return;
|
46003 | }
|
46004 |
|
46005 | // Otherwise, move to the start of the next text node.
|
46006 | change.collapseToStartOf(next);
|
46007 | }
|
46008 | }
|
46009 |
|
46010 | /**
|
46011 | * On `up` key down, for Macs, move the selection to start of the block.
|
46012 | *
|
46013 | * COMPAT: Certain browsers don't handle the selection updates properly. In
|
46014 | * Chrome, option-shift-up doesn't properly extend the selection. And in
|
46015 | * Firefox, option-up doesn't properly move the selection.
|
46016 | *
|
46017 | * @param {Event} e
|
46018 | * @param {Object} data
|
46019 | * @param {Change} change
|
46020 | */
|
46021 |
|
46022 | function onKeyDownUp(e, data, change) {
|
46023 | if (!_environment.IS_MAC || data.isCtrl || !data.isAlt) return;
|
46024 |
|
46025 | var state = change.state;
|
46026 | var selection = state.selection,
|
46027 | document = state.document,
|
46028 | focusKey = state.focusKey,
|
46029 | focusBlock = state.focusBlock;
|
46030 |
|
46031 | var transform = data.isShift ? 'extendToStartOf' : 'collapseToStartOf';
|
46032 | var block = selection.hasFocusAtStartOf(focusBlock) ? document.getPreviousBlock(focusKey) : focusBlock;
|
46033 |
|
46034 | if (!block) return;
|
46035 | var text = block.getFirstText();
|
46036 |
|
46037 | e.preventDefault();
|
46038 | change[transform](text);
|
46039 | }
|
46040 |
|
46041 | /**
|
46042 | * On `down` key down, for Macs, move the selection to end of the block.
|
46043 | *
|
46044 | * COMPAT: Certain browsers don't handle the selection updates properly. In
|
46045 | * Chrome, option-shift-down doesn't properly extend the selection. And in
|
46046 | * Firefox, option-down doesn't properly move the selection.
|
46047 | *
|
46048 | * @param {Event} e
|
46049 | * @param {Object} data
|
46050 | * @param {Change} change
|
46051 | */
|
46052 |
|
46053 | function onKeyDownDown(e, data, change) {
|
46054 | if (!_environment.IS_MAC || data.isCtrl || !data.isAlt) return;
|
46055 |
|
46056 | var state = change.state;
|
46057 | var selection = state.selection,
|
46058 | document = state.document,
|
46059 | focusKey = state.focusKey,
|
46060 | focusBlock = state.focusBlock;
|
46061 |
|
46062 | var transform = data.isShift ? 'extendToEndOf' : 'collapseToEndOf';
|
46063 | var block = selection.hasFocusAtEndOf(focusBlock) ? document.getNextBlock(focusKey) : focusBlock;
|
46064 |
|
46065 | if (!block) return;
|
46066 | var text = block.getLastText();
|
46067 |
|
46068 | e.preventDefault();
|
46069 | change[transform](text);
|
46070 | }
|
46071 |
|
46072 | /**
|
46073 | * On `d` key down, for Macs, delete one character forward.
|
46074 | *
|
46075 | * @param {Event} e
|
46076 | * @param {Object} data
|
46077 | * @param {Change} change
|
46078 | */
|
46079 |
|
46080 | function onKeyDownD(e, data, change) {
|
46081 | if (!_environment.IS_MAC || !data.isCtrl) return;
|
46082 | e.preventDefault();
|
46083 | change.deleteCharForward();
|
46084 | }
|
46085 |
|
46086 | /**
|
46087 | * On `h` key down, for Macs, delete until the end of the line.
|
46088 | *
|
46089 | * @param {Event} e
|
46090 | * @param {Object} data
|
46091 | * @param {Change} change
|
46092 | */
|
46093 |
|
46094 | function onKeyDownH(e, data, change) {
|
46095 | if (!_environment.IS_MAC || !data.isCtrl) return;
|
46096 | e.preventDefault();
|
46097 | change.deleteCharBackward();
|
46098 | }
|
46099 |
|
46100 | /**
|
46101 | * On `k` key down, for Macs, delete until the end of the line.
|
46102 | *
|
46103 | * @param {Event} e
|
46104 | * @param {Object} data
|
46105 | * @param {Change} change
|
46106 | */
|
46107 |
|
46108 | function onKeyDownK(e, data, change) {
|
46109 | if (!_environment.IS_MAC || !data.isCtrl) return;
|
46110 | e.preventDefault();
|
46111 | change.deleteLineForward();
|
46112 | }
|
46113 |
|
46114 | /**
|
46115 | * On `y` key down, redo.
|
46116 | *
|
46117 | * @param {Event} e
|
46118 | * @param {Object} data
|
46119 | * @param {Change} change
|
46120 | */
|
46121 |
|
46122 | function onKeyDownY(e, data, change) {
|
46123 | if (!data.isMod) return;
|
46124 | change.redo();
|
46125 | }
|
46126 |
|
46127 | /**
|
46128 | * On `z` key down, undo or redo.
|
46129 | *
|
46130 | * @param {Event} e
|
46131 | * @param {Object} data
|
46132 | * @param {Change} change
|
46133 | */
|
46134 |
|
46135 | function onKeyDownZ(e, data, change) {
|
46136 | if (!data.isMod) return;
|
46137 | change[data.isShift ? 'redo' : 'undo']();
|
46138 | }
|
46139 |
|
46140 | /**
|
46141 | * On paste.
|
46142 | *
|
46143 | * @param {Event} e
|
46144 | * @param {Object} data
|
46145 | * @param {Change} change
|
46146 | */
|
46147 |
|
46148 | function onPaste(e, data, change) {
|
46149 | debug('onPaste', { data: data });
|
46150 |
|
46151 | switch (data.type) {
|
46152 | case 'fragment':
|
46153 | return onPasteFragment(e, data, change);
|
46154 | case 'text':
|
46155 | case 'html':
|
46156 | return onPasteText(e, data, change);
|
46157 | }
|
46158 | }
|
46159 |
|
46160 | /**
|
46161 | * On paste fragment.
|
46162 | *
|
46163 | * @param {Event} e
|
46164 | * @param {Object} data
|
46165 | * @param {Change} change
|
46166 | */
|
46167 |
|
46168 | function onPasteFragment(e, data, change) {
|
46169 | debug('onPasteFragment', { data: data });
|
46170 | change.insertFragment(data.fragment);
|
46171 | }
|
46172 |
|
46173 | /**
|
46174 | * On paste text, split blocks at new lines.
|
46175 | *
|
46176 | * @param {Event} e
|
46177 | * @param {Object} data
|
46178 | * @param {Change} change
|
46179 | */
|
46180 |
|
46181 | function onPasteText(e, data, change) {
|
46182 | debug('onPasteText', { data: data });
|
46183 |
|
46184 | var state = change.state;
|
46185 | var document = state.document,
|
46186 | selection = state.selection,
|
46187 | startBlock = state.startBlock;
|
46188 |
|
46189 | if (startBlock.isVoid) return;
|
46190 |
|
46191 | var text = data.text;
|
46192 |
|
46193 | var defaultBlock = startBlock;
|
46194 | var defaultMarks = document.getMarksAtRange(selection.collapseToStart());
|
46195 | var fragment = _plain2.default.deserialize(text, { defaultBlock: defaultBlock, defaultMarks: defaultMarks }).document;
|
46196 | change.insertFragment(fragment);
|
46197 | }
|
46198 |
|
46199 | /**
|
46200 | * On select.
|
46201 | *
|
46202 | * @param {Event} e
|
46203 | * @param {Object} data
|
46204 | * @param {Change} change
|
46205 | */
|
46206 |
|
46207 | function onSelect(e, data, change) {
|
46208 | debug('onSelect', { data: data });
|
46209 | change.select(data.selection);
|
46210 | }
|
46211 |
|
46212 | /**
|
46213 | * Render.
|
46214 | *
|
46215 | * @param {Object} props
|
46216 | * @param {State} state
|
46217 | * @param {Editor} editor
|
46218 | * @return {Object}
|
46219 | */
|
46220 |
|
46221 | function render(props, state, editor) {
|
46222 | return _react2.default.createElement(_content2.default, {
|
46223 | autoCorrect: props.autoCorrect,
|
46224 | autoFocus: props.autoFocus,
|
46225 | className: props.className,
|
46226 | children: props.children,
|
46227 | editor: editor,
|
46228 | onBeforeInput: editor.onBeforeInput,
|
46229 | onBlur: editor.onBlur,
|
46230 | onFocus: editor.onFocus,
|
46231 | onCopy: editor.onCopy,
|
46232 | onCut: editor.onCut,
|
46233 | onDrop: editor.onDrop,
|
46234 | onKeyDown: editor.onKeyDown,
|
46235 | onKeyUp: editor.onKeyUp,
|
46236 | onPaste: editor.onPaste,
|
46237 | onSelect: editor.onSelect,
|
46238 | readOnly: props.readOnly,
|
46239 | role: props.role,
|
46240 | schema: editor.getSchema(),
|
46241 | spellCheck: props.spellCheck,
|
46242 | state: state,
|
46243 | style: props.style,
|
46244 | tabIndex: props.tabIndex,
|
46245 | tagName: props.tagName
|
46246 | });
|
46247 | }
|
46248 |
|
46249 | /**
|
46250 | * A default schema rule to render block nodes.
|
46251 | *
|
46252 | * @type {Object}
|
46253 | */
|
46254 |
|
46255 | var BLOCK_RENDER_RULE = {
|
46256 | match: function match(node) {
|
46257 | return node.kind == 'block';
|
46258 | },
|
46259 | render: function render(props) {
|
46260 | return _react2.default.createElement(
|
46261 | 'div',
|
46262 | _extends({}, props.attributes, { style: { position: 'relative' } }),
|
46263 | props.children,
|
46264 | placeholder ? _react2.default.createElement(
|
46265 | _placeholder2.default,
|
46266 | {
|
46267 | className: placeholderClassName,
|
46268 | node: props.node,
|
46269 | parent: props.state.document,
|
46270 | state: props.state,
|
46271 | style: placeholderStyle
|
46272 | },
|
46273 | placeholder
|
46274 | ) : null
|
46275 | );
|
46276 | }
|
46277 | };
|
46278 |
|
46279 | /**
|
46280 | * A default schema rule to render inline nodes.
|
46281 | *
|
46282 | * @type {Object}
|
46283 | */
|
46284 |
|
46285 | var INLINE_RENDER_RULE = {
|
46286 | match: function match(node) {
|
46287 | return node.kind == 'inline';
|
46288 | },
|
46289 | render: function render(props) {
|
46290 | return _react2.default.createElement(
|
46291 | 'span',
|
46292 | _extends({}, props.attributes, { style: { position: 'relative' } }),
|
46293 | props.children
|
46294 | );
|
46295 | }
|
46296 | };
|
46297 |
|
46298 | /**
|
46299 | * Add default rendering rules to the schema.
|
46300 | *
|
46301 | * @type {Object}
|
46302 | */
|
46303 |
|
46304 | var schema = {
|
46305 | rules: [BLOCK_RENDER_RULE, INLINE_RENDER_RULE]
|
46306 | };
|
46307 |
|
46308 | /**
|
46309 | * Return the core plugin.
|
46310 | *
|
46311 | * @type {Object}
|
46312 | */
|
46313 |
|
46314 | return {
|
46315 | onBeforeChange: onBeforeChange,
|
46316 | onBeforeInput: onBeforeInput,
|
46317 | onBlur: onBlur,
|
46318 | onCopy: onCopy,
|
46319 | onCut: onCut,
|
46320 | onDrop: onDrop,
|
46321 | onKeyDown: onKeyDown,
|
46322 | onPaste: onPaste,
|
46323 | onSelect: onSelect,
|
46324 | render: render,
|
46325 | schema: schema
|
46326 | };
|
46327 | }
|
46328 |
|
46329 | /**
|
46330 | * Export.
|
46331 | *
|
46332 | * @type {Object}
|
46333 | */
|
46334 |
|
46335 | exports.default = Plugin;
|
46336 | },{"../components/content":320,"../components/placeholder":324,"../constants/environment":326,"../models/block":331,"../models/inline":337,"../serializers/base-64":351,"../serializers/plain":353,"../utils/find-dom-node":358,"../utils/get-point":362,"debug":375,"get-window":133,"react":309}],350:[function(require,module,exports){
|
46337 | 'use strict';
|
46338 |
|
46339 | Object.defineProperty(exports, "__esModule", {
|
46340 | value: true
|
46341 | });
|
46342 |
|
46343 | var _schema = require('../models/schema');
|
46344 |
|
46345 | var _schema2 = _interopRequireDefault(_schema);
|
46346 |
|
46347 | var _text = require('../models/text');
|
46348 |
|
46349 | var _text2 = _interopRequireDefault(_text);
|
46350 |
|
46351 | var _immutable = require('immutable');
|
46352 |
|
46353 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
46354 |
|
46355 | /**
|
46356 | * Options object with normalize set to `false`.
|
46357 | *
|
46358 | * @type {Object}
|
46359 | */
|
46360 |
|
46361 | var OPTS = { normalize: false };
|
46362 |
|
46363 | /**
|
46364 | * Define the core schema rules, order-sensitive.
|
46365 | *
|
46366 | * @type {Array}
|
46367 | */
|
46368 |
|
46369 | var rules = [
|
46370 |
|
46371 | /**
|
46372 | * Only allow block nodes in documents.
|
46373 | *
|
46374 | * @type {Object}
|
46375 | */
|
46376 |
|
46377 | {
|
46378 | match: function match(node) {
|
46379 | return node.kind == 'document';
|
46380 | },
|
46381 | validate: function validate(document) {
|
46382 | var invalids = document.nodes.filter(function (n) {
|
46383 | return n.kind != 'block';
|
46384 | });
|
46385 | return invalids.size ? invalids : null;
|
46386 | },
|
46387 | normalize: function normalize(change, document, invalids) {
|
46388 | invalids.forEach(function (node) {
|
46389 | change.removeNodeByKey(node.key, OPTS);
|
46390 | });
|
46391 | }
|
46392 | },
|
46393 |
|
46394 | /**
|
46395 | * Only allow block nodes or inline and text nodes in blocks.
|
46396 | *
|
46397 | * @type {Object}
|
46398 | */
|
46399 |
|
46400 | {
|
46401 | match: function match(node) {
|
46402 | return node.kind == 'block';
|
46403 | },
|
46404 | validate: function validate(block) {
|
46405 | var first = block.nodes.first();
|
46406 | if (!first) return null;
|
46407 |
|
46408 | var kinds = first.kind == 'block' ? ['block'] : ['inline', 'text'];
|
46409 |
|
46410 | var invalids = block.nodes.filter(function (n) {
|
46411 | return !kinds.includes(n.kind);
|
46412 | });
|
46413 | return invalids.size ? invalids : null;
|
46414 | },
|
46415 | normalize: function normalize(change, block, invalids) {
|
46416 | invalids.forEach(function (node) {
|
46417 | change.removeNodeByKey(node.key, OPTS);
|
46418 | });
|
46419 | }
|
46420 | },
|
46421 |
|
46422 | /**
|
46423 | * Only allow inline and text nodes in inlines.
|
46424 | *
|
46425 | * @type {Object}
|
46426 | */
|
46427 |
|
46428 | {
|
46429 | match: function match(object) {
|
46430 | return object.kind == 'inline';
|
46431 | },
|
46432 | validate: function validate(inline) {
|
46433 | var invalids = inline.nodes.filter(function (n) {
|
46434 | return n.kind != 'inline' && n.kind != 'text';
|
46435 | });
|
46436 | return invalids.size ? invalids : null;
|
46437 | },
|
46438 | normalize: function normalize(change, inline, invalids) {
|
46439 | invalids.forEach(function (node) {
|
46440 | change.removeNodeByKey(node.key, OPTS);
|
46441 | });
|
46442 | }
|
46443 | },
|
46444 |
|
46445 | /**
|
46446 | * Ensure that block and inline nodes have at least one text child.
|
46447 | *
|
46448 | * @type {Object}
|
46449 | */
|
46450 |
|
46451 | {
|
46452 | match: function match(object) {
|
46453 | return object.kind == 'block' || object.kind == 'inline';
|
46454 | },
|
46455 | validate: function validate(node) {
|
46456 | return node.nodes.size == 0;
|
46457 | },
|
46458 | normalize: function normalize(change, node) {
|
46459 | var text = _text2.default.create();
|
46460 | change.insertNodeByKey(node.key, 0, text, OPTS);
|
46461 | }
|
46462 | },
|
46463 |
|
46464 | /**
|
46465 | * Ensure that void nodes contain a text node with a single space of text.
|
46466 | *
|
46467 | * @type {Object}
|
46468 | */
|
46469 |
|
46470 | {
|
46471 | match: function match(object) {
|
46472 | return (object.kind == 'inline' || object.kind == 'block') && object.isVoid;
|
46473 | },
|
46474 | validate: function validate(node) {
|
46475 | return node.text !== ' ' || node.nodes.size !== 1;
|
46476 | },
|
46477 | normalize: function normalize(change, node, result) {
|
46478 | var text = _text2.default.create(' ');
|
46479 | var index = node.nodes.size;
|
46480 |
|
46481 | change.insertNodeByKey(node.key, index, text, OPTS);
|
46482 |
|
46483 | node.nodes.forEach(function (child) {
|
46484 | change.removeNodeByKey(child.key, OPTS);
|
46485 | });
|
46486 | }
|
46487 | },
|
46488 |
|
46489 | /**
|
46490 | * Ensure that inline nodes are never empty.
|
46491 | *
|
46492 | * This rule is applied to all blocks, because when they contain an empty
|
46493 | * inline, we need to remove the inline from that parent block. If `validate`
|
46494 | * was to be memoized, it should be against the parent node, not the inline
|
46495 | * themselves.
|
46496 | *
|
46497 | * @type {Object}
|
46498 | */
|
46499 |
|
46500 | {
|
46501 | match: function match(object) {
|
46502 | return object.kind == 'block';
|
46503 | },
|
46504 | validate: function validate(block) {
|
46505 | var invalids = block.nodes.filter(function (n) {
|
46506 | return n.kind == 'inline' && n.text == '';
|
46507 | });
|
46508 | return invalids.size ? invalids : null;
|
46509 | },
|
46510 | normalize: function normalize(change, block, invalids) {
|
46511 | // If all of the block's nodes are invalid, insert an empty text node so
|
46512 | // that the selection will be preserved when they are all removed.
|
46513 | if (block.nodes.size == invalids.size) {
|
46514 | var text = _text2.default.create();
|
46515 | change.insertNodeByKey(block.key, 1, text, OPTS);
|
46516 | }
|
46517 |
|
46518 | invalids.forEach(function (node) {
|
46519 | change.removeNodeByKey(node.key, OPTS);
|
46520 | });
|
46521 | }
|
46522 | },
|
46523 |
|
46524 | /**
|
46525 | * Ensure that inline void nodes are surrounded by text nodes, by adding extra
|
46526 | * blank text nodes if necessary.
|
46527 | *
|
46528 | * @type {Object}
|
46529 | */
|
46530 |
|
46531 | {
|
46532 | match: function match(object) {
|
46533 | return object.kind == 'block' || object.kind == 'inline';
|
46534 | },
|
46535 | validate: function validate(node) {
|
46536 | var invalids = node.nodes.reduce(function (list, child, index) {
|
46537 | if (child.kind !== 'inline') return list;
|
46538 |
|
46539 | var prev = index > 0 ? node.nodes.get(index - 1) : null;
|
46540 | var next = node.nodes.get(index + 1);
|
46541 | // We don't test if "prev" is inline, since it has already been processed in the loop
|
46542 | var insertBefore = !prev;
|
46543 | var insertAfter = !next || next.kind == 'inline';
|
46544 |
|
46545 | if (insertAfter || insertBefore) {
|
46546 | list = list.push({ insertAfter: insertAfter, insertBefore: insertBefore, index: index });
|
46547 | }
|
46548 |
|
46549 | return list;
|
46550 | }, new _immutable.List());
|
46551 |
|
46552 | return invalids.size ? invalids : null;
|
46553 | },
|
46554 | normalize: function normalize(change, block, invalids) {
|
46555 | // Shift for every text node inserted previously.
|
46556 | var shift = 0;
|
46557 |
|
46558 | invalids.forEach(function (_ref) {
|
46559 | var index = _ref.index,
|
46560 | insertAfter = _ref.insertAfter,
|
46561 | insertBefore = _ref.insertBefore;
|
46562 |
|
46563 | if (insertBefore) {
|
46564 | change.insertNodeByKey(block.key, shift + index, _text2.default.create(), OPTS);
|
46565 | shift++;
|
46566 | }
|
46567 |
|
46568 | if (insertAfter) {
|
46569 | change.insertNodeByKey(block.key, shift + index + 1, _text2.default.create(), OPTS);
|
46570 | shift++;
|
46571 | }
|
46572 | });
|
46573 | }
|
46574 | },
|
46575 |
|
46576 | /**
|
46577 | * Merge adjacent text nodes.
|
46578 | *
|
46579 | * @type {Object}
|
46580 | */
|
46581 |
|
46582 | {
|
46583 | match: function match(object) {
|
46584 | return object.kind == 'block' || object.kind == 'inline';
|
46585 | },
|
46586 | validate: function validate(node) {
|
46587 | var invalids = node.nodes.map(function (child, i) {
|
46588 | var next = node.nodes.get(i + 1);
|
46589 | if (child.kind != 'text') return;
|
46590 | if (!next || next.kind != 'text') return;
|
46591 | return next;
|
46592 | }).filter(Boolean);
|
46593 |
|
46594 | return invalids.size ? invalids : null;
|
46595 | },
|
46596 | normalize: function normalize(change, node, invalids) {
|
46597 | // Reverse the list to handle consecutive merges, since the earlier nodes
|
46598 | // will always exist after each merge.
|
46599 | invalids.reverse().forEach(function (n) {
|
46600 | return change.mergeNodeByKey(n.key, OPTS);
|
46601 | });
|
46602 | }
|
46603 | },
|
46604 |
|
46605 | /**
|
46606 | * Prevent extra empty text nodes, except when adjacent to inline void nodes.
|
46607 | *
|
46608 | * @type {Object}
|
46609 | */
|
46610 |
|
46611 | {
|
46612 | match: function match(object) {
|
46613 | return object.kind == 'block' || object.kind == 'inline';
|
46614 | },
|
46615 | validate: function validate(node) {
|
46616 | var nodes = node.nodes;
|
46617 |
|
46618 | if (nodes.size <= 1) return;
|
46619 |
|
46620 | var invalids = nodes.filter(function (desc, i) {
|
46621 | if (desc.kind != 'text') return;
|
46622 | if (desc.text.length > 0) return;
|
46623 |
|
46624 | var prev = i > 0 ? nodes.get(i - 1) : null;
|
46625 | var next = nodes.get(i + 1);
|
46626 |
|
46627 | // If it's the first node, and the next is a void, preserve it.
|
46628 | if (!prev && next.kind == 'inline') return;
|
46629 |
|
46630 | // It it's the last node, and the previous is an inline, preserve it.
|
46631 | if (!next && prev.kind == 'inline') return;
|
46632 |
|
46633 | // If it's surrounded by inlines, preserve it.
|
46634 | if (next && prev && next.kind == 'inline' && prev.kind == 'inline') return;
|
46635 |
|
46636 | // Otherwise, remove it.
|
46637 | return true;
|
46638 | });
|
46639 |
|
46640 | return invalids.size ? invalids : null;
|
46641 | },
|
46642 | normalize: function normalize(change, node, invalids) {
|
46643 | invalids.forEach(function (text) {
|
46644 | change.removeNodeByKey(text.key, OPTS);
|
46645 | });
|
46646 | }
|
46647 | }];
|
46648 |
|
46649 | /**
|
46650 | * Create the core schema.
|
46651 | *
|
46652 | * @type {Schema}
|
46653 | */
|
46654 |
|
46655 | var SCHEMA = _schema2.default.create({ rules: rules });
|
46656 |
|
46657 | /**
|
46658 | * Export.
|
46659 | *
|
46660 | * @type {Schema}
|
46661 | */
|
46662 |
|
46663 | exports.default = SCHEMA;
|
46664 | },{"../models/schema":341,"../models/text":345,"immutable":135}],351:[function(require,module,exports){
|
46665 | 'use strict';
|
46666 |
|
46667 | Object.defineProperty(exports, "__esModule", {
|
46668 | value: true
|
46669 | });
|
46670 |
|
46671 | var _state = require('../models/state');
|
46672 |
|
46673 | var _state2 = _interopRequireDefault(_state);
|
46674 |
|
46675 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
46676 |
|
46677 | /**
|
46678 | * Encode a JSON `object` as base-64 `string`.
|
46679 | *
|
46680 | * @param {Object} object
|
46681 | * @return {String}
|
46682 | */
|
46683 |
|
46684 | function encode(object) {
|
46685 | var string = JSON.stringify(object);
|
46686 | var encoded = window.btoa(window.encodeURIComponent(string));
|
46687 | return encoded;
|
46688 | }
|
46689 |
|
46690 | /**
|
46691 | * Decode a base-64 `string` to a JSON `object`.
|
46692 | *
|
46693 | * @param {String} string
|
46694 | * @return {Object}
|
46695 | */
|
46696 |
|
46697 | function decode(string) {
|
46698 | var decoded = window.decodeURIComponent(window.atob(string));
|
46699 | var object = JSON.parse(decoded);
|
46700 | return object;
|
46701 | }
|
46702 |
|
46703 | /**
|
46704 | * Deserialize a State `string`.
|
46705 | *
|
46706 | * @param {String} string
|
46707 | * @return {State}
|
46708 | */
|
46709 |
|
46710 | function deserialize(string, options) {
|
46711 | var raw = decode(string);
|
46712 | var state = _state2.default.fromJSON(raw, options);
|
46713 | return state;
|
46714 | }
|
46715 |
|
46716 | /**
|
46717 | * Deserialize a Node `string`.
|
46718 | *
|
46719 | * @param {String} string
|
46720 | * @return {Node}
|
46721 | */
|
46722 |
|
46723 | function deserializeNode(string, options) {
|
46724 | var Node = require('../models/node');
|
46725 | var raw = decode(string);
|
46726 | var node = Node.fromJSON(raw, options);
|
46727 | return node;
|
46728 | }
|
46729 |
|
46730 | /**
|
46731 | * Serialize a `state`.
|
46732 | *
|
46733 | * @param {State} state
|
46734 | * @return {String}
|
46735 | */
|
46736 |
|
46737 | function serialize(state, options) {
|
46738 | var raw = state.toJSON(options);
|
46739 | var encoded = encode(raw);
|
46740 | return encoded;
|
46741 | }
|
46742 |
|
46743 | /**
|
46744 | * Serialize a `node`.
|
46745 | *
|
46746 | * @param {Node} node
|
46747 | * @return {String}
|
46748 | */
|
46749 |
|
46750 | function serializeNode(node, options) {
|
46751 | var raw = node.toJSON(options);
|
46752 | var encoded = encode(raw);
|
46753 | return encoded;
|
46754 | }
|
46755 |
|
46756 | /**
|
46757 | * Export.
|
46758 | *
|
46759 | * @type {Object}
|
46760 | */
|
46761 |
|
46762 | exports.default = {
|
46763 | deserialize: deserialize,
|
46764 | deserializeNode: deserializeNode,
|
46765 | serialize: serialize,
|
46766 | serializeNode: serializeNode
|
46767 | };
|
46768 | },{"../models/node":339,"../models/state":344}],352:[function(require,module,exports){
|
46769 | 'use strict';
|
46770 |
|
46771 | Object.defineProperty(exports, "__esModule", {
|
46772 | value: true
|
46773 | });
|
46774 |
|
46775 | 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; };
|
46776 |
|
46777 | var _node = require('../models/node');
|
46778 |
|
46779 | var _node2 = _interopRequireDefault(_node);
|
46780 |
|
46781 | var _react = require('react');
|
46782 |
|
46783 | var _react2 = _interopRequireDefault(_react);
|
46784 |
|
46785 | var _server = require('react-dom/server');
|
46786 |
|
46787 | var _server2 = _interopRequireDefault(_server);
|
46788 |
|
46789 | var _state = require('../models/state');
|
46790 |
|
46791 | var _state2 = _interopRequireDefault(_state);
|
46792 |
|
46793 | var _logger = require('../utils/logger');
|
46794 |
|
46795 | var _logger2 = _interopRequireDefault(_logger);
|
46796 |
|
46797 | var _typeOf = require('type-of');
|
46798 |
|
46799 | var _typeOf2 = _interopRequireDefault(_typeOf);
|
46800 |
|
46801 | var _immutable = require('immutable');
|
46802 |
|
46803 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
46804 |
|
46805 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
46806 |
|
46807 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
46808 |
|
46809 | /**
|
46810 | * String.
|
46811 | *
|
46812 | * @type {String}
|
46813 | */
|
46814 |
|
46815 | var String = new _immutable.Record({
|
46816 | kind: 'string',
|
46817 | text: ''
|
46818 | });
|
46819 |
|
46820 | /**
|
46821 | * A rule to (de)serialize text nodes. This is automatically added to the HTML
|
46822 | * serializer so that users don't have to worry about text-level serialization.
|
46823 | *
|
46824 | * @type {Object}
|
46825 | */
|
46826 |
|
46827 | var TEXT_RULE = {
|
46828 | deserialize: function deserialize(el) {
|
46829 | if (el.tagName == 'br') {
|
46830 | return {
|
46831 | kind: 'text',
|
46832 | ranges: [{ text: '\n' }]
|
46833 | };
|
46834 | }
|
46835 |
|
46836 | if (el.nodeName == '#text') {
|
46837 | if (el.value && el.value.match(/<!--.*?-->/)) return;
|
46838 |
|
46839 | return {
|
46840 | kind: 'text',
|
46841 | ranges: [{ text: el.value || el.nodeValue }]
|
46842 | };
|
46843 | }
|
46844 | },
|
46845 | serialize: function serialize(obj, children) {
|
46846 | if (obj.kind == 'string') {
|
46847 | return children.split('\n').reduce(function (array, text, i) {
|
46848 | if (i != 0) array.push(_react2.default.createElement('br', null));
|
46849 | array.push(text);
|
46850 | return array;
|
46851 | }, []);
|
46852 | }
|
46853 | }
|
46854 | };
|
46855 |
|
46856 | /**
|
46857 | * A default `parseHtml` option using the native `DOMParser`.
|
46858 | *
|
46859 | * @param {String} html
|
46860 | * @return {Object}
|
46861 | */
|
46862 |
|
46863 | function defaultParseHtml(html) {
|
46864 | if (typeof DOMParser == 'undefined') {
|
46865 | throw new Error('The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.');
|
46866 | }
|
46867 |
|
46868 | var parsed = new DOMParser().parseFromString(html, 'text/html');
|
46869 | // Unwrap from <html> and <body>.
|
46870 | var fragment = parsed.childNodes[0].childNodes[1];
|
46871 | return fragment;
|
46872 | }
|
46873 |
|
46874 | /**
|
46875 | * HTML serializer.
|
46876 | *
|
46877 | * @type {Html}
|
46878 | */
|
46879 |
|
46880 | var Html =
|
46881 |
|
46882 | /**
|
46883 | * Create a new serializer with `rules`.
|
46884 | *
|
46885 | * @param {Object} options
|
46886 | * @property {Array} rules
|
46887 | * @property {String|Object|Block} defaultBlock
|
46888 | * @property {Function} parseHtml
|
46889 | */
|
46890 |
|
46891 | function Html() {
|
46892 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
46893 |
|
46894 | _classCallCheck(this, Html);
|
46895 |
|
46896 | _initialiseProps.call(this);
|
46897 |
|
46898 | var _options$defaultBlock = options.defaultBlock,
|
46899 | defaultBlock = _options$defaultBlock === undefined ? 'paragraph' : _options$defaultBlock,
|
46900 | _options$parseHtml = options.parseHtml,
|
46901 | parseHtml = _options$parseHtml === undefined ? defaultParseHtml : _options$parseHtml,
|
46902 | _options$rules = options.rules,
|
46903 | rules = _options$rules === undefined ? [] : _options$rules;
|
46904 |
|
46905 |
|
46906 | if (options.defaultBlockType) {
|
46907 | _logger2.default.deprecate('0.23.0', 'The `options.defaultBlockType` argument of the `Html` serializer is deprecated, use `options.defaultBlock` instead.');
|
46908 | defaultBlock = options.defaultBlockType;
|
46909 | }
|
46910 |
|
46911 | defaultBlock = _node2.default.createProperties(defaultBlock);
|
46912 |
|
46913 | this.rules = [].concat(_toConsumableArray(rules), [TEXT_RULE]);
|
46914 | this.defaultBlock = defaultBlock;
|
46915 | this.parseHtml = parseHtml;
|
46916 | }
|
46917 |
|
46918 | /**
|
46919 | * Deserialize pasted HTML.
|
46920 | *
|
46921 | * @param {String} html
|
46922 | * @param {Object} options
|
46923 | * @property {Boolean} toRaw
|
46924 | * @return {State}
|
46925 | */
|
46926 |
|
46927 | /**
|
46928 | * Deserialize an array of DOM elements.
|
46929 | *
|
46930 | * @param {Array} elements
|
46931 | * @return {Array}
|
46932 | */
|
46933 |
|
46934 | /**
|
46935 | * Deserialize a DOM element.
|
46936 | *
|
46937 | * @param {Object} element
|
46938 | * @return {Any}
|
46939 | */
|
46940 |
|
46941 | /**
|
46942 | * Deserialize a `mark` object.
|
46943 | *
|
46944 | * @param {Object} mark
|
46945 | * @return {Array}
|
46946 | */
|
46947 |
|
46948 | /**
|
46949 | * Serialize a `state` object into an HTML string.
|
46950 | *
|
46951 | * @param {State} state
|
46952 | * @param {Object} options
|
46953 | * @property {Boolean} render
|
46954 | * @return {String|Array}
|
46955 | */
|
46956 |
|
46957 | /**
|
46958 | * Serialize a `node`.
|
46959 | *
|
46960 | * @param {Node} node
|
46961 | * @return {String}
|
46962 | */
|
46963 |
|
46964 | /**
|
46965 | * Serialize a `range`.
|
46966 | *
|
46967 | * @param {Range} range
|
46968 | * @return {String}
|
46969 | */
|
46970 |
|
46971 | /**
|
46972 | * Serialize a `string`.
|
46973 | *
|
46974 | * @param {String} string
|
46975 | * @return {String}
|
46976 | */
|
46977 |
|
46978 | /**
|
46979 | * Filter out cruft newline nodes inserted by the DOM parser.
|
46980 | *
|
46981 | * @param {Object} element
|
46982 | * @return {Boolean}
|
46983 | */
|
46984 |
|
46985 | ;
|
46986 |
|
46987 | /**
|
46988 | * Add a unique key to a React `element`.
|
46989 | *
|
46990 | * @param {Element} element
|
46991 | * @return {Element}
|
46992 | */
|
46993 |
|
46994 | var _initialiseProps = function _initialiseProps() {
|
46995 | var _this = this;
|
46996 |
|
46997 | this.deserialize = function (html) {
|
46998 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
46999 | var _options$toJSON = options.toJSON,
|
47000 | toJSON = _options$toJSON === undefined ? false : _options$toJSON;
|
47001 |
|
47002 |
|
47003 | if (options.toRaw) {
|
47004 | _logger2.default.deprecate('0.23.0', 'The `options.toRaw` argument of the `Html` serializer is deprecated, use `options.toJSON` instead.');
|
47005 | toJSON = options.toRaw;
|
47006 | }
|
47007 |
|
47008 | var defaultBlock = _this.defaultBlock,
|
47009 | parseHtml = _this.parseHtml;
|
47010 |
|
47011 | var fragment = parseHtml(html);
|
47012 | var children = Array.from(fragment.childNodes);
|
47013 | var nodes = _this.deserializeElements(children);
|
47014 |
|
47015 | // COMPAT: ensure that all top-level inline nodes are wrapped into a block.
|
47016 | nodes = nodes.reduce(function (memo, node, i, original) {
|
47017 | if (node.kind == 'block') {
|
47018 | memo.push(node);
|
47019 | return memo;
|
47020 | }
|
47021 |
|
47022 | if (i > 0 && original[i - 1].kind != 'block') {
|
47023 | var _block = memo[memo.length - 1];
|
47024 | _block.nodes.push(node);
|
47025 | return memo;
|
47026 | }
|
47027 |
|
47028 | var block = _extends({
|
47029 | kind: 'block',
|
47030 | data: {},
|
47031 | isVoid: false
|
47032 | }, defaultBlock, {
|
47033 | nodes: [node]
|
47034 | });
|
47035 |
|
47036 | memo.push(block);
|
47037 | return memo;
|
47038 | }, []);
|
47039 |
|
47040 | // TODO: pretty sure this is no longer needed.
|
47041 | if (nodes.length == 0) {
|
47042 | nodes = [_extends({
|
47043 | kind: 'block',
|
47044 | data: {},
|
47045 | isVoid: false
|
47046 | }, defaultBlock, {
|
47047 | nodes: [{
|
47048 | kind: 'text',
|
47049 | ranges: [{
|
47050 | kind: 'range',
|
47051 | text: '',
|
47052 | marks: []
|
47053 | }]
|
47054 | }]
|
47055 | })];
|
47056 | }
|
47057 |
|
47058 | var json = {
|
47059 | kind: 'state',
|
47060 | document: {
|
47061 | kind: 'document',
|
47062 | data: {},
|
47063 | nodes: nodes
|
47064 | }
|
47065 | };
|
47066 |
|
47067 | var ret = toJSON ? json : _state2.default.fromJSON(json);
|
47068 | return ret;
|
47069 | };
|
47070 |
|
47071 | this.deserializeElements = function () {
|
47072 | var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
47073 |
|
47074 | var nodes = [];
|
47075 |
|
47076 | elements.filter(_this.cruftNewline).forEach(function (element) {
|
47077 | var node = _this.deserializeElement(element);
|
47078 | switch ((0, _typeOf2.default)(node)) {
|
47079 | case 'array':
|
47080 | nodes = nodes.concat(node);
|
47081 | break;
|
47082 | case 'object':
|
47083 | nodes.push(node);
|
47084 | break;
|
47085 | }
|
47086 | });
|
47087 |
|
47088 | return nodes;
|
47089 | };
|
47090 |
|
47091 | this.deserializeElement = function (element) {
|
47092 | var node = void 0;
|
47093 |
|
47094 | if (!element.tagName) {
|
47095 | element.tagName = '';
|
47096 | }
|
47097 |
|
47098 | var next = function next(elements) {
|
47099 | if (typeof NodeList !== 'undefined' && elements instanceof NodeList) {
|
47100 | elements = Array.from(elements);
|
47101 | }
|
47102 | switch ((0, _typeOf2.default)(elements)) {
|
47103 | case 'array':
|
47104 | return _this.deserializeElements(elements);
|
47105 | case 'object':
|
47106 | return _this.deserializeElement(elements);
|
47107 | case 'null':
|
47108 | case 'undefined':
|
47109 | return;
|
47110 | default:
|
47111 | throw new Error('The `next` argument was called with invalid children: "' + elements + '".');
|
47112 | }
|
47113 | };
|
47114 |
|
47115 | for (var i = 0; i < _this.rules.length; i++) {
|
47116 | var rule = _this.rules[i];
|
47117 | if (!rule.deserialize) continue;
|
47118 | var ret = rule.deserialize(element, next);
|
47119 | var type = (0, _typeOf2.default)(ret);
|
47120 |
|
47121 | if (type != 'array' && type != 'object' && type != 'null' && type != 'undefined') {
|
47122 | throw new Error('A rule returned an invalid deserialized representation: "' + node + '".');
|
47123 | }
|
47124 |
|
47125 | if (ret === undefined) {
|
47126 | continue;
|
47127 | } else if (ret === null) {
|
47128 | return null;
|
47129 | } else if (ret.kind == 'mark') {
|
47130 | node = _this.deserializeMark(ret);
|
47131 | } else {
|
47132 | node = ret;
|
47133 | }
|
47134 |
|
47135 | break;
|
47136 | }
|
47137 |
|
47138 | return node || next(element.childNodes);
|
47139 | };
|
47140 |
|
47141 | this.deserializeMark = function (mark) {
|
47142 | var type = mark.type,
|
47143 | data = mark.data;
|
47144 |
|
47145 |
|
47146 | var applyMark = function applyMark(node) {
|
47147 | if (node.kind == 'mark') {
|
47148 | return _this.deserializeMark(node);
|
47149 | } else if (node.kind == 'text') {
|
47150 | node.ranges = node.ranges.map(function (range) {
|
47151 | range.marks = range.marks || [];
|
47152 | range.marks.push({ type: type, data: data });
|
47153 | return range;
|
47154 | });
|
47155 | } else {
|
47156 | node.nodes = node.nodes.map(applyMark);
|
47157 | }
|
47158 |
|
47159 | return node;
|
47160 | };
|
47161 |
|
47162 | return mark.nodes.reduce(function (nodes, node) {
|
47163 | var ret = applyMark(node);
|
47164 | if (Array.isArray(ret)) return nodes.concat(ret);
|
47165 | nodes.push(ret);
|
47166 | return nodes;
|
47167 | }, []);
|
47168 | };
|
47169 |
|
47170 | this.serialize = function (state) {
|
47171 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47172 | var document = state.document;
|
47173 |
|
47174 | var elements = document.nodes.map(_this.serializeNode);
|
47175 | if (options.render === false) return elements;
|
47176 |
|
47177 | var html = _server2.default.renderToStaticMarkup(_react2.default.createElement(
|
47178 | 'body',
|
47179 | null,
|
47180 | elements
|
47181 | ));
|
47182 | var inner = html.slice(6, -7);
|
47183 | return inner;
|
47184 | };
|
47185 |
|
47186 | this.serializeNode = function (node) {
|
47187 | if (node.kind == 'text') {
|
47188 | var ranges = node.getRanges();
|
47189 | return ranges.map(_this.serializeRange);
|
47190 | }
|
47191 |
|
47192 | var children = node.nodes.map(_this.serializeNode);
|
47193 |
|
47194 | for (var i = 0; i < _this.rules.length; i++) {
|
47195 | var rule = _this.rules[i];
|
47196 | if (!rule.serialize) continue;
|
47197 | var ret = rule.serialize(node, children);
|
47198 | if (ret) return addKey(ret);
|
47199 | }
|
47200 |
|
47201 | throw new Error('No serializer defined for node of type "' + node.type + '".');
|
47202 | };
|
47203 |
|
47204 | this.serializeRange = function (range) {
|
47205 | var string = new String({ text: range.text });
|
47206 | var text = _this.serializeString(string);
|
47207 |
|
47208 | return range.marks.reduce(function (children, mark) {
|
47209 | for (var i = 0; i < _this.rules.length; i++) {
|
47210 | var rule = _this.rules[i];
|
47211 | if (!rule.serialize) continue;
|
47212 | var ret = rule.serialize(mark, children);
|
47213 | if (ret) return addKey(ret);
|
47214 | }
|
47215 |
|
47216 | throw new Error('No serializer defined for mark of type "' + mark.type + '".');
|
47217 | }, text);
|
47218 | };
|
47219 |
|
47220 | this.serializeString = function (string) {
|
47221 | for (var i = 0; i < _this.rules.length; i++) {
|
47222 | var rule = _this.rules[i];
|
47223 | if (!rule.serialize) continue;
|
47224 | var ret = rule.serialize(string, string.text);
|
47225 | if (ret) return ret;
|
47226 | }
|
47227 | };
|
47228 |
|
47229 | this.cruftNewline = function (element) {
|
47230 | return !(element.nodeName == '#text' && element.value == '\n');
|
47231 | };
|
47232 | };
|
47233 |
|
47234 | var key = 0;
|
47235 |
|
47236 | function addKey(element) {
|
47237 | return _react2.default.cloneElement(element, { key: key++ });
|
47238 | }
|
47239 |
|
47240 | /**
|
47241 | * Export.
|
47242 | *
|
47243 | * @type {Html}
|
47244 | */
|
47245 |
|
47246 | exports.default = Html;
|
47247 | },{"../models/node":339,"../models/state":344,"../utils/logger":366,"immutable":135,"react":309,"react-dom/server":283,"type-of":517}],353:[function(require,module,exports){
|
47248 | 'use strict';
|
47249 |
|
47250 | Object.defineProperty(exports, "__esModule", {
|
47251 | value: true
|
47252 | });
|
47253 |
|
47254 | 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; };
|
47255 |
|
47256 | var _block = require('../models/block');
|
47257 |
|
47258 | var _block2 = _interopRequireDefault(_block);
|
47259 |
|
47260 | var _mark = require('../models/mark');
|
47261 |
|
47262 | var _mark2 = _interopRequireDefault(_mark);
|
47263 |
|
47264 | var _node = require('../models/node');
|
47265 |
|
47266 | var _node2 = _interopRequireDefault(_node);
|
47267 |
|
47268 | var _state = require('../models/state');
|
47269 |
|
47270 | var _state2 = _interopRequireDefault(_state);
|
47271 |
|
47272 | var _logger = require('../utils/logger');
|
47273 |
|
47274 | var _logger2 = _interopRequireDefault(_logger);
|
47275 |
|
47276 | var _immutable = require('immutable');
|
47277 |
|
47278 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
47279 |
|
47280 | /**
|
47281 | * Deserialize a plain text `string` to a state.
|
47282 | *
|
47283 | * @param {String} string
|
47284 | * @param {Object} options
|
47285 | * @property {Boolean} toJSON
|
47286 | * @property {String|Object|Block} defaultBlock
|
47287 | * @property {Array|Set} defaultMarks
|
47288 | * @return {State}
|
47289 | */
|
47290 |
|
47291 | function deserialize(string) {
|
47292 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47293 | var _options$defaultBlock = options.defaultBlock,
|
47294 | defaultBlock = _options$defaultBlock === undefined ? 'line' : _options$defaultBlock,
|
47295 | _options$defaultMarks = options.defaultMarks,
|
47296 | defaultMarks = _options$defaultMarks === undefined ? [] : _options$defaultMarks,
|
47297 | _options$toJSON = options.toJSON,
|
47298 | toJSON = _options$toJSON === undefined ? false : _options$toJSON;
|
47299 |
|
47300 |
|
47301 | if (options.toRaw) {
|
47302 | _logger2.default.deprecate('0.23.0', 'The `options.toRaw` argument of the `Plain` serializer is deprecated, use `options.toJSON` instead.');
|
47303 | toJSON = options.toRaw;
|
47304 | }
|
47305 |
|
47306 | if (_immutable.Set.isSet(defaultMarks)) {
|
47307 | defaultMarks = defaultMarks.toArray();
|
47308 | }
|
47309 |
|
47310 | defaultBlock = _node2.default.createProperties(defaultBlock);
|
47311 | defaultMarks = defaultMarks.map(_mark2.default.createProperties);
|
47312 |
|
47313 | var json = {
|
47314 | kind: 'state',
|
47315 | document: {
|
47316 | kind: 'document',
|
47317 | data: {},
|
47318 | nodes: string.split('\n').map(function (line) {
|
47319 | return _extends({}, defaultBlock, {
|
47320 | kind: 'block',
|
47321 | isVoid: false,
|
47322 | data: {},
|
47323 | nodes: [{
|
47324 | kind: 'text',
|
47325 | ranges: [{
|
47326 | kind: 'range',
|
47327 | text: line,
|
47328 | marks: defaultMarks
|
47329 | }]
|
47330 | }]
|
47331 | });
|
47332 | })
|
47333 | }
|
47334 | };
|
47335 |
|
47336 | var ret = toJSON ? json : _state2.default.fromJSON(json);
|
47337 | return ret;
|
47338 | }
|
47339 |
|
47340 | /**
|
47341 | * Serialize a `state` to plain text.
|
47342 | *
|
47343 | * @param {State} state
|
47344 | * @return {String}
|
47345 | */
|
47346 |
|
47347 | function serialize(state) {
|
47348 | return serializeNode(state.document);
|
47349 | }
|
47350 |
|
47351 | /**
|
47352 | * Serialize a `node` to plain text.
|
47353 | *
|
47354 | * @param {Node} node
|
47355 | * @return {String}
|
47356 | */
|
47357 |
|
47358 | function serializeNode(node) {
|
47359 | if (node.kind == 'document' || node.kind == 'block' && _block2.default.isBlockList(node.nodes)) {
|
47360 | return node.nodes.map(serializeNode).join('\n');
|
47361 | } else {
|
47362 | return node.text;
|
47363 | }
|
47364 | }
|
47365 |
|
47366 | /**
|
47367 | * Export.
|
47368 | *
|
47369 | * @type {Object}
|
47370 | */
|
47371 |
|
47372 | exports.default = {
|
47373 | deserialize: deserialize,
|
47374 | serialize: serialize
|
47375 | };
|
47376 | },{"../models/block":331,"../models/mark":338,"../models/node":339,"../models/state":344,"../utils/logger":366,"immutable":135}],354:[function(require,module,exports){
|
47377 | 'use strict';
|
47378 |
|
47379 | Object.defineProperty(exports, "__esModule", {
|
47380 | value: true
|
47381 | });
|
47382 |
|
47383 | var _block = require('../models/block');
|
47384 |
|
47385 | var _block2 = _interopRequireDefault(_block);
|
47386 |
|
47387 | var _document = require('../models/document');
|
47388 |
|
47389 | var _document2 = _interopRequireDefault(_document);
|
47390 |
|
47391 | var _inline = require('../models/inline');
|
47392 |
|
47393 | var _inline2 = _interopRequireDefault(_inline);
|
47394 |
|
47395 | var _mark = require('../models/mark');
|
47396 |
|
47397 | var _mark2 = _interopRequireDefault(_mark);
|
47398 |
|
47399 | var _range = require('../models/range');
|
47400 |
|
47401 | var _range2 = _interopRequireDefault(_range);
|
47402 |
|
47403 | var _selection = require('../models/selection');
|
47404 |
|
47405 | var _selection2 = _interopRequireDefault(_selection);
|
47406 |
|
47407 | var _state = require('../models/state');
|
47408 |
|
47409 | var _state2 = _interopRequireDefault(_state);
|
47410 |
|
47411 | var _text = require('../models/text');
|
47412 |
|
47413 | var _text2 = _interopRequireDefault(_text);
|
47414 |
|
47415 | var _isEmpty = require('is-empty');
|
47416 |
|
47417 | var _isEmpty2 = _interopRequireDefault(_isEmpty);
|
47418 |
|
47419 | var _logger = require('../utils/logger');
|
47420 |
|
47421 | var _logger2 = _interopRequireDefault(_logger);
|
47422 |
|
47423 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
47424 |
|
47425 | /**
|
47426 | * Deprecation helper.
|
47427 | */
|
47428 |
|
47429 | var logged = false;
|
47430 |
|
47431 | function deprecate(options) {
|
47432 | if (logged) {
|
47433 | return;
|
47434 | }
|
47435 |
|
47436 | if (options.terse) {
|
47437 | _logger2.default.deprecate('0.23.0', 'The `terse` option for raw serialization is deprecated and will be removed in a future release.');
|
47438 | }
|
47439 |
|
47440 | _logger2.default.deprecate('0.23.0', 'The `Raw` serializer is deprecated, please use `Model.fromJSON` and `model.toJSON` instead.');
|
47441 | logged = true;
|
47442 | }
|
47443 |
|
47444 | /**
|
47445 | * Raw.
|
47446 | *
|
47447 | * @type {Object}
|
47448 | */
|
47449 |
|
47450 | var Raw = {
|
47451 |
|
47452 | /**
|
47453 | * Deserialize a JSON `object`.
|
47454 | *
|
47455 | * @param {Object} object
|
47456 | * @param {Object} options (optional)
|
47457 | * @return {State}
|
47458 | */
|
47459 |
|
47460 | deserialize: function deserialize(object) {
|
47461 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47462 |
|
47463 | return Raw.deserializeState(object, options);
|
47464 | },
|
47465 |
|
47466 |
|
47467 | /**
|
47468 | * Deserialize a JSON `object` representing a `Block`.
|
47469 | *
|
47470 | * @param {Object} object
|
47471 | * @param {Object} options (optional)
|
47472 | * @return {Block}
|
47473 | */
|
47474 |
|
47475 | deserializeBlock: function deserializeBlock(object) {
|
47476 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47477 |
|
47478 | deprecate(options);
|
47479 |
|
47480 | if (options.terse) {
|
47481 | object = Raw.untersifyBlock(object);
|
47482 | object.nodes = object.nodes.map(function (node) {
|
47483 | return Raw.deserializeNode(node, options);
|
47484 | });
|
47485 | }
|
47486 |
|
47487 | return _block2.default.fromJSON(object);
|
47488 | },
|
47489 |
|
47490 |
|
47491 | /**
|
47492 | * Deserialize a JSON `object` representing a `Document`.
|
47493 | *
|
47494 | * @param {Object} object
|
47495 | * @param {Object} options (optional)
|
47496 | * @return {Document}
|
47497 | */
|
47498 |
|
47499 | deserializeDocument: function deserializeDocument(object) {
|
47500 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47501 |
|
47502 | deprecate(options);
|
47503 |
|
47504 | if (options.terse) {
|
47505 | object.nodes = object.nodes.map(function (node) {
|
47506 | return Raw.deserializeNode(node, options);
|
47507 | });
|
47508 | }
|
47509 |
|
47510 | return _document2.default.fromJSON(object);
|
47511 | },
|
47512 |
|
47513 |
|
47514 | /**
|
47515 | * Deserialize a JSON `object` representing an `Inline`.
|
47516 | *
|
47517 | * @param {Object} object
|
47518 | * @param {Object} options (optional)
|
47519 | * @return {Inline}
|
47520 | */
|
47521 |
|
47522 | deserializeInline: function deserializeInline(object) {
|
47523 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47524 |
|
47525 | deprecate(options);
|
47526 |
|
47527 | if (options.terse) {
|
47528 | object = Raw.untersifyInline(object);
|
47529 | object.nodes = object.nodes.map(function (node) {
|
47530 | return Raw.deserializeNode(node, options);
|
47531 | });
|
47532 | }
|
47533 |
|
47534 | return _inline2.default.fromJSON(object);
|
47535 | },
|
47536 |
|
47537 |
|
47538 | /**
|
47539 | * Deserialize a JSON `object` representing a `Mark`.
|
47540 | *
|
47541 | * @param {Object} object
|
47542 | * @param {Object} options (optional)
|
47543 | * @return {Mark}
|
47544 | */
|
47545 |
|
47546 | deserializeMark: function deserializeMark(object) {
|
47547 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47548 |
|
47549 | deprecate(options);
|
47550 | return _mark2.default.fromJSON(object);
|
47551 | },
|
47552 |
|
47553 |
|
47554 | /**
|
47555 | * Deserialize a JSON object representing a `Node`.
|
47556 | *
|
47557 | * @param {Object} object
|
47558 | * @param {Object} options (optional)
|
47559 | * @return {Node}
|
47560 | */
|
47561 |
|
47562 | deserializeNode: function deserializeNode(object) {
|
47563 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47564 |
|
47565 | switch (object.kind) {
|
47566 | case 'block':
|
47567 | return Raw.deserializeBlock(object, options);
|
47568 | case 'document':
|
47569 | return Raw.deserializeDocument(object, options);
|
47570 | case 'inline':
|
47571 | return Raw.deserializeInline(object, options);
|
47572 | case 'text':
|
47573 | return Raw.deserializeText(object, options);
|
47574 | default:
|
47575 | {
|
47576 | throw new Error('Unrecognized node kind "' + object.kind + '".');
|
47577 | }
|
47578 | }
|
47579 | },
|
47580 |
|
47581 |
|
47582 | /**
|
47583 | * Deserialize a JSON `object` representing a `Range`.
|
47584 | *
|
47585 | * @param {Object} object
|
47586 | * @param {Object} options (optional)
|
47587 | * @return {List<Character>}
|
47588 | */
|
47589 |
|
47590 | deserializeRange: function deserializeRange(object) {
|
47591 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47592 |
|
47593 | deprecate(options);
|
47594 |
|
47595 | if (options.terse) {
|
47596 | object = Raw.untersifyRange(object);
|
47597 | }
|
47598 |
|
47599 | return _range2.default.fromJSON(object);
|
47600 | },
|
47601 |
|
47602 |
|
47603 | /**
|
47604 | * Deserialize a JSON `object` representing a `Selection`.
|
47605 | *
|
47606 | * @param {Object} object
|
47607 | * @param {Object} options (optional)
|
47608 | * @return {State}
|
47609 | */
|
47610 |
|
47611 | deserializeSelection: function deserializeSelection(object) {
|
47612 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47613 |
|
47614 | deprecate(options);
|
47615 | return _selection2.default.fromJSON(object);
|
47616 | },
|
47617 |
|
47618 |
|
47619 | /**
|
47620 | * Deserialize a JSON `object` representing a `State`.
|
47621 | *
|
47622 | * @param {Object} object
|
47623 | * @param {Object} options (optional)
|
47624 | * @return {State}
|
47625 | */
|
47626 |
|
47627 | deserializeState: function deserializeState(object) {
|
47628 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47629 |
|
47630 | deprecate(options);
|
47631 |
|
47632 | if (options.terse) {
|
47633 | object = Raw.untersifyState(object);
|
47634 | object.document = Raw.deserializeDocument(object.document, options);
|
47635 | }
|
47636 |
|
47637 | return _state2.default.fromJSON(object);
|
47638 | },
|
47639 |
|
47640 |
|
47641 | /**
|
47642 | * Deserialize a JSON `object` representing a `Text`.
|
47643 | *
|
47644 | * @param {Object} object
|
47645 | * @param {Object} options (optional)
|
47646 | * @return {Text}
|
47647 | */
|
47648 |
|
47649 | deserializeText: function deserializeText(object) {
|
47650 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47651 |
|
47652 | deprecate(options);
|
47653 |
|
47654 | if (options.terse) {
|
47655 | object = Raw.untersifyText(object);
|
47656 | object.ranges = object.ranges.map(function (range) {
|
47657 | return Raw.deserializeRange(range, options);
|
47658 | });
|
47659 | }
|
47660 |
|
47661 | return _text2.default.fromJSON(object);
|
47662 | },
|
47663 |
|
47664 |
|
47665 | /**
|
47666 | * Serialize a `model`.
|
47667 | *
|
47668 | * @param {Mixed} model
|
47669 | * @param {Object} options (optional)
|
47670 | * @return {Object}
|
47671 | */
|
47672 |
|
47673 | serialize: function serialize(model) {
|
47674 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47675 |
|
47676 | deprecate(options);
|
47677 | return Raw.serializeState(model, options);
|
47678 | },
|
47679 |
|
47680 |
|
47681 | /**
|
47682 | * Serialize a `block` node.
|
47683 | *
|
47684 | * @param {Block} block
|
47685 | * @param {Object} options (optional)
|
47686 | * @return {Object}
|
47687 | */
|
47688 |
|
47689 | serializeBlock: function serializeBlock(block) {
|
47690 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47691 |
|
47692 | deprecate(options);
|
47693 | var object = block.toJSON(options);
|
47694 |
|
47695 | if (options.terse) {
|
47696 | object.nodes = block.nodes.toArray().map(function (node) {
|
47697 | return Raw.serializeNode(node, options);
|
47698 | });
|
47699 | object = Raw.tersifyBlock(object);
|
47700 | }
|
47701 |
|
47702 | return object;
|
47703 | },
|
47704 |
|
47705 |
|
47706 | /**
|
47707 | * Serialize a `document`.
|
47708 | *
|
47709 | * @param {Document} document
|
47710 | * @param {Object} options (optional)
|
47711 | * @return {Object}
|
47712 | */
|
47713 |
|
47714 | serializeDocument: function serializeDocument(document) {
|
47715 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47716 |
|
47717 | deprecate(options);
|
47718 | var object = document.toJSON(options);
|
47719 |
|
47720 | if (options.terse) {
|
47721 | object.nodes = document.nodes.toArray().map(function (node) {
|
47722 | return Raw.serializeNode(node, options);
|
47723 | });
|
47724 | object = Raw.tersifyDocument(object);
|
47725 | }
|
47726 |
|
47727 | return object;
|
47728 | },
|
47729 |
|
47730 |
|
47731 | /**
|
47732 | * Serialize an `inline` node.
|
47733 | *
|
47734 | * @param {Inline} inline
|
47735 | * @param {Object} options (optional)
|
47736 | * @return {Object}
|
47737 | */
|
47738 |
|
47739 | serializeInline: function serializeInline(inline) {
|
47740 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47741 |
|
47742 | deprecate(options);
|
47743 | var object = inline.toJSON(options);
|
47744 |
|
47745 | if (options.terse) {
|
47746 | object.nodes = inline.nodes.toArray().map(function (node) {
|
47747 | return Raw.serializeNode(node, options);
|
47748 | });
|
47749 | object = Raw.tersifyInline(object);
|
47750 | }
|
47751 |
|
47752 | return object;
|
47753 | },
|
47754 |
|
47755 |
|
47756 | /**
|
47757 | * Serialize a `mark`.
|
47758 | *
|
47759 | * @param {Mark} mark
|
47760 | * @param {Object} options (optional)
|
47761 | * @return {Object}
|
47762 | */
|
47763 |
|
47764 | serializeMark: function serializeMark(mark) {
|
47765 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47766 |
|
47767 | deprecate(options);
|
47768 | var object = mark.toJSON();
|
47769 |
|
47770 | if (options.terse) {
|
47771 | object = Raw.tersifyMark(object);
|
47772 | }
|
47773 |
|
47774 | return object;
|
47775 | },
|
47776 |
|
47777 |
|
47778 | /**
|
47779 | * Serialize a `node`.
|
47780 | *
|
47781 | * @param {Node} node
|
47782 | * @param {Object} options (optional)
|
47783 | * @return {Object}
|
47784 | */
|
47785 |
|
47786 | serializeNode: function serializeNode(node) {
|
47787 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47788 |
|
47789 | deprecate(options);
|
47790 | switch (node.kind) {
|
47791 | case 'block':
|
47792 | return Raw.serializeBlock(node, options);
|
47793 | case 'document':
|
47794 | return Raw.serializeDocument(node, options);
|
47795 | case 'inline':
|
47796 | return Raw.serializeInline(node, options);
|
47797 | case 'text':
|
47798 | return Raw.serializeText(node, options);
|
47799 | default:
|
47800 | {
|
47801 | throw new Error('Unrecognized node kind "' + node.kind + '".');
|
47802 | }
|
47803 | }
|
47804 | },
|
47805 |
|
47806 |
|
47807 | /**
|
47808 | * Serialize a `range`.
|
47809 | *
|
47810 | * @param {Range} range
|
47811 | * @param {Object} options (optional)
|
47812 | * @return {Object}
|
47813 | */
|
47814 |
|
47815 | serializeRange: function serializeRange(range) {
|
47816 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47817 |
|
47818 | deprecate(options);
|
47819 | var object = range.toJSON();
|
47820 |
|
47821 | if (options.terse) {
|
47822 | object.marks = range.marks.toArray().map(function (mark) {
|
47823 | return Raw.serializeMark(mark, options);
|
47824 | });
|
47825 | object = Raw.tersifyRange(object);
|
47826 | }
|
47827 |
|
47828 | return object;
|
47829 | },
|
47830 |
|
47831 |
|
47832 | /**
|
47833 | * Serialize a `selection`.
|
47834 | *
|
47835 | * @param {Selection} selection
|
47836 | * @param {Object} options (optional)
|
47837 | * @return {Object}
|
47838 | */
|
47839 |
|
47840 | serializeSelection: function serializeSelection(selection) {
|
47841 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47842 |
|
47843 | deprecate(options);
|
47844 | var object = selection.toJSON(options);
|
47845 |
|
47846 | if (options.terse) {
|
47847 | object = Raw.tersifySelection(object);
|
47848 | }
|
47849 |
|
47850 | return object;
|
47851 | },
|
47852 |
|
47853 |
|
47854 | /**
|
47855 | * Serialize a `state`.
|
47856 | *
|
47857 | * @param {State} state
|
47858 | * @param {Object} options (optional)
|
47859 | * @return {Object}
|
47860 | */
|
47861 |
|
47862 | serializeState: function serializeState(state) {
|
47863 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47864 |
|
47865 | deprecate(options);
|
47866 | var object = state.toJSON(options);
|
47867 |
|
47868 | if (options.terse) {
|
47869 | object.document = Raw.serializeDocument(state.document, options);
|
47870 | object = Raw.tersifyState(object);
|
47871 | }
|
47872 |
|
47873 | return object;
|
47874 | },
|
47875 |
|
47876 |
|
47877 | /**
|
47878 | * Serialize a `text` node.
|
47879 | *
|
47880 | * @param {Text} text
|
47881 | * @param {Object} options (optional)
|
47882 | * @return {Object}
|
47883 | */
|
47884 |
|
47885 | serializeText: function serializeText(text) {
|
47886 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
47887 |
|
47888 | deprecate(options);
|
47889 | var object = text.toJSON(options);
|
47890 |
|
47891 | if (options.terse) {
|
47892 | object.ranges = text.getRanges().toArray().map(function (range) {
|
47893 | return Raw.serializeRange(range, options);
|
47894 | });
|
47895 | object = Raw.tersifyText(object);
|
47896 | }
|
47897 |
|
47898 | return object;
|
47899 | },
|
47900 |
|
47901 |
|
47902 | /**
|
47903 | * Create a terse representation of a block `object`.
|
47904 | *
|
47905 | * @param {Object} object
|
47906 | * @return {Object}
|
47907 | */
|
47908 |
|
47909 | tersifyBlock: function tersifyBlock(object) {
|
47910 | var ret = {};
|
47911 | ret.kind = object.kind;
|
47912 | ret.type = object.type;
|
47913 | if (object.key) ret.key = object.key;
|
47914 | if (!object.isVoid) ret.nodes = object.nodes;
|
47915 | if (object.isVoid) ret.isVoid = object.isVoid;
|
47916 | if (!(0, _isEmpty2.default)(object.data)) ret.data = object.data;
|
47917 | return ret;
|
47918 | },
|
47919 |
|
47920 |
|
47921 | /**
|
47922 | * Create a terse representation of a document `object.
|
47923 | *
|
47924 | * @param {Object} object
|
47925 | * @return {Object}
|
47926 | */
|
47927 |
|
47928 | tersifyDocument: function tersifyDocument(object) {
|
47929 | var ret = {};
|
47930 | ret.nodes = object.nodes;
|
47931 | if (object.key) ret.key = object.key;
|
47932 | if (!(0, _isEmpty2.default)(object.data)) ret.data = object.data;
|
47933 | return ret;
|
47934 | },
|
47935 |
|
47936 |
|
47937 | /**
|
47938 | * Create a terse representation of a inline `object`.
|
47939 | *
|
47940 | * @param {Object} object
|
47941 | * @return {Object}
|
47942 | */
|
47943 |
|
47944 | tersifyInline: function tersifyInline(object) {
|
47945 | var ret = {};
|
47946 | ret.kind = object.kind;
|
47947 | ret.type = object.type;
|
47948 | if (object.key) ret.key = object.key;
|
47949 | if (!object.isVoid) ret.nodes = object.nodes;
|
47950 | if (object.isVoid) ret.isVoid = object.isVoid;
|
47951 | if (!(0, _isEmpty2.default)(object.data)) ret.data = object.data;
|
47952 | return ret;
|
47953 | },
|
47954 |
|
47955 |
|
47956 | /**
|
47957 | * Create a terse representation of a mark `object`.
|
47958 | *
|
47959 | * @param {Object} object
|
47960 | * @return {Object}
|
47961 | */
|
47962 |
|
47963 | tersifyMark: function tersifyMark(object) {
|
47964 | var ret = {};
|
47965 | ret.type = object.type;
|
47966 | if (!(0, _isEmpty2.default)(object.data)) ret.data = object.data;
|
47967 | return ret;
|
47968 | },
|
47969 |
|
47970 |
|
47971 | /**
|
47972 | * Create a terse representation of a range `object`.
|
47973 | *
|
47974 | * @param {Object} object
|
47975 | * @return {Object}
|
47976 | */
|
47977 |
|
47978 | tersifyRange: function tersifyRange(object) {
|
47979 | var ret = {};
|
47980 | ret.text = object.text;
|
47981 | if (!(0, _isEmpty2.default)(object.marks)) ret.marks = object.marks;
|
47982 | return ret;
|
47983 | },
|
47984 |
|
47985 |
|
47986 | /**
|
47987 | * Create a terse representation of a selection `object.`
|
47988 | *
|
47989 | * @param {Object} object
|
47990 | * @return {Object}
|
47991 | */
|
47992 |
|
47993 | tersifySelection: function tersifySelection(object) {
|
47994 | return {
|
47995 | anchorKey: object.anchorKey,
|
47996 | anchorOffset: object.anchorOffset,
|
47997 | focusKey: object.focusKey,
|
47998 | focusOffset: object.focusOffset,
|
47999 | isFocused: object.isFocused
|
48000 | };
|
48001 | },
|
48002 |
|
48003 |
|
48004 | /**
|
48005 | * Create a terse representation of a state `object`.
|
48006 | *
|
48007 | * @param {Object} object
|
48008 | * @return {Object}
|
48009 | */
|
48010 |
|
48011 | tersifyState: function tersifyState(object) {
|
48012 | var data = object.data,
|
48013 | document = object.document,
|
48014 | selection = object.selection;
|
48015 |
|
48016 | var emptyData = (0, _isEmpty2.default)(data);
|
48017 |
|
48018 | if (!selection && emptyData) {
|
48019 | return document;
|
48020 | }
|
48021 |
|
48022 | var ret = { document: document };
|
48023 | if (!emptyData) ret.data = data;
|
48024 | if (selection) ret.selection = selection;
|
48025 | return ret;
|
48026 | },
|
48027 |
|
48028 |
|
48029 | /**
|
48030 | * Create a terse representation of a text `object`.
|
48031 | *
|
48032 | * @param {Object} object
|
48033 | * @return {Object}
|
48034 | */
|
48035 |
|
48036 | tersifyText: function tersifyText(object) {
|
48037 | var ret = {};
|
48038 | ret.kind = object.kind;
|
48039 | if (object.key) ret.key = object.key;
|
48040 |
|
48041 | if (object.ranges.length == 1 && object.ranges[0].marks == null) {
|
48042 | ret.text = object.ranges[0].text;
|
48043 | } else {
|
48044 | ret.ranges = object.ranges;
|
48045 | }
|
48046 |
|
48047 | return ret;
|
48048 | },
|
48049 |
|
48050 |
|
48051 | /**
|
48052 | * Convert a terse representation of a block `object` into a non-terse one.
|
48053 | *
|
48054 | * @param {Object} object
|
48055 | * @return {Object}
|
48056 | */
|
48057 |
|
48058 | untersifyBlock: function untersifyBlock(object) {
|
48059 | if (object.isVoid || !object.nodes || !object.nodes.length) {
|
48060 | return {
|
48061 | key: object.key,
|
48062 | data: object.data,
|
48063 | kind: object.kind,
|
48064 | type: object.type,
|
48065 | isVoid: object.isVoid,
|
48066 | nodes: [{
|
48067 | kind: 'text',
|
48068 | text: ''
|
48069 | }]
|
48070 | };
|
48071 | }
|
48072 |
|
48073 | return object;
|
48074 | },
|
48075 |
|
48076 |
|
48077 | /**
|
48078 | * Convert a terse representation of a inline `object` into a non-terse one.
|
48079 | *
|
48080 | * @param {Object} object
|
48081 | * @return {Object}
|
48082 | */
|
48083 |
|
48084 | untersifyInline: function untersifyInline(object) {
|
48085 | if (object.isVoid || !object.nodes || !object.nodes.length) {
|
48086 | return {
|
48087 | key: object.key,
|
48088 | data: object.data,
|
48089 | kind: object.kind,
|
48090 | type: object.type,
|
48091 | isVoid: object.isVoid,
|
48092 | nodes: [{
|
48093 | kind: 'text',
|
48094 | text: ''
|
48095 | }]
|
48096 | };
|
48097 | }
|
48098 |
|
48099 | return object;
|
48100 | },
|
48101 |
|
48102 |
|
48103 | /**
|
48104 | * Convert a terse representation of a range `object` into a non-terse one.
|
48105 | *
|
48106 | * @param {Object} object
|
48107 | * @return {Object}
|
48108 | */
|
48109 |
|
48110 | untersifyRange: function untersifyRange(object) {
|
48111 | return {
|
48112 | kind: 'range',
|
48113 | text: object.text,
|
48114 | marks: object.marks || []
|
48115 | };
|
48116 | },
|
48117 |
|
48118 |
|
48119 | /**
|
48120 | * Convert a terse representation of a selection `object` into a non-terse one.
|
48121 | *
|
48122 | * @param {Object} object
|
48123 | * @return {Object}
|
48124 | */
|
48125 |
|
48126 | untersifySelection: function untersifySelection(object) {
|
48127 | return {
|
48128 | kind: 'selection',
|
48129 | anchorKey: object.anchorKey,
|
48130 | anchorOffset: object.anchorOffset,
|
48131 | focusKey: object.focusKey,
|
48132 | focusOffset: object.focusOffset,
|
48133 | isBackward: null,
|
48134 | isFocused: false
|
48135 | };
|
48136 | },
|
48137 |
|
48138 |
|
48139 | /**
|
48140 | * Convert a terse representation of a state `object` into a non-terse one.
|
48141 | *
|
48142 | * @param {Object} object
|
48143 | * @return {Object}
|
48144 | */
|
48145 |
|
48146 | untersifyState: function untersifyState(object) {
|
48147 | if (object.document) {
|
48148 | return {
|
48149 | kind: 'state',
|
48150 | data: object.data,
|
48151 | document: object.document,
|
48152 | selection: object.selection
|
48153 | };
|
48154 | }
|
48155 |
|
48156 | return {
|
48157 | kind: 'state',
|
48158 | document: {
|
48159 | data: object.data,
|
48160 | key: object.key,
|
48161 | kind: 'document',
|
48162 | nodes: object.nodes
|
48163 | }
|
48164 | };
|
48165 | },
|
48166 |
|
48167 |
|
48168 | /**
|
48169 | * Convert a terse representation of a text `object` into a non-terse one.
|
48170 | *
|
48171 | * @param {Object} object
|
48172 | * @return {Object}
|
48173 | */
|
48174 |
|
48175 | untersifyText: function untersifyText(object) {
|
48176 | if (object.ranges) return object;
|
48177 |
|
48178 | return {
|
48179 | key: object.key,
|
48180 | kind: object.kind,
|
48181 | ranges: [{
|
48182 | text: object.text,
|
48183 | marks: object.marks || []
|
48184 | }]
|
48185 | };
|
48186 | }
|
48187 | };
|
48188 |
|
48189 | /**
|
48190 | * Export.
|
48191 | *
|
48192 | * @type {Object}
|
48193 | */
|
48194 |
|
48195 | exports.default = Raw;
|
48196 | },{"../models/block":331,"../models/document":335,"../models/inline":337,"../models/mark":338,"../models/range":340,"../models/selection":342,"../models/state":344,"../models/text":345,"../utils/logger":366,"is-empty":136}],355:[function(require,module,exports){
|
48197 | 'use strict';
|
48198 |
|
48199 | Object.defineProperty(exports, "__esModule", {
|
48200 | value: true
|
48201 | });
|
48202 |
|
48203 | /**
|
48204 | * Extends a DOM `selection` to a given `el` and `offset`.
|
48205 | *
|
48206 | * COMPAT: In IE11, `selection.extend` doesn't exist natively, so we have to
|
48207 | * polyfill it with this. (2017/09/06)
|
48208 | *
|
48209 | * https://gist.github.com/tyler-johnson/0a3e8818de3f115b2a2dc47468ac0099
|
48210 | *
|
48211 | * @param {Selection} selection
|
48212 | * @param {Element} el
|
48213 | * @param {Number} offset
|
48214 | * @return {Selection}
|
48215 | */
|
48216 |
|
48217 | function extendSelection(selection, el, offset) {
|
48218 | // Use native method whenever possible.
|
48219 | if (typeof selection.extend === 'function') {
|
48220 | return selection.extend(el, offset);
|
48221 | }
|
48222 |
|
48223 | var range = document.createRange();
|
48224 | var anchor = document.createRange();
|
48225 | var focus = document.createRange();
|
48226 | anchor.setStart(selection.anchorNode, selection.anchorOffset);
|
48227 | focus.setStart(el, offset);
|
48228 |
|
48229 | var v = focus.compareBoundaryPoints(window.Range.START_TO_START, anchor);
|
48230 |
|
48231 | // If the focus is after the anchor...
|
48232 | if (v >= 0) {
|
48233 | range.setStart(selection.anchorNode, selection.anchorOffset);
|
48234 | range.setEnd(el, offset);
|
48235 | }
|
48236 |
|
48237 | // Otherwise, if the anchor if after the focus...
|
48238 | else {
|
48239 | range.setStart(el, offset);
|
48240 | range.setEnd(selection.anchorNode, selection.anchorOffset);
|
48241 | }
|
48242 |
|
48243 | selection.removeAllRanges();
|
48244 | selection.addRange(range);
|
48245 | return selection;
|
48246 | }
|
48247 |
|
48248 | /**
|
48249 | * Export.
|
48250 | *
|
48251 | * @type {Function}
|
48252 | */
|
48253 |
|
48254 | exports.default = extendSelection;
|
48255 | },{}],356:[function(require,module,exports){
|
48256 | 'use strict';
|
48257 |
|
48258 | Object.defineProperty(exports, "__esModule", {
|
48259 | value: true
|
48260 | });
|
48261 |
|
48262 | /**
|
48263 | * Find the closest ancestor of a DOM `element` that matches a given selector.
|
48264 | *
|
48265 | * COMPAT: In IE11, the `Node.closest` method doesn't exist natively, so we
|
48266 | * have to polyfill it. (2017/09/06)
|
48267 | *
|
48268 | * https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
|
48269 | *
|
48270 | * @param {Element} node
|
48271 | * @param {String} selector
|
48272 | * @return {Element}
|
48273 | */
|
48274 |
|
48275 | function findClosestNode(node, selector) {
|
48276 | if (typeof node.closest === 'function') return node.closest(selector);
|
48277 |
|
48278 | var matches = (node.document || node.ownerDocument).querySelectorAll(selector);
|
48279 | var parentNode = node;
|
48280 | var i = void 0;
|
48281 |
|
48282 | do {
|
48283 | i = matches.length;
|
48284 | while (--i >= 0 && matches.item(i) !== parentNode) {}
|
48285 | } while (i < 0 && (parentNode = parentNode.parentElement));
|
48286 |
|
48287 | return parentNode;
|
48288 | }
|
48289 |
|
48290 | /**
|
48291 | * Export.
|
48292 | *
|
48293 | * @type {Function}
|
48294 | */
|
48295 |
|
48296 | exports.default = findClosestNode;
|
48297 | },{}],357:[function(require,module,exports){
|
48298 | "use strict";
|
48299 |
|
48300 | Object.defineProperty(exports, "__esModule", {
|
48301 | value: true
|
48302 | });
|
48303 |
|
48304 | /**
|
48305 | * Find the deepest descendant of a DOM `element`.
|
48306 | *
|
48307 | * @param {Element} node
|
48308 | * @return {Element}
|
48309 | */
|
48310 |
|
48311 | function findDeepestNode(element) {
|
48312 | return element.firstChild ? findDeepestNode(element.firstChild) : element;
|
48313 | }
|
48314 |
|
48315 | /**
|
48316 | * Export.
|
48317 | *
|
48318 | * @type {Function}
|
48319 | */
|
48320 |
|
48321 | exports.default = findDeepestNode;
|
48322 | },{}],358:[function(require,module,exports){
|
48323 | "use strict";
|
48324 |
|
48325 | Object.defineProperty(exports, "__esModule", {
|
48326 | value: true
|
48327 | });
|
48328 |
|
48329 | /**
|
48330 | * Find the DOM node for a `node`.
|
48331 | *
|
48332 | * @param {Node} node
|
48333 | * @return {Element}
|
48334 | */
|
48335 |
|
48336 | function findDOMNode(node) {
|
48337 | var el = window.document.querySelector("[data-key=\"" + node.key + "\"]");
|
48338 |
|
48339 | if (!el) {
|
48340 | throw new Error("Unable to find a DOM node for \"" + node.key + "\". This is often because of forgetting to add `props.attributes` to a component returned from `renderNode`.");
|
48341 | }
|
48342 |
|
48343 | return el;
|
48344 | }
|
48345 |
|
48346 | /**
|
48347 | * Export.
|
48348 | *
|
48349 | * @type {Function}
|
48350 | */
|
48351 |
|
48352 | exports.default = findDOMNode;
|
48353 | },{}],359:[function(require,module,exports){
|
48354 | "use strict";
|
48355 |
|
48356 | Object.defineProperty(exports, "__esModule", {
|
48357 | value: true
|
48358 | });
|
48359 |
|
48360 | /**
|
48361 | * An auto-incrementing index for generating keys.
|
48362 | *
|
48363 | * @type {Number}
|
48364 | */
|
48365 |
|
48366 | var n = void 0;
|
48367 |
|
48368 | /**
|
48369 | * The global key generating function.
|
48370 | *
|
48371 | * @type {Function}
|
48372 | */
|
48373 |
|
48374 | var generate = void 0;
|
48375 |
|
48376 | /**
|
48377 | * Generate a key.
|
48378 | *
|
48379 | * @return {String}
|
48380 | */
|
48381 |
|
48382 | function generateKey() {
|
48383 | return generate();
|
48384 | }
|
48385 |
|
48386 | /**
|
48387 | * Set a different unique ID generating `function`.
|
48388 | *
|
48389 | * @param {Function} func
|
48390 | */
|
48391 |
|
48392 | function setKeyGenerator(func) {
|
48393 | generate = func;
|
48394 | }
|
48395 |
|
48396 | /**
|
48397 | * Reset the key generating function to its initial state.
|
48398 | */
|
48399 |
|
48400 | function resetKeyGenerator() {
|
48401 | n = 0;
|
48402 | generate = function generate() {
|
48403 | return "" + n++;
|
48404 | };
|
48405 | }
|
48406 |
|
48407 | /**
|
48408 | * Set the initial state.
|
48409 | */
|
48410 |
|
48411 | resetKeyGenerator();
|
48412 |
|
48413 | /**
|
48414 | * Export.
|
48415 | *
|
48416 | * @type {Object}
|
48417 | */
|
48418 |
|
48419 | exports.default = generateKey;
|
48420 | exports.setKeyGenerator = setKeyGenerator;
|
48421 | exports.resetKeyGenerator = resetKeyGenerator;
|
48422 | },{}],360:[function(require,module,exports){
|
48423 | 'use strict';
|
48424 |
|
48425 | Object.defineProperty(exports, "__esModule", {
|
48426 | value: true
|
48427 | });
|
48428 |
|
48429 | var _findDeepestNode = require('./find-deepest-node');
|
48430 |
|
48431 | var _findDeepestNode2 = _interopRequireDefault(_findDeepestNode);
|
48432 |
|
48433 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
48434 |
|
48435 | /**
|
48436 | * Get caret position from selection point.
|
48437 | *
|
48438 | * @param {String} key
|
48439 | * @param {Number} offset
|
48440 | * @param {State} state
|
48441 | * @param {Editor} editor
|
48442 | * @param {Element} el
|
48443 | * @return {Object}
|
48444 | */
|
48445 |
|
48446 | function getCaretPosition(key, offset, state, editor, el) {
|
48447 | var document = state.document;
|
48448 |
|
48449 | var text = document.getDescendant(key);
|
48450 | var schema = editor.getSchema();
|
48451 | var decorators = document.getDescendantDecorators(key, schema);
|
48452 | var ranges = text.getRanges(decorators);
|
48453 |
|
48454 | var a = 0;
|
48455 | var index = void 0;
|
48456 | var off = void 0;
|
48457 |
|
48458 | ranges.forEach(function (range, i) {
|
48459 | var length = range.text.length;
|
48460 |
|
48461 | a += length;
|
48462 | if (a < offset) return;
|
48463 | index = i;
|
48464 | off = offset - (a - length);
|
48465 | return false;
|
48466 | });
|
48467 |
|
48468 | var span = el.querySelector('[data-offset-key="' + key + '-' + index + '"]');
|
48469 | var node = (0, _findDeepestNode2.default)(span);
|
48470 | return { node: node, offset: off };
|
48471 | }
|
48472 |
|
48473 | /**
|
48474 | * Export.
|
48475 | *
|
48476 | * @type {Function}
|
48477 | */
|
48478 |
|
48479 | exports.default = getCaretPosition;
|
48480 | },{"./find-deepest-node":357}],361:[function(require,module,exports){
|
48481 | 'use strict';
|
48482 |
|
48483 | Object.defineProperty(exports, "__esModule", {
|
48484 | value: true
|
48485 | });
|
48486 |
|
48487 | var _reactDom = require('react-dom');
|
48488 |
|
48489 | /**
|
48490 | * Get clipboard HTML data by capturing the HTML inserted by the browser's
|
48491 | * native paste action. To make this work, `preventDefault()` may not be
|
48492 | * called on the `onPaste` event. As this method is asynchronous, a callback
|
48493 | * is needed to return the HTML content. This solution was adapted from
|
48494 | * http://stackoverflow.com/a/6804718.
|
48495 | *
|
48496 | * @param {Component} component
|
48497 | * @param {Function} callback
|
48498 | */
|
48499 |
|
48500 | function getHtmlFromNativePaste(component, callback) {
|
48501 | var el = (0, _reactDom.findDOMNode)(component);
|
48502 |
|
48503 | // Create an off-screen clone of the element and give it focus.
|
48504 | var clone = el.cloneNode();
|
48505 | clone.setAttribute('class', '');
|
48506 | clone.setAttribute('style', 'position: fixed; left: -9999px');
|
48507 | el.parentNode.insertBefore(clone, el);
|
48508 | clone.focus();
|
48509 |
|
48510 | // Tick forward so the native paste behaviour occurs in cloned element and we
|
48511 | // can get what was pasted from the DOM.
|
48512 | setTimeout(function () {
|
48513 | if (clone.childElementCount > 0) {
|
48514 | // If the node contains any child nodes, that is the HTML content.
|
48515 | var html = clone.innerHTML;
|
48516 | clone.parentNode.removeChild(clone);
|
48517 | callback(html);
|
48518 | } else {
|
48519 | // Only plain text, no HTML.
|
48520 | callback();
|
48521 | }
|
48522 | }, 0);
|
48523 | }
|
48524 |
|
48525 | /**
|
48526 | * Export.
|
48527 | *
|
48528 | * @type {Function}
|
48529 | */
|
48530 |
|
48531 | exports.default = getHtmlFromNativePaste;
|
48532 | },{"react-dom":153}],362:[function(require,module,exports){
|
48533 | 'use strict';
|
48534 |
|
48535 | Object.defineProperty(exports, "__esModule", {
|
48536 | value: true
|
48537 | });
|
48538 |
|
48539 | var _offsetKey = require('./offset-key');
|
48540 |
|
48541 | var _offsetKey2 = _interopRequireDefault(_offsetKey);
|
48542 |
|
48543 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
48544 |
|
48545 | /**
|
48546 | * Get a point from a native selection's DOM `element` and `offset`.
|
48547 | *
|
48548 | * @param {Element} element
|
48549 | * @param {Number} offset
|
48550 | * @param {State} state
|
48551 | * @param {Editor} editor
|
48552 | * @return {Object}
|
48553 | */
|
48554 |
|
48555 | function getPoint(element, offset, state, editor) {
|
48556 | var document = state.document;
|
48557 |
|
48558 | var schema = editor.getSchema();
|
48559 |
|
48560 | // If we can't find an offset key, we can't get a point.
|
48561 | var offsetKey = _offsetKey2.default.findKey(element, offset);
|
48562 | if (!offsetKey) return null;
|
48563 |
|
48564 | // COMPAT: If someone is clicking from one Slate editor into another, the
|
48565 | // select event fires two, once for the old editor's `element` first, and
|
48566 | // then afterwards for the correct `element`. (2017/03/03)
|
48567 | var key = offsetKey.key;
|
48568 |
|
48569 | var node = document.getDescendant(key);
|
48570 | if (!node) return null;
|
48571 |
|
48572 | var decorators = document.getDescendantDecorators(key, schema);
|
48573 | var ranges = node.getRanges(decorators);
|
48574 | var point = _offsetKey2.default.findPoint(offsetKey, ranges);
|
48575 | return point;
|
48576 | }
|
48577 |
|
48578 | /**
|
48579 | * Export.
|
48580 | *
|
48581 | * @type {Function}
|
48582 | */
|
48583 |
|
48584 | exports.default = getPoint;
|
48585 | },{"./offset-key":370}],363:[function(require,module,exports){
|
48586 | 'use strict';
|
48587 |
|
48588 | Object.defineProperty(exports, "__esModule", {
|
48589 | value: true
|
48590 | });
|
48591 |
|
48592 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
48593 |
|
48594 | var _base = require('../serializers/base-64');
|
48595 |
|
48596 | var _base2 = _interopRequireDefault(_base);
|
48597 |
|
48598 | var _transferTypes = require('../constants/transfer-types');
|
48599 |
|
48600 | var _transferTypes2 = _interopRequireDefault(_transferTypes);
|
48601 |
|
48602 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
48603 |
|
48604 | /**
|
48605 | * Fragment matching regexp for HTML nodes.
|
48606 | *
|
48607 | * @type {RegExp}
|
48608 | */
|
48609 |
|
48610 | var FRAGMENT_MATCHER = / data-slate-fragment="([^\s"]+)"/;
|
48611 |
|
48612 | /**
|
48613 | * Get the data and type from a native data `transfer`.
|
48614 | *
|
48615 | * @param {DataTransfer} transfer
|
48616 | * @return {Object}
|
48617 | */
|
48618 |
|
48619 | function getTransferData(transfer) {
|
48620 | var fragment = getType(transfer, _transferTypes2.default.FRAGMENT);
|
48621 | var node = getType(transfer, _transferTypes2.default.NODE);
|
48622 | var html = getType(transfer, 'text/html');
|
48623 | var rich = getType(transfer, 'text/rtf');
|
48624 | var text = getType(transfer, 'text/plain');
|
48625 | var files = void 0;
|
48626 |
|
48627 | // If there isn't a fragment, but there is HTML, check to see if the HTML is
|
48628 | // actually an encoded fragment.
|
48629 | if (!fragment && html && ~html.indexOf(' data-slate-fragment="')) {
|
48630 | var matches = FRAGMENT_MATCHER.exec(html);
|
48631 |
|
48632 | var _matches = _slicedToArray(matches, 2),
|
48633 | full = _matches[0],
|
48634 | encoded = _matches[1]; // eslint-disable-line no-unused-vars
|
48635 |
|
48636 |
|
48637 | if (encoded) fragment = encoded;
|
48638 | }
|
48639 |
|
48640 | // COMPAT: Edge doesn't handle custom data types
|
48641 | // These will be embedded in text/plain in this case (2017/7/12)
|
48642 | if (text) {
|
48643 | var embeddedTypes = getEmbeddedTypes(text);
|
48644 |
|
48645 | if (embeddedTypes[_transferTypes2.default.FRAGMENT]) fragment = embeddedTypes[_transferTypes2.default.FRAGMENT];
|
48646 | if (embeddedTypes[_transferTypes2.default.NODE]) node = embeddedTypes[_transferTypes2.default.NODE];
|
48647 | if (embeddedTypes['text/plain']) text = embeddedTypes['text/plain'];
|
48648 | }
|
48649 |
|
48650 | // Decode a fragment or node if they exist.
|
48651 | if (fragment) fragment = _base2.default.deserializeNode(fragment);
|
48652 | if (node) node = _base2.default.deserializeNode(node);
|
48653 |
|
48654 | // COMPAT: Edge sometimes throws 'NotSupportedError'
|
48655 | // when accessing `transfer.items` (2017/7/12)
|
48656 | try {
|
48657 | // Get and normalize files if they exist.
|
48658 | if (transfer.items && transfer.items.length) {
|
48659 | files = Array.from(transfer.items).map(function (item) {
|
48660 | return item.kind == 'file' ? item.getAsFile() : null;
|
48661 | }).filter(function (exists) {
|
48662 | return exists;
|
48663 | });
|
48664 | } else if (transfer.files && transfer.files.length) {
|
48665 | files = Array.from(transfer.files);
|
48666 | }
|
48667 | } catch (err) {
|
48668 | if (transfer.files && transfer.files.length) {
|
48669 | files = Array.from(transfer.files);
|
48670 | }
|
48671 | }
|
48672 |
|
48673 | // Determine the type of the data.
|
48674 | var data = { files: files, fragment: fragment, html: html, node: node, rich: rich, text: text };
|
48675 | data.type = getTransferType(data);
|
48676 | return data;
|
48677 | }
|
48678 |
|
48679 | /**
|
48680 | * Takes text input, checks whether contains embedded data
|
48681 | * and returns object with original text +/- additional data
|
48682 | *
|
48683 | * @param {String} text
|
48684 | * @return {Object}
|
48685 | */
|
48686 |
|
48687 | function getEmbeddedTypes(text) {
|
48688 | var prefix = 'SLATE-DATA-EMBED::';
|
48689 |
|
48690 | if (text.substring(0, prefix.length) !== prefix) {
|
48691 | return { 'text/plain': text };
|
48692 | }
|
48693 |
|
48694 | // Attempt to parse, if fails then just standard text/plain
|
48695 | // Otherwise, already had data embedded
|
48696 | try {
|
48697 | return JSON.parse(text.substring(prefix.length));
|
48698 | } catch (err) {
|
48699 | throw new Error('Unable to parse custom embedded drag data');
|
48700 | }
|
48701 | }
|
48702 |
|
48703 | /**
|
48704 | * Get the type of a transfer from its `data`.
|
48705 | *
|
48706 | * @param {Object} data
|
48707 | * @return {String}
|
48708 | */
|
48709 |
|
48710 | function getTransferType(data) {
|
48711 | if (data.fragment) return 'fragment';
|
48712 | if (data.node) return 'node';
|
48713 |
|
48714 | // COMPAT: Microsoft Word adds an image of the selected text to the data.
|
48715 | // Since files are preferred over HTML or text, this would cause the type to
|
48716 | // be considered `files`. But it also adds rich text data so we can check
|
48717 | // for that and properly set the type to `html` or `text`. (2016/11/21)
|
48718 | if (data.rich && data.html) return 'html';
|
48719 | if (data.rich && data.text) return 'text';
|
48720 |
|
48721 | if (data.files && data.files.length) return 'files';
|
48722 | if (data.html) return 'html';
|
48723 | if (data.text) return 'text';
|
48724 | return 'unknown';
|
48725 | }
|
48726 |
|
48727 | /**
|
48728 | * Get one of types `TYPES.FRAGMENT`, `TYPES.NODE`, `text/html`, `text/rtf` or
|
48729 | * `text/plain` from transfers's `data` if possible, otherwise return null.
|
48730 | *
|
48731 | * @param {Object} transfer
|
48732 | * @param {String} type
|
48733 | * @return {String}
|
48734 | */
|
48735 |
|
48736 | function getType(transfer, type) {
|
48737 | if (!transfer.types || !transfer.types.length) {
|
48738 | // COMPAT: In IE 11, there is no `types` field but `getData('Text')`
|
48739 | // is supported`. (2017/06/23)
|
48740 | return type === 'text/plain' ? transfer.getData('Text') || null : null;
|
48741 | }
|
48742 |
|
48743 | return transfer.types.indexOf(type) !== -1 ? transfer.getData(type) || null : null;
|
48744 | }
|
48745 |
|
48746 | /**
|
48747 | * Export.
|
48748 | *
|
48749 | * @type {Function}
|
48750 | */
|
48751 |
|
48752 | exports.default = getTransferData;
|
48753 | },{"../constants/transfer-types":329,"../serializers/base-64":351}],364:[function(require,module,exports){
|
48754 | "use strict";
|
48755 |
|
48756 | Object.defineProperty(exports, "__esModule", {
|
48757 | value: true
|
48758 | });
|
48759 |
|
48760 | /**
|
48761 | * Check if an `index` of a `text` node is in a `range`.
|
48762 | *
|
48763 | * @param {Number} index
|
48764 | * @param {Text} text
|
48765 | * @param {Selection} range
|
48766 | * @return {Boolean}
|
48767 | */
|
48768 |
|
48769 | function isIndexInRange(index, text, range) {
|
48770 | var startKey = range.startKey,
|
48771 | startOffset = range.startOffset,
|
48772 | endKey = range.endKey,
|
48773 | endOffset = range.endOffset;
|
48774 |
|
48775 |
|
48776 | if (text.key == startKey && text.key == endKey) {
|
48777 | return startOffset <= index && index < endOffset;
|
48778 | } else if (text.key == startKey) {
|
48779 | return startOffset <= index;
|
48780 | } else if (text.key == endKey) {
|
48781 | return index < endOffset;
|
48782 | } else {
|
48783 | return true;
|
48784 | }
|
48785 | }
|
48786 |
|
48787 | /**
|
48788 | * Export.
|
48789 | *
|
48790 | * @type {Function}
|
48791 | */
|
48792 |
|
48793 | exports.default = isIndexInRange;
|
48794 | },{}],365:[function(require,module,exports){
|
48795 | "use strict";
|
48796 |
|
48797 | Object.defineProperty(exports, "__esModule", {
|
48798 | value: true
|
48799 | });
|
48800 |
|
48801 | /**
|
48802 | * Check if an `object` is a React component.
|
48803 | *
|
48804 | * @param {Object} object
|
48805 | * @return {Boolean}
|
48806 | */
|
48807 |
|
48808 | function isReactComponent(object) {
|
48809 | return object && object.prototype && object.prototype.isReactComponent;
|
48810 | }
|
48811 |
|
48812 | /**
|
48813 | * Export.
|
48814 | *
|
48815 | * @type {Function}
|
48816 | */
|
48817 |
|
48818 | exports.default = isReactComponent;
|
48819 | },{}],366:[function(require,module,exports){
|
48820 | 'use strict';
|
48821 |
|
48822 | Object.defineProperty(exports, "__esModule", {
|
48823 | value: true
|
48824 | });
|
48825 |
|
48826 | var _isDev = require('../constants/is-dev');
|
48827 |
|
48828 | var _isDev2 = _interopRequireDefault(_isDev);
|
48829 |
|
48830 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
48831 |
|
48832 | /**
|
48833 | * Log a `message` at `level`.
|
48834 | *
|
48835 | * @param {String} level
|
48836 | * @param {String} message
|
48837 | * @param {Any} ...args
|
48838 | */
|
48839 |
|
48840 | function log(level, message) {
|
48841 | if (!_isDev2.default) {
|
48842 | return;
|
48843 | }
|
48844 |
|
48845 | if (typeof console != 'undefined' && typeof console[level] == 'function') {
|
48846 | var _console;
|
48847 |
|
48848 | for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
48849 | args[_key - 2] = arguments[_key];
|
48850 | }
|
48851 |
|
48852 | (_console = console)[level].apply(_console, [message].concat(args));
|
48853 | }
|
48854 | }
|
48855 |
|
48856 | /**
|
48857 | * Log a development warning `message`.
|
48858 | *
|
48859 | * @param {String} message
|
48860 | * @param {Any} ...args
|
48861 | */
|
48862 |
|
48863 | /* eslint-disable no-console */
|
48864 |
|
48865 | function warn(message) {
|
48866 | for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
48867 | args[_key2 - 1] = arguments[_key2];
|
48868 | }
|
48869 |
|
48870 | log.apply(undefined, ['warn', 'Warning: ' + message].concat(args));
|
48871 | }
|
48872 |
|
48873 | /**
|
48874 | * Log a deprecation warning `message`, with helpful `version` number.
|
48875 | *
|
48876 | * @param {String} version
|
48877 | * @param {String} message
|
48878 | * @param {Any} ...args
|
48879 | */
|
48880 |
|
48881 | function deprecate(version, message) {
|
48882 | for (var _len3 = arguments.length, args = Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
48883 | args[_key3 - 2] = arguments[_key3];
|
48884 | }
|
48885 |
|
48886 | log.apply(undefined, ['warn', 'Deprecation (v' + version + '): ' + message].concat(args));
|
48887 | }
|
48888 |
|
48889 | /**
|
48890 | * Export.
|
48891 | *
|
48892 | * @type {Function}
|
48893 | */
|
48894 |
|
48895 | exports.default = {
|
48896 | deprecate: deprecate,
|
48897 | warn: warn
|
48898 | };
|
48899 | },{"../constants/is-dev":327}],367:[function(require,module,exports){
|
48900 | 'use strict';
|
48901 |
|
48902 | Object.defineProperty(exports, "__esModule", {
|
48903 | value: true
|
48904 | });
|
48905 | exports.__enable = exports.__clear = exports.default = undefined;
|
48906 |
|
48907 | var _es6Map = require('es6-map');
|
48908 |
|
48909 | var _es6Map2 = _interopRequireDefault(_es6Map);
|
48910 |
|
48911 | var _isDev = require('../constants/is-dev');
|
48912 |
|
48913 | var _isDev2 = _interopRequireDefault(_isDev);
|
48914 |
|
48915 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
48916 |
|
48917 | /**
|
48918 | * GLOBAL: True if memoization should is enabled. Only effective when `IS_DEV`.
|
48919 | *
|
48920 | * @type {Boolean}
|
48921 | */
|
48922 |
|
48923 | var ENABLED = true;
|
48924 |
|
48925 | /**
|
48926 | * GLOBAL: Changing this cache key will clear all previous cached results.
|
48927 | * Only effective when `IS_DEV`.
|
48928 | *
|
48929 | * @type {Number}
|
48930 | */
|
48931 |
|
48932 | var CACHE_KEY = 0;
|
48933 |
|
48934 | /**
|
48935 | * The leaf node of a cache tree. Used to support variable argument length. A
|
48936 | * unique object, so that native Maps will key it by reference.
|
48937 | *
|
48938 | * @type {Object}
|
48939 | */
|
48940 |
|
48941 | var LEAF = {};
|
48942 |
|
48943 | /**
|
48944 | * A value to represent a memoized undefined value. Allows efficient value
|
48945 | * retrieval using Map.get only.
|
48946 | *
|
48947 | * @type {Object}
|
48948 | */
|
48949 |
|
48950 | var UNDEFINED = {};
|
48951 |
|
48952 | /**
|
48953 | * Default value for unset keys in native Maps
|
48954 | *
|
48955 | * @type {Undefined}
|
48956 | */
|
48957 |
|
48958 | var UNSET = undefined;
|
48959 |
|
48960 | /**
|
48961 | * Memoize all of the `properties` on a `object`.
|
48962 | *
|
48963 | * @param {Object} object
|
48964 | * @param {Array} properties
|
48965 | * @return {Record}
|
48966 | */
|
48967 |
|
48968 | function memoize(object, properties) {
|
48969 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
48970 | var _options$takesArgumen = options.takesArguments,
|
48971 | takesArguments = _options$takesArgumen === undefined ? true : _options$takesArgumen;
|
48972 |
|
48973 | var _loop = function _loop(i) {
|
48974 | var property = properties[i];
|
48975 | var original = object[property];
|
48976 |
|
48977 | if (!original) {
|
48978 | throw new Error('Object does not have a property named "' + property + '".');
|
48979 | }
|
48980 |
|
48981 | object[property] = function () {
|
48982 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
48983 | args[_key] = arguments[_key];
|
48984 | }
|
48985 |
|
48986 | if (_isDev2.default) {
|
48987 | // If memoization is disabled, call into the original method.
|
48988 | if (!ENABLED) return original.apply(this, args);
|
48989 |
|
48990 | // If the cache key is different, previous caches must be cleared.
|
48991 | if (CACHE_KEY !== this.__cache_key) {
|
48992 | this.__cache_key = CACHE_KEY;
|
48993 | this.__cache = new _es6Map2.default();
|
48994 | }
|
48995 | }
|
48996 |
|
48997 | if (!this.__cache) {
|
48998 | this.__cache = new _es6Map2.default();
|
48999 | }
|
49000 |
|
49001 | var cachedValue = void 0;
|
49002 | var keys = void 0;
|
49003 |
|
49004 | if (takesArguments) {
|
49005 | keys = [property].concat(args);
|
49006 | cachedValue = getIn(this.__cache, keys);
|
49007 | } else {
|
49008 | cachedValue = this.__cache.get(property);
|
49009 | }
|
49010 |
|
49011 | // If we've got a result already, return it.
|
49012 | if (cachedValue !== UNSET) {
|
49013 | return cachedValue === UNDEFINED ? undefined : cachedValue;
|
49014 | }
|
49015 |
|
49016 | // Otherwise calculate what it should be once and cache it.
|
49017 | var value = original.apply(this, args);
|
49018 | var v = value === undefined ? UNDEFINED : value;
|
49019 |
|
49020 | if (takesArguments) {
|
49021 | this.__cache = setIn(this.__cache, keys, v);
|
49022 | } else {
|
49023 | this.__cache.set(property, v);
|
49024 | }
|
49025 |
|
49026 | return value;
|
49027 | };
|
49028 | };
|
49029 |
|
49030 | for (var i = 0; i < properties.length; i++) {
|
49031 | _loop(i);
|
49032 | }
|
49033 | }
|
49034 |
|
49035 | /**
|
49036 | * Get a value at a key path in a tree of Map.
|
49037 | *
|
49038 | * If not set, returns UNSET.
|
49039 | * If the set value is undefined, returns UNDEFINED.
|
49040 | *
|
49041 | * @param {Map} map
|
49042 | * @param {Array} keys
|
49043 | * @return {Any|UNSET|UNDEFINED}
|
49044 | */
|
49045 |
|
49046 | function getIn(map, keys) {
|
49047 | for (var i = 0; i < keys.length; i++) {
|
49048 | var key = keys[i];
|
49049 | map = map.get(key);
|
49050 | if (map === UNSET) return UNSET;
|
49051 | }
|
49052 |
|
49053 | return map.get(LEAF);
|
49054 | }
|
49055 |
|
49056 | /**
|
49057 | * Set a value at a key path in a tree of Map, creating Maps on the go.
|
49058 | *
|
49059 | * @param {Map} map
|
49060 | * @param {Array} keys
|
49061 | * @param {Any} value
|
49062 | * @return {Map}
|
49063 | */
|
49064 |
|
49065 | function setIn(map, keys, value) {
|
49066 | var parent = map;
|
49067 | var child = void 0;
|
49068 |
|
49069 | for (var i = 0; i < keys.length; i++) {
|
49070 | var key = keys[i];
|
49071 | child = parent.get(key);
|
49072 |
|
49073 | // If the path was not created yet...
|
49074 | if (child === UNSET) {
|
49075 | child = new _es6Map2.default();
|
49076 | parent.set(key, child);
|
49077 | }
|
49078 |
|
49079 | parent = child;
|
49080 | }
|
49081 |
|
49082 | // The whole path has been created, so set the value to the bottom most map.
|
49083 | child.set(LEAF, value);
|
49084 | return map;
|
49085 | }
|
49086 |
|
49087 | /**
|
49088 | * In DEV mode, clears the previously memoized values, globally.
|
49089 | *
|
49090 | * @return {Void}
|
49091 | */
|
49092 |
|
49093 | function __clear() {
|
49094 | CACHE_KEY++;
|
49095 |
|
49096 | if (CACHE_KEY >= Number.MAX_SAFE_INTEGER) {
|
49097 | CACHE_KEY = 0;
|
49098 | }
|
49099 | }
|
49100 |
|
49101 | /**
|
49102 | * In DEV mode, enable or disable the use of memoize values, globally.
|
49103 | *
|
49104 | * @param {Boolean} enabled
|
49105 | * @return {Void}
|
49106 | */
|
49107 |
|
49108 | function __enable(enabled) {
|
49109 | ENABLED = enabled;
|
49110 | }
|
49111 |
|
49112 | /**
|
49113 | * Export.
|
49114 | *
|
49115 | * @type {Object}
|
49116 | */
|
49117 |
|
49118 | exports.default = memoize;
|
49119 | exports.__clear = __clear;
|
49120 | exports.__enable = __enable;
|
49121 | },{"../constants/is-dev":327,"es6-map":28}],368:[function(require,module,exports){
|
49122 | "use strict";
|
49123 |
|
49124 | Object.defineProperty(exports, "__esModule", {
|
49125 | value: true
|
49126 | });
|
49127 |
|
49128 | /**
|
49129 | * Noop.
|
49130 | *
|
49131 | * @return {Void}
|
49132 | */
|
49133 |
|
49134 | function noop() {}
|
49135 |
|
49136 | /**
|
49137 | * Export.
|
49138 | *
|
49139 | * @type {Function}
|
49140 | */
|
49141 |
|
49142 | exports.default = noop;
|
49143 | },{}],369:[function(require,module,exports){
|
49144 | 'use strict';
|
49145 |
|
49146 | Object.defineProperty(exports, "__esModule", {
|
49147 | value: true
|
49148 | });
|
49149 |
|
49150 | /**
|
49151 | * From a DOM selection's `node` and `offset`, normalize so that it always
|
49152 | * refers to a text node.
|
49153 | *
|
49154 | * @param {Element} node
|
49155 | * @param {Number} offset
|
49156 | * @return {Object}
|
49157 | */
|
49158 |
|
49159 | function normalizeNodeAndOffset(node, offset) {
|
49160 | // If it's an element node, its offset refers to the index of its children
|
49161 | // including comment nodes, so try to find the right text child node.
|
49162 | if (node.nodeType == 1 && node.childNodes.length) {
|
49163 | var isLast = offset == node.childNodes.length;
|
49164 | var direction = isLast ? 'backward' : 'forward';
|
49165 | var index = isLast ? offset - 1 : offset;
|
49166 | node = getEditableChild(node, index, direction);
|
49167 |
|
49168 | // If the node has children, traverse until we have a leaf node. Leaf nodes
|
49169 | // can be either text nodes, or other void DOM nodes.
|
49170 | while (node.nodeType == 1 && node.childNodes.length) {
|
49171 | var i = isLast ? node.childNodes.length - 1 : 0;
|
49172 | node = getEditableChild(node, i, direction);
|
49173 | }
|
49174 |
|
49175 | // Determine the new offset inside the text node.
|
49176 | offset = isLast ? node.textContent.length : 0;
|
49177 | }
|
49178 |
|
49179 | // Return the node and offset.
|
49180 | return { node: node, offset: offset };
|
49181 | }
|
49182 |
|
49183 | /**
|
49184 | * Get the nearest editable child at `index` in a `parent`, preferring
|
49185 | * `direction`.
|
49186 | *
|
49187 | * @param {Element} parent
|
49188 | * @param {Number} index
|
49189 | * @param {String} direction ('forward' or 'backward')
|
49190 | * @return {Element|Null}
|
49191 | */
|
49192 |
|
49193 | function getEditableChild(parent, index, direction) {
|
49194 | var childNodes = parent.childNodes;
|
49195 |
|
49196 | var child = childNodes[index];
|
49197 | var i = index;
|
49198 | var triedForward = false;
|
49199 | var triedBackward = false;
|
49200 |
|
49201 | // While the child is a comment node, or an element node with no children,
|
49202 | // keep iterating to find a sibling non-void, non-comment node.
|
49203 | while (child.nodeType == 8 || child.nodeType == 1 && child.childNodes.length == 0 || child.nodeType == 1 && child.getAttribute('contenteditable') == 'false') {
|
49204 | if (triedForward && triedBackward) break;
|
49205 |
|
49206 | if (i >= childNodes.length) {
|
49207 | triedForward = true;
|
49208 | i = index - 1;
|
49209 | direction = 'backward';
|
49210 | continue;
|
49211 | }
|
49212 |
|
49213 | if (i < 0) {
|
49214 | triedBackward = true;
|
49215 | i = index + 1;
|
49216 | direction = 'forward';
|
49217 | continue;
|
49218 | }
|
49219 |
|
49220 | child = childNodes[i];
|
49221 | if (direction == 'forward') i++;
|
49222 | if (direction == 'backward') i--;
|
49223 | }
|
49224 |
|
49225 | return child || null;
|
49226 | }
|
49227 |
|
49228 | /**
|
49229 | * Export.
|
49230 | *
|
49231 | * @type {Function}
|
49232 | */
|
49233 |
|
49234 | exports.default = normalizeNodeAndOffset;
|
49235 | },{}],370:[function(require,module,exports){
|
49236 | 'use strict';
|
49237 |
|
49238 | Object.defineProperty(exports, "__esModule", {
|
49239 | value: true
|
49240 | });
|
49241 |
|
49242 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
49243 |
|
49244 | var _normalizeNodeAndOffset = require('./normalize-node-and-offset');
|
49245 |
|
49246 | var _normalizeNodeAndOffset2 = _interopRequireDefault(_normalizeNodeAndOffset);
|
49247 |
|
49248 | var _findClosestNode = require('./find-closest-node');
|
49249 |
|
49250 | var _findClosestNode2 = _interopRequireDefault(_findClosestNode);
|
49251 |
|
49252 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
49253 |
|
49254 | /**
|
49255 | * Offset key parser regex.
|
49256 | *
|
49257 | * @type {RegExp}
|
49258 | */
|
49259 |
|
49260 | var PARSER = /^(\w+)(?:-(\d+))?$/;
|
49261 |
|
49262 | /**
|
49263 | * Offset key attribute name.
|
49264 | *
|
49265 | * @type {String}
|
49266 | */
|
49267 |
|
49268 | var ATTRIBUTE = 'data-offset-key';
|
49269 |
|
49270 | /**
|
49271 | * Offset key attribute selector.
|
49272 | *
|
49273 | * @type {String}
|
49274 | */
|
49275 |
|
49276 | var SELECTOR = '[' + ATTRIBUTE + ']';
|
49277 |
|
49278 | /**
|
49279 | * Void node selection.
|
49280 | *
|
49281 | * @type {String}
|
49282 | */
|
49283 |
|
49284 | var VOID_SELECTOR = '[data-slate-void]';
|
49285 |
|
49286 | /**
|
49287 | * Find the start and end bounds from an `offsetKey` and `ranges`.
|
49288 | *
|
49289 | * @param {Number} index
|
49290 | * @param {List<Range>} ranges
|
49291 | * @return {Object}
|
49292 | */
|
49293 |
|
49294 | function findBounds(index, ranges) {
|
49295 | var range = ranges.get(index);
|
49296 | var start = ranges.slice(0, index).reduce(function (memo, r) {
|
49297 | return memo += r.text.length;
|
49298 | }, 0);
|
49299 |
|
49300 | return {
|
49301 | start: start,
|
49302 | end: start + range.text.length
|
49303 | };
|
49304 | }
|
49305 |
|
49306 | /**
|
49307 | * From a DOM node, find the closest parent's offset key.
|
49308 | *
|
49309 | * @param {Element} rawNode
|
49310 | * @param {Number} rawOffset
|
49311 | * @return {Object}
|
49312 | */
|
49313 |
|
49314 | function findKey(rawNode, rawOffset) {
|
49315 | var _normalizeNodeAndOffs = (0, _normalizeNodeAndOffset2.default)(rawNode, rawOffset),
|
49316 | node = _normalizeNodeAndOffs.node,
|
49317 | offset = _normalizeNodeAndOffs.offset;
|
49318 |
|
49319 | var parentNode = node.parentNode;
|
49320 |
|
49321 | // Find the closest parent with an offset key attribute.
|
49322 |
|
49323 | var closest = (0, _findClosestNode2.default)(parentNode, SELECTOR);
|
49324 |
|
49325 | // For void nodes, the element with the offset key will be a cousin, not an
|
49326 | // ancestor, so find it by going down from the nearest void parent.
|
49327 | if (!closest) {
|
49328 | var closestVoid = (0, _findClosestNode2.default)(parentNode, VOID_SELECTOR);
|
49329 | if (!closestVoid) return null;
|
49330 | closest = closestVoid.querySelector(SELECTOR);
|
49331 | offset = closest.textContent.length;
|
49332 | }
|
49333 |
|
49334 | // Get the string value of the offset key attribute.
|
49335 | var offsetKey = closest.getAttribute(ATTRIBUTE);
|
49336 |
|
49337 | // If we still didn't find an offset key, abort.
|
49338 | if (!offsetKey) return null;
|
49339 |
|
49340 | // Return the parsed the offset key.
|
49341 | var parsed = parse(offsetKey);
|
49342 | return {
|
49343 | key: parsed.key,
|
49344 | index: parsed.index,
|
49345 | offset: offset
|
49346 | };
|
49347 | }
|
49348 |
|
49349 | /**
|
49350 | * Find the selection point from an `offsetKey` and `ranges`.
|
49351 | *
|
49352 | * @param {Object} offsetKey
|
49353 | * @param {List<Range>} ranges
|
49354 | * @return {Object}
|
49355 | */
|
49356 |
|
49357 | function findPoint(offsetKey, ranges) {
|
49358 | var key = offsetKey.key,
|
49359 | index = offsetKey.index,
|
49360 | offset = offsetKey.offset;
|
49361 |
|
49362 | var _findBounds = findBounds(index, ranges),
|
49363 | start = _findBounds.start,
|
49364 | end = _findBounds.end;
|
49365 |
|
49366 | // Don't let the offset be outside of the start and end bounds.
|
49367 |
|
49368 |
|
49369 | offset = start + offset;
|
49370 | offset = Math.max(offset, start);
|
49371 | offset = Math.min(offset, end);
|
49372 |
|
49373 | return {
|
49374 | key: key,
|
49375 | index: index,
|
49376 | start: start,
|
49377 | end: end,
|
49378 | offset: offset
|
49379 | };
|
49380 | }
|
49381 |
|
49382 | /**
|
49383 | * Parse an offset key `string`.
|
49384 | *
|
49385 | * @param {String} string
|
49386 | * @return {Object}
|
49387 | */
|
49388 |
|
49389 | function parse(string) {
|
49390 | var matches = PARSER.exec(string);
|
49391 | if (!matches) throw new Error('Invalid offset key string "' + string + '".');
|
49392 |
|
49393 | var _matches = _slicedToArray(matches, 3),
|
49394 | original = _matches[0],
|
49395 | key = _matches[1],
|
49396 | index = _matches[2]; // eslint-disable-line no-unused-vars
|
49397 |
|
49398 |
|
49399 | return {
|
49400 | key: key,
|
49401 | index: parseInt(index, 10)
|
49402 | };
|
49403 | }
|
49404 |
|
49405 | /**
|
49406 | * Stringify an offset key `object`.
|
49407 | *
|
49408 | * @param {Object} object
|
49409 | * @property {String} key
|
49410 | * @property {Number} index
|
49411 | * @return {String}
|
49412 | */
|
49413 |
|
49414 | function stringify(object) {
|
49415 | return object.key + '-' + object.index;
|
49416 | }
|
49417 |
|
49418 | /**
|
49419 | * Export.
|
49420 | *
|
49421 | * @type {Object}
|
49422 | */
|
49423 |
|
49424 | exports.default = {
|
49425 | findBounds: findBounds,
|
49426 | findKey: findKey,
|
49427 | findPoint: findPoint,
|
49428 | parse: parse,
|
49429 | stringify: stringify
|
49430 | };
|
49431 | },{"./find-closest-node":356,"./normalize-node-and-offset":369}],371:[function(require,module,exports){
|
49432 | 'use strict';
|
49433 |
|
49434 | Object.defineProperty(exports, "__esModule", {
|
49435 | value: true
|
49436 | });
|
49437 |
|
49438 | var _block = require('../models/block');
|
49439 |
|
49440 | var _block2 = _interopRequireDefault(_block);
|
49441 |
|
49442 | var _change = require('../models/change');
|
49443 |
|
49444 | var _change2 = _interopRequireDefault(_change);
|
49445 |
|
49446 | var _character = require('../models/character');
|
49447 |
|
49448 | var _character2 = _interopRequireDefault(_character);
|
49449 |
|
49450 | var _data = require('../models/data');
|
49451 |
|
49452 | var _data2 = _interopRequireDefault(_data);
|
49453 |
|
49454 | var _document = require('../models/document');
|
49455 |
|
49456 | var _document2 = _interopRequireDefault(_document);
|
49457 |
|
49458 | var _history = require('../models/history');
|
49459 |
|
49460 | var _history2 = _interopRequireDefault(_history);
|
49461 |
|
49462 | var _inline = require('../models/inline');
|
49463 |
|
49464 | var _inline2 = _interopRequireDefault(_inline);
|
49465 |
|
49466 | var _mark = require('../models/mark');
|
49467 |
|
49468 | var _mark2 = _interopRequireDefault(_mark);
|
49469 |
|
49470 | var _node = require('../models/node');
|
49471 |
|
49472 | var _node2 = _interopRequireDefault(_node);
|
49473 |
|
49474 | var _range = require('../models/range');
|
49475 |
|
49476 | var _range2 = _interopRequireDefault(_range);
|
49477 |
|
49478 | var _schema = require('../models/schema');
|
49479 |
|
49480 | var _schema2 = _interopRequireDefault(_schema);
|
49481 |
|
49482 | var _selection = require('../models/selection');
|
49483 |
|
49484 | var _selection2 = _interopRequireDefault(_selection);
|
49485 |
|
49486 | var _stack = require('../models/stack');
|
49487 |
|
49488 | var _stack2 = _interopRequireDefault(_stack);
|
49489 |
|
49490 | var _state = require('../models/state');
|
49491 |
|
49492 | var _state2 = _interopRequireDefault(_state);
|
49493 |
|
49494 | var _text = require('../models/text');
|
49495 |
|
49496 | var _text2 = _interopRequireDefault(_text);
|
49497 |
|
49498 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
49499 |
|
49500 | /**
|
49501 | * Create a prop type checker for Slate objects with `name` and `validate`.
|
49502 | *
|
49503 | * @param {String} name
|
49504 | * @param {Function} validate
|
49505 | * @return {Function}
|
49506 | */
|
49507 |
|
49508 | function create(name, validate) {
|
49509 | function check(isRequired, props, propName, componentName, location) {
|
49510 | var value = props[propName];
|
49511 | if (value == null && !isRequired) return null;
|
49512 | if (value == null && isRequired) return new Error('The ' + location + ' `' + propName + '` is marked as required in `' + componentName + '`, but it was not supplied.');
|
49513 | if (validate(value)) return null;
|
49514 | return new Error('Invalid ' + location + ' `' + propName + '` supplied to `' + componentName + '`, expected a Slate `' + name + '` but received: ' + value);
|
49515 | }
|
49516 |
|
49517 | function propType() {
|
49518 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
49519 | args[_key] = arguments[_key];
|
49520 | }
|
49521 |
|
49522 | return check.apply(undefined, [false].concat(args));
|
49523 | }
|
49524 |
|
49525 | propType.isRequired = function () {
|
49526 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
49527 | args[_key2] = arguments[_key2];
|
49528 | }
|
49529 |
|
49530 | return check.apply(undefined, [true].concat(args));
|
49531 | };
|
49532 |
|
49533 | return propType;
|
49534 | }
|
49535 |
|
49536 | /**
|
49537 | * Prop type checkers.
|
49538 | *
|
49539 | * @type {Object}
|
49540 | */
|
49541 |
|
49542 | var Types = {
|
49543 | block: create('Block', function (v) {
|
49544 | return _block2.default.isBlock(v);
|
49545 | }),
|
49546 | blocks: create('List<Block>', function (v) {
|
49547 | return _block2.default.isBlockList(v);
|
49548 | }),
|
49549 | change: create('Change', function (v) {
|
49550 | return _change2.default.isChange(v);
|
49551 | }),
|
49552 | character: create('Character', function (v) {
|
49553 | return _character2.default.isCharacter(v);
|
49554 | }),
|
49555 | characters: create('List<Character>', function (v) {
|
49556 | return _character2.default.isCharacterList(v);
|
49557 | }),
|
49558 | data: create('Data', function (v) {
|
49559 | return _data2.default.isData(v);
|
49560 | }),
|
49561 | document: create('Document', function (v) {
|
49562 | return _document2.default.isDocument(v);
|
49563 | }),
|
49564 | history: create('History', function (v) {
|
49565 | return _history2.default.isHistory(v);
|
49566 | }),
|
49567 | inline: create('Inline', function (v) {
|
49568 | return _inline2.default.isInline(v);
|
49569 | }),
|
49570 | mark: create('Mark', function (v) {
|
49571 | return _mark2.default.isMark(v);
|
49572 | }),
|
49573 | marks: create('Set<Mark>', function (v) {
|
49574 | return _mark2.default.isMarkSet(v);
|
49575 | }),
|
49576 | node: create('Node', function (v) {
|
49577 | return _node2.default.isNode(v);
|
49578 | }),
|
49579 | nodes: create('List<Node>', function (v) {
|
49580 | return _node2.default.isNodeList(v);
|
49581 | }),
|
49582 | range: create('Range', function (v) {
|
49583 | return _range2.default.isRange(v);
|
49584 | }),
|
49585 | ranges: create('List<Range>', function (v) {
|
49586 | return _range2.default.isRangeList(v);
|
49587 | }),
|
49588 | schema: create('Schema', function (v) {
|
49589 | return _schema2.default.isSchema(v);
|
49590 | }),
|
49591 | selection: create('Selection', function (v) {
|
49592 | return _selection2.default.isSelection(v);
|
49593 | }),
|
49594 | stack: create('Stack', function (v) {
|
49595 | return _stack2.default.isStack(v);
|
49596 | }),
|
49597 | state: create('State', function (v) {
|
49598 | return _state2.default.isState(v);
|
49599 | }),
|
49600 | text: create('Text', function (v) {
|
49601 | return _text2.default.isText(v);
|
49602 | }),
|
49603 | texts: create('List<Text>', function (v) {
|
49604 | return _text2.default.isTextList(v);
|
49605 | })
|
49606 | };
|
49607 |
|
49608 | /**
|
49609 | * Export.
|
49610 | *
|
49611 | * @type {Object}
|
49612 | */
|
49613 |
|
49614 | exports.default = Types;
|
49615 | },{"../models/block":331,"../models/change":332,"../models/character":333,"../models/data":334,"../models/document":335,"../models/history":336,"../models/inline":337,"../models/mark":338,"../models/node":339,"../models/range":340,"../models/schema":341,"../models/selection":342,"../models/stack":343,"../models/state":344,"../models/text":345}],372:[function(require,module,exports){
|
49616 | 'use strict';
|
49617 |
|
49618 | Object.defineProperty(exports, "__esModule", {
|
49619 | value: true
|
49620 | });
|
49621 |
|
49622 | var _getWindow = require('get-window');
|
49623 |
|
49624 | var _getWindow2 = _interopRequireDefault(_getWindow);
|
49625 |
|
49626 | var _selectionIsBackward = require('selection-is-backward');
|
49627 |
|
49628 | var _selectionIsBackward2 = _interopRequireDefault(_selectionIsBackward);
|
49629 |
|
49630 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
49631 |
|
49632 | /**
|
49633 | * Scroll the current selection's focus point into view if needed.
|
49634 | *
|
49635 | * @param {Selection} selection
|
49636 | */
|
49637 |
|
49638 | function scrollToSelection(selection) {
|
49639 | if (!selection.anchorNode) return;
|
49640 |
|
49641 | var window = (0, _getWindow2.default)(selection.anchorNode);
|
49642 | var backward = (0, _selectionIsBackward2.default)(selection);
|
49643 | var range = selection.getRangeAt(0);
|
49644 | var rect = range.getBoundingClientRect();
|
49645 | var innerWidth = window.innerWidth,
|
49646 | innerHeight = window.innerHeight,
|
49647 | pageYOffset = window.pageYOffset,
|
49648 | pageXOffset = window.pageXOffset;
|
49649 |
|
49650 | var top = (backward ? rect.top : rect.bottom) + pageYOffset;
|
49651 | var left = (backward ? rect.left : rect.right) + pageXOffset;
|
49652 |
|
49653 | var x = left < pageXOffset || innerWidth + pageXOffset < left ? left - innerWidth / 2 : pageXOffset;
|
49654 |
|
49655 | var y = top < pageYOffset || innerHeight + pageYOffset < top ? top - innerHeight / 2 : pageYOffset;
|
49656 |
|
49657 | window.scrollTo(x, y);
|
49658 | }
|
49659 |
|
49660 | /**
|
49661 | * Export.
|
49662 | *
|
49663 | * @type {Function}
|
49664 | */
|
49665 |
|
49666 | exports.default = scrollToSelection;
|
49667 | },{"get-window":133,"selection-is-backward":311}],373:[function(require,module,exports){
|
49668 | 'use strict';
|
49669 |
|
49670 | Object.defineProperty(exports, "__esModule", {
|
49671 | value: true
|
49672 | });
|
49673 |
|
49674 | /**
|
49675 | * Set data with `type` and `content` on a `dataTransfer` object.
|
49676 | *
|
49677 | * COMPAT: In Edge, custom types throw errors, so embed all non-standard
|
49678 | * types in text/plain compound object. (2017/7/12)
|
49679 | *
|
49680 | * @param {DataTransfer} dataTransfer
|
49681 | * @param {String} type
|
49682 | * @param {String} content
|
49683 | */
|
49684 |
|
49685 | function setTransferData(dataTransfer, type, content) {
|
49686 | try {
|
49687 | dataTransfer.setData(type, content);
|
49688 | } catch (err) {
|
49689 | var prefix = 'SLATE-DATA-EMBED::';
|
49690 | var text = dataTransfer.getData('text/plain');
|
49691 | var obj = {};
|
49692 |
|
49693 | // If the existing plain text data is prefixed, it's Slate JSON data.
|
49694 | if (text.substring(0, prefix.length) === prefix) {
|
49695 | try {
|
49696 | obj = JSON.parse(text.substring(prefix.length));
|
49697 | } catch (e) {
|
49698 | throw new Error('Failed to parse Slate data from `DataTransfer` object.');
|
49699 | }
|
49700 | }
|
49701 |
|
49702 | // Otherwise, it's just set it as is.
|
49703 | else {
|
49704 | obj['text/plain'] = text;
|
49705 | }
|
49706 |
|
49707 | obj[type] = content;
|
49708 | var string = '' + prefix + JSON.stringify(obj);
|
49709 | dataTransfer.setData('text/plain', string);
|
49710 | }
|
49711 | }
|
49712 |
|
49713 | /**
|
49714 | * Export.
|
49715 | *
|
49716 | * @type {Function}
|
49717 | */
|
49718 |
|
49719 | exports.default = setTransferData;
|
49720 | },{}],374:[function(require,module,exports){
|
49721 | 'use strict';
|
49722 |
|
49723 | Object.defineProperty(exports, "__esModule", {
|
49724 | value: true
|
49725 | });
|
49726 |
|
49727 | var _esrever = require('esrever');
|
49728 |
|
49729 | /**
|
49730 | * Surrogate pair start and end points.
|
49731 | *
|
49732 | * @type {Number}
|
49733 | */
|
49734 |
|
49735 | var SURROGATE_START = 0xD800;
|
49736 | var SURROGATE_END = 0xDFFF;
|
49737 |
|
49738 | /**
|
49739 | * A regex to match space characters.
|
49740 | *
|
49741 | * @type {RegExp}
|
49742 | */
|
49743 |
|
49744 | var SPACE = /\s/;
|
49745 |
|
49746 | /**
|
49747 | * A regex to match chameleon characters, that count as word characters as long
|
49748 | * as they are inside of a word.
|
49749 | *
|
49750 | * @type {RegExp}
|
49751 | */
|
49752 |
|
49753 | var CHAMELEON = /['\u2018\u2019]/;
|
49754 |
|
49755 | /**
|
49756 | * A regex that matches punctuation.
|
49757 | *
|
49758 | * @type {RegExp}
|
49759 | */
|
49760 |
|
49761 | var PUNCTUATION = /[\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/;
|
49762 |
|
49763 | /**
|
49764 | * Is a character `code` in a surrogate character.
|
49765 | *
|
49766 | * @param {Number} code
|
49767 | * @return {Boolean}
|
49768 | */
|
49769 |
|
49770 | function isSurrogate(code) {
|
49771 | return SURROGATE_START <= code && code <= SURROGATE_END;
|
49772 | }
|
49773 |
|
49774 | /**
|
49775 | * Is a character a word character? Needs the `remaining` characters too.
|
49776 | *
|
49777 | * @param {String} char
|
49778 | * @param {String|Void} remaining
|
49779 | * @return {Boolean}
|
49780 | */
|
49781 |
|
49782 | function isWord(char, remaining) {
|
49783 | if (SPACE.test(char)) return false;
|
49784 |
|
49785 | // If it's a chameleon character, recurse to see if the next one is or not.
|
49786 | if (CHAMELEON.test(char)) {
|
49787 | var next = remaining.charAt(0);
|
49788 | var length = getCharLength(next);
|
49789 | next = remaining.slice(0, length);
|
49790 | var rest = remaining.slice(length);
|
49791 | if (isWord(next, rest)) return true;
|
49792 | }
|
49793 |
|
49794 | if (PUNCTUATION.test(char)) return false;
|
49795 | return true;
|
49796 | }
|
49797 |
|
49798 | /**
|
49799 | * Get the length of a `character`.
|
49800 | *
|
49801 | * @param {String} char
|
49802 | * @return {Number}
|
49803 | */
|
49804 |
|
49805 | function getCharLength(char) {
|
49806 | return isSurrogate(char.charCodeAt(0)) ? 2 : 1;
|
49807 | }
|
49808 |
|
49809 | /**
|
49810 | * Get the offset to the end of the first character in `text`.
|
49811 | *
|
49812 | * @param {String} text
|
49813 | * @return {Number}
|
49814 | */
|
49815 |
|
49816 | function getCharOffset(text) {
|
49817 | var char = text.charAt(0);
|
49818 | return getCharLength(char);
|
49819 | }
|
49820 |
|
49821 | /**
|
49822 | * Get the offset to the end of the character before an `offset` in `text`.
|
49823 | *
|
49824 | * @param {String} text
|
49825 | * @param {Number} offset
|
49826 | * @return {Number}
|
49827 | */
|
49828 |
|
49829 | function getCharOffsetBackward(text, offset) {
|
49830 | text = text.slice(0, offset);
|
49831 | text = (0, _esrever.reverse)(text);
|
49832 | return getCharOffset(text);
|
49833 | }
|
49834 |
|
49835 | /**
|
49836 | * Get the offset to the end of the character after an `offset` in `text`.
|
49837 | *
|
49838 | * @param {String} text
|
49839 | * @param {Number} offset
|
49840 | * @return {Number}
|
49841 | */
|
49842 |
|
49843 | function getCharOffsetForward(text, offset) {
|
49844 | text = text.slice(offset);
|
49845 | return getCharOffset(text);
|
49846 | }
|
49847 |
|
49848 | /**
|
49849 | * Get the offset to the end of the first word in `text`.
|
49850 | *
|
49851 | * @param {String} text
|
49852 | * @return {Number}
|
49853 | */
|
49854 |
|
49855 | function getWordOffset(text) {
|
49856 | var length = 0;
|
49857 | var i = 0;
|
49858 | var started = false;
|
49859 | var char = void 0;
|
49860 |
|
49861 | while (char = text.charAt(i)) {
|
49862 | var l = getCharLength(char);
|
49863 | char = text.slice(i, i + l);
|
49864 | var rest = text.slice(i + l);
|
49865 |
|
49866 | if (isWord(char, rest)) {
|
49867 | started = true;
|
49868 | length += l;
|
49869 | } else if (!started) {
|
49870 | length += l;
|
49871 | } else {
|
49872 | break;
|
49873 | }
|
49874 |
|
49875 | i += l;
|
49876 | }
|
49877 |
|
49878 | return length;
|
49879 | }
|
49880 |
|
49881 | /**
|
49882 | * Get the offset to the end of the word before an `offset` in `text`.
|
49883 | *
|
49884 | * @param {String} text
|
49885 | * @param {Number} offset
|
49886 | * @return {Number}
|
49887 | */
|
49888 |
|
49889 | function getWordOffsetBackward(text, offset) {
|
49890 | text = text.slice(0, offset);
|
49891 | text = (0, _esrever.reverse)(text);
|
49892 | var o = getWordOffset(text);
|
49893 | return o;
|
49894 | }
|
49895 |
|
49896 | /**
|
49897 | * Get the offset to the end of the word after an `offset` in `text`.
|
49898 | *
|
49899 | * @param {String} text
|
49900 | * @param {Number} offset
|
49901 | * @return {Number}
|
49902 | */
|
49903 |
|
49904 | function getWordOffsetForward(text, offset) {
|
49905 | text = text.slice(offset);
|
49906 | var o = getWordOffset(text);
|
49907 | return o;
|
49908 | }
|
49909 |
|
49910 | /**
|
49911 | * Export.
|
49912 | *
|
49913 | * @type {Object}
|
49914 | */
|
49915 |
|
49916 | exports.default = {
|
49917 | getCharOffsetForward: getCharOffsetForward,
|
49918 | getCharOffsetBackward: getCharOffsetBackward,
|
49919 | getWordOffsetBackward: getWordOffsetBackward,
|
49920 | getWordOffsetForward: getWordOffsetForward
|
49921 | };
|
49922 | },{"esrever":108}],375:[function(require,module,exports){
|
49923 | (function (process){
|
49924 | /**
|
49925 | * This is the web browser implementation of `debug()`.
|
49926 | *
|
49927 | * Expose `debug()` as the module.
|
49928 | */
|
49929 |
|
49930 | exports = module.exports = require('./debug');
|
49931 | exports.log = log;
|
49932 | exports.formatArgs = formatArgs;
|
49933 | exports.save = save;
|
49934 | exports.load = load;
|
49935 | exports.useColors = useColors;
|
49936 | exports.storage = 'undefined' != typeof chrome
|
49937 | && 'undefined' != typeof chrome.storage
|
49938 | ? chrome.storage.local
|
49939 | : localstorage();
|
49940 |
|
49941 | /**
|
49942 | * Colors.
|
49943 | */
|
49944 |
|
49945 | exports.colors = [
|
49946 | 'lightseagreen',
|
49947 | 'forestgreen',
|
49948 | 'goldenrod',
|
49949 | 'dodgerblue',
|
49950 | 'darkorchid',
|
49951 | 'crimson'
|
49952 | ];
|
49953 |
|
49954 | /**
|
49955 | * Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
49956 | * and the Firebug extension (any Firefox version) are known
|
49957 | * to support "%c" CSS customizations.
|
49958 | *
|
49959 | * TODO: add a `localStorage` variable to explicitly enable/disable colors
|
49960 | */
|
49961 |
|
49962 | function useColors() {
|
49963 | // NB: In an Electron preload script, document will be defined but not fully
|
49964 | // initialized. Since we know we're in Chrome, we'll just detect this case
|
49965 | // explicitly
|
49966 | if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {
|
49967 | return true;
|
49968 | }
|
49969 |
|
49970 | // is webkit? http://stackoverflow.com/a/16459606/376773
|
49971 | // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
49972 | return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
49973 | // is firebug? http://stackoverflow.com/a/398120/376773
|
49974 | (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
49975 | // is firefox >= v31?
|
49976 | // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
49977 | (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
49978 | // double check webkit in userAgent just in case we are in a worker
|
49979 | (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
49980 | }
|
49981 |
|
49982 | /**
|
49983 | * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
49984 | */
|
49985 |
|
49986 | exports.formatters.j = function(v) {
|
49987 | try {
|
49988 | return JSON.stringify(v);
|
49989 | } catch (err) {
|
49990 | return '[UnexpectedJSONParseError]: ' + err.message;
|
49991 | }
|
49992 | };
|
49993 |
|
49994 |
|
49995 | /**
|
49996 | * Colorize log arguments if enabled.
|
49997 | *
|
49998 | * @api public
|
49999 | */
|
50000 |
|
50001 | function formatArgs(args) {
|
50002 | var useColors = this.useColors;
|
50003 |
|
50004 | args[0] = (useColors ? '%c' : '')
|
50005 | + this.namespace
|
50006 | + (useColors ? ' %c' : ' ')
|
50007 | + args[0]
|
50008 | + (useColors ? '%c ' : ' ')
|
50009 | + '+' + exports.humanize(this.diff);
|
50010 |
|
50011 | if (!useColors) return;
|
50012 |
|
50013 | var c = 'color: ' + this.color;
|
50014 | args.splice(1, 0, c, 'color: inherit')
|
50015 |
|
50016 | // the final "%c" is somewhat tricky, because there could be other
|
50017 | // arguments passed either before or after the %c, so we need to
|
50018 | // figure out the correct index to insert the CSS into
|
50019 | var index = 0;
|
50020 | var lastC = 0;
|
50021 | args[0].replace(/%[a-zA-Z%]/g, function(match) {
|
50022 | if ('%%' === match) return;
|
50023 | index++;
|
50024 | if ('%c' === match) {
|
50025 | // we only are interested in the *last* %c
|
50026 | // (the user may have provided their own)
|
50027 | lastC = index;
|
50028 | }
|
50029 | });
|
50030 |
|
50031 | args.splice(lastC, 0, c);
|
50032 | }
|
50033 |
|
50034 | /**
|
50035 | * Invokes `console.log()` when available.
|
50036 | * No-op when `console.log` is not a "function".
|
50037 | *
|
50038 | * @api public
|
50039 | */
|
50040 |
|
50041 | function log() {
|
50042 | // this hackery is required for IE8/9, where
|
50043 | // the `console.log` function doesn't have 'apply'
|
50044 | return 'object' === typeof console
|
50045 | && console.log
|
50046 | && Function.prototype.apply.call(console.log, console, arguments);
|
50047 | }
|
50048 |
|
50049 | /**
|
50050 | * Save `namespaces`.
|
50051 | *
|
50052 | * @param {String} namespaces
|
50053 | * @api private
|
50054 | */
|
50055 |
|
50056 | function save(namespaces) {
|
50057 | try {
|
50058 | if (null == namespaces) {
|
50059 | exports.storage.removeItem('debug');
|
50060 | } else {
|
50061 | exports.storage.debug = namespaces;
|
50062 | }
|
50063 | } catch(e) {}
|
50064 | }
|
50065 |
|
50066 | /**
|
50067 | * Load `namespaces`.
|
50068 | *
|
50069 | * @return {String} returns the previously persisted debug modes
|
50070 | * @api private
|
50071 | */
|
50072 |
|
50073 | function load() {
|
50074 | var r;
|
50075 | try {
|
50076 | r = exports.storage.debug;
|
50077 | } catch(e) {}
|
50078 |
|
50079 | // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
50080 | if (!r && typeof process !== 'undefined' && 'env' in process) {
|
50081 | r = process.env.DEBUG;
|
50082 | }
|
50083 |
|
50084 | return r;
|
50085 | }
|
50086 |
|
50087 | /**
|
50088 | * Enable namespaces listed in `localStorage.debug` initially.
|
50089 | */
|
50090 |
|
50091 | exports.enable(load());
|
50092 |
|
50093 | /**
|
50094 | * Localstorage attempts to return the localstorage.
|
50095 | *
|
50096 | * This is necessary because safari throws
|
50097 | * when a user disables cookies/localstorage
|
50098 | * and you attempt to access it.
|
50099 | *
|
50100 | * @return {LocalStorage}
|
50101 | * @api private
|
50102 | */
|
50103 |
|
50104 | function localstorage() {
|
50105 | try {
|
50106 | return window.localStorage;
|
50107 | } catch (e) {}
|
50108 | }
|
50109 |
|
50110 | }).call(this,require('_process'))
|
50111 | },{"./debug":376,"_process":144}],376:[function(require,module,exports){
|
50112 |
|
50113 | /**
|
50114 | * This is the common logic for both the Node.js and web browser
|
50115 | * implementations of `debug()`.
|
50116 | *
|
50117 | * Expose `debug()` as the module.
|
50118 | */
|
50119 |
|
50120 | exports = module.exports = createDebug.debug = createDebug['default'] = createDebug;
|
50121 | exports.coerce = coerce;
|
50122 | exports.disable = disable;
|
50123 | exports.enable = enable;
|
50124 | exports.enabled = enabled;
|
50125 | exports.humanize = require('ms');
|
50126 |
|
50127 | /**
|
50128 | * The currently active debug mode names, and names to skip.
|
50129 | */
|
50130 |
|
50131 | exports.names = [];
|
50132 | exports.skips = [];
|
50133 |
|
50134 | /**
|
50135 | * Map of special "%n" handling functions, for the debug "format" argument.
|
50136 | *
|
50137 | * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
50138 | */
|
50139 |
|
50140 | exports.formatters = {};
|
50141 |
|
50142 | /**
|
50143 | * Previous log timestamp.
|
50144 | */
|
50145 |
|
50146 | var prevTime;
|
50147 |
|
50148 | /**
|
50149 | * Select a color.
|
50150 | * @param {String} namespace
|
50151 | * @return {Number}
|
50152 | * @api private
|
50153 | */
|
50154 |
|
50155 | function selectColor(namespace) {
|
50156 | var hash = 0, i;
|
50157 |
|
50158 | for (i in namespace) {
|
50159 | hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
50160 | hash |= 0; // Convert to 32bit integer
|
50161 | }
|
50162 |
|
50163 | return exports.colors[Math.abs(hash) % exports.colors.length];
|
50164 | }
|
50165 |
|
50166 | /**
|
50167 | * Create a debugger with the given `namespace`.
|
50168 | *
|
50169 | * @param {String} namespace
|
50170 | * @return {Function}
|
50171 | * @api public
|
50172 | */
|
50173 |
|
50174 | function createDebug(namespace) {
|
50175 |
|
50176 | function debug() {
|
50177 | // disabled?
|
50178 | if (!debug.enabled) return;
|
50179 |
|
50180 | var self = debug;
|
50181 |
|
50182 | // set `diff` timestamp
|
50183 | var curr = +new Date();
|
50184 | var ms = curr - (prevTime || curr);
|
50185 | self.diff = ms;
|
50186 | self.prev = prevTime;
|
50187 | self.curr = curr;
|
50188 | prevTime = curr;
|
50189 |
|
50190 | // turn the `arguments` into a proper Array
|
50191 | var args = new Array(arguments.length);
|
50192 | for (var i = 0; i < args.length; i++) {
|
50193 | args[i] = arguments[i];
|
50194 | }
|
50195 |
|
50196 | args[0] = exports.coerce(args[0]);
|
50197 |
|
50198 | if ('string' !== typeof args[0]) {
|
50199 | // anything else let's inspect with %O
|
50200 | args.unshift('%O');
|
50201 | }
|
50202 |
|
50203 | // apply any `formatters` transformations
|
50204 | var index = 0;
|
50205 | args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
|
50206 | // if we encounter an escaped % then don't increase the array index
|
50207 | if (match === '%%') return match;
|
50208 | index++;
|
50209 | var formatter = exports.formatters[format];
|
50210 | if ('function' === typeof formatter) {
|
50211 | var val = args[index];
|
50212 | match = formatter.call(self, val);
|
50213 |
|
50214 | // now we need to remove `args[index]` since it's inlined in the `format`
|
50215 | args.splice(index, 1);
|
50216 | index--;
|
50217 | }
|
50218 | return match;
|
50219 | });
|
50220 |
|
50221 | // apply env-specific formatting (colors, etc.)
|
50222 | exports.formatArgs.call(self, args);
|
50223 |
|
50224 | var logFn = debug.log || exports.log || console.log.bind(console);
|
50225 | logFn.apply(self, args);
|
50226 | }
|
50227 |
|
50228 | debug.namespace = namespace;
|
50229 | debug.enabled = exports.enabled(namespace);
|
50230 | debug.useColors = exports.useColors();
|
50231 | debug.color = selectColor(namespace);
|
50232 |
|
50233 | // env-specific initialization logic for debug instances
|
50234 | if ('function' === typeof exports.init) {
|
50235 | exports.init(debug);
|
50236 | }
|
50237 |
|
50238 | return debug;
|
50239 | }
|
50240 |
|
50241 | /**
|
50242 | * Enables a debug mode by namespaces. This can include modes
|
50243 | * separated by a colon and wildcards.
|
50244 | *
|
50245 | * @param {String} namespaces
|
50246 | * @api public
|
50247 | */
|
50248 |
|
50249 | function enable(namespaces) {
|
50250 | exports.save(namespaces);
|
50251 |
|
50252 | exports.names = [];
|
50253 | exports.skips = [];
|
50254 |
|
50255 | var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
50256 | var len = split.length;
|
50257 |
|
50258 | for (var i = 0; i < len; i++) {
|
50259 | if (!split[i]) continue; // ignore empty strings
|
50260 | namespaces = split[i].replace(/\*/g, '.*?');
|
50261 | if (namespaces[0] === '-') {
|
50262 | exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
50263 | } else {
|
50264 | exports.names.push(new RegExp('^' + namespaces + '$'));
|
50265 | }
|
50266 | }
|
50267 | }
|
50268 |
|
50269 | /**
|
50270 | * Disable debug output.
|
50271 | *
|
50272 | * @api public
|
50273 | */
|
50274 |
|
50275 | function disable() {
|
50276 | exports.enable('');
|
50277 | }
|
50278 |
|
50279 | /**
|
50280 | * Returns true if the given mode name is enabled, false otherwise.
|
50281 | *
|
50282 | * @param {String} name
|
50283 | * @return {Boolean}
|
50284 | * @api public
|
50285 | */
|
50286 |
|
50287 | function enabled(name) {
|
50288 | var i, len;
|
50289 | for (i = 0, len = exports.skips.length; i < len; i++) {
|
50290 | if (exports.skips[i].test(name)) {
|
50291 | return false;
|
50292 | }
|
50293 | }
|
50294 | for (i = 0, len = exports.names.length; i < len; i++) {
|
50295 | if (exports.names[i].test(name)) {
|
50296 | return true;
|
50297 | }
|
50298 | }
|
50299 | return false;
|
50300 | }
|
50301 |
|
50302 | /**
|
50303 | * Coerce `val`.
|
50304 | *
|
50305 | * @param {Mixed} val
|
50306 | * @return {Mixed}
|
50307 | * @api private
|
50308 | */
|
50309 |
|
50310 | function coerce(val) {
|
50311 | if (val instanceof Error) return val.stack || val.message;
|
50312 | return val;
|
50313 | }
|
50314 |
|
50315 | },{"ms":516}],377:[function(require,module,exports){
|
50316 | var getNative = require('./_getNative'),
|
50317 | root = require('./_root');
|
50318 |
|
50319 | /* Built-in method references that are verified to be native. */
|
50320 | var DataView = getNative(root, 'DataView');
|
50321 |
|
50322 | module.exports = DataView;
|
50323 |
|
50324 | },{"./_getNative":436,"./_root":473}],378:[function(require,module,exports){
|
50325 | var hashClear = require('./_hashClear'),
|
50326 | hashDelete = require('./_hashDelete'),
|
50327 | hashGet = require('./_hashGet'),
|
50328 | hashHas = require('./_hashHas'),
|
50329 | hashSet = require('./_hashSet');
|
50330 |
|
50331 | /**
|
50332 | * Creates a hash object.
|
50333 | *
|
50334 | * @private
|
50335 | * @constructor
|
50336 | * @param {Array} [entries] The key-value pairs to cache.
|
50337 | */
|
50338 | function Hash(entries) {
|
50339 | var index = -1,
|
50340 | length = entries == null ? 0 : entries.length;
|
50341 |
|
50342 | this.clear();
|
50343 | while (++index < length) {
|
50344 | var entry = entries[index];
|
50345 | this.set(entry[0], entry[1]);
|
50346 | }
|
50347 | }
|
50348 |
|
50349 | // Add methods to `Hash`.
|
50350 | Hash.prototype.clear = hashClear;
|
50351 | Hash.prototype['delete'] = hashDelete;
|
50352 | Hash.prototype.get = hashGet;
|
50353 | Hash.prototype.has = hashHas;
|
50354 | Hash.prototype.set = hashSet;
|
50355 |
|
50356 | module.exports = Hash;
|
50357 |
|
50358 | },{"./_hashClear":442,"./_hashDelete":443,"./_hashGet":444,"./_hashHas":445,"./_hashSet":446}],379:[function(require,module,exports){
|
50359 | var listCacheClear = require('./_listCacheClear'),
|
50360 | listCacheDelete = require('./_listCacheDelete'),
|
50361 | listCacheGet = require('./_listCacheGet'),
|
50362 | listCacheHas = require('./_listCacheHas'),
|
50363 | listCacheSet = require('./_listCacheSet');
|
50364 |
|
50365 | /**
|
50366 | * Creates an list cache object.
|
50367 | *
|
50368 | * @private
|
50369 | * @constructor
|
50370 | * @param {Array} [entries] The key-value pairs to cache.
|
50371 | */
|
50372 | function ListCache(entries) {
|
50373 | var index = -1,
|
50374 | length = entries == null ? 0 : entries.length;
|
50375 |
|
50376 | this.clear();
|
50377 | while (++index < length) {
|
50378 | var entry = entries[index];
|
50379 | this.set(entry[0], entry[1]);
|
50380 | }
|
50381 | }
|
50382 |
|
50383 | // Add methods to `ListCache`.
|
50384 | ListCache.prototype.clear = listCacheClear;
|
50385 | ListCache.prototype['delete'] = listCacheDelete;
|
50386 | ListCache.prototype.get = listCacheGet;
|
50387 | ListCache.prototype.has = listCacheHas;
|
50388 | ListCache.prototype.set = listCacheSet;
|
50389 |
|
50390 | module.exports = ListCache;
|
50391 |
|
50392 | },{"./_listCacheClear":454,"./_listCacheDelete":455,"./_listCacheGet":456,"./_listCacheHas":457,"./_listCacheSet":458}],380:[function(require,module,exports){
|
50393 | var getNative = require('./_getNative'),
|
50394 | root = require('./_root');
|
50395 |
|
50396 | /* Built-in method references that are verified to be native. */
|
50397 | var Map = getNative(root, 'Map');
|
50398 |
|
50399 | module.exports = Map;
|
50400 |
|
50401 | },{"./_getNative":436,"./_root":473}],381:[function(require,module,exports){
|
50402 | var mapCacheClear = require('./_mapCacheClear'),
|
50403 | mapCacheDelete = require('./_mapCacheDelete'),
|
50404 | mapCacheGet = require('./_mapCacheGet'),
|
50405 | mapCacheHas = require('./_mapCacheHas'),
|
50406 | mapCacheSet = require('./_mapCacheSet');
|
50407 |
|
50408 | /**
|
50409 | * Creates a map cache object to store key-value pairs.
|
50410 | *
|
50411 | * @private
|
50412 | * @constructor
|
50413 | * @param {Array} [entries] The key-value pairs to cache.
|
50414 | */
|
50415 | function MapCache(entries) {
|
50416 | var index = -1,
|
50417 | length = entries == null ? 0 : entries.length;
|
50418 |
|
50419 | this.clear();
|
50420 | while (++index < length) {
|
50421 | var entry = entries[index];
|
50422 | this.set(entry[0], entry[1]);
|
50423 | }
|
50424 | }
|
50425 |
|
50426 | // Add methods to `MapCache`.
|
50427 | MapCache.prototype.clear = mapCacheClear;
|
50428 | MapCache.prototype['delete'] = mapCacheDelete;
|
50429 | MapCache.prototype.get = mapCacheGet;
|
50430 | MapCache.prototype.has = mapCacheHas;
|
50431 | MapCache.prototype.set = mapCacheSet;
|
50432 |
|
50433 | module.exports = MapCache;
|
50434 |
|
50435 | },{"./_mapCacheClear":459,"./_mapCacheDelete":460,"./_mapCacheGet":461,"./_mapCacheHas":462,"./_mapCacheSet":463}],382:[function(require,module,exports){
|
50436 | var getNative = require('./_getNative'),
|
50437 | root = require('./_root');
|
50438 |
|
50439 | /* Built-in method references that are verified to be native. */
|
50440 | var Promise = getNative(root, 'Promise');
|
50441 |
|
50442 | module.exports = Promise;
|
50443 |
|
50444 | },{"./_getNative":436,"./_root":473}],383:[function(require,module,exports){
|
50445 | var getNative = require('./_getNative'),
|
50446 | root = require('./_root');
|
50447 |
|
50448 | /* Built-in method references that are verified to be native. */
|
50449 | var Set = getNative(root, 'Set');
|
50450 |
|
50451 | module.exports = Set;
|
50452 |
|
50453 | },{"./_getNative":436,"./_root":473}],384:[function(require,module,exports){
|
50454 | var MapCache = require('./_MapCache'),
|
50455 | setCacheAdd = require('./_setCacheAdd'),
|
50456 | setCacheHas = require('./_setCacheHas');
|
50457 |
|
50458 | /**
|
50459 | *
|
50460 | * Creates an array cache object to store unique values.
|
50461 | *
|
50462 | * @private
|
50463 | * @constructor
|
50464 | * @param {Array} [values] The values to cache.
|
50465 | */
|
50466 | function SetCache(values) {
|
50467 | var index = -1,
|
50468 | length = values == null ? 0 : values.length;
|
50469 |
|
50470 | this.__data__ = new MapCache;
|
50471 | while (++index < length) {
|
50472 | this.add(values[index]);
|
50473 | }
|
50474 | }
|
50475 |
|
50476 | // Add methods to `SetCache`.
|
50477 | SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
|
50478 | SetCache.prototype.has = setCacheHas;
|
50479 |
|
50480 | module.exports = SetCache;
|
50481 |
|
50482 | },{"./_MapCache":381,"./_setCacheAdd":474,"./_setCacheHas":475}],385:[function(require,module,exports){
|
50483 | var ListCache = require('./_ListCache'),
|
50484 | stackClear = require('./_stackClear'),
|
50485 | stackDelete = require('./_stackDelete'),
|
50486 | stackGet = require('./_stackGet'),
|
50487 | stackHas = require('./_stackHas'),
|
50488 | stackSet = require('./_stackSet');
|
50489 |
|
50490 | /**
|
50491 | * Creates a stack cache object to store key-value pairs.
|
50492 | *
|
50493 | * @private
|
50494 | * @constructor
|
50495 | * @param {Array} [entries] The key-value pairs to cache.
|
50496 | */
|
50497 | function Stack(entries) {
|
50498 | var data = this.__data__ = new ListCache(entries);
|
50499 | this.size = data.size;
|
50500 | }
|
50501 |
|
50502 | // Add methods to `Stack`.
|
50503 | Stack.prototype.clear = stackClear;
|
50504 | Stack.prototype['delete'] = stackDelete;
|
50505 | Stack.prototype.get = stackGet;
|
50506 | Stack.prototype.has = stackHas;
|
50507 | Stack.prototype.set = stackSet;
|
50508 |
|
50509 | module.exports = Stack;
|
50510 |
|
50511 | },{"./_ListCache":379,"./_stackClear":479,"./_stackDelete":480,"./_stackGet":481,"./_stackHas":482,"./_stackSet":483}],386:[function(require,module,exports){
|
50512 | var root = require('./_root');
|
50513 |
|
50514 | /** Built-in value references. */
|
50515 | var Symbol = root.Symbol;
|
50516 |
|
50517 | module.exports = Symbol;
|
50518 |
|
50519 | },{"./_root":473}],387:[function(require,module,exports){
|
50520 | var root = require('./_root');
|
50521 |
|
50522 | /** Built-in value references. */
|
50523 | var Uint8Array = root.Uint8Array;
|
50524 |
|
50525 | module.exports = Uint8Array;
|
50526 |
|
50527 | },{"./_root":473}],388:[function(require,module,exports){
|
50528 | var getNative = require('./_getNative'),
|
50529 | root = require('./_root');
|
50530 |
|
50531 | /* Built-in method references that are verified to be native. */
|
50532 | var WeakMap = getNative(root, 'WeakMap');
|
50533 |
|
50534 | module.exports = WeakMap;
|
50535 |
|
50536 | },{"./_getNative":436,"./_root":473}],389:[function(require,module,exports){
|
50537 | /**
|
50538 | * A faster alternative to `Function#apply`, this function invokes `func`
|
50539 | * with the `this` binding of `thisArg` and the arguments of `args`.
|
50540 | *
|
50541 | * @private
|
50542 | * @param {Function} func The function to invoke.
|
50543 | * @param {*} thisArg The `this` binding of `func`.
|
50544 | * @param {Array} args The arguments to invoke `func` with.
|
50545 | * @returns {*} Returns the result of `func`.
|
50546 | */
|
50547 | function apply(func, thisArg, args) {
|
50548 | switch (args.length) {
|
50549 | case 0: return func.call(thisArg);
|
50550 | case 1: return func.call(thisArg, args[0]);
|
50551 | case 2: return func.call(thisArg, args[0], args[1]);
|
50552 | case 3: return func.call(thisArg, args[0], args[1], args[2]);
|
50553 | }
|
50554 | return func.apply(thisArg, args);
|
50555 | }
|
50556 |
|
50557 | module.exports = apply;
|
50558 |
|
50559 | },{}],390:[function(require,module,exports){
|
50560 | /**
|
50561 | * A specialized version of `_.filter` for arrays without support for
|
50562 | * iteratee shorthands.
|
50563 | *
|
50564 | * @private
|
50565 | * @param {Array} [array] The array to iterate over.
|
50566 | * @param {Function} predicate The function invoked per iteration.
|
50567 | * @returns {Array} Returns the new filtered array.
|
50568 | */
|
50569 | function arrayFilter(array, predicate) {
|
50570 | var index = -1,
|
50571 | length = array == null ? 0 : array.length,
|
50572 | resIndex = 0,
|
50573 | result = [];
|
50574 |
|
50575 | while (++index < length) {
|
50576 | var value = array[index];
|
50577 | if (predicate(value, index, array)) {
|
50578 | result[resIndex++] = value;
|
50579 | }
|
50580 | }
|
50581 | return result;
|
50582 | }
|
50583 |
|
50584 | module.exports = arrayFilter;
|
50585 |
|
50586 | },{}],391:[function(require,module,exports){
|
50587 | var baseTimes = require('./_baseTimes'),
|
50588 | isArguments = require('./isArguments'),
|
50589 | isArray = require('./isArray'),
|
50590 | isBuffer = require('./isBuffer'),
|
50591 | isIndex = require('./_isIndex'),
|
50592 | isTypedArray = require('./isTypedArray');
|
50593 |
|
50594 | /** Used for built-in method references. */
|
50595 | var objectProto = Object.prototype;
|
50596 |
|
50597 | /** Used to check objects for own properties. */
|
50598 | var hasOwnProperty = objectProto.hasOwnProperty;
|
50599 |
|
50600 | /**
|
50601 | * Creates an array of the enumerable property names of the array-like `value`.
|
50602 | *
|
50603 | * @private
|
50604 | * @param {*} value The value to query.
|
50605 | * @param {boolean} inherited Specify returning inherited property names.
|
50606 | * @returns {Array} Returns the array of property names.
|
50607 | */
|
50608 | function arrayLikeKeys(value, inherited) {
|
50609 | var isArr = isArray(value),
|
50610 | isArg = !isArr && isArguments(value),
|
50611 | isBuff = !isArr && !isArg && isBuffer(value),
|
50612 | isType = !isArr && !isArg && !isBuff && isTypedArray(value),
|
50613 | skipIndexes = isArr || isArg || isBuff || isType,
|
50614 | result = skipIndexes ? baseTimes(value.length, String) : [],
|
50615 | length = result.length;
|
50616 |
|
50617 | for (var key in value) {
|
50618 | if ((inherited || hasOwnProperty.call(value, key)) &&
|
50619 | !(skipIndexes && (
|
50620 | // Safari 9 has enumerable `arguments.length` in strict mode.
|
50621 | key == 'length' ||
|
50622 | // Node.js 0.10 has enumerable non-index properties on buffers.
|
50623 | (isBuff && (key == 'offset' || key == 'parent')) ||
|
50624 | // PhantomJS 2 has enumerable non-index properties on typed arrays.
|
50625 | (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
|
50626 | // Skip index properties.
|
50627 | isIndex(key, length)
|
50628 | ))) {
|
50629 | result.push(key);
|
50630 | }
|
50631 | }
|
50632 | return result;
|
50633 | }
|
50634 |
|
50635 | module.exports = arrayLikeKeys;
|
50636 |
|
50637 | },{"./_baseTimes":420,"./_isIndex":448,"./isArguments":495,"./isArray":496,"./isBuffer":498,"./isTypedArray":505}],392:[function(require,module,exports){
|
50638 | /**
|
50639 | * A specialized version of `_.map` for arrays without support for iteratee
|
50640 | * shorthands.
|
50641 | *
|
50642 | * @private
|
50643 | * @param {Array} [array] The array to iterate over.
|
50644 | * @param {Function} iteratee The function invoked per iteration.
|
50645 | * @returns {Array} Returns the new mapped array.
|
50646 | */
|
50647 | function arrayMap(array, iteratee) {
|
50648 | var index = -1,
|
50649 | length = array == null ? 0 : array.length,
|
50650 | result = Array(length);
|
50651 |
|
50652 | while (++index < length) {
|
50653 | result[index] = iteratee(array[index], index, array);
|
50654 | }
|
50655 | return result;
|
50656 | }
|
50657 |
|
50658 | module.exports = arrayMap;
|
50659 |
|
50660 | },{}],393:[function(require,module,exports){
|
50661 | /**
|
50662 | * Appends the elements of `values` to `array`.
|
50663 | *
|
50664 | * @private
|
50665 | * @param {Array} array The array to modify.
|
50666 | * @param {Array} values The values to append.
|
50667 | * @returns {Array} Returns `array`.
|
50668 | */
|
50669 | function arrayPush(array, values) {
|
50670 | var index = -1,
|
50671 | length = values.length,
|
50672 | offset = array.length;
|
50673 |
|
50674 | while (++index < length) {
|
50675 | array[offset + index] = values[index];
|
50676 | }
|
50677 | return array;
|
50678 | }
|
50679 |
|
50680 | module.exports = arrayPush;
|
50681 |
|
50682 | },{}],394:[function(require,module,exports){
|
50683 | /**
|
50684 | * A specialized version of `_.some` for arrays without support for iteratee
|
50685 | * shorthands.
|
50686 | *
|
50687 | * @private
|
50688 | * @param {Array} [array] The array to iterate over.
|
50689 | * @param {Function} predicate The function invoked per iteration.
|
50690 | * @returns {boolean} Returns `true` if any element passes the predicate check,
|
50691 | * else `false`.
|
50692 | */
|
50693 | function arraySome(array, predicate) {
|
50694 | var index = -1,
|
50695 | length = array == null ? 0 : array.length;
|
50696 |
|
50697 | while (++index < length) {
|
50698 | if (predicate(array[index], index, array)) {
|
50699 | return true;
|
50700 | }
|
50701 | }
|
50702 | return false;
|
50703 | }
|
50704 |
|
50705 | module.exports = arraySome;
|
50706 |
|
50707 | },{}],395:[function(require,module,exports){
|
50708 | var baseAssignValue = require('./_baseAssignValue'),
|
50709 | eq = require('./eq');
|
50710 |
|
50711 | /** Used for built-in method references. */
|
50712 | var objectProto = Object.prototype;
|
50713 |
|
50714 | /** Used to check objects for own properties. */
|
50715 | var hasOwnProperty = objectProto.hasOwnProperty;
|
50716 |
|
50717 | /**
|
50718 | * Assigns `value` to `key` of `object` if the existing value is not equivalent
|
50719 | * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
50720 | * for equality comparisons.
|
50721 | *
|
50722 | * @private
|
50723 | * @param {Object} object The object to modify.
|
50724 | * @param {string} key The key of the property to assign.
|
50725 | * @param {*} value The value to assign.
|
50726 | */
|
50727 | function assignValue(object, key, value) {
|
50728 | var objValue = object[key];
|
50729 | if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
|
50730 | (value === undefined && !(key in object))) {
|
50731 | baseAssignValue(object, key, value);
|
50732 | }
|
50733 | }
|
50734 |
|
50735 | module.exports = assignValue;
|
50736 |
|
50737 | },{"./_baseAssignValue":397,"./eq":488}],396:[function(require,module,exports){
|
50738 | var eq = require('./eq');
|
50739 |
|
50740 | /**
|
50741 | * Gets the index at which the `key` is found in `array` of key-value pairs.
|
50742 | *
|
50743 | * @private
|
50744 | * @param {Array} array The array to inspect.
|
50745 | * @param {*} key The key to search for.
|
50746 | * @returns {number} Returns the index of the matched value, else `-1`.
|
50747 | */
|
50748 | function assocIndexOf(array, key) {
|
50749 | var length = array.length;
|
50750 | while (length--) {
|
50751 | if (eq(array[length][0], key)) {
|
50752 | return length;
|
50753 | }
|
50754 | }
|
50755 | return -1;
|
50756 | }
|
50757 |
|
50758 | module.exports = assocIndexOf;
|
50759 |
|
50760 | },{"./eq":488}],397:[function(require,module,exports){
|
50761 | var defineProperty = require('./_defineProperty');
|
50762 |
|
50763 | /**
|
50764 | * The base implementation of `assignValue` and `assignMergeValue` without
|
50765 | * value checks.
|
50766 | *
|
50767 | * @private
|
50768 | * @param {Object} object The object to modify.
|
50769 | * @param {string} key The key of the property to assign.
|
50770 | * @param {*} value The value to assign.
|
50771 | */
|
50772 | function baseAssignValue(object, key, value) {
|
50773 | if (key == '__proto__' && defineProperty) {
|
50774 | defineProperty(object, key, {
|
50775 | 'configurable': true,
|
50776 | 'enumerable': true,
|
50777 | 'value': value,
|
50778 | 'writable': true
|
50779 | });
|
50780 | } else {
|
50781 | object[key] = value;
|
50782 | }
|
50783 | }
|
50784 |
|
50785 | module.exports = baseAssignValue;
|
50786 |
|
50787 | },{"./_defineProperty":427}],398:[function(require,module,exports){
|
50788 | /**
|
50789 | * The base implementation of `_.findIndex` and `_.findLastIndex` without
|
50790 | * support for iteratee shorthands.
|
50791 | *
|
50792 | * @private
|
50793 | * @param {Array} array The array to inspect.
|
50794 | * @param {Function} predicate The function invoked per iteration.
|
50795 | * @param {number} fromIndex The index to search from.
|
50796 | * @param {boolean} [fromRight] Specify iterating from right to left.
|
50797 | * @returns {number} Returns the index of the matched value, else `-1`.
|
50798 | */
|
50799 | function baseFindIndex(array, predicate, fromIndex, fromRight) {
|
50800 | var length = array.length,
|
50801 | index = fromIndex + (fromRight ? 1 : -1);
|
50802 |
|
50803 | while ((fromRight ? index-- : ++index < length)) {
|
50804 | if (predicate(array[index], index, array)) {
|
50805 | return index;
|
50806 | }
|
50807 | }
|
50808 | return -1;
|
50809 | }
|
50810 |
|
50811 | module.exports = baseFindIndex;
|
50812 |
|
50813 | },{}],399:[function(require,module,exports){
|
50814 | var arrayPush = require('./_arrayPush'),
|
50815 | isFlattenable = require('./_isFlattenable');
|
50816 |
|
50817 | /**
|
50818 | * The base implementation of `_.flatten` with support for restricting flattening.
|
50819 | *
|
50820 | * @private
|
50821 | * @param {Array} array The array to flatten.
|
50822 | * @param {number} depth The maximum recursion depth.
|
50823 | * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
|
50824 | * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
|
50825 | * @param {Array} [result=[]] The initial result value.
|
50826 | * @returns {Array} Returns the new flattened array.
|
50827 | */
|
50828 | function baseFlatten(array, depth, predicate, isStrict, result) {
|
50829 | var index = -1,
|
50830 | length = array.length;
|
50831 |
|
50832 | predicate || (predicate = isFlattenable);
|
50833 | result || (result = []);
|
50834 |
|
50835 | while (++index < length) {
|
50836 | var value = array[index];
|
50837 | if (depth > 0 && predicate(value)) {
|
50838 | if (depth > 1) {
|
50839 | // Recursively flatten arrays (susceptible to call stack limits).
|
50840 | baseFlatten(value, depth - 1, predicate, isStrict, result);
|
50841 | } else {
|
50842 | arrayPush(result, value);
|
50843 | }
|
50844 | } else if (!isStrict) {
|
50845 | result[result.length] = value;
|
50846 | }
|
50847 | }
|
50848 | return result;
|
50849 | }
|
50850 |
|
50851 | module.exports = baseFlatten;
|
50852 |
|
50853 | },{"./_arrayPush":393,"./_isFlattenable":447}],400:[function(require,module,exports){
|
50854 | var castPath = require('./_castPath'),
|
50855 | toKey = require('./_toKey');
|
50856 |
|
50857 | /**
|
50858 | * The base implementation of `_.get` without support for default values.
|
50859 | *
|
50860 | * @private
|
50861 | * @param {Object} object The object to query.
|
50862 | * @param {Array|string} path The path of the property to get.
|
50863 | * @returns {*} Returns the resolved value.
|
50864 | */
|
50865 | function baseGet(object, path) {
|
50866 | path = castPath(path, object);
|
50867 |
|
50868 | var index = 0,
|
50869 | length = path.length;
|
50870 |
|
50871 | while (object != null && index < length) {
|
50872 | object = object[toKey(path[index++])];
|
50873 | }
|
50874 | return (index && index == length) ? object : undefined;
|
50875 | }
|
50876 |
|
50877 | module.exports = baseGet;
|
50878 |
|
50879 | },{"./_castPath":424,"./_toKey":485}],401:[function(require,module,exports){
|
50880 | var arrayPush = require('./_arrayPush'),
|
50881 | isArray = require('./isArray');
|
50882 |
|
50883 | /**
|
50884 | * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
|
50885 | * `keysFunc` and `symbolsFunc` to get the enumerable property names and
|
50886 | * symbols of `object`.
|
50887 | *
|
50888 | * @private
|
50889 | * @param {Object} object The object to query.
|
50890 | * @param {Function} keysFunc The function to get the keys of `object`.
|
50891 | * @param {Function} symbolsFunc The function to get the symbols of `object`.
|
50892 | * @returns {Array} Returns the array of property names and symbols.
|
50893 | */
|
50894 | function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
50895 | var result = keysFunc(object);
|
50896 | return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
|
50897 | }
|
50898 |
|
50899 | module.exports = baseGetAllKeys;
|
50900 |
|
50901 | },{"./_arrayPush":393,"./isArray":496}],402:[function(require,module,exports){
|
50902 | var Symbol = require('./_Symbol'),
|
50903 | getRawTag = require('./_getRawTag'),
|
50904 | objectToString = require('./_objectToString');
|
50905 |
|
50906 | /** `Object#toString` result references. */
|
50907 | var nullTag = '[object Null]',
|
50908 | undefinedTag = '[object Undefined]';
|
50909 |
|
50910 | /** Built-in value references. */
|
50911 | var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
|
50912 |
|
50913 | /**
|
50914 | * The base implementation of `getTag` without fallbacks for buggy environments.
|
50915 | *
|
50916 | * @private
|
50917 | * @param {*} value The value to query.
|
50918 | * @returns {string} Returns the `toStringTag`.
|
50919 | */
|
50920 | function baseGetTag(value) {
|
50921 | if (value == null) {
|
50922 | return value === undefined ? undefinedTag : nullTag;
|
50923 | }
|
50924 | return (symToStringTag && symToStringTag in Object(value))
|
50925 | ? getRawTag(value)
|
50926 | : objectToString(value);
|
50927 | }
|
50928 |
|
50929 | module.exports = baseGetTag;
|
50930 |
|
50931 | },{"./_Symbol":386,"./_getRawTag":437,"./_objectToString":470}],403:[function(require,module,exports){
|
50932 | /**
|
50933 | * The base implementation of `_.hasIn` without support for deep paths.
|
50934 | *
|
50935 | * @private
|
50936 | * @param {Object} [object] The object to query.
|
50937 | * @param {Array|string} key The key to check.
|
50938 | * @returns {boolean} Returns `true` if `key` exists, else `false`.
|
50939 | */
|
50940 | function baseHasIn(object, key) {
|
50941 | return object != null && key in Object(object);
|
50942 | }
|
50943 |
|
50944 | module.exports = baseHasIn;
|
50945 |
|
50946 | },{}],404:[function(require,module,exports){
|
50947 | var baseGetTag = require('./_baseGetTag'),
|
50948 | isObjectLike = require('./isObjectLike');
|
50949 |
|
50950 | /** `Object#toString` result references. */
|
50951 | var argsTag = '[object Arguments]';
|
50952 |
|
50953 | /**
|
50954 | * The base implementation of `_.isArguments`.
|
50955 | *
|
50956 | * @private
|
50957 | * @param {*} value The value to check.
|
50958 | * @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
50959 | */
|
50960 | function baseIsArguments(value) {
|
50961 | return isObjectLike(value) && baseGetTag(value) == argsTag;
|
50962 | }
|
50963 |
|
50964 | module.exports = baseIsArguments;
|
50965 |
|
50966 | },{"./_baseGetTag":402,"./isObjectLike":503}],405:[function(require,module,exports){
|
50967 | var baseIsEqualDeep = require('./_baseIsEqualDeep'),
|
50968 | isObjectLike = require('./isObjectLike');
|
50969 |
|
50970 | /**
|
50971 | * The base implementation of `_.isEqual` which supports partial comparisons
|
50972 | * and tracks traversed objects.
|
50973 | *
|
50974 | * @private
|
50975 | * @param {*} value The value to compare.
|
50976 | * @param {*} other The other value to compare.
|
50977 | * @param {boolean} bitmask The bitmask flags.
|
50978 | * 1 - Unordered comparison
|
50979 | * 2 - Partial comparison
|
50980 | * @param {Function} [customizer] The function to customize comparisons.
|
50981 | * @param {Object} [stack] Tracks traversed `value` and `other` objects.
|
50982 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
50983 | */
|
50984 | function baseIsEqual(value, other, bitmask, customizer, stack) {
|
50985 | if (value === other) {
|
50986 | return true;
|
50987 | }
|
50988 | if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
|
50989 | return value !== value && other !== other;
|
50990 | }
|
50991 | return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
|
50992 | }
|
50993 |
|
50994 | module.exports = baseIsEqual;
|
50995 |
|
50996 | },{"./_baseIsEqualDeep":406,"./isObjectLike":503}],406:[function(require,module,exports){
|
50997 | var Stack = require('./_Stack'),
|
50998 | equalArrays = require('./_equalArrays'),
|
50999 | equalByTag = require('./_equalByTag'),
|
51000 | equalObjects = require('./_equalObjects'),
|
51001 | getTag = require('./_getTag'),
|
51002 | isArray = require('./isArray'),
|
51003 | isBuffer = require('./isBuffer'),
|
51004 | isTypedArray = require('./isTypedArray');
|
51005 |
|
51006 | /** Used to compose bitmasks for value comparisons. */
|
51007 | var COMPARE_PARTIAL_FLAG = 1;
|
51008 |
|
51009 | /** `Object#toString` result references. */
|
51010 | var argsTag = '[object Arguments]',
|
51011 | arrayTag = '[object Array]',
|
51012 | objectTag = '[object Object]';
|
51013 |
|
51014 | /** Used for built-in method references. */
|
51015 | var objectProto = Object.prototype;
|
51016 |
|
51017 | /** Used to check objects for own properties. */
|
51018 | var hasOwnProperty = objectProto.hasOwnProperty;
|
51019 |
|
51020 | /**
|
51021 | * A specialized version of `baseIsEqual` for arrays and objects which performs
|
51022 | * deep comparisons and tracks traversed objects enabling objects with circular
|
51023 | * references to be compared.
|
51024 | *
|
51025 | * @private
|
51026 | * @param {Object} object The object to compare.
|
51027 | * @param {Object} other The other object to compare.
|
51028 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
51029 | * @param {Function} customizer The function to customize comparisons.
|
51030 | * @param {Function} equalFunc The function to determine equivalents of values.
|
51031 | * @param {Object} [stack] Tracks traversed `object` and `other` objects.
|
51032 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
51033 | */
|
51034 | function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
|
51035 | var objIsArr = isArray(object),
|
51036 | othIsArr = isArray(other),
|
51037 | objTag = objIsArr ? arrayTag : getTag(object),
|
51038 | othTag = othIsArr ? arrayTag : getTag(other);
|
51039 |
|
51040 | objTag = objTag == argsTag ? objectTag : objTag;
|
51041 | othTag = othTag == argsTag ? objectTag : othTag;
|
51042 |
|
51043 | var objIsObj = objTag == objectTag,
|
51044 | othIsObj = othTag == objectTag,
|
51045 | isSameTag = objTag == othTag;
|
51046 |
|
51047 | if (isSameTag && isBuffer(object)) {
|
51048 | if (!isBuffer(other)) {
|
51049 | return false;
|
51050 | }
|
51051 | objIsArr = true;
|
51052 | objIsObj = false;
|
51053 | }
|
51054 | if (isSameTag && !objIsObj) {
|
51055 | stack || (stack = new Stack);
|
51056 | return (objIsArr || isTypedArray(object))
|
51057 | ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
|
51058 | : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
|
51059 | }
|
51060 | if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
|
51061 | var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
51062 | othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
51063 |
|
51064 | if (objIsWrapped || othIsWrapped) {
|
51065 | var objUnwrapped = objIsWrapped ? object.value() : object,
|
51066 | othUnwrapped = othIsWrapped ? other.value() : other;
|
51067 |
|
51068 | stack || (stack = new Stack);
|
51069 | return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
|
51070 | }
|
51071 | }
|
51072 | if (!isSameTag) {
|
51073 | return false;
|
51074 | }
|
51075 | stack || (stack = new Stack);
|
51076 | return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
|
51077 | }
|
51078 |
|
51079 | module.exports = baseIsEqualDeep;
|
51080 |
|
51081 | },{"./_Stack":385,"./_equalArrays":428,"./_equalByTag":429,"./_equalObjects":430,"./_getTag":439,"./isArray":496,"./isBuffer":498,"./isTypedArray":505}],407:[function(require,module,exports){
|
51082 | var Stack = require('./_Stack'),
|
51083 | baseIsEqual = require('./_baseIsEqual');
|
51084 |
|
51085 | /** Used to compose bitmasks for value comparisons. */
|
51086 | var COMPARE_PARTIAL_FLAG = 1,
|
51087 | COMPARE_UNORDERED_FLAG = 2;
|
51088 |
|
51089 | /**
|
51090 | * The base implementation of `_.isMatch` without support for iteratee shorthands.
|
51091 | *
|
51092 | * @private
|
51093 | * @param {Object} object The object to inspect.
|
51094 | * @param {Object} source The object of property values to match.
|
51095 | * @param {Array} matchData The property names, values, and compare flags to match.
|
51096 | * @param {Function} [customizer] The function to customize comparisons.
|
51097 | * @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
51098 | */
|
51099 | function baseIsMatch(object, source, matchData, customizer) {
|
51100 | var index = matchData.length,
|
51101 | length = index,
|
51102 | noCustomizer = !customizer;
|
51103 |
|
51104 | if (object == null) {
|
51105 | return !length;
|
51106 | }
|
51107 | object = Object(object);
|
51108 | while (index--) {
|
51109 | var data = matchData[index];
|
51110 | if ((noCustomizer && data[2])
|
51111 | ? data[1] !== object[data[0]]
|
51112 | : !(data[0] in object)
|
51113 | ) {
|
51114 | return false;
|
51115 | }
|
51116 | }
|
51117 | while (++index < length) {
|
51118 | data = matchData[index];
|
51119 | var key = data[0],
|
51120 | objValue = object[key],
|
51121 | srcValue = data[1];
|
51122 |
|
51123 | if (noCustomizer && data[2]) {
|
51124 | if (objValue === undefined && !(key in object)) {
|
51125 | return false;
|
51126 | }
|
51127 | } else {
|
51128 | var stack = new Stack;
|
51129 | if (customizer) {
|
51130 | var result = customizer(objValue, srcValue, key, object, source, stack);
|
51131 | }
|
51132 | if (!(result === undefined
|
51133 | ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
|
51134 | : result
|
51135 | )) {
|
51136 | return false;
|
51137 | }
|
51138 | }
|
51139 | }
|
51140 | return true;
|
51141 | }
|
51142 |
|
51143 | module.exports = baseIsMatch;
|
51144 |
|
51145 | },{"./_Stack":385,"./_baseIsEqual":405}],408:[function(require,module,exports){
|
51146 | var isFunction = require('./isFunction'),
|
51147 | isMasked = require('./_isMasked'),
|
51148 | isObject = require('./isObject'),
|
51149 | toSource = require('./_toSource');
|
51150 |
|
51151 | /**
|
51152 | * Used to match `RegExp`
|
51153 | * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
51154 | */
|
51155 | var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
51156 |
|
51157 | /** Used to detect host constructors (Safari). */
|
51158 | var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
51159 |
|
51160 | /** Used for built-in method references. */
|
51161 | var funcProto = Function.prototype,
|
51162 | objectProto = Object.prototype;
|
51163 |
|
51164 | /** Used to resolve the decompiled source of functions. */
|
51165 | var funcToString = funcProto.toString;
|
51166 |
|
51167 | /** Used to check objects for own properties. */
|
51168 | var hasOwnProperty = objectProto.hasOwnProperty;
|
51169 |
|
51170 | /** Used to detect if a method is native. */
|
51171 | var reIsNative = RegExp('^' +
|
51172 | funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
51173 | .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
51174 | );
|
51175 |
|
51176 | /**
|
51177 | * The base implementation of `_.isNative` without bad shim checks.
|
51178 | *
|
51179 | * @private
|
51180 | * @param {*} value The value to check.
|
51181 | * @returns {boolean} Returns `true` if `value` is a native function,
|
51182 | * else `false`.
|
51183 | */
|
51184 | function baseIsNative(value) {
|
51185 | if (!isObject(value) || isMasked(value)) {
|
51186 | return false;
|
51187 | }
|
51188 | var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
51189 | return pattern.test(toSource(value));
|
51190 | }
|
51191 |
|
51192 | module.exports = baseIsNative;
|
51193 |
|
51194 | },{"./_isMasked":451,"./_toSource":486,"./isFunction":500,"./isObject":502}],409:[function(require,module,exports){
|
51195 | var baseGetTag = require('./_baseGetTag'),
|
51196 | isLength = require('./isLength'),
|
51197 | isObjectLike = require('./isObjectLike');
|
51198 |
|
51199 | /** `Object#toString` result references. */
|
51200 | var argsTag = '[object Arguments]',
|
51201 | arrayTag = '[object Array]',
|
51202 | boolTag = '[object Boolean]',
|
51203 | dateTag = '[object Date]',
|
51204 | errorTag = '[object Error]',
|
51205 | funcTag = '[object Function]',
|
51206 | mapTag = '[object Map]',
|
51207 | numberTag = '[object Number]',
|
51208 | objectTag = '[object Object]',
|
51209 | regexpTag = '[object RegExp]',
|
51210 | setTag = '[object Set]',
|
51211 | stringTag = '[object String]',
|
51212 | weakMapTag = '[object WeakMap]';
|
51213 |
|
51214 | var arrayBufferTag = '[object ArrayBuffer]',
|
51215 | dataViewTag = '[object DataView]',
|
51216 | float32Tag = '[object Float32Array]',
|
51217 | float64Tag = '[object Float64Array]',
|
51218 | int8Tag = '[object Int8Array]',
|
51219 | int16Tag = '[object Int16Array]',
|
51220 | int32Tag = '[object Int32Array]',
|
51221 | uint8Tag = '[object Uint8Array]',
|
51222 | uint8ClampedTag = '[object Uint8ClampedArray]',
|
51223 | uint16Tag = '[object Uint16Array]',
|
51224 | uint32Tag = '[object Uint32Array]';
|
51225 |
|
51226 | /** Used to identify `toStringTag` values of typed arrays. */
|
51227 | var typedArrayTags = {};
|
51228 | typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
51229 | typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
51230 | typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
51231 | typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
51232 | typedArrayTags[uint32Tag] = true;
|
51233 | typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
|
51234 | typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
51235 | typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
|
51236 | typedArrayTags[errorTag] = typedArrayTags[funcTag] =
|
51237 | typedArrayTags[mapTag] = typedArrayTags[numberTag] =
|
51238 | typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
|
51239 | typedArrayTags[setTag] = typedArrayTags[stringTag] =
|
51240 | typedArrayTags[weakMapTag] = false;
|
51241 |
|
51242 | /**
|
51243 | * The base implementation of `_.isTypedArray` without Node.js optimizations.
|
51244 | *
|
51245 | * @private
|
51246 | * @param {*} value The value to check.
|
51247 | * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
|
51248 | */
|
51249 | function baseIsTypedArray(value) {
|
51250 | return isObjectLike(value) &&
|
51251 | isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
|
51252 | }
|
51253 |
|
51254 | module.exports = baseIsTypedArray;
|
51255 |
|
51256 | },{"./_baseGetTag":402,"./isLength":501,"./isObjectLike":503}],410:[function(require,module,exports){
|
51257 | var baseMatches = require('./_baseMatches'),
|
51258 | baseMatchesProperty = require('./_baseMatchesProperty'),
|
51259 | identity = require('./identity'),
|
51260 | isArray = require('./isArray'),
|
51261 | property = require('./property');
|
51262 |
|
51263 | /**
|
51264 | * The base implementation of `_.iteratee`.
|
51265 | *
|
51266 | * @private
|
51267 | * @param {*} [value=_.identity] The value to convert to an iteratee.
|
51268 | * @returns {Function} Returns the iteratee.
|
51269 | */
|
51270 | function baseIteratee(value) {
|
51271 | // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
|
51272 | // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
|
51273 | if (typeof value == 'function') {
|
51274 | return value;
|
51275 | }
|
51276 | if (value == null) {
|
51277 | return identity;
|
51278 | }
|
51279 | if (typeof value == 'object') {
|
51280 | return isArray(value)
|
51281 | ? baseMatchesProperty(value[0], value[1])
|
51282 | : baseMatches(value);
|
51283 | }
|
51284 | return property(value);
|
51285 | }
|
51286 |
|
51287 | module.exports = baseIteratee;
|
51288 |
|
51289 | },{"./_baseMatches":412,"./_baseMatchesProperty":413,"./identity":494,"./isArray":496,"./property":509}],411:[function(require,module,exports){
|
51290 | var isPrototype = require('./_isPrototype'),
|
51291 | nativeKeys = require('./_nativeKeys');
|
51292 |
|
51293 | /** Used for built-in method references. */
|
51294 | var objectProto = Object.prototype;
|
51295 |
|
51296 | /** Used to check objects for own properties. */
|
51297 | var hasOwnProperty = objectProto.hasOwnProperty;
|
51298 |
|
51299 | /**
|
51300 | * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
|
51301 | *
|
51302 | * @private
|
51303 | * @param {Object} object The object to query.
|
51304 | * @returns {Array} Returns the array of property names.
|
51305 | */
|
51306 | function baseKeys(object) {
|
51307 | if (!isPrototype(object)) {
|
51308 | return nativeKeys(object);
|
51309 | }
|
51310 | var result = [];
|
51311 | for (var key in Object(object)) {
|
51312 | if (hasOwnProperty.call(object, key) && key != 'constructor') {
|
51313 | result.push(key);
|
51314 | }
|
51315 | }
|
51316 | return result;
|
51317 | }
|
51318 |
|
51319 | module.exports = baseKeys;
|
51320 |
|
51321 | },{"./_isPrototype":452,"./_nativeKeys":468}],412:[function(require,module,exports){
|
51322 | var baseIsMatch = require('./_baseIsMatch'),
|
51323 | getMatchData = require('./_getMatchData'),
|
51324 | matchesStrictComparable = require('./_matchesStrictComparable');
|
51325 |
|
51326 | /**
|
51327 | * The base implementation of `_.matches` which doesn't clone `source`.
|
51328 | *
|
51329 | * @private
|
51330 | * @param {Object} source The object of property values to match.
|
51331 | * @returns {Function} Returns the new spec function.
|
51332 | */
|
51333 | function baseMatches(source) {
|
51334 | var matchData = getMatchData(source);
|
51335 | if (matchData.length == 1 && matchData[0][2]) {
|
51336 | return matchesStrictComparable(matchData[0][0], matchData[0][1]);
|
51337 | }
|
51338 | return function(object) {
|
51339 | return object === source || baseIsMatch(object, source, matchData);
|
51340 | };
|
51341 | }
|
51342 |
|
51343 | module.exports = baseMatches;
|
51344 |
|
51345 | },{"./_baseIsMatch":407,"./_getMatchData":435,"./_matchesStrictComparable":465}],413:[function(require,module,exports){
|
51346 | var baseIsEqual = require('./_baseIsEqual'),
|
51347 | get = require('./get'),
|
51348 | hasIn = require('./hasIn'),
|
51349 | isKey = require('./_isKey'),
|
51350 | isStrictComparable = require('./_isStrictComparable'),
|
51351 | matchesStrictComparable = require('./_matchesStrictComparable'),
|
51352 | toKey = require('./_toKey');
|
51353 |
|
51354 | /** Used to compose bitmasks for value comparisons. */
|
51355 | var COMPARE_PARTIAL_FLAG = 1,
|
51356 | COMPARE_UNORDERED_FLAG = 2;
|
51357 |
|
51358 | /**
|
51359 | * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
|
51360 | *
|
51361 | * @private
|
51362 | * @param {string} path The path of the property to get.
|
51363 | * @param {*} srcValue The value to match.
|
51364 | * @returns {Function} Returns the new spec function.
|
51365 | */
|
51366 | function baseMatchesProperty(path, srcValue) {
|
51367 | if (isKey(path) && isStrictComparable(srcValue)) {
|
51368 | return matchesStrictComparable(toKey(path), srcValue);
|
51369 | }
|
51370 | return function(object) {
|
51371 | var objValue = get(object, path);
|
51372 | return (objValue === undefined && objValue === srcValue)
|
51373 | ? hasIn(object, path)
|
51374 | : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
|
51375 | };
|
51376 | }
|
51377 |
|
51378 | module.exports = baseMatchesProperty;
|
51379 |
|
51380 | },{"./_baseIsEqual":405,"./_isKey":449,"./_isStrictComparable":453,"./_matchesStrictComparable":465,"./_toKey":485,"./get":492,"./hasIn":493}],414:[function(require,module,exports){
|
51381 | var basePickBy = require('./_basePickBy'),
|
51382 | hasIn = require('./hasIn');
|
51383 |
|
51384 | /**
|
51385 | * The base implementation of `_.pick` without support for individual
|
51386 | * property identifiers.
|
51387 | *
|
51388 | * @private
|
51389 | * @param {Object} object The source object.
|
51390 | * @param {string[]} paths The property paths to pick.
|
51391 | * @returns {Object} Returns the new object.
|
51392 | */
|
51393 | function basePick(object, paths) {
|
51394 | return basePickBy(object, paths, function(value, path) {
|
51395 | return hasIn(object, path);
|
51396 | });
|
51397 | }
|
51398 |
|
51399 | module.exports = basePick;
|
51400 |
|
51401 | },{"./_basePickBy":415,"./hasIn":493}],415:[function(require,module,exports){
|
51402 | var baseGet = require('./_baseGet'),
|
51403 | baseSet = require('./_baseSet'),
|
51404 | castPath = require('./_castPath');
|
51405 |
|
51406 | /**
|
51407 | * The base implementation of `_.pickBy` without support for iteratee shorthands.
|
51408 | *
|
51409 | * @private
|
51410 | * @param {Object} object The source object.
|
51411 | * @param {string[]} paths The property paths to pick.
|
51412 | * @param {Function} predicate The function invoked per property.
|
51413 | * @returns {Object} Returns the new object.
|
51414 | */
|
51415 | function basePickBy(object, paths, predicate) {
|
51416 | var index = -1,
|
51417 | length = paths.length,
|
51418 | result = {};
|
51419 |
|
51420 | while (++index < length) {
|
51421 | var path = paths[index],
|
51422 | value = baseGet(object, path);
|
51423 |
|
51424 | if (predicate(value, path)) {
|
51425 | baseSet(result, castPath(path, object), value);
|
51426 | }
|
51427 | }
|
51428 | return result;
|
51429 | }
|
51430 |
|
51431 | module.exports = basePickBy;
|
51432 |
|
51433 | },{"./_baseGet":400,"./_baseSet":418,"./_castPath":424}],416:[function(require,module,exports){
|
51434 | /**
|
51435 | * The base implementation of `_.property` without support for deep paths.
|
51436 | *
|
51437 | * @private
|
51438 | * @param {string} key The key of the property to get.
|
51439 | * @returns {Function} Returns the new accessor function.
|
51440 | */
|
51441 | function baseProperty(key) {
|
51442 | return function(object) {
|
51443 | return object == null ? undefined : object[key];
|
51444 | };
|
51445 | }
|
51446 |
|
51447 | module.exports = baseProperty;
|
51448 |
|
51449 | },{}],417:[function(require,module,exports){
|
51450 | var baseGet = require('./_baseGet');
|
51451 |
|
51452 | /**
|
51453 | * A specialized version of `baseProperty` which supports deep paths.
|
51454 | *
|
51455 | * @private
|
51456 | * @param {Array|string} path The path of the property to get.
|
51457 | * @returns {Function} Returns the new accessor function.
|
51458 | */
|
51459 | function basePropertyDeep(path) {
|
51460 | return function(object) {
|
51461 | return baseGet(object, path);
|
51462 | };
|
51463 | }
|
51464 |
|
51465 | module.exports = basePropertyDeep;
|
51466 |
|
51467 | },{"./_baseGet":400}],418:[function(require,module,exports){
|
51468 | var assignValue = require('./_assignValue'),
|
51469 | castPath = require('./_castPath'),
|
51470 | isIndex = require('./_isIndex'),
|
51471 | isObject = require('./isObject'),
|
51472 | toKey = require('./_toKey');
|
51473 |
|
51474 | /**
|
51475 | * The base implementation of `_.set`.
|
51476 | *
|
51477 | * @private
|
51478 | * @param {Object} object The object to modify.
|
51479 | * @param {Array|string} path The path of the property to set.
|
51480 | * @param {*} value The value to set.
|
51481 | * @param {Function} [customizer] The function to customize path creation.
|
51482 | * @returns {Object} Returns `object`.
|
51483 | */
|
51484 | function baseSet(object, path, value, customizer) {
|
51485 | if (!isObject(object)) {
|
51486 | return object;
|
51487 | }
|
51488 | path = castPath(path, object);
|
51489 |
|
51490 | var index = -1,
|
51491 | length = path.length,
|
51492 | lastIndex = length - 1,
|
51493 | nested = object;
|
51494 |
|
51495 | while (nested != null && ++index < length) {
|
51496 | var key = toKey(path[index]),
|
51497 | newValue = value;
|
51498 |
|
51499 | if (index != lastIndex) {
|
51500 | var objValue = nested[key];
|
51501 | newValue = customizer ? customizer(objValue, key, nested) : undefined;
|
51502 | if (newValue === undefined) {
|
51503 | newValue = isObject(objValue)
|
51504 | ? objValue
|
51505 | : (isIndex(path[index + 1]) ? [] : {});
|
51506 | }
|
51507 | }
|
51508 | assignValue(nested, key, newValue);
|
51509 | nested = nested[key];
|
51510 | }
|
51511 | return object;
|
51512 | }
|
51513 |
|
51514 | module.exports = baseSet;
|
51515 |
|
51516 | },{"./_assignValue":395,"./_castPath":424,"./_isIndex":448,"./_toKey":485,"./isObject":502}],419:[function(require,module,exports){
|
51517 | var constant = require('./constant'),
|
51518 | defineProperty = require('./_defineProperty'),
|
51519 | identity = require('./identity');
|
51520 |
|
51521 | /**
|
51522 | * The base implementation of `setToString` without support for hot loop shorting.
|
51523 | *
|
51524 | * @private
|
51525 | * @param {Function} func The function to modify.
|
51526 | * @param {Function} string The `toString` result.
|
51527 | * @returns {Function} Returns `func`.
|
51528 | */
|
51529 | var baseSetToString = !defineProperty ? identity : function(func, string) {
|
51530 | return defineProperty(func, 'toString', {
|
51531 | 'configurable': true,
|
51532 | 'enumerable': false,
|
51533 | 'value': constant(string),
|
51534 | 'writable': true
|
51535 | });
|
51536 | };
|
51537 |
|
51538 | module.exports = baseSetToString;
|
51539 |
|
51540 | },{"./_defineProperty":427,"./constant":487,"./identity":494}],420:[function(require,module,exports){
|
51541 | /**
|
51542 | * The base implementation of `_.times` without support for iteratee shorthands
|
51543 | * or max array length checks.
|
51544 | *
|
51545 | * @private
|
51546 | * @param {number} n The number of times to invoke `iteratee`.
|
51547 | * @param {Function} iteratee The function invoked per iteration.
|
51548 | * @returns {Array} Returns the array of results.
|
51549 | */
|
51550 | function baseTimes(n, iteratee) {
|
51551 | var index = -1,
|
51552 | result = Array(n);
|
51553 |
|
51554 | while (++index < n) {
|
51555 | result[index] = iteratee(index);
|
51556 | }
|
51557 | return result;
|
51558 | }
|
51559 |
|
51560 | module.exports = baseTimes;
|
51561 |
|
51562 | },{}],421:[function(require,module,exports){
|
51563 | var Symbol = require('./_Symbol'),
|
51564 | arrayMap = require('./_arrayMap'),
|
51565 | isArray = require('./isArray'),
|
51566 | isSymbol = require('./isSymbol');
|
51567 |
|
51568 | /** Used as references for various `Number` constants. */
|
51569 | var INFINITY = 1 / 0;
|
51570 |
|
51571 | /** Used to convert symbols to primitives and strings. */
|
51572 | var symbolProto = Symbol ? Symbol.prototype : undefined,
|
51573 | symbolToString = symbolProto ? symbolProto.toString : undefined;
|
51574 |
|
51575 | /**
|
51576 | * The base implementation of `_.toString` which doesn't convert nullish
|
51577 | * values to empty strings.
|
51578 | *
|
51579 | * @private
|
51580 | * @param {*} value The value to process.
|
51581 | * @returns {string} Returns the string.
|
51582 | */
|
51583 | function baseToString(value) {
|
51584 | // Exit early for strings to avoid a performance hit in some environments.
|
51585 | if (typeof value == 'string') {
|
51586 | return value;
|
51587 | }
|
51588 | if (isArray(value)) {
|
51589 | // Recursively convert values (susceptible to call stack limits).
|
51590 | return arrayMap(value, baseToString) + '';
|
51591 | }
|
51592 | if (isSymbol(value)) {
|
51593 | return symbolToString ? symbolToString.call(value) : '';
|
51594 | }
|
51595 | var result = (value + '');
|
51596 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
51597 | }
|
51598 |
|
51599 | module.exports = baseToString;
|
51600 |
|
51601 | },{"./_Symbol":386,"./_arrayMap":392,"./isArray":496,"./isSymbol":504}],422:[function(require,module,exports){
|
51602 | /**
|
51603 | * The base implementation of `_.unary` without support for storing metadata.
|
51604 | *
|
51605 | * @private
|
51606 | * @param {Function} func The function to cap arguments for.
|
51607 | * @returns {Function} Returns the new capped function.
|
51608 | */
|
51609 | function baseUnary(func) {
|
51610 | return function(value) {
|
51611 | return func(value);
|
51612 | };
|
51613 | }
|
51614 |
|
51615 | module.exports = baseUnary;
|
51616 |
|
51617 | },{}],423:[function(require,module,exports){
|
51618 | /**
|
51619 | * Checks if a `cache` value for `key` exists.
|
51620 | *
|
51621 | * @private
|
51622 | * @param {Object} cache The cache to query.
|
51623 | * @param {string} key The key of the entry to check.
|
51624 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
51625 | */
|
51626 | function cacheHas(cache, key) {
|
51627 | return cache.has(key);
|
51628 | }
|
51629 |
|
51630 | module.exports = cacheHas;
|
51631 |
|
51632 | },{}],424:[function(require,module,exports){
|
51633 | var isArray = require('./isArray'),
|
51634 | isKey = require('./_isKey'),
|
51635 | stringToPath = require('./_stringToPath'),
|
51636 | toString = require('./toString');
|
51637 |
|
51638 | /**
|
51639 | * Casts `value` to a path array if it's not one.
|
51640 | *
|
51641 | * @private
|
51642 | * @param {*} value The value to inspect.
|
51643 | * @param {Object} [object] The object to query keys on.
|
51644 | * @returns {Array} Returns the cast property path array.
|
51645 | */
|
51646 | function castPath(value, object) {
|
51647 | if (isArray(value)) {
|
51648 | return value;
|
51649 | }
|
51650 | return isKey(value, object) ? [value] : stringToPath(toString(value));
|
51651 | }
|
51652 |
|
51653 | module.exports = castPath;
|
51654 |
|
51655 | },{"./_isKey":449,"./_stringToPath":484,"./isArray":496,"./toString":515}],425:[function(require,module,exports){
|
51656 | var root = require('./_root');
|
51657 |
|
51658 | /** Used to detect overreaching core-js shims. */
|
51659 | var coreJsData = root['__core-js_shared__'];
|
51660 |
|
51661 | module.exports = coreJsData;
|
51662 |
|
51663 | },{"./_root":473}],426:[function(require,module,exports){
|
51664 | var baseIteratee = require('./_baseIteratee'),
|
51665 | isArrayLike = require('./isArrayLike'),
|
51666 | keys = require('./keys');
|
51667 |
|
51668 | /**
|
51669 | * Creates a `_.find` or `_.findLast` function.
|
51670 | *
|
51671 | * @private
|
51672 | * @param {Function} findIndexFunc The function to find the collection index.
|
51673 | * @returns {Function} Returns the new find function.
|
51674 | */
|
51675 | function createFind(findIndexFunc) {
|
51676 | return function(collection, predicate, fromIndex) {
|
51677 | var iterable = Object(collection);
|
51678 | if (!isArrayLike(collection)) {
|
51679 | var iteratee = baseIteratee(predicate, 3);
|
51680 | collection = keys(collection);
|
51681 | predicate = function(key) { return iteratee(iterable[key], key, iterable); };
|
51682 | }
|
51683 | var index = findIndexFunc(collection, predicate, fromIndex);
|
51684 | return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
|
51685 | };
|
51686 | }
|
51687 |
|
51688 | module.exports = createFind;
|
51689 |
|
51690 | },{"./_baseIteratee":410,"./isArrayLike":497,"./keys":506}],427:[function(require,module,exports){
|
51691 | var getNative = require('./_getNative');
|
51692 |
|
51693 | var defineProperty = (function() {
|
51694 | try {
|
51695 | var func = getNative(Object, 'defineProperty');
|
51696 | func({}, '', {});
|
51697 | return func;
|
51698 | } catch (e) {}
|
51699 | }());
|
51700 |
|
51701 | module.exports = defineProperty;
|
51702 |
|
51703 | },{"./_getNative":436}],428:[function(require,module,exports){
|
51704 | var SetCache = require('./_SetCache'),
|
51705 | arraySome = require('./_arraySome'),
|
51706 | cacheHas = require('./_cacheHas');
|
51707 |
|
51708 | /** Used to compose bitmasks for value comparisons. */
|
51709 | var COMPARE_PARTIAL_FLAG = 1,
|
51710 | COMPARE_UNORDERED_FLAG = 2;
|
51711 |
|
51712 | /**
|
51713 | * A specialized version of `baseIsEqualDeep` for arrays with support for
|
51714 | * partial deep comparisons.
|
51715 | *
|
51716 | * @private
|
51717 | * @param {Array} array The array to compare.
|
51718 | * @param {Array} other The other array to compare.
|
51719 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
51720 | * @param {Function} customizer The function to customize comparisons.
|
51721 | * @param {Function} equalFunc The function to determine equivalents of values.
|
51722 | * @param {Object} stack Tracks traversed `array` and `other` objects.
|
51723 | * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
|
51724 | */
|
51725 | function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
|
51726 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
51727 | arrLength = array.length,
|
51728 | othLength = other.length;
|
51729 |
|
51730 | if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
51731 | return false;
|
51732 | }
|
51733 | // Assume cyclic values are equal.
|
51734 | var stacked = stack.get(array);
|
51735 | if (stacked && stack.get(other)) {
|
51736 | return stacked == other;
|
51737 | }
|
51738 | var index = -1,
|
51739 | result = true,
|
51740 | seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
|
51741 |
|
51742 | stack.set(array, other);
|
51743 | stack.set(other, array);
|
51744 |
|
51745 | // Ignore non-index properties.
|
51746 | while (++index < arrLength) {
|
51747 | var arrValue = array[index],
|
51748 | othValue = other[index];
|
51749 |
|
51750 | if (customizer) {
|
51751 | var compared = isPartial
|
51752 | ? customizer(othValue, arrValue, index, other, array, stack)
|
51753 | : customizer(arrValue, othValue, index, array, other, stack);
|
51754 | }
|
51755 | if (compared !== undefined) {
|
51756 | if (compared) {
|
51757 | continue;
|
51758 | }
|
51759 | result = false;
|
51760 | break;
|
51761 | }
|
51762 | // Recursively compare arrays (susceptible to call stack limits).
|
51763 | if (seen) {
|
51764 | if (!arraySome(other, function(othValue, othIndex) {
|
51765 | if (!cacheHas(seen, othIndex) &&
|
51766 | (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
|
51767 | return seen.push(othIndex);
|
51768 | }
|
51769 | })) {
|
51770 | result = false;
|
51771 | break;
|
51772 | }
|
51773 | } else if (!(
|
51774 | arrValue === othValue ||
|
51775 | equalFunc(arrValue, othValue, bitmask, customizer, stack)
|
51776 | )) {
|
51777 | result = false;
|
51778 | break;
|
51779 | }
|
51780 | }
|
51781 | stack['delete'](array);
|
51782 | stack['delete'](other);
|
51783 | return result;
|
51784 | }
|
51785 |
|
51786 | module.exports = equalArrays;
|
51787 |
|
51788 | },{"./_SetCache":384,"./_arraySome":394,"./_cacheHas":423}],429:[function(require,module,exports){
|
51789 | var Symbol = require('./_Symbol'),
|
51790 | Uint8Array = require('./_Uint8Array'),
|
51791 | eq = require('./eq'),
|
51792 | equalArrays = require('./_equalArrays'),
|
51793 | mapToArray = require('./_mapToArray'),
|
51794 | setToArray = require('./_setToArray');
|
51795 |
|
51796 | /** Used to compose bitmasks for value comparisons. */
|
51797 | var COMPARE_PARTIAL_FLAG = 1,
|
51798 | COMPARE_UNORDERED_FLAG = 2;
|
51799 |
|
51800 | /** `Object#toString` result references. */
|
51801 | var boolTag = '[object Boolean]',
|
51802 | dateTag = '[object Date]',
|
51803 | errorTag = '[object Error]',
|
51804 | mapTag = '[object Map]',
|
51805 | numberTag = '[object Number]',
|
51806 | regexpTag = '[object RegExp]',
|
51807 | setTag = '[object Set]',
|
51808 | stringTag = '[object String]',
|
51809 | symbolTag = '[object Symbol]';
|
51810 |
|
51811 | var arrayBufferTag = '[object ArrayBuffer]',
|
51812 | dataViewTag = '[object DataView]';
|
51813 |
|
51814 | /** Used to convert symbols to primitives and strings. */
|
51815 | var symbolProto = Symbol ? Symbol.prototype : undefined,
|
51816 | symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
|
51817 |
|
51818 | /**
|
51819 | * A specialized version of `baseIsEqualDeep` for comparing objects of
|
51820 | * the same `toStringTag`.
|
51821 | *
|
51822 | * **Note:** This function only supports comparing values with tags of
|
51823 | * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
51824 | *
|
51825 | * @private
|
51826 | * @param {Object} object The object to compare.
|
51827 | * @param {Object} other The other object to compare.
|
51828 | * @param {string} tag The `toStringTag` of the objects to compare.
|
51829 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
51830 | * @param {Function} customizer The function to customize comparisons.
|
51831 | * @param {Function} equalFunc The function to determine equivalents of values.
|
51832 | * @param {Object} stack Tracks traversed `object` and `other` objects.
|
51833 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
51834 | */
|
51835 | function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
|
51836 | switch (tag) {
|
51837 | case dataViewTag:
|
51838 | if ((object.byteLength != other.byteLength) ||
|
51839 | (object.byteOffset != other.byteOffset)) {
|
51840 | return false;
|
51841 | }
|
51842 | object = object.buffer;
|
51843 | other = other.buffer;
|
51844 |
|
51845 | case arrayBufferTag:
|
51846 | if ((object.byteLength != other.byteLength) ||
|
51847 | !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
|
51848 | return false;
|
51849 | }
|
51850 | return true;
|
51851 |
|
51852 | case boolTag:
|
51853 | case dateTag:
|
51854 | case numberTag:
|
51855 | // Coerce booleans to `1` or `0` and dates to milliseconds.
|
51856 | // Invalid dates are coerced to `NaN`.
|
51857 | return eq(+object, +other);
|
51858 |
|
51859 | case errorTag:
|
51860 | return object.name == other.name && object.message == other.message;
|
51861 |
|
51862 | case regexpTag:
|
51863 | case stringTag:
|
51864 | // Coerce regexes to strings and treat strings, primitives and objects,
|
51865 | // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
|
51866 | // for more details.
|
51867 | return object == (other + '');
|
51868 |
|
51869 | case mapTag:
|
51870 | var convert = mapToArray;
|
51871 |
|
51872 | case setTag:
|
51873 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
|
51874 | convert || (convert = setToArray);
|
51875 |
|
51876 | if (object.size != other.size && !isPartial) {
|
51877 | return false;
|
51878 | }
|
51879 | // Assume cyclic values are equal.
|
51880 | var stacked = stack.get(object);
|
51881 | if (stacked) {
|
51882 | return stacked == other;
|
51883 | }
|
51884 | bitmask |= COMPARE_UNORDERED_FLAG;
|
51885 |
|
51886 | // Recursively compare objects (susceptible to call stack limits).
|
51887 | stack.set(object, other);
|
51888 | var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
|
51889 | stack['delete'](object);
|
51890 | return result;
|
51891 |
|
51892 | case symbolTag:
|
51893 | if (symbolValueOf) {
|
51894 | return symbolValueOf.call(object) == symbolValueOf.call(other);
|
51895 | }
|
51896 | }
|
51897 | return false;
|
51898 | }
|
51899 |
|
51900 | module.exports = equalByTag;
|
51901 |
|
51902 | },{"./_Symbol":386,"./_Uint8Array":387,"./_equalArrays":428,"./_mapToArray":464,"./_setToArray":476,"./eq":488}],430:[function(require,module,exports){
|
51903 | var getAllKeys = require('./_getAllKeys');
|
51904 |
|
51905 | /** Used to compose bitmasks for value comparisons. */
|
51906 | var COMPARE_PARTIAL_FLAG = 1;
|
51907 |
|
51908 | /** Used for built-in method references. */
|
51909 | var objectProto = Object.prototype;
|
51910 |
|
51911 | /** Used to check objects for own properties. */
|
51912 | var hasOwnProperty = objectProto.hasOwnProperty;
|
51913 |
|
51914 | /**
|
51915 | * A specialized version of `baseIsEqualDeep` for objects with support for
|
51916 | * partial deep comparisons.
|
51917 | *
|
51918 | * @private
|
51919 | * @param {Object} object The object to compare.
|
51920 | * @param {Object} other The other object to compare.
|
51921 | * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
|
51922 | * @param {Function} customizer The function to customize comparisons.
|
51923 | * @param {Function} equalFunc The function to determine equivalents of values.
|
51924 | * @param {Object} stack Tracks traversed `object` and `other` objects.
|
51925 | * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
51926 | */
|
51927 | function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
|
51928 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
51929 | objProps = getAllKeys(object),
|
51930 | objLength = objProps.length,
|
51931 | othProps = getAllKeys(other),
|
51932 | othLength = othProps.length;
|
51933 |
|
51934 | if (objLength != othLength && !isPartial) {
|
51935 | return false;
|
51936 | }
|
51937 | var index = objLength;
|
51938 | while (index--) {
|
51939 | var key = objProps[index];
|
51940 | if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
|
51941 | return false;
|
51942 | }
|
51943 | }
|
51944 | // Assume cyclic values are equal.
|
51945 | var stacked = stack.get(object);
|
51946 | if (stacked && stack.get(other)) {
|
51947 | return stacked == other;
|
51948 | }
|
51949 | var result = true;
|
51950 | stack.set(object, other);
|
51951 | stack.set(other, object);
|
51952 |
|
51953 | var skipCtor = isPartial;
|
51954 | while (++index < objLength) {
|
51955 | key = objProps[index];
|
51956 | var objValue = object[key],
|
51957 | othValue = other[key];
|
51958 |
|
51959 | if (customizer) {
|
51960 | var compared = isPartial
|
51961 | ? customizer(othValue, objValue, key, other, object, stack)
|
51962 | : customizer(objValue, othValue, key, object, other, stack);
|
51963 | }
|
51964 | // Recursively compare objects (susceptible to call stack limits).
|
51965 | if (!(compared === undefined
|
51966 | ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
|
51967 | : compared
|
51968 | )) {
|
51969 | result = false;
|
51970 | break;
|
51971 | }
|
51972 | skipCtor || (skipCtor = key == 'constructor');
|
51973 | }
|
51974 | if (result && !skipCtor) {
|
51975 | var objCtor = object.constructor,
|
51976 | othCtor = other.constructor;
|
51977 |
|
51978 | // Non `Object` object instances with different constructors are not equal.
|
51979 | if (objCtor != othCtor &&
|
51980 | ('constructor' in object && 'constructor' in other) &&
|
51981 | !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
|
51982 | typeof othCtor == 'function' && othCtor instanceof othCtor)) {
|
51983 | result = false;
|
51984 | }
|
51985 | }
|
51986 | stack['delete'](object);
|
51987 | stack['delete'](other);
|
51988 | return result;
|
51989 | }
|
51990 |
|
51991 | module.exports = equalObjects;
|
51992 |
|
51993 | },{"./_getAllKeys":433}],431:[function(require,module,exports){
|
51994 | var flatten = require('./flatten'),
|
51995 | overRest = require('./_overRest'),
|
51996 | setToString = require('./_setToString');
|
51997 |
|
51998 | /**
|
51999 | * A specialized version of `baseRest` which flattens the rest array.
|
52000 | *
|
52001 | * @private
|
52002 | * @param {Function} func The function to apply a rest parameter to.
|
52003 | * @returns {Function} Returns the new function.
|
52004 | */
|
52005 | function flatRest(func) {
|
52006 | return setToString(overRest(func, undefined, flatten), func + '');
|
52007 | }
|
52008 |
|
52009 | module.exports = flatRest;
|
52010 |
|
52011 | },{"./_overRest":472,"./_setToString":477,"./flatten":491}],432:[function(require,module,exports){
|
52012 | (function (global){
|
52013 | /** Detect free variable `global` from Node.js. */
|
52014 | var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
52015 |
|
52016 | module.exports = freeGlobal;
|
52017 |
|
52018 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
52019 | },{}],433:[function(require,module,exports){
|
52020 | var baseGetAllKeys = require('./_baseGetAllKeys'),
|
52021 | getSymbols = require('./_getSymbols'),
|
52022 | keys = require('./keys');
|
52023 |
|
52024 | /**
|
52025 | * Creates an array of own enumerable property names and symbols of `object`.
|
52026 | *
|
52027 | * @private
|
52028 | * @param {Object} object The object to query.
|
52029 | * @returns {Array} Returns the array of property names and symbols.
|
52030 | */
|
52031 | function getAllKeys(object) {
|
52032 | return baseGetAllKeys(object, keys, getSymbols);
|
52033 | }
|
52034 |
|
52035 | module.exports = getAllKeys;
|
52036 |
|
52037 | },{"./_baseGetAllKeys":401,"./_getSymbols":438,"./keys":506}],434:[function(require,module,exports){
|
52038 | var isKeyable = require('./_isKeyable');
|
52039 |
|
52040 | /**
|
52041 | * Gets the data for `map`.
|
52042 | *
|
52043 | * @private
|
52044 | * @param {Object} map The map to query.
|
52045 | * @param {string} key The reference key.
|
52046 | * @returns {*} Returns the map data.
|
52047 | */
|
52048 | function getMapData(map, key) {
|
52049 | var data = map.__data__;
|
52050 | return isKeyable(key)
|
52051 | ? data[typeof key == 'string' ? 'string' : 'hash']
|
52052 | : data.map;
|
52053 | }
|
52054 |
|
52055 | module.exports = getMapData;
|
52056 |
|
52057 | },{"./_isKeyable":450}],435:[function(require,module,exports){
|
52058 | var isStrictComparable = require('./_isStrictComparable'),
|
52059 | keys = require('./keys');
|
52060 |
|
52061 | /**
|
52062 | * Gets the property names, values, and compare flags of `object`.
|
52063 | *
|
52064 | * @private
|
52065 | * @param {Object} object The object to query.
|
52066 | * @returns {Array} Returns the match data of `object`.
|
52067 | */
|
52068 | function getMatchData(object) {
|
52069 | var result = keys(object),
|
52070 | length = result.length;
|
52071 |
|
52072 | while (length--) {
|
52073 | var key = result[length],
|
52074 | value = object[key];
|
52075 |
|
52076 | result[length] = [key, value, isStrictComparable(value)];
|
52077 | }
|
52078 | return result;
|
52079 | }
|
52080 |
|
52081 | module.exports = getMatchData;
|
52082 |
|
52083 | },{"./_isStrictComparable":453,"./keys":506}],436:[function(require,module,exports){
|
52084 | var baseIsNative = require('./_baseIsNative'),
|
52085 | getValue = require('./_getValue');
|
52086 |
|
52087 | /**
|
52088 | * Gets the native function at `key` of `object`.
|
52089 | *
|
52090 | * @private
|
52091 | * @param {Object} object The object to query.
|
52092 | * @param {string} key The key of the method to get.
|
52093 | * @returns {*} Returns the function if it's native, else `undefined`.
|
52094 | */
|
52095 | function getNative(object, key) {
|
52096 | var value = getValue(object, key);
|
52097 | return baseIsNative(value) ? value : undefined;
|
52098 | }
|
52099 |
|
52100 | module.exports = getNative;
|
52101 |
|
52102 | },{"./_baseIsNative":408,"./_getValue":440}],437:[function(require,module,exports){
|
52103 | var Symbol = require('./_Symbol');
|
52104 |
|
52105 | /** Used for built-in method references. */
|
52106 | var objectProto = Object.prototype;
|
52107 |
|
52108 | /** Used to check objects for own properties. */
|
52109 | var hasOwnProperty = objectProto.hasOwnProperty;
|
52110 |
|
52111 | /**
|
52112 | * Used to resolve the
|
52113 | * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
52114 | * of values.
|
52115 | */
|
52116 | var nativeObjectToString = objectProto.toString;
|
52117 |
|
52118 | /** Built-in value references. */
|
52119 | var symToStringTag = Symbol ? Symbol.toStringTag : undefined;
|
52120 |
|
52121 | /**
|
52122 | * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
|
52123 | *
|
52124 | * @private
|
52125 | * @param {*} value The value to query.
|
52126 | * @returns {string} Returns the raw `toStringTag`.
|
52127 | */
|
52128 | function getRawTag(value) {
|
52129 | var isOwn = hasOwnProperty.call(value, symToStringTag),
|
52130 | tag = value[symToStringTag];
|
52131 |
|
52132 | try {
|
52133 | value[symToStringTag] = undefined;
|
52134 | var unmasked = true;
|
52135 | } catch (e) {}
|
52136 |
|
52137 | var result = nativeObjectToString.call(value);
|
52138 | if (unmasked) {
|
52139 | if (isOwn) {
|
52140 | value[symToStringTag] = tag;
|
52141 | } else {
|
52142 | delete value[symToStringTag];
|
52143 | }
|
52144 | }
|
52145 | return result;
|
52146 | }
|
52147 |
|
52148 | module.exports = getRawTag;
|
52149 |
|
52150 | },{"./_Symbol":386}],438:[function(require,module,exports){
|
52151 | var arrayFilter = require('./_arrayFilter'),
|
52152 | stubArray = require('./stubArray');
|
52153 |
|
52154 | /** Used for built-in method references. */
|
52155 | var objectProto = Object.prototype;
|
52156 |
|
52157 | /** Built-in value references. */
|
52158 | var propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
52159 |
|
52160 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
52161 | var nativeGetSymbols = Object.getOwnPropertySymbols;
|
52162 |
|
52163 | /**
|
52164 | * Creates an array of the own enumerable symbols of `object`.
|
52165 | *
|
52166 | * @private
|
52167 | * @param {Object} object The object to query.
|
52168 | * @returns {Array} Returns the array of symbols.
|
52169 | */
|
52170 | var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
|
52171 | if (object == null) {
|
52172 | return [];
|
52173 | }
|
52174 | object = Object(object);
|
52175 | return arrayFilter(nativeGetSymbols(object), function(symbol) {
|
52176 | return propertyIsEnumerable.call(object, symbol);
|
52177 | });
|
52178 | };
|
52179 |
|
52180 | module.exports = getSymbols;
|
52181 |
|
52182 | },{"./_arrayFilter":390,"./stubArray":510}],439:[function(require,module,exports){
|
52183 | var DataView = require('./_DataView'),
|
52184 | Map = require('./_Map'),
|
52185 | Promise = require('./_Promise'),
|
52186 | Set = require('./_Set'),
|
52187 | WeakMap = require('./_WeakMap'),
|
52188 | baseGetTag = require('./_baseGetTag'),
|
52189 | toSource = require('./_toSource');
|
52190 |
|
52191 | /** `Object#toString` result references. */
|
52192 | var mapTag = '[object Map]',
|
52193 | objectTag = '[object Object]',
|
52194 | promiseTag = '[object Promise]',
|
52195 | setTag = '[object Set]',
|
52196 | weakMapTag = '[object WeakMap]';
|
52197 |
|
52198 | var dataViewTag = '[object DataView]';
|
52199 |
|
52200 | /** Used to detect maps, sets, and weakmaps. */
|
52201 | var dataViewCtorString = toSource(DataView),
|
52202 | mapCtorString = toSource(Map),
|
52203 | promiseCtorString = toSource(Promise),
|
52204 | setCtorString = toSource(Set),
|
52205 | weakMapCtorString = toSource(WeakMap);
|
52206 |
|
52207 | /**
|
52208 | * Gets the `toStringTag` of `value`.
|
52209 | *
|
52210 | * @private
|
52211 | * @param {*} value The value to query.
|
52212 | * @returns {string} Returns the `toStringTag`.
|
52213 | */
|
52214 | var getTag = baseGetTag;
|
52215 |
|
52216 | // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
|
52217 | if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
|
52218 | (Map && getTag(new Map) != mapTag) ||
|
52219 | (Promise && getTag(Promise.resolve()) != promiseTag) ||
|
52220 | (Set && getTag(new Set) != setTag) ||
|
52221 | (WeakMap && getTag(new WeakMap) != weakMapTag)) {
|
52222 | getTag = function(value) {
|
52223 | var result = baseGetTag(value),
|
52224 | Ctor = result == objectTag ? value.constructor : undefined,
|
52225 | ctorString = Ctor ? toSource(Ctor) : '';
|
52226 |
|
52227 | if (ctorString) {
|
52228 | switch (ctorString) {
|
52229 | case dataViewCtorString: return dataViewTag;
|
52230 | case mapCtorString: return mapTag;
|
52231 | case promiseCtorString: return promiseTag;
|
52232 | case setCtorString: return setTag;
|
52233 | case weakMapCtorString: return weakMapTag;
|
52234 | }
|
52235 | }
|
52236 | return result;
|
52237 | };
|
52238 | }
|
52239 |
|
52240 | module.exports = getTag;
|
52241 |
|
52242 | },{"./_DataView":377,"./_Map":380,"./_Promise":382,"./_Set":383,"./_WeakMap":388,"./_baseGetTag":402,"./_toSource":486}],440:[function(require,module,exports){
|
52243 | /**
|
52244 | * Gets the value at `key` of `object`.
|
52245 | *
|
52246 | * @private
|
52247 | * @param {Object} [object] The object to query.
|
52248 | * @param {string} key The key of the property to get.
|
52249 | * @returns {*} Returns the property value.
|
52250 | */
|
52251 | function getValue(object, key) {
|
52252 | return object == null ? undefined : object[key];
|
52253 | }
|
52254 |
|
52255 | module.exports = getValue;
|
52256 |
|
52257 | },{}],441:[function(require,module,exports){
|
52258 | var castPath = require('./_castPath'),
|
52259 | isArguments = require('./isArguments'),
|
52260 | isArray = require('./isArray'),
|
52261 | isIndex = require('./_isIndex'),
|
52262 | isLength = require('./isLength'),
|
52263 | toKey = require('./_toKey');
|
52264 |
|
52265 | /**
|
52266 | * Checks if `path` exists on `object`.
|
52267 | *
|
52268 | * @private
|
52269 | * @param {Object} object The object to query.
|
52270 | * @param {Array|string} path The path to check.
|
52271 | * @param {Function} hasFunc The function to check properties.
|
52272 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
52273 | */
|
52274 | function hasPath(object, path, hasFunc) {
|
52275 | path = castPath(path, object);
|
52276 |
|
52277 | var index = -1,
|
52278 | length = path.length,
|
52279 | result = false;
|
52280 |
|
52281 | while (++index < length) {
|
52282 | var key = toKey(path[index]);
|
52283 | if (!(result = object != null && hasFunc(object, key))) {
|
52284 | break;
|
52285 | }
|
52286 | object = object[key];
|
52287 | }
|
52288 | if (result || ++index != length) {
|
52289 | return result;
|
52290 | }
|
52291 | length = object == null ? 0 : object.length;
|
52292 | return !!length && isLength(length) && isIndex(key, length) &&
|
52293 | (isArray(object) || isArguments(object));
|
52294 | }
|
52295 |
|
52296 | module.exports = hasPath;
|
52297 |
|
52298 | },{"./_castPath":424,"./_isIndex":448,"./_toKey":485,"./isArguments":495,"./isArray":496,"./isLength":501}],442:[function(require,module,exports){
|
52299 | var nativeCreate = require('./_nativeCreate');
|
52300 |
|
52301 | /**
|
52302 | * Removes all key-value entries from the hash.
|
52303 | *
|
52304 | * @private
|
52305 | * @name clear
|
52306 | * @memberOf Hash
|
52307 | */
|
52308 | function hashClear() {
|
52309 | this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
52310 | this.size = 0;
|
52311 | }
|
52312 |
|
52313 | module.exports = hashClear;
|
52314 |
|
52315 | },{"./_nativeCreate":467}],443:[function(require,module,exports){
|
52316 | /**
|
52317 | * Removes `key` and its value from the hash.
|
52318 | *
|
52319 | * @private
|
52320 | * @name delete
|
52321 | * @memberOf Hash
|
52322 | * @param {Object} hash The hash to modify.
|
52323 | * @param {string} key The key of the value to remove.
|
52324 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
52325 | */
|
52326 | function hashDelete(key) {
|
52327 | var result = this.has(key) && delete this.__data__[key];
|
52328 | this.size -= result ? 1 : 0;
|
52329 | return result;
|
52330 | }
|
52331 |
|
52332 | module.exports = hashDelete;
|
52333 |
|
52334 | },{}],444:[function(require,module,exports){
|
52335 | var nativeCreate = require('./_nativeCreate');
|
52336 |
|
52337 | /** Used to stand-in for `undefined` hash values. */
|
52338 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
52339 |
|
52340 | /** Used for built-in method references. */
|
52341 | var objectProto = Object.prototype;
|
52342 |
|
52343 | /** Used to check objects for own properties. */
|
52344 | var hasOwnProperty = objectProto.hasOwnProperty;
|
52345 |
|
52346 | /**
|
52347 | * Gets the hash value for `key`.
|
52348 | *
|
52349 | * @private
|
52350 | * @name get
|
52351 | * @memberOf Hash
|
52352 | * @param {string} key The key of the value to get.
|
52353 | * @returns {*} Returns the entry value.
|
52354 | */
|
52355 | function hashGet(key) {
|
52356 | var data = this.__data__;
|
52357 | if (nativeCreate) {
|
52358 | var result = data[key];
|
52359 | return result === HASH_UNDEFINED ? undefined : result;
|
52360 | }
|
52361 | return hasOwnProperty.call(data, key) ? data[key] : undefined;
|
52362 | }
|
52363 |
|
52364 | module.exports = hashGet;
|
52365 |
|
52366 | },{"./_nativeCreate":467}],445:[function(require,module,exports){
|
52367 | var nativeCreate = require('./_nativeCreate');
|
52368 |
|
52369 | /** Used for built-in method references. */
|
52370 | var objectProto = Object.prototype;
|
52371 |
|
52372 | /** Used to check objects for own properties. */
|
52373 | var hasOwnProperty = objectProto.hasOwnProperty;
|
52374 |
|
52375 | /**
|
52376 | * Checks if a hash value for `key` exists.
|
52377 | *
|
52378 | * @private
|
52379 | * @name has
|
52380 | * @memberOf Hash
|
52381 | * @param {string} key The key of the entry to check.
|
52382 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
52383 | */
|
52384 | function hashHas(key) {
|
52385 | var data = this.__data__;
|
52386 | return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
|
52387 | }
|
52388 |
|
52389 | module.exports = hashHas;
|
52390 |
|
52391 | },{"./_nativeCreate":467}],446:[function(require,module,exports){
|
52392 | var nativeCreate = require('./_nativeCreate');
|
52393 |
|
52394 | /** Used to stand-in for `undefined` hash values. */
|
52395 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
52396 |
|
52397 | /**
|
52398 | * Sets the hash `key` to `value`.
|
52399 | *
|
52400 | * @private
|
52401 | * @name set
|
52402 | * @memberOf Hash
|
52403 | * @param {string} key The key of the value to set.
|
52404 | * @param {*} value The value to set.
|
52405 | * @returns {Object} Returns the hash instance.
|
52406 | */
|
52407 | function hashSet(key, value) {
|
52408 | var data = this.__data__;
|
52409 | this.size += this.has(key) ? 0 : 1;
|
52410 | data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
52411 | return this;
|
52412 | }
|
52413 |
|
52414 | module.exports = hashSet;
|
52415 |
|
52416 | },{"./_nativeCreate":467}],447:[function(require,module,exports){
|
52417 | var Symbol = require('./_Symbol'),
|
52418 | isArguments = require('./isArguments'),
|
52419 | isArray = require('./isArray');
|
52420 |
|
52421 | /** Built-in value references. */
|
52422 | var spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined;
|
52423 |
|
52424 | /**
|
52425 | * Checks if `value` is a flattenable `arguments` object or array.
|
52426 | *
|
52427 | * @private
|
52428 | * @param {*} value The value to check.
|
52429 | * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
|
52430 | */
|
52431 | function isFlattenable(value) {
|
52432 | return isArray(value) || isArguments(value) ||
|
52433 | !!(spreadableSymbol && value && value[spreadableSymbol]);
|
52434 | }
|
52435 |
|
52436 | module.exports = isFlattenable;
|
52437 |
|
52438 | },{"./_Symbol":386,"./isArguments":495,"./isArray":496}],448:[function(require,module,exports){
|
52439 | /** Used as references for various `Number` constants. */
|
52440 | var MAX_SAFE_INTEGER = 9007199254740991;
|
52441 |
|
52442 | /** Used to detect unsigned integer values. */
|
52443 | var reIsUint = /^(?:0|[1-9]\d*)$/;
|
52444 |
|
52445 | /**
|
52446 | * Checks if `value` is a valid array-like index.
|
52447 | *
|
52448 | * @private
|
52449 | * @param {*} value The value to check.
|
52450 | * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
52451 | * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
52452 | */
|
52453 | function isIndex(value, length) {
|
52454 | length = length == null ? MAX_SAFE_INTEGER : length;
|
52455 | return !!length &&
|
52456 | (typeof value == 'number' || reIsUint.test(value)) &&
|
52457 | (value > -1 && value % 1 == 0 && value < length);
|
52458 | }
|
52459 |
|
52460 | module.exports = isIndex;
|
52461 |
|
52462 | },{}],449:[function(require,module,exports){
|
52463 | var isArray = require('./isArray'),
|
52464 | isSymbol = require('./isSymbol');
|
52465 |
|
52466 | /** Used to match property names within property paths. */
|
52467 | var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
|
52468 | reIsPlainProp = /^\w*$/;
|
52469 |
|
52470 | /**
|
52471 | * Checks if `value` is a property name and not a property path.
|
52472 | *
|
52473 | * @private
|
52474 | * @param {*} value The value to check.
|
52475 | * @param {Object} [object] The object to query keys on.
|
52476 | * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
52477 | */
|
52478 | function isKey(value, object) {
|
52479 | if (isArray(value)) {
|
52480 | return false;
|
52481 | }
|
52482 | var type = typeof value;
|
52483 | if (type == 'number' || type == 'symbol' || type == 'boolean' ||
|
52484 | value == null || isSymbol(value)) {
|
52485 | return true;
|
52486 | }
|
52487 | return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
|
52488 | (object != null && value in Object(object));
|
52489 | }
|
52490 |
|
52491 | module.exports = isKey;
|
52492 |
|
52493 | },{"./isArray":496,"./isSymbol":504}],450:[function(require,module,exports){
|
52494 | /**
|
52495 | * Checks if `value` is suitable for use as unique object key.
|
52496 | *
|
52497 | * @private
|
52498 | * @param {*} value The value to check.
|
52499 | * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
|
52500 | */
|
52501 | function isKeyable(value) {
|
52502 | var type = typeof value;
|
52503 | return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
|
52504 | ? (value !== '__proto__')
|
52505 | : (value === null);
|
52506 | }
|
52507 |
|
52508 | module.exports = isKeyable;
|
52509 |
|
52510 | },{}],451:[function(require,module,exports){
|
52511 | var coreJsData = require('./_coreJsData');
|
52512 |
|
52513 | /** Used to detect methods masquerading as native. */
|
52514 | var maskSrcKey = (function() {
|
52515 | var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
|
52516 | return uid ? ('Symbol(src)_1.' + uid) : '';
|
52517 | }());
|
52518 |
|
52519 | /**
|
52520 | * Checks if `func` has its source masked.
|
52521 | *
|
52522 | * @private
|
52523 | * @param {Function} func The function to check.
|
52524 | * @returns {boolean} Returns `true` if `func` is masked, else `false`.
|
52525 | */
|
52526 | function isMasked(func) {
|
52527 | return !!maskSrcKey && (maskSrcKey in func);
|
52528 | }
|
52529 |
|
52530 | module.exports = isMasked;
|
52531 |
|
52532 | },{"./_coreJsData":425}],452:[function(require,module,exports){
|
52533 | /** Used for built-in method references. */
|
52534 | var objectProto = Object.prototype;
|
52535 |
|
52536 | /**
|
52537 | * Checks if `value` is likely a prototype object.
|
52538 | *
|
52539 | * @private
|
52540 | * @param {*} value The value to check.
|
52541 | * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
|
52542 | */
|
52543 | function isPrototype(value) {
|
52544 | var Ctor = value && value.constructor,
|
52545 | proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
|
52546 |
|
52547 | return value === proto;
|
52548 | }
|
52549 |
|
52550 | module.exports = isPrototype;
|
52551 |
|
52552 | },{}],453:[function(require,module,exports){
|
52553 | var isObject = require('./isObject');
|
52554 |
|
52555 | /**
|
52556 | * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
|
52557 | *
|
52558 | * @private
|
52559 | * @param {*} value The value to check.
|
52560 | * @returns {boolean} Returns `true` if `value` if suitable for strict
|
52561 | * equality comparisons, else `false`.
|
52562 | */
|
52563 | function isStrictComparable(value) {
|
52564 | return value === value && !isObject(value);
|
52565 | }
|
52566 |
|
52567 | module.exports = isStrictComparable;
|
52568 |
|
52569 | },{"./isObject":502}],454:[function(require,module,exports){
|
52570 | /**
|
52571 | * Removes all key-value entries from the list cache.
|
52572 | *
|
52573 | * @private
|
52574 | * @name clear
|
52575 | * @memberOf ListCache
|
52576 | */
|
52577 | function listCacheClear() {
|
52578 | this.__data__ = [];
|
52579 | this.size = 0;
|
52580 | }
|
52581 |
|
52582 | module.exports = listCacheClear;
|
52583 |
|
52584 | },{}],455:[function(require,module,exports){
|
52585 | var assocIndexOf = require('./_assocIndexOf');
|
52586 |
|
52587 | /** Used for built-in method references. */
|
52588 | var arrayProto = Array.prototype;
|
52589 |
|
52590 | /** Built-in value references. */
|
52591 | var splice = arrayProto.splice;
|
52592 |
|
52593 | /**
|
52594 | * Removes `key` and its value from the list cache.
|
52595 | *
|
52596 | * @private
|
52597 | * @name delete
|
52598 | * @memberOf ListCache
|
52599 | * @param {string} key The key of the value to remove.
|
52600 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
52601 | */
|
52602 | function listCacheDelete(key) {
|
52603 | var data = this.__data__,
|
52604 | index = assocIndexOf(data, key);
|
52605 |
|
52606 | if (index < 0) {
|
52607 | return false;
|
52608 | }
|
52609 | var lastIndex = data.length - 1;
|
52610 | if (index == lastIndex) {
|
52611 | data.pop();
|
52612 | } else {
|
52613 | splice.call(data, index, 1);
|
52614 | }
|
52615 | --this.size;
|
52616 | return true;
|
52617 | }
|
52618 |
|
52619 | module.exports = listCacheDelete;
|
52620 |
|
52621 | },{"./_assocIndexOf":396}],456:[function(require,module,exports){
|
52622 | var assocIndexOf = require('./_assocIndexOf');
|
52623 |
|
52624 | /**
|
52625 | * Gets the list cache value for `key`.
|
52626 | *
|
52627 | * @private
|
52628 | * @name get
|
52629 | * @memberOf ListCache
|
52630 | * @param {string} key The key of the value to get.
|
52631 | * @returns {*} Returns the entry value.
|
52632 | */
|
52633 | function listCacheGet(key) {
|
52634 | var data = this.__data__,
|
52635 | index = assocIndexOf(data, key);
|
52636 |
|
52637 | return index < 0 ? undefined : data[index][1];
|
52638 | }
|
52639 |
|
52640 | module.exports = listCacheGet;
|
52641 |
|
52642 | },{"./_assocIndexOf":396}],457:[function(require,module,exports){
|
52643 | var assocIndexOf = require('./_assocIndexOf');
|
52644 |
|
52645 | /**
|
52646 | * Checks if a list cache value for `key` exists.
|
52647 | *
|
52648 | * @private
|
52649 | * @name has
|
52650 | * @memberOf ListCache
|
52651 | * @param {string} key The key of the entry to check.
|
52652 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
52653 | */
|
52654 | function listCacheHas(key) {
|
52655 | return assocIndexOf(this.__data__, key) > -1;
|
52656 | }
|
52657 |
|
52658 | module.exports = listCacheHas;
|
52659 |
|
52660 | },{"./_assocIndexOf":396}],458:[function(require,module,exports){
|
52661 | var assocIndexOf = require('./_assocIndexOf');
|
52662 |
|
52663 | /**
|
52664 | * Sets the list cache `key` to `value`.
|
52665 | *
|
52666 | * @private
|
52667 | * @name set
|
52668 | * @memberOf ListCache
|
52669 | * @param {string} key The key of the value to set.
|
52670 | * @param {*} value The value to set.
|
52671 | * @returns {Object} Returns the list cache instance.
|
52672 | */
|
52673 | function listCacheSet(key, value) {
|
52674 | var data = this.__data__,
|
52675 | index = assocIndexOf(data, key);
|
52676 |
|
52677 | if (index < 0) {
|
52678 | ++this.size;
|
52679 | data.push([key, value]);
|
52680 | } else {
|
52681 | data[index][1] = value;
|
52682 | }
|
52683 | return this;
|
52684 | }
|
52685 |
|
52686 | module.exports = listCacheSet;
|
52687 |
|
52688 | },{"./_assocIndexOf":396}],459:[function(require,module,exports){
|
52689 | var Hash = require('./_Hash'),
|
52690 | ListCache = require('./_ListCache'),
|
52691 | Map = require('./_Map');
|
52692 |
|
52693 | /**
|
52694 | * Removes all key-value entries from the map.
|
52695 | *
|
52696 | * @private
|
52697 | * @name clear
|
52698 | * @memberOf MapCache
|
52699 | */
|
52700 | function mapCacheClear() {
|
52701 | this.size = 0;
|
52702 | this.__data__ = {
|
52703 | 'hash': new Hash,
|
52704 | 'map': new (Map || ListCache),
|
52705 | 'string': new Hash
|
52706 | };
|
52707 | }
|
52708 |
|
52709 | module.exports = mapCacheClear;
|
52710 |
|
52711 | },{"./_Hash":378,"./_ListCache":379,"./_Map":380}],460:[function(require,module,exports){
|
52712 | var getMapData = require('./_getMapData');
|
52713 |
|
52714 | /**
|
52715 | * Removes `key` and its value from the map.
|
52716 | *
|
52717 | * @private
|
52718 | * @name delete
|
52719 | * @memberOf MapCache
|
52720 | * @param {string} key The key of the value to remove.
|
52721 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
52722 | */
|
52723 | function mapCacheDelete(key) {
|
52724 | var result = getMapData(this, key)['delete'](key);
|
52725 | this.size -= result ? 1 : 0;
|
52726 | return result;
|
52727 | }
|
52728 |
|
52729 | module.exports = mapCacheDelete;
|
52730 |
|
52731 | },{"./_getMapData":434}],461:[function(require,module,exports){
|
52732 | var getMapData = require('./_getMapData');
|
52733 |
|
52734 | /**
|
52735 | * Gets the map value for `key`.
|
52736 | *
|
52737 | * @private
|
52738 | * @name get
|
52739 | * @memberOf MapCache
|
52740 | * @param {string} key The key of the value to get.
|
52741 | * @returns {*} Returns the entry value.
|
52742 | */
|
52743 | function mapCacheGet(key) {
|
52744 | return getMapData(this, key).get(key);
|
52745 | }
|
52746 |
|
52747 | module.exports = mapCacheGet;
|
52748 |
|
52749 | },{"./_getMapData":434}],462:[function(require,module,exports){
|
52750 | var getMapData = require('./_getMapData');
|
52751 |
|
52752 | /**
|
52753 | * Checks if a map value for `key` exists.
|
52754 | *
|
52755 | * @private
|
52756 | * @name has
|
52757 | * @memberOf MapCache
|
52758 | * @param {string} key The key of the entry to check.
|
52759 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
52760 | */
|
52761 | function mapCacheHas(key) {
|
52762 | return getMapData(this, key).has(key);
|
52763 | }
|
52764 |
|
52765 | module.exports = mapCacheHas;
|
52766 |
|
52767 | },{"./_getMapData":434}],463:[function(require,module,exports){
|
52768 | var getMapData = require('./_getMapData');
|
52769 |
|
52770 | /**
|
52771 | * Sets the map `key` to `value`.
|
52772 | *
|
52773 | * @private
|
52774 | * @name set
|
52775 | * @memberOf MapCache
|
52776 | * @param {string} key The key of the value to set.
|
52777 | * @param {*} value The value to set.
|
52778 | * @returns {Object} Returns the map cache instance.
|
52779 | */
|
52780 | function mapCacheSet(key, value) {
|
52781 | var data = getMapData(this, key),
|
52782 | size = data.size;
|
52783 |
|
52784 | data.set(key, value);
|
52785 | this.size += data.size == size ? 0 : 1;
|
52786 | return this;
|
52787 | }
|
52788 |
|
52789 | module.exports = mapCacheSet;
|
52790 |
|
52791 | },{"./_getMapData":434}],464:[function(require,module,exports){
|
52792 | /**
|
52793 | * Converts `map` to its key-value pairs.
|
52794 | *
|
52795 | * @private
|
52796 | * @param {Object} map The map to convert.
|
52797 | * @returns {Array} Returns the key-value pairs.
|
52798 | */
|
52799 | function mapToArray(map) {
|
52800 | var index = -1,
|
52801 | result = Array(map.size);
|
52802 |
|
52803 | map.forEach(function(value, key) {
|
52804 | result[++index] = [key, value];
|
52805 | });
|
52806 | return result;
|
52807 | }
|
52808 |
|
52809 | module.exports = mapToArray;
|
52810 |
|
52811 | },{}],465:[function(require,module,exports){
|
52812 | /**
|
52813 | * A specialized version of `matchesProperty` for source values suitable
|
52814 | * for strict equality comparisons, i.e. `===`.
|
52815 | *
|
52816 | * @private
|
52817 | * @param {string} key The key of the property to get.
|
52818 | * @param {*} srcValue The value to match.
|
52819 | * @returns {Function} Returns the new spec function.
|
52820 | */
|
52821 | function matchesStrictComparable(key, srcValue) {
|
52822 | return function(object) {
|
52823 | if (object == null) {
|
52824 | return false;
|
52825 | }
|
52826 | return object[key] === srcValue &&
|
52827 | (srcValue !== undefined || (key in Object(object)));
|
52828 | };
|
52829 | }
|
52830 |
|
52831 | module.exports = matchesStrictComparable;
|
52832 |
|
52833 | },{}],466:[function(require,module,exports){
|
52834 | var memoize = require('./memoize');
|
52835 |
|
52836 | /** Used as the maximum memoize cache size. */
|
52837 | var MAX_MEMOIZE_SIZE = 500;
|
52838 |
|
52839 | /**
|
52840 | * A specialized version of `_.memoize` which clears the memoized function's
|
52841 | * cache when it exceeds `MAX_MEMOIZE_SIZE`.
|
52842 | *
|
52843 | * @private
|
52844 | * @param {Function} func The function to have its output memoized.
|
52845 | * @returns {Function} Returns the new memoized function.
|
52846 | */
|
52847 | function memoizeCapped(func) {
|
52848 | var result = memoize(func, function(key) {
|
52849 | if (cache.size === MAX_MEMOIZE_SIZE) {
|
52850 | cache.clear();
|
52851 | }
|
52852 | return key;
|
52853 | });
|
52854 |
|
52855 | var cache = result.cache;
|
52856 | return result;
|
52857 | }
|
52858 |
|
52859 | module.exports = memoizeCapped;
|
52860 |
|
52861 | },{"./memoize":507}],467:[function(require,module,exports){
|
52862 | var getNative = require('./_getNative');
|
52863 |
|
52864 | /* Built-in method references that are verified to be native. */
|
52865 | var nativeCreate = getNative(Object, 'create');
|
52866 |
|
52867 | module.exports = nativeCreate;
|
52868 |
|
52869 | },{"./_getNative":436}],468:[function(require,module,exports){
|
52870 | var overArg = require('./_overArg');
|
52871 |
|
52872 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
52873 | var nativeKeys = overArg(Object.keys, Object);
|
52874 |
|
52875 | module.exports = nativeKeys;
|
52876 |
|
52877 | },{"./_overArg":471}],469:[function(require,module,exports){
|
52878 | var freeGlobal = require('./_freeGlobal');
|
52879 |
|
52880 | /** Detect free variable `exports`. */
|
52881 | var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
|
52882 |
|
52883 | /** Detect free variable `module`. */
|
52884 | var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
|
52885 |
|
52886 | /** Detect the popular CommonJS extension `module.exports`. */
|
52887 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
52888 |
|
52889 | /** Detect free variable `process` from Node.js. */
|
52890 | var freeProcess = moduleExports && freeGlobal.process;
|
52891 |
|
52892 | /** Used to access faster Node.js helpers. */
|
52893 | var nodeUtil = (function() {
|
52894 | try {
|
52895 | return freeProcess && freeProcess.binding && freeProcess.binding('util');
|
52896 | } catch (e) {}
|
52897 | }());
|
52898 |
|
52899 | module.exports = nodeUtil;
|
52900 |
|
52901 | },{"./_freeGlobal":432}],470:[function(require,module,exports){
|
52902 | /** Used for built-in method references. */
|
52903 | var objectProto = Object.prototype;
|
52904 |
|
52905 | /**
|
52906 | * Used to resolve the
|
52907 | * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
52908 | * of values.
|
52909 | */
|
52910 | var nativeObjectToString = objectProto.toString;
|
52911 |
|
52912 | /**
|
52913 | * Converts `value` to a string using `Object.prototype.toString`.
|
52914 | *
|
52915 | * @private
|
52916 | * @param {*} value The value to convert.
|
52917 | * @returns {string} Returns the converted string.
|
52918 | */
|
52919 | function objectToString(value) {
|
52920 | return nativeObjectToString.call(value);
|
52921 | }
|
52922 |
|
52923 | module.exports = objectToString;
|
52924 |
|
52925 | },{}],471:[function(require,module,exports){
|
52926 | /**
|
52927 | * Creates a unary function that invokes `func` with its argument transformed.
|
52928 | *
|
52929 | * @private
|
52930 | * @param {Function} func The function to wrap.
|
52931 | * @param {Function} transform The argument transform.
|
52932 | * @returns {Function} Returns the new function.
|
52933 | */
|
52934 | function overArg(func, transform) {
|
52935 | return function(arg) {
|
52936 | return func(transform(arg));
|
52937 | };
|
52938 | }
|
52939 |
|
52940 | module.exports = overArg;
|
52941 |
|
52942 | },{}],472:[function(require,module,exports){
|
52943 | var apply = require('./_apply');
|
52944 |
|
52945 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
52946 | var nativeMax = Math.max;
|
52947 |
|
52948 | /**
|
52949 | * A specialized version of `baseRest` which transforms the rest array.
|
52950 | *
|
52951 | * @private
|
52952 | * @param {Function} func The function to apply a rest parameter to.
|
52953 | * @param {number} [start=func.length-1] The start position of the rest parameter.
|
52954 | * @param {Function} transform The rest array transform.
|
52955 | * @returns {Function} Returns the new function.
|
52956 | */
|
52957 | function overRest(func, start, transform) {
|
52958 | start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
|
52959 | return function() {
|
52960 | var args = arguments,
|
52961 | index = -1,
|
52962 | length = nativeMax(args.length - start, 0),
|
52963 | array = Array(length);
|
52964 |
|
52965 | while (++index < length) {
|
52966 | array[index] = args[start + index];
|
52967 | }
|
52968 | index = -1;
|
52969 | var otherArgs = Array(start + 1);
|
52970 | while (++index < start) {
|
52971 | otherArgs[index] = args[index];
|
52972 | }
|
52973 | otherArgs[start] = transform(array);
|
52974 | return apply(func, this, otherArgs);
|
52975 | };
|
52976 | }
|
52977 |
|
52978 | module.exports = overRest;
|
52979 |
|
52980 | },{"./_apply":389}],473:[function(require,module,exports){
|
52981 | var freeGlobal = require('./_freeGlobal');
|
52982 |
|
52983 | /** Detect free variable `self`. */
|
52984 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
52985 |
|
52986 | /** Used as a reference to the global object. */
|
52987 | var root = freeGlobal || freeSelf || Function('return this')();
|
52988 |
|
52989 | module.exports = root;
|
52990 |
|
52991 | },{"./_freeGlobal":432}],474:[function(require,module,exports){
|
52992 | /** Used to stand-in for `undefined` hash values. */
|
52993 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
52994 |
|
52995 | /**
|
52996 | * Adds `value` to the array cache.
|
52997 | *
|
52998 | * @private
|
52999 | * @name add
|
53000 | * @memberOf SetCache
|
53001 | * @alias push
|
53002 | * @param {*} value The value to cache.
|
53003 | * @returns {Object} Returns the cache instance.
|
53004 | */
|
53005 | function setCacheAdd(value) {
|
53006 | this.__data__.set(value, HASH_UNDEFINED);
|
53007 | return this;
|
53008 | }
|
53009 |
|
53010 | module.exports = setCacheAdd;
|
53011 |
|
53012 | },{}],475:[function(require,module,exports){
|
53013 | /**
|
53014 | * Checks if `value` is in the array cache.
|
53015 | *
|
53016 | * @private
|
53017 | * @name has
|
53018 | * @memberOf SetCache
|
53019 | * @param {*} value The value to search for.
|
53020 | * @returns {number} Returns `true` if `value` is found, else `false`.
|
53021 | */
|
53022 | function setCacheHas(value) {
|
53023 | return this.__data__.has(value);
|
53024 | }
|
53025 |
|
53026 | module.exports = setCacheHas;
|
53027 |
|
53028 | },{}],476:[function(require,module,exports){
|
53029 | /**
|
53030 | * Converts `set` to an array of its values.
|
53031 | *
|
53032 | * @private
|
53033 | * @param {Object} set The set to convert.
|
53034 | * @returns {Array} Returns the values.
|
53035 | */
|
53036 | function setToArray(set) {
|
53037 | var index = -1,
|
53038 | result = Array(set.size);
|
53039 |
|
53040 | set.forEach(function(value) {
|
53041 | result[++index] = value;
|
53042 | });
|
53043 | return result;
|
53044 | }
|
53045 |
|
53046 | module.exports = setToArray;
|
53047 |
|
53048 | },{}],477:[function(require,module,exports){
|
53049 | var baseSetToString = require('./_baseSetToString'),
|
53050 | shortOut = require('./_shortOut');
|
53051 |
|
53052 | /**
|
53053 | * Sets the `toString` method of `func` to return `string`.
|
53054 | *
|
53055 | * @private
|
53056 | * @param {Function} func The function to modify.
|
53057 | * @param {Function} string The `toString` result.
|
53058 | * @returns {Function} Returns `func`.
|
53059 | */
|
53060 | var setToString = shortOut(baseSetToString);
|
53061 |
|
53062 | module.exports = setToString;
|
53063 |
|
53064 | },{"./_baseSetToString":419,"./_shortOut":478}],478:[function(require,module,exports){
|
53065 | /** Used to detect hot functions by number of calls within a span of milliseconds. */
|
53066 | var HOT_COUNT = 800,
|
53067 | HOT_SPAN = 16;
|
53068 |
|
53069 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
53070 | var nativeNow = Date.now;
|
53071 |
|
53072 | /**
|
53073 | * Creates a function that'll short out and invoke `identity` instead
|
53074 | * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
|
53075 | * milliseconds.
|
53076 | *
|
53077 | * @private
|
53078 | * @param {Function} func The function to restrict.
|
53079 | * @returns {Function} Returns the new shortable function.
|
53080 | */
|
53081 | function shortOut(func) {
|
53082 | var count = 0,
|
53083 | lastCalled = 0;
|
53084 |
|
53085 | return function() {
|
53086 | var stamp = nativeNow(),
|
53087 | remaining = HOT_SPAN - (stamp - lastCalled);
|
53088 |
|
53089 | lastCalled = stamp;
|
53090 | if (remaining > 0) {
|
53091 | if (++count >= HOT_COUNT) {
|
53092 | return arguments[0];
|
53093 | }
|
53094 | } else {
|
53095 | count = 0;
|
53096 | }
|
53097 | return func.apply(undefined, arguments);
|
53098 | };
|
53099 | }
|
53100 |
|
53101 | module.exports = shortOut;
|
53102 |
|
53103 | },{}],479:[function(require,module,exports){
|
53104 | var ListCache = require('./_ListCache');
|
53105 |
|
53106 | /**
|
53107 | * Removes all key-value entries from the stack.
|
53108 | *
|
53109 | * @private
|
53110 | * @name clear
|
53111 | * @memberOf Stack
|
53112 | */
|
53113 | function stackClear() {
|
53114 | this.__data__ = new ListCache;
|
53115 | this.size = 0;
|
53116 | }
|
53117 |
|
53118 | module.exports = stackClear;
|
53119 |
|
53120 | },{"./_ListCache":379}],480:[function(require,module,exports){
|
53121 | /**
|
53122 | * Removes `key` and its value from the stack.
|
53123 | *
|
53124 | * @private
|
53125 | * @name delete
|
53126 | * @memberOf Stack
|
53127 | * @param {string} key The key of the value to remove.
|
53128 | * @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
53129 | */
|
53130 | function stackDelete(key) {
|
53131 | var data = this.__data__,
|
53132 | result = data['delete'](key);
|
53133 |
|
53134 | this.size = data.size;
|
53135 | return result;
|
53136 | }
|
53137 |
|
53138 | module.exports = stackDelete;
|
53139 |
|
53140 | },{}],481:[function(require,module,exports){
|
53141 | /**
|
53142 | * Gets the stack value for `key`.
|
53143 | *
|
53144 | * @private
|
53145 | * @name get
|
53146 | * @memberOf Stack
|
53147 | * @param {string} key The key of the value to get.
|
53148 | * @returns {*} Returns the entry value.
|
53149 | */
|
53150 | function stackGet(key) {
|
53151 | return this.__data__.get(key);
|
53152 | }
|
53153 |
|
53154 | module.exports = stackGet;
|
53155 |
|
53156 | },{}],482:[function(require,module,exports){
|
53157 | /**
|
53158 | * Checks if a stack value for `key` exists.
|
53159 | *
|
53160 | * @private
|
53161 | * @name has
|
53162 | * @memberOf Stack
|
53163 | * @param {string} key The key of the entry to check.
|
53164 | * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
53165 | */
|
53166 | function stackHas(key) {
|
53167 | return this.__data__.has(key);
|
53168 | }
|
53169 |
|
53170 | module.exports = stackHas;
|
53171 |
|
53172 | },{}],483:[function(require,module,exports){
|
53173 | var ListCache = require('./_ListCache'),
|
53174 | Map = require('./_Map'),
|
53175 | MapCache = require('./_MapCache');
|
53176 |
|
53177 | /** Used as the size to enable large array optimizations. */
|
53178 | var LARGE_ARRAY_SIZE = 200;
|
53179 |
|
53180 | /**
|
53181 | * Sets the stack `key` to `value`.
|
53182 | *
|
53183 | * @private
|
53184 | * @name set
|
53185 | * @memberOf Stack
|
53186 | * @param {string} key The key of the value to set.
|
53187 | * @param {*} value The value to set.
|
53188 | * @returns {Object} Returns the stack cache instance.
|
53189 | */
|
53190 | function stackSet(key, value) {
|
53191 | var data = this.__data__;
|
53192 | if (data instanceof ListCache) {
|
53193 | var pairs = data.__data__;
|
53194 | if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
|
53195 | pairs.push([key, value]);
|
53196 | this.size = ++data.size;
|
53197 | return this;
|
53198 | }
|
53199 | data = this.__data__ = new MapCache(pairs);
|
53200 | }
|
53201 | data.set(key, value);
|
53202 | this.size = data.size;
|
53203 | return this;
|
53204 | }
|
53205 |
|
53206 | module.exports = stackSet;
|
53207 |
|
53208 | },{"./_ListCache":379,"./_Map":380,"./_MapCache":381}],484:[function(require,module,exports){
|
53209 | var memoizeCapped = require('./_memoizeCapped');
|
53210 |
|
53211 | /** Used to match property names within property paths. */
|
53212 | var reLeadingDot = /^\./,
|
53213 | rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
53214 |
|
53215 | /** Used to match backslashes in property paths. */
|
53216 | var reEscapeChar = /\\(\\)?/g;
|
53217 |
|
53218 | /**
|
53219 | * Converts `string` to a property path array.
|
53220 | *
|
53221 | * @private
|
53222 | * @param {string} string The string to convert.
|
53223 | * @returns {Array} Returns the property path array.
|
53224 | */
|
53225 | var stringToPath = memoizeCapped(function(string) {
|
53226 | var result = [];
|
53227 | if (reLeadingDot.test(string)) {
|
53228 | result.push('');
|
53229 | }
|
53230 | string.replace(rePropName, function(match, number, quote, string) {
|
53231 | result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
|
53232 | });
|
53233 | return result;
|
53234 | });
|
53235 |
|
53236 | module.exports = stringToPath;
|
53237 |
|
53238 | },{"./_memoizeCapped":466}],485:[function(require,module,exports){
|
53239 | var isSymbol = require('./isSymbol');
|
53240 |
|
53241 | /** Used as references for various `Number` constants. */
|
53242 | var INFINITY = 1 / 0;
|
53243 |
|
53244 | /**
|
53245 | * Converts `value` to a string key if it's not a string or symbol.
|
53246 | *
|
53247 | * @private
|
53248 | * @param {*} value The value to inspect.
|
53249 | * @returns {string|symbol} Returns the key.
|
53250 | */
|
53251 | function toKey(value) {
|
53252 | if (typeof value == 'string' || isSymbol(value)) {
|
53253 | return value;
|
53254 | }
|
53255 | var result = (value + '');
|
53256 | return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
53257 | }
|
53258 |
|
53259 | module.exports = toKey;
|
53260 |
|
53261 | },{"./isSymbol":504}],486:[function(require,module,exports){
|
53262 | /** Used for built-in method references. */
|
53263 | var funcProto = Function.prototype;
|
53264 |
|
53265 | /** Used to resolve the decompiled source of functions. */
|
53266 | var funcToString = funcProto.toString;
|
53267 |
|
53268 | /**
|
53269 | * Converts `func` to its source code.
|
53270 | *
|
53271 | * @private
|
53272 | * @param {Function} func The function to convert.
|
53273 | * @returns {string} Returns the source code.
|
53274 | */
|
53275 | function toSource(func) {
|
53276 | if (func != null) {
|
53277 | try {
|
53278 | return funcToString.call(func);
|
53279 | } catch (e) {}
|
53280 | try {
|
53281 | return (func + '');
|
53282 | } catch (e) {}
|
53283 | }
|
53284 | return '';
|
53285 | }
|
53286 |
|
53287 | module.exports = toSource;
|
53288 |
|
53289 | },{}],487:[function(require,module,exports){
|
53290 | /**
|
53291 | * Creates a function that returns `value`.
|
53292 | *
|
53293 | * @static
|
53294 | * @memberOf _
|
53295 | * @since 2.4.0
|
53296 | * @category Util
|
53297 | * @param {*} value The value to return from the new function.
|
53298 | * @returns {Function} Returns the new constant function.
|
53299 | * @example
|
53300 | *
|
53301 | * var objects = _.times(2, _.constant({ 'a': 1 }));
|
53302 | *
|
53303 | * console.log(objects);
|
53304 | * // => [{ 'a': 1 }, { 'a': 1 }]
|
53305 | *
|
53306 | * console.log(objects[0] === objects[1]);
|
53307 | * // => true
|
53308 | */
|
53309 | function constant(value) {
|
53310 | return function() {
|
53311 | return value;
|
53312 | };
|
53313 | }
|
53314 |
|
53315 | module.exports = constant;
|
53316 |
|
53317 | },{}],488:[function(require,module,exports){
|
53318 | /**
|
53319 | * Performs a
|
53320 | * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
53321 | * comparison between two values to determine if they are equivalent.
|
53322 | *
|
53323 | * @static
|
53324 | * @memberOf _
|
53325 | * @since 4.0.0
|
53326 | * @category Lang
|
53327 | * @param {*} value The value to compare.
|
53328 | * @param {*} other The other value to compare.
|
53329 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
53330 | * @example
|
53331 | *
|
53332 | * var object = { 'a': 1 };
|
53333 | * var other = { 'a': 1 };
|
53334 | *
|
53335 | * _.eq(object, object);
|
53336 | * // => true
|
53337 | *
|
53338 | * _.eq(object, other);
|
53339 | * // => false
|
53340 | *
|
53341 | * _.eq('a', 'a');
|
53342 | * // => true
|
53343 | *
|
53344 | * _.eq('a', Object('a'));
|
53345 | * // => false
|
53346 | *
|
53347 | * _.eq(NaN, NaN);
|
53348 | * // => true
|
53349 | */
|
53350 | function eq(value, other) {
|
53351 | return value === other || (value !== value && other !== other);
|
53352 | }
|
53353 |
|
53354 | module.exports = eq;
|
53355 |
|
53356 | },{}],489:[function(require,module,exports){
|
53357 | var createFind = require('./_createFind'),
|
53358 | findIndex = require('./findIndex');
|
53359 |
|
53360 | /**
|
53361 | * Iterates over elements of `collection`, returning the first element
|
53362 | * `predicate` returns truthy for. The predicate is invoked with three
|
53363 | * arguments: (value, index|key, collection).
|
53364 | *
|
53365 | * @static
|
53366 | * @memberOf _
|
53367 | * @since 0.1.0
|
53368 | * @category Collection
|
53369 | * @param {Array|Object} collection The collection to inspect.
|
53370 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
53371 | * @param {number} [fromIndex=0] The index to search from.
|
53372 | * @returns {*} Returns the matched element, else `undefined`.
|
53373 | * @example
|
53374 | *
|
53375 | * var users = [
|
53376 | * { 'user': 'barney', 'age': 36, 'active': true },
|
53377 | * { 'user': 'fred', 'age': 40, 'active': false },
|
53378 | * { 'user': 'pebbles', 'age': 1, 'active': true }
|
53379 | * ];
|
53380 | *
|
53381 | * _.find(users, function(o) { return o.age < 40; });
|
53382 | * // => object for 'barney'
|
53383 | *
|
53384 | * // The `_.matches` iteratee shorthand.
|
53385 | * _.find(users, { 'age': 1, 'active': true });
|
53386 | * // => object for 'pebbles'
|
53387 | *
|
53388 | * // The `_.matchesProperty` iteratee shorthand.
|
53389 | * _.find(users, ['active', false]);
|
53390 | * // => object for 'fred'
|
53391 | *
|
53392 | * // The `_.property` iteratee shorthand.
|
53393 | * _.find(users, 'active');
|
53394 | * // => object for 'barney'
|
53395 | */
|
53396 | var find = createFind(findIndex);
|
53397 |
|
53398 | module.exports = find;
|
53399 |
|
53400 | },{"./_createFind":426,"./findIndex":490}],490:[function(require,module,exports){
|
53401 | var baseFindIndex = require('./_baseFindIndex'),
|
53402 | baseIteratee = require('./_baseIteratee'),
|
53403 | toInteger = require('./toInteger');
|
53404 |
|
53405 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
53406 | var nativeMax = Math.max;
|
53407 |
|
53408 | /**
|
53409 | * This method is like `_.find` except that it returns the index of the first
|
53410 | * element `predicate` returns truthy for instead of the element itself.
|
53411 | *
|
53412 | * @static
|
53413 | * @memberOf _
|
53414 | * @since 1.1.0
|
53415 | * @category Array
|
53416 | * @param {Array} array The array to inspect.
|
53417 | * @param {Function} [predicate=_.identity] The function invoked per iteration.
|
53418 | * @param {number} [fromIndex=0] The index to search from.
|
53419 | * @returns {number} Returns the index of the found element, else `-1`.
|
53420 | * @example
|
53421 | *
|
53422 | * var users = [
|
53423 | * { 'user': 'barney', 'active': false },
|
53424 | * { 'user': 'fred', 'active': false },
|
53425 | * { 'user': 'pebbles', 'active': true }
|
53426 | * ];
|
53427 | *
|
53428 | * _.findIndex(users, function(o) { return o.user == 'barney'; });
|
53429 | * // => 0
|
53430 | *
|
53431 | * // The `_.matches` iteratee shorthand.
|
53432 | * _.findIndex(users, { 'user': 'fred', 'active': false });
|
53433 | * // => 1
|
53434 | *
|
53435 | * // The `_.matchesProperty` iteratee shorthand.
|
53436 | * _.findIndex(users, ['active', false]);
|
53437 | * // => 0
|
53438 | *
|
53439 | * // The `_.property` iteratee shorthand.
|
53440 | * _.findIndex(users, 'active');
|
53441 | * // => 2
|
53442 | */
|
53443 | function findIndex(array, predicate, fromIndex) {
|
53444 | var length = array == null ? 0 : array.length;
|
53445 | if (!length) {
|
53446 | return -1;
|
53447 | }
|
53448 | var index = fromIndex == null ? 0 : toInteger(fromIndex);
|
53449 | if (index < 0) {
|
53450 | index = nativeMax(length + index, 0);
|
53451 | }
|
53452 | return baseFindIndex(array, baseIteratee(predicate, 3), index);
|
53453 | }
|
53454 |
|
53455 | module.exports = findIndex;
|
53456 |
|
53457 | },{"./_baseFindIndex":398,"./_baseIteratee":410,"./toInteger":513}],491:[function(require,module,exports){
|
53458 | var baseFlatten = require('./_baseFlatten');
|
53459 |
|
53460 | /**
|
53461 | * Flattens `array` a single level deep.
|
53462 | *
|
53463 | * @static
|
53464 | * @memberOf _
|
53465 | * @since 0.1.0
|
53466 | * @category Array
|
53467 | * @param {Array} array The array to flatten.
|
53468 | * @returns {Array} Returns the new flattened array.
|
53469 | * @example
|
53470 | *
|
53471 | * _.flatten([1, [2, [3, [4]], 5]]);
|
53472 | * // => [1, 2, [3, [4]], 5]
|
53473 | */
|
53474 | function flatten(array) {
|
53475 | var length = array == null ? 0 : array.length;
|
53476 | return length ? baseFlatten(array, 1) : [];
|
53477 | }
|
53478 |
|
53479 | module.exports = flatten;
|
53480 |
|
53481 | },{"./_baseFlatten":399}],492:[function(require,module,exports){
|
53482 | var baseGet = require('./_baseGet');
|
53483 |
|
53484 | /**
|
53485 | * Gets the value at `path` of `object`. If the resolved value is
|
53486 | * `undefined`, the `defaultValue` is returned in its place.
|
53487 | *
|
53488 | * @static
|
53489 | * @memberOf _
|
53490 | * @since 3.7.0
|
53491 | * @category Object
|
53492 | * @param {Object} object The object to query.
|
53493 | * @param {Array|string} path The path of the property to get.
|
53494 | * @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
53495 | * @returns {*} Returns the resolved value.
|
53496 | * @example
|
53497 | *
|
53498 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
53499 | *
|
53500 | * _.get(object, 'a[0].b.c');
|
53501 | * // => 3
|
53502 | *
|
53503 | * _.get(object, ['a', '0', 'b', 'c']);
|
53504 | * // => 3
|
53505 | *
|
53506 | * _.get(object, 'a.b.c', 'default');
|
53507 | * // => 'default'
|
53508 | */
|
53509 | function get(object, path, defaultValue) {
|
53510 | var result = object == null ? undefined : baseGet(object, path);
|
53511 | return result === undefined ? defaultValue : result;
|
53512 | }
|
53513 |
|
53514 | module.exports = get;
|
53515 |
|
53516 | },{"./_baseGet":400}],493:[function(require,module,exports){
|
53517 | var baseHasIn = require('./_baseHasIn'),
|
53518 | hasPath = require('./_hasPath');
|
53519 |
|
53520 | /**
|
53521 | * Checks if `path` is a direct or inherited property of `object`.
|
53522 | *
|
53523 | * @static
|
53524 | * @memberOf _
|
53525 | * @since 4.0.0
|
53526 | * @category Object
|
53527 | * @param {Object} object The object to query.
|
53528 | * @param {Array|string} path The path to check.
|
53529 | * @returns {boolean} Returns `true` if `path` exists, else `false`.
|
53530 | * @example
|
53531 | *
|
53532 | * var object = _.create({ 'a': _.create({ 'b': 2 }) });
|
53533 | *
|
53534 | * _.hasIn(object, 'a');
|
53535 | * // => true
|
53536 | *
|
53537 | * _.hasIn(object, 'a.b');
|
53538 | * // => true
|
53539 | *
|
53540 | * _.hasIn(object, ['a', 'b']);
|
53541 | * // => true
|
53542 | *
|
53543 | * _.hasIn(object, 'b');
|
53544 | * // => false
|
53545 | */
|
53546 | function hasIn(object, path) {
|
53547 | return object != null && hasPath(object, path, baseHasIn);
|
53548 | }
|
53549 |
|
53550 | module.exports = hasIn;
|
53551 |
|
53552 | },{"./_baseHasIn":403,"./_hasPath":441}],494:[function(require,module,exports){
|
53553 | /**
|
53554 | * This method returns the first argument it receives.
|
53555 | *
|
53556 | * @static
|
53557 | * @since 0.1.0
|
53558 | * @memberOf _
|
53559 | * @category Util
|
53560 | * @param {*} value Any value.
|
53561 | * @returns {*} Returns `value`.
|
53562 | * @example
|
53563 | *
|
53564 | * var object = { 'a': 1 };
|
53565 | *
|
53566 | * console.log(_.identity(object) === object);
|
53567 | * // => true
|
53568 | */
|
53569 | function identity(value) {
|
53570 | return value;
|
53571 | }
|
53572 |
|
53573 | module.exports = identity;
|
53574 |
|
53575 | },{}],495:[function(require,module,exports){
|
53576 | var baseIsArguments = require('./_baseIsArguments'),
|
53577 | isObjectLike = require('./isObjectLike');
|
53578 |
|
53579 | /** Used for built-in method references. */
|
53580 | var objectProto = Object.prototype;
|
53581 |
|
53582 | /** Used to check objects for own properties. */
|
53583 | var hasOwnProperty = objectProto.hasOwnProperty;
|
53584 |
|
53585 | /** Built-in value references. */
|
53586 | var propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
53587 |
|
53588 | /**
|
53589 | * Checks if `value` is likely an `arguments` object.
|
53590 | *
|
53591 | * @static
|
53592 | * @memberOf _
|
53593 | * @since 0.1.0
|
53594 | * @category Lang
|
53595 | * @param {*} value The value to check.
|
53596 | * @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
53597 | * else `false`.
|
53598 | * @example
|
53599 | *
|
53600 | * _.isArguments(function() { return arguments; }());
|
53601 | * // => true
|
53602 | *
|
53603 | * _.isArguments([1, 2, 3]);
|
53604 | * // => false
|
53605 | */
|
53606 | var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
|
53607 | return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
|
53608 | !propertyIsEnumerable.call(value, 'callee');
|
53609 | };
|
53610 |
|
53611 | module.exports = isArguments;
|
53612 |
|
53613 | },{"./_baseIsArguments":404,"./isObjectLike":503}],496:[function(require,module,exports){
|
53614 | /**
|
53615 | * Checks if `value` is classified as an `Array` object.
|
53616 | *
|
53617 | * @static
|
53618 | * @memberOf _
|
53619 | * @since 0.1.0
|
53620 | * @category Lang
|
53621 | * @param {*} value The value to check.
|
53622 | * @returns {boolean} Returns `true` if `value` is an array, else `false`.
|
53623 | * @example
|
53624 | *
|
53625 | * _.isArray([1, 2, 3]);
|
53626 | * // => true
|
53627 | *
|
53628 | * _.isArray(document.body.children);
|
53629 | * // => false
|
53630 | *
|
53631 | * _.isArray('abc');
|
53632 | * // => false
|
53633 | *
|
53634 | * _.isArray(_.noop);
|
53635 | * // => false
|
53636 | */
|
53637 | var isArray = Array.isArray;
|
53638 |
|
53639 | module.exports = isArray;
|
53640 |
|
53641 | },{}],497:[function(require,module,exports){
|
53642 | var isFunction = require('./isFunction'),
|
53643 | isLength = require('./isLength');
|
53644 |
|
53645 | /**
|
53646 | * Checks if `value` is array-like. A value is considered array-like if it's
|
53647 | * not a function and has a `value.length` that's an integer greater than or
|
53648 | * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
|
53649 | *
|
53650 | * @static
|
53651 | * @memberOf _
|
53652 | * @since 4.0.0
|
53653 | * @category Lang
|
53654 | * @param {*} value The value to check.
|
53655 | * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
53656 | * @example
|
53657 | *
|
53658 | * _.isArrayLike([1, 2, 3]);
|
53659 | * // => true
|
53660 | *
|
53661 | * _.isArrayLike(document.body.children);
|
53662 | * // => true
|
53663 | *
|
53664 | * _.isArrayLike('abc');
|
53665 | * // => true
|
53666 | *
|
53667 | * _.isArrayLike(_.noop);
|
53668 | * // => false
|
53669 | */
|
53670 | function isArrayLike(value) {
|
53671 | return value != null && isLength(value.length) && !isFunction(value);
|
53672 | }
|
53673 |
|
53674 | module.exports = isArrayLike;
|
53675 |
|
53676 | },{"./isFunction":500,"./isLength":501}],498:[function(require,module,exports){
|
53677 | var root = require('./_root'),
|
53678 | stubFalse = require('./stubFalse');
|
53679 |
|
53680 | /** Detect free variable `exports`. */
|
53681 | var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
|
53682 |
|
53683 | /** Detect free variable `module`. */
|
53684 | var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
|
53685 |
|
53686 | /** Detect the popular CommonJS extension `module.exports`. */
|
53687 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
53688 |
|
53689 | /** Built-in value references. */
|
53690 | var Buffer = moduleExports ? root.Buffer : undefined;
|
53691 |
|
53692 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
53693 | var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
|
53694 |
|
53695 | /**
|
53696 | * Checks if `value` is a buffer.
|
53697 | *
|
53698 | * @static
|
53699 | * @memberOf _
|
53700 | * @since 4.3.0
|
53701 | * @category Lang
|
53702 | * @param {*} value The value to check.
|
53703 | * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
|
53704 | * @example
|
53705 | *
|
53706 | * _.isBuffer(new Buffer(2));
|
53707 | * // => true
|
53708 | *
|
53709 | * _.isBuffer(new Uint8Array(2));
|
53710 | * // => false
|
53711 | */
|
53712 | var isBuffer = nativeIsBuffer || stubFalse;
|
53713 |
|
53714 | module.exports = isBuffer;
|
53715 |
|
53716 | },{"./_root":473,"./stubFalse":511}],499:[function(require,module,exports){
|
53717 | var baseIsEqual = require('./_baseIsEqual');
|
53718 |
|
53719 | /**
|
53720 | * Performs a deep comparison between two values to determine if they are
|
53721 | * equivalent.
|
53722 | *
|
53723 | * **Note:** This method supports comparing arrays, array buffers, booleans,
|
53724 | * date objects, error objects, maps, numbers, `Object` objects, regexes,
|
53725 | * sets, strings, symbols, and typed arrays. `Object` objects are compared
|
53726 | * by their own, not inherited, enumerable properties. Functions and DOM
|
53727 | * nodes are compared by strict equality, i.e. `===`.
|
53728 | *
|
53729 | * @static
|
53730 | * @memberOf _
|
53731 | * @since 0.1.0
|
53732 | * @category Lang
|
53733 | * @param {*} value The value to compare.
|
53734 | * @param {*} other The other value to compare.
|
53735 | * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
53736 | * @example
|
53737 | *
|
53738 | * var object = { 'a': 1 };
|
53739 | * var other = { 'a': 1 };
|
53740 | *
|
53741 | * _.isEqual(object, other);
|
53742 | * // => true
|
53743 | *
|
53744 | * object === other;
|
53745 | * // => false
|
53746 | */
|
53747 | function isEqual(value, other) {
|
53748 | return baseIsEqual(value, other);
|
53749 | }
|
53750 |
|
53751 | module.exports = isEqual;
|
53752 |
|
53753 | },{"./_baseIsEqual":405}],500:[function(require,module,exports){
|
53754 | var baseGetTag = require('./_baseGetTag'),
|
53755 | isObject = require('./isObject');
|
53756 |
|
53757 | /** `Object#toString` result references. */
|
53758 | var asyncTag = '[object AsyncFunction]',
|
53759 | funcTag = '[object Function]',
|
53760 | genTag = '[object GeneratorFunction]',
|
53761 | proxyTag = '[object Proxy]';
|
53762 |
|
53763 | /**
|
53764 | * Checks if `value` is classified as a `Function` object.
|
53765 | *
|
53766 | * @static
|
53767 | * @memberOf _
|
53768 | * @since 0.1.0
|
53769 | * @category Lang
|
53770 | * @param {*} value The value to check.
|
53771 | * @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
53772 | * @example
|
53773 | *
|
53774 | * _.isFunction(_);
|
53775 | * // => true
|
53776 | *
|
53777 | * _.isFunction(/abc/);
|
53778 | * // => false
|
53779 | */
|
53780 | function isFunction(value) {
|
53781 | if (!isObject(value)) {
|
53782 | return false;
|
53783 | }
|
53784 | // The use of `Object#toString` avoids issues with the `typeof` operator
|
53785 | // in Safari 9 which returns 'object' for typed arrays and other constructors.
|
53786 | var tag = baseGetTag(value);
|
53787 | return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
53788 | }
|
53789 |
|
53790 | module.exports = isFunction;
|
53791 |
|
53792 | },{"./_baseGetTag":402,"./isObject":502}],501:[function(require,module,exports){
|
53793 | /** Used as references for various `Number` constants. */
|
53794 | var MAX_SAFE_INTEGER = 9007199254740991;
|
53795 |
|
53796 | /**
|
53797 | * Checks if `value` is a valid array-like length.
|
53798 | *
|
53799 | * **Note:** This method is loosely based on
|
53800 | * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
53801 | *
|
53802 | * @static
|
53803 | * @memberOf _
|
53804 | * @since 4.0.0
|
53805 | * @category Lang
|
53806 | * @param {*} value The value to check.
|
53807 | * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
53808 | * @example
|
53809 | *
|
53810 | * _.isLength(3);
|
53811 | * // => true
|
53812 | *
|
53813 | * _.isLength(Number.MIN_VALUE);
|
53814 | * // => false
|
53815 | *
|
53816 | * _.isLength(Infinity);
|
53817 | * // => false
|
53818 | *
|
53819 | * _.isLength('3');
|
53820 | * // => false
|
53821 | */
|
53822 | function isLength(value) {
|
53823 | return typeof value == 'number' &&
|
53824 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
53825 | }
|
53826 |
|
53827 | module.exports = isLength;
|
53828 |
|
53829 | },{}],502:[function(require,module,exports){
|
53830 | /**
|
53831 | * Checks if `value` is the
|
53832 | * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
53833 | * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
53834 | *
|
53835 | * @static
|
53836 | * @memberOf _
|
53837 | * @since 0.1.0
|
53838 | * @category Lang
|
53839 | * @param {*} value The value to check.
|
53840 | * @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
53841 | * @example
|
53842 | *
|
53843 | * _.isObject({});
|
53844 | * // => true
|
53845 | *
|
53846 | * _.isObject([1, 2, 3]);
|
53847 | * // => true
|
53848 | *
|
53849 | * _.isObject(_.noop);
|
53850 | * // => true
|
53851 | *
|
53852 | * _.isObject(null);
|
53853 | * // => false
|
53854 | */
|
53855 | function isObject(value) {
|
53856 | var type = typeof value;
|
53857 | return value != null && (type == 'object' || type == 'function');
|
53858 | }
|
53859 |
|
53860 | module.exports = isObject;
|
53861 |
|
53862 | },{}],503:[function(require,module,exports){
|
53863 | /**
|
53864 | * Checks if `value` is object-like. A value is object-like if it's not `null`
|
53865 | * and has a `typeof` result of "object".
|
53866 | *
|
53867 | * @static
|
53868 | * @memberOf _
|
53869 | * @since 4.0.0
|
53870 | * @category Lang
|
53871 | * @param {*} value The value to check.
|
53872 | * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
53873 | * @example
|
53874 | *
|
53875 | * _.isObjectLike({});
|
53876 | * // => true
|
53877 | *
|
53878 | * _.isObjectLike([1, 2, 3]);
|
53879 | * // => true
|
53880 | *
|
53881 | * _.isObjectLike(_.noop);
|
53882 | * // => false
|
53883 | *
|
53884 | * _.isObjectLike(null);
|
53885 | * // => false
|
53886 | */
|
53887 | function isObjectLike(value) {
|
53888 | return value != null && typeof value == 'object';
|
53889 | }
|
53890 |
|
53891 | module.exports = isObjectLike;
|
53892 |
|
53893 | },{}],504:[function(require,module,exports){
|
53894 | var baseGetTag = require('./_baseGetTag'),
|
53895 | isObjectLike = require('./isObjectLike');
|
53896 |
|
53897 | /** `Object#toString` result references. */
|
53898 | var symbolTag = '[object Symbol]';
|
53899 |
|
53900 | /**
|
53901 | * Checks if `value` is classified as a `Symbol` primitive or object.
|
53902 | *
|
53903 | * @static
|
53904 | * @memberOf _
|
53905 | * @since 4.0.0
|
53906 | * @category Lang
|
53907 | * @param {*} value The value to check.
|
53908 | * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
53909 | * @example
|
53910 | *
|
53911 | * _.isSymbol(Symbol.iterator);
|
53912 | * // => true
|
53913 | *
|
53914 | * _.isSymbol('abc');
|
53915 | * // => false
|
53916 | */
|
53917 | function isSymbol(value) {
|
53918 | return typeof value == 'symbol' ||
|
53919 | (isObjectLike(value) && baseGetTag(value) == symbolTag);
|
53920 | }
|
53921 |
|
53922 | module.exports = isSymbol;
|
53923 |
|
53924 | },{"./_baseGetTag":402,"./isObjectLike":503}],505:[function(require,module,exports){
|
53925 | var baseIsTypedArray = require('./_baseIsTypedArray'),
|
53926 | baseUnary = require('./_baseUnary'),
|
53927 | nodeUtil = require('./_nodeUtil');
|
53928 |
|
53929 | /* Node.js helper references. */
|
53930 | var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
|
53931 |
|
53932 | /**
|
53933 | * Checks if `value` is classified as a typed array.
|
53934 | *
|
53935 | * @static
|
53936 | * @memberOf _
|
53937 | * @since 3.0.0
|
53938 | * @category Lang
|
53939 | * @param {*} value The value to check.
|
53940 | * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
|
53941 | * @example
|
53942 | *
|
53943 | * _.isTypedArray(new Uint8Array);
|
53944 | * // => true
|
53945 | *
|
53946 | * _.isTypedArray([]);
|
53947 | * // => false
|
53948 | */
|
53949 | var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
|
53950 |
|
53951 | module.exports = isTypedArray;
|
53952 |
|
53953 | },{"./_baseIsTypedArray":409,"./_baseUnary":422,"./_nodeUtil":469}],506:[function(require,module,exports){
|
53954 | var arrayLikeKeys = require('./_arrayLikeKeys'),
|
53955 | baseKeys = require('./_baseKeys'),
|
53956 | isArrayLike = require('./isArrayLike');
|
53957 |
|
53958 | /**
|
53959 | * Creates an array of the own enumerable property names of `object`.
|
53960 | *
|
53961 | * **Note:** Non-object values are coerced to objects. See the
|
53962 | * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
|
53963 | * for more details.
|
53964 | *
|
53965 | * @static
|
53966 | * @since 0.1.0
|
53967 | * @memberOf _
|
53968 | * @category Object
|
53969 | * @param {Object} object The object to query.
|
53970 | * @returns {Array} Returns the array of property names.
|
53971 | * @example
|
53972 | *
|
53973 | * function Foo() {
|
53974 | * this.a = 1;
|
53975 | * this.b = 2;
|
53976 | * }
|
53977 | *
|
53978 | * Foo.prototype.c = 3;
|
53979 | *
|
53980 | * _.keys(new Foo);
|
53981 | * // => ['a', 'b'] (iteration order is not guaranteed)
|
53982 | *
|
53983 | * _.keys('hi');
|
53984 | * // => ['0', '1']
|
53985 | */
|
53986 | function keys(object) {
|
53987 | return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
|
53988 | }
|
53989 |
|
53990 | module.exports = keys;
|
53991 |
|
53992 | },{"./_arrayLikeKeys":391,"./_baseKeys":411,"./isArrayLike":497}],507:[function(require,module,exports){
|
53993 | var MapCache = require('./_MapCache');
|
53994 |
|
53995 | /** Error message constants. */
|
53996 | var FUNC_ERROR_TEXT = 'Expected a function';
|
53997 |
|
53998 | /**
|
53999 | * Creates a function that memoizes the result of `func`. If `resolver` is
|
54000 | * provided, it determines the cache key for storing the result based on the
|
54001 | * arguments provided to the memoized function. By default, the first argument
|
54002 | * provided to the memoized function is used as the map cache key. The `func`
|
54003 | * is invoked with the `this` binding of the memoized function.
|
54004 | *
|
54005 | * **Note:** The cache is exposed as the `cache` property on the memoized
|
54006 | * function. Its creation may be customized by replacing the `_.memoize.Cache`
|
54007 | * constructor with one whose instances implement the
|
54008 | * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
|
54009 | * method interface of `clear`, `delete`, `get`, `has`, and `set`.
|
54010 | *
|
54011 | * @static
|
54012 | * @memberOf _
|
54013 | * @since 0.1.0
|
54014 | * @category Function
|
54015 | * @param {Function} func The function to have its output memoized.
|
54016 | * @param {Function} [resolver] The function to resolve the cache key.
|
54017 | * @returns {Function} Returns the new memoized function.
|
54018 | * @example
|
54019 | *
|
54020 | * var object = { 'a': 1, 'b': 2 };
|
54021 | * var other = { 'c': 3, 'd': 4 };
|
54022 | *
|
54023 | * var values = _.memoize(_.values);
|
54024 | * values(object);
|
54025 | * // => [1, 2]
|
54026 | *
|
54027 | * values(other);
|
54028 | * // => [3, 4]
|
54029 | *
|
54030 | * object.a = 2;
|
54031 | * values(object);
|
54032 | * // => [1, 2]
|
54033 | *
|
54034 | * // Modify the result cache.
|
54035 | * values.cache.set(object, ['a', 'b']);
|
54036 | * values(object);
|
54037 | * // => ['a', 'b']
|
54038 | *
|
54039 | * // Replace `_.memoize.Cache`.
|
54040 | * _.memoize.Cache = WeakMap;
|
54041 | */
|
54042 | function memoize(func, resolver) {
|
54043 | if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
|
54044 | throw new TypeError(FUNC_ERROR_TEXT);
|
54045 | }
|
54046 | var memoized = function() {
|
54047 | var args = arguments,
|
54048 | key = resolver ? resolver.apply(this, args) : args[0],
|
54049 | cache = memoized.cache;
|
54050 |
|
54051 | if (cache.has(key)) {
|
54052 | return cache.get(key);
|
54053 | }
|
54054 | var result = func.apply(this, args);
|
54055 | memoized.cache = cache.set(key, result) || cache;
|
54056 | return result;
|
54057 | };
|
54058 | memoized.cache = new (memoize.Cache || MapCache);
|
54059 | return memoized;
|
54060 | }
|
54061 |
|
54062 | // Expose `MapCache`.
|
54063 | memoize.Cache = MapCache;
|
54064 |
|
54065 | module.exports = memoize;
|
54066 |
|
54067 | },{"./_MapCache":381}],508:[function(require,module,exports){
|
54068 | var basePick = require('./_basePick'),
|
54069 | flatRest = require('./_flatRest');
|
54070 |
|
54071 | /**
|
54072 | * Creates an object composed of the picked `object` properties.
|
54073 | *
|
54074 | * @static
|
54075 | * @since 0.1.0
|
54076 | * @memberOf _
|
54077 | * @category Object
|
54078 | * @param {Object} object The source object.
|
54079 | * @param {...(string|string[])} [paths] The property paths to pick.
|
54080 | * @returns {Object} Returns the new object.
|
54081 | * @example
|
54082 | *
|
54083 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
54084 | *
|
54085 | * _.pick(object, ['a', 'c']);
|
54086 | * // => { 'a': 1, 'c': 3 }
|
54087 | */
|
54088 | var pick = flatRest(function(object, paths) {
|
54089 | return object == null ? {} : basePick(object, paths);
|
54090 | });
|
54091 |
|
54092 | module.exports = pick;
|
54093 |
|
54094 | },{"./_basePick":414,"./_flatRest":431}],509:[function(require,module,exports){
|
54095 | var baseProperty = require('./_baseProperty'),
|
54096 | basePropertyDeep = require('./_basePropertyDeep'),
|
54097 | isKey = require('./_isKey'),
|
54098 | toKey = require('./_toKey');
|
54099 |
|
54100 | /**
|
54101 | * Creates a function that returns the value at `path` of a given object.
|
54102 | *
|
54103 | * @static
|
54104 | * @memberOf _
|
54105 | * @since 2.4.0
|
54106 | * @category Util
|
54107 | * @param {Array|string} path The path of the property to get.
|
54108 | * @returns {Function} Returns the new accessor function.
|
54109 | * @example
|
54110 | *
|
54111 | * var objects = [
|
54112 | * { 'a': { 'b': 2 } },
|
54113 | * { 'a': { 'b': 1 } }
|
54114 | * ];
|
54115 | *
|
54116 | * _.map(objects, _.property('a.b'));
|
54117 | * // => [2, 1]
|
54118 | *
|
54119 | * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
|
54120 | * // => [1, 2]
|
54121 | */
|
54122 | function property(path) {
|
54123 | return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
|
54124 | }
|
54125 |
|
54126 | module.exports = property;
|
54127 |
|
54128 | },{"./_baseProperty":416,"./_basePropertyDeep":417,"./_isKey":449,"./_toKey":485}],510:[function(require,module,exports){
|
54129 | /**
|
54130 | * This method returns a new empty array.
|
54131 | *
|
54132 | * @static
|
54133 | * @memberOf _
|
54134 | * @since 4.13.0
|
54135 | * @category Util
|
54136 | * @returns {Array} Returns the new empty array.
|
54137 | * @example
|
54138 | *
|
54139 | * var arrays = _.times(2, _.stubArray);
|
54140 | *
|
54141 | * console.log(arrays);
|
54142 | * // => [[], []]
|
54143 | *
|
54144 | * console.log(arrays[0] === arrays[1]);
|
54145 | * // => false
|
54146 | */
|
54147 | function stubArray() {
|
54148 | return [];
|
54149 | }
|
54150 |
|
54151 | module.exports = stubArray;
|
54152 |
|
54153 | },{}],511:[function(require,module,exports){
|
54154 | /**
|
54155 | * This method returns `false`.
|
54156 | *
|
54157 | * @static
|
54158 | * @memberOf _
|
54159 | * @since 4.13.0
|
54160 | * @category Util
|
54161 | * @returns {boolean} Returns `false`.
|
54162 | * @example
|
54163 | *
|
54164 | * _.times(2, _.stubFalse);
|
54165 | * // => [false, false]
|
54166 | */
|
54167 | function stubFalse() {
|
54168 | return false;
|
54169 | }
|
54170 |
|
54171 | module.exports = stubFalse;
|
54172 |
|
54173 | },{}],512:[function(require,module,exports){
|
54174 | var toNumber = require('./toNumber');
|
54175 |
|
54176 | /** Used as references for various `Number` constants. */
|
54177 | var INFINITY = 1 / 0,
|
54178 | MAX_INTEGER = 1.7976931348623157e+308;
|
54179 |
|
54180 | /**
|
54181 | * Converts `value` to a finite number.
|
54182 | *
|
54183 | * @static
|
54184 | * @memberOf _
|
54185 | * @since 4.12.0
|
54186 | * @category Lang
|
54187 | * @param {*} value The value to convert.
|
54188 | * @returns {number} Returns the converted number.
|
54189 | * @example
|
54190 | *
|
54191 | * _.toFinite(3.2);
|
54192 | * // => 3.2
|
54193 | *
|
54194 | * _.toFinite(Number.MIN_VALUE);
|
54195 | * // => 5e-324
|
54196 | *
|
54197 | * _.toFinite(Infinity);
|
54198 | * // => 1.7976931348623157e+308
|
54199 | *
|
54200 | * _.toFinite('3.2');
|
54201 | * // => 3.2
|
54202 | */
|
54203 | function toFinite(value) {
|
54204 | if (!value) {
|
54205 | return value === 0 ? value : 0;
|
54206 | }
|
54207 | value = toNumber(value);
|
54208 | if (value === INFINITY || value === -INFINITY) {
|
54209 | var sign = (value < 0 ? -1 : 1);
|
54210 | return sign * MAX_INTEGER;
|
54211 | }
|
54212 | return value === value ? value : 0;
|
54213 | }
|
54214 |
|
54215 | module.exports = toFinite;
|
54216 |
|
54217 | },{"./toNumber":514}],513:[function(require,module,exports){
|
54218 | var toFinite = require('./toFinite');
|
54219 |
|
54220 | /**
|
54221 | * Converts `value` to an integer.
|
54222 | *
|
54223 | * **Note:** This method is loosely based on
|
54224 | * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
|
54225 | *
|
54226 | * @static
|
54227 | * @memberOf _
|
54228 | * @since 4.0.0
|
54229 | * @category Lang
|
54230 | * @param {*} value The value to convert.
|
54231 | * @returns {number} Returns the converted integer.
|
54232 | * @example
|
54233 | *
|
54234 | * _.toInteger(3.2);
|
54235 | * // => 3
|
54236 | *
|
54237 | * _.toInteger(Number.MIN_VALUE);
|
54238 | * // => 0
|
54239 | *
|
54240 | * _.toInteger(Infinity);
|
54241 | * // => 1.7976931348623157e+308
|
54242 | *
|
54243 | * _.toInteger('3.2');
|
54244 | * // => 3
|
54245 | */
|
54246 | function toInteger(value) {
|
54247 | var result = toFinite(value),
|
54248 | remainder = result % 1;
|
54249 |
|
54250 | return result === result ? (remainder ? result - remainder : result) : 0;
|
54251 | }
|
54252 |
|
54253 | module.exports = toInteger;
|
54254 |
|
54255 | },{"./toFinite":512}],514:[function(require,module,exports){
|
54256 | var isObject = require('./isObject'),
|
54257 | isSymbol = require('./isSymbol');
|
54258 |
|
54259 | /** Used as references for various `Number` constants. */
|
54260 | var NAN = 0 / 0;
|
54261 |
|
54262 | /** Used to match leading and trailing whitespace. */
|
54263 | var reTrim = /^\s+|\s+$/g;
|
54264 |
|
54265 | /** Used to detect bad signed hexadecimal string values. */
|
54266 | var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
54267 |
|
54268 | /** Used to detect binary string values. */
|
54269 | var reIsBinary = /^0b[01]+$/i;
|
54270 |
|
54271 | /** Used to detect octal string values. */
|
54272 | var reIsOctal = /^0o[0-7]+$/i;
|
54273 |
|
54274 | /** Built-in method references without a dependency on `root`. */
|
54275 | var freeParseInt = parseInt;
|
54276 |
|
54277 | /**
|
54278 | * Converts `value` to a number.
|
54279 | *
|
54280 | * @static
|
54281 | * @memberOf _
|
54282 | * @since 4.0.0
|
54283 | * @category Lang
|
54284 | * @param {*} value The value to process.
|
54285 | * @returns {number} Returns the number.
|
54286 | * @example
|
54287 | *
|
54288 | * _.toNumber(3.2);
|
54289 | * // => 3.2
|
54290 | *
|
54291 | * _.toNumber(Number.MIN_VALUE);
|
54292 | * // => 5e-324
|
54293 | *
|
54294 | * _.toNumber(Infinity);
|
54295 | * // => Infinity
|
54296 | *
|
54297 | * _.toNumber('3.2');
|
54298 | * // => 3.2
|
54299 | */
|
54300 | function toNumber(value) {
|
54301 | if (typeof value == 'number') {
|
54302 | return value;
|
54303 | }
|
54304 | if (isSymbol(value)) {
|
54305 | return NAN;
|
54306 | }
|
54307 | if (isObject(value)) {
|
54308 | var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
|
54309 | value = isObject(other) ? (other + '') : other;
|
54310 | }
|
54311 | if (typeof value != 'string') {
|
54312 | return value === 0 ? value : +value;
|
54313 | }
|
54314 | value = value.replace(reTrim, '');
|
54315 | var isBinary = reIsBinary.test(value);
|
54316 | return (isBinary || reIsOctal.test(value))
|
54317 | ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
54318 | : (reIsBadHex.test(value) ? NAN : +value);
|
54319 | }
|
54320 |
|
54321 | module.exports = toNumber;
|
54322 |
|
54323 | },{"./isObject":502,"./isSymbol":504}],515:[function(require,module,exports){
|
54324 | var baseToString = require('./_baseToString');
|
54325 |
|
54326 | /**
|
54327 | * Converts `value` to a string. An empty string is returned for `null`
|
54328 | * and `undefined` values. The sign of `-0` is preserved.
|
54329 | *
|
54330 | * @static
|
54331 | * @memberOf _
|
54332 | * @since 4.0.0
|
54333 | * @category Lang
|
54334 | * @param {*} value The value to convert.
|
54335 | * @returns {string} Returns the converted string.
|
54336 | * @example
|
54337 | *
|
54338 | * _.toString(null);
|
54339 | * // => ''
|
54340 | *
|
54341 | * _.toString(-0);
|
54342 | * // => '-0'
|
54343 | *
|
54344 | * _.toString([1, 2, 3]);
|
54345 | * // => '1,2,3'
|
54346 | */
|
54347 | function toString(value) {
|
54348 | return value == null ? '' : baseToString(value);
|
54349 | }
|
54350 |
|
54351 | module.exports = toString;
|
54352 |
|
54353 | },{"./_baseToString":421}],516:[function(require,module,exports){
|
54354 | /**
|
54355 | * Helpers.
|
54356 | */
|
54357 |
|
54358 | var s = 1000;
|
54359 | var m = s * 60;
|
54360 | var h = m * 60;
|
54361 | var d = h * 24;
|
54362 | var y = d * 365.25;
|
54363 |
|
54364 | /**
|
54365 | * Parse or format the given `val`.
|
54366 | *
|
54367 | * Options:
|
54368 | *
|
54369 | * - `long` verbose formatting [false]
|
54370 | *
|
54371 | * @param {String|Number} val
|
54372 | * @param {Object} [options]
|
54373 | * @throws {Error} throw an error if val is not a non-empty string or a number
|
54374 | * @return {String|Number}
|
54375 | * @api public
|
54376 | */
|
54377 |
|
54378 | module.exports = function(val, options) {
|
54379 | options = options || {};
|
54380 | var type = typeof val;
|
54381 | if (type === 'string' && val.length > 0) {
|
54382 | return parse(val);
|
54383 | } else if (type === 'number' && isNaN(val) === false) {
|
54384 | return options.long ? fmtLong(val) : fmtShort(val);
|
54385 | }
|
54386 | throw new Error(
|
54387 | 'val is not a non-empty string or a valid number. val=' +
|
54388 | JSON.stringify(val)
|
54389 | );
|
54390 | };
|
54391 |
|
54392 | /**
|
54393 | * Parse the given `str` and return milliseconds.
|
54394 | *
|
54395 | * @param {String} str
|
54396 | * @return {Number}
|
54397 | * @api private
|
54398 | */
|
54399 |
|
54400 | function parse(str) {
|
54401 | str = String(str);
|
54402 | if (str.length > 100) {
|
54403 | return;
|
54404 | }
|
54405 | var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
|
54406 | str
|
54407 | );
|
54408 | if (!match) {
|
54409 | return;
|
54410 | }
|
54411 | var n = parseFloat(match[1]);
|
54412 | var type = (match[2] || 'ms').toLowerCase();
|
54413 | switch (type) {
|
54414 | case 'years':
|
54415 | case 'year':
|
54416 | case 'yrs':
|
54417 | case 'yr':
|
54418 | case 'y':
|
54419 | return n * y;
|
54420 | case 'days':
|
54421 | case 'day':
|
54422 | case 'd':
|
54423 | return n * d;
|
54424 | case 'hours':
|
54425 | case 'hour':
|
54426 | case 'hrs':
|
54427 | case 'hr':
|
54428 | case 'h':
|
54429 | return n * h;
|
54430 | case 'minutes':
|
54431 | case 'minute':
|
54432 | case 'mins':
|
54433 | case 'min':
|
54434 | case 'm':
|
54435 | return n * m;
|
54436 | case 'seconds':
|
54437 | case 'second':
|
54438 | case 'secs':
|
54439 | case 'sec':
|
54440 | case 's':
|
54441 | return n * s;
|
54442 | case 'milliseconds':
|
54443 | case 'millisecond':
|
54444 | case 'msecs':
|
54445 | case 'msec':
|
54446 | case 'ms':
|
54447 | return n;
|
54448 | default:
|
54449 | return undefined;
|
54450 | }
|
54451 | }
|
54452 |
|
54453 | /**
|
54454 | * Short format for `ms`.
|
54455 | *
|
54456 | * @param {Number} ms
|
54457 | * @return {String}
|
54458 | * @api private
|
54459 | */
|
54460 |
|
54461 | function fmtShort(ms) {
|
54462 | if (ms >= d) {
|
54463 | return Math.round(ms / d) + 'd';
|
54464 | }
|
54465 | if (ms >= h) {
|
54466 | return Math.round(ms / h) + 'h';
|
54467 | }
|
54468 | if (ms >= m) {
|
54469 | return Math.round(ms / m) + 'm';
|
54470 | }
|
54471 | if (ms >= s) {
|
54472 | return Math.round(ms / s) + 's';
|
54473 | }
|
54474 | return ms + 'ms';
|
54475 | }
|
54476 |
|
54477 | /**
|
54478 | * Long format for `ms`.
|
54479 | *
|
54480 | * @param {Number} ms
|
54481 | * @return {String}
|
54482 | * @api private
|
54483 | */
|
54484 |
|
54485 | function fmtLong(ms) {
|
54486 | return plural(ms, d, 'day') ||
|
54487 | plural(ms, h, 'hour') ||
|
54488 | plural(ms, m, 'minute') ||
|
54489 | plural(ms, s, 'second') ||
|
54490 | ms + ' ms';
|
54491 | }
|
54492 |
|
54493 | /**
|
54494 | * Pluralization helper.
|
54495 | */
|
54496 |
|
54497 | function plural(ms, n, name) {
|
54498 | if (ms < n) {
|
54499 | return;
|
54500 | }
|
54501 | if (ms < n * 1.5) {
|
54502 | return Math.floor(ms / n) + ' ' + name;
|
54503 | }
|
54504 | return Math.ceil(ms / n) + ' ' + name + 's';
|
54505 | }
|
54506 |
|
54507 | },{}],517:[function(require,module,exports){
|
54508 | var toString = Object.prototype.toString
|
54509 |
|
54510 | module.exports = function(val){
|
54511 | switch (toString.call(val)) {
|
54512 | case '[object Function]': return 'function'
|
54513 | case '[object Date]': return 'date'
|
54514 | case '[object RegExp]': return 'regexp'
|
54515 | case '[object Arguments]': return 'arguments'
|
54516 | case '[object Array]': return 'array'
|
54517 | case '[object String]': return 'string'
|
54518 | }
|
54519 |
|
54520 | if (typeof val == 'object' && val && typeof val.length == 'number') {
|
54521 | try {
|
54522 | if (typeof val.callee == 'function') return 'arguments';
|
54523 | } catch (ex) {
|
54524 | if (ex instanceof TypeError) {
|
54525 | return 'arguments';
|
54526 | }
|
54527 | }
|
54528 | }
|
54529 |
|
54530 | if (val === null) return 'null'
|
54531 | if (val === undefined) return 'undefined'
|
54532 | if (val && val.nodeType === 1) return 'element'
|
54533 | if (val === Object(val)) return 'object'
|
54534 |
|
54535 | return typeof val
|
54536 | }
|
54537 |
|
54538 | },{}]},{},[1]);
|