@blocksuite/block-std
Advanced tools
Comparing version 0.0.0-20230905170607-94acf22c-nightly to 0.0.0-20230906133203-d3774c2c-nightly
@@ -6,3 +6,3 @@ import type { BlockStore } from '../store/index.js'; | ||
export type CommandKeyToData<K extends BlockSuite.CommandDataName> = Pick<BlockSuite.CommandData, K>; | ||
export type Command<In extends BlockSuite.CommandDataName = never, Out extends BlockSuite.CommandDataName = never, InData extends object = {}> = (ctx: CommandKeyToData<In> & InitCommandCtx & InData, next: (ctx: CommandKeyToData<Out>) => Promise<void>) => Promise<void>; | ||
export type Command<In extends BlockSuite.CommandDataName = never, Out extends BlockSuite.CommandDataName = never, InData extends object = {}> = (ctx: CommandKeyToData<In> & InitCommandCtx & InData, next: (ctx?: CommandKeyToData<Out>) => Promise<void>) => Promise<void>; | ||
type Omit1<A, B> = [keyof Omit<A, keyof B>] extends [never] ? void : Omit<A, keyof B>; | ||
@@ -15,2 +15,3 @@ type InDataOfCommand<C> = C extends Command<infer K, any, infer R> ? CommandKeyToData<K> & R : never; | ||
inline: <InlineOut extends BlockSuite.CommandDataName = never>(command: Command<Extract<keyof In, BlockSuite.CommandDataName>, InlineOut>) => Chain<In & CommandKeyToData<InlineOut>>; | ||
try: (fn: (chain: Chain<In>) => Chain<In>[]) => Chain<In>; | ||
}; | ||
@@ -17,0 +18,0 @@ type Chain<In extends object = {}> = CommonMethods<In> & { |
@@ -32,2 +32,21 @@ const cmdSymbol = Symbol('cmds'); | ||
}, | ||
try: fn => { | ||
let success = false; | ||
const chains = fn(this.createChain(methods, cmds)).map(chain => chain.inline(async (_, next) => { | ||
success = true; | ||
await next(); | ||
})); | ||
return this.createChain(methods, [ | ||
...cmds, | ||
async (_, next) => { | ||
for (const chain of chains) { | ||
chain.run(); | ||
if (success) { | ||
await next(); | ||
break; | ||
} | ||
} | ||
}, | ||
]); | ||
}, | ||
...methods, | ||
@@ -34,0 +53,0 @@ }; |
{ | ||
"name": "@blocksuite/block-std", | ||
"version": "0.0.0-20230905170607-94acf22c-nightly", | ||
"version": "0.0.0-20230906133203-d3774c2c-nightly", | ||
"description": "Std for blocksuite blocks", | ||
@@ -12,10 +12,10 @@ "main": "dist/index.js", | ||
"peerDependencies": { | ||
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly" | ||
"@blocksuite/store": "0.0.0-20230906133203-d3774c2c-nightly" | ||
}, | ||
"dependencies": { | ||
"w3c-keyname": "^2.2.8", | ||
"@blocksuite/global": "0.0.0-20230905170607-94acf22c-nightly" | ||
"@blocksuite/global": "0.0.0-20230906133203-d3774c2c-nightly" | ||
}, | ||
"devDependencies": { | ||
"@blocksuite/store": "0.0.0-20230905170607-94acf22c-nightly" | ||
"@blocksuite/store": "0.0.0-20230906133203-d3774c2c-nightly" | ||
}, | ||
@@ -22,0 +22,0 @@ "exports": { |
@@ -18,3 +18,3 @@ import type { BlockStore } from '../store/index.js'; | ||
ctx: CommandKeyToData<In> & InitCommandCtx & InData, | ||
next: (ctx: CommandKeyToData<Out>) => Promise<void> | ||
next: (ctx?: CommandKeyToData<Out>) => Promise<void> | ||
) => Promise<void>; | ||
@@ -39,2 +39,3 @@ type Omit1<A, B> = [keyof Omit<A, keyof B>] extends [never] | ||
) => Chain<In & CommandKeyToData<InlineOut>>; | ||
try: (fn: (chain: Chain<In>) => Chain<In>[]) => Chain<In>; | ||
}; | ||
@@ -96,2 +97,23 @@ const cmdSymbol = Symbol('cmds'); | ||
}, | ||
try: fn => { | ||
let success = false; | ||
const chains = fn(this.createChain(methods, cmds)).map(chain => | ||
chain.inline(async (_, next) => { | ||
success = true; | ||
await next(); | ||
}) | ||
); | ||
return this.createChain(methods, [ | ||
...cmds, | ||
async (_, next) => { | ||
for (const chain of chains) { | ||
chain.run(); | ||
if (success) { | ||
await next(); | ||
break; | ||
} | ||
} | ||
}, | ||
]) as never; | ||
}, | ||
...methods, | ||
@@ -98,0 +120,0 @@ } as Chain; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
281614
3911
+ Added@blocksuite/global@0.0.0-20230906133203-d3774c2c-nightly(transitive)
+ Added@blocksuite/store@0.0.0-20230906133203-d3774c2c-nightly(transitive)
+ Added@blocksuite/virgo@0.0.0-20230906133203-d3774c2c-nightly(transitive)
- Removed@blocksuite/global@0.0.0-20230905170607-94acf22c-nightly(transitive)
- Removed@blocksuite/store@0.0.0-20230905170607-94acf22c-nightly(transitive)
- Removed@blocksuite/virgo@0.0.0-20230905170607-94acf22c-nightly(transitive)
Updated@blocksuite/global@0.0.0-20230906133203-d3774c2c-nightly