@infinite-table/infinite-react 0.4.13 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +3 -0
- package/API.md +0 -0
- package/build/buildPackageJson.js +43 -0
- package/build/scripts/test.js +37 -0
- package/bundler.config.js +25 -0
- package/globals.d.ts +7 -0
- package/package.json +95 -3
- package/rollup.config.js +15 -0
- package/run-build-deepmap.js +47 -0
- package/run-build.js +45 -0
- package/run-dts-concat.js +21 -0
- package/src/components/CSSVariableWatch.tsx +82 -0
- package/src/components/DataSource/BooleanCollectionState.ts +214 -0
- package/src/components/DataSource/BooleanDeepCollectionState.ts +208 -0
- package/src/components/DataSource/DataSourceContext.ts +20 -0
- package/src/components/DataSource/GroupRowsState.ts +74 -0
- package/src/components/DataSource/Indexer.ts +27 -0
- package/src/components/DataSource/RowSelectionState.ts +763 -0
- package/src/components/DataSource/defaultFilterTypes.ts +64 -0
- package/src/components/DataSource/index.tsx +108 -0
- package/src/components/DataSource/privateHooks/getChangeDetect.ts +7 -0
- package/src/components/DataSource/privateHooks/useLoadData.ts +783 -0
- package/src/components/DataSource/publicHooks/useDataSource.ts +19 -0
- package/src/components/DataSource/publicHooks/useDataSourceActions.ts +14 -0
- package/src/components/DataSource/state/getInitialState.ts +494 -0
- package/src/components/DataSource/state/normalizeSortInfo.ts +35 -0
- package/src/components/DataSource/state/reducer.ts +466 -0
- package/src/components/DataSource/state/rowInfoStatus.ts +27 -0
- package/src/components/DataSource/types.ts +548 -0
- package/src/components/HeadlessTable/HeadlessTableWithPinnedContainers.tsx +142 -0
- package/src/components/HeadlessTable/MappedCells.ts +251 -0
- package/src/components/HeadlessTable/RawTable.tsx +98 -0
- package/src/components/HeadlessTable/ReactHeadlessTableRenderer.tsx +1516 -0
- package/src/components/HeadlessTable/index.tsx +234 -0
- package/src/components/InfiniteTable/InfiniteCls.css.ts +164 -0
- package/src/components/InfiniteTable/InfiniteTableContext.ts +16 -0
- package/src/components/InfiniteTable/api/getImperativeApi.ts +391 -0
- package/src/components/InfiniteTable/api/getSelectionApi.ts +364 -0
- package/src/components/InfiniteTable/api/type.ts +11 -0
- package/src/components/InfiniteTable/components/ActiveCellIndicator.css.ts +51 -0
- package/src/components/InfiniteTable/components/ActiveCellIndicator.tsx +116 -0
- package/src/components/InfiniteTable/components/ActiveRowIndicator.css.ts +56 -0
- package/src/components/InfiniteTable/components/ActiveRowIndicator.tsx +94 -0
- package/src/components/InfiniteTable/components/CheckBox.css.ts +13 -0
- package/src/components/InfiniteTable/components/CheckBox.tsx +96 -0
- package/src/components/InfiniteTable/components/FilterEditors.tsx +52 -0
- package/src/components/InfiniteTable/components/InfiniteTableBody/InfiniteTableBody.tsx +27 -0
- package/src/components/InfiniteTable/components/InfiniteTableBody/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableFooter/InfiniteTableFooter.tsx +31 -0
- package/src/components/InfiniteTable/components/InfiniteTableFooter/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableColumnHeaderFilter.tsx +102 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeader.tsx +163 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderCell.tsx +574 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderGroup.tsx +79 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderTypes.tsx +25 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderWrapper.tsx +185 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/GroupResizeHandle.tsx +159 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/ResizeHandle.css.ts +124 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/columnResizer.ts +166 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/index.tsx +146 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/buildColumnAndGroupTree.ts +240 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/header.css.ts +358 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/useColumnGroupResizeHandle.tsx +114 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/useColumnResizeHandle.tsx +146 -0
- package/src/components/InfiniteTable/components/InfiniteTableLicenseFooter/footer.css.ts +7 -0
- package/src/components/InfiniteTable/components/InfiniteTableLicenseFooter/index.tsx +110 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableCell.tsx +120 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableCellTypes.ts +74 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableColumnCell.tsx +457 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRow.tsx +107 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowClassName.ts +6 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowTypes.ts +32 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowUnvirtualized.tsx +75 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/columnRendering.tsx +263 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/row.css.ts +74 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/useRowDOMProps.ts +199 -0
- package/src/components/InfiniteTable/components/LoadMask.css.ts +34 -0
- package/src/components/InfiniteTable/components/LoadMask.tsx +27 -0
- package/src/components/InfiniteTable/components/ScrollbarPlaceholder.tsx +56 -0
- package/src/components/InfiniteTable/components/cell.css.ts +192 -0
- package/src/components/InfiniteTable/components/icons/ArrowDown.tsx +14 -0
- package/src/components/InfiniteTable/components/icons/ArrowUp.tsx +14 -0
- package/src/components/InfiniteTable/components/icons/ExpanderIcon.css.ts +31 -0
- package/src/components/InfiniteTable/components/icons/ExpanderIcon.tsx +63 -0
- package/src/components/InfiniteTable/components/icons/Icon.tsx +18 -0
- package/src/components/InfiniteTable/components/icons/InfiniteTableIconClassName.ts +1 -0
- package/src/components/InfiniteTable/components/icons/LoadingIcon.css.ts +8 -0
- package/src/components/InfiniteTable/components/icons/LoadingIcon.tsx +45 -0
- package/src/components/InfiniteTable/components/icons/MenuIcon.tsx +50 -0
- package/src/components/InfiniteTable/components/icons/SortIcon.tsx +113 -0
- package/src/components/InfiniteTable/eventHandlers/eventHandlerTypes.ts +57 -0
- package/src/components/InfiniteTable/eventHandlers/index.ts +95 -0
- package/src/components/InfiniteTable/eventHandlers/keyboardNavigation.ts +232 -0
- package/src/components/InfiniteTable/eventHandlers/keyboardSelection.ts +110 -0
- package/src/components/InfiniteTable/eventHandlers/onCellClick.ts +94 -0
- package/src/components/InfiniteTable/eventHandlers/onKeyDown.ts +25 -0
- package/src/components/InfiniteTable/hooks/adjustColumnOrderForAllColumns.ts +70 -0
- package/src/components/InfiniteTable/hooks/reorderColumnsOnDrag.ts +476 -0
- package/src/components/InfiniteTable/hooks/useAutoSizeColumns.ts +206 -0
- package/src/components/InfiniteTable/hooks/useCellClassName.ts +80 -0
- package/src/components/InfiniteTable/hooks/useCellRendering.tsx +217 -0
- package/src/components/InfiniteTable/hooks/useColumnGroups.ts +71 -0
- package/src/components/InfiniteTable/hooks/useColumnMenu.ts +72 -0
- package/src/components/InfiniteTable/hooks/useColumnPointerEvents.ts +258 -0
- package/src/components/InfiniteTable/hooks/useColumnRowspan.ts +43 -0
- package/src/components/InfiniteTable/hooks/useColumnSizeFn.ts +24 -0
- package/src/components/InfiniteTable/hooks/useColumnsWhen.ts +582 -0
- package/src/components/InfiniteTable/hooks/useComputed.ts +186 -0
- package/src/components/InfiniteTable/hooks/useComputedVisibleColumns.ts +219 -0
- package/src/components/InfiniteTable/hooks/useDOMProps.ts +306 -0
- package/src/components/InfiniteTable/hooks/useEffectWithRaf.ts +47 -0
- package/src/components/InfiniteTable/hooks/useInfiniteTable.ts +10 -0
- package/src/components/InfiniteTable/hooks/useInfiniteTableState.ts +11 -0
- package/src/components/InfiniteTable/hooks/useInternalProps.ts +8 -0
- package/src/components/InfiniteTable/hooks/useLicense/LicenseDetails.ts +13 -0
- package/src/components/InfiniteTable/hooks/useLicense/crc32.ts +56 -0
- package/src/components/InfiniteTable/hooks/useLicense/decode.ts +147 -0
- package/src/components/InfiniteTable/hooks/useLicense/useLicense.ts +39 -0
- package/src/components/InfiniteTable/hooks/useRerenderOnKeyChange.ts +21 -0
- package/src/components/InfiniteTable/hooks/useRowHover.ts +18 -0
- package/src/components/InfiniteTable/hooks/useScrollToActiveCell.ts +48 -0
- package/src/components/InfiniteTable/hooks/useScrollToActiveRow.ts +44 -0
- package/src/components/InfiniteTable/hooks/useScrollbars.ts +51 -0
- package/src/components/InfiniteTable/hooks/useToggleGroupRow.ts +56 -0
- package/src/components/InfiniteTable/hooks/useUnpinnedRendering.tsx +165 -0
- package/src/components/InfiniteTable/hooks/useYourBrain.ts +55 -0
- package/src/components/InfiniteTable/index.tsx +352 -0
- package/src/components/InfiniteTable/internalProps.ts +4 -0
- package/src/components/InfiniteTable/state/computeColumnGroupsDepths.ts +29 -0
- package/src/components/InfiniteTable/state/getColumnVisibilityForHideEmptyGroupColumns.ts +127 -0
- package/src/components/InfiniteTable/state/getInitialState.ts +375 -0
- package/src/components/InfiniteTable/theme.css.ts +556 -0
- package/src/components/InfiniteTable/types/InfiniteTableAction.ts +6 -0
- package/src/components/InfiniteTable/types/InfiniteTableActionType.ts +12 -0
- package/src/components/InfiniteTable/types/InfiniteTableColumn.ts +478 -0
- package/src/components/InfiniteTable/types/InfiniteTableComputedValues.ts +43 -0
- package/src/components/InfiniteTable/types/InfiniteTableContextValue.ts +12 -0
- package/src/components/InfiniteTable/types/InfiniteTableInternalProps.ts +3 -0
- package/src/components/InfiniteTable/types/InfiniteTableProps.ts +511 -0
- package/src/components/InfiniteTable/types/InfiniteTableState.ts +195 -0
- package/src/components/InfiniteTable/types/Utility.ts +35 -0
- package/src/components/InfiniteTable/types/index.ts +96 -0
- package/src/components/InfiniteTable/utilities.css.ts +179 -0
- package/src/components/InfiniteTable/utils/MultiRowSelector.ts +111 -0
- package/src/components/InfiniteTable/utils/RenderHookComponentForInfinite.tsx +52 -0
- package/src/components/InfiniteTable/utils/adjustColumnOrderForPinning.ts +33 -0
- package/src/components/InfiniteTable/utils/assignFiltered.ts +29 -0
- package/src/components/InfiniteTable/utils/defaultGetColumContextMenuItems.tsx +108 -0
- package/src/components/InfiniteTable/utils/getColumnComputedType.ts +33 -0
- package/src/components/InfiniteTable/utils/getColumnForGroupBy.tsx +313 -0
- package/src/components/InfiniteTable/utils/getComputedVisibleColumns.ts +773 -0
- package/src/components/InfiniteTable/utils/getContextMenuForColumn.tsx +72 -0
- package/src/components/InfiniteTable/utils/infiniteDOMUtils.ts +189 -0
- package/src/components/InfiniteTable/utils/mapToObject.ts +20 -0
- package/src/components/InfiniteTable/utils/moveXatY.ts +25 -0
- package/src/components/InfiniteTable/utils/objectValuesExcept.ts +9 -0
- package/src/components/InfiniteTable/utils/progressiveSpeedScroller.ts +158 -0
- package/src/components/InfiniteTable/utils/rafFn.ts +13 -0
- package/src/components/InfiniteTable/utils/toCSSVarName.ts +1 -0
- package/src/components/InfiniteTable/utils/toMap.ts +24 -0
- package/src/components/Menu/Menu.tsx +750 -0
- package/src/components/Menu/MenuCls.css.ts +139 -0
- package/src/components/Menu/MenuContext.ts +10 -0
- package/src/components/Menu/MenuContextValue.ts +15 -0
- package/src/components/Menu/MenuProps.ts +98 -0
- package/src/components/Menu/MenuState.ts +56 -0
- package/src/components/Menu/MenuTriangleContext.ts +352 -0
- package/src/components/Menu/childrenToRuntimeItems.tsx +103 -0
- package/src/components/Menu/getMenuState.tsx +119 -0
- package/src/components/Menu/index.tsx +88 -0
- package/src/components/Menu/propToIdentifyMenu.ts +1 -0
- package/src/components/RawList/AvoidReactDiff.tsx +48 -0
- package/src/components/RawList/MappedItems.ts +143 -0
- package/src/components/RawList/ReactVirtualRenderer.tsx +307 -0
- package/src/components/RawList/index.tsx +42 -0
- package/src/components/RawList/types.ts +23 -0
- package/src/components/RawList/useVirtualRenderer.ts +36 -0
- package/src/components/RenderHookComponent.tsx +10 -0
- package/src/components/ResizeObserver/index.tsx +170 -0
- package/src/components/VirtualBrain/MatrixBrain.ts +1621 -0
- package/src/components/VirtualBrain/ScrollListener.ts +39 -0
- package/src/components/VirtualBrain/index.ts +664 -0
- package/src/components/VirtualList/ColumnListWithExternalScrolling.tsx +78 -0
- package/src/components/VirtualList/InfiniteListRootClassName.ts +1 -0
- package/src/components/VirtualList/RowListWithExternalScrolling.tsx +120 -0
- package/src/components/VirtualList/SpacePlaceholder.tsx +32 -0
- package/src/components/VirtualList/VirtualList.css.ts +29 -0
- package/src/components/VirtualList/VirtualList.tsx +141 -0
- package/src/components/VirtualList/VirtualRowList.tsx +34 -0
- package/src/components/VirtualList/types.ts +56 -0
- package/src/components/VirtualList/useCorrectHeightForRowElements.ts +14 -0
- package/src/components/VirtualScrollContainer/VirtualScrollContainer.css.ts +51 -0
- package/src/components/VirtualScrollContainer/getScrollableClassName.ts +30 -0
- package/src/components/VirtualScrollContainer/index.tsx +63 -0
- package/src/components/flexbox/index.ts +562 -0
- package/src/components/hooks/useComponentState/index.tsx +562 -0
- package/src/components/hooks/useComponentState/types.ts +32 -0
- package/src/components/hooks/useEffectOnceWithProperUnmount.ts +33 -0
- package/src/components/hooks/useEffectWithChanges.ts +56 -0
- package/src/components/hooks/useImmutableRef.ts +7 -0
- package/src/components/hooks/useInterceptedMap.ts +71 -0
- package/src/components/hooks/useLatest.tsx +8 -0
- package/src/components/hooks/useLazyLatest.ts +23 -0
- package/src/components/hooks/useMemoShallowObjectMerge.ts +16 -0
- package/src/components/hooks/useMounted.ts +18 -0
- package/src/components/hooks/useOnMount.ts +21 -0
- package/src/components/hooks/useOnScroll.ts +34 -0
- package/src/components/hooks/useOnce.ts +10 -0
- package/src/components/hooks/useOverlay/index.tsx +418 -0
- package/src/components/hooks/usePrevious.ts +8 -0
- package/src/components/hooks/usePropertyOld.ts +168 -0
- package/src/components/hooks/useRerender.ts +12 -0
- package/src/components/hooks/xuseProperty.ts +165 -0
- package/src/components/types/CellPosition.ts +4 -0
- package/src/components/types/NonUndefined.ts +1 -0
- package/src/components/types/RemoveObject.ts +22 -0
- package/src/components/types/Renderable.ts +3 -0
- package/src/components/types/ScrollPosition.ts +7 -0
- package/src/components/types/Setter.ts +2 -0
- package/src/components/types/Size.ts +6 -0
- package/src/components/types/SubscriptionCallback.ts +10 -0
- package/src/components/types/VoidFn.ts +1 -0
- package/src/components/utils/buildSubscriptionCallback.tsx +60 -0
- package/src/components/utils/clamp.ts +3 -0
- package/src/components/utils/debounce.ts +16 -0
- package/src/components/utils/decamelize.ts +11 -0
- package/src/components/utils/discardCallsWithEqualArg.ts +42 -0
- package/src/components/utils/getRenderIndexes.ts +33 -0
- package/src/components/utils/getScrollbarWidth.ts +31 -0
- package/src/components/utils/getVirtualRenderCount.ts +21 -0
- package/src/components/utils/isControlled.ts +12 -0
- package/src/components/utils/isControlledValue.ts +5 -0
- package/src/index.tsx +34 -0
- package/src/test.tsx +18 -0
- package/src/utils/DeepMap/index.ts +588 -0
- package/src/utils/DeepMap/once.ts +16 -0
- package/src/utils/DeepMap/sortAscending.ts +1 -0
- package/src/utils/DeepMap/tsconfig.deepmap.json +17 -0
- package/src/utils/DeepMap/xpackage.json +26 -0
- package/src/utils/debug.ts +40 -0
- package/src/utils/deepClone.ts +38 -0
- package/src/utils/getGlobal.ts +3 -0
- package/src/utils/groupAndPivot/defaultToKey.ts +3 -0
- package/src/utils/groupAndPivot/getGroupKeysForDataItem.ts +19 -0
- package/src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts +361 -0
- package/src/utils/groupAndPivot/index.ts +1229 -0
- package/src/utils/groupAndPivot/types.ts +10 -0
- package/src/utils/join.ts +4 -0
- package/src/utils/mathIntersection.ts +21 -0
- package/src/utils/minified.d.ts +2 -0
- package/src/utils/minified.js +6 -0
- package/src/utils/multisort/index.ts +151 -0
- package/src/utils/multisort/sortTypes.ts +25 -0
- package/src/utils/notes-status.md +92 -0
- package/src/utils/pageGeometry/ConvexPoly.ts +34 -0
- package/src/utils/pageGeometry/Point.ts +51 -0
- package/src/utils/pageGeometry/PolyWithPoints.ts +52 -0
- package/src/utils/pageGeometry/Rectangle.ts +98 -0
- package/src/utils/pageGeometry/Triangle.ts +16 -0
- package/src/utils/pageGeometry/alignment/index.ts +221 -0
- package/src/utils/pageGeometry/polyContainsPoint.ts +182 -0
- package/src/utils/pageGeometry/types.ts +3 -0
- package/src/utils/proxyFnCall.ts +46 -0
- package/src/utils/raf.ts +13 -0
- package/src/utils/selectParent.ts +18 -0
- package/src/utils/shallowEqualObjects.ts +49 -0
- package/src/utils/stripVar.ts +3 -0
- package/src/utils/toUpperFirst.ts +5 -0
- package/todo.md +2 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.dev.json +7 -0
- package/tsconfig.json +30 -0
- package/tsconfig.typebundler.json +13 -0
- package/typedoc.json +4 -0
- package/README.md +0 -104
- package/index.css +0 -857
- package/index.d.ts +0 -2111
- package/index.esm.css +0 -857
- package/index.esm.js +0 -13695
- package/index.js +0 -13565
package/src/index.tsx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { debounce } from './components/utils/debounce';
|
|
2
|
+
|
|
3
|
+
export * from './components/InfiniteTable';
|
|
4
|
+
|
|
5
|
+
export * from './components/DataSource';
|
|
6
|
+
export * from './components/Menu';
|
|
7
|
+
export * from './components/Menu/MenuProps';
|
|
8
|
+
export * from './components/hooks/useOverlay';
|
|
9
|
+
|
|
10
|
+
import { InfiniteCheckBox } from './components/InfiniteTable/components/CheckBox';
|
|
11
|
+
import { LoadMask } from './components/InfiniteTable/components/LoadMask';
|
|
12
|
+
|
|
13
|
+
export const components = {
|
|
14
|
+
CheckBox: InfiniteCheckBox,
|
|
15
|
+
LoadMask,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { group, flatten } from './utils/groupAndPivot';
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
useComponentState,
|
|
22
|
+
getComponentStateRoot,
|
|
23
|
+
} from './components/hooks/useComponentState';
|
|
24
|
+
|
|
25
|
+
export { interceptMap } from './components/hooks/useInterceptedMap';
|
|
26
|
+
|
|
27
|
+
export { useEffectWithChanges } from './components/hooks/useEffectWithChanges';
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
defaultFilterEditors,
|
|
31
|
+
StringFilterEditor,
|
|
32
|
+
NumberFilterEditor,
|
|
33
|
+
} from './components/InfiniteTable/components/FilterEditors';
|
|
34
|
+
export { defaultFilterTypes } from './components/DataSource/defaultFilterTypes';
|
package/src/test.tsx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as CSS from 'csstype';
|
|
2
|
+
|
|
3
|
+
const x: CSS.PositionProperty = 'relative';
|
|
4
|
+
console.log(x);
|
|
5
|
+
|
|
6
|
+
import * as PropTypes from 'prop-types';
|
|
7
|
+
import { ReactNodeArray } from 'prop-types';
|
|
8
|
+
|
|
9
|
+
import { Dispatch } from 'react';
|
|
10
|
+
|
|
11
|
+
const arr: PropTypes.ReactNodeArray = [];
|
|
12
|
+
const arr1: ReactNodeArray = [];
|
|
13
|
+
|
|
14
|
+
const d: Dispatch<string> = (_x: string) => {};
|
|
15
|
+
|
|
16
|
+
console.log(arr);
|
|
17
|
+
console.log(arr1);
|
|
18
|
+
console.log(d);
|
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import { once } from './once';
|
|
2
|
+
import { sortAscending } from './sortAscending';
|
|
3
|
+
|
|
4
|
+
type VoidFn = () => void;
|
|
5
|
+
|
|
6
|
+
type Pair<KeyType, ValueType> = {
|
|
7
|
+
value?: ValueType;
|
|
8
|
+
map?: Map<KeyType, Pair<KeyType, ValueType>>;
|
|
9
|
+
length: number;
|
|
10
|
+
revision?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const SORT_ASC_REVISION = (p1: Pair<any, any>, p2: Pair<any, any>) =>
|
|
14
|
+
sortAscending(p1.revision!, p2.revision!);
|
|
15
|
+
|
|
16
|
+
export type DeepMapVisitFn<KeyType, ValueType> = (
|
|
17
|
+
pair: Pair<KeyType, ValueType>,
|
|
18
|
+
keys: KeyType[],
|
|
19
|
+
next: VoidFn,
|
|
20
|
+
) => void;
|
|
21
|
+
|
|
22
|
+
export class DeepMap<KeyType, ValueType> {
|
|
23
|
+
private map = new Map<KeyType, Pair<KeyType, ValueType>>();
|
|
24
|
+
private length = 0;
|
|
25
|
+
private revision = 0;
|
|
26
|
+
private emptyKey = Symbol('emptyKey') as any as KeyType;
|
|
27
|
+
|
|
28
|
+
static clone<KeyType, ValueType>(map: DeepMap<KeyType, ValueType>) {
|
|
29
|
+
const clone = new DeepMap<KeyType, ValueType>();
|
|
30
|
+
|
|
31
|
+
map.visit((pair, keys) => {
|
|
32
|
+
clone.set(keys, pair.value!);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return clone;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
constructor(initial?: [KeyType[], ValueType][]) {
|
|
39
|
+
this.fill(initial);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fill(initial?: [KeyType[], ValueType][]) {
|
|
43
|
+
if (initial) {
|
|
44
|
+
initial.forEach((entry) => {
|
|
45
|
+
const [keys, value] = entry;
|
|
46
|
+
|
|
47
|
+
this.set(keys, value);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getValuesStartingWith(
|
|
53
|
+
keys: KeyType[],
|
|
54
|
+
excludeSelf?: boolean,
|
|
55
|
+
depthLimit?: number,
|
|
56
|
+
): ValueType[] {
|
|
57
|
+
const result: ValueType[] = [];
|
|
58
|
+
this.getStartingWith(
|
|
59
|
+
keys,
|
|
60
|
+
(_keys, value) => {
|
|
61
|
+
result.push(value);
|
|
62
|
+
},
|
|
63
|
+
excludeSelf,
|
|
64
|
+
depthLimit,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getKeysStartingWith(
|
|
71
|
+
keys: KeyType[],
|
|
72
|
+
excludeSelf?: boolean,
|
|
73
|
+
depthLimit?: number,
|
|
74
|
+
): KeyType[][] {
|
|
75
|
+
const result: KeyType[][] = [];
|
|
76
|
+
this.getStartingWith(
|
|
77
|
+
keys,
|
|
78
|
+
(keys) => {
|
|
79
|
+
result.push(keys);
|
|
80
|
+
},
|
|
81
|
+
excludeSelf,
|
|
82
|
+
depthLimit,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private getStartingWith(
|
|
89
|
+
keys: KeyType[],
|
|
90
|
+
fn: (key: KeyType[], value: ValueType) => void,
|
|
91
|
+
excludeSelf?: boolean,
|
|
92
|
+
depthLimit?: number,
|
|
93
|
+
) {
|
|
94
|
+
let currentMap = this.map;
|
|
95
|
+
let pair: Pair<KeyType, ValueType> | undefined;
|
|
96
|
+
let stop = false;
|
|
97
|
+
|
|
98
|
+
if (keys.length) {
|
|
99
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
100
|
+
const key = keys[i];
|
|
101
|
+
|
|
102
|
+
pair = currentMap.get(key);
|
|
103
|
+
|
|
104
|
+
if (!pair || !pair.map) {
|
|
105
|
+
stop = true;
|
|
106
|
+
if (i === len - 1) {
|
|
107
|
+
// if on the last key
|
|
108
|
+
// we want to allow the if clause below to run and check if the value on the last
|
|
109
|
+
// pair is present
|
|
110
|
+
stop = true;
|
|
111
|
+
break;
|
|
112
|
+
} else {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
currentMap = pair.map;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (pair && pair.value !== undefined) {
|
|
122
|
+
if (!excludeSelf) {
|
|
123
|
+
fn(keys, pair.value!);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (stop) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.visitWithNext(
|
|
131
|
+
keys,
|
|
132
|
+
(value, keys, _i, next) => {
|
|
133
|
+
fn(keys, value);
|
|
134
|
+
next?.();
|
|
135
|
+
},
|
|
136
|
+
currentMap,
|
|
137
|
+
depthLimit,
|
|
138
|
+
excludeSelf,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private getMapAt(keys: KeyType[]) {
|
|
143
|
+
let currentMap = this.map;
|
|
144
|
+
let pair: Pair<KeyType, ValueType> | undefined;
|
|
145
|
+
if (!keys.length) {
|
|
146
|
+
return this.map;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
150
|
+
const key = keys[i];
|
|
151
|
+
|
|
152
|
+
pair = currentMap.get(key);
|
|
153
|
+
|
|
154
|
+
if (!pair || !pair.map) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
currentMap = pair.map;
|
|
159
|
+
}
|
|
160
|
+
return currentMap;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getAllChildrenSizeFor(keys: KeyType[]) {
|
|
164
|
+
let currentMap = this.map;
|
|
165
|
+
let pair: Pair<KeyType, ValueType> | undefined;
|
|
166
|
+
if (!keys.length) {
|
|
167
|
+
return this.length;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
171
|
+
const key = keys[i];
|
|
172
|
+
|
|
173
|
+
pair = currentMap.get(key);
|
|
174
|
+
|
|
175
|
+
if (!pair || !pair.map) {
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
currentMap = pair.map;
|
|
180
|
+
}
|
|
181
|
+
return pair!.length;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
getDirectChildrenSizeFor(keys: KeyType[]) {
|
|
185
|
+
let currentMap = this.map;
|
|
186
|
+
if (!keys.length) {
|
|
187
|
+
keys = [this.emptyKey];
|
|
188
|
+
}
|
|
189
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
190
|
+
const key = keys[i];
|
|
191
|
+
const last = i === len - 1;
|
|
192
|
+
const pair = currentMap.get(key);
|
|
193
|
+
|
|
194
|
+
if (!pair || !pair.map) {
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
currentMap = pair.map;
|
|
198
|
+
if (last) {
|
|
199
|
+
return currentMap?.size ?? 0;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return 0;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
set(keys: KeyType[] & { length: Omit<number, 0> }, value: ValueType) {
|
|
206
|
+
let currentMap = this.map;
|
|
207
|
+
if (!keys.length) {
|
|
208
|
+
keys = [this.emptyKey];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
212
|
+
const key = keys[i];
|
|
213
|
+
const last = i === len - 1;
|
|
214
|
+
const pair = currentMap.get(key)! || {
|
|
215
|
+
length: 0,
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
if (last) {
|
|
219
|
+
pair.revision = this.revision++;
|
|
220
|
+
pair.value = value;
|
|
221
|
+
|
|
222
|
+
currentMap.set(key, pair);
|
|
223
|
+
this.length++;
|
|
224
|
+
} else {
|
|
225
|
+
if (!pair.map) {
|
|
226
|
+
pair.map = new Map<KeyType, Pair<KeyType, ValueType>>();
|
|
227
|
+
currentMap.set(key, pair);
|
|
228
|
+
}
|
|
229
|
+
pair.length++;
|
|
230
|
+
|
|
231
|
+
currentMap = pair.map;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
get(keys: KeyType[]): ValueType | undefined {
|
|
239
|
+
let currentMap = this.map;
|
|
240
|
+
if (!keys.length) {
|
|
241
|
+
keys = [this.emptyKey];
|
|
242
|
+
}
|
|
243
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
244
|
+
const key = keys[i];
|
|
245
|
+
const last = i === len - 1;
|
|
246
|
+
const pair = currentMap.get(key);
|
|
247
|
+
if (last) {
|
|
248
|
+
return pair ? pair.value : undefined;
|
|
249
|
+
} else {
|
|
250
|
+
if (!pair || !pair.map) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
currentMap = pair.map;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
get size() {
|
|
260
|
+
return this.length;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
clear() {
|
|
264
|
+
const clearMap = (map: Map<KeyType, Pair<KeyType, ValueType>>) => {
|
|
265
|
+
map.forEach((value, _key) => {
|
|
266
|
+
const { map } = value;
|
|
267
|
+
if (map) {
|
|
268
|
+
clearMap(map);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
map.clear();
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
clearMap(this.map);
|
|
276
|
+
|
|
277
|
+
this.length = 0;
|
|
278
|
+
this.revision = 0;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
delete(keys: KeyType[]): boolean {
|
|
282
|
+
let currentMap = this.map;
|
|
283
|
+
if (!keys.length) {
|
|
284
|
+
keys = [this.emptyKey];
|
|
285
|
+
} else {
|
|
286
|
+
keys = [...keys];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const maps = [currentMap];
|
|
290
|
+
const pairs = [];
|
|
291
|
+
|
|
292
|
+
let result = false;
|
|
293
|
+
|
|
294
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
295
|
+
const key = keys[i];
|
|
296
|
+
const last = i === len - 1;
|
|
297
|
+
const pair = currentMap.get(key);
|
|
298
|
+
if (last) {
|
|
299
|
+
if (pair) {
|
|
300
|
+
if (pair.hasOwnProperty('value')) {
|
|
301
|
+
delete pair.value;
|
|
302
|
+
delete pair.revision;
|
|
303
|
+
|
|
304
|
+
result = true;
|
|
305
|
+
pairs.forEach((pair) => {
|
|
306
|
+
pair.length--;
|
|
307
|
+
});
|
|
308
|
+
this.length--;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (pair.map && pair.map.size === 0) {
|
|
312
|
+
delete pair.map;
|
|
313
|
+
}
|
|
314
|
+
if (!pair.map) {
|
|
315
|
+
// pair is empty, so we can remove it altogether
|
|
316
|
+
currentMap.delete(key);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
break;
|
|
321
|
+
} else {
|
|
322
|
+
if (!pair || !pair.map) {
|
|
323
|
+
result = false;
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
pairs.push(pair);
|
|
327
|
+
currentMap = pair.map;
|
|
328
|
+
maps.push(currentMap);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
while (maps.length) {
|
|
333
|
+
const map = maps.pop();
|
|
334
|
+
const keysLen = keys.length;
|
|
335
|
+
keys.pop();
|
|
336
|
+
if (keysLen > 0 && map?.size === 0) {
|
|
337
|
+
const parentMap = maps[maps.length - 1];
|
|
338
|
+
const parentKey = keys[keys.length - 1];
|
|
339
|
+
const pair = parentMap?.get(parentKey);
|
|
340
|
+
if (pair) {
|
|
341
|
+
// pair.map === map ; which can be deleted
|
|
342
|
+
delete pair.map;
|
|
343
|
+
|
|
344
|
+
if (!pair.hasOwnProperty('value')) {
|
|
345
|
+
// whole pair can be successfully deleted from parentMap
|
|
346
|
+
parentMap.delete(parentKey);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return result;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
has(keys: KeyType[]) {
|
|
355
|
+
let currentMap = this.map;
|
|
356
|
+
if (!keys.length) {
|
|
357
|
+
keys = [this.emptyKey];
|
|
358
|
+
}
|
|
359
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
360
|
+
const key = keys[i];
|
|
361
|
+
const last = i === len - 1;
|
|
362
|
+
const pair = currentMap.get(key);
|
|
363
|
+
if (last) {
|
|
364
|
+
return pair ? pair.hasOwnProperty('value') : false;
|
|
365
|
+
} else {
|
|
366
|
+
if (!pair || !pair.map) {
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
currentMap = pair.map;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
private visitKey(
|
|
376
|
+
key: KeyType,
|
|
377
|
+
currentMap: Map<KeyType, Pair<KeyType, ValueType>>,
|
|
378
|
+
parentKeys: KeyType[],
|
|
379
|
+
fn: DeepMapVisitFn<KeyType, ValueType>,
|
|
380
|
+
) {
|
|
381
|
+
const pair = currentMap.get(key);
|
|
382
|
+
|
|
383
|
+
if (!pair) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const { map } = pair;
|
|
387
|
+
|
|
388
|
+
const keys = key === this.emptyKey ? [] : [...parentKeys, key];
|
|
389
|
+
|
|
390
|
+
const next = once(() => {
|
|
391
|
+
if (map) {
|
|
392
|
+
map.forEach((_, k) => {
|
|
393
|
+
this.visitKey(k, map, keys, fn);
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
if (pair.hasOwnProperty('value')) {
|
|
399
|
+
fn(pair, keys, next);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// if it was called by fn, it won't be called again, as it's once-d
|
|
403
|
+
next();
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
visit = (fn: DeepMapVisitFn<KeyType, ValueType>) => {
|
|
407
|
+
this.map.forEach((_, k) => this.visitKey(k, this.map, [], fn));
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
visitDepthFirst = (
|
|
411
|
+
fn: (
|
|
412
|
+
value: ValueType,
|
|
413
|
+
keys: KeyType[],
|
|
414
|
+
indexInGroup: number,
|
|
415
|
+
next?: VoidFn,
|
|
416
|
+
) => void,
|
|
417
|
+
) => {
|
|
418
|
+
this.visitWithNext([], fn);
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
private visitWithNext = (
|
|
422
|
+
parentKeys: KeyType[],
|
|
423
|
+
|
|
424
|
+
fn: (
|
|
425
|
+
value: ValueType,
|
|
426
|
+
keys: KeyType[],
|
|
427
|
+
indexInGroup: number,
|
|
428
|
+
next?: VoidFn,
|
|
429
|
+
) => void,
|
|
430
|
+
currentMap: Map<KeyType, Pair<KeyType, ValueType>> = this.map,
|
|
431
|
+
depthLimit?: number,
|
|
432
|
+
skipSelfValue?: boolean,
|
|
433
|
+
) => {
|
|
434
|
+
if (!currentMap) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
let i = 0;
|
|
438
|
+
const hasEmptyKey = currentMap.has(this.emptyKey);
|
|
439
|
+
let allowEmptyKey = skipSelfValue ? false : true;
|
|
440
|
+
|
|
441
|
+
if (depthLimit !== undefined) {
|
|
442
|
+
if (depthLimit < 0) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
depthLimit--;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const iterator = (_: Pair<KeyType, ValueType>, key: KeyType) => {
|
|
449
|
+
const pair = currentMap.get(key);
|
|
450
|
+
|
|
451
|
+
if (!pair) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
const { map } = pair;
|
|
455
|
+
|
|
456
|
+
const isEmptyKey = key === this.emptyKey;
|
|
457
|
+
if (isEmptyKey && !allowEmptyKey) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const keys = isEmptyKey ? [] : [...parentKeys, key];
|
|
461
|
+
|
|
462
|
+
let next = map
|
|
463
|
+
? () =>
|
|
464
|
+
this.visitWithNext(
|
|
465
|
+
keys,
|
|
466
|
+
fn,
|
|
467
|
+
map,
|
|
468
|
+
depthLimit !== undefined ? depthLimit - 1 : undefined,
|
|
469
|
+
)
|
|
470
|
+
: undefined;
|
|
471
|
+
|
|
472
|
+
if (pair.hasOwnProperty('value')) {
|
|
473
|
+
fn(pair.value!, keys, i, next);
|
|
474
|
+
i++;
|
|
475
|
+
} else {
|
|
476
|
+
next?.();
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
if (hasEmptyKey) {
|
|
481
|
+
iterator(undefined as any as Pair<KeyType, ValueType>, this.emptyKey);
|
|
482
|
+
allowEmptyKey = false;
|
|
483
|
+
i = 0;
|
|
484
|
+
}
|
|
485
|
+
currentMap.forEach(iterator);
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
private getArray<ReturnType>(
|
|
489
|
+
fn: (pair: Pair<KeyType, ValueType> & { keys: KeyType[] }) => ReturnType,
|
|
490
|
+
) {
|
|
491
|
+
const result: ReturnType[] = [];
|
|
492
|
+
|
|
493
|
+
this.visit((pair, keys) => {
|
|
494
|
+
const res = fn({ ...pair, keys });
|
|
495
|
+
if (keys.length === 0) {
|
|
496
|
+
result.splice(0, 0, res);
|
|
497
|
+
} else {
|
|
498
|
+
result.push(res);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
return result;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
valuesAt(keys: KeyType[]): ValueType[] {
|
|
506
|
+
const map = this.getMapAt(keys);
|
|
507
|
+
if (!map) {
|
|
508
|
+
return [];
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const result: ValueType[] = [];
|
|
512
|
+
map.forEach((bag) => {
|
|
513
|
+
if (bag.value !== undefined) {
|
|
514
|
+
result.push(bag.value);
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
return result;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
values() {
|
|
522
|
+
return this.sortedIterator<ValueType>((pair) => pair.value!);
|
|
523
|
+
}
|
|
524
|
+
keys() {
|
|
525
|
+
const keys = this.sortedIterator<KeyType[]>((pair) => pair.keys);
|
|
526
|
+
|
|
527
|
+
return keys;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
entries() {
|
|
531
|
+
return this.sortedIterator<[KeyType[], ValueType]>((pair) => [
|
|
532
|
+
pair.keys,
|
|
533
|
+
pair.value!,
|
|
534
|
+
]);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
topDownEntries() {
|
|
538
|
+
return this.getArray<[KeyType[], ValueType]>((pair) => [
|
|
539
|
+
pair.keys,
|
|
540
|
+
pair.value!,
|
|
541
|
+
]);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
topDownKeys() {
|
|
545
|
+
return this.getArray<KeyType[]>((pair) => pair.keys);
|
|
546
|
+
}
|
|
547
|
+
topDownValues() {
|
|
548
|
+
return this.getArray<ValueType>((pair) => pair.value!);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
private sortedIterator<ReturnType>(
|
|
552
|
+
fn: (pair: Pair<KeyType, ValueType> & { keys: KeyType[] }) => ReturnType,
|
|
553
|
+
) {
|
|
554
|
+
const result: (Pair<KeyType, ValueType> & { keys: KeyType[] })[] = [];
|
|
555
|
+
|
|
556
|
+
this.visit((pair, keys) => {
|
|
557
|
+
result.push({ ...pair, keys });
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
result.sort(SORT_ASC_REVISION);
|
|
561
|
+
|
|
562
|
+
function* makeIterator() {
|
|
563
|
+
for (let i = 0, len = result.length; i < len; i++) {
|
|
564
|
+
yield fn(result[i]);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
return makeIterator();
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// private iterator<ReturnType>(
|
|
572
|
+
// fn: (pair: Pair<KeyType, ValueType> & { keys: KeyType[] }) => ReturnType,
|
|
573
|
+
// ) {
|
|
574
|
+
// const result: (Pair<KeyType, ValueType> & { keys: KeyType[] })[] = [];
|
|
575
|
+
|
|
576
|
+
// this.visit((pair, keys) => {
|
|
577
|
+
// result.push({ ...pair, keys });
|
|
578
|
+
// });
|
|
579
|
+
|
|
580
|
+
// function* makeIterator() {
|
|
581
|
+
// for (let i = 0, len = result.length; i < len; i++) {
|
|
582
|
+
// yield fn(result[i]);
|
|
583
|
+
// }
|
|
584
|
+
// }
|
|
585
|
+
|
|
586
|
+
// return makeIterator();
|
|
587
|
+
// }
|
|
588
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function once<ReturnType>(fn: () => ReturnType): () => ReturnType {
|
|
2
|
+
let called = false;
|
|
3
|
+
let result: ReturnType | null = null;
|
|
4
|
+
|
|
5
|
+
const onceFn = () => {
|
|
6
|
+
if (called) {
|
|
7
|
+
return result!;
|
|
8
|
+
}
|
|
9
|
+
called = true;
|
|
10
|
+
result = fn();
|
|
11
|
+
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return onceFn;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const sortAscending = (a: number, b: number) => a - b;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": ".",
|
|
4
|
+
/* Basic Options */
|
|
5
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
6
|
+
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
|
7
|
+
"module": "system" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
|
|
10
|
+
/* Strict Type-Checking Options */
|
|
11
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
12
|
+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
|
13
|
+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
14
|
+
},
|
|
15
|
+
"include": ["index.ts"],
|
|
16
|
+
"exclude": ["node_modules", "dist", "dist-deepmap"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@infinite-table/deep-map",
|
|
3
|
+
"description": "DeepMap structure - ala Map but with keys being arrays",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"module": "index.esm.js",
|
|
7
|
+
"typings": "types.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "npm run esbuild && npm run tsc",
|
|
10
|
+
"tsc": "tsc --emitDeclarationOnly --project tsconfig.deepmap.json --outFile ../../../dist-deepmap/types.d.ts ",
|
|
11
|
+
"esbuild": "npm run esbuild-esm && npm run esbuild-cjs",
|
|
12
|
+
"esbuild-esm": "node ../../../run-build-deepmap.js esm",
|
|
13
|
+
"esbuild-cjs": "node ../../../run-build-deepmap.js cjs",
|
|
14
|
+
"///": "//",
|
|
15
|
+
"bump:canary": "npm version prerelease --preid=canary",
|
|
16
|
+
"bump:major:canary": "npm version premajor --preid=canary",
|
|
17
|
+
"bump:minor:canary": "npm version preminor --preid=canary",
|
|
18
|
+
"bump:patch:canary": "npm version prepatch --preid=canary",
|
|
19
|
+
"////": "//",
|
|
20
|
+
"bump:patch": "npm version patch",
|
|
21
|
+
"bump:minor": "npm version minor",
|
|
22
|
+
"bump:major": "npm version major"
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
"license": "MIT"
|
|
26
|
+
}
|