601451f22b
Overlay ~150 upstream items onto our V8.12 base, preserving trade-pro
theme, registry tests, and design docs. Re-applied our patch set
(discovery/env_for/blocks.css/type-mapping/theme_color/frontend entries,
test_theme_pro_v3 mods) — all anchors survived upstream evolution.
New platform enhancement (fixes upgrade-introduced regression):
multilingual.site_locale now honors settings_json.locale, plus
PUT /api/i18n/sites/{id}/locale — standalone English sites get
<html lang='en'> under the V8.15 locale-rewrite pipeline.
compose: adopt V8.21.3 (image 8.21.3-dev.1, /api/ready probes, MySQL/S3
env) with project name pinned to siteforge-v8-10 (data volumes).
Tests: 356 passed / 11 failed — all 11 confirmed pre-existing in
pristine V8.21.3 on this host (10 upstream Windows env + our build test
now green after locale fix). Patch registry updated in plan doc.
Co-Authored-By: Claude Code <noreply@anthropic.com>
40 lines
2.0 KiB
JavaScript
40 lines
2.0 KiB
JavaScript
/* Safe, deterministic editor operations. Exported for Node regression tests. */
|
|
(function (root, factory) {
|
|
const api=factory();
|
|
if(typeof module==='object' && module.exports)module.exports=api;
|
|
root.SiteForgeEditorHelpers=api;
|
|
})(typeof window!=='undefined'?window:globalThis, function(){
|
|
'use strict';
|
|
const deepCopy=value=>JSON.parse(JSON.stringify(value));
|
|
function reorder(items, from, to){
|
|
if(!Array.isArray(items)||!Number.isInteger(from)||!Number.isInteger(to)||from<0||to<0||from>=items.length||to>=items.length)return null;
|
|
if(from===to)return items.slice();
|
|
const next=items.slice();next.splice(to,0,next.splice(from,1)[0]);return next;
|
|
}
|
|
function duplicate(block, idFactory){
|
|
if(!block || typeof idFactory!=='function')throw Error('无效的区块');
|
|
const item=deepCopy(block);
|
|
const rewrite=node=>{
|
|
node.id=idFactory();
|
|
if(node.type==='layout')for(const col of node.columns||[])for(const child of col.blocks||[])rewrite(child);
|
|
};
|
|
rewrite(item);return item;
|
|
}
|
|
function filterBlocks(blocks, term, names={}){
|
|
const query=String(term||'').trim().toLocaleLowerCase();
|
|
if(!query)return blocks.map((block,index)=>({block,index}));
|
|
return blocks.flatMap((block,index)=>{
|
|
const description=[block.title,block.subtitle,block.type,names[block.type]?.name]
|
|
.concat(block.type==='layout'?(block.columns||[]).flatMap(c=>(c.blocks||[]).map(b=>b.title||b.type)):[])
|
|
.filter(x=>typeof x==='string').join(' ').toLocaleLowerCase();
|
|
return description.includes(query)?[{block,index}]:[];
|
|
});
|
|
}
|
|
function historyState(snapshots,cursor){return {canUndo:cursor>0,canRedo:cursor>=0&&cursor<snapshots.length-1};}
|
|
function clampNumber(value,min,max,fallback){const n=Number(value);return Number.isFinite(n)?Math.max(min,Math.min(max,n)):fallback;}
|
|
function shouldAcceptPreview(requestedPage,requestedSeq,currentPage,currentSeq){
|
|
return requestedPage===currentPage&&requestedSeq===currentSeq;
|
|
}
|
|
return {reorder,duplicate,filterBlocks,historyState,clampNumber,shouldAcceptPreview};
|
|
});
|