mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
refactor!: remove next.js (#3267)
This commit is contained in:
15
apps/core/src/utils/create-emotion-cache.ts
Normal file
15
apps/core/src/utils/create-emotion-cache.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { isBrowser } from '@affine/env/constant';
|
||||
import createCache from '@emotion/cache';
|
||||
|
||||
export default function createEmotionCache() {
|
||||
let insertionPoint;
|
||||
|
||||
if (isBrowser) {
|
||||
const emotionInsertionPoint = document.querySelector<HTMLMetaElement>(
|
||||
'meta[name="emotion-insertion-point"]'
|
||||
);
|
||||
insertionPoint = emotionInsertionPoint ?? undefined;
|
||||
}
|
||||
|
||||
return createCache({ key: 'affine', insertionPoint });
|
||||
}
|
||||
18
apps/core/src/utils/filter.ts
Normal file
18
apps/core/src/utils/filter.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { filterByFilterList } from '@affine/component/page-list';
|
||||
import type { Collection } from '@affine/env/filter';
|
||||
import type { PageMeta } from '@blocksuite/store';
|
||||
|
||||
export const filterPage = (collection: Collection, page: PageMeta) => {
|
||||
if (collection.excludeList?.includes(page.id)) {
|
||||
return false;
|
||||
}
|
||||
if (collection.allowList?.includes(page.id)) {
|
||||
return true;
|
||||
}
|
||||
return filterByFilterList(collection.filterList, {
|
||||
'Is Favourited': !!page.favorite,
|
||||
Created: page.createDate,
|
||||
Updated: page.updatedDate ?? page.createDate,
|
||||
Tags: page.tags,
|
||||
});
|
||||
};
|
||||
3
apps/core/src/utils/index.ts
Normal file
3
apps/core/src/utils/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './create-emotion-cache';
|
||||
export * from './string2color';
|
||||
export * from './toast';
|
||||
20
apps/core/src/utils/string2color.ts
Normal file
20
apps/core/src/utils/string2color.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export function stringToColour(str: string) {
|
||||
str = str || 'affine';
|
||||
let colour = '#';
|
||||
let hash = 0;
|
||||
// str to hash
|
||||
for (
|
||||
let i = 0;
|
||||
i < str.length;
|
||||
hash = str.charCodeAt(i++) + ((hash << 5) - hash)
|
||||
);
|
||||
|
||||
// int/hash to hex
|
||||
for (
|
||||
let i = 0;
|
||||
i < 3;
|
||||
colour += ('00' + ((hash >> (i++ * 8)) & 0xff).toString(16)).slice(-2)
|
||||
);
|
||||
|
||||
return colour;
|
||||
}
|
||||
21
apps/core/src/utils/toast.ts
Normal file
21
apps/core/src/utils/toast.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { ToastOptions } from '@affine/component';
|
||||
import { toast as basicToast } from '@affine/component';
|
||||
|
||||
export const toast = (message: string, options?: ToastOptions) => {
|
||||
const mainContainer = document.querySelector(
|
||||
'.main-container'
|
||||
) as HTMLElement;
|
||||
return basicToast(message, {
|
||||
portal: mainContainer || document.body,
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
declare global {
|
||||
// global Events
|
||||
interface WindowEventMap {
|
||||
'affine-toast:emit': CustomEvent<{
|
||||
message: string;
|
||||
}>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user