polarvo-layout 1.0.22 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polarvo-layout",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "type": "module",
5
5
  "author": "unigence <unigencelab@gmail.com>",
6
6
  "repository": {
@@ -79,9 +79,9 @@ const { layoutName, layoutData, activeSection, gapSize, gridNumber, gridRatio }
79
79
 
80
80
  const getBaseStyle = computed(() => {
81
81
  return {
82
- // gridTemplateColumns: gridRatio.value?.column.map((ratio) => `${ratio}%`).join(' '),
83
- // gridTemplateRows: gridRatio.value?.row.map((ratio) => `${ratio}%`).join(' '),
84
- // marginRight: layoutType.value === 'no-split' ? '0' : layoutType.value === 'three-column-split' ? '14px' : '8px',
82
+ gridTemplateColumns: gridRatio.value?.column.map((ratio) => `${ratio}%`).join(' '),
83
+ gridTemplateRows: gridRatio.value?.row.map((ratio) => `${ratio}%`).join(' '),
84
+ marginRight: layoutType.value === 'no-split' ? '0' : layoutType.value === 'three-column-split' ? '14px' : '8px',
85
85
  gap: `${gapSize.value}px`,
86
86
  };
87
87
  });
@@ -45,7 +45,7 @@ watch(
45
45
  () => layoutName.value,
46
46
  () => {
47
47
  emits('click:layout');
48
- }
48
+ },
49
49
  );
50
50
  </script>
51
51
 
@@ -171,6 +171,7 @@ class LayoutEngine {
171
171
  // 1. layoutName(내부 변수) 변경
172
172
  this._layoutName = name;
173
173
 
174
+ const currentGridRatio = { ...this.gridRatio };
174
175
  const { layoutData: userData, gridRatio, gapSize } = screenConfig || {};
175
176
  // 2. layoutData 기본값 세팅
176
177
  this._prepareLayoutData(name, userData);
@@ -179,7 +180,7 @@ class LayoutEngine {
179
180
  this._prepareLayoutConfig(name, gridRatio ?? null, gapSize ?? null);
180
181
 
181
182
  // 초기 설정인 경우 설정값 전파
182
- if (screenConfig) {
183
+ if (setting) {
183
184
  this.eventBus.emit('layout:setLayoutName', {
184
185
  $screenConfig: screenConfig,
185
186
  $layoutData: this.layoutData,
@@ -196,6 +197,7 @@ class LayoutEngine {
196
197
  $gridNumber: this.gridNumber,
197
198
  $gridRatio: this.gridRatio,
198
199
  $gapSize: this.gapSize,
200
+ $prev: { gridRatio: currentGridRatio },
199
201
  timestamp: Date.now(),
200
202
  });
201
203
  }
@@ -283,6 +285,11 @@ class LayoutEngine {
283
285
  * @param {number} ratio - 새로운 비율 값
284
286
  */
285
287
  setRatio(type, index, ratio) {
288
+ const prevRatio = {
289
+ column: [...this.gridRatio.column],
290
+ row: [...this.gridRatio.row],
291
+ };
292
+
286
293
  const ratioArray = this.gridRatio[type];
287
294
  ratioArray[index] = Number(ratio);
288
295
 
@@ -328,6 +335,7 @@ class LayoutEngine {
328
335
  this.eventBus.emit('layout:updateRatio', {
329
336
  $type: type,
330
337
  $gridRatio: this.gridRatio,
338
+ $prev: { gridRatio: prevRatio },
331
339
  timestamp: Date.now(),
332
340
  });
333
341
 
@@ -34,6 +34,7 @@ class EngineManager {
34
34
  // (캐시) dataConverter에서 사용하는 현재 컨테이너 크기
35
35
  this._containerWidth = 1920;
36
36
  this._containerHeight = 1080;
37
+ this._displaySize = { px: 1920, aspectRatio: '16/9' };
37
38
 
38
39
  this._subscriptions = [];
39
40
  this._initialized = false;
@@ -172,6 +173,7 @@ class EngineManager {
172
173
  /** [내부함수] displayEngine 연결 설정 */
173
174
  _setupDisplayEngineConnections() {
174
175
  this._subscribe('display:displayChanged', ({ $displaySize, prev }) => {
176
+ this._displaySize = $displaySize;
175
177
  this._updateElementsScale(prev.displaySize, $displaySize);
176
178
  });
177
179
  }
@@ -202,14 +204,25 @@ class EngineManager {
202
204
  /** ---------------------------------- layout Engine ---------------------------------- **/
203
205
  /** [내부함수] layoutEngine 연결 설정 */
204
206
  _setupLayoutEngineConnections() {
207
+ this._subscribe('layout:updateRatio', ({ $type, $gridRatio, $prev }) => {
208
+ const prevGridRatio = $prev?.gridRatio || { column: [100], row: [100] };
209
+ this._updateElementsScaleByRatio($type, prevGridRatio, $gridRatio);
210
+ });
211
+
205
212
  // layoutName 변경에 따른 activeSection 초기화
206
- this._subscribe('layout:setLayoutName', ({ $layoutData }) => {
213
+ this._subscribe('layout:setLayoutName', ({ $layoutData, $screenConfig }) => {
214
+ this._displaySize = { ...$screenConfig.displaySize };
215
+
207
216
  this.state.layoutData = $layoutData;
208
217
  this.setActiveSection('section1', true);
209
218
  });
210
- this._subscribe('layout:updateLayoutName', ({ $layoutData }) => {
219
+
220
+ this._subscribe('layout:updateLayoutName', ({ $layoutData, $gridRatio, $prev }) => {
211
221
  this.state.layoutData = $layoutData;
212
222
  this.setActiveSection(null, true);
223
+
224
+ const prevGridRatio = $prev?.gridRatio || { column: [100], row: [100] };
225
+ this._updateElementsScaleByRatio('column', prevGridRatio, $gridRatio);
213
226
  });
214
227
 
215
228
  this._subscribe('layout:updateLayoutData', ({ $layoutData, activeSection }) => {
@@ -217,6 +230,53 @@ class EngineManager {
217
230
  });
218
231
  }
219
232
 
233
+ _updateElementsScaleByRatio(type, oldValue, newValue) {
234
+ const oldLength = oldValue[type].length;
235
+ const newLength = newValue[type].length;
236
+
237
+ let newDisplaySize = { ...this._displaySize };
238
+
239
+ // 열 또는 행 개수가 늘어나는 경우 - 요소 크기 줄이기
240
+ if (oldLength < newLength) {
241
+ newDisplaySize.px = newDisplaySize.px / newLength;
242
+ this._updateElementsScale(this._displaySize, newDisplaySize);
243
+ }
244
+ // 열 또는 행 개수가 줄어드는 경우 - 요소 크기 늘리기
245
+ else if (oldLength > newLength) {
246
+ newDisplaySize.px = newDisplaySize.px / oldLength;
247
+ this._updateElementsScale(newDisplaySize, this._displaySize);
248
+ }
249
+ // 열 또는 행 개수는 동일하지만 비율이 변경되는 경우 - 요소 크기 조정
250
+ else {
251
+ this.state.elements = this.state.elements.map((el) => {
252
+ const sectionIndex = el.section ? parseInt(el.section.replace('section', '')) - 1 : 0;
253
+ const oldRatio = oldValue[type][sectionIndex] / 100;
254
+ const newRatio = newValue[type][sectionIndex] / 100;
255
+
256
+ const scaleFactor = newRatio / oldRatio;
257
+ return type === 'column'
258
+ ? {
259
+ ...el,
260
+ position: { ...el.position, x: el.position.x * scaleFactor },
261
+ size: { ...el.size, w: el.size.w * scaleFactor },
262
+ }
263
+ : {
264
+ ...el,
265
+ position: { ...el.position, y: el.position.y * scaleFactor },
266
+ size: { ...el.size, h: el.size.h * scaleFactor },
267
+ };
268
+ });
269
+ }
270
+
271
+ // nextTick(() => {
272
+ this.eventBus.emit('system:requestElementsScale', {
273
+ historyEvent: true,
274
+ $elements: this.state.elements,
275
+ timestamp: Date.now(),
276
+ });
277
+ // });
278
+ }
279
+
220
280
  /** activeSection 변경
221
281
  * @param {string} name - 섹션 이름
222
282
  * @param {boolean} setting - 설정모드 여부