@jsenv/navi 0.17.0 → 0.17.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.
@@ -4858,6 +4858,15 @@ window.addEventListener("unhandledrejection", (event) => {
4858
4858
  }
4859
4859
  });
4860
4860
 
4861
+ const useCancelPrevious = () => {
4862
+ const cancellerRef = useRef();
4863
+ if (!cancellerRef.current) {
4864
+ cancellerRef.current = createRequestCanceller();
4865
+ }
4866
+ const canceller = cancellerRef.current;
4867
+ return canceller;
4868
+ };
4869
+
4861
4870
  /**
4862
4871
  * Merges a component's base className with className received from props.
4863
4872
  *
@@ -12083,11 +12092,10 @@ const renderActionableComponent = (props, {
12083
12092
  }) => {
12084
12093
  const {
12085
12094
  action,
12086
- liveAction,
12087
12095
  shortcuts
12088
12096
  } = props;
12089
12097
  const formContext = useContext(FormContext);
12090
- const hasActionProps = Boolean(action || liveAction || shortcuts && shortcuts.length > 0);
12098
+ const hasActionProps = Boolean(action || shortcuts && shortcuts.length > 0);
12091
12099
  const considerInsideForm = Boolean(formContext);
12092
12100
  if (hasActionProps && WithAction) {
12093
12101
  if (considerInsideForm && WithActionInsideForm) {
@@ -15575,29 +15583,67 @@ const MAX_CONSTRAINT = {
15575
15583
  const listenInputValue = (
15576
15584
  input,
15577
15585
  callback,
15578
- { waitForChange = false } = {},
15586
+ { waitForChange = false, debounce = 0 } = {},
15579
15587
  ) => {
15580
15588
  if (waitForChange) {
15581
15589
  return listenInputValueChange(input, callback);
15582
15590
  }
15583
15591
  const [teardown, addTeardown] = createPubSub();
15584
15592
  let currentValue = input.value;
15585
-
15586
15593
  let timeout;
15594
+ let debounceTimeout;
15595
+
15587
15596
  const onAsyncEvent = (e) => {
15588
15597
  timeout = setTimeout(() => {
15589
15598
  onEvent(e);
15590
15599
  }, 0);
15591
15600
  };
15592
- const onEvent = (e) => {
15593
- clearTimeout(timeout);
15594
- const value = input.value;
15595
- if (value === currentValue) {
15596
- return;
15597
- }
15598
- currentValue = value;
15599
- callback(e);
15600
- };
15601
+
15602
+ let onEvent;
15603
+ if (debounce) {
15604
+ onEvent = (e, { skipDebounce } = {}) => {
15605
+ clearTimeout(timeout);
15606
+ clearTimeout(debounceTimeout);
15607
+
15608
+ const value = input.value;
15609
+ if (value === currentValue) {
15610
+ return;
15611
+ }
15612
+
15613
+ if (skipDebounce) {
15614
+ currentValue = value;
15615
+ callback(e);
15616
+ } else {
15617
+ debounceTimeout = setTimeout(() => {
15618
+ currentValue = value;
15619
+ callback(e);
15620
+ }, debounce);
15621
+ }
15622
+ };
15623
+ // no need to wait for change events (blur, enter key)
15624
+ // we consider this as strong interactions requesting an immediate response
15625
+ const stop = listenInputValueChange(input, (e) => {
15626
+ onEvent(e, { skipDebounce: true });
15627
+ });
15628
+ addTeardown(() => {
15629
+ stop();
15630
+ });
15631
+ } else {
15632
+ onEvent = (e) => {
15633
+ clearTimeout(timeout);
15634
+ const value = input.value;
15635
+ if (value === currentValue) {
15636
+ return;
15637
+ }
15638
+ currentValue = value;
15639
+ callback(e);
15640
+ };
15641
+ // Autocomplete, programmatic changes, form restoration
15642
+ input.addEventListener("change", onEvent);
15643
+ addTeardown(() => {
15644
+ input.removeEventListener("change", onEvent);
15645
+ });
15646
+ }
15601
15647
 
15602
15648
  // Standard user input (typing)
15603
15649
  input.addEventListener("input", onEvent);
@@ -15605,12 +15651,6 @@ const listenInputValue = (
15605
15651
  input.removeEventListener("input", onEvent);
15606
15652
  });
15607
15653
 
15608
- // Autocomplete, programmatic changes, form restoration
15609
- input.addEventListener("change", onEvent);
15610
- addTeardown(() => {
15611
- input.removeEventListener("change", onEvent);
15612
- });
15613
-
15614
15654
  // Form reset - need to check the form
15615
15655
  const form = input.form;
15616
15656
  if (form) {
@@ -16417,6 +16457,7 @@ const installCustomConstraintValidation = (
16417
16457
  if (!elementWithAction) {
16418
16458
  break request_on_input_value_change;
16419
16459
  }
16460
+ const closestElementWithActionAttr = element.closest("[data-action]");
16420
16461
  const stop = listenInputValue(
16421
16462
  element,
16422
16463
  (e) => {
@@ -16426,7 +16467,16 @@ const installCustomConstraintValidation = (
16426
16467
  });
16427
16468
  },
16428
16469
  {
16429
- waitForChange: !element.closest("[data-live-action]"),
16470
+ waitForChange: closestElementWithActionAttr.hasAttribute(
16471
+ "data-action-after-change",
16472
+ ),
16473
+ debounce: closestElementWithActionAttr.hasAttribute(
16474
+ "data-action-debounce",
16475
+ )
16476
+ ? parseFloat(
16477
+ closestElementWithActionAttr.getAttribute("data-action-debounce"),
16478
+ )
16479
+ : undefined,
16430
16480
  },
16431
16481
  );
16432
16482
  addTeardown(() => {
@@ -18800,8 +18850,8 @@ const useUIStateController = (
18800
18850
  ) => {
18801
18851
  const parentUIStateController = useContext(ParentUIStateControllerContext);
18802
18852
  const formContext = useContext(FormContext);
18803
- const { id, name, onUIStateChange, action, liveAction } = props;
18804
- const uncontrolled = !formContext && !action && !liveAction;
18853
+ const { id, name, onUIStateChange, action } = props;
18854
+ const uncontrolled = !formContext && !action;
18805
18855
  const [navState, setNavState] = useNavState$1(id);
18806
18856
 
18807
18857
  const uiStateControllerRef = useRef();
@@ -22971,7 +23021,8 @@ const InputTextualWithAction = props => {
22971
23021
  const uiState = useContext(UIStateContext);
22972
23022
  const {
22973
23023
  action,
22974
- liveAction,
23024
+ actionDebounce,
23025
+ actionAfterChange,
22975
23026
  loading,
22976
23027
  onCancel,
22977
23028
  onActionPrevented,
@@ -22985,7 +23036,7 @@ const InputTextualWithAction = props => {
22985
23036
  } = props;
22986
23037
  const defaultRef = useRef();
22987
23038
  const ref = props.ref || defaultRef;
22988
- const [boundAction] = useActionBoundToOneParam(liveAction || action, uiState);
23039
+ const [boundAction] = useActionBoundToOneParam(action, uiState);
22989
23040
  const {
22990
23041
  loading: actionLoading
22991
23042
  } = useActionStatus(boundAction);
@@ -23026,7 +23077,8 @@ const InputTextualWithAction = props => {
23026
23077
  });
23027
23078
  return jsx(InputTextualBasic, {
23028
23079
  "data-action": boundAction.name,
23029
- "data-live-action": liveAction ? "" : undefined,
23080
+ "data-action-debounce": actionDebounce,
23081
+ "data-action-after-change": actionAfterChange ? "" : undefined,
23030
23082
  ...rest,
23031
23083
  ref: ref,
23032
23084
  loading: loading || actionLoading
@@ -28865,5 +28917,5 @@ const UserSvg = () => jsx("svg", {
28865
28917
  })
28866
28918
  });
28867
28919
 
28868
- export { ActionRenderer, ActiveKeyboardShortcuts, Address, BadgeCount, Box, Button, ButtonCopyToClipboard, Caption, CheckSvg, Checkbox, CheckboxList, Code, Col, Colgroup, ConstructionSvg, Details, DialogLayout, Editable, ErrorBoundaryContext, ExclamationSvg, EyeClosedSvg, EyeSvg, Form, Group, HeartSvg, HomeSvg, Icon, Image, Input, Label, Link, LinkAnchorSvg, LinkBlankTargetSvg, MessageBox, Paragraph, Radio, RadioList, Route, RouteLink, Routes, RowNumberCol, RowNumberTableCell, SINGLE_SPACE_CONSTRAINT, SVGMaskOverlay, SearchSvg, Select, SelectionContext, Separator, SettingsSvg, StarSvg, SummaryMarker, Svg, Tab, TabList, Table, TableCell, Tbody, Text, Thead, Title, Tr, UITransition, UserSvg, ViewportLayout, actionIntegratedVia, addCustomMessage, clearAllRoutes, compareTwoJsValues, createAction, createAvailableConstraint, createRequestCanceller, createSelectionKeyboardShortcuts, enableDebugActions, enableDebugOnDocumentLoading, forwardActionRequested, installCustomConstraintValidation, isCellSelected, isColumnSelected, isRowSelected, localStorageSignal, navBack, navForward, navTo, openCallout, rawUrlPart, reload, removeCustomMessage, requestAction, rerunActions, resource, setBaseUrl, setupRoutes, stateSignal, stopLoad, stringifyTableSelectionValue, updateActions, useActionData, useActionStatus, useArraySignalMembership, useCalloutClose, useCellsAndColumns, useConstraintValidityState, useDependenciesDiff, useDocumentResource, useDocumentState, useDocumentUrl, useEditionController, useFocusGroup, useKeyboardShortcuts, useMatchingRouteInfo, useNavState$1 as useNavState, useRouteStatus, useRunOnMount, useSelectableElement, useSelectionController, useSignalSync, useStateArray, useTitleLevel, useUrlSearchParam, valueInLocalStorage };
28920
+ export { ActionRenderer, ActiveKeyboardShortcuts, Address, BadgeCount, Box, Button, ButtonCopyToClipboard, Caption, CheckSvg, Checkbox, CheckboxList, Code, Col, Colgroup, ConstructionSvg, Details, DialogLayout, Editable, ErrorBoundaryContext, ExclamationSvg, EyeClosedSvg, EyeSvg, Form, Group, HeartSvg, HomeSvg, Icon, Image, Input, Label, Link, LinkAnchorSvg, LinkBlankTargetSvg, MessageBox, Paragraph, Radio, RadioList, Route, RouteLink, Routes, RowNumberCol, RowNumberTableCell, SINGLE_SPACE_CONSTRAINT, SVGMaskOverlay, SearchSvg, Select, SelectionContext, Separator, SettingsSvg, StarSvg, SummaryMarker, Svg, Tab, TabList, Table, TableCell, Tbody, Text, Thead, Title, Tr, UITransition, UserSvg, ViewportLayout, actionIntegratedVia, addCustomMessage, clearAllRoutes, compareTwoJsValues, createAction, createAvailableConstraint, createRequestCanceller, createSelectionKeyboardShortcuts, enableDebugActions, enableDebugOnDocumentLoading, forwardActionRequested, installCustomConstraintValidation, isCellSelected, isColumnSelected, isRowSelected, localStorageSignal, navBack, navForward, navTo, openCallout, rawUrlPart, reload, removeCustomMessage, requestAction, rerunActions, resource, setBaseUrl, setupRoutes, stateSignal, stopLoad, stringifyTableSelectionValue, updateActions, useActionData, useActionStatus, useArraySignalMembership, useCalloutClose, useCancelPrevious, useCellsAndColumns, useConstraintValidityState, useDependenciesDiff, useDocumentResource, useDocumentState, useDocumentUrl, useEditionController, useFocusGroup, useKeyboardShortcuts, useMatchingRouteInfo, useNavState$1 as useNavState, useRouteStatus, useRunOnMount, useSelectableElement, useSelectionController, useSignalSync, useStateArray, useTitleLevel, useUrlSearchParam, valueInLocalStorage };
28869
28921
  //# sourceMappingURL=jsenv_navi.js.map