-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4089 from signalco-io/feature/comments
Feature/comments
- Loading branch information
Showing
43 changed files
with
1,225 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'; | ||
|
||
export function useDocumentEvent<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => void) { | ||
useIsomorphicLayoutEffect(() => { | ||
document.addEventListener(type, listener); | ||
return () => document.removeEventListener(type, listener); | ||
}, []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { DependencyList } from 'react'; | ||
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'; | ||
|
||
export function useWindowEvent<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => void ) { | ||
export function useWindowEvent<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => void, dependencies?: DependencyList | undefined) { | ||
useIsomorphicLayoutEffect(() => { | ||
window.addEventListener(type, listener); | ||
return () => window.removeEventListener(type, listener); | ||
}, []); | ||
}, dependencies ?? []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
function getQuerySelector(element: Element | Node | null | undefined, options: { proceedAfterId: boolean, includeClasses: boolean }) { | ||
if (!(element instanceof Element)) | ||
return ''; | ||
|
||
let currentNode: Element | null = element; | ||
if (!currentNode) | ||
return ''; | ||
|
||
// Walk from current element up to the root | ||
const selectorParts = []; | ||
while (currentNode && currentNode.nodeType === Node.ELEMENT_NODE) { | ||
let currentSelector = ''; | ||
if (currentNode.id) { | ||
currentSelector += '#'.concat(escapeClass(currentNode.id)) | ||
if (!options.proceedAfterId) { | ||
selectorParts.unshift(currentSelector); | ||
break; | ||
} | ||
} else { | ||
// Handle tag | ||
const currentTag = currentNode.nodeName.toLowerCase(); | ||
if ('html' === currentTag) | ||
break; | ||
currentSelector += currentTag; | ||
|
||
// Handle classes | ||
const currentClass = currentNode.classList.item(0); | ||
if (options.includeClasses && currentClass) { | ||
currentSelector += `.${escapeClass(currentClass)}`; | ||
} | ||
|
||
let nthSibiling: Element | null = currentNode; | ||
let sibilingMathingClasses = options.includeClasses && currentClass; | ||
let sibilingsCount = 1 | ||
while (nthSibiling = nthSibiling.previousElementSibling) { | ||
if (nthSibiling.nodeName.toLowerCase() === currentTag) { | ||
sibilingsCount++; | ||
} | ||
if (options.includeClasses && currentClass && nthSibiling.classList.contains(currentClass)) { | ||
sibilingMathingClasses = false; | ||
} | ||
} | ||
if (sibilingsCount !== 1 && !(options.includeClasses && sibilingMathingClasses)) { | ||
currentSelector += `:nth-of-type(${sibilingsCount})`; | ||
} | ||
} | ||
selectorParts.unshift(currentSelector); | ||
currentNode = currentNode.parentNode instanceof Element ? currentNode.parentNode : null; | ||
} | ||
return selectorParts.join('>') | ||
} | ||
function escapeClass(selector: string) { | ||
// Fix ID numbers: "50" -> "\\35\\30" | ||
return selector.replace(/([^a-zA-Z0-9-_])/g, '\\$1') | ||
} | ||
|
||
export const getElementSelector = (element: Element | Node | null | undefined) => { | ||
const variations = [ | ||
getQuerySelector(element, { | ||
proceedAfterId: !1, | ||
includeClasses: !1 | ||
}), | ||
getQuerySelector(element, { | ||
proceedAfterId: !0, | ||
includeClasses: !1 | ||
}), | ||
getQuerySelector(element, { | ||
proceedAfterId: !1, | ||
includeClasses: !0 | ||
}), | ||
getQuerySelector(element, { | ||
proceedAfterId: !0, | ||
includeClasses: !0 | ||
}) | ||
]; | ||
|
||
const selectors = new Set(); | ||
return variations | ||
.filter(variationSelector => { | ||
if (selectors.has(variationSelector)) | ||
return false; | ||
selectors.add(variationSelector); | ||
try { | ||
document.querySelector(variationSelector) | ||
} catch (n) { | ||
console.error('Faulty nodeId selector', variationSelector, String(n)); | ||
return false; | ||
} | ||
return true; | ||
}) | ||
.join(','); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,40 @@ | ||
import { PropsWithChildren } from 'react'; | ||
import { HTMLAttributes } from 'react'; | ||
import { cx } from '../cx'; | ||
|
||
export type AvatarProps = PropsWithChildren<{ | ||
size?: 'sm' | 'md' | 'lg'; // TODO: Implement | ||
src?: string; // TODO: Implement | ||
alt?: string; // TODO: Implement | ||
className?: string; | ||
}>; | ||
export type AvatarProps = HTMLAttributes<HTMLDivElement> & { | ||
size?: 'sm' | 'md' | 'lg'; | ||
} & ({ | ||
children: React.ReactNode; | ||
src?: never; | ||
alt?: never; | ||
} | { | ||
children?: never; | ||
src: string; | ||
alt: string; | ||
}); | ||
|
||
export function Avatar({ children, className }: AvatarProps) { | ||
return (<div className={cx( | ||
'flex h-10 min-w-[40px] max-w-[40px] items-center justify-center rounded-full bg-muted border', | ||
className | ||
)}>{children}</div>); | ||
export function Avatar({ children, size, src, alt, className, ...rest }: AvatarProps) { | ||
return ( | ||
<div | ||
className={cx( | ||
'flex items-center justify-center rounded-full bg-muted border', | ||
(!size || size === 'md') && 'h-10 min-w-[40px] max-w-[40px]', | ||
size === 'sm' && 'h-6 min-w-[24px] max-w-[24px] text-xs', | ||
size === 'lg' && 'h-12 min-w-[48px] max-w-[48px] text-lg', | ||
className | ||
)} | ||
{...rest} | ||
> | ||
{src ? ( | ||
// eslint-disable-next-line @next/next/no-img-element | ||
<img | ||
src={src} | ||
alt={alt} | ||
width={size === 'lg' ? 48 : (size === 'sm' ? 24 : 40)} | ||
height={size === 'lg' ? 48 : (size === 'sm' ? 24 : 40)} /> | ||
) : ( | ||
children | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,24 @@ | ||
import type { AnchorHTMLAttributes } from 'react'; | ||
import NextLink from 'next/link'; | ||
import type { Url } from 'next/dist/shared/lib/router/router'; | ||
import { isAbsoluteUrl } from '@signalco/js'; | ||
import { cx } from '../cx'; | ||
|
||
export type LinkProps = AnchorHTMLAttributes<HTMLAnchorElement> & { | ||
href: string | Url; | ||
href: string; | ||
className?: string | undefined; | ||
'aria-label'?: string | undefined; | ||
legacy?: boolean; | ||
}; | ||
|
||
export function Link({ className, href, children, legacy, ...rest }: LinkProps) { | ||
export function Link({ className, href, children, ...rest }: LinkProps) { | ||
return ( | ||
<NextLink | ||
<a | ||
href={href} | ||
className={cx( | ||
typeof children === 'string' && 'no-underline text-muted-foreground', | ||
className | ||
)} | ||
target={isAbsoluteUrl(href) ? '_blank' : '_self'} | ||
passHref | ||
prefetch={false} | ||
legacyBehavior={legacy} | ||
{...rest}> | ||
{children} | ||
</NextLink> | ||
</a> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.