@bouko/react 3.0.9 → 3.1.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.
- package/dist/core/format.d.ts +4 -1
- package/dist/core/format.js +4 -0
- package/package.json +1 -1
package/dist/core/format.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
1
|
+
import { ReactNode, ReactElement } from "react";
|
|
2
|
+
export declare function renderList<T>(items: T[], Component: (props: T & {
|
|
3
|
+
index: number;
|
|
4
|
+
}) => ReactElement): ReactNode;
|
|
2
5
|
export declare const rn: (...elements: ReactNode[]) => import("react/jsx-runtime").JSX.Element;
|
|
3
6
|
export declare const formatText: (text: string) => import("react/jsx-runtime").JSX.Element;
|
package/dist/core/format.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
1
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { Fragment } from "react";
|
|
3
4
|
const delimiterConfig = [
|
|
@@ -8,6 +9,9 @@ const delimiterConfig = [
|
|
|
8
9
|
const escapeRegex = (str) => str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
9
10
|
const delimiters = delimiterConfig.map(({ delimiter }) => escapeRegex(delimiter) + ".*?" + escapeRegex(delimiter)).join("|");
|
|
10
11
|
const WRAPPED_TEXT_REGEX = new RegExp(`(${delimiters})`, "g");
|
|
12
|
+
export function renderList(items, Component) {
|
|
13
|
+
return items.map((item, i) => (_createElement(Component, { ...item, index: i, key: i })));
|
|
14
|
+
}
|
|
11
15
|
export const rn = (...elements) => (_jsx(Fragment, { children: elements.map((x, i) => (_jsx(Fragment, { children: x }, i))) }));
|
|
12
16
|
const isWrapped = (x, wrapper) => x.startsWith(wrapper) && x.endsWith(wrapper);
|
|
13
17
|
export const formatText = (text) => {
|