@impro.social/impro-plugin 0.0.24 → 0.0.26

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.
Files changed (3) hide show
  1. package/main.d.ts +27 -4
  2. package/main.js +42 -8
  3. package/package.json +3 -2
package/main.d.ts CHANGED
@@ -105,6 +105,8 @@ export class SimpleUUID {
105
105
  export class MenuItem {
106
106
  title: string;
107
107
  icon: string | VirtualEl | null;
108
+ /** @type {string | null} */
109
+ url: string | null;
108
110
  /** @internal */
109
111
  _callback: () => void;
110
112
  /**
@@ -120,6 +122,14 @@ export class MenuItem {
120
122
  * @returns {this}
121
123
  */
122
124
  setIcon(icon: string | VirtualEl): this;
125
+ /**
126
+ * Make the item a link that opens `url` in a new tab. The URL must match
127
+ * one of the `permissions.open` patterns in the plugin's manifest, or the
128
+ * host drops the item. Link items don't call their `onClick` handler.
129
+ * @param {string} url
130
+ * @returns {this}
131
+ */
132
+ setUrl(url: string): this;
123
133
  /**
124
134
  * Called when the user activates the item.
125
135
  * @param {() => void} callback
@@ -145,6 +155,7 @@ export class Menu {
145
155
  _serialize(): {
146
156
  title: string;
147
157
  icon: string | SerializedElement | null;
158
+ url: string | null;
148
159
  handlerId: number;
149
160
  }[];
150
161
  }
@@ -520,12 +531,19 @@ export class Plugin {
520
531
  /**
521
532
  * Adds an item to the impro sidebar. `icon` is a {@link VirtualEl} (typically
522
533
  * an SVG) or a string; `callback` runs when the item is clicked.
534
+ * `options.id` lets a page claim the item via `registerPage`'s
535
+ * `sidebarItemId`, which marks it active while that page is open;
536
+ * `options.activeIcon` replaces `icon` while it is active.
523
537
  * @param {string | VirtualEl} icon
524
538
  * @param {string} title
525
539
  * @param {() => void} [callback]
540
+ * @param {{ id?: string | null, activeIcon?: string | VirtualEl | null }} [options]
526
541
  * @returns {void}
527
542
  */
528
- addSidebarItem(icon: string | VirtualEl, title: string, callback?: () => void): void;
543
+ addSidebarItem(icon: string | VirtualEl, title: string, callback?: () => void, { id, activeIcon }?: {
544
+ id?: string | null;
545
+ activeIcon?: string | VirtualEl | null;
546
+ }): void;
529
547
  /**
530
548
  * Loads this plugin's account-synced JSON blob. Follows the user across
531
549
  * devices via account preferences. Returns whatever was last saved, or null.
@@ -619,13 +637,15 @@ export class Plugin {
619
637
  /**
620
638
  * Registers a full-page view reachable via {@link Plugin.openPage}. `display()`
621
639
  * is called on navigation and must return a {@link VirtualEl}, or nothing to
622
- * render an empty page.
623
- * @param {{ id: string, title?: string | null, display?: () => RenderResult | Promise<RenderResult> }} options
640
+ * render an empty page. `sidebarItemId` names a sidebar item (see
641
+ * {@link Plugin.addSidebarItem}) to mark active while the page is open.
642
+ * @param {{ id: string, title?: string | null, sidebarItemId?: string | null, display?: () => RenderResult | Promise<RenderResult> }} options
624
643
  * @returns {void}
625
644
  */
626
- registerPage({ id, title, display }: {
645
+ registerPage({ id, title, sidebarItemId, display, }: {
627
646
  id: string;
628
647
  title?: string | null;
648
+ sidebarItemId?: string | null;
629
649
  display?: () => RenderResult | Promise<RenderResult>;
630
650
  }): void;
631
651
  /**
@@ -1450,7 +1470,9 @@ export type RegisterEventListenerMessage = {
1450
1470
  export type RegisterSidebarItemMessage = {
1451
1471
  type: "register";
1452
1472
  target: "sidebarItem";
1473
+ id: string | null;
1453
1474
  icon: string | SerializedElement;
1475
+ activeIcon: string | SerializedElement | null;
1454
1476
  title: string;
1455
1477
  handlerId: number;
1456
1478
  };
@@ -1499,6 +1521,7 @@ export type RegisterPageMessage = {
1499
1521
  target: "page";
1500
1522
  id: string;
1501
1523
  title: string | null;
1524
+ sidebarItemId: string | null;
1502
1525
  displayHandlerId: number;
1503
1526
  };
1504
1527
  /**
package/main.js CHANGED
@@ -170,6 +170,8 @@ export class MenuItem {
170
170
  constructor() {
171
171
  this.title = "";
172
172
  this.icon = null;
173
+ /** @type {string | null} */
174
+ this.url = null;
173
175
  /** @internal */
174
176
  this._callback = () => {};
175
177
  }
@@ -192,6 +194,17 @@ export class MenuItem {
192
194
  this.icon = icon;
193
195
  return this;
194
196
  }
197
+ /**
198
+ * Make the item a link that opens `url` in a new tab. The URL must match
199
+ * one of the `permissions.open` patterns in the plugin's manifest, or the
200
+ * host drops the item. Link items don't call their `onClick` handler.
201
+ * @param {string} url
202
+ * @returns {this}
203
+ */
204
+ setUrl(url) {
205
+ this.url = url;
206
+ return this;
207
+ }
195
208
  /**
196
209
  * Called when the user activates the item.
197
210
  * @param {() => void} callback
@@ -231,7 +244,7 @@ export class Menu {
231
244
  callHandlers.set(handlerId, item._callback);
232
245
  const icon =
233
246
  item.icon instanceof VirtualEl ? item.icon._serialize() : item.icon;
234
- return { title: item.title, icon, handlerId };
247
+ return { title: item.title, icon, url: item.url, handlerId };
235
248
  });
236
249
  }
237
250
  }
@@ -383,7 +396,9 @@ export class PluginData {
383
396
  * @returns {Promise<ListView | null>}
384
397
  */
385
398
  getList(uri) {
386
- return /** @type {Promise<ListView | null>} */ (hostCall("getList", { uri }));
399
+ return /** @type {Promise<ListView | null>} */ (
400
+ hostCall("getList", { uri })
401
+ );
387
402
  }
388
403
  /**
389
404
  * Fetch a feed generator view by AT-URI.
@@ -869,18 +884,30 @@ export class Plugin {
869
884
  /**
870
885
  * Adds an item to the impro sidebar. `icon` is a {@link VirtualEl} (typically
871
886
  * an SVG) or a string; `callback` runs when the item is clicked.
887
+ * `options.id` lets a page claim the item via `registerPage`'s
888
+ * `sidebarItemId`, which marks it active while that page is open;
889
+ * `options.activeIcon` replaces `icon` while it is active.
872
890
  * @param {string | VirtualEl} icon
873
891
  * @param {string} title
874
892
  * @param {() => void} [callback]
893
+ * @param {{ id?: string | null, activeIcon?: string | VirtualEl | null }} [options]
875
894
  * @returns {void}
876
895
  */
877
- addSidebarItem(icon, title, callback = () => {}) {
896
+ addSidebarItem(
897
+ icon,
898
+ title,
899
+ callback = () => {},
900
+ { id = null, activeIcon = null } = {},
901
+ ) {
878
902
  const handlerId = uuid.create();
879
903
  callHandlers.set(handlerId, callback);
880
904
  post({
881
905
  type: "register",
882
906
  target: "sidebarItem",
907
+ id,
883
908
  icon: icon instanceof VirtualEl ? icon._serialize() : icon,
909
+ activeIcon:
910
+ activeIcon instanceof VirtualEl ? activeIcon._serialize() : activeIcon,
884
911
  title,
885
912
  handlerId,
886
913
  });
@@ -1056,11 +1083,17 @@ export class Plugin {
1056
1083
  /**
1057
1084
  * Registers a full-page view reachable via {@link Plugin.openPage}. `display()`
1058
1085
  * is called on navigation and must return a {@link VirtualEl}, or nothing to
1059
- * render an empty page.
1060
- * @param {{ id: string, title?: string | null, display?: () => RenderResult | Promise<RenderResult> }} options
1086
+ * render an empty page. `sidebarItemId` names a sidebar item (see
1087
+ * {@link Plugin.addSidebarItem}) to mark active while the page is open.
1088
+ * @param {{ id: string, title?: string | null, sidebarItemId?: string | null, display?: () => RenderResult | Promise<RenderResult> }} options
1061
1089
  * @returns {void}
1062
1090
  */
1063
- registerPage({ id, title = null, display = () => null }) {
1091
+ registerPage({
1092
+ id,
1093
+ title = null,
1094
+ sidebarItemId = null,
1095
+ display = () => null,
1096
+ }) {
1064
1097
  const displayHandlerId = uuid.create();
1065
1098
  callHandlers.set(displayHandlerId, async () => {
1066
1099
  const result = /** @type {unknown} */ (await display());
@@ -1077,6 +1110,7 @@ export class Plugin {
1077
1110
  target: "page",
1078
1111
  id,
1079
1112
  title,
1113
+ sidebarItemId,
1080
1114
  displayHandlerId,
1081
1115
  });
1082
1116
  }
@@ -2160,7 +2194,7 @@ export class VirtualEl {
2160
2194
  * `Date`, `Map` and friends cannot.
2161
2195
  * @typedef {{ type: "register", target: "eventListener", event: string, handlerId: number }} RegisterEventListenerMessage
2162
2196
  * {@internal}
2163
- * @typedef {{ type: "register", target: "sidebarItem", icon: string | SerializedElement, title: string, handlerId: number }} RegisterSidebarItemMessage
2197
+ * @typedef {{ type: "register", target: "sidebarItem", id: string | null, icon: string | SerializedElement, activeIcon: string | SerializedElement | null, title: string, handlerId: number }} RegisterSidebarItemMessage
2164
2198
  * {@internal}
2165
2199
  * @typedef {{ type: "register", target: "settingTab", name: string | null, displayHandlerId: number }} RegisterSettingTabMessage
2166
2200
  * {@internal}
@@ -2170,7 +2204,7 @@ export class VirtualEl {
2170
2204
  * {@internal}
2171
2205
  * @typedef {{ type: "register", target: "slot", name: string, handlerId: number, cacheKey: string[] | null, batch: true }} RegisterSlotMessage
2172
2206
  * {@internal}
2173
- * @typedef {{ type: "register", target: "page", id: string, title: string | null, displayHandlerId: number }} RegisterPageMessage
2207
+ * @typedef {{ type: "register", target: "page", id: string, title: string | null, sidebarItemId: string | null, displayHandlerId: number }} RegisterPageMessage
2174
2208
  * {@internal}
2175
2209
  * @typedef {RegisterEventListenerMessage | RegisterSidebarItemMessage | RegisterSettingTabMessage | RegisterFeedFilterMessage | RegisterRichTextTransformMessage | RegisterSlotMessage | RegisterPageMessage} RegisterMessage
2176
2210
  * {@internal} Announces an extension point this plugin provides.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@impro.social/impro-plugin",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "type": "module",
5
5
  "main": "main.js",
6
6
  "types": "./main.d.ts",
@@ -22,6 +22,7 @@
22
22
  ],
23
23
  "devDependencies": {
24
24
  "typedoc": "^0.28.20",
25
- "typedoc-plugin-markdown": "^4.12.0"
25
+ "typedoc-plugin-markdown": "^4.12.0",
26
+ "typescript": "^5.9.3"
26
27
  }
27
28
  }