@michalrakus/x-react-web-lib 1.36.1 → 1.37.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.
@@ -0,0 +1,3 @@
1
+ // generated by gulp
2
+
3
+ export * from './lib/components/XCheckboxBase';
@@ -0,0 +1,5 @@
1
+ // generated by gulp
2
+
3
+ 'use strict';
4
+
5
+ module.exports = require('./lib/components/XCheckboxBase.js');
package/gulpfile.js CHANGED
@@ -43,6 +43,7 @@ function generateApi(cb) {
43
43
  "./lib/components/XCalendar",
44
44
  "./lib/components/XChangePasswordForm",
45
45
  "./lib/components/XCheckbox",
46
+ "./lib/components/XCheckboxBase",
46
47
  "./lib/components/XDropdown",
47
48
  "./lib/components/XDropdownForEntity",
48
49
  "./lib/components/XEditBrowse",
@@ -1,6 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { XInput, XInputProps } from "./XInput";
3
- import { CheckboxChangeEvent } from "primereact/checkbox";
4
3
  export interface XCheckboxProps extends XInputProps<boolean> {
5
4
  isNotNull?: boolean;
6
5
  }
@@ -8,7 +7,6 @@ export declare class XCheckbox extends XInput<boolean, XCheckboxProps> {
8
7
  constructor(props: XCheckboxProps);
9
8
  isNotNull(): boolean;
10
9
  getValue(): boolean | null;
11
- checkboxOnValueChange(e: CheckboxChangeEvent): void;
12
- triStateCheckboxOnValueChange(e: any): void;
10
+ onValueChange(value: boolean | null): void;
13
11
  render(): JSX.Element;
14
12
  }
@@ -20,47 +20,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.XCheckbox = void 0;
22
22
  var react_1 = __importDefault(require("react"));
23
- var tristatecheckbox_1 = require("primereact/tristatecheckbox");
24
23
  var XInput_1 = require("./XInput");
25
- var checkbox_1 = require("primereact/checkbox");
24
+ var XCheckboxBase_1 = require("./XCheckboxBase");
26
25
  var XCheckbox = /** @class */ (function (_super) {
27
26
  __extends(XCheckbox, _super);
28
27
  function XCheckbox(props) {
29
28
  var _this = _super.call(this, props) || this;
30
- _this.checkboxOnValueChange = _this.checkboxOnValueChange.bind(_this);
31
- _this.triStateCheckboxOnValueChange = _this.triStateCheckboxOnValueChange.bind(_this);
29
+ _this.onValueChange = _this.onValueChange.bind(_this);
32
30
  return _this;
33
31
  }
34
32
  XCheckbox.prototype.isNotNull = function () {
35
33
  return this.props.isNotNull || _super.prototype.isNotNull.call(this);
36
34
  };
37
35
  XCheckbox.prototype.getValue = function () {
38
- // konvertovat null hodnotu na "" (vo funkcii stringAsUI) je dolezite aby sa prejavila zmena na null v modeli
39
- var value = this.getValueFromObject();
40
- return value;
36
+ return this.getValueFromObject();
41
37
  };
42
- XCheckbox.prototype.checkboxOnValueChange = function (e) {
43
- this.onValueChangeBase(e.checked, this.props.onChange);
44
- };
45
- XCheckbox.prototype.triStateCheckboxOnValueChange = function (e) {
46
- var newValue = e.value;
47
- // pri klikani na TriStateCheckbox prichadza v newValue cyklicky: true -> false -> null
48
- // ak mame not null atribut, tak pri null hodnote skocime rovno na true
49
- if (this.isNotNull()) {
50
- if (newValue === null) {
51
- newValue = true;
52
- }
53
- }
54
- // zmenime hodnotu v modeli (odtial sa hodnota cita)
55
- this.onValueChangeBase(newValue, this.props.onChange);
38
+ XCheckbox.prototype.onValueChange = function (value) {
39
+ this.onValueChangeBase(value, this.props.onChange);
56
40
  };
57
41
  XCheckbox.prototype.render = function () {
58
- var _a;
59
- // note: style overrides size (width of the input according to character count)
60
- // pre not null atributy pouzijeme standardny checkbox aby sme pre false mali prazdny biely checkbox - TODO - pomenit ikonky na TriStateCheckbox aby to pekne sedelo
61
- var element = this.isNotNull()
62
- ? react_1.default.createElement(checkbox_1.Checkbox, { id: this.props.field, checked: (_a = this.getValue()) !== null && _a !== void 0 ? _a : false, onChange: this.checkboxOnValueChange, disabled: this.isReadOnly(), style: this.props.inputStyle, tooltip: this.props.tooltip })
63
- : react_1.default.createElement(tristatecheckbox_1.TriStateCheckbox, { id: this.props.field, value: this.getValue(), onChange: this.triStateCheckboxOnValueChange, disabled: this.isReadOnly(), style: this.props.inputStyle, tooltip: this.props.tooltip });
42
+ var element = react_1.default.createElement(XCheckboxBase_1.XCheckboxBase, { id: this.props.field, value: this.getValue(), onChange: this.onValueChange, readOnly: this.isReadOnly(), isNotNull: this.isNotNull(), tooltip: this.props.tooltip, error: this.getError(), style: this.props.inputStyle });
64
43
  if (!this.props.onlyInput) {
65
44
  var label = this.props.label; // nepridavame * ani ak je atribut not null (kedze sa pouziva jednoduchy checkbox, nie je mozne zadat null hodnotu)
66
45
  element = react_1.default.createElement("div", { className: "field grid" },
@@ -0,0 +1,11 @@
1
+ import React, { CSSProperties } from "react";
2
+ export declare const XCheckboxBase: (props: {
3
+ id?: string | undefined;
4
+ value: boolean | null;
5
+ onChange: (value: boolean | null) => void;
6
+ readOnly?: boolean | undefined;
7
+ isNotNull?: boolean | undefined;
8
+ tooltip?: string | undefined;
9
+ error?: string | undefined;
10
+ style?: CSSProperties | undefined;
11
+ }) => React.JSX.Element;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.XCheckboxBase = void 0;
18
+ var react_1 = __importDefault(require("react"));
19
+ var tristatecheckbox_1 = require("primereact/tristatecheckbox");
20
+ var checkbox_1 = require("primereact/checkbox");
21
+ var XUtils_1 = require("./XUtils");
22
+ var XCheckboxBase = function (props) {
23
+ var _a;
24
+ var checkboxOnChange = function (e) {
25
+ var _a;
26
+ props.onChange((_a = e.checked) !== null && _a !== void 0 ? _a : false);
27
+ };
28
+ var triStateCheckboxChange = function (e) {
29
+ var _a;
30
+ // for blank value comes empty string "" (bug in primereact?)
31
+ var newValue = null;
32
+ if (typeof e.value !== 'string') {
33
+ newValue = (_a = e.value) !== null && _a !== void 0 ? _a : null;
34
+ }
35
+ // pri klikani na TriStateCheckbox prichadza v newValue cyklicky: true -> false -> null
36
+ // ak mame not null atribut, tak pri null hodnote skocime rovno na true
37
+ // TODO - pouzijeme, ked zrusime Checkbox a nechame len TriStateCheckbox
38
+ // if (props.isNotNull) {
39
+ // if (newValue === null) {
40
+ // newValue = true;
41
+ // }
42
+ // }
43
+ props.onChange(newValue);
44
+ };
45
+ return (
46
+ // pre not null atributy pouzijeme standardny checkbox aby sme pre false mali prazdny biely checkbox
47
+ // TODO - pomenit ikonky na TriStateCheckbox aby to pekne sedelo, potom mozme zrusit Checkbox
48
+ props.isNotNull ?
49
+ react_1.default.createElement(checkbox_1.Checkbox, __assign({ id: props.id, checked: (_a = props.value) !== null && _a !== void 0 ? _a : false, onChange: checkboxOnChange, disabled: props.readOnly, style: props.style }, XUtils_1.XUtils.createTooltipOrErrorProps(props.error, props.tooltip)))
50
+ : react_1.default.createElement(tristatecheckbox_1.TriStateCheckbox, __assign({ id: props.id, value: props.value, onChange: triStateCheckboxChange, disabled: props.readOnly, style: props.style }, XUtils_1.XUtils.createTooltipOrErrorProps(props.error, props.tooltip))));
51
+ };
52
+ exports.XCheckboxBase = XCheckboxBase;
@@ -1,11 +1,10 @@
1
- import { XFormBase } from "./XFormBase";
2
1
  import React from "react";
3
- import { XField } from "../serverApi/XEntityMetadata";
4
- import { XTableFieldReadOnlyProp } from "./XFormDataTable2";
5
- export declare const XCheckboxDT: (props: {
6
- form: XFormBase;
7
- xField: XField;
8
- field: string;
9
- rowData: any;
10
- readOnly?: XTableFieldReadOnlyProp | undefined;
11
- }) => React.JSX.Element;
2
+ import { XInputDT, XInputDTProps } from "./XInputDT";
3
+ export interface XCheckboxDTProps extends XInputDTProps {
4
+ }
5
+ export declare class XCheckboxDT extends XInputDT<XCheckboxDTProps> {
6
+ constructor(props: XCheckboxDTProps);
7
+ getValue(): boolean | null;
8
+ onValueChange(value: boolean | null): void;
9
+ render(): React.JSX.Element;
10
+ }
@@ -1,39 +1,43 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
19
  };
5
20
  Object.defineProperty(exports, "__esModule", { value: true });
6
21
  exports.XCheckboxDT = void 0;
7
22
  var react_1 = __importDefault(require("react"));
8
- var tristatecheckbox_1 = require("primereact/tristatecheckbox");
9
- var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
10
- var XUtils_1 = require("./XUtils");
11
- var XCheckboxDT = function (props) {
12
- var onValueChange = function (field, rowData, newValue) {
13
- // pri klikani na TriStateCheckbox prichadza v newValue cyklicky: true -> false -> null
14
- // ak mame not null atribut, tak pri null hodnote skocime rovno na true
15
- if (!props.xField.isNullable) {
16
- if (newValue === null) {
17
- newValue = true;
18
- }
19
- }
20
- // zmenime hodnotu v modeli (odtial sa hodnota cita)
21
- rowData[field] = newValue;
22
- // kedze "rowData" je sucastou "props.form.state.object", tak nam staci zavolat setState({object: object}), aby sa zmena prejavila
23
- props.form.onObjectDataChange();
24
- };
25
- var fieldValue = null;
26
- // test na undefined je tu koli insertu noveho riadku
27
- if (props.rowData !== undefined && props.rowData !== null) {
28
- var rowDataValue = XUtilsCommon_1.XUtilsCommon.getValueByPath(props.rowData, props.field);
29
- // pri inserte noveho riadku su (zatial) vsetky fieldy undefined, dame na null, null je standard
30
- if (rowDataValue === undefined) {
31
- rowDataValue = null;
32
- }
33
- // konvertovat null hodnotu na "" (vo funkcii stringAsUI) je dolezite aby sa prejavila zmena na null v modeli (a tiez aby korektne pridal novy riadok)
34
- fieldValue = rowDataValue;
23
+ var XInputDT_1 = require("./XInputDT");
24
+ var XCheckboxBase_1 = require("./XCheckboxBase");
25
+ var XCheckboxDT = /** @class */ (function (_super) {
26
+ __extends(XCheckboxDT, _super);
27
+ function XCheckboxDT(props) {
28
+ var _this = _super.call(this, props) || this;
29
+ _this.onValueChange = _this.onValueChange.bind(_this);
30
+ return _this;
35
31
  }
36
- var readOnly = XUtils_1.XUtils.isReadOnlyTableField(props.field, props.readOnly, props.form.state.object, props.rowData);
37
- return (react_1.default.createElement(tristatecheckbox_1.TriStateCheckbox, { id: props.field, value: fieldValue, onChange: function (e) { return onValueChange(props.field, props.rowData, e.value); }, disabled: readOnly }));
38
- };
32
+ XCheckboxDT.prototype.getValue = function () {
33
+ return this.getValueFromRowData();
34
+ };
35
+ XCheckboxDT.prototype.onValueChange = function (value) {
36
+ this.onValueChangeBase(value, this.props.onChange);
37
+ };
38
+ XCheckboxDT.prototype.render = function () {
39
+ return (react_1.default.createElement(XCheckboxBase_1.XCheckboxBase, { id: this.props.field, value: this.getValue(), onChange: this.onValueChange, readOnly: this.isReadOnly(), isNotNull: this.isNotNull(), error: this.getError(), style: this.props.inputStyle }));
40
+ };
41
+ return XCheckboxDT;
42
+ }(XInputDT_1.XInputDT));
39
43
  exports.XCheckboxDT = XCheckboxDT;
@@ -394,7 +394,7 @@ var XFormDataTable2 = exports.XFormDataTable2 = /** @class */ (function (_super)
394
394
  body = react_1.default.createElement(XInputIntervalDT_1.XInputIntervalDT, { form: this.props.form, entity: this.getEntity(), field: columnPropsInputSimple.field, rowData: rowData, readOnly: readOnly, onChange: columnPropsInputSimple.onChange });
395
395
  }
396
396
  else if (xField.type === "boolean") {
397
- body = react_1.default.createElement(XCheckboxDT_1.XCheckboxDT, { form: this.props.form, xField: xField, field: columnPropsInputSimple.field, rowData: rowData, readOnly: readOnly });
397
+ body = react_1.default.createElement(XCheckboxDT_1.XCheckboxDT, { form: this.props.form, entity: this.getEntity(), field: columnPropsInputSimple.field, rowData: rowData, readOnly: readOnly, onChange: columnPropsInputSimple.onChange });
398
398
  }
399
399
  else {
400
400
  // xField.type === "string", pripadne ine jednoduche typy
@@ -48,10 +48,14 @@ export declare class XUtilsCommon {
48
48
  static dateAddDays(date: Date | null, days: number): Date | null;
49
49
  static dateAddMonths(date: Date | null, months: number): Date | null;
50
50
  static dateEquals(date1: Date | null, date2: Date | null): boolean;
51
+ static dateIntersect(date1From: Date, date1To: Date, date2From: Date, date2To: Date): boolean;
52
+ static dateCompare(date1: Date, date2: Date): number;
51
53
  static dateDiffInYears(dateOld: Date | null, dateNew: Date | null): number | null;
52
54
  static monthDiff(monthOld: Date | null, monthNew: Date | null): number | null;
53
55
  static findFirstMatch(pattern: RegExp, value: string): string | null;
54
56
  static sqlMaxDateIfNull(sqlExp: string): string;
55
57
  static today(): Date;
58
+ static currentMonth(): Date;
59
+ static dateAsMonth(date: Date | null): Date | null;
56
60
  static isInt(stringValue: string): boolean;
57
61
  }
@@ -486,7 +486,8 @@ var XUtilsCommon = exports.XUtilsCommon = /** @class */ (function () {
486
486
  result = true;
487
487
  }
488
488
  else if (date1 !== null && date2 !== null) {
489
- result = (date1.getTime() === date2.getTime());
489
+ // to avoid problems with time part, we use dateCompare
490
+ result = (XUtilsCommon.dateCompare(date1, date2) === 0);
490
491
  // mali sme problem - funkcia dateFromModel() konvertovala string "2025-02-04" na Tue Feb 04 2025 01:00:00 GMT+0100 (Central European Standard Time)
491
492
  // a XCalendar pri vykliknuti datumu vracal Tue Feb 04 2025 00:00:00 GMT+0100 (Central European Standard Time) -> opravili sme XCalendar
492
493
  //result = date1.getFullYear() === date2.getFullYear()
@@ -495,6 +496,24 @@ var XUtilsCommon = exports.XUtilsCommon = /** @class */ (function () {
495
496
  }
496
497
  return result;
497
498
  };
499
+ XUtilsCommon.dateIntersect = function (date1From, date1To, date2From, date2To) {
500
+ return XUtilsCommon.dateCompare(date1From, date2To) <= 0 && XUtilsCommon.dateCompare(date2From, date1To) <= 0;
501
+ };
502
+ // because of time part, the usual compare (using <=) sometimes does not work correct
503
+ XUtilsCommon.dateCompare = function (date1, date2) {
504
+ var dateOnly1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
505
+ var dateOnly2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
506
+ if (dateOnly1.getTime() < dateOnly2.getTime()) {
507
+ return -1;
508
+ }
509
+ else if (dateOnly1.getTime() === dateOnly2.getTime()) {
510
+ return 0;
511
+ }
512
+ else {
513
+ // dateOnly1 > dateOnly2
514
+ return 1;
515
+ }
516
+ };
498
517
  // solution from internet
499
518
  XUtilsCommon.dateDiffInYears = function (dateOld, dateNew) {
500
519
  var diff = null;
@@ -553,6 +572,17 @@ var XUtilsCommon = exports.XUtilsCommon = /** @class */ (function () {
553
572
  XUtilsCommon.today = function () {
554
573
  return new Date((0, XUtilsConversions_1.dateAsYYYY_MM_DD)(new Date()));
555
574
  };
575
+ XUtilsCommon.currentMonth = function () {
576
+ return XUtilsCommon.dateAsMonth(XUtilsCommon.today());
577
+ };
578
+ XUtilsCommon.dateAsMonth = function (date) {
579
+ var month = null;
580
+ if (date !== null) {
581
+ month = new Date(date); // create copy not to change "date"
582
+ month.setUTCDate(1); // first day of month
583
+ }
584
+ return month;
585
+ };
556
586
  // vrati true ak sa string sklada iba z cislic, moze mat + alebo - na zaciatku
557
587
  XUtilsCommon.isInt = function (stringValue) {
558
588
  return /^[-+]?\d+$/.test(stringValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michalrakus/x-react-web-lib",
3
- "version": "1.36.1",
3
+ "version": "1.37.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rimraf lib",