Options for every item and apply-to-all
Show the fabric choices for every placed seat in a modular sofa builder. Use window.mimeeqApp.observers.modular.instanceBlocks to read each item's options without selecting it in the scene. Use window.mimeeqApp.actions.markOptionByCodeForInstances() when a fabric is shared by several products whose block or option IDs differ.
Complete example
Paste this into an HTML page with one embed. Use a shortcode and template for a full modular product that renders inline. Place at least two items with a fabric block. For a shared fabric to apply across products, configure the same block code and fabric option code on each product. You can keep the products' existing block and option IDs.
Find a fabric choice in any item's panel and click Apply to checked items next to it. All items start checked. Uncheck items to target a subset. The example also renders other ordinary option blocks, so it works with the block names and codes from your product.
<mmq-embed short-code="YOUR_SHORT_CODE" template="YOUR_TEMPLATE" render-at-mount></mmq-embed>
<section aria-label="Options by item">
<p id="option-status" role="status">Opening the configurator…</p>
<h2>Automatic synchronization rules</h2>
<ul id="sync-rules"></ul>
<h2>Placed items</h2>
<div id="item-options"></div>
</section>
<script>
document.addEventListener(
'mimeeq-app-loaded',
() => {
const { observers, actions } = window.mimeeqApp;
const { firstRender, settled } = observers.status;
const { instanceBlocks, autoSyncRulesByType, sceneItems } = observers.modular;
const message = document.getElementById('option-status');
const ruleList = document.getElementById('sync-rules');
const panels = document.getElementById('item-options');
if (!message || !ruleList || !panels) return;
const unchecked = new Set();
let applying = false;
let feedback = '';
function canEdit() {
return firstRender.getValue() && settled.getValue();
}
function button(label, disabled, onClick) {
const result = document.createElement('button');
result.type = 'button';
result.textContent = label;
result.disabled = disabled;
result.addEventListener('click', onClick);
return result;
}
async function apply(update) {
if (applying || !canEdit()) return;
applying = true;
feedback = '';
render();
try {
feedback = await update();
} catch (error) {
feedback = 'The option could not be applied. Review the current layout and try again.';
console.error(error);
} finally {
applying = false;
render();
}
}
const render = () => {
const rules = autoSyncRulesByType.getValue();
const blocksById = instanceBlocks.getValue() ?? {};
const items = Object.values(sceneItems.getValue() ?? {}).sort(
(a, b) => a.positionOrder - b.positionOrder,
);
const disabled = applying || !canEdit();
if (!firstRender.getValue()) {
message.textContent = 'Waiting for the scene…';
} else if (applying) {
message.textContent = 'Applying option…';
} else {
message.textContent = items.length ? feedback : 'Place an item to see its options.';
}
const ruleDescriptions = rules?.autoSync.map(({ ruleName, values }) => {
const scope = values.onlySelected
? `Product IDs: ${values.products?.join(', ') || 'none configured'}`
: 'All matching products';
return `${ruleName}: ${values.blocks.join(', ')} (${scope})`;
});
ruleList.replaceChildren(
...(ruleDescriptions?.length ? ruleDescriptions : ['No auto-sync rules available.']).map(
(description) => {
const li = document.createElement('li');
li.textContent = description;
return li;
},
),
);
panels.replaceChildren(
...items.map(({ instanceId, positionOrder, productName, productId }) => {
const panel = document.createElement('fieldset');
const caption = document.createElement('legend');
caption.textContent = `Item ${positionOrder} — ${productName || productId}`;
const check = document.createElement('input');
check.type = 'checkbox';
check.checked = !unchecked.has(instanceId);
check.disabled = disabled;
check.addEventListener('change', () => {
if (check.checked) unchecked.delete(instanceId);
else unchecked.add(instanceId);
});
const label = document.createElement('label');
label.append(check, ' Include in batch changes');
panel.append(caption, label);
const blocks = (blocksById[instanceId] ?? []).filter((block) => !block.isHidden);
for (const block of blocks) {
const heading = document.createElement('h3');
heading.textContent = block.name || block.blockName;
panel.append(heading);
for (const option of block.options ?? []) {
if (option.isHidden) continue;
const row = document.createElement('p');
row.append(
`${option.name || option.code} `,
button(
'Apply to this item',
disabled || !!block.isDisabled || !!option.isDisabled,
() => {
void apply(async () => {
await actions.markOptionModular(
option,
block.id,
block.widgetType,
false,
block.blockName,
[instanceId],
);
return 'Option request finished.';
});
},
),
' ',
button(
'Apply to checked items',
disabled || !block.blockName || !option.code,
() => {
void apply(async () => {
const latest = instanceBlocks.getValue() ?? {};
const targets = Object.entries(latest)
.filter(
([id, availableBlocks]) =>
!unchecked.has(id) &&
availableBlocks.some(
(entry) =>
entry.blockName === block.blockName &&
!entry.isHidden &&
!entry.isDisabled &&
entry.options?.some(
(choice) =>
choice.code === option.code &&
!choice.isHidden &&
!choice.isDisabled,
),
),
)
.map(([id]) => id);
if (!targets.length) return 'No checked item offers this option.';
await actions.markOptionByCodeForInstances(
block.blockName,
option.code,
targets,
);
return 'Batch option request finished. Rules may also update other items.';
});
},
),
);
panel.append(row);
}
}
return panel;
}),
);
};
const subscriptions = [
...[firstRender, settled].map((observer) => observer.subscribe(render)),
sceneItems.subscribe(render),
instanceBlocks.subscribe(render),
autoSyncRulesByType.subscribe(render),
];
window.addEventListener('pagehide', (event) => {
if (!event.persisted) subscriptions.forEach((subscription) => subscription.unsubscribe());
});
},
{ once: true },
);
</script>
<script src="https://cdn.mimeeq.com/read_models/embed/app-embed.js" async></script>
How it works
- Listen for
mimeeq-app-loadedondocumentand subscribe to the scene and modular observers. Each subscription receives the current value immediately as{ newValue, oldValue }. The panel reads current snapshots withgetValue()and enables editing when the scene is ready and idle. - Use the placed item's
instanceIdto look up its prepared blocks. Useblock.nameandoption.nameas labels. Sendblock.blockNameandoption.codeto the batch action. These are the authored codes. - Read
autoSyncRulesByType.autoSyncto show configured synchronization groups. The list shows rule definitions. The effect on a particular option change depends on the products, blocks and other rules in the scene. - For a batch, collect the checked instances that currently expose the same enabled block and option codes. Call
markOptionByCodeForInstances(blockCode, optionCode, instanceIds)once. The action resolves each item's own block and option. A change creates one undo step and emits onemimeeq-modular-select-option-multipleevent ondocument. Itsdetail.selectedIdslists the matched targets anddetail.optiondescribes the first match. Read the resulting observer values to refresh the panel. - Use
markOptionModular(option, blockId, widgetType, setMatchingGroup, blockCode, instanceIds)when you have the exact option object and block ID for a target, as in the Apply to this item button. It also supports widget-specific option data. The example passesfalseforsetMatchingGroupand an explicit instance ID.
See Read the scene and the catalog for the status and modular.sceneItems payloads.
Observer payloads
window.mimeeqApp.observers.modular.instanceBlocks
| Field | Type | Meaning |
|---|---|---|
| Top-level value | Record<string, PreparedBlock[]> | Map keyed by instance ID. {} means there are no placed modular items. An item's array can be empty if it has no prepared blocks. |
block.id, name, blockName | string | Block ID, display label and authored block code. |
block.widgetType | WidgetType | Widget associated with the block. Use it when passing the exact option object to markOptionModular. |
block.isHidden, isDisabled | boolean | undefined | Visibility and disability flags for the block. The panel omits hidden blocks and disables edits on disabled blocks. |
block.disabledTooltipMessage | string | undefined | Optional reason to show for a disabled block. |
block.options, optionsLength | OptionSetOption[] | undefined, number | Available option data and prepared count. An absent or empty options array gives this panel no ordinary choices to display. Some widgets supply their own controls. |
options[].id, name, code | string | Option ID, display label and authored option code. |
options[].isHidden, isDisabled | boolean | undefined | Visibility and disability flags for the option. An unflagged option can be shown. |
window.mimeeqApp.observers.modular.autoSyncRulesByType
| Field | Type | Meaning |
|---|---|---|
| Top-level value | ModularAutoSyncRulesByType | null | null when modular auto-sync rule data is unavailable. A present object can contain no rules. |
autoSync | Array | Configured auto-sync rules with block data. An empty array means there are no rules in this list. |
autoSync[].ruleId, ruleName, ruleType | string, string, 'AUTO_SYNC_BLOCKS' | Rule ID, authored label and type. |
autoSync[].ordinal | number | undefined | Authored order, when supplied. |
autoSync[].values.blocks | string[] | Block codes listed in the sync rule. An empty list has no blocks to sync. |
autoSync[].values.onlySelected, products | boolean | undefined, string[] | undefined | With onlySelected: true, the rule is scoped to the specified product IDs. A missing or empty product list supplies no scoped products. |
Edge cases
- The batch action skips missing instances, blocks or option codes. It resolves without a result payload. If nothing changes, it creates no undo step and emits no selection event.
- The checked items are the direct targets. Auto-sync and other rules can update additional items, so use the rules list to explain shared blocks to the user.
- If spatial adjustment cannot preserve the layout, the action rolls back and rejects with
SpatialAdjustmentError. The example catches errors and renders current values again.
What this replaces
Custom fabric panels have selected a reference item just to read optionSets.blocks or built their own scene-wide cache from several observers. They have also mapped selections by hand between products with different option IDs. Read instanceBlocks for each item and let the batch action resolve the local IDs from the shared codes.
See Read the scene and the catalog for per-item metadata and pricing.