@contrail/extensions-sdk 1.0.26 → 1.0.28

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.
@@ -6,7 +6,9 @@ export declare enum PlanCommand {
6
6
  ADD_PLACEHOLDERS = "plan:add_placeholders",
7
7
  ADD_PLACEHOLDERS_WITH_ITEMS = "plan:add_placeholders_with_items",
8
8
  GET_PLACEHOLDERS = "plan:get_placeholders",
9
- GET_VIEW_STATE = "plan:get_view_state"
9
+ GET_VIEW_STATE = "plan:get_view_state",
10
+ ASSIGN_ITEMS = "plan:assign_items",
11
+ SCROLL_TO_PLACEHOLDER = "plan:scroll_to_placeholder"
10
12
  }
11
13
  /**
12
14
  * A row on a plan. Beyond the item linkage below, properties are the org-configured
@@ -34,6 +36,37 @@ export interface AddPlaceholdersOptions {
34
36
  * - `selected` — only the currently selected rows
35
37
  */
36
38
  export declare type PlanPlaceholderScope = 'all' | 'filtered' | 'displayed' | 'selected';
39
+ /** Assigns one existing item to one existing placeholder row. */
40
+ export interface PlaceholderItemAssignment {
41
+ /** The row to assign onto. */
42
+ placeholderId: string;
43
+ /** The item to assign — an item family or an item option. */
44
+ itemId: string;
45
+ }
46
+ export interface ScrollToPlaceholderOptions {
47
+ /**
48
+ * Also bring this column into view horizontally.
49
+ *
50
+ * Omit to scroll vertically only, which is usually what you want after writing to a row —
51
+ * it leaves the user's horizontal position alone.
52
+ */
53
+ propertySlug?: string;
54
+ }
55
+ /** Why a row could not be brought into view. */
56
+ export declare type ScrollToPlaceholderFailure = 'not-on-plan' | 'not-displayed' | 'no-grid';
57
+ export interface ScrollToPlaceholderResult {
58
+ /** Whether the row was brought into view. Already-visible rows report `true`. */
59
+ revealed: boolean;
60
+ /**
61
+ * Set only when `revealed` is false.
62
+ *
63
+ * - `not-on-plan` - no row on this plan has that id.
64
+ * - `not-displayed` - the row exists but the user's filter or sort excludes it, so there is
65
+ * no position to scroll to. Reading {@link PlanApp.getViewState} will say why.
66
+ * - `no-grid` - the plan is not currently showing the grid, so there is nothing to scroll.
67
+ */
68
+ reason?: ScrollToPlaceholderFailure;
69
+ }
37
70
  export interface GetPlaceholdersOptions {
38
71
  /** Defaults to `all`. */
39
72
  scope?: PlanPlaceholderScope;
@@ -108,6 +141,41 @@ export declare class PlanApp {
108
141
  * Reading is always permitted, including on a view-only plan.
109
142
  */
110
143
  static getViewState(): Promise<PlanViewState>;
144
+ /**
145
+ * Assigns existing items to existing placeholder rows.
146
+ *
147
+ * Runs the plan's own item-assignment pipeline, so the item's properties are mapped onto the
148
+ * row, the project item is created if needed, and carryover is applied — the same work the grid
149
+ * does when a user drops an item onto a row. Rows appear updated immediately and the change is
150
+ * broadcast to other users.
151
+ *
152
+ * Use this to fill placeholders that already carry attribution; to create new rows instead, see
153
+ * {@link addPlaceholders}.
154
+ *
155
+ * Requires the plan to be editable.
156
+ */
157
+ static assignItems(assignments: Array<PlaceholderItemAssignment>): Promise<void>;
158
+ /**
159
+ * Scrolls the plan's grid so a row is in view.
160
+ *
161
+ * Use this after writing to the plan - assigning items or adding rows - so the user can see
162
+ * what changed instead of having to hunt for it. A row that is already on screen is left
163
+ * alone rather than re-centred.
164
+ *
165
+ * This is a view-only operation: it does not select the row, change the filter, or edit
166
+ * anything, and it does not require the plan to be editable.
167
+ *
168
+ * Check the result rather than assuming success - a row outside the user's current filter has
169
+ * no position in the grid to scroll to:
170
+ *
171
+ * ```ts
172
+ * const result = await PlanApp.scrollToPlaceholder(rowId);
173
+ * if (!result.revealed && result.reason === 'not-displayed') {
174
+ * // The row was written, but the user's filter hides it.
175
+ * }
176
+ * ```
177
+ */
178
+ static scrollToPlaceholder(placeholderId: string, options?: ScrollToPlaceholderOptions): Promise<ScrollToPlaceholderResult>;
111
179
  /**
112
180
  * Creates new rows on the plan from property data, and returns them.
113
181
  *
package/lib/apps/plan.js CHANGED
@@ -21,6 +21,8 @@ var PlanCommand;
21
21
  PlanCommand["ADD_PLACEHOLDERS_WITH_ITEMS"] = "plan:add_placeholders_with_items";
22
22
  PlanCommand["GET_PLACEHOLDERS"] = "plan:get_placeholders";
23
23
  PlanCommand["GET_VIEW_STATE"] = "plan:get_view_state";
24
+ PlanCommand["ASSIGN_ITEMS"] = "plan:assign_items";
25
+ PlanCommand["SCROLL_TO_PLACEHOLDER"] = "plan:scroll_to_placeholder";
24
26
  })(PlanCommand = exports.PlanCommand || (exports.PlanCommand = {}));
25
27
  class PlanApp {
26
28
  static getCurrentPlan() {
@@ -144,6 +146,65 @@ class PlanApp {
144
146
  return viewState;
145
147
  });
146
148
  }
149
+ /**
150
+ * Assigns existing items to existing placeholder rows.
151
+ *
152
+ * Runs the plan's own item-assignment pipeline, so the item's properties are mapped onto the
153
+ * row, the project item is created if needed, and carryover is applied — the same work the grid
154
+ * does when a user drops an item onto a row. Rows appear updated immediately and the change is
155
+ * broadcast to other users.
156
+ *
157
+ * Use this to fill placeholders that already carry attribution; to create new rows instead, see
158
+ * {@link addPlaceholders}.
159
+ *
160
+ * Requires the plan to be editable.
161
+ */
162
+ static assignItems(assignments) {
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ PlanApp.validatePlanContext();
165
+ if (!(assignments === null || assignments === void 0 ? void 0 : assignments.length)) {
166
+ return;
167
+ }
168
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToHost({
169
+ command: PlanCommand.ASSIGN_ITEMS,
170
+ data: { assignments },
171
+ });
172
+ PlanApp.validateAndReturnResults(results);
173
+ });
174
+ }
175
+ /**
176
+ * Scrolls the plan's grid so a row is in view.
177
+ *
178
+ * Use this after writing to the plan - assigning items or adding rows - so the user can see
179
+ * what changed instead of having to hunt for it. A row that is already on screen is left
180
+ * alone rather than re-centred.
181
+ *
182
+ * This is a view-only operation: it does not select the row, change the filter, or edit
183
+ * anything, and it does not require the plan to be editable.
184
+ *
185
+ * Check the result rather than assuming success - a row outside the user's current filter has
186
+ * no position in the grid to scroll to:
187
+ *
188
+ * ```ts
189
+ * const result = await PlanApp.scrollToPlaceholder(rowId);
190
+ * if (!result.revealed && result.reason === 'not-displayed') {
191
+ * // The row was written, but the user's filter hides it.
192
+ * }
193
+ * ```
194
+ */
195
+ static scrollToPlaceholder(placeholderId, options) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ PlanApp.validatePlanContext();
198
+ if (!placeholderId) {
199
+ return { revealed: false, reason: 'not-on-plan' };
200
+ }
201
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToHost({
202
+ command: PlanCommand.SCROLL_TO_PLACEHOLDER,
203
+ data: { placeholderId, options },
204
+ });
205
+ return PlanApp.validateAndReturnResults(results);
206
+ });
207
+ }
147
208
  /**
148
209
  * Creates new rows on the plan from property data, and returns them.
149
210
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/extensions-sdk",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "Client library for interfacing with VibeIQ's services and apps from an extension.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",