@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
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { IInteraction, InteractionInitOptions } from '../types';
|
|
2
2
|
import { Interaction } from './base';
|
|
3
|
+
export interface ZoomWheelOptions {
|
|
4
|
+
minViewBoxSize?: number;
|
|
5
|
+
maxViewBoxSize?: number;
|
|
6
|
+
}
|
|
3
7
|
export declare class ZoomWheel extends Interaction implements IInteraction {
|
|
4
8
|
name: string;
|
|
9
|
+
private minViewBoxSize;
|
|
10
|
+
private maxViewBoxSize;
|
|
11
|
+
constructor(options?: ZoomWheelOptions);
|
|
12
|
+
private initialViewBox;
|
|
13
|
+
private handleKeyUp;
|
|
5
14
|
private wheelListener;
|
|
6
15
|
private getMousePoint;
|
|
7
16
|
private getCenterPoint;
|
|
@@ -3,13 +3,26 @@ import { calculateZoomedViewBox, getViewBox, viewBoxToString, } from '../../util
|
|
|
3
3
|
import { UpdateOptionsCommand } from '../commands/index.js';
|
|
4
4
|
import { clientToViewport } from '../utils/index.js';
|
|
5
5
|
import { Interaction } from './base.js';
|
|
6
|
-
const MIN_VIEWBOX_SIZE = 20;
|
|
7
|
-
const MAX_VIEWBOX_SIZE = 2000;
|
|
8
6
|
const ZOOM_FACTOR = 1.1;
|
|
9
7
|
export class ZoomWheel extends Interaction {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super();
|
|
12
10
|
this.name = 'zoom-wheel';
|
|
11
|
+
this.minViewBoxSize = 20;
|
|
12
|
+
this.maxViewBoxSize = 20000;
|
|
13
|
+
this.initialViewBox = null;
|
|
14
|
+
this.handleKeyUp = (event) => {
|
|
15
|
+
const isZoomModifierHeld = event.ctrlKey || event.metaKey || event.shiftKey;
|
|
16
|
+
if (!isZoomModifierHeld && this.initialViewBox) {
|
|
17
|
+
const currentViewBox = viewBoxToString(getViewBox(this.editor.getDocument()));
|
|
18
|
+
if (currentViewBox !== this.initialViewBox) {
|
|
19
|
+
const command = new UpdateOptionsCommand({ viewBox: currentViewBox }, { viewBox: this.initialViewBox });
|
|
20
|
+
void this.commander.execute(command);
|
|
21
|
+
}
|
|
22
|
+
this.initialViewBox = null;
|
|
23
|
+
document.removeEventListener('keyup', this.handleKeyUp);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
13
26
|
this.wheelListener = (event) => {
|
|
14
27
|
if (!this.shouldZoom(event))
|
|
15
28
|
return;
|
|
@@ -22,25 +35,20 @@ export class ZoomWheel extends Interaction {
|
|
|
22
35
|
const { width, height } = viewBox;
|
|
23
36
|
const newWidth = width * factor;
|
|
24
37
|
const newHeight = height * factor;
|
|
25
|
-
if (!inRange(newWidth,
|
|
26
|
-
!inRange(newHeight,
|
|
27
|
-
return;
|
|
28
|
-
// TODO: Remove after implementing the reset UI plugin
|
|
29
|
-
if ((event.ctrlKey || event.metaKey) && event.shiftKey) {
|
|
30
|
-
const command = new UpdateOptionsCommand({
|
|
31
|
-
viewBox: undefined,
|
|
32
|
-
});
|
|
33
|
-
void this.commander.execute(command);
|
|
38
|
+
if (!inRange(newWidth, this.minViewBoxSize, this.maxViewBoxSize) ||
|
|
39
|
+
!inRange(newHeight, this.minViewBoxSize, this.maxViewBoxSize))
|
|
34
40
|
return;
|
|
41
|
+
if (this.initialViewBox === null) {
|
|
42
|
+
this.initialViewBox = viewBoxToString(viewBox);
|
|
43
|
+
document.addEventListener('keyup', this.handleKeyUp);
|
|
35
44
|
}
|
|
36
45
|
const pivot = (event.ctrlKey || event.metaKey) && !event.shiftKey
|
|
37
46
|
? this.getMousePoint(svg, event)
|
|
38
47
|
: this.getCenterPoint(viewBox);
|
|
39
48
|
const newViewBox = calculateZoomedViewBox(viewBox, factor, pivot);
|
|
40
|
-
|
|
49
|
+
this.state.updateOptions({
|
|
41
50
|
viewBox: viewBoxToString(newViewBox),
|
|
42
51
|
});
|
|
43
|
-
void this.commander.execute(command);
|
|
44
52
|
};
|
|
45
53
|
this.getMousePoint = (svg, event) => {
|
|
46
54
|
return clientToViewport(svg, event.clientX, event.clientY);
|
|
@@ -57,8 +65,16 @@ export class ZoomWheel extends Interaction {
|
|
|
57
65
|
return false;
|
|
58
66
|
const isMouseZoom = event.ctrlKey || event.metaKey;
|
|
59
67
|
const isCenterZoom = event.shiftKey;
|
|
68
|
+
if (isMouseZoom && isCenterZoom)
|
|
69
|
+
return false;
|
|
60
70
|
return isMouseZoom || isCenterZoom;
|
|
61
71
|
};
|
|
72
|
+
if ((options === null || options === void 0 ? void 0 : options.minViewBoxSize) !== undefined) {
|
|
73
|
+
this.minViewBoxSize = options.minViewBoxSize;
|
|
74
|
+
}
|
|
75
|
+
if ((options === null || options === void 0 ? void 0 : options.maxViewBoxSize) !== undefined) {
|
|
76
|
+
this.maxViewBoxSize = options.maxViewBoxSize;
|
|
77
|
+
}
|
|
62
78
|
}
|
|
63
79
|
init(options) {
|
|
64
80
|
super.init(options);
|
|
@@ -66,5 +82,6 @@ export class ZoomWheel extends Interaction {
|
|
|
66
82
|
}
|
|
67
83
|
destroy() {
|
|
68
84
|
document.removeEventListener('wheel', this.wheelListener);
|
|
85
|
+
document.removeEventListener('keyup', this.handleKeyUp);
|
|
69
86
|
}
|
|
70
87
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ParsedInfographicOptions } from '../../options';
|
|
1
|
+
import type { ParsedInfographicOptions, UpdatableInfographicOptions } from '../../options';
|
|
2
2
|
import type { Element, IEventEmitter, ItemDatum } from '../../types';
|
|
3
3
|
import type { ElementProps, ICommandManager, IEditor, IStateManager, StateManagerInitOptions } from '../types';
|
|
4
4
|
export declare class StateManager implements IStateManager {
|
|
@@ -12,7 +12,9 @@ export declare class StateManager implements IStateManager {
|
|
|
12
12
|
removeItemDatum(indexes: number[], count?: number): void;
|
|
13
13
|
updateData(key: string, value: any): void;
|
|
14
14
|
updateElement(element: Element, props: Partial<ElementProps>): void;
|
|
15
|
-
updateOptions(options:
|
|
15
|
+
updateOptions(options: UpdatableInfographicOptions, execOptions?: {
|
|
16
|
+
bubbleUp?: boolean;
|
|
17
|
+
}): void;
|
|
16
18
|
getOptions(): ParsedInfographicOptions;
|
|
17
19
|
/**
|
|
18
20
|
* 不包含文本内容、图标类型更新
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getDatumByIndexes, getElementRole, isIconElement
|
|
2
|
-
import { buildItemPath, getChildrenDataByIndexes, getIndexesFromElement, } from '../utils/index.js';
|
|
1
|
+
import { getDatumByIndexes, getElementRole, isIconElement } from '../../utils/index.js';
|
|
2
|
+
import { applyOptionUpdates, buildItemPath, getChildrenDataByIndexes, getIndexesFromElement, } from '../utils/index.js';
|
|
3
3
|
export class StateManager {
|
|
4
4
|
init(options) {
|
|
5
5
|
Object.assign(this, options);
|
|
@@ -25,6 +25,8 @@ export class StateManager {
|
|
|
25
25
|
}
|
|
26
26
|
updateItemDatum(indexes, datum) {
|
|
27
27
|
const item = getDatumByIndexes(this.options.data, indexes);
|
|
28
|
+
if (item == null || indexes.length === 0)
|
|
29
|
+
return;
|
|
28
30
|
Object.assign(item, datum);
|
|
29
31
|
this.emitter.emit('options:data:item:update', { indexes, datum });
|
|
30
32
|
this.emitter.emit('options:change', {
|
|
@@ -74,17 +76,14 @@ export class StateManager {
|
|
|
74
76
|
updateElement(element, props) {
|
|
75
77
|
this.updateBuiltInElement(element, props);
|
|
76
78
|
}
|
|
77
|
-
updateOptions(options) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
setSVGPadding(this.editor.getDocument(), parsePadding(this.options.padding));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
79
|
+
updateOptions(options, execOptions) {
|
|
80
|
+
const { bubbleUp = false } = execOptions || {};
|
|
81
|
+
applyOptionUpdates(this.options, options, '', {
|
|
82
|
+
bubbleUp,
|
|
83
|
+
collector: (path, newVal, oldVal) => {
|
|
84
|
+
this.editor.syncRegistry.trigger(path, newVal, oldVal);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
88
87
|
this.emitter.emit('options:change', {
|
|
89
88
|
type: 'options:change',
|
|
90
89
|
changes: [
|
|
@@ -115,6 +114,8 @@ export class StateManager {
|
|
|
115
114
|
const indexes = isItemElement ? getIndexesFromElement(element) : undefined;
|
|
116
115
|
if (isItemElement) {
|
|
117
116
|
const datum = getDatumByIndexes(data, indexes);
|
|
117
|
+
if (datum == null)
|
|
118
|
+
return;
|
|
118
119
|
const key = role.replace('item-', '');
|
|
119
120
|
datum.attributes || (datum.attributes = {});
|
|
120
121
|
(_a = datum.attributes)[key] || (_a[key] = {});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { InfographicOptionPath } from '../../options';
|
|
2
|
+
import { ISyncRegistry, SyncHandler } from '../types';
|
|
3
|
+
type OptionsGetter = () => any;
|
|
4
|
+
export declare class SyncRegistry implements ISyncRegistry {
|
|
5
|
+
private getOptions;
|
|
6
|
+
private handlers;
|
|
7
|
+
private isDispatching;
|
|
8
|
+
private isDestroyed;
|
|
9
|
+
constructor(getOptions: OptionsGetter);
|
|
10
|
+
register(path: InfographicOptionPath | (string & {}), handler: SyncHandler, options?: {
|
|
11
|
+
immediate?: boolean;
|
|
12
|
+
}): () => void;
|
|
13
|
+
trigger(path: string, newVal: any, oldVal: any): void;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { get } from 'lodash-es';
|
|
2
|
+
export class SyncRegistry {
|
|
3
|
+
constructor(getOptions) {
|
|
4
|
+
this.getOptions = getOptions;
|
|
5
|
+
this.handlers = new Map();
|
|
6
|
+
// lock to prevent recursive updates
|
|
7
|
+
this.isDispatching = false;
|
|
8
|
+
this.isDestroyed = false;
|
|
9
|
+
}
|
|
10
|
+
register(path, handler, options) {
|
|
11
|
+
if (!this.handlers.has(path)) {
|
|
12
|
+
this.handlers.set(path, new Set());
|
|
13
|
+
}
|
|
14
|
+
this.handlers.get(path).add(handler);
|
|
15
|
+
if (options === null || options === void 0 ? void 0 : options.immediate) {
|
|
16
|
+
const currentVal = get(this.getOptions(), path);
|
|
17
|
+
handler(currentVal, undefined);
|
|
18
|
+
}
|
|
19
|
+
return () => {
|
|
20
|
+
const set = this.handlers.get(path);
|
|
21
|
+
if (set) {
|
|
22
|
+
set.delete(handler);
|
|
23
|
+
if (set.size === 0) {
|
|
24
|
+
this.handlers.delete(path);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
trigger(path, newVal, oldVal) {
|
|
30
|
+
if (this.isDestroyed || this.isDispatching) {
|
|
31
|
+
if (this.isDispatching) {
|
|
32
|
+
console.warn(`[SyncRegistry] Recursive update detected on ${path}. Skipped to prevent loop.`);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const handlers = this.handlers.get(path);
|
|
37
|
+
if (handlers) {
|
|
38
|
+
this.isDispatching = true;
|
|
39
|
+
try {
|
|
40
|
+
handlers.forEach((fn) => fn(newVal, oldVal));
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
this.isDispatching = false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
destroy() {
|
|
48
|
+
this.isDestroyed = true;
|
|
49
|
+
this.handlers.clear();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { injectStyleOnce } from '
|
|
1
|
+
import { injectStyleOnce } from '../../../utils/index.js';
|
|
2
2
|
export const IconButton = ({ icon, onClick, activate = false, }) => {
|
|
3
3
|
ensureIconButtonStyle();
|
|
4
4
|
const button = document.createElement('button');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parse } from 'culori';
|
|
2
|
-
import { injectStyleOnce } from '
|
|
2
|
+
import { injectStyleOnce } from '../../../utils/index.js';
|
|
3
3
|
const COLOR_PICKER_CLASS = 'infographic-color-picker';
|
|
4
4
|
const COLOR_PICKER_SWATCHES_CLASS = `${COLOR_PICKER_CLASS}__swatches`;
|
|
5
5
|
const COLOR_PICKER_SWATCH_CLASS = `${COLOR_PICKER_CLASS}__swatch`;
|
|
@@ -13,6 +13,7 @@ export declare const TEXT_ICONS: {
|
|
|
13
13
|
alignCenter: ({ fill }?: IconProps) => HTMLElement;
|
|
14
14
|
alignMiddle: ({ fill }?: IconProps) => HTMLElement;
|
|
15
15
|
};
|
|
16
|
+
export declare const RESET_ICON: ({ fill }?: IconProps) => HTMLElement;
|
|
16
17
|
export declare const ELEMENT_ICONS: {
|
|
17
18
|
align: ({ fill }?: IconProps) => HTMLElement;
|
|
18
19
|
alignTop: ({ fill }?: IconProps) => HTMLElement;
|
|
@@ -16,6 +16,7 @@ export const TEXT_ICONS = {
|
|
|
16
16
|
alignCenter: createIcon(`<path d="M768 800.339c17.673 0 32 14.327 32 32 0 17.496-14.042 31.713-31.47 31.995l-0.53 0.005H256c-17.673 0-32-14.327-32-32 0-17.497 14.042-31.713 31.47-31.996l0.53-0.004h512z m128-213.226c17.673 0 32 14.327 32 32 0 17.496-14.042 31.713-31.47 31.996l-0.53 0.004H128c-17.673 0-32-14.327-32-32 0-17.496 14.042-31.713 31.47-31.996l0.53-0.004h768zM768 373.887c17.673 0 32 14.327 32 32 0 17.496-14.042 31.713-31.47 31.996l-0.53 0.004H256c-17.673 0-32-14.327-32-32 0-17.496 14.042-31.713 31.47-31.996l0.53-0.004h512z m128-213.226c17.673 0 32 14.327 32 32 0 17.497-14.042 31.713-31.47 31.996l-0.53 0.004H128c-17.673 0-32-14.327-32-32 0-17.496 14.042-31.713 31.47-31.995l0.53-0.005h768z"></path>`),
|
|
17
17
|
alignMiddle: createIcon(`<path d="M534.246 617.448l0.377 0.371 128 127.952c12.5 12.494 12.503 32.755 0.009 45.255-12.37 12.374-32.352 12.501-44.878 0.38l-0.377-0.372-73.38-73.352V939c0 17.673-14.326 32-32 32-17.496 0-31.712-14.042-31.995-31.47l-0.004-0.53-0.001-221.314-73.374 73.348c-12.374 12.37-32.356 12.49-44.878 0.363l-0.377-0.371c-12.37-12.375-12.49-32.356-0.362-44.878l0.37-0.377 128-127.952c12.372-12.366 32.347-12.49 44.87-0.37zM896 480.508c17.673 0 32 14.327 32 32 0 17.497-14.042 31.713-31.47 31.996l-0.53 0.004H128c-17.673 0-32-14.327-32-32 0-17.496 14.042-31.713 31.47-31.995l0.53-0.005h768zM511.998 54c17.496 0 31.713 14.042 31.996 31.47l0.004 0.53-0.001 221.314 73.38-73.349c12.499-12.494 32.76-12.49 45.255 0.009 12.37 12.374 12.49 32.356 0.362 44.878l-0.37 0.377-128 127.951c-12.372 12.366-32.347 12.49-44.87 0.371l-0.377-0.37-128-127.952c-12.5-12.495-12.503-32.756-0.009-45.255 12.37-12.374 32.352-12.502 44.878-0.38l0.377 0.371 73.374 73.346V86c0-17.673 14.328-32 32-32z"></path>`),
|
|
18
18
|
};
|
|
19
|
+
export const RESET_ICON = createIcon(`<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"/>`);
|
|
19
20
|
export const ELEMENT_ICONS = {
|
|
20
21
|
align: createIcon(`<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>`),
|
|
21
22
|
alignTop: createIcon(`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { COMPONENT_ROLE } from '
|
|
2
|
-
import { injectStyleOnce, setElementRole } from '
|
|
1
|
+
import { COMPONENT_ROLE } from '../../../constants/index.js';
|
|
2
|
+
import { injectStyleOnce, setElementRole } from '../../../utils/index.js';
|
|
3
3
|
const POPOVER_CLASS = 'infographic-edit-popover';
|
|
4
4
|
const POPOVER_CONTENT_CLASS = `${POPOVER_CLASS}__content`;
|
|
5
5
|
const POPOVER_ARROW_CLASS = `${POPOVER_CLASS}__arrow`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { injectStyleOnce } from '
|
|
1
|
+
import { injectStyleOnce } from '../../../utils/index.js';
|
|
2
2
|
const SELECT_CLASS = 'infographic-edit-select';
|
|
3
3
|
const SELECT_STYLE_ID = 'infographic-edit-select-style';
|
|
4
4
|
const OPTION_CLASS = `${SELECT_CLASS}__option`;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IPlugin, PluginInitOptions } from '../types';
|
|
2
|
+
import { Plugin } from './base';
|
|
3
|
+
export declare class CoreSyncPlugin extends Plugin implements IPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
private unregisters;
|
|
6
|
+
init(options: PluginInitOptions): void;
|
|
7
|
+
destroy(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { parsePadding, setSVGPadding } from '../../utils/index.js';
|
|
2
|
+
import { Plugin } from './base.js';
|
|
3
|
+
export class CoreSyncPlugin extends Plugin {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.name = 'core-sync';
|
|
7
|
+
this.unregisters = [];
|
|
8
|
+
}
|
|
9
|
+
init(options) {
|
|
10
|
+
super.init(options);
|
|
11
|
+
const svg = this.editor.getDocument();
|
|
12
|
+
// viewBox Sync
|
|
13
|
+
this.unregisters.push(this.editor.registerSync('viewBox', (val) => {
|
|
14
|
+
if (val) {
|
|
15
|
+
svg.setAttribute('viewBox', val);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
svg.removeAttribute('viewBox');
|
|
19
|
+
}
|
|
20
|
+
}, { immediate: true }));
|
|
21
|
+
// padding Sync
|
|
22
|
+
this.unregisters.push(this.editor.registerSync('padding', (val) => {
|
|
23
|
+
if (val !== undefined)
|
|
24
|
+
setSVGPadding(svg, parsePadding(val));
|
|
25
|
+
}, { immediate: true }));
|
|
26
|
+
}
|
|
27
|
+
destroy() {
|
|
28
|
+
this.unregisters.forEach((fn) => fn());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -2,7 +2,7 @@ import { getCombinedBounds } from '../../../../jsx/index.js';
|
|
|
2
2
|
import { getAttributes, injectStyleOnce, isIconElement, } from '../../../../utils/index.js';
|
|
3
3
|
import { UpdateElementCommand } from '../../../commands/index.js';
|
|
4
4
|
import { getElementViewportBounds } from '../../../utils/index.js';
|
|
5
|
-
import { ELEMENT_ICONS, IconButton, Popover } from '
|
|
5
|
+
import { ELEMENT_ICONS, IconButton, Popover } from '../../components/index.js';
|
|
6
6
|
const GRID_CLASS = 'infographic-align-grid';
|
|
7
7
|
const GRID_COMPACT_CLASS = `${GRID_CLASS}--compact`;
|
|
8
8
|
const GRID_STYLE_ID = 'infographic-align-grid-style';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { injectStyleOnce } from '../../../../utils/index.js';
|
|
2
2
|
import { UpdateElementCommand } from '../../../commands/index.js';
|
|
3
|
-
import { IconButton, Popover, TEXT_ICONS } from '
|
|
3
|
+
import { IconButton, Popover, TEXT_ICONS } from '../../components/index.js';
|
|
4
4
|
// 常量定义
|
|
5
5
|
const GRID_CLASS = 'infographic-font-align-grid';
|
|
6
6
|
const GRID_STYLE_ID = 'infographic-font-align-grid-style';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hasColor, injectStyleOnce } from '../../../../utils/index.js';
|
|
2
2
|
import { UpdateElementCommand } from '../../../commands/index.js';
|
|
3
|
-
import { ColorPicker, Popover } from '
|
|
3
|
+
import { ColorPicker, Popover } from '../../components/index.js';
|
|
4
4
|
const FONT_COLOR_BUTTON_CLASS = 'infographic-font-color-btn';
|
|
5
5
|
const FONT_COLOR_STYLE_ID = 'infographic-font-color-style';
|
|
6
6
|
const DEFAULT_COLOR = '#1f1f1f';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getFonts } from '../../../../renderer/index.js';
|
|
2
2
|
import { decodeFontFamily, encodeFontFamily, injectStyleOnce, } from '../../../../utils/index.js';
|
|
3
3
|
import { UpdateElementCommand } from '../../../commands/index.js';
|
|
4
|
-
import { IconButton, Popover, TEXT_ICONS } from '
|
|
4
|
+
import { IconButton, Popover, TEXT_ICONS } from '../../components/index.js';
|
|
5
5
|
const FONT_LIST_CLASS = 'infographic-font-family-list';
|
|
6
6
|
const FONT_OPTION_CLASS = `${FONT_LIST_CLASS}__option`;
|
|
7
7
|
const FONT_LIST_STYLE_ID = 'infographic-font-family-list-style';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { injectStyleOnce } from '../../../../utils/index.js';
|
|
2
2
|
import { UpdateElementCommand } from '../../../commands/index.js';
|
|
3
|
-
import { IconButton, Popover, TEXT_ICONS } from '
|
|
3
|
+
import { IconButton, Popover, TEXT_ICONS } from '../../components/index.js';
|
|
4
4
|
const FONT_SIZE_CLASS = 'infographic-font-size-grid';
|
|
5
5
|
const FONT_SIZE_STYLE_ID = 'infographic-font-size-grid-style';
|
|
6
6
|
const FONT_SIZE_OPTIONS = [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hasColor, injectStyleOnce } from '../../../../utils/index.js';
|
|
2
2
|
import { UpdateElementCommand } from '../../../commands/index.js';
|
|
3
|
-
import { ColorPicker, Popover } from '
|
|
3
|
+
import { ColorPicker, Popover } from '../../components/index.js';
|
|
4
4
|
const ICON_COLOR_BUTTON_CLASS = 'infographic-icon-color-btn';
|
|
5
5
|
const ICON_COLOR_STYLE_ID = 'infographic-icon-color-style';
|
|
6
6
|
const DEFAULT_COLOR = '#1f1f1f';
|
|
@@ -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
|
-
export type { ColorPickerHandle, ColorPickerProps, IconButtonHandle, IconButtonProps, IconProps, PopoverHandle, PopoverPlacement, PopoverProps, SelectHandle, SelectOption, SelectProps, SelectValue, } from '
|
|
3
|
+
export type { ColorPickerHandle, ColorPickerProps, IconButtonHandle, IconButtonProps, IconProps, PopoverHandle, PopoverPlacement, PopoverProps, SelectHandle, SelectOption, SelectProps, SelectValue, } from '../components';
|
|
4
4
|
export type { EditBarOptions } from './edit-bar';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ColorPicker, Popover, Select } from '
|
|
1
|
+
export { ColorPicker, Popover, Select } from '../components/index.js';
|
|
2
2
|
export { EditBar } from './edit-bar.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { IPlugin, PluginInitOptions } from '../types';
|
|
2
|
+
import { Plugin } from './base';
|
|
3
|
+
export interface ResetViewBoxOptions {
|
|
4
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
5
|
+
className?: string;
|
|
6
|
+
getContainer?: HTMLElement | (() => HTMLElement);
|
|
7
|
+
}
|
|
8
|
+
export declare class ResetViewBox extends Plugin implements IPlugin {
|
|
9
|
+
private options?;
|
|
10
|
+
name: string;
|
|
11
|
+
private originViewBox;
|
|
12
|
+
private resetButton?;
|
|
13
|
+
private viewBoxChanged;
|
|
14
|
+
private unregisterSync?;
|
|
15
|
+
constructor(options?: ResetViewBoxOptions | undefined);
|
|
16
|
+
init(options: PluginInitOptions): void;
|
|
17
|
+
destroy(): void;
|
|
18
|
+
private handleResize;
|
|
19
|
+
private updateOriginViewBox;
|
|
20
|
+
private handleViewBoxChange;
|
|
21
|
+
protected getOrCreateResetButton: () => HTMLButtonElement;
|
|
22
|
+
/** Get CSS transform scale of an element */
|
|
23
|
+
private getTransformScale;
|
|
24
|
+
/** Find the nearest stable overflow container */
|
|
25
|
+
private findStableContainer;
|
|
26
|
+
private placeButton;
|
|
27
|
+
private updatePosition;
|
|
28
|
+
private resetViewBox;
|
|
29
|
+
private showButton;
|
|
30
|
+
private hideButton;
|
|
31
|
+
private removeButton;
|
|
32
|
+
private ensureButtonStyle;
|
|
33
|
+
}
|