Skip to content

Commit

Permalink
version 3.2.0-beta.7
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmak1 committed Dec 13, 2023
1 parent 1aba620 commit 1060b1e
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 242 deletions.
3 changes: 1 addition & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const IMPORT_REGEX = /\{{{(.*?)}}}/g;
export const CONDITION_REGEX = /!/g;
export const TEXT_REGEX = /\{\{\s*([^}]+)\s*\}\}|([^{}]+)/g;
export const SPACE_REGEX = /\s+/g;
export const CLICK_FUNCTION_NAME = "__click__";
export const EXCLAMATION_POINT = /(\!)/g;
export const { appendChild, insertBefore, removeChild, replaceChild } =
Node.prototype;
Expand All @@ -31,7 +30,7 @@ export const getParentNode = (
export const addClass = DOMTokenList.prototype.add;
export const removeClass = DOMTokenList.prototype.remove;
export const cloneNode = Node.prototype.cloneNode;
export const { push, indexOf, map: mapArray, unshift } = Array.prototype;
export const { push, indexOf, map: mapArray, unshift, pop } = Array.prototype;
export const { split } = String.prototype;
export const {
setAttribute,
Expand Down
28 changes: 14 additions & 14 deletions src/core/components/component/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ export class Component extends DataComponent {
? renderKeyData(firstKeyData, key.properties as Array<string>)
: firstKeyData;
} else {
return renderValues(key, data, importData, undefined);
const str = {
value: ""
};
renderValues(str, key, data, importData, undefined);
return str.value;
}
};
const newFunction = (
Expand Down Expand Up @@ -906,10 +910,9 @@ export class Component extends DataComponent {
el: templateElemenet
} = templateEl;
const el = cloneNode.call(templateElemenet, true);
const length = templateNodes.length;
const nodes: Array<IndexObjNode | ChildNode | null> = [];
push.call(nodes, el as ChildNode);
for (let i = 0; i < length; i++) {
for (let i = 0; i < templateNodes.length; i++) {
const templateNode = templateNodes[i];
const { render, rootId } = templateNode;
push.call(
Expand All @@ -928,11 +931,6 @@ export class Component extends DataComponent {
const attrFunc = (key: CurrentKeyType) =>
renderDynamic(key, data, undefined);
const newValues: NodeValuesType = [];
if (!values.some((e) => e.type === 3)) {
if (this.export) {
createExportObject(index);
}
}
for (const val of values) {
const node = nodes[val.id as number] as Element;
switch (val.type) {
Expand Down Expand Up @@ -966,9 +964,8 @@ export class Component extends DataComponent {
} as NodeValueType);
break;
case 3:
const value4 = val;
const componentName = node.getAttribute("data-cample");
const keyImportString = value4.value;
const keyImportString = val.value;
if (keyImportString && componentName) {
const newImportString = renderComponentTemplate(
keyImportString,
Expand All @@ -981,14 +978,12 @@ export class Component extends DataComponent {
}
break;
case 4:
const value5 = val;
const fnClass = (fnNew: any) =>
updateClass(node, value5, fnNew);
const fnClass = (fnNew: any) => updateClass(node, val, fnNew);
fnClass(attrFunc);
push.call(newValues, {
render: fnClass,
type: 4,
value: value5
value: val
});
break;
}
Expand Down Expand Up @@ -1153,6 +1148,11 @@ export class Component extends DataComponent {
runRenderFunction,
currentComponent.functions
);
if (!newTemplateObj.values.some((e) => e.type === 3)) {
if (this.export) {
createExportObject(index);
}
}
const el = createElement(
index,
data,
Expand Down
122 changes: 92 additions & 30 deletions src/core/components/each/each.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ import {
ValuesTemplateType,
IndexObjNode,
RenderNodeFunctionType,
ValueType
ValueType,
KeyValuesType,
KeyValuesValueType
} from "../../../types/types";
import { createEachDynamicNodeComponentType } from "../../functions/data/create-each-dynamic-node-component";
import { renderAttributes } from "../../functions/render/render-attributes";
Expand Down Expand Up @@ -230,6 +232,7 @@ export class Each extends DataComponent {
const valuesLength = values.length;
for (let i = 0; i < valuesLength; i++) {
const val = values[i];
const valKey = val.key as CurrentKeyType;
const node = nodes[val.id as number];
switch (val.type) {
case 0:
Expand All @@ -238,7 +241,7 @@ export class Each extends DataComponent {
break;
case 1:
const newData = renderDynamic(
val.key as CurrentKeyType,
valKey,
indexData,
importData,
eachIndex
Expand All @@ -255,7 +258,7 @@ export class Each extends DataComponent {
val: NodeTextType
) => {
const newData = renderDynamic(
val.key as CurrentKeyType,
valKey,
currentIndexData,
currentImportData,
currentEachIndex
Expand All @@ -268,7 +271,7 @@ export class Each extends DataComponent {
push.call(newValues, {
render: fnText,
type: 1,
key: val.key,
key: valKey,
value: newData
} as NodeValueType);
break;
Expand Down Expand Up @@ -380,8 +383,7 @@ export class Each extends DataComponent {
currentComponent: EachDynamicNodeComponentType,
dataId: number,
index: number,
importData: ImportDataType | undefined,
isFirst = false
importData: ImportDataType | undefined
) => {
const {
parentNode,
Expand Down Expand Up @@ -610,8 +612,11 @@ export class Each extends DataComponent {
const lastEl = newData[newLastIndex]?.el;
const isLastEl = !!lastEl;
if (isLastEl) {
for (let i = 0; newFirstIndex < newLastIndex--; i++) {
const currentIndex = newFirstIndex + i;
for (
let currentIndex = newFirstIndex;
newFirstIndex < newLastIndex--;
currentIndex++
) {
const currentIndexData = newData[currentIndex];
const newKey = renderKey(
currentIndexData,
Expand All @@ -632,8 +637,11 @@ export class Each extends DataComponent {
newData[currentIndex] = currentNode;
}
} else {
for (let i = 0; newFirstIndex < newLastIndex--; i++) {
const currentIndex = newFirstIndex + i;
for (
let currentIndex = newFirstIndex;
newFirstIndex < newLastIndex--;
currentIndex++
) {
const currentIndexData = newData[currentIndex];
const newKey = renderKey(
currentIndexData,
Expand Down Expand Up @@ -671,8 +679,11 @@ export class Each extends DataComponent {
} else {
const indexesOldArr = {};
const oldLength = oldLastIndex - oldFirstIndex;
for (let i = 0; i < oldLength; i++) {
const currentIndex = oldFirstIndex + i;
for (
let currentIndex = oldFirstIndex;
currentIndex < oldLength;
currentIndex++
) {
indexesOldArr[oldNodes[currentIndex].key as string] =
currentIndex;
}
Expand Down Expand Up @@ -806,8 +817,11 @@ export class Each extends DataComponent {
const lastEl = newData[newLastIndex]?.el;
const isLastEl = !!lastEl;
if (isLastEl) {
for (let i = 0; newFirstIndex < newLastIndex--; i++) {
const currentIndex = newFirstIndex + i;
for (
let currentIndex = newFirstIndex;
newFirstIndex < newLastIndex--;
currentIndex++
) {
const currentIndexData = newData[currentIndex];
const newKey = renderKey(
currentIndexData,
Expand All @@ -828,8 +842,11 @@ export class Each extends DataComponent {
newData[currentIndex] = currentNode;
}
} else {
for (let i = 0; newFirstIndex < newLastIndex--; i++) {
const currentIndex = newFirstIndex + i;
for (
let currentIndex = newFirstIndex;
newFirstIndex < newLastIndex--;
currentIndex++
) {
const currentIndexData = newData[currentIndex];
const newKey = renderKey(
currentIndexData,
Expand Down Expand Up @@ -1232,6 +1249,53 @@ export class Each extends DataComponent {
: concat.call(str.value, prop);
}
};
const renderFn10 = (
str: { value: string },
currentValue: ValueItemType,
data: any,
importData: ImportDataType | undefined,
eachIndex: number
) => {
const { value, render } = currentValue;
const prop = render(value, data, importData, eachIndex);
str.value = prop;
};
const renderFn11 = (
str: { value: string },
currentVal: KeyValuesValueType,
data: any,
importData: any,
eachIndex: number | undefined
) => {
const condition = renderCondition(
currentVal.condition,
data,
importData,
eachIndex
);
const { values, render } = currentVal;
render(str, condition, values, data, importData, eachIndex);
};
const renderFn12 = (
str: { value: string },
vals: KeyValuesType,
data: any,
importData: any,
eachIndex: number | undefined
) => {
for (let i = 0; i < vals.length; i++) {
const currentVal = vals[i];
const condition = renderCondition(
currentVal.condition,
data,
importData,
eachIndex
);
const { values, render } = currentVal;
render(str, condition, values, data, importData, eachIndex);
}
};

data = data as EachDataValueType;
const oldData = isDataObject ? {} : [];
const template = this.eachTemplate;
Expand All @@ -1245,7 +1309,10 @@ export class Each extends DataComponent {
renderFn6,
renderFn7,
renderFn8,
renderFn9
renderFn9,
renderFn10,
renderFn11,
renderFn12
],
template as string,
index,
Expand Down Expand Up @@ -1279,19 +1346,14 @@ export class Each extends DataComponent {
currentComponent
);
const elements: ScriptElementsType = {};
try {
renderNewData(
oldData,
data,
currentComponent,
dataId,
index,
importData,
true
);
} catch (e) {
createError(`${e}`);
}
renderNewData(
oldData,
data,
currentComponent,
dataId,
index,
importData
);
if (
currentComponent.nodes.length &&
Array.isArray(this.script) &&
Expand Down
1 change: 0 additions & 1 deletion src/core/functions/data/update-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const updateClass = (el: Element, value: ClassType, val: string) => {
} else {
setAttribute.call(el, "class", "");
}

value.old = val;
}
};
29 changes: 28 additions & 1 deletion src/core/functions/parse/parse-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DynamicKeyObjectType,
KeyValuesType,
RenderedKeyType,
ValueKeyStringType,
ValuesType
} from "../../../types/types";
import { renderKey } from "../render/render-key";
Expand Down Expand Up @@ -37,6 +38,9 @@ export const parseKey = (
(...args: any[]) => void,
(...args: any[]) => void,
(...args: any[]) => void,
(...args: any[]) => void,
(...args: any[]) => void,
(...args: any[]) => void,
(...args: any[]) => void
],
values?: ValuesType,
Expand Down Expand Up @@ -83,15 +87,38 @@ export const parseKey = (
originType = 3;
break;
}
const isValSingle = val?.length === 1;
const keyObj: CurrentKeyType = {
originKey,
key: isValue ? (renderedKey as string) : key,
originType,
isProperty,
isClass,
values: val,
isValue
};
if (isValue) {
if (isValSingle) {
const keyObjValuesValue = (val as KeyValuesType)[0];
keyObj.values = keyObjValuesValue;
keyObj.render = valueFunctions[8];
const setRender = (val: ValueKeyStringType) => {
const { valueClass } = val;
if (checkObject(valueClass.value)) {
valueClass.render = valueFunctions[7];
}
};
const currentValues = keyObjValuesValue.values;
if (Array.isArray(currentValues)) {
for (let i = 0; i < currentValues.length; i++) {
const currentVal = currentValues[i];
setRender(currentVal);
}
} else setRender(currentValues);
} else {
keyObj.values = val;
keyObj.render = valueFunctions[9];
}
}
if (properties && properties.length) {
keyObj.properties = properties;
}
Expand Down
Loading

0 comments on commit 1060b1e

Please sign in to comment.