@veltdev/types-dev 5.0.2-beta.67 → 5.0.2-beta.68
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.
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { SuggestionEventTypes } from '../../utils/enums';
|
|
2
|
+
import { ApprovedSuggestion, PendingSuggestion, RejectedSuggestion, StaleSuggestion, TargetEditCommitBuilder, TargetEditDetails } from './suggestion.data.model';
|
|
3
|
+
/**
|
|
4
|
+
* Public payload types for the v1 Suggestions feature. Mirrors the layout of
|
|
5
|
+
* `comment-events.data.model.ts` and `recorder-events.data.model.ts`:
|
|
6
|
+
*
|
|
7
|
+
* - One named interface per event payload.
|
|
8
|
+
* - One `SuggestionEventTypesMap` keyed by `SuggestionEventTypes` enum values.
|
|
9
|
+
*
|
|
10
|
+
* Customers pass an event-name string (or the enum constant — they're
|
|
11
|
+
* equivalent) to `velt.getSuggestionElement().on(...)` and receive an
|
|
12
|
+
* `Observable<SuggestionEventTypesMap[T]>`.
|
|
13
|
+
*
|
|
14
|
+
* No separate `actor`/`user` field on the payloads: the user info is on
|
|
15
|
+
* `suggestion.createdBy` (for created) and `suggestion.resolvedBy` (for
|
|
16
|
+
* approved/rejected/stale). Matches the comment-event shape.
|
|
17
|
+
*/
|
|
18
|
+
export interface SuggestionCreatedEvent {
|
|
19
|
+
suggestion: PendingSuggestion;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
}
|
|
22
|
+
export interface SuggestionApprovedEvent {
|
|
23
|
+
suggestion: ApprovedSuggestion;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}
|
|
26
|
+
export interface SuggestionRejectedEvent {
|
|
27
|
+
suggestion: RejectedSuggestion;
|
|
28
|
+
timestamp: number;
|
|
29
|
+
}
|
|
30
|
+
export interface SuggestionStaleEvent {
|
|
31
|
+
suggestion: StaleSuggestion;
|
|
32
|
+
timestamp: number;
|
|
33
|
+
}
|
|
34
|
+
export interface TargetEditStartEvent {
|
|
35
|
+
details: TargetEditDetails;
|
|
36
|
+
timestamp: number;
|
|
37
|
+
}
|
|
38
|
+
export interface TargetEditCommitEvent {
|
|
39
|
+
details: TargetEditDetails;
|
|
40
|
+
/**
|
|
41
|
+
* Pre-bound builder. Calling it commits the suggestion using the SDK's
|
|
42
|
+
* default summary/metadata, optionally overridden by `result`. If the
|
|
43
|
+
* customer's `onTargetEditCommit` handler already returned a non-null
|
|
44
|
+
* result for this edit, this builder is a no-op so subscribers can't
|
|
45
|
+
* double-commit.
|
|
46
|
+
*/
|
|
47
|
+
commitSuggestion: TargetEditCommitBuilder;
|
|
48
|
+
timestamp: number;
|
|
49
|
+
}
|
|
50
|
+
export type SuggestionEventTypesMap = {
|
|
51
|
+
[SuggestionEventTypes.SUGGESTION_CREATED]: SuggestionCreatedEvent;
|
|
52
|
+
[SuggestionEventTypes.SUGGESTION_APPROVED]: SuggestionApprovedEvent;
|
|
53
|
+
[SuggestionEventTypes.SUGGESTION_REJECTED]: SuggestionRejectedEvent;
|
|
54
|
+
[SuggestionEventTypes.SUGGESTION_STALE]: SuggestionStaleEvent;
|
|
55
|
+
[SuggestionEventTypes.TARGET_EDIT_START]: TargetEditStartEvent;
|
|
56
|
+
[SuggestionEventTypes.TARGET_EDIT_COMMIT]: TargetEditCommitEvent;
|
|
57
|
+
};
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* with these via Snippyly.getSuggestionElement(); the SDK constructs all
|
|
9
9
|
* Suggestion objects internally and customers do not build them directly.
|
|
10
10
|
*/
|
|
11
|
+
import { User } from './user.data.model';
|
|
11
12
|
/**
|
|
12
13
|
* Lifecycle state machine for a Suggestion.
|
|
13
14
|
*
|
|
@@ -32,7 +33,16 @@ export type SuggestionMode = 'editing' | 'suggesting';
|
|
|
32
33
|
*/
|
|
33
34
|
export type SuggestionTargetType = 'custom';
|
|
34
35
|
/**
|
|
35
|
-
*
|
|
36
|
+
* Single-arg config passed to `SuggestionElement.registerTarget(config)`.
|
|
37
|
+
* Carrying both `targetId` and `getter` in one object so the API can grow
|
|
38
|
+
* (e.g., metadata, target-specific options) without breaking customers.
|
|
39
|
+
*/
|
|
40
|
+
export interface RegisterTargetConfig<T = unknown> {
|
|
41
|
+
targetId: string;
|
|
42
|
+
getter: TargetGetter<T>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Function the customer registers via SuggestionElement.registerTarget(config).
|
|
36
46
|
* Required for any non-primitive (wrapper) target.
|
|
37
47
|
*
|
|
38
48
|
* The SDK calls this getter twice in a typical edit cycle:
|
|
@@ -151,26 +161,23 @@ export interface SuggestionData {
|
|
|
151
161
|
driftDetected: boolean;
|
|
152
162
|
/** Populated only when status === 'rejected'. */
|
|
153
163
|
rejectReason: string | null;
|
|
154
|
-
/**
|
|
155
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Full User snapshot of the resolver, populated when status moves to
|
|
166
|
+
* approved | rejected | stale | apply_failed. Snapshot rather than userId
|
|
167
|
+
* so customer code can render name/email/photoUrl without an extra lookup,
|
|
168
|
+
* and so historical suggestions retain their resolver record even if the
|
|
169
|
+
* user later updates their profile.
|
|
170
|
+
*/
|
|
171
|
+
resolvedBy: User | null;
|
|
156
172
|
resolvedAt: number | null;
|
|
157
173
|
}
|
|
158
|
-
/**
|
|
159
|
-
* The actor (user) involved in a suggestion event. Sourced from the existing
|
|
160
|
-
* Velt identity layer.
|
|
161
|
-
*/
|
|
162
|
-
export interface SuggestionActor {
|
|
163
|
-
userId: string;
|
|
164
|
-
name?: string;
|
|
165
|
-
email?: string;
|
|
166
|
-
}
|
|
167
174
|
/**
|
|
168
175
|
* Fields shared across every Suggestion regardless of status.
|
|
169
176
|
* Internal — used to build the per-status discriminated types below.
|
|
170
177
|
*/
|
|
171
178
|
interface SuggestionBase<T = unknown> {
|
|
172
|
-
/** Annotation document id
|
|
173
|
-
|
|
179
|
+
/** Annotation document id (same as the underlying CommentAnnotation.annotationId). */
|
|
180
|
+
annotationId: string;
|
|
174
181
|
/** Stable, customer-owned target identifier. */
|
|
175
182
|
targetId: string;
|
|
176
183
|
/** v1: always 'custom'. */
|
|
@@ -185,8 +192,10 @@ interface SuggestionBase<T = unknown> {
|
|
|
185
192
|
metadata: Record<string, any>;
|
|
186
193
|
/** True iff the live value at approve time differed from oldValue. */
|
|
187
194
|
driftDetected: boolean;
|
|
188
|
-
/**
|
|
189
|
-
|
|
195
|
+
/**
|
|
196
|
+
* User of the suggestion's creator (sourced from annotation.from).
|
|
197
|
+
*/
|
|
198
|
+
createdBy?: User;
|
|
190
199
|
createdAt: number;
|
|
191
200
|
}
|
|
192
201
|
/** A suggestion in the 'pending' state — newly created, no owner action yet. */
|
|
@@ -200,21 +209,21 @@ export interface PendingSuggestion<T = unknown> extends SuggestionBase<T> {
|
|
|
200
209
|
export interface ApprovedSuggestion<T = unknown> extends SuggestionBase<T> {
|
|
201
210
|
status: 'approved' | 'apply_failed';
|
|
202
211
|
rejectReason: null;
|
|
203
|
-
resolvedBy:
|
|
212
|
+
resolvedBy: User;
|
|
204
213
|
resolvedAt: number;
|
|
205
214
|
}
|
|
206
215
|
/** A suggestion that has been rejected. rejectReason is non-null. */
|
|
207
216
|
export interface RejectedSuggestion<T = unknown> extends SuggestionBase<T> {
|
|
208
217
|
status: 'rejected';
|
|
209
218
|
rejectReason: string;
|
|
210
|
-
resolvedBy:
|
|
219
|
+
resolvedBy: User;
|
|
211
220
|
resolvedAt: number;
|
|
212
221
|
}
|
|
213
222
|
/** A suggestion whose target was unresolvable at approve time. */
|
|
214
223
|
export interface StaleSuggestion<T = unknown> extends SuggestionBase<T> {
|
|
215
224
|
status: 'stale';
|
|
216
225
|
rejectReason: null;
|
|
217
|
-
resolvedBy:
|
|
226
|
+
resolvedBy: User | null;
|
|
218
227
|
resolvedAt: number | null;
|
|
219
228
|
}
|
|
220
229
|
/**
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { SuggestionEventType } from "../../utils/enums";
|
|
4
|
+
import { SuggestionEventTypesMap } from "../data/suggestion-events.data.model";
|
|
5
|
+
import { CommitSuggestionConfig, EnableSuggestionModeConfig, RegisterTargetConfig, Suggestion, SuggestionGetSuggestionsFilter } from "../data/suggestion.data.model";
|
|
6
|
+
|
|
7
|
+
export declare class SuggestionElement {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Turn on suggestion mode for this user/session and (optionally) register
|
|
11
|
+
* the onTargetEditStart / onTargetEditCommit callbacks the SDK invokes
|
|
12
|
+
* during the auto-detect edit lifecycle.
|
|
13
|
+
*
|
|
14
|
+
* Re-calling with a new config replaces the previous callbacks.
|
|
15
|
+
*/
|
|
16
|
+
enableSuggestionMode: (config?: EnableSuggestionModeConfig) => void;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Turn off suggestion mode and clear any registered callbacks.
|
|
20
|
+
*/
|
|
21
|
+
disableSuggestionMode: () => void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Synchronous read of the current enable flag.
|
|
25
|
+
*/
|
|
26
|
+
isSuggestionModeEnabled: () => boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Reactive enable-flag stream; deduplicated.
|
|
30
|
+
*/
|
|
31
|
+
isSuggestionModeEnabled$: () => Observable<boolean>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Register a getter that returns the current value of a tagged target.
|
|
35
|
+
* Required for non-primitive (wrapper) targets — the SDK calls this on
|
|
36
|
+
* focus to snapshot the pre-edit value, and again on commit for the diff.
|
|
37
|
+
*
|
|
38
|
+
* The getter must reflect edit-time state (typically read from the DOM),
|
|
39
|
+
* not the persisted customer state. See `RegisterTargetConfig`.
|
|
40
|
+
*/
|
|
41
|
+
registerTarget: <T = unknown>(config: RegisterTargetConfig<T>) => void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Drop the registered getter for a target.
|
|
45
|
+
*/
|
|
46
|
+
unregisterTarget: (targetId: string) => void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Manually capture the current value as the snapshot for a target.
|
|
50
|
+
* Use for non-focusable elements (custom widgets, virtualized rows)
|
|
51
|
+
* where the auto-focus snapshot does not fire.
|
|
52
|
+
*/
|
|
53
|
+
startSuggestion: (targetId: string) => void;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Programmatically commit a suggestion. Resolves with the new annotation id.
|
|
57
|
+
* Rejects with one of: INVALID_CONFIG, MODE_NOT_SUGGESTING,
|
|
58
|
+
* TARGET_NOT_REGISTERED, NO_GETTER_FOR_COMPLEX, NO_CHANGE_TO_SUGGEST,
|
|
59
|
+
* SNAPSHOT_FAILED.
|
|
60
|
+
*/
|
|
61
|
+
commitSuggestion: <T = unknown>(config: CommitSuggestionConfig<T>) => Promise<{ id: string }>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Synchronous read of all suggestions on the current document, optionally filtered.
|
|
65
|
+
*/
|
|
66
|
+
getSuggestions: (filter?: SuggestionGetSuggestionsFilter) => Suggestion[];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Reactive variant of getSuggestions. Re-emits on every annotation change,
|
|
70
|
+
* deduplicated via the SDK's standard distinct-until-changed comparator.
|
|
71
|
+
*/
|
|
72
|
+
getSuggestions$: (filter?: SuggestionGetSuggestionsFilter) => Observable<Suggestion[]>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Newest pending suggestion for a target, or null. Convenience for
|
|
76
|
+
* pending-overlay UX patterns where each input shows the proposed
|
|
77
|
+
* value while a suggestion is awaiting resolution.
|
|
78
|
+
*/
|
|
79
|
+
getPendingSuggestion: <T = unknown>(targetId: string) => Suggestion<T> | null;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Reactive variant of getPendingSuggestion.
|
|
83
|
+
*/
|
|
84
|
+
getPendingSuggestion$: <T = unknown>(targetId: string) => Observable<Suggestion<T> | null>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Subscribe to a suggestion event. Customers call `.subscribe(handler)`
|
|
88
|
+
* on the returned Observable. Event names: 'suggestionCreated',
|
|
89
|
+
* 'suggestionApproved', 'suggestionRejected', 'suggestionStale',
|
|
90
|
+
* 'targetEditStart', 'targetEditCommit'.
|
|
91
|
+
*/
|
|
92
|
+
on: <T extends SuggestionEventType>(action: T) => Observable<SuggestionEventTypesMap[T]>;
|
|
93
|
+
|
|
94
|
+
constructor();
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Turn on suggestion mode for this user/session and (optionally) register
|
|
98
|
+
* the onTargetEditStart / onTargetEditCommit callbacks the SDK invokes
|
|
99
|
+
* during the auto-detect edit lifecycle.
|
|
100
|
+
*
|
|
101
|
+
* Re-calling with a new config replaces the previous callbacks.
|
|
102
|
+
*/
|
|
103
|
+
private _enableSuggestionMode;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Turn off suggestion mode and clear any registered callbacks.
|
|
107
|
+
*/
|
|
108
|
+
private _disableSuggestionMode;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Synchronous read of the current enable flag.
|
|
112
|
+
*/
|
|
113
|
+
private _isSuggestionModeEnabled;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Reactive enable-flag stream; deduplicated.
|
|
117
|
+
*/
|
|
118
|
+
private _isSuggestionModeEnabled$;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Register a getter that returns the current value of a tagged target.
|
|
122
|
+
* Required for non-primitive (wrapper) targets — the SDK calls this on
|
|
123
|
+
* focus to snapshot the pre-edit value, and again on commit for the diff.
|
|
124
|
+
*
|
|
125
|
+
* The getter must reflect edit-time state (typically read from the DOM),
|
|
126
|
+
* not the persisted customer state. See `RegisterTargetConfig`.
|
|
127
|
+
*/
|
|
128
|
+
private _registerTarget;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Drop the registered getter for a target.
|
|
132
|
+
*/
|
|
133
|
+
private _unregisterTarget;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Manually capture the current value as the snapshot for a target.
|
|
137
|
+
* Use for non-focusable elements (custom widgets, virtualized rows)
|
|
138
|
+
* where the auto-focus snapshot does not fire.
|
|
139
|
+
*/
|
|
140
|
+
private _startSuggestion;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Programmatically commit a suggestion. Resolves with the new annotation id.
|
|
144
|
+
* Rejects with one of: INVALID_CONFIG, MODE_NOT_SUGGESTING,
|
|
145
|
+
* TARGET_NOT_REGISTERED, NO_GETTER_FOR_COMPLEX, NO_CHANGE_TO_SUGGEST,
|
|
146
|
+
* SNAPSHOT_FAILED.
|
|
147
|
+
*/
|
|
148
|
+
private _commitSuggestion;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Synchronous read of all suggestions on the current document, optionally filtered.
|
|
152
|
+
*/
|
|
153
|
+
private _getSuggestions;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Reactive variant of getSuggestions. Re-emits on every annotation change,
|
|
157
|
+
* deduplicated via the SDK's standard distinct-until-changed comparator.
|
|
158
|
+
*/
|
|
159
|
+
private _getSuggestions$;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Newest pending suggestion for a target, or null. Convenience for
|
|
163
|
+
* pending-overlay UX patterns where each input shows the proposed
|
|
164
|
+
* value while a suggestion is awaiting resolution.
|
|
165
|
+
*/
|
|
166
|
+
private _getPendingSuggestion;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Reactive variant of getPendingSuggestion.
|
|
170
|
+
*/
|
|
171
|
+
private _getPendingSuggestion$;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Subscribe to a suggestion event. Customers call `.subscribe(handler)`
|
|
175
|
+
* on the returned Observable. Event names: 'suggestionCreated',
|
|
176
|
+
* 'suggestionApproved', 'suggestionRejected', 'suggestionStale',
|
|
177
|
+
* 'targetEditStart', 'targetEditCommit'.
|
|
178
|
+
*/
|
|
179
|
+
private _on;
|
|
180
|
+
}
|
package/models.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ export * from './app/models/data/recorder-annotation.data.model';
|
|
|
50
50
|
export * from './app/models/data/recorder-events.data.model';
|
|
51
51
|
export * from './app/models/data/rewriter-annotation.data.model';
|
|
52
52
|
export * from './app/models/data/rewriter-events.data.model';
|
|
53
|
+
export * from './app/models/data/suggestion.data.model';
|
|
54
|
+
export * from './app/models/data/suggestion-events.data.model';
|
|
53
55
|
export * from './app/models/data/screen-size.data.model';
|
|
54
56
|
export * from './app/models/data/screenshot.data.model';
|
|
55
57
|
export * from './app/models/data/selection.model';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veltdev/types-dev",
|
|
3
|
-
"version": "5.0.2-beta.
|
|
3
|
+
"version": "5.0.2-beta.68",
|
|
4
4
|
"description": "Velt is an SDK to add collaborative features to your product within minutes. Example: Comments like Figma, Frame.io, Google docs or sheets, Recording like Loom, Huddles like Slack and much more.",
|
|
5
5
|
"homepage": "https://velt.dev",
|
|
6
6
|
"keywords": [
|
package/types.d.ts
CHANGED
|
@@ -18,4 +18,5 @@ export * from './app/models/element/autocomplete-element.model';
|
|
|
18
18
|
export * from './app/models/element/reaction-element.model';
|
|
19
19
|
export * from './app/models/element/crdt-element.model';
|
|
20
20
|
export * from './app/models/element/activity-element.model';
|
|
21
|
+
export * from './app/models/element/suggestion-element.model';
|
|
21
22
|
export * from './models';
|