@bettercms-ai/kit 3.1.15 → 3.1.17
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/dist/controls/index.js +2 -2
- package/dist/controls/number.d.ts +5 -0
- package/dist/controls/number.js +20 -3
- package/dist/controls/number.js.map +1 -1
- package/dist/controls/rich-text/dom.d.ts +3 -0
- package/dist/controls/rich-text/dom.js +6 -1
- package/dist/controls/rich-text/dom.js.map +1 -1
- package/dist/controls/rich-text/editor.js +6 -4
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/ops.d.ts +2 -2
- package/dist/controls/rich-text/ops.js +28 -7
- package/dist/controls/rich-text/ops.js.map +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/controls/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { JsonControl } from "./json.js";
|
|
|
6
6
|
import { CONTROLS } from "../engine/kit-field.js";
|
|
7
7
|
import { EmailControl, SlugControl, SlugGenerate, StringControl, TEXT_FOCUS, TextControl, UrlControl, slugSource, slugTidy, slugTyping, str } from "./text.js";
|
|
8
8
|
import { ColorControl, HEX_COLOR, pickerHex } from "./color.js";
|
|
9
|
-
import { NUMBER_SCALE, NumberControl, PlainNumber, RatingControl, ratingScale, snapRating, toNum } from "./number.js";
|
|
9
|
+
import { NUMBER_SCALE, NumberControl, PlainNumber, RatingControl, ratingScale, snapRating, toNum, ungroupNumber } from "./number.js";
|
|
10
10
|
import { C1_ACTIONS, C1_CONTROLS, registerC1Controls } from "./c1.js";
|
|
11
11
|
import { UnknownValueNote } from "./unknown-value.js";
|
|
12
12
|
import { BooleanControl, MultiSelectControl, SelectControl, TagsControl, optionIcons, tagRefusal, useOwnDescription } from "./choice.js";
|
|
@@ -34,6 +34,6 @@ function registerKitControls() {
|
|
|
34
34
|
CONTROLS.button = ButtonControl;
|
|
35
35
|
}
|
|
36
36
|
//#endregion
|
|
37
|
-
export { BUTTON_ICONS, BooleanControl, ButtonControl, ButtonIconPicker, ButtonLinkEditor, ButtonPreview, ButtonScreen, ButtonStyleGrid, C1_ACTIONS, C1_CONTROLS, C2_CONTROLS, CodeControl, CodeDialogField, CodeSurface, ColorControl, ComponentSlotControl, DateControl, EmailControl, FileControl, FormPickerControl, GalleryControl, HEX_COLOR, IconControl, IconPicker, IconValueGlyph, ImageControl, JsonControl, LINK_TYPES, LinkControl, LinkField, LinkForm, LinkLine, LinkOptions, LinkPicker, LinkPopoverBody, LinkQuickEdit, LocationControl, MediaPicker, MiniCalendar, MultiSelectControl, NUMBER_SCALE, NumberControl, PlainNumber, REL_ITEMS, RT_PROSE, RatingControl, RefThumb, ReferenceControl, ReferencesControl, RichTextControl, RichTextEditor, RichTextExpandAction, STYLE_ITEMS, ScaleControl, ScaleSlider, SectionAnchorsProvider, SelectControl, SlotDepthContext, SlotPicker, SlugControl, SlugGenerate, StringControl, StyleGlyph, TARGET_KEYS, TEXT_FOCUS, TableControl, TableFrame, TableFullScreenAction, TagsControl, TextControl, UnknownValueNote, UnreadableValue, UrlControl, VideoControl, VideoPreview, acceptsFile, cropChoice, describeLink, detectType, fileNameFromUrl, fileTarget, finalizeLink, findTarget, formatBytes, fromAsset, hasLink, hrefOf, isFormOnly, isVideoUrl, jsonProblem, linkIcon, linkProblem, linkShapeOf, linkText, locationFromDraft, lookLabel, lookOf, nextButton, normImage, normLink, optionIcons, pickerHex, ratingScale, referenceNoun, registerC1Controls, registerC2Controls, registerKitControls, slugSource, slugTidy, slugTyping, snapRating, storedLink, str, tagRefusal, toNum, useLinkTargets, useOwnDescription, useReferenceRecords, useUpload, videoProvider, withCrop, withTarget, withText, youTubeId };
|
|
37
|
+
export { BUTTON_ICONS, BooleanControl, ButtonControl, ButtonIconPicker, ButtonLinkEditor, ButtonPreview, ButtonScreen, ButtonStyleGrid, C1_ACTIONS, C1_CONTROLS, C2_CONTROLS, CodeControl, CodeDialogField, CodeSurface, ColorControl, ComponentSlotControl, DateControl, EmailControl, FileControl, FormPickerControl, GalleryControl, HEX_COLOR, IconControl, IconPicker, IconValueGlyph, ImageControl, JsonControl, LINK_TYPES, LinkControl, LinkField, LinkForm, LinkLine, LinkOptions, LinkPicker, LinkPopoverBody, LinkQuickEdit, LocationControl, MediaPicker, MiniCalendar, MultiSelectControl, NUMBER_SCALE, NumberControl, PlainNumber, REL_ITEMS, RT_PROSE, RatingControl, RefThumb, ReferenceControl, ReferencesControl, RichTextControl, RichTextEditor, RichTextExpandAction, STYLE_ITEMS, ScaleControl, ScaleSlider, SectionAnchorsProvider, SelectControl, SlotDepthContext, SlotPicker, SlugControl, SlugGenerate, StringControl, StyleGlyph, TARGET_KEYS, TEXT_FOCUS, TableControl, TableFrame, TableFullScreenAction, TagsControl, TextControl, UnknownValueNote, UnreadableValue, UrlControl, VideoControl, VideoPreview, acceptsFile, cropChoice, describeLink, detectType, fileNameFromUrl, fileTarget, finalizeLink, findTarget, formatBytes, fromAsset, hasLink, hrefOf, isFormOnly, isVideoUrl, jsonProblem, linkIcon, linkProblem, linkShapeOf, linkText, locationFromDraft, lookLabel, lookOf, nextButton, normImage, normLink, optionIcons, pickerHex, ratingScale, referenceNoun, registerC1Controls, registerC2Controls, registerKitControls, slugSource, slugTidy, slugTyping, snapRating, storedLink, str, tagRefusal, toNum, ungroupNumber, useLinkTargets, useOwnDescription, useReferenceRecords, useUpload, videoProvider, withCrop, withTarget, withText, youTubeId };
|
|
38
38
|
|
|
39
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -5,6 +5,11 @@ export declare const NUMBER_SCALE: {
|
|
|
5
5
|
control?: ComponentType<ControlProps>;
|
|
6
6
|
};
|
|
7
7
|
export declare const toNum: (v: unknown) => number | null;
|
|
8
|
+
/**
|
|
9
|
+
* GAP-203: a pasted number with thousands separators ("1,234.5", "12,000") read as the number it is. Only the
|
|
10
|
+
* unambiguous form (groups of three after a comma, a point for decimals); anything else is not guessed at.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ungroupNumber: (text: string) => string | null;
|
|
8
13
|
export declare function NumberControl(p: ControlProps): import("react/jsx-runtime").JSX.Element;
|
|
9
14
|
export declare function PlainNumber({ field, value, onChange, readOnly, id, invalid, onBlur }: ControlProps): import("react/jsx-runtime").JSX.Element;
|
|
10
15
|
/** Prod's rating scale, from the field's numeric bounds (0 · 5 · 1 unset). */
|
package/dist/controls/number.js
CHANGED
|
@@ -25,6 +25,15 @@ var toNum = (v) => typeof v === "number" && Number.isFinite(v) ? v : typeof v ==
|
|
|
25
25
|
/** What a keystroke may leave in a number box: an optional minus, digits, one decimal point. */
|
|
26
26
|
var NUMBER_TYPING = /^-?\d*\.?\d*$/;
|
|
27
27
|
var decimals = (n) => (String(n).split(".")[1] ?? "").length;
|
|
28
|
+
/**
|
|
29
|
+
* GAP-203: a pasted number with thousands separators ("1,234.5", "12,000") read as the number it is. Only the
|
|
30
|
+
* unambiguous form (groups of three after a comma, a point for decimals); anything else is not guessed at.
|
|
31
|
+
*/
|
|
32
|
+
var ungroupNumber = (text) => {
|
|
33
|
+
const t = text.trim();
|
|
34
|
+
if (NUMBER_TYPING.test(t)) return t;
|
|
35
|
+
return /^-?\d{1,3}(,\d{3})+(\.\d+)?$/.test(t) ? t.replace(/,/g, "") : null;
|
|
36
|
+
};
|
|
28
37
|
function NumberControl(p) {
|
|
29
38
|
if (!fieldScale(p.field)) return /* @__PURE__ */ jsx(PlainNumber, { ...p });
|
|
30
39
|
const Scale = NUMBER_SCALE.control ?? FallbackControl;
|
|
@@ -43,6 +52,7 @@ function PlainNumber({ field, value, onChange, readOnly, id, invalid, onBlur })
|
|
|
43
52
|
};
|
|
44
53
|
const [draft, setDraft] = React.useState(null);
|
|
45
54
|
const [note, setNote] = React.useState(null);
|
|
55
|
+
const pasted = React.useRef(false);
|
|
46
56
|
const start = React.useRef(null);
|
|
47
57
|
const unit = field.numeric?.unit;
|
|
48
58
|
const commit = () => {
|
|
@@ -68,9 +78,16 @@ function PlainNumber({ field, value, onChange, readOnly, id, invalid, onBlur })
|
|
|
68
78
|
"aria-invalid": invalid,
|
|
69
79
|
placeholder: field.placeholder ?? "0",
|
|
70
80
|
onWheel: (e) => e.currentTarget.blur(),
|
|
81
|
+
onPaste: () => pasted.current = true,
|
|
71
82
|
onChange: (e) => {
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
const wasPaste = pasted.current;
|
|
84
|
+
pasted.current = false;
|
|
85
|
+
const text = ungroupNumber(e.target.value);
|
|
86
|
+
if (text === null) {
|
|
87
|
+
if (wasPaste) setNote(`“${e.target.value.trim()}” isn't a number, so it isn't pasted. Use digits, like 1234.5.`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
setDraft(text);
|
|
74
91
|
setNote(null);
|
|
75
92
|
},
|
|
76
93
|
onBlur: () => {
|
|
@@ -216,6 +233,6 @@ function RatingControl({ field, value, onChange, readOnly, id, invalid, onBlur }
|
|
|
216
233
|
});
|
|
217
234
|
}
|
|
218
235
|
//#endregion
|
|
219
|
-
export { NUMBER_SCALE, NumberControl, PlainNumber, RatingControl, ratingScale, snapRating, toNum };
|
|
236
|
+
export { NUMBER_SCALE, NumberControl, PlainNumber, RatingControl, ratingScale, snapRating, toNum, ungroupNumber };
|
|
220
237
|
|
|
221
238
|
//# sourceMappingURL=number.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","names":[],"sources":["../../src/controls/number.tsx"],"sourcesContent":["/**\n * NUMBER — a plain input, NO stepper (prod CPO-068), V2 HEAD 9829bf1 kit/controls/number.tsx, DESIGN §8.4.\n * ↑/↓ step (Shift ×10), the value commits on blur or Enter, clamped to min/max and rounded to the step's precision only when the schema sets a step (V2 rounds to a default step of 1; prod never rounds, so a typed 2.5 stays 2.5);\n * the unit suffix scrubs on drag (Shift ×10); the wheel never changes a value (it blurs).\n * A number with a scale (`field.scale`, or `layout: \"slider\"` + min/max) is the scale control, which the choice lane\n * registers in NUMBER_SCALE; a host that never registered it edits the raw value (FallbackControl), never a plain box.\n * RATING — stars across the prod scale (config.min 0 · max 5 · step 1 unset) plus a number box for half steps.\n *\n * Stored shapes (prod `number`, `typeof === \"number\"`): a number, or null when cleared. A rating stays on its scale\n * (ratingToProd refuses anything off it), so the control only ever writes a step of the scale or null.\n */\nimport * as React from \"react\";\nimport type { ComponentType } from \"react\";\nimport { IconStarFilled } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitEnv } from \"../context\";\nimport { fieldScale } from \"../schema/scale\";\nimport { FallbackControl } from \"../engine/kit-field\";\nimport { Tooltip } from \"../ui/overlay\";\nimport type { ControlProps } from \"../types\";\nimport { TEXT_FOCUS } from \"./text\";\n\n/** Registered by the choice / scale lane: the control for a number with a scale. */\nexport const NUMBER_SCALE: { control?: ComponentType<ControlProps> } = {};\n\nexport const toNum = (v: unknown): number | null =>\n typeof v === \"number\" && Number.isFinite(v) ? v : typeof v === \"string\" && v.trim() !== \"\" && Number.isFinite(Number(v)) ? Number(v) : null;\n/** What a keystroke may leave in a number box: an optional minus, digits, one decimal point. */\nconst NUMBER_TYPING = /^-?\\d*\\.?\\d*$/;\nconst decimals = (n: number) => (String(n).split(\".\")[1] ?? \"\").length;\n\nexport function NumberControl(p: ControlProps) {\n if (!fieldScale(p.field)) return <PlainNumber {...p} />;\n const Scale = NUMBER_SCALE.control ?? FallbackControl;\n return <Scale {...p} />;\n}\n\nexport function PlainNumber({ field, value, onChange, readOnly, id, invalid, onBlur }: ControlProps) {\n const { variant } = useKitEnv();\n const n = toNum(value);\n const step = field.numeric?.step && field.numeric.step > 0 ? field.numeric.step : 1;\n const lo = field.numeric?.min ?? -Infinity;\n const hi = field.numeric?.max ?? Infinity;\n /* Round to the step only when the schema sets one: with no step a typed 2.5 stays 2.5 (prod NumberField never rounds).\n The rounding then only trims float noise from ↑/↓ (2.5 + 1 → 3.5, 0.1 + 0.2 → 0.3). */\n const setStep = !!field.numeric?.step && field.numeric.step > 0;\n const clamp = (x: number, from?: number) => {\n const precision = setStep ? decimals(step) : from == null ? null : Math.max(decimals(step), decimals(from));\n return Math.min(hi, Math.max(lo, precision == null ? x : Number(x.toFixed(precision))));\n };\n const [draft, setDraft] = React.useState<string | null>(null);\n const [note, setNote] = React.useState<string | null>(null);\n const start = React.useRef<{ x: number; v: number } | null>(null);\n const unit = field.numeric?.unit;\n const commit = () => {\n if (draft !== null) {\n const t = draft.trim();\n const x = Number(t);\n if (t === \"\") onChange(null);\n else if (t !== \"-\" && t !== \".\" && Number.isFinite(x)) {\n onChange(clamp(x));\n // a typed value past a bound is replaced by the bound: say which, until the next edit\n setNote(x > hi ? `Largest allowed is ${hi}.` : x < lo ? `Smallest allowed is ${lo}.` : null);\n }\n }\n setDraft(null);\n };\n return (\n <>\n <div\n data-slot=\"kit-number\"\n className={cn(\n \"flex w-full max-w-40 items-center rounded-kit-md border border-kit-line-strong bg-kit-field-bg transition-colors hover:border-kit-line-strong focus-within:border-kit-line-strong focus-within:bg-kit-field-bg\",\n variant === \"document\" ? \"h-9\" : \"h-8\",\n invalid && \"border-[var(--kit-field-invalid)]\",\n readOnly && \"opacity-80\",\n )}\n >\n <input\n id={id}\n inputMode=\"decimal\"\n value={draft ?? (n == null ? \"\" : String(n))}\n readOnly={readOnly}\n aria-invalid={invalid}\n placeholder={field.placeholder ?? \"0\"}\n onWheel={(e) => e.currentTarget.blur()}\n onChange={(e) => {\n if (!NUMBER_TYPING.test(e.target.value)) return;\n setDraft(e.target.value);\n setNote(null);\n }}\n onBlur={() => {\n commit();\n onBlur?.();\n }}\n onKeyDown={(e) => {\n if (readOnly) return;\n if (e.key === \"Enter\") e.currentTarget.blur();\n if (e.key === \"Escape\" && draft !== null) {\n e.stopPropagation();\n setDraft(null);\n }\n if (e.key === \"ArrowUp\" || e.key === \"ArrowDown\") {\n e.preventDefault();\n const base = draft !== null && Number.isFinite(Number(draft)) && draft.trim() !== \"\" ? Number(draft) : (n ?? 0);\n const d = (e.key === \"ArrowUp\" ? 1 : -1) * step * (e.shiftKey ? 10 : 1);\n setDraft(null);\n onChange(clamp(base + d, base));\n }\n }}\n className={cn(TEXT_FOCUS, \"tabular-nums h-full min-w-0 flex-1 bg-transparent px-2.5 text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3\")}\n />\n {unit ? (\n <Tooltip content={readOnly ? undefined : \"Drag to adjust · Shift for ×10\"}>\n <span\n data-slot=\"kit-number-unit\"\n onPointerDown={(e) => {\n if (readOnly) return;\n e.currentTarget.setPointerCapture?.(e.pointerId);\n start.current = { x: e.clientX, v: n ?? 0 };\n }}\n onPointerMove={(e) => {\n if (!start.current) return;\n const dx = e.clientX - start.current.x;\n const next = clamp(start.current.v + Math.round(dx / 4) * step * (e.shiftKey ? 10 : 1), start.current.v);\n if (next !== n) onChange(next);\n }}\n onPointerUp={() => (start.current = null)}\n onPointerCancel={() => (start.current = null)}\n className=\"flex h-full cursor-ew-resize select-none items-center pl-1 pr-2.5 text-kit-xs text-kit-fg-3 hover:text-kit-fg\"\n >\n {unit}\n </span>\n </Tooltip>\n ) : null}\n </div>\n {note ? (\n <p role=\"status\" data-slot=\"kit-number-note\" className=\"text-kit-xs leading-4 text-kit-fg-3\">\n {note}\n </p>\n ) : null}\n </>\n );\n}\n\n/** Prod's rating scale, from the field's numeric bounds (0 · 5 · 1 unset). */\nexport function ratingScale(field: ControlProps[\"field\"]) {\n const min = field.numeric?.min ?? 0;\n const max = field.numeric?.max ?? 5;\n const step = field.numeric?.step && field.numeric.step > 0 ? field.numeric.step : 1;\n return { min, max, step };\n}\n/** A typed rating snapped onto its scale; null when it cannot be (empty, not a number). */\nexport function snapRating(x: number, { min, max, step }: { min: number; max: number; step: number }): number {\n const snapped = min + Math.round((x - min) / step) * step;\n return Number(Math.min(max, Math.max(min, snapped)).toFixed(decimals(step)));\n}\n\nexport function RatingControl({ field, value, onChange, readOnly, id, invalid, onBlur }: ControlProps) {\n const scale = ratingScale(field);\n const stars = Math.max(1, Math.min(10, Math.ceil(scale.max)));\n const n = toNum(value);\n const [hover, setHover] = React.useState<number | null>(null);\n const [draft, setDraft] = React.useState<string | null>(null);\n const shown = hover ?? n ?? 0;\n // DK-024: one Tab stop (the checked star, else the first); arrows step it, Home / End jump, focus follows the pick\n const group = React.useRef<HTMLDivElement>(null);\n const current = n != null ? Math.min(stars, Math.max(1, Math.ceil(n))) : 0;\n const tabStop = current || 1;\n const step = (e: React.KeyboardEvent, i: number) => {\n const to =\n e.key === \"ArrowRight\" || e.key === \"ArrowUp\" ? Math.min(stars, i + 1)\n : e.key === \"ArrowLeft\" || e.key === \"ArrowDown\" ? Math.max(1, i - 1)\n : e.key === \"Home\" ? 1\n : e.key === \"End\" ? stars\n : null;\n if (to === null || readOnly) return;\n e.preventDefault();\n onChange(snapRating(to, scale));\n group.current?.querySelectorAll<HTMLButtonElement>('[role=\"radio\"]')[to - 1]?.focus();\n };\n const commit = () => {\n if (draft !== null) {\n const t = draft.trim();\n if (t === \"\") onChange(null);\n else if (Number.isFinite(Number(t)) && t !== \".\") onChange(snapRating(Number(t), scale));\n }\n setDraft(null);\n };\n return (\n <div className=\"flex items-center gap-3\">\n <div ref={group} role=\"radiogroup\" aria-label={`${field.title} rating`} className=\"flex items-center\" onMouseLeave={() => setHover(null)}>\n {Array.from({ length: stars }, (_, k) => k + 1).map((i) => {\n const fill = Math.max(0, Math.min(1, shown - (i - 1)));\n const pick = snapRating(i, scale);\n return (\n <button\n key={i}\n type=\"button\"\n role=\"radio\"\n aria-checked={n != null && Math.ceil(n) === i}\n aria-label={`${i} star${i > 1 ? \"s\" : \"\"}`}\n tabIndex={i === tabStop ? 0 : -1}\n onKeyDown={(e) => step(e, i)}\n disabled={readOnly}\n onMouseEnter={() => setHover(i)}\n onClick={() => onChange(pick)}\n className=\"relative flex size-7 items-center justify-center transition-transform hover:scale-110\"\n >\n <IconStarFilled className=\"size-[18px] text-kit-line-strong\" />\n <span className=\"absolute inset-0 flex items-center justify-center overflow-hidden\" style={{ clipPath: `inset(0 ${100 - fill * 100}% 0 0)` }}>\n <IconStarFilled className=\"size-[18px] text-kit-warning\" />\n </span>\n </button>\n );\n })}\n </div>\n <input\n id={id}\n inputMode=\"decimal\"\n value={draft ?? (n == null ? \"\" : String(n))}\n readOnly={readOnly}\n aria-invalid={invalid}\n placeholder=\"–\"\n onWheel={(e) => e.currentTarget.blur()}\n onChange={(e) => /^\\d*\\.?\\d*$/.test(e.target.value) && setDraft(e.target.value)}\n onBlur={() => {\n commit();\n onBlur?.();\n }}\n onKeyDown={(e) => e.key === \"Enter\" && e.currentTarget.blur()}\n className=\"tabular-nums h-7 w-12 rounded-kit-md border border-kit-line-strong bg-kit-field-bg px-2 text-kit-sm text-kit-fg outline-none hover:border-kit-line-strong focus:border-kit-line-strong focus:bg-kit-field-bg\"\n />\n <span className=\"text-kit-xs text-kit-fg-3\">out of {scale.max}</span>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAa,eAA0D,CAAC;AAExE,IAAa,SAAS,MACpB,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,IAAI,IAAI,OAAO,MAAM,YAAY,EAAE,KAAK,MAAM,MAAM,OAAO,SAAS,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI;;AAEzI,IAAM,gBAAgB;AACtB,IAAM,YAAY,OAAe,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,GAAA,CAAI;AAEhE,SAAgB,cAAc,GAAiB;CAC7C,IAAI,CAAC,WAAW,EAAE,KAAK,GAAG,OAAO,oBAAC,aAAD,EAAa,GAAI,EAAI,CAAA;CACtD,MAAM,QAAQ,aAAa,WAAW;CACtC,OAAO,oBAAC,OAAD,EAAO,GAAI,EAAI,CAAA;AACxB;AAEA,SAAgB,YAAY,EAAE,OAAO,OAAO,UAAU,UAAU,IAAI,SAAS,UAAwB;CACnG,MAAM,EAAE,YAAY,UAAU;CAC9B,MAAM,IAAI,MAAM,KAAK;CACrB,MAAM,OAAO,MAAM,SAAS,QAAQ,MAAM,QAAQ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U;MAXZ,UAAA,CAaE,oBAAC,gBAAD,EAAgB,WAAU,mCAAoC,CAAA,GAC9D,oBAAC,QAAD;OAAM,WAAU;OAAoE,OAAO,EAAE,UAAU,WAAW,MAAM,OAAO,IAAI,QAAQ;OACzI,UAAA,oBAAC,gBAAD,EAAgB,WAAU,+BAAgC,CAAA;MACtD,CAAA,CACA;KAhBD,GAAA,CAgBC;IAEZ,CAAC;GACE,CAAA;GACL,oBAAC,SAAD;IACM;IACJ,WAAU;IACV,OAAO,UAAU,KAAK,OAAO,KAAK,OAAO,CAAC;IAChC;IACV,gBAAc;IACd,aAAY;IACZ,UAAU,MAAM,EAAE,cAAc,KAAK;IACrC,WAAW,MAAM,cAAc,KAAK,EAAE,OAAO,KAAK,KAAK,SAAS,EAAE,OAAO,KAAK;IAC9E,cAAc;KACZ,OAAO;KACP,SAAS;IACX;IACA,YAAY,MAAM,EAAE,QAAQ,WAAW,EAAE,cAAc,KAAK;IAC5D,WAAU;GACX,CAAA;GACD,qBAAC,QAAD;IAAM,WAAU;IAAhB,UAAA,CAA4C,WAAQ,MAAM,GAAU;;EACjE;;AAET"}
|
|
1
|
+
{"version":3,"file":"number.js","names":[],"sources":["../../src/controls/number.tsx"],"sourcesContent":["/**\n * NUMBER — a plain input, NO stepper (prod CPO-068), V2 HEAD 9829bf1 kit/controls/number.tsx, DESIGN §8.4.\n * ↑/↓ step (Shift ×10), the value commits on blur or Enter, clamped to min/max and rounded to the step's precision only when the schema sets a step (V2 rounds to a default step of 1; prod never rounds, so a typed 2.5 stays 2.5);\n * the unit suffix scrubs on drag (Shift ×10); the wheel never changes a value (it blurs).\n * A number with a scale (`field.scale`, or `layout: \"slider\"` + min/max) is the scale control, which the choice lane\n * registers in NUMBER_SCALE; a host that never registered it edits the raw value (FallbackControl), never a plain box.\n * RATING — stars across the prod scale (config.min 0 · max 5 · step 1 unset) plus a number box for half steps.\n *\n * Stored shapes (prod `number`, `typeof === \"number\"`): a number, or null when cleared. A rating stays on its scale\n * (ratingToProd refuses anything off it), so the control only ever writes a step of the scale or null.\n */\nimport * as React from \"react\";\nimport type { ComponentType } from \"react\";\nimport { IconStarFilled } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitEnv } from \"../context\";\nimport { fieldScale } from \"../schema/scale\";\nimport { FallbackControl } from \"../engine/kit-field\";\nimport { Tooltip } from \"../ui/overlay\";\nimport type { ControlProps } from \"../types\";\nimport { TEXT_FOCUS } from \"./text\";\n\n/** Registered by the choice / scale lane: the control for a number with a scale. */\nexport const NUMBER_SCALE: { control?: ComponentType<ControlProps> } = {};\n\nexport const toNum = (v: unknown): number | null =>\n typeof v === \"number\" && Number.isFinite(v) ? v : typeof v === \"string\" && v.trim() !== \"\" && Number.isFinite(Number(v)) ? Number(v) : null;\n/** What a keystroke may leave in a number box: an optional minus, digits, one decimal point. */\nconst NUMBER_TYPING = /^-?\\d*\\.?\\d*$/;\nconst decimals = (n: number) => (String(n).split(\".\")[1] ?? \"\").length;\n/**\n * GAP-203: a pasted number with thousands separators (\"1,234.5\", \"12,000\") read as the number it is. Only the\n * unambiguous form (groups of three after a comma, a point for decimals); anything else is not guessed at.\n */\nexport const ungroupNumber = (text: string): string | null => {\n const t = text.trim();\n if (NUMBER_TYPING.test(t)) return t;\n return /^-?\\d{1,3}(,\\d{3})+(\\.\\d+)?$/.test(t) ? t.replace(/,/g, \"\") : null;\n};\n\nexport function NumberControl(p: ControlProps) {\n if (!fieldScale(p.field)) return <PlainNumber {...p} />;\n const Scale = NUMBER_SCALE.control ?? FallbackControl;\n return <Scale {...p} />;\n}\n\nexport function PlainNumber({ field, value, onChange, readOnly, id, invalid, onBlur }: ControlProps) {\n const { variant } = useKitEnv();\n const n = toNum(value);\n const step = field.numeric?.step && field.numeric.step > 0 ? field.numeric.step : 1;\n const lo = field.numeric?.min ?? -Infinity;\n const hi = field.numeric?.max ?? Infinity;\n /* Round to the step only when the schema sets one: with no step a typed 2.5 stays 2.5 (prod NumberField never rounds).\n The rounding then only trims float noise from ↑/↓ (2.5 + 1 → 3.5, 0.1 + 0.2 → 0.3). */\n const setStep = !!field.numeric?.step && field.numeric.step > 0;\n const clamp = (x: number, from?: number) => {\n const precision = setStep ? decimals(step) : from == null ? null : Math.max(decimals(step), decimals(from));\n return Math.min(hi, Math.max(lo, precision == null ? x : Number(x.toFixed(precision))));\n };\n const [draft, setDraft] = React.useState<string | null>(null);\n const [note, setNote] = React.useState<string | null>(null);\n const pasted = React.useRef(false);\n const start = React.useRef<{ x: number; v: number } | null>(null);\n const unit = field.numeric?.unit;\n const commit = () => {\n if (draft !== null) {\n const t = draft.trim();\n const x = Number(t);\n if (t === \"\") onChange(null);\n else if (t !== \"-\" && t !== \".\" && Number.isFinite(x)) {\n onChange(clamp(x));\n // a typed value past a bound is replaced by the bound: say which, until the next edit\n setNote(x > hi ? `Largest allowed is ${hi}.` : x < lo ? `Smallest allowed is ${lo}.` : null);\n }\n }\n setDraft(null);\n };\n return (\n <>\n <div\n data-slot=\"kit-number\"\n className={cn(\n \"flex w-full max-w-40 items-center rounded-kit-md border border-kit-line-strong bg-kit-field-bg transition-colors hover:border-kit-line-strong focus-within:border-kit-line-strong focus-within:bg-kit-field-bg\",\n variant === \"document\" ? \"h-9\" : \"h-8\",\n invalid && \"border-[var(--kit-field-invalid)]\",\n readOnly && \"opacity-80\",\n )}\n >\n <input\n id={id}\n inputMode=\"decimal\"\n value={draft ?? (n == null ? \"\" : String(n))}\n readOnly={readOnly}\n aria-invalid={invalid}\n placeholder={field.placeholder ?? \"0\"}\n onWheel={(e) => e.currentTarget.blur()}\n onPaste={() => (pasted.current = true)}\n onChange={(e) => {\n const wasPaste = pasted.current;\n pasted.current = false;\n const text = ungroupNumber(e.target.value);\n if (text === null) {\n // a stray key is simply not typed; a paste that is dropped says why (GAP-203)\n if (wasPaste) setNote(`“${e.target.value.trim()}” isn't a number, so it isn't pasted. Use digits, like 1234.5.`);\n return;\n }\n setDraft(text);\n setNote(null);\n }}\n onBlur={() => {\n commit();\n onBlur?.();\n }}\n onKeyDown={(e) => {\n if (readOnly) return;\n if (e.key === \"Enter\") e.currentTarget.blur();\n if (e.key === \"Escape\" && draft !== null) {\n e.stopPropagation();\n setDraft(null);\n }\n if (e.key === \"ArrowUp\" || e.key === \"ArrowDown\") {\n e.preventDefault();\n const base = draft !== null && Number.isFinite(Number(draft)) && draft.trim() !== \"\" ? Number(draft) : (n ?? 0);\n const d = (e.key === \"ArrowUp\" ? 1 : -1) * step * (e.shiftKey ? 10 : 1);\n setDraft(null);\n onChange(clamp(base + d, base));\n }\n }}\n className={cn(TEXT_FOCUS, \"tabular-nums h-full min-w-0 flex-1 bg-transparent px-2.5 text-kit-sm text-kit-fg outline-none placeholder:text-kit-fg-3\")}\n />\n {unit ? (\n <Tooltip content={readOnly ? undefined : \"Drag to adjust · Shift for ×10\"}>\n <span\n data-slot=\"kit-number-unit\"\n onPointerDown={(e) => {\n if (readOnly) return;\n e.currentTarget.setPointerCapture?.(e.pointerId);\n start.current = { x: e.clientX, v: n ?? 0 };\n }}\n onPointerMove={(e) => {\n if (!start.current) return;\n const dx = e.clientX - start.current.x;\n const next = clamp(start.current.v + Math.round(dx / 4) * step * (e.shiftKey ? 10 : 1), start.current.v);\n if (next !== n) onChange(next);\n }}\n onPointerUp={() => (start.current = null)}\n onPointerCancel={() => (start.current = null)}\n className=\"flex h-full cursor-ew-resize select-none items-center pl-1 pr-2.5 text-kit-xs text-kit-fg-3 hover:text-kit-fg\"\n >\n {unit}\n </span>\n </Tooltip>\n ) : null}\n </div>\n {note ? (\n <p role=\"status\" data-slot=\"kit-number-note\" className=\"text-kit-xs leading-4 text-kit-fg-3\">\n {note}\n </p>\n ) : null}\n </>\n );\n}\n\n/** Prod's rating scale, from the field's numeric bounds (0 · 5 · 1 unset). */\nexport function ratingScale(field: ControlProps[\"field\"]) {\n const min = field.numeric?.min ?? 0;\n const max = field.numeric?.max ?? 5;\n const step = field.numeric?.step && field.numeric.step > 0 ? field.numeric.step : 1;\n return { min, max, step };\n}\n/** A typed rating snapped onto its scale; null when it cannot be (empty, not a number). */\nexport function snapRating(x: number, { min, max, step }: { min: number; max: number; step: number }): number {\n const snapped = min + Math.round((x - min) / step) * step;\n return Number(Math.min(max, Math.max(min, snapped)).toFixed(decimals(step)));\n}\n\nexport function RatingControl({ field, value, onChange, readOnly, id, invalid, onBlur }: ControlProps) {\n const scale = ratingScale(field);\n const stars = Math.max(1, Math.min(10, Math.ceil(scale.max)));\n const n = toNum(value);\n const [hover, setHover] = React.useState<number | null>(null);\n const [draft, setDraft] = React.useState<string | null>(null);\n const shown = hover ?? n ?? 0;\n // DK-024: one Tab stop (the checked star, else the first); arrows step it, Home / End jump, focus follows the pick\n const group = React.useRef<HTMLDivElement>(null);\n const current = n != null ? Math.min(stars, Math.max(1, Math.ceil(n))) : 0;\n const tabStop = current || 1;\n const step = (e: React.KeyboardEvent, i: number) => {\n const to =\n e.key === \"ArrowRight\" || e.key === \"ArrowUp\" ? Math.min(stars, i + 1)\n : e.key === \"ArrowLeft\" || e.key === \"ArrowDown\" ? Math.max(1, i - 1)\n : e.key === \"Home\" ? 1\n : e.key === \"End\" ? stars\n : null;\n if (to === null || readOnly) return;\n e.preventDefault();\n onChange(snapRating(to, scale));\n group.current?.querySelectorAll<HTMLButtonElement>('[role=\"radio\"]')[to - 1]?.focus();\n };\n const commit = () => {\n if (draft !== null) {\n const t = draft.trim();\n if (t === \"\") onChange(null);\n else if (Number.isFinite(Number(t)) && t !== \".\") onChange(snapRating(Number(t), scale));\n }\n setDraft(null);\n };\n return (\n <div className=\"flex items-center gap-3\">\n <div ref={group} role=\"radiogroup\" aria-label={`${field.title} rating`} className=\"flex items-center\" onMouseLeave={() => setHover(null)}>\n {Array.from({ length: stars }, (_, k) => k + 1).map((i) => {\n const fill = Math.max(0, Math.min(1, shown - (i - 1)));\n const pick = snapRating(i, scale);\n return (\n <button\n key={i}\n type=\"button\"\n role=\"radio\"\n aria-checked={n != null && Math.ceil(n) === i}\n aria-label={`${i} star${i > 1 ? \"s\" : \"\"}`}\n tabIndex={i === tabStop ? 0 : -1}\n onKeyDown={(e) => step(e, i)}\n disabled={readOnly}\n onMouseEnter={() => setHover(i)}\n onClick={() => onChange(pick)}\n className=\"relative flex size-7 items-center justify-center transition-transform hover:scale-110\"\n >\n <IconStarFilled className=\"size-[18px] text-kit-line-strong\" />\n <span className=\"absolute inset-0 flex items-center justify-center overflow-hidden\" style={{ clipPath: `inset(0 ${100 - fill * 100}% 0 0)` }}>\n <IconStarFilled className=\"size-[18px] text-kit-warning\" />\n </span>\n </button>\n );\n })}\n </div>\n <input\n id={id}\n inputMode=\"decimal\"\n value={draft ?? (n == null ? \"\" : String(n))}\n readOnly={readOnly}\n aria-invalid={invalid}\n placeholder=\"–\"\n onWheel={(e) => e.currentTarget.blur()}\n onChange={(e) => /^\\d*\\.?\\d*$/.test(e.target.value) && setDraft(e.target.value)}\n onBlur={() => {\n commit();\n onBlur?.();\n }}\n onKeyDown={(e) => e.key === \"Enter\" && e.currentTarget.blur()}\n className=\"tabular-nums h-7 w-12 rounded-kit-md border border-kit-line-strong bg-kit-field-bg px-2 text-kit-sm text-kit-fg outline-none hover:border-kit-line-strong focus:border-kit-line-strong focus:bg-kit-field-bg\"\n />\n <span className=\"text-kit-xs text-kit-fg-3\">out of {scale.max}</span>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAa,eAA0D,CAAC;AAExE,IAAa,SAAS,MACpB,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,IAAI,IAAI,OAAO,MAAM,YAAY,EAAE,KAAK,MAAM,MAAM,OAAO,SAAS,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI;;AAEzI,IAAM,gBAAgB;AACtB,IAAM,YAAY,OAAe,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,GAAA,CAAI;;;;;AAKhE,IAAa,iBAAiB,SAAgC;CAC5D,MAAM,IAAI,K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AY,MAAM,EAAE,QAAQ,WAAW,EAAE,cAAc,KAAK;IAC5D,WAAU;GACX,CAAA;GACD,qBAAC,QAAD;IAAM,WAAU;IAAhB,UAAA,CAA4C,WAAQ,MAAM,GAAU;;EACjE;;AAET"}
|
|
@@ -314,4 +314,7 @@ export declare function editingHost(n: Node | null): HTMLElement | null;
|
|
|
314
314
|
/** A range's box. Browsers measure a collapsed caret as an empty rect, and some engines cannot measure ranges at all: then
|
|
315
315
|
* the box of the element the range sits in. */
|
|
316
316
|
export declare function rangeRect(r: Range, fallback: Element | null): DOMRect;
|
|
317
|
+
/** NEW-Q11-TB1: a menu is the editor's own when it sits inside one of `roots` (the editor box, its selection bubble) or
|
|
318
|
+
* one of their menu triggers is open (the popup itself is portalled to the body). Any other menu is the host's. */
|
|
319
|
+
export declare function ownsMenu(menu: Element, roots: (Element | null | undefined)[]): boolean;
|
|
317
320
|
export declare const isEmptyHtml: (html: string) => boolean;
|
|
@@ -1178,8 +1178,13 @@ function rangeRect(r, fallback) {
|
|
|
1178
1178
|
if (rect && (rect.width || rect.height)) return rect;
|
|
1179
1179
|
return ((r.startContainer.nodeType === 1 ? r.startContainer : r.startContainer.parentElement) ?? fallback ?? document.body).getBoundingClientRect();
|
|
1180
1180
|
}
|
|
1181
|
+
/** NEW-Q11-TB1: a menu is the editor's own when it sits inside one of `roots` (the editor box, its selection bubble) or
|
|
1182
|
+
* one of their menu triggers is open (the popup itself is portalled to the body). Any other menu is the host's. */
|
|
1183
|
+
function ownsMenu(menu, roots) {
|
|
1184
|
+
return roots.some((r) => !!r && (r.contains(menu) || !!r.querySelector("[aria-haspopup=\"menu\"][aria-expanded=\"true\"]")));
|
|
1185
|
+
}
|
|
1181
1186
|
var isEmptyHtml = (html) => !html.replace(/<(?!img|hr|figure|table|details|div data-rt)[^>]*>/g, "").replace(/ /g, "").trim();
|
|
1182
1187
|
//#endregion
|
|
1183
|
-
export { CALLOUT_TONES, IMAGE_ALIGNS, IMAGE_SIZES, ISLAND_KINDS, STORED_COLUMN_TYPES, TEXT_BLOCKS, cloneModel, closestBlock, colAttrs, colSettingsOf, columnSettings, createIsland, defaultModel, detectEmbed, detectKind, editingHost, editorRoundTrip, esc, escAttr, hydrate, isEmptyHtml, isValueType, parasToText, parseIsland, parseStoredTable, placeCaret, rangeRect, readImageFrame, renderStatic, renderStoredTable, rid, sanitize, serialize, textBeforeCaret, textToParas, topBlock, typeAttrOf, typedCellView, typedValueOf, typedWords };
|
|
1188
|
+
export { CALLOUT_TONES, IMAGE_ALIGNS, IMAGE_SIZES, ISLAND_KINDS, STORED_COLUMN_TYPES, TEXT_BLOCKS, cloneModel, closestBlock, colAttrs, colSettingsOf, columnSettings, createIsland, defaultModel, detectEmbed, detectKind, editingHost, editorRoundTrip, esc, escAttr, hydrate, isEmptyHtml, isValueType, ownsMenu, parasToText, parseIsland, parseStoredTable, placeCaret, rangeRect, readImageFrame, renderStatic, renderStoredTable, rid, sanitize, serialize, textBeforeCaret, textToParas, topBlock, typeAttrOf, typedCellView, typedValueOf, typedWords };
|
|
1184
1189
|
|
|
1185
1190
|
//# sourceMappingURL=dom.js.map
|