@krak-stack/registry 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @krak-stack/registry
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9f63def: Add a restricted typed Cron Expression Editor with automatic spacing and per-field validation, and a numeric Phone Number Input with live formatting, protected calling codes and searchable countries. Include bilingual guides and interactive previews. Keep scheduling, phone verification and persistence application-owned.
8
+
9
+ ## 0.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 8d543bf: Add Image Crop Editor and Timezone Select as standalone components with English/French guides and interactive previews. Timezone Select composes the existing Virtualized Combobox with a code-only continent prop (North America by default), local times, UTC offsets and browser-time comparisons. Existing registry entries remain unchanged.
14
+
3
15
  ## 0.6.0
4
16
 
5
17
  ### Minor Changes
@@ -0,0 +1,14 @@
1
+ export { CronDraftSchema, formatCronDraft, } from "./cron-expression-editor.schema.js";
2
+ export declare const getCronPreview: (expression: string, timeZone: string, referenceTime: Date, count?: number) => readonly Date[] | null;
3
+ export type CronExpressionEditorProps = {
4
+ value: string;
5
+ onValueChange: (value: string) => void;
6
+ timeZone: string;
7
+ /** Explicit instant keeps server rendering and DST previews reproducible. */
8
+ referenceTime: Date;
9
+ locale?: string;
10
+ label?: string;
11
+ name?: string;
12
+ disabled?: boolean;
13
+ };
14
+ export declare const CronExpressionEditor: ({ value, onValueChange, timeZone, referenceTime, locale, label, name, disabled, }: CronExpressionEditorProps) => import("react").JSX.Element;
@@ -0,0 +1,206 @@
1
+ // ../../src/components/ui/cron-expression-editor.tsx
2
+ import { useId, useLayoutEffect, useRef } from "react";
3
+ import { Effect as Effect2, Option as Option2 } from "effect";
4
+ import { CronExpressionParser as CronExpressionParser2 } from "cron-parser";
5
+
6
+ // ../../src/components/ui/input.tsx
7
+ import { Input as InputPrimitive } from "@base-ui/react/input";
8
+
9
+ // ../../src/lib/utils.ts
10
+ import { cn } from "cn";
11
+
12
+ // ../../src/components/ui/input.tsx
13
+ import { jsx } from "react/jsx-runtime";
14
+ function Input({ className, type, ...props }) {
15
+ return /* @__PURE__ */ jsx(InputPrimitive, {
16
+ type,
17
+ "data-slot": "input",
18
+ className: cn("h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-2.5 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className),
19
+ ...props
20
+ });
21
+ }
22
+
23
+ // ../../src/components/ui/cron-expression-editor.tsx
24
+ import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
25
+
26
+ // ../../src/components/ui/cron-expression-editor.schema.ts
27
+ import { Effect, Option, Schema } from "effect";
28
+ import { CronExpressionParser } from "cron-parser";
29
+ var acceptsField = (token, index) => {
30
+ const fields = ["*", "*", "*", "*", "*"];
31
+ fields[index] = token;
32
+ return Option.isSome(Effect.runSync(Effect.option(Effect.try(() => CronExpressionParser.parse(fields.join(" "))))));
33
+ };
34
+ var CronDraftSchema = Schema.Struct({
35
+ text: Schema.String.check(Schema.isPattern(/^[\d*/,\- ]*$/), Schema.isMaxLength(150)),
36
+ cursor: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))
37
+ }).check(Schema.makeFilter(({ text, cursor }) => {
38
+ if (!text)
39
+ return true;
40
+ const fields = text.split(" ");
41
+ if (fields.length > 5)
42
+ return false;
43
+ const active = text.slice(0, cursor).split(" ").length - 1;
44
+ return fields.every((token, index) => {
45
+ if (acceptsField(token, index))
46
+ return true;
47
+ if (index !== active || /\/0+$/.test(token))
48
+ return false;
49
+ if (!token)
50
+ return index === fields.length - 1;
51
+ return Array.from({ length: 60 }, (_, number) => String(number)).concat("*").some((suffix) => acceptsField(`${token}${suffix}`, index));
52
+ });
53
+ })).annotate({ identifier: "CronDraft" });
54
+ var formatCronDraft = (text, cursor = text.length) => {
55
+ const normalized = text.replace(/\s+/g, " ").trimStart();
56
+ const normalizedCursor = text.slice(0, cursor).replace(/\s+/g, " ").trimStart().length;
57
+ return Schema.is(CronDraftSchema)({
58
+ text: normalized,
59
+ cursor: normalizedCursor
60
+ }) ? normalized : null;
61
+ };
62
+
63
+ // ../../src/components/ui/cron-expression-editor.tsx
64
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
65
+ var getCronPreview = (expression, timeZone, referenceTime, count = 5) => {
66
+ if (expression.trim().split(/\s+/).length !== 5 || !Number.isFinite(referenceTime.getTime()) || !Number.isInteger(count) || count < 1 || count > 20)
67
+ return null;
68
+ const result = Effect2.runSync(Effect2.option(Effect2.try(() => {
69
+ new Intl.DateTimeFormat("en", { timeZone }).format(referenceTime);
70
+ const interval = CronExpressionParser2.parse(expression, {
71
+ currentDate: referenceTime,
72
+ tz: timeZone
73
+ });
74
+ return Array.from({ length: count }, () => interval.next().toDate());
75
+ })));
76
+ return Option2.getOrNull(result);
77
+ };
78
+ var CronExpressionEditor = ({
79
+ value,
80
+ onValueChange,
81
+ timeZone,
82
+ referenceTime,
83
+ locale,
84
+ label,
85
+ name,
86
+ disabled
87
+ }) => {
88
+ const id = useId();
89
+ const language = useKrakstackLocale(locale);
90
+ const french = language.startsWith("fr");
91
+ const dates = getCronPreview(value, timeZone, referenceTime);
92
+ const selection = useRef(null);
93
+ useLayoutEffect(() => {
94
+ const pending = selection.current;
95
+ if (!pending)
96
+ return;
97
+ selection.current = null;
98
+ pending.element.setSelectionRange(pending.position, pending.position);
99
+ });
100
+ const firstRun = dates?.[0];
101
+ return /* @__PURE__ */ jsxs("div", {
102
+ className: "grid min-w-0 gap-2",
103
+ children: [
104
+ /* @__PURE__ */ jsx2("label", {
105
+ htmlFor: id,
106
+ className: "text-sm font-medium",
107
+ children: label ?? (french ? "Expression cron" : "Cron expression")
108
+ }),
109
+ /* @__PURE__ */ jsx2(Input, {
110
+ id,
111
+ name,
112
+ value,
113
+ disabled,
114
+ autoComplete: "off",
115
+ autoCapitalize: "off",
116
+ spellCheck: false,
117
+ placeholder: "*/15 9 * * 1-5",
118
+ className: "font-mono tracking-wide",
119
+ "aria-invalid": !dates,
120
+ "aria-describedby": `${id}-help`,
121
+ onKeyDown: (event) => {
122
+ if (!event.ctrlKey && !event.metaKey && !event.altKey && event.key.length === 1 && !/[\d*/,\- ]/.test(event.key))
123
+ event.preventDefault();
124
+ },
125
+ onChange: (event) => {
126
+ const raw = event.target.value;
127
+ const cursor = event.target.selectionStart ?? raw.length;
128
+ const next = formatCronDraft(raw, cursor);
129
+ if (next === null)
130
+ return;
131
+ selection.current = {
132
+ element: event.target,
133
+ position: raw.slice(0, cursor).replace(/\s+/g, " ").trimStart().length
134
+ };
135
+ onValueChange(next);
136
+ }
137
+ }),
138
+ /* @__PURE__ */ jsx2("p", {
139
+ id: `${id}-help`,
140
+ className: "text-muted-foreground text-xs",
141
+ children: french ? "Minute · heure · jour du mois · mois · jour de la semaine" : "Minute · hour · day of month · month · day of week"
142
+ }),
143
+ dates && firstRun ? /* @__PURE__ */ jsxs("details", {
144
+ className: "text-muted-foreground min-w-0 text-xs",
145
+ children: [
146
+ /* @__PURE__ */ jsxs("summary", {
147
+ className: "cursor-pointer rounded-sm outline-offset-4",
148
+ children: [
149
+ /* @__PURE__ */ jsx2("span", {
150
+ className: "text-foreground font-medium",
151
+ children: french ? "Prochaines exécutions" : "Next runs"
152
+ }),
153
+ " · ",
154
+ /* @__PURE__ */ jsx2("time", {
155
+ dateTime: firstRun.toISOString(),
156
+ title: timeZone,
157
+ children: new Intl.DateTimeFormat(language, {
158
+ timeZone,
159
+ month: "short",
160
+ day: "numeric",
161
+ hour: "2-digit",
162
+ minute: "2-digit",
163
+ timeZoneName: "short"
164
+ }).format(firstRun)
165
+ }),
166
+ " ",
167
+ /* @__PURE__ */ jsxs("span", {
168
+ children: [
169
+ "+",
170
+ dates.length - 1
171
+ ]
172
+ })
173
+ ]
174
+ }),
175
+ /* @__PURE__ */ jsx2("p", {
176
+ className: "mt-2 break-all",
177
+ children: timeZone
178
+ }),
179
+ /* @__PURE__ */ jsx2("ol", {
180
+ className: "mt-1 grid gap-1",
181
+ children: dates.map((date) => /* @__PURE__ */ jsx2("li", {
182
+ children: /* @__PURE__ */ jsx2("time", {
183
+ dateTime: date.toISOString(),
184
+ children: new Intl.DateTimeFormat(language, {
185
+ timeZone,
186
+ dateStyle: "medium",
187
+ timeStyle: "long"
188
+ }).format(date)
189
+ })
190
+ }, date.toISOString()))
191
+ })
192
+ ]
193
+ }) : /* @__PURE__ */ jsx2("p", {
194
+ role: "status",
195
+ className: "text-destructive text-sm",
196
+ children: french ? "Complétez les cinq champs. Si la règle est complète, vérifiez le fuseau, la date et les prochaines exécutions possibles." : "Complete all five fields. If the rule is complete, check the time zone, reference date and possible next runs."
197
+ })
198
+ ]
199
+ });
200
+ };
201
+ export {
202
+ CronDraftSchema,
203
+ CronExpressionEditor,
204
+ formatCronDraft,
205
+ getCronPreview
206
+ };
@@ -0,0 +1,7 @@
1
+ import { Schema } from "effect";
2
+ /** The active field may be unfinished, but must still be completable. */
3
+ export declare const CronDraftSchema: Schema.Struct<{
4
+ readonly text: Schema.String;
5
+ readonly cursor: Schema.Int;
6
+ }>;
7
+ export declare const formatCronDraft: (text: string, cursor?: number) => string | null;
@@ -0,0 +1,41 @@
1
+ export type ImageCropState = {
2
+ x: number;
3
+ y: number;
4
+ zoom: number;
5
+ rotation: 0 | 90 | 180 | 270;
6
+ };
7
+ export type ImageCropEditorMessages = {
8
+ zoom: string;
9
+ horizontal: string;
10
+ vertical: string;
11
+ rotate: string;
12
+ reset: string;
13
+ export: string;
14
+ loading: string;
15
+ loadError: string;
16
+ help: string;
17
+ exportError: string;
18
+ };
19
+ export type ImageCropEditorProps = {
20
+ src: string;
21
+ label: string;
22
+ value: ImageCropState;
23
+ onValueChange: (value: ImageCropState) => void;
24
+ onExport: (blob: Blob) => void | Promise<void>;
25
+ aspectRatio?: number;
26
+ maxOutputSize?: number;
27
+ disabled?: boolean;
28
+ className?: string;
29
+ locale?: string;
30
+ messages?: Partial<Record<string, Partial<ImageCropEditorMessages>>>;
31
+ };
32
+ /** Coordinates are in rotated source pixels; x/y state is a percentage of available travel. */
33
+ export declare const getImageCropGeometry: (width: number, height: number, value: ImageCropState, aspectRatio?: number) => {
34
+ x: number;
35
+ y: number;
36
+ width: number;
37
+ height: number;
38
+ sourceWidth: number;
39
+ sourceHeight: number;
40
+ };
41
+ export declare const ImageCropEditor: (props: ImageCropEditorProps) => import("react").JSX.Element;