@sincpro/web-ui 2.11.0 → 2.12.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 (148) hide show
  1. package/README.md +35 -3
  2. package/dist/components/activity/Messages.d.ts +3 -23
  3. package/dist/components/activity/Messages.js +3 -17
  4. package/dist/components/activity/index.d.ts +2 -1
  5. package/dist/components/activity/index.js +2 -1
  6. package/dist/components/activity/messageKind.d.ts +23 -0
  7. package/dist/components/activity/messageKind.js +17 -0
  8. package/dist/components/assist/assist.d.ts +1 -1
  9. package/dist/components/assist/assist.js +1 -1
  10. package/dist/components/frame/model.js +1 -1
  11. package/dist/components/guide/index.d.ts +2 -1
  12. package/dist/components/guide/index.js +2 -1
  13. package/dist/components/guide/selector.d.ts +25 -0
  14. package/dist/components/guide/selector.js +14 -0
  15. package/dist/components/guide/target.d.ts +3 -25
  16. package/dist/components/guide/target.js +2 -14
  17. package/dist/components/listing/AxisLevels.d.ts +2 -5
  18. package/dist/components/listing/AxisLevels.js +5 -22
  19. package/dist/components/listing/ColumnsMenu.d.ts +3 -7
  20. package/dist/components/listing/ColumnsMenu.js +4 -8
  21. package/dist/components/listing/collapsed.d.ts +2 -0
  22. package/dist/components/listing/collapsed.js +8 -0
  23. package/dist/components/listing/columnSpecs.d.ts +34 -0
  24. package/dist/components/listing/columnSpecs.js +54 -0
  25. package/dist/components/listing/columns.d.ts +3 -21
  26. package/dist/components/listing/columns.js +2 -39
  27. package/dist/components/listing/index.d.ts +9 -5
  28. package/dist/components/listing/index.js +13 -6
  29. package/dist/components/listing/levels.d.ts +9 -0
  30. package/dist/components/listing/levels.js +27 -0
  31. package/dist/components/listing/pageSizes.d.ts +9 -0
  32. package/dist/components/listing/pageSizes.js +11 -0
  33. package/dist/components/listing/pages.d.ts +2 -9
  34. package/dist/components/listing/pages.js +5 -9
  35. package/dist/components/listing/tree.d.ts +2 -1
  36. package/dist/components/listing/tree.js +4 -5
  37. package/dist/components/preview/FilePreview.d.ts +3 -3
  38. package/dist/components/preview/FilePreview.js +3 -15
  39. package/dist/components/preview/index.d.ts +2 -1
  40. package/dist/components/preview/index.js +2 -1
  41. package/dist/components/preview/previewKind.d.ts +3 -0
  42. package/dist/components/preview/previewKind.js +17 -0
  43. package/dist/components/search/FilterBuilder.d.ts +5 -139
  44. package/dist/components/search/FilterBuilder.js +5 -579
  45. package/dist/components/search/JsonEditor.d.ts +2 -8
  46. package/dist/components/search/JsonEditor.js +5 -15
  47. package/dist/components/search/RuleValue.d.ts +2 -2
  48. package/dist/components/search/RuleValue.js +5 -4
  49. package/dist/components/search/datePeriods.js +1 -1
  50. package/dist/components/search/filterTree.d.ts +183 -0
  51. package/dist/components/search/filterTree.js +570 -0
  52. package/dist/components/search/formatJson.d.ts +8 -0
  53. package/dist/components/search/formatJson.js +17 -0
  54. package/dist/components/search/index.d.ts +5 -3
  55. package/dist/components/search/index.js +7 -3
  56. package/dist/components/search/query.js +1 -1
  57. package/dist/foundations/calendar.js +1 -1
  58. package/dist/foundations/catalog.d.ts +7 -8
  59. package/dist/foundations/catalog.js +10 -35
  60. package/dist/foundations/chart.js +1 -1
  61. package/dist/foundations/controlName.d.ts +12 -0
  62. package/dist/foundations/controlName.js +14 -0
  63. package/dist/foundations/copy.d.ts +3 -1130
  64. package/dist/foundations/copy.es.d.ts +1 -1
  65. package/dist/foundations/copy.js +13 -747
  66. package/dist/foundations/copyStore.d.ts +21 -0
  67. package/dist/foundations/copyStore.js +47 -0
  68. package/dist/foundations/density.d.ts +4 -8
  69. package/dist/foundations/density.js +2 -9
  70. package/dist/foundations/form.d.ts +2 -12
  71. package/dist/foundations/form.js +4 -14
  72. package/dist/foundations/index.d.ts +18 -11
  73. package/dist/foundations/index.js +21 -11
  74. package/dist/foundations/keys.d.ts +8 -0
  75. package/dist/foundations/keys.js +6 -0
  76. package/dist/foundations/pickBy.d.ts +16 -0
  77. package/dist/foundations/pickBy.js +17 -0
  78. package/dist/foundations/pivotSheet.js +0 -0
  79. package/dist/foundations/shortcut.d.ts +3 -9
  80. package/dist/foundations/shortcut.js +2 -7
  81. package/dist/foundations/sticky.d.ts +2 -6
  82. package/dist/foundations/sticky.js +5 -8
  83. package/dist/foundations/stickyStyle.d.ts +12 -0
  84. package/dist/foundations/stickyStyle.js +13 -0
  85. package/dist/foundations/surface.d.ts +2 -2
  86. package/dist/foundations/surface.js +4 -2
  87. package/dist/foundations/theme.d.ts +3 -13
  88. package/dist/foundations/theme.js +2 -15
  89. package/dist/foundations/themeChoice.d.ts +19 -0
  90. package/dist/foundations/themeChoice.js +22 -0
  91. package/dist/foundations/types.d.ts +3 -0
  92. package/dist/foundations/uiCopy.d.ts +1135 -0
  93. package/dist/foundations/uiCopy.js +749 -0
  94. package/dist/foundations/xlsx.d.ts +4 -10
  95. package/dist/foundations/xlsx.js +0 -0
  96. package/dist/foundations/xlsxDownload.d.ts +8 -0
  97. package/dist/foundations/xlsxDownload.js +28 -0
  98. package/dist/primitives/button/Button.d.ts +3 -15
  99. package/dist/primitives/button/Button.js +2 -65
  100. package/dist/primitives/button/classes.d.ts +21 -0
  101. package/dist/primitives/button/classes.js +65 -0
  102. package/dist/primitives/button/index.d.ts +2 -1
  103. package/dist/primitives/button/index.js +3 -1
  104. package/dist/primitives/field/Field.d.ts +2 -6
  105. package/dist/primitives/field/Field.js +4 -10
  106. package/dist/primitives/field/classes.d.ts +6 -0
  107. package/dist/primitives/field/classes.js +13 -0
  108. package/dist/primitives/field/index.d.ts +2 -1
  109. package/dist/primitives/field/index.js +3 -1
  110. package/dist/primitives/menu/Menu.d.ts +2 -19
  111. package/dist/primitives/menu/Menu.js +4 -30
  112. package/dist/primitives/menu/classes.d.ts +18 -0
  113. package/dist/primitives/menu/classes.js +33 -0
  114. package/dist/primitives/menu/index.d.ts +2 -1
  115. package/dist/primitives/menu/index.js +3 -1
  116. package/dist/primitives/table/EditableTable.d.ts +3 -37
  117. package/dist/primitives/table/EditableTable.js +2 -47
  118. package/dist/primitives/table/Table.d.ts +2 -4
  119. package/dist/primitives/table/Table.js +4 -11
  120. package/dist/primitives/table/cellTone.d.ts +5 -0
  121. package/dist/primitives/table/cellTone.js +13 -0
  122. package/dist/primitives/table/editRules.d.ts +43 -0
  123. package/dist/primitives/table/editRules.js +53 -0
  124. package/dist/primitives/table/index.d.ts +4 -2
  125. package/dist/primitives/table/index.js +4 -2
  126. package/dist/primitives/tag/Count.d.ts +2 -3
  127. package/dist/primitives/tag/Count.js +4 -5
  128. package/dist/primitives/tag/countText.d.ts +3 -0
  129. package/dist/primitives/tag/countText.js +7 -0
  130. package/dist/primitives/tag/index.d.ts +2 -1
  131. package/dist/primitives/tag/index.js +2 -1
  132. package/dist/primitives/value/DateValue.d.ts +2 -5
  133. package/dist/primitives/value/DateValue.js +6 -44
  134. package/dist/primitives/value/Meter.d.ts +3 -8
  135. package/dist/primitives/value/Meter.js +2 -9
  136. package/dist/primitives/value/RichText.d.ts +2 -4
  137. package/dist/primitives/value/RichText.js +5 -20
  138. package/dist/primitives/value/Value.d.ts +10 -7
  139. package/dist/primitives/value/Value.js +7 -24
  140. package/dist/primitives/value/format.d.ts +16 -0
  141. package/dist/primitives/value/format.js +81 -0
  142. package/dist/primitives/value/index.d.ts +7 -4
  143. package/dist/primitives/value/index.js +9 -4
  144. package/dist/primitives/value/meterLevel.d.ts +10 -0
  145. package/dist/primitives/value/meterLevel.js +12 -0
  146. package/dist/primitives/value/richTextPlain.d.ts +4 -0
  147. package/dist/primitives/value/richTextPlain.js +23 -0
  148. package/package.json +1 -1
@@ -1,22 +1,26 @@
1
- export { type ColumnControl, type ColumnSpec, defaultVisibleIds, reconcileVisible, toggleColumn, useColumnControl, visibleColumns, } from "./columns.js";
2
- export { ColumnsMenu, specsFromColumns, } from "./ColumnsMenu.js";
1
+ export { toggleCollapsed } from "./collapsed.js";
2
+ export { type ColumnControl, useColumnControl, } from "./columns.js";
3
+ export { ColumnsMenu } from "./ColumnsMenu.js";
4
+ export { type ColumnSpec, defaultVisibleIds, reconcileVisible, specsFromColumns, toggleColumn, visibleColumns, } from "./columnSpecs.js";
3
5
  export { Listing } from "./Listing.js";
4
6
  export { type ListIdentity, ListingBar } from "./ListingBar.js";
5
7
  export { type ModelCellKind } from "./modelCells.js";
6
8
  export { type ClaimedField, claimedFields, columnsFromModel, modelCellKind, readModelValue, } from "./modelColumns.js";
7
- export { type CursorSource, DEFAULT_PAGE_SIZE, PAGE_SIZES, type Pages, type PaginationBridge, type ServerPage, useCursorPagination, usePagination, } from "./pages.js";
9
+ export { type CursorSource, type Pages, type PaginationBridge, type ServerPage, useCursorPagination, usePagination, } from "./pages.js";
10
+ export { DEFAULT_PAGE_SIZE, PAGE_SIZES } from "./pageSizes.js";
8
11
  export { Pagination } from "./Pagination.js";
9
12
  export { RecordLink } from "./RecordLink.js";
10
13
  export { GroupHeader, Row } from "./Row.js";
11
14
  export { type Selection, useSelection } from "./selection.js";
12
15
  export { type SetControl, useSetControl } from "./set.js";
13
- export { toggleCollapsed, type TreeControl, useTreeControl, } from "./tree.js";
16
+ export { type TreeControl, useTreeControl } from "./tree.js";
14
17
  export { type ViewIcon, type ViewOption, ViewSwitcher, } from "./ViewSwitcher.js";
15
- export { AxisLevels, levelId, levelLabeler, } from "./AxisLevels.js";
18
+ export { AxisLevels } from "./AxisLevels.js";
16
19
  export { type BoardColumn, BoardColumns, type BoardStages, } from "./BoardColumns.js";
17
20
  export { type ChartComparison, ChartExplorer, type ChartExplorerProps, } from "./ChartExplorer.js";
18
21
  export { type GroupingControl, useGroupingControl, } from "./grouping.js";
19
22
  export { GroupingLevels, type GroupingLevelsProps, } from "./GroupingLevels.js";
23
+ export { levelId, levelLabeler } from "./levels.js";
20
24
  export { PivotExplorer, type PivotExplorerProps, } from "./PivotExplorer.js";
21
25
  export { RecordCard } from "./RecordCard.js";
22
26
  export { type SortField, SortMenu, type SortMenuProps, } from "./SortMenu.js";
@@ -1,25 +1,32 @@
1
1
  /* LISTING — the pieces a collection of N records is drawn with: rows, columns, paging,
2
- sorting, grouping. The `List` view composes them; any other component may reuse them. */
3
- export { defaultVisibleIds, reconcileVisible, toggleColumn, useColumnControl, visibleColumns, } from "./columns.js";
4
- export { ColumnsMenu, specsFromColumns, } from "./ColumnsMenu.js";
2
+ sorting, grouping. The `List` view composes them; any other component may reuse them. What
3
+ draws nothing — the rules of a set's columns, its page sizes, a branch toggled, a level
4
+ named — comes from modules without `"use client"`, so a server component reads it
5
+ (`tests/serverBoundary.test.ts`). */
6
+ export { toggleCollapsed } from "./collapsed.js";
7
+ export { useColumnControl, } from "./columns.js";
8
+ export { ColumnsMenu } from "./ColumnsMenu.js";
9
+ export { defaultVisibleIds, reconcileVisible, specsFromColumns, toggleColumn, visibleColumns, } from "./columnSpecs.js";
5
10
  export { Listing } from "./Listing.js";
6
11
  export { ListingBar } from "./ListingBar.js";
7
12
  export {} from "./modelCells.js";
8
13
  export { claimedFields, columnsFromModel, modelCellKind, readModelValue, } from "./modelColumns.js";
9
- export { DEFAULT_PAGE_SIZE, PAGE_SIZES, useCursorPagination, usePagination, } from "./pages.js";
14
+ export { useCursorPagination, usePagination, } from "./pages.js";
15
+ export { DEFAULT_PAGE_SIZE, PAGE_SIZES } from "./pageSizes.js";
10
16
  export { Pagination } from "./Pagination.js";
11
17
  export { RecordLink } from "./RecordLink.js";
12
18
  export { GroupHeader, Row } from "./Row.js";
13
19
  export { useSelection } from "./selection.js";
14
20
  export { useSetControl } from "./set.js";
15
- export { toggleCollapsed, useTreeControl, } from "./tree.js";
21
+ export { useTreeControl } from "./tree.js";
16
22
  export { ViewSwitcher, } from "./ViewSwitcher.js";
17
23
  /* The grouping levels' control. The vocabulary is in `system/grouping.ts`. */
18
- export { AxisLevels, levelId, levelLabeler, } from "./AxisLevels.js";
24
+ export { AxisLevels } from "./AxisLevels.js";
19
25
  export { BoardColumns, } from "./BoardColumns.js";
20
26
  export { ChartExplorer, } from "./ChartExplorer.js";
21
27
  export { useGroupingControl, } from "./grouping.js";
22
28
  export { GroupingLevels, } from "./GroupingLevels.js";
29
+ export { levelId, levelLabeler } from "./levels.js";
23
30
  export { PivotExplorer, } from "./PivotExplorer.js";
24
31
  export { RecordCard } from "./RecordCard.js";
25
32
  export { SortMenu, } from "./SortMenu.js";
@@ -0,0 +1,9 @@
1
+ import type { GroupableField, GroupLevel } from "../../foundations/grouping.js";
2
+ /** A level as one string: its field and its grain. */
3
+ export declare const levelId: (level: GroupLevel) => string;
4
+ /** The way back from `levelId`. Exported for `AxisLevels`; not public. */
5
+ export declare const fromId: (id: string) => GroupLevel;
6
+ /** How a level is named: the field's label, and its grain when it is a date. */
7
+ export declare function levelLabeler(fields: readonly GroupableField[]): (level: GroupLevel) => string;
8
+ /** `fields` name what they list; anything else is named by `fallback`, then by its id. */
9
+ export declare function namer(fields: readonly GroupableField[], fallback?: (level: GroupLevel) => string): (level: GroupLevel) => string;
@@ -0,0 +1,27 @@
1
+ import { grainName } from "../../foundations/calendar.js";
2
+ /* How a grouping level is identified and named — the pivot's axes and the chart's series
3
+ (`AxisLevels`). Plain, without `"use client"`: a server component names a level the same
4
+ way. */
5
+ /** A level as one string: its field and its grain. */
6
+ export const levelId = (level) => `${level.field}:${level.grain ?? ""}`;
7
+ /** The way back from `levelId`. Exported for `AxisLevels`; not public. */
8
+ export const fromId = (id) => {
9
+ const [field = "", grain = ""] = id.split(":");
10
+ return grain === "" ? { field } : { field, grain: grain };
11
+ };
12
+ /** How a level is named: the field's label, and its grain when it is a date. */
13
+ export function levelLabeler(fields) {
14
+ return (level) => {
15
+ const field = fields.find((one) => one.field === level.field)?.label ?? level.field;
16
+ return level.grain === undefined
17
+ ? field
18
+ : `${field} · ${grainName(level.grain).toLowerCase()}`;
19
+ };
20
+ }
21
+ /** `fields` name what they list; anything else is named by `fallback`, then by its id. */
22
+ export function namer(fields, fallback) {
23
+ const named = levelLabeler(fields);
24
+ return (level) => fallback !== undefined && !fields.some((one) => one.field === level.field)
25
+ ? fallback(level)
26
+ : named(level);
27
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * How many records a list shows until someone asks for another size.
3
+ *
4
+ * 80 is the product default: enough to scan a catalog without paging every
5
+ * twenty-five rows, still small enough that a table stays a table. 25 / 80 / 100
6
+ * are the presets; any other positive integer is valid and is kept.
7
+ */
8
+ export declare const DEFAULT_PAGE_SIZE = 80;
9
+ export declare const PAGE_SIZES: readonly [25, 80, 100];
@@ -0,0 +1,11 @@
1
+ /* Without `"use client"`, apart from the paging hooks (`pages.ts`): a server component that
2
+ fetches a list's first page asks for the same number of rows the list will show. */
3
+ /**
4
+ * How many records a list shows until someone asks for another size.
5
+ *
6
+ * 80 is the product default: enough to scan a catalog without paging every
7
+ * twenty-five rows, still small enough that a table stays a table. 25 / 80 / 100
8
+ * are the presets; any other positive integer is valid and is kept.
9
+ */
10
+ export const DEFAULT_PAGE_SIZE = 80;
11
+ export const PAGE_SIZES = [25, 80, 100];
@@ -1,12 +1,5 @@
1
- /**
2
- * How many records a list shows until someone asks for another size.
3
- *
4
- * 80 is the product default: enough to scan a catalog without paging every
5
- * twenty-five rows, still small enough that a table stays a table. 25 / 80 / 100
6
- * are the presets; any other positive integer is valid and is kept.
7
- */
8
- export declare const DEFAULT_PAGE_SIZE = 80;
9
- export declare const PAGE_SIZES: readonly [25, 80, 100];
1
+ import { DEFAULT_PAGE_SIZE, PAGE_SIZES } from "./pageSizes.js";
2
+ export { DEFAULT_PAGE_SIZE, PAGE_SIZES };
10
3
  /** What `Pagination` needs, already computed from a set in memory. */
11
4
  export interface PaginationBridge {
12
5
  from: number;
@@ -1,14 +1,10 @@
1
1
  "use client";
2
+ import { DEFAULT_PAGE_SIZE, PAGE_SIZES } from "./pageSizes.js";
2
3
  import { useEffect, useState } from "react";
3
- /**
4
- * How many records a list shows until someone asks for another size.
5
- *
6
- * 80 is the product default: enough to scan a catalog without paging every
7
- * twenty-five rows, still small enough that a table stays a table. 25 / 80 / 100
8
- * are the presets; any other positive integer is valid and is kept.
9
- */
10
- export const DEFAULT_PAGE_SIZE = 80;
11
- export const PAGE_SIZES = [25, 80, 100];
4
+ /* The sizes are plain values (`pageSizes.ts`), without the directive, so a server component
5
+ asks its first page with the size the list will show; re-exported so every path that read
6
+ them here keeps reading them. */
7
+ export { DEFAULT_PAGE_SIZE, PAGE_SIZES };
12
8
  function clampSize(next) {
13
9
  if (!Number.isFinite(next))
14
10
  return DEFAULT_PAGE_SIZE;
@@ -1,3 +1,4 @@
1
+ import { toggleCollapsed } from "./collapsed.js";
1
2
  /**
2
3
  * Which BRANCHES of a set are closed.
3
4
  *
@@ -21,7 +22,7 @@ export type TreeControl = {
21
22
  isOpen: (key: string) => boolean;
22
23
  toggle: (key: string) => void;
23
24
  };
24
- export declare function toggleCollapsed(collapsed: readonly string[], key: string): string[];
25
+ export { toggleCollapsed };
25
26
  export declare function useTreeControl(options?: {
26
27
  collapsed?: readonly string[];
27
28
  onCollapsedChange?: (keys: readonly string[]) => void;
@@ -1,10 +1,9 @@
1
1
  "use client";
2
+ import { toggleCollapsed } from "./collapsed.js";
2
3
  import { useCallback, useState } from "react";
3
- export function toggleCollapsed(collapsed, key) {
4
- return collapsed.includes(key)
5
- ? collapsed.filter((one) => one !== key)
6
- : [...collapsed, key];
7
- }
4
+ /* `toggleCollapsed` is plain (`collapsed.ts`), without the directive, so a server component
5
+ reads it; re-exported so every path that read it here keeps reading it. */
6
+ export { toggleCollapsed };
8
7
  // One empty array for every render: a fresh `[]` would change `toggle` each time.
9
8
  const NONE_COLLAPSED = [];
10
9
  export function useTreeControl(options = {}) {
@@ -1,4 +1,6 @@
1
- export type PreviewKind = "image" | "pdf" | "markdown" | "text" | "other";
1
+ import { type PreviewKind, previewKind } from "./previewKind.js";
2
+ export type { PreviewKind };
3
+ export { previewKind };
2
4
  export type PreviewFile = {
3
5
  /** The file name as saved: it picks the kind together with `type`. */
4
6
  name: string;
@@ -9,8 +11,6 @@ export type PreviewFile = {
9
11
  /** In bytes. Written for the locale in the header. */
10
12
  size?: number;
11
13
  };
12
- /** The renderer for a file. Pure, so the choice is tested without a browser. */
13
- export declare function previewKind(name: string, type?: string): PreviewKind;
14
14
  export type FilePreviewProps = {
15
15
  file: PreviewFile;
16
16
  /** The pdf.js worker, when the application serves it itself. */
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { attachmentKind, fileExtension, formatFileSize, } from "../attachments/files.js";
3
+ import { formatFileSize } from "../attachments/files.js";
4
+ import { previewKind, } from "./previewKind.js";
4
5
  import { useUiCopy } from "../../foundations/copy.js";
5
6
  import { Button, ButtonLink } from "../../primitives/button/Button.js";
6
7
  import { Empty, Failed, Skeleton } from "../../primitives/notice/Notice.js";
@@ -35,20 +36,7 @@ const PdfPreview = lazy(() => import("./PdfPreview.js"));
35
36
  const MarkdownView = lazy(() => import("../../primitives/value/Markdown.js").then((m) => ({ default: m.Markdown })));
36
37
  /** A text preview larger than this is not read into the tab: download instead. */
37
38
  const MAX_TEXT_BYTES = 1_000_000;
38
- const TEXT_EXTENSIONS = new Set(["txt", "csv", "json", "log", "xml", "yaml", "yml"]);
39
- const MARKDOWN_EXTENSIONS = new Set(["md", "markdown"]);
40
- /** The renderer for a file. Pure, so the choice is tested without a browser. */
41
- export function previewKind(name, type) {
42
- const kind = attachmentKind(name, type);
43
- if (kind === "image" || kind === "pdf")
44
- return kind;
45
- const extension = fileExtension(name).toLowerCase();
46
- if (MARKDOWN_EXTENSIONS.has(extension))
47
- return "markdown";
48
- if (TEXT_EXTENSIONS.has(extension) || type?.startsWith("text/") === true)
49
- return "text";
50
- return "other";
51
- }
39
+ export { previewKind };
52
40
  export function FilePreview({ file, pdfWorkerUrl }) {
53
41
  const copy = useUiCopy();
54
42
  const kind = previewKind(file.name, file.type);
@@ -1 +1,2 @@
1
- export { FilePreview, type FilePreviewProps, type PreviewFile, type PreviewKind, previewKind, } from "./FilePreview.js";
1
+ export { FilePreview, type FilePreviewProps, type PreviewFile, } from "./FilePreview.js";
2
+ export { type PreviewKind, previewKind, } from "./previewKind.js";
@@ -1,2 +1,3 @@
1
1
  /* PREVIEW — the file itself, drawn by what it is: an image, a PDF, markdown or text. */
2
- export { FilePreview, previewKind, } from "./FilePreview.js";
2
+ export { FilePreview, } from "./FilePreview.js";
3
+ export { previewKind, } from "./previewKind.js";
@@ -0,0 +1,3 @@
1
+ export type PreviewKind = "image" | "pdf" | "markdown" | "text" | "other";
2
+ /** The renderer for a file. Pure, so the choice is tested without a browser. */
3
+ export declare function previewKind(name: string, type?: string): PreviewKind;
@@ -0,0 +1,17 @@
1
+ import { attachmentKind, fileExtension } from "../attachments/files.js";
2
+ /* Without `"use client"`, apart from `FilePreview.tsx` (which draws the file, and loads a PDF
3
+ viewer to do it): a server component that decides how a file will be shown reads this. */
4
+ const TEXT_EXTENSIONS = new Set(["txt", "csv", "json", "log", "xml", "yaml", "yml"]);
5
+ const MARKDOWN_EXTENSIONS = new Set(["md", "markdown"]);
6
+ /** The renderer for a file. Pure, so the choice is tested without a browser. */
7
+ export function previewKind(name, type) {
8
+ const kind = attachmentKind(name, type);
9
+ if (kind === "image" || kind === "pdf")
10
+ return kind;
11
+ const extension = fileExtension(name).toLowerCase();
12
+ if (MARKDOWN_EXTENSIONS.has(extension))
13
+ return "markdown";
14
+ if (TEXT_EXTENSIONS.has(extension) || type?.startsWith("text/") === true)
15
+ return "text";
16
+ return "other";
17
+ }
@@ -1,151 +1,17 @@
1
1
  import { type ValueEditor } from "./context.js";
2
- import type { BuiltFilter, CriteriaJoin, RecordKey, RecordOption, ThroughMatch } from "./criteria.js";
2
+ import type { BuiltFilter } from "./criteria.js";
3
+ import { blankCondition, blankGroup, describeFilter, isRecognizedFilter, liftRecords, namesOf, type RecordNames, recordOps, type TreeCondition, treeFromFilter, type TreeGroup, type TreeHop, type TreeNode, treeToFilter } from "./filterTree.js";
3
4
  import { type ModelDefinition } from "./model.js";
4
5
  import { type LoadModel, type ModelCache } from "./paths.js";
5
- import { type BrowseRecords, type RecordTarget, type SearchRecords } from "./records.js";
6
- /** Whether this is one of the shapes the filter recognises — condition, or `all`/`any`/
7
- * `negate` group. A valid JSON that is none of these —`{}`, `{"foo": 1}`, a loose array—
8
- * is not a filter this component knows how to draw, and is treated as a shape error instead of
9
- * trying to show anything at all. */
10
- export declare function isRecognizedFilter(value: unknown): value is BuiltFilter;
11
- /** One relation crossed on the way to a condition's field: «Líneas», and how many of the
12
- * lines have to match. Whether the relation reaches many is the MODEL's to say, not the
13
- * hop's: criteria's `{through, selection}` does not carry it, so a hop read back from a
14
- * filter could not know it. A to-one relation keeps `"any"` — the one record it reaches. */
15
- export interface TreeHop {
16
- field: string;
17
- match: ThroughMatch;
18
- }
19
- export interface TreeCondition {
20
- kind: "condition";
21
- /** The relations crossed before `field`, in order: `Líneas > Impuestos` of «Líneas >
22
- * Impuestos > Monto». Absent or empty = a field of the record itself. */
23
- through?: TreeHop[];
24
- /** The LAST field of the path: the one compared. Its operators and its type decide the
25
- * rest of the row. */
26
- field: string;
27
- operator: string;
28
- value: string;
29
- /** The other end, for the operators that compare against two —today `between`—. Empty in
30
- * all the others, where it means nothing. */
31
- upper?: string;
32
- /** The value as it travels when it is not the text: `true`, `7`, a list read back — kept so
33
- * a rule read from a filter goes back out the same, not as the string it is drawn with.
34
- * Writing in the box drops it: what is written is then the value. */
35
- raw?: unknown;
36
- /** The values CHOSEN, with the names they are read by — records of a relation, words of an
37
- * enum, «está en» a list. What travels is their `id`. */
38
- values?: RecordOption[];
39
- /** The rule asks about RECORDS of a relation: `field` is the relation itself, chosen by
40
- * name and compared by key (`recordsFilter`). */
41
- target?: RecordTarget;
42
- }
43
- export interface TreeGroup {
44
- kind: "group";
45
- /** All, any, or NONE. All three, and the same as the bar's: negating
46
- * something could only be written in the JSON, and a question the editor does not
47
- * know how to build is a question most people will not ask. */
48
- join: CriteriaJoin;
49
- children: TreeNode[];
50
- }
51
- export type TreeNode = TreeCondition | TreeGroup;
52
- export declare function blankCondition(model: ModelDefinition, first: string | undefined): TreeCondition;
53
- export declare function blankGroup(model: ModelDefinition, first: string | undefined): TreeGroup;
54
- /** The tree as the filter that travels.
55
- *
56
- * in a lone condition
57
- * out that condition, unwrapped
58
- *
59
- * in group with two children, join «any»
60
- * out {any: [ … , … ]}
61
- *
62
- * A group with a single child is not wrapped —it is that child—, and a group with no children disappears: neither
63
- * an empty «todas» nor «cualquiera» is a filter anybody asked for. The rule holds at any
64
- * level, not only at the root, so nesting a single-condition group is the same as not
65
- * having nested it. */
66
- export declare function treeToFilter(node: TreeNode): BuiltFilter | undefined;
67
- /** The filter read back into a tree.
68
- *
69
- * in {field: "name", operator: "=", value: "labs"}
70
- * out TreeCondition
71
- *
72
- * in {any: [{all: [cond1, cond2]}, cond3]} group inside a group
73
- * out TreeGroup(any) with a TreeGroup(all) and a condition as children
74
- *
75
- * in {negate: {any: [cond1, cond2]}}
76
- * out TreeGroup(not) with the two conditions as children
77
- *
78
- * An `any`'s `negate` opens into the «ninguna» group and does not stay as a group
79
- * inside another: it is what `treeToFilter` writes back, so there and
80
- * back give the same. What can NOT be read —an object that is neither a
81
- * condition nor any of the three shapes— returns `null`, and there the component
82
- * shows it read-only while still letting you touch it as JSON.
83
- */
84
- export declare function treeFromFilter(filter: unknown): TreeNode | null;
85
- /** The operators a rule about records offers: one record or several, in or out — and, through
86
- * a column that admits it, «está vacío». A to-many relation is asked by some of its records
87
- * or none of them. */
88
- export declare function recordOps(target: RecordTarget): string[];
89
- /**
90
- * The rules about RECORDS of a relation, recognised again in a tree read back.
91
- *
92
- * A filter carries keys, never which relation they were chosen from: `customer_id in [7, 9]`
93
- * is, for the tree, a column compared to two numbers. The model says that `customer_id` is
94
- * how «Cliente» is compared, so the row is drawn as «Cliente es alguno de [Andrés Pérez,
95
- * Andrés Gutiérrez]» — the names asked of `searchRecords` by key. The same for a to-many
96
- * crossed to its key: `{through: "tags", selection: {field: "id", operator: "in", …}}` is
97
- * «Etiquetas es alguno de …».
98
- *
99
- * in {field: "customer_id", operator: "in", value: [7, 9]} (customer_id names Cliente)
100
- * out {field: "customer", target: Cliente, operator: "in", values: [#7, #9]}
101
- *
102
- * Only on the record's own fields: a relation of a related record needs its model, and a row
103
- * that stays a plain condition still filters the same.
104
- */
105
- export declare function liftRecords(node: TreeNode, model: ModelDefinition,
106
- /** The model at the end of a path of relations, when it already arrived: with it, a rule
107
- * about records past a relation —«Cliente > País es Bolivia»— is recognised too. */
108
- modelAt?: (path: readonly string[]) => ModelDefinition | undefined): TreeNode;
109
- /** The names of the records a tree has chosen, by relation and key: what says them in a
110
- * sentence (`describeFilter`) once the tree is applied. */
111
- export declare function namesOf(node: TreeNode): RecordNames;
6
+ import { type BrowseRecords, type SearchRecords } from "./records.js";
7
+ export type { RecordNames, TreeCondition, TreeGroup, TreeHop, TreeNode };
8
+ export { blankCondition, blankGroup, describeFilter, isRecognizedFilter, liftRecords, namesOf, recordOps, treeFromFilter, treeToFilter, };
112
9
  /**
113
10
  * Names the records a tree read back carries only by key — ONE question per relation, for the
114
11
  * whole tree. Per row, five rows answered at five moments and each wrote its answer over a tree
115
12
  * that no longer had the others'. Until it answers, a record reads «#7».
116
13
  */
117
14
  export declare function useRecordNames(tree: TreeNode, searchRecords: SearchRecords | undefined, apply: (named: (tree: TreeNode) => TreeNode) => void): void;
118
- /** The filter said in one line, for a chip or a label.
119
- *
120
- * in {field: "row_count", operator: ">", value: 1000}, with the model
121
- * out 'filas mayor que 1000'
122
- *
123
- * in {all: [cond1, cond2]}
124
- * out 'el nombre contiene labs y filas mayor que 1000'
125
- *
126
- * in {any: [cond1, cond2]}
127
- * out 'el nombre es a o el nombre es b'
128
- *
129
- * Each condition is said by `sayCondition`, which is the same one the bar uses: without
130
- * that, what is written in the bar and what is built in the dialog read differently even though
131
- * they filter the same, and nobody knows which of the two phrases is the one in charge.
132
- *
133
- * **The model is the one that knows what a field is called.** Without it the raw
134
- * name remains —`row_count`—, which is the best that can be said without asking
135
- * anybody.
136
- *
137
- * A nested group is enclosed in parentheses, which is what keeps «a y (b o c)» from being
138
- * read as «(a y b) o c». Past three conditions it is cut: a chip that does not fit in
139
- * the bar says nothing — that is what opening the builder and seeing it whole is for. */
140
- export declare function describeFilter(node: BuiltFilter, model?: ModelDefinition,
141
- /** The model at the end of a path of relations, when it already arrived: it names the
142
- * fields of a `through`. Without it they keep their raw names. */
143
- modelAt?: (path: readonly string[]) => ModelDefinition | undefined,
144
- /** The names of the records a filter asks for, by relation and key: «Cliente es Andrés
145
- * Pérez» instead of «customer_id es 7». The builder hands its own (`namesOf`). */
146
- names?: RecordNames): string;
147
- /** A record's name by the relation it was chosen from and its key, when it is known. */
148
- export type RecordNames = (relation: string, key: RecordKey) => string | undefined;
149
15
  /** The filter drawn as it is, recursive: a condition is a line, `all`/`any` are a
150
16
  * group with its label and its children inside, `negate` is «no» wrapping the one it negates.
151
17
  *