@altertable/data-app 0.68.0 → 0.70.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.
Files changed (203) hide show
  1. package/AGENTS.md +10 -0
  2. package/CONTRIBUTING.md +27 -1
  3. package/README.md +18 -21
  4. package/THIRD_PARTY_NOTICES +18 -0
  5. package/dist/chunks/index-22d576sn.js +153 -0
  6. package/dist/chunks/index-22d576sn.js.map +11 -0
  7. package/dist/chunks/index-2ajhmsc4.js +355 -0
  8. package/dist/chunks/index-2ajhmsc4.js.map +13 -0
  9. package/dist/chunks/{index-ktmvs916.js → index-58kks6a8.js} +37 -21
  10. package/dist/chunks/index-58kks6a8.js.map +13 -0
  11. package/dist/chunks/{index-23dktynd.js → index-7q99hf1z.js} +19 -12
  12. package/dist/chunks/index-7q99hf1z.js.map +10 -0
  13. package/dist/chunks/{index-mt93ff2b.js → index-9zqbrv2z.js} +7 -3
  14. package/dist/chunks/index-9zqbrv2z.js.map +10 -0
  15. package/dist/chunks/{index-m6n8ctfc.js → index-cv36cyna.js} +4 -4
  16. package/dist/chunks/index-cv36cyna.js.map +10 -0
  17. package/dist/chunks/{index-ag0cgnvq.js → index-q1w84fv9.js} +178 -31
  18. package/dist/chunks/index-q1w84fv9.js.map +15 -0
  19. package/dist/chunks/{index-qd5xgx6y.js → index-rew95tbg.js} +89 -21
  20. package/dist/chunks/index-rew95tbg.js.map +13 -0
  21. package/dist/chunks/{index-gvers8jw.js → index-vtpygsbq.js} +5651 -2711
  22. package/dist/chunks/index-vtpygsbq.js.map +126 -0
  23. package/dist/chunks/{index-x69p7cv7.js → index-wjt6cavj.js} +6 -4
  24. package/dist/chunks/index-wjt6cavj.js.map +10 -0
  25. package/dist/chunks/{index-f5cnbrjz.js → index-wss3gd3h.js} +39 -9
  26. package/dist/chunks/index-wss3gd3h.js.map +13 -0
  27. package/dist/chunks/{index-ev2b5aaf.js → index-xzb7sx6g.js} +4 -4
  28. package/dist/client/index.js +6 -6
  29. package/dist/core/appearance.js +1 -1
  30. package/dist/core/config.js +3 -3
  31. package/dist/core/contract.js +7 -7
  32. package/dist/core/contract.js.map +1 -1
  33. package/dist/core/format.js +10 -2
  34. package/dist/core/format.js.map +1 -1
  35. package/dist/embed/index.js +26 -25
  36. package/dist/embed/index.js.map +4 -4
  37. package/dist/index.js +3 -3
  38. package/dist/local.js +200 -145
  39. package/dist/local.js.map +10 -7
  40. package/dist/preview.js +1456 -0
  41. package/dist/preview.js.map +17 -0
  42. package/dist/react/embed/index.js +1 -1
  43. package/dist/react/index.js +500 -401
  44. package/dist/react/index.js.map +10 -13
  45. package/dist/react/ui/index.js +1851 -1476
  46. package/dist/react/ui/index.js.map +24 -21
  47. package/dist/server.js +102 -58
  48. package/dist/server.js.map +9 -6
  49. package/dist/types/client/data-client.d.ts +21 -10
  50. package/dist/types/client/download.d.ts +5 -0
  51. package/dist/types/client/iframe.d.ts +4 -2
  52. package/dist/types/client/logger.d.ts +10 -2
  53. package/dist/types/core/annotations.d.ts +5 -0
  54. package/dist/types/core/appearance.d.ts +2 -0
  55. package/dist/types/core/bridge-endpoint.d.ts +2 -2
  56. package/dist/types/core/bridge.d.ts +22 -0
  57. package/dist/types/core/config.d.ts +25 -17
  58. package/dist/types/core/contract.d.ts +26 -14
  59. package/dist/types/core/date-format.d.ts +24 -0
  60. package/dist/types/core/dimension-source.d.ts +64 -0
  61. package/dist/types/core/dimension.d.ts +33 -24
  62. package/dist/types/core/facets.d.ts +13 -0
  63. package/dist/types/core/filters.d.ts +4 -3
  64. package/dist/types/core/format.d.ts +5 -3
  65. package/dist/types/core/keys.d.ts +2 -0
  66. package/dist/types/core/messages.d.ts +3 -1
  67. package/dist/types/core/operation-types.d.ts +12 -11
  68. package/dist/types/core/queries.d.ts +75 -7
  69. package/dist/types/core/time-interval.d.ts +96 -0
  70. package/dist/types/core/variables.d.ts +49 -14
  71. package/dist/types/embed/host.d.ts +4 -4
  72. package/dist/types/embed/sql.d.ts +1 -1
  73. package/dist/types/index.d.ts +1 -1
  74. package/dist/types/react/actions.d.ts +53 -0
  75. package/dist/types/react/annotations/annotation-editor-state.d.ts +2 -0
  76. package/dist/types/react/annotations/annotation-targets.d.ts +1 -0
  77. package/dist/types/react/annotations/getAnnotationProps.d.ts +5 -3
  78. package/dist/types/react/annotations/useAnnotationGeometry.d.ts +2 -2
  79. package/dist/types/react/bindings.d.ts +62 -3
  80. package/dist/types/react/date-formatting.d.ts +12 -0
  81. package/dist/types/react/details.d.ts +46 -0
  82. package/dist/types/react/exploration.d.ts +44 -0
  83. package/dist/types/react/hooks.d.ts +82 -43
  84. package/dist/types/react/index.d.ts +10 -2
  85. package/dist/types/react/search-suggestions.d.ts +8 -0
  86. package/dist/types/react/style-contract.d.ts +1 -5
  87. package/dist/types/react/ui/AboutData.d.ts +9 -4
  88. package/dist/types/react/ui/AreaChart.d.ts +2 -2
  89. package/dist/types/react/ui/BarChart.d.ts +2 -2
  90. package/dist/types/react/ui/Button.d.ts +2 -1
  91. package/dist/types/react/ui/ChartLegend.d.ts +3 -2
  92. package/dist/types/react/ui/ChoicePicker.d.ts +2 -0
  93. package/dist/types/react/ui/ComposedChartLegend.d.ts +2 -1
  94. package/dist/types/react/ui/DataApp.d.ts +8 -4
  95. package/dist/types/react/ui/DataAppFrame.d.ts +14 -3
  96. package/dist/types/react/ui/DataTable.d.ts +6 -4
  97. package/dist/types/react/ui/DataWidget.d.ts +7 -0
  98. package/dist/types/react/ui/DateDisplay.d.ts +9 -0
  99. package/dist/types/react/ui/DateRangePicker.d.ts +3 -1
  100. package/dist/types/react/ui/DateTimeTooltip.d.ts +3 -2
  101. package/dist/types/react/ui/DimensionPicker.d.ts +5 -3
  102. package/dist/types/react/ui/EmptyState.d.ts +1 -1
  103. package/dist/types/react/ui/ExplorationActionControl.d.ts +60 -0
  104. package/dist/types/react/ui/GradientScroll.d.ts +8 -0
  105. package/dist/types/react/ui/Grid.d.ts +1 -1
  106. package/dist/types/react/ui/InspectionProvider.d.ts +2 -2
  107. package/dist/types/react/ui/LineChart.d.ts +2 -2
  108. package/dist/types/react/ui/Menu.d.ts +3 -2
  109. package/dist/types/react/ui/MetricWidget.d.ts +4 -0
  110. package/dist/types/react/ui/NumberFilterPicker.d.ts +3 -1
  111. package/dist/types/react/ui/PeriodSummary.d.ts +2 -1
  112. package/dist/types/react/ui/PickerField.d.ts +23 -0
  113. package/dist/types/react/ui/PieChart.d.ts +2 -2
  114. package/dist/types/react/ui/PopoverSurface.d.ts +5 -0
  115. package/dist/types/react/ui/RequestHint.d.ts +2 -2
  116. package/dist/types/react/ui/SearchField.d.ts +3 -1
  117. package/dist/types/react/ui/SearchTypeahead.d.ts +15 -0
  118. package/dist/types/react/ui/SectionHeading.d.ts +8 -0
  119. package/dist/types/react/ui/Select.d.ts +9 -1
  120. package/dist/types/react/ui/Sheet.d.ts +4 -2
  121. package/dist/types/react/ui/TableWidget.d.ts +8 -0
  122. package/dist/types/react/ui/Tabs.d.ts +4 -3
  123. package/dist/types/react/ui/TrendChart.d.ts +3 -3
  124. package/dist/types/react/ui/VariableBar.d.ts +1 -1
  125. package/dist/types/react/ui/VisualizationWidget.d.ts +1 -1
  126. package/dist/types/react/ui/chart-data.d.ts +8 -6
  127. package/dist/types/react/ui/chart-date-axis.d.ts +15 -0
  128. package/dist/types/react/ui/chart-interaction.d.ts +27 -0
  129. package/dist/types/react/ui/chart-primitives.d.ts +4 -4
  130. package/dist/types/react/ui/chart-time.d.ts +19 -0
  131. package/dist/types/react/ui/chartColor.d.ts +1 -1
  132. package/dist/types/react/ui/icons.d.ts +5 -1
  133. package/dist/types/react/ui/index.d.ts +10 -4
  134. package/dist/types/react/ui/metric-comparison.d.ts +2 -2
  135. package/dist/types/react/ui/metric.d.ts +2 -2
  136. package/dist/types/react/ui/presentation.d.ts +2 -0
  137. package/dist/types/react/ui/searchItems.d.ts +2 -0
  138. package/dist/types/react/ui/use-chart-scroll-to-end.d.ts +2 -0
  139. package/dist/types/react/ui/variables.d.ts +1 -1
  140. package/dist/types/react/view-control-bar.d.ts +18 -0
  141. package/dist/types/react/view-controls.d.ts +3 -2
  142. package/dist/types/react/view-runtime.d.ts +8 -3
  143. package/dist/types/react/view.d.ts +28 -7
  144. package/dist/types/react/widgets.d.ts +22 -11
  145. package/dist/types/server/local.d.ts +3 -1
  146. package/dist/types/server/preview/host.d.ts +1 -0
  147. package/dist/types/server/preview/index.d.ts +16 -0
  148. package/dist/types/server/reload-channel.d.ts +6 -0
  149. package/dist/types/server/request-body.d.ts +4 -0
  150. package/dist/worker.js +1 -1
  151. package/docs/app-authoring.md +27 -12
  152. package/docs/client.md +6 -7
  153. package/docs/composition.md +84 -0
  154. package/docs/contract.md +45 -26
  155. package/docs/data-context.md +2 -0
  156. package/docs/embed.md +11 -3
  157. package/docs/formatting-and-appearance.md +36 -5
  158. package/docs/layout.md +31 -8
  159. package/docs/react-embed.md +4 -4
  160. package/docs/react.md +1 -1
  161. package/docs/server-bun.md +25 -0
  162. package/docs/server.md +2 -2
  163. package/docs/styling.md +10 -27
  164. package/docs/ui.md +32 -18
  165. package/docs/variables.md +174 -25
  166. package/docs/views.md +60 -29
  167. package/docs/widgets.md +131 -26
  168. package/examples/starter-data-app/index.tsx +10 -23
  169. package/examples/starter-local-data-app/.bun-version +1 -0
  170. package/examples/starter-local-data-app/.node-version +1 -0
  171. package/examples/starter-local-data-app/.oxfmtrc.json +4 -0
  172. package/examples/starter-local-data-app/.oxlintrc.json +33 -0
  173. package/examples/starter-local-data-app/AGENTS.md +22 -0
  174. package/examples/starter-local-data-app/README.md +54 -0
  175. package/examples/starter-local-data-app/app.ts +28 -0
  176. package/examples/starter-local-data-app/bunfig.toml +2 -0
  177. package/examples/starter-local-data-app/package.json +33 -0
  178. package/examples/starter-local-data-app/src/App.tsx +8 -0
  179. package/examples/starter-local-data-app/src/assets.d.ts +1 -0
  180. package/examples/starter-local-data-app/src/data-context.ts +21 -0
  181. package/examples/starter-local-data-app/src/favicon.svg +13 -0
  182. package/examples/starter-local-data-app/src/index.html +14 -0
  183. package/examples/starter-local-data-app/src/main.tsx +7 -0
  184. package/examples/starter-local-data-app/src/operations.ts +6 -0
  185. package/examples/starter-local-data-app/src/server.ts +6 -0
  186. package/examples/starter-local-data-app/tsconfig.json +21 -0
  187. package/package.json +13 -3
  188. package/dist/chunks/index-23dktynd.js.map +0 -10
  189. package/dist/chunks/index-ag0cgnvq.js.map +0 -13
  190. package/dist/chunks/index-dq7b35fn.js +0 -307
  191. package/dist/chunks/index-dq7b35fn.js.map +0 -13
  192. package/dist/chunks/index-f5cnbrjz.js.map +0 -13
  193. package/dist/chunks/index-gvers8jw.js.map +0 -109
  194. package/dist/chunks/index-ktmvs916.js.map +0 -13
  195. package/dist/chunks/index-m6n8ctfc.js.map +0 -10
  196. package/dist/chunks/index-mev09s5v.js +0 -77
  197. package/dist/chunks/index-mev09s5v.js.map +0 -10
  198. package/dist/chunks/index-mt93ff2b.js.map +0 -10
  199. package/dist/chunks/index-qd5xgx6y.js.map +0 -13
  200. package/dist/chunks/index-x69p7cv7.js.map +0 -10
  201. package/dist/types/react/shellStyles.d.ts +0 -3
  202. package/dist/types/react/ui/DataAppSkeleton.d.ts +0 -7
  203. /package/dist/chunks/{index-ev2b5aaf.js.map → index-xzb7sx6g.js.map} +0 -0
package/AGENTS.md CHANGED
@@ -16,6 +16,12 @@ and public tokens. Follow [Styling](docs/styling.md)
16
16
  and [UI quality](docs/ui-quality.md).
17
17
  Do not copy package classes onto markup or select private descendants.
18
18
 
19
+ ## UI platform changes
20
+
21
+ Express intent through small typed props and simple data structures. Derive UI
22
+ from the displayed source; configure only meaning the platform cannot infer.
23
+ Follow the [UI platform principles](CONTRIBUTING.md#ui-platform-principles).
24
+
19
25
  ## Documentation
20
26
 
21
27
  Use `<Component>` notation for React components. Keep guidance concise; leave
@@ -30,6 +36,7 @@ Read the matching guide before generating an app. Package contributors follow
30
36
  | Task | Read |
31
37
  | -------------------------------------- | -------------------------------------------------------------- |
32
38
  | Choose hosted or local execution | [App authoring](docs/app-authoring.md) |
39
+ | Plan a coherent exploration and story | [Composition](docs/composition.md) |
33
40
  | Load data and compose loading states | [Views](docs/views.md) |
34
41
  | Add filters | [Variables](docs/variables.md) |
35
42
  | Compose visuals, tables, and narrative | [Widgets](docs/widgets.md), [layout](docs/layout.md) |
@@ -42,6 +49,9 @@ static displays, and deliberately custom UI; see [direct composition](docs/ui.md
42
49
  Prefer derivation over repeated configuration. Keep static context outside loading boundaries. Derive labels, findings, and
43
50
  exports from the displayed result and its input. Edit app-owned files; installed
44
51
  package files are dependencies.
52
+ Declare typed `params` and `projections`; derive operation data from `query()` rows
53
+ without duplicate schemas or type assertions. See [contracts](docs/contract.md)
54
+ and [facets](docs/variables.md#fixed-options-and-query-backed-facets).
45
55
 
46
56
  Keep `docs/` focused on knowledge agents need to build data apps. Put package
47
57
  implementation, testing, and release guidance in `CONTRIBUTING.md`.
package/CONTRIBUTING.md CHANGED
@@ -98,6 +98,17 @@ against a mocked Altertable API
98
98
  ([altertable-mock](https://github.com/altertable-ai/altertable-mock), DuckDB)
99
99
  started with Testcontainers and stopped on exit. Public API tests use their own deterministic consumer fixtures.
100
100
 
101
+ Run `bun run dev:file <path>` to preview a single-file data app such as
102
+ `examples/starter-data-app/index.tsx` from anywhere on disk, or `bun run dev:dir <path>`
103
+ for a local data app directory with `src/server.ts`. Both resolve `@altertable/data-app`
104
+ and React from this checkout's `dist`, so the app needs no install. Run `bun run build`
105
+ after package changes. File previews replace the app iframe on edits and preserve
106
+ URL filters. Directory previews restart the app server when its imports change.
107
+ Unlike `bun run dev`, neither uses the mocked API: set `ALTERTABLE_USERNAME` and `ALTERTABLE_PASSWORD` (or the
108
+ `ALTERTABLE_LAKEHOUSE_` names) to query `https://api.altertable.ai`, or another lakehouse
109
+ with `ALTERTABLE_API_BASE`. A CLI proxy (`ALTERTABLE_DATA_PROXY_URL`) takes precedence.
110
+ Each command prints the lakehouse it targets on startup.
111
+
101
112
  Open the **Widgets** tab (`/gallery?view=widgets`) for one ready example of each
102
113
  composable data display inside `<VisualizationWidget>`. The other tabs cover
103
114
  composed apps, variants, and request states.
@@ -115,7 +126,22 @@ For public changes, update the relevant guide, migrate callers and starters,
115
126
  and verify published usage. Flag breaking changes in commits and PRs.
116
127
 
117
128
  Docs help agents generate data apps: show current usage and focused examples.
118
- Keep package architecture and contributor rules here.
129
+ Keep package architecture and contributor rules here. Document author decisions
130
+ and minimal composition examples; leave automatic interaction mechanics and prop
131
+ inventories to code, TypeScript, and JSDoc.
132
+
133
+ ## UI platform principles
134
+
135
+ Design defaults that let agents build useful data apps with minimal configuration:
136
+
137
+ - Express user intent through small typed props and explicit ownership.
138
+ - Derive values from the displayed source rather than asking authors to repeat them.
139
+ - Configure only semantics that cannot be inferred reliably, such as which filters affect a dataset.
140
+ - Keep data structures simple, data flow direct, and names specific to their purpose.
141
+ - Compose existing primitives; remove unnecessary wrappers and intermediate state.
142
+ - Let components own loading, keyboard behavior, focus recovery, and responsive layout.
143
+ - Document the default path with one short authoring example; keep constraints in TypeScript and JSDoc.
144
+ - Verify public behavior across loading, empty, updating, and ready states.
119
145
 
120
146
  ## Component CSS
121
147
 
package/README.md CHANGED
@@ -2,43 +2,40 @@
2
2
 
3
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
4
4
 
5
- TypeScript contracts, a data client, server handlers, and React UI for building
6
- interactive apps with Altertable data.
5
+ **Build data apps powered by Altertable.**
7
6
 
8
- ## Installation
7
+ A TypeScript and React toolkit with APIs, components, and authoring guides for
8
+ developers and AI agents to build data apps powered by Altertable.
9
+
10
+ A data app combines interactive exploration with explanations and findings,
11
+ helping users answer questions with data. Compose filters, charts, tables, and
12
+ narrative, then let users present findings and export results.
13
+
14
+ ## Install
9
15
 
10
16
  ```fish
11
- # npm
12
17
  npm install @altertable/data-app
13
-
14
- # pnpm
18
+ # or
15
19
  pnpm add @altertable/data-app
16
-
17
- # Bun
20
+ # or
18
21
  bun add @altertable/data-app
19
22
  ```
20
23
 
21
24
  ## Build an app
22
25
 
23
- Apps render in an iframe in Altertable, a chat app, or locally in a browser.
24
- Follow [app authoring](docs/app-authoring.md) to explore data, export displayed results as CSV, and present findings.
26
+ Apps can be embedded in Altertable, ChatGPT, Claude, and other hosts that support
27
+ MCP Apps through a host integration, or run locally in a browser.
25
28
 
26
- | App | Start here |
27
- | ---------------------------------- | ---------------------------------------- |
28
- | Data app (hosted / remote / cloud) | [Single-file guide](docs/hosted-apps.md) |
29
- | Local data app | [Local guide](docs/local-data-apps.md) |
29
+ | App | Guide | Starter |
30
+ | --------------- | -------------------------------------- | ---------------------------------------------------------- |
31
+ | Remote data app | [Remote guide](docs/hosted-apps.md) | [Single file](examples/starter-data-app/index.tsx) |
32
+ | Local data app | [Local guide](docs/local-data-apps.md) | [Local project](examples/starter-local-data-app/README.md) |
30
33
 
31
34
  For agent-assisted work, direct your agent to [AGENTS.md](AGENTS.md).
32
- The package ships its guides and single-file starter alongside the built exports.
33
-
34
- ## Host apps
35
-
36
- For integrating apps into a host, see [embedding](docs/embed.md).
37
35
 
38
36
  ## Development
39
37
 
40
- See [Contributing](CONTRIBUTING.md) for repository structure and focused checks.
41
- Releases use [Release Please and npm trusted publishing](https://github.com/altertable-ai/data-app/blob/main/.github/RELEASING.md).
38
+ See [Contributing](CONTRIBUTING.md) to develop and test the package.
42
39
 
43
40
  ## License
44
41
 
@@ -0,0 +1,18 @@
1
+ d3-time 3.1.0 and d3-array 3.2.4
2
+ https://github.com/d3/d3-time
3
+ https://github.com/d3/d3-array
4
+
5
+ Copyright 2010-2022 Mike Bostock (d3-time)
6
+ Copyright 2010-2023 Mike Bostock (d3-array tick-step helpers)
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any purpose
9
+ with or without fee is hereby granted, provided that the above copyright notice
10
+ and this permission notice appear in all copies.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
14
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
16
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
17
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
18
+ THIS SOFTWARE.
@@ -0,0 +1,153 @@
1
+ // src/core/date-format.ts
2
+ var calendarDate = /^\d{4}-\d{2}-\d{2}$/;
3
+ var timestamp = /^(\d{4}-\d{2}-\d{2})T(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d{1,9})?)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;
4
+ function missing(options) {
5
+ return options.missing ?? "—";
6
+ }
7
+ function parseCalendarDate(value) {
8
+ if (!calendarDate.test(value))
9
+ return null;
10
+ const date = new Date(`${value}T00:00:00.000Z`);
11
+ return Number.isNaN(date.getTime()) || date.toISOString().slice(0, 10) !== value ? null : date;
12
+ }
13
+ function formatter(locale, options) {
14
+ try {
15
+ return new Intl.DateTimeFormat(locale, options);
16
+ } catch {
17
+ return null;
18
+ }
19
+ }
20
+ function formatDate2(value, options = {}) {
21
+ if (value === null || value === undefined)
22
+ return missing(options);
23
+ const date = parseCalendarDate(value);
24
+ const format = formatter(options.locale ?? "en-US", {
25
+ dateStyle: "medium",
26
+ timeZone: "UTC"
27
+ });
28
+ return date && format ? format.format(date) : missing(options);
29
+ }
30
+ function parseDateTime2(value) {
31
+ if (value === null || value === undefined)
32
+ return null;
33
+ if (value instanceof Date) {
34
+ return Number.isNaN(value.getTime()) ? null : value;
35
+ }
36
+ if (typeof value === "number") {
37
+ const date = new Date(value);
38
+ return Number.isNaN(date.getTime()) ? null : date;
39
+ }
40
+ const match = timestamp.exec(value);
41
+ if (!match || !parseCalendarDate(match[1]))
42
+ return null;
43
+ const date = new Date(value);
44
+ return Number.isNaN(date.getTime()) ? null : date;
45
+ }
46
+ function formatDateTime2(value, options = {}) {
47
+ const date = parseDateTime2(value);
48
+ const format = formatter(options.locale ?? "en-US", {
49
+ dateStyle: "medium",
50
+ timeStyle: options.precision === "second" ? "medium" : "short",
51
+ hourCycle: "h23",
52
+ timeZone: options.timeZone ?? "UTC"
53
+ });
54
+ return date && format ? format.format(date) : missing(options);
55
+ }
56
+ function formatTime2(value, options = {}) {
57
+ const date = parseDateTime2(value);
58
+ const format = formatter(options.locale ?? "en-US", {
59
+ hour: "2-digit",
60
+ minute: "2-digit",
61
+ ...options.precision === "second" ? { second: "2-digit" } : {},
62
+ hourCycle: "h23",
63
+ timeZone: options.timeZone ?? "UTC"
64
+ });
65
+ return date && format ? format.format(date) : missing(options);
66
+ }
67
+
68
+ // src/core/format.ts
69
+ function formatDateRange2({ start, end }, options = {}) {
70
+ const first = parseDateTime2(`${start}T00:00:00Z`);
71
+ const last = parseDateTime2(`${end}T00:00:00Z`);
72
+ if (!first || !last || start > end)
73
+ return options.missing ?? "—";
74
+ if (options.locale && options.locale !== "en-US") {
75
+ try {
76
+ return new Intl.DateTimeFormat(options.locale, {
77
+ dateStyle: "medium",
78
+ timeZone: "UTC"
79
+ }).formatRange(first, last);
80
+ } catch {
81
+ return options.missing ?? "—";
82
+ }
83
+ }
84
+ function format(date, options) {
85
+ return new Intl.DateTimeFormat("en-US", {
86
+ ...options,
87
+ timeZone: "UTC"
88
+ }).format(date);
89
+ }
90
+ function formatFullDate(date) {
91
+ return format(date, { month: "short", day: "numeric", year: "numeric" });
92
+ }
93
+ if (start === end)
94
+ return formatFullDate(first);
95
+ if (first.getUTCFullYear() !== last.getUTCFullYear())
96
+ return `${formatFullDate(first)}–${formatFullDate(last)}`;
97
+ const firstMonth = format(first, { month: "short" });
98
+ const lastMonth = format(last, { month: "short" });
99
+ const firstDay = first.getUTCDate();
100
+ const lastDay = last.getUTCDate();
101
+ return firstMonth === lastMonth ? `${firstMonth} ${firstDay}–${lastDay}, ${last.getUTCFullYear()}` : `${firstMonth} ${firstDay}–${lastMonth} ${lastDay}, ${last.getUTCFullYear()}`;
102
+ }
103
+ function formatMetric2(value, format) {
104
+ if (format.kind === "count")
105
+ return formatCount2(value, format);
106
+ if (format.kind === "ratio")
107
+ return formatPercent2(value, format);
108
+ return formatNumber2(value, {
109
+ style: "currency",
110
+ currency: format.currency,
111
+ locale: format.locale
112
+ });
113
+ }
114
+ function formatNumber2(value, options = {}) {
115
+ const { locale = "en-US", missing = "—", ...numberOptions } = options;
116
+ return value === null || value === undefined || !Number.isFinite(value) ? missing : new Intl.NumberFormat(locale, numberOptions).format(Object.is(value, -0) ? 0 : value);
117
+ }
118
+ function formatCount2(value, options = {}) {
119
+ const { compact = false, ...common } = options;
120
+ if (value !== null && value !== undefined && (!Number.isInteger(value) || value < 0)) {
121
+ return common.missing ?? "—";
122
+ }
123
+ return formatNumber2(value, {
124
+ ...common,
125
+ notation: compact ? "compact" : "standard",
126
+ maximumFractionDigits: compact ? 1 : 0
127
+ });
128
+ }
129
+ var pluralRules = new Intl.PluralRules;
130
+ function pluralize2(count, singular, plural = `${singular}s`) {
131
+ return pluralRules.select(count) === "one" ? singular : plural;
132
+ }
133
+ function formatPercent2(ratio, options = {}) {
134
+ if (ratio === null || ratio === undefined || !Number.isFinite(ratio)) {
135
+ return options.missing ?? "—";
136
+ }
137
+ const digits = options.maximumFractionDigits ?? (Math.abs(ratio) < 0.01 ? 2 : 1);
138
+ const percentOptions = {
139
+ locale: options.locale,
140
+ style: "percent",
141
+ maximumFractionDigits: digits
142
+ };
143
+ const smallestVisibleRatio = 10 ** -digits / 100;
144
+ if (ratio !== 0 && Math.round(Math.abs(ratio) / smallestVisibleRatio) === 0) {
145
+ const boundary = formatNumber2(smallestVisibleRatio, percentOptions);
146
+ return ratio > 0 ? `<${boundary}` : `>−${boundary}`;
147
+ }
148
+ return formatNumber2(ratio, percentOptions);
149
+ }
150
+
151
+ export { formatDate2, parseDateTime2, formatDateTime2, formatTime2, formatDateRange2, formatMetric2, formatNumber2, formatCount2, pluralize2, formatPercent2 };
152
+
153
+ //# debugId=96B183DAB5DBF47E64756E2164756E21
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/core/date-format.ts", "../src/core/format.ts"],
4
+ "sourcesContent": [
5
+ "/** Formatting for calendar dates and instants without implicit time-zone parsing. */\n\nexport type DateFormatOptions = {\n locale?: string;\n missing?: string;\n};\n\nexport type DateTimeFormatOptions = DateFormatOptions & {\n timeZone?: string;\n precision?: 'minute' | 'second';\n};\n\nexport type DateFormat =\n | ({ kind: 'date' } & DateFormatOptions)\n | ({ kind: 'dateTime' } & DateTimeFormatOptions);\n\ntype DateTimeValue = string | Date | number | null | undefined;\n\nconst calendarDate = /^\\d{4}-\\d{2}-\\d{2}$/;\nconst timestamp =\n /^(\\d{4}-\\d{2}-\\d{2})T(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d{1,9})?)?(?:Z|[+-](?:[01]\\d|2[0-3]):[0-5]\\d)$/;\n\nfunction missing(options: DateFormatOptions) {\n return options.missing ?? '—';\n}\n\nfunction parseCalendarDate(value: string): Date | null {\n if (!calendarDate.test(value)) return null;\n const date = new Date(`${value}T00:00:00.000Z`);\n\n return Number.isNaN(date.getTime()) ||\n date.toISOString().slice(0, 10) !== value\n ? null\n : date;\n}\n\nfunction formatter(\n locale: string,\n options: Intl.DateTimeFormatOptions\n): Intl.DateTimeFormat | null {\n try {\n return new Intl.DateTimeFormat(locale, options);\n } catch {\n return null;\n }\n}\n\n/** Format an ISO calendar date as a date, never as a browser-local instant. */\nexport function formatDate(\n value: string | null | undefined,\n options: DateFormatOptions = {}\n): string {\n if (value === null || value === undefined) return missing(options);\n const date = parseCalendarDate(value);\n const format = formatter(options.locale ?? 'en-US', {\n dateStyle: 'medium',\n timeZone: 'UTC',\n });\n\n return date && format ? format.format(date) : missing(options);\n}\n\n/** Parse only unambiguous instants. String values must include `Z` or an explicit offset. */\nexport function parseDateTime(value: DateTimeValue): Date | null {\n if (value === null || value === undefined) return null;\n if (value instanceof Date) {\n return Number.isNaN(value.getTime()) ? null : value;\n }\n if (typeof value === 'number') {\n const date = new Date(value);\n return Number.isNaN(date.getTime()) ? null : date;\n }\n const match = timestamp.exec(value);\n if (!match || !parseCalendarDate(match[1]!)) return null;\n const date = new Date(value);\n\n return Number.isNaN(date.getTime()) ? null : date;\n}\n\n/** Format an instant in an explicit reporting zone. Defaults use UTC and 24-hour minutes. */\nexport function formatDateTime(\n value: DateTimeValue,\n options: DateTimeFormatOptions = {}\n): string {\n const date = parseDateTime(value);\n const format = formatter(options.locale ?? 'en-US', {\n dateStyle: 'medium',\n timeStyle: options.precision === 'second' ? 'medium' : 'short',\n hourCycle: 'h23',\n timeZone: options.timeZone ?? 'UTC',\n });\n\n return date && format ? format.format(date) : missing(options);\n}\n\n/** Format an instant's time for intraday chart axes using the same zone and precision policy. */\nexport function formatTime(\n value: DateTimeValue,\n options: DateTimeFormatOptions = {}\n): string {\n const date = parseDateTime(value);\n const format = formatter(options.locale ?? 'en-US', {\n hour: '2-digit',\n minute: '2-digit',\n ...(options.precision === 'second' ? { second: '2-digit' } : {}),\n hourCycle: 'h23',\n timeZone: options.timeZone ?? 'UTC',\n });\n\n return date && format ? format.format(date) : missing(options);\n}\n",
6
+ "import { parseDateTime, type DateFormatOptions } from '@/src/core/date-format';\nexport {\n formatDate,\n formatDateTime,\n formatTime,\n parseDateTime,\n} from '@/src/core/date-format';\nexport type {\n DateFormat,\n DateFormatOptions,\n DateTimeFormatOptions,\n} from '@/src/core/date-format';\n/**\n * Date and number formatting with explicit units and missing-value behavior.\n * @module @altertable/data-app/format\n */\ntype CommonOptions = { locale?: string; missing?: string };\n\n/** Compact, unambiguous calendar dates for labels and request status. */\nexport function formatDateRange(\n { start, end }: { start: string; end: string },\n options: DateFormatOptions = {}\n): string {\n const first = parseDateTime(`${start}T00:00:00Z`);\n const last = parseDateTime(`${end}T00:00:00Z`);\n if (!first || !last || start > end) return options.missing ?? '—';\n if (options.locale && options.locale !== 'en-US') {\n try {\n return new Intl.DateTimeFormat(options.locale, {\n dateStyle: 'medium',\n timeZone: 'UTC',\n }).formatRange(first, last);\n } catch {\n return options.missing ?? '—';\n }\n }\n\n function format(date: Date, options: Intl.DateTimeFormatOptions) {\n return new Intl.DateTimeFormat('en-US', {\n ...options,\n timeZone: 'UTC',\n }).format(date);\n }\n\n function formatFullDate(date: Date) {\n return format(date, { month: 'short', day: 'numeric', year: 'numeric' });\n }\n\n if (start === end) return formatFullDate(first);\n if (first.getUTCFullYear() !== last.getUTCFullYear())\n return `${formatFullDate(first)}–${formatFullDate(last)}`;\n const firstMonth = format(first, { month: 'short' });\n const lastMonth = format(last, { month: 'short' });\n const firstDay = first.getUTCDate();\n const lastDay = last.getUTCDate();\n\n return firstMonth === lastMonth\n ? `${firstMonth} ${firstDay}–${lastDay}, ${last.getUTCFullYear()}`\n : `${firstMonth} ${firstDay}–${lastMonth} ${lastDay}, ${last.getUTCFullYear()}`;\n}\n\nexport type MetricFormat =\n | { kind: 'count'; compact?: boolean; locale?: string }\n | { kind: 'ratio'; maximumFractionDigits?: number; locale?: string }\n | { kind: 'currency'; currency: string; locale?: string };\n\nexport function formatMetric(value: number, format: MetricFormat): string {\n if (format.kind === 'count') return formatCount(value, format);\n if (format.kind === 'ratio') return formatPercent(value, format);\n\n return formatNumber(value, {\n style: 'currency',\n currency: format.currency,\n locale: format.locale,\n });\n}\n\n/** Missing and non-finite values use the `missing` label; negative zero renders as zero. */\nexport function formatNumber(\n value: number | null | undefined,\n options: CommonOptions & Intl.NumberFormatOptions = {}\n): string {\n const { locale = 'en-US', missing = '—', ...numberOptions } = options;\n\n return value === null || value === undefined || !Number.isFinite(value)\n ? missing\n : new Intl.NumberFormat(locale, numberOptions).format(\n Object.is(value, -0) ? 0 : value\n );\n}\n\n/** Negative and fractional counts render as missing. Compact notation is opt-in. */\nexport function formatCount(\n value: number | null | undefined,\n options: CommonOptions & { compact?: boolean } = {}\n): string {\n const { compact = false, ...common } = options;\n if (\n value !== null &&\n value !== undefined &&\n (!Number.isInteger(value) || value < 0)\n ) {\n return common.missing ?? '—';\n }\n\n return formatNumber(value, {\n ...common,\n notation: compact ? 'compact' : 'standard',\n maximumFractionDigits: compact ? 1 : 0,\n });\n}\n\nconst pluralRules = new Intl.PluralRules();\n\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`\n): string {\n return pluralRules.select(count) === 'one' ? singular : plural;\n}\n\n/** Accepts a ratio (0.116), not a percentage (11.6). */\nexport function formatPercent(\n ratio: number | null | undefined,\n options: CommonOptions & { maximumFractionDigits?: number } = {}\n): string {\n if (ratio === null || ratio === undefined || !Number.isFinite(ratio)) {\n return options.missing ?? '—';\n }\n const digits =\n options.maximumFractionDigits ?? (Math.abs(ratio) < 0.01 ? 2 : 1);\n const percentOptions = {\n locale: options.locale,\n style: 'percent' as const,\n maximumFractionDigits: digits,\n };\n const smallestVisibleRatio = 10 ** -digits / 100;\n if (ratio !== 0 && Math.round(Math.abs(ratio) / smallestVisibleRatio) === 0) {\n const boundary = formatNumber(smallestVisibleRatio, percentOptions);\n\n return ratio > 0 ? `<${boundary}` : `>−${boundary}`;\n }\n\n return formatNumber(ratio, percentOptions);\n}\n"
7
+ ],
8
+ "mappings": ";AAkBA,IAAM,eAAe;AACrB,IAAM,YACJ;AAEF,SAAS,OAAO,CAAC,SAA4B;AAAA,EAC3C,OAAO,QAAQ,WAAW;AAAA;AAG5B,SAAS,iBAAiB,CAAC,OAA4B;AAAA,EACrD,IAAI,CAAC,aAAa,KAAK,KAAK;AAAA,IAAG,OAAO;AAAA,EACtC,MAAM,OAAO,IAAI,KAAK,GAAG,qBAAqB;AAAA,EAE9C,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,KAChC,KAAK,YAAY,EAAE,MA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