diff options
| author | Dhravya Shah <[email protected]> | 2024-04-10 09:41:38 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-04-10 09:41:38 -0700 |
| commit | d5544d007076c123294831e23800c67d354e46ec (patch) | |
| tree | ee79efe1d6eb42c373e18d9d52fd5583145899e7 /apps/web/src/lib | |
| parent | change 'categories' to 'spaces' (diff) | |
| parent | better md (diff) | |
| download | archived-supermemory-d5544d007076c123294831e23800c67d354e46ec.tar.xz archived-supermemory-d5544d007076c123294831e23800c67d354e46ec.zip | |
Merge pull request #4 from Dhravya/new-ui
New UI
Diffstat (limited to 'apps/web/src/lib')
| -rw-r--r-- | apps/web/src/lib/searchParams.ts | 12 | ||||
| -rw-r--r-- | apps/web/src/lib/utils.ts | 77 |
2 files changed, 86 insertions, 3 deletions
diff --git a/apps/web/src/lib/searchParams.ts b/apps/web/src/lib/searchParams.ts new file mode 100644 index 00000000..b435295d --- /dev/null +++ b/apps/web/src/lib/searchParams.ts @@ -0,0 +1,12 @@ +import { + createSearchParamsCache, + parseAsInteger, + parseAsString + } from 'nuqs/server' + // Note: import from 'nuqs/server' to avoid the "use client" directive + + export const searchParamsCache = createSearchParamsCache({ + // List your search param keys and associated parsers here: + q: parseAsString.withDefault(''), + maxResults: parseAsInteger.withDefault(10) + })
\ No newline at end of file diff --git a/apps/web/src/lib/utils.ts b/apps/web/src/lib/utils.ts index d084ccad..5eca08cc 100644 --- a/apps/web/src/lib/utils.ts +++ b/apps/web/src/lib/utils.ts @@ -1,6 +1,77 @@ -import { type ClassValue, clsx } from "clsx" -import { twMerge } from "tailwind-merge" +"use client"; +import { type ClassValue, clsx } from "clsx"; +import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { - return twMerge(clsx(inputs)) + return twMerge(clsx(inputs)); +} + +// removes http(s?):// and / from the url +export function cleanUrl(url: string) { + if (url.endsWith("/")) { + url = url.slice(0, -1); + } + return url.startsWith("https://") + ? url.slice(8) + : url.startsWith("http://") + ? url.slice(7) + : url; +} + +export function generateId() { + return Math.random().toString(36).slice(2, 9); +} + +export function svgId(prefix: string, id: string) { + return `${prefix}-${id}`; +} + +export function countLines(textarea: HTMLTextAreaElement): number { + let _buffer: HTMLTextAreaElement | null = null; + + if (_buffer == null) { + _buffer = document.createElement("textarea"); + _buffer.style.border = "none"; + _buffer.style.height = "0"; + _buffer.style.overflow = "hidden"; + _buffer.style.padding = "0"; + _buffer.style.position = "absolute"; + _buffer.style.left = "0"; + _buffer.style.top = "0"; + _buffer.style.zIndex = "-1"; + document.body.appendChild(_buffer); + } + + const cs = window.getComputedStyle(textarea); + const pl = parseInt(cs.paddingLeft as string); + const pr = parseInt(cs.paddingRight as string); + let lh = parseInt(cs.lineHeight as string); + + // [cs.lineHeight] may return 'normal', which means line height = font size. + if (isNaN(lh)) lh = parseInt(cs.fontSize as string); + + // Copy content width. + if (_buffer) { + _buffer.style.width = textarea.clientWidth - pl - pr + "px"; + + // Copy text properties. + _buffer.style.font = cs.font as string; + _buffer.style.letterSpacing = cs.letterSpacing as string; + _buffer.style.whiteSpace = cs.whiteSpace as string; + _buffer.style.wordBreak = cs.wordBreak as string; + _buffer.style.wordSpacing = cs.wordSpacing as string; + _buffer.style.wordWrap = cs.wordWrap as string; + + // Copy value. + _buffer.value = textarea.value; + + const result = Math.floor(_buffer.scrollHeight / lh); + return result > 0 ? result : 1; + } + + return 0; +} + +export function convertRemToPixels(rem: number) { + return rem * parseFloat(getComputedStyle(document.documentElement).fontSize); } |