Skip to content

Commit 90fc02c

Browse files
committed
Esbuild & Mentions: Updated interaction stability and build system
- Updated esbuild system to be module, and fixed build command. - Reverted module use in package.json by default as this impacted test runs/files. - Updated mention user select: - To look better in dark mode. - To not remove text after on select. - To properly revert/restore focus on enter or cancel.
1 parent 3d9aba7 commit 90fc02c

File tree

7 files changed

+38
-13
lines changed

7 files changed

+38
-13
lines changed
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as path from 'node:path';
55
import * as fs from 'node:fs';
66
import * as process from "node:process";
77

8-
98
// Check if we're building for production
109
// (Set via passing `production` as first argument)
1110
const mode = process.argv[2];
@@ -76,7 +75,13 @@ if (mode === 'watch') {
7675
});
7776
} else {
7877
// Build with meta output for analysis
79-
ctx.rebuild().then(result => {
80-
fs.writeFileSync('esbuild-meta.json', JSON.stringify(result.metafile));
81-
}).catch(() => process.exit(1));
78+
const result = await ctx.rebuild();
79+
const outputs = result.metafile.outputs;
80+
const files = Object.keys(outputs);
81+
for (const file of files) {
82+
const output = outputs[file];
83+
console.log(`Written: ${file} @ ${Math.round(output.bytes / 1000)}kB`);
84+
}
85+
fs.writeFileSync('esbuild-meta.json', JSON.stringify(result.metafile));
86+
process.exit(0);
8287
}

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"private": true,
3-
"type": "module",
43
"scripts": {
54
"build:css:dev": "sass ./resources/sass:./public/dist --embed-sources",
65
"build:css:watch": "sass ./resources/sass:./public/dist --watch --embed-sources",
76
"build:css:production": "sass ./resources/sass:./public/dist -s compressed",
8-
"build:js:dev": "node dev/build/esbuild.js",
9-
"build:js:watch": "node dev/build/esbuild.js watch",
10-
"build:js:production": "node dev/build/esbuild.js production",
7+
"build:js:dev": "node dev/build/esbuild.mjs",
8+
"build:js:watch": "node dev/build/esbuild.mjs watch",
9+
"build:js:production": "node dev/build/esbuild.mjs production",
1110
"build": "npm-run-all --parallel build:*:dev",
1211
"production": "npm-run-all --parallel build:*:production",
1312
"dev": "npm-run-all --parallel build:*:watch",

resources/js/wysiwyg/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ export function createCommentEditorInstance(container: HTMLElement, htmlContent:
151151
theme: theme,
152152
});
153153

154-
// TODO - Dedupe this with the basic editor instance
155-
// Changed elements: namespace, registerMentions, toolbar, public event usage, mentioned decorator
156154
const context: EditorUiContext = buildEditorUI(container, editor, options);
157155
editor.setRootElement(context.editorDOM);
158156

resources/js/wysiwyg/services/mentions.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {KEY_AT_COMMAND} from "lexical/LexicalCommands";
66
import {$createMentionNode, $isMentionNode, MentionNode} from "@lexical/link/LexicalMentionNode";
77
import {EditorUiContext} from "../ui/framework/core";
88
import {MentionDecorator} from "../ui/decorators/MentionDecorator";
9+
import {$selectSingleNode} from "../utils/selection";
910

1011

1112
function enterUserSelectMode(context: EditorUiContext, selection: RangeSelection) {
@@ -25,10 +26,13 @@ function enterUserSelectMode(context: EditorUiContext, selection: RangeSelection
2526
}
2627

2728
const split = textNode.splitText(offset);
28-
const newNode = split[atStart ? 0 : 1];
29+
const priorTextNode = split[0];
30+
const afterTextNode = split[atStart ? 0 : 1];
2931

3032
const mention = $createMentionNode(0, '', '');
31-
newNode.replace(mention);
33+
priorTextNode.insertAfter(mention);
34+
afterTextNode.spliceText(0, 1, '', false);
35+
$selectSingleNode(mention);
3236

3337
requestAnimationFrame(() => {
3438
const mentionDecorator = context.manager.getDecoratorByNodeKey(mention.getKey());

resources/js/wysiwyg/ui/decorators/MentionDecorator.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,24 @@ export class MentionDecorator extends EditorDecorator {
170170
this.dropdownContainer?.remove();
171171
this.abortController = null;
172172
this.dropdownContainer = null;
173+
this.context.manager.focus();
173174
}
174175

175176
revertMention() {
176177
this.hideSelection();
177178
this.context.editor.update(() => {
178179
const text = $createTextNode('@');
180+
const before = this.getNode().getPreviousSibling();
179181
this.getNode().replace(text);
180-
text.selectEnd();
182+
requestAnimationFrame(() => {
183+
this.context.editor.update(() => {
184+
if (text.isAttached()) {
185+
text.selectEnd();
186+
} else if (before?.isAttached()) {
187+
before?.selectEnd();
188+
}
189+
});
190+
});
181191
});
182192
}
183193

resources/js/wysiwyg/ui/framework/manager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ export class EditorUIManager {
206206
}
207207
}
208208

209+
/**
210+
* Set the UI focus to the editor.
211+
*/
212+
focus(): void {
213+
this.getContext().editorDOM.focus();
214+
this.getContext().editor.focus();
215+
}
216+
209217
protected updateContextToolbars(update: EditorUiStateUpdate): void {
210218
for (let i = this.activeContextToolbars.length - 1; i >= 0; i--) {
211219
const toolbar = this.activeContextToolbars[i];

resources/sass/_components.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
985985
font-size: 0.8rem;
986986
&:hover,&:focus {
987987
background-color: #F2F2F2;
988+
@include mixins.lightDark(background-color, #F2F2F2, #444);
988989
text-decoration: none;
989990
}
990991
}

0 commit comments

Comments
 (0)