mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-07 15:39:49 -05:00
fix(e2e): update dump params to shape model
This commit is contained in:
parent
99ff81d42c
commit
ade39eebe2
4 changed files with 437 additions and 514 deletions
File diff suppressed because it is too large
Load diff
7
apps/e2e/src/models/shape.model.ts
Normal file
7
apps/e2e/src/models/shape.model.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export interface Shape {
|
||||||
|
id: string;
|
||||||
|
frameId?: string;
|
||||||
|
parentId?: string;
|
||||||
|
shapes?: string[];
|
||||||
|
layoutGridCells?: Shape[];
|
||||||
|
}
|
|
@ -2,14 +2,7 @@ import puppeteer from 'puppeteer';
|
||||||
import { PenpotApi } from './api';
|
import { PenpotApi } from './api';
|
||||||
import { getFileUrl } from './get-file-url';
|
import { getFileUrl } from './get-file-url';
|
||||||
import { idObjectToArray } from './clean-id';
|
import { idObjectToArray } from './clean-id';
|
||||||
|
import { Shape } from '../models/shape.model';
|
||||||
interface Shape {
|
|
||||||
':id': string;
|
|
||||||
':frame-id'?: string;
|
|
||||||
':parent-id'?: string;
|
|
||||||
':shapes'?: string[];
|
|
||||||
':layout-grid-cells'?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
function replaceIds(shapes: Shape[]) {
|
function replaceIds(shapes: Shape[]) {
|
||||||
let id = 1;
|
let id = 1;
|
||||||
|
@ -20,35 +13,32 @@ function replaceIds(shapes: Shape[]) {
|
||||||
|
|
||||||
function replaceChildrenId(id: string, newId: string) {
|
function replaceChildrenId(id: string, newId: string) {
|
||||||
for (const node of shapes) {
|
for (const node of shapes) {
|
||||||
if (node[':parent-id'] === id) {
|
if (node.parentId === id) {
|
||||||
node[':parent-id'] = newId;
|
node.parentId = newId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node[':frame-id'] === id) {
|
if (node.frameId === id) {
|
||||||
node[':frame-id'] = newId;
|
node.frameId = newId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node[':shapes']) {
|
if (node.shapes) {
|
||||||
node[':shapes'] = node[':shapes']?.map((shapeId) => {
|
node.shapes = node.shapes?.map((shapeId) => {
|
||||||
return shapeId === id ? newId : shapeId;
|
return shapeId === id ? newId : shapeId;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node[':layout-grid-cells']) {
|
if (node.layoutGridCells) {
|
||||||
node[':layout-grid-cells'] = idObjectToArray(
|
node.layoutGridCells = idObjectToArray(node.layoutGridCells, newId);
|
||||||
node[':layout-grid-cells'],
|
|
||||||
newId
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const node of shapes) {
|
for (const node of shapes) {
|
||||||
const previousId = node[':id'] as string;
|
const previousId = node.id;
|
||||||
|
|
||||||
node[':id'] = getId();
|
node.id = getId();
|
||||||
|
|
||||||
replaceChildrenId(previousId, node[':id']);
|
replaceChildrenId(previousId, node.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
|
import { Shape } from '../models/shape.model';
|
||||||
|
|
||||||
export function cleanId(id: string) {
|
export function cleanId(id: string) {
|
||||||
return id.replace('~u', '');
|
return id.replace('~u', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function idObjectToArray(obj: Record<string, any>, newId: string) {
|
export function idObjectToArray(obj: Shape[], newId: string) {
|
||||||
return Object.values(obj).map((item) => {
|
return Object.values(obj).map((item) => {
|
||||||
item[':id'] = newId;
|
return {
|
||||||
return item;
|
...item,
|
||||||
|
id: newId,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue