@zeedhi/common 1.69.0 → 1.71.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.
@@ -2869,9 +2869,9 @@ class ModalService {
2869
2869
  * Creates a new modal instance from JSON
2870
2870
  * @param modal modal structure
2871
2871
  */
2872
- static createFromJson(modalPath, local) {
2872
+ static createFromJson(modalPath, local, JSONCache) {
2873
2873
  return __awaiter(this, void 0, void 0, function* () {
2874
- const modal = yield Metadata.get(modalPath, local);
2874
+ const modal = yield Metadata.get(modalPath, local, JSONCache);
2875
2875
  return this.create(modal);
2876
2876
  });
2877
2877
  }
@@ -2948,37 +2948,6 @@ class LoadingService {
2948
2948
  }
2949
2949
  }
2950
2950
 
2951
- class JsonCacheService {
2952
- static saveJSONCache(jsonCollection) {
2953
- return __awaiter(this, void 0, void 0, function* () {
2954
- const jsonCollectionInCache = jsonCollection.map((jsonItem) => __awaiter(this, void 0, void 0, function* () {
2955
- const { path } = jsonItem;
2956
- const metadata = yield Metadata.get(path, true);
2957
- localStorage.setItem(path, JSON.stringify(metadata));
2958
- }));
2959
- yield Promise.all(jsonCollectionInCache);
2960
- });
2961
- }
2962
- static getJSONCache(path) {
2963
- const getMetadaFromCache = localStorage.getItem(path);
2964
- let metadataValueReturn = false;
2965
- if (typeof getMetadaFromCache === 'string') {
2966
- metadataValueReturn = JSON.parse(getMetadaFromCache);
2967
- }
2968
- return metadataValueReturn;
2969
- }
2970
- static clearJSONCache(jsonCollection) {
2971
- jsonCollection.map((jsonItem) => __awaiter(this, void 0, void 0, function* () {
2972
- const { path } = jsonItem;
2973
- localStorage.removeItem(path);
2974
- }));
2975
- }
2976
- }
2977
- /**
2978
- * jsons collection
2979
- */
2980
- JsonCacheService.jsonCollection = [];
2981
-
2982
2951
  /**
2983
2952
  * Base class for Dashboard component.
2984
2953
  */
@@ -4589,18 +4558,8 @@ class Frame extends ComponentRender {
4589
4558
  }
4590
4559
  getMetadata() {
4591
4560
  return __awaiter(this, void 0, void 0, function* () {
4592
- let page;
4593
4561
  try {
4594
- if (this.JSONCache) {
4595
- page = JsonCacheService.getJSONCache(this.path);
4596
- if (page === false) {
4597
- yield JsonCacheService.saveJSONCache([{ path: this.path }]);
4598
- page = yield this.requestPage();
4599
- }
4600
- }
4601
- else {
4602
- page = yield this.requestPage();
4603
- }
4562
+ const page = yield this.requestPage();
4604
4563
  if (typeof page !== 'object')
4605
4564
  throw new Error();
4606
4565
  this.metadata = merge(page, this.override);
@@ -4640,7 +4599,7 @@ class Frame extends ComponentRender {
4640
4599
  if (this.type === 'post') {
4641
4600
  return Metadata.post(this.path, this.params);
4642
4601
  }
4643
- return Metadata.get(this.path, this.local);
4602
+ return Metadata.get(this.path, this.local, this.JSONCache);
4644
4603
  }
4645
4604
  const url = Metadata.getMetadataUrl(this.path, this.local);
4646
4605
  const cache = yield caches.open(Frame.cacheName);
@@ -9985,8 +9944,9 @@ class SelectTree extends TextInput {
9985
9944
  }
9986
9945
  setValue(value) {
9987
9946
  let val = value;
9947
+ const key = this.datasource ? this.dataValue : 'id';
9988
9948
  if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
9989
- val = value[this.dataValue];
9949
+ val = value[key];
9990
9950
  }
9991
9951
  else if (!value && value !== 0) {
9992
9952
  val = null;
@@ -10042,9 +10002,14 @@ class SelectTreeMultiple extends SelectTree {
10042
10002
  * Changes the behavior of checked nodes that will be displayed in the array of values
10043
10003
  */
10044
10004
  this.valueConsistsOf = 'LEAF_PRIORITY';
10005
+ /**
10006
+ * Show the selectAll option
10007
+ */
10008
+ this.showSelectAll = false;
10045
10009
  this.flat = this.getInitValue('flat', props.flat, this.flat);
10046
10010
  this.limit = this.getInitValue('limit', props.limit, this.limit);
10047
10011
  this.valueConsistsOf = this.getInitValue('valueConsistsOf', props.valueConsistsOf, this.valueConsistsOf);
10012
+ this.showSelectAll = this.getInitValue('showSelectAll', props.showSelectAll, this.showSelectAll);
10048
10013
  this.createAccessors();
10049
10014
  }
10050
10015
  /**
@@ -10070,23 +10035,57 @@ class SelectTreeMultiple extends SelectTree {
10070
10035
  }
10071
10036
  setValue(value) {
10072
10037
  const arrValue = Array.isArray(value) ? value : [value];
10073
- if (this.returnObject) {
10074
- this.value = arrValue.map((item) => {
10075
- if (typeof item !== 'object') {
10076
- return { id: item };
10077
- }
10078
- return { id: item[this.dataValue] };
10079
- });
10080
- }
10081
- else {
10038
+ const key = this.datasource ? this.dataValue : 'id';
10039
+ if (!this.returnObject) {
10082
10040
  this.value = arrValue.map((item) => {
10083
10041
  if (typeof item === 'object') {
10084
- return item[this.dataValue];
10042
+ return item[key];
10085
10043
  }
10086
10044
  return item;
10087
10045
  });
10046
+ return;
10047
+ }
10048
+ this.value = arrValue.map((item) => {
10049
+ if (typeof item !== 'object') {
10050
+ return { id: item };
10051
+ }
10052
+ return { id: item[key] };
10053
+ });
10054
+ }
10055
+ getAllNodes(nodes = this.nodes) {
10056
+ let result = nodes;
10057
+ nodes.forEach((node) => {
10058
+ if (!node.children)
10059
+ return;
10060
+ const childNodes = this.getAllNodes(node.children);
10061
+ result = [...result, ...childNodes];
10062
+ });
10063
+ return result;
10064
+ }
10065
+ /**
10066
+ * Dispatches select/unselect event
10067
+ */
10068
+ onSelectAll(isSelected, event, element) {
10069
+ if (isSelected) {
10070
+ this.callEvent('selectedAll', { event, element, component: this });
10071
+ if (!event.defaultPrevented) {
10072
+ this.selectAllItems();
10073
+ }
10074
+ }
10075
+ else {
10076
+ this.callEvent('unselectedAll', { event, element, component: this });
10077
+ if (!event.defaultPrevented) {
10078
+ this.unSelectAllItems();
10079
+ }
10088
10080
  }
10089
10081
  }
10082
+ selectAllItems() {
10083
+ const allNodes = this.datasource ? this.datasource.data : this.getAllNodes();
10084
+ this.setValue(allNodes);
10085
+ }
10086
+ unSelectAllItems() {
10087
+ this.setValue([]);
10088
+ }
10090
10089
  }
10091
10090
 
10092
10091
  /**
@@ -10660,6 +10659,27 @@ class Textarea extends TextInput {
10660
10659
  }
10661
10660
  }
10662
10661
 
10662
+ /**
10663
+ * Selects the time format by the rule:
10664
+ * non-common format > common format
10665
+ * and if the format is a common format, it will be overriden by timeFormat
10666
+ */
10667
+ class TimeFormatSelector {
10668
+ getFormat(format, timeFormat, useSeconds) {
10669
+ const commonsDisplay = ['hh:mm A', 'hh:mm:ss A', 'HH:mm:ss', 'HH:mm'];
10670
+ const seconds = useSeconds ? ':ss' : '';
10671
+ const defaultFormats = {
10672
+ ampm: `hh:mm${seconds} A`,
10673
+ '24hr': `HH:mm${seconds}`,
10674
+ };
10675
+ const timeFormats = ['ampm', '24hr'];
10676
+ if (commonsDisplay.includes(format) && timeFormats.includes(timeFormat)) {
10677
+ return defaultFormats[timeFormat];
10678
+ }
10679
+ return format;
10680
+ }
10681
+ }
10682
+
10663
10683
  /**
10664
10684
  * Base class for Time Picker component.
10665
10685
  */
@@ -10748,21 +10768,20 @@ class Time extends TextInput {
10748
10768
  this.initialMask = this.getInitialMask();
10749
10769
  this.isSimpleDisplay = this.isSimpleFormat(this.displayFormat);
10750
10770
  }
10771
+ getFormat(format, timeFormat) {
10772
+ const timeFormatSelector = new TimeFormatSelector();
10773
+ const selectedFormat = timeFormatSelector.getFormat(format, timeFormat, this.useSeconds);
10774
+ return selectedFormat;
10775
+ }
10751
10776
  get displayFormat() {
10752
- const commonsDisplay = ['hh:mm A', 'hh:mm:ss A', 'HH:mm:ss', 'HH:mm'];
10753
- if (commonsDisplay.includes(this.displayFormatInternal)) {
10754
- this.displayFormatInternal = this.defaultFormats[this.timeFormat];
10755
- }
10777
+ this.displayFormatInternal = this.getFormat(this.displayFormatInternal, this.timeFormat);
10756
10778
  return this.displayFormatInternal;
10757
10779
  }
10758
10780
  set displayFormat(value) {
10759
10781
  this.displayFormatInternal = value;
10760
10782
  }
10761
10783
  get valueFormat() {
10762
- const commonsDisplay = ['hh:mm A', 'hh:mm:ss A', 'HH:mm:ss', 'HH:mm'];
10763
- if (commonsDisplay.includes(this.valueFormatInternal)) {
10764
- this.valueFormatInternal = this.defaultFormats['24hr'];
10765
- }
10784
+ this.valueFormatInternal = this.getFormat(this.valueFormatInternal, '24hr');
10766
10785
  return this.valueFormatInternal;
10767
10786
  }
10768
10787
  set valueFormat(value) {
@@ -10772,13 +10791,6 @@ class Time extends TextInput {
10772
10791
  this.isoFormatValue = this.useSeconds ? 'HH:mm:ss' : 'HH:mm';
10773
10792
  return this.isoFormatValue;
10774
10793
  }
10775
- get defaultFormats() {
10776
- const seconds = this.useSeconds ? ':ss' : '';
10777
- return {
10778
- ampm: `hh:mm${seconds} A`,
10779
- '24hr': `HH:mm${seconds}`,
10780
- };
10781
- }
10782
10794
  getInitialMask() {
10783
10795
  if (isUndefined(this.mask)) {
10784
10796
  this.mask = this.inputFormat && this.maskFormat(this.inputFormat);
@@ -10985,45 +10997,51 @@ class Time extends TextInput {
10985
10997
  this.change(this.value);
10986
10998
  }
10987
10999
  }
10988
- FormatterParserProvider.registerFormatter('ZdTime', (value, { valueFormat = Config.valueTimeFormat, displayFormat = Config.displayTimeFormat, inputFormat = Config.timeInputFormat, mask = '', initialMask, isSimpleDisplay = false, } = {}) => {
11000
+ FormatterParserProvider.registerFormatter('ZdTime', (value, { valueFormat = Config.valueTimeFormat, displayFormat = Config.displayTimeFormat, inputFormat = Config.timeInputFormat, timeFormat = Config.timeFormat || 'ampm', useSeconds = false, mask = '', initialMask, isSimpleDisplay = false, } = {}) => {
10989
11001
  if (!value) {
10990
11002
  return '';
10991
11003
  }
10992
- const isTimeValid = dayjs(value, valueFormat, true).isValid();
11004
+ const timeFormatSelector = new TimeFormatSelector();
11005
+ const timeDisplayFormat = timeFormatSelector.getFormat(displayFormat, timeFormat, useSeconds);
11006
+ const timeValueFormat = timeFormatSelector.getFormat(valueFormat, '24hr', useSeconds);
11007
+ const isTimeValid = dayjs(value, timeValueFormat, true).isValid();
10993
11008
  if (!isTimeValid) {
10994
11009
  return value;
10995
11010
  }
10996
11011
  if (mask && initialMask) {
10997
11012
  if (inputFormat) {
10998
- return dayjs(value, valueFormat).format(inputFormat);
11013
+ return dayjs(value, timeValueFormat).format(inputFormat);
10999
11014
  }
11000
11015
  let valueToUnmask = value;
11001
11016
  if (isSimpleDisplay) {
11002
- valueToUnmask = dayjs(value, valueFormat).format(displayFormat);
11017
+ valueToUnmask = dayjs(value, timeValueFormat).format(timeDisplayFormat);
11003
11018
  }
11004
11019
  const unmasked = Mask.getValueWithoutMask(valueToUnmask);
11005
11020
  const masked = Mask.getValueWithMask(unmasked, mask);
11006
11021
  return masked;
11007
11022
  }
11008
- return dayjs(value, valueFormat).format(displayFormat);
11023
+ return dayjs(value, timeValueFormat).format(timeDisplayFormat);
11009
11024
  });
11010
- FormatterParserProvider.registerParser('ZdTime', (value, { displayFormat = Config.displayTimeFormat, valueFormat = Config.valueTimeFormat, mask = '', initialMask, } = {}) => {
11025
+ FormatterParserProvider.registerParser('ZdTime', (value, { displayFormat = Config.displayTimeFormat, valueFormat = Config.valueTimeFormat, timeFormat = Config.timeFormat || 'ampm', useSeconds = false, mask = '', initialMask, } = {}) => {
11011
11026
  if (!value) {
11012
11027
  return null;
11013
11028
  }
11014
- if (dayjs(value, displayFormat, true).isValid()) {
11015
- return dayjs(value, displayFormat).format(valueFormat);
11029
+ const timeFormatSelector = new TimeFormatSelector();
11030
+ const timeDisplayFormat = timeFormatSelector.getFormat(displayFormat, timeFormat, useSeconds);
11031
+ const timeValueFormat = timeFormatSelector.getFormat(valueFormat, '24hr', useSeconds);
11032
+ if (dayjs(value, timeDisplayFormat, true).isValid()) {
11033
+ return dayjs(value, timeDisplayFormat).format(timeValueFormat);
11016
11034
  }
11017
11035
  if (mask && Mask.checkMask(value, mask)) {
11018
11036
  const unmasked = Mask.getValueWithoutMask(value);
11019
11037
  let masked;
11020
11038
  if (!initialMask) {
11021
- const displayFmtMask = displayFormat.replace(/[A-Za-z]/gi, '#');
11039
+ const displayFmtMask = timeDisplayFormat.replace(/[A-Za-z]/gi, '#');
11022
11040
  masked = Mask.getValueWithMask(unmasked, displayFmtMask);
11023
11041
  }
11024
- const timeFmtMask = valueFormat.replace(/[A-Za-z]/gi, '#');
11042
+ const timeFmtMask = timeValueFormat.replace(/[A-Za-z]/gi, '#');
11025
11043
  masked = Mask.getValueWithMask(unmasked, timeFmtMask);
11026
- if (dayjs(masked, valueFormat, true).format(valueFormat) === masked) {
11044
+ if (dayjs(masked, timeValueFormat, true).format(timeValueFormat) === masked) {
11027
11045
  return masked;
11028
11046
  }
11029
11047
  }
@@ -11550,6 +11568,7 @@ class TreeGrid extends Grid {
11550
11568
  this.parentField = this.getInitValue('parentField', props.parentField, this.parentField);
11551
11569
  this.fetchOnDemand = this.getInitValue('fetchOnDemand', props.fetchOnDemand, this.fetchOnDemand);
11552
11570
  this.flat = this.getInitValue('flat', props.flat, this.flat);
11571
+ this.fieldHasChild = this.getInitValue('fieldHasChild', props.fieldHasChild, this.fieldHasChild);
11553
11572
  this.detach = this.getInitValue('detach', props.detach, this.detach);
11554
11573
  this.treeDataStructure = new TreeDataStructure(this);
11555
11574
  this.createAccessors();
@@ -11668,7 +11687,9 @@ class TreeGrid extends Grid {
11668
11687
  * @param isSelected row is selected
11669
11688
  */
11670
11689
  selectRow(row, isSelected) {
11671
- const childrenRows = !this.flat ? this.treeDataStructure.getChildren(row) : [];
11690
+ const childrenRows = !this.flat
11691
+ ? this.treeDataStructure.getChildren(row)
11692
+ : [];
11672
11693
  const rows = [row, ...childrenRows];
11673
11694
  if (isSelected) {
11674
11695
  this.selectedRows = this.removeDuplicates(this.selectedRows.concat(rows), this.datasource.uniqueKey);
@@ -11711,7 +11732,9 @@ class TreeGrid extends Grid {
11711
11732
  selectParents(row) {
11712
11733
  if (row[this.parentField]) {
11713
11734
  const parentRow = this.treeDataStructure.getRowData(row).tree__parent;
11714
- const every = this.treeDataStructure.getChildren(parentRow).every((item) => {
11735
+ const every = this.treeDataStructure
11736
+ .getChildren(parentRow)
11737
+ .every((item) => {
11715
11738
  const index = this.treeDataStructure.findDataIndex(this.selectedRows, item[this.datasource.uniqueKey]);
11716
11739
  if (index > -1)
11717
11740
  return true;
@@ -13379,4 +13402,4 @@ const AutoNumeric = require('@zeedhi/autonumeric/dist/autoNumeric');
13379
13402
  const packageContent = require('../package.json');
13380
13403
  VersionService.addPackageVersion(packageContent.name, packageContent.version);
13381
13404
 
13382
- export { Alert, AlertService, ApexChart, AutoNumeric, Badge, Breadcrumbs, Button, ButtonGroup, CSVReport, Card, Carousel, Checkbox, CheckboxMultiple, ChildNotFoundError, Chip, CodeEditor, Col, CollapseCard, Column, ColumnNotFoundError, Component, ComponentRender, Container, Currency, Dashboard, Date$1 as Date, DateRange, Dialog, DialogService, Divider, Dropdown, FileInput, Footer, Form, Frame, FramePage, Grid, GridColumn, GridColumnEditable, GridEditable, Header, Icon, Icons, Image, Increment, Input, Iterable, IterableColumnsButton, IterableColumnsButtonController, IterableComponentRender, IterablePageComponent, IterablePageInfo, IterablePageSize, IterablePagination, JsonCacheService, List, ListGroup, ListItem, Loading, LoadingService, Login, LoginButton, MasterDetail, Menu, MenuButton, MenuGroup, MenuLink, MenuSeparator, Modal, ModalCloseButton, ModalService, Month, Number$1 as Number, PDFReport, Password, Progress, Radio, RangeSlider, Report, Row, Search, Select, SelectMultiple, SelectTree, SelectTreeMultiple, SelectableList, SpeedDial, Steppers, SvgMap, Switch, Tab, Table, Tabs, Tag, Text, TextInput, Textarea, Time, Toggleable, Tooltip, Tree, TreeDataStructure, TreeGrid, TreeGridEditable, WatchURL, XLS2Report, XLS3Report, XLSReport, initTheme };
13405
+ export { Alert, AlertService, ApexChart, AutoNumeric, Badge, Breadcrumbs, Button, ButtonGroup, CSVReport, Card, Carousel, Checkbox, CheckboxMultiple, ChildNotFoundError, Chip, CodeEditor, Col, CollapseCard, Column, ColumnNotFoundError, Component, ComponentRender, Container, Currency, Dashboard, Date$1 as Date, DateRange, Dialog, DialogService, Divider, Dropdown, FileInput, Footer, Form, Frame, FramePage, Grid, GridColumn, GridColumnEditable, GridEditable, Header, Icon, Icons, Image, Increment, Input, Iterable, IterableColumnsButton, IterableColumnsButtonController, IterableComponentRender, IterablePageComponent, IterablePageInfo, IterablePageSize, IterablePagination, List, ListGroup, ListItem, Loading, LoadingService, Login, LoginButton, MasterDetail, Menu, MenuButton, MenuGroup, MenuLink, MenuSeparator, Modal, ModalCloseButton, ModalService, Month, Number$1 as Number, PDFReport, Password, Progress, Radio, RangeSlider, Report, Row, Search, Select, SelectMultiple, SelectTree, SelectTreeMultiple, SelectableList, SpeedDial, Steppers, SvgMap, Switch, Tab, Table, Tabs, Tag, Text, TextInput, Textarea, Time, Toggleable, Tooltip, Tree, TreeDataStructure, TreeGrid, TreeGridEditable, WatchURL, XLS2Report, XLS3Report, XLSReport, initTheme };
@@ -2876,9 +2876,9 @@
2876
2876
  * Creates a new modal instance from JSON
2877
2877
  * @param modal modal structure
2878
2878
  */
2879
- static createFromJson(modalPath, local) {
2879
+ static createFromJson(modalPath, local, JSONCache) {
2880
2880
  return __awaiter(this, void 0, void 0, function* () {
2881
- const modal = yield core.Metadata.get(modalPath, local);
2881
+ const modal = yield core.Metadata.get(modalPath, local, JSONCache);
2882
2882
  return this.create(modal);
2883
2883
  });
2884
2884
  }
@@ -2955,37 +2955,6 @@
2955
2955
  }
2956
2956
  }
2957
2957
 
2958
- class JsonCacheService {
2959
- static saveJSONCache(jsonCollection) {
2960
- return __awaiter(this, void 0, void 0, function* () {
2961
- const jsonCollectionInCache = jsonCollection.map((jsonItem) => __awaiter(this, void 0, void 0, function* () {
2962
- const { path } = jsonItem;
2963
- const metadata = yield core.Metadata.get(path, true);
2964
- localStorage.setItem(path, JSON.stringify(metadata));
2965
- }));
2966
- yield Promise.all(jsonCollectionInCache);
2967
- });
2968
- }
2969
- static getJSONCache(path) {
2970
- const getMetadaFromCache = localStorage.getItem(path);
2971
- let metadataValueReturn = false;
2972
- if (typeof getMetadaFromCache === 'string') {
2973
- metadataValueReturn = JSON.parse(getMetadaFromCache);
2974
- }
2975
- return metadataValueReturn;
2976
- }
2977
- static clearJSONCache(jsonCollection) {
2978
- jsonCollection.map((jsonItem) => __awaiter(this, void 0, void 0, function* () {
2979
- const { path } = jsonItem;
2980
- localStorage.removeItem(path);
2981
- }));
2982
- }
2983
- }
2984
- /**
2985
- * jsons collection
2986
- */
2987
- JsonCacheService.jsonCollection = [];
2988
-
2989
2958
  /**
2990
2959
  * Base class for Dashboard component.
2991
2960
  */
@@ -4596,18 +4565,8 @@
4596
4565
  }
4597
4566
  getMetadata() {
4598
4567
  return __awaiter(this, void 0, void 0, function* () {
4599
- let page;
4600
4568
  try {
4601
- if (this.JSONCache) {
4602
- page = JsonCacheService.getJSONCache(this.path);
4603
- if (page === false) {
4604
- yield JsonCacheService.saveJSONCache([{ path: this.path }]);
4605
- page = yield this.requestPage();
4606
- }
4607
- }
4608
- else {
4609
- page = yield this.requestPage();
4610
- }
4569
+ const page = yield this.requestPage();
4611
4570
  if (typeof page !== 'object')
4612
4571
  throw new Error();
4613
4572
  this.metadata = merge__default["default"](page, this.override);
@@ -4647,7 +4606,7 @@
4647
4606
  if (this.type === 'post') {
4648
4607
  return core.Metadata.post(this.path, this.params);
4649
4608
  }
4650
- return core.Metadata.get(this.path, this.local);
4609
+ return core.Metadata.get(this.path, this.local, this.JSONCache);
4651
4610
  }
4652
4611
  const url = core.Metadata.getMetadataUrl(this.path, this.local);
4653
4612
  const cache = yield caches.open(Frame.cacheName);
@@ -9992,8 +9951,9 @@
9992
9951
  }
9993
9952
  setValue(value) {
9994
9953
  let val = value;
9954
+ const key = this.datasource ? this.dataValue : 'id';
9995
9955
  if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
9996
- val = value[this.dataValue];
9956
+ val = value[key];
9997
9957
  }
9998
9958
  else if (!value && value !== 0) {
9999
9959
  val = null;
@@ -10049,9 +10009,14 @@
10049
10009
  * Changes the behavior of checked nodes that will be displayed in the array of values
10050
10010
  */
10051
10011
  this.valueConsistsOf = 'LEAF_PRIORITY';
10012
+ /**
10013
+ * Show the selectAll option
10014
+ */
10015
+ this.showSelectAll = false;
10052
10016
  this.flat = this.getInitValue('flat', props.flat, this.flat);
10053
10017
  this.limit = this.getInitValue('limit', props.limit, this.limit);
10054
10018
  this.valueConsistsOf = this.getInitValue('valueConsistsOf', props.valueConsistsOf, this.valueConsistsOf);
10019
+ this.showSelectAll = this.getInitValue('showSelectAll', props.showSelectAll, this.showSelectAll);
10055
10020
  this.createAccessors();
10056
10021
  }
10057
10022
  /**
@@ -10077,23 +10042,57 @@
10077
10042
  }
10078
10043
  setValue(value) {
10079
10044
  const arrValue = Array.isArray(value) ? value : [value];
10080
- if (this.returnObject) {
10081
- this.value = arrValue.map((item) => {
10082
- if (typeof item !== 'object') {
10083
- return { id: item };
10084
- }
10085
- return { id: item[this.dataValue] };
10086
- });
10087
- }
10088
- else {
10045
+ const key = this.datasource ? this.dataValue : 'id';
10046
+ if (!this.returnObject) {
10089
10047
  this.value = arrValue.map((item) => {
10090
10048
  if (typeof item === 'object') {
10091
- return item[this.dataValue];
10049
+ return item[key];
10092
10050
  }
10093
10051
  return item;
10094
10052
  });
10053
+ return;
10054
+ }
10055
+ this.value = arrValue.map((item) => {
10056
+ if (typeof item !== 'object') {
10057
+ return { id: item };
10058
+ }
10059
+ return { id: item[key] };
10060
+ });
10061
+ }
10062
+ getAllNodes(nodes = this.nodes) {
10063
+ let result = nodes;
10064
+ nodes.forEach((node) => {
10065
+ if (!node.children)
10066
+ return;
10067
+ const childNodes = this.getAllNodes(node.children);
10068
+ result = [...result, ...childNodes];
10069
+ });
10070
+ return result;
10071
+ }
10072
+ /**
10073
+ * Dispatches select/unselect event
10074
+ */
10075
+ onSelectAll(isSelected, event, element) {
10076
+ if (isSelected) {
10077
+ this.callEvent('selectedAll', { event, element, component: this });
10078
+ if (!event.defaultPrevented) {
10079
+ this.selectAllItems();
10080
+ }
10081
+ }
10082
+ else {
10083
+ this.callEvent('unselectedAll', { event, element, component: this });
10084
+ if (!event.defaultPrevented) {
10085
+ this.unSelectAllItems();
10086
+ }
10095
10087
  }
10096
10088
  }
10089
+ selectAllItems() {
10090
+ const allNodes = this.datasource ? this.datasource.data : this.getAllNodes();
10091
+ this.setValue(allNodes);
10092
+ }
10093
+ unSelectAllItems() {
10094
+ this.setValue([]);
10095
+ }
10097
10096
  }
10098
10097
 
10099
10098
  /**
@@ -10667,6 +10666,27 @@
10667
10666
  }
10668
10667
  }
10669
10668
 
10669
+ /**
10670
+ * Selects the time format by the rule:
10671
+ * non-common format > common format
10672
+ * and if the format is a common format, it will be overriden by timeFormat
10673
+ */
10674
+ class TimeFormatSelector {
10675
+ getFormat(format, timeFormat, useSeconds) {
10676
+ const commonsDisplay = ['hh:mm A', 'hh:mm:ss A', 'HH:mm:ss', 'HH:mm'];
10677
+ const seconds = useSeconds ? ':ss' : '';
10678
+ const defaultFormats = {
10679
+ ampm: `hh:mm${seconds} A`,
10680
+ '24hr': `HH:mm${seconds}`,
10681
+ };
10682
+ const timeFormats = ['ampm', '24hr'];
10683
+ if (commonsDisplay.includes(format) && timeFormats.includes(timeFormat)) {
10684
+ return defaultFormats[timeFormat];
10685
+ }
10686
+ return format;
10687
+ }
10688
+ }
10689
+
10670
10690
  /**
10671
10691
  * Base class for Time Picker component.
10672
10692
  */
@@ -10755,21 +10775,20 @@
10755
10775
  this.initialMask = this.getInitialMask();
10756
10776
  this.isSimpleDisplay = this.isSimpleFormat(this.displayFormat);
10757
10777
  }
10778
+ getFormat(format, timeFormat) {
10779
+ const timeFormatSelector = new TimeFormatSelector();
10780
+ const selectedFormat = timeFormatSelector.getFormat(format, timeFormat, this.useSeconds);
10781
+ return selectedFormat;
10782
+ }
10758
10783
  get displayFormat() {
10759
- const commonsDisplay = ['hh:mm A', 'hh:mm:ss A', 'HH:mm:ss', 'HH:mm'];
10760
- if (commonsDisplay.includes(this.displayFormatInternal)) {
10761
- this.displayFormatInternal = this.defaultFormats[this.timeFormat];
10762
- }
10784
+ this.displayFormatInternal = this.getFormat(this.displayFormatInternal, this.timeFormat);
10763
10785
  return this.displayFormatInternal;
10764
10786
  }
10765
10787
  set displayFormat(value) {
10766
10788
  this.displayFormatInternal = value;
10767
10789
  }
10768
10790
  get valueFormat() {
10769
- const commonsDisplay = ['hh:mm A', 'hh:mm:ss A', 'HH:mm:ss', 'HH:mm'];
10770
- if (commonsDisplay.includes(this.valueFormatInternal)) {
10771
- this.valueFormatInternal = this.defaultFormats['24hr'];
10772
- }
10791
+ this.valueFormatInternal = this.getFormat(this.valueFormatInternal, '24hr');
10773
10792
  return this.valueFormatInternal;
10774
10793
  }
10775
10794
  set valueFormat(value) {
@@ -10779,13 +10798,6 @@
10779
10798
  this.isoFormatValue = this.useSeconds ? 'HH:mm:ss' : 'HH:mm';
10780
10799
  return this.isoFormatValue;
10781
10800
  }
10782
- get defaultFormats() {
10783
- const seconds = this.useSeconds ? ':ss' : '';
10784
- return {
10785
- ampm: `hh:mm${seconds} A`,
10786
- '24hr': `HH:mm${seconds}`,
10787
- };
10788
- }
10789
10801
  getInitialMask() {
10790
10802
  if (isUndefined__default["default"](this.mask)) {
10791
10803
  this.mask = this.inputFormat && this.maskFormat(this.inputFormat);
@@ -10992,45 +11004,51 @@
10992
11004
  this.change(this.value);
10993
11005
  }
10994
11006
  }
10995
- core.FormatterParserProvider.registerFormatter('ZdTime', (value, { valueFormat = core.Config.valueTimeFormat, displayFormat = core.Config.displayTimeFormat, inputFormat = core.Config.timeInputFormat, mask = '', initialMask, isSimpleDisplay = false, } = {}) => {
11007
+ core.FormatterParserProvider.registerFormatter('ZdTime', (value, { valueFormat = core.Config.valueTimeFormat, displayFormat = core.Config.displayTimeFormat, inputFormat = core.Config.timeInputFormat, timeFormat = core.Config.timeFormat || 'ampm', useSeconds = false, mask = '', initialMask, isSimpleDisplay = false, } = {}) => {
10996
11008
  if (!value) {
10997
11009
  return '';
10998
11010
  }
10999
- const isTimeValid = core.dayjs(value, valueFormat, true).isValid();
11011
+ const timeFormatSelector = new TimeFormatSelector();
11012
+ const timeDisplayFormat = timeFormatSelector.getFormat(displayFormat, timeFormat, useSeconds);
11013
+ const timeValueFormat = timeFormatSelector.getFormat(valueFormat, '24hr', useSeconds);
11014
+ const isTimeValid = core.dayjs(value, timeValueFormat, true).isValid();
11000
11015
  if (!isTimeValid) {
11001
11016
  return value;
11002
11017
  }
11003
11018
  if (mask && initialMask) {
11004
11019
  if (inputFormat) {
11005
- return core.dayjs(value, valueFormat).format(inputFormat);
11020
+ return core.dayjs(value, timeValueFormat).format(inputFormat);
11006
11021
  }
11007
11022
  let valueToUnmask = value;
11008
11023
  if (isSimpleDisplay) {
11009
- valueToUnmask = core.dayjs(value, valueFormat).format(displayFormat);
11024
+ valueToUnmask = core.dayjs(value, timeValueFormat).format(timeDisplayFormat);
11010
11025
  }
11011
11026
  const unmasked = core.Mask.getValueWithoutMask(valueToUnmask);
11012
11027
  const masked = core.Mask.getValueWithMask(unmasked, mask);
11013
11028
  return masked;
11014
11029
  }
11015
- return core.dayjs(value, valueFormat).format(displayFormat);
11030
+ return core.dayjs(value, timeValueFormat).format(timeDisplayFormat);
11016
11031
  });
11017
- core.FormatterParserProvider.registerParser('ZdTime', (value, { displayFormat = core.Config.displayTimeFormat, valueFormat = core.Config.valueTimeFormat, mask = '', initialMask, } = {}) => {
11032
+ core.FormatterParserProvider.registerParser('ZdTime', (value, { displayFormat = core.Config.displayTimeFormat, valueFormat = core.Config.valueTimeFormat, timeFormat = core.Config.timeFormat || 'ampm', useSeconds = false, mask = '', initialMask, } = {}) => {
11018
11033
  if (!value) {
11019
11034
  return null;
11020
11035
  }
11021
- if (core.dayjs(value, displayFormat, true).isValid()) {
11022
- return core.dayjs(value, displayFormat).format(valueFormat);
11036
+ const timeFormatSelector = new TimeFormatSelector();
11037
+ const timeDisplayFormat = timeFormatSelector.getFormat(displayFormat, timeFormat, useSeconds);
11038
+ const timeValueFormat = timeFormatSelector.getFormat(valueFormat, '24hr', useSeconds);
11039
+ if (core.dayjs(value, timeDisplayFormat, true).isValid()) {
11040
+ return core.dayjs(value, timeDisplayFormat).format(timeValueFormat);
11023
11041
  }
11024
11042
  if (mask && core.Mask.checkMask(value, mask)) {
11025
11043
  const unmasked = core.Mask.getValueWithoutMask(value);
11026
11044
  let masked;
11027
11045
  if (!initialMask) {
11028
- const displayFmtMask = displayFormat.replace(/[A-Za-z]/gi, '#');
11046
+ const displayFmtMask = timeDisplayFormat.replace(/[A-Za-z]/gi, '#');
11029
11047
  masked = core.Mask.getValueWithMask(unmasked, displayFmtMask);
11030
11048
  }
11031
- const timeFmtMask = valueFormat.replace(/[A-Za-z]/gi, '#');
11049
+ const timeFmtMask = timeValueFormat.replace(/[A-Za-z]/gi, '#');
11032
11050
  masked = core.Mask.getValueWithMask(unmasked, timeFmtMask);
11033
- if (core.dayjs(masked, valueFormat, true).format(valueFormat) === masked) {
11051
+ if (core.dayjs(masked, timeValueFormat, true).format(timeValueFormat) === masked) {
11034
11052
  return masked;
11035
11053
  }
11036
11054
  }
@@ -11557,6 +11575,7 @@
11557
11575
  this.parentField = this.getInitValue('parentField', props.parentField, this.parentField);
11558
11576
  this.fetchOnDemand = this.getInitValue('fetchOnDemand', props.fetchOnDemand, this.fetchOnDemand);
11559
11577
  this.flat = this.getInitValue('flat', props.flat, this.flat);
11578
+ this.fieldHasChild = this.getInitValue('fieldHasChild', props.fieldHasChild, this.fieldHasChild);
11560
11579
  this.detach = this.getInitValue('detach', props.detach, this.detach);
11561
11580
  this.treeDataStructure = new TreeDataStructure(this);
11562
11581
  this.createAccessors();
@@ -11675,7 +11694,9 @@
11675
11694
  * @param isSelected row is selected
11676
11695
  */
11677
11696
  selectRow(row, isSelected) {
11678
- const childrenRows = !this.flat ? this.treeDataStructure.getChildren(row) : [];
11697
+ const childrenRows = !this.flat
11698
+ ? this.treeDataStructure.getChildren(row)
11699
+ : [];
11679
11700
  const rows = [row, ...childrenRows];
11680
11701
  if (isSelected) {
11681
11702
  this.selectedRows = this.removeDuplicates(this.selectedRows.concat(rows), this.datasource.uniqueKey);
@@ -11718,7 +11739,9 @@
11718
11739
  selectParents(row) {
11719
11740
  if (row[this.parentField]) {
11720
11741
  const parentRow = this.treeDataStructure.getRowData(row).tree__parent;
11721
- const every = this.treeDataStructure.getChildren(parentRow).every((item) => {
11742
+ const every = this.treeDataStructure
11743
+ .getChildren(parentRow)
11744
+ .every((item) => {
11722
11745
  const index = this.treeDataStructure.findDataIndex(this.selectedRows, item[this.datasource.uniqueKey]);
11723
11746
  if (index > -1)
11724
11747
  return true;
@@ -13440,7 +13463,6 @@
13440
13463
  exports.IterablePageInfo = IterablePageInfo;
13441
13464
  exports.IterablePageSize = IterablePageSize;
13442
13465
  exports.IterablePagination = IterablePagination;
13443
- exports.JsonCacheService = JsonCacheService;
13444
13466
  exports.List = List;
13445
13467
  exports.ListGroup = ListGroup;
13446
13468
  exports.ListItem = ListItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/common",
3
- "version": "1.69.0",
3
+ "version": "1.71.0",
4
4
  "description": "Zeedhi Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -39,5 +39,5 @@
39
39
  "lodash.times": "^4.3.2",
40
40
  "mockdate": "^3.0.2"
41
41
  },
42
- "gitHead": "68d387623e59f31de6b04926cb0d476f2e1715a0"
42
+ "gitHead": "6e0e1cef3955cae7029ad947eb8c83fe589621b7"
43
43
  }
@@ -13,6 +13,7 @@ export interface ISelectTreeMultiple extends ISelectTree {
13
13
  limit?: number;
14
14
  events?: ISelectTreeMultipleEvents;
15
15
  valueConsistsOf?: string;
16
+ showSelectAll?: boolean;
16
17
  }
17
18
  export interface ISelectTreeMultipleSelectedNodesEvent extends IEventParam<SelectTreeMultiple> {
18
19
  selectedNodes: ISelectTreeMultipleNode<IDictionary>[];
@@ -23,4 +24,6 @@ export interface ISelectTreeMultipleDeselectEvent extends IEventParam<SelectTree
23
24
  export interface ISelectTreeMultipleEvents extends ISelectTreeEvents {
24
25
  onChangeSelectedNodes?: IEvent<ISelectTreeMultipleSelectedNodesEvent> | string;
25
26
  onDeselect?: IEvent<ISelectTreeMultipleDeselectEvent> | string;
27
+ selectedAll?: IEvent<IEventParam<any>> | string;
28
+ unselectedAll?: IEvent<IEventParam<any>> | string;
26
29
  }
@@ -26,6 +26,10 @@ export declare class SelectTreeMultiple extends SelectTree implements ISelectTre
26
26
  * Changes the behavior of checked nodes that will be displayed in the array of values
27
27
  */
28
28
  valueConsistsOf: string;
29
+ /**
30
+ * Show the selectAll option
31
+ */
32
+ showSelectAll: boolean;
29
33
  /**
30
34
  * Creates a new instance of Select Tree Multiple
31
35
  * @param props
@@ -42,4 +46,11 @@ export declare class SelectTreeMultiple extends SelectTree implements ISelectTre
42
46
  get value(): any;
43
47
  set value(value: any);
44
48
  setValue(value: any): void;
49
+ getAllNodes(nodes?: import("..").ISelectTreeNode<IDictionary<any>>[]): import("..").ISelectTreeNode<IDictionary<any>>[];
50
+ /**
51
+ * Dispatches select/unselect event
52
+ */
53
+ onSelectAll(isSelected: boolean, event: Event, element: any): void;
54
+ selectAllItems(): void;
55
+ unSelectAllItems(): void;
45
56
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Selects the time format by the rule:
3
+ * non-common format > common format
4
+ * and if the format is a common format, it will be overriden by timeFormat
5
+ */
6
+ export declare class TimeFormatSelector {
7
+ getFormat(format: string, timeFormat: string, useSeconds: boolean): any;
8
+ }
@@ -1,4 +1,3 @@
1
- import { IDictionary } from '@zeedhi/core';
2
1
  import { ITime } from './interfaces';
3
2
  import { TextInput } from '../zd-text-input/text-input';
4
3
  /**
@@ -78,12 +77,12 @@ export declare class Time extends TextInput implements ITime {
78
77
  * @param props Time properties
79
78
  */
80
79
  constructor(props: ITime);
80
+ private getFormat;
81
81
  get displayFormat(): string;
82
82
  set displayFormat(value: string);
83
83
  get valueFormat(): string;
84
84
  set valueFormat(value: string);
85
85
  private get isoFormat();
86
- protected get defaultFormats(): IDictionary<string>;
87
86
  private getInitialMask;
88
87
  formatter(value: string): string;
89
88
  parser(value: string): any;
@@ -5,6 +5,7 @@ export interface ITreeGrid extends IGrid {
5
5
  parentField?: string;
6
6
  openLevelOnLoad?: number | boolean;
7
7
  fetchOnDemand?: boolean;
8
+ fieldHasChild?: string;
8
9
  flat?: boolean;
9
10
  detach?: boolean;
10
11
  }
@@ -19,6 +19,10 @@ export declare class TreeGrid extends Grid implements ITreeGrid {
19
19
  * Defines if the tree will be fetch data only when opening a level
20
20
  */
21
21
  fetchOnDemand: boolean;
22
+ /**
23
+ * Defines if the node tree has child
24
+ */
25
+ fieldHasChild?: string;
22
26
  /**
23
27
  * Defines if should wait and not execute GET method when Datasource is created
24
28
  */
@@ -2,4 +2,3 @@ export * from './zd-alert/alert-service';
2
2
  export * from './zd-dialog/dialog-service';
3
3
  export * from './zd-modal/modal-service';
4
4
  export * from './zd-loading/loading-service';
5
- export * from './zd-json-cache/json-cache-service';
@@ -16,7 +16,7 @@ export declare class ModalService {
16
16
  * Creates a new modal instance from JSON
17
17
  * @param modal modal structure
18
18
  */
19
- static createFromJson(modalPath: string, local?: boolean): Promise<Modal>;
19
+ static createFromJson(modalPath: string, local?: boolean, JSONCache?: boolean): Promise<Modal>;
20
20
  /**
21
21
  * Creates a new modal instance from JSON
22
22
  * @param modal modal structure