@keemakr/ui-sdk 1.5.0-dev-20261022083409 → 1.5.0-dev-20261022112353

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.
@@ -0,0 +1,20 @@
1
+ /** The most categories a chart takes, and so the most values in each series. */
2
+ export declare const CHART_POINTS_MAX = 120;
3
+ /**
4
+ * `limit` evenly spaced indices out of `count`, first and last included, in order. All of them
5
+ * when `count` is not above `limit`.
6
+ */
7
+ export declare function thinnedIndices(count: number, limit: number): number[];
8
+ /** The chart fields that hold one entry per category. */
9
+ interface ChartPoints {
10
+ categories: string[];
11
+ series: Array<{
12
+ values: number[];
13
+ }>;
14
+ }
15
+ /**
16
+ * The chart with at most `limit` categories, each series keeping the value of every category it
17
+ * keeps. Everything else on the chart is kept as it is. The input is not touched.
18
+ */
19
+ export declare function thinChart<T extends ChartPoints>(chart: T, limit: number): T;
20
+ export {};
package/dist/chart.js ADDED
@@ -0,0 +1,38 @@
1
+ // How many points a chart series holds, and how a longer chart is cut down for an app that takes
2
+ // fewer (UI-05).
3
+ //
4
+ // A chart takes up to 120 points per series: 90 days plus margin, so an adoption screen can show
5
+ // DAU, WAU and MAU over the last 90 days. Released apps parse with ui-sdk 1.1.0 or 1.4.0, which
6
+ // refuse more than 50, and a refused chart would cost the app the whole chart. So core sends such
7
+ // an app the chart thinned to 50 evenly spaced points instead (conform.ts). The first and the last
8
+ // point are always kept: the start of the range and today.
9
+ /** The most categories a chart takes, and so the most values in each series. */
10
+ export const CHART_POINTS_MAX = 120;
11
+ /**
12
+ * `limit` evenly spaced indices out of `count`, first and last included, in order. All of them
13
+ * when `count` is not above `limit`.
14
+ */
15
+ export function thinnedIndices(count, limit) {
16
+ if (count <= limit)
17
+ return Array.from({ length: count }, (_, index) => index);
18
+ if (limit <= 1)
19
+ return [count - 1];
20
+ return Array.from({ length: limit }, (_, slot) => Math.round((slot * (count - 1)) / (limit - 1)));
21
+ }
22
+ /**
23
+ * The chart with at most `limit` categories, each series keeping the value of every category it
24
+ * keeps. Everything else on the chart is kept as it is. The input is not touched.
25
+ */
26
+ export function thinChart(chart, limit) {
27
+ if (chart.categories.length <= limit)
28
+ return chart;
29
+ const keep = thinnedIndices(chart.categories.length, limit);
30
+ return {
31
+ ...chart,
32
+ categories: keep.map((index) => chart.categories[index]),
33
+ series: chart.series.map((series) => ({
34
+ ...series,
35
+ values: keep.map((index) => series.values[index]),
36
+ })),
37
+ };
38
+ }
package/dist/conform.js CHANGED
@@ -8,6 +8,9 @@
8
8
  // - `tone: 'info' | 'accent'` (badge cells, tags, board columns, calendar entries, progress
9
9
  // bars; after 1.4.0) -> 'default', or the first tone that parse lists
10
10
  // - a string `min`/`max` on a date or datetime field (after 1.4.0) -> dropped
11
+ // - a chart with more points than the parse takes (120 after 1.4.0, 50 before)
12
+ // -> thinned to that many evenly spaced points,
13
+ // first and last kept (chart.ts)
11
14
  // - anything else the parse refuses (a longer label, a larger list, a value no fold knows)
12
15
  // -> the node's own text fallback
13
16
  // 2. A SAFETY field the app's parse STRIPS while it keeps the control (a `confirm`, or
@@ -24,6 +27,7 @@
24
27
  // line), so the number of repairs is bounded by the number of objects in the tree; the passes are
25
28
  // capped at that bound, and a pass that can repair nothing ends the loop. Only then does the
26
29
  // screen become one line.
30
+ import { thinChart } from './chart.js';
27
31
  /** Repairs one object of a tree can take at most: a tone, a min, a max, a drop, two replacements. */
28
32
  const REPAIRS_PER_OBJECT = 6;
29
33
  /** Lists of controls a client can lose one of without losing the node that holds them. */
@@ -199,6 +203,25 @@ export function conformTree(tree, parser, options) {
199
203
  fallbacks.push({ path: pathText(path), type: String(key), reason: 'parse', as: 'folded' });
200
204
  return true;
201
205
  }
206
+ if ((key === 'categories' || key === 'values') && issue.code === 'too_big') {
207
+ const chartPath = key === 'categories' ? path.slice(0, -1) : path.slice(0, -3);
208
+ const chart = at(work, chartPath);
209
+ const limit = Number(issue.maximum);
210
+ if ((key === 'categories' || path[path.length - 3] === 'series') &&
211
+ isObject(chart) &&
212
+ chart.type === 'chart' &&
213
+ Array.isArray(chart.categories) &&
214
+ Array.isArray(chart.series) &&
215
+ Number.isInteger(limit) &&
216
+ limit >= 1) {
217
+ // Every too-big list of one chart is one thinning: a later issue of it finds it done.
218
+ if (chart.categories.length <= limit)
219
+ return false;
220
+ setAt(work, chartPath, thinChart(chart, limit));
221
+ fallbacks.push({ path: pathText(chartPath), type: 'chart', reason: 'parse', as: 'folded' });
222
+ return true;
223
+ }
224
+ }
202
225
  const control = controlAt(path);
203
226
  if (control)
204
227
  return isGone(control) ? false : drop(control, 'parse');
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { UI_SCHEMA_VERSION, pressSchema, buttonSchema, cellSchema, dateFormatSchema, nodeSchema, screenPresentationSchema, screenTreeSchema, actionResultSchema, screenLoadRequestSchema, screenLoadResponseSchema, screenActionRequestSchema, interfaceFamilySchema, surfaceDefinitionSchema, surfaceSchema, screenRegistrationSchema, uiManifestSchema, jobIdSchema, jobStatusSchema, screenJobRequestSchema, mediaPathSchema, } from './schema.js';
2
2
  export type { Press, ScreenPresentation, ScreenNode, ScreenRootNode, ScreenTree, ActionResult, InterfaceFamily, SurfaceDefinition, Surface, ScreenRegistration, UiManifest, ScreenTreeInput, ActionResultInput, JobStatus, JobStatusInput, } from './schema.js';
3
+ export { CHART_POINTS_MAX, thinChart, thinnedIndices } from './chart.js';
3
4
  export { childNodesOf, KNOWN_CONTAINERS, KNOWN_NODE_TYPES } from './nodes.js';
4
5
  export type { ContainerChild, ContainerNodeType, KnownNodeType } from './nodes.js';
5
6
  export { pageRangeLabel, pageWindow, pressWithValue } from './pager.js';
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@
7
7
  //
8
8
  // Module code never ships to the browser. UI is data, not code.
9
9
  export { UI_SCHEMA_VERSION, pressSchema, buttonSchema, cellSchema, dateFormatSchema, nodeSchema, screenPresentationSchema, screenTreeSchema, actionResultSchema, screenLoadRequestSchema, screenLoadResponseSchema, screenActionRequestSchema, interfaceFamilySchema, surfaceDefinitionSchema, surfaceSchema, screenRegistrationSchema, uiManifestSchema, jobIdSchema, jobStatusSchema, screenJobRequestSchema, mediaPathSchema, } from './schema.js';
10
+ export { CHART_POINTS_MAX, thinChart, thinnedIndices } from './chart.js';
10
11
  export { childNodesOf, KNOWN_CONTAINERS, KNOWN_NODE_TYPES } from './nodes.js';
11
12
  export { pageRangeLabel, pageWindow, pressWithValue } from './pager.js';
12
13
  export { CLIENT_RELEASES, CORE_DRAWN_NODE_TYPES, CURRENT_UI_SDK_SNAPSHOT, FLOOR_NODE_SET, GENERIC_FALLBACK_TEXT, SAFETY_FALLBACK_TEXT, UI_SDK_SNAPSHOTS, fallbackNode, latestRelease, negotiateTree, nodeSetForClient, } from './negotiate.js';
package/dist/schema.js CHANGED
@@ -12,6 +12,7 @@
12
12
  */
13
13
  import { z } from 'zod';
14
14
  import { isTimeZone } from './calendar.js';
15
+ import { CHART_POINTS_MAX } from './chart.js';
15
16
  import { isDateLocale } from './date-format.js';
16
17
  import { datasetNodeSchema } from './dataset-view.js';
17
18
  export const UI_SCHEMA_VERSION = 1;
@@ -166,11 +167,15 @@ const chartSchema = z
166
167
  showValues: z.boolean().default(false),
167
168
  /** Put after each written number: "%", " leads". */
168
169
  valueSuffix: z.string().max(12).optional(),
169
- categories: z.array(z.string().max(80)).min(1).max(50),
170
+ /**
171
+ * Up to 120 (`CHART_POINTS_MAX`): 90 days plus margin. An app whose parse takes only 50 gets
172
+ * the chart thinned to 50 evenly spaced points, first and last kept (chart.ts).
173
+ */
174
+ categories: z.array(z.string().max(80)).min(1).max(CHART_POINTS_MAX),
170
175
  series: z
171
176
  .array(z.object({
172
177
  name: z.string().min(1).max(80),
173
- values: z.array(z.number().finite()).min(1).max(50),
178
+ values: z.array(z.number().finite()).min(1).max(CHART_POINTS_MAX),
174
179
  /**
175
180
  * The series' colour. Without it each series takes the next of the
176
181
  * renderer's own distinct colours.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keemakr/ui-sdk",
3
- "version": "1.5.0-dev-20261022083409",
3
+ "version": "1.5.0-dev-20261022112353",
4
4
  "description": "Product screens for keemakr marketplace modules: a versioned, server-driven UI tree schema plus defineScreen() handlers. Module code never ships to the browser — keemakr-core validates the tree and renders it with platform components.",
5
5
  "license": "MIT",
6
6
  "type": "module",