@yamada-ui/highlight 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Hirotomo Yamada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # @yamada-ui/highlight
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ $ pnpm add @yamada-ui/highlight
7
+ ```
8
+
9
+ or
10
+
11
+ ```sh
12
+ $ yarn add @yamada-ui/highlight
13
+ ```
14
+
15
+ or
16
+
17
+ ```sh
18
+ $ npm install @yamada-ui/highlight
19
+ ```
20
+
21
+ ## Contribution
22
+
23
+ Wouldn't you like to contribute? That's amazing! We have prepared a [contribution guide](https://github.com/hirotomoyamada/yamada-ui/blob/main/CONTRIBUTING.md) to assist you.
24
+
25
+ ## Licence
26
+
27
+ This package is licensed under the terms of the
28
+ [MIT license](https://github.com/hirotomoyamada/yamada-ui/blob/main/LICENSE).
@@ -0,0 +1,56 @@
1
+ // src/highlight.tsx
2
+ import {
3
+ ui,
4
+ forwardRef,
5
+ useComponentStyle,
6
+ omitThemeProps
7
+ } from "@yamada-ui/core";
8
+ import { Text } from "@yamada-ui/typography";
9
+ import { cx, isArray } from "@yamada-ui/utils";
10
+ import { Fragment, useMemo } from "react";
11
+ import { jsx } from "react/jsx-runtime";
12
+ var escapeRegexp = (term) => term.replace(/[|\\{}()[\]^$+*?.-]/g, (char) => `\\${char}`);
13
+ var buildRegex = (query) => {
14
+ query = query.filter(Boolean).map((text) => escapeRegexp(text.trim()));
15
+ if (query.length)
16
+ return new RegExp(`(${query.join("|")})`, "ig");
17
+ };
18
+ var highlightWords = ({ text, query }) => {
19
+ const regex = buildRegex(isArray(query) ? query : [query]);
20
+ if (!regex)
21
+ return [{ text, match: false }];
22
+ return text.split(regex).filter(Boolean).map((text2) => ({ text: text2, match: regex.test(text2) }));
23
+ };
24
+ var useHighlight = ({ text, query }) => useMemo(() => highlightWords({ text, query }), [text, query]);
25
+ var Highlight = ({
26
+ isFragment = false,
27
+ query,
28
+ children: text,
29
+ markProps,
30
+ lineHeight = "tall",
31
+ ...rest
32
+ }) => {
33
+ if (typeof text !== "string")
34
+ throw new Error("The children prop of Highlight must be a string");
35
+ const chunks = useHighlight({ query, text });
36
+ const Component = isFragment ? Fragment : Text;
37
+ return /* @__PURE__ */ jsx(Component, { ...!isFragment ? { lineHeight } : {}, ...rest, children: chunks.map(
38
+ ({ text: text2, match }, i) => match ? /* @__PURE__ */ jsx(Mark, { ...markProps, children: text2 }, i) : /* @__PURE__ */ jsx(Fragment, { children: text2 }, i)
39
+ ) });
40
+ };
41
+ var Mark = forwardRef((props, ref) => {
42
+ const [styles, mergedProps] = useComponentStyle("Mark", props);
43
+ const { className, ...rest } = omitThemeProps(mergedProps);
44
+ const css = {
45
+ bg: "transparent",
46
+ whiteSpace: "nowrap",
47
+ ...styles
48
+ };
49
+ return /* @__PURE__ */ jsx(ui.mark, { ref, className: cx("ui-mark", className), __css: css, ...rest });
50
+ });
51
+
52
+ export {
53
+ useHighlight,
54
+ Highlight,
55
+ Mark
56
+ };
@@ -0,0 +1,25 @@
1
+ import * as _yamada_ui_core from '@yamada-ui/core';
2
+ import { HTMLUIProps, ThemeProps } from '@yamada-ui/core';
3
+ import { TextProps } from '@yamada-ui/typography';
4
+ import { ReactNode, FC } from 'react';
5
+
6
+ type Options = {
7
+ text: string;
8
+ query: string | string[];
9
+ };
10
+ type Chunk = {
11
+ text: string;
12
+ match: boolean;
13
+ };
14
+ declare const useHighlight: ({ text, query }: Options) => Chunk[];
15
+ type HighlightProps = TextProps & {
16
+ isFragment?: boolean;
17
+ query: string | string[];
18
+ children: string | ((props: Chunk[]) => ReactNode);
19
+ markProps?: MarkProps;
20
+ };
21
+ declare const Highlight: FC<HighlightProps>;
22
+ type MarkProps = HTMLUIProps<'mark'> & ThemeProps<'Mark'>;
23
+ declare const Mark: _yamada_ui_core.Component<"mark", MarkProps>;
24
+
25
+ export { Highlight, HighlightProps, Mark, MarkProps, useHighlight };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/highlight.tsx
21
+ var highlight_exports = {};
22
+ __export(highlight_exports, {
23
+ Highlight: () => Highlight,
24
+ Mark: () => Mark,
25
+ useHighlight: () => useHighlight
26
+ });
27
+ module.exports = __toCommonJS(highlight_exports);
28
+ var import_core = require("@yamada-ui/core");
29
+ var import_typography = require("@yamada-ui/typography");
30
+ var import_utils = require("@yamada-ui/utils");
31
+ var import_react = require("react");
32
+ var import_jsx_runtime = require("react/jsx-runtime");
33
+ var escapeRegexp = (term) => term.replace(/[|\\{}()[\]^$+*?.-]/g, (char) => `\\${char}`);
34
+ var buildRegex = (query) => {
35
+ query = query.filter(Boolean).map((text) => escapeRegexp(text.trim()));
36
+ if (query.length)
37
+ return new RegExp(`(${query.join("|")})`, "ig");
38
+ };
39
+ var highlightWords = ({ text, query }) => {
40
+ const regex = buildRegex((0, import_utils.isArray)(query) ? query : [query]);
41
+ if (!regex)
42
+ return [{ text, match: false }];
43
+ return text.split(regex).filter(Boolean).map((text2) => ({ text: text2, match: regex.test(text2) }));
44
+ };
45
+ var useHighlight = ({ text, query }) => (0, import_react.useMemo)(() => highlightWords({ text, query }), [text, query]);
46
+ var Highlight = ({
47
+ isFragment = false,
48
+ query,
49
+ children: text,
50
+ markProps,
51
+ lineHeight = "tall",
52
+ ...rest
53
+ }) => {
54
+ if (typeof text !== "string")
55
+ throw new Error("The children prop of Highlight must be a string");
56
+ const chunks = useHighlight({ query, text });
57
+ const Component = isFragment ? import_react.Fragment : import_typography.Text;
58
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...!isFragment ? { lineHeight } : {}, ...rest, children: chunks.map(
59
+ ({ text: text2, match }, i) => match ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Mark, { ...markProps, children: text2 }, i) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: text2 }, i)
60
+ ) });
61
+ };
62
+ var Mark = (0, import_core.forwardRef)((props, ref) => {
63
+ const [styles, mergedProps] = (0, import_core.useComponentStyle)("Mark", props);
64
+ const { className, ...rest } = (0, import_core.omitThemeProps)(mergedProps);
65
+ const css = {
66
+ bg: "transparent",
67
+ whiteSpace: "nowrap",
68
+ ...styles
69
+ };
70
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ui.mark, { ref, className: (0, import_utils.cx)("ui-mark", className), __css: css, ...rest });
71
+ });
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ Highlight,
75
+ Mark,
76
+ useHighlight
77
+ });
@@ -0,0 +1,10 @@
1
+ import {
2
+ Highlight,
3
+ Mark,
4
+ useHighlight
5
+ } from "./chunk-CLKGZWAJ.mjs";
6
+ export {
7
+ Highlight,
8
+ Mark,
9
+ useHighlight
10
+ };
@@ -0,0 +1,4 @@
1
+ export { Highlight, HighlightProps, Mark, MarkProps, useHighlight } from './highlight.js';
2
+ import '@yamada-ui/core';
3
+ import '@yamada-ui/typography';
4
+ import 'react';
package/dist/index.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Highlight: () => Highlight,
24
+ Mark: () => Mark,
25
+ useHighlight: () => useHighlight
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+
29
+ // src/highlight.tsx
30
+ var import_core = require("@yamada-ui/core");
31
+ var import_typography = require("@yamada-ui/typography");
32
+ var import_utils = require("@yamada-ui/utils");
33
+ var import_react = require("react");
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var escapeRegexp = (term) => term.replace(/[|\\{}()[\]^$+*?.-]/g, (char) => `\\${char}`);
36
+ var buildRegex = (query) => {
37
+ query = query.filter(Boolean).map((text) => escapeRegexp(text.trim()));
38
+ if (query.length)
39
+ return new RegExp(`(${query.join("|")})`, "ig");
40
+ };
41
+ var highlightWords = ({ text, query }) => {
42
+ const regex = buildRegex((0, import_utils.isArray)(query) ? query : [query]);
43
+ if (!regex)
44
+ return [{ text, match: false }];
45
+ return text.split(regex).filter(Boolean).map((text2) => ({ text: text2, match: regex.test(text2) }));
46
+ };
47
+ var useHighlight = ({ text, query }) => (0, import_react.useMemo)(() => highlightWords({ text, query }), [text, query]);
48
+ var Highlight = ({
49
+ isFragment = false,
50
+ query,
51
+ children: text,
52
+ markProps,
53
+ lineHeight = "tall",
54
+ ...rest
55
+ }) => {
56
+ if (typeof text !== "string")
57
+ throw new Error("The children prop of Highlight must be a string");
58
+ const chunks = useHighlight({ query, text });
59
+ const Component = isFragment ? import_react.Fragment : import_typography.Text;
60
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...!isFragment ? { lineHeight } : {}, ...rest, children: chunks.map(
61
+ ({ text: text2, match }, i) => match ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Mark, { ...markProps, children: text2 }, i) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: text2 }, i)
62
+ ) });
63
+ };
64
+ var Mark = (0, import_core.forwardRef)((props, ref) => {
65
+ const [styles, mergedProps] = (0, import_core.useComponentStyle)("Mark", props);
66
+ const { className, ...rest } = (0, import_core.omitThemeProps)(mergedProps);
67
+ const css = {
68
+ bg: "transparent",
69
+ whiteSpace: "nowrap",
70
+ ...styles
71
+ };
72
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ui.mark, { ref, className: (0, import_utils.cx)("ui-mark", className), __css: css, ...rest });
73
+ });
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ Highlight,
77
+ Mark,
78
+ useHighlight
79
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ Highlight,
3
+ Mark,
4
+ useHighlight
5
+ } from "./chunk-CLKGZWAJ.mjs";
6
+ export {
7
+ Highlight,
8
+ Mark,
9
+ useHighlight
10
+ };
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@yamada-ui/highlight",
3
+ "version": "0.1.0",
4
+ "description": "Yamada UI highlight component",
5
+ "keywords": [
6
+ "yamada",
7
+ "yamada ui",
8
+ "react",
9
+ "emotion",
10
+ "component",
11
+ "highlight",
12
+ "ui",
13
+ "uikit",
14
+ "styled",
15
+ "style-props",
16
+ "styled-component",
17
+ "css-in-js"
18
+ ],
19
+ "author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
20
+ "license": "MIT",
21
+ "main": "dist/index.js",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "sideEffects": false,
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/hirotomoyamada/yamada-ui",
32
+ "directory": "packages/components/highlight"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/hirotomoyamada/yamada-ui/issues"
36
+ },
37
+ "dependencies": {
38
+ "@yamada-ui/core": "0.1.0",
39
+ "@yamada-ui/typography": "0.1.0",
40
+ "@yamada-ui/utils": "0.1.0"
41
+ },
42
+ "devDependencies": {
43
+ "react": "^18.0.0",
44
+ "clean-package": "2.2.0"
45
+ },
46
+ "peerDependencies": {
47
+ "react": ">=18"
48
+ },
49
+ "clean-package": "../../../clean-package.config.json",
50
+ "tsup": {
51
+ "clean": true,
52
+ "target": "es2019",
53
+ "format": [
54
+ "cjs",
55
+ "esm"
56
+ ]
57
+ },
58
+ "module": "dist/index.mjs",
59
+ "types": "dist/index.d.ts",
60
+ "exports": {
61
+ ".": {
62
+ "types": "./dist/index.d.ts",
63
+ "import": "./dist/index.mjs",
64
+ "require": "./dist/index.js"
65
+ },
66
+ "./package.json": "./package.json"
67
+ },
68
+ "scripts": {
69
+ "dev": "pnpm build:fast -- --watch",
70
+ "build": "tsup src --dts",
71
+ "build:fast": "tsup src",
72
+ "clean": "rimraf dist .turbo",
73
+ "typecheck": "tsc --noEmit",
74
+ "gen:docs": "tsx ../../../scripts/generate-docs"
75
+ }
76
+ }