diff --git a/packages/common/infra/src/utils/fractional-indexing.ts b/packages/common/infra/src/utils/fractional-indexing.ts index a5adaab78d13c..37f74d4a35f38 100644 --- a/packages/common/infra/src/utils/fractional-indexing.ts +++ b/packages/common/infra/src/utils/fractional-indexing.ts @@ -1,150 +1,5 @@ import { generateKeyBetween } from 'fractional-indexing'; -export interface SortableProvider { - getItems(): T[]; - getItemId(item: T): K; - getItemOrder(item: T): string; - setItemOrder(item: T, order: string): void; -} - -// Using fractional-indexing managing orders of items in a list -/** - * @deprecated - */ -export function createFractionalIndexingSortableHelper< - T, - K extends string | number, ->(provider: SortableProvider) { - function getOrderedItems() { - return provider.getItems().sort((a, b) => { - const oa = provider.getItemOrder(a); - const ob = provider.getItemOrder(b); - return oa > ob ? 1 : oa < ob ? -1 : 0; - }); - } - - function getLargestOrder() { - const lastItem = getOrderedItems().at(-1); - return lastItem ? provider.getItemOrder(lastItem) : null; - } - - function getSmallestOrder() { - const firstItem = getOrderedItems().at(0); - return firstItem ? provider.getItemOrder(firstItem) : null; - } - - /** - * Get a new order at the end of the list - */ - function getNewItemOrder() { - return generateKeyBetween(getLargestOrder(), null); - } - - /** - * Move item from one position to another - * - * in the most common sorting case, moving over will visually place the dragging item to the target position - * the original item in the target position will either move up or down, depending on the direction of the drag - * - * @param fromId - * @param toId - */ - function move(fromId: K, toId: K) { - const items = getOrderedItems(); - const from = items.findIndex(i => provider.getItemId(i) === fromId); - const to = items.findIndex(i => provider.getItemId(i) === toId); - const fromItem = items[from]; - const toItem = items[to]; - const toNextItem = items[from < to ? to + 1 : to - 1]; - const toOrder = toItem ? provider.getItemOrder(toItem) : null; - const toNextOrder = toNextItem ? provider.getItemOrder(toNextItem) : null; - const args: [string | null, string | null] = - from < to ? [toOrder, toNextOrder] : [toNextOrder, toOrder]; - provider.setItemOrder(fromItem, generateKeyBetween(...args)); - } - - function moveTo(fromId: K, toId: K, position: 'before' | 'after') { - const items = getOrderedItems(); - const from = items.findIndex(i => provider.getItemId(i) === fromId); - const to = items.findIndex(i => provider.getItemId(i) === toId); - const fromItem = items[from] as T | undefined; - if (fromItem === undefined) return; - const toItem = items[to] as T | undefined; - const toItemPrev = items[to - 1] as T | undefined; - const toItemNext = items[to + 1] as T | undefined; - const toItemOrder = toItem ? provider.getItemOrder(toItem) : null; - const toItemPrevOrder = toItemPrev - ? provider.getItemOrder(toItemPrev) - : null; - const toItemNextOrder = toItemNext - ? provider.getItemOrder(toItemNext) - : null; - if (position === 'before') { - provider.setItemOrder( - fromItem, - generateKeyBetween(toItemPrevOrder, toItemOrder) - ); - } else { - provider.setItemOrder( - fromItem, - generateKeyBetween(toItemOrder, toItemNextOrder) - ); - } - } - - /** - * Cases example: - * Imagine we have the following items, | a | b | c | - * 1. insertBefore('b', undefined). before is not provided, which means insert b after c - * | a | c | - * ▴ - * b - * result: | a | c | b | - * - * 2. insertBefore('b', 'a'). insert b before a - * | a | c | - * ▴ - * b - * - * result: | b | a | c | - */ - function insertBefore( - id: string | number, - beforeId: string | number | undefined - ) { - const items = getOrderedItems(); - // assert id is in the list - const item = items.find(i => provider.getItemId(i) === id); - if (!item) return; - - const beforeItemIndex = items.findIndex( - i => provider.getItemId(i) === beforeId - ); - const beforeItem = beforeItemIndex !== -1 ? items[beforeItemIndex] : null; - const beforeItemPrev = beforeItem ? items[beforeItemIndex - 1] : null; - - const beforeOrder = beforeItem ? provider.getItemOrder(beforeItem) : null; - const beforePrevOrder = beforeItemPrev - ? provider.getItemOrder(beforeItemPrev) - : null; - - provider.setItemOrder( - item, - generateKeyBetween(beforePrevOrder, beforeOrder) - ); - } - - return { - getOrderedItems, - getLargestOrder, - getSmallestOrder, - getNewItemOrder, - move, - moveTo, - insertBefore, - }; -} - /** * generate a key between a and b, the result key is always satisfied with a < result < b. * the key always has a random suffix, so there is no need to worry about collision. diff --git a/packages/frontend/core/src/modules/cloud/entities/session.ts b/packages/frontend/core/src/modules/cloud/entities/session.ts index 49018306be5e4..879105dd0e68a 100644 --- a/packages/frontend/core/src/modules/cloud/entities/session.ts +++ b/packages/frontend/core/src/modules/cloud/entities/session.ts @@ -35,8 +35,6 @@ export interface AuthSessionAuthenticated { } export class AuthSession extends Entity { - id = 'affine-cloud' as const; - session$: LiveData = LiveData.from(this.store.watchCachedAuthSession(), null).map(session => session