mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-25 01:10:35 +03:00
improve public api
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
XY,
|
||||
TRBL,
|
||||
createEventListenerHub,
|
||||
isPlainObject,
|
||||
} from 'support';
|
||||
import { createStructureSetup, createScrollbarsSetup } from 'setups';
|
||||
import { getOptionsDiff, Options, ReadonlyOptions } from 'options';
|
||||
@@ -31,14 +32,19 @@ import {
|
||||
ScrollbarStructure,
|
||||
} from 'setups/scrollbarsSetup/scrollbarsSetup.elements';
|
||||
|
||||
// Notes:
|
||||
// Height intrinsic detection use "content: true" init strategy - or open ticket for custom height intrinsic observer
|
||||
|
||||
export interface OverlayScrollbarsStatic {
|
||||
(target: InitializationTarget): OverlayScrollbars | undefined;
|
||||
(
|
||||
target: InitializationTarget,
|
||||
options?: DeepPartial<Options>,
|
||||
options: DeepPartial<Options>,
|
||||
eventListeners?: GeneralInitialEventListeners<EventListenerMap>
|
||||
): OverlayScrollbars;
|
||||
|
||||
plugin(plugin: Plugin | Plugin[]): void;
|
||||
valid(osInstance: any): boolean;
|
||||
env(): Environment;
|
||||
}
|
||||
|
||||
@@ -147,27 +153,19 @@ export interface OverlayScrollbars {
|
||||
off<Name extends keyof EventListenerMap>(name: Name, listener: EventListener<Name>[]): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:
|
||||
* Height intrinsic detection use "content: true" init strategy - or open ticket for custom height intrinsic observer
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
||||
export const OverlayScrollbars: OverlayScrollbarsStatic = (
|
||||
target,
|
||||
options?,
|
||||
eventListeners?
|
||||
): OverlayScrollbars => {
|
||||
let destroyed = false;
|
||||
target: InitializationTarget,
|
||||
options?: DeepPartial<Options>,
|
||||
eventListeners?: GeneralInitialEventListeners<EventListenerMap>
|
||||
) => {
|
||||
const { _getDefaultOptions, _addListener: addEnvListener } = getEnvironment();
|
||||
const plugins = getPlugins();
|
||||
const targetIsElement = isHTMLElement(target);
|
||||
const instanceTarget = targetIsElement ? target : target.target;
|
||||
const potentialInstance = getInstance(instanceTarget);
|
||||
if (potentialInstance) {
|
||||
return potentialInstance;
|
||||
}
|
||||
|
||||
if (options && !potentialInstance) {
|
||||
let destroyed = false;
|
||||
const optionsValidationPlugin = plugins[
|
||||
optionsValidationPluginName
|
||||
] as OptionsValidationPluginInstance;
|
||||
@@ -360,9 +358,16 @@ export const OverlayScrollbars: OverlayScrollbarsStatic = (
|
||||
});
|
||||
|
||||
return instance.update(true);
|
||||
}
|
||||
return potentialInstance!;
|
||||
};
|
||||
|
||||
OverlayScrollbars.plugin = addPlugin;
|
||||
OverlayScrollbars.valid = (osInstance: any) => {
|
||||
const hasElmsFn = osInstance && (osInstance as OverlayScrollbars).elements;
|
||||
const elements = isFunction(hasElmsFn) && hasElmsFn();
|
||||
return isPlainObject(elements) && !!getInstance(elements.target);
|
||||
};
|
||||
OverlayScrollbars.env = () => {
|
||||
const {
|
||||
_nativeScrollbarsSize,
|
||||
|
||||
@@ -12,7 +12,7 @@ const pluginRegistry: Record<string, PluginInstance> = {};
|
||||
|
||||
export const getPlugins = () => pluginRegistry;
|
||||
|
||||
export const addPlugin = (addedPlugin: Plugin | Plugin[]) => {
|
||||
export const addPlugin = (addedPlugin: Plugin | Plugin[]): void => {
|
||||
each((isArray(addedPlugin) ? addedPlugin : [addedPlugin]) as Plugin[], (plugin) => {
|
||||
const pluginName = keys(plugin)[0];
|
||||
pluginRegistry[pluginName] = plugin[pluginName];
|
||||
|
||||
Reference in New Issue
Block a user