@singularsystems/neo-react 0.10.65 → 0.10.67

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.
@@ -23,8 +23,19 @@ var AutoRunner = /** @class */ (function () {
23
23
  this.disposerDelayed = reaction(function () { return _this.accessAllValues(model, true, new Map(), ""); }, function () { var _a; return _this.runCallback(model, callback, (_a = _this.options.delayMs) !== null && _a !== void 0 ? _a : 500); });
24
24
  this.disposerImmediate = reaction(function () { return _this.accessAllValues(model, false, new Map(), ""); }, function () { return _this.runCallback(model, callback, 0); });
25
25
  }
26
+ Object.defineProperty(AutoRunner.prototype, "hasPending", {
27
+ get: function () {
28
+ return DebounceHelper.hasPending(this);
29
+ },
30
+ enumerable: false,
31
+ configurable: true
32
+ });
26
33
  AutoRunner.prototype.cancelPending = function () {
27
- DebounceHelper.cancelPending(this);
34
+ if (DebounceHelper.hasPending(this)) {
35
+ DebounceHelper.cancelPending(this);
36
+ return true;
37
+ }
38
+ return false;
28
39
  };
29
40
  AutoRunner.prototype.fireImmediate = function () {
30
41
  DebounceHelper.executeImmediate(this);
@@ -46,8 +46,9 @@ interface IAutoCompleteCommonProps<T> extends ICommonEditorProps, Props<IOption,
46
46
  /**
47
47
  * Callback which fires when an item is selected.
48
48
  * The removedItem parameter will be provided when removing an item from a multi select drop down.
49
+ * The addedItem parameter will be provided when an item is selected in a multi select drop down. This is the item stored in the bindItems list.
49
50
  */
50
- onItemSelected?: (item?: T, removedItem?: Model.ISelectedItem) => void;
51
+ onItemSelected?: (item?: T, removedItem?: Model.ISelectedItem, addedItem?: Model.ISelectedItem) => void;
51
52
  /**
52
53
  * Millisecond delay from the last typed character, to when the itemSource function is called.
53
54
  * Default is 500ms.
@@ -75,12 +75,13 @@ var AutoCompleteDropDown = /** @class */ (function (_super) {
75
75
  // Multi select
76
76
  var itemList = itemsProperty.value;
77
77
  if (action.action === "select-option") {
78
- itemList.push({ id: action.option.value, display: action.option.label });
78
+ var newItem = { id: action.option.value, display: action.option.label };
79
+ itemList.push(newItem);
79
80
  if (this.bindIdsList) {
80
81
  this.bindIdsList.push(action.option.value);
81
82
  }
82
83
  if (onItemSelected) {
83
- onItemSelected((_a = action.option) === null || _a === void 0 ? void 0 : _a.item);
84
+ onItemSelected((_a = action.option) === null || _a === void 0 ? void 0 : _a.item, undefined, newItem);
84
85
  }
85
86
  }
86
87
  else if (action.action === "remove-value") {
@@ -129,15 +130,25 @@ var AutoCompleteDropDown = /** @class */ (function (_super) {
129
130
  var bindDisplayProperty = bindDisplay;
130
131
  var displayInfo = this.bindProperty.validator.getDisplayState(this.context.validationDisplayMode);
131
132
  displayInfo.applyToDom(nativeProps, this.context.parentType !== EditorParentType.FormGroup);
132
- this.displayMember = (_a = this.props.displayMember) !== null && _a !== void 0 ? _a : "";
133
- this.valueMember = (_b = this.props.valueMember) !== null && _b !== void 0 ? _b : "";
133
+ if (!this.displayMember) {
134
+ this.displayMember = (_a = this.props.displayMember) !== null && _a !== void 0 ? _a : "";
135
+ }
136
+ if (!this.valueMember) {
137
+ this.valueMember = (_b = this.props.valueMember) !== null && _b !== void 0 ? _b : "";
138
+ }
134
139
  var defaultItems = undefined;
135
140
  if (this.props.items) {
136
141
  var items_1 = this.getItems(this.props.items);
142
+ defaultItems = this.mapTArrayToOptions(items_1);
137
143
  if (this.props.filterPredicate !== undefined) {
138
- items_1 = items_1.filter(this.props.filterPredicate);
144
+ if (bindValue) {
145
+ // Dont filter out the current selected item even if excluded by the filter.
146
+ defaultItems = defaultItems.filter(function (option) { return bindValue.value === option.value || _this.props.filterPredicate(option.item); });
147
+ }
148
+ else {
149
+ defaultItems = defaultItems.filter(function (option) { return _this.props.filterPredicate(option.item); });
150
+ }
139
151
  }
140
- defaultItems = this.mapTArrayToOptions(items_1);
141
152
  if (descriptionMember === undefined && items_1.length > 0) {
142
153
  if (EnumHelper.isEnumItem(items_1[0])) {
143
154
  descriptionMember = "description";
@@ -26,6 +26,8 @@ export interface IDropDownSpecificProps<T> {
26
26
  nullText?: string;
27
27
  /** Text to display as the first item in the drop down list when the user is allowed to select a blank item. */
28
28
  deSelectText?: string;
29
+ /** Set to true if the property should be sorted by value instead of display text. */
30
+ sortByValue?: boolean;
29
31
  }
30
32
  export interface IDropDownProps<T> extends IBindableEditorProps<HTMLSelectElement> {
31
33
  select: IDropDownSpecificProps<T>;
@@ -34,6 +36,7 @@ export default class DropDown<T> extends DropDownBase<T, IDropDownProps<T>> {
34
36
  static contextType: React.Context<import("../FormContext").FormContextParams>;
35
37
  context: React.ContextType<typeof FormContext>;
36
38
  private selectedItem;
39
+ private sortByValue?;
37
40
  private listIndexSymbol;
38
41
  constructor(props: IDropDownProps<T>);
39
42
  private get items();
@@ -41,7 +41,9 @@ var DropDown = /** @class */ (function (_super) {
41
41
  list.forEach(function (item) { return index[item[_this.valueMember]] = item; });
42
42
  };
43
43
  DropDown.prototype.getSelectedOption = function (value) {
44
- this.props.bind.propertyInfo.hasSortValue = true;
44
+ if (!this.sortByValue) {
45
+ this.props.bind.propertyInfo.hasSortValue = true;
46
+ }
45
47
  if (!this.selectedItem || this.selectedItem[this.valueMember] != value) {
46
48
  var list = this.items;
47
49
  var indexJustCreated = false;
@@ -61,7 +63,9 @@ var DropDown = /** @class */ (function (_super) {
61
63
  this.selectedItem[this.displayMember] = "";
62
64
  this.selectedItem[this.valueMember] = null;
63
65
  }
64
- this.setFieldInfo(this.props.bind, this.selectedItem[this.displayMember]);
66
+ var displayValue = this.selectedItem[this.displayMember];
67
+ this.setFieldInfo(this.props.bind, displayValue);
68
+ this.props.bind.sortValue = this.sortByValue ? value : displayValue;
65
69
  }
66
70
  return this.selectedItem;
67
71
  };
@@ -81,10 +85,11 @@ var DropDown = /** @class */ (function (_super) {
81
85
  };
82
86
  DropDown.prototype.render = function () {
83
87
  var _this = this;
84
- var _a, _b, _c, _d, _e, _f;
88
+ var _a, _b, _c, _d, _e, _f, _g;
85
89
  var splitProps = BindPropsHelper.normaliseEditorProps(this, this.props);
86
90
  var domProps = BindPropsHelper.autoSetDomProperties(splitProps, this.context);
87
91
  domProps.className = Utils.joinWithSpaces(domProps.className, splitProps.isBootstrap ? "form-control" : "neo-forms-editor");
92
+ this.sortByValue = (_a = splitProps.select) === null || _a === void 0 ? void 0 : _a.sortByValue;
88
93
  if (splitProps.select) {
89
94
  if (splitProps.select.valueMember)
90
95
  this.valueMember = splitProps.select.valueMember;
@@ -96,7 +101,7 @@ var DropDown = /** @class */ (function (_super) {
96
101
  var items = this.items;
97
102
  var selectedItem = this.getSelectedOption(this.props.bind.value); // This sets the sort value to allow sorting of drop downs in grids.
98
103
  var value = this.props.bind.value;
99
- var addBlankItem = ((_b = (_a = splitProps.select) === null || _a === void 0 ? void 0 : _a.allowNulls) !== null && _b !== void 0 ? _b : this.props.bind.propertyInfo.allowNulls) || !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;
100
105
  if (addBlankItem && items.find(function (item) { return item[_this.valueMember] === null || item[_this.valueMember] === ""; })) {
101
106
  // If there is an item with a null value, don't add a blank drop down item.
102
107
  addBlankItem = false;
@@ -106,7 +111,7 @@ var DropDown = /** @class */ (function (_super) {
106
111
  control = React.createElement("div", { className: "form-control form-control-loading" },
107
112
  React.createElement("div", { className: "spinner-border" }));
108
113
  }
109
- else if ((_c = splitProps.select) === null || _c === void 0 ? void 0 : _c.renderAsText) {
114
+ else if ((_d = splitProps.select) === null || _d === void 0 ? void 0 : _d.renderAsText) {
110
115
  control = React.createElement("span", null, selectedItem ? selectedItem[this.displayMember] : "");
111
116
  }
112
117
  else if (splitProps.editor.isReadOnly) {
@@ -117,7 +122,7 @@ var DropDown = /** @class */ (function (_super) {
117
122
  domProps.disabled = true;
118
123
  }
119
124
  var valueIsBlank = value === undefined || value === null;
120
- var nullText = (valueIsBlank || ((_d = splitProps.select) === null || _d === void 0 ? void 0 : _d.deSelectText) === undefined) ? (_e = splitProps.select) === null || _e === void 0 ? void 0 : _e.nullText : (_f = splitProps.select) === null || _f === void 0 ? void 0 : _f.deSelectText;
125
+ var nullText = (valueIsBlank || ((_e = splitProps.select) === null || _e === void 0 ? void 0 : _e.deSelectText) === undefined) ? (_f = splitProps.select) === null || _f === void 0 ? void 0 : _f.nullText : (_g = splitProps.select) === null || _g === void 0 ? void 0 : _g.deSelectText;
121
126
  if (valueIsBlank) {
122
127
  domProps.className = Utils.joinWithSpaces(domProps.className, "select-no-value");
123
128
  }
@@ -1,13 +1,12 @@
1
1
  import * as React from 'react';
2
2
  import { Components, Model } from '@singularsystems/neo-core';
3
- import { ItemCallback } from './PropTypes';
4
3
  export interface IFormProps<T extends Model.IModelBase> extends React.FormHTMLAttributes<HTMLElement>, Components.IFormOptions<T> {
5
4
  /**
6
5
  * Called when the form is submitted, but the model is not valid.
7
6
  * The justValidated parameter will be true if the validationDisplayMode is 'AfterSubmit', and this is the first submit attempt.
8
7
  */
9
8
  onInvalid?: (e: React.FormEvent, justValidated?: boolean) => void;
10
- children: React.ReactNode | React.ReactNode[] | ItemCallback<T>;
9
+ children: React.ReactNode | React.ReactNode[] | ((item: T, meta: Model.TransformMetaType<T>) => React.ReactNode);
11
10
  }
12
11
  export default class Form<T extends Model.IModelBase> extends React.Component<IFormProps<T>> {
13
12
  private reactionDisposer?;
@@ -11,6 +11,7 @@ export declare class GridContextParams<T> {
11
11
  inFirstRowInGroup: boolean;
12
12
  columnCount: number;
13
13
  expandProperty?: Model.IPropertyInstance<boolean | null>;
14
+ hideExpandButton?: boolean;
14
15
  expandAll?: boolean;
15
16
  hasSummaries: boolean;
16
17
  dataView: Data.DataViewBase<T>;
@@ -101,11 +101,11 @@ var Grid = /** @class */ (function (_super) {
101
101
  }
102
102
  return (React.createElement("table", __assign({}, domProps, { className: className, ref: this.domRef }),
103
103
  React.createElement(GridContext.Provider, { value: this.gridContext },
104
- React.createElement(TableSection, { type: "header" }, this.headerItem && this.props.children(this.headerItem, this.headerItem.meta)),
104
+ React.createElement(TableSection, { type: "header" }, this.headerItem && this.props.children(this.headerItem, this.headerItem.meta, true)),
105
105
  React.createElement(TableSection, { type: "body" }, this.gridContext.dataView.getItems().map(function (item) { return (React.createElement(ItemGroup, { item: item, key: keyProperty ? item[keyProperty] : item.entityIdentifier, template: _this.props.children })); })),
106
106
  React.createElement(Observer, null, function () { return (showAddButton || addButton || footerButtons || _this.gridContext.hasSummaries || footerContent !== undefined) &&
107
107
  React.createElement(TableSection, { type: "footer" },
108
- _this.gridContext.hasSummaries && _this.headerItem && _this.props.children(_this.headerItem, _this.headerItem.meta),
108
+ _this.gridContext.hasSummaries && _this.headerItem && _this.props.children(_this.headerItem, _this.headerItem.meta, true),
109
109
  footerContent !== undefined && footerContent(_this.gridContext.dataView.getItems()),
110
110
  (showAddButton || addButton || footerButtons) &&
111
111
  React.createElement(AddButtonRow, { addButton: addButton, showAddButton: showAddButton, additionalContent: footerButtons })); }))));
@@ -206,7 +206,7 @@ var ItemGroup = /** @class */ (function (_super) {
206
206
  ItemGroup.prototype.render = function () {
207
207
  this.context.currentItem = this.props.item;
208
208
  //this.context.inFirstRowInGroup = true;
209
- return (this.props.template(this.props.item, this.props.item.meta));
209
+ return (this.props.template(this.props.item, this.props.item.meta, false));
210
210
  };
211
211
  ItemGroup.contextType = GridContext;
212
212
  ItemGroup = __decorate([
@@ -71,6 +71,10 @@ interface INeoRowGroupProps {
71
71
  * To hide the expand button, return null.
72
72
  */
73
73
  expandProperty?: Model.IPropertyInstance<boolean | null>;
74
+ /**
75
+ * Hides the expansion button on this row.
76
+ */
77
+ hideExpandButton?: boolean;
74
78
  }
75
79
  export declare class RowGroup extends React.Component<INeoRowGroupProps> {
76
80
  static contextType: React.Context<import("./Grid").GridContextParams<unknown>>;
@@ -75,7 +75,7 @@ var Row = /** @class */ (function (_super) {
75
75
  var output = ((this.props.showInHeader || inBody) &&
76
76
  React.createElement("tr", __assign({}, domProps),
77
77
  this.expandProperty && this.context.expandAll === undefined &&
78
- React.createElement(Column, { className: "neo-grid-expand-column" }, this.firstRowInGroup && inBody && this.expandProperty.value !== null &&
78
+ React.createElement(Column, { className: "neo-grid-expand-column" }, this.firstRowInGroup && inBody && this.context.hideExpandButton !== true && this.expandProperty.value !== null &&
79
79
  React.createElement(NeoButton, __assign({}, expandButtonOptions))),
80
80
  this.props.children));
81
81
  this.setGridContext();
@@ -193,6 +193,7 @@ var RowGroup = /** @class */ (function (_super) {
193
193
  RowGroup.prototype.render = function () {
194
194
  this.context.expandProperty = this.props.expandProperty;
195
195
  this.context.inFirstRowInGroup = true;
196
+ this.context.hideExpandButton = this.props.hideExpandButton;
196
197
  return this.props.children;
197
198
  };
198
199
  RowGroup.contextType = GridContext;
@@ -11,7 +11,7 @@ import PropertyInfo from '@singularsystems/neo-core/dist/Model/PropertyInfo';
11
11
  import { IComponentBase } from './ComponentBase';
12
12
  import FileInput, { IFileEditorProps } from './FileManager/FileInput';
13
13
  import { FormContextParams } from './FormContext';
14
- export declare type ItemCallback<T> = (item: T, meta: TransformMetaType<T>) => React.ReactNode;
14
+ export declare type ItemCallback<T> = (item: T, meta: TransformMetaType<T>, isHeader: boolean) => React.ReactNode;
15
15
  export declare enum ControlType {
16
16
  Date = 0,
17
17
  Number = 1,
@@ -9,7 +9,7 @@ interface ITabProps {
9
9
  /** Name used for binding to selected tab. (Same as id property) */
10
10
  name?: string;
11
11
  /** Icon to display in tab header. */
12
- icon?: string;
12
+ icon?: any;
13
13
  /** True if the tab is disabled and not allowed to be clicked on. */
14
14
  disabled?: boolean;
15
15
  /**
@@ -1,7 +1,6 @@
1
1
  import { __assign, __extends, __rest } from "tslib";
2
2
  import React from "react";
3
3
  import { Components, Utils } from "@singularsystems/neo-core";
4
- import { ObservableValue } from "@singularsystems/neo-core/dist/Model/ObservableValue";
5
4
  import { TabManager } from './TabManager';
6
5
  var TabContextParams = /** @class */ (function () {
7
6
  function TabContextParams() {
@@ -18,7 +17,6 @@ export var TabContext = React.createContext(new TabContextParams());
18
17
  var TabContainer = /** @class */ (function (_super) {
19
18
  __extends(TabContainer, _super);
20
19
  function TabContainer(props) {
21
- var _a;
22
20
  var _this = _super.call(this, props) || this;
23
21
  _this.tabContext = new TabContextParams();
24
22
  var tabManager;
@@ -27,8 +25,7 @@ var TabContainer = /** @class */ (function (_super) {
27
25
  _this.tabContext.isUserTabManager = true;
28
26
  }
29
27
  else {
30
- tabManager = new TabManager("", true);
31
- tabManager.observable = (_a = _this.props.selectedTab) !== null && _a !== void 0 ? _a : new ObservableValue("");
28
+ tabManager = new TabManager("", true, _this.props.selectedTab);
32
29
  }
33
30
  _this.tabManager = tabManager;
34
31
  _this.tabContext.tabManager = _this.tabManager;
@@ -22,13 +22,14 @@ export interface ITabManagerInternal extends ITabManager {
22
22
  */
23
23
  export declare class TabManager<T extends string = string> {
24
24
  private autoSelectFirstTab;
25
- observable: Model.ObservableValue<T>;
25
+ private reactionDisposer;
26
+ observable: Model.IObservableValue<T>;
26
27
  /**
27
28
  * Creates a tab manager used to bind to a tab container.
28
29
  * @param selectedTab Initially selected tab.
29
30
  * @param autoSelectFirstTab Set to true if the first child tab should become selected.
30
31
  */
31
- constructor(selectedTab?: T, autoSelectFirstTab?: boolean);
32
+ constructor(selectedTab?: T, autoSelectFirstTab?: boolean, observable?: Model.IObservableValue<T>);
32
33
  /** Called by tab container. */
33
34
  private initialise;
34
35
  /** Called by tab container. */
@@ -43,6 +44,7 @@ export declare class TabManager<T extends string = string> {
43
44
  * Registers a callback to run whenever the tab with this tab key is displayed.
44
45
  */
45
46
  onTabDisplayed(tabKey: T, callback: () => void): this;
47
+ /** Called by tab container. */
46
48
  private tabMounted;
47
49
  private getTab;
48
50
  /**
@@ -1,4 +1,5 @@
1
1
  import { Model } from '@singularsystems/neo-core';
2
+ import { reaction } from "mobx";
2
3
  import { CancellableEvent } from '../Misc';
3
4
  /**
4
5
  * Tab manager used to manage a tab component.
@@ -10,14 +11,20 @@ var TabManager = /** @class */ (function () {
10
11
  * @param selectedTab Initially selected tab.
11
12
  * @param autoSelectFirstTab Set to true if the first child tab should become selected.
12
13
  */
13
- function TabManager(selectedTab, autoSelectFirstTab) {
14
+ function TabManager(selectedTab, autoSelectFirstTab, observable) {
15
+ var _this = this;
14
16
  if (selectedTab === void 0) { selectedTab = ""; }
15
17
  if (autoSelectFirstTab === void 0) { autoSelectFirstTab = false; }
16
18
  this.autoSelectFirstTab = autoSelectFirstTab;
17
- this.observable = new Model.ObservableValue("");
18
19
  this.tabs = {};
19
- this.observable.value = selectedTab;
20
+ if (observable) {
21
+ this.observable = observable;
22
+ }
23
+ else {
24
+ this.observable = new Model.ObservableValue(selectedTab);
25
+ }
20
26
  this.onTabChanged = this.onTabChanged.bind(this);
27
+ this.reactionDisposer = reaction(function () { return _this.observable.value; }, function () { return _this.onTabChanged(); });
21
28
  }
22
29
  /** Called by tab container. */
23
30
  TabManager.prototype.initialise = function () {
@@ -27,6 +34,7 @@ var TabManager = /** @class */ (function () {
27
34
  };
28
35
  /** Called by tab container. */
29
36
  TabManager.prototype.destroy = function () {
37
+ this.reactionDisposer();
30
38
  };
31
39
  Object.defineProperty(TabManager.prototype, "selectedTab", {
32
40
  get: function () {
@@ -50,7 +58,6 @@ var TabManager = /** @class */ (function () {
50
58
  }
51
59
  cancellableEvent.tryRunAction(function () {
52
60
  _this.observable.value = value;
53
- _this.onTabChanged();
54
61
  });
55
62
  }
56
63
  },
@@ -73,6 +80,7 @@ var TabManager = /** @class */ (function () {
73
80
  tab.onDisplayed = callback;
74
81
  return this;
75
82
  };
83
+ /** Called by tab container. */
76
84
  TabManager.prototype.tabMounted = function (tabKey, onLeave) {
77
85
  var tab = this.getTab(tabKey, true);
78
86
  tab.onLeave = onLeave;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-react",
3
- "version": "0.10.65",
3
+ "version": "0.10.67",
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",
@@ -32,7 +32,7 @@
32
32
  "typescript": "4.5.5"
33
33
  },
34
34
  "dependencies": {
35
- "@singularsystems/neo-core": "0.10.77",
35
+ "@singularsystems/neo-core": "0.10.80",
36
36
  "@types/rc-slider": "^8.6.5",
37
37
  "@types/react-color": "^3.0.1",
38
38
  "@types/react-select": "3.1.0",
@@ -50,7 +50,7 @@
50
50
  "react-router-dom": "5.1.0"
51
51
  },
52
52
  "peerDependencies": {
53
- "@singularsystems/neo-core": ">=0.10.77",
53
+ "@singularsystems/neo-core": ">=0.10.80",
54
54
  "axios": ">=0.21.1",
55
55
  "inversify": ">=5.0.1",
56
56
  "react": ">=16.13.1",