@linzjs/step-ag-grid 2.3.0 → 2.4.0

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: {
@@ -3000,6 +3000,22 @@ var GridFormDropDown = function (_props) {
3000
3000
  })] }) }))] }));
3001
3001
  };
3002
3002
 
3003
+ var GridSubComponentContext = react.createContext({
3004
+ value: "GridSubComponentContext value no context",
3005
+ setValue: function () {
3006
+ console.error("GridSubComponentContext setValue no context");
3007
+ },
3008
+ setValid: function () {
3009
+ console.error("GridSubComponentContext setValid no context");
3010
+ },
3011
+ triggerSave: function () { return __awaiter(void 0, void 0, void 0, function () {
3012
+ return __generator(this, function (_a) {
3013
+ console.error("GridSubComponentContext triggerSave no context");
3014
+ return [2 /*return*/];
3015
+ });
3016
+ }); }
3017
+ });
3018
+
3003
3019
  var GridFormMultiSelect = function (props) {
3004
3020
  var selectedRows = props.selectedRows;
3005
3021
  var initialiseValues = react.useMemo(function () { return props.initialSelectedValues && props.initialSelectedValues(selectedRows); }, [props, selectedRows]);
@@ -3126,10 +3142,8 @@ var GridFormMultiSelect = function (props) {
3126
3142
  }
3127
3143
  }, onChange: function () {
3128
3144
  /*Do nothing, change handled by menuItem*/
3129
- } }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3130
- return item.subComponent &&
3131
- item.subComponent({
3132
- ref: ref,
3145
+ } }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3146
+ return item.subComponent && (jsxRuntime.jsx(GridSubComponentContext.Provider, __assign({ value: {
3133
3147
  value: subSelectedValues["".concat(item.value)],
3134
3148
  setValue: function (value) {
3135
3149
  subSelectedValues["".concat(item.value)] = value;
@@ -3139,7 +3153,7 @@ var GridFormMultiSelect = function (props) {
3139
3153
  subComponentIsValid.current["".concat(item.value)] = valid;
3140
3154
  },
3141
3155
  triggerSave: triggerSave
3142
- });
3156
+ } }, { children: jsxRuntime.jsx(item.subComponent, {}) })));
3143
3157
  } }), "".concat(item.value, "_subcomponent")))] }, "".concat(index)));
3144
3158
  }) }))] }) })));
3145
3159
  };
@@ -3515,8 +3529,8 @@ var GridFormTextArea = function (_props) {
3515
3529
  if (props.required && value.length == 0) {
3516
3530
  return "Some text is required";
3517
3531
  }
3518
- if (props.maxlength && value.length > props.maxlength) {
3519
- return "Text must be no longer than ".concat(props.maxlength, " characters");
3532
+ if (props.maxLength && value.length > props.maxLength) {
3533
+ return "Text must be no longer than ".concat(props.maxLength, " characters");
3520
3534
  }
3521
3535
  if (props.validate) {
3522
3536
  return props.validate(value);
@@ -3562,8 +3576,8 @@ var GridFormTextInput = function (_props) {
3562
3576
  if (props.required && trimmedValue.length == 0) {
3563
3577
  return "Some text is required";
3564
3578
  }
3565
- if (props.maxlength && trimmedValue.length > props.maxlength) {
3566
- return "Text must be no longer than ".concat(props.maxlength, " characters");
3579
+ if (props.maxLength && trimmedValue.length > props.maxLength) {
3580
+ return "Text must be no longer than ".concat(props.maxLength, " characters");
3567
3581
  }
3568
3582
  if (props.validate) {
3569
3583
  return props.validate(trimmedValue, props.data);
@@ -3614,13 +3628,24 @@ var GridPopoverTextInput = function (colDef, params) {
3614
3628
  };
3615
3629
 
3616
3630
  var GridSubComponentTextArea = function (props) {
3617
- var value = props.value, setValue = props.setValue, setValid = props.setValid, triggerSave = props.triggerSave;
3631
+ var _a = react.useContext(GridSubComponentContext), value = _a.value, setValue = _a.setValue, setValid = _a.setValid, triggerSave = _a.triggerSave;
3632
+ // If is not initialised yet as it's just been created then set the default value
3633
+ react.useEffect(function () {
3634
+ if (value == null)
3635
+ setValue(props.defaultValue);
3636
+ }, [props.defaultValue, setValue, value]);
3618
3637
  var validate = react.useCallback(function (value) {
3638
+ if (value == null)
3639
+ return null;
3640
+ // This can happen because subcomponent is invoked without type safety
3641
+ if (typeof value !== "string") {
3642
+ console.error("Value is not a string", value);
3643
+ }
3619
3644
  if (props.required && value.length === 0) {
3620
3645
  return "Some text is required";
3621
3646
  }
3622
- if (props.maxlength && value.length > props.maxlength) {
3623
- return "Text must be no longer than ".concat(props.maxlength, " characters");
3647
+ if (props.maxLength && value.length > props.maxLength) {
3648
+ return "Text must be no longer than ".concat(props.maxLength, " characters");
3624
3649
  }
3625
3650
  if (props.validate) {
3626
3651
  return props.validate(value);
@@ -3628,7 +3653,7 @@ var GridSubComponentTextArea = function (props) {
3628
3653
  return null;
3629
3654
  }, [props]);
3630
3655
  react.useEffect(function () {
3631
- setValid(validate(value) == null);
3656
+ setValid(value != null && validate(value) == null);
3632
3657
  }, [setValid, validate, value]);
3633
3658
  return (jsxRuntime.jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsxRuntime.jsx(TextInputFormatted, { className: "free-text-input", value: value, onMouseEnter: function (e) {
3634
3659
  if (document.activeElement != e.currentTarget) {