polarvo-layout 1.0.29 → 1.0.31

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.29",
3
+ "version": "1.0.31",
4
4
  "type": "module",
5
5
  "author": "unigence <unigencelab@gmail.com>",
6
6
  "repository": {
@@ -7,9 +7,10 @@
7
7
  @mousedown.stop="activeEditMode ? null : handleMouseDown($event, item.id)"
8
8
  >
9
9
  <!-- 크기-->
10
- <div v-if="item.id === activeId" class="absolute bg-blue-400 px-2 py-1 text-sm text-white right-0 z-10 ">
11
- 가로: {{ size.w }} 세로: {{ size.h }}</div>
12
-
10
+ <div v-if="item.id === activeId" class="absolute bg-blue-400 px-2 py-1 text-sm text-white right-0 z-10">
11
+ 가로: {{ Math.round(size.w) }} 세로: {{ Math.round(size.h) }}
12
+ </div>
13
+
13
14
  <!-- 리사이즈 핸들 -->
14
15
  <div v-if="item.id === activeId" class="absolute inset-0 pointer-events-none">
15
16
  <div
@@ -61,7 +62,7 @@ const props = defineProps({
61
62
 
62
63
  const { activeId, handles, activeElement } = toRefs(props.polarvo.freeDrop.state);
63
64
  const { getElementStyle, handleMouseDown, startResize, toggleLock } = props.polarvo.freeDrop;
64
- const size = computed(() => activeElement.value ? activeElement.value.size : { w: 0, h: 0 });
65
+ const size = computed(() => (activeElement.value ? activeElement.value.size : { w: 0, h: 0 }));
65
66
 
66
67
  const activeEditMode = inject('activeEditMode');
67
68
  function toggleEditMode() {
@@ -4,7 +4,7 @@
4
4
  v-for="(item, index) in allElements"
5
5
  :key="index"
6
6
  class="flex flex-col items-center justify-center border border-gray-200 rounded-lg p-2 hover:bg-gray-50 transition-colors cursor-pointer active:scale-95"
7
- @mousedown.stop="sectionMode == 'free' ? addElementToFree($event, item.elName) : addElementToGrid(item.elName)"
7
+ @mousedown.stop="sectionMode == 'free' ? addElementToFree($event, item) : addElementToGrid(item)"
8
8
  >
9
9
  <img :src="item.imgurl" alt="" class="w-24 h-auto rounded" />
10
10
  <h4 class="text-sm">{{ item.elName }}</h4>
@@ -36,9 +36,21 @@ const allElements = ref([]);
36
36
 
37
37
  /** 프로젝트 폴더에서 요소 컴포넌트 주소를 맞춰줘야 정상 작동합니다.
38
38
  * (현재 /src/components/elements/ 내부에 모든 요소 컴포넌트가 있어야 함) */
39
- const modules = import.meta.glob('@/components/elements/*.vue');
39
+ const modules = import.meta.glob('@/components/elements/*.vue', { eager: true });
40
40
  const imageModules = import.meta.glob('@/assets/el_img/*.{png,gif}', { eager: true });
41
41
 
42
+ function getPropsDefaults(props) {
43
+ if (!props) return {};
44
+ return Object.fromEntries(
45
+ Object.entries(props).map(([key, prop]) => {
46
+ if (prop.default !== undefined) {
47
+ return [key, typeof prop.default === 'function' ? prop.default() : prop.default];
48
+ }
49
+ return [key, null];
50
+ })
51
+ );
52
+ }
53
+
42
54
  async function getElements() {
43
55
  // 특정 컴포넌트는 제외
44
56
  const excludedElements = [
@@ -59,6 +71,7 @@ async function getElements() {
59
71
  })
60
72
  .map((path) => {
61
73
  const elName = path.split('/').pop().replace('.vue', '');
74
+ const propDefaults = getPropsDefaults(modules[path].default?.props);
62
75
 
63
76
  // 확장자 조건 설정
64
77
  const ext = elName === 'dataList' ? 'gif' : 'png';
@@ -66,6 +79,7 @@ async function getElements() {
66
79
 
67
80
  let result = {
68
81
  elName,
82
+ propDefaults: propDefaults,
69
83
  // imgurl: new URL(`../../assets/el_img/${elName}.${ext}`, props.urlBase),
70
84
  imgurl: imageModules[imgKey]?.default ?? '',
71
85
  // component: markRaw(defineAsyncComponent(modules[path]))
@@ -362,10 +362,11 @@ class FreeDropEngine {
362
362
  /** ---------------------------------- 배치요소 관련 메소드 ---------------------------------- **/
363
363
  /** 배치요소 신규 추가 - 메뉴에서 추가 아이템 선택
364
364
  * @param {MouseEvent} event - 마우스 이벤트
365
- * @param {string} elName - 추가할 아이템 이름
365
+ * @param {object} item - 추가할 아이템 정보
366
366
  */
367
- addElement(event, elName) {
367
+ addElement(event, item) {
368
368
  if (this._activeMode !== 'free') return;
369
+ const elName = item.elName;
369
370
 
370
371
  this._startPos = { x: event.clientX, y: event.clientY };
371
372
 
@@ -378,6 +379,7 @@ class FreeDropEngine {
378
379
  size: elementSource[elName] || { w: 100, h: 100 },
379
380
  section: this._activeSection,
380
381
  isLocked: false,
382
+ propDefaults: item.propDefaults || {}, // 아이템의 기본 props 설정
381
383
  };
382
384
 
383
385
  this.setActiveElement(element, 'add');
@@ -334,15 +334,17 @@ class GridDropEngine {
334
334
 
335
335
  /** ---------------------------------- 배치요소 관련 메소드 ---------------------------------- **/
336
336
  /** 배치요소 신규 추가 - 메뉴에서 추가 아이템 선택
337
- * @param {string} elName - 추가할 아이템 이름
337
+ * @param {object} item - 추가할 아이템 정보
338
338
  */
339
- addElement(elName) {
339
+ addElement(item) {
340
340
  if (!this._dragState.activeCell) {
341
341
  console.error('[GridDropEngine] 활성화된 데이터가 없습니다.');
342
342
  return;
343
343
  }
344
344
  if (this._activeMode !== 'grid') return;
345
345
 
346
+ const elName = item.elName;
347
+
346
348
  const element = {
347
349
  id: elName + '_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 7),
348
350
  type: elName,
@@ -351,6 +353,7 @@ class GridDropEngine {
351
353
  size: { colSpan: 1, rowSpan: 1 },
352
354
  section: this._activeSection,
353
355
  isLocked: false,
356
+ propDefaults: item.propDefaults || {}, // 아이템의 기본 props 설정
354
357
  };
355
358
 
356
359
  this.setActiveElement(null, 'add');