Skip to content

Commit d2d9fd0

Browse files
Repeater Child Wrapper
1 parent 69a8eb8 commit d2d9fd0

File tree

6 files changed

+905
-2
lines changed

6 files changed

+905
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "luisa-vue",
3-
"version": "3.0.31",
3+
"version": "3.0.32",
44
"description": "Luisa - VUE Renderer for FIGMA designs. Turn your Figma or Quant-UX design into VUE, or create re-usable designlets",
55
"main": "./dist/luisa-vue3.common.js",
66
"scripts": {

src/qux/core/ExportUtil.js

+23
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,29 @@ export function getBoundingBoxByBoxes (boxes) {
646646
return result;
647647
}
648648

649+
export function getBoundingBoxByTreeChildren (children) {
650+
651+
const result = { x: 100000000, y: 100000000, w: 0, h: 0, z: 100000000, props: {resize: {}}, style: {}};
652+
653+
for (var i = 0; i < children.length; i++) {
654+
const box = children[i];
655+
result.x = Math.min(result.x, box._x);
656+
result.y = Math.min(result.y, box._y);
657+
result.w = Math.max(result.w, box._x + box.w);
658+
result.h = Math.max(result.h, box._y + box.h);
659+
result.z = Math.max(result.z, box.z);
660+
if (isFixedHorizontal(box)) {
661+
result.props.resize.fixedHorizontal = true
662+
}
663+
if (isFixedVertical(box)) {
664+
result.props.resize.fixedVertical = true
665+
}
666+
}
667+
668+
result.h -= result.y;
669+
result.w -= result.x;
670+
return result;
671+
}
649672

650673
export function createInheritedModel(model) {
651674
/**

src/qux/transformer/Flat2Tree.js

+54
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,75 @@ function layoutTree(screen) {
138138
*/
139139
// screen = Rows.addRows(screen)
140140

141+
/**
142+
* Repeaters should have only one child
143+
*/
144+
addRepeaterWrapper(screen)
145+
146+
141147
/**
142148
* First we determine the type of layout
143149
*/
144150
addLayoutType(screen)
145151

146152

153+
147154
/**
148155
* Afterwards we re order the elements
149156
*/
150157
fixParents(screen)
151158

159+
160+
152161
screen = addGrid(screen)
153162
return screen
154163
}
155164

165+
166+
function addRepeaterWrapper(element) {
167+
if (element.type === 'Repeater' && element.children.length > 1) {
168+
Logger.log(-1, "Flat2TRee.addRepeaterWrapper() > fix ", element.name, element.children.length)
169+
const wrapper = createWrapper(element)
170+
element.children = [wrapper]
171+
}
172+
element.children.forEach(child => {
173+
addRepeaterWrapper(child)
174+
})
175+
}
176+
177+
function createWrapper (element) {
178+
179+
180+
let boundingBox = Util.getBoundingBoxByTreeChildren(element.children)
181+
182+
183+
const wrapper = {
184+
id: `w${element.id}`,
185+
name: element.name + 'Wrapper',
186+
groupId: element.id,
187+
isGroup: true,
188+
type: "Box",
189+
x: 0,
190+
y: 0,
191+
w: boundingBox.w,
192+
h: boundingBox.h,
193+
style: element.style ? element.style : {},
194+
props: {
195+
resize: element.props && element.props.resize ? element.props.resize : {
196+
right: false,
197+
up: false,
198+
left: false,
199+
down: false,
200+
fixedHorizontal: false,
201+
fixedVertical: false,
202+
}
203+
},
204+
children: element.children
205+
}
206+
207+
return wrapper
208+
}
209+
156210
function addLayoutType (element) {
157211

158212
/**

src/qux/web/Repeater.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ export default {
6060
return [1,2,3,4,5,6,7]
6161
},
6262
rows () {
63+
console.debug('Repeater', this.element, this.viewModel)
6364
if (this.element && this.element.props && this.element.props.databinding) {
6465
let path = this.element.props.databinding.default
6566
let value = JSONPath.get(this.viewModel, path)
66-
Logger.log(5, 'Repeater.rows() > exit path: > ' + path, value)
67+
Logger.log(-5, 'Repeater.rows() > exit path: > ' + path, value)
6768
if (Array.isArray(value)) {
6869
return value
6970
} else {

tests/unit/RepeaterBug.spec.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import ModelTransformer from '../../src/qux/core/ModelTransformer'
2+
import reaterBug from './data/ReaterBug.json'
3+
import * as Util from '../../src/qux/core/ExportUtil'
4+
import * as TestUtil from './TestUtil'
5+
import CSSOptimizer from '../../src/qux/core/CSSOptimizer'
6+
import CSSFactory from '../../src/qux/core/CSSFactory'
7+
8+
test('Test Repeater Bug', () => {
9+
10+
/**
11+
* Check that group is copied
12+
*/
13+
14+
const t = new ModelTransformer(reaterBug, {
15+
css: {
16+
grid: true
17+
}
18+
})
19+
const model = t.transform()
20+
21+
expect(model).not.toBeNull()
22+
23+
const start = model.screens[0]
24+
console.debug(TestUtil.print(start))
25+
26+
27+
const grid = TestUtil.findOneElementsByName(start, "Grid")
28+
expect(grid.children.length).toBe(1)
29+
expect(grid.children[0].name).toBe("GridWrapper")
30+
31+
});

0 commit comments

Comments
 (0)