dsh-workbench-storage 1.5.1 → 1.5.6
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/lib/client.js +666 -107
- package/lib/domain/tags.js +30 -2
- package/lib/index.js +8 -1
- package/lib/infra/backup.js +6 -0
- package/lib/tagging/source.js +89 -0
- package/package.json +4 -4
package/lib/client.js
CHANGED
|
@@ -597,6 +597,13 @@ var require_description = __commonJS({
|
|
|
597
597
|
var React = require("react");
|
|
598
598
|
var h2 = React.createElement;
|
|
599
599
|
var Body = require_markdown().createBody(React);
|
|
600
|
+
var bodies = typeof WeakMap === "function" ? /* @__PURE__ */ new WeakMap() : null;
|
|
601
|
+
function bodyFor(Highlight) {
|
|
602
|
+
if (!Highlight) return Body;
|
|
603
|
+
if (!bodies) return require_markdown().createBody(React, Highlight);
|
|
604
|
+
if (!bodies.has(Highlight)) bodies.set(Highlight, require_markdown().createBody(React, Highlight));
|
|
605
|
+
return bodies.get(Highlight);
|
|
606
|
+
}
|
|
600
607
|
var BodyMode = require_body_toggle()(React);
|
|
601
608
|
var copy = require_body_copy();
|
|
602
609
|
var Code = (init_code_2(), __toCommonJS(code_2_exports)).default;
|
|
@@ -615,6 +622,7 @@ var require_description = __commonJS({
|
|
|
615
622
|
var mode = React.useState(props.bodyMode === "text" ? "text" : "markdown");
|
|
616
623
|
var labelId = require_body_id()(React) + "-desc", t = copy[props.lang === "en" ? "en" : "zh"];
|
|
617
624
|
var text = props.text == null ? "" : String(props.text);
|
|
625
|
+
var DescBody = bodyFor(props.Highlight);
|
|
618
626
|
var expanded = React.useState(false), overflow = React.useState(false), ref = React.useRef(null);
|
|
619
627
|
React.useEffect(function() {
|
|
620
628
|
expanded[1](false);
|
|
@@ -648,7 +656,7 @@ var require_description = __commonJS({
|
|
|
648
656
|
h2(
|
|
649
657
|
"div",
|
|
650
658
|
{ ref, className: "wb-desc-text" + (expanded[0] ? "" : " wb-desc-clamped") },
|
|
651
|
-
h2(
|
|
659
|
+
h2(DescBody, { text, mode: mode[0], keyword: props.keyword })
|
|
652
660
|
),
|
|
653
661
|
overflow[0] || expanded[0] ? h2("button", {
|
|
654
662
|
type: "button",
|
|
@@ -675,12 +683,47 @@ var require_visual_tokens = __commonJS({
|
|
|
675
683
|
}
|
|
676
684
|
});
|
|
677
685
|
|
|
686
|
+
// packages/addons/lib/filter-checklist-styles.cjs
|
|
687
|
+
var require_filter_checklist_styles = __commonJS({
|
|
688
|
+
"packages/addons/lib/filter-checklist-styles.cjs"(exports2, module2) {
|
|
689
|
+
"use strict";
|
|
690
|
+
module2.exports = [
|
|
691
|
+
".wbck{display:flex;flex-direction:column;min-width:0}",
|
|
692
|
+
".wbck-search{padding:0 0 6px}",
|
|
693
|
+
".wbck-input{width:100%;box-sizing:border-box;font:inherit;font-size:12.5px;padding:6px 9px;border:1px solid var(--wb-border);border-radius:8px;background:var(--wb-surface);color:inherit}",
|
|
694
|
+
".wbck-input:focus-visible{outline:2px solid var(--wb-accent);outline-offset:1px}",
|
|
695
|
+
".wbck-input:disabled{opacity:.6;cursor:not-allowed}",
|
|
696
|
+
".wbck-head{display:flex;align-items:center;gap:6px;font-size:11.5px;color:var(--wb-muted);padding:2px 4px 7px}",
|
|
697
|
+
".wbck-grow{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
698
|
+
".wbck-sel{flex:none;color:var(--wb-accent)}",
|
|
699
|
+
".wbck-clear{appearance:none;flex:none;border:0;background:transparent;color:inherit;border-radius:4px;margin:0;padding:3px 5px;font:inherit;font-size:11.5px;line-height:1;cursor:pointer;opacity:.75}",
|
|
700
|
+
".wbck-clear:hover:enabled{opacity:1;background:color-mix(in srgb, currentColor 8%, transparent)}",
|
|
701
|
+
".wbck-clear:focus-visible{outline:2px solid var(--wb-accent);outline-offset:1px}",
|
|
702
|
+
".wbck-clear:disabled{opacity:.4;cursor:not-allowed}",
|
|
703
|
+
".wbck-list{max-height:220px;overflow:auto;overscroll-behavior:contain;border:1px solid var(--wb-border);border-radius:10px;padding:2px}",
|
|
704
|
+
".wbck-opt{display:flex;align-items:center;gap:7px;padding:6px;border-radius:6px;font-size:12.5px;cursor:pointer}",
|
|
705
|
+
".wbck-opt:hover{background:color-mix(in srgb, currentColor 7%, transparent)}",
|
|
706
|
+
".wbck-opt.is-on{background:color-mix(in srgb, var(--wb-accent) 10%, transparent)}",
|
|
707
|
+
".wbck-opt input{margin:0;flex:none;accent-color:var(--wb-accent)}",
|
|
708
|
+
// 单选变体用 button 渲染(role="radio"),这里把浏览器默认按钮样式清掉,视觉与多选行一致。
|
|
709
|
+
'.wbck-opt[role="radio"]{appearance:none;width:100%;box-sizing:border-box;border:0;background:transparent;color:inherit;font:inherit;text-align:left}',
|
|
710
|
+
'.wbck-opt[role="radio"]:disabled{opacity:.55;cursor:not-allowed}',
|
|
711
|
+
'.wbck-opt[role="radio"]:focus-visible{outline:2px solid var(--wb-accent);outline-offset:-2px}',
|
|
712
|
+
".wbck-nm{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
713
|
+
".wbck-meta{margin-left:auto;flex:none;font-size:11.5px;color:var(--wb-muted)}",
|
|
714
|
+
".wbck-note{font-size:12px;color:var(--wb-muted);padding:8px 6px}",
|
|
715
|
+
".wbck-more{font-size:11px;color:var(--wb-muted);text-align:center;padding:6px 0 2px;opacity:.8}",
|
|
716
|
+
"@media (max-width:760px){.wbck-list{max-height:200px}}"
|
|
717
|
+
];
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
|
|
678
721
|
// packages/addons/storage/client/ui/styles.cjs
|
|
679
722
|
var require_styles = __commonJS({
|
|
680
723
|
"packages/addons/storage/client/ui/styles.cjs"(exports2, module2) {
|
|
681
724
|
module2.exports = require_description().css + require_visual_tokens() + `
|
|
682
|
-
.wbi-root{--line:var(--wb-line,var(--dsw-alias-border-l2,#d9dfe6));--surface:var(--wb-surface,var(--dsw-alias-bg-layer-1,#fff));--muted:var(--dsw-alias-label-secondary,#64748b);--accent:var(--dsw-alias-brand-primary,#2563eb);font-size:13px;color:inherit;min-width:0;container-type:inline-size;container-name:storage}
|
|
683
|
-
.wbi-root *{box-sizing:border-box}.wbi-root h2{font-size:18px;margin:0}.wbi-root h3{font-size:15px;margin:0}.wbi-row{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.wbi-grow{flex:1;min-width:0}.wbi-muted{color:var(--muted);font-size:12px}.wbi-root input,.wbi-root textarea,.wbi-root select{background:var(--surface);color:inherit;border:1px solid var(--line);border-radius:8px;padding:8px 10px;font:inherit;max-width:100%}.wbi-root textarea{resize:vertical;min-height:80px}.wbi-root :focus-visible{outline:2px solid var(--accent);outline-offset:2px}
|
|
725
|
+
.wbi-root{--wbi-hit-bg:color-mix(in oklab,var(--wb-hit-bg-base,var(--dsw-alias-brand-primary,#2563eb)) 18%,transparent);--wbi-hit-fg:inherit;--line:var(--wb-line,var(--dsw-alias-border-l2,#d9dfe6));--surface:var(--wb-surface,var(--dsw-alias-bg-layer-1,#fff));--muted:var(--dsw-alias-label-secondary,#64748b);--accent:var(--dsw-alias-brand-primary,#2563eb);font-size:13px;color:inherit;min-width:0;container-type:inline-size;container-name:storage}
|
|
726
|
+
.wbi-root *{box-sizing:border-box}.wbi-root h2{font-size:18px;margin:0}.wbi-root h3{font-size:15px;margin:0}.wbi-row{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.wbi-grow{flex:1;min-width:0}.wbi-muted{color:var(--muted);font-size:12px}mark.wbi-hit{background:var(--wbi-hit-bg);color:var(--wbi-hit-fg);border-radius:3px;padding:0 2px;box-decoration-break:clone;-webkit-box-decoration-break:clone}.wbi-root input,.wbi-root textarea,.wbi-root select{background:var(--surface);color:inherit;border:1px solid var(--line);border-radius:8px;padding:8px 10px;font:inherit;max-width:100%}.wbi-root textarea{resize:vertical;min-height:80px}.wbi-root :focus-visible{outline:2px solid var(--accent);outline-offset:2px}
|
|
684
727
|
.wbi-btn,.wbi-image,.wbi-root .wb-desc-toggle{border:none;background:var(--wb-btn-bg);color:inherit;min-height:var(--wb-btn-size-sm);min-width:var(--wb-btn-size-sm);border-radius:8px;padding:7px 12px;cursor:pointer;font:inherit}
|
|
685
728
|
.wbi-btn:enabled:hover,.wbi-image:enabled:hover,.wbi-root .wb-desc-toggle:enabled:hover{background:var(--wb-btn-hover-bg)}
|
|
686
729
|
.wbi-btn:enabled:active,.wbi-image:enabled:active,.wbi-root .wb-desc-toggle:enabled:active{background:var(--wb-btn-active-bg)}
|
|
@@ -705,8 +748,9 @@ var require_styles = __commonJS({
|
|
|
705
748
|
.wbi-sr{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.wbi-skeleton{margin:18px 0}.wbi-sk{height:16px;border-radius:var(--wb-radius-sm);background:color-mix(in oklab,currentColor 9%,transparent);animation:wbi-pulse 1.4s ease-in-out infinite}.wbi-sk:nth-child(2){height:48px}.wbi-sk:last-child{width:60%}@keyframes wbi-pulse{50%{opacity:.45}}
|
|
706
749
|
.wbi-cfg-group{border-radius:var(--wb-radius-card)!important}.wbi-cfg{gap:var(--wb-space-md)!important}.wbi-cfg-head h2{display:flex;gap:var(--wb-space-sm);align-items:center}
|
|
707
750
|
@container storage (max-width:480px){.wbi-toolbar{gap:8px}.wbi-toolbar input[type=search]{flex-basis:100%;min-width:0}.wbi-toolbar select{flex:1;min-width:0}.wbi-root>.wbi-row>.wbi-icon-text .wbi-btn-label,.wbi-toolbar>.wbi-icon-text .wbi-btn-label,.wbi-cfg-head>.wbi-icon-text .wbi-btn-label{display:none}.wbi-root>.wbi-row>.wbi-icon-text,.wbi-toolbar>.wbi-icon-text,.wbi-cfg-head>.wbi-icon-text{width:32px;height:32px;padding:0}}
|
|
751
|
+
.wbi-tagfilter{position:relative;display:flex;align-items:center;gap:5px;min-width:0}.wbi-tagfilter .wbi-btn.wbi-tagon{border:1px solid var(--accent);color:var(--accent);background:color-mix(in oklab,var(--accent) 12%,transparent)}.wbi-tagmenu{position:absolute;z-index:60;top:calc(100% + 6px);left:0;width:260px;max-width:min(260px,calc(100vw - 40px));max-height:320px;overflow:auto;padding:8px;border-radius:10px;border:1px solid var(--line);background:var(--surface);box-shadow:0 10px 34px #0004}.wbi-tagmenu-head{display:flex;align-items:center;gap:6px;font-size:11px;color:var(--muted);padding:2px 4px 7px}.wbi-tagsearch{padding:0 0 6px}.wbi-tagsearch input{width:100%;box-sizing:border-box;font-size:12.5px;padding:6px 9px}.wbi-tagsel{border-bottom:1px dashed var(--line);margin-bottom:6px;padding-bottom:5px}.wbi-tagsel-list{display:flex;flex-wrap:wrap;gap:4px;padding:0 2px 2px}.wbi-tagselitem{display:inline-flex;align-items:center;gap:4px;max-width:100%;border:1px solid color-mix(in oklab,var(--accent) 40%,transparent);background:color-mix(in oklab,var(--accent) 10%,transparent);color:var(--accent);border-radius:999px;padding:2px 7px;font-size:11.5px;cursor:pointer;font-family:inherit}.wbi-tagselitem .wbi-tagnm{max-width:150px}.wbi-tagnm{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}.wbi-tagx{opacity:.7;font-size:12px;line-height:1}.wbi-taglist{max-height:236px;overflow:auto;overscroll-behavior:contain}.wbi-tagopt{display:flex;align-items:center;gap:7px;padding:6px;border-radius:6px;cursor:pointer;font-size:12.5px}.wbi-tagopt:hover{background:color-mix(in oklab,currentColor 7%,transparent)}.wbi-tagopt input{margin:0;accent-color:var(--accent)}.wbi-tagmore{font-size:11px;opacity:.5;text-align:center;padding:6px 0 2px}.wbi-note{color:var(--muted);font-size:12px;padding:6px 4px}.wbi-mini{appearance:none;border:0;background:transparent;color:inherit;border-radius:4px;cursor:pointer;font-size:11.5px;line-height:1;padding:3px 5px;font-family:inherit;opacity:.7}.wbi-mini:hover{opacity:1}@container storage (max-width:480px){.wbi-toolbar{position:relative}.wbi-tagfilter{position:static}.wbi-tagmenu{left:8px;right:8px;width:auto;max-width:none;top:calc(100% + 6px)}}
|
|
708
752
|
@media(prefers-reduced-motion:reduce){.wbi-root *,.wbi-root *::after{transition:none!important;animation:none!important}.wbi-card:hover{transform:none}}
|
|
709
|
-
|
|
753
|
+
` + require_filter_checklist_styles().join("\n");
|
|
710
754
|
}
|
|
711
755
|
});
|
|
712
756
|
|
|
@@ -1675,25 +1719,92 @@ var require_editor = __commonJS({
|
|
|
1675
1719
|
};
|
|
1676
1720
|
});
|
|
1677
1721
|
var form = state[0], setForm = state[1];
|
|
1678
|
-
var err = React.useState(null), busy = React.useState(false), query = React.useState(""), options = React.useState(
|
|
1722
|
+
var err = React.useState(null), busy = React.useState(false), query = React.useState(""), options = React.useState([]), page = React.useState(0), total = React.useState(0), hasMore = React.useState(false), loading = React.useState(false), names = React.useState(function() {
|
|
1723
|
+
var map = {};
|
|
1724
|
+
(item.tags || []).forEach(function(t) {
|
|
1725
|
+
map[String(t.id)] = t.name;
|
|
1726
|
+
});
|
|
1727
|
+
return map;
|
|
1728
|
+
});
|
|
1679
1729
|
var selected = React.useState(item.tags || []);
|
|
1730
|
+
var seq = React.useRef(0);
|
|
1731
|
+
var load = React.useCallback(
|
|
1732
|
+
function(text, pageNumber, append) {
|
|
1733
|
+
var mine = ++seq.current;
|
|
1734
|
+
loading[1](true);
|
|
1735
|
+
return ui.call(props.api, "storageTags.search", { text: text || "", pageNumber, pageSize: 20 }).then(function(r) {
|
|
1736
|
+
if (mine !== seq.current) return;
|
|
1737
|
+
loading[1](false);
|
|
1738
|
+
var records = r && r.records || [];
|
|
1739
|
+
total[1](r && r.total || 0);
|
|
1740
|
+
page[1](r && r.current || pageNumber);
|
|
1741
|
+
hasMore[1]((r && r.current || pageNumber) < (r && r.pages || 0));
|
|
1742
|
+
options[1](function(prev) {
|
|
1743
|
+
var list = append ? prev.slice() : [];
|
|
1744
|
+
var seen = {};
|
|
1745
|
+
list.forEach(function(x) {
|
|
1746
|
+
seen[String(x.id)] = true;
|
|
1747
|
+
});
|
|
1748
|
+
records.forEach(function(x) {
|
|
1749
|
+
if (!seen[String(x.id)]) list.push(x);
|
|
1750
|
+
});
|
|
1751
|
+
return list;
|
|
1752
|
+
});
|
|
1753
|
+
names[1](function(prev) {
|
|
1754
|
+
var next = Object.assign({}, prev);
|
|
1755
|
+
records.forEach(function(x) {
|
|
1756
|
+
next[String(x.id)] = x.name;
|
|
1757
|
+
});
|
|
1758
|
+
return next;
|
|
1759
|
+
});
|
|
1760
|
+
}).catch(function(e) {
|
|
1761
|
+
if (mine !== seq.current) return;
|
|
1762
|
+
loading[1](false);
|
|
1763
|
+
err[1](e);
|
|
1764
|
+
});
|
|
1765
|
+
},
|
|
1766
|
+
[props.api]
|
|
1767
|
+
);
|
|
1768
|
+
React.useEffect(
|
|
1769
|
+
function() {
|
|
1770
|
+
if (!props.tagsEnabled) return void 0;
|
|
1771
|
+
var timer = setTimeout(
|
|
1772
|
+
function() {
|
|
1773
|
+
load(query[0], 1, false);
|
|
1774
|
+
},
|
|
1775
|
+
query[0] ? 200 : 0
|
|
1776
|
+
);
|
|
1777
|
+
return function() {
|
|
1778
|
+
clearTimeout(timer);
|
|
1779
|
+
};
|
|
1780
|
+
},
|
|
1781
|
+
[query[0], props.tagsEnabled, load]
|
|
1782
|
+
);
|
|
1680
1783
|
React.useEffect(
|
|
1681
1784
|
function() {
|
|
1682
|
-
if (!props.tagsEnabled) return;
|
|
1785
|
+
if (!props.tagsEnabled) return void 0;
|
|
1786
|
+
var missing = form.tagIds.filter(function(id) {
|
|
1787
|
+
return !names[0][String(id)];
|
|
1788
|
+
});
|
|
1789
|
+
if (!missing.length) return void 0;
|
|
1683
1790
|
var active = true;
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1791
|
+
ui.call(props.api, "storageTags.byIds", { ids: missing }).then(function(r) {
|
|
1792
|
+
if (!active) return;
|
|
1793
|
+
var next = {};
|
|
1794
|
+
(r && r.records || []).forEach(function(x) {
|
|
1795
|
+
next[String(x.id)] = x.name;
|
|
1796
|
+
});
|
|
1797
|
+
if (!Object.keys(next).length) return;
|
|
1798
|
+
names[1](function(prev) {
|
|
1799
|
+
return Object.assign({}, prev, next);
|
|
1689
1800
|
});
|
|
1690
|
-
}
|
|
1801
|
+
}).catch(function() {
|
|
1802
|
+
});
|
|
1691
1803
|
return function() {
|
|
1692
1804
|
active = false;
|
|
1693
|
-
clearTimeout(timer);
|
|
1694
1805
|
};
|
|
1695
1806
|
},
|
|
1696
|
-
[
|
|
1807
|
+
[props.api, props.tagsEnabled, form.tagIds.join(",")]
|
|
1697
1808
|
);
|
|
1698
1809
|
function update(k, v) {
|
|
1699
1810
|
setForm(function(f) {
|
|
@@ -1755,6 +1866,12 @@ var require_editor = __commonJS({
|
|
|
1755
1866
|
selected[0].concat(options[0]).forEach(function(t) {
|
|
1756
1867
|
candidates.set(t.id, t);
|
|
1757
1868
|
});
|
|
1869
|
+
function onListScroll(e) {
|
|
1870
|
+
var el = e.currentTarget;
|
|
1871
|
+
if (!hasMore[0] || loading[0]) return;
|
|
1872
|
+
if (el.scrollTop + el.clientHeight >= el.scrollHeight - 24) load(query[0], (page[0] || 1) + 1, true);
|
|
1873
|
+
}
|
|
1874
|
+
var tagsNote = loading[0] ? tr(lang, "\u52A0\u8F7D\u4E2D\u2026", "Loading\u2026") : !candidates.size ? query[0] ? tr(lang, "\u6CA1\u6709\u5339\u914D\u7684\u6807\u7B7E", "No matching tags") : tr(lang, "\u6682\u65E0\u6807\u7B7E\uFF0C\u53EF\u5728\u6807\u7B7E\u63D2\u4EF6\u4E2D\u521B\u5EFA", "No tags. Create them in the Tags plugin.") : hasMore[0] ? "" : tr(lang, "\u6CA1\u6709\u66F4\u591A", "No more");
|
|
1758
1875
|
return h2(
|
|
1759
1876
|
ui.Modal,
|
|
1760
1877
|
{
|
|
@@ -1794,7 +1911,7 @@ var require_editor = __commonJS({
|
|
|
1794
1911
|
}),
|
|
1795
1912
|
h2(
|
|
1796
1913
|
"div",
|
|
1797
|
-
{ className: "wbi-tagoptions" },
|
|
1914
|
+
{ className: "wbi-tagoptions", onScroll: onListScroll },
|
|
1798
1915
|
Array.from(candidates.values()).map(function(t) {
|
|
1799
1916
|
return h2(
|
|
1800
1917
|
"label",
|
|
@@ -1820,15 +1937,11 @@ var require_editor = __commonJS({
|
|
|
1820
1937
|
});
|
|
1821
1938
|
}
|
|
1822
1939
|
}),
|
|
1823
|
-
t.name
|
|
1940
|
+
names[0][String(t.id)] || t.name
|
|
1824
1941
|
);
|
|
1825
1942
|
})
|
|
1826
1943
|
),
|
|
1827
|
-
|
|
1828
|
-
"span",
|
|
1829
|
-
{ className: "wbi-muted" },
|
|
1830
|
-
tr(lang, "\u6682\u65E0\u6807\u7B7E\uFF0C\u53EF\u5728\u6807\u7B7E\u63D2\u4EF6\u4E2D\u521B\u5EFA", "No tags. Create them in the Tags plugin.")
|
|
1831
|
-
) : null
|
|
1944
|
+
h2("div", { className: "wbi-tagmore" }, tagsNote)
|
|
1832
1945
|
) : h2(
|
|
1833
1946
|
"span",
|
|
1834
1947
|
{ className: "wbi-muted" },
|
|
@@ -1853,6 +1966,60 @@ var require_editor = __commonJS({
|
|
|
1853
1966
|
}
|
|
1854
1967
|
});
|
|
1855
1968
|
|
|
1969
|
+
// packages/addons/lib/highlight.cjs
|
|
1970
|
+
var require_highlight = __commonJS({
|
|
1971
|
+
"packages/addons/lib/highlight.cjs"(exports2, module2) {
|
|
1972
|
+
"use strict";
|
|
1973
|
+
module2.exports = function(React) {
|
|
1974
|
+
var h2 = React.createElement;
|
|
1975
|
+
function sourceOf(keyword) {
|
|
1976
|
+
var pattern = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1977
|
+
return pattern.replace(/[a-zA-Z]/g, function(letter) {
|
|
1978
|
+
return "[" + letter.toLowerCase() + letter.toUpperCase() + "]";
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
return function createHighlight(prefix) {
|
|
1982
|
+
var className = String(prefix || "wb") + "-hit";
|
|
1983
|
+
function hit(rawText, rawKeyword) {
|
|
1984
|
+
var text = rawText == null ? "" : String(rawText);
|
|
1985
|
+
var keyword = rawKeyword == null ? "" : String(rawKeyword);
|
|
1986
|
+
if (!keyword) return text;
|
|
1987
|
+
var matcher, match, end = 0, parts = [];
|
|
1988
|
+
try {
|
|
1989
|
+
matcher = new RegExp(sourceOf(keyword), "g");
|
|
1990
|
+
} catch (error) {
|
|
1991
|
+
return text;
|
|
1992
|
+
}
|
|
1993
|
+
while (match = matcher.exec(text)) {
|
|
1994
|
+
if (match.index > end) parts.push(text.slice(end, match.index));
|
|
1995
|
+
parts.push(h2("mark", { className, key: match.index }, match[0]));
|
|
1996
|
+
end = match.index + match[0].length;
|
|
1997
|
+
if (!match[0]) matcher.lastIndex += 1;
|
|
1998
|
+
}
|
|
1999
|
+
if (!parts.length) return text;
|
|
2000
|
+
if (end < text.length) parts.push(text.slice(end));
|
|
2001
|
+
return parts;
|
|
2002
|
+
}
|
|
2003
|
+
function Highlight(props) {
|
|
2004
|
+
return hit(props.text, props.keyword);
|
|
2005
|
+
}
|
|
2006
|
+
Highlight.hit = hit;
|
|
2007
|
+
return Highlight;
|
|
2008
|
+
};
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
});
|
|
2012
|
+
|
|
2013
|
+
// packages/addons/storage/client/ui/highlight.cjs
|
|
2014
|
+
var require_highlight2 = __commonJS({
|
|
2015
|
+
"packages/addons/storage/client/ui/highlight.cjs"(exports2, module2) {
|
|
2016
|
+
"use strict";
|
|
2017
|
+
module2.exports = function(React) {
|
|
2018
|
+
return require_highlight()(React)("wbi");
|
|
2019
|
+
};
|
|
2020
|
+
}
|
|
2021
|
+
});
|
|
2022
|
+
|
|
1856
2023
|
// packages/addons/storage/client/item/card.cjs
|
|
1857
2024
|
var require_card = __commonJS({
|
|
1858
2025
|
"packages/addons/storage/client/item/card.cjs"(exports2, module2) {
|
|
@@ -1861,8 +2028,10 @@ var require_card = __commonJS({
|
|
|
1861
2028
|
var h2 = ui.h;
|
|
1862
2029
|
var tr = ui.tr;
|
|
1863
2030
|
var Description = require_description().Description;
|
|
2031
|
+
var Highlight = require_highlight2()(React);
|
|
1864
2032
|
function StorageCard(props) {
|
|
1865
2033
|
var item = props.item, lang = props.lang, gallery = React.useState(false);
|
|
2034
|
+
var keyword = String(props.keyword || "");
|
|
1866
2035
|
var images = (item.imgList || []).filter(ui.safeImage), tags = item.tags || [];
|
|
1867
2036
|
var shown = gallery[0] ? images : images.slice(0, 1);
|
|
1868
2037
|
var hasStock = item.stock != null && item.stock !== "";
|
|
@@ -1898,7 +2067,7 @@ var require_card = __commonJS({
|
|
|
1898
2067
|
h2(
|
|
1899
2068
|
"div",
|
|
1900
2069
|
{ className: "wbi-cardhead" },
|
|
1901
|
-
h2("h3", null, item.name),
|
|
2070
|
+
h2("h3", null, h2(Highlight, { text: item.name, keyword })),
|
|
1902
2071
|
h2(
|
|
1903
2072
|
"span",
|
|
1904
2073
|
{ className: "wbi-stock" },
|
|
@@ -1925,9 +2094,10 @@ var require_card = __commonJS({
|
|
|
1925
2094
|
meta.length ? h2(
|
|
1926
2095
|
"div",
|
|
1927
2096
|
{ className: "wbi-muted" },
|
|
1928
|
-
item.brand ? h2("span", { className: "wbi-inline" }, h2(ui.Icon, { name: "brand", size: 11 }),
|
|
2097
|
+
item.brand ? h2("span", { className: "wbi-inline" }, h2(ui.Icon, { name: "brand", size: 11 }), tr(lang, "\u54C1\u724C\uFF1A", "Brand: "), h2(Highlight, { text: item.brand, keyword })) : null,
|
|
2098
|
+
// 单位不参与文字搜索,按原样展示,避免「亮了却搜不到」的错觉。
|
|
1929
2099
|
item.unit ? h2("span", { className: "wbi-inline" }, h2(ui.Icon, { name: "unit", size: 11 }), tr(lang, "\u5355\u4F4D\uFF1A", "Unit: ") + item.unit) : null,
|
|
1930
|
-
item.location ? h2("span", { className: "wbi-inline" }, h2(ui.Icon, { name: "location", size: 11 }), tr(lang, "\u4F4D\u7F6E\uFF1A", "Location: ")
|
|
2100
|
+
item.location ? h2("span", { className: "wbi-inline" }, h2(ui.Icon, { name: "location", size: 11 }), tr(lang, "\u4F4D\u7F6E\uFF1A", "Location: "), h2(Highlight, { text: item.location, keyword })) : null
|
|
1931
2101
|
) : null,
|
|
1932
2102
|
item.createTime || item.updateTime ? h2(
|
|
1933
2103
|
"div",
|
|
@@ -1936,7 +2106,7 @@ var require_card = __commonJS({
|
|
|
1936
2106
|
item.updateTime ? h2("span", null, tr(lang, "\u66F4\u65B0 ", "Updated ") + props.date(item.updateTime)) : null
|
|
1937
2107
|
) : null
|
|
1938
2108
|
) : null,
|
|
1939
|
-
h2(Description, { text: item.remark, lang, bodyMode: props.bodyMode }),
|
|
2109
|
+
h2(Description, { text: item.remark, lang, bodyMode: props.bodyMode, Highlight, keyword }),
|
|
1940
2110
|
images.length ? h2("div", { className: "wbi-images" }, shown.map(function(url, i) {
|
|
1941
2111
|
return h2(
|
|
1942
2112
|
"button",
|
|
@@ -1991,6 +2161,333 @@ var require_card = __commonJS({
|
|
|
1991
2161
|
}
|
|
1992
2162
|
});
|
|
1993
2163
|
|
|
2164
|
+
// packages/addons/lib/filter-checklist.cjs
|
|
2165
|
+
var require_filter_checklist = __commonJS({
|
|
2166
|
+
"packages/addons/lib/filter-checklist.cjs"(exports2, module2) {
|
|
2167
|
+
"use strict";
|
|
2168
|
+
var React = require("react");
|
|
2169
|
+
var h2 = React.createElement;
|
|
2170
|
+
var NEAR = 24;
|
|
2171
|
+
function nearBottom(el, threshold) {
|
|
2172
|
+
if (!el) return false;
|
|
2173
|
+
var gap = Number(threshold);
|
|
2174
|
+
if (!isFinite(gap) || gap < 0) gap = NEAR;
|
|
2175
|
+
return el.scrollTop + el.clientHeight >= el.scrollHeight - gap;
|
|
2176
|
+
}
|
|
2177
|
+
function FilterChecklist(props) {
|
|
2178
|
+
var items = props.items || [];
|
|
2179
|
+
var selected = props.selected || [];
|
|
2180
|
+
var disabled = props.disabled === true;
|
|
2181
|
+
var loading = props.loading === true;
|
|
2182
|
+
var hasMore = props.hasMore === true;
|
|
2183
|
+
var query = props.query || "";
|
|
2184
|
+
var total = typeof props.total === "number" ? props.total : items.length;
|
|
2185
|
+
var title = props.title || "\u5168\u90E8";
|
|
2186
|
+
var selectedText = props.selectedText || "\u5DF2\u9009";
|
|
2187
|
+
var clearText = props.clearText || "\u6E05\u7A7A";
|
|
2188
|
+
var searchPlaceholder = props.searchPlaceholder || "\u641C\u7D22";
|
|
2189
|
+
var emptyText = props.emptyText || "\u6682\u65E0\u6570\u636E";
|
|
2190
|
+
var noMatchText = props.noMatchText || "\u6CA1\u6709\u5339\u914D\u9879";
|
|
2191
|
+
var loadingText = props.loadingText || "\u52A0\u8F7D\u4E2D\u2026";
|
|
2192
|
+
var noMoreText = typeof props.noMoreText === "string" ? props.noMoreText : "\u6CA1\u6709\u66F4\u591A";
|
|
2193
|
+
var onToggle = props.onToggle || function() {
|
|
2194
|
+
};
|
|
2195
|
+
var onQuery = props.onQuery || function() {
|
|
2196
|
+
};
|
|
2197
|
+
var onLoadMore = props.onLoadMore;
|
|
2198
|
+
var onClear = props.onClear || function() {
|
|
2199
|
+
};
|
|
2200
|
+
var single = props.mode === "single";
|
|
2201
|
+
var onPick = typeof props.onPick === "function" ? props.onPick : onToggle;
|
|
2202
|
+
function toggle(id) {
|
|
2203
|
+
if (disabled) return;
|
|
2204
|
+
onToggle(id);
|
|
2205
|
+
}
|
|
2206
|
+
function scroll(e) {
|
|
2207
|
+
if (disabled || loading || !hasMore || !onLoadMore) return;
|
|
2208
|
+
if (nearBottom(e.currentTarget)) onLoadMore();
|
|
2209
|
+
}
|
|
2210
|
+
var head = h2(
|
|
2211
|
+
"div",
|
|
2212
|
+
{ className: "wbck-head" },
|
|
2213
|
+
h2("span", { className: "wbck-grow" }, title + (total ? " \xB7 " + total : "")),
|
|
2214
|
+
!single && selected.length ? h2("span", { className: "wbck-sel" }, selectedText + " " + selected.length) : null,
|
|
2215
|
+
!single && (selected.length || query) ? h2("button", {
|
|
2216
|
+
type: "button",
|
|
2217
|
+
className: "wbck-clear",
|
|
2218
|
+
title: clearText,
|
|
2219
|
+
disabled,
|
|
2220
|
+
onClick: function() {
|
|
2221
|
+
if (disabled) return;
|
|
2222
|
+
onClear();
|
|
2223
|
+
}
|
|
2224
|
+
}, clearText) : null
|
|
2225
|
+
);
|
|
2226
|
+
var body;
|
|
2227
|
+
if (!items.length) {
|
|
2228
|
+
body = h2("div", { className: "wbck-note", role: "status" }, loading ? loadingText : query ? noMatchText : emptyText);
|
|
2229
|
+
} else {
|
|
2230
|
+
body = items.map(function(x) {
|
|
2231
|
+
var on = selected.indexOf(String(x.id)) >= 0;
|
|
2232
|
+
if (single) {
|
|
2233
|
+
return h2(
|
|
2234
|
+
"button",
|
|
2235
|
+
{
|
|
2236
|
+
key: x.id,
|
|
2237
|
+
type: "button",
|
|
2238
|
+
role: "radio",
|
|
2239
|
+
"aria-checked": on ? "true" : "false",
|
|
2240
|
+
className: "wbck-opt" + (on ? " is-on" : ""),
|
|
2241
|
+
disabled,
|
|
2242
|
+
onClick: function() {
|
|
2243
|
+
if (disabled) return;
|
|
2244
|
+
onPick(x.id);
|
|
2245
|
+
}
|
|
2246
|
+
},
|
|
2247
|
+
h2("span", { className: "wbck-nm", title: x.name }, x.name),
|
|
2248
|
+
x.meta ? h2("span", { className: "wbck-meta" }, x.meta) : null
|
|
2249
|
+
);
|
|
2250
|
+
}
|
|
2251
|
+
return h2(
|
|
2252
|
+
"label",
|
|
2253
|
+
{ key: x.id, className: "wbck-opt" + (on ? " is-on" : "") },
|
|
2254
|
+
h2("input", {
|
|
2255
|
+
type: "checkbox",
|
|
2256
|
+
checked: on,
|
|
2257
|
+
disabled,
|
|
2258
|
+
onChange: function() {
|
|
2259
|
+
toggle(x.id);
|
|
2260
|
+
}
|
|
2261
|
+
}),
|
|
2262
|
+
h2("span", { className: "wbck-nm", title: x.name }, x.name),
|
|
2263
|
+
x.meta ? h2("span", { className: "wbck-meta" }, x.meta) : null
|
|
2264
|
+
);
|
|
2265
|
+
});
|
|
2266
|
+
var more = loading ? loadingText : hasMore ? "" : noMoreText;
|
|
2267
|
+
if (more) body = body.concat([h2("div", { key: "__more", className: "wbck-more", role: "status" }, more)]);
|
|
2268
|
+
}
|
|
2269
|
+
return h2(
|
|
2270
|
+
"div",
|
|
2271
|
+
{ className: "wbck", "data-role": "checklist" },
|
|
2272
|
+
h2(
|
|
2273
|
+
"div",
|
|
2274
|
+
{ className: "wbck-search" },
|
|
2275
|
+
h2("input", {
|
|
2276
|
+
type: "search",
|
|
2277
|
+
autoFocus: props.autoFocus !== false,
|
|
2278
|
+
className: "wbck-input",
|
|
2279
|
+
placeholder: searchPlaceholder,
|
|
2280
|
+
"aria-label": searchPlaceholder,
|
|
2281
|
+
value: query,
|
|
2282
|
+
disabled,
|
|
2283
|
+
onChange: function(e) {
|
|
2284
|
+
onQuery(e.target.value);
|
|
2285
|
+
}
|
|
2286
|
+
})
|
|
2287
|
+
),
|
|
2288
|
+
props.beforeHead || null,
|
|
2289
|
+
head,
|
|
2290
|
+
h2("div", {
|
|
2291
|
+
className: "wbck-list",
|
|
2292
|
+
onScroll: scroll,
|
|
2293
|
+
role: single ? "radiogroup" : void 0,
|
|
2294
|
+
"aria-label": single ? props.groupLabel || searchPlaceholder : void 0,
|
|
2295
|
+
"aria-busy": loading ? "true" : "false"
|
|
2296
|
+
}, body)
|
|
2297
|
+
);
|
|
2298
|
+
}
|
|
2299
|
+
module2.exports = FilterChecklist;
|
|
2300
|
+
module2.exports.nearBottom = nearBottom;
|
|
2301
|
+
}
|
|
2302
|
+
});
|
|
2303
|
+
|
|
2304
|
+
// packages/addons/storage/client/ui/tagfilter.cjs
|
|
2305
|
+
var require_tagfilter = __commonJS({
|
|
2306
|
+
"packages/addons/storage/client/ui/tagfilter.cjs"(exports2, module2) {
|
|
2307
|
+
var React = require("react");
|
|
2308
|
+
var ui = require_ui();
|
|
2309
|
+
var FilterChecklist = require_filter_checklist();
|
|
2310
|
+
var h2 = React.createElement;
|
|
2311
|
+
var tr = ui.tr;
|
|
2312
|
+
module2.exports = function TagFilter(props) {
|
|
2313
|
+
var api = props.api, lang = props.lang, enabled = props.enabled !== false, ids = props.ids || [], onChange = props.onChange;
|
|
2314
|
+
var openS = React.useState(false), open = openS[0], setOpen = openS[1];
|
|
2315
|
+
var queryS = React.useState(""), query = queryS[0], setQuery = queryS[1];
|
|
2316
|
+
var optsS = React.useState({ tags: [], total: 0, pageNumber: 0, hasMore: false }), opts = optsS[0], setOpts = optsS[1];
|
|
2317
|
+
var loadingS = React.useState(false), loading = loadingS[0], setLoading = loadingS[1];
|
|
2318
|
+
var namesS = React.useState({}), names = namesS[0], setNames = namesS[1];
|
|
2319
|
+
var seq = React.useRef(0);
|
|
2320
|
+
var load = React.useCallback(
|
|
2321
|
+
function(text, pageNumber, append) {
|
|
2322
|
+
var mine = ++seq.current;
|
|
2323
|
+
setLoading(true);
|
|
2324
|
+
return api.call("storageTags.search", { text: text || "", pageNumber, pageSize: 20 }).then(function(r) {
|
|
2325
|
+
if (mine !== seq.current) return;
|
|
2326
|
+
setLoading(false);
|
|
2327
|
+
if (!r || !r.ok) return;
|
|
2328
|
+
var out = r.result || {}, records = out.records || [], current = out.current || pageNumber, pages = out.pages || 0;
|
|
2329
|
+
setOpts(function(prev) {
|
|
2330
|
+
var list = append ? (prev.tags || []).slice() : [];
|
|
2331
|
+
var seen = {};
|
|
2332
|
+
list.forEach(function(x) {
|
|
2333
|
+
seen[String(x.id)] = true;
|
|
2334
|
+
});
|
|
2335
|
+
records.forEach(function(x) {
|
|
2336
|
+
if (!seen[String(x.id)]) list.push(x);
|
|
2337
|
+
});
|
|
2338
|
+
return { tags: list, total: out.total || 0, pageNumber: current, hasMore: current < pages };
|
|
2339
|
+
});
|
|
2340
|
+
setNames(function(prev) {
|
|
2341
|
+
var next = Object.assign({}, prev);
|
|
2342
|
+
records.forEach(function(x) {
|
|
2343
|
+
next[String(x.id)] = x.name;
|
|
2344
|
+
});
|
|
2345
|
+
return next;
|
|
2346
|
+
});
|
|
2347
|
+
}).catch(function() {
|
|
2348
|
+
if (mine === seq.current) setLoading(false);
|
|
2349
|
+
});
|
|
2350
|
+
},
|
|
2351
|
+
[api]
|
|
2352
|
+
);
|
|
2353
|
+
React.useEffect(
|
|
2354
|
+
function() {
|
|
2355
|
+
if (!open) return void 0;
|
|
2356
|
+
var timer = setTimeout(
|
|
2357
|
+
function() {
|
|
2358
|
+
load(query, 1, false);
|
|
2359
|
+
},
|
|
2360
|
+
query ? 200 : 0
|
|
2361
|
+
);
|
|
2362
|
+
return function() {
|
|
2363
|
+
clearTimeout(timer);
|
|
2364
|
+
};
|
|
2365
|
+
},
|
|
2366
|
+
[open, query, load, props.reloadKey]
|
|
2367
|
+
);
|
|
2368
|
+
React.useEffect(
|
|
2369
|
+
function() {
|
|
2370
|
+
if (!open || !ids.length) return;
|
|
2371
|
+
var wanted = ids.filter(function(id) {
|
|
2372
|
+
return !names[String(id)];
|
|
2373
|
+
});
|
|
2374
|
+
if (!wanted.length) return;
|
|
2375
|
+
api.call("storageTags.byIds", { ids: wanted }).then(function(r) {
|
|
2376
|
+
if (!r || !r.ok) return;
|
|
2377
|
+
var next = {};
|
|
2378
|
+
(r.result && r.result.records || []).forEach(function(x) {
|
|
2379
|
+
next[String(x.id)] = x.name;
|
|
2380
|
+
});
|
|
2381
|
+
if (!Object.keys(next).length) return;
|
|
2382
|
+
setNames(function(prev) {
|
|
2383
|
+
return Object.assign({}, prev, next);
|
|
2384
|
+
});
|
|
2385
|
+
}).catch(function() {
|
|
2386
|
+
});
|
|
2387
|
+
},
|
|
2388
|
+
[open, ids.join(",")]
|
|
2389
|
+
);
|
|
2390
|
+
React.useEffect(
|
|
2391
|
+
function() {
|
|
2392
|
+
if (!open) return void 0;
|
|
2393
|
+
function onKey(e) {
|
|
2394
|
+
if (e.key === "Escape") setOpen(false);
|
|
2395
|
+
}
|
|
2396
|
+
document.addEventListener("keydown", onKey);
|
|
2397
|
+
return function() {
|
|
2398
|
+
document.removeEventListener("keydown", onKey);
|
|
2399
|
+
};
|
|
2400
|
+
},
|
|
2401
|
+
[open]
|
|
2402
|
+
);
|
|
2403
|
+
function toggle(id) {
|
|
2404
|
+
var key = String(id), next = ids.slice(), i = next.indexOf(key);
|
|
2405
|
+
if (i >= 0) next.splice(i, 1);
|
|
2406
|
+
else next.push(key);
|
|
2407
|
+
onChange(next);
|
|
2408
|
+
}
|
|
2409
|
+
if (!enabled) return null;
|
|
2410
|
+
return h2(
|
|
2411
|
+
"div",
|
|
2412
|
+
{ className: "wbi-tagfilter" },
|
|
2413
|
+
h2(
|
|
2414
|
+
"button",
|
|
2415
|
+
{
|
|
2416
|
+
type: "button",
|
|
2417
|
+
className: "wbi-btn" + (ids.length ? " wbi-tagon" : ""),
|
|
2418
|
+
"aria-expanded": open ? "true" : "false",
|
|
2419
|
+
onClick: function(e) {
|
|
2420
|
+
e.stopPropagation();
|
|
2421
|
+
setOpen(!open);
|
|
2422
|
+
}
|
|
2423
|
+
},
|
|
2424
|
+
h2(ui.Icon, { name: "tag", size: 13 }),
|
|
2425
|
+
tr(lang, "\u6807\u7B7E\u7B5B\u9009", "Tag filter") + (ids.length ? " \xB7 " + ids.length : ""),
|
|
2426
|
+
"\u25BE"
|
|
2427
|
+
),
|
|
2428
|
+
open ? h2(
|
|
2429
|
+
"div",
|
|
2430
|
+
{ className: "wbi-tagmenu", role: "menu", onClick: function(e) {
|
|
2431
|
+
e.stopPropagation();
|
|
2432
|
+
} },
|
|
2433
|
+
h2(FilterChecklist, {
|
|
2434
|
+
beforeHead: ids.length ? h2(
|
|
2435
|
+
"div",
|
|
2436
|
+
{ className: "wbi-tagsel" },
|
|
2437
|
+
h2("div", { className: "wbi-tagmenu-head" }, h2("span", null, tr(lang, "\u5DF2\u9009", "Selected") + " " + ids.length)),
|
|
2438
|
+
h2(
|
|
2439
|
+
"div",
|
|
2440
|
+
{ className: "wbi-tagsel-list" },
|
|
2441
|
+
ids.map(function(id) {
|
|
2442
|
+
return h2(
|
|
2443
|
+
"button",
|
|
2444
|
+
{
|
|
2445
|
+
key: id,
|
|
2446
|
+
type: "button",
|
|
2447
|
+
className: "wbi-tagselitem",
|
|
2448
|
+
title: tr(lang, "\u79FB\u9664", "Remove"),
|
|
2449
|
+
onClick: function() {
|
|
2450
|
+
toggle(id);
|
|
2451
|
+
}
|
|
2452
|
+
},
|
|
2453
|
+
h2("span", { className: "wbi-tagnm" }, names[String(id)] || "#" + id),
|
|
2454
|
+
h2("span", { className: "wbi-tagx" }, "\xD7")
|
|
2455
|
+
);
|
|
2456
|
+
})
|
|
2457
|
+
)
|
|
2458
|
+
) : null,
|
|
2459
|
+
items: opts.tags.map(function(x) {
|
|
2460
|
+
return { id: x.id, name: x.name };
|
|
2461
|
+
}),
|
|
2462
|
+
selected: ids,
|
|
2463
|
+
onToggle: toggle,
|
|
2464
|
+
query,
|
|
2465
|
+
onQuery: setQuery,
|
|
2466
|
+
title: tr(lang, "\u5168\u90E8\u6807\u7B7E", "All tags"),
|
|
2467
|
+
total: opts.total,
|
|
2468
|
+
selectedText: tr(lang, "\u5DF2\u9009", "Selected"),
|
|
2469
|
+
clearText: tr(lang, "\u6E05\u7A7A", "Clear"),
|
|
2470
|
+
onClear: function() {
|
|
2471
|
+
onChange([]);
|
|
2472
|
+
setQuery("");
|
|
2473
|
+
},
|
|
2474
|
+
searchPlaceholder: tr(lang, "\u641C\u7D22\u6807\u7B7E\u540D\u79F0", "Search tag names"),
|
|
2475
|
+
loading,
|
|
2476
|
+
hasMore: opts.hasMore,
|
|
2477
|
+
onLoadMore: function() {
|
|
2478
|
+
load(query, (opts.pageNumber || 1) + 1, true);
|
|
2479
|
+
},
|
|
2480
|
+
emptyText: tr(lang, "\u6682\u65E0\u6807\u7B7E", "No tags yet"),
|
|
2481
|
+
noMatchText: tr(lang, "\u6CA1\u6709\u5339\u914D\u7684\u6807\u7B7E", "No matching tags"),
|
|
2482
|
+
loadingText: tr(lang, "\u52A0\u8F7D\u4E2D\u2026", "Loading\u2026"),
|
|
2483
|
+
noMoreText: tr(lang, "\u6CA1\u6709\u66F4\u591A", "No more")
|
|
2484
|
+
})
|
|
2485
|
+
) : null
|
|
2486
|
+
);
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
});
|
|
2490
|
+
|
|
1994
2491
|
// packages/addons/storage/client/ui/selection.cjs
|
|
1995
2492
|
var require_selection = __commonJS({
|
|
1996
2493
|
"packages/addons/storage/client/ui/selection.cjs"(exports2, module2) {
|
|
@@ -2101,11 +2598,12 @@ var require_records = __commonJS({
|
|
|
2101
2598
|
var h2 = ui.h;
|
|
2102
2599
|
var tr = ui.tr;
|
|
2103
2600
|
var StorageCard = require_card().StorageCard;
|
|
2601
|
+
var TagFilter = require_tagfilter();
|
|
2104
2602
|
var selection = require_selection();
|
|
2105
2603
|
function Records(props) {
|
|
2106
2604
|
var api = props.api, lang = props.lang;
|
|
2107
|
-
var items = React.useState(null), error = React.useState(null), loading = React.useState(true), query = React.useState(""), text = React.useState(""), page = React.useState(1), size = React.useState(12), sort = React.useState("update_time"), order = React.useState("desc"), tick = React.useState(0), editing = React.useState(null), deleting = React.useState(null), preview = React.useState(null), busy = React.useState(false), caps = React.useState(false), ready = React.useState(false), confirmDelete = React.useState(true),
|
|
2108
|
-
var scope = JSON.stringify([query[0], text[0], page[0], size[0], sort[0], order[0],
|
|
2605
|
+
var items = React.useState(null), error = React.useState(null), loading = React.useState(true), query = React.useState(""), text = React.useState(""), page = React.useState(1), size = React.useState(12), sort = React.useState("update_time"), order = React.useState("desc"), tick = React.useState(0), editing = React.useState(null), deleting = React.useState(null), preview = React.useState(null), busy = React.useState(false), caps = React.useState(false), ready = React.useState(false), confirmDelete = React.useState(true), tagIds = React.useState([]), bulk = React.useState(null), bulkError = React.useState(null), notice = React.useState(""), pending = React.useRef(false), bodyMode = React.useState("markdown");
|
|
2606
|
+
var scope = JSON.stringify([query[0], text[0], page[0], size[0], sort[0], order[0], tagIds[0].join(","), tick[0]]);
|
|
2109
2607
|
var rows = items[0] && items[0].scope === scope ? items[0].records : [];
|
|
2110
2608
|
var selected = selection.useSelection(scope, rows, busy[0] || !!bulk[0]);
|
|
2111
2609
|
function deleteSelected() {
|
|
@@ -2167,7 +2665,7 @@ var require_records = __commonJS({
|
|
|
2167
2665
|
loading[1](true);
|
|
2168
2666
|
error[1](null);
|
|
2169
2667
|
var args = { text: text[0], pageNumber: page[0], pageSize: size[0], sortColumn: sort[0], sortOrder: order[0] };
|
|
2170
|
-
if (
|
|
2668
|
+
if (tagIds[0].length) args.tagIds = tagIds[0];
|
|
2171
2669
|
ui.call(api, "storage.list", args).then(function(r) {
|
|
2172
2670
|
if (!active) return;
|
|
2173
2671
|
if (page[0] > Math.max(1, r.pages || 1)) {
|
|
@@ -2276,23 +2774,19 @@ var require_records = __commonJS({
|
|
|
2276
2774
|
},
|
|
2277
2775
|
order[0] === "desc" ? tr(lang, "\u964D\u5E8F \u2193", "Descending \u2193") : tr(lang, "\u5347\u5E8F \u2191", "Ascending \u2191")
|
|
2278
2776
|
),
|
|
2279
|
-
h2(ui.Button, { icon: "refresh", onClick: refresh, disabled: loading[0] }, tr(lang, "\u5237\u65B0", "Refresh"))
|
|
2777
|
+
h2(ui.Button, { icon: "refresh", onClick: refresh, disabled: loading[0] }, tr(lang, "\u5237\u65B0", "Refresh")),
|
|
2778
|
+
h2(TagFilter, {
|
|
2779
|
+
api,
|
|
2780
|
+
lang,
|
|
2781
|
+
enabled: caps[0],
|
|
2782
|
+
ids: tagIds[0],
|
|
2783
|
+
reloadKey: tick[0],
|
|
2784
|
+
onChange: function(next) {
|
|
2785
|
+
tagIds[1](next);
|
|
2786
|
+
page[1](1);
|
|
2787
|
+
}
|
|
2788
|
+
})
|
|
2280
2789
|
),
|
|
2281
|
-
tag[0] ? h2(
|
|
2282
|
-
"div",
|
|
2283
|
-
{ className: "wbi-row" },
|
|
2284
|
-
h2("span", { className: "wbi-chip" }, tag[0].name),
|
|
2285
|
-
h2(
|
|
2286
|
-
ui.Button,
|
|
2287
|
-
{
|
|
2288
|
-
onClick: function() {
|
|
2289
|
-
tag[1](null);
|
|
2290
|
-
page[1](1);
|
|
2291
|
-
}
|
|
2292
|
-
},
|
|
2293
|
-
tr(lang, "\u6E05\u9664\u6807\u7B7E\u7B5B\u9009", "Clear tag filter")
|
|
2294
|
-
)
|
|
2295
|
-
) : null,
|
|
2296
2790
|
selected.mode ? h2("p", { className: "wbi-muted" }, tr(
|
|
2297
2791
|
lang,
|
|
2298
2792
|
"\u4EC5\u9009\u62E9\u5F53\u524D\u9875\uFF1B\u641C\u7D22\u3001\u7B5B\u9009\u3001\u6392\u5E8F\u3001\u7FFB\u9875\u6216\u5237\u65B0\u4F1A\u6E05\u7A7A\u9009\u62E9\u3002Shift+\u70B9\u51FB\u8FDE\u9009\uFF0CEsc\u9000\u51FA\u3002",
|
|
@@ -2305,7 +2799,7 @@ var require_records = __commonJS({
|
|
|
2305
2799
|
"div",
|
|
2306
2800
|
{ className: "wbi-empty" },
|
|
2307
2801
|
h2(ui.Icon, { name: "empty", size: 48 }),
|
|
2308
|
-
text[0] ||
|
|
2802
|
+
text[0] || tagIds[0].length ? tr(lang, "\u6CA1\u6709\u5339\u914D\u7684\u7269\u54C1\uFF0C\u8BD5\u8BD5\u5176\u4ED6\u641C\u7D22\u6761\u4EF6", "No matching items. Try another filter.") : tr(lang, "\u8FD8\u6CA1\u6709\u7269\u54C1\uFF0C\u70B9\u51FB\u201C\u65B0\u589E\u7269\u54C1\u201D\u5F00\u59CB\u8BB0\u5F55", "No items yet. Add your first item.")
|
|
2309
2803
|
) : null,
|
|
2310
2804
|
h2(
|
|
2311
2805
|
"div",
|
|
@@ -2319,11 +2813,12 @@ var require_records = __commonJS({
|
|
|
2319
2813
|
caps: caps[0],
|
|
2320
2814
|
busy: busy[0] || !!bulk[0],
|
|
2321
2815
|
date,
|
|
2816
|
+
keyword: String(text[0] || "").trim(),
|
|
2322
2817
|
selectionMode: selected.mode,
|
|
2323
2818
|
checked: selected.ids.includes(item.id),
|
|
2324
2819
|
onCheck: selected.toggle,
|
|
2325
2820
|
onTag: function(t) {
|
|
2326
|
-
|
|
2821
|
+
tagIds[1]([String(t.id)]);
|
|
2327
2822
|
page[1](1);
|
|
2328
2823
|
},
|
|
2329
2824
|
onPreview: preview[1],
|
|
@@ -3448,7 +3943,9 @@ var require_data_view = __commonJS({
|
|
|
3448
3943
|
}
|
|
3449
3944
|
function loadTables() {
|
|
3450
3945
|
setLoadingTables(true);
|
|
3451
|
-
Promise.resolve(
|
|
3946
|
+
Promise.resolve((options.tablesLoader || function(a) {
|
|
3947
|
+
return a.call(DOMAIN + ".dataTables");
|
|
3948
|
+
})(api)).then(function(r) {
|
|
3452
3949
|
if (r && r.ok === false) throw new Error(r && r.error || t.loadFail);
|
|
3453
3950
|
var body = unwrap(r);
|
|
3454
3951
|
if (!body || !Array.isArray(body.tables)) throw new Error(t.loadFail);
|
|
@@ -3513,7 +4010,9 @@ var require_data_view = __commonJS({
|
|
|
3513
4010
|
if (sort) args.sort = sort;
|
|
3514
4011
|
if (search) args.search = search;
|
|
3515
4012
|
if (Object.keys(filters).length) args.filters = filters;
|
|
3516
|
-
Promise.resolve(
|
|
4013
|
+
Promise.resolve((options.query || function(a, q) {
|
|
4014
|
+
return a.call(DOMAIN + ".dataQuery", q);
|
|
4015
|
+
})(api, args)).then(function(r) {
|
|
3517
4016
|
if (req !== reqRef.current) return;
|
|
3518
4017
|
if (r && r.ok === false) throw new Error(r && r.error || t.queryFail);
|
|
3519
4018
|
var body = unwrap(r);
|
|
@@ -3895,7 +4394,7 @@ var require_data_view = __commonJS({
|
|
|
3895
4394
|
}
|
|
3896
4395
|
}
|
|
3897
4396
|
}),
|
|
3898
|
-
h2("span", null, fmt(t.queryTime, { n: data
|
|
4397
|
+
data && data.queryMs !== void 0 ? h2("span", null, fmt(t.queryTime, { n: data.queryMs })) : null
|
|
3899
4398
|
);
|
|
3900
4399
|
}
|
|
3901
4400
|
if (!tables && loadingTables && options.Skeleton) return h2(options.Skeleton, { lang, label: t.loading });
|
|
@@ -3931,7 +4430,7 @@ var require_data_view = __commonJS({
|
|
|
3931
4430
|
"span",
|
|
3932
4431
|
{ className: P + "-stabname" },
|
|
3933
4432
|
h2("span", null, tableLabel(tb)),
|
|
3934
|
-
h2("span", { className: P + "-sidecount" }, String(tb.count))
|
|
4433
|
+
h2("span", { className: P + "-sidecount" }, tb.count === void 0 || tb.count === null ? "" : String(tb.count))
|
|
3935
4434
|
),
|
|
3936
4435
|
h2("span", { className: P + "-sidetable" }, tb.name)
|
|
3937
4436
|
);
|
|
@@ -3958,7 +4457,7 @@ var require_data_view = __commonJS({
|
|
|
3958
4457
|
h2(
|
|
3959
4458
|
"div",
|
|
3960
4459
|
{ className: P + "-sub" },
|
|
3961
|
-
current ? fmt(t.rowCount, { n:
|
|
4460
|
+
current && data && data.total !== void 0 ? fmt(t.rowCount, { n: data.total }) : "",
|
|
3962
4461
|
current && current.deletedCount ? " \xB7 " + fmt(t.deletedCount, { n: current.deletedCount }) : "",
|
|
3963
4462
|
" \xB7 " + t.subtitle
|
|
3964
4463
|
)
|
|
@@ -4164,50 +4663,6 @@ var require_data = __commonJS({
|
|
|
4164
4663
|
}
|
|
4165
4664
|
});
|
|
4166
4665
|
|
|
4167
|
-
// packages/addons/lib/highlight.cjs
|
|
4168
|
-
var require_highlight = __commonJS({
|
|
4169
|
-
"packages/addons/lib/highlight.cjs"(exports2, module2) {
|
|
4170
|
-
"use strict";
|
|
4171
|
-
module2.exports = function(React) {
|
|
4172
|
-
var h2 = React.createElement;
|
|
4173
|
-
function sourceOf(keyword) {
|
|
4174
|
-
var pattern = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4175
|
-
return pattern.replace(/[a-zA-Z]/g, function(letter) {
|
|
4176
|
-
return "[" + letter.toLowerCase() + letter.toUpperCase() + "]";
|
|
4177
|
-
});
|
|
4178
|
-
}
|
|
4179
|
-
return function createHighlight(prefix) {
|
|
4180
|
-
var className = String(prefix || "wb") + "-hit";
|
|
4181
|
-
function hit(rawText, rawKeyword) {
|
|
4182
|
-
var text = rawText == null ? "" : String(rawText);
|
|
4183
|
-
var keyword = rawKeyword == null ? "" : String(rawKeyword);
|
|
4184
|
-
if (!keyword) return text;
|
|
4185
|
-
var matcher, match, end = 0, parts = [];
|
|
4186
|
-
try {
|
|
4187
|
-
matcher = new RegExp(sourceOf(keyword), "g");
|
|
4188
|
-
} catch (error) {
|
|
4189
|
-
return text;
|
|
4190
|
-
}
|
|
4191
|
-
while (match = matcher.exec(text)) {
|
|
4192
|
-
if (match.index > end) parts.push(text.slice(end, match.index));
|
|
4193
|
-
parts.push(h2("mark", { className, key: match.index }, match[0]));
|
|
4194
|
-
end = match.index + match[0].length;
|
|
4195
|
-
if (!match[0]) matcher.lastIndex += 1;
|
|
4196
|
-
}
|
|
4197
|
-
if (!parts.length) return text;
|
|
4198
|
-
if (end < text.length) parts.push(text.slice(end));
|
|
4199
|
-
return parts;
|
|
4200
|
-
}
|
|
4201
|
-
function Highlight(props) {
|
|
4202
|
-
return hit(props.text, props.keyword);
|
|
4203
|
-
}
|
|
4204
|
-
Highlight.hit = hit;
|
|
4205
|
-
return Highlight;
|
|
4206
|
-
};
|
|
4207
|
-
};
|
|
4208
|
-
}
|
|
4209
|
-
});
|
|
4210
|
-
|
|
4211
4666
|
// packages/addons/lib/action-schema-style.cjs
|
|
4212
4667
|
var require_action_schema_style = __commonJS({
|
|
4213
4668
|
"packages/addons/lib/action-schema-style.cjs"(exports2, module2) {
|
|
@@ -4229,8 +4684,21 @@ var require_action_schema_style = __commonJS({
|
|
|
4229
4684
|
"." + P + " select:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}",
|
|
4230
4685
|
"." + P + "-list{display:flex;flex-direction:column;gap:8px}",
|
|
4231
4686
|
"." + P + "-card{border:1px solid var(--wb-border,#e3e5e9);border-radius:10px;padding:10px 12px;background:var(--wb-surface,var(--dsw-alias-bg-layer-1,transparent));display:flex;flex-direction:column;gap:8px;min-width:0}",
|
|
4232
|
-
"." + P + "-cardhead{display:
|
|
4233
|
-
"." + P + "-
|
|
4687
|
+
"." + P + "-cardhead{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:start;gap:8px}",
|
|
4688
|
+
"." + P + "-cardmeta{display:flex;align-items:center;flex-wrap:wrap;gap:8px;min-width:0;min-height:24px}",
|
|
4689
|
+
"." + P + "-cardhead code{font-weight:640;overflow-wrap:anywhere;min-width:0}",
|
|
4690
|
+
"." + P + "-hintline{margin:0;color:var(--dsw-alias-label-tertiary,inherit);font-size:11.5px;line-height:1.5}",
|
|
4691
|
+
"." + P + "-toggle{display:inline-flex;align-items:center;gap:6px;min-height:24px;padding:0 2px;border:0;background:transparent;font:inherit;font-size:11.5px;color:var(--wb-muted);cursor:pointer}",
|
|
4692
|
+
"." + P + "-track{display:inline-flex;align-items:center;box-sizing:border-box;width:30px;height:18px;padding:2px;border:1px solid var(--wb-muted);border-radius:999px;background:var(--wb-surface);color:var(--wb-muted)}",
|
|
4693
|
+
"." + P + "-track::before{content:'';width:12px;height:12px;border-radius:50%;background:currentColor;transition:transform .15s ease}",
|
|
4694
|
+
"." + P + "-toggle[aria-checked=true] ." + P + "-track{background:var(--wb-accent);border-color:var(--wb-accent);color:var(--wb-card)}",
|
|
4695
|
+
"." + P + "-toggle[aria-checked=true] ." + P + "-track::before{transform:translateX(12px)}",
|
|
4696
|
+
"." + P + "-toggle:hover:not(:disabled) ." + P + "-track{outline:1px solid var(--wb-accent)}",
|
|
4697
|
+
"." + P + "-toggle:focus-visible{outline:2px solid var(--wb-accent);outline-offset:2px}",
|
|
4698
|
+
"." + P + "-toggle:disabled{opacity:.6;cursor:progress}",
|
|
4699
|
+
"@media(prefers-reduced-motion:reduce){." + P + "-track::before{transition:none}}",
|
|
4700
|
+
// 安全约束(不可放开):用警示色描边,和可切换的开关区分开。
|
|
4701
|
+
"." + P + "-locked{border-color:var(--wb-warn,#b7791f);color:var(--wb-warn,#b7791f)}",
|
|
4234
4702
|
"." + P + "-desc{margin:0;color:var(--dsw-alias-label-secondary,inherit);line-height:1.55;font-size:12.5px}",
|
|
4235
4703
|
// 搜索命中:用品牌色透明度叠加而不是写死浅色,深浅主题都可读;继承文字颜色、不覆盖 ::selection。
|
|
4236
4704
|
"." + P + " mark." + P + "-hit{background:color-mix(in oklab,var(--dsw-alias-brand-primary,#4f6ef7) 22%,transparent);color:inherit;border-radius:2px;padding:0;font:inherit;box-decoration-break:clone;-webkit-box-decoration-break:clone}",
|
|
@@ -4282,6 +4750,15 @@ var require_action_schema_view = __commonJS({
|
|
|
4282
4750
|
zh: {
|
|
4283
4751
|
title: "Action",
|
|
4284
4752
|
hint: "\u8FD0\u884C\u65F6\u6CE8\u518C \xB7 \u53EA\u8BFB",
|
|
4753
|
+
switchHint: "agent \u5F00\u5173\u843D\u672C\u673A\u3001\u5373\u6539\u5373\u751F\u6548\uFF1B\u754C\u9762\u64CD\u4F5C\u4E0D\u53D7\u5F71\u54CD\u3002",
|
|
4754
|
+
hostHint: "\u5BBF\u4E3B action \u7684 agent \u5F00\u5173\uFF1B\u6807\u300C\u4EC5\u754C\u9762 \xB7 \u5B89\u5168\u7EA6\u675F\u300D\u7684\u4E0D\u53EF\u653E\u5F00\u3002",
|
|
4755
|
+
agentSwitch: "agent \u53EF\u7528",
|
|
4756
|
+
agentLocked: "\u4EC5\u754C\u9762 \xB7 \u5B89\u5168\u7EA6\u675F",
|
|
4757
|
+
agentLockedHint: "\u8BE5 action \u53EA\u80FD\u5728\u754C\u9762\u6267\u884C\uFF08\u5B89\u5168\u7EA6\u675F\uFF09\uFF0Cagent \u5F00\u5173\u4E0D\u53EF\u653E\u5F00",
|
|
4758
|
+
agentSaving: "\u4FDD\u5B58\u4E2D\u2026",
|
|
4759
|
+
agentOnToast: "\u5DF2\u5141\u8BB8 agent \u8C03\u7528",
|
|
4760
|
+
agentOffToast: "\u5DF2\u7981\u6B62 agent \u8C03\u7528",
|
|
4761
|
+
agentFail: "\u5207\u6362 agent \u5F00\u5173\u5931\u8D25",
|
|
4285
4762
|
domain: "\u57DF",
|
|
4286
4763
|
versionLabel: "\u7248\u672C",
|
|
4287
4764
|
shell: "\u5BBF\u4E3B",
|
|
@@ -4327,6 +4804,15 @@ var require_action_schema_view = __commonJS({
|
|
|
4327
4804
|
en: {
|
|
4328
4805
|
title: "Actions",
|
|
4329
4806
|
hint: "runtime registry \xB7 read-only",
|
|
4807
|
+
switchHint: "The agent switch is stored locally and applies immediately; UI actions are unaffected.",
|
|
4808
|
+
hostHint: "Agent switch for host actions; items marked UI-only (security) cannot be opened up.",
|
|
4809
|
+
agentSwitch: "Agent callable",
|
|
4810
|
+
agentLocked: "UI only \xB7 security",
|
|
4811
|
+
agentLockedHint: "This action can only run from the UI (security constraint); the agent switch cannot be opened",
|
|
4812
|
+
agentSaving: "Saving\u2026",
|
|
4813
|
+
agentOnToast: "Agent calls allowed",
|
|
4814
|
+
agentOffToast: "Agent calls blocked",
|
|
4815
|
+
agentFail: "Failed to change the agent switch",
|
|
4330
4816
|
domain: "Domain",
|
|
4331
4817
|
versionLabel: "Version",
|
|
4332
4818
|
shell: "Host",
|
|
@@ -4439,7 +4925,9 @@ var require_action_schema_view = __commonJS({
|
|
|
4439
4925
|
}
|
|
4440
4926
|
module2.exports = function createActionSchemaView(options) {
|
|
4441
4927
|
var raw = String(options.domain || "");
|
|
4442
|
-
var
|
|
4928
|
+
var SOURCE = options.source === "actions.list" ? "actions.list" : "actionSchema";
|
|
4929
|
+
var DOMAIN = SOURCE === "actions.list" ? raw : raw.indexOf("wb-addon-") === 0 ? raw : "wb-addon-" + raw;
|
|
4930
|
+
var LIST_DOMAIN = options.listDomain ? String(options.listDomain) : DOMAIN;
|
|
4443
4931
|
var prefix = options.prefix;
|
|
4444
4932
|
var P = prefix + "-as";
|
|
4445
4933
|
var Icon3 = options.Icon || null;
|
|
@@ -4483,6 +4971,8 @@ var require_action_schema_view = __commonJS({
|
|
|
4483
4971
|
var typePick = typeState[0], setTypePick = typeState[1];
|
|
4484
4972
|
var toastState = React.useState("");
|
|
4485
4973
|
var toast = toastState[0], setToast = toastState[1];
|
|
4974
|
+
var savingState = React.useState("");
|
|
4975
|
+
var saving = savingState[0], setSaving = savingState[1];
|
|
4486
4976
|
React.useEffect(function() {
|
|
4487
4977
|
injectCss();
|
|
4488
4978
|
}, []);
|
|
@@ -4491,9 +4981,10 @@ var require_action_schema_view = __commonJS({
|
|
|
4491
4981
|
setLoading(true);
|
|
4492
4982
|
setErr("");
|
|
4493
4983
|
var pending;
|
|
4494
|
-
var actionName = DOMAIN.replace(/^wb-addon-/, "") + ".actionSchema";
|
|
4984
|
+
var actionName = SOURCE === "actions.list" ? "actions.list" : DOMAIN.replace(/^wb-addon-/, "") + ".actionSchema";
|
|
4985
|
+
var callArgs = SOURCE === "actions.list" ? { detail: true, domain: LIST_DOMAIN } : void 0;
|
|
4495
4986
|
if (api && typeof api.call === "function") {
|
|
4496
|
-
pending = Promise.resolve(api.call(actionName)).then(function(r) {
|
|
4987
|
+
pending = Promise.resolve(api.call(actionName, callArgs)).then(function(r) {
|
|
4497
4988
|
if (r && r.ok === false) return r;
|
|
4498
4989
|
return r && r.result || r;
|
|
4499
4990
|
});
|
|
@@ -4533,6 +5024,39 @@ var require_action_schema_view = __commonJS({
|
|
|
4533
5024
|
plainCopy(text);
|
|
4534
5025
|
done();
|
|
4535
5026
|
}
|
|
5027
|
+
function setAgent(action, next) {
|
|
5028
|
+
var name = action.name;
|
|
5029
|
+
setSaving(name);
|
|
5030
|
+
setToast("");
|
|
5031
|
+
var fail = function(e) {
|
|
5032
|
+
setSaving("");
|
|
5033
|
+
setToast(t.agentFail + "\uFF1A" + String(e && e.message || e || ""));
|
|
5034
|
+
};
|
|
5035
|
+
var done = function(r) {
|
|
5036
|
+
setSaving("");
|
|
5037
|
+
var payload = r && typeof r === "object" && Object.prototype.hasOwnProperty.call(r, "result") ? r.result : r;
|
|
5038
|
+
if (r && r.ok === false) {
|
|
5039
|
+
setToast(t.agentFail + "\uFF1A" + String(r.error || r.text || ""));
|
|
5040
|
+
return;
|
|
5041
|
+
}
|
|
5042
|
+
var value = payload && typeof payload.agentEnabled === "boolean" ? payload.agentEnabled : next;
|
|
5043
|
+
setSnap(function(prev) {
|
|
5044
|
+
if (!prev || !Array.isArray(prev.actions)) return prev;
|
|
5045
|
+
return Object.assign({}, prev, {
|
|
5046
|
+
actions: prev.actions.map(function(a) {
|
|
5047
|
+
if (!a || a.name !== name) return a;
|
|
5048
|
+
return Object.assign({}, a, { agentEnabled: value });
|
|
5049
|
+
})
|
|
5050
|
+
});
|
|
5051
|
+
});
|
|
5052
|
+
setToast(value ? t.agentOnToast : t.agentOffToast);
|
|
5053
|
+
};
|
|
5054
|
+
if (!api || typeof api.call !== "function") {
|
|
5055
|
+
fail(new Error("no call api"));
|
|
5056
|
+
return;
|
|
5057
|
+
}
|
|
5058
|
+
Promise.resolve(api.call("actions.setAgentAccess", { action: name, agentEnabled: next })).then(done, fail);
|
|
5059
|
+
}
|
|
4536
5060
|
var all = snap && Array.isArray(snap.actions) ? snap.actions.filter(function(a) {
|
|
4537
5061
|
return a && a.domain === DOMAIN;
|
|
4538
5062
|
}) : [];
|
|
@@ -4581,6 +5105,35 @@ var require_action_schema_view = __commonJS({
|
|
|
4581
5105
|
h2("td", null, Highlight.hit(row.description, kw))
|
|
4582
5106
|
);
|
|
4583
5107
|
}
|
|
5108
|
+
function agentSwitch(action) {
|
|
5109
|
+
if (action.agentLocked === true) {
|
|
5110
|
+
return h2("span", {
|
|
5111
|
+
className: P + "-badge " + P + "-locked",
|
|
5112
|
+
title: t.agentLockedHint,
|
|
5113
|
+
"data-agent-locked": action.name
|
|
5114
|
+
}, t.agentLocked);
|
|
5115
|
+
}
|
|
5116
|
+
if (typeof action.agentEnabled !== "boolean") return null;
|
|
5117
|
+
var busy = saving === action.name;
|
|
5118
|
+
return h2(
|
|
5119
|
+
"button",
|
|
5120
|
+
{
|
|
5121
|
+
className: P + "-toggle",
|
|
5122
|
+
"data-agent-row": action.name,
|
|
5123
|
+
type: "button",
|
|
5124
|
+
role: "switch",
|
|
5125
|
+
"aria-checked": action.agentEnabled,
|
|
5126
|
+
disabled: busy,
|
|
5127
|
+
"data-agent-toggle": action.name,
|
|
5128
|
+
"aria-label": t.agentSwitch + " \xB7 " + action.name,
|
|
5129
|
+
onClick: function() {
|
|
5130
|
+
setAgent(action, !action.agentEnabled);
|
|
5131
|
+
}
|
|
5132
|
+
},
|
|
5133
|
+
h2("span", { className: P + "-track", "aria-hidden": true }),
|
|
5134
|
+
h2("span", null, busy ? t.agentSaving : t.agentSwitch)
|
|
5135
|
+
);
|
|
5136
|
+
}
|
|
4584
5137
|
function card(action) {
|
|
4585
5138
|
var rows = paramRows(action);
|
|
4586
5139
|
var examples = Array.isArray(action.examples) ? action.examples : [];
|
|
@@ -4590,12 +5143,16 @@ var require_action_schema_view = __commonJS({
|
|
|
4590
5143
|
h2(
|
|
4591
5144
|
"div",
|
|
4592
5145
|
{ className: P + "-cardhead" },
|
|
4593
|
-
h2(
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
5146
|
+
h2(
|
|
5147
|
+
"div",
|
|
5148
|
+
{ className: P + "-cardmeta" },
|
|
5149
|
+
h2("code", { className: P + "-mono" }, Highlight.hit(action.name, kw)),
|
|
5150
|
+
h2("span", { className: P + "-badge" }, rows.length ? t.paramCount(rows.length) : t.noParams),
|
|
5151
|
+
rows.some(function(row) {
|
|
5152
|
+
return row.required;
|
|
5153
|
+
}) ? h2("span", { className: P + "-badge " + P + "-req" }, t.required) : null
|
|
5154
|
+
),
|
|
5155
|
+
agentSwitch(action)
|
|
4599
5156
|
),
|
|
4600
5157
|
action.description ? h2("p", { className: P + "-desc" }, Highlight.hit(action.description, kw)) : null,
|
|
4601
5158
|
rows.length ? h2(
|
|
@@ -4672,6 +5229,7 @@ var require_action_schema_view = __commonJS({
|
|
|
4672
5229
|
h2("span", { className: P + "-badge" }, t.count(visible.length, all.length)),
|
|
4673
5230
|
h2("span", { className: P + "-none" }, t.hint)
|
|
4674
5231
|
),
|
|
5232
|
+
h2("p", { className: P + "-hintline" }, SOURCE === "actions.list" ? t.hostHint : t.switchHint),
|
|
4675
5233
|
snap ? h2(
|
|
4676
5234
|
"div",
|
|
4677
5235
|
{ className: P + "-toolbar" },
|
|
@@ -4758,7 +5316,8 @@ if (host) {
|
|
|
4758
5316
|
h = require("react").createElement, Icon2 = require_icons().Icon;
|
|
4759
5317
|
host.registerAddon({
|
|
4760
5318
|
id: "wb-addon-storage",
|
|
4761
|
-
version: "1.5.
|
|
5319
|
+
version: "1.5.6",
|
|
5320
|
+
icon: (init_package(), __toCommonJS(package_exports)).default,
|
|
4762
5321
|
views: [
|
|
4763
5322
|
{ id: "stats", icon: tabIcon2("chart"), title: { zh: "\u7EDF\u8BA1", en: "Statistics" }, component: require_stats().Stats },
|
|
4764
5323
|
{ id: "storage", icon: tabIcon2("list"), title: { zh: "\u8BB0\u5F55", en: "Records" }, component: require_records().Records },
|
package/lib/domain/tags.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { idsOf, tagsOn, now, newId, logChange, pageInfo, sizeOf } from "../db/db.js";
|
|
1
|
+
import { idsOf, tagsOn, now, newId, logChange, pageInfo, sizeOf, tableExists } from "../db/db.js";
|
|
2
|
+
import { TAG_SOURCE, TAG_SOURCE_OWNER, TAG_SOURCE_TITLE, ensureTagSource, withTagSource } from "../tagging/source.js";
|
|
2
3
|
export function validateTags(api, value) {
|
|
3
4
|
const ids = idsOf(value);
|
|
4
5
|
if (!tagsOn(api)) {
|
|
@@ -10,10 +11,37 @@ export function validateTags(api, value) {
|
|
|
10
11
|
throw new Error("标签不存在:" + id);
|
|
11
12
|
return ids;
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* 启动时幂等登记本域来源(`tag_mapping.item_type='storage'`)。
|
|
16
|
+
* 标签域未装或版本过低时静默跳过;重复注册不阻断启动,写入门禁在写入时给出可读错误。
|
|
17
|
+
*/
|
|
18
|
+
export function ensureStorageTagSource(db, log) {
|
|
19
|
+
if (!tableExists(db, "tag_source")) return { ok: false, skipped: "no_table" };
|
|
20
|
+
try {
|
|
21
|
+
const r = ensureTagSource(db, TAG_SOURCE, TAG_SOURCE_OWNER, TAG_SOURCE_TITLE);
|
|
22
|
+
const hit = db.prepare("SELECT COUNT(*) AS n FROM tag_source WHERE source=? AND deleted_at IS NULL").get(TAG_SOURCE);
|
|
23
|
+
const count = Number((hit && hit.n) || 0);
|
|
24
|
+
if (count !== 1 && typeof log === "function") {
|
|
25
|
+
log("标签来源登记异常(" + TAG_SOURCE + "):当前 " + count + " 条活跃注册,标签写入会被拒绝");
|
|
26
|
+
}
|
|
27
|
+
return { ok: count === 1, count: count, created: !!(r && r.created) };
|
|
28
|
+
} catch (e) {
|
|
29
|
+
if (typeof log === "function") log("标签来源登记失败:" + String((e && e.message) || e));
|
|
30
|
+
return { ok: false, error: String((e && e.message) || e) };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 全量替换某条储物记录的标签(写入门禁:来源必须恰好注册一次)。 */
|
|
13
35
|
export function replaceTags(api, itemId, ids, origin, ts = now()) {
|
|
14
36
|
if (ids === null) return 0;
|
|
15
|
-
const db = api.db;
|
|
16
37
|
if (!tagsOn(api)) return 0;
|
|
38
|
+
return withTagSource(api.db, TAG_SOURCE, function () {
|
|
39
|
+
return writeTags(api, itemId, ids, origin, ts);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function writeTags(api, itemId, ids, origin, ts) {
|
|
44
|
+
const db = api.db;
|
|
17
45
|
const current = db.prepare("SELECT * FROM tag_mapping WHERE item_type='storage' AND item_id=?").all(itemId);
|
|
18
46
|
let removed = 0;
|
|
19
47
|
for (const row of current)
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 储物业务插件:标签筛选列表体改用共享 filter-checklist(1.5.4);
|
|
3
|
+
* 搜索命中字段(名称/品牌/位置/备注)用共享 highlight 高亮(1.5.5)。
|
|
4
|
+
*/
|
|
1
5
|
import { bindClock, ensureSchema } from "./db/db.js";
|
|
6
|
+
import { ensureStorageTagSource } from "./domain/tags.js";
|
|
2
7
|
import { registerStorageActions } from "./domain/storage.js";
|
|
3
8
|
import { registerConfigActions } from "./infra/config.js";
|
|
4
9
|
import { registerDataActions } from "./infra/data.js";
|
|
@@ -43,6 +48,8 @@ function registerActionSchemaAction(api, defs, domain) {
|
|
|
43
48
|
export function setup(api) {
|
|
44
49
|
bindClock(typeof api.now === "function" ? api.now : null);
|
|
45
50
|
ensureSchema(api.db);
|
|
51
|
+
// 标签来源登记:标签域(tags ≥ 1.7.1)要求 item_type 先注册才能写 tag_mapping。
|
|
52
|
+
ensureStorageTagSource(api.db, api.log);
|
|
46
53
|
const actionDefs = trackActions(api);
|
|
47
54
|
registerStorageActions(api);
|
|
48
55
|
registerConfigActions(api);
|
|
@@ -60,7 +67,7 @@ export function apply(ctx) {
|
|
|
60
67
|
id: "wb-addon-storage",
|
|
61
68
|
title: "储物",
|
|
62
69
|
description: "储物:记录物品名称、品牌、单位、库存文本、存放位置、图片URL、备注与可选标签",
|
|
63
|
-
version: "1.5.
|
|
70
|
+
version: "1.5.6",
|
|
64
71
|
tables: ["storage"],
|
|
65
72
|
sync: storageSync,
|
|
66
73
|
backupAfter: ["wb-addon-tags"],
|
package/lib/infra/backup.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fieldsOf, tableExists, tx, logChange } from "../db/db.js";
|
|
2
|
+
import { TAG_SOURCE, TAG_SOURCE_OWNER, TAG_SOURCE_TITLE, ensureTagSource, tagSourceReady, tagSourceError } from "../tagging/source.js";
|
|
2
3
|
export const SCHEMA_VERSION = 1;
|
|
3
4
|
export function exportStorageData(api) {
|
|
4
5
|
const db = api.db;
|
|
@@ -102,6 +103,11 @@ export function importStorageData(api, raw, options = {}) {
|
|
|
102
103
|
const hasMappings = tableExists(db, "tag_mapping");
|
|
103
104
|
if (mappings.length && (!hasMappings || !tableExists(db, "tag")))
|
|
104
105
|
throw new Error("恢复标签映射需要先安装标签插件并恢复标签备份");
|
|
106
|
+
// 来源注册:标签域 ≥ 1.7.1 的写入门禁要求 item_type 先注册,否则整批映射都会被拒。
|
|
107
|
+
if (mappings.length && tableExists(db, "tag_source")) {
|
|
108
|
+
ensureTagSource(db, TAG_SOURCE, TAG_SOURCE_OWNER, TAG_SOURCE_TITLE);
|
|
109
|
+
if (!tagSourceReady(db, TAG_SOURCE).ok) throw tagSourceError(db, TAG_SOURCE);
|
|
110
|
+
}
|
|
105
111
|
tx(db, () => {
|
|
106
112
|
function apply(table, row) {
|
|
107
113
|
const old = db.prepare("SELECT * FROM " + table + " WHERE id=?").get(row.id);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 标签来源(`tag_mapping.item_type`)的业务侧适配。
|
|
3
|
+
*
|
|
4
|
+
* 契约见 `docs/specs/25-标签域解耦审计与改造.md`「6. 来源注册与映射写入门禁」:
|
|
5
|
+
* - 标签域(`wb-addon-tags` ≥ 1.7.1)用 `tag_source` 登记「哪个插件在用哪个 item_type」,
|
|
6
|
+
* 并在 `tag_mapping` 上装触发器:来源未注册(0 条)或重复(≥2 条)时拒绝一切写入;
|
|
7
|
+
* - 业务域负责启动时幂等登记自己的来源,写入前先判、写入异常时翻成统一可读文案。
|
|
8
|
+
*
|
|
9
|
+
* 标签域未安装或版本过低(没有 `tag_source` 表)时整块跳过,保持既有降级行为。
|
|
10
|
+
*/
|
|
11
|
+
import { now, newId, tableExists } from "../db/db.js";
|
|
12
|
+
|
|
13
|
+
export const TAG_SOURCE = "storage";
|
|
14
|
+
export const TAG_SOURCE_OWNER = "wb-addon-storage";
|
|
15
|
+
export const TAG_SOURCE_TITLE = "储物";
|
|
16
|
+
|
|
17
|
+
function coded(code, message) {
|
|
18
|
+
return Object.assign(new Error(message), { code: code });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 该来源的活跃注册行;没有 `tag_source` 表时返回空数组。 */
|
|
22
|
+
export function tagSourceRows(db, source) {
|
|
23
|
+
if (!tableExists(db, "tag_source")) return [];
|
|
24
|
+
return db
|
|
25
|
+
.prepare("SELECT * FROM tag_source WHERE source=? AND deleted_at IS NULL ORDER BY created_at ASC, id ASC")
|
|
26
|
+
.all(String(source));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 恰好 1 条活跃注册才算 ready;`missing` 表示标签域还没建 `tag_source`(老版本),此时不做门禁。 */
|
|
30
|
+
export function tagSourceReady(db, source) {
|
|
31
|
+
if (!tableExists(db, "tag_source")) return { ok: false, missing: true, count: 0, owners: [] };
|
|
32
|
+
const rows = tagSourceRows(db, source);
|
|
33
|
+
return {
|
|
34
|
+
ok: rows.length === 1,
|
|
35
|
+
missing: false,
|
|
36
|
+
count: rows.length,
|
|
37
|
+
owners: rows.map(function (r) { return String(r.owner); }),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 幂等登记本域来源;`tag_source` 不存在时跳过(老标签插件不认识来源注册)。 */
|
|
42
|
+
export function ensureTagSource(db, source, owner, title) {
|
|
43
|
+
if (!tableExists(db, "tag_source")) return { ok: false, missing: true, created: false };
|
|
44
|
+
const src = String(source === undefined || source === null ? "" : source).trim();
|
|
45
|
+
const own = String(owner === undefined || owner === null ? "" : owner).trim();
|
|
46
|
+
if (!src || !own) return { ok: false, created: false };
|
|
47
|
+
const hit = db.prepare("SELECT id FROM tag_source WHERE source=? AND owner=? AND deleted_at IS NULL").get(src, own);
|
|
48
|
+
if (hit) return { ok: true, created: false, id: String(hit.id) };
|
|
49
|
+
const ts = now();
|
|
50
|
+
const id = newId();
|
|
51
|
+
db.prepare(
|
|
52
|
+
"INSERT INTO tag_source(id,source,owner,title,created_at,updated_at,deleted_at,rev) VALUES(?,?,?,?,?,?,NULL,1)",
|
|
53
|
+
).run(id, src, own, String(title || ""), ts, ts);
|
|
54
|
+
return { ok: true, created: true, id: id };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 按当前注册状态给出统一错误:0 条 = 未注册,≥2 条 = 标识重复。 */
|
|
58
|
+
export function tagSourceError(db, source) {
|
|
59
|
+
const state = tagSourceReady(db, source);
|
|
60
|
+
if (state.count === 0) {
|
|
61
|
+
return coded(
|
|
62
|
+
"TAG_SOURCE_UNREGISTERED",
|
|
63
|
+
"标签来源未注册,无法操作(来源:" + source + ");先调用 tags.registerSource 注册该来源",
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return coded(
|
|
67
|
+
"TAG_SOURCE_DUPLICATED",
|
|
68
|
+
"标签来源标识重复,无法操作(来源:" + source + ";归属:" + state.owners.join("、") +
|
|
69
|
+
");请先清理 tag_source 中的重复注册",
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 写入 `tag_mapping` 的统一入口:先判门禁,执行中触发器的原始错误翻成统一文案。
|
|
75
|
+
* `source` 省略时用本域默认来源。注册由启动时的 `ensureXxxTagSource` 负责,这里不补登记——
|
|
76
|
+
* 否则「被人工注销」会被静默覆盖,门禁也就失效了。
|
|
77
|
+
*/
|
|
78
|
+
export function withTagSource(db, source, fn) {
|
|
79
|
+
const src = String(source || TAG_SOURCE);
|
|
80
|
+
// 先判后写:注册由启动时 ensureXxxTagSource 负责,这里只判定,不替调用方补登记。
|
|
81
|
+
if (!tagSourceReady(db, src).ok && !tagSourceReady(db, src).missing) throw tagSourceError(db, src);
|
|
82
|
+
try {
|
|
83
|
+
return fn();
|
|
84
|
+
} catch (e) {
|
|
85
|
+
const msg = String((e && e.message) || "");
|
|
86
|
+
if (msg.indexOf("标签来源") >= 0) throw tagSourceError(db, src);
|
|
87
|
+
throw e;
|
|
88
|
+
}
|
|
89
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-workbench-storage",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "个人工作台储物插件:名称、品牌、位置、单位、库存文本与标签",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"id": "wb-addon-storage",
|
|
10
10
|
"title": "储物",
|
|
11
11
|
"description": "储物:统计/记录/配置/数据四个视图",
|
|
12
|
-
"version": "1.5.
|
|
13
|
-
"minShell": "0.
|
|
12
|
+
"version": "1.5.6",
|
|
13
|
+
"minShell": "0.8.0",
|
|
14
14
|
"tables": [
|
|
15
15
|
"storage"
|
|
16
16
|
],
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"./package.json": "./package.json"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"dsh-workbench-host": "^0.
|
|
50
|
+
"dsh-workbench-host": "^0.8.0"
|
|
51
51
|
},
|
|
52
52
|
"dsh": {
|
|
53
53
|
"bundle": {
|