feat: variables 2.0 state + L0 summary integration
This commit is contained in:
@@ -667,6 +667,62 @@ export function lwbPushVarPath(path, value) {
|
||||
}
|
||||
}
|
||||
|
||||
export function lwbRemoveArrayItemByValue(path, valuesToRemove) {
|
||||
try {
|
||||
const segs = lwbSplitPathWithBrackets(path);
|
||||
if (!segs.length) return '';
|
||||
|
||||
const rootName = String(segs[0]);
|
||||
const rootRaw = getLocalVariable(rootName);
|
||||
const rootObj = maybeParseObject(rootRaw);
|
||||
if (!rootObj) return '';
|
||||
|
||||
// 定位到目标数组
|
||||
let cur = rootObj;
|
||||
for (let i = 1; i < segs.length; i++) {
|
||||
cur = cur?.[segs[i]];
|
||||
if (cur == null) return '';
|
||||
}
|
||||
if (!Array.isArray(cur)) return '';
|
||||
|
||||
const toRemove = Array.isArray(valuesToRemove) ? valuesToRemove : [valuesToRemove];
|
||||
if (!toRemove.length) return '';
|
||||
|
||||
// 找到索引(每个值只删除一个匹配项)
|
||||
const indices = [];
|
||||
for (const v of toRemove) {
|
||||
const vStr = safeJSONStringify(v);
|
||||
if (!vStr) continue;
|
||||
const idx = cur.findIndex(x => safeJSONStringify(x) === vStr);
|
||||
if (idx !== -1) indices.push(idx);
|
||||
}
|
||||
if (!indices.length) return '';
|
||||
|
||||
// 倒序删除,且逐个走 guardian 的 delNode 校验(用 index path)
|
||||
indices.sort((a, b) => b - a);
|
||||
|
||||
for (const idx of indices) {
|
||||
const absIndexPath = normalizePath(`${path}[${idx}]`);
|
||||
|
||||
try {
|
||||
if (globalThis.LWB_Guard?.validate) {
|
||||
const g = globalThis.LWB_Guard.validate('delNode', absIndexPath);
|
||||
if (!g?.allow) continue;
|
||||
}
|
||||
} catch {}
|
||||
|
||||
if (idx >= 0 && idx < cur.length) {
|
||||
cur.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
setLocalVariable(rootName, safeJSONStringify(rootObj));
|
||||
return '';
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function registerXbGetVarSlashCommand() {
|
||||
try {
|
||||
const ctx = getContext();
|
||||
|
||||
Reference in New Issue
Block a user