Consolidate slide preview content resolution
This commit is contained in:
1 parent
726a7fedc7
commit
e9a53f577c
11 files changed
+77
-240
No files matched your search
@@ -0,0 +1,22 @@
|
||||
(function (root, factory) {
|
||||
var helpers = factory();
|
||||
if (typeof module === 'object' && module.exports) {
|
||||
module.exports = helpers;
|
||||
} else {
|
||||
root.pulseRegionContent = helpers;
|
||||
}
|
||||
})(typeof window !== 'undefined' ? window : globalThis, function () {
|
||||
function resolveRegionContent(region, existingContent) {
|
||||
var saved = existingContent && existingContent[region.region_key];
|
||||
var selected = region.read_only === true || Number(region.read_only) === 1 || saved === undefined
|
||||
? region.default_content
|
||||
: saved;
|
||||
if (typeof selected === 'string') {
|
||||
try { selected = JSON.parse(selected); } catch (_error) { selected = { value: selected }; }
|
||||
}
|
||||
var content = selected && typeof selected === 'object' && !Array.isArray(selected) ? selected : { value: selected };
|
||||
return Object.assign({ type: region.region_type }, content);
|
||||
}
|
||||
|
||||
return { resolveRegionContent: resolveRegionContent };
|
||||
});
|
||||
@@ -394,14 +394,7 @@ import { createSlideAnimationEditor } from '/assets/js/slides/slide-animation-ed
|
||||
Object.assign(existingContent, savedExistingContent);
|
||||
}
|
||||
(template && Array.isArray(template.regions) ? template.regions : []).forEach(function (region) {
|
||||
var content = region.default_content;
|
||||
if (typeof content === 'string') {
|
||||
try { content = JSON.parse(content); } catch (_error) { content = {}; }
|
||||
}
|
||||
if (!content || typeof content !== 'object' || Array.isArray(content)) content = {};
|
||||
if (region.read_only === true || Number(region.read_only) === 1 || !Object.prototype.hasOwnProperty.call(existingContent, region.region_key)) {
|
||||
existingContent[region.region_key] = content;
|
||||
}
|
||||
existingContent[region.region_key] = window.pulseRegionContent.resolveRegionContent(region, existingContent);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user