@c9up/nebula 0.2.3 → 0.2.5

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 (99) hide show
  1. package/README.md +9 -8
  2. package/dist/atoms/AspectRatio.d.ts +10 -4
  3. package/dist/atoms/AspectRatio.js +21 -6
  4. package/dist/atoms/Avatar.d.ts +14 -0
  5. package/dist/atoms/Avatar.js +46 -8
  6. package/dist/atoms/NativeSelect.d.ts +10 -0
  7. package/dist/atoms/NativeSelect.js +4 -1
  8. package/dist/atoms/Progress.d.ts +9 -1
  9. package/dist/atoms/Progress.js +21 -5
  10. package/dist/atoms/Switch.d.ts +7 -1
  11. package/dist/atoms/Switch.js +7 -1
  12. package/dist/cli/add.d.ts +2 -0
  13. package/dist/cli/add.js +4 -1
  14. package/dist/cli/diff.d.ts +48 -0
  15. package/dist/cli/diff.js +77 -3
  16. package/dist/cli/projectConfig.d.ts +16 -0
  17. package/dist/cli/projectConfig.js +61 -0
  18. package/dist/console/AddCommand.js +6 -1
  19. package/dist/console/DiffCommand.js +12 -12
  20. package/dist/lib/icons.d.ts +8 -0
  21. package/dist/lib/icons.js +8 -0
  22. package/dist/lib/image.js +12 -1
  23. package/dist/molecules/Accordion.js +1 -2
  24. package/dist/molecules/Collapsible.js +1 -2
  25. package/dist/molecules/InputOTP.d.ts +12 -0
  26. package/dist/molecules/InputOTP.js +68 -27
  27. package/dist/molecules/Resizable.d.ts +6 -0
  28. package/dist/molecules/Resizable.js +8 -2
  29. package/dist/molecules/index.d.ts +1 -1
  30. package/dist/molecules/index.js +1 -1
  31. package/dist/organisms/AlertDialog.js +4 -5
  32. package/dist/organisms/Chart.d.ts +103 -15
  33. package/dist/organisms/Chart.js +518 -99
  34. package/dist/organisms/Combobox.d.ts +13 -0
  35. package/dist/organisms/Combobox.js +5 -2
  36. package/dist/organisms/Command.js +56 -8
  37. package/dist/organisms/Dialog.js +7 -7
  38. package/dist/organisms/Form.d.ts +15 -0
  39. package/dist/organisms/Form.js +10 -0
  40. package/dist/organisms/Select.d.ts +6 -4
  41. package/dist/organisms/Select.js +1 -0
  42. package/dist/organisms/Sidebar.d.ts +9 -9
  43. package/dist/organisms/Sidebar.js +77 -32
  44. package/dist/organisms/Sonner.d.ts +243 -0
  45. package/dist/organisms/Sonner.js +916 -0
  46. package/dist/organisms/Toaster.d.ts +9 -0
  47. package/dist/organisms/Toaster.js +28 -5
  48. package/dist/organisms/Tooltip.d.ts +4 -0
  49. package/dist/organisms/index.d.ts +7 -1
  50. package/dist/organisms/index.js +7 -1
  51. package/dist/primitives/dismissable.d.ts +11 -4
  52. package/dist/primitives/dismissable.js +8 -6
  53. package/dist/primitives/floating.d.ts +5 -1
  54. package/dist/primitives/floating.js +8 -1
  55. package/dist/primitives/menu.js +2 -1
  56. package/dist/primitives/menuParts.js +3 -3
  57. package/dist/primitives/modalSurface.js +70 -36
  58. package/dist/primitives/portal.d.ts +15 -0
  59. package/dist/primitives/portal.js +18 -1
  60. package/dist/primitives/presence.js +8 -5
  61. package/nebula.css +2 -2
  62. package/package.json +1 -1
  63. package/registry.json +13 -0
  64. package/src/atoms/AspectRatio.ts +21 -6
  65. package/src/atoms/Avatar.ts +54 -7
  66. package/src/atoms/NativeSelect.ts +14 -1
  67. package/src/atoms/Progress.ts +21 -5
  68. package/src/atoms/Switch.ts +7 -1
  69. package/src/cli/add.ts +7 -1
  70. package/src/cli/diff.ts +130 -3
  71. package/src/cli/projectConfig.ts +71 -0
  72. package/src/console/AddCommand.ts +6 -1
  73. package/src/console/DiffCommand.ts +18 -16
  74. package/src/lib/icons.ts +28 -0
  75. package/src/lib/image.ts +13 -1
  76. package/src/molecules/Accordion.ts +1 -2
  77. package/src/molecules/Collapsible.ts +1 -3
  78. package/src/molecules/InputOTP.ts +81 -27
  79. package/src/molecules/Resizable.ts +8 -2
  80. package/src/molecules/index.ts +3 -0
  81. package/src/organisms/AlertDialog.ts +3 -5
  82. package/src/organisms/Chart.ts +633 -125
  83. package/src/organisms/Combobox.ts +18 -2
  84. package/src/organisms/Command.ts +66 -7
  85. package/src/organisms/Dialog.ts +6 -7
  86. package/src/organisms/Form.ts +21 -0
  87. package/src/organisms/Select.ts +7 -4
  88. package/src/organisms/Sidebar.ts +75 -25
  89. package/src/organisms/Sonner.ts +1373 -0
  90. package/src/organisms/Toaster.ts +30 -6
  91. package/src/organisms/Tooltip.ts +4 -0
  92. package/src/organisms/index.ts +29 -0
  93. package/src/primitives/dismissable.ts +16 -8
  94. package/src/primitives/floating.ts +13 -2
  95. package/src/primitives/menu.ts +2 -1
  96. package/src/primitives/menuParts.ts +3 -3
  97. package/src/primitives/modalSurface.ts +77 -40
  98. package/src/primitives/portal.ts +27 -1
  99. package/src/primitives/presence.ts +12 -9
@@ -38,6 +38,7 @@ const slotClasses =
38
38
 
39
39
  interface InputOTPApi {
40
40
  readonly length: number;
41
+ readonly inputMode: "numeric" | "text";
41
42
  readonly disabled: () => boolean;
42
43
  readonly slotLabel: (position: number, length: number) => string;
43
44
  /** Claim the next box's index, in the order the slots are built. */
@@ -49,9 +50,22 @@ interface InputOTPApi {
49
50
 
50
51
  const InputOTPContext = createContext<InputOTPApi>("InputOTP");
51
52
 
53
+ /** input-otp's patterns, for the `pattern` prop. */
54
+ export const REGEXP_ONLY_DIGITS = "^\\d+$";
55
+ export const REGEXP_ONLY_CHARS = "^[a-zA-Z]+$";
56
+ export const REGEXP_ONLY_DIGITS_AND_CHARS = "^[a-zA-Z0-9]+$";
57
+
52
58
  export interface InputOTPProps {
53
59
  /** Number of boxes. Default `6` — and it must match the slots built. */
54
60
  length?: number;
61
+ /**
62
+ * What the code may hold, tested against the whole value as input-otp
63
+ * does: a character or a fill that would not match is refused. None by
64
+ * default, as input-otp; `REGEXP_ONLY_DIGITS` for a numeric code.
65
+ */
66
+ pattern?: RegExp | string;
67
+ /** The on-screen keyboard. Default `"numeric"`. */
68
+ inputMode?: "numeric" | "text";
55
69
  /** Each box's accessible name from its position. Default `"Character 2 of 6"`. */
56
70
  slotLabel?: (position: number, length: number) => string;
57
71
  name?: string;
@@ -99,8 +113,47 @@ export const InputOTP = component<InputOTPProps>((props) => {
99
113
  commit(next);
100
114
  }
101
115
 
116
+ const pattern =
117
+ typeof props.pattern === "string"
118
+ ? new RegExp(props.pattern)
119
+ : props.pattern;
120
+
121
+ function accepts(next: readonly string[]): boolean {
122
+ const joined = next.join("");
123
+ return pattern === undefined || joined === "" || pattern.test(joined);
124
+ }
125
+
126
+ /** Put the boxes back to what the code holds. */
127
+ function reflect(): void {
128
+ const inputs = boxes();
129
+ characters().forEach((character, position) => {
130
+ const input = inputs[position];
131
+ if (input !== undefined) input.value = character;
132
+ });
133
+ }
134
+
135
+ /**
136
+ * Share a run of characters out over the boxes from `index`: a paste, and
137
+ * a whole code an autofill or an IME put into one box.
138
+ */
139
+ function spread(index: number, text: string): void {
140
+ const next = [...characters()];
141
+ let cursor = index;
142
+ for (const character of text) {
143
+ if (cursor >= length) break;
144
+ next[cursor] = character;
145
+ cursor += 1;
146
+ }
147
+ if (accepts(next)) commit(next);
148
+ // The boxes are uncontrolled between keystrokes, so writing the signal
149
+ // alone would leave the characters invisible — or a refused fill in place.
150
+ reflect();
151
+ focusBox(Math.min(cursor, length - 1));
152
+ }
153
+
102
154
  provide<InputOTPApi>(InputOTPContext, {
103
155
  length,
156
+ inputMode: props.inputMode ?? "numeric",
104
157
  disabled: () => readOr(props.disabled, false),
105
158
  slotLabel:
106
159
  props.slotLabel ??
@@ -114,12 +167,31 @@ export const InputOTP = component<InputOTPProps>((props) => {
114
167
  const target = event.target;
115
168
  if (!(target instanceof HTMLInputElement)) return;
116
169
 
117
- // A box already holding a character receives the new one appended; keep
118
- // the last, which is what the user just typed.
119
- const typed = target.value.slice(-1);
120
- target.value = typed;
121
- write(index, typed);
122
- if (typed !== "" && index < length - 1) focusBox(index + 1);
170
+ const value = target.value;
171
+ // One key pressed in a box already holding a character: the box holds
172
+ // both, and the one just typed is what counts.
173
+ const typed =
174
+ event instanceof InputEvent &&
175
+ event.inputType === "insertText" &&
176
+ event.data !== null &&
177
+ [...event.data].length === 1
178
+ ? event.data
179
+ : undefined;
180
+ if ([...value].length > 1 && typed === undefined) {
181
+ // A whole code at once: autofill, a password manager, an IME.
182
+ spread(index, value);
183
+ return;
184
+ }
185
+ const character = typed ?? value;
186
+ const next = [...characters()];
187
+ next[index] = character;
188
+ if (!accepts(next)) {
189
+ target.value = characters()[index] ?? "";
190
+ return;
191
+ }
192
+ target.value = character;
193
+ commit(next);
194
+ if (character !== "" && index < length - 1) focusBox(index + 1);
123
195
  },
124
196
  onKeyDown(index, event) {
125
197
  if (event.key === "Backspace") {
@@ -144,25 +216,7 @@ export const InputOTP = component<InputOTPProps>((props) => {
144
216
  const pasted = event.clipboardData?.getData("text") ?? "";
145
217
  if (pasted === "") return;
146
218
  event.preventDefault();
147
-
148
- const next = [...characters()];
149
- let cursor = index;
150
- for (const character of pasted) {
151
- if (cursor >= length) break;
152
- next[cursor] = character;
153
- cursor += 1;
154
- }
155
- commit(next);
156
-
157
- // Reflect into the DOM: the boxes are uncontrolled between keystrokes,
158
- // so writing the signal alone would leave the pasted characters
159
- // invisible.
160
- const inputs = boxes();
161
- next.forEach((character, position) => {
162
- const input = inputs[position];
163
- if (input !== undefined) input.value = character;
164
- });
165
- focusBox(Math.min(cursor, length - 1));
219
+ spread(index, pasted);
166
220
  },
167
221
  });
168
222
 
@@ -209,9 +263,9 @@ export const InputOTPSlot = component<InputOTPSlotProps>((props) => {
209
263
  data-slot="input-otp-slot"
210
264
  data-otp-index="${index}"
211
265
  type="text"
212
- inputmode="numeric"
266
+ inputmode="${otp.inputMode}"
213
267
  autocomplete="${index === 0 ? "one-time-code" : "off"}"
214
- maxlength="1"
268
+ maxlength="${otp.length}"
215
269
  aria-label="${otp.slotLabel(index + 1, otp.length)}"
216
270
  ?disabled="${() => otp.disabled()}"
217
271
  class="${() => cn(slotClasses, read(props.class))}"
@@ -117,14 +117,20 @@ export interface ResizablePanelProps {
117
117
  * share and the second takes the rest. The parts are upstream's so a layout
118
118
  * written against them reads the same; a third panel would simply have no
119
119
  * share of its own.
120
+ *
121
+ * The share is written through the CSSOM (`.style`), never as a `style`
122
+ * attribute: a Content-Security-Policy without `'unsafe-inline'` blocks the
123
+ * attribute, and the CSSOM is not subject to it. A property is not written by
124
+ * the server, so until hydration both panes carry `flex-1` and split the room
125
+ * evenly — the right layout for the default share, and never a collapsed one.
120
126
  */
121
127
  export const ResizablePanel = component<ResizablePanelProps>((props) => {
122
128
  const group = inject(ResizableContext);
123
129
  const first = group.claimPanel() === 1;
124
130
  return html`<div
125
131
  data-slot="resizable-panel"
126
- class="${() => cn("overflow-hidden", first ? "" : "flex-1", read(props.class))}"
127
- style="${() => (first ? `flex: 0 0 ${group.size()}%` : "")}"
132
+ class="${() => cn("flex-1 overflow-hidden", read(props.class))}"
133
+ .style="${() => (first ? `flex: 0 0 ${group.size()}%` : "")}"
128
134
  >${slot(props.children)}</div>`;
129
135
  });
130
136
 
@@ -133,6 +133,9 @@ export {
133
133
  type InputOTPSeparatorProps,
134
134
  InputOTPSlot,
135
135
  type InputOTPSlotProps,
136
+ REGEXP_ONLY_CHARS,
137
+ REGEXP_ONLY_DIGITS,
138
+ REGEXP_ONLY_DIGITS_AND_CHARS,
136
139
  } from "./InputOTP.js";
137
140
  export {
138
141
  Item,
@@ -33,7 +33,6 @@ import {
33
33
  createContext,
34
34
  html,
35
35
  inject,
36
- onUnmount,
37
36
  provide,
38
37
  type TemplateResult,
39
38
  } from "@c9up/aurora";
@@ -46,7 +45,7 @@ import { fadeInOut, zoomInOut } from "../lib/motion.js";
46
45
  import { type Reactive, read } from "../lib/props.js";
47
46
  import { controllable } from "../primitives/controllable.js";
48
47
  import { modalSurface } from "../primitives/modalSurface.js";
49
- import { portal } from "../primitives/portal.js";
48
+ import { portalOnMount } from "../primitives/portal.js";
50
49
  import { dialogBackdropClasses } from "./Dialog.js";
51
50
 
52
51
  const panelClasses =
@@ -226,11 +225,10 @@ export interface AlertDialogPortalProps {
226
225
  * than standing in as a passthrough.
227
226
  */
228
227
  export const AlertDialogPortal = component<AlertDialogPortalProps>((props) => {
229
- const mounted = portal(html`${slot(props.children)}`, {
228
+ portalOnMount(html`${slot(props.children)}`, {
230
229
  container: props.container,
230
+ slot: "alert-dialog-portal",
231
231
  });
232
- mounted.host.setAttribute("data-slot", "alert-dialog-portal");
233
- onUnmount(() => mounted.close());
234
232
  return html``;
235
233
  });
236
234