mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-04 13:50:13 -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 { getFileUrl } from './get-file-url';
|
||||
import { idObjectToArray } from './clean-id';
|
||||
|
||||
interface Shape {
|
||||
':id': string;
|
||||
':frame-id'?: string;
|
||||
':parent-id'?: string;
|
||||
':shapes'?: string[];
|
||||
':layout-grid-cells'?: string[];
|
||||
}
|
||||
import { Shape } from '../models/shape.model';
|
||||
|
||||
function replaceIds(shapes: Shape[]) {
|
||||
let id = 1;
|
||||
|
@ -20,35 +13,32 @@ function replaceIds(shapes: Shape[]) {
|
|||
|
||||
function replaceChildrenId(id: string, newId: string) {
|
||||
for (const node of shapes) {
|
||||
if (node[':parent-id'] === id) {
|
||||
node[':parent-id'] = newId;
|
||||
if (node.parentId === id) {
|
||||
node.parentId = newId;
|
||||
}
|
||||
|
||||
if (node[':frame-id'] === id) {
|
||||
node[':frame-id'] = newId;
|
||||
if (node.frameId === id) {
|
||||
node.frameId = newId;
|
||||
}
|
||||
|
||||
if (node[':shapes']) {
|
||||
node[':shapes'] = node[':shapes']?.map((shapeId) => {
|
||||
if (node.shapes) {
|
||||
node.shapes = node.shapes?.map((shapeId) => {
|
||||
return shapeId === id ? newId : shapeId;
|
||||
});
|
||||
}
|
||||
|
||||
if (node[':layout-grid-cells']) {
|
||||
node[':layout-grid-cells'] = idObjectToArray(
|
||||
node[':layout-grid-cells'],
|
||||
newId
|
||||
);
|
||||
if (node.layoutGridCells) {
|
||||
node.layoutGridCells = idObjectToArray(node.layoutGridCells, newId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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) => {
|
||||
item[':id'] = newId;
|
||||
return item;
|
||||
return {
|
||||
...item,
|
||||
id: newId,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue