@jsenv/navi 0.18.10 → 0.18.12

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.
@@ -1,6 +1,6 @@
1
1
  import { installImportMetaCss } from "./jsenv_navi_side_effects.js";
2
2
  import { isValidElement, createContext, toChildArray, render, createRef, cloneElement } from "preact";
3
- import { useErrorBoundary, useLayoutEffect, useEffect, useCallback, useRef, useState, useContext, useMemo, useImperativeHandle, useId } from "preact/hooks";
3
+ import { useErrorBoundary, useLayoutEffect, useEffect, useMemo, useRef, useState, useCallback, useContext, useImperativeHandle, useId } from "preact/hooks";
4
4
  import { jsxs, jsx, Fragment } from "preact/jsx-runtime";
5
5
  import { signal, effect, computed, batch, useSignal } from "@preact/signals";
6
6
  import { createIterableWeakSet, mergeOneStyle, stringifyStyle, createPubSub, mergeTwoStyles, normalizeStyles, createGroupTransitionController, getElementSignature, getBorderRadius, preventIntermediateScrollbar, createOpacityTransition, findBefore, findAfter, createValueEffect, getVisuallyVisibleInfo, getFirstVisuallyVisibleAncestor, allowWheelThrough, resolveCSSColor, createStyleController, visibleRectEffect, pickPositionRelativeTo, getBorderSizes, getPaddingSizes, hasCSSSizeUnit, resolveCSSSize, activeElementSignal, canInterceptKeys, initFocusGroup, elementIsFocusable, pickLightOrDark, resolveColorLuminance, dragAfterThreshold, getScrollContainer, stickyAsRelativeCoords, createDragToMoveGestureController, getDropTargetInfo, setStyles, useActiveElement } from "@jsenv/dom";
@@ -2402,6 +2402,110 @@ const useRunOnMount = (action, Component) => {
2402
2402
  }, []);
2403
2403
  };
2404
2404
 
2405
+ const addIntoArray = (array, ...valuesToAdd) => {
2406
+ if (valuesToAdd.length === 1) {
2407
+ const [valueToAdd] = valuesToAdd;
2408
+ const arrayWithThisValue = [];
2409
+ for (const value of array) {
2410
+ if (value === valueToAdd) {
2411
+ return array;
2412
+ }
2413
+ arrayWithThisValue.push(value);
2414
+ }
2415
+ arrayWithThisValue.push(valueToAdd);
2416
+ return arrayWithThisValue;
2417
+ }
2418
+
2419
+ const existingValueSet = new Set();
2420
+ const arrayWithTheseValues = [];
2421
+ for (const existingValue of array) {
2422
+ arrayWithTheseValues.push(existingValue);
2423
+ existingValueSet.add(existingValue);
2424
+ }
2425
+ let hasNewValues = false;
2426
+ for (const valueToAdd of valuesToAdd) {
2427
+ if (existingValueSet.has(valueToAdd)) {
2428
+ continue;
2429
+ }
2430
+ arrayWithTheseValues.push(valueToAdd);
2431
+ hasNewValues = true;
2432
+ }
2433
+ return hasNewValues ? arrayWithTheseValues : array;
2434
+ };
2435
+
2436
+ const removeFromArray = (array, ...valuesToRemove) => {
2437
+ if (valuesToRemove.length === 1) {
2438
+ const [valueToRemove] = valuesToRemove;
2439
+ const arrayWithoutThisValue = [];
2440
+ let found = false;
2441
+ for (const value of array) {
2442
+ if (value === valueToRemove) {
2443
+ found = true;
2444
+ continue;
2445
+ }
2446
+ arrayWithoutThisValue.push(value);
2447
+ }
2448
+ if (!found) {
2449
+ return array;
2450
+ }
2451
+ return arrayWithoutThisValue;
2452
+ }
2453
+
2454
+ const valuesToRemoveSet = new Set(valuesToRemove);
2455
+ const arrayWithoutTheseValues = [];
2456
+ let hasRemovedValues = false;
2457
+ for (const value of array) {
2458
+ if (valuesToRemoveSet.has(value)) {
2459
+ hasRemovedValues = true;
2460
+ continue;
2461
+ }
2462
+ arrayWithoutTheseValues.push(value);
2463
+ }
2464
+ return hasRemovedValues ? arrayWithoutTheseValues : array;
2465
+ };
2466
+
2467
+ const useArraySignalMembership = (...args) => {
2468
+ if (args.length < 2) {
2469
+ throw new Error(
2470
+ "useArraySignalMembership requires at least 2 arguments: [arraySignal, id]",
2471
+ );
2472
+ }
2473
+
2474
+ return useMemo(() => {
2475
+ const [isMember, add, remove] = arraySignalMembership(...args);
2476
+ return [isMember(), add, remove];
2477
+ }, args);
2478
+ };
2479
+
2480
+ const arraySignalMembership = (...args) => {
2481
+ if (args.length < 2) {
2482
+ throw new Error(
2483
+ "arraySignalMemberShip requires at least 2 arguments: [arraySignal, id]",
2484
+ );
2485
+ }
2486
+ const [arraySignal, id] = args;
2487
+
2488
+ const isMember = () => {
2489
+ const array = arraySignal.peek();
2490
+ const is = array.includes(id);
2491
+ return is;
2492
+ };
2493
+
2494
+ const add = () => {
2495
+ const arrayWithId = addIntoArray(arraySignal.peek(), id);
2496
+ arraySignal.value = arrayWithId;
2497
+ return arrayWithId;
2498
+ };
2499
+
2500
+ const remove = () => {
2501
+ const arrayWithoutId = removeFromArray(arraySignal.peek(), id);
2502
+ arraySignal.value = arrayWithoutId;
2503
+ return arrayWithoutId;
2504
+ };
2505
+
2506
+ return [isMember, add, remove];
2507
+ };
2508
+
2405
2509
  const localStorageSignal = (key) => {
2406
2510
  const initialValue = localStorage.getItem(key);
2407
2511
 
@@ -4852,87 +4956,6 @@ const isProps = (value) => {
4852
4956
  return value !== null && typeof value === "object";
4853
4957
  };
4854
4958
 
4855
- const addIntoArray = (array, ...valuesToAdd) => {
4856
- if (valuesToAdd.length === 1) {
4857
- const [valueToAdd] = valuesToAdd;
4858
- const arrayWithThisValue = [];
4859
- for (const value of array) {
4860
- if (value === valueToAdd) {
4861
- return array;
4862
- }
4863
- arrayWithThisValue.push(value);
4864
- }
4865
- arrayWithThisValue.push(valueToAdd);
4866
- return arrayWithThisValue;
4867
- }
4868
-
4869
- const existingValueSet = new Set();
4870
- const arrayWithTheseValues = [];
4871
- for (const existingValue of array) {
4872
- arrayWithTheseValues.push(existingValue);
4873
- existingValueSet.add(existingValue);
4874
- }
4875
- let hasNewValues = false;
4876
- for (const valueToAdd of valuesToAdd) {
4877
- if (existingValueSet.has(valueToAdd)) {
4878
- continue;
4879
- }
4880
- arrayWithTheseValues.push(valueToAdd);
4881
- hasNewValues = true;
4882
- }
4883
- return hasNewValues ? arrayWithTheseValues : array;
4884
- };
4885
-
4886
- const removeFromArray = (array, ...valuesToRemove) => {
4887
- if (valuesToRemove.length === 1) {
4888
- const [valueToRemove] = valuesToRemove;
4889
- const arrayWithoutThisValue = [];
4890
- let found = false;
4891
- for (const value of array) {
4892
- if (value === valueToRemove) {
4893
- found = true;
4894
- continue;
4895
- }
4896
- arrayWithoutThisValue.push(value);
4897
- }
4898
- if (!found) {
4899
- return array;
4900
- }
4901
- return arrayWithoutThisValue;
4902
- }
4903
-
4904
- const valuesToRemoveSet = new Set(valuesToRemove);
4905
- const arrayWithoutTheseValues = [];
4906
- let hasRemovedValues = false;
4907
- for (const value of array) {
4908
- if (valuesToRemoveSet.has(value)) {
4909
- hasRemovedValues = true;
4910
- continue;
4911
- }
4912
- arrayWithoutTheseValues.push(value);
4913
- }
4914
- return hasRemovedValues ? arrayWithoutTheseValues : array;
4915
- };
4916
-
4917
- const useArraySignalMembership = (arraySignal, id) => {
4918
- const array = arraySignal.value;
4919
- const isMember = array.includes(id);
4920
-
4921
- const add = useCallback(() => {
4922
- const arrayWithId = addIntoArray(arraySignal.peek(), id);
4923
- arraySignal.value = arrayWithId;
4924
- return arrayWithId;
4925
- }, []);
4926
-
4927
- const remove = useCallback(() => {
4928
- const arrayWithoutId = removeFromArray(arraySignal.peek(), id);
4929
- arraySignal.value = arrayWithoutId;
4930
- return arrayWithoutId;
4931
- }, []);
4932
-
4933
- return [isMember, add, remove];
4934
- };
4935
-
4936
4959
  /**
4937
4960
  * Creates a signal that stays synchronized with an external value,
4938
4961
  * only updating the signal when the value actually changes.
@@ -30294,5 +30317,5 @@ const UserSvg = () => jsx("svg", {
30294
30317
  })
30295
30318
  });
30296
30319
 
30297
- 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, Meter, Paragraph, Radio, RadioList, Route, RouteLink, Routes, RowNumberCol, RowNumberTableCell, SINGLE_SPACE_CONSTRAINT, SVGMaskOverlay, SearchSvg, Select, SelectionContext, Separator, SettingsSvg, StarSvg, Stat, SummaryMarker, Svg, Tab, TabList, Table, TableCell, Tbody, Text, Thead, Title, Tr, UITransition, UserSvg, ViewportLayout, actionIntegratedVia, actionRunEffect, addCustomMessage, compareTwoJsValues, createAction, createAvailableConstraint, createRequestCanceller, createSelectionKeyboardShortcuts, enableDebugActions, enableDebugOnDocumentLoading, forwardActionRequested, installCustomConstraintValidation, isCellSelected, isColumnSelected, isRowSelected, localStorageSignal, navBack, navForward, navTo, openCallout, rawUrlPart, reload, removeCustomMessage, requestAction, rerunActions, resource, route, routeAction, 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 };
30320
+ 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, Meter, Paragraph, Radio, RadioList, Route, RouteLink, Routes, RowNumberCol, RowNumberTableCell, SINGLE_SPACE_CONSTRAINT, SVGMaskOverlay, SearchSvg, Select, SelectionContext, Separator, SettingsSvg, StarSvg, Stat, SummaryMarker, Svg, Tab, TabList, Table, TableCell, Tbody, Text, Thead, Title, Tr, UITransition, UserSvg, ViewportLayout, actionIntegratedVia, actionRunEffect, addCustomMessage, arraySignalMembership, compareTwoJsValues, createAction, createAvailableConstraint, createRequestCanceller, createSelectionKeyboardShortcuts, enableDebugActions, enableDebugOnDocumentLoading, forwardActionRequested, installCustomConstraintValidation, isCellSelected, isColumnSelected, isRowSelected, localStorageSignal, navBack, navForward, navTo, openCallout, rawUrlPart, reload, removeCustomMessage, requestAction, rerunActions, resource, route, routeAction, 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 };
30298
30321
  //# sourceMappingURL=jsenv_navi.js.map