bb-relay 0.0.40 → 0.0.42

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/editor.d.mts CHANGED
@@ -71,6 +71,6 @@ interface TutorialHeader {
71
71
  body: string;
72
72
  }
73
73
 
74
- type WatchFSEvent = "updated" | "deleted" | "updated" | "add";
74
+ type WatchFSEvent = "updated" | "deleted" | "add";
75
75
 
76
76
  export type { CopyArg, GitFileStatus, IconArg, MenuContent, Nav, Route, Settings, Shortcut, TutorialHeader, WatchFSEvent };
package/dist/editor.d.ts CHANGED
@@ -71,6 +71,6 @@ interface TutorialHeader {
71
71
  body: string;
72
72
  }
73
73
 
74
- type WatchFSEvent = "updated" | "deleted" | "updated" | "add";
74
+ type WatchFSEvent = "updated" | "deleted" | "add";
75
75
 
76
76
  export type { CopyArg, GitFileStatus, IconArg, MenuContent, Nav, Route, Settings, Shortcut, TutorialHeader, WatchFSEvent };
package/dist/index.d.mts CHANGED
@@ -11,7 +11,7 @@ import './Wrapper-DWhYVa7F.mjs';
11
11
  */
12
12
  declare function injectStyles(css: string): () => void;
13
13
 
14
- type Permission = "file-system" | "storage" | "project" | "url" | "selection" | "git" | "token";
14
+ type Permission = "file-system" | "project" | "git" | "dialog";
15
15
  type Manifest = {
16
16
  id: string;
17
17
  name: string;
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ import './Wrapper-DWhYVa7F.js';
11
11
  */
12
12
  declare function injectStyles(css: string): () => void;
13
13
 
14
- type Permission = "file-system" | "storage" | "project" | "url" | "selection" | "git" | "token";
14
+ type Permission = "file-system" | "project" | "git" | "dialog";
15
15
  type Manifest = {
16
16
  id: string;
17
17
  name: string;
package/dist/plugin.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { CSSProperties } from 'react';
1
+ import { CSSProperties, InputHTMLAttributes } from 'react';
2
2
  import { IconName } from 'lucide-react/dynamic';
3
3
  import { F as FolderContent, b as FolderStat, a as FileStat } from './FolderStat-Bhmwwc0t.mjs';
4
4
  import { F as FileContent } from './FileContent-CXlulSZq.mjs';
@@ -163,6 +163,41 @@ type RenderStatusType = {
163
163
  onClick?: () => void;
164
164
  };
165
165
 
166
+ type Primitive = string | number;
167
+ type InputOverlay = {
168
+ type: "input";
169
+ inputType?: InputHTMLAttributes<HTMLInputElement>["type"];
170
+ name: string;
171
+ };
172
+ type CheckboxOverlay = {
173
+ type: "checkbox";
174
+ name: string;
175
+ options: Primitive[];
176
+ };
177
+ type RadioOverlay = {
178
+ type: "radio";
179
+ name: string;
180
+ options: Primitive[];
181
+ };
182
+ type TextAreaOverlay = {
183
+ type: "textarea";
184
+ name: string;
185
+ };
186
+ type SubmitOverlay = {
187
+ type: "submit";
188
+ text: string;
189
+ };
190
+ type TextOverlay = {
191
+ type: "text";
192
+ content: string;
193
+ };
194
+ type ContainerOverlay = {
195
+ type: "container";
196
+ children: OverlayType[];
197
+ style?: CSSProperties;
198
+ };
199
+ type OverlayType = InputOverlay | RadioOverlay | CheckboxOverlay | SubmitOverlay | TextAreaOverlay | TextOverlay | ContainerOverlay;
200
+
166
201
  type Store<T extends Record<string, unknown>> = {
167
202
  get(): T;
168
203
  set(next: SetState<T>): void;
@@ -185,7 +220,61 @@ type EditorAPI = {
185
220
  copyFile: (filePath: string, destination: string) => Promise<Result<string>>;
186
221
  listFiles: (glob?: string) => Promise<Result<string[]>>;
187
222
  };
223
+ git?: {
224
+ commit: (arg: {
225
+ files: string[];
226
+ message: string;
227
+ email?: string;
228
+ }) => Promise<Result>;
229
+ };
230
+ dialog?: {
231
+ selectFile: () => Promise<Result<string[]>>;
232
+ selectFolder: () => Promise<Result<string[]>>;
233
+ };
234
+ project?: {
235
+ /**
236
+ * To create a new project
237
+ * @param dir This should be derived from `dialog.selectFolder`
238
+ * @param project The project config that you want to create
239
+ */
240
+ createProject: (dir: string, project: Project["insert"]) => Promise<Result>;
241
+ /**
242
+ * Use this to update current project information
243
+ * @param project
244
+ * @returns
245
+ */
246
+ updateProject: (project: Project["update"]) => Promise<Result>;
247
+ };
248
+ };
249
+ type EventMap = {
250
+ project: {
251
+ /**
252
+ * changed: indicates a different project is selected (change in working directory)
253
+ * created: a new project
254
+ */
255
+ type: "changed" | "created";
256
+ project: Project["insert"] & {
257
+ id?: string;
258
+ };
259
+ };
260
+ file: {
261
+ /**
262
+ * Indicates a file is created, updated, selected or deleted
263
+ * It will only return "null" for selected, if selected is not a file
264
+ * Git refers to file being selected in git mode
265
+ */
266
+ type: "created" | "updated" | "selected" | "deleted" | "git";
267
+ filePath: string | null;
268
+ };
269
+ ping: {
270
+ /**
271
+ * Indicates the source of the ping
272
+ */
273
+ type: "main" | "overlay";
274
+ payload: unknown;
275
+ };
188
276
  };
277
+ type EventSubs = keyof EventMap;
189
278
  type SetState<T extends Record<string, unknown>> = Partial<T> | ((arg: T) => T);
190
279
  declare abstract class Plugin<T extends Record<string, unknown>> {
191
280
  /** CONSTANTS */
@@ -260,7 +349,7 @@ declare abstract class Plugin<T extends Record<string, unknown>> {
260
349
  * So all you need to do is use form inputs for the part that you want to get
261
350
  * back as response
262
351
  */
263
- protected renderOverlay(overlay: ElementInstruction): void;
352
+ protected renderOverlay(overlay: OverlayType): void;
264
353
  protected onOverlayResponse(callback: (arg: unknown) => void): void;
265
354
  destroy(): void;
266
355
  private getPluginChannel;
@@ -268,19 +357,7 @@ declare abstract class Plugin<T extends Record<string, unknown>> {
268
357
  private unregisterHandler;
269
358
  private registerSubscription;
270
359
  protected off(event: string): void;
271
- protected on(event: "project-selected", callback: (arg: Project["insert"] & {
272
- workingDir: string;
273
- id?: string;
274
- }) => void): void;
275
- protected on(event: "new-project", callback: (arg: Project["insert"] & {
276
- workingDir: string;
277
- id?: string;
278
- }) => void): void;
279
- protected on(event: "file-selected", callback: (filePath: string | null) => void): void;
280
- protected on(event: "file-created", callback: (filePath: string) => void): void;
281
- protected on(event: "file-changed", callback: (filePath: string) => void): void;
282
- protected on(event: "file-deleted", callback: (filePath: string) => void): void;
283
- protected on(event: "ping", callback: (arg: unknown) => void): void;
360
+ protected on<K extends EventSubs>(event: K, callback: (res: EventMap[K] | null) => void): void;
284
361
  renderStatusBar?(): RenderStatusType | null;
285
362
  private registerStatus;
286
363
  protected setState(param: SetState<T>): void;
@@ -297,4 +374,4 @@ type Message = {
297
374
 
298
375
  declare const getPluginChannel: (event: string, pluginId: string) => string;
299
376
 
300
- export { type EditorAPI, type ElementInstruction, type InputInstruction, type Message, type PluginElement, type RenderStatusType, type SetState, type Store, type TextVariant, type TextareaInstruction, Plugin as default, getPluginChannel };
377
+ export { type EditorAPI, type ElementInstruction, type EventMap, type InputInstruction, type Message, type OverlayType, type PluginElement, type RenderStatusType, type SetState, type Store, type TextVariant, type TextareaInstruction, Plugin as default, getPluginChannel };
package/dist/plugin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CSSProperties } from 'react';
1
+ import { CSSProperties, InputHTMLAttributes } from 'react';
2
2
  import { IconName } from 'lucide-react/dynamic';
3
3
  import { F as FolderContent, b as FolderStat, a as FileStat } from './FolderStat-Bhmwwc0t.js';
4
4
  import { F as FileContent } from './FileContent-CXlulSZq.js';
@@ -163,6 +163,41 @@ type RenderStatusType = {
163
163
  onClick?: () => void;
164
164
  };
165
165
 
166
+ type Primitive = string | number;
167
+ type InputOverlay = {
168
+ type: "input";
169
+ inputType?: InputHTMLAttributes<HTMLInputElement>["type"];
170
+ name: string;
171
+ };
172
+ type CheckboxOverlay = {
173
+ type: "checkbox";
174
+ name: string;
175
+ options: Primitive[];
176
+ };
177
+ type RadioOverlay = {
178
+ type: "radio";
179
+ name: string;
180
+ options: Primitive[];
181
+ };
182
+ type TextAreaOverlay = {
183
+ type: "textarea";
184
+ name: string;
185
+ };
186
+ type SubmitOverlay = {
187
+ type: "submit";
188
+ text: string;
189
+ };
190
+ type TextOverlay = {
191
+ type: "text";
192
+ content: string;
193
+ };
194
+ type ContainerOverlay = {
195
+ type: "container";
196
+ children: OverlayType[];
197
+ style?: CSSProperties;
198
+ };
199
+ type OverlayType = InputOverlay | RadioOverlay | CheckboxOverlay | SubmitOverlay | TextAreaOverlay | TextOverlay | ContainerOverlay;
200
+
166
201
  type Store<T extends Record<string, unknown>> = {
167
202
  get(): T;
168
203
  set(next: SetState<T>): void;
@@ -185,7 +220,61 @@ type EditorAPI = {
185
220
  copyFile: (filePath: string, destination: string) => Promise<Result<string>>;
186
221
  listFiles: (glob?: string) => Promise<Result<string[]>>;
187
222
  };
223
+ git?: {
224
+ commit: (arg: {
225
+ files: string[];
226
+ message: string;
227
+ email?: string;
228
+ }) => Promise<Result>;
229
+ };
230
+ dialog?: {
231
+ selectFile: () => Promise<Result<string[]>>;
232
+ selectFolder: () => Promise<Result<string[]>>;
233
+ };
234
+ project?: {
235
+ /**
236
+ * To create a new project
237
+ * @param dir This should be derived from `dialog.selectFolder`
238
+ * @param project The project config that you want to create
239
+ */
240
+ createProject: (dir: string, project: Project["insert"]) => Promise<Result>;
241
+ /**
242
+ * Use this to update current project information
243
+ * @param project
244
+ * @returns
245
+ */
246
+ updateProject: (project: Project["update"]) => Promise<Result>;
247
+ };
248
+ };
249
+ type EventMap = {
250
+ project: {
251
+ /**
252
+ * changed: indicates a different project is selected (change in working directory)
253
+ * created: a new project
254
+ */
255
+ type: "changed" | "created";
256
+ project: Project["insert"] & {
257
+ id?: string;
258
+ };
259
+ };
260
+ file: {
261
+ /**
262
+ * Indicates a file is created, updated, selected or deleted
263
+ * It will only return "null" for selected, if selected is not a file
264
+ * Git refers to file being selected in git mode
265
+ */
266
+ type: "created" | "updated" | "selected" | "deleted" | "git";
267
+ filePath: string | null;
268
+ };
269
+ ping: {
270
+ /**
271
+ * Indicates the source of the ping
272
+ */
273
+ type: "main" | "overlay";
274
+ payload: unknown;
275
+ };
188
276
  };
277
+ type EventSubs = keyof EventMap;
189
278
  type SetState<T extends Record<string, unknown>> = Partial<T> | ((arg: T) => T);
190
279
  declare abstract class Plugin<T extends Record<string, unknown>> {
191
280
  /** CONSTANTS */
@@ -260,7 +349,7 @@ declare abstract class Plugin<T extends Record<string, unknown>> {
260
349
  * So all you need to do is use form inputs for the part that you want to get
261
350
  * back as response
262
351
  */
263
- protected renderOverlay(overlay: ElementInstruction): void;
352
+ protected renderOverlay(overlay: OverlayType): void;
264
353
  protected onOverlayResponse(callback: (arg: unknown) => void): void;
265
354
  destroy(): void;
266
355
  private getPluginChannel;
@@ -268,19 +357,7 @@ declare abstract class Plugin<T extends Record<string, unknown>> {
268
357
  private unregisterHandler;
269
358
  private registerSubscription;
270
359
  protected off(event: string): void;
271
- protected on(event: "project-selected", callback: (arg: Project["insert"] & {
272
- workingDir: string;
273
- id?: string;
274
- }) => void): void;
275
- protected on(event: "new-project", callback: (arg: Project["insert"] & {
276
- workingDir: string;
277
- id?: string;
278
- }) => void): void;
279
- protected on(event: "file-selected", callback: (filePath: string | null) => void): void;
280
- protected on(event: "file-created", callback: (filePath: string) => void): void;
281
- protected on(event: "file-changed", callback: (filePath: string) => void): void;
282
- protected on(event: "file-deleted", callback: (filePath: string) => void): void;
283
- protected on(event: "ping", callback: (arg: unknown) => void): void;
360
+ protected on<K extends EventSubs>(event: K, callback: (res: EventMap[K] | null) => void): void;
284
361
  renderStatusBar?(): RenderStatusType | null;
285
362
  private registerStatus;
286
363
  protected setState(param: SetState<T>): void;
@@ -297,4 +374,4 @@ type Message = {
297
374
 
298
375
  declare const getPluginChannel: (event: string, pluginId: string) => string;
299
376
 
300
- export { type EditorAPI, type ElementInstruction, type InputInstruction, type Message, type PluginElement, type RenderStatusType, type SetState, type Store, type TextVariant, type TextareaInstruction, Plugin as default, getPluginChannel };
377
+ export { type EditorAPI, type ElementInstruction, type EventMap, type InputInstruction, type Message, type OverlayType, type PluginElement, type RenderStatusType, type SetState, type Store, type TextVariant, type TextareaInstruction, Plugin as default, getPluginChannel };
package/dist/plugin.js CHANGED
@@ -169,7 +169,9 @@ var Plugin = class {
169
169
  this.subscriptions.delete(channel);
170
170
  }
171
171
  on(event, callback) {
172
- this.registerSubscription(event, callback);
172
+ this.registerSubscription(event, (payload) => {
173
+ callback(payload);
174
+ });
173
175
  }
174
176
  registerStatus() {
175
177
  const arg = _optionalChain([this, 'access', _5 => _5.renderStatusBar, 'optionalCall', _6 => _6()]);
package/dist/plugin.mjs CHANGED
@@ -169,7 +169,9 @@ var Plugin = class {
169
169
  this.subscriptions.delete(channel);
170
170
  }
171
171
  on(event, callback) {
172
- this.registerSubscription(event, callback);
172
+ this.registerSubscription(event, (payload) => {
173
+ callback(payload);
174
+ });
173
175
  }
174
176
  registerStatus() {
175
177
  const arg = this.renderStatusBar?.();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bb-relay",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "description": "For managing bb-editor extension",
5
5
  "license": "ISC",
6
6
  "author": "Ade Adeola",
@@ -0,0 +1,53 @@
1
+ import type { CSSProperties, InputHTMLAttributes } from "react";
2
+
3
+ type Primitive = string | number;
4
+
5
+ type InputOverlay = {
6
+ type: "input";
7
+ inputType?: InputHTMLAttributes<HTMLInputElement>["type"];
8
+ name: string;
9
+ };
10
+
11
+ type CheckboxOverlay = {
12
+ type: "checkbox";
13
+ name: string;
14
+ options: Primitive[];
15
+ };
16
+
17
+ type RadioOverlay = {
18
+ type: "radio";
19
+ name: string;
20
+ options: Primitive[];
21
+ };
22
+
23
+ type TextAreaOverlay = {
24
+ type: "textarea";
25
+ name: string;
26
+ };
27
+
28
+ type SubmitOverlay = {
29
+ type: "submit";
30
+ text: string;
31
+ };
32
+
33
+ type TextOverlay = {
34
+ type: "text";
35
+ content: string;
36
+ };
37
+
38
+ type ContainerOverlay = {
39
+ type: "container";
40
+ children: OverlayType[];
41
+ style?: CSSProperties;
42
+ };
43
+
44
+ type OverlayType =
45
+ | InputOverlay
46
+ | RadioOverlay
47
+ | CheckboxOverlay
48
+ | SubmitOverlay
49
+ | TextAreaOverlay
50
+ | TextOverlay
51
+ | ContainerOverlay;
52
+
53
+ export default OverlayType;
@@ -12,6 +12,7 @@ import {
12
12
  import { Project } from "@/database";
13
13
  import equal from "fast-deep-equal";
14
14
  import { RenderStatusType } from "./RenderStatusType";
15
+ import OverlayType from "./OverlayType";
15
16
 
16
17
  export type Store<T extends Record<string, unknown>> = {
17
18
  get(): T;
@@ -42,20 +43,62 @@ export type EditorAPI = {
42
43
  ) => Promise<Result<string>>;
43
44
  listFiles: (glob?: string) => Promise<Result<string[]>>;
44
45
  };
45
- // project: getProjectInfo, workingDirectory
46
- // dialog: selectFolder, selectFile
47
- // net (should be able to use "fetch api"): download, stream
48
- // git
46
+ git?: {
47
+ commit: (arg: {
48
+ files: string[];
49
+ message: string;
50
+ email?: string;
51
+ }) => Promise<Result>;
52
+ };
53
+ dialog?: {
54
+ selectFile: () => Promise<Result<string[]>>;
55
+ selectFolder: () => Promise<Result<string[]>>;
56
+ };
57
+ project?: {
58
+ /**
59
+ * To create a new project
60
+ * @param dir This should be derived from `dialog.selectFolder`
61
+ * @param project The project config that you want to create
62
+ */
63
+ createProject: (dir: string, project: Project["insert"]) => Promise<Result>;
64
+ /**
65
+ * Use this to update current project information
66
+ * @param project
67
+ * @returns
68
+ */
69
+ updateProject: (project: Project["update"]) => Promise<Result>;
70
+ };
71
+ };
72
+
73
+ export type EventMap = {
74
+ project: {
75
+ /**
76
+ * changed: indicates a different project is selected (change in working directory)
77
+ * created: a new project
78
+ */
79
+ type: "changed" | "created";
80
+ project: Project["insert"] & { id?: string };
81
+ };
82
+
83
+ file: {
84
+ /**
85
+ * Indicates a file is created, updated, selected or deleted
86
+ * It will only return "null" for selected, if selected is not a file
87
+ * Git refers to file being selected in git mode
88
+ */
89
+ type: "created" | "updated" | "selected" | "deleted" | "git";
90
+ filePath: string | null;
91
+ };
92
+ ping: {
93
+ /**
94
+ * Indicates the source of the ping
95
+ */
96
+ type: "main" | "overlay";
97
+ payload: unknown;
98
+ };
49
99
  };
50
100
 
51
- type EventSubs =
52
- | "project-selected"
53
- | "new-project"
54
- | "file-selected"
55
- | "file-created"
56
- | "file-changed"
57
- | "file-deleted"
58
- | "ping";
101
+ type EventSubs = keyof EventMap;
59
102
 
60
103
  export type SetState<T extends Record<string, unknown>> =
61
104
  | Partial<T>
@@ -251,7 +294,7 @@ export abstract class Plugin<T extends Record<string, unknown>> {
251
294
  * back as response
252
295
  */
253
296
 
254
- protected renderOverlay(overlay: ElementInstruction) {
297
+ protected renderOverlay(overlay: OverlayType) {
255
298
  this.sendMessage({ type: "overlay", arg: overlay });
256
299
  }
257
300
 
@@ -318,39 +361,13 @@ export abstract class Plugin<T extends Record<string, unknown>> {
318
361
  this.subscriptions.delete(channel);
319
362
  }
320
363
 
321
- protected on(
322
- event: "project-selected",
323
- callback: (
324
- arg: Project["insert"] & { workingDir: string; id?: string },
325
- ) => void,
326
- ): void;
327
- protected on(
328
- event: "new-project",
329
- callback: (
330
- arg: Project["insert"] & { workingDir: string; id?: string },
331
- ) => void,
332
- ): void;
333
- protected on(
334
- event: "file-selected",
335
- callback: (filePath: string | null) => void,
336
- ): void;
337
- protected on(
338
- event: "file-created",
339
- callback: (filePath: string) => void,
340
- ): void;
341
- protected on(
342
- event: "file-changed",
343
- callback: (filePath: string) => void,
344
- ): void;
345
- protected on(
346
- event: "file-deleted",
347
- callback: (filePath: string) => void,
348
- ): void;
349
-
350
- protected on(event: "ping", callback: (arg: unknown) => void): void;
351
-
352
- protected on(event: EventSubs, callback: (arg: any) => void): void {
353
- this.registerSubscription(event, callback);
364
+ protected on<K extends EventSubs>(
365
+ event: K,
366
+ callback: (res: EventMap[K] | null) => void,
367
+ ): void {
368
+ this.registerSubscription(event, (payload: any) => {
369
+ callback(payload);
370
+ });
354
371
  }
355
372
 
356
373
  // -----------------------------
package/src/plugin.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EditorAPI, Plugin, SetState, Store } from "./lib/plugin";
1
+ import { EditorAPI, EventMap, Plugin, SetState, Store } from "./lib/plugin";
2
2
  import { Message } from "./lib/plugin/Message";
3
3
  import { ElementInstruction } from "./lib/plugin/ElementInstruction";
4
4
  import { InputInstruction } from "./lib/plugin/ElementInstruction/InputInstruction";
@@ -7,6 +7,7 @@ import { TextVariant } from "./lib/plugin/ElementInstruction/TextInstruction";
7
7
  import { getPluginChannel } from "./lib/plugin/getPluginChannel";
8
8
  import { PluginElement } from "./lib/plugin/PluginElement";
9
9
  import { RenderStatusType } from "./lib/plugin/RenderStatusType";
10
+ import OverlayType from "./lib/plugin/OverlayType";
10
11
 
11
12
  export type {
12
13
  RenderStatusType,
@@ -19,6 +20,8 @@ export type {
19
20
  InputInstruction,
20
21
  TextareaInstruction,
21
22
  Message,
23
+ EventMap,
24
+ OverlayType,
22
25
  };
23
26
 
24
27
  export { getPluginChannel };
@@ -1,13 +1,6 @@
1
1
  import { FileContent } from "@/editor";
2
2
 
3
- type Permission =
4
- | "file-system"
5
- | "storage"
6
- | "project"
7
- | "url"
8
- | "selection"
9
- | "git"
10
- | "token";
3
+ type Permission = "file-system" | "project" | "git" | "dialog";
11
4
 
12
5
  export type Manifest = {
13
6
  id: string;
@@ -1 +1 @@
1
- export type WatchFSEvent = "updated" | "deleted" | "updated" | "add";
1
+ export type WatchFSEvent = "updated" | "deleted" | "add";