polarvo-layout 1.0.18 → 1.0.20
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 +1 -1
- package/src/components/FastMenu/DesignFastmenu.vue +2 -2
- package/src/components/FastMenu/LayoutFastMenu.vue +6 -6
- package/src/components/SideBar/ElementSideBar.vue +2 -2
- package/src/components/SideBar/LayoutSettingSideBar.vue +6 -6
- package/src/configs/index.js +1 -0
- package/src/core/engines/DisplayEngine.js +35 -38
- package/src/core/engines/FreeDropEngine.js +41 -42
- package/src/core/engines/GridDropEngine.js +34 -43
- package/src/core/engines/HistoryEngine.js +56 -51
- package/src/core/engines/LayoutEngine.js +38 -26
- package/src/core/engines/originals/FreeDropEngine_0402.js +786 -0
- package/src/core/engines/originals/GridDropEngine_0402.js +557 -0
- package/src/core/managers/EngineManager.js +73 -116
- package/src/core/managers/originals/EngineManager_0402.js +826 -0
- package/src/library/DisplayLibrary.js +12 -15
- package/src/library/FreeDropLibrary.js +6 -4
- package/src/library/GridDropLibrary.js +3 -5
- package/src/library/LayoutLibrary.js +43 -34
- package/src/library/originals/DisplayLibrary_0402.js +137 -0
- package/src/library/originals/FreeDropLibrary_0402.js +185 -0
- package/src/library/originals/GridDropLibrary_0402.js +202 -0
- package/src/library/originals/HistoryLibrary_0402.js +98 -0
- package/src/library/originals/LayoutLibrary_0402.js +264 -0
- package/src/utils/index.js +8 -3
package/package.json
CHANGED
|
@@ -31,8 +31,8 @@ const props = defineProps({
|
|
|
31
31
|
const { activeDesign } = toRefs(props.polarvo.display.state);
|
|
32
32
|
const { setActiveDesign } = props.polarvo.display;
|
|
33
33
|
|
|
34
|
-
const {
|
|
35
|
-
const sectionMode = computed(() =>
|
|
34
|
+
const { activeMode, activeSection } = toRefs(props.polarvo.layout.state);
|
|
35
|
+
const sectionMode = computed(() => activeMode.value);
|
|
36
36
|
|
|
37
37
|
const { activeElement: freeActiveElement } = toRefs(props.polarvo.freeDrop.state);
|
|
38
38
|
const { activeElement: gridActiveElement } = toRefs(props.polarvo.gridDrop.state);
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<div class="text-sm">보조선 표시</div>
|
|
19
19
|
<input
|
|
20
20
|
type="checkbox"
|
|
21
|
-
:checked="
|
|
21
|
+
:checked="activeConfig?.showGuideLine"
|
|
22
22
|
@change="setSectionConfig('guideLine', $event.target.checked)"
|
|
23
23
|
/>
|
|
24
24
|
</div>
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
min="1"
|
|
34
34
|
max="50"
|
|
35
35
|
class="text-sm text-center w-6 border-b-2 border-white focus:outline-none focus:border-b-2 focus:border-blue-500"
|
|
36
|
-
:value="
|
|
36
|
+
:value="activeConfig?.gridRows"
|
|
37
37
|
@change="setSectionConfig('row', $event.target.value)"
|
|
38
38
|
/>
|
|
39
39
|
</div>
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
min="1"
|
|
46
46
|
max="12"
|
|
47
47
|
class="text-sm text-center w-6 border-b-2 border-white focus:outline-none focus:border-b-2 focus:border-blue-500"
|
|
48
|
-
:value="
|
|
48
|
+
:value="activeConfig?.gridColumns"
|
|
49
49
|
@change="setSectionConfig('column', $event.target.value)"
|
|
50
50
|
/>
|
|
51
51
|
</div>
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
min="0"
|
|
58
58
|
max="12"
|
|
59
59
|
class="text-sm text-center w-6 border-b-2 border-white focus:outline-none focus:border-b-2 focus:border-blue-500"
|
|
60
|
-
:value="
|
|
60
|
+
:value="activeConfig?.gridGap"
|
|
61
61
|
@change="setSectionConfig('gap', $event.target.value)"
|
|
62
62
|
/>
|
|
63
63
|
</div>
|
|
@@ -77,9 +77,9 @@ const props = defineProps({
|
|
|
77
77
|
},
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
const { activeSection,
|
|
80
|
+
const { activeSection, activeMode, activeConfig } = toRefs(props.polarvo.layout.state);
|
|
81
81
|
const { setSectionMode, setSectionConfig } = props.polarvo.layout;
|
|
82
|
-
const sectionMode = computed(() =>
|
|
82
|
+
const sectionMode = computed(() => activeMode.value);
|
|
83
83
|
</script>
|
|
84
84
|
|
|
85
85
|
<style scoped lang="scss">
|
|
@@ -29,8 +29,8 @@ const props = defineProps({
|
|
|
29
29
|
const { addElement: addElementToFree } = props.polarvo.freeDrop;
|
|
30
30
|
const { addElement: addElementToGrid } = props.polarvo.gridDrop;
|
|
31
31
|
|
|
32
|
-
const {
|
|
33
|
-
const sectionMode = computed(() =>
|
|
32
|
+
const { activeMode } = toRefs(props.polarvo.layout.state);
|
|
33
|
+
const sectionMode = computed(() => activeMode.value);
|
|
34
34
|
|
|
35
35
|
const allElements = ref([]);
|
|
36
36
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
id="row-count"
|
|
26
26
|
min="1"
|
|
27
27
|
max="50"
|
|
28
|
-
:value="
|
|
28
|
+
:value="activeConfig.gridRows"
|
|
29
29
|
@change="setSectionConfig('row', $event.target.value)"
|
|
30
30
|
/>
|
|
31
31
|
</div>
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
id="column-count"
|
|
38
38
|
min="1"
|
|
39
39
|
max="12"
|
|
40
|
-
:value="
|
|
40
|
+
:value="activeConfig.gridColumns"
|
|
41
41
|
@change="setSectionConfig('column', $event.target.value)"
|
|
42
42
|
/>
|
|
43
43
|
</div>
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
id="gap-size"
|
|
50
50
|
min="0"
|
|
51
51
|
max="12"
|
|
52
|
-
:value="
|
|
52
|
+
:value="activeConfig.gridGap"
|
|
53
53
|
@change="setSectionConfig('gap', $event.target.value)"
|
|
54
54
|
/>
|
|
55
55
|
</div>
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
class="text-sm w-4 h-4 border-b-2 border-white focus:outline-none focus:border-b-2 focus:border-blue-500"
|
|
64
64
|
type="checkbox"
|
|
65
65
|
id="guide-line"
|
|
66
|
-
:checked="
|
|
66
|
+
:checked="activeConfig.showGuideLine"
|
|
67
67
|
@change="setSectionConfig('guideLine', $event.target.checked)"
|
|
68
68
|
/>
|
|
69
69
|
</div>
|
|
@@ -81,10 +81,10 @@ const props = defineProps({
|
|
|
81
81
|
required: true,
|
|
82
82
|
},
|
|
83
83
|
});
|
|
84
|
-
const {
|
|
84
|
+
const { activeMode, activeConfig } = toRefs(props.polarvo.layout.state);
|
|
85
85
|
const { setSectionMode, setSectionConfig } = props.polarvo.layout;
|
|
86
86
|
|
|
87
|
-
const sectionMode = computed(() =>
|
|
87
|
+
const sectionMode = computed(() => activeMode.value);
|
|
88
88
|
</script>
|
|
89
89
|
|
|
90
90
|
<style lang="scss" scoped></style>
|
package/src/configs/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { omit } from 'lodash-es';
|
|
2
|
-
|
|
3
1
|
// event 발행 시 'display'으로 시작하는 이름 사용
|
|
4
2
|
class DisplayEngine {
|
|
5
3
|
constructor({ eventBus, options }) {
|
|
@@ -34,17 +32,7 @@ class DisplayEngine {
|
|
|
34
32
|
this._resetDisplaySizeByMode(this.displayMode);
|
|
35
33
|
|
|
36
34
|
this.eventBus.emit('display:engineInitialized', {
|
|
37
|
-
displaySize: this.displaySize,
|
|
38
|
-
timestamp: Date.now(),
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
this._subscribe('system:enginesReset', () => {
|
|
43
|
-
this.displayMode = 'desktop';
|
|
44
|
-
this._resetDisplaySizeByMode(this.displayMode);
|
|
45
|
-
|
|
46
|
-
this.eventBus.emit('display:enginesReset', {
|
|
47
|
-
displaySize: this.displaySize,
|
|
35
|
+
$displaySize: this.displaySize,
|
|
48
36
|
timestamp: Date.now(),
|
|
49
37
|
});
|
|
50
38
|
});
|
|
@@ -54,15 +42,9 @@ class DisplayEngine {
|
|
|
54
42
|
this.setActiveDesign(null);
|
|
55
43
|
});
|
|
56
44
|
|
|
57
|
-
this._subscribe('layout:setLayoutName', ({ screenConfig }) => {
|
|
58
|
-
this.displayMode = screenConfig.displayMode;
|
|
59
|
-
this.displaySize = {
|
|
60
|
-
|
|
61
|
-
this.eventBus.emit('display:setLayoutName', {
|
|
62
|
-
displayMode: this.displayMode,
|
|
63
|
-
displaySize: this.displaySize,
|
|
64
|
-
timestamp: Date.now(),
|
|
65
|
-
});
|
|
45
|
+
this._subscribe('layout:setLayoutName', ({ $screenConfig }) => {
|
|
46
|
+
this.displayMode = $screenConfig.displayMode;
|
|
47
|
+
this.displaySize = { ...$screenConfig.displaySize };
|
|
66
48
|
});
|
|
67
49
|
|
|
68
50
|
this._subscribe('freeDrop:startDrag', () => {
|
|
@@ -72,19 +54,29 @@ class DisplayEngine {
|
|
|
72
54
|
|
|
73
55
|
this._subscribe('gridDrop:setActiveElement', ({ action }) => {
|
|
74
56
|
if (action === 'update') return;
|
|
75
|
-
|
|
76
|
-
// this.setActiveMenu('element');
|
|
77
|
-
// } else {
|
|
78
|
-
this.setActiveMenu(null);
|
|
79
|
-
// }
|
|
80
|
-
|
|
57
|
+
this.setActiveMenu(null);
|
|
81
58
|
this.setActiveDesign(null);
|
|
82
59
|
});
|
|
83
60
|
|
|
84
61
|
this._subscribe('gridDrop:requestOpenElementBar', () => {
|
|
85
62
|
this.setActiveMenu('element');
|
|
86
63
|
this.setActiveDesign(null);
|
|
87
|
-
})
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 엔진 초기화 */
|
|
68
|
+
reset() {
|
|
69
|
+
this.activeMenu = null;
|
|
70
|
+
this.activeDesign = null;
|
|
71
|
+
this.displayMode = 'desktop';
|
|
72
|
+
this._resetDisplaySizeByMode(this.displayMode);
|
|
73
|
+
|
|
74
|
+
console.log('[DisplayEngine] 리셋 완료');
|
|
75
|
+
|
|
76
|
+
this.eventBus.emit('display:enginesReset', {
|
|
77
|
+
$displaySize: this.displaySize,
|
|
78
|
+
timestamp: Date.now(),
|
|
79
|
+
});
|
|
88
80
|
}
|
|
89
81
|
|
|
90
82
|
/** 삭제 및 정리 */
|
|
@@ -95,6 +87,8 @@ class DisplayEngine {
|
|
|
95
87
|
}
|
|
96
88
|
});
|
|
97
89
|
|
|
90
|
+
this.reset();
|
|
91
|
+
|
|
98
92
|
this._subscriptions = [];
|
|
99
93
|
this.eventBus = null;
|
|
100
94
|
this.resource = null;
|
|
@@ -139,7 +133,7 @@ class DisplayEngine {
|
|
|
139
133
|
this.activeMenu = name;
|
|
140
134
|
|
|
141
135
|
this.eventBus.emit('display:updateActiveMenu', {
|
|
142
|
-
menu: name,
|
|
136
|
+
$menu: name,
|
|
143
137
|
timestamp: Date.now(),
|
|
144
138
|
});
|
|
145
139
|
}
|
|
@@ -152,7 +146,7 @@ class DisplayEngine {
|
|
|
152
146
|
this.activeDesign = name;
|
|
153
147
|
|
|
154
148
|
this.eventBus.emit('display:updateActiveDesign', {
|
|
155
|
-
design: name,
|
|
149
|
+
$design: name,
|
|
156
150
|
timestamp: Date.now(),
|
|
157
151
|
});
|
|
158
152
|
}
|
|
@@ -168,15 +162,16 @@ class DisplayEngine {
|
|
|
168
162
|
|
|
169
163
|
if (this.displayMode === mode) return;
|
|
170
164
|
|
|
165
|
+
const prevDisplayMode = this.displayMode;
|
|
171
166
|
this.displayMode = mode;
|
|
172
167
|
const prevDisplaySize = { ...this.displaySize };
|
|
173
168
|
this._resetDisplaySizeByMode(mode);
|
|
174
169
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
displayMode: this.displayMode,
|
|
178
|
-
displaySize: this.displaySize,
|
|
179
|
-
prev: { displaySize: prevDisplaySize },
|
|
170
|
+
this.eventBus.emit('display:displayChanged', {
|
|
171
|
+
type: 'mode',
|
|
172
|
+
$displayMode: this.displayMode,
|
|
173
|
+
$displaySize: this.displaySize,
|
|
174
|
+
prev: { displayMode: prevDisplayMode, displaySize: prevDisplaySize },
|
|
180
175
|
timestamp: Date.now(),
|
|
181
176
|
});
|
|
182
177
|
}
|
|
@@ -224,8 +219,10 @@ class DisplayEngine {
|
|
|
224
219
|
const prevDisplaySize = { ...this.displaySize };
|
|
225
220
|
this.displaySize[type] = Math.min(Math.max(0, numSize), typeLimit.max);
|
|
226
221
|
|
|
227
|
-
this.eventBus.emit('display:
|
|
228
|
-
|
|
222
|
+
this.eventBus.emit('display:displayChanged', {
|
|
223
|
+
type: 'size',
|
|
224
|
+
$displayMode: this.displayMode,
|
|
225
|
+
$displaySize: this.displaySize,
|
|
229
226
|
prev: { displaySize: prevDisplaySize },
|
|
230
227
|
timestamp: Date.now(),
|
|
231
228
|
});
|
|
@@ -14,8 +14,10 @@ class FreeDropEngine {
|
|
|
14
14
|
this._elementsUpdate = false; // 원본 요소 목록 변경 플래그
|
|
15
15
|
this._freeElements = []; // 로컬에서 사용하는 요소 목록
|
|
16
16
|
|
|
17
|
-
this._activeData = null;
|
|
18
17
|
this._activeSection = null;
|
|
18
|
+
this._activeMode = null;
|
|
19
|
+
this._activeConfig = null;
|
|
20
|
+
|
|
19
21
|
this._activeElement = null; // 드래그 중인 배치요소
|
|
20
22
|
|
|
21
23
|
this.guides = { x: null, y: null, w: null, h: null }; // 가이드 라인 위치
|
|
@@ -50,43 +52,43 @@ class FreeDropEngine {
|
|
|
50
52
|
/** [내부함수] 구독 설정 */
|
|
51
53
|
_setupSubscriptions() {
|
|
52
54
|
// 초기화 완료 이벤트 구독 - from DisplayEngine
|
|
53
|
-
this._subscribe('display:engineInitialized', ({ displaySize }) => {
|
|
54
|
-
const { gridSize } = displaySize;
|
|
55
|
+
this._subscribe('display:engineInitialized', ({ $displaySize }) => {
|
|
56
|
+
const { gridSize } = $displaySize;
|
|
55
57
|
this._gridSize = gridSize;
|
|
56
58
|
|
|
57
59
|
this._initialize();
|
|
58
60
|
});
|
|
59
61
|
|
|
60
|
-
this._subscribe('display:enginesReset', ({ displaySize }) => {
|
|
61
|
-
const { gridSize } = displaySize;
|
|
62
|
+
this._subscribe('display:enginesReset', ({ $displaySize }) => {
|
|
63
|
+
const { gridSize } = $displaySize;
|
|
62
64
|
this._gridSize = gridSize;
|
|
63
65
|
|
|
64
66
|
this._initialize();
|
|
65
67
|
});
|
|
66
68
|
|
|
67
69
|
// displayMode 변경 감지 (displaySize가 함께 초기화됨)
|
|
68
|
-
this._subscribe('display:
|
|
69
|
-
const { gridSize } = displaySize;
|
|
70
|
+
this._subscribe('display:displayChanged', ({ $displaySize }) => {
|
|
71
|
+
const { gridSize } = $displaySize;
|
|
70
72
|
this._gridSize = gridSize;
|
|
71
73
|
});
|
|
72
74
|
|
|
73
75
|
// layoutName 변경 감지 (gridNumber가 함께 초기화됨)
|
|
74
|
-
this._subscribe('layout:setLayoutName', ({ gridNumber }) => {
|
|
75
|
-
this._gridNumber = gridNumber;
|
|
76
|
+
this._subscribe('layout:setLayoutName', ({ $gridNumber }) => {
|
|
77
|
+
this._gridNumber = $gridNumber;
|
|
76
78
|
});
|
|
77
|
-
this._subscribe('layout:updateLayoutName', ({ gridNumber }) => {
|
|
78
|
-
this._gridNumber = gridNumber;
|
|
79
|
+
this._subscribe('layout:updateLayoutName', ({ $gridNumber }) => {
|
|
80
|
+
this._gridNumber = $gridNumber;
|
|
79
81
|
});
|
|
80
82
|
|
|
81
|
-
// activeSection 변경 감지
|
|
82
|
-
this._subscribe('system:updateActiveSection', ({
|
|
83
|
-
this._activeSection =
|
|
84
|
-
this.
|
|
85
|
-
|
|
83
|
+
// activeSection 변경 감지
|
|
84
|
+
this._subscribe('system:updateActiveSection', ({ $section, $mode, $config }) => {
|
|
85
|
+
this._activeSection = $section;
|
|
86
|
+
this._activeMode = $mode;
|
|
87
|
+
this._activeConfig = $config;
|
|
86
88
|
});
|
|
87
89
|
|
|
88
|
-
this._subscribe('system:setElements', ({ elements }) => {
|
|
89
|
-
this._elements = elements;
|
|
90
|
+
this._subscribe('system:setElements', ({ $elements }) => {
|
|
91
|
+
this._elements = $elements;
|
|
90
92
|
this._elementsUpdate = true;
|
|
91
93
|
|
|
92
94
|
// 활성화 요소 초기화
|
|
@@ -98,23 +100,16 @@ class FreeDropEngine {
|
|
|
98
100
|
});
|
|
99
101
|
});
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this._activeData = activeData;
|
|
105
|
-
}
|
|
103
|
+
this._subscribe('layout:updateLayoutData', ({ $mode, $config }) => {
|
|
104
|
+
this._activeMode = $mode;
|
|
105
|
+
this._activeConfig = $config;
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
this._subscribe('system:
|
|
109
|
-
this._elements = elements;
|
|
108
|
+
this._subscribe('system:requestUpdateElement', ({ $elements, $elementId }) => {
|
|
109
|
+
this._elements = $elements;
|
|
110
110
|
this._elementsUpdate = true;
|
|
111
111
|
|
|
112
|
-
this.setActiveElement(this._elements.find((x) => x.id === elementId));
|
|
113
|
-
|
|
114
|
-
if (activeData?.mode == 'free') {
|
|
115
|
-
this._activeData = activeData;
|
|
116
|
-
}
|
|
117
|
-
|
|
112
|
+
this.setActiveElement(this._elements.find((x) => x.id === $elementId));
|
|
118
113
|
this.eventBus.emit('freeDrop:requestUpdateData', {
|
|
119
114
|
elements: cloneDeep(this.freeElements),
|
|
120
115
|
guides: this.guides,
|
|
@@ -138,8 +133,8 @@ class FreeDropEngine {
|
|
|
138
133
|
});
|
|
139
134
|
});
|
|
140
135
|
|
|
141
|
-
this._subscribe('system:
|
|
142
|
-
this._elements = elements;
|
|
136
|
+
this._subscribe('system:requestElementsScale', ({ $elements }) => {
|
|
137
|
+
this._elements = $elements;
|
|
143
138
|
this._elementsUpdate = true;
|
|
144
139
|
});
|
|
145
140
|
|
|
@@ -155,6 +150,12 @@ class FreeDropEngine {
|
|
|
155
150
|
});
|
|
156
151
|
}
|
|
157
152
|
|
|
153
|
+
/** 엔진 초기화 */
|
|
154
|
+
reset() {
|
|
155
|
+
this._initialize();
|
|
156
|
+
console.log('[FreeDropEngine] 리셋 완료');
|
|
157
|
+
}
|
|
158
|
+
|
|
158
159
|
/** 삭제 및 정리 */
|
|
159
160
|
destroy() {
|
|
160
161
|
this._subscriptions.forEach((unsubscribe) => {
|
|
@@ -163,7 +164,8 @@ class FreeDropEngine {
|
|
|
163
164
|
}
|
|
164
165
|
});
|
|
165
166
|
|
|
166
|
-
this.
|
|
167
|
+
this.reset();
|
|
168
|
+
|
|
167
169
|
this._subscriptions = [];
|
|
168
170
|
this.eventBus = null;
|
|
169
171
|
this.resource = null;
|
|
@@ -223,8 +225,9 @@ class FreeDropEngine {
|
|
|
223
225
|
this._startSize = { w: 0, h: 0 };
|
|
224
226
|
this._offsetPos = { x: 0, y: 0 };
|
|
225
227
|
|
|
226
|
-
this._activeData = null;
|
|
227
228
|
this._activeSection = null;
|
|
229
|
+
this._activeMode = null;
|
|
230
|
+
this._activeConfig = null;
|
|
228
231
|
this._activeElement = null;
|
|
229
232
|
this._alreadyExist = false;
|
|
230
233
|
|
|
@@ -309,8 +312,8 @@ class FreeDropEngine {
|
|
|
309
312
|
* @return {boolean} - 가이드라인 표시 여부
|
|
310
313
|
*/
|
|
311
314
|
_getGuideLineConfig() {
|
|
312
|
-
if (this.
|
|
313
|
-
return this.
|
|
315
|
+
if (this._activeConfig) {
|
|
316
|
+
return this._activeConfig?.showGuideLine;
|
|
314
317
|
} else {
|
|
315
318
|
return false;
|
|
316
319
|
}
|
|
@@ -337,11 +340,7 @@ class FreeDropEngine {
|
|
|
337
340
|
* @param {string} elName - 추가할 아이템 이름
|
|
338
341
|
*/
|
|
339
342
|
addElement(event, elName) {
|
|
340
|
-
if (
|
|
341
|
-
console.error('[FreeDropEngine] 활성화된 데이터가 없습니다.');
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
if (this._activeData.mode !== 'free') return;
|
|
343
|
+
if (this._activeMode !== 'free') return;
|
|
345
344
|
|
|
346
345
|
this._startPos = { x: event.clientX, y: event.clientY };
|
|
347
346
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cloneDeep
|
|
1
|
+
import { cloneDeep } from 'lodash-es';
|
|
2
2
|
|
|
3
3
|
// event 발행 시 'gridDrop'으로 시작하는 이름 사용
|
|
4
4
|
class GridDropEngine {
|
|
@@ -10,9 +10,10 @@ class GridDropEngine {
|
|
|
10
10
|
this._elementsUpdate = false; // 원본 요소 목록 변경 플래그
|
|
11
11
|
this._gridElements = []; // 로컬에서 사용하는 요소 목록
|
|
12
12
|
|
|
13
|
-
this.
|
|
14
|
-
this._activeData = null;
|
|
13
|
+
// this._activeData = null;
|
|
15
14
|
this._activeSection = null;
|
|
15
|
+
this._activeMode = null;
|
|
16
|
+
this._activeConfig = null;
|
|
16
17
|
this._activeElement = null;
|
|
17
18
|
|
|
18
19
|
this._targetCell = null; // 드래그 대상 셀
|
|
@@ -50,25 +51,15 @@ class GridDropEngine {
|
|
|
50
51
|
this._initialize();
|
|
51
52
|
});
|
|
52
53
|
|
|
53
|
-
this._subscribe('system:enginesReset', () => {
|
|
54
|
-
this._initialize();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// layoutData 변경 감지
|
|
58
|
-
this._subscribe('system:updateLayoutData', ({ layoutData, activeData }) => {
|
|
59
|
-
this._layoutData = layoutData;
|
|
60
|
-
this._activeData = activeData;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
54
|
// activeSection 변경 감지 (activeData가 함께 초기화됨)
|
|
64
|
-
this._subscribe('system:updateActiveSection', ({
|
|
65
|
-
this._activeSection =
|
|
66
|
-
this.
|
|
67
|
-
|
|
55
|
+
this._subscribe('system:updateActiveSection', ({ $section, $mode, $config }) => {
|
|
56
|
+
this._activeSection = $section;
|
|
57
|
+
this._activeMode = $mode;
|
|
58
|
+
this._activeConfig = $config;
|
|
68
59
|
});
|
|
69
60
|
|
|
70
|
-
this._subscribe('system:setElements', ({ elements }) => {
|
|
71
|
-
this._elements = elements;
|
|
61
|
+
this._subscribe('system:setElements', ({ $elements }) => {
|
|
62
|
+
this._elements = $elements;
|
|
72
63
|
this._elementsUpdate = true;
|
|
73
64
|
|
|
74
65
|
// 활성화 요소 초기화
|
|
@@ -80,22 +71,15 @@ class GridDropEngine {
|
|
|
80
71
|
});
|
|
81
72
|
});
|
|
82
73
|
|
|
83
|
-
this._subscribe('
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this._activeData = activeData;
|
|
87
|
-
}
|
|
74
|
+
this._subscribe('layout:updateLayoutData', ({ $mode, $config }) => {
|
|
75
|
+
this._activeMode = $mode;
|
|
76
|
+
this._activeConfig = $config;
|
|
88
77
|
});
|
|
89
78
|
|
|
90
|
-
this._subscribe('system:
|
|
91
|
-
this._elements = elements;
|
|
79
|
+
this._subscribe('system:requestUpdateElement', ({ action, $elements, $elementId }) => {
|
|
80
|
+
this._elements = $elements;
|
|
92
81
|
this._elementsUpdate = true;
|
|
93
|
-
this.setActiveElement(this._elements.find((x) => x.id === elementId) || null, action);
|
|
94
|
-
|
|
95
|
-
if (activeData?.mode == 'grid') {
|
|
96
|
-
this._layoutData = layoutData;
|
|
97
|
-
this._activeData = activeData;
|
|
98
|
-
}
|
|
82
|
+
this.setActiveElement(this._elements.find((x) => x.id === $elementId) || null, action);
|
|
99
83
|
|
|
100
84
|
this.eventBus.emit('gridDrop:requestUpdateData', {
|
|
101
85
|
elements: cloneDeep(this.gridElements),
|
|
@@ -119,13 +103,12 @@ class GridDropEngine {
|
|
|
119
103
|
});
|
|
120
104
|
});
|
|
121
105
|
|
|
122
|
-
this._subscribe('system:
|
|
123
|
-
this._elements = elements;
|
|
106
|
+
this._subscribe('system:requestElementsScale', ({ $elements }) => {
|
|
107
|
+
this._elements = $elements;
|
|
124
108
|
this._elementsUpdate = true;
|
|
125
109
|
});
|
|
126
110
|
|
|
127
111
|
this._subscribe('system:restoredState', ({ stateData }) => {
|
|
128
|
-
this._layoutData = stateData.layoutData;
|
|
129
112
|
this._elements = stateData.elements;
|
|
130
113
|
this._elementsUpdate = true;
|
|
131
114
|
this.setActiveElement(null);
|
|
@@ -137,6 +120,12 @@ class GridDropEngine {
|
|
|
137
120
|
});
|
|
138
121
|
}
|
|
139
122
|
|
|
123
|
+
/** 엔진 초기화 */
|
|
124
|
+
reset() {
|
|
125
|
+
this._initialize();
|
|
126
|
+
console.log('[GridDropEngine] 리셋 완료');
|
|
127
|
+
}
|
|
128
|
+
|
|
140
129
|
/** 삭제 및 정리 */
|
|
141
130
|
destroy() {
|
|
142
131
|
this._subscriptions.forEach((unsubscribe) => {
|
|
@@ -145,7 +134,7 @@ class GridDropEngine {
|
|
|
145
134
|
}
|
|
146
135
|
});
|
|
147
136
|
|
|
148
|
-
this.
|
|
137
|
+
this.reset();
|
|
149
138
|
|
|
150
139
|
this._subscriptions = [];
|
|
151
140
|
this.eventBus = null;
|
|
@@ -203,8 +192,10 @@ class GridDropEngine {
|
|
|
203
192
|
this._startPos = { x: 0, y: 0 };
|
|
204
193
|
this._startSize = { w: 0, h: 0 };
|
|
205
194
|
|
|
206
|
-
this._activeData = null;
|
|
195
|
+
// this._activeData = null;
|
|
207
196
|
this._activeSection = null;
|
|
197
|
+
this._activeMode = null;
|
|
198
|
+
this._activeConfig = null;
|
|
208
199
|
this._activeElement = null;
|
|
209
200
|
|
|
210
201
|
this._elementsUpdate = false;
|
|
@@ -270,7 +261,7 @@ class GridDropEngine {
|
|
|
270
261
|
* @returns {object} - 드래그된 셀 수 ({ dx: , dy: })
|
|
271
262
|
*/
|
|
272
263
|
_calculateDrag(currentPos, cellSize) {
|
|
273
|
-
const { gridGap } = this.
|
|
264
|
+
const { gridGap } = this._activeConfig;
|
|
274
265
|
|
|
275
266
|
const dx = Math.round((currentPos.x - this._startPos.x) / (cellSize.w + gridGap));
|
|
276
267
|
const dy = Math.round((currentPos.y - this._startPos.y) / (cellSize.h + gridGap));
|
|
@@ -283,7 +274,7 @@ class GridDropEngine {
|
|
|
283
274
|
* @returns {number} - 그리드 셀 너비
|
|
284
275
|
*/
|
|
285
276
|
_getGridCellWidth(element) {
|
|
286
|
-
const { gridGap, gridColumns } = this.
|
|
277
|
+
const { gridGap, gridColumns } = this._activeConfig;
|
|
287
278
|
const totalWidth = element.clientWidth - gridGap * (gridColumns - 1);
|
|
288
279
|
return totalWidth / gridColumns;
|
|
289
280
|
}
|
|
@@ -293,7 +284,7 @@ class GridDropEngine {
|
|
|
293
284
|
* @returns {number} - 그리드 셀 높이
|
|
294
285
|
*/
|
|
295
286
|
_getGridCellHeight(element) {
|
|
296
|
-
const { gridGap, gridRows } = this.
|
|
287
|
+
const { gridGap, gridRows } = this._activeConfig;
|
|
297
288
|
const totalHeight = element.clientHeight - gridGap * (gridRows - 1);
|
|
298
289
|
return totalHeight / gridRows;
|
|
299
290
|
}
|
|
@@ -331,11 +322,11 @@ class GridDropEngine {
|
|
|
331
322
|
* @param {string} elName - 추가할 아이템 이름
|
|
332
323
|
*/
|
|
333
324
|
addElement(elName) {
|
|
334
|
-
if (!this.
|
|
325
|
+
if (!this._dragState.activeCell) {
|
|
335
326
|
console.error('[GridDropEngine] 활성화된 데이터가 없습니다.');
|
|
336
327
|
return;
|
|
337
328
|
}
|
|
338
|
-
if (this.
|
|
329
|
+
if (this._activeMode !== 'grid') return;
|
|
339
330
|
|
|
340
331
|
const element = {
|
|
341
332
|
id: elName + '_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 7),
|
|
@@ -507,7 +498,7 @@ class GridDropEngine {
|
|
|
507
498
|
// 리사이징 중인 경우에만 드래그 가능
|
|
508
499
|
if (!this._dragState.isResizing) return;
|
|
509
500
|
|
|
510
|
-
const { gridColumns, gridRows } = this.
|
|
501
|
+
const { gridColumns, gridRows } = this._activeConfig;
|
|
511
502
|
|
|
512
503
|
const activeSection = document.querySelector('.section-active');
|
|
513
504
|
const { dx, dy } = this._calculateDrag(
|