@sincpro/web-ui 2.12.0 → 2.14.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 (137) hide show
  1. package/README.md +56 -21
  2. package/dist/components/gallery/Gallery.d.ts +29 -0
  3. package/dist/components/gallery/Gallery.js +78 -0
  4. package/dist/components/gallery/Lightbox.d.ts +28 -0
  5. package/dist/components/gallery/Lightbox.js +59 -0
  6. package/dist/components/gallery/index.d.ts +2 -0
  7. package/dist/components/gallery/index.js +3 -0
  8. package/dist/components/index.d.ts +3 -0
  9. package/dist/components/index.js +3 -0
  10. package/dist/components/listing/BoardColumns.js +10 -6
  11. package/dist/components/listing/ColumnsMenu.js +4 -2
  12. package/dist/components/listing/Listing.js +3 -1
  13. package/dist/components/listing/ListingBar.d.ts +16 -94
  14. package/dist/components/listing/ListingBar.js +24 -2
  15. package/dist/components/listing/RecordCard.d.ts +41 -3
  16. package/dist/components/listing/RecordCard.js +63 -22
  17. package/dist/components/listing/Row.js +5 -2
  18. package/dist/components/listing/columns.d.ts +3 -0
  19. package/dist/components/listing/columns.js +4 -0
  20. package/dist/components/listing/index.d.ts +2 -2
  21. package/dist/components/listing/index.js +2 -2
  22. package/dist/components/listing/set.d.ts +1 -1
  23. package/dist/components/plans/PlanCard.d.ts +43 -0
  24. package/dist/components/plans/PlanCard.js +35 -0
  25. package/dist/components/plans/index.d.ts +1 -0
  26. package/dist/components/plans/index.js +2 -0
  27. package/dist/components/receipt/Receipt.d.ts +51 -0
  28. package/dist/components/receipt/Receipt.js +23 -0
  29. package/dist/components/receipt/index.d.ts +1 -0
  30. package/dist/components/receipt/index.js +3 -0
  31. package/dist/components/search/CriteriaChips.d.ts +14 -1
  32. package/dist/components/search/CriteriaChips.js +123 -13
  33. package/dist/components/search/JoinWord.js +8 -14
  34. package/dist/components/search/SearchBar.d.ts +10 -1
  35. package/dist/components/search/SearchBar.js +715 -176
  36. package/dist/components/search/WordChoice.d.ts +19 -0
  37. package/dist/components/search/WordChoice.js +8 -0
  38. package/dist/components/search/criteria.d.ts +27 -0
  39. package/dist/components/search/criteria.js +33 -0
  40. package/dist/components/search/index.d.ts +2 -2
  41. package/dist/components/search/index.js +2 -2
  42. package/dist/components/search/query.d.ts +24 -0
  43. package/dist/components/search/query.js +29 -0
  44. package/dist/components/shell/AppFrame.d.ts +4 -0
  45. package/dist/components/shell/AppFrame.js +4 -1
  46. package/dist/components/shell/Inbox.d.ts +53 -0
  47. package/dist/components/shell/Inbox.js +55 -0
  48. package/dist/components/shell/KioskFrame.d.ts +35 -0
  49. package/dist/components/shell/KioskFrame.js +39 -0
  50. package/dist/components/shell/SearchEntry.js +2 -3
  51. package/dist/components/shell/TopBar.d.ts +4 -2
  52. package/dist/components/shell/TopBar.js +3 -3
  53. package/dist/components/shell/index.d.ts +2 -0
  54. package/dist/components/shell/index.js +4 -0
  55. package/dist/foundations/clock.d.ts +3 -0
  56. package/dist/foundations/clock.js +41 -0
  57. package/dist/foundations/copy.es.js +86 -1
  58. package/dist/foundations/form.d.ts +7 -0
  59. package/dist/foundations/form.js +1 -0
  60. package/dist/foundations/idle.d.ts +1 -0
  61. package/dist/foundations/idle.js +34 -0
  62. package/dist/foundations/index.d.ts +3 -0
  63. package/dist/foundations/index.js +7 -0
  64. package/dist/foundations/pointer.d.ts +25 -0
  65. package/dist/foundations/pointer.js +28 -0
  66. package/dist/foundations/uiCopy.d.ts +123 -2
  67. package/dist/foundations/uiCopy.js +86 -1
  68. package/dist/primitives/choice/RadioGroup.d.ts +8 -1
  69. package/dist/primitives/choice/RadioGroup.js +38 -1
  70. package/dist/primitives/choice/Rating.d.ts +32 -0
  71. package/dist/primitives/choice/Rating.js +75 -0
  72. package/dist/primitives/choice/Slider.d.ts +19 -0
  73. package/dist/primitives/choice/Slider.js +27 -2
  74. package/dist/primitives/choice/index.d.ts +2 -1
  75. package/dist/primitives/choice/index.js +4 -1
  76. package/dist/primitives/choice/options.d.ts +7 -0
  77. package/dist/primitives/field/Field.js +1 -0
  78. package/dist/primitives/field/Keypad.d.ts +43 -0
  79. package/dist/primitives/field/Keypad.js +62 -0
  80. package/dist/primitives/field/Stepper.d.ts +28 -0
  81. package/dist/primitives/field/Stepper.js +52 -0
  82. package/dist/primitives/field/clipboard.js +1 -1
  83. package/dist/primitives/field/index.d.ts +3 -0
  84. package/dist/primitives/field/index.js +6 -0
  85. package/dist/primitives/field/keypadKeys.d.ts +24 -0
  86. package/dist/primitives/field/keypadKeys.js +80 -0
  87. package/dist/primitives/hint/Hint.js +1 -1
  88. package/dist/primitives/hint/Kbd.d.ts +23 -0
  89. package/dist/primitives/hint/Kbd.js +23 -0
  90. package/dist/primitives/hint/index.d.ts +1 -0
  91. package/dist/primitives/hint/index.js +2 -0
  92. package/dist/primitives/menu/ContextMenu.d.ts +29 -0
  93. package/dist/primitives/menu/ContextMenu.js +74 -0
  94. package/dist/primitives/menu/Menu.d.ts +4 -1
  95. package/dist/primitives/menu/Menu.js +2 -2
  96. package/dist/primitives/menu/index.d.ts +1 -0
  97. package/dist/primitives/menu/index.js +2 -0
  98. package/dist/primitives/notice/Banner.d.ts +27 -0
  99. package/dist/primitives/notice/Banner.js +21 -0
  100. package/dist/primitives/notice/Callout.d.ts +4 -4
  101. package/dist/primitives/notice/Callout.js +8 -19
  102. package/dist/primitives/notice/Flag.js +1 -1
  103. package/dist/primitives/notice/Notice.d.ts +38 -10
  104. package/dist/primitives/notice/Notice.js +48 -9
  105. package/dist/primitives/notice/Outcome.d.ts +28 -0
  106. package/dist/primitives/notice/Outcome.js +28 -0
  107. package/dist/primitives/notice/index.d.ts +4 -1
  108. package/dist/primitives/notice/index.js +5 -0
  109. package/dist/primitives/notice/tones.d.ts +8 -0
  110. package/dist/primitives/notice/tones.js +22 -0
  111. package/dist/primitives/table/CellCopy.js +1 -1
  112. package/dist/primitives/table/ReportTable.js +1 -1
  113. package/dist/primitives/table/RowActions.js +1 -1
  114. package/dist/primitives/table/Table.js +9 -5
  115. package/dist/primitives/tag/Tags.d.ts +22 -1
  116. package/dist/primitives/tag/Tags.js +57 -14
  117. package/dist/primitives/tag/index.d.ts +1 -1
  118. package/dist/primitives/value/Elapsed.d.ts +16 -0
  119. package/dist/primitives/value/Elapsed.js +37 -0
  120. package/dist/primitives/value/Price.d.ts +31 -0
  121. package/dist/primitives/value/Price.js +32 -0
  122. package/dist/primitives/value/QrCode.d.ts +32 -0
  123. package/dist/primitives/value/QrCode.js +53 -0
  124. package/dist/primitives/value/elapsedTime.d.ts +26 -0
  125. package/dist/primitives/value/elapsedTime.js +32 -0
  126. package/dist/primitives/value/index.d.ts +5 -0
  127. package/dist/primitives/value/index.js +10 -0
  128. package/dist/primitives/value/priceFormat.d.ts +12 -0
  129. package/dist/primitives/value/priceFormat.js +22 -0
  130. package/dist/tokens.css +126 -1
  131. package/dist/views/list/List.d.ts +11 -0
  132. package/dist/views/list/List.js +14 -3
  133. package/dist/views/list/ListView.d.ts +1 -1
  134. package/dist/views/list/ListView.js +48 -9
  135. package/dist/views/list/types.d.ts +15 -0
  136. package/dist/views/record/Record.js +1 -1
  137. package/package.json +3 -2
@@ -2,12 +2,14 @@
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { filtersOf, groupsOf, } from "./criteria.js";
4
4
  import { JoinWord } from "./JoinWord.js";
5
+ import { chipParts, opLabel, valueLabel, withoutValue, withParts, withTwoValues, } from "./query.js";
6
+ import { WordChoice } from "./WordChoice.js";
5
7
  import { fillCopy, useUiCopy } from "../../foundations/copy.js";
6
8
  import { bySurface, useSurface } from "../../foundations/surface.js";
7
9
  import { chosenTone } from "../../primitives/tag/Tag.js";
8
10
  import { ChevronRight, Layers, X } from "lucide-react";
9
- import { Fragment, useState } from "react";
10
- export function CriteriaChips({ criteria, onOpen, onJoin, onRemove, onRemoveMany, open, collapseAfter = 4, surface, }) {
11
+ import { Fragment, useEffect, useRef, useState } from "react";
12
+ export function CriteriaChips({ criteria, onOpen, onJoin, onRemove, onRemoveMany, open, collapseAfter = 4, fields, onReplace, marked, editing, onEdited, surface, }) {
11
13
  const sup = useSurface(surface);
12
14
  const copy = useUiCopy();
13
15
  const [expanded, setExpanded] = useState(false);
@@ -29,15 +31,19 @@ export function CriteriaChips({ criteria, onOpen, onJoin, onRemove, onRemoveMany
29
31
  node: (_jsx(GroupChain, { groups: groups.map((one) => ({ label: one.label, path: pathOf(one) })), ...(onOpen === undefined ? {} : { onOpen }), ...(onRemoveMany === undefined ? {} : { onRemoveMany }), surface: sup })),
30
32
  },
31
33
  ]),
32
- ...filters.map((one) => ({
34
+ ...filters.map((one, at) => ({
33
35
  key: one.id,
34
36
  label: labelOf(one, copy.search.joins),
35
- node: (_jsx(Node, { node: one, path: pathOf(one), ...(onOpen === undefined ? {} : { onOpen }), ...(onJoin === undefined ? {} : { onJoin }), ...(onRemove === undefined ? {} : { onRemove }), ...(open === undefined ? {} : { open }), surface: sup })),
37
+ node: (_jsx(Node, { node: one, path: pathOf(one), ...(onOpen === undefined ? {} : { onOpen }), ...(onJoin === undefined ? {} : { onJoin }), ...(onRemove === undefined ? {} : { onRemove }), ...(onReplace === undefined ? {} : { onReplace }), ...(open === undefined ? {} : { open }), ...(fields === undefined ? {} : { fields }), editing: editing === at + (groups.length === 0 ? 0 : 1), ...(onEdited === undefined ? {} : { onEdited }), surface: sup })),
36
38
  })),
37
39
  ];
38
40
  /* Folding hides, it does not remove: the open node is where the next one lands, so while
39
41
  there is one everything shows. */
40
- const unfolded = expanded || open !== undefined || !Number.isFinite(collapseAfter);
42
+ const unfolded = expanded ||
43
+ open !== undefined ||
44
+ marked !== undefined ||
45
+ editing !== undefined ||
46
+ !Number.isFinite(collapseAfter);
41
47
  const beyondWide = Math.max(0, facets.length - collapseAfter);
42
48
  const beyondNarrow = Math.max(0, facets.length - 1);
43
49
  const more = (count, hidden, className) => (_jsx("button", { type: "button", onClick: () => setExpanded(true), title: hidden, "aria-label": `${fillCopy(copy.search.moreFacets, { count })}: ${hidden}`, className: `${className} shrink-0 items-center rounded-ui-tag border px-2 py-0.5 text-micro font-medium tabular-nums transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${bySurface(sup, "border-line-strong text-muted hover:bg-ink/5 hover:text-ink", "border-chrome-ink/30 text-chrome-muted hover:bg-chrome-ink/10 hover:text-chrome-ink")}`, children: fillCopy(copy.search.moreFacets, { count }) }));
@@ -45,7 +51,10 @@ export function CriteriaChips({ criteria, onOpen, onJoin, onRemove, onRemoveMany
45
51
  .slice(from)
46
52
  .map((one) => one.label)
47
53
  .join(" · ");
48
- const drawn = (facet, index) => (_jsx("span", { className: `min-w-0 max-w-full ${unfolded
54
+ /* Each piece ARRIVES (`animate-chip-in`): set with Enter, the text clears and the dropdown
55
+ closes, and without a landing the eye looks for where the question went. The key is the
56
+ instance's id, so only the new one moves. */
57
+ const drawn = (facet, index) => (_jsx("span", { "data-marked": marked === index ? "" : undefined, className: `min-w-0 max-w-full rounded-ui-tag motion-safe:animate-chip-in ${marked === index ? "ring-2 ring-primary ring-offset-1 ring-offset-ui-control" : ""} ${unfolded
49
58
  ? "inline-flex"
50
59
  : index >= collapseAfter
51
60
  ? "hidden"
@@ -77,16 +86,17 @@ function labelOf(node, joins) {
77
86
  function GroupChain({ groups, onOpen, onRemoveMany, surface, }) {
78
87
  const copy = useUiCopy();
79
88
  const chain = groups.map((one) => one.label).join(" › ");
80
- return (_jsxs("span", { role: "group", "aria-label": `${copy.search.groupedBy} ${chain}`, title: `${copy.search.groupedBy} ${chain}`, className: `inline-flex min-w-0 max-w-(--container-chain) items-center gap-1 rounded-ui-tag border py-0.5 pl-1.5 text-micro ${bySurface(surface, "border-line-strong bg-surface text-ink", "border-chrome-ink/30 bg-chrome-ink/8 text-chrome-ink")} ${onRemoveMany === undefined ? "pr-2" : "pr-0.5"}`, children: [_jsx(Layers, { className: `size-3 shrink-0 ${bySurface(surface, "text-muted", "text-chrome-muted")}`, strokeWidth: 2, "aria-hidden": true }), _jsx("span", { className: "min-w-0 truncate", children: groups.map((one, at) => (_jsxs(Fragment, { children: [at === 0 ? null : (_jsx(ChevronRight, { className: `mx-0.5 inline size-3 align-middle ${bySurface(surface, "text-muted", "text-chrome-muted")}`, strokeWidth: 2, "aria-hidden": true })), onOpen === undefined ? (_jsx("span", { children: one.label })) : (_jsx("button", { type: "button", onClick: () => onOpen(one.path), title: copy.search.openBuilderHere, className: "inline rounded-control hover:underline hover:underline-offset-4 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary", children: one.label }))] }, one.path.join(".")))) }), onRemoveMany === undefined ? null : (_jsx("button", { type: "button", onClick: () => onRemoveMany(groups.map((one) => one.path)), "aria-label": copy.search.removeGrouping, title: copy.search.removeGrouping, className: `inline-flex size-4 shrink-0 items-center justify-center rounded-pill transition-colors duration-(--duration-instant) ${bySurface(surface, "hover:bg-ink/10", "hover:bg-chrome-ink/20")}`, children: _jsx(X, { className: "size-3", strokeWidth: 2.5 }) }))] }));
89
+ return (_jsxs("span", { role: "group", "aria-label": `${copy.search.groupedBy} ${chain}`, title: `${copy.search.groupedBy} ${chain}`, className: `inline-flex min-w-0 max-w-(--container-chain) items-center gap-1 rounded-ui-tag border py-0.5 pl-1.5 text-micro ${bySurface(surface, "border-line-strong bg-surface text-ink", "border-chrome-ink/30 bg-chrome-ink/8 text-chrome-ink")} ${onRemoveMany === undefined ? "pr-2" : "pr-0.5"}`, children: [_jsx(Layers, { className: `size-3 shrink-0 ${bySurface(surface, "text-muted", "text-chrome-muted")}`, strokeWidth: 2, "aria-hidden": true }), _jsx("span", { className: "min-w-0 truncate", children: groups.map((one, at) => (_jsxs(Fragment, { children: [at === 0 ? null : (_jsx(ChevronRight, { className: `mx-0.5 inline size-3 align-middle ${bySurface(surface, "text-muted", "text-chrome-muted")}`, strokeWidth: 2, "aria-hidden": true })), onOpen === undefined ? (_jsx("span", { children: one.label })) : (_jsx("button", { type: "button", onClick: () => onOpen(one.path), title: copy.search.openBuilderHere, className: "inline rounded-control hover:underline hover:underline-offset-4 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary", children: one.label }))] }, one.path.join(".")))) }), onRemoveMany === undefined ? null : (_jsx("button", { type: "button", onClick: () => onRemoveMany(groups.map((one) => one.path)), "aria-label": copy.search.removeGrouping, title: copy.search.removeGrouping, className: `hit-target inline-flex size-4 shrink-0 items-center justify-center rounded-pill transition-colors touch:size-6 duration-(--duration-instant) ${bySurface(surface, "hover:bg-ink/10", "hover:bg-chrome-ink/20")}`, children: _jsx(X, { className: "size-3", strokeWidth: 2.5 }) }))] }));
81
90
  }
82
- function Node({ node, path, onOpen, onJoin, onRemove, open, surface, }) {
91
+ function Node({ node, path, onOpen, onJoin, onRemove, onReplace, open, fields, editing = false, onEdited, surface, }) {
83
92
  const copy = useUiCopy();
84
93
  if (node.kind !== "join") {
85
94
  /* An instance that carries no expression has nothing to edit: the builder
86
95
  edits what TRAVELS, and this one is answered by whoever declared it. It is seen and removed
87
96
  like any other; what it does not do is promise a door that opens onto nothing. */
88
97
  const editable = node.kind === "group" || node.selection !== undefined;
89
- return (_jsx(Chip, { label: node.label, path: path, ...(onOpen === undefined || !editable ? {} : { onOpen }), ...(onRemove === undefined ? {} : { onRemove }), surface: surface }));
98
+ const parts = fields === undefined ? undefined : chipParts(node, fields);
99
+ return (_jsx(Chip, { node: node, path: path, ...(parts === undefined ? {} : { parts }), ...(onOpen === undefined || !editable ? {} : { onOpen }), ...(onRemove === undefined ? {} : { onRemove }), ...(onReplace === undefined ? {} : { onReplace }), editing: editing, ...(onEdited === undefined ? {} : { onEdited }), surface: surface }));
90
100
  }
91
101
  /* The open node is marked: it is where the next thing will land. A ring and not a
92
102
  background, because inside there are chips that already have their own. */
@@ -94,17 +104,27 @@ function Node({ node, path, onOpen, onJoin, onRemove, open, surface, }) {
94
104
  return (_jsxs("span", { className: `inline-flex min-w-0 flex-wrap items-center gap-1 rounded-control border px-1.5 py-0.5 ${bySurface(surface, "border-line bg-ink/4", "border-chrome-ink/25 bg-chrome-ink/8")} ${isOpen ? "ring-1 ring-primary/60" : ""}`, children: [_jsx(JoinWord, { join: node.join, ...(onJoin === undefined ? {} : { onChange: (next) => onJoin(path, next) }), surface: surface }), node.of.length === 0 ? (
95
105
  /* A newly opened node has nothing inside, and an empty bracket reads
96
106
  as an error. It says it is waiting. */
97
- _jsx("span", { className: `shrink-0 text-micro italic ${bySurface(surface, "text-muted", "text-chrome-muted")}`, children: copy.search.landsHere })) : null, node.of.map((child, at) => (_jsx(Node, { node: child, path: [...path, at], ...(onOpen === undefined ? {} : { onOpen }), ...(onJoin === undefined ? {} : { onJoin }), ...(onRemove === undefined ? {} : { onRemove }), ...(open === undefined ? {} : { open }), surface: surface }, child.id)))] }));
107
+ _jsx("span", { className: `shrink-0 text-micro italic ${bySurface(surface, "text-muted", "text-chrome-muted")}`, children: copy.search.landsHere })) : null, node.of.map((child, at) => (_jsx(Node, { node: child, path: [...path, at], ...(onOpen === undefined ? {} : { onOpen }), ...(onJoin === undefined ? {} : { onJoin }), ...(onRemove === undefined ? {} : { onRemove }), ...(onReplace === undefined ? {} : { onReplace }), ...(open === undefined ? {} : { open }), ...(fields === undefined ? {} : { fields }), surface: surface }, child.id)))] }));
98
108
  }
99
- function Chip({ label, path, onOpen, onRemove, surface, }) {
109
+ /** A part of a chip that is touched: a quiet hover inside the chip's own tone, and the ring. */
110
+ const PART = "min-w-0 rounded-control px-0.5 text-left outline-0 transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary data-focus-visible:outline-2 data-focus-visible:outline-offset-1 data-focus-visible:outline-primary";
111
+ function Chip({ node, path, parts, onOpen, onRemove, onReplace, editing, onEdited, surface, }) {
100
112
  const copy = useUiCopy();
101
- const shell = `inline-flex min-w-0 max-w-(--container-facet) items-center gap-1 rounded-ui-tag py-0.5 text-micro ${chosenTone(surface)} ${onRemove === undefined ? "px-2" : "pr-0.5 pl-2"}`;
113
+ const label = node.label;
114
+ /* Under a finger the chip grows to a size a thumb can aim at (32px, the label in the
115
+ reading size); with a mouse it stays a line of the bar. */
116
+ const shell = `inline-flex min-w-0 max-w-(--container-facet) items-center gap-1 rounded-ui-tag py-0.5 text-micro touch:min-h-8 touch:text-meta ${chosenTone(surface)} ${onRemove === undefined ? "px-2" : "pr-0.5 pl-2"}`;
102
117
  const remove = onRemove === undefined ? null : (_jsx("button", { type: "button", onClick: (event) => {
103
118
  /* Without this, removing it also opens it: the click arrives here and then
104
119
  bubbles up. */
105
120
  event.stopPropagation();
106
121
  onRemove(path);
107
- }, "aria-label": copy.search.removeFilter.replace("{label}", label), className: `inline-flex size-4 shrink-0 items-center justify-center rounded-pill transition-colors duration-(--duration-instant) ${bySurface(surface, "hover:bg-primary/20", "hover:bg-chrome-link/25")}`, children: _jsx(X, { className: "size-3", strokeWidth: 2.5 }) }));
122
+ }, "aria-label": copy.search.removeFilter.replace("{label}", label), className: `hit-target inline-flex size-4 shrink-0 items-center justify-center rounded-pill transition-colors touch:size-6 duration-(--duration-instant) ${bySurface(surface, "hover:bg-primary/20", "hover:bg-chrome-link/25")}`, children: _jsx(X, { className: "size-3", strokeWidth: 2.5 }) }));
123
+ if (parts !== undefined) {
124
+ return (
125
+ /* The whole sentence in the title: a long value is cut at the chip's width. */
126
+ _jsxs("span", { "data-ui": "search.chip", "data-parts": "", title: label, className: shell, children: [_jsx(PartsOf, { node: node, path: path, parts: parts, ...(onOpen === undefined ? {} : { onOpen }), ...(onReplace === undefined ? {} : { onReplace }), editing: editing, ...(onEdited === undefined ? {} : { onEdited }), surface: surface }), remove] }));
127
+ }
108
128
  if (onOpen === undefined) {
109
129
  return (_jsxs("span", { "data-ui": "search.chip", className: shell, children: [_jsx("span", { className: "min-w-0 truncate", children: label }), remove] }));
110
130
  }
@@ -114,3 +134,93 @@ function Chip({ label, path, onOpen, onRemove, surface, }) {
114
134
  (`nested-interactive`). Siblings, each with its own name, are both reachable. */
115
135
  return (_jsxs("span", { "data-ui": "search.chip", className: shell, children: [_jsx("button", { type: "button", onClick: () => onOpen(path), title: copy.search.openBuilderHere, className: "min-w-0 truncate rounded-control text-left hover:underline hover:underline-offset-4 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary", children: label }), remove] }));
116
136
  }
137
+ /**
138
+ * The three parts of a chip the bar wrote: «cliente · contiene · andina».
139
+ *
140
+ * The field is quiet and opens the builder on the chip (the field is the one part that changes
141
+ * the whole question, so it changes where the whole question is edited). The comparison opens
142
+ * into the field's comparisons. The value is strong, and is edited right there: an enum's words
143
+ * open as a list, anything else becomes the text it is, with Enter to set and Escape to leave it
144
+ * as it was.
145
+ */
146
+ function PartsOf({ node, path, parts, onOpen, onReplace, editing, onEdited, surface, }) {
147
+ const copy = useUiCopy();
148
+ const [writing, setWriting] = useState(false);
149
+ /* Enter and Escape settle the edit; the blur that follows the input leaving must not set it
150
+ a second time with the value it had before. */
151
+ const settled = useRef(false);
152
+ const field = parts.field;
153
+ const quiet = bySurface(surface, "text-muted", "text-chrome-muted");
154
+ const hover = bySurface(surface, "hover:bg-primary/12", "hover:bg-chrome-link/25");
155
+ /* Enter on a marked chip asks to edit it: the value is what gets edited. */
156
+ useEffect(() => {
157
+ if (editing)
158
+ setWriting(true);
159
+ }, [editing]);
160
+ useEffect(() => {
161
+ if (writing)
162
+ settled.current = false;
163
+ }, [writing]);
164
+ const fieldPart = onOpen === undefined ? (_jsx("span", { className: `shrink-0 ${quiet}`, children: field.label })) : (_jsx("button", { type: "button", onClick: () => onOpen(path), title: copy.search.openBuilderHere, className: `${PART} shrink-0 ${quiet} ${hover}`, children: field.label }));
165
+ if (parts.kind === "values") {
166
+ const names = parts.values.slice(0, 3).map((one) => one.name);
167
+ const said = parts.values.length > 3
168
+ ? `${names.join(", ")} ${fillCopy(copy.search.andMore, { count: parts.values.length - 3 })}`
169
+ : names.join(` ${copy.search.or} `);
170
+ return (_jsxs(_Fragment, { children: [fieldPart, _jsx("span", { className: "min-w-0 truncate font-medium", children: said })] }));
171
+ }
172
+ const { op, value } = parts;
173
+ /* The focus is given back BEFORE the input goes: an input removed while it holds the focus
174
+ blurs in the middle of React's commit, and the focus falls to the page for a frame. */
175
+ const finish = (giveBack) => {
176
+ settled.current = true;
177
+ onEdited?.(giveBack);
178
+ setWriting(false);
179
+ };
180
+ const put = (nextOp, nextValue) => {
181
+ onReplace?.(path, withParts(node, field, nextOp, nextValue));
182
+ };
183
+ const ops = field.ops.filter((one) => !withTwoValues(one));
184
+ const opPart = onReplace === undefined || ops.length < 2 ? (_jsx("span", { className: `shrink-0 ${quiet}`, children: opLabel(op) })) : (_jsx(WordChoice, { value: op, options: ops.map((one) => ({ id: one, label: opLabel(one), note: one })), onChange: (next) => {
185
+ if (next === op)
186
+ return;
187
+ put(next, withoutValue(next) ? "" : value);
188
+ /* From «está vacío» to a comparison that needs a value: there is none yet, so the
189
+ value is asked right there instead of leaving a chip that asks for «nothing». */
190
+ if (!withoutValue(next) && value === "")
191
+ setWriting(true);
192
+ }, label: fillCopy(copy.search.changeOp, { field: field.label }), word: opLabel(op), className: `${PART} shrink-0 ${quiet} ${hover}` }));
193
+ const choices = field.choices;
194
+ const valuePart = withoutValue(op) ? null : onReplace !== undefined &&
195
+ choices !== undefined &&
196
+ choices.length > 0 ? (_jsx(WordChoice, { value: value, options: choices.map((one) => ({ id: one, label: valueLabel(field, one) })), onChange: (next) => {
197
+ if (next !== value)
198
+ put(op, next);
199
+ onEdited?.(false);
200
+ }, label: fillCopy(copy.search.editValue, { label: field.label }), word: valueLabel(field, value), className: `${PART} truncate font-medium ${hover}` })) : onReplace !== undefined && writing ? (_jsx("input", {
201
+ /* The person asked to edit this value: the focus goes where they will type. */
202
+ autoFocus: true, defaultValue: value, "aria-label": fillCopy(copy.search.editValue, { label: field.label }), onFocus: (event) => event.currentTarget.select(), onKeyDown: (event) => {
203
+ /* The bar's keys are not this field's: Escape here leaves the value as it was, and
204
+ does not undo a step of the bar nor close a dialog around it. */
205
+ event.stopPropagation();
206
+ if (event.key === "Enter") {
207
+ event.preventDefault();
208
+ const next = event.currentTarget.value.trim();
209
+ if (next !== "" && next !== value)
210
+ put(op, next);
211
+ finish(true);
212
+ }
213
+ else if (event.key === "Escape") {
214
+ event.preventDefault();
215
+ finish(true);
216
+ }
217
+ }, onBlur: (event) => {
218
+ if (settled.current)
219
+ return;
220
+ const next = event.currentTarget.value.trim();
221
+ if (next !== "" && next !== value)
222
+ put(op, next);
223
+ finish(false);
224
+ }, style: { fieldSizing: "content" }, className: "min-w-8 rounded-control bg-ui-control px-1 font-medium text-ink outline-2 outline-primary" })) : onReplace === undefined ? (_jsx("span", { className: "min-w-0 truncate font-medium", children: valueLabel(field, value) })) : (_jsx("button", { type: "button", onClick: () => setWriting(true), title: fillCopy(copy.search.editValue, { label: field.label }), className: `${PART} truncate font-medium ${hover}`, children: valueLabel(field, value) }));
225
+ return (_jsxs(_Fragment, { children: [fieldPart, opPart, valuePart] }));
226
+ }
@@ -1,9 +1,8 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { WordChoice } from "./WordChoice.js";
3
4
  import { useUiCopy } from "../../foundations/copy.js";
4
5
  import { bySurface, useSurface } from "../../foundations/surface.js";
5
- import { Tags } from "../../primitives/tag/Tags.js";
6
- import { useState } from "react";
7
6
  /* ==================================================================== *
8
7
  * HOW A NODE IS JOINED, in a word you touch.
9
8
  *
@@ -24,24 +23,19 @@ import { useState } from "react";
24
23
  *
25
24
  * It lives here and not inside the bar because the builder asks the same. A
26
25
  * `<select>` there and a list here are two controls for one decision, and whoever
27
- * learned one does not recognise the other.
26
+ * learned one does not recognise the other. The list is `WordChoice`'s: it floats, the arrows
27
+ * move through it, Escape closes it.
28
28
  * ==================================================================== */
29
29
  const OPTIONS = ["all", "any", "not"];
30
30
  export function JoinWord({ join, onChange, surface, }) {
31
31
  const sup = useSurface(surface);
32
32
  const copy = useUiCopy();
33
- const [open, setOpen] = useState(false);
34
33
  const word = copy.search.joins[join === "not" ? "none" : join];
35
34
  if (onChange === undefined) {
36
35
  return _jsx("span", { className: "shrink-0 text-micro text-muted", children: word });
37
36
  }
38
- return (_jsxs("span", { className: "relative inline-flex shrink-0", children: [_jsx("button", { type: "button", onClick: () => setOpen((current) => !current), "aria-expanded": open, title: copy.search.switchJoin, className: `shrink-0 rounded-control px-1 text-micro font-medium underline decoration-dotted underline-offset-4 decoration-current/40 transition-colors hover:decoration-current focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${bySurface(sup, "text-muted hover:text-ink", "text-chrome-muted hover:text-chrome-ink")}`, children: word }), open ? (_jsx("span", { "data-ui": "popover", className: "absolute top-full left-0 z-40 mt-1 rounded-ui-popover border border-ui-popover-border bg-ui-popover p-1 shadow-ui-popover", children: _jsx(Tags, { stack: true, surface: "canvas", label: copy.search.switchJoin, items: OPTIONS.map((one) => ({
39
- id: one,
40
- label: copy.search.joins[one === "not" ? "none" : one],
41
- selected: one === join,
42
- onSelect: () => {
43
- onChange(one);
44
- setOpen(false);
45
- },
46
- })) }) })) : null] }));
37
+ return (_jsx(WordChoice, { value: join, options: OPTIONS.map((one) => ({
38
+ id: one,
39
+ label: copy.search.joins[one === "not" ? "none" : one],
40
+ })), onChange: onChange, label: copy.search.switchJoin, word: word, className: `shrink-0 rounded-control px-1 text-micro font-medium underline decoration-dotted underline-offset-4 decoration-current/40 transition-colors outline-0 hover:decoration-current data-focus-visible:outline-2 data-focus-visible:outline-offset-1 data-focus-visible:outline-primary ${bySurface(sup, "text-muted hover:text-ink", "text-chrome-muted hover:text-chrome-ink")}` }));
47
41
  }
@@ -108,7 +108,16 @@ export type SearchBarProps = {
108
108
  /** How many facets the bar shows before folding the rest into «+N»; the grouping chain
109
109
  * counts as one. On a narrow bar only the first shows. `Infinity` never folds. */
110
110
  collapseAfter?: number;
111
+ /**
112
+ * Under which name this bar remembers what was searched with it, in this browser: the last
113
+ * five questions put, offered when the empty bar takes the focus («Recientes»). Give each
114
+ * list its own — «facturas», «contactos». Without it, nothing is remembered.
115
+ */
116
+ recentKey?: string;
117
+ /** «/» focuses the bar from anywhere on the page that is not a field (on by default). With
118
+ * several bars on screen the last one mounted answers. `false` leaves «/» to the page. */
119
+ focusOnSlash?: boolean;
111
120
  /** By default it inherits it from the surface that wraps it. */
112
121
  surface?: Surface;
113
122
  };
114
- export declare function SearchBar({ facets, model, criteria, onCriteriaChange, placeholder, filters, grouping, onOpenGroup, favorites, onFilterSelect, onFavoriteSelect, onOpenBuilder, literal, searchRecords: ownSearchRecords, browseRecords: ownBrowseRecords, renderRecord, trailing, collapseAfter, surface, }: SearchBarProps): import("react").JSX.Element;
123
+ export declare function SearchBar({ facets, model, criteria, onCriteriaChange, placeholder, filters, grouping, onOpenGroup, favorites, onFilterSelect, onFavoriteSelect, onOpenBuilder, literal, searchRecords: ownSearchRecords, browseRecords: ownBrowseRecords, renderRecord, trailing, collapseAfter, recentKey, focusOnSlash, surface, }: SearchBarProps): import("react").JSX.Element;