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