@linzjs/step-ag-grid 2.2.2 → 2.3.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.
package/dist/index.js CHANGED
@@ -1305,12 +1305,12 @@ var ControlledMenuFr = function (_a, externalRef) {
1305
1305
  reposition,
1306
1306
  viewScroll,
1307
1307
  ]);
1308
- var clickIsWithinMenu = react.useCallback(function (ev) {
1309
- return hasParentClass("szh-menu--state-open", ev.target) ||
1310
- (closeMenuExclusionClassName && hasParentClass(closeMenuExclusionClassName, ev.target));
1308
+ var isWithinMenu = react.useCallback(function (target) {
1309
+ return hasParentClass("szh-menu--state-open", target) ||
1310
+ (closeMenuExclusionClassName && hasParentClass(closeMenuExclusionClassName, target));
1311
1311
  }, [closeMenuExclusionClassName]);
1312
1312
  var handleScreenEventForSave = react.useCallback(function (ev) {
1313
- if (!clickIsWithinMenu(ev)) {
1313
+ if (!isWithinMenu(ev.target)) {
1314
1314
  ev.preventDefault();
1315
1315
  ev.stopPropagation();
1316
1316
  // FIXME There's an issue in React17
@@ -1332,13 +1332,13 @@ var ControlledMenuFr = function (_a, externalRef) {
1332
1332
  setTimeout(function () { return (skipOpen.current = false); }, 300);
1333
1333
  }
1334
1334
  }
1335
- }, [clickIsWithinMenu, onClose, saveButtonRef, skipOpen]);
1335
+ }, [isWithinMenu, onClose, saveButtonRef, skipOpen]);
1336
1336
  var handleScreenEventForCancel = react.useCallback(function (ev) {
1337
- if (!clickIsWithinMenu(ev)) {
1337
+ if (!isWithinMenu(ev.target)) {
1338
1338
  ev.preventDefault();
1339
1339
  ev.stopPropagation();
1340
1340
  }
1341
- }, [clickIsWithinMenu]);
1341
+ }, [isWithinMenu]);
1342
1342
  react.useEffect(function () {
1343
1343
  if (isMenuOpen(state)) {
1344
1344
  var thisDocument_1 = (anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) ? anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current.ownerDocument : document;
@@ -1391,7 +1391,9 @@ var ControlledMenuFr = function (_a, externalRef) {
1391
1391
  }
1392
1392
  };
1393
1393
  var onBlur = function (e) {
1394
- if (isMenuOpen(state) && !e.currentTarget.contains(e.relatedTarget || document.activeElement)) {
1394
+ if (isMenuOpen(state) &&
1395
+ !e.currentTarget.contains(e.relatedTarget || document.activeElement) &&
1396
+ !isWithinMenu(e.relatedTarget)) {
1395
1397
  safeCall(onClose, { reason: CloseReason.BLUR });
1396
1398
  // If a user clicks on the menu button when a menu is open, we need to close the menu.
1397
1399
  // However, a blur event will be fired prior to the click event on menu button,
@@ -2711,8 +2713,6 @@ var useGridPopoverHook = function (props) {
2711
2713
  }); }, [props, stopEditing, propsRef]);
2712
2714
  var popoverWrapper = react.useCallback(function (children) {
2713
2715
  return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: anchorRef.current && (jsxRuntime.jsxs(ControlledMenu, __assign({ state: isOpen ? "open" : "closed", portal: true, unmountOnClose: true, anchorRef: anchorRef, saveButtonRef: saveButtonRef, menuClassName: "step-ag-grid-react-menu", onClose: function (event) {
2714
- if (event.reason === "blur")
2715
- return;
2716
2716
  triggerSave(event.reason).then();
2717
2717
  }, viewScroll: "auto", dontShrinkIfDirectionIsTop: true, className: props.className, closeMenuExclusionClassName: "ReactModal__Content" }, { children: [saving && ( // This is the overlay that prevents editing when the editor is saving
2718
2718
  jsxRuntime.jsx("div", { style: {
@@ -3002,27 +3002,39 @@ var GridFormDropDown = function (_props) {
3002
3002
 
3003
3003
  var GridFormMultiSelect = function (props) {
3004
3004
  var selectedRows = props.selectedRows;
3005
- var _a = react.useState(""), filter = _a[0], setFilter = _a[1];
3006
- var _b = react.useState([]), filteredValues = _b[0], setFilteredValues = _b[1];
3005
+ var initialiseValues = react.useMemo(function () { return props.initialSelectedValues && props.initialSelectedValues(selectedRows); }, [props, selectedRows]);
3006
+ var subComponentIsValid = react.useRef({});
3007
+ var _a = react.useState(initialiseValues && !Array.isArray(initialiseValues)
3008
+ ? lodashEs.pickBy(initialiseValues, function (value) { return typeof value !== "boolean"; })
3009
+ : {}), subSelectedValues = _a[0], setSubSelectedValues = _a[1];
3010
+ var _b = react.useState(function () {
3011
+ return initialiseValues ? (Array.isArray(initialiseValues) ? initialiseValues : Object.keys(initialiseValues)) : [];
3012
+ }), selectedValues = _b[0], setSelectedValues = _b[1];
3013
+ var _c = react.useState(""), filter = _c[0], setFilter = _c[1];
3014
+ var _d = react.useState([]), filteredValues = _d[0], setFilteredValues = _d[1];
3007
3015
  var optionsInitialising = react.useRef(false);
3008
- var _c = react.useState(), options = _c[0], setOptions = _c[1];
3009
- var subSelectedValues = react.useRef({});
3010
- var _d = react.useState(function () {
3011
- return props.initialSelectedValues ? props.initialSelectedValues(selectedRows) : [];
3012
- }), selectedValues = _d[0], setSelectedValues = _d[1];
3016
+ var _e = react.useState(), options = _e[0], setOptions = _e[1];
3013
3017
  var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3014
- var values;
3015
- return __generator(this, function (_a) {
3016
- switch (_a.label) {
3018
+ var validations, notValid, selectedOptions, selectedResults;
3019
+ var _a;
3020
+ return __generator(this, function (_b) {
3021
+ switch (_b.label) {
3017
3022
  case 0:
3018
- values = lodashEs.fromPairs(selectedValues.map(function (value) { var _a; return [value, (_a = subSelectedValues.current[value]) !== null && _a !== void 0 ? _a : true]; }));
3019
3023
  if (!props.onSave) return [3 /*break*/, 2];
3020
- return [4 /*yield*/, props.onSave({ selectedRows: selectedRows, values: values })];
3021
- case 1: return [2 /*return*/, _a.sent()];
3024
+ validations = lodashEs.pick(subComponentIsValid.current, selectedValues);
3025
+ notValid = Object.values(validations).some(function (v) { return !v; });
3026
+ if (notValid)
3027
+ return [2 /*return*/, false];
3028
+ selectedOptions = (_a = selectedValues.map(function (row) { return (options !== null && options !== void 0 ? options : []).find(function (opt) { return opt.value == row; }); })) !== null && _a !== void 0 ? _a : [];
3029
+ selectedResults = selectedOptions.map(function (selectedOption) {
3030
+ return (__assign(__assign({}, selectedOption), { subValue: subSelectedValues["".concat(selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value)] }));
3031
+ });
3032
+ return [4 /*yield*/, props.onSave(selectedRows, selectedResults)];
3033
+ case 1: return [2 /*return*/, _b.sent()];
3022
3034
  case 2: return [2 /*return*/, true];
3023
3035
  }
3024
3036
  });
3025
- }); }, [props, selectedValues]);
3037
+ }); }, [options, props, selectedValues, subSelectedValues]);
3026
3038
  // Load up options list if it's async function
3027
3039
  react.useEffect(function () {
3028
3040
  var _a;
@@ -3075,7 +3087,7 @@ var GridFormMultiSelect = function (props) {
3075
3087
  })
3076
3088
  .filter(function (r) { return r !== undefined; }));
3077
3089
  }, [props.filtered, filter, options]);
3078
- var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, triggerSave = _e.triggerSave;
3090
+ var _f = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _f.popoverWrapper, triggerSave = _f.triggerSave;
3079
3091
  return popoverWrapper(jsxRuntime.jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormMultiSelect-container" }, { children: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [options && props.filtered && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(FocusableItem, __assign({ className: "filter-item" }, { children: function (_a) {
3080
3092
  var _b;
3081
3093
  var ref = _a.ref;
@@ -3117,16 +3129,23 @@ var GridFormMultiSelect = function (props) {
3117
3129
  } }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3118
3130
  return item.subComponent &&
3119
3131
  item.subComponent({
3132
+ ref: ref,
3133
+ value: subSelectedValues["".concat(item.value)],
3120
3134
  setValue: function (value) {
3121
- subSelectedValues.current[item.value] = value;
3122
- }
3123
- }, ref);
3135
+ subSelectedValues["".concat(item.value)] = value;
3136
+ setSubSelectedValues(__assign({}, subSelectedValues));
3137
+ },
3138
+ setValid: function (valid) {
3139
+ subComponentIsValid.current["".concat(item.value)] = valid;
3140
+ },
3141
+ triggerSave: triggerSave
3142
+ });
3124
3143
  } }), "".concat(item.value, "_subcomponent")))] }, "".concat(index)));
3125
3144
  }) }))] }) })));
3126
3145
  };
3127
3146
 
3128
3147
  var GridPopoutEditMultiSelect = function (colDef, props) {
3129
- return GridCell(__assign({ initialWidth: 65, maxWidth: 150 }, colDef), __assign(__assign({ editor: GridFormMultiSelect }, props), { editorParams: __assign({ className: "GridMultiSelect-containerMedium" }, props.editorParams) }));
3148
+ return GridCell(colDef, __assign(__assign({ editor: GridFormMultiSelect }, props), { editorParams: __assign({ className: "GridMultiSelect-containerMedium" }, props.editorParams) }));
3130
3149
  };
3131
3150
 
3132
3151
  var css_248z$3 = ".GridPopoutMenu-burger{cursor:pointer}.GridPopoutMenu-burger svg{fill:#007198}.GridPopoutMenu-burgerDisabled svg{fill:#989189}";
@@ -3300,7 +3319,7 @@ var css_248z$1 = ".LuiTextInput{margin-bottom:0}.LuiTextInput-formatted{color:#b
3300
3319
  styleInject(css_248z$1);
3301
3320
 
3302
3321
  var TextInputFormatted = function (props) {
3303
- return (jsxRuntime.jsxs("div", __assign({ className: clsx("LuiTextInput Grid-popoverContainer", props.error && "hasError", props.warning && "hasWarning", props.className) }, { children: [jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-inputWrapper" }, { children: [jsxRuntime.jsx("input", __assign({ type: "text", className: "LuiTextInput-input", min: "0", value: props.value, onChange: props.onChange }, props.inputProps)), jsxRuntime.jsx("span", __assign({ className: "LuiTextInput-formatted" }, { children: props.formatted }))] })), props.error && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-error" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextInput-error-icon", size: "sm", status: "error" }), props.error] }))), props.warning && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-warning" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "warning", name: "ic_warning", className: "LuiTextInput-warning-icon", size: "sm", status: "warning" }), props.warning] })))] })));
3322
+ return (jsxRuntime.jsxs("div", __assign({ className: clsx("LuiTextInput Grid-popoverContainer", props.error && "hasError", props.warning && "hasWarning", props.className) }, { children: [jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-inputWrapper" }, { children: [jsxRuntime.jsx("input", __assign({ type: "text", className: "LuiTextInput-input", min: "0", spellCheck: true, defaultValue: props.value, onChange: props.onChange }, props.inputProps)), jsxRuntime.jsx("span", __assign({ className: "LuiTextInput-formatted" }, { children: props.formatted }))] })), props.error && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-error" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextInput-error-icon", size: "sm", status: "error" }), props.error] }))), props.warning && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-warning" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "warning", name: "ic_warning", className: "LuiTextInput-warning-icon", size: "sm", status: "warning" }), props.warning] })))] })));
3304
3323
  };
3305
3324
 
3306
3325
  var GridFormEditBearing = function (_props) {
@@ -3382,7 +3401,7 @@ var GridPopoverEditBearingCorrection = function (colDef, props) {
3382
3401
  };
3383
3402
 
3384
3403
  var GridPopoverEditDropDown = function (colDef, props) {
3385
- return GridCell(__assign({ initialWidth: 65, maxWidth: 150 }, colDef), __assign(__assign({ editor: GridFormDropDown }, props), { editorParams: __assign({
3404
+ return GridCell(colDef, __assign(__assign({ editor: GridFormDropDown }, props), { editorParams: __assign({
3386
3405
  // Defaults to medium size container
3387
3406
  className: "GridPopoverEditDropDown-containerMedium" }, props.editorParams) }));
3388
3407
  };
@@ -3410,7 +3429,7 @@ var GridFormMessage = function (_props) {
3410
3429
  };
3411
3430
 
3412
3431
  var GridPopoverMessage = function (colDef, props) {
3413
- return GridCell(__assign(__assign({ maxWidth: 140 }, colDef), { cellRendererParams: __assign({ singleClickEdit: true }, colDef.cellRendererParams) }), __assign({ editor: GridFormMessage }, props));
3432
+ return GridCell(__assign(__assign({}, colDef), { cellRendererParams: __assign({ singleClickEdit: true }, colDef.cellRendererParams) }), __assign({ editor: GridFormMessage }, props));
3414
3433
  };
3415
3434
 
3416
3435
  // Unique ID creation requires a high quality random # generator. In the browser we therefore
@@ -3531,9 +3550,7 @@ var GridFormTextArea = function (_props) {
3531
3550
  return popoverWrapper(jsxRuntime.jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_b = props.width) !== null && _b !== void 0 ? _b : 240 } }, { children: jsxRuntime.jsx(TextAreaInput, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), inputProps: { placeholder: props.placeholder } }) })));
3532
3551
  };
3533
3552
 
3534
- var GridPopoverTextArea = function (colDef, params) {
3535
- return GridCell(__assign({ maxWidth: 260 }, colDef), __assign({ editor: GridFormTextArea }, params));
3536
- };
3553
+ var GridPopoverTextArea = function (colDef, params) { return GridCell(colDef, __assign({ editor: GridFormTextArea }, params)); };
3537
3554
 
3538
3555
  var GridFormTextInput = function (_props) {
3539
3556
  var _a;
@@ -3578,7 +3595,12 @@ var GridFormTextInput = function (_props) {
3578
3595
  });
3579
3596
  }); }, [invalid, value, initValue, props]);
3580
3597
  var _c = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _c.popoverWrapper, triggerSave = _c.triggerSave;
3581
- return popoverWrapper(jsxRuntime.jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_a = props.width) !== null && _a !== void 0 ? _a : 240 }, className: "FormTest" }, { children: jsxRuntime.jsx(TextInputFormatted, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), formatted: props.units, inputProps: {
3598
+ return popoverWrapper(jsxRuntime.jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_a = props.width) !== null && _a !== void 0 ? _a : 240 }, className: "FormTest" }, { children: jsxRuntime.jsx(TextInputFormatted, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), formatted: props.units, onMouseEnter: function (e) {
3599
+ if (document.activeElement != e.currentTarget) {
3600
+ e.currentTarget.focus();
3601
+ e.currentTarget.selectionStart = e.currentTarget.value.length;
3602
+ }
3603
+ }, inputProps: {
3582
3604
  style: { width: "100%" },
3583
3605
  placeholder: props.placeholder,
3584
3606
  onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -3588,15 +3610,38 @@ var GridFormTextInput = function (_props) {
3588
3610
  };
3589
3611
 
3590
3612
  var GridPopoverTextInput = function (colDef, params) {
3591
- return GridCell(__assign({ maxWidth: 140 }, colDef), __assign({ editor: GridFormTextInput }, params));
3613
+ return GridCell(colDef, __assign({ editor: GridFormTextInput }, params));
3592
3614
  };
3593
3615
 
3594
3616
  var GridSubComponentTextArea = function (props) {
3595
- var _a = react.useState(""), value = _a[0], setValue = _a[1];
3617
+ var value = props.value, setValue = props.setValue, setValid = props.setValid, triggerSave = props.triggerSave;
3618
+ var validate = react.useCallback(function (value) {
3619
+ if (props.required && value.length === 0) {
3620
+ return "Some text is required";
3621
+ }
3622
+ if (props.maxlength && value.length > props.maxlength) {
3623
+ return "Text must be no longer than ".concat(props.maxlength, " characters");
3624
+ }
3625
+ if (props.validate) {
3626
+ return props.validate(value);
3627
+ }
3628
+ return null;
3629
+ }, [props]);
3596
3630
  react.useEffect(function () {
3597
- props.setValue(value);
3598
- }, [props, value]);
3599
- return (jsxRuntime.jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsxRuntime.jsx("textarea", { autoFocus: true, maxLength: 10000, spellCheck: true, className: "free-text-input", onChange: function (e) { return setValue(e.target.value); }, defaultValue: value }) })));
3631
+ setValid(validate(value) == null);
3632
+ }, [setValid, validate, value]);
3633
+ return (jsxRuntime.jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsxRuntime.jsx(TextInputFormatted, { className: "free-text-input", value: value, onMouseEnter: function (e) {
3634
+ if (document.activeElement != e.currentTarget) {
3635
+ e.currentTarget.focus();
3636
+ e.currentTarget.selectionStart = e.currentTarget.value.length;
3637
+ }
3638
+ }, onChange: function (e) { return setValue(e.target.value); }, error: validate(value), inputProps: {
3639
+ autoFocus: true,
3640
+ placeholder: props.placeholder,
3641
+ onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
3642
+ return [2 /*return*/, e.key === "Enter" && triggerSave().then()];
3643
+ }); }); }
3644
+ } }) })));
3600
3645
  };
3601
3646
 
3602
3647
  var css_248z = ".ActionButton{align-items:center;display:flex}.ActionButton .LuiIcon{margin:0 4px!important}.ActionButton-minimalArea{position:relative}.ActionButton-minimalAreaDisplay{position:absolute}.ActionButton-minimalAreaExpand{visibility:hidden}.ActionButton-inProgress{background-color:#e2f3f7!important;color:#007198!important;cursor:progress}.ActionButton-inProgress svg *{fill:#0000!important}";