Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | 1x 6x 10x 1x 1x 1x 1x 1x 1x 1x 1x 5x 2x 1x 1x 1x 1x 1x 6x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import {
XY,
WH,
TRBL,
CacheValues,
each,
hasOwnProperty,
isNumber,
scrollLeft,
scrollTop,
assignDeep,
} from 'support';
import { OSOptions } from 'options';
import { getEnvironment } from 'environment';
import { StructureSetup } from 'setups/structureSetup';
import { lifecycleHubOservers } from 'lifecycles/lifecycleHubObservers';
import { createTrinsicLifecycle } from 'lifecycles/trinsicLifecycle';
import { createPaddingLifecycle } from 'lifecycles/paddingLifecycle';
import { createOverflowLifecycle } from 'lifecycles/overflowLifecycle';
import { StyleObject, PartialOptions } from 'typings';
import { ScrollbarsSetup } from 'setups/scrollbarsSetup';
export type LifecycleCheckOption = <T>(path: string) => LifecycleOptionInfo<T>;
export type Lifecycle = (
updateHints: LifecycleUpdateHints,
checkOption: LifecycleCheckOption,
force: boolean
) => Partial<LifecycleAdaptiveUpdateHints> | void;
export type LifecycleOptionInfo<T> = [T, boolean];
export interface LifecycleCommunication {
_paddingInfo: {
_absolute: boolean;
_padding: TRBL;
};
_viewportPaddingStyle: StyleObject;
_viewportOverflowScroll: XY<boolean>;
_viewportOverflowAmount: WH<number>;
}
export interface LifecycleAdaptiveUpdateHints {
_sizeChanged: boolean;
_hostMutation: boolean;
_contentMutation: boolean;
_paddingStyleChanged: boolean;
}
export interface LifecycleUpdateHints extends LifecycleAdaptiveUpdateHints {
_directionIsRTL: CacheValues<boolean>;
_heightIntrinsic: CacheValues<boolean>;
}
export interface LifecycleHubState {
_overflowAmount: WH<number>;
}
export interface LifecycleHubInstance {
_update(changedOptions: PartialOptions<OSOptions>, force?: boolean): void;
_state(): LifecycleHubState;
_destroy(): void;
}
export interface LifecycleHub {
_options: OSOptions;
_structureSetup: StructureSetup;
// whether the "viewport arrange" strategy must be used (true if no native scrollbar hiding and scrollbars are overlaid)
_doViewportArrange: boolean;
_getLifecycleCommunication(): LifecycleCommunication;
_setLifecycleCommunication(newLifecycleCommunication?: Partial<LifecycleCommunication>): void;
}
const getPropByPath = <T>(obj: any, path: string): T =>
obj
? path.split('.').reduce((o, prop) => (o && hasOwnProperty(o, prop) ? o[prop] : undefined), obj)
: undefined;
const booleanCacheValuesFallback: CacheValues<boolean> = [false, false, false];
const lifecycleCommunicationFallback: LifecycleCommunication = {
_paddingInfo: {
_absolute: false,
_padding: {
t: 0,
r: 0,
b: 0,
l: 0,
},
},
_viewportOverflowScroll: {
x: false,
y: false,
},
_viewportOverflowAmount: {
w: 0,
h: 0,
},
_viewportPaddingStyle: {
marginRight: 0,
marginBottom: 0,
marginLeft: 0,
paddingTop: 0,
paddingRight: 0,
paddingBottom: 0,
paddingLeft: 0,
},
};
export const createLifecycleHub = (
options: OSOptions,
structureSetup: StructureSetup,
scrollbarsSetup: ScrollbarsSetup
): LifecycleHubInstance => {
let lifecycleCommunication = lifecycleCommunicationFallback;
const { _viewport } = structureSetup._targetObj;
const {
_nativeScrollbarStyling,
_nativeScrollbarIsOverlaid,
_flexboxGlue,
_addListener: addEnvironmentListener,
_removeListener: removeEnvironmentListener,
} = getEnvironment();
const doViewportArrange =
!_nativeScrollbarStyling && (_nativeScrollbarIsOverlaid.x || _nativeScrollbarIsOverlaid.y);
const instance: LifecycleHub = {
_options: options,
_structureSetup: structureSetup,
_doViewportArrange: doViewportArrange,
_getLifecycleCommunication: () => lifecycleCommunication,
_setLifecycleCommunication(newLifecycleCommunication) {
lifecycleCommunication = assignDeep({}, lifecycleCommunication, newLifecycleCommunication);
},
};
const lifecycles: Lifecycle[] = [
createTrinsicLifecycle(instance),
createPaddingLifecycle(instance),
createOverflowLifecycle(instance),
];
const updateLifecycles = (
updateHints: Partial<LifecycleUpdateHints>,
changedOptions?: Partial<OSOptions>,
force?: boolean
) => {
let {
// eslint-disable-next-line prefer-const
_directionIsRTL,
// eslint-disable-next-line prefer-const
_heightIntrinsic,
_sizeChanged = force || false,
_hostMutation = force || false,
_contentMutation = force || false,
_paddingStyleChanged = force || false,
} = updateHints || {};
const finalDirectionIsRTL =
_directionIsRTL ||
(_sizeObserver
? _sizeObserver._getCurrentCacheValues(force)._directionIsRTL
: booleanCacheValuesFallback);
const finalHeightIntrinsic =
_heightIntrinsic ||
(_trinsicObserver
? _trinsicObserver._getCurrentCacheValues(force)._heightIntrinsic
: booleanCacheValuesFallback);
const checkOption: LifecycleCheckOption = (path) => [
getPropByPath(options, path),
force || getPropByPath(changedOptions, path) !== undefined,
];
const adjustScrollOffset = doViewportArrange || !_flexboxGlue;
const scrollOffsetX = adjustScrollOffset && scrollLeft(_viewport);
const scrollOffsetY = adjustScrollOffset && scrollTop(_viewport);
// place before updating lifecycles because of possible flushing of debounce
Eif (_updateObserverOptions) {
_updateObserverOptions(checkOption);
}
each(lifecycles, (lifecycle) => {
const {
_sizeChanged: adaptiveSizeChanged,
_hostMutation: adaptiveHostMutation,
_contentMutation: adaptiveContentMutation,
_paddingStyleChanged: adaptivePaddingStyleChanged,
} = lifecycle(
{
_directionIsRTL: finalDirectionIsRTL,
_heightIntrinsic: finalHeightIntrinsic,
_sizeChanged,
_hostMutation,
_contentMutation,
_paddingStyleChanged,
},
checkOption,
!!force
) || {};
_sizeChanged = adaptiveSizeChanged || _sizeChanged;
_hostMutation = adaptiveHostMutation || _hostMutation;
_contentMutation = adaptiveContentMutation || _contentMutation;
_paddingStyleChanged = adaptivePaddingStyleChanged || _paddingStyleChanged;
});
Eif (isNumber(scrollOffsetX)) {
scrollLeft(_viewport, scrollOffsetX);
}
Eif (isNumber(scrollOffsetY)) {
scrollTop(_viewport, scrollOffsetY);
}
Iif (options.callbacks.onUpdated) {
options.callbacks.onUpdated();
}
};
const {
_sizeObserver,
_trinsicObserver,
_updateObserverOptions,
_destroy: destroyObservers,
} = lifecycleHubOservers(instance, updateLifecycles);
const update = (changedOptions: Partial<OSOptions>, force?: boolean) =>
updateLifecycles({}, changedOptions, force);
const envUpdateListener = update.bind(0, {}, true);
addEnvironmentListener(envUpdateListener);
console.log(getEnvironment());
return {
_update: update,
_state: () => ({
_overflowAmount: lifecycleCommunication._viewportOverflowAmount,
}),
_destroy() {
destroyObservers();
removeEnvironmentListener(envUpdateListener);
structureSetup._destroy();
scrollbarsSetup._destroy();
},
};
};
|