@getflip/bridge 0.1.0-alpha.9 → 0.2.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 +286 -5
- package/dist/dialog/dialog.d.ts +10 -0
- package/dist/dialog/dialog.js +45 -0
- package/dist/dialog/dialog.js.map +1 -0
- package/dist/dialog/dialog.spec.d.ts +1 -0
- package/dist/dialog/dialog.spec.js +83 -0
- package/dist/dialog/dialog.spec.js.map +1 -0
- package/dist/dialog/dialog.types.d.ts +33 -0
- package/dist/dialog/dialog.types.js +2 -0
- package/dist/dialog/dialog.types.js.map +1 -0
- package/dist/dialog/index.d.ts +2 -0
- package/dist/dialog/index.js +3 -0
- package/dist/dialog/index.js.map +1 -0
- package/dist/events/events.d.ts +1 -1
- package/dist/events/events.js.map +1 -1
- package/dist/events/events.types.d.ts +2 -0
- package/dist/events/events.types.js +2 -0
- package/dist/events/events.types.js.map +1 -1
- package/dist/index.cjs.js +108 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -7
- package/dist/index.mjs.map +1 -1
- package/dist/modal/index.d.ts +2 -0
- package/dist/modal/index.js +3 -0
- package/dist/modal/index.js.map +1 -0
- package/dist/modal/modal.d.ts +10 -0
- package/dist/modal/modal.js +45 -0
- package/dist/modal/modal.js.map +1 -0
- package/dist/modal/modal.spec.d.ts +1 -0
- package/dist/modal/modal.spec.js +81 -0
- package/dist/modal/modal.spec.js.map +1 -0
- package/dist/modal/modal.types.d.ts +30 -0
- package/dist/modal/modal.types.js +2 -0
- package/dist/modal/modal.types.js.map +1 -0
- package/dist/theming/theming.types.d.ts +3 -3
- package/dist/types.d.ts +18 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,6 +11,8 @@ App or Flip Admin Console.
|
|
|
11
11
|
- [Internationalization](#internationalization)
|
|
12
12
|
- [Navigation](#navigation)
|
|
13
13
|
- [Theming](#theming)
|
|
14
|
+
- [Dialogs](#dialogs)
|
|
15
|
+
- [Modals](#modals)
|
|
14
16
|
- [Events](#events)
|
|
15
17
|
- [Error Handling](#error-handling)
|
|
16
18
|
- [Development](#development)
|
|
@@ -48,7 +50,7 @@ initFlipBridge({
|
|
|
48
50
|
|
|
49
51
|
Get all available languages of the host app.
|
|
50
52
|
|
|
51
|
-
**Returns** `string[]
|
|
53
|
+
**Returns** `Promise<string[]>`
|
|
52
54
|
|
|
53
55
|
**Example**
|
|
54
56
|
|
|
@@ -62,7 +64,7 @@ const availableLanguages = await getAvailableLangs(); // e.g. ['de', 'en', 'fr',
|
|
|
62
64
|
|
|
63
65
|
Get the current language of the host app.
|
|
64
66
|
|
|
65
|
-
**Returns** `string
|
|
67
|
+
**Returns** `Promise<string>`
|
|
66
68
|
|
|
67
69
|
**Example**
|
|
68
70
|
|
|
@@ -78,7 +80,9 @@ const currentLanguage = await getLang(); // e.g. 'en'
|
|
|
78
80
|
|
|
79
81
|
Navigate to a specific route.
|
|
80
82
|
|
|
81
|
-
**
|
|
83
|
+
**Param** `string`
|
|
84
|
+
|
|
85
|
+
**Returns** `Promise<boolean>`
|
|
82
86
|
|
|
83
87
|
**Example**
|
|
84
88
|
|
|
@@ -97,10 +101,10 @@ Get the current theme.
|
|
|
97
101
|
**Returns**
|
|
98
102
|
|
|
99
103
|
```js
|
|
100
|
-
{
|
|
104
|
+
Promise<{
|
|
101
105
|
activeTheme: "light" | "dark";
|
|
102
106
|
preferredTheme: "light" | "dark" | undefined;
|
|
103
|
-
}
|
|
107
|
+
}>
|
|
104
108
|
```
|
|
105
109
|
|
|
106
110
|
**Example**
|
|
@@ -111,6 +115,253 @@ import { getTheme } from "@getflip/bridge";
|
|
|
111
115
|
const theme = await getTheme();
|
|
112
116
|
```
|
|
113
117
|
|
|
118
|
+
### Dialogs
|
|
119
|
+
|
|
120
|
+
#### `createDialog`
|
|
121
|
+
|
|
122
|
+
Creates a modal dialog rendered by the host app.
|
|
123
|
+
|
|
124
|
+
**Param**
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
{
|
|
128
|
+
hideLabel?: boolean;
|
|
129
|
+
id: string;
|
|
130
|
+
intent?: 'primary' | 'critical';
|
|
131
|
+
label: string;
|
|
132
|
+
text: string;
|
|
133
|
+
primaryAction?: {
|
|
134
|
+
label: string;
|
|
135
|
+
};
|
|
136
|
+
secondaryAction?: {
|
|
137
|
+
label: string;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Returns**
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
Promise<{
|
|
146
|
+
id: string;
|
|
147
|
+
open: () => Promise<boolean>;
|
|
148
|
+
close: () => Promise<boolean>;
|
|
149
|
+
destroy: () => Promise<boolean>;
|
|
150
|
+
}>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Example**
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
import { createDialog } from "@getflip/bridge";
|
|
157
|
+
|
|
158
|
+
const dialog = await createDialog({
|
|
159
|
+
id: "my-dialog",
|
|
160
|
+
label: "My Dialog",
|
|
161
|
+
text: "Lorem ipsum",
|
|
162
|
+
primaryAction: {
|
|
163
|
+
label: "Close",
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
await dialog.open();
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### `openDialog`
|
|
171
|
+
|
|
172
|
+
Opens a dialog.
|
|
173
|
+
|
|
174
|
+
**Param**
|
|
175
|
+
|
|
176
|
+
```js
|
|
177
|
+
{
|
|
178
|
+
id: string; // the dialog id
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Returns** `Promise<boolean>`
|
|
183
|
+
|
|
184
|
+
**Example**
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
import { createDialog, openDialog } from "@getflip/bridge";
|
|
188
|
+
|
|
189
|
+
await createDialog({
|
|
190
|
+
id: "my-dialog",
|
|
191
|
+
label: "My Dialog",
|
|
192
|
+
text: "Lorem ipsum",
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
await openDialog({ id: "my-dialog" });
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### `closeDialog`
|
|
199
|
+
|
|
200
|
+
Closes a dialog.
|
|
201
|
+
|
|
202
|
+
**Param**
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
{
|
|
206
|
+
id: string; // the dialog id
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Returns** `Promise<boolean>`
|
|
211
|
+
|
|
212
|
+
**Example**
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
import { closeDialog } from "@getflip/bridge";
|
|
216
|
+
|
|
217
|
+
await closeDialog({ id: "my-dialog" });
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### `destroyDialog`
|
|
221
|
+
|
|
222
|
+
Destroys a dialog, removing it from the DOM.
|
|
223
|
+
|
|
224
|
+
**Param**
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
{
|
|
228
|
+
id: string; // the dialog id
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Returns** `Promise<boolean>`
|
|
233
|
+
|
|
234
|
+
**Example**
|
|
235
|
+
|
|
236
|
+
```js
|
|
237
|
+
import { destroyDialog } from "@getflip/bridge";
|
|
238
|
+
|
|
239
|
+
await destroyDialog({ id: "my-dialog" });
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Modals
|
|
243
|
+
|
|
244
|
+
#### `createModal`
|
|
245
|
+
|
|
246
|
+
Creates a modal rendered by the host app. The modal will show the passed URL as
|
|
247
|
+
an iFrame.
|
|
248
|
+
|
|
249
|
+
**Param**
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
{
|
|
253
|
+
id: string;
|
|
254
|
+
label: string;
|
|
255
|
+
primaryAction?: {
|
|
256
|
+
label: string;
|
|
257
|
+
};
|
|
258
|
+
secondaryAction?: {
|
|
259
|
+
label: string;
|
|
260
|
+
};
|
|
261
|
+
url: string;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Returns**
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
Promise<{
|
|
269
|
+
id: string;
|
|
270
|
+
open: () => Promise<boolean>;
|
|
271
|
+
close: () => Promise<boolean>;
|
|
272
|
+
destroy: () => Promise<boolean>;
|
|
273
|
+
}>
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**Example**
|
|
277
|
+
|
|
278
|
+
```js
|
|
279
|
+
import { createModal } from "@getflip/bridge";
|
|
280
|
+
|
|
281
|
+
const modal = await createModal({
|
|
282
|
+
id: "my-moadl",
|
|
283
|
+
label: "My Modal",
|
|
284
|
+
primaryAction: {
|
|
285
|
+
label: "Close",
|
|
286
|
+
},
|
|
287
|
+
url: "https://google.com",
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
await modal.open();
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
#### `openModal`
|
|
294
|
+
|
|
295
|
+
Opens a modal.
|
|
296
|
+
|
|
297
|
+
**Param**
|
|
298
|
+
|
|
299
|
+
```js
|
|
300
|
+
{
|
|
301
|
+
id: string; // the modal id
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
**Returns** `Promise<boolean>`
|
|
306
|
+
|
|
307
|
+
**Example**
|
|
308
|
+
|
|
309
|
+
```js
|
|
310
|
+
import { createModal, openModal } from "@getflip/bridge";
|
|
311
|
+
|
|
312
|
+
await createModal({
|
|
313
|
+
id: "my-modal",
|
|
314
|
+
label: "My Modal",
|
|
315
|
+
url: "https://google.com",
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
await openModal({ id: "my-modal" });
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### `closeModal`
|
|
322
|
+
|
|
323
|
+
Closes a modal.
|
|
324
|
+
|
|
325
|
+
**Param**
|
|
326
|
+
|
|
327
|
+
```js
|
|
328
|
+
{
|
|
329
|
+
id: string; // the modal id
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
**Returns** `Promise<boolean>`
|
|
334
|
+
|
|
335
|
+
**Example**
|
|
336
|
+
|
|
337
|
+
```js
|
|
338
|
+
import { closeModal } from "@getflip/bridge";
|
|
339
|
+
|
|
340
|
+
await closeModal({ id: "my-modal" });
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
#### `destroyModal`
|
|
344
|
+
|
|
345
|
+
Destroys a modal, removing it from the DOM.
|
|
346
|
+
|
|
347
|
+
**Param**
|
|
348
|
+
|
|
349
|
+
```js
|
|
350
|
+
{
|
|
351
|
+
id: string; // the modal id
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**Returns** `Promise<boolean>`
|
|
356
|
+
|
|
357
|
+
**Example**
|
|
358
|
+
|
|
359
|
+
```js
|
|
360
|
+
import { destroyModal } from "@getflip/bridge";
|
|
361
|
+
|
|
362
|
+
await destroyModal({ id: "my-modal" });
|
|
363
|
+
```
|
|
364
|
+
|
|
114
365
|
## Events
|
|
115
366
|
|
|
116
367
|
Use the `subscribe` functions to subscribe to events.
|
|
@@ -140,6 +391,36 @@ Fires when the user selected language changes.
|
|
|
140
391
|
}
|
|
141
392
|
```
|
|
142
393
|
|
|
394
|
+
### `PRIMARY_ACTION_CLICK`
|
|
395
|
+
|
|
396
|
+
Fires when the primary action button of a dialog or modal is clicked.
|
|
397
|
+
|
|
398
|
+
**Event**
|
|
399
|
+
|
|
400
|
+
```js
|
|
401
|
+
{
|
|
402
|
+
data: {
|
|
403
|
+
parentId: string; // id of the action's dialog or modal
|
|
404
|
+
}
|
|
405
|
+
type: BridgeEventType.PRIMARY_ACTION_CLICK;
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### `SECONDARY_ACTION_CLICK`
|
|
410
|
+
|
|
411
|
+
Fires when the secondary action button of a dialog or modal is clicked.
|
|
412
|
+
|
|
413
|
+
**Event**
|
|
414
|
+
|
|
415
|
+
```js
|
|
416
|
+
{
|
|
417
|
+
data: {
|
|
418
|
+
parentId: string; // id of the action's dialog or modal
|
|
419
|
+
}
|
|
420
|
+
type: BridgeEventType.SECONDARY_ACTION_CLICK;
|
|
421
|
+
}
|
|
422
|
+
```
|
|
423
|
+
|
|
143
424
|
### `THEME_CHANGE`
|
|
144
425
|
|
|
145
426
|
Fires when the user theme changes.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CloseDialogRequest, CloseDialogRequestParams, CreateDialogRequestParams, DestroyDialogRequest, DestroyDialogRequestParams, OpenDialogRequest, OpenDialogRequestParams } from "./dialog.types";
|
|
2
|
+
export declare function createDialog(params: CreateDialogRequestParams): Promise<{
|
|
3
|
+
id: string;
|
|
4
|
+
open: () => Promise<import("../types").BridgeError | OpenDialogRequest>;
|
|
5
|
+
close: () => Promise<import("../types").BridgeError | CloseDialogRequest>;
|
|
6
|
+
destroy: () => Promise<import("../types").BridgeError | DestroyDialogRequest>;
|
|
7
|
+
} | undefined>;
|
|
8
|
+
export declare function openDialog(params: OpenDialogRequestParams): Promise<import("../types").BridgeError | OpenDialogRequest>;
|
|
9
|
+
export declare function closeDialog(params: CloseDialogRequestParams): Promise<import("../types").BridgeError | CloseDialogRequest>;
|
|
10
|
+
export declare function destroyDialog(params: DestroyDialogRequestParams): Promise<import("../types").BridgeError | DestroyDialogRequest>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
|
+
import { makeRequest } from "../messaging";
|
|
3
|
+
import { BridgeMethod } from "../types";
|
|
4
|
+
export async function createDialog(params) {
|
|
5
|
+
const request = {
|
|
6
|
+
id: uuidv4(),
|
|
7
|
+
method: BridgeMethod.CREATE_DIALOG,
|
|
8
|
+
params,
|
|
9
|
+
};
|
|
10
|
+
const result = await makeRequest(request);
|
|
11
|
+
if (!result) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
id: params.id,
|
|
16
|
+
open: async () => openDialog({ id: params.id }),
|
|
17
|
+
close: async () => closeDialog({ id: params.id }),
|
|
18
|
+
destroy: async () => destroyDialog({ id: params.id }),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export async function openDialog(params) {
|
|
22
|
+
const request = {
|
|
23
|
+
id: uuidv4(),
|
|
24
|
+
method: BridgeMethod.OPEN_DIALOG,
|
|
25
|
+
params,
|
|
26
|
+
};
|
|
27
|
+
return makeRequest(request);
|
|
28
|
+
}
|
|
29
|
+
export async function closeDialog(params) {
|
|
30
|
+
const request = {
|
|
31
|
+
id: uuidv4(),
|
|
32
|
+
method: BridgeMethod.CLOSE_DIALOG,
|
|
33
|
+
params,
|
|
34
|
+
};
|
|
35
|
+
return makeRequest(request);
|
|
36
|
+
}
|
|
37
|
+
export async function destroyDialog(params) {
|
|
38
|
+
const request = {
|
|
39
|
+
id: uuidv4(),
|
|
40
|
+
method: BridgeMethod.DESTROY_DIALOG,
|
|
41
|
+
params,
|
|
42
|
+
};
|
|
43
|
+
return makeRequest(request);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=dialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../src/dialog/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAYxC,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAiC;IAClE,MAAM,OAAO,GAAwB;QACnC,EAAE,EAAE,MAAM,EAA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1
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { BridgeMethod } from "../types";
|
|
2
|
+
import { closeDialog, createDialog, destroyDialog, openDialog } from "./dialog";
|
|
3
|
+
jest.mock("../messaging", () => {
|
|
4
|
+
const originalModule = jest.requireActual("../messaging");
|
|
5
|
+
return Object.assign(Object.assign({ __esModule: true }, originalModule), { makeRequest: async (request) => {
|
|
6
|
+
originalModule.makeRequest(request);
|
|
7
|
+
return true;
|
|
8
|
+
} });
|
|
9
|
+
});
|
|
10
|
+
describe("dialog", () => {
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
global.flipBridgeOptions = { hostAppOrigin: "http://localhost" };
|
|
13
|
+
});
|
|
14
|
+
test("'createDialog' sends correct request", async () => {
|
|
15
|
+
const params = {
|
|
16
|
+
hideLabel: false,
|
|
17
|
+
id: "my-dialog",
|
|
18
|
+
label: "My Dialog",
|
|
19
|
+
text: "Lorem ipsum",
|
|
20
|
+
intent: "critical",
|
|
21
|
+
primaryAction: {
|
|
22
|
+
label: "Primary",
|
|
23
|
+
},
|
|
24
|
+
secondaryAction: {
|
|
25
|
+
label: "Secondary",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const spy = jest.fn();
|
|
29
|
+
window.top.postMessage = spy;
|
|
30
|
+
const response = await createDialog(params);
|
|
31
|
+
expect(spy).toHaveBeenCalledWith({
|
|
32
|
+
id: spy.mock.calls[0][0].id,
|
|
33
|
+
method: BridgeMethod.CREATE_DIALOG,
|
|
34
|
+
params,
|
|
35
|
+
}, "http://localhost");
|
|
36
|
+
expect(response === null || response === void 0 ? void 0 : response.id).toBe(params.id);
|
|
37
|
+
expect(typeof (response === null || response === void 0 ? void 0 : response.close)).toBe("function");
|
|
38
|
+
expect(typeof (response === null || response === void 0 ? void 0 : response.open)).toBe("function");
|
|
39
|
+
});
|
|
40
|
+
test("'openDialog' sends correct request", async () => {
|
|
41
|
+
const params = {
|
|
42
|
+
id: "my-dialog",
|
|
43
|
+
};
|
|
44
|
+
const spy = jest.fn();
|
|
45
|
+
window.top.postMessage = spy;
|
|
46
|
+
const response = await openDialog(params);
|
|
47
|
+
expect(spy).toHaveBeenCalledWith({
|
|
48
|
+
id: spy.mock.calls[0][0].id,
|
|
49
|
+
method: BridgeMethod.OPEN_DIALOG,
|
|
50
|
+
params,
|
|
51
|
+
}, "http://localhost");
|
|
52
|
+
expect(response).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
test("'closeDialog' sends correct request", async () => {
|
|
55
|
+
const params = {
|
|
56
|
+
id: "my-dialog",
|
|
57
|
+
};
|
|
58
|
+
const spy = jest.fn();
|
|
59
|
+
window.top.postMessage = spy;
|
|
60
|
+
const response = await closeDialog(params);
|
|
61
|
+
expect(spy).toHaveBeenCalledWith({
|
|
62
|
+
id: spy.mock.calls[0][0].id,
|
|
63
|
+
method: BridgeMethod.CLOSE_DIALOG,
|
|
64
|
+
params,
|
|
65
|
+
}, "http://localhost");
|
|
66
|
+
expect(response).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
test("'destroyDialog' sends correct request", async () => {
|
|
69
|
+
const params = {
|
|
70
|
+
id: "my-dialog",
|
|
71
|
+
};
|
|
72
|
+
const spy = jest.fn();
|
|
73
|
+
window.top.postMessage = spy;
|
|
74
|
+
const response = await destroyDialog(params);
|
|
75
|
+
expect(spy).toHaveBeenCalledWith({
|
|
76
|
+
id: spy.mock.calls[0][0].id,
|
|
77
|
+
method: BridgeMethod.DESTROY_DIALOG,
|
|
78
|
+
params,
|
|
79
|
+
}, "http://localhost");
|
|
80
|
+
expect(response).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=dialog.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.spec.js","sourceRoot":"","sources":["../../src/dialog/dialog.spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE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AAG,GAAG,CAAC;QAEtC,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QAE3C,MAAM,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAC9B;YACE,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;YAC3B,MAAM,EAAE,YAAY,CAAC,YAAY;YACjC,MAAM;SACP,EACD,kBAAkB,CACnB,CAAC;QAEF,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;QACvD,MAAM,MAAM,GAA+B;YACzC,EAAE,EAAE,WAAW;SAChB,CAAC;QAEF,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;QAErB,MAAM,CAAC,GAAW,CAAC,WAAW,GAAG,GAAG,CAAC;QAEtC,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;QAE7C,MAAM,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAC9B;YACE,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;YAC3B,MAAM,EAAE,YAAY,CAAC,cAAc;YACnC,MAAM;SACP,EACD,kBAAkB,CACnB,CAAC;QAEF,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SwirlDialogIntent } from "@getflip/swirl-components/dist/types/components/swirl-dialog/swirl-dialog";
|
|
2
|
+
import { BridgeRequest } from "../messaging/messaging.types";
|
|
3
|
+
import { BridgeMethod } from "../types";
|
|
4
|
+
export type CreateDialogRequestParams = {
|
|
5
|
+
hideLabel?: boolean;
|
|
6
|
+
id: string;
|
|
7
|
+
intent?: SwirlDialogIntent;
|
|
8
|
+
label: string;
|
|
9
|
+
text: string;
|
|
10
|
+
primaryAction?: {
|
|
11
|
+
label: string;
|
|
12
|
+
};
|
|
13
|
+
secondaryAction?: {
|
|
14
|
+
label: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type OpenDialogRequestParams = {
|
|
18
|
+
id: string;
|
|
19
|
+
};
|
|
20
|
+
export type CloseDialogRequestParams = {
|
|
21
|
+
id: string;
|
|
22
|
+
};
|
|
23
|
+
export type DestroyDialogRequestParams = {
|
|
24
|
+
id: string;
|
|
25
|
+
};
|
|
26
|
+
export type CreateDialogRequest = BridgeRequest<BridgeMethod.CREATE_DIALOG, CreateDialogRequestParams>;
|
|
27
|
+
export type OpenDialogRequest = BridgeRequest<BridgeMethod.OPEN_DIALOG, OpenDialogRequestParams>;
|
|
28
|
+
export type CloseDialogRequest = BridgeRequest<BridgeMethod.CLOSE_DIALOG, CloseDialogRequestParams>;
|
|
29
|
+
export type DestroyDialogRequest = BridgeRequest<BridgeMethod.DESTROY_DIALOG, CloseDialogRequestParams>;
|
|
30
|
+
export type CreateDialogResult = boolean;
|
|
31
|
+
export type OpenDialogResult = boolean;
|
|
32
|
+
export type CloseDialogResult = boolean;
|
|
33
|
+
export type DestroyDialogResult = boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialog.types.js","sourceRoot":"","sources":["../../src/dialog/dialog.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dialog/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC"}
|
package/dist/events/events.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BridgeEvent, BridgeEventType, SubscribeOptions, UnsubscribeFunction } from "./events.types";
|
|
2
|
-
export declare function subscribe(type: BridgeEventType, callback: (event?: BridgeEvent) => void, options?: SubscribeOptions): Promise<UnsubscribeFunction>;
|
|
2
|
+
export declare function subscribe<EventDataType = unknown>(type: BridgeEventType, callback: (event?: BridgeEvent<EventDataType>) => void, options?: SubscribeOptions): Promise<UnsubscribeFunction>;
|
|
3
3
|
export declare function isEvent(message: Object): message is BridgeEvent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAEL,eAAe,GAOhB,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAqB,EACrB,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAEL,eAAe,GAOhB,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAqB,EACrB,QAAsD,EACtD,OAA0B;IAE1B,MAAM,cAAc,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,EAAE,KAAI,MAAM,EAAE,CAAC;IAE/C,MAAM,gBAAgB,GAAqB;QACzC,E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AC3B,MAAM,IAAI,OAAO;QACjB,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAuB,CAAC,CACzE,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { BridgeRequest } from "../messaging/messaging.types";
|
|
2
2
|
import { BridgeMethod } from "../types";
|
|
3
3
|
export declare enum BridgeEventType {
|
|
4
|
+
PRIMARY_ACTION_CLICK = "PRIMARY_ACTION_CLICK",
|
|
4
5
|
LANG_CHANGE = "LANG_CHANGE",
|
|
6
|
+
SECONDARY_ACTION_CLICK = "SECONDARY_ACTION_CLICK",
|
|
5
7
|
THEME_CHANGE = "THEME_CHANGE"
|
|
6
8
|
}
|
|
7
9
|
export type BridgeEvent<DataType = unknown> = {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export var BridgeEventType;
|
|
2
2
|
(function (BridgeEventType) {
|
|
3
|
+
BridgeEventType["PRIMARY_ACTION_CLICK"] = "PRIMARY_ACTION_CLICK";
|
|
3
4
|
BridgeEventType["LANG_CHANGE"] = "LANG_CHANGE";
|
|
5
|
+
BridgeEventType["SECONDARY_ACTION_CLICK"] = "SECONDARY_ACTION_CLICK";
|
|
4
6
|
BridgeEventType["THEME_CHANGE"] = "THEME_CHANGE";
|
|
5
7
|
})(BridgeEventType || (BridgeEventType = {}));
|
|
6
8
|
//# sourceMappingURL=events.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.types.js","sourceRoot":"","sources":["../../src/events/events.types.ts"],"names":[],"mappings":"AAGA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"events.types.js","sourceRoot":"","sources":["../../src/events/events.types.ts"],"names":[],"mappings":"AAGA,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,gEAA6C,CAAA;IAC7C,8CAA2B,CAAA;IAC3B,oEAAiD,CAAA;IACjD,gDAA6B,CAAA;AAC/B,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B"}
|