From b31958c6304a25279197c1a08b924b6b44798a99 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Fri, 10 Jul 2026 18:53:26 -0400 Subject: feat(admin): use intereditor.js for mob talk editor to further unify condition/action system --- internal/admin/static/intereditor.js | 523 ++++++++++++++++++++--------------- 1 file changed, 297 insertions(+), 226 deletions(-) (limited to 'internal/admin/static/intereditor.js') diff --git a/internal/admin/static/intereditor.js b/internal/admin/static/intereditor.js index 0e2c03d..152aef3 100644 --- a/internal/admin/static/intereditor.js +++ b/internal/admin/static/intereditor.js @@ -51,6 +51,132 @@ IE_ACT_TYPES.forEach(function(at) { IE_STEP_KINDS.push(at); }); +// ── Scope / Context system ── +// Lets condition & action editors target data models outside the +// default ed[secPath][idx].steps[si] arrangement (e.g. talk node/option +// conditions and single-step actions). When a scope is registered and its +// token is placed on a DOM root via data-ie-scope, all mutation onclicks +// resolve their data target through the scope instead of the legacy trigger +// path. + +window._ieScopes = {}; +var _ieScopeSeq = 0; + +function ie_registerScope(opts, token) { + if (!token) { + token = 'sc' + (++_ieScopeSeq); + } + window._ieScopes[token] = opts; + return token; +} +window.ie_registerScope = ie_registerScope; + +function ie_unregisterScope(token) { + delete window._ieScopes[token]; +} +window.ie_unregisterScope = ie_unregisterScope; + +function _ie_scopeFromEl(el) { + if (!el || !el.closest) return null; + var scopeEl = el.closest('[data-ie-scope]'); + if (!scopeEl) return null; + var token = scopeEl.getAttribute('data-ie-scope'); + return window._ieScopes[token] || null; +} + +// Resolve the .ie-cond-root DOM element scoped to a mutation element el. +// Handles both the root itself and the outer addbar (which sits outside +// .ie-cond-root as a sibling). +function _ie_condScopeRoot(el) { + var root = el.closest('.ie-cond-root'); + if (root) return root; + var addbar = el.closest('.ie-cond-addbar'); + if (!addbar) return null; + var parent = addbar.parentElement; + if (!parent) return null; + return parent.querySelector('.ie-cond-root'); +} + +// Unified condition-editing context. +// Returns { get, set, change } — `get` always syncs DOM → data store +// before returning. Routes through a registered scope when el lives inside +// [data-ie-scope], otherwise through the legacy ed[secPath][idx] trigger path. +function _ie_condCtx(el, secId, secPath, idx, kind) { + var scope = _ie_scopeFromEl(el); + if (scope) { + return { + get: function() { + var root = _ie_condScopeRoot(el); + if (root) { + var cond = ie_collectCond(root); + scope.setCond(cond); + } + return scope.getCond(); + }, + set: function(c) { scope.setCond(c); }, + change: function() { scope.onChange(); } + }; + } + return { + get: function() { + var ed = window._editorData; + if (!ed) return null; + _ie_syncCond(ed, secId, secPath, idx, kind); + return _ie_getCond(ed, secPath, idx, kind); + }, + set: function(c) { + var ed = window._editorData; + if (!ed) return; + _ie_setCond(ed, secPath, idx, kind, c); + ced_syncDOMToData(ed); + }, + change: function() { window._ieRenderOnly(); } + }; +} + +// Unified action/step-editing context. +// Returns { get, set, change }. In scope mode reads the .ie-act-root +// container; in legacy mode operates on ed[secPath][idx].steps[si]. +function _ie_actCtx(el, secId, secPath, idx, si) { + var scope = _ie_scopeFromEl(el); + if (scope) { + return { + get: function() { + var container = el.closest('.ie-act-root'); + if (!container) return scope.getStep() || {}; + var act = ie_collectAct(container); + var msgs = ie_collectMessages(container); + var step = scope.getStep() || {}; + if (act) Object.keys(act).forEach(function(k) { step[k] = act[k]; }); + if (msgs !== null) step.messages = msgs; else delete step.messages; + scope.setStep(step); + return scope.getStep(); + }, + set: function(s) { scope.setStep(s); }, + change: function() { scope.onChange(); } + }; + } + return { + get: function() { + var ed = window._editorData; + if (!ed) return {}; + ie_syncStep(ed, secId, secPath, idx, si); + if (!ed[secPath] || !ed[secPath][idx] || !ed[secPath][idx].steps || !ed[secPath][idx].steps[si]) return {}; + return ed[secPath][idx].steps[si]; + }, + set: function(s) { + var ed = window._editorData; + if (!ed) return; + if (!ed[secPath]) ed[secPath] = []; + if (!ed[secPath][idx]) ed[secPath][idx] = {steps: []}; + if (!ed[secPath][idx].steps) ed[secPath][idx].steps = []; + ed[secPath][idx].steps[si] = s; + ced_syncDOMToData(ed); + }, + change: function() { window._ieRenderOnly(); } + }; +} + // ── Rendering helpers ── // ie_renderStepAddbar: the per-step action add bar revealed by the "+" toggle. @@ -67,9 +193,9 @@ function ie_renderStepAddbar(step, secId, idx, si, secPath) { } } if (sk.key === 'messages') { - h += ''; + h += ''; } else { - h += ''; + h += ''; } }); return h; @@ -80,7 +206,7 @@ function ie_renderStepAddbar(step, secId, idx, si, secPath) { function ie_renderBottomAddbar(secId, secPath, idx) { var h = ''; IE_STEP_KINDS.forEach(function(sk) { - h += ''; + h += ''; }); return h; } @@ -142,7 +268,7 @@ function ie_collectDropTableBlock(container) { } // ie_addStepKind creates a new step initialised with a single action kind. -function ie_addStepKind(secId, secPath, idx, kind) { +function ie_addStepKind(el, secId, secPath, idx, kind) { var ed = window._editorData; if (!ed) return; ced_syncDOMToData(ed); @@ -387,6 +513,8 @@ function ie_collectLeaf(el) { function ie_renderCond(condObj, secId, idx, secPath, kind, opts) { kind = kind || 'entry'; + opts = opts || {}; + var scopeAttr = opts.scopeToken ? ' data-ie-scope="' + escAttr(opts.scopeToken) + '"' : ''; var h = ''; var isGroup = condObj && (condObj.all_of || condObj.any_of); var rootChildCount = isGroup ? (condObj.all_of || condObj.any_of || []).length : 0; @@ -395,21 +523,21 @@ function ie_renderCond(condObj, secId, idx, secPath, kind, opts) { if (kind && kind.indexOf('step-') === 0) { var sn = parseInt(kind.slice(5), 10); if (!isNaN(sn)) condTitleText = 'Condition for Step ' + (sn + 1); - } else if (kind === 'entry') { + } else if (kind === 'entry' && !opts.scopeToken) { condTitleText = 'Condition for Action Block'; } - h += '
'; + h += '
'; if (condTitleText) h += '
' + esc(condTitleText) + '
'; h += ie_renderGroup(condObj, secId, secPath, idx, '', kind); h += '
'; } - var showAddbar = !isGroup || (opts && opts.alwaysOuterAddbar && rootChildCount === 0); + var showAddbar = (!isGroup || (opts.alwaysOuterAddbar && rootChildCount === 0)) && typeof condObj === 'object'; if (showAddbar) { - h += '
'; + h += '
'; IE_COND_TYPES.forEach(function(ct) { - h += ''; + h += ''; }); - h += ''; + h += ''; h += '
'; } return h; @@ -442,10 +570,10 @@ function _ie_renderGroupNode(mode, children, not, secId, secPath, idx, gpath, ki h += '
'; h += '
'; IE_COND_TYPES.forEach(function(ct) { - h += ''; + h += ''; }); - h += ''; - h += ''; + h += ''; + h += ''; h += '
'; h += '
'; return h; @@ -454,13 +582,13 @@ function _ie_renderGroupNode(mode, children, not, secId, secPath, idx, gpath, ki h += '
'; h += '
'; if (children.length >= 2) { - h += ''; h += ''; h += ''; h += ''; } if (children.length >= 2 || not) { - h += ''; + h += ''; } h += '
'; h += '
'; @@ -481,9 +609,9 @@ function _ie_renderGroupNode(mode, children, not, secId, secPath, idx, gpath, ki h += '
'; h += '
'; IE_COND_TYPES.forEach(function(ct) { - h += ''; + h += ''; }); - h += ''; + h += ''; h += '
'; h += '
'; return h; @@ -516,8 +644,8 @@ function _ie_renderLeaf(leafType, leafVal, leafSub, not, secId, secPath, idx, gp h += '='; h += ''; } - h += ''; - h += ''; + h += ''; + h += ''; h += '
'; return h; } @@ -554,27 +682,27 @@ function ie_renderAct(stepObj, secId, idx, si, secPath) { }); } rows += '
'; - rows += ''; + rows += ''; rows += ''; } else if (at.kind === 'checkbox') { rows += '
' + esc(at.label) + ''; rows += ''; - rows += ''; + rows += ''; rows += '
'; } else if (at.kind === 'search') { rows += '
' + esc(at.label) + ''; rows += ''; - rows += ''; + rows += ''; rows += '
'; } else if (at.kind === 'droptable') { rows += '
'; - rows += '
Drop Table
'; - rows += ie_renderDropTableBlock(val, 'ie_addDropRow(\''+escAttr(secId)+'\',\''+escAttr(secPath)+'\','+idx+','+si+',\'item\')', 'ie_addDropRow(\''+escAttr(secId)+'\',\''+escAttr(secPath)+'\','+idx+','+si+',\'table\')', 'ie_removeDropRow(\''+escAttr(secId)+'\',\''+escAttr(secPath)+'\','+idx+','+si+',__RI__)'); + rows += '
Drop Table
'; + rows += ie_renderDropTableBlock(val, 'ie_addDropRow(this,\''+escAttr(secId)+'\',\''+escAttr(secPath)+'\','+idx+','+si+',\'item\')', 'ie_addDropRow(this,\''+escAttr(secId)+'\',\''+escAttr(secPath)+'\','+idx+','+si+',\'table\')', 'ie_removeDropRow(this,\''+escAttr(secId)+'\',\''+escAttr(secPath)+'\','+idx+','+si+',__RI__)'); rows += '
'; } else { rows += '
' + esc(at.label) + ''; rows += ''; - rows += ''; + rows += ''; rows += '
'; } }); @@ -599,15 +727,15 @@ function ie_renderMessages(step, secId, idx, si, secPath) { h += '
'; msgs.forEach(function(m, mi) { var upBtn = mi > 0 - ? '' + ? '' : ''; var dnBtn = mi < msgs.length - 1 - ? '' + ? '' : ''; h += '
' + upBtn + dnBtn + '
'; }); h += '
'; - h += ''; + h += ''; h += ''; return h; } @@ -624,12 +752,12 @@ function ie_renderStepList(steps, secId, idx, secPath) { h += 'Step ' + (si + 1) + ''; h += ''; if (!stepCond) { - h += ''; + h += ''; } h += ''; - if (si > 0) h += ''; - if (si < steps.length - 1) h += ''; - h += ''; + if (si > 0) h += ''; + if (si < steps.length - 1) h += ''; + h += ''; h += ''; if (stepCond) { @@ -789,16 +917,12 @@ function ie_syncAllInteractions(data, secs) { // ── Add/Remove/Toggle: Condition ── -function ie_addLeaf(secId, secPath, idx, kind, groupPath, leafType) { - var ed = window._editorData; - if (!ed) return; - _ie_syncCond(ed, secId, secPath, idx, kind); - var cond = _ie_getCond(ed, secPath, idx, kind); - var group = ie_condAt(cond, groupPath); - +function ie_addLeaf(el, secId, secPath, idx, kind, groupPath, leafType) { + var c = _ie_condCtx(el, secId, secPath, idx, kind); + var cond = c.get(); var leaf = {}; leaf[leafType] = (leafType === 'min_credits' || leafType === 'room') ? 0 : ''; - + var group = ie_condAt(cond, groupPath); var newGroup; if (!group) { newGroup = leaf; @@ -811,29 +935,21 @@ function ie_addLeaf(secId, secPath, idx, kind, groupPath, leafType) { } else { newGroup = {all_of: [group, leaf]}; } - - var newCond = ie_condReplace(cond, groupPath, newGroup); - _ie_setCond(ed, secPath, idx, kind, newCond); - ced_syncDOMToData(ed); - window._ieRenderOnly(); + cond = ie_condReplace(cond, groupPath, newGroup); + c.set(cond); + c.change(); } -function ie_removeCond(secId, secPath, idx, kind, groupPath, childIdx) { - var ed = window._editorData; - if (!ed) return; - _ie_syncCond(ed, secId, secPath, idx, kind); - var cond = _ie_getCond(ed, secPath, idx, kind); - +function ie_removeCond(el, secId, secPath, idx, kind, groupPath, childIdx) { + var c = _ie_condCtx(el, secId, secPath, idx, kind); + var cond = c.get(); if (childIdx === IE_ROOT_LEAF) { - _ie_setCond(ed, secPath, idx, kind, null); - ced_syncDOMToData(ed); - window._ieRenderOnly(); + c.set(null); + c.change(); return; } - var group = ie_condAt(cond, groupPath); if (!group) return; - if (group.all_of || group.any_of) { var mode = group.all_of ? 'all_of' : 'any_of'; var children = (group.all_of || group.any_of).slice(); @@ -848,39 +964,30 @@ function ie_removeCond(secId, secPath, idx, kind, groupPath, childIdx) { if (group.not) newGroup.not = true; newGroup[mode] = children; } - var newCond = ie_condReplace(cond, groupPath, newGroup); - _ie_setCond(ed, secPath, idx, kind, newCond); + cond = ie_condReplace(cond, groupPath, newGroup); } else { - var nc = ie_condReplace(cond, groupPath, null); - _ie_setCond(ed, secPath, idx, kind, nc); + cond = ie_condReplace(cond, groupPath, null); } - ced_syncDOMToData(ed); - window._ieRenderOnly(); + c.set(cond); + c.change(); } -function ie_removeGroup(secId, secPath, idx, kind, groupPath) { - var ed = window._editorData; - if (!ed) return; - _ie_syncCond(ed, secId, secPath, idx, kind); - var cond = _ie_getCond(ed, secPath, idx, kind); - +function ie_removeGroup(el, secId, secPath, idx, kind, groupPath) { + var c = _ie_condCtx(el, secId, secPath, idx, kind); + var cond = c.get(); if (!groupPath) { - _ie_setCond(ed, secPath, idx, kind, null); - ced_syncDOMToData(ed); - window._ieRenderOnly(); + c.set(null); + c.change(); return; } - var parts = groupPath.split('-').map(Number); var childIdx = parts[parts.length - 1]; var parentPath = parts.slice(0, -1).join('-'); var parent = ie_condAt(cond, parentPath); if (!parent || !(parent.all_of || parent.any_of)) return; - var mode = parent.all_of ? 'all_of' : 'any_of'; var children = parent[mode].slice(); children.splice(childIdx, 1); - var newParent; if (children.length === 0) { newParent = null; @@ -891,11 +998,9 @@ function ie_removeGroup(secId, secPath, idx, kind, groupPath) { if (parent.not) newParent.not = true; newParent[mode] = children; } - - var newCond = ie_condReplace(cond, parentPath, newParent); - _ie_setCond(ed, secPath, idx, kind, newCond); - ced_syncDOMToData(ed); - window._ieRenderOnly(); + cond = ie_condReplace(cond, parentPath, newParent); + c.set(cond); + c.change(); } function ie_addRootConditionGroup(secPath, idx, kind) { @@ -919,19 +1024,21 @@ function ie_addRootConditionGroup(secPath, idx, kind) { window._ieRenderOnly(); } -function ie_addStepCond(secId, secPath, idx, si) { +function ie_addStepCond(el, secId, secPath, idx, si) { + if (el && el.nodeType && _ie_scopeFromEl(el)) { + var c = _ie_condCtx(el, secId, secPath, idx, 'step-' + si); + c.get(); + c.change(); + return; + } ie_addRootConditionGroup(secPath, idx, 'step-' + si); } -function ie_addGroup(secId, secPath, idx, kind, groupPath) { - var ed = window._editorData; - if (!ed) return; - _ie_syncCond(ed, secId, secPath, idx, kind); - var cond = _ie_getCond(ed, secPath, idx, kind); +function ie_addGroup(el, secId, secPath, idx, kind, groupPath) { + var c = _ie_condCtx(el, secId, secPath, idx, kind); + var cond = c.get(); var group = ie_condAt(cond, groupPath); - var newSub = {all_of: []}; - var newGroup; if (!group) { newGroup = newSub; @@ -944,78 +1051,59 @@ function ie_addGroup(secId, secPath, idx, kind, groupPath) { } else { newGroup = {all_of: [group, newSub]}; } - - var newCond = ie_condReplace(cond, groupPath, newGroup); - _ie_setCond(ed, secPath, idx, kind, newCond); - ced_syncDOMToData(ed); - window._ieRenderOnly(); + cond = ie_condReplace(cond, groupPath, newGroup); + c.set(cond); + c.change(); } -function ie_addOuterLeaf(secId, secPath, idx, kind, leafType) { - var ed = window._editorData; - if (!ed) return; - _ie_syncCond(ed, secId, secPath, idx, kind); - var cond = _ie_getCond(ed, secPath, idx, kind); - +function ie_addOuterLeaf(el, secId, secPath, idx, kind, leafType) { + var c = _ie_condCtx(el, secId, secPath, idx, kind); + var cond = c.get(); var leaf = {}; leaf[leafType] = (leafType === 'min_credits' || leafType === 'room') ? 0 : ''; - - var newCond; if (!cond) { - newCond = leaf; + cond = leaf; } else { - newCond = {all_of: [cond, leaf]}; + cond = {all_of: [cond, leaf]}; } - - _ie_setCond(ed, secPath, idx, kind, newCond); - ced_syncDOMToData(ed); - window._ieRenderOnly(); + c.set(cond); + c.change(); } -function ie_addOuterGroup(secId, secPath, idx, kind) { - var ed = window._editorData; - if (!ed) return; - _ie_syncCond(ed, secId, secPath, idx, kind); - var cond = _ie_getCond(ed, secPath, idx, kind); - +function ie_addOuterGroup(el, secId, secPath, idx, kind) { + var c = _ie_condCtx(el, secId, secPath, idx, kind); + var cond = c.get(); var newSub = {all_of: []}; - - var newCond; if (!cond) { - newCond = newSub; + cond = newSub; } else { - newCond = {all_of: [cond, newSub]}; + cond = {all_of: [cond, newSub]}; } - - _ie_setCond(ed, secPath, idx, kind, newCond); - ced_syncDOMToData(ed); - window._ieRenderOnly(); + c.set(cond); + c.change(); } -function ie_toggleCondMode(secId, secPath, idx, kind, groupPath) { - var ed = window._editorData; - if (!ed) return; - _ie_syncCond(ed, secId, secPath, idx, kind); - window._ieRenderOnly(); +function ie_toggleCondMode(el, secId, secPath, idx, kind, groupPath) { + var c = _ie_condCtx(el, secId, secPath, idx, kind); + c.get(); + c.change(); } -function ie_toggleCondNot(secId, secPath, idx, kind, groupPath) { - var ed = window._editorData; - if (!ed) return; - _ie_syncCond(ed, secId, secPath, idx, kind); - window._ieRenderOnly(); +function ie_toggleCondNot(el, secId, secPath, idx, kind, groupPath) { + var c = _ie_condCtx(el, secId, secPath, idx, kind); + c.get(); + c.change(); } -function ie_toggleNotLeaf(secId, secPath, idx, kind, groupPath, ci) { - var ed = window._editorData; - if (!ed) return; - _ie_syncCond(ed, secId, secPath, idx, kind); - window._ieRenderOnly(); +function ie_toggleNotLeaf(el, secId, secPath, idx, kind, groupPath, ci) { + var c = _ie_condCtx(el, secId, secPath, idx, kind); + c.get(); + c.change(); } // ── Add/Remove: Steps ── -function ie_removeStep(secId, secPath, idx, si) { +function ie_removeStep(el, secId, secPath, idx, si) { var ed = window._editorData; if (!ed) return; ced_syncDOMToData(ed); @@ -1025,7 +1113,7 @@ function ie_removeStep(secId, secPath, idx, si) { window._ieRenderCurrent(); } -function ie_moveStep(secId, secPath, idx, fromSi, toSi) { +function ie_moveStep(el, secId, secPath, idx, fromSi, toSi) { var ed = window._editorData; if (!ed) return; ced_syncDOMToData(ed); @@ -1049,62 +1137,54 @@ function ie_moveRow(secPath, fromIdx, toIdx) { window._ieRenderOnly(); } -function ie_moveMessage(secId, secPath, idx, si, fromMi, toMi) { - var ed = window._editorData; - if (!ed) return; - ced_syncDOMToData(ed); - ie_syncStep(ed, secId, secPath, idx, si); - var step = ed[secPath] && ed[secPath][idx] && ed[secPath][idx].steps && ed[secPath][idx].steps[si]; +function ie_moveMessage(el, secId, secPath, idx, si, fromMi, toMi) { + var c = _ie_actCtx(el, secId, secPath, idx, si); + var step = c.get(); if (!step || !Array.isArray(step.messages)) return; if (fromMi < 0 || fromMi >= step.messages.length || toMi < 0 || toMi >= step.messages.length) return; var m = step.messages.splice(fromMi, 1)[0]; step.messages.splice(toMi, 0, m); - window._ieRenderOnly(); + c.set(step); + c.change(); } // ── Add/Remove: Action effects ── -function ie_addActEffect(secId, secPath, idx, si, effectKey) { - var ed = window._editorData; - if (!ed) return; - ie_syncStep(ed, secId, secPath, idx, si); - if (!ed[secPath]) ed[secPath] = []; - if (!ed[secPath][idx]) ed[secPath][idx] = {}; - if (!ed[secPath][idx].steps) ed[secPath][idx].steps = []; - if (!ed[secPath][idx].steps[si]) ed[secPath][idx].steps[si] = {}; - var step = ed[secPath][idx].steps[si]; - +function ie_addActEffect(el, secId, secPath, idx, si, effectKey) { + var c = _ie_actCtx(el, secId, secPath, idx, si); + var step = c.get(); var at = IE_ACT_TYPES.find(function(a) { return a.key === effectKey; }); if (!at) return; - if (at.kind === 'kv') { - step[effectKey] = {}; - } else if (at.kind === 'checkbox') { - step[effectKey] = true; - } else if (at.kind === 'number') { - step[effectKey] = 0; - } else if (at.kind === 'droptable') { - step[effectKey] = []; - } else { - step[effectKey] = ''; - } - ced_syncDOMToData(ed); - window._ieRenderOnly(); + if (at.kind === 'kv') step[effectKey] = {}; + else if (at.kind === 'checkbox') step[effectKey] = true; + else if (at.kind === 'number') step[effectKey] = 0; + else if (at.kind === 'droptable') step[effectKey] = []; + else step[effectKey] = ''; + c.set(step); + c.change(); } -function ie_removeActEffect(secId, secPath, idx, si, effectKey) { - var ed = window._editorData; - if (!ed) return; - ie_syncStep(ed, secId, secPath, idx, si); - var step = ed[secPath] && ed[secPath][idx] && ed[secPath][idx].steps && ed[secPath][idx].steps[si]; - if (!step) return; +function ie_removeActEffect(el, secId, secPath, idx, si, effectKey) { + var c = _ie_actCtx(el, secId, secPath, idx, si); + var step = c.get(); delete step[effectKey]; - ced_syncDOMToData(ed); - window._ieRenderOnly(); + c.set(step); + c.change(); } // ── Add/Remove: KV row ── -function ie_addKVRow(secId, secPath, idx, si, effectKey) { +function ie_addKVRow(el, secId, secPath, idx, si, effectKey) { + if (_ie_scopeFromEl(el)) { + var c = _ie_actCtx(el, secId, secPath, idx, si); + var step = c.get(); + if (!step[effectKey] || typeof step[effectKey] !== 'object') step[effectKey] = {}; + step[effectKey][''] = ''; + c.set(step); + c.change(); + return; + } + var ed = window._editorData; if (!ed) return; ie_syncStep(ed, secId, secPath, idx, si); @@ -1122,67 +1202,67 @@ function ie_addKVRow(secId, secPath, idx, si, effectKey) { } function ie_removeKVRow(rowEl, secId, secPath, idx, si, effectKey) { - var ed = window._editorData; - if (!ed) return; if (rowEl && rowEl.closest) { var kvRow = rowEl.closest('.ie-kv-row'); if (kvRow) rowEl = kvRow; } - ie_syncStep(ed, secId, secPath, idx, si); - var step = ed[secPath] && ed[secPath][idx] && ed[secPath][idx].steps && ed[secPath][idx].steps[si]; + var c = _ie_actCtx(rowEl, secId, secPath, idx, si); + var step = c.get(); if (!step || !step.hasOwnProperty(effectKey)) return; var keyEl = rowEl.querySelector('.ie-kv-key'); var k = keyEl ? keyEl.value.trim() : ''; if (k && step[effectKey].hasOwnProperty(k)) delete step[effectKey][k]; - if (Object.keys(step[effectKey]).length === 0) { - delete step[effectKey]; - } - ced_syncDOMToData(ed); - window._ieRenderOnly(); + if (Object.keys(step[effectKey]).length === 0) delete step[effectKey]; + c.set(step); + c.change(); } // ── Add/Remove: Messages ── -function ie_addMessages(secId, secPath, idx, si) { - var ed = window._editorData; - if (!ed) return; - ie_syncStep(ed, secId, secPath, idx, si); - if (!ed[secPath] || !ed[secPath][idx] || !ed[secPath][idx].steps || !ed[secPath][idx].steps[si]) return; - var step = ed[secPath][idx].steps[si]; +function ie_addMessages(el, secId, secPath, idx, si) { + var c = _ie_actCtx(el, secId, secPath, idx, si); + var step = c.get(); if (!step.messages || !Array.isArray(step.messages)) step.messages = []; step.messages.push(''); - window._ieRenderCurrent(); + c.set(step); + c.change(); } // ── Drop Table row add/remove ── -function ie_addDropRow(secId, secPath, idx, si, kind) { - var ed = window._editorData; - if (!ed) return; - ie_syncStep(ed, secId, secPath, idx, si); - if (!ed[secPath] || !ed[secPath][idx] || !ed[secPath][idx].steps || !ed[secPath][idx].steps[si]) return; - var step = ed[secPath][idx].steps[si]; +function ie_addDropRow(el, secId, secPath, idx, si, kind) { + var c = _ie_actCtx(el, secId, secPath, idx, si); + var step = c.get(); if (!Array.isArray(step.drop_table)) step.drop_table = []; if (kind === 'table') { step.drop_table.push({table: '', weight: 10, quantity: 1, _kind: 'table'}); } else { step.drop_table.push({item_id: '', weight: 10, quantity: 1, _kind: 'item'}); } - window._ieRenderOnly(); + c.set(step); + c.change(); } -function ie_removeDropRow(secId, secPath, idx, si, ri) { - var ed = window._editorData; - if (!ed) return; - ie_syncStep(ed, secId, secPath, idx, si); - if (!ed[secPath] || !ed[secPath][idx] || !ed[secPath][idx].steps || !ed[secPath][idx].steps[si]) return; - var step = ed[secPath][idx].steps[si]; +function ie_removeDropRow(el, secId, secPath, idx, si, ri) { + var c = _ie_actCtx(el, secId, secPath, idx, si); + var step = c.get(); if (!Array.isArray(step.drop_table)) return; step.drop_table.splice(ri, 1); - window._ieRenderOnly(); + c.set(step); + c.change(); } -function ie_addMessage(secId, secPath, idx, si) { +function ie_addMessage(el, secId, secPath, idx, si) { + if (_ie_scopeFromEl(el)) { + var c = _ie_actCtx(el, secId, secPath, idx, si); + var step = c.get(); + if (!step.messages || !Array.isArray(step.messages)) step.messages = []; + step.messages.push(''); + c.set(step); + c.change(); + return; + } + var ed = window._editorData; if (!ed) return; ie_syncStep(ed, secId, secPath, idx, si); @@ -1201,32 +1281,23 @@ function ie_addMessage(secId, secPath, idx, si) { } function ie_removeMessage(rowEl, secId, secPath, idx, si) { - var ed = window._editorData; - if (!ed) return; if (rowEl && rowEl.closest) { var kvRow = rowEl.closest('.ie-kv-row'); if (kvRow) rowEl = kvRow; } - ie_syncStep(ed, secId, secPath, idx, si); - var step = ed[secPath] && ed[secPath][idx] && ed[secPath][idx].steps && ed[secPath][idx].steps[si]; + var c = _ie_actCtx(rowEl, secId, secPath, idx, si); + var step = c.get(); if (!step || !Array.isArray(step.messages)) return; - - var card = document.querySelector('.obj-card[data-card="' + secId + '"]'); - var stepRow = card.querySelector('.obj-sub-row.ie-inter-row[data-idx="' + idx + '"] .ie-step-row[data-step="' + si + '"]'); - if (stepRow) { - var kvRows = stepRow.querySelectorAll('.ie-act-kv[data-ie-act-key="messages"] .ie-kv-row'); - for (var ri = 0; ri < kvRows.length; ri++) { - if (kvRows[ri] === rowEl || kvRows[ri].contains(rowEl)) { - step.messages.splice(ri, 1); - break; - } + var kvRows = document.querySelectorAll('.ie-act-kv[data-ie-act-key="messages"] .ie-kv-row'); + for (var ri = 0; ri < kvRows.length; ri++) { + if (kvRows[ri] === rowEl || kvRows[ri].contains(rowEl)) { + step.messages.splice(ri, 1); + break; } } - if (step.messages.length === 0) { - delete step.messages; - } - ced_syncDOMToData(ed); - window._ieRenderOnly(); + if (step.messages.length === 0) delete step.messages; + c.set(step); + c.change(); } // ── Shared trigger-style array-section renderer ── -- cgit v1.2.3