@contrail/extensions-sdk 1.0.28 → 1.0.29
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/lib/apps/boards.d.ts +77 -1
- package/lib/apps/boards.js +39 -0
- package/package.json +1 -1
package/lib/apps/boards.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export declare enum BoardCommand {
|
|
|
8
8
|
RECOLOR_IMAGES = "board:recolor_images",
|
|
9
9
|
ADD_CONTENT_TO_ENTITY_FROM_ELEMENTS = "board:add_content_to_entity_from_elements",
|
|
10
10
|
ADD_FRAMES_FROM_TEMPLATE = "board:add_frames_from_template",
|
|
11
|
-
ADD_ITEMS_TO_CLIPBOARD = "board:add_items_to_clipboard"
|
|
11
|
+
ADD_ITEMS_TO_CLIPBOARD = "board:add_items_to_clipboard",
|
|
12
|
+
COMPOSE_CONTENT = "board:compose_content"
|
|
12
13
|
}
|
|
13
14
|
/** Payload for bulk-add items to clipboard (Board and Showcase). */
|
|
14
15
|
export interface ClipboardItemsPayload {
|
|
@@ -17,6 +18,59 @@ export interface ClipboardItemsPayload {
|
|
|
17
18
|
projectItemId?: string | null;
|
|
18
19
|
}>;
|
|
19
20
|
}
|
|
21
|
+
/** One image in a composition, placed in fractions of the output box. */
|
|
22
|
+
export interface ComposeContentLayer {
|
|
23
|
+
/** The content to draw. The host resolves it to an image, so no URL is needed - and none can
|
|
24
|
+
* expire between planning the layout and composing it. */
|
|
25
|
+
contentId: string;
|
|
26
|
+
/**
|
|
27
|
+
* Top-left corner as a fraction of the composition box, so `{x: 0.5, y: 0}` is the top middle.
|
|
28
|
+
*
|
|
29
|
+
* Fractions rather than pixels: the layout is then independent of whatever size the extension
|
|
30
|
+
* previewed it at, and the same plan can be reused at any output resolution.
|
|
31
|
+
*/
|
|
32
|
+
position: {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
};
|
|
36
|
+
/** Size as a fraction of the composition box. `{width: 1, height: 1}` fills it. */
|
|
37
|
+
size: {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
};
|
|
41
|
+
/** Degrees clockwise about the layer's centre. */
|
|
42
|
+
rotation?: number;
|
|
43
|
+
/** 0-1. Defaults to fully opaque. */
|
|
44
|
+
opacity?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface ComposeContentRequest {
|
|
47
|
+
/** Drawn back to front: the first layer is behind, the last on top. */
|
|
48
|
+
layers: Array<ComposeContentLayer>;
|
|
49
|
+
/**
|
|
50
|
+
* What the new content is filed against, e.g. `item:<id>`.
|
|
51
|
+
*
|
|
52
|
+
* Required: content cannot be created free-floating - the platform derives its access policies
|
|
53
|
+
* from the holder.
|
|
54
|
+
*/
|
|
55
|
+
contentHolderReference: string;
|
|
56
|
+
/** Output size in pixels. The host derives one from the source images when omitted. */
|
|
57
|
+
outputSize?: {
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
};
|
|
61
|
+
/** Defaults to transparent, which is usually what a composed pack shot wants. */
|
|
62
|
+
backgroundColor?: string;
|
|
63
|
+
fileName?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ComposeContentResult {
|
|
66
|
+
contentId: string;
|
|
67
|
+
primaryFileId?: string;
|
|
68
|
+
primaryFileUrl?: string;
|
|
69
|
+
size: {
|
|
70
|
+
width: number;
|
|
71
|
+
height: number;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
20
74
|
export interface BoardDocumentElement extends DocumentElement {
|
|
21
75
|
[key: string]: any;
|
|
22
76
|
}
|
|
@@ -59,6 +113,28 @@ export declare class BoardsApp {
|
|
|
59
113
|
static getElements(criteria: object): Promise<Array<DocumentElement>>;
|
|
60
114
|
/** Creates new content from a set of elements and assigns to an entity (item, etc) as a viewable */
|
|
61
115
|
static createNewContentAndAssignToEntity(assignmentOptions: any, entity: any, elements: Array<DocumentElement>): Promise<Array<DocumentElement>>;
|
|
116
|
+
/**
|
|
117
|
+
* Composes several contents into one new image, and returns it as a new content.
|
|
118
|
+
*
|
|
119
|
+
* The extension supplies a layout - which content goes where, at what size - and the board
|
|
120
|
+
* rasterises it with the same renderer its own image export uses. Nothing is added to the
|
|
121
|
+
* board: the elements exist only for the duration of the render.
|
|
122
|
+
*
|
|
123
|
+
* This is the way to build a composed image from an extension. Reading the source images into
|
|
124
|
+
* a canvas the extension owns would taint it and make the export throw, because the image
|
|
125
|
+
* files are cross-origin.
|
|
126
|
+
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* const composed = await BoardsApp.composeContent({
|
|
129
|
+
* layers: [
|
|
130
|
+
* { contentId: 'c1', position: { x: 0, y: 0 }, size: { width: 0.6, height: 0.6 } },
|
|
131
|
+
* { contentId: 'c2', position: { x: 0.4, y: 0.4 }, size: { width: 0.6, height: 0.6 } },
|
|
132
|
+
* ],
|
|
133
|
+
* contentHolderReference: `item:${setItem.id}`,
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
static composeContent(request: ComposeContentRequest): Promise<ComposeContentResult>;
|
|
62
138
|
static recolorImages(imageElements: Array<DocumentElement>, hexCode: string, hexMap?: {}): Promise<Array<DocumentElement>>;
|
|
63
139
|
/** Request the host to bulk-add items to the user's clipboard. */
|
|
64
140
|
static addItemsToClipboard(clipboardItems: Array<{
|
package/lib/apps/boards.js
CHANGED
|
@@ -22,6 +22,7 @@ var BoardCommand;
|
|
|
22
22
|
BoardCommand["ADD_CONTENT_TO_ENTITY_FROM_ELEMENTS"] = "board:add_content_to_entity_from_elements";
|
|
23
23
|
BoardCommand["ADD_FRAMES_FROM_TEMPLATE"] = "board:add_frames_from_template";
|
|
24
24
|
BoardCommand["ADD_ITEMS_TO_CLIPBOARD"] = "board:add_items_to_clipboard";
|
|
25
|
+
BoardCommand["COMPOSE_CONTENT"] = "board:compose_content";
|
|
25
26
|
})(BoardCommand = exports.BoardCommand || (exports.BoardCommand = {}));
|
|
26
27
|
class BoardsApp {
|
|
27
28
|
static getCurrentBoard() {
|
|
@@ -92,6 +93,44 @@ class BoardsApp {
|
|
|
92
93
|
return this.validateAndReturnResults(results);
|
|
93
94
|
});
|
|
94
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Composes several contents into one new image, and returns it as a new content.
|
|
98
|
+
*
|
|
99
|
+
* The extension supplies a layout - which content goes where, at what size - and the board
|
|
100
|
+
* rasterises it with the same renderer its own image export uses. Nothing is added to the
|
|
101
|
+
* board: the elements exist only for the duration of the render.
|
|
102
|
+
*
|
|
103
|
+
* This is the way to build a composed image from an extension. Reading the source images into
|
|
104
|
+
* a canvas the extension owns would taint it and make the export throw, because the image
|
|
105
|
+
* files are cross-origin.
|
|
106
|
+
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* const composed = await BoardsApp.composeContent({
|
|
109
|
+
* layers: [
|
|
110
|
+
* { contentId: 'c1', position: { x: 0, y: 0 }, size: { width: 0.6, height: 0.6 } },
|
|
111
|
+
* { contentId: 'c2', position: { x: 0.4, y: 0.4 }, size: { width: 0.6, height: 0.6 } },
|
|
112
|
+
* ],
|
|
113
|
+
* contentHolderReference: `item:${setItem.id}`,
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
static composeContent(request) {
|
|
118
|
+
var _a;
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
BoardsApp.validateBoardContext();
|
|
121
|
+
if (!((_a = request === null || request === void 0 ? void 0 : request.layers) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
122
|
+
throw new Error('composeContent requires at least one layer.');
|
|
123
|
+
}
|
|
124
|
+
if (!(request === null || request === void 0 ? void 0 : request.contentHolderReference)) {
|
|
125
|
+
throw new Error('composeContent requires a contentHolderReference, e.g. `item:<id>`.');
|
|
126
|
+
}
|
|
127
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToHost({
|
|
128
|
+
command: BoardCommand.COMPOSE_CONTENT,
|
|
129
|
+
data: request,
|
|
130
|
+
});
|
|
131
|
+
return this.validateAndReturnResults(results);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
95
134
|
static recolorImages(imageElements, hexCode, hexMap = {}) {
|
|
96
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
136
|
BoardsApp.validateBoardContext();
|
package/package.json
CHANGED