@keemakr/ui-sdk 1.4.0-dev-20261013225946 → 1.4.0-dev-20261013225756

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.
@@ -25,7 +25,7 @@
25
25
  */
26
26
  import { z } from 'zod';
27
27
  import { type DatasetDeclaration, type DatasetField, type DatasetQueryRequestInput, type DatasetQueryResponse, type DatasetRow } from './dataset.js';
28
- export declare const DATASET_LAYOUTS: readonly ["table", "board", "list", "record", "chart"];
28
+ export declare const DATASET_LAYOUTS: readonly ["table", "board", "list", "record"];
29
29
  export type DatasetLayout = (typeof DATASET_LAYOUTS)[number];
30
30
  /** Deepest page a table reaches. Paging walks cursors from page 1. */
31
31
  export declare const DATASET_MAX_PAGE = 20;
@@ -37,7 +37,6 @@ export declare const datasetNodeSchema: z.ZodObject<{
37
37
  table: "table";
38
38
  board: "board";
39
39
  list: "list";
40
- chart: "chart";
41
40
  }>>;
42
41
  fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
43
42
  filters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -50,13 +49,6 @@ export declare const datasetNodeSchema: z.ZodObject<{
50
49
  }, z.core.$strip>>;
51
50
  limit: z.ZodDefault<z.ZodNumber>;
52
51
  groupBy: z.ZodOptional<z.ZodString>;
53
- chart: z.ZodOptional<z.ZodObject<{
54
- form: z.ZodDefault<z.ZodEnum<{
55
- bars: "bars";
56
- funnel: "funnel";
57
- }>>;
58
- measure: z.ZodOptional<z.ZodString>;
59
- }, z.core.$strip>>;
60
52
  open: z.ZodOptional<z.ZodObject<{
61
53
  screen: z.ZodString;
62
54
  param: z.ZodDefault<z.ZodString>;
@@ -33,7 +33,7 @@ const fieldName = z
33
33
  .string()
34
34
  .max(64)
35
35
  .regex(/^[a-z][a-z0-9_]*$/, 'must be lowercase snake_case, starting with a letter');
36
- export const DATASET_LAYOUTS = ['table', 'board', 'list', 'record', 'chart'];
36
+ export const DATASET_LAYOUTS = ['table', 'board', 'list', 'record'];
37
37
  /** Deepest page a table reaches. Paging walks cursors from page 1. */
38
38
  export const DATASET_MAX_PAGE = 20;
39
39
  export const datasetNodeSchema = z.object({
@@ -54,23 +54,8 @@ export const datasetNodeSchema = z.object({
54
54
  .optional(),
55
55
  /** Rows per page for a table; the most cards for a board. */
56
56
  limit: z.number().int().min(1).max(100).default(25),
57
- /**
58
- * The board's columns, or the chart's bars: an enum field. Defaults to the
59
- * stage field, then the status field.
60
- */
57
+ /** The board's columns: an enum field. Defaults to the stage field, then the status field. */
61
58
  groupBy: fieldName.optional(),
62
- /**
63
- * For a chart. `bars`: one bar per option of `groupBy`. `funnel`: how many
64
- * reached each step, in option order; an option with a destructive tone (a
65
- * lost deal) is an exit, not a step. `measure` sums a number field instead
66
- * of counting rows. A chart reads up to 200 rows.
67
- */
68
- chart: z
69
- .object({
70
- form: z.enum(['bars', 'funnel']).default('bars'),
71
- measure: fieldName.optional(),
72
- })
73
- .optional(),
74
59
  /**
75
60
  * Pressing a row or card opens this screen, with the row's key under `param`.
76
61
  * A list without it opens the row beside the list.
@@ -104,17 +89,6 @@ export function datasetNodeIssues(node, declaration) {
104
89
  else if ((group.options?.length ?? 0) > 8)
105
90
  issues.push('a board shows at most 8 columns');
106
91
  }
107
- if (node.layout === 'chart') {
108
- if (!boardGroupField(node, declaration)) {
109
- issues.push('a chart needs an enum field to group by (a stage or a status)');
110
- }
111
- const measure = node.chart?.measure;
112
- if (measure && byName.get(measure)?.type !== 'number') {
113
- issues.push(`a chart can only add up a number field, and "${measure}" is not one`);
114
- }
115
- }
116
- if (node.chart && node.layout !== 'chart')
117
- issues.push('only a chart takes chart settings');
118
92
  return issues;
119
93
  }
120
94
  function boardGroupField(node, declaration) {
@@ -123,82 +97,6 @@ function boardGroupField(node, declaration) {
123
97
  return enums.find((field) => field.name === node.groupBy);
124
98
  return enums.find((f) => f.role === 'stage') ?? enums.find((f) => f.role === 'status');
125
99
  }
126
- const NUMBER = new Intl.NumberFormat('en-US', { maximumFractionDigits: 2 });
127
- /** Bars or a funnel over the rows, with the totals above them. */
128
- function compileDatasetChart(node, declaration, response, hasMore) {
129
- const group = boardGroupField(node, declaration);
130
- const measure = node.chart?.measure
131
- ? declaration.fields.find((field) => field.name === node.chart?.measure)
132
- : undefined;
133
- const funnel = node.chart?.form === 'funnel';
134
- const valueOf = (row) => {
135
- if (!measure)
136
- return 1;
137
- const value = row[measure.name];
138
- return typeof value === 'number' ? value : 0;
139
- };
140
- const options = (group.options ?? []).filter((option) => !funnel || option.tone !== 'destructive');
141
- const index = new Map(options.map((option, i) => [option.value, i]));
142
- const values = options.map(() => 0);
143
- for (const row of response.rows) {
144
- const at = index.get(String(row[group.name]));
145
- if (at === undefined)
146
- continue;
147
- // A funnel counts a row at its own step and at every step before it: it reached them.
148
- if (funnel)
149
- for (let i = 0; i <= at; i += 1)
150
- values[i] += valueOf(row);
151
- else
152
- values[at] += valueOf(row);
153
- }
154
- const rounded = values.map((value) => Math.round(value * 100) / 100);
155
- const total = response.rows.reduce((sum, row) => sum + valueOf(row), 0);
156
- const unit = measure ? measure.label : declaration.label;
157
- const stats = [
158
- {
159
- type: 'stat',
160
- label: declaration.label.slice(0, 80),
161
- value: NUMBER.format(response.rows.length),
162
- },
163
- ...(measure
164
- ? [
165
- {
166
- type: 'stat',
167
- label: `Total ${measure.label}`.slice(0, 80),
168
- value: NUMBER.format(total),
169
- },
170
- ]
171
- : []),
172
- ];
173
- const out = [
174
- { type: 'section', layout: 'row', children: stats },
175
- {
176
- type: 'chart',
177
- chartType: 'bar',
178
- title: `${unit} ${funnel ? 'reaching each' : 'by'} ${group.label.toLowerCase()}`.slice(0, 120),
179
- orientation: funnel ? 'horizontal' : 'vertical',
180
- showValues: true,
181
- categories: options.map((option) => option.label.slice(0, 80)),
182
- series: [{ name: unit.slice(0, 80), values: rounded }],
183
- },
184
- ];
185
- if (funnel && options.length > 1) {
186
- const steps = options.slice(1).map((option, i) => {
187
- const before = rounded[i];
188
- const share = before > 0 ? Math.round((rounded[i + 1] / before) * 100) : 0;
189
- return `${option.label}: ${share}% of ${options[i].label}`;
190
- });
191
- out.push({ type: 'text', value: steps.join(' · ').slice(0, 5000), muted: true });
192
- }
193
- if (hasMore) {
194
- out.push({
195
- type: 'text',
196
- value: `Counts the first ${response.rows.length} rows only.`,
197
- muted: true,
198
- });
199
- }
200
- return out;
201
- }
202
100
  /** Which page of a table the params ask for, 1 when none. */
203
101
  export function datasetPage(node, params) {
204
102
  if (node.layout !== 'table' && node.layout !== 'list')
@@ -251,11 +149,7 @@ export function datasetQueryFor(node, declaration, params) {
251
149
  return {
252
150
  filters,
253
151
  ...(sort ? { sort } : {}),
254
- limit: node.layout === 'chart'
255
- ? DATASET_LIMITS.rows
256
- : node.layout === 'board'
257
- ? Math.min(DATASET_LIMITS.rows, node.limit * 4)
258
- : node.limit,
152
+ limit: node.layout === 'board' ? Math.min(DATASET_LIMITS.rows, node.limit * 4) : node.limit,
259
153
  };
260
154
  }
261
155
  /** The fields a view shows, in order. */
@@ -461,9 +355,6 @@ export function compileDatasetNode(opts) {
461
355
  : {};
462
356
  };
463
357
  const note = response.note ? [{ type: 'text', value: response.note, muted: true }] : [];
464
- if (node.layout === 'chart') {
465
- return [...compileDatasetChart(node, declaration, response, opts.hasMore), ...note];
466
- }
467
358
  if (node.layout === 'board') {
468
359
  const group = boardGroupField(node, declaration);
469
360
  const subtitleField = declaration.fields.find((f) => f.role === 'subtitle') ??
@@ -650,7 +541,7 @@ function formField(field, required) {
650
541
  export function compileDatasetCreate(opts) {
651
542
  const { node, declaration, screen } = opts;
652
543
  const create = declaration.accepts?.create;
653
- if (!create || !node.create || node.layout === 'record' || node.layout === 'chart')
544
+ if (!create || !node.create || node.layout === 'record')
654
545
  return [];
655
546
  const here = { kind: 'navigate', screen: screen.screen };
656
547
  if (screen.params[DATASET_NEW_PARAM] !== node.dataset) {
package/dist/schema.d.ts CHANGED
@@ -348,8 +348,8 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
348
348
  }>;
349
349
  title: z.ZodOptional<z.ZodString>;
350
350
  orientation: z.ZodDefault<z.ZodEnum<{
351
- horizontal: "horizontal";
352
351
  vertical: "vertical";
352
+ horizontal: "horizontal";
353
353
  }>>;
354
354
  barWeight: z.ZodDefault<z.ZodEnum<{
355
355
  regular: "regular";
@@ -809,7 +809,6 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
809
809
  table: "table";
810
810
  board: "board";
811
811
  list: "list";
812
- chart: "chart";
813
812
  }>>;
814
813
  fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
815
814
  filters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -822,13 +821,6 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
822
821
  }, z.core.$strip>>;
823
822
  limit: z.ZodDefault<z.ZodNumber>;
824
823
  groupBy: z.ZodOptional<z.ZodString>;
825
- chart: z.ZodOptional<z.ZodObject<{
826
- form: z.ZodDefault<z.ZodEnum<{
827
- bars: "bars";
828
- funnel: "funnel";
829
- }>>;
830
- measure: z.ZodOptional<z.ZodString>;
831
- }, z.core.$strip>>;
832
824
  open: z.ZodOptional<z.ZodObject<{
833
825
  screen: z.ZodString;
834
826
  param: z.ZodDefault<z.ZodString>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keemakr/ui-sdk",
3
- "version": "1.4.0-dev-20261013225946",
3
+ "version": "1.4.0-dev-20261013225756",
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",