bb-relay 0.0.31 → 0.0.33
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/dist/{EventReturn-CGAZ-l1W.d.mts → RequestReturn-ClPSkigo.d.mts} +30 -12
- package/dist/{EventReturn-CXACStVQ.d.ts → RequestReturn-xCEiRgI1.d.ts} +30 -12
- package/dist/api.d.mts +10 -4
- package/dist/api.d.ts +10 -4
- package/dist/constant.d.mts +0 -1
- package/dist/constant.d.ts +0 -1
- package/dist/constant.js +1 -27
- package/dist/constant.mjs +0 -26
- package/dist/editor.d.mts +2 -4
- package/dist/editor.d.ts +2 -4
- package/dist/index.d.mts +10 -11
- package/dist/index.d.ts +10 -11
- package/dist/index.js +54 -57
- package/dist/index.mjs +53 -56
- package/dist/plugin.d.mts +22 -23
- package/dist/plugin.d.ts +22 -23
- package/dist/plugin.js +62 -38
- package/dist/plugin.mjs +61 -37
- package/package.json +2 -1
- package/src/api.ts +11 -1
- package/src/constant.ts +1 -9
- package/src/editor.ts +0 -2
- package/src/index.ts +5 -5
- package/src/lib/plugin/ElementInstruction/BaseInstruction.ts +2 -1
- package/src/lib/plugin/ElementInstruction/InputInstruction.ts +1 -1
- package/src/lib/plugin/ElementInstruction/ViewInstruction.ts +1 -4
- package/src/lib/plugin/index.ts +72 -48
- package/src/lib/validate-manifest/index.ts +3 -2
- package/src/relay/postEventResponse.ts +0 -2
- package/src/relay/postRequestResponse.ts +14 -0
- package/src/relay/registerRequest.ts +35 -0
- package/src/relay/request.ts +19 -0
- package/src/relay/subscribe.ts +17 -0
- package/src/types/api/EventParam.ts +0 -1
- package/src/types/api/EventReturn.ts +0 -2
- package/src/types/api/RelayEvent.ts +1 -7
- package/src/types/api/RequestParam.ts +10 -0
- package/src/types/api/RequestReturn.ts +9 -0
- package/src/types/editor/Load.ts +1 -2
- package/src/types/editor/Manifest.ts +1 -0
- package/src/types/editor/Settings.ts +1 -3
- package/dist/COLOR_LIST-BfSSBFUY.d.mts +0 -4
- package/dist/COLOR_LIST-BfSSBFUY.d.ts +0 -4
- package/src/constants/COLOR_LIST.ts +0 -27
- package/src/relay/index.ts +0 -61
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { F as FileContent } from './FileContent-BWulmcoi.mjs';
|
|
2
2
|
|
|
3
3
|
type Load = {
|
|
4
|
-
|
|
5
|
-
theme: "light" | "dark";
|
|
4
|
+
theme: string;
|
|
6
5
|
languages: string[];
|
|
7
6
|
};
|
|
8
7
|
|
|
@@ -11,7 +10,7 @@ type RelayEvent = {
|
|
|
11
10
|
* Indicate change in theme
|
|
12
11
|
*/
|
|
13
12
|
theme: {
|
|
14
|
-
response:
|
|
13
|
+
response: string;
|
|
15
14
|
};
|
|
16
15
|
/**
|
|
17
16
|
* Indicate that the iframe is loaded and ready to receive instructions
|
|
@@ -22,12 +21,6 @@ type RelayEvent = {
|
|
|
22
21
|
load: {
|
|
23
22
|
response: Load;
|
|
24
23
|
};
|
|
25
|
-
/**
|
|
26
|
-
* The style of the editor
|
|
27
|
-
*/
|
|
28
|
-
style: {
|
|
29
|
-
response: string;
|
|
30
|
-
};
|
|
31
24
|
/**
|
|
32
25
|
* The language of the editor
|
|
33
26
|
*/
|
|
@@ -55,8 +48,33 @@ type RelayEvent = {
|
|
|
55
48
|
interface EventReturn<K extends keyof RelayEvent> {
|
|
56
49
|
type: K;
|
|
57
50
|
response: RelayEvent[K]["response"];
|
|
58
|
-
responseId: string;
|
|
59
|
-
source: "event";
|
|
60
51
|
}
|
|
61
52
|
|
|
62
|
-
|
|
53
|
+
type RelayRequest = {
|
|
54
|
+
/**
|
|
55
|
+
* Updates the content of the current file
|
|
56
|
+
* Note, type is not stated, it would use the one stated in manifest
|
|
57
|
+
*/
|
|
58
|
+
update: {
|
|
59
|
+
args: {
|
|
60
|
+
content: string;
|
|
61
|
+
};
|
|
62
|
+
response: {
|
|
63
|
+
error: string | null;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
ping: {
|
|
67
|
+
args: unknown;
|
|
68
|
+
response: {
|
|
69
|
+
data: unknown | null;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
interface RequestReturn<K extends keyof RelayRequest> {
|
|
75
|
+
type: K;
|
|
76
|
+
response: RelayRequest[K]["response"];
|
|
77
|
+
id: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type { EventReturn as E, RelayEvent as R, RelayRequest as a, RequestReturn as b };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { F as FileContent } from './FileContent-BWulmcoi.js';
|
|
2
2
|
|
|
3
3
|
type Load = {
|
|
4
|
-
|
|
5
|
-
theme: "light" | "dark";
|
|
4
|
+
theme: string;
|
|
6
5
|
languages: string[];
|
|
7
6
|
};
|
|
8
7
|
|
|
@@ -11,7 +10,7 @@ type RelayEvent = {
|
|
|
11
10
|
* Indicate change in theme
|
|
12
11
|
*/
|
|
13
12
|
theme: {
|
|
14
|
-
response:
|
|
13
|
+
response: string;
|
|
15
14
|
};
|
|
16
15
|
/**
|
|
17
16
|
* Indicate that the iframe is loaded and ready to receive instructions
|
|
@@ -22,12 +21,6 @@ type RelayEvent = {
|
|
|
22
21
|
load: {
|
|
23
22
|
response: Load;
|
|
24
23
|
};
|
|
25
|
-
/**
|
|
26
|
-
* The style of the editor
|
|
27
|
-
*/
|
|
28
|
-
style: {
|
|
29
|
-
response: string;
|
|
30
|
-
};
|
|
31
24
|
/**
|
|
32
25
|
* The language of the editor
|
|
33
26
|
*/
|
|
@@ -55,8 +48,33 @@ type RelayEvent = {
|
|
|
55
48
|
interface EventReturn<K extends keyof RelayEvent> {
|
|
56
49
|
type: K;
|
|
57
50
|
response: RelayEvent[K]["response"];
|
|
58
|
-
responseId: string;
|
|
59
|
-
source: "event";
|
|
60
51
|
}
|
|
61
52
|
|
|
62
|
-
|
|
53
|
+
type RelayRequest = {
|
|
54
|
+
/**
|
|
55
|
+
* Updates the content of the current file
|
|
56
|
+
* Note, type is not stated, it would use the one stated in manifest
|
|
57
|
+
*/
|
|
58
|
+
update: {
|
|
59
|
+
args: {
|
|
60
|
+
content: string;
|
|
61
|
+
};
|
|
62
|
+
response: {
|
|
63
|
+
error: string | null;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
ping: {
|
|
67
|
+
args: unknown;
|
|
68
|
+
response: {
|
|
69
|
+
data: unknown | null;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
interface RequestReturn<K extends keyof RelayRequest> {
|
|
75
|
+
type: K;
|
|
76
|
+
response: RelayRequest[K]["response"];
|
|
77
|
+
id: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type { EventReturn as E, RelayEvent as R, RelayRequest as a, RequestReturn as b };
|
package/dist/api.d.mts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { R as RelayEvent } from './
|
|
2
|
-
export { E as EventReturn } from './
|
|
1
|
+
import { R as RelayEvent, a as RelayRequest } from './RequestReturn-ClPSkigo.mjs';
|
|
2
|
+
export { E as EventReturn, b as RequestReturn } from './RequestReturn-ClPSkigo.mjs';
|
|
3
3
|
import './FileContent-BWulmcoi.mjs';
|
|
4
4
|
|
|
5
5
|
type EventParam<K extends keyof RelayEvent> = {
|
|
6
|
-
id: string;
|
|
7
6
|
type: K;
|
|
8
7
|
source: "event";
|
|
9
8
|
};
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
type RequestParam<K extends keyof RelayRequest> = {
|
|
11
|
+
type: K;
|
|
12
|
+
source: "request";
|
|
13
|
+
id: string;
|
|
14
|
+
arg: RelayRequest[K]["args"];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { type EventParam, RelayEvent, RelayRequest, type RequestParam };
|
package/dist/api.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { R as RelayEvent } from './
|
|
2
|
-
export { E as EventReturn } from './
|
|
1
|
+
import { R as RelayEvent, a as RelayRequest } from './RequestReturn-xCEiRgI1.js';
|
|
2
|
+
export { E as EventReturn, b as RequestReturn } from './RequestReturn-xCEiRgI1.js';
|
|
3
3
|
import './FileContent-BWulmcoi.js';
|
|
4
4
|
|
|
5
5
|
type EventParam<K extends keyof RelayEvent> = {
|
|
6
|
-
id: string;
|
|
7
6
|
type: K;
|
|
8
7
|
source: "event";
|
|
9
8
|
};
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
type RequestParam<K extends keyof RelayRequest> = {
|
|
11
|
+
type: K;
|
|
12
|
+
source: "request";
|
|
13
|
+
id: string;
|
|
14
|
+
arg: RelayRequest[K]["args"];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { type EventParam, RelayEvent, RelayRequest, type RequestParam };
|
package/dist/constant.d.mts
CHANGED
package/dist/constant.d.ts
CHANGED
package/dist/constant.js
CHANGED
|
@@ -45,35 +45,9 @@ var PROJECT_CATEGORY = [
|
|
|
45
45
|
];
|
|
46
46
|
var PROJECT_CATEGORY_default = PROJECT_CATEGORY;
|
|
47
47
|
|
|
48
|
-
// src/constants/COLOR_LIST.ts
|
|
49
|
-
var COLOR_LIST = [
|
|
50
|
-
"red",
|
|
51
|
-
"slate",
|
|
52
|
-
"stone",
|
|
53
|
-
"zinc",
|
|
54
|
-
"gray",
|
|
55
|
-
"orange",
|
|
56
|
-
"amber",
|
|
57
|
-
"yellow",
|
|
58
|
-
"lime",
|
|
59
|
-
"green",
|
|
60
|
-
"emerald",
|
|
61
|
-
"teal",
|
|
62
|
-
"cyan",
|
|
63
|
-
"sky",
|
|
64
|
-
"blue",
|
|
65
|
-
"indigo",
|
|
66
|
-
"violet",
|
|
67
|
-
"purple",
|
|
68
|
-
"fuchsia",
|
|
69
|
-
"pink",
|
|
70
|
-
"rose"
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
|
|
74
48
|
|
|
75
49
|
|
|
76
50
|
|
|
77
51
|
|
|
78
52
|
|
|
79
|
-
exports.
|
|
53
|
+
exports.DATA_ALIAS = DATA_ALIAS; exports.PLUGIN_URL = PLUGIN_URL_default; exports.PROJECT_CATEGORY = PROJECT_CATEGORY_default; exports.SENTINEL_FILE = SENTINEL_FILE_default; exports.WEBSITE = WEBSITE_default;
|
package/dist/constant.mjs
CHANGED
|
@@ -44,33 +44,7 @@ var PROJECT_CATEGORY = [
|
|
|
44
44
|
"Other"
|
|
45
45
|
];
|
|
46
46
|
var PROJECT_CATEGORY_default = PROJECT_CATEGORY;
|
|
47
|
-
|
|
48
|
-
// src/constants/COLOR_LIST.ts
|
|
49
|
-
var COLOR_LIST = [
|
|
50
|
-
"red",
|
|
51
|
-
"slate",
|
|
52
|
-
"stone",
|
|
53
|
-
"zinc",
|
|
54
|
-
"gray",
|
|
55
|
-
"orange",
|
|
56
|
-
"amber",
|
|
57
|
-
"yellow",
|
|
58
|
-
"lime",
|
|
59
|
-
"green",
|
|
60
|
-
"emerald",
|
|
61
|
-
"teal",
|
|
62
|
-
"cyan",
|
|
63
|
-
"sky",
|
|
64
|
-
"blue",
|
|
65
|
-
"indigo",
|
|
66
|
-
"violet",
|
|
67
|
-
"purple",
|
|
68
|
-
"fuchsia",
|
|
69
|
-
"pink",
|
|
70
|
-
"rose"
|
|
71
|
-
];
|
|
72
47
|
export {
|
|
73
|
-
COLOR_LIST,
|
|
74
48
|
DATA_ALIAS,
|
|
75
49
|
PLUGIN_URL_default as PLUGIN_URL,
|
|
76
50
|
PROJECT_CATEGORY_default as PROJECT_CATEGORY,
|
package/dist/editor.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ export { C as Commit } from './Commit-PdsjrKSG.mjs';
|
|
|
2
2
|
export { a as FileStat, F as FolderContent, b as FolderStat } from './FolderStat-Bhmwwc0t.mjs';
|
|
3
3
|
export { F as FileContent } from './FileContent-BWulmcoi.mjs';
|
|
4
4
|
import { L as Language, a as Locale } from './Locale-DvFwr_9k.mjs';
|
|
5
|
-
import { a as Color } from './COLOR_LIST-BfSSBFUY.mjs';
|
|
6
5
|
export { R as Result } from './Result-BLbZLEgX.mjs';
|
|
7
6
|
|
|
8
7
|
type CopyArg = {
|
|
@@ -44,7 +43,6 @@ type Shortcut = {
|
|
|
44
43
|
keys: string[];
|
|
45
44
|
};
|
|
46
45
|
type Settings = {
|
|
47
|
-
theme: "light" | "dark" | "system";
|
|
48
46
|
language?: Locale;
|
|
49
47
|
sidebarWidth: number;
|
|
50
48
|
baseAppFont: number;
|
|
@@ -53,7 +51,7 @@ type Settings = {
|
|
|
53
51
|
showAllFile: boolean;
|
|
54
52
|
trashBehaviour: "permanent" | "trash";
|
|
55
53
|
shortcuts: Shortcut[];
|
|
56
|
-
|
|
54
|
+
theme: string;
|
|
57
55
|
/**
|
|
58
56
|
* { [fileExtension: string]: pluginId }
|
|
59
57
|
*/
|
|
@@ -73,4 +71,4 @@ interface TutorialHeader {
|
|
|
73
71
|
|
|
74
72
|
type WatchFSEvent = "updated" | "deleted" | "updated" | "add";
|
|
75
73
|
|
|
76
|
-
export {
|
|
74
|
+
export type { CopyArg, GitFileStatus, IconArg, MenuContent, Nav, Route, Settings, Shortcut, TutorialHeader, WatchFSEvent };
|
package/dist/editor.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export { C as Commit } from './Commit-PdsjrKSG.js';
|
|
|
2
2
|
export { a as FileStat, F as FolderContent, b as FolderStat } from './FolderStat-Bhmwwc0t.js';
|
|
3
3
|
export { F as FileContent } from './FileContent-BWulmcoi.js';
|
|
4
4
|
import { L as Language, a as Locale } from './Locale-DvFwr_9k.js';
|
|
5
|
-
import { a as Color } from './COLOR_LIST-BfSSBFUY.js';
|
|
6
5
|
export { R as Result } from './Result-BLbZLEgX.js';
|
|
7
6
|
|
|
8
7
|
type CopyArg = {
|
|
@@ -44,7 +43,6 @@ type Shortcut = {
|
|
|
44
43
|
keys: string[];
|
|
45
44
|
};
|
|
46
45
|
type Settings = {
|
|
47
|
-
theme: "light" | "dark" | "system";
|
|
48
46
|
language?: Locale;
|
|
49
47
|
sidebarWidth: number;
|
|
50
48
|
baseAppFont: number;
|
|
@@ -53,7 +51,7 @@ type Settings = {
|
|
|
53
51
|
showAllFile: boolean;
|
|
54
52
|
trashBehaviour: "permanent" | "trash";
|
|
55
53
|
shortcuts: Shortcut[];
|
|
56
|
-
|
|
54
|
+
theme: string;
|
|
57
55
|
/**
|
|
58
56
|
* { [fileExtension: string]: pluginId }
|
|
59
57
|
*/
|
|
@@ -73,4 +71,4 @@ interface TutorialHeader {
|
|
|
73
71
|
|
|
74
72
|
type WatchFSEvent = "updated" | "deleted" | "updated" | "add";
|
|
75
73
|
|
|
76
|
-
export {
|
|
74
|
+
export type { CopyArg, GitFileStatus, IconArg, MenuContent, Nav, Route, Settings, Shortcut, TutorialHeader, WatchFSEvent };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { R as RelayEvent, E as EventReturn } from './EventReturn-CGAZ-l1W.mjs';
|
|
2
1
|
import { F as FileContent } from './FileContent-BWulmcoi.mjs';
|
|
3
2
|
export { R as Result } from './Result-BLbZLEgX.mjs';
|
|
4
3
|
import { P as Plugin } from './Plugin-Db_XUKx0.mjs';
|
|
4
|
+
import { R as RelayEvent, E as EventReturn, a as RelayRequest, b as RequestReturn } from './RequestReturn-ClPSkigo.mjs';
|
|
5
5
|
import './Wrapper-DWhYVa7F.mjs';
|
|
6
6
|
|
|
7
|
-
declare class Relay {
|
|
8
|
-
private eventCallbacks;
|
|
9
|
-
handleEvent<K extends keyof RelayEvent>(data: EventReturn<K>): void;
|
|
10
|
-
init: () => void;
|
|
11
|
-
constructor();
|
|
12
|
-
subscribe<K extends keyof RelayEvent>(type: K, callback: (response: RelayEvent[K]["response"]) => void): () => void;
|
|
13
|
-
destroy(): void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
7
|
/**
|
|
17
8
|
* This is the function to inject styles to the iframe from the parent window
|
|
18
9
|
* @param css the css styles from parent window
|
|
@@ -43,6 +34,7 @@ type Manifest = {
|
|
|
43
34
|
author?: string;
|
|
44
35
|
homepage?: string;
|
|
45
36
|
repository?: string;
|
|
37
|
+
theme?: string;
|
|
46
38
|
[key: string]: unknown;
|
|
47
39
|
};
|
|
48
40
|
|
|
@@ -74,4 +66,11 @@ declare function validateUpload(manifest: Manifest, plugin: Plugin["doc"]): bool
|
|
|
74
66
|
type BBEventKey = keyof RelayEvent;
|
|
75
67
|
declare function postEventResponse<K extends BBEventKey>(window: Window, response: Omit<EventReturn<K>, "source" | "responseId">): void;
|
|
76
68
|
|
|
77
|
-
|
|
69
|
+
declare function subscribe<K extends keyof RelayEvent>(type: K, callback: (response: RelayEvent[K]["response"]) => void): void;
|
|
70
|
+
|
|
71
|
+
type BBRequestKey = keyof RelayRequest;
|
|
72
|
+
declare function postRequestResponse<K extends BBRequestKey>(window: Window, response: RequestReturn<K>): void;
|
|
73
|
+
|
|
74
|
+
declare function request<K extends keyof RelayRequest>(type: K, arg: RelayRequest[K]["args"], callback?: (response: RelayRequest[K]["response"]) => void): void;
|
|
75
|
+
|
|
76
|
+
export { type FileNode, type Manifest, type Zip, extractStyles, injectStyles, postEventResponse, postRequestResponse, request, subscribe, validateManifest, validateUpload };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { R as RelayEvent, E as EventReturn } from './EventReturn-CXACStVQ.js';
|
|
2
1
|
import { F as FileContent } from './FileContent-BWulmcoi.js';
|
|
3
2
|
export { R as Result } from './Result-BLbZLEgX.js';
|
|
4
3
|
import { P as Plugin } from './Plugin-t8StCIag.js';
|
|
4
|
+
import { R as RelayEvent, E as EventReturn, a as RelayRequest, b as RequestReturn } from './RequestReturn-xCEiRgI1.js';
|
|
5
5
|
import './Wrapper-DWhYVa7F.js';
|
|
6
6
|
|
|
7
|
-
declare class Relay {
|
|
8
|
-
private eventCallbacks;
|
|
9
|
-
handleEvent<K extends keyof RelayEvent>(data: EventReturn<K>): void;
|
|
10
|
-
init: () => void;
|
|
11
|
-
constructor();
|
|
12
|
-
subscribe<K extends keyof RelayEvent>(type: K, callback: (response: RelayEvent[K]["response"]) => void): () => void;
|
|
13
|
-
destroy(): void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
7
|
/**
|
|
17
8
|
* This is the function to inject styles to the iframe from the parent window
|
|
18
9
|
* @param css the css styles from parent window
|
|
@@ -43,6 +34,7 @@ type Manifest = {
|
|
|
43
34
|
author?: string;
|
|
44
35
|
homepage?: string;
|
|
45
36
|
repository?: string;
|
|
37
|
+
theme?: string;
|
|
46
38
|
[key: string]: unknown;
|
|
47
39
|
};
|
|
48
40
|
|
|
@@ -74,4 +66,11 @@ declare function validateUpload(manifest: Manifest, plugin: Plugin["doc"]): bool
|
|
|
74
66
|
type BBEventKey = keyof RelayEvent;
|
|
75
67
|
declare function postEventResponse<K extends BBEventKey>(window: Window, response: Omit<EventReturn<K>, "source" | "responseId">): void;
|
|
76
68
|
|
|
77
|
-
|
|
69
|
+
declare function subscribe<K extends keyof RelayEvent>(type: K, callback: (response: RelayEvent[K]["response"]) => void): void;
|
|
70
|
+
|
|
71
|
+
type BBRequestKey = keyof RelayRequest;
|
|
72
|
+
declare function postRequestResponse<K extends BBRequestKey>(window: Window, response: RequestReturn<K>): void;
|
|
73
|
+
|
|
74
|
+
declare function request<K extends keyof RelayRequest>(type: K, arg: RelayRequest[K]["args"], callback?: (response: RelayRequest[K]["response"]) => void): void;
|
|
75
|
+
|
|
76
|
+
export { type FileNode, type Manifest, type Zip, extractStyles, injectStyles, postEventResponse, postRequestResponse, request, subscribe, validateManifest, validateUpload };
|
package/dist/index.js
CHANGED
|
@@ -1,52 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
2
|
-
function registerEvent(event) {
|
|
3
|
-
if (!window) throw new Error("Window not found");
|
|
4
|
-
if (window === window.parent) throw new Error("No parent window available");
|
|
5
|
-
window.parent.postMessage({ ...event, source: "event" }, "*");
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// src/relay/index.ts
|
|
9
|
-
var Relay = class {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.eventCallbacks = /* @__PURE__ */ new Map();
|
|
12
|
-
this.init = () => {
|
|
13
|
-
window.addEventListener("message", (event) => {
|
|
14
|
-
this.handleEvent(event.data);
|
|
15
|
-
});
|
|
16
|
-
window.addEventListener("unload", () => {
|
|
17
|
-
this.destroy();
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
this.init();
|
|
21
|
-
}
|
|
22
|
-
handleEvent(data) {
|
|
23
|
-
if (data.source !== "event") return;
|
|
24
|
-
for (const [, { type, callback }] of this.eventCallbacks) {
|
|
25
|
-
const { response } = data;
|
|
26
|
-
if (type === data.type) {
|
|
27
|
-
callback(response);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
subscribe(type, callback) {
|
|
33
|
-
const id = crypto.randomUUID();
|
|
34
|
-
this.eventCallbacks.set(id, {
|
|
35
|
-
type,
|
|
36
|
-
callback
|
|
37
|
-
});
|
|
38
|
-
registerEvent({ type, id, source: "event" });
|
|
39
|
-
return () => {
|
|
40
|
-
this.eventCallbacks.delete(id);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
destroy() {
|
|
44
|
-
this.eventCallbacks.clear();
|
|
45
|
-
window.removeEventListener("message", this.init);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// src/utils/inject-styles.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/utils/inject-styles.ts
|
|
50
2
|
function injectStyles(css) {
|
|
51
3
|
const style = document.createElement("style");
|
|
52
4
|
style.textContent = css;
|
|
@@ -80,8 +32,6 @@ var validateManifest = (manifestContent) => {
|
|
|
80
32
|
errors.push("Manifest permissions is missing");
|
|
81
33
|
} else if (!Array.isArray(content.permissions)) {
|
|
82
34
|
errors.push("Manifest permissions is not an array");
|
|
83
|
-
} else if (content.permissions.length === 0) {
|
|
84
|
-
errors.push("Manifest permissions is empty");
|
|
85
35
|
}
|
|
86
36
|
if (content.main) {
|
|
87
37
|
if (!content.main.path) {
|
|
@@ -115,6 +65,9 @@ var validateManifest = (manifestContent) => {
|
|
|
115
65
|
errors.push("Manifest entry must be a js file");
|
|
116
66
|
} else fileChecks.push(content.entry);
|
|
117
67
|
}
|
|
68
|
+
if (content.theme) {
|
|
69
|
+
fileChecks.push(content.theme);
|
|
70
|
+
}
|
|
118
71
|
return {
|
|
119
72
|
errors,
|
|
120
73
|
fileChecks,
|
|
@@ -152,15 +105,59 @@ function validateUpload(manifest, plugin) {
|
|
|
152
105
|
// src/relay/postEventResponse.ts
|
|
153
106
|
function postEventResponse(window2, response) {
|
|
154
107
|
const res = {
|
|
155
|
-
...response
|
|
156
|
-
source: "event",
|
|
157
|
-
responseId: crypto.randomUUID()
|
|
108
|
+
...response
|
|
158
109
|
};
|
|
159
110
|
window2.postMessage(res, "*");
|
|
160
111
|
}
|
|
161
112
|
|
|
162
|
-
// src/
|
|
163
|
-
|
|
113
|
+
// src/relay/registerEvent.ts
|
|
114
|
+
function registerEvent(event) {
|
|
115
|
+
if (!window) throw new Error("Window not found");
|
|
116
|
+
if (window === window.parent) throw new Error("No parent window available");
|
|
117
|
+
window.parent.postMessage({ ...event, source: "event" }, "*");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/relay/subscribe.ts
|
|
121
|
+
function subscribe(type, callback) {
|
|
122
|
+
registerEvent({ type, source: "event" });
|
|
123
|
+
window.addEventListener("message", (ev) => {
|
|
124
|
+
const data = ev.data;
|
|
125
|
+
const { response } = data;
|
|
126
|
+
if (type === data.type) {
|
|
127
|
+
callback(response);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/relay/postRequestResponse.ts
|
|
133
|
+
function postRequestResponse(window2, response) {
|
|
134
|
+
const res = {
|
|
135
|
+
...response
|
|
136
|
+
};
|
|
137
|
+
window2.postMessage(res, "*");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/relay/registerRequest.ts
|
|
141
|
+
function registerRequest(request2) {
|
|
142
|
+
if (!window) throw new Error("Window not found");
|
|
143
|
+
if (window === window.parent) throw new Error("No parent window available");
|
|
144
|
+
window.parent.postMessage({ ...request2, source: "request" }, "*");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/relay/request.ts
|
|
148
|
+
function request(type, arg, callback) {
|
|
149
|
+
const id = crypto.randomUUID();
|
|
150
|
+
registerRequest({ type, id, arg, source: "request" });
|
|
151
|
+
window.addEventListener("message", (ev) => {
|
|
152
|
+
const data = ev.data;
|
|
153
|
+
const { response } = data;
|
|
154
|
+
if (type === data.type && id === data.id) {
|
|
155
|
+
_optionalChain([callback, 'optionalCall', _ => _(response)]);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
164
161
|
|
|
165
162
|
|
|
166
163
|
|
|
@@ -168,4 +165,4 @@ var index_default = Relay;
|
|
|
168
165
|
|
|
169
166
|
|
|
170
167
|
|
|
171
|
-
exports.
|
|
168
|
+
exports.extractStyles = extract_styles_default; exports.injectStyles = injectStyles; exports.postEventResponse = postEventResponse; exports.postRequestResponse = postRequestResponse; exports.request = request; exports.subscribe = subscribe; exports.validateManifest = validate_manifest_default; exports.validateUpload = validateUpload;
|