@aiyiran/myclaw 1.0.224 → 1.0.226
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/assets/myclaw-artifacts.js +70 -25
- package/package.json +1 -1
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
btn.id = 'myclaw-artifacts-btn';
|
|
63
63
|
btn.style.cssText = [
|
|
64
64
|
'position: fixed',
|
|
65
|
-
'top:
|
|
65
|
+
'top: 200px',
|
|
66
66
|
'right: 0',
|
|
67
67
|
'padding: 3px 10px',
|
|
68
68
|
'background: rgba(100, 100, 100, 0.7)',
|
|
@@ -107,10 +107,10 @@
|
|
|
107
107
|
panel.id = 'myclaw-artifacts-panel';
|
|
108
108
|
panel.style.cssText = [
|
|
109
109
|
'position: fixed',
|
|
110
|
-
'top:
|
|
110
|
+
'top: 230px',
|
|
111
111
|
'right: 0',
|
|
112
112
|
'width: 380px',
|
|
113
|
-
'max-height: calc(100vh -
|
|
113
|
+
'max-height: calc(100vh - 250px)',
|
|
114
114
|
'background: #1e1e2e',
|
|
115
115
|
'border-radius: 8px 0 0 8px',
|
|
116
116
|
'overflow: hidden',
|
|
@@ -258,18 +258,16 @@
|
|
|
258
258
|
return tb.localeCompare(ta);
|
|
259
259
|
});
|
|
260
260
|
|
|
261
|
-
var topUpdatedAt = data.updated_at || '';
|
|
262
|
-
|
|
263
261
|
sorted.forEach(function (asset, idx) {
|
|
264
|
-
//
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
var
|
|
268
|
-
|
|
269
|
-
//
|
|
270
|
-
var
|
|
271
|
-
var
|
|
272
|
-
var
|
|
262
|
+
// 状态判断:基于 last_open 时间戳
|
|
263
|
+
// - 无 last_open → [最新](从未点开过)
|
|
264
|
+
// - updated_at > last_open → [有更新](更新了但没看过)
|
|
265
|
+
var assetKey = asset.id || asset.path;
|
|
266
|
+
var lastOpenKey = 'myclaw-artifacts-last-open-' + assetKey;
|
|
267
|
+
var lastOpen = localStorage.getItem(lastOpenKey); // ISO string or null
|
|
268
|
+
var assetUpdated = asset.updated_at || '';
|
|
269
|
+
var isLatest = !lastOpen;
|
|
270
|
+
var isUpdated = lastOpen && assetUpdated && new Date(assetUpdated) > new Date(lastOpen);
|
|
273
271
|
|
|
274
272
|
var row = document.createElement('div');
|
|
275
273
|
row.style.cssText = [
|
|
@@ -283,12 +281,20 @@
|
|
|
283
281
|
row.onmouseenter = function () { row.style.background = '#2d2d3f'; };
|
|
284
282
|
row.onmouseleave = function () { row.style.background = 'transparent'; };
|
|
285
283
|
row.onclick = function () {
|
|
286
|
-
|
|
287
|
-
|
|
284
|
+
// 记录点开时间
|
|
285
|
+
localStorage.setItem(lastOpenKey, new Date().toISOString());
|
|
286
|
+
// 复制文件名到剪贴板
|
|
287
|
+
var fileName = pathParts[pathParts.length - 1] || asset.name || '未命名';
|
|
288
|
+
navigator.clipboard.writeText(fileName).then(function () {
|
|
289
|
+
var orig = nameSpan.textContent;
|
|
290
|
+
nameSpan.textContent = '✓ 已复制';
|
|
291
|
+
nameSpan.style.color = '#10b981';
|
|
292
|
+
setTimeout(function () {
|
|
293
|
+
nameSpan.textContent = orig;
|
|
294
|
+
nameSpan.style.color = '';
|
|
295
|
+
}, 800);
|
|
296
|
+
});
|
|
288
297
|
openPreviewModal(data, asset);
|
|
289
|
-
if (asset.type === 'html') {
|
|
290
|
-
window.open(buildPreviewUrl(data, asset.path), '_blank');
|
|
291
|
-
}
|
|
292
298
|
};
|
|
293
299
|
|
|
294
300
|
// 更新时间
|
|
@@ -311,13 +317,12 @@
|
|
|
311
317
|
var nameSpan = document.createElement('span');
|
|
312
318
|
nameSpan.textContent = pathParts[pathParts.length - 1] || asset.name || '未命名';
|
|
313
319
|
nameSpan.title = asset.path || '';
|
|
314
|
-
|
|
315
|
-
if (isLatest && !isLatestSeen) {
|
|
320
|
+
if (isLatest) {
|
|
316
321
|
var badge = document.createElement('span');
|
|
317
322
|
badge.style.cssText = 'color:#ff4444;font-size:10px;font-weight:bold;flex-shrink:0;';
|
|
318
323
|
badge.textContent = '[最新]';
|
|
319
324
|
fname.appendChild(badge);
|
|
320
|
-
} else if (isUpdated
|
|
325
|
+
} else if (isUpdated) {
|
|
321
326
|
var badge = document.createElement('span');
|
|
322
327
|
badge.style.cssText = 'color:#10b981;font-size:10px;font-weight:bold;flex-shrink:0;';
|
|
323
328
|
badge.textContent = '[有更新]';
|
|
@@ -380,17 +385,36 @@
|
|
|
380
385
|
].join(';');
|
|
381
386
|
header.innerHTML = '<span>\uD83C\uDFA8 ' + (asset.name || '预览') + '</span>';
|
|
382
387
|
|
|
388
|
+
var headerRight = document.createElement('span');
|
|
389
|
+
headerRight.style.cssText = 'display:flex;align-items:center;gap:10px;';
|
|
390
|
+
|
|
391
|
+
var openBtn = document.createElement('span');
|
|
392
|
+
openBtn.textContent = '\u5728\u65B0\u9875\u9762\u6253\u5F00';
|
|
393
|
+
openBtn.style.cssText = 'cursor:pointer;padding:4px 10px;border-radius:4px;font-size:12px;background:rgba(255,255,255,0.08);transition:background 0.15s;';
|
|
394
|
+
openBtn.onmouseenter = function () { openBtn.style.background = 'rgba(255,255,255,0.18)'; };
|
|
395
|
+
openBtn.onmouseleave = function () { openBtn.style.background = 'rgba(255,255,255,0.08)'; };
|
|
396
|
+
var previewUrl = buildPreviewUrl(data, asset.path);
|
|
397
|
+
openBtn.onclick = function () {
|
|
398
|
+
window.open(previewUrl, '_blank');
|
|
399
|
+
navigator.clipboard.writeText(previewUrl).then(function () {
|
|
400
|
+
openBtn.textContent = '\u2713 \u5DF2\u590D\u5236';
|
|
401
|
+
setTimeout(function () { openBtn.textContent = '\u5728\u65B0\u9875\u9762\u6253\u5F00'; }, 1500);
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
headerRight.appendChild(openBtn);
|
|
405
|
+
|
|
383
406
|
var closeBtn = document.createElement('span');
|
|
384
407
|
closeBtn.textContent = '\u2715';
|
|
385
408
|
closeBtn.style.cssText = 'cursor:pointer;padding:4px 10px;border-radius:4px;font-size:18px;font-weight:bold;transition:background 0.15s;';
|
|
386
409
|
closeBtn.onmouseenter = function () { closeBtn.style.background = 'rgba(255,255,255,0.15)'; };
|
|
387
410
|
closeBtn.onmouseleave = function () { closeBtn.style.background = 'none'; };
|
|
388
411
|
closeBtn.onclick = function () { closePreviewModal(); };
|
|
389
|
-
|
|
412
|
+
headerRight.appendChild(closeBtn);
|
|
413
|
+
header.appendChild(headerRight);
|
|
390
414
|
|
|
391
415
|
// iframe
|
|
392
416
|
var iframe = document.createElement('iframe');
|
|
393
|
-
iframe.src = buildPreviewUrl(data, asset.path);
|
|
417
|
+
iframe.src = buildPreviewUrl(data, asset.path) + '?t=' + Date.now();
|
|
394
418
|
iframe.style.cssText = [
|
|
395
419
|
'flex: 1',
|
|
396
420
|
'width: 100%',
|
|
@@ -419,6 +443,10 @@
|
|
|
419
443
|
console.log('[myclaw-artifacts-publish] html assets:', cachedData.assets.filter(function (a) { return a.type && a.type.toLowerCase() === 'html'; }));
|
|
420
444
|
console.log('[myclaw-artifacts-publish] image assets:', cachedData.assets.filter(function (a) { return a.type && a.type.toLowerCase() === 'image'; }));
|
|
421
445
|
|
|
446
|
+
// 读取上次发布缓存
|
|
447
|
+
var savedForm = {};
|
|
448
|
+
try { savedForm = JSON.parse(localStorage.getItem('myclaw-publish-cache')) || {}; } catch (e) {}
|
|
449
|
+
|
|
422
450
|
var overlay = document.createElement('div');
|
|
423
451
|
overlay.id = 'myclaw-artifacts-publish-modal';
|
|
424
452
|
overlay.style.cssText = [
|
|
@@ -483,7 +511,7 @@
|
|
|
483
511
|
var titleInput = document.createElement('input');
|
|
484
512
|
titleInput.type = 'text';
|
|
485
513
|
titleInput.placeholder = '\u8F93\u5165\u5C55\u793A\u6807\u9898';
|
|
486
|
-
titleInput.value = cachedData.title || '';
|
|
514
|
+
titleInput.value = savedForm.title || cachedData.title || '';
|
|
487
515
|
titleInput.style.cssText = 'padding:8px 10px;background:#252536;border:1px solid #3d3d5c;border-radius:4px;color:#cdd6f4;font-size:13px;font-family:monospace;outline:none;';
|
|
488
516
|
titleInput.onfocus = function () { titleInput.style.borderColor = '#6c6caa'; };
|
|
489
517
|
titleInput.onblur = function () { titleInput.style.borderColor = '#3d3d5c'; };
|
|
@@ -527,6 +555,14 @@
|
|
|
527
555
|
}
|
|
528
556
|
};
|
|
529
557
|
coverRow.appendChild(coverSelect);
|
|
558
|
+
// 恢复缓存选中
|
|
559
|
+
if (savedForm.cover_path) {
|
|
560
|
+
coverSelect.value = savedForm.cover_path;
|
|
561
|
+
if (coverSelect.value) {
|
|
562
|
+
coverPreview.src = buildPreviewUrl(cachedData, coverSelect.value);
|
|
563
|
+
coverPreview.style.display = 'block';
|
|
564
|
+
}
|
|
565
|
+
}
|
|
530
566
|
coverRow.appendChild(coverPreview);
|
|
531
567
|
coverGroup.appendChild(coverLabel);
|
|
532
568
|
coverGroup.appendChild(coverRow);
|
|
@@ -555,6 +591,10 @@
|
|
|
555
591
|
});
|
|
556
592
|
entryGroup.appendChild(entryLabel);
|
|
557
593
|
entryGroup.appendChild(entrySelect);
|
|
594
|
+
// 恢复缓存选中
|
|
595
|
+
if (savedForm.entry_path) {
|
|
596
|
+
entrySelect.value = savedForm.entry_path;
|
|
597
|
+
}
|
|
558
598
|
form.appendChild(entryGroup);
|
|
559
599
|
|
|
560
600
|
// 确认发布按钮
|
|
@@ -589,6 +629,11 @@
|
|
|
589
629
|
.then(function (res) { return res.json(); })
|
|
590
630
|
.then(function (data) {
|
|
591
631
|
console.log('[myclaw-artifacts-publish]', payload, data);
|
|
632
|
+
localStorage.setItem('myclaw-publish-cache', JSON.stringify({
|
|
633
|
+
title: titleVal,
|
|
634
|
+
cover_path: coverSelect.value || '',
|
|
635
|
+
entry_path: entrySelect.value || '',
|
|
636
|
+
}));
|
|
592
637
|
closePublishModal();
|
|
593
638
|
})
|
|
594
639
|
.catch(function (err) {
|