@colixsystems/widget-sdk 0.338.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 +6 -2
- package/dist/contract.cjs +10 -4
- package/dist/contract.js +10 -4
- package/dist/host.d.ts +35 -4
- package/dist/host.js +6 -0
- package/dist/index.d.ts +4 -1
- package/dist/navigation.cjs +116 -8
- package/dist/navigation.js +111 -8
- package/package.json +1 -1
- package/src/contract.js +10 -4
package/README.md
CHANGED
|
@@ -91,7 +91,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
91
|
|
|
92
92
|
## Status
|
|
93
93
|
|
|
94
|
-
`v0.
|
|
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
|
+
|
|
96
|
+
### What's new in 0.339.0 (contract 1.277.0)
|
|
97
|
+
|
|
98
|
+
**An Action a widget runs gets its 500 ms to itself.** The 500 ms now counts from the script's first statement, so the time AppStudio spends setting the run up no longer eats into it. The whole press is still bounded: it waits at most 200 ms for a free sandbox and is over 1 s after it reaches the server, so a press can now wait up to about 1 s before `run()` rejects with `ACTION_TIMEOUT` (504), whose outcome stays unknown. A press that could not start its script in time (the sandboxes were busy, or setup ran past 1 s) now rejects with `RATE_LIMITED` (429, `Retry-After: 1`) instead of `ACTION_TIMEOUT`: nothing ran, so a retry is safe. No hook, export or code was added.
|
|
95
99
|
|
|
96
100
|
### What's new in 0.338.0 (contract 1.276.0)
|
|
97
101
|
|
|
@@ -582,7 +586,7 @@ const { available, run, running, result, error } = useAction(props.actionId);
|
|
|
582
586
|
|
|
583
587
|
**Bind it with an `actionRef` property.** Declare `{ type: "actionRef" }` in your `propertySchema` and the Studio renders an Action picker that warns when the chosen Action lacks the app trigger. The value is a bare Action id, so Copy Workspace remaps it like `pageRef`.
|
|
584
588
|
|
|
585
|
-
When nothing is bound, or the host brokers no actions client, `available` is `false` and `run()` rejects `UNAVAILABLE`: render a visible "pick an action" state, never a blank box. A changed binding clears `result` and `error`, and a run that settles after the binding changed or the widget unmounted writes nothing. When runs overlap, `result` and `error` follow the newest one. Branch on `error.code`: `ACTION_NOT_APP_INVOKABLE` and `ACTION_NOT_FOUND` will not clear on a retry, `RATE_LIMITED` will, `INVALID_ACTION_INPUT` means the input was refused, `AUTH_REQUIRED`, `TOKEN_EXPIRED` and `TOKEN_INVALID` mean the app user must sign in, `ACTION_FAILED` means the Action ran and failed, and `ACTION_TIMEOUT` means
|
|
589
|
+
When nothing is bound, or the host brokers no actions client, `available` is `false` and `run()` rejects `UNAVAILABLE`: render a visible "pick an action" state, never a blank box. A changed binding clears `result` and `error`, and a run that settles after the binding changed or the widget unmounted writes nothing. When runs overlap, `result` and `error` follow the newest one. Branch on `error.code`: `ACTION_NOT_APP_INVOKABLE` and `ACTION_NOT_FOUND` will not clear on a retry, `RATE_LIMITED` will (from `run()` it can also mean the server was too busy to start the script, so nothing ran), `INVALID_ACTION_INPUT` means the input was refused, `AUTH_REQUIRED`, `TOKEN_EXPIRED` and `TOKEN_INVALID` mean the app user must sign in, `ACTION_FAILED` means the Action ran and failed, and `ACTION_TIMEOUT` means its script ran for 500 ms of its own, or the press reached 1 s, and was stopped, so its outcome is unknown: some of its writes may have happened. Never show an app user the raw message. A text answer from a bot is often markdown, so render it with `<RichText>`.
|
|
586
590
|
|
|
587
591
|
The linter rejects `useAction()` unless your manifest declares `actions.run:*` in `requestedScopes`.
|
|
588
592
|
|
package/dist/contract.cjs
CHANGED
|
@@ -2341,9 +2341,11 @@ const HOOKS = [
|
|
|
2341
2341
|
"(or after unmount) writes nothing. ActionError.code: " +
|
|
2342
2342
|
"INVALID_ACTION_INPUT (400) — the input was refused; " +
|
|
2343
2343
|
"ACTION_NOT_APP_INVOKABLE (403) and ACTION_NOT_FOUND (404) will NOT " +
|
|
2344
|
-
"clear on a retry, so hide the affordance; RATE_LIMITED (429) will
|
|
2345
|
-
"
|
|
2346
|
-
"
|
|
2344
|
+
"clear on a retry, so hide the affordance; RATE_LIMITED (429) will, and " +
|
|
2345
|
+
"from run() it can also mean the server was too busy to start the " +
|
|
2346
|
+
"script, so nothing ran; " +
|
|
2347
|
+
"ACTION_TIMEOUT (504) — the script ran for 500 ms of its own, or the " +
|
|
2348
|
+
"press reached 1 s, and was stopped, so its OUTCOME IS UNKNOWN: some of its writes may " +
|
|
2347
2349
|
"have happened. Never retry it blindly and never tell the user it did " +
|
|
2348
2350
|
"nothing; an Action a widget runs must do its writes as one call or be " +
|
|
2349
2351
|
"safe to repeat, and slow or multi-step work belongs in a " +
|
|
@@ -7117,7 +7119,11 @@ const CONTRACT = deepFreeze({
|
|
|
7117
7119
|
// 1.276.0: stricter lint (sc-17764) — a widget that calls a key
|
|
7118
7120
|
// useDatastoreMutation() does not return is the publish-blocking
|
|
7119
7121
|
// `datastore-method-unknown` finding.
|
|
7120
|
-
|
|
7122
|
+
// 1.277.0: behaviour (sc-17821) — an app run's 500 ms counts only the
|
|
7123
|
+
// script's own run, inside a 1 s cap on the whole press, so a press can
|
|
7124
|
+
// wait up to about 1 s before ACTION_TIMEOUT. A press that never started
|
|
7125
|
+
// its script rejects RATE_LIMITED (429, Retry-After: 1): nothing ran.
|
|
7126
|
+
version: "1.277.0",
|
|
7121
7127
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7122
7128
|
hooks: HOOKS,
|
|
7123
7129
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -2336,9 +2336,11 @@ const HOOKS = [
|
|
|
2336
2336
|
"(or after unmount) writes nothing. ActionError.code: " +
|
|
2337
2337
|
"INVALID_ACTION_INPUT (400) — the input was refused; " +
|
|
2338
2338
|
"ACTION_NOT_APP_INVOKABLE (403) and ACTION_NOT_FOUND (404) will NOT " +
|
|
2339
|
-
"clear on a retry, so hide the affordance; RATE_LIMITED (429) will
|
|
2340
|
-
"
|
|
2341
|
-
"
|
|
2339
|
+
"clear on a retry, so hide the affordance; RATE_LIMITED (429) will, and " +
|
|
2340
|
+
"from run() it can also mean the server was too busy to start the " +
|
|
2341
|
+
"script, so nothing ran; " +
|
|
2342
|
+
"ACTION_TIMEOUT (504) — the script ran for 500 ms of its own, or the " +
|
|
2343
|
+
"press reached 1 s, and was stopped, so its OUTCOME IS UNKNOWN: some of its writes may " +
|
|
2342
2344
|
"have happened. Never retry it blindly and never tell the user it did " +
|
|
2343
2345
|
"nothing; an Action a widget runs must do its writes as one call or be " +
|
|
2344
2346
|
"safe to repeat, and slow or multi-step work belongs in a " +
|
|
@@ -7112,7 +7114,11 @@ const CONTRACT = deepFreeze({
|
|
|
7112
7114
|
// 1.276.0: stricter lint (sc-17764) — a widget that calls a key
|
|
7113
7115
|
// useDatastoreMutation() does not return is the publish-blocking
|
|
7114
7116
|
// `datastore-method-unknown` finding.
|
|
7115
|
-
|
|
7117
|
+
// 1.277.0: behaviour (sc-17821) — an app run's 500 ms counts only the
|
|
7118
|
+
// script's own run, inside a 1 s cap on the whole press, so a press can
|
|
7119
|
+
// wait up to about 1 s before ACTION_TIMEOUT. A press that never started
|
|
7120
|
+
// its script rejects RATE_LIMITED (429, Retry-After: 1): nothing ran.
|
|
7121
|
+
version: "1.277.0",
|
|
7116
7122
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7117
7123
|
hooks: HOOKS,
|
|
7118
7124
|
primitives: PRIMITIVES,
|
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
|
@@ -3720,7 +3720,10 @@ export class AgentError extends Error {
|
|
|
3720
3720
|
/**
|
|
3721
3721
|
* sc-13843 — structured error thrown by `useAction().run` and `.enqueue`. Branch on `code`:
|
|
3722
3722
|
* `ACTION_NOT_APP_INVOKABLE` and `ACTION_NOT_FOUND` will not clear on a retry,
|
|
3723
|
-
* `RATE_LIMITED` will
|
|
3723
|
+
* `RATE_LIMITED` will; from `run` it can also mean the server was too busy to
|
|
3724
|
+
* start the script, so nothing ran. `ACTION_TIMEOUT`: the script ran for 500 ms
|
|
3725
|
+
* of its own, or the press reached 1 s, and was stopped; its outcome is unknown.
|
|
3726
|
+
* `AUTH_REQUIRED`, `TOKEN_EXPIRED` and `TOKEN_INVALID`
|
|
3724
3727
|
* mean the app user must sign in. Never show an app user the raw message.
|
|
3725
3728
|
*/
|
|
3726
3729
|
/**
|
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
package/src/contract.js
CHANGED
|
@@ -2336,9 +2336,11 @@ const HOOKS = [
|
|
|
2336
2336
|
"(or after unmount) writes nothing. ActionError.code: " +
|
|
2337
2337
|
"INVALID_ACTION_INPUT (400) — the input was refused; " +
|
|
2338
2338
|
"ACTION_NOT_APP_INVOKABLE (403) and ACTION_NOT_FOUND (404) will NOT " +
|
|
2339
|
-
"clear on a retry, so hide the affordance; RATE_LIMITED (429) will
|
|
2340
|
-
"
|
|
2341
|
-
"
|
|
2339
|
+
"clear on a retry, so hide the affordance; RATE_LIMITED (429) will, and " +
|
|
2340
|
+
"from run() it can also mean the server was too busy to start the " +
|
|
2341
|
+
"script, so nothing ran; " +
|
|
2342
|
+
"ACTION_TIMEOUT (504) — the script ran for 500 ms of its own, or the " +
|
|
2343
|
+
"press reached 1 s, and was stopped, so its OUTCOME IS UNKNOWN: some of its writes may " +
|
|
2342
2344
|
"have happened. Never retry it blindly and never tell the user it did " +
|
|
2343
2345
|
"nothing; an Action a widget runs must do its writes as one call or be " +
|
|
2344
2346
|
"safe to repeat, and slow or multi-step work belongs in a " +
|
|
@@ -7112,7 +7114,11 @@ const CONTRACT = deepFreeze({
|
|
|
7112
7114
|
// 1.276.0: stricter lint (sc-17764) — a widget that calls a key
|
|
7113
7115
|
// useDatastoreMutation() does not return is the publish-blocking
|
|
7114
7116
|
// `datastore-method-unknown` finding.
|
|
7115
|
-
|
|
7117
|
+
// 1.277.0: behaviour (sc-17821) — an app run's 500 ms counts only the
|
|
7118
|
+
// script's own run, inside a 1 s cap on the whole press, so a press can
|
|
7119
|
+
// wait up to about 1 s before ACTION_TIMEOUT. A press that never started
|
|
7120
|
+
// its script rejects RATE_LIMITED (429, Retry-After: 1): nothing ran.
|
|
7121
|
+
version: "1.277.0",
|
|
7116
7122
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7117
7123
|
hooks: HOOKS,
|
|
7118
7124
|
primitives: PRIMITIVES,
|