@mistriwork/ui 1.0.0-rc.39 → 1.0.0-rc.41

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 (47) hide show
  1. package/dist/Avatar.d.ts +3 -1
  2. package/dist/Avatar.js +4 -1
  3. package/dist/Button.d.ts +13 -3
  4. package/dist/Button.js +9 -1
  5. package/dist/Choices.d.ts +11 -5
  6. package/dist/Choices.js +12 -5
  7. package/dist/DateField.d.ts +3 -1
  8. package/dist/DateField.js +4 -1
  9. package/dist/Drawer.d.ts +2 -1
  10. package/dist/Drawer.js +4 -1
  11. package/dist/DropMenu.d.ts +8 -4
  12. package/dist/DropMenu.js +10 -4
  13. package/dist/Dropdown.d.ts +4 -2
  14. package/dist/Dropdown.js +6 -2
  15. package/dist/Modal.d.ts +2 -1
  16. package/dist/Modal.js +4 -1
  17. package/dist/Pagination.d.ts +2 -1
  18. package/dist/Pagination.js +4 -1
  19. package/dist/Popover.d.ts +3 -1
  20. package/dist/Popover.js +4 -1
  21. package/dist/Select.d.ts +4 -2
  22. package/dist/Select.js +6 -2
  23. package/dist/SensitiveField.d.ts +3 -1
  24. package/dist/SensitiveField.js +4 -1
  25. package/dist/Slider.d.ts +3 -1
  26. package/dist/Slider.js +4 -1
  27. package/dist/Switch.d.ts +3 -1
  28. package/dist/Switch.js +4 -1
  29. package/dist/Tabs.d.ts +3 -1
  30. package/dist/Tabs.js +4 -1
  31. package/dist/TextField.d.ts +7 -3
  32. package/dist/TextField.js +8 -3
  33. package/dist/Tooltip.d.ts +3 -1
  34. package/dist/Tooltip.js +4 -1
  35. package/dist/Typeahead.d.ts +3 -2
  36. package/dist/Typeahead.js +4 -1
  37. package/dist/UiKit.d.ts +86 -0
  38. package/dist/UiKit.js +32 -0
  39. package/dist/conformance.d.ts +9 -0
  40. package/dist/conformance.js +470 -0
  41. package/dist/index.d.ts +3 -2
  42. package/dist/index.js +3 -1
  43. package/dist/internal/uiKitContext.d.ts +15 -0
  44. package/dist/internal/uiKitContext.js +23 -0
  45. package/dist/uiKitSlots.d.ts +13 -0
  46. package/dist/uiKitSlots.js +83 -0
  47. package/package.json +4 -1
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The slots a control kit may fill and the rules a kit is held to before it draws (UiKit.tsx, Preview), in a module
3
+ * with no React and no primitive in it: an App's load and `mistri check` judge a kit with these on the server, where
4
+ * an App's own typecheck follows the import and has no JSX to read a primitive's module with.
5
+ */
6
+ /** Every slot a kit may fill, in the order the docs list them. */
7
+ export const SLOT_NAMES = [
8
+ 'Button',
9
+ 'ButtonLink',
10
+ 'TextField',
11
+ 'MaskedField',
12
+ 'MoneyField',
13
+ 'SensitiveField',
14
+ 'Select',
15
+ 'MultiSelect',
16
+ 'Dropdown',
17
+ 'MultiDropdown',
18
+ 'Typeahead',
19
+ 'DateField',
20
+ 'Checkbox',
21
+ 'YesNo',
22
+ 'ChoiceCards',
23
+ 'CheckCards',
24
+ 'Consent',
25
+ 'Switch',
26
+ 'Slider',
27
+ 'Modal',
28
+ 'Drawer',
29
+ 'Popover',
30
+ 'Tooltip',
31
+ 'DropMenu',
32
+ 'DropGroup',
33
+ 'DropItem',
34
+ 'DropSeparator',
35
+ 'Tabs',
36
+ 'Pagination',
37
+ 'Avatar',
38
+ ];
39
+ /* The parts that share one state of their own: a kit that drew a menu's items but not its menu would hand Base UI's
40
+ items a menu they cannot find. */
41
+ const FAMILIES = [['DropMenu', 'DropGroup', 'DropItem', 'DropSeparator']];
42
+ const isSlot = (name) => SLOT_NAMES.includes(name);
43
+ /* The slot a misspelled name was meant to be: one letter's case, or two edits, away. */
44
+ function nearest(name) {
45
+ const lower = name.toLowerCase();
46
+ return SLOT_NAMES.find((slot) => slot.toLowerCase() === lower) ?? SLOT_NAMES.find((slot) => edits(slot.toLowerCase(), lower) <= 2);
47
+ }
48
+ function edits(a, b) {
49
+ let row = Array.from({ length: b.length + 1 }, (_, i) => i);
50
+ for (let i = 1; i <= a.length; i++) {
51
+ const next = [i];
52
+ for (let j = 1; j <= b.length; j++)
53
+ next[j] = Math.min(row[j] + 1, next[j - 1] + 1, row[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
54
+ row = next;
55
+ }
56
+ return row[b.length];
57
+ }
58
+ /**
59
+ * What is wrong with a value offered as a kit, each as the rest of a sentence that begins with the kit's name ("the
60
+ * UI kit (./ui/kit.tsx) has no slot named …"); none for a kit. `mistri check` and an App's load say the same.
61
+ */
62
+ export function uiKitProblems(value) {
63
+ if (!value || typeof value !== 'object' || Array.isArray(value))
64
+ return ['has no default export made by defineUiKit: export default defineUiKit({ Button, … }).'];
65
+ const problems = [];
66
+ const names = Object.keys(value);
67
+ for (const name of names) {
68
+ if (!isSlot(name)) {
69
+ const near = nearest(name);
70
+ problems.push(`has no slot named "${name}"${near ? ` (did you mean "${near}"?)` : ''}; the slots are ${SLOT_NAMES.join(', ')}.`);
71
+ continue;
72
+ }
73
+ const component = value[name];
74
+ if (typeof component !== 'function' && !(component && typeof component === 'object'))
75
+ problems.push(`gives "${name}" something that is not a component: a slot takes a function that draws it.`);
76
+ }
77
+ for (const family of FAMILIES) {
78
+ const given = family.filter((name) => names.includes(name));
79
+ if (given.length && given.length < family.length)
80
+ problems.push(`draws ${given.join(', ')} but not ${family.filter((name) => !given.includes(name)).join(', ')}: a menu's parts share the menu's state, so a kit draws all ${family.length} or none.`);
81
+ }
82
+ return problems;
83
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/ui",
3
- "version": "1.0.0-rc.39",
3
+ "version": "1.0.0-rc.41",
4
4
  "description": "The standalone React primitives both shells are drawn with: Modal, DropMenu, Dropdown, Typeahead, Button, Field, Icon and DateField over Base UI, Switch, Tabs, Drawer, Popover, Avatar, Pagination, Carousel, Resizable, ScrollArea and Tooltip, the form controls built on them (text, masked, money and sensitive boxes, listboxes, choices, slider, progress and action bar; Preview), the landing hero's blocks (badge, photo tiles, icon rows; Preview), their tokens and stylesheet, and the zoom-aware ruler their popups are placed by.",
5
5
  "homepage": "https://mistriwork.dev",
6
6
  "bugs": {
@@ -63,6 +63,9 @@
63
63
  "./internal/ruler.js": "./dist/internal/ruler.js",
64
64
  "./style.css": "./dist/style.css",
65
65
  "./tokens.css": "./dist/tokens.css",
66
+ "./uiKitSlots.js": "./dist/uiKitSlots.js",
67
+ "./UiKit.js": "./dist/UiKit.js",
68
+ "./conformance.js": "./dist/conformance.js",
66
69
  "./package.json": "./package.json"
67
70
  },
68
71
  "peerDependencies": {