@rolder/kit 3.0.0-alpha-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.
Files changed (114) hide show
  1. package/README.md +23 -0
  2. package/dist/functions/cookies/getCookie.d.ts +3 -0
  3. package/dist/functions/cookies/getCookie.js +8 -0
  4. package/dist/functions/cookies/index.d.ts +3 -0
  5. package/dist/functions/cookies/index.js +3 -0
  6. package/dist/functions/cookies/setCookie.d.ts +10 -0
  7. package/dist/functions/cookies/setCookie.js +19 -0
  8. package/dist/functions/cookies/setCookies.d.ts +14 -0
  9. package/dist/functions/cookies/setCookies.js +13 -0
  10. package/dist/functions/index.d.ts +1 -0
  11. package/dist/functions/index.js +1 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.js +2 -0
  14. package/dist/ui/AnimatedChevron.d.ts +6 -0
  15. package/dist/ui/AnimatedChevron.js +13 -0
  16. package/dist/ui/JsonInput.d.ts +2 -0
  17. package/dist/ui/JsonInput.js +45 -0
  18. package/dist/ui/editor/Content.d.ts +3 -0
  19. package/dist/ui/editor/Content.js +13 -0
  20. package/dist/ui/editor/Provider.d.ts +17 -0
  21. package/dist/ui/editor/Provider.js +80 -0
  22. package/dist/ui/editor/Root.d.ts +2 -0
  23. package/dist/ui/editor/Root.js +19 -0
  24. package/dist/ui/editor/Toolbar.d.ts +5 -0
  25. package/dist/ui/editor/Toolbar.js +138 -0
  26. package/dist/ui/editor/index.d.ts +12 -0
  27. package/dist/ui/editor/index.js +11 -0
  28. package/dist/ui/editor/types.d.ts +7 -0
  29. package/dist/ui/editor/types.js +0 -0
  30. package/dist/ui/form/blurOnError.d.ts +4 -0
  31. package/dist/ui/form/blurOnError.js +11 -0
  32. package/dist/ui/form/buttons/CancelButton.d.ts +5 -0
  33. package/dist/ui/form/buttons/CancelButton.js +22 -0
  34. package/dist/ui/form/buttons/SubmitButton.d.ts +5 -0
  35. package/dist/ui/form/buttons/SubmitButton.js +22 -0
  36. package/dist/ui/form/buttons/SubscribeActionIcon.d.ts +4 -0
  37. package/dist/ui/form/buttons/SubscribeActionIcon.js +15 -0
  38. package/dist/ui/form/buttons/SubscribeButton.d.ts +5 -0
  39. package/dist/ui/form/buttons/SubscribeButton.js +16 -0
  40. package/dist/ui/form/buttons/index.d.ts +4 -0
  41. package/dist/ui/form/buttons/index.js +4 -0
  42. package/dist/ui/form/context.d.ts +83 -0
  43. package/dist/ui/form/context.js +26 -0
  44. package/dist/ui/form/fields/JsonField.d.ts +2 -0
  45. package/dist/ui/form/fields/JsonField.js +13 -0
  46. package/dist/ui/form/fields/MultiSelectField.d.ts +2 -0
  47. package/dist/ui/form/fields/MultiSelectField.js +15 -0
  48. package/dist/ui/form/fields/NumberField.d.ts +2 -0
  49. package/dist/ui/form/fields/NumberField.js +15 -0
  50. package/dist/ui/form/fields/PassowrdField.d.ts +2 -0
  51. package/dist/ui/form/fields/PassowrdField.js +18 -0
  52. package/dist/ui/form/fields/SelectField.d.ts +2 -0
  53. package/dist/ui/form/fields/SelectField.js +15 -0
  54. package/dist/ui/form/fields/SwitchField.d.ts +2 -0
  55. package/dist/ui/form/fields/SwitchField.js +15 -0
  56. package/dist/ui/form/fields/TextField.d.ts +2 -0
  57. package/dist/ui/form/fields/TextField.js +15 -0
  58. package/dist/ui/form/fields/TextPassowrdField.d.ts +2 -0
  59. package/dist/ui/form/fields/TextPassowrdField.js +29 -0
  60. package/dist/ui/form/fields/TextareaField.d.ts +2 -0
  61. package/dist/ui/form/fields/TextareaField.js +15 -0
  62. package/dist/ui/form/fields/index.d.ts +9 -0
  63. package/dist/ui/form/fields/index.js +9 -0
  64. package/dist/ui/form/fieldsSchema.d.ts +12 -0
  65. package/dist/ui/form/fieldsSchema.js +13 -0
  66. package/dist/ui/form/index.d.ts +3 -0
  67. package/dist/ui/form/index.js +4 -0
  68. package/dist/ui/hoverActionIcon/HoverActionIcon.d.ts +6 -0
  69. package/dist/ui/hoverActionIcon/HoverActionIcon.js +14 -0
  70. package/dist/ui/hoverActionIcon/index.d.ts +1 -0
  71. package/dist/ui/hoverActionIcon/index.js +1 -0
  72. package/dist/ui/hoverPaper/HoverPaper.d.ts +6 -0
  73. package/dist/ui/hoverPaper/HoverPaper.js +16 -0
  74. package/dist/ui/hoverPaper/index.d.ts +2 -0
  75. package/dist/ui/hoverPaper/index.js +2 -0
  76. package/dist/ui/hoverPaper/usePaperHover.d.ts +4 -0
  77. package/dist/ui/hoverPaper/usePaperHover.js +9 -0
  78. package/dist/ui/index.d.ts +9 -0
  79. package/dist/ui/index.js +9 -0
  80. package/dist/ui/routerLink/RouterLink.d.ts +16 -0
  81. package/dist/ui/routerLink/RouterLink.js +37 -0
  82. package/dist/ui/routerLink/index.d.ts +1 -0
  83. package/dist/ui/routerLink/index.js +1 -0
  84. package/dist/ui/saveInput/JsonInput.d.ts +6 -0
  85. package/dist/ui/saveInput/JsonInput.js +34 -0
  86. package/dist/ui/saveInput/NumberInput.d.ts +6 -0
  87. package/dist/ui/saveInput/NumberInput.js +27 -0
  88. package/dist/ui/saveInput/SaveInput.d.ts +36 -0
  89. package/dist/ui/saveInput/SaveInput.js +15 -0
  90. package/dist/ui/saveInput/Select.d.ts +6 -0
  91. package/dist/ui/saveInput/Select.js +27 -0
  92. package/dist/ui/saveInput/Switch.d.ts +6 -0
  93. package/dist/ui/saveInput/Switch.js +30 -0
  94. package/dist/ui/saveInput/TextInput.d.ts +6 -0
  95. package/dist/ui/saveInput/TextInput.js +26 -0
  96. package/dist/ui/saveInput/Textarea.d.ts +6 -0
  97. package/dist/ui/saveInput/Textarea.js +26 -0
  98. package/dist/ui/saveInput/index.d.ts +1 -0
  99. package/dist/ui/saveInput/index.js +2 -0
  100. package/dist/ui/scrollArea/ScrollArea.d.ts +62 -0
  101. package/dist/ui/scrollArea/ScrollArea.js +30 -0
  102. package/dist/ui/scrollArea/ScrollAreaButton.d.ts +5 -0
  103. package/dist/ui/scrollArea/ScrollAreaButton.js +30 -0
  104. package/dist/ui/scrollArea/ScrollAreaContent.d.ts +6 -0
  105. package/dist/ui/scrollArea/ScrollAreaContent.js +30 -0
  106. package/dist/ui/scrollArea/context.d.ts +28 -0
  107. package/dist/ui/scrollArea/context.js +10 -0
  108. package/dist/ui/scrollArea/index.d.ts +3 -0
  109. package/dist/ui/scrollArea/index.js +3 -0
  110. package/dist/ui/scrollArea/types.d.ts +65 -0
  111. package/dist/ui/scrollArea/types.js +0 -0
  112. package/dist/ui/scrollArea/useScrollArea.d.ts +9 -0
  113. package/dist/ui/scrollArea/useScrollArea.js +146 -0
  114. package/package.json +59 -0
@@ -0,0 +1,146 @@
1
+ import { useDebouncedCallback, useMergedRef, useResizeObserver } from "@mantine/hooks";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ const useScrollAreaState = (options = {})=>{
4
+ const { autoScroll = false, scrollToBottomOnInit = false, animated = true, nearThreshold = 32 } = options;
5
+ const scrollAreaRef = useRef(null);
6
+ const isUserInteractingRef = useRef(false);
7
+ const userInteractionTimeoutRef = useRef(void 0);
8
+ const isInitializedRef = useRef(false);
9
+ const [contentResizeRef, contentRect] = useResizeObserver();
10
+ const [scrollPosition, setScrollPosition] = useState({
11
+ scrollTop: 0,
12
+ clientHeight: 0,
13
+ scrollHeight: 0
14
+ });
15
+ const isAtTop = 0 === scrollPosition.scrollTop;
16
+ const isAtBottom = scrollPosition.scrollTop + scrollPosition.clientHeight >= scrollPosition.scrollHeight;
17
+ const isNearTop = scrollPosition.scrollTop <= nearThreshold;
18
+ const isNearBottom = scrollPosition.scrollTop + scrollPosition.clientHeight >= scrollPosition.scrollHeight - nearThreshold;
19
+ const isAboveCenter = scrollPosition.scrollTop < (scrollPosition.scrollHeight - scrollPosition.clientHeight) / 2;
20
+ const hasScrollableContent = scrollPosition.scrollHeight > scrollPosition.clientHeight;
21
+ const debouncedUpdatePosition = useDebouncedCallback((element)=>{
22
+ const newPosition = {
23
+ scrollTop: element.scrollTop,
24
+ clientHeight: element.clientHeight,
25
+ scrollHeight: element.scrollHeight
26
+ };
27
+ setScrollPosition(newPosition);
28
+ }, {
29
+ delay: 16
30
+ });
31
+ const scrollToTop = useCallback((isAnimated)=>{
32
+ const element = scrollAreaRef.current;
33
+ if (!element) return;
34
+ const shouldAnimate = isAnimated ?? animated;
35
+ if (shouldAnimate) element.scrollTo({
36
+ top: 0,
37
+ behavior: 'smooth'
38
+ });
39
+ else element.scrollTop = 0;
40
+ }, [
41
+ animated
42
+ ]);
43
+ const scrollToBottom = useCallback((isAnimated)=>{
44
+ const element = scrollAreaRef.current;
45
+ if (!element) return;
46
+ const shouldAnimate = isAnimated ?? animated;
47
+ if (shouldAnimate) element.scrollTo({
48
+ top: element.scrollHeight,
49
+ behavior: 'smooth'
50
+ });
51
+ else element.scrollTop = element.scrollHeight;
52
+ const scrollHeightBefore = element.scrollHeight;
53
+ setTimeout(()=>{
54
+ const scrollHeightAfter = element.scrollHeight;
55
+ const diff = element.scrollHeight - (element.scrollTop + element.clientHeight);
56
+ if (diff > 1 && scrollHeightAfter !== scrollHeightBefore) element.scrollTop = element.scrollHeight;
57
+ }, 50);
58
+ }, [
59
+ animated
60
+ ]);
61
+ const performAutoScroll = useCallback(()=>{
62
+ if (!autoScroll || isUserInteractingRef.current || !scrollAreaRef.current) return;
63
+ if (isAtBottom) scrollToBottom(false);
64
+ }, [
65
+ autoScroll,
66
+ isAtBottom,
67
+ scrollToBottom
68
+ ]);
69
+ const handleUserInteraction = useCallback(()=>{
70
+ isUserInteractingRef.current = true;
71
+ if (userInteractionTimeoutRef.current) clearTimeout(userInteractionTimeoutRef.current);
72
+ userInteractionTimeoutRef.current = setTimeout(()=>{
73
+ isUserInteractingRef.current = false;
74
+ }, 150);
75
+ }, []);
76
+ const handleScroll = useCallback((event)=>{
77
+ const element = event.target;
78
+ debouncedUpdatePosition(element);
79
+ }, [
80
+ debouncedUpdatePosition
81
+ ]);
82
+ useEffect(()=>{
83
+ if (!scrollToBottomOnInit || isInitializedRef.current) return;
84
+ if (hasScrollableContent) {
85
+ scrollToBottom(animated);
86
+ isInitializedRef.current = true;
87
+ }
88
+ }, [
89
+ scrollToBottomOnInit,
90
+ hasScrollableContent,
91
+ scrollToBottom,
92
+ animated
93
+ ]);
94
+ useEffect(()=>{
95
+ const element = scrollAreaRef.current;
96
+ if (!element || 0 === contentRect.height) return;
97
+ debouncedUpdatePosition(element);
98
+ const timeoutId = setTimeout(performAutoScroll, 10);
99
+ return ()=>clearTimeout(timeoutId);
100
+ }, [
101
+ contentRect.height,
102
+ debouncedUpdatePosition,
103
+ performAutoScroll
104
+ ]);
105
+ useEffect(()=>{
106
+ const element = scrollAreaRef.current;
107
+ if (!element) return;
108
+ const events = [
109
+ 'wheel',
110
+ 'touchstart',
111
+ 'touchmove',
112
+ 'mousedown'
113
+ ];
114
+ element.addEventListener('scroll', handleScroll);
115
+ events.forEach((event)=>{
116
+ element.addEventListener(event, handleUserInteraction);
117
+ });
118
+ debouncedUpdatePosition(element);
119
+ return ()=>{
120
+ element.removeEventListener('scroll', handleScroll);
121
+ events.forEach((event)=>{
122
+ element.removeEventListener(event, handleUserInteraction);
123
+ });
124
+ if (userInteractionTimeoutRef.current) clearTimeout(userInteractionTimeoutRef.current);
125
+ };
126
+ }, [
127
+ handleScroll,
128
+ handleUserInteraction,
129
+ debouncedUpdatePosition
130
+ ]);
131
+ const callbackRef = useMergedRef(scrollAreaRef);
132
+ return {
133
+ isAtTop,
134
+ isNearTop,
135
+ isAtBottom,
136
+ isNearBottom,
137
+ isAboveCenter,
138
+ hasScrollableContent,
139
+ scrollToTop,
140
+ scrollToBottom,
141
+ viewportRef: scrollAreaRef,
142
+ _callbackRef: callbackRef,
143
+ _contentResizeRef: contentResizeRef
144
+ };
145
+ };
146
+ export { useScrollAreaState };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@rolder/kit",
3
+ "version": "3.0.0-alpha-1",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js"
9
+ }
10
+ },
11
+ "types": "./dist/index.d.ts",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "scripts": {
16
+ "build": "rslib build",
17
+ "dev": "rslib build --watch",
18
+ "check": "biome check --write && tsc --noEmit"
19
+ },
20
+ "devDependencies": {
21
+ "@biomejs/biome": "2.3.8",
22
+ "@rsbuild/plugin-react": "^1.4.2",
23
+ "@rslib/core": "^0.19.2",
24
+ "@types/react": "^19.2.8",
25
+ "react": "^19.2.3",
26
+ "typescript": "^5.9.3",
27
+ "@types/bun": "^1.3.5",
28
+ "@types/js-cookie": "^3.0.6"
29
+ },
30
+ "peerDependencies": {
31
+ "react": ">=16.9.0",
32
+ "react-dom": ">=16.9.0",
33
+ "@tabler/icons-react": "^3.36.1",
34
+ "clsx": "^2.1.1",
35
+ "@tiptap/extension-highlight": "^3.15.3",
36
+ "@tiptap/extension-placeholder": "^3.15.3",
37
+ "@tiptap/extension-table": "^3.15.3",
38
+ "@tiptap/extension-task-item": "^3.15.3",
39
+ "@tiptap/extension-task-list": "^3.15.3",
40
+ "@tiptap/extension-text-align": "^3.15.3",
41
+ "@tiptap/starter-kit": "^3.15.3",
42
+ "@codemirror/lang-json": "^6.0.2",
43
+ "@codemirror/lint": "^6.9.2",
44
+ "@uiw/codemirror-theme-vscode": "^4.25.4",
45
+ "@uiw/react-codemirror": "^4.25.4",
46
+ "@mantine/core": "^8.3.11",
47
+ "@mantine/hooks": "^8.3.11",
48
+ "@mantine/tiptap": "^8.3.11",
49
+ "@tanstack/react-router": "1.147.3",
50
+ "@tanstack/react-form": "1.27.7",
51
+ "@tanstack/react-start": "^1.149.1",
52
+ "zod": "^4.3.5",
53
+ "js-cookie": "^3.0.5"
54
+ },
55
+ "trustedDependencies": [
56
+ "core-js",
57
+ "esbuild"
58
+ ]
59
+ }