@colixsystems/widget-sdk 0.339.0 → 0.340.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 CHANGED
@@ -91,7 +91,7 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
91
91
 
92
92
  ## Status
93
93
 
94
- `v0.339.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
94
+ `v0.340.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
95
95
 
96
96
  ### What's new in 0.339.0 (contract 1.277.0)
97
97
 
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
- /** A stored menu item with neither a page nor a link: a sub-menu (sc-14098). */
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`, `parent_id` and `submenu` when
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?: { of?: (entry: T) => { id?: unknown; parent_id?: unknown; submenu?: unknown } },
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,
@@ -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? One with neither a page nor
692
- * a link; it holds the items whose `parent_id` names it.
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 isPlainObject(item) && !item.page_id && !item.url;
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` and `submenu` flag when they
714
- * live inside it (the web chrome's `{ page, isActive }` rows).
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
- return submenu !== true && typeof parent === "string" && subMenuIds.has(parent) ? parent : null;
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,
@@ -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? One with neither a page nor
687
- * a link; it holds the items whose `parent_id` names it.
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 isPlainObject(item) && !item.page_id && !item.url;
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` and `submenu` flag when they
709
- * live inside it (the web chrome's `{ page, isActive }` rows).
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
- return submenu !== true && typeof parent === "string" && subMenuIds.has(parent) ? parent : null;
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.339.0",
3
+ "version": "0.340.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "repository": {
6
6
  "type": "git",