one-design-next 0.0.119 → 0.0.120

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.
@@ -22,6 +22,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
22
22
 
23
23
  import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from 'react';
24
24
  import { createPortal } from 'react-dom';
25
+ import { svgData } from "../icon/svg-data";
25
26
  import ScrollArea from "../scroll-area";
26
27
  import { caretBeforeHintIn, caretRangeFromPoint, findChipHostBeforeCaret, getCaretBeforeHint, getCurrentLine, isCaretBeforeHint, isCaretOnHintLine, isPointOnHint, isPositionAfterHint, mergeLineIntoPreviousAtCaretStart, normalizeCollapsedCaretAtChipBoundary, normalizeCollapsedCaretBeforeHint, resolveCaretMove, splitLineAt, wouldArrowCrossHint } from "./caret";
27
28
  import { buildClipboardPayload, COMPOSER_CLIPBOARD_MIME, parseClipboardPayload, plainTextFromClipboardPayload, remapClipboardPayload } from "./clipboard";
@@ -102,8 +103,36 @@ var findDirectHint = function findDirectHint(line) {
102
103
  return null;
103
104
  };
104
105
 
106
+ /** 小块右侧的箭头图标:OD icon `arrow-right-to-line`(文案 → 填入的指向)。 */
107
+ var HINT_ACCEPT_ICON_NAME = 'arrow-right-to-line';
108
+
109
+ /**
110
+ * 拼一个 `<svg>` 图标节点。
111
+ *
112
+ * 小块由 DOM API 直接构建(editor 的 children 归 contenteditable 自治,不走
113
+ * React),所以这里从图标数据里取 viewBox / content 自己建元素;描边用
114
+ * `currentColor`,颜色跟随父级文字色。尺寸取 12:与本块 12px 文案同高,
115
+ * Lucide 的 24 viewBox 缩到 12 后描边正好 1px,与文字笔画同重。
116
+ */
117
+ var createHintAcceptArrowNode = function createHintAcceptArrowNode() {
118
+ var _svgData$HINT_ACCEPT_ = svgData[HINT_ACCEPT_ICON_NAME],
119
+ viewBox = _svgData$HINT_ACCEPT_.viewBox,
120
+ content = _svgData$HINT_ACCEPT_.content;
121
+ var arrow = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
122
+ arrow.setAttribute('data-odn-composer-hint-accept-arrow', '');
123
+ arrow.setAttribute('viewBox', viewBox);
124
+ arrow.setAttribute('width', '12');
125
+ arrow.setAttribute('height', '12');
126
+ arrow.setAttribute('fill', 'none');
127
+ /* 装饰性图标:文案已经说清动作,不给读屏重复播报。 */
128
+ arrow.setAttribute('aria-hidden', 'true');
129
+ arrow.setAttribute('focusable', 'false');
130
+ arrow.innerHTML = content;
131
+ return arrow;
132
+ };
133
+
105
134
  /**
106
- * hint 末尾的「按 TAB 键填入」小块:点它 = 按 Tab 填入这段模板文案。
135
+ * hint 末尾的「TAB 键填入」小块:点它 = 按 Tab 填入这段模板文案。
107
136
  *
108
137
  * 与 hint 文本是同级节点(见 `COMPOSER_HINT_ACCEPT_ATTR` 的说明),由
109
138
  * `syncHintNode` 一起插入 / 移除,不进 value / 剪贴板 / segments。
@@ -120,16 +149,13 @@ var createHintAcceptNode = function createHintAcceptNode() {
120
149
  * - aria-label 会盖掉可见文案,反而违反「可见标签即无障碍名」。
121
150
  * - title 是浏览器原生 tooltip:延迟出现、样式不可控、会盖住灰字。 */
122
151
 
123
- var prefix = document.createElement('span');
124
- prefix.setAttribute('data-odn-composer-hint-accept-prefix', '');
125
- prefix.textContent = '按';
126
152
  var key = document.createElement('span');
127
153
  key.setAttribute('data-odn-composer-hint-accept-key', '');
128
154
  key.textContent = 'TAB';
129
155
  var label = document.createElement('span');
130
156
  label.setAttribute('data-odn-composer-hint-accept-label', '');
131
157
  label.textContent = '键填入';
132
- accept.append(prefix, key, label);
158
+ accept.append(key, label, createHintAcceptArrowNode());
133
159
  return accept;
134
160
  };
135
161
 
@@ -473,7 +499,7 @@ export var ComposerEditor = /*#__PURE__*/forwardRef(function ComposerEditor(_ref
473
499
  * 它不归 React 管(editor 的 children 由 contenteditable 自治),由 fireChange
474
500
  * 按结构谓词增删/挪位;`getPlainText` 会整棵子树跳过,所以不进 value / 剪贴板。
475
501
  *
476
- * 末尾的「按 TAB 键填入」小块是 hint 文本的**兄弟节点**(不是子节点):hint 的
502
+ * 末尾的「TAB 键填入」小块是 hint 文本的**兄弟节点**(不是子节点):hint 的
477
503
  * textContent 必须保持纯提示文案(采纳时直接落成正文,调试面板也按它读)。 */
478
504
  var hintNodeRef = useRef(null);
479
505
  var hintAcceptNodeRef = useRef(null);
@@ -521,7 +547,7 @@ export var ComposerEditor = /*#__PURE__*/forwardRef(function ComposerEditor(_ref
521
547
  var cur = host.nextSibling;
522
548
  while (cur) {
523
549
  var _cur$textContent;
524
- // 跳过 hint 自身与它的「按 TAB 键填入」小块:上一轮若排到了锚点前面,
550
+ // 跳过 hint 自身与它的「TAB 键填入」小块:上一轮若排到了锚点前面,
525
551
  // 这里顺手挪回末尾
526
552
  if (cur === node || cur === accept) {
527
553
  cur = cur.nextSibling;
@@ -550,7 +576,7 @@ export var ComposerEditor = /*#__PURE__*/forwardRef(function ComposerEditor(_ref
550
576
  if (node.parentNode !== parent || node.previousSibling !== anchor) {
551
577
  parent.insertBefore(node, anchor.nextSibling);
552
578
  }
553
- /* 「按 TAB 键填入」小块紧跟 hint 文案之后(同一套行内流),顺序必须是
579
+ /* 「TAB 键填入」小块紧跟 hint 文案之后(同一套行内流),顺序必须是
554
580
  * hint → 小块:caret 的合法落点只到 hint 之前,块本身
555
581
  * contentEditable=false,不会成为落点。 */
556
582
  if (accept.parentNode !== parent || accept.previousSibling !== node) {
@@ -660,14 +686,14 @@ export var ComposerEditor = /*#__PURE__*/forwardRef(function ComposerEditor(_ref
660
686
  recomputeTriggerRef.current = recomputeTrigger;
661
687
 
662
688
  /* ─────────────────────────────────────
663
- * 采纳 hint(Tab / 点击「按 TAB 键填入」小块)
689
+ * 采纳 hint(Tab / 点击「TAB 键填入」小块)
664
690
  *
665
691
  * hint 只是结构投影(不进 value);caret 恰好停在 chip 与 hint 之间
666
692
  * (= 内容末尾)时按 Tab,表示用户接受这段模板,于是把提示文案落成正文:
667
693
  * chip 之后出现内容 → 结构谓词不再命中 → 灰字自动移除,onChange 抛出的
668
694
  * value 里带上这段文案,与用户自己敲进去的效果一致。
669
695
  *
670
- * 鼠标点末尾的「按 TAB 键填入」小块走**同一条链路**,只是带 `force`:
696
+ * 鼠标点末尾的「TAB 键填入」小块走**同一条链路**,只是带 `force`:
671
697
  * 不要求点击前 caret 就停在 hint 之前,先把 caret 归位到 chip 右侧再落。
672
698
  * ───────────────────────────────────── */
673
699
  var acceptHintAsText = useCallback(function (options) {
@@ -1219,7 +1245,7 @@ export var ComposerEditor = /*#__PURE__*/forwardRef(function ComposerEditor(_ref
1219
1245
  // shift+click 是扩选,不劫持
1220
1246
  if (e.shiftKey) return;
1221
1247
 
1222
- /* 「按 TAB 键填入」小块:点它等价于按 Tab(同一条采纳链路),且不要求点击前
1248
+ /* 「TAB 键填入」小块:点它等价于按 Tab(同一条采纳链路),且不要求点击前
1223
1249
  * caret 就停在 hint 之前。在 mousedown 阶段接管 + preventDefault,
1224
1250
  * 原生 caret 一帧都不会落到 hint 之后。 */
1225
1251
  if (e.target instanceof Element && e.target.closest(COMPOSER_HINT_ACCEPT_SELECTOR)) {
@@ -356,15 +356,16 @@
356
356
  }
357
357
 
358
358
  /* ------------------------------------------------------------------
359
- * hint 末尾的「按 TAB 键填入」小块(点击 = 按 Tab 填入,见 editor.tsx)
359
+ * hint 末尾的「TAB 键填入」小块(点击 = 按 Tab 填入,见 editor.tsx)
360
360
  *
361
361
  * 与 hint 文本是同级节点,一起增删。它不是正文:contentEditable=false、
362
362
  * getPlainText 整棵跳过,点它走 force 版 acceptHintAsText。
363
- * 尺寸对齐 Figma 9857:75425(90 × 22 / 圆角 6 / 内层键帽 28 × 16):
363
+ * 尺寸对齐 Figma 9857:75425(22 高 / 圆角 6 / 内层键帽 28 × 16);
364
+ * 宽度随内容自然撑开(键帽 + 「键填入」+ 12px 箭头图标,约 90):
364
365
  * - 编辑器固定 font-size 14 / line-height 24,块高 22 + top 1 → 视觉居中
365
366
  * 且不撑高行盒(改编辑器行高时要同步调这个 1px)
366
367
  * - 底色 black-2(5%)、键帽 bg-elevated + black-5(12%) 1px 描边
367
- * - 「按」「键填入」与键帽之间 gap 3,左右内边距 4
368
+ * - 「键填入」与键帽之间 gap 3,左右内边距 4
368
369
  * ----------------------------------------------------------------- */
369
370
  [data-odn-composer] [data-odn-composer-hint-accept] {
370
371
  display: inline-flex;
@@ -416,12 +417,18 @@
416
417
  letter-spacing: 0;
417
418
  }
418
419
 
419
- [data-odn-composer] [data-odn-composer-hint-accept-prefix],
420
420
  [data-odn-composer] [data-odn-composer-hint-accept-label] {
421
421
  font-size: 12px;
422
422
  line-height: 20px;
423
423
  }
424
424
 
425
+ /* 文案右侧的箭头图标(OD icon arrow-right-to-line,DOM 见 editor.tsx):
426
+ * 宽高由 svg 属性锁 12,这里只保证它不被 flex 压缩。 */
427
+ [data-odn-composer] [data-odn-composer-hint-accept-arrow] {
428
+ display: block;
429
+ flex: none;
430
+ }
431
+
425
432
  /* 禁用态:hint 仍按内容结构展示,但小块不可点(与 editor 冻结一致) */
426
433
  [data-odn-composer] [data-odn-composer-editor][data-odn-composer-editor-disabled] [data-odn-composer-hint-accept] {
427
434
  cursor: not-allowed;
@@ -23,7 +23,7 @@ export declare const LINE_ATTR_NAME = "data-composer-line";
23
23
  export declare const COMPOSER_HINT_ATTR = "data-odn-composer-skill-hint";
24
24
  export declare const COMPOSER_HINT_SELECTOR = "[data-odn-composer-skill-hint]";
25
25
  /**
26
- * 派生 hint 末尾的「按 TAB 键填入」小块(可点击采纳)。
26
+ * 派生 hint 末尾的「TAB 键填入」小块(可点击采纳)。
27
27
  *
28
28
  * 与 hint 文本是**兄弟节点**(不是子节点):hint 自身的 `textContent` 必须
29
29
  * 保持纯提示文案——采纳时直接把这段文字落成正文,且 `getPlainText` /
@@ -40,7 +40,7 @@ export var COMPOSER_HINT_ATTR = 'data-odn-composer-skill-hint';
40
40
  export var COMPOSER_HINT_SELECTOR = "[".concat(COMPOSER_HINT_ATTR, "]");
41
41
 
42
42
  /**
43
- * 派生 hint 末尾的「按 TAB 键填入」小块(可点击采纳)。
43
+ * 派生 hint 末尾的「TAB 键填入」小块(可点击采纳)。
44
44
  *
45
45
  * 与 hint 文本是**兄弟节点**(不是子节点):hint 自身的 `textContent` 必须
46
46
  * 保持纯提示文案——采纳时直接把这段文字落成正文,且 `getPlainText` /
@@ -302,7 +302,7 @@ export function getPlainText(editor) {
302
302
  var out = '';
303
303
  var visit = function visit(node) {
304
304
  if (node instanceof HTMLElement) {
305
- // 派生 hint(含末尾的「按 TAB 键填入」小块)整棵子树都不是正文,直接跳过
305
+ // 派生 hint(含末尾的「TAB 键填入」小块)整棵子树都不是正文,直接跳过
306
306
  if (node.hasAttribute(COMPOSER_HINT_ATTR) || node.hasAttribute(COMPOSER_HINT_ACCEPT_ATTR)) return;
307
307
  var id = node.dataset[chipIdAttr];
308
308
  if (id) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "one-design-next",
3
- "version": "0.0.119",
3
+ "version": "0.0.120",
4
4
  "description": "One Design Next from TAD@tencent.com",
5
5
  "license": "MIT",
6
6
  "type": "module",