jsoneditor-rails 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6163c46a3fb59a4fcb76589122912265e4b3ef1b9e0d4e48c5baa36f7b56eb34
4
- data.tar.gz: f344b862fb8a83b0d1c875e90ade7a9dd5a284f7147ffb0a896fdfe2c52651b8
3
+ metadata.gz: 1b1f64b68e6fe24fd9e7b5cb600dd2289b8a05d14db957eb3844661c012e9d50
4
+ data.tar.gz: d55f4e5c69896922118ec5072adfa9332f4c40cc41f35c2a0c8bd5064c332c5c
5
5
  SHA512:
6
- metadata.gz: d380a77d5b140f28bb928cb37c0585f4ccd554d7483b69a684387a81b4baf6d187157de3dfca4eff4c06a63eac5102a3ae5186ddfd19c61b9ecc2c7bb79efa61
7
- data.tar.gz: 4e628a164b14da4f8fc04d9ad0e163768be8bb61dc3a52c335bedd1677b8e7e3fa96aea34012b0b9c91e55d9c6b35b07f85509afb8b6bccbc3196dafb5e77a7c
6
+ metadata.gz: ff175b3f9a234a5016ef93e0a570bf41192ba517568cce22ccb478f1821b683dfa96e949665c11411b99526cd9e3dc4676e697030759df526ad7c63766d95351
7
+ data.tar.gz: fc2923853f7dea9b731b3d01a4ba019e7e5d20edf172f879b12a9651477167544bf4997e4850cb0987f5a446fd3878e4ce164766432f20e4941df8588a184334
@@ -1,3 +1,7 @@
1
+ ## 1.0.3 (2018-12-07)
2
+
3
+ * Updated jsoneditor to version 5.26.3 ([#5](../../pull/5))
4
+
1
5
  ## 1.0.2 (2018-09-14)
2
6
 
3
7
  * Updated jsoneditor to version 5.24.6 ([#4](../../pull/4))
@@ -1,5 +1,5 @@
1
1
  module Jsoneditor
2
2
  module Rails
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
@@ -21,11 +21,11 @@
21
21
  * License for the specific language governing permissions and limitations under
22
22
  * the License.
23
23
  *
24
- * Copyright (c) 2011-2017 Jos de Jong, http://jsoneditoronline.org
24
+ * Copyright (c) 2011-2018 Jos de Jong, http://jsoneditoronline.org
25
25
  *
26
26
  * @author Jos de Jong, <wjosdejong@gmail.com>
27
- * @version 5.24.6
28
- * @date 2018-09-12
27
+ * @version 5.26.3
28
+ * @date 2018-12-06
29
29
  */
30
30
  (function webpackUniversalModuleDefinition(root, factory) {
31
31
  if(typeof exports === 'object' && typeof module === 'object')
@@ -252,7 +252,7 @@ return /******/ (function(modules) { // webpackBootstrap
252
252
  'colorPicker', 'onColorPicker',
253
253
  'timestampTag',
254
254
  'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation',
255
- 'sortObjectKeys', 'navigationBar', 'statusBar', 'languages', 'language'
255
+ 'sortObjectKeys', 'navigationBar', 'statusBar', 'mainMenuBar', 'languages', 'language', 'enableSort', 'enableTransform'
256
256
  ];
257
257
 
258
258
  /**
@@ -1580,8 +1580,6 @@ return /******/ (function(modules) { // webpackBootstrap
1580
1580
  * @private
1581
1581
  */
1582
1582
  treemode._setOptions = function (options) {
1583
- var editor = this;
1584
-
1585
1583
  this.options = {
1586
1584
  search: true,
1587
1585
  history: true,
@@ -1591,6 +1589,7 @@ return /******/ (function(modules) { // webpackBootstrap
1591
1589
  schemaRefs: null,
1592
1590
  autocomplete: null,
1593
1591
  navigationBar : true,
1592
+ mainMenuBar: true,
1594
1593
  onSelectionChange: null,
1595
1594
  colorPicker: true,
1596
1595
  onColorPicker: function (parent, color, onChange) {
@@ -1600,11 +1599,11 @@ return /******/ (function(modules) { // webpackBootstrap
1600
1599
  color: color,
1601
1600
  popup: 'bottom',
1602
1601
  onDone: function (color) {
1603
- var alpha = color.rgba[3]
1602
+ var alpha = color.rgba[3];
1604
1603
  var hex = (alpha === 1)
1605
1604
  ? color.hex.substr(0, 7) // return #RRGGBB
1606
- : color.hex // return #RRGGBBAA
1607
- onChange(hex)
1605
+ : color.hex; // return #RRGGBBAA
1606
+ onChange(hex);
1608
1607
  }
1609
1608
  }).show();
1610
1609
  }
@@ -1614,7 +1613,9 @@ return /******/ (function(modules) { // webpackBootstrap
1614
1613
  }
1615
1614
  },
1616
1615
  timestampTag: true,
1617
- onEvent: null
1616
+ onEvent: null,
1617
+ enableSort: true,
1618
+ enableTransform: true
1618
1619
  };
1619
1620
 
1620
1621
  // copy all options
@@ -1949,9 +1950,27 @@ return /******/ (function(modules) { // webpackBootstrap
1949
1950
  return;
1950
1951
  }
1951
1952
 
1953
+ // selection can be changed after undo/redo
1954
+ this.selection = this.getDomSelection();
1955
+
1952
1956
  // validate JSON schema (if configured)
1953
1957
  this._debouncedValidate();
1954
1958
 
1959
+ if (this.treePath) {
1960
+ var selectedNode = this.selection
1961
+ ? this.node.findNodeByInternalPath(this.selection.path)
1962
+ : this.multiselection
1963
+ ? this.multiselection.nodes[0]
1964
+ : undefined;
1965
+
1966
+ if (selectedNode) {
1967
+ this._updateTreePath(selectedNode.getNodePath())
1968
+ }
1969
+ else {
1970
+ this.treePath.reset()
1971
+ }
1972
+ }
1973
+
1955
1974
  // trigger the onChange callback
1956
1975
  if (this.options.onChange) {
1957
1976
  try {
@@ -2373,6 +2392,9 @@ return /******/ (function(modules) { // webpackBootstrap
2373
2392
  this.frame.className = 'jsoneditor jsoneditor-mode-' + this.options.mode;
2374
2393
  this.container.appendChild(this.frame);
2375
2394
 
2395
+ this.contentOuter = document.createElement('div');
2396
+ this.contentOuter.className = 'jsoneditor-outer';
2397
+
2376
2398
  // create one global event listener to handle all events from all nodes
2377
2399
  var editor = this;
2378
2400
  function onEvent(event) {
@@ -2411,107 +2433,115 @@ return /******/ (function(modules) { // webpackBootstrap
2411
2433
  this.frame.onfocusin = onEvent; // for IE
2412
2434
  this.frame.onfocusout = onEvent; // for IE
2413
2435
 
2414
- // create menu
2415
- this.menu = document.createElement('div');
2416
- this.menu.className = 'jsoneditor-menu';
2417
- this.frame.appendChild(this.menu);
2418
-
2419
- // create expand all button
2420
- var expandAll = document.createElement('button');
2421
- expandAll.type = 'button';
2422
- expandAll.className = 'jsoneditor-expand-all';
2423
- expandAll.title = translate('expandAll');
2424
- expandAll.onclick = function () {
2425
- editor.expandAll();
2426
- };
2427
- this.menu.appendChild(expandAll);
2428
-
2429
- // create collapse all button
2430
- var collapseAll = document.createElement('button');
2431
- collapseAll.type = 'button';
2432
- collapseAll.title = translate('collapseAll');
2433
- collapseAll.className = 'jsoneditor-collapse-all';
2434
- collapseAll.onclick = function () {
2435
- editor.collapseAll();
2436
- };
2437
- this.menu.appendChild(collapseAll);
2438
-
2439
- // create sort button
2440
- var sort = document.createElement('button');
2441
- sort.type = 'button';
2442
- sort.className = 'jsoneditor-sort';
2443
- sort.title = translate('sortTitleShort');
2444
- sort.onclick = function () {
2445
- var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
2446
- showSortModal(editor.node, anchor)
2447
- };
2448
- this.menu.appendChild(sort);
2449
-
2450
- // create transform button
2451
- var transform = document.createElement('button');
2452
- transform.type = 'button';
2453
- transform.title = translate('transformTitleShort');
2454
- transform.className = 'jsoneditor-transform';
2455
- transform.onclick = function () {
2456
- var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
2457
- showTransformModal(editor.node, anchor)
2458
- };
2459
- this.menu.appendChild(transform);
2460
-
2461
- // create undo/redo buttons
2462
- if (this.history) {
2463
- // create undo button
2464
- var undo = document.createElement('button');
2465
- undo.type = 'button';
2466
- undo.className = 'jsoneditor-undo jsoneditor-separator';
2467
- undo.title = translate('undo');
2468
- undo.onclick = function () {
2469
- editor._onUndo();
2436
+ if (this.options.mainMenuBar) {
2437
+ util.addClassName(this.contentOuter, 'has-main-menu-bar');
2438
+
2439
+ // create menu
2440
+ this.menu = document.createElement('div');
2441
+ this.menu.className = 'jsoneditor-menu';
2442
+ this.frame.appendChild(this.menu);
2443
+
2444
+ // create expand all button
2445
+ var expandAll = document.createElement('button');
2446
+ expandAll.type = 'button';
2447
+ expandAll.className = 'jsoneditor-expand-all';
2448
+ expandAll.title = translate('expandAll');
2449
+ expandAll.onclick = function () {
2450
+ editor.expandAll();
2470
2451
  };
2471
- this.menu.appendChild(undo);
2472
- this.dom.undo = undo;
2473
-
2474
- // create redo button
2475
- var redo = document.createElement('button');
2476
- redo.type = 'button';
2477
- redo.className = 'jsoneditor-redo';
2478
- redo.title = translate('redo');
2479
- redo.onclick = function () {
2480
- editor._onRedo();
2452
+ this.menu.appendChild(expandAll);
2453
+
2454
+ // create collapse all button
2455
+ var collapseAll = document.createElement('button');
2456
+ collapseAll.type = 'button';
2457
+ collapseAll.title = translate('collapseAll');
2458
+ collapseAll.className = 'jsoneditor-collapse-all';
2459
+ collapseAll.onclick = function () {
2460
+ editor.collapseAll();
2481
2461
  };
2482
- this.menu.appendChild(redo);
2483
- this.dom.redo = redo;
2462
+ this.menu.appendChild(collapseAll);
2463
+
2464
+ // create sort button
2465
+ if (this.options.enableSort) {
2466
+ var sort = document.createElement('button');
2467
+ sort.type = 'button';
2468
+ sort.className = 'jsoneditor-sort';
2469
+ sort.title = translate('sortTitleShort');
2470
+ sort.onclick = function () {
2471
+ var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
2472
+ showSortModal(editor.node, anchor)
2473
+ };
2474
+ this.menu.appendChild(sort);
2475
+ }
2476
+
2477
+ // create transform button
2478
+ if (this.options.enableTransform) {
2479
+ var transform = document.createElement('button');
2480
+ transform.type = 'button';
2481
+ transform.title = translate('transformTitleShort');
2482
+ transform.className = 'jsoneditor-transform';
2483
+ transform.onclick = function () {
2484
+ var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
2485
+ showTransformModal(editor.node, anchor)
2486
+ };
2487
+ this.menu.appendChild(transform);
2488
+ }
2489
+
2490
+ // create undo/redo buttons
2491
+ if (this.history) {
2492
+ // create undo button
2493
+ var undo = document.createElement('button');
2494
+ undo.type = 'button';
2495
+ undo.className = 'jsoneditor-undo jsoneditor-separator';
2496
+ undo.title = translate('undo');
2497
+ undo.onclick = function () {
2498
+ editor._onUndo();
2499
+ };
2500
+ this.menu.appendChild(undo);
2501
+ this.dom.undo = undo;
2502
+
2503
+ // create redo button
2504
+ var redo = document.createElement('button');
2505
+ redo.type = 'button';
2506
+ redo.className = 'jsoneditor-redo';
2507
+ redo.title = translate('redo');
2508
+ redo.onclick = function () {
2509
+ editor._onRedo();
2510
+ };
2511
+ this.menu.appendChild(redo);
2512
+ this.dom.redo = redo;
2484
2513
 
2485
- // register handler for onchange of history
2486
- this.history.onChange = function () {
2487
- undo.disabled = !editor.history.canUndo();
2488
- redo.disabled = !editor.history.canRedo();
2489
- };
2490
- this.history.onChange();
2491
- }
2514
+ // register handler for onchange of history
2515
+ this.history.onChange = function () {
2516
+ undo.disabled = !editor.history.canUndo();
2517
+ redo.disabled = !editor.history.canRedo();
2518
+ };
2519
+ this.history.onChange();
2520
+ }
2492
2521
 
2493
- // create mode box
2494
- if (this.options && this.options.modes && this.options.modes.length) {
2495
- var me = this;
2496
- this.modeSwitcher = new ModeSwitcher(this.menu, this.options.modes, this.options.mode, function onSwitch(mode) {
2497
- // switch mode and restore focus
2498
- me.setMode(mode);
2499
- me.modeSwitcher.focus();
2500
- });
2501
- }
2522
+ // create mode box
2523
+ if (this.options && this.options.modes && this.options.modes.length) {
2524
+ var me = this;
2525
+ this.modeSwitcher = new ModeSwitcher(this.menu, this.options.modes, this.options.mode, function onSwitch(mode) {
2526
+ // switch mode and restore focus
2527
+ me.setMode(mode);
2528
+ me.modeSwitcher.focus();
2529
+ });
2530
+ }
2502
2531
 
2503
- // create search box
2504
- if (this.options.search) {
2505
- this.searchBox = new SearchBox(this, this.menu);
2532
+ // create search box
2533
+ if (this.options.search) {
2534
+ this.searchBox = new SearchBox(this, this.menu);
2535
+ }
2506
2536
  }
2507
2537
 
2508
- if(this.options.navigationBar) {
2538
+ if (this.options.navigationBar) {
2509
2539
  // create second menu row for treepath
2510
2540
  this.navBar = document.createElement('div');
2511
2541
  this.navBar.className = 'jsoneditor-navigation-bar nav-bar-empty';
2512
2542
  this.frame.appendChild(this.navBar);
2513
2543
 
2514
- this.treePath = new TreePath(this.navBar);
2544
+ this.treePath = new TreePath(this.navBar, this.frame);
2515
2545
  this.treePath.onSectionSelected(this._onTreePathSectionSelected.bind(this));
2516
2546
  this.treePath.onContextMenuItemSelected(this._onTreePathMenuItemSelected.bind(this));
2517
2547
  }
@@ -2602,7 +2632,8 @@ return /******/ (function(modules) { // webpackBootstrap
2602
2632
  }
2603
2633
  }
2604
2634
  else {
2605
- if (event.type === 'mousedown') {
2635
+ // filter mouse events in the contents part of the editor (not the main menu)
2636
+ if (event.type === 'mousedown' && util.hasParentNode(event.target, this.content)) {
2606
2637
  this.deselect();
2607
2638
 
2608
2639
  if (node && event.target === node.dom.drag) {
@@ -2636,7 +2667,7 @@ return /******/ (function(modules) { // webpackBootstrap
2636
2667
  name: getName(node),
2637
2668
  node: node,
2638
2669
  children: []
2639
- }
2670
+ };
2640
2671
  if (node.childs && node.childs.length) {
2641
2672
  node.childs.forEach(function (childNode) {
2642
2673
  pathObj.children.push({
@@ -2752,6 +2783,7 @@ return /******/ (function(modules) { // webpackBootstrap
2752
2783
  });
2753
2784
  }
2754
2785
 
2786
+ event.preventDefault();
2755
2787
  };
2756
2788
 
2757
2789
  /**
@@ -2799,10 +2831,9 @@ return /******/ (function(modules) { // webpackBootstrap
2799
2831
 
2800
2832
  /**
2801
2833
  * End of multiselect nodes by dragging
2802
- * @param event
2803
2834
  * @private
2804
2835
  */
2805
- treemode._onMultiSelectEnd = function (event) {
2836
+ treemode._onMultiSelectEnd = function () {
2806
2837
  // set focus to the context menu button of the first node
2807
2838
  if (this.multiselection.nodes[0]) {
2808
2839
  this.multiselection.nodes[0].dom.menu.focus();
@@ -3026,16 +3057,13 @@ return /******/ (function(modules) { // webpackBootstrap
3026
3057
  * @private
3027
3058
  */
3028
3059
  treemode._createTable = function () {
3029
- var contentOuter = document.createElement('div');
3030
- contentOuter.className = 'jsoneditor-outer';
3031
- if(this.options.navigationBar) {
3032
- util.addClassName(contentOuter, 'has-nav-bar');
3060
+ if (this.options.navigationBar) {
3061
+ util.addClassName(this.contentOuter, 'has-nav-bar');
3033
3062
  }
3034
- this.contentOuter = contentOuter;
3035
3063
 
3036
3064
  this.scrollableContent = document.createElement('div');
3037
3065
  this.scrollableContent.className = 'jsoneditor-tree';
3038
- contentOuter.appendChild(this.scrollableContent);
3066
+ this.contentOuter.appendChild(this.scrollableContent);
3039
3067
 
3040
3068
  // the jsoneditor-tree-inner div with bottom padding is here to
3041
3069
  // keep space for the action menu dropdown. It's created as a
@@ -3069,7 +3097,7 @@ return /******/ (function(modules) { // webpackBootstrap
3069
3097
  this.tbody = document.createElement('tbody');
3070
3098
  this.table.appendChild(this.tbody);
3071
3099
 
3072
- this.frame.appendChild(contentOuter);
3100
+ this.frame.appendChild(this.contentOuter);
3073
3101
  };
3074
3102
 
3075
3103
  /**
@@ -3081,7 +3109,7 @@ return /******/ (function(modules) { // webpackBootstrap
3081
3109
  */
3082
3110
  treemode.showContextMenu = function (anchor, onClose) {
3083
3111
  var items = [];
3084
- var editor = this;
3112
+ var selectedNodes = this.multiselection.nodes.slice();
3085
3113
 
3086
3114
  // create duplicate button
3087
3115
  items.push({
@@ -3089,7 +3117,7 @@ return /******/ (function(modules) { // webpackBootstrap
3089
3117
  title: translate('duplicateTitle'),
3090
3118
  className: 'jsoneditor-duplicate',
3091
3119
  click: function () {
3092
- Node.onDuplicate(editor.multiselection.nodes);
3120
+ Node.onDuplicate(selectedNodes );
3093
3121
  }
3094
3122
  });
3095
3123
 
@@ -3099,12 +3127,12 @@ return /******/ (function(modules) { // webpackBootstrap
3099
3127
  title: translate('removeTitle'),
3100
3128
  className: 'jsoneditor-remove',
3101
3129
  click: function () {
3102
- Node.onRemove(editor.multiselection.nodes);
3130
+ Node.onRemove(selectedNodes);
3103
3131
  }
3104
3132
  });
3105
3133
 
3106
3134
  var menu = new ContextMenu(items, {close: onClose});
3107
- menu.show(anchor, editor.frame);
3135
+ menu.show(anchor, this.frame);
3108
3136
  };
3109
3137
 
3110
3138
  /**
@@ -3133,12 +3161,10 @@ return /******/ (function(modules) { // webpackBootstrap
3133
3161
  };
3134
3162
 
3135
3163
  /**
3136
- * Callback registraion for selection change
3164
+ * Callback registration for selection change
3137
3165
  * @param {selectionCallback} callback
3138
3166
  *
3139
3167
  * @callback selectionCallback
3140
- * @param {SerializableNode=} start
3141
- * @param {SerializableNode=} end
3142
3168
  */
3143
3169
  treemode.onSelectionChange = function (callback) {
3144
3170
  if (typeof callback === 'function') {
@@ -3157,7 +3183,7 @@ return /******/ (function(modules) { // webpackBootstrap
3157
3183
  treemode.setSelection = function (start, end) {
3158
3184
  // check for old usage
3159
3185
  if (start && start.dom && start.range) {
3160
- console.warn('setSelection/getSelection usage for text selection is depracated and should not be used, see documantaion for supported selection options');
3186
+ console.warn('setSelection/getSelection usage for text selection is deprecated and should not be used, see documentation for supported selection options');
3161
3187
  this.setDomSelection(start);
3162
3188
  }
3163
3189
 
@@ -3173,7 +3199,7 @@ return /******/ (function(modules) { // webpackBootstrap
3173
3199
  * Returns a set of Nodes according to a range of selection
3174
3200
  * @param {{path: Array.<String>}} start object contains the path for range start
3175
3201
  * @param {{path: Array.<String>}=} end object contains the path for range end
3176
- * @return {Array.<Node>} Node intances on the given range
3202
+ * @return {Array.<Node>} Node instances on the given range
3177
3203
  * @private
3178
3204
  */
3179
3205
  treemode._getNodeInstancesByRange = function (start, end) {
@@ -4632,13 +4658,17 @@ return /******/ (function(modules) { // webpackBootstrap
4632
4658
  function next() { return jsString.charAt(i + 1); }
4633
4659
  function prev() { return jsString.charAt(i - 1); }
4634
4660
 
4661
+ function isWhiteSpace(c) {
4662
+ return c === ' ' || c === '\n' || c === '\r' || c === '\t';
4663
+ }
4664
+
4635
4665
  // get the last parsed non-whitespace character
4636
4666
  function lastNonWhitespace () {
4637
4667
  var p = chars.length - 1;
4638
4668
 
4639
4669
  while (p >= 0) {
4640
4670
  var pp = chars[p];
4641
- if (pp !== ' ' && pp !== '\n' && pp !== '\r' && pp !== '\t') { // non whitespace
4671
+ if (!isWhiteSpace(pp)) {
4642
4672
  return pp;
4643
4673
  }
4644
4674
  p--;
@@ -4647,6 +4677,16 @@ return /******/ (function(modules) { // webpackBootstrap
4647
4677
  return '';
4648
4678
  }
4649
4679
 
4680
+ // get at the first next non-white space character
4681
+ function nextNonWhiteSpace() {
4682
+ var iNext = i + 1;
4683
+ while (iNext < jsString.length && isWhiteSpace(jsString[iNext])) {
4684
+ iNext++;
4685
+ }
4686
+
4687
+ return jsString[iNext];
4688
+ }
4689
+
4650
4690
  // skip a block comment '/* ... */'
4651
4691
  function skipBlockComment () {
4652
4692
  i += 2;
@@ -4733,7 +4773,7 @@ return /******/ (function(modules) { // webpackBootstrap
4733
4773
  }
4734
4774
  else if (c === '\u00A0' || (c >= '\u2000' && c <= '\u200A') || c === '\u202F' || c === '\u205F' || c === '\u3000') {
4735
4775
  // special white spaces (like non breaking space)
4736
- chars.push(' ')
4776
+ chars.push(' ');
4737
4777
  i++
4738
4778
  }
4739
4779
  else if (c === quote) {
@@ -4751,6 +4791,10 @@ return /******/ (function(modules) { // webpackBootstrap
4751
4791
  else if (c === quoteDblLeft) {
4752
4792
  parseString(quoteDblRight);
4753
4793
  }
4794
+ else if (c === ',' && [']', '}'].indexOf(nextNonWhiteSpace()) !== -1) {
4795
+ // skip trailing commas
4796
+ i++;
4797
+ }
4754
4798
  else if (/[a-zA-Z_$]/.test(c) && ['{', ','].indexOf(lastNonWhitespace()) !== -1) {
4755
4799
  // an unquoted object key (like a in '{a:2}')
4756
4800
  parseKey();
@@ -5147,6 +5191,25 @@ return /******/ (function(modules) { // webpackBootstrap
5147
5191
  return '';
5148
5192
  };
5149
5193
 
5194
+ /**
5195
+ * Test whether an element has the provided parent node somewhere up the node tree.
5196
+ * @param {Element} elem
5197
+ * @param {Element} parent
5198
+ * @return {boolean}
5199
+ */
5200
+ exports.hasParentNode = function (elem, parent) {
5201
+ var e = elem ? elem.parentNode : undefined;
5202
+
5203
+ while (e) {
5204
+ if (e === parent) {
5205
+ return true;
5206
+ }
5207
+ e = e.parentNode;
5208
+ }
5209
+
5210
+ return false;
5211
+ }
5212
+
5150
5213
  /**
5151
5214
  * Returns the version of Internet Explorer or a -1
5152
5215
  * (indicating the use of another browser).
@@ -6714,10 +6777,12 @@ return /******/ (function(modules) { // webpackBootstrap
6714
6777
  /**
6715
6778
  * Creates a component that visualize path selection in tree based editors
6716
6779
  * @param {HTMLElement} container
6780
+ * @param {HTMLElement} root
6717
6781
  * @constructor
6718
6782
  */
6719
- function TreePath(container) {
6783
+ function TreePath(container, root) {
6720
6784
  if (container) {
6785
+ this.root = root;
6721
6786
  this.path = document.createElement('div');
6722
6787
  this.path.className = 'jsoneditor-treepath';
6723
6788
  container.appendChild(this.path);
@@ -6767,10 +6832,10 @@ return /******/ (function(modules) { // webpackBootstrap
6767
6832
  });
6768
6833
  });
6769
6834
  var menu = new ContextMenu(items);
6770
- menu.show(sepEl);
6835
+ menu.show(sepEl, me.root);
6771
6836
  };
6772
6837
 
6773
- me.path.appendChild(sepEl, me.container);
6838
+ me.path.appendChild(sepEl);
6774
6839
  }
6775
6840
 
6776
6841
  if(idx === pathObjs.length - 1) {
@@ -6967,7 +7032,7 @@ return /******/ (function(modules) { // webpackBootstrap
6967
7032
 
6968
7033
  /**
6969
7034
  * Find child node by serializable path
6970
- * @param {Array<String>} path
7035
+ * @param {Array<String>} path
6971
7036
  */
6972
7037
  Node.prototype.findNodeByPath = function (path) {
6973
7038
  if (!path) {
@@ -7009,7 +7074,7 @@ return /******/ (function(modules) { // webpackBootstrap
7009
7074
 
7010
7075
  /**
7011
7076
  * @typedef {{value: String|Object|Number|Boolean, path: Array.<String|Number>}} SerializableNode
7012
- *
7077
+ *
7013
7078
  * Returns serializable representation for the node
7014
7079
  * @return {SerializableNode}
7015
7080
  */
@@ -8219,7 +8284,7 @@ return /******/ (function(modules) { // webpackBootstrap
8219
8284
  this.childs = [];
8220
8285
  }
8221
8286
 
8222
- this.childs.forEach(function (child, index) {
8287
+ this.childs.forEach(function (child) {
8223
8288
  child.clearDom();
8224
8289
  delete child.index;
8225
8290
  child.fieldEditable = true;
@@ -8292,7 +8357,7 @@ return /******/ (function(modules) { // webpackBootstrap
8292
8357
  }
8293
8358
  }
8294
8359
  else if (this.type === 'object') {
8295
- if (typeof json !== 'object') {
8360
+ if (typeof json !== 'object' || !json) {
8296
8361
  return false;
8297
8362
  }
8298
8363
 
@@ -9339,7 +9404,7 @@ return /******/ (function(modules) { // webpackBootstrap
9339
9404
  //Locating the schema of the node and checking for any enum type
9340
9405
  if(this.editor && this.editor.options) {
9341
9406
  // find the part of the json schema matching this nodes path
9342
- this.schema = this.editor.options.schema
9407
+ this.schema = this.editor.options.schema
9343
9408
  ? Node._findSchema(this.editor.options.schema, this.getPath())
9344
9409
  : null;
9345
9410
  if (this.schema) {
@@ -9780,7 +9845,7 @@ return /******/ (function(modules) { // webpackBootstrap
9780
9845
  };
9781
9846
  // For leaf values, include value
9782
9847
  if (!this._hasChilds() &&element === this.dom.value) {
9783
- info.value = this.getValue();
9848
+ info.value = this.getValue();
9784
9849
  }
9785
9850
  this.editor.options.onEvent(info, event);
9786
9851
  }
@@ -10195,7 +10260,7 @@ return /******/ (function(modules) { // webpackBootstrap
10195
10260
  }
10196
10261
  });
10197
10262
  }
10198
- }
10263
+ };
10199
10264
 
10200
10265
  /**
10201
10266
  * Remove nodes
@@ -10693,7 +10758,7 @@ return /******/ (function(modules) { // webpackBootstrap
10693
10758
  }
10694
10759
 
10695
10760
  return false;
10696
- }
10761
+ };
10697
10762
 
10698
10763
  /**
10699
10764
  * Remove the focus of given nodes, and move the focus to the (a) node before,
@@ -10991,25 +11056,29 @@ return /******/ (function(modules) { // webpackBootstrap
10991
11056
  }
10992
11057
 
10993
11058
  if (this._hasChilds()) {
10994
- items.push({
10995
- text: translate('sort'),
10996
- title: translate('sortTitle', {type: this.type}),
10997
- className: 'jsoneditor-sort-asc',
10998
- click: function () {
10999
- var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
11000
- showSortModal(node, anchor)
11001
- }
11002
- });
11059
+ if (this.editor.options.enableSort) {
11060
+ items.push({
11061
+ text: translate('sort'),
11062
+ title: translate('sortTitle', {type: this.type}),
11063
+ className: 'jsoneditor-sort-asc',
11064
+ click: function () {
11065
+ var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
11066
+ showSortModal(node, anchor)
11067
+ }
11068
+ });
11069
+ }
11003
11070
 
11004
- items.push({
11005
- text: translate('transform'),
11006
- title: translate('transformTitle', {type: this.type}),
11007
- className: 'jsoneditor-transform',
11008
- click: function () {
11009
- var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
11010
- showTransformModal(node, anchor)
11011
- }
11012
- });
11071
+ if (this.editor.options.enableTransform) {
11072
+ items.push({
11073
+ text: translate('transform'),
11074
+ title: translate('transformTitle', {type: this.type}),
11075
+ className: 'jsoneditor-transform',
11076
+ click: function () {
11077
+ var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
11078
+ showTransformModal(node, anchor)
11079
+ }
11080
+ });
11081
+ }
11013
11082
  }
11014
11083
 
11015
11084
  if (this.parent && this.parent._hasChilds()) {
@@ -17213,10 +17282,13 @@ return /******/ (function(modules) { // webpackBootstrap
17213
17282
  // read options
17214
17283
  options = options || {};
17215
17284
 
17216
- if(typeof options.statusBar === 'undefined') {
17285
+ if (typeof options.statusBar === 'undefined') {
17217
17286
  options.statusBar = true;
17218
17287
  }
17219
17288
 
17289
+ // setting default for textmode
17290
+ options.mainMenuBar = options.mainMenuBar !== false;
17291
+
17220
17292
  this.options = options;
17221
17293
 
17222
17294
  // indentation
@@ -17280,67 +17352,89 @@ return /******/ (function(modules) { // webpackBootstrap
17280
17352
  this.frame.onkeydown = function (event) {
17281
17353
  me._onKeyDown(event);
17282
17354
  };
17283
-
17284
- // create menu
17285
- this.menu = document.createElement('div');
17286
- this.menu.className = 'jsoneditor-menu';
17287
- this.frame.appendChild(this.menu);
17288
-
17289
- // create format button
17290
- var buttonFormat = document.createElement('button');
17291
- buttonFormat.type = 'button';
17292
- buttonFormat.className = 'jsoneditor-format';
17293
- buttonFormat.title = 'Format JSON data, with proper indentation and line feeds (Ctrl+\\)';
17294
- this.menu.appendChild(buttonFormat);
17295
- buttonFormat.onclick = function () {
17296
- try {
17297
- me.format();
17298
- me._onChange();
17299
- }
17300
- catch (err) {
17301
- me._onError(err);
17302
- }
17303
- };
17304
17355
 
17305
- // create compact button
17306
- var buttonCompact = document.createElement('button');
17307
- buttonCompact.type = 'button';
17308
- buttonCompact.className = 'jsoneditor-compact';
17309
- buttonCompact.title = 'Compact JSON data, remove all whitespaces (Ctrl+Shift+\\)';
17310
- this.menu.appendChild(buttonCompact);
17311
- buttonCompact.onclick = function () {
17312
- try {
17313
- me.compact();
17314
- me._onChange();
17315
- }
17316
- catch (err) {
17317
- me._onError(err);
17318
- }
17319
- };
17356
+ this.content = document.createElement('div');
17357
+ this.content.className = 'jsoneditor-outer';
17320
17358
 
17321
- // create repair button
17322
- var buttonRepair = document.createElement('button');
17323
- buttonRepair.type = 'button';
17324
- buttonRepair.className = 'jsoneditor-repair';
17325
- buttonRepair.title = 'Repair JSON: fix quotes and escape characters, remove comments and JSONP notation, turn JavaScript objects into JSON.';
17326
- this.menu.appendChild(buttonRepair);
17327
- buttonRepair.onclick = function () {
17328
- try {
17329
- me.repair();
17330
- me._onChange();
17331
- }
17332
- catch (err) {
17333
- me._onError(err);
17359
+ if (this.options.mainMenuBar) {
17360
+ util.addClassName(this.content, 'has-main-menu-bar');
17361
+
17362
+ // create menu
17363
+ this.menu = document.createElement('div');
17364
+ this.menu.className = 'jsoneditor-menu';
17365
+ this.frame.appendChild(this.menu);
17366
+
17367
+ // create format button
17368
+ var buttonFormat = document.createElement('button');
17369
+ buttonFormat.type = 'button';
17370
+ buttonFormat.className = 'jsoneditor-format';
17371
+ buttonFormat.title = 'Format JSON data, with proper indentation and line feeds (Ctrl+\\)';
17372
+ this.menu.appendChild(buttonFormat);
17373
+ buttonFormat.onclick = function () {
17374
+ try {
17375
+ me.format();
17376
+ me._onChange();
17377
+ }
17378
+ catch (err) {
17379
+ me._onError(err);
17380
+ }
17381
+ };
17382
+
17383
+ // create compact button
17384
+ var buttonCompact = document.createElement('button');
17385
+ buttonCompact.type = 'button';
17386
+ buttonCompact.className = 'jsoneditor-compact';
17387
+ buttonCompact.title = 'Compact JSON data, remove all whitespaces (Ctrl+Shift+\\)';
17388
+ this.menu.appendChild(buttonCompact);
17389
+ buttonCompact.onclick = function () {
17390
+ try {
17391
+ me.compact();
17392
+ me._onChange();
17393
+ }
17394
+ catch (err) {
17395
+ me._onError(err);
17396
+ }
17397
+ };
17398
+
17399
+ // create repair button
17400
+ var buttonRepair = document.createElement('button');
17401
+ buttonRepair.type = 'button';
17402
+ buttonRepair.className = 'jsoneditor-repair';
17403
+ buttonRepair.title = 'Repair JSON: fix quotes and escape characters, remove comments and JSONP notation, turn JavaScript objects into JSON.';
17404
+ this.menu.appendChild(buttonRepair);
17405
+ buttonRepair.onclick = function () {
17406
+ try {
17407
+ me.repair();
17408
+ me._onChange();
17409
+ }
17410
+ catch (err) {
17411
+ me._onError(err);
17412
+ }
17413
+ };
17414
+
17415
+ // create mode box
17416
+ if (this.options && this.options.modes && this.options.modes.length) {
17417
+ this.modeSwitcher = new ModeSwitcher(this.menu, this.options.modes, this.options.mode, function onSwitch(mode) {
17418
+ // switch mode and restore focus
17419
+ me.setMode(mode);
17420
+ me.modeSwitcher.focus();
17421
+ });
17334
17422
  }
17335
- };
17336
17423
 
17337
- // create mode box
17338
- if (this.options && this.options.modes && this.options.modes.length) {
17339
- this.modeSwitcher = new ModeSwitcher(this.menu, this.options.modes, this.options.mode, function onSwitch(mode) {
17340
- // switch mode and restore focus
17341
- me.setMode(mode);
17342
- me.modeSwitcher.focus();
17343
- });
17424
+ if (this.mode == 'code') {
17425
+ var poweredBy = document.createElement('a');
17426
+ poweredBy.appendChild(document.createTextNode('powered by ace'));
17427
+ poweredBy.href = 'http://ace.ajax.org';
17428
+ poweredBy.target = '_blank';
17429
+ poweredBy.className = 'jsoneditor-poweredBy';
17430
+ poweredBy.onclick = function () {
17431
+ // TODO: this anchor falls below the margin of the content,
17432
+ // therefore the normal a.href does not work. We use a click event
17433
+ // for now, but this should be fixed.
17434
+ window.open(poweredBy.href, poweredBy.target);
17435
+ };
17436
+ this.menu.appendChild(poweredBy);
17437
+ }
17344
17438
  }
17345
17439
 
17346
17440
  var emptyNode = {};
@@ -17348,10 +17442,7 @@ return /******/ (function(modules) { // webpackBootstrap
17348
17442
  && typeof(this.options.onEditable === 'function')
17349
17443
  && !this.options.onEditable(emptyNode));
17350
17444
 
17351
- this.content = document.createElement('div');
17352
- this.content.className = 'jsoneditor-outer';
17353
17445
  this.frame.appendChild(this.content);
17354
-
17355
17446
  this.container.appendChild(this.frame);
17356
17447
 
17357
17448
  if (this.mode == 'code') {
@@ -17396,19 +17487,6 @@ return /******/ (function(modules) { // webpackBootstrap
17396
17487
  });
17397
17488
  }
17398
17489
 
17399
- var poweredBy = document.createElement('a');
17400
- poweredBy.appendChild(document.createTextNode('powered by ace'));
17401
- poweredBy.href = 'http://ace.ajax.org';
17402
- poweredBy.target = '_blank';
17403
- poweredBy.className = 'jsoneditor-poweredBy';
17404
- poweredBy.onclick = function () {
17405
- // TODO: this anchor falls below the margin of the content,
17406
- // therefore the normal a.href does not work. We use a click event
17407
- // for now, but this should be fixed.
17408
- window.open(poweredBy.href, poweredBy.target);
17409
- };
17410
- this.menu.appendChild(poweredBy);
17411
-
17412
17490
  // register onchange event
17413
17491
  aceEditor.on('change', this._onChange.bind(this));
17414
17492
  aceEditor.on('changeSelection', this._onSelect.bind(this));
@@ -17441,12 +17519,12 @@ return /******/ (function(modules) { // webpackBootstrap
17441
17519
  this.dom.validationErrorsContainer = validationErrorsContainer;
17442
17520
  this.frame.appendChild(validationErrorsContainer);
17443
17521
 
17444
- var additinalErrorsIndication = document.createElement('div');
17445
- additinalErrorsIndication.style.display = 'none';
17446
- additinalErrorsIndication.className = "jsoneditor-additional-errors fadein";
17447
- additinalErrorsIndication.innerHTML = "Scroll for more &#9663;";
17448
- this.dom.additinalErrorsIndication = additinalErrorsIndication;
17449
- validationErrorsContainer.appendChild(additinalErrorsIndication);
17522
+ var additionalErrorsIndication = document.createElement('div');
17523
+ additionalErrorsIndication.style.display = 'none';
17524
+ additionalErrorsIndication.className = "jsoneditor-additional-errors fadein";
17525
+ additionalErrorsIndication.innerHTML = "Scroll for more &#9663;";
17526
+ this.dom.additionalErrorsIndication = additionalErrorsIndication;
17527
+ validationErrorsContainer.appendChild(additionalErrorsIndication);
17450
17528
 
17451
17529
  if (options.statusBar) {
17452
17530
  util.addClassName(this.content, 'has-status-bar');
@@ -17600,20 +17678,18 @@ return /******/ (function(modules) { // webpackBootstrap
17600
17678
 
17601
17679
  /**
17602
17680
  * Event handler for mousedown.
17603
- * @param {Event} event
17604
17681
  * @private
17605
17682
  */
17606
- textmode._onMouseDown = function (event) {
17683
+ textmode._onMouseDown = function () {
17607
17684
  this._updateCursorInfo();
17608
17685
  this._emitSelectionChange();
17609
17686
  };
17610
17687
 
17611
17688
  /**
17612
17689
  * Event handler for blur.
17613
- * @param {Event} event
17614
17690
  * @private
17615
17691
  */
17616
- textmode._onBlur = function (event) {
17692
+ textmode._onBlur = function () {
17617
17693
  var me = this;
17618
17694
  // this allows to avoid blur when clicking inner elements (like the errors panel)
17619
17695
  // just make sure to set the isFocused to true on the inner element onclick callback
@@ -17653,7 +17729,7 @@ return /******/ (function(modules) { // webpackBootstrap
17653
17729
  line: line,
17654
17730
  column: col,
17655
17731
  count: count
17656
- }
17732
+ };
17657
17733
 
17658
17734
  if(me.options.statusBar) {
17659
17735
  updateDisplay();
@@ -17672,7 +17748,7 @@ return /******/ (function(modules) { // webpackBootstrap
17672
17748
  line: line,
17673
17749
  column: col,
17674
17750
  count: count
17675
- }
17751
+ };
17676
17752
 
17677
17753
  if(this.options.statusBar) {
17678
17754
  updateDisplay();
@@ -17700,11 +17776,22 @@ return /******/ (function(modules) { // webpackBootstrap
17700
17776
  var currentSelection = this.getTextSelection();
17701
17777
  this._selectionChangedHandler(currentSelection.start, currentSelection.end, currentSelection.text);
17702
17778
  }
17703
- }
17779
+ };
17704
17780
 
17705
- textmode._refreshAnnotations = function () {
17706
- this.aceEditor && this.aceEditor.getSession().setAnnotations();
17707
- }
17781
+ /**
17782
+ * refresh ERROR annotations state
17783
+ * error annotations are handled by the ace json mode (ace/mode/json)
17784
+ * validation annotations are handled by this mode
17785
+ * therefore in order to refresh we send only the annotations of error type in order to maintain its state
17786
+ * @private
17787
+ */
17788
+ textmode._refreshAnnotations = function () {
17789
+ var session = this.aceEditor && this.aceEditor.getSession();
17790
+ if (session) {
17791
+ var errEnnotations = session.getAnnotations().filter(function(annotation) {return annotation.type === 'error' });
17792
+ session.setAnnotations(errEnnotations);
17793
+ }
17794
+ };
17708
17795
 
17709
17796
  /**
17710
17797
  * Destroy the editor. Clean up DOM, event listeners, and web workers.
@@ -17886,19 +17973,25 @@ return /******/ (function(modules) { // webpackBootstrap
17886
17973
  var json;
17887
17974
  try {
17888
17975
  json = this.get(); // this can fail when there is no valid json
17889
- this.parseErrorIndication.style.display = 'none';
17976
+ if (this.parseErrorIndication) {
17977
+ this.parseErrorIndication.style.display = 'none';
17978
+ }
17890
17979
  doValidate = true;
17891
17980
  }
17892
17981
  catch (err) {
17893
17982
  if (this.getText()) {
17894
- this.parseErrorIndication.style.display = 'block';
17983
+ if (this.parseErrorIndication) {
17984
+ this.parseErrorIndication.style.display = 'block';
17985
+ }
17895
17986
  // try to extract the line number from the jsonlint error message
17896
17987
  var match = /\w*line\s*(\d+)\w*/g.exec(err.message);
17897
17988
  var line;
17898
17989
  if (match) {
17899
17990
  line = +match[1];
17900
17991
  }
17901
- this.parseErrorIndication.title = !isNaN(line) ? ('parse error on line ' + line) : 'parse error - check that the json is valid';
17992
+ if (this.parseErrorIndication) {
17993
+ this.parseErrorIndication.title = !isNaN(line) ? ('parse error on line ' + line) : 'parse error - check that the json is valid';
17994
+ }
17902
17995
  parseErrors.push({
17903
17996
  type: 'error',
17904
17997
  message: err.message.replace(/\n/g, '<br>'),
@@ -18003,7 +18096,7 @@ return /******/ (function(modules) { // webpackBootstrap
18003
18096
  if (this.dom.validationErrors) {
18004
18097
  this.dom.validationErrors.parentNode.removeChild(this.dom.validationErrors);
18005
18098
  this.dom.validationErrors = null;
18006
- this.dom.additinalErrorsIndication.style.display = 'none';
18099
+ this.dom.additionalErrorsIndication.style.display = 'none';
18007
18100
 
18008
18101
  this.content.style.marginBottom = '';
18009
18102
  this.content.style.paddingBottom = '';
@@ -18088,12 +18181,12 @@ return /******/ (function(modules) { // webpackBootstrap
18088
18181
 
18089
18182
  this.dom.validationErrors = validationErrors;
18090
18183
  this.dom.validationErrorsContainer.appendChild(validationErrors);
18091
- this.dom.additinalErrorsIndication.title = errors.length + " errors total";
18184
+ this.dom.additionalErrorsIndication.title = errors.length + " errors total";
18092
18185
 
18093
18186
  if (this.dom.validationErrorsContainer.clientHeight < this.dom.validationErrorsContainer.scrollHeight) {
18094
- this.dom.additinalErrorsIndication.style.display = 'block';
18187
+ this.dom.additionalErrorsIndication.style.display = 'block';
18095
18188
  this.dom.validationErrorsContainer.onscroll = function () {
18096
- me.dom.additinalErrorsIndication.style.display =
18189
+ me.dom.additionalErrorsIndication.style.display =
18097
18190
  (me.dom.validationErrorsContainer.clientHeight > 0 && me.dom.validationErrorsContainer.scrollTop === 0) ? 'block' : 'none';
18098
18191
  }
18099
18192
  } else {
@@ -18182,13 +18275,10 @@ return /******/ (function(modules) { // webpackBootstrap
18182
18275
  };
18183
18276
 
18184
18277
  /**
18185
- * Callback registraion for selection change
18278
+ * Callback registration for selection change
18186
18279
  * @param {selectionCallback} callback
18187
18280
  *
18188
18281
  * @callback selectionCallback
18189
- * @param {{row:Number, column:Number}} startPos selection start position
18190
- * @param {{row:Number, column:Number}} endPos selected end position
18191
- * @param {String} text selected text
18192
18282
  */
18193
18283
  textmode.onTextSelectionChange = function (callback) {
18194
18284
  if (typeof callback === 'function') {