@easyx/editor 1.0.0 → 1.1.0
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/dist/index.cjs +186 -20
- package/dist/index.js +186 -20
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -50,11 +50,13 @@ var __webpack_modules__ = {
|
|
|
50
50
|
--easyx-editor-toolbar-bg: #fff;
|
|
51
51
|
--easyx-editor-toolbar-border: #e5e7eb;
|
|
52
52
|
--easyx-editor-toolbar-padding: 6px;
|
|
53
|
+
--easyx-editor-toolbar-gap: 2px;
|
|
53
54
|
--easyx-editor-toolbar-btn-hover: #f3f4f6;
|
|
54
55
|
--easyx-editor-toolbar-btn-active: #e0e7ff;
|
|
55
56
|
--easyx-editor-toolbar-btn-size: 32px;
|
|
56
57
|
--easyx-editor-toolbar-btn-radius: 6px;
|
|
57
58
|
--easyx-editor-toolbar-btn-color: #4b5563;
|
|
59
|
+
--easyx-editor-toolbar-btn-disabled: #9ca3af;
|
|
58
60
|
--easyx-editor-toolbar-divider: #e5e7eb;
|
|
59
61
|
--easyx-editor-bubble-bg: #fff;
|
|
60
62
|
--easyx-editor-bubble-border: #e5e7eb;
|
|
@@ -108,8 +110,9 @@ var __webpack_modules__ = {
|
|
|
108
110
|
--easyx-editor-toolbar-bg: #1f2937;
|
|
109
111
|
--easyx-editor-toolbar-border: #374151;
|
|
110
112
|
--easyx-editor-toolbar-btn-hover: #374151;
|
|
111
|
-
--easyx-editor-toolbar-btn-active: #
|
|
113
|
+
--easyx-editor-toolbar-btn-active: #3730a3;
|
|
112
114
|
--easyx-editor-toolbar-btn-color: #d1d5db;
|
|
115
|
+
--easyx-editor-toolbar-btn-disabled: #6b7280;
|
|
113
116
|
--easyx-editor-toolbar-divider: #374151;
|
|
114
117
|
--easyx-editor-bubble-bg: #1f2937;
|
|
115
118
|
--easyx-editor-bubble-border: #374151;
|
|
@@ -132,6 +135,7 @@ var __webpack_modules__ = {
|
|
|
132
135
|
font-family: var(--easyx-editor-font-family);
|
|
133
136
|
font-size: var(--easyx-editor-font-size);
|
|
134
137
|
line-height: var(--easyx-editor-line-height);
|
|
138
|
+
box-sizing: border-box;
|
|
135
139
|
min-height: var(--easyx-editor-min-height);
|
|
136
140
|
border: 1px solid var(--easyx-editor-border);
|
|
137
141
|
border-radius: var(--easyx-editor-radius);
|
|
@@ -143,6 +147,64 @@ var __webpack_modules__ = {
|
|
|
143
147
|
border-color: var(--easyx-editor-border-focus);
|
|
144
148
|
}
|
|
145
149
|
|
|
150
|
+
.easyx-editor.easyx-editor-scroll {
|
|
151
|
+
flex-direction: column;
|
|
152
|
+
display: flex;
|
|
153
|
+
overflow: hidden;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.easyx-editor.easyx-editor-scroll .easyx-editor-content {
|
|
157
|
+
flex: auto;
|
|
158
|
+
min-height: 0;
|
|
159
|
+
overflow-y: auto;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.easyx-editor-resize-handle {
|
|
163
|
+
cursor: ns-resize;
|
|
164
|
+
z-index: 5;
|
|
165
|
+
touch-action: none;
|
|
166
|
+
background: none;
|
|
167
|
+
border: none;
|
|
168
|
+
height: 10px;
|
|
169
|
+
padding: 0;
|
|
170
|
+
position: absolute;
|
|
171
|
+
bottom: 0;
|
|
172
|
+
left: 0;
|
|
173
|
+
right: 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.easyx-editor-resize-handle:hover, .easyx-editor-resize-handle:focus-visible {
|
|
177
|
+
background: var(--easyx-editor-primary);
|
|
178
|
+
opacity: .12;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.easyx-editor-resize-handle:focus-visible {
|
|
182
|
+
outline: 2px solid var(--easyx-editor-primary);
|
|
183
|
+
outline-offset: -2px;
|
|
184
|
+
opacity: .25;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.easyx-editor-resize-handle-grip {
|
|
188
|
+
background: var(--easyx-editor-toolbar-divider);
|
|
189
|
+
pointer-events: none;
|
|
190
|
+
border-radius: 2px;
|
|
191
|
+
width: 40px;
|
|
192
|
+
height: 4px;
|
|
193
|
+
transition: background .15s;
|
|
194
|
+
position: absolute;
|
|
195
|
+
bottom: 2px;
|
|
196
|
+
left: 50%;
|
|
197
|
+
transform: translateX(-50%);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.easyx-editor-resize-handle:hover .easyx-editor-resize-handle-grip, .easyx-editor-resize-handle:focus-visible .easyx-editor-resize-handle-grip {
|
|
201
|
+
background: var(--easyx-editor-primary);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.easyx-editor.easyx-editor-resizing {
|
|
205
|
+
user-select: none;
|
|
206
|
+
}
|
|
207
|
+
|
|
146
208
|
.easyx-editor-disabled {
|
|
147
209
|
opacity: .6;
|
|
148
210
|
pointer-events: none;
|
|
@@ -707,14 +769,14 @@ var __webpack_modules__ = {
|
|
|
707
769
|
}
|
|
708
770
|
|
|
709
771
|
.easyx-editor-toolbar {
|
|
772
|
+
align-items: center;
|
|
773
|
+
gap: var(--easyx-editor-toolbar-gap);
|
|
710
774
|
padding: var(--easyx-editor-toolbar-padding);
|
|
711
775
|
background: var(--easyx-editor-toolbar-bg);
|
|
712
776
|
border-bottom: 1px solid var(--easyx-editor-toolbar-border);
|
|
713
777
|
border-radius: var(--easyx-editor-radius) var(--easyx-editor-radius) 0 0;
|
|
714
778
|
z-index: 99;
|
|
715
779
|
flex-wrap: wrap;
|
|
716
|
-
align-items: center;
|
|
717
|
-
gap: 2px;
|
|
718
780
|
display: flex;
|
|
719
781
|
position: sticky;
|
|
720
782
|
top: 0;
|
|
@@ -733,7 +795,7 @@ var __webpack_modules__ = {
|
|
|
733
795
|
padding: 0;
|
|
734
796
|
font-size: 14px;
|
|
735
797
|
line-height: 1;
|
|
736
|
-
transition: background .15s;
|
|
798
|
+
transition: background .15s, color .15s, opacity .15s;
|
|
737
799
|
display: inline-flex;
|
|
738
800
|
}
|
|
739
801
|
|
|
@@ -741,6 +803,11 @@ var __webpack_modules__ = {
|
|
|
741
803
|
background: var(--easyx-editor-toolbar-btn-hover);
|
|
742
804
|
}
|
|
743
805
|
|
|
806
|
+
.easyx-editor-toolbar-btn:focus-visible {
|
|
807
|
+
outline: 2px solid var(--easyx-editor-primary);
|
|
808
|
+
outline-offset: -2px;
|
|
809
|
+
}
|
|
810
|
+
|
|
744
811
|
.easyx-editor-toolbar-btn.is-active {
|
|
745
812
|
background: var(--easyx-editor-toolbar-btn-active);
|
|
746
813
|
color: var(--easyx-editor-primary);
|
|
@@ -748,8 +815,8 @@ var __webpack_modules__ = {
|
|
|
748
815
|
|
|
749
816
|
.easyx-editor-toolbar-btn svg {
|
|
750
817
|
fill: currentColor;
|
|
751
|
-
width:
|
|
752
|
-
height:
|
|
818
|
+
width: 18px;
|
|
819
|
+
height: 18px;
|
|
753
820
|
}
|
|
754
821
|
|
|
755
822
|
.easyx-editor-toolbar-btn--history.is-active {
|
|
@@ -758,7 +825,7 @@ var __webpack_modules__ = {
|
|
|
758
825
|
}
|
|
759
826
|
|
|
760
827
|
.easyx-editor-toolbar-btn--history:not(.is-active) {
|
|
761
|
-
|
|
828
|
+
color: var(--easyx-editor-toolbar-btn-disabled);
|
|
762
829
|
}
|
|
763
830
|
|
|
764
831
|
.easyx-editor-toolbar-btn--history:not(.is-active):hover {
|
|
@@ -787,27 +854,38 @@ var __webpack_modules__ = {
|
|
|
787
854
|
}
|
|
788
855
|
|
|
789
856
|
.easyx-editor-toolbar-select {
|
|
790
|
-
border: 1px solid var(--easyx-editor-toolbar-border);
|
|
791
857
|
border-radius: var(--easyx-editor-toolbar-btn-radius);
|
|
792
858
|
height: var(--easyx-editor-toolbar-btn-size);
|
|
793
859
|
cursor: pointer;
|
|
860
|
+
color: var(--easyx-editor-toolbar-btn-color);
|
|
794
861
|
background: none;
|
|
862
|
+
border: none;
|
|
795
863
|
outline: none;
|
|
796
864
|
align-items: center;
|
|
797
865
|
gap: 2px;
|
|
798
866
|
padding: 0 4px;
|
|
799
|
-
transition:
|
|
867
|
+
transition: background .15s, color .15s;
|
|
800
868
|
display: inline-flex;
|
|
801
869
|
}
|
|
802
870
|
|
|
803
871
|
.easyx-editor-toolbar-select:hover {
|
|
804
|
-
|
|
872
|
+
background: var(--easyx-editor-toolbar-btn-hover);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
.easyx-editor-toolbar-select:focus-visible {
|
|
876
|
+
outline: 2px solid var(--easyx-editor-primary);
|
|
877
|
+
outline-offset: -2px;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
.easyx-editor-toolbar-select.is-active {
|
|
881
|
+
background: var(--easyx-editor-toolbar-btn-active);
|
|
882
|
+
color: var(--easyx-editor-primary);
|
|
805
883
|
}
|
|
806
884
|
|
|
807
885
|
.easyx-editor-toolbar-select-icon {
|
|
808
886
|
width: var(--easyx-editor-toolbar-btn-size);
|
|
809
887
|
height: var(--easyx-editor-toolbar-btn-size);
|
|
810
|
-
color:
|
|
888
|
+
color: inherit;
|
|
811
889
|
pointer-events: none;
|
|
812
890
|
justify-content: center;
|
|
813
891
|
align-items: center;
|
|
@@ -816,14 +894,14 @@ var __webpack_modules__ = {
|
|
|
816
894
|
|
|
817
895
|
.easyx-editor-toolbar-select-icon svg {
|
|
818
896
|
fill: currentColor;
|
|
819
|
-
width:
|
|
820
|
-
height:
|
|
897
|
+
width: 16px;
|
|
898
|
+
height: 16px;
|
|
821
899
|
}
|
|
822
900
|
|
|
823
901
|
.easyx-editor-toolbar-select-value {
|
|
824
902
|
text-align: center;
|
|
825
|
-
width:
|
|
826
|
-
color:
|
|
903
|
+
min-width: 28px;
|
|
904
|
+
color: inherit;
|
|
827
905
|
white-space: nowrap;
|
|
828
906
|
font-size: 12px;
|
|
829
907
|
}
|
|
@@ -831,7 +909,7 @@ var __webpack_modules__ = {
|
|
|
831
909
|
.easyx-editor-toolbar-select-arrow {
|
|
832
910
|
width: 14px;
|
|
833
911
|
height: 14px;
|
|
834
|
-
color:
|
|
912
|
+
color: inherit;
|
|
835
913
|
flex-shrink: 0;
|
|
836
914
|
justify-content: center;
|
|
837
915
|
align-items: center;
|
|
@@ -1021,6 +1099,11 @@ var __webpack_modules__ = {
|
|
|
1021
1099
|
background: var(--easyx-editor-bubble-btn-hover);
|
|
1022
1100
|
}
|
|
1023
1101
|
|
|
1102
|
+
.easyx-editor-bubble-btn:focus-visible {
|
|
1103
|
+
outline: 2px solid var(--easyx-editor-primary);
|
|
1104
|
+
outline-offset: -2px;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1024
1107
|
.easyx-editor-bubble-btn.is-active {
|
|
1025
1108
|
background: var(--easyx-editor-bubble-btn-active);
|
|
1026
1109
|
color: var(--easyx-editor-primary);
|
|
@@ -1028,8 +1111,8 @@ var __webpack_modules__ = {
|
|
|
1028
1111
|
|
|
1029
1112
|
.easyx-editor-bubble-btn svg {
|
|
1030
1113
|
fill: currentColor;
|
|
1031
|
-
width:
|
|
1032
|
-
height:
|
|
1114
|
+
width: 18px;
|
|
1115
|
+
height: 18px;
|
|
1033
1116
|
}
|
|
1034
1117
|
|
|
1035
1118
|
.easyx-editor-bubble-btn--color {
|
|
@@ -2952,6 +3035,7 @@ var __webpack_exports__ = {};
|
|
|
2952
3035
|
const current = getCurrent(editor) ?? '';
|
|
2953
3036
|
const currentLabel = getLabel ? getLabel(current) : options.find((o)=>o.value === current)?.label ?? defaultLabel;
|
|
2954
3037
|
valueEl.textContent = currentLabel;
|
|
3038
|
+
trigger.classList.toggle('is-active', Boolean(current));
|
|
2955
3039
|
if (dropdown?.isConnected) {
|
|
2956
3040
|
const items = dropdown.querySelectorAll(`.${selectClassName}-item`);
|
|
2957
3041
|
items.forEach((item)=>{
|
|
@@ -4553,12 +4637,12 @@ var __webpack_exports__ = {};
|
|
|
4553
4637
|
createSelect(toolbarEl, SELECT_CLASS, editor, ICONS.fontSize, '字体大小', FONT_SIZE_OPTIONS, (e)=>{
|
|
4554
4638
|
const attrs = e.getAttributes('textStyle');
|
|
4555
4639
|
return attrs.fontSize || null;
|
|
4556
|
-
}, (e, value)=>e.chain().focus().setFontSize(value).run(), (e)=>e.chain().focus().unsetFontSize().run());
|
|
4640
|
+
}, (e, value)=>e.chain().focus().setFontSize(value).run(), (e)=>e.chain().focus().unsetFontSize().run(), '自动');
|
|
4557
4641
|
div();
|
|
4558
4642
|
createSelect(toolbarEl, SELECT_CLASS, editor, ICONS.lineHeight, '行高', LINE_HEIGHT_OPTIONS, (e)=>{
|
|
4559
4643
|
const attrs = e.getAttributes('textStyle');
|
|
4560
4644
|
return attrs.lineHeight || null;
|
|
4561
|
-
}, (e, value)=>e.chain().focus().setLineHeight(value).run(), (e)=>e.chain().focus().unsetLineHeight().run());
|
|
4645
|
+
}, (e, value)=>e.chain().focus().setLineHeight(value).run(), (e)=>e.chain().focus().unsetLineHeight().run(), '自动');
|
|
4562
4646
|
div();
|
|
4563
4647
|
const alignBtns = [
|
|
4564
4648
|
{
|
|
@@ -4827,10 +4911,89 @@ var __webpack_exports__ = {};
|
|
|
4827
4911
|
return null;
|
|
4828
4912
|
}
|
|
4829
4913
|
}
|
|
4914
|
+
function createResizeHandle(container, options) {
|
|
4915
|
+
const handle = document.createElement('button');
|
|
4916
|
+
handle.type = 'button';
|
|
4917
|
+
handle.className = 'easyx-editor-resize-handle';
|
|
4918
|
+
handle.setAttribute('aria-label', '拖拽调整编辑器高度');
|
|
4919
|
+
handle.innerHTML = '<span class="easyx-editor-resize-handle-grip" aria-hidden="true"></span>';
|
|
4920
|
+
container.appendChild(handle);
|
|
4921
|
+
const getMin = ()=>{
|
|
4922
|
+
if (null == options.minHeight) return 100;
|
|
4923
|
+
const v = parseFloat(getComputedStyle(container).minHeight);
|
|
4924
|
+
return Number.isFinite(v) ? v : 100;
|
|
4925
|
+
};
|
|
4926
|
+
const getMax = ()=>{
|
|
4927
|
+
if (null == options.maxHeight) return 1 / 0;
|
|
4928
|
+
const v = parseFloat(getComputedStyle(container).maxHeight);
|
|
4929
|
+
return Number.isFinite(v) ? v : 1 / 0;
|
|
4930
|
+
};
|
|
4931
|
+
const clamp = (h)=>Math.min(getMax(), Math.max(getMin(), h));
|
|
4932
|
+
const setHeight = (h)=>{
|
|
4933
|
+
container.style.height = `${clamp(h)}px`;
|
|
4934
|
+
};
|
|
4935
|
+
let dragging = false;
|
|
4936
|
+
let startY = 0;
|
|
4937
|
+
let startH = 0;
|
|
4938
|
+
const currentHeight = ()=>container.offsetHeight;
|
|
4939
|
+
const onPointerDown = (e)=>{
|
|
4940
|
+
dragging = true;
|
|
4941
|
+
startY = e.clientY;
|
|
4942
|
+
startH = currentHeight();
|
|
4943
|
+
handle.setPointerCapture(e.pointerId);
|
|
4944
|
+
container.classList.add('easyx-editor-resizing');
|
|
4945
|
+
e.preventDefault();
|
|
4946
|
+
};
|
|
4947
|
+
const onPointerMove = (e)=>{
|
|
4948
|
+
if (!dragging) return;
|
|
4949
|
+
setHeight(startH + (e.clientY - startY));
|
|
4950
|
+
};
|
|
4951
|
+
const onPointerUp = (e)=>{
|
|
4952
|
+
if (!dragging) return;
|
|
4953
|
+
dragging = false;
|
|
4954
|
+
container.classList.remove('easyx-editor-resizing');
|
|
4955
|
+
if (handle.hasPointerCapture(e.pointerId)) handle.releasePointerCapture(e.pointerId);
|
|
4956
|
+
};
|
|
4957
|
+
const onKeyDown = (e)=>{
|
|
4958
|
+
if ('ArrowUp' !== e.key && 'ArrowDown' !== e.key) return;
|
|
4959
|
+
e.preventDefault();
|
|
4960
|
+
const step = 10;
|
|
4961
|
+
const cur = currentHeight();
|
|
4962
|
+
setHeight('ArrowUp' === e.key ? cur + step : cur - step);
|
|
4963
|
+
};
|
|
4964
|
+
handle.addEventListener('pointerdown', onPointerDown);
|
|
4965
|
+
handle.addEventListener('pointermove', onPointerMove);
|
|
4966
|
+
handle.addEventListener('pointerup', onPointerUp);
|
|
4967
|
+
handle.addEventListener('pointercancel', onPointerUp);
|
|
4968
|
+
handle.addEventListener('keydown', onKeyDown);
|
|
4969
|
+
return ()=>{
|
|
4970
|
+
handle.removeEventListener('pointerdown', onPointerDown);
|
|
4971
|
+
handle.removeEventListener('pointermove', onPointerMove);
|
|
4972
|
+
handle.removeEventListener('pointerup', onPointerUp);
|
|
4973
|
+
handle.removeEventListener('pointercancel', onPointerUp);
|
|
4974
|
+
handle.removeEventListener('keydown', onKeyDown);
|
|
4975
|
+
handle.remove();
|
|
4976
|
+
};
|
|
4977
|
+
}
|
|
4830
4978
|
function createEditorInstance(container, options) {
|
|
4831
4979
|
container.classList.add('easyx-editor');
|
|
4832
4980
|
if ('dark' === options.defaultTheme) container.classList.add('easyx-editor-dark');
|
|
4833
4981
|
if (options.readOnly) container.classList.add('easyx-editor-readonly');
|
|
4982
|
+
const toCssLength = (v)=>'number' == typeof v ? `${v}px` : v;
|
|
4983
|
+
const isFixed = null != options.height && 'auto' !== options.height;
|
|
4984
|
+
const isBounded = isFixed || null != options.maxHeight || options.resizable;
|
|
4985
|
+
if (isBounded) container.classList.add('easyx-editor-scroll');
|
|
4986
|
+
if (null != options.minHeight) container.style.minHeight = toCssLength(options.minHeight);
|
|
4987
|
+
if (isFixed) {
|
|
4988
|
+
container.style.height = toCssLength(options.height);
|
|
4989
|
+
if (null == options.minHeight) container.style.minHeight = '0';
|
|
4990
|
+
}
|
|
4991
|
+
if (null != options.maxHeight) container.style.maxHeight = toCssLength(options.maxHeight);
|
|
4992
|
+
if (options.resizable && !isFixed) {
|
|
4993
|
+
const base = options.maxHeight ?? options.minHeight ?? '320px';
|
|
4994
|
+
container.style.height = toCssLength(base);
|
|
4995
|
+
if (null == options.minHeight) container.style.minHeight = '0';
|
|
4996
|
+
}
|
|
4834
4997
|
const toolbarEl = createToolbarElement();
|
|
4835
4998
|
container.appendChild(toolbarEl);
|
|
4836
4999
|
const editorContent = document.createElement('div');
|
|
@@ -4842,6 +5005,8 @@ var __webpack_exports__ = {};
|
|
|
4842
5005
|
const emitter = new EventEmitter();
|
|
4843
5006
|
let refreshAllToolbar = null;
|
|
4844
5007
|
let linkHoverDestroy = null;
|
|
5008
|
+
let resizeCleanup = null;
|
|
5009
|
+
if (options.resizable) resizeCleanup = createResizeHandle(container, options);
|
|
4845
5010
|
let editor;
|
|
4846
5011
|
editor = new core_namespaceObject.Editor({
|
|
4847
5012
|
element: editorContent,
|
|
@@ -5036,6 +5201,7 @@ var __webpack_exports__ = {};
|
|
|
5036
5201
|
onDestroy () {
|
|
5037
5202
|
if (refreshAllToolbar) editor.off('selectionUpdate', refreshAllToolbar);
|
|
5038
5203
|
linkHoverDestroy?.();
|
|
5204
|
+
resizeCleanup?.();
|
|
5039
5205
|
emitter.emit('destroy');
|
|
5040
5206
|
options.onDestroy?.();
|
|
5041
5207
|
}
|
package/dist/index.js
CHANGED
|
@@ -109,11 +109,13 @@ __webpack_require__.add({
|
|
|
109
109
|
--easyx-editor-toolbar-bg: #fff;
|
|
110
110
|
--easyx-editor-toolbar-border: #e5e7eb;
|
|
111
111
|
--easyx-editor-toolbar-padding: 6px;
|
|
112
|
+
--easyx-editor-toolbar-gap: 2px;
|
|
112
113
|
--easyx-editor-toolbar-btn-hover: #f3f4f6;
|
|
113
114
|
--easyx-editor-toolbar-btn-active: #e0e7ff;
|
|
114
115
|
--easyx-editor-toolbar-btn-size: 32px;
|
|
115
116
|
--easyx-editor-toolbar-btn-radius: 6px;
|
|
116
117
|
--easyx-editor-toolbar-btn-color: #4b5563;
|
|
118
|
+
--easyx-editor-toolbar-btn-disabled: #9ca3af;
|
|
117
119
|
--easyx-editor-toolbar-divider: #e5e7eb;
|
|
118
120
|
--easyx-editor-bubble-bg: #fff;
|
|
119
121
|
--easyx-editor-bubble-border: #e5e7eb;
|
|
@@ -167,8 +169,9 @@ __webpack_require__.add({
|
|
|
167
169
|
--easyx-editor-toolbar-bg: #1f2937;
|
|
168
170
|
--easyx-editor-toolbar-border: #374151;
|
|
169
171
|
--easyx-editor-toolbar-btn-hover: #374151;
|
|
170
|
-
--easyx-editor-toolbar-btn-active: #
|
|
172
|
+
--easyx-editor-toolbar-btn-active: #3730a3;
|
|
171
173
|
--easyx-editor-toolbar-btn-color: #d1d5db;
|
|
174
|
+
--easyx-editor-toolbar-btn-disabled: #6b7280;
|
|
172
175
|
--easyx-editor-toolbar-divider: #374151;
|
|
173
176
|
--easyx-editor-bubble-bg: #1f2937;
|
|
174
177
|
--easyx-editor-bubble-border: #374151;
|
|
@@ -191,6 +194,7 @@ __webpack_require__.add({
|
|
|
191
194
|
font-family: var(--easyx-editor-font-family);
|
|
192
195
|
font-size: var(--easyx-editor-font-size);
|
|
193
196
|
line-height: var(--easyx-editor-line-height);
|
|
197
|
+
box-sizing: border-box;
|
|
194
198
|
min-height: var(--easyx-editor-min-height);
|
|
195
199
|
border: 1px solid var(--easyx-editor-border);
|
|
196
200
|
border-radius: var(--easyx-editor-radius);
|
|
@@ -202,6 +206,64 @@ __webpack_require__.add({
|
|
|
202
206
|
border-color: var(--easyx-editor-border-focus);
|
|
203
207
|
}
|
|
204
208
|
|
|
209
|
+
.easyx-editor.easyx-editor-scroll {
|
|
210
|
+
flex-direction: column;
|
|
211
|
+
display: flex;
|
|
212
|
+
overflow: hidden;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.easyx-editor.easyx-editor-scroll .easyx-editor-content {
|
|
216
|
+
flex: auto;
|
|
217
|
+
min-height: 0;
|
|
218
|
+
overflow-y: auto;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.easyx-editor-resize-handle {
|
|
222
|
+
cursor: ns-resize;
|
|
223
|
+
z-index: 5;
|
|
224
|
+
touch-action: none;
|
|
225
|
+
background: none;
|
|
226
|
+
border: none;
|
|
227
|
+
height: 10px;
|
|
228
|
+
padding: 0;
|
|
229
|
+
position: absolute;
|
|
230
|
+
bottom: 0;
|
|
231
|
+
left: 0;
|
|
232
|
+
right: 0;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.easyx-editor-resize-handle:hover, .easyx-editor-resize-handle:focus-visible {
|
|
236
|
+
background: var(--easyx-editor-primary);
|
|
237
|
+
opacity: .12;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.easyx-editor-resize-handle:focus-visible {
|
|
241
|
+
outline: 2px solid var(--easyx-editor-primary);
|
|
242
|
+
outline-offset: -2px;
|
|
243
|
+
opacity: .25;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.easyx-editor-resize-handle-grip {
|
|
247
|
+
background: var(--easyx-editor-toolbar-divider);
|
|
248
|
+
pointer-events: none;
|
|
249
|
+
border-radius: 2px;
|
|
250
|
+
width: 40px;
|
|
251
|
+
height: 4px;
|
|
252
|
+
transition: background .15s;
|
|
253
|
+
position: absolute;
|
|
254
|
+
bottom: 2px;
|
|
255
|
+
left: 50%;
|
|
256
|
+
transform: translateX(-50%);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.easyx-editor-resize-handle:hover .easyx-editor-resize-handle-grip, .easyx-editor-resize-handle:focus-visible .easyx-editor-resize-handle-grip {
|
|
260
|
+
background: var(--easyx-editor-primary);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.easyx-editor.easyx-editor-resizing {
|
|
264
|
+
user-select: none;
|
|
265
|
+
}
|
|
266
|
+
|
|
205
267
|
.easyx-editor-disabled {
|
|
206
268
|
opacity: .6;
|
|
207
269
|
pointer-events: none;
|
|
@@ -766,14 +828,14 @@ __webpack_require__.add({
|
|
|
766
828
|
}
|
|
767
829
|
|
|
768
830
|
.easyx-editor-toolbar {
|
|
831
|
+
align-items: center;
|
|
832
|
+
gap: var(--easyx-editor-toolbar-gap);
|
|
769
833
|
padding: var(--easyx-editor-toolbar-padding);
|
|
770
834
|
background: var(--easyx-editor-toolbar-bg);
|
|
771
835
|
border-bottom: 1px solid var(--easyx-editor-toolbar-border);
|
|
772
836
|
border-radius: var(--easyx-editor-radius) var(--easyx-editor-radius) 0 0;
|
|
773
837
|
z-index: 99;
|
|
774
838
|
flex-wrap: wrap;
|
|
775
|
-
align-items: center;
|
|
776
|
-
gap: 2px;
|
|
777
839
|
display: flex;
|
|
778
840
|
position: sticky;
|
|
779
841
|
top: 0;
|
|
@@ -792,7 +854,7 @@ __webpack_require__.add({
|
|
|
792
854
|
padding: 0;
|
|
793
855
|
font-size: 14px;
|
|
794
856
|
line-height: 1;
|
|
795
|
-
transition: background .15s;
|
|
857
|
+
transition: background .15s, color .15s, opacity .15s;
|
|
796
858
|
display: inline-flex;
|
|
797
859
|
}
|
|
798
860
|
|
|
@@ -800,6 +862,11 @@ __webpack_require__.add({
|
|
|
800
862
|
background: var(--easyx-editor-toolbar-btn-hover);
|
|
801
863
|
}
|
|
802
864
|
|
|
865
|
+
.easyx-editor-toolbar-btn:focus-visible {
|
|
866
|
+
outline: 2px solid var(--easyx-editor-primary);
|
|
867
|
+
outline-offset: -2px;
|
|
868
|
+
}
|
|
869
|
+
|
|
803
870
|
.easyx-editor-toolbar-btn.is-active {
|
|
804
871
|
background: var(--easyx-editor-toolbar-btn-active);
|
|
805
872
|
color: var(--easyx-editor-primary);
|
|
@@ -807,8 +874,8 @@ __webpack_require__.add({
|
|
|
807
874
|
|
|
808
875
|
.easyx-editor-toolbar-btn svg {
|
|
809
876
|
fill: currentColor;
|
|
810
|
-
width:
|
|
811
|
-
height:
|
|
877
|
+
width: 18px;
|
|
878
|
+
height: 18px;
|
|
812
879
|
}
|
|
813
880
|
|
|
814
881
|
.easyx-editor-toolbar-btn--history.is-active {
|
|
@@ -817,7 +884,7 @@ __webpack_require__.add({
|
|
|
817
884
|
}
|
|
818
885
|
|
|
819
886
|
.easyx-editor-toolbar-btn--history:not(.is-active) {
|
|
820
|
-
|
|
887
|
+
color: var(--easyx-editor-toolbar-btn-disabled);
|
|
821
888
|
}
|
|
822
889
|
|
|
823
890
|
.easyx-editor-toolbar-btn--history:not(.is-active):hover {
|
|
@@ -846,27 +913,38 @@ __webpack_require__.add({
|
|
|
846
913
|
}
|
|
847
914
|
|
|
848
915
|
.easyx-editor-toolbar-select {
|
|
849
|
-
border: 1px solid var(--easyx-editor-toolbar-border);
|
|
850
916
|
border-radius: var(--easyx-editor-toolbar-btn-radius);
|
|
851
917
|
height: var(--easyx-editor-toolbar-btn-size);
|
|
852
918
|
cursor: pointer;
|
|
919
|
+
color: var(--easyx-editor-toolbar-btn-color);
|
|
853
920
|
background: none;
|
|
921
|
+
border: none;
|
|
854
922
|
outline: none;
|
|
855
923
|
align-items: center;
|
|
856
924
|
gap: 2px;
|
|
857
925
|
padding: 0 4px;
|
|
858
|
-
transition:
|
|
926
|
+
transition: background .15s, color .15s;
|
|
859
927
|
display: inline-flex;
|
|
860
928
|
}
|
|
861
929
|
|
|
862
930
|
.easyx-editor-toolbar-select:hover {
|
|
863
|
-
|
|
931
|
+
background: var(--easyx-editor-toolbar-btn-hover);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
.easyx-editor-toolbar-select:focus-visible {
|
|
935
|
+
outline: 2px solid var(--easyx-editor-primary);
|
|
936
|
+
outline-offset: -2px;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
.easyx-editor-toolbar-select.is-active {
|
|
940
|
+
background: var(--easyx-editor-toolbar-btn-active);
|
|
941
|
+
color: var(--easyx-editor-primary);
|
|
864
942
|
}
|
|
865
943
|
|
|
866
944
|
.easyx-editor-toolbar-select-icon {
|
|
867
945
|
width: var(--easyx-editor-toolbar-btn-size);
|
|
868
946
|
height: var(--easyx-editor-toolbar-btn-size);
|
|
869
|
-
color:
|
|
947
|
+
color: inherit;
|
|
870
948
|
pointer-events: none;
|
|
871
949
|
justify-content: center;
|
|
872
950
|
align-items: center;
|
|
@@ -875,14 +953,14 @@ __webpack_require__.add({
|
|
|
875
953
|
|
|
876
954
|
.easyx-editor-toolbar-select-icon svg {
|
|
877
955
|
fill: currentColor;
|
|
878
|
-
width:
|
|
879
|
-
height:
|
|
956
|
+
width: 16px;
|
|
957
|
+
height: 16px;
|
|
880
958
|
}
|
|
881
959
|
|
|
882
960
|
.easyx-editor-toolbar-select-value {
|
|
883
961
|
text-align: center;
|
|
884
|
-
width:
|
|
885
|
-
color:
|
|
962
|
+
min-width: 28px;
|
|
963
|
+
color: inherit;
|
|
886
964
|
white-space: nowrap;
|
|
887
965
|
font-size: 12px;
|
|
888
966
|
}
|
|
@@ -890,7 +968,7 @@ __webpack_require__.add({
|
|
|
890
968
|
.easyx-editor-toolbar-select-arrow {
|
|
891
969
|
width: 14px;
|
|
892
970
|
height: 14px;
|
|
893
|
-
color:
|
|
971
|
+
color: inherit;
|
|
894
972
|
flex-shrink: 0;
|
|
895
973
|
justify-content: center;
|
|
896
974
|
align-items: center;
|
|
@@ -1080,6 +1158,11 @@ __webpack_require__.add({
|
|
|
1080
1158
|
background: var(--easyx-editor-bubble-btn-hover);
|
|
1081
1159
|
}
|
|
1082
1160
|
|
|
1161
|
+
.easyx-editor-bubble-btn:focus-visible {
|
|
1162
|
+
outline: 2px solid var(--easyx-editor-primary);
|
|
1163
|
+
outline-offset: -2px;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1083
1166
|
.easyx-editor-bubble-btn.is-active {
|
|
1084
1167
|
background: var(--easyx-editor-bubble-btn-active);
|
|
1085
1168
|
color: var(--easyx-editor-primary);
|
|
@@ -1087,8 +1170,8 @@ __webpack_require__.add({
|
|
|
1087
1170
|
|
|
1088
1171
|
.easyx-editor-bubble-btn svg {
|
|
1089
1172
|
fill: currentColor;
|
|
1090
|
-
width:
|
|
1091
|
-
height:
|
|
1173
|
+
width: 18px;
|
|
1174
|
+
height: 18px;
|
|
1092
1175
|
}
|
|
1093
1176
|
|
|
1094
1177
|
.easyx-editor-bubble-btn--color {
|
|
@@ -2935,6 +3018,7 @@ function createSelect(container, selectClassName, editor, icon, title, options,
|
|
|
2935
3018
|
const current = getCurrent(editor) ?? '';
|
|
2936
3019
|
const currentLabel = getLabel ? getLabel(current) : options.find((o)=>o.value === current)?.label ?? defaultLabel;
|
|
2937
3020
|
valueEl.textContent = currentLabel;
|
|
3021
|
+
trigger.classList.toggle('is-active', Boolean(current));
|
|
2938
3022
|
if (dropdown?.isConnected) {
|
|
2939
3023
|
const items = dropdown.querySelectorAll(`.${selectClassName}-item`);
|
|
2940
3024
|
items.forEach((item)=>{
|
|
@@ -4536,12 +4620,12 @@ function populateToolbar(toolbarEl, editor, mediaConfig) {
|
|
|
4536
4620
|
createSelect(toolbarEl, SELECT_CLASS, editor, ICONS.fontSize, '字体大小', FONT_SIZE_OPTIONS, (e)=>{
|
|
4537
4621
|
const attrs = e.getAttributes('textStyle');
|
|
4538
4622
|
return attrs.fontSize || null;
|
|
4539
|
-
}, (e, value)=>e.chain().focus().setFontSize(value).run(), (e)=>e.chain().focus().unsetFontSize().run());
|
|
4623
|
+
}, (e, value)=>e.chain().focus().setFontSize(value).run(), (e)=>e.chain().focus().unsetFontSize().run(), '自动');
|
|
4540
4624
|
div();
|
|
4541
4625
|
createSelect(toolbarEl, SELECT_CLASS, editor, ICONS.lineHeight, '行高', LINE_HEIGHT_OPTIONS, (e)=>{
|
|
4542
4626
|
const attrs = e.getAttributes('textStyle');
|
|
4543
4627
|
return attrs.lineHeight || null;
|
|
4544
|
-
}, (e, value)=>e.chain().focus().setLineHeight(value).run(), (e)=>e.chain().focus().unsetLineHeight().run());
|
|
4628
|
+
}, (e, value)=>e.chain().focus().setLineHeight(value).run(), (e)=>e.chain().focus().unsetLineHeight().run(), '自动');
|
|
4545
4629
|
div();
|
|
4546
4630
|
const alignBtns = [
|
|
4547
4631
|
{
|
|
@@ -4810,10 +4894,89 @@ function getMediaNodeAnchor(nodeType, tag) {
|
|
|
4810
4894
|
return null;
|
|
4811
4895
|
}
|
|
4812
4896
|
}
|
|
4897
|
+
function createResizeHandle(container, options) {
|
|
4898
|
+
const handle = document.createElement('button');
|
|
4899
|
+
handle.type = 'button';
|
|
4900
|
+
handle.className = 'easyx-editor-resize-handle';
|
|
4901
|
+
handle.setAttribute('aria-label', '拖拽调整编辑器高度');
|
|
4902
|
+
handle.innerHTML = '<span class="easyx-editor-resize-handle-grip" aria-hidden="true"></span>';
|
|
4903
|
+
container.appendChild(handle);
|
|
4904
|
+
const getMin = ()=>{
|
|
4905
|
+
if (null == options.minHeight) return 100;
|
|
4906
|
+
const v = parseFloat(getComputedStyle(container).minHeight);
|
|
4907
|
+
return Number.isFinite(v) ? v : 100;
|
|
4908
|
+
};
|
|
4909
|
+
const getMax = ()=>{
|
|
4910
|
+
if (null == options.maxHeight) return 1 / 0;
|
|
4911
|
+
const v = parseFloat(getComputedStyle(container).maxHeight);
|
|
4912
|
+
return Number.isFinite(v) ? v : 1 / 0;
|
|
4913
|
+
};
|
|
4914
|
+
const clamp = (h)=>Math.min(getMax(), Math.max(getMin(), h));
|
|
4915
|
+
const setHeight = (h)=>{
|
|
4916
|
+
container.style.height = `${clamp(h)}px`;
|
|
4917
|
+
};
|
|
4918
|
+
let dragging = false;
|
|
4919
|
+
let startY = 0;
|
|
4920
|
+
let startH = 0;
|
|
4921
|
+
const currentHeight = ()=>container.offsetHeight;
|
|
4922
|
+
const onPointerDown = (e)=>{
|
|
4923
|
+
dragging = true;
|
|
4924
|
+
startY = e.clientY;
|
|
4925
|
+
startH = currentHeight();
|
|
4926
|
+
handle.setPointerCapture(e.pointerId);
|
|
4927
|
+
container.classList.add('easyx-editor-resizing');
|
|
4928
|
+
e.preventDefault();
|
|
4929
|
+
};
|
|
4930
|
+
const onPointerMove = (e)=>{
|
|
4931
|
+
if (!dragging) return;
|
|
4932
|
+
setHeight(startH + (e.clientY - startY));
|
|
4933
|
+
};
|
|
4934
|
+
const onPointerUp = (e)=>{
|
|
4935
|
+
if (!dragging) return;
|
|
4936
|
+
dragging = false;
|
|
4937
|
+
container.classList.remove('easyx-editor-resizing');
|
|
4938
|
+
if (handle.hasPointerCapture(e.pointerId)) handle.releasePointerCapture(e.pointerId);
|
|
4939
|
+
};
|
|
4940
|
+
const onKeyDown = (e)=>{
|
|
4941
|
+
if ('ArrowUp' !== e.key && 'ArrowDown' !== e.key) return;
|
|
4942
|
+
e.preventDefault();
|
|
4943
|
+
const step = 10;
|
|
4944
|
+
const cur = currentHeight();
|
|
4945
|
+
setHeight('ArrowUp' === e.key ? cur + step : cur - step);
|
|
4946
|
+
};
|
|
4947
|
+
handle.addEventListener('pointerdown', onPointerDown);
|
|
4948
|
+
handle.addEventListener('pointermove', onPointerMove);
|
|
4949
|
+
handle.addEventListener('pointerup', onPointerUp);
|
|
4950
|
+
handle.addEventListener('pointercancel', onPointerUp);
|
|
4951
|
+
handle.addEventListener('keydown', onKeyDown);
|
|
4952
|
+
return ()=>{
|
|
4953
|
+
handle.removeEventListener('pointerdown', onPointerDown);
|
|
4954
|
+
handle.removeEventListener('pointermove', onPointerMove);
|
|
4955
|
+
handle.removeEventListener('pointerup', onPointerUp);
|
|
4956
|
+
handle.removeEventListener('pointercancel', onPointerUp);
|
|
4957
|
+
handle.removeEventListener('keydown', onKeyDown);
|
|
4958
|
+
handle.remove();
|
|
4959
|
+
};
|
|
4960
|
+
}
|
|
4813
4961
|
function createEditorInstance(container, options) {
|
|
4814
4962
|
container.classList.add('easyx-editor');
|
|
4815
4963
|
if ('dark' === options.defaultTheme) container.classList.add('easyx-editor-dark');
|
|
4816
4964
|
if (options.readOnly) container.classList.add('easyx-editor-readonly');
|
|
4965
|
+
const toCssLength = (v)=>'number' == typeof v ? `${v}px` : v;
|
|
4966
|
+
const isFixed = null != options.height && 'auto' !== options.height;
|
|
4967
|
+
const isBounded = isFixed || null != options.maxHeight || options.resizable;
|
|
4968
|
+
if (isBounded) container.classList.add('easyx-editor-scroll');
|
|
4969
|
+
if (null != options.minHeight) container.style.minHeight = toCssLength(options.minHeight);
|
|
4970
|
+
if (isFixed) {
|
|
4971
|
+
container.style.height = toCssLength(options.height);
|
|
4972
|
+
if (null == options.minHeight) container.style.minHeight = '0';
|
|
4973
|
+
}
|
|
4974
|
+
if (null != options.maxHeight) container.style.maxHeight = toCssLength(options.maxHeight);
|
|
4975
|
+
if (options.resizable && !isFixed) {
|
|
4976
|
+
const base = options.maxHeight ?? options.minHeight ?? '320px';
|
|
4977
|
+
container.style.height = toCssLength(base);
|
|
4978
|
+
if (null == options.minHeight) container.style.minHeight = '0';
|
|
4979
|
+
}
|
|
4817
4980
|
const toolbarEl = createToolbarElement();
|
|
4818
4981
|
container.appendChild(toolbarEl);
|
|
4819
4982
|
const editorContent = document.createElement('div');
|
|
@@ -4825,6 +4988,8 @@ function createEditorInstance(container, options) {
|
|
|
4825
4988
|
const emitter = new EventEmitter();
|
|
4826
4989
|
let refreshAllToolbar = null;
|
|
4827
4990
|
let linkHoverDestroy = null;
|
|
4991
|
+
let resizeCleanup = null;
|
|
4992
|
+
if (options.resizable) resizeCleanup = createResizeHandle(container, options);
|
|
4828
4993
|
let editor;
|
|
4829
4994
|
editor = new Editor({
|
|
4830
4995
|
element: editorContent,
|
|
@@ -5019,6 +5184,7 @@ function createEditorInstance(container, options) {
|
|
|
5019
5184
|
onDestroy () {
|
|
5020
5185
|
if (refreshAllToolbar) editor.off('selectionUpdate', refreshAllToolbar);
|
|
5021
5186
|
linkHoverDestroy?.();
|
|
5187
|
+
resizeCleanup?.();
|
|
5022
5188
|
emitter.emit('destroy');
|
|
5023
5189
|
options.onDestroy?.();
|
|
5024
5190
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -16,6 +16,14 @@ export interface EasyxEditorOptions {
|
|
|
16
16
|
video?: MediaUploadConfig;
|
|
17
17
|
audio?: MediaUploadConfig;
|
|
18
18
|
attachment?: MediaUploadConfig;
|
|
19
|
+
/** 编辑器最小高度,number 视为 px,或任意 CSS 长度 */
|
|
20
|
+
minHeight?: number | string;
|
|
21
|
+
/** 编辑器高度:'auto'/缺省表示随内容伸缩;给定值时固定高度并内部滚动 */
|
|
22
|
+
height?: number | 'auto' | string;
|
|
23
|
+
/** 编辑器最大高度,内容撑到上限后内部滚动 */
|
|
24
|
+
maxHeight?: number | string;
|
|
25
|
+
/** 是否启用右下角拖拽手柄调节高度,受 minHeight / maxHeight 约束 */
|
|
26
|
+
resizable?: boolean;
|
|
19
27
|
onChange?: (content: ContentType) => void;
|
|
20
28
|
onReady?: () => void;
|
|
21
29
|
onFocus?: () => void;
|