@douyinfe/semi-foundation 2.77.1 → 2.78.0-beta.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/cropper/foundation.ts +83 -0
- package/jsonViewer/foundation.ts +29 -9
- package/lib/cjs/cropper/foundation.d.ts +15 -0
- package/lib/cjs/cropper/foundation.js +84 -0
- package/lib/cjs/jsonViewer/foundation.d.ts +4 -3
- package/lib/cjs/jsonViewer/foundation.js +34 -13
- package/lib/es/cropper/foundation.d.ts +15 -0
- package/lib/es/cropper/foundation.js +84 -0
- package/lib/es/jsonViewer/foundation.d.ts +4 -3
- package/lib/es/jsonViewer/foundation.js +34 -13
- package/package.json +4 -4
package/cropper/foundation.ts
CHANGED
|
@@ -60,6 +60,12 @@ export default class CropperFoundation <P = Record<string, any>, S = Record<stri
|
|
|
60
60
|
rangeX: [number, number];
|
|
61
61
|
rangeY: [number, number];
|
|
62
62
|
initial: boolean;
|
|
63
|
+
previewImg: HTMLImageElement;
|
|
64
|
+
previewContainer: HTMLElement;
|
|
65
|
+
previewContainerInitSize: {
|
|
66
|
+
width: number;
|
|
67
|
+
height: number
|
|
68
|
+
};
|
|
63
69
|
|
|
64
70
|
constructor(adapter: CropperAdapter<P, S>) {
|
|
65
71
|
super({ ...adapter });
|
|
@@ -74,6 +80,8 @@ export default class CropperFoundation <P = Record<string, any>, S = Record<stri
|
|
|
74
80
|
this.rangeX = null;
|
|
75
81
|
this.rangeY = null;
|
|
76
82
|
this.initial = false;
|
|
83
|
+
this.previewImg = null;
|
|
84
|
+
this.previewContainer = null;
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
init() {
|
|
@@ -88,6 +96,7 @@ export default class CropperFoundation <P = Record<string, any>, S = Record<stri
|
|
|
88
96
|
destroy() {
|
|
89
97
|
this.unBindMoveEvent();
|
|
90
98
|
this.unBindResizeEvent();
|
|
99
|
+
this.removePreview();
|
|
91
100
|
}
|
|
92
101
|
|
|
93
102
|
getImgDataWhenResize = (ratio: number) => {
|
|
@@ -228,6 +237,80 @@ export default class CropperFoundation <P = Record<string, any>, S = Record<stri
|
|
|
228
237
|
cropperBox: newCropperBoxState,
|
|
229
238
|
loaded: true,
|
|
230
239
|
} as any);
|
|
240
|
+
|
|
241
|
+
this.renderPreview();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
renderPreview = () => {
|
|
245
|
+
const { preview, src } = this.getProps();
|
|
246
|
+
const previewNode = preview?.();
|
|
247
|
+
if (!previewNode) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const img = document.createElement('img');
|
|
251
|
+
this.previewImg = img;
|
|
252
|
+
this.previewContainer = previewNode;
|
|
253
|
+
img.src = src;
|
|
254
|
+
previewNode.appendChild(img);
|
|
255
|
+
this.previewContainer.style.overflow = 'hidden';
|
|
256
|
+
// 记录预览容器初始宽高
|
|
257
|
+
const { width: previewWidth, height: previewHeight } = previewNode.getBoundingClientRect();
|
|
258
|
+
this.previewContainerInitSize = {
|
|
259
|
+
width: previewWidth,
|
|
260
|
+
height: previewHeight,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
updatePreview = (props: {
|
|
265
|
+
width: number;
|
|
266
|
+
height: number;
|
|
267
|
+
translateX: number;
|
|
268
|
+
translateY: number;
|
|
269
|
+
rotate: number
|
|
270
|
+
}) => {
|
|
271
|
+
if (!this.previewImg) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const { cropperBox } = this.getStates();
|
|
275
|
+
let zoom = 1;
|
|
276
|
+
const { width: containerWidth, height: containerHeight } = this.previewContainerInitSize;
|
|
277
|
+
let previewWidth = containerWidth;
|
|
278
|
+
let previewHeight = containerHeight;
|
|
279
|
+
if (previewWidth < previewHeight) {
|
|
280
|
+
zoom = containerWidth / cropperBox.width;
|
|
281
|
+
let tempHeight = zoom * cropperBox.height;
|
|
282
|
+
if (tempHeight > containerHeight) {
|
|
283
|
+
zoom = containerHeight / cropperBox.height;
|
|
284
|
+
previewWidth = zoom * cropperBox.width;
|
|
285
|
+
} else {
|
|
286
|
+
previewHeight = tempHeight;
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
zoom = containerHeight / cropperBox.height;
|
|
290
|
+
let tempWidth = zoom * cropperBox.width;
|
|
291
|
+
if (tempWidth > containerWidth) {
|
|
292
|
+
zoom = containerWidth / cropperBox.width;
|
|
293
|
+
previewHeight = zoom * cropperBox.height;
|
|
294
|
+
} else {
|
|
295
|
+
previewWidth = tempWidth;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const { width, height, translateX, translateY, rotate } = props;
|
|
299
|
+
// Set the image style
|
|
300
|
+
this.previewImg.style.width = `${width * zoom}px`;
|
|
301
|
+
this.previewImg.style.height = `${height * zoom}px`;
|
|
302
|
+
this.previewImg.style.transform = `translate(${translateX * zoom}px, ${translateY * zoom}px) rotate(${rotate}deg)`;
|
|
303
|
+
this.previewImg.style.transformOrigin = 'center';
|
|
304
|
+
// set preview container size
|
|
305
|
+
this.previewContainer.style.width = `${previewWidth}px`;
|
|
306
|
+
this.previewContainer.style.height = `${previewHeight}px`;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
removePreview = () => {
|
|
310
|
+
if (this.previewImg && this.previewContainer) {
|
|
311
|
+
this.previewContainer.removeChild(this.previewImg);
|
|
312
|
+
this.previewImg = null;
|
|
313
|
+
}
|
|
231
314
|
}
|
|
232
315
|
|
|
233
316
|
handleWheel = (e: any) => {
|
package/jsonViewer/foundation.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import { JsonViewer, JsonViewerOptions, CustomRenderRule } from '@douyinfe/semi-json-viewer-core';
|
|
3
2
|
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
4
3
|
|
|
@@ -37,18 +36,35 @@ class JsonViewerFoundation extends BaseFoundation<JsonViewerAdapter> {
|
|
|
37
36
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
search(searchText: string) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
search(searchText: string, caseSensitive?: boolean, wholeWord?: boolean, regex?: boolean) {
|
|
40
|
+
let options;
|
|
41
|
+
if (caseSensitive !== undefined || wholeWord !== undefined || regex !== undefined) {
|
|
42
|
+
options = {
|
|
43
|
+
caseSensitive: caseSensitive ?? false,
|
|
44
|
+
wholeWord: wholeWord ?? false,
|
|
45
|
+
regex: regex ?? false
|
|
46
|
+
};
|
|
47
|
+
} else {
|
|
48
|
+
options = this.getState('searchOptions');
|
|
49
|
+
}
|
|
50
|
+
const { caseSensitive: cs, wholeWord: ww, regex: rx } = options;
|
|
51
|
+
this.jsonViewer?.getSearchWidget().search(searchText, cs, ww, rx);
|
|
44
52
|
}
|
|
45
53
|
|
|
46
|
-
prevSearch() {
|
|
47
|
-
|
|
54
|
+
prevSearch(step?: number) {
|
|
55
|
+
if (step === undefined) {
|
|
56
|
+
this.jsonViewer?.getSearchWidget().navigateResults(-1);
|
|
57
|
+
} else {
|
|
58
|
+
this.jsonViewer?.getSearchWidget().navigateResults(-step);
|
|
59
|
+
}
|
|
48
60
|
}
|
|
49
61
|
|
|
50
|
-
nextSearch() {
|
|
51
|
-
|
|
62
|
+
nextSearch(step?: number) {
|
|
63
|
+
if (step === undefined) {
|
|
64
|
+
this.jsonViewer?.getSearchWidget().navigateResults(1);
|
|
65
|
+
} else {
|
|
66
|
+
this.jsonViewer?.getSearchWidget().navigateResults(step);
|
|
67
|
+
}
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
replace(replaceText: string) {
|
|
@@ -72,6 +88,10 @@ class JsonViewerFoundation extends BaseFoundation<JsonViewerAdapter> {
|
|
|
72
88
|
showSearchBar() {
|
|
73
89
|
this._adapter.showSearchBar();
|
|
74
90
|
}
|
|
91
|
+
|
|
92
|
+
getSearchResults() {
|
|
93
|
+
return this.jsonViewer?.getSearchWidget().searchResults;
|
|
94
|
+
}
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
export default JsonViewerFoundation;
|
|
@@ -51,6 +51,12 @@ export default class CropperFoundation<P = Record<string, any>, S = Record<strin
|
|
|
51
51
|
rangeX: [number, number];
|
|
52
52
|
rangeY: [number, number];
|
|
53
53
|
initial: boolean;
|
|
54
|
+
previewImg: HTMLImageElement;
|
|
55
|
+
previewContainer: HTMLElement;
|
|
56
|
+
previewContainerInitSize: {
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
};
|
|
54
60
|
constructor(adapter: CropperAdapter<P, S>);
|
|
55
61
|
init(): void;
|
|
56
62
|
destroy(): void;
|
|
@@ -72,6 +78,15 @@ export default class CropperFoundation<P = Record<string, any>, S = Record<strin
|
|
|
72
78
|
};
|
|
73
79
|
handleResize: () => void;
|
|
74
80
|
handleImageLoad: (e: any) => void;
|
|
81
|
+
renderPreview: () => void;
|
|
82
|
+
updatePreview: (props: {
|
|
83
|
+
width: number;
|
|
84
|
+
height: number;
|
|
85
|
+
translateX: number;
|
|
86
|
+
translateY: number;
|
|
87
|
+
rotate: number;
|
|
88
|
+
}) => void;
|
|
89
|
+
removePreview: () => void;
|
|
75
90
|
handleWheel: (e: any) => void;
|
|
76
91
|
getMoveParamByDir(dir: string): {
|
|
77
92
|
paramX: number;
|
|
@@ -156,6 +156,87 @@ class CropperFoundation extends _foundation.default {
|
|
|
156
156
|
cropperBox: newCropperBoxState,
|
|
157
157
|
loaded: true
|
|
158
158
|
});
|
|
159
|
+
this.renderPreview();
|
|
160
|
+
};
|
|
161
|
+
this.renderPreview = () => {
|
|
162
|
+
const {
|
|
163
|
+
preview,
|
|
164
|
+
src
|
|
165
|
+
} = this.getProps();
|
|
166
|
+
const previewNode = preview === null || preview === void 0 ? void 0 : preview();
|
|
167
|
+
if (!previewNode) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const img = document.createElement('img');
|
|
171
|
+
this.previewImg = img;
|
|
172
|
+
this.previewContainer = previewNode;
|
|
173
|
+
img.src = src;
|
|
174
|
+
previewNode.appendChild(img);
|
|
175
|
+
this.previewContainer.style.overflow = 'hidden';
|
|
176
|
+
// 记录预览容器初始宽高
|
|
177
|
+
const {
|
|
178
|
+
width: previewWidth,
|
|
179
|
+
height: previewHeight
|
|
180
|
+
} = previewNode.getBoundingClientRect();
|
|
181
|
+
this.previewContainerInitSize = {
|
|
182
|
+
width: previewWidth,
|
|
183
|
+
height: previewHeight
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
this.updatePreview = props => {
|
|
187
|
+
if (!this.previewImg) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const {
|
|
191
|
+
cropperBox
|
|
192
|
+
} = this.getStates();
|
|
193
|
+
let zoom = 1;
|
|
194
|
+
const {
|
|
195
|
+
width: containerWidth,
|
|
196
|
+
height: containerHeight
|
|
197
|
+
} = this.previewContainerInitSize;
|
|
198
|
+
let previewWidth = containerWidth;
|
|
199
|
+
let previewHeight = containerHeight;
|
|
200
|
+
if (previewWidth < previewHeight) {
|
|
201
|
+
zoom = containerWidth / cropperBox.width;
|
|
202
|
+
let tempHeight = zoom * cropperBox.height;
|
|
203
|
+
if (tempHeight > containerHeight) {
|
|
204
|
+
zoom = containerHeight / cropperBox.height;
|
|
205
|
+
previewWidth = zoom * cropperBox.width;
|
|
206
|
+
} else {
|
|
207
|
+
previewHeight = tempHeight;
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
zoom = containerHeight / cropperBox.height;
|
|
211
|
+
let tempWidth = zoom * cropperBox.width;
|
|
212
|
+
if (tempWidth > containerWidth) {
|
|
213
|
+
zoom = containerWidth / cropperBox.width;
|
|
214
|
+
previewHeight = zoom * cropperBox.height;
|
|
215
|
+
} else {
|
|
216
|
+
previewWidth = tempWidth;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const {
|
|
220
|
+
width,
|
|
221
|
+
height,
|
|
222
|
+
translateX,
|
|
223
|
+
translateY,
|
|
224
|
+
rotate
|
|
225
|
+
} = props;
|
|
226
|
+
// Set the image style
|
|
227
|
+
this.previewImg.style.width = `${width * zoom}px`;
|
|
228
|
+
this.previewImg.style.height = `${height * zoom}px`;
|
|
229
|
+
this.previewImg.style.transform = `translate(${translateX * zoom}px, ${translateY * zoom}px) rotate(${rotate}deg)`;
|
|
230
|
+
this.previewImg.style.transformOrigin = 'center';
|
|
231
|
+
// set preview container size
|
|
232
|
+
this.previewContainer.style.width = `${previewWidth}px`;
|
|
233
|
+
this.previewContainer.style.height = `${previewHeight}px`;
|
|
234
|
+
};
|
|
235
|
+
this.removePreview = () => {
|
|
236
|
+
if (this.previewImg && this.previewContainer) {
|
|
237
|
+
this.previewContainer.removeChild(this.previewImg);
|
|
238
|
+
this.previewImg = null;
|
|
239
|
+
}
|
|
159
240
|
};
|
|
160
241
|
this.handleWheel = e => {
|
|
161
242
|
// 防止双手缩放导致页面被放大
|
|
@@ -729,6 +810,8 @@ class CropperFoundation extends _foundation.default {
|
|
|
729
810
|
this.rangeX = null;
|
|
730
811
|
this.rangeY = null;
|
|
731
812
|
this.initial = false;
|
|
813
|
+
this.previewImg = null;
|
|
814
|
+
this.previewContainer = null;
|
|
732
815
|
}
|
|
733
816
|
init() {
|
|
734
817
|
// 获取容器的宽高
|
|
@@ -741,6 +824,7 @@ class CropperFoundation extends _foundation.default {
|
|
|
741
824
|
destroy() {
|
|
742
825
|
this.unBindMoveEvent();
|
|
743
826
|
this.unBindResizeEvent();
|
|
827
|
+
this.removePreview();
|
|
744
828
|
}
|
|
745
829
|
getMoveParamByDir(dir) {
|
|
746
830
|
let paramX = 0,
|
|
@@ -14,12 +14,13 @@ declare class JsonViewerFoundation extends BaseFoundation<JsonViewerAdapter> {
|
|
|
14
14
|
constructor(adapter: JsonViewerAdapter);
|
|
15
15
|
jsonViewer: JsonViewer | null;
|
|
16
16
|
init(): void;
|
|
17
|
-
search(searchText: string): void;
|
|
18
|
-
prevSearch(): void;
|
|
19
|
-
nextSearch(): void;
|
|
17
|
+
search(searchText: string, caseSensitive?: boolean, wholeWord?: boolean, regex?: boolean): void;
|
|
18
|
+
prevSearch(step?: number): void;
|
|
19
|
+
nextSearch(step?: number): void;
|
|
20
20
|
replace(replaceText: string): void;
|
|
21
21
|
replaceAll(replaceText: string): void;
|
|
22
22
|
setSearchOptions(key: string): void;
|
|
23
23
|
showSearchBar(): void;
|
|
24
|
+
getSearchResults(): import("@douyinfe/semi-json-viewer-core/src/common/model").FindMatch[];
|
|
24
25
|
}
|
|
25
26
|
export default JsonViewerFoundation;
|
|
@@ -28,23 +28,40 @@ class JsonViewerFoundation extends _foundation.default {
|
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
search(searchText) {
|
|
31
|
+
search(searchText, caseSensitive, wholeWord, regex) {
|
|
32
32
|
var _a;
|
|
33
|
-
|
|
33
|
+
let options;
|
|
34
|
+
if (caseSensitive !== undefined || wholeWord !== undefined || regex !== undefined) {
|
|
35
|
+
options = {
|
|
36
|
+
caseSensitive: caseSensitive !== null && caseSensitive !== void 0 ? caseSensitive : false,
|
|
37
|
+
wholeWord: wholeWord !== null && wholeWord !== void 0 ? wholeWord : false,
|
|
38
|
+
regex: regex !== null && regex !== void 0 ? regex : false
|
|
39
|
+
};
|
|
40
|
+
} else {
|
|
41
|
+
options = this.getState('searchOptions');
|
|
42
|
+
}
|
|
34
43
|
const {
|
|
35
|
-
caseSensitive,
|
|
36
|
-
wholeWord,
|
|
37
|
-
regex
|
|
38
|
-
} =
|
|
39
|
-
(_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().search(searchText,
|
|
44
|
+
caseSensitive: cs,
|
|
45
|
+
wholeWord: ww,
|
|
46
|
+
regex: rx
|
|
47
|
+
} = options;
|
|
48
|
+
(_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().search(searchText, cs, ww, rx);
|
|
40
49
|
}
|
|
41
|
-
prevSearch() {
|
|
42
|
-
var _a;
|
|
43
|
-
(
|
|
50
|
+
prevSearch(step) {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
if (step === undefined) {
|
|
53
|
+
(_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().navigateResults(-1);
|
|
54
|
+
} else {
|
|
55
|
+
(_b = this.jsonViewer) === null || _b === void 0 ? void 0 : _b.getSearchWidget().navigateResults(-step);
|
|
56
|
+
}
|
|
44
57
|
}
|
|
45
|
-
nextSearch() {
|
|
46
|
-
var _a;
|
|
47
|
-
(
|
|
58
|
+
nextSearch(step) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
if (step === undefined) {
|
|
61
|
+
(_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().navigateResults(1);
|
|
62
|
+
} else {
|
|
63
|
+
(_b = this.jsonViewer) === null || _b === void 0 ? void 0 : _b.getSearchWidget().navigateResults(step);
|
|
64
|
+
}
|
|
48
65
|
}
|
|
49
66
|
replace(replaceText) {
|
|
50
67
|
var _a;
|
|
@@ -66,5 +83,9 @@ class JsonViewerFoundation extends _foundation.default {
|
|
|
66
83
|
showSearchBar() {
|
|
67
84
|
this._adapter.showSearchBar();
|
|
68
85
|
}
|
|
86
|
+
getSearchResults() {
|
|
87
|
+
var _a;
|
|
88
|
+
return (_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().searchResults;
|
|
89
|
+
}
|
|
69
90
|
}
|
|
70
91
|
var _default = exports.default = JsonViewerFoundation;
|
|
@@ -51,6 +51,12 @@ export default class CropperFoundation<P = Record<string, any>, S = Record<strin
|
|
|
51
51
|
rangeX: [number, number];
|
|
52
52
|
rangeY: [number, number];
|
|
53
53
|
initial: boolean;
|
|
54
|
+
previewImg: HTMLImageElement;
|
|
55
|
+
previewContainer: HTMLElement;
|
|
56
|
+
previewContainerInitSize: {
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
};
|
|
54
60
|
constructor(adapter: CropperAdapter<P, S>);
|
|
55
61
|
init(): void;
|
|
56
62
|
destroy(): void;
|
|
@@ -72,6 +78,15 @@ export default class CropperFoundation<P = Record<string, any>, S = Record<strin
|
|
|
72
78
|
};
|
|
73
79
|
handleResize: () => void;
|
|
74
80
|
handleImageLoad: (e: any) => void;
|
|
81
|
+
renderPreview: () => void;
|
|
82
|
+
updatePreview: (props: {
|
|
83
|
+
width: number;
|
|
84
|
+
height: number;
|
|
85
|
+
translateX: number;
|
|
86
|
+
translateY: number;
|
|
87
|
+
rotate: number;
|
|
88
|
+
}) => void;
|
|
89
|
+
removePreview: () => void;
|
|
75
90
|
handleWheel: (e: any) => void;
|
|
76
91
|
getMoveParamByDir(dir: string): {
|
|
77
92
|
paramX: number;
|
|
@@ -149,6 +149,87 @@ export default class CropperFoundation extends BaseFoundation {
|
|
|
149
149
|
cropperBox: newCropperBoxState,
|
|
150
150
|
loaded: true
|
|
151
151
|
});
|
|
152
|
+
this.renderPreview();
|
|
153
|
+
};
|
|
154
|
+
this.renderPreview = () => {
|
|
155
|
+
const {
|
|
156
|
+
preview,
|
|
157
|
+
src
|
|
158
|
+
} = this.getProps();
|
|
159
|
+
const previewNode = preview === null || preview === void 0 ? void 0 : preview();
|
|
160
|
+
if (!previewNode) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const img = document.createElement('img');
|
|
164
|
+
this.previewImg = img;
|
|
165
|
+
this.previewContainer = previewNode;
|
|
166
|
+
img.src = src;
|
|
167
|
+
previewNode.appendChild(img);
|
|
168
|
+
this.previewContainer.style.overflow = 'hidden';
|
|
169
|
+
// 记录预览容器初始宽高
|
|
170
|
+
const {
|
|
171
|
+
width: previewWidth,
|
|
172
|
+
height: previewHeight
|
|
173
|
+
} = previewNode.getBoundingClientRect();
|
|
174
|
+
this.previewContainerInitSize = {
|
|
175
|
+
width: previewWidth,
|
|
176
|
+
height: previewHeight
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
this.updatePreview = props => {
|
|
180
|
+
if (!this.previewImg) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const {
|
|
184
|
+
cropperBox
|
|
185
|
+
} = this.getStates();
|
|
186
|
+
let zoom = 1;
|
|
187
|
+
const {
|
|
188
|
+
width: containerWidth,
|
|
189
|
+
height: containerHeight
|
|
190
|
+
} = this.previewContainerInitSize;
|
|
191
|
+
let previewWidth = containerWidth;
|
|
192
|
+
let previewHeight = containerHeight;
|
|
193
|
+
if (previewWidth < previewHeight) {
|
|
194
|
+
zoom = containerWidth / cropperBox.width;
|
|
195
|
+
let tempHeight = zoom * cropperBox.height;
|
|
196
|
+
if (tempHeight > containerHeight) {
|
|
197
|
+
zoom = containerHeight / cropperBox.height;
|
|
198
|
+
previewWidth = zoom * cropperBox.width;
|
|
199
|
+
} else {
|
|
200
|
+
previewHeight = tempHeight;
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
zoom = containerHeight / cropperBox.height;
|
|
204
|
+
let tempWidth = zoom * cropperBox.width;
|
|
205
|
+
if (tempWidth > containerWidth) {
|
|
206
|
+
zoom = containerWidth / cropperBox.width;
|
|
207
|
+
previewHeight = zoom * cropperBox.height;
|
|
208
|
+
} else {
|
|
209
|
+
previewWidth = tempWidth;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const {
|
|
213
|
+
width,
|
|
214
|
+
height,
|
|
215
|
+
translateX,
|
|
216
|
+
translateY,
|
|
217
|
+
rotate
|
|
218
|
+
} = props;
|
|
219
|
+
// Set the image style
|
|
220
|
+
this.previewImg.style.width = `${width * zoom}px`;
|
|
221
|
+
this.previewImg.style.height = `${height * zoom}px`;
|
|
222
|
+
this.previewImg.style.transform = `translate(${translateX * zoom}px, ${translateY * zoom}px) rotate(${rotate}deg)`;
|
|
223
|
+
this.previewImg.style.transformOrigin = 'center';
|
|
224
|
+
// set preview container size
|
|
225
|
+
this.previewContainer.style.width = `${previewWidth}px`;
|
|
226
|
+
this.previewContainer.style.height = `${previewHeight}px`;
|
|
227
|
+
};
|
|
228
|
+
this.removePreview = () => {
|
|
229
|
+
if (this.previewImg && this.previewContainer) {
|
|
230
|
+
this.previewContainer.removeChild(this.previewImg);
|
|
231
|
+
this.previewImg = null;
|
|
232
|
+
}
|
|
152
233
|
};
|
|
153
234
|
this.handleWheel = e => {
|
|
154
235
|
// 防止双手缩放导致页面被放大
|
|
@@ -722,6 +803,8 @@ export default class CropperFoundation extends BaseFoundation {
|
|
|
722
803
|
this.rangeX = null;
|
|
723
804
|
this.rangeY = null;
|
|
724
805
|
this.initial = false;
|
|
806
|
+
this.previewImg = null;
|
|
807
|
+
this.previewContainer = null;
|
|
725
808
|
}
|
|
726
809
|
init() {
|
|
727
810
|
// 获取容器的宽高
|
|
@@ -734,6 +817,7 @@ export default class CropperFoundation extends BaseFoundation {
|
|
|
734
817
|
destroy() {
|
|
735
818
|
this.unBindMoveEvent();
|
|
736
819
|
this.unBindResizeEvent();
|
|
820
|
+
this.removePreview();
|
|
737
821
|
}
|
|
738
822
|
getMoveParamByDir(dir) {
|
|
739
823
|
let paramX = 0,
|
|
@@ -14,12 +14,13 @@ declare class JsonViewerFoundation extends BaseFoundation<JsonViewerAdapter> {
|
|
|
14
14
|
constructor(adapter: JsonViewerAdapter);
|
|
15
15
|
jsonViewer: JsonViewer | null;
|
|
16
16
|
init(): void;
|
|
17
|
-
search(searchText: string): void;
|
|
18
|
-
prevSearch(): void;
|
|
19
|
-
nextSearch(): void;
|
|
17
|
+
search(searchText: string, caseSensitive?: boolean, wholeWord?: boolean, regex?: boolean): void;
|
|
18
|
+
prevSearch(step?: number): void;
|
|
19
|
+
nextSearch(step?: number): void;
|
|
20
20
|
replace(replaceText: string): void;
|
|
21
21
|
replaceAll(replaceText: string): void;
|
|
22
22
|
setSearchOptions(key: string): void;
|
|
23
23
|
showSearchBar(): void;
|
|
24
|
+
getSearchResults(): import("@douyinfe/semi-json-viewer-core/src/common/model").FindMatch[];
|
|
24
25
|
}
|
|
25
26
|
export default JsonViewerFoundation;
|
|
@@ -21,23 +21,40 @@ class JsonViewerFoundation extends BaseFoundation {
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
search(searchText) {
|
|
24
|
+
search(searchText, caseSensitive, wholeWord, regex) {
|
|
25
25
|
var _a;
|
|
26
|
-
|
|
26
|
+
let options;
|
|
27
|
+
if (caseSensitive !== undefined || wholeWord !== undefined || regex !== undefined) {
|
|
28
|
+
options = {
|
|
29
|
+
caseSensitive: caseSensitive !== null && caseSensitive !== void 0 ? caseSensitive : false,
|
|
30
|
+
wholeWord: wholeWord !== null && wholeWord !== void 0 ? wholeWord : false,
|
|
31
|
+
regex: regex !== null && regex !== void 0 ? regex : false
|
|
32
|
+
};
|
|
33
|
+
} else {
|
|
34
|
+
options = this.getState('searchOptions');
|
|
35
|
+
}
|
|
27
36
|
const {
|
|
28
|
-
caseSensitive,
|
|
29
|
-
wholeWord,
|
|
30
|
-
regex
|
|
31
|
-
} =
|
|
32
|
-
(_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().search(searchText,
|
|
37
|
+
caseSensitive: cs,
|
|
38
|
+
wholeWord: ww,
|
|
39
|
+
regex: rx
|
|
40
|
+
} = options;
|
|
41
|
+
(_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().search(searchText, cs, ww, rx);
|
|
33
42
|
}
|
|
34
|
-
prevSearch() {
|
|
35
|
-
var _a;
|
|
36
|
-
(
|
|
43
|
+
prevSearch(step) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
if (step === undefined) {
|
|
46
|
+
(_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().navigateResults(-1);
|
|
47
|
+
} else {
|
|
48
|
+
(_b = this.jsonViewer) === null || _b === void 0 ? void 0 : _b.getSearchWidget().navigateResults(-step);
|
|
49
|
+
}
|
|
37
50
|
}
|
|
38
|
-
nextSearch() {
|
|
39
|
-
var _a;
|
|
40
|
-
(
|
|
51
|
+
nextSearch(step) {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (step === undefined) {
|
|
54
|
+
(_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().navigateResults(1);
|
|
55
|
+
} else {
|
|
56
|
+
(_b = this.jsonViewer) === null || _b === void 0 ? void 0 : _b.getSearchWidget().navigateResults(step);
|
|
57
|
+
}
|
|
41
58
|
}
|
|
42
59
|
replace(replaceText) {
|
|
43
60
|
var _a;
|
|
@@ -59,5 +76,9 @@ class JsonViewerFoundation extends BaseFoundation {
|
|
|
59
76
|
showSearchBar() {
|
|
60
77
|
this._adapter.showSearchBar();
|
|
61
78
|
}
|
|
79
|
+
getSearchResults() {
|
|
80
|
+
var _a;
|
|
81
|
+
return (_a = this.jsonViewer) === null || _a === void 0 ? void 0 : _a.getSearchWidget().searchResults;
|
|
82
|
+
}
|
|
62
83
|
}
|
|
63
84
|
export default JsonViewerFoundation;
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douyinfe/semi-foundation",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.78.0-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build:lib": "node ./scripts/compileLib.js",
|
|
7
7
|
"prepublishOnly": "npm run build:lib"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@douyinfe/semi-animation": "2.
|
|
11
|
-
"@douyinfe/semi-json-viewer-core": "2.
|
|
10
|
+
"@douyinfe/semi-animation": "2.78.0-beta.0",
|
|
11
|
+
"@douyinfe/semi-json-viewer-core": "2.78.0-beta.0",
|
|
12
12
|
"@mdx-js/mdx": "^3.0.1",
|
|
13
13
|
"async-validator": "^3.5.0",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"*.scss",
|
|
30
30
|
"*.css"
|
|
31
31
|
],
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "763dd181e5b8c00d69b15a0cec20b011532742ab",
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@babel/plugin-transform-runtime": "^7.15.8",
|
|
35
35
|
"@babel/preset-env": "^7.15.8",
|