mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 00:56:26 +08:00
846350bbb1
This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [oxlint](https://oxc.rs) ([source](https://redirect.github.com/oxc-project/oxc/tree/HEAD/npm/oxlint)) | [`0.16.8` -> `0.16.9`](https://renovatebot.com/diffs/npm/oxlint/0.16.8/0.16.9) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>oxc-project/oxc (oxlint)</summary> ### [`v0.16.9`](https://redirect.github.com/oxc-project/oxc/releases/tag/oxlint_v0.16.9): oxlint v0.16.9 [Compare Source](https://redirect.github.com/oxc-project/oxc/compare/oxlint_v0.16.8...oxlint_v0.16.9) #### \[0.16.9] - 2025-05-03 ##### Features - [`63f02a8`](https://redirect.github.com/oxc-project/oxc/commit/63f02a8) linter: Add react/forward_ref_uses_ref ([#​10506](https://redirect.github.com/oxc-project/oxc/issues/10506)) (x6eull) - [`a3ada34`](https://redirect.github.com/oxc-project/oxc/commit/a3ada34) linter: Implement fixer for unicorn/prefer-number-properties ([#​10693](https://redirect.github.com/oxc-project/oxc/issues/10693)) (camc314) - [`e97a4e0`](https://redirect.github.com/oxc-project/oxc/commit/e97a4e0) linter: Add fixer to unicorn/prefer-spread ([#​10691](https://redirect.github.com/oxc-project/oxc/issues/10691)) (camc314) - [`a69a0ee`](https://redirect.github.com/oxc-project/oxc/commit/a69a0ee) linter: Add eslint/block-scoped-var ([#​10237](https://redirect.github.com/oxc-project/oxc/issues/10237)) (yefan) - [`387af3a`](https://redirect.github.com/oxc-project/oxc/commit/387af3a) linter: Report vars only used as types ([#​10664](https://redirect.github.com/oxc-project/oxc/issues/10664)) (camc314) - [`eac205f`](https://redirect.github.com/oxc-project/oxc/commit/eac205f) linter: Add unicorn/consistent-assert rule ([#​10653](https://redirect.github.com/oxc-project/oxc/issues/10653)) (Shota Kitahara) - [`0e6a727`](https://redirect.github.com/oxc-project/oxc/commit/0e6a727) linter: Add autofixer for eslint/radix ([#​10652](https://redirect.github.com/oxc-project/oxc/issues/10652)) (yefan) - [`fb070c4`](https://redirect.github.com/oxc-project/oxc/commit/fb070c4) linter/no-extra-boolean-cast: Implement auto-fixer ([#​10682](https://redirect.github.com/oxc-project/oxc/issues/10682)) (DonIsaac) - [`432cd77`](https://redirect.github.com/oxc-project/oxc/commit/432cd77) linter/no-new-wrapper: Implement auto-fixer ([#​10680](https://redirect.github.com/oxc-project/oxc/issues/10680)) (DonIsaac) ##### Bug Fixes - [`4ee95ec`](https://redirect.github.com/oxc-project/oxc/commit/4ee95ec) editor: Activate extension when astro files are opened too ([#​10725](https://redirect.github.com/oxc-project/oxc/issues/10725)) (Sysix) - [`46665bd`](https://redirect.github.com/oxc-project/oxc/commit/46665bd) langage_server: Fix initialize nested configs ([#​10698](https://redirect.github.com/oxc-project/oxc/issues/10698)) (Sysix) - [`eb3f37c`](https://redirect.github.com/oxc-project/oxc/commit/eb3f37c) language_server: On configuration change, send updated diagnostics to the client ([#​10764](https://redirect.github.com/oxc-project/oxc/issues/10764)) (Sysix) - [`8c499c6`](https://redirect.github.com/oxc-project/oxc/commit/8c499c6) linter: Fix panic when doing code gen on regexp ([#​10769](https://redirect.github.com/oxc-project/oxc/issues/10769)) (camc314) - [`8e99abf`](https://redirect.github.com/oxc-project/oxc/commit/8e99abf) linter: Fix grammer in no unused vars diagnostic msg ([#​10770](https://redirect.github.com/oxc-project/oxc/issues/10770)) (camc314) - [`b38338a`](https://redirect.github.com/oxc-project/oxc/commit/b38338a) linter: Make require post message target origin a fixer a suggestion ([#​10754](https://redirect.github.com/oxc-project/oxc/issues/10754)) (camc314) - [`48c542d`](https://redirect.github.com/oxc-project/oxc/commit/48c542d) linter: Skip linting vue <script> where `lang` is not js / ts ([#​10740](https://redirect.github.com/oxc-project/oxc/issues/10740)) (Boshen) - [`c9575f6`](https://redirect.github.com/oxc-project/oxc/commit/c9575f6) linter: Fix false positive in react/exhaustive deps ([#​10727](https://redirect.github.com/oxc-project/oxc/issues/10727)) (camc314) - [`d8d8f64`](https://redirect.github.com/oxc-project/oxc/commit/d8d8f64) linter: Shorten span of promise/prefer-await-to-then ([#​10717](https://redirect.github.com/oxc-project/oxc/issues/10717)) (camc314) - [`a88e349`](https://redirect.github.com/oxc-project/oxc/commit/a88e349) linter: Mark `isNan` and `isFinite` as dangerous fixes in `unicorn/prefer-number-properties` ([#​10706](https://redirect.github.com/oxc-project/oxc/issues/10706)) (Sysix) - [`f4ab05f`](https://redirect.github.com/oxc-project/oxc/commit/f4ab05f) linter: Panic in unicorn/no-useless-spread ([#​10715](https://redirect.github.com/oxc-project/oxc/issues/10715)) (camc314) - [`06f1717`](https://redirect.github.com/oxc-project/oxc/commit/06f1717) linter: False positive in no unused vars when importing value used as type ([#​10690](https://redirect.github.com/oxc-project/oxc/issues/10690)) (camc314) - [`746b318`](https://redirect.github.com/oxc-project/oxc/commit/746b318) linter: False positive in typescript/explicit-function-return-type with `satisfies` ([#​10668](https://redirect.github.com/oxc-project/oxc/issues/10668)) (camc314) - [`cce1043`](https://redirect.github.com/oxc-project/oxc/commit/cce1043) linter: False positive in typescript/explicit-function-return-type ([#​10667](https://redirect.github.com/oxc-project/oxc/issues/10667)) (camc314) - [`c89da93`](https://redirect.github.com/oxc-project/oxc/commit/c89da93) linter: False positive in eslint/curly on windows ([#​10671](https://redirect.github.com/oxc-project/oxc/issues/10671)) (camc314) - [`374e19e`](https://redirect.github.com/oxc-project/oxc/commit/374e19e) linter: False positive in react/jsx-curly-brace-presence ([#​10663](https://redirect.github.com/oxc-project/oxc/issues/10663)) (camc314) - [`e7c2b32`](https://redirect.github.com/oxc-project/oxc/commit/e7c2b32) linter: Move `consistent-assert` to `pedantic` ([#​10665](https://redirect.github.com/oxc-project/oxc/issues/10665)) (camc314) - [`344ef88`](https://redirect.github.com/oxc-project/oxc/commit/344ef88) linter: False positive in `eslint/no-unused-vars` when calling inside sequence expression ([#​10646](https://redirect.github.com/oxc-project/oxc/issues/10646)) (Ulrich Stark) - [`98bcd5f`](https://redirect.github.com/oxc-project/oxc/commit/98bcd5f) lsp: Incorrect quick fix offset in vue files ([#​10742](https://redirect.github.com/oxc-project/oxc/issues/10742)) (camc314) ##### Documentation - [`275fe71`](https://redirect.github.com/oxc-project/oxc/commit/275fe71) editor: `oxc.flags` are not related to `oxlint` ([#​10645](https://redirect.github.com/oxc-project/oxc/issues/10645)) (Sysix) ##### Refactor - [`2efe3f0`](https://redirect.github.com/oxc-project/oxc/commit/2efe3f0) linter: Move run on regex node to utils ([#​10772](https://redirect.github.com/oxc-project/oxc/issues/10772)) (camc314) ##### Testing - [`1c4f90f`](https://redirect.github.com/oxc-project/oxc/commit/1c4f90f) editor: Add test for nested config serverity ([#​10697](https://redirect.github.com/oxc-project/oxc/issues/10697)) (Sysix) - [`9ebf3d4`](https://redirect.github.com/oxc-project/oxc/commit/9ebf3d4) language_server: Refactor tester to use WorkspaceWorker ([#​10730](https://redirect.github.com/oxc-project/oxc/issues/10730)) (Sysix) - [`5a709ad`](https://redirect.github.com/oxc-project/oxc/commit/5a709ad) language_server: Add test for `init_nested_configs` ([#​10728](https://redirect.github.com/oxc-project/oxc/issues/10728)) (Sysix) - [`2615758`](https://redirect.github.com/oxc-project/oxc/commit/2615758) language_server: Fix slow test ([#​10659](https://redirect.github.com/oxc-project/oxc/issues/10659)) (Alexander S.) - [`fd18aaa`](https://redirect.github.com/oxc-project/oxc/commit/fd18aaa) language_server: Skip slow test ([#​10658](https://redirect.github.com/oxc-project/oxc/issues/10658)) (overlookmotel) - [`f6f1c5c`](https://redirect.github.com/oxc-project/oxc/commit/f6f1c5c) lsp: Include fixed content in lsp snapshots ([#​10744](https://redirect.github.com/oxc-project/oxc/issues/10744)) (camc314) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/toeverything/AFFiNE). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yNjQuMCIsInVwZGF0ZWRJblZlciI6IjM5LjI2NC4wIiwidGFyZ2V0QnJhbmNoIjoiY2FuYXJ5IiwibGFiZWxzIjpbImRlcGVuZGVuY2llcyJdfQ==-->
190 lines
3.9 KiB
TypeScript
190 lines
3.9 KiB
TypeScript
// Inspired by react-hot-toast library
|
|
import type {
|
|
ToastActionElement,
|
|
ToastProps,
|
|
} from '@affine/admin/components/ui/toast';
|
|
import * as React from 'react';
|
|
|
|
const TOAST_LIMIT = 1;
|
|
const TOAST_REMOVE_DELAY = 1000000;
|
|
|
|
type ToasterToast = ToastProps & {
|
|
id: string;
|
|
title?: React.ReactNode;
|
|
description?: React.ReactNode;
|
|
action?: ToastActionElement;
|
|
};
|
|
|
|
let count = 0;
|
|
|
|
function genId() {
|
|
count = (count + 1) % Number.MAX_SAFE_INTEGER;
|
|
return count.toString();
|
|
}
|
|
|
|
type ActionType = {
|
|
ADD_TOAST: 'ADD_TOAST';
|
|
UPDATE_TOAST: 'UPDATE_TOAST';
|
|
DISMISS_TOAST: 'DISMISS_TOAST';
|
|
REMOVE_TOAST: 'REMOVE_TOAST';
|
|
};
|
|
|
|
type Action =
|
|
| {
|
|
type: ActionType['ADD_TOAST'];
|
|
toast: ToasterToast;
|
|
}
|
|
| {
|
|
type: ActionType['UPDATE_TOAST'];
|
|
toast: Partial<ToasterToast>;
|
|
}
|
|
| {
|
|
type: ActionType['DISMISS_TOAST'];
|
|
toastId?: ToasterToast['id'];
|
|
}
|
|
| {
|
|
type: ActionType['REMOVE_TOAST'];
|
|
toastId?: ToasterToast['id'];
|
|
};
|
|
|
|
interface State {
|
|
toasts: ToasterToast[];
|
|
}
|
|
|
|
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
|
|
|
|
const addToRemoveQueue = (toastId: string) => {
|
|
if (toastTimeouts.has(toastId)) {
|
|
return;
|
|
}
|
|
|
|
const timeout = setTimeout(() => {
|
|
toastTimeouts.delete(toastId);
|
|
dispatch({
|
|
type: 'REMOVE_TOAST',
|
|
toastId: toastId,
|
|
});
|
|
}, TOAST_REMOVE_DELAY);
|
|
|
|
toastTimeouts.set(toastId, timeout);
|
|
};
|
|
|
|
export const reducer = (state: State, action: Action): State => {
|
|
switch (action.type) {
|
|
case 'ADD_TOAST':
|
|
return {
|
|
...state,
|
|
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
|
};
|
|
|
|
case 'UPDATE_TOAST':
|
|
return {
|
|
...state,
|
|
toasts: state.toasts.map(t =>
|
|
t.id === action.toast.id ? { ...t, ...action.toast } : t
|
|
),
|
|
};
|
|
|
|
case 'DISMISS_TOAST': {
|
|
const { toastId } = action;
|
|
|
|
// ! Side effects ! - This could be extracted into a dismissToast() action,
|
|
// but I'll keep it here for simplicity
|
|
if (toastId) {
|
|
addToRemoveQueue(toastId);
|
|
} else {
|
|
state.toasts.forEach(toast => {
|
|
addToRemoveQueue(toast.id);
|
|
});
|
|
}
|
|
|
|
return {
|
|
...state,
|
|
toasts: state.toasts.map(t =>
|
|
t.id === toastId || toastId === undefined
|
|
? {
|
|
...t,
|
|
open: false,
|
|
}
|
|
: t
|
|
),
|
|
};
|
|
}
|
|
case 'REMOVE_TOAST':
|
|
if (action.toastId === undefined) {
|
|
return {
|
|
...state,
|
|
toasts: [],
|
|
};
|
|
}
|
|
return {
|
|
...state,
|
|
toasts: state.toasts.filter(t => t.id !== action.toastId),
|
|
};
|
|
}
|
|
};
|
|
|
|
const listeners: Array<(state: State) => void> = [];
|
|
|
|
let memoryState: State = { toasts: [] };
|
|
|
|
function dispatch(action: Action) {
|
|
memoryState = reducer(memoryState, action);
|
|
listeners.forEach(listener => {
|
|
listener(memoryState);
|
|
});
|
|
}
|
|
|
|
type Toast = Omit<ToasterToast, 'id'>;
|
|
|
|
function toast({ ...props }: Toast) {
|
|
const id = genId();
|
|
|
|
const update = (props: ToasterToast) =>
|
|
dispatch({
|
|
type: 'UPDATE_TOAST',
|
|
toast: { ...props, id },
|
|
});
|
|
const dismiss = () => dispatch({ type: 'DISMISS_TOAST', toastId: id });
|
|
|
|
dispatch({
|
|
type: 'ADD_TOAST',
|
|
toast: {
|
|
...props,
|
|
id,
|
|
open: true,
|
|
onOpenChange: open => {
|
|
if (!open) dismiss();
|
|
},
|
|
},
|
|
});
|
|
|
|
return {
|
|
id: id,
|
|
dismiss,
|
|
update,
|
|
};
|
|
}
|
|
|
|
function useToast() {
|
|
const [state, setState] = React.useState<State>(memoryState);
|
|
|
|
React.useEffect(() => {
|
|
listeners.push(setState);
|
|
return () => {
|
|
const index = listeners.indexOf(setState);
|
|
if (index > -1) {
|
|
listeners.splice(index, 1);
|
|
}
|
|
};
|
|
}, [state]);
|
|
|
|
return {
|
|
...state,
|
|
toast,
|
|
dismiss: (toastId?: string) => dispatch({ type: 'DISMISS_TOAST', toastId }),
|
|
};
|
|
}
|
|
|
|
export { toast, useToast };
|