@michalrakus/x-react-web-lib 1.31.0 → 1.31.1

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.
@@ -4,6 +4,7 @@ import { OperationType } from "./XUtils";
4
4
  import { XFieldOnChange, XFormComponent } from "./XFormComponent";
5
5
  import { XTableFieldOnChange, XFormDataTable2, XRowTechData } from "./XFormDataTable2";
6
6
  import { XErrorMap, XErrors } from "./XErrors";
7
+ import { XEntity } from "../serverApi/XEntityMetadata";
7
8
  export type XOnSaveOrCancelProp = (object: XObject | null, objectChange: OperationType) => void;
8
9
  export interface XFormProps {
9
10
  id?: number;
@@ -17,6 +18,7 @@ export declare function Form(entity: string): <T extends new (...args: any[]) =>
17
18
  } & T;
18
19
  export declare abstract class XFormBase extends Component<XFormProps> {
19
20
  entity?: string;
21
+ xEntity: XEntity | undefined;
20
22
  fields: Set<string>;
21
23
  state: {
22
24
  object: XObject | null;
@@ -34,7 +36,7 @@ export declare abstract class XFormBase extends Component<XFormProps> {
34
36
  getEntity(): string;
35
37
  getXObject(): XObject;
36
38
  getObject(): any;
37
- isAddRow(): any;
39
+ isAddRow(): boolean;
38
40
  isInDialog(): boolean;
39
41
  onFieldChange(field: string, value: any, error?: string | undefined, onChange?: XFieldOnChange, assocObjectChange?: OperationType): void;
40
42
  onTableFieldChange(rowData: any, field: string, value: any, error?: string | undefined, onChange?: XTableFieldOnChange, assocObjectChange?: OperationType): void;
@@ -93,6 +93,7 @@ exports.XFormBase = exports.Form = void 0;
93
93
  var react_1 = require("react");
94
94
  var XUtils_1 = require("./XUtils");
95
95
  var XUtilsCommon_1 = require("../serverApi/XUtilsCommon");
96
+ var XUtilsMetadataCommon_1 = require("../serverApi/XUtilsMetadataCommon");
96
97
  // class decorator ktory nastavuje property entity (dalo by sa to nastavovat v konstruktore ale decorator je menej ukecany)
97
98
  // ma sa pouzivat len na triedach odvodenych od XFormBase - obmedzenie som vsak nevedel nakodit
98
99
  // property sa nastavi az po zbehnuti konstruktora
@@ -156,6 +157,7 @@ var XFormBase = /** @class */ (function (_super) {
156
157
  if (this.entity === undefined) {
157
158
  throw "XFormBase: Property entity is not defined - use decorator @Form.";
158
159
  }
160
+ this.xEntity = XUtilsMetadataCommon_1.XUtilsMetadataCommon.getXEntity(this.entity);
159
161
  if (!(this.props.id !== undefined)) return [3 /*break*/, 2];
160
162
  return [4 /*yield*/, XUtils_1.XUtils.fetchById(this.entity, Array.from(this.fields), this.props.id)];
161
163
  case 1:
@@ -221,7 +223,14 @@ var XFormBase = /** @class */ (function (_super) {
221
223
  return this.getXObject();
222
224
  };
223
225
  XFormBase.prototype.isAddRow = function () {
224
- return this.props.id === undefined;
226
+ // povodny kod
227
+ //return this.props.id === undefined;
228
+ // aby sme mohli zmenit insert na update (napr. ak po kontrole id fieldov zistime ze zaznam existuje), tak zistujeme id-cko z this.state.object
229
+ var isAddRow = false; // default
230
+ if (this.state.object && this.xEntity) {
231
+ isAddRow = this.state.object[this.xEntity.idField] === undefined;
232
+ }
233
+ return isAddRow;
225
234
  };
226
235
  // helper method
227
236
  XFormBase.prototype.isInDialog = function () {
@@ -12,9 +12,11 @@ export declare class XInputTextarea extends XInput<string, XInputTextareaProps>
12
12
  cols: string;
13
13
  labelOnTop: boolean;
14
14
  };
15
+ xInputTextareaBaseRef: any;
15
16
  constructor(props: XInputTextareaProps);
16
17
  getValue(): string | null;
17
18
  onValueChange(value: string | null): void;
18
19
  getLabelStyle(): React.CSSProperties;
20
+ autoResize(): void;
19
21
  render(): React.JSX.Element;
20
22
  }
@@ -28,6 +28,7 @@ var XInputTextarea = /** @class */ (function (_super) {
28
28
  __extends(XInputTextarea, _super);
29
29
  function XInputTextarea(props) {
30
30
  var _this = _super.call(this, props) || this;
31
+ _this.xInputTextareaBaseRef = react_1.default.createRef();
31
32
  _this.onValueChange = _this.onValueChange.bind(_this);
32
33
  return _this;
33
34
  }
@@ -41,6 +42,12 @@ var XInputTextarea = /** @class */ (function (_super) {
41
42
  var _a;
42
43
  return this.props.labelOnTop ? ((_a = this.props.labelStyle) !== null && _a !== void 0 ? _a : {}) : _super.prototype.getLabelStyle.call(this);
43
44
  };
45
+ // api method - can be called through "ref" from parent if needed to adjust the height of the input textarea according to the (changed) content
46
+ XInputTextarea.prototype.autoResize = function () {
47
+ if (this.xInputTextareaBaseRef.current) {
48
+ this.xInputTextareaBaseRef.current.autoResize();
49
+ }
50
+ };
44
51
  XInputTextarea.prototype.render = function () {
45
52
  var _a, _b;
46
53
  var fieldStyle = this.props.fieldStyle;
@@ -86,7 +93,7 @@ var XInputTextarea = /** @class */ (function (_super) {
86
93
  react_1.default.createElement("label", { id: labelElemId, htmlFor: this.props.field, className: !this.props.labelOnTop ? 'col-fixed' : undefined, style: labelStyle }, this.getLabel()),
87
94
  labelTooltip ? react_1.default.createElement(tooltip_1.Tooltip, { target: "#".concat(labelElemId), content: labelTooltip }) : null,
88
95
  this.props.form.state.object ?
89
- react_1.default.createElement(XInputTextareaBase_1.XInputTextareaBase, { id: this.props.field, value: value, onChange: this.onValueChange, readOnly: this.isReadOnly(), maxLength: this.xField.length, style: inputStyle, rows: this.props.rows, cols: cols, autoResize: this.props.autoResize, error: this.getError(), tooltip: this.props.tooltip, placeholder: (_b = this.props.placeholder) !== null && _b !== void 0 ? _b : this.props.desc })
96
+ react_1.default.createElement(XInputTextareaBase_1.XInputTextareaBase, { ref: this.xInputTextareaBaseRef, id: this.props.field, value: value, onChange: this.onValueChange, readOnly: this.isReadOnly(), maxLength: this.xField.length, style: inputStyle, rows: this.props.rows, cols: cols, autoResize: this.props.autoResize, error: this.getError(), tooltip: this.props.tooltip, placeholder: (_b = this.props.placeholder) !== null && _b !== void 0 ? _b : this.props.desc })
90
97
  : null));
91
98
  };
92
99
  XInputTextarea.defaultProps = {
@@ -1,15 +1,28 @@
1
- import React from "react";
2
- export declare const XInputTextareaBase: (props: {
3
- id?: string | undefined;
1
+ import React, { Component } from "react";
2
+ export interface XInputTextareaBaseProps {
3
+ id?: string;
4
4
  value: string | null;
5
5
  onChange: (value: string | null) => void;
6
- rows?: number | undefined;
7
- cols?: number | undefined;
8
- autoResize?: boolean | undefined;
9
- readOnly?: boolean | undefined;
10
- error?: string | undefined;
11
- style?: React.CSSProperties | undefined;
12
- maxLength?: number | undefined;
13
- tooltip?: string | undefined;
14
- placeholder?: string | undefined;
15
- }) => React.JSX.Element;
6
+ rows?: number;
7
+ cols?: number;
8
+ autoResize?: boolean;
9
+ readOnly?: boolean;
10
+ error?: string;
11
+ style?: React.CSSProperties;
12
+ maxLength?: number;
13
+ tooltip?: string;
14
+ placeholder?: string;
15
+ }
16
+ export declare class XInputTextareaBase extends Component<XInputTextareaBaseProps> {
17
+ inputTextareaRef: any;
18
+ state: {
19
+ inputChanged: boolean;
20
+ inputValueState: string | undefined;
21
+ };
22
+ constructor(props: XInputTextareaBaseProps);
23
+ onChange(e: any): void;
24
+ onBlur(e: React.FocusEvent<HTMLTextAreaElement>): void;
25
+ getInputValue(): string;
26
+ autoResize(): void;
27
+ render(): React.JSX.Element;
28
+ }
@@ -1,4 +1,19 @@
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 __assign = (this && this.__assign) || function () {
3
18
  __assign = Object.assign || function(t) {
4
19
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -33,59 +48,59 @@ var __importStar = (this && this.__importStar) || function (mod) {
33
48
  __setModuleDefault(result, mod);
34
49
  return result;
35
50
  };
36
- var __read = (this && this.__read) || function (o, n) {
37
- var m = typeof Symbol === "function" && o[Symbol.iterator];
38
- if (!m) return o;
39
- var i = m.call(o), r, ar = [], e;
40
- try {
41
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
42
- }
43
- catch (error) { e = { error: error }; }
44
- finally {
45
- try {
46
- if (r && !r.done && (m = i["return"])) m.call(i);
47
- }
48
- finally { if (e) throw e.error; }
49
- }
50
- return ar;
51
- };
52
51
  Object.defineProperty(exports, "__esModule", { value: true });
53
52
  exports.XInputTextareaBase = void 0;
54
53
  var react_1 = __importStar(require("react"));
55
54
  var XUtilsConversions_1 = require("../serverApi/XUtilsConversions");
56
55
  var XUtils_1 = require("./XUtils");
57
56
  var inputtextarea_1 = require("primereact/inputtextarea");
58
- // koli optimalizacii - typovany text si zapisuje do svojej stavovej premennej a onChange zavola az z onBlur
59
- // pri velkych formularoch je totiz volanie zmeny stavu this.setState({object: this.state.object, errorMap: this.state.errorMap}); pomale
60
- var XInputTextareaBase = function (props) {
61
- // true, ak uzivatel typuje hodnotu
62
- // false, ak bol zavolany onBlur
63
- var _a = __read((0, react_1.useState)(false), 2), inputChanged = _a[0], setInputChanged = _a[1];
64
- // pouzivane, len ak inputChanged === true, je tu zapisana zmenena hodnota v inpute
65
- var _b = __read((0, react_1.useState)(undefined), 2), inputValueState = _b[0], setInputValueState = _b[1];
66
- var onChange = function (e) {
67
- setInputChanged(true);
68
- setInputValueState(e.target.value);
57
+ var XInputTextareaBase = /** @class */ (function (_super) {
58
+ __extends(XInputTextareaBase, _super);
59
+ function XInputTextareaBase(props) {
60
+ var _this = _super.call(this, props) || this;
61
+ _this.inputTextareaRef = react_1.default.createRef();
62
+ _this.state = {
63
+ inputChanged: false,
64
+ inputValueState: undefined
65
+ };
66
+ _this.onChange = _this.onChange.bind(_this);
67
+ _this.onBlur = _this.onBlur.bind(_this);
68
+ return _this;
69
+ }
70
+ XInputTextareaBase.prototype.onChange = function (e) {
71
+ this.setState({ inputChanged: true, inputValueState: e.target.value });
69
72
  };
70
- var onBlur = function (e) {
73
+ XInputTextareaBase.prototype.onBlur = function (e) {
71
74
  // optimalizacia - onChange volame len ak inputChanged === true
72
- if (inputChanged) {
75
+ if (this.state.inputChanged) {
73
76
  var value = (0, XUtilsConversions_1.stringFromUI)(e.target.value);
74
- props.onChange(value);
75
- setInputChanged(false);
76
- setInputValueState(undefined); // pre poriadok
77
+ this.props.onChange(value);
78
+ // pre poriadok nastavujeme inputValueState na undefined
79
+ this.setState({ inputChanged: false, inputValueState: undefined });
77
80
  }
78
81
  };
79
- var getInputValue = function () {
82
+ XInputTextareaBase.prototype.getInputValue = function () {
80
83
  var inputValue;
81
- if (inputChanged) {
82
- inputValue = inputValueState;
84
+ if (this.state.inputChanged) {
85
+ inputValue = this.state.inputValueState;
83
86
  }
84
87
  else {
85
- inputValue = (0, XUtilsConversions_1.stringAsUI)(props.value);
88
+ inputValue = (0, XUtilsConversions_1.stringAsUI)(this.props.value);
86
89
  }
87
90
  return inputValue;
88
91
  };
89
- return (react_1.default.createElement(inputtextarea_1.InputTextarea, __assign({ id: props.id, value: getInputValue(), onChange: onChange, onBlur: onBlur, readOnly: props.readOnly, maxLength: props.maxLength, style: props.style, rows: props.rows, cols: props.cols, autoResize: props.autoResize }, XUtils_1.XUtils.createTooltipOrErrorProps(props.error, props.tooltip), { placeholder: props.placeholder })));
90
- };
92
+ // call this method to autoresize textarea after setting the content of XInputTextareaBase via onChange of some other attribute (e.g. onChangeClient)
93
+ // must be called as callback (param) of the method XFormBase.setStateXForm
94
+ XInputTextareaBase.prototype.autoResize = function () {
95
+ // code from ChatGPT
96
+ if (this.inputTextareaRef.current) {
97
+ this.inputTextareaRef.current.style.height = 'auto'; // Reset height
98
+ this.inputTextareaRef.current.style.height = "".concat(this.inputTextareaRef.current.scrollHeight, "px"); // Set height based on scrollHeight
99
+ }
100
+ };
101
+ XInputTextareaBase.prototype.render = function () {
102
+ return (react_1.default.createElement(inputtextarea_1.InputTextarea, __assign({ ref: this.inputTextareaRef, id: this.props.id, value: this.getInputValue(), onChange: this.onChange, onBlur: this.onBlur, readOnly: this.props.readOnly, maxLength: this.props.maxLength, style: this.props.style, rows: this.props.rows, cols: this.props.cols, autoResize: this.props.autoResize }, XUtils_1.XUtils.createTooltipOrErrorProps(this.props.error, this.props.tooltip), { placeholder: this.props.placeholder })));
103
+ };
104
+ return XInputTextareaBase;
105
+ }(react_1.Component));
91
106
  exports.XInputTextareaBase = XInputTextareaBase;
@@ -16,6 +16,7 @@ export declare function dateFromModel(value: any): Date | null;
16
16
  export declare function dateFromUI(valueString: string, dateScale?: XDateScale): Date | null | undefined;
17
17
  export declare function dateAsUI(value: Date | null, dateScale?: XDateScale): string;
18
18
  export declare function dateAsYYYY_MM_DD(date: Date): string;
19
+ export declare function dateAsDB(date: Date | null): string;
19
20
  export declare function datetimeAsUI(value: Date | null): string;
20
21
  export declare function timeFromModel(value: any): Date | null;
21
22
  export declare function dateFormatUI(dateScale?: XDateScale): string;
@@ -27,7 +27,7 @@ var __read = (this && this.__read) || function (o, n) {
27
27
  return ar;
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.convertValueBase = exports.convertValue = exports.convertObject = exports.AsUIType = exports.booleanAsUIText = exports.intervalAsUI = exports.intervalFromUI = exports.datetimeFormatUI = exports.dateFormatCalendar = exports.dateFormatUI = exports.timeFromModel = exports.datetimeAsUI = exports.dateAsYYYY_MM_DD = exports.dateAsUI = exports.dateFromUI = exports.dateFromModel = exports.XDateScale = exports.numberFromString = exports.numberFromModel = exports.numberAsUI = exports.intFromUI = exports.stringAsDB = exports.stringAsUI = exports.stringFromUI = void 0;
30
+ exports.convertValueBase = exports.convertValue = exports.convertObject = exports.AsUIType = exports.booleanAsUIText = exports.intervalAsUI = exports.intervalFromUI = exports.datetimeFormatUI = exports.dateFormatCalendar = exports.dateFormatUI = exports.timeFromModel = exports.datetimeAsUI = exports.dateAsDB = exports.dateAsYYYY_MM_DD = exports.dateAsUI = exports.dateFromUI = exports.dateFromModel = exports.XDateScale = exports.numberFromString = exports.numberFromModel = exports.numberAsUI = exports.intFromUI = exports.stringAsDB = exports.stringAsUI = exports.stringFromUI = void 0;
31
31
  var XUtilsCommon_1 = require("./XUtilsCommon");
32
32
  var XLocale_1 = require("../components/XLocale");
33
33
  var XUtilsMetadataCommon_1 = require("./XUtilsMetadataCommon");
@@ -228,6 +228,10 @@ function dateAsYYYY_MM_DD(date) {
228
228
  return "".concat(date.getFullYear(), "-").concat(monthStr, "-").concat(dayStr);
229
229
  }
230
230
  exports.dateAsYYYY_MM_DD = dateAsYYYY_MM_DD;
231
+ function dateAsDB(date) {
232
+ return date !== null ? "'".concat(dateAsYYYY_MM_DD(date), "'::DATE") : "NULL::DATE";
233
+ }
234
+ exports.dateAsDB = dateAsDB;
231
235
  function datetimeAsUI(value) {
232
236
  if (value !== null) {
233
237
  return (0, XUtilsCommon_1.dateFormat)(value, datetimeFormatUI());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michalrakus/x-react-web-lib",
3
- "version": "1.31.0",
3
+ "version": "1.31.1",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rimraf lib",
@@ -40,8 +40,8 @@
40
40
  "peerDependencies": {
41
41
  "primeflex": "^3.3.1",
42
42
  "primeicons": "^7.0.0",
43
- "primereact": "~10.4.0",
44
- "quill": "^1.3.7",
43
+ "primereact": "~10.8.2",
44
+ "quill": "^2.0.2",
45
45
  "react": "^18.2.0",
46
46
  "react-dom": "^18.2.0",
47
47
  "react-transition-group": "^4.4.5"