@jvs-milkdown/crepe 1.2.18 → 1.2.20
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/lib/cjs/feature/toolbar/index.js +47 -20
- package/lib/cjs/feature/toolbar/index.js.map +1 -1
- package/lib/cjs/index.js +166 -82
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/feature/toolbar/index.js +47 -20
- package/lib/esm/feature/toolbar/index.js.map +1 -1
- package/lib/esm/index.js +325 -241
- package/lib/esm/index.js.map +1 -1
- package/lib/theme/common/toolbar.css +3 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/core/crepe.d.ts +1 -0
- package/lib/types/core/crepe.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/component.d.ts.map +1 -1
- package/lib/types/feature/fixed-toolbar/menu-bar.d.ts.map +1 -1
- package/lib/types/feature/toolbar/component.d.ts.map +1 -1
- package/lib/types/utils/fixed-toolbar-popup-state.d.ts +1 -0
- package/lib/types/utils/fixed-toolbar-popup-state.d.ts.map +1 -1
- package/package.json +116 -62
- package/src/core/crepe.ts +83 -21
- package/src/feature/fixed-toolbar/component.tsx +3 -6
- package/src/feature/fixed-toolbar/index.ts +1 -1
- package/src/feature/fixed-toolbar/menu-bar.tsx +0 -1
- package/src/feature/toolbar/component.tsx +55 -21
- package/src/theme/common/toolbar.css +3 -0
- package/src/utils/fixed-toolbar-popup-state.ts +5 -0
- package/LICENSE +0 -21
|
@@ -549,7 +549,11 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
549
549
|
|
|
550
550
|
if (!isFixed) {
|
|
551
551
|
const view = ctx.get(editorViewCtx)
|
|
552
|
-
|
|
552
|
+
const containerDOM =
|
|
553
|
+
view.dom.closest('.milkdown-editor-container') ||
|
|
554
|
+
view.dom.closest('.milkdown') ||
|
|
555
|
+
view.dom
|
|
556
|
+
container.style.maxWidth = `${containerDOM.clientWidth - 32}px`
|
|
553
557
|
}
|
|
554
558
|
|
|
555
559
|
// For fixed toolbar: use available space in parent (minus MenuBar & separator)
|
|
@@ -573,18 +577,17 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
573
577
|
}
|
|
574
578
|
} else {
|
|
575
579
|
const view = ctx.get(editorViewCtx)
|
|
576
|
-
|
|
580
|
+
const containerDOM =
|
|
581
|
+
view.dom.closest('.milkdown-editor-container') ||
|
|
582
|
+
view.dom.closest('.milkdown') ||
|
|
583
|
+
view.dom
|
|
584
|
+
containerWidth = containerDOM.clientWidth - 32
|
|
577
585
|
}
|
|
578
586
|
|
|
579
|
-
if (containerWidth === lastContainerWidth) {
|
|
580
|
-
return
|
|
581
|
-
}
|
|
582
|
-
lastContainerWidth = containerWidth
|
|
583
|
-
|
|
584
587
|
if (showOverflowMenu.value) {
|
|
585
588
|
showOverflowMenu.value = false
|
|
586
589
|
}
|
|
587
|
-
const MORE_BUTTON_WIDTH =
|
|
590
|
+
const MORE_BUTTON_WIDTH = 56
|
|
588
591
|
const children = Array.from(container.children) as HTMLElement[]
|
|
589
592
|
const toolbarChildren = children.filter(
|
|
590
593
|
(el): el is HTMLElement =>
|
|
@@ -598,6 +601,15 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
598
601
|
totalWidth += measureChild(child, i)
|
|
599
602
|
}
|
|
600
603
|
|
|
604
|
+
if (totalWidth === 0) {
|
|
605
|
+
return
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (containerWidth === lastContainerWidth) {
|
|
609
|
+
return
|
|
610
|
+
}
|
|
611
|
+
lastContainerWidth = containerWidth
|
|
612
|
+
|
|
601
613
|
if (totalWidth <= containerWidth) {
|
|
602
614
|
overflowVisibleCount.value = Infinity
|
|
603
615
|
totalSectionCount.value = toolbarChildren.length
|
|
@@ -808,6 +820,16 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
808
820
|
} else {
|
|
809
821
|
const view = ctx.get(editorViewCtx)
|
|
810
822
|
overflowResizeObserver.observe(view.dom)
|
|
823
|
+
|
|
824
|
+
const containerDOM = view.dom.closest('.milkdown-editor-container')
|
|
825
|
+
if (containerDOM) {
|
|
826
|
+
overflowResizeObserver.observe(containerDOM)
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
const rootDOM = view.dom.closest('.milkdown')
|
|
830
|
+
if (rootDOM) {
|
|
831
|
+
overflowResizeObserver.observe(rootDOM)
|
|
832
|
+
}
|
|
811
833
|
}
|
|
812
834
|
computeOverflow()
|
|
813
835
|
}
|
|
@@ -849,6 +871,18 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
849
871
|
setTimeout(computeOverflow, 0)
|
|
850
872
|
})
|
|
851
873
|
|
|
874
|
+
watch(
|
|
875
|
+
() => props.show?.value,
|
|
876
|
+
(val) => {
|
|
877
|
+
if (val) {
|
|
878
|
+
cachedWidths.clear()
|
|
879
|
+
overflowVisibleCount.value = Infinity
|
|
880
|
+
lastContainerWidth = 0
|
|
881
|
+
setTimeout(computeOverflow, 0)
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
)
|
|
885
|
+
|
|
852
886
|
const onClick = (fn: (ctx: Ctx) => void) => (e: MouseEvent) => {
|
|
853
887
|
e.preventDefault()
|
|
854
888
|
if (ctx) fn(ctx)
|
|
@@ -1398,7 +1432,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
1398
1432
|
<div
|
|
1399
1433
|
style={{
|
|
1400
1434
|
position: 'relative',
|
|
1401
|
-
display: isSectionOverflowed(
|
|
1435
|
+
display: isSectionOverflowed(1) ? 'none' : 'flex',
|
|
1402
1436
|
flexShrink: 0,
|
|
1403
1437
|
}}
|
|
1404
1438
|
>
|
|
@@ -1444,7 +1478,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
1444
1478
|
style={{
|
|
1445
1479
|
margin: '0 4px',
|
|
1446
1480
|
alignSelf: 'center',
|
|
1447
|
-
display: isSectionOverflowed(
|
|
1481
|
+
display: isSectionOverflowed(2) ? 'none' : undefined,
|
|
1448
1482
|
flexShrink: 0,
|
|
1449
1483
|
}}
|
|
1450
1484
|
></div>
|
|
@@ -1456,7 +1490,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
1456
1490
|
onMouseleave={handleFontFamilyLeave}
|
|
1457
1491
|
style={{
|
|
1458
1492
|
position: 'relative',
|
|
1459
|
-
display: isSectionOverflowed(
|
|
1493
|
+
display: isSectionOverflowed(3) ? 'none' : 'flex',
|
|
1460
1494
|
alignItems: 'center',
|
|
1461
1495
|
padding: '0 6px',
|
|
1462
1496
|
minWidth: '50px',
|
|
@@ -1502,7 +1536,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
1502
1536
|
onMouseleave={handleFontSizeLeave}
|
|
1503
1537
|
style={{
|
|
1504
1538
|
position: 'relative',
|
|
1505
|
-
display: isSectionOverflowed(
|
|
1539
|
+
display: isSectionOverflowed(4) ? 'none' : 'flex',
|
|
1506
1540
|
alignItems: 'center',
|
|
1507
1541
|
padding: '0 6px',
|
|
1508
1542
|
minWidth: '40px',
|
|
@@ -1533,7 +1567,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
1533
1567
|
style={{
|
|
1534
1568
|
margin: '0 4px',
|
|
1535
1569
|
alignSelf: 'center',
|
|
1536
|
-
display: isSectionOverflowed(
|
|
1570
|
+
display: isSectionOverflowed(5) ? 'none' : undefined,
|
|
1537
1571
|
flexShrink: 0,
|
|
1538
1572
|
}}
|
|
1539
1573
|
></div>
|
|
@@ -1545,7 +1579,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
1545
1579
|
onMouseleave={handleAlignLeave}
|
|
1546
1580
|
style={{
|
|
1547
1581
|
position: 'relative',
|
|
1548
|
-
display: isSectionOverflowed(
|
|
1582
|
+
display: isSectionOverflowed(6) ? 'none' : 'flex',
|
|
1549
1583
|
alignItems: 'center',
|
|
1550
1584
|
padding: '0 6px',
|
|
1551
1585
|
flexShrink: 0,
|
|
@@ -1575,7 +1609,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
1575
1609
|
onMouseleave={handleColorLeave}
|
|
1576
1610
|
style={{
|
|
1577
1611
|
position: 'relative',
|
|
1578
|
-
display: isSectionOverflowed(
|
|
1612
|
+
display: isSectionOverflowed(7) ? 'none' : 'flex',
|
|
1579
1613
|
alignItems: 'center',
|
|
1580
1614
|
padding: '0 4px',
|
|
1581
1615
|
flexShrink: 0,
|
|
@@ -1608,7 +1642,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
1608
1642
|
|
|
1609
1643
|
{/* Formatting Tools (sections 7+) */}
|
|
1610
1644
|
{(() => {
|
|
1611
|
-
let sectionIdx =
|
|
1645
|
+
let sectionIdx = 8
|
|
1612
1646
|
return nonHeadingGroups.map((group: any, groupIndex: number) => {
|
|
1613
1647
|
const items = group.items.map((item: any) => {
|
|
1614
1648
|
const idx = sectionIdx
|
|
@@ -2607,7 +2641,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
2607
2641
|
)
|
|
2608
2642
|
}
|
|
2609
2643
|
// Section 2: Font Family
|
|
2610
|
-
if (
|
|
2644
|
+
if (3 >= cutoff) {
|
|
2611
2645
|
items.push(
|
|
2612
2646
|
renderIconButton(
|
|
2613
2647
|
textIcon,
|
|
@@ -2621,7 +2655,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
2621
2655
|
)
|
|
2622
2656
|
}
|
|
2623
2657
|
// Section 3: Font Size
|
|
2624
|
-
if (
|
|
2658
|
+
if (4 >= cutoff) {
|
|
2625
2659
|
items.push(
|
|
2626
2660
|
renderIconButton(
|
|
2627
2661
|
textIcon,
|
|
@@ -2635,7 +2669,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
2635
2669
|
)
|
|
2636
2670
|
}
|
|
2637
2671
|
// Section 5: Alignment
|
|
2638
|
-
if (
|
|
2672
|
+
if (6 >= cutoff) {
|
|
2639
2673
|
items.push(
|
|
2640
2674
|
renderIconButton(
|
|
2641
2675
|
currentAlignIndent.value.align === 'center'
|
|
@@ -2653,7 +2687,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
2653
2687
|
)
|
|
2654
2688
|
}
|
|
2655
2689
|
// Section 6: Color
|
|
2656
|
-
if (
|
|
2690
|
+
if (7 >= cutoff) {
|
|
2657
2691
|
items.push(
|
|
2658
2692
|
renderIconButton(
|
|
2659
2693
|
fontColorIcon,
|
|
@@ -2667,7 +2701,7 @@ export const Toolbar = defineComponent<ToolbarProps>({
|
|
|
2667
2701
|
)
|
|
2668
2702
|
}
|
|
2669
2703
|
// Formatting buttons (section 7+)
|
|
2670
|
-
let fmtIdx =
|
|
2704
|
+
let fmtIdx = 8
|
|
2671
2705
|
for (const group of nonHeadingGroups) {
|
|
2672
2706
|
for (const item of group.items) {
|
|
2673
2707
|
const idx = fmtIdx
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020-present Mirone
|
|
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.
|