-
Notifications
You must be signed in to change notification settings - Fork 31
/
navigator.ts
71 lines (68 loc) · 2.05 KB
/
navigator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { NavigatorAPI, IdsAPI, NavigatorSlideInfo } from './types'
import { Channel } from './channel'
import { Signal } from './signal'
export default function createNavigator(channel: Channel, ids: IdsAPI): NavigatorAPI {
const _onSlideInSignal = new Signal<[NavigatorSlideInfo]>()
channel.addHandler('navigateSlideIn', (data: any) => {
_onSlideInSignal.dispatch(data)
})
return {
openEntry: (id, opts) => {
return channel.call('navigateToContentEntity', {
...opts,
entityType: 'Entry',
id,
}) as Promise<any>
},
openNewEntry: (contentTypeId: string, opts) => {
return channel.call('navigateToContentEntity', {
...opts,
entityType: 'Entry',
id: null,
contentTypeId,
}) as Promise<any>
},
openBulkEditor: (entryId: string, opts) => {
return channel.call('navigateToBulkEditor', {
entryId,
...opts,
}) as Promise<any>
},
openAsset: (id, opts) => {
return channel.call('navigateToContentEntity', {
...opts,
entityType: 'Asset',
id,
}) as Promise<any>
},
openNewAsset: (opts) => {
return channel.call('navigateToContentEntity', {
...opts,
entityType: 'Asset',
id: null,
}) as Promise<any>
},
openPageExtension: (opts) => {
return channel.call('navigateToPage', {
type: 'extension',
id: ids.extension,
...opts,
}) as Promise<any>
},
openCurrentAppPage: (opts) => {
return channel.call('navigateToPage', { type: 'app', id: ids.app, ...opts }) as Promise<any>
},
openAppConfig: () => {
return channel.call('navigateToAppConfig') as Promise<void>
},
openEntriesList: () => {
return channel.call('navigateToSpaceEnvRoute', { route: 'entries' }) as Promise<void>
},
openAssetsList: () => {
return channel.call('navigateToSpaceEnvRoute', { route: 'assets' }) as Promise<void>
},
onSlideInNavigation: (handler) => {
return _onSlideInSignal.attach(handler)
},
}
}