@react-pakistan/util-functions 1.25.90 → 2.0.0
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/README.md +74 -315
- package/constants/api-methods.d.ts +3 -1
- package/constants/api-methods.js +1 -15
- package/constants/cache-time.d.ts +7 -5
- package/constants/cache-time.js +1 -8
- package/constants/countries-timezones.d.ts +4 -2
- package/constants/countries-timezones.js +1 -1411
- package/constants/currencies.d.ts +4 -2
- package/constants/currencies.js +1 -1076
- package/constants/dial-codes.d.ts +5 -3
- package/constants/dial-codes.js +1 -1216
- package/constants/layout-direction.d.ts +3 -1
- package/constants/layout-direction.js +1 -8
- package/constants/react-pakistan-meta.d.ts +4 -2
- package/constants/react-pakistan-meta.js +1 -35
- package/constants/react-pakistan.d.ts +5 -3
- package/constants/react-pakistan.js +12 -104
- package/constants/select-value-delimiter.d.ts +3 -1
- package/constants/select-value-delimiter.js +1 -13
- package/constants/social-media-colors.d.ts +3 -1
- package/constants/social-media-colors.js +1 -42
- package/constants/social-media-sizes.d.ts +6 -4
- package/constants/social-media-sizes.js +1 -327
- package/constants/user-roles.d.ts +3 -1
- package/constants/user-roles.js +1 -9
- package/edu-pilot-pro/types/academics.d.ts +2 -266
- package/edu-pilot-pro/types/academics.js +1 -9
- package/edu-pilot-pro/types/admission.d.ts +803 -10
- package/edu-pilot-pro/types/admission.js +1 -7
- package/edu-pilot-pro/types/communication.d.ts +2 -165
- package/edu-pilot-pro/types/communication.js +1 -8
- package/edu-pilot-pro/types/enums.d.ts +30 -28
- package/edu-pilot-pro/types/enums.js +1 -445
- package/edu-pilot-pro/types/finance.d.ts +2 -128
- package/edu-pilot-pro/types/finance.js +1 -8
- package/edu-pilot-pro/types/index.d.ts +2 -12
- package/edu-pilot-pro/types/index.js +1 -28
- package/edu-pilot-pro/types/user-management.d.ts +2 -236
- package/edu-pilot-pro/types/user-management.js +1 -8
- package/factory/generic-component-factory.d.ts +12 -9
- package/factory/generic-component-factory.js +1 -131
- package/factory/generic-module-factory.d.ts +14 -10
- package/factory/generic-module-factory.js +1 -190
- package/general/basic-get.d.ts +8 -1
- package/general/basic-get.js +1 -83
- package/general/basic-post.d.ts +8 -1
- package/general/basic-post.js +1 -70
- package/general/calculate-pages.d.ts +9 -1
- package/general/calculate-pages.js +1 -7
- package/general/camel-to-sentence-case.d.ts +3 -1
- package/general/camel-to-sentence-case.js +1 -20
- package/general/check-even-odd-length.d.ts +3 -1
- package/general/check-even-odd-length.js +1 -17
- package/general/clear-cache.d.ts +7 -2
- package/general/clear-cache.js +1 -12
- package/general/cnic-formatter.d.ts +16 -3
- package/general/cnic-formatter.js +1 -53
- package/general/convert-url-to-base64.d.ts +8 -6
- package/general/convert-url-to-base64.js +1 -231
- package/general/countries.d.ts +5 -3
- package/general/countries.js +1 -514
- package/general/create-date.d.ts +3 -1
- package/general/create-date.js +1 -22
- package/general/crypto.d.ts +4 -2
- package/general/crypto.js +1 -45
- package/general/currencies.d.ts +2 -0
- package/general/currencies.js +0 -1077
- package/general/delete-image-from-private-supabase.d.ts +10 -2
- package/general/delete-image-from-private-supabase.js +1 -66
- package/general/delete-image-from-public-supabase.d.ts +10 -2
- package/general/delete-image-from-public-supabase.js +1 -66
- package/general/download-from-url.d.ts +8 -1
- package/general/download-from-url.js +1 -82
- package/general/dynamic-page-limit.d.ts +9 -3
- package/general/dynamic-page-limit.js +1 -7
- package/general/enum-to-text.d.ts +8 -1
- package/general/enum-to-text.js +1 -11
- package/general/fetch-data.d.ts +16 -4
- package/general/fetch-data.js +1 -95
- package/general/fetch-supabase-image.d.ts +11 -2
- package/general/fetch-supabase-image.js +1 -67
- package/general/fetch-supabase-private-assets.d.ts +11 -2
- package/general/fetch-supabase-private-assets.js +1 -69
- package/general/format-date.d.ts +10 -2
- package/general/format-date.js +1 -49
- package/general/format-number.d.ts +12 -2
- package/general/format-number.js +1 -35
- package/general/format-phone-display.d.ts +9 -1
- package/general/format-phone-display.js +1 -32
- package/general/format-phone.d.ts +10 -2
- package/general/format-phone.js +1 -20
- package/general/format-pricing.d.ts +8 -1
- package/general/format-pricing.js +1 -23
- package/general/format-secs.d.ts +8 -1
- package/general/format-secs.js +1 -21
- package/general/format-time.d.ts +8 -2
- package/general/format-time.js +1 -38
- package/general/format-value.d.ts +8 -1
- package/general/format-value.js +1 -7
- package/general/full-month-range.d.ts +3 -2
- package/general/full-month-range.js +1 -24
- package/general/full-year-range.d.ts +3 -2
- package/general/full-year-range.js +1 -20
- package/general/generate-article-schema.d.ts +3 -2
- package/general/generate-article-schema.js +1 -100
- package/general/generate-blog-schema.d.ts +3 -2
- package/general/generate-blog-schema.js +1 -32
- package/general/generate-book-schema.d.ts +3 -2
- package/general/generate-book-schema.js +1 -109
- package/general/generate-breadcrumb-schema.d.ts +3 -2
- package/general/generate-breadcrumb-schema.js +1 -34
- package/general/generate-carousel-schema.d.ts +3 -2
- package/general/generate-carousel-schema.js +1 -172
- package/general/generate-course-schema.d.ts +3 -2
- package/general/generate-course-schema.js +1 -124
- package/general/generate-dataset-schema.d.ts +3 -2
- package/general/generate-dataset-schema.js +1 -156
- package/general/generate-discussion-forum-schema.d.ts +3 -2
- package/general/generate-discussion-forum-schema.js +1 -67
- package/general/generate-education-schema.d.ts +3 -2
- package/general/generate-education-schema.js +1 -137
- package/general/generate-employer-aggregate-rating-schema.d.ts +3 -2
- package/general/generate-employer-aggregate-rating-schema.js +1 -64
- package/general/generate-event-schema.d.ts +3 -2
- package/general/generate-event-schema.js +1 -214
- package/general/generate-faq-schema.d.ts +3 -2
- package/general/generate-faq-schema.js +1 -43
- package/general/generate-grid.d.ts +3 -2
- package/general/generate-grid.js +1 -55
- package/general/generate-image-metadata-schema.d.ts +3 -2
- package/general/generate-image-metadata-schema.js +1 -73
- package/general/generate-job-posting-schema.d.ts +3 -2
- package/general/generate-job-posting-schema.js +1 -120
- package/general/generate-local-business-schema.d.ts +3 -2
- package/general/generate-local-business-schema.js +1 -75
- package/general/generate-math-solver-schema.d.ts +3 -2
- package/general/generate-math-solver-schema.js +1 -83
- package/general/generate-movie-carousel-schema.d.ts +3 -2
- package/general/generate-movie-carousel-schema.js +1 -160
- package/general/generate-organization-schema.d.ts +3 -2
- package/general/generate-organization-schema.js +1 -39
- package/general/generate-profile-page-schema.d.ts +3 -2
- package/general/generate-profile-page-schema.js +1 -82
- package/general/generate-qa-page-schema.d.ts +3 -2
- package/general/generate-qa-page-schema.js +1 -67
- package/general/generate-recipe-schema.d.ts +3 -2
- package/general/generate-recipe-schema.js +1 -104
- package/general/generate-ref.d.ts +8 -2
- package/general/generate-ref.js +1 -12
- package/general/generate-review-snippet-schema.d.ts +3 -2
- package/general/generate-review-snippet-schema.js +1 -137
- package/general/generate-shopping-loyalty-program-schema.d.ts +3 -2
- package/general/generate-shopping-loyalty-program-schema.js +1 -59
- package/general/generate-shopping-merchant-listing-schema.d.ts +3 -2
- package/general/generate-shopping-merchant-listing-schema.js +1 -153
- package/general/generate-shopping-merchant-return-policy-schema.d.ts +3 -2
- package/general/generate-shopping-merchant-return-policy-schema.js +1 -68
- package/general/generate-shopping-merchant-shipping-policy-schema.d.ts +3 -2
- package/general/generate-shopping-merchant-shipping-policy-schema.js +1 -74
- package/general/generate-shopping-overview-schema.d.ts +3 -2
- package/general/generate-shopping-overview-schema.js +1 -157
- package/general/generate-shopping-product-snippet-schema.d.ts +3 -2
- package/general/generate-shopping-product-snippet-schema.js +1 -167
- package/general/generate-shopping-variants-schema.d.ts +3 -2
- package/general/generate-shopping-variants-schema.js +1 -143
- package/general/generate-software-app-schema.d.ts +3 -2
- package/general/generate-software-app-schema.js +1 -143
- package/general/generate-speakable-schema.d.ts +3 -2
- package/general/generate-speakable-schema.js +1 -139
- package/general/generate-subscription-schema.d.ts +3 -2
- package/general/generate-subscription-schema.js +1 -133
- package/general/generate-vacation-rental-schema.d.ts +3 -2
- package/general/generate-vacation-rental-schema.js +1 -135
- package/general/generate-video-schema.d.ts +3 -2
- package/general/generate-video-schema.js +1 -163
- package/general/generic-cache.d.ts +17 -15
- package/general/generic-cache.js +1 -659
- package/general/get-available-page-limit.d.ts +8 -2
- package/general/get-available-page-limit.js +1 -31
- package/general/get-calendar-current-month.d.ts +11 -3
- package/general/get-calendar-current-month.js +1 -31
- package/general/get-calendar-dates.d.ts +11 -3
- package/general/get-calendar-dates.js +1 -42
- package/general/get-calendar-next-month.d.ts +12 -3
- package/general/get-calendar-next-month.js +1 -32
- package/general/get-calendar-previous-month.d.ts +12 -3
- package/general/get-calendar-previous-month.js +1 -36
- package/general/get-current-year.d.ts +7 -1
- package/general/get-current-year.js +1 -5
- package/general/get-day-name.d.ts +5 -3
- package/general/get-day-name.js +1 -14
- package/general/get-dial-code.d.ts +8 -1
- package/general/get-dial-code.js +1 -8
- package/general/get-full-name.d.ts +9 -2
- package/general/get-full-name.js +1 -8
- package/general/get-href.d.ts +3 -1
- package/general/get-href.js +1 -13
- package/general/get-month-name.d.ts +5 -3
- package/general/get-month-name.js +1 -19
- package/general/get-month-number.d.ts +5 -3
- package/general/get-month-number.js +1 -29
- package/general/get-number-of-days-in-month.d.ts +9 -2
- package/general/get-number-of-days-in-month.js +1 -12
- package/general/get-pathname.d.ts +3 -1
- package/general/get-pathname.js +1 -16
- package/general/get-week-day.d.ts +8 -1
- package/general/get-week-day.js +1 -9
- package/general/image-url-to-base64.d.ts +3 -1
- package/general/image-url-to-base64.js +1 -80
- package/general/is-created-or-updated.d.ts +3 -1
- package/general/is-created-or-updated.js +1 -26
- package/general/is-next-button-disabled.d.ts +9 -1
- package/general/is-next-button-disabled.js +1 -5
- package/general/is-odd.d.ts +3 -1
- package/general/is-odd.js +1 -13
- package/general/is-previous-button-disabled.d.ts +8 -1
- package/general/is-previous-button-disabled.js +1 -7
- package/general/linear-gradients.d.ts +4 -2
- package/general/linear-gradients.js +1 -52
- package/general/multi-part-search.d.ts +10 -2
- package/general/multi-part-search.js +1 -16
- package/general/normalize-phone.d.ts +15 -2
- package/general/normalize-phone.js +1 -40
- package/general/parse-frontmatter.d.ts +11 -4
- package/general/parse-frontmatter.js +2 -35
- package/general/remove-data-image-prefix.d.ts +8 -1
- package/general/remove-data-image-prefix.js +1 -7
- package/general/repeat-times.d.ts +3 -1
- package/general/repeat-times.js +1 -21
- package/general/resolve-anchor-link.d.ts +3 -1
- package/general/resolve-anchor-link.js +1 -26
- package/general/resolve-current-date.d.ts +3 -1
- package/general/resolve-current-date.js +1 -22
- package/general/resolve-grid.d.ts +3 -1
- package/general/resolve-grid.js +1 -18
- package/general/resolve-initials.d.ts +3 -1
- package/general/resolve-initials.js +1 -17
- package/general/set-timezone.d.ts +11 -1
- package/general/set-timezone.js +1 -12
- package/general/slugify.d.ts +3 -1
- package/general/slugify.js +1 -24
- package/general/text-to-enum.d.ts +8 -1
- package/general/text-to-enum.js +1 -10
- package/general/text-to-sentence-case.d.ts +3 -1
- package/general/text-to-sentence-case.js +1 -16
- package/general/time-out.d.ts +3 -1
- package/general/time-out.js +1 -16
- package/general/time-zones.d.ts +3 -1
- package/general/time-zones.js +1 -437
- package/general/truncate-text.d.ts +3 -1
- package/general/truncate-text.js +1 -18
- package/general/type.d.ts +3 -1
- package/general/type.js +1 -2
- package/general/upload-blob-to-private-supabase.d.ts +14 -2
- package/general/upload-blob-to-private-supabase.js +1 -62
- package/general/upload-blob-to-public-supabase.d.ts +14 -2
- package/general/upload-blob-to-public-supabase.js +1 -62
- package/general/upload-image-to-private-supabase.d.ts +15 -3
- package/general/upload-image-to-private-supabase.js +1 -66
- package/general/upload-image-to-public-supabase.d.ts +15 -3
- package/general/upload-image-to-public-supabase.js +1 -66
- package/general/url-to-sentence-case.d.ts +3 -1
- package/general/url-to-sentence-case.js +1 -19
- package/general/validate-comment.d.ts +3 -1
- package/general/validate-comment.js +1 -21
- package/general/validate-email.d.ts +3 -1
- package/general/validate-email.js +1 -24
- package/general/validate-form.d.ts +12 -3
- package/general/validate-form.js +1 -29
- package/general/validate-name.d.ts +3 -1
- package/general/validate-name.js +1 -21
- package/hooks/use-change.d.ts +11 -2
- package/hooks/use-change.js +1 -23
- package/hooks/use-debounce.d.ts +10 -1
- package/hooks/use-debounce.js +1 -14
- package/hooks/use-fetch.d.ts +7 -5
- package/hooks/use-fetch.js +1 -239
- package/hooks/use-force-render.d.ts +6 -2
- package/hooks/use-force-render.js +1 -17
- package/hooks/use-ip-geo-location.d.ts +8 -1
- package/hooks/use-ip-geo-location.js +1 -79
- package/hooks/use-is-mobile.d.ts +8 -1
- package/hooks/use-is-mobile.js +1 -22
- package/hooks/use-module-entity-v2.d.ts +7 -4
- package/hooks/use-module-entity-v2.js +1 -188
- package/hooks/use-module-entity.d.ts +7 -4
- package/hooks/use-module-entity.js +1 -177
- package/hooks/use-phone-formatter.d.ts +10 -2
- package/hooks/use-phone-formatter.js +1 -23
- package/hooks/use-position.d.ts +6 -3
- package/hooks/use-position.js +1 -43
- package/hooks/use-rtl.d.ts +4 -2
- package/hooks/use-rtl.js +1 -84
- package/hooks/use-sticky.d.ts +3 -1
- package/hooks/use-sticky.js +1 -39
- package/hooks/use-toggle-state.d.ts +3 -2
- package/hooks/use-toggle-state.js +1 -26
- package/hooks/use-window-event-listener.d.ts +9 -1
- package/hooks/use-window-event-listener.js +1 -11
- package/hooks/with-seo.d.ts +11 -2
- package/hooks/with-seo.js +1 -37
- package/local-storage/get-storage-value.d.ts +5 -2
- package/local-storage/get-storage-value.js +1 -20
- package/local-storage/remove-storage-value.d.ts +3 -1
- package/local-storage/remove-storage-value.js +1 -14
- package/local-storage/set-storage-value.d.ts +3 -1
- package/local-storage/set-storage-value.js +1 -14
- package/local-storage/type.d.ts +3 -1
- package/local-storage/type.js +1 -2
- package/npm.d.d.ts +2 -0
- package/npm.d.js +0 -0
- package/package.json +20 -18
- package/storybook/generate-sitemap.d.ts +3 -1
- package/storybook/generate-sitemap.js +17 -26
- package/storybook/preview.d.ts +4 -2
- package/storybook/preview.js +1 -62
- package/storybook/react-design-story-script.d.ts +3 -1
- package/storybook/react-design-story-script.js +5 -27
- package/storybook/react-emoji-collection.d.ts +3 -1
- package/storybook/react-emoji-collection.js +10 -55
- package/storybook/react-emoji-story-script.d.ts +3 -1
- package/storybook/react-emoji-story-script.js +5 -31
- package/storybook/react-emoji-story-template.d.ts +3 -1
- package/storybook/react-emoji-story-template.js +45 -15
- package/storybook/react-icon-collection.d.ts +3 -1
- package/storybook/react-icon-collection.js +10 -42
- package/storybook/react-icon-story-script.d.ts +3 -1
- package/storybook/react-icon-story-script.js +5 -27
- package/storybook/react-icon-story-template.d.ts +3 -1
- package/storybook/react-icon-story-template.js +45 -14
- package/storybook/react-logo-collection.d.ts +3 -1
- package/storybook/react-logo-collection.js +10 -42
- package/storybook/react-logo-story-script.d.ts +3 -1
- package/storybook/react-logo-story-script.js +5 -27
- package/storybook/react-logo-story-template.d.ts +3 -1
- package/storybook/react-logo-story-template.js +45 -14
- package/storybook/react-pakistan-theme.d.ts +3 -1
- package/storybook/react-pakistan-theme.js +1 -31
- package/storybook/responsive-args.d.ts +11 -10
- package/storybook/responsive-args.js +1 -19
- package/storybook/responsive-component.d.ts +4 -2
- package/storybook/responsive-component.js +37 -23
- package/storybook/responsive-screens.d.ts +3 -1
- package/storybook/responsive-screens.js +1 -109
- package/storybook/theme.d.ts +17 -15
- package/storybook/theme.js +1 -1022
- package/api/stellar-solutions/app-user/index.d.ts +0 -51
- package/api/stellar-solutions/app-user/index.js +0 -210
- package/api/stellar-solutions/bank/index.d.ts +0 -59
- package/api/stellar-solutions/bank/index.js +0 -210
- package/api/stellar-solutions/branch/index.d.ts +0 -58
- package/api/stellar-solutions/branch/index.js +0 -220
- package/api/stellar-solutions/company/index.d.ts +0 -57
- package/api/stellar-solutions/company/index.js +0 -218
- package/api/stellar-solutions/company-report/index.d.ts +0 -15
- package/api/stellar-solutions/company-report/index.js +0 -74
- package/api/stellar-solutions/constants.d.ts +0 -19
- package/api/stellar-solutions/constants.js +0 -22
- package/api/stellar-solutions/contact/index.d.ts +0 -56
- package/api/stellar-solutions/contact/index.js +0 -217
- package/api/stellar-solutions/currency/index.d.ts +0 -55
- package/api/stellar-solutions/currency/index.js +0 -212
- package/api/stellar-solutions/customer/index.d.ts +0 -68
- package/api/stellar-solutions/customer/index.js +0 -249
- package/api/stellar-solutions/expense/index.d.ts +0 -58
- package/api/stellar-solutions/expense/index.js +0 -229
- package/api/stellar-solutions/expense-category/index.d.ts +0 -53
- package/api/stellar-solutions/expense-category/index.js +0 -214
- package/api/stellar-solutions/lead/index.d.ts +0 -51
- package/api/stellar-solutions/lead/index.js +0 -206
- package/api/stellar-solutions/menu-order/index.d.ts +0 -53
- package/api/stellar-solutions/menu-order/index.js +0 -202
- package/api/stellar-solutions/payment/index.d.ts +0 -65
- package/api/stellar-solutions/payment/index.js +0 -230
- package/api/stellar-solutions/payment-mode/index.d.ts +0 -53
- package/api/stellar-solutions/payment-mode/index.js +0 -191
- package/api/stellar-solutions/preference/index.d.ts +0 -25
- package/api/stellar-solutions/preference/index.js +0 -114
- package/api/stellar-solutions/product/index.d.ts +0 -64
- package/api/stellar-solutions/product/index.js +0 -235
- package/api/stellar-solutions/product-category/index.d.ts +0 -51
- package/api/stellar-solutions/product-category/index.js +0 -212
- package/api/stellar-solutions/profile/index.d.ts +0 -78
- package/api/stellar-solutions/profile/index.js +0 -234
- package/api/stellar-solutions/quote-invoice/index.d.ts +0 -97
- package/api/stellar-solutions/quote-invoice/index.js +0 -369
- package/api/stellar-solutions/quote-invoice-report/index.d.ts +0 -15
- package/api/stellar-solutions/quote-invoice-report/index.js +0 -74
- package/api/stellar-solutions/tax/index.d.ts +0 -55
- package/api/stellar-solutions/tax/index.js +0 -224
- package/api/stellar-solutions/types/common.d.ts +0 -24
- package/api/stellar-solutions/types/common.js +0 -22
- package/api/stellar-solutions/types/erp.d.ts +0 -302
- package/api/stellar-solutions/types/erp.js +0 -73
- package/api/stellar-solutions/types/index.d.ts +0 -3
- package/api/stellar-solutions/types/index.js +0 -19
- package/api/stellar-solutions/types/pos.d.ts +0 -176
- package/api/stellar-solutions/types/pos.js +0 -61
- package/constants/index.d.ts +0 -12
- package/constants/index.js +0 -28
- package/factory/index.d.ts +0 -2
- package/factory/index.js +0 -18
- package/general/index.d.ts +0 -95
- package/general/index.js +0 -111
- package/index.d.ts +0 -28
- package/index.js +0 -44
- package/local-storage/index.d.ts +0 -4
- package/local-storage/index.js +0 -20
- package/setupTests.d.ts +0 -1
- package/setupTests.js +0 -52
- package/storybook/index.d.ts +0 -17
- package/storybook/index.js +0 -33
|
@@ -1,188 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
/**
|
|
3
|
-
* useModuleEntityV2
|
|
4
|
-
*
|
|
5
|
-
* Summary
|
|
6
|
-
* - A convenience hook that manages common module/entity operations: list, get-by-id,
|
|
7
|
-
* create/update, and delete. It composes `useFetch` for HTTP calls and `useDebounce`
|
|
8
|
-
* for debouncing search queries.
|
|
9
|
-
*
|
|
10
|
-
* Main features
|
|
11
|
-
* - List: performs a GET to `listUrl` with `listParams`. The hook listens to
|
|
12
|
-
* `searchQuery` (debounced) and `listDeps` to re-run the list fetch.
|
|
13
|
-
* - Get by ID: performs a GET to `unitByIdUrl` with `byIdParams` and returns
|
|
14
|
-
* `byIdFetchNow`, `byIdLoading`, and `byIdError`.
|
|
15
|
-
* - Create/Update: performs a PUT to `unitUrl` with a JSON body `updateParams`.
|
|
16
|
-
* On successful create/update the hook triggers a coalesced list refresh.
|
|
17
|
-
* - Delete: performs a DELETE to `unitUrl` with a JSON body `deleteParams` and
|
|
18
|
-
* triggers a coalesced list refresh when the operation succeeds.
|
|
19
|
-
* - Refresh batching: `refreshList(delay)` coalesces multiple rapid updates/deletes
|
|
20
|
-
* using a short timeout (default 300ms) to avoid unnecessary list reloads.
|
|
21
|
-
*
|
|
22
|
-
* Parameters (object)
|
|
23
|
-
* - `byIdCallback(data)`, `byIdDeps`, `byIdParams` — params for GET by ID request
|
|
24
|
-
* - `deleteCallback(data)`, `deleteDeps`, `deleteParams` — body for DELETE request
|
|
25
|
-
* - `listCallback(data)`, `listDeps`, `listParams`, `listUrl` — params for GET list
|
|
26
|
-
* - `searchQuery` (string) — debounced before influencing the list fetch
|
|
27
|
-
* - `unitByIdUrl`, `unitUrl`
|
|
28
|
-
* - `updateCallback(data)`, `updateDeps`, `updateParams` — body for PUT request
|
|
29
|
-
*
|
|
30
|
-
* Parameter types
|
|
31
|
-
* - `listParams` and `byIdParams` support all primitive types including booleans.
|
|
32
|
-
* They are appended as URL query parameters for GET requests.
|
|
33
|
-
* Example: { active: true, page: 1 } → ?active=true&page=1
|
|
34
|
-
* - `updateParams` and `deleteParams` are sent as JSON in request body.
|
|
35
|
-
*
|
|
36
|
-
* Return values
|
|
37
|
-
* - `byIdFetchNow(url?, config?)`, `byIdLoading`, `byIdError`
|
|
38
|
-
* - `listFetchNow(url?, config?)`, `listLoading`, `listError`
|
|
39
|
-
* - `updateFetchNow(url?, config?)`, `updateLoading`, `updateError`
|
|
40
|
-
* - `deleteFetchNow(url?, config?)`, `deleteLoading`, `deleteError`
|
|
41
|
-
*
|
|
42
|
-
* Behavior notes
|
|
43
|
-
* - All callbacks receive an object `{ data, error, status, ok }` from `useFetch`.
|
|
44
|
-
* - Callbacks are wrapped so that any errors they throw are swallowed; this
|
|
45
|
-
* ensures the hook's refresh logic still runs reliably.
|
|
46
|
-
* - `refreshList()` calls `listFetchNow(undefined, { method: 'POST', params: listParams })`
|
|
47
|
-
* to explicitly re-query the list endpoint with the current `listParams`.
|
|
48
|
-
* - Network calls are delegated to `useFetch`; callers can call the returned
|
|
49
|
-
* `*FetchNow` functions directly with an override URL or config.
|
|
50
|
-
*
|
|
51
|
-
* Example
|
|
52
|
-
* const { listFetchNow, updateFetchNow } = useModuleEntityV2({
|
|
53
|
-
* listUrl: '/items',
|
|
54
|
-
* listParams: { page: 1, active: true },
|
|
55
|
-
* listCallback: (res) => console.log(res),
|
|
56
|
-
* unitUrl: '/items',
|
|
57
|
-
* updateCallback: () => {},
|
|
58
|
-
* updateParams: {}
|
|
59
|
-
* });
|
|
60
|
-
*/
|
|
61
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
62
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
63
|
-
if (ar || !(i in from)) {
|
|
64
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
65
|
-
ar[i] = from[i];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
69
|
-
};
|
|
70
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
-
exports.useModuleEntityV2 = void 0;
|
|
72
|
-
var react_1 = require("react");
|
|
73
|
-
var constants_1 = require("../constants");
|
|
74
|
-
var use_fetch_1 = require("./use-fetch");
|
|
75
|
-
var use_debounce_1 = require("./use-debounce");
|
|
76
|
-
var useModuleEntityV2 = function (_a) {
|
|
77
|
-
var byIdCallback = _a.byIdCallback, _b = _a.byIdDeps, byIdDeps = _b === void 0 ? [] : _b, byIdParams = _a.byIdParams, deleteCallback = _a.deleteCallback, _c = _a.deleteDeps, deleteDeps = _c === void 0 ? [] : _c, deleteParams = _a.deleteParams, listCallback = _a.listCallback, _d = _a.listDeps, listDeps = _d === void 0 ? [] : _d, listParams = _a.listParams, listUrl = _a.listUrl, headers = _a.headers, searchQuery = _a.searchQuery, unitByIdUrl = _a.unitByIdUrl, unitUrl = _a.unitUrl, updateCallback = _a.updateCallback, _e = _a.updateDeps, updateDeps = _e === void 0 ? [] : _e, updateParams = _a.updateParams;
|
|
78
|
-
var debouncedQuery = (0, use_debounce_1.useDebounce)(searchQuery, 800);
|
|
79
|
-
// debounced list refresh to batch multiple updates/deletes
|
|
80
|
-
var refreshTimerRef = (0, react_1.useRef)(null);
|
|
81
|
-
(0, react_1.useEffect)(function () { return function () {
|
|
82
|
-
if (refreshTimerRef.current) {
|
|
83
|
-
globalThis.clearTimeout(refreshTimerRef.current);
|
|
84
|
-
refreshTimerRef.current = null;
|
|
85
|
-
}
|
|
86
|
-
}; }, []);
|
|
87
|
-
// list
|
|
88
|
-
var _f = (0, use_fetch_1.useFetch)(listUrl, {
|
|
89
|
-
method: constants_1.API_METHODS.GET,
|
|
90
|
-
params: listParams,
|
|
91
|
-
headers: headers,
|
|
92
|
-
callback: listCallback,
|
|
93
|
-
credentials: true,
|
|
94
|
-
}, __spreadArray([debouncedQuery, listParams], listDeps, true)), listError = _f.error, listFetchNow = _f.fetchNow, listLoading = _f.loading;
|
|
95
|
-
var refreshList = function (delay) {
|
|
96
|
-
if (delay === void 0) { delay = 300; }
|
|
97
|
-
if (refreshTimerRef.current) {
|
|
98
|
-
globalThis.clearTimeout(refreshTimerRef.current);
|
|
99
|
-
}
|
|
100
|
-
refreshTimerRef.current = globalThis.setTimeout(function () {
|
|
101
|
-
try {
|
|
102
|
-
// pass current list params explicitly so the fetch uses the latest values
|
|
103
|
-
listFetchNow(undefined, {
|
|
104
|
-
method: constants_1.API_METHODS.GET,
|
|
105
|
-
params: listParams,
|
|
106
|
-
headers: headers,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
catch (_a) {
|
|
110
|
-
// noop
|
|
111
|
-
}
|
|
112
|
-
refreshTimerRef.current = null;
|
|
113
|
-
}, delay);
|
|
114
|
-
};
|
|
115
|
-
// create / edit
|
|
116
|
-
var _g = (0, use_fetch_1.useFetch)(unitUrl, {
|
|
117
|
-
method: constants_1.API_METHODS.PUT,
|
|
118
|
-
body: JSON.stringify(updateParams),
|
|
119
|
-
headers: headers,
|
|
120
|
-
callback: function (d) {
|
|
121
|
-
if (updateCallback) {
|
|
122
|
-
try {
|
|
123
|
-
updateCallback(d);
|
|
124
|
-
}
|
|
125
|
-
catch (_a) {
|
|
126
|
-
// swallow callback errors to ensure list refresh still runs
|
|
127
|
-
// caller's callback is responsible for its own error handling
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
// refresh the list after update/create only when the operation succeeded
|
|
131
|
-
try {
|
|
132
|
-
if (d && d.ok) {
|
|
133
|
-
refreshList();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
catch (_b) {
|
|
137
|
-
// noop
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
}, __spreadArray([], updateDeps, true)), updateError = _g.error, updateLoading = _g.loading, updateFetchNow = _g.fetchNow;
|
|
141
|
-
// by id
|
|
142
|
-
var _h = (0, use_fetch_1.useFetch)(unitByIdUrl, {
|
|
143
|
-
method: constants_1.API_METHODS.GET,
|
|
144
|
-
params: byIdParams,
|
|
145
|
-
headers: headers,
|
|
146
|
-
callback: byIdCallback,
|
|
147
|
-
}, __spreadArray([], byIdDeps, true)), byIdError = _h.error, byIdLoading = _h.loading, byIdFetchNow = _h.fetchNow;
|
|
148
|
-
// delete
|
|
149
|
-
var _j = (0, use_fetch_1.useFetch)(unitUrl, {
|
|
150
|
-
method: constants_1.API_METHODS.DELETE,
|
|
151
|
-
body: JSON.stringify(deleteParams),
|
|
152
|
-
headers: headers,
|
|
153
|
-
callback: function (d) {
|
|
154
|
-
if (deleteCallback) {
|
|
155
|
-
try {
|
|
156
|
-
deleteCallback(d);
|
|
157
|
-
}
|
|
158
|
-
catch (_a) {
|
|
159
|
-
// swallow callback errors to ensure list refresh still runs
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
// refresh the list after delete only when the operation succeeded
|
|
163
|
-
try {
|
|
164
|
-
if (d && d.ok) {
|
|
165
|
-
refreshList();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
catch (_b) {
|
|
169
|
-
// noop
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
}, __spreadArray([], deleteDeps, true)), deleteError = _j.error, deleteLoading = _j.loading, deleteFetchNow = _j.fetchNow;
|
|
173
|
-
return {
|
|
174
|
-
byIdError: byIdError,
|
|
175
|
-
byIdFetchNow: byIdFetchNow,
|
|
176
|
-
byIdLoading: byIdLoading,
|
|
177
|
-
deleteError: deleteError,
|
|
178
|
-
deleteFetchNow: deleteFetchNow,
|
|
179
|
-
deleteLoading: deleteLoading,
|
|
180
|
-
listError: listError,
|
|
181
|
-
listFetchNow: listFetchNow,
|
|
182
|
-
listLoading: listLoading,
|
|
183
|
-
updateError: updateError,
|
|
184
|
-
updateFetchNow: updateFetchNow,
|
|
185
|
-
updateLoading: updateLoading,
|
|
186
|
-
};
|
|
187
|
-
};
|
|
188
|
-
exports.useModuleEntityV2 = useModuleEntityV2;
|
|
1
|
+
var g=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var M=(e,r)=>{for(var i in r)g(e,i,{get:r[i],enumerable:!0})},Q=(e,r,i,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of x(r))!J.call(e,o)&&o!==i&&g(e,o,{get:()=>r[o],enumerable:!(c=U(r,o))||c.enumerable});return e};var B=e=>Q(g({},"__esModule",{value:!0}),e);var _={};M(_,{useModuleEntityV2:()=>H});module.exports=B(_);var d=require("react"),n=require("../constants/api-methods"),s=require("./use-fetch"),h=require("./use-debounce");const H=({byIdCallback:e,byIdDeps:r=[],byIdParams:i,deleteCallback:c,deleteDeps:o=[],deleteParams:p,listCallback:E,listDeps:k=[],listParams:u,listUrl:T,headers:l,searchQuery:C,unitByIdUrl:F,unitUrl:b,updateCallback:y,updateDeps:N=[],updateParams:P})=>{const w=(0,h.useDebounce)(C,800),a=(0,d.useRef)(null);(0,d.useEffect)(()=>()=>{a.current&&(globalThis.clearTimeout(a.current),a.current=null)},[]);const{error:I,fetchNow:f,loading:L}=(0,s.useFetch)(T,{method:n.API_METHODS.GET,params:u,headers:l,callback:E,credentials:!0},[w,u,...k]),m=(t=300)=>{a.current&&globalThis.clearTimeout(a.current),a.current=globalThis.setTimeout(()=>{try{f(void 0,{method:n.API_METHODS.GET,params:u,headers:l})}catch{}a.current=null},t)},{error:v,loading:A,fetchNow:V}=(0,s.useFetch)(b,{method:n.API_METHODS.PUT,body:JSON.stringify(P),headers:l,callback:t=>{if(y)try{y(t)}catch{}try{t&&t.ok&&m()}catch{}}},[...N]),{error:D,loading:R,fetchNow:j}=(0,s.useFetch)(F,{method:n.API_METHODS.GET,params:i,headers:l,callback:e},[...r]),{error:G,loading:O,fetchNow:S}=(0,s.useFetch)(b,{method:n.API_METHODS.DELETE,body:JSON.stringify(p),headers:l,callback:t=>{if(c)try{c(t)}catch{}try{t&&t.ok&&m()}catch{}}},[...o]);return{byIdError:D,byIdFetchNow:j,byIdLoading:R,deleteError:G,deleteFetchNow:S,deleteLoading:O,listError:I,listFetchNow:f,listLoading:L,updateError:v,updateFetchNow:V,updateLoading:A}};0&&(module.exports={useModuleEntityV2});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { FetchConfig } from './use-fetch.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* useModuleEntity
|
|
3
5
|
*
|
|
@@ -52,8 +54,8 @@
|
|
|
52
54
|
* updateParams: {}
|
|
53
55
|
* });
|
|
54
56
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
|
|
58
|
+
interface CallbackParams {
|
|
57
59
|
data: any;
|
|
58
60
|
error: any;
|
|
59
61
|
status?: number;
|
|
@@ -91,5 +93,6 @@ interface Return {
|
|
|
91
93
|
updateFetchNow: (url?: string, config?: FetchConfig) => void;
|
|
92
94
|
updateLoading: boolean;
|
|
93
95
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
declare const useModuleEntity: ({ byIdCallback, byIdDeps, byIdParams, deleteCallback, deleteDeps, deleteParams, listCallback, listDeps, listParams, listUrl, searchQuery, unitByIdUrl, unitUrl, updateCallback, updateDeps, updateParams, }: Params) => Return;
|
|
97
|
+
|
|
98
|
+
export { type CallbackParams, useModuleEntity };
|
|
@@ -1,177 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
/**
|
|
3
|
-
* useModuleEntity
|
|
4
|
-
*
|
|
5
|
-
* Summary
|
|
6
|
-
* - A convenience hook that manages common module/entity operations: list, get-by-id,
|
|
7
|
-
* create/update, and delete. It composes `useFetch` for HTTP calls and `useDebounce`
|
|
8
|
-
* for debouncing search queries.
|
|
9
|
-
*
|
|
10
|
-
* Main features
|
|
11
|
-
* - List: performs a POST to `listUrl` with a JSON body `listParams` and re-runs
|
|
12
|
-
* when `searchQuery` (debounced) or `listDeps` change.
|
|
13
|
-
* - Get by ID: performs a POST to `unitByIdUrl` with `byIdParams` in the JSON body
|
|
14
|
-
* and exposes `byIdFetchNow`, `byIdLoading`, and `byIdError`.
|
|
15
|
-
* - Create/Update: performs a POST to `unitUrl` with a JSON body `updateParams`.
|
|
16
|
-
* On successful create/update the hook triggers a coalesced list refresh.
|
|
17
|
-
* - Delete: performs a DELETE to `unitUrl` with a JSON body `deleteParams` and
|
|
18
|
-
* triggers a coalesced list refresh when the operation succeeds.
|
|
19
|
-
* - Refresh batching: `refreshList(delay)` coalesces multiple rapid updates/deletes
|
|
20
|
-
* using a short timeout (default 300ms) to avoid unnecessary list reloads.
|
|
21
|
-
*
|
|
22
|
-
* Parameters (object)
|
|
23
|
-
* - `byIdCallback(data)`, `byIdDeps`, `byIdParams`
|
|
24
|
-
* - `deleteCallback(data)`, `deleteDeps`, `deleteParams`
|
|
25
|
-
* - `listCallback(data)`, `listDeps`, `listParams`, `listUrl`
|
|
26
|
-
* - `searchQuery` (string) — debounced before influencing the list fetch
|
|
27
|
-
* - `unitByIdUrl`, `unitUrl`
|
|
28
|
-
* - `updateCallback(data)`, `updateDeps`, `updateParams`
|
|
29
|
-
*
|
|
30
|
-
* Return values
|
|
31
|
-
* - `byIdFetchNow(url?, config?)`, `byIdLoading`, `byIdError`
|
|
32
|
-
* - `listFetchNow(url?, config?)`, `listLoading`, `listError`
|
|
33
|
-
* - `updateFetchNow(url?, config?)`, `updateLoading`, `updateError`
|
|
34
|
-
* - `deleteFetchNow(url?, config?)`, `deleteLoading`, `deleteError`
|
|
35
|
-
*
|
|
36
|
-
* Behavior notes
|
|
37
|
-
* - All requests that accept parameters send them in the JSON request body (stringified).
|
|
38
|
-
* - All callbacks receive an object `{ data, error, status, ok }` from `useFetch`.
|
|
39
|
-
* - Callbacks are wrapped so thrown errors are swallowed to ensure refresh logic
|
|
40
|
-
* still runs reliably.
|
|
41
|
-
* - `refreshList()` calls `listFetchNow(undefined, { method: 'POST', body: JSON.stringify(listParams) })`
|
|
42
|
-
* to explicitly re-query the list endpoint with the current `listParams`.
|
|
43
|
-
* - Network calls are delegated to `useFetch`; callers can invoke the returned
|
|
44
|
-
* `*FetchNow` functions directly with an override URL or config.
|
|
45
|
-
*
|
|
46
|
-
* Example
|
|
47
|
-
* const { listFetchNow, updateFetchNow } = useModuleEntity({
|
|
48
|
-
* listUrl: '/items',
|
|
49
|
-
* listParams: { page: 1 },
|
|
50
|
-
* listCallback: (res) => console.log(res),
|
|
51
|
-
* unitUrl: '/items',
|
|
52
|
-
* updateCallback: () => {},
|
|
53
|
-
* updateParams: {}
|
|
54
|
-
* });
|
|
55
|
-
*/
|
|
56
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
57
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
58
|
-
if (ar || !(i in from)) {
|
|
59
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
60
|
-
ar[i] = from[i];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
64
|
-
};
|
|
65
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
|
-
exports.useModuleEntity = void 0;
|
|
67
|
-
var react_1 = require("react");
|
|
68
|
-
var constants_1 = require("../constants");
|
|
69
|
-
var use_fetch_1 = require("./use-fetch");
|
|
70
|
-
var use_debounce_1 = require("./use-debounce");
|
|
71
|
-
var useModuleEntity = function (_a) {
|
|
72
|
-
var byIdCallback = _a.byIdCallback, _b = _a.byIdDeps, byIdDeps = _b === void 0 ? [] : _b, byIdParams = _a.byIdParams, deleteCallback = _a.deleteCallback, _c = _a.deleteDeps, deleteDeps = _c === void 0 ? [] : _c, deleteParams = _a.deleteParams, listCallback = _a.listCallback, _d = _a.listDeps, listDeps = _d === void 0 ? [] : _d, listParams = _a.listParams, listUrl = _a.listUrl, searchQuery = _a.searchQuery, unitByIdUrl = _a.unitByIdUrl, unitUrl = _a.unitUrl, updateCallback = _a.updateCallback, _e = _a.updateDeps, updateDeps = _e === void 0 ? [] : _e, updateParams = _a.updateParams;
|
|
73
|
-
var debouncedQuery = (0, use_debounce_1.useDebounce)(searchQuery, 800);
|
|
74
|
-
// debounced list refresh to batch multiple updates/deletes
|
|
75
|
-
var refreshTimerRef = (0, react_1.useRef)(null);
|
|
76
|
-
(0, react_1.useEffect)(function () { return function () {
|
|
77
|
-
if (refreshTimerRef.current) {
|
|
78
|
-
globalThis.clearTimeout(refreshTimerRef.current);
|
|
79
|
-
refreshTimerRef.current = null;
|
|
80
|
-
}
|
|
81
|
-
}; }, []);
|
|
82
|
-
// list
|
|
83
|
-
var _f = (0, use_fetch_1.useFetch)(listUrl, {
|
|
84
|
-
method: constants_1.API_METHODS.POST,
|
|
85
|
-
body: JSON.stringify(listParams),
|
|
86
|
-
callback: listCallback,
|
|
87
|
-
}, __spreadArray([debouncedQuery, JSON.stringify(listParams)], listDeps, true)), listError = _f.error, listFetchNow = _f.fetchNow, listLoading = _f.loading;
|
|
88
|
-
var refreshList = function (delay) {
|
|
89
|
-
if (delay === void 0) { delay = 300; }
|
|
90
|
-
if (refreshTimerRef.current) {
|
|
91
|
-
globalThis.clearTimeout(refreshTimerRef.current);
|
|
92
|
-
}
|
|
93
|
-
refreshTimerRef.current = globalThis.setTimeout(function () {
|
|
94
|
-
try {
|
|
95
|
-
// pass current list params explicitly so the fetch uses the latest values
|
|
96
|
-
listFetchNow(undefined, {
|
|
97
|
-
method: constants_1.API_METHODS.POST,
|
|
98
|
-
body: JSON.stringify(listParams),
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
catch (_a) {
|
|
102
|
-
// noop
|
|
103
|
-
}
|
|
104
|
-
refreshTimerRef.current = null;
|
|
105
|
-
}, delay);
|
|
106
|
-
};
|
|
107
|
-
// create / edit
|
|
108
|
-
var _g = (0, use_fetch_1.useFetch)(unitUrl, {
|
|
109
|
-
method: constants_1.API_METHODS.POST,
|
|
110
|
-
body: JSON.stringify(updateParams),
|
|
111
|
-
callback: function (d) {
|
|
112
|
-
if (updateCallback) {
|
|
113
|
-
try {
|
|
114
|
-
updateCallback(d);
|
|
115
|
-
}
|
|
116
|
-
catch (_a) {
|
|
117
|
-
// swallow callback errors to ensure list refresh still runs
|
|
118
|
-
// caller's callback is responsible for its own error handling
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// refresh the list after update/create only when the operation succeeded
|
|
122
|
-
try {
|
|
123
|
-
if (d && d.ok) {
|
|
124
|
-
refreshList();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch (_b) {
|
|
128
|
-
// noop
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
}, __spreadArray([], updateDeps, true)), updateError = _g.error, updateLoading = _g.loading, updateFetchNow = _g.fetchNow;
|
|
132
|
-
// by id
|
|
133
|
-
var _h = (0, use_fetch_1.useFetch)(unitByIdUrl, {
|
|
134
|
-
method: constants_1.API_METHODS.POST,
|
|
135
|
-
body: JSON.stringify(byIdParams),
|
|
136
|
-
callback: byIdCallback,
|
|
137
|
-
}, __spreadArray([], byIdDeps, true)), byIdError = _h.error, byIdLoading = _h.loading, byIdFetchNow = _h.fetchNow;
|
|
138
|
-
// delete
|
|
139
|
-
var _j = (0, use_fetch_1.useFetch)(unitUrl, {
|
|
140
|
-
method: constants_1.API_METHODS.DELETE,
|
|
141
|
-
body: JSON.stringify(deleteParams),
|
|
142
|
-
callback: function (d) {
|
|
143
|
-
if (deleteCallback) {
|
|
144
|
-
try {
|
|
145
|
-
deleteCallback(d);
|
|
146
|
-
}
|
|
147
|
-
catch (_a) {
|
|
148
|
-
// swallow callback errors to ensure list refresh still runs
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
// refresh the list after delete only when the operation succeeded
|
|
152
|
-
try {
|
|
153
|
-
if (d && d.ok) {
|
|
154
|
-
refreshList();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
catch (_b) {
|
|
158
|
-
// noop
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
}, __spreadArray([], deleteDeps, true)), deleteError = _j.error, deleteLoading = _j.loading, deleteFetchNow = _j.fetchNow;
|
|
162
|
-
return {
|
|
163
|
-
byIdError: byIdError,
|
|
164
|
-
byIdFetchNow: byIdFetchNow,
|
|
165
|
-
byIdLoading: byIdLoading,
|
|
166
|
-
deleteError: deleteError,
|
|
167
|
-
deleteFetchNow: deleteFetchNow,
|
|
168
|
-
deleteLoading: deleteLoading,
|
|
169
|
-
listError: listError,
|
|
170
|
-
listFetchNow: listFetchNow,
|
|
171
|
-
listLoading: listLoading,
|
|
172
|
-
updateError: updateError,
|
|
173
|
-
updateFetchNow: updateFetchNow,
|
|
174
|
-
updateLoading: updateLoading,
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
exports.useModuleEntity = useModuleEntity;
|
|
1
|
+
var u=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var U=(e,r)=>{for(var i in r)u(e,i,{get:r[i],enumerable:!0})},B=(e,r,i,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of M(r))!Q.call(e,o)&&o!==i&&u(e,o,{get:()=>r[o],enumerable:!(c=x(r,o))||c.enumerable});return e};var H=e=>B(u({},"__esModule",{value:!0}),e);var q={};U(q,{useModuleEntity:()=>_});module.exports=H(q);var s=require("react"),n=require("../constants/api-methods"),l=require("./use-fetch"),h=require("./use-debounce");const _=({byIdCallback:e,byIdDeps:r=[],byIdParams:i,deleteCallback:c,deleteDeps:o=[],deleteParams:m,listCallback:p,listDeps:E=[],listParams:d,listUrl:N,searchQuery:k,unitByIdUrl:P,unitUrl:y,updateCallback:b,updateDeps:T=[],updateParams:C})=>{const F=(0,h.useDebounce)(k,800),a=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{a.current&&(globalThis.clearTimeout(a.current),a.current=null)},[]);const{error:w,fetchNow:g,loading:I}=(0,l.useFetch)(N,{method:n.API_METHODS.POST,body:JSON.stringify(d),callback:p},[F,JSON.stringify(d),...E]),f=(t=300)=>{a.current&&globalThis.clearTimeout(a.current),a.current=globalThis.setTimeout(()=>{try{g(void 0,{method:n.API_METHODS.POST,body:JSON.stringify(d)})}catch{}a.current=null},t)},{error:O,loading:S,fetchNow:L}=(0,l.useFetch)(y,{method:n.API_METHODS.POST,body:JSON.stringify(C),callback:t=>{if(b)try{b(t)}catch{}try{t&&t.ok&&f()}catch{}}},[...T]),{error:v,loading:A,fetchNow:D}=(0,l.useFetch)(P,{method:n.API_METHODS.POST,body:JSON.stringify(i),callback:e},[...r]),{error:J,loading:R,fetchNow:j}=(0,l.useFetch)(y,{method:n.API_METHODS.DELETE,body:JSON.stringify(m),callback:t=>{if(c)try{c(t)}catch{}try{t&&t.ok&&f()}catch{}}},[...o]);return{byIdError:v,byIdFetchNow:D,byIdLoading:A,deleteError:J,deleteFetchNow:j,deleteLoading:R,listError:w,listFetchNow:g,listLoading:I,updateError:O,updateFetchNow:L,updateLoading:S}};0&&(module.exports={useModuleEntity});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CountryCode } from 'libphonenumber-js';
|
|
2
|
+
|
|
2
3
|
interface FormattedPhoneNumber {
|
|
3
4
|
e164: string;
|
|
4
5
|
international: string;
|
|
@@ -7,5 +8,12 @@ interface Return {
|
|
|
7
8
|
formatted: FormattedPhoneNumber | null;
|
|
8
9
|
formatNumber: (v: string) => void;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Parses and formats phone numbers into E.164 and international formats.
|
|
13
|
+
*
|
|
14
|
+
* @param defaultCountry - The default country code to use when parsing (default 'US').
|
|
15
|
+
* @returns An object containing the formatted phone number (or null) and a setter function.
|
|
16
|
+
*/
|
|
17
|
+
declare const usePhoneFormatter: (defaultCountry?: CountryCode) => Return;
|
|
18
|
+
|
|
19
|
+
export { usePhoneFormatter };
|
|
@@ -1,23 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.usePhoneFormatter = void 0;
|
|
4
|
-
var react_1 = require("react");
|
|
5
|
-
var libphonenumber_js_1 = require("libphonenumber-js");
|
|
6
|
-
var usePhoneFormatter = function (defaultCountry) {
|
|
7
|
-
if (defaultCountry === void 0) { defaultCountry = 'US'; }
|
|
8
|
-
var _a = (0, react_1.useState)(null), formatted = _a[0], setFormatted = _a[1];
|
|
9
|
-
var formatNumber = function (value) {
|
|
10
|
-
var phoneNumber = (0, libphonenumber_js_1.parsePhoneNumberFromString)(value, defaultCountry);
|
|
11
|
-
if (phoneNumber) {
|
|
12
|
-
setFormatted({
|
|
13
|
-
e164: phoneNumber.isValid() ? phoneNumber.format('E.164') : '',
|
|
14
|
-
international: phoneNumber.formatInternational(),
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
setFormatted(null);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
return { formatted: formatted, formatNumber: formatNumber };
|
|
22
|
-
};
|
|
23
|
-
exports.usePhoneFormatter = usePhoneFormatter;
|
|
1
|
+
var a=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var d=(r,t)=>{for(var e in t)a(r,e,{get:t[e],enumerable:!0})},b=(r,t,e,m)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of l(t))!f.call(r,o)&&o!==e&&a(r,o,{get:()=>t[o],enumerable:!(m=s(t,o))||m.enumerable});return r};var N=r=>b(a({},"__esModule",{value:!0}),r);var h={};d(h,{usePhoneFormatter:()=>c});module.exports=N(h);var i=require("react"),u=require("libphonenumber-js");const c=(r="US")=>{const[t,e]=(0,i.useState)(null);return{formatted:t,formatNumber:o=>{const n=(0,u.parsePhoneNumberFromString)(o,r);e(n?{e164:n.isValid()?n.format("E.164"):"",international:n.formatInternational()}:null)}}};0&&(module.exports={usePhoneFormatter});
|
package/hooks/use-position.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* A util hook to get element positioning.
|
|
3
5
|
*
|
|
@@ -7,7 +9,7 @@
|
|
|
7
9
|
* @remarks
|
|
8
10
|
*/
|
|
9
11
|
/** End file docs */
|
|
10
|
-
|
|
12
|
+
|
|
11
13
|
type PositionRef = {
|
|
12
14
|
offsetLeft: 0 | null;
|
|
13
15
|
offsetRight: 0 | null;
|
|
@@ -22,5 +24,6 @@ type StateY = {
|
|
|
22
24
|
yTop: 0 | null;
|
|
23
25
|
yBottom: 0 | null;
|
|
24
26
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
declare const usePosition: (elementRef: RefObject<PositionRef>) => [StateX, StateY];
|
|
28
|
+
|
|
29
|
+
export { usePosition };
|
package/hooks/use-position.js
CHANGED
|
@@ -1,43 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
/**
|
|
3
|
-
* A util hook to get element positioning.
|
|
4
|
-
*
|
|
5
|
-
* @param elementRef as an element ref for it's position
|
|
6
|
-
* @returns [x, y]
|
|
7
|
-
* @author Taimoor Khan
|
|
8
|
-
* @remarks
|
|
9
|
-
*/
|
|
10
|
-
/** End file docs */
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.usePosition = void 0;
|
|
13
|
-
var react_1 = require("react");
|
|
14
|
-
var usePosition = function (elementRef) {
|
|
15
|
-
var _a = (0, react_1.useState)({
|
|
16
|
-
xLeft: 0,
|
|
17
|
-
xRight: 0,
|
|
18
|
-
}), x = _a[0], setX = _a[1];
|
|
19
|
-
var _b = (0, react_1.useState)({
|
|
20
|
-
yTop: 0,
|
|
21
|
-
yBottom: 0,
|
|
22
|
-
}), y = _b[0], setY = _b[1];
|
|
23
|
-
var getPosition = (0, react_1.useCallback)(function () {
|
|
24
|
-
var _a, _b, _c, _d;
|
|
25
|
-
var xLeft = ((_a = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _a === void 0 ? void 0 : _a.offsetLeft) || null;
|
|
26
|
-
var xRight = ((_b = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _b === void 0 ? void 0 : _b.offsetRight) || null;
|
|
27
|
-
var yTop = ((_c = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _c === void 0 ? void 0 : _c.offsetTop) || null;
|
|
28
|
-
var yBottom = ((_d = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _d === void 0 ? void 0 : _d.offsetBottom) || null;
|
|
29
|
-
setX({
|
|
30
|
-
xLeft: xLeft,
|
|
31
|
-
xRight: xRight,
|
|
32
|
-
});
|
|
33
|
-
setY({
|
|
34
|
-
yTop: yTop,
|
|
35
|
-
yBottom: yBottom,
|
|
36
|
-
});
|
|
37
|
-
}, [elementRef, setX, setY]);
|
|
38
|
-
(0, react_1.useEffect)(function () {
|
|
39
|
-
getPosition();
|
|
40
|
-
}, [getPosition]);
|
|
41
|
-
return [x, y];
|
|
42
|
-
};
|
|
43
|
-
exports.usePosition = usePosition;
|
|
1
|
+
var l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var S=(t,o)=>{for(var s in o)l(t,s,{get:o[s],enumerable:!0})},g=(t,o,s,f)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of a(o))!x.call(t,e)&&e!==s&&l(t,e,{get:()=>o[e],enumerable:!(f=y(o,e))||f.enumerable});return t};var h=t=>g(l({},"__esModule",{value:!0}),t);var L={};S(L,{usePosition:()=>B});module.exports=h(L);var n=require("react");const B=t=>{const[o,s]=(0,n.useState)({xLeft:0,xRight:0}),[f,e]=(0,n.useState)({yTop:0,yBottom:0}),u=(0,n.useCallback)(()=>{const c=t?.current?.offsetLeft||null,i=t?.current?.offsetRight||null,r=t?.current?.offsetTop||null,p=t?.current?.offsetBottom||null;s({xLeft:c,xRight:i}),e({yTop:r,yBottom:p})},[t,s,e]);return(0,n.useEffect)(()=>{u()},[u]),[o,f]};0&&(module.exports={usePosition});
|
package/hooks/use-rtl.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Hook to detect RTL (Right-to-Left) layout based on current locale
|
|
3
3
|
* @returns {boolean} true if current locale requires RTL layout (Urdu), false otherwise
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
declare const useRTL: (forcedLocale?: string) => boolean;
|
|
6
6
|
/**
|
|
7
7
|
* Hook to get RTL-aware CSS classes
|
|
8
8
|
*
|
|
@@ -24,7 +24,7 @@ export declare const useRTL: (forcedLocale?: string) => boolean;
|
|
|
24
24
|
* </Button>
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
declare const useRTLClasses: (forcedLocale?: string) => {
|
|
28
28
|
isRTL: boolean;
|
|
29
29
|
container: string;
|
|
30
30
|
direction: string;
|
|
@@ -42,3 +42,5 @@ export declare const useRTLClasses: () => {
|
|
|
42
42
|
iconButton: string;
|
|
43
43
|
iconWithText: (iconPosition?: "left" | "right") => "flex items-center flex-row-reverse gap-2" | "flex items-center gap-2";
|
|
44
44
|
};
|
|
45
|
+
|
|
46
|
+
export { useRTL, useRTLClasses };
|
package/hooks/use-rtl.js
CHANGED
|
@@ -1,84 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRTLClasses = exports.useRTL = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Hook to detect RTL (Right-to-Left) layout based on current locale
|
|
6
|
-
* @returns {boolean} true if current locale requires RTL layout (Urdu), false otherwise
|
|
7
|
-
*/
|
|
8
|
-
var useRTL = function (forcedLocale) {
|
|
9
|
-
if (forcedLocale)
|
|
10
|
-
return forcedLocale === 'ur';
|
|
11
|
-
try {
|
|
12
|
-
// Require at runtime so bundlers don't statically include next-intl unless used
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
14
|
-
var useLocale = require('next-intl').useLocale;
|
|
15
|
-
var locale = useLocale();
|
|
16
|
-
return locale === 'ur';
|
|
17
|
-
}
|
|
18
|
-
catch (_a) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
exports.useRTL = useRTL;
|
|
23
|
-
/**
|
|
24
|
-
* Hook to get RTL-aware CSS classes
|
|
25
|
-
*
|
|
26
|
-
* @returns Object containing common RTL-aware class combinations
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* const rtlClasses = useRTLClasses();
|
|
31
|
-
*
|
|
32
|
-
* // For icon buttons (ensures proper centering in RTL)
|
|
33
|
-
* <Button size="icon" className={`h-8 w-8 ${rtlClasses.iconButton}`}>
|
|
34
|
-
* <Icon />
|
|
35
|
-
* </Button>
|
|
36
|
-
*
|
|
37
|
-
* // For buttons with icon and text
|
|
38
|
-
* <Button className={rtlClasses.iconWithText("left")}>
|
|
39
|
-
* <Icon />
|
|
40
|
-
* <span>Button Text</span>
|
|
41
|
-
* </Button>
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
var useRTLClasses = function () {
|
|
45
|
-
var isRTL = (0, exports.useRTL)();
|
|
46
|
-
return {
|
|
47
|
-
isRTL: isRTL,
|
|
48
|
-
// Container classes
|
|
49
|
-
container: isRTL ? 'rtl' : 'ltr',
|
|
50
|
-
direction: isRTL ? 'rtl' : 'ltr',
|
|
51
|
-
// Flex classes
|
|
52
|
-
flexRow: isRTL ? 'flex-row-reverse' : 'flex-row',
|
|
53
|
-
flexRowReverse: isRTL ? 'flex-row' : 'flex-row-reverse',
|
|
54
|
-
// Text alignment
|
|
55
|
-
textAlign: isRTL ? 'text-right' : 'text-left',
|
|
56
|
-
textAlignReverse: isRTL ? 'text-left' : 'text-right',
|
|
57
|
-
// Margin classes
|
|
58
|
-
marginLeft: isRTL ? 'mr-auto' : 'ml-auto',
|
|
59
|
-
marginRight: isRTL ? 'ml-auto' : 'mr-auto',
|
|
60
|
-
// Padding classes
|
|
61
|
-
paddingLeft: function (size) { return (isRTL ? "pr-".concat(size) : "pl-".concat(size)); },
|
|
62
|
-
paddingRight: function (size) { return (isRTL ? "pl-".concat(size) : "pr-".concat(size)); },
|
|
63
|
-
// Gap and spacing
|
|
64
|
-
gap: function (size) { return "gap-".concat(size); },
|
|
65
|
-
// Border radius (for buttons, cards, etc.)
|
|
66
|
-
roundedLeft: isRTL ? 'rounded-r' : 'rounded-l',
|
|
67
|
-
roundedRight: isRTL ? 'rounded-l' : 'rounded-r',
|
|
68
|
-
// Icon button classes for proper centering in RTL
|
|
69
|
-
iconButton: 'flex items-center justify-center border',
|
|
70
|
-
// Icon with text combinations
|
|
71
|
-
iconWithText: function (iconPosition) {
|
|
72
|
-
if (iconPosition === void 0) { iconPosition = 'left'; }
|
|
73
|
-
if (iconPosition === 'left') {
|
|
74
|
-
return isRTL
|
|
75
|
-
? 'flex items-center flex-row-reverse gap-2'
|
|
76
|
-
: 'flex items-center gap-2';
|
|
77
|
-
}
|
|
78
|
-
return isRTL
|
|
79
|
-
? 'flex items-center gap-2'
|
|
80
|
-
: 'flex items-center flex-row-reverse gap-2';
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
exports.useRTLClasses = useRTLClasses;
|
|
1
|
+
var l=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var g=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},x=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of f(e))!u.call(r,n)&&n!==t&&l(r,n,{get:()=>e[n],enumerable:!(o=s(e,n))||o.enumerable});return r};var a=r=>x(l({},"__esModule",{value:!0}),r);var d={};g(d,{useRTL:()=>i,useRTLClasses:()=>c});module.exports=a(d);const i=r=>{if(r)return r==="ur";try{const{useLocale:e}=require("next-intl");return e()==="ur"}catch{return!1}},c=r=>{const e=i(r);return{isRTL:e,container:e?"rtl":"ltr",direction:e?"rtl":"ltr",flexRow:e?"flex-row-reverse":"flex-row",flexRowReverse:e?"flex-row":"flex-row-reverse",textAlign:e?"text-right":"text-left",textAlignReverse:e?"text-left":"text-right",marginLeft:e?"mr-auto":"ml-auto",marginRight:e?"ml-auto":"mr-auto",paddingLeft:t=>e?`pr-${t}`:`pl-${t}`,paddingRight:t=>e?`pl-${t}`:`pr-${t}`,gap:t=>`gap-${t}`,roundedLeft:e?"rounded-r":"rounded-l",roundedRight:e?"rounded-l":"rounded-r",iconButton:"flex items-center justify-center border",iconWithText:(t="left")=>t==="left"?e?"flex items-center flex-row-reverse gap-2":"flex items-center gap-2":e?"flex items-center gap-2":"flex items-center flex-row-reverse gap-2"}};0&&(module.exports={useRTL,useRTLClasses});
|