@singularsystems/neo-react 0.10.36 → 0.10.39

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.
@@ -17,10 +17,11 @@ export { AutoRunnerFactory };
17
17
  var AutoRunner = /** @class */ (function () {
18
18
  function AutoRunner(model, callback, options) {
19
19
  var _this = this;
20
+ this.isPaused = false;
20
21
  this.propertyMap = {};
21
22
  this.options = (options !== null && options !== void 0 ? options : {});
22
- this.disposerDelayed = reaction(function () { return _this.accessAllValues(model, true, new Map(), ""); }, function () { var _a; return Utils.debounce(_this, function () { return callback(model); }, (_a = _this.options.delayMs, (_a !== null && _a !== void 0 ? _a : 500))); });
23
- this.disposerImmediate = reaction(function () { return _this.accessAllValues(model, false, new Map(), ""); }, function () { return Utils.debounce(_this, function () { return callback(model); }, 0); });
23
+ this.disposerDelayed = reaction(function () { return _this.accessAllValues(model, true, new Map(), ""); }, function () { var _a; return _this.runCallback(model, callback, (_a = _this.options.delayMs, (_a !== null && _a !== void 0 ? _a : 500))); });
24
+ this.disposerImmediate = reaction(function () { return _this.accessAllValues(model, false, new Map(), ""); }, function () { return _this.runCallback(model, callback, 0); });
24
25
  }
25
26
  AutoRunner.prototype.cancelPending = function () {
26
27
  Utils.clearDebounce(this);
@@ -29,6 +30,20 @@ var AutoRunner = /** @class */ (function () {
29
30
  this.disposerDelayed();
30
31
  this.disposerImmediate();
31
32
  };
33
+ AutoRunner.prototype.runCallback = function (model, callback, delay) {
34
+ var _this = this;
35
+ if (!this.isPaused) {
36
+ Utils.debounce(this, function () {
37
+ _this.isPaused = true;
38
+ try {
39
+ callback(model);
40
+ }
41
+ finally {
42
+ _this.isPaused = false;
43
+ }
44
+ }, delay);
45
+ }
46
+ };
32
47
  /**
33
48
  * Access all the property values of a model including it's value objects properties.
34
49
  * @param instance Instance to access.
@@ -9,6 +9,8 @@ export interface INeoColumnProps<TData> extends INeoCommonColumnProps, IEditorCo
9
9
  width?: number | string;
10
10
  /** Tooltip to show in header. If you want the tooltip to show on the cells as well, use 'data-tip'. */
11
11
  headerTooltip?: string;
12
+ /** Tooltip to show in cells. If you want the tooltip to show on the cells as well, use 'data-tip'. */
13
+ cellTooltip?: string;
12
14
  /** Allows you to disable sorting on a column, or make clicking a column heading sort a specific property. */
13
15
  sort?: Model.IPropertyInstance | false;
14
16
  /** True if this column must have a total cell. */
@@ -91,7 +91,7 @@ var Column = /** @class */ (function (_super) {
91
91
  var _a;
92
92
  this.onRender();
93
93
  var allProps = BindPropsHelper.normaliseContainerProps(this, this.props, false);
94
- var _b = allProps.containerDom, width = _b.width, hideBelow = _b.hideBelow, hideAbove = _b.hideAbove, headerTooltip = _b.headerTooltip, alignment = _b.alignment, sort = _b.sort, sum = _b.sum, footerContent = _b.footerContent, headerClassName = _b.headerClassName, cellClassName = _b.cellClassName, onHeaderClick = _b.onHeaderClick, domProps = __rest(_b, ["width", "hideBelow", "hideAbove", "headerTooltip", "alignment", "sort", "sum", "footerContent", "headerClassName", "cellClassName", "onHeaderClick"]);
94
+ var _b = allProps.containerDom, width = _b.width, hideBelow = _b.hideBelow, hideAbove = _b.hideAbove, headerTooltip = _b.headerTooltip, cellTooltip = _b.cellTooltip, alignment = _b.alignment, sort = _b.sort, sum = _b.sum, footerContent = _b.footerContent, headerClassName = _b.headerClassName, cellClassName = _b.cellClassName, onHeaderClick = _b.onHeaderClick, domProps = __rest(_b, ["width", "hideBelow", "hideAbove", "headerTooltip", "cellTooltip", "alignment", "sort", "sum", "footerContent", "headerClassName", "cellClassName", "onHeaderClick"]);
95
95
  if (allProps.bind !== undefined) {
96
96
  if (!this.controlType || this.isHeader) {
97
97
  this.controlType = BindPropsHelper.getControlType(allProps);
@@ -133,7 +133,7 @@ var Column = /** @class */ (function (_super) {
133
133
  this.refreshStateObserver(allProps.editor);
134
134
  return this.isHeader ? this.renderHeader(allProps, domProps, headerTooltip, headerClassName) :
135
135
  this.isFooter ? this.renderFooter(allProps, domProps) :
136
- this.renderBody(allProps, domProps, cellClassName);
136
+ this.renderBody(allProps, domProps, cellTooltip, cellClassName);
137
137
  };
138
138
  Column.prototype.renderHeader = function (props, domProps, tooltip, headerClassName) {
139
139
  var _this = this;
@@ -153,7 +153,7 @@ var Column = /** @class */ (function (_super) {
153
153
  sortIcon &&
154
154
  React.createElement("i", { className: "column-sort-icon fa fa-" + sortIcon })));
155
155
  };
156
- Column.prototype.renderBody = function (props, domProps, cellClassName) {
156
+ Column.prototype.renderBody = function (props, domProps, cellTooltip, cellClassName) {
157
157
  var _this = this;
158
158
  var editorProps = props.editor;
159
159
  var containerProps = props.container;
@@ -183,7 +183,7 @@ var Column = /** @class */ (function (_super) {
183
183
  }
184
184
  }
185
185
  domProps.className = Utils.joinWithSpaces(domProps.className, cellClassName);
186
- return (React.createElement("td", __assign({}, domProps),
186
+ return (React.createElement("td", __assign({ "data-tip": cellTooltip }, domProps),
187
187
  !containerProps.suppressDefaultContent && (editor !== undefined ?
188
188
  editor :
189
189
  editorProps.bind ? displayValue : undefined),
@@ -0,0 +1,15 @@
1
+ export interface ICancellableEvent {
2
+ /** Informs the caller to cancel any further actions or processing. */
3
+ cancel(): void;
4
+ /** Continues with the original action. */
5
+ continue(): void;
6
+ }
7
+ export declare class CancellableEvent implements ICancellableEvent {
8
+ private canContinue;
9
+ private hasCancelled;
10
+ private cancelledAction?;
11
+ constructor(canContinue: () => boolean);
12
+ cancel(): void;
13
+ tryRunAction(action: () => void): void;
14
+ continue(): void;
15
+ }
@@ -0,0 +1,28 @@
1
+ var CancellableEvent = /** @class */ (function () {
2
+ function CancellableEvent(canContinue) {
3
+ this.canContinue = canContinue;
4
+ this.hasCancelled = false;
5
+ }
6
+ CancellableEvent.prototype.cancel = function () {
7
+ this.hasCancelled = true;
8
+ };
9
+ CancellableEvent.prototype.tryRunAction = function (action) {
10
+ if (this.hasCancelled) {
11
+ this.cancelledAction = action;
12
+ }
13
+ else {
14
+ action();
15
+ }
16
+ };
17
+ CancellableEvent.prototype.continue = function () {
18
+ if (this.cancelledAction === undefined) {
19
+ throw Error("continue() cannot be called multiple times, or if the event was not cancelled.");
20
+ }
21
+ if (this.canContinue()) {
22
+ this.cancelledAction();
23
+ }
24
+ this.cancelledAction = undefined;
25
+ };
26
+ return CancellableEvent;
27
+ }());
28
+ export { CancellableEvent };
@@ -85,6 +85,9 @@ var Modal = /** @class */ (function (_super) {
85
85
  acceptButton.isSubmit = true;
86
86
  }
87
87
  }
88
+ else {
89
+ suppressForm = true;
90
+ }
88
91
  if (closeButton === undefined) {
89
92
  closeButton = {};
90
93
  }
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import { TabContext } from "./TabContainer";
3
+ import { ICancellableEvent } from "../Misc";
3
4
  interface ITabProps {
4
5
  /** Name to show in the tab header. */
5
6
  header: string | JSX.Element;
@@ -19,6 +20,8 @@ interface ITabProps {
19
20
  * Callback to run whenever this tab is displayed.
20
21
  */
21
22
  onDisplayed?: () => void;
23
+ /** Callback to run when selecting a different tab. The event can be cancelled. */
24
+ onLeave?: (e: ICancellableEvent) => void;
22
25
  }
23
26
  export default class Tab extends React.Component<ITabProps> {
24
27
  static contextType: React.Context<import("./TabContainer").TabContextParams>;
@@ -29,7 +29,7 @@ var Tab = /** @class */ (function (_super) {
29
29
  if (this.props.onDisplayed) {
30
30
  this.context.tabManager.onTabDisplayed(this.tabKey, this.props.onDisplayed);
31
31
  }
32
- this.context.tabManager.tabMounted(this.tabKey);
32
+ this.context.tabManager.tabMounted(this.tabKey, this.props.onLeave);
33
33
  };
34
34
  Tab.prototype.render = function () {
35
35
  if (this.isHeader === undefined)
@@ -1,4 +1,5 @@
1
1
  import { Model } from '@singularsystems/neo-core';
2
+ import { ICancellableEvent } from '../Misc';
2
3
  export interface ITabManager {
3
4
  selectedTab: string;
4
5
  /**
@@ -12,7 +13,7 @@ export interface ITabManager {
12
13
  }
13
14
  export interface ITabManagerInternal extends ITabManager {
14
15
  initialise(): void;
15
- tabMounted(tabKey: string): void;
16
+ tabMounted(tabKey: string, onLeave?: (e: ICancellableEvent) => void): void;
16
17
  destroy(): void;
17
18
  }
18
19
  /**
@@ -21,7 +22,6 @@ export interface ITabManagerInternal extends ITabManager {
21
22
  */
22
23
  export declare class TabManager<T extends string = string> {
23
24
  private autoSelectFirstTab;
24
- private reactionDisposer;
25
25
  observable: Model.ObservableValue<T>;
26
26
  /**
27
27
  * Creates a tab manager used to bind to a tab container.
@@ -1,5 +1,5 @@
1
1
  import { Model } from '@singularsystems/neo-core';
2
- import { reaction } from 'mobx';
2
+ import { CancellableEvent } from '../Misc';
3
3
  /**
4
4
  * Tab manager used to manage a tab component.
5
5
  * @param T string union type of tab names.
@@ -14,31 +14,27 @@ var TabManager = /** @class */ (function () {
14
14
  if (selectedTab === void 0) { selectedTab = ""; }
15
15
  if (autoSelectFirstTab === void 0) { autoSelectFirstTab = false; }
16
16
  this.autoSelectFirstTab = autoSelectFirstTab;
17
- this.reactionDisposer = null;
18
17
  this.observable = new Model.ObservableValue("");
19
18
  this.tabs = {};
20
- this.selectedTab = selectedTab;
19
+ this.observable.value = selectedTab;
21
20
  this.onTabChanged = this.onTabChanged.bind(this);
22
21
  }
23
22
  /** Called by tab container. */
24
23
  TabManager.prototype.initialise = function () {
25
- var _this = this;
26
- this.reactionDisposer = reaction(function () { return _this.selectedTab; }, this.onTabChanged);
27
24
  if (this.selectedTab !== "") {
28
25
  this.onTabChanged();
29
26
  }
30
27
  };
31
28
  /** Called by tab container. */
32
29
  TabManager.prototype.destroy = function () {
33
- if (this.reactionDisposer) {
34
- this.reactionDisposer();
35
- }
36
30
  };
37
31
  Object.defineProperty(TabManager.prototype, "selectedTab", {
38
32
  get: function () {
39
33
  return this.observable.value;
40
34
  },
41
35
  set: function (value) {
36
+ var _this = this;
37
+ var _a;
42
38
  if (!this.tabs[value]) {
43
39
  // Probably different case, find the actual tab key.
44
40
  var foundValue = Object.keys(this.tabs).find(function (t) { return t.toLowerCase() === value.toLowerCase(); });
@@ -46,7 +42,18 @@ var TabManager = /** @class */ (function () {
46
42
  value = foundValue;
47
43
  }
48
44
  }
49
- this.observable.value = value;
45
+ var currentTabKey = this.observable.peek;
46
+ if (value !== currentTabKey) {
47
+ var cancellableEvent = new CancellableEvent(function () { return currentTabKey === _this.observable.peek; });
48
+ var currentTab = this.tabs[currentTabKey];
49
+ if (((_a = currentTab) === null || _a === void 0 ? void 0 : _a.onLeave) !== undefined) {
50
+ currentTab.onLeave(cancellableEvent);
51
+ }
52
+ cancellableEvent.tryRunAction(function () {
53
+ _this.observable.value = value;
54
+ _this.onTabChanged();
55
+ });
56
+ }
50
57
  },
51
58
  enumerable: true,
52
59
  configurable: true
@@ -67,8 +74,9 @@ var TabManager = /** @class */ (function () {
67
74
  tab.onDisplayed = callback;
68
75
  return this;
69
76
  };
70
- TabManager.prototype.tabMounted = function (tabKey) {
71
- void this.getTab(tabKey, true);
77
+ TabManager.prototype.tabMounted = function (tabKey, onLeave) {
78
+ var tab = this.getTab(tabKey, true);
79
+ tab.onLeave = onLeave;
72
80
  if (!this.selectedTab && this.autoSelectFirstTab) {
73
81
  this.selectedTab = tabKey;
74
82
  }
@@ -1,6 +1,10 @@
1
1
  import { Components } from '@singularsystems/neo-core';
2
2
  import React, { HTMLProps } from 'react';
3
3
  export interface ITooltipProps extends Components.Tooltip.ITooltipOptions<string | JSX.Element> {
4
+ /**
5
+ * True if the div wrapping the content must display inline.
6
+ */
7
+ inline?: boolean;
4
8
  }
5
9
  export default class Tooltip extends React.Component<ITooltipProps> {
6
10
  private divRef;
@@ -23,7 +23,7 @@ var Tooltip = /** @class */ (function (_super) {
23
23
  TooltipHelper.hideTooltip();
24
24
  };
25
25
  Tooltip.prototype.render = function () {
26
- return React.createElement("div", { ref: this.divRef, onMouseEnter: this.onMouseEnter, onMouseLeave: this.onMouseLeave },
26
+ return React.createElement("div", { ref: this.divRef, onMouseEnter: this.onMouseEnter, onMouseLeave: this.onMouseLeave, style: { display: this.props.inline ? "inline-block" : "" } },
27
27
  React.createElement("div", { style: { display: "none" }, ref: this.contentRef }, this.props.content),
28
28
  this.props.children);
29
29
  };
package/dist/index.d.ts CHANGED
@@ -7,3 +7,4 @@ import * as Views from './Views/';
7
7
  import * as Managers from './ReactComponents/_Managers';
8
8
  export * from './React/Decorators';
9
9
  export { Managers, NeoReactModule, NeoReactTypes, Neo, NeoGrid, Routing, Views };
10
+ export { ICancellableEvent } from './ReactComponents/Misc';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-react",
3
- "version": "0.10.36",
3
+ "version": "0.10.39",
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",
@@ -33,7 +33,7 @@
33
33
  "@types/rc-slider": "^8.6.5",
34
34
  "@types/react-color": "^3.0.1",
35
35
  "@types/react-select": "3.1.0",
36
- "@singularsystems/neo-core": "^0.10.42",
36
+ "@singularsystems/neo-core": "^0.10.47",
37
37
  "axios": "^0.21.1",
38
38
  "decimal.js-light": "2.5.1",
39
39
  "history": "4.10.1",
package/styles/Modal.scss CHANGED
@@ -14,16 +14,12 @@ body.has-modal-scroll-fix {
14
14
  .modal-container {
15
15
  position: relative;
16
16
  outline: none;
17
+ transition: opacity .3s linear;
17
18
 
18
19
  &.modal-container-additional {
19
- transition: transform .3s ease-out, opacity .3s linear;
20
- transform: translate(0, -50%);
20
+ transition: transform .3s ease-out, opacity .3s linear, margin .3s ease;
21
21
  opacity: 0;
22
-
23
- &.show {
24
- transform: translate(0, 0);
25
-
26
- }
22
+
27
23
  &.show:not(.inactive) {
28
24
  opacity: 1;
29
25
  }