@antv/infographic 0.2.13 → 0.2.15
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/README.md +12 -5
- package/README.zh-CN.md +12 -5
- package/dist/infographic.min.js +180 -171
- package/dist/infographic.min.js.map +1 -1
- package/esm/designs/structures/index.d.ts +1 -0
- package/esm/designs/structures/index.js +1 -0
- package/esm/designs/structures/relation-dagre-flow.js +4 -139
- package/esm/designs/structures/sequence-interaction.d.ts +54 -0
- package/esm/designs/structures/sequence-interaction.js +440 -0
- package/esm/designs/utils/geometry.d.ts +44 -0
- package/esm/designs/utils/geometry.js +244 -0
- package/esm/designs/utils/index.d.ts +1 -0
- package/esm/designs/utils/index.js +1 -0
- package/esm/editor/commands/UpdateOptions.d.ts +4 -4
- package/esm/editor/commands/UpdateOptions.js +6 -3
- package/esm/editor/editor.d.ts +5 -1
- package/esm/editor/editor.js +16 -5
- package/esm/editor/index.d.ts +1 -0
- package/esm/editor/index.js +1 -0
- package/esm/editor/interactions/brush-select.d.ts +0 -1
- package/esm/editor/interactions/brush-select.js +2 -10
- package/esm/editor/interactions/drag-canvas.d.ts +35 -0
- package/esm/editor/interactions/drag-canvas.js +161 -0
- package/esm/editor/interactions/drag-element.js +4 -3
- package/esm/editor/interactions/index.d.ts +1 -0
- package/esm/editor/interactions/index.js +1 -0
- package/esm/editor/interactions/zoom-wheel.d.ts +9 -0
- package/esm/editor/interactions/zoom-wheel.js +32 -15
- package/esm/editor/managers/index.d.ts +1 -0
- package/esm/editor/managers/index.js +1 -0
- package/esm/editor/managers/state.d.ts +4 -2
- package/esm/editor/managers/state.js +14 -13
- package/esm/editor/managers/sync-registry.d.ts +16 -0
- package/esm/editor/managers/sync-registry.js +51 -0
- package/esm/editor/plugins/{edit-bar/components → components}/button.js +1 -1
- package/esm/editor/plugins/{edit-bar/components → components}/color-picker.js +1 -1
- package/esm/editor/plugins/{edit-bar/components → components}/icons.d.ts +1 -0
- package/esm/editor/plugins/{edit-bar/components → components}/icons.js +1 -0
- package/esm/editor/plugins/{edit-bar/components → components}/popover.js +2 -2
- package/esm/editor/plugins/{edit-bar/components → components}/select.js +1 -1
- package/esm/editor/plugins/core-sync.d.ts +8 -0
- package/esm/editor/plugins/core-sync.js +30 -0
- package/esm/editor/plugins/edit-bar/edit-items/align-elements.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-color.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-family.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/font-size.js +1 -1
- package/esm/editor/plugins/edit-bar/edit-items/icon-color.js +1 -1
- package/esm/editor/plugins/edit-bar/index.d.ts +2 -2
- package/esm/editor/plugins/edit-bar/index.js +1 -1
- package/esm/editor/plugins/index.d.ts +2 -0
- package/esm/editor/plugins/index.js +2 -0
- package/esm/editor/plugins/reset-viewbox.d.ts +33 -0
- package/esm/editor/plugins/reset-viewbox.js +186 -0
- package/esm/editor/types/editor.d.ts +14 -0
- package/esm/editor/types/index.d.ts +1 -0
- package/esm/editor/types/interaction.d.ts +9 -0
- package/esm/editor/types/state.d.ts +4 -2
- package/esm/editor/types/sync.d.ts +27 -0
- package/esm/editor/types/sync.js +1 -0
- package/esm/editor/utils/data.js +3 -1
- package/esm/editor/utils/event.d.ts +1 -0
- package/esm/editor/utils/event.js +8 -0
- package/esm/editor/utils/index.d.ts +1 -0
- package/esm/editor/utils/index.js +1 -0
- package/esm/editor/utils/object.d.ts +15 -0
- package/esm/editor/utils/object.js +77 -0
- package/esm/index.d.ts +4 -3
- package/esm/index.js +3 -2
- package/esm/options/types.d.ts +7 -0
- package/esm/runtime/Infographic.js +20 -7
- package/esm/runtime/options.js +7 -2
- package/esm/syntax/index.js +40 -20
- package/esm/syntax/relations.js +26 -2
- package/esm/syntax/schema.js +1 -0
- package/esm/templates/built-in.js +27 -2
- package/esm/templates/sequence-interaction.d.ts +2 -0
- package/esm/templates/sequence-interaction.js +76 -0
- package/esm/types/data.d.ts +1 -0
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/measure-text.js +40 -9
- package/esm/utils/padding.d.ts +1 -0
- package/esm/utils/padding.js +6 -2
- package/esm/utils/types.d.ts +16 -0
- package/esm/utils/types.js +12 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/designs/structures/index.d.ts +1 -0
- package/lib/designs/structures/index.js +1 -0
- package/lib/designs/structures/relation-dagre-flow.js +5 -140
- package/lib/designs/structures/sequence-interaction.d.ts +54 -0
- package/lib/designs/structures/sequence-interaction.js +444 -0
- package/lib/designs/utils/geometry.d.ts +44 -0
- package/lib/designs/utils/geometry.js +256 -0
- package/lib/designs/utils/index.d.ts +1 -0
- package/lib/designs/utils/index.js +1 -0
- package/lib/editor/commands/UpdateOptions.d.ts +4 -4
- package/lib/editor/commands/UpdateOptions.js +6 -3
- package/lib/editor/editor.d.ts +5 -1
- package/lib/editor/editor.js +16 -5
- package/lib/editor/index.d.ts +1 -0
- package/lib/editor/index.js +1 -0
- package/lib/editor/interactions/brush-select.d.ts +0 -1
- package/lib/editor/interactions/brush-select.js +1 -9
- package/lib/editor/interactions/drag-canvas.d.ts +35 -0
- package/lib/editor/interactions/drag-canvas.js +165 -0
- package/lib/editor/interactions/drag-element.js +4 -3
- package/lib/editor/interactions/index.d.ts +1 -0
- package/lib/editor/interactions/index.js +3 -1
- package/lib/editor/interactions/zoom-wheel.d.ts +9 -0
- package/lib/editor/interactions/zoom-wheel.js +32 -15
- package/lib/editor/managers/index.d.ts +1 -0
- package/lib/editor/managers/index.js +1 -0
- package/lib/editor/managers/state.d.ts +4 -2
- package/lib/editor/managers/state.js +12 -11
- package/lib/editor/managers/sync-registry.d.ts +16 -0
- package/lib/editor/managers/sync-registry.js +55 -0
- package/lib/editor/plugins/{edit-bar/components → components}/button.js +1 -1
- package/lib/editor/plugins/{edit-bar/components → components}/color-picker.js +1 -1
- package/lib/editor/plugins/{edit-bar/components → components}/icons.d.ts +1 -0
- package/lib/editor/plugins/{edit-bar/components → components}/icons.js +2 -1
- package/lib/editor/plugins/{edit-bar/components → components}/popover.js +2 -2
- package/lib/editor/plugins/{edit-bar/components → components}/select.js +1 -1
- package/lib/editor/plugins/core-sync.d.ts +8 -0
- package/lib/editor/plugins/core-sync.js +34 -0
- package/lib/editor/plugins/edit-bar/edit-items/align-elements.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-align.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-color.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-family.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/font-size.js +1 -1
- package/lib/editor/plugins/edit-bar/edit-items/icon-color.js +1 -1
- package/lib/editor/plugins/edit-bar/index.d.ts +2 -2
- package/lib/editor/plugins/edit-bar/index.js +1 -1
- package/lib/editor/plugins/index.d.ts +2 -0
- package/lib/editor/plugins/index.js +5 -1
- package/lib/editor/plugins/reset-viewbox.d.ts +33 -0
- package/lib/editor/plugins/reset-viewbox.js +190 -0
- package/lib/editor/types/editor.d.ts +14 -0
- package/lib/editor/types/index.d.ts +1 -0
- package/lib/editor/types/interaction.d.ts +9 -0
- package/lib/editor/types/state.d.ts +4 -2
- package/lib/editor/types/sync.d.ts +27 -0
- package/lib/editor/types/sync.js +2 -0
- package/lib/editor/utils/data.js +3 -1
- package/lib/editor/utils/event.d.ts +1 -0
- package/lib/editor/utils/event.js +9 -0
- package/lib/editor/utils/index.d.ts +1 -0
- package/lib/editor/utils/index.js +1 -0
- package/lib/editor/utils/object.d.ts +15 -0
- package/lib/editor/utils/object.js +80 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +9 -2
- package/lib/options/types.d.ts +7 -0
- package/lib/runtime/Infographic.js +19 -6
- package/lib/runtime/options.js +6 -1
- package/lib/syntax/index.js +40 -20
- package/lib/syntax/relations.js +26 -2
- package/lib/syntax/schema.js +1 -0
- package/lib/templates/built-in.js +27 -2
- package/lib/templates/sequence-interaction.d.ts +2 -0
- package/lib/templates/sequence-interaction.js +79 -0
- package/lib/types/data.d.ts +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/measure-text.js +39 -8
- package/lib/utils/padding.d.ts +1 -0
- package/lib/utils/padding.js +7 -2
- package/lib/utils/types.d.ts +16 -0
- package/lib/utils/types.js +13 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/designs/structures/index.ts +1 -0
- package/src/designs/structures/relation-dagre-flow.tsx +14 -178
- package/src/designs/structures/sequence-interaction.tsx +885 -0
- package/src/designs/utils/geometry.tsx +315 -0
- package/src/designs/utils/index.ts +1 -0
- package/src/editor/commands/UpdateOptions.ts +11 -6
- package/src/editor/editor.ts +26 -5
- package/src/editor/index.ts +1 -0
- package/src/editor/interactions/brush-select.ts +2 -8
- package/src/editor/interactions/drag-canvas.ts +203 -0
- package/src/editor/interactions/drag-element.ts +5 -4
- package/src/editor/interactions/index.ts +1 -0
- package/src/editor/interactions/zoom-wheel.ts +49 -13
- package/src/editor/managers/index.ts +1 -0
- package/src/editor/managers/state.ts +21 -21
- package/src/editor/managers/sync-registry.ts +66 -0
- package/src/editor/plugins/{edit-bar/components → components}/button.ts +1 -1
- package/src/editor/plugins/{edit-bar/components → components}/color-picker.ts +1 -1
- package/src/editor/plugins/{edit-bar/components → components}/icons.ts +4 -0
- package/src/editor/plugins/{edit-bar/components → components}/popover.ts +2 -2
- package/src/editor/plugins/{edit-bar/components → components}/select.ts +1 -1
- package/src/editor/plugins/core-sync.ts +44 -0
- package/src/editor/plugins/edit-bar/edit-items/align-elements.ts +2 -2
- package/src/editor/plugins/edit-bar/edit-items/font-align.ts +1 -1
- package/src/editor/plugins/edit-bar/edit-items/font-color.ts +1 -1
- package/src/editor/plugins/edit-bar/edit-items/font-family.ts +1 -1
- package/src/editor/plugins/edit-bar/edit-items/font-size.ts +3 -3
- package/src/editor/plugins/edit-bar/edit-items/icon-color.ts +1 -1
- package/src/editor/plugins/edit-bar/index.ts +2 -2
- package/src/editor/plugins/index.ts +2 -0
- package/src/editor/plugins/reset-viewbox.ts +258 -0
- package/src/editor/types/editor.ts +18 -0
- package/src/editor/types/index.ts +1 -0
- package/src/editor/types/interaction.ts +31 -0
- package/src/editor/types/state.ts +14 -2
- package/src/editor/types/sync.ts +33 -0
- package/src/editor/utils/data.ts +2 -1
- package/src/editor/utils/event.ts +7 -0
- package/src/editor/utils/index.ts +1 -0
- package/src/editor/utils/object.ts +116 -0
- package/src/index.ts +26 -2
- package/src/options/types.ts +11 -0
- package/src/runtime/Infographic.tsx +27 -17
- package/src/runtime/options.ts +8 -1
- package/src/syntax/index.ts +51 -18
- package/src/syntax/relations.ts +29 -2
- package/src/syntax/schema.ts +1 -0
- package/src/templates/built-in.ts +30 -0
- package/src/templates/sequence-interaction.ts +101 -0
- package/src/types/data.ts +1 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/measure-text.ts +41 -9
- package/src/utils/padding.ts +10 -2
- package/src/utils/types.ts +61 -0
- package/src/version.ts +1 -1
- /package/esm/editor/plugins/{edit-bar/components → components}/button.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/color-picker.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/index.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/index.js +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/popover.d.ts +0 -0
- /package/esm/editor/plugins/{edit-bar/components → components}/select.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/button.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/color-picker.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/index.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/index.js +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/popover.d.ts +0 -0
- /package/lib/editor/plugins/{edit-bar/components → components}/select.d.ts +0 -0
- /package/src/editor/plugins/{edit-bar/components → components}/index.ts +0 -0
|
@@ -9,12 +9,50 @@ import type { IInteraction, InteractionInitOptions } from '../types';
|
|
|
9
9
|
import { clientToViewport } from '../utils';
|
|
10
10
|
import { Interaction } from './base';
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
export interface ZoomWheelOptions {
|
|
13
|
+
minViewBoxSize?: number;
|
|
14
|
+
maxViewBoxSize?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
14
17
|
const ZOOM_FACTOR = 1.1;
|
|
15
18
|
|
|
16
19
|
export class ZoomWheel extends Interaction implements IInteraction {
|
|
17
20
|
name = 'zoom-wheel';
|
|
21
|
+
private minViewBoxSize = 20;
|
|
22
|
+
private maxViewBoxSize = 20000;
|
|
23
|
+
|
|
24
|
+
constructor(options?: ZoomWheelOptions) {
|
|
25
|
+
super();
|
|
26
|
+
if (options?.minViewBoxSize !== undefined) {
|
|
27
|
+
this.minViewBoxSize = options.minViewBoxSize;
|
|
28
|
+
}
|
|
29
|
+
if (options?.maxViewBoxSize !== undefined) {
|
|
30
|
+
this.maxViewBoxSize = options.maxViewBoxSize;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private initialViewBox: string | null = null;
|
|
35
|
+
|
|
36
|
+
private handleKeyUp = (event: KeyboardEvent) => {
|
|
37
|
+
const isZoomModifierHeld = event.ctrlKey || event.metaKey || event.shiftKey;
|
|
38
|
+
|
|
39
|
+
if (!isZoomModifierHeld && this.initialViewBox) {
|
|
40
|
+
const currentViewBox = viewBoxToString(
|
|
41
|
+
getViewBox(this.editor.getDocument()),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
if (currentViewBox !== this.initialViewBox) {
|
|
45
|
+
const command = new UpdateOptionsCommand(
|
|
46
|
+
{ viewBox: currentViewBox },
|
|
47
|
+
{ viewBox: this.initialViewBox },
|
|
48
|
+
);
|
|
49
|
+
void this.commander.execute(command);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.initialViewBox = null;
|
|
53
|
+
document.removeEventListener('keyup', this.handleKeyUp);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
18
56
|
|
|
19
57
|
private wheelListener = (event: WheelEvent) => {
|
|
20
58
|
if (!this.shouldZoom(event)) return;
|
|
@@ -32,19 +70,16 @@ export class ZoomWheel extends Interaction implements IInteraction {
|
|
|
32
70
|
const newHeight = height * factor;
|
|
33
71
|
|
|
34
72
|
if (
|
|
35
|
-
!inRange(newWidth,
|
|
36
|
-
!inRange(newHeight,
|
|
73
|
+
!inRange(newWidth, this.minViewBoxSize, this.maxViewBoxSize) ||
|
|
74
|
+
!inRange(newHeight, this.minViewBoxSize, this.maxViewBoxSize)
|
|
37
75
|
)
|
|
38
76
|
return;
|
|
39
77
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
viewBox: undefined,
|
|
44
|
-
});
|
|
45
|
-
void this.commander.execute(command);
|
|
46
|
-
return;
|
|
78
|
+
if (this.initialViewBox === null) {
|
|
79
|
+
this.initialViewBox = viewBoxToString(viewBox);
|
|
80
|
+
document.addEventListener('keyup', this.handleKeyUp);
|
|
47
81
|
}
|
|
82
|
+
|
|
48
83
|
const pivot =
|
|
49
84
|
(event.ctrlKey || event.metaKey) && !event.shiftKey
|
|
50
85
|
? this.getMousePoint(svg, event)
|
|
@@ -52,10 +87,9 @@ export class ZoomWheel extends Interaction implements IInteraction {
|
|
|
52
87
|
|
|
53
88
|
const newViewBox = calculateZoomedViewBox(viewBox, factor, pivot);
|
|
54
89
|
|
|
55
|
-
|
|
90
|
+
this.state.updateOptions({
|
|
56
91
|
viewBox: viewBoxToString(newViewBox),
|
|
57
92
|
});
|
|
58
|
-
void this.commander.execute(command);
|
|
59
93
|
};
|
|
60
94
|
|
|
61
95
|
private getMousePoint = (svg: SVGSVGElement, event: WheelEvent) => {
|
|
@@ -79,6 +113,7 @@ export class ZoomWheel extends Interaction implements IInteraction {
|
|
|
79
113
|
|
|
80
114
|
const isMouseZoom = event.ctrlKey || event.metaKey;
|
|
81
115
|
const isCenterZoom = event.shiftKey;
|
|
116
|
+
if (isMouseZoom && isCenterZoom) return false;
|
|
82
117
|
|
|
83
118
|
return isMouseZoom || isCenterZoom;
|
|
84
119
|
};
|
|
@@ -90,5 +125,6 @@ export class ZoomWheel extends Interaction implements IInteraction {
|
|
|
90
125
|
|
|
91
126
|
destroy() {
|
|
92
127
|
document.removeEventListener('wheel', this.wheelListener);
|
|
128
|
+
document.removeEventListener('keyup', this.handleKeyUp);
|
|
93
129
|
}
|
|
94
130
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { ElementTypeEnum } from '../../constants';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
ParsedInfographicOptions,
|
|
4
|
+
UpdatableInfographicOptions,
|
|
5
|
+
} from '../../options';
|
|
3
6
|
import type { Element, IEventEmitter, ItemDatum } from '../../types';
|
|
4
|
-
import {
|
|
5
|
-
getDatumByIndexes,
|
|
6
|
-
getElementRole,
|
|
7
|
-
isIconElement,
|
|
8
|
-
parsePadding,
|
|
9
|
-
setSVGPadding,
|
|
10
|
-
} from '../../utils';
|
|
7
|
+
import { getDatumByIndexes, getElementRole, isIconElement } from '../../utils';
|
|
11
8
|
import type {
|
|
12
9
|
ElementProps,
|
|
13
10
|
ICommandManager,
|
|
@@ -17,6 +14,7 @@ import type {
|
|
|
17
14
|
StateManagerInitOptions,
|
|
18
15
|
} from '../types';
|
|
19
16
|
import {
|
|
17
|
+
applyOptionUpdates,
|
|
20
18
|
buildItemPath,
|
|
21
19
|
getChildrenDataByIndexes,
|
|
22
20
|
getIndexesFromElement,
|
|
@@ -56,6 +54,7 @@ export class StateManager implements IStateManager {
|
|
|
56
54
|
|
|
57
55
|
updateItemDatum(indexes: number[], datum: Partial<ItemDatum>): void {
|
|
58
56
|
const item = getDatumByIndexes(this.options.data, indexes);
|
|
57
|
+
if (item == null || indexes.length === 0) return;
|
|
59
58
|
Object.assign(item, datum);
|
|
60
59
|
this.emitter.emit('options:data:item:update', { indexes, datum });
|
|
61
60
|
this.emitter.emit('options:change', {
|
|
@@ -111,19 +110,19 @@ export class StateManager implements IStateManager {
|
|
|
111
110
|
this.updateBuiltInElement(element, props);
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
updateOptions(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
113
|
+
updateOptions(
|
|
114
|
+
options: UpdatableInfographicOptions,
|
|
115
|
+
execOptions?: { bubbleUp?: boolean },
|
|
116
|
+
) {
|
|
117
|
+
const { bubbleUp = false } = execOptions || {};
|
|
118
|
+
|
|
119
|
+
applyOptionUpdates(this.options, options, '', {
|
|
120
|
+
bubbleUp,
|
|
121
|
+
collector: (path, newVal, oldVal) => {
|
|
122
|
+
this.editor.syncRegistry.trigger(path, newVal, oldVal);
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
127
126
|
this.emitter.emit('options:change', {
|
|
128
127
|
type: 'options:change',
|
|
129
128
|
changes: [
|
|
@@ -156,6 +155,7 @@ export class StateManager implements IStateManager {
|
|
|
156
155
|
const indexes = isItemElement ? getIndexesFromElement(element) : undefined;
|
|
157
156
|
if (isItemElement) {
|
|
158
157
|
const datum = getDatumByIndexes(data, indexes!);
|
|
158
|
+
if (datum == null) return;
|
|
159
159
|
const key = role.replace('item-', '');
|
|
160
160
|
datum.attributes ||= {};
|
|
161
161
|
datum.attributes[key] ||= {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { get } from 'lodash-es';
|
|
2
|
+
import type { InfographicOptionPath } from '../../options';
|
|
3
|
+
import { ISyncRegistry, SyncHandler } from '../types';
|
|
4
|
+
|
|
5
|
+
type OptionsGetter = () => any;
|
|
6
|
+
|
|
7
|
+
export class SyncRegistry implements ISyncRegistry {
|
|
8
|
+
private handlers = new Map<string, Set<SyncHandler>>();
|
|
9
|
+
// lock to prevent recursive updates
|
|
10
|
+
private isDispatching = false;
|
|
11
|
+
private isDestroyed = false;
|
|
12
|
+
|
|
13
|
+
constructor(private getOptions: OptionsGetter) {}
|
|
14
|
+
|
|
15
|
+
register(
|
|
16
|
+
path: InfographicOptionPath | (string & {}),
|
|
17
|
+
handler: SyncHandler,
|
|
18
|
+
options?: { immediate?: boolean },
|
|
19
|
+
): () => void {
|
|
20
|
+
if (!this.handlers.has(path)) {
|
|
21
|
+
this.handlers.set(path, new Set());
|
|
22
|
+
}
|
|
23
|
+
this.handlers.get(path)!.add(handler);
|
|
24
|
+
|
|
25
|
+
if (options?.immediate) {
|
|
26
|
+
const currentVal = get(this.getOptions(), path);
|
|
27
|
+
handler(currentVal, undefined);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
const set = this.handlers.get(path);
|
|
32
|
+
if (set) {
|
|
33
|
+
set.delete(handler);
|
|
34
|
+
if (set.size === 0) {
|
|
35
|
+
this.handlers.delete(path);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
trigger(path: string, newVal: any, oldVal: any): void {
|
|
41
|
+
if (this.isDestroyed || this.isDispatching) {
|
|
42
|
+
if (this.isDispatching) {
|
|
43
|
+
console.warn(
|
|
44
|
+
`[SyncRegistry] Recursive update detected on ${path}. Skipped to prevent loop.`,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const handlers = this.handlers.get(path);
|
|
51
|
+
|
|
52
|
+
if (handlers) {
|
|
53
|
+
this.isDispatching = true;
|
|
54
|
+
try {
|
|
55
|
+
handlers.forEach((fn) => fn(newVal, oldVal));
|
|
56
|
+
} finally {
|
|
57
|
+
this.isDispatching = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
destroy() {
|
|
63
|
+
this.isDestroyed = true;
|
|
64
|
+
this.handlers.clear();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -54,6 +54,10 @@ export const TEXT_ICONS = {
|
|
|
54
54
|
),
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
+
export const RESET_ICON = createIcon(
|
|
58
|
+
`<path d="M502.714987 58.258904l-126.531056-54.617723a52.797131 52.797131 0 0 0-41.873587 96.855428A447.865322 447.865322 0 0 0 392.02307 946.707184a61.535967 61.535967 0 0 0 13.83649 1.820591 52.797131 52.797131 0 0 0 13.65443-103.773672 342.453118 342.453118 0 0 1-31.678278-651.771485l-8.374718 19.480321a52.615072 52.615072 0 0 0 27.855039 69.182448 51.522718 51.522718 0 0 0 20.572675 4.369418A52.797131 52.797131 0 0 0 476.498481 254.882703L530.205907 127.441352a52.979191 52.979191 0 0 0-27.49092-69.182448zM962.960326 509.765407A448.775617 448.775617 0 0 0 643.992829 68.090094a52.797131 52.797131 0 1 0-30.403866 101.042786A342.635177 342.635177 0 0 1 674.578753 801.059925a52.615072 52.615072 0 0 0-92.30395-50.612422l-71.913335 117.246043a52.433013 52.433013 0 0 0 17.295612 72.82363l117.063985 72.823629a52.797131 52.797131 0 1 0 54.617722-89.755123l-16.021198-10.013249A448.593558 448.593558 0 0 0 962.960326 509.765407z" p-id="1630"/>`,
|
|
59
|
+
);
|
|
60
|
+
|
|
57
61
|
export const ELEMENT_ICONS = {
|
|
58
62
|
align: createIcon(
|
|
59
63
|
`<path d="M555.188 715.059c17.673 0 32 14.327 32 32V875c0 17.673-14.327 32-32 32H171c-17.673 0-32-14.327-32-32V747.059c0-17.673 14.327-32 32-32z m-32.001 63.999H203V843h320.187v-63.942zM854 416.529c17.673 0 32 14.327 32 32v127.942c0 17.673-14.327 32-32 32H171c-17.673 0-32-14.327-32-32V448.529c0-17.673 14.327-32 32-32z m-32 64H203v63.941h619v-63.941zM683.25 118c17.673 0 32 14.327 32 32v127.941c0 17.673-14.327 32-32 32H171c-17.673 0-32-14.327-32-32V150c0-17.673 14.327-32 32-32z m-32 64H203v63.941h448.25V182z"></path>`,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { COMPONENT_ROLE } from '
|
|
2
|
-
import { injectStyleOnce, setElementRole } from '
|
|
1
|
+
import { COMPONENT_ROLE } from '../../../constants';
|
|
2
|
+
import { injectStyleOnce, setElementRole } from '../../../utils';
|
|
3
3
|
|
|
4
4
|
export type PopoverPlacement = 'top' | 'bottom' | 'left' | 'right';
|
|
5
5
|
export type PopoverPlacementPreference = PopoverPlacement | PopoverPlacement[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { parsePadding, setSVGPadding } from '../../utils';
|
|
2
|
+
import type { IPlugin, PluginInitOptions } from '../types';
|
|
3
|
+
import { Plugin } from './base';
|
|
4
|
+
|
|
5
|
+
export class CoreSyncPlugin extends Plugin implements IPlugin {
|
|
6
|
+
name = 'core-sync';
|
|
7
|
+
|
|
8
|
+
private unregisters: (() => void)[] = [];
|
|
9
|
+
|
|
10
|
+
init(options: PluginInitOptions) {
|
|
11
|
+
super.init(options);
|
|
12
|
+
const svg = this.editor.getDocument();
|
|
13
|
+
|
|
14
|
+
// viewBox Sync
|
|
15
|
+
this.unregisters.push(
|
|
16
|
+
this.editor.registerSync(
|
|
17
|
+
'viewBox',
|
|
18
|
+
(val) => {
|
|
19
|
+
if (val) {
|
|
20
|
+
svg.setAttribute('viewBox', val);
|
|
21
|
+
} else {
|
|
22
|
+
svg.removeAttribute('viewBox');
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{ immediate: true },
|
|
26
|
+
),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// padding Sync
|
|
30
|
+
this.unregisters.push(
|
|
31
|
+
this.editor.registerSync(
|
|
32
|
+
'padding',
|
|
33
|
+
(val) => {
|
|
34
|
+
if (val !== undefined) setSVGPadding(svg, parsePadding(val));
|
|
35
|
+
},
|
|
36
|
+
{ immediate: true },
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
destroy() {
|
|
42
|
+
this.unregisters.forEach((fn) => fn());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
import { UpdateElementCommand } from '../../../commands';
|
|
9
9
|
import type { ICommandManager, Selection } from '../../../types';
|
|
10
10
|
import { getElementViewportBounds } from '../../../utils';
|
|
11
|
-
import { ELEMENT_ICONS, IconButton, Popover } from '
|
|
12
|
-
import type { Icon } from '
|
|
11
|
+
import { ELEMENT_ICONS, IconButton, Popover } from '../../components';
|
|
12
|
+
import type { Icon } from '../../components/icons';
|
|
13
13
|
import type { EditItem } from './types';
|
|
14
14
|
|
|
15
15
|
const GRID_CLASS = 'infographic-align-grid';
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
} from '../../../../types';
|
|
6
6
|
import { injectStyleOnce } from '../../../../utils';
|
|
7
7
|
import { UpdateElementCommand } from '../../../commands';
|
|
8
|
-
import { Button, IconButton, Popover, TEXT_ICONS } from '
|
|
8
|
+
import { Button, IconButton, Popover, TEXT_ICONS } from '../../components';
|
|
9
9
|
import type { EditItem } from './types';
|
|
10
10
|
|
|
11
11
|
// 常量定义
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TextAttributes } from '../../../../types';
|
|
2
2
|
import { hasColor, injectStyleOnce } from '../../../../utils';
|
|
3
3
|
import { UpdateElementCommand } from '../../../commands';
|
|
4
|
-
import { ColorPicker, Popover } from '
|
|
4
|
+
import { ColorPicker, Popover } from '../../components';
|
|
5
5
|
import type { EditItem } from './types';
|
|
6
6
|
|
|
7
7
|
const FONT_COLOR_BUTTON_CLASS = 'infographic-font-color-btn';
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
injectStyleOnce,
|
|
7
7
|
} from '../../../../utils';
|
|
8
8
|
import { UpdateElementCommand } from '../../../commands';
|
|
9
|
-
import { IconButton, Popover, TEXT_ICONS } from '
|
|
9
|
+
import { IconButton, Popover, TEXT_ICONS } from '../../components';
|
|
10
10
|
import type { EditItem } from './types';
|
|
11
11
|
|
|
12
12
|
const FONT_LIST_CLASS = 'infographic-font-family-list';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TextAttributes } from '../../../../types';
|
|
2
2
|
import { injectStyleOnce } from '../../../../utils';
|
|
3
3
|
import { UpdateElementCommand } from '../../../commands';
|
|
4
|
-
import { IconButton, Popover, TEXT_ICONS } from '
|
|
5
|
-
import type { Button } from '
|
|
6
|
-
import type { Icon } from '
|
|
4
|
+
import { IconButton, Popover, TEXT_ICONS } from '../../components';
|
|
5
|
+
import type { Button } from '../../components/button';
|
|
6
|
+
import type { Icon } from '../../components/icons';
|
|
7
7
|
import type { EditItem } from './types';
|
|
8
8
|
|
|
9
9
|
const FONT_SIZE_CLASS = 'infographic-font-size-grid';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IconAttributes } from '../../../../types';
|
|
2
2
|
import { hasColor, injectStyleOnce } from '../../../../utils';
|
|
3
3
|
import { UpdateElementCommand } from '../../../commands';
|
|
4
|
-
import { ColorPicker, Popover } from '
|
|
4
|
+
import { ColorPicker, Popover } from '../../components';
|
|
5
5
|
import type { EditItem } from './types';
|
|
6
6
|
|
|
7
7
|
const ICON_COLOR_BUTTON_CLASS = 'infographic-icon-color-btn';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ColorPicker, Popover, Select } from '
|
|
1
|
+
export { ColorPicker, Popover, Select } from '../components';
|
|
2
2
|
export { EditBar } from './edit-bar';
|
|
3
3
|
|
|
4
4
|
export type {
|
|
@@ -14,5 +14,5 @@ export type {
|
|
|
14
14
|
SelectOption,
|
|
15
15
|
SelectProps,
|
|
16
16
|
SelectValue,
|
|
17
|
-
} from '
|
|
17
|
+
} from '../components';
|
|
18
18
|
export type { EditBarOptions } from './edit-bar';
|