@appsemble/sdk 0.20.27 → 0.20.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/README.md +4 -4
- package/package.json +2 -2
- package/changed/added/.gitkeep +0 -0
- package/changed/changed/.gitkeep +0 -0
- package/changed/deprecated/.gitkeep +0 -0
- package/changed/fixed/.gitkeep +0 -0
- package/changed/removed/.gitkeep +0 -0
- package/changed/security/.gitkeep +0 -0
- package/index.js.map +0 -1
- package/index.test.js.map +0 -1
- package/index.test.ts +0 -34
- package/index.ts +0 -323
- package/jest.config.js +0 -3
- package/tsconfig.json +0 -6
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#  Appsemble SDK
|
|
2
2
|
|
|
3
3
|
> Build your own blocks
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@appsemble/sdk)
|
|
6
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.20.29)
|
|
7
|
+
[](https://codecov.io/gl/appsemble/appsemble)
|
|
8
8
|
[](https://prettier.io)
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
@@ -144,5 +144,5 @@ declare module '@appsemble/sdk' {
|
|
|
144
144
|
|
|
145
145
|
## License
|
|
146
146
|
|
|
147
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.20.
|
|
147
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.20.29/LICENSE.md) ©
|
|
148
148
|
[Appsemble](https://appsemble.com)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/sdk",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.29",
|
|
4
4
|
"description": "Build your own blocks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@appsemble/types": "0.20.
|
|
37
|
+
"@appsemble/types": "0.20.29",
|
|
38
38
|
"@fortawesome/fontawesome-common-types": "^6.0.0",
|
|
39
39
|
"type-fest": "^2.0.0"
|
|
40
40
|
}
|
package/changed/added/.gitkeep
DELETED
|
File without changes
|
package/changed/changed/.gitkeep
DELETED
|
File without changes
|
|
File without changes
|
package/changed/fixed/.gitkeep
DELETED
|
File without changes
|
package/changed/removed/.gitkeep
DELETED
|
File without changes
|
|
File without changes
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAiTA;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,EAAqB;IAC7C,MAAM,KAAK,GAA4B,IAAI,WAAW,CAAC,oBAAoB,EAAE;QAC3E,MAAM,EAAE;YACN,EAAE;YACF,QAAQ;SACT;KACF,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,aAAa,EAAE;QAC1B,QAAQ,CAAC,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;KAC7C;AACH,CAAC"}
|
package/index.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,IAAI,KAAkB,CAAC;AACvB,IAAI,qBAA6C,CAAC;AAElD,UAAU,CAAC,GAAG,EAAE;IACd,qBAAqB,GAAG,QAAQ,CAAC,aAAa,CAAC;IAC/C,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,eAAe,EAAE;QAC/C,KAAK,EAAE;YACL,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;gBACvC,KAAK,GAAG,CAAC,CAAC;YACZ,CAAC,CAAC;SACH;QACD,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC,GAAG,EAAE;IACb,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,eAAe,EAAE;QAC/C,KAAK,EAAE,qBAAqB;QAC5B,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IACH,qBAAqB,GAAG,SAAS,CAAC;AACpC,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QACjC,SAAS,CAAC,EAAE,CAAC,CAAC;QACd,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,oBAAoB,CAAC,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;QACvF,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC9C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/index.test.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { bootstrap } from './index.js';
|
|
2
|
-
|
|
3
|
-
let event: CustomEvent;
|
|
4
|
-
let originalCurrentScript: HTMLOrSVGScriptElement;
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
originalCurrentScript = document.currentScript;
|
|
8
|
-
Object.defineProperty(document, 'currentScript', {
|
|
9
|
-
value: {
|
|
10
|
-
dispatchEvent: import.meta.jest.fn((e) => {
|
|
11
|
-
event = e;
|
|
12
|
-
}),
|
|
13
|
-
},
|
|
14
|
-
writable: true,
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
Object.defineProperty(document, 'currentScript', {
|
|
20
|
-
value: originalCurrentScript,
|
|
21
|
-
writable: true,
|
|
22
|
-
});
|
|
23
|
-
originalCurrentScript = undefined;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('bootstrap', () => {
|
|
27
|
-
it('should dispatch the AppsembleBootstrap event', () => {
|
|
28
|
-
const fn = import.meta.jest.fn();
|
|
29
|
-
bootstrap(fn);
|
|
30
|
-
expect(document.currentScript.dispatchEvent).toHaveBeenCalledWith(new CustomEvent(''));
|
|
31
|
-
expect(event.type).toBe('AppsembleBootstrap');
|
|
32
|
-
expect(event.detail).toStrictEqual({ fn, document });
|
|
33
|
-
});
|
|
34
|
-
});
|
package/index.ts
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
2
|
-
import type { Action, BaseMessage, BulmaColor, BulmaSize, Theme } from '@appsemble/types';
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
4
|
-
import type { IconName } from '@fortawesome/fontawesome-common-types';
|
|
5
|
-
import { Promisable } from 'type-fest';
|
|
6
|
-
|
|
7
|
-
export { IconName };
|
|
8
|
-
export { Action, BulmaColor, BulmaSize, Theme };
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A user defined remapper function.
|
|
12
|
-
*/
|
|
13
|
-
export type Remapper = object[] | boolean | number | object | string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Actions defined on a block.
|
|
17
|
-
*
|
|
18
|
-
* If a block uses actions, extend this interface using module augmentation. The keys are the names
|
|
19
|
-
* of the events the block supports.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* declare module '@appsemble/sdk' {
|
|
23
|
-
* interface Actions {
|
|
24
|
-
* onClick: {}
|
|
25
|
-
* }
|
|
26
|
-
* }
|
|
27
|
-
*/
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
29
|
-
export interface Actions {}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Messages defined on a block.
|
|
33
|
-
*
|
|
34
|
-
* If a block uses messages, extend this interface using module augmentation.
|
|
35
|
-
* The keys are the names of the messages.
|
|
36
|
-
* The types are either `never` if the message doesn’t support parameters
|
|
37
|
-
* or an object containing the keys of values and the type of the value.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* declare module '@appsemble/sdk' {
|
|
41
|
-
* interface Messages {
|
|
42
|
-
* exampleMessage: never;
|
|
43
|
-
* hello: { person: string };
|
|
44
|
-
* }
|
|
45
|
-
* }
|
|
46
|
-
*/
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
48
|
-
export interface Messages {}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Event emitters defined on a block.
|
|
52
|
-
*
|
|
53
|
-
* If a block emits events, extend this interface using module augmentation. The keys are the names
|
|
54
|
-
* of the events the block can emit.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* declare module '@appsemble/sdk' {
|
|
58
|
-
* interface EventEmitters {
|
|
59
|
-
* data: {}
|
|
60
|
-
* }
|
|
61
|
-
* }
|
|
62
|
-
*/
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
64
|
-
export interface EventEmitters {}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Event listeners defined on a block.
|
|
68
|
-
*
|
|
69
|
-
* If a block listens on events, extend this interface using module augmentation. The keys are the
|
|
70
|
-
* names of the events the block can emit.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* declare module '@appsemble/sdk' {
|
|
74
|
-
* interface EventListeners {
|
|
75
|
-
* data: {}
|
|
76
|
-
* }
|
|
77
|
-
* }
|
|
78
|
-
*/
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
80
|
-
export interface EventListeners {}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Custom free form parameters defined on a block.
|
|
84
|
-
*
|
|
85
|
-
* If a block listens on events, extend this interface using module augmentation. The keys are the
|
|
86
|
-
* names of the events the block can emit.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* declare module '@appsemble/sdk' {
|
|
90
|
-
* interface Parameters {
|
|
91
|
-
* param1: string;
|
|
92
|
-
* param2: number;
|
|
93
|
-
* param3: {
|
|
94
|
-
* nested: boolean;
|
|
95
|
-
* }
|
|
96
|
-
* }
|
|
97
|
-
* }
|
|
98
|
-
*/
|
|
99
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
100
|
-
export interface Parameters {}
|
|
101
|
-
|
|
102
|
-
export type PageParameters = Record<string, string>;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* A menu item that can be displayed in addition to the normal app menu.
|
|
106
|
-
*/
|
|
107
|
-
export interface MenuItem {
|
|
108
|
-
/**
|
|
109
|
-
* The title of the menu item.
|
|
110
|
-
*/
|
|
111
|
-
title: string;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* The icon to display next to the title.
|
|
115
|
-
*/
|
|
116
|
-
icon?: IconName;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* The color to use for the icon.
|
|
120
|
-
*/
|
|
121
|
-
iconColor?: BulmaColor;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* The click handler for when the menu item is clicked.
|
|
125
|
-
*/
|
|
126
|
-
onClick: () => void;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* The submenu items associated with this menu item.
|
|
130
|
-
*/
|
|
131
|
-
submenu?: Omit<MenuItem, 'submenu'>[];
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Whether the item is considered active.
|
|
135
|
-
*/
|
|
136
|
-
active?: boolean;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export interface Message extends BaseMessage {
|
|
140
|
-
/**
|
|
141
|
-
* The content of the message to display.
|
|
142
|
-
*/
|
|
143
|
-
body: string;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* A set of utility functions provided by the Appsemble SDK.
|
|
148
|
-
*/
|
|
149
|
-
export interface Utils {
|
|
150
|
-
/**
|
|
151
|
-
* Register a function that should be called when the block is being removed.
|
|
152
|
-
*
|
|
153
|
-
* Use this to clean up resouces that would otherwise stay in memory, e.g. object URLs.
|
|
154
|
-
*/
|
|
155
|
-
addCleanup: (fn: () => void) => void;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Remap data based in a user defined remapper function.
|
|
159
|
-
*
|
|
160
|
-
* @param remapper The user defined remapper function.
|
|
161
|
-
* @param data The data to remap.
|
|
162
|
-
* @param context The context to retrieve contextual data from.
|
|
163
|
-
* @returns The result of the remapped data.
|
|
164
|
-
*/
|
|
165
|
-
remap: (remapper: Remapper, data: unknown, context?: Record<string, unknown>) => unknown;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Show a bulma style message.
|
|
169
|
-
*/
|
|
170
|
-
showMessage: (message: Message | string) => void;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Formats a message using ICU syntax.
|
|
174
|
-
*/
|
|
175
|
-
formatMessage: <T extends keyof Messages>(
|
|
176
|
-
message: T,
|
|
177
|
-
...args: Messages[T] extends never ? [] : [Messages[T]]
|
|
178
|
-
) => string;
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Get a URL serving an asset for the given asset id.
|
|
182
|
-
*
|
|
183
|
-
* @param assetId The id of the asset whose URL to get.
|
|
184
|
-
* @returns The URL that matches the given asset id.
|
|
185
|
-
*/
|
|
186
|
-
asset: (assetId: string) => string;
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Convert a FontAwesome icon name into a valid FontAwesome CSS class.
|
|
190
|
-
*
|
|
191
|
-
* @param icon The FontAwesome icon.
|
|
192
|
-
* @returns String containing the FontAwesome classes for the icon.
|
|
193
|
-
*/
|
|
194
|
-
fa: (icon: IconName) => string;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* @param items The list of menu items to display.
|
|
198
|
-
* @param header A header that can be used to separate from other block menus.
|
|
199
|
-
*/
|
|
200
|
-
menu: (items: MenuItem[], header?: string) => void;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export interface Events {
|
|
204
|
-
/**
|
|
205
|
-
* Emit an Appsemble event.
|
|
206
|
-
*
|
|
207
|
-
* @param type The type of event to emit.
|
|
208
|
-
* @param data Data to emit with the event.
|
|
209
|
-
* @returns Boolean indicating whether an emitter is implemented or not.
|
|
210
|
-
*/
|
|
211
|
-
emit: { [K in keyof EventEmitters]: (data: unknown, error?: string) => Promise<boolean> };
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Remove an event listener for an Appsemble event.
|
|
215
|
-
*
|
|
216
|
-
* @param type The type of event to listen remove the listener from.
|
|
217
|
-
* @param callback The callback to remove.
|
|
218
|
-
* @returns Boolean indicating whether a listener is implemented or not.
|
|
219
|
-
*/
|
|
220
|
-
off: {
|
|
221
|
-
[K in keyof EventListeners]: <T>(callback: (data: T, error?: string) => void) => boolean;
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Add an event listener for an Appsemble event.
|
|
226
|
-
*
|
|
227
|
-
* @param type The type of event to listen on.
|
|
228
|
-
* @param callback A callback to register for the event.
|
|
229
|
-
* @returns Boolean indicating whether a listener is implemented or not.
|
|
230
|
-
*/
|
|
231
|
-
on: {
|
|
232
|
-
[K in keyof EventListeners]: <T>(callback: (data: T, error?: string) => void) => boolean;
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* The parameters that get passed to the bootstrap function.
|
|
238
|
-
*/
|
|
239
|
-
export interface BootstrapParams {
|
|
240
|
-
/**
|
|
241
|
-
* The actions that may be dispatched by the block.
|
|
242
|
-
*/
|
|
243
|
-
actions: { [K in keyof Actions]: Action };
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* The parameters as they are defined in the app definition.
|
|
247
|
-
*/
|
|
248
|
-
parameters: Parameters;
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Any kind of data that has been passed in by some context.
|
|
252
|
-
*/
|
|
253
|
-
data: unknown;
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Event related functions and constants.
|
|
257
|
-
*/
|
|
258
|
-
events: Events;
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* URL parameters of the current route.
|
|
262
|
-
*
|
|
263
|
-
* If the page on which the block is rendered, has parameters specified on a page level, the
|
|
264
|
-
* parameter keys and values of the page will be extracted and set as this object.
|
|
265
|
-
*/
|
|
266
|
-
pageParameters?: PageParameters;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* The path of the block as it is being rendered on the page using the page’s normalized name.
|
|
270
|
-
*/
|
|
271
|
-
path: string;
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* The path of the block as it is being rendered on the page using the page’s index.
|
|
275
|
-
*/
|
|
276
|
-
pathIndex: string;
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* The theme of the block given the context.
|
|
280
|
-
*
|
|
281
|
-
* This is based on a combination of the base theme, app theme, page theme and block theme.
|
|
282
|
-
*/
|
|
283
|
-
theme: Theme;
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* The shadow root to which DOM elements may be appended.
|
|
287
|
-
*/
|
|
288
|
-
shadowRoot: ShadowRoot;
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Some utility functions provided by the Appsemble app framework.
|
|
292
|
-
*/
|
|
293
|
-
utils: Utils;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
297
|
-
export type BootstrapFunction = (params: BootstrapParams) => Promisable<Element | void>;
|
|
298
|
-
|
|
299
|
-
export interface AppsembleBootstrapEvent extends CustomEvent {
|
|
300
|
-
detail: {
|
|
301
|
-
fn: BootstrapFunction;
|
|
302
|
-
document: Document;
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Register a bootstrap function.
|
|
308
|
-
*
|
|
309
|
-
* @param fn The bootstrap function to register
|
|
310
|
-
*
|
|
311
|
-
* If the function returns an element, it’s appended to the shadow root.
|
|
312
|
-
*/
|
|
313
|
-
export function bootstrap(fn: BootstrapFunction): void {
|
|
314
|
-
const event: AppsembleBootstrapEvent = new CustomEvent('AppsembleBootstrap', {
|
|
315
|
-
detail: {
|
|
316
|
-
fn,
|
|
317
|
-
document,
|
|
318
|
-
},
|
|
319
|
-
});
|
|
320
|
-
if (document.currentScript) {
|
|
321
|
-
document.currentScript.dispatchEvent(event);
|
|
322
|
-
}
|
|
323
|
-
}
|
package/jest.config.js
DELETED