@impro.social/impro-plugin 0.0.25 → 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.
- package/main.d.ts +16 -4
- package/main.js +25 -6
- package/package.json +1 -1
package/main.d.ts
CHANGED
|
@@ -531,12 +531,19 @@ export class Plugin {
|
|
|
531
531
|
/**
|
|
532
532
|
* Adds an item to the impro sidebar. `icon` is a {@link VirtualEl} (typically
|
|
533
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.
|
|
534
537
|
* @param {string | VirtualEl} icon
|
|
535
538
|
* @param {string} title
|
|
536
539
|
* @param {() => void} [callback]
|
|
540
|
+
* @param {{ id?: string | null, activeIcon?: string | VirtualEl | null }} [options]
|
|
537
541
|
* @returns {void}
|
|
538
542
|
*/
|
|
539
|
-
addSidebarItem(icon: string | VirtualEl, title: string, callback?: () => void
|
|
543
|
+
addSidebarItem(icon: string | VirtualEl, title: string, callback?: () => void, { id, activeIcon }?: {
|
|
544
|
+
id?: string | null;
|
|
545
|
+
activeIcon?: string | VirtualEl | null;
|
|
546
|
+
}): void;
|
|
540
547
|
/**
|
|
541
548
|
* Loads this plugin's account-synced JSON blob. Follows the user across
|
|
542
549
|
* devices via account preferences. Returns whatever was last saved, or null.
|
|
@@ -630,13 +637,15 @@ export class Plugin {
|
|
|
630
637
|
/**
|
|
631
638
|
* Registers a full-page view reachable via {@link Plugin.openPage}. `display()`
|
|
632
639
|
* is called on navigation and must return a {@link VirtualEl}, or nothing to
|
|
633
|
-
* render an empty page.
|
|
634
|
-
* @
|
|
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
|
|
635
643
|
* @returns {void}
|
|
636
644
|
*/
|
|
637
|
-
registerPage({ id, title, display }: {
|
|
645
|
+
registerPage({ id, title, sidebarItemId, display, }: {
|
|
638
646
|
id: string;
|
|
639
647
|
title?: string | null;
|
|
648
|
+
sidebarItemId?: string | null;
|
|
640
649
|
display?: () => RenderResult | Promise<RenderResult>;
|
|
641
650
|
}): void;
|
|
642
651
|
/**
|
|
@@ -1461,7 +1470,9 @@ export type RegisterEventListenerMessage = {
|
|
|
1461
1470
|
export type RegisterSidebarItemMessage = {
|
|
1462
1471
|
type: "register";
|
|
1463
1472
|
target: "sidebarItem";
|
|
1473
|
+
id: string | null;
|
|
1464
1474
|
icon: string | SerializedElement;
|
|
1475
|
+
activeIcon: string | SerializedElement | null;
|
|
1465
1476
|
title: string;
|
|
1466
1477
|
handlerId: number;
|
|
1467
1478
|
};
|
|
@@ -1510,6 +1521,7 @@ export type RegisterPageMessage = {
|
|
|
1510
1521
|
target: "page";
|
|
1511
1522
|
id: string;
|
|
1512
1523
|
title: string | null;
|
|
1524
|
+
sidebarItemId: string | null;
|
|
1513
1525
|
displayHandlerId: number;
|
|
1514
1526
|
};
|
|
1515
1527
|
/**
|
package/main.js
CHANGED
|
@@ -884,18 +884,30 @@ export class Plugin {
|
|
|
884
884
|
/**
|
|
885
885
|
* Adds an item to the impro sidebar. `icon` is a {@link VirtualEl} (typically
|
|
886
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.
|
|
887
890
|
* @param {string | VirtualEl} icon
|
|
888
891
|
* @param {string} title
|
|
889
892
|
* @param {() => void} [callback]
|
|
893
|
+
* @param {{ id?: string | null, activeIcon?: string | VirtualEl | null }} [options]
|
|
890
894
|
* @returns {void}
|
|
891
895
|
*/
|
|
892
|
-
addSidebarItem(
|
|
896
|
+
addSidebarItem(
|
|
897
|
+
icon,
|
|
898
|
+
title,
|
|
899
|
+
callback = () => {},
|
|
900
|
+
{ id = null, activeIcon = null } = {},
|
|
901
|
+
) {
|
|
893
902
|
const handlerId = uuid.create();
|
|
894
903
|
callHandlers.set(handlerId, callback);
|
|
895
904
|
post({
|
|
896
905
|
type: "register",
|
|
897
906
|
target: "sidebarItem",
|
|
907
|
+
id,
|
|
898
908
|
icon: icon instanceof VirtualEl ? icon._serialize() : icon,
|
|
909
|
+
activeIcon:
|
|
910
|
+
activeIcon instanceof VirtualEl ? activeIcon._serialize() : activeIcon,
|
|
899
911
|
title,
|
|
900
912
|
handlerId,
|
|
901
913
|
});
|
|
@@ -1071,11 +1083,17 @@ export class Plugin {
|
|
|
1071
1083
|
/**
|
|
1072
1084
|
* Registers a full-page view reachable via {@link Plugin.openPage}. `display()`
|
|
1073
1085
|
* is called on navigation and must return a {@link VirtualEl}, or nothing to
|
|
1074
|
-
* render an empty page.
|
|
1075
|
-
* @
|
|
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
|
|
1076
1089
|
* @returns {void}
|
|
1077
1090
|
*/
|
|
1078
|
-
registerPage({
|
|
1091
|
+
registerPage({
|
|
1092
|
+
id,
|
|
1093
|
+
title = null,
|
|
1094
|
+
sidebarItemId = null,
|
|
1095
|
+
display = () => null,
|
|
1096
|
+
}) {
|
|
1079
1097
|
const displayHandlerId = uuid.create();
|
|
1080
1098
|
callHandlers.set(displayHandlerId, async () => {
|
|
1081
1099
|
const result = /** @type {unknown} */ (await display());
|
|
@@ -1092,6 +1110,7 @@ export class Plugin {
|
|
|
1092
1110
|
target: "page",
|
|
1093
1111
|
id,
|
|
1094
1112
|
title,
|
|
1113
|
+
sidebarItemId,
|
|
1095
1114
|
displayHandlerId,
|
|
1096
1115
|
});
|
|
1097
1116
|
}
|
|
@@ -2175,7 +2194,7 @@ export class VirtualEl {
|
|
|
2175
2194
|
* `Date`, `Map` and friends cannot.
|
|
2176
2195
|
* @typedef {{ type: "register", target: "eventListener", event: string, handlerId: number }} RegisterEventListenerMessage
|
|
2177
2196
|
* {@internal}
|
|
2178
|
-
* @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
|
|
2179
2198
|
* {@internal}
|
|
2180
2199
|
* @typedef {{ type: "register", target: "settingTab", name: string | null, displayHandlerId: number }} RegisterSettingTabMessage
|
|
2181
2200
|
* {@internal}
|
|
@@ -2185,7 +2204,7 @@ export class VirtualEl {
|
|
|
2185
2204
|
* {@internal}
|
|
2186
2205
|
* @typedef {{ type: "register", target: "slot", name: string, handlerId: number, cacheKey: string[] | null, batch: true }} RegisterSlotMessage
|
|
2187
2206
|
* {@internal}
|
|
2188
|
-
* @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
|
|
2189
2208
|
* {@internal}
|
|
2190
2209
|
* @typedef {RegisterEventListenerMessage | RegisterSidebarItemMessage | RegisterSettingTabMessage | RegisterFeedFilterMessage | RegisterRichTextTransformMessage | RegisterSlotMessage | RegisterPageMessage} RegisterMessage
|
|
2191
2210
|
* {@internal} Announces an extension point this plugin provides.
|