@ilokesto/utilinent 0.0.22 → 0.0.23

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.
@@ -1,14 +1,16 @@
1
- import { createElement } from "react";
1
+ import { createElement, forwardRef } from "react";
2
2
  import { htmlTags } from "../constants/htmlTags";
3
3
  function BaseFor({ each, children, fallback = null, }) {
4
4
  return each && each.length > 0 ? each.map(children) : fallback;
5
5
  }
6
- const renderForTag = (tag) => ({ each, children, fallback = null, ...props }) => {
6
+ const renderForTag = (tag) =>
7
+ // forward ref so consumers can attach a ref to the underlying DOM element
8
+ forwardRef(({ each, children, fallback = null, ...props }, ref) => {
7
9
  if (!each || each.length === 0)
8
10
  return fallback;
9
11
  const content = each.map(children);
10
- return createElement(tag, props, content);
11
- };
12
+ return createElement(tag, { ...props, ref }, content);
13
+ });
12
14
  const tagEntries = htmlTags.reduce((acc, tag) => {
13
15
  acc[tag] = renderForTag(tag);
14
16
  return acc;
@@ -1,5 +1,5 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- import { createElement } from "react";
2
+ import { createElement, forwardRef } from "react";
3
3
  import { htmlTags } from "../constants/htmlTags";
4
4
  function BaseRepeat({ times, children, fallback = null }) {
5
5
  if (!times || times <= 0 || !Number.isInteger(times)) {
@@ -7,13 +7,15 @@ function BaseRepeat({ times, children, fallback = null }) {
7
7
  }
8
8
  return _jsx(_Fragment, { children: Array.from({ length: times }, (_, i) => children(i)) });
9
9
  }
10
- const renderForTag = (tag) => ({ times, children, fallback = null, ...props }) => {
10
+ const renderForTag = (tag) =>
11
+ // forward ref so consumers can attach a ref to the underlying DOM element
12
+ forwardRef(({ times, children, fallback = null, ...props }, ref) => {
11
13
  if (!times || times <= 0 || !Number.isInteger(times)) {
12
14
  return fallback ?? null;
13
15
  }
14
16
  const content = Array.from({ length: times }, (_, i) => children(i));
15
- return createElement(tag, props, content);
16
- };
17
+ return createElement(tag, { ...props, ref }, content);
18
+ });
17
19
  const tagEntries = htmlTags.reduce((acc, tag) => {
18
20
  acc[tag] = renderForTag(tag);
19
21
  return acc;
@@ -1,4 +1,4 @@
1
- import { createElement } from "react";
1
+ import { createElement, forwardRef } from "react";
2
2
  import { htmlTags } from "../constants/htmlTags";
3
3
  const BaseShow = ({ when, children, fallback = null }) => {
4
4
  const shouldRender = Array.isArray(when) ? when.every(Boolean) : !!when;
@@ -8,13 +8,15 @@ const BaseShow = ({ when, children, fallback = null }) => {
8
8
  : children
9
9
  : fallback;
10
10
  };
11
- const renderForTag = (tag) => ({ when, children, fallback = null, ...props }) => {
11
+ const renderForTag = (tag) =>
12
+ // forward ref so consumers like Observer can pass a ref to the real DOM element
13
+ forwardRef(function Render({ when, children, fallback = null, ...props }, ref) {
12
14
  const shouldRender = Array.isArray(when) ? when.every(Boolean) : !!when;
13
15
  if (!shouldRender)
14
16
  return fallback;
15
17
  const content = typeof children === "function" ? children(when) : children;
16
- return createElement(tag, props, content);
17
- };
18
+ return createElement(tag, { ...props, ref }, content);
19
+ });
18
20
  const tagEntries = htmlTags.reduce((acc, tag) => {
19
21
  acc[tag] = renderForTag(tag);
20
22
  return acc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ilokesto/utilinent",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ilokesto/utilinent.git"