@colixsystems/widget-sdk 0.332.0 → 0.333.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.332.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.333.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.332.0 (contract 1.271.0)
97
97
 
package/dist/contract.cjs CHANGED
@@ -6470,7 +6470,7 @@ const CONTRACT = deepFreeze({
6470
6470
  // it. The app's global mobile quick bar is retired: it was a SELECTION
6471
6471
  // over the global menu, and the rail and drawer list every menu page
6472
6472
  // regardless, so nothing was reachable only through it. The bottom edge
6473
- // belongs to a PAGE's own bottom navigation bar (`local_nav = BOTTOM_BAR`,
6473
+ // belongs to a section menu's bottom navigation bar (`layout = BOTTOM_BAR`,
6474
6474
  // REQ-NAV-LOCAL), chosen per page. `resolveFooterTokens` is unchanged —
6475
6475
  // it is the bottom edge's token set and the surviving bar reads it.
6476
6476
  // 1.113.0: additive (sc-7951) — `resolveFooterTokens` gains the bottom
package/dist/contract.js CHANGED
@@ -6465,7 +6465,7 @@ const CONTRACT = deepFreeze({
6465
6465
  // it. The app's global mobile quick bar is retired: it was a SELECTION
6466
6466
  // over the global menu, and the rail and drawer list every menu page
6467
6467
  // regardless, so nothing was reachable only through it. The bottom edge
6468
- // belongs to a PAGE's own bottom navigation bar (`local_nav = BOTTOM_BAR`,
6468
+ // belongs to a section menu's bottom navigation bar (`layout = BOTTOM_BAR`,
6469
6469
  // REQ-NAV-LOCAL), chosen per page. `resolveFooterTokens` is unchanged —
6470
6470
  // it is the bottom edge's token set and the surviving bar reads it.
6471
6471
  // 1.113.0: additive (sc-7951) — `resolveFooterTokens` gains the bottom
package/dist/host.d.ts CHANGED
@@ -395,45 +395,18 @@ export interface SidebarTokens {
395
395
  */
396
396
  export function resolveSidebarTokens(theme: unknown): SidebarTokens;
397
397
 
398
- /** One destination of a page's local menu, as a host hands it over. `key`
399
- * identifies the target in the caller's own vocabulary (a page slug on web, a
400
- * screen name in the export); a URL item carries none. */
401
- export interface SidebarUnfoldItem {
402
- key?: string | null;
403
- [field: string]: unknown;
404
- }
405
-
406
- /** One section's local menu and the sidebar entry it hangs beneath. `inside`
407
- * marks the section the visitor is in — the one that starts unfolded. */
408
- export interface SidebarUnfoldTree {
409
- under: string;
410
- items: Array<SidebarUnfoldItem & { current: boolean }>;
411
- standalone: boolean;
412
- inside: boolean;
413
- }
414
-
415
- /** Where a page's `SIDEBAR` local menu unfolds (REQ-NAV-LOCAL, sc-7696).
416
- * `under` is the global menu entry the visitor's own section hangs beneath,
417
- * or null when they are in none. `standalone` marks the case where the global
418
- * menu does not list the page, so the page itself is the entry. `trees` is
419
- * every section an entry carries, in menu order, so an entry can offer its
420
- * menu from any page; a `standalone` tree comes last. */
421
- export interface SidebarUnfold {
422
- under: string | null;
423
- items: Array<SidebarUnfoldItem & { current: boolean }>;
424
- standalone: boolean;
425
- trees: SidebarUnfoldTree[];
426
- }
427
-
428
- /** Resolve where the viewed page's local menu unfolds in the sidebar and the
429
- * drawer. The one derivation both hosts read: the Player calls it per render,
430
- * the compiler once per screen, so the rail and the exported drawer cannot
431
- * disagree. */
432
- export function resolveSidebarUnfold(input: {
433
- entries?: readonly string[];
434
- active?: string | null;
435
- sections?: Record<string, { menu?: unknown; items?: readonly unknown[] }>;
436
- }): SidebarUnfold;
398
+ /** A stored menu item with neither a page nor a link: a sub-menu (sc-14098). */
399
+ export function isSubMenuItem(item: unknown): boolean;
400
+
401
+ /** A menu's flat entries as both hosts draw them (sc-14098): the top-level
402
+ * ones in order, a sub-menu returned with its own entries as `children`.
403
+ * 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. */
406
+ export function menuTree<T extends object>(
407
+ entries: readonly T[],
408
+ options?: { of?: (entry: T) => { id?: unknown; parent_id?: unknown; submenu?: unknown } },
409
+ ): Array<T | (T & { children: T[] })>;
437
410
 
438
411
 
439
412
  /** The top app bar's resolved tokens. `tintColor` and `titleColor` are separate
package/dist/host.js CHANGED
@@ -93,13 +93,9 @@ export { bannerScopeDefaults } from "./banner-tokens.js";
93
93
  // row above the side panel holds, in what order, and the box it sits in. The
94
94
  // same bar is drawn by the desktop top bar, the phone header and the exported
95
95
  // app's screen header, and each hard-coded its own row before this.
96
- // REQ-NAV-LOCAL (sc-7696): `resolveSidebarUnfold` answers where a page's
97
- // SIDEBAR local menu hangs in the rail and the drawer. The compiler asks it
98
- // once per screen at build time and the Player once per render, so the two
99
- // chromes derive the same tree from the same code.
100
- // REQ-NAV-LOCAL (sc-8901): `resolveLocalNavModel` answers WHICH model a page
101
- // wears in one device view, so the same menu can be a bottom bar on a phone and
102
- // unfold in the rail on a desktop.
96
+ // REQ-NAV-LOCAL (sc-8901, sc-12397): `resolveLocalNavModel` answers WHICH
97
+ // model a menu wears in one device view, so the same menu can be a bottom
98
+ // bar on a phone and a tab row on a desktop.
103
99
  export {
104
100
  normaliseNavigation,
105
101
  menuItemCap,
@@ -122,9 +118,17 @@ export {
122
118
  MAX_TOP_STRIPE_OFFSET_Y_PX,
123
119
  DEFAULT_TOP_STRIPE_HEIGHT_PX,
124
120
  DEFAULT_TOP_STRIPE_PADDING_X_PX,
125
- resolveSidebarUnfold,
121
+ // sc-14098: a menu's sub-menus, grouped the one way both hosts draw them.
122
+ isSubMenuItem,
123
+ menuTree,
126
124
  resolveLocalNavModel,
127
125
  drawsLocalNavAnywhere,
126
+ mainMenuAppearsOn,
127
+ LOCAL_NAV_POSITIONS,
128
+ localNavPosition,
129
+ resolvePageBars,
130
+ drawsTopNavigation,
131
+ topNavigationPageIds,
128
132
  isDarkSurface,
129
133
  resolveAppLogo,
130
134
  } from "./navigation.js";
@@ -67,7 +67,7 @@ function menuItemCap(menuType) {
67
67
  // navigation bar is drawn from.
68
68
  //
69
69
  // sc-7753: the global quick bar these tokens were introduced for is retired;
70
- // the bar that reads them now is the page's own (`local_nav = BOTTOM_BAR`).
70
+ // the bar that reads them now is a section menu's (`layout = BOTTOM_BAR`).
71
71
  //
72
72
  // sc-8033: the block is SELF-CONTAINED — it reads `theme.footer` and nothing
73
73
  // else. Every colour used to fall back to the rail's, so restyling the sidebar
@@ -688,121 +688,59 @@ function resolveTopBarTokens(theme) {
688
688
  }
689
689
 
690
690
  /**
691
- * REQ-NAV-LOCAL (sc-7696) — where a page's `SIDEBAR` local menu unfolds.
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.
692
693
  *
693
- * The one derivation both hosts read, so the web rail, the web drawer and the
694
- * exported app's drawer cannot disagree about what hangs under what. Keys are
695
- * the caller's own (the web Player passes page slugs, the compiler passes
696
- * screen names); this only compares them.
697
- *
698
- * A page belongs to a section in either of two ways, and both keep the tree
699
- * open: it CARRIES the model itself, or the section's menu LISTS it. The
700
- * second is what makes the model usable — clicking a destination would
701
- * otherwise collapse the menu that led there unless the author repeated the
702
- * setting on every sub-page.
703
- *
704
- * The unfold point is the first GLOBAL menu entry carrying that section's
705
- * saved menu, so the tree hangs in the same place from every page of the
706
- * section. When the global menu lists no such page, the section's own page
707
- * becomes a top-level entry (`standalone`) for as long as the visitor is
708
- * inside it, so the menu is never lost — a section off the menu is exactly
709
- * the case that would otherwise render blank.
694
+ * @param {object|null|undefined} item — a menu item as the API serves it.
695
+ * @returns {boolean}
696
+ */
697
+ function isSubMenuItem(item) {
698
+ return isPlainObject(item) && !item.page_id && !item.url;
699
+ }
700
+
701
+ /**
702
+ * sc-14098 — a menu's flat entries as both hosts draw them: the top-level
703
+ * ones in order, each sub-menu carrying its own as `children`. The one
704
+ * grouping the web chrome and the compiler read, so a page cannot sit in a
705
+ * sub-menu on one host and at the top level on the other (§8).
710
706
  *
711
- * sc-10693: `trees` answers EVERY section, not only the visitor's own, so a
712
- * section's entry can offer its menu from any page. `under` / `items` /
713
- * `standalone` still name the one the visitor is inside.
707
+ * An entry naming no sub-menu of the list stands at the top level; a
708
+ * sub-menu left with nothing in it (its pages hidden from this visitor, say)
709
+ * is dropped rather than drawn as a heading over nothing.
714
710
  *
715
- * @param {{ entries?: unknown, active?: unknown, sections?: unknown }} input
716
- * `entries` — the global menu's keys, in menu order.
717
- * `active` — the key of the page being viewed.
718
- * `sections` — `{ [key]: { menu, items } }` for pages whose local nav is
719
- * `SIDEBAR`; `menu` identifies the saved menu, `items` carry their own key.
720
- * @returns {{ under: string|null, items: Array<object>, standalone: boolean, trees: Array<object> }}
721
- * `under` is null when the visitor is in no section; when `standalone` it
722
- * names the section's own page, which the host draws as the entry. Each
723
- * item is returned with a `current` flag rather than leaving each host to
724
- * recompute it. `trees` lists `{ under, items, standalone, inside }` in menu
725
- * order, a `standalone` one last; `inside` marks the visitor's own.
711
+ * @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).
715
+ * @returns {Array<object>} the top-level entries; a sub-menu is returned as
716
+ * `{ ...entry, children }`, every other entry as it came.
726
717
  */
727
- function resolveSidebarUnfold(input) {
728
- const { entries, active, sections } = isPlainObject(input) ? input : {};
729
- const viewed = typeof active === "string" && active ? active : null;
730
- const bank = isPlainObject(sections) ? sections : {};
731
- const order = Array.isArray(entries) ? entries : [];
732
- const sectionAt = (key) => {
733
- const candidate = isPlainObject(bank[key]) ? bank[key] : null;
734
- const items = candidate && Array.isArray(candidate.items) ? candidate.items : [];
735
- return items.length ? { key, menu: candidate.menu, items } : null;
736
- };
737
- const lists = (key) => {
738
- const candidate = sectionAt(key);
739
- return (
740
- Boolean(candidate) &&
741
- candidate.items.some(
742
- (item) => isPlainObject(item) && item.key === viewed,
743
- )
744
- );
745
- };
746
- // The page's own section wins; otherwise the section whose menu lists it,
747
- // preferring one a global entry carries so the tree hangs where it always
748
- // does. Both are the same section from the visitor's side.
749
- const section = viewed
750
- ? sectionAt(viewed) ||
751
- sectionAt(order.find(lists)) ||
752
- sectionAt(Object.keys(bank).find(lists))
753
- : null;
754
- const mark = (items) =>
755
- items.map((item) => ({
756
- ...(isPlainObject(item) ? item : {}),
757
- current:
758
- viewed !== null &&
759
- isPlainObject(item) &&
760
- typeof item.key === "string" &&
761
- item.key === viewed,
762
- }));
763
- // A saved menu hangs under the FIRST global entry carrying it, so two
764
- // entries sharing one menu never draw it twice.
765
- const claimed = [];
766
- const trees = [];
767
- for (const key of order) {
768
- if (!isPlainObject(bank[key])) continue;
769
- const { menu } = bank[key];
770
- if (claimed.includes(menu)) continue;
771
- claimed.push(menu);
772
- // An unusable key still owns its menu: nothing may hang it elsewhere.
773
- if (typeof key !== "string" || !key) continue;
774
- const inside = Boolean(section) && menu === section.menu;
775
- const own = inside ? section : sectionAt(key);
776
- if (!own) continue;
777
- trees.push({ under: key, items: mark(own.items), standalone: false, inside });
778
- }
779
- if (!section) return { under: null, items: [], standalone: false, trees };
780
- const owned = trees.find((tree) => tree.inside);
781
- if (owned) {
782
- return { under: owned.under, items: owned.items, standalone: false, trees };
783
- }
784
- const alone = {
785
- under: section.key,
786
- items: mark(section.items),
787
- standalone: true,
788
- inside: true,
789
- };
790
- return {
791
- under: alone.under,
792
- items: alone.items,
793
- standalone: true,
794
- trees: [...trees, alone],
718
+ function menuTree(entries, { of = (entry) => entry } = {}) {
719
+ const list = Array.isArray(entries) ? entries.filter(isPlainObject) : [];
720
+ const read = (entry) => (isPlainObject(of(entry)) ? of(entry) : {});
721
+ const subMenuIds = new Set(
722
+ list.filter((entry) => read(entry).submenu === true).map((entry) => read(entry).id),
723
+ );
724
+ const parentOf = (entry) => {
725
+ const { parent_id: parent, submenu } = read(entry);
726
+ return submenu !== true && typeof parent === "string" && subMenuIds.has(parent) ? parent : null;
795
727
  };
728
+ return list
729
+ .filter((entry) => parentOf(entry) === null)
730
+ .flatMap((entry) => {
731
+ if (read(entry).submenu !== true) return [entry];
732
+ const children = list.filter((child) => parentOf(child) === read(entry).id);
733
+ return children.length ? [{ ...entry, children }] : [];
734
+ });
796
735
  }
797
736
 
798
737
  /**
799
- * REQ-NAV-LOCAL (sc-8901) — which local-navigation model a page wears in ONE
800
- * device view, so the same saved menu can be a bottom bar on a phone and unfold
801
- * in the rail on a desktop.
738
+ * REQ-NAV-LOCAL (sc-8901, sc-12397) — how a menu is drawn in ONE device
739
+ * view, so the same menu can be a bottom bar on a phone and a tab row on a
740
+ * desktop. Since sc-12397 the MENU owns this, not each page.
802
741
  *
803
- * `local_nav` is the MOBILE value and the base of the cascade: a page authored
804
- * before the wider views existed leaves both of them unset and therefore
805
- * renders identically at every width. The cascade is REQ-LAY-07's — the one the
742
+ * `layout` is the MOBILE value and the base of the cascade; a wider view left
743
+ * null follows the narrower one. The cascade is REQ-LAY-07's — the one the
806
744
  * layout grid and every responsive widget prop already use — because a page's
807
745
  * chrome and its content must not disagree about what a tablet is.
808
746
  *
@@ -810,21 +748,21 @@ function resolveSidebarUnfold(input) {
810
748
  * host's own switch decides what it can draw, so a kind a newer backend allows
811
749
  * cascades correctly here instead of being flattened to `NONE` on the way.
812
750
  *
813
- * @param {object|null|undefined} page — a page row carrying `local_nav` and,
814
- * optionally, `local_nav_tablet` / `local_nav_desktop`.
751
+ * @param {object|null|undefined} menu — a menu carrying `layout` and,
752
+ * optionally, `layout_tablet` / `layout_desktop`. No menu draws nothing.
815
753
  * @param {"mobile"|"tablet"|"desktop"} view — the device view being drawn.
816
- * @returns {string} the model for that view; `NONE` when the page sets none.
754
+ * @returns {string} the model for that view; `NONE` when the menu sets none.
817
755
  */
818
- function resolveLocalNavModel(page, view) {
756
+ function resolveLocalNavModel(menu, view) {
819
757
  const at = (key) => {
820
- const value = isPlainObject(page) ? page[key] : null;
758
+ const value = isPlainObject(menu) ? menu[key] : null;
821
759
  return typeof value === "string" && value ? value : null;
822
760
  };
823
- const mobile = at("local_nav") || "NONE";
761
+ const mobile = at("layout") || "NONE";
824
762
  if (view === "desktop") {
825
- return at("local_nav_desktop") || at("local_nav_tablet") || mobile;
763
+ return at("layout_desktop") || at("layout_tablet") || mobile;
826
764
  }
827
- if (view === "tablet") return at("local_nav_tablet") || mobile;
765
+ if (view === "tablet") return at("layout_tablet") || mobile;
828
766
  return mobile;
829
767
  }
830
768
 
@@ -834,25 +772,117 @@ function resolveLocalNavModel(page, view) {
834
772
  const LOCAL_NAV_VIEWS = ["mobile", "tablet", "desktop"];
835
773
 
836
774
  /**
837
- * REQ-NAV-LOCAL (sc-8901) — does this page draw a local bar in ANY device view?
775
+ * REQ-NAV-LOCAL (sc-8901) — does this menu draw a bar in ANY device view?
838
776
  *
839
- * The saved-menu reference is shared by all three views, so it is required — and
840
- * resolved onto the wire — as soon as one of them draws. Asking
841
- * `local_nav !== "NONE"` alone would miss a page that carries a bar only on the
842
- * wider views.
777
+ * Beside the cascade it is derived from, so the API, the export's screen bake
778
+ * and the Studio cannot disagree about which pages show a bar.
843
779
  *
844
- * Beside the cascade it is derived from, so the API rule, the export's screen
845
- * bake and Copy Workspace cannot disagree about which pages have a bar.
846
- *
847
- * @param {object|null|undefined} page — a page row.
780
+ * @param {object|null|undefined} menu — a menu row, or its layout fields.
848
781
  * @returns {boolean}
849
782
  */
850
- function drawsLocalNavAnywhere(page) {
783
+ function drawsLocalNavAnywhere(menu) {
851
784
  return LOCAL_NAV_VIEWS.some(
852
- (view) => resolveLocalNavModel(page, view) !== "NONE",
785
+ (view) => resolveLocalNavModel(menu, view) !== "NONE",
853
786
  );
854
787
  }
855
788
 
789
+ /**
790
+ * sc-12426 — does the app's main menu frame this page? A page it leaves out
791
+ * is full screen. Asked by the Player per render and by the compiler per
792
+ * screen, so both hosts frame the same pages (§8).
793
+ *
794
+ * @param {{appears_on?: string, page_ids?: string[]}|null|undefined} menu —
795
+ * the main menu; absent frames every page.
796
+ * @param {string} pageId
797
+ * @returns {boolean}
798
+ */
799
+ function mainMenuAppearsOn(menu, pageId) {
800
+ if (!isPlainObject(menu) || menu.appears_on !== "ALL_EXCEPT") return true;
801
+ return !(Array.isArray(menu.page_ids) && menu.page_ids.includes(pageId));
802
+ }
803
+
804
+ /**
805
+ * sc-12530 — the place on the page each layout draws in. Two menus in one
806
+ * place would stack, so a page shows at most one per place per view.
807
+ */
808
+ const LOCAL_NAV_POSITIONS = Object.freeze({
809
+ TOP_BAR: "top",
810
+ BOTTOM_BAR: "bottom",
811
+ SIDEBAR: "side",
812
+ HEADER: "header",
813
+ });
814
+
815
+ /**
816
+ * sc-12530 — where a model draws; null for `NONE`. A kind this SDK does not
817
+ * know is its own place, so two of them still never stack.
818
+ *
819
+ * @param {string} model — from resolveLocalNavModel.
820
+ * @returns {string|null}
821
+ */
822
+ function localNavPosition(model) {
823
+ if (!model || model === "NONE") return null;
824
+ return LOCAL_NAV_POSITIONS[model] || model;
825
+ }
826
+
827
+ /**
828
+ * sc-12530 — the section menus a page draws in ONE device view, at most one
829
+ * per position. A menu picked for this page (`appears_on: "SELECTED"`) wins
830
+ * its position over one shown on all pages; between equals the first listed
831
+ * wins. The server refuses a save that would leave a tie (409
832
+ * MENU_POSITION_CLASH), so the tie-break only steadies older data. Asked by
833
+ * the Player per render and by the compiler per screen (§8).
834
+ *
835
+ * @param {Array<object>|null|undefined} menus — the page's `local_nav_menus`.
836
+ * @param {"mobile"|"tablet"|"desktop"} view
837
+ * @returns {Object<string, {menu: object, model: string}>} by position.
838
+ */
839
+ function resolvePageBars(menus, view) {
840
+ const bars = {};
841
+ const specific = (menu) => menu.appears_on === "SELECTED";
842
+ for (const menu of Array.isArray(menus) ? menus : []) {
843
+ if (!isPlainObject(menu)) continue;
844
+ const model = resolveLocalNavModel(menu, view);
845
+ const position = localNavPosition(model);
846
+ if (!position) continue;
847
+ const held = bars[position];
848
+ if (held && (specific(held.menu) || !specific(menu))) continue;
849
+ bars[position] = { menu, model };
850
+ }
851
+ return bars;
852
+ }
853
+
854
+ /**
855
+ * sc-12427 — whether a menu is a Top navigation bar at any view. The Studio
856
+ * styles that bar only for an app that draws one.
857
+ *
858
+ * @param {object|null|undefined} menu
859
+ * @returns {boolean}
860
+ */
861
+ function drawsTopNavigation(menu) {
862
+ return ["mobile", "tablet", "desktop"].some(
863
+ (view) => resolveLocalNavModel(menu, view) === "HEADER",
864
+ );
865
+ }
866
+
867
+ /**
868
+ * sc-12427 — the pages a Top navigation bar links to, at any view: they are
869
+ * top-level destinations, as the main menu's are, so neither host offers a
870
+ * back control on them.
871
+ *
872
+ * @param {Array<object>|null|undefined} menus — every menu a page may draw.
873
+ * @returns {Set<string>} page ids.
874
+ */
875
+ function topNavigationPageIds(menus) {
876
+ const ids = new Set();
877
+ for (const menu of Array.isArray(menus) ? menus : []) {
878
+ if (!isPlainObject(menu) || !drawsTopNavigation(menu)) continue;
879
+ for (const item of Array.isArray(menu.items) ? menu.items : []) {
880
+ if (isPlainObject(item) && typeof item.page_id === "string") ids.add(item.page_id);
881
+ }
882
+ }
883
+ return ids;
884
+ }
885
+
856
886
  // REQ-THEME-LOOK: the divider's width in px, bounded HERE so both hosts inherit
857
887
  // one range. The export clamped it on its way into the StyleSheet
858
888
  // (`coerceBorderWidth(...) ?? 1`) where the Player passed any finite number
@@ -910,7 +940,14 @@ module.exports = {
910
940
  isDarkSurface,
911
941
  resolveAppLogo,
912
942
  resolveTopBarTokens,
913
- resolveSidebarUnfold,
943
+ isSubMenuItem,
944
+ menuTree,
914
945
  resolveLocalNavModel,
915
946
  drawsLocalNavAnywhere,
947
+ mainMenuAppearsOn,
948
+ LOCAL_NAV_POSITIONS,
949
+ localNavPosition,
950
+ resolvePageBars,
951
+ drawsTopNavigation,
952
+ topNavigationPageIds,
916
953
  };
@@ -62,7 +62,7 @@ export function menuItemCap(menuType) {
62
62
  // navigation bar is drawn from.
63
63
  //
64
64
  // sc-7753: the global quick bar these tokens were introduced for is retired;
65
- // the bar that reads them now is the page's own (`local_nav = BOTTOM_BAR`).
65
+ // the bar that reads them now is a section menu's (`layout = BOTTOM_BAR`).
66
66
  //
67
67
  // sc-8033: the block is SELF-CONTAINED — it reads `theme.footer` and nothing
68
68
  // else. Every colour used to fall back to the rail's, so restyling the sidebar
@@ -683,121 +683,59 @@ export function resolveTopBarTokens(theme) {
683
683
  }
684
684
 
685
685
  /**
686
- * REQ-NAV-LOCAL (sc-7696) — where a page's `SIDEBAR` local menu unfolds.
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.
687
688
  *
688
- * The one derivation both hosts read, so the web rail, the web drawer and the
689
- * exported app's drawer cannot disagree about what hangs under what. Keys are
690
- * the caller's own (the web Player passes page slugs, the compiler passes
691
- * screen names); this only compares them.
692
- *
693
- * A page belongs to a section in either of two ways, and both keep the tree
694
- * open: it CARRIES the model itself, or the section's menu LISTS it. The
695
- * second is what makes the model usable — clicking a destination would
696
- * otherwise collapse the menu that led there unless the author repeated the
697
- * setting on every sub-page.
698
- *
699
- * The unfold point is the first GLOBAL menu entry carrying that section's
700
- * saved menu, so the tree hangs in the same place from every page of the
701
- * section. When the global menu lists no such page, the section's own page
702
- * becomes a top-level entry (`standalone`) for as long as the visitor is
703
- * inside it, so the menu is never lost — a section off the menu is exactly
704
- * the case that would otherwise render blank.
689
+ * @param {object|null|undefined} item — a menu item as the API serves it.
690
+ * @returns {boolean}
691
+ */
692
+ export function isSubMenuItem(item) {
693
+ return isPlainObject(item) && !item.page_id && !item.url;
694
+ }
695
+
696
+ /**
697
+ * sc-14098 — a menu's flat entries as both hosts draw them: the top-level
698
+ * ones in order, each sub-menu carrying its own as `children`. The one
699
+ * grouping the web chrome and the compiler read, so a page cannot sit in a
700
+ * sub-menu on one host and at the top level on the other (§8).
705
701
  *
706
- * sc-10693: `trees` answers EVERY section, not only the visitor's own, so a
707
- * section's entry can offer its menu from any page. `under` / `items` /
708
- * `standalone` still name the one the visitor is inside.
702
+ * An entry naming no sub-menu of the list stands at the top level; a
703
+ * sub-menu left with nothing in it (its pages hidden from this visitor, say)
704
+ * is dropped rather than drawn as a heading over nothing.
709
705
  *
710
- * @param {{ entries?: unknown, active?: unknown, sections?: unknown }} input
711
- * `entries` — the global menu's keys, in menu order.
712
- * `active` — the key of the page being viewed.
713
- * `sections` — `{ [key]: { menu, items } }` for pages whose local nav is
714
- * `SIDEBAR`; `menu` identifies the saved menu, `items` carry their own key.
715
- * @returns {{ under: string|null, items: Array<object>, standalone: boolean, trees: Array<object> }}
716
- * `under` is null when the visitor is in no section; when `standalone` it
717
- * names the section's own page, which the host draws as the entry. Each
718
- * item is returned with a `current` flag rather than leaving each host to
719
- * recompute it. `trees` lists `{ under, items, standalone, inside }` in menu
720
- * order, a `standalone` one last; `inside` marks the visitor's own.
706
+ * @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).
710
+ * @returns {Array<object>} the top-level entries; a sub-menu is returned as
711
+ * `{ ...entry, children }`, every other entry as it came.
721
712
  */
722
- export function resolveSidebarUnfold(input) {
723
- const { entries, active, sections } = isPlainObject(input) ? input : {};
724
- const viewed = typeof active === "string" && active ? active : null;
725
- const bank = isPlainObject(sections) ? sections : {};
726
- const order = Array.isArray(entries) ? entries : [];
727
- const sectionAt = (key) => {
728
- const candidate = isPlainObject(bank[key]) ? bank[key] : null;
729
- const items = candidate && Array.isArray(candidate.items) ? candidate.items : [];
730
- return items.length ? { key, menu: candidate.menu, items } : null;
731
- };
732
- const lists = (key) => {
733
- const candidate = sectionAt(key);
734
- return (
735
- Boolean(candidate) &&
736
- candidate.items.some(
737
- (item) => isPlainObject(item) && item.key === viewed,
738
- )
739
- );
740
- };
741
- // The page's own section wins; otherwise the section whose menu lists it,
742
- // preferring one a global entry carries so the tree hangs where it always
743
- // does. Both are the same section from the visitor's side.
744
- const section = viewed
745
- ? sectionAt(viewed) ||
746
- sectionAt(order.find(lists)) ||
747
- sectionAt(Object.keys(bank).find(lists))
748
- : null;
749
- const mark = (items) =>
750
- items.map((item) => ({
751
- ...(isPlainObject(item) ? item : {}),
752
- current:
753
- viewed !== null &&
754
- isPlainObject(item) &&
755
- typeof item.key === "string" &&
756
- item.key === viewed,
757
- }));
758
- // A saved menu hangs under the FIRST global entry carrying it, so two
759
- // entries sharing one menu never draw it twice.
760
- const claimed = [];
761
- const trees = [];
762
- for (const key of order) {
763
- if (!isPlainObject(bank[key])) continue;
764
- const { menu } = bank[key];
765
- if (claimed.includes(menu)) continue;
766
- claimed.push(menu);
767
- // An unusable key still owns its menu: nothing may hang it elsewhere.
768
- if (typeof key !== "string" || !key) continue;
769
- const inside = Boolean(section) && menu === section.menu;
770
- const own = inside ? section : sectionAt(key);
771
- if (!own) continue;
772
- trees.push({ under: key, items: mark(own.items), standalone: false, inside });
773
- }
774
- if (!section) return { under: null, items: [], standalone: false, trees };
775
- const owned = trees.find((tree) => tree.inside);
776
- if (owned) {
777
- return { under: owned.under, items: owned.items, standalone: false, trees };
778
- }
779
- const alone = {
780
- under: section.key,
781
- items: mark(section.items),
782
- standalone: true,
783
- inside: true,
784
- };
785
- return {
786
- under: alone.under,
787
- items: alone.items,
788
- standalone: true,
789
- trees: [...trees, alone],
713
+ export function menuTree(entries, { of = (entry) => entry } = {}) {
714
+ const list = Array.isArray(entries) ? entries.filter(isPlainObject) : [];
715
+ const read = (entry) => (isPlainObject(of(entry)) ? of(entry) : {});
716
+ const subMenuIds = new Set(
717
+ list.filter((entry) => read(entry).submenu === true).map((entry) => read(entry).id),
718
+ );
719
+ const parentOf = (entry) => {
720
+ const { parent_id: parent, submenu } = read(entry);
721
+ return submenu !== true && typeof parent === "string" && subMenuIds.has(parent) ? parent : null;
790
722
  };
723
+ return list
724
+ .filter((entry) => parentOf(entry) === null)
725
+ .flatMap((entry) => {
726
+ if (read(entry).submenu !== true) return [entry];
727
+ const children = list.filter((child) => parentOf(child) === read(entry).id);
728
+ return children.length ? [{ ...entry, children }] : [];
729
+ });
791
730
  }
792
731
 
793
732
  /**
794
- * REQ-NAV-LOCAL (sc-8901) — which local-navigation model a page wears in ONE
795
- * device view, so the same saved menu can be a bottom bar on a phone and unfold
796
- * in the rail on a desktop.
733
+ * REQ-NAV-LOCAL (sc-8901, sc-12397) — how a menu is drawn in ONE device
734
+ * view, so the same menu can be a bottom bar on a phone and a tab row on a
735
+ * desktop. Since sc-12397 the MENU owns this, not each page.
797
736
  *
798
- * `local_nav` is the MOBILE value and the base of the cascade: a page authored
799
- * before the wider views existed leaves both of them unset and therefore
800
- * renders identically at every width. The cascade is REQ-LAY-07's — the one the
737
+ * `layout` is the MOBILE value and the base of the cascade; a wider view left
738
+ * null follows the narrower one. The cascade is REQ-LAY-07's — the one the
801
739
  * layout grid and every responsive widget prop already use — because a page's
802
740
  * chrome and its content must not disagree about what a tablet is.
803
741
  *
@@ -805,21 +743,21 @@ export function resolveSidebarUnfold(input) {
805
743
  * host's own switch decides what it can draw, so a kind a newer backend allows
806
744
  * cascades correctly here instead of being flattened to `NONE` on the way.
807
745
  *
808
- * @param {object|null|undefined} page — a page row carrying `local_nav` and,
809
- * optionally, `local_nav_tablet` / `local_nav_desktop`.
746
+ * @param {object|null|undefined} menu — a menu carrying `layout` and,
747
+ * optionally, `layout_tablet` / `layout_desktop`. No menu draws nothing.
810
748
  * @param {"mobile"|"tablet"|"desktop"} view — the device view being drawn.
811
- * @returns {string} the model for that view; `NONE` when the page sets none.
749
+ * @returns {string} the model for that view; `NONE` when the menu sets none.
812
750
  */
813
- export function resolveLocalNavModel(page, view) {
751
+ export function resolveLocalNavModel(menu, view) {
814
752
  const at = (key) => {
815
- const value = isPlainObject(page) ? page[key] : null;
753
+ const value = isPlainObject(menu) ? menu[key] : null;
816
754
  return typeof value === "string" && value ? value : null;
817
755
  };
818
- const mobile = at("local_nav") || "NONE";
756
+ const mobile = at("layout") || "NONE";
819
757
  if (view === "desktop") {
820
- return at("local_nav_desktop") || at("local_nav_tablet") || mobile;
758
+ return at("layout_desktop") || at("layout_tablet") || mobile;
821
759
  }
822
- if (view === "tablet") return at("local_nav_tablet") || mobile;
760
+ if (view === "tablet") return at("layout_tablet") || mobile;
823
761
  return mobile;
824
762
  }
825
763
 
@@ -829,25 +767,117 @@ export function resolveLocalNavModel(page, view) {
829
767
  const LOCAL_NAV_VIEWS = ["mobile", "tablet", "desktop"];
830
768
 
831
769
  /**
832
- * REQ-NAV-LOCAL (sc-8901) — does this page draw a local bar in ANY device view?
770
+ * REQ-NAV-LOCAL (sc-8901) — does this menu draw a bar in ANY device view?
833
771
  *
834
- * The saved-menu reference is shared by all three views, so it is required — and
835
- * resolved onto the wire — as soon as one of them draws. Asking
836
- * `local_nav !== "NONE"` alone would miss a page that carries a bar only on the
837
- * wider views.
772
+ * Beside the cascade it is derived from, so the API, the export's screen bake
773
+ * and the Studio cannot disagree about which pages show a bar.
838
774
  *
839
- * Beside the cascade it is derived from, so the API rule, the export's screen
840
- * bake and Copy Workspace cannot disagree about which pages have a bar.
841
- *
842
- * @param {object|null|undefined} page — a page row.
775
+ * @param {object|null|undefined} menu — a menu row, or its layout fields.
843
776
  * @returns {boolean}
844
777
  */
845
- export function drawsLocalNavAnywhere(page) {
778
+ export function drawsLocalNavAnywhere(menu) {
846
779
  return LOCAL_NAV_VIEWS.some(
847
- (view) => resolveLocalNavModel(page, view) !== "NONE",
780
+ (view) => resolveLocalNavModel(menu, view) !== "NONE",
848
781
  );
849
782
  }
850
783
 
784
+ /**
785
+ * sc-12426 — does the app's main menu frame this page? A page it leaves out
786
+ * is full screen. Asked by the Player per render and by the compiler per
787
+ * screen, so both hosts frame the same pages (§8).
788
+ *
789
+ * @param {{appears_on?: string, page_ids?: string[]}|null|undefined} menu —
790
+ * the main menu; absent frames every page.
791
+ * @param {string} pageId
792
+ * @returns {boolean}
793
+ */
794
+ export function mainMenuAppearsOn(menu, pageId) {
795
+ if (!isPlainObject(menu) || menu.appears_on !== "ALL_EXCEPT") return true;
796
+ return !(Array.isArray(menu.page_ids) && menu.page_ids.includes(pageId));
797
+ }
798
+
799
+ /**
800
+ * sc-12530 — the place on the page each layout draws in. Two menus in one
801
+ * place would stack, so a page shows at most one per place per view.
802
+ */
803
+ export const LOCAL_NAV_POSITIONS = Object.freeze({
804
+ TOP_BAR: "top",
805
+ BOTTOM_BAR: "bottom",
806
+ SIDEBAR: "side",
807
+ HEADER: "header",
808
+ });
809
+
810
+ /**
811
+ * sc-12530 — where a model draws; null for `NONE`. A kind this SDK does not
812
+ * know is its own place, so two of them still never stack.
813
+ *
814
+ * @param {string} model — from resolveLocalNavModel.
815
+ * @returns {string|null}
816
+ */
817
+ export function localNavPosition(model) {
818
+ if (!model || model === "NONE") return null;
819
+ return LOCAL_NAV_POSITIONS[model] || model;
820
+ }
821
+
822
+ /**
823
+ * sc-12530 — the section menus a page draws in ONE device view, at most one
824
+ * per position. A menu picked for this page (`appears_on: "SELECTED"`) wins
825
+ * its position over one shown on all pages; between equals the first listed
826
+ * wins. The server refuses a save that would leave a tie (409
827
+ * MENU_POSITION_CLASH), so the tie-break only steadies older data. Asked by
828
+ * the Player per render and by the compiler per screen (§8).
829
+ *
830
+ * @param {Array<object>|null|undefined} menus — the page's `local_nav_menus`.
831
+ * @param {"mobile"|"tablet"|"desktop"} view
832
+ * @returns {Object<string, {menu: object, model: string}>} by position.
833
+ */
834
+ export function resolvePageBars(menus, view) {
835
+ const bars = {};
836
+ const specific = (menu) => menu.appears_on === "SELECTED";
837
+ for (const menu of Array.isArray(menus) ? menus : []) {
838
+ if (!isPlainObject(menu)) continue;
839
+ const model = resolveLocalNavModel(menu, view);
840
+ const position = localNavPosition(model);
841
+ if (!position) continue;
842
+ const held = bars[position];
843
+ if (held && (specific(held.menu) || !specific(menu))) continue;
844
+ bars[position] = { menu, model };
845
+ }
846
+ return bars;
847
+ }
848
+
849
+ /**
850
+ * sc-12427 — whether a menu is a Top navigation bar at any view. The Studio
851
+ * styles that bar only for an app that draws one.
852
+ *
853
+ * @param {object|null|undefined} menu
854
+ * @returns {boolean}
855
+ */
856
+ export function drawsTopNavigation(menu) {
857
+ return ["mobile", "tablet", "desktop"].some(
858
+ (view) => resolveLocalNavModel(menu, view) === "HEADER",
859
+ );
860
+ }
861
+
862
+ /**
863
+ * sc-12427 — the pages a Top navigation bar links to, at any view: they are
864
+ * top-level destinations, as the main menu's are, so neither host offers a
865
+ * back control on them.
866
+ *
867
+ * @param {Array<object>|null|undefined} menus — every menu a page may draw.
868
+ * @returns {Set<string>} page ids.
869
+ */
870
+ export function topNavigationPageIds(menus) {
871
+ const ids = new Set();
872
+ for (const menu of Array.isArray(menus) ? menus : []) {
873
+ if (!isPlainObject(menu) || !drawsTopNavigation(menu)) continue;
874
+ for (const item of Array.isArray(menu.items) ? menu.items : []) {
875
+ if (isPlainObject(item) && typeof item.page_id === "string") ids.add(item.page_id);
876
+ }
877
+ }
878
+ return ids;
879
+ }
880
+
851
881
  // REQ-THEME-LOOK: the divider's width in px, bounded HERE so both hosts inherit
852
882
  // one range. The export clamped it on its way into the StyleSheet
853
883
  // (`coerceBorderWidth(...) ?? 1`) where the Player passed any finite number
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.332.0",
3
+ "version": "0.333.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/contract.js CHANGED
@@ -6465,7 +6465,7 @@ const CONTRACT = deepFreeze({
6465
6465
  // it. The app's global mobile quick bar is retired: it was a SELECTION
6466
6466
  // over the global menu, and the rail and drawer list every menu page
6467
6467
  // regardless, so nothing was reachable only through it. The bottom edge
6468
- // belongs to a PAGE's own bottom navigation bar (`local_nav = BOTTOM_BAR`,
6468
+ // belongs to a section menu's bottom navigation bar (`layout = BOTTOM_BAR`,
6469
6469
  // REQ-NAV-LOCAL), chosen per page. `resolveFooterTokens` is unchanged —
6470
6470
  // it is the bottom edge's token set and the surviving bar reads it.
6471
6471
  // 1.113.0: additive (sc-7951) — `resolveFooterTokens` gains the bottom