@colixsystems/widget-sdk 0.339.0 → 0.341.0
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/README.md +17 -1
- package/dist/cli.js +21 -2
- package/dist/connector-app-operations.cjs +100 -0
- package/dist/connector-credential-entry.cjs +77 -0
- package/dist/connector-template-data.json +186 -0
- package/dist/connector-template.cjs +620 -0
- package/dist/contract.cjs +13 -1
- package/dist/contract.js +13 -1
- package/dist/host.d.ts +35 -4
- package/dist/host.js +6 -0
- package/dist/index.d.ts +35 -0
- package/dist/navigation.cjs +116 -8
- package/dist/navigation.js +111 -8
- package/package.json +5 -1
- package/src/contract.js +13 -1
package/dist/host.d.ts
CHANGED
|
@@ -395,19 +395,50 @@ export interface SidebarTokens {
|
|
|
395
395
|
*/
|
|
396
396
|
export function resolveSidebarTokens(theme: unknown): SidebarTokens;
|
|
397
397
|
|
|
398
|
-
/**
|
|
398
|
+
/** What a stored menu item can be (sc-17872). */
|
|
399
|
+
export type MenuItemKind = "PAGE" | "LINK" | "SUBMENU" | "SUBHEADING" | "DIVIDER";
|
|
400
|
+
export const MENU_ITEM_KINDS: readonly MenuItemKind[];
|
|
401
|
+
|
|
402
|
+
/** What a stored menu item is; an item served without `kind` is a page, a
|
|
403
|
+
* link, or (with neither) a sub-menu. Null for no item (sc-17872). */
|
|
404
|
+
export function menuItemKind(item: unknown): MenuItemKind | null;
|
|
405
|
+
|
|
406
|
+
/** A stored menu item that holds other items: a sub-menu (sc-14098). */
|
|
399
407
|
export function isSubMenuItem(item: unknown): boolean;
|
|
400
408
|
|
|
409
|
+
/** The separator a stored menu item is, if it is one (sc-17872). */
|
|
410
|
+
export function menuSeparatorKind(item: unknown): "SUBHEADING" | "DIVIDER" | null;
|
|
411
|
+
|
|
401
412
|
/** A menu's flat entries as both hosts draw them (sc-14098): the top-level
|
|
402
413
|
* ones in order, a sub-menu returned with its own entries as `children`.
|
|
403
414
|
* An empty sub-menu is dropped; an entry naming no sub-menu of the list
|
|
404
|
-
* stands at the top level. `of` reads `id`,
|
|
405
|
-
* they live inside the entry. */
|
|
415
|
+
* stands at the top level, as a separator always does. `of` reads `id`,
|
|
416
|
+
* `parent_id`, `submenu` and `separator` when they live inside the entry. */
|
|
406
417
|
export function menuTree<T extends object>(
|
|
407
418
|
entries: readonly T[],
|
|
408
|
-
options?: {
|
|
419
|
+
options?: {
|
|
420
|
+
of?: (entry: T) => { id?: unknown; parent_id?: unknown; submenu?: unknown; separator?: unknown };
|
|
421
|
+
},
|
|
409
422
|
): Array<T | (T & { children: T[] })>;
|
|
410
423
|
|
|
424
|
+
/** The separators a menu draws in one place (sc-17872), where the maker put
|
|
425
|
+
* them: `sidebar` both kinds, `header` dividers only, `bar` none. `of`
|
|
426
|
+
* reads `separator`. */
|
|
427
|
+
export function placeMenuSeparators<T extends object>(
|
|
428
|
+
entries: readonly T[],
|
|
429
|
+
place: "sidebar" | "header" | "bar",
|
|
430
|
+
options?: { of?: (entry: T) => { separator?: unknown } },
|
|
431
|
+
): T[];
|
|
432
|
+
|
|
433
|
+
/** Skips a separator whose grouped links are all hidden from this visitor
|
|
434
|
+
* (sc-17872): a subheading's links follow it, a divider's sit on each side.
|
|
435
|
+
* Run on the top-level entries before hidden ones are removed. */
|
|
436
|
+
export function dropHiddenSeparators<T extends object>(
|
|
437
|
+
entries: readonly T[],
|
|
438
|
+
isShown: (entry: T) => boolean,
|
|
439
|
+
options?: { of?: (entry: T) => { separator?: unknown } },
|
|
440
|
+
): T[];
|
|
441
|
+
|
|
411
442
|
|
|
412
443
|
/** The top app bar's resolved tokens. `tintColor` and `titleColor` are separate
|
|
413
444
|
* because an unthemed bar paints its icons slate and its app name in the brand
|
package/dist/host.js
CHANGED
|
@@ -121,6 +121,12 @@ export {
|
|
|
121
121
|
// sc-14098: a menu's sub-menus, grouped the one way both hosts draw them.
|
|
122
122
|
isSubMenuItem,
|
|
123
123
|
menuTree,
|
|
124
|
+
// sc-17872: subheadings and dividers, and where each host draws them.
|
|
125
|
+
MENU_ITEM_KINDS,
|
|
126
|
+
menuItemKind,
|
|
127
|
+
menuSeparatorKind,
|
|
128
|
+
placeMenuSeparators,
|
|
129
|
+
dropHiddenSeparators,
|
|
124
130
|
resolveLocalNavModel,
|
|
125
131
|
drawsLocalNavAnywhere,
|
|
126
132
|
mainMenuAppearsOn,
|
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,31 @@ export type WidgetPropertyType =
|
|
|
78
78
|
// an array `value` of at most 100 members and no `valueMode`.
|
|
79
79
|
| "filterList";
|
|
80
80
|
|
|
81
|
+
/** One operation a widget calls on its connector (`useConnector(...).call(key, …)`). */
|
|
82
|
+
export interface WidgetConnectorAppOperation {
|
|
83
|
+
key: string;
|
|
84
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
85
|
+
/** Starts with "/"; each `{name}` segment is one `params` value. */
|
|
86
|
+
path: string;
|
|
87
|
+
/** The query names a call may send. */
|
|
88
|
+
query?: string[];
|
|
89
|
+
/** Whether a call sends a body; never on GET. */
|
|
90
|
+
body?: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A REST connector a widget ships, as an Action's `connectorTemplates` entry plus `appOperations`. */
|
|
94
|
+
export interface WidgetConnectorTemplate {
|
|
95
|
+
key: string;
|
|
96
|
+
name: string;
|
|
97
|
+
baseUrl: string;
|
|
98
|
+
authType?: "none" | "bearer" | "basic" | "apiKey" | "oauth2_client_credentials" | "oauth2_authorization_code";
|
|
99
|
+
/** Non-secret prefill only: never a token, password, API key value or client secret. */
|
|
100
|
+
authConfig?: Record<string, unknown>;
|
|
101
|
+
defaultHeaders?: Record<string, string>;
|
|
102
|
+
description?: string;
|
|
103
|
+
appOperations: WidgetConnectorAppOperation[];
|
|
104
|
+
}
|
|
105
|
+
|
|
81
106
|
export interface WidgetPropertyDef {
|
|
82
107
|
type: WidgetPropertyType;
|
|
83
108
|
label: string;
|
|
@@ -96,6 +121,11 @@ export interface WidgetPropertyDef {
|
|
|
96
121
|
// a styleSchema field keeps its only-when-set contract. Prefer this over a
|
|
97
122
|
// literal `default` whenever the fallback is a theme token.
|
|
98
123
|
themeDefault?: string;
|
|
124
|
+
/**
|
|
125
|
+
* `connectorRef` only: the key of one of the manifest's `connectorTemplates`.
|
|
126
|
+
* Placing the widget binds the property to the connector its install created.
|
|
127
|
+
*/
|
|
128
|
+
template?: string;
|
|
99
129
|
ui?: {
|
|
100
130
|
widget?: "textarea" | "slider" | "code";
|
|
101
131
|
group?: string;
|
|
@@ -472,6 +502,11 @@ export interface WidgetManifest {
|
|
|
472
502
|
* structural constraints enforced at submission time.
|
|
473
503
|
*/
|
|
474
504
|
datastoreTemplate?: WidgetDatastoreTemplate;
|
|
505
|
+
/**
|
|
506
|
+
* REST connectors created in the installing workspace at install, callable
|
|
507
|
+
* from the app with exactly the listed `appOperations`. Never a credential.
|
|
508
|
+
*/
|
|
509
|
+
connectorTemplates?: WidgetConnectorTemplate[];
|
|
475
510
|
/**
|
|
476
511
|
* @deprecated Refused by `validateManifest` and at publish: ship the
|
|
477
512
|
* automation as a marketplace Action (`@colixsystems/action-sdk`).
|
package/dist/navigation.cjs
CHANGED
|
@@ -687,15 +687,116 @@ function resolveTopBarTokens(theme) {
|
|
|
687
687
|
};
|
|
688
688
|
}
|
|
689
689
|
|
|
690
|
+
/** sc-17872 — what a stored menu item can be. */
|
|
691
|
+
const MENU_ITEM_KINDS = Object.freeze(["PAGE", "LINK", "SUBMENU", "SUBHEADING", "DIVIDER"]);
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* sc-17872 — what a stored menu item is. An item served before `kind`
|
|
695
|
+
* existed is a page, a link, or (with neither) a sub-menu.
|
|
696
|
+
*
|
|
697
|
+
* @param {object|null|undefined} item — a menu item as the API serves it.
|
|
698
|
+
* @returns {"PAGE"|"LINK"|"SUBMENU"|"SUBHEADING"|"DIVIDER"|null} null for no item.
|
|
699
|
+
*/
|
|
700
|
+
function menuItemKind(item) {
|
|
701
|
+
if (!isPlainObject(item)) return null;
|
|
702
|
+
if (MENU_ITEM_KINDS.includes(item.kind)) return item.kind;
|
|
703
|
+
if (item.page_id) return "PAGE";
|
|
704
|
+
if (item.url) return "LINK";
|
|
705
|
+
return "SUBMENU";
|
|
706
|
+
}
|
|
707
|
+
|
|
690
708
|
/**
|
|
691
|
-
* sc-14098 — is this stored menu item a sub-menu?
|
|
692
|
-
*
|
|
709
|
+
* sc-14098 — is this stored menu item a sub-menu? It holds the items whose
|
|
710
|
+
* `parent_id` names it.
|
|
693
711
|
*
|
|
694
712
|
* @param {object|null|undefined} item — a menu item as the API serves it.
|
|
695
713
|
* @returns {boolean}
|
|
696
714
|
*/
|
|
697
715
|
function isSubMenuItem(item) {
|
|
698
|
-
return
|
|
716
|
+
return menuItemKind(item) === "SUBMENU";
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* sc-17872 — the separator a stored menu item is, if it is one.
|
|
721
|
+
*
|
|
722
|
+
* @param {object|null|undefined} item — a menu item as the API serves it.
|
|
723
|
+
* @returns {"SUBHEADING"|"DIVIDER"|null}
|
|
724
|
+
*/
|
|
725
|
+
function menuSeparatorKind(item) {
|
|
726
|
+
const kind = menuItemKind(item);
|
|
727
|
+
return kind === "SUBHEADING" || kind === "DIVIDER" ? kind : null;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
const separatorOf = (of, entry) => {
|
|
731
|
+
const read = isPlainObject(of(entry)) ? of(entry) : {};
|
|
732
|
+
return read.separator === "SUBHEADING" || read.separator === "DIVIDER" ? read.separator : null;
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* sc-17872 — the separators a menu draws in one place, read by both hosts
|
|
737
|
+
* (§8). A separator shows where the maker put it, wherever it can show:
|
|
738
|
+
*
|
|
739
|
+
* - `sidebar` (the rail, the drawer, the menu sheets): subheadings and dividers.
|
|
740
|
+
* - `header` (the Top navigation bar): dividers, as a short upright line.
|
|
741
|
+
* - `bar` (tabs, the bottom bar): none.
|
|
742
|
+
*
|
|
743
|
+
* @param {Array<object>} entries — top-level entries in menu order.
|
|
744
|
+
* @param {"sidebar"|"header"|"bar"} place
|
|
745
|
+
* @param {{ of?: (entry: object) => { separator?: unknown } }} [options]
|
|
746
|
+
* `of` reads an entry's `separator` ("SUBHEADING" | "DIVIDER" | null) when
|
|
747
|
+
* it lives inside the entry.
|
|
748
|
+
* @returns {Array<object>} the entries to draw, each as it came.
|
|
749
|
+
*/
|
|
750
|
+
function placeMenuSeparators(entries, place, { of = (entry) => entry } = {}) {
|
|
751
|
+
const list = Array.isArray(entries) ? entries.filter(isPlainObject) : [];
|
|
752
|
+
if (place === "sidebar") return list;
|
|
753
|
+
if (place === "header") return list.filter((entry) => separatorOf(of, entry) !== "SUBHEADING");
|
|
754
|
+
return list.filter((entry) => !separatorOf(of, entry));
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* sc-17872 — the separators a visitor's hidden links leave stranded. A
|
|
759
|
+
* subheading goes when every destination after it, up to the next separator,
|
|
760
|
+
* is hidden. A divider goes when the group after it, up to the next divider
|
|
761
|
+
* (subheadings skipped), is hidden, or when the group before it is hidden and
|
|
762
|
+
* nothing shows on one of its sides. So hiding a group merges the dividers
|
|
763
|
+
* around it into one, and none is left at either end of what the visitor
|
|
764
|
+
* sees. A group the maker left empty hides nothing: separators the maker
|
|
765
|
+
* placed next to each other stay.
|
|
766
|
+
*
|
|
767
|
+
* Run it on the top-level entries BEFORE hidden ones are removed, with
|
|
768
|
+
* `isShown` saying which destinations this visitor sees. The server runs it
|
|
769
|
+
* for the web Player's menus and the export at runtime (§8).
|
|
770
|
+
*
|
|
771
|
+
* @param {Array<object>} entries — top-level entries in menu order.
|
|
772
|
+
* @param {(entry: object) => boolean} isShown — whether a destination shows.
|
|
773
|
+
* @param {{ of?: (entry: object) => { separator?: unknown } }} [options]
|
|
774
|
+
* @returns {Array<object>} every entry as it came, less the skipped separators.
|
|
775
|
+
*/
|
|
776
|
+
function dropHiddenSeparators(entries, isShown, { of = (entry) => entry } = {}) {
|
|
777
|
+
const list = Array.isArray(entries) ? entries.filter(isPlainObject) : [];
|
|
778
|
+
const kindAt = (at) => separatorOf(of, list[at]);
|
|
779
|
+
// "empty" (no destinations), "shown" (one shows) or "hidden" (none shows).
|
|
780
|
+
const groupFrom = (from, step, stopsAt) => {
|
|
781
|
+
let group = "empty";
|
|
782
|
+
for (let at = from; at >= 0 && at < list.length && !stopsAt(kindAt(at)); at += step) {
|
|
783
|
+
if (kindAt(at)) continue;
|
|
784
|
+
if (isShown(list[at])) return "shown";
|
|
785
|
+
group = "hidden";
|
|
786
|
+
}
|
|
787
|
+
return group;
|
|
788
|
+
};
|
|
789
|
+
const anySeparator = (separator) => separator !== null;
|
|
790
|
+
const aDivider = (separator) => separator === "DIVIDER";
|
|
791
|
+
const never = () => false;
|
|
792
|
+
return list.filter((entry, index) => {
|
|
793
|
+
const separator = separatorOf(of, entry);
|
|
794
|
+
if (!separator) return true;
|
|
795
|
+
if (separator === "SUBHEADING") return groupFrom(index + 1, 1, anySeparator) !== "hidden";
|
|
796
|
+
if (groupFrom(index + 1, 1, aDivider) === "hidden") return false;
|
|
797
|
+
if (groupFrom(index - 1, -1, aDivider) !== "hidden") return true;
|
|
798
|
+
return groupFrom(index - 1, -1, never) === "shown" && groupFrom(index + 1, 1, never) === "shown";
|
|
799
|
+
});
|
|
699
800
|
}
|
|
700
801
|
|
|
701
802
|
/**
|
|
@@ -709,9 +810,10 @@ function isSubMenuItem(item) {
|
|
|
709
810
|
* is dropped rather than drawn as a heading over nothing.
|
|
710
811
|
*
|
|
711
812
|
* @param {Array<object>} entries — in menu order, each with an `id`.
|
|
712
|
-
* @param {{ of?: (entry: object) => { id?: unknown, parent_id?: unknown, submenu?: unknown } }} [options]
|
|
713
|
-
* `of` reads an entry's `id`, `parent_id
|
|
714
|
-
* live inside it (the web chrome's `{ page, isActive }`
|
|
813
|
+
* @param {{ of?: (entry: object) => { id?: unknown, parent_id?: unknown, submenu?: unknown, separator?: unknown } }} [options]
|
|
814
|
+
* `of` reads an entry's `id`, `parent_id`, `submenu` flag and (sc-17872)
|
|
815
|
+
* `separator` when they live inside it (the web chrome's `{ page, isActive }`
|
|
816
|
+
* rows). A separator always stands at the top level.
|
|
715
817
|
* @returns {Array<object>} the top-level entries; a sub-menu is returned as
|
|
716
818
|
* `{ ...entry, children }`, every other entry as it came.
|
|
717
819
|
*/
|
|
@@ -722,8 +824,9 @@ function menuTree(entries, { of = (entry) => entry } = {}) {
|
|
|
722
824
|
list.filter((entry) => read(entry).submenu === true).map((entry) => read(entry).id),
|
|
723
825
|
);
|
|
724
826
|
const parentOf = (entry) => {
|
|
725
|
-
const { parent_id: parent, submenu } = read(entry);
|
|
726
|
-
|
|
827
|
+
const { parent_id: parent, submenu, separator } = read(entry);
|
|
828
|
+
if (submenu === true || separator) return null;
|
|
829
|
+
return typeof parent === "string" && subMenuIds.has(parent) ? parent : null;
|
|
727
830
|
};
|
|
728
831
|
return list
|
|
729
832
|
.filter((entry) => parentOf(entry) === null)
|
|
@@ -960,7 +1063,12 @@ module.exports = {
|
|
|
960
1063
|
isDarkSurface,
|
|
961
1064
|
resolveAppLogo,
|
|
962
1065
|
resolveTopBarTokens,
|
|
1066
|
+
MENU_ITEM_KINDS,
|
|
1067
|
+
menuItemKind,
|
|
963
1068
|
isSubMenuItem,
|
|
1069
|
+
menuSeparatorKind,
|
|
1070
|
+
placeMenuSeparators,
|
|
1071
|
+
dropHiddenSeparators,
|
|
964
1072
|
menuTree,
|
|
965
1073
|
resolveLocalNavModel,
|
|
966
1074
|
drawsLocalNavAnywhere,
|
package/dist/navigation.js
CHANGED
|
@@ -682,15 +682,116 @@ export function resolveTopBarTokens(theme) {
|
|
|
682
682
|
};
|
|
683
683
|
}
|
|
684
684
|
|
|
685
|
+
/** sc-17872 — what a stored menu item can be. */
|
|
686
|
+
export const MENU_ITEM_KINDS = Object.freeze(["PAGE", "LINK", "SUBMENU", "SUBHEADING", "DIVIDER"]);
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* sc-17872 — what a stored menu item is. An item served before `kind`
|
|
690
|
+
* existed is a page, a link, or (with neither) a sub-menu.
|
|
691
|
+
*
|
|
692
|
+
* @param {object|null|undefined} item — a menu item as the API serves it.
|
|
693
|
+
* @returns {"PAGE"|"LINK"|"SUBMENU"|"SUBHEADING"|"DIVIDER"|null} null for no item.
|
|
694
|
+
*/
|
|
695
|
+
export function menuItemKind(item) {
|
|
696
|
+
if (!isPlainObject(item)) return null;
|
|
697
|
+
if (MENU_ITEM_KINDS.includes(item.kind)) return item.kind;
|
|
698
|
+
if (item.page_id) return "PAGE";
|
|
699
|
+
if (item.url) return "LINK";
|
|
700
|
+
return "SUBMENU";
|
|
701
|
+
}
|
|
702
|
+
|
|
685
703
|
/**
|
|
686
|
-
* sc-14098 — is this stored menu item a sub-menu?
|
|
687
|
-
*
|
|
704
|
+
* sc-14098 — is this stored menu item a sub-menu? It holds the items whose
|
|
705
|
+
* `parent_id` names it.
|
|
688
706
|
*
|
|
689
707
|
* @param {object|null|undefined} item — a menu item as the API serves it.
|
|
690
708
|
* @returns {boolean}
|
|
691
709
|
*/
|
|
692
710
|
export function isSubMenuItem(item) {
|
|
693
|
-
return
|
|
711
|
+
return menuItemKind(item) === "SUBMENU";
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* sc-17872 — the separator a stored menu item is, if it is one.
|
|
716
|
+
*
|
|
717
|
+
* @param {object|null|undefined} item — a menu item as the API serves it.
|
|
718
|
+
* @returns {"SUBHEADING"|"DIVIDER"|null}
|
|
719
|
+
*/
|
|
720
|
+
export function menuSeparatorKind(item) {
|
|
721
|
+
const kind = menuItemKind(item);
|
|
722
|
+
return kind === "SUBHEADING" || kind === "DIVIDER" ? kind : null;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
const separatorOf = (of, entry) => {
|
|
726
|
+
const read = isPlainObject(of(entry)) ? of(entry) : {};
|
|
727
|
+
return read.separator === "SUBHEADING" || read.separator === "DIVIDER" ? read.separator : null;
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* sc-17872 — the separators a menu draws in one place, read by both hosts
|
|
732
|
+
* (§8). A separator shows where the maker put it, wherever it can show:
|
|
733
|
+
*
|
|
734
|
+
* - `sidebar` (the rail, the drawer, the menu sheets): subheadings and dividers.
|
|
735
|
+
* - `header` (the Top navigation bar): dividers, as a short upright line.
|
|
736
|
+
* - `bar` (tabs, the bottom bar): none.
|
|
737
|
+
*
|
|
738
|
+
* @param {Array<object>} entries — top-level entries in menu order.
|
|
739
|
+
* @param {"sidebar"|"header"|"bar"} place
|
|
740
|
+
* @param {{ of?: (entry: object) => { separator?: unknown } }} [options]
|
|
741
|
+
* `of` reads an entry's `separator` ("SUBHEADING" | "DIVIDER" | null) when
|
|
742
|
+
* it lives inside the entry.
|
|
743
|
+
* @returns {Array<object>} the entries to draw, each as it came.
|
|
744
|
+
*/
|
|
745
|
+
export function placeMenuSeparators(entries, place, { of = (entry) => entry } = {}) {
|
|
746
|
+
const list = Array.isArray(entries) ? entries.filter(isPlainObject) : [];
|
|
747
|
+
if (place === "sidebar") return list;
|
|
748
|
+
if (place === "header") return list.filter((entry) => separatorOf(of, entry) !== "SUBHEADING");
|
|
749
|
+
return list.filter((entry) => !separatorOf(of, entry));
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* sc-17872 — the separators a visitor's hidden links leave stranded. A
|
|
754
|
+
* subheading goes when every destination after it, up to the next separator,
|
|
755
|
+
* is hidden. A divider goes when the group after it, up to the next divider
|
|
756
|
+
* (subheadings skipped), is hidden, or when the group before it is hidden and
|
|
757
|
+
* nothing shows on one of its sides. So hiding a group merges the dividers
|
|
758
|
+
* around it into one, and none is left at either end of what the visitor
|
|
759
|
+
* sees. A group the maker left empty hides nothing: separators the maker
|
|
760
|
+
* placed next to each other stay.
|
|
761
|
+
*
|
|
762
|
+
* Run it on the top-level entries BEFORE hidden ones are removed, with
|
|
763
|
+
* `isShown` saying which destinations this visitor sees. The server runs it
|
|
764
|
+
* for the web Player's menus and the export at runtime (§8).
|
|
765
|
+
*
|
|
766
|
+
* @param {Array<object>} entries — top-level entries in menu order.
|
|
767
|
+
* @param {(entry: object) => boolean} isShown — whether a destination shows.
|
|
768
|
+
* @param {{ of?: (entry: object) => { separator?: unknown } }} [options]
|
|
769
|
+
* @returns {Array<object>} every entry as it came, less the skipped separators.
|
|
770
|
+
*/
|
|
771
|
+
export function dropHiddenSeparators(entries, isShown, { of = (entry) => entry } = {}) {
|
|
772
|
+
const list = Array.isArray(entries) ? entries.filter(isPlainObject) : [];
|
|
773
|
+
const kindAt = (at) => separatorOf(of, list[at]);
|
|
774
|
+
// "empty" (no destinations), "shown" (one shows) or "hidden" (none shows).
|
|
775
|
+
const groupFrom = (from, step, stopsAt) => {
|
|
776
|
+
let group = "empty";
|
|
777
|
+
for (let at = from; at >= 0 && at < list.length && !stopsAt(kindAt(at)); at += step) {
|
|
778
|
+
if (kindAt(at)) continue;
|
|
779
|
+
if (isShown(list[at])) return "shown";
|
|
780
|
+
group = "hidden";
|
|
781
|
+
}
|
|
782
|
+
return group;
|
|
783
|
+
};
|
|
784
|
+
const anySeparator = (separator) => separator !== null;
|
|
785
|
+
const aDivider = (separator) => separator === "DIVIDER";
|
|
786
|
+
const never = () => false;
|
|
787
|
+
return list.filter((entry, index) => {
|
|
788
|
+
const separator = separatorOf(of, entry);
|
|
789
|
+
if (!separator) return true;
|
|
790
|
+
if (separator === "SUBHEADING") return groupFrom(index + 1, 1, anySeparator) !== "hidden";
|
|
791
|
+
if (groupFrom(index + 1, 1, aDivider) === "hidden") return false;
|
|
792
|
+
if (groupFrom(index - 1, -1, aDivider) !== "hidden") return true;
|
|
793
|
+
return groupFrom(index - 1, -1, never) === "shown" && groupFrom(index + 1, 1, never) === "shown";
|
|
794
|
+
});
|
|
694
795
|
}
|
|
695
796
|
|
|
696
797
|
/**
|
|
@@ -704,9 +805,10 @@ export function isSubMenuItem(item) {
|
|
|
704
805
|
* is dropped rather than drawn as a heading over nothing.
|
|
705
806
|
*
|
|
706
807
|
* @param {Array<object>} entries — in menu order, each with an `id`.
|
|
707
|
-
* @param {{ of?: (entry: object) => { id?: unknown, parent_id?: unknown, submenu?: unknown } }} [options]
|
|
708
|
-
* `of` reads an entry's `id`, `parent_id
|
|
709
|
-
* live inside it (the web chrome's `{ page, isActive }`
|
|
808
|
+
* @param {{ of?: (entry: object) => { id?: unknown, parent_id?: unknown, submenu?: unknown, separator?: unknown } }} [options]
|
|
809
|
+
* `of` reads an entry's `id`, `parent_id`, `submenu` flag and (sc-17872)
|
|
810
|
+
* `separator` when they live inside it (the web chrome's `{ page, isActive }`
|
|
811
|
+
* rows). A separator always stands at the top level.
|
|
710
812
|
* @returns {Array<object>} the top-level entries; a sub-menu is returned as
|
|
711
813
|
* `{ ...entry, children }`, every other entry as it came.
|
|
712
814
|
*/
|
|
@@ -717,8 +819,9 @@ export function menuTree(entries, { of = (entry) => entry } = {}) {
|
|
|
717
819
|
list.filter((entry) => read(entry).submenu === true).map((entry) => read(entry).id),
|
|
718
820
|
);
|
|
719
821
|
const parentOf = (entry) => {
|
|
720
|
-
const { parent_id: parent, submenu } = read(entry);
|
|
721
|
-
|
|
822
|
+
const { parent_id: parent, submenu, separator } = read(entry);
|
|
823
|
+
if (submenu === true || separator) return null;
|
|
824
|
+
return typeof parent === "string" && subMenuIds.has(parent) ? parent : null;
|
|
722
825
|
};
|
|
723
826
|
return list
|
|
724
827
|
.filter((entry) => parentOf(entry) === null)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.341.0",
|
|
4
4
|
"description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,6 +39,10 @@
|
|
|
39
39
|
"import": "./dist/text-scale.js",
|
|
40
40
|
"default": "./dist/text-scale.js"
|
|
41
41
|
},
|
|
42
|
+
"./connector-template": {
|
|
43
|
+
"require": "./dist/connector-template.cjs",
|
|
44
|
+
"default": "./dist/connector-template.cjs"
|
|
45
|
+
},
|
|
42
46
|
"./contract": {
|
|
43
47
|
"types": "./dist/index.d.ts",
|
|
44
48
|
"require": "./dist/contract.cjs",
|
package/src/contract.js
CHANGED
|
@@ -4370,6 +4370,13 @@ const MANIFEST_SCHEMA = {
|
|
|
4370
4370
|
"Optional (REQ-L10N-WIDGET). Translation strings the widget ships. Shape { <key>: { en: string, <locale>?: string, ... } } — `en` is REQUIRED per key. At install the host merges these into the tenant's localization dictionary under a per-widget namespace (`widget.<manifest.id>.<key>`); `useI18n().t(\"<key>\")` resolves the namespaced key automatically, so authors never type the prefix. Non-destructive: an existing admin-edited value is never overwritten, and a language the tenant has not added is never created (values for absent locales are dropped; the widget's `en` seeds the tenant's base language so every key renders). Keys persist across uninstalls; admins prune them from the Translations admin (bulk delete by `widget.<id>.` prefix). Limits: ≤500 keys; each key matches /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/; each value ≤1 KB; the namespaced key must fit the dictionary key cap (128 chars).",
|
|
4371
4371
|
default: {},
|
|
4372
4372
|
},
|
|
4373
|
+
connectorTemplates: {
|
|
4374
|
+
type: "array",
|
|
4375
|
+
required: false,
|
|
4376
|
+
description:
|
|
4377
|
+
"Optional. The REST connectors the widget calls, created in the installing workspace at install so the installer only adds the credential. Each entry is { key, name, baseUrl, authType?, authConfig?, defaultHeaders?, description?, appOperations }, the same contract an Action's connectorTemplates follow, plus `appOperations` (required): the operations the widget calls with `useConnector(connectorId).call(\"<operation>\", { params, query, body })`, each { key, method, path, query?, body? }. The connector is created callable from the app with exactly those operations. A manifest never carries a credential (a token, password, API key value or client secret): publishing one is refused, and the installer enters it on the connector. Declare `connectors.call:*` in requestedScopes, and give the widget a `connectorRef` property with `template: \"<key>\"` so placing it binds the property to the connector its install created. A reinstall or an upgrade keeps the installer's credential and creates no second connector. An upgrade that adds or changes an operation, asks its token for more, or moves the connector to another host is not applied to an installed connector, so keep the operations an earlier version listed working. At most 4 templates.",
|
|
4378
|
+
default: [],
|
|
4379
|
+
},
|
|
4373
4380
|
};
|
|
4374
4381
|
|
|
4375
4382
|
const WIDGET_CONTEXT_SHAPE = {
|
|
@@ -7118,7 +7125,12 @@ const CONTRACT = deepFreeze({
|
|
|
7118
7125
|
// script's own run, inside a 1 s cap on the whole press, so a press can
|
|
7119
7126
|
// wait up to about 1 s before ACTION_TIMEOUT. A press that never started
|
|
7120
7127
|
// its script rejects RATE_LIMITED (429, Retry-After: 1): nothing ran.
|
|
7121
|
-
|
|
7128
|
+
// 1.278.0: additive (sc-17829) — manifest `connectorTemplates`: the REST
|
|
7129
|
+
// connectors a widget ships, provisioned at install with the
|
|
7130
|
+
// `appOperations` it calls; a `connectorRef` property may name one with
|
|
7131
|
+
// `template`. Checked by `appstudio-widget lint --manifest`. The template
|
|
7132
|
+
// contract is shared with the action SDK (`./connector-template`).
|
|
7133
|
+
version: "1.278.0",
|
|
7122
7134
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7123
7135
|
hooks: HOOKS,
|
|
7124
7136
|
primitives: PRIMITIVES,
|