@itwin/core-markup 4.0.0-dev.8 → 4.0.0-dev.80

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/lib/cjs/Markup.d.ts +323 -310
  3. package/lib/cjs/Markup.d.ts.map +1 -1
  4. package/lib/cjs/Markup.js +451 -420
  5. package/lib/cjs/Markup.js.map +1 -1
  6. package/lib/cjs/MarkupTool.d.ts +38 -38
  7. package/lib/cjs/MarkupTool.js +88 -88
  8. package/lib/cjs/MarkupTool.js.map +1 -1
  9. package/lib/cjs/RedlineTool.d.ts +145 -145
  10. package/lib/cjs/RedlineTool.d.ts.map +1 -1
  11. package/lib/cjs/RedlineTool.js +498 -512
  12. package/lib/cjs/RedlineTool.js.map +1 -1
  13. package/lib/cjs/SelectTool.d.ts +126 -126
  14. package/lib/cjs/SelectTool.js +741 -741
  15. package/lib/cjs/SelectTool.js.map +1 -1
  16. package/lib/cjs/SvgJsExt.d.ts +85 -85
  17. package/lib/cjs/SvgJsExt.js +185 -185
  18. package/lib/cjs/TextEdit.d.ts +43 -43
  19. package/lib/cjs/TextEdit.js +196 -196
  20. package/lib/cjs/TextEdit.js.map +1 -1
  21. package/lib/cjs/Undo.d.ts +46 -46
  22. package/lib/cjs/Undo.js +168 -168
  23. package/lib/cjs/core-markup.d.ts +18 -18
  24. package/lib/cjs/core-markup.js +38 -34
  25. package/lib/cjs/core-markup.js.map +1 -1
  26. package/lib/esm/Markup.d.ts +323 -310
  27. package/lib/esm/Markup.d.ts.map +1 -1
  28. package/lib/esm/Markup.js +447 -415
  29. package/lib/esm/Markup.js.map +1 -1
  30. package/lib/esm/MarkupTool.d.ts +38 -38
  31. package/lib/esm/MarkupTool.js +85 -84
  32. package/lib/esm/MarkupTool.js.map +1 -1
  33. package/lib/esm/RedlineTool.d.ts +145 -145
  34. package/lib/esm/RedlineTool.d.ts.map +1 -1
  35. package/lib/esm/RedlineTool.js +494 -498
  36. package/lib/esm/RedlineTool.js.map +1 -1
  37. package/lib/esm/SelectTool.d.ts +126 -126
  38. package/lib/esm/SelectTool.js +735 -734
  39. package/lib/esm/SelectTool.js.map +1 -1
  40. package/lib/esm/SvgJsExt.d.ts +85 -85
  41. package/lib/esm/SvgJsExt.js +180 -180
  42. package/lib/esm/TextEdit.d.ts +43 -43
  43. package/lib/esm/TextEdit.js +193 -191
  44. package/lib/esm/TextEdit.js.map +1 -1
  45. package/lib/esm/Undo.d.ts +46 -46
  46. package/lib/esm/Undo.js +164 -164
  47. package/lib/esm/core-markup.d.ts +18 -18
  48. package/lib/esm/core-markup.js +22 -22
  49. package/package.json +19 -19
@@ -1,197 +1,197 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module MarkupTools
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.EditTextTool = exports.PlaceTextTool = void 0;
11
- const core_frontend_1 = require("@itwin/core-frontend");
12
- const svg_js_1 = require("@svgdotjs/svg.js");
13
- const Markup_1 = require("./Markup");
14
- const MarkupTool_1 = require("./MarkupTool");
15
- const RedlineTool_1 = require("./RedlineTool");
16
- // cspell:ignore rbox
17
- /** Tool to place new text notes on a Markup.
18
- * @public
19
- */
20
- class PlaceTextTool extends RedlineTool_1.RedlineTool {
21
- constructor() {
22
- super(...arguments);
23
- this._nRequiredPoints = 1;
24
- this._minPoints = 0;
25
- }
26
- async onPostInstall() {
27
- this._value = Markup_1.MarkupApp.props.text.startValue; // so applications can put a default string (e.g. user's initials) in the note. Can be empty
28
- return super.onPostInstall();
29
- }
30
- showPrompt() { this.provideToolAssistance(`${MarkupTool_1.MarkupTool.toolKey}Text.Place.Prompts.FirstPoint`, true); }
31
- async createMarkup(svg, ev, isDynamics) {
32
- if (isDynamics && core_frontend_1.InputSource.Touch === ev.inputSource)
33
- return;
34
- const start = Markup_1.MarkupApp.convertVpToVb(ev.viewPoint); // starting point in viewbox coordinates
35
- const text = new svg_js_1.Text().plain(this._value); // create a plain text element
36
- svg.put(text); // add it to the supplied container
37
- this.setCurrentTextStyle(text); // apply active text style
38
- text.translate(start.x, start.y); // and position it relative to the cursor
39
- if (isDynamics) {
40
- svg.add(text.getOutline().attr(Markup_1.MarkupApp.props.text.edit.textBox).addClass(Markup_1.MarkupApp.textOutlineClass)); // in dynamics, draw the box around the text
41
- }
42
- else {
43
- await new EditTextTool(text, true).run(); // text is now positioned, open text editor
44
- }
45
- }
46
- async onResetButtonUp(_ev) {
47
- await this.exitTool();
48
- return core_frontend_1.EventHandled.Yes;
49
- }
50
- }
51
- exports.PlaceTextTool = PlaceTextTool;
52
- PlaceTextTool.toolId = "Markup.Text.Place";
53
- PlaceTextTool.iconSpec = "icon-text-medium";
54
- /** Tool for editing text. Started automatically by the place text tool and by clicking on text from the SelectTool
55
- * @public
56
- */
57
- class EditTextTool extends MarkupTool_1.MarkupTool {
58
- constructor(text, _fromPlaceTool = false) {
59
- super();
60
- this.text = text;
61
- this._fromPlaceTool = _fromPlaceTool;
62
- }
63
- showPrompt() {
64
- const mainInstruction = core_frontend_1.ToolAssistance.createInstruction(this.iconSpec, core_frontend_1.IModelApp.localization.getLocalizedString(`${MarkupTool_1.MarkupTool.toolKey}Text.Edit.Prompts.FirstPoint`));
65
- const mouseInstructions = [];
66
- const touchInstructions = [];
67
- const acceptMsg = core_frontend_1.CoreTools.translate("ElementSet.Inputs.Accept");
68
- const rejectMsg = core_frontend_1.CoreTools.translate("ElementSet.Inputs.Exit");
69
- touchInstructions.push(core_frontend_1.ToolAssistance.createInstruction(core_frontend_1.ToolAssistanceImage.OneTouchTap, acceptMsg, false, core_frontend_1.ToolAssistanceInputMethod.Touch));
70
- mouseInstructions.push(core_frontend_1.ToolAssistance.createInstruction(core_frontend_1.ToolAssistanceImage.LeftClick, acceptMsg, false, core_frontend_1.ToolAssistanceInputMethod.Mouse));
71
- touchInstructions.push(core_frontend_1.ToolAssistance.createInstruction(core_frontend_1.ToolAssistanceImage.TwoTouchTap, rejectMsg, false, core_frontend_1.ToolAssistanceInputMethod.Touch));
72
- mouseInstructions.push(core_frontend_1.ToolAssistance.createInstruction(core_frontend_1.ToolAssistanceImage.RightClick, rejectMsg, false, core_frontend_1.ToolAssistanceInputMethod.Mouse));
73
- const sections = [];
74
- sections.push(core_frontend_1.ToolAssistance.createSection(mouseInstructions, core_frontend_1.ToolAssistance.inputsLabel));
75
- sections.push(core_frontend_1.ToolAssistance.createSection(touchInstructions, core_frontend_1.ToolAssistance.inputsLabel));
76
- const instructions = core_frontend_1.ToolAssistance.createInstructions(mainInstruction, sections);
77
- core_frontend_1.IModelApp.notifications.setToolAssistance(instructions);
78
- }
79
- /** Open the text editor */
80
- startEditor() {
81
- let text = this.text;
82
- if (text === undefined)
83
- return;
84
- if (text instanceof svg_js_1.G) {
85
- this.boxed = text;
86
- text = text.children()[1];
87
- if (!(text instanceof svg_js_1.Text))
88
- return;
89
- this.text = text;
90
- }
91
- const markupDiv = this.markup.markupDiv;
92
- const editDiv = this.editDiv = document.createElement("div"); // create a new DIV to hold the text editor
93
- const editProps = Markup_1.MarkupApp.props.text.edit;
94
- let style = editDiv.style;
95
- style.backgroundColor = editProps.background;
96
- style.top = style.left = "0";
97
- style.right = style.bottom = "100%";
98
- markupDiv.appendChild(editDiv); // add textEditor div to markup div
99
- const divRect = markupDiv.getBoundingClientRect();
100
- const outline = text.getOutline(); // use the outline rather than the text in case it's blank.
101
- text.after(outline); // we have to add it to the DOM or the rbox call doesn't work.
102
- const rbox = outline.rbox();
103
- const bbox = outline.bbox();
104
- outline.remove(); // take it out again.
105
- const editor = this.editor = document.createElement("textarea");
106
- editDiv.appendChild(editor);
107
- editor.className = Markup_1.MarkupApp.textEditorClass;
108
- editor.contentEditable = "true";
109
- editor.spellcheck = true;
110
- editor.wrap = "off";
111
- // so we don't send these events to the ToolAdmin and process them by tools. We want default handling
112
- const mouseListener = (ev) => (ev.stopPropagation(), true);
113
- editor.onselectstart = editor.oncontextmenu = editor.onmousedown = editor.onmouseup = mouseListener; // enable default handling for these events
114
- // Tab, Escape, ctrl-enter, or shift-enter all end the editor
115
- editor.onkeydown = async (ev) => {
116
- if (ev.key === "Tab" || ev.key === "Escape" || (ev.key === "Enter" && (ev.shiftKey || ev.ctrlKey)))
117
- this.exitTool(); // eslint-disable-line @typescript-eslint/no-floating-promises
118
- ev.stopPropagation();
119
- };
120
- const textElStyle = window.getComputedStyle(text.node);
121
- style = editor.style;
122
- style.pointerEvents = "auto";
123
- style.position = "absolute";
124
- style.top = `${(rbox.cy - (bbox.h / 2)) - divRect.top}px`; // put the editor over the middle of the text element
125
- style.left = `${(rbox.cx - (bbox.w / 2)) - divRect.left}px`;
126
- style.height = editProps.size.height;
127
- style.width = editProps.size.width;
128
- style.resize = "both";
129
- style.fontFamily = textElStyle.fontFamily; // set the font family and anchor to the same as the text element
130
- style.textAnchor = textElStyle.textAnchor;
131
- style.fontSize = editProps.fontSize; // from app.props
132
- const parentZ = parseInt(window.getComputedStyle(markupDiv).zIndex || "0", 10);
133
- style.zIndex = (parentZ + 200).toString();
134
- editor.innerHTML = text.getMarkup(); // start with existing text
135
- this.editor.focus(); // give the editor focus
136
- // if we're started from the place text tool, select the entire current value, otherwise place the cursor at the end.
137
- this.editor.setSelectionRange(this._fromPlaceTool ? 0 : editor.value.length, editor.value.length);
138
- }
139
- /** Called when EditText exits, saves the edited value into the text element */
140
- async onCleanup() {
141
- if (!this.editDiv)
142
- return;
143
- const text = this.text;
144
- const original = this.boxed ? this.boxed : text;
145
- const undo = this.markup.undo;
146
- undo.performOperation(this.keyin, () => {
147
- const newVal = this.editor.value;
148
- if (newVal.trim() === "") { // if the result of the editing is blank, just delete the text element
149
- if (!this._fromPlaceTool)
150
- undo.onDelete(original);
151
- original.remove(); // must do this *after* we call undo.onDelete
152
- return;
153
- }
154
- let newText = text.clone();
155
- const fontSize = text.getFontSize();
156
- newText.createMarkup(newVal, fontSize);
157
- if (this.boxed) {
158
- newText = this.createBoxedText(original.parent(), newText);
159
- newText.matrix(original.matrix());
160
- }
161
- original.replace(newText);
162
- if (this._fromPlaceTool)
163
- undo.onAdded(newText);
164
- else
165
- undo.onModified(newText, original);
166
- });
167
- const editSize = Markup_1.MarkupApp.props.text.edit.size;
168
- const style = this.editor.style;
169
- editSize.height = style.height;
170
- editSize.width = style.width;
171
- this.editDiv.remove();
172
- this.editDiv = undefined;
173
- this.editor = undefined;
174
- }
175
- async onInstall() {
176
- if (!await super.onInstall())
177
- return false;
178
- this.startEditor();
179
- return true;
180
- }
181
- async onResetButtonUp(_ev) {
182
- await this.exitTool();
183
- return core_frontend_1.EventHandled.Yes;
184
- }
185
- async onDataButtonUp(_ev) {
186
- await this.exitTool();
187
- return core_frontend_1.EventHandled.Yes;
188
- }
189
- async onMouseStartDrag(_ev) {
190
- await this.exitTool();
191
- return core_frontend_1.EventHandled.Yes;
192
- }
193
- }
194
- exports.EditTextTool = EditTextTool;
195
- EditTextTool.toolId = "Markup.Text.Edit";
196
- EditTextTool.iconSpec = "icon-text-medium";
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module MarkupTools
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.EditTextTool = exports.PlaceTextTool = void 0;
11
+ const core_frontend_1 = require("@itwin/core-frontend");
12
+ const svg_js_1 = require("@svgdotjs/svg.js");
13
+ const Markup_1 = require("./Markup");
14
+ const MarkupTool_1 = require("./MarkupTool");
15
+ const RedlineTool_1 = require("./RedlineTool");
16
+ // cspell:ignore rbox
17
+ /** Tool to place new text notes on a Markup.
18
+ * @public
19
+ */
20
+ class PlaceTextTool extends RedlineTool_1.RedlineTool {
21
+ constructor() {
22
+ super(...arguments);
23
+ this._nRequiredPoints = 1;
24
+ this._minPoints = 0;
25
+ }
26
+ async onPostInstall() {
27
+ this._value = Markup_1.MarkupApp.props.text.startValue; // so applications can put a default string (e.g. user's initials) in the note. Can be empty
28
+ return super.onPostInstall();
29
+ }
30
+ showPrompt() { this.provideToolAssistance(`${MarkupTool_1.MarkupTool.toolKey}Text.Place.Prompts.FirstPoint`, true); }
31
+ async createMarkup(svg, ev, isDynamics) {
32
+ if (isDynamics && core_frontend_1.InputSource.Touch === ev.inputSource)
33
+ return;
34
+ const start = Markup_1.MarkupApp.convertVpToVb(ev.viewPoint); // starting point in viewbox coordinates
35
+ const text = new svg_js_1.Text().plain(this._value); // create a plain text element
36
+ svg.put(text); // add it to the supplied container
37
+ this.setCurrentTextStyle(text); // apply active text style
38
+ text.translate(start.x, start.y); // and position it relative to the cursor
39
+ if (isDynamics) {
40
+ svg.add(text.getOutline().attr(Markup_1.MarkupApp.props.text.edit.textBox).addClass(Markup_1.MarkupApp.textOutlineClass)); // in dynamics, draw the box around the text
41
+ }
42
+ else {
43
+ await new EditTextTool(text, true).run(); // text is now positioned, open text editor
44
+ }
45
+ }
46
+ async onResetButtonUp(_ev) {
47
+ await this.exitTool();
48
+ return core_frontend_1.EventHandled.Yes;
49
+ }
50
+ }
51
+ PlaceTextTool.toolId = "Markup.Text.Place";
52
+ PlaceTextTool.iconSpec = "icon-text-medium";
53
+ exports.PlaceTextTool = PlaceTextTool;
54
+ /** Tool for editing text. Started automatically by the place text tool and by clicking on text from the SelectTool
55
+ * @public
56
+ */
57
+ class EditTextTool extends MarkupTool_1.MarkupTool {
58
+ constructor(text, _fromPlaceTool = false) {
59
+ super();
60
+ this.text = text;
61
+ this._fromPlaceTool = _fromPlaceTool;
62
+ }
63
+ showPrompt() {
64
+ const mainInstruction = core_frontend_1.ToolAssistance.createInstruction(this.iconSpec, core_frontend_1.IModelApp.localization.getLocalizedString(`${MarkupTool_1.MarkupTool.toolKey}Text.Edit.Prompts.FirstPoint`));
65
+ const mouseInstructions = [];
66
+ const touchInstructions = [];
67
+ const acceptMsg = core_frontend_1.CoreTools.translate("ElementSet.Inputs.Accept");
68
+ const rejectMsg = core_frontend_1.CoreTools.translate("ElementSet.Inputs.Exit");
69
+ touchInstructions.push(core_frontend_1.ToolAssistance.createInstruction(core_frontend_1.ToolAssistanceImage.OneTouchTap, acceptMsg, false, core_frontend_1.ToolAssistanceInputMethod.Touch));
70
+ mouseInstructions.push(core_frontend_1.ToolAssistance.createInstruction(core_frontend_1.ToolAssistanceImage.LeftClick, acceptMsg, false, core_frontend_1.ToolAssistanceInputMethod.Mouse));
71
+ touchInstructions.push(core_frontend_1.ToolAssistance.createInstruction(core_frontend_1.ToolAssistanceImage.TwoTouchTap, rejectMsg, false, core_frontend_1.ToolAssistanceInputMethod.Touch));
72
+ mouseInstructions.push(core_frontend_1.ToolAssistance.createInstruction(core_frontend_1.ToolAssistanceImage.RightClick, rejectMsg, false, core_frontend_1.ToolAssistanceInputMethod.Mouse));
73
+ const sections = [];
74
+ sections.push(core_frontend_1.ToolAssistance.createSection(mouseInstructions, core_frontend_1.ToolAssistance.inputsLabel));
75
+ sections.push(core_frontend_1.ToolAssistance.createSection(touchInstructions, core_frontend_1.ToolAssistance.inputsLabel));
76
+ const instructions = core_frontend_1.ToolAssistance.createInstructions(mainInstruction, sections);
77
+ core_frontend_1.IModelApp.notifications.setToolAssistance(instructions);
78
+ }
79
+ /** Open the text editor */
80
+ startEditor() {
81
+ let text = this.text;
82
+ if (text === undefined)
83
+ return;
84
+ if (text instanceof svg_js_1.G) {
85
+ this.boxed = text;
86
+ text = text.children()[1];
87
+ if (!(text instanceof svg_js_1.Text))
88
+ return;
89
+ this.text = text;
90
+ }
91
+ const markupDiv = this.markup.markupDiv;
92
+ const editDiv = this.editDiv = document.createElement("div"); // create a new DIV to hold the text editor
93
+ const editProps = Markup_1.MarkupApp.props.text.edit;
94
+ let style = editDiv.style;
95
+ style.backgroundColor = editProps.background;
96
+ style.top = style.left = "0";
97
+ style.right = style.bottom = "100%";
98
+ markupDiv.appendChild(editDiv); // add textEditor div to markup div
99
+ const divRect = markupDiv.getBoundingClientRect();
100
+ const outline = text.getOutline(); // use the outline rather than the text in case it's blank.
101
+ text.after(outline); // we have to add it to the DOM or the rbox call doesn't work.
102
+ const rbox = outline.rbox();
103
+ const bbox = outline.bbox();
104
+ outline.remove(); // take it out again.
105
+ const editor = this.editor = document.createElement("textarea");
106
+ editDiv.appendChild(editor);
107
+ editor.className = Markup_1.MarkupApp.textEditorClass;
108
+ editor.contentEditable = "true";
109
+ editor.spellcheck = true;
110
+ editor.wrap = "off";
111
+ // so we don't send these events to the ToolAdmin and process them by tools. We want default handling
112
+ const mouseListener = (ev) => (ev.stopPropagation(), true);
113
+ editor.onselectstart = editor.oncontextmenu = editor.onmousedown = editor.onmouseup = mouseListener; // enable default handling for these events
114
+ // Tab, Escape, ctrl-enter, or shift-enter all end the editor
115
+ editor.onkeydown = async (ev) => {
116
+ if (ev.key === "Tab" || ev.key === "Escape" || (ev.key === "Enter" && (ev.shiftKey || ev.ctrlKey)))
117
+ this.exitTool(); // eslint-disable-line @typescript-eslint/no-floating-promises
118
+ ev.stopPropagation();
119
+ };
120
+ const textElStyle = window.getComputedStyle(text.node);
121
+ style = editor.style;
122
+ style.pointerEvents = "auto";
123
+ style.position = "absolute";
124
+ style.top = `${(rbox.cy - (bbox.h / 2)) - divRect.top}px`; // put the editor over the middle of the text element
125
+ style.left = `${(rbox.cx - (bbox.w / 2)) - divRect.left}px`;
126
+ style.height = editProps.size.height;
127
+ style.width = editProps.size.width;
128
+ style.resize = "both";
129
+ style.fontFamily = textElStyle.fontFamily; // set the font family and anchor to the same as the text element
130
+ style.textAnchor = textElStyle.textAnchor;
131
+ style.fontSize = editProps.fontSize; // from app.props
132
+ const parentZ = parseInt(window.getComputedStyle(markupDiv).zIndex || "0", 10);
133
+ style.zIndex = (parentZ + 200).toString();
134
+ editor.innerHTML = text.getMarkup(); // start with existing text
135
+ this.editor.focus(); // give the editor focus
136
+ // if we're started from the place text tool, select the entire current value, otherwise place the cursor at the end.
137
+ this.editor.setSelectionRange(this._fromPlaceTool ? 0 : editor.value.length, editor.value.length);
138
+ }
139
+ /** Called when EditText exits, saves the edited value into the text element */
140
+ async onCleanup() {
141
+ if (!this.editDiv)
142
+ return;
143
+ const text = this.text;
144
+ const original = this.boxed ? this.boxed : text;
145
+ const undo = this.markup.undo;
146
+ undo.performOperation(this.keyin, () => {
147
+ const newVal = this.editor.value;
148
+ if (newVal.trim() === "") { // if the result of the editing is blank, just delete the text element
149
+ if (!this._fromPlaceTool)
150
+ undo.onDelete(original);
151
+ original.remove(); // must do this *after* we call undo.onDelete
152
+ return;
153
+ }
154
+ let newText = text.clone();
155
+ const fontSize = text.getFontSize();
156
+ newText.createMarkup(newVal, fontSize);
157
+ if (this.boxed) {
158
+ newText = this.createBoxedText(original.parent(), newText);
159
+ newText.matrix(original.matrix());
160
+ }
161
+ original.replace(newText);
162
+ if (this._fromPlaceTool)
163
+ undo.onAdded(newText);
164
+ else
165
+ undo.onModified(newText, original);
166
+ });
167
+ const editSize = Markup_1.MarkupApp.props.text.edit.size;
168
+ const style = this.editor.style;
169
+ editSize.height = style.height;
170
+ editSize.width = style.width;
171
+ this.editDiv.remove();
172
+ this.editDiv = undefined;
173
+ this.editor = undefined;
174
+ }
175
+ async onInstall() {
176
+ if (!await super.onInstall())
177
+ return false;
178
+ this.startEditor();
179
+ return true;
180
+ }
181
+ async onResetButtonUp(_ev) {
182
+ await this.exitTool();
183
+ return core_frontend_1.EventHandled.Yes;
184
+ }
185
+ async onDataButtonUp(_ev) {
186
+ await this.exitTool();
187
+ return core_frontend_1.EventHandled.Yes;
188
+ }
189
+ async onMouseStartDrag(_ev) {
190
+ await this.exitTool();
191
+ return core_frontend_1.EventHandled.Yes;
192
+ }
193
+ }
194
+ EditTextTool.toolId = "Markup.Text.Edit";
195
+ EditTextTool.iconSpec = "icon-text-medium";
196
+ exports.EditTextTool = EditTextTool;
197
197
  //# sourceMappingURL=TextEdit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TextEdit.js","sourceRoot":"","sources":["../../src/TextEdit.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAG8B;AAC9B,6CAAyD;AACzD,qCAAqC;AACrC,6CAA0C;AAC1C,+CAA4C;AAE5C,qBAAqB;AAErB;;GAEG;AACH,MAAa,aAAc,SAAQ,yBAAW;IAA9C;;QAGqB,qBAAgB,GAAG,CAAC,CAAC;QACrB,eAAU,GAAG,CAAC,CAAC;IA4BpC,CAAC;IAzBiB,KAAK,CAAC,aAAa;QACjC,IAAI,CAAC,MAAM,GAAG,kBAAS,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,4FAA4F;QAC3I,OAAO,KAAK,CAAC,aAAa,EAAE,CAAC;IAC/B,CAAC;IAEkB,UAAU,KAAW,IAAI,CAAC,qBAAqB,CAAC,GAAG,uBAAU,CAAC,OAAO,+BAA+B,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAE9G,KAAK,CAAC,YAAY,CAAC,GAAM,EAAE,EAAiB,EAAE,UAAmB;QAClF,IAAI,UAAU,IAAI,2BAAW,CAAC,KAAK,KAAK,EAAE,CAAC,WAAW;YACpD,OAAO;QACT,MAAM,KAAK,GAAG,kBAAS,CAAC,aAAa,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,wCAAwC;QAC7F,MAAM,IAAI,GAAG,IAAI,aAAU,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,8BAA8B;QAChF,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,mCAAmC;QAClD,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,0BAA0B;QAC1D,IAAI,CAAC,SAAS,CAAC,K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QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAC7B,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;IAEe,KAAK,CAAC,SAAS;QAC7B,IAAI,CAAC,MAAM,KAAK,CAAC,SAAS,EAAE;YAC1B,OAAO,KAAK,CAAC;QACf,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,eAAe,CAAC,GAAkB;QACtD,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtB,OAAO,4BAAY,CAAC,GAAG,CAAC;IAC1B,CAAC;IAEe,KAAK,CAAC,cAAc,CAAC,GAAkB;QACrD,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtB,OAAO,4BAAY,CAAC,GAAG,CAAC;IAC1B,CAAC;IAEe,KAAK,CAAC,gBAAgB,CAAC,GAAkB;QACvD,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtB,OAAO,4BAAY,CAAC,GAAG,CAAC;IAC1B,CAAC;;AA9JH,oCA+JC;AA9JwB,mBAAM,GAAG,kBAAkB,CAAC;AAC5B,qBAAQ,GAAG,kBAAkB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module MarkupTools\r\n */\r\n\r\nimport {\r\n BeButtonEvent, CoreTools, EventHandled, IModelApp, InputSource, ToolAssistance, ToolAssistanceImage, ToolAssistanceInputMethod,\r\n ToolAssistanceInstruction, ToolAssistanceSection,\r\n} from \"@itwin/core-frontend\";\r\nimport { G, Text as MarkupText } from \"@svgdotjs/svg.js\";\r\nimport { MarkupApp } from \"./Markup\";\r\nimport { MarkupTool } from \"./MarkupTool\";\r\nimport { RedlineTool } from \"./RedlineTool\";\r\n\r\n// cspell:ignore rbox\r\n\r\n/** Tool to place new text notes on a Markup.\r\n * @public\r\n */\r\nexport class PlaceTextTool extends RedlineTool {\r\n public static override toolId = \"Markup.Text.Place\";\r\n public static override iconSpec = \"icon-text-medium\";\r\n protected override _nRequiredPoints = 1;\r\n protected override _minPoints = 0;\r\n protected _value!: string;\r\n\r\n public override async onPostInstall() {\r\n this._value = MarkupApp.props.text.startValue; // so applications can put a default string (e.g. user's initials) in the note. Can be empty\r\n return super.onPostInstall();\r\n }\r\n\r\n protected override showPrompt(): void { this.provideToolAssistance(`${MarkupTool.toolKey}Text.Place.Prompts.FirstPoint`, true); }\r\n\r\n protected override async createMarkup(svg: G, ev: BeButtonEvent, isDynamics: boolean): Promise<void> {\r\n if (isDynamics && InputSource.Touch === ev.inputSource)\r\n return;\r\n const start = MarkupApp.convertVpToVb(ev.viewPoint); // starting point in viewbox coordinates\r\n const text = new MarkupText().plain(this._value); // create a plain text element\r\n svg.put(text); // add it to the supplied container\r\n this.setCurrentTextStyle(text); // apply active text style\r\n text.translate(start.x, start.y); // and position it relative to the cursor\r\n if (isDynamics) {\r\n svg.add(text.getOutline().attr(MarkupApp.props.text.edit.textBox).addClass(MarkupApp.textOutlineClass)); // in dynamics, draw the box around the text\r\n } else {\r\n await new EditTextTool(text, true).run(); // text is now positioned, open text editor\r\n }\r\n }\r\n public override async onResetButtonUp(_ev: BeButtonEvent): Promise<EventHandled> {\r\n await this.exitTool();\r\n return EventHandled.Yes;\r\n }\r\n}\r\n\r\n/** Tool for editing text. Started automatically by the place text tool and by clicking on text from the SelectTool\r\n * @public\r\n */\r\nexport class EditTextTool extends MarkupTool {\r\n public static override toolId = \"Markup.Text.Edit\";\r\n public static override iconSpec = \"icon-text-medium\";\r\n public editor?: HTMLTextAreaElement;\r\n public editDiv?: HTMLDivElement;\r\n public boxed?: G;\r\n constructor(public text?: MarkupText | G, private _fromPlaceTool = false) { super(); }\r\n\r\n protected override showPrompt(): void {\r\n const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, IModelApp.localization.getLocalizedString(`${MarkupTool.toolKey}Text.Edit.Prompts.FirstPoint`));\r\n const mouseInstructions: ToolAssistanceInstruction[] = [];\r\n const touchInstructions: ToolAssistanceInstruction[] = [];\r\n\r\n const acceptMsg = CoreTools.translate(\"ElementSet.Inputs.Accept\");\r\n const rejectMsg = CoreTools.translate(\"ElementSet.Inputs.Exit\");\r\n touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, acceptMsg, false, ToolAssistanceInputMethod.Touch));\r\n mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, acceptMsg, false, ToolAssistanceInputMethod.Mouse));\r\n touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, rejectMsg, false, ToolAssistanceInputMethod.Touch));\r\n mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, rejectMsg, false, ToolAssistanceInputMethod.Mouse));\r\n\r\n const sections: ToolAssistanceSection[] = [];\r\n sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));\r\n sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));\r\n\r\n const instructions = ToolAssistance.createInstructions(mainInstruction, sections);\r\n IModelApp.notifications.setToolAssistance(instructions);\r\n }\r\n\r\n /** Open the text editor */\r\n public startEditor() {\r\n let text = this.text;\r\n if (text === undefined)\r\n return;\r\n\r\n if (text instanceof G) {\r\n this.boxed = text;\r\n text = text.children()[1] as MarkupText;\r\n if (!(text instanceof MarkupText))\r\n return;\r\n this.text = text;\r\n }\r\n const markupDiv = this.markup.markupDiv;\r\n const editDiv = this.editDiv = document.createElement(\"div\"); // create a new DIV to hold the text editor\r\n const editProps = MarkupApp.props.text.edit;\r\n let style = editDiv.style;\r\n style.backgroundColor = editProps.background;\r\n style.top = style.left = \"0\";\r\n style.right = style.bottom = \"100%\";\r\n\r\n markupDiv.appendChild(editDiv); // add textEditor div to markup div\r\n\r\n const divRect = markupDiv.getBoundingClientRect();\r\n const outline = text.getOutline(); // use the outline rather than the text in case it's blank.\r\n text.after(outline); // we have to add it to the DOM or the rbox call doesn't work.\r\n const rbox = outline.rbox();\r\n const bbox = outline.bbox();\r\n outline.remove(); // take it out again.\r\n const editor = this.editor = document.createElement(\"textarea\");\r\n editDiv.appendChild(editor);\r\n editor.className = MarkupApp.textEditorClass;\r\n editor.contentEditable = \"true\";\r\n editor.spellcheck = true;\r\n editor.wrap = \"off\";\r\n // so we don't send these events to the ToolAdmin and process them by tools. We want default handling\r\n const mouseListener = (ev: Event) => (ev.stopPropagation(), true);\r\n (editor as any).onselectstart = editor.oncontextmenu = editor.onmousedown = editor.onmouseup = mouseListener; // enable default handling for these events\r\n\r\n // Tab, Escape, ctrl-enter, or shift-enter all end the editor\r\n editor.onkeydown = async (ev: KeyboardEvent) => {\r\n if (ev.key === \"Tab\" || ev.key === \"Escape\" || (ev.key === \"Enter\" && (ev.shiftKey || ev.ctrlKey)))\r\n this.exitTool(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n ev.stopPropagation();\r\n\r\n };\r\n const textElStyle = window.getComputedStyle(text.node);\r\n\r\n style = editor.style;\r\n style.pointerEvents = \"auto\";\r\n style.position = \"absolute\";\r\n style.top = `${(rbox.cy - (bbox.h / 2)) - divRect.top}px`; // put the editor over the middle of the text element\r\n style.left = `${(rbox.cx - (bbox.w / 2)) - divRect.left}px`;\r\n style.height = editProps.size.height;\r\n style.width = editProps.size.width;\r\n style.resize = \"both\";\r\n style.fontFamily = textElStyle.fontFamily; // set the font family and anchor to the same as the text element\r\n style.textAnchor = textElStyle.textAnchor;\r\n style.fontSize = editProps.fontSize; // from app.props\r\n\r\n const parentZ = parseInt(window.getComputedStyle(markupDiv).zIndex || \"0\", 10);\r\n style.zIndex = (parentZ + 200).toString();\r\n\r\n editor.innerHTML = text.getMarkup(); // start with existing text\r\n this.editor.focus(); // give the editor focus\r\n\r\n // if we're started from the place text tool, select the entire current value, otherwise place the cursor at the end.\r\n this.editor.setSelectionRange(this._fromPlaceTool ? 0 : editor.value.length, editor.value.length);\r\n }\r\n\r\n /** Called when EditText exits, saves the edited value into the text element */\r\n public override async onCleanup() {\r\n if (!this.editDiv)\r\n return;\r\n\r\n const text = this.text! as MarkupText;\r\n const original = this.boxed ? this.boxed : text;\r\n const undo = this.markup.undo;\r\n undo.performOperation(this.keyin, () => {\r\n const newVal = this.editor!.value;\r\n if (newVal.trim() === \"\") { // if the result of the editing is blank, just delete the text element\r\n if (!this._fromPlaceTool)\r\n undo.onDelete(original);\r\n original.remove(); // must do this *after* we call undo.onDelete\r\n return;\r\n }\r\n\r\n let newText: G | MarkupText = text.clone();\r\n const fontSize = text.getFontSize();\r\n newText.createMarkup(newVal, fontSize);\r\n if (this.boxed) {\r\n newText = this.createBoxedText((original as G).parent() as G, newText);\r\n newText.matrix(original.matrix());\r\n }\r\n original.replace(newText);\r\n if (this._fromPlaceTool)\r\n undo.onAdded(newText);\r\n else\r\n undo.onModified(newText, original);\r\n });\r\n\r\n const editSize = MarkupApp.props.text.edit.size;\r\n const style = this.editor!.style;\r\n editSize.height = style.height;\r\n editSize.width = style.width;\r\n this.editDiv.remove();\r\n this.editDiv = undefined;\r\n this.editor = undefined;\r\n }\r\n\r\n public override async onInstall() {\r\n if (!await super.onInstall())\r\n return false;\r\n this.startEditor();\r\n return true;\r\n }\r\n\r\n public override async onResetButtonUp(_ev: BeButtonEvent): Promise<EventHandled> {\r\n await this.exitTool();\r\n return EventHandled.Yes;\r\n }\r\n\r\n public override async onDataButtonUp(_ev: BeButtonEvent): Promise<EventHandled> {\r\n await this.exitTool();\r\n return EventHandled.Yes;\r\n }\r\n\r\n public override async onMouseStartDrag(_ev: BeButtonEvent): Promise<EventHandled> {\r\n await this.exitTool();\r\n return EventHandled.Yes;\r\n }\r\n}\r\n"]}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AC;QACtB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;IAEe,KAAK,CAAC,SAAS;QAC7B,IAAI,CAAC,MAAM,KAAK,CAAC,SAAS,EAAE;YAC1B,OAAO,KAAK,CAAC;QACf,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,eAAe,CAAC,GAAkB;QACtD,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtB,OAAO,4BAAY,CAAC,GAAG,CAAC;IAC1B,CAAC;IAEe,KAAK,CAAC,cAAc,CAAC,GAAkB;QACrD,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtB,OAAO,4BAAY,CAAC,GAAG,CAAC;IAC1B,CAAC;IAEe,KAAK,CAAC,gBAAgB,CAAC,GAAkB;QACvD,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtB,OAAO,4BAAY,CAAC,GAAG,CAAC;IAC1B,CAAC;;AA7JsB,mBAAM,GAAG,kBAAkB,CAAC;AAC5B,qBAAQ,GAAG,kBAAkB,CAAC;AAF1C,oCAAY","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module MarkupTools\r\n */\r\n\r\nimport {\r\n BeButtonEvent, CoreTools, EventHandled, IModelApp, InputSource, ToolAssistance, ToolAssistanceImage, ToolAssistanceInputMethod,\r\n ToolAssistanceInstruction, ToolAssistanceSection,\r\n} from \"@itwin/core-frontend\";\r\nimport { G, Text as MarkupText } from \"@svgdotjs/svg.js\";\r\nimport { MarkupApp } from \"./Markup\";\r\nimport { MarkupTool } from \"./MarkupTool\";\r\nimport { RedlineTool } from \"./RedlineTool\";\r\n\r\n// cspell:ignore rbox\r\n\r\n/** Tool to place new text notes on a Markup.\r\n * @public\r\n */\r\nexport class PlaceTextTool extends RedlineTool {\r\n public static override toolId = \"Markup.Text.Place\";\r\n public static override iconSpec = \"icon-text-medium\";\r\n protected override _nRequiredPoints = 1;\r\n protected override _minPoints = 0;\r\n protected _value!: string;\r\n\r\n public override async onPostInstall() {\r\n this._value = MarkupApp.props.text.startValue; // so applications can put a default string (e.g. user's initials) in the note. Can be empty\r\n return super.onPostInstall();\r\n }\r\n\r\n protected override showPrompt(): void { this.provideToolAssistance(`${MarkupTool.toolKey}Text.Place.Prompts.FirstPoint`, true); }\r\n\r\n protected override async createMarkup(svg: G, ev: BeButtonEvent, isDynamics: boolean): Promise<void> {\r\n if (isDynamics && InputSource.Touch === ev.inputSource)\r\n return;\r\n const start = MarkupApp.convertVpToVb(ev.viewPoint); // starting point in viewbox coordinates\r\n const text = new MarkupText().plain(this._value); // create a plain text element\r\n svg.put(text); // add it to the supplied container\r\n this.setCurrentTextStyle(text); // apply active text style\r\n text.translate(start.x, start.y); // and position it relative to the cursor\r\n if (isDynamics) {\r\n svg.add(text.getOutline().attr(MarkupApp.props.text.edit.textBox).addClass(MarkupApp.textOutlineClass)); // in dynamics, draw the box around the text\r\n } else {\r\n await new EditTextTool(text, true).run(); // text is now positioned, open text editor\r\n }\r\n }\r\n public override async onResetButtonUp(_ev: BeButtonEvent): Promise<EventHandled> {\r\n await this.exitTool();\r\n return EventHandled.Yes;\r\n }\r\n}\r\n\r\n/** Tool for editing text. Started automatically by the place text tool and by clicking on text from the SelectTool\r\n * @public\r\n */\r\nexport class EditTextTool extends MarkupTool {\r\n public static override toolId = \"Markup.Text.Edit\";\r\n public static override iconSpec = \"icon-text-medium\";\r\n public editor?: HTMLTextAreaElement;\r\n public editDiv?: HTMLDivElement;\r\n public boxed?: G;\r\n constructor(public text?: MarkupText | G, private _fromPlaceTool = false) { super(); }\r\n\r\n protected override showPrompt(): void {\r\n const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, IModelApp.localization.getLocalizedString(`${MarkupTool.toolKey}Text.Edit.Prompts.FirstPoint`));\r\n const mouseInstructions: ToolAssistanceInstruction[] = [];\r\n const touchInstructions: ToolAssistanceInstruction[] = [];\r\n\r\n const acceptMsg = CoreTools.translate(\"ElementSet.Inputs.Accept\");\r\n const rejectMsg = CoreTools.translate(\"ElementSet.Inputs.Exit\");\r\n touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, acceptMsg, false, ToolAssistanceInputMethod.Touch));\r\n mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, acceptMsg, false, ToolAssistanceInputMethod.Mouse));\r\n touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, rejectMsg, false, ToolAssistanceInputMethod.Touch));\r\n mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, rejectMsg, false, ToolAssistanceInputMethod.Mouse));\r\n\r\n const sections: ToolAssistanceSection[] = [];\r\n sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));\r\n sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));\r\n\r\n const instructions = ToolAssistance.createInstructions(mainInstruction, sections);\r\n IModelApp.notifications.setToolAssistance(instructions);\r\n }\r\n\r\n /** Open the text editor */\r\n public startEditor() {\r\n let text = this.text;\r\n if (text === undefined)\r\n return;\r\n\r\n if (text instanceof G) {\r\n this.boxed = text;\r\n text = text.children()[1] as MarkupText;\r\n if (!(text instanceof MarkupText))\r\n return;\r\n this.text = text;\r\n }\r\n const markupDiv = this.markup.markupDiv;\r\n const editDiv = this.editDiv = document.createElement(\"div\"); // create a new DIV to hold the text editor\r\n const editProps = MarkupApp.props.text.edit;\r\n let style = editDiv.style;\r\n style.backgroundColor = editProps.background;\r\n style.top = style.left = \"0\";\r\n style.right = style.bottom = \"100%\";\r\n\r\n markupDiv.appendChild(editDiv); // add textEditor div to markup div\r\n\r\n const divRect = markupDiv.getBoundingClientRect();\r\n const outline = text.getOutline(); // use the outline rather than the text in case it's blank.\r\n text.after(outline); // we have to add it to the DOM or the rbox call doesn't work.\r\n const rbox = outline.rbox();\r\n const bbox = outline.bbox();\r\n outline.remove(); // take it out again.\r\n const editor = this.editor = document.createElement(\"textarea\");\r\n editDiv.appendChild(editor);\r\n editor.className = MarkupApp.textEditorClass;\r\n editor.contentEditable = \"true\";\r\n editor.spellcheck = true;\r\n editor.wrap = \"off\";\r\n // so we don't send these events to the ToolAdmin and process them by tools. We want default handling\r\n const mouseListener = (ev: Event) => (ev.stopPropagation(), true);\r\n (editor as any).onselectstart = editor.oncontextmenu = editor.onmousedown = editor.onmouseup = mouseListener; // enable default handling for these events\r\n\r\n // Tab, Escape, ctrl-enter, or shift-enter all end the editor\r\n editor.onkeydown = async (ev: KeyboardEvent) => {\r\n if (ev.key === \"Tab\" || ev.key === \"Escape\" || (ev.key === \"Enter\" && (ev.shiftKey || ev.ctrlKey)))\r\n this.exitTool(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n ev.stopPropagation();\r\n\r\n };\r\n const textElStyle = window.getComputedStyle(text.node);\r\n\r\n style = editor.style;\r\n style.pointerEvents = \"auto\";\r\n style.position = \"absolute\";\r\n style.top = `${(rbox.cy - (bbox.h / 2)) - divRect.top}px`; // put the editor over the middle of the text element\r\n style.left = `${(rbox.cx - (bbox.w / 2)) - divRect.left}px`;\r\n style.height = editProps.size.height;\r\n style.width = editProps.size.width;\r\n style.resize = \"both\";\r\n style.fontFamily = textElStyle.fontFamily; // set the font family and anchor to the same as the text element\r\n style.textAnchor = textElStyle.textAnchor;\r\n style.fontSize = editProps.fontSize; // from app.props\r\n\r\n const parentZ = parseInt(window.getComputedStyle(markupDiv).zIndex || \"0\", 10);\r\n style.zIndex = (parentZ + 200).toString();\r\n\r\n editor.innerHTML = text.getMarkup(); // start with existing text\r\n this.editor.focus(); // give the editor focus\r\n\r\n // if we're started from the place text tool, select the entire current value, otherwise place the cursor at the end.\r\n this.editor.setSelectionRange(this._fromPlaceTool ? 0 : editor.value.length, editor.value.length);\r\n }\r\n\r\n /** Called when EditText exits, saves the edited value into the text element */\r\n public override async onCleanup() {\r\n if (!this.editDiv)\r\n return;\r\n\r\n const text = this.text! as MarkupText;\r\n const original = this.boxed ? this.boxed : text;\r\n const undo = this.markup.undo;\r\n undo.performOperation(this.keyin, () => {\r\n const newVal = this.editor!.value;\r\n if (newVal.trim() === \"\") { // if the result of the editing is blank, just delete the text element\r\n if (!this._fromPlaceTool)\r\n undo.onDelete(original);\r\n original.remove(); // must do this *after* we call undo.onDelete\r\n return;\r\n }\r\n\r\n let newText: G | MarkupText = text.clone();\r\n const fontSize = text.getFontSize();\r\n newText.createMarkup(newVal, fontSize);\r\n if (this.boxed) {\r\n newText = this.createBoxedText((original as G).parent() as G, newText);\r\n newText.matrix(original.matrix());\r\n }\r\n original.replace(newText);\r\n if (this._fromPlaceTool)\r\n undo.onAdded(newText);\r\n else\r\n undo.onModified(newText, original);\r\n });\r\n\r\n const editSize = MarkupApp.props.text.edit.size;\r\n const style = this.editor!.style;\r\n editSize.height = style.height;\r\n editSize.width = style.width;\r\n this.editDiv.remove();\r\n this.editDiv = undefined;\r\n this.editor = undefined;\r\n }\r\n\r\n public override async onInstall() {\r\n if (!await super.onInstall())\r\n return false;\r\n this.startEditor();\r\n return true;\r\n }\r\n\r\n public override async onResetButtonUp(_ev: BeButtonEvent): Promise<EventHandled> {\r\n await this.exitTool();\r\n return EventHandled.Yes;\r\n }\r\n\r\n public override async onDataButtonUp(_ev: BeButtonEvent): Promise<EventHandled> {\r\n await this.exitTool();\r\n return EventHandled.Yes;\r\n }\r\n\r\n public override async onMouseStartDrag(_ev: BeButtonEvent): Promise<EventHandled> {\r\n await this.exitTool();\r\n return EventHandled.Yes;\r\n }\r\n}\r\n"]}
package/lib/cjs/Undo.d.ts CHANGED
@@ -1,47 +1,47 @@
1
- /** @packageDocumentation
2
- * @module MarkupTools
3
- */
4
- import { Element as MarkupElement } from "@svgdotjs/svg.js";
5
- /** Stores the sequence of operations performed on a Markup. Facilitates undo/redo of the operations.
6
- * @public
7
- */
8
- export declare class UndoManager {
9
- private _currentCmd;
10
- private _grouped;
11
- private _stack;
12
- private _currentPos;
13
- private _cmdName;
14
- private addAction;
15
- /** @internal */
16
- get size(): number;
17
- private startCommand;
18
- private startGroup;
19
- private endGroup;
20
- /** Perform a series of changes to markup elements that should all be reversed as a single operation.
21
- * @param fn the function that performs the changes to the elements. It must call the onXXX methods of this class to store
22
- * the operations in the undo buffer.
23
- * @note all of the onXXX methods of this class should *only* be called from within the callback function of this method.
24
- */
25
- performOperation(cmdName: string, fn: VoidFunction): void;
26
- /** call this from within a [[performOperation]] function *after* an element has been added to a markup */
27
- onAdded(elem: MarkupElement): void;
28
- /** call this from within a [[performOperation]] function *before* an element is about to be deleted from a markup */
29
- onDelete(elem: MarkupElement): void;
30
- /** call this from within a [[performOperation]] function *after* an element has been moved in display order in a markup */
31
- onRepositioned(elem: MarkupElement, oldIndex: number, oldParent: MarkupElement): void;
32
- /** call this from within a [[performOperation]] function *after* an element has been modified in a markup */
33
- onModified(newElem: MarkupElement, oldElem: MarkupElement): void;
34
- /** determine whether there are any un-reversed operations */
35
- get undoPossible(): boolean;
36
- /** determine whether there are any reversed operations */
37
- get redoPossible(): boolean;
38
- /** the name of the operation that can be undone (or undefined) */
39
- get undoString(): string | undefined;
40
- /** the name of the operation that can be redone (or undefined) */
41
- get redoString(): string | undefined;
42
- /** reverse the most recent operation, if any */
43
- doUndo(): void;
44
- /** reinstate the most recently reversed operation, if any */
45
- doRedo(): void;
46
- }
1
+ /** @packageDocumentation
2
+ * @module MarkupTools
3
+ */
4
+ import { Element as MarkupElement } from "@svgdotjs/svg.js";
5
+ /** Stores the sequence of operations performed on a Markup. Facilitates undo/redo of the operations.
6
+ * @public
7
+ */
8
+ export declare class UndoManager {
9
+ private _currentCmd;
10
+ private _grouped;
11
+ private _stack;
12
+ private _currentPos;
13
+ private _cmdName;
14
+ private addAction;
15
+ /** @internal */
16
+ get size(): number;
17
+ private startCommand;
18
+ private startGroup;
19
+ private endGroup;
20
+ /** Perform a series of changes to markup elements that should all be reversed as a single operation.
21
+ * @param fn the function that performs the changes to the elements. It must call the onXXX methods of this class to store
22
+ * the operations in the undo buffer.
23
+ * @note all of the onXXX methods of this class should *only* be called from within the callback function of this method.
24
+ */
25
+ performOperation(cmdName: string, fn: VoidFunction): void;
26
+ /** call this from within a [[performOperation]] function *after* an element has been added to a markup */
27
+ onAdded(elem: MarkupElement): void;
28
+ /** call this from within a [[performOperation]] function *before* an element is about to be deleted from a markup */
29
+ onDelete(elem: MarkupElement): void;
30
+ /** call this from within a [[performOperation]] function *after* an element has been moved in display order in a markup */
31
+ onRepositioned(elem: MarkupElement, oldIndex: number, oldParent: MarkupElement): void;
32
+ /** call this from within a [[performOperation]] function *after* an element has been modified in a markup */
33
+ onModified(newElem: MarkupElement, oldElem: MarkupElement): void;
34
+ /** determine whether there are any un-reversed operations */
35
+ get undoPossible(): boolean;
36
+ /** determine whether there are any reversed operations */
37
+ get redoPossible(): boolean;
38
+ /** the name of the operation that can be undone (or undefined) */
39
+ get undoString(): string | undefined;
40
+ /** the name of the operation that can be redone (or undefined) */
41
+ get redoString(): string | undefined;
42
+ /** reverse the most recent operation, if any */
43
+ doUndo(): void;
44
+ /** reinstate the most recently reversed operation, if any */
45
+ doRedo(): void;
46
+ }
47
47
  //# sourceMappingURL=Undo.d.ts.map