Compare commits
3
Commits
551ee36897
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3fc512b0b | ||
|
|
b2924c5529 | ||
|
|
68ea59d94d |
@@ -20,7 +20,7 @@
|
||||
| `bun run dev:typecheck` | Typecheck the playground (`dev/tsconfig.json`) |
|
||||
| `./publish.sh "msg"`| Typecheck → test → compile → `git commit/push` → `bun publish` |
|
||||
|
||||
`publish.sh` pushes and publishes - only run it when explicitly asked. Bump `version` in `package.json` before publishing.
|
||||
`publish.sh` pushes and publishes. **Never run it, or `bun publish`, without asking the user first - every time, for every version.** A change that needs a release is not permission to publish one. Bump `version` in `package.json` before publishing.
|
||||
|
||||
## Layout
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/twui",
|
||||
"version": "0.1.13",
|
||||
"version": "0.1.15",
|
||||
"description": "A modular skeletal React component framework for Tailwind CSS v4",
|
||||
"author": "Benjamin Toby",
|
||||
"type": "module",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import _ from "lodash";
|
||||
import React from "react";
|
||||
import twuiOmit from "../../utils/omit";
|
||||
import { TWUIPopoverStyles } from "../../elements/Modal";
|
||||
import twuiNumberfy from "../../utils/numberfy";
|
||||
|
||||
@@ -58,29 +58,25 @@ export default function twuiGrabPopoverStyles({
|
||||
};
|
||||
|
||||
if (position === "bottom") {
|
||||
popoverStyle = _.merge(popoverStyle, defaultBottomStyle);
|
||||
popoverStyle = { ...popoverStyle, ...defaultBottomStyle };
|
||||
} else if (position === "bottom-left") {
|
||||
popoverStyle = _.merge(
|
||||
popoverStyle,
|
||||
_.omit(defaultBottomStyle, ["transform"]),
|
||||
{
|
||||
left: rect.left + window.scrollX,
|
||||
} as React.CSSProperties
|
||||
);
|
||||
popoverStyle = {
|
||||
...popoverStyle,
|
||||
...twuiOmit(defaultBottomStyle, ["transform"]),
|
||||
left: rect.left + window.scrollX,
|
||||
};
|
||||
} else if (position === "bottom-right") {
|
||||
popoverStyle = _.merge(
|
||||
popoverStyle,
|
||||
_.omit(defaultBottomStyle, ["left", "transform"]),
|
||||
{
|
||||
right:
|
||||
viewportWidth -
|
||||
(rect.left + window.scrollX) -
|
||||
rect.width -
|
||||
targetElRightPadding,
|
||||
} as React.CSSProperties
|
||||
);
|
||||
popoverStyle = {
|
||||
...popoverStyle,
|
||||
...twuiOmit(defaultBottomStyle, ["left", "transform"]),
|
||||
right:
|
||||
viewportWidth -
|
||||
(rect.left + window.scrollX) -
|
||||
rect.width -
|
||||
targetElRightPadding,
|
||||
};
|
||||
} else if (position === "top") {
|
||||
popoverStyle = _.merge(popoverStyle, defaultTopStyleStyle);
|
||||
popoverStyle = { ...popoverStyle, ...defaultTopStyleStyle };
|
||||
} else if (position === "right") {
|
||||
popoverStyle.top = rect.top + window.scrollY + rect.height / 2;
|
||||
popoverStyle.left = rect.right + window.scrollX + 8;
|
||||
|
||||
@@ -5,7 +5,7 @@ import Button from "../layout/Button";
|
||||
import { X } from "lucide-react";
|
||||
import { type TWUI_MODAL_PROPS } from "../elements/Modal";
|
||||
import Paper from "../elements/Paper";
|
||||
import _ from "lodash";
|
||||
import twuiOmit from "../utils/omit";
|
||||
|
||||
type Props = TWUI_MODAL_PROPS & {
|
||||
open: boolean;
|
||||
@@ -54,7 +54,7 @@ export default function ModalComponent({
|
||||
}}
|
||||
></div>
|
||||
<Paper
|
||||
{..._.omit(props, [
|
||||
{...twuiOmit(props, [
|
||||
"target",
|
||||
"targetRef",
|
||||
"targetWrapperProps",
|
||||
|
||||
@@ -3,7 +3,7 @@ import { twMerge } from "tailwind-merge";
|
||||
import ReactDOM from "react-dom";
|
||||
import type { TWUI_MODAL_PROPS } from "../elements/Modal";
|
||||
import Paper from "../elements/Paper";
|
||||
import _ from "lodash";
|
||||
import twuiOmit from "../utils/omit";
|
||||
import twuiGrabPopoverStyles from "../(functions)/popver/grab-popover-styles";
|
||||
|
||||
type Props = TWUI_MODAL_PROPS & {
|
||||
@@ -93,7 +93,7 @@ export default function PopoverComponent({
|
||||
|
||||
return ReactDOM.createPortal(
|
||||
<Paper
|
||||
{..._.omit(props, [
|
||||
{...twuiOmit(props, [
|
||||
"target",
|
||||
"targetRef",
|
||||
"targetWrapperProps",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { ComponentProps, Dispatch, SetStateAction } from "react";
|
||||
import _ from "lodash";
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
import Row from "../layout/Row";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from "react";
|
||||
import _ from "lodash";
|
||||
import throttle from "lodash/throttle";
|
||||
import twuiStripMarkdown from "../../utils/strip-markdown";
|
||||
import {
|
||||
twuiAIChatMessageId,
|
||||
@@ -190,7 +190,7 @@ export default function useAIChatHistory({
|
||||
// Writing on every streamed chunk would thrash storage: throttle
|
||||
const persist = React.useMemo(
|
||||
() =>
|
||||
_.throttle(
|
||||
throttle(
|
||||
(list: TWUIAIChatConversation[], active: string | null) => {
|
||||
if (storageKey) {
|
||||
try {
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
import _ from "lodash";
|
||||
import twuiOmit from "../utils/omit";
|
||||
import type { DetailedHTMLProps, FormHTMLAttributes, RefObject } from "react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
@@ -16,7 +16,7 @@ type Props<T extends { [key: string]: any } = { [key: string]: any }> =
|
||||
export default function Form<
|
||||
T extends { [key: string]: any } = { [key: string]: any },
|
||||
>({ formRef, ...props }: Props<T>) {
|
||||
const finalProps = _.omit(props, ["submitHandler", "changeHandler"]);
|
||||
const finalProps = twuiOmit(props, ["submitHandler", "changeHandler"]);
|
||||
|
||||
return (
|
||||
<form
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
import _ from "lodash";
|
||||
import twuiOmit from "../utils/omit";
|
||||
import React, {
|
||||
type DetailedHTMLProps,
|
||||
type ImgHTMLAttributes,
|
||||
@@ -44,7 +44,7 @@ export default function Img({
|
||||
|
||||
const [imageError, setImageError] = React.useState(false);
|
||||
|
||||
const finalProps = _.omit(props, [
|
||||
const finalProps = twuiOmit(props, [
|
||||
"size",
|
||||
"circle",
|
||||
"bgImg",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import _ from "lodash";
|
||||
import type { DetailedHTMLProps, HTMLAttributes } from "react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import _ from "lodash";
|
||||
import twuiOmit from "../utils/omit";
|
||||
import type { DetailedHTMLProps, HTMLAttributes } from "react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
@@ -16,7 +16,7 @@ type Props = DetailedHTMLProps<
|
||||
* @className twui-stack
|
||||
*/
|
||||
export default function Stack({ gap, componentRef, ...props }: Props) {
|
||||
const finalProps = _.omit(props, "center");
|
||||
const finalProps = twuiOmit(props, "center");
|
||||
return (
|
||||
<div
|
||||
{...finalProps}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import twuiOmit from "./omit";
|
||||
|
||||
describe("twuiOmit", () => {
|
||||
test("leaves out a single key", () => {
|
||||
expect(twuiOmit({ center: true, gap: 4 }, "center")).toEqual({ gap: 4 });
|
||||
});
|
||||
|
||||
test("leaves out several keys", () => {
|
||||
const props = { a: 1, b: 2, c: 3 };
|
||||
expect(twuiOmit(props, ["a", "c"])).toEqual({ b: 2 });
|
||||
});
|
||||
|
||||
test("does not change the object it was given", () => {
|
||||
const props = { a: 1, b: 2 };
|
||||
twuiOmit(props, "a");
|
||||
expect(props).toEqual({ a: 1, b: 2 });
|
||||
});
|
||||
|
||||
test("is shallow: a nested object keeps every key", () => {
|
||||
const nested = { keep: true, drop: false };
|
||||
const result = twuiOmit({ nested, drop: 1 }, "drop");
|
||||
expect(result).toEqual({ nested: { keep: true, drop: false } });
|
||||
expect(result.nested).toBe(nested);
|
||||
});
|
||||
|
||||
test("ignores a named key that is not there", () => {
|
||||
expect(twuiOmit({ a: 1 }, "missing")).toEqual({ a: 1 });
|
||||
});
|
||||
|
||||
test("returns a new object even when nothing is left out", () => {
|
||||
const props = { a: 1 };
|
||||
expect(twuiOmit(props, [])).toEqual({ a: 1 });
|
||||
expect(twuiOmit(props, [])).not.toBe(props);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* A new object without the named keys. Components use it to keep their own
|
||||
* props off the element they render.
|
||||
*
|
||||
* It is shallow, like lodash's omit, but importing lodash for three helpers
|
||||
* put the whole library in every page that uses a twui component, so this
|
||||
* lives here instead.
|
||||
*
|
||||
* The return type stays T: the keys are runtime-only here, and a spread of
|
||||
* the result into the element it renders keeps its required props required
|
||||
* (Partial<T> would make `alt` optional on an img).
|
||||
*/
|
||||
export default function twuiOmit<T extends object>(
|
||||
object: T,
|
||||
keys: string | string[],
|
||||
): T {
|
||||
const result = { ...object } as Record<string, unknown>;
|
||||
|
||||
for (const key of Array.isArray(keys) ? keys : [keys]) {
|
||||
delete result[key];
|
||||
}
|
||||
|
||||
return result as T;
|
||||
}
|
||||
Reference in New Issue
Block a user