@haklex/rich-renderer-alert 0.0.1

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,28 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Innei
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.
22
+
23
+
24
+ Additional Terms and Conditions
25
+
26
+ ----------------
27
+
28
+ Use of this software is governed by the terms of MIT and, in addition, by the terms and conditions described in the additional file (ADDITIONAL_TERMS.md). By using this software, you agree to abide by these additional terms and conditions.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @haklex/rich-renderer-alert
2
+
3
+ GitHub 风格提示块渲染器。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pnpm add @haklex/rich-renderer-alert
9
+ ```
10
+
11
+ ## 导出
12
+
13
+ ```ts
14
+ export { AlertRenderer } from './AlertRenderer'
15
+ export { AlertEditRenderer } from './AlertEditRenderer'
16
+ ```
17
+
18
+ ## 类型
19
+
20
+ Alert 类型:`'note' | 'tip' | 'important' | 'warning' | 'caution'`
21
+
22
+ ## 使用
23
+
24
+ 渲染器通过 `rendererConfig` 传入:
25
+
26
+ ```tsx
27
+ import { AlertRenderer } from '@haklex/rich-renderer-alert'
28
+ import type { RendererConfig } from '@haklex/rich-editor'
29
+
30
+ const config: RendererConfig = {
31
+ Alert: AlertRenderer,
32
+ }
33
+ ```
34
+
35
+ ## License
36
+
37
+ MIT
@@ -0,0 +1,4 @@
1
+ import { AlertRendererProps } from '@haklex/rich-editor';
2
+ import { FC } from 'react';
3
+ export declare const AlertEditRenderer: FC<AlertRendererProps>;
4
+ //# sourceMappingURL=AlertEditRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlertEditRenderer.d.ts","sourceRoot":"","sources":["../src/AlertEditRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAQ7D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAU/B,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC,kBAAkB,CAsCpD,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { AlertRendererProps } from '@haklex/rich-editor';
2
+ import { LucideProps } from 'lucide-react';
3
+ import { FC } from 'react';
4
+ type AlertType = AlertRendererProps['type'];
5
+ export declare const ALERT_ICONS: Record<AlertType, FC<LucideProps>>;
6
+ export declare const ALERT_LABELS: Record<AlertType, string>;
7
+ export declare const ALL_TYPES: AlertType[];
8
+ export declare const AlertRenderer: FC<AlertRendererProps>;
9
+ export default AlertRenderer;
10
+ //# sourceMappingURL=AlertRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlertRenderer.d.ts","sourceRoot":"","sources":["../src/AlertRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAQ/C,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAI/B,KAAK,SAAS,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAA;AAE3C,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC,WAAW,CAAC,CAM1D,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAMlD,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,SAAS,EAMhC,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,kBAAkB,CAUhD,CAAA;AAED,eAAe,aAAa,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { AlertEditRenderer } from './AlertEditRenderer';
2
+ export { AlertRenderer, default } from './AlertRenderer';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,76 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from "@haklex/rich-editor-ui";
3
+ import { OctagonAlert, TriangleAlert, MessageSquareWarning, Lightbulb, Info, ChevronDown } from "lucide-react";
4
+ var alertHeader = "pq4lod1";
5
+ var alertTrigger = "pq4lod2";
6
+ var alertChevron = "pq4lod3";
7
+ var alertIcon = "pq4lod4";
8
+ var alertLabel = "pq4lod5";
9
+ var alertMenuIcon = "pq4lod6";
10
+ const ALERT_ICONS = {
11
+ note: Info,
12
+ tip: Lightbulb,
13
+ important: MessageSquareWarning,
14
+ warning: TriangleAlert,
15
+ caution: OctagonAlert
16
+ };
17
+ const ALERT_LABELS = {
18
+ note: "Note",
19
+ tip: "Tip",
20
+ important: "Important",
21
+ warning: "Warning",
22
+ caution: "Caution"
23
+ };
24
+ const ALL_TYPES = [
25
+ "note",
26
+ "tip",
27
+ "important",
28
+ "warning",
29
+ "caution"
30
+ ];
31
+ const AlertRenderer = ({ type }) => {
32
+ const Icon = ALERT_ICONS[type];
33
+ const label = ALERT_LABELS[type];
34
+ return /* @__PURE__ */ jsxs("div", { className: alertHeader, "data-alert-type": type, children: [
35
+ /* @__PURE__ */ jsx(Icon, { className: alertIcon }),
36
+ /* @__PURE__ */ jsx("span", { className: alertLabel, children: label })
37
+ ] });
38
+ };
39
+ const AlertEditRenderer = ({
40
+ type,
41
+ editable,
42
+ onTypeChange
43
+ }) => {
44
+ if (!editable || !onTypeChange) {
45
+ return /* @__PURE__ */ jsx(AlertRenderer, { type });
46
+ }
47
+ const Icon = ALERT_ICONS[type];
48
+ const label = ALERT_LABELS[type];
49
+ return /* @__PURE__ */ jsx("div", { className: alertHeader, "data-alert-type": type, children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
50
+ /* @__PURE__ */ jsxs(DropdownMenuTrigger, { className: alertTrigger, children: [
51
+ /* @__PURE__ */ jsx(Icon, { className: alertIcon }),
52
+ /* @__PURE__ */ jsx("span", { className: alertLabel, children: label }),
53
+ /* @__PURE__ */ jsx(ChevronDown, { className: alertChevron })
54
+ ] }),
55
+ /* @__PURE__ */ jsx(DropdownMenuContent, { sideOffset: 6, align: "start", children: ALL_TYPES.map((t) => {
56
+ const ItemIcon = ALERT_ICONS[t];
57
+ return /* @__PURE__ */ jsxs(
58
+ DropdownMenuItem,
59
+ {
60
+ "data-alert-type": t,
61
+ onClick: () => onTypeChange(t),
62
+ children: [
63
+ /* @__PURE__ */ jsx(ItemIcon, { className: alertMenuIcon }),
64
+ /* @__PURE__ */ jsx("span", { children: ALERT_LABELS[t] })
65
+ ]
66
+ },
67
+ t
68
+ );
69
+ }) })
70
+ ] }) });
71
+ };
72
+ export {
73
+ AlertEditRenderer,
74
+ AlertRenderer,
75
+ AlertRenderer as default
76
+ };
@@ -0,0 +1,173 @@
1
+ .pq4lod1 {
2
+ display: flex;
3
+ align-items: center;
4
+ gap: 8px;
5
+ font-weight: 600;
6
+ text-transform: uppercase;
7
+ letter-spacing: 0.02em;
8
+ font-size: 0.875rem;
9
+ line-height: 1;
10
+ margin-bottom: 6px;
11
+ }
12
+ .pq4lod2 {
13
+ display: inline-flex;
14
+ align-items: center;
15
+ gap: 6px;
16
+ cursor: pointer;
17
+ padding: 2px 6px;
18
+ border-radius: 4px;
19
+ margin-inline: -6px;
20
+ border: none;
21
+ background: none;
22
+ font: inherit;
23
+ font-weight: 600;
24
+ text-transform: uppercase;
25
+ letter-spacing: 0.02em;
26
+ font-size: 0.875rem;
27
+ line-height: 1;
28
+ transition: background-color 0.15s;
29
+ }
30
+ .pq4lod2:hover {
31
+ background-color: color-mix(in srgb, var(--rc-text) 5%, transparent);
32
+ }
33
+ .pq4lod3 {
34
+ opacity: 0;
35
+ transition: opacity 0.15s;
36
+ width: 14px;
37
+ height: 14px;
38
+ flex-shrink: 0;
39
+ }
40
+ .pq4lod2:hover .pq4lod3 {
41
+ opacity: 0.6;
42
+ }
43
+ .pq4lod2[data-popup-open] .pq4lod3 {
44
+ opacity: 0.8;
45
+ }
46
+ .pq4lod4 {
47
+ width: 16px;
48
+ height: 16px;
49
+ flex-shrink: 0;
50
+ color: var(--pq4lod0);
51
+ }
52
+ .pq4lod5 {
53
+ color: var(--pq4lod0);
54
+ }
55
+ .pq4lod6 {
56
+ width: 16px;
57
+ height: 16px;
58
+ flex-shrink: 0;
59
+ }
60
+ [data-alert-type='note'] {
61
+ --pq4lod0: var(--rc-alert-info);
62
+ }
63
+ [data-alert-type='tip'] {
64
+ --pq4lod0: var(--rc-alert-tip);
65
+ }
66
+ [data-alert-type='important'] {
67
+ --pq4lod0: var(--rc-alert-important);
68
+ }
69
+ [data-alert-type='warning'] {
70
+ --pq4lod0: var(--rc-alert-warning);
71
+ }
72
+ [data-alert-type='caution'] {
73
+ --pq4lod0: var(--rc-alert-caution);
74
+ }
75
+ [data-alert-type='note'] .pq4lod6 {
76
+ color: var(--rc-alert-info);
77
+ }
78
+ [data-alert-type='tip'] .pq4lod6 {
79
+ color: var(--rc-alert-tip);
80
+ }
81
+ [data-alert-type='important'] .pq4lod6 {
82
+ color: var(--rc-alert-important);
83
+ }
84
+ [data-alert-type='warning'] .pq4lod6 {
85
+ color: var(--rc-alert-warning);
86
+ }
87
+ [data-alert-type='caution'] .pq4lod6 {
88
+ color: var(--rc-alert-caution);
89
+ }
90
+ .rich-alert {
91
+ position: relative;
92
+ padding: var(--rc-space-md);
93
+ padding-left: calc(var(--rc-space-md) + 4px);
94
+ border-radius: 0 var(--rc-radius-sm) var(--rc-radius-sm) 0;
95
+ margin: var(--rc-space-md) 0;
96
+ background-color: var(--rc-bg-secondary);
97
+ }
98
+ .rich-alert::before {
99
+ content: "";
100
+ position: absolute;
101
+ left: 0;
102
+ top: 0;
103
+ bottom: 0;
104
+ width: 4px;
105
+ border-radius: var(--rc-radius-sm);
106
+ }
107
+ .rich-alert-note::before {
108
+ background-color: var(--rc-alert-info);
109
+ }
110
+ .rich-alert-tip::before {
111
+ background-color: var(--rc-alert-tip);
112
+ }
113
+ .rich-alert-important::before {
114
+ background-color: var(--rc-alert-important);
115
+ }
116
+ .rich-alert-warning::before {
117
+ background-color: var(--rc-alert-warning);
118
+ }
119
+ .rich-alert-caution::before {
120
+ background-color: var(--rc-alert-caution);
121
+ }
122
+ .rich-alert-header {
123
+ position: relative;
124
+ display: flex;
125
+ align-items: center;
126
+ gap: var(--rc-space-sm);
127
+ font-weight: 600;
128
+ margin-bottom: var(--rc-space-md);
129
+ font-size: var(--rc-font-size-small);
130
+ text-transform: uppercase;
131
+ letter-spacing: 0.02em;
132
+ line-height: 1;
133
+ }
134
+ .rich-alert-icon {
135
+ display: inline-flex;
136
+ width: 16px;
137
+ height: 16px;
138
+ flex-shrink: 0;
139
+ }
140
+ .rich-alert-header-note {
141
+ color: var(--rc-alert-info);
142
+ }
143
+ .rich-alert-header-tip {
144
+ color: var(--rc-alert-tip);
145
+ }
146
+ .rich-alert-header-important {
147
+ color: var(--rc-alert-important);
148
+ }
149
+ .rich-alert-header-warning {
150
+ color: var(--rc-alert-warning);
151
+ }
152
+ .rich-alert-header-caution {
153
+ color: var(--rc-alert-caution);
154
+ }
155
+ .rich-alert-content {
156
+ min-height: 1em;
157
+ }
158
+ .rich-alert-content > .rich-paragraph:first-child {
159
+ margin-top: 0;
160
+ }
161
+ .rich-alert-content > .rich-paragraph:last-child {
162
+ margin-bottom: 0;
163
+ }
164
+ .rich-alert-content-editable {
165
+ outline: none;
166
+ }
167
+ .rich-alert-content .rich-paragraph {
168
+ margin: 0;
169
+ margin-bottom: 0.5em;
170
+ }
171
+ .rich-alert-content .rich-paragraph:last-child {
172
+ margin-bottom: 0;
173
+ }
@@ -0,0 +1,7 @@
1
+ export declare const alertHeader: string;
2
+ export declare const alertTrigger: string;
3
+ export declare const alertChevron: string;
4
+ export declare const alertIcon: string;
5
+ export declare const alertLabel: string;
6
+ export declare const alertMenuIcon: string;
7
+ //# sourceMappingURL=styles.css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.css.d.ts","sourceRoot":"","sources":["../src/styles.css.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW,QAUtB,CAAA;AAEF,eAAO,MAAM,YAAY,QAsBvB,CAAA;AAEF,eAAO,MAAM,YAAY,QAMvB,CAAA;AAUF,eAAO,MAAM,SAAS,QAKpB,CAAA;AAEF,eAAO,MAAM,UAAU,QAErB,CAAA;AAEF,eAAO,MAAM,aAAa,QAIxB,CAAA"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@haklex/rich-renderer-alert",
3
+ "version": "0.0.1",
4
+ "description": "Alert renderer for haklex rich editor",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts"
11
+ },
12
+ "./style.css": "./dist/rich-renderer-alert.css"
13
+ },
14
+ "main": "./dist/index.mjs",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "lucide-react": "^0.574.0"
20
+ },
21
+ "devDependencies": {
22
+ "@types/react": "^19.0.0",
23
+ "@types/react-dom": "^19.0.0",
24
+ "@vanilla-extract/css": "^1.18.0",
25
+ "@vanilla-extract/vite-plugin": "^5.1.4",
26
+ "react": "19.2.4",
27
+ "react-dom": "19.2.4",
28
+ "typescript": "^5.9.0",
29
+ "vite": "^7.3.1",
30
+ "vite-plugin-dts": "^4.5.0",
31
+ "@haklex/rich-editor": "0.0.1",
32
+ "@haklex/rich-style-token": "0.0.1",
33
+ "@haklex/rich-editor-ui": "0.0.1"
34
+ },
35
+ "peerDependencies": {
36
+ "react": ">=19",
37
+ "react-dom": ">=19",
38
+ "@haklex/rich-editor": "0.0.1",
39
+ "@haklex/rich-editor-ui": "0.0.1",
40
+ "@haklex/rich-style-token": "0.0.1"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "scripts": {
46
+ "build": "vite build",
47
+ "dev:build": "vite build --watch"
48
+ },
49
+ "types": "./dist/index.d.ts"
50
+ }