remons-markdown-editor 1.0.0-beta.1 → 1.0.0-beta.11

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 (33) 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/Panel/SplitPanels.d.ts +7 -0
  8. package/dist/components/Preview/index.d.ts +10 -0
  9. package/dist/components/Toolbar/buttons.d.ts +34 -0
  10. package/dist/components/Toolbar/config.d.ts +6 -0
  11. package/dist/components/Toolbar/hooks/useToolbar.d.ts +14 -0
  12. package/dist/components/Toolbar/index.d.ts +13 -0
  13. package/dist/components/Toolbar/renderers/TablePicker/TableDropdown.d.ts +5 -0
  14. package/dist/components/Toolbar/renderers/TablePicker/index.d.ts +9 -0
  15. package/dist/components/Toolbar/renderers/ToolbarItemRenderer.d.ts +7 -0
  16. package/dist/hooks/useFullscreen.d.ts +4 -0
  17. package/dist/hooks/useRegisterToolbar.d.ts +101 -0
  18. package/dist/hooks/useScrollSync.d.ts +6 -0
  19. package/dist/index.cjs +1480 -1198
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.css +185 -113
  22. package/dist/index.d.ts +5 -90
  23. package/dist/index.js +1456 -1178
  24. package/dist/index.js.map +1 -1
  25. package/dist/main.d.ts +0 -0
  26. package/dist/registry/componentRegistry.d.ts +34 -0
  27. package/dist/types/index.d.ts +148 -0
  28. package/dist/utils/parseContainer.d.ts +18 -0
  29. package/dist/utils/writeContainer.d.ts +16 -0
  30. package/package.json +79 -81
  31. package/readme.md +309 -81
  32. package/dist/index.css.map +0 -1
  33. package/dist/index.d.cts +0 -90
package/dist/index.css CHANGED
@@ -1,64 +1,203 @@
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
+ :where(.css-dev-only-do-not-override-19u5a7b).ant-btn:not(:disabled):not(.ant-btn-disabled):hover {
56
+ border: none !important;
57
+ background-color: var(--remons-md-editor-bg-hover) !important;
58
+ color: var(--remons-md-editor-color-text-hover) !important;
59
+ }
60
+
61
+ #markdown-editor {
62
+ height: 100vh;
63
+ width: 100vw;
64
+ overflow: hidden;
65
+ border-radius: 12px;
66
+ background: var(--remons-md-editor-bg-primary);
67
+ }
68
+
69
+ /* ===== CSS 自定义属性(主题变量) ===== */
70
+ /* 浅色主题(默认) */
71
+ :root,
72
+ [data-theme="light"] {
73
+ /* 背景色 */
74
+ --remons-md-editor-bg-primary: #f3f3f3;
75
+ --remons-md-editor-bg-white: rgba(255, 255, 255, 0.6);
76
+ --remons-md-editor-bg-hover: #e1e4e8;
77
+ --remons-md-editor-bg-active: #d0d7de;
78
+ --remons-md-editor-bg-fullscreen: #fff;
79
+
80
+ /* 文字颜色 */
81
+ --remons-md-editor-color-text: #24292f;
82
+ --remons-md-editor-color-text-hover: #0969da;
83
+
84
+ /* 边框 */
85
+ --remons-md-editor-color-border: rgba(255, 255, 255, 0.8);
86
+ --remons-md-editor-color-border-light: #d0d7de;
87
+
88
+ /* 焦点 */
89
+ --remons-md-editor-color-focus: #0969da;
90
+ --remons-md-editor-color-focus-shadow: rgba(9, 105, 218, 0.1);
91
+
92
+ /* 工具选择器 */
93
+ --remons-md-editor-bg-picker: #fff;
94
+ --remons-md-editor-bg-cell-active: #ddf4ff;
95
+ --remons-md-editor-color-cell-active: #91caff;
96
+ --remons-md-editor-color-hint: #999;
97
+ --remons-md-editor-color-label: #666;
98
+ }
99
+
100
+ /* ===== 深色主题 ===== */
101
+ [data-theme="dark"] {
102
+ /* 背景色 */
103
+ --remons-md-editor-bg-primary: #1a1d23;
104
+ --remons-md-editor-bg-white: rgba(46, 51, 80, 0.8);
105
+ --remons-md-editor-bg-hover: #4a5163;
106
+ --remons-md-editor-bg-active: #5a6278;
107
+ --remons-md-editor-bg-fullscreen: #1a1d23;
108
+
109
+ /* 文字颜色 */
110
+ --remons-md-editor-color-text: #c9d1d9;
111
+ --remons-md-editor-color-text-hover: #58a6ff;
112
+
113
+ /* 边框 */
114
+ --remons-md-editor-color-border: rgba(255, 255, 255, 0.1);
115
+ --remons-md-editor-color-border-light: #3a3f4b;
116
+
117
+ /* 焦点 */
118
+ --remons-md-editor-color-focus: #58a6ff;
119
+ --remons-md-editor-color-focus-shadow: rgba(88, 166, 255, 0.15);
120
+
121
+ /* 工具选择器 */
122
+ --remons-md-editor-bg-picker: #2e3350;
123
+ --remons-md-editor-bg-cell-active: #1a3a5c;
124
+ --remons-md-editor-color-cell-active: #58a6ff;
125
+ --remons-md-editor-color-hint: #8b949e;
126
+ --remons-md-editor-color-label: #8b949e;
127
+ }
128
+
129
+ .ant-anchor-link-title {
130
+ white-space: inherit !important;
131
+ }@font-face {
132
+ font-family: 'Inter';
133
+ font-style: normal;
134
+ font-weight: 400;
135
+ font-display: swap;
136
+ src: url(https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfMZg.ttf) format('truetype');
137
+ }
138
+ @font-face {
139
+ font-family: 'Inter';
140
+ font-style: normal;
141
+ font-weight: 500;
142
+ font-display: swap;
143
+ src: url(https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuI6fMZg.ttf) format('truetype');
144
+ }
145
+ @font-face {
146
+ font-family: 'Inter';
147
+ font-style: normal;
148
+ font-weight: 600;
149
+ font-display: swap;
150
+ src: url(https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuGKYMZg.ttf) format('truetype');
151
+ }
152
+ @font-face {
153
+ font-family: 'Inter';
154
+ font-style: normal;
155
+ font-weight: 700;
156
+ font-display: swap;
157
+ src: url(https://fonts.gstatic.com/s/inter/v20/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuFuYMZg.ttf) format('truetype');
158
+ }
159
+ @font-face {
160
+ font-family: 'Noto Sans SC';
161
+ font-style: normal;
162
+ font-weight: 400;
163
+ font-display: swap;
164
+ src: url(https://fonts.gstatic.com/s/notosanssc/v40/k3kCo84MPvpLmixcA63oeAL7Iqp5IZJF9bmaG9_FnYw.ttf) format('truetype');
165
+ }
166
+ @font-face {
167
+ font-family: 'Noto Sans SC';
168
+ font-style: normal;
169
+ font-weight: 500;
170
+ font-display: swap;
171
+ src: url(https://fonts.gstatic.com/s/notosanssc/v40/k3kCo84MPvpLmixcA63oeAL7Iqp5IZJF9bmaG-3FnYw.ttf) format('truetype');
172
+ }
173
+ @font-face {
174
+ font-family: 'Noto Sans SC';
175
+ font-style: normal;
176
+ font-weight: 600;
177
+ font-display: swap;
178
+ src: url(https://fonts.gstatic.com/s/notosanssc/v40/k3kCo84MPvpLmixcA63oeAL7Iqp5IZJF9bmaGwHCnYw.ttf) format('truetype');
179
+ }
180
+ @font-face {
181
+ font-family: 'Noto Sans SC';
182
+ font-style: normal;
183
+ font-weight: 700;
184
+ font-display: swap;
185
+ src: url(https://fonts.gstatic.com/s/notosanssc/v40/k3kCo84MPvpLmixcA63oeAL7Iqp5IZJF9bmaGzjCnYw.ttf) format('truetype');
186
+ }
187
+ .markdown-editor-app {
188
+ height: 100%;
51
189
  display: flex;
52
190
  flex-direction: column;
191
+ border: 1px solid var(--markdown-editor-color-border);
53
192
  }
54
- .app.fullscreen {
193
+ .markdown-editor-app.fullscreen {
55
194
  position: fixed;
56
195
  top: 0;
57
196
  left: 0;
58
197
  right: 0;
59
198
  bottom: 0;
60
199
  z-index: 9999;
61
- background: #fff;
200
+ background: var(--remons-md-editor-bg-fullscreen);
62
201
  width: 100vw;
63
202
  height: 100vh;
64
203
  }
@@ -67,8 +206,8 @@
67
206
  display: flex;
68
207
  align-items: center;
69
208
  padding: 4px 8px;
70
- background: #f6f8fa;
71
- border-bottom: 1px solid #d0d7de;
209
+ background: var(--remons-md-editor-bg-white);
210
+ border-bottom: 1px solid var(--remons-md-editor-color-border-light);
72
211
  gap: 4px;
73
212
  overflow-x: auto;
74
213
  }
@@ -90,16 +229,20 @@
90
229
  cursor: pointer;
91
230
  font-size: 16px;
92
231
  font-weight: 500;
93
- color: #24292f;
232
+ color: var(--remons-md-editor-color-text);
94
233
  transition: background-color 0.15s, color 0.15s;
95
234
  white-space: nowrap;
96
235
  }
236
+ .toolbar-button svg {
237
+ width: 16px;
238
+ height: 16px;
239
+ }
97
240
  .toolbar-button:hover {
98
- background: #e1e4e8;
99
- color: #0969da;
241
+ background: var(--remons-md-editor-bg-hover);
242
+ color: var(--remons-md-editor-color-text-hover);
100
243
  }
101
244
  .toolbar-button:active {
102
- background: #d0d7de;
245
+ background: var(--remons-md-editor-bg-active);
103
246
  }
104
247
  .toolbar-button.ant-btn {
105
248
  min-width: 32px;
@@ -109,8 +252,8 @@
109
252
  box-shadow: none !important;
110
253
  }
111
254
  .toolbar-button.ant-btn:hover {
112
- background: #e1e4e8;
113
- color: #0969da;
255
+ background: var(--remons-md-editor-bg-hover);
256
+ color: var(--remons-md-editor-color-text-hover);
114
257
  border-color: transparent !important;
115
258
  box-shadow: none !important;
116
259
  }
@@ -120,11 +263,13 @@
120
263
  }
121
264
  :where(.css-dev-only-do-not-override-u6izyw).ant-btn:not(:disabled):not(.ant-btn-disabled):hover {
122
265
  border: none !important;
266
+ background-color: var(--remons-md-editor-bg-hover) !important;
267
+ color: var(--remons-md-editor-color-text-hover) !important;
123
268
  }
124
269
  .toolbar-separator {
125
270
  width: 1px;
126
271
  height: 24px;
127
- background: #d0d7de;
272
+ background: var(--remons-md-editor-color-border-light);
128
273
  margin: 0 4px;
129
274
  }
130
275
  .split-panels {
@@ -142,16 +287,7 @@
142
287
  height: 100%;
143
288
  }
144
289
  .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;
290
+ font-family: Consolas, Inter, 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif !important;
155
291
  }
156
292
  .cm-editor {
157
293
  height: 100%;
@@ -160,78 +296,14 @@
160
296
  height: 100%;
161
297
  overflow: auto;
162
298
  }
299
+ /* 通用容器基类 */
163
300
  .md-container {
164
301
  margin: 16px 0;
165
302
  border-radius: 6px;
166
- border: 1px solid #d0d7de;
303
+ border: 1px solid var(--remons-md-editor-color-border-light);
167
304
  overflow: hidden;
168
305
  }
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
- }
306
+ /* 编辑弹窗样式 */
235
307
  .edit-dialog {
236
308
  padding: 8px 0;
237
309
  }
@@ -243,23 +315,23 @@
243
315
  margin-bottom: 6px;
244
316
  font-size: 14px;
245
317
  font-weight: 500;
246
- color: #24292f;
318
+ color: var(--remons-md-editor-color-text);
247
319
  }
248
320
  .edit-dialog-input {
249
321
  width: 100%;
250
322
  padding: 6px 10px;
251
323
  font-size: 14px;
252
- border: 1px solid #d0d7de;
324
+ border: 1px solid var(--remons-md-editor-color-border-light);
253
325
  border-radius: 6px;
254
326
  outline: none;
255
327
  transition: border-color 0.15s;
256
328
  }
257
329
  .edit-dialog-input:focus {
258
- border-color: #0969da;
259
- box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.1);
330
+ border-color: var(--remons-md-editor-color-focus);
331
+ box-shadow: 0 0 0 3px var(--remons-md-editor-color-focus-shadow);
260
332
  }
261
333
  .edit-dialog-textarea {
262
334
  resize: vertical;
263
335
  font-family: inherit;
264
336
  }
265
- /*# sourceMappingURL=index.css.map */
337
+ /*$vite$:1*/
package/dist/index.d.ts CHANGED
@@ -1,90 +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
- declare function useRegisterToolbar(schema: ComponentSchema): void;
89
-
90
- 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';