lupine.components 1.0.23 → 1.0.24

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": "lupine.components",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "license": "MIT",
5
5
  "author": "uuware.com",
6
6
  "homepage": "https://github.com/uuware/lupine.js",
@@ -49,7 +49,7 @@ export const DragFresh = (props: DragRefreshProps) => {
49
49
  if (!container || !pullDom || !spinnerDom) return;
50
50
  let touchstartY = 0;
51
51
  let touchstartX = 0;
52
- let direction = '';
52
+ let direction: 'X' | 'Y' | '' = '';
53
53
  let needRefresh = false;
54
54
  const maxHeight = 150;
55
55
  container.addEventListener('touchstart', (e: any) => {
@@ -59,23 +59,23 @@ export const DragFresh = (props: DragRefreshProps) => {
59
59
  needRefresh = false;
60
60
  });
61
61
  container.addEventListener('touchmove', (e: any) => {
62
- console.log(`window.scrollY: ${window.scrollY}`);
63
62
  const touchY = e.touches[0].clientY;
64
63
  const touchX = e.touches[0].clientX;
65
64
  const movedY = touchY - touchstartY;
66
65
  const movedX = touchX - touchstartX;
67
66
  if (direction === '') {
68
- if (movedY > 0) {
67
+ if (Math.abs(movedY) > Math.abs(movedX)) {
69
68
  direction = 'Y';
70
- } else if (movedX > 0) {
69
+ } else {
71
70
  direction = 'X';
72
71
  }
73
72
  }
74
- if (direction === 'X') {
73
+ // console.log(`direction: ${direction}, movedX: ${movedX}, movedY: ${movedY}, container.scrollTop: ${container.scrollTop}`);
74
+ if (direction !== 'Y') {
75
75
  return;
76
76
  }
77
- if (window.scrollY === 0) {
78
- needRefresh = movedY > 30;
77
+ if (container.scrollTop <= 0 && movedY > 5) {
78
+ needRefresh = movedY > 60;
79
79
  if (movedY > 5) {
80
80
  pullDom.classList.add('show');
81
81
  spinnerDom.style.height = `${Math.min(maxHeight, movedY)}px`;
@@ -83,7 +83,7 @@ export const DragFresh = (props: DragRefreshProps) => {
83
83
  pullDom.classList.remove('show');
84
84
  spinnerDom.style.height = '0';
85
85
  }
86
- } else if (window.scrollY > Math.min(maxHeight, movedY)) {
86
+ } else {
87
87
  pullDom.classList.remove('show');
88
88
  spinnerDom.style.height = '0';
89
89
  }
@@ -15,6 +15,7 @@ export type FloatWindowShowProps = {
15
15
  handleClicked: (index: number, close: FloatWindowCloseProps) => void;
16
16
  closeWhenClickOutside?: boolean; // default false
17
17
  zIndex?: string;
18
+ contentOverflowY?: string;
18
19
  };
19
20
 
20
21
  // because it's over a mask, so it can use primary colors
@@ -45,6 +46,7 @@ export class FloatWindow {
45
46
  handleClicked,
46
47
  closeWhenClickOutside = false,
47
48
  zIndex,
49
+ contentOverflowY = 'auto',
48
50
  }: FloatWindowShowProps): Promise<FloatWindowCloseProps> {
49
51
  const onClickContainer = (event: any) => {
50
52
  if (closeWhenClickOutside !== false && event.target.className === 'fwin-box') {
@@ -143,7 +145,7 @@ export class FloatWindow {
143
145
  '.fwin-content': {
144
146
  padding: '15px',
145
147
  maxHeight: contentMaxHeight ? `min(${contentMaxHeight}, calc(100% - 100px))` : 'calc(100% - 100px)',
146
- overflowY: 'auto',
148
+ overflowY: contentOverflowY,
147
149
  },
148
150
  '.fwin-bottom': {
149
151
  display: 'flex',
@@ -1,99 +1,175 @@
1
- import { CssProps, bindGlobalStyles, getRenderPageProps } from 'lupine.web';
1
+ import { CssProps, RefProps, bindGlobalStyles, getRenderPageProps } from 'lupine.web';
2
2
 
3
- let _DEFAULT_PAGE_LIMIT = 7;
3
+ let _DEFAULT_PAGE_LIMIT = 10;
4
4
  export const getDefaultPageLimit = () => {
5
5
  return _DEFAULT_PAGE_LIMIT;
6
6
  };
7
7
  export const setDefaultPageLimit = (limit: number) => {
8
8
  _DEFAULT_PAGE_LIMIT = limit;
9
9
  };
10
+ const pageLinkOptions = [10, 20, 50, 100, 200, 500];
10
11
  export type PagingLinkProps = {
11
12
  itemsCount: number;
12
13
  pageLimit?: number;
13
14
  pageIndex?: number;
14
15
  baseLink: string;
15
16
  onClick?: (index: number) => void; // if onClick is set then use it instead of href
17
+ textPerpage?: string;
18
+ textOk?: string;
19
+ textTo?: string;
20
+ textPage?: string;
21
+ showControl?: boolean;
16
22
  };
17
23
 
18
- export const PagingLink = (props: PagingLinkProps) => {
24
+ export const PagingLink = ({
25
+ itemsCount,
26
+ pageLimit = getDefaultPageLimit(),
27
+ pageIndex = 0,
28
+ baseLink,
29
+ onClick,
30
+ textPerpage = '/Page',
31
+ textOk = 'Go',
32
+ textTo = 'To',
33
+ textPage = 'Page',
34
+ showControl,
35
+ }: PagingLinkProps) => {
19
36
  const css: CssProps = {
37
+ display: 'flex',
38
+ justifyContent: 'end',
39
+ alignItems: 'center',
20
40
  textAlign: 'right',
21
- paddingRight: '16px',
22
- '.paging-link-index': {
23
- padding: '0px 4px',
24
- },
25
- a: {
41
+ padding: '6px 16px 6px 0',
42
+ fontSize: '14px',
43
+ '.paging-link-index a, .paging-link-index.current': {
44
+ padding: '2px 6px',
26
45
  textDecoration: 'none',
27
46
  },
47
+ '.paging-link-index.current': {
48
+ fontWeight: 'bold',
49
+ },
50
+ 'span.paging-link-index a:hover, span.paging-link-go a:hover': {
51
+ textDecoration: 'underline',
52
+ },
53
+ '.paging-link-ctl-box': {
54
+ display: 'flex',
55
+ alignItems: 'center',
56
+ },
57
+ '.paging-link-ctl-box .paging-link-jump': {
58
+ width: '50px',
59
+ padding: '1px 3px',
60
+ margin: '0 3px',
61
+ textAlign: 'right',
62
+ },
63
+ '.paging-link-ctl-box .paging-link-limit': {
64
+ width: '90px',
65
+ padding: '1px 3px',
66
+ margin: '0 3px',
67
+ },
68
+ '.paging-link-ok': {
69
+ margin: '0 3px',
70
+ },
28
71
  };
29
72
 
30
73
  bindGlobalStyles('paging-link-box', '.paging-link-box', css);
31
- const html = [];
32
- let pageIndex = props.pageIndex ?? (Number.parseInt(getRenderPageProps().query['pg_i'] || '') || 0);
33
- const pageLimit = props.pageLimit || _DEFAULT_PAGE_LIMIT;
34
- if (props.itemsCount > 0 && pageLimit > 0) {
35
- let maxPages = Math.floor(props.itemsCount / pageLimit);
36
- if (props.itemsCount % pageLimit !== 0) {
74
+ pageIndex = pageIndex ?? (Number.parseInt(getRenderPageProps().query['pg_i'] || '') || 0);
75
+ pageLimit = pageLimit || _DEFAULT_PAGE_LIMIT;
76
+ let maxPages = Math.floor(itemsCount / pageLimit);
77
+ if (itemsCount > 0 && pageLimit > 0) {
78
+ if (itemsCount % pageLimit !== 0) {
37
79
  maxPages++;
38
80
  }
39
81
  if (pageIndex > maxPages) {
40
82
  pageIndex = maxPages - 1;
41
83
  }
42
- if (pageIndex > 0) {
43
- html.push(
84
+ }
85
+
86
+ const onPageLimitChange = (e: Event) => {
87
+ const limit = Number((e.target as HTMLSelectElement).value || '0');
88
+ if (limit > 0) {
89
+ setDefaultPageLimit(limit);
90
+ onClick && onClick(pageIndex);
91
+ }
92
+ };
93
+
94
+ const onOkClick = () => {
95
+ let index = Number((ref.$('.paging-link-jump') as HTMLInputElement).value || '0');
96
+ if (index < 1) {
97
+ index = 1;
98
+ }
99
+ if (index > maxPages) {
100
+ index = maxPages;
101
+ }
102
+ onClick && onClick(index - 1);
103
+ };
104
+
105
+ const ref: RefProps = {};
106
+ return (
107
+ <div ref={ref} class='paging-link-box'>
108
+ {pageIndex > 0 ? (
44
109
  <span class='paging-link-go'>
45
110
  <a
46
- href={props.onClick ? 'javascript:void(0)' : props.baseLink + '?pg_i=' + (pageIndex - 1)}
47
- onClick={() => props.onClick && props.onClick(pageIndex - 1)}
111
+ href={onClick ? 'javascript:void(0)' : baseLink + '?pg_i=' + (pageIndex - 1)}
112
+ onClick={() => onClick && onClick(pageIndex - 1)}
48
113
  >
49
114
  &lt;
50
115
  </a>
51
116
  </span>
52
- );
53
- } else {
54
- html.push(<span class='paging-link-go disabled'>&lt;</span>);
55
- }
56
- for (let i = 0; i < maxPages; i++) {
57
- if (i < 2 || i >= maxPages - 2 || (i > pageIndex - 3 && i < pageIndex + 3)) {
58
- if (i == pageIndex) {
59
- html.push(
60
- <span class='paging-link-index current'>
61
- <b>{'' + (i + 1)}</b>
62
- </span>
63
- );
64
- } else {
65
- html.push(
66
- <span class='paging-link-index'>
67
- <a
68
- href={props.onClick ? 'javascript:void(0)' : props.baseLink + '?pg_i=' + i}
69
- onClick={() => props.onClick && props.onClick(i)}
70
- >
71
- {'' + (i + 1)}
72
- </a>
73
- </span>
74
- );
75
- }
76
- } else {
77
- if (i == pageIndex - 4 || i == pageIndex + 4) {
78
- html.push(<span class='paging-link-skip'>...</span>);
79
- }
80
- }
81
- }
82
- if (pageIndex < maxPages - 1) {
83
- html.push(
117
+ ) : (
118
+ <span class='paging-link-go disabled'>&lt;</span>
119
+ )}
120
+
121
+ {Array.from({ length: maxPages }, (_, i) => i).map((i) => (
122
+ <>
123
+ {i < 2 || i >= maxPages - 2 || (i > pageIndex - 3 && i < pageIndex + 3) ? (
124
+ i == pageIndex ? (
125
+ <span class='paging-link-index current'>{i + 1}</span>
126
+ ) : (
127
+ <span class='paging-link-index'>
128
+ <a
129
+ href={onClick ? 'javascript:void(0)' : baseLink + '?pg_i=' + i}
130
+ onClick={() => onClick && onClick(i)}
131
+ >
132
+ {i + 1}
133
+ </a>
134
+ </span>
135
+ )
136
+ ) : (
137
+ (i == pageIndex - 4 || i == pageIndex + 4) && <span class='paging-link-skip'>...</span>
138
+ )}
139
+ </>
140
+ ))}
141
+
142
+ {pageIndex < maxPages - 1 ? (
84
143
  <span class='paging-link-go'>
85
144
  <a
86
- href={props.onClick ? 'javascript:void(0)' : props.baseLink + '?pg_i=' + (pageIndex + 1)}
87
- onClick={() => props.onClick && props.onClick(pageIndex + 1)}
145
+ href={onClick ? 'javascript:void(0)' : baseLink + '?pg_i=' + (pageIndex + 1)}
146
+ onClick={() => onClick && onClick(pageIndex + 1)}
88
147
  >
89
148
  &gt;
90
149
  </a>
91
150
  </span>
92
- );
93
- } else {
94
- html.push(<span class='paging-link-go disabled'>&gt;</span>);
95
- }
96
- }
97
-
98
- return html.length > 0 ? <div class='paging-link-box'>{html}</div> : <></>;
151
+ ) : (
152
+ <span class='paging-link-go disabled'>&gt;</span>
153
+ )}
154
+ {showControl && (
155
+ <div class='paging-link-ctl-box'>
156
+ {textTo}
157
+ <input class='input-base paging-link-jump input-s' type='number' value={pageIndex + 1} /> / {maxPages}{' '}
158
+ {textPage}
159
+ <button class='button-base button-s paging-link-ok' onClick={onOkClick}>
160
+ {textOk}
161
+ </button>
162
+ <select class='input-base paging-link-limit input-s' onChange={onPageLimitChange}>
163
+ <option value=''> - </option>
164
+ {pageLinkOptions.map((page) => (
165
+ <option value={page}>
166
+ {page}
167
+ {textPerpage}
168
+ </option>
169
+ ))}
170
+ </select>
171
+ </div>
172
+ )}
173
+ </div>
174
+ );
99
175
  };
@@ -57,7 +57,7 @@ export const ResponsiveFrame = async (props: ResponsiveFrameProps) => {
57
57
  padding: '0 16px',
58
58
  },
59
59
  [MediaQueryRange.TabletBelow]: {
60
- '.frame-footer .footer-box, .frame-top-menu .desktop-menu-box': {
60
+ '.frame-footer .d-footer-box, .frame-top-menu .desktop-menu-box': {
61
61
  display: 'none',
62
62
  },
63
63
  },