@singularsystems/neo-react 1.0.0-beta.4 → 1.0.0-beta.6

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.
@@ -10,12 +10,10 @@ import { AutoRunnerFactory } from '../React/AutoRunner';
10
10
  import { RoutingState } from '../Routing/RoutingState';
11
11
  import { ContextMenuState } from '../ReactComponents/ContextMenu/ContextMenuState';
12
12
  import { DisposeHelper } from '../Services/DisposeHelper';
13
- import Decimal from 'decimal.js-light';
14
13
  import { IconFactory } from '../ReactComponents/Icons/IconFactory';
15
14
  var neoReactModule = new AppServices.Module("neo-react", function (container) {
16
15
  container.bind(AppServices.NeoTypes.Core.AutoRunnerFactory).to(AutoRunnerFactory).inSingletonScope();
17
16
  container.bind(AppServices.NeoTypes.Core.ModelCreator).to(ReactModelCreator).inTransientScope();
18
- container.bind(AppServices.NeoTypes.Misc.DecimalType).toConstantValue(Decimal);
19
17
  container.bind(AppServices.NeoTypes.UI.ErrorHandler).to(ErrorHandler).inSingletonScope();
20
18
  container.bind(AppServices.NeoTypes.UI.GlobalContextMenuState).toConstantValue(new ContextMenuState());
21
19
  container.bind(AppServices.NeoTypes.Routing.PageLeaveHandler).to(PageLeaveHandler).inSingletonScope();
@@ -1,5 +1,5 @@
1
1
  import { AppServices, Utils } from '@singularsystems/neo-core';
2
- import { configure, runInAction, untracked } from 'mobx';
2
+ import { configure, isObservableArray, runInAction, untracked } from 'mobx';
3
3
  import React from 'react';
4
4
  import { NeoReactTypes } from './Types';
5
5
  export function runReactSetup(container) {
@@ -10,6 +10,12 @@ export function runReactSetup(container) {
10
10
  return React.createElement("div", { dangerouslySetInnerHTML: { __html: html } });
11
11
  };
12
12
  Utils.batchUpdate = runInAction;
13
+ Utils.sortableArray = function (array) {
14
+ if (isObservableArray(array)) {
15
+ return array.slice();
16
+ }
17
+ return array;
18
+ };
13
19
  window.addEventListener("beforeunload", function (e) {
14
20
  container.get(AppServices.NeoTypes.Routing.PageLeaveHandler).onWindowUnload(container.get(NeoReactTypes.Routing.GlobalRoutingState).currentView, e);
15
21
  });
@@ -5,7 +5,6 @@ import Slider, { Range } from 'rc-slider';
5
5
  import { SketchPicker } from 'react-color';
6
6
  import AsyncSelect from 'react-select/async';
7
7
  import { AxiosStatic } from 'axios';
8
- import Decimal from 'decimal.js-light';
9
8
  import Select from 'react-select';
10
9
  import { IDisposeHelper } from '../Services/IDisposeHelper';
11
10
  import { IIconFactory } from '../ReactComponents/Icons/IIconFactory';
@@ -36,14 +35,12 @@ declare const NeoReactTypes: {
36
35
  Core: {
37
36
  AutoRunnerFactory: AppServices.ServiceIdentifier<import("@singularsystems/neo-core/dist/Model/IAutoRunner").IAutoRunnerFactory>;
38
37
  ConnectionManager: AppServices.ServiceIdentifier<import("@singularsystems/neo-core/dist/ConnectionManager").IConnectionManager>;
38
+ DecimalService: AppServices.ServiceIdentifier<import("@singularsystems/neo-core/dist/Numeric").IDecimalService<import("@singularsystems/neo-core/dist/Numeric").IDecimal>>;
39
39
  ModelCreator: AppServices.ServiceIdentifier<import("@singularsystems/neo-core/dist/Model/IModelCreatorBase").default>;
40
40
  };
41
41
  Localisation: {
42
42
  LocalisationService: AppServices.ServiceIdentifier<import("@singularsystems/neo-core/dist/Localisation").ILocalisationService>;
43
43
  };
44
- Misc: {
45
- DecimalType: AppServices.ServiceIdentifier<typeof Decimal>;
46
- };
47
44
  Security: {
48
45
  AuthenticationService: AppServices.ServiceIdentifier<import("@singularsystems/neo-core/dist/Security").IAuthenticationService>;
49
46
  AuthorisationService: AppServices.ServiceIdentifier<import("@singularsystems/neo-core/dist/Security").IAuthorisationService>;
@@ -27,11 +27,11 @@ var ReactModelCreator = /** @class */ (function (_super) {
27
27
  model.isSuspended = false;
28
28
  };
29
29
  ReactModelCreator.prototype.setupObject = function (typeInfo, object, options) {
30
- var _a, _b, _c;
30
+ var _a, _b;
31
31
  var annotations = {};
32
32
  var observables = {};
33
- for (var _i = 0, _d = typeInfo.properties; _i < _d.length; _i++) {
34
- var propertyInfo = _d[_i];
33
+ for (var _i = 0, _c = typeInfo.properties; _i < _c.length; _i++) {
34
+ var propertyInfo = _c[_i];
35
35
  if (propertyInfo.isObservable !== false) {
36
36
  var propertyName = propertyInfo.propertyName, makeObservable_1 = (_a = propertyInfo.isObservable) !== null && _a !== void 0 ? _a : options.makeObservable;
37
37
  var propertyInstance = void 0;
@@ -56,9 +56,9 @@ var ReactModelCreator = /** @class */ (function (_super) {
56
56
  }
57
57
  }
58
58
  }
59
- for (var _e = 0, _f = Array.from(typeInfo.methods.values()); _e < _f.length; _e++) {
60
- var methodInfo = _f[_e];
61
- if ((_c = (_b = methodInfo.isAction) !== null && _b !== void 0 ? _b : options.autoActions) !== null && _c !== void 0 ? _c : options.makeObservable) {
59
+ for (var _d = 0, _e = Array.from(typeInfo.methods.values()); _d < _e.length; _d++) {
60
+ var methodInfo = _e[_d];
61
+ if ((_b = methodInfo.isAction) !== null && _b !== void 0 ? _b : options.autoActions) {
62
62
  annotations[methodInfo.name] = action;
63
63
  }
64
64
  }
@@ -101,7 +101,8 @@ var DropDown = /** @class */ (function (_super) {
101
101
  var items = this.items;
102
102
  var selectedItem = this.getSelectedOption(this.props.bind.value); // This sets the sort value to allow sorting of drop downs in grids.
103
103
  var value = this.props.bind.value;
104
- var addBlankItem = ((_c = (_b = splitProps.select) === null || _b === void 0 ? void 0 : _b.allowNulls) !== null && _c !== void 0 ? _c : this.props.bind.propertyInfo.allowNulls) || !value;
104
+ var notFound = items.length > 0 && value && selectedItem[this.valueMember] !== value;
105
+ var addBlankItem = ((_c = (_b = splitProps.select) === null || _b === void 0 ? void 0 : _b.allowNulls) !== null && _c !== void 0 ? _c : this.props.bind.propertyInfo.allowNulls) || !value || notFound;
105
106
  if (addBlankItem && items.find(function (item) { return item[_this.valueMember] === null || item[_this.valueMember] === ""; })) {
106
107
  // If there is an item with a null value, don't add a blank drop down item.
107
108
  addBlankItem = false;
@@ -128,7 +129,7 @@ var DropDown = /** @class */ (function (_super) {
128
129
  }
129
130
  control =
130
131
  React.createElement("select", __assign({ value: valueIsBlank ? "" : value, onChange: this.onItemSelected, ref: splitProps.editor.inputElement }, domProps),
131
- addBlankItem && React.createElement("option", { className: "option-default" }, nullText),
132
+ addBlankItem && React.createElement("option", { className: "option-default" }, notFound ? "(Not found): ".concat(value) : nullText),
132
133
  items.map(function (item) { return (React.createElement("option", { value: item[_this.valueMember], key: item[_this.valueMember] }, item[_this.displayMember])); }));
133
134
  }
134
135
  return (InputHelpers.surroundWithInputGroup(control, splitProps.editor));
@@ -22,6 +22,7 @@ export interface INeoColumnProps<TData> extends INeoCommonColumnProps, IEditorCo
22
22
  /** Class name to apply to body cells. */
23
23
  cellClassName?: string;
24
24
  onHeaderClick?: (e: React.MouseEvent) => void;
25
+ children?: React.ReactNode | (() => React.ReactNode);
25
26
  }
26
27
  export default class Column<TData> extends ComponentBase<INeoColumnProps<TData>> {
27
28
  static isColumnComponent: boolean;
@@ -186,9 +186,9 @@ var Column = /** @class */ (function (_super) {
186
186
  !containerProps.suppressDefaultContent && (editor !== undefined ?
187
187
  editor :
188
188
  editorProps.bind ? displayValue : undefined),
189
- !containerProps.bindContext && this.props.children,
189
+ !containerProps.bindContext && (this.props.children instanceof Function ? this.props.children() : this.props.children),
190
190
  containerProps.bindContext &&
191
- React.createElement(FormContext.Consumer, null, function (value) { return (React.createElement(FormContext.Provider, { value: __assign(__assign({}, value), { parentType: EditorParentType.Column, bindProperty: containerProps.bindContext }) }, _this.props.children)); })));
191
+ React.createElement(FormContext.Consumer, null, function (value) { return (React.createElement(FormContext.Provider, { value: __assign(__assign({}, value), { parentType: EditorParentType.Column, bindProperty: containerProps.bindContext }) }, _this.props.children instanceof Function ? _this.props.children() : _this.props.children)); })));
192
192
  };
193
193
  Column.prototype.renderFooter = function (props, domProps) {
194
194
  var _this = this;
@@ -1,8 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { IBindableEditorProps } from './PropTypes';
3
3
  import { FormContext } from './FormContext';
4
- import { Misc, Model } from '@singularsystems/neo-core';
5
- import Decimal from 'decimal.js-light';
4
+ import { Misc, Model, Numeric } from '@singularsystems/neo-core';
6
5
  import ComponentBase from './ComponentBase';
7
6
  export interface INumberInputSpecificProps {
8
7
  /** Format string of number */
@@ -33,7 +32,7 @@ export declare class FormatState {
33
32
  /** How many decimals the value is allowed. */
34
33
  allowedDecimals: number, zeroText?: string | undefined, useNative?: boolean | undefined);
35
34
  static create(propertyInfo: Model.PropertyInfo, numericType: Misc.DataType, numProps?: INumberInputSpecificProps, appendText?: string): FormatState;
36
- getFormattedValue(value?: number | Decimal | null): string;
35
+ getFormattedValue(value?: number | Numeric.IDecimal | null): string;
37
36
  }
38
37
  export default class NumberInput extends ComponentBase<INumberInputProps> {
39
38
  static contextType: React.Context<import("./FormContext").FormContextParams>;
@@ -3,7 +3,6 @@ import * as React from 'react';
3
3
  import { BindPropsHelper } from './PropTypes';
4
4
  import { FormContext } from './FormContext';
5
5
  import { Misc, NumberUtils, Utils } from '@singularsystems/neo-core';
6
- import Decimal from 'decimal.js-light';
7
6
  import { InputHelpers } from './InputHelpers';
8
7
  import { observer } from 'mobx-react';
9
8
  import memoize from 'memoize-one';
@@ -57,9 +56,7 @@ var FormatState = /** @class */ (function () {
57
56
  return this.zeroText;
58
57
  }
59
58
  if (value !== undefined && value !== null) {
60
- if (value instanceof Misc.Globals.decimalType) {
61
- value = value.toNumber();
62
- }
59
+ value = NumberUtils.decimalService.toNumber(value);
63
60
  if (typeof value === "number") {
64
61
  if (this.hasExternalPercentSymbol) {
65
62
  value *= 100;
@@ -112,18 +109,18 @@ var NumberInput = /** @class */ (function (_super) {
112
109
  return;
113
110
  }
114
111
  }
112
+ var decimal = NumberUtils.decimalService;
115
113
  if (stringValue == "") {
116
- newValue = this.props.bind.propertyInfo.allowNulls ? null : new Decimal(0);
114
+ newValue = this.props.bind.propertyInfo.allowNulls ? null : decimal.createDecimal(0);
117
115
  }
118
116
  else if (this.formatState.isPercent && NumberUtils.transformPercent) {
119
- newValue = new Decimal(stringValue).dividedBy(100);
117
+ newValue = decimal.divideBy(decimal.createDecimal(stringValue), 100);
120
118
  }
121
119
  else if (this.numericType === Misc.DataType.Float || this.numericType === Misc.DataType.Decimal) {
122
- newValue = new Decimal(stringValue);
120
+ newValue = decimal.createDecimal(stringValue);
123
121
  }
124
122
  else {
125
- // Rounds to zero.
126
- newValue = new Decimal(stringValue).toDecimalPlaces(0, Decimal.ROUND_DOWN);
123
+ newValue = decimal.truncate(decimal.createDecimal(stringValue));
127
124
  }
128
125
  if (newValue === null) {
129
126
  this.props.bind.value = newValue;
@@ -136,7 +133,7 @@ var NumberInput = /** @class */ (function (_super) {
136
133
  this.props.bind.value = newValue;
137
134
  }
138
135
  else {
139
- this.props.bind.value = newValue.toNumber();
136
+ this.props.bind.value = decimal.toNumber(newValue);
140
137
  }
141
138
  }
142
139
  };
@@ -148,13 +145,7 @@ var NumberInput = /** @class */ (function (_super) {
148
145
  }
149
146
  };
150
147
  NumberInput.prototype.getBindValueAsNumber = function () {
151
- var propertyValue = this.props.bind.value;
152
- if (propertyValue instanceof Misc.Globals.decimalType) {
153
- return propertyValue.toNumber();
154
- }
155
- else {
156
- return propertyValue;
157
- }
148
+ return NumberUtils.decimalService.toNumber(this.props.bind.value);
158
149
  };
159
150
  NumberInput.prototype.setFocusedText = function (element) {
160
151
  this.hasFocus = true;
@@ -208,7 +199,7 @@ var NumberInput = /** @class */ (function (_super) {
208
199
  value -= deltaValue;
209
200
  }
210
201
  if (this.numericType === Misc.DataType.Decimal) {
211
- this.props.bind.value = new Decimal(value);
202
+ this.props.bind.value = NumberUtils.decimalService.createDecimal(value);
212
203
  }
213
204
  else {
214
205
  this.props.bind.value = value;
@@ -57,6 +57,7 @@ export interface IBindableEditorProps<T = HTMLElement> extends IBindableEditorPr
57
57
  * Value of true results in the readable property name being used.
58
58
  */
59
59
  placeholder?: any;
60
+ children?: any;
60
61
  }
61
62
  interface IEditorSelectorProps<T> {
62
63
  /** Drop down props if this editor must be a drop down */
@@ -6,7 +6,7 @@ export interface IViewParameter {
6
6
  /**
7
7
  * Gets or sets the current parameter value.
8
8
  */
9
- value: number | string | null;
9
+ value: number | string | string[] | null;
10
10
  /**
11
11
  * Clears the value, replacing the url instead of adding to the history.
12
12
  * This prevents the back button returning the params to the current state.
@@ -31,6 +31,10 @@ export interface IViewParameter {
31
31
  * Returns the value as a string. String will be empty if the underlying value is null.
32
32
  */
33
33
  asString(): string;
34
+ /**
35
+ * Returns the value as a list of string.
36
+ */
37
+ asStringList(): string[];
34
38
  /**
35
39
  * Allows this view parameter to automatically update when the provided properties value changes.
36
40
  * This is one way, you will still need to set the property value in viewParamsUpdated()
@@ -51,8 +55,8 @@ export declare class ViewParameter implements IViewParameter {
51
55
  prefixes: IViewParameterPrefix[];
52
56
  constructor(parent: IViewParameterListInternal, name: string, routeParameter: IRouteParameter);
53
57
  bindTo(propertyOrCallback: Model.IPropertyInstance | (() => (string | number | null | undefined))): void;
54
- get value(): number | string | null;
55
- set value(value: number | string | null);
58
+ get value(): number | string | string[] | null;
59
+ set value(value: number | string | string[] | null);
56
60
  reset(): void;
57
61
  _description: string;
58
62
  get description(): string;
@@ -60,6 +64,7 @@ export declare class ViewParameter implements IViewParameter {
60
64
  setDescription(description: string, getPrefixes?: (currentPrefixes: IViewParameterPrefix[]) => IViewParameterPrefix[]): void;
61
65
  asNullableInt(): number | null;
62
66
  asString(): string;
67
+ asStringList(): string[];
63
68
  /** Updates the current value, and returns true if the value changed. */
64
69
  update(value: string | null): boolean;
65
70
  getParamString(state: {
@@ -26,7 +26,13 @@ export var ViewParameter = /** @class */ (function () {
26
26
  return this._value;
27
27
  },
28
28
  set: function (value) {
29
- var stringValue = value ? value.toString() : null;
29
+ var stringValue;
30
+ if (value instanceof Array) {
31
+ stringValue = value.join(",");
32
+ }
33
+ else {
34
+ stringValue = value ? value.toString() : null;
35
+ }
30
36
  if (stringValue !== this._value) {
31
37
  this.hasPendingValue = true;
32
38
  this.pendingValue = stringValue;
@@ -69,6 +75,14 @@ export var ViewParameter = /** @class */ (function () {
69
75
  ViewParameter.prototype.asString = function () {
70
76
  return this._value || "";
71
77
  };
78
+ ViewParameter.prototype.asStringList = function () {
79
+ if (this._value) {
80
+ return this._value.split(",");
81
+ }
82
+ else {
83
+ return [];
84
+ }
85
+ };
72
86
  /** Updates the current value, and returns true if the value changed. */
73
87
  ViewParameter.prototype.update = function (value) {
74
88
  if (value) {
@@ -24,7 +24,7 @@ export interface IViewParameterListOfT<TParams extends RouteParameterObject<TPar
24
24
  * @param values New values.
25
25
  */
26
26
  setValues(values: {
27
- [P in keyof TParams]?: number | string | null;
27
+ [P in keyof TParams]?: number | string | string[] | null;
28
28
  }, options?: ISetValuesOptions | boolean): void;
29
29
  }
30
30
  export interface IViewParameterListInternal extends IViewParameterList {
@@ -42,7 +42,7 @@ export declare class ViewParameterList<TParams extends RouteParameterObject<TPar
42
42
  getBreadCrumbList(upTo?: ViewParameter): BreadCrumbItem[];
43
43
  private getQueryString;
44
44
  setValues(values: {
45
- [P in keyof TParams]?: number | string | null;
45
+ [P in keyof TParams]?: number | string | string[] | null;
46
46
  }, options?: ISetValuesOptions | boolean): void;
47
47
  setUrl(viewParameter: ViewParameter | null, replace?: boolean): void;
48
48
  /**
@@ -22,7 +22,7 @@ var ViewParameterList = /** @class */ (function () {
22
22
  var basePath = Misc.Globals.appService.get(NeoReactTypes.Routing.NavigationHelper).getCurrentViewPath();
23
23
  var breadCrumbs = [];
24
24
  var state = { hasQuery: false };
25
- var queryPath = this.getQueryString();
25
+ var queryPath = this.getQueryString(state);
26
26
  var paramPath = basePath;
27
27
  var selectablePath = basePath;
28
28
  for (var _i = 0, _b = this.params; _i < _b.length; _i++) {
@@ -56,10 +56,12 @@ var ViewParameterList = /** @class */ (function () {
56
56
  break;
57
57
  }
58
58
  }
59
+ if (breadCrumbs.length === 0 && state.hasQuery) {
60
+ breadCrumbs.push(new BreadCrumbItem("", queryPath));
61
+ }
59
62
  return breadCrumbs;
60
63
  };
61
- ViewParameterList.prototype.getQueryString = function () {
62
- var state = { hasQuery: false };
64
+ ViewParameterList.prototype.getQueryString = function (state) {
63
65
  var queryPath = "";
64
66
  for (var _i = 0, _a = this.params; _i < _a.length; _i++) {
65
67
  var viewParam = _a[_i];
@@ -159,7 +161,7 @@ var ViewParameterList = /** @class */ (function () {
159
161
  while (paramPath.endsWith("/")) {
160
162
  paramPath = paramPath.substring(0, paramPath.length - 1);
161
163
  }
162
- return paramPath + viewParameterList.getQueryString();
164
+ return paramPath + viewParameterList.getQueryString(state);
163
165
  };
164
166
  return ViewParameterList;
165
167
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-react",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "React application logic and components for the Neo client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,11 +29,10 @@
29
29
  "typescript": "5.0.4"
30
30
  },
31
31
  "dependencies": {
32
- "@singularsystems/neo-core": "1.0.0-beta.5",
32
+ "@singularsystems/neo-core": "1.0.0-beta.6",
33
33
  "@types/rc-slider": "^8.6.5",
34
34
  "@types/react-color": "^3.0.1",
35
35
  "axios": "1.4.0",
36
- "decimal.js-light": "^2.5.1",
37
36
  "history": "4.10.1",
38
37
  "inversify": "^6.0.1",
39
38
  "memoize-one": "6.0.0",
@@ -48,7 +47,7 @@
48
47
  "tslib": "2.5.0"
49
48
  },
50
49
  "peerDependencies": {
51
- "@singularsystems/neo-core": ">=1.0.0-beta.5",
50
+ "@singularsystems/neo-core": ">=1.0.0-beta.6",
52
51
  "axios": "1.4.0",
53
52
  "inversify": ">=5.0.1",
54
53
  "mobx": ">=6.9.0",