@itwin/components-react 4.7.2 → 4.8.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/CHANGELOG.md +7 -4
- package/lib/cjs/components-react/common/DelayedSpinner.js +3 -2
- package/lib/cjs/components-react/common/DelayedSpinner.js.map +1 -1
- package/lib/cjs/components-react/common/UseDebouncedAsyncValue.js +2 -1
- package/lib/cjs/components-react/common/UseDebouncedAsyncValue.js.map +1 -1
- package/lib/cjs/components-react/converters/NumericTypeConverter.js +4 -2
- package/lib/cjs/components-react/converters/NumericTypeConverter.js.map +1 -1
- package/lib/cjs/components-react/converters/TypeConverter.js +2 -1
- package/lib/cjs/components-react/converters/TypeConverter.js.map +1 -1
- package/lib/cjs/components-react/editors/CustomNumberEditor.js +8 -6
- package/lib/cjs/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/lib/cjs/components-react/editors/DateTimeEditor.js +3 -2
- package/lib/cjs/components-react/editors/DateTimeEditor.js.map +1 -1
- package/lib/cjs/components-react/editors/PopupButton.js +4 -3
- package/lib/cjs/components-react/editors/PopupButton.js.map +1 -1
- package/lib/cjs/components-react/editors/TextEditor.js +4 -2
- package/lib/cjs/components-react/editors/TextEditor.js.map +1 -1
- package/lib/cjs/components-react/favorite/FavoritePropertyList.js +3 -3
- package/lib/cjs/components-react/favorite/FavoritePropertyList.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleOperator.js +2 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleOperator.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleProperty.js +3 -3
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleProperty.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.js +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderState.d.ts +2 -0
- package/lib/cjs/components-react/filter-builder/FilterBuilderState.d.ts.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderState.js +8 -2
- package/lib/cjs/components-react/filter-builder/FilterBuilderState.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/CommonPropertyRenderer.js +4 -3
- package/lib/cjs/components-react/properties/renderers/CommonPropertyRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/NonPrimitivePropertyRenderer.js +1 -1
- package/lib/cjs/components-react/properties/renderers/NonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/PrimitivePropertyRenderer.js +3 -2
- package/lib/cjs/components-react/properties/renderers/PrimitivePropertyRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/label/PropertyLabelRenderer.js +4 -4
- package/lib/cjs/components-react/properties/renderers/label/PropertyLabelRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/Common.js +2 -1
- package/lib/cjs/components-react/properties/renderers/value/Common.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js +6 -3
- package/lib/cjs/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/PrimitivePropertyValueRenderer.js +6 -3
- package/lib/cjs/components-react/properties/renderers/value/PrimitivePropertyValueRenderer.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/PropertyCategoryRendererManager.js +2 -1
- package/lib/cjs/components-react/propertygrid/PropertyCategoryRendererManager.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js +2 -1
- package/lib/cjs/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/PropertyCategoryBlock.js +2 -1
- package/lib/cjs/components-react/propertygrid/component/PropertyCategoryBlock.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/PropertyGridCommons.js +2 -2
- package/lib/cjs/components-react/propertygrid/component/PropertyGridCommons.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/VirtualizedPropertyGrid.d.ts.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/VirtualizedPropertyGrid.js +54 -48
- package/lib/cjs/components-react/propertygrid/component/VirtualizedPropertyGrid.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/dataproviders/FilteringDataProvider.js +13 -11
- package/lib/cjs/components-react/propertygrid/dataproviders/FilteringDataProvider.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js +2 -2
- package/lib/cjs/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js +2 -1
- package/lib/cjs/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js +2 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js +2 -2
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableGridCategory.js +3 -2
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableGridCategory.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableGridItemFactory.js +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableGridItemFactory.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.js +7 -5
- package/lib/cjs/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.js.map +1 -1
- package/lib/cjs/components-react/selectable-content/SelectableContent.js +3 -2
- package/lib/cjs/components-react/selectable-content/SelectableContent.js.map +1 -1
- package/lib/cjs/components-react/toolbar/InternalToolbarComponent.js +6 -4
- package/lib/cjs/components-react/toolbar/InternalToolbarComponent.js.map +1 -1
- package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.js +6 -5
- package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeModel.js +8 -7
- package/lib/cjs/components-react/tree/controlled/TreeModel.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeNodeLoader.js +8 -6
- package/lib/cjs/components-react/tree/controlled/TreeNodeLoader.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/internal/SparseTree.js +2 -1
- package/lib/cjs/components-react/tree/controlled/internal/SparseTree.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/internal/TreeSelectionManager.js +4 -2
- package/lib/cjs/components-react/tree/controlled/internal/TreeSelectionManager.js.map +1 -1
- package/lib/esm/components-react/common/DelayedSpinner.js +3 -2
- package/lib/esm/components-react/common/DelayedSpinner.js.map +1 -1
- package/lib/esm/components-react/common/UseDebouncedAsyncValue.js +2 -1
- package/lib/esm/components-react/common/UseDebouncedAsyncValue.js.map +1 -1
- package/lib/esm/components-react/converters/NumericTypeConverter.js +4 -2
- package/lib/esm/components-react/converters/NumericTypeConverter.js.map +1 -1
- package/lib/esm/components-react/converters/TypeConverter.js +2 -1
- package/lib/esm/components-react/converters/TypeConverter.js.map +1 -1
- package/lib/esm/components-react/editors/CustomNumberEditor.js +8 -6
- package/lib/esm/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/lib/esm/components-react/editors/DateTimeEditor.js +3 -2
- package/lib/esm/components-react/editors/DateTimeEditor.js.map +1 -1
- package/lib/esm/components-react/editors/PopupButton.js +4 -3
- package/lib/esm/components-react/editors/PopupButton.js.map +1 -1
- package/lib/esm/components-react/editors/TextEditor.js +4 -2
- package/lib/esm/components-react/editors/TextEditor.js.map +1 -1
- package/lib/esm/components-react/favorite/FavoritePropertyList.js +3 -3
- package/lib/esm/components-react/favorite/FavoritePropertyList.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleOperator.js +2 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleOperator.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleProperty.js +3 -3
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleProperty.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.js +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderState.d.ts +2 -0
- package/lib/esm/components-react/filter-builder/FilterBuilderState.d.ts.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderState.js +8 -2
- package/lib/esm/components-react/filter-builder/FilterBuilderState.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/CommonPropertyRenderer.js +4 -3
- package/lib/esm/components-react/properties/renderers/CommonPropertyRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/NonPrimitivePropertyRenderer.js +1 -1
- package/lib/esm/components-react/properties/renderers/NonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/PrimitivePropertyRenderer.js +3 -2
- package/lib/esm/components-react/properties/renderers/PrimitivePropertyRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/label/PropertyLabelRenderer.js +4 -4
- package/lib/esm/components-react/properties/renderers/label/PropertyLabelRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/Common.js +2 -1
- package/lib/esm/components-react/properties/renderers/value/Common.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js +6 -3
- package/lib/esm/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/PrimitivePropertyValueRenderer.js +6 -3
- package/lib/esm/components-react/properties/renderers/value/PrimitivePropertyValueRenderer.js.map +1 -1
- package/lib/esm/components-react/propertygrid/PropertyCategoryRendererManager.js +2 -1
- package/lib/esm/components-react/propertygrid/PropertyCategoryRendererManager.js.map +1 -1
- package/lib/esm/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js +2 -1
- package/lib/esm/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js.map +1 -1
- package/lib/esm/components-react/propertygrid/component/PropertyCategoryBlock.js +2 -1
- package/lib/esm/components-react/propertygrid/component/PropertyCategoryBlock.js.map +1 -1
- package/lib/esm/components-react/propertygrid/component/PropertyGridCommons.js +2 -2
- package/lib/esm/components-react/propertygrid/component/PropertyGridCommons.js.map +1 -1
- package/lib/esm/components-react/propertygrid/component/VirtualizedPropertyGrid.d.ts.map +1 -1
- package/lib/esm/components-react/propertygrid/component/VirtualizedPropertyGrid.js +54 -48
- package/lib/esm/components-react/propertygrid/component/VirtualizedPropertyGrid.js.map +1 -1
- package/lib/esm/components-react/propertygrid/dataproviders/FilteringDataProvider.js +13 -11
- package/lib/esm/components-react/propertygrid/dataproviders/FilteringDataProvider.js.map +1 -1
- package/lib/esm/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js +2 -2
- package/lib/esm/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js.map +1 -1
- package/lib/esm/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js +2 -1
- package/lib/esm/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js +2 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js +2 -2
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableGridCategory.js +3 -2
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableGridCategory.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableGridItemFactory.js +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableGridItemFactory.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.js +7 -5
- package/lib/esm/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.js.map +1 -1
- package/lib/esm/components-react/selectable-content/SelectableContent.js +3 -2
- package/lib/esm/components-react/selectable-content/SelectableContent.js.map +1 -1
- package/lib/esm/components-react/toolbar/InternalToolbarComponent.js +6 -4
- package/lib/esm/components-react/toolbar/InternalToolbarComponent.js.map +1 -1
- package/lib/esm/components-react/toolbar/useConditionalSynchedItems.js +6 -5
- package/lib/esm/components-react/toolbar/useConditionalSynchedItems.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeModel.js +8 -7
- package/lib/esm/components-react/tree/controlled/TreeModel.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeNodeLoader.js +8 -6
- package/lib/esm/components-react/tree/controlled/TreeNodeLoader.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/internal/SparseTree.js +2 -1
- package/lib/esm/components-react/tree/controlled/internal/SparseTree.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/internal/TreeSelectionManager.js +4 -2
- package/lib/esm/components-react/tree/controlled/internal/TreeSelectionManager.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConditionalSynchedItems.js","sourceRoot":"","sources":["../../../../src/components-react/toolbar/useConditionalSynchedItems.ts"],"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I,KAAK,EAAE;QACxB,IAAI,WAAW,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;QAC9B,IAAI,OAAO,IAAI,WAAW,EAAE;YAC1B,MAAM,UAAU,GAAG,YAAY,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC7D,WAAW,GAAG;gBACZ,GAAG,WAAW;gBACd,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"useConditionalSynchedItems.js","sourceRoot":"","sources":["../../../../src/components-react/toolbar/useConditionalSynchedItems.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;gGAGgG;AAChG,0DAG+B;AAE/B,kDAAwD;AACxD,6CAA+B;AAE/B;;;;;GAKG;AACH,SAAS,aAAa,CACpB,QAAqB,EACrB,KAAmB;IAEnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,KAAK,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC5C,IAAI,KAAK,YAAY,wCAAuB,EAAE;gBAC5C,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,OAAe,EAAE,EAAE,CAC7C,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CACpC,CAAC;aACH;iBAAM,IAAI,KAAK,YAAY,uCAAsB,EAAE;gBAClD,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,OAAe,EAAE,EAAE,CAC7C,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CACpC,CAAC;aACH;iBAAM,IAAI,gCAAmB,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE;gBAC3D,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,OAAe,EAAE,EAAE,CAC7C,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CACpC,CAAC;aACH;SACF;Q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AAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,0BAA0B,CACxC,KAAmB,EACnB,WAA2E;IAE3E,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAE9D,EAAE,CAAC,CAAC;IACN,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;;QACnB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;QAC9B,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,oBAAoB,CAAC,MAAA,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,mCAAI,KAAK,CAAC,CAAC;QACxD,MAAM,iBAAiB,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5C,OAAO,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE;YACvC,IAAI,CAAC,KAAK,iBAAiB,CAAC,MAAM;gBAAE,OAAO;YAE3C,IACE,iBAAiB,CAAC,IAAI,CAAC,CAAC,KAAa,EAAW,EAAE,CAChD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CACvC,EACD;gBACA,oBAAoB,CAClB,CAAC,OAAO,EAAE,EAAE,WAAC,OAAA,MAAA,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,mCAAI,OAAO,CAAA,EAAA,CAC7D,CAAC;aACH;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IACzB,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AA3BD,gEA2BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\nimport {\n ConditionalBooleanValue,\n ConditionalStringValue,\n} from \"@itwin/appui-abstract\";\nimport type { BeEvent } from \"@itwin/core-bentley\";\nimport { ConditionalIconItem } from \"@itwin/core-react\";\nimport * as React from \"react\";\n\n/**\n * From a list of ToolbarItem, recursively return the list of syncIds\n * that are relevant to every Conditional members used in the items.\n * @param eventIds Set to fill with syncIds\n * @param items ToolbarItems list to search through\n */\nfunction gatherSyncIds<T extends {} | { items: T[] }>(\n eventIds: Set<string>,\n items: readonly T[]\n) {\n for (const item of items) {\n for (const [, entry] of Object.entries(item)) {\n if (entry instanceof ConditionalBooleanValue) {\n entry.syncEventIds.forEach((eventId: string) =>\n eventIds.add(eventId.toLowerCase())\n );\n } else if (entry instanceof ConditionalStringValue) {\n entry.syncEventIds.forEach((eventId: string) =>\n eventIds.add(eventId.toLowerCase())\n );\n } else if (ConditionalIconItem.isConditionalIconItem(entry)) {\n entry.syncEventIds.forEach((eventId: string) =>\n eventIds.add(eventId.toLowerCase())\n );\n }\n }\n if (\"items\" in item) {\n gatherSyncIds(eventIds, item.items);\n }\n }\n}\n\n/**\n * Refresh all conditional values interested by the provided eventIds.\n * @param items List of ToolbarItems that may content Conditional properties.\n * @param eventIds Set of triggered eventIds.\n * @returns null if no updates occurred, or the provided items with updated values if ANY were updated.\n */\nfunction refreshItems<T extends {} | { items: T[] }>(\n items: readonly T[],\n eventIds: Set<string>\n): T[] | null {\n if (0 === eventIds.size) return null;\n let itemsUpdated = false;\n const updatedItems: T[] = [];\n\n for (const item of items) {\n let updatedItem = { ...item };\n if (\"items\" in updatedItem) {\n const childItems = refreshItems(updatedItem.items, eventIds);\n updatedItem = {\n ...updatedItem,\n items: childItems ?? updatedItem.items,\n };\n itemsUpdated ||= !!childItems;\n }\n\n for (const [, entry] of Object.entries(updatedItem)) {\n if (\n (entry instanceof ConditionalBooleanValue &&\n ConditionalBooleanValue.refreshValue(entry, eventIds)) ||\n (entry instanceof ConditionalStringValue &&\n ConditionalStringValue.refreshValue(entry, eventIds)) ||\n (ConditionalIconItem.isConditionalIconItem(entry) &&\n ConditionalIconItem.refreshValue(entry, eventIds))\n ) {\n itemsUpdated = true;\n }\n }\n updatedItems.push(updatedItem);\n }\n return itemsUpdated ? updatedItems : null;\n}\n\n/**\n * Register a listener on the syncUiEVent and updates all conditionals within the provided items.\n * @param items Items to keep up to date\n * @param syncUiEvent Event to attach to (because we don't depend on appui-react);\n * @returns Synched items\n * @internal\n */\nexport function useConditionalSynchedItems<T extends {} | { items: T[] }>(\n items: readonly T[],\n syncUiEvent: undefined | BeEvent<(args: { eventIds: Set<string> }) => void>\n) {\n const [eventSynchedItems, setEventSynchedItems] = React.useState<\n readonly T[]\n >([]);\n React.useEffect(() => {\n const ids = new Set<string>();\n gatherSyncIds(ids, items);\n setEventSynchedItems(refreshItems(items, ids) ?? items);\n const syncIdsOfInterest = [...ids.values()];\n return syncUiEvent?.addListener((args) => {\n if (0 === syncIdsOfInterest.length) return;\n\n if (\n syncIdsOfInterest.some((value: string): boolean =>\n args.eventIds.has(value.toLowerCase())\n )\n ) {\n setEventSynchedItems(\n (current) => refreshItems(current, args.eventIds) ?? current\n );\n }\n });\n }, [syncUiEvent, items]);\n return eventSynchedItems;\n}\n"]}
|
|
@@ -127,6 +127,7 @@ class MutableTreeModel {
|
|
|
127
127
|
* @returns `true` on success, `false` otherwise.
|
|
128
128
|
*/
|
|
129
129
|
changeNodeId(currentId, newId) {
|
|
130
|
+
var _b, _c;
|
|
130
131
|
const node = this.getNode(currentId);
|
|
131
132
|
if (node === undefined) {
|
|
132
133
|
return false;
|
|
@@ -140,7 +141,7 @@ class MutableTreeModel {
|
|
|
140
141
|
return false;
|
|
141
142
|
}
|
|
142
143
|
node.id = newId; // eslint-disable-line @typescript-eslint/no-unnecessary-type-assertion
|
|
143
|
-
for (const [childId] of this.getChildren(newId)
|
|
144
|
+
for (const [childId] of (_c = (_b = this.getChildren(newId)) === null || _b === void 0 ? void 0 : _b.iterateValues()) !== null && _c !== void 0 ? _c : []) {
|
|
144
145
|
const child = this.getNode(childId);
|
|
145
146
|
(0, core_bentley_1.assert)(child !== undefined);
|
|
146
147
|
child.parentId = newId;
|
|
@@ -179,12 +180,12 @@ class MutableTreeModel {
|
|
|
179
180
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
180
181
|
sourceNode.parentId = targetParentId;
|
|
181
182
|
const updateDepths = (parentId, depth) => {
|
|
183
|
+
var _b, _c;
|
|
182
184
|
const node = this.getNode(parentId);
|
|
183
185
|
(0, core_bentley_1.assert)(node !== undefined);
|
|
184
186
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
185
187
|
node.depth = depth;
|
|
186
|
-
for (const [nodeId] of this.getChildren(parentId)
|
|
187
|
-
[]) {
|
|
188
|
+
for (const [nodeId] of (_c = (_b = this.getChildren(parentId)) === null || _b === void 0 ? void 0 : _b.iterateValues()) !== null && _c !== void 0 ? _c : []) {
|
|
188
189
|
updateDepths(nodeId, depth + 1);
|
|
189
190
|
}
|
|
190
191
|
};
|
|
@@ -211,7 +212,7 @@ class MutableTreeModel {
|
|
|
211
212
|
}
|
|
212
213
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
213
214
|
parentNode.numChildren = numChildren;
|
|
214
|
-
this._tree.setNumChildren(parentId, numChildren
|
|
215
|
+
this._tree.setNumChildren(parentId, numChildren !== null && numChildren !== void 0 ? numChildren : 0);
|
|
215
216
|
}
|
|
216
217
|
/** Removes children specified by id.
|
|
217
218
|
* @param parentId id of the parent node.
|
|
@@ -345,11 +346,11 @@ function getVisibleDescendants(model, parentNode, result = []) {
|
|
|
345
346
|
}
|
|
346
347
|
exports.getVisibleDescendants = getVisibleDescendants;
|
|
347
348
|
function cloneSubree(source, target, parentId) {
|
|
349
|
+
var _b, _c;
|
|
348
350
|
target.setNumChildren(parentId, (parentId === undefined ? source.getRootNode() : source.getNode(parentId))
|
|
349
351
|
.numChildren);
|
|
350
|
-
for (const [childId, index] of source
|
|
351
|
-
.getChildren(parentId)
|
|
352
|
-
?.iterateValues() ?? []) {
|
|
352
|
+
for (const [childId, index] of (_c = (_b = source
|
|
353
|
+
.getChildren(parentId)) === null || _b === void 0 ? void 0 : _b.iterateValues()) !== null && _c !== void 0 ? _c : []) {
|
|
353
354
|
const node = source.getNode(childId);
|
|
354
355
|
target.setChildren(parentId, [{ ...node, isLoading: !!node.isLoading }], index);
|
|
355
356
|
cloneSubree(source, target, childId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeModel.js","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeModel.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;AAEH,iCAAkC;AAClC,mCAAmC;AACnC,sDAA6C;AAE7C,kDAAkD;AAOlD,sDAAmD;AA4HnD;;;GAGG;AACH,SAAgB,eAAe,CAC7B,GAAkC;IAElC,OAAO,CACL,GAAG,KAAK,SAAS;QACjB,CAAC,0BAA0B,CAAC,GAAG,CAAC;QAChC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAC1B,CAAC;AACJ,CAAC;AARD,0CAQC;AAED;;;GAGG;AACH,SAAgB,0BAA0B,CACxC,GAAkC;IAElC,OAAO,GAAG,KAAK,SAAS,IAAI,YAAY,IAAI,GAAG,CAAC;AAClD,CAAC;AAJD,gEAIC;AAED;;;GAGG;AACH,SAAgB,mBAAmB,CACjC,GAAkC;IAElC,OAAO,CACL,GAAG,KAAK,SAAS;QAChB,GAAyB,CAAC,EAAE,KAAK,SAAS;QAC3C,CAAC,CAAC,YAAY,IAAI,GAAG,CAAC,CACvB,CAAC;AACJ,CAAC;AARD,kDAQC;AAkDD;;;GAGG;AACH,MAAa,gBAAgB;IAU3B,YAAmB,IAAgB;QAT5B,QAAW,GAAG,IAAI,CAAC;QAElB,UAAK,GAAG,IAAI,uBAAU,EAAwB,CAAC;QAC/C,cAAS,GAAsB;YACrC,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------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport { immerable } from \"immer\";\nimport { cloneDeep } from \"lodash\";\nimport { assert } from \"@itwin/core-bentley\";\nimport type { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { CheckBoxState } from \"@itwin/core-react\";\nimport type {\n DelayLoadedTreeNodeItem,\n ImmediatelyLoadedTreeNodeItem,\n TreeNodeItem,\n} from \"../TreeDataProvider\";\nimport type { SparseArray } from \"./internal/SparseTree\";\nimport { SparseTree } from \"./internal/SparseTree\";\n\n/**\n * Immutable data structure that describes tree node.\n * @public\n */\nexport interface TreeModelNode {\n readonly id: string;\n readonly parentId: string | undefined;\n readonly depth: number;\n\n readonly isLoading?: boolean;\n readonly numChildren: number | undefined;\n\n readonly description: string | undefined;\n readonly isExpanded: boolean;\n readonly label: PropertyRecord;\n readonly isSelected: boolean;\n readonly isSelectionDisabled?: boolean;\n\n /** Specifies that node is in editing mode. It holds callbacks that are used by node editor. */\n readonly editingInfo?: TreeModelNodeEditingInfo;\n\n readonly checkbox: CheckBoxInfo;\n\n readonly item: TreeNodeItem;\n}\n\n/**\n * Immutable data structure that describes checkbox info.\n * @public\n */\nexport interface CheckBoxInfo {\n readonly state: CheckBoxState;\n readonly tooltip?: string;\n readonly isDisabled: boolean;\n readonly isVisible: boolean;\n}\n\n/**\n * Mutable data structure that describes tree node.\n * @public\n */\nexport interface MutableTreeModelNode extends TreeModelNode {\n isLoading: boolean;\n\n description: string;\n isExpanded: boolean;\n label: PropertyRecord;\n isSelected: boolean;\n isSelectionDisabled?: boolean;\n\n /** Specifies that node is in editing mode. It holds callbacks that are used by node editor. */\n editingInfo?: TreeModelNodeEditingInfo;\n\n checkbox: MutableCheckBoxInfo;\n\n item: TreeNodeItem;\n}\n\n/**\n * Data structure that holds callbacks used for tree node editing.\n * @public\n */\nexport interface TreeModelNodeEditingInfo {\n onCommit: (node: TreeModelNode, newValue: string) => void;\n onCancel: () => void;\n}\n\n/**\n * Mutable data structure that describes checkbox info.\n * @public\n */\nexport interface MutableCheckBoxInfo extends CheckBoxInfo {\n state: CheckBoxState;\n tooltip?: string;\n isDisabled: boolean;\n isVisible: boolean;\n}\n\n/**\n * Data structure that describes tree node placeholder.\n * @public\n */\nexport interface TreeModelNodePlaceholder {\n readonly childIndex: number;\n readonly depth: number;\n readonly parentId?: string;\n}\n\n/**\n * Data structure that describes tree root node.\n * @public\n */\nexport interface TreeModelRootNode {\n readonly depth: -1;\n readonly id: undefined;\n readonly numChildren: number | undefined;\n}\n\n/**\n * Data structure that describes input used to create tree node.\n * @public\n */\nexport interface TreeModelNodeInput {\n readonly description?: string;\n readonly isExpanded: boolean;\n readonly id: string;\n readonly item: TreeNodeItem;\n readonly label: PropertyRecord;\n readonly isLoading: boolean;\n readonly numChildren?: number;\n readonly isSelected: boolean;\n}\n\n/**\n * Type definition of all tree model nodes.\n * @public\n */\nexport type TreeModelNodeType =\n | TreeModelNode\n | TreeModelNodePlaceholder\n | TreeModelRootNode;\n\n/**\n * Checks if object is [[TreeModelNode]]\n * @public\n */\nexport function isTreeModelNode(\n obj: TreeModelNodeType | undefined\n): obj is TreeModelNode {\n return (\n obj !== undefined &&\n !isTreeModelNodePlaceholder(obj) &&\n !isTreeModelRootNode(obj)\n );\n}\n\n/**\n * Checks if object is [[TreeModelNodePlaceholder]]\n * @public\n */\nexport function isTreeModelNodePlaceholder(\n obj: TreeModelNodeType | undefined\n): obj is TreeModelNodePlaceholder {\n return obj !== undefined && \"childIndex\" in obj;\n}\n\n/**\n * Checks if object is [[TreeModelRootNode]]\n * @public\n */\nexport function isTreeModelRootNode(\n obj: TreeModelNodeType | undefined\n): obj is TreeModelRootNode {\n return (\n obj !== undefined &&\n (obj as TreeModelRootNode).id === undefined &&\n !(\"childIndex\" in obj)\n );\n}\n\n/**\n * Type definition of tree node item data.\n * @public\n */\nexport type TreeNodeItemData = ImmediatelyLoadedTreeNodeItem &\n DelayLoadedTreeNodeItem;\n\n/**\n * Data structure that describes set of visible tree nodes as a flat list.\n * @public\n */\nexport interface VisibleTreeNodes\n extends Iterable<TreeModelNode | TreeModelNodePlaceholder> {\n getNumNodes(): number;\n getAtIndex(\n index: number\n ): TreeModelNode | TreeModelNodePlaceholder | undefined;\n getModel(): TreeModel;\n getNumRootNodes(): number | undefined;\n getIndexOfNode(nodeId: string): number;\n}\n\n/**\n * Data structure that describes tree model.\n * @public\n */\nexport interface TreeModel {\n getRootNode(): TreeModelRootNode;\n\n getNode(id: string): TreeModelNode | undefined;\n getNode(\n parentId: string | undefined,\n childIndex: number\n ): TreeModelNode | TreeModelNodePlaceholder | undefined;\n getNode(\n nodeId: string | undefined,\n childIndex?: number\n ): TreeModelNode | TreeModelNodePlaceholder | TreeModelRootNode | undefined;\n\n getChildren(parentId: string | undefined): SparseArray<string> | undefined;\n getChildOffset(\n parentId: string | undefined,\n childId: string\n ): number | undefined;\n\n iterateTreeModelNodes(parentId?: string): IterableIterator<TreeModelNode>;\n}\n\n/**\n * Mutable tree model which holds nodes and allows adding or removing them.\n * @public\n */\nexport class MutableTreeModel implements TreeModel {\n public [immerable] = true;\n\n private _tree = new SparseTree<MutableTreeModelNode>();\n private _rootNode: TreeModelRootNode = {\n depth: -1,\n id: undefined,\n numChildren: undefined,\n };\n\n public constructor(seed?: TreeModel) {\n if (!seed) {\n return;\n }\n\n cloneSubree(seed, this, undefined);\n }\n\n /** Returns root node of a tree. This node is not visible and is there to allow having multiple visible root nodes. */\n public getRootNode(): TreeModelRootNode {\n return this._rootNode;\n }\n\n /** Returns tree node or placeholder for node that is not loaded yet.\n * @returns node, node placeholder or undefined if node is not found in model.\n */\n public getNode(id: string): MutableTreeModelNode | undefined;\n public getNode(\n parentId: string | undefined,\n childIndex: number\n ): MutableTreeModelNode | TreeModelNodePlaceholder | undefined;\n public getNode(\n nodeId: string | undefined,\n childIndex?: number\n ): MutableTreeModelNode | TreeModelNodePlaceholder | undefined {\n if (childIndex === undefined) {\n return this._tree.getNode(nodeId!);\n }\n\n const children = this._tree.getChildren(nodeId);\n const childId =\n children !== undefined ? children.get(childIndex) : undefined;\n if (childId !== undefined) {\n return this._tree.getNode(childId);\n }\n\n const parentNode =\n nodeId === undefined ? this._rootNode : this._tree.getNode(nodeId);\n if (parentNode !== undefined) {\n return {\n childIndex,\n depth: parentNode.depth + 1,\n parentId: nodeId,\n };\n }\n\n return undefined;\n }\n\n /** Returns children for specific parent.\n * @param parentId id of parent node.\n * @returns children of parent node or root nodes if undefined is passed as parent id.\n */\n public getChildren(\n parentId: string | undefined\n ): SparseArray<string> | undefined {\n return this._tree.getChildren(parentId);\n }\n\n /** Returns children offset in children array for specific parent. */\n public getChildOffset(\n parentId: string | undefined,\n childId: string\n ): number | undefined {\n return this._tree.getChildOffset(parentId, childId);\n }\n\n /**\n * Sets children for parent node starting from the specific offset.\n * If offset overlaps with already added nodes, the overlapping nodes are overwritten.\n */\n public setChildren(\n parentId: string | undefined,\n nodeInputs: TreeModelNodeInput[],\n offset: number\n ): void {\n const parentNode =\n parentId === undefined ? this._rootNode : this._tree.getNode(parentId);\n if (parentNode === undefined) return;\n\n const children: MutableTreeModelNode[] = [];\n for (const input of nodeInputs) {\n const child = MutableTreeModel.createTreeModelNode(parentNode, input);\n children.push(child);\n }\n\n this._tree.setChildren(parentNode.id, children, offset);\n MutableTreeModel.setNumChildrenForNode(\n parentNode,\n this._tree.getChildren(parentNode.id)\n );\n }\n\n /**\n * Inserts child in the specified position.\n * If offset is higher then current length of children array, the length is increased.\n */\n public insertChild(\n parentId: string | undefined,\n childNodeInput: TreeModelNodeInput,\n offset: number\n ): void {\n const parentNode =\n parentId === undefined ? this._rootNode : this._tree.getNode(parentId);\n if (parentNode === undefined) return;\n\n const child = MutableTreeModel.createTreeModelNode(\n parentNode,\n childNodeInput\n );\n\n this._tree.insertChild(parentNode.id, child, offset);\n MutableTreeModel.setNumChildrenForNode(\n parentNode,\n this._tree.getChildren(parentNode.id)\n );\n }\n\n /**\n * Changes the id of target node.\n * @returns `true` on success, `false` otherwise.\n */\n public changeNodeId(currentId: string, newId: string): boolean {\n const node = this.getNode(currentId);\n if (node === undefined) {\n return false;\n }\n\n if (currentId === newId) {\n return true;\n }\n\n const index = this.getChildOffset(node.parentId, currentId);\n assert(index !== undefined);\n\n if (!this._tree.setNodeId(node.parentId, index, newId)) {\n return false;\n }\n\n (node.id as string) = newId; // eslint-disable-line @typescript-eslint/no-unnecessary-type-assertion\n for (const [childId] of this.getChildren(newId)?.iterateValues() ?? []) {\n const child = this.getNode(childId);\n assert(child !== undefined);\n (child.parentId as string) = newId;\n }\n\n return true;\n }\n\n /**\n * Transfers node along with its children to a new location. Fails if destination has undefined child count.\n * @param sourceNodeId Node that is being moved.\n * @param targetParentId Node that will receive a new child.\n * @param targetIndex Insertion location among target's *current* children.\n * @returns `true` on success, `false` otherwise.\n */\n public moveNode(\n sourceNodeId: string,\n targetParentId: string | undefined,\n targetIndex: number\n ): boolean {\n const sourceNode = this.getNode(sourceNodeId);\n if (sourceNode === undefined) {\n return false;\n }\n\n const targetParent =\n targetParentId === undefined\n ? this._rootNode\n : this.getNode(targetParentId);\n if (targetParent === undefined || targetParent.numChildren === undefined) {\n return false;\n }\n\n if (\n targetParentId !== undefined &&\n this.areNodesRelated(sourceNodeId, targetParentId)\n ) {\n return false;\n }\n\n this._tree.moveNode(\n sourceNode.parentId,\n sourceNodeId,\n targetParentId,\n targetIndex\n );\n\n const sourceParent =\n sourceNode.parentId === undefined\n ? this._rootNode\n : this.getNode(sourceNode.parentId);\n assert(sourceParent !== undefined);\n MutableTreeModel.setNumChildrenForNode(\n sourceParent,\n this._tree.getChildren(sourceNode.parentId)\n );\n MutableTreeModel.setNumChildrenForNode(\n targetParent,\n this._tree.getChildren(targetParentId)\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (sourceNode.parentId as string | undefined) = targetParentId;\n\n const updateDepths = (parentId: string, depth: number) => {\n const node = this.getNode(parentId);\n assert(node !== undefined);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (node.depth as number) = depth;\n for (const [nodeId] of this.getChildren(parentId)?.iterateValues() ??\n []) {\n updateDepths(nodeId, depth + 1);\n }\n };\n\n updateDepths(sourceNodeId, targetParent.depth + 1);\n return true;\n }\n\n private areNodesRelated(\n ancestorNodeId: string,\n descendantNodeId: string\n ): boolean {\n const node = this.getNode(descendantNodeId);\n if (node === undefined || node.parentId === undefined) {\n return false;\n }\n\n return node.parentId === ancestorNodeId\n ? true\n : this.areNodesRelated(ancestorNodeId, node.parentId);\n }\n\n /**\n * Sets the number of child nodes a parent is expected to contain. All child nodes of this parent will be subsequently\n * removed.\n */\n public setNumChildren(\n parentId: string | undefined,\n numChildren: number | undefined\n ): void {\n const parentNode =\n parentId === undefined ? this._rootNode : this._tree.getNode(parentId);\n if (parentNode === undefined) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (parentNode.numChildren as number | undefined) = numChildren;\n this._tree.setNumChildren(parentId, numChildren ?? 0);\n }\n\n /** Removes children specified by id.\n * @param parentId id of the parent node.\n * @param child child node id or index that should be removed.\n */\n public removeChild(\n parentId: string | undefined,\n child: string | number\n ): void {\n const parentNode =\n parentId === undefined ? this._rootNode : this._tree.getNode(parentId);\n this._tree.removeChild(parentId, child);\n\n // istanbul ignore else\n if (parentNode)\n MutableTreeModel.setNumChildrenForNode(\n parentNode,\n this._tree.getChildren(parentNode.id)\n );\n }\n\n /** Removes all children for parent specified by id.\n * @param parentId id of parent node or undefined to remove root nodes.\n */\n public clearChildren(parentId: string | undefined) {\n const parentNode =\n parentId === undefined ? this._rootNode : this._tree.getNode(parentId);\n if (parentNode !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (parentNode.numChildren as number | undefined) = undefined;\n }\n this._tree.deleteSubtree(parentId, false);\n }\n\n /** Iterates over all nodes present in the tree model. */\n public *iterateTreeModelNodes(\n parentId?: string\n ): IterableIterator<MutableTreeModelNode> {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const _this = this;\n function* iterateDescendants(\n subParentId: string | undefined\n ): IterableIterator<MutableTreeModelNode> {\n const children = _this.getChildren(subParentId);\n if (children === undefined) {\n return;\n }\n\n for (const [nodeId] of children.iterateValues()) {\n const node = _this.getNode(nodeId);\n if (node !== undefined) {\n yield node;\n yield* iterateDescendants(nodeId);\n }\n }\n }\n\n yield* iterateDescendants(parentId);\n }\n\n private static setNumChildrenForNode(\n node: TreeModelRootNode | MutableTreeModelNode,\n children: SparseArray<string> | undefined\n ) {\n const numChildren = children ? children.getLength() : undefined;\n if (node.numChildren === numChildren) return;\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (node.numChildren as number | undefined) = numChildren;\n }\n\n private static createTreeModelNode(\n parentNode: TreeModelNode | TreeModelRootNode,\n input: TreeModelNodeInput\n ): MutableTreeModelNode {\n return {\n id: input.id,\n parentId: parentNode.id,\n depth: parentNode.depth + 1,\n\n isLoading: input.isLoading,\n numChildren: input.numChildren,\n\n description: input.description || \"\",\n isExpanded: input.isExpanded,\n label: input.label,\n isSelected: input.isSelected,\n isSelectionDisabled: input.item.isSelectionDisabled,\n\n checkbox: {\n state: input.item.checkBoxState || CheckBoxState.Off,\n isDisabled: !!input.item.isCheckboxDisabled,\n isVisible: !!input.item.isCheckboxVisible,\n },\n\n item: cloneDeep(input.item),\n };\n }\n}\n\n/**\n * Generates flat list of visible nodes in the tree model.\n * @public\n */\nexport function computeVisibleNodes(model: TreeModel): VisibleTreeNodes {\n const result = getVisibleDescendants(model, model.getRootNode());\n return {\n getNumNodes: () => result.length,\n getAtIndex: (\n index: number\n ): TreeModelNode | TreeModelNodePlaceholder | undefined => {\n return result[index];\n },\n getModel: () => model,\n getNumRootNodes: () => model.getRootNode().numChildren,\n [Symbol.iterator]: () => result[Symbol.iterator](),\n getIndexOfNode: (nodeId: string): number => {\n return result.findIndex(\n (visibleNode) => (visibleNode as TreeModelNode).id === nodeId\n );\n },\n };\n}\n\n/**\n * Traverses the tree and collects visible descendants.\n * @public\n */\nexport function getVisibleDescendants(\n model: TreeModel,\n parentNode: TreeModelNode | TreeModelRootNode,\n result: Array<TreeModelNode | TreeModelNodePlaceholder> = []\n): Array<TreeModelNode | TreeModelNodePlaceholder> {\n const children = model.getChildren(parentNode.id);\n if (!children) {\n return result;\n }\n\n let index = 0;\n for (const childId of children) {\n if (childId === undefined) {\n result.push({\n parentId: parentNode.id,\n depth: parentNode.depth + 1,\n childIndex: index,\n });\n } else {\n const childNode = model.getNode(childId);\n if (childNode === undefined) {\n // node was disposed\n result.push({\n parentId: parentNode.id,\n depth: parentNode.depth + 1,\n childIndex: index,\n });\n } else {\n result.push(childNode);\n if (childNode.isExpanded && childNode.numChildren !== undefined) {\n getVisibleDescendants(model, childNode, result);\n }\n }\n }\n ++index;\n }\n\n return result;\n}\n\nfunction cloneSubree(\n source: TreeModel,\n target: MutableTreeModel,\n parentId: string | undefined\n): void {\n target.setNumChildren(\n parentId,\n (parentId === undefined ? source.getRootNode() : source.getNode(parentId)!)\n .numChildren\n );\n for (const [childId, index] of source\n .getChildren(parentId)\n ?.iterateValues() ?? []) {\n const node = source.getNode(childId)!;\n target.setChildren(\n parentId,\n [{ ...node, isLoading: !!node.isLoading }],\n index\n );\n cloneSubree(source, target, childId);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeModel.js","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeModel.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;AAEH,iCAAkC;AAClC,mCAAmC;AACnC,sDAA6C;AAE7C,kDAAkD;AAOlD,sDAAmD;AA4HnD;;;GAGG;AACH,SAAgB,eAAe,CAC7B,GAAkC;IAElC,OAAO,CACL,GAAG,KAAK,SAAS;QACjB,CAAC,0BAA0B,CAAC,GAAG,C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AAC,cAAc,CACnB,QAAQ,EACR,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAE,CAAC;SACxE,WAAW,CACf,CAAC;IACF,KAAK,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,MAAA,MAAA,MAAM;SAClC,WAAW,CAAC,QAAQ,CAAC,0CACpB,aAAa,EAAE,mCAAI,EAAE,EAAE;QACzB,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAE,CAAC;QACtC,MAAM,CAAC,WAAW,CAChB,QAAQ,EACR,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,EAC1C,KAAK,CACN,CAAC;QACF,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;KACtC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport { immerable } from \"immer\";\nimport { cloneDeep } from \"lodash\";\nimport { assert } from \"@itwin/core-bentley\";\nimport type { PropertyRecord } from \"@itwin/appui-abstract\";\nimport { CheckBoxState } from \"@itwin/core-react\";\nimport type {\n DelayLoadedTreeNodeItem,\n ImmediatelyLoadedTreeNodeItem,\n TreeNodeItem,\n} from \"../TreeDataProvider\";\nimport type { SparseArray } from \"./internal/SparseTree\";\nimport { SparseTree } from \"./internal/SparseTree\";\n\n/**\n * Immutable data structure that describes tree node.\n * @public\n */\nexport interface TreeModelNode {\n readonly id: string;\n readonly parentId: string | undefined;\n readonly depth: number;\n\n readonly isLoading?: boolean;\n readonly numChildren: number | undefined;\n\n readonly description: string | undefined;\n readonly isExpanded: boolean;\n readonly label: PropertyRecord;\n readonly isSelected: boolean;\n readonly isSelectionDisabled?: boolean;\n\n /** Specifies that node is in editing mode. It holds callbacks that are used by node editor. */\n readonly editingInfo?: TreeModelNodeEditingInfo;\n\n readonly checkbox: CheckBoxInfo;\n\n readonly item: TreeNodeItem;\n}\n\n/**\n * Immutable data structure that describes checkbox info.\n * @public\n */\nexport interface CheckBoxInfo {\n readonly state: CheckBoxState;\n readonly tooltip?: string;\n readonly isDisabled: boolean;\n readonly isVisible: boolean;\n}\n\n/**\n * Mutable data structure that describes tree node.\n * @public\n */\nexport interface MutableTreeModelNode extends TreeModelNode {\n isLoading: boolean;\n\n description: string;\n isExpanded: boolean;\n label: PropertyRecord;\n isSelected: boolean;\n isSelectionDisabled?: boolean;\n\n /** Specifies that node is in editing mode. It holds callbacks that are used by node editor. */\n editingInfo?: TreeModelNodeEditingInfo;\n\n checkbox: MutableCheckBoxInfo;\n\n item: TreeNodeItem;\n}\n\n/**\n * Data structure that holds callbacks used for tree node editing.\n * @public\n */\nexport interface TreeModelNodeEditingInfo {\n onCommit: (node: TreeModelNode, newValue: string) => void;\n onCancel: () => void;\n}\n\n/**\n * Mutable data structure that describes checkbox info.\n * @public\n */\nexport interface MutableCheckBoxInfo extends CheckBoxInfo {\n state: CheckBoxState;\n tooltip?: string;\n isDisabled: boolean;\n isVisible: boolean;\n}\n\n/**\n * Data structure that describes tree node placeholder.\n * @public\n */\nexport interface TreeModelNodePlaceholder {\n readonly childIndex: number;\n readonly depth: number;\n readonly parentId?: string;\n}\n\n/**\n * Data structure that describes tree root node.\n * @public\n */\nexport interface TreeModelRootNode {\n readonly depth: -1;\n readonly id: undefined;\n readonly numChildren: number | undefined;\n}\n\n/**\n * Data structure that describes input used to create tree node.\n * @public\n */\nexport interface TreeModelNodeInput {\n readonly description?: string;\n readonly isExpanded: boolean;\n readonly id: string;\n readonly item: TreeNodeItem;\n readonly label: PropertyRecord;\n readonly isLoading: boolean;\n readonly numChildren?: number;\n readonly isSelected: boolean;\n}\n\n/**\n * Type definition of all tree model nodes.\n * @public\n */\nexport type TreeModelNodeType =\n | TreeModelNode\n | TreeModelNodePlaceholder\n | TreeModelRootNode;\n\n/**\n * Checks if object is [[TreeModelNode]]\n * @public\n */\nexport function isTreeModelNode(\n obj: TreeModelNodeType | undefined\n): obj is TreeModelNode {\n return (\n obj !== undefined &&\n !isTreeModelNodePlaceholder(obj) &&\n !isTreeModelRootNode(obj)\n );\n}\n\n/**\n * Checks if object is [[TreeModelNodePlaceholder]]\n * @public\n */\nexport function isTreeModelNodePlaceholder(\n obj: TreeModelNodeType | undefined\n): obj is TreeModelNodePlaceholder {\n return obj !== undefined && \"childIndex\" in obj;\n}\n\n/**\n * Checks if object is [[TreeModelRootNode]]\n * @public\n */\nexport function isTreeModelRootNode(\n obj: TreeModelNodeType | undefined\n): obj is TreeModelRootNode {\n return (\n obj !== undefined &&\n (obj as TreeModelRootNode).id === undefined &&\n !(\"childIndex\" in obj)\n );\n}\n\n/**\n * Type definition of tree node item data.\n * @public\n */\nexport type TreeNodeItemData = ImmediatelyLoadedTreeNodeItem &\n DelayLoadedTreeNodeItem;\n\n/**\n * Data structure that describes set of visible tree nodes as a flat list.\n * @public\n */\nexport interface VisibleTreeNodes\n extends Iterable<TreeModelNode | TreeModelNodePlaceholder> {\n getNumNodes(): number;\n getAtIndex(\n index: number\n ): TreeModelNode | TreeModelNodePlaceholder | undefined;\n getModel(): TreeModel;\n getNumRootNodes(): number | undefined;\n getIndexOfNode(nodeId: string): number;\n}\n\n/**\n * Data structure that describes tree model.\n * @public\n */\nexport interface TreeModel {\n getRootNode(): TreeModelRootNode;\n\n getNode(id: string): TreeModelNode | undefined;\n getNode(\n parentId: string | undefined,\n childIndex: number\n ): TreeModelNode | TreeModelNodePlaceholder | undefined;\n getNode(\n nodeId: string | undefined,\n childIndex?: number\n ): TreeModelNode | TreeModelNodePlaceholder | TreeModelRootNode | undefined;\n\n getChildren(parentId: string | undefined): SparseArray<string> | undefined;\n getChildOffset(\n parentId: string | undefined,\n childId: string\n ): number | undefined;\n\n iterateTreeModelNodes(parentId?: string): IterableIterator<TreeModelNode>;\n}\n\n/**\n * Mutable tree model which holds nodes and allows adding or removing them.\n * @public\n */\nexport class MutableTreeModel implements TreeModel {\n public [immerable] = true;\n\n private _tree = new SparseTree<MutableTreeModelNode>();\n private _rootNode: TreeModelRootNode = {\n depth: -1,\n id: undefined,\n numChildren: undefined,\n };\n\n public constructor(seed?: TreeModel) {\n if (!seed) {\n return;\n }\n\n cloneSubree(seed, this, undefined);\n }\n\n /** Returns root node of a tree. This node is not visible and is there to allow having multiple visible root nodes. */\n public getRootNode(): TreeModelRootNode {\n return this._rootNode;\n }\n\n /** Returns tree node or placeholder for node that is not loaded yet.\n * @returns node, node placeholder or undefined if node is not found in model.\n */\n public getNode(id: string): MutableTreeModelNode | undefined;\n public getNode(\n parentId: string | undefined,\n childIndex: number\n ): MutableTreeModelNode | TreeModelNodePlaceholder | undefined;\n public getNode(\n nodeId: string | undefined,\n childIndex?: number\n ): MutableTreeModelNode | TreeModelNodePlaceholder | undefined {\n if (childIndex === undefined) {\n return this._tree.getNode(nodeId!);\n }\n\n const children = this._tree.getChildren(nodeId);\n const childId =\n children !== undefined ? children.get(childIndex) : undefined;\n if (childId !== undefined) {\n return this._tree.getNode(childId);\n }\n\n const parentNode =\n nodeId === undefined ? this._rootNode : this._tree.getNode(nodeId);\n if (parentNode !== undefined) {\n return {\n childIndex,\n depth: parentNode.depth + 1,\n parentId: nodeId,\n };\n }\n\n return undefined;\n }\n\n /** Returns children for specific parent.\n * @param parentId id of parent node.\n * @returns children of parent node or root nodes if undefined is passed as parent id.\n */\n public getChildren(\n parentId: string | undefined\n ): SparseArray<string> | undefined {\n return this._tree.getChildren(parentId);\n }\n\n /** Returns children offset in children array for specific parent. */\n public getChildOffset(\n parentId: string | undefined,\n childId: string\n ): number | undefined {\n return this._tree.getChildOffset(parentId, childId);\n }\n\n /**\n * Sets children for parent node starting from the specific offset.\n * If offset overlaps with already added nodes, the overlapping nodes are overwritten.\n */\n public setChildren(\n parentId: string | undefined,\n nodeInputs: TreeModelNodeInput[],\n offset: number\n ): void {\n const parentNode =\n parentId === undefined ? this._rootNode : this._tree.getNode(parentId);\n if (parentNode === undefined) return;\n\n const children: MutableTreeModelNode[] = [];\n for (const input of nodeInputs) {\n const child = MutableTreeModel.createTreeModelNode(parentNode, input);\n children.push(child);\n }\n\n this._tree.setChildren(parentNode.id, children, offset);\n MutableTreeModel.setNumChildrenForNode(\n parentNode,\n this._tree.getChildren(parentNode.id)\n );\n }\n\n /**\n * Inserts child in the specified position.\n * If offset is higher then current length of children array, the length is increased.\n */\n public insertChild(\n parentId: string | undefined,\n childNodeInput: TreeModelNodeInput,\n offset: number\n ): void {\n const parentNode =\n parentId === undefined ? this._rootNode : this._tree.getNode(parentId);\n if (parentNode === undefined) return;\n\n const child = MutableTreeModel.createTreeModelNode(\n parentNode,\n childNodeInput\n );\n\n this._tree.insertChild(parentNode.id, child, offset);\n MutableTreeModel.setNumChildrenForNode(\n parentNode,\n this._tree.getChildren(parentNode.id)\n );\n }\n\n /**\n * Changes the id of target node.\n * @returns `true` on success, `false` otherwise.\n */\n public changeNodeId(currentId: string, newId: string): boolean {\n const node = this.getNode(currentId);\n if (node === undefined) {\n return false;\n }\n\n if (currentId === newId) {\n return true;\n }\n\n const index = this.getChildOffset(node.parentId, currentId);\n assert(index !== undefined);\n\n if (!this._tree.setNodeId(node.parentId, index, newId)) {\n return false;\n }\n\n (node.id as string) = newId; // eslint-disable-line @typescript-eslint/no-unnecessary-type-assertion\n for (const [childId] of this.getChildren(newId)?.iterateValues() ?? []) {\n const child = this.getNode(childId);\n assert(child !== undefined);\n (child.parentId as string) = newId;\n }\n\n return true;\n }\n\n /**\n * Transfers node along with its children to a new location. Fails if destination has undefined child count.\n * @param sourceNodeId Node that is being moved.\n * @param targetParentId Node that will receive a new child.\n * @param targetIndex Insertion location among target's *current* children.\n * @returns `true` on success, `false` otherwise.\n */\n public moveNode(\n sourceNodeId: string,\n targetParentId: string | undefined,\n targetIndex: number\n ): boolean {\n const sourceNode = this.getNode(sourceNodeId);\n if (sourceNode === undefined) {\n return false;\n }\n\n const targetParent =\n targetParentId === undefined\n ? this._rootNode\n : this.getNode(targetParentId);\n if (targetParent === undefined || targetParent.numChildren === undefined) {\n return false;\n }\n\n if (\n targetParentId !== undefined &&\n this.areNodesRelated(sourceNodeId, targetParentId)\n ) {\n return false;\n }\n\n this._tree.moveNode(\n sourceNode.parentId,\n sourceNodeId,\n targetParentId,\n targetIndex\n );\n\n const sourceParent =\n sourceNode.parentId === undefined\n ? this._rootNode\n : this.getNode(sourceNode.parentId);\n assert(sourceParent !== undefined);\n MutableTreeModel.setNumChildrenForNode(\n sourceParent,\n this._tree.getChildren(sourceNode.parentId)\n );\n MutableTreeModel.setNumChildrenForNode(\n targetParent,\n this._tree.getChildren(targetParentId)\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (sourceNode.parentId as string | undefined) = targetParentId;\n\n const updateDepths = (parentId: string, depth: number) => {\n const node = this.getNode(parentId);\n assert(node !== undefined);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (node.depth as number) = depth;\n for (const [nodeId] of this.getChildren(parentId)?.iterateValues() ??\n []) {\n updateDepths(nodeId, depth + 1);\n }\n };\n\n updateDepths(sourceNodeId, targetParent.depth + 1);\n return true;\n }\n\n private areNodesRelated(\n ancestorNodeId: string,\n descendantNodeId: string\n ): boolean {\n const node = this.getNode(descendantNodeId);\n if (node === undefined || node.parentId === undefined) {\n return false;\n }\n\n return node.parentId === ancestorNodeId\n ? true\n : this.areNodesRelated(ancestorNodeId, node.parentId);\n }\n\n /**\n * Sets the number of child nodes a parent is expected to contain. All child nodes of this parent will be subsequently\n * removed.\n */\n public setNumChildren(\n parentId: string | undefined,\n numChildren: number | undefined\n ): void {\n const parentNode =\n parentId === undefined ? this._rootNode : this._tree.getNode(parentId);\n if (parentNode === undefined) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (parentNode.numChildren as number | undefined) = numChildren;\n this._tree.setNumChildren(parentId, numChildren ?? 0);\n }\n\n /** Removes children specified by id.\n * @param parentId id of the parent node.\n * @param child child node id or index that should be removed.\n */\n public removeChild(\n parentId: string | undefined,\n child: string | number\n ): void {\n const parentNode =\n parentId === undefined ? this._rootNode : this._tree.getNode(parentId);\n this._tree.removeChild(parentId, child);\n\n // istanbul ignore else\n if (parentNode)\n MutableTreeModel.setNumChildrenForNode(\n parentNode,\n this._tree.getChildren(parentNode.id)\n );\n }\n\n /** Removes all children for parent specified by id.\n * @param parentId id of parent node or undefined to remove root nodes.\n */\n public clearChildren(parentId: string | undefined) {\n const parentNode =\n parentId === undefined ? this._rootNode : this._tree.getNode(parentId);\n if (parentNode !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (parentNode.numChildren as number | undefined) = undefined;\n }\n this._tree.deleteSubtree(parentId, false);\n }\n\n /** Iterates over all nodes present in the tree model. */\n public *iterateTreeModelNodes(\n parentId?: string\n ): IterableIterator<MutableTreeModelNode> {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const _this = this;\n function* iterateDescendants(\n subParentId: string | undefined\n ): IterableIterator<MutableTreeModelNode> {\n const children = _this.getChildren(subParentId);\n if (children === undefined) {\n return;\n }\n\n for (const [nodeId] of children.iterateValues()) {\n const node = _this.getNode(nodeId);\n if (node !== undefined) {\n yield node;\n yield* iterateDescendants(nodeId);\n }\n }\n }\n\n yield* iterateDescendants(parentId);\n }\n\n private static setNumChildrenForNode(\n node: TreeModelRootNode | MutableTreeModelNode,\n children: SparseArray<string> | undefined\n ) {\n const numChildren = children ? children.getLength() : undefined;\n if (node.numChildren === numChildren) return;\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (node.numChildren as number | undefined) = numChildren;\n }\n\n private static createTreeModelNode(\n parentNode: TreeModelNode | TreeModelRootNode,\n input: TreeModelNodeInput\n ): MutableTreeModelNode {\n return {\n id: input.id,\n parentId: parentNode.id,\n depth: parentNode.depth + 1,\n\n isLoading: input.isLoading,\n numChildren: input.numChildren,\n\n description: input.description || \"\",\n isExpanded: input.isExpanded,\n label: input.label,\n isSelected: input.isSelected,\n isSelectionDisabled: input.item.isSelectionDisabled,\n\n checkbox: {\n state: input.item.checkBoxState || CheckBoxState.Off,\n isDisabled: !!input.item.isCheckboxDisabled,\n isVisible: !!input.item.isCheckboxVisible,\n },\n\n item: cloneDeep(input.item),\n };\n }\n}\n\n/**\n * Generates flat list of visible nodes in the tree model.\n * @public\n */\nexport function computeVisibleNodes(model: TreeModel): VisibleTreeNodes {\n const result = getVisibleDescendants(model, model.getRootNode());\n return {\n getNumNodes: () => result.length,\n getAtIndex: (\n index: number\n ): TreeModelNode | TreeModelNodePlaceholder | undefined => {\n return result[index];\n },\n getModel: () => model,\n getNumRootNodes: () => model.getRootNode().numChildren,\n [Symbol.iterator]: () => result[Symbol.iterator](),\n getIndexOfNode: (nodeId: string): number => {\n return result.findIndex(\n (visibleNode) => (visibleNode as TreeModelNode).id === nodeId\n );\n },\n };\n}\n\n/**\n * Traverses the tree and collects visible descendants.\n * @public\n */\nexport function getVisibleDescendants(\n model: TreeModel,\n parentNode: TreeModelNode | TreeModelRootNode,\n result: Array<TreeModelNode | TreeModelNodePlaceholder> = []\n): Array<TreeModelNode | TreeModelNodePlaceholder> {\n const children = model.getChildren(parentNode.id);\n if (!children) {\n return result;\n }\n\n let index = 0;\n for (const childId of children) {\n if (childId === undefined) {\n result.push({\n parentId: parentNode.id,\n depth: parentNode.depth + 1,\n childIndex: index,\n });\n } else {\n const childNode = model.getNode(childId);\n if (childNode === undefined) {\n // node was disposed\n result.push({\n parentId: parentNode.id,\n depth: parentNode.depth + 1,\n childIndex: index,\n });\n } else {\n result.push(childNode);\n if (childNode.isExpanded && childNode.numChildren !== undefined) {\n getVisibleDescendants(model, childNode, result);\n }\n }\n }\n ++index;\n }\n\n return result;\n}\n\nfunction cloneSubree(\n source: TreeModel,\n target: MutableTreeModel,\n parentId: string | undefined\n): void {\n target.setNumChildren(\n parentId,\n (parentId === undefined ? source.getRootNode() : source.getNode(parentId)!)\n .numChildren\n );\n for (const [childId, index] of source\n .getChildren(parentId)\n ?.iterateValues() ?? []) {\n const node = source.getNode(childId)!;\n target.setChildren(\n parentId,\n [{ ...node, isLoading: !!node.isLoading }],\n index\n );\n cloneSubree(source, target, childId);\n }\n}\n"]}
|
|
@@ -79,7 +79,7 @@ class TreeNodeLoader extends AbstractTreeNodeLoaderWithProvider {
|
|
|
79
79
|
loadNode(parent, _childIndex) {
|
|
80
80
|
return (0, rxjs_1.defer)(() => {
|
|
81
81
|
const parentItem = (0, TreeModel_1.isTreeModelNode)(parent) ? parent.item : undefined;
|
|
82
|
-
const parentId = parentItem
|
|
82
|
+
const parentId = parentItem === null || parentItem === void 0 ? void 0 : parentItem.id;
|
|
83
83
|
const activeRequest = this._activeRequests.get(parentId);
|
|
84
84
|
if (activeRequest) {
|
|
85
85
|
return activeRequest;
|
|
@@ -122,10 +122,10 @@ class PagedTreeNodeLoader extends AbstractTreeNodeLoaderWithProvider {
|
|
|
122
122
|
*/
|
|
123
123
|
loadNode(parent, childIndex) {
|
|
124
124
|
return (0, rxjs_1.defer)(() => {
|
|
125
|
+
var _a;
|
|
125
126
|
const parentItem = (0, TreeModel_1.isTreeModelNode)(parent) ? parent.item : undefined;
|
|
126
|
-
const parentId = parentItem
|
|
127
|
-
const parentPageRequests = this._activePageRequests.get(parentId)
|
|
128
|
-
new Map();
|
|
127
|
+
const parentId = parentItem === null || parentItem === void 0 ? void 0 : parentItem.id;
|
|
128
|
+
const parentPageRequests = (_a = this._activePageRequests.get(parentId)) !== null && _a !== void 0 ? _a : new Map();
|
|
129
129
|
const page = Math.trunc(childIndex / this._pageSize);
|
|
130
130
|
const activeRequest = parentPageRequests.get(page);
|
|
131
131
|
if (activeRequest) {
|
|
@@ -215,6 +215,7 @@ function handleLoadedNodeHierarchy(modelSource, loadedHierarchy) {
|
|
|
215
215
|
}
|
|
216
216
|
exports.handleLoadedNodeHierarchy = handleLoadedNodeHierarchy;
|
|
217
217
|
function updateChildren(model, parentId, hierarchyItems, startIndex, numChildren) {
|
|
218
|
+
var _a;
|
|
218
219
|
// numChildren set to undefined indicates that this is not the first request for children
|
|
219
220
|
if (numChildren !== undefined) {
|
|
220
221
|
model.setNumChildren(parentId, numChildren);
|
|
@@ -236,7 +237,7 @@ function updateChildren(model, parentId, hierarchyItems, startIndex, numChildren
|
|
|
236
237
|
}
|
|
237
238
|
else {
|
|
238
239
|
existingNode.label = nodeInput.label;
|
|
239
|
-
existingNode.description = nodeInput.description
|
|
240
|
+
existingNode.description = (_a = nodeInput.description) !== null && _a !== void 0 ? _a : "";
|
|
240
241
|
existingNode.item = nodeInput.item;
|
|
241
242
|
}
|
|
242
243
|
if (hierarchyItem.children) {
|
|
@@ -317,9 +318,10 @@ class TreeDataSource {
|
|
|
317
318
|
throw new appui_abstract_1.UiError(UiComponents_1.UiComponents.loggerCategory(this), "Unsupported TreeDataProvider.");
|
|
318
319
|
}
|
|
319
320
|
getChildren(rawProvider, parent) {
|
|
321
|
+
var _a;
|
|
320
322
|
if (parent === undefined)
|
|
321
323
|
return rawProvider;
|
|
322
|
-
return parent.children
|
|
324
|
+
return (_a = parent.children) !== null && _a !== void 0 ? _a : [];
|
|
323
325
|
}
|
|
324
326
|
}
|
|
325
327
|
exports.TreeDataSource = TreeDataSource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeLoader.js","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeNodeLoader.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAGH,+BAUc;AACd,0DAAgD;AAChD,8EAG4C;AAC5C,qDAAkD;AAOlD,0DAK6B;AAE7B,6CAAgD;AAQhD,2CAA8C;AAsC9C;;;GAGG;AACH,MAAsB,sBA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;QAE7C,OAAQ,MAAwC,CAAC,QAAQ,IAAI,EAAE,CAAC;IAClE,CAAC;CACF;AAnFD,wCAmFC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport type { Observable as RxjsObservable } from \"rxjs\";\nimport {\n concatAll,\n concatMap,\n defer,\n finalize,\n from,\n map,\n of,\n share,\n toArray,\n} from \"rxjs\";\nimport { UiError } from \"@itwin/appui-abstract\";\nimport {\n scheduleSubscription,\n SubscriptionScheduler,\n} from \"../../common/SubscriptionScheduler\";\nimport { UiComponents } from \"../../UiComponents\";\nimport type {\n ImmediatelyLoadedTreeNodeItem,\n TreeDataProvider,\n TreeDataProviderRaw,\n TreeNodeItem,\n} from \"../TreeDataProvider\";\nimport {\n isTreeDataProviderInterface,\n isTreeDataProviderMethod,\n isTreeDataProviderPromise,\n isTreeDataProviderRaw,\n} from \"../TreeDataProvider\";\nimport type { Observable } from \"./Observable\";\nimport { toRxjsObservable } from \"./Observable\";\nimport type {\n MutableTreeModel,\n TreeModelNode,\n TreeModelNodeInput,\n TreeModelRootNode,\n TreeNodeItemData,\n} from \"./TreeModel\";\nimport { isTreeModelNode } from \"./TreeModel\";\nimport type { TreeModelSource } from \"./TreeModelSource\";\n\n/**\n * Data structure that describes node load result\n * @public\n */\nexport interface TreeNodeLoadResult {\n loadedNodes: TreeNodeItem[];\n}\n\n/**\n * Tree node loader which is used to load tree nodes.\n * @public\n */\nexport interface ITreeNodeLoader {\n /**\n * Loads node at specified place in tree.\n * @param parentId specifies tree branch\n * @param childIndex specifies offset in the branch.\n */\n loadNode(\n parentId: TreeModelNode | TreeModelRootNode,\n childIndex: number\n ): Observable<TreeNodeLoadResult>;\n}\n\n/**\n * Tree node loader which uses `TreeDataProvider` to load nodes.\n * @public\n */\nexport interface ITreeNodeLoaderWithProvider<\n TDataProvider extends TreeDataProvider\n> extends ITreeNodeLoader {\n /** Returns `TreeDataProvider` used to load nodes. */\n readonly dataProvider: TDataProvider;\n}\n\n/**\n * Abstract node loader implementation which loads nodes into provided model source.\n * @public\n */\nexport abstract class AbstractTreeNodeLoader implements ITreeNodeLoader {\n private _treeModelSource: TreeModelSource;\n private _loadScheduler = new SubscriptionScheduler<LoadedNodeHierarchy>();\n\n protected constructor(modelSource: TreeModelSource) {\n this._treeModelSource = modelSource;\n }\n\n public get modelSource() {\n return this._treeModelSource;\n }\n\n /** Do not override this method. @see `load` */\n public loadNode(\n parent: TreeModelNode | TreeModelRootNode,\n childIndex: number\n ): Observable<TreeNodeLoadResult> {\n return toRxjsObservable(this.load(parent, childIndex)).pipe(\n scheduleSubscription(this._loadScheduler),\n map((loadedHierarchy) => {\n this.updateModel(loadedHierarchy);\n return {\n loadedNodes: collectTreeNodeItems(loadedHierarchy.hierarchyItems),\n };\n })\n );\n }\n\n /**\n * A method that's called when `load` loads some nodes and we need to put them into model source. The\n * default implementation simply puts loaded child nodes under their parent at correct positions. Concrete\n * implementation may override this method to handle loaded nodes in a a custom way (put them at custom locations\n * in the hierarchy, etc.)\n */\n protected updateModel(loadedHierarchy: LoadedNodeHierarchy): void {\n handleLoadedNodeHierarchy(this._treeModelSource, loadedHierarchy);\n }\n\n /** An abstract method to load a node at the specific index for the specified parent. */\n protected abstract load(\n parent: TreeModelNode | TreeModelRootNode,\n childIndex: number\n ): Observable<LoadedNodeHierarchy>;\n}\n\n/**\n * Abstract node loader with tree data provider which loads nodes into provided model source.\n * @public\n */\nexport abstract class AbstractTreeNodeLoaderWithProvider<\n TDataProvider extends TreeDataProvider\n >\n extends AbstractTreeNodeLoader\n implements ITreeNodeLoaderWithProvider<TDataProvider>\n{\n private _dataProvider: TDataProvider;\n\n protected constructor(\n modelSource: TreeModelSource,\n dataProvider: TDataProvider\n ) {\n super(modelSource);\n this._dataProvider = dataProvider;\n }\n\n public get dataProvider() {\n return this._dataProvider;\n }\n}\n\n/**\n * Default tree node loader with `TreeDataProvider` implementation.\n * @public\n */\nexport class TreeNodeLoader<\n TDataProvider extends TreeDataProvider\n> extends AbstractTreeNodeLoaderWithProvider<TDataProvider> {\n private _treeDataSource: TreeDataSource;\n private _activeRequests = new Map<\n string | undefined,\n RxjsObservable<TreeNodeLoadResult>\n >();\n private _scheduler = new SubscriptionScheduler<LoadedNodeHierarchy>();\n\n constructor(dataProvider: TDataProvider, modelSource: TreeModelSource) {\n super(modelSource, dataProvider);\n this._treeDataSource = new TreeDataSource(dataProvider);\n }\n\n /**\n * Schedules to load children of node and returns an Observable.\n * @note It does not start loading node until '.subscribe()' is called on returned Observable.\n */\n public override loadNode(\n parent: TreeModelNode | TreeModelRootNode,\n _childIndex?: number\n ): Observable<TreeNodeLoadResult> {\n return defer(() => {\n const parentItem = isTreeModelNode(parent) ? parent.item : undefined;\n const parentId = parentItem?.id;\n const activeRequest = this._activeRequests.get(parentId);\n if (activeRequest) {\n return activeRequest;\n }\n\n const newRequest = requestLoadedHierarchy(\n parentItem,\n this._treeDataSource,\n 0,\n 0,\n parent.numChildren === undefined\n ).pipe(\n scheduleSubscription(this._scheduler),\n map((loadedHierarchy) => {\n this.updateModel(loadedHierarchy);\n return {\n loadedNodes: collectTreeNodeItems(loadedHierarchy.hierarchyItems),\n };\n }),\n finalize(() => this._activeRequests.delete(parentId))\n );\n this._activeRequests.set(parentId, newRequest);\n return newRequest;\n });\n }\n\n // istanbul ignore next\n protected load(): Observable<LoadedNodeHierarchy> {\n throw new Error(\"Method not implemented.\");\n }\n}\n\n/**\n * Default paged tree node loader with `TreeDataProvider` implementation.\n * @public\n */\nexport class PagedTreeNodeLoader<\n TDataProvider extends TreeDataProvider\n> extends AbstractTreeNodeLoaderWithProvider<TDataProvider> {\n private _treeDataSource: TreeDataSource;\n private _pageSize: number;\n private _activePageRequests: Map<\n string | undefined,\n Map<number, RxjsObservable<TreeNodeLoadResult>>\n >;\n private _scheduler: SubscriptionScheduler<LoadedNodeHierarchy>;\n\n constructor(\n dataProvider: TDataProvider,\n modelSource: TreeModelSource,\n pageSize: number\n ) {\n super(modelSource, dataProvider);\n this._treeDataSource = new TreeDataSource(dataProvider);\n this._pageSize = pageSize;\n this._activePageRequests = new Map();\n this._scheduler = new SubscriptionScheduler();\n }\n\n /** Returns page size used by tree node loader. */\n public get pageSize(): number {\n return this._pageSize;\n }\n\n /**\n * Schedules to load one page of node children and returns an Observable.\n * @note It does not start loading node page until '.subscribe()' is called on returned Observable.\n */\n public override loadNode(\n parent: TreeModelNode | TreeModelRootNode,\n childIndex: number\n ): Observable<TreeNodeLoadResult> {\n return defer(() => {\n const parentItem = isTreeModelNode(parent) ? parent.item : undefined;\n const parentId = parentItem?.id;\n const parentPageRequests =\n this._activePageRequests.get(parentId) ??\n new Map<number, RxjsObservable<TreeNodeLoadResult>>();\n const page = Math.trunc(childIndex / this._pageSize);\n const activeRequest = parentPageRequests.get(page);\n if (activeRequest) {\n return activeRequest;\n }\n\n const startIndex = page * this._pageSize;\n const newRequest = requestLoadedHierarchy(\n parentItem,\n this._treeDataSource,\n startIndex,\n this._pageSize,\n parent.numChildren === undefined\n ).pipe(\n scheduleSubscription(this._scheduler),\n map((loadedHierarchy) => {\n this.updateModel(loadedHierarchy);\n return {\n loadedNodes: collectTreeNodeItems(loadedHierarchy.hierarchyItems),\n };\n }),\n finalize(() => {\n parentPageRequests.delete(page);\n if (parentPageRequests.size === 0) {\n this._activePageRequests.delete(parentId);\n }\n })\n );\n\n parentPageRequests.set(page, newRequest);\n this._activePageRequests.set(parentId, parentPageRequests);\n return newRequest;\n });\n }\n\n // istanbul ignore next\n protected load(): Observable<LoadedNodeHierarchy> {\n throw new Error(\"Method not implemented.\");\n }\n}\n\n/**\n * Data structure that describes hierarchy loaded for parent node.\n * @public\n */\nexport interface LoadedNodeHierarchy {\n /** Node id of the parent node for loaded hierarchy. */\n parentId: string | undefined;\n /** Hierarchy items offset in parent node children array. */\n offset: number;\n /** Loaded hierarchy items. */\n hierarchyItems: LoadedNodeHierarchyItem[];\n /** Number of children parent node has. */\n numChildren?: number;\n}\n\n/**\n * Data structure that describes one loaded hierarchy item.\n * @public\n */\nexport interface LoadedNodeHierarchyItem {\n /** Loaded tree node item. */\n item: TreeNodeItemData;\n /** Children of loaded tree node item. */\n children?: LoadedNodeHierarchyItem[];\n /** Number of children tree node item has. */\n numChildren?: number;\n}\n\nfunction requestLoadedHierarchy(\n parentItem: TreeNodeItem | undefined,\n dataSource: TreeDataSource,\n start: number,\n take: number,\n requestNumChildren: boolean\n) {\n const parentId = parentItem && parentItem.id;\n return dataSource\n .requestItems(parentItem, start, take, requestNumChildren)\n .pipe(\n concatMap(({ numChildren, loadedItems }) =>\n loadHierarchy(loadedItems, dataSource, take).pipe(\n map((hierarchyItems) => ({\n parentId,\n offset: start,\n hierarchyItems,\n numChildren,\n }))\n )\n )\n );\n}\n\nfunction loadHierarchy(\n rootItems: TreeNodeItemData[],\n dataSource: TreeDataSource,\n take: number\n): RxjsObservable<LoadedNodeHierarchyItem[]> {\n return from(rootItems).pipe(\n concatMap((item) => {\n if (!item.autoExpand || item.children) {\n return of(convertToLoadedNodeHierarchyItem(item));\n }\n\n return dataSource\n .requestItems(item, 0, take, true)\n .pipe(\n concatMap(({ numChildren, loadedItems }) =>\n loadHierarchy(loadedItems, dataSource, take).pipe(\n map((children) => ({ item, children, numChildren }))\n )\n )\n );\n }),\n toArray()\n );\n}\n\nfunction convertToLoadedNodeHierarchyItem(\n item: TreeNodeItemData\n): LoadedNodeHierarchyItem {\n return {\n item,\n children: item.children\n ? item.children.map((child) => convertToLoadedNodeHierarchyItem(child))\n : undefined,\n numChildren: item.children ? item.children.length : undefined,\n };\n}\n\nfunction collectTreeNodeItems(\n hierarchyItems: LoadedNodeHierarchyItem[],\n result: TreeNodeItem[] = []\n) {\n for (const hierarchyItem of hierarchyItems) {\n result.push(hierarchyItem.item);\n if (hierarchyItem.children)\n collectTreeNodeItems(hierarchyItem.children, result);\n }\n\n return result;\n}\n\n/** @internal */\nexport function handleLoadedNodeHierarchy(\n modelSource: TreeModelSource,\n loadedHierarchy: LoadedNodeHierarchy\n) {\n modelSource.modifyModel((model) => {\n if (loadedHierarchy.parentId !== undefined) {\n // Make sure the model sill contains the parent node\n /* istanbul ignore if */\n if (model.getNode(loadedHierarchy.parentId) === undefined) return;\n }\n\n updateChildren(\n model,\n loadedHierarchy.parentId,\n loadedHierarchy.hierarchyItems,\n loadedHierarchy.offset,\n loadedHierarchy.numChildren\n );\n if (loadedHierarchy.parentId !== undefined) {\n const parentNode = model.getNode(loadedHierarchy.parentId);\n /* istanbul ignore else */\n if (\n parentNode &&\n parentNode.isLoading &&\n parentNode.numChildren !== undefined\n ) {\n parentNode.isLoading = false;\n }\n }\n });\n}\n\nfunction updateChildren(\n model: MutableTreeModel,\n parentId: string | undefined,\n hierarchyItems: LoadedNodeHierarchyItem[],\n startIndex: number,\n numChildren?: number\n) {\n // numChildren set to undefined indicates that this is not the first request for children\n if (numChildren !== undefined) {\n model.setNumChildren(parentId, numChildren);\n }\n\n // if children array is undefined do not add children as they should be disposed\n if (model.getChildren(parentId) === undefined) {\n return;\n }\n\n let offset = startIndex;\n for (const hierarchyItem of hierarchyItems) {\n const nodeInput = convertToTreeModelNodeInput(hierarchyItem.item);\n const existingNode = model.getNode(hierarchyItem.item.id);\n\n // if same item exists in the same position and is expanded update it without removing it's subtree\n if (\n !existingNode ||\n !existingNode.isExpanded ||\n model.getChildOffset(parentId, existingNode.id) !== offset ||\n nodeInput.numChildren === 0\n ) {\n model.setChildren(parentId, [nodeInput], offset);\n } else {\n existingNode.label = nodeInput.label;\n existingNode.description = nodeInput.description ?? \"\";\n existingNode.item = nodeInput.item;\n }\n\n if (hierarchyItem.children) {\n updateChildren(\n model,\n hierarchyItem.item.id,\n hierarchyItem.children,\n 0,\n hierarchyItem.numChildren\n );\n }\n offset++;\n }\n}\n\nfunction convertToTreeModelNodeInput(\n item: TreeNodeItemData\n): TreeModelNodeInput {\n let numChildren: number | undefined;\n if (item.children) {\n numChildren = item.children.length;\n } else if (!item.hasChildren) {\n numChildren = 0;\n }\n\n return {\n description: item.description,\n isExpanded: !!item.autoExpand,\n id: item.id,\n item,\n label: item.label,\n isLoading: false,\n numChildren,\n isSelected: false,\n };\n}\n\ninterface TreeDataSourceResult {\n loadedItems: TreeNodeItemData[];\n numChildren?: number;\n}\n\n/**\n * Wrapper to handle different types of `TreeDataProvider`. Provides one method\n * to request items from `TreeDataProviderRaw`, `TreeDataProviderMethod`,\n * `TreeDataProviderPromise` or `TreeDataProviderInterface`.\n *\n * @internal\n */\nexport class TreeDataSource {\n private _dataProvider: TreeDataProvider;\n\n constructor(dataProvider: TreeDataProvider) {\n this._dataProvider = dataProvider;\n }\n\n public requestItems(\n parent: TreeNodeItem | undefined,\n firstItemIndex: number,\n numItems: number,\n requestNumChildren: boolean\n ): RxjsObservable<TreeDataSourceResult> {\n // During each async operation there is a chance that data provider will become stale. Create an opportunity to\n // unsubscribe after each async operation so that we stop interacting with the stale data provider immediately.\n return defer(async () => {\n if (isTreeDataProviderInterface(this._dataProvider)) {\n const dataProvider = this._dataProvider;\n return from(\n requestNumChildren ? dataProvider.getNodesCount(parent) : [undefined]\n ).pipe(\n concatMap(async (numChildren) => {\n const pageOptions =\n numItems !== 0\n ? { size: numItems, start: firstItemIndex }\n : undefined;\n return {\n loadedItems: await dataProvider.getNodes(parent, pageOptions),\n numChildren,\n };\n })\n );\n }\n\n return from(this.getItems(parent)).pipe(\n map((loadedItems) => ({\n loadedItems:\n numItems !== 0\n ? loadedItems.slice(firstItemIndex, firstItemIndex + numItems)\n : loadedItems,\n numChildren: loadedItems.length,\n }))\n );\n }).pipe(\n concatAll(),\n share({\n resetOnError: false,\n resetOnComplete: false,\n resetOnRefCountZero: true,\n })\n );\n }\n\n private async getItems(\n parent: TreeNodeItem | undefined\n ): Promise<TreeNodeItemData[]> {\n if (isTreeDataProviderRaw(this._dataProvider)) {\n return this.getChildren(this._dataProvider, parent);\n }\n\n if (isTreeDataProviderMethod(this._dataProvider)) {\n return this._dataProvider(parent);\n }\n\n if (isTreeDataProviderPromise(this._dataProvider)) {\n this._dataProvider = await this._dataProvider;\n return this.getChildren(this._dataProvider, parent);\n }\n\n throw new UiError(\n UiComponents.loggerCategory(this),\n \"Unsupported TreeDataProvider.\"\n );\n }\n\n private getChildren(\n rawProvider: TreeDataProviderRaw,\n parent: TreeNodeItem | undefined\n ): TreeNodeItemData[] {\n if (parent === undefined) return rawProvider;\n\n return (parent as ImmediatelyLoadedTreeNodeItem).children ?? [];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeNodeLoader.js","sourceRoot":"","sources":["../../../../../src/components-react/tree/controlled/TreeNodeLoader.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAGH,+BAUc;AACd,0DAAgD;AAChD,8EAG4C;AAC5C,qDAAkD;AAOlD,0DAK6B;AAE7B,6CAAgD;AAQhD,2CAA8C;AAsC9C;;;GAGG;AACH,MAAsB,sBAAsB;IAI1C,YAAsB,WAA4B;QAF1C,mBAAc,GAAG,IAAI,6CAAqB,EAAuB,CAAC;QAGxE,IAAI,CAAC,gBAAgB,GAAG,WAAW,CAAC;IACtC,CAAC;IAED,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED,+CAA+C;IACxC,QAAQ,CACb,MAAyC,EACzC,UAAkB;QAElB,OAAO,IAAA,6BAAgB,EAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CACzD,IAAA,4CAAoB,EAAC,IAAI,CAAC,cAAc,CAAC,EACzC,IAAA,UAAG,EAAC,CAAC,eAAe,EAAE,EAAE;YACtB,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;YAClC,OAAO;gBACL,WAAW,EAAE,oBAAoB,CAAC,eAAe,CAAC,cAAc,CAAC;aAClE,CAAC;Q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AAC;IAEO,KAAK,CAAC,QAAQ,CACpB,MAAgC;QAEhC,IAAI,IAAA,wCAAqB,EAAC,IAAI,CAAC,aAAa,CAAC,EAAE;YAC7C,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;SACrD;QAED,IAAI,IAAA,2CAAwB,EAAC,IAAI,CAAC,aAAa,CAAC,EAAE;YAChD,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;SACnC;QAED,IAAI,IAAA,4CAAyB,EAAC,IAAI,CAAC,aAAa,CAAC,EAAE;YACjD,IAAI,CAAC,aAAa,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC;YAC9C,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;SACrD;QAED,MAAM,IAAI,wBAAO,CACf,2BAAY,CAAC,cAAc,CAAC,IAAI,CAAC,EACjC,+BAA+B,CAChC,CAAC;IACJ,CAAC;IAEO,WAAW,CACjB,WAAgC,EAChC,MAAgC;;QAEhC,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,WAAW,CAAC;QAE7C,OAAO,MAAC,MAAwC,CAAC,QAAQ,mCAAI,EAAE,CAAC;IAClE,CAAC;CACF;AAnFD,wCAmFC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport type { Observable as RxjsObservable } from \"rxjs\";\nimport {\n concatAll,\n concatMap,\n defer,\n finalize,\n from,\n map,\n of,\n share,\n toArray,\n} from \"rxjs\";\nimport { UiError } from \"@itwin/appui-abstract\";\nimport {\n scheduleSubscription,\n SubscriptionScheduler,\n} from \"../../common/SubscriptionScheduler\";\nimport { UiComponents } from \"../../UiComponents\";\nimport type {\n ImmediatelyLoadedTreeNodeItem,\n TreeDataProvider,\n TreeDataProviderRaw,\n TreeNodeItem,\n} from \"../TreeDataProvider\";\nimport {\n isTreeDataProviderInterface,\n isTreeDataProviderMethod,\n isTreeDataProviderPromise,\n isTreeDataProviderRaw,\n} from \"../TreeDataProvider\";\nimport type { Observable } from \"./Observable\";\nimport { toRxjsObservable } from \"./Observable\";\nimport type {\n MutableTreeModel,\n TreeModelNode,\n TreeModelNodeInput,\n TreeModelRootNode,\n TreeNodeItemData,\n} from \"./TreeModel\";\nimport { isTreeModelNode } from \"./TreeModel\";\nimport type { TreeModelSource } from \"./TreeModelSource\";\n\n/**\n * Data structure that describes node load result\n * @public\n */\nexport interface TreeNodeLoadResult {\n loadedNodes: TreeNodeItem[];\n}\n\n/**\n * Tree node loader which is used to load tree nodes.\n * @public\n */\nexport interface ITreeNodeLoader {\n /**\n * Loads node at specified place in tree.\n * @param parentId specifies tree branch\n * @param childIndex specifies offset in the branch.\n */\n loadNode(\n parentId: TreeModelNode | TreeModelRootNode,\n childIndex: number\n ): Observable<TreeNodeLoadResult>;\n}\n\n/**\n * Tree node loader which uses `TreeDataProvider` to load nodes.\n * @public\n */\nexport interface ITreeNodeLoaderWithProvider<\n TDataProvider extends TreeDataProvider\n> extends ITreeNodeLoader {\n /** Returns `TreeDataProvider` used to load nodes. */\n readonly dataProvider: TDataProvider;\n}\n\n/**\n * Abstract node loader implementation which loads nodes into provided model source.\n * @public\n */\nexport abstract class AbstractTreeNodeLoader implements ITreeNodeLoader {\n private _treeModelSource: TreeModelSource;\n private _loadScheduler = new SubscriptionScheduler<LoadedNodeHierarchy>();\n\n protected constructor(modelSource: TreeModelSource) {\n this._treeModelSource = modelSource;\n }\n\n public get modelSource() {\n return this._treeModelSource;\n }\n\n /** Do not override this method. @see `load` */\n public loadNode(\n parent: TreeModelNode | TreeModelRootNode,\n childIndex: number\n ): Observable<TreeNodeLoadResult> {\n return toRxjsObservable(this.load(parent, childIndex)).pipe(\n scheduleSubscription(this._loadScheduler),\n map((loadedHierarchy) => {\n this.updateModel(loadedHierarchy);\n return {\n loadedNodes: collectTreeNodeItems(loadedHierarchy.hierarchyItems),\n };\n })\n );\n }\n\n /**\n * A method that's called when `load` loads some nodes and we need to put them into model source. The\n * default implementation simply puts loaded child nodes under their parent at correct positions. Concrete\n * implementation may override this method to handle loaded nodes in a a custom way (put them at custom locations\n * in the hierarchy, etc.)\n */\n protected updateModel(loadedHierarchy: LoadedNodeHierarchy): void {\n handleLoadedNodeHierarchy(this._treeModelSource, loadedHierarchy);\n }\n\n /** An abstract method to load a node at the specific index for the specified parent. */\n protected abstract load(\n parent: TreeModelNode | TreeModelRootNode,\n childIndex: number\n ): Observable<LoadedNodeHierarchy>;\n}\n\n/**\n * Abstract node loader with tree data provider which loads nodes into provided model source.\n * @public\n */\nexport abstract class AbstractTreeNodeLoaderWithProvider<\n TDataProvider extends TreeDataProvider\n >\n extends AbstractTreeNodeLoader\n implements ITreeNodeLoaderWithProvider<TDataProvider>\n{\n private _dataProvider: TDataProvider;\n\n protected constructor(\n modelSource: TreeModelSource,\n dataProvider: TDataProvider\n ) {\n super(modelSource);\n this._dataProvider = dataProvider;\n }\n\n public get dataProvider() {\n return this._dataProvider;\n }\n}\n\n/**\n * Default tree node loader with `TreeDataProvider` implementation.\n * @public\n */\nexport class TreeNodeLoader<\n TDataProvider extends TreeDataProvider\n> extends AbstractTreeNodeLoaderWithProvider<TDataProvider> {\n private _treeDataSource: TreeDataSource;\n private _activeRequests = new Map<\n string | undefined,\n RxjsObservable<TreeNodeLoadResult>\n >();\n private _scheduler = new SubscriptionScheduler<LoadedNodeHierarchy>();\n\n constructor(dataProvider: TDataProvider, modelSource: TreeModelSource) {\n super(modelSource, dataProvider);\n this._treeDataSource = new TreeDataSource(dataProvider);\n }\n\n /**\n * Schedules to load children of node and returns an Observable.\n * @note It does not start loading node until '.subscribe()' is called on returned Observable.\n */\n public override loadNode(\n parent: TreeModelNode | TreeModelRootNode,\n _childIndex?: number\n ): Observable<TreeNodeLoadResult> {\n return defer(() => {\n const parentItem = isTreeModelNode(parent) ? parent.item : undefined;\n const parentId = parentItem?.id;\n const activeRequest = this._activeRequests.get(parentId);\n if (activeRequest) {\n return activeRequest;\n }\n\n const newRequest = requestLoadedHierarchy(\n parentItem,\n this._treeDataSource,\n 0,\n 0,\n parent.numChildren === undefined\n ).pipe(\n scheduleSubscription(this._scheduler),\n map((loadedHierarchy) => {\n this.updateModel(loadedHierarchy);\n return {\n loadedNodes: collectTreeNodeItems(loadedHierarchy.hierarchyItems),\n };\n }),\n finalize(() => this._activeRequests.delete(parentId))\n );\n this._activeRequests.set(parentId, newRequest);\n return newRequest;\n });\n }\n\n // istanbul ignore next\n protected load(): Observable<LoadedNodeHierarchy> {\n throw new Error(\"Method not implemented.\");\n }\n}\n\n/**\n * Default paged tree node loader with `TreeDataProvider` implementation.\n * @public\n */\nexport class PagedTreeNodeLoader<\n TDataProvider extends TreeDataProvider\n> extends AbstractTreeNodeLoaderWithProvider<TDataProvider> {\n private _treeDataSource: TreeDataSource;\n private _pageSize: number;\n private _activePageRequests: Map<\n string | undefined,\n Map<number, RxjsObservable<TreeNodeLoadResult>>\n >;\n private _scheduler: SubscriptionScheduler<LoadedNodeHierarchy>;\n\n constructor(\n dataProvider: TDataProvider,\n modelSource: TreeModelSource,\n pageSize: number\n ) {\n super(modelSource, dataProvider);\n this._treeDataSource = new TreeDataSource(dataProvider);\n this._pageSize = pageSize;\n this._activePageRequests = new Map();\n this._scheduler = new SubscriptionScheduler();\n }\n\n /** Returns page size used by tree node loader. */\n public get pageSize(): number {\n return this._pageSize;\n }\n\n /**\n * Schedules to load one page of node children and returns an Observable.\n * @note It does not start loading node page until '.subscribe()' is called on returned Observable.\n */\n public override loadNode(\n parent: TreeModelNode | TreeModelRootNode,\n childIndex: number\n ): Observable<TreeNodeLoadResult> {\n return defer(() => {\n const parentItem = isTreeModelNode(parent) ? parent.item : undefined;\n const parentId = parentItem?.id;\n const parentPageRequests =\n this._activePageRequests.get(parentId) ??\n new Map<number, RxjsObservable<TreeNodeLoadResult>>();\n const page = Math.trunc(childIndex / this._pageSize);\n const activeRequest = parentPageRequests.get(page);\n if (activeRequest) {\n return activeRequest;\n }\n\n const startIndex = page * this._pageSize;\n const newRequest = requestLoadedHierarchy(\n parentItem,\n this._treeDataSource,\n startIndex,\n this._pageSize,\n parent.numChildren === undefined\n ).pipe(\n scheduleSubscription(this._scheduler),\n map((loadedHierarchy) => {\n this.updateModel(loadedHierarchy);\n return {\n loadedNodes: collectTreeNodeItems(loadedHierarchy.hierarchyItems),\n };\n }),\n finalize(() => {\n parentPageRequests.delete(page);\n if (parentPageRequests.size === 0) {\n this._activePageRequests.delete(parentId);\n }\n })\n );\n\n parentPageRequests.set(page, newRequest);\n this._activePageRequests.set(parentId, parentPageRequests);\n return newRequest;\n });\n }\n\n // istanbul ignore next\n protected load(): Observable<LoadedNodeHierarchy> {\n throw new Error(\"Method not implemented.\");\n }\n}\n\n/**\n * Data structure that describes hierarchy loaded for parent node.\n * @public\n */\nexport interface LoadedNodeHierarchy {\n /** Node id of the parent node for loaded hierarchy. */\n parentId: string | undefined;\n /** Hierarchy items offset in parent node children array. */\n offset: number;\n /** Loaded hierarchy items. */\n hierarchyItems: LoadedNodeHierarchyItem[];\n /** Number of children parent node has. */\n numChildren?: number;\n}\n\n/**\n * Data structure that describes one loaded hierarchy item.\n * @public\n */\nexport interface LoadedNodeHierarchyItem {\n /** Loaded tree node item. */\n item: TreeNodeItemData;\n /** Children of loaded tree node item. */\n children?: LoadedNodeHierarchyItem[];\n /** Number of children tree node item has. */\n numChildren?: number;\n}\n\nfunction requestLoadedHierarchy(\n parentItem: TreeNodeItem | undefined,\n dataSource: TreeDataSource,\n start: number,\n take: number,\n requestNumChildren: boolean\n) {\n const parentId = parentItem && parentItem.id;\n return dataSource\n .requestItems(parentItem, start, take, requestNumChildren)\n .pipe(\n concatMap(({ numChildren, loadedItems }) =>\n loadHierarchy(loadedItems, dataSource, take).pipe(\n map((hierarchyItems) => ({\n parentId,\n offset: start,\n hierarchyItems,\n numChildren,\n }))\n )\n )\n );\n}\n\nfunction loadHierarchy(\n rootItems: TreeNodeItemData[],\n dataSource: TreeDataSource,\n take: number\n): RxjsObservable<LoadedNodeHierarchyItem[]> {\n return from(rootItems).pipe(\n concatMap((item) => {\n if (!item.autoExpand || item.children) {\n return of(convertToLoadedNodeHierarchyItem(item));\n }\n\n return dataSource\n .requestItems(item, 0, take, true)\n .pipe(\n concatMap(({ numChildren, loadedItems }) =>\n loadHierarchy(loadedItems, dataSource, take).pipe(\n map((children) => ({ item, children, numChildren }))\n )\n )\n );\n }),\n toArray()\n );\n}\n\nfunction convertToLoadedNodeHierarchyItem(\n item: TreeNodeItemData\n): LoadedNodeHierarchyItem {\n return {\n item,\n children: item.children\n ? item.children.map((child) => convertToLoadedNodeHierarchyItem(child))\n : undefined,\n numChildren: item.children ? item.children.length : undefined,\n };\n}\n\nfunction collectTreeNodeItems(\n hierarchyItems: LoadedNodeHierarchyItem[],\n result: TreeNodeItem[] = []\n) {\n for (const hierarchyItem of hierarchyItems) {\n result.push(hierarchyItem.item);\n if (hierarchyItem.children)\n collectTreeNodeItems(hierarchyItem.children, result);\n }\n\n return result;\n}\n\n/** @internal */\nexport function handleLoadedNodeHierarchy(\n modelSource: TreeModelSource,\n loadedHierarchy: LoadedNodeHierarchy\n) {\n modelSource.modifyModel((model) => {\n if (loadedHierarchy.parentId !== undefined) {\n // Make sure the model sill contains the parent node\n /* istanbul ignore if */\n if (model.getNode(loadedHierarchy.parentId) === undefined) return;\n }\n\n updateChildren(\n model,\n loadedHierarchy.parentId,\n loadedHierarchy.hierarchyItems,\n loadedHierarchy.offset,\n loadedHierarchy.numChildren\n );\n if (loadedHierarchy.parentId !== undefined) {\n const parentNode = model.getNode(loadedHierarchy.parentId);\n /* istanbul ignore else */\n if (\n parentNode &&\n parentNode.isLoading &&\n parentNode.numChildren !== undefined\n ) {\n parentNode.isLoading = false;\n }\n }\n });\n}\n\nfunction updateChildren(\n model: MutableTreeModel,\n parentId: string | undefined,\n hierarchyItems: LoadedNodeHierarchyItem[],\n startIndex: number,\n numChildren?: number\n) {\n // numChildren set to undefined indicates that this is not the first request for children\n if (numChildren !== undefined) {\n model.setNumChildren(parentId, numChildren);\n }\n\n // if children array is undefined do not add children as they should be disposed\n if (model.getChildren(parentId) === undefined) {\n return;\n }\n\n let offset = startIndex;\n for (const hierarchyItem of hierarchyItems) {\n const nodeInput = convertToTreeModelNodeInput(hierarchyItem.item);\n const existingNode = model.getNode(hierarchyItem.item.id);\n\n // if same item exists in the same position and is expanded update it without removing it's subtree\n if (\n !existingNode ||\n !existingNode.isExpanded ||\n model.getChildOffset(parentId, existingNode.id) !== offset ||\n nodeInput.numChildren === 0\n ) {\n model.setChildren(parentId, [nodeInput], offset);\n } else {\n existingNode.label = nodeInput.label;\n existingNode.description = nodeInput.description ?? \"\";\n existingNode.item = nodeInput.item;\n }\n\n if (hierarchyItem.children) {\n updateChildren(\n model,\n hierarchyItem.item.id,\n hierarchyItem.children,\n 0,\n hierarchyItem.numChildren\n );\n }\n offset++;\n }\n}\n\nfunction convertToTreeModelNodeInput(\n item: TreeNodeItemData\n): TreeModelNodeInput {\n let numChildren: number | undefined;\n if (item.children) {\n numChildren = item.children.length;\n } else if (!item.hasChildren) {\n numChildren = 0;\n }\n\n return {\n description: item.description,\n isExpanded: !!item.autoExpand,\n id: item.id,\n item,\n label: item.label,\n isLoading: false,\n numChildren,\n isSelected: false,\n };\n}\n\ninterface TreeDataSourceResult {\n loadedItems: TreeNodeItemData[];\n numChildren?: number;\n}\n\n/**\n * Wrapper to handle different types of `TreeDataProvider`. Provides one method\n * to request items from `TreeDataProviderRaw`, `TreeDataProviderMethod`,\n * `TreeDataProviderPromise` or `TreeDataProviderInterface`.\n *\n * @internal\n */\nexport class TreeDataSource {\n private _dataProvider: TreeDataProvider;\n\n constructor(dataProvider: TreeDataProvider) {\n this._dataProvider = dataProvider;\n }\n\n public requestItems(\n parent: TreeNodeItem | undefined,\n firstItemIndex: number,\n numItems: number,\n requestNumChildren: boolean\n ): RxjsObservable<TreeDataSourceResult> {\n // During each async operation there is a chance that data provider will become stale. Create an opportunity to\n // unsubscribe after each async operation so that we stop interacting with the stale data provider immediately.\n return defer(async () => {\n if (isTreeDataProviderInterface(this._dataProvider)) {\n const dataProvider = this._dataProvider;\n return from(\n requestNumChildren ? dataProvider.getNodesCount(parent) : [undefined]\n ).pipe(\n concatMap(async (numChildren) => {\n const pageOptions =\n numItems !== 0\n ? { size: numItems, start: firstItemIndex }\n : undefined;\n return {\n loadedItems: await dataProvider.getNodes(parent, pageOptions),\n numChildren,\n };\n })\n );\n }\n\n return from(this.getItems(parent)).pipe(\n map((loadedItems) => ({\n loadedItems:\n numItems !== 0\n ? loadedItems.slice(firstItemIndex, firstItemIndex + numItems)\n : loadedItems,\n numChildren: loadedItems.length,\n }))\n );\n }).pipe(\n concatAll(),\n share({\n resetOnError: false,\n resetOnComplete: false,\n resetOnRefCountZero: true,\n })\n );\n }\n\n private async getItems(\n parent: TreeNodeItem | undefined\n ): Promise<TreeNodeItemData[]> {\n if (isTreeDataProviderRaw(this._dataProvider)) {\n return this.getChildren(this._dataProvider, parent);\n }\n\n if (isTreeDataProviderMethod(this._dataProvider)) {\n return this._dataProvider(parent);\n }\n\n if (isTreeDataProviderPromise(this._dataProvider)) {\n this._dataProvider = await this._dataProvider;\n return this.getChildren(this._dataProvider, parent);\n }\n\n throw new UiError(\n UiComponents.loggerCategory(this),\n \"Unsupported TreeDataProvider.\"\n );\n }\n\n private getChildren(\n rawProvider: TreeDataProviderRaw,\n parent: TreeNodeItem | undefined\n ): TreeNodeItemData[] {\n if (parent === undefined) return rawProvider;\n\n return (parent as ImmediatelyLoadedTreeNodeItem).children ?? [];\n }\n}\n"]}
|
|
@@ -58,7 +58,8 @@ class SparseTree {
|
|
|
58
58
|
this._idToNode[child.id] = child;
|
|
59
59
|
}
|
|
60
60
|
setNodeId(parentId, index, newId) {
|
|
61
|
-
|
|
61
|
+
var _a;
|
|
62
|
+
const previousNodeId = (_a = this.getChildren(parentId)) === null || _a === void 0 ? void 0 : _a.get(index);
|
|
62
63
|
if (previousNodeId === undefined) {
|
|
63
64
|
return false;
|
|
64
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SparseTree.js","sourceRoot":"","sources":["../../../../../../src/components-react/tree/controlled/internal/SparseTree.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,iCAAkC;AAClC,sDAAyE;AAOzE;;;;;GAKG;AACH,MAAa,UAAU;IAOrB;QAJQ,eAAU,GAAG,IAAI,WAAW,EAAU,CAAC;QACvC,sBAAiB,GAAwC,EAAE,CAAC;QAC5D,cAAS,GAAsB,EAAE,CAAC;QAGxC,IAAI,CAAC,iBAAS,CAAC,GAAG,IAAI,CAAC;IACzB,CAAC;IAEM,OAAO,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAEM,cAAc,CACnB,QAA4B,EAC5B,OAAe;QAEf,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ;YAAE,OAAO,SAAS,CAAC;QAEhC,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAEM,WAAW,CAChB,QAA4B,EAC5B,mBAA4B,KAAK;QAEjC,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,OAAO,IAAI,CAAC,UAAU,CAAC;SACxB;QAED,IAAI,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,KAAK,SAAS,IAAI,gBAAgB,EAAE;YACtE,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,IAAI,WAAW,EAAU,CAAC;SAC9D;QAED,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAE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AC;IAEO,MAAM,CAAC,OAAO,CAAI,KAAa,EAAE,KAAkB;QACzD,OAAO,IAAA,6BAAc,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AApHD,kCAoHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport { immerable } from \"immer\";\nimport { assert, compareNumbers, lowerBound } from \"@itwin/core-bentley\";\n\n/** @internal */\nexport interface Node {\n readonly id: string;\n}\n\n/**\n * Structure for sparse tree storage.\n * It uses SparseArray to store children ids for parent. This allows\n * having tree structure with some nodes missing in the tree branch.\n * @internal\n */\nexport class SparseTree<T extends Node> {\n public [immerable]: boolean;\n\n private _rootNodes = new SparseArray<string>();\n private _parentToChildren: Record<string, SparseArray<string>> = {};\n private _idToNode: Record<string, T> = {};\n\n constructor() {\n this[immerable] = true;\n }\n\n public getNode(nodeId: string): T | undefined {\n return this._idToNode[nodeId];\n }\n\n public getChildOffset(\n parentId: string | undefined,\n childId: string\n ): number | undefined {\n const children = this.getChildren(parentId);\n if (!children) return undefined;\n\n return children.getIndex(childId);\n }\n\n public getChildren(\n parentId: string | undefined,\n createIfNotExist: boolean = false\n ): SparseArray<string> | undefined {\n if (parentId === undefined) {\n return this._rootNodes;\n }\n\n if (this._parentToChildren[parentId] === undefined && createIfNotExist) {\n this._parentToChildren[parentId] = new SparseArray<string>();\n }\n\n return this._parentToChildren[parentId];\n }\n\n public setChildren(\n parentId: string | undefined,\n children: T[],\n offset: number\n ) {\n const existingChildren = this.getChildren(parentId, true)!;\n children.forEach((child, index) => {\n const existingChildId = existingChildren.get(offset + index);\n if (existingChildId !== undefined) {\n this.deleteSubtree(existingChildId);\n }\n\n existingChildren.set(offset + index, child.id);\n this._idToNode[child.id] = child;\n });\n }\n\n public insertChild(parentId: string | undefined, child: T, offset: number) {\n const existingChildren = this.getChildren(parentId, true)!;\n existingChildren.insert(offset, child.id);\n this._idToNode[child.id] = child;\n }\n\n public setNodeId(\n parentId: string | undefined,\n index: number,\n newId: string\n ): boolean {\n const previousNodeId = this.getChildren(parentId)?.get(index);\n if (previousNodeId === undefined) {\n return false;\n }\n\n if (previousNodeId === newId) {\n return true;\n }\n\n if (this.getNode(newId) !== undefined) {\n return false;\n }\n\n this._idToNode[newId] = this._idToNode[previousNodeId];\n delete this._idToNode[previousNodeId];\n\n this._parentToChildren[newId] = this._parentToChildren[previousNodeId];\n delete this._parentToChildren[previousNodeId];\n\n if (parentId === undefined) {\n this._rootNodes.set(index, newId);\n } else {\n this._parentToChildren[parentId].set(index, newId);\n }\n\n return true;\n }\n\n public moveNode(\n sourceParentId: string | undefined,\n sourceNodeId: string,\n targetParentId: string | undefined,\n targetIndex: number\n ): void {\n const sourceNodeSiblings = this.getChildren(sourceParentId);\n assert(sourceNodeSiblings !== undefined);\n\n const sourceIndex = this.getChildOffset(sourceParentId, sourceNodeId);\n assert(sourceIndex !== undefined);\n\n sourceNodeSiblings.remove(sourceIndex);\n if (targetParentId === sourceParentId && targetIndex > sourceIndex) {\n targetIndex -= 1;\n }\n\n const targetNodeSiblings = this.getChildren(targetParentId, true);\n assert(targetNodeSiblings !== undefined);\n targetNodeSiblings.insert(targetIndex, sourceNodeId);\n }\n\n public setNumChildren(parentId: string | undefined, numChildren: number) {\n const children = this.getChildren(parentId, true)!;\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n\n children.setLength(numChildren);\n }\n\n public removeChild(\n parentId: string | undefined,\n child: string | number\n ): void {\n const children = this.getChildren(parentId);\n if (children === undefined) return;\n\n if (typeof child === \"string\") {\n const childIndex = children.getIndex(child);\n if (childIndex !== undefined) {\n children.remove(childIndex);\n }\n\n this.deleteSubtree(child);\n } else {\n const childId = children.get(child);\n children.remove(child);\n if (childId !== undefined) {\n this.deleteSubtree(childId);\n }\n }\n }\n\n public deleteSubtree(\n parentId: string | undefined,\n deleteParent: boolean = true\n ) {\n const children = this.getChildren(parentId);\n if (children !== undefined) {\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n }\n\n if (parentId === undefined) {\n this._rootNodes.setLength(0);\n return;\n }\n if (deleteParent) {\n delete this._idToNode[parentId];\n }\n delete this._parentToChildren[parentId];\n }\n}\n\n/**\n * Structure for sparse array value storage.\n * The main advantage of this class over the standard javascript array is that\n * this class does not need to check each index when iterating values that are\n * stored in the array.\n * @public\n */\nexport class SparseArray<T> implements Iterable<T | undefined> {\n public [immerable]: boolean;\n\n private _length = 0;\n private _array: Array<[T, number]> = [];\n\n constructor() {\n this[immerable] = true;\n }\n\n /** Returns length of array including intermediate 'undefined' values */\n public getLength(): number {\n return this._length;\n }\n\n /** Sets length of array. */\n public setLength(length: number) {\n const { index } = this.lowerBound(length);\n this._array.length = index;\n this._length = length;\n }\n\n /** Returns index of supplied value.\n *\n * @returns index of value or undefined if value is not found.\n */\n public getIndex(lookupValue: T): number | undefined {\n for (const [value, index] of this._array) {\n if (value === lookupValue) return index;\n }\n return undefined;\n }\n\n /** Returns value at specific position.\n *\n * @returns stored value or undefined.\n */\n public get(index: number): T | undefined {\n const { index: i, equal } = this.lowerBound(index);\n return equal ? this._array[i][0] : undefined;\n }\n\n /** Sets value at specific position. Overrides any existing value. */\n public set(index: number, value: T) {\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0, [value, index]);\n this._length = Math.max(this._length, index + 1);\n }\n\n /** Inserts value at specific position. Increases array length by one. */\n public insert(index: number, value: T) {\n const { index: i } = this.lowerBound(index);\n this._array.splice(i, 0, [value, index]);\n\n for (let j = i + 1; j < this._array.length; j++) {\n this._array[j][1]++;\n }\n\n this._length = Math.max(this._length + 1, index + 1);\n }\n\n /** Removes value at specified index and reduces array length by one. */\n public remove(index: number): void {\n if (index >= this._length) {\n return;\n }\n\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0);\n\n for (let j = i; j < this._array.length; j++) {\n this._array[j][1]--;\n }\n\n this._length = Math.max(0, this._length - 1);\n }\n\n /**\n * Iterates values that are stored in the array\n * @returns `[value, index]` tuples.\n */\n public iterateValues(): IterableIterator<[T, number]> {\n return this._array[Symbol.iterator]();\n }\n\n /** Iterates the array with all intermediate `undefined` values */\n public [Symbol.iterator](): IterableIterator<T | undefined> {\n const array = this._array;\n const length = this._length;\n return (function* () {\n let currentIndex = 0;\n for (const [value, index] of array) {\n for (; currentIndex < index; ++currentIndex) {\n yield undefined;\n }\n\n yield value;\n ++currentIndex;\n }\n\n for (; currentIndex < length; ++currentIndex) {\n yield undefined;\n }\n })();\n }\n\n private lowerBound(index: number): {\n index: number;\n equal: boolean;\n } {\n return lowerBound(index, this._array, SparseArray.compare);\n }\n\n private static compare<T>(index: number, value: [T, number]): number {\n return compareNumbers(index, value[1]);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SparseTree.js","sourceRoot":"","sources":["../../../../../../src/components-react/tree/controlled/internal/SparseTree.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,iCAAkC;AAClC,sDAAyE;AAOzE;;;;;GAKG;AACH,MAAa,UAAU;IAOrB;QAJQ,eAAU,GAAG,IAAI,WAAW,EAAU,CAAC;QACvC,sBAAiB,GAAwC,EAAE,CAAC;QAC5D,cAAS,GAAsB,EAAE,CAAC;QAGxC,IAAI,CAAC,iBAAS,CAAC,GAAG,IAAI,CAAC;IACzB,CAAC;IAEM,OAAO,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAEM,cAAc,CACnB,QAA4B,EAC5B,OAAe;QAEf,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ;YAAE,OAAO,SAAS,CAAC;QAEh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AK,EAAE,KAAK,CAAC,IAAI,KAAK,EAAE;gBAClC,OAAO,YAAY,GAAG,KAAK,EAAE,EAAE,YAAY,EAAE;oBAC3C,MAAM,SAAS,CAAC;iBACjB;gBAED,MAAM,KAAK,CAAC;gBACZ,EAAE,YAAY,CAAC;aAChB;YAED,OAAO,YAAY,GAAG,MAAM,EAAE,EAAE,YAAY,EAAE;gBAC5C,MAAM,SAAS,CAAC;aACjB;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;IAEO,UAAU,CAAC,KAAa;QAI9B,OAAO,IAAA,yBAAU,EAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;IAEO,MAAM,CAAC,OAAO,CAAI,KAAa,EAAE,KAAkB;QACzD,OAAO,IAAA,6BAAc,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AApHD,kCAoHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tree\n */\n\nimport { immerable } from \"immer\";\nimport { assert, compareNumbers, lowerBound } from \"@itwin/core-bentley\";\n\n/** @internal */\nexport interface Node {\n readonly id: string;\n}\n\n/**\n * Structure for sparse tree storage.\n * It uses SparseArray to store children ids for parent. This allows\n * having tree structure with some nodes missing in the tree branch.\n * @internal\n */\nexport class SparseTree<T extends Node> {\n public [immerable]: boolean;\n\n private _rootNodes = new SparseArray<string>();\n private _parentToChildren: Record<string, SparseArray<string>> = {};\n private _idToNode: Record<string, T> = {};\n\n constructor() {\n this[immerable] = true;\n }\n\n public getNode(nodeId: string): T | undefined {\n return this._idToNode[nodeId];\n }\n\n public getChildOffset(\n parentId: string | undefined,\n childId: string\n ): number | undefined {\n const children = this.getChildren(parentId);\n if (!children) return undefined;\n\n return children.getIndex(childId);\n }\n\n public getChildren(\n parentId: string | undefined,\n createIfNotExist: boolean = false\n ): SparseArray<string> | undefined {\n if (parentId === undefined) {\n return this._rootNodes;\n }\n\n if (this._parentToChildren[parentId] === undefined && createIfNotExist) {\n this._parentToChildren[parentId] = new SparseArray<string>();\n }\n\n return this._parentToChildren[parentId];\n }\n\n public setChildren(\n parentId: string | undefined,\n children: T[],\n offset: number\n ) {\n const existingChildren = this.getChildren(parentId, true)!;\n children.forEach((child, index) => {\n const existingChildId = existingChildren.get(offset + index);\n if (existingChildId !== undefined) {\n this.deleteSubtree(existingChildId);\n }\n\n existingChildren.set(offset + index, child.id);\n this._idToNode[child.id] = child;\n });\n }\n\n public insertChild(parentId: string | undefined, child: T, offset: number) {\n const existingChildren = this.getChildren(parentId, true)!;\n existingChildren.insert(offset, child.id);\n this._idToNode[child.id] = child;\n }\n\n public setNodeId(\n parentId: string | undefined,\n index: number,\n newId: string\n ): boolean {\n const previousNodeId = this.getChildren(parentId)?.get(index);\n if (previousNodeId === undefined) {\n return false;\n }\n\n if (previousNodeId === newId) {\n return true;\n }\n\n if (this.getNode(newId) !== undefined) {\n return false;\n }\n\n this._idToNode[newId] = this._idToNode[previousNodeId];\n delete this._idToNode[previousNodeId];\n\n this._parentToChildren[newId] = this._parentToChildren[previousNodeId];\n delete this._parentToChildren[previousNodeId];\n\n if (parentId === undefined) {\n this._rootNodes.set(index, newId);\n } else {\n this._parentToChildren[parentId].set(index, newId);\n }\n\n return true;\n }\n\n public moveNode(\n sourceParentId: string | undefined,\n sourceNodeId: string,\n targetParentId: string | undefined,\n targetIndex: number\n ): void {\n const sourceNodeSiblings = this.getChildren(sourceParentId);\n assert(sourceNodeSiblings !== undefined);\n\n const sourceIndex = this.getChildOffset(sourceParentId, sourceNodeId);\n assert(sourceIndex !== undefined);\n\n sourceNodeSiblings.remove(sourceIndex);\n if (targetParentId === sourceParentId && targetIndex > sourceIndex) {\n targetIndex -= 1;\n }\n\n const targetNodeSiblings = this.getChildren(targetParentId, true);\n assert(targetNodeSiblings !== undefined);\n targetNodeSiblings.insert(targetIndex, sourceNodeId);\n }\n\n public setNumChildren(parentId: string | undefined, numChildren: number) {\n const children = this.getChildren(parentId, true)!;\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n\n children.setLength(numChildren);\n }\n\n public removeChild(\n parentId: string | undefined,\n child: string | number\n ): void {\n const children = this.getChildren(parentId);\n if (children === undefined) return;\n\n if (typeof child === \"string\") {\n const childIndex = children.getIndex(child);\n if (childIndex !== undefined) {\n children.remove(childIndex);\n }\n\n this.deleteSubtree(child);\n } else {\n const childId = children.get(child);\n children.remove(child);\n if (childId !== undefined) {\n this.deleteSubtree(childId);\n }\n }\n }\n\n public deleteSubtree(\n parentId: string | undefined,\n deleteParent: boolean = true\n ) {\n const children = this.getChildren(parentId);\n if (children !== undefined) {\n for (const [childId] of children.iterateValues()) {\n this.deleteSubtree(childId);\n }\n }\n\n if (parentId === undefined) {\n this._rootNodes.setLength(0);\n return;\n }\n if (deleteParent) {\n delete this._idToNode[parentId];\n }\n delete this._parentToChildren[parentId];\n }\n}\n\n/**\n * Structure for sparse array value storage.\n * The main advantage of this class over the standard javascript array is that\n * this class does not need to check each index when iterating values that are\n * stored in the array.\n * @public\n */\nexport class SparseArray<T> implements Iterable<T | undefined> {\n public [immerable]: boolean;\n\n private _length = 0;\n private _array: Array<[T, number]> = [];\n\n constructor() {\n this[immerable] = true;\n }\n\n /** Returns length of array including intermediate 'undefined' values */\n public getLength(): number {\n return this._length;\n }\n\n /** Sets length of array. */\n public setLength(length: number) {\n const { index } = this.lowerBound(length);\n this._array.length = index;\n this._length = length;\n }\n\n /** Returns index of supplied value.\n *\n * @returns index of value or undefined if value is not found.\n */\n public getIndex(lookupValue: T): number | undefined {\n for (const [value, index] of this._array) {\n if (value === lookupValue) return index;\n }\n return undefined;\n }\n\n /** Returns value at specific position.\n *\n * @returns stored value or undefined.\n */\n public get(index: number): T | undefined {\n const { index: i, equal } = this.lowerBound(index);\n return equal ? this._array[i][0] : undefined;\n }\n\n /** Sets value at specific position. Overrides any existing value. */\n public set(index: number, value: T) {\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0, [value, index]);\n this._length = Math.max(this._length, index + 1);\n }\n\n /** Inserts value at specific position. Increases array length by one. */\n public insert(index: number, value: T) {\n const { index: i } = this.lowerBound(index);\n this._array.splice(i, 0, [value, index]);\n\n for (let j = i + 1; j < this._array.length; j++) {\n this._array[j][1]++;\n }\n\n this._length = Math.max(this._length + 1, index + 1);\n }\n\n /** Removes value at specified index and reduces array length by one. */\n public remove(index: number): void {\n if (index >= this._length) {\n return;\n }\n\n const { index: i, equal } = this.lowerBound(index);\n this._array.splice(i, equal ? 1 : 0);\n\n for (let j = i; j < this._array.length; j++) {\n this._array[j][1]--;\n }\n\n this._length = Math.max(0, this._length - 1);\n }\n\n /**\n * Iterates values that are stored in the array\n * @returns `[value, index]` tuples.\n */\n public iterateValues(): IterableIterator<[T, number]> {\n return this._array[Symbol.iterator]();\n }\n\n /** Iterates the array with all intermediate `undefined` values */\n public [Symbol.iterator](): IterableIterator<T | undefined> {\n const array = this._array;\n const length = this._length;\n return (function* () {\n let currentIndex = 0;\n for (const [value, index] of array) {\n for (; currentIndex < index; ++currentIndex) {\n yield undefined;\n }\n\n yield value;\n ++currentIndex;\n }\n\n for (; currentIndex < length; ++currentIndex) {\n yield undefined;\n }\n })();\n }\n\n private lowerBound(index: number): {\n index: number;\n equal: boolean;\n } {\n return lowerBound(index, this._array, SparseArray.compare);\n }\n\n private static compare<T>(index: number, value: [T, number]): number {\n return compareNumbers(index, value[1]);\n }\n}\n"]}
|
|
@@ -215,11 +215,13 @@ class ItemHandler {
|
|
|
215
215
|
deselect() { }
|
|
216
216
|
// eslint-disable-next-line @itwin/prefer-get
|
|
217
217
|
isSelected() {
|
|
218
|
+
var _a;
|
|
218
219
|
// istanbul ignore next
|
|
219
|
-
return !!this._node
|
|
220
|
+
return !!((_a = this._node) === null || _a === void 0 ? void 0 : _a.isSelected);
|
|
220
221
|
}
|
|
221
222
|
item() {
|
|
222
|
-
|
|
223
|
+
var _a, _b;
|
|
224
|
+
return (_b = (_a = this._node) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : "";
|
|
223
225
|
}
|
|
224
226
|
}
|
|
225
227
|
//# sourceMappingURL=TreeSelectionManager.js.map
|