dsh-workbench-storage 1.5.1 → 1.5.5
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 +526 -97
- 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 +3 -3
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,43 @@ 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
|
+
".wbck-nm{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
709
|
+
".wbck-meta{margin-left:auto;flex:none;font-size:11.5px;color:var(--wb-muted)}",
|
|
710
|
+
".wbck-note{font-size:12px;color:var(--wb-muted);padding:8px 6px}",
|
|
711
|
+
".wbck-more{font-size:11px;color:var(--wb-muted);text-align:center;padding:6px 0 2px;opacity:.8}",
|
|
712
|
+
"@media (max-width:760px){.wbck-list{max-height:200px}}"
|
|
713
|
+
];
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
|
|
678
717
|
// packages/addons/storage/client/ui/styles.cjs
|
|
679
718
|
var require_styles = __commonJS({
|
|
680
719
|
"packages/addons/storage/client/ui/styles.cjs"(exports2, module2) {
|
|
681
720
|
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}
|
|
721
|
+
.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}
|
|
722
|
+
.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
723
|
.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
724
|
.wbi-btn:enabled:hover,.wbi-image:enabled:hover,.wbi-root .wb-desc-toggle:enabled:hover{background:var(--wb-btn-hover-bg)}
|
|
686
725
|
.wbi-btn:enabled:active,.wbi-image:enabled:active,.wbi-root .wb-desc-toggle:enabled:active{background:var(--wb-btn-active-bg)}
|
|
@@ -705,8 +744,9 @@ var require_styles = __commonJS({
|
|
|
705
744
|
.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
745
|
.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
746
|
@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}}
|
|
747
|
+
.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
748
|
@media(prefers-reduced-motion:reduce){.wbi-root *,.wbi-root *::after{transition:none!important;animation:none!important}.wbi-card:hover{transform:none}}
|
|
709
|
-
|
|
749
|
+
` + require_filter_checklist_styles().join("\n");
|
|
710
750
|
}
|
|
711
751
|
});
|
|
712
752
|
|
|
@@ -1675,25 +1715,92 @@ var require_editor = __commonJS({
|
|
|
1675
1715
|
};
|
|
1676
1716
|
});
|
|
1677
1717
|
var form = state[0], setForm = state[1];
|
|
1678
|
-
var err = React.useState(null), busy = React.useState(false), query = React.useState(""), options = React.useState(
|
|
1718
|
+
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() {
|
|
1719
|
+
var map = {};
|
|
1720
|
+
(item.tags || []).forEach(function(t) {
|
|
1721
|
+
map[String(t.id)] = t.name;
|
|
1722
|
+
});
|
|
1723
|
+
return map;
|
|
1724
|
+
});
|
|
1679
1725
|
var selected = React.useState(item.tags || []);
|
|
1726
|
+
var seq = React.useRef(0);
|
|
1727
|
+
var load = React.useCallback(
|
|
1728
|
+
function(text, pageNumber, append) {
|
|
1729
|
+
var mine = ++seq.current;
|
|
1730
|
+
loading[1](true);
|
|
1731
|
+
return ui.call(props.api, "storageTags.search", { text: text || "", pageNumber, pageSize: 20 }).then(function(r) {
|
|
1732
|
+
if (mine !== seq.current) return;
|
|
1733
|
+
loading[1](false);
|
|
1734
|
+
var records = r && r.records || [];
|
|
1735
|
+
total[1](r && r.total || 0);
|
|
1736
|
+
page[1](r && r.current || pageNumber);
|
|
1737
|
+
hasMore[1]((r && r.current || pageNumber) < (r && r.pages || 0));
|
|
1738
|
+
options[1](function(prev) {
|
|
1739
|
+
var list = append ? prev.slice() : [];
|
|
1740
|
+
var seen = {};
|
|
1741
|
+
list.forEach(function(x) {
|
|
1742
|
+
seen[String(x.id)] = true;
|
|
1743
|
+
});
|
|
1744
|
+
records.forEach(function(x) {
|
|
1745
|
+
if (!seen[String(x.id)]) list.push(x);
|
|
1746
|
+
});
|
|
1747
|
+
return list;
|
|
1748
|
+
});
|
|
1749
|
+
names[1](function(prev) {
|
|
1750
|
+
var next = Object.assign({}, prev);
|
|
1751
|
+
records.forEach(function(x) {
|
|
1752
|
+
next[String(x.id)] = x.name;
|
|
1753
|
+
});
|
|
1754
|
+
return next;
|
|
1755
|
+
});
|
|
1756
|
+
}).catch(function(e) {
|
|
1757
|
+
if (mine !== seq.current) return;
|
|
1758
|
+
loading[1](false);
|
|
1759
|
+
err[1](e);
|
|
1760
|
+
});
|
|
1761
|
+
},
|
|
1762
|
+
[props.api]
|
|
1763
|
+
);
|
|
1764
|
+
React.useEffect(
|
|
1765
|
+
function() {
|
|
1766
|
+
if (!props.tagsEnabled) return void 0;
|
|
1767
|
+
var timer = setTimeout(
|
|
1768
|
+
function() {
|
|
1769
|
+
load(query[0], 1, false);
|
|
1770
|
+
},
|
|
1771
|
+
query[0] ? 200 : 0
|
|
1772
|
+
);
|
|
1773
|
+
return function() {
|
|
1774
|
+
clearTimeout(timer);
|
|
1775
|
+
};
|
|
1776
|
+
},
|
|
1777
|
+
[query[0], props.tagsEnabled, load]
|
|
1778
|
+
);
|
|
1680
1779
|
React.useEffect(
|
|
1681
1780
|
function() {
|
|
1682
|
-
if (!props.tagsEnabled) return;
|
|
1781
|
+
if (!props.tagsEnabled) return void 0;
|
|
1782
|
+
var missing = form.tagIds.filter(function(id) {
|
|
1783
|
+
return !names[0][String(id)];
|
|
1784
|
+
});
|
|
1785
|
+
if (!missing.length) return void 0;
|
|
1683
1786
|
var active = true;
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1787
|
+
ui.call(props.api, "storageTags.byIds", { ids: missing }).then(function(r) {
|
|
1788
|
+
if (!active) return;
|
|
1789
|
+
var next = {};
|
|
1790
|
+
(r && r.records || []).forEach(function(x) {
|
|
1791
|
+
next[String(x.id)] = x.name;
|
|
1792
|
+
});
|
|
1793
|
+
if (!Object.keys(next).length) return;
|
|
1794
|
+
names[1](function(prev) {
|
|
1795
|
+
return Object.assign({}, prev, next);
|
|
1689
1796
|
});
|
|
1690
|
-
}
|
|
1797
|
+
}).catch(function() {
|
|
1798
|
+
});
|
|
1691
1799
|
return function() {
|
|
1692
1800
|
active = false;
|
|
1693
|
-
clearTimeout(timer);
|
|
1694
1801
|
};
|
|
1695
1802
|
},
|
|
1696
|
-
[
|
|
1803
|
+
[props.api, props.tagsEnabled, form.tagIds.join(",")]
|
|
1697
1804
|
);
|
|
1698
1805
|
function update(k, v) {
|
|
1699
1806
|
setForm(function(f) {
|
|
@@ -1755,6 +1862,12 @@ var require_editor = __commonJS({
|
|
|
1755
1862
|
selected[0].concat(options[0]).forEach(function(t) {
|
|
1756
1863
|
candidates.set(t.id, t);
|
|
1757
1864
|
});
|
|
1865
|
+
function onListScroll(e) {
|
|
1866
|
+
var el = e.currentTarget;
|
|
1867
|
+
if (!hasMore[0] || loading[0]) return;
|
|
1868
|
+
if (el.scrollTop + el.clientHeight >= el.scrollHeight - 24) load(query[0], (page[0] || 1) + 1, true);
|
|
1869
|
+
}
|
|
1870
|
+
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
1871
|
return h2(
|
|
1759
1872
|
ui.Modal,
|
|
1760
1873
|
{
|
|
@@ -1794,7 +1907,7 @@ var require_editor = __commonJS({
|
|
|
1794
1907
|
}),
|
|
1795
1908
|
h2(
|
|
1796
1909
|
"div",
|
|
1797
|
-
{ className: "wbi-tagoptions" },
|
|
1910
|
+
{ className: "wbi-tagoptions", onScroll: onListScroll },
|
|
1798
1911
|
Array.from(candidates.values()).map(function(t) {
|
|
1799
1912
|
return h2(
|
|
1800
1913
|
"label",
|
|
@@ -1820,15 +1933,11 @@ var require_editor = __commonJS({
|
|
|
1820
1933
|
});
|
|
1821
1934
|
}
|
|
1822
1935
|
}),
|
|
1823
|
-
t.name
|
|
1936
|
+
names[0][String(t.id)] || t.name
|
|
1824
1937
|
);
|
|
1825
1938
|
})
|
|
1826
1939
|
),
|
|
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
|
|
1940
|
+
h2("div", { className: "wbi-tagmore" }, tagsNote)
|
|
1832
1941
|
) : h2(
|
|
1833
1942
|
"span",
|
|
1834
1943
|
{ className: "wbi-muted" },
|
|
@@ -1853,6 +1962,60 @@ var require_editor = __commonJS({
|
|
|
1853
1962
|
}
|
|
1854
1963
|
});
|
|
1855
1964
|
|
|
1965
|
+
// packages/addons/lib/highlight.cjs
|
|
1966
|
+
var require_highlight = __commonJS({
|
|
1967
|
+
"packages/addons/lib/highlight.cjs"(exports2, module2) {
|
|
1968
|
+
"use strict";
|
|
1969
|
+
module2.exports = function(React) {
|
|
1970
|
+
var h2 = React.createElement;
|
|
1971
|
+
function sourceOf(keyword) {
|
|
1972
|
+
var pattern = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1973
|
+
return pattern.replace(/[a-zA-Z]/g, function(letter) {
|
|
1974
|
+
return "[" + letter.toLowerCase() + letter.toUpperCase() + "]";
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
return function createHighlight(prefix) {
|
|
1978
|
+
var className = String(prefix || "wb") + "-hit";
|
|
1979
|
+
function hit(rawText, rawKeyword) {
|
|
1980
|
+
var text = rawText == null ? "" : String(rawText);
|
|
1981
|
+
var keyword = rawKeyword == null ? "" : String(rawKeyword);
|
|
1982
|
+
if (!keyword) return text;
|
|
1983
|
+
var matcher, match, end = 0, parts = [];
|
|
1984
|
+
try {
|
|
1985
|
+
matcher = new RegExp(sourceOf(keyword), "g");
|
|
1986
|
+
} catch (error) {
|
|
1987
|
+
return text;
|
|
1988
|
+
}
|
|
1989
|
+
while (match = matcher.exec(text)) {
|
|
1990
|
+
if (match.index > end) parts.push(text.slice(end, match.index));
|
|
1991
|
+
parts.push(h2("mark", { className, key: match.index }, match[0]));
|
|
1992
|
+
end = match.index + match[0].length;
|
|
1993
|
+
if (!match[0]) matcher.lastIndex += 1;
|
|
1994
|
+
}
|
|
1995
|
+
if (!parts.length) return text;
|
|
1996
|
+
if (end < text.length) parts.push(text.slice(end));
|
|
1997
|
+
return parts;
|
|
1998
|
+
}
|
|
1999
|
+
function Highlight(props) {
|
|
2000
|
+
return hit(props.text, props.keyword);
|
|
2001
|
+
}
|
|
2002
|
+
Highlight.hit = hit;
|
|
2003
|
+
return Highlight;
|
|
2004
|
+
};
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
|
|
2009
|
+
// packages/addons/storage/client/ui/highlight.cjs
|
|
2010
|
+
var require_highlight2 = __commonJS({
|
|
2011
|
+
"packages/addons/storage/client/ui/highlight.cjs"(exports2, module2) {
|
|
2012
|
+
"use strict";
|
|
2013
|
+
module2.exports = function(React) {
|
|
2014
|
+
return require_highlight()(React)("wbi");
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
});
|
|
2018
|
+
|
|
1856
2019
|
// packages/addons/storage/client/item/card.cjs
|
|
1857
2020
|
var require_card = __commonJS({
|
|
1858
2021
|
"packages/addons/storage/client/item/card.cjs"(exports2, module2) {
|
|
@@ -1861,8 +2024,10 @@ var require_card = __commonJS({
|
|
|
1861
2024
|
var h2 = ui.h;
|
|
1862
2025
|
var tr = ui.tr;
|
|
1863
2026
|
var Description = require_description().Description;
|
|
2027
|
+
var Highlight = require_highlight2()(React);
|
|
1864
2028
|
function StorageCard(props) {
|
|
1865
2029
|
var item = props.item, lang = props.lang, gallery = React.useState(false);
|
|
2030
|
+
var keyword = String(props.keyword || "");
|
|
1866
2031
|
var images = (item.imgList || []).filter(ui.safeImage), tags = item.tags || [];
|
|
1867
2032
|
var shown = gallery[0] ? images : images.slice(0, 1);
|
|
1868
2033
|
var hasStock = item.stock != null && item.stock !== "";
|
|
@@ -1898,7 +2063,7 @@ var require_card = __commonJS({
|
|
|
1898
2063
|
h2(
|
|
1899
2064
|
"div",
|
|
1900
2065
|
{ className: "wbi-cardhead" },
|
|
1901
|
-
h2("h3", null, item.name),
|
|
2066
|
+
h2("h3", null, h2(Highlight, { text: item.name, keyword })),
|
|
1902
2067
|
h2(
|
|
1903
2068
|
"span",
|
|
1904
2069
|
{ className: "wbi-stock" },
|
|
@@ -1925,9 +2090,10 @@ var require_card = __commonJS({
|
|
|
1925
2090
|
meta.length ? h2(
|
|
1926
2091
|
"div",
|
|
1927
2092
|
{ className: "wbi-muted" },
|
|
1928
|
-
item.brand ? h2("span", { className: "wbi-inline" }, h2(ui.Icon, { name: "brand", size: 11 }),
|
|
2093
|
+
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,
|
|
2094
|
+
// 单位不参与文字搜索,按原样展示,避免「亮了却搜不到」的错觉。
|
|
1929
2095
|
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: ")
|
|
2096
|
+
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
2097
|
) : null,
|
|
1932
2098
|
item.createTime || item.updateTime ? h2(
|
|
1933
2099
|
"div",
|
|
@@ -1936,7 +2102,7 @@ var require_card = __commonJS({
|
|
|
1936
2102
|
item.updateTime ? h2("span", null, tr(lang, "\u66F4\u65B0 ", "Updated ") + props.date(item.updateTime)) : null
|
|
1937
2103
|
) : null
|
|
1938
2104
|
) : null,
|
|
1939
|
-
h2(Description, { text: item.remark, lang, bodyMode: props.bodyMode }),
|
|
2105
|
+
h2(Description, { text: item.remark, lang, bodyMode: props.bodyMode, Highlight, keyword }),
|
|
1940
2106
|
images.length ? h2("div", { className: "wbi-images" }, shown.map(function(url, i) {
|
|
1941
2107
|
return h2(
|
|
1942
2108
|
"button",
|
|
@@ -1991,6 +2157,310 @@ var require_card = __commonJS({
|
|
|
1991
2157
|
}
|
|
1992
2158
|
});
|
|
1993
2159
|
|
|
2160
|
+
// packages/addons/lib/filter-checklist.cjs
|
|
2161
|
+
var require_filter_checklist = __commonJS({
|
|
2162
|
+
"packages/addons/lib/filter-checklist.cjs"(exports2, module2) {
|
|
2163
|
+
"use strict";
|
|
2164
|
+
var React = require("react");
|
|
2165
|
+
var h2 = React.createElement;
|
|
2166
|
+
var NEAR = 24;
|
|
2167
|
+
function nearBottom(el, threshold) {
|
|
2168
|
+
if (!el) return false;
|
|
2169
|
+
var gap = Number(threshold);
|
|
2170
|
+
if (!isFinite(gap) || gap < 0) gap = NEAR;
|
|
2171
|
+
return el.scrollTop + el.clientHeight >= el.scrollHeight - gap;
|
|
2172
|
+
}
|
|
2173
|
+
function FilterChecklist(props) {
|
|
2174
|
+
var items = props.items || [];
|
|
2175
|
+
var selected = props.selected || [];
|
|
2176
|
+
var disabled = props.disabled === true;
|
|
2177
|
+
var loading = props.loading === true;
|
|
2178
|
+
var hasMore = props.hasMore === true;
|
|
2179
|
+
var query = props.query || "";
|
|
2180
|
+
var total = typeof props.total === "number" ? props.total : items.length;
|
|
2181
|
+
var title = props.title || "\u5168\u90E8";
|
|
2182
|
+
var selectedText = props.selectedText || "\u5DF2\u9009";
|
|
2183
|
+
var clearText = props.clearText || "\u6E05\u7A7A";
|
|
2184
|
+
var searchPlaceholder = props.searchPlaceholder || "\u641C\u7D22";
|
|
2185
|
+
var emptyText = props.emptyText || "\u6682\u65E0\u6570\u636E";
|
|
2186
|
+
var noMatchText = props.noMatchText || "\u6CA1\u6709\u5339\u914D\u9879";
|
|
2187
|
+
var loadingText = props.loadingText || "\u52A0\u8F7D\u4E2D\u2026";
|
|
2188
|
+
var noMoreText = typeof props.noMoreText === "string" ? props.noMoreText : "\u6CA1\u6709\u66F4\u591A";
|
|
2189
|
+
var onToggle = props.onToggle || function() {
|
|
2190
|
+
};
|
|
2191
|
+
var onQuery = props.onQuery || function() {
|
|
2192
|
+
};
|
|
2193
|
+
var onLoadMore = props.onLoadMore;
|
|
2194
|
+
var onClear = props.onClear || function() {
|
|
2195
|
+
};
|
|
2196
|
+
function toggle(id) {
|
|
2197
|
+
if (disabled) return;
|
|
2198
|
+
onToggle(id);
|
|
2199
|
+
}
|
|
2200
|
+
function scroll(e) {
|
|
2201
|
+
if (disabled || loading || !hasMore || !onLoadMore) return;
|
|
2202
|
+
if (nearBottom(e.currentTarget)) onLoadMore();
|
|
2203
|
+
}
|
|
2204
|
+
var head = h2(
|
|
2205
|
+
"div",
|
|
2206
|
+
{ className: "wbck-head" },
|
|
2207
|
+
h2("span", { className: "wbck-grow" }, title + (total ? " \xB7 " + total : "")),
|
|
2208
|
+
selected.length ? h2("span", { className: "wbck-sel" }, selectedText + " " + selected.length) : null,
|
|
2209
|
+
selected.length || query ? h2("button", {
|
|
2210
|
+
type: "button",
|
|
2211
|
+
className: "wbck-clear",
|
|
2212
|
+
title: clearText,
|
|
2213
|
+
disabled,
|
|
2214
|
+
onClick: function() {
|
|
2215
|
+
if (disabled) return;
|
|
2216
|
+
onClear();
|
|
2217
|
+
}
|
|
2218
|
+
}, clearText) : null
|
|
2219
|
+
);
|
|
2220
|
+
var body;
|
|
2221
|
+
if (!items.length) {
|
|
2222
|
+
body = h2("div", { className: "wbck-note", role: "status" }, loading ? loadingText : query ? noMatchText : emptyText);
|
|
2223
|
+
} else {
|
|
2224
|
+
body = items.map(function(x) {
|
|
2225
|
+
var on = selected.indexOf(String(x.id)) >= 0;
|
|
2226
|
+
return h2(
|
|
2227
|
+
"label",
|
|
2228
|
+
{ key: x.id, className: "wbck-opt" + (on ? " is-on" : "") },
|
|
2229
|
+
h2("input", {
|
|
2230
|
+
type: "checkbox",
|
|
2231
|
+
checked: on,
|
|
2232
|
+
disabled,
|
|
2233
|
+
onChange: function() {
|
|
2234
|
+
toggle(x.id);
|
|
2235
|
+
}
|
|
2236
|
+
}),
|
|
2237
|
+
h2("span", { className: "wbck-nm", title: x.name }, x.name),
|
|
2238
|
+
x.meta ? h2("span", { className: "wbck-meta" }, x.meta) : null
|
|
2239
|
+
);
|
|
2240
|
+
});
|
|
2241
|
+
var more = loading ? loadingText : hasMore ? "" : noMoreText;
|
|
2242
|
+
if (more) body = body.concat([h2("div", { key: "__more", className: "wbck-more", role: "status" }, more)]);
|
|
2243
|
+
}
|
|
2244
|
+
return h2(
|
|
2245
|
+
"div",
|
|
2246
|
+
{ className: "wbck", "data-role": "checklist" },
|
|
2247
|
+
h2(
|
|
2248
|
+
"div",
|
|
2249
|
+
{ className: "wbck-search" },
|
|
2250
|
+
h2("input", {
|
|
2251
|
+
type: "search",
|
|
2252
|
+
autoFocus: props.autoFocus !== false,
|
|
2253
|
+
className: "wbck-input",
|
|
2254
|
+
placeholder: searchPlaceholder,
|
|
2255
|
+
"aria-label": searchPlaceholder,
|
|
2256
|
+
value: query,
|
|
2257
|
+
disabled,
|
|
2258
|
+
onChange: function(e) {
|
|
2259
|
+
onQuery(e.target.value);
|
|
2260
|
+
}
|
|
2261
|
+
})
|
|
2262
|
+
),
|
|
2263
|
+
props.beforeHead || null,
|
|
2264
|
+
head,
|
|
2265
|
+
h2("div", {
|
|
2266
|
+
className: "wbck-list",
|
|
2267
|
+
onScroll: scroll,
|
|
2268
|
+
"aria-busy": loading ? "true" : "false"
|
|
2269
|
+
}, body)
|
|
2270
|
+
);
|
|
2271
|
+
}
|
|
2272
|
+
module2.exports = FilterChecklist;
|
|
2273
|
+
module2.exports.nearBottom = nearBottom;
|
|
2274
|
+
}
|
|
2275
|
+
});
|
|
2276
|
+
|
|
2277
|
+
// packages/addons/storage/client/ui/tagfilter.cjs
|
|
2278
|
+
var require_tagfilter = __commonJS({
|
|
2279
|
+
"packages/addons/storage/client/ui/tagfilter.cjs"(exports2, module2) {
|
|
2280
|
+
var React = require("react");
|
|
2281
|
+
var ui = require_ui();
|
|
2282
|
+
var FilterChecklist = require_filter_checklist();
|
|
2283
|
+
var h2 = React.createElement;
|
|
2284
|
+
var tr = ui.tr;
|
|
2285
|
+
module2.exports = function TagFilter(props) {
|
|
2286
|
+
var api = props.api, lang = props.lang, enabled = props.enabled !== false, ids = props.ids || [], onChange = props.onChange;
|
|
2287
|
+
var openS = React.useState(false), open = openS[0], setOpen = openS[1];
|
|
2288
|
+
var queryS = React.useState(""), query = queryS[0], setQuery = queryS[1];
|
|
2289
|
+
var optsS = React.useState({ tags: [], total: 0, pageNumber: 0, hasMore: false }), opts = optsS[0], setOpts = optsS[1];
|
|
2290
|
+
var loadingS = React.useState(false), loading = loadingS[0], setLoading = loadingS[1];
|
|
2291
|
+
var namesS = React.useState({}), names = namesS[0], setNames = namesS[1];
|
|
2292
|
+
var seq = React.useRef(0);
|
|
2293
|
+
var load = React.useCallback(
|
|
2294
|
+
function(text, pageNumber, append) {
|
|
2295
|
+
var mine = ++seq.current;
|
|
2296
|
+
setLoading(true);
|
|
2297
|
+
return api.call("storageTags.search", { text: text || "", pageNumber, pageSize: 20 }).then(function(r) {
|
|
2298
|
+
if (mine !== seq.current) return;
|
|
2299
|
+
setLoading(false);
|
|
2300
|
+
if (!r || !r.ok) return;
|
|
2301
|
+
var out = r.result || {}, records = out.records || [], current = out.current || pageNumber, pages = out.pages || 0;
|
|
2302
|
+
setOpts(function(prev) {
|
|
2303
|
+
var list = append ? (prev.tags || []).slice() : [];
|
|
2304
|
+
var seen = {};
|
|
2305
|
+
list.forEach(function(x) {
|
|
2306
|
+
seen[String(x.id)] = true;
|
|
2307
|
+
});
|
|
2308
|
+
records.forEach(function(x) {
|
|
2309
|
+
if (!seen[String(x.id)]) list.push(x);
|
|
2310
|
+
});
|
|
2311
|
+
return { tags: list, total: out.total || 0, pageNumber: current, hasMore: current < pages };
|
|
2312
|
+
});
|
|
2313
|
+
setNames(function(prev) {
|
|
2314
|
+
var next = Object.assign({}, prev);
|
|
2315
|
+
records.forEach(function(x) {
|
|
2316
|
+
next[String(x.id)] = x.name;
|
|
2317
|
+
});
|
|
2318
|
+
return next;
|
|
2319
|
+
});
|
|
2320
|
+
}).catch(function() {
|
|
2321
|
+
if (mine === seq.current) setLoading(false);
|
|
2322
|
+
});
|
|
2323
|
+
},
|
|
2324
|
+
[api]
|
|
2325
|
+
);
|
|
2326
|
+
React.useEffect(
|
|
2327
|
+
function() {
|
|
2328
|
+
if (!open) return void 0;
|
|
2329
|
+
var timer = setTimeout(
|
|
2330
|
+
function() {
|
|
2331
|
+
load(query, 1, false);
|
|
2332
|
+
},
|
|
2333
|
+
query ? 200 : 0
|
|
2334
|
+
);
|
|
2335
|
+
return function() {
|
|
2336
|
+
clearTimeout(timer);
|
|
2337
|
+
};
|
|
2338
|
+
},
|
|
2339
|
+
[open, query, load, props.reloadKey]
|
|
2340
|
+
);
|
|
2341
|
+
React.useEffect(
|
|
2342
|
+
function() {
|
|
2343
|
+
if (!open || !ids.length) return;
|
|
2344
|
+
var wanted = ids.filter(function(id) {
|
|
2345
|
+
return !names[String(id)];
|
|
2346
|
+
});
|
|
2347
|
+
if (!wanted.length) return;
|
|
2348
|
+
api.call("storageTags.byIds", { ids: wanted }).then(function(r) {
|
|
2349
|
+
if (!r || !r.ok) return;
|
|
2350
|
+
var next = {};
|
|
2351
|
+
(r.result && r.result.records || []).forEach(function(x) {
|
|
2352
|
+
next[String(x.id)] = x.name;
|
|
2353
|
+
});
|
|
2354
|
+
if (!Object.keys(next).length) return;
|
|
2355
|
+
setNames(function(prev) {
|
|
2356
|
+
return Object.assign({}, prev, next);
|
|
2357
|
+
});
|
|
2358
|
+
}).catch(function() {
|
|
2359
|
+
});
|
|
2360
|
+
},
|
|
2361
|
+
[open, ids.join(",")]
|
|
2362
|
+
);
|
|
2363
|
+
React.useEffect(
|
|
2364
|
+
function() {
|
|
2365
|
+
if (!open) return void 0;
|
|
2366
|
+
function onKey(e) {
|
|
2367
|
+
if (e.key === "Escape") setOpen(false);
|
|
2368
|
+
}
|
|
2369
|
+
document.addEventListener("keydown", onKey);
|
|
2370
|
+
return function() {
|
|
2371
|
+
document.removeEventListener("keydown", onKey);
|
|
2372
|
+
};
|
|
2373
|
+
},
|
|
2374
|
+
[open]
|
|
2375
|
+
);
|
|
2376
|
+
function toggle(id) {
|
|
2377
|
+
var key = String(id), next = ids.slice(), i = next.indexOf(key);
|
|
2378
|
+
if (i >= 0) next.splice(i, 1);
|
|
2379
|
+
else next.push(key);
|
|
2380
|
+
onChange(next);
|
|
2381
|
+
}
|
|
2382
|
+
if (!enabled) return null;
|
|
2383
|
+
return h2(
|
|
2384
|
+
"div",
|
|
2385
|
+
{ className: "wbi-tagfilter" },
|
|
2386
|
+
h2(
|
|
2387
|
+
"button",
|
|
2388
|
+
{
|
|
2389
|
+
type: "button",
|
|
2390
|
+
className: "wbi-btn" + (ids.length ? " wbi-tagon" : ""),
|
|
2391
|
+
"aria-expanded": open ? "true" : "false",
|
|
2392
|
+
onClick: function(e) {
|
|
2393
|
+
e.stopPropagation();
|
|
2394
|
+
setOpen(!open);
|
|
2395
|
+
}
|
|
2396
|
+
},
|
|
2397
|
+
h2(ui.Icon, { name: "tag", size: 13 }),
|
|
2398
|
+
tr(lang, "\u6807\u7B7E\u7B5B\u9009", "Tag filter") + (ids.length ? " \xB7 " + ids.length : ""),
|
|
2399
|
+
"\u25BE"
|
|
2400
|
+
),
|
|
2401
|
+
open ? h2(
|
|
2402
|
+
"div",
|
|
2403
|
+
{ className: "wbi-tagmenu", role: "menu", onClick: function(e) {
|
|
2404
|
+
e.stopPropagation();
|
|
2405
|
+
} },
|
|
2406
|
+
h2(FilterChecklist, {
|
|
2407
|
+
beforeHead: ids.length ? h2(
|
|
2408
|
+
"div",
|
|
2409
|
+
{ className: "wbi-tagsel" },
|
|
2410
|
+
h2("div", { className: "wbi-tagmenu-head" }, h2("span", null, tr(lang, "\u5DF2\u9009", "Selected") + " " + ids.length)),
|
|
2411
|
+
h2(
|
|
2412
|
+
"div",
|
|
2413
|
+
{ className: "wbi-tagsel-list" },
|
|
2414
|
+
ids.map(function(id) {
|
|
2415
|
+
return h2(
|
|
2416
|
+
"button",
|
|
2417
|
+
{
|
|
2418
|
+
key: id,
|
|
2419
|
+
type: "button",
|
|
2420
|
+
className: "wbi-tagselitem",
|
|
2421
|
+
title: tr(lang, "\u79FB\u9664", "Remove"),
|
|
2422
|
+
onClick: function() {
|
|
2423
|
+
toggle(id);
|
|
2424
|
+
}
|
|
2425
|
+
},
|
|
2426
|
+
h2("span", { className: "wbi-tagnm" }, names[String(id)] || "#" + id),
|
|
2427
|
+
h2("span", { className: "wbi-tagx" }, "\xD7")
|
|
2428
|
+
);
|
|
2429
|
+
})
|
|
2430
|
+
)
|
|
2431
|
+
) : null,
|
|
2432
|
+
items: opts.tags.map(function(x) {
|
|
2433
|
+
return { id: x.id, name: x.name };
|
|
2434
|
+
}),
|
|
2435
|
+
selected: ids,
|
|
2436
|
+
onToggle: toggle,
|
|
2437
|
+
query,
|
|
2438
|
+
onQuery: setQuery,
|
|
2439
|
+
title: tr(lang, "\u5168\u90E8\u6807\u7B7E", "All tags"),
|
|
2440
|
+
total: opts.total,
|
|
2441
|
+
selectedText: tr(lang, "\u5DF2\u9009", "Selected"),
|
|
2442
|
+
clearText: tr(lang, "\u6E05\u7A7A", "Clear"),
|
|
2443
|
+
onClear: function() {
|
|
2444
|
+
onChange([]);
|
|
2445
|
+
setQuery("");
|
|
2446
|
+
},
|
|
2447
|
+
searchPlaceholder: tr(lang, "\u641C\u7D22\u6807\u7B7E\u540D\u79F0", "Search tag names"),
|
|
2448
|
+
loading,
|
|
2449
|
+
hasMore: opts.hasMore,
|
|
2450
|
+
onLoadMore: function() {
|
|
2451
|
+
load(query, (opts.pageNumber || 1) + 1, true);
|
|
2452
|
+
},
|
|
2453
|
+
emptyText: tr(lang, "\u6682\u65E0\u6807\u7B7E", "No tags yet"),
|
|
2454
|
+
noMatchText: tr(lang, "\u6CA1\u6709\u5339\u914D\u7684\u6807\u7B7E", "No matching tags"),
|
|
2455
|
+
loadingText: tr(lang, "\u52A0\u8F7D\u4E2D\u2026", "Loading\u2026"),
|
|
2456
|
+
noMoreText: tr(lang, "\u6CA1\u6709\u66F4\u591A", "No more")
|
|
2457
|
+
})
|
|
2458
|
+
) : null
|
|
2459
|
+
);
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
});
|
|
2463
|
+
|
|
1994
2464
|
// packages/addons/storage/client/ui/selection.cjs
|
|
1995
2465
|
var require_selection = __commonJS({
|
|
1996
2466
|
"packages/addons/storage/client/ui/selection.cjs"(exports2, module2) {
|
|
@@ -2101,11 +2571,12 @@ var require_records = __commonJS({
|
|
|
2101
2571
|
var h2 = ui.h;
|
|
2102
2572
|
var tr = ui.tr;
|
|
2103
2573
|
var StorageCard = require_card().StorageCard;
|
|
2574
|
+
var TagFilter = require_tagfilter();
|
|
2104
2575
|
var selection = require_selection();
|
|
2105
2576
|
function Records(props) {
|
|
2106
2577
|
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],
|
|
2578
|
+
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");
|
|
2579
|
+
var scope = JSON.stringify([query[0], text[0], page[0], size[0], sort[0], order[0], tagIds[0].join(","), tick[0]]);
|
|
2109
2580
|
var rows = items[0] && items[0].scope === scope ? items[0].records : [];
|
|
2110
2581
|
var selected = selection.useSelection(scope, rows, busy[0] || !!bulk[0]);
|
|
2111
2582
|
function deleteSelected() {
|
|
@@ -2167,7 +2638,7 @@ var require_records = __commonJS({
|
|
|
2167
2638
|
loading[1](true);
|
|
2168
2639
|
error[1](null);
|
|
2169
2640
|
var args = { text: text[0], pageNumber: page[0], pageSize: size[0], sortColumn: sort[0], sortOrder: order[0] };
|
|
2170
|
-
if (
|
|
2641
|
+
if (tagIds[0].length) args.tagIds = tagIds[0];
|
|
2171
2642
|
ui.call(api, "storage.list", args).then(function(r) {
|
|
2172
2643
|
if (!active) return;
|
|
2173
2644
|
if (page[0] > Math.max(1, r.pages || 1)) {
|
|
@@ -2276,23 +2747,19 @@ var require_records = __commonJS({
|
|
|
2276
2747
|
},
|
|
2277
2748
|
order[0] === "desc" ? tr(lang, "\u964D\u5E8F \u2193", "Descending \u2193") : tr(lang, "\u5347\u5E8F \u2191", "Ascending \u2191")
|
|
2278
2749
|
),
|
|
2279
|
-
h2(ui.Button, { icon: "refresh", onClick: refresh, disabled: loading[0] }, tr(lang, "\u5237\u65B0", "Refresh"))
|
|
2750
|
+
h2(ui.Button, { icon: "refresh", onClick: refresh, disabled: loading[0] }, tr(lang, "\u5237\u65B0", "Refresh")),
|
|
2751
|
+
h2(TagFilter, {
|
|
2752
|
+
api,
|
|
2753
|
+
lang,
|
|
2754
|
+
enabled: caps[0],
|
|
2755
|
+
ids: tagIds[0],
|
|
2756
|
+
reloadKey: tick[0],
|
|
2757
|
+
onChange: function(next) {
|
|
2758
|
+
tagIds[1](next);
|
|
2759
|
+
page[1](1);
|
|
2760
|
+
}
|
|
2761
|
+
})
|
|
2280
2762
|
),
|
|
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
2763
|
selected.mode ? h2("p", { className: "wbi-muted" }, tr(
|
|
2297
2764
|
lang,
|
|
2298
2765
|
"\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 +2772,7 @@ var require_records = __commonJS({
|
|
|
2305
2772
|
"div",
|
|
2306
2773
|
{ className: "wbi-empty" },
|
|
2307
2774
|
h2(ui.Icon, { name: "empty", size: 48 }),
|
|
2308
|
-
text[0] ||
|
|
2775
|
+
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
2776
|
) : null,
|
|
2310
2777
|
h2(
|
|
2311
2778
|
"div",
|
|
@@ -2319,11 +2786,12 @@ var require_records = __commonJS({
|
|
|
2319
2786
|
caps: caps[0],
|
|
2320
2787
|
busy: busy[0] || !!bulk[0],
|
|
2321
2788
|
date,
|
|
2789
|
+
keyword: String(text[0] || "").trim(),
|
|
2322
2790
|
selectionMode: selected.mode,
|
|
2323
2791
|
checked: selected.ids.includes(item.id),
|
|
2324
2792
|
onCheck: selected.toggle,
|
|
2325
2793
|
onTag: function(t) {
|
|
2326
|
-
|
|
2794
|
+
tagIds[1]([String(t.id)]);
|
|
2327
2795
|
page[1](1);
|
|
2328
2796
|
},
|
|
2329
2797
|
onPreview: preview[1],
|
|
@@ -3448,7 +3916,9 @@ var require_data_view = __commonJS({
|
|
|
3448
3916
|
}
|
|
3449
3917
|
function loadTables() {
|
|
3450
3918
|
setLoadingTables(true);
|
|
3451
|
-
Promise.resolve(
|
|
3919
|
+
Promise.resolve((options.tablesLoader || function(a) {
|
|
3920
|
+
return a.call(DOMAIN + ".dataTables");
|
|
3921
|
+
})(api)).then(function(r) {
|
|
3452
3922
|
if (r && r.ok === false) throw new Error(r && r.error || t.loadFail);
|
|
3453
3923
|
var body = unwrap(r);
|
|
3454
3924
|
if (!body || !Array.isArray(body.tables)) throw new Error(t.loadFail);
|
|
@@ -3513,7 +3983,9 @@ var require_data_view = __commonJS({
|
|
|
3513
3983
|
if (sort) args.sort = sort;
|
|
3514
3984
|
if (search) args.search = search;
|
|
3515
3985
|
if (Object.keys(filters).length) args.filters = filters;
|
|
3516
|
-
Promise.resolve(
|
|
3986
|
+
Promise.resolve((options.query || function(a, q) {
|
|
3987
|
+
return a.call(DOMAIN + ".dataQuery", q);
|
|
3988
|
+
})(api, args)).then(function(r) {
|
|
3517
3989
|
if (req !== reqRef.current) return;
|
|
3518
3990
|
if (r && r.ok === false) throw new Error(r && r.error || t.queryFail);
|
|
3519
3991
|
var body = unwrap(r);
|
|
@@ -3895,7 +4367,7 @@ var require_data_view = __commonJS({
|
|
|
3895
4367
|
}
|
|
3896
4368
|
}
|
|
3897
4369
|
}),
|
|
3898
|
-
h2("span", null, fmt(t.queryTime, { n: data
|
|
4370
|
+
data && data.queryMs !== void 0 ? h2("span", null, fmt(t.queryTime, { n: data.queryMs })) : null
|
|
3899
4371
|
);
|
|
3900
4372
|
}
|
|
3901
4373
|
if (!tables && loadingTables && options.Skeleton) return h2(options.Skeleton, { lang, label: t.loading });
|
|
@@ -3931,7 +4403,7 @@ var require_data_view = __commonJS({
|
|
|
3931
4403
|
"span",
|
|
3932
4404
|
{ className: P + "-stabname" },
|
|
3933
4405
|
h2("span", null, tableLabel(tb)),
|
|
3934
|
-
h2("span", { className: P + "-sidecount" }, String(tb.count))
|
|
4406
|
+
h2("span", { className: P + "-sidecount" }, tb.count === void 0 || tb.count === null ? "" : String(tb.count))
|
|
3935
4407
|
),
|
|
3936
4408
|
h2("span", { className: P + "-sidetable" }, tb.name)
|
|
3937
4409
|
);
|
|
@@ -3958,7 +4430,7 @@ var require_data_view = __commonJS({
|
|
|
3958
4430
|
h2(
|
|
3959
4431
|
"div",
|
|
3960
4432
|
{ className: P + "-sub" },
|
|
3961
|
-
current ? fmt(t.rowCount, { n:
|
|
4433
|
+
current && data && data.total !== void 0 ? fmt(t.rowCount, { n: data.total }) : "",
|
|
3962
4434
|
current && current.deletedCount ? " \xB7 " + fmt(t.deletedCount, { n: current.deletedCount }) : "",
|
|
3963
4435
|
" \xB7 " + t.subtitle
|
|
3964
4436
|
)
|
|
@@ -4164,50 +4636,6 @@ var require_data = __commonJS({
|
|
|
4164
4636
|
}
|
|
4165
4637
|
});
|
|
4166
4638
|
|
|
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
4639
|
// packages/addons/lib/action-schema-style.cjs
|
|
4212
4640
|
var require_action_schema_style = __commonJS({
|
|
4213
4641
|
"packages/addons/lib/action-schema-style.cjs"(exports2, module2) {
|
|
@@ -4591,7 +5019,7 @@ var require_action_schema_view = __commonJS({
|
|
|
4591
5019
|
"div",
|
|
4592
5020
|
{ className: P + "-cardhead" },
|
|
4593
5021
|
h2("code", { className: P + "-mono" }, Highlight.hit(action.name, kw)),
|
|
4594
|
-
|
|
5022
|
+
// 域名在页头已展示一次,卡片内不再重复(所有条目必然同域,见 visible 过滤)。
|
|
4595
5023
|
h2("span", { className: P + "-badge" }, rows.length ? t.paramCount(rows.length) : t.noParams),
|
|
4596
5024
|
rows.some(function(row) {
|
|
4597
5025
|
return row.required;
|
|
@@ -4758,7 +5186,8 @@ if (host) {
|
|
|
4758
5186
|
h = require("react").createElement, Icon2 = require_icons().Icon;
|
|
4759
5187
|
host.registerAddon({
|
|
4760
5188
|
id: "wb-addon-storage",
|
|
4761
|
-
version: "1.5.
|
|
5189
|
+
version: "1.5.5",
|
|
5190
|
+
icon: (init_package(), __toCommonJS(package_exports)).default,
|
|
4762
5191
|
views: [
|
|
4763
5192
|
{ id: "stats", icon: tabIcon2("chart"), title: { zh: "\u7EDF\u8BA1", en: "Statistics" }, component: require_stats().Stats },
|
|
4764
5193
|
{ 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.5",
|
|
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.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "个人工作台储物插件:名称、品牌、位置、单位、库存文本与标签",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"id": "wb-addon-storage",
|
|
10
10
|
"title": "储物",
|
|
11
11
|
"description": "储物:统计/记录/配置/数据四个视图",
|
|
12
|
-
"version": "1.5.
|
|
12
|
+
"version": "1.5.5",
|
|
13
13
|
"minShell": "0.5.7",
|
|
14
14
|
"tables": [
|
|
15
15
|
"storage"
|
|
@@ -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.7.0"
|
|
51
51
|
},
|
|
52
52
|
"dsh": {
|
|
53
53
|
"bundle": {
|