@lapis-notes/ui 0.1.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.
Files changed (100) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE.md +4 -0
  3. package/README.md +46 -0
  4. package/dist/codemirror-autocomplete.css +223 -0
  5. package/dist/command-fuzzy-filter.d.ts +15 -0
  6. package/dist/command-fuzzy-filter.js +27 -0
  7. package/dist/components/ui/confirm-dialog/confirm-dialog.css +11 -0
  8. package/dist/components/ui/confirm-dialog/confirm-dialog.svelte +94 -0
  9. package/dist/components/ui/confirm-dialog/confirm-dialog.svelte.d.ts +18 -0
  10. package/dist/components/ui/confirm-dialog/index.d.ts +3 -0
  11. package/dist/components/ui/confirm-dialog/index.js +3 -0
  12. package/dist/components/ui/modal/index.d.ts +3 -0
  13. package/dist/components/ui/modal/index.js +3 -0
  14. package/dist/components/ui/modal/modal.css +16 -0
  15. package/dist/components/ui/modal/modal.svelte +74 -0
  16. package/dist/components/ui/modal/modal.svelte.d.ts +16 -0
  17. package/dist/components/ui/search/index.d.ts +3 -0
  18. package/dist/components/ui/search/index.js +3 -0
  19. package/dist/components/ui/search/search.css +55 -0
  20. package/dist/components/ui/search/search.svelte +54 -0
  21. package/dist/components/ui/search/search.svelte.d.ts +10 -0
  22. package/dist/components/ui/sidebar-custom/constants.d.ts +6 -0
  23. package/dist/components/ui/sidebar-custom/constants.js +6 -0
  24. package/dist/components/ui/sidebar-custom/context.svelte.d.ts +49 -0
  25. package/dist/components/ui/sidebar-custom/context.svelte.js +68 -0
  26. package/dist/components/ui/sidebar-custom/index.d.ts +26 -0
  27. package/dist/components/ui/sidebar-custom/index.js +28 -0
  28. package/dist/components/ui/sidebar-custom/sidebar-content.svelte +23 -0
  29. package/dist/components/ui/sidebar-custom/sidebar-content.svelte.d.ts +5 -0
  30. package/dist/components/ui/sidebar-custom/sidebar-custom.css +1357 -0
  31. package/dist/components/ui/sidebar-custom/sidebar-footer.svelte +23 -0
  32. package/dist/components/ui/sidebar-custom/sidebar-footer.svelte.d.ts +5 -0
  33. package/dist/components/ui/sidebar-custom/sidebar-group-action.svelte +37 -0
  34. package/dist/components/ui/sidebar-custom/sidebar-group-action.svelte.d.ts +11 -0
  35. package/dist/components/ui/sidebar-custom/sidebar-group-content.svelte +23 -0
  36. package/dist/components/ui/sidebar-custom/sidebar-group-content.svelte.d.ts +5 -0
  37. package/dist/components/ui/sidebar-custom/sidebar-group-label.svelte +37 -0
  38. package/dist/components/ui/sidebar-custom/sidebar-group-label.svelte.d.ts +11 -0
  39. package/dist/components/ui/sidebar-custom/sidebar-group.svelte +23 -0
  40. package/dist/components/ui/sidebar-custom/sidebar-group.svelte.d.ts +5 -0
  41. package/dist/components/ui/sidebar-custom/sidebar-header.svelte +23 -0
  42. package/dist/components/ui/sidebar-custom/sidebar-header.svelte.d.ts +5 -0
  43. package/dist/components/ui/sidebar-custom/sidebar-input.svelte +24 -0
  44. package/dist/components/ui/sidebar-custom/sidebar-input.svelte.d.ts +4 -0
  45. package/dist/components/ui/sidebar-custom/sidebar-inset.svelte +22 -0
  46. package/dist/components/ui/sidebar-custom/sidebar-inset.svelte.d.ts +5 -0
  47. package/dist/components/ui/sidebar-custom/sidebar-menu-action.svelte +40 -0
  48. package/dist/components/ui/sidebar-custom/sidebar-menu-action.svelte.d.ts +12 -0
  49. package/dist/components/ui/sidebar-custom/sidebar-menu-badge.svelte +23 -0
  50. package/dist/components/ui/sidebar-custom/sidebar-menu-badge.svelte.d.ts +5 -0
  51. package/dist/components/ui/sidebar-custom/sidebar-menu-button.svelte +106 -0
  52. package/dist/components/ui/sidebar-custom/sidebar-menu-button.svelte.d.ts +27 -0
  53. package/dist/components/ui/sidebar-custom/sidebar-menu-item.svelte +23 -0
  54. package/dist/components/ui/sidebar-custom/sidebar-menu-item.svelte.d.ts +5 -0
  55. package/dist/components/ui/sidebar-custom/sidebar-menu-skeleton.svelte +43 -0
  56. package/dist/components/ui/sidebar-custom/sidebar-menu-skeleton.svelte.d.ts +8 -0
  57. package/dist/components/ui/sidebar-custom/sidebar-menu-sub-button.svelte +43 -0
  58. package/dist/components/ui/sidebar-custom/sidebar-menu-sub-button.svelte.d.ts +13 -0
  59. package/dist/components/ui/sidebar-custom/sidebar-menu-sub-item.svelte +23 -0
  60. package/dist/components/ui/sidebar-custom/sidebar-menu-sub-item.svelte.d.ts +5 -0
  61. package/dist/components/ui/sidebar-custom/sidebar-menu-sub.svelte +23 -0
  62. package/dist/components/ui/sidebar-custom/sidebar-menu-sub.svelte.d.ts +5 -0
  63. package/dist/components/ui/sidebar-custom/sidebar-menu.svelte +26 -0
  64. package/dist/components/ui/sidebar-custom/sidebar-menu.svelte.d.ts +5 -0
  65. package/dist/components/ui/sidebar-custom/sidebar-nested-provider.svelte +69 -0
  66. package/dist/components/ui/sidebar-custom/sidebar-nested-provider.svelte.d.ts +16 -0
  67. package/dist/components/ui/sidebar-custom/sidebar-provider.svelte +72 -0
  68. package/dist/components/ui/sidebar-custom/sidebar-provider.svelte.d.ts +15 -0
  69. package/dist/components/ui/sidebar-custom/sidebar-rail.svelte +44 -0
  70. package/dist/components/ui/sidebar-custom/sidebar-rail.svelte.d.ts +9 -0
  71. package/dist/components/ui/sidebar-custom/sidebar-resize.svelte.d.ts +15 -0
  72. package/dist/components/ui/sidebar-custom/sidebar-resize.svelte.js +131 -0
  73. package/dist/components/ui/sidebar-custom/sidebar-separator.svelte +22 -0
  74. package/dist/components/ui/sidebar-custom/sidebar-separator.svelte.d.ts +4 -0
  75. package/dist/components/ui/sidebar-custom/sidebar-trigger.svelte +86 -0
  76. package/dist/components/ui/sidebar-custom/sidebar-trigger.svelte.d.ts +10 -0
  77. package/dist/components/ui/sidebar-custom/sidebar.svelte +102 -0
  78. package/dist/components/ui/sidebar-custom/sidebar.svelte.d.ts +11 -0
  79. package/dist/components/ui/table-dnd/index.d.ts +3 -0
  80. package/dist/components/ui/table-dnd/index.js +3 -0
  81. package/dist/components/ui/table-dnd/table-dnd-sensors.d.ts +2 -0
  82. package/dist/components/ui/table-dnd/table-dnd-sensors.js +11 -0
  83. package/dist/components/ui/table-dnd/table-dnd-utils.d.ts +29 -0
  84. package/dist/components/ui/table-dnd/table-dnd-utils.js +77 -0
  85. package/dist/components/ui/table-dnd/table-dnd.css +12 -0
  86. package/dist/components/ui/table-dnd/table-drag-grip.svelte +63 -0
  87. package/dist/components/ui/table-dnd/table-drag-grip.svelte.d.ts +17 -0
  88. package/dist/fuzzy-search.d.ts +12 -0
  89. package/dist/fuzzy-search.js +22 -0
  90. package/dist/hooks/index.d.ts +1 -0
  91. package/dist/hooks/index.js +1 -0
  92. package/dist/hooks/is-mobile.svelte.d.ts +4 -0
  93. package/dist/hooks/is-mobile.svelte.js +7 -0
  94. package/dist/index.d.ts +4 -0
  95. package/dist/index.js +4 -0
  96. package/dist/styles.css +11 -0
  97. package/dist/theme.css +89 -0
  98. package/dist/utils.d.ts +12 -0
  99. package/dist/utils.js +5 -0
  100. package/package.json +109 -0
@@ -0,0 +1,23 @@
1
+ <script lang="ts">
2
+ import { type WithElementRef } from "../../../utils.js";
3
+ import type { HTMLAttributes } from "svelte/elements";
4
+
5
+ let {
6
+ ref = $bindable(null),
7
+ children,
8
+ class: className,
9
+ ...restProps
10
+ }: WithElementRef<HTMLAttributes<HTMLLIElement>> = $props();
11
+ </script>
12
+
13
+ <li
14
+ bind:this={ref}
15
+ {...restProps}
16
+ data-ui-component="sidebar-custom"
17
+ data-ui-part="sidebar-menu-sub-item"
18
+ data-slot="sidebar-menu-sub-item"
19
+ data-sidebar="menu-sub-item"
20
+ class={className}
21
+ >
22
+ {@render children?.()}
23
+ </li>
@@ -0,0 +1,5 @@
1
+ import { type WithElementRef } from "../../../utils.js";
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+ declare const SidebarMenuSubItem: import("svelte").Component<WithElementRef<HTMLAttributes<HTMLLIElement>>, {}, "ref">;
4
+ type SidebarMenuSubItem = ReturnType<typeof SidebarMenuSubItem>;
5
+ export default SidebarMenuSubItem;
@@ -0,0 +1,23 @@
1
+ <script lang="ts">
2
+ import { type WithElementRef } from "../../../utils.js";
3
+ import type { HTMLAttributes } from "svelte/elements";
4
+
5
+ let {
6
+ ref = $bindable(null),
7
+ class: className,
8
+ children,
9
+ ...restProps
10
+ }: WithElementRef<HTMLAttributes<HTMLUListElement>> = $props();
11
+ </script>
12
+
13
+ <ul
14
+ bind:this={ref}
15
+ {...restProps}
16
+ data-ui-component="sidebar-custom"
17
+ data-ui-part="sidebar-menu-sub"
18
+ data-slot="sidebar-menu-sub"
19
+ data-sidebar="menu-sub"
20
+ class={className}
21
+ >
22
+ {@render children?.()}
23
+ </ul>
@@ -0,0 +1,5 @@
1
+ import { type WithElementRef } from "../../../utils.js";
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+ declare const SidebarMenuSub: import("svelte").Component<WithElementRef<HTMLAttributes<HTMLUListElement>>, {}, "ref">;
4
+ type SidebarMenuSub = ReturnType<typeof SidebarMenuSub>;
5
+ export default SidebarMenuSub;
@@ -0,0 +1,26 @@
1
+ <script lang="ts">
2
+ import { type WithElementRef } from "../../../utils.js";
3
+ import type { HTMLAttributes } from "svelte/elements";
4
+
5
+ let {
6
+ ref = $bindable(null),
7
+ class: className,
8
+ children,
9
+ ...restProps
10
+ }: WithElementRef<
11
+ HTMLAttributes<HTMLUListElement>,
12
+ HTMLUListElement
13
+ > = $props();
14
+ </script>
15
+
16
+ <ul
17
+ bind:this={ref}
18
+ {...restProps}
19
+ data-ui-component="sidebar-custom"
20
+ data-ui-part="sidebar-menu"
21
+ data-slot="sidebar-menu"
22
+ data-sidebar="menu"
23
+ class={className}
24
+ >
25
+ {@render children?.()}
26
+ </ul>
@@ -0,0 +1,5 @@
1
+ import { type WithElementRef } from "../../../utils.js";
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+ declare const SidebarMenu: import("svelte").Component<WithElementRef<HTMLAttributes<HTMLUListElement>, HTMLUListElement>, {}, "ref">;
4
+ type SidebarMenu = ReturnType<typeof SidebarMenu>;
5
+ export default SidebarMenu;
@@ -0,0 +1,69 @@
1
+ <script lang="ts">
2
+ import type { WithElementRef } from "bits-ui";
3
+ import { untrack } from "svelte";
4
+ import type { HTMLAttributes } from "svelte/elements";
5
+ import {
6
+ SIDEBAR_COOKIE_MAX_AGE,
7
+ SIDEBAR_COOKIE_NAME,
8
+ SIDEBAR_WIDTH,
9
+ SIDEBAR_WIDTH_ICON,
10
+ } from "./constants.js";
11
+ import { setSidebar, SidebarState } from "./context.svelte.js";
12
+ import "./sidebar-custom.css";
13
+
14
+ let {
15
+ ref = $bindable(null),
16
+ open = $bindable(true),
17
+ id,
18
+ sidebarState,
19
+ style,
20
+ initialWidth = SIDEBAR_WIDTH,
21
+ onOpenChange = () => {},
22
+ controlledOpen = false,
23
+ collapsedSize,
24
+ class: className,
25
+ children,
26
+ ...restProps
27
+ }: WithElementRef<HTMLAttributes<HTMLDivElement>> & {
28
+ open?: boolean;
29
+ onOpenChange?: (open: boolean) => void;
30
+ controlledOpen?: boolean;
31
+ sidebarState?: SidebarState;
32
+ collapsedSize?: string;
33
+ initialWidth?: string;
34
+ id: string;
35
+ } = $props();
36
+
37
+ let sidebar = untrack(() =>
38
+ setSidebar(
39
+ sidebarState ?? {
40
+ id,
41
+ collapsedSize,
42
+ open: () => open,
43
+ setOpen: (value: boolean) => {
44
+ if (controlledOpen) {
45
+ onOpenChange(value);
46
+ } else {
47
+ open = value;
48
+ onOpenChange(value);
49
+ }
50
+
51
+ // This sets the cookie to keep the sidebar state.
52
+ document.cookie = `${SIDEBAR_COOKIE_NAME}${id ? `:${id}` : ""}=${open}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
53
+ },
54
+ },
55
+ ),
56
+ );
57
+ </script>
58
+
59
+ <div
60
+ bind:this={ref}
61
+ {...restProps}
62
+ data-ui-component="sidebar-custom"
63
+ data-ui-part="sidebar-nested-wrapper"
64
+ data-slot="sidebar-nested-wrapper"
65
+ style="--sidebar-width-icon: {SIDEBAR_WIDTH_ICON}; {style}; --sidebar-width: {sidebar.width};"
66
+ class={className}
67
+ >
68
+ {@render children?.()}
69
+ </div>
@@ -0,0 +1,16 @@
1
+ import type { WithElementRef } from "bits-ui";
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+ import { SidebarState } from "./context.svelte.js";
4
+ import "./sidebar-custom.css";
5
+ type $$ComponentProps = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
6
+ open?: boolean;
7
+ onOpenChange?: (open: boolean) => void;
8
+ controlledOpen?: boolean;
9
+ sidebarState?: SidebarState;
10
+ collapsedSize?: string;
11
+ initialWidth?: string;
12
+ id: string;
13
+ };
14
+ declare const SidebarNestedProvider: import("svelte").Component<$$ComponentProps, {}, "open" | "ref">;
15
+ type SidebarNestedProvider = ReturnType<typeof SidebarNestedProvider>;
16
+ export default SidebarNestedProvider;
@@ -0,0 +1,72 @@
1
+ <script lang="ts">
2
+ import * as Tooltip from "@lapismd/design-core/shadcn/tooltip";
3
+ import { type WithElementRef } from "../../../utils.js";
4
+ import { untrack } from "svelte";
5
+ import type { HTMLAttributes } from "svelte/elements";
6
+ import {
7
+ SIDEBAR_COOKIE_MAX_AGE,
8
+ SIDEBAR_COOKIE_NAME,
9
+ SIDEBAR_WIDTH,
10
+ SIDEBAR_WIDTH_ICON,
11
+ } from "./constants.js";
12
+ import { setSidebar, SidebarState } from "./context.svelte.js";
13
+ import "./sidebar-custom.css";
14
+
15
+ let {
16
+ ref = $bindable(null),
17
+ open = $bindable(true),
18
+ onOpenChange = () => {},
19
+ id = "left",
20
+ initialWidth = SIDEBAR_WIDTH,
21
+ sidebarState,
22
+ controlledOpen = false,
23
+ class: className,
24
+ style,
25
+ children,
26
+ ...restProps
27
+ }: WithElementRef<HTMLAttributes<HTMLDivElement>> & {
28
+ open?: boolean;
29
+ onOpenChange?: (open: boolean) => void;
30
+ controlledOpen?: boolean;
31
+ sidebarState?: SidebarState;
32
+ id: string;
33
+ initialWidth?: string;
34
+ } = $props();
35
+
36
+ const sidebar = untrack(() =>
37
+ setSidebar(
38
+ sidebarState ?? {
39
+ initialWidth,
40
+ id,
41
+ open: () => open,
42
+ setOpen: (value: boolean) => {
43
+ if (controlledOpen) {
44
+ onOpenChange(value);
45
+ } else {
46
+ open = value;
47
+ onOpenChange(value);
48
+ }
49
+
50
+ // This sets the cookie to keep the sidebar state.
51
+ document.cookie = `${SIDEBAR_COOKIE_NAME}=${open}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
52
+ },
53
+ },
54
+ ),
55
+ );
56
+ </script>
57
+
58
+ <svelte:window onkeydown={sidebar.handleShortcutKeydown} />
59
+
60
+ <Tooltip.Provider delayDuration={0}>
61
+ <div
62
+ {...restProps}
63
+ data-ui-component="sidebar-custom"
64
+ data-ui-part="sidebar-wrapper"
65
+ data-slot="sidebar-wrapper"
66
+ style="--sidebar-width: {sidebar.size}; --sidebar-width-icon: {SIDEBAR_WIDTH_ICON}; {style}"
67
+ class={className}
68
+ bind:this={ref}
69
+ >
70
+ {@render children?.()}
71
+ </div>
72
+ </Tooltip.Provider>
@@ -0,0 +1,15 @@
1
+ import { type WithElementRef } from "../../../utils.js";
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+ import { SidebarState } from "./context.svelte.js";
4
+ import "./sidebar-custom.css";
5
+ type $$ComponentProps = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
6
+ open?: boolean;
7
+ onOpenChange?: (open: boolean) => void;
8
+ controlledOpen?: boolean;
9
+ sidebarState?: SidebarState;
10
+ id: string;
11
+ initialWidth?: string;
12
+ };
13
+ declare const SidebarProvider: import("svelte").Component<$$ComponentProps, {}, "open" | "ref">;
14
+ type SidebarProvider = ReturnType<typeof SidebarProvider>;
15
+ export default SidebarProvider;
@@ -0,0 +1,44 @@
1
+ <script lang="ts">
2
+ import { type WithElementRef } from "../../../utils.js";
3
+ import { untrack } from "svelte";
4
+ import type { HTMLAttributes } from "svelte/elements";
5
+ import { useSidebar } from "./context.svelte.js";
6
+ import { useSidebarResize } from "./sidebar-resize.svelte.js";
7
+
8
+ let {
9
+ ref = $bindable(null),
10
+ class: className,
11
+ enableDrag = false,
12
+ side = "left",
13
+ children,
14
+ ...restProps
15
+ }: WithElementRef<HTMLAttributes<HTMLButtonElement>, HTMLButtonElement> & {
16
+ enableDrag?: boolean;
17
+ side: "left" | "right";
18
+ } = $props();
19
+
20
+ const sidebar = useSidebar();
21
+ const { handleMouseDown } = untrack(() =>
22
+ useSidebarResize({
23
+ side,
24
+ enableDrag,
25
+ sidebar,
26
+ }),
27
+ );
28
+ </script>
29
+
30
+ <button
31
+ bind:this={ref}
32
+ data-sidebar="rail"
33
+ {...restProps}
34
+ data-ui-component="sidebar-custom"
35
+ data-ui-part="sidebar-rail"
36
+ data-slot="sidebar-rail"
37
+ aria-label="Toggle Sidebar"
38
+ tabindex={-1}
39
+ onmousedown={handleMouseDown}
40
+ title="Toggle Sidebar"
41
+ class={className}
42
+ >
43
+ {@render children?.()}
44
+ </button>
@@ -0,0 +1,9 @@
1
+ import { type WithElementRef } from "../../../utils.js";
2
+ import type { HTMLAttributes } from "svelte/elements";
3
+ type $$ComponentProps = WithElementRef<HTMLAttributes<HTMLButtonElement>, HTMLButtonElement> & {
4
+ enableDrag?: boolean;
5
+ side: "left" | "right";
6
+ };
7
+ declare const SidebarRail: import("svelte").Component<$$ComponentProps, {}, "ref">;
8
+ type SidebarRail = ReturnType<typeof SidebarRail>;
9
+ export default SidebarRail;
@@ -0,0 +1,15 @@
1
+ import { type SidebarState } from "./context.svelte";
2
+ interface UseSidebarResizeProps {
3
+ enableDrag?: boolean;
4
+ sidebar: SidebarState;
5
+ side: "left" | "right";
6
+ minResizeWidth?: string;
7
+ maxResizeWidth?: string;
8
+ }
9
+ export declare function useSidebarResize({ enableDrag, sidebar, minResizeWidth, side, maxResizeWidth, }: UseSidebarResizeProps): {
10
+ isDragging: {
11
+ current: boolean | null;
12
+ };
13
+ handleMouseDown: (evt: MouseEvent) => void;
14
+ };
15
+ export {};
@@ -0,0 +1,131 @@
1
+ import { SIDEBAR_WIDTH_ICON } from "./constants.js";
2
+ import {} from "./context.svelte";
3
+ function parseWidth(width) {
4
+ const unit = (width || "").toString().endsWith("rem") ? "rem" : "px";
5
+ const value = Number.parseFloat(width);
6
+ return { value, unit };
7
+ }
8
+ // Convert any width to pixels for calculations
9
+ function toPx(width) {
10
+ const { value, unit } = parseWidth(width);
11
+ return unit === "rem" ? value * 16 : value;
12
+ }
13
+ function formatWidth(value, unit) {
14
+ return `${unit === "rem" ? value.toFixed(1) : Math.round(value)}${unit}`;
15
+ }
16
+ const SIDEBAR_WIDTH_COOKIE_NAME = "sidebar:width";
17
+ const SIDEBAR_WIDTH_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
18
+ function useRef(initialValue = null) {
19
+ return {
20
+ current: initialValue,
21
+ };
22
+ }
23
+ export function useSidebarResize({ enableDrag = true, sidebar, minResizeWidth = SIDEBAR_WIDTH_ICON, side, maxResizeWidth = "80rem", }) {
24
+ const isDragging = useRef(false);
25
+ const startX = useRef(0);
26
+ const startWidth = useRef(0);
27
+ const isInteractingWithRail = useRef(false);
28
+ const lastWidth = useRef(0);
29
+ const lastLoggedWidth = useRef(0);
30
+ const autoCollapseThreshold = useRef(toPx(minResizeWidth) * 0.55); // 55% of min width
31
+ const persistWidth = (width) => {
32
+ sidebar.width = width;
33
+ document.cookie = `${SIDEBAR_WIDTH_COOKIE_NAME}:${side}=${width}; path=/; max-age=${SIDEBAR_WIDTH_COOKIE_MAX_AGE}`;
34
+ };
35
+ function isCollapsed() {
36
+ return sidebar.state === "collapsed";
37
+ }
38
+ function onToggle() {
39
+ sidebar.toggle();
40
+ }
41
+ function onResize(width) {
42
+ sidebar.width = width;
43
+ }
44
+ function setIsDraggingRail(isDraggingRail) {
45
+ sidebar.isDraggingRail = isDraggingRail;
46
+ }
47
+ const handleMouseDown = (evt) => {
48
+ if (!enableDrag) {
49
+ return;
50
+ }
51
+ isInteractingWithRail.current = true;
52
+ startWidth.current = toPx(sidebar.width);
53
+ startX.current = evt.clientX;
54
+ lastWidth.current = startWidth.current;
55
+ lastLoggedWidth.current = startWidth.current;
56
+ evt.preventDefault();
57
+ };
58
+ $effect(() => {
59
+ const handleMouseMove = (e) => {
60
+ if (!isInteractingWithRail.current || isCollapsed())
61
+ return;
62
+ const deltaX = Math.abs(e.clientX - startX.current);
63
+ if (!isDragging.current && deltaX > 5) {
64
+ isDragging.current = true;
65
+ // console.log("[Rail] Started dragging");
66
+ setIsDraggingRail(true);
67
+ }
68
+ if (isDragging.current) {
69
+ const { unit } = parseWidth(sidebar.width);
70
+ const minWidthPx = toPx(minResizeWidth);
71
+ const maxWidthPx = toPx(maxResizeWidth);
72
+ // Calculate new width in pixels
73
+ const deltaWidth = (e.clientX - startX.current) * (side === "left" ? 1 : -1);
74
+ const newWidthPx = startWidth.current + deltaWidth;
75
+ // Auto-collapse if dragged below threshold
76
+ if (newWidthPx < autoCollapseThreshold.current && !isCollapsed()) {
77
+ onToggle();
78
+ isDragging.current = false;
79
+ isInteractingWithRail.current = false;
80
+ setIsDraggingRail(false);
81
+ return;
82
+ }
83
+ // Rest of the existing width calculation logic
84
+ const clampedWidthPx = Math.max(minWidthPx, Math.min(maxWidthPx, newWidthPx));
85
+ // Convert to the target unit if needed
86
+ const newWidth = unit === "rem" ? clampedWidthPx / 16 : clampedWidthPx;
87
+ // Use appropriate threshold based on unit
88
+ const threshold = unit === "rem" ? 0.1 : 1;
89
+ if (Math.abs(newWidth - lastWidth.current / (unit === "rem" ? 16 : 1)) >=
90
+ threshold) {
91
+ const formattedWidth = formatWidth(newWidth, unit);
92
+ onResize(formattedWidth);
93
+ persistWidth(formattedWidth); // Store width in cookie when it changes
94
+ lastWidth.current = clampedWidthPx; // Store in px for consistent comparisons
95
+ // Log on larger changes
96
+ const logThreshold = unit === "rem" ? 1 : 16;
97
+ if (Math.abs(newWidth - lastLoggedWidth.current / (unit === "rem" ? 16 : 1)) >= logThreshold) {
98
+ // console.log(`[Rail] Width: ${formattedWidth}`);
99
+ lastLoggedWidth.current = clampedWidthPx;
100
+ }
101
+ }
102
+ }
103
+ };
104
+ const handleMouseUp = () => {
105
+ if (!isInteractingWithRail.current)
106
+ return;
107
+ if (!isDragging.current) {
108
+ // console.log("[Rail] Clicked, toggling sidebar");
109
+ onToggle();
110
+ }
111
+ else {
112
+ // console.log(`[Rail] Finished at ${lastWidth.current}`);
113
+ }
114
+ isDragging.current = false;
115
+ isInteractingWithRail.current = false;
116
+ lastWidth.current = 0;
117
+ lastLoggedWidth.current = 0;
118
+ setIsDraggingRail(false);
119
+ };
120
+ document.addEventListener("mousemove", handleMouseMove);
121
+ document.addEventListener("mouseup", handleMouseUp);
122
+ return () => {
123
+ document.removeEventListener("mousemove", handleMouseMove);
124
+ document.removeEventListener("mouseup", handleMouseUp);
125
+ };
126
+ });
127
+ return {
128
+ isDragging,
129
+ handleMouseDown,
130
+ };
131
+ }
@@ -0,0 +1,22 @@
1
+ <script lang="ts">
2
+ import {
3
+ Separator,
4
+ type SeparatorProps,
5
+ } from "@lapismd/design-core/shadcn/separator";
6
+
7
+ let {
8
+ ref = $bindable(null),
9
+ class: className,
10
+ ...restProps
11
+ }: SeparatorProps = $props();
12
+ </script>
13
+
14
+ <Separator
15
+ bind:ref
16
+ data-ui-component="sidebar-custom"
17
+ data-ui-part="sidebar-separator"
18
+ data-slot="sidebar-separator"
19
+ data-sidebar="separator"
20
+ class={className}
21
+ {...restProps}
22
+ />
@@ -0,0 +1,4 @@
1
+ import { type SeparatorProps } from "@lapismd/design-core/shadcn/separator";
2
+ declare const SidebarSeparator: import("svelte").Component<SeparatorProps, {}, "ref">;
3
+ type SidebarSeparator = ReturnType<typeof SidebarSeparator>;
4
+ export default SidebarSeparator;
@@ -0,0 +1,86 @@
1
+ <script lang="ts">
2
+ import { Button } from "@lapismd/design-core/shadcn/button";
3
+ import { untrack, type ComponentProps } from "svelte";
4
+ import { SidebarState, useSidebar } from "./context.svelte.js";
5
+
6
+ let {
7
+ ref = $bindable(null),
8
+ class: className,
9
+ sidebarState,
10
+ onclick,
11
+ ...restProps
12
+ }: ComponentProps<typeof Button> & {
13
+ sidebarState?: SidebarState;
14
+ onclick?: (e: MouseEvent) => void;
15
+ } = $props();
16
+
17
+ const sidebar = untrack(() => sidebarState ?? useSidebar());
18
+ </script>
19
+
20
+ <Button
21
+ bind:ref
22
+ data-sidebar="trigger"
23
+ data-ui-component="sidebar-custom"
24
+ data-ui-part="sidebar-trigger"
25
+ data-slot="sidebar-trigger"
26
+ variant="ghost"
27
+ size="icon"
28
+ class={`sidebar-toggle-button mod-${sidebar.props.id}${className ? ` ${className}` : ""}`}
29
+ type="button"
30
+ onclick={(e) => {
31
+ onclick?.(e);
32
+ sidebar.toggle();
33
+ }}
34
+ {...restProps}
35
+ >
36
+ {#if sidebar.props.id === "right"}
37
+ <svg
38
+ xmlns="http://www.w3.org/2000/svg"
39
+ width="24"
40
+ height="24"
41
+ viewBox="0 0 24 24"
42
+ fill="none"
43
+ stroke="currentColor"
44
+ stroke-width="2"
45
+ stroke-linecap="round"
46
+ stroke-linejoin="round"
47
+ class="svg-icon sidebar-toggle-button-icon"
48
+ >
49
+ <rect x="1" y="2" width="22" height="20" rx="4"></rect>
50
+ <rect
51
+ x="4"
52
+ y="5"
53
+ width="2"
54
+ height="14"
55
+ rx="2"
56
+ fill="currentColor"
57
+ class="sidebar-toggle-icon-inner"
58
+ ></rect></svg
59
+ >
60
+ {:else}
61
+ <svg
62
+ xmlns="http://www.w3.org/2000/svg"
63
+ width="24"
64
+ height="24"
65
+ viewBox="0 0 24 24"
66
+ fill="none"
67
+ stroke="currentColor"
68
+ stroke-width="2"
69
+ stroke-linecap="round"
70
+ stroke-linejoin="round"
71
+ class="svg-icon sidebar-toggle-button-icon"
72
+ >
73
+ <rect x="1" y="2" width="22" height="20" rx="4"></rect>
74
+ <rect
75
+ x="4"
76
+ y="5"
77
+ width="2"
78
+ height="14"
79
+ rx="2"
80
+ fill="currentColor"
81
+ class="sidebar-toggle-icon-inner"
82
+ ></rect>
83
+ </svg>
84
+ {/if}
85
+ <span class="sr-only">Toggle Sidebar</span>
86
+ </Button>
@@ -0,0 +1,10 @@
1
+ import { Button } from "@lapismd/design-core/shadcn/button";
2
+ import { type ComponentProps } from "svelte";
3
+ import { SidebarState } from "./context.svelte.js";
4
+ type $$ComponentProps = ComponentProps<typeof Button> & {
5
+ sidebarState?: SidebarState;
6
+ onclick?: (e: MouseEvent) => void;
7
+ };
8
+ declare const SidebarTrigger: import("svelte").Component<$$ComponentProps, {}, "ref">;
9
+ type SidebarTrigger = ReturnType<typeof SidebarTrigger>;
10
+ export default SidebarTrigger;