@r2digisolutions/components 0.21.31 → 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(() => {
@@ -96,7 +109,9 @@
96
109
  <div class={['relative w-full select-none', className]}>
97
110
  <svg
98
111
  viewBox={`0 0 ${W} ${height}`}
99
- class="h-auto w-full overflow-visible"
112
+ preserveAspectRatio="none"
113
+ class="block w-full overflow-visible"
114
+ style:height={`${height}px`}
100
115
  role="img"
101
116
  aria-label="Area line chart"
102
117
  >
@@ -79,7 +79,9 @@
79
79
  <div class={['relative w-full select-none', className]}>
80
80
  <svg
81
81
  viewBox={`0 0 ${W} ${height}`}
82
- class="h-auto w-full overflow-visible"
82
+ preserveAspectRatio="none"
83
+ class="block w-full overflow-visible"
84
+ style:height={`${height}px`}
83
85
  role="img"
84
86
  aria-label="Bar chart"
85
87
  >
@@ -65,7 +65,9 @@
65
65
  <div class={['relative w-full select-none', className]}>
66
66
  <svg
67
67
  viewBox={`0 0 ${W} ${H}`}
68
- class="h-auto w-full overflow-visible"
68
+ preserveAspectRatio="none"
69
+ class="block w-full overflow-visible"
70
+ style:height={`${H}px`}
69
71
  role="img"
70
72
  aria-label="Horizontal bar chart"
71
73
  >
@@ -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(() => {
@@ -112,7 +121,9 @@
112
121
  <div class={['relative w-full select-none', className]}>
113
122
  <svg
114
123
  viewBox={`0 0 ${W} ${height}`}
115
- class="h-auto w-full overflow-visible"
124
+ preserveAspectRatio="none"
125
+ class="block w-full overflow-visible"
126
+ style:height={`${height}px`}
116
127
  role="img"
117
128
  aria-label="Multi-line chart"
118
129
  >
@@ -100,7 +100,9 @@
100
100
  <div class="relative w-full select-none">
101
101
  <svg
102
102
  viewBox={`0 0 ${W} ${height}`}
103
- class="h-auto w-full overflow-visible"
103
+ preserveAspectRatio="none"
104
+ class="block w-full overflow-visible"
105
+ style:height={`${height}px`}
104
106
  role="img"
105
107
  aria-label="Stacked bar chart"
106
108
  >
@@ -1,4 +1,6 @@
1
1
  <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+
2
4
  export interface TimelineItem {
3
5
  id: string;
4
6
  title: string;
@@ -12,6 +14,8 @@
12
14
  size?: 'sm' | 'md' | 'lg';
13
15
  /** Connect dots with a continuous vertical line */
14
16
  showConnectors?: boolean;
17
+ /** Optional extra content under each item (thumbnails, badges, …). */
18
+ content?: Snippet<[TimelineItem, number]>;
15
19
  class?: string;
16
20
  }
17
21
 
@@ -19,6 +23,7 @@
19
23
  items = [],
20
24
  size = 'md',
21
25
  showConnectors = true,
26
+ content,
22
27
  class: className = ''
23
28
  }: TimelineProps = $props();
24
29
 
@@ -114,6 +119,9 @@
114
119
  {#if item.description}
115
120
  <p class={['mt-0.5 text-secondary', sizeClasses.desc]}>{item.description}</p>
116
121
  {/if}
122
+ {#if content}
123
+ {@render content(item, index)}
124
+ {/if}
117
125
  </div>
118
126
  </li>
119
127
  {/each}
@@ -1,3 +1,4 @@
1
+ import type { Snippet } from 'svelte';
1
2
  export interface TimelineItem {
2
3
  id: string;
3
4
  title: string;
@@ -10,6 +11,8 @@ interface TimelineProps {
10
11
  size?: 'sm' | 'md' | 'lg';
11
12
  /** Connect dots with a continuous vertical line */
12
13
  showConnectors?: boolean;
14
+ /** Optional extra content under each item (thumbnails, badges, …). */
15
+ content?: Snippet<[TimelineItem, number]>;
13
16
  class?: string;
14
17
  }
15
18
  declare const Timeline: import("svelte").Component<TimelineProps, {}, "">;
@@ -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.31",
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",