bb-relay 0.0.40 → 0.0.41

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/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;
@@ -186,6 +221,35 @@ type EditorAPI = {
186
221
  listFiles: (glob?: string) => Promise<Result<string[]>>;
187
222
  };
188
223
  };
224
+ type EventMap = {
225
+ project: {
226
+ /**
227
+ * changed: indicates a different project is selected (change in working directory)
228
+ * created: a new project
229
+ */
230
+ type: "changed" | "created";
231
+ project: Project["insert"] & {
232
+ id?: string;
233
+ };
234
+ };
235
+ file: {
236
+ /**
237
+ * Indicates a file is created, updated, selected or deleted
238
+ * It will only return "null" for selected, if selected is not a file
239
+ * Git refers to file being selected in git mode
240
+ */
241
+ type: "created" | "updated" | "selected" | "deleted" | "git";
242
+ filePath: string | null;
243
+ };
244
+ ping: {
245
+ /**
246
+ * Indicates the source of the ping
247
+ */
248
+ type: "main" | "overlay";
249
+ payload: unknown;
250
+ };
251
+ };
252
+ type EventSubs = keyof EventMap;
189
253
  type SetState<T extends Record<string, unknown>> = Partial<T> | ((arg: T) => T);
190
254
  declare abstract class Plugin<T extends Record<string, unknown>> {
191
255
  /** CONSTANTS */
@@ -260,7 +324,7 @@ declare abstract class Plugin<T extends Record<string, unknown>> {
260
324
  * So all you need to do is use form inputs for the part that you want to get
261
325
  * back as response
262
326
  */
263
- protected renderOverlay(overlay: ElementInstruction): void;
327
+ protected renderOverlay(overlay: OverlayType): void;
264
328
  protected onOverlayResponse(callback: (arg: unknown) => void): void;
265
329
  destroy(): void;
266
330
  private getPluginChannel;
@@ -268,19 +332,7 @@ declare abstract class Plugin<T extends Record<string, unknown>> {
268
332
  private unregisterHandler;
269
333
  private registerSubscription;
270
334
  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;
335
+ protected on<K extends EventSubs>(event: K, callback: (res: EventMap[K] | null) => void): void;
284
336
  renderStatusBar?(): RenderStatusType | null;
285
337
  private registerStatus;
286
338
  protected setState(param: SetState<T>): void;
@@ -297,4 +349,4 @@ type Message = {
297
349
 
298
350
  declare const getPluginChannel: (event: string, pluginId: string) => string;
299
351
 
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 };
352
+ 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;
@@ -186,6 +221,35 @@ type EditorAPI = {
186
221
  listFiles: (glob?: string) => Promise<Result<string[]>>;
187
222
  };
188
223
  };
224
+ type EventMap = {
225
+ project: {
226
+ /**
227
+ * changed: indicates a different project is selected (change in working directory)
228
+ * created: a new project
229
+ */
230
+ type: "changed" | "created";
231
+ project: Project["insert"] & {
232
+ id?: string;
233
+ };
234
+ };
235
+ file: {
236
+ /**
237
+ * Indicates a file is created, updated, selected or deleted
238
+ * It will only return "null" for selected, if selected is not a file
239
+ * Git refers to file being selected in git mode
240
+ */
241
+ type: "created" | "updated" | "selected" | "deleted" | "git";
242
+ filePath: string | null;
243
+ };
244
+ ping: {
245
+ /**
246
+ * Indicates the source of the ping
247
+ */
248
+ type: "main" | "overlay";
249
+ payload: unknown;
250
+ };
251
+ };
252
+ type EventSubs = keyof EventMap;
189
253
  type SetState<T extends Record<string, unknown>> = Partial<T> | ((arg: T) => T);
190
254
  declare abstract class Plugin<T extends Record<string, unknown>> {
191
255
  /** CONSTANTS */
@@ -260,7 +324,7 @@ declare abstract class Plugin<T extends Record<string, unknown>> {
260
324
  * So all you need to do is use form inputs for the part that you want to get
261
325
  * back as response
262
326
  */
263
- protected renderOverlay(overlay: ElementInstruction): void;
327
+ protected renderOverlay(overlay: OverlayType): void;
264
328
  protected onOverlayResponse(callback: (arg: unknown) => void): void;
265
329
  destroy(): void;
266
330
  private getPluginChannel;
@@ -268,19 +332,7 @@ declare abstract class Plugin<T extends Record<string, unknown>> {
268
332
  private unregisterHandler;
269
333
  private registerSubscription;
270
334
  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;
335
+ protected on<K extends EventSubs>(event: K, callback: (res: EventMap[K] | null) => void): void;
284
336
  renderStatusBar?(): RenderStatusType | null;
285
337
  private registerStatus;
286
338
  protected setState(param: SetState<T>): void;
@@ -297,4 +349,4 @@ type Message = {
297
349
 
298
350
  declare const getPluginChannel: (event: string, pluginId: string) => string;
299
351
 
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 };
352
+ 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.41",
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;
@@ -48,14 +49,35 @@ export type EditorAPI = {
48
49
  // git
49
50
  };
50
51
 
51
- type EventSubs =
52
- | "project-selected"
53
- | "new-project"
54
- | "file-selected"
55
- | "file-created"
56
- | "file-changed"
57
- | "file-deleted"
58
- | "ping";
52
+ export type EventMap = {
53
+ project: {
54
+ /**
55
+ * changed: indicates a different project is selected (change in working directory)
56
+ * created: a new project
57
+ */
58
+ type: "changed" | "created";
59
+ project: Project["insert"] & { id?: string };
60
+ };
61
+
62
+ file: {
63
+ /**
64
+ * Indicates a file is created, updated, selected or deleted
65
+ * It will only return "null" for selected, if selected is not a file
66
+ * Git refers to file being selected in git mode
67
+ */
68
+ type: "created" | "updated" | "selected" | "deleted" | "git";
69
+ filePath: string | null;
70
+ };
71
+ ping: {
72
+ /**
73
+ * Indicates the source of the ping
74
+ */
75
+ type: "main" | "overlay";
76
+ payload: unknown;
77
+ };
78
+ };
79
+
80
+ type EventSubs = keyof EventMap;
59
81
 
60
82
  export type SetState<T extends Record<string, unknown>> =
61
83
  | Partial<T>
@@ -251,7 +273,7 @@ export abstract class Plugin<T extends Record<string, unknown>> {
251
273
  * back as response
252
274
  */
253
275
 
254
- protected renderOverlay(overlay: ElementInstruction) {
276
+ protected renderOverlay(overlay: OverlayType) {
255
277
  this.sendMessage({ type: "overlay", arg: overlay });
256
278
  }
257
279
 
@@ -318,39 +340,13 @@ export abstract class Plugin<T extends Record<string, unknown>> {
318
340
  this.subscriptions.delete(channel);
319
341
  }
320
342
 
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);
343
+ protected on<K extends EventSubs>(
344
+ event: K,
345
+ callback: (res: EventMap[K] | null) => void,
346
+ ): void {
347
+ this.registerSubscription(event, (payload: any) => {
348
+ callback(payload);
349
+ });
354
350
  }
355
351
 
356
352
  // -----------------------------
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 +1 @@
1
- export type WatchFSEvent = "updated" | "deleted" | "updated" | "add";
1
+ export type WatchFSEvent = "updated" | "deleted" | "add";