@stonecrop/atable 0.3.9 → 0.3.11

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.
@@ -73,25 +73,25 @@ export declare const createTableStore: (initData: {
73
73
  rowModified?: boolean | undefined;
74
74
  }[]>;
75
75
  modal: import("vue").Ref<{
76
+ bottom?: number | undefined;
76
77
  colIndex?: number | undefined;
77
78
  event?: string | undefined;
78
79
  height?: number | undefined;
79
80
  left?: number | undefined;
80
81
  parent?: HTMLElement | undefined;
81
82
  rowIndex?: number | undefined;
82
- top?: number | undefined;
83
83
  visible?: boolean | undefined;
84
84
  width?: number | undefined;
85
85
  component?: string | undefined;
86
86
  componentProps?: Record<string, any> | undefined;
87
87
  }, TableModal | {
88
+ bottom?: number | undefined;
88
89
  colIndex?: number | undefined;
89
90
  event?: string | undefined;
90
91
  height?: number | undefined;
91
92
  left?: number | undefined;
92
93
  parent?: HTMLElement | undefined;
93
94
  rowIndex?: number | undefined;
94
- top?: number | undefined;
95
95
  visible?: boolean | undefined;
96
96
  width?: number | undefined;
97
97
  component?: string | undefined;
@@ -179,25 +179,25 @@ export declare const createTableStore: (initData: {
179
179
  rowModified?: boolean | undefined;
180
180
  }[]>;
181
181
  modal: import("vue").Ref<{
182
+ bottom?: number | undefined;
182
183
  colIndex?: number | undefined;
183
184
  event?: string | undefined;
184
185
  height?: number | undefined;
185
186
  left?: number | undefined;
186
187
  parent?: HTMLElement | undefined;
187
188
  rowIndex?: number | undefined;
188
- top?: number | undefined;
189
189
  visible?: boolean | undefined;
190
190
  width?: number | undefined;
191
191
  component?: string | undefined;
192
192
  componentProps?: Record<string, any> | undefined;
193
193
  }, TableModal | {
194
+ bottom?: number | undefined;
194
195
  colIndex?: number | undefined;
195
196
  event?: string | undefined;
196
197
  height?: number | undefined;
197
198
  left?: number | undefined;
198
199
  parent?: HTMLElement | undefined;
199
200
  rowIndex?: number | undefined;
200
- top?: number | undefined;
201
201
  visible?: boolean | undefined;
202
202
  width?: number | undefined;
203
203
  component?: string | undefined;
@@ -285,25 +285,25 @@ export declare const createTableStore: (initData: {
285
285
  rowModified?: boolean | undefined;
286
286
  }[]>;
287
287
  modal: import("vue").Ref<{
288
+ bottom?: number | undefined;
288
289
  colIndex?: number | undefined;
289
290
  event?: string | undefined;
290
291
  height?: number | undefined;
291
292
  left?: number | undefined;
292
293
  parent?: HTMLElement | undefined;
293
294
  rowIndex?: number | undefined;
294
- top?: number | undefined;
295
295
  visible?: boolean | undefined;
296
296
  width?: number | undefined;
297
297
  component?: string | undefined;
298
298
  componentProps?: Record<string, any> | undefined;
299
299
  }, TableModal | {
300
+ bottom?: number | undefined;
300
301
  colIndex?: number | undefined;
301
302
  event?: string | undefined;
302
303
  height?: number | undefined;
303
304
  left?: number | undefined;
304
305
  parent?: HTMLElement | undefined;
305
306
  rowIndex?: number | undefined;
306
- top?: number | undefined;
307
307
  visible?: boolean | undefined;
308
308
  width?: number | undefined;
309
309
  component?: string | undefined;
@@ -1,3 +1,4 @@
1
+ import { useElementBounding } from '@vueuse/core';
1
2
  import { createTableStore } from '../stores/table';
2
3
  /**
3
4
  * Table column definition.
@@ -86,20 +87,20 @@ export type TableRow = {
86
87
  * @public
87
88
  */
88
89
  export type TableModal = {
90
+ bottom?: ReturnType<typeof useElementBounding>['bottom'];
89
91
  colIndex?: number;
90
92
  event?: string;
91
- height?: number;
92
- left?: number;
93
+ height?: ReturnType<typeof useElementBounding>['height'];
94
+ left?: ReturnType<typeof useElementBounding>['left'];
93
95
  parent?: HTMLElement;
94
96
  rowIndex?: number;
95
- top?: number;
96
97
  visible?: boolean;
97
- width?: number;
98
+ width?: ReturnType<typeof useElementBounding>['width'];
98
99
  component?: string;
99
100
  componentProps?: Record<string, any>;
100
101
  };
101
102
  /**
102
- * Table modal props definition.
103
+ * Table modal component props definition.
103
104
  * @public
104
105
  */
105
106
  export type TableModalProps = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../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AAC,CAAA;CACpC,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAA;CAC1C,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/atable",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": {
@@ -38,8 +38,8 @@
38
38
  "@vueuse/core": "^12.0.0",
39
39
  "pinia": "^2.3.0",
40
40
  "vue": "^3.5.11",
41
- "@stonecrop/themes": "0.3.9",
42
- "@stonecrop/utilities": "0.3.9"
41
+ "@stonecrop/themes": "0.3.11",
42
+ "@stonecrop/utilities": "0.3.11"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@microsoft/api-documenter": "^7.26.2",
@@ -50,7 +50,6 @@ const {
50
50
  const emit = defineEmits<{ cellInput: [colIndex: number, rowIndex: number, newValue: string, oldValue: string] }>()
51
51
 
52
52
  const cellRef = useTemplateRef<HTMLTableCellElement>('cell')
53
- const { width, height } = useElementBounding(cellRef)
54
53
 
55
54
  // keep a shallow copy of the original cell value for comparison
56
55
  const originalData = store.getCellData(colIndex, rowIndex)
@@ -80,6 +79,8 @@ const cellStyle = computed((): CSSProperties => {
80
79
  })
81
80
 
82
81
  const showModal = () => {
82
+ const { left, bottom, width, height } = useElementBounding(cellRef)
83
+
83
84
  if (column.mask) {
84
85
  // TODO: add masking to cell values
85
86
  // column.mask(event)
@@ -90,11 +91,11 @@ const showModal = () => {
90
91
  state.modal.visible = true
91
92
  state.modal.colIndex = colIndex
92
93
  state.modal.rowIndex = rowIndex
93
- state.modal.parent = cellRef.value!
94
- state.modal.top = cellRef.value!.offsetTop + cellRef.value!.offsetHeight
95
- state.modal.left = cellRef.value!.offsetLeft
96
- state.modal.width = width.value
97
- state.modal.height = height.value
94
+ // TODO: typing refs somehow resolves to unref'd value; probably a bug in API Extractor?
95
+ state.modal.left = left
96
+ state.modal.bottom = bottom
97
+ state.modal.width = width
98
+ state.modal.height = height
98
99
 
99
100
  if (typeof column.modalComponent === 'function') {
100
101
  state.modal.component = column.modalComponent({ table: state.table, row, column })
@@ -33,12 +33,7 @@
33
33
 
34
34
  <slot name="footer" :data="store" />
35
35
  <slot name="modal" :data="store">
36
- <ATableModal
37
- v-show="store.modal.visible"
38
- :colIndex="store.modal.colIndex"
39
- :rowIndex="store.modal.rowIndex"
40
- :store="store"
41
- :container="tableRef">
36
+ <ATableModal v-show="store.modal.visible" :store="store">
42
37
  <template #default>
43
38
  <component
44
39
  :key="`${store.modal.rowIndex}:${store.modal.colIndex}`"
@@ -126,8 +121,8 @@ const assignStickyCellWidths = () => {
126
121
  const table = tableRef.value
127
122
 
128
123
  // set header cell width to match sticky cells' width
129
- const headerRow = table.rows[0]
130
- const firstDataRow = table.rows[1]
124
+ const headerRow = table?.rows[0]
125
+ const firstDataRow = table?.rows[1]
131
126
  const headerCells = headerRow ? Array.from(headerRow.cells) : []
132
127
  for (const [index, headerCell] of headerCells.entries()) {
133
128
  const rowCell = firstDataRow?.cells[index]
@@ -137,7 +132,7 @@ const assignStickyCellWidths = () => {
137
132
  }
138
133
 
139
134
  // pin cells in row that are sticky
140
- for (const row of table.rows) {
135
+ for (const row of table?.rows || []) {
141
136
  let totalWidth = 0
142
137
  const columns: HTMLTableCellElement[] = []
143
138
 
@@ -5,43 +5,43 @@
5
5
  </template>
6
6
 
7
7
  <script setup lang="ts">
8
- import { useElementBounding } from '@vueuse/core'
8
+ import { useElementBounding, useWindowScroll } from '@vueuse/core'
9
9
  import { useTemplateRef, computed } from 'vue'
10
10
 
11
11
  import { createTableStore } from '../stores/table'
12
12
 
13
- const { store, container } = defineProps<{
14
- colIndex?: number
15
- rowIndex?: number
16
- store?: ReturnType<typeof createTableStore>
17
- container?: HTMLElement
18
- }>()
13
+ const { store } = defineProps<{ store: ReturnType<typeof createTableStore> }>()
19
14
 
20
15
  const amodalRef = useTemplateRef('amodal')
21
16
  const { width, height } = useElementBounding(amodalRef)
17
+ const { y: scrollY } = useWindowScroll()
22
18
 
23
19
  const amodalStyles = computed(() => {
24
- // the modal usually will appear left align with and below the element it is associated with,
25
- // but needs to detect and adjust its position if it would overflow the rightr or bottom edges
20
+ if (!(store.modal.height && store.modal.width && store.modal.left && store.modal.bottom)) return
26
21
 
27
- // get the dimensions of whatever container is holding this modal, e.g. Table, Window, div so the modal can detect edges
28
- const containerWidth = container?.offsetWidth || 0
29
- const containerHeight = container?.offsetHeight || 0
22
+ const body = document.body
23
+ const html = document.documentElement
30
24
 
31
- // if this modal would go outside the edge of its container, instead place it above the element (Y) or along the right side (X)
32
- const modalLeft =
33
- store.modal.left + width.value > containerWidth
34
- ? store.modal.left - (width.value - store.modal.width)
35
- : store.modal.left
25
+ const maxHeight = Math.max(
26
+ body.scrollHeight,
27
+ body.offsetHeight,
28
+ html.clientHeight,
29
+ html.scrollHeight,
30
+ html.offsetHeight
31
+ )
32
+ const maxWidth = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth)
36
33
 
37
- const modalTop =
38
- store.modal.top + height.value > containerHeight
39
- ? store.modal.top - height.value - store.modal.height
40
- : store.modal.top
34
+ const modalY =
35
+ store.modal.bottom + height.value + scrollY.value <= maxHeight
36
+ ? store.modal.bottom
37
+ : store.modal.bottom - height.value - store.modal.height
38
+
39
+ const modalX =
40
+ store.modal.left + width.value <= maxWidth ? store.modal.left : store.modal.left - (width.value - store.modal.width)
41
41
 
42
42
  return {
43
- left: `${modalLeft}px`,
44
- top: `${modalTop}px`,
43
+ left: `${modalX}px`,
44
+ top: `${modalY}px`,
45
45
  }
46
46
  })
47
47
 
@@ -54,8 +54,8 @@ const handleInput = (event: Event) => {
54
54
  @import url('@stonecrop/themes/default.css');
55
55
 
56
56
  .amodal {
57
- position: absolute;
57
+ position: fixed;
58
58
  background-color: var(--sc-row-color-zebra-dark);
59
- z-index: 100;
59
+ z-index: 1000;
60
60
  }
61
61
  </style>
@@ -1,3 +1,5 @@
1
+ import { useElementBounding } from '@vueuse/core'
2
+
1
3
  import { createTableStore } from '../stores/table'
2
4
 
3
5
  /**
@@ -93,22 +95,22 @@ export type TableRow = {
93
95
  * @public
94
96
  */
95
97
  export type TableModal = {
98
+ bottom?: ReturnType<typeof useElementBounding>['bottom']
96
99
  colIndex?: number
97
100
  event?: string
98
- height?: number
99
- left?: number
101
+ height?: ReturnType<typeof useElementBounding>['height']
102
+ left?: ReturnType<typeof useElementBounding>['left']
100
103
  parent?: HTMLElement
101
104
  rowIndex?: number
102
- top?: number
103
105
  visible?: boolean
104
- width?: number
106
+ width?: ReturnType<typeof useElementBounding>['width']
105
107
 
106
108
  component?: string
107
109
  componentProps?: Record<string, any>
108
110
  }
109
111
 
110
112
  /**
111
- * Table modal props definition.
113
+ * Table modal component props definition.
112
114
  * @public
113
115
  */
114
116
  export type TableModalProps = {