@blocksuite/global
Advanced tools
Comparing version 0.5.0-20230305195734-5878b62 to 0.5.0-20230306231625-c219ab3
@@ -47,3 +47,3 @@ import type { TemplateResult } from 'lit/html.js'; | ||
icon: TemplateResult<1>; | ||
toolTip: string; | ||
tooltip: string; | ||
} | { | ||
@@ -55,3 +55,3 @@ flavour: string; | ||
icon: TemplateResult<1>; | ||
toolTip: string; | ||
tooltip: string; | ||
})[]; | ||
@@ -64,3 +64,3 @@ export declare const BLOCKHUB_LIST_ITEMS: { | ||
icon: TemplateResult<1>; | ||
toolTip: string; | ||
tooltip: string; | ||
}[]; | ||
@@ -73,4 +73,4 @@ export declare const BLOCKHUB_FILE_ITEMS: { | ||
icon: TemplateResult<1>; | ||
toolTip: string; | ||
tooltip: string; | ||
}[]; | ||
//# sourceMappingURL=block-hub.d.ts.map |
@@ -101,3 +101,3 @@ import { BulletedListIcon, CodeBlockIcon, DividerIcon, H1Icon, H2Icon, H3Icon, H4Icon, H5Icon, H6Icon, ImageIcon, NumberedListIcon, QuoteIcon, TextIcon, TodoIcon, } from '../icons.js'; | ||
icon: TextIcon, | ||
toolTip: 'Drag to insert Text block', | ||
tooltip: 'Drag to insert Text block', | ||
}, | ||
@@ -110,3 +110,3 @@ { | ||
icon: H1Icon, | ||
toolTip: 'Drag to insert Heading 1', | ||
tooltip: 'Drag to insert Heading 1', | ||
}, | ||
@@ -119,3 +119,3 @@ { | ||
icon: H2Icon, | ||
toolTip: 'Drag to insert Heading 2', | ||
tooltip: 'Drag to insert Heading 2', | ||
}, | ||
@@ -128,3 +128,3 @@ { | ||
icon: H3Icon, | ||
toolTip: 'Drag to insert Heading 3', | ||
tooltip: 'Drag to insert Heading 3', | ||
}, | ||
@@ -137,3 +137,3 @@ { | ||
icon: H4Icon, | ||
toolTip: 'Drag to insert Heading 4', | ||
tooltip: 'Drag to insert Heading 4', | ||
}, | ||
@@ -146,3 +146,3 @@ { | ||
icon: H5Icon, | ||
toolTip: 'Drag to insert Heading 5', | ||
tooltip: 'Drag to insert Heading 5', | ||
}, | ||
@@ -155,3 +155,3 @@ { | ||
icon: H6Icon, | ||
toolTip: 'Drag to insert Heading 6', | ||
tooltip: 'Drag to insert Heading 6', | ||
}, | ||
@@ -164,3 +164,3 @@ { | ||
icon: CodeBlockIcon, | ||
toolTip: 'Drag to insert Code Block', | ||
tooltip: 'Drag to insert Code Block', | ||
}, | ||
@@ -173,3 +173,3 @@ { | ||
icon: QuoteIcon, | ||
toolTip: 'Drag to insert Quote', | ||
tooltip: 'Drag to insert Quote', | ||
}, | ||
@@ -182,3 +182,3 @@ { | ||
icon: DividerIcon, | ||
toolTip: 'A visual divider', | ||
tooltip: 'A visual divider', | ||
}, | ||
@@ -193,3 +193,3 @@ ]; | ||
icon: BulletedListIcon, | ||
toolTip: 'Drag to insert Bulleted List', | ||
tooltip: 'Drag to insert Bulleted List', | ||
}, | ||
@@ -202,3 +202,3 @@ { | ||
icon: NumberedListIcon, | ||
toolTip: 'Drag to insert Numbered List', | ||
tooltip: 'Drag to insert Numbered List', | ||
}, | ||
@@ -211,3 +211,3 @@ { | ||
icon: TodoIcon, | ||
toolTip: 'Drag to insert To-do List', | ||
tooltip: 'Drag to insert To-do List', | ||
}, | ||
@@ -222,5 +222,5 @@ ]; | ||
icon: ImageIcon, | ||
toolTip: 'Drag to insert Image', | ||
tooltip: 'Drag to insert Image', | ||
}, | ||
]; | ||
//# sourceMappingURL=block-hub.js.map |
import type { BaseBlockModel } from '@blocksuite/store'; | ||
import type { BlockModels } from './types.js'; | ||
export type { Disposable } from './utils/disposable.js'; | ||
export { DisposableGroup, flattenDisposable } from './utils/disposable.js'; | ||
export { DisposableGroup } from './utils/disposable.js'; | ||
export { Slot } from './utils/slot.js'; | ||
@@ -6,0 +6,0 @@ export { caretRangeFromPoint, isFirefox, isWeb } from './utils/web.js'; |
@@ -1,2 +0,2 @@ | ||
export { DisposableGroup, flattenDisposable } from './utils/disposable.js'; | ||
export { DisposableGroup } from './utils/disposable.js'; | ||
export { Slot } from './utils/slot.js'; | ||
@@ -3,0 +3,0 @@ export { caretRangeFromPoint, isFirefox, isWeb } from './utils/web.js'; |
@@ -0,20 +1,18 @@ | ||
type DisposeCallback = () => void; | ||
export interface Disposable { | ||
dispose(): void; | ||
dispose: DisposeCallback; | ||
} | ||
type DisposeLogic = Disposable | (() => void); | ||
export declare class DisposableGroup implements Disposable { | ||
private _disposed; | ||
private _disposables; | ||
private _disposed; | ||
get disposed(): boolean; | ||
constructor(_disposables?: DisposeLogic[]); | ||
/** | ||
* Add to group to be disposed with others. | ||
* | ||
* This will be immediately disposed if this group has already been disposed. | ||
*/ | ||
add(disposable: DisposeLogic | undefined | null | false): void; | ||
add(d: Disposable | DisposeCallback): void; | ||
dispose(): void; | ||
} | ||
export declare function flattenDisposable(disposables: Disposable[]): Disposable; | ||
export declare function flattenDisposables(disposables: Disposable[]): Disposable; | ||
export {}; | ||
//# sourceMappingURL=disposable.d.ts.map |
export class DisposableGroup { | ||
constructor() { | ||
this._disposed = false; | ||
this._disposables = []; | ||
} | ||
get disposed() { | ||
return this._disposed; | ||
} | ||
constructor(_disposables = []) { | ||
this._disposables = _disposables; | ||
this._disposed = false; | ||
} | ||
/** | ||
* Add to group to be disposed with others. | ||
* | ||
* This will be immediately disposed if this group has already been disposed. | ||
*/ | ||
add(disposable) { | ||
if (disposable) { | ||
add(d) { | ||
if (typeof d === 'function') { | ||
if (this._disposed) | ||
execDisposeLogic(disposable); | ||
d(); | ||
else | ||
this._disposables.push(disposable); | ||
this._disposables.push({ dispose: d }); | ||
} | ||
else { | ||
if (this._disposed) | ||
d.dispose(); | ||
else | ||
this._disposables.push(d); | ||
} | ||
} | ||
dispose() { | ||
disposeAllAndClearArray(this._disposables); | ||
disposeAll(this._disposables); | ||
this._disposables = []; | ||
this._disposed = true; | ||
} | ||
} | ||
export function flattenDisposable(disposables) { | ||
export function flattenDisposables(disposables) { | ||
return { | ||
dispose: disposeAllAndClearArray.bind(null, disposables), | ||
dispose: () => disposeAll(disposables), | ||
}; | ||
} | ||
/** @internal */ | ||
function disposeAllAndClearArray(disposables) { | ||
function disposeAll(disposables) { | ||
for (const disposable of disposables) { | ||
try { | ||
execDisposeLogic(disposable); | ||
disposable.dispose(); | ||
} | ||
@@ -42,11 +47,3 @@ catch (err) { | ||
} | ||
disposables.length = 0; | ||
} | ||
/** @internal */ | ||
function execDisposeLogic(disposable) { | ||
if (typeof disposable === 'function') | ||
disposable(); | ||
else | ||
disposable.dispose(); | ||
} | ||
//# sourceMappingURL=disposable.js.map |
@@ -7,7 +7,7 @@ import { Disposable } from './disposable.js'; | ||
/** | ||
* This is method will return a disposable that will remove the listener | ||
* Returns a disposable that will remove the listener | ||
*/ | ||
static disposableListener<N extends keyof WindowEventMap>(element: Window, eventName: N, handler: (e: WindowEventMap[N]) => void, options?: boolean | AddEventListenerOptions): Disposable; | ||
static disposableListener<N extends keyof DocumentEventMap>(element: Document, eventName: N, handler: (e: DocumentEventMap[N]) => void, eventOptions?: boolean | AddEventListenerOptions): Disposable; | ||
static disposableListener<N extends keyof HTMLElementEventMap>(element: HTMLElement, eventName: N, handler: (e: HTMLElementEventMap[N]) => void, eventOptions?: boolean | AddEventListenerOptions): Disposable; | ||
static fromEvent<N extends keyof WindowEventMap>(element: Window, eventName: N, handler: (e: WindowEventMap[N]) => void, options?: boolean | AddEventListenerOptions): Disposable; | ||
static fromEvent<N extends keyof DocumentEventMap>(element: Document, eventName: N, handler: (e: DocumentEventMap[N]) => void, eventOptions?: boolean | AddEventListenerOptions): Disposable; | ||
static fromEvent<N extends keyof HTMLElementEventMap>(element: HTMLElement, eventName: N, handler: (e: HTMLElementEventMap[N]) => void, eventOptions?: boolean | AddEventListenerOptions): Disposable; | ||
filter(testFun: (v: T) => boolean): Slot<T>; | ||
@@ -14,0 +14,0 @@ on(callback: (v: T) => unknown): Disposable; |
@@ -1,2 +0,2 @@ | ||
import { flattenDisposable } from './disposable.js'; | ||
import { flattenDisposables } from './disposable.js'; | ||
// borrowed from blocky-editor | ||
@@ -24,3 +24,3 @@ // https://github.com/vincentdchan/blocky-editor | ||
} | ||
static disposableListener(element, eventName, handler, eventOptions) { | ||
static fromEvent(element, eventName, handler, eventOptions) { | ||
element.addEventListener(eventName, handler, eventOptions); | ||
@@ -118,4 +118,5 @@ return { | ||
dispose() { | ||
flattenDisposable(this._disposables).dispose(); | ||
this._callbacks.length = 0; | ||
flattenDisposables(this._disposables).dispose(); | ||
this._callbacks = []; | ||
this._disposables = []; | ||
} | ||
@@ -122,0 +123,0 @@ toDispose(disposables) { |
{ | ||
"name": "@blocksuite/global", | ||
"version": "0.5.0-20230305195734-5878b62", | ||
"version": "0.5.0-20230306231625-c219ab3", | ||
"types": "./index.d.ts", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -133,3 +133,3 @@ import type { TemplateResult } from 'lit/html.js'; | ||
icon: TextIcon, | ||
toolTip: 'Drag to insert Text block', | ||
tooltip: 'Drag to insert Text block', | ||
}, | ||
@@ -142,3 +142,3 @@ { | ||
icon: H1Icon, | ||
toolTip: 'Drag to insert Heading 1', | ||
tooltip: 'Drag to insert Heading 1', | ||
}, | ||
@@ -151,3 +151,3 @@ { | ||
icon: H2Icon, | ||
toolTip: 'Drag to insert Heading 2', | ||
tooltip: 'Drag to insert Heading 2', | ||
}, | ||
@@ -160,3 +160,3 @@ { | ||
icon: H3Icon, | ||
toolTip: 'Drag to insert Heading 3', | ||
tooltip: 'Drag to insert Heading 3', | ||
}, | ||
@@ -169,3 +169,3 @@ { | ||
icon: H4Icon, | ||
toolTip: 'Drag to insert Heading 4', | ||
tooltip: 'Drag to insert Heading 4', | ||
}, | ||
@@ -178,3 +178,3 @@ { | ||
icon: H5Icon, | ||
toolTip: 'Drag to insert Heading 5', | ||
tooltip: 'Drag to insert Heading 5', | ||
}, | ||
@@ -187,3 +187,3 @@ { | ||
icon: H6Icon, | ||
toolTip: 'Drag to insert Heading 6', | ||
tooltip: 'Drag to insert Heading 6', | ||
}, | ||
@@ -196,3 +196,3 @@ { | ||
icon: CodeBlockIcon, | ||
toolTip: 'Drag to insert Code Block', | ||
tooltip: 'Drag to insert Code Block', | ||
}, | ||
@@ -205,3 +205,3 @@ { | ||
icon: QuoteIcon, | ||
toolTip: 'Drag to insert Quote', | ||
tooltip: 'Drag to insert Quote', | ||
}, | ||
@@ -214,3 +214,3 @@ { | ||
icon: DividerIcon, | ||
toolTip: 'A visual divider', | ||
tooltip: 'A visual divider', | ||
}, | ||
@@ -226,3 +226,3 @@ ]; | ||
icon: BulletedListIcon, | ||
toolTip: 'Drag to insert Bulleted List', | ||
tooltip: 'Drag to insert Bulleted List', | ||
}, | ||
@@ -235,3 +235,3 @@ { | ||
icon: NumberedListIcon, | ||
toolTip: 'Drag to insert Numbered List', | ||
tooltip: 'Drag to insert Numbered List', | ||
}, | ||
@@ -244,3 +244,3 @@ { | ||
icon: TodoIcon, | ||
toolTip: 'Drag to insert To-do List', | ||
tooltip: 'Drag to insert To-do List', | ||
}, | ||
@@ -256,4 +256,4 @@ ]; | ||
icon: ImageIcon, | ||
toolTip: 'Drag to insert Image', | ||
tooltip: 'Drag to insert Image', | ||
}, | ||
]; |
@@ -6,3 +6,3 @@ import type { BaseBlockModel } from '@blocksuite/store'; | ||
export type { Disposable } from './utils/disposable.js'; | ||
export { DisposableGroup, flattenDisposable } from './utils/disposable.js'; | ||
export { DisposableGroup } from './utils/disposable.js'; | ||
export { Slot } from './utils/slot.js'; | ||
@@ -9,0 +9,0 @@ export { caretRangeFromPoint, isFirefox, isWeb } from './utils/web.js'; |
@@ -0,26 +1,32 @@ | ||
type DisposeCallback = () => void; | ||
export interface Disposable { | ||
dispose(): void; | ||
dispose: DisposeCallback; | ||
} | ||
type DisposeLogic = Disposable | (() => void); | ||
export class DisposableGroup implements Disposable { | ||
private _disposed = false; | ||
private _disposables: Disposable[] = []; | ||
get disposed() { | ||
return this._disposed; | ||
} | ||
constructor(private _disposables: DisposeLogic[] = []) {} | ||
/** | ||
* Add to group to be disposed with others. | ||
* | ||
* This will be immediately disposed if this group has already been disposed. | ||
*/ | ||
add(disposable: DisposeLogic | undefined | null | false): void { | ||
if (disposable) { | ||
if (this._disposed) execDisposeLogic(disposable); | ||
else this._disposables.push(disposable); | ||
add(d: Disposable | DisposeCallback) { | ||
if (typeof d === 'function') { | ||
if (this._disposed) d(); | ||
else this._disposables.push({ dispose: d }); | ||
} else { | ||
if (this._disposed) d.dispose(); | ||
else this._disposables.push(d); | ||
} | ||
} | ||
dispose(): void { | ||
disposeAllAndClearArray(this._disposables); | ||
dispose() { | ||
disposeAll(this._disposables); | ||
this._disposables = []; | ||
this._disposed = true; | ||
@@ -30,13 +36,12 @@ } | ||
export function flattenDisposable(disposables: Disposable[]): Disposable { | ||
export function flattenDisposables(disposables: Disposable[]): Disposable { | ||
return { | ||
dispose: disposeAllAndClearArray.bind(null, disposables), | ||
dispose: () => disposeAll(disposables), | ||
}; | ||
} | ||
/** @internal */ | ||
function disposeAllAndClearArray(disposables: DisposeLogic[]) { | ||
function disposeAll(disposables: Disposable[]) { | ||
for (const disposable of disposables) { | ||
try { | ||
execDisposeLogic(disposable); | ||
disposable.dispose(); | ||
} catch (err) { | ||
@@ -46,9 +51,2 @@ console.error(err); | ||
} | ||
disposables.length = 0; | ||
} | ||
/** @internal */ | ||
function execDisposeLogic(disposable: DisposeLogic) { | ||
if (typeof disposable === 'function') disposable(); | ||
else disposable.dispose(); | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Disposable, flattenDisposable } from './disposable.js'; | ||
import { Disposable, flattenDisposables } from './disposable.js'; | ||
@@ -11,5 +11,5 @@ // borrowed from blocky-editor | ||
/** | ||
* This is method will return a disposable that will remove the listener | ||
* Returns a disposable that will remove the listener | ||
*/ | ||
static disposableListener<N extends keyof WindowEventMap>( | ||
static fromEvent<N extends keyof WindowEventMap>( | ||
element: Window, | ||
@@ -20,3 +20,3 @@ eventName: N, | ||
): Disposable; | ||
static disposableListener<N extends keyof DocumentEventMap>( | ||
static fromEvent<N extends keyof DocumentEventMap>( | ||
element: Document, | ||
@@ -27,3 +27,3 @@ eventName: N, | ||
): Disposable; | ||
static disposableListener<N extends keyof HTMLElementEventMap>( | ||
static fromEvent<N extends keyof HTMLElementEventMap>( | ||
element: HTMLElement, | ||
@@ -34,3 +34,3 @@ eventName: N, | ||
): Disposable; | ||
static disposableListener( | ||
static fromEvent( | ||
element: HTMLElement | Window | Document, | ||
@@ -159,4 +159,5 @@ eventName: string, | ||
dispose() { | ||
flattenDisposable(this._disposables).dispose(); | ||
this._callbacks.length = 0; | ||
flattenDisposables(this._disposables).dispose(); | ||
this._callbacks = []; | ||
this._disposables = []; | ||
} | ||
@@ -163,0 +164,0 @@ |
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
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
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
417931
4479