@itwin/saved-views-react 0.6.0 → 0.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/README.md +5 -20
- package/lib/SavedView.d.ts +20 -12
- package/lib/SavedViewTile/SavedViewOptions.js +10 -10
- package/lib/SavedViewTile/SavedViewTile.css +8 -1
- package/lib/SavedViewTile/SavedViewTile.d.ts +4 -3
- package/lib/SavedViewTile/SavedViewTile.js +4 -8
- package/lib/SavedViewTile/SavedViewTileContext.d.ts +0 -1
- package/lib/SavedViewTile/SavedViewTileContext.js +1 -1
- package/lib/SavedViewsClient/ITwinSavedViewsClient.d.ts +20 -22
- package/lib/SavedViewsClient/ITwinSavedViewsClient.js +79 -42
- package/lib/SavedViewsClient/SavedViewsClient.d.ts +55 -40
- package/lib/SavedViewsWidget/SavedViewGroupTile/SavedViewGroupTile.js +2 -3
- package/lib/SavedViewsWidget/SavedViewGroupTile/SavedViewGroupTileContext.d.ts +0 -1
- package/lib/SavedViewsWidget/SavedViewGroupTile/SavedViewGroupTileContext.js +1 -1
- package/lib/SavedViewsWidget/SavedViewsExpandableBlockWidget.d.ts +5 -3
- package/lib/SavedViewsWidget/SavedViewsExpandableBlockWidget.js +3 -3
- package/lib/SavedViewsWidget/SavedViewsFolderWidget.d.ts +5 -4
- package/lib/SavedViewsWidget/SavedViewsFolderWidget.js +7 -7
- package/lib/applySavedView.d.ts +33 -31
- package/lib/applySavedView.js +58 -23
- package/lib/captureSavedViewData.d.ts +12 -16
- package/lib/captureSavedViewData.js +76 -62
- package/lib/captureSavedViewThumbnail.d.ts +1 -1
- package/lib/captureSavedViewThumbnail.js +8 -7
- package/lib/createViewState.d.ts +8 -7
- package/lib/createViewState.js +16 -24
- package/lib/index.d.ts +10 -10
- package/lib/index.js +7 -7
- package/lib/translation/SavedViewTypes.d.ts +1 -1
- package/lib/translation/clipVectorsLegacyExtractor.js +4 -0
- package/lib/translation/displayStyleExtractor.js +8 -3
- package/lib/translation/extractionUtilities.d.ts +9 -1
- package/lib/translation/extractionUtilities.js +16 -0
- package/lib/useSavedViews.d.ts +171 -38
- package/lib/useSavedViews.js +373 -492
- package/lib/utils.d.ts +8 -1
- package/lib/utils.js +13 -0
- package/package.json +28 -21
package/lib/useSavedViews.d.ts
CHANGED
|
@@ -1,58 +1,191 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type ReactNode, type SetStateAction } from "react";
|
|
2
|
+
import type { SavedView, SavedViewData, SavedViewGroup, SavedViewTag, WriteableSavedViewProperties } from "./SavedView.js";
|
|
2
3
|
import type { SavedViewsClient } from "./SavedViewsClient/SavedViewsClient.js";
|
|
3
|
-
import type
|
|
4
|
-
|
|
4
|
+
import { type AllOrNone } from "./utils.js";
|
|
5
|
+
type UseSavedViewsArgs = {
|
|
5
6
|
/** iTwin identifier. */
|
|
6
7
|
iTwinId: string;
|
|
7
8
|
/** iModel identifier. */
|
|
8
9
|
iModelId: string;
|
|
9
10
|
/** Implements communication with Saved Views store. */
|
|
10
11
|
client: SavedViewsClient;
|
|
12
|
+
} & AllOrNone<ExternalState>;
|
|
13
|
+
interface ExternalState {
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
13
|
-
* {@linkcode
|
|
15
|
+
* Current immutable value of Saved Views store. If provided, it is returned as
|
|
16
|
+
* {@linkcode UseSavedViewsResult.store}; otherwise an internal store is used.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const [state, setState] = useState(useSavedViews.emptyState);
|
|
20
|
+
* const { store } = useSavedViews({ iTwinId, iModelId, client, state, setState });
|
|
21
|
+
* console.log(store === state); // true
|
|
14
22
|
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
state: SavedViewsState;
|
|
24
|
+
/**
|
|
25
|
+
* Function which updates Saved Views store. It should behave the same as `setState` callback
|
|
26
|
+
* that is returned by `React.useState`.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* When hook arguments change, the state is not cleared automatically.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const [state, setState] = useState(useSavedViews.emptyState);
|
|
33
|
+
* const savedViews = useSavedViews({ iTwinId, iModelId, client, state, setState });
|
|
34
|
+
*/
|
|
35
|
+
setState: (action: SetStateAction<SavedViewsState>) => void;
|
|
20
36
|
}
|
|
21
|
-
interface
|
|
37
|
+
export interface SavedViewsState {
|
|
38
|
+
/** Maps `savedViewId` to {@link SavedView}. */
|
|
22
39
|
savedViews: Map<string, SavedView>;
|
|
40
|
+
/** Maps `savedViewId` to {@link SavedViewData}. */
|
|
41
|
+
savedViewData: Map<string, SavedViewData>;
|
|
42
|
+
/** Maps `groupId` to {@link SavedViewGroup}. */
|
|
23
43
|
groups: Map<string, SavedViewGroup>;
|
|
44
|
+
/** Maps `tagId` to {@link SavedViewTag}. */
|
|
24
45
|
tags: Map<string, SavedViewTag>;
|
|
25
|
-
|
|
46
|
+
/** Maps `savedViewId` to {@link ReactNode} representing Saved View thumbnail. */
|
|
47
|
+
thumbnails: Map<string, ReactNode>;
|
|
26
48
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
interface UseSavedViewsResult extends SavedViewsActions {
|
|
50
|
+
/**
|
|
51
|
+
* Immutable state which holds Saved Views data. If {@linkcode UseSavedViewsArgs.state} is not
|
|
52
|
+
* specified, an internal state is returned; otherwise its value is the same as the provided
|
|
53
|
+
* `state` argument.
|
|
54
|
+
*/
|
|
55
|
+
store: SavedViewsState;
|
|
56
|
+
/**
|
|
57
|
+
* When invoked, {@link SavedViewsClient} is queried for all available Saved Views, Groups, and
|
|
58
|
+
* Tags. When the operation ends, all obtained entities are inserted into Saved Views store.
|
|
59
|
+
*
|
|
60
|
+
* @param callback Optional callback that is invoked when the operation ends. If an error occurs,
|
|
61
|
+
* the operation gets cancelled and the error object is passed as the argument.
|
|
62
|
+
* @returns Callback that cancels the operation.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const { startLoadingData } = useSavedViews({ iTwinId, iModelId, client });
|
|
66
|
+
* const [isLoading, setIsLoading] = useState(true);
|
|
67
|
+
* useEffect(
|
|
68
|
+
* () => {
|
|
69
|
+
* return startLoadingData((error) => {
|
|
70
|
+
* setIsLoading(false);
|
|
71
|
+
* if (error) {
|
|
72
|
+
* console.error(error);
|
|
73
|
+
* }
|
|
74
|
+
* });
|
|
75
|
+
* },
|
|
76
|
+
* [],
|
|
77
|
+
* );
|
|
78
|
+
*/
|
|
79
|
+
startLoadingData: (callback?: (error?: unknown) => void) => () => void;
|
|
80
|
+
}
|
|
81
|
+
export interface SavedViewsActions {
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new {@link SavedView} entity using {@link SavedViewsClient} and stores the result in
|
|
84
|
+
* Saved Views store.
|
|
85
|
+
* @returns Identifier of the newly created Saved View.
|
|
86
|
+
*/
|
|
87
|
+
createSavedView: (savedView: WriteableSavedViewProperties, savedViewData: SavedViewData) => Promise<string>;
|
|
88
|
+
/**
|
|
89
|
+
* Retrieves {@link SavedViewData} associated with given {@linkcode savedViewId} from the Saved
|
|
90
|
+
* Views store if the data is present; otherwise it is queried from {@link SavedViewsClient} and the
|
|
91
|
+
* store is updated to include the new data.
|
|
92
|
+
*/
|
|
93
|
+
lookupSavedViewData: (savedViewId: string) => Promise<SavedViewData>;
|
|
94
|
+
/**
|
|
95
|
+
* Uses {@link SavedViewsClient} to update {@link SavedView} entity. On success, updates
|
|
96
|
+
* {@link SavedView} in Saved Views store with provided values.
|
|
97
|
+
*/
|
|
98
|
+
updateSavedView: (savedViewId: string, savedView: Partial<WriteableSavedViewProperties>, savedViewData?: SavedViewData | undefined) => Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Uses {@link SavedViewsClient} to update {@link SavedView} entity associated with given {@linkcode savedViewId}.
|
|
101
|
+
* On success, updates {@link SavedView} in Saved Views store with provided name.
|
|
102
|
+
*/
|
|
103
|
+
renameSavedView: (savedViewId: string, newName: string) => Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Uses {@link SavedViewsClient} to mark {@link SavedView} entity as shared or unshared. On
|
|
106
|
+
* success, updates {@link SavedView} in Saved Views store with provided status.
|
|
107
|
+
*/
|
|
108
|
+
shareSavedView: (savedViewId: string, shared: boolean) => Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Uses {@link SavedViewsClient} to delete {@link SavedView} entity. On success, removes
|
|
111
|
+
* {@link SavedView} from Saved Views store.
|
|
112
|
+
*/
|
|
113
|
+
deleteSavedView: (savedViewId: string) => Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new {@link SavedViewGroup} entity using {@link SavedViewsClient} and stores the
|
|
116
|
+
* result in Saved Views store.
|
|
117
|
+
* @returns Identifier of the newly created Saved View Group.
|
|
118
|
+
*/
|
|
119
|
+
createGroup: (groupName: string) => Promise<string>;
|
|
120
|
+
/**
|
|
121
|
+
* Uses {@link SavedViewsClient} to update {@link SavedViewGroup} entity. On success, updates
|
|
122
|
+
* {@link SavedViewGroup} in Saved Views store with provided name.
|
|
123
|
+
*/
|
|
124
|
+
renameGroup: (groupId: string, newName: string) => Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Uses {@link SavedViewsClient} to mark {@link SavedViewGroup} entity as shared or unshared. On
|
|
127
|
+
* success, updates {@link SavedViewGroup} in Saved Views store with provided status.
|
|
128
|
+
*/
|
|
129
|
+
shareGroup: (groupId: string, shared: boolean) => Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Uses {@link SavedViewsClient} to move {@link SavedView} entity to the specified Saved View group.
|
|
132
|
+
*/
|
|
133
|
+
moveToGroup: (savedViewId: string, groupId: string | undefined) => Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Uses {@link SavedViewsClient} to delete {@link SavedViewGroup} entity. On success, removes
|
|
136
|
+
* {@link SavedViewGroup} from Saved Views store.
|
|
137
|
+
*/
|
|
138
|
+
deleteGroup: (groupId: string) => Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Creates a new {@link SavedViewTag} entity using {@link SavedViewsClient} and stores the result
|
|
141
|
+
* in Saved Views store.
|
|
142
|
+
* @returns Identifier of the newly created Saved View Tag.
|
|
143
|
+
*/
|
|
144
|
+
createTag: (tagName: string) => Promise<string>;
|
|
145
|
+
/** Uses {@link SavedViewsClient} to add {@link SavedViewTag} to {@link SavedView} entity. */
|
|
146
|
+
addTag: (savedViewId: string, tagId: string) => Promise<void>;
|
|
147
|
+
/** Uses {@link SavedViewsClient} to remove {@link SavedViewTag} from {@link SavedView} entity. */
|
|
148
|
+
removeTag: (savedViewId: string, tagId: string) => Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Uses {@link SavedViewsClient} to delete {@link SavedViewTag} entity. On success, removes
|
|
151
|
+
* {@link SavedViewTag} from Saved Views store.
|
|
152
|
+
*/
|
|
153
|
+
deleteTag: (tagId: string) => Promise<void>;
|
|
154
|
+
/** Uses {@link SavedViewsClient} to change thumbnail image for {@link SavedView} entity. */
|
|
155
|
+
uploadThumbnail: (savedViewId: string, imageDataUrl: string) => Promise<void>;
|
|
42
156
|
}
|
|
43
|
-
type SavedViewCreationProps = PartialExcept<WriteableSavedViewProperties, "displayName" | "viewData">;
|
|
44
|
-
type SavedViewUpdateProps = WriteableSavedViewProperties & {
|
|
45
|
-
id: string;
|
|
46
|
-
};
|
|
47
157
|
/**
|
|
48
|
-
*
|
|
49
|
-
* the store is performed via {@linkcode SavedViewsClient} interface which could communicate, for instance, with
|
|
50
|
-
* [iTwin Saved Views API](https://developer.bentley.com/apis/savedviews/overview/) using `ITwinSavedViewsClient`.
|
|
158
|
+
* Provides basic functionality to help get started with Saved Views.
|
|
51
159
|
*
|
|
52
160
|
* @remarks
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
161
|
+
* When hook arguments change, it does not automatically clear the {@linkcode UseSavedViewsResult.store}.
|
|
162
|
+
* If you want more control over the state, provide an external store via {@linkcode UseSavedViewsArgs.state}
|
|
163
|
+
* and {@linkcode UseSavedViewsArgs.setState} arguments.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* const { iTwinId, iModelId, client, viewport } = props;
|
|
167
|
+
* const savedViews = useSavedViews({ iTwinId, iModelId, client });
|
|
168
|
+
* const [isLoading, setIsLoading] = useState(true);
|
|
169
|
+
* useEffect(
|
|
170
|
+
* () => {
|
|
171
|
+
* return savedViews.startLoadingData(() => { setIsLoading(false); });
|
|
172
|
+
* },
|
|
173
|
+
* [],
|
|
174
|
+
* );
|
|
175
|
+
*
|
|
176
|
+
* if (isLoading) {
|
|
177
|
+
* return <MyLoadingState />;
|
|
178
|
+
* }
|
|
179
|
+
*
|
|
180
|
+
* const handleOpenSavedView = async (savedViewId) => {
|
|
181
|
+
* const savedViewData = await savedViews.lookupSavedViewData(savedViewId);
|
|
182
|
+
* await applySavedView(iModel, viewport, savedViewData);
|
|
183
|
+
* };
|
|
184
|
+
*
|
|
185
|
+
* return <MySavedViewsWidget savedViews={savedViews} onOpenSavedView={handleOpenSavedView} />;
|
|
56
186
|
*/
|
|
57
|
-
export declare
|
|
187
|
+
export declare const useSavedViews: ((args: UseSavedViewsArgs) => UseSavedViewsResult) & {
|
|
188
|
+
/** Suggested initial state of custom Saved View stores. Immutable. */
|
|
189
|
+
emptyState: SavedViewsState;
|
|
190
|
+
};
|
|
58
191
|
export {};
|