From 55888c812781cb4985a9fa6f04e2530da0de39b3 Mon Sep 17 00:00:00 2001 From: CokaKoala <31664583+AdrianGonz97@users.noreply.github.com> Date: Wed, 1 May 2024 14:15:53 -0400 Subject: [PATCH] chore: fix ci (#36) --- .github/workflows/ci.yml | 4 - .prettierignore | 1 - .prettierrc | 2 - package.json | 118 +++++++++--------- .../runed/src/lib/functions/box/box.svelte.ts | 44 ++++--- .../src/lib/functions/box/box.test.svelte.ts | 2 +- packages/runed/src/lib/functions/index.ts | 4 +- .../useActiveElement.svelte.ts | 2 +- .../useActiveElement.test.svelte.ts | 21 ++-- .../useDebounce/useDebounce.svelte.ts | 2 +- .../useElementSize/useElementSize.svelte.ts | 5 +- .../useEventListener.svelte.ts | 6 +- .../functions/useMounted/useMounted.svelte.ts | 2 +- .../src/lib/functions/usePrevious/index.ts | 2 +- .../usePrevious/usePrevious.svelte.ts | 16 +-- .../usePrevious/usePrevious.test.svelte.ts | 44 +++---- .../lib/functions/useStateHistory/index.ts | 2 +- .../useStateHistory/useStateHistory.svelte.ts | 75 +++++------ .../useStateHistory.test.svelte.ts | 11 +- .../useSupported/useSupported.svelte.ts | 2 +- .../runed/src/lib/functions/watch/index.ts | 2 +- .../src/lib/functions/watch/watch.svelte.ts | 8 +- .../runed/src/lib/internal/utils/array.ts | 18 ++- pnpm-workspace.yaml | 4 +- .../content/functions/use-state-history.md | 9 +- sites/docs/mdsx.config.js | 8 +- .../components/layout/footer/footer.svelte | 4 +- .../layout/sidebar/sidebar-nav-item.svelte | 5 +- .../layout/toc/table-of-contents.svelte | 11 +- .../lib/components/markdown/blueprint.svelte | 22 +--- .../docs/src/lib/components/ui/alert/index.ts | 3 +- .../src/lib/components/ui/button/index.ts | 3 +- .../lib/components/ui/sonner/sonner.svelte | 3 +- .../src/lib/components/ui/toggle/index.ts | 3 +- .../lib/styles/themes/tokyo-night-light.json | 6 +- .../lib/styles/themes/tokyo-night-storm.json | 6 +- sites/docs/src/lib/utils/styles.ts | 6 +- 37 files changed, 215 insertions(+), 271 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86f1b852..17b52637 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,11 +4,7 @@ on: push: branches: - main - paths-ignore: - - '.changeset/**' pull_request: - paths-ignore: - - '.changeset/**' concurrency: group: ${{ github.workflow }}-${{ github.event.number || github.sha }} diff --git a/.prettierignore b/.prettierignore index a4301617..f41062c8 100644 --- a/.prettierignore +++ b/.prettierignore @@ -12,7 +12,6 @@ package-lock.json yarn.lock **/.changeset/ .prettierrc -package.json .vercel .contentlayer **/dist diff --git a/.prettierrc b/.prettierrc index e15c9816..e4515501 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,6 +1,5 @@ { "useTabs": true, - "tabWidth": 4, "singleQuote": false, "trailingComma": "es5", "semi": true, @@ -19,7 +18,6 @@ "parser": "markdown", "printWidth": 100, "proseWrap": "always", - "tabWidth": 2, "useTabs": true, "trailingComma": "none", "bracketSameLine": true diff --git a/package.json b/package.json index f32e25a9..9479ca6d 100644 --- a/package.json +++ b/package.json @@ -1,60 +1,60 @@ { - "name": "root", - "description": "Monorepo for Runed.", - "private": true, - "version": "0.0.0", - "homepage": "https://runed.dev", - "contributors": [ - { - "name": "Thomas G. Lopes", - "url": "https://thomasglopes.com" - }, - { - "name": "Hunter Johnston", - "url": "https://x.com/huntabyte" - } - ], - "funding": [ - "https://github.com/sponsors/huntabyte", - "https://github.com/sponsors/tglide" - ], - "main": "index.js", - "repository": { - "type": "git", - "url": "https://github.com/svecosystem/runed" - }, - "scripts": { - "dev": "pnpm sync && pnpm --parallel dev", - "test": "pnpm -r test", - "test:package": "pnpm -F \"./packages/**\" test", - "test:package:watch": "pnpm -F \"./packages/**\" test:watch", - "build": "pnpm -r build", - "build:packages": "pnpm -F \"./packages/**\" --parallel build", - "build:content": "pnpm -F \"./sites/**\" --parallel build:content", - "ci:publish": "pnpm build:packages && changeset publish", - "lint": "prettier --check . && eslint .", - "format": "prettier --write .", - "check": "pnpm -r check", - "sync": "pnpm -r sync", - "postinstall": "pnpm -r sync" - }, - "license": "MIT", - "devDependencies": { - "@changesets/cli": "^2.27.1", - "@huntabyte/eslint-config": "^0.3.1", - "@svitejs/changesets-changelog-github-compact": "^1.1.0", - "eslint": "^9.1.1", - "eslint-plugin-svelte": "2.38.0", - "prettier": "^3.2.5", - "prettier-plugin-svelte": "^3.2.3", - "prettier-plugin-tailwindcss": "^0.5.14", - "svelte-eslint-parser": "^0.35.0", - "wrangler": "^3.52.0" - }, - "type": "module", - "pnpm": { - "overrides": { - "bits-ui@0.16.0": "^0.21.5" - } - } -} \ No newline at end of file + "name": "root", + "description": "Monorepo for Runed.", + "private": true, + "version": "0.0.0", + "homepage": "https://runed.dev", + "contributors": [ + { + "name": "Thomas G. Lopes", + "url": "https://thomasglopes.com" + }, + { + "name": "Hunter Johnston", + "url": "https://x.com/huntabyte" + } + ], + "funding": [ + "https://github.com/sponsors/huntabyte", + "https://github.com/sponsors/tglide" + ], + "main": "index.js", + "repository": { + "type": "git", + "url": "https://github.com/svecosystem/runed" + }, + "scripts": { + "dev": "pnpm sync && pnpm --parallel dev", + "test": "pnpm -r test", + "test:package": "pnpm -F \"./packages/**\" test", + "test:package:watch": "pnpm -F \"./packages/**\" test:watch", + "build": "pnpm -r build", + "build:packages": "pnpm -F \"./packages/**\" --parallel build", + "build:content": "pnpm -F \"./sites/**\" --parallel build:content", + "ci:publish": "pnpm build:packages && changeset publish", + "lint": "prettier --check . && eslint .", + "format": "prettier --write .", + "check": "pnpm -r check", + "sync": "pnpm -r sync", + "postinstall": "pnpm -r sync" + }, + "license": "MIT", + "devDependencies": { + "@changesets/cli": "^2.27.1", + "@huntabyte/eslint-config": "^0.3.1", + "@svitejs/changesets-changelog-github-compact": "^1.1.0", + "eslint": "^9.1.1", + "eslint-plugin-svelte": "2.38.0", + "prettier": "^3.2.5", + "prettier-plugin-svelte": "^3.2.3", + "prettier-plugin-tailwindcss": "^0.5.14", + "svelte-eslint-parser": "^0.35.0", + "wrangler": "^3.52.0" + }, + "type": "module", + "pnpm": { + "overrides": { + "bits-ui@0.16.0": "^0.21.5" + } + } +} diff --git a/packages/runed/src/lib/functions/box/box.svelte.ts b/packages/runed/src/lib/functions/box/box.svelte.ts index 558985ff..f12c6943 100644 --- a/packages/runed/src/lib/functions/box/box.svelte.ts +++ b/packages/runed/src/lib/functions/box/box.svelte.ts @@ -16,7 +16,7 @@ export interface WritableBox extends ReadableBox { /** * @returns Whether the value is a Box - * + * * @see {@link https://runed.dev/docs/functions/box} */ function isBox(value: unknown): value is ReadableBox { @@ -24,7 +24,7 @@ function isBox(value: unknown): value is ReadableBox { } /** * @returns Whether the value is a WritableBox - * + * * @see {@link https://runed.dev/docs/functions/box} */ function isWritableBox(value: unknown): value is WritableBox { @@ -36,7 +36,7 @@ function isWritableBox(value: unknown): value is WritableBox { * * @returns A box with a `value` property which can be set to a new value. * Useful to pass state to other functions. - * + * * @see {@link https://runed.dev/docs/functions/box} */ export function box(): WritableBox; @@ -46,7 +46,7 @@ export function box(): WritableBox; * @param initialValue The initial value of the box. * @returns A box with a `value` property which can be set to a new value. * Useful to pass state to other functions. - * + * * @see {@link https://runed.dev/docs/functions/box} */ export function box(initialValue: T): WritableBox; @@ -71,7 +71,7 @@ export function box(initialValue?: unknown) { * @param getter Function to get the value of the box * @returns A box with a `value` property whose value is the result of the getter. * Useful to pass state to other functions. - * + * * @see {@link https://runed.dev/docs/functions/box} */ function boxWith(getter: () => T): ReadableBox; @@ -82,7 +82,7 @@ function boxWith(getter: () => T): ReadableBox; * @param setter Function to set the value of the box * @returns A box with a `value` property which can be set to a new value. * Useful to pass state to other functions. - * + * * @see {@link https://runed.dev/docs/functions/box} */ function boxWith(getter: () => T, setter: (v: T) => void): WritableBox; @@ -110,25 +110,23 @@ function boxWith(getter: () => T, setter?: (v: T) => void) { }; } - - /** * Creates a box from either a static value, a box, or a getter function. * Useful when you want to receive any of these types of values and generate a boxed version of it. * * @returns A box with a `value` property whose value. - * + * * @see {@link https://runed.dev/docs/functions/box} */ function boxFrom(value: T | WritableBox): WritableBox; function boxFrom(value: ReadableBox): ReadableBox; function boxFrom(value: Getter): ReadableBox; -function boxFrom(value: MaybeBoxOrGetter): ReadableBox +function boxFrom(value: MaybeBoxOrGetter): ReadableBox; function boxFrom(value: T): WritableBox; function boxFrom(value: MaybeBoxOrGetter) { if (box.isBox(value)) return value; if (isFunction(value)) return box.with(value); - return box(value) + return box(value); } type GetKeys = { @@ -143,16 +141,16 @@ type BoxFlatten> = Expand< }, never > & - RemoveValues< - { - readonly [K in keyof R]: R[K] extends WritableBox - ? never - : R[K] extends ReadableBox - ? T - : never; - }, - never - > + RemoveValues< + { + readonly [K in keyof R]: R[K] extends WritableBox + ? never + : R[K] extends ReadableBox + ? T + : never; + }, + never + > > & RemoveValues< { @@ -168,7 +166,7 @@ type BoxFlatten> = Expand< * const count = box(0) * const flat = box.flatten({ count, double: box.with(() => count.value) }) * // type of flat is { count: number, readonly double: number } - * + * * @see {@link https://runed.dev/docs/functions/box} */ function boxFlatten>(boxes: R): BoxFlatten { @@ -205,7 +203,7 @@ function boxFlatten>(boxes: R): BoxFlatten * @example * const count = box(0) // WritableBox * const countReadonly = box.readonly(count) // ReadableBox - * + * * @see {@link https://runed.dev/docs/functions/box} */ function toReadonlyBox(b: ReadableBox): ReadableBox { diff --git a/packages/runed/src/lib/functions/box/box.test.svelte.ts b/packages/runed/src/lib/functions/box/box.test.svelte.ts index f7fa4622..45890185 100644 --- a/packages/runed/src/lib/functions/box/box.test.svelte.ts +++ b/packages/runed/src/lib/functions/box/box.test.svelte.ts @@ -176,7 +176,7 @@ describe("box types", () => { const count = 0 as MaybeBoxOrGetter; const count2 = box.from(count); expectTypeOf(count2).toMatchTypeOf>(); - }) + }); test("box.isWritableBox = true should allow box to be settable", () => { const count = box(0) as WritableBox | ReadableBox; diff --git a/packages/runed/src/lib/functions/index.ts b/packages/runed/src/lib/functions/index.ts index 1bfad924..53ed9f33 100644 --- a/packages/runed/src/lib/functions/index.ts +++ b/packages/runed/src/lib/functions/index.ts @@ -6,5 +6,5 @@ export * from "./useEventListener/index.js"; export * from "./useMounted/index.js"; export * from "./useSupported/index.js"; export * from "./useStateHistory/index.js"; -export * from './watch/index.js'; -export * from './usePrevious/index.js'; +export * from "./watch/index.js"; +export * from "./usePrevious/index.js"; diff --git a/packages/runed/src/lib/functions/useActiveElement/useActiveElement.svelte.ts b/packages/runed/src/lib/functions/useActiveElement/useActiveElement.svelte.ts index 7c85c745..b237b592 100644 --- a/packages/runed/src/lib/functions/useActiveElement/useActiveElement.svelte.ts +++ b/packages/runed/src/lib/functions/useActiveElement/useActiveElement.svelte.ts @@ -7,7 +7,7 @@ import { isBrowser } from "$lib/internal/utils/browser.js"; * * @returns an object with a reactive value `value` that is equal to `document.activeElement`, * or `null` if there's no active element. - * + * * @see {@link https://runed.dev/docs/functions/use-active-element} */ export function useActiveElement(): ReadableBox { diff --git a/packages/runed/src/lib/functions/useActiveElement/useActiveElement.test.svelte.ts b/packages/runed/src/lib/functions/useActiveElement/useActiveElement.test.svelte.ts index 5e540658..7fdabf50 100644 --- a/packages/runed/src/lib/functions/useActiveElement/useActiveElement.test.svelte.ts +++ b/packages/runed/src/lib/functions/useActiveElement/useActiveElement.test.svelte.ts @@ -8,17 +8,14 @@ describe("useActiveElement", () => { const activeElement = useActiveElement(); expect(activeElement.value).toBe(document.activeElement); }); - testWithEffect( - "updates accordingly when `document.activeElement` element changes", - async () => { - const input = document.createElement("input"); - document.body.appendChild(input); - input.focus(); + testWithEffect("updates accordingly when `document.activeElement` element changes", async () => { + const input = document.createElement("input"); + document.body.appendChild(input); + input.focus(); - const activeElement = useActiveElement(); - await tick(); - expect(document.activeElement).toBe(input); - expect(activeElement.value).toBe(input); - } - ); + const activeElement = useActiveElement(); + await tick(); + expect(document.activeElement).toBe(input); + expect(activeElement.value).toBe(input); + }); }); diff --git a/packages/runed/src/lib/functions/useDebounce/useDebounce.svelte.ts b/packages/runed/src/lib/functions/useDebounce/useDebounce.svelte.ts index ccf218ec..cd660ab1 100644 --- a/packages/runed/src/lib/functions/useDebounce/useDebounce.svelte.ts +++ b/packages/runed/src/lib/functions/useDebounce/useDebounce.svelte.ts @@ -12,7 +12,7 @@ import type { FunctionArgs, MaybeGetter } from "$lib/internal/types.js"; * The second parameter is the time to wait before calling the original callback. * Alternatively, it can also be a getter function that returns the time to wait. * - * + * * @see {@link https://runed.dev/docs/functions/use-debounce} */ export function useDebounce( diff --git a/packages/runed/src/lib/functions/useElementSize/useElementSize.svelte.ts b/packages/runed/src/lib/functions/useElementSize/useElementSize.svelte.ts index ddb90f72..10b81a0b 100644 --- a/packages/runed/src/lib/functions/useElementSize/useElementSize.svelte.ts +++ b/packages/runed/src/lib/functions/useElementSize/useElementSize.svelte.ts @@ -17,7 +17,7 @@ export type UseElementSizeOptions = { * - `box`: The box model to use. Can be either `"content-box"` or `"border-box"`. Defaults to `"border-box"`. * * @returns an object with `width` and `height` properties. - * + * * @see {@link https://runed.dev/docs/functions/use-element-size} */ export function useElementSize( @@ -37,8 +37,7 @@ export function useElementSize( const observer = new ResizeObserver((entries) => { for (const entry of entries) { - const boxSize = - options.box === "content-box" ? entry.contentBoxSize : entry.borderBoxSize; + const boxSize = options.box === "content-box" ? entry.contentBoxSize : entry.borderBoxSize; const boxSizeArr = Array.isArray(boxSize) ? boxSize : [boxSize]; size.width = boxSizeArr.reduce((acc, size) => Math.max(acc, size.inlineSize), 0); size.height = boxSizeArr.reduce((acc, size) => Math.max(acc, size.blockSize), 0); diff --git a/packages/runed/src/lib/functions/useEventListener/useEventListener.svelte.ts b/packages/runed/src/lib/functions/useEventListener/useEventListener.svelte.ts index 3449120b..d6bb719d 100644 --- a/packages/runed/src/lib/functions/useEventListener/useEventListener.svelte.ts +++ b/packages/runed/src/lib/functions/useEventListener/useEventListener.svelte.ts @@ -8,7 +8,7 @@ import { addEventListener } from "$lib/internal/utils/event.js"; * @param event The event(s) to listen for. * @param handler The function to be called when the event is triggered. * @param options An optional object that specifies characteristics about the event listener. - * + * * @see {@link https://runed.dev/docs/functions/use-event-listener} */ export function useEventListener( @@ -31,7 +31,7 @@ export function useEventListener( * @param event The event(s) to listen for. * @param handler The function to be called when the event is triggered. * @param options An optional object that specifies characteristics about the event listener. - * + * * @see {@link https://runed.dev/docs/functions/use-event-listener} */ export function useEventListener< @@ -50,7 +50,7 @@ export function useEventListener< * @param event The event(s) to listen for. * @param handler The function to be called when the event is triggered. * @param options An optional object that specifies characteristics about the event listener. - * + * * @see {@link https://runed.dev/docs/functions/use-event-listener} */ export function useEventListener( diff --git a/packages/runed/src/lib/functions/useMounted/useMounted.svelte.ts b/packages/runed/src/lib/functions/useMounted/useMounted.svelte.ts index 6febda96..74d241a1 100644 --- a/packages/runed/src/lib/functions/useMounted/useMounted.svelte.ts +++ b/packages/runed/src/lib/functions/useMounted/useMounted.svelte.ts @@ -4,7 +4,7 @@ import { type ReadableBox, box } from "../box/box.svelte.js"; /** * Returns a box with the mounted state of the component * that invokes this function. - * + * * @see {@link https://runed.dev/docs/functions/use-mounted} */ export function useMounted(): ReadableBox { diff --git a/packages/runed/src/lib/functions/usePrevious/index.ts b/packages/runed/src/lib/functions/usePrevious/index.ts index 5a65c81c..66405c0e 100644 --- a/packages/runed/src/lib/functions/usePrevious/index.ts +++ b/packages/runed/src/lib/functions/usePrevious/index.ts @@ -1 +1 @@ -export * from './usePrevious.svelte.js' \ No newline at end of file +export * from "./usePrevious.svelte.js"; diff --git a/packages/runed/src/lib/functions/usePrevious/usePrevious.svelte.ts b/packages/runed/src/lib/functions/usePrevious/usePrevious.svelte.ts index 1f44e0b2..65996881 100644 --- a/packages/runed/src/lib/functions/usePrevious/usePrevious.svelte.ts +++ b/packages/runed/src/lib/functions/usePrevious/usePrevious.svelte.ts @@ -8,14 +8,14 @@ import type { BoxOrGetter } from "$lib/internal/types.js"; * @see {@link https://runed.dev/docs/functions/use-previous} */ export function usePrevious(value: BoxOrGetter) { - const boxed = box.from(value); - let curr: T | undefined = $state() - const previous = box(undefined); + const boxed = box.from(value); + let curr: T | undefined = $state(); + const previous = box(undefined); - $effect(() => { - previous.value = untrack(() => curr); - curr = boxed.value; - }); + $effect(() => { + previous.value = untrack(() => curr); + curr = boxed.value; + }); - return previous; + return previous; } diff --git a/packages/runed/src/lib/functions/usePrevious/usePrevious.test.svelte.ts b/packages/runed/src/lib/functions/usePrevious/usePrevious.test.svelte.ts index 77079726..49eb3ad8 100644 --- a/packages/runed/src/lib/functions/usePrevious/usePrevious.test.svelte.ts +++ b/packages/runed/src/lib/functions/usePrevious/usePrevious.test.svelte.ts @@ -1,27 +1,27 @@ import { describe } from "node:test"; import { expect, test } from "vitest"; -import { box } from "../index.js"; -import { usePrevious } from "./usePrevious.svelte.js"; -import { testWithEffect } from "$lib/test/util.svelte.js"; +// import { box } from "../index.js"; +// import { usePrevious } from "./usePrevious.svelte.js"; +// import { testWithEffect } from "$lib/test/util.svelte.js"; // TODO: Find out why tests aren't working, even though the demo works -describe('usePrevious', () => { - test('dummy test', () => { - expect(true).toBe(true) - }) - // testWithEffect('Should return undefined initially', () => { - // const previous = usePrevious(() => 0); - // expect(previous.value).toBe(undefined) - // }) +describe("usePrevious", () => { + test("dummy test", () => { + expect(true).toBe(true); + }); + // testWithEffect('Should return undefined initially', () => { + // const previous = usePrevious(() => 0); + // expect(previous.value).toBe(undefined) + // }) - // testWithEffect('Should return previous value', async () => { - // const count = box(0); - // const previous = usePrevious(count); - // expect(previous.value).toBe(undefined) - // count.value = 1 - // await new Promise(resolve => setTimeout(resolve, 100)) - // expect(previous.value).toBe(0) - // count.value = 2 - // expect(previous.value).toBe(1) - // }) -}) \ No newline at end of file + // testWithEffect('Should return previous value', async () => { + // const count = box(0); + // const previous = usePrevious(count); + // expect(previous.value).toBe(undefined) + // count.value = 1 + // await new Promise(resolve => setTimeout(resolve, 100)) + // expect(previous.value).toBe(0) + // count.value = 2 + // expect(previous.value).toBe(1) + // }) +}); diff --git a/packages/runed/src/lib/functions/useStateHistory/index.ts b/packages/runed/src/lib/functions/useStateHistory/index.ts index 922c45c2..873c552a 100644 --- a/packages/runed/src/lib/functions/useStateHistory/index.ts +++ b/packages/runed/src/lib/functions/useStateHistory/index.ts @@ -1 +1 @@ -export * from './useStateHistory.svelte.js' \ No newline at end of file +export * from "./useStateHistory.svelte.js"; diff --git a/packages/runed/src/lib/functions/useStateHistory/useStateHistory.svelte.ts b/packages/runed/src/lib/functions/useStateHistory/useStateHistory.svelte.ts index 40a26933..cfcaf9f6 100644 --- a/packages/runed/src/lib/functions/useStateHistory/useStateHistory.svelte.ts +++ b/packages/runed/src/lib/functions/useStateHistory/useStateHistory.svelte.ts @@ -3,13 +3,13 @@ import { watch } from "../watch/watch.svelte.js"; import type { MaybeBoxOrGetter } from "$lib/internal/types.js"; type UseStateHistoryOptions = { - capacity?: MaybeBoxOrGetter -} + capacity?: MaybeBoxOrGetter; +}; type LogEvent = { - snapshot: T - timestamp: number -} + snapshot: T; + timestamp: number; +}; /** * Tracks the change history of a box, providing undo and redo capabilities. @@ -17,63 +17,66 @@ type LogEvent = { * @see {@link https://runed.dev/docs/functions/use-state-history} */ export function useStateHistory(b: WritableBox, options?: UseStateHistoryOptions) { - const capacity = box.from(options?.capacity) + const capacity = box.from(options?.capacity); - const log = box[]>([]) - const redoStack = box[]>([]) + const log = box[]>([]); + const redoStack = box[]>([]); - const canUndo = box.with(() => log.value.length > 1) - const canRedo = box.with(() => redoStack.value.length > 0) + const canUndo = box.with(() => log.value.length > 1); + const canRedo = box.with(() => redoStack.value.length > 0); let ignoreUpdate = false; function addEvent(event: LogEvent) { - log.value.push(event) + log.value.push(event); if (capacity.value && log.value.length > capacity.value) { - log.value = log.value.slice(-capacity.value) + log.value = log.value.slice(-capacity.value); } } - watch(() => b.value, (v) => { - if (ignoreUpdate) { - ignoreUpdate = false - return - } - - addEvent({ snapshot: v, timestamp: new Date().getTime() }) - redoStack.value = [] - }) + watch( + () => b.value, + (v) => { + if (ignoreUpdate) { + ignoreUpdate = false; + return; + } - watch(() => capacity.value, (c) => { - if (!c) return; - log.value = log.value.slice(-c) - }) + addEvent({ snapshot: v, timestamp: new Date().getTime() }); + redoStack.value = []; + } + ); + watch( + () => capacity.value, + (c) => { + if (!c) return; + log.value = log.value.slice(-c); + } + ); function undo() { - const [prev, curr] = log.value.slice(-2) + const [prev, curr] = log.value.slice(-2); if (!curr || !prev) return; ignoreUpdate = true; - redoStack.value.push(curr) - log.value.pop() - b.value = prev.snapshot + redoStack.value.push(curr); + log.value.pop(); + b.value = prev.snapshot; } function redo() { - const nextEvent = redoStack.value.pop() + const nextEvent = redoStack.value.pop(); if (!nextEvent) return; ignoreUpdate = true; - addEvent(nextEvent) - b.value = nextEvent.snapshot + addEvent(nextEvent); + b.value = nextEvent.snapshot; } - return box.flatten({ log, undo, canUndo, redo, - canRedo - }) - + canRedo, + }); } diff --git a/packages/runed/src/lib/functions/useStateHistory/useStateHistory.test.svelte.ts b/packages/runed/src/lib/functions/useStateHistory/useStateHistory.test.svelte.ts index 3f9e7241..25edcd31 100644 --- a/packages/runed/src/lib/functions/useStateHistory/useStateHistory.test.svelte.ts +++ b/packages/runed/src/lib/functions/useStateHistory/useStateHistory.test.svelte.ts @@ -1,8 +1,7 @@ -import { describe, expect, test } from "vitest" - +import { describe, expect, test } from "vitest"; describe("useStateHistory", () => { - test("dummy test", () => { - expect(true).toBe(true) - }) -}) \ No newline at end of file + test("dummy test", () => { + expect(true).toBe(true); + }); +}); diff --git a/packages/runed/src/lib/functions/useSupported/useSupported.svelte.ts b/packages/runed/src/lib/functions/useSupported/useSupported.svelte.ts index a7421edf..0238cc42 100644 --- a/packages/runed/src/lib/functions/useSupported/useSupported.svelte.ts +++ b/packages/runed/src/lib/functions/useSupported/useSupported.svelte.ts @@ -13,7 +13,7 @@ import { type ReadableBox, box } from "../box/box.svelte.js"; * // do something with navigator * } * ``` - * + * * @see {@link https://runed.dev/docs/functions/use-supported} */ export function useSupported(predicate: () => boolean): ReadableBox { diff --git a/packages/runed/src/lib/functions/watch/index.ts b/packages/runed/src/lib/functions/watch/index.ts index 705c4108..58ed11fd 100644 --- a/packages/runed/src/lib/functions/watch/index.ts +++ b/packages/runed/src/lib/functions/watch/index.ts @@ -1 +1 @@ -export * from './watch.svelte.js' \ No newline at end of file +export * from "./watch.svelte.js"; diff --git a/packages/runed/src/lib/functions/watch/watch.svelte.ts b/packages/runed/src/lib/functions/watch/watch.svelte.ts index 7186e5e9..c3297bcb 100644 --- a/packages/runed/src/lib/functions/watch/watch.svelte.ts +++ b/packages/runed/src/lib/functions/watch/watch.svelte.ts @@ -3,7 +3,7 @@ import type { Getter } from "$lib/internal/types.js"; export function watch(getDeps: Getter, callback: (args: T) => void) { $effect(() => { - const deps = getDeps() - untrack(() => callback(deps)) - }) -} \ No newline at end of file + const deps = getDeps(); + untrack(() => callback(deps)); + }); +} diff --git a/packages/runed/src/lib/internal/utils/array.ts b/packages/runed/src/lib/internal/utils/array.ts index 8e7e2030..c9081cea 100644 --- a/packages/runed/src/lib/internal/utils/array.ts +++ b/packages/runed/src/lib/internal/utils/array.ts @@ -1,19 +1,17 @@ /** * Get nth item of Array. Negative for backward */ -export function at(array: readonly [], index: number): undefined -export function at(array: readonly T[], index: number): T +export function at(array: readonly [], index: number): undefined; +export function at(array: readonly T[], index: number): T; export function at(array: readonly T[] | [], index: number): T | undefined { - const len = array.length - if (!len) - return undefined + const len = array.length; + if (!len) return undefined; - if (index < 0) - index += len + if (index < 0) index += len; - return array[index] + return array[index]; } export function last(array: readonly T[]): T | undefined { - return array[array.length - 1] -} \ No newline at end of file + return array[array.length - 1]; +} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 51853af5..52d0ce88 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,3 @@ packages: - - "packages/*" - - "sites/*" + - "packages/*" + - "sites/*" diff --git a/sites/docs/content/functions/use-state-history.md b/sites/docs/content/functions/use-state-history.md index fd2f6a3e..715f5eb2 100644 --- a/sites/docs/content/functions/use-state-history.md +++ b/sites/docs/content/functions/use-state-history.md @@ -21,7 +21,7 @@ import { box, useStateHistory } from "runed"; let count = box(0); const history = useStateHistory(count); -history.log[0] // { snapshot: 0, timestamp: ... } +history.log[0]; // { snapshot: 0, timestamp: ... } ``` You can also use `box.with` to track existing $state. @@ -30,7 +30,12 @@ You can also use `box.with` to track existing $state. import { box, useStateHistory } from "runed"; let count = $state(0); -const history = useStateHistory(box.with(() => count, (c) => count = c)); +const history = useStateHistory( + box.with( + () => count, + (c) => (count = c) + ) +); ``` Besides `log`, the returned object contains `undo` and `redo` functionality. diff --git a/sites/docs/mdsx.config.js b/sites/docs/mdsx.config.js index 742e2679..5ff37bf0 100644 --- a/sites/docs/mdsx.config.js +++ b/sites/docs/mdsx.config.js @@ -24,14 +24,10 @@ const __dirname = fileURLToPath(new URL(".", import.meta.url)); const prettyCodeOptions = { theme: { dark: JSON.parse( - String( - readFileSync(resolve(__dirname, "./src/lib/styles/themes/tokyo-night-storm.json")) - ) + String(readFileSync(resolve(__dirname, "./src/lib/styles/themes/tokyo-night-storm.json"))) ), light: JSON.parse( - String( - readFileSync(resolve(__dirname, "./src/lib/styles/themes/tokyo-night-light.json")) - ) + String(readFileSync(resolve(__dirname, "./src/lib/styles/themes/tokyo-night-light.json"))) ), }, getHighlighter: (options) => diff --git a/sites/docs/src/lib/components/layout/footer/footer.svelte b/sites/docs/src/lib/components/layout/footer/footer.svelte index 5db16775..b7c19543 100644 --- a/sites/docs/src/lib/components/layout/footer/footer.svelte +++ b/sites/docs/src/lib/components/layout/footer/footer.svelte @@ -5,9 +5,7 @@