polarvo-layout 1.0.35 → 1.0.37

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.35",
3
+ "version": "1.0.37",
4
4
  "type": "module",
5
5
  "author": "unigence <unigencelab@gmail.com>",
6
6
  "repository": {
@@ -7,7 +7,7 @@
7
7
  :polarvo="props.polarvo"
8
8
  :sectionKey="props.sectionKey"
9
9
  ></FreeItem>
10
-
10
+
11
11
  <!-- 오버레이 -->
12
12
  <div v-if="activeEditMode" class="absolute inset-0 bg-black opacity-50"></div>
13
13
 
@@ -68,7 +68,8 @@ const selectedElement = inject('selectedElement');
68
68
  const activeEditMode = inject('activeEditMode');
69
69
 
70
70
  let _isElementSwitching = false;
71
- import { omit, cloneDeep } from 'lodash-es';
71
+ import { omit, cloneDeep, debounce } from 'lodash-es';
72
+
72
73
  watch(
73
74
  () => activeElement.value?.id,
74
75
  (newId, oldId) => {
@@ -83,7 +84,6 @@ watch(
83
84
 
84
85
  // activeElement 바뀌면 편집 모드 해제
85
86
  activeEditMode.value = false;
86
-
87
87
  },
88
88
  );
89
89
 
@@ -68,15 +68,22 @@ const filteredElements = computed(() => {
68
68
  watch(
69
69
  () => filteredElements.value,
70
70
  () => {
71
- debouncedUpdate();
71
+ debouncedUpdateMergedData();
72
72
  },
73
73
  { deep: true },
74
74
  );
75
- const debouncedUpdate = debounce(() => {
75
+ const debouncedUpdateMergedData = debounce(() => {
76
76
  setMergedData();
77
77
  // gridRows 업데이트
78
78
  }, 10);
79
79
 
80
+ watch(
81
+ () => `${props.sectionData?.config?.gridColumns}-${props.sectionData?.config?.gridRows}`,
82
+ () => {
83
+ initData();
84
+ },
85
+ );
86
+
80
87
  function setMergedData() {
81
88
  const grid = Array.from({ length: gridRows.value + 1 }, () => Array(gridColumns.value + 1).fill(false));
82
89
  // const filled = elements.value.filter((el) => props.elementIds?.includes(el.id) && el.section === props.sectionKey);
@@ -125,7 +132,7 @@ watch(
125
132
  _isElementSwitching = false;
126
133
  return;
127
134
  }
128
- updateActiveElement(selectedElement.value?.id, newElement);
135
+ updateActiveElement(selectedElement.value?.id, newElement);
129
136
  },
130
137
  { deep: true },
131
138
  );
@@ -11,6 +11,7 @@ const props = defineProps({
11
11
  default: 'free',
12
12
  },
13
13
  });
14
+
14
15
  </script>
15
16
 
16
17
  <style scoped>
@@ -129,7 +129,7 @@ class FreeDropEngine {
129
129
  });
130
130
 
131
131
  this._subscribe('system:restoredState', ({ domain, state: snapShot }) => {
132
- if (domain === 'all') {
132
+ if (domain === 'all' || domain === 'draft') {
133
133
  this._elements = snapShot.manager.elements || [];
134
134
  this._elementsUpdate = true;
135
135
  this.setActiveElement(null);
@@ -427,7 +427,6 @@ class FreeDropEngine {
427
427
  this._activeElement = element;
428
428
  this._alreadyExist = action === 'add' ? false : true;
429
429
  // this._elementsUpdate = true;
430
- console.log('setActiveElement', this._activeElement?.id, this.freeElements)
431
430
 
432
431
  this.eventBus.emit('freeDrop:setActiveElement', {
433
432
  $alreadyExist: this._alreadyExist,
@@ -109,7 +109,7 @@ class GridDropEngine {
109
109
  });
110
110
 
111
111
  this._subscribe('system:restoredState', ({ domain, state: snapShot }) => {
112
- if (domain === 'all') {
112
+ if (domain === 'all'|| domain === 'draft') {
113
113
  this._elements = snapShot.manager.elements || [];
114
114
  this._elementsUpdate = true;
115
115
 
@@ -38,6 +38,9 @@ class EngineManager {
38
38
 
39
39
  this._subscriptions = [];
40
40
  this._initialized = false;
41
+
42
+ this._beforeUnloadHandler = () => this.saveSession();
43
+ window.addEventListener('beforeunload', this._beforeUnloadHandler);
41
44
  }
42
45
 
43
46
  /** activeSection 데이터 반환
@@ -72,6 +75,22 @@ class EngineManager {
72
75
 
73
76
  restoreState(domain, state) {
74
77
  switch (domain) {
78
+ case 'draft': {
79
+ // manager
80
+ this.setState(state.manager);
81
+
82
+ // layout
83
+ this.getEngine('layout').setState(state.layout);
84
+ this.state.layoutData = state.layout.layoutData;
85
+
86
+ // display
87
+ this.getEngine('display')?.setState(state.display);
88
+ this._displaySize = state.display.displaySize;
89
+
90
+ this.setActiveSection(state.manager?.activeSection, true);
91
+ break;
92
+ }
93
+
75
94
  // all
76
95
  case 'all': {
77
96
  // manager
@@ -124,6 +143,15 @@ class EngineManager {
124
143
  this.eventBus.emit('system:restoredState', { domain, state });
125
144
  }
126
145
 
146
+ saveSession() {
147
+ const snapshot = {
148
+ manager: this.getState(),
149
+ layout: this.getEngine('layout')?.getState() || null,
150
+ display: this.getEngine('display')?.getState() || null,
151
+ };
152
+ sessionStorage.setItem('polarvo-session', JSON.stringify(snapshot));
153
+ }
154
+
127
155
  /** [내부함수] activeSection의 설정값 업데이트
128
156
  * @param {string} type - 설정 타입 (mode, config)
129
157
  * @param {object} updates - 업데이트할 설정 값 객체
@@ -625,6 +653,21 @@ class EngineManager {
625
653
  await this._createEngines();
626
654
  await this._setupEngineConnections();
627
655
  this._initialized = true;
656
+
657
+ // 세션 복원
658
+ const saved = sessionStorage.getItem('polarvo-session');
659
+ if (saved) {
660
+ this.restoreState('draft', JSON.parse(saved));
661
+
662
+ this.eventBus.emit('system:historyCheckpoint', {
663
+ domain: 'draft',
664
+ state: {
665
+ manager: this.getState() || null,
666
+ layout: this.getEngine('layout')?.getState() || null,
667
+ display: this.getEngine('display')?.getState() || null,
668
+ },
669
+ });
670
+ }
628
671
  }
629
672
  }
630
673
 
@@ -701,6 +744,11 @@ class EngineManager {
701
744
  }
702
745
  });
703
746
 
747
+ // 가장 최신 상태를 세션 스토리지에 저장 (새로고침 대비)
748
+ this.eventBus.subscribe('system:historyCheckpoint', () => {
749
+ this.saveSession();
750
+ });
751
+
704
752
  // 모든 연결 설정 완료 후 초기화 완료 이벤트 발행
705
753
  this.eventBus.emit('system:engineInitialized', {
706
754
  state: this.state,
@@ -773,6 +821,8 @@ class EngineManager {
773
821
  destroy() {
774
822
  console.log('[EngineManager] 엔진 매니저 삭제 시작');
775
823
 
824
+ window.removeEventListener('beforeunload', this._beforeUnloadHandler);
825
+
776
826
  // 모든 구독 해제
777
827
  this._subscriptions.forEach((unsubscribe) => {
778
828
  if (typeof unsubscribe === 'function') {
@@ -61,7 +61,7 @@ function useDisplay(api) {
61
61
  });
62
62
 
63
63
  _subscribe('system:restoredState', ({ domain, state: snapShot }) => {
64
- if (domain === 'all') {
64
+ if (domain === 'all'|| domain === 'draft') {
65
65
  state.displayMode = snapShot.display.displayMode;
66
66
  state.displaySize = { ...snapShot.display.displaySize };
67
67
  }
@@ -117,7 +117,7 @@ function useLayout(api) {
117
117
  });
118
118
 
119
119
  _subscribe('system:restoredState', ({ domain, state: snapShot }) => {
120
- if (domain === 'all') {
120
+ if (domain === 'all'|| domain === 'draft') {
121
121
  state.elements = snapShot.manager.elements;
122
122
  // state.layoutData = snapShot.manager.layoutData
123
123