@grida/svg-editor 1.0.0-alpha.18 → 1.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -4
- package/dist/{dom-BMzX1CXZ.d.ts → dom-CQkWJNrK.d.ts} +77 -6
- package/dist/{dom-DKQ4Vt3z.js → dom-CfYDV311.js} +342 -55
- package/dist/{dom-OP-kmK8k.mjs → dom-Dub-TMoN.mjs} +342 -55
- package/dist/{dom-TctdgRnn.d.mts → dom-Dw2SPHgc.d.mts} +77 -6
- package/dist/dom.d.mts +3 -3
- package/dist/dom.d.ts +3 -3
- package/dist/dom.js +1 -1
- package/dist/dom.mjs +1 -1
- package/dist/{editor-Be6UrMeV.js → editor-4U9LAZ6r.js} +70 -182
- package/dist/{editor-BkCbYCz2.mjs → editor-B1GmFnS9.mjs} +63 -175
- package/dist/{editor-KqpIW1qm.d.mts → editor-CcW4BVth.d.mts} +54 -0
- package/dist/{editor-BSxTUsW_.d.ts → editor-CxqRhhzP.d.ts} +54 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{model-BLhMJZKJ.js → model-CzL6_zId.js} +179 -1
- package/dist/{model-DU0GOMwM.mjs → model-DS5MxDrd.mjs} +161 -2
- package/dist/presets.d.mts +2 -2
- package/dist/presets.d.ts +2 -2
- package/dist/presets.js +3 -4
- package/dist/presets.mjs +2 -3
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +13 -2
- package/dist/react.mjs +13 -2
- package/package.json +6 -5
package/dist/dom.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as BoundsResolver, E as CameraOptions, T as CameraConstraints, d as GestureContext, f as GestureId, g as MemoizedGeometryProvider, h as GeometrySignals, i as DomComputedResolver, m as GeometryProvider, p as Gestures, r as DomComputedPaint, u as GestureBinding, w as Camera } from "./editor-
|
|
2
|
-
import { a as
|
|
3
|
-
export { type BoundsResolver, Camera, type CameraConstraints, type CameraOptions, DEFAULT_SNAP_OPTIONS, type DomComputedPaint, type DomComputedResolver, DomSurfaceHandle, DomSurfaceOptions, type GeometryProvider, type GeometrySignals, type GestureBinding, type GestureContext, type GestureId, Gestures, MemoizedGeometryProvider, type SnapOptions, attach_dom_surface, install_font_load_geometry_bump, inverse_project_rect, project_delta_inverse_ctm, project_point_through_ctm };
|
|
1
|
+
import { C as BoundsResolver, E as CameraOptions, T as CameraConstraints, d as GestureContext, f as GestureId, g as MemoizedGeometryProvider, h as GeometrySignals, i as DomComputedResolver, m as GeometryProvider, p as Gestures, r as DomComputedPaint, u as GestureBinding, w as Camera } from "./editor-CcW4BVth.mjs";
|
|
2
|
+
import { a as install_font_load_geometry_bump, c as project_point_through_ctm, i as attach_dom_surface, l as DEFAULT_SNAP_OPTIONS, n as DomSurfaceHandle, o as inverse_project_rect, r as DomSurfaceOptions, s as project_delta_inverse_ctm, t as AttentionScope, u as SnapOptions } from "./dom-Dw2SPHgc.mjs";
|
|
3
|
+
export { AttentionScope, type BoundsResolver, Camera, type CameraConstraints, type CameraOptions, DEFAULT_SNAP_OPTIONS, type DomComputedPaint, type DomComputedResolver, DomSurfaceHandle, DomSurfaceOptions, type GeometryProvider, type GeometrySignals, type GestureBinding, type GestureContext, type GestureId, Gestures, MemoizedGeometryProvider, type SnapOptions, attach_dom_surface, install_font_load_geometry_bump, inverse_project_rect, project_delta_inverse_ctm, project_point_through_ctm };
|
package/dist/dom.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as BoundsResolver, E as CameraOptions, T as CameraConstraints, d as GestureContext, f as GestureId, g as MemoizedGeometryProvider, h as GeometrySignals, i as DomComputedResolver, m as GeometryProvider, p as Gestures, r as DomComputedPaint, u as GestureBinding, w as Camera } from "./editor-
|
|
2
|
-
import { a as
|
|
3
|
-
export { type BoundsResolver, Camera, type CameraConstraints, type CameraOptions, DEFAULT_SNAP_OPTIONS, type DomComputedPaint, type DomComputedResolver, DomSurfaceHandle, DomSurfaceOptions, type GeometryProvider, type GeometrySignals, type GestureBinding, type GestureContext, type GestureId, Gestures, MemoizedGeometryProvider, type SnapOptions, attach_dom_surface, install_font_load_geometry_bump, inverse_project_rect, project_delta_inverse_ctm, project_point_through_ctm };
|
|
1
|
+
import { C as BoundsResolver, E as CameraOptions, T as CameraConstraints, d as GestureContext, f as GestureId, g as MemoizedGeometryProvider, h as GeometrySignals, i as DomComputedResolver, m as GeometryProvider, p as Gestures, r as DomComputedPaint, u as GestureBinding, w as Camera } from "./editor-CxqRhhzP.js";
|
|
2
|
+
import { a as install_font_load_geometry_bump, c as project_point_through_ctm, i as attach_dom_surface, l as DEFAULT_SNAP_OPTIONS, n as DomSurfaceHandle, o as inverse_project_rect, r as DomSurfaceOptions, s as project_delta_inverse_ctm, t as AttentionScope, u as SnapOptions } from "./dom-CQkWJNrK.js";
|
|
3
|
+
export { AttentionScope, type BoundsResolver, Camera, type CameraConstraints, type CameraOptions, DEFAULT_SNAP_OPTIONS, type DomComputedPaint, type DomComputedResolver, DomSurfaceHandle, DomSurfaceOptions, type GeometryProvider, type GeometrySignals, type GestureBinding, type GestureContext, type GestureId, Gestures, MemoizedGeometryProvider, type SnapOptions, attach_dom_surface, install_font_load_geometry_bump, inverse_project_rect, project_delta_inverse_ctm, project_point_through_ctm };
|
package/dist/dom.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_dom = require("./dom-
|
|
2
|
+
const require_dom = require("./dom-CfYDV311.js");
|
|
3
3
|
exports.Camera = require_dom.Camera;
|
|
4
4
|
exports.DEFAULT_SNAP_OPTIONS = require_dom.DEFAULT_SNAP_OPTIONS;
|
|
5
5
|
exports.Gestures = require_dom.Gestures;
|
package/dist/dom.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as project_point_through_ctm, c as MemoizedGeometryProvider, i as project_delta_inverse_ctm, l as Camera, n as install_font_load_geometry_bump, o as Gestures, r as inverse_project_rect, s as DEFAULT_SNAP_OPTIONS, t as attach_dom_surface } from "./dom-
|
|
1
|
+
import { a as project_point_through_ctm, c as MemoizedGeometryProvider, i as project_delta_inverse_ctm, l as Camera, n as install_font_load_geometry_bump, o as Gestures, r as inverse_project_rect, s as DEFAULT_SNAP_OPTIONS, t as attach_dom_surface } from "./dom-Dub-TMoN.mjs";
|
|
2
2
|
export { Camera, DEFAULT_SNAP_OPTIONS, Gestures, MemoizedGeometryProvider, attach_dom_surface, install_font_load_geometry_bump, inverse_project_rect, project_delta_inverse_ctm, project_point_through_ctm };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_model = require("./model-
|
|
1
|
+
const require_model = require("./model-CzL6_zId.js");
|
|
2
2
|
let _grida_history = require("@grida/history");
|
|
3
3
|
let _grida_keybinding = require("@grida/keybinding");
|
|
4
4
|
let _grida_cmath = require("@grida/cmath");
|
|
@@ -38,164 +38,6 @@ var CommandRegistry = class {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
//#endregion
|
|
41
|
-
//#region src/commands/defaults.ts
|
|
42
|
-
/** Command id for `tool.set`. Bound to V/R/O/L in `keymap/defaults.ts`. */
|
|
43
|
-
const TOOL_SET = "tool.set";
|
|
44
|
-
/**
|
|
45
|
-
* The headless default `transform.nudge` handler. Exported so a host
|
|
46
|
-
* surface that overrides nudge (e.g. for faux-snap UX) can restore the
|
|
47
|
-
* default on teardown — the registry doesn't stack handlers, so a plain
|
|
48
|
-
* unregister leaves the slot empty.
|
|
49
|
-
*/
|
|
50
|
-
function default_nudge_handler(editor) {
|
|
51
|
-
return (args) => {
|
|
52
|
-
if (editor.state.selection.length === 0) return false;
|
|
53
|
-
const { dx, dy } = args;
|
|
54
|
-
editor.commands.nudge({
|
|
55
|
-
dx,
|
|
56
|
-
dy
|
|
57
|
-
});
|
|
58
|
-
return true;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function registerDefaultCommands(reg, editor) {
|
|
62
|
-
reg.register("history.undo", () => {
|
|
63
|
-
if (!editor.state.can_undo) return false;
|
|
64
|
-
editor.commands.undo();
|
|
65
|
-
return true;
|
|
66
|
-
});
|
|
67
|
-
reg.register("history.redo", () => {
|
|
68
|
-
if (!editor.state.can_redo) return false;
|
|
69
|
-
editor.commands.redo();
|
|
70
|
-
return true;
|
|
71
|
-
});
|
|
72
|
-
reg.register("selection.deselect", () => {
|
|
73
|
-
if (editor.state.selection.length === 0) return false;
|
|
74
|
-
editor.commands.deselect();
|
|
75
|
-
return true;
|
|
76
|
-
});
|
|
77
|
-
reg.register("selection.remove", () => {
|
|
78
|
-
if (editor.state.selection.length === 0) return false;
|
|
79
|
-
editor.commands.remove();
|
|
80
|
-
return true;
|
|
81
|
-
});
|
|
82
|
-
reg.register("selection.group", () => {
|
|
83
|
-
if (editor.state.mode !== "select") return false;
|
|
84
|
-
if (editor.state.selection.length === 0) return false;
|
|
85
|
-
return editor.commands.group();
|
|
86
|
-
});
|
|
87
|
-
reg.register("selection.duplicate", () => {
|
|
88
|
-
if (editor.state.mode !== "select") return false;
|
|
89
|
-
if (editor.state.selection.length === 0) return false;
|
|
90
|
-
return editor.commands.duplicate().length > 0;
|
|
91
|
-
});
|
|
92
|
-
reg.register("selection.ungroup", () => {
|
|
93
|
-
if (editor.state.mode !== "select") return false;
|
|
94
|
-
if (editor.state.selection.length !== 1) return false;
|
|
95
|
-
return editor.commands.ungroup();
|
|
96
|
-
});
|
|
97
|
-
reg.register("selection.resize_to", (args) => {
|
|
98
|
-
if (editor.state.mode !== "select") return false;
|
|
99
|
-
if (editor.state.selection.length === 0) return false;
|
|
100
|
-
const target = args;
|
|
101
|
-
return editor.commands.resize_to(target);
|
|
102
|
-
});
|
|
103
|
-
reg.register("selection.nudge_resize", (args) => {
|
|
104
|
-
if (editor.state.mode !== "select") return false;
|
|
105
|
-
if (editor.state.selection.length === 0) return false;
|
|
106
|
-
const { dw, dh } = args;
|
|
107
|
-
return editor.commands.resize_by({
|
|
108
|
-
dw,
|
|
109
|
-
dh
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
reg.register("selection.rotate", (args) => {
|
|
113
|
-
if (editor.state.mode !== "select") return false;
|
|
114
|
-
if (editor.state.selection.length === 0) return false;
|
|
115
|
-
const a = args;
|
|
116
|
-
return editor.commands.rotate(a.angle, { pivot: a.pivot });
|
|
117
|
-
});
|
|
118
|
-
reg.register("selection.rotate_to", (args) => {
|
|
119
|
-
if (editor.state.mode !== "select") return false;
|
|
120
|
-
if (editor.state.selection.length === 0) return false;
|
|
121
|
-
const a = args;
|
|
122
|
-
return editor.commands.rotate_to(a.angle, { pivot: a.pivot });
|
|
123
|
-
});
|
|
124
|
-
reg.register("selection.flatten_transform", () => {
|
|
125
|
-
if (editor.state.mode !== "select") return false;
|
|
126
|
-
if (editor.state.selection.length === 0) return false;
|
|
127
|
-
return editor.commands.flatten_transform();
|
|
128
|
-
});
|
|
129
|
-
reg.register("selection.all", () => {
|
|
130
|
-
if (editor.state.mode !== "select") return false;
|
|
131
|
-
return editor.commands.select_all();
|
|
132
|
-
});
|
|
133
|
-
reg.register("selection.sibling", (args) => {
|
|
134
|
-
if (editor.state.mode !== "select") return false;
|
|
135
|
-
return editor.commands.select_sibling(args);
|
|
136
|
-
});
|
|
137
|
-
reg.register("selection.align", (args) => {
|
|
138
|
-
if (editor.state.mode !== "select") return false;
|
|
139
|
-
return editor.commands.align(args);
|
|
140
|
-
});
|
|
141
|
-
reg.register("clipboard.copy", () => {
|
|
142
|
-
if (editor.state.mode !== "select") return false;
|
|
143
|
-
if (editor.state.selection.length === 0) return false;
|
|
144
|
-
return editor.commands.copy() !== null;
|
|
145
|
-
});
|
|
146
|
-
reg.register("clipboard.cut", () => {
|
|
147
|
-
if (editor.state.mode !== "select") return false;
|
|
148
|
-
if (editor.state.selection.length === 0) return false;
|
|
149
|
-
return editor.commands.cut() !== null;
|
|
150
|
-
});
|
|
151
|
-
reg.register("clipboard.paste", (args) => {
|
|
152
|
-
if (editor.state.mode !== "select") return false;
|
|
153
|
-
const text = args?.text;
|
|
154
|
-
if (typeof text === "string") return editor.commands.paste(text).length > 0;
|
|
155
|
-
const provider = editor.providers.clipboard;
|
|
156
|
-
if (provider) {
|
|
157
|
-
provider.read().then((text) => {
|
|
158
|
-
if (text) editor.commands.paste(text);
|
|
159
|
-
}).catch((err) => {
|
|
160
|
-
console.warn("[svg-editor] clipboard provider read failed:", err);
|
|
161
|
-
});
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
return editor.commands.paste().length > 0;
|
|
165
|
-
});
|
|
166
|
-
reg.register("content.enter", () => editor.enter_content_edit());
|
|
167
|
-
reg.register("hierarchy.enter", () => {
|
|
168
|
-
if (editor.state.selection.length !== 1) return false;
|
|
169
|
-
const id = editor.state.selection[0];
|
|
170
|
-
const node = editor.tree().nodes.get(id);
|
|
171
|
-
if (!node || node.children.length === 0) return false;
|
|
172
|
-
editor.commands.select(node.children[0]);
|
|
173
|
-
return true;
|
|
174
|
-
});
|
|
175
|
-
reg.register("hierarchy.exit", () => {
|
|
176
|
-
if (editor.state.selection.length !== 1) return false;
|
|
177
|
-
const id = editor.state.selection[0];
|
|
178
|
-
const tree = editor.tree();
|
|
179
|
-
const node = tree.nodes.get(id);
|
|
180
|
-
if (!node || node.parent === null || node.parent === tree.root) return false;
|
|
181
|
-
editor.commands.select(node.parent);
|
|
182
|
-
return true;
|
|
183
|
-
});
|
|
184
|
-
reg.register("transform.nudge", default_nudge_handler(editor));
|
|
185
|
-
reg.register("reorder", (args) => {
|
|
186
|
-
if (editor.state.selection.length !== 1) return false;
|
|
187
|
-
editor.commands.reorder(args);
|
|
188
|
-
return true;
|
|
189
|
-
});
|
|
190
|
-
reg.register(TOOL_SET, (args) => {
|
|
191
|
-
const next = args;
|
|
192
|
-
const required_mode = next.type === "lasso" || next.type === "bend" ? "edit-content" : next.type === "insert" || next.type === "insert-text" ? "select" : null;
|
|
193
|
-
if (required_mode !== null && editor.state.mode !== required_mode) return false;
|
|
194
|
-
editor.set_tool(next);
|
|
195
|
-
return true;
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
//#endregion
|
|
199
41
|
//#region src/keymap/keymap.ts
|
|
200
42
|
/**
|
|
201
43
|
* Keymap — bindings of declarative `Keybinding`s (from `@grida/keybinding`)
|
|
@@ -578,12 +420,12 @@ const DEFAULT_BINDINGS = [
|
|
|
578
420
|
},
|
|
579
421
|
{
|
|
580
422
|
keybinding: (0, _grida_keybinding.kb)(_grida_keybinding.KeyCode.KeyV),
|
|
581
|
-
command: TOOL_SET,
|
|
423
|
+
command: require_model.TOOL_SET,
|
|
582
424
|
args: { type: "cursor" }
|
|
583
425
|
},
|
|
584
426
|
{
|
|
585
427
|
keybinding: (0, _grida_keybinding.kb)(_grida_keybinding.KeyCode.KeyR),
|
|
586
|
-
command: TOOL_SET,
|
|
428
|
+
command: require_model.TOOL_SET,
|
|
587
429
|
args: {
|
|
588
430
|
type: "insert",
|
|
589
431
|
tag: "rect"
|
|
@@ -591,7 +433,7 @@ const DEFAULT_BINDINGS = [
|
|
|
591
433
|
},
|
|
592
434
|
{
|
|
593
435
|
keybinding: (0, _grida_keybinding.kb)(_grida_keybinding.KeyCode.KeyO),
|
|
594
|
-
command: TOOL_SET,
|
|
436
|
+
command: require_model.TOOL_SET,
|
|
595
437
|
args: {
|
|
596
438
|
type: "insert",
|
|
597
439
|
tag: "ellipse"
|
|
@@ -599,7 +441,7 @@ const DEFAULT_BINDINGS = [
|
|
|
599
441
|
},
|
|
600
442
|
{
|
|
601
443
|
keybinding: (0, _grida_keybinding.kb)(_grida_keybinding.KeyCode.KeyL),
|
|
602
|
-
command: TOOL_SET,
|
|
444
|
+
command: require_model.TOOL_SET,
|
|
603
445
|
args: {
|
|
604
446
|
type: "insert",
|
|
605
447
|
tag: "line"
|
|
@@ -607,12 +449,12 @@ const DEFAULT_BINDINGS = [
|
|
|
607
449
|
},
|
|
608
450
|
{
|
|
609
451
|
keybinding: (0, _grida_keybinding.kb)(_grida_keybinding.KeyCode.KeyT),
|
|
610
|
-
command: TOOL_SET,
|
|
452
|
+
command: require_model.TOOL_SET,
|
|
611
453
|
args: { type: "insert-text" }
|
|
612
454
|
},
|
|
613
455
|
{
|
|
614
456
|
keybinding: (0, _grida_keybinding.kb)(_grida_keybinding.KeyCode.KeyQ),
|
|
615
|
-
command: TOOL_SET,
|
|
457
|
+
command: require_model.TOOL_SET,
|
|
616
458
|
args: { type: "lasso" }
|
|
617
459
|
},
|
|
618
460
|
{
|
|
@@ -1526,8 +1368,28 @@ function _create_svg_editor_internal(opts) {
|
|
|
1526
1368
|
if (properties.choose_write_carrier(doc, id, name) === "inline_style") doc.set_style(id, name, value);
|
|
1527
1369
|
else doc.set_attr(id, name, value);
|
|
1528
1370
|
}
|
|
1371
|
+
/** Open `preview_property` sessions, keyed by property name. A discrete
|
|
1372
|
+
* write to the same name supersedes the in-flight gesture: the session
|
|
1373
|
+
* is silently discarded so a later host-side `commit()` cannot replay
|
|
1374
|
+
* the stale previewed value over the discrete write. The stored
|
|
1375
|
+
* function reverts the previewed value and unregisters itself. */
|
|
1376
|
+
const open_property_previews = /* @__PURE__ */ new Map();
|
|
1377
|
+
function supersede_property_preview(name) {
|
|
1378
|
+
open_property_previews.get(name)?.();
|
|
1379
|
+
}
|
|
1380
|
+
/** End EVERY open preview session. Called by operations that detach
|
|
1381
|
+
* nodes (remove / cut, ungroup) or replace the document (load,
|
|
1382
|
+
* reset): the sessions' deltas target nodes that are about to die,
|
|
1383
|
+
* so a later close-time `commit()` would push a dead history step.
|
|
1384
|
+
* Must run BEFORE the destructive mutation — each discard reverts
|
|
1385
|
+
* its in-flight delta against the still-intact document. (Live
|
|
1386
|
+
* iteration is safe: each discard deletes only its own map entry.) */
|
|
1387
|
+
function discard_open_property_previews() {
|
|
1388
|
+
for (const discard of open_property_previews.values()) discard();
|
|
1389
|
+
}
|
|
1529
1390
|
function set_property(name, value) {
|
|
1530
1391
|
if (selection.length === 0) return;
|
|
1392
|
+
supersede_property_preview(name);
|
|
1531
1393
|
const before = [];
|
|
1532
1394
|
for (const id of selection) before.push({
|
|
1533
1395
|
id,
|
|
@@ -1557,19 +1419,34 @@ function _create_svg_editor_internal(opts) {
|
|
|
1557
1419
|
});
|
|
1558
1420
|
}
|
|
1559
1421
|
function preview_property(name) {
|
|
1422
|
+
supersede_property_preview(name);
|
|
1423
|
+
const targets = [...selection];
|
|
1560
1424
|
const before = [];
|
|
1561
|
-
for (const id of
|
|
1425
|
+
for (const id of targets) before.push({
|
|
1562
1426
|
id,
|
|
1563
1427
|
attr: doc.get_attr(id, name),
|
|
1564
1428
|
style: doc.get_style(id, name)
|
|
1565
1429
|
});
|
|
1566
1430
|
const preview = history.preview(`change ${name}`);
|
|
1431
|
+
const live = () => preview.state === "active";
|
|
1432
|
+
const close = () => {
|
|
1433
|
+
if (open_property_previews.get(name) === discard) open_property_previews.delete(name);
|
|
1434
|
+
};
|
|
1435
|
+
const discard = () => {
|
|
1436
|
+
close();
|
|
1437
|
+
if (live()) preview.discard();
|
|
1438
|
+
};
|
|
1439
|
+
open_property_previews.set(name, discard);
|
|
1567
1440
|
return {
|
|
1441
|
+
get live() {
|
|
1442
|
+
return live();
|
|
1443
|
+
},
|
|
1568
1444
|
update(value) {
|
|
1445
|
+
if (!live()) return;
|
|
1569
1446
|
preview.set({
|
|
1570
1447
|
providerId: PROVIDER_ID,
|
|
1571
1448
|
apply: () => {
|
|
1572
|
-
for (const id of
|
|
1449
|
+
for (const id of targets) write_property(id, name, value);
|
|
1573
1450
|
emit();
|
|
1574
1451
|
},
|
|
1575
1452
|
revert: () => {
|
|
@@ -1582,8 +1459,11 @@ function _create_svg_editor_internal(opts) {
|
|
|
1582
1459
|
}
|
|
1583
1460
|
});
|
|
1584
1461
|
},
|
|
1585
|
-
commit: () =>
|
|
1586
|
-
|
|
1462
|
+
commit: () => {
|
|
1463
|
+
close();
|
|
1464
|
+
if (live()) preview.commit();
|
|
1465
|
+
},
|
|
1466
|
+
discard
|
|
1587
1467
|
};
|
|
1588
1468
|
}
|
|
1589
1469
|
function set_paint(channel, p) {
|
|
@@ -1593,6 +1473,9 @@ function _create_svg_editor_internal(opts) {
|
|
|
1593
1473
|
function preview_paint(channel) {
|
|
1594
1474
|
const session = preview_property(channel);
|
|
1595
1475
|
return {
|
|
1476
|
+
get live() {
|
|
1477
|
+
return session.live;
|
|
1478
|
+
},
|
|
1596
1479
|
update: (p) => session.update(require_model.paint.serialize(p)),
|
|
1597
1480
|
commit: () => session.commit(),
|
|
1598
1481
|
discard: () => session.discard()
|
|
@@ -2148,6 +2031,7 @@ function _create_svg_editor_internal(opts) {
|
|
|
2148
2031
|
if (selection.length === 0) return;
|
|
2149
2032
|
const filtered = doc.prune_nested_nodes(selection).filter((id) => doc.parent_of(id) !== null);
|
|
2150
2033
|
if (filtered.length === 0) return;
|
|
2034
|
+
discard_open_property_previews();
|
|
2151
2035
|
const captures = [...filtered].sort(require_model.subtree.by_document_order(doc)).map((id) => ({
|
|
2152
2036
|
id,
|
|
2153
2037
|
parent: doc.parent_of(id),
|
|
@@ -2209,6 +2093,7 @@ function _create_svg_editor_internal(opts) {
|
|
|
2209
2093
|
if (selection.length !== 1) return false;
|
|
2210
2094
|
target = selection[0];
|
|
2211
2095
|
}
|
|
2096
|
+
discard_open_property_previews();
|
|
2212
2097
|
const plan = require_model.group.plan_ungroup(doc, target);
|
|
2213
2098
|
if (!plan) return false;
|
|
2214
2099
|
const group_id = plan.group_id;
|
|
@@ -2363,6 +2248,8 @@ function _create_svg_editor_internal(opts) {
|
|
|
2363
2248
|
return copy_impl(true);
|
|
2364
2249
|
}
|
|
2365
2250
|
function cut_impl(deliver_external) {
|
|
2251
|
+
if (selection.length === 0) return null;
|
|
2252
|
+
discard_open_property_previews();
|
|
2366
2253
|
const payload = copy_impl(deliver_external);
|
|
2367
2254
|
if (payload === null) return null;
|
|
2368
2255
|
remove_selection("cut");
|
|
@@ -2461,7 +2348,7 @@ function _create_svg_editor_internal(opts) {
|
|
|
2461
2348
|
doc.insert(id, parent, insert_before);
|
|
2462
2349
|
set_selection([id]);
|
|
2463
2350
|
const preview = history.preview(`insert ${tag}`);
|
|
2464
|
-
|
|
2351
|
+
const live = () => preview.state === "active";
|
|
2465
2352
|
const apply = () => {
|
|
2466
2353
|
for (const name in live_attrs) doc.set_attr(id, name, live_attrs[name]);
|
|
2467
2354
|
if (doc.parent_of(id) === null) doc.insert(id, parent, insert_before);
|
|
@@ -2480,7 +2367,7 @@ function _create_svg_editor_internal(opts) {
|
|
|
2480
2367
|
return {
|
|
2481
2368
|
id,
|
|
2482
2369
|
update(attrs) {
|
|
2483
|
-
if (!
|
|
2370
|
+
if (!live()) return;
|
|
2484
2371
|
for (const name in attrs) {
|
|
2485
2372
|
live_attrs[name] = attrs[name];
|
|
2486
2373
|
doc.set_attr(id, name, attrs[name]);
|
|
@@ -2488,13 +2375,11 @@ function _create_svg_editor_internal(opts) {
|
|
|
2488
2375
|
preview.set(entry);
|
|
2489
2376
|
},
|
|
2490
2377
|
commit() {
|
|
2491
|
-
if (!
|
|
2492
|
-
active = false;
|
|
2378
|
+
if (!live()) return;
|
|
2493
2379
|
preview.commit();
|
|
2494
2380
|
},
|
|
2495
2381
|
discard() {
|
|
2496
|
-
if (!
|
|
2497
|
-
active = false;
|
|
2382
|
+
if (!live()) return;
|
|
2498
2383
|
preview.discard();
|
|
2499
2384
|
}
|
|
2500
2385
|
};
|
|
@@ -2536,7 +2421,7 @@ function _create_svg_editor_internal(opts) {
|
|
|
2536
2421
|
set_selection(previous_selection);
|
|
2537
2422
|
};
|
|
2538
2423
|
const preview = history.preview("insert text");
|
|
2539
|
-
|
|
2424
|
+
const live = () => preview.state === "active";
|
|
2540
2425
|
preview.set({
|
|
2541
2426
|
providerId: PROVIDER_ID,
|
|
2542
2427
|
apply,
|
|
@@ -2545,14 +2430,12 @@ function _create_svg_editor_internal(opts) {
|
|
|
2545
2430
|
return {
|
|
2546
2431
|
id,
|
|
2547
2432
|
commit() {
|
|
2548
|
-
if (!
|
|
2549
|
-
active = false;
|
|
2433
|
+
if (!live()) return;
|
|
2550
2434
|
committed_text = doc.text_of(id);
|
|
2551
2435
|
preview.commit();
|
|
2552
2436
|
},
|
|
2553
2437
|
discard() {
|
|
2554
|
-
if (!
|
|
2555
|
-
active = false;
|
|
2438
|
+
if (!live()) return;
|
|
2556
2439
|
preview.discard();
|
|
2557
2440
|
}
|
|
2558
2441
|
};
|
|
@@ -2620,12 +2503,13 @@ function _create_svg_editor_internal(opts) {
|
|
|
2620
2503
|
return content_edit_driver(id);
|
|
2621
2504
|
}
|
|
2622
2505
|
function load_svg(svg) {
|
|
2506
|
+
discard_open_property_previews();
|
|
2507
|
+
history.clear();
|
|
2623
2508
|
doc.load(svg);
|
|
2624
2509
|
selection = [];
|
|
2625
2510
|
scope = null;
|
|
2626
2511
|
mode = "select";
|
|
2627
2512
|
tool = require_model.TOOL_CURSOR;
|
|
2628
|
-
history.clear();
|
|
2629
2513
|
active_duplication = null;
|
|
2630
2514
|
baseline_revision = doc.revision;
|
|
2631
2515
|
load_version++;
|
|
@@ -2691,6 +2575,7 @@ function _create_svg_editor_internal(opts) {
|
|
|
2691
2575
|
return doc.serialize();
|
|
2692
2576
|
}
|
|
2693
2577
|
function reset() {
|
|
2578
|
+
discard_open_property_previews();
|
|
2694
2579
|
history.clear();
|
|
2695
2580
|
doc.reset_to_original();
|
|
2696
2581
|
selection = [];
|
|
@@ -2920,6 +2805,9 @@ function _create_svg_editor_internal(opts) {
|
|
|
2920
2805
|
set_geometry(p) {
|
|
2921
2806
|
geometry_provider = p;
|
|
2922
2807
|
},
|
|
2808
|
+
register_command(id, handler) {
|
|
2809
|
+
return registry.register(id, handler);
|
|
2810
|
+
},
|
|
2923
2811
|
bump_geometry() {
|
|
2924
2812
|
doc.bump_geometry();
|
|
2925
2813
|
fire_geometry_listeners_if_advanced();
|
|
@@ -2927,7 +2815,7 @@ function _create_svg_editor_internal(opts) {
|
|
|
2927
2815
|
},
|
|
2928
2816
|
keymap
|
|
2929
2817
|
};
|
|
2930
|
-
registerDefaultCommands(registry, public_editor);
|
|
2818
|
+
require_model.registerDefaultCommands(registry, public_editor);
|
|
2931
2819
|
applyDefaultBindings(keymap);
|
|
2932
2820
|
return public_editor;
|
|
2933
2821
|
}
|