@lvce-editor/renderer-process 30.63.1 → 30.64.0

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.
@@ -4703,16 +4703,18 @@ const pendingBatches = new Map();
4703
4703
  const state$9 = {
4704
4704
  nextTransactionId: 1
4705
4705
  };
4706
- const queue = (uid, commands) => {
4706
+ const queue = (uid, commands, focusVersion = 0) => {
4707
4707
  const transactionId = state$9.nextTransactionId++;
4708
4708
  pendingBatches.set(transactionId, {
4709
4709
  commands,
4710
4710
  committed: false,
4711
+ focusVersion,
4711
4712
  uid
4712
4713
  });
4713
4714
  return transactionId;
4714
4715
  };
4715
- const take = (uid, transactionId) => {
4716
+ const focusCommands = new Set(['Viewlet.focus', 'Viewlet.focusElementByName', 'Viewlet.focusSelector', 'Viewlet.focusSelectorAfterRender']);
4717
+ const take = (uid, transactionId, focusVersion = 0) => {
4716
4718
  const batch = pendingBatches.get(transactionId);
4717
4719
  if (!batch) {
4718
4720
  throw new Error(`pending viewlet command transaction not found: ${transactionId}`);
@@ -4729,7 +4731,11 @@ const take = (uid, transactionId) => {
4729
4731
  if (!pendingBatch.committed) {
4730
4732
  break;
4731
4733
  }
4732
- commands.push(...pendingBatch.commands);
4734
+ for (const command of pendingBatch.commands) {
4735
+ if (pendingBatch.focusVersion === focusVersion || !focusCommands.has(command[0])) {
4736
+ commands.push(command);
4737
+ }
4738
+ }
4733
4739
  pendingBatches.delete(pendingTransactionId);
4734
4740
  }
4735
4741
  return commands;
@@ -9592,11 +9598,25 @@ const attachWindowEvents = () => {
9592
9598
  const sendMultiple = commands => {
9593
9599
  executeCommands(commands);
9594
9600
  };
9601
+ const queuedFocus = {
9602
+ listening: false,
9603
+ version: 0
9604
+ };
9605
+ const getFocusVersion = () => {
9606
+ if (!queuedFocus.listening) {
9607
+ // One observer for this document's lifetime, without retaining focused elements.
9608
+ document.addEventListener('focusin', () => queuedFocus.version++, {
9609
+ capture: true
9610
+ });
9611
+ queuedFocus.listening = true;
9612
+ }
9613
+ return queuedFocus.version;
9614
+ };
9595
9615
  const queueCommands = (uid, commands) => {
9596
- return queue(uid, commands);
9616
+ return queue(uid, commands, getFocusVersion());
9597
9617
  };
9598
9618
  const commitPending = (uid, transactionId) => {
9599
- executeCommands(take(uid, transactionId));
9619
+ executeCommands(take(uid, transactionId, getFocusVersion()));
9600
9620
  };
9601
9621
  const dispose$4 = id => {
9602
9622
  try {
@@ -12234,7 +12254,7 @@ const flushPendingData = state => {
12234
12254
  terminal
12235
12255
  } = state;
12236
12256
  for (const data of pendingData) {
12237
- terminal.write(data);
12257
+ if (data?.restore) restore(state, data.restore);else terminal.write(data);
12238
12258
  }
12239
12259
  pendingData.length = 0;
12240
12260
  };
@@ -12266,6 +12286,7 @@ const mountTerminal = async (state, uid) => {
12266
12286
  cols,
12267
12287
  rows
12268
12288
  }) => {
12289
+ if (state.restoring) return;
12269
12290
  resize(uid, {
12270
12291
  columns: cols,
12271
12292
  rows
@@ -12273,6 +12294,7 @@ const mountTerminal = async (state, uid) => {
12273
12294
  });
12274
12295
  terminal.open(state.$Viewlet);
12275
12296
  const resizeObserver = new ResizeObserver(() => {
12297
+ if (state.restoring) return;
12276
12298
  fitAddon.fit();
12277
12299
  focusIfConnected(state);
12278
12300
  });
@@ -12298,6 +12320,7 @@ const create = () => {
12298
12320
  pendingData: [],
12299
12321
  pendingFocus: false,
12300
12322
  resizeObserver: undefined,
12323
+ restoring: false,
12301
12324
  terminal: undefined
12302
12325
  };
12303
12326
  };
@@ -12322,6 +12345,35 @@ const write = (state, data) => {
12322
12345
  }
12323
12346
  terminal.write(data);
12324
12347
  };
12348
+ const restore = (state, snapshot) => {
12349
+ if (state.disposed) return;
12350
+ const {
12351
+ columns,
12352
+ data,
12353
+ rows
12354
+ } = snapshot;
12355
+ if (!Number.isSafeInteger(columns) || !Number.isSafeInteger(rows) || columns < 2 || columns > 500 || rows < 1 || rows > 200 || typeof data !== 'string') {
12356
+ throw new Error('Invalid terminal snapshot');
12357
+ }
12358
+ const {
12359
+ terminal
12360
+ } = state;
12361
+ if (!terminal) {
12362
+ state.pendingData.push({
12363
+ restore: snapshot
12364
+ });
12365
+ return;
12366
+ }
12367
+ state.restoring = true;
12368
+ terminal.reset();
12369
+ terminal.resize(columns, rows);
12370
+ terminal.write(data, () => {
12371
+ if (state.disposed) return;
12372
+ state.restoring = false;
12373
+ state.fitAddon.fit();
12374
+ focusIfConnected(state);
12375
+ });
12376
+ };
12325
12377
  const focus = state => {
12326
12378
  object(state);
12327
12379
  const {
@@ -12371,6 +12423,7 @@ const ViewletTerminal2 = {
12371
12423
  dispose,
12372
12424
  focus,
12373
12425
  handleMouseDown,
12426
+ restore,
12374
12427
  setTerminal,
12375
12428
  write
12376
12429
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "30.63.1",
3
+ "version": "30.64.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"