remons-markdown-editor 1.0.0-beta.2 → 1.0.0-beta.21

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.
Files changed (34) hide show
  1. package/dist/App.d.ts +2 -0
  2. package/dist/MarkdownEditor.d.ts +23 -0
  3. package/dist/components/Dialog/EditDialog.d.ts +21 -0
  4. package/dist/components/Editor/codemirrorExtensions.d.ts +12 -0
  5. package/dist/components/Editor/containerWidget.d.ts +20 -0
  6. package/dist/components/Editor/index.d.ts +16 -0
  7. package/dist/components/Icon/index.d.ts +2 -0
  8. package/dist/components/Panel/SplitPanels.d.ts +7 -0
  9. package/dist/components/Preview/index.d.ts +10 -0
  10. package/dist/components/Toolbar/buttons.d.ts +59 -0
  11. package/dist/components/Toolbar/config.d.ts +6 -0
  12. package/dist/components/Toolbar/hooks/useToolbar.d.ts +14 -0
  13. package/dist/components/Toolbar/index.d.ts +13 -0
  14. package/dist/components/Toolbar/renderers/TablePicker/TableDropdown.d.ts +5 -0
  15. package/dist/components/Toolbar/renderers/TablePicker/index.d.ts +9 -0
  16. package/dist/components/Toolbar/renderers/ToolbarItemRenderer.d.ts +7 -0
  17. package/dist/hooks/useFullscreen.d.ts +4 -0
  18. package/dist/hooks/useRegisterToolbar.d.ts +101 -0
  19. package/dist/hooks/useScrollSync.d.ts +6 -0
  20. package/dist/index.cjs +1612 -1202
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.css +184 -113
  23. package/dist/index.d.ts +5 -98
  24. package/dist/index.js +1588 -1182
  25. package/dist/index.js.map +1 -1
  26. package/dist/main.d.ts +0 -0
  27. package/dist/registry/componentRegistry.d.ts +34 -0
  28. package/dist/types/index.d.ts +148 -0
  29. package/dist/utils/parseContainer.d.ts +18 -0
  30. package/dist/utils/writeContainer.d.ts +16 -0
  31. package/package.json +77 -81
  32. package/readme.md +309 -91
  33. package/dist/index.css.map +0 -1
  34. package/dist/index.d.cts +0 -98
package/dist/index.css CHANGED
@@ -1,64 +1,202 @@
1
- @import "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+SC:wght@400;500;600;700&display=swap";
2
-
3
- /* src/components/Toolbar/renderers/TablePicker/index.module.less */
4
- .container {
1
+ .index-module__container___l6BT- {
5
2
  padding: 4px;
6
3
  display: block;
7
4
  min-width: 200px;
8
- background: #fff;
9
- border: 1px solid #e5e7eb;
5
+ background: var(--remons-md-editor-bg-picker);
6
+ border: 1px solid var(--remons-md-editor-color-border-light);
10
7
  border-radius: 6px;
11
8
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
12
9
  }
13
- .grid {
10
+ .index-module__grid___tCZ-r {
14
11
  display: grid;
15
12
  gap: 2px;
16
13
  transition: all 0.1s ease;
17
14
  justify-content: flex-start;
18
15
  }
19
- .grid .cell {
16
+ .index-module__grid___tCZ-r .index-module__cell___vTDQz {
20
17
  width: 24px;
21
18
  height: 24px;
22
- border: 1px solid #e8e8e8;
19
+ border: 1px solid var(--remons-md-editor-color-border-light);
23
20
  border-radius: 2px;
24
21
  background: transparent;
25
22
  cursor: pointer;
26
23
  transition: all 0.1s ease;
27
24
  }
28
- .grid .cell.cellActive {
29
- border-color: #91caff;
30
- background: #ddf4ff;
25
+ .index-module__grid___tCZ-r .index-module__cell___vTDQz.index-module__cellActive___0EYvU {
26
+ border-color: var(--remons-md-editor-color-cell-active);
27
+ background: var(--remons-md-editor-bg-cell-active);
31
28
  }
32
- .hint {
29
+ .index-module__hint___dTObk {
33
30
  padding: 12px 16px;
34
- color: #999;
31
+ color: var(--remons-md-editor-color-hint);
35
32
  font-size: 12px;
36
33
  text-align: center;
37
34
  cursor: pointer;
38
35
  }
39
- .label {
36
+ .index-module__label___2CmK1 {
40
37
  margin-top: 8px;
41
38
  font-size: 13px;
42
- color: #666;
39
+ color: var(--remons-md-editor-color-label);
43
40
  font-weight: 500;
44
41
  min-height: 20px;
45
42
  text-align: center;
46
43
  }
47
-
48
- /* src/App.css */
49
- .app {
50
- height: 100vh;
44
+ html,
45
+ body {
46
+ margin: 0;
47
+ padding: 0;
48
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
49
+ 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
50
+ sans-serif;
51
+ -webkit-font-smoothing: antialiased;
52
+ -moz-osx-font-smoothing: grayscale;
53
+ }
54
+
55
+ #markdown-editor {
56
+ height: 100vh;
57
+ width: 100vw;
58
+ overflow: hidden;
59
+ }
60
+
61
+ /* ===== CSS 自定义属性(主题变量) ===== */
62
+ /* 浅色主题(默认) */
63
+ :root,
64
+ [data-theme="light"] {
65
+ /* 背景色 */
66
+ --remons-md-editor-bg-primary: #f3f3f3;
67
+ --remons-md-editor-bg-white: rgba(255, 255, 255, 0.6);
68
+ --remons-md-editor-bg-hover: #e1e4e8;
69
+ --remons-md-editor-bg-active: #d0d7de;
70
+ --remons-md-editor-bg-fullscreen: #fff;
71
+
72
+ /* 文字颜色 */
73
+ --remons-md-editor-color-text: #24292f;
74
+ --remons-md-editor-color-text-hover: #0969da;
75
+
76
+ /* 边框 */
77
+ --remons-md-editor-color-border: rgba(255, 255, 255, 0.8);
78
+ --remons-md-editor-color-border-light: #d0d7de;
79
+
80
+ /* 焦点 */
81
+ --remons-md-editor-color-focus: #0969da;
82
+ --remons-md-editor-color-focus-shadow: rgba(9, 105, 218, 0.1);
83
+
84
+ /* 工具选择器 */
85
+ --remons-md-editor-bg-picker: #fff;
86
+ --remons-md-editor-bg-cell-active: #ddf4ff;
87
+ --remons-md-editor-color-cell-active: #91caff;
88
+ --remons-md-editor-color-hint: #999;
89
+ --remons-md-editor-color-label: #666;
90
+ }
91
+
92
+ /* ===== 深色主题 ===== */
93
+ [data-theme="dark"] {
94
+ /* 背景色 */
95
+ --remons-md-editor-bg-primary: #1a1d23;
96
+ --remons-md-editor-bg-white: rgba(46, 51, 80, 0.8);
97
+ --remons-md-editor-bg-hover: #4a5163;
98
+ --remons-md-editor-bg-active: #5a6278;
99
+ --remons-md-editor-bg-fullscreen: #1a1d23;
100
+
101
+ /* 文字颜色 */
102
+ --remons-md-editor-color-text: #c9d1d9;
103
+ --remons-md-editor-color-text-hover: #58a6ff;
104
+
105
+ /* 边框 */
106
+ --remons-md-editor-color-border: rgba(255, 255, 255, 0.1);
107
+ --remons-md-editor-color-border-light: #3a3f4b;
108
+
109
+ /* 焦点 */
110
+ --remons-md-editor-color-focus: #58a6ff;
111
+ --remons-md-editor-color-focus-shadow: rgba(88, 166, 255, 0.15);
112
+
113
+ /* 工具选择器 */
114
+ --remons-md-editor-bg-picker: #2e3350;
115
+ --remons-md-editor-bg-cell-active: #1a3a5c;
116
+ --remons-md-editor-color-cell-active: #58a6ff;
117
+ --remons-md-editor-color-hint: #8b949e;
118
+ --remons-md-editor-color-label: #8b949e;
119
+ }
120
+
121
+ .ant-anchor-link-title {
122
+ white-space: inherit !important;
123
+ }@font-face {
124
+ font-family: 'Inter';
125
+ font-style: normal;
126
+ font-weight: 400;
127
+ font-display: swap;
128
+ src: url(https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfMZg.ttf) format('truetype');
129
+ }
130
+ @font-face {
131
+ font-family: 'Inter';
132
+ font-style: normal;
133
+ font-weight: 500;
134
+ font-display: swap;
135
+ src: url(https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuI6fMZg.ttf) format('truetype');
136
+ }
137
+ @font-face {
138
+ font-family: 'Inter';
139
+ font-style: normal;
140
+ font-weight: 600;
141
+ font-display: swap;
142
+ src: url(https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuGKYMZg.ttf) format('truetype');
143
+ }
144
+ @font-face {
145
+ font-family: 'Inter';
146
+ font-style: normal;
147
+ font-weight: 700;
148
+ font-display: swap;
149
+ src: url(https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuFuYMZg.ttf) format('truetype');
150
+ }
151
+ @font-face {
152
+ font-family: 'Noto Sans SC';
153
+ font-style: normal;
154
+ font-weight: 400;
155
+ font-display: swap;
156
+ src: url(https://fonts.gstatic.com/s/notosanssc/v41/k3kCo84MPvpLmixcA63oeAL7Iqp5IZJF9bmaG9_FnYw.ttf) format('truetype');
157
+ }
158
+ @font-face {
159
+ font-family: 'Noto Sans SC';
160
+ font-style: normal;
161
+ font-weight: 500;
162
+ font-display: swap;
163
+ src: url(https://fonts.gstatic.com/s/notosanssc/v41/k3kCo84MPvpLmixcA63oeAL7Iqp5IZJF9bmaG-3FnYw.ttf) format('truetype');
164
+ }
165
+ @font-face {
166
+ font-family: 'Noto Sans SC';
167
+ font-style: normal;
168
+ font-weight: 600;
169
+ font-display: swap;
170
+ src: url(https://fonts.gstatic.com/s/notosanssc/v41/k3kCo84MPvpLmixcA63oeAL7Iqp5IZJF9bmaGwHCnYw.ttf) format('truetype');
171
+ }
172
+ @font-face {
173
+ font-family: 'Noto Sans SC';
174
+ font-style: normal;
175
+ font-weight: 700;
176
+ font-display: swap;
177
+ src: url(https://fonts.gstatic.com/s/notosanssc/v41/k3kCo84MPvpLmixcA63oeAL7Iqp5IZJF9bmaGzjCnYw.ttf) format('truetype');
178
+ }
179
+ .markdown-editor-app {
180
+ height: 100%;
51
181
  display: flex;
52
182
  flex-direction: column;
183
+ border: 1px solid var(--markdown-editor-color-border);
184
+ border-radius: 12px;
185
+ background: var(--remons-md-editor-bg-primary);
53
186
  }
54
- .app.fullscreen {
187
+ .markdown-editor-app .ant-btn:hover {
188
+ border: none !important;
189
+ background-color: var(--remons-md-editor-bg-hover) !important;
190
+ color: var(--remons-md-editor-color-text-hover) !important;
191
+ }
192
+ .markdown-editor-app.fullscreen {
55
193
  position: fixed;
56
194
  top: 0;
57
195
  left: 0;
58
196
  right: 0;
59
197
  bottom: 0;
60
198
  z-index: 9999;
61
- background: #fff;
199
+ background: var(--remons-md-editor-bg-fullscreen);
62
200
  width: 100vw;
63
201
  height: 100vh;
64
202
  }
@@ -67,8 +205,8 @@
67
205
  display: flex;
68
206
  align-items: center;
69
207
  padding: 4px 8px;
70
- background: #f6f8fa;
71
- border-bottom: 1px solid #d0d7de;
208
+ background: var(--remons-md-editor-bg-white);
209
+ border-bottom: 1px solid var(--remons-md-editor-color-border-light);
72
210
  gap: 4px;
73
211
  overflow-x: auto;
74
212
  }
@@ -90,16 +228,20 @@
90
228
  cursor: pointer;
91
229
  font-size: 16px;
92
230
  font-weight: 500;
93
- color: #24292f;
231
+ color: var(--remons-md-editor-color-text);
94
232
  transition: background-color 0.15s, color 0.15s;
95
233
  white-space: nowrap;
96
234
  }
235
+ .toolbar-button svg {
236
+ width: 16px;
237
+ height: 16px;
238
+ }
97
239
  .toolbar-button:hover {
98
- background: #e1e4e8;
99
- color: #0969da;
240
+ background: var(--remons-md-editor-bg-hover);
241
+ color: var(--remons-md-editor-color-text-hover);
100
242
  }
101
243
  .toolbar-button:active {
102
- background: #d0d7de;
244
+ background: var(--remons-md-editor-bg-active);
103
245
  }
104
246
  .toolbar-button.ant-btn {
105
247
  min-width: 32px;
@@ -109,8 +251,8 @@
109
251
  box-shadow: none !important;
110
252
  }
111
253
  .toolbar-button.ant-btn:hover {
112
- background: #e1e4e8;
113
- color: #0969da;
254
+ background: var(--remons-md-editor-bg-hover);
255
+ color: var(--remons-md-editor-color-text-hover);
114
256
  border-color: transparent !important;
115
257
  box-shadow: none !important;
116
258
  }
@@ -120,11 +262,13 @@
120
262
  }
121
263
  :where(.css-dev-only-do-not-override-u6izyw).ant-btn:not(:disabled):not(.ant-btn-disabled):hover {
122
264
  border: none !important;
265
+ background-color: var(--remons-md-editor-bg-hover) !important;
266
+ color: var(--remons-md-editor-color-text-hover) !important;
123
267
  }
124
268
  .toolbar-separator {
125
269
  width: 1px;
126
270
  height: 24px;
127
- background: #d0d7de;
271
+ background: var(--remons-md-editor-color-border-light);
128
272
  margin: 0 4px;
129
273
  }
130
274
  .split-panels {
@@ -142,16 +286,7 @@
142
286
  height: 100%;
143
287
  }
144
288
  .cm-scroller {
145
- font-family:
146
- Consolas,
147
- Inter,
148
- Noto Sans SC,
149
- -apple-system,
150
- BlinkMacSystemFont,
151
- Segoe UI,
152
- PingFang SC,
153
- Microsoft YaHei,
154
- sans-serif !important;
289
+ font-family: Consolas, Inter, 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif !important;
155
290
  }
156
291
  .cm-editor {
157
292
  height: 100%;
@@ -160,78 +295,14 @@
160
295
  height: 100%;
161
296
  overflow: auto;
162
297
  }
298
+ /* 通用容器基类 */
163
299
  .md-container {
164
300
  margin: 16px 0;
165
301
  border-radius: 6px;
166
- border: 1px solid #d0d7de;
302
+ border: 1px solid var(--remons-md-editor-color-border-light);
167
303
  overflow: hidden;
168
304
  }
169
- .link-card {
170
- background: #f6f8fa;
171
- }
172
- .link-card-content {
173
- padding: 16px;
174
- }
175
- .link-card-title {
176
- margin: 0 0 4px;
177
- font-size: 16px;
178
- font-weight: 600;
179
- }
180
- .link-card-title a {
181
- color: #0969da;
182
- text-decoration: none;
183
- }
184
- .link-card-title a:hover {
185
- text-decoration: underline;
186
- }
187
- .link-card-desc {
188
- margin: 0;
189
- font-size: 14px;
190
- color: #57606a;
191
- line-height: 1.5;
192
- }
193
- .link-card-primary {
194
- background: #ddf4ff;
195
- border-color: #54aeff;
196
- }
197
- .link-card-primary .link-card-title a {
198
- color: #0550ae;
199
- }
200
- .link-card-warning {
201
- background: #fff8c5;
202
- border-color: #d4a72c;
203
- }
204
- .link-card-warning .link-card-title a {
205
- color: #7d4e00;
206
- }
207
- .note {
208
- padding: 12px 16px;
209
- }
210
- .note-info {
211
- background: #ddf4ff;
212
- border-color: #54aeff;
213
- }
214
- .note-tip {
215
- background: #dafbe1;
216
- border-color: #4ac26b;
217
- }
218
- .note-warning {
219
- background: #fff8c5;
220
- border-color: #d4a72c;
221
- }
222
- .note-danger {
223
- background: #ffebe9;
224
- border-color: #fb857b;
225
- }
226
- .note-title {
227
- margin: 0 0 4px;
228
- font-size: 14px;
229
- font-weight: 600;
230
- }
231
- .note-text {
232
- font-size: 14px;
233
- line-height: 1.5;
234
- }
305
+ /* 编辑弹窗样式 */
235
306
  .edit-dialog {
236
307
  padding: 8px 0;
237
308
  }
@@ -243,23 +314,23 @@
243
314
  margin-bottom: 6px;
244
315
  font-size: 14px;
245
316
  font-weight: 500;
246
- color: #24292f;
317
+ color: var(--remons-md-editor-color-text);
247
318
  }
248
319
  .edit-dialog-input {
249
320
  width: 100%;
250
321
  padding: 6px 10px;
251
322
  font-size: 14px;
252
- border: 1px solid #d0d7de;
323
+ border: 1px solid var(--remons-md-editor-color-border-light);
253
324
  border-radius: 6px;
254
325
  outline: none;
255
326
  transition: border-color 0.15s;
256
327
  }
257
328
  .edit-dialog-input:focus {
258
- border-color: #0969da;
259
- box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.1);
329
+ border-color: var(--remons-md-editor-color-focus);
330
+ box-shadow: 0 0 0 3px var(--remons-md-editor-color-focus-shadow);
260
331
  }
261
332
  .edit-dialog-textarea {
262
333
  resize: vertical;
263
334
  font-family: inherit;
264
335
  }
265
- /*# sourceMappingURL=index.css.map */
336
+ /*$vite$:1*/
package/dist/index.d.ts CHANGED
@@ -1,98 +1,5 @@
1
- import * as React from 'react';
2
- import React__default from 'react';
3
- import { EditorView } from '@codemirror/view';
4
- import { EditorState } from '@codemirror/state';
5
-
6
- interface MarkdownEditorRef {
7
- getContent: () => string;
8
- }
9
- interface MarkdownEditorProps {
10
- /** 初始内容 */
11
- defaultValue?: string;
12
- /** 受控内容 */
13
- value?: string;
14
- /** 内容变化回调 */
15
- onChange?: (value: string) => void;
16
- /** 是否显示预览面板 */
17
- showPreview?: boolean;
18
- /** 是否支持全屏 */
19
- fullscreen?: boolean;
20
- }
21
- declare const _default: React.ForwardRefExoticComponent<MarkdownEditorProps & React.RefAttributes<MarkdownEditorRef>>;
22
-
23
- interface ToolbarButtonConfig {
24
- id?: string;
25
- icon?: React__default.ComponentType;
26
- label?: string;
27
- children?: ToolbarButtonConfig[];
28
- handler?: (view: EditorView, state: EditorState) => void;
29
- separatorBefore?: boolean;
30
- customRender?: () => React__default.ReactNode;
31
- }
32
- /**
33
- * 弹窗属性配置
34
- * 用于定义 Markdown 容器中需要填充的属性字段
35
- */
36
- interface DialogField {
37
- /** 字段键名,用于 Markdown 属性填充 */
38
- key: string;
39
- /** 默认值 */
40
- defaultValue?: string;
41
- }
42
- /**
43
- * 组件 Schema
44
- * 每个容器组件(如 :::linkCard)定义可编辑字段和弹窗渲染逻辑
45
- */
46
- interface ComponentSchema {
47
- /** 容器名称,对应 :::name 语法 */
48
- name: string;
49
- /** 工具栏按钮显示的标签 */
50
- label: string;
51
- /** 工具栏按钮显示的图标 */
52
- icon?: React__default.ReactNode;
53
- /** 弹窗属性配置 — 用于定义 Markdown 内容中需要填充的字段 */
54
- fields: DialogField[];
55
- /**
56
- * 弹窗内容渲染函数(必填)
57
- * 接收当前属性值和回调函数,由用户完全自定义弹窗内容的渲染
58
- * @param props 当前属性值,用于回显
59
- * @param onChange 属性变更回调,用于更新表单值
60
- * @returns 弹窗内容的 ReactNode
61
- */
62
- renderDialog: (props: Record<string, string>, onChange: (key: string, value: string) => void) => React__default.ReactNode;
63
- }
64
-
65
- /**
66
- * 注册自定义容器组件到工具栏。支持单个或批量注册。
67
- * 支持 linkCard 形式的 schema(name + fields + renderDialog)。
68
- * fields 定义 Markdown 属性字段,renderDialog 定义弹窗内容。
69
- *
70
- * @example 单个注册
71
- * ```tsx
72
- * const schema: ComponentSchema = {
73
- * name: 'alert',
74
- * label: '警告框',
75
- * icon: <AlertOutlined />,
76
- * fields: [{ key: 'level', defaultValue: 'info' }],
77
- * renderDialog: (props, onChange) => (
78
- * <Input value={props.level} onChange={e => onChange('level', e.target.value)} />
79
- * ),
80
- * }
81
- *
82
- * function MyPage() {
83
- * useRegisterToolbar(schema)
84
- * return <MarkdownEditor />
85
- * }
86
- * ```
87
- *
88
- * @example 批量注册
89
- * ```tsx
90
- * function MyPage() {
91
- * useRegisterToolbar([schema1, schema2, schema3])
92
- * return <MarkdownEditor />
93
- * }
94
- * ```
95
- */
96
- declare function useRegisterToolbar(schemas: ComponentSchema | ComponentSchema[]): void;
97
-
98
- export { type ComponentSchema, type DialogField, _default as MarkdownEditor, type MarkdownEditorProps, type MarkdownEditorRef, type ToolbarButtonConfig, useRegisterToolbar };
1
+ export { default as MarkdownEditor } from './MarkdownEditor';
2
+ export type { MarkdownEditorProps, MarkdownEditorRef } from './MarkdownEditor';
3
+ export { useRegisterToolbar } from './hooks/useRegisterToolbar';
4
+ export type { ComponentSchema, DialogField, ToolbarButtonConfig, ImageUploadConfig, } from './types';
5
+ export type { PreviewOptions } from './components/Preview';