@marianmeres/stuic 3.175.0 → 3.176.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.
@@ -237,7 +237,7 @@
237
237
  import Button from "../Button/Button.svelte";
238
238
  import EmptyState from "../EmptyState/EmptyState.svelte";
239
239
  import Pagination from "../Pagination/Pagination.svelte";
240
- import Thc, { isTHCNotEmpty, getTHCStringContent } from "../Thc/Thc.svelte";
240
+ import Thc, { isTHCNotEmpty } from "../Thc/Thc.svelte";
241
241
 
242
242
  let {
243
243
  columns,
@@ -746,7 +746,7 @@
746
746
  <div class={!unstyled ? "stuic-data-table-card-row" : undefined}>
747
747
  <span class={!unstyled ? "stuic-data-table-card-label" : undefined}>
748
748
  {#if isTHCNotEmpty(col.label)}
749
- {getTHCStringContent(col.label) || col.key}
749
+ <Thc thc={col.label!} />
750
750
  {:else}
751
751
  {col.key}
752
752
  {/if}
@@ -159,14 +159,6 @@
159
159
  ...rest
160
160
  }: Props = $props();
161
161
 
162
- // `isTHCNotEmpty` only knows string/text/html/component — a snippet (bare or
163
- // `{ snippet }`) is renderable content it reports as empty, which would silently
164
- // drop a snippet description. Widen the test here.
165
- const _hasContent = (thc: THC | undefined | null): boolean =>
166
- typeof thc === "function" ||
167
- !!(thc && typeof thc === "object" && "snippet" in thc) ||
168
- isTHCNotEmpty(thc);
169
-
170
162
  /** Emptiness of a VALUE is deliberately not `isTHCNotEmpty`: `0` is a value, not empty. */
171
163
  const _isEmptyValue = (v: THC | number | undefined | null): boolean =>
172
164
  v === undefined || v === null || v === "";
@@ -257,7 +249,7 @@
257
249
  <Thc thc={_value(item)} />
258
250
  {/if}
259
251
  </dd>
260
- {#if _hasContent(item.description)}
252
+ {#if isTHCNotEmpty(item.description)}
261
253
  <dd class={_classDescription(item)}>
262
254
  <Thc thc={item.description!} />
263
255
  </dd>
@@ -387,7 +387,7 @@
387
387
  // aria-live announcement text for reorder actions
388
388
  let liveAnnouncement = $state("");
389
389
  let parentHiddenInputEl: HTMLInputElement | undefined = $state();
390
- let hasLabel = $derived(isTHCNotEmpty(label) || typeof label === "function");
390
+ let hasLabel = $derived(isTHCNotEmpty(label));
391
391
  let inputEl = $state<HTMLInputElement>()!;
392
392
  // Outer wrapper for scrollIntoView and focus targeting.
393
393
  let wrapEl: HTMLDivElement | undefined = $state();
@@ -151,10 +151,11 @@
151
151
  classLabel
152
152
  )}
153
153
  >
154
- {#if isTHCNotEmpty(label)}
155
- <Thc thc={label as THC} forceAsHtml />
156
- {:else}
154
+ <!-- a snippet label first: it takes `{ id }`, which `Thc` cannot pass -->
155
+ {#if typeof label === "function"}
157
156
  {@render (label as SnippetWithId)({ id })}
157
+ {:else if isTHCNotEmpty(label)}
158
+ <Thc thc={label as THC} forceAsHtml />
158
159
  {/if}
159
160
  </div>
160
161
  {/if}
@@ -147,10 +147,11 @@
147
147
  classLabel
148
148
  )}
149
149
  >
150
- {#if isTHCNotEmpty(label)}
151
- <Thc thc={label as THC} forceAsHtml />
152
- {:else}
150
+ <!-- a snippet label first: it takes `{ id }`, which `Thc` cannot pass -->
151
+ {#if typeof label === "function"}
153
152
  {@render (label as SnippetWithId)({ id })}
153
+ {:else if isTHCNotEmpty(label)}
154
+ <Thc thc={label as THC} forceAsHtml />
154
155
  {/if}
155
156
  </div>
156
157
  {/if}
@@ -82,7 +82,7 @@
82
82
  }
83
83
  });
84
84
 
85
- let hasLabel = $derived(isTHCNotEmpty(label) || typeof label === "function");
85
+ let hasLabel = $derived(isTHCNotEmpty(label));
86
86
  </script>
87
87
 
88
88
  {#snippet snippetOrThc({ id, value }: { id: string; value?: SnippetWithId | THC })}
@@ -26,15 +26,21 @@ type THC =
26
26
 
27
27
  ### `isTHCNotEmpty(value)`
28
28
 
29
- Checks if a THC value has renderable content.
29
+ Checks if a THC value has renderable content — every form `Thc` itself can render.
30
30
 
31
31
  ```ts
32
32
  isTHCNotEmpty("Hello"); // true
33
33
  isTHCNotEmpty({ text: "Hi" }); // true
34
+ isTHCNotEmpty(mySnippet); // true
35
+ isTHCNotEmpty({ snippet }); // true
34
36
  isTHCNotEmpty(""); // false
35
37
  isTHCNotEmpty(null); // false
36
38
  ```
37
39
 
40
+ > **Note:** a snippet label that needs an argument (e.g. the `{ id }` the `Field*`
41
+ > components pass) must be rendered directly, not through `Thc` — `Thc` renders a bare
42
+ > snippet with no arguments. Test `typeof value === "function"` first in that case.
43
+
38
44
  ### `getTHCStringContent(value)`
39
45
 
40
46
  Extracts string content from a THC value.
@@ -70,13 +70,18 @@
70
70
  /**
71
71
  * Checks if a THC value has renderable content.
72
72
  *
73
+ * Covers every form `Thc` itself can render: non-empty text/html, a component,
74
+ * a `{ snippet }`, and a bare snippet function.
75
+ *
73
76
  * @param m - The THC value to check
74
- * @returns `true` if the value contains non-empty text, html, or a component
77
+ * @returns `true` if the value contains renderable content
75
78
  *
76
79
  * @example
77
80
  * ```ts
78
81
  * isTHCNotEmpty("Hello"); // true
79
82
  * isTHCNotEmpty({ text: "Hi" }); // true
83
+ * isTHCNotEmpty(mySnippet); // true
84
+ * isTHCNotEmpty({ snippet }); // true
80
85
  * isTHCNotEmpty(""); // false
81
86
  * isTHCNotEmpty(null); // false
82
87
  * ```
@@ -87,7 +92,10 @@
87
92
  _is(m) ||
88
93
  _is((m as WithText)?.text) ||
89
94
  _is((m as WithHtml)?.html) ||
90
- !!(m as WithComponent)?.component
95
+ !!(m as WithComponent)?.component ||
96
+ // a bare snippet is a function; `{ snippet }` is the object form
97
+ typeof m === "function" ||
98
+ !!(m as WithSnippet)?.snippet
91
99
  );
92
100
  }
93
101
 
@@ -58,13 +58,18 @@ export interface Props extends Record<string, any> {
58
58
  /**
59
59
  * Checks if a THC value has renderable content.
60
60
  *
61
+ * Covers every form `Thc` itself can render: non-empty text/html, a component,
62
+ * a `{ snippet }`, and a bare snippet function.
63
+ *
61
64
  * @param m - The THC value to check
62
- * @returns `true` if the value contains non-empty text, html, or a component
65
+ * @returns `true` if the value contains renderable content
63
66
  *
64
67
  * @example
65
68
  * ```ts
66
69
  * isTHCNotEmpty("Hello"); // true
67
70
  * isTHCNotEmpty({ text: "Hi" }); // true
71
+ * isTHCNotEmpty(mySnippet); // true
72
+ * isTHCNotEmpty({ snippet }); // true
68
73
  * isTHCNotEmpty(""); // false
69
74
  * isTHCNotEmpty(null); // false
70
75
  * ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "3.175.0",
3
+ "version": "3.176.0",
4
4
  "packageManager": "pnpm@11.5.0",
5
5
  "scripts": {
6
6
  "dev": "vite dev",