Skip to content

Commit

Permalink
feat: p3
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-krakowski committed Feb 1, 2023
1 parent 34be380 commit 32163b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
9 changes: 5 additions & 4 deletions packages/p3/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,21 @@ const changeStatus = ({ status, appearance }) => {
};
const archive = () => {
var _a;
console.log('archive');
const archivePage = (_a = figma.root.findChild((node) => node.name === 'Archive')) !== null && _a !== void 0 ? _a : figma.createPage();
archivePage.name = 'Archive';
figma.currentPage.selection.forEach((el) => {
const yPositions = archivePage.children.map((child) => ({
var _a;
const yPositions = (_a = archivePage.children) === null || _a === void 0 ? void 0 : _a.map((child) => ({
y: child.y,
x: child.x,
}));
const minY = Math.min(...yPositions.map((pos) => pos.y));
const x = Math.min(...yPositions.filter((pos) => pos.y === minY).map((pos) => pos.x));
console.log('isFinite(minY) ? minY - el.height - 400 : 0', isFinite(minY) ? minY - el.height - 400 : 0);
archivePage.appendChild(el);
el.name = `${el.name.replace(/^(🚧||) /, '')} | Archived on ${new Date().toLocaleDateString()}`;
el.y = minY - el.height - 400;
el.x = x;
el.y = isFinite(minY) ? minY - el.height - 400 : 0;
el.x = isFinite(x) ? x : 0;
});
};
init();
11 changes: 3 additions & 8 deletions packages/p3/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ type ChangeStatusPayload = {

const init = async () => {
figma.showUI(__uiFiles__.main, { width: 400, height: 400 })

// figma.currentPage.selection.forEach((el) => {
// console.log(el.y)
// })
}

type MessageProps =
Expand Down Expand Up @@ -126,12 +122,11 @@ const changeStatus = ({ status, appearance }: ChangeStatusPayload) => {
}

const archive = () => {
console.log('archive')
const archivePage = figma.root.findChild((node) => node.name === 'Archive') ?? figma.createPage()
archivePage.name = 'Archive'

figma.currentPage.selection.forEach((el) => {
const yPositions = archivePage.children.map((child) => ({
const yPositions = archivePage.children?.map((child) => ({
y: child.y,
x: child.x,
}))
Expand All @@ -140,8 +135,8 @@ const archive = () => {

archivePage.appendChild(el)
el.name = `${el.name.replace(/^(🚧||) /, '')} | Archived on ${new Date().toLocaleDateString()}`
el.y = minY - el.height - 400
el.x = x
el.y = isFinite(minY) ? minY - el.height - 400 : 0
el.x = isFinite(x) ? x : 0
})
}

Expand Down

0 comments on commit 32163b6

Please sign in to comment.