Skip to content

Commit

Permalink
feat(expanded): collapse all new created elements by default
Browse files Browse the repository at this point in the history
update typings
do not show image fills
  • Loading branch information
ph1p committed Feb 6, 2020
1 parent d24407f commit b910fb9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 32 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ At the bottom you can set the arrow style.
- [ ] Save settings in Storage
- [ ] Show and hide all measurements
- [ ] Better resizing
- [ ] Collapse Groups
- [x] Collapse Groups
- [x] Show typo specific informations
- [x] Add tooltip group
- [x] Add tooltip image properties

Feel free to open a feature request: https://github.com/ph1p/figma-measure/issues

Expand Down
40 changes: 12 additions & 28 deletions figma.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ declare global {
center: Vector;
zoom: number;
scrollAndZoomIntoView(nodes: ReadonlyArray<BaseNode>): void;

/** PROPOSED API ONLY */
readonly bounds: Rect;
}

Expand Down Expand Up @@ -516,9 +514,6 @@ declare global {
interface SceneNodeMixin {
visible: boolean;
locked: boolean;

/** PROPOSED API ONLY */
expanded: boolean;
}

interface ChildrenMixin {
Expand All @@ -527,20 +522,18 @@ declare global {
appendChild(child: SceneNode): void;
insertChild(index: number, child: SceneNode): void;

/** PROPOSED API ONLY */
findChildren(callback?: (node: SceneNode) => boolean): SceneNode[];
/** PROPOSED API ONLY */
findChild(callback: (node: SceneNode) => boolean): SceneNode | null;

/**
* If you only need to search immediate children, it is much faster
* to call node.children.filter(callback) or node.findChildren(callback)
* to call node.children.filter(callback)
*/
findAll(callback?: (node: SceneNode) => boolean): SceneNode[];

/**
* If you only need to search immediate children, it is much faster
* to call node.children.find(callback) or node.findChild(callback)
* to call node.children.find(callback)
*/
findOne(callback: (node: SceneNode) => boolean): SceneNode | null;
}
Expand All @@ -558,11 +551,9 @@ declare global {

readonly width: number;
readonly height: number;

/** PROPOSED API ONLY */
constrainProportions: boolean;

layoutAlign: 'MIN' | 'CENTER' | 'MAX'; // applicable only inside auto-layout frames
layoutAlign: 'MIN' | 'CENTER' | 'MAX' | 'STRETCH'; // applicable only inside auto-layout frames

resize(width: number, height: number): void;
resizeWithoutConstraints(width: number, height: number): void;
Expand All @@ -577,6 +568,7 @@ declare global {
}

interface ContainerMixin {
expanded: boolean;
backgrounds: ReadonlyArray<Paint>; // DEPRECATED: use 'fills' instead
layoutGrids: ReadonlyArray<LayoutGrid>;
clipsContent: boolean;
Expand All @@ -598,17 +590,13 @@ declare global {
fills: ReadonlyArray<Paint> | PluginAPI['mixed'];
strokes: ReadonlyArray<Paint>;
strokeWeight: number;
strokeMiterLimit: number;
strokeAlign: 'CENTER' | 'INSIDE' | 'OUTSIDE';
strokeCap: StrokeCap | PluginAPI['mixed'];
strokeJoin: StrokeJoin | PluginAPI['mixed'];
dashPattern: ReadonlyArray<number>;
fillStyleId: string | PluginAPI['mixed'];
strokeStyleId: string;

/** PROPOSED API ONLY */
strokeMiterLimit: number;

/** PROPOSED API ONLY */
outlineStroke(): VectorNode | null;
}

Expand All @@ -630,10 +618,9 @@ declare global {
}

interface RelaunchableMixin {
/** PROPOSED API ONLY */
setRelaunchData(description: string): void;
/** PROPOSED API ONLY */
clearRelaunchData(): void;
setRelaunchData(relaunchData: {
[command: string]: /* description */ string;
}): void;
}

interface ReactionMixin {
Expand Down Expand Up @@ -688,23 +675,20 @@ declare global {

appendChild(child: PageNode): void;
insertChild(index: number, child: PageNode): void;

/** PROPOSED API ONLY */
findChildren(callback?: (node: PageNode) => boolean): Array<PageNode>;
/** PROPOSED API ONLY */
findChild(callback: (node: PageNode) => boolean): PageNode | null;

/**
* If you only need to search immediate children, it is much faster
* to call node.children.filter(callback) or node.findChildren(callback)
* to call node.children.filter(callback)
*/
findAll(
callback?: (node: PageNode | SceneNode) => boolean
): Array<PageNode | SceneNode>;

/**
* If you only need to search immediate children, it is much faster
* to call node.children.find(callback) or node.findChild(callback)
* to call node.children.find(callback)
*/
findOne(
callback: (node: PageNode | SceneNode) => boolean
Expand Down Expand Up @@ -885,8 +869,6 @@ declare global {
readonly type: 'INSTANCE';
clone(): InstanceNode;
masterComponent: ComponentNode;

/** PROPOSED API ONLY */
scaleFactor: number;
}

Expand All @@ -897,6 +879,8 @@ declare global {
readonly type: 'BOOLEAN_OPERATION';
clone(): BooleanOperationNode;
booleanOperation: 'UNION' | 'INTERSECT' | 'SUBTRACT' | 'EXCLUDE';

expanded: boolean;
}

type BaseNode = DocumentNode | PageNode | SceneNode;
Expand Down
5 changes: 3 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const getLineFrame = (node, data) => {
isHorizontal: data.isHorizontal,
alignment: data.alignment
};

frame.expanded = false;
frame.setPluginData(name, JSON.stringify(lineData));

return frame;
Expand Down Expand Up @@ -429,6 +429,7 @@ async function createLineFromMessage({
} else {
const measureGroup = figma.group(nodes, figma.currentPage);
measureGroup.locked = true;
measureGroup.expanded = false;
measureGroup.name = `📐 Measurements | ${node.name}`;

measureGroup.setPluginData('parent', node.id);
Expand Down Expand Up @@ -489,14 +490,14 @@ const setAngleInCanvas = () => {
const ySin = transformPosition[1][1];

// group

const group = nodeGroup(node);

if (group) {
group.appendChild(angleFrame);
} else {
const group = figma.group([angleFrame], figma.currentPage);
group.locked = true;
group.expanded = false;
group.name = `📐 Measurements | ${node.name}`;
group.setPluginData('parent', node.id);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/tooltip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const getTooltipFrame = (node, data) => {
if (!tooltipFrame) {
tooltipFrame = figma.createFrame();
}
tooltipFrame.expanded = false;
tooltipFrame.name = 'Tooltip ' + node.name;
tooltipFrame.locked = true;
tooltipFrame.clipsContent = false;
Expand Down
7 changes: 6 additions & 1 deletion src/main/tooltip/types/parts/fills.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { createTooltipTextNode, colorString } from '../../../helper';

export default function fillsPart(node, { fontColor = '', fontSize = 0 }) {
if (node.fills) {

const fillsAvailable = node.fills.some(f => f.type !== 'IMAGE');

if (fillsAvailable) {
const textNode = createTooltipTextNode({
fontColor,
fontSize
});

textNode.characters += `Fill / Color\n`;

(node.fills as any[]).map(f => {
if (f.type === 'SOLID') {
textNode.characters += colorString(f.color, f.opacity);
Expand Down

0 comments on commit b910fb9

Please sign in to comment.