Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for (let i = 0, len = records.length; i < len; i++) {
const record = records[i];
if (record.signalType) continue;
if (record.fStory) {
const [tempState, pathStr] = rxStory(state, record, options);
state = tempState;
if (pathStr) newStories.push(pathStr);
} else {
state = rxLog(state, record, options);
}
}
// Don't expand stories that are already closed upon reception
for (let j = 0, len1 = newStories.length; j < len1; j++) {
const pathStr = newStories[j];
const fOpen = timm.getIn(state, (`mainStory/${pathStr}/fOpen`).split('/'));
if (fOpen) continue;
state = timm.setIn(state, (`mainStory/${pathStr}/fExpanded`).split('/'), false);
}
return state;
};
setIn(parentElement, ["value", "items"], [movedElement])
);
}
switch (to.containerType) {
case "column":
return simpleMove(oldValue, from, to, movedElement);
case "row":
return moveShortcodeToRow(oldValue, from, to, movedElement);
case "section":
return moveShortcodeToSection(oldValue, from, to, movedElement);
}
}
if (from.itemType === "column") {
const parentElement = getIn(oldValue, from.itemPath.slice(0, -3));
if (
from.containerType === "posts" ||
(from.containerType === "carousel" &&
parentElement.value.dynamic === "on")
) {
// Cloned Column and changed the paths for the first column
from.itemPath[from.itemPath.length - 1] = "0";
const movedElement = setIds(getIn(oldValue, from.itemPath));
oldValue = addIn(oldValue, from.itemPath, movedElement);
}
switch (to.containerType) {
case "column":
return moveColumnToSection(oldValue, from, to);
case "row":
}
}
// Normal case
if (nextRecords == null) nextRecords = timm.addLast(prevRecords, record);
return nextRecords;
});
// Flag stories containing warnings and errors
const fWarn = record.level === k.LEVEL_STR_TO_NUM.WARN;
const fError = record.level >= k.LEVEL_STR_TO_NUM.ERROR;
if (fWarn || fError) {
const recurPath = [].concat(path);
while (true) { // eslint-disable-line no-constant-condition
recurPath.pop(); // recurPath is now the story path
const story = timm.getIn(state, recurPath);
if (story.fMain) break;
if (fWarn && !story.fHasWarning) {
state = timm.setIn(state, recurPath.concat(['fHasWarning']), true);
}
if (fError && !story.fHasError) {
state = timm.setIn(state, recurPath.concat(['fHasError']), true);
}
recurPath.pop();
}
}
return { state, fDuplicate };
};
function getValue(value, { from, to }) {
let oldValue = value;
if (from.itemType === "shortcode") {
let movedElement = getIn(oldValue, from.itemPath);
if (from.containerType === "cloneable") {
let parentElement = getIn(oldValue, from.itemPath.slice(0, -3));
// if cloneable has only one item we remove it
if (parentElement.value.items.length <= 1) {
from.containerPath = from.itemPath.slice(0, -4);
from.itemPath = from.itemPath.slice(0, -3);
from.itemIndex = Number(from.itemPath[from.itemPath.length - 1]);
// if the cloneable will be removed
// and we do not decrement to.index then
// it will go one position after the desired one
// in the case when dragging from up to down
if (
_.isEqual(from.containerPath, to.containerPath) &&
from.itemIndex < to.itemIndex
) {
const forgetRecords = (state0, action, settings) => {
let state = state0;
const { pathStr } = action;
const { maxRecords, forgetHysteresis } = settings;
const path = `mainStory/${pathStr}`.split('/');
const prevStory = timm.getIn(state, path);
const { numRecords } = prevStory;
const targetForget = Math.ceil((numRecords - maxRecords) + (maxRecords * forgetHysteresis));
const { nextStory, numForgotten, updatedStoryPaths } =
forgetRecursively(prevStory, targetForget, {}, prevStory.pathStr);
nextStory.numRecords = numRecords - numForgotten;
state = timm.setIn(state, path, nextStory);
const openStories = updateStoryPaths(state.openStories, updatedStoryPaths);
const closedStories = updateStoryPaths(state.closedStories, updatedStoryPaths);
state = timm.merge(state, { openStories, closedStories });
return state;
};
const path = (`mainStory/${action.pathStr}/fExpanded`).split('/');
return timm.updateIn(state, path, (fExpanded) => !fExpanded);
}
if (action.type === 'TOGGLE_HIERARCHICAL') {
if (action.pathStr == null) return state;
const path = (`mainStory/${action.pathStr}/fHierarchical`).split('/');
return timm.updateIn(state, path, (fHierarchical) => !fHierarchical);
}
if (action.type === 'TOGGLE_ATTACHMENT') {
let { pathStr } = action;
const { recordId } = action;
if (pathStr == null || recordId == null) return state;
pathStr = `mainStory/${pathStr}`;
const story = timm.getIn(state, pathStr.split('/'));
if (story == null) return state;
const recordPathStr = findRecord(story, recordId, !story.fHierarchical, pathStr);
if (recordPathStr == null) return state;
const recordPath = recordPathStr.split('/');
const record = timm.getIn(state, recordPath);
recordPath.push('objExpanded');
return timm.setIn(state, recordPath, !record.objExpanded);
}
if (action.type === 'EXPAND_ALL_STORIES') return expandCollapseAll(state, true);
if (action.type === 'COLLAPSE_ALL_STORIES') return expandCollapseAll(state, false);
if (action.type === 'QUICK_FIND') {
const { txt } = action;
let quickFind;
if (txt.length) {
const normalizeColumnsWidths = (value, path, from) => {
const targetColumns = getIn(value, path);
const { containerType, containerPath } = from;
const inCarousel =
containerType === "carousel" && _.isEqual(containerPath, path);
if (
!targetColumns ||
!_.every(targetColumns, ({ type }) => type === "Column") ||
inCarousel
)
return value;
return setIn(value, path, normalizeRowColumns(targetColumns));
};
const addIn = (object, [...path], value) => {
let index = path.pop();
index = Number(index) ? Number(index) : index;
let newObj = getIn(object, path);
newObj = insert(newObj, index, value);
return setIn(object, path, newObj);
};
const removeIn = (object, [...path]) => {
const removeIn = (object, [...path]) => {
let index = path.pop();
index = Number(index) ? Number(index) : index;
let newObj = getIn(object, path);
newObj = removeAt(newObj, index);
return setIn(object, path, newObj);
};