akanjs 3.4.0-rc.4 → 3.4.0-rc.6

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.
@@ -75,6 +75,22 @@ const rootWriter = (rootDict: RootDictionary, languages: readonly string[], refN
75
75
  };
76
76
  };
77
77
 
78
+ const pageArgTrans = (
79
+ languages: readonly string[],
80
+ pageKey: string,
81
+ sortDictionary: { [key: string]: Translated },
82
+ ) => ({
83
+ trans: languages.map(() => pageKey),
84
+ descTrans: languages.map((_, idx) => {
85
+ if (pageKey !== "sort") return pageKey;
86
+ const keys = Object.entries(sortDictionary).map(([key, { trans, descTrans }]) => {
87
+ const meaning = (descTrans ?? trans)[idx];
88
+ return meaning ? `${key} (${meaning})` : key;
89
+ });
90
+ return keys.length ? keys.join(", ") : pageKey;
91
+ }),
92
+ });
93
+
78
94
  const registerEnums = (rootDict: RootDictionary, languages: readonly string[], enumDictionary: object) => {
79
95
  for (const [refName, enumTrans] of Object.entries(enumDictionary as { [key: string]: object }))
80
96
  rootWriter(rootDict, languages, refName).fields([], enumTrans);
@@ -444,10 +460,10 @@ export class ModelDictInfo<
444
460
  root.head(["signal"], insightKey, sliceTrans, (t) => `Slice Insight - ${t}`);
445
461
  for (const [argKey, argTrans] of Object.entries(sliceTrans.argTrans as { [key: string]: Translated })) {
446
462
  root.field(["signal", listKey, "arg"], argKey, argTrans);
447
- for (const pageKey of ["skip", "limit", "sort"])
448
- root.field(["signal", listKey, "arg"], pageKey, argTrans, () => pageKey);
449
463
  root.field(["signal", insightKey, "arg"], argKey, argTrans);
450
464
  }
465
+ for (const pageKey of ["skip", "limit", "sort"])
466
+ root.field(["signal", listKey, "arg"], pageKey, pageArgTrans(this.languages, pageKey, this.sortDictionary));
451
467
  }
452
468
  root.fns(["signal"], this.endpointDictionary);
453
469
 
@@ -561,10 +561,10 @@ export class FetchClient {
561
561
  }
562
562
  }
563
563
 
564
- static paginationArgs: SerializedArg[] = [
564
+ static paginationArgs = (sortKeys?: string[]): SerializedArg[] => [
565
565
  { type: "search", name: "skip", refName: "Int" },
566
566
  { type: "search", name: "limit", refName: "Int" },
567
- { type: "search", name: "sort", refName: "String" },
567
+ { type: "search", name: "sort", refName: "String", ...(sortKeys?.length ? { oneOf: sortKeys } : {}) },
568
568
  ];
569
569
 
570
570
  static makeHttpUrl(
@@ -766,7 +766,7 @@ export class FetchClient {
766
766
  const endpoint: { [key: string]: SerializedEndpoint } = {
767
767
  [names.list]: {
768
768
  type: "query",
769
- args: [...slice.args, ...FetchClient.paginationArgs],
769
+ args: [...slice.args, ...FetchClient.paginationArgs(slice.sortKeys)],
770
770
  returns: { refName, modelType: "light", arrDepth: 1 },
771
771
  guards: slice.guards,
772
772
  ...mcp,
package/index.ts CHANGED
@@ -350,6 +350,12 @@ export interface AkanNativeDmgConfig {
350
350
  export interface AkanNativeSettings {
351
351
  /** The client the app opens, a basePath the routes declare; an app without basePaths leaves it out. */
352
352
  basePath?: string;
353
+ /**
354
+ * The server a build for each environment calls, an origin such as `https://api.example.com`. Default: the first
355
+ * domain the routes give the target's basePath for that environment, else `<app>-<env>.<serveDomain>`.
356
+ * `AKAN_PUBLIC_SERVER_URL` at build time wins over both.
357
+ */
358
+ serverUrl?: { [env in Exclude<NativeEnv, "local">]?: string };
353
359
  /**
354
360
  * Where the app starts, and falls back to for a deep link's stack and a back with no history. Default `/`. A platform
355
361
  * section's own `indexPath` (`desktop.indexPath`) wins on that platform.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.4.0-rc.4",
3
+ "version": "3.4.0-rc.6",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -10,6 +10,7 @@ import {
10
10
  type DocumentTouchOptions,
11
11
  type DocumentUpdateInput,
12
12
  type FindQueryOption,
13
+ getFilterMeta,
13
14
  getFilterSortByKey,
14
15
  getLoaderInfos,
15
16
  type ListQueryOption,
@@ -38,7 +39,10 @@ const modelQueryOptionsOf = (database: DatabaseModel) => {
38
39
  const resolveSort = (sortKey?: string | null): { [key: string]: 1 | -1 } | null => {
39
40
  if (!sortKey) return null;
40
41
  const sort = getFilterSortByKey(database.filter, sortKey) as { [key: string]: 1 | -1 } | undefined;
41
- if (!sort) throw new Exception.BadRequest(`Unknown sort key for ${modelName}: ${sortKey}`);
42
+ if (!sort) {
43
+ const known = Object.keys(getFilterMeta(database.filter).sort).join(", ");
44
+ throw new Exception.BadRequest(`Unknown sort key for ${modelName}: ${sortKey}. Sort by one of: ${known}.`);
45
+ }
42
46
  return sort;
43
47
  };
44
48
  const getListQuery = (query?: QueryOf<any>, queryOption?: ListQueryOption) => ({
@@ -138,6 +138,7 @@ export class FetchSerializer {
138
138
 
139
139
  const queryKeyArg = slice[""]?.args.find((arg) => arg.name === "queryKey");
140
140
  if (queryKeyArg && filter) queryKeyArg.oneOf = Object.keys(filter.filter);
141
+ if (filter) for (const serialized of Object.values(slice)) serialized.sortKeys = filter.sortKeys;
141
142
  return {
142
143
  ...(prefix ? { prefix } : {}),
143
144
  ...(Object.keys(slice).length ? { slice } : {}),
package/signal/types.ts CHANGED
@@ -167,6 +167,8 @@ interface SerializedSignalOption {
167
167
  export interface SerializedSlice extends SerializedSignalOption {
168
168
  /** `sort`: keys a subscriber may place a new row under itself (others refetch); `pauseOn` travels only when set. */
169
169
  live?: { sort: string[]; pauseOn?: string[] };
170
+ /** The model filter's sort keys, the values its list's `sort` argument takes. */
171
+ sortKeys?: string[];
170
172
  }
171
173
 
172
174
  export interface SerializedReturns {
@@ -11,6 +11,15 @@ export class AgentCursor {
11
11
  static readonly driftBy = 18;
12
12
  /** Fade delay after the last call, for a host that reports no turn boundary (one that does calls `hold`). */
13
13
  static readonly idleMs = 1400;
14
+ static readonly #travelMax = 600;
15
+ static readonly #dwellMs = 420;
16
+ static #landsAt = 0;
17
+ static #waiting: ReturnType<typeof setTimeout> | null = null;
18
+ static readonly #hopFrom = 48;
19
+ static readonly #lingerMs = 6000;
20
+ static readonly #coveredMs = 360;
21
+ static readonly #recallMs = 8000;
22
+ static #left: { x: number; y: number; at: number } | null = null;
14
23
  static readonly thinkingClass = "akan-agent-cursor-thinking";
15
24
  static readonly scrollingClass = "akan-agent-cursor-scrolling";
16
25
 
@@ -24,16 +33,22 @@ export class AgentCursor {
24
33
  static press(target: HTMLElement): Promise<void> {
25
34
  if (typeof document === "undefined") return Promise.resolve();
26
35
  AgentCursor.#el?.classList.remove(AgentCursor.thinkingClass);
36
+ AgentCursor.#stopWaiting();
27
37
  return new Promise((resolve) => {
28
- ScreenFlash.whenStill(target, () => {
38
+
39
+ const land = (isFirst: boolean) => {
29
40
  if (!ScreenFlash.onTop(target)) {
30
- AgentCursor.hide();
31
- resolve();
41
+ if (isFirst) setTimeout(() => land(false), AgentCursor.#coveredMs);
42
+ else {
43
+ AgentCursor.#stopScrolling();
44
+ resolve();
45
+ }
32
46
  return;
33
47
  }
34
48
  const { top, left, width, height, right, bottom } = target.getBoundingClientRect();
35
49
  AgentCursor.#pressed = { top, left, right, bottom };
36
50
  const travel = AgentCursor.#moveTo(left + width / 2, top + height / 2);
51
+ AgentCursor.#landsAt = Date.now() + travel;
37
52
 
38
53
  if (travel)
39
54
  setTimeout(() => {
@@ -44,7 +59,8 @@ export class AgentCursor {
44
59
  AgentCursor.#tap();
45
60
  resolve();
46
61
  }
47
- });
62
+ };
63
+ ScreenFlash.whenStill(target, () => land(true));
48
64
  });
49
65
  }
50
66
 
@@ -63,15 +79,30 @@ export class AgentCursor {
63
79
  AgentCursor.#idle = null;
64
80
  }
65
81
 
82
+ /** A turn's end leaves the pointer where it is for a moment: a run of several turns then travels on from there. */
66
83
  static release() {
67
84
  AgentCursor.#held = false;
68
- AgentCursor.hide();
85
+ AgentCursor.#el?.classList.remove(AgentCursor.thinkingClass);
86
+ if (AgentCursor.#idle) clearTimeout(AgentCursor.#idle);
87
+ AgentCursor.#idle = setTimeout(() => {
88
+ AgentCursor.#idle = null;
89
+ AgentCursor.hide();
90
+ }, AgentCursor.#lingerMs);
69
91
  }
70
92
 
71
93
  /** Drifts clear of the last pressed control and shows the waiting spinner; a no-op before the first press. */
72
94
  static think() {
73
95
  const el = AgentCursor.#el;
74
96
  if (!el?.isConnected) return;
97
+ AgentCursor.#stopWaiting();
98
+ const wait = AgentCursor.#landsAt + AgentCursor.#dwellMs - Date.now();
99
+ if (wait > 0) {
100
+ AgentCursor.#waiting = setTimeout(() => {
101
+ AgentCursor.#waiting = null;
102
+ AgentCursor.think();
103
+ }, wait);
104
+ return;
105
+ }
75
106
  el.classList.remove(`${AgentCursor.className}-tap`);
76
107
  AgentCursor.#driftOff();
77
108
  el.classList.add(AgentCursor.thinkingClass);
@@ -91,10 +122,12 @@ export class AgentCursor {
91
122
  }
92
123
 
93
124
  static hide() {
125
+ AgentCursor.#stopWaiting();
94
126
  AgentCursor.#pressed = null;
95
127
  AgentCursor.#stopScrolling();
96
128
  AgentCursor.#el?.classList.remove(AgentCursor.thinkingClass);
97
129
  AgentCursor.#el?.classList.remove(`${AgentCursor.className}-shown`);
130
+ if (AgentCursor.#at) AgentCursor.#left = { ...AgentCursor.#at, at: Date.now() };
98
131
  AgentCursor.#at = null;
99
132
  const el = AgentCursor.#el;
100
133
  setTimeout(() => {
@@ -104,6 +137,12 @@ export class AgentCursor {
104
137
  }, 400);
105
138
  }
106
139
 
140
+ /** A call can end while the pointer is still on its way: the drift to the waiting spot holds until the press has shown. */
141
+ static #stopWaiting() {
142
+ if (AgentCursor.#waiting) clearTimeout(AgentCursor.#waiting);
143
+ AgentCursor.#waiting = null;
144
+ }
145
+
107
146
  static #stopScrolling() {
108
147
  AgentCursor.#el?.classList.remove(AgentCursor.scrollingClass, `${AgentCursor.scrollingClass}-up`);
109
148
  }
@@ -112,10 +151,13 @@ export class AgentCursor {
112
151
  const el = AgentCursor.#mounted();
113
152
  AgentCursor.#stopScrolling();
114
153
  el.classList.remove(AgentCursor.thinkingClass);
115
- const at = AgentCursor.#at;
116
-
117
- const travel = at && Math.hypot(x - at.x, y - at.y) >= AgentCursor.travelFrom ? AgentCursor.travelMs : 0;
118
-
154
+ const from = AgentCursor.#at ?? AgentCursor.#entryOf(el);
155
+ const distance = Math.hypot(x - from.x, y - from.y);
156
+ const travel =
157
+ distance >= AgentCursor.#hopFrom
158
+ ? Math.round(Math.min(AgentCursor.#travelMax, Math.max(AgentCursor.travelMs, 220 + distance * 0.55)))
159
+ : 0;
160
+ el.style.setProperty("--akan-agent-travel", `${travel || AgentCursor.travelMs}ms`);
119
161
  if (!travel) el.classList.add(`${AgentCursor.className}-placing`);
120
162
  el.style.transform = `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`;
121
163
  if (!travel) {
@@ -128,6 +170,20 @@ export class AgentCursor {
128
170
  return travel;
129
171
  }
130
172
 
173
+ /** Where a pointer with no place yet comes from: where it last left the screen, else the screen's far corner. */
174
+ static #entryOf(el: HTMLElement): { x: number; y: number } {
175
+ const left = AgentCursor.#left;
176
+ const from =
177
+ left && Date.now() - left.at < AgentCursor.#recallMs
178
+ ? { x: left.x, y: left.y }
179
+ : { x: window.innerWidth - 48, y: window.innerHeight - 48 };
180
+ el.classList.add(`${AgentCursor.className}-placing`);
181
+ el.style.transform = `translate3d(${Math.round(from.x)}px, ${Math.round(from.y)}px, 0)`;
182
+ void el.offsetWidth;
183
+ el.classList.remove(`${AgentCursor.className}-placing`);
184
+ return from;
185
+ }
186
+
131
187
  static #tap() {
132
188
  const el = AgentCursor.#el;
133
189
  if (!el) return;
@@ -17,8 +17,10 @@ export class AgentVisual {
17
17
  static readonly revealCap = 4;
18
18
  /** How many of a form patch's fields are drawn. */
19
19
  static readonly fieldCap = 5;
20
- /** The longest a navigate call waits for its press to land. */
20
+ /** The longest a call waits for its press to land. */
21
21
  static readonly leadMs = 600;
22
+ static readonly #pressable = "button, a[href], [role='button'], input, select, textarea";
23
+ static readonly #cornerPx = 96;
22
24
 
23
25
  static #revealed = 0;
24
26
  static #idle: ReturnType<typeof setTimeout> | null = null;
@@ -59,7 +61,7 @@ export class AgentVisual {
59
61
  AgentVisual.#acting += 1;
60
62
  const pressed = AgentVisual.#targetsOf(event).map((target) => AgentVisual.#act(target, { reveal, cursor }));
61
63
 
62
- if (!cursor || !pressed.length || !AgentVisual.#navigating(event.name)) return;
64
+ if (!cursor || !pressed.length) return;
63
65
  return AgentVisual.#capped(Promise.all(pressed));
64
66
  }
65
67
 
@@ -74,7 +76,10 @@ export class AgentVisual {
74
76
  static #targetsOf(event: ToolActivity): HTMLElement[] {
75
77
  if (AgentVisual.#navigating(event.name)) return AgentVisual.#linkTo(event.args.path);
76
78
  const form = AgentVisual.#formOf(event.name);
77
- if (!form) return AgentVisual.#only(ScreenTarget.controls(event.name), event.args);
79
+ if (!form) {
80
+ const controls = AgentVisual.#only(AgentVisual.#controlsOf(event.name), event.args);
81
+ return controls.length ? controls : AgentVisual.#closeOf(event.name);
82
+ }
78
83
  return Object.keys(event.args)
79
84
  .slice(0, AgentVisual.fieldCap)
80
85
  .flatMap((key) => AgentVisual.#only(ScreenTarget.controls(`${form}.${key}`)));
@@ -107,6 +112,37 @@ export class AgentVisual {
107
112
  return pressed;
108
113
  }
109
114
 
115
+ /** A control marked on a wrapper with no box of its own (`display: contents`) is pressed on what the wrapper holds. */
116
+ static #controlsOf(name: string): HTMLElement[] {
117
+ const marked = ScreenTarget.controls(name);
118
+ if (marked.length || !document.body) return marked;
119
+ const holders = document.body.querySelectorAll<HTMLElement>(`[data-akan-action="${CSS.escape(name)}"]`);
120
+ return [...holders].flatMap((holder) => {
121
+ const held = [...holder.querySelectorAll<HTMLElement>(AgentVisual.#pressable)].find(ScreenTarget.visible);
122
+ return held ? [held] : [];
123
+ });
124
+ }
125
+
126
+ /** Leaving a form (`cancelEditOf<Model>`) has no marked control: the pointer takes the button at the top corner of the dialog holding that form. */
127
+ static #closeOf(name: string): HTMLElement[] {
128
+ const match = /^cancelEditOf([A-Z]\w*)$/.exec(name.slice(name.lastIndexOf(".") + 1));
129
+ if (!match || !document.body) return [];
130
+ const held = `[data-akan-action$="On${match[1]}"], [data-akan-action="submit${match[1]}"]`;
131
+ const dialog = [...document.body.querySelectorAll<HTMLElement>('[role="dialog"]')]
132
+ .reverse()
133
+ .find((one) => ScreenTarget.visible(one) && one.querySelector(held));
134
+ if (!dialog) return [];
135
+ const box = dialog.getBoundingClientRect();
136
+ const farOf = (button: HTMLElement) => {
137
+ const at = button.getBoundingClientRect();
138
+ return Math.hypot(box.right - (at.left + at.width / 2), box.top - (at.top + at.height / 2));
139
+ };
140
+ const [nearest] = [...dialog.querySelectorAll<HTMLElement>("button")]
141
+ .filter((button) => ScreenTarget.visible(button) && !button.closest("[data-akan-action], [data-akan-state]"))
142
+ .sort((a, b) => farOf(a) - farOf(b));
143
+ return nearest && farOf(nearest) <= AgentVisual.#cornerPx ? [nearest] : [];
144
+ }
145
+
110
146
  static #linkTo(path: unknown): HTMLElement[] {
111
147
  const wanted = ScreenTarget.routeOf(typeof path === "string" ? path : "");
112
148
  if (!wanted || !document.body) return [];
@@ -114,7 +150,7 @@ export class AgentVisual {
114
150
  (link) =>
115
151
  ScreenTarget.routeOf(ScreenReader.hrefOf(link)) === wanted &&
116
152
  ScreenTarget.visible(link) &&
117
- ScreenFlash.inView(link),
153
+ ScreenFlash.inView(link, 0),
118
154
  );
119
155
  return AgentVisual.#only(links);
120
156
  }
@@ -32,7 +32,8 @@ export class ScreenFlash {
32
32
 
33
33
  /** Painted at its own centre, not just laid out — `checkVisibility` passes a control under a modal backdrop. */
34
34
  static onTop(target: HTMLElement) {
35
- if (!ScreenFlash.inView(target)) return false;
35
+
36
+ if (!ScreenFlash.inView(target, 0)) return false;
36
37
  if (typeof document.elementFromPoint !== "function") return true;
37
38
  const { top, left, width, height } = target.getBoundingClientRect();
38
39
  const hit = document.elementFromPoint(left + width / 2, top + height / 2);
@@ -81,7 +81,7 @@ export declare class FetchClient {
81
81
  /** Every socket this client holds or opens later: its own and one per `FetchPolicy.origin`. */
82
82
  configureWs(options: WsClientOptions): void;
83
83
  setJwt(jwt: string | null): void;
84
- static paginationArgs: SerializedArg[];
84
+ static paginationArgs: (sortKeys?: string[]) => SerializedArg[];
85
85
  static makeHttpUrl(key: string, endpoint: SerializedEndpoint, prefix: string | undefined, argMap: Map<string, unknown>): string;
86
86
  static getBaseEndpoint(refName: string, signal: SerializedSignal): {
87
87
  [key: string]: SerializedEndpoint;
package/types/index.d.ts CHANGED
@@ -356,6 +356,14 @@ export interface AkanNativeDmgConfig {
356
356
  export interface AkanNativeSettings {
357
357
  /** The client the app opens, a basePath the routes declare; an app without basePaths leaves it out. */
358
358
  basePath?: string;
359
+ /**
360
+ * The server a build for each environment calls, an origin such as `https://api.example.com`. Default: the first
361
+ * domain the routes give the target's basePath for that environment, else `<app>-<env>.<serveDomain>`.
362
+ * `AKAN_PUBLIC_SERVER_URL` at build time wins over both.
363
+ */
364
+ serverUrl?: {
365
+ [env in Exclude<NativeEnv, "local">]?: string;
366
+ };
359
367
  /**
360
368
  * Where the app starts, and falls back to for a deep link's stack and a back with no history. Default `/`. A platform
361
369
  * section's own `indexPath` (`desktop.indexPath`) wins on that platform.
@@ -155,6 +155,8 @@ export interface SerializedSlice extends SerializedSignalOption {
155
155
  sort: string[];
156
156
  pauseOn?: string[];
157
157
  };
158
+ /** The model filter's sort keys, the values its list's `sort` argument takes. */
159
+ sortKeys?: string[];
158
160
  }
159
161
  export interface SerializedReturns {
160
162
  refName: Exclude<DefaultPrimitiveName, "Map" | "Upload"> | (string & {});
@@ -17,6 +17,7 @@ export declare class AgentCursor {
17
17
  static scroll(way: "up" | "down"): void;
18
18
  /** Keeps the pointer up for as long as the turn runs, instead of for `idleMs` after the last call. */
19
19
  static hold(): void;
20
+ /** A turn's end leaves the pointer where it is for a moment: a run of several turns then travels on from there. */
20
21
  static release(): void;
21
22
  /** Drifts clear of the last pressed control and shows the waiting spinner; a no-op before the first press. */
22
23
  static think(): void;
@@ -12,7 +12,7 @@ export declare class AgentVisual {
12
12
  static readonly revealCap = 4;
13
13
  /** How many of a form patch's fields are drawn. */
14
14
  static readonly fieldCap = 5;
15
- /** The longest a navigate call waits for its press to land. */
15
+ /** The longest a call waits for its press to land. */
16
16
  static readonly leadMs = 600;
17
17
  /** The handlers `agentSessionOf` hands the session. `true` is every effect; an object turns one of them off. */
18
18
  static sink(option?: boolean | AgentVisualOption): {
package/ui/styles.css CHANGED
@@ -486,7 +486,7 @@ body.akan-mobile-document {
486
486
  pointer-events: none;
487
487
  opacity: 0;
488
488
  transition:
489
- transform 320ms cubic-bezier(0.22, 0.61, 0.36, 1),
489
+ transform var(--akan-agent-travel, 320ms) cubic-bezier(0.22, 0.61, 0.36, 1),
490
490
  opacity 200ms ease-out;
491
491
  }
492
492