@wirecore/wirelayer-recipes 0.6.0 → 0.8.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 (90) hide show
  1. package/dist/a11y.d.ts +11 -0
  2. package/dist/a11y.d.ts.map +1 -1
  3. package/dist/a11y.js +44 -0
  4. package/dist/a11y.js.map +1 -1
  5. package/dist/alert.d.ts +30 -0
  6. package/dist/alert.d.ts.map +1 -1
  7. package/dist/alert.js +8 -0
  8. package/dist/alert.js.map +1 -1
  9. package/dist/blocks.d.ts +3 -3
  10. package/dist/card.d.ts +51 -0
  11. package/dist/card.d.ts.map +1 -1
  12. package/dist/card.js +20 -0
  13. package/dist/card.js.map +1 -1
  14. package/dist/config.d.ts.map +1 -1
  15. package/dist/config.js +4 -0
  16. package/dist/config.js.map +1 -1
  17. package/dist/controls.d.ts +3 -3
  18. package/dist/editor.d.ts +6 -6
  19. package/dist/field.d.ts +30 -0
  20. package/dist/field.d.ts.map +1 -1
  21. package/dist/field.js +8 -0
  22. package/dist/field.js.map +1 -1
  23. package/dist/filters.d.ts +3 -3
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +2 -2
  27. package/dist/index.js.map +1 -1
  28. package/dist/inputs.d.ts +18 -0
  29. package/dist/inputs.d.ts.map +1 -1
  30. package/dist/inputs.js +4 -0
  31. package/dist/inputs.js.map +1 -1
  32. package/dist/native/data.d.ts +99 -0
  33. package/dist/native/data.d.ts.map +1 -1
  34. package/dist/native/data.js +25 -0
  35. package/dist/native/data.js.map +1 -1
  36. package/dist/native/display.d.ts +143 -32
  37. package/dist/native/display.d.ts.map +1 -1
  38. package/dist/native/display.js +29 -0
  39. package/dist/native/display.js.map +1 -1
  40. package/dist/native/form.d.ts +30 -0
  41. package/dist/native/form.d.ts.map +1 -1
  42. package/dist/native/form.js +8 -0
  43. package/dist/native/form.js.map +1 -1
  44. package/dist/native/inputs.d.ts +3 -3
  45. package/dist/native/overlay.d.ts +30 -0
  46. package/dist/native/overlay.d.ts.map +1 -1
  47. package/dist/native/overlay.js +10 -0
  48. package/dist/native/overlay.js.map +1 -1
  49. package/dist/native/widgets.d.ts +3 -3
  50. package/dist/navigation.d.ts +129 -3
  51. package/dist/navigation.d.ts.map +1 -1
  52. package/dist/navigation.js +65 -6
  53. package/dist/navigation.js.map +1 -1
  54. package/dist/overlay.d.ts +30 -0
  55. package/dist/overlay.d.ts.map +1 -1
  56. package/dist/overlay.js +10 -0
  57. package/dist/overlay.js.map +1 -1
  58. package/dist/sources/alert.css +1 -1
  59. package/dist/sources/card.css +1 -1
  60. package/dist/sources/cardParts.css +1 -1
  61. package/dist/sources/dialog.css +1 -1
  62. package/dist/sources/passwordInput.css +1 -1
  63. package/dist/sources/progress.css +1 -1
  64. package/dist/sources/textarea.css +1 -1
  65. package/dist/tv.js +2 -2
  66. package/dist/tv.js.map +1 -1
  67. package/dist/utils.d.ts +28 -0
  68. package/dist/utils.d.ts.map +1 -1
  69. package/dist/utils.js +45 -0
  70. package/dist/utils.js.map +1 -1
  71. package/dist/vite.d.ts.map +1 -1
  72. package/dist/vite.js +20 -2
  73. package/dist/vite.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/a11y.ts +46 -0
  76. package/src/alert.ts +8 -0
  77. package/src/card.ts +20 -0
  78. package/src/config.ts +4 -0
  79. package/src/field.ts +8 -0
  80. package/src/index.ts +5 -0
  81. package/src/inputs.ts +4 -0
  82. package/src/native/data.ts +25 -0
  83. package/src/native/display.ts +29 -0
  84. package/src/native/form.ts +8 -0
  85. package/src/native/overlay.ts +10 -0
  86. package/src/navigation.ts +65 -6
  87. package/src/overlay.ts +10 -0
  88. package/src/tv.ts +2 -2
  89. package/src/utils.ts +51 -0
  90. package/src/vite.ts +19 -2
@@ -85,6 +85,8 @@ export const alert = tv({
85
85
  content: 'min-w-0 flex-1 gap-0.5 pt-[3px]',
86
86
  title: 'font-sans-semibold text-sm text-fg',
87
87
  description: 'font-sans text-[13px] leading-5 text-muted',
88
+ /** Buttons in the message (`actions`), below the text */
89
+ actions: 'mt-2 flex-row flex-wrap items-center gap-2',
88
90
  dismiss: ['size-7 items-center justify-center rounded-full', pressable, 'active:bg-line active:opacity-100'],
89
91
  dismissIcon: 'size-3.5 text-muted',
90
92
  },
@@ -226,5 +228,32 @@ export const progress = tv({
226
228
  value: 'shrink-0 font-mono text-[11px] text-muted',
227
229
  track: 'h-1.5 overflow-hidden rounded-[3px] bg-line-2',
228
230
  range: 'h-full overflow-hidden rounded-[3px] bg-primary',
231
+ /** Text in the bar (`barText`) over the empty part */
232
+ barText: 'absolute inset-0 items-center justify-center px-1.5',
233
+ barTextLabel: 'font-mono text-[10.5px] text-fg',
234
+ /** The same text inside the filled part (as wide as the track), in the colour for the fill */
235
+ barTextFill: 'absolute top-0 bottom-0 left-0 items-center justify-center px-1.5',
236
+ barTextFillLabel: 'font-mono text-[10.5px] text-on-primary',
229
237
  },
238
+ variants: {
239
+ /** `xs`: small text, e.g. in a list */
240
+ size: {
241
+ xs: { base: 'gap-1', label: 'text-[10px]', value: 'text-[10px]' },
242
+ md: {},
243
+ },
244
+ /** Colour of the filled part by its state */
245
+ status: {
246
+ info: { range: 'bg-info', barTextFillLabel: 'text-on-info' },
247
+ success: { range: 'bg-success', barTextFillLabel: 'text-on-success' },
248
+ warn: { range: 'bg-warn', barTextFillLabel: 'text-on-warn' },
249
+ danger: { range: 'bg-danger', barTextFillLabel: 'text-on-danger' },
250
+ /** Grey, e.g. a cancelled transfer */
251
+ neutral: { range: 'bg-muted', barTextFillLabel: 'text-bg' },
252
+ },
253
+ /** The label only names the bar; the value stays at the end */
254
+ hideLabel: {
255
+ true: { header: 'justify-end' },
256
+ },
257
+ },
258
+ compoundVariants: [{ size: 'xs', class: { barTextLabel: 'text-[10px]', barTextFillLabel: 'text-[10px]' } }],
230
259
  });
@@ -67,6 +67,10 @@ export const input = tv({
67
67
  hasIcon: {
68
68
  true: { control: 'pl-2' },
69
69
  },
70
+ /** Monospace font of the theme – for paths, tokens, codes and keys */
71
+ mono: {
72
+ true: { control: 'font-mono' },
73
+ },
70
74
  },
71
75
  defaultVariants: {
72
76
  size: 'md',
@@ -93,6 +97,10 @@ export const textarea = tv({
93
97
  md: {},
94
98
  lg: 'rounded-[10px] px-4 py-3 text-base',
95
99
  },
100
+ /** Monospace font of the theme – for keys, codes and logs */
101
+ mono: {
102
+ true: 'font-mono',
103
+ },
96
104
  },
97
105
  });
98
106
 
@@ -72,6 +72,16 @@ export const dialog = tv({
72
72
  bare: {
73
73
  true: { body: 'pt-[18px]' },
74
74
  },
75
+ /** `titlePosition: 'header'`: the title in the row of the close button (a smaller icon before it), as on the Drawer */
76
+ titleInHeader: {
77
+ true: {
78
+ header: 'border-b border-line pb-3',
79
+ iconBox: 'size-7 rounded-lg',
80
+ icon: 'size-4',
81
+ title: 'min-w-0 flex-1 text-base',
82
+ body: 'pt-4',
83
+ },
84
+ },
75
85
  /** The body scrolls, title and buttons stay */
76
86
  scrollInside: {
77
87
  true: { content: 'max-h-full' },
package/src/navigation.ts CHANGED
@@ -240,8 +240,32 @@ export const progress = tv({
240
240
  legendItem: 'flex items-center gap-1.5',
241
241
  swatch: 'size-2 shrink-0 rounded-full',
242
242
  legendValue: 'text-muted tabular-nums',
243
+ /** Text in the bar (`barText`) over the empty part */
244
+ barText: [
245
+ 'pointer-events-none absolute inset-0 flex items-center justify-center overflow-hidden px-1.5',
246
+ 'font-mono text-[10.5px] leading-none whitespace-nowrap text-fg tabular-nums',
247
+ ],
248
+ /** The same text in the range, as wide as the track (100cqw) and cut by the range – in the colour for the fill */
249
+ barTextFill: [
250
+ 'pointer-events-none absolute inset-y-0 start-0 flex w-[100cqw] items-center justify-center px-1.5',
251
+ 'font-mono text-[10.5px] leading-none whitespace-nowrap text-on-primary tabular-nums',
252
+ 'forced-colors:text-[HighlightText]',
253
+ ],
243
254
  },
244
255
  variants: {
256
+ /** `xs`: a thin bar with small text, e.g. in a list or a status bar */
257
+ size: {
258
+ xs: { base: 'gap-1', header: 'text-[10px]', track: 'h-1' },
259
+ md: {},
260
+ },
261
+ /** The label only names the bar for screen readers; the value stays at the end */
262
+ hideLabel: {
263
+ true: { header: 'justify-end' },
264
+ },
265
+ /** Text in the bar: a taller track, the range covers the text below and cuts the text in it */
266
+ hasText: {
267
+ true: { track: 'relative @container h-4', range: 'relative overflow-hidden' },
268
+ },
245
269
  /** Vertical bar: grows from the bottom (fill the height of the parent) */
246
270
  orientation: {
247
271
  horizontal: {},
@@ -271,19 +295,54 @@ export const progress = tv({
271
295
  animated: {
272
296
  true: { range: 'motion-safe:animate-progress-stripes', segment: 'motion-safe:animate-progress-stripes' },
273
297
  },
274
- /** Colour of a segment */
298
+ /** Colour of a segment – and of the filled part (`status`) */
275
299
  color: {
276
300
  primary: { segment: 'bg-primary', swatch: 'bg-primary' },
277
- info: { segment: 'bg-info', swatch: 'bg-info' },
278
- success: { segment: 'bg-success', swatch: 'bg-success' },
279
- warn: { segment: 'bg-warn', swatch: 'bg-warn' },
280
- danger: { segment: 'bg-danger', swatch: 'bg-danger' },
281
- muted: { segment: 'bg-muted', swatch: 'bg-muted' },
301
+ info: {
302
+ segment: 'bg-info',
303
+ swatch: 'bg-info',
304
+ range: 'bg-info',
305
+ step: 'data-[state=complete]:bg-info',
306
+ barTextFill: 'text-on-info',
307
+ },
308
+ success: {
309
+ segment: 'bg-success',
310
+ swatch: 'bg-success',
311
+ range: 'bg-success',
312
+ step: 'data-[state=complete]:bg-success',
313
+ barTextFill: 'text-on-success',
314
+ },
315
+ warn: {
316
+ segment: 'bg-warn',
317
+ swatch: 'bg-warn',
318
+ range: 'bg-warn',
319
+ step: 'data-[state=complete]:bg-warn',
320
+ barTextFill: 'text-on-warn',
321
+ },
322
+ danger: {
323
+ segment: 'bg-danger',
324
+ swatch: 'bg-danger',
325
+ range: 'bg-danger',
326
+ step: 'data-[state=complete]:bg-danger',
327
+ barTextFill: 'text-on-danger',
328
+ },
329
+ /** Also the fill of `status: 'neutral'` (e.g. a cancelled transfer) */
330
+ muted: {
331
+ segment: 'bg-muted',
332
+ swatch: 'bg-muted',
333
+ range: 'bg-muted',
334
+ step: 'data-[state=complete]:bg-muted',
335
+ barTextFill: 'text-bg',
336
+ },
282
337
  },
283
338
  },
339
+ compoundVariants: [
340
+ { size: 'xs', hasText: true, class: { track: 'h-3.5', barText: 'text-[10px]', barTextFill: 'text-[10px]' } },
341
+ ],
284
342
  defaultVariants: {
285
343
  orientation: 'horizontal',
286
344
  color: 'primary',
345
+ size: 'md',
287
346
  },
288
347
  });
289
348
 
package/src/overlay.ts CHANGED
@@ -130,6 +130,16 @@ export const dialog = tv({
130
130
  hideTitle: {
131
131
  true: { title: 'sr-only' },
132
132
  },
133
+ /** `titlePosition: 'header'`: the title in the row of the close button (a smaller icon before it), as on the Drawer */
134
+ titleInHeader: {
135
+ true: {
136
+ header: 'border-b border-line pb-3',
137
+ iconBox: 'size-7 shrink-0 rounded-lg',
138
+ icon: 'size-4',
139
+ title: 'min-w-0 flex-1 text-base break-words',
140
+ body: 'pt-4',
141
+ },
142
+ },
133
143
  status: {
134
144
  neutral: { iconBox: 'bg-line text-fg' },
135
145
  success: { iconBox: 'bg-success/14 text-success' },
package/src/tv.ts CHANGED
@@ -3,8 +3,8 @@ import { createTV } from 'tailwind-variants';
3
3
  /** tailwind-merge knows the custom WireLayer utilities (also used by the @wirecore/wirelayer-css generator). */
4
4
  export const twMergeConfig = {
5
5
  extend: {
6
- // rounded-popup is a radius, so `classes` like rounded-none replace it
7
- theme: { radius: ['popup'] },
6
+ // rounded-popup, -card and -panel are radii, so `classes` like rounded-none (or a Card's size) replace them
7
+ theme: { radius: ['popup', 'card', 'panel'] },
8
8
  classGroups: {
9
9
  'bg-image': ['bg-glow'],
10
10
  'text-gradient': ['text-gradient'],
package/src/utils.ts CHANGED
@@ -665,6 +665,35 @@ export function createLongPress(
665
665
  };
666
666
  }
667
667
 
668
+ /** How a context menu is being opened – the second argument of ContextMenu's before-open */
669
+ export interface ContextMenuOpenDetails {
670
+ /** `pointer`: right click or long press; `keyboard`: Shift+F10 or the menu key */
671
+ source: 'pointer' | 'keyboard';
672
+ /** With the keyboard: the element that has the focus (e.g. a row of a list) – null with the pointer */
673
+ focused: Element | null;
674
+ }
675
+
676
+ /**
677
+ * Tells the contextmenu events of the keyboard (Shift+F10, the menu key) from those of the pointer: give it the
678
+ * keydown and pointerdown events of the area, and ask it on contextmenu. Browser only.
679
+ */
680
+ export function createContextMenuSource() {
681
+ let keyboard = false;
682
+ return {
683
+ keydown(event: { key: string; shiftKey: boolean }) {
684
+ if (event.key === 'ContextMenu' || (event.key === 'F10' && event.shiftKey)) keyboard = true;
685
+ },
686
+ pointerdown() {
687
+ keyboard = false;
688
+ },
689
+ contextmenu(): ContextMenuOpenDetails {
690
+ const source = keyboard ? 'keyboard' : 'pointer';
691
+ keyboard = false;
692
+ return { source, focused: source === 'keyboard' ? document.activeElement : null };
693
+ },
694
+ };
695
+ }
696
+
668
697
  /** A toast swiped sideways by `distance` pixels closes once it moved 80 pixels or 40 % of its width */
669
698
  export function isSwipeDismiss(distance: number, width: number): boolean {
670
699
  return Math.abs(distance) >= Math.min(80, width * 0.4);
@@ -867,3 +896,25 @@ export function highlightFirstMenuItem(
867
896
  if (first) menu.setHighlightedValue(first.dataset.value ?? '');
868
897
  return first?.id;
869
898
  }
899
+
900
+ /**
901
+ * Closes an open menu on what it does not follow: the page scrolling (not a scroll inside a menu), the window being
902
+ * resized or losing the focus (switching to another window). Returns the cleanup. Browser only.
903
+ */
904
+ export function closeMenuOnPageEvents(
905
+ close: () => void,
906
+ events: { scroll?: boolean; resize?: boolean; blur?: boolean }
907
+ ): () => void {
908
+ const onScroll = (event: Event) => {
909
+ if (event.target instanceof Element && event.target.closest('[data-scope=menu]')) return;
910
+ close();
911
+ };
912
+ const listeners: [string, EventListener, AddEventListenerOptions][] = [];
913
+ if (events.scroll) listeners.push(['scroll', onScroll, { capture: true, passive: true }]);
914
+ if (events.resize) listeners.push(['resize', close, {}]);
915
+ if (events.blur) listeners.push(['blur', close, {}]);
916
+ for (const [type, listener, options] of listeners) window.addEventListener(type, listener, options);
917
+ return () => {
918
+ for (const [type, listener, options] of listeners) window.removeEventListener(type, listener, options);
919
+ };
920
+ }
package/src/vite.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
2
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
3
3
  import { createRequire } from 'node:module';
4
4
  import { dirname, extname, join, relative } from 'node:path';
5
5
  import type { Plugin, ViteDevServer } from 'vite';
@@ -95,6 +95,18 @@ export function wirelayer(options: WireLayerSourcesOptions = {}): Plugin {
95
95
  const perFile = new Map<string, Map<string, Set<string>>>();
96
96
  let imports = '';
97
97
  const entries = new Set<string>();
98
+ let cacheDir = join(root, 'node_modules/.vite');
99
+ /**
100
+ * In the dev server the imports live in a file of their own: Tailwind's Vite plugin only builds a CSS file again
101
+ * when one of the files it imports changed on disk – imports added to the code alone would be ignored until a
102
+ * restart
103
+ */
104
+ let devFile: string | undefined;
105
+ const writeDevFile = () => {
106
+ if (!devFile) return;
107
+ mkdirSync(dirname(devFile), { recursive: true });
108
+ writeFileSync(devFile, `${imports}\n`);
109
+ };
98
110
 
99
111
  const read = (file: string) => {
100
112
  try {
@@ -126,9 +138,11 @@ export function wirelayer(options: WireLayerSourcesOptions = {}): Plugin {
126
138
  enforce: 'pre',
127
139
  configResolved(config) {
128
140
  root = config.root;
141
+ cacheDir = config.cacheDir ?? join(root, 'node_modules/.vite');
129
142
  },
130
143
  buildStart() {
131
144
  scan();
145
+ writeDevFile();
132
146
  },
133
147
  transform(code, id) {
134
148
  const entry = id.split('?')[0]!.endsWith('.css') ? ENTRY.exec(code) : null;
@@ -136,12 +150,14 @@ export function wirelayer(options: WireLayerSourcesOptions = {}): Plugin {
136
150
  entries.add(id);
137
151
  // Right after the theme import – @import rules come before all others
138
152
  const end = code.indexOf(';', entry.index) + 1;
153
+ const added = devFile ? `@import '${devFile.replaceAll('\\', '/')}';` : imports;
139
154
  return {
140
- code: `${code.slice(0, end)}\n/* added by wirelayer() */\n${imports}\n${code.slice(end)}`,
155
+ code: `${code.slice(0, end)}\n/* added by wirelayer() */\n${added}\n${code.slice(end)}`,
141
156
  map: null,
142
157
  };
143
158
  },
144
159
  configureServer(server: ViteDevServer) {
160
+ devFile = join(cacheDir, 'wirelayer-sources.css');
145
161
  // A new or changed import adds its sources file: the CSS is built again
146
162
  const update = (file: string) => {
147
163
  if (!SOURCE_FILES.has(extname(file)) || relative(root, file).startsWith('..')) return;
@@ -150,6 +166,7 @@ export function wirelayer(options: WireLayerSourcesOptions = {}): Plugin {
150
166
  const next = collect();
151
167
  if (next === imports) return;
152
168
  imports = next;
169
+ writeDevFile();
153
170
  for (const id of entries) {
154
171
  const module = server.moduleGraph.getModuleById(id);
155
172
  if (module) void server.reloadModule(module);