@likec4/diagram 1.50.0 → 1.52.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.
@@ -6,9 +6,9 @@ import { Stack, VisuallyHidden, UnstyledButton, ThemeIcon, Group, Highlight, Bad
6
6
  import * as m from 'motion/react-m';
7
7
  import { memo, useRef, useMemo } from 'react';
8
8
  import { first } from 'remeda';
9
- import { useCurrentViewId } from '../../hooks/useCurrentView.js';
10
9
  import { useLikeC4Model } from '../../hooks/useLikeC4Model.js';
11
- import { useNormalizedSearch, useSearchActor } from '../hooks.js';
10
+ import { useNormalizedSearch } from '../hooks.js';
11
+ import { useSearchContext } from '../SearchContext.js';
12
12
  import { emptyBoX, focusable, buttonsva } from './_shared.css.js';
13
13
  import { moveFocusToSearchInput, queryAllFocusable, centerY } from './utils.js';
14
14
  import { viewButton } from './ViewsColumn.css.js';
@@ -17,7 +17,7 @@ import IconZoomScan from '../../node_modules/.pnpm/@tabler_icons-react@3.36.1_re
17
17
 
18
18
  const NothingFound = () => /* @__PURE__ */ jsx(Box, { className: emptyBoX, children: "Nothing found" });
19
19
  const useFoundViews = () => {
20
- const currentViewId = useCurrentViewId();
20
+ const { currentViewId } = useSearchContext();
21
21
  const likec4model = useLikeC4Model();
22
22
  const search = useNormalizedSearch();
23
23
  return useMemo(() => {
@@ -79,7 +79,7 @@ const ViewsColumn = memo(() => {
79
79
  ViewButton,
80
80
  {
81
81
  view,
82
- currentViewId,
82
+ currentViewId: currentViewId ?? "",
83
83
  search,
84
84
  tabIndex: i === 0 ? 0 : -1
85
85
  }
@@ -90,15 +90,11 @@ const ViewsColumn = memo(() => {
90
90
  });
91
91
  const btn = buttonsva();
92
92
  function ViewButton({ className, view, loop = false, search, focusOnElement, currentViewId, ...props }) {
93
- const searchActorRef = useSearchActor();
93
+ const ctx = useSearchContext();
94
94
  const nextViewId = view.id;
95
95
  const isCurrentView = nextViewId === currentViewId;
96
96
  const navigate = () => {
97
- searchActorRef.send({
98
- type: "navigate.to",
99
- viewId: nextViewId,
100
- focusOnElement
101
- });
97
+ ctx.navigateTo(nextViewId, focusOnElement);
102
98
  };
103
99
  return /* @__PURE__ */ jsxs(
104
100
  UnstyledButton,
@@ -1,5 +1,3 @@
1
- import { SearchActorRef } from './searchActor';
2
- export declare function useSearchActor(): SearchActorRef;
3
1
  export declare function useSearch(): [string, (search: string) => void];
4
2
  export declare function useNormalizedSearch(): string;
5
3
  export declare function useUpdateSearch(): (search: string) => void;
@@ -1,41 +1,15 @@
1
- import { useSelector } from '@xstate/react';
2
1
  import { useCallback, useDeferredValue } from 'react';
3
- import { useSearchActorRef } from '../hooks/useSearchActor.js';
2
+ import { useSearchContext } from './SearchContext.js';
4
3
 
5
- function useSearchActor() {
6
- const searchActorRef = useSearchActorRef();
7
- if (!searchActorRef) {
8
- throw new Error("Search actor not found");
9
- }
10
- return searchActorRef;
11
- }
12
- const selectSearchValue = (s) => s.context.searchValue;
13
- function useSearch() {
14
- const searchActorRef = useSearchActor();
15
- const searchValue = useSelector(searchActorRef, selectSearchValue);
16
- const updateSearch = useCallback((search) => {
17
- searchActorRef.send({ type: "change.search", search });
18
- }, [searchActorRef]);
19
- return [searchValue, updateSearch];
20
- }
21
- const selectNormalizedSearchValue = (s) => {
22
- let v = selectSearchValue(s);
23
- if (v === "") return v;
24
- v = v.trim().toLowerCase();
25
- if (v.startsWith("#") && v.length <= 2) {
26
- return "";
27
- }
28
- return v.length > 1 ? v : "";
29
- };
30
4
  function useNormalizedSearch() {
31
- const searchActorRef = useSearchActor();
32
- return useDeferredValue(useSelector(searchActorRef, selectNormalizedSearchValue));
5
+ const ctx = useSearchContext();
6
+ return useDeferredValue(ctx.normalizedSearch);
33
7
  }
34
8
  function useUpdateSearch() {
35
- const searchActorRef = useSearchActor();
9
+ const { setSearchValue } = useSearchContext();
36
10
  return useCallback((search) => {
37
- searchActorRef.send({ type: "change.search", search });
38
- }, [searchActorRef]);
11
+ setSearchValue(search);
12
+ }, [setSearchValue]);
39
13
  }
40
14
 
41
- export { useNormalizedSearch, useSearch, useSearchActor, useUpdateSearch };
15
+ export { useNormalizedSearch, useUpdateSearch };