mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 01:56:27 +08:00
refactor(editor): reorg code structure of store package (#9525)
This commit is contained in:
@@ -3,11 +3,6 @@ import { nanoid as nanoidGenerator } from 'nanoid';
|
||||
|
||||
export type IdGenerator = () => string;
|
||||
|
||||
export function createAutoIncrementIdGenerator(): IdGenerator {
|
||||
let i = 0;
|
||||
return () => (i++).toString();
|
||||
}
|
||||
|
||||
export const uuidv4: IdGenerator = () => {
|
||||
return uuidv4IdGenerator();
|
||||
};
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { SYS_KEYS } from '../consts.js';
|
||||
import { native2Y } from '../reactive/index.js';
|
||||
import type { BlockModel, BlockSchema } from '../schema/base.js';
|
||||
import { internalPrimitives } from '../schema/base.js';
|
||||
import type { YBlock } from '../store/doc/block/index.js';
|
||||
import type { BlockProps } from '../store/workspace.js';
|
||||
|
||||
export function syncBlockProps(
|
||||
schema: z.infer<typeof BlockSchema>,
|
||||
model: BlockModel,
|
||||
yBlock: YBlock,
|
||||
props: Partial<BlockProps>
|
||||
) {
|
||||
const defaultProps = schema.model.props?.(internalPrimitives) ?? {};
|
||||
|
||||
Object.entries(props).forEach(([key, value]) => {
|
||||
if (SYS_KEYS.has(key)) return;
|
||||
if (value === undefined) return;
|
||||
|
||||
// @ts-expect-error allow props
|
||||
model[key] = value;
|
||||
});
|
||||
|
||||
// set default value
|
||||
Object.entries(defaultProps).forEach(([key, value]) => {
|
||||
const notExists =
|
||||
!yBlock.has(`prop:${key}`) || yBlock.get(`prop:${key}`) === undefined;
|
||||
if (!notExists) {
|
||||
return;
|
||||
}
|
||||
|
||||
// @ts-expect-error allow props
|
||||
model[key] = native2Y(value);
|
||||
});
|
||||
}
|
||||
|
||||
export const hash = (str: string) => {
|
||||
return str
|
||||
.split('')
|
||||
.reduce(
|
||||
(prevHash, currVal) =>
|
||||
((prevHash << 5) - prevHash + currVal.charCodeAt(0)) | 0,
|
||||
0
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user