mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-21 03:20:36 +03:00
further improve project structure
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import { rAF, cAF, isEmptyArray, indexOf, createCache, runEach, push } from 'support';
|
import { rAF, cAF, isEmptyArray, indexOf, createCache, runEach, push } from 'support';
|
||||||
//import { getEnvironment } from 'environment';
|
// import { getEnvironment } from 'environment';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This code isn't used in the final build, just created it have it in case this feature is needed.
|
* This code isn't used in the final build, just created it have it in case this feature is needed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export interface AutoUpdateLoop {
|
interface AutoUpdateLoop {
|
||||||
_add(fn: (delta: number) => any): () => void;
|
_add(fn: (delta: number) => any): () => void;
|
||||||
_interval(newInterval: number): () => void;
|
_interval(newInterval: number): () => void;
|
||||||
_interval(): number;
|
_interval(): number;
|
||||||
@@ -81,7 +81,7 @@ const createAutoUpdateLoop = (): AutoUpdateLoop => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAutoUpdateLoop = (): AutoUpdateLoop => {
|
const getAutoUpdateLoop = (): AutoUpdateLoop => {
|
||||||
if (!autoUpdateLoopInstance) {
|
if (!autoUpdateLoopInstance) {
|
||||||
autoUpdateLoopInstance = createAutoUpdateLoop();
|
autoUpdateLoopInstance = createAutoUpdateLoop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +1 @@
|
|||||||
import { OSTarget, OSTargetObject } from 'typings';
|
export * from 'overlayscrollbars';
|
||||||
import { PartialOptions, validateOptions, assignDeep, isEmptyObject } from 'support';
|
|
||||||
import { createStructureSetup, StructureSetup } from 'setups/structureSetup';
|
|
||||||
import { createLifecycleHub } from 'lifecycles/lifecycleHub';
|
|
||||||
import { OSOptions, optionsTemplate } from 'options';
|
|
||||||
import { getEnvironment } from 'environment';
|
|
||||||
|
|
||||||
export interface OverlayScrollbarsStatic {
|
|
||||||
(target: OSTarget | OSTargetObject, options?: PartialOptions<OSOptions>, extensions?: any): OverlayScrollbars;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface OverlayScrollbars {
|
|
||||||
options(): OSOptions;
|
|
||||||
options(newOptions?: PartialOptions<OSOptions>): OSOptions;
|
|
||||||
|
|
||||||
update(force?: boolean): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const OverlayScrollbars: OverlayScrollbarsStatic = (
|
|
||||||
target: OSTarget | OSTargetObject,
|
|
||||||
options?: PartialOptions<OSOptions>,
|
|
||||||
extensions?: any
|
|
||||||
): OverlayScrollbars => {
|
|
||||||
const { _getDefaultOptions } = getEnvironment();
|
|
||||||
const currentOptions: OSOptions = assignDeep(
|
|
||||||
{},
|
|
||||||
_getDefaultOptions(),
|
|
||||||
validateOptions(options || ({} as PartialOptions<OSOptions>), optionsTemplate, null, true)._validated
|
|
||||||
);
|
|
||||||
const structureSetup: StructureSetup = createStructureSetup(target);
|
|
||||||
const lifecycleHub = createLifecycleHub(currentOptions, structureSetup);
|
|
||||||
const instance: OverlayScrollbars = {
|
|
||||||
options(newOptions?: PartialOptions<OSOptions>) {
|
|
||||||
if (newOptions) {
|
|
||||||
const { _validated: _changedOptions } = validateOptions(newOptions, optionsTemplate, currentOptions, true);
|
|
||||||
|
|
||||||
if (!isEmptyObject(_changedOptions)) {
|
|
||||||
assignDeep(currentOptions, _changedOptions);
|
|
||||||
lifecycleHub._update(_changedOptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return currentOptions;
|
|
||||||
},
|
|
||||||
update(force?: boolean) {
|
|
||||||
lifecycleHub._update(null, force);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
instance.update(true);
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default OverlayScrollbars;
|
|
||||||
|
|||||||
@@ -262,8 +262,6 @@ export const createLifecycleHub = (options: OSOptions, structureSetup: Structure
|
|||||||
const envUpdateListener = update.bind(null, null, true);
|
const envUpdateListener = update.bind(null, null, true);
|
||||||
addEnvironmentListener(envUpdateListener);
|
addEnvironmentListener(envUpdateListener);
|
||||||
|
|
||||||
console.log(getEnvironment());
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_update: update,
|
_update: update,
|
||||||
_destroy() {
|
_destroy() {
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { OSTarget, OSTargetObject } from 'typings';
|
||||||
|
import { PartialOptions, validateOptions, assignDeep, isEmptyObject } from 'support';
|
||||||
|
import { createStructureSetup, StructureSetup } from 'setups/structureSetup';
|
||||||
|
import { createLifecycleHub } from 'lifecycles/lifecycleHub';
|
||||||
|
import { OSOptions, optionsTemplate } from 'options';
|
||||||
|
import { getEnvironment } from 'environment';
|
||||||
|
|
||||||
|
export interface OverlayScrollbarsStatic {
|
||||||
|
(target: OSTarget | OSTargetObject, options?: PartialOptions<OSOptions>, extensions?: any): OverlayScrollbars;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OverlayScrollbars {
|
||||||
|
options(): OSOptions;
|
||||||
|
options(newOptions?: PartialOptions<OSOptions>): OSOptions;
|
||||||
|
|
||||||
|
update(force?: boolean): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const OverlayScrollbars: OverlayScrollbarsStatic = (
|
||||||
|
target: OSTarget | OSTargetObject,
|
||||||
|
options?: PartialOptions<OSOptions>,
|
||||||
|
extensions?: any
|
||||||
|
): OverlayScrollbars => {
|
||||||
|
const { _getDefaultOptions } = getEnvironment();
|
||||||
|
const currentOptions: OSOptions = assignDeep(
|
||||||
|
{},
|
||||||
|
_getDefaultOptions(),
|
||||||
|
validateOptions(options || ({} as PartialOptions<OSOptions>), optionsTemplate, null, true)._validated
|
||||||
|
);
|
||||||
|
const structureSetup: StructureSetup = createStructureSetup(target);
|
||||||
|
const lifecycleHub = createLifecycleHub(currentOptions, structureSetup);
|
||||||
|
const instance: OverlayScrollbars = {
|
||||||
|
options(newOptions?: PartialOptions<OSOptions>) {
|
||||||
|
if (newOptions) {
|
||||||
|
const { _validated: _changedOptions } = validateOptions(newOptions, optionsTemplate, currentOptions, true);
|
||||||
|
|
||||||
|
if (!isEmptyObject(_changedOptions)) {
|
||||||
|
assignDeep(currentOptions, _changedOptions);
|
||||||
|
lifecycleHub._update(_changedOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return currentOptions;
|
||||||
|
},
|
||||||
|
update(force?: boolean) {
|
||||||
|
lifecycleHub._update(null, force);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
instance.update(true);
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default OverlayScrollbars;
|
||||||
@@ -17,11 +17,11 @@ const cssNumber = {
|
|||||||
//flexshrink: 1,
|
//flexshrink: 1,
|
||||||
//fontweight: 1,
|
//fontweight: 1,
|
||||||
//lineheight: 1,
|
//lineheight: 1,
|
||||||
//opacity: 1,
|
opacity: 1,
|
||||||
//order: 1,
|
//order: 1,
|
||||||
//orphans: 1,
|
//orphans: 1,
|
||||||
//widows: 1,
|
//widows: 1,
|
||||||
//zindex: 1,
|
zindex: 1,
|
||||||
//zoom: 1,
|
//zoom: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'overlayscrollbars.scss';
|
import 'styles/overlayscrollbars.scss';
|
||||||
import { createDOM, appendChildren } from 'support';
|
import { createDOM, appendChildren } from 'support';
|
||||||
import { getEnvironment } from 'environment';
|
import { getEnvironment } from 'environment';
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
import 'overlayscrollbars.scss';
|
import 'styles/overlayscrollbars.scss';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
import { createDiv, appendChildren, parent, style, on, off, addClass, WH, XY, clientSize } from 'support';
|
import { createDiv, appendChildren, parent, style, on, off, addClass, WH, XY, clientSize } from 'support';
|
||||||
import { OverlayScrollbars } from 'overlayscrollbars/OverlayScrollbars';
|
import OverlayScrollbars from 'overlayscrollbars';
|
||||||
|
|
||||||
const targetElm = document.querySelector('#target') as HTMLElement;
|
const targetElm = document.querySelector('#target') as HTMLElement;
|
||||||
window.os = OverlayScrollbars({ target: targetElm, content: false });
|
window.os = OverlayScrollbars({ target: targetElm, content: false });
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'overlayscrollbars.scss';
|
import 'styles/overlayscrollbars.scss';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
import should from 'should';
|
import should from 'should';
|
||||||
import { generateSelectCallback, iterateSelect } from '@/testing-browser/Select';
|
import { generateSelectCallback, iterateSelect } from '@/testing-browser/Select';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'overlayscrollbars.scss';
|
import 'styles/overlayscrollbars.scss';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
import should from 'should';
|
import should from 'should';
|
||||||
// import { generateClassChangeSelectCallback, iterateSelect, setTestResult, waitForOrFailTest, timeout } from '@/testing-browser';
|
// import { generateClassChangeSelectCallback, iterateSelect, setTestResult, waitForOrFailTest, timeout } from '@/testing-browser';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'overlayscrollbars.scss';
|
import 'styles/overlayscrollbars.scss';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
import should from 'should';
|
import should from 'should';
|
||||||
import { generateClassChangeSelectCallback, iterateSelect, selectOption } from '@/testing-browser/Select';
|
import { generateClassChangeSelectCallback, iterateSelect, selectOption } from '@/testing-browser/Select';
|
||||||
@@ -118,7 +118,7 @@ const start = async () => {
|
|||||||
|
|
||||||
startBtn?.addEventListener('click', start);
|
startBtn?.addEventListener('click', start);
|
||||||
|
|
||||||
createTrinsicObserver(targetElm as HTMLElement, (widthIntrinsic, heightIntrinsicCache) => {
|
createTrinsicObserver(targetElm as HTMLElement, (heightIntrinsicCache) => {
|
||||||
if (heightIntrinsicCache._changed) {
|
if (heightIntrinsicCache._changed) {
|
||||||
heightIterations += 1;
|
heightIterations += 1;
|
||||||
heightIntrinsic = heightIntrinsicCache._value;
|
heightIntrinsic = heightIntrinsicCache._value;
|
||||||
|
|||||||
+11
-6
@@ -1,7 +1,11 @@
|
|||||||
import { getAutoUpdateLoop } from 'autoUpdateLoop';
|
// import { getAutoUpdateLoop } from 'autoUpdateLoop';
|
||||||
import { getEnvironment } from 'environment';
|
// import { getEnvironment } from 'environment';
|
||||||
|
|
||||||
describe('autoUpdateLoop', () => {
|
describe('autoUpdateLoop', () => {
|
||||||
|
test('true', () => {
|
||||||
|
expect(true).toBe(true);
|
||||||
|
});
|
||||||
|
/*
|
||||||
test('first creation', async () => {
|
test('first creation', async () => {
|
||||||
const deltas: number[] = [];
|
const deltas: number[] = [];
|
||||||
const wait = 2700;
|
const wait = 2700;
|
||||||
@@ -16,7 +20,7 @@ describe('autoUpdateLoop', () => {
|
|||||||
expect(delta >= defaultInterval).toBe(true);
|
expect(delta >= defaultInterval).toBe(true);
|
||||||
deltas.push(delta);
|
deltas.push(delta);
|
||||||
});
|
});
|
||||||
expect(getEnvironment()._autoUpdateLoop).toBe(true);
|
// expect(getEnvironment()._autoUpdateLoop).toBe(true);
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, wait));
|
await new Promise((resolve) => setTimeout(resolve, wait));
|
||||||
const elapsedDeltas = deltas.reduce((a, b) => a + b, 0);
|
const elapsedDeltas = deltas.reduce((a, b) => a + b, 0);
|
||||||
@@ -24,7 +28,7 @@ describe('autoUpdateLoop', () => {
|
|||||||
expect(wait - elapsedDeltas < defaultInterval * 2).toBe(true);
|
expect(wait - elapsedDeltas < defaultInterval * 2).toBe(true);
|
||||||
|
|
||||||
remove();
|
remove();
|
||||||
expect(getEnvironment()._autoUpdateLoop).toBe(false);
|
// expect(getEnvironment()._autoUpdateLoop).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('add multiple', async () => {
|
test('add multiple', async () => {
|
||||||
@@ -37,7 +41,7 @@ describe('autoUpdateLoop', () => {
|
|||||||
const remove2 = loop._add(fn2);
|
const remove2 = loop._add(fn2);
|
||||||
const remove3 = loop._add(fn3);
|
const remove3 = loop._add(fn3);
|
||||||
|
|
||||||
expect(getEnvironment()._autoUpdateLoop).toBe(true);
|
// expect(getEnvironment()._autoUpdateLoop).toBe(true);
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 2500));
|
await new Promise((resolve) => setTimeout(resolve, 2500));
|
||||||
|
|
||||||
@@ -49,7 +53,7 @@ describe('autoUpdateLoop', () => {
|
|||||||
remove2();
|
remove2();
|
||||||
remove3();
|
remove3();
|
||||||
|
|
||||||
expect(getEnvironment()._autoUpdateLoop).toBe(false);
|
// expect(getEnvironment()._autoUpdateLoop).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('change interval', async () => {
|
test('change interval', async () => {
|
||||||
@@ -74,4 +78,5 @@ describe('autoUpdateLoop', () => {
|
|||||||
|
|
||||||
expect(loop._interval()).toBe(defaultInterval);
|
expect(loop._interval()).toBe(defaultInterval);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
});
|
});
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { addInstance, removeInstance, getInstance, allInstances } from 'instances';
|
import { addInstance, removeInstance, getInstance, allInstances } from 'instances';
|
||||||
|
import OverlayScrollbars from 'overlayscrollbars';
|
||||||
|
|
||||||
const testElm = document.body;
|
const testElm = document.body;
|
||||||
const testInstance = { value: 'value' };
|
const testInstance = OverlayScrollbars(document.body);
|
||||||
|
|
||||||
describe('instances', () => {
|
describe('instances', () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user