@zeedhi/common 1.58.0 → 1.59.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.
@@ -1,8 +1,9 @@
1
- import { AccessorManager, Event, KeyMap, Metadata, FormatterParserProvider, Validation, Mask, Accessor, DatasourceFactory, I18n, MethodNotAssignedError, Loader, Config, dayjs, DateHelper, Utils, Router, InstanceNotFoundError, Http, Cookie, URL as URL$1, VersionService } from '@zeedhi/core';
1
+ import { AccessorManager, Event, KeyMap, Metadata, FormatterParserProvider, Validation, Mask, Accessor, DatasourceFactory, I18n, MethodNotAssignedError, Loader, Config, dayjs, DateHelper, Utils, Router, InstanceNotFoundError, Cookie, Http, URL as URL$1, VersionService } from '@zeedhi/core';
2
2
  import merge from 'lodash.merge';
3
3
  import debounce from 'lodash.debounce';
4
4
  import isUndefined from 'lodash.isundefined';
5
5
  import set from 'lodash.set';
6
+ import get from 'lodash.get';
6
7
 
7
8
  /**
8
9
  * Child not found error
@@ -1474,6 +1475,14 @@ class Form extends ComponentRender {
1474
1475
  }
1475
1476
  });
1476
1477
  }
1478
+ /**
1479
+ * Clear all form inputs
1480
+ */
1481
+ clearForm() {
1482
+ Object.keys(this.value).forEach((item) => {
1483
+ this.value[item] = null;
1484
+ });
1485
+ }
1477
1486
  /**
1478
1487
  * Saves input instance and defines property on form value.
1479
1488
  * @param component Children component
@@ -7167,6 +7176,119 @@ class Search extends TextInput {
7167
7176
  }
7168
7177
  }
7169
7178
 
7179
+ /**
7180
+ * Base class for IterableComponentRender component.
7181
+ * This component uses every row returned by Iterable.datasource to render
7182
+ * components defined by componentMetadata property.
7183
+ * If the data inside the datasource is changed you should perform
7184
+ * a datasource.get() to force updating the rendered components.
7185
+ */
7186
+ class IterableComponentRender extends Iterable {
7187
+ constructor(props) {
7188
+ super(props);
7189
+ /**
7190
+ * Components that will be rendered on toolbar slot
7191
+ */
7192
+ this.toolbarSlot = [];
7193
+ /**
7194
+ * Components that will be rendered on footer slot
7195
+ */
7196
+ this.footerSlot = [];
7197
+ /**
7198
+ * Row property name
7199
+ */
7200
+ this.rowPropName = 'row';
7201
+ /**
7202
+ * Components that will be rendered in no-data case
7203
+ */
7204
+ this.noDataSlot = [
7205
+ {
7206
+ name: '<<NAME>>_no-data',
7207
+ component: 'ZdText',
7208
+ cssClass: 'no-data',
7209
+ text: 'NO_DATA',
7210
+ },
7211
+ ];
7212
+ /**
7213
+ * Components that will be rendered in no-result case
7214
+ */
7215
+ this.noResultSlot = [
7216
+ {
7217
+ name: '<<NAME>>_no-result',
7218
+ component: 'ZdText',
7219
+ cssClass: 'no-result',
7220
+ text: 'NO_RESULT',
7221
+ },
7222
+ ];
7223
+ /**
7224
+ * Sets the height for the component.
7225
+ */
7226
+ this.height = 'auto';
7227
+ /**
7228
+ * Sets the maximum height for the component.
7229
+ */
7230
+ this.maxHeight = 'none';
7231
+ /**
7232
+ * Sets the minimum height for the component.
7233
+ */
7234
+ this.minHeight = 'none';
7235
+ /**
7236
+ * Components that will be rendered in error case
7237
+ */
7238
+ this.errorSlot = [];
7239
+ this.toolbarSlot = props.toolbarSlot || this.toolbarSlot;
7240
+ this.footerSlot = props.footerSlot || this.footerSlot;
7241
+ this.componentMetadata = this.getInitValue('componentMetadata', props.componentMetadata, this.componentMetadata);
7242
+ this.rowPropName = this.getInitValue('rowPropName', props.rowPropName, this.rowPropName);
7243
+ this.noDataSlot = props.noDataSlot || this.noDataSlot;
7244
+ this.noResultSlot = props.noResultSlot || this.noResultSlot;
7245
+ this.errorSlot = props.errorSlot || this.errorSlot;
7246
+ this.noDataSlot = this.changeDefaultSlotNames(this.noDataSlot);
7247
+ this.noResultSlot = this.changeDefaultSlotNames(this.noResultSlot);
7248
+ this.height = this.getInitValue('height', props.height, this.height);
7249
+ this.maxHeight = this.getInitValue('maxHeight', props.maxHeight, this.maxHeight);
7250
+ this.minHeight = this.getInitValue('minHeight', props.minHeight, this.minHeight);
7251
+ this.createAccessors();
7252
+ }
7253
+ addSlashes(value) {
7254
+ if (typeof value === 'string') {
7255
+ return value.replace(/\\/g, '\\\\')
7256
+ .replace(/\t/g, '\\t')
7257
+ .replace(/\n/g, '\\n')
7258
+ .replace(/\f/g, '\\f')
7259
+ .replace(/\r/g, '\\r')
7260
+ .replace(/"/g, '\\"');
7261
+ }
7262
+ return value;
7263
+ }
7264
+ /**
7265
+ * Returns the iterable component metadata based on row data
7266
+ */
7267
+ getComponentMetadata(row) {
7268
+ const exp = new RegExp(`<<${this.rowPropName}.(.[A-z]+?)>>|"<<${this.rowPropName}.(.[A-z]+?)>>"`, 'g');
7269
+ const rowExp = new RegExp(`"<<${this.rowPropName}>>"`, 'g');
7270
+ const metadata = JSON.stringify(this.componentMetadata)
7271
+ .replace(rowExp, JSON.stringify(row))
7272
+ .replace(exp, (match) => {
7273
+ const propPath = match.replace(/<<|>>|"/g, '').split('.').splice(1).join('.');
7274
+ const value = this.addSlashes(get(row, propPath));
7275
+ if (typeof value === 'string') {
7276
+ if (match.startsWith('"') && match.endsWith('"'))
7277
+ return `"${value}"`;
7278
+ return value;
7279
+ }
7280
+ return value;
7281
+ });
7282
+ return JSON.parse(metadata);
7283
+ }
7284
+ changeDefaultSlotNames(slot) {
7285
+ slot.forEach((item) => {
7286
+ item.name = item.name.replace('<<NAME>>', this.name);
7287
+ });
7288
+ return slot;
7289
+ }
7290
+ }
7291
+
7170
7292
  /**
7171
7293
  * Item not found error
7172
7294
  */
@@ -8950,7 +9072,17 @@ class SelectMultiple extends Select {
8950
9072
  }
8951
9073
  unSelectAllItems() {
8952
9074
  return __awaiter(this, void 0, void 0, function* () {
8953
- yield this.setValue([]);
9075
+ if (!this.datasource.search) {
9076
+ this.removeInserts();
9077
+ this.insertSelected();
9078
+ yield this.setValue([]);
9079
+ }
9080
+ else {
9081
+ const newData = this.insertedValues;
9082
+ yield this.setValue(newData);
9083
+ this.removeInserts();
9084
+ this.insertSelected();
9085
+ }
8954
9086
  });
8955
9087
  }
8956
9088
  checkValueOnBlur() { }
@@ -13050,4 +13182,4 @@ const AutoNumeric = require('@zeedhi/autonumeric/dist/autoNumeric');
13050
13182
  const packageContent = require('../package.json');
13051
13183
  VersionService.addPackageVersion(packageContent.name, packageContent.version);
13052
13184
 
13053
- 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, 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 };
13185
+ 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 };
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@zeedhi/core'), require('lodash.merge'), require('lodash.debounce'), require('lodash.isundefined'), require('lodash.set')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@zeedhi/core', 'lodash.merge', 'lodash.debounce', 'lodash.isundefined', 'lodash.set'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@zeedhi/common"] = {}, global.core, global.merge, global.debounce, global.isUndefined, global.set));
5
- })(this, (function (exports, core, merge, debounce, isUndefined, set) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@zeedhi/core'), require('lodash.merge'), require('lodash.debounce'), require('lodash.isundefined'), require('lodash.set'), require('lodash.get')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@zeedhi/core', 'lodash.merge', 'lodash.debounce', 'lodash.isundefined', 'lodash.set', 'lodash.get'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@zeedhi/common"] = {}, global.core, global.merge, global.debounce, global.isUndefined, global.set, global.get));
5
+ })(this, (function (exports, core, merge, debounce, isUndefined, set, get) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -10,6 +10,7 @@
10
10
  var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
11
11
  var isUndefined__default = /*#__PURE__*/_interopDefaultLegacy(isUndefined);
12
12
  var set__default = /*#__PURE__*/_interopDefaultLegacy(set);
13
+ var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
13
14
 
14
15
  /**
15
16
  * Child not found error
@@ -1481,6 +1482,14 @@
1481
1482
  }
1482
1483
  });
1483
1484
  }
1485
+ /**
1486
+ * Clear all form inputs
1487
+ */
1488
+ clearForm() {
1489
+ Object.keys(this.value).forEach((item) => {
1490
+ this.value[item] = null;
1491
+ });
1492
+ }
1484
1493
  /**
1485
1494
  * Saves input instance and defines property on form value.
1486
1495
  * @param component Children component
@@ -7174,6 +7183,119 @@
7174
7183
  }
7175
7184
  }
7176
7185
 
7186
+ /**
7187
+ * Base class for IterableComponentRender component.
7188
+ * This component uses every row returned by Iterable.datasource to render
7189
+ * components defined by componentMetadata property.
7190
+ * If the data inside the datasource is changed you should perform
7191
+ * a datasource.get() to force updating the rendered components.
7192
+ */
7193
+ class IterableComponentRender extends Iterable {
7194
+ constructor(props) {
7195
+ super(props);
7196
+ /**
7197
+ * Components that will be rendered on toolbar slot
7198
+ */
7199
+ this.toolbarSlot = [];
7200
+ /**
7201
+ * Components that will be rendered on footer slot
7202
+ */
7203
+ this.footerSlot = [];
7204
+ /**
7205
+ * Row property name
7206
+ */
7207
+ this.rowPropName = 'row';
7208
+ /**
7209
+ * Components that will be rendered in no-data case
7210
+ */
7211
+ this.noDataSlot = [
7212
+ {
7213
+ name: '<<NAME>>_no-data',
7214
+ component: 'ZdText',
7215
+ cssClass: 'no-data',
7216
+ text: 'NO_DATA',
7217
+ },
7218
+ ];
7219
+ /**
7220
+ * Components that will be rendered in no-result case
7221
+ */
7222
+ this.noResultSlot = [
7223
+ {
7224
+ name: '<<NAME>>_no-result',
7225
+ component: 'ZdText',
7226
+ cssClass: 'no-result',
7227
+ text: 'NO_RESULT',
7228
+ },
7229
+ ];
7230
+ /**
7231
+ * Sets the height for the component.
7232
+ */
7233
+ this.height = 'auto';
7234
+ /**
7235
+ * Sets the maximum height for the component.
7236
+ */
7237
+ this.maxHeight = 'none';
7238
+ /**
7239
+ * Sets the minimum height for the component.
7240
+ */
7241
+ this.minHeight = 'none';
7242
+ /**
7243
+ * Components that will be rendered in error case
7244
+ */
7245
+ this.errorSlot = [];
7246
+ this.toolbarSlot = props.toolbarSlot || this.toolbarSlot;
7247
+ this.footerSlot = props.footerSlot || this.footerSlot;
7248
+ this.componentMetadata = this.getInitValue('componentMetadata', props.componentMetadata, this.componentMetadata);
7249
+ this.rowPropName = this.getInitValue('rowPropName', props.rowPropName, this.rowPropName);
7250
+ this.noDataSlot = props.noDataSlot || this.noDataSlot;
7251
+ this.noResultSlot = props.noResultSlot || this.noResultSlot;
7252
+ this.errorSlot = props.errorSlot || this.errorSlot;
7253
+ this.noDataSlot = this.changeDefaultSlotNames(this.noDataSlot);
7254
+ this.noResultSlot = this.changeDefaultSlotNames(this.noResultSlot);
7255
+ this.height = this.getInitValue('height', props.height, this.height);
7256
+ this.maxHeight = this.getInitValue('maxHeight', props.maxHeight, this.maxHeight);
7257
+ this.minHeight = this.getInitValue('minHeight', props.minHeight, this.minHeight);
7258
+ this.createAccessors();
7259
+ }
7260
+ addSlashes(value) {
7261
+ if (typeof value === 'string') {
7262
+ return value.replace(/\\/g, '\\\\')
7263
+ .replace(/\t/g, '\\t')
7264
+ .replace(/\n/g, '\\n')
7265
+ .replace(/\f/g, '\\f')
7266
+ .replace(/\r/g, '\\r')
7267
+ .replace(/"/g, '\\"');
7268
+ }
7269
+ return value;
7270
+ }
7271
+ /**
7272
+ * Returns the iterable component metadata based on row data
7273
+ */
7274
+ getComponentMetadata(row) {
7275
+ const exp = new RegExp(`<<${this.rowPropName}.(.[A-z]+?)>>|"<<${this.rowPropName}.(.[A-z]+?)>>"`, 'g');
7276
+ const rowExp = new RegExp(`"<<${this.rowPropName}>>"`, 'g');
7277
+ const metadata = JSON.stringify(this.componentMetadata)
7278
+ .replace(rowExp, JSON.stringify(row))
7279
+ .replace(exp, (match) => {
7280
+ const propPath = match.replace(/<<|>>|"/g, '').split('.').splice(1).join('.');
7281
+ const value = this.addSlashes(get__default["default"](row, propPath));
7282
+ if (typeof value === 'string') {
7283
+ if (match.startsWith('"') && match.endsWith('"'))
7284
+ return `"${value}"`;
7285
+ return value;
7286
+ }
7287
+ return value;
7288
+ });
7289
+ return JSON.parse(metadata);
7290
+ }
7291
+ changeDefaultSlotNames(slot) {
7292
+ slot.forEach((item) => {
7293
+ item.name = item.name.replace('<<NAME>>', this.name);
7294
+ });
7295
+ return slot;
7296
+ }
7297
+ }
7298
+
7177
7299
  /**
7178
7300
  * Item not found error
7179
7301
  */
@@ -8957,7 +9079,17 @@
8957
9079
  }
8958
9080
  unSelectAllItems() {
8959
9081
  return __awaiter(this, void 0, void 0, function* () {
8960
- yield this.setValue([]);
9082
+ if (!this.datasource.search) {
9083
+ this.removeInserts();
9084
+ this.insertSelected();
9085
+ yield this.setValue([]);
9086
+ }
9087
+ else {
9088
+ const newData = this.insertedValues;
9089
+ yield this.setValue(newData);
9090
+ this.removeInserts();
9091
+ this.insertSelected();
9092
+ }
8961
9093
  });
8962
9094
  }
8963
9095
  checkValueOnBlur() { }
@@ -13106,6 +13238,7 @@
13106
13238
  exports.Iterable = Iterable;
13107
13239
  exports.IterableColumnsButton = IterableColumnsButton;
13108
13240
  exports.IterableColumnsButtonController = IterableColumnsButtonController;
13241
+ exports.IterableComponentRender = IterableComponentRender;
13109
13242
  exports.IterablePageComponent = IterablePageComponent;
13110
13243
  exports.IterablePageInfo = IterablePageInfo;
13111
13244
  exports.IterablePageSize = IterablePageSize;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/common",
3
- "version": "1.58.0",
3
+ "version": "1.59.0",
4
4
  "description": "Zeedhi Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -21,6 +21,7 @@
21
21
  "dependencies": {
22
22
  "@zeedhi/autonumeric": "^4.6.0",
23
23
  "lodash.debounce": "^4.0.8",
24
+ "lodash.get": "^4.4.2",
24
25
  "lodash.isundefined": "^3.0.1",
25
26
  "lodash.merge": "^4.6.2",
26
27
  "lodash.set": "^4.3.2"
@@ -30,6 +31,7 @@
30
31
  },
31
32
  "devDependencies": {
32
33
  "@types/lodash.debounce": "^4.0.6",
34
+ "@types/lodash.get": "^4.4.6",
33
35
  "@types/lodash.isundefined": "^3.0.6",
34
36
  "@types/lodash.merge": "^4.6.6",
35
37
  "@types/lodash.set": "^4.3.6",
@@ -37,5 +39,5 @@
37
39
  "lodash.times": "^4.3.2",
38
40
  "mockdate": "^3.0.2"
39
41
  },
40
- "gitHead": "8d8d49f8a582b003f4c86d0c7849e839f88f1c13"
42
+ "gitHead": "1994ad253bafc3190adf1dd0db028b2825a2f16e"
41
43
  }
@@ -81,6 +81,8 @@ export * from './zd-iterable/iterable-page-info';
81
81
  export * from './zd-iterable/iterable-pagination';
82
82
  export * from './zd-iterable/search';
83
83
  export * from './zd-iterable/interfaces';
84
+ export * from './zd-iterable-component-render/iterable-component-render';
85
+ export * from './zd-iterable-component-render/interfaces';
84
86
  export * from './zd-list/list';
85
87
  export * from './zd-list/list-item';
86
88
  export * from './zd-list/list-group';
@@ -55,6 +55,10 @@ export declare class Form extends ComponentRender implements IForm {
55
55
  */
56
56
  get value(): IDictionary;
57
57
  set value(value: IDictionary);
58
+ /**
59
+ * Clear all form inputs
60
+ */
61
+ clearForm(): void;
58
62
  /**
59
63
  * Saves input instance and defines property on form value.
60
64
  * @param component Children component
@@ -0,0 +1,14 @@
1
+ import { IComponentRender } from '../zd-component/interfaces';
2
+ import { IIterable } from '../zd-iterable/interfaces';
3
+ export interface IIterableComponentRender extends IIterable {
4
+ rowPropName?: string;
5
+ componentMetadata?: IComponentRender;
6
+ footerSlot?: IComponentRender[];
7
+ toolbarSlot?: IComponentRender[];
8
+ errorSlot?: IComponentRender[];
9
+ noDataSlot?: IComponentRender[];
10
+ noResultSlot?: IComponentRender[];
11
+ height?: number | string;
12
+ maxHeight?: number | string;
13
+ minHeight?: number | string;
14
+ }
@@ -0,0 +1,60 @@
1
+ import { IDictionary } from '@zeedhi/core';
2
+ import { IComponentRender } from '../zd-component/interfaces';
3
+ import { IIterableComponentRender } from './interfaces';
4
+ import { Iterable } from '../zd-iterable/iterable';
5
+ /**
6
+ * Base class for IterableComponentRender component.
7
+ * This component uses every row returned by Iterable.datasource to render
8
+ * components defined by componentMetadata property.
9
+ * If the data inside the datasource is changed you should perform
10
+ * a datasource.get() to force updating the rendered components.
11
+ */
12
+ export declare class IterableComponentRender extends Iterable implements IIterableComponentRender {
13
+ /**
14
+ * Components that will be rendered on toolbar slot
15
+ */
16
+ toolbarSlot: IComponentRender[];
17
+ /**
18
+ * Components that will be rendered on footer slot
19
+ */
20
+ footerSlot: IComponentRender[];
21
+ /**
22
+ * Component item definition
23
+ */
24
+ componentMetadata: IComponentRender;
25
+ /**
26
+ * Row property name
27
+ */
28
+ rowPropName: string;
29
+ /**
30
+ * Components that will be rendered in no-data case
31
+ */
32
+ noDataSlot: IComponentRender[];
33
+ /**
34
+ * Components that will be rendered in no-result case
35
+ */
36
+ noResultSlot: IComponentRender[];
37
+ /**
38
+ * Sets the height for the component.
39
+ */
40
+ height: number | string;
41
+ /**
42
+ * Sets the maximum height for the component.
43
+ */
44
+ maxHeight: number | string;
45
+ /**
46
+ * Sets the minimum height for the component.
47
+ */
48
+ minHeight: number | string;
49
+ /**
50
+ * Components that will be rendered in error case
51
+ */
52
+ errorSlot: IComponentRender[];
53
+ constructor(props: IIterableComponentRender);
54
+ private addSlashes;
55
+ /**
56
+ * Returns the iterable component metadata based on row data
57
+ */
58
+ getComponentMetadata(row: IDictionary<any>): any;
59
+ private changeDefaultSlotNames;
60
+ }