@king-design/vue 3.8.0-beta.1 → 3.8.0-beta.2

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.
@@ -24,6 +24,7 @@ export function useXMarkdownDisplay(getPrefixCls) {
24
24
  var previousContent = instance.get('content');
25
25
  var previousLoading = !!instance.get('loading');
26
26
  var previousStreaming = !!instance.get('streaming');
27
+ var typingTargetKey = '';
27
28
  // Markdown 渲染缓存
28
29
  var lastStableMarkdownSource = '';
29
30
  var lastStableMarkdownBlocks = [];
@@ -130,12 +131,16 @@ export function useXMarkdownDisplay(getPrefixCls) {
130
131
  if (typing && typeof typing === 'object') {
131
132
  return {
132
133
  interval: Math.max(typing.interval || 24, 16),
133
- step: Math.max(typing.step || 2, 1)
134
+ step: Math.max(typing.step || 2, 1),
135
+ keepPrefix: typing.keepPrefix !== false,
136
+ resumeFrom: typing.resumeFrom
134
137
  };
135
138
  }
136
139
  return {
137
140
  interval: 24,
138
- step: 2
141
+ step: 2,
142
+ keepPrefix: true,
143
+ resumeFrom: undefined
139
144
  };
140
145
  }
141
146
  /**
@@ -209,19 +214,50 @@ export function useXMarkdownDisplay(getPrefixCls) {
209
214
  function getDisplayedContent() {
210
215
  return instance.get('$displayContent') || '';
211
216
  }
217
+ function getSafeContentPrefix(content, prefix) {
218
+ if (!prefix) return '';
219
+ if (_startsWithInstanceProperty(content).call(content, prefix)) return prefix;
220
+ var i = 0;
221
+ while (i < prefix.length && i < content.length && prefix[i] === content[i]) {
222
+ i++;
223
+ }
224
+ return _sliceInstanceProperty(prefix).call(prefix, 0, i);
225
+ }
226
+ function getResumePrefix(content) {
227
+ var _getTypingOptions = getTypingOptions(),
228
+ resumeFrom = _getTypingOptions.resumeFrom;
229
+ if (resumeFrom === undefined || resumeFrom === null) return '';
230
+ if (resumeFrom === 'content') return content;
231
+ if (typeof resumeFrom === 'number') return _sliceInstanceProperty(content).call(content, 0, Math.max(0, resumeFrom));
232
+ return getSafeContentPrefix(content, String(resumeFrom));
233
+ }
234
+ function getTypingTargetKey(content) {
235
+ var _getTypingOptions2 = getTypingOptions(),
236
+ keepPrefix = _getTypingOptions2.keepPrefix,
237
+ resumeFrom = _getTypingOptions2.resumeFrom;
238
+ return (keepPrefix ? '1' : '0') + "\0" + String(resumeFrom) + "\0" + content;
239
+ }
240
+ function syncTypingStart(content) {
241
+ var targetKey = getTypingTargetKey(content);
242
+ if (targetKey === typingTargetKey) return;
243
+ typingTargetKey = targetKey;
244
+ var sharedPrefix = getSharedPrefix(content);
245
+ if (sharedPrefix !== getDisplayedContent()) {
246
+ resetTypingComplete();
247
+ setDisplayContent(sharedPrefix);
248
+ }
249
+ }
212
250
  /**
213
251
  * 获取共享前缀
214
252
  */
215
253
  function getSharedPrefix(content) {
216
254
  var displayedContent = getDisplayedContent();
217
- if (!displayedContent || _startsWithInstanceProperty(content).call(content, displayedContent)) {
255
+ if (!displayedContent) return getResumePrefix(content);
256
+ if (!getTypingOptions().keepPrefix) return '';
257
+ if (_startsWithInstanceProperty(content).call(content, displayedContent)) {
218
258
  return displayedContent;
219
259
  }
220
- var i = 0;
221
- while (i < displayedContent.length && i < content.length && displayedContent[i] === content[i]) {
222
- i++;
223
- }
224
- return _sliceInstanceProperty(displayedContent).call(displayedContent, 0, i);
260
+ return getSafeContentPrefix(content, displayedContent);
225
261
  }
226
262
  /**
227
263
  * 立即渲染 Markdown
@@ -352,8 +388,8 @@ export function useXMarkdownDisplay(getPrefixCls) {
352
388
  runTyping();
353
389
  return;
354
390
  }
355
- var _getTypingOptions = getTypingOptions(),
356
- interval = _getTypingOptions.interval;
391
+ var _getTypingOptions3 = getTypingOptions(),
392
+ interval = _getTypingOptions3.interval;
357
393
  setTypingActive(true);
358
394
  typingTimer = window.setTimeout(function () {
359
395
  typingTimer = null;
@@ -371,6 +407,7 @@ export function useXMarkdownDisplay(getPrefixCls) {
371
407
  if (instance.get('loading')) {
372
408
  stopTyping();
373
409
  resetTypingComplete();
410
+ typingTargetKey = '';
374
411
  if (!setDisplayContent('')) {
375
412
  syncRenderedMarkdown();
376
413
  }
@@ -379,6 +416,7 @@ export function useXMarkdownDisplay(getPrefixCls) {
379
416
  // 无内容或禁用打字
380
417
  if (!instance.get('typing') || !nextValue) {
381
418
  stopTyping();
419
+ typingTargetKey = '';
382
420
  if (!setDisplayContent(nextValue)) {
383
421
  syncRenderedMarkdown();
384
422
  }
@@ -388,15 +426,11 @@ export function useXMarkdownDisplay(getPrefixCls) {
388
426
  return;
389
427
  }
390
428
  // 内容变化检测
391
- var sharedPrefix = getSharedPrefix(nextValue);
392
- if (sharedPrefix !== getDisplayedContent()) {
393
- resetTypingComplete();
394
- setDisplayContent(sharedPrefix);
395
- }
429
+ syncTypingStart(nextValue);
396
430
  var currentValue = getDisplayedContent();
397
- var _getTypingOptions2 = getTypingOptions(),
398
- interval = _getTypingOptions2.interval,
399
- step = _getTypingOptions2.step;
431
+ var _getTypingOptions4 = getTypingOptions(),
432
+ interval = _getTypingOptions4.interval,
433
+ step = _getTypingOptions4.step;
400
434
  // 逐步显示内容
401
435
  if (currentValue !== nextValue) {
402
436
  var nextLength = Math.min(currentValue.length + step, nextValue.length);
@@ -430,6 +464,7 @@ export function useXMarkdownDisplay(getPrefixCls) {
430
464
  if (instance.get('loading')) {
431
465
  stopTyping();
432
466
  resetTypingComplete();
467
+ typingTargetKey = '';
433
468
  if (!setDisplayContent('')) {
434
469
  syncRenderedMarkdown();
435
470
  }
@@ -442,6 +477,7 @@ export function useXMarkdownDisplay(getPrefixCls) {
442
477
  // 空内容或禁用打字效果,直接显示
443
478
  if (!nextValue || !typing) {
444
479
  stopTyping();
480
+ typingTargetKey = '';
445
481
  if (!setDisplayContent(nextValue)) {
446
482
  syncRenderedMarkdown();
447
483
  }
@@ -451,12 +487,11 @@ export function useXMarkdownDisplay(getPrefixCls) {
451
487
  return;
452
488
  }
453
489
  // 内容变化检测
454
- var sharedPrefix = getSharedPrefix(nextValue);
490
+ var previousDisplayContent = getDisplayedContent();
491
+ syncTypingStart(nextValue);
455
492
  // 内容发生"非追加"变化时
456
- if (sharedPrefix !== getDisplayedContent()) {
493
+ if (getDisplayedContent() !== previousDisplayContent) {
457
494
  stopTyping();
458
- resetTypingComplete();
459
- setDisplayContent(sharedPrefix);
460
495
  }
461
496
  // 已完成
462
497
  if (getDisplayedContent() === nextValue) {
@@ -475,8 +510,10 @@ export function useXMarkdownDisplay(getPrefixCls) {
475
510
  */
476
511
  function bootstrap() {
477
512
  var content = instance.get('content');
513
+ var nextValue = content === undefined || content === null ? '' : String(content);
478
514
  setTypingActive(false);
479
- setDisplayContent(!instance.get('loading') && !instance.get('typing') && content !== undefined && content !== null ? String(content) : '');
515
+ var initialDisplayContent = !instance.get('loading') && nextValue ? instance.get('typing') ? getResumePrefix(nextValue) : nextValue : '';
516
+ setDisplayContent(initialDisplayContent);
480
517
  // 监听核心属性变化
481
518
  ['content', 'loading', 'streaming', 'typing'].forEach(function (key) {
482
519
  instance.watch(key, function () {
@@ -6,6 +6,8 @@ export interface XMarkdownTyping {
6
6
  interval?: number;
7
7
  step?: number;
8
8
  suffix?: boolean;
9
+ keepPrefix?: boolean;
10
+ resumeFrom?: string | number | 'content';
9
11
  }
10
12
  export interface XMarkdownProps {
11
13
  content?: string | number;