aprog 1.9.1 → 1.9.3

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/index.js CHANGED
@@ -12,7 +12,7 @@ export { encrypt, decrypt } from './src/shifrator.js';
12
12
  export { gemini } from './src/OpenAI.js';
13
13
  export { mathInput, autoPPI } from './src/math.js';
14
14
  export { cookie, storage, cacheKey, downloadFile } from './src/storage.js';
15
- export { paginate, parseData } from './src/paginate.js';
15
+ export { paginate, parseData, __paginate, __counter } from './src/paginate.js';
16
16
  export { saveItem, loadItem, setSecretKey } from './src/secretStorage.js';
17
17
  export {
18
18
  pushHTMLElementPrototype, pushAfterHTMLElementPrototype,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aprog",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "Допоміжна бібліотека js",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/paginate.js CHANGED
@@ -1,5 +1,5 @@
1
- import {storage} from "./storage.js";
2
- import {button, div} from "./aprog.js";
1
+ import {cookie, storage} from "./storage.js";
2
+ import {button, div, GUID} from "./aprog.js";
3
3
 
4
4
  export const paginate = ({ count = 0, currentPage = 1, onPageChange = () => {}, colors = {}, customStyles = {} } = {}) => {
5
5
  const defaultColors = {
@@ -169,3 +169,215 @@ export const parseData = (data, page) => {
169
169
 
170
170
  return [pages, cutData, page, totalData];
171
171
  };
172
+
173
+ export const __paginate = ({
174
+ lastPage = 1,
175
+ currentPage = 1,
176
+ onPageChange = () => {},
177
+ customStyles = {}
178
+ } = {}) => {
179
+ const defaultStyles = {
180
+ position: "relative",
181
+ width: "100vw",
182
+ margin: "20px 0",
183
+ padding: "0 20px",
184
+ display: "flex",
185
+ alignItems: "center",
186
+ justifyContent: "center",
187
+ gap: "5px",
188
+ color: "#043458",
189
+ backgroundColor: "#ffffff",
190
+ boxShadow: "0 3px 6px 0 rgba(115,73,118, 0.4), 0 3px 6px 0 rgba(115,73,118, 0.39)",
191
+ borderRadius: "0.5rem",
192
+ fontSize: "16px",
193
+ border: "0.0313rem solid #043458",
194
+ };
195
+
196
+ const theme = { ...defaultStyles, ...customStyles };
197
+
198
+ const styles = `
199
+ <style>
200
+ .paginate-block {
201
+ position: ${theme.position};
202
+ width: ${theme.width};
203
+ margin: ${theme.margin};
204
+ padding: ${theme.padding};
205
+ display: ${theme.display};
206
+ align-items: ${theme.alignItems};
207
+ justify-content: ${theme.justifyContent};
208
+ gap: ${theme.gap};
209
+ }
210
+ .paginate-btn,
211
+ .paginate-dots,
212
+ .paginate-prev,
213
+ .paginate-next {
214
+ padding: 10px 20px;
215
+ font-size: ${theme.fontSize};
216
+ font-weight: 600;
217
+ color: ${theme.color};
218
+ background: ${theme.backgroundColor};
219
+ border: ${theme.border};
220
+ border-radius: ${theme.borderRadius};
221
+ cursor: pointer;
222
+ box-shadow: ${theme.boxShadow};
223
+ }
224
+ .paginate-prev,
225
+ .paginate-next {
226
+ font-family: Roboto, serif;
227
+ font-weight: 700;
228
+ }
229
+ .paginate-btn.active {
230
+ background: ${theme.color};
231
+ color: ${theme.backgroundColor};
232
+ }
233
+ .paginate-btn:disabled,
234
+ .paginate-dots:disabled,
235
+ .paginate-prev:disabled,
236
+ .paginate-next:disabled {
237
+ cursor: not-allowed;
238
+ opacity: 0.5;
239
+ }
240
+
241
+ /** Counter */
242
+ .counter {
243
+ width: 100%;
244
+ margin: 20px 0;
245
+ padding: 0 20px;
246
+ display: flex;
247
+ align-items: center;
248
+ justify-content: start;
249
+ gap: 20px;
250
+ }
251
+ .counter span {
252
+ padding: 8px 16px;
253
+ border-radius: ${theme.borderRadius};
254
+ box-shadow: ${theme.boxShadow};
255
+ cursor: pointer;
256
+ }
257
+ .counter span.active {
258
+ color: ${theme.backgroundColor};
259
+ background-color: ${theme.color};
260
+ }
261
+ </style>
262
+ `;
263
+
264
+ const generatePageButtons = () => {
265
+ const buttons = [];
266
+ if (lastPage <= 5) {
267
+ for (let i = 1; i <= lastPage; i++) {
268
+ buttons.push(createPageButton(i));
269
+ }
270
+ } else {
271
+ buttons.push(createPageButton(1));
272
+ if (currentPage > 3) {
273
+ buttons.push(createDotsButton());
274
+ }
275
+ for (
276
+ let i = Math.max(2, currentPage - 1);
277
+ i <= Math.min(lastPage - 1, currentPage + 1);
278
+ i++
279
+ ) {
280
+ buttons.push(createPageButton(i));
281
+ }
282
+ if (currentPage < lastPage - 2) {
283
+ buttons.push(createDotsButton());
284
+ }
285
+ buttons.push(createPageButton(lastPage));
286
+ }
287
+ return buttons;
288
+ };
289
+
290
+ const createPageButton = (page) => button({
291
+ class: `paginate-btn ${page === currentPage ? "active" : ""}`,
292
+ value: `${page}`,
293
+ onClick: () => onPageChange(page),
294
+ });
295
+
296
+ const createDotsButton = () => button({
297
+ class: "paginate-dots",
298
+ disabled: true,
299
+ value: "...",
300
+ });
301
+
302
+ const navigateTo = (page) => {
303
+ const url = new URL(window.location.href);
304
+ const searchParams = new URLSearchParams(url.search);
305
+ searchParams.set("page", String(page));
306
+ window.history.pushState("", "", `${window.location.pathname}?${searchParams}`);
307
+ };
308
+
309
+ navigateTo(currentPage);
310
+
311
+ return div({
312
+ class: "paginate-block",
313
+ value: [
314
+ [styles],
315
+ button({
316
+ class: "paginate-prev",
317
+ value: "<<<",
318
+ onClick: () => onPageChange(currentPage > 1 ? currentPage - 1 : 1),
319
+ disabled: currentPage === 1,
320
+ }),
321
+ ...generatePageButtons(),
322
+ button({
323
+ class: "paginate-next",
324
+ value: ">>>",
325
+ onClick: () => onPageChange(currentPage < lastPage ? currentPage + 1 : lastPage),
326
+ disabled: currentPage === lastPage,
327
+ }),
328
+ ],
329
+ });
330
+ };
331
+
332
+ export const __counter = ({
333
+ perPage,
334
+ currentPage,
335
+ total,
336
+ callback,
337
+ params = [0, 1],
338
+ counts = [10, 20, 50, 100, 200, 500],
339
+ upText = undefined,
340
+ downText = undefined,
341
+ className = "",
342
+ style = {
343
+ width: "100%",
344
+ display: "flex",
345
+ alignItems: "center",
346
+ justifyContent: "center",
347
+ gap: "1rem"
348
+ }
349
+ }) => {
350
+ const from = (currentPage - 1) * perPage + 1;
351
+ const to = Math.min(currentPage * perPage, total);
352
+
353
+ downText = downText?.replace(/:from/g, from)?.replace(/:to/g, to)?.replace(/:all/g, total);
354
+
355
+ return div({
356
+ class: `${GUID()} ${className}`,
357
+ style: style,
358
+ value: [
359
+ div({
360
+ value: [
361
+ div({
362
+ style: { fontWeight: 600 },
363
+ value: upText || "Кількість строк в таблиці"
364
+ }),
365
+ div({
366
+ style: { fontSize: "10px" },
367
+ value: downText || `Отримано: [з ${from} по ${to}] Всього: ${total}`
368
+ })
369
+ ]
370
+ }),
371
+ ...counts.flatMap(count => button({
372
+ class: `${GUID()} paginate-btn ${Number(perPage) === count ? "active" : ""}`,
373
+ value: count,
374
+ onClick: () => {
375
+ cookie.set("perPage", count.toString(), 365);
376
+ params[0] = count;
377
+ params[1] = 1;
378
+ callback(...params);
379
+ }
380
+ }))
381
+ ]
382
+ });
383
+ };