@r2digisolutions/components 0.21.32 → 0.21.33

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.
@@ -56,21 +56,34 @@
56
56
  let tipIndex = $state<number | null>(null);
57
57
 
58
58
  const values = $derived(data.map((d) => d.value));
59
- const domain = $derived(
60
- yMin !== undefined && yMax !== undefined
61
- ? { min: yMin, max: yMax }
62
- : scaleDomain(values)
63
- );
59
+ const domain = $derived.by(() => {
60
+ if (yMin !== undefined && yMax !== undefined) return { min: yMin, max: yMax };
61
+ const auto = scaleDomain(values);
62
+ /** Counts never go below zero unless the caller sets an explicit floor. */
63
+ if (yMin !== undefined) return { min: yMin, max: Math.max(auto.max, yMin + 1) };
64
+ if (values.length > 0 && Math.min(...values) >= 0 && auto.min < 0) {
65
+ return { min: 0, max: auto.max };
66
+ }
67
+ return auto;
68
+ });
64
69
  const points = $derived(mapPoints(values, W, height, pad, domain));
65
70
  const line = $derived(smooth ? smoothLinePath(points) : linearLinePath(points));
66
71
  const area = $derived(areaPath(line, points, height, pad));
67
72
 
73
+ const integerValues = $derived(values.every((v) => Number.isInteger(v)));
74
+
68
75
  const gridYs = $derived.by(() => {
69
76
  const { min, max } = domain;
70
- return [0, 0.5, 1].map((t) => ({
71
- y: pad.t + (1 - t) * (height - pad.t - pad.b),
72
- label: formatTick(min + t * (max - min))
73
- }));
77
+ return [0, 0.5, 1].map((t) => {
78
+ const raw = min + t * (max - min);
79
+ const label = integerValues
80
+ ? String(Math.round(raw))
81
+ : formatTick(raw);
82
+ return {
83
+ y: pad.t + (1 - t) * (height - pad.t - pad.b),
84
+ label
85
+ };
86
+ });
74
87
  });
75
88
 
76
89
  const tip = $derived.by(() => {
@@ -55,11 +55,15 @@
55
55
  let tipIndex = $state<number | null>(null);
56
56
 
57
57
  const allValues = $derived(series.flatMap((s) => s.values));
58
- const domain = $derived(
59
- yMin !== undefined && yMax !== undefined
60
- ? { min: yMin, max: yMax }
61
- : scaleDomain(allValues)
62
- );
58
+ const domain = $derived.by(() => {
59
+ if (yMin !== undefined && yMax !== undefined) return { min: yMin, max: yMax };
60
+ const auto = scaleDomain(allValues);
61
+ if (yMin !== undefined) return { min: yMin, max: Math.max(auto.max, yMin + 1) };
62
+ if (allValues.length > 0 && Math.min(...allValues) >= 0 && auto.min < 0) {
63
+ return { min: 0, max: auto.max };
64
+ }
65
+ return auto;
66
+ });
63
67
 
64
68
  const plotted = $derived(
65
69
  series.map((s, si) => {
@@ -74,12 +78,17 @@
74
78
  })
75
79
  );
76
80
 
81
+ const integerValues = $derived(allValues.every((v) => Number.isInteger(v)));
82
+
77
83
  const gridYs = $derived.by(() => {
78
84
  const { min, max } = domain;
79
- return [0, 0.5, 1].map((t) => ({
80
- y: pad.t + (1 - t) * (height - pad.t - pad.b),
81
- label: formatTick(min + t * (max - min))
82
- }));
85
+ return [0, 0.5, 1].map((t) => {
86
+ const raw = min + t * (max - min);
87
+ return {
88
+ y: pad.t + (1 - t) * (height - pad.t - pad.b),
89
+ label: integerValues ? String(Math.round(raw)) : formatTick(raw)
90
+ };
91
+ });
83
92
  });
84
93
 
85
94
  const tip = $derived.by(() => {
@@ -5,13 +5,23 @@ export function scaleDomain(values, padRatio = 0.08) {
5
5
  return { min: 0, max: 1 };
6
6
  let min = Math.min(...values);
7
7
  let max = Math.max(...values);
8
+ const nonNegative = min >= 0;
8
9
  if (min === max) {
9
- const bump = min === 0 ? 1 : Math.abs(min) * 0.05 || 1;
10
+ if (min === 0)
11
+ return { min: 0, max: 1 };
12
+ const bump = Math.abs(min) * 0.05 || 1;
10
13
  min -= bump;
11
14
  max += bump;
12
15
  }
13
- const span = max - min;
14
- return { min: min - span * padRatio, max: max + span * padRatio };
16
+ else {
17
+ const span = max - min;
18
+ min -= span * padRatio;
19
+ max += span * padRatio;
20
+ }
21
+ /** Counts / rates ≥ 0 should never show a negative floor (e.g. visits → -2.7). */
22
+ if (nonNegative && min < 0)
23
+ min = 0;
24
+ return { min, max };
15
25
  }
16
26
  export function mapPoints(values, width, height, pad = DEFAULT_PAD, domain) {
17
27
  if (values.length === 0)
@@ -62,7 +72,10 @@ export function tipAlign(leftPct) {
62
72
  return 'center';
63
73
  }
64
74
  export function formatTick(n, digits = 1) {
65
- if (Math.abs(n) >= 100)
75
+ if (!Number.isFinite(n))
76
+ return '0';
77
+ if (Math.abs(n) >= 100 || Number.isInteger(n))
66
78
  return String(Math.round(n));
67
- return n.toFixed(digits).replace(/\.0$/, '');
79
+ const fixed = n.toFixed(digits).replace(/\.0+$/, '').replace(/(\.\d*?)0+$/, '$1');
80
+ return fixed;
68
81
  }
@@ -58,30 +58,31 @@ export type ResolvedRemoteInputProps = {
58
58
  export declare function getRemoteFormId(action: string | undefined | null): string | null;
59
59
  /**
60
60
  * Resolve HTML input props for a field inside a Kit remote form.
61
- * Prefer a precomputed `formId` string so fields never touch Kit proxies.
62
61
  *
63
- * Kit requires names that end with `/${formId}` (from `.as()`), e.g.
64
- * `email/1p9kxmo/login_user` or `n:age/1p9kxmo/login_user`.
62
+ * Kit 2.70+ `.as()` emits the logical path only (`email`, `n:age`, `b:active`).
63
+ * The remote id lives on the form `action` (`?/remote=…`), not on each field name.
64
+ * Appending `/${formId}` breaks `convert_formdata` / `split_path` — especially with
65
+ * keyed instances (`.for(key)` → `…/"default"`), which surfaces as:
66
+ * `Invalid path status/…/updateProduct_remote/"default"`.
67
+ *
68
+ * `formId` is kept for call-site compatibility / legacy stripping in
69
+ * {@link parseRemoteFieldName}; it is not appended to `name`.
65
70
  */
66
- export declare function resolveRemoteInputProps(formId: string | null | undefined, logicalName: string | undefined, type?: string): ResolvedRemoteInputProps;
71
+ export declare function resolveRemoteInputProps(_formId: string | null | undefined, logicalName: string | undefined, type?: string): ResolvedRemoteInputProps;
67
72
  export type ParsedRemoteFieldName = {
68
73
  /** Field path for errors / `form.data` (`email`, `items[0].name`) */
69
74
  logicalName: string | undefined;
70
75
  /** Exact HTML `name` to put on the input (Kit-encoded or plain) */
71
76
  htmlName: string | undefined;
72
- /** True when `name` already includes `/formId` (from Kit `.as()`) */
77
+ /** True when `name` still has a legacy `/${formId}` suffix */
73
78
  isEncoded: boolean;
74
79
  };
75
80
  /**
76
- * Split a Kit-encoded HTML `name` (`email/1p9kxmo/login_user`, `n:age/...`)
77
- * into logical + html parts. Plain names pass through unchanged.
78
- *
79
- * When `formId` is known, uses Kit’s suffix rule (`/${formId}`).
80
- * Otherwise treats the first `/` after an optional `n:`/`b:` prefix as the form-id boundary
81
- * (logical paths use `.` / `[n]`, never `/`).
81
+ * Split a (possibly legacy) HTML `name` into logical + html parts.
82
+ * Plain Kit 2.70+ names (`email`, `n:age`) pass through unchanged.
82
83
  *
83
- * Note: Kit `.as()` emits names ending with `/${formId}` (e.g. `email/hash/login`).
84
- * `resolveRemoteInputProps` must append the same suffix when given a logical name.
84
+ * Still strips a legacy `/${formId}` suffix when present (older lib builds
85
+ * appended the remote action id to every field name).
85
86
  */
86
87
  export declare function parseRemoteFieldName(name: string | undefined, formId?: string | null): ParsedRemoteFieldName;
87
88
  /**
@@ -19,15 +19,20 @@ export function getRemoteFormId(action) {
19
19
  }
20
20
  /**
21
21
  * Resolve HTML input props for a field inside a Kit remote form.
22
- * Prefer a precomputed `formId` string so fields never touch Kit proxies.
23
22
  *
24
- * Kit requires names that end with `/${formId}` (from `.as()`), e.g.
25
- * `email/1p9kxmo/login_user` or `n:age/1p9kxmo/login_user`.
23
+ * Kit 2.70+ `.as()` emits the logical path only (`email`, `n:age`, `b:active`).
24
+ * The remote id lives on the form `action` (`?/remote=…`), not on each field name.
25
+ * Appending `/${formId}` breaks `convert_formdata` / `split_path` — especially with
26
+ * keyed instances (`.for(key)` → `…/"default"`), which surfaces as:
27
+ * `Invalid path status/…/updateProduct_remote/"default"`.
28
+ *
29
+ * `formId` is kept for call-site compatibility / legacy stripping in
30
+ * {@link parseRemoteFieldName}; it is not appended to `name`.
26
31
  */
27
- export function resolveRemoteInputProps(formId, logicalName, type = 'text') {
32
+ export function resolveRemoteInputProps(_formId, logicalName, type = 'text') {
28
33
  if (!logicalName)
29
34
  return {};
30
- // Already Kit-encoded (contains `/formId` or was passed from `.as()`).
35
+ // Already Kit-encoded or legacy `field/formId` — leave as-is.
31
36
  if (logicalName.includes('/')) {
32
37
  return { name: logicalName };
33
38
  }
@@ -36,21 +41,14 @@ export function resolveRemoteInputProps(formId, logicalName, type = 'text') {
36
41
  prefix = 'n:';
37
42
  else if (type === 'checkbox' || type === 'boolean')
38
43
  prefix = 'b:';
39
- const base = `${prefix}${logicalName}`;
40
- if (!formId)
41
- return { name: base };
42
- return { name: `${base}/${formId}` };
44
+ return { name: `${prefix}${logicalName}` };
43
45
  }
44
46
  /**
45
- * Split a Kit-encoded HTML `name` (`email/1p9kxmo/login_user`, `n:age/...`)
46
- * into logical + html parts. Plain names pass through unchanged.
47
- *
48
- * When `formId` is known, uses Kit’s suffix rule (`/${formId}`).
49
- * Otherwise treats the first `/` after an optional `n:`/`b:` prefix as the form-id boundary
50
- * (logical paths use `.` / `[n]`, never `/`).
47
+ * Split a (possibly legacy) HTML `name` into logical + html parts.
48
+ * Plain Kit 2.70+ names (`email`, `n:age`) pass through unchanged.
51
49
  *
52
- * Note: Kit `.as()` emits names ending with `/${formId}` (e.g. `email/hash/login`).
53
- * `resolveRemoteInputProps` must append the same suffix when given a logical name.
50
+ * Still strips a legacy `/${formId}` suffix when present (older lib builds
51
+ * appended the remote action id to every field name).
54
52
  */
55
53
  export function parseRemoteFieldName(name, formId) {
56
54
  if (!name) {
@@ -65,7 +63,7 @@ export function parseRemoteFieldName(name, formId) {
65
63
  logical = logical.slice(0, -2);
66
64
  return { logicalName: logical, htmlName, isEncoded: true };
67
65
  }
68
- // Heuristic without formId: Kit-encoded names contain `/`
66
+ // Legacy heuristic: names with `/` used to mean `field/formId`
69
67
  if (name.includes('/')) {
70
68
  let rest = name;
71
69
  if (rest.startsWith('n:') || rest.startsWith('b:'))
@@ -78,7 +76,12 @@ export function parseRemoteFieldName(name, formId) {
78
76
  return { logicalName: logical, htmlName, isEncoded: true };
79
77
  }
80
78
  }
81
- return { logicalName: name, htmlName: name, isEncoded: false };
79
+ let logical = name;
80
+ if (logical.startsWith('n:') || logical.startsWith('b:'))
81
+ logical = logical.slice(2);
82
+ if (logical.endsWith('[]'))
83
+ logical = logical.slice(0, -2);
84
+ return { logicalName: logical, htmlName: name, isEncoded: false };
82
85
  }
83
86
  /**
84
87
  * Safe props to spread onto `FormField` / `FormPasswordInput` from Kit `.as(...)`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.21.32",
3
+ "version": "0.21.33",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",