@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
package/README.md CHANGED
@@ -123,9 +123,36 @@ export default { plugins: { "@tailwindcss/postcss": {} } };
123
123
  ```
124
124
 
125
125
  - **Server Components** may import from `@sincpro/web-ui`. Every module that needs the browser
126
- (hooks, context, events) starts with `"use client"`, and a test keeps it that way; pure logic
127
- (calendar, pivot, criteria) stays callable from the server. The views are client components:
128
- compose `Record` or `List` inside a client component of your own.
126
+ (hooks, context, events) starts with `"use client"`, and a test keeps it that way. What is
127
+ public and draws nothing lives in a module WITHOUT it, so a Server Component calls it and
128
+ gets a value, not a client reference: the looks (`buttonClasses`, `controlClasses`,
129
+ `menuTriggerClasses`, `CELL_TONE`, `byDensity`, `bySurface`), the formatters (`formatCount`,
130
+ `formatNumber`, `formatWith`, `formatDateTime`, `formatRelative`, `countText`), the words
131
+ (`installCopy`, `currentCopy`, `fillCopy`, `ENGLISH_COPY`), the theme's names
132
+ (`THEME_ATTRIBUTE`, `isTheme`), `writeXlsx`, the calendar, the pivot, the criteria and the
133
+ filter's tree (`describeFilter`, `treeFromFilter`) — `tests/serverBoundary.test.ts` holds
134
+ it. What needs a browser stays client: `downloadFile`, `downloadXlsx`, `applyTheme`,
135
+ `sanitizeRichText`. The views are client components: compose `Record` or `List` inside a
136
+ client component of your own.
137
+
138
+ ```tsx
139
+ // app/invoices/page.tsx — a Server Component
140
+ import Link from "next/link";
141
+ import { buttonClasses, formatCount } from "@sincpro/web-ui";
142
+
143
+ export default async function Invoices() {
144
+ const pending = await countPending();
145
+ return (
146
+ <header>
147
+ <p>{formatCount(pending)} por cobrar</p>
148
+ <Link href="/invoices/new" className={buttonClasses("primary", "md")}>
149
+ Nueva factura
150
+ </Link>
151
+ </header>
152
+ );
153
+ }
154
+ ```
155
+
129
156
  - **The language.** `installCopy` sets the one global there is — and on a server, one process
130
157
  renders every page and every request. Installed in one page, it leaks into the next page the
131
158
  server renders, which the browser then draws in English: a hydration error. Install it in a
@@ -142,6 +169,11 @@ export default { plugins: { "@tailwindcss/postcss": {} } };
142
169
  }
143
170
  ```
144
171
 
172
+ A Server Component that formats (`formatCount`, `formatDateTime`, `describeFilter`) reads
173
+ the words installed in ITS module graph — the server components' copy of the package is not
174
+ the browser's. Install the language there too, at the top of a module your root layout
175
+ imports (the same for every request), or pass the locale: `formatCount(total, "es-BO")`.
176
+
145
177
  - **webpack** (`next build --webpack`): a Server Component that imports from the package root
146
178
  makes webpack send the WHOLE library to the browser (~1.2 MB gzip for one `Button`). Let Next
147
179
  rewrite those imports — Turbopack, the default, does not need it:
@@ -1,5 +1,5 @@
1
+ import { type MessageKind, writeANote } from "./messageKind.js";
1
2
  import type { AttachmentFile } from "../attachments/files.js";
2
- import { type UiCopy } from "../../foundations/copy.js";
3
3
  import { type ReactNode } from "react";
4
4
  /**
5
5
  * The box to write in. What gets written is drawn by `Activity`, together with
@@ -38,28 +38,8 @@ export type Message = {
38
38
  * (`FileList`). A message may be only its files: then `body` is empty. */
39
39
  files?: readonly AttachmentFile[];
40
40
  };
41
- /** A way of writing. `note` stays inside; everything else leaves, and what
42
- * changes between them is only the channel and who is on the other side. */
43
- export type MessageKind = {
44
- id: string;
45
- label: string;
46
- /** It stays inside. Without this the kit assumes it leaves, which is the
47
- * answer that errs on the side of asking. */
48
- internal?: boolean;
49
- /** Who gets it, in their own words: names for a mail, numbers for WhatsApp.
50
- * Shown before sending, never after. */
51
- recipients?: readonly string[];
52
- placeholder?: string;
53
- };
54
- /**
55
- * WRITE A NOTE, the way every list has.
56
- *
57
- * It is a function and not a constant because its words come from the copy, and a
58
- * constant would freeze them with whatever there was when the module loaded —that is, the
59
- * factory ones— even if another is installed afterwards. Without `copy`, the installed ones; a
60
- * component passes it those of its branch.
61
- */
62
- export declare function writeANote(copy?: UiCopy): MessageKind;
41
+ export type { MessageKind };
42
+ export { writeANote };
63
43
  export type MessageComposerProps = {
64
44
  /** The ways of writing this record takes. Its own list because it is the
65
45
  * application that knows whether there is WhatsApp, and to whose number. */
@@ -1,26 +1,12 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { currentCopy, useUiCopy } from "../../foundations/copy.js";
3
+ import { writeANote, } from "./messageKind.js";
4
+ import { useUiCopy } from "../../foundations/copy.js";
4
5
  import { Button } from "../../primitives/button/Button.js";
5
6
  import { TextArea } from "../../primitives/field/Field.js";
6
7
  import { Send, Users, X } from "lucide-react";
7
8
  import { useState } from "react";
8
- /**
9
- * WRITE A NOTE, the way every list has.
10
- *
11
- * It is a function and not a constant because its words come from the copy, and a
12
- * constant would freeze them with whatever there was when the module loaded —that is, the
13
- * factory ones— even if another is installed afterwards. Without `copy`, the installed ones; a
14
- * component passes it those of its branch.
15
- */
16
- export function writeANote(copy = currentCopy()) {
17
- return {
18
- id: "note",
19
- label: copy.activity.writeNote,
20
- internal: true,
21
- placeholder: copy.activity.notePlaceholder,
22
- };
23
- }
9
+ export { writeANote };
24
10
  export function MessageComposer({ kinds, onSend, sending = false, footer, }) {
25
11
  const copy = useUiCopy();
26
12
  /* The default way is built in here and not in the signature: a parameter
@@ -1,4 +1,5 @@
1
1
  export { Activity, type ActivityAlert, type ActivityChange, type ActivityEvent, type ActivityLayout, type ActivityProps, useActivity, } from "./Activity.js";
2
2
  export { ActivityBadge, type ActivityState, } from "./ActivityBadge.js";
3
- export { type Message, MessageComposer, type MessageComposerProps, type MessageKind, writeANote, } from "./Messages.js";
3
+ export { type MessageKind, writeANote, } from "./messageKind.js";
4
+ export { type Message, MessageComposer, type MessageComposerProps, } from "./Messages.js";
4
5
  export { Timeline, type TimelineItemProps, type TimelineProps, } from "./Timeline.js";
@@ -1,5 +1,6 @@
1
1
  /* ACTIVITY — everything around a record: its notices, its conversation and its history. */
2
2
  export { Activity, useActivity, } from "./Activity.js";
3
3
  export { ActivityBadge, } from "./ActivityBadge.js";
4
- export { MessageComposer, writeANote, } from "./Messages.js";
4
+ export { writeANote, } from "./messageKind.js";
5
+ export { MessageComposer, } from "./Messages.js";
5
6
  export { Timeline, } from "./Timeline.js";
@@ -0,0 +1,23 @@
1
+ import { type UiCopy } from "../../foundations/uiCopy.js";
2
+ /** A way of writing. `note` stays inside; everything else leaves, and what
3
+ * changes between them is only the channel and who is on the other side. */
4
+ export type MessageKind = {
5
+ id: string;
6
+ label: string;
7
+ /** It stays inside. Without this the kit assumes it leaves, which is the
8
+ * answer that errs on the side of asking. */
9
+ internal?: boolean;
10
+ /** Who gets it, in their own words: names for a mail, numbers for WhatsApp.
11
+ * Shown before sending, never after. */
12
+ recipients?: readonly string[];
13
+ placeholder?: string;
14
+ };
15
+ /**
16
+ * WRITE A NOTE, the way every list has.
17
+ *
18
+ * It is a function and not a constant because its words come from the copy, and a
19
+ * constant would freeze them with whatever there was when the module loaded —that is, the
20
+ * factory ones— even if another is installed afterwards. Without `copy`, the installed ones; a
21
+ * component passes it those of its branch.
22
+ */
23
+ export declare function writeANote(copy?: UiCopy): MessageKind;
@@ -0,0 +1,17 @@
1
+ import { currentCopy } from "../../foundations/uiCopy.js";
2
+ /**
3
+ * WRITE A NOTE, the way every list has.
4
+ *
5
+ * It is a function and not a constant because its words come from the copy, and a
6
+ * constant would freeze them with whatever there was when the module loaded —that is, the
7
+ * factory ones— even if another is installed afterwards. Without `copy`, the installed ones; a
8
+ * component passes it those of its branch.
9
+ */
10
+ export function writeANote(copy = currentCopy()) {
11
+ return {
12
+ id: "note",
13
+ label: copy.activity.writeNote,
14
+ internal: true,
15
+ placeholder: copy.activity.notePlaceholder,
16
+ };
17
+ }
@@ -1,4 +1,4 @@
1
- import { type UiCopy } from "../../foundations/copy.js";
1
+ import { type UiCopy } from "../../foundations/uiCopy.js";
2
2
  import type { ToastSpec } from "../../primitives/notice/Toast.js";
3
3
  import { type LucideIcon } from "lucide-react";
4
4
  import type { ReactNode } from "react";
@@ -1,4 +1,4 @@
1
- import { fillCopy } from "../../foundations/copy.js";
1
+ import { fillCopy } from "../../foundations/uiCopy.js";
2
2
  import { Bot } from "lucide-react";
3
3
  /* ==================================================================== *
4
4
  * THE ASSISTANT'S CONTRACT — what every piece of this family agrees on.
@@ -1,4 +1,4 @@
1
- import { currentCopy, currentCopyLocale, fillCopy } from "../../foundations/copy.js";
1
+ import { currentCopy, currentCopyLocale, fillCopy } from "../../foundations/uiCopy.js";
2
2
  const BINS = 12;
3
3
  const TOP = 12;
4
4
  export function frameFromRows(columns, rows) {
@@ -1,4 +1,5 @@
1
1
  export { Guide, type GuideCloseReason, type GuideProps, type GuideStep, } from "./Guide.js";
2
2
  export { GuideSpot } from "./GuideSpot.js";
3
3
  export { type Box as GuideBox, type CardPlacement as GuideCardPlacement, type GuideSide, type Size as GuideSize, placeCard, } from "./place.js";
4
- export { boxOf, findTarget, type Found as GuideMatch, type GuideTarget, selectorOf, } from "./target.js";
4
+ export { type GuideTarget, selectorOf } from "./selector.js";
5
+ export { boxOf, findTarget, type Found as GuideMatch, } from "./target.js";
@@ -3,4 +3,5 @@ export { Guide, } from "./Guide.js";
3
3
  export { GuideSpot } from "./GuideSpot.js";
4
4
  /* The rules underneath, for an application that draws a tour of its own. */
5
5
  export { placeCard, } from "./place.js";
6
- export { boxOf, findTarget, selectorOf, } from "./target.js";
6
+ export { selectorOf } from "./selector.js";
7
+ export { boxOf, findTarget, } from "./target.js";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * What a step of a tour points at.
3
+ *
4
+ * Context: the anchors are the ones the system already keeps stable, so no component needs a
5
+ * prop to be pointed at:
6
+ *
7
+ * - `{ part }` — a web-ui part (`data-ui`, listed in the README and guarded by a test):
8
+ * `{ part: "sidebar.search" }`. With `key`, one item of a collection:
9
+ * `{ part: "navigation.item", key: "socios.cuotas" }`.
10
+ * - `{ spot }` — anything the application marked: `<GuideSpot id="cifras">` or its own
11
+ * element with `data-guide="cifras"`.
12
+ * - `{ selector }` — any CSS selector, for what has no name yet.
13
+ * - a function — a ref, or whatever the application computes at that moment.
14
+ */
15
+ export type GuideTarget = {
16
+ part: string;
17
+ key?: string;
18
+ } | {
19
+ spot: string;
20
+ } | {
21
+ selector: string;
22
+ } | (() => Element | null | undefined);
23
+ /** The CSS selector a target names; `null` for a function. */
24
+ export declare function selectorOf(target: Exclude<GuideTarget, () => unknown>): string;
25
+ export declare function selectorOf(target: GuideTarget): string | null;
@@ -0,0 +1,14 @@
1
+ /* A quoted attribute value: only `"` and `\` need escaping there — and unlike `CSS.escape`
2
+ this also runs where there is no DOM (a test, a server). */
3
+ const quoted = (value) => `"${value.replace(/["\\]/g, "\\$&")}"`;
4
+ export function selectorOf(target) {
5
+ if (typeof target === "function")
6
+ return null;
7
+ if ("part" in target) {
8
+ const part = `[data-ui=${quoted(target.part)}]`;
9
+ return target.key === undefined ? part : `${part}[data-key=${quoted(target.key)}]`;
10
+ }
11
+ if ("spot" in target)
12
+ return `[data-guide=${quoted(target.spot)}]`;
13
+ return target.selector;
14
+ }
@@ -1,29 +1,7 @@
1
1
  import type { Box } from "./place.js";
2
- /**
3
- * What a step of a tour points at.
4
- *
5
- * Context: the anchors are the ones the system already keeps stable, so no component needs a
6
- * prop to be pointed at:
7
- *
8
- * - `{ part }` — a web-ui part (`data-ui`, listed in the README and guarded by a test):
9
- * `{ part: "sidebar.search" }`. With `key`, one item of a collection:
10
- * `{ part: "navigation.item", key: "socios.cuotas" }`.
11
- * - `{ spot }` — anything the application marked: `<GuideSpot id="cifras">` or its own
12
- * element with `data-guide="cifras"`.
13
- * - `{ selector }` — any CSS selector, for what has no name yet.
14
- * - a function — a ref, or whatever the application computes at that moment.
15
- */
16
- export type GuideTarget = {
17
- part: string;
18
- key?: string;
19
- } | {
20
- spot: string;
21
- } | {
22
- selector: string;
23
- } | (() => Element | null | undefined);
24
- /** The CSS selector a target names; `null` for a function. */
25
- export declare function selectorOf(target: Exclude<GuideTarget, () => unknown>): string;
26
- export declare function selectorOf(target: GuideTarget): string | null;
2
+ import { type GuideTarget, selectorOf } from "./selector.js";
3
+ export type { GuideTarget };
4
+ export { selectorOf };
27
5
  /** The element's box on screen, `null` when it has none — hidden, or not laid out. A
28
6
  * `GuideSpot` measures as the union of what it wraps. */
29
7
  export declare function boxOf(element: Element): Box | null;
@@ -1,18 +1,6 @@
1
1
  "use client";
2
- /* A quoted attribute value: only `"` and `\` need escaping there — and unlike `CSS.escape`
3
- this also runs where there is no DOM (a test, a server). */
4
- const quoted = (value) => `"${value.replace(/["\\]/g, "\\$&")}"`;
5
- export function selectorOf(target) {
6
- if (typeof target === "function")
7
- return null;
8
- if ("part" in target) {
9
- const part = `[data-ui=${quoted(target.part)}]`;
10
- return target.key === undefined ? part : `${part}[data-key=${quoted(target.key)}]`;
11
- }
12
- if ("spot" in target)
13
- return `[data-guide=${quoted(target.spot)}]`;
14
- return target.selector;
15
- }
2
+ import { selectorOf } from "./selector.js";
3
+ export { selectorOf };
16
4
  /** `display: contents` has no box of its own (a `GuideSpot`): its box is its children's. */
17
5
  function wraps(element) {
18
6
  return getComputedStyle(element).display === "contents";
@@ -1,3 +1,4 @@
1
+ import { levelId, levelLabeler, namer } from "./levels.js";
1
2
  import type { GroupableField, GroupLevel } from "../../foundations/grouping.js";
2
3
  /**
3
4
  * The levels of ONE axis, chosen on the screen: a tag per level with its ×, and «+» to add
@@ -6,11 +7,7 @@ import type { GroupableField, GroupLevel } from "../../foundations/grouping.js";
6
7
  * Context: the pivot had it written inline, and the chart asks the same question twice
7
8
  * (its axis and its series). Two copies would drift; this is the one both draw.
8
9
  */
9
- export declare const levelId: (level: GroupLevel) => string;
10
- /** How a level is named: the field's label, and its grain when it is a date. */
11
- export declare function levelLabeler(fields: readonly GroupableField[]): (level: GroupLevel) => string;
12
- /** `fields` name what they list; anything else is named by `fallback`, then by its id. */
13
- export declare function namer(fields: readonly GroupableField[], fallback?: (level: GroupLevel) => string): (level: GroupLevel) => string;
10
+ export { levelId, levelLabeler, namer };
14
11
  export declare function AxisLevels({ name, levels, onChange, fields, used, labelOf: outerLabel, }: {
15
12
  name: string;
16
13
  levels: readonly GroupLevel[];
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { grainName } from "../../foundations/calendar.js";
3
+ import { fromId, levelId, levelLabeler, namer, } from "./levels.js";
4
4
  import { fillCopy, useUiCopy } from "../../foundations/copy.js";
5
5
  import { Menu } from "../../primitives/menu/Menu.js";
6
6
  import { Tags } from "../../primitives/tag/Tags.js";
@@ -12,27 +12,10 @@ import { Plus } from "lucide-react";
12
12
  * Context: the pivot had it written inline, and the chart asks the same question twice
13
13
  * (its axis and its series). Two copies would drift; this is the one both draw.
14
14
  */
15
- export const levelId = (level) => `${level.field}:${level.grain ?? ""}`;
16
- const fromId = (id) => {
17
- const [field = "", grain = ""] = id.split(":");
18
- return grain === "" ? { field } : { field, grain: grain };
19
- };
20
- /** How a level is named: the field's label, and its grain when it is a date. */
21
- export function levelLabeler(fields) {
22
- return (level) => {
23
- const field = fields.find((one) => one.field === level.field)?.label ?? level.field;
24
- return level.grain === undefined
25
- ? field
26
- : `${field} · ${grainName(level.grain).toLowerCase()}`;
27
- };
28
- }
29
- /** `fields` name what they list; anything else is named by `fallback`, then by its id. */
30
- export function namer(fields, fallback) {
31
- const named = levelLabeler(fields);
32
- return (level) => fallback !== undefined && !fields.some((one) => one.field === level.field)
33
- ? fallback(level)
34
- : named(level);
35
- }
15
+ /* `levelId`, `levelLabeler` and `namer` are plain (`levels.ts`), without the directive, so a
16
+ server component names a level the same way; re-exported so every path that read them here
17
+ keeps reading them. */
18
+ export { levelId, levelLabeler, namer };
36
19
  export function AxisLevels({ name, levels, onChange, fields, used, labelOf: outerLabel, }) {
37
20
  const words = useUiCopy().pivot;
38
21
  const labelOf = namer(fields, outerLabel);
@@ -1,4 +1,5 @@
1
- import type { ColumnControl, ColumnSpec } from "./columns.js";
1
+ import type { ColumnControl } from "./columns.js";
2
+ import { specsFromColumns } from "./columnSpecs.js";
2
3
  import { type PathPick } from "../search/FieldPath.js";
3
4
  import type { Surface } from "../../foundations/types.js";
4
5
  /**
@@ -18,9 +19,4 @@ export declare function ColumnsMenu({ control, surface, addPath, }: {
18
19
  surface?: Surface;
19
20
  addPath?: PathPick;
20
21
  }): import("react").JSX.Element | null;
21
- export declare function specsFromColumns(columns: readonly {
22
- id: string;
23
- header: string;
24
- optional?: boolean;
25
- defaultHidden?: boolean;
26
- }[], fallbackOptional: boolean): ColumnSpec[];
22
+ export { specsFromColumns };
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { specsFromColumns } from "./columnSpecs.js";
3
4
  import { FieldPath } from "../search/FieldPath.js";
4
5
  import { useUiCopy } from "../../foundations/copy.js";
5
6
  import { Menu } from "../../primitives/menu/Menu.js";
@@ -47,11 +48,6 @@ export function ColumnsMenu({ control, surface, addPath, }) {
47
48
  const menu = (_jsx(Menu, { label: copy.frame.columns, icon: Columns3, groups: groups, onSelect: control.toggle, closeOnSelect: false, active: hiddenOptional, ...(surface === undefined ? {} : { surface }), size: "sm" }));
48
49
  return picker === null ? (menu) : (_jsxs("span", { className: "flex items-center gap-1.5", children: [menu, picker] }));
49
50
  }
50
- export function specsFromColumns(columns, fallbackOptional) {
51
- return columns.map((column) => ({
52
- id: column.id,
53
- label: column.header,
54
- optional: column.optional ?? fallbackOptional,
55
- ...(column.defaultHidden === true ? { defaultHidden: true } : {}),
56
- }));
57
- }
51
+ /* `specsFromColumns` is plain (`columnSpecs.ts`), without the directive; re-exported so every
52
+ path that read it here keeps reading it. */
53
+ export { specsFromColumns };
@@ -0,0 +1,2 @@
1
+ /** `key` opened if it was closed, closed if it was open. */
2
+ export declare function toggleCollapsed(collapsed: readonly string[], key: string): string[];
@@ -0,0 +1,8 @@
1
+ /* Without `"use client"`, apart from `useTreeControl` (`tree.ts`): the closed branches of a set
2
+ are a list of pile paths, and opening or closing one is a plain function. */
3
+ /** `key` opened if it was closed, closed if it was open. */
4
+ export function toggleCollapsed(collapsed, key) {
5
+ return collapsed.includes(key)
6
+ ? collapsed.filter((one) => one !== key)
7
+ : [...collapsed, key];
8
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Which columns of a set are on screen, as plain rules: the spec (required or optional,
3
+ * hidden at first), the default set, a toggle, the set reconciled. `useColumnControl`
4
+ * (`columns.ts`) keeps them in state; these live apart and without `"use client"`, so a server
5
+ * component — the page that reads the person's columns from a cookie — computes the same set.
6
+ */
7
+ export type ColumnSpec = {
8
+ id: string;
9
+ label: string;
10
+ /** When true, the column may leave the view. Required columns stay, and
11
+ * the submenu shows them checked and disabled so the split is visible. */
12
+ optional?: boolean;
13
+ /** Odoo `optional="hide"`: start off. Only for optional columns. */
14
+ defaultHidden?: boolean;
15
+ };
16
+ export declare function isRequiredColumn(column: ColumnSpec): boolean;
17
+ export declare function defaultVisibleIds(columns: readonly ColumnSpec[]): string[];
18
+ /**
19
+ * Required columns always stay. Unknown ids drop out. If everything optional
20
+ * was unchecked, the first column remains — a table with zero columns is not
21
+ * a table.
22
+ */
23
+ export declare function reconcileVisible(columns: readonly ColumnSpec[], visibleIds: readonly string[]): string[];
24
+ export declare function toggleColumn(columns: readonly ColumnSpec[], visibleIds: readonly string[], id: string): string[];
25
+ export declare function visibleColumns<T extends {
26
+ id: string;
27
+ }>(columns: readonly T[], visibleIds: readonly string[]): T[];
28
+ /** A table's columns as specs: `header` is the label, `optional` falls back to the table's. */
29
+ export declare function specsFromColumns(columns: readonly {
30
+ id: string;
31
+ header: string;
32
+ optional?: boolean;
33
+ defaultHidden?: boolean;
34
+ }[], fallbackOptional: boolean): ColumnSpec[];
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Which columns of a set are on screen, as plain rules: the spec (required or optional,
3
+ * hidden at first), the default set, a toggle, the set reconciled. `useColumnControl`
4
+ * (`columns.ts`) keeps them in state; these live apart and without `"use client"`, so a server
5
+ * component — the page that reads the person's columns from a cookie — computes the same set.
6
+ */
7
+ export function isRequiredColumn(column) {
8
+ return column.optional !== true;
9
+ }
10
+ export function defaultVisibleIds(columns) {
11
+ return columns
12
+ .filter((column) => isRequiredColumn(column) || column.defaultHidden !== true)
13
+ .map((column) => column.id);
14
+ }
15
+ /**
16
+ * Required columns always stay. Unknown ids drop out. If everything optional
17
+ * was unchecked, the first column remains — a table with zero columns is not
18
+ * a table.
19
+ */
20
+ export function reconcileVisible(columns, visibleIds) {
21
+ if (columns.length === 0)
22
+ return [];
23
+ const known = new Set(columns.map((column) => column.id));
24
+ const visible = new Set(visibleIds.filter((id) => known.has(id)));
25
+ for (const column of columns) {
26
+ if (isRequiredColumn(column))
27
+ visible.add(column.id);
28
+ }
29
+ if (visible.size === 0)
30
+ visible.add(columns[0].id);
31
+ return columns.filter((column) => visible.has(column.id)).map((column) => column.id);
32
+ }
33
+ export function toggleColumn(columns, visibleIds, id) {
34
+ const column = columns.find((one) => one.id === id);
35
+ if (column === undefined || isRequiredColumn(column)) {
36
+ return reconcileVisible(columns, visibleIds);
37
+ }
38
+ const current = reconcileVisible(columns, visibleIds);
39
+ const next = current.includes(id) ? current.filter((one) => one !== id) : [...current, id];
40
+ return reconcileVisible(columns, next);
41
+ }
42
+ export function visibleColumns(columns, visibleIds) {
43
+ const wanted = new Set(visibleIds);
44
+ return columns.filter((column) => wanted.has(column.id));
45
+ }
46
+ /** A table's columns as specs: `header` is the label, `optional` falls back to the table's. */
47
+ export function specsFromColumns(columns, fallbackOptional) {
48
+ return columns.map((column) => ({
49
+ id: column.id,
50
+ label: column.header,
51
+ optional: column.optional ?? fallbackOptional,
52
+ ...(column.defaultHidden === true ? { defaultHidden: true } : {}),
53
+ }));
54
+ }
@@ -1,3 +1,4 @@
1
+ import { type ColumnSpec, defaultVisibleIds, isRequiredColumn, reconcileVisible, toggleColumn, visibleColumns } from "./columnSpecs.js";
1
2
  /**
2
3
  * Which FIELDS of a set are on screen.
3
4
  *
@@ -11,15 +12,6 @@
11
12
  * and `useSelection` (which rows). Presentation can change; the visible
12
13
  * field set stays.
13
14
  */
14
- export type ColumnSpec = {
15
- id: string;
16
- label: string;
17
- /** When true, the column may leave the view. Required columns stay, and
18
- * the submenu shows them checked and disabled so the split is visible. */
19
- optional?: boolean;
20
- /** Odoo `optional="hide"`: start off. Only for optional columns. */
21
- defaultHidden?: boolean;
22
- };
23
15
  export type ColumnControl = {
24
16
  visibleIds: readonly string[];
25
17
  isVisible: (id: string) => boolean;
@@ -29,18 +21,8 @@ export type ColumnControl = {
29
21
  required: readonly ColumnSpec[];
30
22
  hasOptional: boolean;
31
23
  };
32
- export declare function isRequiredColumn(column: ColumnSpec): boolean;
33
- export declare function defaultVisibleIds(columns: readonly ColumnSpec[]): string[];
34
- /**
35
- * Required columns always stay. Unknown ids drop out. If everything optional
36
- * was unchecked, the first column remains — a table with zero columns is not
37
- * a table.
38
- */
39
- export declare function reconcileVisible(columns: readonly ColumnSpec[], visibleIds: readonly string[]): string[];
40
- export declare function toggleColumn(columns: readonly ColumnSpec[], visibleIds: readonly string[], id: string): string[];
41
- export declare function visibleColumns<T extends {
42
- id: string;
43
- }>(columns: readonly T[], visibleIds: readonly string[]): T[];
24
+ export type { ColumnSpec };
25
+ export { defaultVisibleIds, isRequiredColumn, reconcileVisible, toggleColumn, visibleColumns, };
44
26
  export declare function useColumnControl(columns: readonly ColumnSpec[], options?: {
45
27
  visibleIds?: readonly string[];
46
28
  onVisibleIdsChange?: (ids: readonly string[]) => void;
@@ -1,44 +1,7 @@
1
1
  "use client";
2
+ import { defaultVisibleIds, isRequiredColumn, reconcileVisible, toggleColumn, visibleColumns, } from "./columnSpecs.js";
2
3
  import { useCallback, useState } from "react";
3
- export function isRequiredColumn(column) {
4
- return column.optional !== true;
5
- }
6
- export function defaultVisibleIds(columns) {
7
- return columns
8
- .filter((column) => isRequiredColumn(column) || column.defaultHidden !== true)
9
- .map((column) => column.id);
10
- }
11
- /**
12
- * Required columns always stay. Unknown ids drop out. If everything optional
13
- * was unchecked, the first column remains — a table with zero columns is not
14
- * a table.
15
- */
16
- export function reconcileVisible(columns, visibleIds) {
17
- if (columns.length === 0)
18
- return [];
19
- const known = new Set(columns.map((column) => column.id));
20
- const visible = new Set(visibleIds.filter((id) => known.has(id)));
21
- for (const column of columns) {
22
- if (isRequiredColumn(column))
23
- visible.add(column.id);
24
- }
25
- if (visible.size === 0)
26
- visible.add(columns[0].id);
27
- return columns.filter((column) => visible.has(column.id)).map((column) => column.id);
28
- }
29
- export function toggleColumn(columns, visibleIds, id) {
30
- const column = columns.find((one) => one.id === id);
31
- if (column === undefined || isRequiredColumn(column)) {
32
- return reconcileVisible(columns, visibleIds);
33
- }
34
- const current = reconcileVisible(columns, visibleIds);
35
- const next = current.includes(id) ? current.filter((one) => one !== id) : [...current, id];
36
- return reconcileVisible(columns, next);
37
- }
38
- export function visibleColumns(columns, visibleIds) {
39
- const wanted = new Set(visibleIds);
40
- return columns.filter((column) => wanted.has(column.id));
41
- }
4
+ export { defaultVisibleIds, isRequiredColumn, reconcileVisible, toggleColumn, visibleColumns, };
42
5
  export function useColumnControl(columns, options = {}) {
43
6
  const signature = columns.map((column) => column.id).join("\0");
44
7
  const [owned, setOwned] = useState(() => defaultVisibleIds(columns));