@zhin.js/adapter-sandbox 1.1.33 → 1.1.35

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/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter-sandbox",
3
- "version": "1.1.33",
4
- "description": "Zhin.js Sandbox adapter for Plugin Runtime (WebSocket /sandbox)",
3
+ "version": "1.1.35",
4
+ "description": "Sandbox adapter: a local chat workspace for the Remote Console, for development and testing without a real platform.",
5
+ "keywords": [
6
+ "zhin.js",
7
+ "sandbox",
8
+ "testing",
9
+ "development"
10
+ ],
11
+ "author": {
12
+ "name": "lc-cn",
13
+ "url": "https://github.com/zhinjs/zhin"
14
+ },
5
15
  "type": "module",
6
16
  "main": "./lib/index.js",
7
17
  "types": "./lib/index.d.ts",
@@ -21,21 +31,6 @@
21
31
  "README.md",
22
32
  "CHANGELOG.md"
23
33
  ],
24
- "keywords": [
25
- "zhin",
26
- "zhin.js",
27
- "bot",
28
- "adapter",
29
- "sandbox",
30
- "test",
31
- "development",
32
- "local"
33
- ],
34
- "author": {
35
- "name": "lc-cn",
36
- "email": "admin@liucl.cn",
37
- "url": "https://github.com/lc-cn"
38
- },
39
34
  "license": "MIT",
40
35
  "repository": {
41
36
  "url": "git+https://github.com/zhinjs/zhin.git",
@@ -44,15 +39,15 @@
44
39
  },
45
40
  "dependencies": {
46
41
  "lucide-react": "^0.525.0",
47
- "@zhin.js/adapter": "1.1.34",
48
- "@zhin.js/client": "1.1.34",
49
- "@zhin.js/console-contract": "1.1.6",
50
- "@zhin.js/core": "1.7.0",
51
- "@zhin.js/feature-kit": "1.1.17",
52
- "@zhin.js/host-http": "1.2.2",
53
- "@zhin.js/im-contract": "1.1.14",
54
- "@zhin.js/logger": "1.1.3",
55
- "@zhin.js/page": "1.1.19"
42
+ "@zhin.js/adapter": "1.3.1",
43
+ "@zhin.js/client": "1.2.1",
44
+ "@zhin.js/console-contract": "1.2.0",
45
+ "@zhin.js/core": "1.9.0",
46
+ "@zhin.js/feature-kit": "1.1.18",
47
+ "@zhin.js/host-http": "1.4.0",
48
+ "@zhin.js/im-contract": "1.2.0",
49
+ "@zhin.js/logger": "1.2.0",
50
+ "@zhin.js/page": "1.1.20"
56
51
  },
57
52
  "devDependencies": {
58
53
  "@types/react": "^19.2.18",
@@ -61,18 +56,18 @@
61
56
  "typescript": "^6.0.3",
62
57
  "vitest": "^4.1.10",
63
58
  "ws": "^8.21.1",
64
- "@zhin.js/pagemanager": "1.1.27",
65
- "@zhin.js/runtime": "1.2.2",
66
- "zhin.js": "1.2.0"
59
+ "@zhin.js/pagemanager": "1.1.29",
60
+ "@zhin.js/runtime": "1.4.0",
61
+ "zhin.js": "1.4.0"
67
62
  },
68
63
  "peerDependencies": {
69
64
  "react": "^19.0.0",
70
- "@zhin.js/adapter": "^1.1.34",
71
- "@zhin.js/console-contract": "^1.1.6",
72
- "@zhin.js/core": "^1.7.0",
73
- "@zhin.js/host-http": "^1.2.2",
74
- "@zhin.js/page": "^1.1.19",
75
- "zhin.js": "^1.2.0"
65
+ "@zhin.js/adapter": "^1.3.1",
66
+ "@zhin.js/console-contract": "^1.2.0",
67
+ "@zhin.js/core": "^1.9.0",
68
+ "@zhin.js/host-http": "^1.4.0",
69
+ "@zhin.js/page": "^1.1.20",
70
+ "zhin.js": "^1.4.0"
76
71
  },
77
72
  "peerDependenciesMeta": {
78
73
  "react": {
@@ -102,7 +97,19 @@
102
97
  "api": "^1.0.0"
103
98
  }
104
99
  ],
105
- "plugins": []
100
+ "plugins": [],
101
+ "metadata": {
102
+ "displayName": "Sandbox Adapter",
103
+ "displayNameI18n": {
104
+ "zh-CN": "沙盒适配器",
105
+ "en": "Sandbox Adapter"
106
+ },
107
+ "descriptionI18n": {
108
+ "zh-CN": "沙盒适配器:为 Remote Console 提供本地会话工作区,用于开发和测试,无需接入真实平台。",
109
+ "en": "Sandbox adapter: a local chat workspace for the Remote Console, for development and testing without a real platform."
110
+ },
111
+ "category": "adapter"
112
+ }
106
113
  },
107
114
  "scripts": {
108
115
  "build": "tsc",
@@ -199,6 +199,55 @@ const RichTextEditor = forwardRef(({ locale = 'zh-CN', placeholder = sandboxText
199
199
  handleChange();
200
200
  }
201
201
  };
202
+ // Quick-command prefill (#1250). An empty composer gets the command; a non-empty draft
203
+ // (text, images, faces, mentions) is never overwritten: the command is inserted at the
204
+ // caret, or at the start when the caret is outside the editor. `insertText` keeps the
205
+ // browser undo stack; the Range fallback dispatches `input` so state stays in sync.
206
+ const setText = (text) => {
207
+ const editor = editorRef.current;
208
+ if (!editor)
209
+ return;
210
+ const draftIsEmpty = (editor.textContent ?? '').trim() === ''
211
+ && editor.querySelector('img, [data-type], [data-url], [contenteditable="false"]') === null;
212
+ const selection = window.getSelection();
213
+ const caretInEditor = !!selection && selection.rangeCount > 0
214
+ && editor.contains(selection.getRangeAt(0).commonAncestorContainer);
215
+ editor.focus();
216
+ if (!selection)
217
+ return;
218
+ const range = document.createRange();
219
+ let insertion = text;
220
+ if (draftIsEmpty) {
221
+ // Only whitespace / <br> placeholders: replace them with the command.
222
+ range.selectNodeContents(editor);
223
+ }
224
+ else if (caretInEditor) {
225
+ // Collapse a selection to its end so no selected draft content is replaced.
226
+ const current = selection.getRangeAt(0);
227
+ range.setStart(current.endContainer, current.endOffset);
228
+ range.collapse(true);
229
+ }
230
+ else {
231
+ range.setStart(editor, 0);
232
+ range.collapse(true);
233
+ insertion = `${text} `;
234
+ }
235
+ selection.removeAllRanges();
236
+ selection.addRange(range);
237
+ // execCommand is deprecated but remains the only undo-preserving insertion API for contentEditable.
238
+ const inserted = typeof document.execCommand === 'function' && document.execCommand('insertText', false, insertion);
239
+ if (!inserted) {
240
+ const node = document.createTextNode(insertion);
241
+ range.deleteContents();
242
+ range.insertNode(node);
243
+ range.setStartAfter(node);
244
+ range.collapse(true);
245
+ selection.removeAllRanges();
246
+ selection.addRange(range);
247
+ editor.dispatchEvent(new Event('input', { bubbles: true }));
248
+ }
249
+ handleChange();
250
+ };
202
251
  // 聚焦编辑器
203
252
  const focus = () => {
204
253
  editorRef.current?.focus();
@@ -339,6 +388,7 @@ const RichTextEditor = forwardRef(({ locale = 'zh-CN', placeholder = sandboxText
339
388
  useImperativeHandle(ref, () => ({
340
389
  focus,
341
390
  clear,
391
+ setText,
342
392
  insertFace,
343
393
  insertImage,
344
394
  insertVideo,
@@ -19,6 +19,8 @@ export interface RichTextEditorProps {
19
19
  export interface RichTextEditorRef {
20
20
  focus: () => void
21
21
  clear: () => void
22
+ /** Quick-command prefill: fills an empty draft, otherwise inserts at the caret without deleting the draft; never sends. */
23
+ setText: (text: string) => void
22
24
  insertFace: (faceId: number) => void
23
25
  insertImage: (url: string) => void
24
26
  insertVideo: (url: string) => void
@@ -236,6 +238,52 @@ const RichTextEditor = forwardRef<RichTextEditorRef, RichTextEditorProps>(
236
238
  }
237
239
  }
238
240
 
241
+ // Quick-command prefill (#1250). An empty composer gets the command; a non-empty draft
242
+ // (text, images, faces, mentions) is never overwritten: the command is inserted at the
243
+ // caret, or at the start when the caret is outside the editor. `insertText` keeps the
244
+ // browser undo stack; the Range fallback dispatches `input` so state stays in sync.
245
+ const setText = (text: string) => {
246
+ const editor = editorRef.current
247
+ if (!editor) return
248
+ const draftIsEmpty = (editor.textContent ?? '').trim() === ''
249
+ && editor.querySelector('img, [data-type], [data-url], [contenteditable="false"]') === null
250
+ const selection = window.getSelection()
251
+ const caretInEditor = !!selection && selection.rangeCount > 0
252
+ && editor.contains(selection.getRangeAt(0).commonAncestorContainer)
253
+ editor.focus()
254
+ if (!selection) return
255
+ const range = document.createRange()
256
+ let insertion = text
257
+ if (draftIsEmpty) {
258
+ // Only whitespace / <br> placeholders: replace them with the command.
259
+ range.selectNodeContents(editor)
260
+ } else if (caretInEditor) {
261
+ // Collapse a selection to its end so no selected draft content is replaced.
262
+ const current = selection.getRangeAt(0)
263
+ range.setStart(current.endContainer, current.endOffset)
264
+ range.collapse(true)
265
+ } else {
266
+ range.setStart(editor, 0)
267
+ range.collapse(true)
268
+ insertion = `${text} `
269
+ }
270
+ selection.removeAllRanges()
271
+ selection.addRange(range)
272
+ // execCommand is deprecated but remains the only undo-preserving insertion API for contentEditable.
273
+ const inserted = typeof document.execCommand === 'function' && document.execCommand('insertText', false, insertion)
274
+ if (!inserted) {
275
+ const node = document.createTextNode(insertion)
276
+ range.deleteContents()
277
+ range.insertNode(node)
278
+ range.setStartAfter(node)
279
+ range.collapse(true)
280
+ selection.removeAllRanges()
281
+ selection.addRange(range)
282
+ editor.dispatchEvent(new Event('input', { bubbles: true }))
283
+ }
284
+ handleChange()
285
+ }
286
+
239
287
  // 聚焦编辑器
240
288
  const focus = () => {
241
289
  editorRef.current?.focus()
@@ -399,6 +447,7 @@ const RichTextEditor = forwardRef<RichTextEditorRef, RichTextEditorProps>(
399
447
  useImperativeHandle(ref, () => ({
400
448
  focus,
401
449
  clear,
450
+ setText,
402
451
  insertFace,
403
452
  insertImage,
404
453
  insertVideo,