dsh-bash-terminal-ts 0.10.0-rc.1 → 0.10.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.
@@ -7737,51 +7737,45 @@ function MultiShellTerminal(props) {
7737
7737
  async function createSlot(shellId) {
7738
7738
  if (sessionId === void 0 || creatingRef.current) return;
7739
7739
  creatingRef.current = true;
7740
- const placeholderId = `pending-${Date.now()}`;
7740
+ const slotKey = `slot-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
7741
7741
  const newSlot = {
7742
- terminalId: placeholderId,
7742
+ slotKey,
7743
+ terminalId: "",
7743
7744
  shell: shellId,
7744
7745
  phase: "allocating",
7745
7746
  detail: "",
7746
7747
  title: "",
7747
7748
  controller: null
7748
- // will be set after create resolves
7749
7749
  };
7750
7750
  setSlots((prev) => [...prev, newSlot]);
7751
7751
  setActiveIdx(slots.length);
7752
7752
  await new Promise((r) => {
7753
7753
  requestAnimationFrame(() => r());
7754
7754
  });
7755
- const host = hostRefs.current.get(placeholderId);
7755
+ const host = hostRefs.current.get(slotKey);
7756
7756
  if (host === null || host === void 0) {
7757
7757
  creatingRef.current = false;
7758
- setSlots((prev) => prev.filter((s) => s.terminalId !== placeholderId));
7758
+ setSlots((prev) => prev.filter((s) => s.slotKey !== slotKey));
7759
7759
  return;
7760
7760
  }
7761
7761
  const result = await EmbeddedTerminal.create(host, sessionId, shellId, {
7762
7762
  onPhase: (next, reason) => {
7763
7763
  setSlots((prev) => prev.map(
7764
- (s) => s.terminalId === placeholderId ? { ...s, phase: next, detail: reason ?? "" } : s
7764
+ (s) => s.slotKey === slotKey ? { ...s, phase: next, detail: reason ?? "" } : s
7765
7765
  ));
7766
7766
  },
7767
7767
  onTitle: (text) => {
7768
7768
  setSlots((prev) => prev.map(
7769
- (s) => s.terminalId === placeholderId ? { ...s, title: text } : s
7769
+ (s) => s.slotKey === slotKey ? { ...s, title: text } : s
7770
7770
  ));
7771
7771
  }
7772
7772
  });
7773
7773
  if (result instanceof EmbeddedTerminal) {
7774
- const realId = result.id || placeholderId;
7775
7774
  setSlots((prev) => prev.map(
7776
- (s) => s.terminalId === placeholderId ? { ...s, terminalId: realId, controller: result } : s
7775
+ (s) => s.slotKey === slotKey ? { ...s, terminalId: result.id, controller: result } : s
7777
7776
  ));
7778
- const el = hostRefs.current.get(placeholderId);
7779
- if (el !== void 0) {
7780
- hostRefs.current.delete(placeholderId);
7781
- hostRefs.current.set(realId, el);
7782
- }
7783
7777
  } else {
7784
- setSlots((prev) => prev.filter((s) => s.terminalId !== placeholderId));
7778
+ setSlots((prev) => prev.filter((s) => s.slotKey !== slotKey));
7785
7779
  }
7786
7780
  creatingRef.current = false;
7787
7781
  }
@@ -7789,11 +7783,11 @@ function MultiShellTerminal(props) {
7789
7783
  const slot = slots[idx];
7790
7784
  if (slot === void 0) return;
7791
7785
  slot.controller?.dispose();
7792
- if (slot.terminalId !== "" && !slot.terminalId.startsWith("pending-")) {
7786
+ if (slot.terminalId !== "") {
7793
7787
  void closeTerminal(slot.terminalId).catch(() => {
7794
7788
  });
7795
7789
  }
7796
- hostRefs.current.delete(slot.terminalId);
7790
+ hostRefs.current.delete(slot.slotKey);
7797
7791
  setSlots((prev) => {
7798
7792
  const next = prev.filter((_, i) => i !== idx);
7799
7793
  if (activeIdx >= next.length) setActiveIdx(Math.max(0, next.length - 1));
@@ -7854,7 +7848,7 @@ function MultiShellTerminal(props) {
7854
7848
  )
7855
7849
  ]
7856
7850
  },
7857
- slot.terminalId
7851
+ slot.slotKey
7858
7852
  )) }) : null,
7859
7853
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 8, padding: "6px 10px", flex: "none" }, children: [
7860
7854
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -7887,8 +7881,8 @@ function MultiShellTerminal(props) {
7887
7881
  "div",
7888
7882
  {
7889
7883
  ref: (el) => {
7890
- if (el !== null) hostRefs.current.set(slot.terminalId, el);
7891
- else hostRefs.current.delete(slot.terminalId);
7884
+ if (el !== null) hostRefs.current.set(slot.slotKey, el);
7885
+ else hostRefs.current.delete(slot.slotKey);
7892
7886
  },
7893
7887
  style: {
7894
7888
  position: "absolute",
@@ -7898,7 +7892,7 @@ function MultiShellTerminal(props) {
7898
7892
  display: i === activeIdx ? "block" : "none"
7899
7893
  }
7900
7894
  },
7901
- slot.terminalId
7895
+ slot.slotKey
7902
7896
  )) })
7903
7897
  ] });
7904
7898
  }
package/dist/client.js CHANGED
@@ -7742,51 +7742,45 @@ function MultiShellTerminal(props) {
7742
7742
  async function createSlot(shellId) {
7743
7743
  if (sessionId === void 0 || creatingRef.current) return;
7744
7744
  creatingRef.current = true;
7745
- const placeholderId = `pending-${Date.now()}`;
7745
+ const slotKey = `slot-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
7746
7746
  const newSlot = {
7747
- terminalId: placeholderId,
7747
+ slotKey,
7748
+ terminalId: "",
7748
7749
  shell: shellId,
7749
7750
  phase: "allocating",
7750
7751
  detail: "",
7751
7752
  title: "",
7752
7753
  controller: null
7753
- // will be set after create resolves
7754
7754
  };
7755
7755
  setSlots((prev) => [...prev, newSlot]);
7756
7756
  setActiveIdx(slots.length);
7757
7757
  await new Promise((r) => {
7758
7758
  requestAnimationFrame(() => r());
7759
7759
  });
7760
- const host = hostRefs.current.get(placeholderId);
7760
+ const host = hostRefs.current.get(slotKey);
7761
7761
  if (host === null || host === void 0) {
7762
7762
  creatingRef.current = false;
7763
- setSlots((prev) => prev.filter((s) => s.terminalId !== placeholderId));
7763
+ setSlots((prev) => prev.filter((s) => s.slotKey !== slotKey));
7764
7764
  return;
7765
7765
  }
7766
7766
  const result = await EmbeddedTerminal.create(host, sessionId, shellId, {
7767
7767
  onPhase: (next, reason) => {
7768
7768
  setSlots((prev) => prev.map(
7769
- (s) => s.terminalId === placeholderId ? { ...s, phase: next, detail: reason ?? "" } : s
7769
+ (s) => s.slotKey === slotKey ? { ...s, phase: next, detail: reason ?? "" } : s
7770
7770
  ));
7771
7771
  },
7772
7772
  onTitle: (text) => {
7773
7773
  setSlots((prev) => prev.map(
7774
- (s) => s.terminalId === placeholderId ? { ...s, title: text } : s
7774
+ (s) => s.slotKey === slotKey ? { ...s, title: text } : s
7775
7775
  ));
7776
7776
  }
7777
7777
  });
7778
7778
  if (result instanceof EmbeddedTerminal) {
7779
- const realId = result.id || placeholderId;
7780
7779
  setSlots((prev) => prev.map(
7781
- (s) => s.terminalId === placeholderId ? { ...s, terminalId: realId, controller: result } : s
7780
+ (s) => s.slotKey === slotKey ? { ...s, terminalId: result.id, controller: result } : s
7782
7781
  ));
7783
- const el = hostRefs.current.get(placeholderId);
7784
- if (el !== void 0) {
7785
- hostRefs.current.delete(placeholderId);
7786
- hostRefs.current.set(realId, el);
7787
- }
7788
7782
  } else {
7789
- setSlots((prev) => prev.filter((s) => s.terminalId !== placeholderId));
7783
+ setSlots((prev) => prev.filter((s) => s.slotKey !== slotKey));
7790
7784
  }
7791
7785
  creatingRef.current = false;
7792
7786
  }
@@ -7794,11 +7788,11 @@ function MultiShellTerminal(props) {
7794
7788
  const slot = slots[idx];
7795
7789
  if (slot === void 0) return;
7796
7790
  slot.controller?.dispose();
7797
- if (slot.terminalId !== "" && !slot.terminalId.startsWith("pending-")) {
7791
+ if (slot.terminalId !== "") {
7798
7792
  void closeTerminal(slot.terminalId).catch(() => {
7799
7793
  });
7800
7794
  }
7801
- hostRefs.current.delete(slot.terminalId);
7795
+ hostRefs.current.delete(slot.slotKey);
7802
7796
  setSlots((prev) => {
7803
7797
  const next = prev.filter((_, i) => i !== idx);
7804
7798
  if (activeIdx >= next.length) setActiveIdx(Math.max(0, next.length - 1));
@@ -7859,7 +7853,7 @@ function MultiShellTerminal(props) {
7859
7853
  )
7860
7854
  ]
7861
7855
  },
7862
- slot.terminalId
7856
+ slot.slotKey
7863
7857
  )) }) : null,
7864
7858
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 8, padding: "6px 10px", flex: "none" }, children: [
7865
7859
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -7892,8 +7886,8 @@ function MultiShellTerminal(props) {
7892
7886
  "div",
7893
7887
  {
7894
7888
  ref: (el) => {
7895
- if (el !== null) hostRefs.current.set(slot.terminalId, el);
7896
- else hostRefs.current.delete(slot.terminalId);
7889
+ if (el !== null) hostRefs.current.set(slot.slotKey, el);
7890
+ else hostRefs.current.delete(slot.slotKey);
7897
7891
  },
7898
7892
  style: {
7899
7893
  position: "absolute",
@@ -7903,7 +7897,7 @@ function MultiShellTerminal(props) {
7903
7897
  display: i === activeIdx ? "block" : "none"
7904
7898
  }
7905
7899
  },
7906
- slot.terminalId
7900
+ slot.slotKey
7907
7901
  )) })
7908
7902
  ] });
7909
7903
  }
package/dsh.plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "dsh-bash-terminal-ts",
3
3
  "name": "dsh-bash-terminal-ts",
4
- "version": "0.10.0-rc.1",
4
+ "version": "0.10.0",
5
5
  "description": {
6
6
  "en": "One shell tool that runs commands through PowerShell, Git Bash, MSYS2, WSL or Niubash on Windows, plus an embedded terminal for the bottom dock with per-shell activation switches and a default-shell fallback chain.",
7
7
  "zh": "一个 shell 工具,可在 Windows 上通过 PowerShell / Git Bash / MSYS2 / WSL / Niubash 执行命令;另提供底部工作台的内嵌终端,支持按 shell 激活开关与默认 shell 回落链。",
package/lib/client.js CHANGED
@@ -7742,51 +7742,45 @@ function MultiShellTerminal(props) {
7742
7742
  async function createSlot(shellId) {
7743
7743
  if (sessionId === void 0 || creatingRef.current) return;
7744
7744
  creatingRef.current = true;
7745
- const placeholderId = `pending-${Date.now()}`;
7745
+ const slotKey = `slot-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
7746
7746
  const newSlot = {
7747
- terminalId: placeholderId,
7747
+ slotKey,
7748
+ terminalId: "",
7748
7749
  shell: shellId,
7749
7750
  phase: "allocating",
7750
7751
  detail: "",
7751
7752
  title: "",
7752
7753
  controller: null
7753
- // will be set after create resolves
7754
7754
  };
7755
7755
  setSlots((prev) => [...prev, newSlot]);
7756
7756
  setActiveIdx(slots.length);
7757
7757
  await new Promise((r) => {
7758
7758
  requestAnimationFrame(() => r());
7759
7759
  });
7760
- const host = hostRefs.current.get(placeholderId);
7760
+ const host = hostRefs.current.get(slotKey);
7761
7761
  if (host === null || host === void 0) {
7762
7762
  creatingRef.current = false;
7763
- setSlots((prev) => prev.filter((s) => s.terminalId !== placeholderId));
7763
+ setSlots((prev) => prev.filter((s) => s.slotKey !== slotKey));
7764
7764
  return;
7765
7765
  }
7766
7766
  const result = await EmbeddedTerminal.create(host, sessionId, shellId, {
7767
7767
  onPhase: (next, reason) => {
7768
7768
  setSlots((prev) => prev.map(
7769
- (s) => s.terminalId === placeholderId ? { ...s, phase: next, detail: reason ?? "" } : s
7769
+ (s) => s.slotKey === slotKey ? { ...s, phase: next, detail: reason ?? "" } : s
7770
7770
  ));
7771
7771
  },
7772
7772
  onTitle: (text) => {
7773
7773
  setSlots((prev) => prev.map(
7774
- (s) => s.terminalId === placeholderId ? { ...s, title: text } : s
7774
+ (s) => s.slotKey === slotKey ? { ...s, title: text } : s
7775
7775
  ));
7776
7776
  }
7777
7777
  });
7778
7778
  if (result instanceof EmbeddedTerminal) {
7779
- const realId = result.id || placeholderId;
7780
7779
  setSlots((prev) => prev.map(
7781
- (s) => s.terminalId === placeholderId ? { ...s, terminalId: realId, controller: result } : s
7780
+ (s) => s.slotKey === slotKey ? { ...s, terminalId: result.id, controller: result } : s
7782
7781
  ));
7783
- const el = hostRefs.current.get(placeholderId);
7784
- if (el !== void 0) {
7785
- hostRefs.current.delete(placeholderId);
7786
- hostRefs.current.set(realId, el);
7787
- }
7788
7782
  } else {
7789
- setSlots((prev) => prev.filter((s) => s.terminalId !== placeholderId));
7783
+ setSlots((prev) => prev.filter((s) => s.slotKey !== slotKey));
7790
7784
  }
7791
7785
  creatingRef.current = false;
7792
7786
  }
@@ -7794,11 +7788,11 @@ function MultiShellTerminal(props) {
7794
7788
  const slot = slots[idx];
7795
7789
  if (slot === void 0) return;
7796
7790
  slot.controller?.dispose();
7797
- if (slot.terminalId !== "" && !slot.terminalId.startsWith("pending-")) {
7791
+ if (slot.terminalId !== "") {
7798
7792
  void closeTerminal(slot.terminalId).catch(() => {
7799
7793
  });
7800
7794
  }
7801
- hostRefs.current.delete(slot.terminalId);
7795
+ hostRefs.current.delete(slot.slotKey);
7802
7796
  setSlots((prev) => {
7803
7797
  const next = prev.filter((_, i) => i !== idx);
7804
7798
  if (activeIdx >= next.length) setActiveIdx(Math.max(0, next.length - 1));
@@ -7859,7 +7853,7 @@ function MultiShellTerminal(props) {
7859
7853
  )
7860
7854
  ]
7861
7855
  },
7862
- slot.terminalId
7856
+ slot.slotKey
7863
7857
  )) }) : null,
7864
7858
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 8, padding: "6px 10px", flex: "none" }, children: [
7865
7859
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -7892,8 +7886,8 @@ function MultiShellTerminal(props) {
7892
7886
  "div",
7893
7887
  {
7894
7888
  ref: (el) => {
7895
- if (el !== null) hostRefs.current.set(slot.terminalId, el);
7896
- else hostRefs.current.delete(slot.terminalId);
7889
+ if (el !== null) hostRefs.current.set(slot.slotKey, el);
7890
+ else hostRefs.current.delete(slot.slotKey);
7897
7891
  },
7898
7892
  style: {
7899
7893
  position: "absolute",
@@ -7903,7 +7897,7 @@ function MultiShellTerminal(props) {
7903
7897
  display: i === activeIdx ? "block" : "none"
7904
7898
  }
7905
7899
  },
7906
- slot.terminalId
7900
+ slot.slotKey
7907
7901
  )) })
7908
7902
  ] });
7909
7903
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-bash-terminal-ts",
3
- "version": "0.10.0-rc.1",
3
+ "version": "0.10.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "tag": "latest"
@@ -34,6 +34,8 @@ export interface MultiShellTabProps {
34
34
 
35
35
  /** One live terminal slot within the panel. */
36
36
  interface TerminalSlot {
37
+ /** Stable React key — never changes after creation. */
38
+ readonly slotKey: string;
37
39
  readonly terminalId: string;
38
40
  readonly shell: string;
39
41
  phase: EmbeddedPhase;
@@ -92,62 +94,48 @@ export function MultiShellTerminal(props: MultiShellTabProps) {
92
94
  async function createSlot(shellId: string): Promise<void> {
93
95
  if (sessionId === undefined || creatingRef.current) return;
94
96
  creatingRef.current = true;
95
- // Wait for the host div to be rendered for this new slot.
96
- // We use a placeholder id so React can mount the div before the controller attaches.
97
- const placeholderId = `pending-${Date.now()}`;
97
+ const slotKey = `slot-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
98
98
  const newSlot: TerminalSlot = {
99
- terminalId: placeholderId,
99
+ slotKey,
100
+ terminalId: "",
100
101
  shell: shellId,
101
102
  phase: "allocating",
102
103
  detail: "",
103
104
  title: "",
104
- controller: null as unknown as EmbeddedTerminal, // will be set after create resolves
105
+ controller: null as unknown as EmbeddedTerminal,
105
106
  };
106
107
  setSlots((prev) => [...prev, newSlot]);
107
- setActiveIdx(slots.length); // point to the new slot (slots.length is the pre-push index)
108
+ setActiveIdx(slots.length);
108
109
 
109
110
  // Give React a tick to render the div.
110
111
  await new Promise<void>((r) => { requestAnimationFrame(() => r()); });
111
112
 
112
- const host = hostRefs.current.get(placeholderId);
113
+ const host = hostRefs.current.get(slotKey);
113
114
  if (host === null || host === undefined) {
114
115
  creatingRef.current = false;
115
- setSlots((prev) => prev.filter((s) => s.terminalId !== placeholderId));
116
+ setSlots((prev) => prev.filter((s) => s.slotKey !== slotKey));
116
117
  return;
117
118
  }
118
119
 
119
120
  const result = await EmbeddedTerminal.create(host, sessionId, shellId, {
120
121
  onPhase: (next, reason) => {
121
122
  setSlots((prev) => prev.map((s) =>
122
- s.terminalId === placeholderId
123
- ? { ...s, phase: next, detail: reason ?? "" }
124
- : s
123
+ s.slotKey === slotKey ? { ...s, phase: next, detail: reason ?? "" } : s
125
124
  ));
126
125
  },
127
126
  onTitle: (text) => {
128
127
  setSlots((prev) => prev.map((s) =>
129
- s.terminalId === placeholderId ? { ...s, title: text } : s
128
+ s.slotKey === slotKey ? { ...s, title: text } : s
130
129
  ));
131
130
  },
132
131
  });
133
132
 
134
133
  if (result instanceof EmbeddedTerminal) {
135
- // Replace the placeholder id with the real terminalId.
136
- const realId = result.id || placeholderId;
137
134
  setSlots((prev) => prev.map((s) =>
138
- s.terminalId === placeholderId
139
- ? { ...s, terminalId: realId, controller: result }
140
- : s
135
+ s.slotKey === slotKey ? { ...s, terminalId: result.id, controller: result } : s
141
136
  ));
142
- // Re-key the hostRef so the div lookup works on subsequent renders.
143
- const el = hostRefs.current.get(placeholderId);
144
- if (el !== undefined) {
145
- hostRefs.current.delete(placeholderId);
146
- hostRefs.current.set(realId, el);
147
- }
148
137
  } else {
149
- // Allocation failed — remove the slot.
150
- setSlots((prev) => prev.filter((s) => s.terminalId !== placeholderId));
138
+ setSlots((prev) => prev.filter((s) => s.slotKey !== slotKey));
151
139
  }
152
140
  creatingRef.current = false;
153
141
  }
@@ -156,10 +144,10 @@ export function MultiShellTerminal(props: MultiShellTabProps) {
156
144
  const slot = slots[idx];
157
145
  if (slot === undefined) return;
158
146
  slot.controller?.dispose();
159
- if (slot.terminalId !== "" && !slot.terminalId.startsWith("pending-")) {
147
+ if (slot.terminalId !== "") {
160
148
  void closeTerminal(slot.terminalId).catch(() => { /* already gone */ });
161
149
  }
162
- hostRefs.current.delete(slot.terminalId);
150
+ hostRefs.current.delete(slot.slotKey);
163
151
  setSlots((prev) => {
164
152
  const next = prev.filter((_, i) => i !== idx);
165
153
  if (activeIdx >= next.length) setActiveIdx(Math.max(0, next.length - 1));
@@ -187,7 +175,7 @@ export function MultiShellTerminal(props: MultiShellTabProps) {
187
175
  <div className="btSubTabBar" style={{ display: "flex", alignItems: "center", gap: 0, borderBottom: "1px solid var(--dsw-alias-border-l2, #333)", flex: "none" }}>
188
176
  {slots.map((slot, i) => (
189
177
  <div
190
- key={slot.terminalId}
178
+ key={slot.slotKey}
191
179
  className={"btSubTab" + (i === activeIdx ? " btSubTabActive" : "")}
192
180
  style={{
193
181
  display: "flex", alignItems: "center", gap: 4, padding: "4px 10px",
@@ -250,10 +238,10 @@ export function MultiShellTerminal(props: MultiShellTabProps) {
250
238
  <div style={{ position: "relative", flex: 1, minHeight: 0 }}>
251
239
  {slots.map((slot, i) => (
252
240
  <div
253
- key={slot.terminalId}
241
+ key={slot.slotKey}
254
242
  ref={(el) => {
255
- if (el !== null) hostRefs.current.set(slot.terminalId, el);
256
- else hostRefs.current.delete(slot.terminalId);
243
+ if (el !== null) hostRefs.current.set(slot.slotKey, el);
244
+ else hostRefs.current.delete(slot.slotKey);
257
245
  }}
258
246
  style={{
259
247
  position: "absolute", inset: 0,