@jvs-milkdown/crepe 1.2.29 → 1.2.30

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 (38) hide show
  1. package/lib/cjs/builder.js +2 -1
  2. package/lib/cjs/builder.js.map +1 -1
  3. package/lib/cjs/feature/toolbar/index.js +84 -62
  4. package/lib/cjs/feature/toolbar/index.js.map +1 -1
  5. package/lib/cjs/index.js +1121 -988
  6. package/lib/cjs/index.js.map +1 -1
  7. package/lib/esm/builder.js +2 -1
  8. package/lib/esm/builder.js.map +1 -1
  9. package/lib/esm/feature/toolbar/index.js +84 -62
  10. package/lib/esm/feature/toolbar/index.js.map +1 -1
  11. package/lib/esm/index.js +1143 -1010
  12. package/lib/esm/index.js.map +1 -1
  13. package/lib/theme/common/image-block.css +5 -1
  14. package/lib/theme/common/reset.css +1 -1
  15. package/lib/theme/common/table.css +5 -0
  16. package/lib/theme/common/toolbar.css +23 -0
  17. package/lib/tsconfig.tsbuildinfo +1 -1
  18. package/lib/types/feature/fixed-toolbar/component.d.ts +2 -2
  19. package/lib/types/feature/fixed-toolbar/component.d.ts.map +1 -1
  20. package/lib/types/feature/fixed-toolbar/index.d.ts +2 -0
  21. package/lib/types/feature/fixed-toolbar/index.d.ts.map +1 -1
  22. package/lib/types/feature/fixed-toolbar/outline-panel.d.ts.map +1 -1
  23. package/lib/types/feature/fixed-toolbar/view-menu-state.d.ts +3 -0
  24. package/lib/types/feature/fixed-toolbar/view-menu-state.d.ts.map +1 -1
  25. package/lib/types/feature/toolbar/component.d.ts +2 -2
  26. package/lib/types/feature/toolbar/component.d.ts.map +1 -1
  27. package/lib/types/feature/toolbar/index.d.ts.map +1 -1
  28. package/package.json +4 -4
  29. package/src/feature/fixed-toolbar/component.tsx +203 -110
  30. package/src/feature/fixed-toolbar/index.ts +30 -8
  31. package/src/feature/fixed-toolbar/outline-panel.tsx +1 -2
  32. package/src/feature/fixed-toolbar/view-menu-state.ts +2 -0
  33. package/src/feature/toolbar/component.tsx +57 -44
  34. package/src/feature/toolbar/index.ts +9 -13
  35. package/src/theme/common/image-block.css +6 -1
  36. package/src/theme/common/reset.css +1 -1
  37. package/src/theme/common/table.css +5 -0
  38. package/src/theme/common/toolbar.css +30 -0
@@ -1,5 +1,6 @@
1
1
  import type { Ctx } from '@jvs-milkdown/kit/ctx'
2
2
  import type { Mark } from '@jvs-milkdown/kit/prose/model'
3
+ import type { EditorState } from '@jvs-milkdown/kit/prose/state'
3
4
 
4
5
  import { Icon } from '@jvs-milkdown/kit/component'
5
6
  import {
@@ -14,11 +15,7 @@ import {
14
15
  selectTextNearPosCommand,
15
16
  } from '@jvs-milkdown/kit/preset/commonmark'
16
17
  import { createTable, mergeCellsCommand } from '@jvs-milkdown/kit/preset/gfm'
17
- import {
18
- type Selection,
19
- TextSelection,
20
- NodeSelection,
21
- } from '@jvs-milkdown/kit/prose/state'
18
+ import { TextSelection, NodeSelection } from '@jvs-milkdown/kit/prose/state'
22
19
  import {
23
20
  mergeCells,
24
21
  splitCell,
@@ -144,7 +141,7 @@ type ToolbarProps = {
144
141
  ctx: Ctx
145
142
  hide: () => void
146
143
  show: Ref<boolean>
147
- selection: ShallowRef<Selection>
144
+ state: ShallowRef<EditorState>
148
145
  config?: ToolbarFeatureConfig
149
146
  isFixed?: boolean
150
147
  }
@@ -167,7 +164,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
167
164
  ctx: { type: Object as any, required: true },
168
165
  hide: { type: Function as any, required: true },
169
166
  show: { type: Object as any, required: true },
170
- selection: { type: Object as any, required: true },
167
+ state: { type: Object as any, required: true },
171
168
  config: { type: Object as any, required: false },
172
169
  isFixed: { type: Boolean, required: false },
173
170
  },
@@ -903,7 +900,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
903
900
  }
904
901
 
905
902
  function checkActive(checker: ToolbarItem['active']) {
906
- keepAlive(props.selection.value)
903
+ keepAlive(props.state, props.state?.value)
907
904
  const status = ctx?.get(editorCtx)?.status
908
905
  if (status !== EditorStatus.Created) return false
909
906
  return checker(ctx)
@@ -912,7 +909,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
912
909
  const blockGroups = computed(() => getBlockGroups('', undefined, ctx))
913
910
 
914
911
  const activeBlockItem = computed(() => {
915
- keepAlive(props.selection.value)
912
+ keepAlive(props.state, props.state?.value)
916
913
  const status = ctx?.get(editorCtx)?.status
917
914
  if (status !== EditorStatus.Created) return null
918
915
 
@@ -957,7 +954,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
957
954
  })
958
955
 
959
956
  const currentAlignIndent = computed(() => {
960
- keepAlive(props.selection.value)
957
+ keepAlive(props.state, props.state?.value)
961
958
  const status = ctx?.get(editorCtx)?.status
962
959
  if (status !== EditorStatus.Created) return { align: 'left', indent: 0 }
963
960
  const view = ctx.get(editorViewCtx)
@@ -1052,14 +1049,14 @@ export const Toolbar = defineComponent<ToolbarProps>({
1052
1049
  }
1053
1050
 
1054
1051
  const canMerge = computed(() => {
1055
- keepAlive(props.selection.value)
1052
+ keepAlive(props.state, props.state?.value)
1056
1053
  const view = ctx?.get(editorViewCtx)
1057
1054
  if (!view) return false
1058
1055
  return mergeCells(view.state)
1059
1056
  })
1060
1057
 
1061
1058
  const canSplit = computed(() => {
1062
- keepAlive(props.selection.value)
1059
+ keepAlive(props.state, props.state?.value)
1063
1060
  const view = ctx?.get(editorViewCtx)
1064
1061
  if (!view) return false
1065
1062
  return splitCell(view.state)
@@ -1136,7 +1133,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
1136
1133
  }
1137
1134
 
1138
1135
  const currentColorState = computed(() => {
1139
- keepAlive(props.selection.value)
1136
+ keepAlive(props.state, props.state?.value)
1140
1137
  const status = ctx?.get(editorCtx)?.status
1141
1138
  if (status !== EditorStatus.Created)
1142
1139
  return { textColor: null, bgColor: null }
@@ -1145,8 +1142,8 @@ export const Toolbar = defineComponent<ToolbarProps>({
1145
1142
  const { state } = view
1146
1143
  const schema = ctx.get(schemaCtx)
1147
1144
 
1148
- const tcHasMark = schema.marks[textColorSchema.id]
1149
- const bcHasMark = schema.marks[bgColorSchema.id]
1145
+ const tcHasMark = schema.marks['textColor']
1146
+ const bcHasMark = schema.marks['bgColor']
1150
1147
 
1151
1148
  if (!tcHasMark || !bcHasMark) return { textColor: null, bgColor: null }
1152
1149
 
@@ -1204,8 +1201,8 @@ export const Toolbar = defineComponent<ToolbarProps>({
1204
1201
  const { from, to, empty } = state.selection
1205
1202
  const schema = ctx.get(schemaCtx)
1206
1203
 
1207
- const tcHasMark = schema.marks[textColorSchema.id]
1208
- const bcHasMark = schema.marks[bgColorSchema.id]
1204
+ const tcHasMark = schema.marks['textColor']
1205
+ const bcHasMark = schema.marks['bgColor']
1209
1206
 
1210
1207
  if (!tcHasMark || !bcHasMark) return
1211
1208
 
@@ -1227,7 +1224,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
1227
1224
  }
1228
1225
 
1229
1226
  const currentFontState = computed(() => {
1230
- keepAlive(props.selection.value)
1227
+ keepAlive(props.state, props.state?.value)
1231
1228
  const status = ctx?.get(editorCtx)?.status
1232
1229
  if (status !== EditorStatus.Created)
1233
1230
  return { fontFamily: null, fontSize: null }
@@ -1236,24 +1233,32 @@ export const Toolbar = defineComponent<ToolbarProps>({
1236
1233
  const { state } = view
1237
1234
  const schema = ctx.get(schemaCtx)
1238
1235
 
1239
- const ffHasMark = schema.marks[fontFamilySchema.id]
1240
- const fsHasMark = schema.marks[fontSizeSchema.id]
1236
+ const ffHasMark = schema.marks['fontFamily']
1237
+ const fsHasMark = schema.marks['fontSize']
1241
1238
 
1242
- if (!ffHasMark || !fsHasMark) return { fontFamily: null, fontSize: null }
1239
+ if (!ffHasMark || !fsHasMark) {
1240
+ return { fontFamily: null, fontSize: null }
1241
+ }
1243
1242
 
1244
1243
  const ffType = fontFamilySchema.type(ctx)
1245
1244
  const fsType = fontSizeSchema.type(ctx)
1246
1245
  const { $cursor, ranges } = state.selection as any
1247
1246
 
1247
+ let result: { fontFamily: string | null; fontSize: string | null } = {
1248
+ fontFamily: null,
1249
+ fontSize: null,
1250
+ }
1248
1251
  if ($cursor) {
1249
- let fontFamily = null
1250
- let fontSize = null
1252
+ let fontFamily: string | null = null
1253
+ let fontSize: string | null = null
1251
1254
  const marks = state.storedMarks || $cursor.marks()
1252
1255
  for (const mark of marks) {
1253
- if (mark.type === ffType) fontFamily = mark.attrs.fontFamily
1254
- if (mark.type === fsType) fontSize = mark.attrs.fontSize
1256
+ if (mark.type === ffType)
1257
+ fontFamily = (mark.attrs.fontFamily as string | null) || null
1258
+ if (mark.type === fsType)
1259
+ fontSize = (mark.attrs.fontSize as string | null) || null
1255
1260
  }
1256
- return { fontFamily, fontSize }
1261
+ result = { fontFamily, fontSize }
1257
1262
  } else {
1258
1263
  const fontFamilies = new Set<string | null>()
1259
1264
  const fontSizes = new Set<string | null>()
@@ -1264,19 +1269,24 @@ export const Toolbar = defineComponent<ToolbarProps>({
1264
1269
  if (node.isText) {
1265
1270
  const ffMark = ffType.isInSet(node.marks)
1266
1271
  const fsMark = fsType.isInSet(node.marks)
1267
- fontFamilies.add(ffMark ? ffMark.attrs.fontFamily : null)
1268
- fontSizes.add(fsMark ? fsMark.attrs.fontSize : null)
1272
+ fontFamilies.add(
1273
+ ffMark ? (ffMark.attrs.fontFamily as string | null) : null
1274
+ )
1275
+ fontSizes.add(
1276
+ fsMark ? (fsMark.attrs.fontSize as string | null) : null
1277
+ )
1269
1278
  }
1270
1279
  })
1271
1280
  }
1272
1281
 
1273
1282
  const fontFamily =
1274
- fontFamilies.size === 1 ? Array.from(fontFamilies)[0] : 'mixed'
1283
+ fontFamilies.size === 1 ? Array.from(fontFamilies)[0]! : 'mixed'
1275
1284
  const fontSize =
1276
- fontSizes.size === 1 ? Array.from(fontSizes)[0] : 'mixed'
1285
+ fontSizes.size === 1 ? Array.from(fontSizes)[0]! : 'mixed'
1277
1286
 
1278
- return { fontFamily, fontSize }
1287
+ result = { fontFamily, fontSize }
1279
1288
  }
1289
+ return result
1280
1290
  })
1281
1291
 
1282
1292
  const setFontFamily = (fontFamily: string | null) => {
@@ -1521,15 +1531,18 @@ export const Toolbar = defineComponent<ToolbarProps>({
1521
1531
  color: '#363B4C',
1522
1532
  }}
1523
1533
  >
1524
- {currentFontState.value.fontFamily &&
1525
- currentFontState.value.fontFamily !== 'mixed'
1526
- ? currentFontState.value.fontFamily
1527
- .split(',')[0]
1528
- .replace(/['"]/g, '') ||
1529
- (ctx ? i18n(ctx, 'customMenu.fontDefault' as any) : '默认')
1530
- : ctx
1531
- ? i18n(ctx, 'customMenu.fontDefault' as any)
1532
- : '默认'}
1534
+ {(() => {
1535
+ const fontState = currentFontState.value
1536
+ const fontFamily = fontState?.fontFamily
1537
+ return fontFamily && fontFamily !== 'mixed'
1538
+ ? fontFamily.split(',')[0]!.replace(/['"]/g, '') ||
1539
+ (ctx
1540
+ ? i18n(ctx, 'customMenu.fontDefault' as any)
1541
+ : '默认')
1542
+ : ctx
1543
+ ? i18n(ctx, 'customMenu.fontDefault' as any)
1544
+ : '默认'
1545
+ })()}
1533
1546
  </span>
1534
1547
  <span
1535
1548
  style={{
@@ -1558,10 +1571,10 @@ export const Toolbar = defineComponent<ToolbarProps>({
1558
1571
  }}
1559
1572
  >
1560
1573
  <span style={{ fontSize: '13px', color: '#363B4C' }}>
1561
- {currentFontState.value.fontSize &&
1562
- currentFontState.value.fontSize !== 'mixed'
1563
- ? currentFontState.value.fontSize
1564
- : '16px'}
1574
+ {(() => {
1575
+ const fs = currentFontState.value.fontSize
1576
+ return fs && fs !== 'mixed' ? fs : '16px'
1577
+ })()}
1565
1578
  </span>
1566
1579
  <span
1567
1580
  style={{
@@ -1,9 +1,5 @@
1
1
  import type { Ctx } from '@jvs-milkdown/kit/ctx'
2
- import type {
3
- EditorState,
4
- PluginView,
5
- Selection,
6
- } from '@jvs-milkdown/kit/prose/state'
2
+ import type { EditorState, PluginView } from '@jvs-milkdown/kit/prose/state'
7
3
  import type { EditorView } from '@jvs-milkdown/kit/prose/view'
8
4
 
9
5
  import { editorViewOptionsCtx } from '@jvs-milkdown/kit/core'
@@ -21,14 +17,14 @@ import type { ToolbarItem } from './config'
21
17
 
22
18
  import { crepeFeatureConfig } from '../../core/slice'
23
19
  import { CrepeFeature } from '../../feature'
24
- import { colorPlugins } from './color'
25
- import { Toolbar } from './component'
26
- import { highlightMark } from './highlight-mark'
27
- import { underline } from './underline'
28
20
  import {
29
21
  getIsAnyPopupOpen,
30
22
  addPopupChangeListener,
31
23
  } from '../../utils/fixed-toolbar-popup-state'
24
+ import { colorPlugins } from './color'
25
+ import { Toolbar } from './component'
26
+ import { highlightMark } from './highlight-mark'
27
+ import { underline } from './underline'
32
28
 
33
29
  interface ToolbarConfig {
34
30
  boldIcon: string
@@ -56,7 +52,7 @@ class ToolbarView implements PluginView {
56
52
  #tooltipProvider: TooltipProvider
57
53
  #content: HTMLElement
58
54
  #app: App
59
- #selection: ShallowRef<Selection>
55
+ #state: ShallowRef<EditorState>
60
56
  #show = ref(false)
61
57
  #mousePressed = false
62
58
  #removePopupListener: (() => void) | undefined
@@ -65,12 +61,12 @@ class ToolbarView implements PluginView {
65
61
  constructor(ctx: Ctx, view: EditorView, config?: ToolbarFeatureConfig) {
66
62
  const content = document.createElement('div')
67
63
  content.className = 'milkdown-toolbar'
68
- this.#selection = shallowRef(view.state.selection)
64
+ this.#state = shallowRef(view.state)
69
65
  const app = createApp(Toolbar, {
70
66
  ctx,
71
67
  hide: this.hide,
72
68
  config,
73
- selection: this.#selection,
69
+ state: this.#state,
74
70
  show: this.#show,
75
71
  })
76
72
  app.mount(content)
@@ -161,7 +157,7 @@ class ToolbarView implements PluginView {
161
157
 
162
158
  update = (view: EditorView, prevState?: EditorState) => {
163
159
  this.#tooltipProvider.update(view, prevState)
164
- this.#selection.value = view.state.selection
160
+ this.#state.value = view.state
165
161
  }
166
162
 
167
163
  destroy = () => {
@@ -155,7 +155,7 @@
155
155
  position: relative;
156
156
 
157
157
  &:hover {
158
- z-index: 120;
158
+ z-index: 210;
159
159
  }
160
160
 
161
161
  & > .image-wrapper {
@@ -325,6 +325,11 @@
325
325
  &:hover {
326
326
  background: var(--crepe-color-hover);
327
327
  }
328
+
329
+ &.active {
330
+ background: var(--crepe-color-selected);
331
+ color: var(--crepe-color-primary);
332
+ }
328
333
  }
329
334
 
330
335
  .image-wrapper .image-resize-handle {
@@ -36,7 +36,7 @@
36
36
 
37
37
  font-family: var(--crepe-font-default);
38
38
  color: var(--crepe-color-on-background);
39
- background: var(--crepe-color-surface);
39
+ background: transparent;
40
40
 
41
41
  .milkdown-icon {
42
42
  display: inline-flex;
@@ -4,6 +4,11 @@
4
4
  .milkdown-table-block {
5
5
  display: block;
6
6
  margin: 12px 0 4px 0;
7
+ position: relative;
8
+
9
+ &:hover {
10
+ z-index: 210;
11
+ }
7
12
 
8
13
  table {
9
14
  width: auto;
@@ -100,6 +100,36 @@
100
100
  min-width: 0;
101
101
  max-width: 100%;
102
102
  box-sizing: border-box;
103
+ transition: all 0.2s ease-in-out;
104
+
105
+ &.collapsed {
106
+ background: transparent !important;
107
+ border-bottom: none !important;
108
+ height: 0 !important;
109
+ min-height: 0 !important;
110
+ padding: 0 !important;
111
+ overflow: visible !important;
112
+ pointer-events: none;
113
+ }
114
+
115
+ .fixed-toolbar-expand-btn {
116
+ svg {
117
+ width: 20px !important;
118
+ height: 20px !important;
119
+ path {
120
+ fill: var(--crepe-color-on-surface, #363b4c);
121
+ }
122
+ }
123
+ }
124
+
125
+ .toolbar-item.collapse-btn {
126
+ --toolbar-icon-color: #363b4c;
127
+ svg {
128
+ path {
129
+ fill: currentColor !important;
130
+ }
131
+ }
132
+ }
103
133
 
104
134
  .toolbar-shortcut-btn {
105
135
  display: flex;