@nebula.js/stardust 2.6.1 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/esm/dev.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * @nebula.js/stardust v2.6.1
2
+ * @nebula.js/stardust v2.7.0
3
3
  * Copyright (c) 2022 QlikTech International AB
4
4
  * Released under the MIT license.
5
5
  */
@@ -742,14 +742,9 @@ function ownKeys(object, enumerableOnly) {
742
742
 
743
743
  if (Object.getOwnPropertySymbols) {
744
744
  var symbols = Object.getOwnPropertySymbols(object);
745
-
746
- if (enumerableOnly) {
747
- symbols = symbols.filter(function (sym) {
748
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
749
- });
750
- }
751
-
752
- keys.push.apply(keys, symbols);
745
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
746
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
747
+ })), keys.push.apply(keys, symbols);
753
748
  }
754
749
 
755
750
  return keys;
@@ -757,19 +752,12 @@ function ownKeys(object, enumerableOnly) {
757
752
 
758
753
  function _objectSpread2(target) {
759
754
  for (var i = 1; i < arguments.length; i++) {
760
- var source = arguments[i] != null ? arguments[i] : {};
761
-
762
- if (i % 2) {
763
- ownKeys(Object(source), true).forEach(function (key) {
764
- _defineProperty$1(target, key, source[key]);
765
- });
766
- } else if (Object.getOwnPropertyDescriptors) {
767
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
768
- } else {
769
- ownKeys(Object(source)).forEach(function (key) {
770
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
771
- });
772
- }
755
+ var source = null != arguments[i] ? arguments[i] : {};
756
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
757
+ _defineProperty$1(target, key, source[key]);
758
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
759
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
760
+ });
773
761
  }
774
762
 
775
763
  return target;
@@ -1001,6 +989,26 @@ var CurrentSelections_Of = {
1001
989
  "zh-TW": "{0}/ {1}"
1002
990
  }
1003
991
  };
992
+ var Listbox_Lock = {
993
+ id: "Listbox.Lock",
994
+ locale: {
995
+ "de-DE": "Auswahlen sperren",
996
+ "en-US": "Lock selections",
997
+ "es-ES": "Bloquear selecciones",
998
+ "fr-FR": "Verrouiller les sélections",
999
+ "it-IT": "Blocca selezioni",
1000
+ "ja-JP": "選択をロック",
1001
+ "ko-KR": "선택 내용 잠금",
1002
+ "nl-NL": "Selecties vergrendelen",
1003
+ "pl-PL": "Zablokuj wybory",
1004
+ "pt-BR": "Bloquear seleções",
1005
+ "ru-RU": "Заблокировать выборки",
1006
+ "sv-SE": "Lås urval",
1007
+ "tr-TR": "Seçimleri kilitle",
1008
+ "zh-CN": "锁定选择项",
1009
+ "zh-TW": "鎖定選項"
1010
+ }
1011
+ };
1004
1012
  var Listbox_Search = {
1005
1013
  id: "Listbox.Search",
1006
1014
  locale: {
@@ -1021,6 +1029,26 @@ var Listbox_Search = {
1021
1029
  "zh-TW": "在清單方塊中搜尋"
1022
1030
  }
1023
1031
  };
1032
+ var Listbox_Unlock = {
1033
+ id: "Listbox.Unlock",
1034
+ locale: {
1035
+ "de-DE": "Auswahlen entsperren",
1036
+ "en-US": "Unlock selections",
1037
+ "es-ES": "Desbloquear selecciones",
1038
+ "fr-FR": "Déverrouiller les sélections",
1039
+ "it-IT": "Sblocca selezioni",
1040
+ "ja-JP": "選択をロック解除",
1041
+ "ko-KR": "선택 내용 잠금 해제",
1042
+ "nl-NL": "Selecties ontgrendelen",
1043
+ "pl-PL": "Odblokuj wybory",
1044
+ "pt-BR": "Desbloquear seleções",
1045
+ "ru-RU": "Разблокировать выборки",
1046
+ "sv-SE": "Lås upp urval",
1047
+ "tr-TR": "Seçimlerin kilidini aç",
1048
+ "zh-CN": "将选择项解锁",
1049
+ "zh-TW": "解鎖選項"
1050
+ }
1051
+ };
1024
1052
  var Menu_More = {
1025
1053
  id: "Menu.More",
1026
1054
  locale: {
@@ -1505,7 +1533,9 @@ var all = {
1505
1533
  Cancel: Cancel$1,
1506
1534
  CurrentSelections_All: CurrentSelections_All,
1507
1535
  CurrentSelections_Of: CurrentSelections_Of,
1536
+ Listbox_Lock: Listbox_Lock,
1508
1537
  Listbox_Search: Listbox_Search,
1538
+ Listbox_Unlock: Listbox_Unlock,
1509
1539
  Menu_More: Menu_More,
1510
1540
  Navigate_Back: Navigate_Back,
1511
1541
  Navigate_Forward: Navigate_Forward,
@@ -2928,7 +2958,7 @@ function generateOrdinalScales(scalesDef) {
2928
2958
  }
2929
2959
 
2930
2960
  /**
2931
- * Creates the follwing array of paths
2961
+ * Creates the following array of paths
2932
2962
  * object.barChart - legend.title - fontSize
2933
2963
  * object - legend.title - fontSize
2934
2964
  * legend.title - fontSize
@@ -2983,7 +3013,7 @@ function getObject$1(root, steps) {
2983
3013
  if (obj[steps[i]]) {
2984
3014
  obj = obj[steps[i]];
2985
3015
  } else {
2986
- return null;
3016
+ return undefined;
2987
3017
  }
2988
3018
  }
2989
3019
 
@@ -2991,12 +3021,11 @@ function getObject$1(root, steps) {
2991
3021
  }
2992
3022
 
2993
3023
  function searchPathArray(pathArray, attribute, theme) {
2994
- for (let i = 0; i < pathArray.length; i++) {
2995
- const target = getObject$1(theme, pathArray[i]);
3024
+ const attributeArray = attribute.split('.');
2996
3025
 
2997
- if (target !== null && target[attribute]) {
2998
- return target[attribute];
2999
- }
3026
+ for (let i = 0; i < pathArray.length; i++) {
3027
+ const restult = getObject$1(theme, [...pathArray[i], ...attributeArray]);
3028
+ if (restult !== undefined) return restult;
3000
3029
  }
3001
3030
 
3002
3031
  return undefined;
@@ -3032,11 +3061,15 @@ function styleResolver(basePath, themeJSON) {
3032
3061
  * object.barChart - fontSize
3033
3062
  * object - fontSize
3034
3063
  * fontSize
3064
+ * When attributes separated by dots is provided, they are required in the theme JSON file
3065
+ * Ex. Base path: "object" , Path: "legend", ", Attribute: "title.fontSize"
3066
+ * title: {fontSize: ...} must be matched and the rest is the same as above
3067
+ * If you want a exact match, you can use `getStyle('object', '', 'legend.title.fontSize');`
3035
3068
  * @ignore
3036
3069
  *
3037
- * @param {string} component string of properties seperated by dots to search in
3038
- * @param {string} attribute to return
3039
- * @returns {any} value of the resolved path, undefined if not found
3070
+ * @param {string} component String of properties separated by dots to search in
3071
+ * @param {string} attribute Name of the style attribute
3072
+ * @returns {string|undefined} The style value of the resolved path, undefined if not found
3040
3073
  */
3041
3074
  getStyle(component, attribute) {
3042
3075
  // TODO - object overrides
@@ -3199,17 +3232,23 @@ function theme() {
3199
3232
  },
3200
3233
 
3201
3234
  /**
3202
- * Get the value of a style attribute in the theme by searching in the theme's JSON structure.
3203
- * The search starts at the specified base path and continues upwards until the value is found.
3235
+ * Get the value of a style attribute in the theme
3236
+ * by searching in the theme's JSON structure.
3237
+ * The search starts at the specified base path
3238
+ * and continues upwards until the value is found.
3204
3239
  * If possible it will get the attribute's value using the given path.
3240
+ * When attributes separated by dots are provided, such as 'hover.color',
3241
+ * they are required in the theme JSON file
3205
3242
  *
3206
3243
  * @param {string} basePath - Base path in the theme's JSON structure to start the search in (specified as a name path separated by dots).
3207
3244
  * @param {string} path - Expected path for the attribute (specified as a name path separated by dots).
3208
- * @param {string} attribute - Name of the style attribute.
3209
- * @returns {string} The style value
3245
+ * @param {string} attribute - Name of the style attribute. (specified as a name attribute separated by dots).
3246
+ * @returns {string|undefined} The style value or undefined if not found
3210
3247
  *
3211
3248
  * @example
3212
3249
  * theme.getStyle('object', 'title.main', 'fontSize');
3250
+ * theme.getStyle('object', 'title', 'main.fontSize');
3251
+ * theme.getStyle('object', '', 'title.main.fontSize');
3213
3252
  * theme.getStyle('', '', 'fontSize');
3214
3253
  */
3215
3254
  getStyle(basePath, path, attribute) {
@@ -3217,7 +3256,7 @@ function theme() {
3217
3256
  styleResolverInstanceCache[basePath] = styleResolver(basePath, resolvedThemeJSON);
3218
3257
  }
3219
3258
 
3220
- return styleResolverInstanceCache[basePath].getStyle(path, attribute, false);
3259
+ return styleResolverInstanceCache[basePath].getStyle(path, attribute);
3221
3260
  }
3222
3261
 
3223
3262
  };
@@ -3256,7 +3295,9 @@ function theme() {
3256
3295
 
3257
3296
  /* eslint no-underscore-dangle:0 */
3258
3297
 
3259
- const timed = (t, v) => new Promise(resolve => setTimeout(() => resolve(v), t));
3298
+ const timed = (t, v) => new Promise(resolve => {
3299
+ setTimeout(() => resolve(v), t);
3300
+ });
3260
3301
 
3261
3302
  const LOAD_THEME_TIMEOUT = 5000;
3262
3303
  function appTheme() {
@@ -5234,7 +5275,7 @@ function useAppSelections(app) {
5234
5275
  return [appSelections, navState];
5235
5276
  }
5236
5277
 
5237
- const NEBULA_VERSION_HASH = "375a" ;
5278
+ const NEBULA_VERSION_HASH = "b1d7" ;
5238
5279
  let counter = 0;
5239
5280
  const NebulaApp = forwardRef((_ref, ref) => {
5240
5281
  let {
@@ -5280,7 +5321,7 @@ const NebulaApp = forwardRef((_ref, ref) => {
5280
5321
  theme: theme
5281
5322
  }, /*#__PURE__*/React.createElement(InstanceContext.Provider, {
5282
5323
  value: context
5283
- }, /*#__PURE__*/React.createElement(React.Fragment, null, components))));
5324
+ }, components)));
5284
5325
  });
5285
5326
  function boot(_ref2) {
5286
5327
  let {
@@ -5294,7 +5335,7 @@ function boot(_ref2) {
5294
5335
  const appRef = React.createRef();
5295
5336
  const element = document.createElement('div');
5296
5337
  element.style.display = 'none';
5297
- element.setAttribute('data-nebulajs-version', "2.6.1" );
5338
+ element.setAttribute('data-nebulajs-version', "2.7.0" );
5298
5339
  element.setAttribute('data-app-id', app.id);
5299
5340
  document.body.appendChild(element);
5300
5341
  ReactDOM.render( /*#__PURE__*/React.createElement(NebulaApp, {
@@ -6515,7 +6556,8 @@ function getElemNumbersFromPages(pages) {
6515
6556
  return elemNumbers;
6516
6557
  }
6517
6558
  /**
6518
- * @typedef {object} MinMaxResult
6559
+ * @ignore
6560
+ * @interface MinMaxResult
6519
6561
  * @property {number} min
6520
6562
  * @property {number} max
6521
6563
  */
@@ -6524,6 +6566,7 @@ function getElemNumbersFromPages(pages) {
6524
6566
  * Returns the min and max indices of elemNumbersOrdered which contains
6525
6567
  * all numbers in elementNbrs.
6526
6568
  *
6569
+ * @ignore
6527
6570
  * @param {number[]} elementNbrs
6528
6571
  * @param {number[]} elemNumbersOrdered
6529
6572
  * @returns {MinMaxResult}
@@ -6567,6 +6610,7 @@ function useSelectionsInteractions(_ref) {
6567
6610
  pages = [],
6568
6611
  rangeSelect = true,
6569
6612
  checkboxes = false,
6613
+ selectDisabled,
6570
6614
  doc = document
6571
6615
  } = _ref;
6572
6616
  const [instantPages, setInstantPages] = useState$1(pages);
@@ -6583,6 +6627,11 @@ function useSelectionsInteractions(_ref) {
6583
6627
  const select = async function () {
6584
6628
  let elemNumbers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
6585
6629
  let additive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
6630
+
6631
+ if (selectDisabled()) {
6632
+ return;
6633
+ }
6634
+
6586
6635
  setSelectingValues(true);
6587
6636
  const isSingleSelect = getIsSingleSelect();
6588
6637
  const filtered = additive ? elemNumbers.filter(n => !selected.includes(n)) : elemNumbers;
@@ -6597,6 +6646,11 @@ function useSelectionsInteractions(_ref) {
6597
6646
 
6598
6647
  const preSelect = function (elemNumbers) {
6599
6648
  let additive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
6649
+
6650
+ if (selectDisabled()) {
6651
+ return;
6652
+ }
6653
+
6600
6654
  setPreSelected(existing => {
6601
6655
  const uniques = getUniques([...existing, ...elemNumbers]);
6602
6656
  const filtered = additive ? uniques.filter(n => !selected.includes(n)) : uniques;
@@ -6605,16 +6659,26 @@ function useSelectionsInteractions(_ref) {
6605
6659
  });
6606
6660
  };
6607
6661
 
6662
+ const selectManually = function () {
6663
+ let elementIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
6664
+ let additive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
6665
+ setMouseDown(true);
6666
+ preSelect(elementIds, additive || isRangeSelection);
6667
+ const p = select(elementIds, additive || isRangeSelection);
6668
+ setMouseDown(false);
6669
+ return p;
6670
+ };
6671
+
6608
6672
  const onClick = useCallback(event => {
6609
- if (selectingValues) {
6673
+ if (selectingValues || selectDisabled()) {
6610
6674
  return;
6611
6675
  }
6612
6676
 
6613
6677
  const elemNumber = +event.currentTarget.getAttribute('data-n');
6614
6678
  setPreSelected([elemNumber]);
6615
- }, [selectingValues]);
6679
+ }, [selectingValues, selectDisabled]);
6616
6680
  const onMouseDown = useCallback(event => {
6617
- if (selectingValues) {
6681
+ if (selectingValues || selectDisabled()) {
6618
6682
  return;
6619
6683
  }
6620
6684
 
@@ -6622,7 +6686,7 @@ function useSelectionsInteractions(_ref) {
6622
6686
  setMouseDown(true);
6623
6687
  const elemNumber = +event.currentTarget.getAttribute('data-n');
6624
6688
  setPreSelected([elemNumber]);
6625
- }, [selectingValues]);
6689
+ }, [selectingValues, selectDisabled]);
6626
6690
  const onMouseUp = useCallback(event => {
6627
6691
  const elemNumber = +event.currentTarget.getAttribute('data-n');
6628
6692
 
@@ -6632,21 +6696,21 @@ function useSelectionsInteractions(_ref) {
6632
6696
  }
6633
6697
 
6634
6698
  preSelect([elemNumber]);
6635
- }, [mouseDown, selectingValues, preSelected, selected, isRangeSelection]);
6699
+ }, [mouseDown, selectingValues, preSelected, selected, isRangeSelection, selectDisabled]);
6636
6700
  const onMouseUpDoc = useCallback(() => {
6637
6701
  // Ensure we end interactions when mouseup happens outside the Listbox.
6638
6702
  setMouseDown(false);
6639
6703
  setSelectingValues(false);
6640
6704
  }, []);
6641
6705
  const onMouseEnter = useCallback(event => {
6642
- if (getIsSingleSelect() || !mouseDown || selectingValues) {
6706
+ if (getIsSingleSelect() || !mouseDown || selectingValues || selectDisabled()) {
6643
6707
  return;
6644
6708
  }
6645
6709
 
6646
6710
  setIsRangeSelection(true);
6647
6711
  const elemNumber = +event.currentTarget.getAttribute('data-n');
6648
6712
  preSelect([elemNumber], true);
6649
- }, [mouseDown, selectingValues, isRangeSelection, preSelected, selected, layout && layout.qListObject.qDimensionInfo.qIsOneAndOnlyOne]);
6713
+ }, [mouseDown, selectingValues, isRangeSelection, preSelected, selected, selectDisabled, layout && layout.qListObject.qDimensionInfo.qIsOneAndOnlyOne]);
6650
6714
  useEffect$1(() => {
6651
6715
  // Perform selections of pre-selected values. This can
6652
6716
  // happen only when interactions have finished (mouseup).
@@ -6657,7 +6721,7 @@ function useSelectionsInteractions(_ref) {
6657
6721
  }
6658
6722
 
6659
6723
  select(preSelected, isRangeSelection);
6660
- }, [preSelected, mouseDown]);
6724
+ }, [preSelected, mouseDown, selectDisabled()]);
6661
6725
  useEffect$1(() => {
6662
6726
  doc.addEventListener('mouseup', onMouseUpDoc);
6663
6727
  return () => {
@@ -6703,7 +6767,9 @@ function useSelectionsInteractions(_ref) {
6703
6767
 
6704
6768
  return {
6705
6769
  instantPages,
6706
- interactionEvents
6770
+ interactionEvents,
6771
+ select: selectManually // preselect and select without having to trigger an event
6772
+
6707
6773
  };
6708
6774
  }
6709
6775
 
@@ -6720,7 +6786,7 @@ var Tick = (props => SvgIcon(tick(props)));
6720
6786
 
6721
6787
  const CheckboxChecked = "url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath" + " fill-rule='evenodd' clip-rule='evenodd' d='M12 5c-.28 0-.53.11-.71.29L7 9.59l-2.29-2.3a1.003 " + "1.003 0 00-1.42 1.42l3 3c.18.18.43.29.71.29s.53-.11.71-.29l5-5A1.003 1.003 0 0012 5z' fill='%23fff'/%3E%3C/svg%3E\")";
6722
6788
 
6723
- const useStyles$b = makeStyles(theme => ({
6789
+ const useStyles$c = makeStyles(theme => ({
6724
6790
  cbIcon: {
6725
6791
  borderRadius: 3,
6726
6792
  width: 16,
@@ -6757,11 +6823,10 @@ function ListboxCheckbox(_ref) {
6757
6823
  label,
6758
6824
  dense
6759
6825
  } = _ref;
6760
- const styles = useStyles$b();
6826
+ const styles = useStyles$c();
6761
6827
  return /*#__PURE__*/React.createElement(Checkbox, {
6762
6828
  edge: "start",
6763
6829
  checked: checked,
6764
- tabIndex: -1,
6765
6830
  disableRipple: true,
6766
6831
  className: [styles.checkbox, dense && styles.dense].filter(Boolean).join(' '),
6767
6832
  inputProps: {
@@ -6778,18 +6843,21 @@ function ListboxCheckbox(_ref) {
6778
6843
  }
6779
6844
 
6780
6845
  /**
6781
- * @typedef {object} Range
6846
+ * @ignore
6847
+ * @interface Range
6782
6848
  * @property {number} qCharPos The (absolute) index where the highlighted range starts.
6783
6849
  * @property {number} qCharCount The length of the sub-string (starting from qChartPos) that should be highlighted.
6784
6850
  */
6785
6851
 
6786
6852
  /**
6787
- * @typedef {object} Segment
6853
+ * @ignore
6854
+ * @interface Segment
6788
6855
  * @property {string} segment The sub-string/segment cut out from the original label.
6789
6856
  * @property {boolean} highlighted A flag which tells whether the segment should be highlighted or not.
6790
6857
  */
6791
6858
 
6792
6859
  /**
6860
+ * @ignore
6793
6861
  * @param {string} label The label we want to create segments out of.
6794
6862
  * @param {Range} range The indexes which define how to create the segments.
6795
6863
  * @param {number=} [startIndex] An optional index which tells where we want to start the first segment from
@@ -6814,6 +6882,7 @@ function getSegmentsFromRange(label, range) {
6814
6882
  return segments;
6815
6883
  }
6816
6884
  /**
6885
+ * @ignore
6817
6886
  * @param {string} label The label we want to create segments out of.
6818
6887
  * @param {Range[]} ranges The ranges defining indices for cutting the string into segments.
6819
6888
  * @returns {Segment[]} An array of segments, covering the entire string label.
@@ -6841,27 +6910,199 @@ function getSegmentsFromRanges(label, ranges) {
6841
6910
  return labels;
6842
6911
  }
6843
6912
 
6913
+ const KEYS = Object.freeze({
6914
+ ENTER: 13,
6915
+ ESCAPE: 27,
6916
+ SPACE: 32,
6917
+ TAB: 9,
6918
+ BACKSPACE: 8,
6919
+ DELETE: 46,
6920
+ ALT: 18,
6921
+ CTRL: 17,
6922
+ SHIFT: 16,
6923
+ ARROW_UP: 38,
6924
+ ARROW_DOWN: 40,
6925
+ ARROW_LEFT: 37,
6926
+ ARROW_RIGHT: 39,
6927
+ PAGE_DOWN: 34,
6928
+ PAGE_UP: 33,
6929
+ HOME: 36,
6930
+ END: 35,
6931
+ F10: 121,
6932
+ A: 65,
6933
+ F: 70,
6934
+ ZERO: 48,
6935
+ NINE: 57,
6936
+ NUMPAD_ZERO: 96,
6937
+ NUMPAD_NINE: 105,
6938
+ SUBTRACTION: 189,
6939
+ DECIMAL: 190,
6940
+ NUMPAD_DECIMAL: 110,
6941
+ isArrow: key => key === KEYS.ARROW_UP || key === KEYS.ARROW_DOWN || key === KEYS.ARROW_LEFT || key === KEYS.ARROW_RIGHT
6942
+ });
6943
+
6944
+ function getFieldKeyboardNavigation(_ref) {
6945
+ let {
6946
+ select,
6947
+ confirm,
6948
+ cancel
6949
+ } = _ref;
6950
+
6951
+ const getElement = function (elm) {
6952
+ let next = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
6953
+ const parentElm = elm && elm.parentElement[next ? 'nextElementSibling' : 'previousElementSibling'];
6954
+ return parentElm && parentElm.querySelector('[role]');
6955
+ };
6956
+
6957
+ let startedRange = false;
6958
+
6959
+ const setStartedRange = val => {
6960
+ startedRange = val;
6961
+ };
6962
+
6963
+ const handleKeyDown = event => {
6964
+ let elementToFocus;
6965
+ const {
6966
+ keyCode,
6967
+ shiftKey = false
6968
+ } = event.nativeEvent;
6969
+
6970
+ switch (keyCode) {
6971
+ case KEYS.SHIFT:
6972
+ // This is to ensure we include the first value when starting a range selection.
6973
+ setStartedRange(true);
6974
+ break;
6975
+
6976
+ case KEYS.SPACE:
6977
+ select([+event.currentTarget.getAttribute('data-n')]);
6978
+ break;
6979
+
6980
+ case KEYS.ARROW_DOWN:
6981
+ case KEYS.ARROW_RIGHT:
6982
+ elementToFocus = getElement(event.currentTarget, true);
6983
+
6984
+ if (shiftKey && elementToFocus) {
6985
+ if (startedRange) {
6986
+ select([+event.currentTarget.getAttribute('data-n')], true);
6987
+ setStartedRange(false);
6988
+ }
6989
+
6990
+ select([+elementToFocus.getAttribute('data-n')], true);
6991
+ }
6992
+
6993
+ break;
6994
+
6995
+ case KEYS.ARROW_UP:
6996
+ case KEYS.ARROW_LEFT:
6997
+ elementToFocus = getElement(event.currentTarget, false);
6998
+
6999
+ if (shiftKey && elementToFocus) {
7000
+ if (startedRange) {
7001
+ select([+event.currentTarget.getAttribute('data-n')], true);
7002
+ setStartedRange(false);
7003
+ }
7004
+
7005
+ select([+elementToFocus.getAttribute('data-n')], true);
7006
+ }
7007
+
7008
+ break;
7009
+
7010
+ case KEYS.ENTER:
7011
+ confirm();
7012
+ break;
7013
+
7014
+ case KEYS.ESCAPE:
7015
+ cancel();
7016
+ return;
7017
+ // let it propagate to top-level
7018
+
7019
+ default:
7020
+ return;
7021
+ // don't stop propagation since we want to outsource keydown to other handlers.
7022
+ }
7023
+
7024
+ if (elementToFocus) {
7025
+ elementToFocus.focus();
7026
+ }
7027
+
7028
+ event.preventDefault();
7029
+ event.stopPropagation();
7030
+ };
7031
+
7032
+ return handleKeyDown;
7033
+ }
7034
+ function getListboxInlineKeyboardNavigation(_ref2) {
7035
+ let {
7036
+ setKeyboardActive
7037
+ } = _ref2;
7038
+
7039
+ const focusInsideListbox = element => {
7040
+ const fieldElement = element.querySelector('.search input, .value.selector, .value');
7041
+ setKeyboardActive(true);
7042
+
7043
+ if (fieldElement) {
7044
+ fieldElement.focus();
7045
+ }
7046
+ };
7047
+
7048
+ const focusContainer = element => {
7049
+ setKeyboardActive(false);
7050
+ element.focus();
7051
+ };
7052
+
7053
+ const handleKeyDown = event => {
7054
+ const {
7055
+ keyCode
7056
+ } = event.nativeEvent;
7057
+
7058
+ switch (keyCode) {
7059
+ // case KEYS.TAB: TODO: Focus confirm button using keyboard.focusSelection when we can access the useKeyboard hook.
7060
+ case KEYS.ENTER:
7061
+ case KEYS.SPACE:
7062
+ focusInsideListbox(event.currentTarget);
7063
+ break;
7064
+
7065
+ case KEYS.ESCAPE:
7066
+ focusContainer(event.currentTarget);
7067
+ break;
7068
+
7069
+ default:
7070
+ return;
7071
+ } // Note: We should not stop propagation here as it will block the containing app
7072
+ // from handling keydown events.
7073
+
7074
+
7075
+ event.preventDefault();
7076
+ };
7077
+
7078
+ return handleKeyDown;
7079
+ }
7080
+
6844
7081
  const ellipsis = {
6845
7082
  width: '100%',
6846
7083
  overflow: 'hidden',
6847
7084
  textOverflow: 'ellipsis'
6848
7085
  };
6849
- const useStyles$a = makeStyles(theme => ({
7086
+ const barPadPx = 4;
7087
+ const barBorderWidthPx = 1;
7088
+ const barWithCheckboxLeftPadEm = 2;
7089
+ const frequencyTextNone = '0';
7090
+ const useStyles$b = makeStyles(theme => ({
6850
7091
  row: {
6851
7092
  flexWrap: 'nowrap',
6852
7093
  borderBottom: "1px solid ".concat(theme.palette.divider),
6853
- color: theme.palette.text.primary,
6854
- '&:focus': {
6855
- boxShadow: "inset 0 0 0 2px ".concat(theme.palette.custom.focusOutline),
6856
- outline: 'none'
6857
- }
7094
+ color: theme.palette.text.primary
6858
7095
  },
6859
7096
  column: {
6860
7097
  flexWrap: 'nowrap',
6861
7098
  borderRight: "1px solid ".concat(theme.palette.divider),
6862
- color: theme.palette.text.primary,
7099
+ color: theme.palette.text.primary
7100
+ },
7101
+ fieldRoot: {
6863
7102
  '&:focus': {
6864
- boxShadow: "inset 0 0 0 2px ".concat(theme.palette.custom.focusOutline),
7103
+ boxShadow: "inset 0 0 0 2px ".concat(theme.palette.custom.focusBorder, " !important")
7104
+ },
7105
+ '&:focus-visible': {
6865
7106
  outline: 'none'
6866
7107
  }
6867
7108
  },
@@ -6900,7 +7141,11 @@ const useStyles$a = makeStyles(theme => ({
6900
7141
  margin: 0,
6901
7142
  width: '100%',
6902
7143
  // For checkboxes the first child is the checkbox container, second is the label container.
6903
- '& > span:nth-child(2)': _objectSpread2({}, ellipsis)
7144
+ '& > span:nth-child(2)': _objectSpread2(_objectSpread2({}, ellipsis), {}, {
7145
+ display: 'flex',
7146
+ alignItems: 'center',
7147
+ paddingLeft: '8px'
7148
+ })
6904
7149
  },
6905
7150
  // The icons container holding tick and lock, shown inside fields.
6906
7151
  icon: {
@@ -6923,6 +7168,38 @@ const useStyles$a = makeStyles(theme => ({
6923
7168
  X: {
6924
7169
  background: theme.palette.selected.excluded,
6925
7170
  color: theme.palette.selected.excludedContrastText
7171
+ },
7172
+ frequencyCount: {
7173
+ paddingLeft: '8px',
7174
+ paddingRight: '8px'
7175
+ },
7176
+ barContainer: {
7177
+ position: 'relative'
7178
+ },
7179
+ bar: {
7180
+ border: "".concat(barBorderWidthPx, "px solid"),
7181
+ borderColor: '#D9D9D9',
7182
+ height: '1em',
7183
+ position: 'absolute',
7184
+ zIndex: '-1',
7185
+ alignSelf: 'center',
7186
+ left: "".concat(barPadPx, "px"),
7187
+ transition: 'width 0.2s'
7188
+ },
7189
+ barSelected: {
7190
+ opacity: '30%',
7191
+ zIndex: '0',
7192
+ background: theme.palette.background.lighter
7193
+ },
7194
+ barWithCheckbox: {
7195
+ left: "".concat(barWithCheckboxLeftPadEm, "em")
7196
+ },
7197
+ barSelectedWithCheckbox: {
7198
+ background: '#BFE5D0',
7199
+ borderColor: '#BFE5D0'
7200
+ },
7201
+ excludedTextWithCheckbox: {
7202
+ color: '#828282'
6926
7203
  }
6927
7204
  }));
6928
7205
  function RowColumn(_ref) {
@@ -6940,11 +7217,17 @@ function RowColumn(_ref) {
6940
7217
  pages,
6941
7218
  isLocked,
6942
7219
  checkboxes = false,
6943
- dense = false
7220
+ dense = false,
7221
+ frequencyMode = 'N',
7222
+ actions,
7223
+ frequencyMax = '',
7224
+ histogram = false,
7225
+ keyboard
6944
7226
  } = data;
7227
+ const handleKeyDownCallback = useCallback(getFieldKeyboardNavigation(actions), [actions]);
6945
7228
  const [isSelected, setSelected] = useState$1(false);
6946
7229
  const [cell, setCell] = useState$1();
6947
- const classes = useStyles$a();
7230
+ const classes = useStyles$b();
6948
7231
  const [classArr, setClassArr] = useState$1([]);
6949
7232
  useEffect$1(() => {
6950
7233
  if (!pages) {
@@ -6964,6 +7247,11 @@ function RowColumn(_ref) {
6964
7247
 
6965
7248
  setCell(c);
6966
7249
  }, [pages]);
7250
+
7251
+ const isExcluded = c => c ? c.qState === 'X' || c.qState === 'XS' || c.qState === 'XL' : null;
7252
+
7253
+ const isAlternative = c => c ? c.qState === 'A' : null;
7254
+
6967
7255
  useEffect$1(() => {
6968
7256
  if (!cell) {
6969
7257
  return;
@@ -6976,9 +7264,9 @@ function RowColumn(_ref) {
6976
7264
  if (!checkboxes) {
6977
7265
  if (cell.qState === 'S' || cell.qState === 'L') {
6978
7266
  clazzArr.push(classes.S);
6979
- } else if (cell.qState === 'A') {
7267
+ } else if (isAlternative(cell)) {
6980
7268
  clazzArr.push(classes.A);
6981
- } else if (cell.qState === 'X' || cell.qState === 'XS' || cell.qState === 'XL') {
7269
+ } else if (isExcluded(cell)) {
6982
7270
  clazzArr.push(classes.X);
6983
7271
  }
6984
7272
  }
@@ -6986,6 +7274,10 @@ function RowColumn(_ref) {
6986
7274
  setClassArr(clazzArr);
6987
7275
  }, [cell && cell.qState]);
6988
7276
 
7277
+ const joinClassNames = namesArray => namesArray.filter(c => !!c).join(' ').trim();
7278
+
7279
+ const hasGrayText = () => (isAlternative(cell) || isExcluded(cell)) && checkboxes ? classes.excludedTextWithCheckbox : false;
7280
+
6989
7281
  const getValueField = _ref2 => {
6990
7282
  let {
6991
7283
  lbl,
@@ -6997,7 +7289,7 @@ function RowColumn(_ref) {
6997
7289
  component: "span",
6998
7290
  variant: "body2",
6999
7291
  key: ix,
7000
- className: [classes.labelText, highlighted && classes.highlighted, dense && classes.labelDense].filter(c => !!c).join(' ').trim(),
7292
+ className: joinClassNames([classes.labelText, highlighted && classes.highlighted, dense && classes.labelDense, hasGrayText()]),
7001
7293
  color: color
7002
7294
  }, /*#__PURE__*/React.createElement("span", {
7003
7295
  style: {
@@ -7031,7 +7323,16 @@ function RowColumn(_ref) {
7031
7323
  });
7032
7324
  };
7033
7325
 
7034
- const label = cell ? cell.qText : ''; // Search highlights. Split up labelText span into several and add the highlighted class to matching sub-strings.
7326
+ const label = cell ? cell.qText : '';
7327
+
7328
+ const getFrequencyText = () => {
7329
+ if (cell) {
7330
+ return cell.qFrequency ? cell.qFrequency : frequencyTextNone;
7331
+ }
7332
+
7333
+ return '';
7334
+ }; // Search highlights. Split up labelText span into several and add the highlighted class to matching sub-strings.
7335
+
7035
7336
 
7036
7337
  const ranges = cell && cell.qHighlightRanges && cell.qHighlightRanges.qRanges.sort((a, b) => a.qCharPos - b.qCharPos) || [];
7037
7338
  const labels = getSegmentsFromRanges(label, ranges);
@@ -7067,19 +7368,43 @@ function RowColumn(_ref) {
7067
7368
  flexGrow: 1,
7068
7369
  padding: checkboxes ? 0 : undefined
7069
7370
  };
7070
- return /*#__PURE__*/React.createElement(Grid, {
7371
+
7372
+ const hasHistogramBar = () => cell && histogram && getFrequencyText() !== frequencyTextNone;
7373
+
7374
+ const getBarWidth = qFrequency => {
7375
+ const freqStr = String(qFrequency);
7376
+ const isPercent = freqStr.substring(freqStr.length - 1) === '%';
7377
+ const freq = parseFloat(isPercent ? freqStr : qFrequency);
7378
+ const rightSlice = checkboxes ? "(".concat(barWithCheckboxLeftPadEm, "em + ").concat(barPadPx + barBorderWidthPx * 2, "px)") : "".concat(barPadPx * 2 + barBorderWidthPx * 2, "px");
7379
+ const width = isPercent ? freq : freq / frequencyMax * 100;
7380
+ return "calc(".concat(width, "% - ").concat(rightSlice, ")");
7381
+ };
7382
+
7383
+ const isFirstElement = index === 0;
7384
+ return /*#__PURE__*/React.createElement("div", {
7385
+ className: classes.barContainer
7386
+ }, /*#__PURE__*/React.createElement(Grid, {
7071
7387
  container: true,
7072
7388
  spacing: 0,
7073
- className: ['value', ...classArr].join(' ').trim(),
7389
+ className: joinClassNames(['value', ...classArr]),
7390
+ classes: {
7391
+ root: classes.fieldRoot
7392
+ },
7074
7393
  style: style,
7075
7394
  onClick: onClick,
7076
7395
  onMouseDown: onMouseDown,
7077
7396
  onMouseUp: onMouseUp,
7078
7397
  onMouseEnter: onMouseEnter,
7398
+ onKeyDown: handleKeyDownCallback,
7079
7399
  role: column ? 'column' : 'row',
7080
- tabIndex: 0,
7400
+ tabIndex: isFirstElement && (!keyboard.enabled || keyboard.active) ? 0 : -1,
7081
7401
  "data-n": cell && cell.qElemNumber
7082
- }, /*#__PURE__*/React.createElement(Grid, {
7402
+ }, hasHistogramBar() && /*#__PURE__*/React.createElement("div", {
7403
+ className: joinClassNames([classes.bar, checkboxes && classes.barWithCheckbox, isSelected && (checkboxes ? classes.barSelectedWithCheckbox : classes.barSelected)]),
7404
+ style: {
7405
+ width: getBarWidth(cell.qFrequency)
7406
+ }
7407
+ }), /*#__PURE__*/React.createElement(Grid, {
7083
7408
  item: true,
7084
7409
  style: cellStyle,
7085
7410
  className: classes.cell,
@@ -7089,7 +7414,19 @@ function RowColumn(_ref) {
7089
7414
  color: 'inherit'
7090
7415
  }) : getFieldWithRanges({
7091
7416
  lbls: labels
7092
- })), (showLock || showTick) && /*#__PURE__*/React.createElement(Grid, {
7417
+ })), frequencyMode !== 'N' && /*#__PURE__*/React.createElement(Grid, {
7418
+ item: true,
7419
+ style: {
7420
+ display: 'flex',
7421
+ alignItems: 'center'
7422
+ },
7423
+ className: classes.frequencyCount
7424
+ }, /*#__PURE__*/React.createElement(Typography, {
7425
+ noWrap: true,
7426
+ color: "inherit",
7427
+ variant: "body2",
7428
+ className: joinClassNames([dense && classes.labelDense, classes.labelText, hasGrayText()])
7429
+ }, getFrequencyText())), (showLock || showTick) && /*#__PURE__*/React.createElement(Grid, {
7093
7430
  item: true,
7094
7431
  className: classes.icon
7095
7432
  }, showLock && /*#__PURE__*/React.createElement(Lock, {
@@ -7098,7 +7435,7 @@ function RowColumn(_ref) {
7098
7435
  }), showTick && /*#__PURE__*/React.createElement(Tick, {
7099
7436
  style: iconStyles,
7100
7437
  size: "small"
7101
- })));
7438
+ }))));
7102
7439
  }
7103
7440
 
7104
7441
  function getSizeInfo(_ref) {
@@ -7130,23 +7467,29 @@ function ListBox(_ref2) {
7130
7467
  height,
7131
7468
  width,
7132
7469
  listLayout = 'vertical',
7470
+ frequencyMode = 'N',
7471
+ histogram = false,
7133
7472
  rangeSelect = true,
7134
7473
  checkboxes = false,
7135
7474
  update = undefined,
7136
- dense = false
7475
+ dense = false,
7476
+ keyboard = {},
7477
+ selectDisabled = () => false
7137
7478
  } = _ref2;
7138
7479
  const [layout] = useLayout$1(model);
7139
7480
  const [pages, setPages] = useState$1(null);
7140
7481
  const [isLoadingData, setIsLoadingData] = useState$1(false);
7141
7482
  const {
7142
7483
  instantPages = [],
7143
- interactionEvents
7484
+ interactionEvents,
7485
+ select
7144
7486
  } = useSelectionsInteractions({
7145
7487
  layout,
7146
7488
  selections,
7147
7489
  pages,
7148
7490
  rangeSelect,
7149
7491
  checkboxes,
7492
+ selectDisabled,
7150
7493
  doc: document
7151
7494
  });
7152
7495
  const loaderRef = useRef(null);
@@ -7248,6 +7591,9 @@ function ListBox(_ref2) {
7248
7591
  height
7249
7592
  });
7250
7593
  const isLocked = layout && layout.qListObject.qDimensionInfo.qLocked;
7594
+ const {
7595
+ frequencyMax
7596
+ } = layout;
7251
7597
  return /*#__PURE__*/React.createElement(InfiniteLoader, {
7252
7598
  isItemLoaded: isItemLoaded,
7253
7599
  itemCount: count,
@@ -7274,9 +7620,18 @@ function ListBox(_ref2) {
7274
7620
  isLocked,
7275
7621
  column: !isVertical,
7276
7622
  pages
7277
- }, isLocked ? {} : interactionEvents), {}, {
7623
+ }, isLocked || selectDisabled() ? {} : interactionEvents), {}, {
7278
7624
  checkboxes,
7279
- dense
7625
+ dense,
7626
+ frequencyMode,
7627
+ actions: {
7628
+ select,
7629
+ confirm: () => selections && selections.confirm.call(selections),
7630
+ cancel: () => selections && selections.cancel.call(selections)
7631
+ },
7632
+ frequencyMax,
7633
+ histogram,
7634
+ keyboard
7280
7635
  }),
7281
7636
  itemSize: itemSize,
7282
7637
  onItemsRendered: onItemsRendered,
@@ -7512,13 +7867,13 @@ function useDefaultSelectionActions(_ref) {
7512
7867
  }];
7513
7868
  }
7514
7869
 
7515
- const useStyles$9 = makeStyles$1(theme => ({
7870
+ const useStyles$a = makeStyles$1(theme => ({
7516
7871
  icon: {
7517
7872
  color: theme.palette.text.primary
7518
7873
  }
7519
7874
  }));
7520
7875
 
7521
- const MoreItem = _ref => {
7876
+ function MoreItem(_ref) {
7522
7877
  let {
7523
7878
  item,
7524
7879
  onActionClick = () => {}
@@ -7530,7 +7885,7 @@ const MoreItem = _ref => {
7530
7885
  } = useActionState(item);
7531
7886
  const {
7532
7887
  icon
7533
- } = useStyles$9();
7888
+ } = useStyles$a();
7534
7889
 
7535
7890
  const handleClick = () => {
7536
7891
  item.action();
@@ -7546,7 +7901,7 @@ const MoreItem = _ref => {
7546
7901
  }, SvgIcon(item.getSvgIconShape())), /*#__PURE__*/React.createElement(Typography, {
7547
7902
  noWrap: true
7548
7903
  }, item.label)) : null;
7549
- };
7904
+ }
7550
7905
 
7551
7906
  const More$1 = React.forwardRef((_ref2, ref) => {
7552
7907
  let {
@@ -7606,7 +7961,7 @@ const ActionToolbarElement = {
7606
7961
  /** @type {'njs-action-toolbar-popover'} */
7607
7962
  className: 'njs-action-toolbar-popover'
7608
7963
  };
7609
- const useStyles$8 = makeStyles$1(theme => ({
7964
+ const useStyles$9 = makeStyles$1(theme => ({
7610
7965
  itemSpacing: {
7611
7966
  padding: theme.spacing(0, 0.5)
7612
7967
  },
@@ -7628,7 +7983,7 @@ const ActionsGroup = React.forwardRef((_ref, ref) => {
7628
7983
  itemSpacing,
7629
7984
  firstItemSpacing,
7630
7985
  lastItemSpacing
7631
- } = useStyles$8();
7986
+ } = useStyles$9();
7632
7987
  return actions.length > 0 ? /*#__PURE__*/React.createElement(Grid, {
7633
7988
  item: true,
7634
7989
  container: true,
@@ -7675,7 +8030,7 @@ const popoverTransformOrigin = {
7675
8030
  horizontal: 'right'
7676
8031
  };
7677
8032
 
7678
- const ActionsToolbar = _ref2 => {
8033
+ function ActionsToolbar(_ref2) {
7679
8034
  let {
7680
8035
  show = true,
7681
8036
  actions = [],
@@ -7704,7 +8059,7 @@ const ActionsToolbar = _ref2 => {
7704
8059
  const defaultSelectionActions = useDefaultSelectionActions(selections);
7705
8060
  const {
7706
8061
  itemSpacing
7707
- } = useStyles$8();
8062
+ } = useStyles$9();
7708
8063
  const {
7709
8064
  translator,
7710
8065
  keyboardNavigation
@@ -7837,7 +8192,7 @@ const ActionsToolbar = _ref2 => {
7837
8192
  }
7838
8193
  }
7839
8194
  }, Actions) : show && Actions;
7840
- };
8195
+ }
7841
8196
 
7842
8197
  const search = props => _objectSpread2(_objectSpread2({}, props), {}, {
7843
8198
  shapes: [{
@@ -7848,13 +8203,19 @@ const search = props => _objectSpread2(_objectSpread2({}, props), {}, {
7848
8203
  }]
7849
8204
  });
7850
8205
 
7851
- var Search = (props => SvgIcon(search(props)));
8206
+ var SearchIcon = (props => SvgIcon(search(props)));
7852
8207
 
7853
- const useStyles$7 = makeStyles(theme => ({
8208
+ const useStyles$8 = makeStyles(theme => ({
7854
8209
  root: {
8210
+ border: 'none',
8211
+ borderRadius: 0,
7855
8212
  '& fieldset': {
7856
- borderRadius: 0,
7857
- borderColor: "".concat(theme.palette.divider, " transparent")
8213
+ border: "1px solid ".concat(theme.palette.divider),
8214
+ borderWidth: '1px 0 1px 0',
8215
+ borderRadius: 0
8216
+ },
8217
+ '&:hover': {
8218
+ border: 'none'
7858
8219
  }
7859
8220
  },
7860
8221
  dense: {
@@ -7870,6 +8231,7 @@ const TREE_PATH = '/qListObjectDef';
7870
8231
  function ListBoxSearch(_ref) {
7871
8232
  let {
7872
8233
  model,
8234
+ keyboard,
7873
8235
  autoFocus = true,
7874
8236
  dense = false
7875
8237
  } = _ref;
@@ -7896,11 +8258,11 @@ function ListBoxSearch(_ref) {
7896
8258
  }
7897
8259
  };
7898
8260
 
7899
- const classes = useStyles$7();
8261
+ const classes = useStyles$8();
7900
8262
  return /*#__PURE__*/React.createElement(OutlinedInput, {
7901
8263
  startAdornment: /*#__PURE__*/React.createElement(InputAdornment, {
7902
8264
  position: "start"
7903
- }, /*#__PURE__*/React.createElement(Search, {
8265
+ }, /*#__PURE__*/React.createElement(SearchIcon, {
7904
8266
  size: dense ? 'small' : 'normal'
7905
8267
  })),
7906
8268
  className: ['search', classes.root, dense && classes.dense].filter(Boolean).join(' '),
@@ -7910,7 +8272,10 @@ function ListBoxSearch(_ref) {
7910
8272
  placeholder: translator.get('Listbox.Search'),
7911
8273
  value: value,
7912
8274
  onChange: onChange,
7913
- onKeyDown: onKeyDown
8275
+ onKeyDown: onKeyDown,
8276
+ inputProps: {
8277
+ tabIndex: !keyboard.enabled || keyboard.active ? 0 : -1
8278
+ }
7914
8279
  });
7915
8280
  }
7916
8281
 
@@ -8232,10 +8597,14 @@ function ListBoxPopover(_ref) {
8232
8597
  }, isLocked ? /*#__PURE__*/React.createElement(IconButton, {
8233
8598
  onClick: unlock,
8234
8599
  disabled: !isLocked
8235
- }, /*#__PURE__*/React.createElement(Lock, null)) : /*#__PURE__*/React.createElement(IconButton, {
8600
+ }, /*#__PURE__*/React.createElement(Lock, {
8601
+ title: translator.get('Listbox.Unlock')
8602
+ })) : /*#__PURE__*/React.createElement(IconButton, {
8236
8603
  onClick: lock,
8237
8604
  disabled: !hasSelections
8238
- }, /*#__PURE__*/React.createElement(Unlock, null))), /*#__PURE__*/React.createElement(Grid, {
8605
+ }, /*#__PURE__*/React.createElement(Unlock, {
8606
+ title: translator.get('Listbox.Lock')
8607
+ }))), /*#__PURE__*/React.createElement(Grid, {
8239
8608
  item: true,
8240
8609
  xs: true
8241
8610
  }), /*#__PURE__*/React.createElement(Grid, {
@@ -8273,7 +8642,7 @@ function ListBoxPopover(_ref) {
8273
8642
  }))));
8274
8643
  }
8275
8644
 
8276
- const useStyles$6 = makeStyles(theme => ({
8645
+ const useStyles$7 = makeStyles(theme => ({
8277
8646
  item: {
8278
8647
  backgroundColor: theme.palette.background.paper,
8279
8648
  position: 'relative',
@@ -8299,7 +8668,7 @@ function OneField(_ref) {
8299
8668
  const alignTo = moreAlignTo || useRef();
8300
8669
  const theme = useTheme$1();
8301
8670
  const [showListBoxPopover, setShowListBoxPopover] = useState$1(false);
8302
- const classes = useStyles$6();
8671
+ const classes = useStyles$7();
8303
8672
 
8304
8673
  const handleShowListBoxPopover = e => {
8305
8674
  if (e.currentTarget.contains(e.target)) {
@@ -8456,7 +8825,7 @@ const downArrow = props => _objectSpread2(_objectSpread2({}, props), {}, {
8456
8825
 
8457
8826
  var DownArrow = (props => SvgIcon(downArrow(props)));
8458
8827
 
8459
- const useStyles$5 = makeStyles(theme => ({
8828
+ const useStyles$6 = makeStyles(theme => ({
8460
8829
  item: {
8461
8830
  backgroundColor: theme.palette.background.paper,
8462
8831
  position: 'relative',
@@ -8479,7 +8848,7 @@ function MultiState(_ref) {
8479
8848
  moreAlignTo = null,
8480
8849
  onClose = () => {}
8481
8850
  } = _ref;
8482
- const classes = useStyles$5(); // If originated from the `more` item show fields directly
8851
+ const classes = useStyles$6(); // If originated from the `more` item show fields directly
8483
8852
 
8484
8853
  const [showFields, setShowFields] = useState$1(!!moreAlignTo);
8485
8854
  const [showStateIx, setShowStateIx] = useState$1(-1); // If originated from the `more` item align it
@@ -8619,7 +8988,7 @@ function MultiState(_ref) {
8619
8988
  }) : Component;
8620
8989
  }
8621
8990
 
8622
- const useStyles$4 = makeStyles(theme => ({
8991
+ const useStyles$5 = makeStyles(theme => ({
8623
8992
  item: {
8624
8993
  backgroundColor: theme.palette.background.paper,
8625
8994
  position: 'relative',
@@ -8640,7 +9009,7 @@ function More(_ref) {
8640
9009
  items = [],
8641
9010
  api
8642
9011
  } = _ref;
8643
- const classes = useStyles$4();
9012
+ const classes = useStyles$5();
8644
9013
  const theme = useTheme$1();
8645
9014
  const [showMoreItems, setShowMoreItems] = useState$1(false);
8646
9015
  const [showItemIx, setShowItemIx] = useState$1(-1);
@@ -8959,7 +9328,7 @@ function Nav(_ref) {
8959
9328
  }, /*#__PURE__*/React.createElement(ClearSelections, null))));
8960
9329
  }
8961
9330
 
8962
- const AppSelections = _ref => {
9331
+ function AppSelections(_ref) {
8963
9332
  let {
8964
9333
  app
8965
9334
  } = _ref;
@@ -8993,7 +9362,7 @@ const AppSelections = _ref => {
8993
9362
  api: appSelections,
8994
9363
  app: app
8995
9364
  })));
8996
- };
9365
+ }
8997
9366
  function mount(_ref2) {
8998
9367
  let {
8999
9368
  element,
@@ -9487,33 +9856,26 @@ AutoSizer.defaultProps = {
9487
9856
  style: {}
9488
9857
  };
9489
9858
 
9490
- function ListBoxPortal(_ref) {
9491
- let {
9492
- app,
9493
- fieldIdentifier,
9494
- stateName,
9495
- element,
9496
- options
9497
- } = _ref;
9498
- return ReactDOM.createPortal( /*#__PURE__*/React.createElement(ListBoxInline, {
9499
- app: app,
9500
- fieldIdentifier: fieldIdentifier,
9501
- stateName: stateName,
9502
- options: options
9503
- }), element);
9504
- }
9505
- function ListBoxInline(_ref2) {
9859
+ const useStyles$4 = makeStyles(() => ({
9860
+ listBoxHeader: {
9861
+ alignSelf: 'center',
9862
+ display: 'inline-flex'
9863
+ }
9864
+ }));
9865
+ function ListBoxInline(_ref) {
9506
9866
  let {
9507
9867
  app,
9508
9868
  fieldIdentifier,
9509
9869
  stateName = '$',
9510
- options = {}
9511
- } = _ref2;
9870
+ options = {},
9871
+ fieldDef
9872
+ } = _ref;
9512
9873
  const {
9513
9874
  title,
9514
9875
  direction,
9515
9876
  listLayout,
9516
9877
  search = true,
9878
+ focusSearch = false,
9517
9879
  toolbar = true,
9518
9880
  rangeSelect = true,
9519
9881
  checkboxes = false,
@@ -9521,8 +9883,42 @@ function ListBoxInline(_ref2) {
9521
9883
  sessionModel = undefined,
9522
9884
  selectionsApi = undefined,
9523
9885
  update = undefined,
9524
- dense = false
9886
+ dense = false,
9887
+ selectDisabled = () => false
9525
9888
  } = options;
9889
+ let {
9890
+ frequencyMode,
9891
+ histogram = false
9892
+ } = options;
9893
+
9894
+ if (fieldDef && fieldDef.failedToFetchFieldDef) {
9895
+ histogram = false;
9896
+ frequencyMode = 'N';
9897
+ }
9898
+
9899
+ switch (true) {
9900
+ case ['none', 'N', 'NX_FREQUENCY_NONE'].includes(frequencyMode):
9901
+ frequencyMode = 'N';
9902
+ break;
9903
+
9904
+ case ['value', 'V', 'NX_FREQUENCY_VALUE', 'default'].includes(frequencyMode):
9905
+ frequencyMode = 'V';
9906
+ break;
9907
+
9908
+ case ['percent', 'P', 'NX_FREQUENCY_PERCENT'].includes(frequencyMode):
9909
+ frequencyMode = 'P';
9910
+ break;
9911
+
9912
+ case ['relative', 'R', 'NX_FREQUENCY_RELATIVE'].includes(frequencyMode):
9913
+ frequencyMode = 'R';
9914
+ break;
9915
+
9916
+ default:
9917
+ frequencyMode = 'N';
9918
+ break;
9919
+ }
9920
+
9921
+ const getListdefFrequencyMode = () => histogram && frequencyMode === 'N' ? 'V' : frequencyMode;
9526
9922
 
9527
9923
  const listdef = _objectSpread2({
9528
9924
  qInfo: {
@@ -9531,6 +9927,7 @@ function ListBoxInline(_ref2) {
9531
9927
  qListObjectDef: {
9532
9928
  qStateName: stateName,
9533
9929
  qShowAlternatives: true,
9930
+ qFrequencyMode: getListdefFrequencyMode(),
9534
9931
  qInitialDataFetch: [{
9535
9932
  qTop: 0,
9536
9933
  qLeft: 0,
@@ -9560,6 +9957,13 @@ function ListBoxInline(_ref2) {
9560
9957
  fieldName = fieldIdentifier;
9561
9958
  }
9562
9959
 
9960
+ if (frequencyMode !== 'N' || histogram) {
9961
+ const field = fieldIdentifier.qLibraryId ? fieldDef : fieldName;
9962
+ listdef.frequencyMax = {
9963
+ qValueExpression: "Max(AGGR(Count([".concat(field, "]), [").concat(field, "]))")
9964
+ };
9965
+ }
9966
+
9563
9967
  let [model] = useSessionModel(listdef, sessionModel ? null : app, fieldName, stateName);
9564
9968
 
9565
9969
  if (sessionModel) {
@@ -9573,6 +9977,7 @@ function ListBoxInline(_ref2) {
9573
9977
  }
9574
9978
 
9575
9979
  const theme = useTheme$1();
9980
+ const classes = useStyles$4();
9576
9981
  const lock = useCallback(() => {
9577
9982
  model.lock('/qListObjectDef');
9578
9983
  }, [model]);
@@ -9580,11 +9985,24 @@ function ListBoxInline(_ref2) {
9580
9985
  model.unlock('/qListObjectDef');
9581
9986
  }, [model]);
9582
9987
  const {
9583
- translator
9988
+ translator,
9989
+ keyboardNavigation
9584
9990
  } = useContext(InstanceContext);
9585
9991
  const moreAlignTo = useRef();
9586
9992
  const [layout] = useLayout$1(model);
9587
9993
  const [showToolbar, setShowToolbar] = useState$1(false);
9994
+ const [showSearch, setShowSearch] = useState$1(false);
9995
+ const [autoFocusSearch, setAutoFocusSearch] = useState$1(focusSearch);
9996
+ const [keyboardActive, setKeyboardActive] = useState$1(false);
9997
+ const handleKeyDown = getListboxInlineKeyboardNavigation({
9998
+ setKeyboardActive
9999
+ }); // Expose the keyboard flags in the same way as the keyboard hook does.
10000
+
10001
+ const keyboard = {
10002
+ enabled: keyboardNavigation,
10003
+ // this will be static until we can access the useKeyboard hook
10004
+ active: keyboardActive
10005
+ };
9588
10006
  useEffect$1(() => {
9589
10007
  if (selections) {
9590
10008
  if (!selections.isModal(model)) {
@@ -9615,32 +10033,52 @@ function ListBoxInline(_ref2) {
9615
10033
  }) : [];
9616
10034
  const counts = layout.qListObject.qDimensionInfo.qStateCounts;
9617
10035
  const hasSelections = counts.qSelected + counts.qSelectedExcluded + counts.qLocked + counts.qLockedExcluded > 0;
9618
- const minHeight = 49 + (search ? 40 : 0) + 49;
10036
+ const searchVisible = (search === true || search === 'toggle' && showSearch) && !selectDisabled();
10037
+ const minHeight = 49 + (searchVisible ? 40 : 0) + 49;
10038
+
10039
+ const onShowSearch = () => {
10040
+ const newValue = !showSearch;
10041
+ setShowSearch(newValue);
10042
+ setAutoFocusSearch(newValue);
10043
+ };
10044
+
10045
+ const getSearchOrUnlock = () => search === 'toggle' && !hasSelections ? /*#__PURE__*/React.createElement(IconButton, {
10046
+ onClick: onShowSearch,
10047
+ tabIndex: -1,
10048
+ title: translator.get('Listbox.Search')
10049
+ }, /*#__PURE__*/React.createElement(SearchIcon, null)) : /*#__PURE__*/React.createElement(IconButton, {
10050
+ onClick: lock,
10051
+ tabIndex: -1,
10052
+ disabled: !hasSelections
10053
+ }, /*#__PURE__*/React.createElement(Unlock, null));
10054
+
9619
10055
  return /*#__PURE__*/React.createElement(Grid, {
9620
10056
  container: true,
10057
+ tabIndex: keyboard.enabled && !keyboard.active ? 0 : -1,
9621
10058
  direction: "column",
9622
10059
  spacing: 0,
9623
10060
  style: {
9624
10061
  height: '100%',
9625
10062
  minHeight: "".concat(minHeight, "px")
9626
- }
10063
+ },
10064
+ onKeyDown: handleKeyDown
9627
10065
  }, toolbar && /*#__PURE__*/React.createElement(Grid, {
9628
10066
  item: true,
9629
10067
  container: true,
9630
10068
  style: {
9631
- padding: theme.spacing(1),
9632
- borderBottom: "1px solid ".concat(theme.palette.divider)
10069
+ padding: theme.spacing(1)
9633
10070
  }
9634
10071
  }, /*#__PURE__*/React.createElement(Grid, {
9635
10072
  item: true
9636
10073
  }, isLocked ? /*#__PURE__*/React.createElement(IconButton, {
10074
+ tabIndex: -1,
9637
10075
  onClick: unlock,
9638
10076
  disabled: !isLocked
9639
- }, /*#__PURE__*/React.createElement(Lock, null)) : /*#__PURE__*/React.createElement(IconButton, {
9640
- onClick: lock,
9641
- disabled: !hasSelections
9642
- }, /*#__PURE__*/React.createElement(Unlock, null))), /*#__PURE__*/React.createElement(Grid, {
9643
- item: true
10077
+ }, /*#__PURE__*/React.createElement(Lock, {
10078
+ title: translator.get('Listbox.Unlock')
10079
+ })) : getSearchOrUnlock()), /*#__PURE__*/React.createElement(Grid, {
10080
+ item: true,
10081
+ className: classes.listBoxHeader
9644
10082
  }, /*#__PURE__*/React.createElement(Typography, {
9645
10083
  variant: "h6",
9646
10084
  noWrap: true
@@ -9668,43 +10106,109 @@ function ListBoxInline(_ref2) {
9668
10106
  onConfirm: () => {},
9669
10107
  onCancel: () => {}
9670
10108
  }
9671
- }))), search ? /*#__PURE__*/React.createElement(Grid, {
10109
+ }))), searchVisible && /*#__PURE__*/React.createElement(Grid, {
9672
10110
  item: true
9673
10111
  }, /*#__PURE__*/React.createElement(ListBoxSearch, {
9674
10112
  model: model,
9675
- autoFocus: false,
9676
- dense: dense
9677
- })) : '', /*#__PURE__*/React.createElement(Grid, {
10113
+ autoFocus: autoFocusSearch,
10114
+ dense: dense,
10115
+ keyboard: keyboard
10116
+ })), /*#__PURE__*/React.createElement(Grid, {
9678
10117
  item: true,
9679
10118
  xs: true
9680
10119
  }, /*#__PURE__*/React.createElement("div", {
9681
10120
  ref: moreAlignTo
9682
- }), /*#__PURE__*/React.createElement(AutoSizer, null, _ref3 => {
10121
+ }), /*#__PURE__*/React.createElement(AutoSizer, null, _ref2 => {
9683
10122
  let {
9684
10123
  height,
9685
10124
  width
9686
- } = _ref3;
10125
+ } = _ref2;
9687
10126
  return /*#__PURE__*/React.createElement(ListBox, {
9688
10127
  model: model,
9689
10128
  selections: selections,
9690
10129
  direction: direction,
9691
10130
  listLayout: listLayout,
10131
+ frequencyMode: frequencyMode,
10132
+ histogram: histogram,
9692
10133
  rangeSelect: rangeSelect,
9693
10134
  checkboxes: checkboxes,
9694
10135
  height: height,
9695
10136
  width: width,
9696
10137
  update: update,
9697
- dense: dense
10138
+ dense: dense,
10139
+ selectDisabled: selectDisabled,
10140
+ keyboard: keyboard
9698
10141
  });
9699
10142
  })));
9700
10143
  }
9701
10144
 
9702
- const idGen = [[10, 31], [0, 31], [0, 31], [0, 31], [0, 31], [0, 31]];
9703
-
9704
- function toChar(_ref) {
9705
- let [min, max] = _ref;
9706
- return (min + (Math.random() * (max - min) | 0)).toString(32);
9707
- }
10145
+ function ListBoxFetchMasterItem(_ref) {
10146
+ let {
10147
+ app,
10148
+ fieldIdentifier,
10149
+ stateName = '$',
10150
+ options = {}
10151
+ } = _ref;
10152
+ const [fieldDef, setFieldDef] = useState$1('');
10153
+ const [isFetchingData, setIsFetchingData] = useState$1(false);
10154
+ useEffect$1(() => {
10155
+ async function fetchData() {
10156
+ setIsFetchingData(true);
10157
+
10158
+ try {
10159
+ const dim = await app.getDimension(fieldIdentifier.qLibraryId);
10160
+ const dimLayout = await dim.getLayout();
10161
+ setFieldDef(dimLayout.qDim.qFieldDefs ? dimLayout.qDim.qFieldDefs[0] : '');
10162
+ setIsFetchingData(false);
10163
+ } catch (e) {
10164
+ setIsFetchingData(false);
10165
+ setFieldDef({
10166
+ failedToFetchFieldDef: true
10167
+ });
10168
+ throw new Error("Disabling frequency count and histogram: ".concat(e && e.message));
10169
+ }
10170
+ }
10171
+
10172
+ fetchData();
10173
+ }, []);
10174
+
10175
+ if (isFetchingData) {
10176
+ return null;
10177
+ }
10178
+
10179
+ return /*#__PURE__*/React.createElement(ListBoxInline, {
10180
+ app: app,
10181
+ fieldIdentifier: fieldIdentifier,
10182
+ stateName: stateName,
10183
+ options: options,
10184
+ fieldDef: fieldDef
10185
+ });
10186
+ }
10187
+ function ListBoxPortal(_ref2) {
10188
+ let {
10189
+ app,
10190
+ fieldIdentifier,
10191
+ stateName,
10192
+ element,
10193
+ options
10194
+ } = _ref2;
10195
+ const isFrequencyMaxNeeded = options.histogram || options.frequencyMode !== 'N';
10196
+ const TheComponent = fieldIdentifier.qLibraryId && isFrequencyMaxNeeded ? ListBoxFetchMasterItem : ListBoxInline;
10197
+ return ReactDOM.createPortal( /*#__PURE__*/React.createElement(TheComponent, {
10198
+ app: app,
10199
+ fieldIdentifier: fieldIdentifier,
10200
+ stateName: stateName,
10201
+ element: element,
10202
+ options: options
10203
+ }), element);
10204
+ }
10205
+
10206
+ const idGen = [[10, 31], [0, 31], [0, 31], [0, 31], [0, 31], [0, 31]];
10207
+
10208
+ function toChar(_ref) {
10209
+ let [min, max] = _ref;
10210
+ return (min + (Math.random() * (max - min) | 0)).toString(32);
10211
+ }
9708
10212
 
9709
10213
  function uid() {
9710
10214
  return idGen.map(toChar).join('');
@@ -10874,7 +11378,7 @@ var WarningTriangle = (props => SvgIcon(warning(props)));
10874
11378
 
10875
11379
  /* eslint-disable react/no-array-index-key */
10876
11380
 
10877
- const DescriptionRow = _ref => {
11381
+ function DescriptionRow(_ref) {
10878
11382
  let {
10879
11383
  d
10880
11384
  } = _ref;
@@ -10931,9 +11435,9 @@ const DescriptionRow = _ref => {
10931
11435
  fontWeight: 400
10932
11436
  }
10933
11437
  }, d.label))));
10934
- };
11438
+ }
10935
11439
 
10936
- const Descriptions = _ref2 => {
11440
+ function Descriptions(_ref2) {
10937
11441
  let {
10938
11442
  data
10939
11443
  } = _ref2;
@@ -10966,7 +11470,7 @@ const Descriptions = _ref2 => {
10966
11470
  color: "textSecondary"
10967
11471
  }, e.title), Rows);
10968
11472
  }));
10969
- };
11473
+ }
10970
11474
 
10971
11475
  function Error$1(_ref3) {
10972
11476
  let {
@@ -11071,7 +11575,7 @@ const useStyles$2 = makeStyles$1(() => ({
11071
11575
  }
11072
11576
  }
11073
11577
  }));
11074
- const Cancel = _ref => {
11578
+ function Cancel(_ref) {
11075
11579
  let {
11076
11580
  cancel,
11077
11581
  translator
@@ -11097,8 +11601,8 @@ const Cancel = _ref => {
11097
11601
  variant: "contained",
11098
11602
  onClick: cancel
11099
11603
  }, translator.get('Cancel'))));
11100
- };
11101
- const Retry = _ref2 => {
11604
+ }
11605
+ function Retry(_ref2) {
11102
11606
  let {
11103
11607
  retry,
11104
11608
  translator
@@ -11122,7 +11626,7 @@ const Retry = _ref2 => {
11122
11626
  variant: "contained",
11123
11627
  onClick: retry
11124
11628
  }, props), translator.get('Retry'))));
11125
- };
11629
+ }
11126
11630
  function LongRunningQuery(_ref3) {
11127
11631
  let {
11128
11632
  canCancel,
@@ -11216,7 +11720,7 @@ const useStyles$1 = makeStyles$1(theme => ({
11216
11720
  }
11217
11721
  }));
11218
11722
 
11219
- const Header = _ref => {
11723
+ function Header(_ref) {
11220
11724
  let {
11221
11725
  layout,
11222
11726
  sn,
@@ -11293,7 +11797,7 @@ const Header = _ref => {
11293
11797
  }, layout.subtitle))), /*#__PURE__*/React.createElement(Grid, {
11294
11798
  item: true
11295
11799
  }, Toolbar));
11296
- };
11800
+ }
11297
11801
 
11298
11802
  /**
11299
11803
  * @interface
@@ -11312,7 +11816,7 @@ const useStyles = makeStyles$1(theme => ({
11312
11816
  }
11313
11817
  }));
11314
11818
 
11315
- const Footer = _ref => {
11819
+ function Footer(_ref) {
11316
11820
  let {
11317
11821
  layout
11318
11822
  } = _ref;
@@ -11329,7 +11833,7 @@ const Footer = _ref => {
11329
11833
  variant: "body2",
11330
11834
  className: CellFooter.className
11331
11835
  }, layout.footnote))) : null;
11332
- };
11836
+ }
11333
11837
 
11334
11838
  class RenderDebouncer {
11335
11839
  constructor() {
@@ -11399,7 +11903,7 @@ const VizElement = {
11399
11903
  className: 'njs-viz'
11400
11904
  };
11401
11905
 
11402
- const Supernova = _ref => {
11906
+ function Supernova(_ref) {
11403
11907
  let {
11404
11908
  sn,
11405
11909
  snOptions: options,
@@ -11519,7 +12023,7 @@ const Supernova = _ref => {
11519
12023
  height: '100%'
11520
12024
  }
11521
12025
  }));
11522
- };
12026
+ }
11523
12027
 
11524
12028
  /**
11525
12029
  * @interface
@@ -11597,7 +12101,7 @@ const contentReducer = (state, action) => {
11597
12101
  }
11598
12102
  };
11599
12103
 
11600
- const LoadingSn = _ref => {
12104
+ function LoadingSn(_ref) {
11601
12105
  let {
11602
12106
  delay = 750
11603
12107
  } = _ref;
@@ -11607,7 +12111,7 @@ const LoadingSn = _ref => {
11607
12111
  return () => clearTimeout(handle);
11608
12112
  }, []);
11609
12113
  return showLoading ? /*#__PURE__*/React.createElement(Loading, null) : null;
11610
- };
12114
+ }
11611
12115
 
11612
12116
  const handleModal = _ref2 => {
11613
12117
  let {
@@ -12182,7 +12686,8 @@ function isEqual(a, b) {
12182
12686
  }
12183
12687
 
12184
12688
  return a === b;
12185
- }
12689
+ } // eslint-disable-next-line default-param-last
12690
+
12186
12691
 
12187
12692
  function getPatches() {
12188
12693
  let path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '/';
@@ -13054,7 +13559,7 @@ function actionhero (_ref) {
13054
13559
  /* eslint no-console: 0 */
13055
13560
 
13056
13561
  /* eslint no-use-before-define: 0 */
13057
- // Hooks implementation heavily inspired by prect hooks
13562
+ // Hooks implementation heavily inspired by preact hooks
13058
13563
  let currentComponent;
13059
13564
  let currentIndex;
13060
13565
 
@@ -14864,1556 +15369,1603 @@ function generatorFn(UserSN, galaxy) {
14864
15369
  var semver = {exports: {}};
14865
15370
 
14866
15371
  (function (module, exports) {
14867
- exports = module.exports = SemVer;
14868
- var debug;
14869
- /* istanbul ignore next */
14870
-
14871
- if (typeof process === 'object' && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
14872
- debug = function () {
14873
- var args = Array.prototype.slice.call(arguments, 0);
14874
- args.unshift('SEMVER');
14875
- console.log.apply(console, args);
14876
- };
14877
- } else {
14878
- debug = function () {};
14879
- } // Note: this is the semver.org version of the spec that it implements
14880
- // Not necessarily the package version of this code.
14881
-
14882
-
14883
- exports.SEMVER_SPEC_VERSION = '2.0.0';
14884
- var MAX_LENGTH = 256;
14885
- var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
14886
- /* istanbul ignore next */
14887
- 9007199254740991; // Max safe segment length for coercion.
14888
-
14889
- var MAX_SAFE_COMPONENT_LENGTH = 16; // The actual regexps go on exports.re
14890
-
14891
- var re = exports.re = [];
14892
- var src = exports.src = [];
14893
- var t = exports.tokens = {};
14894
- var R = 0;
14895
-
14896
- function tok(n) {
14897
- t[n] = R++;
14898
- } // The following Regular Expressions can be used for tokenizing,
14899
- // validating, and parsing SemVer version strings.
14900
- // ## Numeric Identifier
14901
- // A single `0`, or a non-zero digit followed by zero or more digits.
14902
-
14903
-
14904
- tok('NUMERICIDENTIFIER');
14905
- src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*';
14906
- tok('NUMERICIDENTIFIERLOOSE');
14907
- src[t.NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
14908
- // Zero or more digits, followed by a letter or hyphen, and then zero or
14909
- // more letters, digits, or hyphens.
14910
-
14911
- tok('NONNUMERICIDENTIFIER');
14912
- src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
14913
- // Three dot-separated numeric identifiers.
14914
-
14915
- tok('MAINVERSION');
14916
- src[t.MAINVERSION] = '(' + src[t.NUMERICIDENTIFIER] + ')\\.' + '(' + src[t.NUMERICIDENTIFIER] + ')\\.' + '(' + src[t.NUMERICIDENTIFIER] + ')';
14917
- tok('MAINVERSIONLOOSE');
14918
- src[t.MAINVERSIONLOOSE] = '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
14919
- // A numeric identifier, or a non-numeric identifier.
14920
-
14921
- tok('PRERELEASEIDENTIFIER');
14922
- src[t.PRERELEASEIDENTIFIER] = '(?:' + src[t.NUMERICIDENTIFIER] + '|' + src[t.NONNUMERICIDENTIFIER] + ')';
14923
- tok('PRERELEASEIDENTIFIERLOOSE');
14924
- src[t.PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[t.NUMERICIDENTIFIERLOOSE] + '|' + src[t.NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
14925
- // Hyphen, followed by one or more dot-separated pre-release version
14926
- // identifiers.
14927
-
14928
- tok('PRERELEASE');
14929
- src[t.PRERELEASE] = '(?:-(' + src[t.PRERELEASEIDENTIFIER] + '(?:\\.' + src[t.PRERELEASEIDENTIFIER] + ')*))';
14930
- tok('PRERELEASELOOSE');
14931
- src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[t.PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
14932
- // Any combination of digits, letters, or hyphens.
14933
-
14934
- tok('BUILDIDENTIFIER');
14935
- src[t.BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
14936
- // Plus sign, followed by one or more period-separated build metadata
14937
- // identifiers.
14938
-
14939
- tok('BUILD');
14940
- src[t.BUILD] = '(?:\\+(' + src[t.BUILDIDENTIFIER] + '(?:\\.' + src[t.BUILDIDENTIFIER] + ')*))'; // ## Full Version String
14941
- // A main version, followed optionally by a pre-release version and
14942
- // build metadata.
14943
- // Note that the only major, minor, patch, and pre-release sections of
14944
- // the version string are capturing groups. The build metadata is not a
14945
- // capturing group, because it should not ever be used in version
14946
- // comparison.
14947
-
14948
- tok('FULL');
14949
- tok('FULLPLAIN');
14950
- src[t.FULLPLAIN] = 'v?' + src[t.MAINVERSION] + src[t.PRERELEASE] + '?' + src[t.BUILD] + '?';
14951
- src[t.FULL] = '^' + src[t.FULLPLAIN] + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
14952
- // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
14953
- // common in the npm registry.
14954
-
14955
- tok('LOOSEPLAIN');
14956
- src[t.LOOSEPLAIN] = '[v=\\s]*' + src[t.MAINVERSIONLOOSE] + src[t.PRERELEASELOOSE] + '?' + src[t.BUILD] + '?';
14957
- tok('LOOSE');
14958
- src[t.LOOSE] = '^' + src[t.LOOSEPLAIN] + '$';
14959
- tok('GTLT');
14960
- src[t.GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
14961
- // Note that "x.x" is a valid xRange identifer, meaning "any version"
14962
- // Only the first item is strictly required.
14963
-
14964
- tok('XRANGEIDENTIFIERLOOSE');
14965
- src[t.XRANGEIDENTIFIERLOOSE] = src[t.NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
14966
- tok('XRANGEIDENTIFIER');
14967
- src[t.XRANGEIDENTIFIER] = src[t.NUMERICIDENTIFIER] + '|x|X|\\*';
14968
- tok('XRANGEPLAIN');
14969
- src[t.XRANGEPLAIN] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' + '(?:' + src[t.PRERELEASE] + ')?' + src[t.BUILD] + '?' + ')?)?';
14970
- tok('XRANGEPLAINLOOSE');
14971
- src[t.XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[t.PRERELEASELOOSE] + ')?' + src[t.BUILD] + '?' + ')?)?';
14972
- tok('XRANGE');
14973
- src[t.XRANGE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAIN] + '$';
14974
- tok('XRANGELOOSE');
14975
- src[t.XRANGELOOSE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAINLOOSE] + '$'; // Coercion.
14976
- // Extract anything that could conceivably be a part of a valid semver
14977
-
14978
- tok('COERCE');
14979
- src[t.COERCE] = '(^|[^\\d])' + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:$|[^\\d])';
14980
- tok('COERCERTL');
14981
- re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g'); // Tilde ranges.
14982
- // Meaning is "reasonably at or greater than"
14983
-
14984
- tok('LONETILDE');
14985
- src[t.LONETILDE] = '(?:~>?)';
14986
- tok('TILDETRIM');
14987
- src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+';
14988
- re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g');
14989
- var tildeTrimReplace = '$1~';
14990
- tok('TILDE');
14991
- src[t.TILDE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAIN] + '$';
14992
- tok('TILDELOOSE');
14993
- src[t.TILDELOOSE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAINLOOSE] + '$'; // Caret ranges.
14994
- // Meaning is "at least and backwards compatible with"
14995
-
14996
- tok('LONECARET');
14997
- src[t.LONECARET] = '(?:\\^)';
14998
- tok('CARETTRIM');
14999
- src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+';
15000
- re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g');
15001
- var caretTrimReplace = '$1^';
15002
- tok('CARET');
15003
- src[t.CARET] = '^' + src[t.LONECARET] + src[t.XRANGEPLAIN] + '$';
15004
- tok('CARETLOOSE');
15005
- src[t.CARETLOOSE] = '^' + src[t.LONECARET] + src[t.XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
15006
-
15007
- tok('COMPARATORLOOSE');
15008
- src[t.COMPARATORLOOSE] = '^' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + ')$|^$';
15009
- tok('COMPARATOR');
15010
- src[t.COMPARATOR] = '^' + src[t.GTLT] + '\\s*(' + src[t.FULLPLAIN] + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
15011
- // it modifies, so that `> 1.2.3` ==> `>1.2.3`
15012
-
15013
- tok('COMPARATORTRIM');
15014
- src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + '|' + src[t.XRANGEPLAIN] + ')'; // this one has to use the /g flag
15015
-
15016
- re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g');
15017
- var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
15018
- // Note that these all use the loose form, because they'll be
15019
- // checked against either the strict or loose comparator form
15020
- // later.
15021
-
15022
- tok('HYPHENRANGE');
15023
- src[t.HYPHENRANGE] = '^\\s*(' + src[t.XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[t.XRANGEPLAIN] + ')' + '\\s*$';
15024
- tok('HYPHENRANGELOOSE');
15025
- src[t.HYPHENRANGELOOSE] = '^\\s*(' + src[t.XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[t.XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
15026
-
15027
- tok('STAR');
15028
- src[t.STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
15029
- // All are flag-free, unless they were created above with a flag.
15030
-
15031
- for (var i = 0; i < R; i++) {
15032
- debug(i, src[i]);
15033
-
15034
- if (!re[i]) {
15035
- re[i] = new RegExp(src[i]);
15036
- }
15037
- }
15038
-
15039
- exports.parse = parse;
15040
-
15041
- function parse(version, options) {
15042
- if (!options || typeof options !== 'object') {
15043
- options = {
15044
- loose: !!options,
15045
- includePrerelease: false
15046
- };
15047
- }
15372
+ exports = module.exports = SemVer;
15373
+
15374
+ var debug;
15375
+ /* istanbul ignore next */
15376
+ if (typeof process === 'object' &&
15377
+ process.env &&
15378
+ process.env.NODE_DEBUG &&
15379
+ /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
15380
+ debug = function () {
15381
+ var args = Array.prototype.slice.call(arguments, 0);
15382
+ args.unshift('SEMVER');
15383
+ console.log.apply(console, args);
15384
+ };
15385
+ } else {
15386
+ debug = function () {};
15387
+ }
15048
15388
 
15049
- if (version instanceof SemVer) {
15050
- return version;
15051
- }
15389
+ // Note: this is the semver.org version of the spec that it implements
15390
+ // Not necessarily the package version of this code.
15391
+ exports.SEMVER_SPEC_VERSION = '2.0.0';
15052
15392
 
15053
- if (typeof version !== 'string') {
15054
- return null;
15055
- }
15393
+ var MAX_LENGTH = 256;
15394
+ var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
15395
+ /* istanbul ignore next */ 9007199254740991;
15056
15396
 
15057
- if (version.length > MAX_LENGTH) {
15058
- return null;
15059
- }
15397
+ // Max safe segment length for coercion.
15398
+ var MAX_SAFE_COMPONENT_LENGTH = 16;
15060
15399
 
15061
- var r = options.loose ? re[t.LOOSE] : re[t.FULL];
15400
+ // The actual regexps go on exports.re
15401
+ var re = exports.re = [];
15402
+ var src = exports.src = [];
15403
+ var t = exports.tokens = {};
15404
+ var R = 0;
15062
15405
 
15063
- if (!r.test(version)) {
15064
- return null;
15065
- }
15406
+ function tok (n) {
15407
+ t[n] = R++;
15408
+ }
15066
15409
 
15067
- try {
15068
- return new SemVer(version, options);
15069
- } catch (er) {
15070
- return null;
15071
- }
15410
+ // The following Regular Expressions can be used for tokenizing,
15411
+ // validating, and parsing SemVer version strings.
15412
+
15413
+ // ## Numeric Identifier
15414
+ // A single `0`, or a non-zero digit followed by zero or more digits.
15415
+
15416
+ tok('NUMERICIDENTIFIER');
15417
+ src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*';
15418
+ tok('NUMERICIDENTIFIERLOOSE');
15419
+ src[t.NUMERICIDENTIFIERLOOSE] = '[0-9]+';
15420
+
15421
+ // ## Non-numeric Identifier
15422
+ // Zero or more digits, followed by a letter or hyphen, and then zero or
15423
+ // more letters, digits, or hyphens.
15424
+
15425
+ tok('NONNUMERICIDENTIFIER');
15426
+ src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*';
15427
+
15428
+ // ## Main Version
15429
+ // Three dot-separated numeric identifiers.
15430
+
15431
+ tok('MAINVERSION');
15432
+ src[t.MAINVERSION] = '(' + src[t.NUMERICIDENTIFIER] + ')\\.' +
15433
+ '(' + src[t.NUMERICIDENTIFIER] + ')\\.' +
15434
+ '(' + src[t.NUMERICIDENTIFIER] + ')';
15435
+
15436
+ tok('MAINVERSIONLOOSE');
15437
+ src[t.MAINVERSIONLOOSE] = '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' +
15438
+ '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' +
15439
+ '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')';
15440
+
15441
+ // ## Pre-release Version Identifier
15442
+ // A numeric identifier, or a non-numeric identifier.
15443
+
15444
+ tok('PRERELEASEIDENTIFIER');
15445
+ src[t.PRERELEASEIDENTIFIER] = '(?:' + src[t.NUMERICIDENTIFIER] +
15446
+ '|' + src[t.NONNUMERICIDENTIFIER] + ')';
15447
+
15448
+ tok('PRERELEASEIDENTIFIERLOOSE');
15449
+ src[t.PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[t.NUMERICIDENTIFIERLOOSE] +
15450
+ '|' + src[t.NONNUMERICIDENTIFIER] + ')';
15451
+
15452
+ // ## Pre-release Version
15453
+ // Hyphen, followed by one or more dot-separated pre-release version
15454
+ // identifiers.
15455
+
15456
+ tok('PRERELEASE');
15457
+ src[t.PRERELEASE] = '(?:-(' + src[t.PRERELEASEIDENTIFIER] +
15458
+ '(?:\\.' + src[t.PRERELEASEIDENTIFIER] + ')*))';
15459
+
15460
+ tok('PRERELEASELOOSE');
15461
+ src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] +
15462
+ '(?:\\.' + src[t.PRERELEASEIDENTIFIERLOOSE] + ')*))';
15463
+
15464
+ // ## Build Metadata Identifier
15465
+ // Any combination of digits, letters, or hyphens.
15466
+
15467
+ tok('BUILDIDENTIFIER');
15468
+ src[t.BUILDIDENTIFIER] = '[0-9A-Za-z-]+';
15469
+
15470
+ // ## Build Metadata
15471
+ // Plus sign, followed by one or more period-separated build metadata
15472
+ // identifiers.
15473
+
15474
+ tok('BUILD');
15475
+ src[t.BUILD] = '(?:\\+(' + src[t.BUILDIDENTIFIER] +
15476
+ '(?:\\.' + src[t.BUILDIDENTIFIER] + ')*))';
15477
+
15478
+ // ## Full Version String
15479
+ // A main version, followed optionally by a pre-release version and
15480
+ // build metadata.
15481
+
15482
+ // Note that the only major, minor, patch, and pre-release sections of
15483
+ // the version string are capturing groups. The build metadata is not a
15484
+ // capturing group, because it should not ever be used in version
15485
+ // comparison.
15486
+
15487
+ tok('FULL');
15488
+ tok('FULLPLAIN');
15489
+ src[t.FULLPLAIN] = 'v?' + src[t.MAINVERSION] +
15490
+ src[t.PRERELEASE] + '?' +
15491
+ src[t.BUILD] + '?';
15492
+
15493
+ src[t.FULL] = '^' + src[t.FULLPLAIN] + '$';
15494
+
15495
+ // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
15496
+ // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
15497
+ // common in the npm registry.
15498
+ tok('LOOSEPLAIN');
15499
+ src[t.LOOSEPLAIN] = '[v=\\s]*' + src[t.MAINVERSIONLOOSE] +
15500
+ src[t.PRERELEASELOOSE] + '?' +
15501
+ src[t.BUILD] + '?';
15502
+
15503
+ tok('LOOSE');
15504
+ src[t.LOOSE] = '^' + src[t.LOOSEPLAIN] + '$';
15505
+
15506
+ tok('GTLT');
15507
+ src[t.GTLT] = '((?:<|>)?=?)';
15508
+
15509
+ // Something like "2.*" or "1.2.x".
15510
+ // Note that "x.x" is a valid xRange identifer, meaning "any version"
15511
+ // Only the first item is strictly required.
15512
+ tok('XRANGEIDENTIFIERLOOSE');
15513
+ src[t.XRANGEIDENTIFIERLOOSE] = src[t.NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
15514
+ tok('XRANGEIDENTIFIER');
15515
+ src[t.XRANGEIDENTIFIER] = src[t.NUMERICIDENTIFIER] + '|x|X|\\*';
15516
+
15517
+ tok('XRANGEPLAIN');
15518
+ src[t.XRANGEPLAIN] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIER] + ')' +
15519
+ '(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' +
15520
+ '(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' +
15521
+ '(?:' + src[t.PRERELEASE] + ')?' +
15522
+ src[t.BUILD] + '?' +
15523
+ ')?)?';
15524
+
15525
+ tok('XRANGEPLAINLOOSE');
15526
+ src[t.XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
15527
+ '(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
15528
+ '(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
15529
+ '(?:' + src[t.PRERELEASELOOSE] + ')?' +
15530
+ src[t.BUILD] + '?' +
15531
+ ')?)?';
15532
+
15533
+ tok('XRANGE');
15534
+ src[t.XRANGE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAIN] + '$';
15535
+ tok('XRANGELOOSE');
15536
+ src[t.XRANGELOOSE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAINLOOSE] + '$';
15537
+
15538
+ // Coercion.
15539
+ // Extract anything that could conceivably be a part of a valid semver
15540
+ tok('COERCE');
15541
+ src[t.COERCE] = '(^|[^\\d])' +
15542
+ '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' +
15543
+ '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
15544
+ '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
15545
+ '(?:$|[^\\d])';
15546
+ tok('COERCERTL');
15547
+ re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g');
15548
+
15549
+ // Tilde ranges.
15550
+ // Meaning is "reasonably at or greater than"
15551
+ tok('LONETILDE');
15552
+ src[t.LONETILDE] = '(?:~>?)';
15553
+
15554
+ tok('TILDETRIM');
15555
+ src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+';
15556
+ re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g');
15557
+ var tildeTrimReplace = '$1~';
15558
+
15559
+ tok('TILDE');
15560
+ src[t.TILDE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAIN] + '$';
15561
+ tok('TILDELOOSE');
15562
+ src[t.TILDELOOSE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAINLOOSE] + '$';
15563
+
15564
+ // Caret ranges.
15565
+ // Meaning is "at least and backwards compatible with"
15566
+ tok('LONECARET');
15567
+ src[t.LONECARET] = '(?:\\^)';
15568
+
15569
+ tok('CARETTRIM');
15570
+ src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+';
15571
+ re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g');
15572
+ var caretTrimReplace = '$1^';
15573
+
15574
+ tok('CARET');
15575
+ src[t.CARET] = '^' + src[t.LONECARET] + src[t.XRANGEPLAIN] + '$';
15576
+ tok('CARETLOOSE');
15577
+ src[t.CARETLOOSE] = '^' + src[t.LONECARET] + src[t.XRANGEPLAINLOOSE] + '$';
15578
+
15579
+ // A simple gt/lt/eq thing, or just "" to indicate "any version"
15580
+ tok('COMPARATORLOOSE');
15581
+ src[t.COMPARATORLOOSE] = '^' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + ')$|^$';
15582
+ tok('COMPARATOR');
15583
+ src[t.COMPARATOR] = '^' + src[t.GTLT] + '\\s*(' + src[t.FULLPLAIN] + ')$|^$';
15584
+
15585
+ // An expression to strip any whitespace between the gtlt and the thing
15586
+ // it modifies, so that `> 1.2.3` ==> `>1.2.3`
15587
+ tok('COMPARATORTRIM');
15588
+ src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] +
15589
+ '\\s*(' + src[t.LOOSEPLAIN] + '|' + src[t.XRANGEPLAIN] + ')';
15590
+
15591
+ // this one has to use the /g flag
15592
+ re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g');
15593
+ var comparatorTrimReplace = '$1$2$3';
15594
+
15595
+ // Something like `1.2.3 - 1.2.4`
15596
+ // Note that these all use the loose form, because they'll be
15597
+ // checked against either the strict or loose comparator form
15598
+ // later.
15599
+ tok('HYPHENRANGE');
15600
+ src[t.HYPHENRANGE] = '^\\s*(' + src[t.XRANGEPLAIN] + ')' +
15601
+ '\\s+-\\s+' +
15602
+ '(' + src[t.XRANGEPLAIN] + ')' +
15603
+ '\\s*$';
15604
+
15605
+ tok('HYPHENRANGELOOSE');
15606
+ src[t.HYPHENRANGELOOSE] = '^\\s*(' + src[t.XRANGEPLAINLOOSE] + ')' +
15607
+ '\\s+-\\s+' +
15608
+ '(' + src[t.XRANGEPLAINLOOSE] + ')' +
15609
+ '\\s*$';
15610
+
15611
+ // Star ranges basically just allow anything at all.
15612
+ tok('STAR');
15613
+ src[t.STAR] = '(<|>)?=?\\s*\\*';
15614
+
15615
+ // Compile to actual regexp objects.
15616
+ // All are flag-free, unless they were created above with a flag.
15617
+ for (var i = 0; i < R; i++) {
15618
+ debug(i, src[i]);
15619
+ if (!re[i]) {
15620
+ re[i] = new RegExp(src[i]);
15621
+ }
15622
+ }
15623
+
15624
+ exports.parse = parse;
15625
+ function parse (version, options) {
15626
+ if (!options || typeof options !== 'object') {
15627
+ options = {
15628
+ loose: !!options,
15629
+ includePrerelease: false
15630
+ };
15072
15631
  }
15073
15632
 
15074
- exports.valid = valid;
15633
+ if (version instanceof SemVer) {
15634
+ return version
15635
+ }
15075
15636
 
15076
- function valid(version, options) {
15077
- var v = parse(version, options);
15078
- return v ? v.version : null;
15637
+ if (typeof version !== 'string') {
15638
+ return null
15079
15639
  }
15080
15640
 
15081
- exports.clean = clean;
15641
+ if (version.length > MAX_LENGTH) {
15642
+ return null
15643
+ }
15082
15644
 
15083
- function clean(version, options) {
15084
- var s = parse(version.trim().replace(/^[=v]+/, ''), options);
15085
- return s ? s.version : null;
15645
+ var r = options.loose ? re[t.LOOSE] : re[t.FULL];
15646
+ if (!r.test(version)) {
15647
+ return null
15086
15648
  }
15087
15649
 
15088
- exports.SemVer = SemVer;
15650
+ try {
15651
+ return new SemVer(version, options)
15652
+ } catch (er) {
15653
+ return null
15654
+ }
15655
+ }
15089
15656
 
15090
- function SemVer(version, options) {
15091
- if (!options || typeof options !== 'object') {
15092
- options = {
15093
- loose: !!options,
15094
- includePrerelease: false
15095
- };
15096
- }
15657
+ exports.valid = valid;
15658
+ function valid (version, options) {
15659
+ var v = parse(version, options);
15660
+ return v ? v.version : null
15661
+ }
15097
15662
 
15098
- if (version instanceof SemVer) {
15099
- if (version.loose === options.loose) {
15100
- return version;
15101
- } else {
15102
- version = version.version;
15103
- }
15104
- } else if (typeof version !== 'string') {
15105
- throw new TypeError('Invalid Version: ' + version);
15106
- }
15663
+ exports.clean = clean;
15664
+ function clean (version, options) {
15665
+ var s = parse(version.trim().replace(/^[=v]+/, ''), options);
15666
+ return s ? s.version : null
15667
+ }
15107
15668
 
15108
- if (version.length > MAX_LENGTH) {
15109
- throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
15110
- }
15669
+ exports.SemVer = SemVer;
15111
15670
 
15112
- if (!(this instanceof SemVer)) {
15113
- return new SemVer(version, options);
15671
+ function SemVer (version, options) {
15672
+ if (!options || typeof options !== 'object') {
15673
+ options = {
15674
+ loose: !!options,
15675
+ includePrerelease: false
15676
+ };
15677
+ }
15678
+ if (version instanceof SemVer) {
15679
+ if (version.loose === options.loose) {
15680
+ return version
15681
+ } else {
15682
+ version = version.version;
15114
15683
  }
15684
+ } else if (typeof version !== 'string') {
15685
+ throw new TypeError('Invalid Version: ' + version)
15686
+ }
15115
15687
 
15116
- debug('SemVer', version, options);
15117
- this.options = options;
15118
- this.loose = !!options.loose;
15119
- var m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
15688
+ if (version.length > MAX_LENGTH) {
15689
+ throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters')
15690
+ }
15120
15691
 
15121
- if (!m) {
15122
- throw new TypeError('Invalid Version: ' + version);
15123
- }
15692
+ if (!(this instanceof SemVer)) {
15693
+ return new SemVer(version, options)
15694
+ }
15124
15695
 
15125
- this.raw = version; // these are actually numbers
15696
+ debug('SemVer', version, options);
15697
+ this.options = options;
15698
+ this.loose = !!options.loose;
15126
15699
 
15127
- this.major = +m[1];
15128
- this.minor = +m[2];
15129
- this.patch = +m[3];
15700
+ var m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
15130
15701
 
15131
- if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
15132
- throw new TypeError('Invalid major version');
15133
- }
15702
+ if (!m) {
15703
+ throw new TypeError('Invalid Version: ' + version)
15704
+ }
15134
15705
 
15135
- if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
15136
- throw new TypeError('Invalid minor version');
15137
- }
15706
+ this.raw = version;
15707
+
15708
+ // these are actually numbers
15709
+ this.major = +m[1];
15710
+ this.minor = +m[2];
15711
+ this.patch = +m[3];
15138
15712
 
15139
- if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
15140
- throw new TypeError('Invalid patch version');
15141
- } // numberify any prerelease numeric ids
15713
+ if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
15714
+ throw new TypeError('Invalid major version')
15715
+ }
15142
15716
 
15717
+ if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
15718
+ throw new TypeError('Invalid minor version')
15719
+ }
15143
15720
 
15144
- if (!m[4]) {
15145
- this.prerelease = [];
15146
- } else {
15147
- this.prerelease = m[4].split('.').map(function (id) {
15148
- if (/^[0-9]+$/.test(id)) {
15149
- var num = +id;
15721
+ if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
15722
+ throw new TypeError('Invalid patch version')
15723
+ }
15150
15724
 
15151
- if (num >= 0 && num < MAX_SAFE_INTEGER) {
15152
- return num;
15153
- }
15725
+ // numberify any prerelease numeric ids
15726
+ if (!m[4]) {
15727
+ this.prerelease = [];
15728
+ } else {
15729
+ this.prerelease = m[4].split('.').map(function (id) {
15730
+ if (/^[0-9]+$/.test(id)) {
15731
+ var num = +id;
15732
+ if (num >= 0 && num < MAX_SAFE_INTEGER) {
15733
+ return num
15154
15734
  }
15735
+ }
15736
+ return id
15737
+ });
15738
+ }
15155
15739
 
15156
- return id;
15157
- });
15158
- }
15740
+ this.build = m[5] ? m[5].split('.') : [];
15741
+ this.format();
15742
+ }
15159
15743
 
15160
- this.build = m[5] ? m[5].split('.') : [];
15161
- this.format();
15744
+ SemVer.prototype.format = function () {
15745
+ this.version = this.major + '.' + this.minor + '.' + this.patch;
15746
+ if (this.prerelease.length) {
15747
+ this.version += '-' + this.prerelease.join('.');
15162
15748
  }
15749
+ return this.version
15750
+ };
15163
15751
 
15164
- SemVer.prototype.format = function () {
15165
- this.version = this.major + '.' + this.minor + '.' + this.patch;
15752
+ SemVer.prototype.toString = function () {
15753
+ return this.version
15754
+ };
15166
15755
 
15167
- if (this.prerelease.length) {
15168
- this.version += '-' + this.prerelease.join('.');
15169
- }
15756
+ SemVer.prototype.compare = function (other) {
15757
+ debug('SemVer.compare', this.version, this.options, other);
15758
+ if (!(other instanceof SemVer)) {
15759
+ other = new SemVer(other, this.options);
15760
+ }
15170
15761
 
15171
- return this.version;
15172
- };
15762
+ return this.compareMain(other) || this.comparePre(other)
15763
+ };
15173
15764
 
15174
- SemVer.prototype.toString = function () {
15175
- return this.version;
15176
- };
15765
+ SemVer.prototype.compareMain = function (other) {
15766
+ if (!(other instanceof SemVer)) {
15767
+ other = new SemVer(other, this.options);
15768
+ }
15177
15769
 
15178
- SemVer.prototype.compare = function (other) {
15179
- debug('SemVer.compare', this.version, this.options, other);
15770
+ return compareIdentifiers(this.major, other.major) ||
15771
+ compareIdentifiers(this.minor, other.minor) ||
15772
+ compareIdentifiers(this.patch, other.patch)
15773
+ };
15180
15774
 
15181
- if (!(other instanceof SemVer)) {
15182
- other = new SemVer(other, this.options);
15775
+ SemVer.prototype.comparePre = function (other) {
15776
+ if (!(other instanceof SemVer)) {
15777
+ other = new SemVer(other, this.options);
15778
+ }
15779
+
15780
+ // NOT having a prerelease is > having one
15781
+ if (this.prerelease.length && !other.prerelease.length) {
15782
+ return -1
15783
+ } else if (!this.prerelease.length && other.prerelease.length) {
15784
+ return 1
15785
+ } else if (!this.prerelease.length && !other.prerelease.length) {
15786
+ return 0
15787
+ }
15788
+
15789
+ var i = 0;
15790
+ do {
15791
+ var a = this.prerelease[i];
15792
+ var b = other.prerelease[i];
15793
+ debug('prerelease compare', i, a, b);
15794
+ if (a === undefined && b === undefined) {
15795
+ return 0
15796
+ } else if (b === undefined) {
15797
+ return 1
15798
+ } else if (a === undefined) {
15799
+ return -1
15800
+ } else if (a === b) {
15801
+ continue
15802
+ } else {
15803
+ return compareIdentifiers(a, b)
15183
15804
  }
15805
+ } while (++i)
15806
+ };
15184
15807
 
15185
- return this.compareMain(other) || this.comparePre(other);
15186
- };
15187
-
15188
- SemVer.prototype.compareMain = function (other) {
15189
- if (!(other instanceof SemVer)) {
15190
- other = new SemVer(other, this.options);
15808
+ SemVer.prototype.compareBuild = function (other) {
15809
+ if (!(other instanceof SemVer)) {
15810
+ other = new SemVer(other, this.options);
15811
+ }
15812
+
15813
+ var i = 0;
15814
+ do {
15815
+ var a = this.build[i];
15816
+ var b = other.build[i];
15817
+ debug('prerelease compare', i, a, b);
15818
+ if (a === undefined && b === undefined) {
15819
+ return 0
15820
+ } else if (b === undefined) {
15821
+ return 1
15822
+ } else if (a === undefined) {
15823
+ return -1
15824
+ } else if (a === b) {
15825
+ continue
15826
+ } else {
15827
+ return compareIdentifiers(a, b)
15191
15828
  }
15829
+ } while (++i)
15830
+ };
15192
15831
 
15193
- return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
15194
- };
15832
+ // preminor will bump the version up to the next minor release, and immediately
15833
+ // down to pre-release. premajor and prepatch work the same way.
15834
+ SemVer.prototype.inc = function (release, identifier) {
15835
+ switch (release) {
15836
+ case 'premajor':
15837
+ this.prerelease.length = 0;
15838
+ this.patch = 0;
15839
+ this.minor = 0;
15840
+ this.major++;
15841
+ this.inc('pre', identifier);
15842
+ break
15843
+ case 'preminor':
15844
+ this.prerelease.length = 0;
15845
+ this.patch = 0;
15846
+ this.minor++;
15847
+ this.inc('pre', identifier);
15848
+ break
15849
+ case 'prepatch':
15850
+ // If this is already a prerelease, it will bump to the next version
15851
+ // drop any prereleases that might already exist, since they are not
15852
+ // relevant at this point.
15853
+ this.prerelease.length = 0;
15854
+ this.inc('patch', identifier);
15855
+ this.inc('pre', identifier);
15856
+ break
15857
+ // If the input is a non-prerelease version, this acts the same as
15858
+ // prepatch.
15859
+ case 'prerelease':
15860
+ if (this.prerelease.length === 0) {
15861
+ this.inc('patch', identifier);
15862
+ }
15863
+ this.inc('pre', identifier);
15864
+ break
15865
+
15866
+ case 'major':
15867
+ // If this is a pre-major version, bump up to the same major version.
15868
+ // Otherwise increment major.
15869
+ // 1.0.0-5 bumps to 1.0.0
15870
+ // 1.1.0 bumps to 2.0.0
15871
+ if (this.minor !== 0 ||
15872
+ this.patch !== 0 ||
15873
+ this.prerelease.length === 0) {
15874
+ this.major++;
15875
+ }
15876
+ this.minor = 0;
15877
+ this.patch = 0;
15878
+ this.prerelease = [];
15879
+ break
15880
+ case 'minor':
15881
+ // If this is a pre-minor version, bump up to the same minor version.
15882
+ // Otherwise increment minor.
15883
+ // 1.2.0-5 bumps to 1.2.0
15884
+ // 1.2.1 bumps to 1.3.0
15885
+ if (this.patch !== 0 || this.prerelease.length === 0) {
15886
+ this.minor++;
15887
+ }
15888
+ this.patch = 0;
15889
+ this.prerelease = [];
15890
+ break
15891
+ case 'patch':
15892
+ // If this is not a pre-release version, it will increment the patch.
15893
+ // If it is a pre-release it will bump up to the same patch version.
15894
+ // 1.2.0-5 patches to 1.2.0
15895
+ // 1.2.0 patches to 1.2.1
15896
+ if (this.prerelease.length === 0) {
15897
+ this.patch++;
15898
+ }
15899
+ this.prerelease = [];
15900
+ break
15901
+ // This probably shouldn't be used publicly.
15902
+ // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
15903
+ case 'pre':
15904
+ if (this.prerelease.length === 0) {
15905
+ this.prerelease = [0];
15906
+ } else {
15907
+ var i = this.prerelease.length;
15908
+ while (--i >= 0) {
15909
+ if (typeof this.prerelease[i] === 'number') {
15910
+ this.prerelease[i]++;
15911
+ i = -2;
15912
+ }
15913
+ }
15914
+ if (i === -1) {
15915
+ // didn't increment anything
15916
+ this.prerelease.push(0);
15917
+ }
15918
+ }
15919
+ if (identifier) {
15920
+ // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
15921
+ // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
15922
+ if (this.prerelease[0] === identifier) {
15923
+ if (isNaN(this.prerelease[1])) {
15924
+ this.prerelease = [identifier, 0];
15925
+ }
15926
+ } else {
15927
+ this.prerelease = [identifier, 0];
15928
+ }
15929
+ }
15930
+ break
15195
15931
 
15196
- SemVer.prototype.comparePre = function (other) {
15197
- if (!(other instanceof SemVer)) {
15198
- other = new SemVer(other, this.options);
15199
- } // NOT having a prerelease is > having one
15932
+ default:
15933
+ throw new Error('invalid increment argument: ' + release)
15934
+ }
15935
+ this.format();
15936
+ this.raw = this.version;
15937
+ return this
15938
+ };
15200
15939
 
15940
+ exports.inc = inc;
15941
+ function inc (version, release, loose, identifier) {
15942
+ if (typeof (loose) === 'string') {
15943
+ identifier = loose;
15944
+ loose = undefined;
15945
+ }
15201
15946
 
15202
- if (this.prerelease.length && !other.prerelease.length) {
15203
- return -1;
15204
- } else if (!this.prerelease.length && other.prerelease.length) {
15205
- return 1;
15206
- } else if (!this.prerelease.length && !other.prerelease.length) {
15207
- return 0;
15947
+ try {
15948
+ return new SemVer(version, loose).inc(release, identifier).version
15949
+ } catch (er) {
15950
+ return null
15951
+ }
15952
+ }
15953
+
15954
+ exports.diff = diff;
15955
+ function diff (version1, version2) {
15956
+ if (eq(version1, version2)) {
15957
+ return null
15958
+ } else {
15959
+ var v1 = parse(version1);
15960
+ var v2 = parse(version2);
15961
+ var prefix = '';
15962
+ if (v1.prerelease.length || v2.prerelease.length) {
15963
+ prefix = 'pre';
15964
+ var defaultResult = 'prerelease';
15965
+ }
15966
+ for (var key in v1) {
15967
+ if (key === 'major' || key === 'minor' || key === 'patch') {
15968
+ if (v1[key] !== v2[key]) {
15969
+ return prefix + key
15970
+ }
15971
+ }
15208
15972
  }
15973
+ return defaultResult // may be undefined
15974
+ }
15975
+ }
15209
15976
 
15210
- var i = 0;
15977
+ exports.compareIdentifiers = compareIdentifiers;
15211
15978
 
15212
- do {
15213
- var a = this.prerelease[i];
15214
- var b = other.prerelease[i];
15215
- debug('prerelease compare', i, a, b);
15979
+ var numeric = /^[0-9]+$/;
15980
+ function compareIdentifiers (a, b) {
15981
+ var anum = numeric.test(a);
15982
+ var bnum = numeric.test(b);
15216
15983
 
15217
- if (a === undefined && b === undefined) {
15218
- return 0;
15219
- } else if (b === undefined) {
15220
- return 1;
15221
- } else if (a === undefined) {
15222
- return -1;
15223
- } else if (a === b) {
15224
- continue;
15225
- } else {
15226
- return compareIdentifiers(a, b);
15227
- }
15228
- } while (++i);
15229
- };
15984
+ if (anum && bnum) {
15985
+ a = +a;
15986
+ b = +b;
15987
+ }
15230
15988
 
15231
- SemVer.prototype.compareBuild = function (other) {
15232
- if (!(other instanceof SemVer)) {
15233
- other = new SemVer(other, this.options);
15234
- }
15989
+ return a === b ? 0
15990
+ : (anum && !bnum) ? -1
15991
+ : (bnum && !anum) ? 1
15992
+ : a < b ? -1
15993
+ : 1
15994
+ }
15235
15995
 
15236
- var i = 0;
15996
+ exports.rcompareIdentifiers = rcompareIdentifiers;
15997
+ function rcompareIdentifiers (a, b) {
15998
+ return compareIdentifiers(b, a)
15999
+ }
15237
16000
 
15238
- do {
15239
- var a = this.build[i];
15240
- var b = other.build[i];
15241
- debug('prerelease compare', i, a, b);
16001
+ exports.major = major;
16002
+ function major (a, loose) {
16003
+ return new SemVer(a, loose).major
16004
+ }
15242
16005
 
15243
- if (a === undefined && b === undefined) {
15244
- return 0;
15245
- } else if (b === undefined) {
15246
- return 1;
15247
- } else if (a === undefined) {
15248
- return -1;
15249
- } else if (a === b) {
15250
- continue;
15251
- } else {
15252
- return compareIdentifiers(a, b);
15253
- }
15254
- } while (++i);
15255
- }; // preminor will bump the version up to the next minor release, and immediately
15256
- // down to pre-release. premajor and prepatch work the same way.
16006
+ exports.minor = minor;
16007
+ function minor (a, loose) {
16008
+ return new SemVer(a, loose).minor
16009
+ }
15257
16010
 
16011
+ exports.patch = patch;
16012
+ function patch (a, loose) {
16013
+ return new SemVer(a, loose).patch
16014
+ }
15258
16015
 
15259
- SemVer.prototype.inc = function (release, identifier) {
15260
- switch (release) {
15261
- case 'premajor':
15262
- this.prerelease.length = 0;
15263
- this.patch = 0;
15264
- this.minor = 0;
15265
- this.major++;
15266
- this.inc('pre', identifier);
15267
- break;
16016
+ exports.compare = compare;
16017
+ function compare (a, b, loose) {
16018
+ return new SemVer(a, loose).compare(new SemVer(b, loose))
16019
+ }
15268
16020
 
15269
- case 'preminor':
15270
- this.prerelease.length = 0;
15271
- this.patch = 0;
15272
- this.minor++;
15273
- this.inc('pre', identifier);
15274
- break;
16021
+ exports.compareLoose = compareLoose;
16022
+ function compareLoose (a, b) {
16023
+ return compare(a, b, true)
16024
+ }
15275
16025
 
15276
- case 'prepatch':
15277
- // If this is already a prerelease, it will bump to the next version
15278
- // drop any prereleases that might already exist, since they are not
15279
- // relevant at this point.
15280
- this.prerelease.length = 0;
15281
- this.inc('patch', identifier);
15282
- this.inc('pre', identifier);
15283
- break;
15284
- // If the input is a non-prerelease version, this acts the same as
15285
- // prepatch.
16026
+ exports.compareBuild = compareBuild;
16027
+ function compareBuild (a, b, loose) {
16028
+ var versionA = new SemVer(a, loose);
16029
+ var versionB = new SemVer(b, loose);
16030
+ return versionA.compare(versionB) || versionA.compareBuild(versionB)
16031
+ }
15286
16032
 
15287
- case 'prerelease':
15288
- if (this.prerelease.length === 0) {
15289
- this.inc('patch', identifier);
15290
- }
16033
+ exports.rcompare = rcompare;
16034
+ function rcompare (a, b, loose) {
16035
+ return compare(b, a, loose)
16036
+ }
15291
16037
 
15292
- this.inc('pre', identifier);
15293
- break;
16038
+ exports.sort = sort;
16039
+ function sort (list, loose) {
16040
+ return list.sort(function (a, b) {
16041
+ return exports.compareBuild(a, b, loose)
16042
+ })
16043
+ }
15294
16044
 
15295
- case 'major':
15296
- // If this is a pre-major version, bump up to the same major version.
15297
- // Otherwise increment major.
15298
- // 1.0.0-5 bumps to 1.0.0
15299
- // 1.1.0 bumps to 2.0.0
15300
- if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
15301
- this.major++;
15302
- }
16045
+ exports.rsort = rsort;
16046
+ function rsort (list, loose) {
16047
+ return list.sort(function (a, b) {
16048
+ return exports.compareBuild(b, a, loose)
16049
+ })
16050
+ }
15303
16051
 
15304
- this.minor = 0;
15305
- this.patch = 0;
15306
- this.prerelease = [];
15307
- break;
16052
+ exports.gt = gt;
16053
+ function gt (a, b, loose) {
16054
+ return compare(a, b, loose) > 0
16055
+ }
15308
16056
 
15309
- case 'minor':
15310
- // If this is a pre-minor version, bump up to the same minor version.
15311
- // Otherwise increment minor.
15312
- // 1.2.0-5 bumps to 1.2.0
15313
- // 1.2.1 bumps to 1.3.0
15314
- if (this.patch !== 0 || this.prerelease.length === 0) {
15315
- this.minor++;
15316
- }
16057
+ exports.lt = lt;
16058
+ function lt (a, b, loose) {
16059
+ return compare(a, b, loose) < 0
16060
+ }
15317
16061
 
15318
- this.patch = 0;
15319
- this.prerelease = [];
15320
- break;
16062
+ exports.eq = eq;
16063
+ function eq (a, b, loose) {
16064
+ return compare(a, b, loose) === 0
16065
+ }
15321
16066
 
15322
- case 'patch':
15323
- // If this is not a pre-release version, it will increment the patch.
15324
- // If it is a pre-release it will bump up to the same patch version.
15325
- // 1.2.0-5 patches to 1.2.0
15326
- // 1.2.0 patches to 1.2.1
15327
- if (this.prerelease.length === 0) {
15328
- this.patch++;
15329
- }
16067
+ exports.neq = neq;
16068
+ function neq (a, b, loose) {
16069
+ return compare(a, b, loose) !== 0
16070
+ }
15330
16071
 
15331
- this.prerelease = [];
15332
- break;
15333
- // This probably shouldn't be used publicly.
15334
- // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
16072
+ exports.gte = gte;
16073
+ function gte (a, b, loose) {
16074
+ return compare(a, b, loose) >= 0
16075
+ }
15335
16076
 
15336
- case 'pre':
15337
- if (this.prerelease.length === 0) {
15338
- this.prerelease = [0];
15339
- } else {
15340
- var i = this.prerelease.length;
16077
+ exports.lte = lte;
16078
+ function lte (a, b, loose) {
16079
+ return compare(a, b, loose) <= 0
16080
+ }
15341
16081
 
15342
- while (--i >= 0) {
15343
- if (typeof this.prerelease[i] === 'number') {
15344
- this.prerelease[i]++;
15345
- i = -2;
15346
- }
15347
- }
16082
+ exports.cmp = cmp;
16083
+ function cmp (a, op, b, loose) {
16084
+ switch (op) {
16085
+ case '===':
16086
+ if (typeof a === 'object')
16087
+ a = a.version;
16088
+ if (typeof b === 'object')
16089
+ b = b.version;
16090
+ return a === b
15348
16091
 
15349
- if (i === -1) {
15350
- // didn't increment anything
15351
- this.prerelease.push(0);
15352
- }
15353
- }
16092
+ case '!==':
16093
+ if (typeof a === 'object')
16094
+ a = a.version;
16095
+ if (typeof b === 'object')
16096
+ b = b.version;
16097
+ return a !== b
15354
16098
 
15355
- if (identifier) {
15356
- // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
15357
- // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
15358
- if (this.prerelease[0] === identifier) {
15359
- if (isNaN(this.prerelease[1])) {
15360
- this.prerelease = [identifier, 0];
15361
- }
15362
- } else {
15363
- this.prerelease = [identifier, 0];
15364
- }
15365
- }
16099
+ case '':
16100
+ case '=':
16101
+ case '==':
16102
+ return eq(a, b, loose)
15366
16103
 
15367
- break;
16104
+ case '!=':
16105
+ return neq(a, b, loose)
15368
16106
 
15369
- default:
15370
- throw new Error('invalid increment argument: ' + release);
15371
- }
16107
+ case '>':
16108
+ return gt(a, b, loose)
15372
16109
 
15373
- this.format();
15374
- this.raw = this.version;
15375
- return this;
15376
- };
16110
+ case '>=':
16111
+ return gte(a, b, loose)
15377
16112
 
15378
- exports.inc = inc;
16113
+ case '<':
16114
+ return lt(a, b, loose)
15379
16115
 
15380
- function inc(version, release, loose, identifier) {
15381
- if (typeof loose === 'string') {
15382
- identifier = loose;
15383
- loose = undefined;
15384
- }
16116
+ case '<=':
16117
+ return lte(a, b, loose)
15385
16118
 
15386
- try {
15387
- return new SemVer(version, loose).inc(release, identifier).version;
15388
- } catch (er) {
15389
- return null;
15390
- }
16119
+ default:
16120
+ throw new TypeError('Invalid operator: ' + op)
15391
16121
  }
16122
+ }
15392
16123
 
15393
- exports.diff = diff;
16124
+ exports.Comparator = Comparator;
16125
+ function Comparator (comp, options) {
16126
+ if (!options || typeof options !== 'object') {
16127
+ options = {
16128
+ loose: !!options,
16129
+ includePrerelease: false
16130
+ };
16131
+ }
15394
16132
 
15395
- function diff(version1, version2) {
15396
- if (eq(version1, version2)) {
15397
- return null;
16133
+ if (comp instanceof Comparator) {
16134
+ if (comp.loose === !!options.loose) {
16135
+ return comp
15398
16136
  } else {
15399
- var v1 = parse(version1);
15400
- var v2 = parse(version2);
15401
- var prefix = '';
15402
-
15403
- if (v1.prerelease.length || v2.prerelease.length) {
15404
- prefix = 'pre';
15405
- var defaultResult = 'prerelease';
15406
- }
15407
-
15408
- for (var key in v1) {
15409
- if (key === 'major' || key === 'minor' || key === 'patch') {
15410
- if (v1[key] !== v2[key]) {
15411
- return prefix + key;
15412
- }
15413
- }
15414
- }
15415
-
15416
- return defaultResult; // may be undefined
16137
+ comp = comp.value;
15417
16138
  }
15418
16139
  }
15419
16140
 
15420
- exports.compareIdentifiers = compareIdentifiers;
15421
- var numeric = /^[0-9]+$/;
15422
-
15423
- function compareIdentifiers(a, b) {
15424
- var anum = numeric.test(a);
15425
- var bnum = numeric.test(b);
16141
+ if (!(this instanceof Comparator)) {
16142
+ return new Comparator(comp, options)
16143
+ }
15426
16144
 
15427
- if (anum && bnum) {
15428
- a = +a;
15429
- b = +b;
15430
- }
16145
+ debug('comparator', comp, options);
16146
+ this.options = options;
16147
+ this.loose = !!options.loose;
16148
+ this.parse(comp);
15431
16149
 
15432
- return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
16150
+ if (this.semver === ANY) {
16151
+ this.value = '';
16152
+ } else {
16153
+ this.value = this.operator + this.semver.version;
15433
16154
  }
15434
16155
 
15435
- exports.rcompareIdentifiers = rcompareIdentifiers;
16156
+ debug('comp', this);
16157
+ }
16158
+
16159
+ var ANY = {};
16160
+ Comparator.prototype.parse = function (comp) {
16161
+ var r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
16162
+ var m = comp.match(r);
15436
16163
 
15437
- function rcompareIdentifiers(a, b) {
15438
- return compareIdentifiers(b, a);
16164
+ if (!m) {
16165
+ throw new TypeError('Invalid comparator: ' + comp)
15439
16166
  }
15440
16167
 
15441
- exports.major = major;
16168
+ this.operator = m[1] !== undefined ? m[1] : '';
16169
+ if (this.operator === '=') {
16170
+ this.operator = '';
16171
+ }
15442
16172
 
15443
- function major(a, loose) {
15444
- return new SemVer(a, loose).major;
16173
+ // if it literally is just '>' or '' then allow anything.
16174
+ if (!m[2]) {
16175
+ this.semver = ANY;
16176
+ } else {
16177
+ this.semver = new SemVer(m[2], this.options.loose);
15445
16178
  }
16179
+ };
16180
+
16181
+ Comparator.prototype.toString = function () {
16182
+ return this.value
16183
+ };
15446
16184
 
15447
- exports.minor = minor;
16185
+ Comparator.prototype.test = function (version) {
16186
+ debug('Comparator.test', version, this.options.loose);
15448
16187
 
15449
- function minor(a, loose) {
15450
- return new SemVer(a, loose).minor;
16188
+ if (this.semver === ANY || version === ANY) {
16189
+ return true
15451
16190
  }
15452
16191
 
15453
- exports.patch = patch;
15454
-
15455
- function patch(a, loose) {
15456
- return new SemVer(a, loose).patch;
15457
- }
15458
-
15459
- exports.compare = compare;
15460
-
15461
- function compare(a, b, loose) {
15462
- return new SemVer(a, loose).compare(new SemVer(b, loose));
15463
- }
15464
-
15465
- exports.compareLoose = compareLoose;
15466
-
15467
- function compareLoose(a, b) {
15468
- return compare(a, b, true);
15469
- }
15470
-
15471
- exports.compareBuild = compareBuild;
15472
-
15473
- function compareBuild(a, b, loose) {
15474
- var versionA = new SemVer(a, loose);
15475
- var versionB = new SemVer(b, loose);
15476
- return versionA.compare(versionB) || versionA.compareBuild(versionB);
15477
- }
15478
-
15479
- exports.rcompare = rcompare;
15480
-
15481
- function rcompare(a, b, loose) {
15482
- return compare(b, a, loose);
16192
+ if (typeof version === 'string') {
16193
+ try {
16194
+ version = new SemVer(version, this.options);
16195
+ } catch (er) {
16196
+ return false
16197
+ }
15483
16198
  }
15484
16199
 
15485
- exports.sort = sort;
16200
+ return cmp(version, this.operator, this.semver, this.options)
16201
+ };
15486
16202
 
15487
- function sort(list, loose) {
15488
- return list.sort(function (a, b) {
15489
- return exports.compareBuild(a, b, loose);
15490
- });
16203
+ Comparator.prototype.intersects = function (comp, options) {
16204
+ if (!(comp instanceof Comparator)) {
16205
+ throw new TypeError('a Comparator is required')
15491
16206
  }
15492
16207
 
15493
- exports.rsort = rsort;
15494
-
15495
- function rsort(list, loose) {
15496
- return list.sort(function (a, b) {
15497
- return exports.compareBuild(b, a, loose);
15498
- });
16208
+ if (!options || typeof options !== 'object') {
16209
+ options = {
16210
+ loose: !!options,
16211
+ includePrerelease: false
16212
+ };
15499
16213
  }
15500
16214
 
15501
- exports.gt = gt;
16215
+ var rangeTmp;
16216
+
16217
+ if (this.operator === '') {
16218
+ if (this.value === '') {
16219
+ return true
16220
+ }
16221
+ rangeTmp = new Range(comp.value, options);
16222
+ return satisfies(this.value, rangeTmp, options)
16223
+ } else if (comp.operator === '') {
16224
+ if (comp.value === '') {
16225
+ return true
16226
+ }
16227
+ rangeTmp = new Range(this.value, options);
16228
+ return satisfies(comp.semver, rangeTmp, options)
16229
+ }
16230
+
16231
+ var sameDirectionIncreasing =
16232
+ (this.operator === '>=' || this.operator === '>') &&
16233
+ (comp.operator === '>=' || comp.operator === '>');
16234
+ var sameDirectionDecreasing =
16235
+ (this.operator === '<=' || this.operator === '<') &&
16236
+ (comp.operator === '<=' || comp.operator === '<');
16237
+ var sameSemVer = this.semver.version === comp.semver.version;
16238
+ var differentDirectionsInclusive =
16239
+ (this.operator === '>=' || this.operator === '<=') &&
16240
+ (comp.operator === '>=' || comp.operator === '<=');
16241
+ var oppositeDirectionsLessThan =
16242
+ cmp(this.semver, '<', comp.semver, options) &&
16243
+ ((this.operator === '>=' || this.operator === '>') &&
16244
+ (comp.operator === '<=' || comp.operator === '<'));
16245
+ var oppositeDirectionsGreaterThan =
16246
+ cmp(this.semver, '>', comp.semver, options) &&
16247
+ ((this.operator === '<=' || this.operator === '<') &&
16248
+ (comp.operator === '>=' || comp.operator === '>'));
16249
+
16250
+ return sameDirectionIncreasing || sameDirectionDecreasing ||
16251
+ (sameSemVer && differentDirectionsInclusive) ||
16252
+ oppositeDirectionsLessThan || oppositeDirectionsGreaterThan
16253
+ };
15502
16254
 
15503
- function gt(a, b, loose) {
15504
- return compare(a, b, loose) > 0;
16255
+ exports.Range = Range;
16256
+ function Range (range, options) {
16257
+ if (!options || typeof options !== 'object') {
16258
+ options = {
16259
+ loose: !!options,
16260
+ includePrerelease: false
16261
+ };
15505
16262
  }
15506
16263
 
15507
- exports.lt = lt;
15508
-
15509
- function lt(a, b, loose) {
15510
- return compare(a, b, loose) < 0;
16264
+ if (range instanceof Range) {
16265
+ if (range.loose === !!options.loose &&
16266
+ range.includePrerelease === !!options.includePrerelease) {
16267
+ return range
16268
+ } else {
16269
+ return new Range(range.raw, options)
16270
+ }
15511
16271
  }
15512
16272
 
15513
- exports.eq = eq;
15514
-
15515
- function eq(a, b, loose) {
15516
- return compare(a, b, loose) === 0;
16273
+ if (range instanceof Comparator) {
16274
+ return new Range(range.value, options)
15517
16275
  }
15518
16276
 
15519
- exports.neq = neq;
15520
-
15521
- function neq(a, b, loose) {
15522
- return compare(a, b, loose) !== 0;
16277
+ if (!(this instanceof Range)) {
16278
+ return new Range(range, options)
15523
16279
  }
15524
16280
 
15525
- exports.gte = gte;
15526
-
15527
- function gte(a, b, loose) {
15528
- return compare(a, b, loose) >= 0;
15529
- }
16281
+ this.options = options;
16282
+ this.loose = !!options.loose;
16283
+ this.includePrerelease = !!options.includePrerelease;
15530
16284
 
15531
- exports.lte = lte;
16285
+ // First, split based on boolean or ||
16286
+ this.raw = range;
16287
+ this.set = range.split(/\s*\|\|\s*/).map(function (range) {
16288
+ return this.parseRange(range.trim())
16289
+ }, this).filter(function (c) {
16290
+ // throw out any that are not relevant for whatever reason
16291
+ return c.length
16292
+ });
15532
16293
 
15533
- function lte(a, b, loose) {
15534
- return compare(a, b, loose) <= 0;
16294
+ if (!this.set.length) {
16295
+ throw new TypeError('Invalid SemVer Range: ' + range)
15535
16296
  }
15536
16297
 
15537
- exports.cmp = cmp;
15538
-
15539
- function cmp(a, op, b, loose) {
15540
- switch (op) {
15541
- case '===':
15542
- if (typeof a === 'object') a = a.version;
15543
- if (typeof b === 'object') b = b.version;
15544
- return a === b;
15545
-
15546
- case '!==':
15547
- if (typeof a === 'object') a = a.version;
15548
- if (typeof b === 'object') b = b.version;
15549
- return a !== b;
15550
-
15551
- case '':
15552
- case '=':
15553
- case '==':
15554
- return eq(a, b, loose);
15555
-
15556
- case '!=':
15557
- return neq(a, b, loose);
15558
-
15559
- case '>':
15560
- return gt(a, b, loose);
15561
-
15562
- case '>=':
15563
- return gte(a, b, loose);
16298
+ this.format();
16299
+ }
15564
16300
 
15565
- case '<':
15566
- return lt(a, b, loose);
16301
+ Range.prototype.format = function () {
16302
+ this.range = this.set.map(function (comps) {
16303
+ return comps.join(' ').trim()
16304
+ }).join('||').trim();
16305
+ return this.range
16306
+ };
15567
16307
 
15568
- case '<=':
15569
- return lte(a, b, loose);
16308
+ Range.prototype.toString = function () {
16309
+ return this.range
16310
+ };
15570
16311
 
15571
- default:
15572
- throw new TypeError('Invalid operator: ' + op);
15573
- }
16312
+ Range.prototype.parseRange = function (range) {
16313
+ var loose = this.options.loose;
16314
+ range = range.trim();
16315
+ // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
16316
+ var hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
16317
+ range = range.replace(hr, hyphenReplace);
16318
+ debug('hyphen replace', range);
16319
+ // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
16320
+ range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
16321
+ debug('comparator trim', range, re[t.COMPARATORTRIM]);
16322
+
16323
+ // `~ 1.2.3` => `~1.2.3`
16324
+ range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
16325
+
16326
+ // `^ 1.2.3` => `^1.2.3`
16327
+ range = range.replace(re[t.CARETTRIM], caretTrimReplace);
16328
+
16329
+ // normalize spaces
16330
+ range = range.split(/\s+/).join(' ');
16331
+
16332
+ // At this point, the range is completely trimmed and
16333
+ // ready to be split into comparators.
16334
+
16335
+ var compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
16336
+ var set = range.split(' ').map(function (comp) {
16337
+ return parseComparator(comp, this.options)
16338
+ }, this).join(' ').split(/\s+/);
16339
+ if (this.options.loose) {
16340
+ // in loose mode, throw out any that are not valid comparators
16341
+ set = set.filter(function (comp) {
16342
+ return !!comp.match(compRe)
16343
+ });
15574
16344
  }
16345
+ set = set.map(function (comp) {
16346
+ return new Comparator(comp, this.options)
16347
+ }, this);
15575
16348
 
15576
- exports.Comparator = Comparator;
15577
-
15578
- function Comparator(comp, options) {
15579
- if (!options || typeof options !== 'object') {
15580
- options = {
15581
- loose: !!options,
15582
- includePrerelease: false
15583
- };
15584
- }
15585
-
15586
- if (comp instanceof Comparator) {
15587
- if (comp.loose === !!options.loose) {
15588
- return comp;
15589
- } else {
15590
- comp = comp.value;
15591
- }
15592
- }
15593
-
15594
- if (!(this instanceof Comparator)) {
15595
- return new Comparator(comp, options);
15596
- }
15597
-
15598
- debug('comparator', comp, options);
15599
- this.options = options;
15600
- this.loose = !!options.loose;
15601
- this.parse(comp);
15602
-
15603
- if (this.semver === ANY) {
15604
- this.value = '';
15605
- } else {
15606
- this.value = this.operator + this.semver.version;
15607
- }
16349
+ return set
16350
+ };
15608
16351
 
15609
- debug('comp', this);
16352
+ Range.prototype.intersects = function (range, options) {
16353
+ if (!(range instanceof Range)) {
16354
+ throw new TypeError('a Range is required')
15610
16355
  }
15611
16356
 
15612
- var ANY = {};
15613
-
15614
- Comparator.prototype.parse = function (comp) {
15615
- var r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
15616
- var m = comp.match(r);
15617
-
15618
- if (!m) {
15619
- throw new TypeError('Invalid comparator: ' + comp);
15620
- }
15621
-
15622
- this.operator = m[1] !== undefined ? m[1] : '';
16357
+ return this.set.some(function (thisComparators) {
16358
+ return (
16359
+ isSatisfiable(thisComparators, options) &&
16360
+ range.set.some(function (rangeComparators) {
16361
+ return (
16362
+ isSatisfiable(rangeComparators, options) &&
16363
+ thisComparators.every(function (thisComparator) {
16364
+ return rangeComparators.every(function (rangeComparator) {
16365
+ return thisComparator.intersects(rangeComparator, options)
16366
+ })
16367
+ })
16368
+ )
16369
+ })
16370
+ )
16371
+ })
16372
+ };
15623
16373
 
15624
- if (this.operator === '=') {
15625
- this.operator = '';
15626
- } // if it literally is just '>' or '' then allow anything.
16374
+ // take a set of comparators and determine whether there
16375
+ // exists a version which can satisfy it
16376
+ function isSatisfiable (comparators, options) {
16377
+ var result = true;
16378
+ var remainingComparators = comparators.slice();
16379
+ var testComparator = remainingComparators.pop();
15627
16380
 
16381
+ while (result && remainingComparators.length) {
16382
+ result = remainingComparators.every(function (otherComparator) {
16383
+ return testComparator.intersects(otherComparator, options)
16384
+ });
15628
16385
 
15629
- if (!m[2]) {
15630
- this.semver = ANY;
16386
+ testComparator = remainingComparators.pop();
16387
+ }
16388
+
16389
+ return result
16390
+ }
16391
+
16392
+ // Mostly just for testing and legacy API reasons
16393
+ exports.toComparators = toComparators;
16394
+ function toComparators (range, options) {
16395
+ return new Range(range, options).set.map(function (comp) {
16396
+ return comp.map(function (c) {
16397
+ return c.value
16398
+ }).join(' ').trim().split(' ')
16399
+ })
16400
+ }
16401
+
16402
+ // comprised of xranges, tildes, stars, and gtlt's at this point.
16403
+ // already replaced the hyphen ranges
16404
+ // turn into a set of JUST comparators.
16405
+ function parseComparator (comp, options) {
16406
+ debug('comp', comp, options);
16407
+ comp = replaceCarets(comp, options);
16408
+ debug('caret', comp);
16409
+ comp = replaceTildes(comp, options);
16410
+ debug('tildes', comp);
16411
+ comp = replaceXRanges(comp, options);
16412
+ debug('xrange', comp);
16413
+ comp = replaceStars(comp, options);
16414
+ debug('stars', comp);
16415
+ return comp
16416
+ }
16417
+
16418
+ function isX (id) {
16419
+ return !id || id.toLowerCase() === 'x' || id === '*'
16420
+ }
16421
+
16422
+ // ~, ~> --> * (any, kinda silly)
16423
+ // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
16424
+ // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
16425
+ // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
16426
+ // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
16427
+ // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
16428
+ function replaceTildes (comp, options) {
16429
+ return comp.trim().split(/\s+/).map(function (comp) {
16430
+ return replaceTilde(comp, options)
16431
+ }).join(' ')
16432
+ }
16433
+
16434
+ function replaceTilde (comp, options) {
16435
+ var r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
16436
+ return comp.replace(r, function (_, M, m, p, pr) {
16437
+ debug('tilde', comp, _, M, m, p, pr);
16438
+ var ret;
16439
+
16440
+ if (isX(M)) {
16441
+ ret = '';
16442
+ } else if (isX(m)) {
16443
+ ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
16444
+ } else if (isX(p)) {
16445
+ // ~1.2 == >=1.2.0 <1.3.0
16446
+ ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
16447
+ } else if (pr) {
16448
+ debug('replaceTilde pr', pr);
16449
+ ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
16450
+ ' <' + M + '.' + (+m + 1) + '.0';
15631
16451
  } else {
15632
- this.semver = new SemVer(m[2], this.options.loose);
15633
- }
15634
- };
15635
-
15636
- Comparator.prototype.toString = function () {
15637
- return this.value;
15638
- };
15639
-
15640
- Comparator.prototype.test = function (version) {
15641
- debug('Comparator.test', version, this.options.loose);
15642
-
15643
- if (this.semver === ANY || version === ANY) {
15644
- return true;
15645
- }
15646
-
15647
- if (typeof version === 'string') {
15648
- try {
15649
- version = new SemVer(version, this.options);
15650
- } catch (er) {
15651
- return false;
15652
- }
15653
- }
15654
-
15655
- return cmp(version, this.operator, this.semver, this.options);
15656
- };
15657
-
15658
- Comparator.prototype.intersects = function (comp, options) {
15659
- if (!(comp instanceof Comparator)) {
15660
- throw new TypeError('a Comparator is required');
15661
- }
15662
-
15663
- if (!options || typeof options !== 'object') {
15664
- options = {
15665
- loose: !!options,
15666
- includePrerelease: false
15667
- };
15668
- }
15669
-
15670
- var rangeTmp;
15671
-
15672
- if (this.operator === '') {
15673
- if (this.value === '') {
15674
- return true;
16452
+ // ~1.2.3 == >=1.2.3 <1.3.0
16453
+ ret = '>=' + M + '.' + m + '.' + p +
16454
+ ' <' + M + '.' + (+m + 1) + '.0';
16455
+ }
16456
+
16457
+ debug('tilde return', ret);
16458
+ return ret
16459
+ })
16460
+ }
16461
+
16462
+ // ^ --> * (any, kinda silly)
16463
+ // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
16464
+ // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
16465
+ // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
16466
+ // ^1.2.3 --> >=1.2.3 <2.0.0
16467
+ // ^1.2.0 --> >=1.2.0 <2.0.0
16468
+ function replaceCarets (comp, options) {
16469
+ return comp.trim().split(/\s+/).map(function (comp) {
16470
+ return replaceCaret(comp, options)
16471
+ }).join(' ')
16472
+ }
16473
+
16474
+ function replaceCaret (comp, options) {
16475
+ debug('caret', comp, options);
16476
+ var r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
16477
+ return comp.replace(r, function (_, M, m, p, pr) {
16478
+ debug('caret', comp, _, M, m, p, pr);
16479
+ var ret;
16480
+
16481
+ if (isX(M)) {
16482
+ ret = '';
16483
+ } else if (isX(m)) {
16484
+ ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
16485
+ } else if (isX(p)) {
16486
+ if (M === '0') {
16487
+ ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
16488
+ } else {
16489
+ ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
15675
16490
  }
15676
-
15677
- rangeTmp = new Range(comp.value, options);
15678
- return satisfies(this.value, rangeTmp, options);
15679
- } else if (comp.operator === '') {
15680
- if (comp.value === '') {
15681
- return true;
16491
+ } else if (pr) {
16492
+ debug('replaceCaret pr', pr);
16493
+ if (M === '0') {
16494
+ if (m === '0') {
16495
+ ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
16496
+ ' <' + M + '.' + m + '.' + (+p + 1);
16497
+ } else {
16498
+ ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
16499
+ ' <' + M + '.' + (+m + 1) + '.0';
16500
+ }
16501
+ } else {
16502
+ ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
16503
+ ' <' + (+M + 1) + '.0.0';
15682
16504
  }
15683
-
15684
- rangeTmp = new Range(this.value, options);
15685
- return satisfies(comp.semver, rangeTmp, options);
15686
- }
15687
-
15688
- var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
15689
- var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
15690
- var sameSemVer = this.semver.version === comp.semver.version;
15691
- var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
15692
- var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, options) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
15693
- var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, options) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
15694
- return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
15695
- };
15696
-
15697
- exports.Range = Range;
15698
-
15699
- function Range(range, options) {
15700
- if (!options || typeof options !== 'object') {
15701
- options = {
15702
- loose: !!options,
15703
- includePrerelease: false
15704
- };
15705
- }
15706
-
15707
- if (range instanceof Range) {
15708
- if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
15709
- return range;
16505
+ } else {
16506
+ debug('no pr');
16507
+ if (M === '0') {
16508
+ if (m === '0') {
16509
+ ret = '>=' + M + '.' + m + '.' + p +
16510
+ ' <' + M + '.' + m + '.' + (+p + 1);
16511
+ } else {
16512
+ ret = '>=' + M + '.' + m + '.' + p +
16513
+ ' <' + M + '.' + (+m + 1) + '.0';
16514
+ }
15710
16515
  } else {
15711
- return new Range(range.raw, options);
16516
+ ret = '>=' + M + '.' + m + '.' + p +
16517
+ ' <' + (+M + 1) + '.0.0';
15712
16518
  }
15713
16519
  }
15714
16520
 
15715
- if (range instanceof Comparator) {
15716
- return new Range(range.value, options);
15717
- }
15718
-
15719
- if (!(this instanceof Range)) {
15720
- return new Range(range, options);
15721
- }
15722
-
15723
- this.options = options;
15724
- this.loose = !!options.loose;
15725
- this.includePrerelease = !!options.includePrerelease; // First, split based on boolean or ||
15726
-
15727
- this.raw = range;
15728
- this.set = range.split(/\s*\|\|\s*/).map(function (range) {
15729
- return this.parseRange(range.trim());
15730
- }, this).filter(function (c) {
15731
- // throw out any that are not relevant for whatever reason
15732
- return c.length;
15733
- });
15734
-
15735
- if (!this.set.length) {
15736
- throw new TypeError('Invalid SemVer Range: ' + range);
15737
- }
15738
-
15739
- this.format();
15740
- }
15741
-
15742
- Range.prototype.format = function () {
15743
- this.range = this.set.map(function (comps) {
15744
- return comps.join(' ').trim();
15745
- }).join('||').trim();
15746
- return this.range;
15747
- };
15748
-
15749
- Range.prototype.toString = function () {
15750
- return this.range;
15751
- };
15752
-
15753
- Range.prototype.parseRange = function (range) {
15754
- var loose = this.options.loose;
15755
- range = range.trim(); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
15756
-
15757
- var hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
15758
- range = range.replace(hr, hyphenReplace);
15759
- debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
15760
-
15761
- range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
15762
- debug('comparator trim', range, re[t.COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
15763
-
15764
- range = range.replace(re[t.TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
15765
-
15766
- range = range.replace(re[t.CARETTRIM], caretTrimReplace); // normalize spaces
15767
-
15768
- range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
15769
- // ready to be split into comparators.
15770
-
15771
- var compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
15772
- var set = range.split(' ').map(function (comp) {
15773
- return parseComparator(comp, this.options);
15774
- }, this).join(' ').split(/\s+/);
15775
-
15776
- if (this.options.loose) {
15777
- // in loose mode, throw out any that are not valid comparators
15778
- set = set.filter(function (comp) {
15779
- return !!comp.match(compRe);
15780
- });
15781
- }
15782
-
15783
- set = set.map(function (comp) {
15784
- return new Comparator(comp, this.options);
15785
- }, this);
15786
- return set;
15787
- };
15788
-
15789
- Range.prototype.intersects = function (range, options) {
15790
- if (!(range instanceof Range)) {
15791
- throw new TypeError('a Range is required');
15792
- }
15793
-
15794
- return this.set.some(function (thisComparators) {
15795
- return isSatisfiable(thisComparators, options) && range.set.some(function (rangeComparators) {
15796
- return isSatisfiable(rangeComparators, options) && thisComparators.every(function (thisComparator) {
15797
- return rangeComparators.every(function (rangeComparator) {
15798
- return thisComparator.intersects(rangeComparator, options);
15799
- });
15800
- });
15801
- });
15802
- });
15803
- }; // take a set of comparators and determine whether there
15804
- // exists a version which can satisfy it
16521
+ debug('caret return', ret);
16522
+ return ret
16523
+ })
16524
+ }
15805
16525
 
16526
+ function replaceXRanges (comp, options) {
16527
+ debug('replaceXRanges', comp, options);
16528
+ return comp.split(/\s+/).map(function (comp) {
16529
+ return replaceXRange(comp, options)
16530
+ }).join(' ')
16531
+ }
15806
16532
 
15807
- function isSatisfiable(comparators, options) {
15808
- var result = true;
15809
- var remainingComparators = comparators.slice();
15810
- var testComparator = remainingComparators.pop();
16533
+ function replaceXRange (comp, options) {
16534
+ comp = comp.trim();
16535
+ var r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
16536
+ return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
16537
+ debug('xRange', comp, ret, gtlt, M, m, p, pr);
16538
+ var xM = isX(M);
16539
+ var xm = xM || isX(m);
16540
+ var xp = xm || isX(p);
16541
+ var anyX = xp;
15811
16542
 
15812
- while (result && remainingComparators.length) {
15813
- result = remainingComparators.every(function (otherComparator) {
15814
- return testComparator.intersects(otherComparator, options);
15815
- });
15816
- testComparator = remainingComparators.pop();
16543
+ if (gtlt === '=' && anyX) {
16544
+ gtlt = '';
15817
16545
  }
15818
16546
 
15819
- return result;
15820
- } // Mostly just for testing and legacy API reasons
15821
-
15822
-
15823
- exports.toComparators = toComparators;
15824
-
15825
- function toComparators(range, options) {
15826
- return new Range(range, options).set.map(function (comp) {
15827
- return comp.map(function (c) {
15828
- return c.value;
15829
- }).join(' ').trim().split(' ');
15830
- });
15831
- } // comprised of xranges, tildes, stars, and gtlt's at this point.
15832
- // already replaced the hyphen ranges
15833
- // turn into a set of JUST comparators.
15834
-
15835
-
15836
- function parseComparator(comp, options) {
15837
- debug('comp', comp, options);
15838
- comp = replaceCarets(comp, options);
15839
- debug('caret', comp);
15840
- comp = replaceTildes(comp, options);
15841
- debug('tildes', comp);
15842
- comp = replaceXRanges(comp, options);
15843
- debug('xrange', comp);
15844
- comp = replaceStars(comp, options);
15845
- debug('stars', comp);
15846
- return comp;
15847
- }
15848
-
15849
- function isX(id) {
15850
- return !id || id.toLowerCase() === 'x' || id === '*';
15851
- } // ~, ~> --> * (any, kinda silly)
15852
- // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
15853
- // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
15854
- // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
15855
- // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
15856
- // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
15857
-
15858
-
15859
- function replaceTildes(comp, options) {
15860
- return comp.trim().split(/\s+/).map(function (comp) {
15861
- return replaceTilde(comp, options);
15862
- }).join(' ');
15863
- }
15864
-
15865
- function replaceTilde(comp, options) {
15866
- var r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
15867
- return comp.replace(r, function (_, M, m, p, pr) {
15868
- debug('tilde', comp, _, M, m, p, pr);
15869
- var ret;
16547
+ // if we're including prereleases in the match, then we need
16548
+ // to fix this to -0, the lowest possible prerelease value
16549
+ pr = options.includePrerelease ? '-0' : '';
15870
16550
 
15871
- if (isX(M)) {
15872
- ret = '';
15873
- } else if (isX(m)) {
15874
- ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
15875
- } else if (isX(p)) {
15876
- // ~1.2 == >=1.2.0 <1.3.0
15877
- ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
15878
- } else if (pr) {
15879
- debug('replaceTilde pr', pr);
15880
- ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + (+m + 1) + '.0';
16551
+ if (xM) {
16552
+ if (gtlt === '>' || gtlt === '<') {
16553
+ // nothing is allowed
16554
+ ret = '<0.0.0-0';
15881
16555
  } else {
15882
- // ~1.2.3 == >=1.2.3 <1.3.0
15883
- ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
16556
+ // nothing is forbidden
16557
+ ret = '*';
15884
16558
  }
16559
+ } else if (gtlt && anyX) {
16560
+ // we know patch is an x, because we have any x at all.
16561
+ // replace X with 0
16562
+ if (xm) {
16563
+ m = 0;
16564
+ }
16565
+ p = 0;
15885
16566
 
15886
- debug('tilde return', ret);
15887
- return ret;
15888
- });
15889
- } // ^ --> * (any, kinda silly)
15890
- // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
15891
- // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
15892
- // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
15893
- // ^1.2.3 --> >=1.2.3 <2.0.0
15894
- // ^1.2.0 --> >=1.2.0 <2.0.0
15895
-
15896
-
15897
- function replaceCarets(comp, options) {
15898
- return comp.trim().split(/\s+/).map(function (comp) {
15899
- return replaceCaret(comp, options);
15900
- }).join(' ');
15901
- }
15902
-
15903
- function replaceCaret(comp, options) {
15904
- debug('caret', comp, options);
15905
- var r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
15906
- return comp.replace(r, function (_, M, m, p, pr) {
15907
- debug('caret', comp, _, M, m, p, pr);
15908
- var ret;
15909
-
15910
- if (isX(M)) {
15911
- ret = '';
15912
- } else if (isX(m)) {
15913
- ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
15914
- } else if (isX(p)) {
15915
- if (M === '0') {
15916
- ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
15917
- } else {
15918
- ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
15919
- }
15920
- } else if (pr) {
15921
- debug('replaceCaret pr', pr);
15922
-
15923
- if (M === '0') {
15924
- if (m === '0') {
15925
- ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + m + '.' + (+p + 1);
15926
- } else {
15927
- ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + (+m + 1) + '.0';
15928
- }
16567
+ if (gtlt === '>') {
16568
+ // >1 => >=2.0.0
16569
+ // >1.2 => >=1.3.0
16570
+ // >1.2.3 => >= 1.2.4
16571
+ gtlt = '>=';
16572
+ if (xm) {
16573
+ M = +M + 1;
16574
+ m = 0;
16575
+ p = 0;
15929
16576
  } else {
15930
- ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + (+M + 1) + '.0.0';
16577
+ m = +m + 1;
16578
+ p = 0;
15931
16579
  }
15932
- } else {
15933
- debug('no pr');
15934
-
15935
- if (M === '0') {
15936
- if (m === '0') {
15937
- ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);
15938
- } else {
15939
- ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
15940
- }
16580
+ } else if (gtlt === '<=') {
16581
+ // <=0.7.x is actually <0.8.0, since any 0.7.x should
16582
+ // pass. Similarly, <=7.x is actually <8.0.0, etc.
16583
+ gtlt = '<';
16584
+ if (xm) {
16585
+ M = +M + 1;
15941
16586
  } else {
15942
- ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
16587
+ m = +m + 1;
15943
16588
  }
15944
16589
  }
15945
16590
 
15946
- debug('caret return', ret);
15947
- return ret;
15948
- });
16591
+ ret = gtlt + M + '.' + m + '.' + p + pr;
16592
+ } else if (xm) {
16593
+ ret = '>=' + M + '.0.0' + pr + ' <' + (+M + 1) + '.0.0' + pr;
16594
+ } else if (xp) {
16595
+ ret = '>=' + M + '.' + m + '.0' + pr +
16596
+ ' <' + M + '.' + (+m + 1) + '.0' + pr;
16597
+ }
16598
+
16599
+ debug('xRange return', ret);
16600
+
16601
+ return ret
16602
+ })
16603
+ }
16604
+
16605
+ // Because * is AND-ed with everything else in the comparator,
16606
+ // and '' means "any version", just remove the *s entirely.
16607
+ function replaceStars (comp, options) {
16608
+ debug('replaceStars', comp, options);
16609
+ // Looseness is ignored here. star is always as loose as it gets!
16610
+ return comp.trim().replace(re[t.STAR], '')
16611
+ }
16612
+
16613
+ // This function is passed to string.replace(re[t.HYPHENRANGE])
16614
+ // M, m, patch, prerelease, build
16615
+ // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
16616
+ // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
16617
+ // 1.2 - 3.4 => >=1.2.0 <3.5.0
16618
+ function hyphenReplace ($0,
16619
+ from, fM, fm, fp, fpr, fb,
16620
+ to, tM, tm, tp, tpr, tb) {
16621
+ if (isX(fM)) {
16622
+ from = '';
16623
+ } else if (isX(fm)) {
16624
+ from = '>=' + fM + '.0.0';
16625
+ } else if (isX(fp)) {
16626
+ from = '>=' + fM + '.' + fm + '.0';
16627
+ } else {
16628
+ from = '>=' + from;
15949
16629
  }
15950
16630
 
15951
- function replaceXRanges(comp, options) {
15952
- debug('replaceXRanges', comp, options);
15953
- return comp.split(/\s+/).map(function (comp) {
15954
- return replaceXRange(comp, options);
15955
- }).join(' ');
16631
+ if (isX(tM)) {
16632
+ to = '';
16633
+ } else if (isX(tm)) {
16634
+ to = '<' + (+tM + 1) + '.0.0';
16635
+ } else if (isX(tp)) {
16636
+ to = '<' + tM + '.' + (+tm + 1) + '.0';
16637
+ } else if (tpr) {
16638
+ to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
16639
+ } else {
16640
+ to = '<=' + to;
15956
16641
  }
15957
16642
 
15958
- function replaceXRange(comp, options) {
15959
- comp = comp.trim();
15960
- var r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
15961
- return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
15962
- debug('xRange', comp, ret, gtlt, M, m, p, pr);
15963
- var xM = isX(M);
15964
- var xm = xM || isX(m);
15965
- var xp = xm || isX(p);
15966
- var anyX = xp;
15967
-
15968
- if (gtlt === '=' && anyX) {
15969
- gtlt = '';
15970
- } // if we're including prereleases in the match, then we need
15971
- // to fix this to -0, the lowest possible prerelease value
15972
-
16643
+ return (from + ' ' + to).trim()
16644
+ }
15973
16645
 
15974
- pr = options.includePrerelease ? '-0' : '';
16646
+ // if ANY of the sets match ALL of its comparators, then pass
16647
+ Range.prototype.test = function (version) {
16648
+ if (!version) {
16649
+ return false
16650
+ }
15975
16651
 
15976
- if (xM) {
15977
- if (gtlt === '>' || gtlt === '<') {
15978
- // nothing is allowed
15979
- ret = '<0.0.0-0';
15980
- } else {
15981
- // nothing is forbidden
15982
- ret = '*';
15983
- }
15984
- } else if (gtlt && anyX) {
15985
- // we know patch is an x, because we have any x at all.
15986
- // replace X with 0
15987
- if (xm) {
15988
- m = 0;
15989
- }
16652
+ if (typeof version === 'string') {
16653
+ try {
16654
+ version = new SemVer(version, this.options);
16655
+ } catch (er) {
16656
+ return false
16657
+ }
16658
+ }
15990
16659
 
15991
- p = 0;
16660
+ for (var i = 0; i < this.set.length; i++) {
16661
+ if (testSet(this.set[i], version, this.options)) {
16662
+ return true
16663
+ }
16664
+ }
16665
+ return false
16666
+ };
15992
16667
 
15993
- if (gtlt === '>') {
15994
- // >1 => >=2.0.0
15995
- // >1.2 => >=1.3.0
15996
- // >1.2.3 => >= 1.2.4
15997
- gtlt = '>=';
16668
+ function testSet (set, version, options) {
16669
+ for (var i = 0; i < set.length; i++) {
16670
+ if (!set[i].test(version)) {
16671
+ return false
16672
+ }
16673
+ }
15998
16674
 
15999
- if (xm) {
16000
- M = +M + 1;
16001
- m = 0;
16002
- p = 0;
16003
- } else {
16004
- m = +m + 1;
16005
- p = 0;
16006
- }
16007
- } else if (gtlt === '<=') {
16008
- // <=0.7.x is actually <0.8.0, since any 0.7.x should
16009
- // pass. Similarly, <=7.x is actually <8.0.0, etc.
16010
- gtlt = '<';
16675
+ if (version.prerelease.length && !options.includePrerelease) {
16676
+ // Find the set of versions that are allowed to have prereleases
16677
+ // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
16678
+ // That should allow `1.2.3-pr.2` to pass.
16679
+ // However, `1.2.4-alpha.notready` should NOT be allowed,
16680
+ // even though it's within the range set by the comparators.
16681
+ for (i = 0; i < set.length; i++) {
16682
+ debug(set[i].semver);
16683
+ if (set[i].semver === ANY) {
16684
+ continue
16685
+ }
16011
16686
 
16012
- if (xm) {
16013
- M = +M + 1;
16014
- } else {
16015
- m = +m + 1;
16016
- }
16687
+ if (set[i].semver.prerelease.length > 0) {
16688
+ var allowed = set[i].semver;
16689
+ if (allowed.major === version.major &&
16690
+ allowed.minor === version.minor &&
16691
+ allowed.patch === version.patch) {
16692
+ return true
16017
16693
  }
16018
-
16019
- ret = gtlt + M + '.' + m + '.' + p + pr;
16020
- } else if (xm) {
16021
- ret = '>=' + M + '.0.0' + pr + ' <' + (+M + 1) + '.0.0' + pr;
16022
- } else if (xp) {
16023
- ret = '>=' + M + '.' + m + '.0' + pr + ' <' + M + '.' + (+m + 1) + '.0' + pr;
16024
16694
  }
16025
-
16026
- debug('xRange return', ret);
16027
- return ret;
16028
- });
16029
- } // Because * is AND-ed with everything else in the comparator,
16030
- // and '' means "any version", just remove the *s entirely.
16031
-
16032
-
16033
- function replaceStars(comp, options) {
16034
- debug('replaceStars', comp, options); // Looseness is ignored here. star is always as loose as it gets!
16035
-
16036
- return comp.trim().replace(re[t.STAR], '');
16037
- } // This function is passed to string.replace(re[t.HYPHENRANGE])
16038
- // M, m, patch, prerelease, build
16039
- // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
16040
- // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
16041
- // 1.2 - 3.4 => >=1.2.0 <3.5.0
16042
-
16043
-
16044
- function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
16045
- if (isX(fM)) {
16046
- from = '';
16047
- } else if (isX(fm)) {
16048
- from = '>=' + fM + '.0.0';
16049
- } else if (isX(fp)) {
16050
- from = '>=' + fM + '.' + fm + '.0';
16051
- } else {
16052
- from = '>=' + from;
16053
16695
  }
16054
16696
 
16055
- if (isX(tM)) {
16056
- to = '';
16057
- } else if (isX(tm)) {
16058
- to = '<' + (+tM + 1) + '.0.0';
16059
- } else if (isX(tp)) {
16060
- to = '<' + tM + '.' + (+tm + 1) + '.0';
16061
- } else if (tpr) {
16062
- to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
16063
- } else {
16064
- to = '<=' + to;
16065
- }
16066
-
16067
- return (from + ' ' + to).trim();
16068
- } // if ANY of the sets match ALL of its comparators, then pass
16069
-
16697
+ // Version has a -pre, but it's not one of the ones we like.
16698
+ return false
16699
+ }
16070
16700
 
16071
- Range.prototype.test = function (version) {
16072
- if (!version) {
16073
- return false;
16074
- }
16701
+ return true
16702
+ }
16075
16703
 
16076
- if (typeof version === 'string') {
16077
- try {
16078
- version = new SemVer(version, this.options);
16079
- } catch (er) {
16080
- return false;
16081
- }
16082
- }
16704
+ exports.satisfies = satisfies;
16705
+ function satisfies (version, range, options) {
16706
+ try {
16707
+ range = new Range(range, options);
16708
+ } catch (er) {
16709
+ return false
16710
+ }
16711
+ return range.test(version)
16712
+ }
16083
16713
 
16084
- for (var i = 0; i < this.set.length; i++) {
16085
- if (testSet(this.set[i], version, this.options)) {
16086
- return true;
16714
+ exports.maxSatisfying = maxSatisfying;
16715
+ function maxSatisfying (versions, range, options) {
16716
+ var max = null;
16717
+ var maxSV = null;
16718
+ try {
16719
+ var rangeObj = new Range(range, options);
16720
+ } catch (er) {
16721
+ return null
16722
+ }
16723
+ versions.forEach(function (v) {
16724
+ if (rangeObj.test(v)) {
16725
+ // satisfies(v, range, options)
16726
+ if (!max || maxSV.compare(v) === -1) {
16727
+ // compare(max, v, true)
16728
+ max = v;
16729
+ maxSV = new SemVer(max, options);
16087
16730
  }
16088
16731
  }
16732
+ });
16733
+ return max
16734
+ }
16089
16735
 
16090
- return false;
16091
- };
16092
-
16093
- function testSet(set, version, options) {
16094
- for (var i = 0; i < set.length; i++) {
16095
- if (!set[i].test(version)) {
16096
- return false;
16736
+ exports.minSatisfying = minSatisfying;
16737
+ function minSatisfying (versions, range, options) {
16738
+ var min = null;
16739
+ var minSV = null;
16740
+ try {
16741
+ var rangeObj = new Range(range, options);
16742
+ } catch (er) {
16743
+ return null
16744
+ }
16745
+ versions.forEach(function (v) {
16746
+ if (rangeObj.test(v)) {
16747
+ // satisfies(v, range, options)
16748
+ if (!min || minSV.compare(v) === 1) {
16749
+ // compare(min, v, true)
16750
+ min = v;
16751
+ minSV = new SemVer(min, options);
16097
16752
  }
16098
16753
  }
16754
+ });
16755
+ return min
16756
+ }
16099
16757
 
16100
- if (version.prerelease.length && !options.includePrerelease) {
16101
- // Find the set of versions that are allowed to have prereleases
16102
- // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
16103
- // That should allow `1.2.3-pr.2` to pass.
16104
- // However, `1.2.4-alpha.notready` should NOT be allowed,
16105
- // even though it's within the range set by the comparators.
16106
- for (i = 0; i < set.length; i++) {
16107
- debug(set[i].semver);
16108
-
16109
- if (set[i].semver === ANY) {
16110
- continue;
16111
- }
16112
-
16113
- if (set[i].semver.prerelease.length > 0) {
16114
- var allowed = set[i].semver;
16115
-
16116
- if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) {
16117
- return true;
16118
- }
16119
- }
16120
- } // Version has a -pre, but it's not one of the ones we like.
16121
-
16122
-
16123
- return false;
16124
- }
16758
+ exports.minVersion = minVersion;
16759
+ function minVersion (range, loose) {
16760
+ range = new Range(range, loose);
16125
16761
 
16126
- return true;
16762
+ var minver = new SemVer('0.0.0');
16763
+ if (range.test(minver)) {
16764
+ return minver
16127
16765
  }
16128
16766
 
16129
- exports.satisfies = satisfies;
16130
-
16131
- function satisfies(version, range, options) {
16132
- try {
16133
- range = new Range(range, options);
16134
- } catch (er) {
16135
- return false;
16136
- }
16137
-
16138
- return range.test(version);
16767
+ minver = new SemVer('0.0.0-0');
16768
+ if (range.test(minver)) {
16769
+ return minver
16139
16770
  }
16140
16771
 
16141
- exports.maxSatisfying = maxSatisfying;
16142
-
16143
- function maxSatisfying(versions, range, options) {
16144
- var max = null;
16145
- var maxSV = null;
16772
+ minver = null;
16773
+ for (var i = 0; i < range.set.length; ++i) {
16774
+ var comparators = range.set[i];
16146
16775
 
16147
- try {
16148
- var rangeObj = new Range(range, options);
16149
- } catch (er) {
16150
- return null;
16151
- }
16152
-
16153
- versions.forEach(function (v) {
16154
- if (rangeObj.test(v)) {
16155
- // satisfies(v, range, options)
16156
- if (!max || maxSV.compare(v) === -1) {
16157
- // compare(max, v, true)
16158
- max = v;
16159
- maxSV = new SemVer(max, options);
16160
- }
16776
+ comparators.forEach(function (comparator) {
16777
+ // Clone to avoid manipulating the comparator's semver object.
16778
+ var compver = new SemVer(comparator.semver.version);
16779
+ switch (comparator.operator) {
16780
+ case '>':
16781
+ if (compver.prerelease.length === 0) {
16782
+ compver.patch++;
16783
+ } else {
16784
+ compver.prerelease.push(0);
16785
+ }
16786
+ compver.raw = compver.format();
16787
+ /* fallthrough */
16788
+ case '':
16789
+ case '>=':
16790
+ if (!minver || gt(minver, compver)) {
16791
+ minver = compver;
16792
+ }
16793
+ break
16794
+ case '<':
16795
+ case '<=':
16796
+ /* Ignore maximum versions */
16797
+ break
16798
+ /* istanbul ignore next */
16799
+ default:
16800
+ throw new Error('Unexpected operation: ' + comparator.operator)
16161
16801
  }
16162
16802
  });
16163
- return max;
16164
16803
  }
16165
16804
 
16166
- exports.minSatisfying = minSatisfying;
16167
-
16168
- function minSatisfying(versions, range, options) {
16169
- var min = null;
16170
- var minSV = null;
16171
-
16172
- try {
16173
- var rangeObj = new Range(range, options);
16174
- } catch (er) {
16175
- return null;
16176
- }
16177
-
16178
- versions.forEach(function (v) {
16179
- if (rangeObj.test(v)) {
16180
- // satisfies(v, range, options)
16181
- if (!min || minSV.compare(v) === 1) {
16182
- // compare(min, v, true)
16183
- min = v;
16184
- minSV = new SemVer(min, options);
16185
- }
16186
- }
16187
- });
16188
- return min;
16805
+ if (minver && range.test(minver)) {
16806
+ return minver
16189
16807
  }
16190
16808
 
16191
- exports.minVersion = minVersion;
16192
-
16193
- function minVersion(range, loose) {
16194
- range = new Range(range, loose);
16195
- var minver = new SemVer('0.0.0');
16196
-
16197
- if (range.test(minver)) {
16198
- return minver;
16199
- }
16200
-
16201
- minver = new SemVer('0.0.0-0');
16202
-
16203
- if (range.test(minver)) {
16204
- return minver;
16205
- }
16206
-
16207
- minver = null;
16208
-
16209
- for (var i = 0; i < range.set.length; ++i) {
16210
- var comparators = range.set[i];
16211
- comparators.forEach(function (comparator) {
16212
- // Clone to avoid manipulating the comparator's semver object.
16213
- var compver = new SemVer(comparator.semver.version);
16214
-
16215
- switch (comparator.operator) {
16216
- case '>':
16217
- if (compver.prerelease.length === 0) {
16218
- compver.patch++;
16219
- } else {
16220
- compver.prerelease.push(0);
16221
- }
16809
+ return null
16810
+ }
16222
16811
 
16223
- compver.raw = compver.format();
16812
+ exports.validRange = validRange;
16813
+ function validRange (range, options) {
16814
+ try {
16815
+ // Return '*' instead of '' so that truthiness works.
16816
+ // This will throw if it's invalid anyway
16817
+ return new Range(range, options).range || '*'
16818
+ } catch (er) {
16819
+ return null
16820
+ }
16821
+ }
16822
+
16823
+ // Determine if version is less than all the versions possible in the range
16824
+ exports.ltr = ltr;
16825
+ function ltr (version, range, options) {
16826
+ return outside(version, range, '<', options)
16827
+ }
16828
+
16829
+ // Determine if version is greater than all the versions possible in the range.
16830
+ exports.gtr = gtr;
16831
+ function gtr (version, range, options) {
16832
+ return outside(version, range, '>', options)
16833
+ }
16834
+
16835
+ exports.outside = outside;
16836
+ function outside (version, range, hilo, options) {
16837
+ version = new SemVer(version, options);
16838
+ range = new Range(range, options);
16839
+
16840
+ var gtfn, ltefn, ltfn, comp, ecomp;
16841
+ switch (hilo) {
16842
+ case '>':
16843
+ gtfn = gt;
16844
+ ltefn = lte;
16845
+ ltfn = lt;
16846
+ comp = '>';
16847
+ ecomp = '>=';
16848
+ break
16849
+ case '<':
16850
+ gtfn = lt;
16851
+ ltefn = gte;
16852
+ ltfn = gt;
16853
+ comp = '<';
16854
+ ecomp = '<=';
16855
+ break
16856
+ default:
16857
+ throw new TypeError('Must provide a hilo val of "<" or ">"')
16858
+ }
16224
16859
 
16225
- /* fallthrough */
16860
+ // If it satisifes the range it is not outside
16861
+ if (satisfies(version, range, options)) {
16862
+ return false
16863
+ }
16226
16864
 
16227
- case '':
16228
- case '>=':
16229
- if (!minver || gt(minver, compver)) {
16230
- minver = compver;
16231
- }
16865
+ // From now on, variable terms are as if we're in "gtr" mode.
16866
+ // but note that everything is flipped for the "ltr" function.
16232
16867
 
16233
- break;
16868
+ for (var i = 0; i < range.set.length; ++i) {
16869
+ var comparators = range.set[i];
16234
16870
 
16235
- case '<':
16236
- case '<=':
16237
- /* Ignore maximum versions */
16238
- break;
16871
+ var high = null;
16872
+ var low = null;
16239
16873
 
16240
- /* istanbul ignore next */
16874
+ comparators.forEach(function (comparator) {
16875
+ if (comparator.semver === ANY) {
16876
+ comparator = new Comparator('>=0.0.0');
16877
+ }
16878
+ high = high || comparator;
16879
+ low = low || comparator;
16880
+ if (gtfn(comparator.semver, high.semver, options)) {
16881
+ high = comparator;
16882
+ } else if (ltfn(comparator.semver, low.semver, options)) {
16883
+ low = comparator;
16884
+ }
16885
+ });
16241
16886
 
16242
- default:
16243
- throw new Error('Unexpected operation: ' + comparator.operator);
16244
- }
16245
- });
16887
+ // If the edge version comparator has a operator then our version
16888
+ // isn't outside it
16889
+ if (high.operator === comp || high.operator === ecomp) {
16890
+ return false
16246
16891
  }
16247
16892
 
16248
- if (minver && range.test(minver)) {
16249
- return minver;
16893
+ // If the lowest version comparator has an operator and our version
16894
+ // is less than it then it isn't higher than the range
16895
+ if ((!low.operator || low.operator === comp) &&
16896
+ ltefn(version, low.semver)) {
16897
+ return false
16898
+ } else if (low.operator === ecomp && ltfn(version, low.semver)) {
16899
+ return false
16250
16900
  }
16251
-
16252
- return null;
16253
16901
  }
16902
+ return true
16903
+ }
16254
16904
 
16255
- exports.validRange = validRange;
16256
-
16257
- function validRange(range, options) {
16258
- try {
16259
- // Return '*' instead of '' so that truthiness works.
16260
- // This will throw if it's invalid anyway
16261
- return new Range(range, options).range || '*';
16262
- } catch (er) {
16263
- return null;
16264
- }
16265
- } // Determine if version is less than all the versions possible in the range
16266
-
16267
-
16268
- exports.ltr = ltr;
16269
-
16270
- function ltr(version, range, options) {
16271
- return outside(version, range, '<', options);
16272
- } // Determine if version is greater than all the versions possible in the range.
16273
-
16905
+ exports.prerelease = prerelease;
16906
+ function prerelease (version, options) {
16907
+ var parsed = parse(version, options);
16908
+ return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
16909
+ }
16274
16910
 
16275
- exports.gtr = gtr;
16911
+ exports.intersects = intersects;
16912
+ function intersects (r1, r2, options) {
16913
+ r1 = new Range(r1, options);
16914
+ r2 = new Range(r2, options);
16915
+ return r1.intersects(r2)
16916
+ }
16276
16917
 
16277
- function gtr(version, range, options) {
16278
- return outside(version, range, '>', options);
16918
+ exports.coerce = coerce;
16919
+ function coerce (version, options) {
16920
+ if (version instanceof SemVer) {
16921
+ return version
16279
16922
  }
16280
16923
 
16281
- exports.outside = outside;
16282
-
16283
- function outside(version, range, hilo, options) {
16284
- version = new SemVer(version, options);
16285
- range = new Range(range, options);
16286
- var gtfn, ltefn, ltfn, comp, ecomp;
16287
-
16288
- switch (hilo) {
16289
- case '>':
16290
- gtfn = gt;
16291
- ltefn = lte;
16292
- ltfn = lt;
16293
- comp = '>';
16294
- ecomp = '>=';
16295
- break;
16296
-
16297
- case '<':
16298
- gtfn = lt;
16299
- ltefn = gte;
16300
- ltfn = gt;
16301
- comp = '<';
16302
- ecomp = '<=';
16303
- break;
16304
-
16305
- default:
16306
- throw new TypeError('Must provide a hilo val of "<" or ">"');
16307
- } // If it satisifes the range it is not outside
16308
-
16309
-
16310
- if (satisfies(version, range, options)) {
16311
- return false;
16312
- } // From now on, variable terms are as if we're in "gtr" mode.
16313
- // but note that everything is flipped for the "ltr" function.
16314
-
16315
-
16316
- for (var i = 0; i < range.set.length; ++i) {
16317
- var comparators = range.set[i];
16318
- var high = null;
16319
- var low = null;
16320
- comparators.forEach(function (comparator) {
16321
- if (comparator.semver === ANY) {
16322
- comparator = new Comparator('>=0.0.0');
16323
- }
16324
-
16325
- high = high || comparator;
16326
- low = low || comparator;
16327
-
16328
- if (gtfn(comparator.semver, high.semver, options)) {
16329
- high = comparator;
16330
- } else if (ltfn(comparator.semver, low.semver, options)) {
16331
- low = comparator;
16332
- }
16333
- }); // If the edge version comparator has a operator then our version
16334
- // isn't outside it
16924
+ if (typeof version === 'number') {
16925
+ version = String(version);
16926
+ }
16335
16927
 
16336
- if (high.operator === comp || high.operator === ecomp) {
16337
- return false;
16338
- } // If the lowest version comparator has an operator and our version
16339
- // is less than it then it isn't higher than the range
16928
+ if (typeof version !== 'string') {
16929
+ return null
16930
+ }
16340
16931
 
16932
+ options = options || {};
16341
16933
 
16342
- if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
16343
- return false;
16344
- } else if (low.operator === ecomp && ltfn(version, low.semver)) {
16345
- return false;
16934
+ var match = null;
16935
+ if (!options.rtl) {
16936
+ match = version.match(re[t.COERCE]);
16937
+ } else {
16938
+ // Find the right-most coercible string that does not share
16939
+ // a terminus with a more left-ward coercible string.
16940
+ // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
16941
+ //
16942
+ // Walk through the string checking with a /g regexp
16943
+ // Manually set the index so as to pick up overlapping matches.
16944
+ // Stop when we get a match that ends at the string end, since no
16945
+ // coercible string can be more right-ward without the same terminus.
16946
+ var next;
16947
+ while ((next = re[t.COERCERTL].exec(version)) &&
16948
+ (!match || match.index + match[0].length !== version.length)
16949
+ ) {
16950
+ if (!match ||
16951
+ next.index + next[0].length !== match.index + match[0].length) {
16952
+ match = next;
16346
16953
  }
16954
+ re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length;
16347
16955
  }
16348
-
16349
- return true;
16956
+ // leave it in a clean state
16957
+ re[t.COERCERTL].lastIndex = -1;
16350
16958
  }
16351
16959
 
16352
- exports.prerelease = prerelease;
16353
-
16354
- function prerelease(version, options) {
16355
- var parsed = parse(version, options);
16356
- return parsed && parsed.prerelease.length ? parsed.prerelease : null;
16960
+ if (match === null) {
16961
+ return null
16357
16962
  }
16358
16963
 
16359
- exports.intersects = intersects;
16360
-
16361
- function intersects(r1, r2, options) {
16362
- r1 = new Range(r1, options);
16363
- r2 = new Range(r2, options);
16364
- return r1.intersects(r2);
16365
- }
16366
-
16367
- exports.coerce = coerce;
16368
-
16369
- function coerce(version, options) {
16370
- if (version instanceof SemVer) {
16371
- return version;
16372
- }
16373
-
16374
- if (typeof version === 'number') {
16375
- version = String(version);
16376
- }
16377
-
16378
- if (typeof version !== 'string') {
16379
- return null;
16380
- }
16381
-
16382
- options = options || {};
16383
- var match = null;
16384
-
16385
- if (!options.rtl) {
16386
- match = version.match(re[t.COERCE]);
16387
- } else {
16388
- // Find the right-most coercible string that does not share
16389
- // a terminus with a more left-ward coercible string.
16390
- // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
16391
- //
16392
- // Walk through the string checking with a /g regexp
16393
- // Manually set the index so as to pick up overlapping matches.
16394
- // Stop when we get a match that ends at the string end, since no
16395
- // coercible string can be more right-ward without the same terminus.
16396
- var next;
16397
-
16398
- while ((next = re[t.COERCERTL].exec(version)) && (!match || match.index + match[0].length !== version.length)) {
16399
- if (!match || next.index + next[0].length !== match.index + match[0].length) {
16400
- match = next;
16401
- }
16402
-
16403
- re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length;
16404
- } // leave it in a clean state
16405
-
16406
-
16407
- re[t.COERCERTL].lastIndex = -1;
16408
- }
16409
-
16410
- if (match === null) {
16411
- return null;
16412
- }
16413
-
16414
- return parse(match[2] + '.' + (match[3] || '0') + '.' + (match[4] || '0'), options);
16415
- }
16416
- })(semver, semver.exports);
16964
+ return parse(match[2] +
16965
+ '.' + (match[3] || '0') +
16966
+ '.' + (match[4] || '0'), options)
16967
+ }
16968
+ }(semver, semver.exports));
16417
16969
 
16418
16970
  const LOADED = {};
16419
16971
  /**
@@ -16973,6 +17525,22 @@ function nuked() {
16973
17525
  if (!fieldName) {
16974
17526
  throw new Error("Field identifier must be provided");
16975
17527
  }
17528
+ /**
17529
+ * @typedef { 'ltr' | 'rtl' } Direction
17530
+ */
17531
+
17532
+ /**
17533
+ * @typedef { 'vertical' | 'horizontal' } ListLayout
17534
+ */
17535
+
17536
+ /**
17537
+ * @typedef { 'none' | 'value' | 'percent' | 'relative' } FrequencyMode
17538
+ */
17539
+
17540
+ /**
17541
+ * @typedef { false | true | 'toggle' } SearchMode
17542
+ */
17543
+
16976
17544
  /**
16977
17545
  * @typedef {function(function)} ReceiverFunction A callback function which receives another function as input.
16978
17546
  */
@@ -16992,9 +17560,13 @@ function nuked() {
16992
17560
  * @param {HTMLElement} element
16993
17561
  * @param {object=} options Settings for the embedded listbox
16994
17562
  * @param {string=} options.title Custom title, defaults to fieldname
16995
- * @param {string=} [options.direction=ltr] Direction setting ltr|rtl.
16996
- * @param {string=} [options.listLayout=vertical] Layout direction vertical|horizontal
16997
- * @param {boolean=} [options.search=true] Show the search bar
17563
+ * @param {Direction=} [options.direction=ltr] Direction setting ltr|rtl.
17564
+ * @param {ListLayout=} [options.listLayout=vertical] Layout direction vertical|horizontal
17565
+ * @param {FrequencyMode=} [options.frequencyMode=none] Show frequency none|value|percent|relative
17566
+ * @param {boolean=} [options.histogram=false] Show histogram bar
17567
+ * @param {SearchMode=} [options.search=true] Show the search bar permanently or using the toggle button: false|true|toggle|toggleShow
17568
+ * @param {boolean=} [options.focusSearch=false] Initialize the Listbox with the search input focused. Only applicable when
17569
+ * search is true, since toggling will always focus the search input on show.
16998
17570
  * @param {boolean=} [options.toolbar=true] Show the toolbar
16999
17571
  * @param {boolean=} [options.checkboxes=false] Show values as checkboxes instead of as fields
17000
17572
  * @param {boolean=} [options.rangeSelect=true] Enable range selection
@@ -17003,6 +17575,7 @@ function nuked() {
17003
17575
  * @param {object=} [options.properties={}] Properties object to extend default properties with
17004
17576
  * @param {object} [options.sessionModel] Use a custom sessionModel.
17005
17577
  * @param {object} [options.selectionsApi] Use a custom selectionsApi to customize how values are selected.
17578
+ * @param {function():boolean} [options.selectDisabled=] Define a function which tells when selections are disabled (true) or enabled (false). By default, always returns false.
17006
17579
  * @param {ReceiverFunction} [options.update] A function which receives an update function which upon call will trigger a data fetch.
17007
17580
  * @since 1.1.0
17008
17581
  * @instance