@enigmax/primitives 0.22.0 → 0.24.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 (79) hide show
  1. package/dist/{chunk-QQFNAKMY.js → chunk-45UHLZYT.js} +1 -1
  2. package/dist/chunk-4VUHQFAT.js +130 -0
  3. package/dist/{chunk-D5A2ZMAG.js → chunk-4ZPMP47J.js} +6 -1
  4. package/dist/chunk-DZMHY3SU.js +777 -0
  5. package/dist/{chunk-FWVWX67R.js → chunk-FGBIZDV2.js} +3 -3
  6. package/dist/chunk-N6PDHMAX.js +213 -0
  7. package/dist/chunk-NONGREXC.js +248 -0
  8. package/dist/{chunk-R4ZAEE7V.js → chunk-QJJ34E4G.js} +34 -10
  9. package/dist/chunk-S2FPN5ID.js +115 -0
  10. package/dist/chunk-S7EE57YB.js +9 -0
  11. package/dist/chunk-VKL3DEIQ.js +804 -0
  12. package/dist/chunk-WSQC3PCC.js +466 -0
  13. package/dist/chunk-Z3VDE7OA.js +532 -0
  14. package/dist/clipboard-menu-B_ouitfS.d.ts +264 -0
  15. package/dist/color-D_rZ83Oc.d.ts +152 -0
  16. package/dist/color-OPV3BJV6.js +452 -0
  17. package/dist/{index-BHpOZncw.d.ts → index-ZPvlf9vs.d.ts} +53 -5
  18. package/dist/index.d.ts +6 -2
  19. package/dist/index.js +9 -4
  20. package/dist/keys-D2zJs1uB.d.ts +100 -0
  21. package/dist/next/index.d.ts +10 -3
  22. package/dist/next/index.js +22 -13
  23. package/dist/react/context-menu.d.ts +219 -0
  24. package/dist/react/context-menu.js +6 -0
  25. package/dist/react/index.d.ts +12 -5
  26. package/dist/react/index.js +21 -12
  27. package/dist/react/input.d.ts +3 -3
  28. package/dist/react/input.js +2 -1
  29. package/dist/react/palette.d.ts +1 -1
  30. package/dist/react/palette.js +3 -3
  31. package/dist/react/search.d.ts +1 -1
  32. package/dist/react/search.js +2 -2
  33. package/dist/react/select.d.ts +217 -0
  34. package/dist/react/select.js +7 -0
  35. package/dist/react/selection.d.ts +104 -0
  36. package/dist/react/selection.js +4 -0
  37. package/dist/react-router/index.d.ts +10 -3
  38. package/dist/react-router/index.js +22 -13
  39. package/dist/search/index.d.ts +2 -2
  40. package/dist/search/index.js +1 -1
  41. package/dist/{search-BD9-5O5U.d.ts → search-DYgqRp37.d.ts} +13 -1
  42. package/dist/{search-UQEXAPQB.js → search-PBZORZ7P.js} +1 -1
  43. package/dist/select-ClSy-J1f.d.ts +100 -0
  44. package/dist/selection-B_pmzHpy.d.ts +150 -0
  45. package/package.json +23 -2
  46. package/recipes/color/styles.css +143 -0
  47. package/recipes/context-menu/styles.css +185 -0
  48. package/recipes/input/styles.css +9 -0
  49. package/recipes/palette/styles.css +3 -0
  50. package/recipes/search/tailwind.tsx +3 -2
  51. package/recipes/select/styles.css +230 -0
  52. package/recipes/toast/styles.css +1 -1
  53. package/registry.json +432 -5
  54. package/src/core/clipboard-menu.ts +270 -0
  55. package/src/core/color.ts +248 -0
  56. package/src/core/context-menu.ts +694 -0
  57. package/src/core/keys.ts +264 -0
  58. package/src/core/search.ts +19 -0
  59. package/src/core/select.ts +404 -0
  60. package/src/core/selection.ts +648 -0
  61. package/src/index.ts +92 -1
  62. package/src/react/context-menu/context.ts +64 -0
  63. package/src/react/context-menu/index.tsx +108 -0
  64. package/src/react/context-menu/root.tsx +970 -0
  65. package/src/react/context-menu/styles.ts +194 -0
  66. package/src/react/index.ts +100 -1
  67. package/src/react/input/color-styles.ts +156 -0
  68. package/src/react/input/color.tsx +466 -0
  69. package/src/react/input/index.tsx +54 -6
  70. package/src/react/input/types.ts +59 -3
  71. package/src/react/palette/root.tsx +2 -2
  72. package/src/react/select/context.ts +56 -0
  73. package/src/react/select/index.tsx +96 -0
  74. package/src/react/select/root.tsx +839 -0
  75. package/src/react/select/styles.ts +238 -0
  76. package/src/react/selection/index.tsx +115 -0
  77. package/src/react/selection/use-selection.ts +260 -0
  78. package/dist/password-C8lG4Zm9.d.ts +0 -71
  79. /package/dist/{chunk-U3V4EHOB.js → chunk-MSOCCQGH.js} +0 -0
@@ -0,0 +1,150 @@
1
+ import { b as ShortcutSpec, a as ShortcutEvent } from './keys-D2zJs1uB.js';
2
+
3
+ /**
4
+ * The parts of a selectable list that are not rendering: what is selected, where the cursor
5
+ * is, which row the next Shift+click measures from, and which command a key press stands for.
6
+ *
7
+ * This is the file-manager selection model, on purpose and in full: a plain click replaces
8
+ * the selection, Ctrl toggles one row without losing the rest, Shift takes everything between
9
+ * the anchor and here, Ctrl+Shift adds that range to what was already there, Ctrl+A takes the
10
+ * lot and Escape drops it. Every one of those is a rule people already know from Explorer,
11
+ * Finder and every list built on them, and every one of them is a bug when a list re-invents
12
+ * it - a Shift+click that measures from the last CLICK instead of the anchor, a Ctrl+click
13
+ * that clears the selection, an Escape that does nothing.
14
+ *
15
+ * The commands are DATA. Each one has a default binding, any of them can be rebound, removed
16
+ * one at a time or turned off altogether, and a binding that is not a built-in command is
17
+ * still matched and reported - so a list can add "star" on Mod+D without this file knowing
18
+ * what starring is.
19
+ */
20
+
21
+ /**
22
+ * What a key press means.
23
+ *
24
+ * The first group the list PERFORMS - it owns the selection, so it moves it. The second it
25
+ * only REPORTS, because deleting, renaming and opening are the caller's. Both are reported,
26
+ * and both can be stopped by the handler, so a list that wants to confirm a delete or animate
27
+ * its own select-all can.
28
+ */
29
+ type SelectionCommand = "selectAll" | "clear" | "invert" | "moveUp" | "moveDown" | "moveLeft" | "moveRight" | "moveHome" | "moveEnd" | "movePageUp" | "movePageDown" | "extendUp" | "extendDown" | "extendLeft" | "extendRight" | "extendHome" | "extendEnd" | "extendPageUp" | "extendPageDown" | "cursorUp" | "cursorDown" | "toggleCursor" | "open" | "rename" | "delete" | "deletePermanent" | "copy" | "cut" | "paste";
30
+ /** A command name: one of the built-ins, or anything else the caller binds. */
31
+ type SelectionCommandName = SelectionCommand | (string & {});
32
+ /**
33
+ * What each command is bound to out of the box.
34
+ *
35
+ * `Mod` is Command on an Apple keyboard and Control everywhere else, which is what these
36
+ * shortcuts mean on both. `invert` ships unbound deliberately: Explorer has the action and no
37
+ * key for it, and inventing one would take a combination the page may already use.
38
+ */
39
+ declare const DEFAULT_SELECTION_SHORTCUTS: Readonly<Record<SelectionCommand, ShortcutSpec>>;
40
+ /**
41
+ * The bindings, as the caller writes them.
42
+ *
43
+ * A missing entry keeps the default, `false` removes that one command, and a string or a list
44
+ * replaces it. `shortcuts: false` on the options removes every one of them at once - for a
45
+ * list inside an editor, or one whose keyboard belongs to something else.
46
+ */
47
+ type SelectionShortcuts = Partial<Record<SelectionCommandName, ShortcutSpec>>;
48
+ /** The modifiers a click carried. A real MouseEvent or PointerEvent satisfies it. */
49
+ interface SelectionClickModifiers {
50
+ ctrlKey?: boolean;
51
+ metaKey?: boolean;
52
+ shiftKey?: boolean;
53
+ }
54
+ interface SelectionCommandEvent<Item> {
55
+ command: SelectionCommandName;
56
+ /**
57
+ * What the command applies to: everything selected, or the row under the cursor when
58
+ * nothing is. That fallback is the file-manager rule - pressing Delete with one row
59
+ * focused and none selected deletes that row.
60
+ */
61
+ items: Item[];
62
+ ids: string[];
63
+ /** The row the cursor is on, selected or not. */
64
+ cursor: Item | null;
65
+ cursorIndex: number;
66
+ /** The press that matched, for a handler that needs the modifiers back. */
67
+ event: ShortcutEvent;
68
+ /** Stop what the list would have done - the moves, select-all, clear, invert. */
69
+ preventDefault(): void;
70
+ defaultPrevented: boolean;
71
+ }
72
+ interface SelectionOptions<Item> {
73
+ items?: readonly Item[];
74
+ /** How a row is identified across reorders and reloads. Default: its index, as a string. */
75
+ getId?: (item: Item, index: number) => string;
76
+ /** A row that cannot be selected or landed on. Still rendered, still counted. */
77
+ disabled?: (item: Item, index: number) => boolean;
78
+ /** One row at a time: Ctrl and Shift stop meaning anything. Default: many. */
79
+ multiple?: boolean;
80
+ /** Columns in a grid, so Left and Right move by one and Up and Down by a row. Default 1. */
81
+ columns?: number;
82
+ /** How far PageUp and PageDown jump. Default 10. */
83
+ page?: number;
84
+ /** Rebind, remove or extend the commands. `false` removes every binding. */
85
+ shortcuts?: SelectionShortcuts | false;
86
+ /** A command matched a press. Fired for built-ins too, before the list acts on them. */
87
+ onCommand?: (event: SelectionCommandEvent<Item>) => void;
88
+ /** Every state change. */
89
+ onChange?: (state: SelectionState<Item>) => void;
90
+ /** Only the selection, when it actually changed. */
91
+ onSelectionChange?: (ids: string[], items: Item[]) => void;
92
+ }
93
+ interface SelectionState<Item> {
94
+ /** Selected ids, in the order the rows appear - not the order they were clicked. */
95
+ selected: string[];
96
+ /** The same ids, for a renderer that asks per row. */
97
+ selectedSet: ReadonlySet<string>;
98
+ /** The selected rows themselves. */
99
+ items: Item[];
100
+ /** Where the keyboard is. -1 when the list has not been touched. */
101
+ cursor: number;
102
+ /** Where the next Shift+click or Shift+arrow measures from. */
103
+ anchor: number;
104
+ count: number;
105
+ /** Every selectable row is selected. What a header checkbox reads. */
106
+ allSelected: boolean;
107
+ /** Some but not all - the third state of that same checkbox. */
108
+ partiallySelected: boolean;
109
+ /** A rubber band is being dragged. */
110
+ marquee: boolean;
111
+ }
112
+ interface SelectionInstance<Item> {
113
+ readonly state: SelectionState<Item>;
114
+ /** A click on a row, with its modifiers. The whole Explorer rule, in one call. */
115
+ click(index: number, modifiers?: SelectionClickModifiers): void;
116
+ /** A key press. Returns whether a command matched, so the caller knows to prevent it. */
117
+ keyDown(event: ShortcutEvent): boolean;
118
+ select(ids: readonly string[]): void;
119
+ selectIndex(index: number, additive?: boolean): void;
120
+ toggle(index: number): void;
121
+ /** Everything from the anchor to here. `additive` keeps what was already selected. */
122
+ selectRange(index: number, additive?: boolean): void;
123
+ selectAll(): void;
124
+ clear(): void;
125
+ invert(): void;
126
+ /** Move the cursor. `extend` takes everything from the anchor, `carry` leaves the selection alone. */
127
+ moveCursor(delta: number, extend?: boolean, carry?: boolean): void;
128
+ setCursor(index: number): void;
129
+ /**
130
+ * What an action on this row applies to: the selection when the row is part of it, and the
131
+ * row alone when it is not. The rule every file manager's context menu follows - and the
132
+ * one that makes right-clicking outside a selection act on what was clicked.
133
+ */
134
+ targets(index: number): Item[];
135
+ /** Start a rubber band. `additive` keeps the current selection as its base. */
136
+ beginMarquee(additive?: boolean): void;
137
+ /** The rows the band currently covers. */
138
+ marqueeTo(indices: readonly number[]): void;
139
+ endMarquee(): void;
140
+ /** The resolved bindings, so a menu can print the same shortcut the list listens for. */
141
+ bindings(): Record<string, ShortcutSpec>;
142
+ /** What one command is bound to, or false when it has no binding. */
143
+ binding(command: SelectionCommandName): ShortcutSpec;
144
+ update(options: Partial<SelectionOptions<Item>>): void;
145
+ subscribe(listener: (state: SelectionState<Item>) => void): () => void;
146
+ destroy(): void;
147
+ }
148
+ declare function createSelection<Item>(options?: SelectionOptions<Item>): SelectionInstance<Item>;
149
+
150
+ export { DEFAULT_SELECTION_SHORTCUTS as D, type SelectionClickModifiers as S, type SelectionCommand as a, type SelectionCommandEvent as b, type SelectionCommandName as c, type SelectionInstance as d, type SelectionOptions as e, type SelectionShortcuts as f, type SelectionState as g, createSelection as h };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enigmax/primitives",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Headless components: the behaviour, the timing and the accessibility, with no styles of their own. Framework-agnostic core plus thin adapters.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -25,6 +25,18 @@
25
25
  "types": "./dist/react/palette.d.ts",
26
26
  "import": "./dist/react/palette.js"
27
27
  },
28
+ "./react/select": {
29
+ "types": "./dist/react/select.d.ts",
30
+ "import": "./dist/react/select.js"
31
+ },
32
+ "./react/context-menu": {
33
+ "types": "./dist/react/context-menu.d.ts",
34
+ "import": "./dist/react/context-menu.js"
35
+ },
36
+ "./react/selection": {
37
+ "types": "./dist/react/selection.d.ts",
38
+ "import": "./dist/react/selection.js"
39
+ },
28
40
  "./react/button": {
29
41
  "types": "./dist/react/button.d.ts",
30
42
  "import": "./dist/react/button.js"
@@ -77,9 +89,12 @@
77
89
  "./relative-time.css": "./recipes/relative-time/styles.css",
78
90
  "./toast.css": "./recipes/toast/styles.css",
79
91
  "./input.css": "./recipes/input/styles.css",
92
+ "./color.css": "./recipes/color/styles.css",
80
93
  "./marquee.css": "./recipes/marquee/styles.css",
81
94
  "./logo-marquee.css": "./recipes/logo-marquee/styles.css",
82
- "./palette.css": "./recipes/palette/styles.css"
95
+ "./palette.css": "./recipes/palette/styles.css",
96
+ "./select.css": "./recipes/select/styles.css",
97
+ "./context-menu.css": "./recipes/context-menu/styles.css"
83
98
  },
84
99
  "scripts": {
85
100
  "build": "tsup",
@@ -143,12 +158,15 @@
143
158
  },
144
159
  "keywords": [
145
160
  "carousel",
161
+ "color-picker",
162
+ "context-menu",
146
163
  "enigma",
147
164
  "flags",
148
165
  "fuse",
149
166
  "headless",
150
167
  "input",
151
168
  "marquee",
169
+ "menu",
152
170
  "network",
153
171
  "notifications",
154
172
  "password",
@@ -156,6 +174,9 @@
156
174
  "react",
157
175
  "relative-time",
158
176
  "search",
177
+ "select",
178
+ "selection",
179
+ "shortcuts",
159
180
  "toast",
160
181
  "unstyled",
161
182
  "vanilla"
@@ -0,0 +1,143 @@
1
+ /*
2
+ * The color stylesheet.
3
+ *
4
+ * GENERATED from src/react/input/color-styles.ts by scripts/sync-recipes.mjs - edit that file, not
5
+ * this one. It exists as a stylesheet as well as a string because the component injects it,
6
+ * and this is the same sheet for anyone who would rather import it, copy it with
7
+ * `enigma add input --copy`, or fork it outright.
8
+ */
9
+ :root {
10
+ --enigma-color-panel-bg: #1c1c1c;
11
+ --enigma-color-panel-border: #333333;
12
+ --enigma-color-panel-radius: 0.625rem;
13
+ --enigma-color-panel-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
14
+ --enigma-color-panel-width: 13.5rem;
15
+ --enigma-color-text: #f5f5f5;
16
+ --enigma-color-muted: #a3a3a3;
17
+ --enigma-color-border: #404040;
18
+ --enigma-color-focus: #a3a3a3;
19
+ --enigma-color-area-height: 8rem;
20
+ --enigma-color-rail-height: 0.625rem;
21
+ --enigma-color-thumb: #ffffff;
22
+ --enigma-color-thumb-ring: rgba(0, 0, 0, 0.55);
23
+ /* The light square of the transparency chequerboard. The dark one is the surface it sits
24
+ on, which is why only one colour is a property. */
25
+ --enigma-color-checker: rgba(255, 255, 255, 0.22);
26
+ --enigma-color-checker-size: 0.5rem;
27
+ }
28
+
29
+ @media (prefers-color-scheme: light) {
30
+ :root {
31
+ --enigma-color-panel-bg: #ffffff;
32
+ --enigma-color-panel-border: #e5e5e5;
33
+ --enigma-color-panel-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
34
+ --enigma-color-text: #171717;
35
+ --enigma-color-muted: #737373;
36
+ --enigma-color-border: #d4d4d4;
37
+ --enigma-color-focus: #737373;
38
+ --enigma-color-thumb-ring: rgba(0, 0, 0, 0.35);
39
+ --enigma-color-checker: rgba(0, 0, 0, 0.14);
40
+ }
41
+ }
42
+
43
+ /* The anchor the panel hangs from. Inline so it sits in the field's own row, and the
44
+ positioning context so the panel needs no portal and no scroll listener: it moves with
45
+ the field because it is INSIDE it. */
46
+ [data-enigma-color] { position: relative; display: inline-flex; flex: none; }
47
+
48
+ [data-enigma-color-swatch] {
49
+ display: block; width: 1.25rem; height: 1.25rem; padding: 0;
50
+ background: none; border: 1px solid var(--enigma-color-border); border-radius: 0.3125rem;
51
+ cursor: pointer; overflow: hidden;
52
+ }
53
+ [data-enigma-color-swatch]:focus-visible { outline: 2px solid var(--enigma-color-focus); outline-offset: 2px; }
54
+ [data-enigma-color-swatch]:disabled { opacity: 0.5; cursor: not-allowed; }
55
+
56
+ /* The chequerboard, so a colour with alpha reads as transparent rather than as a lighter
57
+ colour - which is the whole difference between #ff000080 and #ff8080. */
58
+ [data-enigma-color-checkers] {
59
+ background-image:
60
+ conic-gradient(var(--enigma-color-checker) 0 25%, transparent 0 50%, var(--enigma-color-checker) 0 75%, transparent 0);
61
+ background-size: var(--enigma-color-checker-size) var(--enigma-color-checker-size);
62
+ }
63
+
64
+ [data-enigma-color-fill] { display: block; width: 100%; height: 100%; }
65
+ /* An unparseable field has no colour to show, so the swatch shows the chequerboard alone
66
+ rather than the last good colour: a stale swatch says the value is fine when it is not. */
67
+ [data-enigma-color-swatch][data-invalid] [data-enigma-color-fill] { background: none; }
68
+
69
+ [data-enigma-color-panel] {
70
+ position: absolute; z-index: 60; top: calc(100% + 0.375rem); left: 0;
71
+ display: grid; gap: 0.625rem;
72
+ box-sizing: border-box; width: var(--enigma-color-panel-width); padding: 0.625rem;
73
+ color: var(--enigma-color-text); background: var(--enigma-color-panel-bg);
74
+ border: 1px solid var(--enigma-color-panel-border);
75
+ border-radius: var(--enigma-color-panel-radius);
76
+ box-shadow: var(--enigma-color-panel-shadow);
77
+ }
78
+ /* Flipped when the field sits near the bottom of the window. Without it the panel opens off
79
+ the screen and the controls are unreachable, which is the same defect the select fixes. */
80
+ [data-enigma-color-panel][data-side="top"] { top: auto; bottom: calc(100% + 0.375rem); }
81
+
82
+ [data-enigma-color-area] {
83
+ position: relative; height: var(--enigma-color-area-height);
84
+ border-radius: 0.375rem; cursor: crosshair;
85
+ /* The drag IS the control here, so the page must not scroll under it. The marquee's
86
+ warning about touch-action is the opposite case: a full-width row still has to let the
87
+ page move. */
88
+ touch-action: none;
89
+ background:
90
+ linear-gradient(to top, #000000, rgba(0, 0, 0, 0)),
91
+ linear-gradient(to right, #ffffff, rgba(255, 255, 255, 0)),
92
+ hsl(var(--enigma-color-hue, 0), 100%, 50%);
93
+ }
94
+ [data-enigma-color-area]:focus-visible,
95
+ [data-enigma-color-rail]:focus-visible { outline: 2px solid var(--enigma-color-focus); outline-offset: 2px; }
96
+
97
+ [data-enigma-color-controls] { display: flex; align-items: center; gap: 0.5rem; }
98
+ [data-enigma-color-rails] { display: grid; gap: 0.5rem; flex: 1; min-width: 0; }
99
+
100
+ [data-enigma-color-rail] {
101
+ position: relative; height: var(--enigma-color-rail-height);
102
+ border-radius: 999px; cursor: pointer; touch-action: none;
103
+ }
104
+ [data-enigma-color-rail="hue"] {
105
+ background: linear-gradient(to right, #ff0000, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000);
106
+ }
107
+ [data-enigma-color-rail="alpha"] { background-image: none; }
108
+ [data-enigma-color-rail="alpha"] [data-enigma-color-gradient] {
109
+ position: absolute; inset: 0; border-radius: inherit;
110
+ background: linear-gradient(to right, transparent, var(--enigma-color-opaque, #000000));
111
+ }
112
+
113
+ /* One handle for the square and the rails. It must never take the pointer: a press that
114
+ lands on the handle instead of the surface under it would start no drag at all. */
115
+ [data-enigma-color-thumb] {
116
+ position: absolute; pointer-events: none;
117
+ width: 0.75rem; height: 0.75rem; margin: -0.375rem 0 0 -0.375rem;
118
+ border: 2px solid var(--enigma-color-thumb); border-radius: 999px;
119
+ box-shadow: 0 0 0 1px var(--enigma-color-thumb-ring), inset 0 0 0 1px var(--enigma-color-thumb-ring);
120
+ }
121
+ [data-enigma-color-rail] [data-enigma-color-thumb] { top: 50%; }
122
+
123
+ [data-enigma-color-preview] {
124
+ position: relative; flex: none; width: 1.75rem; height: 1.75rem;
125
+ border: 1px solid var(--enigma-color-border); border-radius: 999px; overflow: hidden;
126
+ }
127
+
128
+ [data-enigma-color-eyedropper] {
129
+ display: grid; place-items: center; flex: none;
130
+ width: 1.75rem; height: 1.75rem; padding: 0;
131
+ color: var(--enigma-color-muted); background: none;
132
+ border: 1px solid var(--enigma-color-border); border-radius: 0.375rem; cursor: pointer;
133
+ }
134
+ [data-enigma-color-eyedropper]:hover { color: var(--enigma-color-text); }
135
+ [data-enigma-color-eyedropper]:focus-visible { outline: 2px solid var(--enigma-color-focus); outline-offset: 2px; }
136
+
137
+ [data-enigma-color-swatches] { display: flex; flex-wrap: wrap; gap: 0.25rem; }
138
+ [data-enigma-color-preset] {
139
+ width: 1.125rem; height: 1.125rem; padding: 0;
140
+ border: 1px solid var(--enigma-color-border); border-radius: 0.25rem; cursor: pointer;
141
+ }
142
+ [data-enigma-color-preset]:focus-visible { outline: 2px solid var(--enigma-color-focus); outline-offset: 2px; }
143
+ [data-enigma-color-preset][aria-pressed="true"] { box-shadow: 0 0 0 2px var(--enigma-color-focus); }
@@ -0,0 +1,185 @@
1
+ /*
2
+ * The context-menu stylesheet.
3
+ *
4
+ * GENERATED from src/react/context-menu/styles.ts by scripts/sync-recipes.mjs - edit that file, not
5
+ * this one. It exists as a stylesheet as well as a string because the component injects it,
6
+ * and this is the same sheet for anyone who would rather import it, copy it with
7
+ * `enigma add context-menu --copy`, or fork it outright.
8
+ */
9
+ :root {
10
+ --enigma-menu-bg: #1c1c1c;
11
+ --enigma-menu-border: #333333;
12
+ --enigma-menu-radius: 0.625rem;
13
+ --enigma-menu-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
14
+ --enigma-menu-text: #f5f5f5;
15
+ --enigma-menu-muted: #a3a3a3;
16
+ --enigma-menu-font-size: 0.8125rem;
17
+ --enigma-menu-min-width: 12rem;
18
+ --enigma-menu-max-height: 20rem;
19
+
20
+ --enigma-menu-active-bg: #2a2a2a;
21
+ --enigma-menu-accent: #fbbf24;
22
+ --enigma-menu-danger: #f87171;
23
+ --enigma-menu-danger-bg: rgba(248, 113, 113, 0.12);
24
+ }
25
+
26
+ @media (prefers-color-scheme: light) {
27
+ :root {
28
+ --enigma-menu-bg: #ffffff;
29
+ --enigma-menu-border: #e5e5e5;
30
+ --enigma-menu-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
31
+ --enigma-menu-text: #171717;
32
+ --enigma-menu-muted: #737373;
33
+ --enigma-menu-active-bg: #f5f5f5;
34
+ --enigma-menu-accent: #b45309;
35
+ --enigma-menu-danger: #b91c1c;
36
+ --enigma-menu-danger-bg: rgba(185, 28, 28, 0.08);
37
+ }
38
+ }
39
+
40
+ /* Every panel is positioned in VIEWPORT coordinates, which is what a pointer event reports
41
+ and what a menu opened at the pointer needs. Fixed rather than absolute so a scrolling
42
+ ancestor cannot drag it away from the place it was opened. */
43
+ [data-enigma-menu-panel] {
44
+ position: fixed; z-index: 60;
45
+ box-sizing: border-box;
46
+ min-width: var(--enigma-menu-min-width);
47
+ max-width: min(22rem, calc(100vw - 1rem));
48
+ padding: 0.25rem;
49
+ color: var(--enigma-menu-text);
50
+ background: var(--enigma-menu-bg);
51
+ border: 1px solid var(--enigma-menu-border);
52
+ border-radius: var(--enigma-menu-radius);
53
+ box-shadow: var(--enigma-menu-shadow);
54
+ font-size: var(--enigma-menu-font-size);
55
+ animation: enigma-menu-in 90ms ease-out;
56
+ /* Measured before it is placed, and placed before it is seen: without this the panel is
57
+ painted at 0,0 for one frame and jumps to the pointer on the next. */
58
+ visibility: hidden;
59
+ }
60
+ [data-enigma-menu-panel][data-placed] { visibility: visible; }
61
+ /* No focus ring around the panel. It takes focus so the keyboard has somewhere to be, not
62
+ because it is a control: what MOVES is the highlighted row, drawn by [data-active] and
63
+ announced through aria-activedescendant. A ring around the whole menu says the menu is the
64
+ thing focused, which is not what is happening - and it appears the moment you press an
65
+ arrow, over a surface that was already showing you where you are. Nothing is lost by
66
+ removing it, because nothing inside is reachable by Tab: the menu owns that key. */
67
+ [data-enigma-menu-panel]:focus,
68
+ [data-enigma-menu-panel]:focus-visible { outline: none; }
69
+ @keyframes enigma-menu-in {
70
+ from { opacity: 0; transform: scale(0.98); }
71
+ to { opacity: 1; transform: none; }
72
+ }
73
+ @media (prefers-reduced-motion: reduce) {
74
+ [data-enigma-menu-panel] { animation: none; }
75
+ }
76
+
77
+ /* The heading: what the menu is acting ON. A long file name is cut rather than allowed to
78
+ set the panel's width, and the full one stays reachable through its title attribute. */
79
+ [data-enigma-menu-title] {
80
+ margin: 0; padding: 0.375rem 0.5rem 0.25rem;
81
+ font-size: 0.6875rem; font-weight: 600;
82
+ color: var(--enigma-menu-muted);
83
+ overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
84
+ }
85
+
86
+ [data-enigma-menu-search] {
87
+ width: 100%; box-sizing: border-box;
88
+ padding: 0.375rem 0.5rem 0.5rem;
89
+ font: inherit; font-size: var(--enigma-menu-font-size);
90
+ color: var(--enigma-menu-text); background: transparent;
91
+ border: 0; border-bottom: 1px solid var(--enigma-menu-border);
92
+ outline: none;
93
+ }
94
+ [data-enigma-menu-search]::-webkit-search-cancel-button,
95
+ [data-enigma-menu-search]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
96
+
97
+ [data-enigma-menu-list] {
98
+ max-height: var(--enigma-menu-max-height);
99
+ overflow-y: auto; overscroll-behavior: contain;
100
+ }
101
+
102
+ [data-enigma-menu-item] {
103
+ display: flex; align-items: center; gap: 0.5rem;
104
+ padding: 0.3125rem 0.5rem; border-radius: 0.375rem;
105
+ line-height: 1.4;
106
+ color: var(--enigma-menu-text);
107
+ /* The hand, not the arrow. A native menu uses the arrow because the whole surface is
108
+ drawn by the OS and nothing on a page looks like it; here the rows sit on a web page,
109
+ where the hand is what says "this is a thing you press". */
110
+ cursor: pointer; user-select: none;
111
+ }
112
+ [data-enigma-menu-item][data-active] { background: var(--enigma-menu-active-bg); }
113
+ [data-enigma-menu-item][data-disabled] { opacity: 0.45; cursor: not-allowed; }
114
+ [data-enigma-menu-item][data-destructive] { color: var(--enigma-menu-danger); }
115
+ [data-enigma-menu-item][data-destructive][data-active] { background: var(--enigma-menu-danger-bg); }
116
+
117
+ [data-enigma-menu-item-text] { display: grid; min-width: 0; }
118
+ [data-enigma-menu-item-label] { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
119
+ [data-enigma-menu-item-description] {
120
+ font-size: 0.6875rem; color: var(--enigma-menu-muted);
121
+ overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
122
+ }
123
+
124
+ [data-enigma-menu-icon] { display: inline-flex; align-items: center; flex: none; width: 1rem; max-height: 1.25em; line-height: 0; }
125
+
126
+ /* The shortcut, on the right, the way every desktop menu prints it. margin-left: auto is
127
+ what pushes it there, and flex: none is what stops a long label squashing it. */
128
+ [data-enigma-menu-shortcut] {
129
+ display: flex; align-items: center; gap: 0.125rem;
130
+ flex: none; margin-left: auto; padding-left: 1.5rem;
131
+ font-size: 0.6875rem; color: var(--enigma-menu-muted);
132
+ font-variant-numeric: tabular-nums;
133
+ }
134
+ [data-enigma-menu-shortcut] kbd { font: inherit; }
135
+
136
+ /* The submenu arrow shares the shortcut's slot, so a row never has both pushed apart. */
137
+ [data-enigma-menu-arrow] {
138
+ flex: none; margin-left: auto;
139
+ width: 0.35rem; height: 0.35rem;
140
+ border-right: 1.5px solid currentColor; border-top: 1.5px solid currentColor;
141
+ transform: rotate(45deg);
142
+ opacity: 0.6;
143
+ }
144
+ [data-enigma-menu-shortcut] + [data-enigma-menu-arrow] { margin-left: 0.5rem; }
145
+
146
+ /* Check and radio: drawn rather than loaded, and reserving their space either way so
147
+ choosing a row does not shift the label under the pointer. */
148
+ [data-enigma-menu-check] {
149
+ flex: none; width: 1rem; height: 1rem;
150
+ display: grid; place-items: center;
151
+ color: var(--enigma-menu-accent);
152
+ }
153
+ [data-enigma-menu-check]::after { content: ""; width: 0.35rem; height: 0.6rem; opacity: 0; }
154
+ [data-enigma-menu-item][aria-checked="true"] [data-enigma-menu-check]::after {
155
+ opacity: 1;
156
+ border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
157
+ transform: rotate(45deg) translate(-0.05rem, -0.05rem);
158
+ }
159
+ [data-enigma-menu-item][role="menuitemradio"] [data-enigma-menu-check]::after {
160
+ width: 0.4rem; height: 0.4rem; border-radius: 999px; background: currentColor;
161
+ transform: none; border: 0;
162
+ }
163
+
164
+ [data-enigma-menu-separator] {
165
+ height: 1px; margin: 0.25rem 0.25rem;
166
+ background: var(--enigma-menu-border);
167
+ }
168
+
169
+ [data-enigma-menu-label] {
170
+ margin: 0.375rem 0 0.125rem; padding: 0 0.5rem;
171
+ font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
172
+ color: var(--enigma-menu-muted);
173
+ }
174
+
175
+ [data-enigma-menu-status] {
176
+ margin: 0; padding: 0.625rem 0.5rem;
177
+ font-size: var(--enigma-menu-font-size); color: var(--enigma-menu-muted);
178
+ /* The quoted query is cut in the text as well, but a pasted string with no spaces has no
179
+ break opportunity at all - so this is what stops it stretching the panel. */
180
+ overflow-wrap: anywhere;
181
+ }
182
+ [data-enigma-menu-status][data-error] { color: var(--enigma-menu-danger); }
183
+
184
+ /* The end-of-window marker: one pixel, so it has a box to be scrolled into. */
185
+ [data-enigma-menu-more] { height: 1px; }
@@ -57,6 +57,15 @@
57
57
  background: transparent; border: 0; outline: none;
58
58
  }
59
59
 
60
+ /* The platform's own clear button, gone. A search field here already renders one - so
61
+ WebKit draws a SECOND cross next to it, and only in WebKit, which makes it a duplicate
62
+ half the visitors see and the other half never do. */
63
+ [data-enigma-input]::-webkit-search-cancel-button,
64
+ [data-enigma-input]::-webkit-search-decoration,
65
+ [data-enigma-input]::-webkit-search-results-button {
66
+ -webkit-appearance: none; appearance: none; display: none;
67
+ }
68
+
60
69
  /* A breached password is worth showing on the field itself, not only in the message. */
61
70
  [data-enigma-input-root][data-breached] [data-enigma-input-field] { border-color: var(--enigma-input-danger); }
62
71
 
@@ -214,6 +214,9 @@
214
214
  text-align: center;
215
215
  color: var(--enigma-palette-muted);
216
216
  font-size: 0.875rem;
217
+ /* It quotes the query, and a pasted string with no spaces in it has no break
218
+ opportunity: without this it runs out of the panel rather than wrapping. */
219
+ overflow-wrap: anywhere;
217
220
  }
218
221
 
219
222
  [data-enigma-palette-footer] {
@@ -1,6 +1,6 @@
1
1
  import Fuse from "fuse.js";
2
2
  import type { ReactNode } from "react";
3
- import { useSearch } from "@enigmax/primitives/react";
3
+ import { useSearch, shortenQuery } from "@enigmax/primitives/react";
4
4
 
5
5
  /**
6
6
  * A styled search field with its result list, yours to edit.
@@ -46,12 +46,13 @@ export function Search<T>({
46
46
  rounded-lg border border-neutral-700 bg-neutral-900 px-3 py-2.5
47
47
  text-sm text-neutral-100 outline-none
48
48
  placeholder:text-neutral-500 focus:border-neutral-400
49
+ [&::-webkit-search-cancel-button]:appearance-none
49
50
  "
50
51
  />
51
52
 
52
53
  {query && (
53
54
  <p className="font-mono text-[11px] text-neutral-500">
54
- {results.length} result{results.length === 1 ? "" : "s"} for &quot;{query}&quot;
55
+ {results.length} result{results.length === 1 ? "" : "s"} for &quot;{shortenQuery(query)}&quot;
55
56
  </p>
56
57
  )}
57
58