@mlightcad/mtext-input-box 0.1.1 → 0.1.3
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 +78 -7
- package/dist/index.d.ts +1 -1
- package/dist/ui/toolbar.d.ts +6 -2
- package/dist/ui/toolbar.js +95 -13
- package/dist/viewer/index.d.ts +1 -1
- package/dist/viewer/types.d.ts +25 -0
- package/dist/viewer/viewer.d.ts +2 -0
- package/dist/viewer/viewer.js +10 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Three.js Rich Text Editor
|
|
2
2
|
|
|
3
3
|
Three.js-based MTEXT editor component with built-in IME bridge, cursor/selection rendering, and floating toolbar.
|
|
4
4
|
|
|
5
|
+

|
|
6
|
+
|
|
5
7
|
## Purpose
|
|
6
8
|
|
|
7
|
-
- MTEXT-style editing in Three.js
|
|
8
|
-
- Keyboard/mouse/IME editing, selection, formatting, undo/redo
|
|
9
|
-
- Built-in toolbar (theme
|
|
10
|
-
-
|
|
9
|
+
- MTEXT-style editing in Three.js
|
|
10
|
+
- Keyboard/mouse/IME editing, selection, formatting, and undo/redo
|
|
11
|
+
- Built-in toolbar (configurable theme, font list, container, and offset)
|
|
12
|
+
- Integration with `@mlightcad/mtext-renderer` and `@mlightcad/text-box-cursor`
|
|
13
|
+
|
|
14
|
+
## Technical Details
|
|
15
|
+
|
|
16
|
+
- Medium article: [Building a Three.js Rich Text Editor](https://medium.com/@mlightcad/building-a-three-js-rich-text-editor-b7283126ee97)
|
|
17
|
+
|
|
18
|
+

|
|
11
19
|
|
|
12
20
|
## Install
|
|
13
21
|
|
|
@@ -66,16 +74,79 @@ Notes:
|
|
|
66
74
|
|
|
67
75
|
## Toolbar
|
|
68
76
|
|
|
69
|
-
The built-in toolbar is a DOM overlay mounted above the active editor and updated automatically when camera
|
|
77
|
+
The built-in toolbar is a DOM overlay mounted above the active editor and updated automatically when the camera or viewport changes.
|
|
70
78
|
|
|
71
79
|
`toolbar` options:
|
|
72
80
|
|
|
73
81
|
- `enabled?: boolean` (default `true`)
|
|
74
82
|
- `theme?: 'light' | 'dark'` (default `dark`)
|
|
75
83
|
- `fontFamilies?: string[]` (default `['Arial', 'Helvetica', 'Verdana', 'Tahoma', 'Trebuchet MS', 'Times New Roman', 'Georgia', 'Courier New', 'system-ui', 'sans-serif', 'serif', 'monospace']`)
|
|
84
|
+
- `colorPicker?: (context) => { setValue?, setTheme?, dispose? }` (optional custom picker factory)
|
|
76
85
|
- `container?: HTMLElement` (default `document.body`)
|
|
77
86
|
- `offsetY?: number` (default `10`)
|
|
78
87
|
|
|
88
|
+
Custom color picker factory context:
|
|
89
|
+
|
|
90
|
+
- `container: HTMLElement`: mount point for your UI.
|
|
91
|
+
- `theme: 'light' | 'dark'`: current toolbar theme.
|
|
92
|
+
- `initialColor: '#RRGGBB'`: initial color.
|
|
93
|
+
- `onChange(hexColor)`: call this when user picks a new color.
|
|
94
|
+
|
|
95
|
+
Custom color picker instance methods:
|
|
96
|
+
|
|
97
|
+
- `setValue(color: MTextColor)`: sync when editor format changes (color may be ACI or RGB).
|
|
98
|
+
- `setTheme(theme)`: optional hook for theme changes.
|
|
99
|
+
- `dispose()`: cleanup any mounted resources.
|
|
100
|
+
|
|
101
|
+
Example (mount a Vue color picker):
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { createApp, h, ref } from 'vue';
|
|
105
|
+
import { getColorByIndex } from '@mlightcad/mtext-renderer';
|
|
106
|
+
import { MTextColor } from '@mlightcad/mtext-parser';
|
|
107
|
+
|
|
108
|
+
toolbar: {
|
|
109
|
+
colorPicker: ({ container, initialColor, theme, onChange }) => {
|
|
110
|
+
const color = ref(initialColor);
|
|
111
|
+
const toHex = (value: MTextColor) => {
|
|
112
|
+
if (value.isRgb && value.rgbValue !== null) {
|
|
113
|
+
return `#${value.rgbValue.toString(16).padStart(6, '0')}`;
|
|
114
|
+
}
|
|
115
|
+
if (value.isAci && value.aci !== null) {
|
|
116
|
+
return `#${getColorByIndex(value.aci).toString(16).padStart(6, '0')}`;
|
|
117
|
+
}
|
|
118
|
+
return '#ffffff';
|
|
119
|
+
};
|
|
120
|
+
const app = createApp({
|
|
121
|
+
render() {
|
|
122
|
+
return h(MyVueColorPicker, {
|
|
123
|
+
modelValue: color.value,
|
|
124
|
+
theme,
|
|
125
|
+
'onUpdate:modelValue': (next: string) => {
|
|
126
|
+
color.value = next;
|
|
127
|
+
onChange(next);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
app.mount(container);
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
setValue(next: MTextColor) {
|
|
137
|
+
color.value = toHex(next);
|
|
138
|
+
},
|
|
139
|
+
setTheme(nextTheme: 'light' | 'dark') {
|
|
140
|
+
// Optional: forward theme into your picker state if needed.
|
|
141
|
+
},
|
|
142
|
+
dispose() {
|
|
143
|
+
app.unmount();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
79
150
|
Public toolbar-related methods:
|
|
80
151
|
|
|
81
152
|
- `setToolbarTheme('light' | 'dark')`
|
|
@@ -99,7 +170,7 @@ Public toolbar-related methods:
|
|
|
99
170
|
- `boundingBoxStyle?: { color?, opacity?, padding?, zOffset? }`: boundary style overrides.
|
|
100
171
|
- `workerUrl?: string | URL`: worker URL for renderer initialization.
|
|
101
172
|
- `cursorStyle` / `selectionStyle`: forwarded to cursor renderer.
|
|
102
|
-
- `toolbar`: built-in toolbar options (`enabled`, `theme`, `fontFamilies`, `container`, `offsetY`).
|
|
173
|
+
- `toolbar`: built-in toolbar options (`enabled`, `theme`, `fontFamilies`, `colorPicker`, `container`, `offsetY`).
|
|
103
174
|
|
|
104
175
|
## Input And Interaction
|
|
105
176
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export { MTextInputBox, MTextEditor, defaultCharFormat, sameFormat } from './vie
|
|
|
2
2
|
export { MTextDocument, parseMTextToAst, buildMTextFromAst, insertTextInAst, deleteRangeInAst, replaceRangeInAst } from './model';
|
|
3
3
|
export { EditorUiAdapter } from './controller';
|
|
4
4
|
export { MTextToolbar } from './ui';
|
|
5
|
-
export type { CharFormat, CharScript, CursorDirection, EditorState, LayoutCharBox, CursorLayoutData, MTextBoundingBoxStyle, MTextInputBoxEvent, MTextInputBoxOptions, MTextToolbarOptions, MTextToolbarTheme, MTextEditorEvent, MTextEditorOptions, MTextRendererOutput, SelectionDirection } from './viewer';
|
|
5
|
+
export type { CharFormat, CharScript, CursorDirection, EditorState, LayoutCharBox, CursorLayoutData, MTextBoundingBoxStyle, MTextInputBoxEvent, MTextInputBoxOptions, MTextToolbarColorPickerContext, MTextToolbarColorPickerFactory, MTextToolbarColorPickerInstance, MTextToolbarOptions, MTextToolbarTheme, MTextEditorEvent, MTextEditorOptions, MTextRendererOutput, SelectionDirection } from './viewer';
|
|
6
6
|
export type { MTextScript, MTextStyle, MTextAst, MTextAstNode, EditorSelection } from './model';
|
|
7
7
|
export type { EditorCommand, EditorKeyEventLike } from './controller';
|
package/dist/ui/toolbar.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type { CharFormat, MTextToolbarTheme } from '../viewer/types';
|
|
1
|
+
import type { CharFormat, MTextToolbarColorPickerFactory, MTextToolbarTheme } from '../viewer/types';
|
|
2
2
|
export interface ToolbarOptions {
|
|
3
3
|
anchorElement: HTMLElement;
|
|
4
4
|
container?: HTMLElement;
|
|
5
5
|
theme: MTextToolbarTheme;
|
|
6
6
|
fontFamilies?: string[];
|
|
7
|
+
colorPicker?: MTextToolbarColorPickerFactory;
|
|
7
8
|
onFormatChange: (partial: Partial<CharFormat>) => void;
|
|
8
9
|
onToggleStack: () => void;
|
|
9
10
|
onToggleSuperscript?: () => boolean;
|
|
10
11
|
onToggleSubscript?: () => boolean;
|
|
11
12
|
}
|
|
12
|
-
export type ToolbarSessionOptions = Omit<ToolbarOptions, 'container' | 'theme' | 'fontFamilies'>;
|
|
13
|
+
export type ToolbarSessionOptions = Omit<ToolbarOptions, 'container' | 'theme' | 'fontFamilies' | 'colorPicker'>;
|
|
13
14
|
export declare class MTextToolbar {
|
|
14
15
|
private anchorElement;
|
|
15
16
|
private readonly root;
|
|
@@ -19,6 +20,7 @@ export declare class MTextToolbar {
|
|
|
19
20
|
private onToggleSuperscript;
|
|
20
21
|
private onToggleSubscript;
|
|
21
22
|
private theme;
|
|
23
|
+
private readonly colorPicker;
|
|
22
24
|
constructor(options: ToolbarOptions);
|
|
23
25
|
setTheme(theme: MTextToolbarTheme): void;
|
|
24
26
|
getTheme(): MTextToolbarTheme;
|
|
@@ -31,4 +33,6 @@ export declare class MTextToolbar {
|
|
|
31
33
|
private setToggleState;
|
|
32
34
|
private ensureSelectValue;
|
|
33
35
|
private bindEvents;
|
|
36
|
+
private createColorPicker;
|
|
37
|
+
private applyColorChange;
|
|
34
38
|
}
|
package/dist/ui/toolbar.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getColorByIndex } from '@mlightcad/mtext-renderer';
|
|
2
|
+
import { MTextColor } from '@mlightcad/mtext-parser';
|
|
1
3
|
import { toolbarIcons } from './icons';
|
|
2
4
|
const STYLE_ID = 'mlightcad-mtext-toolbar-style';
|
|
3
5
|
const DEFAULT_FONT_FAMILIES = [
|
|
@@ -147,6 +149,36 @@ function hexToColorNumber(hex) {
|
|
|
147
149
|
return 0xffffff;
|
|
148
150
|
return Number.parseInt(hex.slice(1), 16);
|
|
149
151
|
}
|
|
152
|
+
function mtextColorToHex(color) {
|
|
153
|
+
if (color.isRgb && color.rgbValue !== null) {
|
|
154
|
+
return colorNumberToHex(color.rgbValue);
|
|
155
|
+
}
|
|
156
|
+
if (color.isAci && color.aci !== null) {
|
|
157
|
+
return colorNumberToHex(getColorByIndex(color.aci));
|
|
158
|
+
}
|
|
159
|
+
return '#ffffff';
|
|
160
|
+
}
|
|
161
|
+
function formatToMTextColor(format) {
|
|
162
|
+
const color = new MTextColor();
|
|
163
|
+
if (format.aci !== null && Number.isFinite(format.aci)) {
|
|
164
|
+
color.aci = format.aci;
|
|
165
|
+
return color;
|
|
166
|
+
}
|
|
167
|
+
if (format.rgb !== null) {
|
|
168
|
+
color.rgbValue = normalizeColorNumber(format.rgb);
|
|
169
|
+
return color;
|
|
170
|
+
}
|
|
171
|
+
color.rgbValue = 0xffffff;
|
|
172
|
+
return color;
|
|
173
|
+
}
|
|
174
|
+
function normalizeHexColor(hex) {
|
|
175
|
+
const normalized = hex.trim().toLowerCase();
|
|
176
|
+
if (/^#[0-9a-f]{6}$/.test(normalized))
|
|
177
|
+
return normalized;
|
|
178
|
+
if (/^[0-9a-f]{6}$/.test(normalized))
|
|
179
|
+
return `#${normalized}`;
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
150
182
|
function createIconButton(title, icon) {
|
|
151
183
|
const btn = document.createElement('button');
|
|
152
184
|
btn.type = 'button';
|
|
@@ -179,6 +211,7 @@ export class MTextToolbar {
|
|
|
179
211
|
onToggleSuperscript;
|
|
180
212
|
onToggleSubscript;
|
|
181
213
|
theme;
|
|
214
|
+
colorPicker;
|
|
182
215
|
constructor(options) {
|
|
183
216
|
ensureToolbarStyles();
|
|
184
217
|
this.anchorElement = options.anchorElement;
|
|
@@ -205,10 +238,8 @@ export class MTextToolbar {
|
|
|
205
238
|
fontSize.min = '1';
|
|
206
239
|
fontSize.max = '1024';
|
|
207
240
|
fontSize.step = '1';
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
fontColor.type = 'color';
|
|
211
|
-
typographyGroup.append(fontFamily, fontSize, fontColor);
|
|
241
|
+
this.colorPicker = this.createColorPicker(options.colorPicker);
|
|
242
|
+
typographyGroup.append(fontFamily, fontSize, this.colorPicker.host);
|
|
212
243
|
const separator1 = document.createElement('div');
|
|
213
244
|
separator1.className = 'ml-mtext-toolbar__separator';
|
|
214
245
|
const styleGroup = document.createElement('div');
|
|
@@ -226,7 +257,6 @@ export class MTextToolbar {
|
|
|
226
257
|
this.controls = {
|
|
227
258
|
fontFamily,
|
|
228
259
|
fontSize,
|
|
229
|
-
fontColor,
|
|
230
260
|
boldBtn,
|
|
231
261
|
italicBtn,
|
|
232
262
|
underlineBtn,
|
|
@@ -243,6 +273,7 @@ export class MTextToolbar {
|
|
|
243
273
|
setTheme(theme) {
|
|
244
274
|
this.theme = theme;
|
|
245
275
|
this.root.dataset.theme = theme;
|
|
276
|
+
this.colorPicker.setTheme(theme);
|
|
246
277
|
}
|
|
247
278
|
getTheme() {
|
|
248
279
|
return this.theme;
|
|
@@ -272,8 +303,8 @@ export class MTextToolbar {
|
|
|
272
303
|
setFormat(format) {
|
|
273
304
|
this.ensureSelectValue(format.fontFamily);
|
|
274
305
|
this.controls.fontSize.value = String(Math.max(1, Math.round(format.fontSize)));
|
|
275
|
-
const color = format
|
|
276
|
-
this.
|
|
306
|
+
const color = formatToMTextColor(format);
|
|
307
|
+
this.colorPicker.setValue(color);
|
|
277
308
|
this.setToggleState(this.controls.boldBtn, format.bold);
|
|
278
309
|
this.setToggleState(this.controls.italicBtn, format.italic);
|
|
279
310
|
this.setToggleState(this.controls.underlineBtn, format.underline);
|
|
@@ -283,6 +314,7 @@ export class MTextToolbar {
|
|
|
283
314
|
this.setToggleState(this.controls.subscriptBtn, format.script === 'subscript');
|
|
284
315
|
}
|
|
285
316
|
dispose() {
|
|
317
|
+
this.colorPicker.dispose();
|
|
286
318
|
this.root.remove();
|
|
287
319
|
}
|
|
288
320
|
setStackActive(active) {
|
|
@@ -320,12 +352,6 @@ export class MTextToolbar {
|
|
|
320
352
|
this.anchorElement.focus({ preventScroll: true });
|
|
321
353
|
}
|
|
322
354
|
});
|
|
323
|
-
this.controls.fontColor.addEventListener('input', () => {
|
|
324
|
-
this.onFormatChange({
|
|
325
|
-
aci: null,
|
|
326
|
-
rgb: hexToColorNumber(this.controls.fontColor.value)
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
355
|
this.controls.boldBtn.addEventListener('click', () => {
|
|
330
356
|
this.onFormatChange({ bold: !this.controls.boldBtn.classList.contains('is-active') });
|
|
331
357
|
});
|
|
@@ -360,10 +386,66 @@ export class MTextToolbar {
|
|
|
360
386
|
const target = event.target;
|
|
361
387
|
if (!target)
|
|
362
388
|
return;
|
|
389
|
+
if (target.closest('[data-ml-mtext-toolbar-interactive="true"]'))
|
|
390
|
+
return;
|
|
363
391
|
if (target.tagName === 'INPUT' || target.tagName === 'SELECT' || target.tagName === 'OPTION')
|
|
364
392
|
return;
|
|
365
393
|
event.preventDefault();
|
|
366
394
|
this.anchorElement.focus({ preventScroll: true });
|
|
367
395
|
});
|
|
368
396
|
}
|
|
397
|
+
createColorPicker(factory) {
|
|
398
|
+
if (!factory) {
|
|
399
|
+
const input = document.createElement('input');
|
|
400
|
+
input.className = 'ml-mtext-toolbar__color';
|
|
401
|
+
input.type = 'color';
|
|
402
|
+
input.dataset.mlMtextToolbarInteractive = 'true';
|
|
403
|
+
input.addEventListener('input', () => {
|
|
404
|
+
this.applyColorChange(input.value);
|
|
405
|
+
});
|
|
406
|
+
return {
|
|
407
|
+
host: input,
|
|
408
|
+
setValue: (color) => {
|
|
409
|
+
const normalized = normalizeHexColor(mtextColorToHex(color));
|
|
410
|
+
if (normalized)
|
|
411
|
+
input.value = normalized;
|
|
412
|
+
},
|
|
413
|
+
setTheme: () => { },
|
|
414
|
+
dispose: () => { }
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
const host = document.createElement('div');
|
|
418
|
+
host.className = 'ml-mtext-toolbar__color';
|
|
419
|
+
host.dataset.mlMtextToolbarInteractive = 'true';
|
|
420
|
+
const instance = factory({
|
|
421
|
+
container: host,
|
|
422
|
+
theme: this.theme,
|
|
423
|
+
initialColor: '#ffffff',
|
|
424
|
+
onChange: (hex) => {
|
|
425
|
+
this.applyColorChange(hex);
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
const typed = (instance ?? {});
|
|
429
|
+
return {
|
|
430
|
+
host,
|
|
431
|
+
setValue: (color) => {
|
|
432
|
+
typed.setValue?.(color);
|
|
433
|
+
},
|
|
434
|
+
setTheme: (theme) => {
|
|
435
|
+
typed.setTheme?.(theme);
|
|
436
|
+
},
|
|
437
|
+
dispose: () => {
|
|
438
|
+
typed.dispose?.();
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
applyColorChange(hex) {
|
|
443
|
+
const normalized = normalizeHexColor(hex);
|
|
444
|
+
if (!normalized)
|
|
445
|
+
return;
|
|
446
|
+
this.onFormatChange({
|
|
447
|
+
aci: null,
|
|
448
|
+
rgb: hexToColorNumber(normalized)
|
|
449
|
+
});
|
|
450
|
+
}
|
|
369
451
|
}
|
package/dist/viewer/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { MTextInputBox, MTextEditor, defaultCharFormat, sameFormat } from './viewer';
|
|
2
|
-
export type { CharFormat, CharScript, EditorState, LayoutCharBox, RendererContainerBox, RendererLineInfo, MTextRendererOutput, CursorLayoutData, MTextBoundingBoxStyle, MTextInputBoxOptions, MTextToolbarOptions, MTextToolbarTheme, CursorDirection, SelectionDirection, MTextInputBoxEvent, MTextEditorEvent, MTextEditorOptions } from './types';
|
|
2
|
+
export type { CharFormat, CharScript, EditorState, LayoutCharBox, RendererContainerBox, RendererLineInfo, MTextRendererOutput, CursorLayoutData, MTextBoundingBoxStyle, MTextInputBoxOptions, MTextToolbarColorPickerContext, MTextToolbarColorPickerFactory, MTextToolbarColorPickerInstance, MTextToolbarOptions, MTextToolbarTheme, CursorDirection, SelectionDirection, MTextInputBoxEvent, MTextEditorEvent, MTextEditorOptions } from './types';
|
package/dist/viewer/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Box, CursorStyle, SelectionStyle } from '@mlightcad/text-box-cursor';
|
|
2
|
+
import type { MTextColor } from '@mlightcad/mtext-parser';
|
|
2
3
|
import type * as THREE from 'three';
|
|
3
4
|
/** Vertical script style for a character run. */
|
|
4
5
|
export type CharScript = 'normal' | 'superscript' | 'subscript';
|
|
@@ -111,6 +112,28 @@ export interface MTextBoundingBoxStyle {
|
|
|
111
112
|
}
|
|
112
113
|
/** Construction options for `MTextInputBox`. */
|
|
113
114
|
export type MTextToolbarTheme = 'light' | 'dark';
|
|
115
|
+
/** Context passed to custom toolbar color picker factory. */
|
|
116
|
+
export interface MTextToolbarColorPickerContext {
|
|
117
|
+
/** Host element where custom UI should be mounted. */
|
|
118
|
+
container: HTMLElement;
|
|
119
|
+
/** Current toolbar theme. */
|
|
120
|
+
theme: MTextToolbarTheme;
|
|
121
|
+
/** Initial color as hex string (`#RRGGBB`). */
|
|
122
|
+
initialColor: string;
|
|
123
|
+
/** Call when user picks a new color. */
|
|
124
|
+
onChange: (hexColor: string) => void;
|
|
125
|
+
}
|
|
126
|
+
/** Lifecycle hooks for a custom toolbar color picker. */
|
|
127
|
+
export interface MTextToolbarColorPickerInstance {
|
|
128
|
+
/** Sync picker UI when editor format changes (color may be ACI or RGB). */
|
|
129
|
+
setValue?: (color: MTextColor) => void;
|
|
130
|
+
/** Sync picker UI when toolbar theme changes. */
|
|
131
|
+
setTheme?: (theme: MTextToolbarTheme) => void;
|
|
132
|
+
/** Cleanup mounted resources when toolbar is disposed. */
|
|
133
|
+
dispose?: () => void;
|
|
134
|
+
}
|
|
135
|
+
/** Factory used to mount custom toolbar color picker UI (for example a Vue component). */
|
|
136
|
+
export type MTextToolbarColorPickerFactory = (context: MTextToolbarColorPickerContext) => MTextToolbarColorPickerInstance | void;
|
|
114
137
|
/** Toolbar options for built-in editor toolbar UI. */
|
|
115
138
|
export interface MTextToolbarOptions {
|
|
116
139
|
/** Enables the built-in toolbar. Defaults to true. */
|
|
@@ -119,6 +142,8 @@ export interface MTextToolbarOptions {
|
|
|
119
142
|
theme?: MTextToolbarTheme;
|
|
120
143
|
/** Available font family options shown in toolbar dropdown. */
|
|
121
144
|
fontFamilies?: string[];
|
|
145
|
+
/** Custom color picker factory used instead of native `<input type="color">`. */
|
|
146
|
+
colorPicker?: MTextToolbarColorPickerFactory;
|
|
122
147
|
/** Custom DOM container to mount toolbar. Defaults to document.body. */
|
|
123
148
|
container?: HTMLElement;
|
|
124
149
|
/** Vertical offset in pixels above editor top edge. Defaults to 10. */
|
package/dist/viewer/viewer.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class MTextInputBox {
|
|
|
11
11
|
private static sharedToolbar;
|
|
12
12
|
private static sharedToolbarContainer;
|
|
13
13
|
private static sharedToolbarFontFamiliesKey;
|
|
14
|
+
private static sharedToolbarColorPickerFactory;
|
|
14
15
|
private static readonly instances;
|
|
15
16
|
private readonly scene;
|
|
16
17
|
private readonly camera;
|
|
@@ -57,6 +58,7 @@ export declare class MTextInputBox {
|
|
|
57
58
|
private toolbarEnabled;
|
|
58
59
|
private toolbarContainer;
|
|
59
60
|
private toolbarFontFamilies;
|
|
61
|
+
private toolbarColorPicker;
|
|
60
62
|
private readonly onImeKeyDown;
|
|
61
63
|
private readonly onWindowKeyDown;
|
|
62
64
|
private readonly onImeBeforeInput;
|
package/dist/viewer/viewer.js
CHANGED
|
@@ -14,6 +14,7 @@ export class MTextInputBox {
|
|
|
14
14
|
static sharedToolbar = null;
|
|
15
15
|
static sharedToolbarContainer = null;
|
|
16
16
|
static sharedToolbarFontFamiliesKey = '';
|
|
17
|
+
static sharedToolbarColorPickerFactory = null;
|
|
17
18
|
static instances = new Set();
|
|
18
19
|
scene;
|
|
19
20
|
camera;
|
|
@@ -70,6 +71,7 @@ export class MTextInputBox {
|
|
|
70
71
|
toolbarEnabled = true;
|
|
71
72
|
toolbarContainer = null;
|
|
72
73
|
toolbarFontFamilies = null;
|
|
74
|
+
toolbarColorPicker;
|
|
73
75
|
onImeKeyDown = (event) => {
|
|
74
76
|
if (!this.isActiveEditor())
|
|
75
77
|
return;
|
|
@@ -213,6 +215,7 @@ export class MTextInputBox {
|
|
|
213
215
|
this.toolbarEnabled = options.toolbar?.enabled ?? true;
|
|
214
216
|
this.toolbarContainer = options.toolbar?.container ?? null;
|
|
215
217
|
this.toolbarFontFamilies = options.toolbar?.fontFamilies ?? null;
|
|
218
|
+
this.toolbarColorPicker = options.toolbar?.colorPicker;
|
|
216
219
|
this.width = Math.max(1, options.width);
|
|
217
220
|
this.position = options.position?.clone() ?? new THREE.Vector3(0, 0, 0);
|
|
218
221
|
this.enableWordWrap = options.enableWordWrap ?? true;
|
|
@@ -699,6 +702,7 @@ export class MTextInputBox {
|
|
|
699
702
|
MTextInputBox.sharedToolbar = null;
|
|
700
703
|
MTextInputBox.sharedToolbarContainer = null;
|
|
701
704
|
MTextInputBox.sharedToolbarFontFamiliesKey = '';
|
|
705
|
+
MTextInputBox.sharedToolbarColorPickerFactory = null;
|
|
702
706
|
MTextInputBox.activeEditor = null;
|
|
703
707
|
}
|
|
704
708
|
}
|
|
@@ -870,7 +874,8 @@ export class MTextInputBox {
|
|
|
870
874
|
const fontFamiliesKey = this.toolbarFontFamilies?.join('\u0000') ?? '';
|
|
871
875
|
const shouldRecreate = !MTextInputBox.sharedToolbar ||
|
|
872
876
|
MTextInputBox.sharedToolbarContainer !== container ||
|
|
873
|
-
MTextInputBox.sharedToolbarFontFamiliesKey !== fontFamiliesKey
|
|
877
|
+
MTextInputBox.sharedToolbarFontFamiliesKey !== fontFamiliesKey ||
|
|
878
|
+
MTextInputBox.sharedToolbarColorPickerFactory !== (this.toolbarColorPicker ?? null);
|
|
874
879
|
if (shouldRecreate) {
|
|
875
880
|
MTextInputBox.sharedToolbar?.dispose();
|
|
876
881
|
const toolbarOptions = {
|
|
@@ -881,9 +886,13 @@ export class MTextInputBox {
|
|
|
881
886
|
if (this.toolbarFontFamilies) {
|
|
882
887
|
toolbarOptions.fontFamilies = this.toolbarFontFamilies;
|
|
883
888
|
}
|
|
889
|
+
if (this.toolbarColorPicker) {
|
|
890
|
+
toolbarOptions.colorPicker = this.toolbarColorPicker;
|
|
891
|
+
}
|
|
884
892
|
MTextInputBox.sharedToolbar = new MTextToolbar(toolbarOptions);
|
|
885
893
|
MTextInputBox.sharedToolbarContainer = container;
|
|
886
894
|
MTextInputBox.sharedToolbarFontFamiliesKey = fontFamiliesKey;
|
|
895
|
+
MTextInputBox.sharedToolbarColorPickerFactory = this.toolbarColorPicker ?? null;
|
|
887
896
|
}
|
|
888
897
|
const toolbar = MTextInputBox.sharedToolbar;
|
|
889
898
|
if (!toolbar) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/mtext-input-box",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"@mlightcad/text-box-cursor": "0.1.1"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@mlightcad/mtext-parser": "^1.3.
|
|
21
|
-
"@mlightcad/mtext-renderer": "^0.10.
|
|
20
|
+
"@mlightcad/mtext-parser": "^1.3.3",
|
|
21
|
+
"@mlightcad/mtext-renderer": "^0.10.2",
|
|
22
22
|
"three": "^0.172.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|